@@ -15,213 +15,213 @@ |
||
15 | 15 | class EE_Register_Capabilities implements EEI_Plugin_API |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Holds the settings for a specific registration. |
|
20 | - * |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected static $_registry = []; |
|
18 | + /** |
|
19 | + * Holds the settings for a specific registration. |
|
20 | + * |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected static $_registry = []; |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * Used to register capability items with EE core. |
|
28 | - * |
|
29 | - * @param string $identifier usually will be a class name |
|
30 | - * that references capability |
|
31 | - * related items setup for |
|
32 | - * something. |
|
33 | - * @param array $setup_args { |
|
34 | - * An array of items related to |
|
35 | - * registering capabilities. |
|
36 | - * @type array $capabilities An array mapping capability |
|
37 | - * strings to core WP Role. |
|
38 | - * Something like: array( |
|
39 | - * 'administrator' => array( |
|
40 | - * 'read_cap', 'edit_cap', |
|
41 | - * 'delete_cap'), |
|
42 | - * 'author' => |
|
43 | - * array( 'read_cap' ) |
|
44 | - * ). |
|
45 | - * @type array $capability_maps EE_Meta_Capability_Map[] |
|
46 | - * @return void |
|
47 | - * @throws EE_Error |
|
48 | - * @since 4.5.0 |
|
49 | - * @see EE_Capabilities.php for php docs on these objects. |
|
50 | - * Should be indexed by the |
|
51 | - * classname for the capability |
|
52 | - * map and values representing |
|
53 | - * the arguments for the map. |
|
54 | - * } |
|
55 | - */ |
|
56 | - public static function register($identifier = '', array $setup_args = []) |
|
57 | - { |
|
58 | - // required fields MUST be present, so let's make sure they are. |
|
59 | - if ($identifier === null || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
60 | - throw new EE_Error( |
|
61 | - __( |
|
62 | - 'In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', |
|
63 | - 'event_espresso' |
|
64 | - ) |
|
65 | - ); |
|
66 | - } |
|
67 | - // make sure we don't register twice |
|
68 | - if (isset(self::$_registry[ $identifier ])) { |
|
69 | - return; |
|
70 | - } |
|
71 | - // make sure this is not registered too late or too early. |
|
72 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
73 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
74 | - ) { |
|
75 | - EE_Error::doing_it_wrong( |
|
76 | - __METHOD__, |
|
77 | - sprintf( |
|
78 | - __( |
|
79 | - '%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - $identifier |
|
83 | - ), |
|
84 | - '4.5.0' |
|
85 | - ); |
|
86 | - } |
|
87 | - // some preliminary sanitization and setting to the $_registry property |
|
88 | - self::$_registry[ $identifier ] = [ |
|
89 | - 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) |
|
90 | - ? $setup_args['capabilities'] |
|
91 | - : [], |
|
92 | - 'cap_maps' => isset($setup_args['capability_maps']) ? $setup_args['capability_maps'] : [], |
|
93 | - ]; |
|
94 | - // set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once) |
|
95 | - add_filter( |
|
96 | - 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
97 | - ['EE_Register_Capabilities', 'register_capabilities'] |
|
98 | - ); |
|
99 | - // add filter for cap maps |
|
100 | - add_filter( |
|
101 | - 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
102 | - ['EE_Register_Capabilities', 'register_cap_maps'] |
|
103 | - ); |
|
104 | - } |
|
26 | + /** |
|
27 | + * Used to register capability items with EE core. |
|
28 | + * |
|
29 | + * @param string $identifier usually will be a class name |
|
30 | + * that references capability |
|
31 | + * related items setup for |
|
32 | + * something. |
|
33 | + * @param array $setup_args { |
|
34 | + * An array of items related to |
|
35 | + * registering capabilities. |
|
36 | + * @type array $capabilities An array mapping capability |
|
37 | + * strings to core WP Role. |
|
38 | + * Something like: array( |
|
39 | + * 'administrator' => array( |
|
40 | + * 'read_cap', 'edit_cap', |
|
41 | + * 'delete_cap'), |
|
42 | + * 'author' => |
|
43 | + * array( 'read_cap' ) |
|
44 | + * ). |
|
45 | + * @type array $capability_maps EE_Meta_Capability_Map[] |
|
46 | + * @return void |
|
47 | + * @throws EE_Error |
|
48 | + * @since 4.5.0 |
|
49 | + * @see EE_Capabilities.php for php docs on these objects. |
|
50 | + * Should be indexed by the |
|
51 | + * classname for the capability |
|
52 | + * map and values representing |
|
53 | + * the arguments for the map. |
|
54 | + * } |
|
55 | + */ |
|
56 | + public static function register($identifier = '', array $setup_args = []) |
|
57 | + { |
|
58 | + // required fields MUST be present, so let's make sure they are. |
|
59 | + if ($identifier === null || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
60 | + throw new EE_Error( |
|
61 | + __( |
|
62 | + 'In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', |
|
63 | + 'event_espresso' |
|
64 | + ) |
|
65 | + ); |
|
66 | + } |
|
67 | + // make sure we don't register twice |
|
68 | + if (isset(self::$_registry[ $identifier ])) { |
|
69 | + return; |
|
70 | + } |
|
71 | + // make sure this is not registered too late or too early. |
|
72 | + if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
73 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
74 | + ) { |
|
75 | + EE_Error::doing_it_wrong( |
|
76 | + __METHOD__, |
|
77 | + sprintf( |
|
78 | + __( |
|
79 | + '%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + $identifier |
|
83 | + ), |
|
84 | + '4.5.0' |
|
85 | + ); |
|
86 | + } |
|
87 | + // some preliminary sanitization and setting to the $_registry property |
|
88 | + self::$_registry[ $identifier ] = [ |
|
89 | + 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) |
|
90 | + ? $setup_args['capabilities'] |
|
91 | + : [], |
|
92 | + 'cap_maps' => isset($setup_args['capability_maps']) ? $setup_args['capability_maps'] : [], |
|
93 | + ]; |
|
94 | + // set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once) |
|
95 | + add_filter( |
|
96 | + 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
97 | + ['EE_Register_Capabilities', 'register_capabilities'] |
|
98 | + ); |
|
99 | + // add filter for cap maps |
|
100 | + add_filter( |
|
101 | + 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
102 | + ['EE_Register_Capabilities', 'register_cap_maps'] |
|
103 | + ); |
|
104 | + } |
|
105 | 105 | |
106 | 106 | |
107 | - /** |
|
108 | - * callback for FHEE__EE_Capabilities__init_caps_map__caps filter. |
|
109 | - * Takes care of registering additional capabilities to the caps map. Note, that this also on the initial |
|
110 | - * registration ensures that new capabilities are added to existing roles. |
|
111 | - * |
|
112 | - * @param array $incoming_caps The original caps map. |
|
113 | - * @return array merged in new caps. |
|
114 | - */ |
|
115 | - public static function register_capabilities(array $incoming_caps) |
|
116 | - { |
|
117 | - foreach (self::$_registry as $caps_and_cap_map) { |
|
118 | - $incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']); |
|
119 | - } |
|
120 | - return $incoming_caps; |
|
121 | - } |
|
107 | + /** |
|
108 | + * callback for FHEE__EE_Capabilities__init_caps_map__caps filter. |
|
109 | + * Takes care of registering additional capabilities to the caps map. Note, that this also on the initial |
|
110 | + * registration ensures that new capabilities are added to existing roles. |
|
111 | + * |
|
112 | + * @param array $incoming_caps The original caps map. |
|
113 | + * @return array merged in new caps. |
|
114 | + */ |
|
115 | + public static function register_capabilities(array $incoming_caps) |
|
116 | + { |
|
117 | + foreach (self::$_registry as $caps_and_cap_map) { |
|
118 | + $incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']); |
|
119 | + } |
|
120 | + return $incoming_caps; |
|
121 | + } |
|
122 | 122 | |
123 | 123 | |
124 | - /** |
|
125 | - * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of |
|
126 | - * capability maps for the WP meta_caps filter called in EE_Capabilities. |
|
127 | - * |
|
128 | - * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array. |
|
129 | - * @return EE_Meta_Capability_Map[] |
|
130 | - * @throws EE_Error |
|
131 | - * @since 4.5.0 |
|
132 | - */ |
|
133 | - public static function register_cap_maps(array $cap_maps) |
|
134 | - { |
|
135 | - // loop through and instantiate cap maps. |
|
136 | - foreach (self::$_registry as $identifier => $setup) { |
|
137 | - if (! isset($setup['cap_maps'])) { |
|
138 | - continue; |
|
139 | - } |
|
140 | - foreach ($setup['cap_maps'] as $cap_class => $args) { |
|
124 | + /** |
|
125 | + * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of |
|
126 | + * capability maps for the WP meta_caps filter called in EE_Capabilities. |
|
127 | + * |
|
128 | + * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array. |
|
129 | + * @return EE_Meta_Capability_Map[] |
|
130 | + * @throws EE_Error |
|
131 | + * @since 4.5.0 |
|
132 | + */ |
|
133 | + public static function register_cap_maps(array $cap_maps) |
|
134 | + { |
|
135 | + // loop through and instantiate cap maps. |
|
136 | + foreach (self::$_registry as $identifier => $setup) { |
|
137 | + if (! isset($setup['cap_maps'])) { |
|
138 | + continue; |
|
139 | + } |
|
140 | + foreach ($setup['cap_maps'] as $cap_class => $args) { |
|
141 | 141 | |
142 | - /** |
|
143 | - * account for cases where capability maps may be indexed |
|
144 | - * numerically to allow for the same map class to be utilized |
|
145 | - * In those cases, maps will be setup in an array like: |
|
146 | - * array( |
|
147 | - * 0 => array( 'EE_Meta_Capability' => array( |
|
148 | - * 'ee_edit_cap', array( 'Object_Name', |
|
149 | - * 'ee_edit_published_cap', |
|
150 | - * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
151 | - * ) ) |
|
152 | - * 1 => ... |
|
153 | - * ) |
|
154 | - * instead of: |
|
155 | - * array( |
|
156 | - * 'EE_Meta_Capability' => array( |
|
157 | - * 'ee_edit_cap', array( 'Object_Name', |
|
158 | - * 'ee_edit_published_cap', |
|
159 | - * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
160 | - * ), |
|
161 | - * ... |
|
162 | - * ) |
|
163 | - */ |
|
164 | - if (is_numeric($cap_class)) { |
|
165 | - $cap_class = key($args); |
|
166 | - $args = $args[ $cap_class ]; |
|
167 | - } |
|
142 | + /** |
|
143 | + * account for cases where capability maps may be indexed |
|
144 | + * numerically to allow for the same map class to be utilized |
|
145 | + * In those cases, maps will be setup in an array like: |
|
146 | + * array( |
|
147 | + * 0 => array( 'EE_Meta_Capability' => array( |
|
148 | + * 'ee_edit_cap', array( 'Object_Name', |
|
149 | + * 'ee_edit_published_cap', |
|
150 | + * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
151 | + * ) ) |
|
152 | + * 1 => ... |
|
153 | + * ) |
|
154 | + * instead of: |
|
155 | + * array( |
|
156 | + * 'EE_Meta_Capability' => array( |
|
157 | + * 'ee_edit_cap', array( 'Object_Name', |
|
158 | + * 'ee_edit_published_cap', |
|
159 | + * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
160 | + * ), |
|
161 | + * ... |
|
162 | + * ) |
|
163 | + */ |
|
164 | + if (is_numeric($cap_class)) { |
|
165 | + $cap_class = key($args); |
|
166 | + $args = $args[ $cap_class ]; |
|
167 | + } |
|
168 | 168 | |
169 | - if (! class_exists($cap_class)) { |
|
170 | - throw new EE_Error( |
|
171 | - sprintf( |
|
172 | - __( |
|
173 | - 'An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', |
|
174 | - 'event_espresso' |
|
175 | - ), |
|
176 | - $identifier |
|
177 | - ) |
|
178 | - ); |
|
179 | - } |
|
169 | + if (! class_exists($cap_class)) { |
|
170 | + throw new EE_Error( |
|
171 | + sprintf( |
|
172 | + __( |
|
173 | + 'An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', |
|
174 | + 'event_espresso' |
|
175 | + ), |
|
176 | + $identifier |
|
177 | + ) |
|
178 | + ); |
|
179 | + } |
|
180 | 180 | |
181 | - if (count($args) !== 2) { |
|
182 | - throw new EE_Error( |
|
183 | - sprintf( |
|
184 | - __( |
|
185 | - 'An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments. The array should have two values the first being a string and the second an array.', |
|
186 | - 'event_espresso' |
|
187 | - ), |
|
188 | - $identifier |
|
189 | - ) |
|
190 | - ); |
|
191 | - } |
|
192 | - $cap_maps[] = new $cap_class($args[0], $args[1]); |
|
193 | - } |
|
194 | - } |
|
195 | - return $cap_maps; |
|
196 | - } |
|
181 | + if (count($args) !== 2) { |
|
182 | + throw new EE_Error( |
|
183 | + sprintf( |
|
184 | + __( |
|
185 | + 'An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments. The array should have two values the first being a string and the second an array.', |
|
186 | + 'event_espresso' |
|
187 | + ), |
|
188 | + $identifier |
|
189 | + ) |
|
190 | + ); |
|
191 | + } |
|
192 | + $cap_maps[] = new $cap_class($args[0], $args[1]); |
|
193 | + } |
|
194 | + } |
|
195 | + return $cap_maps; |
|
196 | + } |
|
197 | 197 | |
198 | 198 | |
199 | - /** |
|
200 | - * @param string $identifier |
|
201 | - * @throws InvalidArgumentException |
|
202 | - * @throws InvalidDataTypeException |
|
203 | - * @throws InvalidInterfaceException |
|
204 | - */ |
|
205 | - public static function deregister($identifier = '') |
|
206 | - { |
|
207 | - if (! empty(self::$_registry[ $identifier ])) { |
|
208 | - if (! empty(self::$_registry[ $identifier ]['caps'])) { |
|
209 | - // if it's too early to remove capabilities, wait to do this until core is loaded and ready |
|
210 | - $caps_to_remove = self::$_registry[ $identifier ]['caps']; |
|
211 | - if (did_action('AHEE__EE_System__core_loaded_and_ready')) { |
|
212 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
213 | - $capabilities->removeCaps($caps_to_remove); |
|
214 | - } else { |
|
215 | - add_action( |
|
216 | - 'AHEE__EE_System__core_loaded_and_ready', |
|
217 | - function () use ($caps_to_remove) { |
|
218 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
219 | - $capabilities->removeCaps($caps_to_remove); |
|
220 | - } |
|
221 | - ); |
|
222 | - } |
|
223 | - } |
|
224 | - } |
|
225 | - unset(self::$_registry[ $identifier ]); |
|
226 | - } |
|
199 | + /** |
|
200 | + * @param string $identifier |
|
201 | + * @throws InvalidArgumentException |
|
202 | + * @throws InvalidDataTypeException |
|
203 | + * @throws InvalidInterfaceException |
|
204 | + */ |
|
205 | + public static function deregister($identifier = '') |
|
206 | + { |
|
207 | + if (! empty(self::$_registry[ $identifier ])) { |
|
208 | + if (! empty(self::$_registry[ $identifier ]['caps'])) { |
|
209 | + // if it's too early to remove capabilities, wait to do this until core is loaded and ready |
|
210 | + $caps_to_remove = self::$_registry[ $identifier ]['caps']; |
|
211 | + if (did_action('AHEE__EE_System__core_loaded_and_ready')) { |
|
212 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
213 | + $capabilities->removeCaps($caps_to_remove); |
|
214 | + } else { |
|
215 | + add_action( |
|
216 | + 'AHEE__EE_System__core_loaded_and_ready', |
|
217 | + function () use ($caps_to_remove) { |
|
218 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
219 | + $capabilities->removeCaps($caps_to_remove); |
|
220 | + } |
|
221 | + ); |
|
222 | + } |
|
223 | + } |
|
224 | + } |
|
225 | + unset(self::$_registry[ $identifier ]); |
|
226 | + } |
|
227 | 227 | } |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | ); |
66 | 66 | } |
67 | 67 | // make sure we don't register twice |
68 | - if (isset(self::$_registry[ $identifier ])) { |
|
68 | + if (isset(self::$_registry[$identifier])) { |
|
69 | 69 | return; |
70 | 70 | } |
71 | 71 | // make sure this is not registered too late or too early. |
72 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
72 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') |
|
73 | 73 | || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
74 | 74 | ) { |
75 | 75 | EE_Error::doing_it_wrong( |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | ); |
86 | 86 | } |
87 | 87 | // some preliminary sanitization and setting to the $_registry property |
88 | - self::$_registry[ $identifier ] = [ |
|
88 | + self::$_registry[$identifier] = [ |
|
89 | 89 | 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) |
90 | 90 | ? $setup_args['capabilities'] |
91 | 91 | : [], |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | { |
135 | 135 | // loop through and instantiate cap maps. |
136 | 136 | foreach (self::$_registry as $identifier => $setup) { |
137 | - if (! isset($setup['cap_maps'])) { |
|
137 | + if ( ! isset($setup['cap_maps'])) { |
|
138 | 138 | continue; |
139 | 139 | } |
140 | 140 | foreach ($setup['cap_maps'] as $cap_class => $args) { |
@@ -163,10 +163,10 @@ discard block |
||
163 | 163 | */ |
164 | 164 | if (is_numeric($cap_class)) { |
165 | 165 | $cap_class = key($args); |
166 | - $args = $args[ $cap_class ]; |
|
166 | + $args = $args[$cap_class]; |
|
167 | 167 | } |
168 | 168 | |
169 | - if (! class_exists($cap_class)) { |
|
169 | + if ( ! class_exists($cap_class)) { |
|
170 | 170 | throw new EE_Error( |
171 | 171 | sprintf( |
172 | 172 | __( |
@@ -204,17 +204,17 @@ discard block |
||
204 | 204 | */ |
205 | 205 | public static function deregister($identifier = '') |
206 | 206 | { |
207 | - if (! empty(self::$_registry[ $identifier ])) { |
|
208 | - if (! empty(self::$_registry[ $identifier ]['caps'])) { |
|
207 | + if ( ! empty(self::$_registry[$identifier])) { |
|
208 | + if ( ! empty(self::$_registry[$identifier]['caps'])) { |
|
209 | 209 | // if it's too early to remove capabilities, wait to do this until core is loaded and ready |
210 | - $caps_to_remove = self::$_registry[ $identifier ]['caps']; |
|
210 | + $caps_to_remove = self::$_registry[$identifier]['caps']; |
|
211 | 211 | if (did_action('AHEE__EE_System__core_loaded_and_ready')) { |
212 | 212 | $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
213 | 213 | $capabilities->removeCaps($caps_to_remove); |
214 | 214 | } else { |
215 | 215 | add_action( |
216 | 216 | 'AHEE__EE_System__core_loaded_and_ready', |
217 | - function () use ($caps_to_remove) { |
|
217 | + function() use ($caps_to_remove) { |
|
218 | 218 | $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
219 | 219 | $capabilities->removeCaps($caps_to_remove); |
220 | 220 | } |
@@ -222,6 +222,6 @@ discard block |
||
222 | 222 | } |
223 | 223 | } |
224 | 224 | } |
225 | - unset(self::$_registry[ $identifier ]); |
|
225 | + unset(self::$_registry[$identifier]); |
|
226 | 226 | } |
227 | 227 | } |
@@ -11,330 +11,330 @@ |
||
11 | 11 | class EE_Register_Messages_Template_Variations implements EEI_Plugin_API |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * Holds values for registered variations |
|
16 | - * |
|
17 | - * @since 4.5.0 |
|
18 | - * |
|
19 | - * @var array |
|
20 | - */ |
|
21 | - protected static $_registry = []; |
|
14 | + /** |
|
15 | + * Holds values for registered variations |
|
16 | + * |
|
17 | + * @since 4.5.0 |
|
18 | + * |
|
19 | + * @var array |
|
20 | + */ |
|
21 | + protected static $_registry = []; |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * Used to register new variations |
|
26 | - * |
|
27 | - * Variations are attached to template packs and do not typically change any structural layout but merely tweak the |
|
28 | - * style of the layout. The most commonly known variation is css. CSS does not affect html structure just the |
|
29 | - * style of existing structure. |
|
30 | - * |
|
31 | - * It's important to remember that when variation files are loaded, the file structure looked for is: |
|
32 | - * '{$messenger}_{$messenger_variation_type}_{$variation_slug}.{$extension}'. |
|
33 | - * |
|
34 | - * - Every variation applies to specific messengers. That's why the variation file includes the messenger name |
|
35 | - * it. This ensures that if a template pack the variation is registered with supports multiple variations that |
|
36 | - * you can have the correct variation loaded. |
|
37 | - * - EE_messengers also implicitly define variation "types" which typically are the context in which a specific |
|
38 | - * variation is loaded. For instance the email messenger has: 'inline', which is the css added inline to the |
|
39 | - * email templates; 'preview', which is the same css only customized for when emails are previewed; and |
|
40 | - * 'wpeditor', which is the same css only customized so that it works with the wpeditor fields for templates to |
|
41 | - * give a accurate representation of the style in the wysiwyg editor. This means that for each variation, if |
|
42 | - * you want it to be accurately represented in various template contexts you need to have that relevant |
|
43 | - * variation file available. |
|
44 | - * - $variation_slug is simply the variation slug for that variation. |
|
45 | - * - $extension = whatever the extension is for the variation used for the messenger calling it. In MOST cases |
|
46 | - * messenger variations are .css files. Note: if your file names are not formatted correctly then they will NOT |
|
47 | - * be loaded. The EE messages template pack system will fallback to corresponding default template pack for the |
|
48 | - * given messenger or as a last resort (i.e. no default variation for the given messenger) will not load any |
|
49 | - * variation (so the template pack would be unstyled) |
|
50 | - * |
|
51 | - * @see /core/libraries/messages/defaults/default/variations/* for example variation files for the email and html |
|
52 | - * messengers. |
|
53 | - * |
|
54 | - * @param string $identifier unique reference used to describe this variation registry. If |
|
55 | - * this ISN'T unique then this method will make it unique (and it |
|
56 | - * becomes harder to deregister). |
|
57 | - * @param array $setup_args { |
|
58 | - * an array of required values for registering the variations. |
|
59 | - * @type array $variations { |
|
60 | - * An array indexed by template_pack->dbref. and values are an array |
|
61 | - * indexed by messenger name and values are an array indexed by |
|
62 | - * message_type and values are an array indexed by variation_slug |
|
63 | - * and value is the localized label for the variation. Note this |
|
64 | - * api reserves the "default" variation name for the default |
|
65 | - * template pack so you can't register a default variation. Also, |
|
66 | - * try to use unique variation slugs to reference your variations |
|
67 | - * because this api checks if any existing variations are in place |
|
68 | - * with that name. If there are then subsequent variations for that |
|
69 | - * template pack with that same name will fail to register with a |
|
70 | - * persistent notice put up for the user. Required. |
|
71 | - * 'default' => array( |
|
72 | - * 'email' => array( |
|
73 | - * 'registration_approved' => array( |
|
74 | - * my_ee_addon_blue_lagoon' => __('Blue Lagoon', |
|
75 | - * 'text_domain'), |
|
76 | - * 'my_ee_addon_red_sunset' => __('Red Sunset', |
|
77 | - * 'text_domain') |
|
78 | - * ) |
|
79 | - * ) |
|
80 | - * ) |
|
81 | - * } |
|
82 | - * @type string $base_path The base path for where all your variations are found. Although |
|
83 | - * the full path to your variation files should include |
|
84 | - * '/variations/' in it, do not include the |
|
85 | - * 'variations/' in this. Required. |
|
86 | - * @type string $base_url The base url for where all your variations are found. See note |
|
87 | - * above about the 'variations/' string. Required. |
|
88 | - * } |
|
89 | - * } |
|
90 | - * |
|
91 | - * @throws EE_Error |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public static function register($identifier = '', array $setup_args = []) |
|
95 | - { |
|
24 | + /** |
|
25 | + * Used to register new variations |
|
26 | + * |
|
27 | + * Variations are attached to template packs and do not typically change any structural layout but merely tweak the |
|
28 | + * style of the layout. The most commonly known variation is css. CSS does not affect html structure just the |
|
29 | + * style of existing structure. |
|
30 | + * |
|
31 | + * It's important to remember that when variation files are loaded, the file structure looked for is: |
|
32 | + * '{$messenger}_{$messenger_variation_type}_{$variation_slug}.{$extension}'. |
|
33 | + * |
|
34 | + * - Every variation applies to specific messengers. That's why the variation file includes the messenger name |
|
35 | + * it. This ensures that if a template pack the variation is registered with supports multiple variations that |
|
36 | + * you can have the correct variation loaded. |
|
37 | + * - EE_messengers also implicitly define variation "types" which typically are the context in which a specific |
|
38 | + * variation is loaded. For instance the email messenger has: 'inline', which is the css added inline to the |
|
39 | + * email templates; 'preview', which is the same css only customized for when emails are previewed; and |
|
40 | + * 'wpeditor', which is the same css only customized so that it works with the wpeditor fields for templates to |
|
41 | + * give a accurate representation of the style in the wysiwyg editor. This means that for each variation, if |
|
42 | + * you want it to be accurately represented in various template contexts you need to have that relevant |
|
43 | + * variation file available. |
|
44 | + * - $variation_slug is simply the variation slug for that variation. |
|
45 | + * - $extension = whatever the extension is for the variation used for the messenger calling it. In MOST cases |
|
46 | + * messenger variations are .css files. Note: if your file names are not formatted correctly then they will NOT |
|
47 | + * be loaded. The EE messages template pack system will fallback to corresponding default template pack for the |
|
48 | + * given messenger or as a last resort (i.e. no default variation for the given messenger) will not load any |
|
49 | + * variation (so the template pack would be unstyled) |
|
50 | + * |
|
51 | + * @see /core/libraries/messages/defaults/default/variations/* for example variation files for the email and html |
|
52 | + * messengers. |
|
53 | + * |
|
54 | + * @param string $identifier unique reference used to describe this variation registry. If |
|
55 | + * this ISN'T unique then this method will make it unique (and it |
|
56 | + * becomes harder to deregister). |
|
57 | + * @param array $setup_args { |
|
58 | + * an array of required values for registering the variations. |
|
59 | + * @type array $variations { |
|
60 | + * An array indexed by template_pack->dbref. and values are an array |
|
61 | + * indexed by messenger name and values are an array indexed by |
|
62 | + * message_type and values are an array indexed by variation_slug |
|
63 | + * and value is the localized label for the variation. Note this |
|
64 | + * api reserves the "default" variation name for the default |
|
65 | + * template pack so you can't register a default variation. Also, |
|
66 | + * try to use unique variation slugs to reference your variations |
|
67 | + * because this api checks if any existing variations are in place |
|
68 | + * with that name. If there are then subsequent variations for that |
|
69 | + * template pack with that same name will fail to register with a |
|
70 | + * persistent notice put up for the user. Required. |
|
71 | + * 'default' => array( |
|
72 | + * 'email' => array( |
|
73 | + * 'registration_approved' => array( |
|
74 | + * my_ee_addon_blue_lagoon' => __('Blue Lagoon', |
|
75 | + * 'text_domain'), |
|
76 | + * 'my_ee_addon_red_sunset' => __('Red Sunset', |
|
77 | + * 'text_domain') |
|
78 | + * ) |
|
79 | + * ) |
|
80 | + * ) |
|
81 | + * } |
|
82 | + * @type string $base_path The base path for where all your variations are found. Although |
|
83 | + * the full path to your variation files should include |
|
84 | + * '/variations/' in it, do not include the |
|
85 | + * 'variations/' in this. Required. |
|
86 | + * @type string $base_url The base url for where all your variations are found. See note |
|
87 | + * above about the 'variations/' string. Required. |
|
88 | + * } |
|
89 | + * } |
|
90 | + * |
|
91 | + * @throws EE_Error |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public static function register($identifier = '', array $setup_args = []) |
|
95 | + { |
|
96 | 96 | |
97 | - // check for required params |
|
98 | - if (empty($identifier)) { |
|
99 | - throw new EE_Error( |
|
100 | - __( |
|
101 | - 'In order to register variations for a EE_Message_Template_Pack, you must include a value to reference the variations being registered', |
|
102 | - 'event_espresso' |
|
103 | - ) |
|
104 | - ); |
|
105 | - } |
|
97 | + // check for required params |
|
98 | + if (empty($identifier)) { |
|
99 | + throw new EE_Error( |
|
100 | + __( |
|
101 | + 'In order to register variations for a EE_Message_Template_Pack, you must include a value to reference the variations being registered', |
|
102 | + 'event_espresso' |
|
103 | + ) |
|
104 | + ); |
|
105 | + } |
|
106 | 106 | |
107 | - if (! is_array($setup_args) |
|
108 | - || empty($setup_args['variations']) |
|
109 | - || empty($setup_args['base_path']) |
|
110 | - || empty($setup_args['base_url']) |
|
111 | - ) { |
|
112 | - throw new EE_Error( |
|
113 | - __( |
|
114 | - 'In order to register variations for a EE_Message_Template_Pack, you must include an array containing the following keys: "variations", "base_path", "base_url", "extension"', |
|
115 | - 'event_espresso' |
|
116 | - ) |
|
117 | - ); |
|
118 | - } |
|
107 | + if (! is_array($setup_args) |
|
108 | + || empty($setup_args['variations']) |
|
109 | + || empty($setup_args['base_path']) |
|
110 | + || empty($setup_args['base_url']) |
|
111 | + ) { |
|
112 | + throw new EE_Error( |
|
113 | + __( |
|
114 | + 'In order to register variations for a EE_Message_Template_Pack, you must include an array containing the following keys: "variations", "base_path", "base_url", "extension"', |
|
115 | + 'event_espresso' |
|
116 | + ) |
|
117 | + ); |
|
118 | + } |
|
119 | 119 | |
120 | - // make sure we don't register twice |
|
121 | - if (isset(self::$_registry[ $identifier ])) { |
|
122 | - return; |
|
123 | - } |
|
120 | + // make sure we don't register twice |
|
121 | + if (isset(self::$_registry[ $identifier ])) { |
|
122 | + return; |
|
123 | + } |
|
124 | 124 | |
125 | - // make sure variation ref is unique. |
|
126 | - if (isset(self::$_registry[ $identifier ])) { |
|
127 | - $identifier = uniqid() . '_' . $identifier; |
|
128 | - } |
|
125 | + // make sure variation ref is unique. |
|
126 | + if (isset(self::$_registry[ $identifier ])) { |
|
127 | + $identifier = uniqid() . '_' . $identifier; |
|
128 | + } |
|
129 | 129 | |
130 | 130 | |
131 | - // make sure this was called in the right place! |
|
132 | - if (! did_action('EE_Brewing_Regular___messages_caf') |
|
133 | - || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
134 | - ) { |
|
135 | - EE_Error::doing_it_wrong( |
|
136 | - __METHOD__, |
|
137 | - sprintf( |
|
138 | - __( |
|
139 | - 'Messages Templates Variations given the reference "%s" has been attempted to be registered with the EE Messages Template Pack System. It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.', |
|
140 | - 'event_espresso' |
|
141 | - ), |
|
142 | - $identifier |
|
143 | - ), |
|
144 | - '4.5.0' |
|
145 | - ); |
|
146 | - } |
|
131 | + // make sure this was called in the right place! |
|
132 | + if (! did_action('EE_Brewing_Regular___messages_caf') |
|
133 | + || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
134 | + ) { |
|
135 | + EE_Error::doing_it_wrong( |
|
136 | + __METHOD__, |
|
137 | + sprintf( |
|
138 | + __( |
|
139 | + 'Messages Templates Variations given the reference "%s" has been attempted to be registered with the EE Messages Template Pack System. It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.', |
|
140 | + 'event_espresso' |
|
141 | + ), |
|
142 | + $identifier |
|
143 | + ), |
|
144 | + '4.5.0' |
|
145 | + ); |
|
146 | + } |
|
147 | 147 | |
148 | - // validate/sanitize incoming args. |
|
149 | - $validated = [ |
|
150 | - 'variations' => (array) $setup_args['variations'], |
|
151 | - 'base_path' => (string) $setup_args['base_path'], |
|
152 | - 'base_url' => (string) $setup_args['base_url'], |
|
153 | - ]; |
|
148 | + // validate/sanitize incoming args. |
|
149 | + $validated = [ |
|
150 | + 'variations' => (array) $setup_args['variations'], |
|
151 | + 'base_path' => (string) $setup_args['base_path'], |
|
152 | + 'base_url' => (string) $setup_args['base_url'], |
|
153 | + ]; |
|
154 | 154 | |
155 | 155 | |
156 | - // check that no reserved variation names are in use and also checks if there are already existing variation names for a given template pack. The former will throw an error. The latter will remove the conflicting variation name but still register the others and will add EE_Error notice. |
|
157 | - $validated = self::_verify_variations($identifier, $validated); |
|
158 | - self::$_registry[ $identifier ] = $validated; |
|
156 | + // check that no reserved variation names are in use and also checks if there are already existing variation names for a given template pack. The former will throw an error. The latter will remove the conflicting variation name but still register the others and will add EE_Error notice. |
|
157 | + $validated = self::_verify_variations($identifier, $validated); |
|
158 | + self::$_registry[ $identifier ] = $validated; |
|
159 | 159 | |
160 | - add_filter( |
|
161 | - 'FHEE__EE_Messages_Template_Pack__get_variations', |
|
162 | - ['EE_Register_Messages_Template_Variations', 'get_variations'], |
|
163 | - 10, |
|
164 | - 4 |
|
165 | - ); |
|
166 | - add_filter( |
|
167 | - 'FHEE__EE_Messages_Template_Pack__get_variation', |
|
168 | - ['EE_Register_Messages_Template_Variations', 'get_variation'], |
|
169 | - 10, |
|
170 | - 8 |
|
171 | - ); |
|
172 | - } |
|
160 | + add_filter( |
|
161 | + 'FHEE__EE_Messages_Template_Pack__get_variations', |
|
162 | + ['EE_Register_Messages_Template_Variations', 'get_variations'], |
|
163 | + 10, |
|
164 | + 4 |
|
165 | + ); |
|
166 | + add_filter( |
|
167 | + 'FHEE__EE_Messages_Template_Pack__get_variation', |
|
168 | + ['EE_Register_Messages_Template_Variations', 'get_variation'], |
|
169 | + 10, |
|
170 | + 8 |
|
171 | + ); |
|
172 | + } |
|
173 | 173 | |
174 | 174 | |
175 | - /** |
|
176 | - * Cycles through the variations registered and makes sure there are no reserved variations being registered which |
|
177 | - * throws an error. Also checks if there is already a |
|
178 | - * |
|
179 | - * @param string $identifier the reference for the variations being registered |
|
180 | - * @param array $validated_variations The variations setup array that's being registered (and verified). |
|
181 | - * @return array |
|
182 | - * @throws EE_Error |
|
183 | - * @since 4.5.0 |
|
184 | - * |
|
185 | - */ |
|
186 | - private static function _verify_variations($identifier, array $validated_variations) |
|
187 | - { |
|
188 | - foreach (self::$_registry as $settings) { |
|
189 | - foreach ($settings['variations'] as $messenger) { |
|
190 | - foreach ($messenger as $all_variations) { |
|
191 | - if (isset($all_variations['default'])) { |
|
192 | - throw new EE_Error( |
|
193 | - sprintf( |
|
194 | - __( |
|
195 | - 'Variations registered through the EE_Register_Messages_Template_Variations api cannot override the default variation for the default template. Please check the code registering variations with this reference, "%s" and modify.', |
|
196 | - 'event_espresso' |
|
197 | - ), |
|
198 | - $identifier |
|
199 | - ) |
|
200 | - ); |
|
201 | - } |
|
202 | - } |
|
203 | - } |
|
204 | - } |
|
175 | + /** |
|
176 | + * Cycles through the variations registered and makes sure there are no reserved variations being registered which |
|
177 | + * throws an error. Also checks if there is already a |
|
178 | + * |
|
179 | + * @param string $identifier the reference for the variations being registered |
|
180 | + * @param array $validated_variations The variations setup array that's being registered (and verified). |
|
181 | + * @return array |
|
182 | + * @throws EE_Error |
|
183 | + * @since 4.5.0 |
|
184 | + * |
|
185 | + */ |
|
186 | + private static function _verify_variations($identifier, array $validated_variations) |
|
187 | + { |
|
188 | + foreach (self::$_registry as $settings) { |
|
189 | + foreach ($settings['variations'] as $messenger) { |
|
190 | + foreach ($messenger as $all_variations) { |
|
191 | + if (isset($all_variations['default'])) { |
|
192 | + throw new EE_Error( |
|
193 | + sprintf( |
|
194 | + __( |
|
195 | + 'Variations registered through the EE_Register_Messages_Template_Variations api cannot override the default variation for the default template. Please check the code registering variations with this reference, "%s" and modify.', |
|
196 | + 'event_espresso' |
|
197 | + ), |
|
198 | + $identifier |
|
199 | + ) |
|
200 | + ); |
|
201 | + } |
|
202 | + } |
|
203 | + } |
|
204 | + } |
|
205 | 205 | |
206 | - // is there already a variation registered with a given variation slug? |
|
207 | - foreach ($validated_variations['variations'] as $template_pack => $messenger) { |
|
208 | - foreach ($messenger as $message_type => $variations) { |
|
209 | - foreach ($variations as $slug => $label) { |
|
210 | - foreach (self::$_registry as $registered_var => $reg_settings) { |
|
211 | - if (isset($reg_settings['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ])) { |
|
212 | - unset($validated_variations['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ]); |
|
213 | - EE_Error::add_error( |
|
214 | - sprintf( |
|
215 | - __( |
|
216 | - 'Unable to register the %s variation for the %s template pack with the %s messenger and %s message_type because a variation with this slug was already registered for this template pack and messenger and message type by an addon using this key %s.', |
|
217 | - 'event_espresso' |
|
218 | - ), |
|
219 | - $label, |
|
220 | - $template_pack, |
|
221 | - $messenger, |
|
222 | - $message_type, |
|
223 | - $registered_var |
|
224 | - ) |
|
225 | - ); |
|
226 | - } |
|
227 | - } |
|
228 | - } |
|
229 | - } |
|
230 | - } |
|
231 | - return $validated_variations; |
|
232 | - } |
|
206 | + // is there already a variation registered with a given variation slug? |
|
207 | + foreach ($validated_variations['variations'] as $template_pack => $messenger) { |
|
208 | + foreach ($messenger as $message_type => $variations) { |
|
209 | + foreach ($variations as $slug => $label) { |
|
210 | + foreach (self::$_registry as $registered_var => $reg_settings) { |
|
211 | + if (isset($reg_settings['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ])) { |
|
212 | + unset($validated_variations['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ]); |
|
213 | + EE_Error::add_error( |
|
214 | + sprintf( |
|
215 | + __( |
|
216 | + 'Unable to register the %s variation for the %s template pack with the %s messenger and %s message_type because a variation with this slug was already registered for this template pack and messenger and message type by an addon using this key %s.', |
|
217 | + 'event_espresso' |
|
218 | + ), |
|
219 | + $label, |
|
220 | + $template_pack, |
|
221 | + $messenger, |
|
222 | + $message_type, |
|
223 | + $registered_var |
|
224 | + ) |
|
225 | + ); |
|
226 | + } |
|
227 | + } |
|
228 | + } |
|
229 | + } |
|
230 | + } |
|
231 | + return $validated_variations; |
|
232 | + } |
|
233 | 233 | |
234 | 234 | |
235 | - /** |
|
236 | - * Callback for the FHEE__EE_Messages_Template_Pack__get_variation filter to ensure registered variations are used. |
|
237 | - * |
|
238 | - * @param string $variation_path The path generated for the current variation |
|
239 | - * @param string $messenger The messenger the variation is for |
|
240 | - * @param string $message_type EE_message_type->name |
|
241 | - * @param string $type The type of variation being requested |
|
242 | - * @param string $variation The slug for the variation being requested |
|
243 | - * @param string $file_extension What the file extension is for the variation |
|
244 | - * @param bool $url Whether url or path is being returned. |
|
245 | - * @param EE_Messages_Template_Pack $template_pack |
|
246 | - * |
|
247 | - * @return string The path to the requested variation. |
|
248 | - * @since 4.5.0 |
|
249 | - * |
|
250 | - */ |
|
251 | - public static function get_variation( |
|
252 | - $variation_path, |
|
253 | - $messenger, |
|
254 | - $message_type, |
|
255 | - $type, |
|
256 | - $variation, |
|
257 | - $file_extension, |
|
258 | - $url, |
|
259 | - EE_Messages_Template_Pack $template_pack |
|
260 | - ) { |
|
261 | - // so let's loop through our registered variations and then pull any details matching the request. |
|
262 | - foreach (self::$_registry as $registry_settings) { |
|
263 | - $base = $url ? $registry_settings['base_url'] : $registry_settings['base_path']; |
|
264 | - $file_string = $messenger . '_' . $type . '_' . $variation . $file_extension; |
|
265 | - // see if this file exists |
|
266 | - if (is_readable($registry_settings['base_path'] . $file_string)) { |
|
267 | - return $base . $file_string; |
|
268 | - } |
|
269 | - } |
|
235 | + /** |
|
236 | + * Callback for the FHEE__EE_Messages_Template_Pack__get_variation filter to ensure registered variations are used. |
|
237 | + * |
|
238 | + * @param string $variation_path The path generated for the current variation |
|
239 | + * @param string $messenger The messenger the variation is for |
|
240 | + * @param string $message_type EE_message_type->name |
|
241 | + * @param string $type The type of variation being requested |
|
242 | + * @param string $variation The slug for the variation being requested |
|
243 | + * @param string $file_extension What the file extension is for the variation |
|
244 | + * @param bool $url Whether url or path is being returned. |
|
245 | + * @param EE_Messages_Template_Pack $template_pack |
|
246 | + * |
|
247 | + * @return string The path to the requested variation. |
|
248 | + * @since 4.5.0 |
|
249 | + * |
|
250 | + */ |
|
251 | + public static function get_variation( |
|
252 | + $variation_path, |
|
253 | + $messenger, |
|
254 | + $message_type, |
|
255 | + $type, |
|
256 | + $variation, |
|
257 | + $file_extension, |
|
258 | + $url, |
|
259 | + EE_Messages_Template_Pack $template_pack |
|
260 | + ) { |
|
261 | + // so let's loop through our registered variations and then pull any details matching the request. |
|
262 | + foreach (self::$_registry as $registry_settings) { |
|
263 | + $base = $url ? $registry_settings['base_url'] : $registry_settings['base_path']; |
|
264 | + $file_string = $messenger . '_' . $type . '_' . $variation . $file_extension; |
|
265 | + // see if this file exists |
|
266 | + if (is_readable($registry_settings['base_path'] . $file_string)) { |
|
267 | + return $base . $file_string; |
|
268 | + } |
|
269 | + } |
|
270 | 270 | |
271 | - // no match |
|
272 | - return $variation_path; |
|
273 | - } |
|
271 | + // no match |
|
272 | + return $variation_path; |
|
273 | + } |
|
274 | 274 | |
275 | 275 | |
276 | - /** |
|
277 | - * callback for the FHEE__EE_Messages_Template_Pack__get_variations filter. |
|
278 | - * |
|
279 | - * |
|
280 | - * @param array $variations The original contents for the template pack variations property. |
|
281 | - * @param string $messenger The messenger requesting the variations. |
|
282 | - * @param string $message_type |
|
283 | - * @param EE_Messages_Template_Pack $template_pack |
|
284 | - * |
|
285 | - * @return array new variations array (or existing one if nothing registered) |
|
286 | - * @since 4.5.0 |
|
287 | - * |
|
288 | - * @see $_variation property definition in EE_Messages_Template_Pack |
|
289 | - */ |
|
290 | - public static function get_variations( |
|
291 | - array $variations, |
|
292 | - $messenger, |
|
293 | - $message_type, |
|
294 | - EE_Messages_Template_Pack $template_pack |
|
295 | - ) { |
|
296 | - // first let's check if we even have registered variations and get out early. |
|
297 | - if (empty(self::$_registry)) { |
|
298 | - return $variations; |
|
299 | - } |
|
276 | + /** |
|
277 | + * callback for the FHEE__EE_Messages_Template_Pack__get_variations filter. |
|
278 | + * |
|
279 | + * |
|
280 | + * @param array $variations The original contents for the template pack variations property. |
|
281 | + * @param string $messenger The messenger requesting the variations. |
|
282 | + * @param string $message_type |
|
283 | + * @param EE_Messages_Template_Pack $template_pack |
|
284 | + * |
|
285 | + * @return array new variations array (or existing one if nothing registered) |
|
286 | + * @since 4.5.0 |
|
287 | + * |
|
288 | + * @see $_variation property definition in EE_Messages_Template_Pack |
|
289 | + */ |
|
290 | + public static function get_variations( |
|
291 | + array $variations, |
|
292 | + $messenger, |
|
293 | + $message_type, |
|
294 | + EE_Messages_Template_Pack $template_pack |
|
295 | + ) { |
|
296 | + // first let's check if we even have registered variations and get out early. |
|
297 | + if (empty(self::$_registry)) { |
|
298 | + return $variations; |
|
299 | + } |
|
300 | 300 | |
301 | - // do we have any new variations for the given messenger, $message_type, and template packs |
|
302 | - foreach (self::$_registry as $registry_settings) { |
|
303 | - // allow for different conditions. |
|
304 | - if (empty($messenger)) { |
|
305 | - return array_merge($registry_settings['variations'], $variations); |
|
306 | - } |
|
307 | - if (empty($message_type)) { |
|
308 | - if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ])) { |
|
309 | - return array_merge( |
|
310 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ], |
|
311 | - $variations |
|
312 | - ); |
|
313 | - } |
|
314 | - } else { |
|
315 | - if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ])) { |
|
316 | - return array_merge( |
|
317 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ], |
|
318 | - $variations |
|
319 | - ); |
|
320 | - } |
|
321 | - } |
|
322 | - } |
|
323 | - return $variations; |
|
324 | - } |
|
301 | + // do we have any new variations for the given messenger, $message_type, and template packs |
|
302 | + foreach (self::$_registry as $registry_settings) { |
|
303 | + // allow for different conditions. |
|
304 | + if (empty($messenger)) { |
|
305 | + return array_merge($registry_settings['variations'], $variations); |
|
306 | + } |
|
307 | + if (empty($message_type)) { |
|
308 | + if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ])) { |
|
309 | + return array_merge( |
|
310 | + $registry_settings['variations'][ $template_pack->dbref ][ $messenger ], |
|
311 | + $variations |
|
312 | + ); |
|
313 | + } |
|
314 | + } else { |
|
315 | + if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ])) { |
|
316 | + return array_merge( |
|
317 | + $registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ], |
|
318 | + $variations |
|
319 | + ); |
|
320 | + } |
|
321 | + } |
|
322 | + } |
|
323 | + return $variations; |
|
324 | + } |
|
325 | 325 | |
326 | 326 | |
327 | - /** |
|
328 | - * This deregisters a variation set that was previously registered with the given slug. |
|
329 | - * |
|
330 | - * @param string $identifier The name for the variation set that was previously registered. |
|
331 | - * |
|
332 | - * @return void |
|
333 | - * @since 4.5.0 |
|
334 | - * |
|
335 | - */ |
|
336 | - public static function deregister($identifier = '') |
|
337 | - { |
|
338 | - unset(self::$_registry[ $identifier ]); |
|
339 | - } |
|
327 | + /** |
|
328 | + * This deregisters a variation set that was previously registered with the given slug. |
|
329 | + * |
|
330 | + * @param string $identifier The name for the variation set that was previously registered. |
|
331 | + * |
|
332 | + * @return void |
|
333 | + * @since 4.5.0 |
|
334 | + * |
|
335 | + */ |
|
336 | + public static function deregister($identifier = '') |
|
337 | + { |
|
338 | + unset(self::$_registry[ $identifier ]); |
|
339 | + } |
|
340 | 340 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | ); |
105 | 105 | } |
106 | 106 | |
107 | - if (! is_array($setup_args) |
|
107 | + if ( ! is_array($setup_args) |
|
108 | 108 | || empty($setup_args['variations']) |
109 | 109 | || empty($setup_args['base_path']) |
110 | 110 | || empty($setup_args['base_url']) |
@@ -118,18 +118,18 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | // make sure we don't register twice |
121 | - if (isset(self::$_registry[ $identifier ])) { |
|
121 | + if (isset(self::$_registry[$identifier])) { |
|
122 | 122 | return; |
123 | 123 | } |
124 | 124 | |
125 | 125 | // make sure variation ref is unique. |
126 | - if (isset(self::$_registry[ $identifier ])) { |
|
127 | - $identifier = uniqid() . '_' . $identifier; |
|
126 | + if (isset(self::$_registry[$identifier])) { |
|
127 | + $identifier = uniqid().'_'.$identifier; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | |
131 | 131 | // make sure this was called in the right place! |
132 | - if (! did_action('EE_Brewing_Regular___messages_caf') |
|
132 | + if ( ! did_action('EE_Brewing_Regular___messages_caf') |
|
133 | 133 | || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
134 | 134 | ) { |
135 | 135 | EE_Error::doing_it_wrong( |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | |
156 | 156 | // check that no reserved variation names are in use and also checks if there are already existing variation names for a given template pack. The former will throw an error. The latter will remove the conflicting variation name but still register the others and will add EE_Error notice. |
157 | 157 | $validated = self::_verify_variations($identifier, $validated); |
158 | - self::$_registry[ $identifier ] = $validated; |
|
158 | + self::$_registry[$identifier] = $validated; |
|
159 | 159 | |
160 | 160 | add_filter( |
161 | 161 | 'FHEE__EE_Messages_Template_Pack__get_variations', |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | foreach ($messenger as $message_type => $variations) { |
209 | 209 | foreach ($variations as $slug => $label) { |
210 | 210 | foreach (self::$_registry as $registered_var => $reg_settings) { |
211 | - if (isset($reg_settings['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ])) { |
|
212 | - unset($validated_variations['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ]); |
|
211 | + if (isset($reg_settings['variations'][$template_pack][$messenger][$message_type][$slug])) { |
|
212 | + unset($validated_variations['variations'][$template_pack][$messenger][$message_type][$slug]); |
|
213 | 213 | EE_Error::add_error( |
214 | 214 | sprintf( |
215 | 215 | __( |
@@ -261,10 +261,10 @@ discard block |
||
261 | 261 | // so let's loop through our registered variations and then pull any details matching the request. |
262 | 262 | foreach (self::$_registry as $registry_settings) { |
263 | 263 | $base = $url ? $registry_settings['base_url'] : $registry_settings['base_path']; |
264 | - $file_string = $messenger . '_' . $type . '_' . $variation . $file_extension; |
|
264 | + $file_string = $messenger.'_'.$type.'_'.$variation.$file_extension; |
|
265 | 265 | // see if this file exists |
266 | - if (is_readable($registry_settings['base_path'] . $file_string)) { |
|
267 | - return $base . $file_string; |
|
266 | + if (is_readable($registry_settings['base_path'].$file_string)) { |
|
267 | + return $base.$file_string; |
|
268 | 268 | } |
269 | 269 | } |
270 | 270 | |
@@ -305,16 +305,16 @@ discard block |
||
305 | 305 | return array_merge($registry_settings['variations'], $variations); |
306 | 306 | } |
307 | 307 | if (empty($message_type)) { |
308 | - if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ])) { |
|
308 | + if ( ! empty($registry_settings['variations'][$template_pack->dbref][$messenger])) { |
|
309 | 309 | return array_merge( |
310 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ], |
|
310 | + $registry_settings['variations'][$template_pack->dbref][$messenger], |
|
311 | 311 | $variations |
312 | 312 | ); |
313 | 313 | } |
314 | 314 | } else { |
315 | - if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ])) { |
|
315 | + if ( ! empty($registry_settings['variations'][$template_pack->dbref][$messenger][$message_type])) { |
|
316 | 316 | return array_merge( |
317 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ], |
|
317 | + $registry_settings['variations'][$template_pack->dbref][$messenger][$message_type], |
|
318 | 318 | $variations |
319 | 319 | ); |
320 | 320 | } |
@@ -335,6 +335,6 @@ discard block |
||
335 | 335 | */ |
336 | 336 | public static function deregister($identifier = '') |
337 | 337 | { |
338 | - unset(self::$_registry[ $identifier ]); |
|
338 | + unset(self::$_registry[$identifier]); |
|
339 | 339 | } |
340 | 340 | } |
@@ -13,55 +13,55 @@ |
||
13 | 13 | class EE_Register_Privacy_Policy implements EEI_Plugin_API |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * FQCN for all privacy policy generators |
|
18 | - * |
|
19 | - * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
20 | - */ |
|
21 | - protected static $privacy_policies = array(); |
|
16 | + /** |
|
17 | + * FQCN for all privacy policy generators |
|
18 | + * |
|
19 | + * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
20 | + */ |
|
21 | + protected static $privacy_policies = array(); |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * @param string $identifier |
|
26 | - * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
27 | - * OR fully qualified class names of privacy policies |
|
28 | - */ |
|
29 | - public static function register($identifier = '', array $setup_args = []) |
|
30 | - { |
|
31 | - self::$privacy_policies[ $identifier ] = $setup_args; |
|
32 | - // add to list of modules to be registered |
|
33 | - add_filter( |
|
34 | - 'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies', |
|
35 | - array('EE_Register_Privacy_Policy', 'addPrivacyPolicies') |
|
36 | - ); |
|
37 | - } |
|
24 | + /** |
|
25 | + * @param string $identifier |
|
26 | + * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
27 | + * OR fully qualified class names of privacy policies |
|
28 | + */ |
|
29 | + public static function register($identifier = '', array $setup_args = []) |
|
30 | + { |
|
31 | + self::$privacy_policies[ $identifier ] = $setup_args; |
|
32 | + // add to list of modules to be registered |
|
33 | + add_filter( |
|
34 | + 'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies', |
|
35 | + array('EE_Register_Privacy_Policy', 'addPrivacyPolicies') |
|
36 | + ); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * @param string $identifier |
|
42 | - */ |
|
43 | - public static function deregister($identifier = '') |
|
44 | - { |
|
45 | - unset(self::$privacy_policies[ $identifier ]); |
|
46 | - } |
|
40 | + /** |
|
41 | + * @param string $identifier |
|
42 | + */ |
|
43 | + public static function deregister($identifier = '') |
|
44 | + { |
|
45 | + unset(self::$privacy_policies[ $identifier ]); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * Adds our privacy policy generators registered by add-ons |
|
51 | - * |
|
52 | - * @param string[] $privacy_policies |
|
53 | - * @return string[] |
|
54 | - */ |
|
55 | - public static function addPrivacyPolicies(array $privacy_policies) |
|
56 | - { |
|
57 | - foreach (self::$privacy_policies as $privacy_policies_per_addon) { |
|
58 | - $privacy_policies = array_merge( |
|
59 | - $privacy_policies, |
|
60 | - $privacy_policies_per_addon |
|
61 | - ); |
|
62 | - } |
|
63 | - return $privacy_policies; |
|
64 | - } |
|
49 | + /** |
|
50 | + * Adds our privacy policy generators registered by add-ons |
|
51 | + * |
|
52 | + * @param string[] $privacy_policies |
|
53 | + * @return string[] |
|
54 | + */ |
|
55 | + public static function addPrivacyPolicies(array $privacy_policies) |
|
56 | + { |
|
57 | + foreach (self::$privacy_policies as $privacy_policies_per_addon) { |
|
58 | + $privacy_policies = array_merge( |
|
59 | + $privacy_policies, |
|
60 | + $privacy_policies_per_addon |
|
61 | + ); |
|
62 | + } |
|
63 | + return $privacy_policies; |
|
64 | + } |
|
65 | 65 | } |
66 | 66 | // End of file EE_Register_Privacy_Policy.lib.php |
67 | 67 | // Location: ${NAMESPACE}/EE_Register_Privacy_Policy.lib.php |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public static function register($identifier = '', array $setup_args = []) |
30 | 30 | { |
31 | - self::$privacy_policies[ $identifier ] = $setup_args; |
|
31 | + self::$privacy_policies[$identifier] = $setup_args; |
|
32 | 32 | // add to list of modules to be registered |
33 | 33 | add_filter( |
34 | 34 | 'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies', |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public static function deregister($identifier = '') |
44 | 44 | { |
45 | - unset(self::$privacy_policies[ $identifier ]); |
|
45 | + unset(self::$privacy_policies[$identifier]); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 |
@@ -19,162 +19,162 @@ |
||
19 | 19 | class EE_Register_Payment_Method implements EEI_Plugin_API |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * Holds values for registered payment methods |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected static $_settings = []; |
|
22 | + /** |
|
23 | + * Holds values for registered payment methods |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected static $_settings = []; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * Method for registering new EE_PMT_Base children |
|
32 | - * |
|
33 | - * @param string $identifier a unique identifier for this set of modules Required. |
|
34 | - * @param array $setup_args an array of arguments provided for registering modules Required.{ |
|
35 | - * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class |
|
36 | - * (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains |
|
37 | - * the files EE_PMT_Payomatic.pm.php) |
|
38 | - * } |
|
39 | - * @return void |
|
40 | - * @throws EE_Error |
|
41 | - * @type array payment_method_paths an array of full server paths to folders containing any EE_PMT_Base |
|
42 | - * children, or to the EED_Module files themselves |
|
43 | - * @throws InvalidDataTypeException |
|
44 | - * @throws DomainException |
|
45 | - * @throws InvalidArgumentException |
|
46 | - * @throws InvalidInterfaceException |
|
47 | - * @throws InvalidDataTypeException |
|
48 | - * @since 4.5.0 |
|
49 | - */ |
|
50 | - public static function register($identifier = '', array $setup_args = []) |
|
51 | - { |
|
52 | - // required fields MUST be present, so let's make sure they are. |
|
53 | - if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) { |
|
54 | - throw new EE_Error( |
|
55 | - esc_html__( |
|
56 | - 'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)', |
|
57 | - 'event_espresso' |
|
58 | - ) |
|
59 | - ); |
|
60 | - } |
|
61 | - // make sure we don't register twice |
|
62 | - if (isset(self::$_settings[ $identifier ])) { |
|
63 | - return; |
|
64 | - } |
|
65 | - // make sure this was called in the right place! |
|
66 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
67 | - || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
68 | - ) { |
|
69 | - EE_Error::doing_it_wrong( |
|
70 | - __METHOD__, |
|
71 | - esc_html__( |
|
72 | - 'An attempt to register modules has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.', |
|
73 | - 'event_espresso' |
|
74 | - ), |
|
75 | - '4.3.0' |
|
76 | - ); |
|
77 | - } |
|
78 | - // setup $_settings array from incoming values. |
|
79 | - self::$_settings[ $identifier ] = [ |
|
80 | - // array of full server paths to any EE_PMT_Base children used |
|
81 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
82 | - ? (array) $setup_args['payment_method_paths'] |
|
83 | - : [], |
|
84 | - ]; |
|
85 | - // add to list of modules to be registered |
|
86 | - add_filter( |
|
87 | - 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
88 | - ['EE_Register_Payment_Method', 'add_payment_methods'] |
|
89 | - ); |
|
90 | - // If EE_Payment_Method_Manager::register_payment_methods has already been called, |
|
91 | - // then we need to add our caps for this payment method manually |
|
92 | - if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) { |
|
93 | - $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
94 | - // register payment methods directly |
|
95 | - foreach (self::$_settings[ $identifier ]['payment_method_paths'] as $payment_method_path) { |
|
96 | - $payment_method_manager->register_payment_method($payment_method_path); |
|
97 | - } |
|
98 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
99 | - $capabilities->addCaps( |
|
100 | - self::getPaymentMethodCapabilities(self::$_settings[ $identifier ]) |
|
101 | - ); |
|
102 | - } |
|
103 | - } |
|
30 | + /** |
|
31 | + * Method for registering new EE_PMT_Base children |
|
32 | + * |
|
33 | + * @param string $identifier a unique identifier for this set of modules Required. |
|
34 | + * @param array $setup_args an array of arguments provided for registering modules Required.{ |
|
35 | + * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class |
|
36 | + * (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains |
|
37 | + * the files EE_PMT_Payomatic.pm.php) |
|
38 | + * } |
|
39 | + * @return void |
|
40 | + * @throws EE_Error |
|
41 | + * @type array payment_method_paths an array of full server paths to folders containing any EE_PMT_Base |
|
42 | + * children, or to the EED_Module files themselves |
|
43 | + * @throws InvalidDataTypeException |
|
44 | + * @throws DomainException |
|
45 | + * @throws InvalidArgumentException |
|
46 | + * @throws InvalidInterfaceException |
|
47 | + * @throws InvalidDataTypeException |
|
48 | + * @since 4.5.0 |
|
49 | + */ |
|
50 | + public static function register($identifier = '', array $setup_args = []) |
|
51 | + { |
|
52 | + // required fields MUST be present, so let's make sure they are. |
|
53 | + if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) { |
|
54 | + throw new EE_Error( |
|
55 | + esc_html__( |
|
56 | + 'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)', |
|
57 | + 'event_espresso' |
|
58 | + ) |
|
59 | + ); |
|
60 | + } |
|
61 | + // make sure we don't register twice |
|
62 | + if (isset(self::$_settings[ $identifier ])) { |
|
63 | + return; |
|
64 | + } |
|
65 | + // make sure this was called in the right place! |
|
66 | + if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
67 | + || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
68 | + ) { |
|
69 | + EE_Error::doing_it_wrong( |
|
70 | + __METHOD__, |
|
71 | + esc_html__( |
|
72 | + 'An attempt to register modules has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.', |
|
73 | + 'event_espresso' |
|
74 | + ), |
|
75 | + '4.3.0' |
|
76 | + ); |
|
77 | + } |
|
78 | + // setup $_settings array from incoming values. |
|
79 | + self::$_settings[ $identifier ] = [ |
|
80 | + // array of full server paths to any EE_PMT_Base children used |
|
81 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
82 | + ? (array) $setup_args['payment_method_paths'] |
|
83 | + : [], |
|
84 | + ]; |
|
85 | + // add to list of modules to be registered |
|
86 | + add_filter( |
|
87 | + 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
88 | + ['EE_Register_Payment_Method', 'add_payment_methods'] |
|
89 | + ); |
|
90 | + // If EE_Payment_Method_Manager::register_payment_methods has already been called, |
|
91 | + // then we need to add our caps for this payment method manually |
|
92 | + if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) { |
|
93 | + $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
94 | + // register payment methods directly |
|
95 | + foreach (self::$_settings[ $identifier ]['payment_method_paths'] as $payment_method_path) { |
|
96 | + $payment_method_manager->register_payment_method($payment_method_path); |
|
97 | + } |
|
98 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
99 | + $capabilities->addCaps( |
|
100 | + self::getPaymentMethodCapabilities(self::$_settings[ $identifier ]) |
|
101 | + ); |
|
102 | + } |
|
103 | + } |
|
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * Filters the list of payment methods to add ours. |
|
108 | - * and they're just full filepaths to FOLDERS containing a payment method class file. Eg. |
|
109 | - * |
|
110 | - * @param array $payment_method_folders array of paths to all payment methods that require registering |
|
111 | - * @return array |
|
112 | - */ |
|
113 | - public static function add_payment_methods(array $payment_method_folders) |
|
114 | - { |
|
115 | - foreach (self::$_settings as $settings) { |
|
116 | - foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
117 | - $payment_method_folders[] = $payment_method_path; |
|
118 | - } |
|
119 | - } |
|
120 | - return $payment_method_folders; |
|
121 | - } |
|
106 | + /** |
|
107 | + * Filters the list of payment methods to add ours. |
|
108 | + * and they're just full filepaths to FOLDERS containing a payment method class file. Eg. |
|
109 | + * |
|
110 | + * @param array $payment_method_folders array of paths to all payment methods that require registering |
|
111 | + * @return array |
|
112 | + */ |
|
113 | + public static function add_payment_methods(array $payment_method_folders) |
|
114 | + { |
|
115 | + foreach (self::$_settings as $settings) { |
|
116 | + foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
117 | + $payment_method_folders[] = $payment_method_path; |
|
118 | + } |
|
119 | + } |
|
120 | + return $payment_method_folders; |
|
121 | + } |
|
122 | 122 | |
123 | 123 | |
124 | - /** |
|
125 | - * This deregisters a module that was previously registered with a specific $identifier. |
|
126 | - * |
|
127 | - * @param string $identifier the name for the module that was previously registered |
|
128 | - * @return void |
|
129 | - * @throws DomainException |
|
130 | - * @throws InvalidArgumentException |
|
131 | - * @throws InvalidInterfaceException |
|
132 | - * @throws InvalidDataTypeException |
|
133 | - * @since 4.3.0 |
|
134 | - */ |
|
135 | - public static function deregister($identifier = '') |
|
136 | - { |
|
137 | - if (isset(self::$_settings[ $identifier ])) { |
|
138 | - // set action for just this module id to delay deregistration until core is loaded and ready. |
|
139 | - $module_settings = self::$_settings[ $identifier ]; |
|
140 | - unset(self::$_settings[ $identifier ]); |
|
141 | - add_action( |
|
142 | - 'AHEE__EE_System__core_loaded_and_ready', |
|
143 | - function () use ($module_settings) { |
|
144 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
145 | - $capabilities->removeCaps( |
|
146 | - EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings) |
|
147 | - ); |
|
148 | - } |
|
149 | - ); |
|
150 | - } |
|
151 | - } |
|
124 | + /** |
|
125 | + * This deregisters a module that was previously registered with a specific $identifier. |
|
126 | + * |
|
127 | + * @param string $identifier the name for the module that was previously registered |
|
128 | + * @return void |
|
129 | + * @throws DomainException |
|
130 | + * @throws InvalidArgumentException |
|
131 | + * @throws InvalidInterfaceException |
|
132 | + * @throws InvalidDataTypeException |
|
133 | + * @since 4.3.0 |
|
134 | + */ |
|
135 | + public static function deregister($identifier = '') |
|
136 | + { |
|
137 | + if (isset(self::$_settings[ $identifier ])) { |
|
138 | + // set action for just this module id to delay deregistration until core is loaded and ready. |
|
139 | + $module_settings = self::$_settings[ $identifier ]; |
|
140 | + unset(self::$_settings[ $identifier ]); |
|
141 | + add_action( |
|
142 | + 'AHEE__EE_System__core_loaded_and_ready', |
|
143 | + function () use ($module_settings) { |
|
144 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
145 | + $capabilities->removeCaps( |
|
146 | + EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings) |
|
147 | + ); |
|
148 | + } |
|
149 | + ); |
|
150 | + } |
|
151 | + } |
|
152 | 152 | |
153 | 153 | |
154 | - /** |
|
155 | - * returns an array of the caps that get added when a Payment Method is registered |
|
156 | - * |
|
157 | - * @param array $settings |
|
158 | - * @return array |
|
159 | - * @throws DomainException |
|
160 | - * @throws InvalidArgumentException |
|
161 | - * @throws InvalidInterfaceException |
|
162 | - * @throws InvalidDataTypeException |
|
163 | - * @access private Developers do NOT use this method. It's only public for PHP5.3 closure support (see deregister) |
|
164 | - * When we drop support for PHP5.3 this will be made private again. You have been warned. |
|
165 | - */ |
|
166 | - public static function getPaymentMethodCapabilities(array $settings) |
|
167 | - { |
|
168 | - $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
169 | - $payment_method_caps = ['administrator' => []]; |
|
170 | - if (isset($settings['payment_method_paths'])) { |
|
171 | - foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
172 | - $payment_method_caps = $payment_method_manager->addPaymentMethodCap( |
|
173 | - strtolower(basename($payment_method_path)), |
|
174 | - $payment_method_caps |
|
175 | - ); |
|
176 | - } |
|
177 | - } |
|
178 | - return $payment_method_caps; |
|
179 | - } |
|
154 | + /** |
|
155 | + * returns an array of the caps that get added when a Payment Method is registered |
|
156 | + * |
|
157 | + * @param array $settings |
|
158 | + * @return array |
|
159 | + * @throws DomainException |
|
160 | + * @throws InvalidArgumentException |
|
161 | + * @throws InvalidInterfaceException |
|
162 | + * @throws InvalidDataTypeException |
|
163 | + * @access private Developers do NOT use this method. It's only public for PHP5.3 closure support (see deregister) |
|
164 | + * When we drop support for PHP5.3 this will be made private again. You have been warned. |
|
165 | + */ |
|
166 | + public static function getPaymentMethodCapabilities(array $settings) |
|
167 | + { |
|
168 | + $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
169 | + $payment_method_caps = ['administrator' => []]; |
|
170 | + if (isset($settings['payment_method_paths'])) { |
|
171 | + foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
172 | + $payment_method_caps = $payment_method_manager->addPaymentMethodCap( |
|
173 | + strtolower(basename($payment_method_path)), |
|
174 | + $payment_method_caps |
|
175 | + ); |
|
176 | + } |
|
177 | + } |
|
178 | + return $payment_method_caps; |
|
179 | + } |
|
180 | 180 | } |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | ); |
60 | 60 | } |
61 | 61 | // make sure we don't register twice |
62 | - if (isset(self::$_settings[ $identifier ])) { |
|
62 | + if (isset(self::$_settings[$identifier])) { |
|
63 | 63 | return; |
64 | 64 | } |
65 | 65 | // make sure this was called in the right place! |
66 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
66 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') |
|
67 | 67 | || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
68 | 68 | ) { |
69 | 69 | EE_Error::doing_it_wrong( |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | ); |
77 | 77 | } |
78 | 78 | // setup $_settings array from incoming values. |
79 | - self::$_settings[ $identifier ] = [ |
|
79 | + self::$_settings[$identifier] = [ |
|
80 | 80 | // array of full server paths to any EE_PMT_Base children used |
81 | 81 | 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
82 | 82 | ? (array) $setup_args['payment_method_paths'] |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) { |
93 | 93 | $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
94 | 94 | // register payment methods directly |
95 | - foreach (self::$_settings[ $identifier ]['payment_method_paths'] as $payment_method_path) { |
|
95 | + foreach (self::$_settings[$identifier]['payment_method_paths'] as $payment_method_path) { |
|
96 | 96 | $payment_method_manager->register_payment_method($payment_method_path); |
97 | 97 | } |
98 | 98 | $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
99 | 99 | $capabilities->addCaps( |
100 | - self::getPaymentMethodCapabilities(self::$_settings[ $identifier ]) |
|
100 | + self::getPaymentMethodCapabilities(self::$_settings[$identifier]) |
|
101 | 101 | ); |
102 | 102 | } |
103 | 103 | } |
@@ -134,13 +134,13 @@ discard block |
||
134 | 134 | */ |
135 | 135 | public static function deregister($identifier = '') |
136 | 136 | { |
137 | - if (isset(self::$_settings[ $identifier ])) { |
|
137 | + if (isset(self::$_settings[$identifier])) { |
|
138 | 138 | // set action for just this module id to delay deregistration until core is loaded and ready. |
139 | - $module_settings = self::$_settings[ $identifier ]; |
|
140 | - unset(self::$_settings[ $identifier ]); |
|
139 | + $module_settings = self::$_settings[$identifier]; |
|
140 | + unset(self::$_settings[$identifier]); |
|
141 | 141 | add_action( |
142 | 142 | 'AHEE__EE_System__core_loaded_and_ready', |
143 | - function () use ($module_settings) { |
|
143 | + function() use ($module_settings) { |
|
144 | 144 | $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
145 | 145 | $capabilities->removeCaps( |
146 | 146 | EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings) |
@@ -12,131 +12,131 @@ |
||
12 | 12 | class EE_Register_Model_Extensions implements EEI_Plugin_API |
13 | 13 | { |
14 | 14 | |
15 | - protected static $_registry; |
|
15 | + protected static $_registry; |
|
16 | 16 | |
17 | - protected static $_extensions = []; |
|
17 | + protected static $_extensions = []; |
|
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * register method for setting up model extensions |
|
22 | - * |
|
23 | - * @param string $identifier unique id for the extensions being setup |
|
24 | - * @param array $setup_args { |
|
25 | - * @return void |
|
26 | - * @throws EE_Error |
|
27 | - * @type array $model_extension_paths array of folders containing DB model extensions, where each file follows |
|
28 | - * the models naming convention, which is: |
|
29 | - * EEME_{your_plugin_slug}_model_name_extended}.model_ext.php. |
|
30 | - * Where {your_plugin_slug} is really anything you want (but something having |
|
31 | - * to do with your addon, like 'Calendar' or '3D_View') and |
|
32 | - * model_name_extended} is the model extended. |
|
33 | - * The class contained in teh file should extend |
|
34 | - * EEME_Base_{model_name_extended}.model_ext.php. |
|
35 | - * Where {your_plugin_slug} is really anything you want (but something |
|
36 | - * having to do with your addon, like 'Calendar' or '3D_View') and |
|
37 | - * {model_name_extended} is the model extended. The class contained in teh |
|
38 | - * file should extend EEME_Base |
|
39 | - * @type array $class_extension_paths array of folders containing DB class extensions, where each file follows |
|
40 | - * the model class extension naming convention, which is: |
|
41 | - * EEE_{your_plugin_slug}_model_name_extended}.class_ext.php. |
|
42 | - * Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc, |
|
43 | - * and model_name_extended} is the name of the model extended, eg |
|
44 | - * 'Attendee','Event',etc. |
|
45 | - * The class contained in the file should extend EEE_Base_Class |
|
46 | - * ._{model_name_extended}.class_ext.php. |
|
47 | - * Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc, |
|
48 | - * and {model_name_extended} is the name of the model extended, eg |
|
49 | - * 'Attendee','Event',etc. The class contained in the file should extend |
|
50 | - * EEE_Base_Class. |
|
51 | - * } |
|
52 | - * |
|
53 | - */ |
|
54 | - public static function register($identifier = '', array $setup_args = []) |
|
55 | - { |
|
56 | - // required fields MUST be present, so let's make sure they are. |
|
57 | - if (empty($identifier) |
|
58 | - || ! is_array($setup_args) |
|
59 | - || (empty($setup_args['model_extension_paths']) && empty($setup_args['class_extension_paths'])) |
|
60 | - ) { |
|
61 | - throw new EE_Error( |
|
62 | - __( |
|
63 | - 'In order to register Model extensions with EE_Register_Model_Extensions::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_extension_paths" (an array of full server paths to folders that contain model extensions), and "class_extension_paths" (an array of full server paths to folders that contain class extensions)', |
|
64 | - 'event_espresso' |
|
65 | - ) |
|
66 | - ); |
|
67 | - } |
|
20 | + /** |
|
21 | + * register method for setting up model extensions |
|
22 | + * |
|
23 | + * @param string $identifier unique id for the extensions being setup |
|
24 | + * @param array $setup_args { |
|
25 | + * @return void |
|
26 | + * @throws EE_Error |
|
27 | + * @type array $model_extension_paths array of folders containing DB model extensions, where each file follows |
|
28 | + * the models naming convention, which is: |
|
29 | + * EEME_{your_plugin_slug}_model_name_extended}.model_ext.php. |
|
30 | + * Where {your_plugin_slug} is really anything you want (but something having |
|
31 | + * to do with your addon, like 'Calendar' or '3D_View') and |
|
32 | + * model_name_extended} is the model extended. |
|
33 | + * The class contained in teh file should extend |
|
34 | + * EEME_Base_{model_name_extended}.model_ext.php. |
|
35 | + * Where {your_plugin_slug} is really anything you want (but something |
|
36 | + * having to do with your addon, like 'Calendar' or '3D_View') and |
|
37 | + * {model_name_extended} is the model extended. The class contained in teh |
|
38 | + * file should extend EEME_Base |
|
39 | + * @type array $class_extension_paths array of folders containing DB class extensions, where each file follows |
|
40 | + * the model class extension naming convention, which is: |
|
41 | + * EEE_{your_plugin_slug}_model_name_extended}.class_ext.php. |
|
42 | + * Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc, |
|
43 | + * and model_name_extended} is the name of the model extended, eg |
|
44 | + * 'Attendee','Event',etc. |
|
45 | + * The class contained in the file should extend EEE_Base_Class |
|
46 | + * ._{model_name_extended}.class_ext.php. |
|
47 | + * Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc, |
|
48 | + * and {model_name_extended} is the name of the model extended, eg |
|
49 | + * 'Attendee','Event',etc. The class contained in the file should extend |
|
50 | + * EEE_Base_Class. |
|
51 | + * } |
|
52 | + * |
|
53 | + */ |
|
54 | + public static function register($identifier = '', array $setup_args = []) |
|
55 | + { |
|
56 | + // required fields MUST be present, so let's make sure they are. |
|
57 | + if (empty($identifier) |
|
58 | + || ! is_array($setup_args) |
|
59 | + || (empty($setup_args['model_extension_paths']) && empty($setup_args['class_extension_paths'])) |
|
60 | + ) { |
|
61 | + throw new EE_Error( |
|
62 | + __( |
|
63 | + 'In order to register Model extensions with EE_Register_Model_Extensions::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_extension_paths" (an array of full server paths to folders that contain model extensions), and "class_extension_paths" (an array of full server paths to folders that contain class extensions)', |
|
64 | + 'event_espresso' |
|
65 | + ) |
|
66 | + ); |
|
67 | + } |
|
68 | 68 | |
69 | - // make sure we don't register twice |
|
70 | - if (isset(self::$_registry[ $identifier ])) { |
|
71 | - return; |
|
72 | - } |
|
73 | - // check correct loading |
|
74 | - if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) { |
|
75 | - EE_Error::doing_it_wrong( |
|
76 | - __METHOD__, |
|
77 | - sprintf( |
|
78 | - __( |
|
79 | - 'An attempt was made to register "%1$s" as a Model extension has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.%2$s Hook Status: %2$s "AHEE__EE_System__load_espresso_addons" : %3$s %2$s "AHEE__EE_Admin__loaded" : %4$s%2$s', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - $identifier, |
|
83 | - '<br />', |
|
84 | - did_action('AHEE__EE_System__load_espresso_addons') ? 'action done' : 'action NOT done', |
|
85 | - did_action('AHEE__EE_Admin__loaded') ? 'action done' : 'action NOT done' |
|
86 | - ), |
|
87 | - '4.3' |
|
88 | - ); |
|
89 | - } |
|
69 | + // make sure we don't register twice |
|
70 | + if (isset(self::$_registry[ $identifier ])) { |
|
71 | + return; |
|
72 | + } |
|
73 | + // check correct loading |
|
74 | + if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) { |
|
75 | + EE_Error::doing_it_wrong( |
|
76 | + __METHOD__, |
|
77 | + sprintf( |
|
78 | + __( |
|
79 | + 'An attempt was made to register "%1$s" as a Model extension has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.%2$s Hook Status: %2$s "AHEE__EE_System__load_espresso_addons" : %3$s %2$s "AHEE__EE_Admin__loaded" : %4$s%2$s', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + $identifier, |
|
83 | + '<br />', |
|
84 | + did_action('AHEE__EE_System__load_espresso_addons') ? 'action done' : 'action NOT done', |
|
85 | + did_action('AHEE__EE_Admin__loaded') ? 'action done' : 'action NOT done' |
|
86 | + ), |
|
87 | + '4.3' |
|
88 | + ); |
|
89 | + } |
|
90 | 90 | |
91 | - self::$_registry[ $identifier ] = $setup_args; |
|
92 | - self::$_extensions[ $identifier ] = []; |
|
91 | + self::$_registry[ $identifier ] = $setup_args; |
|
92 | + self::$_extensions[ $identifier ] = []; |
|
93 | 93 | |
94 | - if (isset($setup_args['model_extension_paths'])) { |
|
95 | - require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php'); |
|
96 | - $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_extension_paths']); |
|
97 | - // remove all files that are not PHP |
|
98 | - foreach ($class_to_filepath_map as $class => $path) { |
|
99 | - if (substr($path, strlen($path) - 3) !== 'php') { |
|
100 | - unset($class_to_filepath_map[ $class ]); |
|
101 | - } |
|
102 | - } |
|
103 | - EEH_Autoloader::register_autoloader($class_to_filepath_map); |
|
104 | - foreach (array_keys($class_to_filepath_map) as $classname) { |
|
105 | - self::$_extensions[ $identifier ]['models'][ $classname ] = new $classname; |
|
106 | - } |
|
107 | - unset($setup_args['model_extension_paths']); |
|
108 | - } |
|
109 | - if (isset($setup_args['class_extension_paths'])) { |
|
110 | - require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php'); |
|
111 | - $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_extension_paths']); |
|
112 | - EEH_Autoloader::register_autoloader($class_to_filepath_map); |
|
113 | - foreach (array_keys($class_to_filepath_map) as $classname) { |
|
114 | - self::$_extensions[ $identifier ]['classes'][ $classname ] = new $classname; |
|
115 | - } |
|
116 | - unset($setup_args['class_extension_paths']); |
|
117 | - } |
|
118 | - foreach ($setup_args as $unknown_key => $unknown_config) { |
|
119 | - throw new EE_Error( |
|
120 | - sprintf(__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key) |
|
121 | - ); |
|
122 | - } |
|
123 | - } |
|
94 | + if (isset($setup_args['model_extension_paths'])) { |
|
95 | + require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php'); |
|
96 | + $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_extension_paths']); |
|
97 | + // remove all files that are not PHP |
|
98 | + foreach ($class_to_filepath_map as $class => $path) { |
|
99 | + if (substr($path, strlen($path) - 3) !== 'php') { |
|
100 | + unset($class_to_filepath_map[ $class ]); |
|
101 | + } |
|
102 | + } |
|
103 | + EEH_Autoloader::register_autoloader($class_to_filepath_map); |
|
104 | + foreach (array_keys($class_to_filepath_map) as $classname) { |
|
105 | + self::$_extensions[ $identifier ]['models'][ $classname ] = new $classname; |
|
106 | + } |
|
107 | + unset($setup_args['model_extension_paths']); |
|
108 | + } |
|
109 | + if (isset($setup_args['class_extension_paths'])) { |
|
110 | + require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php'); |
|
111 | + $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_extension_paths']); |
|
112 | + EEH_Autoloader::register_autoloader($class_to_filepath_map); |
|
113 | + foreach (array_keys($class_to_filepath_map) as $classname) { |
|
114 | + self::$_extensions[ $identifier ]['classes'][ $classname ] = new $classname; |
|
115 | + } |
|
116 | + unset($setup_args['class_extension_paths']); |
|
117 | + } |
|
118 | + foreach ($setup_args as $unknown_key => $unknown_config) { |
|
119 | + throw new EE_Error( |
|
120 | + sprintf(__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key) |
|
121 | + ); |
|
122 | + } |
|
123 | + } |
|
124 | 124 | |
125 | 125 | |
126 | - /** |
|
127 | - * deregister |
|
128 | - * |
|
129 | - * @param string $identifier |
|
130 | - */ |
|
131 | - public static function deregister($identifier = '') |
|
132 | - { |
|
133 | - if (isset(self::$_registry[ $identifier ])) { |
|
134 | - unset(self::$_registry[ $identifier ]); |
|
135 | - foreach (self::$_extensions[ $identifier ] as $extension_of_type) { |
|
136 | - foreach ($extension_of_type as $extension) { |
|
137 | - $extension->deregister(); |
|
138 | - } |
|
139 | - } |
|
140 | - } |
|
141 | - } |
|
126 | + /** |
|
127 | + * deregister |
|
128 | + * |
|
129 | + * @param string $identifier |
|
130 | + */ |
|
131 | + public static function deregister($identifier = '') |
|
132 | + { |
|
133 | + if (isset(self::$_registry[ $identifier ])) { |
|
134 | + unset(self::$_registry[ $identifier ]); |
|
135 | + foreach (self::$_extensions[ $identifier ] as $extension_of_type) { |
|
136 | + foreach ($extension_of_type as $extension) { |
|
137 | + $extension->deregister(); |
|
138 | + } |
|
139 | + } |
|
140 | + } |
|
141 | + } |
|
142 | 142 | } |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | // make sure we don't register twice |
70 | - if (isset(self::$_registry[ $identifier ])) { |
|
70 | + if (isset(self::$_registry[$identifier])) { |
|
71 | 71 | return; |
72 | 72 | } |
73 | 73 | // check correct loading |
74 | - if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) { |
|
74 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) { |
|
75 | 75 | EE_Error::doing_it_wrong( |
76 | 76 | __METHOD__, |
77 | 77 | sprintf( |
@@ -88,30 +88,30 @@ discard block |
||
88 | 88 | ); |
89 | 89 | } |
90 | 90 | |
91 | - self::$_registry[ $identifier ] = $setup_args; |
|
92 | - self::$_extensions[ $identifier ] = []; |
|
91 | + self::$_registry[$identifier] = $setup_args; |
|
92 | + self::$_extensions[$identifier] = []; |
|
93 | 93 | |
94 | 94 | if (isset($setup_args['model_extension_paths'])) { |
95 | - require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php'); |
|
95 | + require_once(EE_LIBRARIES.'plugin_api/db/EEME_Base.lib.php'); |
|
96 | 96 | $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_extension_paths']); |
97 | 97 | // remove all files that are not PHP |
98 | 98 | foreach ($class_to_filepath_map as $class => $path) { |
99 | 99 | if (substr($path, strlen($path) - 3) !== 'php') { |
100 | - unset($class_to_filepath_map[ $class ]); |
|
100 | + unset($class_to_filepath_map[$class]); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | EEH_Autoloader::register_autoloader($class_to_filepath_map); |
104 | 104 | foreach (array_keys($class_to_filepath_map) as $classname) { |
105 | - self::$_extensions[ $identifier ]['models'][ $classname ] = new $classname; |
|
105 | + self::$_extensions[$identifier]['models'][$classname] = new $classname; |
|
106 | 106 | } |
107 | 107 | unset($setup_args['model_extension_paths']); |
108 | 108 | } |
109 | 109 | if (isset($setup_args['class_extension_paths'])) { |
110 | - require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php'); |
|
110 | + require_once(EE_LIBRARIES.'plugin_api/db/EEE_Base_Class.lib.php'); |
|
111 | 111 | $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_extension_paths']); |
112 | 112 | EEH_Autoloader::register_autoloader($class_to_filepath_map); |
113 | 113 | foreach (array_keys($class_to_filepath_map) as $classname) { |
114 | - self::$_extensions[ $identifier ]['classes'][ $classname ] = new $classname; |
|
114 | + self::$_extensions[$identifier]['classes'][$classname] = new $classname; |
|
115 | 115 | } |
116 | 116 | unset($setup_args['class_extension_paths']); |
117 | 117 | } |
@@ -130,9 +130,9 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public static function deregister($identifier = '') |
132 | 132 | { |
133 | - if (isset(self::$_registry[ $identifier ])) { |
|
134 | - unset(self::$_registry[ $identifier ]); |
|
135 | - foreach (self::$_extensions[ $identifier ] as $extension_of_type) { |
|
133 | + if (isset(self::$_registry[$identifier])) { |
|
134 | + unset(self::$_registry[$identifier]); |
|
135 | + foreach (self::$_extensions[$identifier] as $extension_of_type) { |
|
136 | 136 | foreach ($extension_of_type as $extension) { |
137 | 137 | $extension->deregister(); |
138 | 138 | } |
@@ -20,157 +20,157 @@ |
||
20 | 20 | class EE_Register_Shortcode implements EEI_Plugin_API |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * Holds values for registered shortcodes |
|
25 | - * |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected static $_settings = []; |
|
23 | + /** |
|
24 | + * Holds values for registered shortcodes |
|
25 | + * |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected static $_settings = []; |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * Method for registering new EE_Shortcodes |
|
33 | - * |
|
34 | - * @param string $identifier a unique identifier for this set of modules Required. |
|
35 | - * @param array $setup_args an array of arguments provided for registering shortcodes Required. |
|
36 | - * @type array shortcode_paths an array of full server paths to folders containing any EES_Shortcodes |
|
37 | - * @type array shortcode_fqcns an array of fully qualified class names for any new shortcode classes to register. |
|
38 | - * Shortcode classes should extend EspressoShortcode |
|
39 | - * and be properly namespaced so they are autoloaded. |
|
40 | - * @return void |
|
41 | - * @throws EE_Error |
|
42 | - * @since 4.3.0 |
|
43 | - * @since 4.9.46.rc.025 for the new `shortcode_fqcns` array argument. |
|
44 | - */ |
|
45 | - public static function register($identifier = '', array $setup_args = []) |
|
46 | - { |
|
47 | - // required fields MUST be present, so let's make sure they are. |
|
48 | - if (empty($identifier) |
|
49 | - || ! is_array($setup_args) |
|
50 | - || ( |
|
51 | - empty($setup_args['shortcode_paths'])) |
|
52 | - && empty($setup_args['shortcode_fqcns']) |
|
53 | - ) { |
|
54 | - throw new EE_Error( |
|
55 | - esc_html__( |
|
56 | - 'In order to register Modules with EE_Register_Shortcode::register(), you must include a "shortcode_id" (a unique identifier for this set of shortcodes), and an array containing the following keys: "shortcode_paths" (an array of full server paths to folders that contain shortcodes, or to the shortcode files themselves)', |
|
57 | - 'event_espresso' |
|
58 | - ) |
|
59 | - ); |
|
60 | - } |
|
31 | + /** |
|
32 | + * Method for registering new EE_Shortcodes |
|
33 | + * |
|
34 | + * @param string $identifier a unique identifier for this set of modules Required. |
|
35 | + * @param array $setup_args an array of arguments provided for registering shortcodes Required. |
|
36 | + * @type array shortcode_paths an array of full server paths to folders containing any EES_Shortcodes |
|
37 | + * @type array shortcode_fqcns an array of fully qualified class names for any new shortcode classes to register. |
|
38 | + * Shortcode classes should extend EspressoShortcode |
|
39 | + * and be properly namespaced so they are autoloaded. |
|
40 | + * @return void |
|
41 | + * @throws EE_Error |
|
42 | + * @since 4.3.0 |
|
43 | + * @since 4.9.46.rc.025 for the new `shortcode_fqcns` array argument. |
|
44 | + */ |
|
45 | + public static function register($identifier = '', array $setup_args = []) |
|
46 | + { |
|
47 | + // required fields MUST be present, so let's make sure they are. |
|
48 | + if (empty($identifier) |
|
49 | + || ! is_array($setup_args) |
|
50 | + || ( |
|
51 | + empty($setup_args['shortcode_paths'])) |
|
52 | + && empty($setup_args['shortcode_fqcns']) |
|
53 | + ) { |
|
54 | + throw new EE_Error( |
|
55 | + esc_html__( |
|
56 | + 'In order to register Modules with EE_Register_Shortcode::register(), you must include a "shortcode_id" (a unique identifier for this set of shortcodes), and an array containing the following keys: "shortcode_paths" (an array of full server paths to folders that contain shortcodes, or to the shortcode files themselves)', |
|
57 | + 'event_espresso' |
|
58 | + ) |
|
59 | + ); |
|
60 | + } |
|
61 | 61 | |
62 | - // make sure we don't register twice |
|
63 | - if (isset(self::$_settings[ $identifier ])) { |
|
64 | - return; |
|
65 | - } |
|
62 | + // make sure we don't register twice |
|
63 | + if (isset(self::$_settings[ $identifier ])) { |
|
64 | + return; |
|
65 | + } |
|
66 | 66 | |
67 | - // make sure this was called in the right place! |
|
68 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
69 | - || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
70 | - ) { |
|
71 | - EE_Error::doing_it_wrong( |
|
72 | - __METHOD__, |
|
73 | - esc_html__( |
|
74 | - 'An attempt to register shortcodes has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register shortcodes.', |
|
75 | - 'event_espresso' |
|
76 | - ), |
|
77 | - '4.3.0' |
|
78 | - ); |
|
79 | - } |
|
80 | - // setup $_settings array from incoming values. |
|
81 | - self::$_settings[ $identifier ] = [ |
|
82 | - // array of full server paths to any EES_Shortcodes used by the shortcode |
|
83 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
84 | - ? (array) $setup_args['shortcode_paths'] |
|
85 | - : [], |
|
86 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
87 | - ? (array) $setup_args['shortcode_fqcns'] |
|
88 | - : [], |
|
89 | - ]; |
|
90 | - // add to list of shortcodes to be registered |
|
91 | - add_filter( |
|
92 | - 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
93 | - ['EE_Register_Shortcode', 'add_shortcodes'] |
|
94 | - ); |
|
67 | + // make sure this was called in the right place! |
|
68 | + if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
69 | + || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
70 | + ) { |
|
71 | + EE_Error::doing_it_wrong( |
|
72 | + __METHOD__, |
|
73 | + esc_html__( |
|
74 | + 'An attempt to register shortcodes has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register shortcodes.', |
|
75 | + 'event_espresso' |
|
76 | + ), |
|
77 | + '4.3.0' |
|
78 | + ); |
|
79 | + } |
|
80 | + // setup $_settings array from incoming values. |
|
81 | + self::$_settings[ $identifier ] = [ |
|
82 | + // array of full server paths to any EES_Shortcodes used by the shortcode |
|
83 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
84 | + ? (array) $setup_args['shortcode_paths'] |
|
85 | + : [], |
|
86 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
87 | + ? (array) $setup_args['shortcode_fqcns'] |
|
88 | + : [], |
|
89 | + ]; |
|
90 | + // add to list of shortcodes to be registered |
|
91 | + add_filter( |
|
92 | + 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
93 | + ['EE_Register_Shortcode', 'add_shortcodes'] |
|
94 | + ); |
|
95 | 95 | |
96 | - add_filter( |
|
97 | - 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
98 | - ['EE_Register_Shortcode', 'instantiateAndAddToShortcodeCollection'] |
|
99 | - ); |
|
100 | - } |
|
96 | + add_filter( |
|
97 | + 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
98 | + ['EE_Register_Shortcode', 'instantiateAndAddToShortcodeCollection'] |
|
99 | + ); |
|
100 | + } |
|
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * Filters the list of shortcodes to add ours. |
|
105 | - * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg. |
|
106 | - * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey'...) |
|
107 | - * |
|
108 | - * @param array $shortcodes_to_register array of paths to all shortcodes that require registering |
|
109 | - * @return array |
|
110 | - */ |
|
111 | - public static function add_shortcodes(array $shortcodes_to_register) |
|
112 | - { |
|
113 | - foreach (self::$_settings as $settings) { |
|
114 | - $shortcodes_to_register = array_merge($shortcodes_to_register, $settings['shortcode_paths']); |
|
115 | - } |
|
116 | - return $shortcodes_to_register; |
|
117 | - } |
|
103 | + /** |
|
104 | + * Filters the list of shortcodes to add ours. |
|
105 | + * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg. |
|
106 | + * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey'...) |
|
107 | + * |
|
108 | + * @param array $shortcodes_to_register array of paths to all shortcodes that require registering |
|
109 | + * @return array |
|
110 | + */ |
|
111 | + public static function add_shortcodes(array $shortcodes_to_register) |
|
112 | + { |
|
113 | + foreach (self::$_settings as $settings) { |
|
114 | + $shortcodes_to_register = array_merge($shortcodes_to_register, $settings['shortcode_paths']); |
|
115 | + } |
|
116 | + return $shortcodes_to_register; |
|
117 | + } |
|
118 | 118 | |
119 | 119 | |
120 | - /** |
|
121 | - * Hooks into |
|
122 | - * FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection and |
|
123 | - * registers any provided shortcode fully qualified class names. |
|
124 | - * |
|
125 | - * @param CollectionInterface $shortcodes_collection |
|
126 | - * @return CollectionInterface |
|
127 | - * @throws InvalidArgumentException |
|
128 | - * @throws InvalidClassException |
|
129 | - * @throws InvalidDataTypeException |
|
130 | - * @throws InvalidInterfaceException |
|
131 | - */ |
|
132 | - public static function instantiateAndAddToShortcodeCollection(CollectionInterface $shortcodes_collection) |
|
133 | - { |
|
134 | - foreach (self::$_settings as $settings) { |
|
135 | - if (! empty($settings['shortcode_fqcns'])) { |
|
136 | - foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) { |
|
137 | - if (! class_exists($shortcode_fqcn)) { |
|
138 | - throw new InvalidClassException( |
|
139 | - sprintf( |
|
140 | - esc_html__( |
|
141 | - 'Are you sure %s is the right fully qualified class name for the shortcode class?', |
|
142 | - 'event_espresso' |
|
143 | - ), |
|
144 | - $shortcode_fqcn |
|
145 | - ) |
|
146 | - ); |
|
147 | - } |
|
148 | - if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) { |
|
149 | - // register dependencies |
|
150 | - EE_Dependency_Map::register_dependencies( |
|
151 | - $shortcode_fqcn, |
|
152 | - [ |
|
153 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
154 | - ] |
|
155 | - ); |
|
156 | - } |
|
157 | - $shortcodes_collection->add(LoaderFactory::getLoader()->getShared($shortcode_fqcn)); |
|
158 | - } |
|
159 | - } |
|
160 | - } |
|
161 | - return $shortcodes_collection; |
|
162 | - } |
|
120 | + /** |
|
121 | + * Hooks into |
|
122 | + * FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection and |
|
123 | + * registers any provided shortcode fully qualified class names. |
|
124 | + * |
|
125 | + * @param CollectionInterface $shortcodes_collection |
|
126 | + * @return CollectionInterface |
|
127 | + * @throws InvalidArgumentException |
|
128 | + * @throws InvalidClassException |
|
129 | + * @throws InvalidDataTypeException |
|
130 | + * @throws InvalidInterfaceException |
|
131 | + */ |
|
132 | + public static function instantiateAndAddToShortcodeCollection(CollectionInterface $shortcodes_collection) |
|
133 | + { |
|
134 | + foreach (self::$_settings as $settings) { |
|
135 | + if (! empty($settings['shortcode_fqcns'])) { |
|
136 | + foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) { |
|
137 | + if (! class_exists($shortcode_fqcn)) { |
|
138 | + throw new InvalidClassException( |
|
139 | + sprintf( |
|
140 | + esc_html__( |
|
141 | + 'Are you sure %s is the right fully qualified class name for the shortcode class?', |
|
142 | + 'event_espresso' |
|
143 | + ), |
|
144 | + $shortcode_fqcn |
|
145 | + ) |
|
146 | + ); |
|
147 | + } |
|
148 | + if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) { |
|
149 | + // register dependencies |
|
150 | + EE_Dependency_Map::register_dependencies( |
|
151 | + $shortcode_fqcn, |
|
152 | + [ |
|
153 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
154 | + ] |
|
155 | + ); |
|
156 | + } |
|
157 | + $shortcodes_collection->add(LoaderFactory::getLoader()->getShared($shortcode_fqcn)); |
|
158 | + } |
|
159 | + } |
|
160 | + } |
|
161 | + return $shortcodes_collection; |
|
162 | + } |
|
163 | 163 | |
164 | 164 | |
165 | - /** |
|
166 | - * This deregisters a shortcode that was previously registered with a specific $identifier. |
|
167 | - * |
|
168 | - * @param string $identifier the name for the shortcode that was previously registered |
|
169 | - * @return void |
|
170 | - * @since 4.3.0 |
|
171 | - */ |
|
172 | - public static function deregister($identifier = '') |
|
173 | - { |
|
174 | - unset(self::$_settings[ $identifier ]); |
|
175 | - } |
|
165 | + /** |
|
166 | + * This deregisters a shortcode that was previously registered with a specific $identifier. |
|
167 | + * |
|
168 | + * @param string $identifier the name for the shortcode that was previously registered |
|
169 | + * @return void |
|
170 | + * @since 4.3.0 |
|
171 | + */ |
|
172 | + public static function deregister($identifier = '') |
|
173 | + { |
|
174 | + unset(self::$_settings[ $identifier ]); |
|
175 | + } |
|
176 | 176 | } |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | // make sure we don't register twice |
63 | - if (isset(self::$_settings[ $identifier ])) { |
|
63 | + if (isset(self::$_settings[$identifier])) { |
|
64 | 64 | return; |
65 | 65 | } |
66 | 66 | |
67 | 67 | // make sure this was called in the right place! |
68 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
68 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') |
|
69 | 69 | || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
70 | 70 | ) { |
71 | 71 | EE_Error::doing_it_wrong( |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | ); |
79 | 79 | } |
80 | 80 | // setup $_settings array from incoming values. |
81 | - self::$_settings[ $identifier ] = [ |
|
81 | + self::$_settings[$identifier] = [ |
|
82 | 82 | // array of full server paths to any EES_Shortcodes used by the shortcode |
83 | 83 | 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
84 | 84 | ? (array) $setup_args['shortcode_paths'] |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | public static function instantiateAndAddToShortcodeCollection(CollectionInterface $shortcodes_collection) |
133 | 133 | { |
134 | 134 | foreach (self::$_settings as $settings) { |
135 | - if (! empty($settings['shortcode_fqcns'])) { |
|
135 | + if ( ! empty($settings['shortcode_fqcns'])) { |
|
136 | 136 | foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) { |
137 | - if (! class_exists($shortcode_fqcn)) { |
|
137 | + if ( ! class_exists($shortcode_fqcn)) { |
|
138 | 138 | throw new InvalidClassException( |
139 | 139 | sprintf( |
140 | 140 | esc_html__( |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | ) |
146 | 146 | ); |
147 | 147 | } |
148 | - if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) { |
|
148 | + if ( ! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) { |
|
149 | 149 | // register dependencies |
150 | 150 | EE_Dependency_Map::register_dependencies( |
151 | 151 | $shortcode_fqcn, |
@@ -171,6 +171,6 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public static function deregister($identifier = '') |
173 | 173 | { |
174 | - unset(self::$_settings[ $identifier ]); |
|
174 | + unset(self::$_settings[$identifier]); |
|
175 | 175 | } |
176 | 176 | } |
@@ -18,23 +18,23 @@ |
||
18 | 18 | interface EEI_Plugin_API |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * Used to register a component with EE. |
|
23 | - * |
|
24 | - * @param string $identifier a unique name for the component being registered |
|
25 | - * @param array $setup_args an array of key value pairs of info for registering the component |
|
26 | - * @return void |
|
27 | - * @since 4.3.0 |
|
28 | - */ |
|
29 | - public static function register($identifier = '', array $setup_args = []); |
|
21 | + /** |
|
22 | + * Used to register a component with EE. |
|
23 | + * |
|
24 | + * @param string $identifier a unique name for the component being registered |
|
25 | + * @param array $setup_args an array of key value pairs of info for registering the component |
|
26 | + * @return void |
|
27 | + * @since 4.3.0 |
|
28 | + */ |
|
29 | + public static function register($identifier = '', array $setup_args = []); |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * Used to deregister a component with EE. |
|
34 | - * |
|
35 | - * @param string $identifier a unique name for the component being registered |
|
36 | - * @return void |
|
37 | - * @since 4.3.0 |
|
38 | - */ |
|
39 | - public static function deregister($identifier = ''); |
|
32 | + /** |
|
33 | + * Used to deregister a component with EE. |
|
34 | + * |
|
35 | + * @param string $identifier a unique name for the component being registered |
|
36 | + * @return void |
|
37 | + * @since 4.3.0 |
|
38 | + */ |
|
39 | + public static function deregister($identifier = ''); |
|
40 | 40 | } |
@@ -12,201 +12,201 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * Holds values for registered template pack |
|
17 | - * |
|
18 | - * @since 4.5.0 |
|
19 | - * |
|
20 | - * @var array |
|
21 | - */ |
|
22 | - protected static $_registry = []; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * Used to register a new template pack with the messages system. |
|
27 | - * |
|
28 | - * Template packs are primarily defined via class extending EE_Messages_Template_Pack and are typically used to |
|
29 | - * change entire layouts for a set of message templates. This method is used to register the new template pack and |
|
30 | - * automatically have it loaded in the appropriate places. |
|
31 | - * |
|
32 | - * This registry also verifies that there isn't already a template pack registered with the same name and if there |
|
33 | - * is then it will add an EE_Error notice. |
|
34 | - * |
|
35 | - * Note that this only handles registering the your Template Pack class with the message template pack system. |
|
36 | - * However, there is also a naming schema you must follow for templates you are providing with your template pack. |
|
37 | - * |
|
38 | - * @param string $identifier The internal reference used to refer to this template pack. Note, this is first come, |
|
39 | - * first serve. If there is already a template pack registered with this name then the |
|
40 | - * registry will assign a unique reference for it so it can still be activated (but this |
|
41 | - * makes it harder to deregister as it will be unique per load - so its best to try to |
|
42 | - * make this a unique string!) |
|
43 | - * @param array $setup_args array { |
|
44 | - * An array of required values for registering the template pack. |
|
45 | - * @type string $path The path for the new template pack class. |
|
46 | - * @type string $classname The name of the new Template Pack Class. |
|
47 | - * } |
|
48 | - * |
|
49 | - * @return void |
|
50 | - * @throws EE_Error |
|
51 | - * |
|
52 | - * @see core/libraries/messages/defaults/default/* for all the example templates the default template pack |
|
53 | - * supports. |
|
54 | - * |
|
55 | - * |
|
56 | - * @since 4.5.0 |
|
57 | - * @see EE_Messages_Template_Pack_Default for an example class |
|
58 | - */ |
|
59 | - public static function register($identifier = '', array $setup_args = []) |
|
60 | - { |
|
61 | - |
|
62 | - // check for required params |
|
63 | - if (empty($identifier) || empty($setup_args['path']) || empty($setup_args['classname'])) { |
|
64 | - throw new EE_Error( |
|
65 | - __( |
|
66 | - 'In order to register a new template pack for the EE Messages system, you must include a value to reference the template pack being registered and the setup_args must have the path for the new template pack class as well as the classname for the new Template Pack Class. ', |
|
67 | - 'event_espresso' |
|
68 | - ) |
|
69 | - ); |
|
70 | - } |
|
71 | - |
|
72 | - // make sure we don't register twice |
|
73 | - if (isset(self::$_registry[ $identifier ])) { |
|
74 | - return; |
|
75 | - } |
|
76 | - |
|
77 | - // check that incoming $identifier doesn't already exist. If it does then we'll create a unique reference for this template pack. |
|
78 | - if (isset(self::$_registry[ $identifier ])) { |
|
79 | - $identifier = uniqid() . '_' . $identifier; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - // make sure this was called in the right place! |
|
84 | - if (! did_action('EE_Brewing_Regular___messages_caf') |
|
85 | - || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
86 | - ) { |
|
87 | - EE_Error::doing_it_wrong( |
|
88 | - __METHOD__, |
|
89 | - sprintf( |
|
90 | - __( |
|
91 | - 'A EE Messages Template Pack given the reference "%s" has been attempted to be registered with the EE Messages System. It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.', |
|
92 | - 'event_espresso' |
|
93 | - ), |
|
94 | - $identifier |
|
95 | - ), |
|
96 | - '4.5.0' |
|
97 | - ); |
|
98 | - } |
|
99 | - |
|
100 | - if (self::_verify_class_not_exist($setup_args['classname'])) { |
|
101 | - self::$_registry[ $identifier ] = [ |
|
102 | - 'path' => (string) $setup_args['path'], |
|
103 | - 'classname' => (string) $setup_args['classname'], |
|
104 | - ]; |
|
105 | - } |
|
106 | - |
|
107 | - // hook into the system |
|
108 | - add_filter( |
|
109 | - 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
110 | - ['EE_Register_Messages_Template_Pack', 'set_template_pack_path'], |
|
111 | - 10 |
|
112 | - ); |
|
113 | - add_filter( |
|
114 | - 'FHEE__EED_Messages__get_template_packs__template_packs', |
|
115 | - ['EE_Register_Messages_Template_Pack', 'set_template_pack'], |
|
116 | - 10 |
|
117 | - ); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Callback for the FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter. This adds this template packs path |
|
123 | - * to the messages autoloader paths. |
|
124 | - * |
|
125 | - * @param array $paths Array of paths already registered with the messages autoloader |
|
126 | - * |
|
127 | - * @return array |
|
128 | - * @since 4.5.0 |
|
129 | - * |
|
130 | - */ |
|
131 | - public static function set_template_pack_path(array $paths) |
|
132 | - { |
|
133 | - foreach (self::$_registry as $args) { |
|
134 | - $paths[] = $args['path']; |
|
135 | - } |
|
136 | - return $paths; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * Callback for the FHEE__EED_Messages__get_template_packs__template_packs filter. This adds the instantiated, |
|
142 | - * registered template pack to the template packs array when requested by client code. |
|
143 | - * |
|
144 | - * @param EE_Messages_Template_Pack[] $template_packs |
|
145 | - * @return EE_Messages_Template_Pack[] |
|
146 | - * @since 4.5.0 |
|
147 | - * |
|
148 | - */ |
|
149 | - public static function set_template_pack(array $template_packs) |
|
150 | - { |
|
151 | - foreach (self::$_registry as $args) { |
|
152 | - // verify class_exists |
|
153 | - if (! class_exists($args['classname'])) { |
|
154 | - require_once($args['path'] . '/' . $args['classname'] . '.class.php'); |
|
155 | - } |
|
156 | - |
|
157 | - // check again! |
|
158 | - if (class_exists($args['classname'])) { |
|
159 | - $template_pack = new $args['classname']; |
|
160 | - $template_packs[ $template_pack->dbref ] = $template_pack; |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - return $template_packs; |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * This verifies that the classes for each registered template pack are unique names. |
|
170 | - * |
|
171 | - * @param string $classname The classname being checked |
|
172 | - * |
|
173 | - * @return bool |
|
174 | - */ |
|
175 | - private static function _verify_class_not_exist($classname) |
|
176 | - { |
|
177 | - // loop through the existing registry and see if the classname is already present. |
|
178 | - foreach (self::$_registry as $args) { |
|
179 | - if ($args['classname'] == $classname) { |
|
180 | - EE_Error::add_error( |
|
181 | - sprintf( |
|
182 | - __( |
|
183 | - 'The %s template pack that you just activated cannot be registered with the messages system because there is already a template pack active using the same classname. Contact the author of this template pack to let them know of the conflict. To stop seeing this message you will need to deactivate this template pack.', |
|
184 | - 'event_espresso' |
|
185 | - ), |
|
186 | - $classname |
|
187 | - ), |
|
188 | - __FILE__, |
|
189 | - __LINE__, |
|
190 | - __FUNCTION__ |
|
191 | - ); |
|
192 | - return false; |
|
193 | - } |
|
194 | - } |
|
195 | - return true; |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * This deregisters a variation set that was previously registered with the given slug. |
|
201 | - * |
|
202 | - * @param string $identifier The name for the variation set that was previously registered. |
|
203 | - * |
|
204 | - * @return void |
|
205 | - * @since 4.5.0 |
|
206 | - * |
|
207 | - */ |
|
208 | - public static function deregister($identifier = '') |
|
209 | - { |
|
210 | - unset(self::$_registry[ $identifier ]); |
|
211 | - } |
|
15 | + /** |
|
16 | + * Holds values for registered template pack |
|
17 | + * |
|
18 | + * @since 4.5.0 |
|
19 | + * |
|
20 | + * @var array |
|
21 | + */ |
|
22 | + protected static $_registry = []; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * Used to register a new template pack with the messages system. |
|
27 | + * |
|
28 | + * Template packs are primarily defined via class extending EE_Messages_Template_Pack and are typically used to |
|
29 | + * change entire layouts for a set of message templates. This method is used to register the new template pack and |
|
30 | + * automatically have it loaded in the appropriate places. |
|
31 | + * |
|
32 | + * This registry also verifies that there isn't already a template pack registered with the same name and if there |
|
33 | + * is then it will add an EE_Error notice. |
|
34 | + * |
|
35 | + * Note that this only handles registering the your Template Pack class with the message template pack system. |
|
36 | + * However, there is also a naming schema you must follow for templates you are providing with your template pack. |
|
37 | + * |
|
38 | + * @param string $identifier The internal reference used to refer to this template pack. Note, this is first come, |
|
39 | + * first serve. If there is already a template pack registered with this name then the |
|
40 | + * registry will assign a unique reference for it so it can still be activated (but this |
|
41 | + * makes it harder to deregister as it will be unique per load - so its best to try to |
|
42 | + * make this a unique string!) |
|
43 | + * @param array $setup_args array { |
|
44 | + * An array of required values for registering the template pack. |
|
45 | + * @type string $path The path for the new template pack class. |
|
46 | + * @type string $classname The name of the new Template Pack Class. |
|
47 | + * } |
|
48 | + * |
|
49 | + * @return void |
|
50 | + * @throws EE_Error |
|
51 | + * |
|
52 | + * @see core/libraries/messages/defaults/default/* for all the example templates the default template pack |
|
53 | + * supports. |
|
54 | + * |
|
55 | + * |
|
56 | + * @since 4.5.0 |
|
57 | + * @see EE_Messages_Template_Pack_Default for an example class |
|
58 | + */ |
|
59 | + public static function register($identifier = '', array $setup_args = []) |
|
60 | + { |
|
61 | + |
|
62 | + // check for required params |
|
63 | + if (empty($identifier) || empty($setup_args['path']) || empty($setup_args['classname'])) { |
|
64 | + throw new EE_Error( |
|
65 | + __( |
|
66 | + 'In order to register a new template pack for the EE Messages system, you must include a value to reference the template pack being registered and the setup_args must have the path for the new template pack class as well as the classname for the new Template Pack Class. ', |
|
67 | + 'event_espresso' |
|
68 | + ) |
|
69 | + ); |
|
70 | + } |
|
71 | + |
|
72 | + // make sure we don't register twice |
|
73 | + if (isset(self::$_registry[ $identifier ])) { |
|
74 | + return; |
|
75 | + } |
|
76 | + |
|
77 | + // check that incoming $identifier doesn't already exist. If it does then we'll create a unique reference for this template pack. |
|
78 | + if (isset(self::$_registry[ $identifier ])) { |
|
79 | + $identifier = uniqid() . '_' . $identifier; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + // make sure this was called in the right place! |
|
84 | + if (! did_action('EE_Brewing_Regular___messages_caf') |
|
85 | + || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
86 | + ) { |
|
87 | + EE_Error::doing_it_wrong( |
|
88 | + __METHOD__, |
|
89 | + sprintf( |
|
90 | + __( |
|
91 | + 'A EE Messages Template Pack given the reference "%s" has been attempted to be registered with the EE Messages System. It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.', |
|
92 | + 'event_espresso' |
|
93 | + ), |
|
94 | + $identifier |
|
95 | + ), |
|
96 | + '4.5.0' |
|
97 | + ); |
|
98 | + } |
|
99 | + |
|
100 | + if (self::_verify_class_not_exist($setup_args['classname'])) { |
|
101 | + self::$_registry[ $identifier ] = [ |
|
102 | + 'path' => (string) $setup_args['path'], |
|
103 | + 'classname' => (string) $setup_args['classname'], |
|
104 | + ]; |
|
105 | + } |
|
106 | + |
|
107 | + // hook into the system |
|
108 | + add_filter( |
|
109 | + 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
110 | + ['EE_Register_Messages_Template_Pack', 'set_template_pack_path'], |
|
111 | + 10 |
|
112 | + ); |
|
113 | + add_filter( |
|
114 | + 'FHEE__EED_Messages__get_template_packs__template_packs', |
|
115 | + ['EE_Register_Messages_Template_Pack', 'set_template_pack'], |
|
116 | + 10 |
|
117 | + ); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Callback for the FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter. This adds this template packs path |
|
123 | + * to the messages autoloader paths. |
|
124 | + * |
|
125 | + * @param array $paths Array of paths already registered with the messages autoloader |
|
126 | + * |
|
127 | + * @return array |
|
128 | + * @since 4.5.0 |
|
129 | + * |
|
130 | + */ |
|
131 | + public static function set_template_pack_path(array $paths) |
|
132 | + { |
|
133 | + foreach (self::$_registry as $args) { |
|
134 | + $paths[] = $args['path']; |
|
135 | + } |
|
136 | + return $paths; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * Callback for the FHEE__EED_Messages__get_template_packs__template_packs filter. This adds the instantiated, |
|
142 | + * registered template pack to the template packs array when requested by client code. |
|
143 | + * |
|
144 | + * @param EE_Messages_Template_Pack[] $template_packs |
|
145 | + * @return EE_Messages_Template_Pack[] |
|
146 | + * @since 4.5.0 |
|
147 | + * |
|
148 | + */ |
|
149 | + public static function set_template_pack(array $template_packs) |
|
150 | + { |
|
151 | + foreach (self::$_registry as $args) { |
|
152 | + // verify class_exists |
|
153 | + if (! class_exists($args['classname'])) { |
|
154 | + require_once($args['path'] . '/' . $args['classname'] . '.class.php'); |
|
155 | + } |
|
156 | + |
|
157 | + // check again! |
|
158 | + if (class_exists($args['classname'])) { |
|
159 | + $template_pack = new $args['classname']; |
|
160 | + $template_packs[ $template_pack->dbref ] = $template_pack; |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + return $template_packs; |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * This verifies that the classes for each registered template pack are unique names. |
|
170 | + * |
|
171 | + * @param string $classname The classname being checked |
|
172 | + * |
|
173 | + * @return bool |
|
174 | + */ |
|
175 | + private static function _verify_class_not_exist($classname) |
|
176 | + { |
|
177 | + // loop through the existing registry and see if the classname is already present. |
|
178 | + foreach (self::$_registry as $args) { |
|
179 | + if ($args['classname'] == $classname) { |
|
180 | + EE_Error::add_error( |
|
181 | + sprintf( |
|
182 | + __( |
|
183 | + 'The %s template pack that you just activated cannot be registered with the messages system because there is already a template pack active using the same classname. Contact the author of this template pack to let them know of the conflict. To stop seeing this message you will need to deactivate this template pack.', |
|
184 | + 'event_espresso' |
|
185 | + ), |
|
186 | + $classname |
|
187 | + ), |
|
188 | + __FILE__, |
|
189 | + __LINE__, |
|
190 | + __FUNCTION__ |
|
191 | + ); |
|
192 | + return false; |
|
193 | + } |
|
194 | + } |
|
195 | + return true; |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * This deregisters a variation set that was previously registered with the given slug. |
|
201 | + * |
|
202 | + * @param string $identifier The name for the variation set that was previously registered. |
|
203 | + * |
|
204 | + * @return void |
|
205 | + * @since 4.5.0 |
|
206 | + * |
|
207 | + */ |
|
208 | + public static function deregister($identifier = '') |
|
209 | + { |
|
210 | + unset(self::$_registry[ $identifier ]); |
|
211 | + } |
|
212 | 212 | } |
@@ -70,18 +70,18 @@ discard block |
||
70 | 70 | } |
71 | 71 | |
72 | 72 | // make sure we don't register twice |
73 | - if (isset(self::$_registry[ $identifier ])) { |
|
73 | + if (isset(self::$_registry[$identifier])) { |
|
74 | 74 | return; |
75 | 75 | } |
76 | 76 | |
77 | 77 | // check that incoming $identifier doesn't already exist. If it does then we'll create a unique reference for this template pack. |
78 | - if (isset(self::$_registry[ $identifier ])) { |
|
79 | - $identifier = uniqid() . '_' . $identifier; |
|
78 | + if (isset(self::$_registry[$identifier])) { |
|
79 | + $identifier = uniqid().'_'.$identifier; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | |
83 | 83 | // make sure this was called in the right place! |
84 | - if (! did_action('EE_Brewing_Regular___messages_caf') |
|
84 | + if ( ! did_action('EE_Brewing_Regular___messages_caf') |
|
85 | 85 | || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
86 | 86 | ) { |
87 | 87 | EE_Error::doing_it_wrong( |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | } |
99 | 99 | |
100 | 100 | if (self::_verify_class_not_exist($setup_args['classname'])) { |
101 | - self::$_registry[ $identifier ] = [ |
|
101 | + self::$_registry[$identifier] = [ |
|
102 | 102 | 'path' => (string) $setup_args['path'], |
103 | 103 | 'classname' => (string) $setup_args['classname'], |
104 | 104 | ]; |
@@ -150,14 +150,14 @@ discard block |
||
150 | 150 | { |
151 | 151 | foreach (self::$_registry as $args) { |
152 | 152 | // verify class_exists |
153 | - if (! class_exists($args['classname'])) { |
|
154 | - require_once($args['path'] . '/' . $args['classname'] . '.class.php'); |
|
153 | + if ( ! class_exists($args['classname'])) { |
|
154 | + require_once($args['path'].'/'.$args['classname'].'.class.php'); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | // check again! |
158 | 158 | if (class_exists($args['classname'])) { |
159 | 159 | $template_pack = new $args['classname']; |
160 | - $template_packs[ $template_pack->dbref ] = $template_pack; |
|
160 | + $template_packs[$template_pack->dbref] = $template_pack; |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
@@ -207,6 +207,6 @@ discard block |
||
207 | 207 | */ |
208 | 208 | public static function deregister($identifier = '') |
209 | 209 | { |
210 | - unset(self::$_registry[ $identifier ]); |
|
210 | + unset(self::$_registry[$identifier]); |
|
211 | 211 | } |
212 | 212 | } |
@@ -12,114 +12,114 @@ |
||
12 | 12 | class EE_Register_Config implements EEI_Plugin_API |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Holds registered EE_Config items |
|
17 | - * |
|
18 | - * @var array |
|
19 | - */ |
|
20 | - protected static $_ee_config_registry = []; |
|
15 | + /** |
|
16 | + * Holds registered EE_Config items |
|
17 | + * |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + protected static $_ee_config_registry = []; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * Handles registering the new config with the EE_Config::instance()->addons property |
|
25 | - * |
|
26 | - * @param string $identifier The name of the Config class being registered. |
|
27 | - * Note this class must extend EE_Config Base and must have |
|
28 | - * already been registered with an autoloader. |
|
29 | - * @param array $setup_args { |
|
30 | - * |
|
31 | - * @type string $config_name Optional. by default the new config will be registered to |
|
32 | - * EE_Config::instance()->addons->{config_class}, but supplying a "config_name" will set the property name |
|
33 | - * that this variable is accessible by. ie: EE_Config::instance()->addons->{config_name} |
|
34 | - * } |
|
35 | - * @return void |
|
36 | - * @throws EE_Error |
|
37 | - * |
|
38 | - * @since 4.3.0 |
|
39 | - */ |
|
40 | - public static function register($identifier = '', array $setup_args = []) |
|
41 | - { |
|
23 | + /** |
|
24 | + * Handles registering the new config with the EE_Config::instance()->addons property |
|
25 | + * |
|
26 | + * @param string $identifier The name of the Config class being registered. |
|
27 | + * Note this class must extend EE_Config Base and must have |
|
28 | + * already been registered with an autoloader. |
|
29 | + * @param array $setup_args { |
|
30 | + * |
|
31 | + * @type string $config_name Optional. by default the new config will be registered to |
|
32 | + * EE_Config::instance()->addons->{config_class}, but supplying a "config_name" will set the property name |
|
33 | + * that this variable is accessible by. ie: EE_Config::instance()->addons->{config_name} |
|
34 | + * } |
|
35 | + * @return void |
|
36 | + * @throws EE_Error |
|
37 | + * |
|
38 | + * @since 4.3.0 |
|
39 | + */ |
|
40 | + public static function register($identifier = '', array $setup_args = []) |
|
41 | + { |
|
42 | 42 | |
43 | - $setup_args['config_name'] = isset($setup_args['config_name']) && ! empty($setup_args['config_name']) |
|
44 | - ? $setup_args['config_name'] : $identifier; |
|
45 | - $setup_args['config_section'] = isset($setup_args['config_section']) && ! empty($setup_args['config_section']) |
|
46 | - ? $setup_args['config_section'] : 'addons'; |
|
43 | + $setup_args['config_name'] = isset($setup_args['config_name']) && ! empty($setup_args['config_name']) |
|
44 | + ? $setup_args['config_name'] : $identifier; |
|
45 | + $setup_args['config_section'] = isset($setup_args['config_section']) && ! empty($setup_args['config_section']) |
|
46 | + ? $setup_args['config_section'] : 'addons'; |
|
47 | 47 | |
48 | - // required fields MUST be present, so let's make sure they are. |
|
49 | - if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['config_name'])) { |
|
50 | - throw new EE_Error( |
|
51 | - __( |
|
52 | - 'In order to register a Config Class with EE_Register_Config::register(), you must include a "config_class" (the actual class name for this config class). As well, you can supply an array containing the following keys: "config_section" the main section of the config object the settings will be saved under (by default the new config will be registered under EE_Config::instance()->modules or EE_Config::instance()->addons depending on what type of class is calling this), "config_name" (by default the new config will be registered to EE_Config::instance()->{config_section}->{config_class}, but supplying a "config_name" will set the property name that this variable is accessible by. ie: EE_Config::instance()->{config_section}->{config_name})', |
|
53 | - 'event_espresso' |
|
54 | - ) |
|
55 | - ); |
|
56 | - } |
|
48 | + // required fields MUST be present, so let's make sure they are. |
|
49 | + if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['config_name'])) { |
|
50 | + throw new EE_Error( |
|
51 | + __( |
|
52 | + 'In order to register a Config Class with EE_Register_Config::register(), you must include a "config_class" (the actual class name for this config class). As well, you can supply an array containing the following keys: "config_section" the main section of the config object the settings will be saved under (by default the new config will be registered under EE_Config::instance()->modules or EE_Config::instance()->addons depending on what type of class is calling this), "config_name" (by default the new config will be registered to EE_Config::instance()->{config_section}->{config_class}, but supplying a "config_name" will set the property name that this variable is accessible by. ie: EE_Config::instance()->{config_section}->{config_name})', |
|
53 | + 'event_espresso' |
|
54 | + ) |
|
55 | + ); |
|
56 | + } |
|
57 | 57 | |
58 | - // make sure we don't register twice |
|
59 | - if (isset(self::$_ee_config_registry[ $identifier ])) { |
|
60 | - return; |
|
61 | - } |
|
58 | + // make sure we don't register twice |
|
59 | + if (isset(self::$_ee_config_registry[ $identifier ])) { |
|
60 | + return; |
|
61 | + } |
|
62 | 62 | |
63 | 63 | |
64 | - // first find out if this happened too late. |
|
65 | - if (did_action('AHEE__EE_System__load_core_configuration__begin')) { |
|
66 | - EE_Error::doing_it_wrong( |
|
67 | - __METHOD__, |
|
68 | - sprintf( |
|
69 | - __( |
|
70 | - 'An attempt to register "%s" as an EE_Config object has failed because it was not registered at the correct hookpoint. Please register before the "AHEE__EE_System__load_core_configuration__begin" hook has fired', |
|
71 | - 'event_espresso' |
|
72 | - ), |
|
73 | - $setup_args['config_name'] |
|
74 | - ), |
|
75 | - '4.3' |
|
76 | - ); |
|
77 | - } |
|
78 | - // add incoming stuff to our registry property |
|
79 | - self::$_ee_config_registry[ $identifier ] = [ |
|
80 | - 'section' => $setup_args['config_section'], |
|
81 | - 'name' => $setup_args['config_name'], |
|
82 | - ]; |
|
64 | + // first find out if this happened too late. |
|
65 | + if (did_action('AHEE__EE_System__load_core_configuration__begin')) { |
|
66 | + EE_Error::doing_it_wrong( |
|
67 | + __METHOD__, |
|
68 | + sprintf( |
|
69 | + __( |
|
70 | + 'An attempt to register "%s" as an EE_Config object has failed because it was not registered at the correct hookpoint. Please register before the "AHEE__EE_System__load_core_configuration__begin" hook has fired', |
|
71 | + 'event_espresso' |
|
72 | + ), |
|
73 | + $setup_args['config_name'] |
|
74 | + ), |
|
75 | + '4.3' |
|
76 | + ); |
|
77 | + } |
|
78 | + // add incoming stuff to our registry property |
|
79 | + self::$_ee_config_registry[ $identifier ] = [ |
|
80 | + 'section' => $setup_args['config_section'], |
|
81 | + 'name' => $setup_args['config_name'], |
|
82 | + ]; |
|
83 | 83 | |
84 | - add_action('AHEE__EE_Config___load_core_config__end', ['EE_Register_Config', 'set_config'], 15, 1); |
|
85 | - add_action('AHEE__EE_Config__update_espresso_config__end', ['EE_Register_Config', 'set_config'], 15, 1); |
|
86 | - } |
|
84 | + add_action('AHEE__EE_Config___load_core_config__end', ['EE_Register_Config', 'set_config'], 15, 1); |
|
85 | + add_action('AHEE__EE_Config__update_espresso_config__end', ['EE_Register_Config', 'set_config'], 15, 1); |
|
86 | + } |
|
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * Callback for the AHEE__EE_Config___load_core_config__end hook. |
|
91 | - * basically just calls EE_Config->get_config() which will take care of loading or creating our config object for us |
|
92 | - * |
|
93 | - * @param EE_Config $EE_Config |
|
94 | - * @return void |
|
95 | - * @throws EE_Error |
|
96 | - * @since 4.3.0 |
|
97 | - */ |
|
98 | - public static function set_config(EE_Config $EE_Config) |
|
99 | - { |
|
100 | - foreach (self::$_ee_config_registry as $identifier => $settings) { |
|
101 | - // first some validation of our incoming class_name. We'll throw an error early if its' not registered correctly |
|
102 | - if (! class_exists($identifier)) { |
|
103 | - throw new EE_Error( |
|
104 | - sprintf( |
|
105 | - __( |
|
106 | - 'The "%s" config class can not be registered with EE_Config because it does not exist. Verify that an autoloader has been set for this class', |
|
107 | - 'event_espresso' |
|
108 | - ), |
|
109 | - $identifier |
|
110 | - ) |
|
111 | - ); |
|
112 | - } |
|
113 | - $EE_Config->get_config($settings['section'], $settings['name'], $identifier); |
|
114 | - } |
|
115 | - } |
|
89 | + /** |
|
90 | + * Callback for the AHEE__EE_Config___load_core_config__end hook. |
|
91 | + * basically just calls EE_Config->get_config() which will take care of loading or creating our config object for us |
|
92 | + * |
|
93 | + * @param EE_Config $EE_Config |
|
94 | + * @return void |
|
95 | + * @throws EE_Error |
|
96 | + * @since 4.3.0 |
|
97 | + */ |
|
98 | + public static function set_config(EE_Config $EE_Config) |
|
99 | + { |
|
100 | + foreach (self::$_ee_config_registry as $identifier => $settings) { |
|
101 | + // first some validation of our incoming class_name. We'll throw an error early if its' not registered correctly |
|
102 | + if (! class_exists($identifier)) { |
|
103 | + throw new EE_Error( |
|
104 | + sprintf( |
|
105 | + __( |
|
106 | + 'The "%s" config class can not be registered with EE_Config because it does not exist. Verify that an autoloader has been set for this class', |
|
107 | + 'event_espresso' |
|
108 | + ), |
|
109 | + $identifier |
|
110 | + ) |
|
111 | + ); |
|
112 | + } |
|
113 | + $EE_Config->get_config($settings['section'], $settings['name'], $identifier); |
|
114 | + } |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | - /** |
|
119 | - * @param string $identifier |
|
120 | - */ |
|
121 | - public static function deregister($identifier = '') |
|
122 | - { |
|
123 | - unset(self::$_ee_config_registry[ $identifier ]); |
|
124 | - } |
|
118 | + /** |
|
119 | + * @param string $identifier |
|
120 | + */ |
|
121 | + public static function deregister($identifier = '') |
|
122 | + { |
|
123 | + unset(self::$_ee_config_registry[ $identifier ]); |
|
124 | + } |
|
125 | 125 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | // make sure we don't register twice |
59 | - if (isset(self::$_ee_config_registry[ $identifier ])) { |
|
59 | + if (isset(self::$_ee_config_registry[$identifier])) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | 62 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | ); |
77 | 77 | } |
78 | 78 | // add incoming stuff to our registry property |
79 | - self::$_ee_config_registry[ $identifier ] = [ |
|
79 | + self::$_ee_config_registry[$identifier] = [ |
|
80 | 80 | 'section' => $setup_args['config_section'], |
81 | 81 | 'name' => $setup_args['config_name'], |
82 | 82 | ]; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | { |
100 | 100 | foreach (self::$_ee_config_registry as $identifier => $settings) { |
101 | 101 | // first some validation of our incoming class_name. We'll throw an error early if its' not registered correctly |
102 | - if (! class_exists($identifier)) { |
|
102 | + if ( ! class_exists($identifier)) { |
|
103 | 103 | throw new EE_Error( |
104 | 104 | sprintf( |
105 | 105 | __( |
@@ -120,6 +120,6 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public static function deregister($identifier = '') |
122 | 122 | { |
123 | - unset(self::$_ee_config_registry[ $identifier ]); |
|
123 | + unset(self::$_ee_config_registry[$identifier]); |
|
124 | 124 | } |
125 | 125 | } |