forked from publishpress/PublishPress-Authors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServices.php
126 lines (108 loc) · 3.58 KB
/
Services.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* @package MultipleAuthors
* @author PublishPress <[email protected]>
* @copyright Copyright (C) 2018 PublishPress. All rights reserved.
* @license GPLv2 or later
* @since 1.0.0
*/
namespace MultipleAuthors;
use Allex\Core;
use MultipleAuthors\Classes\Legacy\LegacyPlugin;
use Pimple\Container as Pimple;
use Pimple\ServiceProviderInterface;
use Twig_Environment;
use Twig_Loader_Filesystem;
use Twig_SimpleFunction;
defined('ABSPATH') or die('No direct script access allowed.');
/**
* Class Services
*/
class Services implements ServiceProviderInterface
{
/**
* Registers services on the given container.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param Pimple $container A container instance
*
* @since 1.2.3
*
*/
public function register(Pimple $container)
{
$container['legacy_plugin'] = function ($c) {
return new LegacyPlugin();
};
$container['module'] = function ($c) {
$legacyPlugin = $c['legacy_plugin'];
return $legacyPlugin->multiple_authors;
};
$container['twig_loader'] = function ($c) {
return new Twig_Loader_Filesystem(PP_AUTHORS_TWIG_PATH);
};
$container['twig'] = function ($c) {
$twig = new Twig_Environment($c['twig_loader']);
$function = new Twig_SimpleFunction(
'settings_fields', function () use ($c) {
return settings_fields('multiple_authors_options');
}
);
$twig->addFunction($function);
$function = new Twig_SimpleFunction(
'nonce_field', function ($context) {
return wp_nonce_field($context);
}
);
$twig->addFunction($function);
$function = new Twig_SimpleFunction(
'submit_button', function () {
return submit_button();
}
);
$twig->addFunction($function);
$function = new Twig_SimpleFunction(
'__', function ($id, $domain = 'publishpress-authors') {
return __($id, $domain);
}
);
$twig->addFunction($function);
$function = new Twig_SimpleFunction(
'do_settings_sections', function ($section) {
return do_settings_sections($section);
}
);
$twig->addFunction($function);
$function = new Twig_SimpleFunction(
'esc_attr', function ($string) {
return esc_attr($string);
}
);
$twig->addFunction($function);
$function = new Twig_SimpleFunction(
'do_shortcode', function ($string) {
return do_shortcode($string);
}
);
$twig->addFunction($function);
/**
* @deprecated 2.2.1 Replaced by the author.avatar attribute, which includes avatar for guest authors.
*/
$function = new Twig_SimpleFunction(
'get_avatar', function ($user_email, $size = 35) {
return get_avatar($user_email, $size);
}
);
$twig->addFunction($function);
/**
* @param Twig_Environment $twig
*
* @return Twig_Environment
*/
$twig = apply_filters('pp_authors_twig', $twig);
return $twig;
};
}
}