@@ -10,485 +10,485 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_Register_Message_Type implements EEI_Plugin_API |
12 | 12 | { |
13 | - /** |
|
14 | - * Holds values for registered message types |
|
15 | - * |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected static $_ee_message_type_registry = []; |
|
13 | + /** |
|
14 | + * Holds values for registered message types |
|
15 | + * |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected static $_ee_message_type_registry = []; |
|
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * Method for registering new message types in the EE_messages system. |
|
23 | - * Note: All message types must have the following files in order to work: |
|
24 | - * Template files for default templates getting setup. |
|
25 | - * See /core/libraries/messages/defaults/default/ for examples |
|
26 | - * (note that template files match a specific naming schema). |
|
27 | - * These templates will need to be registered with the default template pack. |
|
28 | - * - EE_Messages_Validator extended class(es). See /core/libraries/messages/validators/email/ |
|
29 | - * for examples. Note for any new message types, there will need to be a validator for each |
|
30 | - * messenger combo this message type can activate with. |
|
31 | - * - And of course the main EE_{Message_Type_Name}_message_type class that defines the new |
|
32 | - * message type and its properties. |
|
33 | - * |
|
34 | - * @param string $addon_name Whatever is defined for the $name property of |
|
35 | - * the message type you are registering (eg. |
|
36 | - * declined_registration). Required. |
|
37 | - * @param array $setup_args An array of arguments provided for registering the message type. |
|
38 | - * @throws EE_Error |
|
39 | - * } |
|
40 | - * @see inline docs in the register method for what can be passed in as arguments. |
|
41 | - * @since 4.3.0 |
|
42 | - */ |
|
43 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
44 | - { |
|
45 | - // required fields MUST be present, so let's make sure they are. |
|
46 | - if ( |
|
47 | - ! isset($addon_name) |
|
48 | - || ! is_array($setup_args) |
|
49 | - || empty($setup_args['mtfilename']) |
|
50 | - || empty($setup_args['autoloadpaths']) |
|
51 | - ) { |
|
52 | - throw new EE_Error( |
|
53 | - esc_html__( |
|
54 | - 'In order to register a message type with EE_Register_Message_Type::register, you must include a unique name for the message type, plus an array containing the following keys: "mtfilename", "autoloadpaths"', |
|
55 | - 'event_espresso' |
|
56 | - ) |
|
57 | - ); |
|
58 | - } |
|
21 | + /** |
|
22 | + * Method for registering new message types in the EE_messages system. |
|
23 | + * Note: All message types must have the following files in order to work: |
|
24 | + * Template files for default templates getting setup. |
|
25 | + * See /core/libraries/messages/defaults/default/ for examples |
|
26 | + * (note that template files match a specific naming schema). |
|
27 | + * These templates will need to be registered with the default template pack. |
|
28 | + * - EE_Messages_Validator extended class(es). See /core/libraries/messages/validators/email/ |
|
29 | + * for examples. Note for any new message types, there will need to be a validator for each |
|
30 | + * messenger combo this message type can activate with. |
|
31 | + * - And of course the main EE_{Message_Type_Name}_message_type class that defines the new |
|
32 | + * message type and its properties. |
|
33 | + * |
|
34 | + * @param string $addon_name Whatever is defined for the $name property of |
|
35 | + * the message type you are registering (eg. |
|
36 | + * declined_registration). Required. |
|
37 | + * @param array $setup_args An array of arguments provided for registering the message type. |
|
38 | + * @throws EE_Error |
|
39 | + * } |
|
40 | + * @see inline docs in the register method for what can be passed in as arguments. |
|
41 | + * @since 4.3.0 |
|
42 | + */ |
|
43 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
44 | + { |
|
45 | + // required fields MUST be present, so let's make sure they are. |
|
46 | + if ( |
|
47 | + ! isset($addon_name) |
|
48 | + || ! is_array($setup_args) |
|
49 | + || empty($setup_args['mtfilename']) |
|
50 | + || empty($setup_args['autoloadpaths']) |
|
51 | + ) { |
|
52 | + throw new EE_Error( |
|
53 | + esc_html__( |
|
54 | + 'In order to register a message type with EE_Register_Message_Type::register, you must include a unique name for the message type, plus an array containing the following keys: "mtfilename", "autoloadpaths"', |
|
55 | + 'event_espresso' |
|
56 | + ) |
|
57 | + ); |
|
58 | + } |
|
59 | 59 | |
60 | - // make sure we don't register twice |
|
61 | - if (isset(self::$_ee_message_type_registry[ $addon_name ])) { |
|
62 | - return true; |
|
63 | - } |
|
60 | + // make sure we don't register twice |
|
61 | + if (isset(self::$_ee_message_type_registry[ $addon_name ])) { |
|
62 | + return true; |
|
63 | + } |
|
64 | 64 | |
65 | - // make sure this was called in the right place! |
|
66 | - if ( |
|
67 | - ! did_action('EE_Brewing_Regular___messages_caf') |
|
68 | - || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
69 | - ) { |
|
70 | - EE_Error::doing_it_wrong( |
|
71 | - __METHOD__, |
|
72 | - sprintf( |
|
73 | - esc_html__( |
|
74 | - 'A message type named "%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.', |
|
75 | - 'event_espresso' |
|
76 | - ), |
|
77 | - $addon_name |
|
78 | - ), |
|
79 | - '4.3.0' |
|
80 | - ); |
|
81 | - } |
|
82 | - // setup $__ee_message_type_registry array from incoming values. |
|
83 | - self::$_ee_message_type_registry[ $addon_name ] = [ |
|
84 | - /** |
|
85 | - * The file name for the message type being registered. |
|
86 | - * Required. |
|
87 | - * |
|
88 | - * @type string |
|
89 | - */ |
|
90 | - 'mtfilename' => (string) $setup_args['mtfilename'], |
|
91 | - /** |
|
92 | - * Autoload paths for classes used by the message type. |
|
93 | - * Required. |
|
94 | - * |
|
95 | - * @type array |
|
96 | - */ |
|
97 | - 'autoloadpaths' => (array) $setup_args['autoloadpaths'], |
|
98 | - /** |
|
99 | - * Messengers that the message type should be able to activate with. |
|
100 | - * Use messenger slugs. |
|
101 | - * |
|
102 | - * @type array |
|
103 | - */ |
|
104 | - 'messengers_to_activate_with' => ! empty($setup_args['messengers_to_activate_with']) |
|
105 | - ? (array) $setup_args['messengers_to_activate_with'] |
|
106 | - : [], |
|
107 | - /** |
|
108 | - * Messengers that the message type should validate with. |
|
109 | - * Use messenger slugs. |
|
110 | - * |
|
111 | - * @type array |
|
112 | - */ |
|
113 | - 'messengers_to_validate_with' => ! empty($setup_args['messengers_to_validate_with']) |
|
114 | - ? (array) $setup_args['messengers_to_validate_with'] |
|
115 | - : [], |
|
116 | - /** |
|
117 | - * Whether to force activate this message type the first time it is registered. |
|
118 | - * |
|
119 | - * @type bool False means its not activated by default and left up to the end user to activate. |
|
120 | - */ |
|
121 | - 'force_activation' => ! empty($setup_args['force_activation']) |
|
122 | - && $setup_args['force_activation'], |
|
123 | - /** |
|
124 | - * What messengers this message type supports the default template pack for. |
|
125 | - * Note: If you do not set this (or any of the following template pack/variation related arguments) to true, |
|
126 | - * then it is expected that the message type being registered is doing its own custom default template |
|
127 | - * pack/variation registration. |
|
128 | - * |
|
129 | - * If this is set and has values, then it is expected that the following arguments are also set in the incoming options |
|
130 | - * $setup_arguments array as well: |
|
131 | - * - 'base_path_for_default_templates' |
|
132 | - * |
|
133 | - * @type array Expect an array of messengers this supports default template packs for. |
|
134 | - */ |
|
135 | - 'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with']) |
|
136 | - ? (array) $setup_args['messengers_supporting_default_template_pack_with'] |
|
137 | - : [], |
|
138 | - /** |
|
139 | - * The base path where the default templates for this message type can be found. |
|
140 | - * |
|
141 | - * @type string |
|
142 | - */ |
|
143 | - 'base_path_for_default_templates' => $setup_args['base_path_for_default_templates'] ?? '', |
|
144 | - /** |
|
145 | - * The base path where the default variations for this message type can be found. |
|
146 | - * |
|
147 | - * @type string |
|
148 | - */ |
|
149 | - 'base_path_for_default_variation' => $setup_args['base_path_for_default_variation'] ?? '', |
|
150 | - /** |
|
151 | - * The base url for the default variations for this message type. |
|
152 | - * |
|
153 | - * @type string |
|
154 | - */ |
|
155 | - 'base_url_for_default_variation' => $setup_args['base_url_for_default_variation'] ?? '', |
|
156 | - ]; |
|
157 | - // add filters but only if they haven't already been set (these filters only need to be registered ONCE because |
|
158 | - // the callback handles all registered message types. |
|
159 | - if ( |
|
160 | - has_filter( |
|
161 | - 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
162 | - ['EE_Register_Message_Type', 'register_msgs_autoload_paths'] |
|
163 | - ) === false |
|
164 | - ) { |
|
165 | - add_filter( |
|
166 | - 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
167 | - ['EE_Register_Message_Type', 'register_msgs_autoload_paths'], |
|
168 | - 10 |
|
169 | - ); |
|
170 | - add_filter( |
|
171 | - 'FHEE__EE_messages__get_installed__messagetype_files', |
|
172 | - ['EE_Register_Message_Type', 'register_messagetype_files'], |
|
173 | - 10, |
|
174 | - 1 |
|
175 | - ); |
|
176 | - add_filter( |
|
177 | - 'FHEE__EE_messenger__get_default_message_types__default_types', |
|
178 | - ['EE_Register_Message_Type', 'register_messengers_to_activate_mt_with'], |
|
179 | - 10, |
|
180 | - 2 |
|
181 | - ); |
|
182 | - add_filter( |
|
183 | - 'FHEE__EE_messenger__get_valid_message_types__valid_types', |
|
184 | - ['EE_Register_Message_Type', 'register_messengers_to_validate_mt_with'], |
|
185 | - 10, |
|
186 | - 2 |
|
187 | - ); |
|
188 | - // actions |
|
189 | - add_action( |
|
190 | - 'AHEE__EE_Addon__initialize_default_data__begin', |
|
191 | - ['EE_Register_Message_Type', 'set_defaults'] |
|
192 | - ); |
|
65 | + // make sure this was called in the right place! |
|
66 | + if ( |
|
67 | + ! did_action('EE_Brewing_Regular___messages_caf') |
|
68 | + || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
69 | + ) { |
|
70 | + EE_Error::doing_it_wrong( |
|
71 | + __METHOD__, |
|
72 | + sprintf( |
|
73 | + esc_html__( |
|
74 | + 'A message type named "%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.', |
|
75 | + 'event_espresso' |
|
76 | + ), |
|
77 | + $addon_name |
|
78 | + ), |
|
79 | + '4.3.0' |
|
80 | + ); |
|
81 | + } |
|
82 | + // setup $__ee_message_type_registry array from incoming values. |
|
83 | + self::$_ee_message_type_registry[ $addon_name ] = [ |
|
84 | + /** |
|
85 | + * The file name for the message type being registered. |
|
86 | + * Required. |
|
87 | + * |
|
88 | + * @type string |
|
89 | + */ |
|
90 | + 'mtfilename' => (string) $setup_args['mtfilename'], |
|
91 | + /** |
|
92 | + * Autoload paths for classes used by the message type. |
|
93 | + * Required. |
|
94 | + * |
|
95 | + * @type array |
|
96 | + */ |
|
97 | + 'autoloadpaths' => (array) $setup_args['autoloadpaths'], |
|
98 | + /** |
|
99 | + * Messengers that the message type should be able to activate with. |
|
100 | + * Use messenger slugs. |
|
101 | + * |
|
102 | + * @type array |
|
103 | + */ |
|
104 | + 'messengers_to_activate_with' => ! empty($setup_args['messengers_to_activate_with']) |
|
105 | + ? (array) $setup_args['messengers_to_activate_with'] |
|
106 | + : [], |
|
107 | + /** |
|
108 | + * Messengers that the message type should validate with. |
|
109 | + * Use messenger slugs. |
|
110 | + * |
|
111 | + * @type array |
|
112 | + */ |
|
113 | + 'messengers_to_validate_with' => ! empty($setup_args['messengers_to_validate_with']) |
|
114 | + ? (array) $setup_args['messengers_to_validate_with'] |
|
115 | + : [], |
|
116 | + /** |
|
117 | + * Whether to force activate this message type the first time it is registered. |
|
118 | + * |
|
119 | + * @type bool False means its not activated by default and left up to the end user to activate. |
|
120 | + */ |
|
121 | + 'force_activation' => ! empty($setup_args['force_activation']) |
|
122 | + && $setup_args['force_activation'], |
|
123 | + /** |
|
124 | + * What messengers this message type supports the default template pack for. |
|
125 | + * Note: If you do not set this (or any of the following template pack/variation related arguments) to true, |
|
126 | + * then it is expected that the message type being registered is doing its own custom default template |
|
127 | + * pack/variation registration. |
|
128 | + * |
|
129 | + * If this is set and has values, then it is expected that the following arguments are also set in the incoming options |
|
130 | + * $setup_arguments array as well: |
|
131 | + * - 'base_path_for_default_templates' |
|
132 | + * |
|
133 | + * @type array Expect an array of messengers this supports default template packs for. |
|
134 | + */ |
|
135 | + 'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with']) |
|
136 | + ? (array) $setup_args['messengers_supporting_default_template_pack_with'] |
|
137 | + : [], |
|
138 | + /** |
|
139 | + * The base path where the default templates for this message type can be found. |
|
140 | + * |
|
141 | + * @type string |
|
142 | + */ |
|
143 | + 'base_path_for_default_templates' => $setup_args['base_path_for_default_templates'] ?? '', |
|
144 | + /** |
|
145 | + * The base path where the default variations for this message type can be found. |
|
146 | + * |
|
147 | + * @type string |
|
148 | + */ |
|
149 | + 'base_path_for_default_variation' => $setup_args['base_path_for_default_variation'] ?? '', |
|
150 | + /** |
|
151 | + * The base url for the default variations for this message type. |
|
152 | + * |
|
153 | + * @type string |
|
154 | + */ |
|
155 | + 'base_url_for_default_variation' => $setup_args['base_url_for_default_variation'] ?? '', |
|
156 | + ]; |
|
157 | + // add filters but only if they haven't already been set (these filters only need to be registered ONCE because |
|
158 | + // the callback handles all registered message types. |
|
159 | + if ( |
|
160 | + has_filter( |
|
161 | + 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
162 | + ['EE_Register_Message_Type', 'register_msgs_autoload_paths'] |
|
163 | + ) === false |
|
164 | + ) { |
|
165 | + add_filter( |
|
166 | + 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
167 | + ['EE_Register_Message_Type', 'register_msgs_autoload_paths'], |
|
168 | + 10 |
|
169 | + ); |
|
170 | + add_filter( |
|
171 | + 'FHEE__EE_messages__get_installed__messagetype_files', |
|
172 | + ['EE_Register_Message_Type', 'register_messagetype_files'], |
|
173 | + 10, |
|
174 | + 1 |
|
175 | + ); |
|
176 | + add_filter( |
|
177 | + 'FHEE__EE_messenger__get_default_message_types__default_types', |
|
178 | + ['EE_Register_Message_Type', 'register_messengers_to_activate_mt_with'], |
|
179 | + 10, |
|
180 | + 2 |
|
181 | + ); |
|
182 | + add_filter( |
|
183 | + 'FHEE__EE_messenger__get_valid_message_types__valid_types', |
|
184 | + ['EE_Register_Message_Type', 'register_messengers_to_validate_mt_with'], |
|
185 | + 10, |
|
186 | + 2 |
|
187 | + ); |
|
188 | + // actions |
|
189 | + add_action( |
|
190 | + 'AHEE__EE_Addon__initialize_default_data__begin', |
|
191 | + ['EE_Register_Message_Type', 'set_defaults'] |
|
192 | + ); |
|
193 | 193 | |
194 | - // default template packs and variations related |
|
195 | - add_filter( |
|
196 | - 'FHEE__EE_Messages_Template_Pack_Default__get_supports', |
|
197 | - ['EE_Register_Message_Type', 'register_default_template_pack_supports'] |
|
198 | - ); |
|
199 | - add_filter( |
|
200 | - 'FHEE__EE_Template_Pack___get_specific_template__filtered_base_path', |
|
201 | - ['EE_Register_Message_Type', 'register_base_template_path'], |
|
202 | - 10, |
|
203 | - 6 |
|
204 | - ); |
|
205 | - add_filter( |
|
206 | - 'FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url', |
|
207 | - ['EE_Register_Message_Type', 'register_variation_base_path_or_url'], |
|
208 | - 10, |
|
209 | - 8 |
|
210 | - ); |
|
211 | - add_filter( |
|
212 | - 'FHEE__EE_Messages_Template_Pack__get_variation__base_path', |
|
213 | - ['EE_Register_Message_Type', 'register_variation_base_path_or_url'], |
|
214 | - 10, |
|
215 | - 8 |
|
216 | - ); |
|
217 | - } |
|
218 | - return true; |
|
219 | - } |
|
194 | + // default template packs and variations related |
|
195 | + add_filter( |
|
196 | + 'FHEE__EE_Messages_Template_Pack_Default__get_supports', |
|
197 | + ['EE_Register_Message_Type', 'register_default_template_pack_supports'] |
|
198 | + ); |
|
199 | + add_filter( |
|
200 | + 'FHEE__EE_Template_Pack___get_specific_template__filtered_base_path', |
|
201 | + ['EE_Register_Message_Type', 'register_base_template_path'], |
|
202 | + 10, |
|
203 | + 6 |
|
204 | + ); |
|
205 | + add_filter( |
|
206 | + 'FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url', |
|
207 | + ['EE_Register_Message_Type', 'register_variation_base_path_or_url'], |
|
208 | + 10, |
|
209 | + 8 |
|
210 | + ); |
|
211 | + add_filter( |
|
212 | + 'FHEE__EE_Messages_Template_Pack__get_variation__base_path', |
|
213 | + ['EE_Register_Message_Type', 'register_variation_base_path_or_url'], |
|
214 | + 10, |
|
215 | + 8 |
|
216 | + ); |
|
217 | + } |
|
218 | + return true; |
|
219 | + } |
|
220 | 220 | |
221 | 221 | |
222 | - /** |
|
223 | - * This just ensures that when an addon registers a message type that on initial activation/reactivation the |
|
224 | - * defaults the addon sets are taken care of. |
|
225 | - * |
|
226 | - * @throws EE_Error |
|
227 | - * @throws ReflectionException |
|
228 | - */ |
|
229 | - public static function set_defaults() |
|
230 | - { |
|
231 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
232 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
222 | + /** |
|
223 | + * This just ensures that when an addon registers a message type that on initial activation/reactivation the |
|
224 | + * defaults the addon sets are taken care of. |
|
225 | + * |
|
226 | + * @throws EE_Error |
|
227 | + * @throws ReflectionException |
|
228 | + */ |
|
229 | + public static function set_defaults() |
|
230 | + { |
|
231 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
232 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
233 | 233 | |
234 | - // for any message types with force activation, let's ensure they are activated |
|
235 | - foreach (self::$_ee_message_type_registry as $addon_name => $settings) { |
|
236 | - if ($settings['force_activation']) { |
|
237 | - foreach ($settings['messengers_to_activate_with'] as $messenger) { |
|
238 | - // DO not force activation if this message type has already been activated in the system |
|
239 | - if ( |
|
240 | - ! $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
241 | - $addon_name, |
|
242 | - $messenger |
|
243 | - ) |
|
244 | - ) { |
|
245 | - $message_resource_manager->ensure_message_type_is_active($addon_name, $messenger); |
|
246 | - } |
|
247 | - } |
|
248 | - } |
|
249 | - } |
|
250 | - } |
|
234 | + // for any message types with force activation, let's ensure they are activated |
|
235 | + foreach (self::$_ee_message_type_registry as $addon_name => $settings) { |
|
236 | + if ($settings['force_activation']) { |
|
237 | + foreach ($settings['messengers_to_activate_with'] as $messenger) { |
|
238 | + // DO not force activation if this message type has already been activated in the system |
|
239 | + if ( |
|
240 | + ! $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
241 | + $addon_name, |
|
242 | + $messenger |
|
243 | + ) |
|
244 | + ) { |
|
245 | + $message_resource_manager->ensure_message_type_is_active($addon_name, $messenger); |
|
246 | + } |
|
247 | + } |
|
248 | + } |
|
249 | + } |
|
250 | + } |
|
251 | 251 | |
252 | 252 | |
253 | - /** |
|
254 | - * This deregisters a message type that was previously registered with a specific message_type_name. |
|
255 | - * |
|
256 | - * @param string $addon_name the name for the message type that was previously registered |
|
257 | - * @return void |
|
258 | - * @throws EE_Error |
|
259 | - * @throws ReflectionException |
|
260 | - * @since 4.3.0 |
|
261 | - */ |
|
262 | - public static function deregister(string $addon_name = '') |
|
263 | - { |
|
264 | - if (! empty(self::$_ee_message_type_registry[ $addon_name ])) { |
|
265 | - // let's make sure that we remove any place this message type was made active |
|
266 | - /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
267 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
268 | - // ensures that if this message type is registered again that it retains its previous active state vs |
|
269 | - // remaining inactive. |
|
270 | - $Message_Resource_Manager->remove_message_type_has_been_activated_from_all_messengers( |
|
271 | - $addon_name, |
|
272 | - true |
|
273 | - ); |
|
274 | - $Message_Resource_Manager->deactivate_message_type($addon_name, false); |
|
275 | - } |
|
276 | - unset(self::$_ee_message_type_registry[ $addon_name ]); |
|
277 | - } |
|
253 | + /** |
|
254 | + * This deregisters a message type that was previously registered with a specific message_type_name. |
|
255 | + * |
|
256 | + * @param string $addon_name the name for the message type that was previously registered |
|
257 | + * @return void |
|
258 | + * @throws EE_Error |
|
259 | + * @throws ReflectionException |
|
260 | + * @since 4.3.0 |
|
261 | + */ |
|
262 | + public static function deregister(string $addon_name = '') |
|
263 | + { |
|
264 | + if (! empty(self::$_ee_message_type_registry[ $addon_name ])) { |
|
265 | + // let's make sure that we remove any place this message type was made active |
|
266 | + /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
267 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
268 | + // ensures that if this message type is registered again that it retains its previous active state vs |
|
269 | + // remaining inactive. |
|
270 | + $Message_Resource_Manager->remove_message_type_has_been_activated_from_all_messengers( |
|
271 | + $addon_name, |
|
272 | + true |
|
273 | + ); |
|
274 | + $Message_Resource_Manager->deactivate_message_type($addon_name, false); |
|
275 | + } |
|
276 | + unset(self::$_ee_message_type_registry[ $addon_name ]); |
|
277 | + } |
|
278 | 278 | |
279 | 279 | |
280 | - /** |
|
281 | - * callback for FHEE__EE_messages__get_installed__messagetype_files filter. |
|
282 | - * |
|
283 | - * @param array $messagetype_files The current array of message type file names |
|
284 | - * @return array Array of message type file names |
|
285 | - * @since 4.3.0 |
|
286 | - */ |
|
287 | - public static function register_messagetype_files(array $messagetype_files): array |
|
288 | - { |
|
289 | - if (empty(self::$_ee_message_type_registry)) { |
|
290 | - return $messagetype_files; |
|
291 | - } |
|
292 | - foreach (self::$_ee_message_type_registry as $mt_reg) { |
|
293 | - if (empty($mt_reg['mtfilename'])) { |
|
294 | - continue; |
|
295 | - } |
|
296 | - $messagetype_files[] = $mt_reg['mtfilename']; |
|
297 | - } |
|
298 | - return $messagetype_files; |
|
299 | - } |
|
280 | + /** |
|
281 | + * callback for FHEE__EE_messages__get_installed__messagetype_files filter. |
|
282 | + * |
|
283 | + * @param array $messagetype_files The current array of message type file names |
|
284 | + * @return array Array of message type file names |
|
285 | + * @since 4.3.0 |
|
286 | + */ |
|
287 | + public static function register_messagetype_files(array $messagetype_files): array |
|
288 | + { |
|
289 | + if (empty(self::$_ee_message_type_registry)) { |
|
290 | + return $messagetype_files; |
|
291 | + } |
|
292 | + foreach (self::$_ee_message_type_registry as $mt_reg) { |
|
293 | + if (empty($mt_reg['mtfilename'])) { |
|
294 | + continue; |
|
295 | + } |
|
296 | + $messagetype_files[] = $mt_reg['mtfilename']; |
|
297 | + } |
|
298 | + return $messagetype_files; |
|
299 | + } |
|
300 | 300 | |
301 | 301 | |
302 | - /** |
|
303 | - * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter. |
|
304 | - * |
|
305 | - * @param array $paths array of paths to be checked by EE_messages autoloader. |
|
306 | - * @return array |
|
307 | - * @since 4.3.0 |
|
308 | - */ |
|
309 | - public static function register_msgs_autoload_paths(array $paths): array |
|
310 | - { |
|
311 | - $autoload_paths = []; |
|
312 | - if (! empty(self::$_ee_message_type_registry)) { |
|
313 | - foreach (self::$_ee_message_type_registry as $mt_reg) { |
|
314 | - if (empty($mt_reg['autoloadpaths'])) { |
|
315 | - continue; |
|
316 | - } |
|
317 | - $autoload_paths[] = $mt_reg['autoloadpaths']; |
|
318 | - } |
|
319 | - } |
|
320 | - return array_merge($paths, ...$autoload_paths); |
|
321 | - } |
|
302 | + /** |
|
303 | + * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter. |
|
304 | + * |
|
305 | + * @param array $paths array of paths to be checked by EE_messages autoloader. |
|
306 | + * @return array |
|
307 | + * @since 4.3.0 |
|
308 | + */ |
|
309 | + public static function register_msgs_autoload_paths(array $paths): array |
|
310 | + { |
|
311 | + $autoload_paths = []; |
|
312 | + if (! empty(self::$_ee_message_type_registry)) { |
|
313 | + foreach (self::$_ee_message_type_registry as $mt_reg) { |
|
314 | + if (empty($mt_reg['autoloadpaths'])) { |
|
315 | + continue; |
|
316 | + } |
|
317 | + $autoload_paths[] = $mt_reg['autoloadpaths']; |
|
318 | + } |
|
319 | + } |
|
320 | + return array_merge($paths, ...$autoload_paths); |
|
321 | + } |
|
322 | 322 | |
323 | 323 | |
324 | - /** |
|
325 | - * callback for FHEE__EE_messenger__get_default_message_types__default_types filter. |
|
326 | - * |
|
327 | - * @param array $default_types array of message types activated with messenger ( |
|
328 | - * corresponds to the $name property of message type) |
|
329 | - * @param EE_messenger $messenger The EE_messenger the filter is called from. |
|
330 | - * @return array |
|
331 | - * @since 4.3.0 |
|
332 | - */ |
|
333 | - public static function register_messengers_to_activate_mt_with(array $default_types, EE_messenger $messenger): array |
|
334 | - { |
|
335 | - if (empty(self::$_ee_message_type_registry)) { |
|
336 | - return $default_types; |
|
337 | - } |
|
338 | - foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) { |
|
339 | - if (empty($mt_reg['messengers_to_activate_with']) || empty($mt_reg['mtfilename'])) { |
|
340 | - continue; |
|
341 | - } |
|
342 | - // loop through each of the messengers and if it matches the loaded class |
|
343 | - // then we add this message type to the |
|
344 | - foreach ($mt_reg['messengers_to_activate_with'] as $msgr) { |
|
345 | - if ($messenger->name == $msgr) { |
|
346 | - $default_types[] = $addon_name; |
|
347 | - } |
|
348 | - } |
|
349 | - } |
|
324 | + /** |
|
325 | + * callback for FHEE__EE_messenger__get_default_message_types__default_types filter. |
|
326 | + * |
|
327 | + * @param array $default_types array of message types activated with messenger ( |
|
328 | + * corresponds to the $name property of message type) |
|
329 | + * @param EE_messenger $messenger The EE_messenger the filter is called from. |
|
330 | + * @return array |
|
331 | + * @since 4.3.0 |
|
332 | + */ |
|
333 | + public static function register_messengers_to_activate_mt_with(array $default_types, EE_messenger $messenger): array |
|
334 | + { |
|
335 | + if (empty(self::$_ee_message_type_registry)) { |
|
336 | + return $default_types; |
|
337 | + } |
|
338 | + foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) { |
|
339 | + if (empty($mt_reg['messengers_to_activate_with']) || empty($mt_reg['mtfilename'])) { |
|
340 | + continue; |
|
341 | + } |
|
342 | + // loop through each of the messengers and if it matches the loaded class |
|
343 | + // then we add this message type to the |
|
344 | + foreach ($mt_reg['messengers_to_activate_with'] as $msgr) { |
|
345 | + if ($messenger->name == $msgr) { |
|
346 | + $default_types[] = $addon_name; |
|
347 | + } |
|
348 | + } |
|
349 | + } |
|
350 | 350 | |
351 | - return $default_types; |
|
352 | - } |
|
351 | + return $default_types; |
|
352 | + } |
|
353 | 353 | |
354 | 354 | |
355 | - /** |
|
356 | - * callback for FHEE__EE_messenger__get_valid_message_types__default_types filter. |
|
357 | - * |
|
358 | - * @param array $valid_types array of message types valid with messenger ( |
|
359 | - * corresponds to the $name property of message type) |
|
360 | - * @param EE_messenger $messenger The EE_messenger the filter is called from. |
|
361 | - * @return array |
|
362 | - * @since 4.3.0 |
|
363 | - */ |
|
364 | - public static function register_messengers_to_validate_mt_with(array $valid_types, EE_messenger $messenger): array |
|
365 | - { |
|
366 | - if (empty(self::$_ee_message_type_registry)) { |
|
367 | - return $valid_types; |
|
368 | - } |
|
369 | - foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) { |
|
370 | - if (empty($mt_reg['messengers_to_validate_with']) || empty($mt_reg['mtfilename'])) { |
|
371 | - continue; |
|
372 | - } |
|
373 | - // loop through each of the messengers and if it matches the loaded class |
|
374 | - // then we add this message type to the |
|
375 | - foreach ($mt_reg['messengers_to_validate_with'] as $msgr) { |
|
376 | - if ($messenger->name == $msgr) { |
|
377 | - $valid_types[] = $addon_name; |
|
378 | - } |
|
379 | - } |
|
380 | - } |
|
355 | + /** |
|
356 | + * callback for FHEE__EE_messenger__get_valid_message_types__default_types filter. |
|
357 | + * |
|
358 | + * @param array $valid_types array of message types valid with messenger ( |
|
359 | + * corresponds to the $name property of message type) |
|
360 | + * @param EE_messenger $messenger The EE_messenger the filter is called from. |
|
361 | + * @return array |
|
362 | + * @since 4.3.0 |
|
363 | + */ |
|
364 | + public static function register_messengers_to_validate_mt_with(array $valid_types, EE_messenger $messenger): array |
|
365 | + { |
|
366 | + if (empty(self::$_ee_message_type_registry)) { |
|
367 | + return $valid_types; |
|
368 | + } |
|
369 | + foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) { |
|
370 | + if (empty($mt_reg['messengers_to_validate_with']) || empty($mt_reg['mtfilename'])) { |
|
371 | + continue; |
|
372 | + } |
|
373 | + // loop through each of the messengers and if it matches the loaded class |
|
374 | + // then we add this message type to the |
|
375 | + foreach ($mt_reg['messengers_to_validate_with'] as $msgr) { |
|
376 | + if ($messenger->name == $msgr) { |
|
377 | + $valid_types[] = $addon_name; |
|
378 | + } |
|
379 | + } |
|
380 | + } |
|
381 | 381 | |
382 | - return $valid_types; |
|
383 | - } |
|
382 | + return $valid_types; |
|
383 | + } |
|
384 | 384 | |
385 | 385 | |
386 | - /** |
|
387 | - * Callback for `FHEE__EE_Messages_Template_Pack_Default__get_supports` filter to register this message type as |
|
388 | - * supporting the default template pack |
|
389 | - * |
|
390 | - * @param array $supports |
|
391 | - * |
|
392 | - * @return array |
|
393 | - */ |
|
394 | - public static function register_default_template_pack_supports(array $supports): array |
|
395 | - { |
|
396 | - foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) { |
|
397 | - if (empty($mt_reg['messengers_supporting_default_template_pack_with'])) { |
|
398 | - continue; |
|
399 | - } |
|
400 | - foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) { |
|
401 | - $supports[ $messenger_slug ][] = $addon_name; |
|
402 | - } |
|
403 | - } |
|
404 | - return $supports; |
|
405 | - } |
|
386 | + /** |
|
387 | + * Callback for `FHEE__EE_Messages_Template_Pack_Default__get_supports` filter to register this message type as |
|
388 | + * supporting the default template pack |
|
389 | + * |
|
390 | + * @param array $supports |
|
391 | + * |
|
392 | + * @return array |
|
393 | + */ |
|
394 | + public static function register_default_template_pack_supports(array $supports): array |
|
395 | + { |
|
396 | + foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) { |
|
397 | + if (empty($mt_reg['messengers_supporting_default_template_pack_with'])) { |
|
398 | + continue; |
|
399 | + } |
|
400 | + foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) { |
|
401 | + $supports[ $messenger_slug ][] = $addon_name; |
|
402 | + } |
|
403 | + } |
|
404 | + return $supports; |
|
405 | + } |
|
406 | 406 | |
407 | 407 | |
408 | - /** |
|
409 | - * Callback for FHEE__EE_Template_Pack___get_specific_template__filtered_base_path |
|
410 | - * |
|
411 | - * @param string $base_path The original base path for message templates |
|
412 | - * @param EE_messenger $messenger |
|
413 | - * @param EE_message_type $message_type |
|
414 | - * @param string $field The field requesting a template |
|
415 | - * @param string $context The context requesting a template |
|
416 | - * @param EE_Messages_Template_Pack $template_pack |
|
417 | - * |
|
418 | - * @return string |
|
419 | - */ |
|
420 | - public static function register_base_template_path( |
|
421 | - string $base_path, |
|
422 | - EE_messenger $messenger, |
|
423 | - EE_message_type $message_type, |
|
424 | - string $field, |
|
425 | - string $context, |
|
426 | - EE_Messages_Template_Pack $template_pack |
|
427 | - ): string { |
|
428 | - if ( |
|
429 | - ! $template_pack instanceof EE_Messages_Template_Pack_Default |
|
430 | - || ! $message_type instanceof EE_message_type |
|
431 | - ) { |
|
432 | - return $base_path; |
|
433 | - } |
|
434 | - foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) { |
|
435 | - if ( |
|
436 | - $message_type->name === $addon_name |
|
437 | - && ! empty($mt_reg['base_path_for_default_templates']) |
|
438 | - ) { |
|
439 | - return $mt_reg['base_path_for_default_templates']; |
|
440 | - } |
|
441 | - } |
|
442 | - return $base_path; |
|
443 | - } |
|
408 | + /** |
|
409 | + * Callback for FHEE__EE_Template_Pack___get_specific_template__filtered_base_path |
|
410 | + * |
|
411 | + * @param string $base_path The original base path for message templates |
|
412 | + * @param EE_messenger $messenger |
|
413 | + * @param EE_message_type $message_type |
|
414 | + * @param string $field The field requesting a template |
|
415 | + * @param string $context The context requesting a template |
|
416 | + * @param EE_Messages_Template_Pack $template_pack |
|
417 | + * |
|
418 | + * @return string |
|
419 | + */ |
|
420 | + public static function register_base_template_path( |
|
421 | + string $base_path, |
|
422 | + EE_messenger $messenger, |
|
423 | + EE_message_type $message_type, |
|
424 | + string $field, |
|
425 | + string $context, |
|
426 | + EE_Messages_Template_Pack $template_pack |
|
427 | + ): string { |
|
428 | + if ( |
|
429 | + ! $template_pack instanceof EE_Messages_Template_Pack_Default |
|
430 | + || ! $message_type instanceof EE_message_type |
|
431 | + ) { |
|
432 | + return $base_path; |
|
433 | + } |
|
434 | + foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) { |
|
435 | + if ( |
|
436 | + $message_type->name === $addon_name |
|
437 | + && ! empty($mt_reg['base_path_for_default_templates']) |
|
438 | + ) { |
|
439 | + return $mt_reg['base_path_for_default_templates']; |
|
440 | + } |
|
441 | + } |
|
442 | + return $base_path; |
|
443 | + } |
|
444 | 444 | |
445 | 445 | |
446 | - /** |
|
447 | - * Callback for FHEE__EE_Messages_Template_Pack__get_variation__base_path and |
|
448 | - * FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url hooks |
|
449 | - * |
|
450 | - * @param string $base_path_or_url The original incoming base url or path |
|
451 | - * @param string $messenger_slug The slug of the messenger the template is being generated |
|
452 | - * for. |
|
453 | - * @param string $message_type_slug The slug of the message type the template is being generated |
|
454 | - * for. |
|
455 | - * @param string $type The "type" of css being requested. |
|
456 | - * @param string $variation The variation being requested. |
|
457 | - * @param bool $url whether a url or path is being requested. |
|
458 | - * @param string $file_extension What file extension is expected for the variation file. |
|
459 | - * @param EE_Messages_Template_Pack $template_pack |
|
460 | - * |
|
461 | - * @return string |
|
462 | - */ |
|
463 | - public static function register_variation_base_path_or_url( |
|
464 | - string $base_path_or_url, |
|
465 | - string $messenger_slug, |
|
466 | - string $message_type_slug, |
|
467 | - string $type, |
|
468 | - string $variation, |
|
469 | - bool $url, |
|
470 | - string $file_extension, |
|
471 | - EE_Messages_Template_Pack $template_pack |
|
472 | - ): string { |
|
473 | - if (! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
474 | - return $base_path_or_url; |
|
475 | - } |
|
476 | - foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) { |
|
477 | - if ($addon_name === $message_type_slug) { |
|
478 | - if ($url && ! empty($mt_reg['base_url_for_default_variation'])) { |
|
479 | - return $mt_reg['base_url_for_default_variation']; |
|
480 | - } |
|
481 | - if (! $url && ! empty($mt_reg['base_path_for_default_variation'])) { |
|
482 | - return $mt_reg['base_path_for_default_variation']; |
|
483 | - } |
|
484 | - } |
|
485 | - } |
|
486 | - return $base_path_or_url; |
|
487 | - } |
|
446 | + /** |
|
447 | + * Callback for FHEE__EE_Messages_Template_Pack__get_variation__base_path and |
|
448 | + * FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url hooks |
|
449 | + * |
|
450 | + * @param string $base_path_or_url The original incoming base url or path |
|
451 | + * @param string $messenger_slug The slug of the messenger the template is being generated |
|
452 | + * for. |
|
453 | + * @param string $message_type_slug The slug of the message type the template is being generated |
|
454 | + * for. |
|
455 | + * @param string $type The "type" of css being requested. |
|
456 | + * @param string $variation The variation being requested. |
|
457 | + * @param bool $url whether a url or path is being requested. |
|
458 | + * @param string $file_extension What file extension is expected for the variation file. |
|
459 | + * @param EE_Messages_Template_Pack $template_pack |
|
460 | + * |
|
461 | + * @return string |
|
462 | + */ |
|
463 | + public static function register_variation_base_path_or_url( |
|
464 | + string $base_path_or_url, |
|
465 | + string $messenger_slug, |
|
466 | + string $message_type_slug, |
|
467 | + string $type, |
|
468 | + string $variation, |
|
469 | + bool $url, |
|
470 | + string $file_extension, |
|
471 | + EE_Messages_Template_Pack $template_pack |
|
472 | + ): string { |
|
473 | + if (! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
474 | + return $base_path_or_url; |
|
475 | + } |
|
476 | + foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) { |
|
477 | + if ($addon_name === $message_type_slug) { |
|
478 | + if ($url && ! empty($mt_reg['base_url_for_default_variation'])) { |
|
479 | + return $mt_reg['base_url_for_default_variation']; |
|
480 | + } |
|
481 | + if (! $url && ! empty($mt_reg['base_path_for_default_variation'])) { |
|
482 | + return $mt_reg['base_path_for_default_variation']; |
|
483 | + } |
|
484 | + } |
|
485 | + } |
|
486 | + return $base_path_or_url; |
|
487 | + } |
|
488 | 488 | |
489 | 489 | |
490 | - public static function reset(): void |
|
491 | - { |
|
492 | - self::$_ee_message_type_registry = []; |
|
493 | - } |
|
490 | + public static function reset(): void |
|
491 | + { |
|
492 | + self::$_ee_message_type_registry = []; |
|
493 | + } |
|
494 | 494 | } |
@@ -14,222 +14,222 @@ |
||
14 | 14 | */ |
15 | 15 | class EE_Register_Capabilities implements EEI_Plugin_API |
16 | 16 | { |
17 | - /** |
|
18 | - * Holds the settings for a specific registration. |
|
19 | - * |
|
20 | - * @var array |
|
21 | - */ |
|
22 | - protected static $_registry = []; |
|
17 | + /** |
|
18 | + * Holds the settings for a specific registration. |
|
19 | + * |
|
20 | + * @var array |
|
21 | + */ |
|
22 | + protected static $_registry = []; |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * Used to register capability items with EE core. |
|
27 | - * |
|
28 | - * @param string $addon_name usually will be a class name |
|
29 | - * that references capability |
|
30 | - * related items setup for |
|
31 | - * something. |
|
32 | - * @param array $setup_args { |
|
33 | - * An array of items related to |
|
34 | - * registering capabilities. |
|
35 | - * @type array $capabilities An array mapping capability |
|
36 | - * strings to core WP Role. |
|
37 | - * Something like: array( |
|
38 | - * 'administrator' => array( |
|
39 | - * 'read_cap', 'edit_cap', |
|
40 | - * 'delete_cap'), |
|
41 | - * 'author' => |
|
42 | - * array( 'read_cap' ) |
|
43 | - * ). |
|
44 | - * @type array $capability_maps EE_Meta_Capability_Map[] |
|
45 | - * @return bool |
|
46 | - * @throws EE_Error |
|
47 | - * @since 4.5.0 |
|
48 | - * @see EE_Capabilities.php for php docs on these objects. |
|
49 | - * Should be indexed by the |
|
50 | - * classname for the capability |
|
51 | - * map and values representing |
|
52 | - * the arguments for the map. |
|
53 | - * } |
|
54 | - */ |
|
55 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
56 | - { |
|
57 | - // required fields MUST be present, so let's make sure they are. |
|
58 | - if ($addon_name === null || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
59 | - throw new EE_Error( |
|
60 | - esc_html__( |
|
61 | - '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".', |
|
62 | - 'event_espresso' |
|
63 | - ) |
|
64 | - ); |
|
65 | - } |
|
66 | - // make sure we don't register twice |
|
67 | - if (isset(self::$_registry[ $addon_name ])) { |
|
68 | - return true; |
|
69 | - } |
|
70 | - // make sure this is not registered too late or too early. |
|
71 | - if ( |
|
72 | - ! 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 | - esc_html__( |
|
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 | - $addon_name |
|
83 | - ), |
|
84 | - '4.5.0' |
|
85 | - ); |
|
86 | - return false; |
|
87 | - } |
|
88 | - // some preliminary sanitization and setting to the $_registry property |
|
89 | - self::$_registry[ $addon_name ] = [ |
|
90 | - 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) |
|
91 | - ? $setup_args['capabilities'] |
|
92 | - : [], |
|
93 | - 'cap_maps' => $setup_args['capability_maps'] ?? [], |
|
94 | - ]; |
|
95 | - // set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once) |
|
96 | - add_filter( |
|
97 | - 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
98 | - ['EE_Register_Capabilities', 'register_capabilities'] |
|
99 | - ); |
|
100 | - // add filter for cap maps |
|
101 | - add_filter( |
|
102 | - 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
103 | - ['EE_Register_Capabilities', 'register_cap_maps'] |
|
104 | - ); |
|
105 | - return true; |
|
106 | - } |
|
25 | + /** |
|
26 | + * Used to register capability items with EE core. |
|
27 | + * |
|
28 | + * @param string $addon_name usually will be a class name |
|
29 | + * that references capability |
|
30 | + * related items setup for |
|
31 | + * something. |
|
32 | + * @param array $setup_args { |
|
33 | + * An array of items related to |
|
34 | + * registering capabilities. |
|
35 | + * @type array $capabilities An array mapping capability |
|
36 | + * strings to core WP Role. |
|
37 | + * Something like: array( |
|
38 | + * 'administrator' => array( |
|
39 | + * 'read_cap', 'edit_cap', |
|
40 | + * 'delete_cap'), |
|
41 | + * 'author' => |
|
42 | + * array( 'read_cap' ) |
|
43 | + * ). |
|
44 | + * @type array $capability_maps EE_Meta_Capability_Map[] |
|
45 | + * @return bool |
|
46 | + * @throws EE_Error |
|
47 | + * @since 4.5.0 |
|
48 | + * @see EE_Capabilities.php for php docs on these objects. |
|
49 | + * Should be indexed by the |
|
50 | + * classname for the capability |
|
51 | + * map and values representing |
|
52 | + * the arguments for the map. |
|
53 | + * } |
|
54 | + */ |
|
55 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
56 | + { |
|
57 | + // required fields MUST be present, so let's make sure they are. |
|
58 | + if ($addon_name === null || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
59 | + throw new EE_Error( |
|
60 | + esc_html__( |
|
61 | + '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".', |
|
62 | + 'event_espresso' |
|
63 | + ) |
|
64 | + ); |
|
65 | + } |
|
66 | + // make sure we don't register twice |
|
67 | + if (isset(self::$_registry[ $addon_name ])) { |
|
68 | + return true; |
|
69 | + } |
|
70 | + // make sure this is not registered too late or too early. |
|
71 | + if ( |
|
72 | + ! 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 | + esc_html__( |
|
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 | + $addon_name |
|
83 | + ), |
|
84 | + '4.5.0' |
|
85 | + ); |
|
86 | + return false; |
|
87 | + } |
|
88 | + // some preliminary sanitization and setting to the $_registry property |
|
89 | + self::$_registry[ $addon_name ] = [ |
|
90 | + 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) |
|
91 | + ? $setup_args['capabilities'] |
|
92 | + : [], |
|
93 | + 'cap_maps' => $setup_args['capability_maps'] ?? [], |
|
94 | + ]; |
|
95 | + // set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once) |
|
96 | + add_filter( |
|
97 | + 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
98 | + ['EE_Register_Capabilities', 'register_capabilities'] |
|
99 | + ); |
|
100 | + // add filter for cap maps |
|
101 | + add_filter( |
|
102 | + 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
103 | + ['EE_Register_Capabilities', 'register_cap_maps'] |
|
104 | + ); |
|
105 | + return true; |
|
106 | + } |
|
107 | 107 | |
108 | 108 | |
109 | - /** |
|
110 | - * callback for FHEE__EE_Capabilities__init_caps_map__caps filter. |
|
111 | - * Takes care of registering additional capabilities to the caps map. Note, that this also on the initial |
|
112 | - * registration ensures that new capabilities are added to existing roles. |
|
113 | - * |
|
114 | - * @param array $incoming_caps The original caps map. |
|
115 | - * @return array merged in new caps. |
|
116 | - */ |
|
117 | - public static function register_capabilities(array $incoming_caps): array |
|
118 | - { |
|
119 | - $caps = []; |
|
120 | - foreach (self::$_registry as $caps_and_cap_map) { |
|
121 | - $caps[] = $caps_and_cap_map['caps']; |
|
122 | - } |
|
123 | - return array_merge_recursive($incoming_caps, ...$caps); |
|
124 | - } |
|
109 | + /** |
|
110 | + * callback for FHEE__EE_Capabilities__init_caps_map__caps filter. |
|
111 | + * Takes care of registering additional capabilities to the caps map. Note, that this also on the initial |
|
112 | + * registration ensures that new capabilities are added to existing roles. |
|
113 | + * |
|
114 | + * @param array $incoming_caps The original caps map. |
|
115 | + * @return array merged in new caps. |
|
116 | + */ |
|
117 | + public static function register_capabilities(array $incoming_caps): array |
|
118 | + { |
|
119 | + $caps = []; |
|
120 | + foreach (self::$_registry as $caps_and_cap_map) { |
|
121 | + $caps[] = $caps_and_cap_map['caps']; |
|
122 | + } |
|
123 | + return array_merge_recursive($incoming_caps, ...$caps); |
|
124 | + } |
|
125 | 125 | |
126 | 126 | |
127 | - /** |
|
128 | - * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of |
|
129 | - * capability maps for the WP meta_caps filter called in EE_Capabilities. |
|
130 | - * |
|
131 | - * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array. |
|
132 | - * @return EE_Meta_Capability_Map[] |
|
133 | - * @throws EE_Error |
|
134 | - * @since 4.5.0 |
|
135 | - */ |
|
136 | - public static function register_cap_maps(array $cap_maps): array |
|
137 | - { |
|
138 | - // loop through and instantiate cap maps. |
|
139 | - foreach (self::$_registry as $addon_name => $setup) { |
|
140 | - if (! isset($setup['cap_maps'])) { |
|
141 | - continue; |
|
142 | - } |
|
143 | - foreach ($setup['cap_maps'] as $cap_class => $args) { |
|
127 | + /** |
|
128 | + * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of |
|
129 | + * capability maps for the WP meta_caps filter called in EE_Capabilities. |
|
130 | + * |
|
131 | + * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array. |
|
132 | + * @return EE_Meta_Capability_Map[] |
|
133 | + * @throws EE_Error |
|
134 | + * @since 4.5.0 |
|
135 | + */ |
|
136 | + public static function register_cap_maps(array $cap_maps): array |
|
137 | + { |
|
138 | + // loop through and instantiate cap maps. |
|
139 | + foreach (self::$_registry as $addon_name => $setup) { |
|
140 | + if (! isset($setup['cap_maps'])) { |
|
141 | + continue; |
|
142 | + } |
|
143 | + foreach ($setup['cap_maps'] as $cap_class => $args) { |
|
144 | 144 | |
145 | - /** |
|
146 | - * account for cases where capability maps may be indexed |
|
147 | - * numerically to allow for the same map class to be utilized |
|
148 | - * In those cases, maps will be setup in an array like: |
|
149 | - * array( |
|
150 | - * 0 => array( 'EE_Meta_Capability' => array( |
|
151 | - * 'ee_edit_cap', array( 'Object_Name', |
|
152 | - * 'ee_edit_published_cap', |
|
153 | - * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
154 | - * ) ) |
|
155 | - * 1 => ... |
|
156 | - * ) |
|
157 | - * instead of: |
|
158 | - * array( |
|
159 | - * 'EE_Meta_Capability' => array( |
|
160 | - * 'ee_edit_cap', array( 'Object_Name', |
|
161 | - * 'ee_edit_published_cap', |
|
162 | - * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
163 | - * ), |
|
164 | - * ... |
|
165 | - * ) |
|
166 | - */ |
|
167 | - if (is_numeric($cap_class)) { |
|
168 | - $cap_class = key($args); |
|
169 | - $args = $args[ $cap_class ]; |
|
170 | - } |
|
145 | + /** |
|
146 | + * account for cases where capability maps may be indexed |
|
147 | + * numerically to allow for the same map class to be utilized |
|
148 | + * In those cases, maps will be setup in an array like: |
|
149 | + * array( |
|
150 | + * 0 => array( 'EE_Meta_Capability' => array( |
|
151 | + * 'ee_edit_cap', array( 'Object_Name', |
|
152 | + * 'ee_edit_published_cap', |
|
153 | + * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
154 | + * ) ) |
|
155 | + * 1 => ... |
|
156 | + * ) |
|
157 | + * instead of: |
|
158 | + * array( |
|
159 | + * 'EE_Meta_Capability' => array( |
|
160 | + * 'ee_edit_cap', array( 'Object_Name', |
|
161 | + * 'ee_edit_published_cap', |
|
162 | + * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
163 | + * ), |
|
164 | + * ... |
|
165 | + * ) |
|
166 | + */ |
|
167 | + if (is_numeric($cap_class)) { |
|
168 | + $cap_class = key($args); |
|
169 | + $args = $args[ $cap_class ]; |
|
170 | + } |
|
171 | 171 | |
172 | - if (! class_exists($cap_class)) { |
|
173 | - throw new EE_Error( |
|
174 | - sprintf( |
|
175 | - esc_html__( |
|
176 | - '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', |
|
177 | - 'event_espresso' |
|
178 | - ), |
|
179 | - $addon_name |
|
180 | - ) |
|
181 | - ); |
|
182 | - } |
|
172 | + if (! class_exists($cap_class)) { |
|
173 | + throw new EE_Error( |
|
174 | + sprintf( |
|
175 | + esc_html__( |
|
176 | + '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', |
|
177 | + 'event_espresso' |
|
178 | + ), |
|
179 | + $addon_name |
|
180 | + ) |
|
181 | + ); |
|
182 | + } |
|
183 | 183 | |
184 | - if (count($args) !== 2) { |
|
185 | - throw new EE_Error( |
|
186 | - sprintf( |
|
187 | - esc_html__( |
|
188 | - '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.', |
|
189 | - 'event_espresso' |
|
190 | - ), |
|
191 | - $addon_name |
|
192 | - ) |
|
193 | - ); |
|
194 | - } |
|
195 | - $cap_maps[] = new $cap_class($args[0], $args[1]); |
|
196 | - } |
|
197 | - } |
|
198 | - return $cap_maps; |
|
199 | - } |
|
184 | + if (count($args) !== 2) { |
|
185 | + throw new EE_Error( |
|
186 | + sprintf( |
|
187 | + esc_html__( |
|
188 | + '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.', |
|
189 | + 'event_espresso' |
|
190 | + ), |
|
191 | + $addon_name |
|
192 | + ) |
|
193 | + ); |
|
194 | + } |
|
195 | + $cap_maps[] = new $cap_class($args[0], $args[1]); |
|
196 | + } |
|
197 | + } |
|
198 | + return $cap_maps; |
|
199 | + } |
|
200 | 200 | |
201 | 201 | |
202 | - /** |
|
203 | - * @param string $addon_name |
|
204 | - * @throws InvalidArgumentException |
|
205 | - * @throws InvalidDataTypeException |
|
206 | - * @throws InvalidInterfaceException |
|
207 | - */ |
|
208 | - public static function deregister(string $addon_name = '') |
|
209 | - { |
|
210 | - if (! empty(self::$_registry[ $addon_name ])) { |
|
211 | - if (! empty(self::$_registry[ $addon_name ]['caps'])) { |
|
212 | - // if it's too early to remove capabilities, wait to do this until core is loaded and ready |
|
213 | - $caps_to_remove = self::$_registry[ $addon_name ]['caps']; |
|
214 | - if (did_action('AHEE__EE_System__core_loaded_and_ready')) { |
|
215 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
216 | - $capabilities->removeCaps($caps_to_remove); |
|
217 | - } else { |
|
218 | - add_action( |
|
219 | - 'AHEE__EE_System__core_loaded_and_ready', |
|
220 | - function () use ($caps_to_remove) { |
|
221 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
222 | - $capabilities->removeCaps($caps_to_remove); |
|
223 | - } |
|
224 | - ); |
|
225 | - } |
|
226 | - } |
|
227 | - } |
|
228 | - unset(self::$_registry[ $addon_name ]); |
|
229 | - } |
|
202 | + /** |
|
203 | + * @param string $addon_name |
|
204 | + * @throws InvalidArgumentException |
|
205 | + * @throws InvalidDataTypeException |
|
206 | + * @throws InvalidInterfaceException |
|
207 | + */ |
|
208 | + public static function deregister(string $addon_name = '') |
|
209 | + { |
|
210 | + if (! empty(self::$_registry[ $addon_name ])) { |
|
211 | + if (! empty(self::$_registry[ $addon_name ]['caps'])) { |
|
212 | + // if it's too early to remove capabilities, wait to do this until core is loaded and ready |
|
213 | + $caps_to_remove = self::$_registry[ $addon_name ]['caps']; |
|
214 | + if (did_action('AHEE__EE_System__core_loaded_and_ready')) { |
|
215 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
216 | + $capabilities->removeCaps($caps_to_remove); |
|
217 | + } else { |
|
218 | + add_action( |
|
219 | + 'AHEE__EE_System__core_loaded_and_ready', |
|
220 | + function () use ($caps_to_remove) { |
|
221 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
222 | + $capabilities->removeCaps($caps_to_remove); |
|
223 | + } |
|
224 | + ); |
|
225 | + } |
|
226 | + } |
|
227 | + } |
|
228 | + unset(self::$_registry[ $addon_name ]); |
|
229 | + } |
|
230 | 230 | |
231 | - public static function reset(): void |
|
232 | - { |
|
233 | - self::$_registry = []; |
|
234 | - } |
|
231 | + public static function reset(): void |
|
232 | + { |
|
233 | + self::$_registry = []; |
|
234 | + } |
|
235 | 235 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | ); |
65 | 65 | } |
66 | 66 | // make sure we don't register twice |
67 | - if (isset(self::$_registry[ $addon_name ])) { |
|
67 | + if (isset(self::$_registry[$addon_name])) { |
|
68 | 68 | return true; |
69 | 69 | } |
70 | 70 | // make sure this is not registered too late or too early. |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | return false; |
87 | 87 | } |
88 | 88 | // some preliminary sanitization and setting to the $_registry property |
89 | - self::$_registry[ $addon_name ] = [ |
|
89 | + self::$_registry[$addon_name] = [ |
|
90 | 90 | 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) |
91 | 91 | ? $setup_args['capabilities'] |
92 | 92 | : [], |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | { |
138 | 138 | // loop through and instantiate cap maps. |
139 | 139 | foreach (self::$_registry as $addon_name => $setup) { |
140 | - if (! isset($setup['cap_maps'])) { |
|
140 | + if ( ! isset($setup['cap_maps'])) { |
|
141 | 141 | continue; |
142 | 142 | } |
143 | 143 | foreach ($setup['cap_maps'] as $cap_class => $args) { |
@@ -166,10 +166,10 @@ discard block |
||
166 | 166 | */ |
167 | 167 | if (is_numeric($cap_class)) { |
168 | 168 | $cap_class = key($args); |
169 | - $args = $args[ $cap_class ]; |
|
169 | + $args = $args[$cap_class]; |
|
170 | 170 | } |
171 | 171 | |
172 | - if (! class_exists($cap_class)) { |
|
172 | + if ( ! class_exists($cap_class)) { |
|
173 | 173 | throw new EE_Error( |
174 | 174 | sprintf( |
175 | 175 | esc_html__( |
@@ -207,17 +207,17 @@ discard block |
||
207 | 207 | */ |
208 | 208 | public static function deregister(string $addon_name = '') |
209 | 209 | { |
210 | - if (! empty(self::$_registry[ $addon_name ])) { |
|
211 | - if (! empty(self::$_registry[ $addon_name ]['caps'])) { |
|
210 | + if ( ! empty(self::$_registry[$addon_name])) { |
|
211 | + if ( ! empty(self::$_registry[$addon_name]['caps'])) { |
|
212 | 212 | // if it's too early to remove capabilities, wait to do this until core is loaded and ready |
213 | - $caps_to_remove = self::$_registry[ $addon_name ]['caps']; |
|
213 | + $caps_to_remove = self::$_registry[$addon_name]['caps']; |
|
214 | 214 | if (did_action('AHEE__EE_System__core_loaded_and_ready')) { |
215 | 215 | $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
216 | 216 | $capabilities->removeCaps($caps_to_remove); |
217 | 217 | } else { |
218 | 218 | add_action( |
219 | 219 | 'AHEE__EE_System__core_loaded_and_ready', |
220 | - function () use ($caps_to_remove) { |
|
220 | + function() use ($caps_to_remove) { |
|
221 | 221 | $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
222 | 222 | $capabilities->removeCaps($caps_to_remove); |
223 | 223 | } |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | } |
226 | 226 | } |
227 | 227 | } |
228 | - unset(self::$_registry[ $addon_name ]); |
|
228 | + unset(self::$_registry[$addon_name]); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | public static function reset(): void |
@@ -18,169 +18,169 @@ |
||
18 | 18 | */ |
19 | 19 | class EE_Register_Payment_Method implements EEI_Plugin_API |
20 | 20 | { |
21 | - /** |
|
22 | - * Holds values for registered payment methods |
|
23 | - * |
|
24 | - * @var array |
|
25 | - */ |
|
26 | - protected static $_settings = []; |
|
21 | + /** |
|
22 | + * Holds values for registered payment methods |
|
23 | + * |
|
24 | + * @var array |
|
25 | + */ |
|
26 | + protected static $_settings = []; |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * Method for registering new EE_PMT_Base children |
|
31 | - * |
|
32 | - * @param string $addon_name a unique identifier for this set of modules Required. |
|
33 | - * @param array $setup_args an array of arguments provided for registering modules Required.{ |
|
34 | - * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class |
|
35 | - * (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains |
|
36 | - * the files EE_PMT_Payomatic.pm.php) |
|
37 | - * } |
|
38 | - * @return bool |
|
39 | - * @throws EE_Error |
|
40 | - * @type array payment_method_paths an array of full server paths to folders containing any EE_PMT_Base |
|
41 | - * children, or to the EED_Module files themselves |
|
42 | - * @throws InvalidDataTypeException |
|
43 | - * @throws DomainException |
|
44 | - * @throws InvalidArgumentException |
|
45 | - * @throws InvalidInterfaceException |
|
46 | - * @throws InvalidDataTypeException |
|
47 | - * @since 4.5.0 |
|
48 | - */ |
|
49 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
50 | - { |
|
51 | - // required fields MUST be present, so let's make sure they are. |
|
52 | - if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) { |
|
53 | - throw new EE_Error( |
|
54 | - esc_html__( |
|
55 | - '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)', |
|
56 | - 'event_espresso' |
|
57 | - ) |
|
58 | - ); |
|
59 | - } |
|
60 | - // make sure we don't register twice |
|
61 | - if (isset(self::$_settings[ $addon_name ])) { |
|
62 | - return true; |
|
63 | - } |
|
64 | - // make sure this was called in the right place! |
|
65 | - if ( |
|
66 | - ! 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[ $addon_name ] = [ |
|
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[ $addon_name ]['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[ $addon_name ]) |
|
101 | - ); |
|
102 | - } |
|
103 | - return true; |
|
104 | - } |
|
29 | + /** |
|
30 | + * Method for registering new EE_PMT_Base children |
|
31 | + * |
|
32 | + * @param string $addon_name a unique identifier for this set of modules Required. |
|
33 | + * @param array $setup_args an array of arguments provided for registering modules Required.{ |
|
34 | + * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class |
|
35 | + * (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains |
|
36 | + * the files EE_PMT_Payomatic.pm.php) |
|
37 | + * } |
|
38 | + * @return bool |
|
39 | + * @throws EE_Error |
|
40 | + * @type array payment_method_paths an array of full server paths to folders containing any EE_PMT_Base |
|
41 | + * children, or to the EED_Module files themselves |
|
42 | + * @throws InvalidDataTypeException |
|
43 | + * @throws DomainException |
|
44 | + * @throws InvalidArgumentException |
|
45 | + * @throws InvalidInterfaceException |
|
46 | + * @throws InvalidDataTypeException |
|
47 | + * @since 4.5.0 |
|
48 | + */ |
|
49 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
50 | + { |
|
51 | + // required fields MUST be present, so let's make sure they are. |
|
52 | + if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) { |
|
53 | + throw new EE_Error( |
|
54 | + esc_html__( |
|
55 | + '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)', |
|
56 | + 'event_espresso' |
|
57 | + ) |
|
58 | + ); |
|
59 | + } |
|
60 | + // make sure we don't register twice |
|
61 | + if (isset(self::$_settings[ $addon_name ])) { |
|
62 | + return true; |
|
63 | + } |
|
64 | + // make sure this was called in the right place! |
|
65 | + if ( |
|
66 | + ! 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[ $addon_name ] = [ |
|
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[ $addon_name ]['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[ $addon_name ]) |
|
101 | + ); |
|
102 | + } |
|
103 | + return true; |
|
104 | + } |
|
105 | 105 | |
106 | 106 | |
107 | - /** |
|
108 | - * Filters the list of payment methods to add ours. |
|
109 | - * and they're just full filepaths to FOLDERS containing a payment method class file. Eg. |
|
110 | - * |
|
111 | - * @param array $payment_method_folders array of paths to all payment methods that require registering |
|
112 | - * @return array |
|
113 | - */ |
|
114 | - public static function add_payment_methods(array $payment_method_folders): array |
|
115 | - { |
|
116 | - $payment_method_paths = []; |
|
117 | - foreach (self::$_settings as $settings) { |
|
118 | - $payment_method_paths[] = $settings['payment_method_paths']; |
|
119 | - } |
|
120 | - return array_merge($payment_method_folders, ...$payment_method_paths); |
|
121 | - } |
|
107 | + /** |
|
108 | + * Filters the list of payment methods to add ours. |
|
109 | + * and they're just full filepaths to FOLDERS containing a payment method class file. Eg. |
|
110 | + * |
|
111 | + * @param array $payment_method_folders array of paths to all payment methods that require registering |
|
112 | + * @return array |
|
113 | + */ |
|
114 | + public static function add_payment_methods(array $payment_method_folders): array |
|
115 | + { |
|
116 | + $payment_method_paths = []; |
|
117 | + foreach (self::$_settings as $settings) { |
|
118 | + $payment_method_paths[] = $settings['payment_method_paths']; |
|
119 | + } |
|
120 | + return array_merge($payment_method_folders, ...$payment_method_paths); |
|
121 | + } |
|
122 | 122 | |
123 | 123 | |
124 | - /** |
|
125 | - * This deregisters a module that was previously registered with a specific $addon_name. |
|
126 | - * |
|
127 | - * @param string $addon_name 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(string $addon_name = '') |
|
136 | - { |
|
137 | - if (isset(self::$_settings[ $addon_name ])) { |
|
138 | - // set action for just this module id to delay deregistration until core is loaded and ready. |
|
139 | - $module_settings = self::$_settings[ $addon_name ]; |
|
140 | - unset(self::$_settings[ $addon_name ]); |
|
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 $addon_name. |
|
126 | + * |
|
127 | + * @param string $addon_name 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(string $addon_name = '') |
|
136 | + { |
|
137 | + if (isset(self::$_settings[ $addon_name ])) { |
|
138 | + // set action for just this module id to delay deregistration until core is loaded and ready. |
|
139 | + $module_settings = self::$_settings[ $addon_name ]; |
|
140 | + unset(self::$_settings[ $addon_name ]); |
|
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): array |
|
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): array |
|
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 | |
181 | 181 | |
182 | - public static function reset(): void |
|
183 | - { |
|
184 | - self::$_settings = []; |
|
185 | - } |
|
182 | + public static function reset(): void |
|
183 | + { |
|
184 | + self::$_settings = []; |
|
185 | + } |
|
186 | 186 | } |
@@ -12,57 +12,57 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Register_Personal_Data_Exporter implements EEI_Plugin_API |
14 | 14 | { |
15 | - /** |
|
16 | - * FQCN for all privacy policy generators |
|
17 | - * |
|
18 | - * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
19 | - */ |
|
20 | - protected static $exporters = []; |
|
15 | + /** |
|
16 | + * FQCN for all privacy policy generators |
|
17 | + * |
|
18 | + * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
19 | + */ |
|
20 | + protected static $exporters = []; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * @param string $addon_name |
|
25 | - * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
26 | - * OR fully qualified class names of privacy policies |
|
27 | - * @return bool |
|
28 | - */ |
|
29 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
30 | - { |
|
31 | - self::$exporters[ $addon_name ] = $setup_args; |
|
32 | - // add to list of modules to be registered |
|
33 | - add_filter( |
|
34 | - 'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters', |
|
35 | - ['EE_Register_Personal_Data_Exporter', 'addExporters'] |
|
36 | - ); |
|
37 | - return true; |
|
38 | - } |
|
23 | + /** |
|
24 | + * @param string $addon_name |
|
25 | + * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
26 | + * OR fully qualified class names of privacy policies |
|
27 | + * @return bool |
|
28 | + */ |
|
29 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
30 | + { |
|
31 | + self::$exporters[ $addon_name ] = $setup_args; |
|
32 | + // add to list of modules to be registered |
|
33 | + add_filter( |
|
34 | + 'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters', |
|
35 | + ['EE_Register_Personal_Data_Exporter', 'addExporters'] |
|
36 | + ); |
|
37 | + return true; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @param string $addon_name |
|
43 | - */ |
|
44 | - public static function deregister(string $addon_name = '') |
|
45 | - { |
|
46 | - unset(self::$exporters[ $addon_name ]); |
|
47 | - } |
|
41 | + /** |
|
42 | + * @param string $addon_name |
|
43 | + */ |
|
44 | + public static function deregister(string $addon_name = '') |
|
45 | + { |
|
46 | + unset(self::$exporters[ $addon_name ]); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * Adds our personal data exporters registered by add-ons |
|
52 | - * |
|
53 | - * @param string[] $exporters |
|
54 | - * @return string[] |
|
55 | - */ |
|
56 | - public static function addExporters(array $exporters): array |
|
57 | - { |
|
58 | - return array_merge($exporters, ...self::$exporters); |
|
59 | - } |
|
50 | + /** |
|
51 | + * Adds our personal data exporters registered by add-ons |
|
52 | + * |
|
53 | + * @param string[] $exporters |
|
54 | + * @return string[] |
|
55 | + */ |
|
56 | + public static function addExporters(array $exporters): array |
|
57 | + { |
|
58 | + return array_merge($exporters, ...self::$exporters); |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - public static function reset(): void |
|
63 | - { |
|
64 | - self::$exporters = []; |
|
65 | - } |
|
62 | + public static function reset(): void |
|
63 | + { |
|
64 | + self::$exporters = []; |
|
65 | + } |
|
66 | 66 | } |
67 | 67 | // End of file EE_Register_Personal_Data_Exporter.lib.php |
68 | 68 | // Location: ${NAMESPACE}/EE_Register_Personal_Data_Exporter.lib.php |
@@ -19,169 +19,169 @@ |
||
19 | 19 | */ |
20 | 20 | class EE_Register_Shortcode implements EEI_Plugin_API |
21 | 21 | { |
22 | - /** |
|
23 | - * Holds values for registered shortcodes |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected static $_settings = []; |
|
22 | + /** |
|
23 | + * Holds values for registered shortcodes |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected static $_settings = []; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * Method for registering new EE_Shortcodes |
|
32 | - * |
|
33 | - * @param string $addon_name a unique identifier for this set of modules Required. |
|
34 | - * @param array $setup_args an array of arguments provided for registering shortcodes Required. |
|
35 | - * @type array shortcode_paths an array of full server paths to folders containing any EES_Shortcodes |
|
36 | - * @type array shortcode_fqcns an array of fully qualified class names for any new shortcode classes to register. |
|
37 | - * Shortcode classes should extend EspressoShortcode |
|
38 | - * and be properly namespaced so they are autoloaded. |
|
39 | - * @return bool |
|
40 | - * @throws EE_Error |
|
41 | - * @since 4.3.0 |
|
42 | - * @since 4.9.46.rc.025 for the new `shortcode_fqcns` array argument. |
|
43 | - */ |
|
44 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
45 | - { |
|
46 | - // required fields MUST be present, so let's make sure they are. |
|
47 | - if ( |
|
48 | - empty($addon_name) |
|
49 | - || ! is_array($setup_args) |
|
50 | - || ( |
|
51 | - empty($setup_args['shortcode_paths']) |
|
52 | - ) |
|
53 | - && empty($setup_args['shortcode_fqcns']) |
|
54 | - ) { |
|
55 | - throw new EE_Error( |
|
56 | - esc_html__( |
|
57 | - '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)', |
|
58 | - 'event_espresso' |
|
59 | - ) |
|
60 | - ); |
|
61 | - } |
|
30 | + /** |
|
31 | + * Method for registering new EE_Shortcodes |
|
32 | + * |
|
33 | + * @param string $addon_name a unique identifier for this set of modules Required. |
|
34 | + * @param array $setup_args an array of arguments provided for registering shortcodes Required. |
|
35 | + * @type array shortcode_paths an array of full server paths to folders containing any EES_Shortcodes |
|
36 | + * @type array shortcode_fqcns an array of fully qualified class names for any new shortcode classes to register. |
|
37 | + * Shortcode classes should extend EspressoShortcode |
|
38 | + * and be properly namespaced so they are autoloaded. |
|
39 | + * @return bool |
|
40 | + * @throws EE_Error |
|
41 | + * @since 4.3.0 |
|
42 | + * @since 4.9.46.rc.025 for the new `shortcode_fqcns` array argument. |
|
43 | + */ |
|
44 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
45 | + { |
|
46 | + // required fields MUST be present, so let's make sure they are. |
|
47 | + if ( |
|
48 | + empty($addon_name) |
|
49 | + || ! is_array($setup_args) |
|
50 | + || ( |
|
51 | + empty($setup_args['shortcode_paths']) |
|
52 | + ) |
|
53 | + && empty($setup_args['shortcode_fqcns']) |
|
54 | + ) { |
|
55 | + throw new EE_Error( |
|
56 | + esc_html__( |
|
57 | + '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)', |
|
58 | + 'event_espresso' |
|
59 | + ) |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | |
63 | - // make sure we don't register twice |
|
64 | - if (isset(self::$_settings[ $addon_name ])) { |
|
65 | - return true; |
|
66 | - } |
|
63 | + // make sure we don't register twice |
|
64 | + if (isset(self::$_settings[ $addon_name ])) { |
|
65 | + return true; |
|
66 | + } |
|
67 | 67 | |
68 | - // make sure this was called in the right place! |
|
69 | - if ( |
|
70 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
71 | - || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
72 | - ) { |
|
73 | - EE_Error::doing_it_wrong( |
|
74 | - __METHOD__, |
|
75 | - esc_html__( |
|
76 | - '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.', |
|
77 | - 'event_espresso' |
|
78 | - ), |
|
79 | - '4.3.0' |
|
80 | - ); |
|
81 | - } |
|
82 | - // setup $_settings array from incoming values. |
|
83 | - self::$_settings[ $addon_name ] = [ |
|
84 | - // array of full server paths to any EES_Shortcodes used by the shortcode |
|
85 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
86 | - ? (array) $setup_args['shortcode_paths'] |
|
87 | - : [], |
|
88 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
89 | - ? (array) $setup_args['shortcode_fqcns'] |
|
90 | - : [], |
|
91 | - ]; |
|
92 | - // add to list of shortcodes to be registered |
|
93 | - add_filter( |
|
94 | - 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
95 | - ['EE_Register_Shortcode', 'add_shortcodes'] |
|
96 | - ); |
|
68 | + // make sure this was called in the right place! |
|
69 | + if ( |
|
70 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
71 | + || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
72 | + ) { |
|
73 | + EE_Error::doing_it_wrong( |
|
74 | + __METHOD__, |
|
75 | + esc_html__( |
|
76 | + '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.', |
|
77 | + 'event_espresso' |
|
78 | + ), |
|
79 | + '4.3.0' |
|
80 | + ); |
|
81 | + } |
|
82 | + // setup $_settings array from incoming values. |
|
83 | + self::$_settings[ $addon_name ] = [ |
|
84 | + // array of full server paths to any EES_Shortcodes used by the shortcode |
|
85 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
86 | + ? (array) $setup_args['shortcode_paths'] |
|
87 | + : [], |
|
88 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
89 | + ? (array) $setup_args['shortcode_fqcns'] |
|
90 | + : [], |
|
91 | + ]; |
|
92 | + // add to list of shortcodes to be registered |
|
93 | + add_filter( |
|
94 | + 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
95 | + ['EE_Register_Shortcode', 'add_shortcodes'] |
|
96 | + ); |
|
97 | 97 | |
98 | - add_filter( |
|
99 | - 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
100 | - ['EE_Register_Shortcode', 'instantiateAndAddToShortcodeCollection'] |
|
101 | - ); |
|
102 | - return true; |
|
103 | - } |
|
98 | + add_filter( |
|
99 | + 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
100 | + ['EE_Register_Shortcode', 'instantiateAndAddToShortcodeCollection'] |
|
101 | + ); |
|
102 | + return true; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * Filters the list of shortcodes to add ours. |
|
108 | - * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg. |
|
109 | - * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey'...) |
|
110 | - * |
|
111 | - * @param array $shortcodes_to_register array of paths to all shortcodes that require registering |
|
112 | - * @return array |
|
113 | - */ |
|
114 | - public static function add_shortcodes(array $shortcodes_to_register): array |
|
115 | - { |
|
116 | - $shortcode_paths = []; |
|
117 | - foreach (self::$_settings as $settings) { |
|
118 | - $shortcode_paths[] = $settings['shortcode_paths']; |
|
119 | - } |
|
120 | - return array_merge($shortcodes_to_register, ...$shortcode_paths); |
|
121 | - } |
|
106 | + /** |
|
107 | + * Filters the list of shortcodes to add ours. |
|
108 | + * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg. |
|
109 | + * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey'...) |
|
110 | + * |
|
111 | + * @param array $shortcodes_to_register array of paths to all shortcodes that require registering |
|
112 | + * @return array |
|
113 | + */ |
|
114 | + public static function add_shortcodes(array $shortcodes_to_register): array |
|
115 | + { |
|
116 | + $shortcode_paths = []; |
|
117 | + foreach (self::$_settings as $settings) { |
|
118 | + $shortcode_paths[] = $settings['shortcode_paths']; |
|
119 | + } |
|
120 | + return array_merge($shortcodes_to_register, ...$shortcode_paths); |
|
121 | + } |
|
122 | 122 | |
123 | 123 | |
124 | - /** |
|
125 | - * Hooks into |
|
126 | - * FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection and |
|
127 | - * registers any provided shortcode fully qualified class names. |
|
128 | - * |
|
129 | - * @param CollectionInterface $shortcodes_collection |
|
130 | - * @return CollectionInterface |
|
131 | - * @throws InvalidArgumentException |
|
132 | - * @throws InvalidClassException |
|
133 | - * @throws InvalidDataTypeException |
|
134 | - * @throws InvalidInterfaceException |
|
135 | - */ |
|
136 | - public static function instantiateAndAddToShortcodeCollection( |
|
137 | - CollectionInterface $shortcodes_collection |
|
138 | - ): CollectionInterface { |
|
139 | - foreach (self::$_settings as $settings) { |
|
140 | - if (! empty($settings['shortcode_fqcns'])) { |
|
141 | - foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) { |
|
142 | - if (! class_exists($shortcode_fqcn)) { |
|
143 | - throw new InvalidClassException( |
|
144 | - sprintf( |
|
145 | - esc_html__( |
|
146 | - 'Are you sure %s is the right fully qualified class name for the shortcode class?', |
|
147 | - 'event_espresso' |
|
148 | - ), |
|
149 | - $shortcode_fqcn |
|
150 | - ) |
|
151 | - ); |
|
152 | - } |
|
153 | - if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) { |
|
154 | - // register dependencies |
|
155 | - EE_Dependency_Map::register_dependencies( |
|
156 | - $shortcode_fqcn, |
|
157 | - [ |
|
158 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
159 | - ] |
|
160 | - ); |
|
161 | - } |
|
162 | - $shortcodes_collection->add(LoaderFactory::getLoader()->getShared($shortcode_fqcn)); |
|
163 | - } |
|
164 | - } |
|
165 | - } |
|
166 | - return $shortcodes_collection; |
|
167 | - } |
|
124 | + /** |
|
125 | + * Hooks into |
|
126 | + * FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection and |
|
127 | + * registers any provided shortcode fully qualified class names. |
|
128 | + * |
|
129 | + * @param CollectionInterface $shortcodes_collection |
|
130 | + * @return CollectionInterface |
|
131 | + * @throws InvalidArgumentException |
|
132 | + * @throws InvalidClassException |
|
133 | + * @throws InvalidDataTypeException |
|
134 | + * @throws InvalidInterfaceException |
|
135 | + */ |
|
136 | + public static function instantiateAndAddToShortcodeCollection( |
|
137 | + CollectionInterface $shortcodes_collection |
|
138 | + ): CollectionInterface { |
|
139 | + foreach (self::$_settings as $settings) { |
|
140 | + if (! empty($settings['shortcode_fqcns'])) { |
|
141 | + foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) { |
|
142 | + if (! class_exists($shortcode_fqcn)) { |
|
143 | + throw new InvalidClassException( |
|
144 | + sprintf( |
|
145 | + esc_html__( |
|
146 | + 'Are you sure %s is the right fully qualified class name for the shortcode class?', |
|
147 | + 'event_espresso' |
|
148 | + ), |
|
149 | + $shortcode_fqcn |
|
150 | + ) |
|
151 | + ); |
|
152 | + } |
|
153 | + if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) { |
|
154 | + // register dependencies |
|
155 | + EE_Dependency_Map::register_dependencies( |
|
156 | + $shortcode_fqcn, |
|
157 | + [ |
|
158 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
159 | + ] |
|
160 | + ); |
|
161 | + } |
|
162 | + $shortcodes_collection->add(LoaderFactory::getLoader()->getShared($shortcode_fqcn)); |
|
163 | + } |
|
164 | + } |
|
165 | + } |
|
166 | + return $shortcodes_collection; |
|
167 | + } |
|
168 | 168 | |
169 | 169 | |
170 | - /** |
|
171 | - * This deregisters a shortcode that was previously registered with a specific $addon_name. |
|
172 | - * |
|
173 | - * @param string $addon_name the name for the shortcode that was previously registered |
|
174 | - * @return void |
|
175 | - * @since 4.3.0 |
|
176 | - */ |
|
177 | - public static function deregister(string $addon_name = '') |
|
178 | - { |
|
179 | - unset(self::$_settings[ $addon_name ]); |
|
180 | - } |
|
170 | + /** |
|
171 | + * This deregisters a shortcode that was previously registered with a specific $addon_name. |
|
172 | + * |
|
173 | + * @param string $addon_name the name for the shortcode that was previously registered |
|
174 | + * @return void |
|
175 | + * @since 4.3.0 |
|
176 | + */ |
|
177 | + public static function deregister(string $addon_name = '') |
|
178 | + { |
|
179 | + unset(self::$_settings[ $addon_name ]); |
|
180 | + } |
|
181 | 181 | |
182 | 182 | |
183 | - public static function reset(): void |
|
184 | - { |
|
185 | - self::$_settings = []; |
|
186 | - } |
|
183 | + public static function reset(): void |
|
184 | + { |
|
185 | + self::$_settings = []; |
|
186 | + } |
|
187 | 187 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | } |
62 | 62 | |
63 | 63 | // make sure we don't register twice |
64 | - if (isset(self::$_settings[ $addon_name ])) { |
|
64 | + if (isset(self::$_settings[$addon_name])) { |
|
65 | 65 | return true; |
66 | 66 | } |
67 | 67 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | ); |
81 | 81 | } |
82 | 82 | // setup $_settings array from incoming values. |
83 | - self::$_settings[ $addon_name ] = [ |
|
83 | + self::$_settings[$addon_name] = [ |
|
84 | 84 | // array of full server paths to any EES_Shortcodes used by the shortcode |
85 | 85 | 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
86 | 86 | ? (array) $setup_args['shortcode_paths'] |
@@ -137,9 +137,9 @@ discard block |
||
137 | 137 | CollectionInterface $shortcodes_collection |
138 | 138 | ): CollectionInterface { |
139 | 139 | foreach (self::$_settings as $settings) { |
140 | - if (! empty($settings['shortcode_fqcns'])) { |
|
140 | + if ( ! empty($settings['shortcode_fqcns'])) { |
|
141 | 141 | foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) { |
142 | - if (! class_exists($shortcode_fqcn)) { |
|
142 | + if ( ! class_exists($shortcode_fqcn)) { |
|
143 | 143 | throw new InvalidClassException( |
144 | 144 | sprintf( |
145 | 145 | esc_html__( |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | ) |
151 | 151 | ); |
152 | 152 | } |
153 | - if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) { |
|
153 | + if ( ! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) { |
|
154 | 154 | // register dependencies |
155 | 155 | EE_Dependency_Map::register_dependencies( |
156 | 156 | $shortcode_fqcn, |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | */ |
177 | 177 | public static function deregister(string $addon_name = '') |
178 | 178 | { |
179 | - unset(self::$_settings[ $addon_name ]); |
|
179 | + unset(self::$_settings[$addon_name]); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 |
@@ -17,30 +17,30 @@ |
||
17 | 17 | */ |
18 | 18 | interface EEI_Plugin_API |
19 | 19 | { |
20 | - /** |
|
21 | - * Used to register a component with EE. |
|
22 | - * |
|
23 | - * @param string $addon_name a unique name for the component being registered |
|
24 | - * @param array $setup_args an array of key value pairs of info for registering the component |
|
25 | - * @return bool |
|
26 | - * @since 4.3.0 |
|
27 | - */ |
|
28 | - public static function register(string $addon_name = '', array $setup_args = []): bool; |
|
20 | + /** |
|
21 | + * Used to register a component with EE. |
|
22 | + * |
|
23 | + * @param string $addon_name a unique name for the component being registered |
|
24 | + * @param array $setup_args an array of key value pairs of info for registering the component |
|
25 | + * @return bool |
|
26 | + * @since 4.3.0 |
|
27 | + */ |
|
28 | + public static function register(string $addon_name = '', array $setup_args = []): bool; |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * Used to deregister a component with EE. |
|
33 | - * |
|
34 | - * @param string $addon_name a unique name for the component being registered |
|
35 | - * @return void |
|
36 | - * @since 4.3.0 |
|
37 | - */ |
|
38 | - public static function deregister(string $addon_name = ''); |
|
31 | + /** |
|
32 | + * Used to deregister a component with EE. |
|
33 | + * |
|
34 | + * @param string $addon_name a unique name for the component being registered |
|
35 | + * @return void |
|
36 | + * @since 4.3.0 |
|
37 | + */ |
|
38 | + public static function deregister(string $addon_name = ''); |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @return void |
|
43 | - * @since 5.0.8.p |
|
44 | - */ |
|
45 | - public static function reset(): void; |
|
41 | + /** |
|
42 | + * @return void |
|
43 | + * @since 5.0.8.p |
|
44 | + */ |
|
45 | + public static function reset(): void; |
|
46 | 46 | } |
@@ -11,144 +11,144 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Register_Model_Extensions implements EEI_Plugin_API |
13 | 13 | { |
14 | - protected static $_registry; |
|
14 | + protected static $_registry; |
|
15 | 15 | |
16 | - protected static $_extensions = []; |
|
16 | + protected static $_extensions = []; |
|
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * register method for setting up model extensions |
|
21 | - * |
|
22 | - * @param string $addon_name unique id for the extensions being setup |
|
23 | - * @param array $setup_args { |
|
24 | - * @return bool |
|
25 | - * @throws EE_Error |
|
26 | - * @type array $model_extension_paths array of folders containing DB model extensions, where each file follows |
|
27 | - * the models naming convention, which is: |
|
28 | - * EEME_{your_plugin_slug}_model_name_extended}.model_ext.php. |
|
29 | - * Where {your_plugin_slug} is really anything you want (but something having |
|
30 | - * to do with your addon, like 'Calendar' or '3D_View') and |
|
31 | - * model_name_extended} is the model extended. |
|
32 | - * The class contained in teh file should extend |
|
33 | - * EEME_Base_{model_name_extended}.model_ext.php. |
|
34 | - * Where {your_plugin_slug} is really anything you want (but something |
|
35 | - * having to do with your addon, like 'Calendar' or '3D_View') and |
|
36 | - * {model_name_extended} is the model extended. The class contained in teh |
|
37 | - * file should extend EEME_Base |
|
38 | - * @type array $class_extension_paths array of folders containing DB class extensions, where each file follows |
|
39 | - * the model class extension naming convention, which is: |
|
40 | - * EEE_{your_plugin_slug}_model_name_extended}.class_ext.php. |
|
41 | - * Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc, |
|
42 | - * and model_name_extended} is the name of the model extended, eg |
|
43 | - * 'Attendee','Event',etc. |
|
44 | - * The class contained in the file should extend EEE_Base_Class |
|
45 | - * ._{model_name_extended}.class_ext.php. |
|
46 | - * Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc, |
|
47 | - * and {model_name_extended} is the name of the model extended, eg |
|
48 | - * 'Attendee','Event',etc. The class contained in the file should extend |
|
49 | - * EEE_Base_Class. |
|
50 | - * } |
|
51 | - * |
|
52 | - */ |
|
53 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
54 | - { |
|
55 | - // required fields MUST be present, so let's make sure they are. |
|
56 | - if ( |
|
57 | - empty($addon_name) |
|
58 | - || ! is_array($setup_args) |
|
59 | - || ( |
|
60 | - empty($setup_args['model_extension_paths']) |
|
61 | - && empty($setup_args['class_extension_paths']) |
|
62 | - ) |
|
63 | - ) { |
|
64 | - throw new EE_Error( |
|
65 | - esc_html__( |
|
66 | - '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)', |
|
67 | - 'event_espresso' |
|
68 | - ) |
|
69 | - ); |
|
70 | - } |
|
19 | + /** |
|
20 | + * register method for setting up model extensions |
|
21 | + * |
|
22 | + * @param string $addon_name unique id for the extensions being setup |
|
23 | + * @param array $setup_args { |
|
24 | + * @return bool |
|
25 | + * @throws EE_Error |
|
26 | + * @type array $model_extension_paths array of folders containing DB model extensions, where each file follows |
|
27 | + * the models naming convention, which is: |
|
28 | + * EEME_{your_plugin_slug}_model_name_extended}.model_ext.php. |
|
29 | + * Where {your_plugin_slug} is really anything you want (but something having |
|
30 | + * to do with your addon, like 'Calendar' or '3D_View') and |
|
31 | + * model_name_extended} is the model extended. |
|
32 | + * The class contained in teh file should extend |
|
33 | + * EEME_Base_{model_name_extended}.model_ext.php. |
|
34 | + * Where {your_plugin_slug} is really anything you want (but something |
|
35 | + * having to do with your addon, like 'Calendar' or '3D_View') and |
|
36 | + * {model_name_extended} is the model extended. The class contained in teh |
|
37 | + * file should extend EEME_Base |
|
38 | + * @type array $class_extension_paths array of folders containing DB class extensions, where each file follows |
|
39 | + * the model class extension naming convention, which is: |
|
40 | + * EEE_{your_plugin_slug}_model_name_extended}.class_ext.php. |
|
41 | + * Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc, |
|
42 | + * and model_name_extended} is the name of the model extended, eg |
|
43 | + * 'Attendee','Event',etc. |
|
44 | + * The class contained in the file should extend EEE_Base_Class |
|
45 | + * ._{model_name_extended}.class_ext.php. |
|
46 | + * Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc, |
|
47 | + * and {model_name_extended} is the name of the model extended, eg |
|
48 | + * 'Attendee','Event',etc. The class contained in the file should extend |
|
49 | + * EEE_Base_Class. |
|
50 | + * } |
|
51 | + * |
|
52 | + */ |
|
53 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
54 | + { |
|
55 | + // required fields MUST be present, so let's make sure they are. |
|
56 | + if ( |
|
57 | + empty($addon_name) |
|
58 | + || ! is_array($setup_args) |
|
59 | + || ( |
|
60 | + empty($setup_args['model_extension_paths']) |
|
61 | + && empty($setup_args['class_extension_paths']) |
|
62 | + ) |
|
63 | + ) { |
|
64 | + throw new EE_Error( |
|
65 | + esc_html__( |
|
66 | + '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)', |
|
67 | + 'event_espresso' |
|
68 | + ) |
|
69 | + ); |
|
70 | + } |
|
71 | 71 | |
72 | - // make sure we don't register twice |
|
73 | - if (isset(self::$_registry[ $addon_name ])) { |
|
74 | - return true; |
|
75 | - } |
|
76 | - // check correct loading |
|
77 | - if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) { |
|
78 | - EE_Error::doing_it_wrong( |
|
79 | - __METHOD__, |
|
80 | - sprintf( |
|
81 | - esc_html__( |
|
82 | - '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', |
|
83 | - 'event_espresso' |
|
84 | - ), |
|
85 | - $addon_name, |
|
86 | - '<br />', |
|
87 | - did_action('AHEE__EE_System__load_espresso_addons') ? 'action done' : 'action NOT done', |
|
88 | - did_action('AHEE__EE_Admin__loaded') ? 'action done' : 'action NOT done' |
|
89 | - ), |
|
90 | - '4.3' |
|
91 | - ); |
|
92 | - return false; |
|
93 | - } |
|
72 | + // make sure we don't register twice |
|
73 | + if (isset(self::$_registry[ $addon_name ])) { |
|
74 | + return true; |
|
75 | + } |
|
76 | + // check correct loading |
|
77 | + if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) { |
|
78 | + EE_Error::doing_it_wrong( |
|
79 | + __METHOD__, |
|
80 | + sprintf( |
|
81 | + esc_html__( |
|
82 | + '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', |
|
83 | + 'event_espresso' |
|
84 | + ), |
|
85 | + $addon_name, |
|
86 | + '<br />', |
|
87 | + did_action('AHEE__EE_System__load_espresso_addons') ? 'action done' : 'action NOT done', |
|
88 | + did_action('AHEE__EE_Admin__loaded') ? 'action done' : 'action NOT done' |
|
89 | + ), |
|
90 | + '4.3' |
|
91 | + ); |
|
92 | + return false; |
|
93 | + } |
|
94 | 94 | |
95 | - self::$_registry[ $addon_name ] = $setup_args; |
|
96 | - self::$_extensions[ $addon_name ] = []; |
|
95 | + self::$_registry[ $addon_name ] = $setup_args; |
|
96 | + self::$_extensions[ $addon_name ] = []; |
|
97 | 97 | |
98 | - if (isset($setup_args['model_extension_paths'])) { |
|
99 | - require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php'); |
|
100 | - $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_extension_paths']); |
|
101 | - // remove all files that are not PHP |
|
102 | - foreach ($class_to_filepath_map as $class => $path) { |
|
103 | - if (substr($path, strlen($path) - 3) !== 'php') { |
|
104 | - unset($class_to_filepath_map[ $class ]); |
|
105 | - } |
|
106 | - } |
|
107 | - EEH_Autoloader::register_autoloader($class_to_filepath_map); |
|
108 | - foreach (array_keys($class_to_filepath_map) as $classname) { |
|
109 | - self::$_extensions[ $addon_name ]['models'][ $classname ] = new $classname(); |
|
110 | - } |
|
111 | - unset($setup_args['model_extension_paths']); |
|
112 | - } |
|
113 | - if (isset($setup_args['class_extension_paths'])) { |
|
114 | - require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php'); |
|
115 | - $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_extension_paths']); |
|
116 | - EEH_Autoloader::register_autoloader($class_to_filepath_map); |
|
117 | - foreach (array_keys($class_to_filepath_map) as $classname) { |
|
118 | - self::$_extensions[ $addon_name ]['classes'][ $classname ] = new $classname(); |
|
119 | - } |
|
120 | - unset($setup_args['class_extension_paths']); |
|
121 | - } |
|
122 | - foreach ($setup_args as $unknown_key => $unknown_config) { |
|
123 | - throw new EE_Error( |
|
124 | - sprintf(esc_html__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key) |
|
125 | - ); |
|
126 | - } |
|
127 | - return true; |
|
128 | - } |
|
98 | + if (isset($setup_args['model_extension_paths'])) { |
|
99 | + require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php'); |
|
100 | + $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_extension_paths']); |
|
101 | + // remove all files that are not PHP |
|
102 | + foreach ($class_to_filepath_map as $class => $path) { |
|
103 | + if (substr($path, strlen($path) - 3) !== 'php') { |
|
104 | + unset($class_to_filepath_map[ $class ]); |
|
105 | + } |
|
106 | + } |
|
107 | + EEH_Autoloader::register_autoloader($class_to_filepath_map); |
|
108 | + foreach (array_keys($class_to_filepath_map) as $classname) { |
|
109 | + self::$_extensions[ $addon_name ]['models'][ $classname ] = new $classname(); |
|
110 | + } |
|
111 | + unset($setup_args['model_extension_paths']); |
|
112 | + } |
|
113 | + if (isset($setup_args['class_extension_paths'])) { |
|
114 | + require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php'); |
|
115 | + $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_extension_paths']); |
|
116 | + EEH_Autoloader::register_autoloader($class_to_filepath_map); |
|
117 | + foreach (array_keys($class_to_filepath_map) as $classname) { |
|
118 | + self::$_extensions[ $addon_name ]['classes'][ $classname ] = new $classname(); |
|
119 | + } |
|
120 | + unset($setup_args['class_extension_paths']); |
|
121 | + } |
|
122 | + foreach ($setup_args as $unknown_key => $unknown_config) { |
|
123 | + throw new EE_Error( |
|
124 | + sprintf(esc_html__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key) |
|
125 | + ); |
|
126 | + } |
|
127 | + return true; |
|
128 | + } |
|
129 | 129 | |
130 | 130 | |
131 | - /** |
|
132 | - * deregister |
|
133 | - * |
|
134 | - * @param string $addon_name |
|
135 | - */ |
|
136 | - public static function deregister(string $addon_name = '') |
|
137 | - { |
|
138 | - if (isset(self::$_registry[ $addon_name ])) { |
|
139 | - unset(self::$_registry[ $addon_name ]); |
|
140 | - foreach (self::$_extensions[ $addon_name ] as $extension_of_type) { |
|
141 | - foreach ($extension_of_type as $extension) { |
|
142 | - $extension->deregister(); |
|
143 | - } |
|
144 | - } |
|
145 | - } |
|
146 | - } |
|
131 | + /** |
|
132 | + * deregister |
|
133 | + * |
|
134 | + * @param string $addon_name |
|
135 | + */ |
|
136 | + public static function deregister(string $addon_name = '') |
|
137 | + { |
|
138 | + if (isset(self::$_registry[ $addon_name ])) { |
|
139 | + unset(self::$_registry[ $addon_name ]); |
|
140 | + foreach (self::$_extensions[ $addon_name ] as $extension_of_type) { |
|
141 | + foreach ($extension_of_type as $extension) { |
|
142 | + $extension->deregister(); |
|
143 | + } |
|
144 | + } |
|
145 | + } |
|
146 | + } |
|
147 | 147 | |
148 | 148 | |
149 | - public static function reset(): void |
|
150 | - { |
|
151 | - self::$_registry = []; |
|
152 | - self::$_extensions = []; |
|
153 | - } |
|
149 | + public static function reset(): void |
|
150 | + { |
|
151 | + self::$_registry = []; |
|
152 | + self::$_extensions = []; |
|
153 | + } |
|
154 | 154 | } |
@@ -12,57 +12,57 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Register_Personal_Data_Eraser implements EEI_Plugin_API |
14 | 14 | { |
15 | - /** |
|
16 | - * FQCN for all privacy policy generators |
|
17 | - * |
|
18 | - * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
19 | - */ |
|
20 | - protected static $erasers = []; |
|
15 | + /** |
|
16 | + * FQCN for all privacy policy generators |
|
17 | + * |
|
18 | + * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
19 | + */ |
|
20 | + protected static $erasers = []; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * @param string $addon_name |
|
25 | - * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
26 | - * OR fully qualified class names of privacy policies |
|
27 | - * @return bool |
|
28 | - */ |
|
29 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
30 | - { |
|
31 | - self::$erasers[ $addon_name ] = $setup_args; |
|
32 | - // add to list of modules to be registered |
|
33 | - add_filter( |
|
34 | - 'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers', |
|
35 | - ['EE_Register_Personal_Data_Eraser', 'addErasers'] |
|
36 | - ); |
|
37 | - return true; |
|
38 | - } |
|
23 | + /** |
|
24 | + * @param string $addon_name |
|
25 | + * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
26 | + * OR fully qualified class names of privacy policies |
|
27 | + * @return bool |
|
28 | + */ |
|
29 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
30 | + { |
|
31 | + self::$erasers[ $addon_name ] = $setup_args; |
|
32 | + // add to list of modules to be registered |
|
33 | + add_filter( |
|
34 | + 'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers', |
|
35 | + ['EE_Register_Personal_Data_Eraser', 'addErasers'] |
|
36 | + ); |
|
37 | + return true; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @param string $addon_name |
|
43 | - */ |
|
44 | - public static function deregister(string $addon_name = '') |
|
45 | - { |
|
46 | - unset(self::$erasers[ $addon_name ]); |
|
47 | - } |
|
41 | + /** |
|
42 | + * @param string $addon_name |
|
43 | + */ |
|
44 | + public static function deregister(string $addon_name = '') |
|
45 | + { |
|
46 | + unset(self::$erasers[ $addon_name ]); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * Adds our personal data erasers registered by add-ons |
|
52 | - * |
|
53 | - * @param string[] $erasers |
|
54 | - * @return string[] |
|
55 | - */ |
|
56 | - public static function addErasers(array $erasers): array |
|
57 | - { |
|
58 | - return array_merge($erasers, ...self::$erasers); |
|
59 | - } |
|
50 | + /** |
|
51 | + * Adds our personal data erasers registered by add-ons |
|
52 | + * |
|
53 | + * @param string[] $erasers |
|
54 | + * @return string[] |
|
55 | + */ |
|
56 | + public static function addErasers(array $erasers): array |
|
57 | + { |
|
58 | + return array_merge($erasers, ...self::$erasers); |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - public static function reset(): void |
|
63 | - { |
|
64 | - self::$erasers = []; |
|
65 | - } |
|
62 | + public static function reset(): void |
|
63 | + { |
|
64 | + self::$erasers = []; |
|
65 | + } |
|
66 | 66 | } |
67 | 67 | // End of file EE_Register_Personal_Data_Eraser.lib.php |
68 | 68 | // Location: ${NAMESPACE}/EE_Register_Personal_Data_Eraser.lib.php |
@@ -12,262 +12,262 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Register_CPT implements EEI_Plugin_API |
14 | 14 | { |
15 | - /** |
|
16 | - * Holds values for registered variations |
|
17 | - * |
|
18 | - * @since 4.5.0 |
|
19 | - * |
|
20 | - * @var array[][][] |
|
21 | - */ |
|
22 | - protected static $_registry = []; |
|
15 | + /** |
|
16 | + * Holds values for registered variations |
|
17 | + * |
|
18 | + * @since 4.5.0 |
|
19 | + * |
|
20 | + * @var array[][][] |
|
21 | + */ |
|
22 | + protected static $_registry = []; |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * Used to register new CPTs and Taxonomies. |
|
27 | - * |
|
28 | - * @param string $addon_name reference used for the addon registering cpts and cts |
|
29 | - * @param array $setup_args { |
|
30 | - * An array of required values for registering the cpts and taxonomies |
|
31 | - * @type array $cpts { |
|
32 | - * An array of cpts and their arguments.(short example below) |
|
33 | - * @return bool |
|
34 | - * @throws EE_Error |
|
35 | - * @see CustomPostTypeDefinitions::setDefinitions for a more complete example. |
|
36 | - * 'people' => array( |
|
37 | - * 'singular_name' => esc_html__('People', 'event_espresso'), |
|
38 | - * 'plural_name' => esc_html__('People', 'event_espresso'), |
|
39 | - * 'singular_slug' => esc_html__('people', 'event_espresso'), |
|
40 | - * 'plural_slug' => esc_html__('peoples', 'event_espresso'), |
|
41 | - * 'class_name' => 'EE_People' |
|
42 | - * ) |
|
43 | - * }, |
|
44 | - * @type array $cts { |
|
45 | - * An array of custom taxonomies and their arguments (short example below). |
|
46 | - * @see CustomTaxonomyDefinitions::setTaxonomies() for a more complete example. |
|
47 | - * 'espresso_people_type' => array( |
|
48 | - * 'singular_name' => esc_html__('People Type', 'event_espresso'), |
|
49 | - * 'plural_name' => esc_html__('People Types', 'event_espresso'), |
|
50 | - * 'args' => array() |
|
51 | - * ) |
|
52 | - * }, |
|
53 | - * @type array $default_terms { |
|
54 | - * An array of terms to set as the default for a given taxonomy and the |
|
55 | - * custom post types applied to. |
|
56 | - * 'taxonomy_name' => array( |
|
57 | - * 'term' => array( 'cpt_a_name', 'cpt_b_name' ) |
|
58 | - * ) |
|
59 | - * } |
|
60 | - * } |
|
61 | - */ |
|
62 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
63 | - { |
|
25 | + /** |
|
26 | + * Used to register new CPTs and Taxonomies. |
|
27 | + * |
|
28 | + * @param string $addon_name reference used for the addon registering cpts and cts |
|
29 | + * @param array $setup_args { |
|
30 | + * An array of required values for registering the cpts and taxonomies |
|
31 | + * @type array $cpts { |
|
32 | + * An array of cpts and their arguments.(short example below) |
|
33 | + * @return bool |
|
34 | + * @throws EE_Error |
|
35 | + * @see CustomPostTypeDefinitions::setDefinitions for a more complete example. |
|
36 | + * 'people' => array( |
|
37 | + * 'singular_name' => esc_html__('People', 'event_espresso'), |
|
38 | + * 'plural_name' => esc_html__('People', 'event_espresso'), |
|
39 | + * 'singular_slug' => esc_html__('people', 'event_espresso'), |
|
40 | + * 'plural_slug' => esc_html__('peoples', 'event_espresso'), |
|
41 | + * 'class_name' => 'EE_People' |
|
42 | + * ) |
|
43 | + * }, |
|
44 | + * @type array $cts { |
|
45 | + * An array of custom taxonomies and their arguments (short example below). |
|
46 | + * @see CustomTaxonomyDefinitions::setTaxonomies() for a more complete example. |
|
47 | + * 'espresso_people_type' => array( |
|
48 | + * 'singular_name' => esc_html__('People Type', 'event_espresso'), |
|
49 | + * 'plural_name' => esc_html__('People Types', 'event_espresso'), |
|
50 | + * 'args' => array() |
|
51 | + * ) |
|
52 | + * }, |
|
53 | + * @type array $default_terms { |
|
54 | + * An array of terms to set as the default for a given taxonomy and the |
|
55 | + * custom post types applied to. |
|
56 | + * 'taxonomy_name' => array( |
|
57 | + * 'term' => array( 'cpt_a_name', 'cpt_b_name' ) |
|
58 | + * ) |
|
59 | + * } |
|
60 | + * } |
|
61 | + */ |
|
62 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
63 | + { |
|
64 | 64 | |
65 | - // check for required params |
|
66 | - if (empty($addon_name)) { |
|
67 | - throw new EE_Error( |
|
68 | - esc_html__( |
|
69 | - 'In order to register custom post types and custom taxonomies, you must include a value to reference what had been registered', |
|
70 | - 'event_espresso' |
|
71 | - ) |
|
72 | - ); |
|
73 | - } |
|
65 | + // check for required params |
|
66 | + if (empty($addon_name)) { |
|
67 | + throw new EE_Error( |
|
68 | + esc_html__( |
|
69 | + 'In order to register custom post types and custom taxonomies, you must include a value to reference what had been registered', |
|
70 | + 'event_espresso' |
|
71 | + ) |
|
72 | + ); |
|
73 | + } |
|
74 | 74 | |
75 | - if (! is_array($setup_args) || (empty($setup_args['cpts']) && empty($setup_args['cts']))) { |
|
76 | - throw new EE_Error( |
|
77 | - esc_html__( |
|
78 | - 'In order to register custom post types or custom taxonomies, you must include an array containing either an array of custom post types to register (key "cpts"), an array of custom taxonomies ("cts") or both.', |
|
79 | - 'event_espresso' |
|
80 | - ) |
|
81 | - ); |
|
82 | - } |
|
75 | + if (! is_array($setup_args) || (empty($setup_args['cpts']) && empty($setup_args['cts']))) { |
|
76 | + throw new EE_Error( |
|
77 | + esc_html__( |
|
78 | + 'In order to register custom post types or custom taxonomies, you must include an array containing either an array of custom post types to register (key "cpts"), an array of custom taxonomies ("cts") or both.', |
|
79 | + 'event_espresso' |
|
80 | + ) |
|
81 | + ); |
|
82 | + } |
|
83 | 83 | |
84 | - // make sure we don't register twice |
|
85 | - if (isset(self::$_registry[ $addon_name ])) { |
|
86 | - return true; |
|
87 | - } |
|
84 | + // make sure we don't register twice |
|
85 | + if (isset(self::$_registry[ $addon_name ])) { |
|
86 | + return true; |
|
87 | + } |
|
88 | 88 | |
89 | - // make sure cpt ref is unique. |
|
90 | - if (isset(self::$_registry[ $addon_name ])) { |
|
91 | - $addon_name = uniqid() . '_' . $addon_name; |
|
92 | - } |
|
89 | + // make sure cpt ref is unique. |
|
90 | + if (isset(self::$_registry[ $addon_name ])) { |
|
91 | + $addon_name = uniqid() . '_' . $addon_name; |
|
92 | + } |
|
93 | 93 | |
94 | - // make sure this was called in the right place! |
|
95 | - if (did_action('AHEE__EE_System__load_CPTs_and_session__complete')) { |
|
96 | - EE_Error::doing_it_wrong( |
|
97 | - __METHOD__, |
|
98 | - sprintf( |
|
99 | - esc_html__( |
|
100 | - 'EE_Register_CPT has been called and given a reference of "%s". It may or may not work because it should be called on or before "AHEE__EE_System__load_CPTs_and_session__complete" action hook.', |
|
101 | - 'event_espresso' |
|
102 | - ), |
|
103 | - $addon_name |
|
104 | - ), |
|
105 | - '4.5.0' |
|
106 | - ); |
|
107 | - } |
|
108 | - // validate incoming args |
|
109 | - $validated = [ |
|
110 | - 'cpts' => isset($setup_args['cpts']) |
|
111 | - ? (array) $setup_args['cpts'] |
|
112 | - : [], |
|
113 | - 'cts' => isset($setup_args['cts']) |
|
114 | - ? (array) $setup_args['cts'] |
|
115 | - : [], |
|
116 | - 'default_terms' => isset($setup_args['default_terms']) |
|
117 | - ? (array) $setup_args['default_terms'] |
|
118 | - : [], |
|
119 | - ]; |
|
94 | + // make sure this was called in the right place! |
|
95 | + if (did_action('AHEE__EE_System__load_CPTs_and_session__complete')) { |
|
96 | + EE_Error::doing_it_wrong( |
|
97 | + __METHOD__, |
|
98 | + sprintf( |
|
99 | + esc_html__( |
|
100 | + 'EE_Register_CPT has been called and given a reference of "%s". It may or may not work because it should be called on or before "AHEE__EE_System__load_CPTs_and_session__complete" action hook.', |
|
101 | + 'event_espresso' |
|
102 | + ), |
|
103 | + $addon_name |
|
104 | + ), |
|
105 | + '4.5.0' |
|
106 | + ); |
|
107 | + } |
|
108 | + // validate incoming args |
|
109 | + $validated = [ |
|
110 | + 'cpts' => isset($setup_args['cpts']) |
|
111 | + ? (array) $setup_args['cpts'] |
|
112 | + : [], |
|
113 | + 'cts' => isset($setup_args['cts']) |
|
114 | + ? (array) $setup_args['cts'] |
|
115 | + : [], |
|
116 | + 'default_terms' => isset($setup_args['default_terms']) |
|
117 | + ? (array) $setup_args['default_terms'] |
|
118 | + : [], |
|
119 | + ]; |
|
120 | 120 | |
121 | - self::$_registry[ $addon_name ] = $validated; |
|
121 | + self::$_registry[ $addon_name ] = $validated; |
|
122 | 122 | |
123 | - // hook into to cpt system |
|
124 | - add_filter( |
|
125 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes', |
|
126 | - [__CLASS__, 'filterCustomPostTypeDefinitions'], |
|
127 | - 5 |
|
128 | - ); |
|
129 | - add_filter( |
|
130 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies', |
|
131 | - [__CLASS__, 'filterCustomTaxonomyDefinitions'], |
|
132 | - 5 |
|
133 | - ); |
|
134 | - add_action( |
|
135 | - 'AHEE__EventEspresso_core_domain_services_custom_post_types_RegisterCustomTaxonomyTerms__construct_end', |
|
136 | - [__CLASS__, 'registerCustomTaxonomyTerm'], |
|
137 | - 5 |
|
138 | - ); |
|
139 | - return true; |
|
140 | - } |
|
123 | + // hook into to cpt system |
|
124 | + add_filter( |
|
125 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes', |
|
126 | + [__CLASS__, 'filterCustomPostTypeDefinitions'], |
|
127 | + 5 |
|
128 | + ); |
|
129 | + add_filter( |
|
130 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies', |
|
131 | + [__CLASS__, 'filterCustomTaxonomyDefinitions'], |
|
132 | + 5 |
|
133 | + ); |
|
134 | + add_action( |
|
135 | + 'AHEE__EventEspresso_core_domain_services_custom_post_types_RegisterCustomTaxonomyTerms__construct_end', |
|
136 | + [__CLASS__, 'registerCustomTaxonomyTerm'], |
|
137 | + 5 |
|
138 | + ); |
|
139 | + return true; |
|
140 | + } |
|
141 | 141 | |
142 | 142 | |
143 | - /** |
|
144 | - * Callback for |
|
145 | - * FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes |
|
146 | - * that adds additional custom post types to be registered. |
|
147 | - * |
|
148 | - * @param array $custom_post_type_definitions array of cpts that are already set |
|
149 | - * @return array new array of cpts and their registration information |
|
150 | - */ |
|
151 | - public static function filterCustomPostTypeDefinitions(array $custom_post_type_definitions): array |
|
152 | - { |
|
153 | - foreach (self::$_registry as $registries) { |
|
154 | - foreach ($registries['cpts'] as $cpt_name => $cpt_settings) { |
|
155 | - $custom_post_type_definitions[ $cpt_name ] = $cpt_settings; |
|
156 | - } |
|
157 | - } |
|
158 | - return $custom_post_type_definitions; |
|
159 | - } |
|
143 | + /** |
|
144 | + * Callback for |
|
145 | + * FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes |
|
146 | + * that adds additional custom post types to be registered. |
|
147 | + * |
|
148 | + * @param array $custom_post_type_definitions array of cpts that are already set |
|
149 | + * @return array new array of cpts and their registration information |
|
150 | + */ |
|
151 | + public static function filterCustomPostTypeDefinitions(array $custom_post_type_definitions): array |
|
152 | + { |
|
153 | + foreach (self::$_registry as $registries) { |
|
154 | + foreach ($registries['cpts'] as $cpt_name => $cpt_settings) { |
|
155 | + $custom_post_type_definitions[ $cpt_name ] = $cpt_settings; |
|
156 | + } |
|
157 | + } |
|
158 | + return $custom_post_type_definitions; |
|
159 | + } |
|
160 | 160 | |
161 | 161 | |
162 | - /** |
|
163 | - * Callback for |
|
164 | - * FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies |
|
165 | - * that adds additional custom taxonomies to be registered. |
|
166 | - * |
|
167 | - * @param array $custom_taxonomy_definitions array of cts that are already set. |
|
168 | - * @return array new array of cts and their registration information. |
|
169 | - */ |
|
170 | - public static function filterCustomTaxonomyDefinitions(array $custom_taxonomy_definitions): array |
|
171 | - { |
|
172 | - foreach (self::$_registry as $registries) { |
|
173 | - foreach ($registries['cts'] as $ct_name => $ct_settings) { |
|
174 | - $custom_taxonomy_definitions[ $ct_name ] = $ct_settings; |
|
175 | - } |
|
176 | - } |
|
177 | - return $custom_taxonomy_definitions; |
|
178 | - } |
|
162 | + /** |
|
163 | + * Callback for |
|
164 | + * FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies |
|
165 | + * that adds additional custom taxonomies to be registered. |
|
166 | + * |
|
167 | + * @param array $custom_taxonomy_definitions array of cts that are already set. |
|
168 | + * @return array new array of cts and their registration information. |
|
169 | + */ |
|
170 | + public static function filterCustomTaxonomyDefinitions(array $custom_taxonomy_definitions): array |
|
171 | + { |
|
172 | + foreach (self::$_registry as $registries) { |
|
173 | + foreach ($registries['cts'] as $ct_name => $ct_settings) { |
|
174 | + $custom_taxonomy_definitions[ $ct_name ] = $ct_settings; |
|
175 | + } |
|
176 | + } |
|
177 | + return $custom_taxonomy_definitions; |
|
178 | + } |
|
179 | 179 | |
180 | 180 | |
181 | - /** |
|
182 | - * Callback for |
|
183 | - * AHEE__EventEspresso_core_domain_services_custom_post_types_RegisterCustomTaxonomyTerms__construct_end |
|
184 | - * which is used to set the default terms |
|
185 | - * |
|
186 | - * @param RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms |
|
187 | - * @return void |
|
188 | - */ |
|
189 | - public static function registerCustomTaxonomyTerm(RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms) |
|
190 | - { |
|
191 | - foreach (self::$_registry as $registries) { |
|
192 | - foreach ($registries['default_terms'] as $taxonomy => $terms) { |
|
193 | - foreach ($terms as $term => $cpts) { |
|
194 | - $register_custom_taxonomy_terms->registerCustomTaxonomyTerm( |
|
195 | - $taxonomy, |
|
196 | - $term, |
|
197 | - $cpts |
|
198 | - ); |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
202 | - } |
|
181 | + /** |
|
182 | + * Callback for |
|
183 | + * AHEE__EventEspresso_core_domain_services_custom_post_types_RegisterCustomTaxonomyTerms__construct_end |
|
184 | + * which is used to set the default terms |
|
185 | + * |
|
186 | + * @param RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms |
|
187 | + * @return void |
|
188 | + */ |
|
189 | + public static function registerCustomTaxonomyTerm(RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms) |
|
190 | + { |
|
191 | + foreach (self::$_registry as $registries) { |
|
192 | + foreach ($registries['default_terms'] as $taxonomy => $terms) { |
|
193 | + foreach ($terms as $term => $cpts) { |
|
194 | + $register_custom_taxonomy_terms->registerCustomTaxonomyTerm( |
|
195 | + $taxonomy, |
|
196 | + $term, |
|
197 | + $cpts |
|
198 | + ); |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | + } |
|
203 | 203 | |
204 | 204 | |
205 | - /** |
|
206 | - * @param array $cpts array of cpts that are already set |
|
207 | - * @return array new array of cpts and their registration information |
|
208 | - * @deprecated 4.9.62.p |
|
209 | - */ |
|
210 | - public static function filter_cpts(array $cpts): array |
|
211 | - { |
|
212 | - foreach (self::$_registry as $registries) { |
|
213 | - foreach ($registries['cpts'] as $cpt_name => $cpt_settings) { |
|
214 | - $cpts[ $cpt_name ] = $cpt_settings; |
|
215 | - } |
|
216 | - } |
|
217 | - return $cpts; |
|
218 | - } |
|
205 | + /** |
|
206 | + * @param array $cpts array of cpts that are already set |
|
207 | + * @return array new array of cpts and their registration information |
|
208 | + * @deprecated 4.9.62.p |
|
209 | + */ |
|
210 | + public static function filter_cpts(array $cpts): array |
|
211 | + { |
|
212 | + foreach (self::$_registry as $registries) { |
|
213 | + foreach ($registries['cpts'] as $cpt_name => $cpt_settings) { |
|
214 | + $cpts[ $cpt_name ] = $cpt_settings; |
|
215 | + } |
|
216 | + } |
|
217 | + return $cpts; |
|
218 | + } |
|
219 | 219 | |
220 | 220 | |
221 | - /** |
|
222 | - * @param array $cts array of cts that are already set. |
|
223 | - * @return array new array of cts and their registration information. |
|
224 | - * @deprecated 4.9.62.p |
|
225 | - */ |
|
226 | - public static function filter_cts(array $cts): array |
|
227 | - { |
|
228 | - foreach (self::$_registry as $registries) { |
|
229 | - foreach ($registries['cts'] as $ct_name => $ct_settings) { |
|
230 | - $cts[ $ct_name ] = $ct_settings; |
|
231 | - } |
|
232 | - } |
|
233 | - return $cts; |
|
234 | - } |
|
221 | + /** |
|
222 | + * @param array $cts array of cts that are already set. |
|
223 | + * @return array new array of cts and their registration information. |
|
224 | + * @deprecated 4.9.62.p |
|
225 | + */ |
|
226 | + public static function filter_cts(array $cts): array |
|
227 | + { |
|
228 | + foreach (self::$_registry as $registries) { |
|
229 | + foreach ($registries['cts'] as $ct_name => $ct_settings) { |
|
230 | + $cts[ $ct_name ] = $ct_settings; |
|
231 | + } |
|
232 | + } |
|
233 | + return $cts; |
|
234 | + } |
|
235 | 235 | |
236 | 236 | |
237 | - /** |
|
238 | - * @param EE_Register_CPTs $cpt_class |
|
239 | - * @return void |
|
240 | - * @deprecated 4.9.62.p |
|
241 | - */ |
|
242 | - public static function default_terms(EE_Register_CPTs $cpt_class) |
|
243 | - { |
|
244 | - foreach (self::$_registry as $registries) { |
|
245 | - foreach ($registries['default_terms'] as $taxonomy => $terms) { |
|
246 | - foreach ($terms as $term => $cpts) { |
|
247 | - $cpt_class->set_default_term($taxonomy, $term, $cpts); |
|
248 | - } |
|
249 | - } |
|
250 | - } |
|
251 | - } |
|
237 | + /** |
|
238 | + * @param EE_Register_CPTs $cpt_class |
|
239 | + * @return void |
|
240 | + * @deprecated 4.9.62.p |
|
241 | + */ |
|
242 | + public static function default_terms(EE_Register_CPTs $cpt_class) |
|
243 | + { |
|
244 | + foreach (self::$_registry as $registries) { |
|
245 | + foreach ($registries['default_terms'] as $taxonomy => $terms) { |
|
246 | + foreach ($terms as $term => $cpts) { |
|
247 | + $cpt_class->set_default_term($taxonomy, $term, $cpts); |
|
248 | + } |
|
249 | + } |
|
250 | + } |
|
251 | + } |
|
252 | 252 | |
253 | 253 | |
254 | - /** |
|
255 | - * This deregisters whats been registered on this class (for the given slug). |
|
256 | - * |
|
257 | - * @param string $addon_name The reference for the item registered to be removed. |
|
258 | - * |
|
259 | - * @return void |
|
260 | - * @since 4.5.0 |
|
261 | - * |
|
262 | - */ |
|
263 | - public static function deregister(string $addon_name = '') |
|
264 | - { |
|
265 | - unset(self::$_registry[ $addon_name ]); |
|
266 | - } |
|
254 | + /** |
|
255 | + * This deregisters whats been registered on this class (for the given slug). |
|
256 | + * |
|
257 | + * @param string $addon_name The reference for the item registered to be removed. |
|
258 | + * |
|
259 | + * @return void |
|
260 | + * @since 4.5.0 |
|
261 | + * |
|
262 | + */ |
|
263 | + public static function deregister(string $addon_name = '') |
|
264 | + { |
|
265 | + unset(self::$_registry[ $addon_name ]); |
|
266 | + } |
|
267 | 267 | |
268 | 268 | |
269 | - public static function reset(): void |
|
270 | - { |
|
271 | - self::$_registry = []; |
|
272 | - } |
|
269 | + public static function reset(): void |
|
270 | + { |
|
271 | + self::$_registry = []; |
|
272 | + } |
|
273 | 273 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | ); |
73 | 73 | } |
74 | 74 | |
75 | - if (! is_array($setup_args) || (empty($setup_args['cpts']) && empty($setup_args['cts']))) { |
|
75 | + if ( ! is_array($setup_args) || (empty($setup_args['cpts']) && empty($setup_args['cts']))) { |
|
76 | 76 | throw new EE_Error( |
77 | 77 | esc_html__( |
78 | 78 | 'In order to register custom post types or custom taxonomies, you must include an array containing either an array of custom post types to register (key "cpts"), an array of custom taxonomies ("cts") or both.', |
@@ -82,13 +82,13 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | // make sure we don't register twice |
85 | - if (isset(self::$_registry[ $addon_name ])) { |
|
85 | + if (isset(self::$_registry[$addon_name])) { |
|
86 | 86 | return true; |
87 | 87 | } |
88 | 88 | |
89 | 89 | // make sure cpt ref is unique. |
90 | - if (isset(self::$_registry[ $addon_name ])) { |
|
91 | - $addon_name = uniqid() . '_' . $addon_name; |
|
90 | + if (isset(self::$_registry[$addon_name])) { |
|
91 | + $addon_name = uniqid().'_'.$addon_name; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | // make sure this was called in the right place! |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | : [], |
119 | 119 | ]; |
120 | 120 | |
121 | - self::$_registry[ $addon_name ] = $validated; |
|
121 | + self::$_registry[$addon_name] = $validated; |
|
122 | 122 | |
123 | 123 | // hook into to cpt system |
124 | 124 | add_filter( |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | { |
153 | 153 | foreach (self::$_registry as $registries) { |
154 | 154 | foreach ($registries['cpts'] as $cpt_name => $cpt_settings) { |
155 | - $custom_post_type_definitions[ $cpt_name ] = $cpt_settings; |
|
155 | + $custom_post_type_definitions[$cpt_name] = $cpt_settings; |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 | return $custom_post_type_definitions; |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | { |
172 | 172 | foreach (self::$_registry as $registries) { |
173 | 173 | foreach ($registries['cts'] as $ct_name => $ct_settings) { |
174 | - $custom_taxonomy_definitions[ $ct_name ] = $ct_settings; |
|
174 | + $custom_taxonomy_definitions[$ct_name] = $ct_settings; |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | return $custom_taxonomy_definitions; |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | { |
212 | 212 | foreach (self::$_registry as $registries) { |
213 | 213 | foreach ($registries['cpts'] as $cpt_name => $cpt_settings) { |
214 | - $cpts[ $cpt_name ] = $cpt_settings; |
|
214 | + $cpts[$cpt_name] = $cpt_settings; |
|
215 | 215 | } |
216 | 216 | } |
217 | 217 | return $cpts; |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | { |
228 | 228 | foreach (self::$_registry as $registries) { |
229 | 229 | foreach ($registries['cts'] as $ct_name => $ct_settings) { |
230 | - $cts[ $ct_name ] = $ct_settings; |
|
230 | + $cts[$ct_name] = $ct_settings; |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 | return $cts; |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | */ |
263 | 263 | public static function deregister(string $addon_name = '') |
264 | 264 | { |
265 | - unset(self::$_registry[ $addon_name ]); |
|
265 | + unset(self::$_registry[$addon_name]); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 |