@@ -28,7 +28,7 @@ |
||
28 | 28 | margin-right: .25em; |
29 | 29 | } |
30 | 30 | </style> |
31 | -<?php endif;?> |
|
31 | +<?php endif; ?> |
|
32 | 32 | <div id="<?php echo $persistent_admin_notice_name; ?>" class="espresso-notices updated ee-nag-notice clearfix"> |
33 | 33 | <button class="dismiss-ee-nag-notice-btn dismiss-ee-nag-notice hide-if-no-js" data-target="<?php echo $persistent_admin_notice_name; ?>"> |
34 | 34 | <a><span class="dashicons dashicons-dismiss"></span><?php esc_html_e('Dismiss', 'event_espresso'); ?></a> |
@@ -49,29 +49,29 @@ |
||
49 | 49 | |
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * _migration_step |
|
54 | - * |
|
55 | - * @access protected |
|
56 | - * @param int $num_items |
|
57 | - * @throws EE_Error |
|
58 | - * @return int number of items ACTUALLY migrated |
|
59 | - * @throws InvalidDataTypeException |
|
60 | - */ |
|
52 | + /** |
|
53 | + * _migration_step |
|
54 | + * |
|
55 | + * @access protected |
|
56 | + * @param int $num_items |
|
57 | + * @throws EE_Error |
|
58 | + * @return int number of items ACTUALLY migrated |
|
59 | + * @throws InvalidDataTypeException |
|
60 | + */ |
|
61 | 61 | protected function _migration_step( $num_items = 1 ){ |
62 | 62 | |
63 | 63 | $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
64 | 64 | $overridden_invoice_body = EEH_Template::locate_template( $templates_relative_path . 'invoice_body.template.php', NULL, FALSE, FALSE, TRUE ); |
65 | 65 | $overridden_receipt_body= EEH_Template::locate_template( $templates_relative_path . 'receipt_body.template.php', NULL, FALSE, FALSE, TRUE ); |
66 | 66 | if( $overridden_invoice_body || $overridden_receipt_body ) { |
67 | - new PersistentAdminNotice( |
|
68 | - 'invoice_overriding_templates', |
|
69 | - esc_html__( |
|
70 | - 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents (but this will be removed in an upcoming version). We recommend deleting your old Invoice/Receipt templates and using the new messages system. Then modify the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
71 | - 'event_espresso' |
|
72 | - ), |
|
73 | - true |
|
74 | - ); |
|
67 | + new PersistentAdminNotice( |
|
68 | + 'invoice_overriding_templates', |
|
69 | + esc_html__( |
|
70 | + 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents (but this will be removed in an upcoming version). We recommend deleting your old Invoice/Receipt templates and using the new messages system. Then modify the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
71 | + 'event_espresso' |
|
72 | + ), |
|
73 | + true |
|
74 | + ); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | //regardless of whether it worked or not, we ought to continue the migration |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * Just initializes the status of the migration |
31 | 31 | */ |
32 | 32 | public function __construct() { |
33 | - $this->_pretty_name = __( 'Update Invoice Settings', 'event_espresso' ); |
|
33 | + $this->_pretty_name = __('Update Invoice Settings', 'event_espresso'); |
|
34 | 34 | parent::__construct(); |
35 | 35 | } |
36 | 36 | |
@@ -58,12 +58,12 @@ discard block |
||
58 | 58 | * @return int number of items ACTUALLY migrated |
59 | 59 | * @throws InvalidDataTypeException |
60 | 60 | */ |
61 | - protected function _migration_step( $num_items = 1 ){ |
|
61 | + protected function _migration_step($num_items = 1) { |
|
62 | 62 | |
63 | 63 | $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
64 | - $overridden_invoice_body = EEH_Template::locate_template( $templates_relative_path . 'invoice_body.template.php', NULL, FALSE, FALSE, TRUE ); |
|
65 | - $overridden_receipt_body= EEH_Template::locate_template( $templates_relative_path . 'receipt_body.template.php', NULL, FALSE, FALSE, TRUE ); |
|
66 | - if( $overridden_invoice_body || $overridden_receipt_body ) { |
|
64 | + $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path.'invoice_body.template.php', NULL, FALSE, FALSE, TRUE); |
|
65 | + $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path.'receipt_body.template.php', NULL, FALSE, FALSE, TRUE); |
|
66 | + if ($overridden_invoice_body || $overridden_receipt_body) { |
|
67 | 67 | new PersistentAdminNotice( |
68 | 68 | 'invoice_overriding_templates', |
69 | 69 | esc_html__( |
@@ -18,65 +18,65 @@ |
||
18 | 18 | class CoffeeMill |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var CoffeeShop $coffee_shop |
|
23 | - */ |
|
24 | - private static $coffee_shop; |
|
25 | - |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * @return mixed |
|
30 | - */ |
|
31 | - public static function getCoffeeShop() |
|
32 | - { |
|
33 | - return self::$coffee_shop; |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @param CoffeeShop $coffee_shop |
|
40 | - */ |
|
41 | - public static function setCoffeeShop(CoffeeShop $coffee_shop) |
|
42 | - { |
|
43 | - self::$coffee_shop = $coffee_shop; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @param string $identifier |
|
50 | - * @param array $arguments |
|
51 | - * @param string $type |
|
52 | - * @return mixed |
|
53 | - * @throws ServiceNotFoundException |
|
54 | - */ |
|
55 | - public static function createNew($identifier, $arguments = array(), $type = CoffeeMaker::BREW_NEW) |
|
56 | - { |
|
57 | - return self::$coffee_shop->brew($identifier, $arguments, $type); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * IMPORTANT!!! |
|
64 | - * Usage of this method is discouraged as it promotes service location. |
|
65 | - * It's current use is only as a stop gap measure until the CoffeeShop |
|
66 | - * Dependency Injection Container can be implemented properly for all classes. |
|
67 | - * If it is at all possible, inject your dependencies via your class constructor. |
|
68 | - * This method WILL BE DEPRECATED at some point in the near future. |
|
69 | - * |
|
70 | - * @param string $identifier |
|
71 | - * @param array $arguments |
|
72 | - * @param string $type |
|
73 | - * @return mixed |
|
74 | - * @throws ServiceNotFoundException |
|
75 | - */ |
|
76 | - public static function getService($identifier, $arguments = array(), $type = CoffeeMaker::BREW_SHARED) |
|
77 | - { |
|
78 | - return self::$coffee_shop->brew($identifier, $arguments, $type); |
|
79 | - } |
|
21 | + /** |
|
22 | + * @var CoffeeShop $coffee_shop |
|
23 | + */ |
|
24 | + private static $coffee_shop; |
|
25 | + |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * @return mixed |
|
30 | + */ |
|
31 | + public static function getCoffeeShop() |
|
32 | + { |
|
33 | + return self::$coffee_shop; |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @param CoffeeShop $coffee_shop |
|
40 | + */ |
|
41 | + public static function setCoffeeShop(CoffeeShop $coffee_shop) |
|
42 | + { |
|
43 | + self::$coffee_shop = $coffee_shop; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @param string $identifier |
|
50 | + * @param array $arguments |
|
51 | + * @param string $type |
|
52 | + * @return mixed |
|
53 | + * @throws ServiceNotFoundException |
|
54 | + */ |
|
55 | + public static function createNew($identifier, $arguments = array(), $type = CoffeeMaker::BREW_NEW) |
|
56 | + { |
|
57 | + return self::$coffee_shop->brew($identifier, $arguments, $type); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * IMPORTANT!!! |
|
64 | + * Usage of this method is discouraged as it promotes service location. |
|
65 | + * It's current use is only as a stop gap measure until the CoffeeShop |
|
66 | + * Dependency Injection Container can be implemented properly for all classes. |
|
67 | + * If it is at all possible, inject your dependencies via your class constructor. |
|
68 | + * This method WILL BE DEPRECATED at some point in the near future. |
|
69 | + * |
|
70 | + * @param string $identifier |
|
71 | + * @param array $arguments |
|
72 | + * @param string $type |
|
73 | + * @return mixed |
|
74 | + * @throws ServiceNotFoundException |
|
75 | + */ |
|
76 | + public static function getService($identifier, $arguments = array(), $type = CoffeeMaker::BREW_SHARED) |
|
77 | + { |
|
78 | + return self::$coffee_shop->brew($identifier, $arguments, $type); |
|
79 | + } |
|
80 | 80 | |
81 | 81 | } |
82 | 82 | // End of file CoffeeMill.php |
@@ -27,338 +27,338 @@ |
||
27 | 27 | class PersistentAdminNoticeManager |
28 | 28 | { |
29 | 29 | |
30 | - const WP_OPTION_KEY = 'ee_pers_admin_notices'; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var Collection|PersistentAdminNotice[] $notice_collection |
|
34 | - */ |
|
35 | - private $notice_collection; |
|
36 | - |
|
37 | - /** |
|
38 | - * @type string $return_url |
|
39 | - */ |
|
40 | - private $return_url; |
|
41 | - |
|
42 | - /** |
|
43 | - * @type CapabilitiesChecker $capabilities_checker |
|
44 | - */ |
|
45 | - private $capabilities_checker; |
|
46 | - |
|
47 | - /** |
|
48 | - * @type EE_Request $request |
|
49 | - */ |
|
50 | - private $request; |
|
51 | - |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * CapChecker constructor |
|
56 | - * |
|
57 | - * @param string $return_url |
|
58 | - * @param CapabilitiesChecker $capabilities_checker |
|
59 | - * @param EE_Request $request |
|
60 | - * @throws InvalidDataTypeException |
|
61 | - */ |
|
62 | - public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, EE_Request $request) |
|
63 | - { |
|
64 | - $this->setReturnUrl($return_url); |
|
65 | - $this->capabilities_checker = $capabilities_checker; |
|
66 | - $this->request = $request; |
|
67 | - //ok so we want to enable the entire admin |
|
68 | - add_action('admin_notices', array($this, 'displayNotices'), 9); |
|
69 | - add_action('network_admin_notices', array($this, 'displayNotices'), 9); |
|
70 | - add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice')); |
|
71 | - add_action('shutdown', array($this, 'saveNotices')); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @param string $return_url |
|
78 | - * @throws InvalidDataTypeException |
|
79 | - */ |
|
80 | - private function setReturnUrl($return_url) |
|
81 | - { |
|
82 | - if ( ! is_string($return_url)) { |
|
83 | - throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
|
84 | - } |
|
85 | - $this->return_url = $return_url; |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @return Collection |
|
92 | - * @throws InvalidInterfaceException |
|
93 | - * @throws InvalidDataTypeException |
|
94 | - * @throws DomainException |
|
95 | - */ |
|
96 | - protected function getPersistentAdminNoticeCollection() |
|
97 | - { |
|
98 | - if ( ! $this->notice_collection instanceof Collection) { |
|
99 | - $this->notice_collection = new Collection( |
|
100 | - '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
101 | - ); |
|
102 | - $this->retrieveStoredNotices(); |
|
103 | - $this->registerNotices(); |
|
104 | - } |
|
105 | - return $this->notice_collection; |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db |
|
112 | - * |
|
113 | - * @return void |
|
114 | - * @throws DomainException |
|
115 | - * @throws InvalidDataTypeException |
|
116 | - */ |
|
117 | - public function retrieveStoredNotices() |
|
118 | - { |
|
119 | - $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
120 | - // \EEH_Debug_Tools::printr($persistent_admin_notices, '$persistent_admin_notices', __FILE__, __LINE__); |
|
121 | - if ( ! empty($persistent_admin_notices)) { |
|
122 | - foreach ($persistent_admin_notices as $name => $details) { |
|
123 | - if (is_array($details)){ |
|
124 | - if ( |
|
125 | - ! isset( |
|
126 | - $details['message'], |
|
127 | - $details['capability'], |
|
128 | - $details['cap_context'], |
|
129 | - $details['dismissed'] |
|
130 | - ) |
|
131 | - ) { |
|
132 | - throw new DomainException( |
|
133 | - sprintf( |
|
134 | - esc_html__( |
|
135 | - 'The "%1$s" PersistentAdminNotice could not be retrieved from the database.', |
|
136 | - 'event_espresso' |
|
137 | - ), |
|
138 | - $name |
|
139 | - ) |
|
140 | - ); |
|
141 | - } |
|
142 | - // new format for nag notices |
|
143 | - new PersistentAdminNotice( |
|
144 | - $name, |
|
145 | - $details['message'], |
|
146 | - false, |
|
147 | - $details['capability'], |
|
148 | - $details['cap_context'], |
|
149 | - $details['dismissed'] |
|
150 | - ); |
|
151 | - } else { |
|
152 | - try { |
|
153 | - // old nag notices, that we want to convert to the new format |
|
154 | - new PersistentAdminNotice( |
|
155 | - $name, |
|
156 | - (string)$details, |
|
157 | - false, |
|
158 | - '', |
|
159 | - '', |
|
160 | - empty($details) |
|
161 | - ); |
|
162 | - } catch (\Exception $e) { |
|
163 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
164 | - } |
|
165 | - } |
|
166 | - // each notice will self register when the action hook in registerNotices is triggered |
|
167 | - } |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * exposes the Persistent Admin Notice Collection via an action |
|
175 | - * so that PersistentAdminNotice objects can be added and/or removed |
|
176 | - * without compromising the actual collection like a filter would |
|
177 | - */ |
|
178 | - public function registerNotices() |
|
179 | - { |
|
180 | - do_action( |
|
181 | - 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
182 | - $this->notice_collection |
|
183 | - ); |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * @throws DomainException |
|
190 | - * @throws InvalidClassException |
|
191 | - * @throws InvalidDataTypeException |
|
192 | - * @throws InvalidInterfaceException |
|
193 | - */ |
|
194 | - public function displayNotices() |
|
195 | - { |
|
196 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
197 | - if ($this->notice_collection->hasObjects()) { |
|
198 | - // and display notices |
|
199 | - foreach ($this->notice_collection as $persistent_admin_notice) { |
|
200 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
201 | - // don't display notices that have already been dismissed |
|
202 | - if ($persistent_admin_notice->getDismissed()) { |
|
203 | - continue; |
|
204 | - } |
|
205 | - try { |
|
206 | - $this->capabilities_checker->processCapCheck( |
|
207 | - $persistent_admin_notice->getCapCheck() |
|
208 | - ); |
|
209 | - } catch (InsufficientPermissionsException $e) { |
|
210 | - // user does not have required cap, so skip to next notice |
|
211 | - // and just eat the exception - nom nom nom nom |
|
212 | - continue; |
|
213 | - } |
|
214 | - $this->displayPersistentAdminNotice($persistent_admin_notice); |
|
215 | - } |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * does what it's named |
|
223 | - * |
|
224 | - * @return bool |
|
225 | - */ |
|
226 | - public function enqueueAssets() |
|
227 | - { |
|
228 | - static $print_scripts = true; |
|
229 | - if (! $print_scripts) { |
|
230 | - return $print_scripts; |
|
231 | - } |
|
232 | - wp_register_script( |
|
233 | - 'espresso_core', |
|
234 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
235 | - array('jquery'), |
|
236 | - EVENT_ESPRESSO_VERSION, |
|
237 | - true |
|
238 | - ); |
|
239 | - wp_register_script( |
|
240 | - 'ee_error_js', |
|
241 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
242 | - array('espresso_core'), |
|
243 | - EVENT_ESPRESSO_VERSION, |
|
244 | - true |
|
245 | - ); |
|
246 | - wp_enqueue_script('ee_error_js'); |
|
247 | - $print_scripts = true; |
|
248 | - return $print_scripts; |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * displayPersistentAdminNoticeHtml |
|
256 | - * |
|
257 | - * @param PersistentAdminNotice $persistent_admin_notice |
|
258 | - */ |
|
259 | - public function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice) |
|
260 | - { |
|
261 | - // used in template for printing css |
|
262 | - $print_styles = $this->enqueueAssets(); |
|
263 | - wp_localize_script( |
|
264 | - 'espresso_core', |
|
265 | - 'ee_dismiss', |
|
266 | - array( |
|
267 | - 'nag_notice' => $persistent_admin_notice->getName(), |
|
268 | - 'return_url' => urlencode($this->return_url), |
|
269 | - 'ajax_url' => WP_AJAX_URL, |
|
270 | - 'unknown_error' => esc_html__( |
|
271 | - 'An unknown error has occurred on the server while attempting to dismiss this notice.', |
|
272 | - 'event_espresso' |
|
273 | - ) |
|
274 | - ) |
|
275 | - ); |
|
276 | - // used in template |
|
277 | - $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
|
278 | - $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
|
279 | - require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php'; |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * dismissNotice |
|
286 | - * |
|
287 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
288 | - * @param bool $purge if true, then delete it from the db |
|
289 | - * @param bool $return forget all of this AJAX or redirect nonsense, and just return |
|
290 | - * @return void |
|
291 | - * @throws InvalidInterfaceException |
|
292 | - * @throws InvalidDataTypeException |
|
293 | - * @throws DomainException |
|
294 | - */ |
|
295 | - public function dismissNotice($pan_name = '', $purge = false, $return = false) |
|
296 | - { |
|
297 | - $pan_name = $this->request->get('ee_nag_notice', $pan_name); |
|
298 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
299 | - if ( ! empty($pan_name) && $this->notice_collection->has($pan_name)){ |
|
300 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
301 | - $persistent_admin_notice = $this->notice_collection->get($pan_name); |
|
302 | - $persistent_admin_notice->setDismissed(true); |
|
303 | - $persistent_admin_notice->setPurge($purge); |
|
304 | - $this->saveNotices(); |
|
305 | - } |
|
306 | - if ($return) { |
|
307 | - return; |
|
308 | - } else if ($this->request->ajax) { |
|
309 | - // grab any notices and concatenate into string |
|
310 | - echo wp_json_encode( |
|
311 | - array( |
|
312 | - 'errors' => implode('<br />', EE_Error::get_notices(false)) |
|
313 | - ) |
|
314 | - ); |
|
315 | - exit(); |
|
316 | - } else { |
|
317 | - // save errors to a transient to be displayed on next request (after redirect) |
|
318 | - EE_Error::get_notices(false, true); |
|
319 | - wp_safe_redirect( |
|
320 | - urldecode( |
|
321 | - $this->request->get('return_url', '') |
|
322 | - ) |
|
323 | - ); |
|
324 | - } |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * saveNotices |
|
331 | - * |
|
332 | - * @throws DomainException |
|
333 | - * @throws InvalidDataTypeException |
|
334 | - * @throws InvalidInterfaceException |
|
335 | - */ |
|
336 | - public function saveNotices() |
|
337 | - { |
|
338 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
339 | - if ($this->notice_collection->hasObjects()) { |
|
340 | - $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
341 | - //maybe initialize persistent_admin_notices |
|
342 | - if (empty($persistent_admin_notices)) { |
|
343 | - add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no'); |
|
344 | - } |
|
345 | - foreach ($this->notice_collection as $persistent_admin_notice) { |
|
346 | - // are we deleting this notice ? |
|
347 | - if ($persistent_admin_notice->getPurge()) { |
|
348 | - unset($persistent_admin_notices[$persistent_admin_notice->getName()]); |
|
349 | - } else { |
|
350 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
351 | - $persistent_admin_notices[$persistent_admin_notice->getName()] = array( |
|
352 | - 'message' => $persistent_admin_notice->getMessage(), |
|
353 | - 'capability' => $persistent_admin_notice->getCapability(), |
|
354 | - 'cap_context' => $persistent_admin_notice->getCapContext(), |
|
355 | - 'dismissed' => $persistent_admin_notice->getDismissed(), |
|
356 | - ); |
|
357 | - } |
|
358 | - } |
|
359 | - update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices); |
|
360 | - } |
|
361 | - } |
|
30 | + const WP_OPTION_KEY = 'ee_pers_admin_notices'; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var Collection|PersistentAdminNotice[] $notice_collection |
|
34 | + */ |
|
35 | + private $notice_collection; |
|
36 | + |
|
37 | + /** |
|
38 | + * @type string $return_url |
|
39 | + */ |
|
40 | + private $return_url; |
|
41 | + |
|
42 | + /** |
|
43 | + * @type CapabilitiesChecker $capabilities_checker |
|
44 | + */ |
|
45 | + private $capabilities_checker; |
|
46 | + |
|
47 | + /** |
|
48 | + * @type EE_Request $request |
|
49 | + */ |
|
50 | + private $request; |
|
51 | + |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * CapChecker constructor |
|
56 | + * |
|
57 | + * @param string $return_url |
|
58 | + * @param CapabilitiesChecker $capabilities_checker |
|
59 | + * @param EE_Request $request |
|
60 | + * @throws InvalidDataTypeException |
|
61 | + */ |
|
62 | + public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, EE_Request $request) |
|
63 | + { |
|
64 | + $this->setReturnUrl($return_url); |
|
65 | + $this->capabilities_checker = $capabilities_checker; |
|
66 | + $this->request = $request; |
|
67 | + //ok so we want to enable the entire admin |
|
68 | + add_action('admin_notices', array($this, 'displayNotices'), 9); |
|
69 | + add_action('network_admin_notices', array($this, 'displayNotices'), 9); |
|
70 | + add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice')); |
|
71 | + add_action('shutdown', array($this, 'saveNotices')); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @param string $return_url |
|
78 | + * @throws InvalidDataTypeException |
|
79 | + */ |
|
80 | + private function setReturnUrl($return_url) |
|
81 | + { |
|
82 | + if ( ! is_string($return_url)) { |
|
83 | + throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
|
84 | + } |
|
85 | + $this->return_url = $return_url; |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @return Collection |
|
92 | + * @throws InvalidInterfaceException |
|
93 | + * @throws InvalidDataTypeException |
|
94 | + * @throws DomainException |
|
95 | + */ |
|
96 | + protected function getPersistentAdminNoticeCollection() |
|
97 | + { |
|
98 | + if ( ! $this->notice_collection instanceof Collection) { |
|
99 | + $this->notice_collection = new Collection( |
|
100 | + '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
101 | + ); |
|
102 | + $this->retrieveStoredNotices(); |
|
103 | + $this->registerNotices(); |
|
104 | + } |
|
105 | + return $this->notice_collection; |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db |
|
112 | + * |
|
113 | + * @return void |
|
114 | + * @throws DomainException |
|
115 | + * @throws InvalidDataTypeException |
|
116 | + */ |
|
117 | + public function retrieveStoredNotices() |
|
118 | + { |
|
119 | + $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
120 | + // \EEH_Debug_Tools::printr($persistent_admin_notices, '$persistent_admin_notices', __FILE__, __LINE__); |
|
121 | + if ( ! empty($persistent_admin_notices)) { |
|
122 | + foreach ($persistent_admin_notices as $name => $details) { |
|
123 | + if (is_array($details)){ |
|
124 | + if ( |
|
125 | + ! isset( |
|
126 | + $details['message'], |
|
127 | + $details['capability'], |
|
128 | + $details['cap_context'], |
|
129 | + $details['dismissed'] |
|
130 | + ) |
|
131 | + ) { |
|
132 | + throw new DomainException( |
|
133 | + sprintf( |
|
134 | + esc_html__( |
|
135 | + 'The "%1$s" PersistentAdminNotice could not be retrieved from the database.', |
|
136 | + 'event_espresso' |
|
137 | + ), |
|
138 | + $name |
|
139 | + ) |
|
140 | + ); |
|
141 | + } |
|
142 | + // new format for nag notices |
|
143 | + new PersistentAdminNotice( |
|
144 | + $name, |
|
145 | + $details['message'], |
|
146 | + false, |
|
147 | + $details['capability'], |
|
148 | + $details['cap_context'], |
|
149 | + $details['dismissed'] |
|
150 | + ); |
|
151 | + } else { |
|
152 | + try { |
|
153 | + // old nag notices, that we want to convert to the new format |
|
154 | + new PersistentAdminNotice( |
|
155 | + $name, |
|
156 | + (string)$details, |
|
157 | + false, |
|
158 | + '', |
|
159 | + '', |
|
160 | + empty($details) |
|
161 | + ); |
|
162 | + } catch (\Exception $e) { |
|
163 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
164 | + } |
|
165 | + } |
|
166 | + // each notice will self register when the action hook in registerNotices is triggered |
|
167 | + } |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * exposes the Persistent Admin Notice Collection via an action |
|
175 | + * so that PersistentAdminNotice objects can be added and/or removed |
|
176 | + * without compromising the actual collection like a filter would |
|
177 | + */ |
|
178 | + public function registerNotices() |
|
179 | + { |
|
180 | + do_action( |
|
181 | + 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
182 | + $this->notice_collection |
|
183 | + ); |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * @throws DomainException |
|
190 | + * @throws InvalidClassException |
|
191 | + * @throws InvalidDataTypeException |
|
192 | + * @throws InvalidInterfaceException |
|
193 | + */ |
|
194 | + public function displayNotices() |
|
195 | + { |
|
196 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
197 | + if ($this->notice_collection->hasObjects()) { |
|
198 | + // and display notices |
|
199 | + foreach ($this->notice_collection as $persistent_admin_notice) { |
|
200 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
201 | + // don't display notices that have already been dismissed |
|
202 | + if ($persistent_admin_notice->getDismissed()) { |
|
203 | + continue; |
|
204 | + } |
|
205 | + try { |
|
206 | + $this->capabilities_checker->processCapCheck( |
|
207 | + $persistent_admin_notice->getCapCheck() |
|
208 | + ); |
|
209 | + } catch (InsufficientPermissionsException $e) { |
|
210 | + // user does not have required cap, so skip to next notice |
|
211 | + // and just eat the exception - nom nom nom nom |
|
212 | + continue; |
|
213 | + } |
|
214 | + $this->displayPersistentAdminNotice($persistent_admin_notice); |
|
215 | + } |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * does what it's named |
|
223 | + * |
|
224 | + * @return bool |
|
225 | + */ |
|
226 | + public function enqueueAssets() |
|
227 | + { |
|
228 | + static $print_scripts = true; |
|
229 | + if (! $print_scripts) { |
|
230 | + return $print_scripts; |
|
231 | + } |
|
232 | + wp_register_script( |
|
233 | + 'espresso_core', |
|
234 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
235 | + array('jquery'), |
|
236 | + EVENT_ESPRESSO_VERSION, |
|
237 | + true |
|
238 | + ); |
|
239 | + wp_register_script( |
|
240 | + 'ee_error_js', |
|
241 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
242 | + array('espresso_core'), |
|
243 | + EVENT_ESPRESSO_VERSION, |
|
244 | + true |
|
245 | + ); |
|
246 | + wp_enqueue_script('ee_error_js'); |
|
247 | + $print_scripts = true; |
|
248 | + return $print_scripts; |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * displayPersistentAdminNoticeHtml |
|
256 | + * |
|
257 | + * @param PersistentAdminNotice $persistent_admin_notice |
|
258 | + */ |
|
259 | + public function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice) |
|
260 | + { |
|
261 | + // used in template for printing css |
|
262 | + $print_styles = $this->enqueueAssets(); |
|
263 | + wp_localize_script( |
|
264 | + 'espresso_core', |
|
265 | + 'ee_dismiss', |
|
266 | + array( |
|
267 | + 'nag_notice' => $persistent_admin_notice->getName(), |
|
268 | + 'return_url' => urlencode($this->return_url), |
|
269 | + 'ajax_url' => WP_AJAX_URL, |
|
270 | + 'unknown_error' => esc_html__( |
|
271 | + 'An unknown error has occurred on the server while attempting to dismiss this notice.', |
|
272 | + 'event_espresso' |
|
273 | + ) |
|
274 | + ) |
|
275 | + ); |
|
276 | + // used in template |
|
277 | + $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
|
278 | + $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
|
279 | + require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php'; |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * dismissNotice |
|
286 | + * |
|
287 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
288 | + * @param bool $purge if true, then delete it from the db |
|
289 | + * @param bool $return forget all of this AJAX or redirect nonsense, and just return |
|
290 | + * @return void |
|
291 | + * @throws InvalidInterfaceException |
|
292 | + * @throws InvalidDataTypeException |
|
293 | + * @throws DomainException |
|
294 | + */ |
|
295 | + public function dismissNotice($pan_name = '', $purge = false, $return = false) |
|
296 | + { |
|
297 | + $pan_name = $this->request->get('ee_nag_notice', $pan_name); |
|
298 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
299 | + if ( ! empty($pan_name) && $this->notice_collection->has($pan_name)){ |
|
300 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
301 | + $persistent_admin_notice = $this->notice_collection->get($pan_name); |
|
302 | + $persistent_admin_notice->setDismissed(true); |
|
303 | + $persistent_admin_notice->setPurge($purge); |
|
304 | + $this->saveNotices(); |
|
305 | + } |
|
306 | + if ($return) { |
|
307 | + return; |
|
308 | + } else if ($this->request->ajax) { |
|
309 | + // grab any notices and concatenate into string |
|
310 | + echo wp_json_encode( |
|
311 | + array( |
|
312 | + 'errors' => implode('<br />', EE_Error::get_notices(false)) |
|
313 | + ) |
|
314 | + ); |
|
315 | + exit(); |
|
316 | + } else { |
|
317 | + // save errors to a transient to be displayed on next request (after redirect) |
|
318 | + EE_Error::get_notices(false, true); |
|
319 | + wp_safe_redirect( |
|
320 | + urldecode( |
|
321 | + $this->request->get('return_url', '') |
|
322 | + ) |
|
323 | + ); |
|
324 | + } |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * saveNotices |
|
331 | + * |
|
332 | + * @throws DomainException |
|
333 | + * @throws InvalidDataTypeException |
|
334 | + * @throws InvalidInterfaceException |
|
335 | + */ |
|
336 | + public function saveNotices() |
|
337 | + { |
|
338 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
339 | + if ($this->notice_collection->hasObjects()) { |
|
340 | + $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
341 | + //maybe initialize persistent_admin_notices |
|
342 | + if (empty($persistent_admin_notices)) { |
|
343 | + add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no'); |
|
344 | + } |
|
345 | + foreach ($this->notice_collection as $persistent_admin_notice) { |
|
346 | + // are we deleting this notice ? |
|
347 | + if ($persistent_admin_notice->getPurge()) { |
|
348 | + unset($persistent_admin_notices[$persistent_admin_notice->getName()]); |
|
349 | + } else { |
|
350 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
351 | + $persistent_admin_notices[$persistent_admin_notice->getName()] = array( |
|
352 | + 'message' => $persistent_admin_notice->getMessage(), |
|
353 | + 'capability' => $persistent_admin_notice->getCapability(), |
|
354 | + 'cap_context' => $persistent_admin_notice->getCapContext(), |
|
355 | + 'dismissed' => $persistent_admin_notice->getDismissed(), |
|
356 | + ); |
|
357 | + } |
|
358 | + } |
|
359 | + update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices); |
|
360 | + } |
|
361 | + } |
|
362 | 362 | |
363 | 363 | |
364 | 364 |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | // \EEH_Debug_Tools::printr($persistent_admin_notices, '$persistent_admin_notices', __FILE__, __LINE__); |
121 | 121 | if ( ! empty($persistent_admin_notices)) { |
122 | 122 | foreach ($persistent_admin_notices as $name => $details) { |
123 | - if (is_array($details)){ |
|
123 | + if (is_array($details)) { |
|
124 | 124 | if ( |
125 | 125 | ! isset( |
126 | 126 | $details['message'], |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | // old nag notices, that we want to convert to the new format |
154 | 154 | new PersistentAdminNotice( |
155 | 155 | $name, |
156 | - (string)$details, |
|
156 | + (string) $details, |
|
157 | 157 | false, |
158 | 158 | '', |
159 | 159 | '', |
@@ -226,19 +226,19 @@ discard block |
||
226 | 226 | public function enqueueAssets() |
227 | 227 | { |
228 | 228 | static $print_scripts = true; |
229 | - if (! $print_scripts) { |
|
229 | + if ( ! $print_scripts) { |
|
230 | 230 | return $print_scripts; |
231 | 231 | } |
232 | 232 | wp_register_script( |
233 | 233 | 'espresso_core', |
234 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
234 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
235 | 235 | array('jquery'), |
236 | 236 | EVENT_ESPRESSO_VERSION, |
237 | 237 | true |
238 | 238 | ); |
239 | 239 | wp_register_script( |
240 | 240 | 'ee_error_js', |
241 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
241 | + EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', |
|
242 | 242 | array('espresso_core'), |
243 | 243 | EVENT_ESPRESSO_VERSION, |
244 | 244 | true |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | // used in template |
277 | 277 | $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
278 | 278 | $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
279 | - require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php'; |
|
279 | + require EE_TEMPLATES.DS.'notifications'.DS.'persistent_admin_notice.template.php'; |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | { |
297 | 297 | $pan_name = $this->request->get('ee_nag_notice', $pan_name); |
298 | 298 | $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
299 | - if ( ! empty($pan_name) && $this->notice_collection->has($pan_name)){ |
|
299 | + if ( ! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
300 | 300 | /** @var PersistentAdminNotice $persistent_admin_notice */ |
301 | 301 | $persistent_admin_notice = $this->notice_collection->get($pan_name); |
302 | 302 | $persistent_admin_notice->setDismissed(true); |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\exceptions\InvalidDataTypeException; |
2 | 2 | |
3 | 3 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('No direct script access allowed'); |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | |
@@ -20,153 +20,153 @@ discard block |
||
20 | 20 | { |
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * converts a Request to a Response |
|
25 | - * |
|
26 | - * @param EE_Request $request |
|
27 | - * @param EE_Response $response |
|
28 | - * @return EE_Response |
|
29 | - */ |
|
30 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
31 | - { |
|
32 | - $this->_request = $request; |
|
33 | - $this->_response = $response; |
|
34 | - //$this->_response->add_output( "\n\t IN >> " . __CLASS__ ); |
|
35 | - //$this->_response->set_notice( 1, 'hey look at this' ); |
|
36 | - // check required WP version |
|
37 | - if ( ! $this->_minimum_wp_version_required()) { |
|
38 | - $this->_request->un_set('activate', true); |
|
39 | - add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1); |
|
40 | - //$this->_response->add_output( "\n<br />" . 'minimum_wp_version_error' ); |
|
41 | - $this->_response->terminate_request(); |
|
42 | - $this->_response->deactivate_plugin(); |
|
43 | - } |
|
44 | - // check recommended PHP version |
|
45 | - if ( ! $this->_minimum_php_version_recommended()) { |
|
46 | - $this->_display_minimum_recommended_php_version_notice(); |
|
47 | - } |
|
48 | - $this->_response = $this->process_request_stack($this->_request, $this->_response); |
|
49 | - //$this->_response->add_output( "\n\t OUT << " . __CLASS__ ); |
|
50 | - return $this->_response; |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * Helper method to assess installed wp version against given values. |
|
56 | - * By default this compares the required minimum version of WP for EE against the installed version of WP |
|
57 | - * |
|
58 | - * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked against) |
|
59 | - * so consider that when sending in your values. |
|
60 | - * |
|
61 | - * @param string $version_to_check |
|
62 | - * @param string $operator |
|
63 | - * @return bool |
|
64 | - */ |
|
65 | - public static function check_wp_version($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
66 | - { |
|
67 | - global $wp_version; |
|
68 | - return version_compare( |
|
69 | - //first account for wp_version being pre-release (like RC, beta etc which are usually in the format like |
|
70 | - //4.7-RC3-39519 |
|
71 | - strpos($wp_version, '-') > 0 ? substr($wp_version, 0, strpos($wp_version, '-')) : $wp_version, |
|
72 | - $version_to_check, |
|
73 | - $operator |
|
74 | - ); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * _minimum_wp_version_required |
|
81 | - * |
|
82 | - * @access private |
|
83 | - * @return boolean |
|
84 | - */ |
|
85 | - private function _minimum_wp_version_required() |
|
86 | - { |
|
87 | - return self::check_wp_version(); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * _check_php_version |
|
94 | - * |
|
95 | - * @access private |
|
96 | - * @param string $min_version |
|
97 | - * @return boolean |
|
98 | - */ |
|
99 | - private function _check_php_version($min_version = EE_MIN_PHP_VER_RECOMMENDED) |
|
100 | - { |
|
101 | - return version_compare(PHP_VERSION, $min_version, '>=') ? true : false; |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * _minimum_php_version_recommended |
|
108 | - * |
|
109 | - * @access private |
|
110 | - * @return boolean |
|
111 | - */ |
|
112 | - private function _minimum_php_version_recommended() |
|
113 | - { |
|
114 | - return $this->_check_php_version(EE_MIN_PHP_VER_RECOMMENDED); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * minimum_wp_version_error |
|
121 | - * |
|
122 | - * @return void |
|
123 | - */ |
|
124 | - public function minimum_wp_version_error() |
|
125 | - { |
|
126 | - global $wp_version; |
|
127 | - ?> |
|
23 | + /** |
|
24 | + * converts a Request to a Response |
|
25 | + * |
|
26 | + * @param EE_Request $request |
|
27 | + * @param EE_Response $response |
|
28 | + * @return EE_Response |
|
29 | + */ |
|
30 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
31 | + { |
|
32 | + $this->_request = $request; |
|
33 | + $this->_response = $response; |
|
34 | + //$this->_response->add_output( "\n\t IN >> " . __CLASS__ ); |
|
35 | + //$this->_response->set_notice( 1, 'hey look at this' ); |
|
36 | + // check required WP version |
|
37 | + if ( ! $this->_minimum_wp_version_required()) { |
|
38 | + $this->_request->un_set('activate', true); |
|
39 | + add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1); |
|
40 | + //$this->_response->add_output( "\n<br />" . 'minimum_wp_version_error' ); |
|
41 | + $this->_response->terminate_request(); |
|
42 | + $this->_response->deactivate_plugin(); |
|
43 | + } |
|
44 | + // check recommended PHP version |
|
45 | + if ( ! $this->_minimum_php_version_recommended()) { |
|
46 | + $this->_display_minimum_recommended_php_version_notice(); |
|
47 | + } |
|
48 | + $this->_response = $this->process_request_stack($this->_request, $this->_response); |
|
49 | + //$this->_response->add_output( "\n\t OUT << " . __CLASS__ ); |
|
50 | + return $this->_response; |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * Helper method to assess installed wp version against given values. |
|
56 | + * By default this compares the required minimum version of WP for EE against the installed version of WP |
|
57 | + * |
|
58 | + * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked against) |
|
59 | + * so consider that when sending in your values. |
|
60 | + * |
|
61 | + * @param string $version_to_check |
|
62 | + * @param string $operator |
|
63 | + * @return bool |
|
64 | + */ |
|
65 | + public static function check_wp_version($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
66 | + { |
|
67 | + global $wp_version; |
|
68 | + return version_compare( |
|
69 | + //first account for wp_version being pre-release (like RC, beta etc which are usually in the format like |
|
70 | + //4.7-RC3-39519 |
|
71 | + strpos($wp_version, '-') > 0 ? substr($wp_version, 0, strpos($wp_version, '-')) : $wp_version, |
|
72 | + $version_to_check, |
|
73 | + $operator |
|
74 | + ); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * _minimum_wp_version_required |
|
81 | + * |
|
82 | + * @access private |
|
83 | + * @return boolean |
|
84 | + */ |
|
85 | + private function _minimum_wp_version_required() |
|
86 | + { |
|
87 | + return self::check_wp_version(); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * _check_php_version |
|
94 | + * |
|
95 | + * @access private |
|
96 | + * @param string $min_version |
|
97 | + * @return boolean |
|
98 | + */ |
|
99 | + private function _check_php_version($min_version = EE_MIN_PHP_VER_RECOMMENDED) |
|
100 | + { |
|
101 | + return version_compare(PHP_VERSION, $min_version, '>=') ? true : false; |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * _minimum_php_version_recommended |
|
108 | + * |
|
109 | + * @access private |
|
110 | + * @return boolean |
|
111 | + */ |
|
112 | + private function _minimum_php_version_recommended() |
|
113 | + { |
|
114 | + return $this->_check_php_version(EE_MIN_PHP_VER_RECOMMENDED); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * minimum_wp_version_error |
|
121 | + * |
|
122 | + * @return void |
|
123 | + */ |
|
124 | + public function minimum_wp_version_error() |
|
125 | + { |
|
126 | + global $wp_version; |
|
127 | + ?> |
|
128 | 128 | <div class="error"> |
129 | 129 | <p> |
130 | 130 | <?php |
131 | - printf( |
|
132 | - __('We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', |
|
133 | - 'event_espresso'), |
|
134 | - EE_MIN_WP_VER_REQUIRED, |
|
135 | - $wp_version, |
|
136 | - '<br/>', |
|
137 | - '<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>' |
|
138 | - ); |
|
139 | - ?> |
|
131 | + printf( |
|
132 | + __('We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', |
|
133 | + 'event_espresso'), |
|
134 | + EE_MIN_WP_VER_REQUIRED, |
|
135 | + $wp_version, |
|
136 | + '<br/>', |
|
137 | + '<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>' |
|
138 | + ); |
|
139 | + ?> |
|
140 | 140 | </p> |
141 | 141 | </div> |
142 | 142 | <?php |
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * _display_minimum_recommended_php_version_notice |
|
149 | - * |
|
150 | - * @access private |
|
151 | - * @return void |
|
152 | - * @throws InvalidDataTypeException |
|
153 | - */ |
|
154 | - private function _display_minimum_recommended_php_version_notice() |
|
155 | - { |
|
156 | - new \EventEspresso\core\domain\entities\notifications\PersistentAdminNotice( |
|
157 | - 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
158 | - sprintf( |
|
159 | - __( |
|
160 | - 'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
161 | - 'event_espresso' |
|
162 | - ), |
|
163 | - EE_MIN_PHP_VER_RECOMMENDED, |
|
164 | - PHP_VERSION, |
|
165 | - '<br/>', |
|
166 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
167 | - ) |
|
168 | - ); |
|
169 | - } |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * _display_minimum_recommended_php_version_notice |
|
149 | + * |
|
150 | + * @access private |
|
151 | + * @return void |
|
152 | + * @throws InvalidDataTypeException |
|
153 | + */ |
|
154 | + private function _display_minimum_recommended_php_version_notice() |
|
155 | + { |
|
156 | + new \EventEspresso\core\domain\entities\notifications\PersistentAdminNotice( |
|
157 | + 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
158 | + sprintf( |
|
159 | + __( |
|
160 | + 'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
161 | + 'event_espresso' |
|
162 | + ), |
|
163 | + EE_MIN_PHP_VER_RECOMMENDED, |
|
164 | + PHP_VERSION, |
|
165 | + '<br/>', |
|
166 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
167 | + ) |
|
168 | + ); |
|
169 | + } |
|
170 | 170 | |
171 | 171 | |
172 | 172 | } |
@@ -154,7 +154,7 @@ |
||
154 | 154 | private function _display_minimum_recommended_php_version_notice() |
155 | 155 | { |
156 | 156 | new \EventEspresso\core\domain\entities\notifications\PersistentAdminNotice( |
157 | - 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
157 | + 'php_version_'.str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED).'_recommended', |
|
158 | 158 | sprintf( |
159 | 159 | __( |
160 | 160 | 'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
@@ -294,15 +294,15 @@ discard block |
||
294 | 294 | |
295 | 295 | |
296 | 296 | |
297 | - /** |
|
298 | - * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
299 | - * but also verifies the payment method type of each is a usable object. If not, |
|
300 | - * deactivate it, sets a notification, and deactivates it |
|
301 | - * |
|
302 | - * @param array $rows |
|
303 | - * @return EE_Payment_Method[] |
|
304 | - * @throws InvalidDataTypeException |
|
305 | - */ |
|
297 | + /** |
|
298 | + * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
299 | + * but also verifies the payment method type of each is a usable object. If not, |
|
300 | + * deactivate it, sets a notification, and deactivates it |
|
301 | + * |
|
302 | + * @param array $rows |
|
303 | + * @return EE_Payment_Method[] |
|
304 | + * @throws InvalidDataTypeException |
|
305 | + */ |
|
306 | 306 | protected function _create_objects( $rows = array() ) { |
307 | 307 | EE_Registry::instance()->load_lib( 'Payment_Method_Manager' ); |
308 | 308 | $payment_methods = parent::_create_objects( $rows ); |
@@ -319,20 +319,20 @@ discard block |
||
319 | 319 | //only deactivate and notify the admin if the payment is active somewhere |
320 | 320 | $payment_method->deactivate(); |
321 | 321 | $payment_method->save(); |
322 | - new PersistentAdminNotice( |
|
323 | - 'auto-deactivated-' . $payment_method->type(), |
|
324 | - sprintf( |
|
325 | - __('The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
326 | - 'event_espresso'), |
|
327 | - $payment_method->admin_name(), |
|
328 | - '<br />', |
|
329 | - '<a href="' . admin_url('plugins.php') . '">', |
|
330 | - '</a>' |
|
331 | - ), |
|
332 | - true, |
|
333 | - '', |
|
334 | - '' |
|
335 | - ); |
|
322 | + new PersistentAdminNotice( |
|
323 | + 'auto-deactivated-' . $payment_method->type(), |
|
324 | + sprintf( |
|
325 | + __('The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
326 | + 'event_espresso'), |
|
327 | + $payment_method->admin_name(), |
|
328 | + '<br />', |
|
329 | + '<a href="' . admin_url('plugins.php') . '">', |
|
330 | + '</a>' |
|
331 | + ), |
|
332 | + true, |
|
333 | + '', |
|
334 | + '' |
|
335 | + ); |
|
336 | 336 | } |
337 | 337 | } |
338 | 338 | return $usable_payment_methods; |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\domain\entities\notifications\PersistentAdminNotice; |
2 | 2 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
3 | 3 | |
4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
5 | - exit( 'No direct script access allowed' ); |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | /** |
8 | 8 | * |
@@ -40,33 +40,33 @@ discard block |
||
40 | 40 | * @access protected |
41 | 41 | * @return EEM_Payment_Method |
42 | 42 | */ |
43 | - protected function __construct( $timezone = NULL ) { |
|
44 | - $this->singlular_item = __( 'Payment Method', 'event_espresso' ); |
|
45 | - $this->plural_item = __( 'Payment Methods', 'event_espresso' ); |
|
46 | - $this->_tables = array( 'Payment_Method' => new EE_Primary_Table( 'esp_payment_method', 'PMD_ID' ) ); |
|
43 | + protected function __construct($timezone = NULL) { |
|
44 | + $this->singlular_item = __('Payment Method', 'event_espresso'); |
|
45 | + $this->plural_item = __('Payment Methods', 'event_espresso'); |
|
46 | + $this->_tables = array('Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID')); |
|
47 | 47 | $this->_fields = array( |
48 | 48 | 'Payment_Method' => array( |
49 | - 'PMD_ID' => new EE_Primary_Key_Int_Field( 'PMD_ID', __( "ID", 'event_espresso' ) ), |
|
50 | - 'PMD_type' => new EE_Plain_Text_Field( 'PMD_type', __( "Payment Method Type", 'event_espresso' ), FALSE, 'Admin_Only' ), |
|
51 | - 'PMD_name' => new EE_Plain_Text_Field( 'PMD_name', __( "Name", 'event_espresso' ), FALSE ), |
|
52 | - 'PMD_desc' => new EE_Post_Content_Field( 'PMD_desc', __( "Description", 'event_espresso' ), FALSE, '' ), |
|
53 | - 'PMD_admin_name' => new EE_Plain_Text_Field( 'PMD_admin_name', __( "Admin-Only Name", 'event_espresso' ), TRUE ), |
|
54 | - 'PMD_admin_desc' => new EE_Post_Content_Field( 'PMD_admin_desc', __( "Admin-Only Description", 'event_espresso' ), TRUE ), |
|
55 | - 'PMD_slug' => new EE_Slug_Field( 'PMD_slug', __( "Slug", 'event_espresso' ), FALSE ), |
|
56 | - 'PMD_order' => new EE_Integer_Field( 'PMD_order', __( "Order", 'event_espresso' ), FALSE, 0 ), |
|
57 | - 'PMD_debug_mode' => new EE_Boolean_Field( 'PMD_debug_mode', __( "Debug Mode On?", 'event_espresso' ), FALSE, FALSE ), |
|
58 | - 'PMD_wp_user' => new EE_WP_User_Field( 'PMD_wp_user', __( "Payment Method Creator ID", 'event_espresso' ), FALSE ), |
|
59 | - 'PMD_open_by_default' => new EE_Boolean_Field( 'PMD_open_by_default', __( "Open by Default?", 'event_espresso' ), FALSE, FALSE ), 'PMD_button_url' => new EE_Plain_Text_Field( 'PMD_button_url', __( "Button URL", 'event_espresso' ), TRUE, '' ), |
|
60 | - 'PMD_scope' => new EE_Serialized_Text_Field( 'PMD_scope', __( "Usable From?", 'event_espresso' ), FALSE, array() ), //possible values currently are 'CART','ADMIN','API' |
|
49 | + 'PMD_ID' => new EE_Primary_Key_Int_Field('PMD_ID', __("ID", 'event_espresso')), |
|
50 | + 'PMD_type' => new EE_Plain_Text_Field('PMD_type', __("Payment Method Type", 'event_espresso'), FALSE, 'Admin_Only'), |
|
51 | + 'PMD_name' => new EE_Plain_Text_Field('PMD_name', __("Name", 'event_espresso'), FALSE), |
|
52 | + 'PMD_desc' => new EE_Post_Content_Field('PMD_desc', __("Description", 'event_espresso'), FALSE, ''), |
|
53 | + 'PMD_admin_name' => new EE_Plain_Text_Field('PMD_admin_name', __("Admin-Only Name", 'event_espresso'), TRUE), |
|
54 | + 'PMD_admin_desc' => new EE_Post_Content_Field('PMD_admin_desc', __("Admin-Only Description", 'event_espresso'), TRUE), |
|
55 | + 'PMD_slug' => new EE_Slug_Field('PMD_slug', __("Slug", 'event_espresso'), FALSE), |
|
56 | + 'PMD_order' => new EE_Integer_Field('PMD_order', __("Order", 'event_espresso'), FALSE, 0), |
|
57 | + 'PMD_debug_mode' => new EE_Boolean_Field('PMD_debug_mode', __("Debug Mode On?", 'event_espresso'), FALSE, FALSE), |
|
58 | + 'PMD_wp_user' => new EE_WP_User_Field('PMD_wp_user', __("Payment Method Creator ID", 'event_espresso'), FALSE), |
|
59 | + 'PMD_open_by_default' => new EE_Boolean_Field('PMD_open_by_default', __("Open by Default?", 'event_espresso'), FALSE, FALSE), 'PMD_button_url' => new EE_Plain_Text_Field('PMD_button_url', __("Button URL", 'event_espresso'), TRUE, ''), |
|
60 | + 'PMD_scope' => new EE_Serialized_Text_Field('PMD_scope', __("Usable From?", 'event_espresso'), FALSE, array()), //possible values currently are 'CART','ADMIN','API' |
|
61 | 61 | ) ); |
62 | 62 | $this->_model_relations = array( |
63 | 63 | // 'Event'=>new EE_HABTM_Relation('Event_Payment_Method'), |
64 | 64 | 'Payment' => new EE_Has_Many_Relation(), |
65 | - 'Currency' => new EE_HABTM_Relation( 'Currency_Payment_Method' ), |
|
65 | + 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
66 | 66 | 'Transaction' => new EE_Has_Many_Relation(), |
67 | 67 | 'WP_User' => new EE_Belongs_To_Relation(), |
68 | 68 | ); |
69 | - parent::__construct( $timezone ); |
|
69 | + parent::__construct($timezone); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * @param string $slug |
77 | 77 | * @return EE_Payment_Method |
78 | 78 | */ |
79 | - public function get_one_by_slug( $slug ) { |
|
80 | - return $this->get_one( array( array( 'PMD_slug' => $slug ) ) ); |
|
79 | + public function get_one_by_slug($slug) { |
|
80 | + return $this->get_one(array(array('PMD_slug' => $slug))); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | return apply_filters( |
92 | 92 | 'FHEE__EEM_Payment_Method__scopes', |
93 | 93 | array( |
94 | - self::scope_cart => __( "Front-end Registration Page", 'event_espresso' ), |
|
95 | - self::scope_admin => __( "Admin Registration Page (no online processing)", 'event_espresso' ) |
|
94 | + self::scope_cart => __("Front-end Registration Page", 'event_espresso'), |
|
95 | + self::scope_admin => __("Admin Registration Page (no online processing)", 'event_espresso') |
|
96 | 96 | ) |
97 | 97 | ); |
98 | 98 | } |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
105 | 105 | * @return boolean |
106 | 106 | */ |
107 | - public function is_valid_scope( $scope ) { |
|
107 | + public function is_valid_scope($scope) { |
|
108 | 108 | $scopes = $this->scopes(); |
109 | - if ( isset( $scopes[ $scope ] ) ) { |
|
109 | + if (isset($scopes[$scope])) { |
|
110 | 110 | return TRUE; |
111 | 111 | } else { |
112 | 112 | return FALSE; |
@@ -122,11 +122,11 @@ discard block |
||
122 | 122 | * @throws EE_Error |
123 | 123 | * @return EE_Payment_Method[] |
124 | 124 | */ |
125 | - public function get_all_active( $scope = NULL, $query_params = array() ) { |
|
126 | - if( ! isset( $query_params[ 'order_by' ] ) && ! isset( $query_params[ 'order' ] ) ) { |
|
127 | - $query_params = array( 'order_by' => array( 'PMD_order' => 'ASC', 'PMD_ID' => 'ASC' ) ); |
|
125 | + public function get_all_active($scope = NULL, $query_params = array()) { |
|
126 | + if ( ! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
127 | + $query_params = array('order_by' => array('PMD_order' => 'ASC', 'PMD_ID' => 'ASC')); |
|
128 | 128 | } |
129 | - return $this->get_all( $this->_get_query_params_for_all_active( $scope, $query_params ) ); |
|
129 | + return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | * @param array $query_params |
136 | 136 | * @return int |
137 | 137 | */ |
138 | - public function count_active( $scope = NULL, $query_params = array() ){ |
|
139 | - return $this->count( $this->_get_query_params_for_all_active( $scope, $query_params ) ); |
|
138 | + public function count_active($scope = NULL, $query_params = array()) { |
|
139 | + return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -147,21 +147,21 @@ discard block |
||
147 | 147 | * @return array like param of EEM_Base::get_all() |
148 | 148 | * @throws EE_Error |
149 | 149 | */ |
150 | - protected function _get_query_params_for_all_active( $scope = NULL, $query_params = array() ){ |
|
151 | - if ( $scope ) { |
|
152 | - if ( $this->is_valid_scope( $scope ) ) { |
|
153 | - return array_replace_recursive( array( array( 'PMD_scope' => array( 'LIKE', "%$scope%" ) ) ), $query_params ); |
|
150 | + protected function _get_query_params_for_all_active($scope = NULL, $query_params = array()) { |
|
151 | + if ($scope) { |
|
152 | + if ($this->is_valid_scope($scope)) { |
|
153 | + return array_replace_recursive(array(array('PMD_scope' => array('LIKE', "%$scope%"))), $query_params); |
|
154 | 154 | } else { |
155 | - throw new EE_Error( sprintf( __( "'%s' is not a valid scope for a payment method", "event_espresso" ), $scope ) ); |
|
155 | + throw new EE_Error(sprintf(__("'%s' is not a valid scope for a payment method", "event_espresso"), $scope)); |
|
156 | 156 | } |
157 | 157 | } else { |
158 | 158 | $acceptable_scopes = array(); |
159 | 159 | $count = 0; |
160 | - foreach ( $this->scopes() as $scope_name => $desc ) { |
|
160 | + foreach ($this->scopes() as $scope_name => $desc) { |
|
161 | 161 | $count++; |
162 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = array( 'LIKE', '%' . $scope_name . '%' ); |
|
162 | + $acceptable_scopes['PMD_scope*'.$count] = array('LIKE', '%'.$scope_name.'%'); |
|
163 | 163 | } |
164 | - return array_replace_recursive( array( array( 'OR*active_scope' => $acceptable_scopes ) ), $query_params ); |
|
164 | + return array_replace_recursive(array(array('OR*active_scope' => $acceptable_scopes)), $query_params); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | * @return array like param of EEM_Base::get_all() |
174 | 174 | * @throws EE_Error |
175 | 175 | */ |
176 | - public function get_query_params_for_all_active( $scope = NULL, $query_params = array() ) { |
|
177 | - return $this->_get_query_params_for_all_active( $scope, $query_params ); |
|
176 | + public function get_query_params_for_all_active($scope = NULL, $query_params = array()) { |
|
177 | + return $this->_get_query_params_for_all_active($scope, $query_params); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | * @param array $query_params |
185 | 185 | * @return EE_Payment_Method |
186 | 186 | */ |
187 | - public function get_one_active( $scope = NULL, $query_params = array() ) { |
|
188 | - return $this->get_one( $this->_get_query_params_for_all_active( $scope, $query_params ) ); |
|
187 | + public function get_one_active($scope = NULL, $query_params = array()) { |
|
188 | + return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | |
@@ -195,8 +195,8 @@ discard block |
||
195 | 195 | * @param string $type |
196 | 196 | * @return EE_Payment_Method |
197 | 197 | */ |
198 | - public function get_one_of_type( $type ) { |
|
199 | - return $this->get_one( array( array( 'PMD_type' => $type ) ) ); |
|
198 | + public function get_one_of_type($type) { |
|
199 | + return $this->get_one(array(array('PMD_type' => $type))); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | |
@@ -209,22 +209,22 @@ discard block |
||
209 | 209 | * @return EE_Payment_Method |
210 | 210 | * @throws EE_Error |
211 | 211 | */ |
212 | - public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ) { |
|
212 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) { |
|
213 | 213 | //first: check if it's a slug |
214 | - if( is_string( $base_class_obj_or_id ) ) { |
|
215 | - $obj = $this->get_one_by_slug( $base_class_obj_or_id ); |
|
216 | - if( $obj ) { |
|
214 | + if (is_string($base_class_obj_or_id)) { |
|
215 | + $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
216 | + if ($obj) { |
|
217 | 217 | return $obj; |
218 | 218 | } |
219 | 219 | } |
220 | 220 | //ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
221 | 221 | try { |
222 | - return parent::ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db ); |
|
222 | + return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
223 | 223 | } |
224 | - catch ( EE_Error $e ) { |
|
224 | + catch (EE_Error $e) { |
|
225 | 225 | //handle it outside the catch |
226 | 226 | } |
227 | - throw new EE_Error( sprintf( __( "'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso" ), $base_class_obj_or_id ) ); |
|
227 | + throw new EE_Error(sprintf(__("'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso"), $base_class_obj_or_id)); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | |
@@ -235,12 +235,12 @@ discard block |
||
235 | 235 | * @param mixed $base_obj_or_id_or_slug |
236 | 236 | * @return int |
237 | 237 | */ |
238 | - function ensure_is_ID( $base_obj_or_id_or_slug ) { |
|
239 | - if ( is_string( $base_obj_or_id_or_slug ) ) { |
|
238 | + function ensure_is_ID($base_obj_or_id_or_slug) { |
|
239 | + if (is_string($base_obj_or_id_or_slug)) { |
|
240 | 240 | //assume it's a slug |
241 | - $base_obj_or_id_or_slug = $this->get_one_by_slug( $base_obj_or_id_or_slug ); |
|
241 | + $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
242 | 242 | } |
243 | - return parent::ensure_is_ID( $base_obj_or_id_or_slug ); |
|
243 | + return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | |
@@ -249,36 +249,36 @@ discard block |
||
249 | 249 | * Verifies the button urls on all the passed payment methods have a valid button url. If not, resets them to their default. |
250 | 250 | * @param EE_Payment_Method[] $payment_methods. If NULL is provided defaults to all payment methods active in the cart |
251 | 251 | */ |
252 | - function verify_button_urls( $payment_methods = NULL ) { |
|
253 | - $payment_methods = is_array( $payment_methods ) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
254 | - foreach ( $payment_methods as $payment_method ) { |
|
252 | + function verify_button_urls($payment_methods = NULL) { |
|
253 | + $payment_methods = is_array($payment_methods) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
254 | + foreach ($payment_methods as $payment_method) { |
|
255 | 255 | try { |
256 | 256 | $current_button_url = $payment_method->button_url(); |
257 | - $buttons_urls_to_try = apply_filters( 'FHEE__EEM_Payment_Method__verify_button_urls__button_urls_to_try', array( |
|
258 | - 'current_ssl' => str_replace( "http://", "https://", $current_button_url ), |
|
259 | - 'current' => str_replace( "https://", "http://", $current_button_url ), |
|
260 | - 'default_ssl' => str_replace( "http://", "https://", $payment_method->type_obj()->default_button_url() ), |
|
261 | - 'default' => str_replace( "https://", "http://", $payment_method->type_obj()->default_button_url() ), |
|
262 | - ) ); |
|
263 | - foreach( $buttons_urls_to_try as $button_url_to_try ) { |
|
264 | - if( |
|
257 | + $buttons_urls_to_try = apply_filters('FHEE__EEM_Payment_Method__verify_button_urls__button_urls_to_try', array( |
|
258 | + 'current_ssl' => str_replace("http://", "https://", $current_button_url), |
|
259 | + 'current' => str_replace("https://", "http://", $current_button_url), |
|
260 | + 'default_ssl' => str_replace("http://", "https://", $payment_method->type_obj()->default_button_url()), |
|
261 | + 'default' => str_replace("https://", "http://", $payment_method->type_obj()->default_button_url()), |
|
262 | + )); |
|
263 | + foreach ($buttons_urls_to_try as $button_url_to_try) { |
|
264 | + if ( |
|
265 | 265 | (//this is the current url and it exists, regardless of SSL issues |
266 | 266 | $button_url_to_try == $current_button_url && |
267 | 267 | EEH_URL::remote_file_exists( |
268 | 268 | $button_url_to_try, |
269 | 269 | array( |
270 | 270 | 'sslverify' => false, |
271 | - 'limit_response_size' => 4095,//we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
271 | + 'limit_response_size' => 4095, //we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
272 | 272 | ) ) |
273 | 273 | ) |
274 | 274 | || |
275 | 275 | (//this is NOT the current url and it exists with a working SSL cert |
276 | 276 | $button_url_to_try != $current_button_url && |
277 | - EEH_URL::remote_file_exists( $button_url_to_try ) |
|
277 | + EEH_URL::remote_file_exists($button_url_to_try) |
|
278 | 278 | ) ) { |
279 | - if( $current_button_url != $button_url_to_try ){ |
|
280 | - $payment_method->save( array( 'PMD_button_url' => $button_url_to_try ) ); |
|
281 | - EE_Error::add_attention( sprintf( __( "Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso" ), $payment_method->name(), $button_url_to_try ) ); |
|
279 | + if ($current_button_url != $button_url_to_try) { |
|
280 | + $payment_method->save(array('PMD_button_url' => $button_url_to_try)); |
|
281 | + EE_Error::add_attention(sprintf(__("Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso"), $payment_method->name(), $button_url_to_try)); |
|
282 | 282 | } |
283 | 283 | //this image exists. So if wasn't set before, now it is; |
284 | 284 | //or if it was already set, we have nothing to do |
@@ -286,8 +286,8 @@ discard block |
||
286 | 286 | } |
287 | 287 | } |
288 | 288 | } |
289 | - catch ( EE_Error $e ) { |
|
290 | - $payment_method->set_active( FALSE ); |
|
289 | + catch (EE_Error $e) { |
|
290 | + $payment_method->set_active(FALSE); |
|
291 | 291 | } |
292 | 292 | } |
293 | 293 | } |
@@ -303,30 +303,30 @@ discard block |
||
303 | 303 | * @return EE_Payment_Method[] |
304 | 304 | * @throws InvalidDataTypeException |
305 | 305 | */ |
306 | - protected function _create_objects( $rows = array() ) { |
|
307 | - EE_Registry::instance()->load_lib( 'Payment_Method_Manager' ); |
|
308 | - $payment_methods = parent::_create_objects( $rows ); |
|
306 | + protected function _create_objects($rows = array()) { |
|
307 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
308 | + $payment_methods = parent::_create_objects($rows); |
|
309 | 309 | /* @var $payment_methods EE_Payment_Method[] */ |
310 | 310 | $usable_payment_methods = array(); |
311 | - foreach ( $payment_methods as $key => $payment_method ) { |
|
312 | - if ( EE_Payment_Method_Manager::instance()->payment_method_type_exists( $payment_method->type() ) ) { |
|
313 | - $usable_payment_methods[ $key ] = $payment_method; |
|
311 | + foreach ($payment_methods as $key => $payment_method) { |
|
312 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
313 | + $usable_payment_methods[$key] = $payment_method; |
|
314 | 314 | //some payment methods enqueue their scripts in EE_PMT_*::__construct |
315 | 315 | //which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
316 | 316 | //its scripts). but for backwards-compat we should continue to do that |
317 | 317 | $payment_method->type_obj(); |
318 | - } elseif( $payment_method->active() ) { |
|
318 | + } elseif ($payment_method->active()) { |
|
319 | 319 | //only deactivate and notify the admin if the payment is active somewhere |
320 | 320 | $payment_method->deactivate(); |
321 | 321 | $payment_method->save(); |
322 | 322 | new PersistentAdminNotice( |
323 | - 'auto-deactivated-' . $payment_method->type(), |
|
323 | + 'auto-deactivated-'.$payment_method->type(), |
|
324 | 324 | sprintf( |
325 | 325 | __('The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
326 | 326 | 'event_espresso'), |
327 | 327 | $payment_method->admin_name(), |
328 | 328 | '<br />', |
329 | - '<a href="' . admin_url('plugins.php') . '">', |
|
329 | + '<a href="'.admin_url('plugins.php').'">', |
|
330 | 330 | '</a>' |
331 | 331 | ), |
332 | 332 | true, |
@@ -348,16 +348,16 @@ discard block |
||
348 | 348 | * @param string $scope @see EEM_Payment_Method::get_all_for_events |
349 | 349 | * @return EE_Payment_Method[] |
350 | 350 | */ |
351 | - public function get_all_for_transaction( $transaction, $scope ) { |
|
351 | + public function get_all_for_transaction($transaction, $scope) { |
|
352 | 352 | //@todo take relations between events and payment methods into account, once that relation exists |
353 | - if ( $transaction instanceof EE_Transaction ) { |
|
353 | + if ($transaction instanceof EE_Transaction) { |
|
354 | 354 | //@todo take the relation between transaction and currencies into account |
355 | 355 | } |
356 | - $currencies_for_events = array( EE_Config::instance()->currency->code ); |
|
356 | + $currencies_for_events = array(EE_Config::instance()->currency->code); |
|
357 | 357 | //give addons a chance to override what payment methods are chosen based on the transaction |
358 | 358 | return apply_filters( |
359 | 359 | 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
360 | - $this->get_all_active( $scope, array( array( 'Currency.CUR_code' => array( 'IN', $currencies_for_events ) ) ) ), |
|
360 | + $this->get_all_active($scope, array(array('Currency.CUR_code' => array('IN', $currencies_for_events)))), |
|
361 | 361 | $transaction, |
362 | 362 | $scope |
363 | 363 | ); |
@@ -373,16 +373,16 @@ discard block |
||
373 | 373 | * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the registration. |
374 | 374 | * @return EE_Payment|null |
375 | 375 | */ |
376 | - public function get_last_used_for_registration( $registration_or_reg_id ) { |
|
377 | - $registration_id = EEM_Registration::instance()->ensure_is_ID( $registration_or_reg_id ); |
|
376 | + public function get_last_used_for_registration($registration_or_reg_id) { |
|
377 | + $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
378 | 378 | |
379 | 379 | $query_params = array( |
380 | 380 | 0 => array( |
381 | 381 | 'Payment.Registration.REG_ID' => $registration_id, |
382 | 382 | ), |
383 | - 'order_by' => array( 'Payment.PAY_ID' => 'DESC' ) |
|
383 | + 'order_by' => array('Payment.PAY_ID' => 'DESC') |
|
384 | 384 | ); |
385 | - return $this->get_one( $query_params ); |
|
385 | + return $this->get_one($query_params); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | } |
@@ -83,9 +83,9 @@ |
||
83 | 83 | // build DI container |
84 | 84 | $OpenCoffeeShop = new OpenCoffeeShop(); |
85 | 85 | $OpenCoffeeShop->addRecipes(); |
86 | - $OpenCoffeeShop->CoffeeShop()->addService('EE_Request', $request); |
|
87 | - $OpenCoffeeShop->CoffeeShop()->addService('EE_Response', $response); |
|
88 | - CoffeeMill::setCoffeeShop($OpenCoffeeShop->CoffeeShop()); |
|
86 | + $OpenCoffeeShop->CoffeeShop()->addService('EE_Request', $request); |
|
87 | + $OpenCoffeeShop->CoffeeShop()->addService('EE_Response', $response); |
|
88 | + CoffeeMill::setCoffeeShop($OpenCoffeeShop->CoffeeShop()); |
|
89 | 89 | // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
90 | 90 | // create and cache the CommandBus, and also add the CapChecker middleware |
91 | 91 | $this->registry->create( |
@@ -2,8 +2,8 @@ discard block |
||
2 | 2 | use EventEspresso\core\services\container\CoffeeMill; |
3 | 3 | use EventEspresso\core\services\container\OpenCoffeeShop; |
4 | 4 | |
5 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
6 | - exit( 'No direct script access allowed' ); |
|
5 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | + exit('No direct script access allowed'); |
|
7 | 7 | } |
8 | 8 | /** |
9 | 9 | * |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function __construct() { |
56 | 56 | // deprecated functions |
57 | - espresso_load_required( 'EventEspresso\core\Factory', EE_CORE . 'Factory.php' ); |
|
57 | + espresso_load_required('EventEspresso\core\Factory', EE_CORE.'Factory.php'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | |
@@ -70,16 +70,16 @@ discard block |
||
70 | 70 | * @param EE_Response $response |
71 | 71 | * @return EE_Response |
72 | 72 | */ |
73 | - public function handle_request( EE_Request $request, EE_Response $response ) { |
|
73 | + public function handle_request(EE_Request $request, EE_Response $response) { |
|
74 | 74 | $this->request = $request; |
75 | 75 | $this->response = $response; |
76 | 76 | // info about how to load classes required by other classes |
77 | 77 | $this->dependency_map = $this->_load_dependency_map(); |
78 | 78 | // central repository for classes |
79 | 79 | $this->registry = $this->_load_registry(); |
80 | - do_action( 'EE_Load_Espresso_Core__handle_request__initialize_core_loading' ); |
|
80 | + do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
81 | 81 | // PSR4 Autoloaders |
82 | - $this->registry->load_core( 'EE_Psr4AutoloaderInit' ); |
|
82 | + $this->registry->load_core('EE_Psr4AutoloaderInit'); |
|
83 | 83 | // build DI container |
84 | 84 | $OpenCoffeeShop = new OpenCoffeeShop(); |
85 | 85 | $OpenCoffeeShop->addRecipes(); |
@@ -92,20 +92,20 @@ discard block |
||
92 | 92 | 'CommandBusInterface', |
93 | 93 | array( |
94 | 94 | null, |
95 | - $this->registry->create( 'CapChecker' ) |
|
95 | + $this->registry->create('CapChecker') |
|
96 | 96 | ), |
97 | 97 | true |
98 | 98 | ); |
99 | 99 | // workarounds for PHP < 5.3 |
100 | 100 | $this->_load_class_tools(); |
101 | 101 | // load interfaces |
102 | - espresso_load_required( 'EEI_Payment_Method_Interfaces', EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php' ); |
|
102 | + espresso_load_required('EEI_Payment_Method_Interfaces', EE_LIBRARIES.'payment_methods'.DS.'EEI_Payment_Method_Interfaces.php'); |
|
103 | 103 | // deprecated functions |
104 | - espresso_load_required( 'EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php' ); |
|
104 | + espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php'); |
|
105 | 105 | // WP cron jobs |
106 | - $this->registry->load_core( 'Cron_Tasks' ); |
|
107 | - $this->registry->load_core( 'EE_Request_Handler' ); |
|
108 | - $this->registry->load_core( 'EE_System' ); |
|
106 | + $this->registry->load_core('Cron_Tasks'); |
|
107 | + $this->registry->load_core('EE_Request_Handler'); |
|
108 | + $this->registry->load_core('EE_System'); |
|
109 | 109 | |
110 | 110 | return $this->response; |
111 | 111 | } |
@@ -135,11 +135,11 @@ discard block |
||
135 | 135 | * @throws \EE_Error |
136 | 136 | */ |
137 | 137 | public function dependency_map() { |
138 | - if ( ! $this->dependency_map instanceof EE_Dependency_Map ) { |
|
138 | + if ( ! $this->dependency_map instanceof EE_Dependency_Map) { |
|
139 | 139 | throw new EE_Error( |
140 | 140 | sprintf( |
141 | - __( 'Invalid EE_Dependency_Map: "%1$s"', 'event_espresso' ), |
|
142 | - print_r( $this->dependency_map, true ) |
|
141 | + __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
|
142 | + print_r($this->dependency_map, true) |
|
143 | 143 | ) |
144 | 144 | ); |
145 | 145 | } |
@@ -153,11 +153,11 @@ discard block |
||
153 | 153 | * @throws \EE_Error |
154 | 154 | */ |
155 | 155 | public function registry() { |
156 | - if ( ! $this->registry instanceof EE_Registry ) { |
|
156 | + if ( ! $this->registry instanceof EE_Registry) { |
|
157 | 157 | throw new EE_Error( |
158 | 158 | sprintf( |
159 | - __( 'Invalid EE_Registry: "%1$s"', 'event_espresso' ), |
|
160 | - print_r( $this->registry, true ) |
|
159 | + __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
|
160 | + print_r($this->registry, true) |
|
161 | 161 | ) |
162 | 162 | ); |
163 | 163 | } |
@@ -173,15 +173,15 @@ discard block |
||
173 | 173 | * @return EE_Dependency_Map |
174 | 174 | */ |
175 | 175 | private function _load_dependency_map() { |
176 | - if ( ! is_readable( EE_CORE . 'EE_Dependency_Map.core.php' ) ) { |
|
176 | + if ( ! is_readable(EE_CORE.'EE_Dependency_Map.core.php')) { |
|
177 | 177 | EE_Error::add_error( |
178 | - __( 'The EE_Dependency_Map core class could not be loaded.', 'event_espresso' ), |
|
178 | + __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
|
179 | 179 | __FILE__, __FUNCTION__, __LINE__ |
180 | 180 | ); |
181 | - wp_die( EE_Error::get_notices() ); |
|
181 | + wp_die(EE_Error::get_notices()); |
|
182 | 182 | } |
183 | - require_once( EE_CORE . 'EE_Dependency_Map.core.php' ); |
|
184 | - return EE_Dependency_Map::instance( $this->request, $this->response ); |
|
183 | + require_once(EE_CORE.'EE_Dependency_Map.core.php'); |
|
184 | + return EE_Dependency_Map::instance($this->request, $this->response); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | |
@@ -193,15 +193,15 @@ discard block |
||
193 | 193 | * @return EE_Registry |
194 | 194 | */ |
195 | 195 | private function _load_registry() { |
196 | - if ( ! is_readable( EE_CORE . 'EE_Registry.core.php' )) { |
|
196 | + if ( ! is_readable(EE_CORE.'EE_Registry.core.php')) { |
|
197 | 197 | EE_Error::add_error( |
198 | - __( 'The EE_Registry core class could not be loaded.', 'event_espresso' ), |
|
198 | + __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
|
199 | 199 | __FILE__, __FUNCTION__, __LINE__ |
200 | 200 | ); |
201 | - wp_die( EE_Error::get_notices() ); |
|
201 | + wp_die(EE_Error::get_notices()); |
|
202 | 202 | } |
203 | - require_once( EE_CORE . 'EE_Registry.core.php' ); |
|
204 | - return EE_Registry::instance( $this->dependency_map ); |
|
203 | + require_once(EE_CORE.'EE_Registry.core.php'); |
|
204 | + return EE_Registry::instance($this->dependency_map); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | |
@@ -212,13 +212,13 @@ discard block |
||
212 | 212 | * @return void |
213 | 213 | */ |
214 | 214 | private function _load_class_tools() { |
215 | - if ( ! is_readable( EE_HELPERS . 'EEH_Class_Tools.helper.php' )) { |
|
215 | + if ( ! is_readable(EE_HELPERS.'EEH_Class_Tools.helper.php')) { |
|
216 | 216 | EE_Error::add_error( |
217 | - __( 'The EEH_Class_Tools helper could not be loaded.', 'event_espresso' ), |
|
217 | + __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
|
218 | 218 | __FILE__, __FUNCTION__, __LINE__ |
219 | 219 | ); |
220 | 220 | } |
221 | - require_once( EE_HELPERS . 'EEH_Class_Tools.helper.php' ); |
|
221 | + require_once(EE_HELPERS.'EEH_Class_Tools.helper.php'); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | |
@@ -232,13 +232,13 @@ discard block |
||
232 | 232 | * @param \EE_Request $request |
233 | 233 | * @param \EE_Response $response |
234 | 234 | */ |
235 | - public function handle_response( EE_Request $request, EE_Response $response ) { |
|
235 | + public function handle_response(EE_Request $request, EE_Response $response) { |
|
236 | 236 | //\EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 ); |
237 | 237 | //EEH_Debug_Tools::printr( $request, '$request', __FILE__, __LINE__ ); |
238 | 238 | //EEH_Debug_Tools::printr( $response, '$response', __FILE__, __LINE__ ); |
239 | 239 | //die(); |
240 | - if ( $response->plugin_deactivated() ) { |
|
241 | - espresso_deactivate_plugin( EE_PLUGIN_BASENAME ); |
|
240 | + if ($response->plugin_deactivated()) { |
|
241 | + espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
242 | 242 | } |
243 | 243 | } |
244 | 244 |
@@ -25,330 +25,329 @@ |
||
25 | 25 | class PersistentAdminNotice implements RequiresCapCheckInterface |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * @var string $name |
|
30 | - */ |
|
31 | - protected $name = ''; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var string $message |
|
35 | - */ |
|
36 | - protected $message = ''; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var boolean $force_update |
|
40 | - */ |
|
41 | - protected $force_update = false; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var string $capability |
|
45 | - */ |
|
46 | - protected $capability = 'manage_options'; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var string $cap_context |
|
50 | - */ |
|
51 | - protected $cap_context = 'view persistent admin notice'; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var boolean $dismissed |
|
55 | - */ |
|
56 | - protected $dismissed = false; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var CapCheckInterface $cap_check |
|
60 | - */ |
|
61 | - protected $cap_check; |
|
62 | - |
|
63 | - /** |
|
64 | - * if true, then this notice will be deleted from the database |
|
65 | - * |
|
66 | - * @var boolean $purge |
|
67 | - */ |
|
68 | - protected $purge = false; |
|
69 | - |
|
70 | - /** |
|
71 | - * gets set to true if notice is successfully registered with the PersistentAdminNoticeManager |
|
72 | - * if false, and WP_DEBUG is on, then an exception will be thrown in the admin footer |
|
73 | - * |
|
74 | - * @var boolean $registered |
|
75 | - */ |
|
76 | - private $registered = false; |
|
77 | - |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * PersistentAdminNotice constructor |
|
82 | - |
|
83 | - * |
|
84 | - * @param string $name [required] the name, or key of the Persistent Admin Notice to be stored |
|
85 | - * @param string $message [required] the message to be stored persistently until dismissed |
|
86 | - * @param bool $force_update enforce the reappearance of a persistent message |
|
87 | - * @param string $capability user capability required to view this notice |
|
88 | - * @param string $cap_context description for why the cap check is being performed |
|
89 | - * @param bool $dismissed whether or not the user has already dismissed/viewed this notice |
|
90 | - * @throws InvalidDataTypeException |
|
91 | - */ |
|
92 | - public function __construct( |
|
93 | - $name, |
|
94 | - $message, |
|
95 | - $force_update = false, |
|
96 | - $capability = 'manage_options', |
|
97 | - $cap_context = 'view persistent admin notice', |
|
98 | - $dismissed = false |
|
99 | - ) { |
|
100 | - $this->setName($name); |
|
101 | - $this->setMessage($message); |
|
102 | - $this->setForceUpdate($force_update); |
|
103 | - $this->setCapability($capability); |
|
104 | - $this->setCapContext($cap_context); |
|
105 | - $this->setDismissed($dismissed); |
|
106 | - add_action( |
|
107 | - 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
108 | - array($this, 'registerPersistentAdminNotice') |
|
109 | - ); |
|
110 | - add_action('admin_footer', array($this, 'confirmRegistered')); |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - public function getName() |
|
119 | - { |
|
120 | - return $this->name; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @param string $name |
|
127 | - * @throws InvalidDataTypeException |
|
128 | - */ |
|
129 | - private function setName($name) |
|
130 | - { |
|
131 | - if ( ! is_string($name)) { |
|
132 | - throw new InvalidDataTypeException('$name', $name, 'string'); |
|
133 | - } |
|
134 | - $this->name = sanitize_key($name); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public function getMessage() |
|
143 | - { |
|
144 | - return $this->message; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * @param string $message |
|
151 | - * @throws InvalidDataTypeException |
|
152 | - */ |
|
153 | - private function setMessage($message) |
|
154 | - { |
|
155 | - // \EEH_Debug_Tools::printr($this->name, '$this->name', __FILE__, __LINE__); |
|
156 | - // \EEH_Debug_Tools::printr($message, '$message', __FILE__, __LINE__); |
|
157 | - if ( ! is_string($message)) { |
|
158 | - throw new InvalidDataTypeException('$message', $message, 'string'); |
|
159 | - } |
|
160 | - global $allowedtags; |
|
161 | - $allowedtags['br'] = array(); |
|
162 | - $this->message = wp_kses($message, $allowedtags); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @return bool |
|
169 | - */ |
|
170 | - public function getForceUpdate() |
|
171 | - { |
|
172 | - return $this->force_update; |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * @param bool $force_update |
|
179 | - */ |
|
180 | - private function setForceUpdate($force_update) |
|
181 | - { |
|
182 | - $this->force_update = filter_var($force_update, FILTER_VALIDATE_BOOLEAN); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * @return string |
|
189 | - */ |
|
190 | - public function getCapability() |
|
191 | - { |
|
192 | - return $this->capability; |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @param string $capability |
|
199 | - * @throws InvalidDataTypeException |
|
200 | - */ |
|
201 | - private function setCapability($capability) |
|
202 | - { |
|
203 | - if ( ! is_string($capability)) { |
|
204 | - throw new InvalidDataTypeException('$capability', $capability, 'string'); |
|
205 | - } |
|
206 | - $this->capability = $capability; |
|
207 | - } |
|
28 | + /** |
|
29 | + * @var string $name |
|
30 | + */ |
|
31 | + protected $name = ''; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var string $message |
|
35 | + */ |
|
36 | + protected $message = ''; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var boolean $force_update |
|
40 | + */ |
|
41 | + protected $force_update = false; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var string $capability |
|
45 | + */ |
|
46 | + protected $capability = 'manage_options'; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var string $cap_context |
|
50 | + */ |
|
51 | + protected $cap_context = 'view persistent admin notice'; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var boolean $dismissed |
|
55 | + */ |
|
56 | + protected $dismissed = false; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var CapCheckInterface $cap_check |
|
60 | + */ |
|
61 | + protected $cap_check; |
|
62 | + |
|
63 | + /** |
|
64 | + * if true, then this notice will be deleted from the database |
|
65 | + * |
|
66 | + * @var boolean $purge |
|
67 | + */ |
|
68 | + protected $purge = false; |
|
69 | + |
|
70 | + /** |
|
71 | + * gets set to true if notice is successfully registered with the PersistentAdminNoticeManager |
|
72 | + * if false, and WP_DEBUG is on, then an exception will be thrown in the admin footer |
|
73 | + * |
|
74 | + * @var boolean $registered |
|
75 | + */ |
|
76 | + private $registered = false; |
|
77 | + |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * PersistentAdminNotice constructor |
|
82 | + * |
|
83 | + * @param string $name [required] the name, or key of the Persistent Admin Notice to be stored |
|
84 | + * @param string $message [required] the message to be stored persistently until dismissed |
|
85 | + * @param bool $force_update enforce the reappearance of a persistent message |
|
86 | + * @param string $capability user capability required to view this notice |
|
87 | + * @param string $cap_context description for why the cap check is being performed |
|
88 | + * @param bool $dismissed whether or not the user has already dismissed/viewed this notice |
|
89 | + * @throws InvalidDataTypeException |
|
90 | + */ |
|
91 | + public function __construct( |
|
92 | + $name, |
|
93 | + $message, |
|
94 | + $force_update = false, |
|
95 | + $capability = 'manage_options', |
|
96 | + $cap_context = 'view persistent admin notice', |
|
97 | + $dismissed = false |
|
98 | + ) { |
|
99 | + $this->setName($name); |
|
100 | + $this->setMessage($message); |
|
101 | + $this->setForceUpdate($force_update); |
|
102 | + $this->setCapability($capability); |
|
103 | + $this->setCapContext($cap_context); |
|
104 | + $this->setDismissed($dismissed); |
|
105 | + add_action( |
|
106 | + 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
107 | + array($this, 'registerPersistentAdminNotice') |
|
108 | + ); |
|
109 | + add_action('admin_footer', array($this, 'confirmRegistered')); |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @return string |
|
116 | + */ |
|
117 | + public function getName() |
|
118 | + { |
|
119 | + return $this->name; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @param string $name |
|
126 | + * @throws InvalidDataTypeException |
|
127 | + */ |
|
128 | + private function setName($name) |
|
129 | + { |
|
130 | + if ( ! is_string($name)) { |
|
131 | + throw new InvalidDataTypeException('$name', $name, 'string'); |
|
132 | + } |
|
133 | + $this->name = sanitize_key($name); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + public function getMessage() |
|
142 | + { |
|
143 | + return $this->message; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @param string $message |
|
150 | + * @throws InvalidDataTypeException |
|
151 | + */ |
|
152 | + private function setMessage($message) |
|
153 | + { |
|
154 | + // \EEH_Debug_Tools::printr($this->name, '$this->name', __FILE__, __LINE__); |
|
155 | + // \EEH_Debug_Tools::printr($message, '$message', __FILE__, __LINE__); |
|
156 | + if ( ! is_string($message)) { |
|
157 | + throw new InvalidDataTypeException('$message', $message, 'string'); |
|
158 | + } |
|
159 | + global $allowedtags; |
|
160 | + $allowedtags['br'] = array(); |
|
161 | + $this->message = wp_kses($message, $allowedtags); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * @return bool |
|
168 | + */ |
|
169 | + public function getForceUpdate() |
|
170 | + { |
|
171 | + return $this->force_update; |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * @param bool $force_update |
|
178 | + */ |
|
179 | + private function setForceUpdate($force_update) |
|
180 | + { |
|
181 | + $this->force_update = filter_var($force_update, FILTER_VALIDATE_BOOLEAN); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * @return string |
|
188 | + */ |
|
189 | + public function getCapability() |
|
190 | + { |
|
191 | + return $this->capability; |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * @param string $capability |
|
198 | + * @throws InvalidDataTypeException |
|
199 | + */ |
|
200 | + private function setCapability($capability) |
|
201 | + { |
|
202 | + if ( ! is_string($capability)) { |
|
203 | + throw new InvalidDataTypeException('$capability', $capability, 'string'); |
|
204 | + } |
|
205 | + $this->capability = $capability; |
|
206 | + } |
|
208 | 207 | |
209 | 208 | |
210 | 209 | |
211 | - /** |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - public function getCapContext() |
|
215 | - { |
|
216 | - return $this->cap_context; |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * @param string $cap_context |
|
223 | - * @throws InvalidDataTypeException |
|
224 | - */ |
|
225 | - private function setCapContext($cap_context) |
|
226 | - { |
|
227 | - if ( ! is_string($cap_context)) { |
|
228 | - throw new InvalidDataTypeException('$cap_context', $cap_context, 'string'); |
|
229 | - } |
|
230 | - $this->cap_context = $cap_context; |
|
231 | - } |
|
232 | - |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * @return bool |
|
237 | - */ |
|
238 | - public function getDismissed() |
|
239 | - { |
|
240 | - return $this->dismissed; |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * @param bool $dismissed |
|
247 | - */ |
|
248 | - public function setDismissed($dismissed) |
|
249 | - { |
|
250 | - $this->dismissed = filter_var($dismissed, FILTER_VALIDATE_BOOLEAN); |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * @return CapCheckInterface |
|
257 | - * @throws InvalidDataTypeException |
|
258 | - */ |
|
259 | - public function getCapCheck() |
|
260 | - { |
|
261 | - if ( ! $this->cap_check instanceof CapCheckInterface) { |
|
262 | - $this->setCapCheck( |
|
263 | - new CapCheck( |
|
264 | - $this->capability, |
|
265 | - $this->cap_context |
|
266 | - ) |
|
267 | - ); |
|
268 | - } |
|
269 | - return $this->cap_check; |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * @param CapCheckInterface $cap_check |
|
276 | - */ |
|
277 | - private function setCapCheck(CapCheckInterface $cap_check) |
|
278 | - { |
|
279 | - $this->cap_check = $cap_check; |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * @return bool |
|
286 | - */ |
|
287 | - public function getPurge() |
|
288 | - { |
|
289 | - return $this->purge; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * @param bool $purge |
|
296 | - */ |
|
297 | - public function setPurge($purge) |
|
298 | - { |
|
299 | - $this->purge = filter_var($purge, FILTER_VALIDATE_BOOLEAN); |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * given a valid PersistentAdminNotice Collection, |
|
306 | - * this notice will be added if it is not already found in the collection (using its name as the identifier) |
|
307 | - * if an existing notice is found that has already been dismissed, |
|
308 | - * but we are overriding with a forced update, then we will toggle its dismissed state, |
|
309 | - * so that the notice is displayed again |
|
310 | - * |
|
311 | - * @param Collection $persistent_admin_notice_collection |
|
312 | - * @throws InvalidEntityException |
|
313 | - */ |
|
314 | - public function registerPersistentAdminNotice(Collection $persistent_admin_notice_collection) |
|
315 | - { |
|
316 | - // first check if this notice has already been added to the collection |
|
317 | - if ($persistent_admin_notice_collection->has($this->name)) { |
|
318 | - /** @var PersistentAdminNotice $existing */ |
|
319 | - $existing = $persistent_admin_notice_collection->get($this->name); |
|
320 | - // we don't need to add it again (we can't actually) |
|
321 | - // but if it has already been dismissed, and we are overriding with a forced update |
|
322 | - if ($existing->getDismissed() && $this->getForceUpdate()) { |
|
323 | - // then toggle the notice's dismissed state to true |
|
324 | - // so that it gets displayed again |
|
325 | - $existing->setDismissed(false); |
|
326 | - } |
|
327 | - } else { |
|
328 | - $persistent_admin_notice_collection->add($this, $this->name); |
|
329 | - } |
|
330 | - $this->registered = true; |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * @throws DomainException |
|
337 | - */ |
|
338 | - public function confirmRegistered() |
|
339 | - { |
|
340 | - if( ! $this->registered && WP_DEBUG) { |
|
341 | - throw new DomainException( |
|
342 | - sprintf( |
|
343 | - esc_html__( |
|
344 | - 'The "%1$s" PersistentAdminNotice was not successfully registered. Please ensure that it is being created prior to either the "admin_notices" or "network_admin_notices" hooks being triggered.', |
|
345 | - 'event_espresso' |
|
346 | - ), |
|
347 | - $this->name |
|
348 | - ) |
|
349 | - ); |
|
350 | - } |
|
351 | - } |
|
210 | + /** |
|
211 | + * @return string |
|
212 | + */ |
|
213 | + public function getCapContext() |
|
214 | + { |
|
215 | + return $this->cap_context; |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * @param string $cap_context |
|
222 | + * @throws InvalidDataTypeException |
|
223 | + */ |
|
224 | + private function setCapContext($cap_context) |
|
225 | + { |
|
226 | + if ( ! is_string($cap_context)) { |
|
227 | + throw new InvalidDataTypeException('$cap_context', $cap_context, 'string'); |
|
228 | + } |
|
229 | + $this->cap_context = $cap_context; |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + |
|
234 | + /** |
|
235 | + * @return bool |
|
236 | + */ |
|
237 | + public function getDismissed() |
|
238 | + { |
|
239 | + return $this->dismissed; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * @param bool $dismissed |
|
246 | + */ |
|
247 | + public function setDismissed($dismissed) |
|
248 | + { |
|
249 | + $this->dismissed = filter_var($dismissed, FILTER_VALIDATE_BOOLEAN); |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * @return CapCheckInterface |
|
256 | + * @throws InvalidDataTypeException |
|
257 | + */ |
|
258 | + public function getCapCheck() |
|
259 | + { |
|
260 | + if ( ! $this->cap_check instanceof CapCheckInterface) { |
|
261 | + $this->setCapCheck( |
|
262 | + new CapCheck( |
|
263 | + $this->capability, |
|
264 | + $this->cap_context |
|
265 | + ) |
|
266 | + ); |
|
267 | + } |
|
268 | + return $this->cap_check; |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * @param CapCheckInterface $cap_check |
|
275 | + */ |
|
276 | + private function setCapCheck(CapCheckInterface $cap_check) |
|
277 | + { |
|
278 | + $this->cap_check = $cap_check; |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * @return bool |
|
285 | + */ |
|
286 | + public function getPurge() |
|
287 | + { |
|
288 | + return $this->purge; |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * @param bool $purge |
|
295 | + */ |
|
296 | + public function setPurge($purge) |
|
297 | + { |
|
298 | + $this->purge = filter_var($purge, FILTER_VALIDATE_BOOLEAN); |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * given a valid PersistentAdminNotice Collection, |
|
305 | + * this notice will be added if it is not already found in the collection (using its name as the identifier) |
|
306 | + * if an existing notice is found that has already been dismissed, |
|
307 | + * but we are overriding with a forced update, then we will toggle its dismissed state, |
|
308 | + * so that the notice is displayed again |
|
309 | + * |
|
310 | + * @param Collection $persistent_admin_notice_collection |
|
311 | + * @throws InvalidEntityException |
|
312 | + */ |
|
313 | + public function registerPersistentAdminNotice(Collection $persistent_admin_notice_collection) |
|
314 | + { |
|
315 | + // first check if this notice has already been added to the collection |
|
316 | + if ($persistent_admin_notice_collection->has($this->name)) { |
|
317 | + /** @var PersistentAdminNotice $existing */ |
|
318 | + $existing = $persistent_admin_notice_collection->get($this->name); |
|
319 | + // we don't need to add it again (we can't actually) |
|
320 | + // but if it has already been dismissed, and we are overriding with a forced update |
|
321 | + if ($existing->getDismissed() && $this->getForceUpdate()) { |
|
322 | + // then toggle the notice's dismissed state to true |
|
323 | + // so that it gets displayed again |
|
324 | + $existing->setDismissed(false); |
|
325 | + } |
|
326 | + } else { |
|
327 | + $persistent_admin_notice_collection->add($this, $this->name); |
|
328 | + } |
|
329 | + $this->registered = true; |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * @throws DomainException |
|
336 | + */ |
|
337 | + public function confirmRegistered() |
|
338 | + { |
|
339 | + if( ! $this->registered && WP_DEBUG) { |
|
340 | + throw new DomainException( |
|
341 | + sprintf( |
|
342 | + esc_html__( |
|
343 | + 'The "%1$s" PersistentAdminNotice was not successfully registered. Please ensure that it is being created prior to either the "admin_notices" or "network_admin_notices" hooks being triggered.', |
|
344 | + 'event_espresso' |
|
345 | + ), |
|
346 | + $this->name |
|
347 | + ) |
|
348 | + ); |
|
349 | + } |
|
350 | + } |
|
352 | 351 | |
353 | 352 | |
354 | 353 | } |
@@ -337,7 +337,7 @@ |
||
337 | 337 | */ |
338 | 338 | public function confirmRegistered() |
339 | 339 | { |
340 | - if( ! $this->registered && WP_DEBUG) { |
|
340 | + if ( ! $this->registered && WP_DEBUG) { |
|
341 | 341 | throw new DomainException( |
342 | 342 | sprintf( |
343 | 343 | esc_html__( |
@@ -405,21 +405,21 @@ discard block |
||
405 | 405 | $class_name = $this->_get_classname_for_admin_init_page( $page ); |
406 | 406 | EE_Registry::instance()->load_file( $path, $class_name, 'core' ); |
407 | 407 | if ( ! class_exists( $class_name )) { |
408 | - $inner_error_msg = '<br />' . sprintf( |
|
409 | - esc_html__( |
|
410 | - 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
411 | - 'event_espresso' |
|
412 | - ), |
|
413 | - '<strong>' . $class_name . '</strong>' |
|
414 | - ); |
|
408 | + $inner_error_msg = '<br />' . sprintf( |
|
409 | + esc_html__( |
|
410 | + 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
411 | + 'event_espresso' |
|
412 | + ), |
|
413 | + '<strong>' . $class_name . '</strong>' |
|
414 | + ); |
|
415 | 415 | $error_msg[] = sprintf( __('Something went wrong with loading the %s admin page.', 'event_espresso' ), $page); |
416 | 416 | $error_msg[] = $error_msg[0] |
417 | - . "\r\n" |
|
418 | - . sprintf( |
|
419 | - esc_html__( 'There is no Init class in place for the %s admin page.', 'event_espresso'), |
|
420 | - $page |
|
421 | - ) |
|
422 | - . $inner_error_msg; |
|
417 | + . "\r\n" |
|
418 | + . sprintf( |
|
419 | + esc_html__( 'There is no Init class in place for the %s admin page.', 'event_espresso'), |
|
420 | + $page |
|
421 | + ) |
|
422 | + . $inner_error_msg; |
|
423 | 423 | throw new EE_Error( implode( '||', $error_msg )); |
424 | 424 | } |
425 | 425 | $a = new ReflectionClass($class_name); |
@@ -465,15 +465,15 @@ discard block |
||
465 | 465 | |
466 | 466 | |
467 | 467 | |
468 | - /** |
|
469 | - * _prep_pages |
|
470 | - * sets the _prepped_menu_maps property |
|
471 | - * |
|
472 | - * @access private |
|
473 | - * @throws EE_Error |
|
474 | - * @return void |
|
475 | - * @throws InvalidDataTypeException |
|
476 | - */ |
|
468 | + /** |
|
469 | + * _prep_pages |
|
470 | + * sets the _prepped_menu_maps property |
|
471 | + * |
|
472 | + * @access private |
|
473 | + * @throws EE_Error |
|
474 | + * @return void |
|
475 | + * @throws InvalidDataTypeException |
|
476 | + */ |
|
477 | 477 | private function _prep_pages() { |
478 | 478 | $pages_array = array(); |
479 | 479 | |
@@ -485,16 +485,16 @@ discard block |
||
485 | 485 | $page_map = $page->get_menu_map(); |
486 | 486 | //if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
487 | 487 | if ( is_array( $page_map ) || empty( $page_map ) ) { |
488 | - new PersistentAdminNotice( |
|
489 | - 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
490 | - sprintf( |
|
491 | - __( |
|
492 | - 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
|
493 | - 'event_espresso' |
|
494 | - ), |
|
495 | - $page->label |
|
496 | - ) |
|
497 | - ); |
|
488 | + new PersistentAdminNotice( |
|
489 | + 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
490 | + sprintf( |
|
491 | + __( |
|
492 | + 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
|
493 | + 'event_espresso' |
|
494 | + ), |
|
495 | + $page->label |
|
496 | + ) |
|
497 | + ); |
|
498 | 498 | continue; |
499 | 499 | } |
500 | 500 |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\domain\entities\notifications\PersistentAdminNotice; |
3 | 3 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
4 | 4 | |
5 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
5 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
6 | 6 | exit('NO direct script access allowed'); |
7 | 7 | |
8 | 8 | /** |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | //let's do a scan and see what installed pages we have |
123 | 123 | $this->_get_installed_pages(); |
124 | 124 | //set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to). |
125 | - add_action('admin_menu', array( $this, 'set_menus' )); |
|
126 | - add_action( 'network_admin_menu', array( $this, 'set_network_menus' ) ); |
|
125 | + add_action('admin_menu', array($this, 'set_menus')); |
|
126 | + add_action('network_admin_menu', array($this, 'set_network_menus')); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | |
@@ -136,13 +136,13 @@ discard block |
||
136 | 136 | * @return void |
137 | 137 | */ |
138 | 138 | private function _define_caffeinated_constants() { |
139 | - if ( ! defined( 'EE_CORE_CAF_ADMIN' ) ) { |
|
140 | - define( 'EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
141 | - define( 'EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
142 | - define( 'EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
143 | - define( 'EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
144 | - define( 'EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
145 | - define( 'EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
139 | + if ( ! defined('EE_CORE_CAF_ADMIN')) { |
|
140 | + define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH.'caffeinated/admin/'); |
|
141 | + define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL.'caffeinated/admin/'); |
|
142 | + define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN.'new/'); |
|
143 | + define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN.'extend/'); |
|
144 | + define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL.'extend/'); |
|
145 | + define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN.'hooks/'); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | |
162 | 162 | //set array of EE_Admin_Page_Menu_Group objects |
163 | 163 | $groups = array( |
164 | - 'main' => new EE_Admin_Page_Menu_Group( array( |
|
164 | + 'main' => new EE_Admin_Page_Menu_Group(array( |
|
165 | 165 | 'menu_label' => __('Main', 'event_espresso'), |
166 | 166 | 'show_on_menu' => EE_Admin_Page_Menu_Map::NONE, |
167 | 167 | 'menu_slug' => 'main', |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | 'menu_order' => 0, |
170 | 170 | 'parent_slug' => 'espresso_events', |
171 | 171 | )), |
172 | - 'management' => new EE_Admin_Page_Menu_Group( array( |
|
172 | + 'management' => new EE_Admin_Page_Menu_Group(array( |
|
173 | 173 | 'menu_label' => __('Management', 'event_espresso'), |
174 | 174 | 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
175 | 175 | 'menu_slug' => 'management', |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | 'menu_order' => 10, |
178 | 178 | 'parent_slug' => 'espresso_events' |
179 | 179 | )), |
180 | - 'settings' => new EE_Admin_Page_Menu_Group( array( |
|
180 | + 'settings' => new EE_Admin_Page_Menu_Group(array( |
|
181 | 181 | 'menu_label' => __('Settings', 'event_espresso'), |
182 | 182 | 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
183 | 183 | 'menu_slug' => 'settings', |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | 'menu_order' => 30, |
186 | 186 | 'parent_slug' => 'espresso_events' |
187 | 187 | )), |
188 | - 'templates' => new EE_Admin_Page_Menu_Group( array( |
|
188 | + 'templates' => new EE_Admin_Page_Menu_Group(array( |
|
189 | 189 | 'menu_label' => __('Templates', 'event_espresso'), |
190 | 190 | 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
191 | 191 | 'menu_slug' => 'templates', |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | 'menu_order' => 40, |
194 | 194 | 'parent_slug' => 'espresso_events' |
195 | 195 | )), |
196 | - 'extras' => new EE_Admin_Page_Menu_Group( array( |
|
196 | + 'extras' => new EE_Admin_Page_Menu_Group(array( |
|
197 | 197 | 'menu_label' => __('Extras', 'event_espresso'), |
198 | 198 | 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
199 | 199 | 'menu_slug' => 'extras', |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | 'parent_slug' => 'espresso_events', |
203 | 203 | 'maintenance_mode_parent' => 'espresso_maintenance_settings' |
204 | 204 | )), |
205 | - 'tools' => new EE_Admin_Page_Menu_Group( array( |
|
205 | + 'tools' => new EE_Admin_Page_Menu_Group(array( |
|
206 | 206 | 'menu_label' => __("Tools", "event_espresso"), |
207 | 207 | 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
208 | 208 | 'menu_slug' => 'tools', |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | 'menu_order' => 60, |
211 | 211 | 'parent_slug' => 'espresso_events' |
212 | 212 | )), |
213 | - 'addons' => new EE_Admin_Page_Menu_Group( array( |
|
213 | + 'addons' => new EE_Admin_Page_Menu_Group(array( |
|
214 | 214 | 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
215 | 215 | 'menu_label' => __('Add-ons', 'event_espresso'), |
216 | 216 | 'menu_slug' => 'addons', |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | )) |
221 | 221 | ); |
222 | 222 | |
223 | - $this->_admin_menu_groups = apply_filters( 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', $groups ); |
|
223 | + $this->_admin_menu_groups = apply_filters('FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', $groups); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | |
@@ -238,10 +238,10 @@ discard block |
||
238 | 238 | private function _rearrange_menu_groups() { |
239 | 239 | $groups = array(); |
240 | 240 | //first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
241 | - usort( $this->_admin_menu_groups, array( $this, '_sort_menu_maps' ) ); |
|
242 | - foreach ( $this->_admin_menu_groups as $group ) { |
|
243 | - if ( ! $group instanceof EE_Admin_Page_Menu_Group ) |
|
244 | - throw new EE_Error( sprintf( __('Unable to continue sorting the menu groups array because there is an invalid value for the menu groups. All values in this array are required to be a EE_Admin_Page_Menu_Group object. Instead there was: %s', 'event_espresso'), print_r($group, TRUE) ) ); |
|
241 | + usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
|
242 | + foreach ($this->_admin_menu_groups as $group) { |
|
243 | + if ( ! $group instanceof EE_Admin_Page_Menu_Group) |
|
244 | + throw new EE_Error(sprintf(__('Unable to continue sorting the menu groups array because there is an invalid value for the menu groups. All values in this array are required to be a EE_Admin_Page_Menu_Group object. Instead there was: %s', 'event_espresso'), print_r($group, TRUE))); |
|
245 | 245 | $groups[$group->menu_slug] = $group; |
246 | 246 | } |
247 | 247 | return $groups; |
@@ -259,48 +259,48 @@ discard block |
||
259 | 259 | */ |
260 | 260 | private function _get_installed_pages() { |
261 | 261 | $installed_refs = array(); |
262 | - $exclude = array( 'assets', 'templates' ); |
|
262 | + $exclude = array('assets', 'templates'); |
|
263 | 263 | // grab everything in the admin core directory |
264 | - $admin_screens = glob( EE_ADMIN_PAGES . '*', GLOB_ONLYDIR ); |
|
265 | - if ( $admin_screens ) { |
|
266 | - foreach( $admin_screens as $admin_screen ) { |
|
264 | + $admin_screens = glob(EE_ADMIN_PAGES.'*', GLOB_ONLYDIR); |
|
265 | + if ($admin_screens) { |
|
266 | + foreach ($admin_screens as $admin_screen) { |
|
267 | 267 | // files and anything in the exclude array need not apply |
268 | - if ( is_dir( $admin_screen ) && ! in_array( basename( $admin_screen ), $exclude )) { |
|
268 | + if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
269 | 269 | // these folders represent the different EE admin pages |
270 | - $installed_refs[ basename( $admin_screen ) ] = $admin_screen; |
|
270 | + $installed_refs[basename($admin_screen)] = $admin_screen; |
|
271 | 271 | } |
272 | 272 | } |
273 | 273 | } |
274 | 274 | |
275 | - if ( empty( $installed_refs ) ) { |
|
275 | + if (empty($installed_refs)) { |
|
276 | 276 | $error_msg[] = __('There are no EE_Admin pages detected, it looks like EE did not install properly', 'event_espresso'); |
277 | - $error_msg[] = $error_msg[0] . "\r\n" . sprintf( __('Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', 'event_espresso'), EE_ADMIN_PAGES ); |
|
278 | - throw new EE_Error( implode( '||', $error_msg )); |
|
277 | + $error_msg[] = $error_msg[0]."\r\n".sprintf(__('Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', 'event_espresso'), EE_ADMIN_PAGES); |
|
278 | + throw new EE_Error(implode('||', $error_msg)); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | //this just checks the caffeinated folder and takes care of setting up any caffeinated stuff. |
282 | 282 | $installed_refs = $this->_set_caffeinated($installed_refs); |
283 | 283 | //allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.; |
284 | - $installed_refs = apply_filters( 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', $installed_refs ); |
|
285 | - $this->_caffeinated_extends = apply_filters( 'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends', $this->_caffeinated_extends ); |
|
284 | + $installed_refs = apply_filters('FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', $installed_refs); |
|
285 | + $this->_caffeinated_extends = apply_filters('FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends', $this->_caffeinated_extends); |
|
286 | 286 | |
287 | 287 | //loop through admin pages and setup the $_installed_pages array. |
288 | 288 | $hooks_ref = array(); |
289 | - foreach ( $installed_refs as $page => $path ) { |
|
289 | + foreach ($installed_refs as $page => $path) { |
|
290 | 290 | // set autoloaders for our admin page classes based on included path information |
291 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder( $path ); |
|
291 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path); |
|
292 | 292 | // build list of installed pages |
293 | - $this->_installed_pages[$page] = $this->_load_admin_page( $page, $path ); |
|
293 | + $this->_installed_pages[$page] = $this->_load_admin_page($page, $path); |
|
294 | 294 | // verify returned object |
295 | - if ( $this->_installed_pages[$page] instanceof EE_Admin_Page_Init ) { |
|
296 | - if ( ! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map ) { |
|
295 | + if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
296 | + if ( ! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
297 | 297 | continue; |
298 | 298 | } |
299 | 299 | |
300 | 300 | //skip if in full maintenance mode and maintenance_mode_parent is set |
301 | 301 | $maintenance_mode_parent = $this->_installed_pages[$page]->get_menu_map()->maintenance_mode_parent; |
302 | - if ( empty( $maintenance_mode_parent ) && EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance ) { |
|
303 | - unset( $installed_refs[$page] ); |
|
302 | + if (empty($maintenance_mode_parent) && EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
303 | + unset($installed_refs[$page]); |
|
304 | 304 | continue; |
305 | 305 | } |
306 | 306 | |
@@ -308,45 +308,45 @@ discard block |
||
308 | 308 | //flag for register hooks on extended pages b/c extended pages use the default INIT. |
309 | 309 | $extend = FALSE; |
310 | 310 | //now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals. If there are then let's hook into the init admin filter and load our extend instead. |
311 | - if ( isset( $this->_caffeinated_extends[$page] ) ) { |
|
311 | + if (isset($this->_caffeinated_extends[$page])) { |
|
312 | 312 | $this->_current_caf_extend_slug = $page; |
313 | - $path_hook = 'FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__' . $this->_installed_pages[$page]->get_menu_map()->menu_slug . '_' . $this->_installed_pages[$page]->get_admin_page_name(); |
|
314 | - $path_runtime = 'return "' . $this->_caffeinated_extends[$this->_current_caf_extend_slug]["path"] . '";'; |
|
315 | - $page_hook = 'FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__' . $this->_installed_pages[$page]->get_menu_map()->menu_slug . '_' . $this->_installed_pages[$page]->get_admin_page_name(); |
|
316 | - $page_runtime = 'return "' . $this->_caffeinated_extends[$this->_current_caf_extend_slug]["admin_page"] . '";'; |
|
313 | + $path_hook = 'FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__'.$this->_installed_pages[$page]->get_menu_map()->menu_slug.'_'.$this->_installed_pages[$page]->get_admin_page_name(); |
|
314 | + $path_runtime = 'return "'.$this->_caffeinated_extends[$this->_current_caf_extend_slug]["path"].'";'; |
|
315 | + $page_hook = 'FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__'.$this->_installed_pages[$page]->get_menu_map()->menu_slug.'_'.$this->_installed_pages[$page]->get_admin_page_name(); |
|
316 | + $page_runtime = 'return "'.$this->_caffeinated_extends[$this->_current_caf_extend_slug]["admin_page"].'";'; |
|
317 | 317 | |
318 | - $hook_function_path = create_function( '$path_to_file', $path_runtime); |
|
319 | - $hook_function_page = create_function( '$admin_page', $page_runtime ); |
|
318 | + $hook_function_path = create_function('$path_to_file', $path_runtime); |
|
319 | + $hook_function_page = create_function('$admin_page', $page_runtime); |
|
320 | 320 | |
321 | - add_filter( $path_hook, $hook_function_path ); |
|
322 | - add_filter( $page_hook, $hook_function_page ); |
|
321 | + add_filter($path_hook, $hook_function_path); |
|
322 | + add_filter($page_hook, $hook_function_page); |
|
323 | 323 | $extend = TRUE; |
324 | 324 | } |
325 | 325 | //let's do the registered hooks |
326 | - $extended_hooks = $this->_installed_pages[$page]->register_hooks( $extend ); |
|
326 | + $extended_hooks = $this->_installed_pages[$page]->register_hooks($extend); |
|
327 | 327 | $hooks_ref = array_merge($hooks_ref, $extended_hooks); |
328 | 328 | } |
329 | 329 | } |
330 | 330 | |
331 | 331 | //the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder. So we want to make sure we load the file for the parent. |
332 | 332 | //first make sure we've got unique values |
333 | - $hooks_ref = array_unique( $hooks_ref ); |
|
333 | + $hooks_ref = array_unique($hooks_ref); |
|
334 | 334 | //now let's loop and require! |
335 | - foreach ( $hooks_ref as $path ) { |
|
336 | - require_once( $path ); |
|
335 | + foreach ($hooks_ref as $path) { |
|
336 | + require_once($path); |
|
337 | 337 | } |
338 | 338 | //make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested. |
339 | 339 | global $ee_menu_slugs; |
340 | 340 | $ee_menu_slugs = $this->_menu_slugs; |
341 | 341 | |
342 | 342 | //we need to loop again to run any early code |
343 | - foreach ( $installed_refs as $page => $path ) { |
|
344 | - if ( $this->_installed_pages[$page] instanceof EE_Admin_Page_Init ) { |
|
343 | + foreach ($installed_refs as $page => $path) { |
|
344 | + if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
345 | 345 | $this->_installed_pages[$page]->do_initial_loads(); |
346 | 346 | } |
347 | 347 | } |
348 | 348 | |
349 | - do_action( 'AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages ); |
|
349 | + do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages); |
|
350 | 350 | |
351 | 351 | } |
352 | 352 | |
@@ -358,9 +358,9 @@ discard block |
||
358 | 358 | * @param string $page_slug |
359 | 359 | * @return EE_Admin_Page |
360 | 360 | */ |
361 | - public function get_admin_page_object( $page_slug = '' ) { |
|
362 | - if ( isset( $this->_installed_pages[ $page_slug ] )) { |
|
363 | - return $this->_installed_pages[ $page_slug ]->loaded_page_object(); |
|
361 | + public function get_admin_page_object($page_slug = '') { |
|
362 | + if (isset($this->_installed_pages[$page_slug])) { |
|
363 | + return $this->_installed_pages[$page_slug]->loaded_page_object(); |
|
364 | 364 | } |
365 | 365 | return NULL; |
366 | 366 | } |
@@ -373,9 +373,9 @@ discard block |
||
373 | 373 | * @param $dir_name |
374 | 374 | * @return string |
375 | 375 | */ |
376 | - private function _get_classname_for_admin_page( $dir_name = '' ) { |
|
377 | - $class_name = str_replace( '_', ' ', strtolower( $dir_name )); |
|
378 | - return str_replace( ' ', '_', ucwords( $class_name )) . '_Admin_Page'; |
|
376 | + private function _get_classname_for_admin_page($dir_name = '') { |
|
377 | + $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
378 | + return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page'; |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | |
@@ -386,9 +386,9 @@ discard block |
||
386 | 386 | * @param $dir_name |
387 | 387 | * @return string |
388 | 388 | */ |
389 | - private function _get_classname_for_admin_init_page( $dir_name = '' ) { |
|
390 | - $class_name = str_replace( '_', ' ', strtolower( $dir_name )); |
|
391 | - return str_replace( ' ', '_', ucwords( $class_name )) . '_Admin_Page_Init'; |
|
389 | + private function _get_classname_for_admin_init_page($dir_name = '') { |
|
390 | + $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
391 | + return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page_Init'; |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | |
@@ -401,26 +401,26 @@ discard block |
||
401 | 401 | * @throws EE_Error |
402 | 402 | * @return object|bool return page object if valid, bool false if not. |
403 | 403 | */ |
404 | - private function _load_admin_page( $page = '', $path = '' ) { |
|
405 | - $class_name = $this->_get_classname_for_admin_init_page( $page ); |
|
406 | - EE_Registry::instance()->load_file( $path, $class_name, 'core' ); |
|
407 | - if ( ! class_exists( $class_name )) { |
|
408 | - $inner_error_msg = '<br />' . sprintf( |
|
404 | + private function _load_admin_page($page = '', $path = '') { |
|
405 | + $class_name = $this->_get_classname_for_admin_init_page($page); |
|
406 | + EE_Registry::instance()->load_file($path, $class_name, 'core'); |
|
407 | + if ( ! class_exists($class_name)) { |
|
408 | + $inner_error_msg = '<br />'.sprintf( |
|
409 | 409 | esc_html__( |
410 | 410 | 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
411 | 411 | 'event_espresso' |
412 | 412 | ), |
413 | - '<strong>' . $class_name . '</strong>' |
|
413 | + '<strong>'.$class_name.'</strong>' |
|
414 | 414 | ); |
415 | - $error_msg[] = sprintf( __('Something went wrong with loading the %s admin page.', 'event_espresso' ), $page); |
|
415 | + $error_msg[] = sprintf(__('Something went wrong with loading the %s admin page.', 'event_espresso'), $page); |
|
416 | 416 | $error_msg[] = $error_msg[0] |
417 | 417 | . "\r\n" |
418 | 418 | . sprintf( |
419 | - esc_html__( 'There is no Init class in place for the %s admin page.', 'event_espresso'), |
|
419 | + esc_html__('There is no Init class in place for the %s admin page.', 'event_espresso'), |
|
420 | 420 | $page |
421 | 421 | ) |
422 | 422 | . $inner_error_msg; |
423 | - throw new EE_Error( implode( '||', $error_msg )); |
|
423 | + throw new EE_Error(implode('||', $error_msg)); |
|
424 | 424 | } |
425 | 425 | $a = new ReflectionClass($class_name); |
426 | 426 | return $a->newInstance(); |
@@ -439,9 +439,9 @@ discard block |
||
439 | 439 | public function set_menus() { |
440 | 440 | //prep the menu pages (sort, group.) |
441 | 441 | $this->_prep_pages(); |
442 | - foreach( $this->_prepped_menu_maps as $menu_map ) { |
|
443 | - if ( EE_Registry::instance()->CAP->current_user_can( $menu_map->capability, $menu_map->menu_slug ) ) { |
|
444 | - $menu_map->add_menu_page( FALSE ); |
|
442 | + foreach ($this->_prepped_menu_maps as $menu_map) { |
|
443 | + if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
444 | + $menu_map->add_menu_page(FALSE); |
|
445 | 445 | } |
446 | 446 | } |
447 | 447 | } |
@@ -454,11 +454,11 @@ discard block |
||
454 | 454 | * |
455 | 455 | * @return void |
456 | 456 | */ |
457 | - public function set_network_menus(){ |
|
457 | + public function set_network_menus() { |
|
458 | 458 | $this->_prep_pages(); |
459 | - foreach( $this->_prepped_menu_maps as $menu_map ) { |
|
460 | - if ( EE_Registry::instance()->CAP->current_user_can( $menu_map->capability, $menu_map->menu_slug ) ) { |
|
461 | - $menu_map->add_menu_page( TRUE ); |
|
459 | + foreach ($this->_prepped_menu_maps as $menu_map) { |
|
460 | + if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
461 | + $menu_map->add_menu_page(TRUE); |
|
462 | 462 | } |
463 | 463 | } |
464 | 464 | } |
@@ -480,13 +480,13 @@ discard block |
||
480 | 480 | //rearrange _admin_menu_groups to be indexed by group slug. |
481 | 481 | $menu_groups = $this->_rearrange_menu_groups(); |
482 | 482 | |
483 | - foreach( $this->_installed_pages as $page ) { |
|
484 | - if ( $page instanceof EE_Admin_page_Init ) { |
|
483 | + foreach ($this->_installed_pages as $page) { |
|
484 | + if ($page instanceof EE_Admin_page_Init) { |
|
485 | 485 | $page_map = $page->get_menu_map(); |
486 | 486 | //if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
487 | - if ( is_array( $page_map ) || empty( $page_map ) ) { |
|
487 | + if (is_array($page_map) || empty($page_map)) { |
|
488 | 488 | new PersistentAdminNotice( |
489 | - 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
489 | + 'menu_map_warning_'.str_replace(' ', '_', $page->label).'_'.EVENT_ESPRESSO_VERSION, |
|
490 | 490 | sprintf( |
491 | 491 | __( |
492 | 492 | 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
@@ -499,12 +499,12 @@ discard block |
||
499 | 499 | } |
500 | 500 | |
501 | 501 | //if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
502 | - if ( ! $page_map instanceof EE_Admin_Page_Menu_Map ) { |
|
503 | - throw new EE_Error( sprintf( __('The menu map for %s must be an EE_Admin_Page_Menu_Map object. Instead it is %s. Please double check that the menu map has been configured correctly.', 'event_espresso'), $page->label, $page_map ) ); |
|
502 | + if ( ! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
503 | + throw new EE_Error(sprintf(__('The menu map for %s must be an EE_Admin_Page_Menu_Map object. Instead it is %s. Please double check that the menu map has been configured correctly.', 'event_espresso'), $page->label, $page_map)); |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | //use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array. |
507 | - if ( empty( $page_map->maintenance_mode_parent ) && EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance ) { |
|
507 | + if (empty($page_map->maintenance_mode_parent) && EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
508 | 508 | continue; |
509 | 509 | } |
510 | 510 | |
@@ -513,21 +513,21 @@ discard block |
||
513 | 513 | } |
514 | 514 | } |
515 | 515 | |
516 | - if ( empty( $pages_array )) { |
|
517 | - throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso') ); |
|
516 | + if (empty($pages_array)) { |
|
517 | + throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso')); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | //let's sort the groups, make sure it's a valid group, add header (if to show). |
521 | - foreach ( $pages_array as $group => $menu_maps ) { |
|
521 | + foreach ($pages_array as $group => $menu_maps) { |
|
522 | 522 | //valid_group? |
523 | - if ( ! array_key_exists( $group, $menu_groups ) ) |
|
523 | + if ( ! array_key_exists($group, $menu_groups)) |
|
524 | 524 | continue; |
525 | 525 | |
526 | 526 | //sort pages. |
527 | - usort( $menu_maps, array( $this, '_sort_menu_maps' ) ); |
|
527 | + usort($menu_maps, array($this, '_sort_menu_maps')); |
|
528 | 528 | |
529 | 529 | //prepend header |
530 | - array_unshift( $menu_maps, $menu_groups[$group] ); |
|
530 | + array_unshift($menu_maps, $menu_groups[$group]); |
|
531 | 531 | |
532 | 532 | //reset $pages_array with prepped data |
533 | 533 | $pages_array[$group] = $menu_maps; |
@@ -535,9 +535,9 @@ discard block |
||
535 | 535 | |
536 | 536 | |
537 | 537 | //now let's setup the _prepped_menu_maps property |
538 | - foreach ( $menu_groups as $group => $group_objs ) { |
|
539 | - if ( isset( $pages_array[$group] ) ) |
|
540 | - $this->_prepped_menu_maps = array_merge( $this->_prepped_menu_maps, $pages_array[$group] ); |
|
538 | + foreach ($menu_groups as $group => $group_objs) { |
|
539 | + if (isset($pages_array[$group])) |
|
540 | + $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[$group]); |
|
541 | 541 | }/**/ |
542 | 542 | |
543 | 543 | } |
@@ -557,10 +557,10 @@ discard block |
||
557 | 557 | * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be loaded. |
558 | 558 | * @return array |
559 | 559 | */ |
560 | - private function _set_caffeinated( $installed_refs ) { |
|
560 | + private function _set_caffeinated($installed_refs) { |
|
561 | 561 | |
562 | 562 | //first let's check if there IS a caffeinated folder. If there is not then lets get out. |
563 | - if ( ! is_dir( EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin' ) || ( defined( 'EE_DECAF' ) && EE_DECAF )) { |
|
563 | + if ( ! is_dir(EE_PLUGIN_DIR_PATH.'caffeinated'.DS.'admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
564 | 564 | return $installed_refs; |
565 | 565 | } |
566 | 566 | |
@@ -569,15 +569,15 @@ discard block |
||
569 | 569 | $exclude = array('tickets'); |
570 | 570 | |
571 | 571 | //okay let's setup an "New" pages first (we'll return installed refs later) |
572 | - $new_admin_screens = glob( EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR ); |
|
573 | - if ( $new_admin_screens ) { |
|
574 | - foreach( $new_admin_screens as $admin_screen ) { |
|
572 | + $new_admin_screens = glob(EE_CORE_CAF_ADMIN.'new/*', GLOB_ONLYDIR); |
|
573 | + if ($new_admin_screens) { |
|
574 | + foreach ($new_admin_screens as $admin_screen) { |
|
575 | 575 | // files and anything in the exclude array need not apply |
576 | - if ( is_dir( $admin_screen ) && ! in_array( basename( $admin_screen ), $exclude )) { |
|
576 | + if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
577 | 577 | // these folders represent the different NEW EE admin pages |
578 | - $installed_refs[ basename( $admin_screen ) ] = $admin_screen; |
|
578 | + $installed_refs[basename($admin_screen)] = $admin_screen; |
|
579 | 579 | // set autoloaders for our admin page classes based on included path information |
580 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder( $admin_screen ); |
|
580 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen); |
|
581 | 581 | // $this->_caf_autoloader[] = array( |
582 | 582 | // 'dir' => 'new', |
583 | 583 | // 'folder' => basename( $admin_screen ) |
@@ -587,18 +587,18 @@ discard block |
||
587 | 587 | } |
588 | 588 | |
589 | 589 | //let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
590 | - $extends = glob( EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR ); |
|
591 | - if ( $extends ) { |
|
592 | - foreach( $extends as $extend ) { |
|
593 | - if ( is_dir( $extend ) ) { |
|
594 | - $extend_ref = basename( $extend ); |
|
590 | + $extends = glob(EE_CORE_CAF_ADMIN.'extend/*', GLOB_ONLYDIR); |
|
591 | + if ($extends) { |
|
592 | + foreach ($extends as $extend) { |
|
593 | + if (is_dir($extend)) { |
|
594 | + $extend_ref = basename($extend); |
|
595 | 595 | //now let's make sure there is a file that matches the expected format |
596 | - $filename = str_replace(' ', '_', ucwords( str_replace('_', ' ', $extend_ref ) ) ); |
|
597 | - $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
598 | - $this->_caffeinated_extends[$extend_ref]['path'] = str_replace( array( '\\', '/' ), DS, EE_CORE_CAF_ADMIN . 'extend' . DS . $extend_ref . DS . $filename . '.core.php' ); |
|
596 | + $filename = str_replace(' ', '_', ucwords(str_replace('_', ' ', $extend_ref))); |
|
597 | + $filename = 'Extend_'.$filename.'_Admin_Page'; |
|
598 | + $this->_caffeinated_extends[$extend_ref]['path'] = str_replace(array('\\', '/'), DS, EE_CORE_CAF_ADMIN.'extend'.DS.$extend_ref.DS.$filename.'.core.php'); |
|
599 | 599 | $this->_caffeinated_extends[$extend_ref]['admin_page'] = $filename; |
600 | 600 | // set autoloaders for our admin page classes based on included path information |
601 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder( $extend ); |
|
601 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend); |
|
602 | 602 | // $this->_caf_autoloader[] = array( |
603 | 603 | // 'dir' => 'extend', |
604 | 604 | // 'folder' => $extend_ref |
@@ -609,22 +609,22 @@ discard block |
||
609 | 609 | |
610 | 610 | //let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
611 | 611 | $ee_admin_hooks = array(); |
612 | - $hooks = glob( EE_CORE_CAF_ADMIN . 'hooks/*.class.php' ); |
|
613 | - if ( $hooks ) { |
|
614 | - foreach ( $hooks as $hook ) { |
|
615 | - if ( is_readable( $hook ) ) { |
|
612 | + $hooks = glob(EE_CORE_CAF_ADMIN.'hooks/*.class.php'); |
|
613 | + if ($hooks) { |
|
614 | + foreach ($hooks as $hook) { |
|
615 | + if (is_readable($hook)) { |
|
616 | 616 | require_once $hook; |
617 | - $classname = str_replace( EE_CORE_CAF_ADMIN . 'hooks/', '', $hook ); |
|
617 | + $classname = str_replace(EE_CORE_CAF_ADMIN.'hooks/', '', $hook); |
|
618 | 618 | $classname = str_replace('.class.php', '', $classname); |
619 | - if ( class_exists( $classname ) ) { |
|
620 | - $a = new ReflectionClass( $classname ); |
|
619 | + if (class_exists($classname)) { |
|
620 | + $a = new ReflectionClass($classname); |
|
621 | 621 | $ee_admin_hooks[] = $a->newInstance(); |
622 | 622 | } |
623 | 623 | } |
624 | 624 | } |
625 | 625 | }/**/ |
626 | 626 | |
627 | - $ee_admin_hooks = apply_filters( 'FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks ); |
|
627 | + $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks); |
|
628 | 628 | |
629 | 629 | return $installed_refs; |
630 | 630 | |
@@ -679,8 +679,8 @@ discard block |
||
679 | 679 | * @param EE_Admin_Page_Menu_Map $b being compared to |
680 | 680 | * @return int sort order |
681 | 681 | */ |
682 | - private function _sort_menu_maps( EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b ) { |
|
683 | - if ( $a->menu_order == $b->menu_order ) |
|
682 | + private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b) { |
|
683 | + if ($a->menu_order == $b->menu_order) |
|
684 | 684 | return 0; |
685 | 685 | return ($a->menu_order < $b->menu_order) ? -1 : 1; |
686 | 686 | } |
@@ -2,8 +2,9 @@ discard block |
||
2 | 2 | use EventEspresso\core\domain\entities\notifications\PersistentAdminNotice; |
3 | 3 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
4 | 4 | |
5 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
5 | +if (!defined('EVENT_ESPRESSO_VERSION') ) { |
|
6 | 6 | exit('NO direct script access allowed'); |
7 | +} |
|
7 | 8 | |
8 | 9 | /** |
9 | 10 | * Event Espresso |
@@ -240,8 +241,9 @@ discard block |
||
240 | 241 | //first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
241 | 242 | usort( $this->_admin_menu_groups, array( $this, '_sort_menu_maps' ) ); |
242 | 243 | foreach ( $this->_admin_menu_groups as $group ) { |
243 | - if ( ! $group instanceof EE_Admin_Page_Menu_Group ) |
|
244 | - throw new EE_Error( sprintf( __('Unable to continue sorting the menu groups array because there is an invalid value for the menu groups. All values in this array are required to be a EE_Admin_Page_Menu_Group object. Instead there was: %s', 'event_espresso'), print_r($group, TRUE) ) ); |
|
244 | + if ( ! $group instanceof EE_Admin_Page_Menu_Group ) { |
|
245 | + throw new EE_Error( sprintf( __('Unable to continue sorting the menu groups array because there is an invalid value for the menu groups. All values in this array are required to be a EE_Admin_Page_Menu_Group object. Instead there was: %s', 'event_espresso'), print_r($group, TRUE) ) ); |
|
246 | + } |
|
245 | 247 | $groups[$group->menu_slug] = $group; |
246 | 248 | } |
247 | 249 | return $groups; |
@@ -520,8 +522,9 @@ discard block |
||
520 | 522 | //let's sort the groups, make sure it's a valid group, add header (if to show). |
521 | 523 | foreach ( $pages_array as $group => $menu_maps ) { |
522 | 524 | //valid_group? |
523 | - if ( ! array_key_exists( $group, $menu_groups ) ) |
|
524 | - continue; |
|
525 | + if ( ! array_key_exists( $group, $menu_groups ) ) { |
|
526 | + continue; |
|
527 | + } |
|
525 | 528 | |
526 | 529 | //sort pages. |
527 | 530 | usort( $menu_maps, array( $this, '_sort_menu_maps' ) ); |
@@ -536,8 +539,9 @@ discard block |
||
536 | 539 | |
537 | 540 | //now let's setup the _prepped_menu_maps property |
538 | 541 | foreach ( $menu_groups as $group => $group_objs ) { |
539 | - if ( isset( $pages_array[$group] ) ) |
|
540 | - $this->_prepped_menu_maps = array_merge( $this->_prepped_menu_maps, $pages_array[$group] ); |
|
542 | + if ( isset( $pages_array[$group] ) ) { |
|
543 | + $this->_prepped_menu_maps = array_merge( $this->_prepped_menu_maps, $pages_array[$group] ); |
|
544 | + } |
|
541 | 545 | }/**/ |
542 | 546 | |
543 | 547 | } |
@@ -680,8 +684,9 @@ discard block |
||
680 | 684 | * @return int sort order |
681 | 685 | */ |
682 | 686 | private function _sort_menu_maps( EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b ) { |
683 | - if ( $a->menu_order == $b->menu_order ) |
|
684 | - return 0; |
|
687 | + if ( $a->menu_order == $b->menu_order ) { |
|
688 | + return 0; |
|
689 | + } |
|
685 | 690 | return ($a->menu_order < $b->menu_order) ? -1 : 1; |
686 | 691 | } |
687 | 692 |