@@ -11,326 +11,326 @@ |
||
11 | 11 | class EE_Register_Messages_Template_Variations implements EEI_Plugin_API |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * Holds values for registered variations |
|
16 | - * |
|
17 | - * @since 4.5.0 |
|
18 | - * |
|
19 | - * @var array |
|
20 | - */ |
|
21 | - protected static $_registry = array(); |
|
14 | + /** |
|
15 | + * Holds values for registered variations |
|
16 | + * |
|
17 | + * @since 4.5.0 |
|
18 | + * |
|
19 | + * @var array |
|
20 | + */ |
|
21 | + protected static $_registry = array(); |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * Used to register new variations |
|
26 | - * |
|
27 | - * Variations are attached to template packs and do not typically change any structural layout but merely tweak the |
|
28 | - * style of the layout. The most commonly known variation is css. CSS does not affect html structure just the |
|
29 | - * style of existing structure. |
|
30 | - * |
|
31 | - * It's important to remember that when variation files are loaded, the file structure looked for is: |
|
32 | - * '{$messenger}_{$messenger_variation_type}_{$variation_slug}.{$extension}'. |
|
33 | - * |
|
34 | - * - Every variation applies to specific messengers. That's why the variation file includes the messenger name |
|
35 | - * it. This ensures that if a template pack the variation is registered with supports multiple variations that |
|
36 | - * you can have the correct variation loaded. |
|
37 | - * - EE_messengers also implicitly define variation "types" which typically are the context in which a specific |
|
38 | - * variation is loaded. For instance the email messenger has: 'inline', which is the css added inline to the |
|
39 | - * email templates; 'preview', which is the same css only customized for when emails are previewed; and |
|
40 | - * 'wpeditor', which is the same css only customized so that it works with the wpeditor fields for templates to |
|
41 | - * give a accurate representation of the style in the wysiwyg editor. This means that for each variation, if |
|
42 | - * you want it to be accurately represented in various temlpate contexts you need to have that relevant |
|
43 | - * variation file available. |
|
44 | - * - $variation_slug is simply the variation slug for that variation. |
|
45 | - * - $extension = whatever the extension is for the variation used for the messenger calling it. In MOST cases |
|
46 | - * messenger variations are .css files. Note: if your file names are not formatted correctly then they will NOT |
|
47 | - * be loaded. The EE messages template pack system will fallback to corresponding default template pack for the |
|
48 | - * given messenger or as a last resort (i.e. no default variation for the given messenger) will not load any |
|
49 | - * variation (so the template pack would be unstyled) |
|
50 | - * |
|
51 | - * @see /core/libraries/messages/defaults/default/variations/* for example variation files for the email and html |
|
52 | - * messengers. |
|
53 | - * |
|
54 | - * @param string $variation_ref unique reference used to describe this variation registry. If |
|
55 | - * this ISN'T unique then this method will make it unique (and it |
|
56 | - * becomes harder to deregister). |
|
57 | - * @param array $setup_args { |
|
58 | - * an array of required values for registering the variations. |
|
59 | - * @type array $variations { |
|
60 | - * An array indexed by template_pack->dbref. and values are an array |
|
61 | - * indexed by messenger name and values are an array indexed by |
|
62 | - * message_type and values are an array indexed by variation_slug |
|
63 | - * and value is the localized label for the variation. Note this |
|
64 | - * api reserves the "default" variation name for the default |
|
65 | - * template pack so you can't register a default variation. Also, |
|
66 | - * try to use unique variation slugs to reference your variations |
|
67 | - * because this api checks if any existing varations are in place |
|
68 | - * with that name. If there are then subsequent variations for that |
|
69 | - * template pack with that same name will fail to register with a |
|
70 | - * persistent notice put up for the user. Required. |
|
71 | - * 'default' => array( |
|
72 | - * 'email' => array( |
|
73 | - * 'registration_approved' => array( |
|
74 | - * my_ee_addon_blue_lagoon' => __('Blue Lagoon', |
|
75 | - * 'text_domain'), |
|
76 | - * 'my_ee_addon_red_sunset' => __('Red Sunset', |
|
77 | - * 'text_domain') |
|
78 | - * ) |
|
79 | - * ) |
|
80 | - * ) |
|
81 | - * } |
|
82 | - * @type string $base_path The base path for where all your variations are found. Although |
|
83 | - * the full path to your variation files should include '/variations/' in it, do not include the |
|
84 | - * 'variations/' in this. Required. |
|
85 | - * @type string $base_url The base url for where all your variations are found. See note |
|
86 | - * above about the 'variations/' string. Required. |
|
87 | - * } |
|
88 | - * } |
|
89 | - * |
|
90 | - * @throws EE_Error |
|
91 | - * @return void |
|
92 | - */ |
|
93 | - public static function register($variation_ref = null, $setup_args = array()) |
|
94 | - { |
|
24 | + /** |
|
25 | + * Used to register new variations |
|
26 | + * |
|
27 | + * Variations are attached to template packs and do not typically change any structural layout but merely tweak the |
|
28 | + * style of the layout. The most commonly known variation is css. CSS does not affect html structure just the |
|
29 | + * style of existing structure. |
|
30 | + * |
|
31 | + * It's important to remember that when variation files are loaded, the file structure looked for is: |
|
32 | + * '{$messenger}_{$messenger_variation_type}_{$variation_slug}.{$extension}'. |
|
33 | + * |
|
34 | + * - Every variation applies to specific messengers. That's why the variation file includes the messenger name |
|
35 | + * it. This ensures that if a template pack the variation is registered with supports multiple variations that |
|
36 | + * you can have the correct variation loaded. |
|
37 | + * - EE_messengers also implicitly define variation "types" which typically are the context in which a specific |
|
38 | + * variation is loaded. For instance the email messenger has: 'inline', which is the css added inline to the |
|
39 | + * email templates; 'preview', which is the same css only customized for when emails are previewed; and |
|
40 | + * 'wpeditor', which is the same css only customized so that it works with the wpeditor fields for templates to |
|
41 | + * give a accurate representation of the style in the wysiwyg editor. This means that for each variation, if |
|
42 | + * you want it to be accurately represented in various temlpate contexts you need to have that relevant |
|
43 | + * variation file available. |
|
44 | + * - $variation_slug is simply the variation slug for that variation. |
|
45 | + * - $extension = whatever the extension is for the variation used for the messenger calling it. In MOST cases |
|
46 | + * messenger variations are .css files. Note: if your file names are not formatted correctly then they will NOT |
|
47 | + * be loaded. The EE messages template pack system will fallback to corresponding default template pack for the |
|
48 | + * given messenger or as a last resort (i.e. no default variation for the given messenger) will not load any |
|
49 | + * variation (so the template pack would be unstyled) |
|
50 | + * |
|
51 | + * @see /core/libraries/messages/defaults/default/variations/* for example variation files for the email and html |
|
52 | + * messengers. |
|
53 | + * |
|
54 | + * @param string $variation_ref unique reference used to describe this variation registry. If |
|
55 | + * this ISN'T unique then this method will make it unique (and it |
|
56 | + * becomes harder to deregister). |
|
57 | + * @param array $setup_args { |
|
58 | + * an array of required values for registering the variations. |
|
59 | + * @type array $variations { |
|
60 | + * An array indexed by template_pack->dbref. and values are an array |
|
61 | + * indexed by messenger name and values are an array indexed by |
|
62 | + * message_type and values are an array indexed by variation_slug |
|
63 | + * and value is the localized label for the variation. Note this |
|
64 | + * api reserves the "default" variation name for the default |
|
65 | + * template pack so you can't register a default variation. Also, |
|
66 | + * try to use unique variation slugs to reference your variations |
|
67 | + * because this api checks if any existing varations are in place |
|
68 | + * with that name. If there are then subsequent variations for that |
|
69 | + * template pack with that same name will fail to register with a |
|
70 | + * persistent notice put up for the user. Required. |
|
71 | + * 'default' => array( |
|
72 | + * 'email' => array( |
|
73 | + * 'registration_approved' => array( |
|
74 | + * my_ee_addon_blue_lagoon' => __('Blue Lagoon', |
|
75 | + * 'text_domain'), |
|
76 | + * 'my_ee_addon_red_sunset' => __('Red Sunset', |
|
77 | + * 'text_domain') |
|
78 | + * ) |
|
79 | + * ) |
|
80 | + * ) |
|
81 | + * } |
|
82 | + * @type string $base_path The base path for where all your variations are found. Although |
|
83 | + * the full path to your variation files should include '/variations/' in it, do not include the |
|
84 | + * 'variations/' in this. Required. |
|
85 | + * @type string $base_url The base url for where all your variations are found. See note |
|
86 | + * above about the 'variations/' string. Required. |
|
87 | + * } |
|
88 | + * } |
|
89 | + * |
|
90 | + * @throws EE_Error |
|
91 | + * @return void |
|
92 | + */ |
|
93 | + public static function register($variation_ref = null, $setup_args = array()) |
|
94 | + { |
|
95 | 95 | |
96 | - // check for required params |
|
97 | - if (empty($variation_ref)) { |
|
98 | - throw new EE_Error( |
|
99 | - __( |
|
100 | - 'In order to register variations for a EE_Message_Template_Pack, you must include a value to reference the variations being registered', |
|
101 | - 'event_espresso' |
|
102 | - ) |
|
103 | - ); |
|
104 | - } |
|
96 | + // check for required params |
|
97 | + if (empty($variation_ref)) { |
|
98 | + throw new EE_Error( |
|
99 | + __( |
|
100 | + 'In order to register variations for a EE_Message_Template_Pack, you must include a value to reference the variations being registered', |
|
101 | + 'event_espresso' |
|
102 | + ) |
|
103 | + ); |
|
104 | + } |
|
105 | 105 | |
106 | - if (! is_array($setup_args) |
|
107 | - || empty($setup_args['variations']) |
|
108 | - || empty($setup_args['base_path']) |
|
109 | - || empty($setup_args['base_url']) |
|
110 | - ) { |
|
111 | - throw new EE_Error( |
|
112 | - __( |
|
113 | - 'In order to register variations for a EE_Message_Template_Pack, you must include an array containing the following keys: "variations", "base_path", "base_url", "extension"', |
|
114 | - 'event_espresso' |
|
115 | - ) |
|
116 | - ); |
|
117 | - } |
|
106 | + if (! is_array($setup_args) |
|
107 | + || empty($setup_args['variations']) |
|
108 | + || empty($setup_args['base_path']) |
|
109 | + || empty($setup_args['base_url']) |
|
110 | + ) { |
|
111 | + throw new EE_Error( |
|
112 | + __( |
|
113 | + 'In order to register variations for a EE_Message_Template_Pack, you must include an array containing the following keys: "variations", "base_path", "base_url", "extension"', |
|
114 | + 'event_espresso' |
|
115 | + ) |
|
116 | + ); |
|
117 | + } |
|
118 | 118 | |
119 | - // make sure we don't register twice |
|
120 | - if (isset(self::$_registry[ $variation_ref ])) { |
|
121 | - return; |
|
122 | - } |
|
119 | + // make sure we don't register twice |
|
120 | + if (isset(self::$_registry[ $variation_ref ])) { |
|
121 | + return; |
|
122 | + } |
|
123 | 123 | |
124 | - // make sure variation ref is unique. |
|
125 | - if (isset(self::$_registry[ $variation_ref ])) { |
|
126 | - $variation_ref = uniqid() . '_' . $variation_ref; |
|
127 | - } |
|
124 | + // make sure variation ref is unique. |
|
125 | + if (isset(self::$_registry[ $variation_ref ])) { |
|
126 | + $variation_ref = uniqid() . '_' . $variation_ref; |
|
127 | + } |
|
128 | 128 | |
129 | 129 | |
130 | - // make sure this was called in the right place! |
|
131 | - if (! did_action('EE_Brewing_Regular___messages_caf') |
|
132 | - || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
133 | - ) { |
|
134 | - EE_Error::doing_it_wrong( |
|
135 | - __METHOD__, |
|
136 | - sprintf( |
|
137 | - __( |
|
138 | - 'Messages Templates Variations given the reference "%s" has been attempted to be registered with the EE Messages Template Pack System. It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.', |
|
139 | - 'event_espresso' |
|
140 | - ), |
|
141 | - $variation_ref |
|
142 | - ), |
|
143 | - '4.5.0' |
|
144 | - ); |
|
145 | - } |
|
130 | + // make sure this was called in the right place! |
|
131 | + if (! did_action('EE_Brewing_Regular___messages_caf') |
|
132 | + || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
133 | + ) { |
|
134 | + EE_Error::doing_it_wrong( |
|
135 | + __METHOD__, |
|
136 | + sprintf( |
|
137 | + __( |
|
138 | + 'Messages Templates Variations given the reference "%s" has been attempted to be registered with the EE Messages Template Pack System. It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.', |
|
139 | + 'event_espresso' |
|
140 | + ), |
|
141 | + $variation_ref |
|
142 | + ), |
|
143 | + '4.5.0' |
|
144 | + ); |
|
145 | + } |
|
146 | 146 | |
147 | - // validate/sanitize incoming args. |
|
148 | - $validated = array( |
|
149 | - 'variations' => (array) $setup_args['variations'], |
|
150 | - 'base_path' => (string) $setup_args['base_path'], |
|
151 | - 'base_url' => (string) $setup_args['base_url'], |
|
152 | - ); |
|
147 | + // validate/sanitize incoming args. |
|
148 | + $validated = array( |
|
149 | + 'variations' => (array) $setup_args['variations'], |
|
150 | + 'base_path' => (string) $setup_args['base_path'], |
|
151 | + 'base_url' => (string) $setup_args['base_url'], |
|
152 | + ); |
|
153 | 153 | |
154 | 154 | |
155 | - // check that no reserved variation names are in use and also checks if there are already existing variation names for a given template pack. The former will throw an error. The latter will remove the conflicting variation name but still register the others and will add EE_Error notice. |
|
156 | - $validated = self::_verify_variations($variation_ref, $validated); |
|
157 | - self::$_registry[ $variation_ref ] = $validated; |
|
155 | + // check that no reserved variation names are in use and also checks if there are already existing variation names for a given template pack. The former will throw an error. The latter will remove the conflicting variation name but still register the others and will add EE_Error notice. |
|
156 | + $validated = self::_verify_variations($variation_ref, $validated); |
|
157 | + self::$_registry[ $variation_ref ] = $validated; |
|
158 | 158 | |
159 | - add_filter( |
|
160 | - 'FHEE__EE_Messages_Template_Pack__get_variations', |
|
161 | - array('EE_Register_Messages_Template_Variations', 'get_variations'), |
|
162 | - 10, |
|
163 | - 4 |
|
164 | - ); |
|
165 | - add_filter( |
|
166 | - 'FHEE__EE_Messages_Template_Pack__get_variation', |
|
167 | - array('EE_Register_Messages_Template_Variations', 'get_variation'), |
|
168 | - 10, |
|
169 | - 8 |
|
170 | - ); |
|
171 | - } |
|
159 | + add_filter( |
|
160 | + 'FHEE__EE_Messages_Template_Pack__get_variations', |
|
161 | + array('EE_Register_Messages_Template_Variations', 'get_variations'), |
|
162 | + 10, |
|
163 | + 4 |
|
164 | + ); |
|
165 | + add_filter( |
|
166 | + 'FHEE__EE_Messages_Template_Pack__get_variation', |
|
167 | + array('EE_Register_Messages_Template_Variations', 'get_variation'), |
|
168 | + 10, |
|
169 | + 8 |
|
170 | + ); |
|
171 | + } |
|
172 | 172 | |
173 | 173 | |
174 | - /** |
|
175 | - * Cycles through the variations registered and makes sure there are no reserved variations being registered which |
|
176 | - * throws an error. Also checks if there is already a |
|
177 | - * |
|
178 | - * @since 4.5.0 |
|
179 | - * |
|
180 | - * @param string $variation_ref the reference for the variations being registered |
|
181 | - * @param array $validated_variations The variations setup array that's being registered (and verified). |
|
182 | - * @throws EE_Error |
|
183 | - * @return bool |
|
184 | - */ |
|
185 | - private static function _verify_variations($variation_ref, $validated_variations) |
|
186 | - { |
|
187 | - foreach (self::$_registry as $variation_ref => $settings) { |
|
188 | - foreach ($settings['variations'] as $template_pack => $messenger) { |
|
189 | - foreach ($messenger as $all_variations) { |
|
190 | - if (isset($all_variations['default'])) { |
|
191 | - throw new EE_Error( |
|
192 | - sprintf( |
|
193 | - __( |
|
194 | - 'Variations registered through the EE_Register_Messages_Template_Variations api cannot override the default variation for the default template. Please check the code registering variations with this reference, "%s" and modify.', |
|
195 | - 'event_espresso' |
|
196 | - ), |
|
197 | - $variation_ref |
|
198 | - ) |
|
199 | - ); |
|
200 | - } |
|
201 | - } |
|
202 | - } |
|
203 | - } |
|
174 | + /** |
|
175 | + * Cycles through the variations registered and makes sure there are no reserved variations being registered which |
|
176 | + * throws an error. Also checks if there is already a |
|
177 | + * |
|
178 | + * @since 4.5.0 |
|
179 | + * |
|
180 | + * @param string $variation_ref the reference for the variations being registered |
|
181 | + * @param array $validated_variations The variations setup array that's being registered (and verified). |
|
182 | + * @throws EE_Error |
|
183 | + * @return bool |
|
184 | + */ |
|
185 | + private static function _verify_variations($variation_ref, $validated_variations) |
|
186 | + { |
|
187 | + foreach (self::$_registry as $variation_ref => $settings) { |
|
188 | + foreach ($settings['variations'] as $template_pack => $messenger) { |
|
189 | + foreach ($messenger as $all_variations) { |
|
190 | + if (isset($all_variations['default'])) { |
|
191 | + throw new EE_Error( |
|
192 | + sprintf( |
|
193 | + __( |
|
194 | + 'Variations registered through the EE_Register_Messages_Template_Variations api cannot override the default variation for the default template. Please check the code registering variations with this reference, "%s" and modify.', |
|
195 | + 'event_espresso' |
|
196 | + ), |
|
197 | + $variation_ref |
|
198 | + ) |
|
199 | + ); |
|
200 | + } |
|
201 | + } |
|
202 | + } |
|
203 | + } |
|
204 | 204 | |
205 | - // is there already a variation registered with a given variation slug? |
|
206 | - foreach ($validated_variations['variations'] as $template_pack => $messenger) { |
|
207 | - foreach ($messenger as $message_type => $variations) { |
|
208 | - foreach ($variations as $slug => $label) { |
|
209 | - foreach (self::$_registry as $registered_var => $reg_settings) { |
|
210 | - if (isset($reg_settings['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ])) { |
|
211 | - unset($validated_variations['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ]); |
|
212 | - EE_Error::add_error( |
|
213 | - sprintf( |
|
214 | - __( |
|
215 | - 'Unable to register the %s variation for the %s template pack with the %s messenger and %s message_type because a variation with this slug was already registered for this template pack and messenger and message type by an addon using this key %s.', |
|
216 | - 'event_espresso' |
|
217 | - ), |
|
218 | - $label, |
|
219 | - $template_pack, |
|
220 | - $messenger, |
|
221 | - $message_type, |
|
222 | - $registered_var |
|
223 | - ) |
|
224 | - ); |
|
225 | - } |
|
226 | - } |
|
227 | - } |
|
228 | - } |
|
229 | - } |
|
230 | - return $validated_variations; |
|
231 | - } |
|
205 | + // is there already a variation registered with a given variation slug? |
|
206 | + foreach ($validated_variations['variations'] as $template_pack => $messenger) { |
|
207 | + foreach ($messenger as $message_type => $variations) { |
|
208 | + foreach ($variations as $slug => $label) { |
|
209 | + foreach (self::$_registry as $registered_var => $reg_settings) { |
|
210 | + if (isset($reg_settings['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ])) { |
|
211 | + unset($validated_variations['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ]); |
|
212 | + EE_Error::add_error( |
|
213 | + sprintf( |
|
214 | + __( |
|
215 | + 'Unable to register the %s variation for the %s template pack with the %s messenger and %s message_type because a variation with this slug was already registered for this template pack and messenger and message type by an addon using this key %s.', |
|
216 | + 'event_espresso' |
|
217 | + ), |
|
218 | + $label, |
|
219 | + $template_pack, |
|
220 | + $messenger, |
|
221 | + $message_type, |
|
222 | + $registered_var |
|
223 | + ) |
|
224 | + ); |
|
225 | + } |
|
226 | + } |
|
227 | + } |
|
228 | + } |
|
229 | + } |
|
230 | + return $validated_variations; |
|
231 | + } |
|
232 | 232 | |
233 | 233 | |
234 | - /** |
|
235 | - * Callback for the FHEE__EE_Messages_Template_Pack__get_variation filter to ensure registered variations are used. |
|
236 | - * |
|
237 | - * @since 4.5.0 |
|
238 | - * |
|
239 | - * @param string $variation_path The path generated for the current variation |
|
240 | - * @param string $messenger The messenger the variation is for |
|
241 | - * @param string $message_type EE_message_type->name |
|
242 | - * @param string $type The type of variation being requested |
|
243 | - * @param string $variation The slug for the variation being requested |
|
244 | - * @param string $file_extension What the file extension is for the variation |
|
245 | - * @param bool $url Whether url or path is being returned. |
|
246 | - * @param EE_Messages_Template_Pack $template_pack |
|
247 | - * |
|
248 | - * @return string The path to the requested variation. |
|
249 | - */ |
|
250 | - public static function get_variation( |
|
251 | - $variation_path, |
|
252 | - $messenger, |
|
253 | - $message_type, |
|
254 | - $type, |
|
255 | - $variation, |
|
256 | - $file_extension, |
|
257 | - $url, |
|
258 | - EE_Messages_Template_Pack $template_pack |
|
259 | - ) { |
|
234 | + /** |
|
235 | + * Callback for the FHEE__EE_Messages_Template_Pack__get_variation filter to ensure registered variations are used. |
|
236 | + * |
|
237 | + * @since 4.5.0 |
|
238 | + * |
|
239 | + * @param string $variation_path The path generated for the current variation |
|
240 | + * @param string $messenger The messenger the variation is for |
|
241 | + * @param string $message_type EE_message_type->name |
|
242 | + * @param string $type The type of variation being requested |
|
243 | + * @param string $variation The slug for the variation being requested |
|
244 | + * @param string $file_extension What the file extension is for the variation |
|
245 | + * @param bool $url Whether url or path is being returned. |
|
246 | + * @param EE_Messages_Template_Pack $template_pack |
|
247 | + * |
|
248 | + * @return string The path to the requested variation. |
|
249 | + */ |
|
250 | + public static function get_variation( |
|
251 | + $variation_path, |
|
252 | + $messenger, |
|
253 | + $message_type, |
|
254 | + $type, |
|
255 | + $variation, |
|
256 | + $file_extension, |
|
257 | + $url, |
|
258 | + EE_Messages_Template_Pack $template_pack |
|
259 | + ) { |
|
260 | 260 | |
261 | - // so let's loop through our registered variations and then pull any details matching the request. |
|
262 | - foreach (self::$_registry as $registry_slug => $registry_settings) { |
|
263 | - $base = $url ? $registry_settings['base_url'] : $registry_settings['base_path']; |
|
264 | - $file_string = $messenger . '_' . $type . '_' . $variation . $file_extension; |
|
265 | - // see if this file exists |
|
266 | - if (is_readable($registry_settings['base_path'] . $file_string)) { |
|
267 | - return $base . $file_string; |
|
268 | - } |
|
269 | - } |
|
261 | + // so let's loop through our registered variations and then pull any details matching the request. |
|
262 | + foreach (self::$_registry as $registry_slug => $registry_settings) { |
|
263 | + $base = $url ? $registry_settings['base_url'] : $registry_settings['base_path']; |
|
264 | + $file_string = $messenger . '_' . $type . '_' . $variation . $file_extension; |
|
265 | + // see if this file exists |
|
266 | + if (is_readable($registry_settings['base_path'] . $file_string)) { |
|
267 | + return $base . $file_string; |
|
268 | + } |
|
269 | + } |
|
270 | 270 | |
271 | - // no match |
|
272 | - return $variation_path; |
|
273 | - } |
|
271 | + // no match |
|
272 | + return $variation_path; |
|
273 | + } |
|
274 | 274 | |
275 | 275 | |
276 | - /** |
|
277 | - * callback for the FHEE__EE_Messages_Template_Pack__get_variations filter. |
|
278 | - * |
|
279 | - * |
|
280 | - * @since 4.5.0 |
|
281 | - * |
|
282 | - * @param array $variations The original contents for the template pack variations property. |
|
283 | - * @see $_variation property definition in EE_Messages_Template_Pack |
|
284 | - * @param string $messenger The messenger requesting the variations. |
|
285 | - * @param EE_Messages_Template_Pack $template_pack |
|
286 | - * |
|
287 | - * @return array new variations array (or existing one if nothing registered) |
|
288 | - */ |
|
289 | - public static function get_variations( |
|
290 | - $variations, |
|
291 | - $messenger, |
|
292 | - $message_type, |
|
293 | - EE_Messages_Template_Pack $template_pack |
|
294 | - ) { |
|
295 | - // first let's check if we even have registered variations and get out early. |
|
296 | - if (empty(self::$_registry)) { |
|
297 | - return $variations; |
|
298 | - } |
|
276 | + /** |
|
277 | + * callback for the FHEE__EE_Messages_Template_Pack__get_variations filter. |
|
278 | + * |
|
279 | + * |
|
280 | + * @since 4.5.0 |
|
281 | + * |
|
282 | + * @param array $variations The original contents for the template pack variations property. |
|
283 | + * @see $_variation property definition in EE_Messages_Template_Pack |
|
284 | + * @param string $messenger The messenger requesting the variations. |
|
285 | + * @param EE_Messages_Template_Pack $template_pack |
|
286 | + * |
|
287 | + * @return array new variations array (or existing one if nothing registered) |
|
288 | + */ |
|
289 | + public static function get_variations( |
|
290 | + $variations, |
|
291 | + $messenger, |
|
292 | + $message_type, |
|
293 | + EE_Messages_Template_Pack $template_pack |
|
294 | + ) { |
|
295 | + // first let's check if we even have registered variations and get out early. |
|
296 | + if (empty(self::$_registry)) { |
|
297 | + return $variations; |
|
298 | + } |
|
299 | 299 | |
300 | - // do we have any new variations for the given messenger, $message_type, and template packs |
|
301 | - foreach (self::$_registry as $registry_slug => $registry_settings) { |
|
302 | - // allow for different conditions. |
|
303 | - if (empty($messenger)) { |
|
304 | - $variations = array_merge($registry_settings['variations'], $variations); |
|
305 | - } elseif (! empty($messenger) && empty($message_type) && ! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ])) { |
|
306 | - $variations = array_merge( |
|
307 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ], |
|
308 | - $variations |
|
309 | - ); |
|
310 | - } elseif (! empty($messenger) && ! empty($message_type) && ! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ])) { |
|
311 | - $variations = array_merge( |
|
312 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ], |
|
313 | - $variations |
|
314 | - ); |
|
315 | - } |
|
316 | - } |
|
317 | - return $variations; |
|
318 | - } |
|
300 | + // do we have any new variations for the given messenger, $message_type, and template packs |
|
301 | + foreach (self::$_registry as $registry_slug => $registry_settings) { |
|
302 | + // allow for different conditions. |
|
303 | + if (empty($messenger)) { |
|
304 | + $variations = array_merge($registry_settings['variations'], $variations); |
|
305 | + } elseif (! empty($messenger) && empty($message_type) && ! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ])) { |
|
306 | + $variations = array_merge( |
|
307 | + $registry_settings['variations'][ $template_pack->dbref ][ $messenger ], |
|
308 | + $variations |
|
309 | + ); |
|
310 | + } elseif (! empty($messenger) && ! empty($message_type) && ! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ])) { |
|
311 | + $variations = array_merge( |
|
312 | + $registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ], |
|
313 | + $variations |
|
314 | + ); |
|
315 | + } |
|
316 | + } |
|
317 | + return $variations; |
|
318 | + } |
|
319 | 319 | |
320 | 320 | |
321 | - /** |
|
322 | - * This deregisters a variation set that was previously registered with the given slug. |
|
323 | - * |
|
324 | - * @since 4.5.0 |
|
325 | - * |
|
326 | - * @param string $variation_ref The name for the variation set that was previously registered. |
|
327 | - * |
|
328 | - * @return void |
|
329 | - */ |
|
330 | - public static function deregister($variation_ref = null) |
|
331 | - { |
|
332 | - if (! empty(self::$_registry[ $variation_ref ])) { |
|
333 | - unset(self::$_registry[ $variation_ref ]); |
|
334 | - } |
|
335 | - } |
|
321 | + /** |
|
322 | + * This deregisters a variation set that was previously registered with the given slug. |
|
323 | + * |
|
324 | + * @since 4.5.0 |
|
325 | + * |
|
326 | + * @param string $variation_ref The name for the variation set that was previously registered. |
|
327 | + * |
|
328 | + * @return void |
|
329 | + */ |
|
330 | + public static function deregister($variation_ref = null) |
|
331 | + { |
|
332 | + if (! empty(self::$_registry[ $variation_ref ])) { |
|
333 | + unset(self::$_registry[ $variation_ref ]); |
|
334 | + } |
|
335 | + } |
|
336 | 336 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | ); |
104 | 104 | } |
105 | 105 | |
106 | - if (! is_array($setup_args) |
|
106 | + if ( ! is_array($setup_args) |
|
107 | 107 | || empty($setup_args['variations']) |
108 | 108 | || empty($setup_args['base_path']) |
109 | 109 | || empty($setup_args['base_url']) |
@@ -117,18 +117,18 @@ discard block |
||
117 | 117 | } |
118 | 118 | |
119 | 119 | // make sure we don't register twice |
120 | - if (isset(self::$_registry[ $variation_ref ])) { |
|
120 | + if (isset(self::$_registry[$variation_ref])) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | |
124 | 124 | // make sure variation ref is unique. |
125 | - if (isset(self::$_registry[ $variation_ref ])) { |
|
126 | - $variation_ref = uniqid() . '_' . $variation_ref; |
|
125 | + if (isset(self::$_registry[$variation_ref])) { |
|
126 | + $variation_ref = uniqid().'_'.$variation_ref; |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | |
130 | 130 | // make sure this was called in the right place! |
131 | - if (! did_action('EE_Brewing_Regular___messages_caf') |
|
131 | + if ( ! did_action('EE_Brewing_Regular___messages_caf') |
|
132 | 132 | || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
133 | 133 | ) { |
134 | 134 | EE_Error::doing_it_wrong( |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | |
155 | 155 | // check that no reserved variation names are in use and also checks if there are already existing variation names for a given template pack. The former will throw an error. The latter will remove the conflicting variation name but still register the others and will add EE_Error notice. |
156 | 156 | $validated = self::_verify_variations($variation_ref, $validated); |
157 | - self::$_registry[ $variation_ref ] = $validated; |
|
157 | + self::$_registry[$variation_ref] = $validated; |
|
158 | 158 | |
159 | 159 | add_filter( |
160 | 160 | 'FHEE__EE_Messages_Template_Pack__get_variations', |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | foreach ($messenger as $message_type => $variations) { |
208 | 208 | foreach ($variations as $slug => $label) { |
209 | 209 | foreach (self::$_registry as $registered_var => $reg_settings) { |
210 | - if (isset($reg_settings['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ])) { |
|
211 | - unset($validated_variations['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ]); |
|
210 | + if (isset($reg_settings['variations'][$template_pack][$messenger][$message_type][$slug])) { |
|
211 | + unset($validated_variations['variations'][$template_pack][$messenger][$message_type][$slug]); |
|
212 | 212 | EE_Error::add_error( |
213 | 213 | sprintf( |
214 | 214 | __( |
@@ -261,10 +261,10 @@ discard block |
||
261 | 261 | // so let's loop through our registered variations and then pull any details matching the request. |
262 | 262 | foreach (self::$_registry as $registry_slug => $registry_settings) { |
263 | 263 | $base = $url ? $registry_settings['base_url'] : $registry_settings['base_path']; |
264 | - $file_string = $messenger . '_' . $type . '_' . $variation . $file_extension; |
|
264 | + $file_string = $messenger.'_'.$type.'_'.$variation.$file_extension; |
|
265 | 265 | // see if this file exists |
266 | - if (is_readable($registry_settings['base_path'] . $file_string)) { |
|
267 | - return $base . $file_string; |
|
266 | + if (is_readable($registry_settings['base_path'].$file_string)) { |
|
267 | + return $base.$file_string; |
|
268 | 268 | } |
269 | 269 | } |
270 | 270 | |
@@ -302,14 +302,14 @@ discard block |
||
302 | 302 | // allow for different conditions. |
303 | 303 | if (empty($messenger)) { |
304 | 304 | $variations = array_merge($registry_settings['variations'], $variations); |
305 | - } elseif (! empty($messenger) && empty($message_type) && ! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ])) { |
|
305 | + } elseif ( ! empty($messenger) && empty($message_type) && ! empty($registry_settings['variations'][$template_pack->dbref][$messenger])) { |
|
306 | 306 | $variations = array_merge( |
307 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ], |
|
307 | + $registry_settings['variations'][$template_pack->dbref][$messenger], |
|
308 | 308 | $variations |
309 | 309 | ); |
310 | - } elseif (! empty($messenger) && ! empty($message_type) && ! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ])) { |
|
310 | + } elseif ( ! empty($messenger) && ! empty($message_type) && ! empty($registry_settings['variations'][$template_pack->dbref][$messenger][$message_type])) { |
|
311 | 311 | $variations = array_merge( |
312 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ], |
|
312 | + $registry_settings['variations'][$template_pack->dbref][$messenger][$message_type], |
|
313 | 313 | $variations |
314 | 314 | ); |
315 | 315 | } |
@@ -329,8 +329,8 @@ discard block |
||
329 | 329 | */ |
330 | 330 | public static function deregister($variation_ref = null) |
331 | 331 | { |
332 | - if (! empty(self::$_registry[ $variation_ref ])) { |
|
333 | - unset(self::$_registry[ $variation_ref ]); |
|
332 | + if ( ! empty(self::$_registry[$variation_ref])) { |
|
333 | + unset(self::$_registry[$variation_ref]); |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | } |
@@ -12,116 +12,116 @@ |
||
12 | 12 | class EE_Register_Config implements EEI_Plugin_API |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Holds registered EE_Config items |
|
17 | - * |
|
18 | - * @var array |
|
19 | - */ |
|
20 | - protected static $_ee_config_registry = array(); |
|
15 | + /** |
|
16 | + * Holds registered EE_Config items |
|
17 | + * |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + protected static $_ee_config_registry = array(); |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * Handles registering the new config with the EE_Config::instance()->addons property |
|
25 | - * |
|
26 | - * @since 4.3.0 |
|
27 | - * @throws EE_Error |
|
28 | - * |
|
29 | - * @param string $config_class The name of the Config class being registered. |
|
30 | - * Note this class must extend EE_Config Base and must have |
|
31 | - * already been registered with an autoloader. |
|
32 | - * @param array $setup_args { |
|
33 | - * |
|
34 | - * @type string $config_name Optional. by default the new config will be registered to |
|
35 | - * EE_Config::instance()->addons->{config_class}, but supplying a "config_name" will set the property name |
|
36 | - * that this variable is accessible by. ie: EE_Config::instance()->addons->{config_name} |
|
37 | - * } |
|
38 | - * @return void |
|
39 | - */ |
|
40 | - public static function register($config_class = null, $setup_args = array()) |
|
41 | - { |
|
23 | + /** |
|
24 | + * Handles registering the new config with the EE_Config::instance()->addons property |
|
25 | + * |
|
26 | + * @since 4.3.0 |
|
27 | + * @throws EE_Error |
|
28 | + * |
|
29 | + * @param string $config_class The name of the Config class being registered. |
|
30 | + * Note this class must extend EE_Config Base and must have |
|
31 | + * already been registered with an autoloader. |
|
32 | + * @param array $setup_args { |
|
33 | + * |
|
34 | + * @type string $config_name Optional. by default the new config will be registered to |
|
35 | + * EE_Config::instance()->addons->{config_class}, but supplying a "config_name" will set the property name |
|
36 | + * that this variable is accessible by. ie: EE_Config::instance()->addons->{config_name} |
|
37 | + * } |
|
38 | + * @return void |
|
39 | + */ |
|
40 | + public static function register($config_class = null, $setup_args = array()) |
|
41 | + { |
|
42 | 42 | |
43 | - $setup_args['config_name'] = isset($setup_args['config_name']) && ! empty($setup_args['config_name']) |
|
44 | - ? $setup_args['config_name'] : $config_class; |
|
45 | - $setup_args['config_section'] = isset($setup_args['config_section']) && ! empty($setup_args['config_section']) |
|
46 | - ? $setup_args['config_section'] : 'addons'; |
|
43 | + $setup_args['config_name'] = isset($setup_args['config_name']) && ! empty($setup_args['config_name']) |
|
44 | + ? $setup_args['config_name'] : $config_class; |
|
45 | + $setup_args['config_section'] = isset($setup_args['config_section']) && ! empty($setup_args['config_section']) |
|
46 | + ? $setup_args['config_section'] : 'addons'; |
|
47 | 47 | |
48 | - // required fields MUST be present, so let's make sure they are. |
|
49 | - if (empty($config_class) || ! is_array($setup_args) || empty($setup_args['config_name'])) { |
|
50 | - throw new EE_Error( |
|
51 | - __( |
|
52 | - 'In order to register a Config Class with EE_Register_Config::register(), you must include a "config_class" (the actual class name for this config class). As well, you can supply an array containing the following keys: "config_section" the main section of the config object the settings will be saved under (by default the new config will be registered under EE_Config::instance()->modules or EE_Config::instance()->addons depending on what type of class is calling this), "config_name" (by default the new config will be registered to EE_Config::instance()->{config_section}->{config_class}, but supplying a "config_name" will set the property name that this variable is accessible by. ie: EE_Config::instance()->{config_section}->{config_name})', |
|
53 | - 'event_espresso' |
|
54 | - ) |
|
55 | - ); |
|
56 | - } |
|
48 | + // required fields MUST be present, so let's make sure they are. |
|
49 | + if (empty($config_class) || ! is_array($setup_args) || empty($setup_args['config_name'])) { |
|
50 | + throw new EE_Error( |
|
51 | + __( |
|
52 | + 'In order to register a Config Class with EE_Register_Config::register(), you must include a "config_class" (the actual class name for this config class). As well, you can supply an array containing the following keys: "config_section" the main section of the config object the settings will be saved under (by default the new config will be registered under EE_Config::instance()->modules or EE_Config::instance()->addons depending on what type of class is calling this), "config_name" (by default the new config will be registered to EE_Config::instance()->{config_section}->{config_class}, but supplying a "config_name" will set the property name that this variable is accessible by. ie: EE_Config::instance()->{config_section}->{config_name})', |
|
53 | + 'event_espresso' |
|
54 | + ) |
|
55 | + ); |
|
56 | + } |
|
57 | 57 | |
58 | - // make sure we don't register twice |
|
59 | - if (isset(self::$_ee_config_registry[ $config_class ])) { |
|
60 | - return; |
|
61 | - } |
|
58 | + // make sure we don't register twice |
|
59 | + if (isset(self::$_ee_config_registry[ $config_class ])) { |
|
60 | + return; |
|
61 | + } |
|
62 | 62 | |
63 | 63 | |
64 | - // first find out if this happened too late. |
|
65 | - if (did_action('AHEE__EE_System__load_core_configuration__begin')) { |
|
66 | - EE_Error::doing_it_wrong( |
|
67 | - __METHOD__, |
|
68 | - sprintf( |
|
69 | - __( |
|
70 | - 'An attempt to register "%s" as an EE_Config object has failed because it was not registered at the correct hookpoint. Please register before the "AHEE__EE_System__load_core_configuration__begin" hook has fired', |
|
71 | - 'event_espresso' |
|
72 | - ), |
|
73 | - $setup_args['config_name'] |
|
74 | - ), |
|
75 | - '4.3' |
|
76 | - ); |
|
77 | - } |
|
78 | - // add incoming stuff to our registry property |
|
79 | - self::$_ee_config_registry[ $config_class ] = array( |
|
80 | - 'section' => $setup_args['config_section'], |
|
81 | - 'name' => $setup_args['config_name'], |
|
82 | - ); |
|
64 | + // first find out if this happened too late. |
|
65 | + if (did_action('AHEE__EE_System__load_core_configuration__begin')) { |
|
66 | + EE_Error::doing_it_wrong( |
|
67 | + __METHOD__, |
|
68 | + sprintf( |
|
69 | + __( |
|
70 | + 'An attempt to register "%s" as an EE_Config object has failed because it was not registered at the correct hookpoint. Please register before the "AHEE__EE_System__load_core_configuration__begin" hook has fired', |
|
71 | + 'event_espresso' |
|
72 | + ), |
|
73 | + $setup_args['config_name'] |
|
74 | + ), |
|
75 | + '4.3' |
|
76 | + ); |
|
77 | + } |
|
78 | + // add incoming stuff to our registry property |
|
79 | + self::$_ee_config_registry[ $config_class ] = array( |
|
80 | + 'section' => $setup_args['config_section'], |
|
81 | + 'name' => $setup_args['config_name'], |
|
82 | + ); |
|
83 | 83 | |
84 | - add_action('AHEE__EE_Config___load_core_config__end', array('EE_Register_Config', 'set_config'), 15, 1); |
|
85 | - add_action('AHEE__EE_Config__update_espresso_config__end', array('EE_Register_Config', 'set_config'), 15, 1); |
|
86 | - } |
|
84 | + add_action('AHEE__EE_Config___load_core_config__end', array('EE_Register_Config', 'set_config'), 15, 1); |
|
85 | + add_action('AHEE__EE_Config__update_espresso_config__end', array('EE_Register_Config', 'set_config'), 15, 1); |
|
86 | + } |
|
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * Callback for the AHEE__EE_Config___load_core_config__end hook. |
|
91 | - * basically just calls EE_Config->get_config() which will take care of loading or creating our config object for us |
|
92 | - * |
|
93 | - * @since 4.3.0 |
|
94 | - * @throws EE_Error |
|
95 | - * @param \EE_Config $EE_Config |
|
96 | - * @return \StdClass |
|
97 | - */ |
|
98 | - public static function set_config(EE_Config $EE_Config) |
|
99 | - { |
|
100 | - foreach (self::$_ee_config_registry as $config_class => $settings) { |
|
101 | - // first some validation of our incoming class_name. We'll throw an error early if its' not registered correctly |
|
102 | - if (! class_exists($config_class)) { |
|
103 | - throw new EE_Error( |
|
104 | - sprintf( |
|
105 | - __( |
|
106 | - 'The "%s" config class can not be registered with EE_Config because it does not exist. Verify that an autoloader has been set for this class', |
|
107 | - 'event_espresso' |
|
108 | - ), |
|
109 | - $config_class |
|
110 | - ) |
|
111 | - ); |
|
112 | - } |
|
113 | - $EE_Config->get_config($settings['section'], $settings['name'], $config_class); |
|
114 | - } |
|
115 | - } |
|
89 | + /** |
|
90 | + * Callback for the AHEE__EE_Config___load_core_config__end hook. |
|
91 | + * basically just calls EE_Config->get_config() which will take care of loading or creating our config object for us |
|
92 | + * |
|
93 | + * @since 4.3.0 |
|
94 | + * @throws EE_Error |
|
95 | + * @param \EE_Config $EE_Config |
|
96 | + * @return \StdClass |
|
97 | + */ |
|
98 | + public static function set_config(EE_Config $EE_Config) |
|
99 | + { |
|
100 | + foreach (self::$_ee_config_registry as $config_class => $settings) { |
|
101 | + // first some validation of our incoming class_name. We'll throw an error early if its' not registered correctly |
|
102 | + if (! class_exists($config_class)) { |
|
103 | + throw new EE_Error( |
|
104 | + sprintf( |
|
105 | + __( |
|
106 | + 'The "%s" config class can not be registered with EE_Config because it does not exist. Verify that an autoloader has been set for this class', |
|
107 | + 'event_espresso' |
|
108 | + ), |
|
109 | + $config_class |
|
110 | + ) |
|
111 | + ); |
|
112 | + } |
|
113 | + $EE_Config->get_config($settings['section'], $settings['name'], $config_class); |
|
114 | + } |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | - /** |
|
119 | - * @param mixed $config_class_name |
|
120 | - */ |
|
121 | - public static function deregister($config_class_name = null) |
|
122 | - { |
|
123 | - if (! empty(self::$_ee_config_registry[ $config_class_name ])) { |
|
124 | - unset(self::$_ee_config_registry[ $config_class_name ]); |
|
125 | - } |
|
126 | - } |
|
118 | + /** |
|
119 | + * @param mixed $config_class_name |
|
120 | + */ |
|
121 | + public static function deregister($config_class_name = null) |
|
122 | + { |
|
123 | + if (! empty(self::$_ee_config_registry[ $config_class_name ])) { |
|
124 | + unset(self::$_ee_config_registry[ $config_class_name ]); |
|
125 | + } |
|
126 | + } |
|
127 | 127 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | // make sure we don't register twice |
59 | - if (isset(self::$_ee_config_registry[ $config_class ])) { |
|
59 | + if (isset(self::$_ee_config_registry[$config_class])) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | 62 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | ); |
77 | 77 | } |
78 | 78 | // add incoming stuff to our registry property |
79 | - self::$_ee_config_registry[ $config_class ] = array( |
|
79 | + self::$_ee_config_registry[$config_class] = array( |
|
80 | 80 | 'section' => $setup_args['config_section'], |
81 | 81 | 'name' => $setup_args['config_name'], |
82 | 82 | ); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | { |
100 | 100 | foreach (self::$_ee_config_registry as $config_class => $settings) { |
101 | 101 | // first some validation of our incoming class_name. We'll throw an error early if its' not registered correctly |
102 | - if (! class_exists($config_class)) { |
|
102 | + if ( ! class_exists($config_class)) { |
|
103 | 103 | throw new EE_Error( |
104 | 104 | sprintf( |
105 | 105 | __( |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public static function deregister($config_class_name = null) |
122 | 122 | { |
123 | - if (! empty(self::$_ee_config_registry[ $config_class_name ])) { |
|
124 | - unset(self::$_ee_config_registry[ $config_class_name ]); |
|
123 | + if ( ! empty(self::$_ee_config_registry[$config_class_name])) { |
|
124 | + unset(self::$_ee_config_registry[$config_class_name]); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | } |
@@ -15,97 +15,97 @@ |
||
15 | 15 | class EE_Register_Data_Migration_Scripts implements EEI_Plugin_API |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Holds values for registered DMSs |
|
20 | - * |
|
21 | - * @var array[][] |
|
22 | - */ |
|
23 | - protected static $_settings = array(); |
|
18 | + /** |
|
19 | + * Holds values for registered DMSs |
|
20 | + * |
|
21 | + * @var array[][] |
|
22 | + */ |
|
23 | + protected static $_settings = array(); |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * Method for registering new Data Migration Scripts |
|
28 | - * |
|
29 | - * @since 4.3.0 |
|
30 | - * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
31 | - * If EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
32 | - * @param array $setup_args { |
|
33 | - * @type string $dms_paths an array of full server paths to folders that contain data migration scripts |
|
34 | - * } |
|
35 | - * @throws EE_Error |
|
36 | - * @return void |
|
37 | - */ |
|
38 | - public static function register($addon_name = '', $setup_args = array()) |
|
39 | - { |
|
40 | - // required fields MUST be present, so let's make sure they are. |
|
41 | - if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['dms_paths'])) { |
|
42 | - throw new EE_Error( |
|
43 | - esc_html__( |
|
44 | - 'In order to register Data Migration Scripts with EE_Register_Data_Migration_Scripts::register(), you must include the EE_Addon class name (used as a unique identifier for this set of data migration scripts), and an array containing the following keys: "dms_paths" (an array of full server paths to folders that contain data migration scripts)', |
|
45 | - 'event_espresso' |
|
46 | - ) |
|
47 | - ); |
|
48 | - } |
|
49 | - // make sure we don't register twice |
|
50 | - if (isset(self::$_settings[ $addon_name ])) { |
|
51 | - return; |
|
52 | - } |
|
53 | - // make sure this was called in the right place! |
|
54 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
55 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
56 | - ) { |
|
57 | - EE_Error::doing_it_wrong( |
|
58 | - __METHOD__, |
|
59 | - esc_html__( |
|
60 | - 'An attempt to register Data Migration Scripts has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register Data Migration Scripts.', |
|
61 | - 'event_espresso' |
|
62 | - ), |
|
63 | - '4.3.0' |
|
64 | - ); |
|
65 | - } |
|
66 | - // setup $_settings array from incoming values. |
|
67 | - self::$_settings[ $addon_name ] = array( |
|
68 | - 'dms_paths' => (array) $setup_args['dms_paths'], |
|
69 | - ); |
|
70 | - // setup DMS |
|
71 | - add_filter( |
|
72 | - 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
73 | - array('EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders') |
|
74 | - ); |
|
75 | - } |
|
26 | + /** |
|
27 | + * Method for registering new Data Migration Scripts |
|
28 | + * |
|
29 | + * @since 4.3.0 |
|
30 | + * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
31 | + * If EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
32 | + * @param array $setup_args { |
|
33 | + * @type string $dms_paths an array of full server paths to folders that contain data migration scripts |
|
34 | + * } |
|
35 | + * @throws EE_Error |
|
36 | + * @return void |
|
37 | + */ |
|
38 | + public static function register($addon_name = '', $setup_args = array()) |
|
39 | + { |
|
40 | + // required fields MUST be present, so let's make sure they are. |
|
41 | + if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['dms_paths'])) { |
|
42 | + throw new EE_Error( |
|
43 | + esc_html__( |
|
44 | + 'In order to register Data Migration Scripts with EE_Register_Data_Migration_Scripts::register(), you must include the EE_Addon class name (used as a unique identifier for this set of data migration scripts), and an array containing the following keys: "dms_paths" (an array of full server paths to folders that contain data migration scripts)', |
|
45 | + 'event_espresso' |
|
46 | + ) |
|
47 | + ); |
|
48 | + } |
|
49 | + // make sure we don't register twice |
|
50 | + if (isset(self::$_settings[ $addon_name ])) { |
|
51 | + return; |
|
52 | + } |
|
53 | + // make sure this was called in the right place! |
|
54 | + if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
55 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
56 | + ) { |
|
57 | + EE_Error::doing_it_wrong( |
|
58 | + __METHOD__, |
|
59 | + esc_html__( |
|
60 | + 'An attempt to register Data Migration Scripts has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register Data Migration Scripts.', |
|
61 | + 'event_espresso' |
|
62 | + ), |
|
63 | + '4.3.0' |
|
64 | + ); |
|
65 | + } |
|
66 | + // setup $_settings array from incoming values. |
|
67 | + self::$_settings[ $addon_name ] = array( |
|
68 | + 'dms_paths' => (array) $setup_args['dms_paths'], |
|
69 | + ); |
|
70 | + // setup DMS |
|
71 | + add_filter( |
|
72 | + 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
73 | + array('EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders') |
|
74 | + ); |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | - /** |
|
79 | - * @param array $dms_paths |
|
80 | - * @return array |
|
81 | - */ |
|
82 | - public static function add_data_migration_script_folders($dms_paths = array()) |
|
83 | - { |
|
84 | - foreach (self::$_settings as $addon_name => $settings) { |
|
85 | - $wildcards = 0; |
|
86 | - foreach ($settings['dms_paths'] as $dms_path) { |
|
87 | - // since we are using the addon name for the array key |
|
88 | - // we need to ensure that the key is unique, |
|
89 | - // so if for some reason an addon has multiple dms paths, |
|
90 | - // we append one or more * to the classname |
|
91 | - // which will get stripped out later on |
|
92 | - $dms_paths[ $addon_name . str_repeat('*', $wildcards) ] = $dms_path; |
|
93 | - $wildcards++; |
|
94 | - } |
|
95 | - } |
|
96 | - return $dms_paths; |
|
97 | - } |
|
78 | + /** |
|
79 | + * @param array $dms_paths |
|
80 | + * @return array |
|
81 | + */ |
|
82 | + public static function add_data_migration_script_folders($dms_paths = array()) |
|
83 | + { |
|
84 | + foreach (self::$_settings as $addon_name => $settings) { |
|
85 | + $wildcards = 0; |
|
86 | + foreach ($settings['dms_paths'] as $dms_path) { |
|
87 | + // since we are using the addon name for the array key |
|
88 | + // we need to ensure that the key is unique, |
|
89 | + // so if for some reason an addon has multiple dms paths, |
|
90 | + // we append one or more * to the classname |
|
91 | + // which will get stripped out later on |
|
92 | + $dms_paths[ $addon_name . str_repeat('*', $wildcards) ] = $dms_path; |
|
93 | + $wildcards++; |
|
94 | + } |
|
95 | + } |
|
96 | + return $dms_paths; |
|
97 | + } |
|
98 | 98 | |
99 | 99 | |
100 | - /** |
|
101 | - * This deregisters a set of Data Migration Scripts that were previously registered with a specific dms_id |
|
102 | - * |
|
103 | - * @since 4.3.0 |
|
104 | - * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - public static function deregister($addon_name = '') |
|
108 | - { |
|
109 | - unset(self::$_settings[ $addon_name ]); |
|
110 | - } |
|
100 | + /** |
|
101 | + * This deregisters a set of Data Migration Scripts that were previously registered with a specific dms_id |
|
102 | + * |
|
103 | + * @since 4.3.0 |
|
104 | + * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + public static function deregister($addon_name = '') |
|
108 | + { |
|
109 | + unset(self::$_settings[ $addon_name ]); |
|
110 | + } |
|
111 | 111 | } |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | ); |
48 | 48 | } |
49 | 49 | // make sure we don't register twice |
50 | - if (isset(self::$_settings[ $addon_name ])) { |
|
50 | + if (isset(self::$_settings[$addon_name])) { |
|
51 | 51 | return; |
52 | 52 | } |
53 | 53 | // make sure this was called in the right place! |
54 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
54 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') |
|
55 | 55 | || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
56 | 56 | ) { |
57 | 57 | EE_Error::doing_it_wrong( |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | ); |
65 | 65 | } |
66 | 66 | // setup $_settings array from incoming values. |
67 | - self::$_settings[ $addon_name ] = array( |
|
67 | + self::$_settings[$addon_name] = array( |
|
68 | 68 | 'dms_paths' => (array) $setup_args['dms_paths'], |
69 | 69 | ); |
70 | 70 | // setup DMS |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | // so if for some reason an addon has multiple dms paths, |
90 | 90 | // we append one or more * to the classname |
91 | 91 | // which will get stripped out later on |
92 | - $dms_paths[ $addon_name . str_repeat('*', $wildcards) ] = $dms_path; |
|
92 | + $dms_paths[$addon_name.str_repeat('*', $wildcards)] = $dms_path; |
|
93 | 93 | $wildcards++; |
94 | 94 | } |
95 | 95 | } |
@@ -106,6 +106,6 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public static function deregister($addon_name = '') |
108 | 108 | { |
109 | - unset(self::$_settings[ $addon_name ]); |
|
109 | + unset(self::$_settings[$addon_name]); |
|
110 | 110 | } |
111 | 111 | } |
@@ -19,166 +19,166 @@ |
||
19 | 19 | class EE_Register_Payment_Method implements EEI_Plugin_API |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * Holds values for registered payment methods |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected static $_settings = array(); |
|
22 | + /** |
|
23 | + * Holds values for registered payment methods |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected static $_settings = array(); |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * Method for registering new EE_PMT_Base children |
|
32 | - * |
|
33 | - * @since 4.5.0 |
|
34 | - * @param string $payment_method_id a unique identifier for this set of modules Required. |
|
35 | - * @param array $setup_args an array of arguments provided for registering modules Required.{ |
|
36 | - * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class |
|
37 | - * (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains |
|
38 | - * the files EE_PMT_Payomatic.pm.php) |
|
39 | - * } |
|
40 | - * @throws EE_Error |
|
41 | - * @type array payment_method_paths an array of full server paths to folders containing any EE_PMT_Base |
|
42 | - * children, or to the EED_Module files themselves |
|
43 | - * @return void |
|
44 | - * @throws InvalidDataTypeException |
|
45 | - * @throws DomainException |
|
46 | - * @throws InvalidArgumentException |
|
47 | - * @throws InvalidInterfaceException |
|
48 | - * @throws InvalidDataTypeException |
|
49 | - */ |
|
50 | - public static function register($payment_method_id = null, $setup_args = array()) |
|
51 | - { |
|
52 | - // required fields MUST be present, so let's make sure they are. |
|
53 | - if (empty($payment_method_id) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) { |
|
54 | - throw new EE_Error( |
|
55 | - esc_html__( |
|
56 | - 'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)', |
|
57 | - 'event_espresso' |
|
58 | - ) |
|
59 | - ); |
|
60 | - } |
|
61 | - // make sure we don't register twice |
|
62 | - if (isset(self::$_settings[ $payment_method_id ])) { |
|
63 | - return; |
|
64 | - } |
|
65 | - // make sure this was called in the right place! |
|
66 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
67 | - || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
68 | - ) { |
|
69 | - EE_Error::doing_it_wrong( |
|
70 | - __METHOD__, |
|
71 | - esc_html__( |
|
72 | - 'An attempt to register modules has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.', |
|
73 | - 'event_espresso' |
|
74 | - ), |
|
75 | - '4.3.0' |
|
76 | - ); |
|
77 | - } |
|
78 | - // setup $_settings array from incoming values. |
|
79 | - self::$_settings[ $payment_method_id ] = array( |
|
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 | - : array(), |
|
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 | - array('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[ $payment_method_id ]['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[ $payment_method_id ]) |
|
101 | - ); |
|
102 | - } |
|
103 | - } |
|
30 | + /** |
|
31 | + * Method for registering new EE_PMT_Base children |
|
32 | + * |
|
33 | + * @since 4.5.0 |
|
34 | + * @param string $payment_method_id a unique identifier for this set of modules Required. |
|
35 | + * @param array $setup_args an array of arguments provided for registering modules Required.{ |
|
36 | + * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class |
|
37 | + * (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains |
|
38 | + * the files EE_PMT_Payomatic.pm.php) |
|
39 | + * } |
|
40 | + * @throws EE_Error |
|
41 | + * @type array payment_method_paths an array of full server paths to folders containing any EE_PMT_Base |
|
42 | + * children, or to the EED_Module files themselves |
|
43 | + * @return void |
|
44 | + * @throws InvalidDataTypeException |
|
45 | + * @throws DomainException |
|
46 | + * @throws InvalidArgumentException |
|
47 | + * @throws InvalidInterfaceException |
|
48 | + * @throws InvalidDataTypeException |
|
49 | + */ |
|
50 | + public static function register($payment_method_id = null, $setup_args = array()) |
|
51 | + { |
|
52 | + // required fields MUST be present, so let's make sure they are. |
|
53 | + if (empty($payment_method_id) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) { |
|
54 | + throw new EE_Error( |
|
55 | + esc_html__( |
|
56 | + 'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)', |
|
57 | + 'event_espresso' |
|
58 | + ) |
|
59 | + ); |
|
60 | + } |
|
61 | + // make sure we don't register twice |
|
62 | + if (isset(self::$_settings[ $payment_method_id ])) { |
|
63 | + return; |
|
64 | + } |
|
65 | + // make sure this was called in the right place! |
|
66 | + if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
67 | + || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
68 | + ) { |
|
69 | + EE_Error::doing_it_wrong( |
|
70 | + __METHOD__, |
|
71 | + esc_html__( |
|
72 | + 'An attempt to register modules has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.', |
|
73 | + 'event_espresso' |
|
74 | + ), |
|
75 | + '4.3.0' |
|
76 | + ); |
|
77 | + } |
|
78 | + // setup $_settings array from incoming values. |
|
79 | + self::$_settings[ $payment_method_id ] = array( |
|
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 | + : array(), |
|
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 | + array('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[ $payment_method_id ]['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[ $payment_method_id ]) |
|
101 | + ); |
|
102 | + } |
|
103 | + } |
|
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * Filters the list of payment methods to add ours. |
|
108 | - * and they're just full filepaths to FOLDERS containing a payment method class file. Eg. |
|
109 | - * |
|
110 | - * @param array $payment_method_folders array of paths to all payment methods that require registering |
|
111 | - * @return array |
|
112 | - */ |
|
113 | - public static function add_payment_methods($payment_method_folders) |
|
114 | - { |
|
115 | - foreach (self::$_settings as $settings) { |
|
116 | - foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
117 | - $payment_method_folders[] = $payment_method_path; |
|
118 | - } |
|
119 | - } |
|
120 | - return $payment_method_folders; |
|
121 | - } |
|
106 | + /** |
|
107 | + * Filters the list of payment methods to add ours. |
|
108 | + * and they're just full filepaths to FOLDERS containing a payment method class file. Eg. |
|
109 | + * |
|
110 | + * @param array $payment_method_folders array of paths to all payment methods that require registering |
|
111 | + * @return array |
|
112 | + */ |
|
113 | + public static function add_payment_methods($payment_method_folders) |
|
114 | + { |
|
115 | + foreach (self::$_settings as $settings) { |
|
116 | + foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
117 | + $payment_method_folders[] = $payment_method_path; |
|
118 | + } |
|
119 | + } |
|
120 | + return $payment_method_folders; |
|
121 | + } |
|
122 | 122 | |
123 | 123 | |
124 | - /** |
|
125 | - * This deregisters a module that was previously registered with a specific $module_id. |
|
126 | - * |
|
127 | - * @since 4.3.0 |
|
128 | - * |
|
129 | - * @param string $module_id the name for the module that was previously registered |
|
130 | - * @return void |
|
131 | - * @throws DomainException |
|
132 | - * @throws EE_Error |
|
133 | - * @throws InvalidArgumentException |
|
134 | - * @throws InvalidInterfaceException |
|
135 | - * @throws InvalidDataTypeException |
|
136 | - */ |
|
137 | - public static function deregister($module_id = null) |
|
138 | - { |
|
139 | - if (isset(self::$_settings[ $module_id ])) { |
|
140 | - // set action for just this module id to delay deregistration until core is loaded and ready. |
|
141 | - $module_settings = self::$_settings[ $module_id ]; |
|
142 | - unset(self::$_settings[ $module_id ]); |
|
143 | - add_action( |
|
144 | - 'AHEE__EE_System__core_loaded_and_ready', |
|
145 | - function () use ($module_settings) { |
|
146 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
147 | - $capabilities->removeCaps( |
|
148 | - EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings) |
|
149 | - ); |
|
150 | - } |
|
151 | - ); |
|
152 | - } |
|
153 | - } |
|
124 | + /** |
|
125 | + * This deregisters a module that was previously registered with a specific $module_id. |
|
126 | + * |
|
127 | + * @since 4.3.0 |
|
128 | + * |
|
129 | + * @param string $module_id the name for the module that was previously registered |
|
130 | + * @return void |
|
131 | + * @throws DomainException |
|
132 | + * @throws EE_Error |
|
133 | + * @throws InvalidArgumentException |
|
134 | + * @throws InvalidInterfaceException |
|
135 | + * @throws InvalidDataTypeException |
|
136 | + */ |
|
137 | + public static function deregister($module_id = null) |
|
138 | + { |
|
139 | + if (isset(self::$_settings[ $module_id ])) { |
|
140 | + // set action for just this module id to delay deregistration until core is loaded and ready. |
|
141 | + $module_settings = self::$_settings[ $module_id ]; |
|
142 | + unset(self::$_settings[ $module_id ]); |
|
143 | + add_action( |
|
144 | + 'AHEE__EE_System__core_loaded_and_ready', |
|
145 | + function () use ($module_settings) { |
|
146 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
147 | + $capabilities->removeCaps( |
|
148 | + EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings) |
|
149 | + ); |
|
150 | + } |
|
151 | + ); |
|
152 | + } |
|
153 | + } |
|
154 | 154 | |
155 | 155 | |
156 | - /** |
|
157 | - * returns an array of the caps that get added when a Payment Method is registered |
|
158 | - * |
|
159 | - * @param array $settings |
|
160 | - * @return array |
|
161 | - * @throws DomainException |
|
162 | - * @throws EE_Error |
|
163 | - * @throws InvalidArgumentException |
|
164 | - * @throws InvalidInterfaceException |
|
165 | - * @throws InvalidDataTypeException |
|
166 | - * @access private Developers do NOT use this method. It's only public for PHP5.3 closure support (see deregister) |
|
167 | - * When we drop support for PHP5.3 this will be made private again. You have been warned. |
|
168 | - * |
|
169 | - */ |
|
170 | - public static function getPaymentMethodCapabilities(array $settings) |
|
171 | - { |
|
172 | - $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
173 | - $payment_method_caps = array('administrator' => array()); |
|
174 | - if (isset($settings['payment_method_paths'])) { |
|
175 | - foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
176 | - $payment_method_caps = $payment_method_manager->addPaymentMethodCap( |
|
177 | - strtolower(basename($payment_method_path)), |
|
178 | - $payment_method_caps |
|
179 | - ); |
|
180 | - } |
|
181 | - } |
|
182 | - return $payment_method_caps; |
|
183 | - } |
|
156 | + /** |
|
157 | + * returns an array of the caps that get added when a Payment Method is registered |
|
158 | + * |
|
159 | + * @param array $settings |
|
160 | + * @return array |
|
161 | + * @throws DomainException |
|
162 | + * @throws EE_Error |
|
163 | + * @throws InvalidArgumentException |
|
164 | + * @throws InvalidInterfaceException |
|
165 | + * @throws InvalidDataTypeException |
|
166 | + * @access private Developers do NOT use this method. It's only public for PHP5.3 closure support (see deregister) |
|
167 | + * When we drop support for PHP5.3 this will be made private again. You have been warned. |
|
168 | + * |
|
169 | + */ |
|
170 | + public static function getPaymentMethodCapabilities(array $settings) |
|
171 | + { |
|
172 | + $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
173 | + $payment_method_caps = array('administrator' => array()); |
|
174 | + if (isset($settings['payment_method_paths'])) { |
|
175 | + foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
176 | + $payment_method_caps = $payment_method_manager->addPaymentMethodCap( |
|
177 | + strtolower(basename($payment_method_path)), |
|
178 | + $payment_method_caps |
|
179 | + ); |
|
180 | + } |
|
181 | + } |
|
182 | + return $payment_method_caps; |
|
183 | + } |
|
184 | 184 | } |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | ); |
60 | 60 | } |
61 | 61 | // make sure we don't register twice |
62 | - if (isset(self::$_settings[ $payment_method_id ])) { |
|
62 | + if (isset(self::$_settings[$payment_method_id])) { |
|
63 | 63 | return; |
64 | 64 | } |
65 | 65 | // make sure this was called in the right place! |
66 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
66 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') |
|
67 | 67 | || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
68 | 68 | ) { |
69 | 69 | EE_Error::doing_it_wrong( |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | ); |
77 | 77 | } |
78 | 78 | // setup $_settings array from incoming values. |
79 | - self::$_settings[ $payment_method_id ] = array( |
|
79 | + self::$_settings[$payment_method_id] = array( |
|
80 | 80 | // array of full server paths to any EE_PMT_Base children used |
81 | 81 | 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
82 | 82 | ? (array) $setup_args['payment_method_paths'] |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) { |
93 | 93 | $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
94 | 94 | // register payment methods directly |
95 | - foreach (self::$_settings[ $payment_method_id ]['payment_method_paths'] as $payment_method_path) { |
|
95 | + foreach (self::$_settings[$payment_method_id]['payment_method_paths'] as $payment_method_path) { |
|
96 | 96 | $payment_method_manager->register_payment_method($payment_method_path); |
97 | 97 | } |
98 | 98 | $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
99 | 99 | $capabilities->addCaps( |
100 | - self::getPaymentMethodCapabilities(self::$_settings[ $payment_method_id ]) |
|
100 | + self::getPaymentMethodCapabilities(self::$_settings[$payment_method_id]) |
|
101 | 101 | ); |
102 | 102 | } |
103 | 103 | } |
@@ -136,13 +136,13 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public static function deregister($module_id = null) |
138 | 138 | { |
139 | - if (isset(self::$_settings[ $module_id ])) { |
|
139 | + if (isset(self::$_settings[$module_id])) { |
|
140 | 140 | // set action for just this module id to delay deregistration until core is loaded and ready. |
141 | - $module_settings = self::$_settings[ $module_id ]; |
|
142 | - unset(self::$_settings[ $module_id ]); |
|
141 | + $module_settings = self::$_settings[$module_id]; |
|
142 | + unset(self::$_settings[$module_id]); |
|
143 | 143 | add_action( |
144 | 144 | 'AHEE__EE_System__core_loaded_and_ready', |
145 | - function () use ($module_settings) { |
|
145 | + function() use ($module_settings) { |
|
146 | 146 | $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
147 | 147 | $capabilities->removeCaps( |
148 | 148 | EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings) |
@@ -12,204 +12,204 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * Holds values for registered template pack |
|
17 | - * |
|
18 | - * @since 4.5.0 |
|
19 | - * |
|
20 | - * @var array |
|
21 | - */ |
|
22 | - protected static $_registry = array(); |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * Used to register a new template pack with the messages system. |
|
27 | - * |
|
28 | - * Template packs are primarily defined via class extending EE_Messages_Template_Pack and are typically used to |
|
29 | - * change entire layouts for a set of message templates. This method is used to register the new template pack and |
|
30 | - * automatically have it loaded in the appropriate places. |
|
31 | - * |
|
32 | - * This registry also verifies that there isn't already a template pack registered with the same name and if there |
|
33 | - * is then it will add an EE_Error notice. |
|
34 | - * |
|
35 | - * Note that this only handles registering the your Template Pack class with the message template pack system. |
|
36 | - * However, there is also a naming schema you must follow for templates you are providing with your template pack. |
|
37 | - * |
|
38 | - * @see EE_Messages_Template_Pack_Default for an example class |
|
39 | - * @see core/libraries/messages/defaults/default/* for all the example templates the default template pack |
|
40 | - * supports. |
|
41 | - * |
|
42 | - * |
|
43 | - * @since 4.5.0 |
|
44 | - * @throws EE_Error |
|
45 | - * |
|
46 | - * @param string $ref The internal reference used to refer to this template pack. Note, this is first come, |
|
47 | - * first serve. If there is already a template pack registered with this name then the |
|
48 | - * registry will assign a unique reference for it so it can still be activated (but this |
|
49 | - * makes it harder to deregister as it will be unique per load - so its best to try to |
|
50 | - * make this a unique string!) |
|
51 | - * @param array $setup_args array { |
|
52 | - * An array of required values for registering the template pack. |
|
53 | - * @type string $path The path for the new template pack class. |
|
54 | - * @type string $classname The name of the new Template Pack Class. |
|
55 | - * } |
|
56 | - * |
|
57 | - * @return void |
|
58 | - */ |
|
59 | - public static function register($ref = null, $setup_args = array()) |
|
60 | - { |
|
61 | - |
|
62 | - // check for required params |
|
63 | - if (empty($ref) || empty($setup_args['path']) || empty($setup_args['classname'])) { |
|
64 | - throw new EE_Error( |
|
65 | - __( |
|
66 | - 'In order to register a new template pack for the EE Messages system, you must include a value to reference the template pack being registered and the setup_args must have the path for the new template pack class as well as the classname for the new Template Pack Class. ', |
|
67 | - 'event_espresso' |
|
68 | - ) |
|
69 | - ); |
|
70 | - } |
|
71 | - |
|
72 | - // make sure we don't register twice |
|
73 | - if (isset(self::$_registry[ $ref ])) { |
|
74 | - return; |
|
75 | - } |
|
76 | - |
|
77 | - // check that incoming $ref doesn't already exist. If it does then we'll create a unique reference for this template pack. |
|
78 | - if (isset(self::$_registry[ $ref ])) { |
|
79 | - $ref = uniqid() . '_' . $ref; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - // make sure this was called in the right place! |
|
84 | - if (! did_action('EE_Brewing_Regular___messages_caf') |
|
85 | - || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
86 | - ) { |
|
87 | - EE_Error::doing_it_wrong( |
|
88 | - __METHOD__, |
|
89 | - sprintf( |
|
90 | - __( |
|
91 | - 'A EE Messages Template Pack given the reference "%s" has been attempted to be registered with the EE Messages System. It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.', |
|
92 | - 'event_espresso' |
|
93 | - ), |
|
94 | - $ref |
|
95 | - ), |
|
96 | - '4.5.0' |
|
97 | - ); |
|
98 | - } |
|
99 | - |
|
100 | - if (self::_verify_class_not_exist($setup_args['classname'])) { |
|
101 | - self::$_registry[ $ref ] = array( |
|
102 | - 'path' => (string) $setup_args['path'], |
|
103 | - 'classname' => (string) $setup_args['classname'], |
|
104 | - ); |
|
105 | - } |
|
106 | - |
|
107 | - // hook into the system |
|
108 | - add_filter( |
|
109 | - 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
110 | - array('EE_Register_Messages_Template_Pack', 'set_template_pack_path'), |
|
111 | - 10 |
|
112 | - ); |
|
113 | - add_filter( |
|
114 | - 'FHEE__EED_Messages__get_template_packs__template_packs', |
|
115 | - array('EE_Register_Messages_Template_Pack', 'set_template_pack'), |
|
116 | - 10 |
|
117 | - ); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Callback for the FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter. This adds this template packs path |
|
123 | - * to the messages autoloader paths. |
|
124 | - * |
|
125 | - * @since 4.5.0 |
|
126 | - * |
|
127 | - * @param array $paths Array of paths already registered with the messages autoloader |
|
128 | - * |
|
129 | - * @return array |
|
130 | - */ |
|
131 | - public static function set_template_pack_path($paths) |
|
132 | - { |
|
133 | - foreach (self::$_registry as $ref => $args) { |
|
134 | - $paths[] = $args['path']; |
|
135 | - } |
|
136 | - return $paths; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * Callback for the FHEE__EED_Messages__get_template_packs__template_packs filter. This adds the instantiated, |
|
142 | - * registered template pack to the template packs array when requested by client code. |
|
143 | - * |
|
144 | - * @since 4.5.0 |
|
145 | - * |
|
146 | - * @param EE_Messages_Template_Pack[] $template_packs |
|
147 | - * @return EE_Messages_Template_Pack[] |
|
148 | - */ |
|
149 | - public static function set_template_pack($template_packs) |
|
150 | - { |
|
151 | - foreach (self::$_registry as $ref => $args) { |
|
152 | - // verify class_exists |
|
153 | - if (! class_exists($args['classname'])) { |
|
154 | - require_once($args['path'] . '/' . $args['classname'] . '.class.php'); |
|
155 | - } |
|
156 | - |
|
157 | - // check again! |
|
158 | - if (class_exists($args['classname'])) { |
|
159 | - $template_pack = new $args['classname']; |
|
160 | - $template_packs[ $template_pack->dbref ] = $template_pack; |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - return $template_packs; |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * This verifies that the classes for each registered template pack are unique names. |
|
170 | - * |
|
171 | - * @param string $classname The classname being checked |
|
172 | - * |
|
173 | - * @return bool |
|
174 | - */ |
|
175 | - private static function _verify_class_not_exist($classname) |
|
176 | - { |
|
177 | - |
|
178 | - // loop through the existing registry and see if the classname is already present. |
|
179 | - foreach (self::$_registry as $ref => $args) { |
|
180 | - if ($args['classname'] == $classname) { |
|
181 | - EE_Error::add_error( |
|
182 | - sprintf( |
|
183 | - __( |
|
184 | - 'The %s template pack that you just activated cannot be registered with the messages system because there is already a template pack active using the same classname. Contact the author of this template pack to let them know of the conflict. To stop seeing this message you will need to deactivate this template pack.', |
|
185 | - 'event_espresso' |
|
186 | - ), |
|
187 | - (string) $setup_args['classname'] |
|
188 | - ), |
|
189 | - __FILE__, |
|
190 | - __LINE__, |
|
191 | - __FUNCTION__ |
|
192 | - ); |
|
193 | - return false; |
|
194 | - } |
|
195 | - } |
|
196 | - return true; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * This deregisters a variation set that was previously registered with the given slug. |
|
202 | - * |
|
203 | - * @since 4.5.0 |
|
204 | - * |
|
205 | - * @param string $variation_ref The name for the variation set that was previously registered. |
|
206 | - * |
|
207 | - * @return void |
|
208 | - */ |
|
209 | - public static function deregister($variation_ref = null) |
|
210 | - { |
|
211 | - if (! empty(self::$_registry[ $variation_ref ])) { |
|
212 | - unset(self::$_registry[ $variation_ref ]); |
|
213 | - } |
|
214 | - } |
|
15 | + /** |
|
16 | + * Holds values for registered template pack |
|
17 | + * |
|
18 | + * @since 4.5.0 |
|
19 | + * |
|
20 | + * @var array |
|
21 | + */ |
|
22 | + protected static $_registry = array(); |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * Used to register a new template pack with the messages system. |
|
27 | + * |
|
28 | + * Template packs are primarily defined via class extending EE_Messages_Template_Pack and are typically used to |
|
29 | + * change entire layouts for a set of message templates. This method is used to register the new template pack and |
|
30 | + * automatically have it loaded in the appropriate places. |
|
31 | + * |
|
32 | + * This registry also verifies that there isn't already a template pack registered with the same name and if there |
|
33 | + * is then it will add an EE_Error notice. |
|
34 | + * |
|
35 | + * Note that this only handles registering the your Template Pack class with the message template pack system. |
|
36 | + * However, there is also a naming schema you must follow for templates you are providing with your template pack. |
|
37 | + * |
|
38 | + * @see EE_Messages_Template_Pack_Default for an example class |
|
39 | + * @see core/libraries/messages/defaults/default/* for all the example templates the default template pack |
|
40 | + * supports. |
|
41 | + * |
|
42 | + * |
|
43 | + * @since 4.5.0 |
|
44 | + * @throws EE_Error |
|
45 | + * |
|
46 | + * @param string $ref The internal reference used to refer to this template pack. Note, this is first come, |
|
47 | + * first serve. If there is already a template pack registered with this name then the |
|
48 | + * registry will assign a unique reference for it so it can still be activated (but this |
|
49 | + * makes it harder to deregister as it will be unique per load - so its best to try to |
|
50 | + * make this a unique string!) |
|
51 | + * @param array $setup_args array { |
|
52 | + * An array of required values for registering the template pack. |
|
53 | + * @type string $path The path for the new template pack class. |
|
54 | + * @type string $classname The name of the new Template Pack Class. |
|
55 | + * } |
|
56 | + * |
|
57 | + * @return void |
|
58 | + */ |
|
59 | + public static function register($ref = null, $setup_args = array()) |
|
60 | + { |
|
61 | + |
|
62 | + // check for required params |
|
63 | + if (empty($ref) || empty($setup_args['path']) || empty($setup_args['classname'])) { |
|
64 | + throw new EE_Error( |
|
65 | + __( |
|
66 | + 'In order to register a new template pack for the EE Messages system, you must include a value to reference the template pack being registered and the setup_args must have the path for the new template pack class as well as the classname for the new Template Pack Class. ', |
|
67 | + 'event_espresso' |
|
68 | + ) |
|
69 | + ); |
|
70 | + } |
|
71 | + |
|
72 | + // make sure we don't register twice |
|
73 | + if (isset(self::$_registry[ $ref ])) { |
|
74 | + return; |
|
75 | + } |
|
76 | + |
|
77 | + // check that incoming $ref doesn't already exist. If it does then we'll create a unique reference for this template pack. |
|
78 | + if (isset(self::$_registry[ $ref ])) { |
|
79 | + $ref = uniqid() . '_' . $ref; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + // make sure this was called in the right place! |
|
84 | + if (! did_action('EE_Brewing_Regular___messages_caf') |
|
85 | + || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
86 | + ) { |
|
87 | + EE_Error::doing_it_wrong( |
|
88 | + __METHOD__, |
|
89 | + sprintf( |
|
90 | + __( |
|
91 | + 'A EE Messages Template Pack given the reference "%s" has been attempted to be registered with the EE Messages System. It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.', |
|
92 | + 'event_espresso' |
|
93 | + ), |
|
94 | + $ref |
|
95 | + ), |
|
96 | + '4.5.0' |
|
97 | + ); |
|
98 | + } |
|
99 | + |
|
100 | + if (self::_verify_class_not_exist($setup_args['classname'])) { |
|
101 | + self::$_registry[ $ref ] = array( |
|
102 | + 'path' => (string) $setup_args['path'], |
|
103 | + 'classname' => (string) $setup_args['classname'], |
|
104 | + ); |
|
105 | + } |
|
106 | + |
|
107 | + // hook into the system |
|
108 | + add_filter( |
|
109 | + 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
110 | + array('EE_Register_Messages_Template_Pack', 'set_template_pack_path'), |
|
111 | + 10 |
|
112 | + ); |
|
113 | + add_filter( |
|
114 | + 'FHEE__EED_Messages__get_template_packs__template_packs', |
|
115 | + array('EE_Register_Messages_Template_Pack', 'set_template_pack'), |
|
116 | + 10 |
|
117 | + ); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Callback for the FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter. This adds this template packs path |
|
123 | + * to the messages autoloader paths. |
|
124 | + * |
|
125 | + * @since 4.5.0 |
|
126 | + * |
|
127 | + * @param array $paths Array of paths already registered with the messages autoloader |
|
128 | + * |
|
129 | + * @return array |
|
130 | + */ |
|
131 | + public static function set_template_pack_path($paths) |
|
132 | + { |
|
133 | + foreach (self::$_registry as $ref => $args) { |
|
134 | + $paths[] = $args['path']; |
|
135 | + } |
|
136 | + return $paths; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * Callback for the FHEE__EED_Messages__get_template_packs__template_packs filter. This adds the instantiated, |
|
142 | + * registered template pack to the template packs array when requested by client code. |
|
143 | + * |
|
144 | + * @since 4.5.0 |
|
145 | + * |
|
146 | + * @param EE_Messages_Template_Pack[] $template_packs |
|
147 | + * @return EE_Messages_Template_Pack[] |
|
148 | + */ |
|
149 | + public static function set_template_pack($template_packs) |
|
150 | + { |
|
151 | + foreach (self::$_registry as $ref => $args) { |
|
152 | + // verify class_exists |
|
153 | + if (! class_exists($args['classname'])) { |
|
154 | + require_once($args['path'] . '/' . $args['classname'] . '.class.php'); |
|
155 | + } |
|
156 | + |
|
157 | + // check again! |
|
158 | + if (class_exists($args['classname'])) { |
|
159 | + $template_pack = new $args['classname']; |
|
160 | + $template_packs[ $template_pack->dbref ] = $template_pack; |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + return $template_packs; |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * This verifies that the classes for each registered template pack are unique names. |
|
170 | + * |
|
171 | + * @param string $classname The classname being checked |
|
172 | + * |
|
173 | + * @return bool |
|
174 | + */ |
|
175 | + private static function _verify_class_not_exist($classname) |
|
176 | + { |
|
177 | + |
|
178 | + // loop through the existing registry and see if the classname is already present. |
|
179 | + foreach (self::$_registry as $ref => $args) { |
|
180 | + if ($args['classname'] == $classname) { |
|
181 | + EE_Error::add_error( |
|
182 | + sprintf( |
|
183 | + __( |
|
184 | + 'The %s template pack that you just activated cannot be registered with the messages system because there is already a template pack active using the same classname. Contact the author of this template pack to let them know of the conflict. To stop seeing this message you will need to deactivate this template pack.', |
|
185 | + 'event_espresso' |
|
186 | + ), |
|
187 | + (string) $setup_args['classname'] |
|
188 | + ), |
|
189 | + __FILE__, |
|
190 | + __LINE__, |
|
191 | + __FUNCTION__ |
|
192 | + ); |
|
193 | + return false; |
|
194 | + } |
|
195 | + } |
|
196 | + return true; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * This deregisters a variation set that was previously registered with the given slug. |
|
202 | + * |
|
203 | + * @since 4.5.0 |
|
204 | + * |
|
205 | + * @param string $variation_ref The name for the variation set that was previously registered. |
|
206 | + * |
|
207 | + * @return void |
|
208 | + */ |
|
209 | + public static function deregister($variation_ref = null) |
|
210 | + { |
|
211 | + if (! empty(self::$_registry[ $variation_ref ])) { |
|
212 | + unset(self::$_registry[ $variation_ref ]); |
|
213 | + } |
|
214 | + } |
|
215 | 215 | } |
@@ -70,18 +70,18 @@ discard block |
||
70 | 70 | } |
71 | 71 | |
72 | 72 | // make sure we don't register twice |
73 | - if (isset(self::$_registry[ $ref ])) { |
|
73 | + if (isset(self::$_registry[$ref])) { |
|
74 | 74 | return; |
75 | 75 | } |
76 | 76 | |
77 | 77 | // check that incoming $ref doesn't already exist. If it does then we'll create a unique reference for this template pack. |
78 | - if (isset(self::$_registry[ $ref ])) { |
|
79 | - $ref = uniqid() . '_' . $ref; |
|
78 | + if (isset(self::$_registry[$ref])) { |
|
79 | + $ref = uniqid().'_'.$ref; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | |
83 | 83 | // make sure this was called in the right place! |
84 | - if (! did_action('EE_Brewing_Regular___messages_caf') |
|
84 | + if ( ! did_action('EE_Brewing_Regular___messages_caf') |
|
85 | 85 | || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
86 | 86 | ) { |
87 | 87 | EE_Error::doing_it_wrong( |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | } |
99 | 99 | |
100 | 100 | if (self::_verify_class_not_exist($setup_args['classname'])) { |
101 | - self::$_registry[ $ref ] = array( |
|
101 | + self::$_registry[$ref] = array( |
|
102 | 102 | 'path' => (string) $setup_args['path'], |
103 | 103 | 'classname' => (string) $setup_args['classname'], |
104 | 104 | ); |
@@ -150,14 +150,14 @@ discard block |
||
150 | 150 | { |
151 | 151 | foreach (self::$_registry as $ref => $args) { |
152 | 152 | // verify class_exists |
153 | - if (! class_exists($args['classname'])) { |
|
154 | - require_once($args['path'] . '/' . $args['classname'] . '.class.php'); |
|
153 | + if ( ! class_exists($args['classname'])) { |
|
154 | + require_once($args['path'].'/'.$args['classname'].'.class.php'); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | // check again! |
158 | 158 | if (class_exists($args['classname'])) { |
159 | 159 | $template_pack = new $args['classname']; |
160 | - $template_packs[ $template_pack->dbref ] = $template_pack; |
|
160 | + $template_packs[$template_pack->dbref] = $template_pack; |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | */ |
209 | 209 | public static function deregister($variation_ref = null) |
210 | 210 | { |
211 | - if (! empty(self::$_registry[ $variation_ref ])) { |
|
212 | - unset(self::$_registry[ $variation_ref ]); |
|
211 | + if ( ! empty(self::$_registry[$variation_ref])) { |
|
212 | + unset(self::$_registry[$variation_ref]); |
|
213 | 213 | } |
214 | 214 | } |
215 | 215 | } |
@@ -12,111 +12,111 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * Sending messenger |
|
17 | - * |
|
18 | - * @type EE_messenger | string |
|
19 | - */ |
|
20 | - protected $_sending_messenger = ''; |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * Holds the incoming token; |
|
25 | - * @type string |
|
26 | - */ |
|
27 | - public $token = ''; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * Constructor |
|
32 | - * |
|
33 | - * @param string $sending_messenger_slug This is used to set what messenger is used to "send" |
|
34 | - * the EE_Message retrieved from the DB via the given token. |
|
35 | - * @param string $token This is a token for a Message that should already exist int the db. |
|
36 | - * This is then used to populate the properties in here. |
|
37 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
38 | - */ |
|
39 | - public function __construct($token, $sending_messenger_slug = 'html', EE_Message_Resource_Manager $message_resource_manager) |
|
40 | - { |
|
41 | - $this->token = $token; |
|
42 | - $this->_sending_messenger = $this->_set_sending_messenger($sending_messenger_slug, $message_resource_manager); |
|
43 | - $this->_message = $this->_generate_message(); |
|
44 | - // set params for parent from the message object |
|
45 | - parent::__construct( |
|
46 | - $this->_message->messenger(), |
|
47 | - $this->_message->message_type(), |
|
48 | - array(), |
|
49 | - $this->_message->context(), |
|
50 | - false |
|
51 | - ); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @param string $sending_messenger_slug |
|
58 | - * @param \EE_Message_Resource_Manager $message_resource_manager |
|
59 | - * @return \EE_messenger | string |
|
60 | - */ |
|
61 | - protected function _set_sending_messenger( |
|
62 | - $sending_messenger_slug, |
|
63 | - EE_Message_Resource_Manager $message_resource_manager |
|
64 | - ) { |
|
65 | - $sending_messenger = $message_resource_manager->get_active_messenger($sending_messenger_slug); |
|
66 | - return $sending_messenger instanceof EE_messenger ? $sending_messenger : $sending_messenger_slug; |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @return EE_messenger |
|
73 | - */ |
|
74 | - public function sending_messenger() |
|
75 | - { |
|
76 | - return $this->_sending_messenger; |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * generates an EE_Message using the supplied arguments and some defaults |
|
83 | - * |
|
84 | - * @param array $properties |
|
85 | - * @return EE_Message |
|
86 | - * @throws \EE_Error |
|
87 | - */ |
|
88 | - protected function _generate_message($properties = array()) |
|
89 | - { |
|
90 | - // a message was generated immediately but the parent class will call this again |
|
91 | - if ($this->_message instanceof EE_Message) { |
|
92 | - return $this->_message; |
|
93 | - } |
|
94 | - $message = EEM_Message::instance()->get_one_by_token($this->token); |
|
95 | - if (! $message instanceof EE_Message) { |
|
96 | - throw new EE_Error( |
|
97 | - sprintf( |
|
98 | - __('Unable to retrieve generated message from DB using given token: "%1$s"', 'event_espresso'), |
|
99 | - $this->token |
|
100 | - ) |
|
101 | - ); |
|
102 | - } |
|
103 | - $message->set_STS_ID(EEM_Message::status_idle); |
|
104 | - |
|
105 | - if (! $this->_sending_messenger instanceof EE_messenger) { |
|
106 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
107 | - $message->set_error_message( |
|
108 | - sprintf( |
|
109 | - __('Unable to send message because the "%1$s" messenger is not active or not installed', 'event_espresso'), |
|
110 | - $this->_sending_messenger |
|
111 | - ) |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - // set properties |
|
116 | - $this->_valid = true; |
|
117 | - $this->_messenger = $message->messenger_object(); |
|
118 | - $this->_message_type = $message->message_type_object(); |
|
119 | - $this->_send_now = $message->send_now(); |
|
120 | - return $message; |
|
121 | - } |
|
15 | + /** |
|
16 | + * Sending messenger |
|
17 | + * |
|
18 | + * @type EE_messenger | string |
|
19 | + */ |
|
20 | + protected $_sending_messenger = ''; |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * Holds the incoming token; |
|
25 | + * @type string |
|
26 | + */ |
|
27 | + public $token = ''; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * Constructor |
|
32 | + * |
|
33 | + * @param string $sending_messenger_slug This is used to set what messenger is used to "send" |
|
34 | + * the EE_Message retrieved from the DB via the given token. |
|
35 | + * @param string $token This is a token for a Message that should already exist int the db. |
|
36 | + * This is then used to populate the properties in here. |
|
37 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
38 | + */ |
|
39 | + public function __construct($token, $sending_messenger_slug = 'html', EE_Message_Resource_Manager $message_resource_manager) |
|
40 | + { |
|
41 | + $this->token = $token; |
|
42 | + $this->_sending_messenger = $this->_set_sending_messenger($sending_messenger_slug, $message_resource_manager); |
|
43 | + $this->_message = $this->_generate_message(); |
|
44 | + // set params for parent from the message object |
|
45 | + parent::__construct( |
|
46 | + $this->_message->messenger(), |
|
47 | + $this->_message->message_type(), |
|
48 | + array(), |
|
49 | + $this->_message->context(), |
|
50 | + false |
|
51 | + ); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @param string $sending_messenger_slug |
|
58 | + * @param \EE_Message_Resource_Manager $message_resource_manager |
|
59 | + * @return \EE_messenger | string |
|
60 | + */ |
|
61 | + protected function _set_sending_messenger( |
|
62 | + $sending_messenger_slug, |
|
63 | + EE_Message_Resource_Manager $message_resource_manager |
|
64 | + ) { |
|
65 | + $sending_messenger = $message_resource_manager->get_active_messenger($sending_messenger_slug); |
|
66 | + return $sending_messenger instanceof EE_messenger ? $sending_messenger : $sending_messenger_slug; |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @return EE_messenger |
|
73 | + */ |
|
74 | + public function sending_messenger() |
|
75 | + { |
|
76 | + return $this->_sending_messenger; |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * generates an EE_Message using the supplied arguments and some defaults |
|
83 | + * |
|
84 | + * @param array $properties |
|
85 | + * @return EE_Message |
|
86 | + * @throws \EE_Error |
|
87 | + */ |
|
88 | + protected function _generate_message($properties = array()) |
|
89 | + { |
|
90 | + // a message was generated immediately but the parent class will call this again |
|
91 | + if ($this->_message instanceof EE_Message) { |
|
92 | + return $this->_message; |
|
93 | + } |
|
94 | + $message = EEM_Message::instance()->get_one_by_token($this->token); |
|
95 | + if (! $message instanceof EE_Message) { |
|
96 | + throw new EE_Error( |
|
97 | + sprintf( |
|
98 | + __('Unable to retrieve generated message from DB using given token: "%1$s"', 'event_espresso'), |
|
99 | + $this->token |
|
100 | + ) |
|
101 | + ); |
|
102 | + } |
|
103 | + $message->set_STS_ID(EEM_Message::status_idle); |
|
104 | + |
|
105 | + if (! $this->_sending_messenger instanceof EE_messenger) { |
|
106 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
107 | + $message->set_error_message( |
|
108 | + sprintf( |
|
109 | + __('Unable to send message because the "%1$s" messenger is not active or not installed', 'event_espresso'), |
|
110 | + $this->_sending_messenger |
|
111 | + ) |
|
112 | + ); |
|
113 | + } |
|
114 | + |
|
115 | + // set properties |
|
116 | + $this->_valid = true; |
|
117 | + $this->_messenger = $message->messenger_object(); |
|
118 | + $this->_message_type = $message->message_type_object(); |
|
119 | + $this->_send_now = $message->send_now(); |
|
120 | + return $message; |
|
121 | + } |
|
122 | 122 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | return $this->_message; |
93 | 93 | } |
94 | 94 | $message = EEM_Message::instance()->get_one_by_token($this->token); |
95 | - if (! $message instanceof EE_Message) { |
|
95 | + if ( ! $message instanceof EE_Message) { |
|
96 | 96 | throw new EE_Error( |
97 | 97 | sprintf( |
98 | 98 | __('Unable to retrieve generated message from DB using given token: "%1$s"', 'event_espresso'), |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | } |
103 | 103 | $message->set_STS_ID(EEM_Message::status_idle); |
104 | 104 | |
105 | - if (! $this->_sending_messenger instanceof EE_messenger) { |
|
105 | + if ( ! $this->_sending_messenger instanceof EE_messenger) { |
|
106 | 106 | $message->set_STS_ID(EEM_Message::status_failed); |
107 | 107 | $message->set_error_message( |
108 | 108 | sprintf( |
@@ -11,198 +11,198 @@ |
||
11 | 11 | class EE_Messages_Scheduler extends EE_Base |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * Number of seconds between batch sends/generates on the cron job. |
|
16 | - * Defaults to 5 minutes in seconds. If you want to change this interval, you can use the native WordPress |
|
17 | - * `cron_schedules` filter and modify the existing custom `ee_message_cron` schedule interval added. |
|
18 | - * |
|
19 | - * @type int |
|
20 | - */ |
|
21 | - const message_cron_schedule = 300; |
|
22 | - |
|
23 | - /** |
|
24 | - * Constructor |
|
25 | - */ |
|
26 | - public function __construct() |
|
27 | - { |
|
28 | - // register tasks (and make sure only registered once). |
|
29 | - if (! has_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'))) { |
|
30 | - add_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'), 10); |
|
31 | - } |
|
32 | - |
|
33 | - // register callbacks for scheduled events (but make sure they are set only once). |
|
34 | - if (! has_action( |
|
35 | - 'AHEE__EE_Messages_Scheduler__generation', |
|
36 | - array('EE_Messages_Scheduler', 'batch_generation') |
|
37 | - )) { |
|
38 | - add_action('AHEE__EE_Messages_Scheduler__generation', array('EE_Messages_Scheduler', 'batch_generation')); |
|
39 | - add_action('AHEE__EE_Messages_Scheduler__sending', array('EE_Messages_Scheduler', 'batch_sending')); |
|
40 | - add_action('AHEE__EE_Messages_Scheduler__cleanup', array('EE_Messages_Scheduler', 'cleanup')); |
|
41 | - } |
|
42 | - |
|
43 | - // add custom schedules |
|
44 | - add_filter('cron_schedules', array($this, 'custom_schedules')); |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * Add custom schedules for wp_cron |
|
50 | - * |
|
51 | - * @param $schedules |
|
52 | - */ |
|
53 | - public function custom_schedules($schedules) |
|
54 | - { |
|
55 | - $schedules['ee_message_cron'] = array( |
|
56 | - 'interval' => self::message_cron_schedule, |
|
57 | - 'display' => __( |
|
58 | - 'This is the cron time interval for EE Message schedules (defaults to once every 5 minutes)', |
|
59 | - 'event_espresso' |
|
60 | - ), |
|
61 | - ); |
|
62 | - return $schedules; |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * Callback for FHEE__EEH_Activation__get_cron_tasks that is used to retrieve scheduled Cron events to add and |
|
68 | - * remove. |
|
69 | - * |
|
70 | - * @param array $tasks already existing scheduled tasks |
|
71 | - * @return array |
|
72 | - */ |
|
73 | - public function register_scheduled_tasks($tasks) |
|
74 | - { |
|
75 | - EE_Registry::instance()->load_helper('DTT_Helper'); |
|
76 | - $tasks['AHEE__EE_Messages_Scheduler__generation'] = 'ee_message_cron'; |
|
77 | - $tasks['AHEE__EE_Messages_Scheduler__sending'] = 'ee_message_cron'; |
|
78 | - $tasks['AHEE__EE_Messages_Scheduler__cleanup'] = array( EEH_DTT_Helper::tomorrow(), 'daily'); |
|
79 | - return $tasks; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * This initiates a non-blocking separate request to execute on a scheduled task. |
|
85 | - * Note: The EED_Messages module has the handlers for these requests. |
|
86 | - * |
|
87 | - * @param string $task The task the request is being generated for. |
|
88 | - */ |
|
89 | - public static function initiate_scheduled_non_blocking_request($task) |
|
90 | - { |
|
91 | - if (apply_filters( |
|
92 | - 'EE_Messages_Scheduler__initiate_scheduled_non_blocking_request__do_separate_request', |
|
93 | - true |
|
94 | - )) { |
|
95 | - $request_url = add_query_arg( |
|
96 | - array_merge( |
|
97 | - array('ee' => 'msg_cron_trigger'), |
|
98 | - EE_Messages_Scheduler::get_request_params($task) |
|
99 | - ), |
|
100 | - site_url() |
|
101 | - ); |
|
102 | - $request_args = array( |
|
103 | - 'timeout' => 300, |
|
104 | - 'blocking' => (defined('DOING_CRON') && DOING_CRON) || (defined('DOING_AJAX') && DOING_AJAX) ? true : false, |
|
105 | - 'sslverify' => false, |
|
106 | - 'redirection' => 10, |
|
107 | - ); |
|
108 | - $response = wp_remote_get($request_url, $request_args); |
|
109 | - if (is_wp_error($response)) { |
|
110 | - trigger_error($response->get_error_message()); |
|
111 | - } |
|
112 | - } else { |
|
113 | - EE_Messages_Scheduler::initiate_immediate_request_on_cron($task); |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * This returns |
|
120 | - * the request params used for a scheduled message task request. |
|
121 | - * |
|
122 | - * @param string $task The task the request is for. |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - public static function get_request_params($task) |
|
126 | - { |
|
127 | - // transient is used for flood control on msg_cron_trigger requests |
|
128 | - $transient_key = 'ee_trans_' . uniqid($task); |
|
129 | - set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS); |
|
130 | - return array( |
|
131 | - 'type' => $task, |
|
132 | - 'key' => $transient_key, |
|
133 | - ); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * This is used to execute an immediate call to the run_cron task performed by EED_Messages |
|
139 | - * |
|
140 | - * @param string $task The task the request is being generated for. |
|
141 | - */ |
|
142 | - public static function initiate_immediate_request_on_cron($task) |
|
143 | - { |
|
144 | - $request_args = EE_Messages_Scheduler::get_request_params($task); |
|
145 | - // set those request args in the request so it gets picked up |
|
146 | - foreach ($request_args as $request_key => $request_value) { |
|
147 | - EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
148 | - } |
|
149 | - EED_Messages::instance()->run_cron(); |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * Callback for scheduled AHEE__EE_Messages_Scheduler__generation wp cron event |
|
155 | - */ |
|
156 | - public static function batch_generation() |
|
157 | - { |
|
158 | - /** |
|
159 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority() |
|
160 | - */ |
|
161 | - if (! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
162 | - || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
163 | - ) { |
|
164 | - EE_Messages_Scheduler::initiate_immediate_request_on_cron('generate'); |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * Callback for scheduled AHEE__EE_Messages_Scheduler__sending |
|
171 | - */ |
|
172 | - public static function batch_sending() |
|
173 | - { |
|
174 | - /** |
|
175 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority() |
|
176 | - */ |
|
177 | - if (! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
178 | - || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
179 | - ) { |
|
180 | - EE_Messages_Scheduler::initiate_immediate_request_on_cron('send'); |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * This is the callback for the `AHEE__EE_Messages_Scheduler__cleanup` scheduled event action. |
|
187 | - * This runs once a day and if cleanup is active (set via messages settings), it will (by default) delete permanently |
|
188 | - * from the database messages that have a MSG_modified date older than 30 days. |
|
189 | - */ |
|
190 | - public static function cleanup() |
|
191 | - { |
|
192 | - // first check if user has cleanup turned on or if we're in maintenance mode. If in maintenance mode we'll wait |
|
193 | - // until the next scheduled event. |
|
194 | - if (! EE_Registry::instance()->CFG->messages->delete_threshold |
|
195 | - || ! EE_Maintenance_Mode::instance()->models_can_query() |
|
196 | - ) { |
|
197 | - return; |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * This filter switch allows other code (such as the EE_Worker_Queue add-on) to replace this with its own handling |
|
202 | - * of deleting messages. |
|
203 | - */ |
|
204 | - if (apply_filters('FHEE__EE_Messages_Scheduler__cleanup__handle_cleanup_on_cron', true)) { |
|
205 | - EEM_Message::instance()->delete_old_messages(EE_Registry::instance()->CFG->messages->delete_threshold); |
|
206 | - } |
|
207 | - } |
|
14 | + /** |
|
15 | + * Number of seconds between batch sends/generates on the cron job. |
|
16 | + * Defaults to 5 minutes in seconds. If you want to change this interval, you can use the native WordPress |
|
17 | + * `cron_schedules` filter and modify the existing custom `ee_message_cron` schedule interval added. |
|
18 | + * |
|
19 | + * @type int |
|
20 | + */ |
|
21 | + const message_cron_schedule = 300; |
|
22 | + |
|
23 | + /** |
|
24 | + * Constructor |
|
25 | + */ |
|
26 | + public function __construct() |
|
27 | + { |
|
28 | + // register tasks (and make sure only registered once). |
|
29 | + if (! has_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'))) { |
|
30 | + add_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'), 10); |
|
31 | + } |
|
32 | + |
|
33 | + // register callbacks for scheduled events (but make sure they are set only once). |
|
34 | + if (! has_action( |
|
35 | + 'AHEE__EE_Messages_Scheduler__generation', |
|
36 | + array('EE_Messages_Scheduler', 'batch_generation') |
|
37 | + )) { |
|
38 | + add_action('AHEE__EE_Messages_Scheduler__generation', array('EE_Messages_Scheduler', 'batch_generation')); |
|
39 | + add_action('AHEE__EE_Messages_Scheduler__sending', array('EE_Messages_Scheduler', 'batch_sending')); |
|
40 | + add_action('AHEE__EE_Messages_Scheduler__cleanup', array('EE_Messages_Scheduler', 'cleanup')); |
|
41 | + } |
|
42 | + |
|
43 | + // add custom schedules |
|
44 | + add_filter('cron_schedules', array($this, 'custom_schedules')); |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * Add custom schedules for wp_cron |
|
50 | + * |
|
51 | + * @param $schedules |
|
52 | + */ |
|
53 | + public function custom_schedules($schedules) |
|
54 | + { |
|
55 | + $schedules['ee_message_cron'] = array( |
|
56 | + 'interval' => self::message_cron_schedule, |
|
57 | + 'display' => __( |
|
58 | + 'This is the cron time interval for EE Message schedules (defaults to once every 5 minutes)', |
|
59 | + 'event_espresso' |
|
60 | + ), |
|
61 | + ); |
|
62 | + return $schedules; |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * Callback for FHEE__EEH_Activation__get_cron_tasks that is used to retrieve scheduled Cron events to add and |
|
68 | + * remove. |
|
69 | + * |
|
70 | + * @param array $tasks already existing scheduled tasks |
|
71 | + * @return array |
|
72 | + */ |
|
73 | + public function register_scheduled_tasks($tasks) |
|
74 | + { |
|
75 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
76 | + $tasks['AHEE__EE_Messages_Scheduler__generation'] = 'ee_message_cron'; |
|
77 | + $tasks['AHEE__EE_Messages_Scheduler__sending'] = 'ee_message_cron'; |
|
78 | + $tasks['AHEE__EE_Messages_Scheduler__cleanup'] = array( EEH_DTT_Helper::tomorrow(), 'daily'); |
|
79 | + return $tasks; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * This initiates a non-blocking separate request to execute on a scheduled task. |
|
85 | + * Note: The EED_Messages module has the handlers for these requests. |
|
86 | + * |
|
87 | + * @param string $task The task the request is being generated for. |
|
88 | + */ |
|
89 | + public static function initiate_scheduled_non_blocking_request($task) |
|
90 | + { |
|
91 | + if (apply_filters( |
|
92 | + 'EE_Messages_Scheduler__initiate_scheduled_non_blocking_request__do_separate_request', |
|
93 | + true |
|
94 | + )) { |
|
95 | + $request_url = add_query_arg( |
|
96 | + array_merge( |
|
97 | + array('ee' => 'msg_cron_trigger'), |
|
98 | + EE_Messages_Scheduler::get_request_params($task) |
|
99 | + ), |
|
100 | + site_url() |
|
101 | + ); |
|
102 | + $request_args = array( |
|
103 | + 'timeout' => 300, |
|
104 | + 'blocking' => (defined('DOING_CRON') && DOING_CRON) || (defined('DOING_AJAX') && DOING_AJAX) ? true : false, |
|
105 | + 'sslverify' => false, |
|
106 | + 'redirection' => 10, |
|
107 | + ); |
|
108 | + $response = wp_remote_get($request_url, $request_args); |
|
109 | + if (is_wp_error($response)) { |
|
110 | + trigger_error($response->get_error_message()); |
|
111 | + } |
|
112 | + } else { |
|
113 | + EE_Messages_Scheduler::initiate_immediate_request_on_cron($task); |
|
114 | + } |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * This returns |
|
120 | + * the request params used for a scheduled message task request. |
|
121 | + * |
|
122 | + * @param string $task The task the request is for. |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + public static function get_request_params($task) |
|
126 | + { |
|
127 | + // transient is used for flood control on msg_cron_trigger requests |
|
128 | + $transient_key = 'ee_trans_' . uniqid($task); |
|
129 | + set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS); |
|
130 | + return array( |
|
131 | + 'type' => $task, |
|
132 | + 'key' => $transient_key, |
|
133 | + ); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * This is used to execute an immediate call to the run_cron task performed by EED_Messages |
|
139 | + * |
|
140 | + * @param string $task The task the request is being generated for. |
|
141 | + */ |
|
142 | + public static function initiate_immediate_request_on_cron($task) |
|
143 | + { |
|
144 | + $request_args = EE_Messages_Scheduler::get_request_params($task); |
|
145 | + // set those request args in the request so it gets picked up |
|
146 | + foreach ($request_args as $request_key => $request_value) { |
|
147 | + EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
148 | + } |
|
149 | + EED_Messages::instance()->run_cron(); |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * Callback for scheduled AHEE__EE_Messages_Scheduler__generation wp cron event |
|
155 | + */ |
|
156 | + public static function batch_generation() |
|
157 | + { |
|
158 | + /** |
|
159 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority() |
|
160 | + */ |
|
161 | + if (! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
162 | + || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
163 | + ) { |
|
164 | + EE_Messages_Scheduler::initiate_immediate_request_on_cron('generate'); |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * Callback for scheduled AHEE__EE_Messages_Scheduler__sending |
|
171 | + */ |
|
172 | + public static function batch_sending() |
|
173 | + { |
|
174 | + /** |
|
175 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority() |
|
176 | + */ |
|
177 | + if (! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
178 | + || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
179 | + ) { |
|
180 | + EE_Messages_Scheduler::initiate_immediate_request_on_cron('send'); |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * This is the callback for the `AHEE__EE_Messages_Scheduler__cleanup` scheduled event action. |
|
187 | + * This runs once a day and if cleanup is active (set via messages settings), it will (by default) delete permanently |
|
188 | + * from the database messages that have a MSG_modified date older than 30 days. |
|
189 | + */ |
|
190 | + public static function cleanup() |
|
191 | + { |
|
192 | + // first check if user has cleanup turned on or if we're in maintenance mode. If in maintenance mode we'll wait |
|
193 | + // until the next scheduled event. |
|
194 | + if (! EE_Registry::instance()->CFG->messages->delete_threshold |
|
195 | + || ! EE_Maintenance_Mode::instance()->models_can_query() |
|
196 | + ) { |
|
197 | + return; |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * This filter switch allows other code (such as the EE_Worker_Queue add-on) to replace this with its own handling |
|
202 | + * of deleting messages. |
|
203 | + */ |
|
204 | + if (apply_filters('FHEE__EE_Messages_Scheduler__cleanup__handle_cleanup_on_cron', true)) { |
|
205 | + EEM_Message::instance()->delete_old_messages(EE_Registry::instance()->CFG->messages->delete_threshold); |
|
206 | + } |
|
207 | + } |
|
208 | 208 | } |
@@ -26,12 +26,12 @@ discard block |
||
26 | 26 | public function __construct() |
27 | 27 | { |
28 | 28 | // register tasks (and make sure only registered once). |
29 | - if (! has_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'))) { |
|
29 | + if ( ! has_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'))) { |
|
30 | 30 | add_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'), 10); |
31 | 31 | } |
32 | 32 | |
33 | 33 | // register callbacks for scheduled events (but make sure they are set only once). |
34 | - if (! has_action( |
|
34 | + if ( ! has_action( |
|
35 | 35 | 'AHEE__EE_Messages_Scheduler__generation', |
36 | 36 | array('EE_Messages_Scheduler', 'batch_generation') |
37 | 37 | )) { |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | EE_Registry::instance()->load_helper('DTT_Helper'); |
76 | 76 | $tasks['AHEE__EE_Messages_Scheduler__generation'] = 'ee_message_cron'; |
77 | 77 | $tasks['AHEE__EE_Messages_Scheduler__sending'] = 'ee_message_cron'; |
78 | - $tasks['AHEE__EE_Messages_Scheduler__cleanup'] = array( EEH_DTT_Helper::tomorrow(), 'daily'); |
|
78 | + $tasks['AHEE__EE_Messages_Scheduler__cleanup'] = array(EEH_DTT_Helper::tomorrow(), 'daily'); |
|
79 | 79 | return $tasks; |
80 | 80 | } |
81 | 81 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | 'EE_Messages_Scheduler__initiate_scheduled_non_blocking_request__do_separate_request', |
93 | 93 | true |
94 | 94 | )) { |
95 | - $request_url = add_query_arg( |
|
95 | + $request_url = add_query_arg( |
|
96 | 96 | array_merge( |
97 | 97 | array('ee' => 'msg_cron_trigger'), |
98 | 98 | EE_Messages_Scheduler::get_request_params($task) |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | 'sslverify' => false, |
106 | 106 | 'redirection' => 10, |
107 | 107 | ); |
108 | - $response = wp_remote_get($request_url, $request_args); |
|
108 | + $response = wp_remote_get($request_url, $request_args); |
|
109 | 109 | if (is_wp_error($response)) { |
110 | 110 | trigger_error($response->get_error_message()); |
111 | 111 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | public static function get_request_params($task) |
126 | 126 | { |
127 | 127 | // transient is used for flood control on msg_cron_trigger requests |
128 | - $transient_key = 'ee_trans_' . uniqid($task); |
|
128 | + $transient_key = 'ee_trans_'.uniqid($task); |
|
129 | 129 | set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS); |
130 | 130 | return array( |
131 | 131 | 'type' => $task, |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | /** |
159 | 159 | * @see filter usage in EE_Messages_Queue::initiate_request_by_priority() |
160 | 160 | */ |
161 | - if (! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
161 | + if ( ! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
162 | 162 | || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
163 | 163 | ) { |
164 | 164 | EE_Messages_Scheduler::initiate_immediate_request_on_cron('generate'); |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | /** |
175 | 175 | * @see filter usage in EE_Messages_Queue::initiate_request_by_priority() |
176 | 176 | */ |
177 | - if (! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
177 | + if ( ! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
178 | 178 | || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
179 | 179 | ) { |
180 | 180 | EE_Messages_Scheduler::initiate_immediate_request_on_cron('send'); |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | { |
192 | 192 | // first check if user has cleanup turned on or if we're in maintenance mode. If in maintenance mode we'll wait |
193 | 193 | // until the next scheduled event. |
194 | - if (! EE_Registry::instance()->CFG->messages->delete_threshold |
|
194 | + if ( ! EE_Registry::instance()->CFG->messages->delete_threshold |
|
195 | 195 | || ! EE_Maintenance_Mode::instance()->models_can_query() |
196 | 196 | ) { |
197 | 197 | return; |
@@ -12,256 +12,256 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * EE_Message_Repository constructor |
|
17 | - */ |
|
18 | - public function __construct() |
|
19 | - { |
|
20 | - $this->interface = 'EE_Message'; |
|
21 | - parent::__construct(); |
|
22 | - } |
|
15 | + /** |
|
16 | + * EE_Message_Repository constructor |
|
17 | + */ |
|
18 | + public function __construct() |
|
19 | + { |
|
20 | + $this->interface = 'EE_Message'; |
|
21 | + parent::__construct(); |
|
22 | + } |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * Add the EE_Message to the repository. |
|
27 | - * This also ensures that the MSG_token is saves as a part of the info for retrieval. |
|
28 | - * |
|
29 | - * @param EE_Message $message |
|
30 | - * @param mixed $info Any included data is saved in the attached object info array indexed by 'data' |
|
31 | - * @return bool |
|
32 | - */ |
|
33 | - public function add($message, $info = null) |
|
34 | - { |
|
35 | - $attached = parent::add($message); |
|
36 | - // ensure $info is an array if not already |
|
37 | - $info = $info === null ? $info = array() : (array) $info; |
|
38 | - $data = $this->_init_data($info, $attached, $message); |
|
39 | - if ($attached) { |
|
40 | - $this->set_info($message, $data); |
|
41 | - } |
|
42 | - return $attached; |
|
43 | - } |
|
25 | + /** |
|
26 | + * Add the EE_Message to the repository. |
|
27 | + * This also ensures that the MSG_token is saves as a part of the info for retrieval. |
|
28 | + * |
|
29 | + * @param EE_Message $message |
|
30 | + * @param mixed $info Any included data is saved in the attached object info array indexed by 'data' |
|
31 | + * @return bool |
|
32 | + */ |
|
33 | + public function add($message, $info = null) |
|
34 | + { |
|
35 | + $attached = parent::add($message); |
|
36 | + // ensure $info is an array if not already |
|
37 | + $info = $info === null ? $info = array() : (array) $info; |
|
38 | + $data = $this->_init_data($info, $attached, $message); |
|
39 | + if ($attached) { |
|
40 | + $this->set_info($message, $data); |
|
41 | + } |
|
42 | + return $attached; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * Initializes the data from the incoming info. |
|
48 | - * |
|
49 | - * @param array $info incoming data. |
|
50 | - * @param bool $attached Indicates whether the object was attached successfully. |
|
51 | - * @param EE_Message $message |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - protected function _init_data($info, $attached, $message) |
|
55 | - { |
|
56 | - $data = array( |
|
57 | - 'test_send' => false, |
|
58 | - 'preview' => false, |
|
59 | - 'data_handler_class_name' => '', |
|
60 | - 'data' => array( |
|
61 | - 'MSG_generation_data' => array(), |
|
62 | - ), |
|
63 | - ); |
|
64 | - if (isset($info['preview'])) { |
|
65 | - $data['preview'] = $info['preview']; |
|
66 | - unset($info['preview']); |
|
67 | - } |
|
68 | - if (isset($info['test_send'])) { |
|
69 | - $data['test_send'] = $info['test_send']; |
|
70 | - unset($info['test_send']); |
|
71 | - } |
|
72 | - if (isset($info['data_handler_class_name'])) { |
|
73 | - $data['data_handler_class_name'] = $info['data_handler_class_name']; |
|
74 | - unset($info['data_handler_class_name']); |
|
75 | - } |
|
76 | - if ($attached && $message->STS_ID() === EEM_Message::status_incomplete) { |
|
77 | - $generation_data = isset($info['MSG_generation_data']) ? $info['MSG_generation_data'] : array(); |
|
78 | - // if data isn't in $info...let's see if its available via the message object |
|
79 | - $generation_data = ! $generation_data ? $message->get_generation_data() : $generation_data; |
|
80 | - // still empty then let's just use info |
|
81 | - $generation_data = ! $generation_data ? $info : $generation_data; |
|
82 | - $data['data']['MSG_generation_data'] = $generation_data; |
|
83 | - } |
|
84 | - return $data; |
|
85 | - } |
|
46 | + /** |
|
47 | + * Initializes the data from the incoming info. |
|
48 | + * |
|
49 | + * @param array $info incoming data. |
|
50 | + * @param bool $attached Indicates whether the object was attached successfully. |
|
51 | + * @param EE_Message $message |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + protected function _init_data($info, $attached, $message) |
|
55 | + { |
|
56 | + $data = array( |
|
57 | + 'test_send' => false, |
|
58 | + 'preview' => false, |
|
59 | + 'data_handler_class_name' => '', |
|
60 | + 'data' => array( |
|
61 | + 'MSG_generation_data' => array(), |
|
62 | + ), |
|
63 | + ); |
|
64 | + if (isset($info['preview'])) { |
|
65 | + $data['preview'] = $info['preview']; |
|
66 | + unset($info['preview']); |
|
67 | + } |
|
68 | + if (isset($info['test_send'])) { |
|
69 | + $data['test_send'] = $info['test_send']; |
|
70 | + unset($info['test_send']); |
|
71 | + } |
|
72 | + if (isset($info['data_handler_class_name'])) { |
|
73 | + $data['data_handler_class_name'] = $info['data_handler_class_name']; |
|
74 | + unset($info['data_handler_class_name']); |
|
75 | + } |
|
76 | + if ($attached && $message->STS_ID() === EEM_Message::status_incomplete) { |
|
77 | + $generation_data = isset($info['MSG_generation_data']) ? $info['MSG_generation_data'] : array(); |
|
78 | + // if data isn't in $info...let's see if its available via the message object |
|
79 | + $generation_data = ! $generation_data ? $message->get_generation_data() : $generation_data; |
|
80 | + // still empty then let's just use info |
|
81 | + $generation_data = ! $generation_data ? $info : $generation_data; |
|
82 | + $data['data']['MSG_generation_data'] = $generation_data; |
|
83 | + } |
|
84 | + return $data; |
|
85 | + } |
|
86 | 86 | |
87 | 87 | |
88 | - /** |
|
89 | - * Save all EE_Message objects to the db. |
|
90 | - * |
|
91 | - * @param bool $do_hooks_only When true, only the hooks related to saving are fired. |
|
92 | - * @return array array( |
|
93 | - * 'updated' => 0, //count of how many messages updated |
|
94 | - * 'notupdated' => 0, //count of how many messages not updated. |
|
95 | - * 'errors' => array( $token ), //array of message object tokens that had errors in saving |
|
96 | - * ) |
|
97 | - */ |
|
98 | - public function saveAll($do_hooks_only = false) |
|
99 | - { |
|
100 | - $save_tracking = array('updated' => 0, 'notupdated' => 0, 'errors' => array()); |
|
88 | + /** |
|
89 | + * Save all EE_Message objects to the db. |
|
90 | + * |
|
91 | + * @param bool $do_hooks_only When true, only the hooks related to saving are fired. |
|
92 | + * @return array array( |
|
93 | + * 'updated' => 0, //count of how many messages updated |
|
94 | + * 'notupdated' => 0, //count of how many messages not updated. |
|
95 | + * 'errors' => array( $token ), //array of message object tokens that had errors in saving |
|
96 | + * ) |
|
97 | + */ |
|
98 | + public function saveAll($do_hooks_only = false) |
|
99 | + { |
|
100 | + $save_tracking = array('updated' => 0, 'notupdated' => 0, 'errors' => array()); |
|
101 | 101 | |
102 | - if (! $do_hooks_only) { |
|
103 | - $this->rewind(); |
|
104 | - // exit early if there is nothing to save. |
|
105 | - if ($this->count() < 1) { |
|
106 | - return $save_tracking; |
|
107 | - } |
|
102 | + if (! $do_hooks_only) { |
|
103 | + $this->rewind(); |
|
104 | + // exit early if there is nothing to save. |
|
105 | + if ($this->count() < 1) { |
|
106 | + return $save_tracking; |
|
107 | + } |
|
108 | 108 | |
109 | - while ($this->valid()) { |
|
110 | - $saved = $this->current()->save(); |
|
111 | - if ($saved === false) { |
|
112 | - $save_tracking['errors'][] = $this->current()->MSG_token(); |
|
113 | - } elseif ($saved) { |
|
114 | - $save_tracking['updated']++; |
|
115 | - } else { |
|
116 | - $save_tracking['notupdated']++; |
|
117 | - } |
|
118 | - // maybe persist generation data if this is an incomplete EE_Message. |
|
119 | - $this->_maybe_persist_attached_data(); |
|
109 | + while ($this->valid()) { |
|
110 | + $saved = $this->current()->save(); |
|
111 | + if ($saved === false) { |
|
112 | + $save_tracking['errors'][] = $this->current()->MSG_token(); |
|
113 | + } elseif ($saved) { |
|
114 | + $save_tracking['updated']++; |
|
115 | + } else { |
|
116 | + $save_tracking['notupdated']++; |
|
117 | + } |
|
118 | + // maybe persist generation data if this is an incomplete EE_Message. |
|
119 | + $this->_maybe_persist_attached_data(); |
|
120 | 120 | |
121 | - $this->next(); |
|
122 | - } |
|
123 | - } |
|
124 | - do_action('AHEE__EE_Message_Repository__saveAll__after', $save_tracking, $this, $do_hooks_only); |
|
125 | - return $save_tracking; |
|
126 | - } |
|
121 | + $this->next(); |
|
122 | + } |
|
123 | + } |
|
124 | + do_action('AHEE__EE_Message_Repository__saveAll__after', $save_tracking, $this, $do_hooks_only); |
|
125 | + return $save_tracking; |
|
126 | + } |
|
127 | 127 | |
128 | 128 | |
129 | - /** |
|
130 | - * Retrieves a EE_Message from the repository that matches the given token. |
|
131 | - * |
|
132 | - * @param string $token Token. |
|
133 | - * @return EE_Message | null |
|
134 | - */ |
|
135 | - public function getMessageByToken($token) |
|
136 | - { |
|
137 | - $this->rewind(); |
|
138 | - while ($this->valid()) { |
|
139 | - if ($this->current()->MSG_token() === $token) { |
|
140 | - $message = $this->current(); |
|
141 | - $this->rewind(); |
|
142 | - return $message; |
|
143 | - } |
|
144 | - $this->next(); |
|
145 | - } |
|
146 | - return null; |
|
147 | - } |
|
129 | + /** |
|
130 | + * Retrieves a EE_Message from the repository that matches the given token. |
|
131 | + * |
|
132 | + * @param string $token Token. |
|
133 | + * @return EE_Message | null |
|
134 | + */ |
|
135 | + public function getMessageByToken($token) |
|
136 | + { |
|
137 | + $this->rewind(); |
|
138 | + while ($this->valid()) { |
|
139 | + if ($this->current()->MSG_token() === $token) { |
|
140 | + $message = $this->current(); |
|
141 | + $this->rewind(); |
|
142 | + return $message; |
|
143 | + } |
|
144 | + $this->next(); |
|
145 | + } |
|
146 | + return null; |
|
147 | + } |
|
148 | 148 | |
149 | 149 | |
150 | - /** |
|
151 | - * This retrieves any data required for generation that may be saved with the current EE_Message in storage. |
|
152 | - * |
|
153 | - * @return array(); |
|
154 | - */ |
|
155 | - public function get_generation_data() |
|
156 | - { |
|
157 | - // first verify we're at a valid iterator point. |
|
158 | - if (! $this->valid()) { |
|
159 | - return array(); |
|
160 | - } |
|
161 | - $info = $this->getInfo(); |
|
162 | - return isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array(); |
|
163 | - } |
|
150 | + /** |
|
151 | + * This retrieves any data required for generation that may be saved with the current EE_Message in storage. |
|
152 | + * |
|
153 | + * @return array(); |
|
154 | + */ |
|
155 | + public function get_generation_data() |
|
156 | + { |
|
157 | + // first verify we're at a valid iterator point. |
|
158 | + if (! $this->valid()) { |
|
159 | + return array(); |
|
160 | + } |
|
161 | + $info = $this->getInfo(); |
|
162 | + return isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array(); |
|
163 | + } |
|
164 | 164 | |
165 | 165 | |
166 | - /** |
|
167 | - * Retrieves the data_handler_class_name or reference associated with the current EE_Message object in the iterator. |
|
168 | - * |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function get_data_handler() |
|
172 | - { |
|
173 | - if (! $this->valid()) { |
|
174 | - return ''; |
|
175 | - } |
|
176 | - $info = $this->getInfo(); |
|
177 | - return isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : ''; |
|
178 | - } |
|
166 | + /** |
|
167 | + * Retrieves the data_handler_class_name or reference associated with the current EE_Message object in the iterator. |
|
168 | + * |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function get_data_handler() |
|
172 | + { |
|
173 | + if (! $this->valid()) { |
|
174 | + return ''; |
|
175 | + } |
|
176 | + $info = $this->getInfo(); |
|
177 | + return isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : ''; |
|
178 | + } |
|
179 | 179 | |
180 | 180 | |
181 | - /** |
|
182 | - * Returns whether this EE_Message is for a preview or not. |
|
183 | - * |
|
184 | - * @return bool |
|
185 | - */ |
|
186 | - public function is_preview() |
|
187 | - { |
|
188 | - if (! $this->valid()) { |
|
189 | - return false; |
|
190 | - } |
|
191 | - $info = $this->getInfo(); |
|
192 | - return $info['preview']; |
|
193 | - } |
|
181 | + /** |
|
182 | + * Returns whether this EE_Message is for a preview or not. |
|
183 | + * |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | + public function is_preview() |
|
187 | + { |
|
188 | + if (! $this->valid()) { |
|
189 | + return false; |
|
190 | + } |
|
191 | + $info = $this->getInfo(); |
|
192 | + return $info['preview']; |
|
193 | + } |
|
194 | 194 | |
195 | 195 | |
196 | - /** |
|
197 | - * Returns whether the current message pointed to is for a test send. |
|
198 | - * |
|
199 | - * @return bool |
|
200 | - */ |
|
201 | - public function is_test_send() |
|
202 | - { |
|
203 | - if (! $this->valid()) { |
|
204 | - return false; |
|
205 | - } |
|
206 | - $info = $this->getInfo(); |
|
207 | - return $info['test_send']; |
|
208 | - } |
|
196 | + /** |
|
197 | + * Returns whether the current message pointed to is for a test send. |
|
198 | + * |
|
199 | + * @return bool |
|
200 | + */ |
|
201 | + public function is_test_send() |
|
202 | + { |
|
203 | + if (! $this->valid()) { |
|
204 | + return false; |
|
205 | + } |
|
206 | + $info = $this->getInfo(); |
|
207 | + return $info['test_send']; |
|
208 | + } |
|
209 | 209 | |
210 | 210 | |
211 | - /** |
|
212 | - * This checks if the current EE_Message in the iterator is incomplete. If it is, then |
|
213 | - * data is attached for later retrieval (batch generation). |
|
214 | - */ |
|
215 | - protected function _maybe_persist_attached_data() |
|
216 | - { |
|
217 | - if (! $this->valid()) { |
|
218 | - return; |
|
219 | - } |
|
211 | + /** |
|
212 | + * This checks if the current EE_Message in the iterator is incomplete. If it is, then |
|
213 | + * data is attached for later retrieval (batch generation). |
|
214 | + */ |
|
215 | + protected function _maybe_persist_attached_data() |
|
216 | + { |
|
217 | + if (! $this->valid()) { |
|
218 | + return; |
|
219 | + } |
|
220 | 220 | |
221 | - $info = $this->getInfo(); |
|
222 | - $data_handler_class_name = isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : ''; |
|
223 | - $data = isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array(); |
|
224 | - if ($data && $this->current()->STS_ID() === EEM_Message::status_incomplete) { |
|
225 | - $this->current()->set_generation_data($data); |
|
226 | - $this->current()->set_field_or_extra_meta('data_handler_class_name', $data_handler_class_name); |
|
227 | - } |
|
228 | - } |
|
221 | + $info = $this->getInfo(); |
|
222 | + $data_handler_class_name = isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : ''; |
|
223 | + $data = isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array(); |
|
224 | + if ($data && $this->current()->STS_ID() === EEM_Message::status_incomplete) { |
|
225 | + $this->current()->set_generation_data($data); |
|
226 | + $this->current()->set_field_or_extra_meta('data_handler_class_name', $data_handler_class_name); |
|
227 | + } |
|
228 | + } |
|
229 | 229 | |
230 | 230 | |
231 | - /** |
|
232 | - * This method returns a count of messages in the repository that have a given priority. |
|
233 | - * |
|
234 | - * @param int $priority the priority that is being filtered for the count. |
|
235 | - * @param array $status the optional status(es) that will also be filtered by when priority matches. |
|
236 | - * @return int count of messages in the queue matching the conditions. |
|
237 | - */ |
|
238 | - public function count_by_priority_and_status($priority, $status = array()) |
|
239 | - { |
|
240 | - if (! empty($status)) { |
|
241 | - $status = is_array($status) ? $status : array($status); |
|
242 | - } |
|
231 | + /** |
|
232 | + * This method returns a count of messages in the repository that have a given priority. |
|
233 | + * |
|
234 | + * @param int $priority the priority that is being filtered for the count. |
|
235 | + * @param array $status the optional status(es) that will also be filtered by when priority matches. |
|
236 | + * @return int count of messages in the queue matching the conditions. |
|
237 | + */ |
|
238 | + public function count_by_priority_and_status($priority, $status = array()) |
|
239 | + { |
|
240 | + if (! empty($status)) { |
|
241 | + $status = is_array($status) ? $status : array($status); |
|
242 | + } |
|
243 | 243 | |
244 | - $count = 0; |
|
245 | - $this->rewind(); |
|
246 | - while ($this->valid()) { |
|
247 | - if ($this->current()->priority() === $priority && (($status && in_array( |
|
248 | - $this->current()->STS_ID(), |
|
249 | - $status |
|
250 | - )) || ! $status) |
|
251 | - ) { |
|
252 | - $count++; |
|
253 | - } |
|
254 | - $this->next(); |
|
255 | - } |
|
256 | - return $count; |
|
257 | - } |
|
244 | + $count = 0; |
|
245 | + $this->rewind(); |
|
246 | + while ($this->valid()) { |
|
247 | + if ($this->current()->priority() === $priority && (($status && in_array( |
|
248 | + $this->current()->STS_ID(), |
|
249 | + $status |
|
250 | + )) || ! $status) |
|
251 | + ) { |
|
252 | + $count++; |
|
253 | + } |
|
254 | + $this->next(); |
|
255 | + } |
|
256 | + return $count; |
|
257 | + } |
|
258 | 258 | |
259 | 259 | |
260 | - /** |
|
261 | - * @return EE_Message |
|
262 | - */ |
|
263 | - public function current() |
|
264 | - { |
|
265 | - return parent::current(); |
|
266 | - } |
|
260 | + /** |
|
261 | + * @return EE_Message |
|
262 | + */ |
|
263 | + public function current() |
|
264 | + { |
|
265 | + return parent::current(); |
|
266 | + } |
|
267 | 267 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | { |
100 | 100 | $save_tracking = array('updated' => 0, 'notupdated' => 0, 'errors' => array()); |
101 | 101 | |
102 | - if (! $do_hooks_only) { |
|
102 | + if ( ! $do_hooks_only) { |
|
103 | 103 | $this->rewind(); |
104 | 104 | // exit early if there is nothing to save. |
105 | 105 | if ($this->count() < 1) { |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | public function get_generation_data() |
156 | 156 | { |
157 | 157 | // first verify we're at a valid iterator point. |
158 | - if (! $this->valid()) { |
|
158 | + if ( ! $this->valid()) { |
|
159 | 159 | return array(); |
160 | 160 | } |
161 | 161 | $info = $this->getInfo(); |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | */ |
171 | 171 | public function get_data_handler() |
172 | 172 | { |
173 | - if (! $this->valid()) { |
|
173 | + if ( ! $this->valid()) { |
|
174 | 174 | return ''; |
175 | 175 | } |
176 | 176 | $info = $this->getInfo(); |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public function is_preview() |
187 | 187 | { |
188 | - if (! $this->valid()) { |
|
188 | + if ( ! $this->valid()) { |
|
189 | 189 | return false; |
190 | 190 | } |
191 | 191 | $info = $this->getInfo(); |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | */ |
201 | 201 | public function is_test_send() |
202 | 202 | { |
203 | - if (! $this->valid()) { |
|
203 | + if ( ! $this->valid()) { |
|
204 | 204 | return false; |
205 | 205 | } |
206 | 206 | $info = $this->getInfo(); |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | */ |
215 | 215 | protected function _maybe_persist_attached_data() |
216 | 216 | { |
217 | - if (! $this->valid()) { |
|
217 | + if ( ! $this->valid()) { |
|
218 | 218 | return; |
219 | 219 | } |
220 | 220 | |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | */ |
238 | 238 | public function count_by_priority_and_status($priority, $status = array()) |
239 | 239 | { |
240 | - if (! empty($status)) { |
|
240 | + if ( ! empty($status)) { |
|
241 | 241 | $status = is_array($status) ? $status : array($status); |
242 | 242 | } |
243 | 243 |
@@ -14,168 +14,168 @@ |
||
14 | 14 | class EE_Message_Type_Collection extends EE_Object_Collection |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * EE_Message_Type_Collection constructor. |
|
19 | - */ |
|
20 | - public function __construct() |
|
21 | - { |
|
22 | - $this->interface = 'EE_message_type'; |
|
23 | - } |
|
24 | - |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * add |
|
29 | - * |
|
30 | - * attaches an object to the Collection |
|
31 | - * and sets any supplied data associated with the current iterator entry |
|
32 | - * by calling EE_Object_Collection::set_info() |
|
33 | - * |
|
34 | - * @access public |
|
35 | - * @param object $object |
|
36 | - * @param mixed $info |
|
37 | - * @return bool |
|
38 | - */ |
|
39 | - public function add($object, $info = null) |
|
40 | - { |
|
41 | - $info = empty($info) && $object instanceof $this->interface ? $object->name : $info; |
|
42 | - return parent::add($object, $info); |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * set_info |
|
49 | - * |
|
50 | - * Sets the data associated with an object in the Collection |
|
51 | - * if no $info is supplied, then the spl_object_hash() is used |
|
52 | - * |
|
53 | - * @access public |
|
54 | - * @param object $object |
|
55 | - * @param mixed $info |
|
56 | - * @return bool |
|
57 | - */ |
|
58 | - public function set_info($object, $info = null) |
|
59 | - { |
|
60 | - $info = empty($info) && $object instanceof $this->interface ? $object->name : $info; |
|
61 | - return parent::set_info($object, $info); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * get_by_info |
|
68 | - * |
|
69 | - * finds and returns an object in the Collection based on the info that was set using addObject() |
|
70 | - * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
71 | - * |
|
72 | - * @access public |
|
73 | - * @param mixed |
|
74 | - * @return null | object |
|
75 | - */ |
|
76 | - public function get_by_info($info) |
|
77 | - { |
|
78 | - return parent::get_by_info(str_replace(' ', '_', strtolower($info))); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * has |
|
85 | - * |
|
86 | - * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
87 | - * |
|
88 | - * @access public |
|
89 | - * @param object $object |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - public function has($object) |
|
93 | - { |
|
94 | - return parent::has($object); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * has_by_name |
|
101 | - * |
|
102 | - * returns TRUE or FALSE depending on whether the supplied message_type classname is within the Collection |
|
103 | - * |
|
104 | - * @access public |
|
105 | - * @param string $message_type_name |
|
106 | - * @return bool |
|
107 | - */ |
|
108 | - public function has_by_name($message_type_name) |
|
109 | - { |
|
110 | - return $this->get_by_info($message_type_name) instanceof $this->interface ? true : false; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * remove |
|
117 | - * |
|
118 | - * detaches an object from the Collection |
|
119 | - * |
|
120 | - * @access public |
|
121 | - * @param $object |
|
122 | - * @return bool |
|
123 | - */ |
|
124 | - public function remove($object) |
|
125 | - { |
|
126 | - return parent::remove($object); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * set_current |
|
133 | - * |
|
134 | - * advances pointer to the provided object |
|
135 | - * |
|
136 | - * @access public |
|
137 | - * @param $object |
|
138 | - * @return void |
|
139 | - */ |
|
140 | - public function set_current($object) |
|
141 | - { |
|
142 | - parent::set_current($object); |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * set_current_by_info |
|
149 | - * |
|
150 | - * advances pointer to the object whose info matches that which was provided |
|
151 | - * |
|
152 | - * @access public |
|
153 | - * @param $info |
|
154 | - * @return void |
|
155 | - */ |
|
156 | - public function set_current_by_info($info) |
|
157 | - { |
|
158 | - parent::set_current_by_info($info); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * show_collection_classes |
|
165 | - * |
|
166 | - * displays list of collection classes if WP_DEBUG is on |
|
167 | - * |
|
168 | - * @access public |
|
169 | - * @return void |
|
170 | - */ |
|
171 | - public function show_collection_classes() |
|
172 | - { |
|
173 | - if (WP_DEBUG) { |
|
174 | - $this->rewind(); |
|
175 | - while ($this->valid()) { |
|
176 | - echo '<h5 style="color:#2EA2CC;">' . __CLASS__ . ' class : <span style="color:#E76700">' . $this->getInfo() . '</span></h5>'; |
|
177 | - $this->next(); |
|
178 | - } |
|
179 | - } |
|
180 | - } |
|
17 | + /** |
|
18 | + * EE_Message_Type_Collection constructor. |
|
19 | + */ |
|
20 | + public function __construct() |
|
21 | + { |
|
22 | + $this->interface = 'EE_message_type'; |
|
23 | + } |
|
24 | + |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * add |
|
29 | + * |
|
30 | + * attaches an object to the Collection |
|
31 | + * and sets any supplied data associated with the current iterator entry |
|
32 | + * by calling EE_Object_Collection::set_info() |
|
33 | + * |
|
34 | + * @access public |
|
35 | + * @param object $object |
|
36 | + * @param mixed $info |
|
37 | + * @return bool |
|
38 | + */ |
|
39 | + public function add($object, $info = null) |
|
40 | + { |
|
41 | + $info = empty($info) && $object instanceof $this->interface ? $object->name : $info; |
|
42 | + return parent::add($object, $info); |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * set_info |
|
49 | + * |
|
50 | + * Sets the data associated with an object in the Collection |
|
51 | + * if no $info is supplied, then the spl_object_hash() is used |
|
52 | + * |
|
53 | + * @access public |
|
54 | + * @param object $object |
|
55 | + * @param mixed $info |
|
56 | + * @return bool |
|
57 | + */ |
|
58 | + public function set_info($object, $info = null) |
|
59 | + { |
|
60 | + $info = empty($info) && $object instanceof $this->interface ? $object->name : $info; |
|
61 | + return parent::set_info($object, $info); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * get_by_info |
|
68 | + * |
|
69 | + * finds and returns an object in the Collection based on the info that was set using addObject() |
|
70 | + * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
71 | + * |
|
72 | + * @access public |
|
73 | + * @param mixed |
|
74 | + * @return null | object |
|
75 | + */ |
|
76 | + public function get_by_info($info) |
|
77 | + { |
|
78 | + return parent::get_by_info(str_replace(' ', '_', strtolower($info))); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * has |
|
85 | + * |
|
86 | + * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
87 | + * |
|
88 | + * @access public |
|
89 | + * @param object $object |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + public function has($object) |
|
93 | + { |
|
94 | + return parent::has($object); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * has_by_name |
|
101 | + * |
|
102 | + * returns TRUE or FALSE depending on whether the supplied message_type classname is within the Collection |
|
103 | + * |
|
104 | + * @access public |
|
105 | + * @param string $message_type_name |
|
106 | + * @return bool |
|
107 | + */ |
|
108 | + public function has_by_name($message_type_name) |
|
109 | + { |
|
110 | + return $this->get_by_info($message_type_name) instanceof $this->interface ? true : false; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * remove |
|
117 | + * |
|
118 | + * detaches an object from the Collection |
|
119 | + * |
|
120 | + * @access public |
|
121 | + * @param $object |
|
122 | + * @return bool |
|
123 | + */ |
|
124 | + public function remove($object) |
|
125 | + { |
|
126 | + return parent::remove($object); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * set_current |
|
133 | + * |
|
134 | + * advances pointer to the provided object |
|
135 | + * |
|
136 | + * @access public |
|
137 | + * @param $object |
|
138 | + * @return void |
|
139 | + */ |
|
140 | + public function set_current($object) |
|
141 | + { |
|
142 | + parent::set_current($object); |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * set_current_by_info |
|
149 | + * |
|
150 | + * advances pointer to the object whose info matches that which was provided |
|
151 | + * |
|
152 | + * @access public |
|
153 | + * @param $info |
|
154 | + * @return void |
|
155 | + */ |
|
156 | + public function set_current_by_info($info) |
|
157 | + { |
|
158 | + parent::set_current_by_info($info); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * show_collection_classes |
|
165 | + * |
|
166 | + * displays list of collection classes if WP_DEBUG is on |
|
167 | + * |
|
168 | + * @access public |
|
169 | + * @return void |
|
170 | + */ |
|
171 | + public function show_collection_classes() |
|
172 | + { |
|
173 | + if (WP_DEBUG) { |
|
174 | + $this->rewind(); |
|
175 | + while ($this->valid()) { |
|
176 | + echo '<h5 style="color:#2EA2CC;">' . __CLASS__ . ' class : <span style="color:#E76700">' . $this->getInfo() . '</span></h5>'; |
|
177 | + $this->next(); |
|
178 | + } |
|
179 | + } |
|
180 | + } |
|
181 | 181 | } |
@@ -173,7 +173,7 @@ |
||
173 | 173 | if (WP_DEBUG) { |
174 | 174 | $this->rewind(); |
175 | 175 | while ($this->valid()) { |
176 | - echo '<h5 style="color:#2EA2CC;">' . __CLASS__ . ' class : <span style="color:#E76700">' . $this->getInfo() . '</span></h5>'; |
|
176 | + echo '<h5 style="color:#2EA2CC;">'.__CLASS__.' class : <span style="color:#E76700">'.$this->getInfo().'</span></h5>'; |
|
177 | 177 | $this->next(); |
178 | 178 | } |
179 | 179 | } |