@@ -15,94 +15,94 @@ |
||
15 | 15 | */ |
16 | 16 | class LicenseService |
17 | 17 | { |
18 | - /** |
|
19 | - * @var Config |
|
20 | - */ |
|
21 | - private $config; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * @var Stats |
|
26 | - */ |
|
27 | - private $stats_collection; |
|
28 | - |
|
29 | - public function __construct(Stats $stats_collection, Config $config) |
|
30 | - { |
|
31 | - $this->config = $config; |
|
32 | - $this->stats_collection = $stats_collection; |
|
33 | - $this->loadPueClient(); |
|
34 | - } |
|
35 | - |
|
36 | - private function loadPueClient() |
|
37 | - { |
|
38 | - // PUE Auto Upgrades stuff |
|
39 | - if (is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) { // include the file |
|
40 | - require_once(EE_THIRD_PARTY . 'pue/pue-client.php'); |
|
41 | - |
|
42 | - // $options needs to be an array with the included keys as listed. |
|
43 | - $options = array( |
|
44 | - // 'optionName' => '', //(optional) - used as the reference for saving update information in the |
|
45 | - // clients options table. Will be automatically set if left blank. |
|
46 | - 'apikey' => $this->config->siteLicenseKey(), |
|
47 | - // (required), you will need to obtain the apikey that the client gets from your site and |
|
48 | - // then saves in their sites options table (see 'getting an api-key' below) |
|
49 | - 'lang_domain' => $this->config->i18nDomain(), |
|
50 | - // (optional) - put here whatever reference you are using for the localization of your plugin (if it's |
|
51 | - // localized). That way strings in this file will be included in the translation for your plugin. |
|
52 | - 'checkPeriod' => $this->config->checkPeriod(), |
|
53 | - // (optional) - use this parameter to indicate how often you want the client's install to ping your |
|
54 | - // server for update checks. The integer indicates hours. If you don't include this parameter it will |
|
55 | - // default to 12 hours. |
|
56 | - 'option_key' => $this->config->optionKey(), |
|
57 | - // this is what is used to reference the api_key in your plugin options. PUE uses this to trigger |
|
58 | - // updating your information message whenever this option_key is modified. |
|
59 | - 'options_page_slug' => $this->config->optionsPageSlug(), |
|
60 | - 'plugin_basename' => EE_PLUGIN_BASENAME, |
|
61 | - 'use_wp_update' => true, |
|
62 | - // if TRUE then you want FREE versions of the plugin to be updated from WP |
|
63 | - 'extra_stats' => $this->stats_collection->statsCallback(), |
|
64 | - 'turn_on_notices_saved' => true, |
|
65 | - ); |
|
66 | - // initiate the class and start the plugin update engine! |
|
67 | - new PluginUpdateEngineChecker( |
|
68 | - $this->config->hostServerUrl(), |
|
69 | - $this->config->pluginSlug(), |
|
70 | - $options |
|
71 | - ); |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * This is a handy helper method for retrieving whether there is an update available for the given plugin. |
|
78 | - * |
|
79 | - * @param string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to |
|
80 | - * identify plugins. Defaults to core update |
|
81 | - * @return boolean True if update available, false if not. |
|
82 | - */ |
|
83 | - public static function isUpdateAvailable($basename = '') |
|
84 | - { |
|
85 | - $basename = ! empty($basename) ? $basename : EE_PLUGIN_BASENAME; |
|
86 | - |
|
87 | - $update = false; |
|
88 | - |
|
89 | - // should take "event-espresso-core/espresso.php" and change to "/event-espresso-core" |
|
90 | - $folder = '/' . dirname($basename); |
|
91 | - |
|
92 | - $plugins = get_plugins($folder); |
|
93 | - $current = get_site_transient('update_plugins'); |
|
94 | - |
|
95 | - foreach ((array) $plugins as $plugin_file => $plugin_data) { |
|
96 | - if (isset($current->response['plugin_file'])) { |
|
97 | - $update = true; |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - // it's possible that there is an update but an invalid site-license-key is in use |
|
102 | - if (get_site_option('pue_json_error_' . $basename)) { |
|
103 | - $update = true; |
|
104 | - } |
|
105 | - |
|
106 | - return $update; |
|
107 | - } |
|
18 | + /** |
|
19 | + * @var Config |
|
20 | + */ |
|
21 | + private $config; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * @var Stats |
|
26 | + */ |
|
27 | + private $stats_collection; |
|
28 | + |
|
29 | + public function __construct(Stats $stats_collection, Config $config) |
|
30 | + { |
|
31 | + $this->config = $config; |
|
32 | + $this->stats_collection = $stats_collection; |
|
33 | + $this->loadPueClient(); |
|
34 | + } |
|
35 | + |
|
36 | + private function loadPueClient() |
|
37 | + { |
|
38 | + // PUE Auto Upgrades stuff |
|
39 | + if (is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) { // include the file |
|
40 | + require_once(EE_THIRD_PARTY . 'pue/pue-client.php'); |
|
41 | + |
|
42 | + // $options needs to be an array with the included keys as listed. |
|
43 | + $options = array( |
|
44 | + // 'optionName' => '', //(optional) - used as the reference for saving update information in the |
|
45 | + // clients options table. Will be automatically set if left blank. |
|
46 | + 'apikey' => $this->config->siteLicenseKey(), |
|
47 | + // (required), you will need to obtain the apikey that the client gets from your site and |
|
48 | + // then saves in their sites options table (see 'getting an api-key' below) |
|
49 | + 'lang_domain' => $this->config->i18nDomain(), |
|
50 | + // (optional) - put here whatever reference you are using for the localization of your plugin (if it's |
|
51 | + // localized). That way strings in this file will be included in the translation for your plugin. |
|
52 | + 'checkPeriod' => $this->config->checkPeriod(), |
|
53 | + // (optional) - use this parameter to indicate how often you want the client's install to ping your |
|
54 | + // server for update checks. The integer indicates hours. If you don't include this parameter it will |
|
55 | + // default to 12 hours. |
|
56 | + 'option_key' => $this->config->optionKey(), |
|
57 | + // this is what is used to reference the api_key in your plugin options. PUE uses this to trigger |
|
58 | + // updating your information message whenever this option_key is modified. |
|
59 | + 'options_page_slug' => $this->config->optionsPageSlug(), |
|
60 | + 'plugin_basename' => EE_PLUGIN_BASENAME, |
|
61 | + 'use_wp_update' => true, |
|
62 | + // if TRUE then you want FREE versions of the plugin to be updated from WP |
|
63 | + 'extra_stats' => $this->stats_collection->statsCallback(), |
|
64 | + 'turn_on_notices_saved' => true, |
|
65 | + ); |
|
66 | + // initiate the class and start the plugin update engine! |
|
67 | + new PluginUpdateEngineChecker( |
|
68 | + $this->config->hostServerUrl(), |
|
69 | + $this->config->pluginSlug(), |
|
70 | + $options |
|
71 | + ); |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * This is a handy helper method for retrieving whether there is an update available for the given plugin. |
|
78 | + * |
|
79 | + * @param string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to |
|
80 | + * identify plugins. Defaults to core update |
|
81 | + * @return boolean True if update available, false if not. |
|
82 | + */ |
|
83 | + public static function isUpdateAvailable($basename = '') |
|
84 | + { |
|
85 | + $basename = ! empty($basename) ? $basename : EE_PLUGIN_BASENAME; |
|
86 | + |
|
87 | + $update = false; |
|
88 | + |
|
89 | + // should take "event-espresso-core/espresso.php" and change to "/event-espresso-core" |
|
90 | + $folder = '/' . dirname($basename); |
|
91 | + |
|
92 | + $plugins = get_plugins($folder); |
|
93 | + $current = get_site_transient('update_plugins'); |
|
94 | + |
|
95 | + foreach ((array) $plugins as $plugin_file => $plugin_data) { |
|
96 | + if (isset($current->response['plugin_file'])) { |
|
97 | + $update = true; |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + // it's possible that there is an update but an invalid site-license-key is in use |
|
102 | + if (get_site_option('pue_json_error_' . $basename)) { |
|
103 | + $update = true; |
|
104 | + } |
|
105 | + |
|
106 | + return $update; |
|
107 | + } |
|
108 | 108 | } |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | private function loadPueClient() |
37 | 37 | { |
38 | 38 | // PUE Auto Upgrades stuff |
39 | - if (is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) { // include the file |
|
40 | - require_once(EE_THIRD_PARTY . 'pue/pue-client.php'); |
|
39 | + if (is_readable(EE_THIRD_PARTY.'pue/pue-client.php')) { // include the file |
|
40 | + require_once(EE_THIRD_PARTY.'pue/pue-client.php'); |
|
41 | 41 | |
42 | 42 | // $options needs to be an array with the included keys as listed. |
43 | 43 | $options = array( |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $update = false; |
88 | 88 | |
89 | 89 | // should take "event-espresso-core/espresso.php" and change to "/event-espresso-core" |
90 | - $folder = '/' . dirname($basename); |
|
90 | + $folder = '/'.dirname($basename); |
|
91 | 91 | |
92 | 92 | $plugins = get_plugins($folder); |
93 | 93 | $current = get_site_transient('update_plugins'); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | } |
100 | 100 | |
101 | 101 | // it's possible that there is an update but an invalid site-license-key is in use |
102 | - if (get_site_option('pue_json_error_' . $basename)) { |
|
102 | + if (get_site_option('pue_json_error_'.$basename)) { |
|
103 | 103 | $update = true; |
104 | 104 | } |
105 | 105 |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function setReturnUrl($return_url) |
87 | 87 | { |
88 | - if (! is_string($return_url)) { |
|
88 | + if ( ! is_string($return_url)) { |
|
89 | 89 | throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
90 | 90 | } |
91 | 91 | $this->return_url = $return_url; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | protected function getPersistentAdminNoticeCollection() |
104 | 104 | { |
105 | - if (! $this->notice_collection instanceof Collection) { |
|
105 | + if ( ! $this->notice_collection instanceof Collection) { |
|
106 | 106 | $this->notice_collection = new Collection( |
107 | 107 | 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
108 | 108 | ); |
@@ -125,10 +125,10 @@ discard block |
||
125 | 125 | protected function retrieveStoredNotices() |
126 | 126 | { |
127 | 127 | $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
128 | - if (! empty($persistent_admin_notices)) { |
|
128 | + if ( ! empty($persistent_admin_notices)) { |
|
129 | 129 | foreach ($persistent_admin_notices as $name => $details) { |
130 | 130 | if (is_array($details)) { |
131 | - if (! isset( |
|
131 | + if ( ! isset( |
|
132 | 132 | $details['message'], |
133 | 133 | $details['capability'], |
134 | 134 | $details['cap_context'], |
@@ -245,14 +245,14 @@ discard block |
||
245 | 245 | { |
246 | 246 | wp_register_script( |
247 | 247 | 'espresso_core', |
248 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
248 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
249 | 249 | array('jquery'), |
250 | 250 | EVENT_ESPRESSO_VERSION, |
251 | 251 | true |
252 | 252 | ); |
253 | 253 | wp_register_script( |
254 | 254 | 'ee_error_js', |
255 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
255 | + EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', |
|
256 | 256 | array('espresso_core'), |
257 | 257 | EVENT_ESPRESSO_VERSION, |
258 | 258 | true |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | // used in template |
284 | 284 | $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
285 | 285 | $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
286 | - require EE_TEMPLATES . '/notifications/persistent_admin_notice.template.php'; |
|
286 | + require EE_TEMPLATES.'/notifications/persistent_admin_notice.template.php'; |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | { |
309 | 309 | $pan_name = $this->request->getRequestParam('ee_nag_notice', $pan_name); |
310 | 310 | $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
311 | - if (! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
311 | + if ( ! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
312 | 312 | /** @var PersistentAdminNotice $persistent_admin_notice */ |
313 | 313 | $persistent_admin_notice = $this->notice_collection->get($pan_name); |
314 | 314 | $persistent_admin_notice->setDismissed(true); |
@@ -358,10 +358,10 @@ discard block |
||
358 | 358 | foreach ($this->notice_collection as $persistent_admin_notice) { |
359 | 359 | // are we deleting this notice ? |
360 | 360 | if ($persistent_admin_notice->getPurge()) { |
361 | - unset($persistent_admin_notices[ $persistent_admin_notice->getName() ]); |
|
361 | + unset($persistent_admin_notices[$persistent_admin_notice->getName()]); |
|
362 | 362 | } else { |
363 | 363 | /** @var PersistentAdminNotice $persistent_admin_notice */ |
364 | - $persistent_admin_notices[ $persistent_admin_notice->getName() ] = array( |
|
364 | + $persistent_admin_notices[$persistent_admin_notice->getName()] = array( |
|
365 | 365 | 'message' => $persistent_admin_notice->getMessage(), |
366 | 366 | 'capability' => $persistent_admin_notice->getCapability(), |
367 | 367 | 'cap_context' => $persistent_admin_notice->getCapContext(), |
@@ -31,387 +31,387 @@ |
||
31 | 31 | class PersistentAdminNoticeManager |
32 | 32 | { |
33 | 33 | |
34 | - const WP_OPTION_KEY = 'ee_pers_admin_notices'; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var Collection|PersistentAdminNotice[] $notice_collection |
|
38 | - */ |
|
39 | - private $notice_collection; |
|
40 | - |
|
41 | - /** |
|
42 | - * if AJAX is not enabled, then the return URL will be used for redirecting back to the admin page where the |
|
43 | - * persistent admin notice was displayed, and ultimately dismissed from. |
|
44 | - * |
|
45 | - * @var string $return_url |
|
46 | - */ |
|
47 | - private $return_url; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var CapabilitiesChecker $capabilities_checker |
|
51 | - */ |
|
52 | - private $capabilities_checker; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var RequestInterface $request |
|
56 | - */ |
|
57 | - private $request; |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * PersistentAdminNoticeManager constructor |
|
62 | - * |
|
63 | - * @param string $return_url where to redirect to after dismissing notices |
|
64 | - * @param CapabilitiesChecker $capabilities_checker |
|
65 | - * @param RequestInterface $request |
|
66 | - * @throws InvalidDataTypeException |
|
67 | - */ |
|
68 | - public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, RequestInterface $request) |
|
69 | - { |
|
70 | - $this->setReturnUrl($return_url); |
|
71 | - $this->capabilities_checker = $capabilities_checker; |
|
72 | - $this->request = $request; |
|
73 | - // setup up notices at priority 9 because `EE_Admin::display_admin_notices()` runs at priority 10, |
|
74 | - // and we want to retrieve and generate any nag notices at the last possible moment |
|
75 | - add_action('admin_notices', array($this, 'displayNotices'), 9); |
|
76 | - add_action('network_admin_notices', array($this, 'displayNotices'), 9); |
|
77 | - add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice')); |
|
78 | - add_action('shutdown', array($this, 'registerAndSaveNotices'), 998); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @param string $return_url |
|
84 | - * @throws InvalidDataTypeException |
|
85 | - */ |
|
86 | - public function setReturnUrl($return_url) |
|
87 | - { |
|
88 | - if (! is_string($return_url)) { |
|
89 | - throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
|
90 | - } |
|
91 | - $this->return_url = $return_url; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @return Collection |
|
97 | - * @throws InvalidEntityException |
|
98 | - * @throws InvalidInterfaceException |
|
99 | - * @throws InvalidDataTypeException |
|
100 | - * @throws DomainException |
|
101 | - * @throws DuplicateCollectionIdentifierException |
|
102 | - */ |
|
103 | - protected function getPersistentAdminNoticeCollection() |
|
104 | - { |
|
105 | - if (! $this->notice_collection instanceof Collection) { |
|
106 | - $this->notice_collection = new Collection( |
|
107 | - 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
108 | - ); |
|
109 | - $this->retrieveStoredNotices(); |
|
110 | - $this->registerNotices(); |
|
111 | - } |
|
112 | - return $this->notice_collection; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db |
|
118 | - * |
|
119 | - * @return void |
|
120 | - * @throws InvalidEntityException |
|
121 | - * @throws DomainException |
|
122 | - * @throws InvalidDataTypeException |
|
123 | - * @throws DuplicateCollectionIdentifierException |
|
124 | - */ |
|
125 | - protected function retrieveStoredNotices() |
|
126 | - { |
|
127 | - $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
128 | - if (! empty($persistent_admin_notices)) { |
|
129 | - foreach ($persistent_admin_notices as $name => $details) { |
|
130 | - if (is_array($details)) { |
|
131 | - if (! isset( |
|
132 | - $details['message'], |
|
133 | - $details['capability'], |
|
134 | - $details['cap_context'], |
|
135 | - $details['dismissed'] |
|
136 | - )) { |
|
137 | - throw new DomainException( |
|
138 | - sprintf( |
|
139 | - esc_html__( |
|
140 | - 'The "%1$s" PersistentAdminNotice could not be retrieved from the database.', |
|
141 | - 'event_espresso' |
|
142 | - ), |
|
143 | - $name |
|
144 | - ) |
|
145 | - ); |
|
146 | - } |
|
147 | - // new format for nag notices |
|
148 | - $this->notice_collection->add( |
|
149 | - new PersistentAdminNotice( |
|
150 | - $name, |
|
151 | - $details['message'], |
|
152 | - false, |
|
153 | - $details['capability'], |
|
154 | - $details['cap_context'], |
|
155 | - $details['dismissed'] |
|
156 | - ), |
|
157 | - sanitize_key($name) |
|
158 | - ); |
|
159 | - } else { |
|
160 | - try { |
|
161 | - // old nag notices, that we want to convert to the new format |
|
162 | - $this->notice_collection->add( |
|
163 | - new PersistentAdminNotice( |
|
164 | - $name, |
|
165 | - (string) $details, |
|
166 | - false, |
|
167 | - '', |
|
168 | - '', |
|
169 | - empty($details) |
|
170 | - ), |
|
171 | - sanitize_key($name) |
|
172 | - ); |
|
173 | - } catch (Exception $e) { |
|
174 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
175 | - } |
|
176 | - } |
|
177 | - // each notice will self register when the action hook in registerNotices is triggered |
|
178 | - } |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * exposes the Persistent Admin Notice Collection via an action |
|
185 | - * so that PersistentAdminNotice objects can be added and/or removed |
|
186 | - * without compromising the actual collection like a filter would |
|
187 | - */ |
|
188 | - protected function registerNotices() |
|
189 | - { |
|
190 | - do_action( |
|
191 | - 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
192 | - $this->notice_collection |
|
193 | - ); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @throws DomainException |
|
199 | - * @throws InvalidClassException |
|
200 | - * @throws InvalidDataTypeException |
|
201 | - * @throws InvalidInterfaceException |
|
202 | - * @throws InvalidEntityException |
|
203 | - * @throws DuplicateCollectionIdentifierException |
|
204 | - */ |
|
205 | - public function displayNotices() |
|
206 | - { |
|
207 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
208 | - if ($this->notice_collection->hasObjects()) { |
|
209 | - $enqueue_assets = false; |
|
210 | - // and display notices |
|
211 | - foreach ($this->notice_collection as $persistent_admin_notice) { |
|
212 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
213 | - // don't display notices that have already been dismissed |
|
214 | - if ($persistent_admin_notice->getDismissed()) { |
|
215 | - continue; |
|
216 | - } |
|
217 | - try { |
|
218 | - $this->capabilities_checker->processCapCheck( |
|
219 | - $persistent_admin_notice->getCapCheck() |
|
220 | - ); |
|
221 | - } catch (InsufficientPermissionsException $e) { |
|
222 | - // user does not have required cap, so skip to next notice |
|
223 | - // and just eat the exception - nom nom nom nom |
|
224 | - continue; |
|
225 | - } |
|
226 | - if ($persistent_admin_notice->getMessage() === '') { |
|
227 | - continue; |
|
228 | - } |
|
229 | - $this->displayPersistentAdminNotice($persistent_admin_notice); |
|
230 | - $enqueue_assets = true; |
|
231 | - } |
|
232 | - if ($enqueue_assets) { |
|
233 | - $this->enqueueAssets(); |
|
234 | - } |
|
235 | - } |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * does what it's named |
|
241 | - * |
|
242 | - * @return void |
|
243 | - */ |
|
244 | - public function enqueueAssets() |
|
245 | - { |
|
246 | - wp_register_script( |
|
247 | - 'espresso_core', |
|
248 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
249 | - array('jquery'), |
|
250 | - EVENT_ESPRESSO_VERSION, |
|
251 | - true |
|
252 | - ); |
|
253 | - wp_register_script( |
|
254 | - 'ee_error_js', |
|
255 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
256 | - array('espresso_core'), |
|
257 | - EVENT_ESPRESSO_VERSION, |
|
258 | - true |
|
259 | - ); |
|
260 | - wp_localize_script( |
|
261 | - 'ee_error_js', |
|
262 | - 'ee_dismiss', |
|
263 | - array( |
|
264 | - 'return_url' => urlencode($this->return_url), |
|
265 | - 'ajax_url' => WP_AJAX_URL, |
|
266 | - 'unknown_error' => wp_strip_all_tags( |
|
267 | - __( |
|
268 | - 'An unknown error has occurred on the server while attempting to dismiss this notice.', |
|
269 | - 'event_espresso' |
|
270 | - ) |
|
271 | - ), |
|
272 | - ) |
|
273 | - ); |
|
274 | - wp_enqueue_script('ee_error_js'); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * displayPersistentAdminNoticeHtml |
|
280 | - * |
|
281 | - * @param PersistentAdminNotice $persistent_admin_notice |
|
282 | - */ |
|
283 | - protected function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice) |
|
284 | - { |
|
285 | - // used in template |
|
286 | - $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
|
287 | - $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
|
288 | - require EE_TEMPLATES . '/notifications/persistent_admin_notice.template.php'; |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * dismissNotice |
|
294 | - * |
|
295 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
296 | - * @param bool $purge if true, then delete it from the db |
|
297 | - * @param bool $return forget all of this AJAX or redirect nonsense, and just return |
|
298 | - * @return void |
|
299 | - * @throws InvalidEntityException |
|
300 | - * @throws InvalidInterfaceException |
|
301 | - * @throws InvalidDataTypeException |
|
302 | - * @throws DomainException |
|
303 | - * @throws InvalidArgumentException |
|
304 | - * @throws InvalidArgumentException |
|
305 | - * @throws InvalidArgumentException |
|
306 | - * @throws InvalidArgumentException |
|
307 | - * @throws DuplicateCollectionIdentifierException |
|
308 | - */ |
|
309 | - public function dismissNotice($pan_name = '', $purge = false, $return = false) |
|
310 | - { |
|
311 | - $pan_name = $this->request->getRequestParam('ee_nag_notice', $pan_name); |
|
312 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
313 | - if (! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
314 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
315 | - $persistent_admin_notice = $this->notice_collection->get($pan_name); |
|
316 | - $persistent_admin_notice->setDismissed(true); |
|
317 | - $persistent_admin_notice->setPurge($purge); |
|
318 | - $this->saveNotices(); |
|
319 | - } |
|
320 | - if ($return) { |
|
321 | - return; |
|
322 | - } |
|
323 | - if ($this->request->isAjax()) { |
|
324 | - // grab any notices and concatenate into string |
|
325 | - echo wp_json_encode( |
|
326 | - array( |
|
327 | - 'errors' => implode('<br />', EE_Error::get_notices(false)), |
|
328 | - ) |
|
329 | - ); |
|
330 | - exit(); |
|
331 | - } |
|
332 | - // save errors to a transient to be displayed on next request (after redirect) |
|
333 | - EE_Error::get_notices(false, true); |
|
334 | - wp_safe_redirect( |
|
335 | - urldecode( |
|
336 | - $this->request->getRequestParam('return_url', '') |
|
337 | - ) |
|
338 | - ); |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * saveNotices |
|
344 | - * |
|
345 | - * @throws DomainException |
|
346 | - * @throws InvalidDataTypeException |
|
347 | - * @throws InvalidInterfaceException |
|
348 | - * @throws InvalidEntityException |
|
349 | - * @throws DuplicateCollectionIdentifierException |
|
350 | - */ |
|
351 | - public function saveNotices() |
|
352 | - { |
|
353 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
354 | - if ($this->notice_collection->hasObjects()) { |
|
355 | - $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
356 | - // maybe initialize persistent_admin_notices |
|
357 | - if (empty($persistent_admin_notices)) { |
|
358 | - add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no'); |
|
359 | - } |
|
360 | - foreach ($this->notice_collection as $persistent_admin_notice) { |
|
361 | - // are we deleting this notice ? |
|
362 | - if ($persistent_admin_notice->getPurge()) { |
|
363 | - unset($persistent_admin_notices[ $persistent_admin_notice->getName() ]); |
|
364 | - } else { |
|
365 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
366 | - $persistent_admin_notices[ $persistent_admin_notice->getName() ] = array( |
|
367 | - 'message' => $persistent_admin_notice->getMessage(), |
|
368 | - 'capability' => $persistent_admin_notice->getCapability(), |
|
369 | - 'cap_context' => $persistent_admin_notice->getCapContext(), |
|
370 | - 'dismissed' => $persistent_admin_notice->getDismissed(), |
|
371 | - ); |
|
372 | - } |
|
373 | - } |
|
374 | - update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices); |
|
375 | - } |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * @throws DomainException |
|
381 | - * @throws InvalidDataTypeException |
|
382 | - * @throws InvalidEntityException |
|
383 | - * @throws InvalidInterfaceException |
|
384 | - * @throws DuplicateCollectionIdentifierException |
|
385 | - */ |
|
386 | - public function registerAndSaveNotices() |
|
387 | - { |
|
388 | - $this->getPersistentAdminNoticeCollection(); |
|
389 | - $this->registerNotices(); |
|
390 | - $this->saveNotices(); |
|
391 | - add_filter( |
|
392 | - 'PersistentAdminNoticeManager__registerAndSaveNotices__complete', |
|
393 | - '__return_true' |
|
394 | - ); |
|
395 | - } |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * @throws DomainException |
|
400 | - * @throws InvalidDataTypeException |
|
401 | - * @throws InvalidEntityException |
|
402 | - * @throws InvalidInterfaceException |
|
403 | - * @throws InvalidArgumentException |
|
404 | - * @throws DuplicateCollectionIdentifierException |
|
405 | - */ |
|
406 | - public static function loadRegisterAndSaveNotices() |
|
407 | - { |
|
408 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
409 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
410 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
411 | - ); |
|
412 | - // if shutdown has already run, then call registerAndSaveNotices() manually |
|
413 | - if (did_action('shutdown')) { |
|
414 | - $persistent_admin_notice_manager->registerAndSaveNotices(); |
|
415 | - } |
|
416 | - } |
|
34 | + const WP_OPTION_KEY = 'ee_pers_admin_notices'; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var Collection|PersistentAdminNotice[] $notice_collection |
|
38 | + */ |
|
39 | + private $notice_collection; |
|
40 | + |
|
41 | + /** |
|
42 | + * if AJAX is not enabled, then the return URL will be used for redirecting back to the admin page where the |
|
43 | + * persistent admin notice was displayed, and ultimately dismissed from. |
|
44 | + * |
|
45 | + * @var string $return_url |
|
46 | + */ |
|
47 | + private $return_url; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var CapabilitiesChecker $capabilities_checker |
|
51 | + */ |
|
52 | + private $capabilities_checker; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var RequestInterface $request |
|
56 | + */ |
|
57 | + private $request; |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * PersistentAdminNoticeManager constructor |
|
62 | + * |
|
63 | + * @param string $return_url where to redirect to after dismissing notices |
|
64 | + * @param CapabilitiesChecker $capabilities_checker |
|
65 | + * @param RequestInterface $request |
|
66 | + * @throws InvalidDataTypeException |
|
67 | + */ |
|
68 | + public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, RequestInterface $request) |
|
69 | + { |
|
70 | + $this->setReturnUrl($return_url); |
|
71 | + $this->capabilities_checker = $capabilities_checker; |
|
72 | + $this->request = $request; |
|
73 | + // setup up notices at priority 9 because `EE_Admin::display_admin_notices()` runs at priority 10, |
|
74 | + // and we want to retrieve and generate any nag notices at the last possible moment |
|
75 | + add_action('admin_notices', array($this, 'displayNotices'), 9); |
|
76 | + add_action('network_admin_notices', array($this, 'displayNotices'), 9); |
|
77 | + add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice')); |
|
78 | + add_action('shutdown', array($this, 'registerAndSaveNotices'), 998); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @param string $return_url |
|
84 | + * @throws InvalidDataTypeException |
|
85 | + */ |
|
86 | + public function setReturnUrl($return_url) |
|
87 | + { |
|
88 | + if (! is_string($return_url)) { |
|
89 | + throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
|
90 | + } |
|
91 | + $this->return_url = $return_url; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @return Collection |
|
97 | + * @throws InvalidEntityException |
|
98 | + * @throws InvalidInterfaceException |
|
99 | + * @throws InvalidDataTypeException |
|
100 | + * @throws DomainException |
|
101 | + * @throws DuplicateCollectionIdentifierException |
|
102 | + */ |
|
103 | + protected function getPersistentAdminNoticeCollection() |
|
104 | + { |
|
105 | + if (! $this->notice_collection instanceof Collection) { |
|
106 | + $this->notice_collection = new Collection( |
|
107 | + 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
108 | + ); |
|
109 | + $this->retrieveStoredNotices(); |
|
110 | + $this->registerNotices(); |
|
111 | + } |
|
112 | + return $this->notice_collection; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db |
|
118 | + * |
|
119 | + * @return void |
|
120 | + * @throws InvalidEntityException |
|
121 | + * @throws DomainException |
|
122 | + * @throws InvalidDataTypeException |
|
123 | + * @throws DuplicateCollectionIdentifierException |
|
124 | + */ |
|
125 | + protected function retrieveStoredNotices() |
|
126 | + { |
|
127 | + $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
128 | + if (! empty($persistent_admin_notices)) { |
|
129 | + foreach ($persistent_admin_notices as $name => $details) { |
|
130 | + if (is_array($details)) { |
|
131 | + if (! isset( |
|
132 | + $details['message'], |
|
133 | + $details['capability'], |
|
134 | + $details['cap_context'], |
|
135 | + $details['dismissed'] |
|
136 | + )) { |
|
137 | + throw new DomainException( |
|
138 | + sprintf( |
|
139 | + esc_html__( |
|
140 | + 'The "%1$s" PersistentAdminNotice could not be retrieved from the database.', |
|
141 | + 'event_espresso' |
|
142 | + ), |
|
143 | + $name |
|
144 | + ) |
|
145 | + ); |
|
146 | + } |
|
147 | + // new format for nag notices |
|
148 | + $this->notice_collection->add( |
|
149 | + new PersistentAdminNotice( |
|
150 | + $name, |
|
151 | + $details['message'], |
|
152 | + false, |
|
153 | + $details['capability'], |
|
154 | + $details['cap_context'], |
|
155 | + $details['dismissed'] |
|
156 | + ), |
|
157 | + sanitize_key($name) |
|
158 | + ); |
|
159 | + } else { |
|
160 | + try { |
|
161 | + // old nag notices, that we want to convert to the new format |
|
162 | + $this->notice_collection->add( |
|
163 | + new PersistentAdminNotice( |
|
164 | + $name, |
|
165 | + (string) $details, |
|
166 | + false, |
|
167 | + '', |
|
168 | + '', |
|
169 | + empty($details) |
|
170 | + ), |
|
171 | + sanitize_key($name) |
|
172 | + ); |
|
173 | + } catch (Exception $e) { |
|
174 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
175 | + } |
|
176 | + } |
|
177 | + // each notice will self register when the action hook in registerNotices is triggered |
|
178 | + } |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * exposes the Persistent Admin Notice Collection via an action |
|
185 | + * so that PersistentAdminNotice objects can be added and/or removed |
|
186 | + * without compromising the actual collection like a filter would |
|
187 | + */ |
|
188 | + protected function registerNotices() |
|
189 | + { |
|
190 | + do_action( |
|
191 | + 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
192 | + $this->notice_collection |
|
193 | + ); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @throws DomainException |
|
199 | + * @throws InvalidClassException |
|
200 | + * @throws InvalidDataTypeException |
|
201 | + * @throws InvalidInterfaceException |
|
202 | + * @throws InvalidEntityException |
|
203 | + * @throws DuplicateCollectionIdentifierException |
|
204 | + */ |
|
205 | + public function displayNotices() |
|
206 | + { |
|
207 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
208 | + if ($this->notice_collection->hasObjects()) { |
|
209 | + $enqueue_assets = false; |
|
210 | + // and display notices |
|
211 | + foreach ($this->notice_collection as $persistent_admin_notice) { |
|
212 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
213 | + // don't display notices that have already been dismissed |
|
214 | + if ($persistent_admin_notice->getDismissed()) { |
|
215 | + continue; |
|
216 | + } |
|
217 | + try { |
|
218 | + $this->capabilities_checker->processCapCheck( |
|
219 | + $persistent_admin_notice->getCapCheck() |
|
220 | + ); |
|
221 | + } catch (InsufficientPermissionsException $e) { |
|
222 | + // user does not have required cap, so skip to next notice |
|
223 | + // and just eat the exception - nom nom nom nom |
|
224 | + continue; |
|
225 | + } |
|
226 | + if ($persistent_admin_notice->getMessage() === '') { |
|
227 | + continue; |
|
228 | + } |
|
229 | + $this->displayPersistentAdminNotice($persistent_admin_notice); |
|
230 | + $enqueue_assets = true; |
|
231 | + } |
|
232 | + if ($enqueue_assets) { |
|
233 | + $this->enqueueAssets(); |
|
234 | + } |
|
235 | + } |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * does what it's named |
|
241 | + * |
|
242 | + * @return void |
|
243 | + */ |
|
244 | + public function enqueueAssets() |
|
245 | + { |
|
246 | + wp_register_script( |
|
247 | + 'espresso_core', |
|
248 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
249 | + array('jquery'), |
|
250 | + EVENT_ESPRESSO_VERSION, |
|
251 | + true |
|
252 | + ); |
|
253 | + wp_register_script( |
|
254 | + 'ee_error_js', |
|
255 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
256 | + array('espresso_core'), |
|
257 | + EVENT_ESPRESSO_VERSION, |
|
258 | + true |
|
259 | + ); |
|
260 | + wp_localize_script( |
|
261 | + 'ee_error_js', |
|
262 | + 'ee_dismiss', |
|
263 | + array( |
|
264 | + 'return_url' => urlencode($this->return_url), |
|
265 | + 'ajax_url' => WP_AJAX_URL, |
|
266 | + 'unknown_error' => wp_strip_all_tags( |
|
267 | + __( |
|
268 | + 'An unknown error has occurred on the server while attempting to dismiss this notice.', |
|
269 | + 'event_espresso' |
|
270 | + ) |
|
271 | + ), |
|
272 | + ) |
|
273 | + ); |
|
274 | + wp_enqueue_script('ee_error_js'); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * displayPersistentAdminNoticeHtml |
|
280 | + * |
|
281 | + * @param PersistentAdminNotice $persistent_admin_notice |
|
282 | + */ |
|
283 | + protected function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice) |
|
284 | + { |
|
285 | + // used in template |
|
286 | + $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
|
287 | + $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
|
288 | + require EE_TEMPLATES . '/notifications/persistent_admin_notice.template.php'; |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * dismissNotice |
|
294 | + * |
|
295 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
296 | + * @param bool $purge if true, then delete it from the db |
|
297 | + * @param bool $return forget all of this AJAX or redirect nonsense, and just return |
|
298 | + * @return void |
|
299 | + * @throws InvalidEntityException |
|
300 | + * @throws InvalidInterfaceException |
|
301 | + * @throws InvalidDataTypeException |
|
302 | + * @throws DomainException |
|
303 | + * @throws InvalidArgumentException |
|
304 | + * @throws InvalidArgumentException |
|
305 | + * @throws InvalidArgumentException |
|
306 | + * @throws InvalidArgumentException |
|
307 | + * @throws DuplicateCollectionIdentifierException |
|
308 | + */ |
|
309 | + public function dismissNotice($pan_name = '', $purge = false, $return = false) |
|
310 | + { |
|
311 | + $pan_name = $this->request->getRequestParam('ee_nag_notice', $pan_name); |
|
312 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
313 | + if (! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
314 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
315 | + $persistent_admin_notice = $this->notice_collection->get($pan_name); |
|
316 | + $persistent_admin_notice->setDismissed(true); |
|
317 | + $persistent_admin_notice->setPurge($purge); |
|
318 | + $this->saveNotices(); |
|
319 | + } |
|
320 | + if ($return) { |
|
321 | + return; |
|
322 | + } |
|
323 | + if ($this->request->isAjax()) { |
|
324 | + // grab any notices and concatenate into string |
|
325 | + echo wp_json_encode( |
|
326 | + array( |
|
327 | + 'errors' => implode('<br />', EE_Error::get_notices(false)), |
|
328 | + ) |
|
329 | + ); |
|
330 | + exit(); |
|
331 | + } |
|
332 | + // save errors to a transient to be displayed on next request (after redirect) |
|
333 | + EE_Error::get_notices(false, true); |
|
334 | + wp_safe_redirect( |
|
335 | + urldecode( |
|
336 | + $this->request->getRequestParam('return_url', '') |
|
337 | + ) |
|
338 | + ); |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * saveNotices |
|
344 | + * |
|
345 | + * @throws DomainException |
|
346 | + * @throws InvalidDataTypeException |
|
347 | + * @throws InvalidInterfaceException |
|
348 | + * @throws InvalidEntityException |
|
349 | + * @throws DuplicateCollectionIdentifierException |
|
350 | + */ |
|
351 | + public function saveNotices() |
|
352 | + { |
|
353 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
354 | + if ($this->notice_collection->hasObjects()) { |
|
355 | + $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
356 | + // maybe initialize persistent_admin_notices |
|
357 | + if (empty($persistent_admin_notices)) { |
|
358 | + add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no'); |
|
359 | + } |
|
360 | + foreach ($this->notice_collection as $persistent_admin_notice) { |
|
361 | + // are we deleting this notice ? |
|
362 | + if ($persistent_admin_notice->getPurge()) { |
|
363 | + unset($persistent_admin_notices[ $persistent_admin_notice->getName() ]); |
|
364 | + } else { |
|
365 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
366 | + $persistent_admin_notices[ $persistent_admin_notice->getName() ] = array( |
|
367 | + 'message' => $persistent_admin_notice->getMessage(), |
|
368 | + 'capability' => $persistent_admin_notice->getCapability(), |
|
369 | + 'cap_context' => $persistent_admin_notice->getCapContext(), |
|
370 | + 'dismissed' => $persistent_admin_notice->getDismissed(), |
|
371 | + ); |
|
372 | + } |
|
373 | + } |
|
374 | + update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices); |
|
375 | + } |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * @throws DomainException |
|
381 | + * @throws InvalidDataTypeException |
|
382 | + * @throws InvalidEntityException |
|
383 | + * @throws InvalidInterfaceException |
|
384 | + * @throws DuplicateCollectionIdentifierException |
|
385 | + */ |
|
386 | + public function registerAndSaveNotices() |
|
387 | + { |
|
388 | + $this->getPersistentAdminNoticeCollection(); |
|
389 | + $this->registerNotices(); |
|
390 | + $this->saveNotices(); |
|
391 | + add_filter( |
|
392 | + 'PersistentAdminNoticeManager__registerAndSaveNotices__complete', |
|
393 | + '__return_true' |
|
394 | + ); |
|
395 | + } |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * @throws DomainException |
|
400 | + * @throws InvalidDataTypeException |
|
401 | + * @throws InvalidEntityException |
|
402 | + * @throws InvalidInterfaceException |
|
403 | + * @throws InvalidArgumentException |
|
404 | + * @throws DuplicateCollectionIdentifierException |
|
405 | + */ |
|
406 | + public static function loadRegisterAndSaveNotices() |
|
407 | + { |
|
408 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
409 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
410 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
411 | + ); |
|
412 | + // if shutdown has already run, then call registerAndSaveNotices() manually |
|
413 | + if (did_action('shutdown')) { |
|
414 | + $persistent_admin_notice_manager->registerAndSaveNotices(); |
|
415 | + } |
|
416 | + } |
|
417 | 417 | } |
@@ -16,29 +16,29 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * used for setting up css and js required for the display strategy |
|
21 | - * |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - public function enqueueStylesAndScripts() |
|
25 | - { |
|
26 | - // core/services/progress_steps/display_strategies/number_bubbles/number_bubbles.css |
|
27 | - wp_enqueue_style( |
|
28 | - 'ee_progress_steps_display_number_bubbles', |
|
29 | - plugin_dir_url(__FILE__) . 'number_bubbles.css' |
|
30 | - ); |
|
31 | - } |
|
19 | + /** |
|
20 | + * used for setting up css and js required for the display strategy |
|
21 | + * |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + public function enqueueStylesAndScripts() |
|
25 | + { |
|
26 | + // core/services/progress_steps/display_strategies/number_bubbles/number_bubbles.css |
|
27 | + wp_enqueue_style( |
|
28 | + 'ee_progress_steps_display_number_bubbles', |
|
29 | + plugin_dir_url(__FILE__) . 'number_bubbles.css' |
|
30 | + ); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * loads and returns a full server path to the template used for the display strategy |
|
36 | - * |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - public function getTemplate() |
|
40 | - { |
|
41 | - // return plugin_dir_path( __FILE__ ) . 'number_bubbles.template.php'; |
|
42 | - return __DIR__ . '/number_bubbles.template.php'; |
|
43 | - } |
|
34 | + /** |
|
35 | + * loads and returns a full server path to the template used for the display strategy |
|
36 | + * |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + public function getTemplate() |
|
40 | + { |
|
41 | + // return plugin_dir_path( __FILE__ ) . 'number_bubbles.template.php'; |
|
42 | + return __DIR__ . '/number_bubbles.template.php'; |
|
43 | + } |
|
44 | 44 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | // core/services/progress_steps/display_strategies/number_bubbles/number_bubbles.css |
27 | 27 | wp_enqueue_style( |
28 | 28 | 'ee_progress_steps_display_number_bubbles', |
29 | - plugin_dir_url(__FILE__) . 'number_bubbles.css' |
|
29 | + plugin_dir_url(__FILE__).'number_bubbles.css' |
|
30 | 30 | ); |
31 | 31 | } |
32 | 32 | |
@@ -39,6 +39,6 @@ discard block |
||
39 | 39 | public function getTemplate() |
40 | 40 | { |
41 | 41 | // return plugin_dir_path( __FILE__ ) . 'number_bubbles.template.php'; |
42 | - return __DIR__ . '/number_bubbles.template.php'; |
|
42 | + return __DIR__.'/number_bubbles.template.php'; |
|
43 | 43 | } |
44 | 44 | } |
@@ -21,409 +21,409 @@ |
||
21 | 21 | class LegacyShortcodesManager |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var EE_Registry $registry |
|
26 | - */ |
|
27 | - private $registry; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * LegacyShortcodesManager constructor. |
|
32 | - * |
|
33 | - * @param \EE_Registry $registry |
|
34 | - */ |
|
35 | - public function __construct(EE_Registry $registry) |
|
36 | - { |
|
37 | - $this->registry = $registry; |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * @return EE_Registry |
|
43 | - */ |
|
44 | - public function registry() |
|
45 | - { |
|
46 | - return $this->registry; |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * registerShortcodes |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function registerShortcodes() |
|
56 | - { |
|
57 | - $this->registry->shortcodes = $this->getShortcodes(); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * getShortcodes |
|
63 | - * |
|
64 | - * @return array |
|
65 | - */ |
|
66 | - public function getShortcodes() |
|
67 | - { |
|
68 | - // previously this method would glob the shortcodes directory |
|
69 | - // then filter that list of shortcodes to register, |
|
70 | - // but now we are going to just supply an empty array. |
|
71 | - // this allows any shortcodes that have not yet been converted to the new system |
|
72 | - // to still get loaded and processed, albeit using the same legacy logic as before |
|
73 | - $shortcodes_to_register = apply_filters( |
|
74 | - 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
75 | - array() |
|
76 | - ); |
|
77 | - if (! empty($shortcodes_to_register)) { |
|
78 | - // cycle thru shortcode folders |
|
79 | - foreach ($shortcodes_to_register as $shortcode_path) { |
|
80 | - // add to list of installed shortcode modules |
|
81 | - $this->registerShortcode($shortcode_path); |
|
82 | - } |
|
83 | - } |
|
84 | - // filter list of installed modules |
|
85 | - return apply_filters( |
|
86 | - 'FHEE__EE_Config___register_shortcodes__installed_shortcodes', |
|
87 | - ! empty($this->registry->shortcodes) |
|
88 | - ? $this->registry->shortcodes |
|
89 | - : array() |
|
90 | - ); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * register_shortcode - makes core aware of this shortcode |
|
96 | - * |
|
97 | - * @access public |
|
98 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
99 | - * @return bool |
|
100 | - */ |
|
101 | - public function registerShortcode($shortcode_path = null) |
|
102 | - { |
|
103 | - do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path); |
|
104 | - $shortcode_ext = '.shortcode.php'; |
|
105 | - // make all separators match |
|
106 | - $shortcode_path = str_replace(array('\\', '/'), '/', $shortcode_path); |
|
107 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
108 | - if (strpos($shortcode_path, $shortcode_ext) !== false) { |
|
109 | - // grab shortcode file name from directory name and break apart at dots |
|
110 | - $shortcode_file = explode('.', basename($shortcode_path)); |
|
111 | - // take first segment from file name pieces and remove class prefix if it exists |
|
112 | - $shortcode = strpos($shortcode_file[0], 'EES_') === 0 |
|
113 | - ? substr($shortcode_file[0], 4) |
|
114 | - : $shortcode_file[0]; |
|
115 | - // sanitize shortcode directory name |
|
116 | - $shortcode = sanitize_key($shortcode); |
|
117 | - // now we need to rebuild the shortcode path |
|
118 | - $shortcode_path = explode('/', $shortcode_path); |
|
119 | - // remove last segment |
|
120 | - array_pop($shortcode_path); |
|
121 | - // glue it back together |
|
122 | - $shortcode_path = implode('/', $shortcode_path) . '/'; |
|
123 | - } else { |
|
124 | - // we need to generate the filename based off of the folder name |
|
125 | - // grab and sanitize shortcode directory name |
|
126 | - $shortcode = sanitize_key(basename($shortcode_path)); |
|
127 | - $shortcode_path = rtrim($shortcode_path, '/') . '/'; |
|
128 | - } |
|
129 | - // create classname from shortcode directory or file name |
|
130 | - $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode))); |
|
131 | - // add class prefix |
|
132 | - $shortcode_class = 'EES_' . $shortcode; |
|
133 | - // does the shortcode exist ? |
|
134 | - if (! is_readable($shortcode_path . '/' . $shortcode_class . $shortcode_ext)) { |
|
135 | - $msg = sprintf( |
|
136 | - esc_html__( |
|
137 | - 'The requested %1$s shortcode file could not be found or is not readable due to file permissions. It should be in %2$s', |
|
138 | - 'event_espresso' |
|
139 | - ), |
|
140 | - $shortcode_class, |
|
141 | - $shortcode_path . '/' . $shortcode_class . $shortcode_ext |
|
142 | - ); |
|
143 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
144 | - return false; |
|
145 | - } |
|
146 | - // load the shortcode class file |
|
147 | - require_once($shortcode_path . $shortcode_class . $shortcode_ext); |
|
148 | - // verify that class exists |
|
149 | - if (! class_exists($shortcode_class)) { |
|
150 | - $msg = sprintf( |
|
151 | - esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'), |
|
152 | - $shortcode_class |
|
153 | - ); |
|
154 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
155 | - return false; |
|
156 | - } |
|
157 | - $shortcode = strtoupper($shortcode); |
|
158 | - // add to array of registered shortcodes |
|
159 | - $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext; |
|
160 | - return true; |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * _initialize_shortcodes |
|
166 | - * allow shortcodes to set hooks for the rest of the system |
|
167 | - * |
|
168 | - * @access private |
|
169 | - * @return void |
|
170 | - */ |
|
171 | - public function addShortcodes() |
|
172 | - { |
|
173 | - // cycle thru shortcode folders |
|
174 | - foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) { |
|
175 | - // add class prefix |
|
176 | - $shortcode_class = 'EES_' . $shortcode; |
|
177 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
178 | - // which set hooks ? |
|
179 | - if (is_admin()) { |
|
180 | - // fire immediately |
|
181 | - call_user_func(array($shortcode_class, 'set_hooks_admin')); |
|
182 | - } else { |
|
183 | - // delay until other systems are online |
|
184 | - add_action( |
|
185 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
186 | - array($shortcode_class, 'set_hooks') |
|
187 | - ); |
|
188 | - // convert classname to UPPERCASE and create WP shortcode. |
|
189 | - $shortcode_tag = strtoupper($shortcode); |
|
190 | - // but first check if the shortcode has already |
|
191 | - // been added before assigning 'fallback_shortcode_processor' |
|
192 | - if (! shortcode_exists($shortcode_tag)) { |
|
193 | - // NOTE: this shortcode declaration will get overridden if the shortcode |
|
194 | - // is successfully detected in the post content in initializeShortcode() |
|
195 | - add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor')); |
|
196 | - } |
|
197 | - } |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * callback for the WP "get_header" hook point |
|
204 | - * checks posts for EE shortcodes, and initializes them, |
|
205 | - * then toggles filter switch that loads core default assets |
|
206 | - * |
|
207 | - * @param \WP_Query $wp_query |
|
208 | - * @return void |
|
209 | - */ |
|
210 | - public function initializeShortcodes(WP_Query $wp_query) |
|
211 | - { |
|
212 | - if (empty($this->registry->shortcodes) || ! $wp_query->is_main_query() || is_admin()) { |
|
213 | - return; |
|
214 | - } |
|
215 | - global $wp; |
|
216 | - /** @var EE_Front_controller $Front_Controller */ |
|
217 | - $Front_Controller = $this->registry->load_core('Front_Controller', array(), false); |
|
218 | - do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $wp, $Front_Controller); |
|
219 | - $Front_Controller->Request_Handler()->set_request_vars(); |
|
220 | - // grab post_name from request |
|
221 | - $current_post = apply_filters( |
|
222 | - 'FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name', |
|
223 | - $Front_Controller->Request_Handler()->get('post_name') |
|
224 | - ); |
|
225 | - $show_on_front = get_option('show_on_front'); |
|
226 | - // if it's not set, then check if frontpage is blog |
|
227 | - if (empty($current_post)) { |
|
228 | - // yup.. this is the posts page, prepare to load all shortcode modules |
|
229 | - $current_post = 'posts'; |
|
230 | - // unless.. |
|
231 | - if ($show_on_front === 'page') { |
|
232 | - // some other page is set as the homepage |
|
233 | - $page_on_front = get_option('page_on_front'); |
|
234 | - if ($page_on_front) { |
|
235 | - // k now we need to find the post_name for this page |
|
236 | - global $wpdb; |
|
237 | - $page_on_front = $wpdb->get_var( |
|
238 | - $wpdb->prepare( |
|
239 | - "SELECT post_name from {$wpdb->posts} WHERE post_type='page' AND post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d", |
|
240 | - $page_on_front |
|
241 | - ) |
|
242 | - ); |
|
243 | - // set the current post slug to what it actually is |
|
244 | - $current_post = $page_on_front ? $page_on_front : $current_post; |
|
245 | - } |
|
246 | - } |
|
247 | - } |
|
248 | - // in case $current_post is hierarchical like: /parent-page/current-page |
|
249 | - $current_post = basename($current_post); |
|
250 | - if (// is current page/post the "blog" page ? |
|
251 | - $current_post === EE_Config::get_page_for_posts() |
|
252 | - // or are we on a category page? |
|
253 | - || ( |
|
254 | - is_array(term_exists($current_post, 'category')) |
|
255 | - || array_key_exists('category_name', $wp->query_vars) |
|
256 | - ) |
|
257 | - ) { |
|
258 | - // initialize all legacy shortcodes |
|
259 | - $load_assets = $this->parseContentForShortcodes('', true); |
|
260 | - } else { |
|
261 | - global $wpdb; |
|
262 | - $post_content = $wpdb->get_var( |
|
263 | - $wpdb->prepare( |
|
264 | - "SELECT post_content from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s", |
|
265 | - $current_post |
|
266 | - ) |
|
267 | - ); |
|
268 | - $load_assets = $this->parseContentForShortcodes($post_content); |
|
269 | - } |
|
270 | - if ($load_assets) { |
|
271 | - $this->registry->REQ->set_espresso_page(true); |
|
272 | - add_filter('FHEE_load_css', '__return_true'); |
|
273 | - add_filter('FHEE_load_js', '__return_true'); |
|
274 | - } |
|
275 | - do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $Front_Controller); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * checks supplied content against list of legacy shortcodes, |
|
281 | - * then initializes any found shortcodes, and returns true. |
|
282 | - * returns false if no shortcodes found. |
|
283 | - * |
|
284 | - * @param string $content |
|
285 | - * @param bool $load_all if true, then ALL active legacy shortcodes will be initialized |
|
286 | - * @return bool |
|
287 | - */ |
|
288 | - public function parseContentForShortcodes($content = '', $load_all = false) |
|
289 | - { |
|
290 | - $has_shortcode = false; |
|
291 | - foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) { |
|
292 | - if ($load_all || has_shortcode($content, $shortcode_class)) { |
|
293 | - // load up the shortcode |
|
294 | - $this->initializeShortcode($shortcode_class); |
|
295 | - $has_shortcode = true; |
|
296 | - } |
|
297 | - } |
|
298 | - return $has_shortcode; |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * given a shortcode name, will instantiate the shortcode and call it's run() method |
|
304 | - * |
|
305 | - * @param string $shortcode_class |
|
306 | - * @param WP $wp |
|
307 | - */ |
|
308 | - public function initializeShortcode($shortcode_class = '', WP $wp = null) |
|
309 | - { |
|
310 | - // don't do anything if shortcode is already initialized |
|
311 | - if (empty($this->registry->shortcodes->{$shortcode_class}) |
|
312 | - || ! is_string($this->registry->shortcodes->{$shortcode_class}) |
|
313 | - ) { |
|
314 | - return; |
|
315 | - } |
|
316 | - // let's pause to reflect on this... |
|
317 | - $sc_reflector = new ReflectionClass(LegacyShortcodesManager::addShortcodeClassPrefix($shortcode_class)); |
|
318 | - // ensure that class is actually a shortcode |
|
319 | - if (defined('WP_DEBUG') |
|
320 | - && WP_DEBUG === true |
|
321 | - && ! $sc_reflector->isSubclassOf('EES_Shortcode') |
|
322 | - ) { |
|
323 | - EE_Error::add_error( |
|
324 | - sprintf( |
|
325 | - esc_html__( |
|
326 | - 'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.', |
|
327 | - 'event_espresso' |
|
328 | - ), |
|
329 | - $shortcode_class |
|
330 | - ), |
|
331 | - __FILE__, |
|
332 | - __FUNCTION__, |
|
333 | - __LINE__ |
|
334 | - ); |
|
335 | - add_filter('FHEE_run_EE_the_content', '__return_true'); |
|
336 | - return; |
|
337 | - } |
|
338 | - global $wp; |
|
339 | - // and pass the request object to the run method |
|
340 | - $this->registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance(); |
|
341 | - // fire the shortcode class's run method, so that it can activate resources |
|
342 | - $this->registry->shortcodes->{$shortcode_class}->run($wp); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * get classname, remove EES_prefix, and convert to UPPERCASE |
|
348 | - * |
|
349 | - * @param string $class_name |
|
350 | - * @return string |
|
351 | - */ |
|
352 | - public static function generateShortcodeTagFromClassName($class_name) |
|
353 | - { |
|
354 | - return strtoupper(str_replace('EES_', '', $class_name)); |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * add EES_prefix and Capitalize words |
|
360 | - * |
|
361 | - * @param string $tag |
|
362 | - * @return string |
|
363 | - */ |
|
364 | - public static function generateShortcodeClassNameFromTag($tag) |
|
365 | - { |
|
366 | - // order of operation runs from inside to out |
|
367 | - // 5) maybe add prefix |
|
368 | - return LegacyShortcodesManager::addShortcodeClassPrefix( |
|
369 | - // 4) find spaces, replace with underscores |
|
370 | - str_replace( |
|
371 | - ' ', |
|
372 | - '_', |
|
373 | - // 3) capitalize first letter of each word |
|
374 | - ucwords( |
|
375 | - // 2) also change to lowercase so ucwords() will work |
|
376 | - strtolower( |
|
377 | - // 1) find underscores, replace with spaces so ucwords() will work |
|
378 | - str_replace( |
|
379 | - '_', |
|
380 | - ' ', |
|
381 | - $tag |
|
382 | - ) |
|
383 | - ) |
|
384 | - ) |
|
385 | - ) |
|
386 | - ); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * maybe add EES_prefix |
|
392 | - * |
|
393 | - * @param string $class_name |
|
394 | - * @return string |
|
395 | - */ |
|
396 | - public static function addShortcodeClassPrefix($class_name) |
|
397 | - { |
|
398 | - return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name; |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * @return array |
|
404 | - */ |
|
405 | - public function getEspressoShortcodeTags() |
|
406 | - { |
|
407 | - static $shortcode_tags = array(); |
|
408 | - if (empty($shortcode_tags)) { |
|
409 | - $shortcode_tags = array_keys((array) $this->registry->shortcodes); |
|
410 | - } |
|
411 | - return $shortcode_tags; |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * @param string $content |
|
417 | - * @return string |
|
418 | - */ |
|
419 | - public function doShortcode($content) |
|
420 | - { |
|
421 | - foreach ($this->getEspressoShortcodeTags() as $shortcode_tag) { |
|
422 | - if (strpos($content, $shortcode_tag) !== false) { |
|
423 | - $shortcode_class = LegacyShortcodesManager::generateShortcodeClassNameFromTag($shortcode_tag); |
|
424 | - $this->initializeShortcode($shortcode_class); |
|
425 | - } |
|
426 | - } |
|
427 | - return do_shortcode($content); |
|
428 | - } |
|
24 | + /** |
|
25 | + * @var EE_Registry $registry |
|
26 | + */ |
|
27 | + private $registry; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * LegacyShortcodesManager constructor. |
|
32 | + * |
|
33 | + * @param \EE_Registry $registry |
|
34 | + */ |
|
35 | + public function __construct(EE_Registry $registry) |
|
36 | + { |
|
37 | + $this->registry = $registry; |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * @return EE_Registry |
|
43 | + */ |
|
44 | + public function registry() |
|
45 | + { |
|
46 | + return $this->registry; |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * registerShortcodes |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function registerShortcodes() |
|
56 | + { |
|
57 | + $this->registry->shortcodes = $this->getShortcodes(); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * getShortcodes |
|
63 | + * |
|
64 | + * @return array |
|
65 | + */ |
|
66 | + public function getShortcodes() |
|
67 | + { |
|
68 | + // previously this method would glob the shortcodes directory |
|
69 | + // then filter that list of shortcodes to register, |
|
70 | + // but now we are going to just supply an empty array. |
|
71 | + // this allows any shortcodes that have not yet been converted to the new system |
|
72 | + // to still get loaded and processed, albeit using the same legacy logic as before |
|
73 | + $shortcodes_to_register = apply_filters( |
|
74 | + 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
75 | + array() |
|
76 | + ); |
|
77 | + if (! empty($shortcodes_to_register)) { |
|
78 | + // cycle thru shortcode folders |
|
79 | + foreach ($shortcodes_to_register as $shortcode_path) { |
|
80 | + // add to list of installed shortcode modules |
|
81 | + $this->registerShortcode($shortcode_path); |
|
82 | + } |
|
83 | + } |
|
84 | + // filter list of installed modules |
|
85 | + return apply_filters( |
|
86 | + 'FHEE__EE_Config___register_shortcodes__installed_shortcodes', |
|
87 | + ! empty($this->registry->shortcodes) |
|
88 | + ? $this->registry->shortcodes |
|
89 | + : array() |
|
90 | + ); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * register_shortcode - makes core aware of this shortcode |
|
96 | + * |
|
97 | + * @access public |
|
98 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
99 | + * @return bool |
|
100 | + */ |
|
101 | + public function registerShortcode($shortcode_path = null) |
|
102 | + { |
|
103 | + do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path); |
|
104 | + $shortcode_ext = '.shortcode.php'; |
|
105 | + // make all separators match |
|
106 | + $shortcode_path = str_replace(array('\\', '/'), '/', $shortcode_path); |
|
107 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
108 | + if (strpos($shortcode_path, $shortcode_ext) !== false) { |
|
109 | + // grab shortcode file name from directory name and break apart at dots |
|
110 | + $shortcode_file = explode('.', basename($shortcode_path)); |
|
111 | + // take first segment from file name pieces and remove class prefix if it exists |
|
112 | + $shortcode = strpos($shortcode_file[0], 'EES_') === 0 |
|
113 | + ? substr($shortcode_file[0], 4) |
|
114 | + : $shortcode_file[0]; |
|
115 | + // sanitize shortcode directory name |
|
116 | + $shortcode = sanitize_key($shortcode); |
|
117 | + // now we need to rebuild the shortcode path |
|
118 | + $shortcode_path = explode('/', $shortcode_path); |
|
119 | + // remove last segment |
|
120 | + array_pop($shortcode_path); |
|
121 | + // glue it back together |
|
122 | + $shortcode_path = implode('/', $shortcode_path) . '/'; |
|
123 | + } else { |
|
124 | + // we need to generate the filename based off of the folder name |
|
125 | + // grab and sanitize shortcode directory name |
|
126 | + $shortcode = sanitize_key(basename($shortcode_path)); |
|
127 | + $shortcode_path = rtrim($shortcode_path, '/') . '/'; |
|
128 | + } |
|
129 | + // create classname from shortcode directory or file name |
|
130 | + $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode))); |
|
131 | + // add class prefix |
|
132 | + $shortcode_class = 'EES_' . $shortcode; |
|
133 | + // does the shortcode exist ? |
|
134 | + if (! is_readable($shortcode_path . '/' . $shortcode_class . $shortcode_ext)) { |
|
135 | + $msg = sprintf( |
|
136 | + esc_html__( |
|
137 | + 'The requested %1$s shortcode file could not be found or is not readable due to file permissions. It should be in %2$s', |
|
138 | + 'event_espresso' |
|
139 | + ), |
|
140 | + $shortcode_class, |
|
141 | + $shortcode_path . '/' . $shortcode_class . $shortcode_ext |
|
142 | + ); |
|
143 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
144 | + return false; |
|
145 | + } |
|
146 | + // load the shortcode class file |
|
147 | + require_once($shortcode_path . $shortcode_class . $shortcode_ext); |
|
148 | + // verify that class exists |
|
149 | + if (! class_exists($shortcode_class)) { |
|
150 | + $msg = sprintf( |
|
151 | + esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'), |
|
152 | + $shortcode_class |
|
153 | + ); |
|
154 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
155 | + return false; |
|
156 | + } |
|
157 | + $shortcode = strtoupper($shortcode); |
|
158 | + // add to array of registered shortcodes |
|
159 | + $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext; |
|
160 | + return true; |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * _initialize_shortcodes |
|
166 | + * allow shortcodes to set hooks for the rest of the system |
|
167 | + * |
|
168 | + * @access private |
|
169 | + * @return void |
|
170 | + */ |
|
171 | + public function addShortcodes() |
|
172 | + { |
|
173 | + // cycle thru shortcode folders |
|
174 | + foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) { |
|
175 | + // add class prefix |
|
176 | + $shortcode_class = 'EES_' . $shortcode; |
|
177 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
178 | + // which set hooks ? |
|
179 | + if (is_admin()) { |
|
180 | + // fire immediately |
|
181 | + call_user_func(array($shortcode_class, 'set_hooks_admin')); |
|
182 | + } else { |
|
183 | + // delay until other systems are online |
|
184 | + add_action( |
|
185 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
186 | + array($shortcode_class, 'set_hooks') |
|
187 | + ); |
|
188 | + // convert classname to UPPERCASE and create WP shortcode. |
|
189 | + $shortcode_tag = strtoupper($shortcode); |
|
190 | + // but first check if the shortcode has already |
|
191 | + // been added before assigning 'fallback_shortcode_processor' |
|
192 | + if (! shortcode_exists($shortcode_tag)) { |
|
193 | + // NOTE: this shortcode declaration will get overridden if the shortcode |
|
194 | + // is successfully detected in the post content in initializeShortcode() |
|
195 | + add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor')); |
|
196 | + } |
|
197 | + } |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * callback for the WP "get_header" hook point |
|
204 | + * checks posts for EE shortcodes, and initializes them, |
|
205 | + * then toggles filter switch that loads core default assets |
|
206 | + * |
|
207 | + * @param \WP_Query $wp_query |
|
208 | + * @return void |
|
209 | + */ |
|
210 | + public function initializeShortcodes(WP_Query $wp_query) |
|
211 | + { |
|
212 | + if (empty($this->registry->shortcodes) || ! $wp_query->is_main_query() || is_admin()) { |
|
213 | + return; |
|
214 | + } |
|
215 | + global $wp; |
|
216 | + /** @var EE_Front_controller $Front_Controller */ |
|
217 | + $Front_Controller = $this->registry->load_core('Front_Controller', array(), false); |
|
218 | + do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $wp, $Front_Controller); |
|
219 | + $Front_Controller->Request_Handler()->set_request_vars(); |
|
220 | + // grab post_name from request |
|
221 | + $current_post = apply_filters( |
|
222 | + 'FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name', |
|
223 | + $Front_Controller->Request_Handler()->get('post_name') |
|
224 | + ); |
|
225 | + $show_on_front = get_option('show_on_front'); |
|
226 | + // if it's not set, then check if frontpage is blog |
|
227 | + if (empty($current_post)) { |
|
228 | + // yup.. this is the posts page, prepare to load all shortcode modules |
|
229 | + $current_post = 'posts'; |
|
230 | + // unless.. |
|
231 | + if ($show_on_front === 'page') { |
|
232 | + // some other page is set as the homepage |
|
233 | + $page_on_front = get_option('page_on_front'); |
|
234 | + if ($page_on_front) { |
|
235 | + // k now we need to find the post_name for this page |
|
236 | + global $wpdb; |
|
237 | + $page_on_front = $wpdb->get_var( |
|
238 | + $wpdb->prepare( |
|
239 | + "SELECT post_name from {$wpdb->posts} WHERE post_type='page' AND post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d", |
|
240 | + $page_on_front |
|
241 | + ) |
|
242 | + ); |
|
243 | + // set the current post slug to what it actually is |
|
244 | + $current_post = $page_on_front ? $page_on_front : $current_post; |
|
245 | + } |
|
246 | + } |
|
247 | + } |
|
248 | + // in case $current_post is hierarchical like: /parent-page/current-page |
|
249 | + $current_post = basename($current_post); |
|
250 | + if (// is current page/post the "blog" page ? |
|
251 | + $current_post === EE_Config::get_page_for_posts() |
|
252 | + // or are we on a category page? |
|
253 | + || ( |
|
254 | + is_array(term_exists($current_post, 'category')) |
|
255 | + || array_key_exists('category_name', $wp->query_vars) |
|
256 | + ) |
|
257 | + ) { |
|
258 | + // initialize all legacy shortcodes |
|
259 | + $load_assets = $this->parseContentForShortcodes('', true); |
|
260 | + } else { |
|
261 | + global $wpdb; |
|
262 | + $post_content = $wpdb->get_var( |
|
263 | + $wpdb->prepare( |
|
264 | + "SELECT post_content from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s", |
|
265 | + $current_post |
|
266 | + ) |
|
267 | + ); |
|
268 | + $load_assets = $this->parseContentForShortcodes($post_content); |
|
269 | + } |
|
270 | + if ($load_assets) { |
|
271 | + $this->registry->REQ->set_espresso_page(true); |
|
272 | + add_filter('FHEE_load_css', '__return_true'); |
|
273 | + add_filter('FHEE_load_js', '__return_true'); |
|
274 | + } |
|
275 | + do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $Front_Controller); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * checks supplied content against list of legacy shortcodes, |
|
281 | + * then initializes any found shortcodes, and returns true. |
|
282 | + * returns false if no shortcodes found. |
|
283 | + * |
|
284 | + * @param string $content |
|
285 | + * @param bool $load_all if true, then ALL active legacy shortcodes will be initialized |
|
286 | + * @return bool |
|
287 | + */ |
|
288 | + public function parseContentForShortcodes($content = '', $load_all = false) |
|
289 | + { |
|
290 | + $has_shortcode = false; |
|
291 | + foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) { |
|
292 | + if ($load_all || has_shortcode($content, $shortcode_class)) { |
|
293 | + // load up the shortcode |
|
294 | + $this->initializeShortcode($shortcode_class); |
|
295 | + $has_shortcode = true; |
|
296 | + } |
|
297 | + } |
|
298 | + return $has_shortcode; |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * given a shortcode name, will instantiate the shortcode and call it's run() method |
|
304 | + * |
|
305 | + * @param string $shortcode_class |
|
306 | + * @param WP $wp |
|
307 | + */ |
|
308 | + public function initializeShortcode($shortcode_class = '', WP $wp = null) |
|
309 | + { |
|
310 | + // don't do anything if shortcode is already initialized |
|
311 | + if (empty($this->registry->shortcodes->{$shortcode_class}) |
|
312 | + || ! is_string($this->registry->shortcodes->{$shortcode_class}) |
|
313 | + ) { |
|
314 | + return; |
|
315 | + } |
|
316 | + // let's pause to reflect on this... |
|
317 | + $sc_reflector = new ReflectionClass(LegacyShortcodesManager::addShortcodeClassPrefix($shortcode_class)); |
|
318 | + // ensure that class is actually a shortcode |
|
319 | + if (defined('WP_DEBUG') |
|
320 | + && WP_DEBUG === true |
|
321 | + && ! $sc_reflector->isSubclassOf('EES_Shortcode') |
|
322 | + ) { |
|
323 | + EE_Error::add_error( |
|
324 | + sprintf( |
|
325 | + esc_html__( |
|
326 | + 'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.', |
|
327 | + 'event_espresso' |
|
328 | + ), |
|
329 | + $shortcode_class |
|
330 | + ), |
|
331 | + __FILE__, |
|
332 | + __FUNCTION__, |
|
333 | + __LINE__ |
|
334 | + ); |
|
335 | + add_filter('FHEE_run_EE_the_content', '__return_true'); |
|
336 | + return; |
|
337 | + } |
|
338 | + global $wp; |
|
339 | + // and pass the request object to the run method |
|
340 | + $this->registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance(); |
|
341 | + // fire the shortcode class's run method, so that it can activate resources |
|
342 | + $this->registry->shortcodes->{$shortcode_class}->run($wp); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * get classname, remove EES_prefix, and convert to UPPERCASE |
|
348 | + * |
|
349 | + * @param string $class_name |
|
350 | + * @return string |
|
351 | + */ |
|
352 | + public static function generateShortcodeTagFromClassName($class_name) |
|
353 | + { |
|
354 | + return strtoupper(str_replace('EES_', '', $class_name)); |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * add EES_prefix and Capitalize words |
|
360 | + * |
|
361 | + * @param string $tag |
|
362 | + * @return string |
|
363 | + */ |
|
364 | + public static function generateShortcodeClassNameFromTag($tag) |
|
365 | + { |
|
366 | + // order of operation runs from inside to out |
|
367 | + // 5) maybe add prefix |
|
368 | + return LegacyShortcodesManager::addShortcodeClassPrefix( |
|
369 | + // 4) find spaces, replace with underscores |
|
370 | + str_replace( |
|
371 | + ' ', |
|
372 | + '_', |
|
373 | + // 3) capitalize first letter of each word |
|
374 | + ucwords( |
|
375 | + // 2) also change to lowercase so ucwords() will work |
|
376 | + strtolower( |
|
377 | + // 1) find underscores, replace with spaces so ucwords() will work |
|
378 | + str_replace( |
|
379 | + '_', |
|
380 | + ' ', |
|
381 | + $tag |
|
382 | + ) |
|
383 | + ) |
|
384 | + ) |
|
385 | + ) |
|
386 | + ); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * maybe add EES_prefix |
|
392 | + * |
|
393 | + * @param string $class_name |
|
394 | + * @return string |
|
395 | + */ |
|
396 | + public static function addShortcodeClassPrefix($class_name) |
|
397 | + { |
|
398 | + return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name; |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * @return array |
|
404 | + */ |
|
405 | + public function getEspressoShortcodeTags() |
|
406 | + { |
|
407 | + static $shortcode_tags = array(); |
|
408 | + if (empty($shortcode_tags)) { |
|
409 | + $shortcode_tags = array_keys((array) $this->registry->shortcodes); |
|
410 | + } |
|
411 | + return $shortcode_tags; |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * @param string $content |
|
417 | + * @return string |
|
418 | + */ |
|
419 | + public function doShortcode($content) |
|
420 | + { |
|
421 | + foreach ($this->getEspressoShortcodeTags() as $shortcode_tag) { |
|
422 | + if (strpos($content, $shortcode_tag) !== false) { |
|
423 | + $shortcode_class = LegacyShortcodesManager::generateShortcodeClassNameFromTag($shortcode_tag); |
|
424 | + $this->initializeShortcode($shortcode_class); |
|
425 | + } |
|
426 | + } |
|
427 | + return do_shortcode($content); |
|
428 | + } |
|
429 | 429 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
75 | 75 | array() |
76 | 76 | ); |
77 | - if (! empty($shortcodes_to_register)) { |
|
77 | + if ( ! empty($shortcodes_to_register)) { |
|
78 | 78 | // cycle thru shortcode folders |
79 | 79 | foreach ($shortcodes_to_register as $shortcode_path) { |
80 | 80 | // add to list of installed shortcode modules |
@@ -119,44 +119,44 @@ discard block |
||
119 | 119 | // remove last segment |
120 | 120 | array_pop($shortcode_path); |
121 | 121 | // glue it back together |
122 | - $shortcode_path = implode('/', $shortcode_path) . '/'; |
|
122 | + $shortcode_path = implode('/', $shortcode_path).'/'; |
|
123 | 123 | } else { |
124 | 124 | // we need to generate the filename based off of the folder name |
125 | 125 | // grab and sanitize shortcode directory name |
126 | 126 | $shortcode = sanitize_key(basename($shortcode_path)); |
127 | - $shortcode_path = rtrim($shortcode_path, '/') . '/'; |
|
127 | + $shortcode_path = rtrim($shortcode_path, '/').'/'; |
|
128 | 128 | } |
129 | 129 | // create classname from shortcode directory or file name |
130 | 130 | $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode))); |
131 | 131 | // add class prefix |
132 | - $shortcode_class = 'EES_' . $shortcode; |
|
132 | + $shortcode_class = 'EES_'.$shortcode; |
|
133 | 133 | // does the shortcode exist ? |
134 | - if (! is_readable($shortcode_path . '/' . $shortcode_class . $shortcode_ext)) { |
|
134 | + if ( ! is_readable($shortcode_path.'/'.$shortcode_class.$shortcode_ext)) { |
|
135 | 135 | $msg = sprintf( |
136 | 136 | esc_html__( |
137 | 137 | 'The requested %1$s shortcode file could not be found or is not readable due to file permissions. It should be in %2$s', |
138 | 138 | 'event_espresso' |
139 | 139 | ), |
140 | 140 | $shortcode_class, |
141 | - $shortcode_path . '/' . $shortcode_class . $shortcode_ext |
|
141 | + $shortcode_path.'/'.$shortcode_class.$shortcode_ext |
|
142 | 142 | ); |
143 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
143 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
144 | 144 | return false; |
145 | 145 | } |
146 | 146 | // load the shortcode class file |
147 | - require_once($shortcode_path . $shortcode_class . $shortcode_ext); |
|
147 | + require_once($shortcode_path.$shortcode_class.$shortcode_ext); |
|
148 | 148 | // verify that class exists |
149 | - if (! class_exists($shortcode_class)) { |
|
149 | + if ( ! class_exists($shortcode_class)) { |
|
150 | 150 | $msg = sprintf( |
151 | 151 | esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'), |
152 | 152 | $shortcode_class |
153 | 153 | ); |
154 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
154 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
155 | 155 | return false; |
156 | 156 | } |
157 | 157 | $shortcode = strtoupper($shortcode); |
158 | 158 | // add to array of registered shortcodes |
159 | - $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext; |
|
159 | + $this->registry->shortcodes->{$shortcode} = $shortcode_path.$shortcode_class.$shortcode_ext; |
|
160 | 160 | return true; |
161 | 161 | } |
162 | 162 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | // cycle thru shortcode folders |
174 | 174 | foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) { |
175 | 175 | // add class prefix |
176 | - $shortcode_class = 'EES_' . $shortcode; |
|
176 | + $shortcode_class = 'EES_'.$shortcode; |
|
177 | 177 | // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
178 | 178 | // which set hooks ? |
179 | 179 | if (is_admin()) { |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | $shortcode_tag = strtoupper($shortcode); |
190 | 190 | // but first check if the shortcode has already |
191 | 191 | // been added before assigning 'fallback_shortcode_processor' |
192 | - if (! shortcode_exists($shortcode_tag)) { |
|
192 | + if ( ! shortcode_exists($shortcode_tag)) { |
|
193 | 193 | // NOTE: this shortcode declaration will get overridden if the shortcode |
194 | 194 | // is successfully detected in the post content in initializeShortcode() |
195 | 195 | add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor')); |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | */ |
396 | 396 | public static function addShortcodeClassPrefix($class_name) |
397 | 397 | { |
398 | - return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name; |
|
398 | + return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_'.$class_name; |
|
399 | 399 | } |
400 | 400 | |
401 | 401 |
@@ -11,670 +11,670 @@ discard block |
||
11 | 11 | class EEH_Debug_Tools |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * instance of the EEH_Autoloader object |
|
16 | - * |
|
17 | - * @var $_instance |
|
18 | - * @access private |
|
19 | - */ |
|
20 | - private static $_instance; |
|
21 | - |
|
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $_memory_usage_points = array(); |
|
26 | - |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * @singleton method used to instantiate class object |
|
31 | - * @access public |
|
32 | - * @return EEH_Debug_Tools |
|
33 | - */ |
|
34 | - public static function instance() |
|
35 | - { |
|
36 | - // check if class object is instantiated, and instantiated properly |
|
37 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
38 | - self::$_instance = new self(); |
|
39 | - } |
|
40 | - return self::$_instance; |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * private class constructor |
|
47 | - */ |
|
48 | - private function __construct() |
|
49 | - { |
|
50 | - // load Kint PHP debugging library |
|
51 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')) { |
|
52 | - // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
53 | - // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
54 | - // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
55 | - // so we've moved it to our test folder so that it is not included with production releases |
|
56 | - // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
57 | - require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
58 | - } |
|
59 | - // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
60 | - // add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
61 | - // } |
|
62 | - $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
63 | - add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
64 | - add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
65 | - add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * show_db_name |
|
72 | - * |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public static function show_db_name() |
|
76 | - { |
|
77 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
78 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
79 | - . DB_NAME |
|
80 | - . '</p>'; |
|
81 | - } |
|
82 | - if (EE_DEBUG) { |
|
83 | - Benchmark::displayResults(); |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * dump EE_Session object at bottom of page after everything else has happened |
|
91 | - * |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public function espresso_session_footer_dump() |
|
95 | - { |
|
96 | - if ((defined('WP_DEBUG') && WP_DEBUG) |
|
97 | - && ! defined('DOING_AJAX') |
|
98 | - && class_exists('Kint') |
|
99 | - && function_exists('wp_get_current_user') |
|
100 | - && current_user_can('update_core') |
|
101 | - && class_exists('EE_Registry') |
|
102 | - ) { |
|
103 | - Kint::dump(EE_Registry::instance()->SSN->id()); |
|
104 | - Kint::dump(EE_Registry::instance()->SSN); |
|
105 | - // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
106 | - $this->espresso_list_hooked_functions(); |
|
107 | - Benchmark::displayResults(); |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * List All Hooked Functions |
|
115 | - * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
116 | - * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
117 | - * |
|
118 | - * @param string $tag |
|
119 | - * @return void |
|
120 | - */ |
|
121 | - public function espresso_list_hooked_functions($tag = '') |
|
122 | - { |
|
123 | - global $wp_filter; |
|
124 | - echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
125 | - if ($tag) { |
|
126 | - $hook[ $tag ] = $wp_filter[ $tag ]; |
|
127 | - if (! is_array($hook[ $tag ])) { |
|
128 | - trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
129 | - return; |
|
130 | - } |
|
131 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
132 | - } else { |
|
133 | - $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
134 | - ksort($hook); |
|
135 | - } |
|
136 | - foreach ($hook as $tag_name => $priorities) { |
|
137 | - echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
138 | - ksort($priorities); |
|
139 | - foreach ($priorities as $priority => $function) { |
|
140 | - echo $priority; |
|
141 | - foreach ($function as $name => $properties) { |
|
142 | - echo "\t$name<br />"; |
|
143 | - } |
|
144 | - } |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * registered_filter_callbacks |
|
152 | - * |
|
153 | - * @param string $hook_name |
|
154 | - * @return array |
|
155 | - */ |
|
156 | - public static function registered_filter_callbacks($hook_name = '') |
|
157 | - { |
|
158 | - $filters = array(); |
|
159 | - global $wp_filter; |
|
160 | - if (isset($wp_filter[ $hook_name ])) { |
|
161 | - $filters[ $hook_name ] = array(); |
|
162 | - foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
163 | - $filters[ $hook_name ][ $priority ] = array(); |
|
164 | - foreach ($callbacks as $callback) { |
|
165 | - $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
166 | - } |
|
167 | - } |
|
168 | - } |
|
169 | - return $filters; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * captures plugin activation errors for debugging |
|
176 | - * |
|
177 | - * @return void |
|
178 | - * @throws EE_Error |
|
179 | - */ |
|
180 | - public static function ee_plugin_activation_errors() |
|
181 | - { |
|
182 | - if (WP_DEBUG) { |
|
183 | - $activation_errors = ob_get_contents(); |
|
184 | - if (! empty($activation_errors)) { |
|
185 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
186 | - } |
|
187 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
188 | - if (class_exists('EEH_File')) { |
|
189 | - try { |
|
190 | - EEH_File::ensure_file_exists_and_is_writable( |
|
191 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
192 | - ); |
|
193 | - EEH_File::write_to_file( |
|
194 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
195 | - $activation_errors |
|
196 | - ); |
|
197 | - } catch (EE_Error $e) { |
|
198 | - EE_Error::add_error( |
|
199 | - sprintf( |
|
200 | - __( |
|
201 | - 'The Event Espresso activation errors file could not be setup because: %s', |
|
202 | - 'event_espresso' |
|
203 | - ), |
|
204 | - $e->getMessage() |
|
205 | - ), |
|
206 | - __FILE__, |
|
207 | - __FUNCTION__, |
|
208 | - __LINE__ |
|
209 | - ); |
|
210 | - } |
|
211 | - } else { |
|
212 | - // old school attempt |
|
213 | - file_put_contents( |
|
214 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
215 | - $activation_errors |
|
216 | - ); |
|
217 | - } |
|
218 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
219 | - update_option('ee_plugin_activation_errors', $activation_errors); |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
227 | - * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
228 | - * or we want to make sure they use something the right way. |
|
229 | - * |
|
230 | - * @access public |
|
231 | - * @param string $function The function that was called |
|
232 | - * @param string $message A message explaining what has been done incorrectly |
|
233 | - * @param string $version The version of Event Espresso where the error was added |
|
234 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
235 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
236 | - * but not have any notices appear until a later version. This allows developers |
|
237 | - * extra time to update their code before notices appear. |
|
238 | - * @param int $error_type |
|
239 | - * @uses trigger_error() |
|
240 | - */ |
|
241 | - public function doing_it_wrong( |
|
242 | - $function, |
|
243 | - $message, |
|
244 | - $version, |
|
245 | - $applies_when = '', |
|
246 | - $error_type = null |
|
247 | - ) { |
|
248 | - $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
249 | - $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
250 | - // because we swapped the parameter order around for the last two params, |
|
251 | - // let's verify that some third party isn't still passing an error type value for the third param |
|
252 | - if (is_int($applies_when)) { |
|
253 | - $error_type = $applies_when; |
|
254 | - $applies_when = espresso_version(); |
|
255 | - } |
|
256 | - // if not displaying notices yet, then just leave |
|
257 | - if (version_compare(espresso_version(), $applies_when, '<')) { |
|
258 | - return; |
|
259 | - } |
|
260 | - do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
261 | - $version = $version === null |
|
262 | - ? '' |
|
263 | - : sprintf( |
|
264 | - __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
265 | - $version |
|
266 | - ); |
|
267 | - $error_message = sprintf( |
|
268 | - esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
269 | - $function, |
|
270 | - '<strong>', |
|
271 | - '</strong>', |
|
272 | - $message, |
|
273 | - $version |
|
274 | - ); |
|
275 | - // don't trigger error if doing ajax, |
|
276 | - // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
277 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
278 | - $error_message .= ' ' . esc_html__( |
|
279 | - 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
280 | - 'event_espresso' |
|
281 | - ); |
|
282 | - $error_message .= '<ul><li>'; |
|
283 | - $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
284 | - $error_message .= '</ul>'; |
|
285 | - EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
286 | - // now we set this on the transient so it shows up on the next request. |
|
287 | - EE_Error::get_notices(false, true); |
|
288 | - } else { |
|
289 | - trigger_error($error_message, $error_type); |
|
290 | - } |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * Logger helpers |
|
298 | - */ |
|
299 | - /** |
|
300 | - * debug |
|
301 | - * |
|
302 | - * @param string $class |
|
303 | - * @param string $func |
|
304 | - * @param string $line |
|
305 | - * @param array $info |
|
306 | - * @param bool $display_request |
|
307 | - * @param string $debug_index |
|
308 | - * @param string $debug_key |
|
309 | - * @throws EE_Error |
|
310 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
311 | - */ |
|
312 | - public static function log( |
|
313 | - $class = '', |
|
314 | - $func = '', |
|
315 | - $line = '', |
|
316 | - $info = array(), |
|
317 | - $display_request = false, |
|
318 | - $debug_index = '', |
|
319 | - $debug_key = 'EE_DEBUG_SPCO' |
|
320 | - ) { |
|
321 | - if (WP_DEBUG) { |
|
322 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
323 | - $debug_data = get_option($debug_key, array()); |
|
324 | - $default_data = array( |
|
325 | - $class => $func . '() : ' . $line, |
|
326 | - 'REQ' => $display_request ? $_REQUEST : '', |
|
327 | - ); |
|
328 | - // don't serialize objects |
|
329 | - $info = self::strip_objects($info); |
|
330 | - $index = ! empty($debug_index) ? $debug_index : 0; |
|
331 | - if (! isset($debug_data[ $index ])) { |
|
332 | - $debug_data[ $index ] = array(); |
|
333 | - } |
|
334 | - $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
335 | - update_option($debug_key, $debug_data); |
|
336 | - } |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * strip_objects |
|
343 | - * |
|
344 | - * @param array $info |
|
345 | - * @return array |
|
346 | - */ |
|
347 | - public static function strip_objects($info = array()) |
|
348 | - { |
|
349 | - foreach ($info as $key => $value) { |
|
350 | - if (is_array($value)) { |
|
351 | - $info[ $key ] = self::strip_objects($value); |
|
352 | - } elseif (is_object($value)) { |
|
353 | - $object_class = get_class($value); |
|
354 | - $info[ $object_class ] = array(); |
|
355 | - $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
356 | - if (method_exists($value, 'ID')) { |
|
357 | - $info[ $object_class ]['ID'] = $value->ID(); |
|
358 | - } |
|
359 | - if (method_exists($value, 'status')) { |
|
360 | - $info[ $object_class ]['status'] = $value->status(); |
|
361 | - } elseif (method_exists($value, 'status_ID')) { |
|
362 | - $info[ $object_class ]['status'] = $value->status_ID(); |
|
363 | - } |
|
364 | - unset($info[ $key ]); |
|
365 | - } |
|
366 | - } |
|
367 | - return (array) $info; |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * @param mixed $var |
|
374 | - * @param string $var_name |
|
375 | - * @param string $file |
|
376 | - * @param int|string $line |
|
377 | - * @param int|string $heading_tag |
|
378 | - * @param bool $die |
|
379 | - * @param string $margin |
|
380 | - */ |
|
381 | - public static function printv( |
|
382 | - $var, |
|
383 | - $var_name = '', |
|
384 | - $file = '', |
|
385 | - $line = '', |
|
386 | - $heading_tag = 5, |
|
387 | - $die = false, |
|
388 | - $margin = '' |
|
389 | - ) { |
|
390 | - $var_name = ! $var_name ? 'string' : $var_name; |
|
391 | - $var_name = ucwords(str_replace('$', '', $var_name)); |
|
392 | - $is_method = method_exists($var_name, $var); |
|
393 | - $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
394 | - $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
395 | - $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
396 | - $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
397 | - $result .= $is_method |
|
398 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
399 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
400 | - $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
401 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
402 | - if ($die) { |
|
403 | - die($result); |
|
404 | - } |
|
405 | - echo $result; |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - protected static function headingTag($heading_tag) |
|
410 | - { |
|
411 | - $heading_tag = absint($heading_tag); |
|
412 | - return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - protected static function headingSpacer($heading_tag) |
|
417 | - { |
|
418 | - return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2') |
|
419 | - ? "\n" |
|
420 | - : ''; |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - protected static function plainOutput() |
|
425 | - { |
|
426 | - return defined('EE_TESTS_DIR') |
|
427 | - || (defined('DOING_AJAX') && DOING_AJAX) |
|
428 | - || ( |
|
429 | - isset($_SERVER['REQUEST_URI']) |
|
430 | - && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false |
|
431 | - ); |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * @param string $var_name |
|
437 | - * @param string $heading_tag |
|
438 | - * @param string $margin |
|
439 | - * @param int $line |
|
440 | - * @return string |
|
441 | - */ |
|
442 | - protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
443 | - { |
|
444 | - if (EEH_Debug_Tools::plainOutput()) { |
|
445 | - $heading = ''; |
|
446 | - if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
447 | - $heading .= "\n"; |
|
448 | - } |
|
449 | - $heading .= "\n{$line}) {$var_name}"; |
|
450 | - return $heading; |
|
451 | - } |
|
452 | - $margin = "25px 0 0 {$margin}"; |
|
453 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
454 | - } |
|
455 | - |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * @param string $heading_tag |
|
460 | - * @return string |
|
461 | - */ |
|
462 | - protected static function headingX($heading_tag = 'h5') |
|
463 | - { |
|
464 | - if (EEH_Debug_Tools::plainOutput()) { |
|
465 | - return ''; |
|
466 | - } |
|
467 | - return '</' . $heading_tag . '>'; |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - |
|
472 | - /** |
|
473 | - * @param string $content |
|
474 | - * @return string |
|
475 | - */ |
|
476 | - protected static function grey_span($content = '') |
|
477 | - { |
|
478 | - if (EEH_Debug_Tools::plainOutput()) { |
|
479 | - return $content; |
|
480 | - } |
|
481 | - return '<span style="color:#999">' . $content . '</span>'; |
|
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - |
|
486 | - /** |
|
487 | - * @param string $file |
|
488 | - * @param int $line |
|
489 | - * @return string |
|
490 | - */ |
|
491 | - protected static function file_and_line($file, $line, $heading_tag) |
|
492 | - { |
|
493 | - if ($file === '' || $line === '') { |
|
494 | - return ''; |
|
495 | - } |
|
496 | - $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
|
497 | - if (EEH_Debug_Tools::plainOutput()) { |
|
498 | - if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
499 | - return " ({$file})"; |
|
500 | - } |
|
501 | - return ''; |
|
502 | - } |
|
503 | - return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
504 | - . $file |
|
505 | - . '<br />line no: ' |
|
506 | - . $line |
|
507 | - . '</span>'; |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * @param string $content |
|
514 | - * @return string |
|
515 | - */ |
|
516 | - protected static function orange_span($content = '') |
|
517 | - { |
|
518 | - if (EEH_Debug_Tools::plainOutput()) { |
|
519 | - return $content; |
|
520 | - } |
|
521 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
522 | - } |
|
523 | - |
|
524 | - |
|
525 | - |
|
526 | - /** |
|
527 | - * @param mixed $var |
|
528 | - * @return string |
|
529 | - */ |
|
530 | - protected static function pre_span($var) |
|
531 | - { |
|
532 | - ob_start(); |
|
533 | - var_dump($var); |
|
534 | - $var = ob_get_clean(); |
|
535 | - if (EEH_Debug_Tools::plainOutput()) { |
|
536 | - return $var; |
|
537 | - } |
|
538 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * @param mixed $var |
|
545 | - * @param string $var_name |
|
546 | - * @param string $file |
|
547 | - * @param int|string $line |
|
548 | - * @param int|string $heading_tag |
|
549 | - * @param bool $die |
|
550 | - */ |
|
551 | - public static function printr( |
|
552 | - $var, |
|
553 | - $var_name = '', |
|
554 | - $file = '', |
|
555 | - $line = '', |
|
556 | - $heading_tag = 5, |
|
557 | - $die = false |
|
558 | - ) { |
|
559 | - // return; |
|
560 | - $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
561 | - $margin = is_admin() ? ' 180px' : '0'; |
|
562 | - // $print_r = false; |
|
563 | - if (is_string($var)) { |
|
564 | - EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
565 | - return; |
|
566 | - } |
|
567 | - if (is_object($var)) { |
|
568 | - $var_name = ! $var_name ? 'object' : $var_name; |
|
569 | - // $print_r = true; |
|
570 | - } elseif (is_array($var)) { |
|
571 | - $var_name = ! $var_name ? 'array' : $var_name; |
|
572 | - // $print_r = true; |
|
573 | - } elseif (is_numeric($var)) { |
|
574 | - $var_name = ! $var_name ? 'numeric' : $var_name; |
|
575 | - } elseif ($var === null) { |
|
576 | - $var_name = ! $var_name ? 'null' : $var_name; |
|
577 | - } |
|
578 | - $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
579 | - $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
580 | - $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
581 | - $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
582 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
583 | - EEH_Debug_Tools::pre_span($var) |
|
584 | - ); |
|
585 | - $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
586 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
587 | - if ($die) { |
|
588 | - die($result); |
|
589 | - } |
|
590 | - echo $result; |
|
591 | - } |
|
592 | - |
|
593 | - |
|
594 | - |
|
595 | - /******************** deprecated ********************/ |
|
596 | - |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * @deprecated 4.9.39.rc.034 |
|
601 | - */ |
|
602 | - public function reset_times() |
|
603 | - { |
|
604 | - Benchmark::resetTimes(); |
|
605 | - } |
|
606 | - |
|
607 | - |
|
608 | - |
|
609 | - /** |
|
610 | - * @deprecated 4.9.39.rc.034 |
|
611 | - * @param null $timer_name |
|
612 | - */ |
|
613 | - public function start_timer($timer_name = null) |
|
614 | - { |
|
615 | - Benchmark::startTimer($timer_name); |
|
616 | - } |
|
617 | - |
|
618 | - |
|
619 | - |
|
620 | - /** |
|
621 | - * @deprecated 4.9.39.rc.034 |
|
622 | - * @param string $timer_name |
|
623 | - */ |
|
624 | - public function stop_timer($timer_name = '') |
|
625 | - { |
|
626 | - Benchmark::stopTimer($timer_name); |
|
627 | - } |
|
628 | - |
|
629 | - |
|
630 | - |
|
631 | - /** |
|
632 | - * @deprecated 4.9.39.rc.034 |
|
633 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
634 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
635 | - * @return void |
|
636 | - */ |
|
637 | - public function measure_memory($label, $output_now = false) |
|
638 | - { |
|
639 | - Benchmark::measureMemory($label, $output_now); |
|
640 | - } |
|
641 | - |
|
642 | - |
|
643 | - |
|
644 | - /** |
|
645 | - * @deprecated 4.9.39.rc.034 |
|
646 | - * @param int $size |
|
647 | - * @return string |
|
648 | - */ |
|
649 | - public function convert($size) |
|
650 | - { |
|
651 | - return Benchmark::convert($size); |
|
652 | - } |
|
653 | - |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * @deprecated 4.9.39.rc.034 |
|
658 | - * @param bool $output_now |
|
659 | - * @return string |
|
660 | - */ |
|
661 | - public function show_times($output_now = true) |
|
662 | - { |
|
663 | - return Benchmark::displayResults($output_now); |
|
664 | - } |
|
665 | - |
|
666 | - |
|
667 | - |
|
668 | - /** |
|
669 | - * @deprecated 4.9.39.rc.034 |
|
670 | - * @param string $timer_name |
|
671 | - * @param float $total_time |
|
672 | - * @return string |
|
673 | - */ |
|
674 | - public function format_time($timer_name, $total_time) |
|
675 | - { |
|
676 | - return Benchmark::formatTime($timer_name, $total_time); |
|
677 | - } |
|
14 | + /** |
|
15 | + * instance of the EEH_Autoloader object |
|
16 | + * |
|
17 | + * @var $_instance |
|
18 | + * @access private |
|
19 | + */ |
|
20 | + private static $_instance; |
|
21 | + |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $_memory_usage_points = array(); |
|
26 | + |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * @singleton method used to instantiate class object |
|
31 | + * @access public |
|
32 | + * @return EEH_Debug_Tools |
|
33 | + */ |
|
34 | + public static function instance() |
|
35 | + { |
|
36 | + // check if class object is instantiated, and instantiated properly |
|
37 | + if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
38 | + self::$_instance = new self(); |
|
39 | + } |
|
40 | + return self::$_instance; |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * private class constructor |
|
47 | + */ |
|
48 | + private function __construct() |
|
49 | + { |
|
50 | + // load Kint PHP debugging library |
|
51 | + if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')) { |
|
52 | + // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
53 | + // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
54 | + // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
55 | + // so we've moved it to our test folder so that it is not included with production releases |
|
56 | + // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
57 | + require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
58 | + } |
|
59 | + // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
60 | + // add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
61 | + // } |
|
62 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
63 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
64 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
65 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * show_db_name |
|
72 | + * |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public static function show_db_name() |
|
76 | + { |
|
77 | + if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
78 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
79 | + . DB_NAME |
|
80 | + . '</p>'; |
|
81 | + } |
|
82 | + if (EE_DEBUG) { |
|
83 | + Benchmark::displayResults(); |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * dump EE_Session object at bottom of page after everything else has happened |
|
91 | + * |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public function espresso_session_footer_dump() |
|
95 | + { |
|
96 | + if ((defined('WP_DEBUG') && WP_DEBUG) |
|
97 | + && ! defined('DOING_AJAX') |
|
98 | + && class_exists('Kint') |
|
99 | + && function_exists('wp_get_current_user') |
|
100 | + && current_user_can('update_core') |
|
101 | + && class_exists('EE_Registry') |
|
102 | + ) { |
|
103 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
104 | + Kint::dump(EE_Registry::instance()->SSN); |
|
105 | + // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
106 | + $this->espresso_list_hooked_functions(); |
|
107 | + Benchmark::displayResults(); |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * List All Hooked Functions |
|
115 | + * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
116 | + * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
117 | + * |
|
118 | + * @param string $tag |
|
119 | + * @return void |
|
120 | + */ |
|
121 | + public function espresso_list_hooked_functions($tag = '') |
|
122 | + { |
|
123 | + global $wp_filter; |
|
124 | + echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
125 | + if ($tag) { |
|
126 | + $hook[ $tag ] = $wp_filter[ $tag ]; |
|
127 | + if (! is_array($hook[ $tag ])) { |
|
128 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
129 | + return; |
|
130 | + } |
|
131 | + echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
132 | + } else { |
|
133 | + $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
134 | + ksort($hook); |
|
135 | + } |
|
136 | + foreach ($hook as $tag_name => $priorities) { |
|
137 | + echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
138 | + ksort($priorities); |
|
139 | + foreach ($priorities as $priority => $function) { |
|
140 | + echo $priority; |
|
141 | + foreach ($function as $name => $properties) { |
|
142 | + echo "\t$name<br />"; |
|
143 | + } |
|
144 | + } |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * registered_filter_callbacks |
|
152 | + * |
|
153 | + * @param string $hook_name |
|
154 | + * @return array |
|
155 | + */ |
|
156 | + public static function registered_filter_callbacks($hook_name = '') |
|
157 | + { |
|
158 | + $filters = array(); |
|
159 | + global $wp_filter; |
|
160 | + if (isset($wp_filter[ $hook_name ])) { |
|
161 | + $filters[ $hook_name ] = array(); |
|
162 | + foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
163 | + $filters[ $hook_name ][ $priority ] = array(); |
|
164 | + foreach ($callbacks as $callback) { |
|
165 | + $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
166 | + } |
|
167 | + } |
|
168 | + } |
|
169 | + return $filters; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * captures plugin activation errors for debugging |
|
176 | + * |
|
177 | + * @return void |
|
178 | + * @throws EE_Error |
|
179 | + */ |
|
180 | + public static function ee_plugin_activation_errors() |
|
181 | + { |
|
182 | + if (WP_DEBUG) { |
|
183 | + $activation_errors = ob_get_contents(); |
|
184 | + if (! empty($activation_errors)) { |
|
185 | + $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
186 | + } |
|
187 | + espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
188 | + if (class_exists('EEH_File')) { |
|
189 | + try { |
|
190 | + EEH_File::ensure_file_exists_and_is_writable( |
|
191 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
192 | + ); |
|
193 | + EEH_File::write_to_file( |
|
194 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
195 | + $activation_errors |
|
196 | + ); |
|
197 | + } catch (EE_Error $e) { |
|
198 | + EE_Error::add_error( |
|
199 | + sprintf( |
|
200 | + __( |
|
201 | + 'The Event Espresso activation errors file could not be setup because: %s', |
|
202 | + 'event_espresso' |
|
203 | + ), |
|
204 | + $e->getMessage() |
|
205 | + ), |
|
206 | + __FILE__, |
|
207 | + __FUNCTION__, |
|
208 | + __LINE__ |
|
209 | + ); |
|
210 | + } |
|
211 | + } else { |
|
212 | + // old school attempt |
|
213 | + file_put_contents( |
|
214 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
215 | + $activation_errors |
|
216 | + ); |
|
217 | + } |
|
218 | + $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
219 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
227 | + * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
228 | + * or we want to make sure they use something the right way. |
|
229 | + * |
|
230 | + * @access public |
|
231 | + * @param string $function The function that was called |
|
232 | + * @param string $message A message explaining what has been done incorrectly |
|
233 | + * @param string $version The version of Event Espresso where the error was added |
|
234 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
235 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
236 | + * but not have any notices appear until a later version. This allows developers |
|
237 | + * extra time to update their code before notices appear. |
|
238 | + * @param int $error_type |
|
239 | + * @uses trigger_error() |
|
240 | + */ |
|
241 | + public function doing_it_wrong( |
|
242 | + $function, |
|
243 | + $message, |
|
244 | + $version, |
|
245 | + $applies_when = '', |
|
246 | + $error_type = null |
|
247 | + ) { |
|
248 | + $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
249 | + $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
250 | + // because we swapped the parameter order around for the last two params, |
|
251 | + // let's verify that some third party isn't still passing an error type value for the third param |
|
252 | + if (is_int($applies_when)) { |
|
253 | + $error_type = $applies_when; |
|
254 | + $applies_when = espresso_version(); |
|
255 | + } |
|
256 | + // if not displaying notices yet, then just leave |
|
257 | + if (version_compare(espresso_version(), $applies_when, '<')) { |
|
258 | + return; |
|
259 | + } |
|
260 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
261 | + $version = $version === null |
|
262 | + ? '' |
|
263 | + : sprintf( |
|
264 | + __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
265 | + $version |
|
266 | + ); |
|
267 | + $error_message = sprintf( |
|
268 | + esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
269 | + $function, |
|
270 | + '<strong>', |
|
271 | + '</strong>', |
|
272 | + $message, |
|
273 | + $version |
|
274 | + ); |
|
275 | + // don't trigger error if doing ajax, |
|
276 | + // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
277 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
278 | + $error_message .= ' ' . esc_html__( |
|
279 | + 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
280 | + 'event_espresso' |
|
281 | + ); |
|
282 | + $error_message .= '<ul><li>'; |
|
283 | + $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
284 | + $error_message .= '</ul>'; |
|
285 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
286 | + // now we set this on the transient so it shows up on the next request. |
|
287 | + EE_Error::get_notices(false, true); |
|
288 | + } else { |
|
289 | + trigger_error($error_message, $error_type); |
|
290 | + } |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * Logger helpers |
|
298 | + */ |
|
299 | + /** |
|
300 | + * debug |
|
301 | + * |
|
302 | + * @param string $class |
|
303 | + * @param string $func |
|
304 | + * @param string $line |
|
305 | + * @param array $info |
|
306 | + * @param bool $display_request |
|
307 | + * @param string $debug_index |
|
308 | + * @param string $debug_key |
|
309 | + * @throws EE_Error |
|
310 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
311 | + */ |
|
312 | + public static function log( |
|
313 | + $class = '', |
|
314 | + $func = '', |
|
315 | + $line = '', |
|
316 | + $info = array(), |
|
317 | + $display_request = false, |
|
318 | + $debug_index = '', |
|
319 | + $debug_key = 'EE_DEBUG_SPCO' |
|
320 | + ) { |
|
321 | + if (WP_DEBUG) { |
|
322 | + $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
323 | + $debug_data = get_option($debug_key, array()); |
|
324 | + $default_data = array( |
|
325 | + $class => $func . '() : ' . $line, |
|
326 | + 'REQ' => $display_request ? $_REQUEST : '', |
|
327 | + ); |
|
328 | + // don't serialize objects |
|
329 | + $info = self::strip_objects($info); |
|
330 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
331 | + if (! isset($debug_data[ $index ])) { |
|
332 | + $debug_data[ $index ] = array(); |
|
333 | + } |
|
334 | + $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
335 | + update_option($debug_key, $debug_data); |
|
336 | + } |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * strip_objects |
|
343 | + * |
|
344 | + * @param array $info |
|
345 | + * @return array |
|
346 | + */ |
|
347 | + public static function strip_objects($info = array()) |
|
348 | + { |
|
349 | + foreach ($info as $key => $value) { |
|
350 | + if (is_array($value)) { |
|
351 | + $info[ $key ] = self::strip_objects($value); |
|
352 | + } elseif (is_object($value)) { |
|
353 | + $object_class = get_class($value); |
|
354 | + $info[ $object_class ] = array(); |
|
355 | + $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
356 | + if (method_exists($value, 'ID')) { |
|
357 | + $info[ $object_class ]['ID'] = $value->ID(); |
|
358 | + } |
|
359 | + if (method_exists($value, 'status')) { |
|
360 | + $info[ $object_class ]['status'] = $value->status(); |
|
361 | + } elseif (method_exists($value, 'status_ID')) { |
|
362 | + $info[ $object_class ]['status'] = $value->status_ID(); |
|
363 | + } |
|
364 | + unset($info[ $key ]); |
|
365 | + } |
|
366 | + } |
|
367 | + return (array) $info; |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * @param mixed $var |
|
374 | + * @param string $var_name |
|
375 | + * @param string $file |
|
376 | + * @param int|string $line |
|
377 | + * @param int|string $heading_tag |
|
378 | + * @param bool $die |
|
379 | + * @param string $margin |
|
380 | + */ |
|
381 | + public static function printv( |
|
382 | + $var, |
|
383 | + $var_name = '', |
|
384 | + $file = '', |
|
385 | + $line = '', |
|
386 | + $heading_tag = 5, |
|
387 | + $die = false, |
|
388 | + $margin = '' |
|
389 | + ) { |
|
390 | + $var_name = ! $var_name ? 'string' : $var_name; |
|
391 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
392 | + $is_method = method_exists($var_name, $var); |
|
393 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
394 | + $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
395 | + $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
396 | + $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
397 | + $result .= $is_method |
|
398 | + ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
399 | + : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
400 | + $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
401 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
402 | + if ($die) { |
|
403 | + die($result); |
|
404 | + } |
|
405 | + echo $result; |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + protected static function headingTag($heading_tag) |
|
410 | + { |
|
411 | + $heading_tag = absint($heading_tag); |
|
412 | + return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + protected static function headingSpacer($heading_tag) |
|
417 | + { |
|
418 | + return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2') |
|
419 | + ? "\n" |
|
420 | + : ''; |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + protected static function plainOutput() |
|
425 | + { |
|
426 | + return defined('EE_TESTS_DIR') |
|
427 | + || (defined('DOING_AJAX') && DOING_AJAX) |
|
428 | + || ( |
|
429 | + isset($_SERVER['REQUEST_URI']) |
|
430 | + && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false |
|
431 | + ); |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * @param string $var_name |
|
437 | + * @param string $heading_tag |
|
438 | + * @param string $margin |
|
439 | + * @param int $line |
|
440 | + * @return string |
|
441 | + */ |
|
442 | + protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
443 | + { |
|
444 | + if (EEH_Debug_Tools::plainOutput()) { |
|
445 | + $heading = ''; |
|
446 | + if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
447 | + $heading .= "\n"; |
|
448 | + } |
|
449 | + $heading .= "\n{$line}) {$var_name}"; |
|
450 | + return $heading; |
|
451 | + } |
|
452 | + $margin = "25px 0 0 {$margin}"; |
|
453 | + return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
454 | + } |
|
455 | + |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * @param string $heading_tag |
|
460 | + * @return string |
|
461 | + */ |
|
462 | + protected static function headingX($heading_tag = 'h5') |
|
463 | + { |
|
464 | + if (EEH_Debug_Tools::plainOutput()) { |
|
465 | + return ''; |
|
466 | + } |
|
467 | + return '</' . $heading_tag . '>'; |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + |
|
472 | + /** |
|
473 | + * @param string $content |
|
474 | + * @return string |
|
475 | + */ |
|
476 | + protected static function grey_span($content = '') |
|
477 | + { |
|
478 | + if (EEH_Debug_Tools::plainOutput()) { |
|
479 | + return $content; |
|
480 | + } |
|
481 | + return '<span style="color:#999">' . $content . '</span>'; |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + |
|
486 | + /** |
|
487 | + * @param string $file |
|
488 | + * @param int $line |
|
489 | + * @return string |
|
490 | + */ |
|
491 | + protected static function file_and_line($file, $line, $heading_tag) |
|
492 | + { |
|
493 | + if ($file === '' || $line === '') { |
|
494 | + return ''; |
|
495 | + } |
|
496 | + $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
|
497 | + if (EEH_Debug_Tools::plainOutput()) { |
|
498 | + if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
499 | + return " ({$file})"; |
|
500 | + } |
|
501 | + return ''; |
|
502 | + } |
|
503 | + return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
504 | + . $file |
|
505 | + . '<br />line no: ' |
|
506 | + . $line |
|
507 | + . '</span>'; |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * @param string $content |
|
514 | + * @return string |
|
515 | + */ |
|
516 | + protected static function orange_span($content = '') |
|
517 | + { |
|
518 | + if (EEH_Debug_Tools::plainOutput()) { |
|
519 | + return $content; |
|
520 | + } |
|
521 | + return '<span style="color:#E76700">' . $content . '</span>'; |
|
522 | + } |
|
523 | + |
|
524 | + |
|
525 | + |
|
526 | + /** |
|
527 | + * @param mixed $var |
|
528 | + * @return string |
|
529 | + */ |
|
530 | + protected static function pre_span($var) |
|
531 | + { |
|
532 | + ob_start(); |
|
533 | + var_dump($var); |
|
534 | + $var = ob_get_clean(); |
|
535 | + if (EEH_Debug_Tools::plainOutput()) { |
|
536 | + return $var; |
|
537 | + } |
|
538 | + return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * @param mixed $var |
|
545 | + * @param string $var_name |
|
546 | + * @param string $file |
|
547 | + * @param int|string $line |
|
548 | + * @param int|string $heading_tag |
|
549 | + * @param bool $die |
|
550 | + */ |
|
551 | + public static function printr( |
|
552 | + $var, |
|
553 | + $var_name = '', |
|
554 | + $file = '', |
|
555 | + $line = '', |
|
556 | + $heading_tag = 5, |
|
557 | + $die = false |
|
558 | + ) { |
|
559 | + // return; |
|
560 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
561 | + $margin = is_admin() ? ' 180px' : '0'; |
|
562 | + // $print_r = false; |
|
563 | + if (is_string($var)) { |
|
564 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
565 | + return; |
|
566 | + } |
|
567 | + if (is_object($var)) { |
|
568 | + $var_name = ! $var_name ? 'object' : $var_name; |
|
569 | + // $print_r = true; |
|
570 | + } elseif (is_array($var)) { |
|
571 | + $var_name = ! $var_name ? 'array' : $var_name; |
|
572 | + // $print_r = true; |
|
573 | + } elseif (is_numeric($var)) { |
|
574 | + $var_name = ! $var_name ? 'numeric' : $var_name; |
|
575 | + } elseif ($var === null) { |
|
576 | + $var_name = ! $var_name ? 'null' : $var_name; |
|
577 | + } |
|
578 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
579 | + $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
580 | + $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
581 | + $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
582 | + $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
583 | + EEH_Debug_Tools::pre_span($var) |
|
584 | + ); |
|
585 | + $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
586 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
587 | + if ($die) { |
|
588 | + die($result); |
|
589 | + } |
|
590 | + echo $result; |
|
591 | + } |
|
592 | + |
|
593 | + |
|
594 | + |
|
595 | + /******************** deprecated ********************/ |
|
596 | + |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * @deprecated 4.9.39.rc.034 |
|
601 | + */ |
|
602 | + public function reset_times() |
|
603 | + { |
|
604 | + Benchmark::resetTimes(); |
|
605 | + } |
|
606 | + |
|
607 | + |
|
608 | + |
|
609 | + /** |
|
610 | + * @deprecated 4.9.39.rc.034 |
|
611 | + * @param null $timer_name |
|
612 | + */ |
|
613 | + public function start_timer($timer_name = null) |
|
614 | + { |
|
615 | + Benchmark::startTimer($timer_name); |
|
616 | + } |
|
617 | + |
|
618 | + |
|
619 | + |
|
620 | + /** |
|
621 | + * @deprecated 4.9.39.rc.034 |
|
622 | + * @param string $timer_name |
|
623 | + */ |
|
624 | + public function stop_timer($timer_name = '') |
|
625 | + { |
|
626 | + Benchmark::stopTimer($timer_name); |
|
627 | + } |
|
628 | + |
|
629 | + |
|
630 | + |
|
631 | + /** |
|
632 | + * @deprecated 4.9.39.rc.034 |
|
633 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
634 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
635 | + * @return void |
|
636 | + */ |
|
637 | + public function measure_memory($label, $output_now = false) |
|
638 | + { |
|
639 | + Benchmark::measureMemory($label, $output_now); |
|
640 | + } |
|
641 | + |
|
642 | + |
|
643 | + |
|
644 | + /** |
|
645 | + * @deprecated 4.9.39.rc.034 |
|
646 | + * @param int $size |
|
647 | + * @return string |
|
648 | + */ |
|
649 | + public function convert($size) |
|
650 | + { |
|
651 | + return Benchmark::convert($size); |
|
652 | + } |
|
653 | + |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * @deprecated 4.9.39.rc.034 |
|
658 | + * @param bool $output_now |
|
659 | + * @return string |
|
660 | + */ |
|
661 | + public function show_times($output_now = true) |
|
662 | + { |
|
663 | + return Benchmark::displayResults($output_now); |
|
664 | + } |
|
665 | + |
|
666 | + |
|
667 | + |
|
668 | + /** |
|
669 | + * @deprecated 4.9.39.rc.034 |
|
670 | + * @param string $timer_name |
|
671 | + * @param float $total_time |
|
672 | + * @return string |
|
673 | + */ |
|
674 | + public function format_time($timer_name, $total_time) |
|
675 | + { |
|
676 | + return Benchmark::formatTime($timer_name, $total_time); |
|
677 | + } |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | |
@@ -684,31 +684,31 @@ discard block |
||
684 | 684 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
685 | 685 | */ |
686 | 686 | if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
687 | - function dump_wp_query() |
|
688 | - { |
|
689 | - global $wp_query; |
|
690 | - d($wp_query); |
|
691 | - } |
|
687 | + function dump_wp_query() |
|
688 | + { |
|
689 | + global $wp_query; |
|
690 | + d($wp_query); |
|
691 | + } |
|
692 | 692 | } |
693 | 693 | /** |
694 | 694 | * borrowed from Kint Debugger |
695 | 695 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
696 | 696 | */ |
697 | 697 | if (class_exists('Kint') && ! function_exists('dump_wp')) { |
698 | - function dump_wp() |
|
699 | - { |
|
700 | - global $wp; |
|
701 | - d($wp); |
|
702 | - } |
|
698 | + function dump_wp() |
|
699 | + { |
|
700 | + global $wp; |
|
701 | + d($wp); |
|
702 | + } |
|
703 | 703 | } |
704 | 704 | /** |
705 | 705 | * borrowed from Kint Debugger |
706 | 706 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
707 | 707 | */ |
708 | 708 | if (class_exists('Kint') && ! function_exists('dump_post')) { |
709 | - function dump_post() |
|
710 | - { |
|
711 | - global $post; |
|
712 | - d($post); |
|
713 | - } |
|
709 | + function dump_post() |
|
710 | + { |
|
711 | + global $post; |
|
712 | + d($post); |
|
713 | + } |
|
714 | 714 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | public static function instance() |
35 | 35 | { |
36 | 36 | // check if class object is instantiated, and instantiated properly |
37 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
37 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
38 | 38 | self::$_instance = new self(); |
39 | 39 | } |
40 | 40 | return self::$_instance; |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | private function __construct() |
49 | 49 | { |
50 | 50 | // load Kint PHP debugging library |
51 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')) { |
|
51 | + if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php')) { |
|
52 | 52 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
53 | 53 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
54 | 54 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
55 | 55 | // so we've moved it to our test folder so that it is not included with production releases |
56 | 56 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
57 | - require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
57 | + require_once(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php'); |
|
58 | 58 | } |
59 | 59 | // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
60 | 60 | // add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public static function show_db_name() |
76 | 76 | { |
77 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
77 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
78 | 78 | echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
79 | 79 | . DB_NAME |
80 | 80 | . '</p>'; |
@@ -123,12 +123,12 @@ discard block |
||
123 | 123 | global $wp_filter; |
124 | 124 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
125 | 125 | if ($tag) { |
126 | - $hook[ $tag ] = $wp_filter[ $tag ]; |
|
127 | - if (! is_array($hook[ $tag ])) { |
|
126 | + $hook[$tag] = $wp_filter[$tag]; |
|
127 | + if ( ! is_array($hook[$tag])) { |
|
128 | 128 | trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
129 | 129 | return; |
130 | 130 | } |
131 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
131 | + echo '<h5>For Tag: '.$tag.'</h5>'; |
|
132 | 132 | } else { |
133 | 133 | $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
134 | 134 | ksort($hook); |
@@ -157,12 +157,12 @@ discard block |
||
157 | 157 | { |
158 | 158 | $filters = array(); |
159 | 159 | global $wp_filter; |
160 | - if (isset($wp_filter[ $hook_name ])) { |
|
161 | - $filters[ $hook_name ] = array(); |
|
162 | - foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
163 | - $filters[ $hook_name ][ $priority ] = array(); |
|
160 | + if (isset($wp_filter[$hook_name])) { |
|
161 | + $filters[$hook_name] = array(); |
|
162 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
163 | + $filters[$hook_name][$priority] = array(); |
|
164 | 164 | foreach ($callbacks as $callback) { |
165 | - $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
165 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | } |
@@ -181,17 +181,17 @@ discard block |
||
181 | 181 | { |
182 | 182 | if (WP_DEBUG) { |
183 | 183 | $activation_errors = ob_get_contents(); |
184 | - if (! empty($activation_errors)) { |
|
185 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
184 | + if ( ! empty($activation_errors)) { |
|
185 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
186 | 186 | } |
187 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
187 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
188 | 188 | if (class_exists('EEH_File')) { |
189 | 189 | try { |
190 | 190 | EEH_File::ensure_file_exists_and_is_writable( |
191 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
191 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html' |
|
192 | 192 | ); |
193 | 193 | EEH_File::write_to_file( |
194 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
194 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html', |
|
195 | 195 | $activation_errors |
196 | 196 | ); |
197 | 197 | } catch (EE_Error $e) { |
@@ -211,11 +211,11 @@ discard block |
||
211 | 211 | } else { |
212 | 212 | // old school attempt |
213 | 213 | file_put_contents( |
214 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
214 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html', |
|
215 | 215 | $activation_errors |
216 | 216 | ); |
217 | 217 | } |
218 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
218 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
219 | 219 | update_option('ee_plugin_activation_errors', $activation_errors); |
220 | 220 | } |
221 | 221 | } |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | // don't trigger error if doing ajax, |
276 | 276 | // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
277 | 277 | if (defined('DOING_AJAX') && DOING_AJAX) { |
278 | - $error_message .= ' ' . esc_html__( |
|
278 | + $error_message .= ' '.esc_html__( |
|
279 | 279 | 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
280 | 280 | 'event_espresso' |
281 | 281 | ); |
@@ -319,19 +319,19 @@ discard block |
||
319 | 319 | $debug_key = 'EE_DEBUG_SPCO' |
320 | 320 | ) { |
321 | 321 | if (WP_DEBUG) { |
322 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
322 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
323 | 323 | $debug_data = get_option($debug_key, array()); |
324 | 324 | $default_data = array( |
325 | - $class => $func . '() : ' . $line, |
|
325 | + $class => $func.'() : '.$line, |
|
326 | 326 | 'REQ' => $display_request ? $_REQUEST : '', |
327 | 327 | ); |
328 | 328 | // don't serialize objects |
329 | 329 | $info = self::strip_objects($info); |
330 | 330 | $index = ! empty($debug_index) ? $debug_index : 0; |
331 | - if (! isset($debug_data[ $index ])) { |
|
332 | - $debug_data[ $index ] = array(); |
|
331 | + if ( ! isset($debug_data[$index])) { |
|
332 | + $debug_data[$index] = array(); |
|
333 | 333 | } |
334 | - $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
334 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
335 | 335 | update_option($debug_key, $debug_data); |
336 | 336 | } |
337 | 337 | } |
@@ -348,20 +348,20 @@ discard block |
||
348 | 348 | { |
349 | 349 | foreach ($info as $key => $value) { |
350 | 350 | if (is_array($value)) { |
351 | - $info[ $key ] = self::strip_objects($value); |
|
351 | + $info[$key] = self::strip_objects($value); |
|
352 | 352 | } elseif (is_object($value)) { |
353 | 353 | $object_class = get_class($value); |
354 | - $info[ $object_class ] = array(); |
|
355 | - $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
354 | + $info[$object_class] = array(); |
|
355 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
356 | 356 | if (method_exists($value, 'ID')) { |
357 | - $info[ $object_class ]['ID'] = $value->ID(); |
|
357 | + $info[$object_class]['ID'] = $value->ID(); |
|
358 | 358 | } |
359 | 359 | if (method_exists($value, 'status')) { |
360 | - $info[ $object_class ]['status'] = $value->status(); |
|
360 | + $info[$object_class]['status'] = $value->status(); |
|
361 | 361 | } elseif (method_exists($value, 'status_ID')) { |
362 | - $info[ $object_class ]['status'] = $value->status_ID(); |
|
362 | + $info[$object_class]['status'] = $value->status_ID(); |
|
363 | 363 | } |
364 | - unset($info[ $key ]); |
|
364 | + unset($info[$key]); |
|
365 | 365 | } |
366 | 366 | } |
367 | 367 | return (array) $info; |
@@ -395,8 +395,8 @@ discard block |
||
395 | 395 | $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
396 | 396 | $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
397 | 397 | $result .= $is_method |
398 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
399 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
398 | + ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()') |
|
399 | + : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var); |
|
400 | 400 | $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
401 | 401 | $result .= EEH_Debug_Tools::headingX($heading_tag); |
402 | 402 | if ($die) { |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | return $heading; |
451 | 451 | } |
452 | 452 | $margin = "25px 0 0 {$margin}"; |
453 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
453 | + return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>'; |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | if (EEH_Debug_Tools::plainOutput()) { |
465 | 465 | return ''; |
466 | 466 | } |
467 | - return '</' . $heading_tag . '>'; |
|
467 | + return '</'.$heading_tag.'>'; |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | if (EEH_Debug_Tools::plainOutput()) { |
479 | 479 | return $content; |
480 | 480 | } |
481 | - return '<span style="color:#999">' . $content . '</span>'; |
|
481 | + return '<span style="color:#999">'.$content.'</span>'; |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | |
@@ -518,7 +518,7 @@ discard block |
||
518 | 518 | if (EEH_Debug_Tools::plainOutput()) { |
519 | 519 | return $content; |
520 | 520 | } |
521 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
521 | + return '<span style="color:#E76700">'.$content.'</span>'; |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | if (EEH_Debug_Tools::plainOutput()) { |
536 | 536 | return $var; |
537 | 537 | } |
538 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
538 | + return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>'; |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
580 | 580 | $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
581 | 581 | $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
582 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
582 | + $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span( |
|
583 | 583 | EEH_Debug_Tools::pre_span($var) |
584 | 584 | ); |
585 | 585 | $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
@@ -5,35 +5,35 @@ discard block |
||
5 | 5 | use EventEspresso\core\services\loaders\LoaderFactory; |
6 | 6 | |
7 | 7 | if (! function_exists('espresso_get_template_part')) { |
8 | - /** |
|
9 | - * espresso_get_template_part |
|
10 | - * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
|
11 | - * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name |
|
12 | - * |
|
13 | - * @param string $slug The slug name for the generic template. |
|
14 | - * @param string $name The name of the specialised template. |
|
15 | - * @return string the html output for the formatted money value |
|
16 | - */ |
|
17 | - function espresso_get_template_part($slug = null, $name = null) |
|
18 | - { |
|
19 | - EEH_Template::get_template_part($slug, $name); |
|
20 | - } |
|
8 | + /** |
|
9 | + * espresso_get_template_part |
|
10 | + * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
|
11 | + * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name |
|
12 | + * |
|
13 | + * @param string $slug The slug name for the generic template. |
|
14 | + * @param string $name The name of the specialised template. |
|
15 | + * @return string the html output for the formatted money value |
|
16 | + */ |
|
17 | + function espresso_get_template_part($slug = null, $name = null) |
|
18 | + { |
|
19 | + EEH_Template::get_template_part($slug, $name); |
|
20 | + } |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | |
24 | 24 | if (! function_exists('espresso_get_object_css_class')) { |
25 | - /** |
|
26 | - * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
27 | - * |
|
28 | - * @param EE_Base_Class $object the EE object the css class is being generated for |
|
29 | - * @param string $prefix added to the beginning of the generated class |
|
30 | - * @param string $suffix added to the end of the generated class |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
34 | - { |
|
35 | - return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
36 | - } |
|
25 | + /** |
|
26 | + * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
27 | + * |
|
28 | + * @param EE_Base_Class $object the EE object the css class is being generated for |
|
29 | + * @param string $prefix added to the beginning of the generated class |
|
30 | + * @param string $suffix added to the end of the generated class |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
34 | + { |
|
35 | + return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
36 | + } |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | |
@@ -48,672 +48,672 @@ discard block |
||
48 | 48 | class EEH_Template |
49 | 49 | { |
50 | 50 | |
51 | - private static $_espresso_themes = array(); |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme |
|
56 | - * |
|
57 | - * @return boolean |
|
58 | - */ |
|
59 | - public static function is_espresso_theme() |
|
60 | - { |
|
61 | - return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then |
|
66 | - * load it's functions.php file ( if not already loaded ) |
|
67 | - * |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - public static function load_espresso_theme_functions() |
|
71 | - { |
|
72 | - if (! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
73 | - if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) { |
|
74 | - require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php'); |
|
75 | - } |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory |
|
82 | - * |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - public static function get_espresso_themes() |
|
86 | - { |
|
87 | - if (empty(EEH_Template::$_espresso_themes)) { |
|
88 | - $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
89 | - if (empty($espresso_themes)) { |
|
90 | - return array(); |
|
91 | - } |
|
92 | - if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
|
93 | - unset($espresso_themes[ $key ]); |
|
94 | - } |
|
95 | - EEH_Template::$_espresso_themes = array(); |
|
96 | - foreach ($espresso_themes as $espresso_theme) { |
|
97 | - EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme; |
|
98 | - } |
|
99 | - } |
|
100 | - return EEH_Template::$_espresso_themes; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * EEH_Template::get_template_part |
|
106 | - * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, |
|
107 | - * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS |
|
108 | - * filtering based off of the entire template part name |
|
109 | - * |
|
110 | - * @param string $slug The slug name for the generic template. |
|
111 | - * @param string $name The name of the specialised template. |
|
112 | - * @param array $template_args |
|
113 | - * @param bool $return_string |
|
114 | - * @return string the html output for the formatted money value |
|
115 | - */ |
|
116 | - public static function get_template_part( |
|
117 | - $slug = null, |
|
118 | - $name = null, |
|
119 | - $template_args = array(), |
|
120 | - $return_string = false |
|
121 | - ) { |
|
122 | - do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
|
123 | - $templates = array(); |
|
124 | - $name = (string) $name; |
|
125 | - if ($name != '') { |
|
126 | - $templates[] = "{$slug}-{$name}.php"; |
|
127 | - } |
|
128 | - // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
|
129 | - if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) { |
|
130 | - EEH_Template::locate_template($templates, $template_args, true, $return_string); |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * locate_template |
|
137 | - * locate a template file by looking in the following places, in the following order: |
|
138 | - * <server path up to>/wp-content/themes/<current active WordPress theme>/ |
|
139 | - * <assumed full absolute server path> |
|
140 | - * <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/ |
|
141 | - * <server path up to>/wp-content/uploads/espresso/templates/ |
|
142 | - * <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/ |
|
143 | - * <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/ |
|
144 | - * <server path up to>/wp-content/plugins/<EE4 folder>/ |
|
145 | - * as soon as the template is found in one of these locations, it will be returned or loaded |
|
146 | - * Example: |
|
147 | - * You are using the WordPress Twenty Sixteen theme, |
|
148 | - * and you want to customize the "some-event.template.php" template, |
|
149 | - * which is located in the "/relative/path/to/" folder relative to the main EE plugin folder. |
|
150 | - * Assuming WP is installed on your server in the "/home/public_html/" folder, |
|
151 | - * EEH_Template::locate_template() will look at the following paths in order until the template is found: |
|
152 | - * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
153 | - * /relative/path/to/some-event.template.php |
|
154 | - * /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
155 | - * /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php |
|
156 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
157 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
158 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php |
|
159 | - * Had you passed an absolute path to your template that was in some other location, |
|
160 | - * ie: "/absolute/path/to/some-event.template.php" |
|
161 | - * then the search would have been : |
|
162 | - * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
163 | - * /absolute/path/to/some-event.template.php |
|
164 | - * and stopped there upon finding it in the second location |
|
165 | - * |
|
166 | - * @param array|string $templates array of template file names including extension (or just a single string) |
|
167 | - * @param array $template_args an array of arguments to be extracted for use in the template |
|
168 | - * @param boolean $load whether to pass the located template path on to the |
|
169 | - * EEH_Template::display_template() method or simply return it |
|
170 | - * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
171 | - * string |
|
172 | - * @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will |
|
173 | - * generate a custom template or not. Used in places where you don't actually |
|
174 | - * load the template, you just want to know if there's a custom version of it. |
|
175 | - * @return mixed |
|
176 | - * @throws DomainException |
|
177 | - * @throws InvalidArgumentException |
|
178 | - * @throws InvalidDataTypeException |
|
179 | - * @throws InvalidInterfaceException |
|
180 | - */ |
|
181 | - public static function locate_template( |
|
182 | - $templates = array(), |
|
183 | - $template_args = array(), |
|
184 | - $load = true, |
|
185 | - $return_string = true, |
|
186 | - $check_if_custom = false |
|
187 | - ) { |
|
188 | - // first use WP locate_template to check for template in the current theme folder |
|
189 | - $template_path = locate_template($templates); |
|
190 | - |
|
191 | - if ($check_if_custom && ! empty($template_path)) { |
|
192 | - return true; |
|
193 | - } |
|
194 | - |
|
195 | - // not in the theme |
|
196 | - if (empty($template_path)) { |
|
197 | - // not even a template to look for ? |
|
198 | - if (empty($templates)) { |
|
199 | - // get post_type |
|
200 | - $post_type = EE_Registry::instance()->REQ->get('post_type'); |
|
201 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
202 | - $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
203 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
204 | - ); |
|
205 | - // get array of EE Custom Post Types |
|
206 | - $EE_CPTs = $custom_post_types->getDefinitions(); |
|
207 | - // build template name based on request |
|
208 | - if (isset($EE_CPTs[ $post_type ])) { |
|
209 | - $archive_or_single = is_archive() ? 'archive' : ''; |
|
210 | - $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
211 | - $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
212 | - } |
|
213 | - } |
|
214 | - // currently active EE template theme |
|
215 | - $current_theme = EE_Config::get_current_theme(); |
|
216 | - |
|
217 | - // array of paths to folders that may contain templates |
|
218 | - $template_folder_paths = array( |
|
219 | - // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
|
220 | - EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
221 | - // then in the root of the /wp-content/uploads/espresso/templates/ folder |
|
222 | - EVENT_ESPRESSO_TEMPLATE_DIR, |
|
223 | - ); |
|
224 | - |
|
225 | - // add core plugin folders for checking only if we're not $check_if_custom |
|
226 | - if (! $check_if_custom) { |
|
227 | - $core_paths = array( |
|
228 | - // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
|
229 | - EE_PUBLIC . $current_theme, |
|
230 | - // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
|
231 | - EE_TEMPLATES . $current_theme, |
|
232 | - // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
|
233 | - EE_PLUGIN_DIR_PATH, |
|
234 | - ); |
|
235 | - $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
236 | - } |
|
237 | - |
|
238 | - // now filter that array |
|
239 | - $template_folder_paths = apply_filters( |
|
240 | - 'FHEE__EEH_Template__locate_template__template_folder_paths', |
|
241 | - $template_folder_paths |
|
242 | - ); |
|
243 | - $templates = is_array($templates) ? $templates : array($templates); |
|
244 | - $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths); |
|
245 | - // array to hold all possible template paths |
|
246 | - $full_template_paths = array(); |
|
247 | - |
|
248 | - // loop through $templates |
|
249 | - foreach ($templates as $template) { |
|
250 | - // normalize directory separators |
|
251 | - $template = EEH_File::standardise_directory_separators($template); |
|
252 | - $file_name = basename($template); |
|
253 | - $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
254 | - // while looping through all template folder paths |
|
255 | - foreach ($template_folder_paths as $template_folder_path) { |
|
256 | - // normalize directory separators |
|
257 | - $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
258 | - // determine if any common base path exists between the two paths |
|
259 | - $common_base_path = EEH_Template::_find_common_base_path( |
|
260 | - array($template_folder_path, $template_path_minus_file_name) |
|
261 | - ); |
|
262 | - if ($common_base_path !== '') { |
|
263 | - // both paths have a common base, so just tack the filename onto our search path |
|
264 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
265 | - } else { |
|
266 | - // no common base path, so let's just concatenate |
|
267 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
268 | - } |
|
269 | - // build up our template locations array by adding our resolved paths |
|
270 | - $full_template_paths[] = $resolved_path; |
|
271 | - } |
|
272 | - // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
|
273 | - array_unshift($full_template_paths, $template); |
|
274 | - // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
|
275 | - array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name); |
|
276 | - } |
|
277 | - // filter final array of full template paths |
|
278 | - $full_template_paths = apply_filters( |
|
279 | - 'FHEE__EEH_Template__locate_template__full_template_paths', |
|
280 | - $full_template_paths, |
|
281 | - $file_name |
|
282 | - ); |
|
283 | - // now loop through our final array of template location paths and check each location |
|
284 | - foreach ((array) $full_template_paths as $full_template_path) { |
|
285 | - if (is_readable($full_template_path)) { |
|
286 | - $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path); |
|
287 | - break; |
|
288 | - } |
|
289 | - } |
|
290 | - } |
|
291 | - |
|
292 | - // hook that can be used to display the full template path that will be used |
|
293 | - do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
294 | - |
|
295 | - // if we got it and you want to see it... |
|
296 | - if ($template_path && $load && ! $check_if_custom) { |
|
297 | - if ($return_string) { |
|
298 | - return EEH_Template::display_template($template_path, $template_args, true); |
|
299 | - } else { |
|
300 | - EEH_Template::display_template($template_path, $template_args, false); |
|
301 | - } |
|
302 | - } |
|
303 | - return $check_if_custom && ! empty($template_path) ? true : $template_path; |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * _find_common_base_path |
|
309 | - * given two paths, this determines if there is a common base path between the two |
|
310 | - * |
|
311 | - * @param array $paths |
|
312 | - * @return string |
|
313 | - */ |
|
314 | - protected static function _find_common_base_path($paths) |
|
315 | - { |
|
316 | - $last_offset = 0; |
|
317 | - $common_base_path = ''; |
|
318 | - while (($index = strpos($paths[0], '/', $last_offset)) !== false) { |
|
319 | - $dir_length = $index - $last_offset + 1; |
|
320 | - $directory = substr($paths[0], $last_offset, $dir_length); |
|
321 | - foreach ($paths as $path) { |
|
322 | - if (substr($path, $last_offset, $dir_length) != $directory) { |
|
323 | - return $common_base_path; |
|
324 | - } |
|
325 | - } |
|
326 | - $common_base_path .= $directory; |
|
327 | - $last_offset = $index + 1; |
|
328 | - } |
|
329 | - return substr($common_base_path, 0, -1); |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * load and display a template |
|
335 | - * |
|
336 | - * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
|
337 | - * @param array $template_args an array of arguments to be extracted for use in the template |
|
338 | - * @param boolean $return_string whether to send output immediately to screen, or capture and return as a string |
|
339 | - * @param bool $throw_exceptions if set to true, will throw an exception if the template is either |
|
340 | - * not found or is not readable |
|
341 | - * @return mixed string |
|
342 | - * @throws \DomainException |
|
343 | - */ |
|
344 | - public static function display_template( |
|
345 | - $template_path = false, |
|
346 | - $template_args = array(), |
|
347 | - $return_string = false, |
|
348 | - $throw_exceptions = false |
|
349 | - ) { |
|
350 | - |
|
351 | - /** |
|
352 | - * These two filters are intended for last minute changes to templates being loaded and/or template arg |
|
353 | - * modifications. NOTE... modifying these things can cause breakage as most templates running through |
|
354 | - * the display_template method are templates we DON'T want modified (usually because of js |
|
355 | - * dependencies etc). So unless you know what you are doing, do NOT filter templates or template args |
|
356 | - * using this. |
|
357 | - * |
|
358 | - * @since 4.6.0 |
|
359 | - */ |
|
360 | - $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
361 | - $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
|
362 | - |
|
363 | - // you gimme nuttin - YOU GET NUTTIN !! |
|
364 | - if (! $template_path || ! is_readable($template_path)) { |
|
365 | - return ''; |
|
366 | - } |
|
367 | - // if $template_args are not in an array, then make it so |
|
368 | - if (! is_array($template_args) && ! is_object($template_args)) { |
|
369 | - $template_args = array($template_args); |
|
370 | - } |
|
371 | - extract($template_args, EXTR_SKIP); |
|
372 | - // ignore whether template is accessible ? |
|
373 | - if ($throw_exceptions && ! is_readable($template_path)) { |
|
374 | - throw new \DomainException( |
|
375 | - esc_html__( |
|
376 | - 'Invalid, unreadable, or missing file.', |
|
377 | - 'event_espresso' |
|
378 | - ) |
|
379 | - ); |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - if ($return_string) { |
|
384 | - // because we want to return a string, we are going to capture the output |
|
385 | - ob_start(); |
|
386 | - include($template_path); |
|
387 | - return ob_get_clean(); |
|
388 | - } else { |
|
389 | - include($template_path); |
|
390 | - } |
|
391 | - return ''; |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - /** |
|
396 | - * get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
397 | - * |
|
398 | - * @param EE_Base_Class $object the EE object the css class is being generated for |
|
399 | - * @param string $prefix added to the beginning of the generated class |
|
400 | - * @param string $suffix added to the end of the generated class |
|
401 | - * @return string |
|
402 | - */ |
|
403 | - public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
404 | - { |
|
405 | - // in the beginning... |
|
406 | - $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
407 | - // da muddle |
|
408 | - $class = ''; |
|
409 | - // the end |
|
410 | - $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
411 | - // is the passed object an EE object ? |
|
412 | - if ($object instanceof EE_Base_Class) { |
|
413 | - // grab the exact type of object |
|
414 | - $obj_class = get_class($object); |
|
415 | - // depending on the type of object... |
|
416 | - switch ($obj_class) { |
|
417 | - // no specifics just yet... |
|
418 | - default: |
|
419 | - $class = strtolower(str_replace('_', '-', $obj_class)); |
|
420 | - $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
421 | - } |
|
422 | - } |
|
423 | - return $prefix . $class . $suffix; |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * EEH_Template::format_currency |
|
430 | - * This helper takes a raw float value and formats it according to the default config country currency settings, or |
|
431 | - * the country currency settings from the supplied country ISO code |
|
432 | - * |
|
433 | - * @param float $amount raw money value |
|
434 | - * @param boolean $return_raw whether to return the formatted float value only with no currency sign or code |
|
435 | - * @param boolean $display_code whether to display the country code (USD). Default = TRUE |
|
436 | - * @param string $CNT_ISO 2 letter ISO code for a country |
|
437 | - * @param string $cur_code_span_class |
|
438 | - * @return string the html output for the formatted money value |
|
439 | - * @throws \EE_Error |
|
440 | - */ |
|
441 | - public static function format_currency( |
|
442 | - $amount = null, |
|
443 | - $return_raw = false, |
|
444 | - $display_code = true, |
|
445 | - $CNT_ISO = '', |
|
446 | - $cur_code_span_class = 'currency-code' |
|
447 | - ) { |
|
448 | - // ensure amount was received |
|
449 | - if ($amount === null) { |
|
450 | - $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
451 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
452 | - return ''; |
|
453 | - } |
|
454 | - // ensure amount is float |
|
455 | - $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount); |
|
456 | - $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
457 | - // filter raw amount (allows 0.00 to be changed to "free" for example) |
|
458 | - $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
459 | - // still a number or was amount converted to a string like "free" ? |
|
460 | - if (is_float($amount_formatted)) { |
|
461 | - // was a country ISO code passed ? if so generate currency config object for that country |
|
462 | - $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
463 | - // verify results |
|
464 | - if (! $mny instanceof EE_Currency_Config) { |
|
465 | - // set default config country currency settings |
|
466 | - $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
467 | - ? EE_Registry::instance()->CFG->currency |
|
468 | - : new EE_Currency_Config(); |
|
469 | - } |
|
470 | - // format float |
|
471 | - $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
472 | - // add formatting ? |
|
473 | - if (! $return_raw) { |
|
474 | - // add currency sign |
|
475 | - if ($mny->sign_b4) { |
|
476 | - if ($amount >= 0) { |
|
477 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
478 | - } else { |
|
479 | - $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
480 | - } |
|
481 | - } else { |
|
482 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
483 | - } |
|
484 | - |
|
485 | - // filter to allow global setting of display_code |
|
486 | - $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
|
487 | - |
|
488 | - // add currency code ? |
|
489 | - $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
490 | - } |
|
491 | - // filter results |
|
492 | - $amount_formatted = apply_filters( |
|
493 | - 'FHEE__EEH_Template__format_currency__amount_formatted', |
|
494 | - $amount_formatted, |
|
495 | - $mny, |
|
496 | - $return_raw |
|
497 | - ); |
|
498 | - } |
|
499 | - // clean up vars |
|
500 | - unset($mny); |
|
501 | - // return formatted currency amount |
|
502 | - return $amount_formatted; |
|
503 | - } |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * This function is used for outputting the localized label for a given status id in the schema requested (and |
|
508 | - * possibly plural). The intended use of this function is only for cases where wanting a label outside of a |
|
509 | - * related status model or model object (i.e. in documentation etc.) |
|
510 | - * |
|
511 | - * @param string $status_id Status ID matching a registered status in the esp_status table. If there is no |
|
512 | - * match, then 'Unknown' will be returned. |
|
513 | - * @param boolean $plural Whether to return plural or not |
|
514 | - * @param string $schema 'UPPER', 'lower', or 'Sentence' |
|
515 | - * @return string The localized label for the status id. |
|
516 | - */ |
|
517 | - public static function pretty_status($status_id, $plural = false, $schema = 'upper') |
|
518 | - { |
|
519 | - /** @type EEM_Status $EEM_Status */ |
|
520 | - $EEM_Status = EE_Registry::instance()->load_model('Status'); |
|
521 | - $status = $EEM_Status->localized_status( |
|
522 | - array($status_id => __('unknown', 'event_espresso')), |
|
523 | - $plural, |
|
524 | - $schema |
|
525 | - ); |
|
526 | - return $status[ $status_id ]; |
|
527 | - } |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * This helper just returns a button or link for the given parameters |
|
532 | - * |
|
533 | - * @param string $url the url for the link, note that `esc_url` will be called on it |
|
534 | - * @param string $label What is the label you want displayed for the button |
|
535 | - * @param string $class what class is used for the button (defaults to 'button-primary') |
|
536 | - * @param string $icon |
|
537 | - * @param string $title |
|
538 | - * @return string the html output for the button |
|
539 | - */ |
|
540 | - public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '') |
|
541 | - { |
|
542 | - $icon_html = ''; |
|
543 | - if (! empty($icon)) { |
|
544 | - $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
545 | - $dashicons = array_filter($dashicons); |
|
546 | - $count = count($dashicons); |
|
547 | - $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
|
548 | - foreach ($dashicons as $dashicon) { |
|
549 | - $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
550 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
551 | - } |
|
552 | - $icon_html .= $count > 1 ? '</span>' : ''; |
|
553 | - } |
|
554 | - $label = ! empty($icon) ? $icon_html . $label : $label; |
|
555 | - $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
556 | - return $button; |
|
557 | - } |
|
558 | - |
|
559 | - |
|
560 | - /** |
|
561 | - * This returns a generated link that will load the related help tab on admin pages. |
|
562 | - * |
|
563 | - * @param string $help_tab_id the id for the connected help tab |
|
564 | - * @param bool|string $page The page identifier for the page the help tab is on |
|
565 | - * @param bool|string $action The action (route) for the admin page the help tab is on. |
|
566 | - * @param bool|string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
567 | - * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
|
568 | - * @return string generated link |
|
569 | - */ |
|
570 | - public static function get_help_tab_link( |
|
571 | - $help_tab_id, |
|
572 | - $page = false, |
|
573 | - $action = false, |
|
574 | - $icon_style = false, |
|
575 | - $help_text = false |
|
576 | - ) { |
|
577 | - |
|
578 | - if (! $page) { |
|
579 | - $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page; |
|
580 | - } |
|
581 | - |
|
582 | - if (! $action) { |
|
583 | - $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action; |
|
584 | - } |
|
585 | - |
|
586 | - $action = empty($action) ? 'default' : $action; |
|
587 | - |
|
588 | - |
|
589 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
590 | - $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
|
591 | - $help_text = ! $help_text ? '' : $help_text; |
|
592 | - return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__( |
|
593 | - 'Click to open the \'Help\' tab for more information about this feature.', |
|
594 | - 'event_espresso' |
|
595 | - ) . '" > ' . $help_text . ' </a>'; |
|
596 | - } |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * This helper generates the html structure for the jquery joyride plugin with the given params. |
|
601 | - * |
|
602 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
603 | - * @see EE_Admin_Page->_stop_callback() for the construct expected for the $stops param. |
|
604 | - * @param EE_Help_Tour |
|
605 | - * @return string html |
|
606 | - */ |
|
607 | - public static function help_tour_stops_generator(EE_Help_Tour $tour) |
|
608 | - { |
|
609 | - $id = $tour->get_slug(); |
|
610 | - $stops = $tour->get_stops(); |
|
611 | - |
|
612 | - $content = '<ol style="display:none" id="' . $id . '">'; |
|
613 | - |
|
614 | - foreach ($stops as $stop) { |
|
615 | - $data_id = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
616 | - $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
617 | - |
|
618 | - // if container is set to modal then let's make sure we set the options accordingly |
|
619 | - if (empty($data_id) && empty($data_class)) { |
|
620 | - $stop['options']['modal'] = true; |
|
621 | - $stop['options']['expose'] = true; |
|
622 | - } |
|
623 | - |
|
624 | - $custom_class = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
625 | - $button_text = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
626 | - $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
|
627 | - |
|
628 | - // options |
|
629 | - if (isset($stop['options']) && is_array($stop['options'])) { |
|
630 | - $options = ' data-options="'; |
|
631 | - foreach ($stop['options'] as $option => $value) { |
|
632 | - $options .= $option . ':' . $value . ';'; |
|
633 | - } |
|
634 | - $options .= '"'; |
|
635 | - } else { |
|
636 | - $options = ''; |
|
637 | - } |
|
638 | - |
|
639 | - // let's put all together |
|
640 | - $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
641 | - } |
|
642 | - |
|
643 | - $content .= '</ol>'; |
|
644 | - return $content; |
|
645 | - } |
|
646 | - |
|
647 | - |
|
648 | - /** |
|
649 | - * This is a helper method to generate a status legend for a given status array. |
|
650 | - * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods |
|
651 | - * status_array. |
|
652 | - * |
|
653 | - * @param array $status_array array of statuses that will make up the legend. In format: |
|
654 | - * array( |
|
655 | - * 'status_item' => 'status_name' |
|
656 | - * ) |
|
657 | - * @param string $active_status This is used to indicate what the active status is IF that is to be highlighted in |
|
658 | - * the legend. |
|
659 | - * @throws EE_Error |
|
660 | - * @return string html structure for status. |
|
661 | - */ |
|
662 | - public static function status_legend($status_array, $active_status = '') |
|
663 | - { |
|
664 | - if (! is_array($status_array)) { |
|
665 | - throw new EE_Error(esc_html__( |
|
666 | - 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
|
667 | - 'event_espresso' |
|
668 | - )); |
|
669 | - } |
|
670 | - |
|
671 | - $setup_array = array(); |
|
672 | - foreach ($status_array as $item => $status) { |
|
673 | - $setup_array[ $item ] = array( |
|
674 | - 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
675 | - 'desc' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
676 | - 'status' => $status, |
|
677 | - ); |
|
678 | - } |
|
679 | - |
|
680 | - $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
681 | - $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n"; |
|
682 | - $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
683 | - foreach ($setup_array as $item => $details) { |
|
684 | - $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
|
685 | - $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
686 | - $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
687 | - $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
688 | - $content .= '</dt>' . "\n"; |
|
689 | - } |
|
690 | - $content .= '</dl>' . "\n"; |
|
691 | - $content .= '</div>' . "\n"; |
|
692 | - return $content; |
|
693 | - } |
|
694 | - |
|
695 | - |
|
696 | - /** |
|
697 | - * Gets HTML for laying out a deeply-nested array (and objects) in a format |
|
698 | - * that's nice for presenting in the wp admin |
|
699 | - * |
|
700 | - * @param mixed $data |
|
701 | - * @return string |
|
702 | - */ |
|
703 | - public static function layout_array_as_table($data) |
|
704 | - { |
|
705 | - if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
706 | - $data = (array) $data; |
|
707 | - } |
|
708 | - ob_start(); |
|
709 | - if (is_array($data)) { |
|
710 | - if (EEH_Array::is_associative_array($data)) { |
|
711 | - ?> |
|
51 | + private static $_espresso_themes = array(); |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme |
|
56 | + * |
|
57 | + * @return boolean |
|
58 | + */ |
|
59 | + public static function is_espresso_theme() |
|
60 | + { |
|
61 | + return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then |
|
66 | + * load it's functions.php file ( if not already loaded ) |
|
67 | + * |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + public static function load_espresso_theme_functions() |
|
71 | + { |
|
72 | + if (! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
73 | + if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) { |
|
74 | + require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php'); |
|
75 | + } |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory |
|
82 | + * |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + public static function get_espresso_themes() |
|
86 | + { |
|
87 | + if (empty(EEH_Template::$_espresso_themes)) { |
|
88 | + $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
89 | + if (empty($espresso_themes)) { |
|
90 | + return array(); |
|
91 | + } |
|
92 | + if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
|
93 | + unset($espresso_themes[ $key ]); |
|
94 | + } |
|
95 | + EEH_Template::$_espresso_themes = array(); |
|
96 | + foreach ($espresso_themes as $espresso_theme) { |
|
97 | + EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme; |
|
98 | + } |
|
99 | + } |
|
100 | + return EEH_Template::$_espresso_themes; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * EEH_Template::get_template_part |
|
106 | + * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, |
|
107 | + * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS |
|
108 | + * filtering based off of the entire template part name |
|
109 | + * |
|
110 | + * @param string $slug The slug name for the generic template. |
|
111 | + * @param string $name The name of the specialised template. |
|
112 | + * @param array $template_args |
|
113 | + * @param bool $return_string |
|
114 | + * @return string the html output for the formatted money value |
|
115 | + */ |
|
116 | + public static function get_template_part( |
|
117 | + $slug = null, |
|
118 | + $name = null, |
|
119 | + $template_args = array(), |
|
120 | + $return_string = false |
|
121 | + ) { |
|
122 | + do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
|
123 | + $templates = array(); |
|
124 | + $name = (string) $name; |
|
125 | + if ($name != '') { |
|
126 | + $templates[] = "{$slug}-{$name}.php"; |
|
127 | + } |
|
128 | + // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
|
129 | + if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) { |
|
130 | + EEH_Template::locate_template($templates, $template_args, true, $return_string); |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * locate_template |
|
137 | + * locate a template file by looking in the following places, in the following order: |
|
138 | + * <server path up to>/wp-content/themes/<current active WordPress theme>/ |
|
139 | + * <assumed full absolute server path> |
|
140 | + * <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/ |
|
141 | + * <server path up to>/wp-content/uploads/espresso/templates/ |
|
142 | + * <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/ |
|
143 | + * <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/ |
|
144 | + * <server path up to>/wp-content/plugins/<EE4 folder>/ |
|
145 | + * as soon as the template is found in one of these locations, it will be returned or loaded |
|
146 | + * Example: |
|
147 | + * You are using the WordPress Twenty Sixteen theme, |
|
148 | + * and you want to customize the "some-event.template.php" template, |
|
149 | + * which is located in the "/relative/path/to/" folder relative to the main EE plugin folder. |
|
150 | + * Assuming WP is installed on your server in the "/home/public_html/" folder, |
|
151 | + * EEH_Template::locate_template() will look at the following paths in order until the template is found: |
|
152 | + * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
153 | + * /relative/path/to/some-event.template.php |
|
154 | + * /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
155 | + * /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php |
|
156 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
157 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
158 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php |
|
159 | + * Had you passed an absolute path to your template that was in some other location, |
|
160 | + * ie: "/absolute/path/to/some-event.template.php" |
|
161 | + * then the search would have been : |
|
162 | + * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
163 | + * /absolute/path/to/some-event.template.php |
|
164 | + * and stopped there upon finding it in the second location |
|
165 | + * |
|
166 | + * @param array|string $templates array of template file names including extension (or just a single string) |
|
167 | + * @param array $template_args an array of arguments to be extracted for use in the template |
|
168 | + * @param boolean $load whether to pass the located template path on to the |
|
169 | + * EEH_Template::display_template() method or simply return it |
|
170 | + * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
171 | + * string |
|
172 | + * @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will |
|
173 | + * generate a custom template or not. Used in places where you don't actually |
|
174 | + * load the template, you just want to know if there's a custom version of it. |
|
175 | + * @return mixed |
|
176 | + * @throws DomainException |
|
177 | + * @throws InvalidArgumentException |
|
178 | + * @throws InvalidDataTypeException |
|
179 | + * @throws InvalidInterfaceException |
|
180 | + */ |
|
181 | + public static function locate_template( |
|
182 | + $templates = array(), |
|
183 | + $template_args = array(), |
|
184 | + $load = true, |
|
185 | + $return_string = true, |
|
186 | + $check_if_custom = false |
|
187 | + ) { |
|
188 | + // first use WP locate_template to check for template in the current theme folder |
|
189 | + $template_path = locate_template($templates); |
|
190 | + |
|
191 | + if ($check_if_custom && ! empty($template_path)) { |
|
192 | + return true; |
|
193 | + } |
|
194 | + |
|
195 | + // not in the theme |
|
196 | + if (empty($template_path)) { |
|
197 | + // not even a template to look for ? |
|
198 | + if (empty($templates)) { |
|
199 | + // get post_type |
|
200 | + $post_type = EE_Registry::instance()->REQ->get('post_type'); |
|
201 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
202 | + $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
203 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
204 | + ); |
|
205 | + // get array of EE Custom Post Types |
|
206 | + $EE_CPTs = $custom_post_types->getDefinitions(); |
|
207 | + // build template name based on request |
|
208 | + if (isset($EE_CPTs[ $post_type ])) { |
|
209 | + $archive_or_single = is_archive() ? 'archive' : ''; |
|
210 | + $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
211 | + $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
212 | + } |
|
213 | + } |
|
214 | + // currently active EE template theme |
|
215 | + $current_theme = EE_Config::get_current_theme(); |
|
216 | + |
|
217 | + // array of paths to folders that may contain templates |
|
218 | + $template_folder_paths = array( |
|
219 | + // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
|
220 | + EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
221 | + // then in the root of the /wp-content/uploads/espresso/templates/ folder |
|
222 | + EVENT_ESPRESSO_TEMPLATE_DIR, |
|
223 | + ); |
|
224 | + |
|
225 | + // add core plugin folders for checking only if we're not $check_if_custom |
|
226 | + if (! $check_if_custom) { |
|
227 | + $core_paths = array( |
|
228 | + // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
|
229 | + EE_PUBLIC . $current_theme, |
|
230 | + // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
|
231 | + EE_TEMPLATES . $current_theme, |
|
232 | + // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
|
233 | + EE_PLUGIN_DIR_PATH, |
|
234 | + ); |
|
235 | + $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
236 | + } |
|
237 | + |
|
238 | + // now filter that array |
|
239 | + $template_folder_paths = apply_filters( |
|
240 | + 'FHEE__EEH_Template__locate_template__template_folder_paths', |
|
241 | + $template_folder_paths |
|
242 | + ); |
|
243 | + $templates = is_array($templates) ? $templates : array($templates); |
|
244 | + $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths); |
|
245 | + // array to hold all possible template paths |
|
246 | + $full_template_paths = array(); |
|
247 | + |
|
248 | + // loop through $templates |
|
249 | + foreach ($templates as $template) { |
|
250 | + // normalize directory separators |
|
251 | + $template = EEH_File::standardise_directory_separators($template); |
|
252 | + $file_name = basename($template); |
|
253 | + $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
254 | + // while looping through all template folder paths |
|
255 | + foreach ($template_folder_paths as $template_folder_path) { |
|
256 | + // normalize directory separators |
|
257 | + $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
258 | + // determine if any common base path exists between the two paths |
|
259 | + $common_base_path = EEH_Template::_find_common_base_path( |
|
260 | + array($template_folder_path, $template_path_minus_file_name) |
|
261 | + ); |
|
262 | + if ($common_base_path !== '') { |
|
263 | + // both paths have a common base, so just tack the filename onto our search path |
|
264 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
265 | + } else { |
|
266 | + // no common base path, so let's just concatenate |
|
267 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
268 | + } |
|
269 | + // build up our template locations array by adding our resolved paths |
|
270 | + $full_template_paths[] = $resolved_path; |
|
271 | + } |
|
272 | + // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
|
273 | + array_unshift($full_template_paths, $template); |
|
274 | + // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
|
275 | + array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name); |
|
276 | + } |
|
277 | + // filter final array of full template paths |
|
278 | + $full_template_paths = apply_filters( |
|
279 | + 'FHEE__EEH_Template__locate_template__full_template_paths', |
|
280 | + $full_template_paths, |
|
281 | + $file_name |
|
282 | + ); |
|
283 | + // now loop through our final array of template location paths and check each location |
|
284 | + foreach ((array) $full_template_paths as $full_template_path) { |
|
285 | + if (is_readable($full_template_path)) { |
|
286 | + $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path); |
|
287 | + break; |
|
288 | + } |
|
289 | + } |
|
290 | + } |
|
291 | + |
|
292 | + // hook that can be used to display the full template path that will be used |
|
293 | + do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
294 | + |
|
295 | + // if we got it and you want to see it... |
|
296 | + if ($template_path && $load && ! $check_if_custom) { |
|
297 | + if ($return_string) { |
|
298 | + return EEH_Template::display_template($template_path, $template_args, true); |
|
299 | + } else { |
|
300 | + EEH_Template::display_template($template_path, $template_args, false); |
|
301 | + } |
|
302 | + } |
|
303 | + return $check_if_custom && ! empty($template_path) ? true : $template_path; |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * _find_common_base_path |
|
309 | + * given two paths, this determines if there is a common base path between the two |
|
310 | + * |
|
311 | + * @param array $paths |
|
312 | + * @return string |
|
313 | + */ |
|
314 | + protected static function _find_common_base_path($paths) |
|
315 | + { |
|
316 | + $last_offset = 0; |
|
317 | + $common_base_path = ''; |
|
318 | + while (($index = strpos($paths[0], '/', $last_offset)) !== false) { |
|
319 | + $dir_length = $index - $last_offset + 1; |
|
320 | + $directory = substr($paths[0], $last_offset, $dir_length); |
|
321 | + foreach ($paths as $path) { |
|
322 | + if (substr($path, $last_offset, $dir_length) != $directory) { |
|
323 | + return $common_base_path; |
|
324 | + } |
|
325 | + } |
|
326 | + $common_base_path .= $directory; |
|
327 | + $last_offset = $index + 1; |
|
328 | + } |
|
329 | + return substr($common_base_path, 0, -1); |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * load and display a template |
|
335 | + * |
|
336 | + * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
|
337 | + * @param array $template_args an array of arguments to be extracted for use in the template |
|
338 | + * @param boolean $return_string whether to send output immediately to screen, or capture and return as a string |
|
339 | + * @param bool $throw_exceptions if set to true, will throw an exception if the template is either |
|
340 | + * not found or is not readable |
|
341 | + * @return mixed string |
|
342 | + * @throws \DomainException |
|
343 | + */ |
|
344 | + public static function display_template( |
|
345 | + $template_path = false, |
|
346 | + $template_args = array(), |
|
347 | + $return_string = false, |
|
348 | + $throw_exceptions = false |
|
349 | + ) { |
|
350 | + |
|
351 | + /** |
|
352 | + * These two filters are intended for last minute changes to templates being loaded and/or template arg |
|
353 | + * modifications. NOTE... modifying these things can cause breakage as most templates running through |
|
354 | + * the display_template method are templates we DON'T want modified (usually because of js |
|
355 | + * dependencies etc). So unless you know what you are doing, do NOT filter templates or template args |
|
356 | + * using this. |
|
357 | + * |
|
358 | + * @since 4.6.0 |
|
359 | + */ |
|
360 | + $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
361 | + $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
|
362 | + |
|
363 | + // you gimme nuttin - YOU GET NUTTIN !! |
|
364 | + if (! $template_path || ! is_readable($template_path)) { |
|
365 | + return ''; |
|
366 | + } |
|
367 | + // if $template_args are not in an array, then make it so |
|
368 | + if (! is_array($template_args) && ! is_object($template_args)) { |
|
369 | + $template_args = array($template_args); |
|
370 | + } |
|
371 | + extract($template_args, EXTR_SKIP); |
|
372 | + // ignore whether template is accessible ? |
|
373 | + if ($throw_exceptions && ! is_readable($template_path)) { |
|
374 | + throw new \DomainException( |
|
375 | + esc_html__( |
|
376 | + 'Invalid, unreadable, or missing file.', |
|
377 | + 'event_espresso' |
|
378 | + ) |
|
379 | + ); |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + if ($return_string) { |
|
384 | + // because we want to return a string, we are going to capture the output |
|
385 | + ob_start(); |
|
386 | + include($template_path); |
|
387 | + return ob_get_clean(); |
|
388 | + } else { |
|
389 | + include($template_path); |
|
390 | + } |
|
391 | + return ''; |
|
392 | + } |
|
393 | + |
|
394 | + |
|
395 | + /** |
|
396 | + * get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
397 | + * |
|
398 | + * @param EE_Base_Class $object the EE object the css class is being generated for |
|
399 | + * @param string $prefix added to the beginning of the generated class |
|
400 | + * @param string $suffix added to the end of the generated class |
|
401 | + * @return string |
|
402 | + */ |
|
403 | + public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
404 | + { |
|
405 | + // in the beginning... |
|
406 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
407 | + // da muddle |
|
408 | + $class = ''; |
|
409 | + // the end |
|
410 | + $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
411 | + // is the passed object an EE object ? |
|
412 | + if ($object instanceof EE_Base_Class) { |
|
413 | + // grab the exact type of object |
|
414 | + $obj_class = get_class($object); |
|
415 | + // depending on the type of object... |
|
416 | + switch ($obj_class) { |
|
417 | + // no specifics just yet... |
|
418 | + default: |
|
419 | + $class = strtolower(str_replace('_', '-', $obj_class)); |
|
420 | + $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
421 | + } |
|
422 | + } |
|
423 | + return $prefix . $class . $suffix; |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * EEH_Template::format_currency |
|
430 | + * This helper takes a raw float value and formats it according to the default config country currency settings, or |
|
431 | + * the country currency settings from the supplied country ISO code |
|
432 | + * |
|
433 | + * @param float $amount raw money value |
|
434 | + * @param boolean $return_raw whether to return the formatted float value only with no currency sign or code |
|
435 | + * @param boolean $display_code whether to display the country code (USD). Default = TRUE |
|
436 | + * @param string $CNT_ISO 2 letter ISO code for a country |
|
437 | + * @param string $cur_code_span_class |
|
438 | + * @return string the html output for the formatted money value |
|
439 | + * @throws \EE_Error |
|
440 | + */ |
|
441 | + public static function format_currency( |
|
442 | + $amount = null, |
|
443 | + $return_raw = false, |
|
444 | + $display_code = true, |
|
445 | + $CNT_ISO = '', |
|
446 | + $cur_code_span_class = 'currency-code' |
|
447 | + ) { |
|
448 | + // ensure amount was received |
|
449 | + if ($amount === null) { |
|
450 | + $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
451 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
452 | + return ''; |
|
453 | + } |
|
454 | + // ensure amount is float |
|
455 | + $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount); |
|
456 | + $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
457 | + // filter raw amount (allows 0.00 to be changed to "free" for example) |
|
458 | + $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
459 | + // still a number or was amount converted to a string like "free" ? |
|
460 | + if (is_float($amount_formatted)) { |
|
461 | + // was a country ISO code passed ? if so generate currency config object for that country |
|
462 | + $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
463 | + // verify results |
|
464 | + if (! $mny instanceof EE_Currency_Config) { |
|
465 | + // set default config country currency settings |
|
466 | + $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
467 | + ? EE_Registry::instance()->CFG->currency |
|
468 | + : new EE_Currency_Config(); |
|
469 | + } |
|
470 | + // format float |
|
471 | + $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
472 | + // add formatting ? |
|
473 | + if (! $return_raw) { |
|
474 | + // add currency sign |
|
475 | + if ($mny->sign_b4) { |
|
476 | + if ($amount >= 0) { |
|
477 | + $amount_formatted = $mny->sign . $amount_formatted; |
|
478 | + } else { |
|
479 | + $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
480 | + } |
|
481 | + } else { |
|
482 | + $amount_formatted = $amount_formatted . $mny->sign; |
|
483 | + } |
|
484 | + |
|
485 | + // filter to allow global setting of display_code |
|
486 | + $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
|
487 | + |
|
488 | + // add currency code ? |
|
489 | + $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
490 | + } |
|
491 | + // filter results |
|
492 | + $amount_formatted = apply_filters( |
|
493 | + 'FHEE__EEH_Template__format_currency__amount_formatted', |
|
494 | + $amount_formatted, |
|
495 | + $mny, |
|
496 | + $return_raw |
|
497 | + ); |
|
498 | + } |
|
499 | + // clean up vars |
|
500 | + unset($mny); |
|
501 | + // return formatted currency amount |
|
502 | + return $amount_formatted; |
|
503 | + } |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * This function is used for outputting the localized label for a given status id in the schema requested (and |
|
508 | + * possibly plural). The intended use of this function is only for cases where wanting a label outside of a |
|
509 | + * related status model or model object (i.e. in documentation etc.) |
|
510 | + * |
|
511 | + * @param string $status_id Status ID matching a registered status in the esp_status table. If there is no |
|
512 | + * match, then 'Unknown' will be returned. |
|
513 | + * @param boolean $plural Whether to return plural or not |
|
514 | + * @param string $schema 'UPPER', 'lower', or 'Sentence' |
|
515 | + * @return string The localized label for the status id. |
|
516 | + */ |
|
517 | + public static function pretty_status($status_id, $plural = false, $schema = 'upper') |
|
518 | + { |
|
519 | + /** @type EEM_Status $EEM_Status */ |
|
520 | + $EEM_Status = EE_Registry::instance()->load_model('Status'); |
|
521 | + $status = $EEM_Status->localized_status( |
|
522 | + array($status_id => __('unknown', 'event_espresso')), |
|
523 | + $plural, |
|
524 | + $schema |
|
525 | + ); |
|
526 | + return $status[ $status_id ]; |
|
527 | + } |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * This helper just returns a button or link for the given parameters |
|
532 | + * |
|
533 | + * @param string $url the url for the link, note that `esc_url` will be called on it |
|
534 | + * @param string $label What is the label you want displayed for the button |
|
535 | + * @param string $class what class is used for the button (defaults to 'button-primary') |
|
536 | + * @param string $icon |
|
537 | + * @param string $title |
|
538 | + * @return string the html output for the button |
|
539 | + */ |
|
540 | + public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '') |
|
541 | + { |
|
542 | + $icon_html = ''; |
|
543 | + if (! empty($icon)) { |
|
544 | + $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
545 | + $dashicons = array_filter($dashicons); |
|
546 | + $count = count($dashicons); |
|
547 | + $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
|
548 | + foreach ($dashicons as $dashicon) { |
|
549 | + $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
550 | + $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
551 | + } |
|
552 | + $icon_html .= $count > 1 ? '</span>' : ''; |
|
553 | + } |
|
554 | + $label = ! empty($icon) ? $icon_html . $label : $label; |
|
555 | + $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
556 | + return $button; |
|
557 | + } |
|
558 | + |
|
559 | + |
|
560 | + /** |
|
561 | + * This returns a generated link that will load the related help tab on admin pages. |
|
562 | + * |
|
563 | + * @param string $help_tab_id the id for the connected help tab |
|
564 | + * @param bool|string $page The page identifier for the page the help tab is on |
|
565 | + * @param bool|string $action The action (route) for the admin page the help tab is on. |
|
566 | + * @param bool|string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
567 | + * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
|
568 | + * @return string generated link |
|
569 | + */ |
|
570 | + public static function get_help_tab_link( |
|
571 | + $help_tab_id, |
|
572 | + $page = false, |
|
573 | + $action = false, |
|
574 | + $icon_style = false, |
|
575 | + $help_text = false |
|
576 | + ) { |
|
577 | + |
|
578 | + if (! $page) { |
|
579 | + $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page; |
|
580 | + } |
|
581 | + |
|
582 | + if (! $action) { |
|
583 | + $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action; |
|
584 | + } |
|
585 | + |
|
586 | + $action = empty($action) ? 'default' : $action; |
|
587 | + |
|
588 | + |
|
589 | + $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
590 | + $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
|
591 | + $help_text = ! $help_text ? '' : $help_text; |
|
592 | + return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__( |
|
593 | + 'Click to open the \'Help\' tab for more information about this feature.', |
|
594 | + 'event_espresso' |
|
595 | + ) . '" > ' . $help_text . ' </a>'; |
|
596 | + } |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * This helper generates the html structure for the jquery joyride plugin with the given params. |
|
601 | + * |
|
602 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
603 | + * @see EE_Admin_Page->_stop_callback() for the construct expected for the $stops param. |
|
604 | + * @param EE_Help_Tour |
|
605 | + * @return string html |
|
606 | + */ |
|
607 | + public static function help_tour_stops_generator(EE_Help_Tour $tour) |
|
608 | + { |
|
609 | + $id = $tour->get_slug(); |
|
610 | + $stops = $tour->get_stops(); |
|
611 | + |
|
612 | + $content = '<ol style="display:none" id="' . $id . '">'; |
|
613 | + |
|
614 | + foreach ($stops as $stop) { |
|
615 | + $data_id = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
616 | + $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
617 | + |
|
618 | + // if container is set to modal then let's make sure we set the options accordingly |
|
619 | + if (empty($data_id) && empty($data_class)) { |
|
620 | + $stop['options']['modal'] = true; |
|
621 | + $stop['options']['expose'] = true; |
|
622 | + } |
|
623 | + |
|
624 | + $custom_class = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
625 | + $button_text = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
626 | + $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
|
627 | + |
|
628 | + // options |
|
629 | + if (isset($stop['options']) && is_array($stop['options'])) { |
|
630 | + $options = ' data-options="'; |
|
631 | + foreach ($stop['options'] as $option => $value) { |
|
632 | + $options .= $option . ':' . $value . ';'; |
|
633 | + } |
|
634 | + $options .= '"'; |
|
635 | + } else { |
|
636 | + $options = ''; |
|
637 | + } |
|
638 | + |
|
639 | + // let's put all together |
|
640 | + $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
641 | + } |
|
642 | + |
|
643 | + $content .= '</ol>'; |
|
644 | + return $content; |
|
645 | + } |
|
646 | + |
|
647 | + |
|
648 | + /** |
|
649 | + * This is a helper method to generate a status legend for a given status array. |
|
650 | + * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods |
|
651 | + * status_array. |
|
652 | + * |
|
653 | + * @param array $status_array array of statuses that will make up the legend. In format: |
|
654 | + * array( |
|
655 | + * 'status_item' => 'status_name' |
|
656 | + * ) |
|
657 | + * @param string $active_status This is used to indicate what the active status is IF that is to be highlighted in |
|
658 | + * the legend. |
|
659 | + * @throws EE_Error |
|
660 | + * @return string html structure for status. |
|
661 | + */ |
|
662 | + public static function status_legend($status_array, $active_status = '') |
|
663 | + { |
|
664 | + if (! is_array($status_array)) { |
|
665 | + throw new EE_Error(esc_html__( |
|
666 | + 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
|
667 | + 'event_espresso' |
|
668 | + )); |
|
669 | + } |
|
670 | + |
|
671 | + $setup_array = array(); |
|
672 | + foreach ($status_array as $item => $status) { |
|
673 | + $setup_array[ $item ] = array( |
|
674 | + 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
675 | + 'desc' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
676 | + 'status' => $status, |
|
677 | + ); |
|
678 | + } |
|
679 | + |
|
680 | + $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
681 | + $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n"; |
|
682 | + $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
683 | + foreach ($setup_array as $item => $details) { |
|
684 | + $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
|
685 | + $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
686 | + $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
687 | + $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
688 | + $content .= '</dt>' . "\n"; |
|
689 | + } |
|
690 | + $content .= '</dl>' . "\n"; |
|
691 | + $content .= '</div>' . "\n"; |
|
692 | + return $content; |
|
693 | + } |
|
694 | + |
|
695 | + |
|
696 | + /** |
|
697 | + * Gets HTML for laying out a deeply-nested array (and objects) in a format |
|
698 | + * that's nice for presenting in the wp admin |
|
699 | + * |
|
700 | + * @param mixed $data |
|
701 | + * @return string |
|
702 | + */ |
|
703 | + public static function layout_array_as_table($data) |
|
704 | + { |
|
705 | + if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
706 | + $data = (array) $data; |
|
707 | + } |
|
708 | + ob_start(); |
|
709 | + if (is_array($data)) { |
|
710 | + if (EEH_Array::is_associative_array($data)) { |
|
711 | + ?> |
|
712 | 712 | <table class="widefat"> |
713 | 713 | <tbody> |
714 | 714 | <?php |
715 | - foreach ($data as $data_key => $data_values) { |
|
716 | - ?> |
|
715 | + foreach ($data as $data_key => $data_values) { |
|
716 | + ?> |
|
717 | 717 | <tr> |
718 | 718 | <td> |
719 | 719 | <?php echo $data_key; ?> |
@@ -723,291 +723,291 @@ discard block |
||
723 | 723 | </td> |
724 | 724 | </tr> |
725 | 725 | <?php |
726 | - } ?> |
|
726 | + } ?> |
|
727 | 727 | </tbody> |
728 | 728 | </table> |
729 | 729 | <?php |
730 | - } else { |
|
731 | - ?> |
|
730 | + } else { |
|
731 | + ?> |
|
732 | 732 | <ul> |
733 | 733 | <?php |
734 | - foreach ($data as $datum) { |
|
735 | - echo "<li>"; |
|
736 | - echo self::layout_array_as_table($datum); |
|
737 | - echo "</li>"; |
|
738 | - } ?> |
|
734 | + foreach ($data as $datum) { |
|
735 | + echo "<li>"; |
|
736 | + echo self::layout_array_as_table($datum); |
|
737 | + echo "</li>"; |
|
738 | + } ?> |
|
739 | 739 | </ul> |
740 | 740 | <?php |
741 | - } |
|
742 | - } else { |
|
743 | - // simple value |
|
744 | - echo esc_html($data); |
|
745 | - } |
|
746 | - return ob_get_clean(); |
|
747 | - } |
|
748 | - |
|
749 | - |
|
750 | - /** |
|
751 | - * wrapper for self::get_paging_html() that simply echos the generated paging html |
|
752 | - * |
|
753 | - * @since 4.4.0 |
|
754 | - * @see self:get_paging_html() for argument docs. |
|
755 | - * @param $total_items |
|
756 | - * @param $current |
|
757 | - * @param $per_page |
|
758 | - * @param $url |
|
759 | - * @param bool $show_num_field |
|
760 | - * @param string $paged_arg_name |
|
761 | - * @param array $items_label |
|
762 | - * @return string |
|
763 | - */ |
|
764 | - public static function paging_html( |
|
765 | - $total_items, |
|
766 | - $current, |
|
767 | - $per_page, |
|
768 | - $url, |
|
769 | - $show_num_field = true, |
|
770 | - $paged_arg_name = 'paged', |
|
771 | - $items_label = array() |
|
772 | - ) { |
|
773 | - echo self::get_paging_html( |
|
774 | - $total_items, |
|
775 | - $current, |
|
776 | - $per_page, |
|
777 | - $url, |
|
778 | - $show_num_field, |
|
779 | - $paged_arg_name, |
|
780 | - $items_label |
|
781 | - ); |
|
782 | - } |
|
783 | - |
|
784 | - |
|
785 | - /** |
|
786 | - * A method for generating paging similar to WP_List_Table |
|
787 | - * |
|
788 | - * @since 4.4.0 |
|
789 | - * @see wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination() |
|
790 | - * @param integer $total_items How many total items there are to page. |
|
791 | - * @param integer $current What the current page is. |
|
792 | - * @param integer $per_page How many items per page. |
|
793 | - * @param string $url What the base url for page links is. |
|
794 | - * @param boolean $show_num_field Whether to show the input for changing page number. |
|
795 | - * @param string $paged_arg_name The name of the key for the paged query argument. |
|
796 | - * @param array $items_label An array of singular/plural values for the items label: |
|
797 | - * array( |
|
798 | - * 'single' => 'item', |
|
799 | - * 'plural' => 'items' |
|
800 | - * ) |
|
801 | - * @return string |
|
802 | - */ |
|
803 | - public static function get_paging_html( |
|
804 | - $total_items, |
|
805 | - $current, |
|
806 | - $per_page, |
|
807 | - $url, |
|
808 | - $show_num_field = true, |
|
809 | - $paged_arg_name = 'paged', |
|
810 | - $items_label = array() |
|
811 | - ) { |
|
812 | - $page_links = array(); |
|
813 | - $disable_first = $disable_last = ''; |
|
814 | - $total_items = (int) $total_items; |
|
815 | - $per_page = (int) $per_page; |
|
816 | - $current = (int) $current; |
|
817 | - $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
818 | - |
|
819 | - // filter items_label |
|
820 | - $items_label = apply_filters( |
|
821 | - 'FHEE__EEH_Template__get_paging_html__items_label', |
|
822 | - $items_label |
|
823 | - ); |
|
824 | - |
|
825 | - if (empty($items_label) |
|
826 | - || ! is_array($items_label) |
|
827 | - || ! isset($items_label['single']) |
|
828 | - || ! isset($items_label['plural']) |
|
829 | - ) { |
|
830 | - $items_label = array( |
|
831 | - 'single' => __('1 item', 'event_espresso'), |
|
832 | - 'plural' => __('%s items', 'event_espresso'), |
|
833 | - ); |
|
834 | - } else { |
|
835 | - $items_label = array( |
|
836 | - 'single' => '1 ' . esc_html($items_label['single']), |
|
837 | - 'plural' => '%s ' . esc_html($items_label['plural']), |
|
838 | - ); |
|
839 | - } |
|
840 | - |
|
841 | - $total_pages = ceil($total_items / $per_page); |
|
842 | - |
|
843 | - if ($total_pages <= 1) { |
|
844 | - return ''; |
|
845 | - } |
|
846 | - |
|
847 | - $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
848 | - |
|
849 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
850 | - |
|
851 | - if ($current === 1) { |
|
852 | - $disable_first = ' disabled'; |
|
853 | - } |
|
854 | - if ($current == $total_pages) { |
|
855 | - $disable_last = ' disabled'; |
|
856 | - } |
|
857 | - |
|
858 | - $page_links[] = sprintf( |
|
859 | - "<a class='%s' title='%s' href='%s'>%s</a>", |
|
860 | - 'first-page' . $disable_first, |
|
861 | - esc_attr__('Go to the first page', 'event_espresso'), |
|
862 | - esc_url(remove_query_arg($paged_arg_name, $url)), |
|
863 | - '«' |
|
864 | - ); |
|
865 | - |
|
866 | - $page_links[] = sprintf( |
|
867 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
868 | - 'prev-page' . $disable_first, |
|
869 | - esc_attr__('Go to the previous page', 'event_espresso'), |
|
870 | - esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
871 | - '‹' |
|
872 | - ); |
|
873 | - |
|
874 | - if (! $show_num_field) { |
|
875 | - $html_current_page = $current; |
|
876 | - } else { |
|
877 | - $html_current_page = sprintf( |
|
878 | - "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
879 | - esc_attr__('Current page', 'event_espresso'), |
|
880 | - $current, |
|
881 | - strlen($total_pages) |
|
882 | - ); |
|
883 | - } |
|
884 | - |
|
885 | - $html_total_pages = sprintf( |
|
886 | - '<span class="total-pages">%s</span>', |
|
887 | - number_format_i18n($total_pages) |
|
888 | - ); |
|
889 | - $page_links[] = sprintf( |
|
890 | - _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'), |
|
891 | - $html_current_page, |
|
892 | - $html_total_pages, |
|
893 | - '<span class="paging-input">', |
|
894 | - '</span>' |
|
895 | - ); |
|
896 | - |
|
897 | - $page_links[] = sprintf( |
|
898 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
899 | - 'next-page' . $disable_last, |
|
900 | - esc_attr__('Go to the next page', 'event_espresso'), |
|
901 | - esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
902 | - '›' |
|
903 | - ); |
|
904 | - |
|
905 | - $page_links[] = sprintf( |
|
906 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
907 | - 'last-page' . $disable_last, |
|
908 | - esc_attr__('Go to the last page', 'event_espresso'), |
|
909 | - esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
910 | - '»' |
|
911 | - ); |
|
912 | - |
|
913 | - $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
914 | - // set page class |
|
915 | - if ($total_pages) { |
|
916 | - $page_class = $total_pages < 2 ? ' one-page' : ''; |
|
917 | - } else { |
|
918 | - $page_class = ' no-pages'; |
|
919 | - } |
|
920 | - |
|
921 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
922 | - } |
|
923 | - |
|
924 | - |
|
925 | - /** |
|
926 | - * @param string $wrap_class |
|
927 | - * @param string $wrap_id |
|
928 | - * @return string |
|
929 | - */ |
|
930 | - public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array()) |
|
931 | - { |
|
932 | - $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
933 | - if (! $admin && |
|
934 | - ! apply_filters( |
|
935 | - 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
|
936 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
937 | - ) |
|
938 | - ) { |
|
939 | - return ''; |
|
940 | - } |
|
941 | - $tag = $admin ? 'span' : 'div'; |
|
942 | - $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : ''; |
|
943 | - $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class; |
|
944 | - $attributes .= ! empty($wrap_class) |
|
945 | - ? " class=\"{$wrap_class} powered-by-event-espresso-credit\"" |
|
946 | - : ' class="powered-by-event-espresso-credit"'; |
|
947 | - $query_args = array_merge( |
|
948 | - array( |
|
949 | - 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id(), |
|
950 | - 'utm_source' => 'powered_by_event_espresso', |
|
951 | - 'utm_medium' => 'link', |
|
952 | - 'utm_campaign' => 'powered_by', |
|
953 | - ), |
|
954 | - $query_args |
|
955 | - ); |
|
956 | - $powered_by = apply_filters( |
|
957 | - 'FHEE__EEH_Template__powered_by_event_espresso_text', |
|
958 | - $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
959 | - ); |
|
960 | - $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
|
961 | - $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
962 | - return (string) apply_filters( |
|
963 | - 'FHEE__EEH_Template__powered_by_event_espresso__html', |
|
964 | - sprintf( |
|
965 | - esc_html_x( |
|
966 | - '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s', |
|
967 | - 'Online event registration and ticketing powered by [link to eventespresso.com]', |
|
968 | - 'event_espresso' |
|
969 | - ), |
|
970 | - "<{$tag}{$attributes}>", |
|
971 | - "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>", |
|
972 | - $admin ? '' : '<br />' |
|
973 | - ), |
|
974 | - $wrap_class, |
|
975 | - $wrap_id |
|
976 | - ); |
|
977 | - } |
|
741 | + } |
|
742 | + } else { |
|
743 | + // simple value |
|
744 | + echo esc_html($data); |
|
745 | + } |
|
746 | + return ob_get_clean(); |
|
747 | + } |
|
748 | + |
|
749 | + |
|
750 | + /** |
|
751 | + * wrapper for self::get_paging_html() that simply echos the generated paging html |
|
752 | + * |
|
753 | + * @since 4.4.0 |
|
754 | + * @see self:get_paging_html() for argument docs. |
|
755 | + * @param $total_items |
|
756 | + * @param $current |
|
757 | + * @param $per_page |
|
758 | + * @param $url |
|
759 | + * @param bool $show_num_field |
|
760 | + * @param string $paged_arg_name |
|
761 | + * @param array $items_label |
|
762 | + * @return string |
|
763 | + */ |
|
764 | + public static function paging_html( |
|
765 | + $total_items, |
|
766 | + $current, |
|
767 | + $per_page, |
|
768 | + $url, |
|
769 | + $show_num_field = true, |
|
770 | + $paged_arg_name = 'paged', |
|
771 | + $items_label = array() |
|
772 | + ) { |
|
773 | + echo self::get_paging_html( |
|
774 | + $total_items, |
|
775 | + $current, |
|
776 | + $per_page, |
|
777 | + $url, |
|
778 | + $show_num_field, |
|
779 | + $paged_arg_name, |
|
780 | + $items_label |
|
781 | + ); |
|
782 | + } |
|
783 | + |
|
784 | + |
|
785 | + /** |
|
786 | + * A method for generating paging similar to WP_List_Table |
|
787 | + * |
|
788 | + * @since 4.4.0 |
|
789 | + * @see wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination() |
|
790 | + * @param integer $total_items How many total items there are to page. |
|
791 | + * @param integer $current What the current page is. |
|
792 | + * @param integer $per_page How many items per page. |
|
793 | + * @param string $url What the base url for page links is. |
|
794 | + * @param boolean $show_num_field Whether to show the input for changing page number. |
|
795 | + * @param string $paged_arg_name The name of the key for the paged query argument. |
|
796 | + * @param array $items_label An array of singular/plural values for the items label: |
|
797 | + * array( |
|
798 | + * 'single' => 'item', |
|
799 | + * 'plural' => 'items' |
|
800 | + * ) |
|
801 | + * @return string |
|
802 | + */ |
|
803 | + public static function get_paging_html( |
|
804 | + $total_items, |
|
805 | + $current, |
|
806 | + $per_page, |
|
807 | + $url, |
|
808 | + $show_num_field = true, |
|
809 | + $paged_arg_name = 'paged', |
|
810 | + $items_label = array() |
|
811 | + ) { |
|
812 | + $page_links = array(); |
|
813 | + $disable_first = $disable_last = ''; |
|
814 | + $total_items = (int) $total_items; |
|
815 | + $per_page = (int) $per_page; |
|
816 | + $current = (int) $current; |
|
817 | + $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
818 | + |
|
819 | + // filter items_label |
|
820 | + $items_label = apply_filters( |
|
821 | + 'FHEE__EEH_Template__get_paging_html__items_label', |
|
822 | + $items_label |
|
823 | + ); |
|
824 | + |
|
825 | + if (empty($items_label) |
|
826 | + || ! is_array($items_label) |
|
827 | + || ! isset($items_label['single']) |
|
828 | + || ! isset($items_label['plural']) |
|
829 | + ) { |
|
830 | + $items_label = array( |
|
831 | + 'single' => __('1 item', 'event_espresso'), |
|
832 | + 'plural' => __('%s items', 'event_espresso'), |
|
833 | + ); |
|
834 | + } else { |
|
835 | + $items_label = array( |
|
836 | + 'single' => '1 ' . esc_html($items_label['single']), |
|
837 | + 'plural' => '%s ' . esc_html($items_label['plural']), |
|
838 | + ); |
|
839 | + } |
|
840 | + |
|
841 | + $total_pages = ceil($total_items / $per_page); |
|
842 | + |
|
843 | + if ($total_pages <= 1) { |
|
844 | + return ''; |
|
845 | + } |
|
846 | + |
|
847 | + $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
848 | + |
|
849 | + $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
850 | + |
|
851 | + if ($current === 1) { |
|
852 | + $disable_first = ' disabled'; |
|
853 | + } |
|
854 | + if ($current == $total_pages) { |
|
855 | + $disable_last = ' disabled'; |
|
856 | + } |
|
857 | + |
|
858 | + $page_links[] = sprintf( |
|
859 | + "<a class='%s' title='%s' href='%s'>%s</a>", |
|
860 | + 'first-page' . $disable_first, |
|
861 | + esc_attr__('Go to the first page', 'event_espresso'), |
|
862 | + esc_url(remove_query_arg($paged_arg_name, $url)), |
|
863 | + '«' |
|
864 | + ); |
|
865 | + |
|
866 | + $page_links[] = sprintf( |
|
867 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
868 | + 'prev-page' . $disable_first, |
|
869 | + esc_attr__('Go to the previous page', 'event_espresso'), |
|
870 | + esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
871 | + '‹' |
|
872 | + ); |
|
873 | + |
|
874 | + if (! $show_num_field) { |
|
875 | + $html_current_page = $current; |
|
876 | + } else { |
|
877 | + $html_current_page = sprintf( |
|
878 | + "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
879 | + esc_attr__('Current page', 'event_espresso'), |
|
880 | + $current, |
|
881 | + strlen($total_pages) |
|
882 | + ); |
|
883 | + } |
|
884 | + |
|
885 | + $html_total_pages = sprintf( |
|
886 | + '<span class="total-pages">%s</span>', |
|
887 | + number_format_i18n($total_pages) |
|
888 | + ); |
|
889 | + $page_links[] = sprintf( |
|
890 | + _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'), |
|
891 | + $html_current_page, |
|
892 | + $html_total_pages, |
|
893 | + '<span class="paging-input">', |
|
894 | + '</span>' |
|
895 | + ); |
|
896 | + |
|
897 | + $page_links[] = sprintf( |
|
898 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
899 | + 'next-page' . $disable_last, |
|
900 | + esc_attr__('Go to the next page', 'event_espresso'), |
|
901 | + esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
902 | + '›' |
|
903 | + ); |
|
904 | + |
|
905 | + $page_links[] = sprintf( |
|
906 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
907 | + 'last-page' . $disable_last, |
|
908 | + esc_attr__('Go to the last page', 'event_espresso'), |
|
909 | + esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
910 | + '»' |
|
911 | + ); |
|
912 | + |
|
913 | + $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
914 | + // set page class |
|
915 | + if ($total_pages) { |
|
916 | + $page_class = $total_pages < 2 ? ' one-page' : ''; |
|
917 | + } else { |
|
918 | + $page_class = ' no-pages'; |
|
919 | + } |
|
920 | + |
|
921 | + return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
922 | + } |
|
923 | + |
|
924 | + |
|
925 | + /** |
|
926 | + * @param string $wrap_class |
|
927 | + * @param string $wrap_id |
|
928 | + * @return string |
|
929 | + */ |
|
930 | + public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array()) |
|
931 | + { |
|
932 | + $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
933 | + if (! $admin && |
|
934 | + ! apply_filters( |
|
935 | + 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
|
936 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
937 | + ) |
|
938 | + ) { |
|
939 | + return ''; |
|
940 | + } |
|
941 | + $tag = $admin ? 'span' : 'div'; |
|
942 | + $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : ''; |
|
943 | + $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class; |
|
944 | + $attributes .= ! empty($wrap_class) |
|
945 | + ? " class=\"{$wrap_class} powered-by-event-espresso-credit\"" |
|
946 | + : ' class="powered-by-event-espresso-credit"'; |
|
947 | + $query_args = array_merge( |
|
948 | + array( |
|
949 | + 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id(), |
|
950 | + 'utm_source' => 'powered_by_event_espresso', |
|
951 | + 'utm_medium' => 'link', |
|
952 | + 'utm_campaign' => 'powered_by', |
|
953 | + ), |
|
954 | + $query_args |
|
955 | + ); |
|
956 | + $powered_by = apply_filters( |
|
957 | + 'FHEE__EEH_Template__powered_by_event_espresso_text', |
|
958 | + $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
959 | + ); |
|
960 | + $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
|
961 | + $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
962 | + return (string) apply_filters( |
|
963 | + 'FHEE__EEH_Template__powered_by_event_espresso__html', |
|
964 | + sprintf( |
|
965 | + esc_html_x( |
|
966 | + '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s', |
|
967 | + 'Online event registration and ticketing powered by [link to eventespresso.com]', |
|
968 | + 'event_espresso' |
|
969 | + ), |
|
970 | + "<{$tag}{$attributes}>", |
|
971 | + "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>", |
|
972 | + $admin ? '' : '<br />' |
|
973 | + ), |
|
974 | + $wrap_class, |
|
975 | + $wrap_id |
|
976 | + ); |
|
977 | + } |
|
978 | 978 | } |
979 | 979 | |
980 | 980 | |
981 | 981 | |
982 | 982 | |
983 | 983 | if (! function_exists('espresso_pagination')) { |
984 | - /** |
|
985 | - * espresso_pagination |
|
986 | - * |
|
987 | - * @access public |
|
988 | - * @return void |
|
989 | - */ |
|
990 | - function espresso_pagination() |
|
991 | - { |
|
992 | - global $wp_query; |
|
993 | - $big = 999999999; // need an unlikely integer |
|
994 | - $pagination = paginate_links( |
|
995 | - array( |
|
996 | - 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
997 | - 'format' => '?paged=%#%', |
|
998 | - 'current' => max(1, get_query_var('paged')), |
|
999 | - 'total' => $wp_query->max_num_pages, |
|
1000 | - 'show_all' => true, |
|
1001 | - 'end_size' => 10, |
|
1002 | - 'mid_size' => 6, |
|
1003 | - 'prev_next' => true, |
|
1004 | - 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
1005 | - 'next_text' => __('NEXT ›', 'event_espresso'), |
|
1006 | - 'type' => 'plain', |
|
1007 | - 'add_args' => false, |
|
1008 | - 'add_fragment' => '', |
|
1009 | - ) |
|
1010 | - ); |
|
1011 | - echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
1012 | - } |
|
984 | + /** |
|
985 | + * espresso_pagination |
|
986 | + * |
|
987 | + * @access public |
|
988 | + * @return void |
|
989 | + */ |
|
990 | + function espresso_pagination() |
|
991 | + { |
|
992 | + global $wp_query; |
|
993 | + $big = 999999999; // need an unlikely integer |
|
994 | + $pagination = paginate_links( |
|
995 | + array( |
|
996 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
997 | + 'format' => '?paged=%#%', |
|
998 | + 'current' => max(1, get_query_var('paged')), |
|
999 | + 'total' => $wp_query->max_num_pages, |
|
1000 | + 'show_all' => true, |
|
1001 | + 'end_size' => 10, |
|
1002 | + 'mid_size' => 6, |
|
1003 | + 'prev_next' => true, |
|
1004 | + 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
1005 | + 'next_text' => __('NEXT ›', 'event_espresso'), |
|
1006 | + 'type' => 'plain', |
|
1007 | + 'add_args' => false, |
|
1008 | + 'add_fragment' => '', |
|
1009 | + ) |
|
1010 | + ); |
|
1011 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
1012 | + } |
|
1013 | 1013 | } |
1014 | 1014 | \ No newline at end of file |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
5 | 5 | use EventEspresso\core\services\loaders\LoaderFactory; |
6 | 6 | |
7 | -if (! function_exists('espresso_get_template_part')) { |
|
7 | +if ( ! function_exists('espresso_get_template_part')) { |
|
8 | 8 | /** |
9 | 9 | * espresso_get_template_part |
10 | 10 | * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | } |
22 | 22 | |
23 | 23 | |
24 | -if (! function_exists('espresso_get_object_css_class')) { |
|
24 | +if ( ! function_exists('espresso_get_object_css_class')) { |
|
25 | 25 | /** |
26 | 26 | * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
27 | 27 | * |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public static function load_espresso_theme_functions() |
71 | 71 | { |
72 | - if (! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
73 | - if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) { |
|
74 | - require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php'); |
|
72 | + if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
73 | + if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php')) { |
|
74 | + require_once(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php'); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | } |
@@ -85,16 +85,16 @@ discard block |
||
85 | 85 | public static function get_espresso_themes() |
86 | 86 | { |
87 | 87 | if (empty(EEH_Template::$_espresso_themes)) { |
88 | - $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
88 | + $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR); |
|
89 | 89 | if (empty($espresso_themes)) { |
90 | 90 | return array(); |
91 | 91 | } |
92 | 92 | if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
93 | - unset($espresso_themes[ $key ]); |
|
93 | + unset($espresso_themes[$key]); |
|
94 | 94 | } |
95 | 95 | EEH_Template::$_espresso_themes = array(); |
96 | 96 | foreach ($espresso_themes as $espresso_theme) { |
97 | - EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme; |
|
97 | + EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme; |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | return EEH_Template::$_espresso_themes; |
@@ -205,10 +205,10 @@ discard block |
||
205 | 205 | // get array of EE Custom Post Types |
206 | 206 | $EE_CPTs = $custom_post_types->getDefinitions(); |
207 | 207 | // build template name based on request |
208 | - if (isset($EE_CPTs[ $post_type ])) { |
|
208 | + if (isset($EE_CPTs[$post_type])) { |
|
209 | 209 | $archive_or_single = is_archive() ? 'archive' : ''; |
210 | 210 | $archive_or_single = is_single() ? 'single' : $archive_or_single; |
211 | - $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
211 | + $templates = $archive_or_single.'-'.$post_type.'.php'; |
|
212 | 212 | } |
213 | 213 | } |
214 | 214 | // currently active EE template theme |
@@ -217,18 +217,18 @@ discard block |
||
217 | 217 | // array of paths to folders that may contain templates |
218 | 218 | $template_folder_paths = array( |
219 | 219 | // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
220 | - EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
220 | + EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme, |
|
221 | 221 | // then in the root of the /wp-content/uploads/espresso/templates/ folder |
222 | 222 | EVENT_ESPRESSO_TEMPLATE_DIR, |
223 | 223 | ); |
224 | 224 | |
225 | 225 | // add core plugin folders for checking only if we're not $check_if_custom |
226 | - if (! $check_if_custom) { |
|
227 | - $core_paths = array( |
|
226 | + if ( ! $check_if_custom) { |
|
227 | + $core_paths = array( |
|
228 | 228 | // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
229 | - EE_PUBLIC . $current_theme, |
|
229 | + EE_PUBLIC.$current_theme, |
|
230 | 230 | // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
231 | - EE_TEMPLATES . $current_theme, |
|
231 | + EE_TEMPLATES.$current_theme, |
|
232 | 232 | // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
233 | 233 | EE_PLUGIN_DIR_PATH, |
234 | 234 | ); |
@@ -261,10 +261,10 @@ discard block |
||
261 | 261 | ); |
262 | 262 | if ($common_base_path !== '') { |
263 | 263 | // both paths have a common base, so just tack the filename onto our search path |
264 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
264 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name; |
|
265 | 265 | } else { |
266 | 266 | // no common base path, so let's just concatenate |
267 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
267 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template; |
|
268 | 268 | } |
269 | 269 | // build up our template locations array by adding our resolved paths |
270 | 270 | $full_template_paths[] = $resolved_path; |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
273 | 273 | array_unshift($full_template_paths, $template); |
274 | 274 | // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
275 | - array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name); |
|
275 | + array_unshift($full_template_paths, get_stylesheet_directory().'/'.$file_name); |
|
276 | 276 | } |
277 | 277 | // filter final array of full template paths |
278 | 278 | $full_template_paths = apply_filters( |
@@ -361,11 +361,11 @@ discard block |
||
361 | 361 | $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
362 | 362 | |
363 | 363 | // you gimme nuttin - YOU GET NUTTIN !! |
364 | - if (! $template_path || ! is_readable($template_path)) { |
|
364 | + if ( ! $template_path || ! is_readable($template_path)) { |
|
365 | 365 | return ''; |
366 | 366 | } |
367 | 367 | // if $template_args are not in an array, then make it so |
368 | - if (! is_array($template_args) && ! is_object($template_args)) { |
|
368 | + if ( ! is_array($template_args) && ! is_object($template_args)) { |
|
369 | 369 | $template_args = array($template_args); |
370 | 370 | } |
371 | 371 | extract($template_args, EXTR_SKIP); |
@@ -403,11 +403,11 @@ discard block |
||
403 | 403 | public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
404 | 404 | { |
405 | 405 | // in the beginning... |
406 | - $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
406 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : ''; |
|
407 | 407 | // da muddle |
408 | 408 | $class = ''; |
409 | 409 | // the end |
410 | - $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
410 | + $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : ''; |
|
411 | 411 | // is the passed object an EE object ? |
412 | 412 | if ($object instanceof EE_Base_Class) { |
413 | 413 | // grab the exact type of object |
@@ -417,10 +417,10 @@ discard block |
||
417 | 417 | // no specifics just yet... |
418 | 418 | default: |
419 | 419 | $class = strtolower(str_replace('_', '-', $obj_class)); |
420 | - $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
420 | + $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : ''; |
|
421 | 421 | } |
422 | 422 | } |
423 | - return $prefix . $class . $suffix; |
|
423 | + return $prefix.$class.$suffix; |
|
424 | 424 | } |
425 | 425 | |
426 | 426 | |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | // was a country ISO code passed ? if so generate currency config object for that country |
462 | 462 | $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
463 | 463 | // verify results |
464 | - if (! $mny instanceof EE_Currency_Config) { |
|
464 | + if ( ! $mny instanceof EE_Currency_Config) { |
|
465 | 465 | // set default config country currency settings |
466 | 466 | $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
467 | 467 | ? EE_Registry::instance()->CFG->currency |
@@ -470,23 +470,23 @@ discard block |
||
470 | 470 | // format float |
471 | 471 | $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
472 | 472 | // add formatting ? |
473 | - if (! $return_raw) { |
|
473 | + if ( ! $return_raw) { |
|
474 | 474 | // add currency sign |
475 | 475 | if ($mny->sign_b4) { |
476 | 476 | if ($amount >= 0) { |
477 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
477 | + $amount_formatted = $mny->sign.$amount_formatted; |
|
478 | 478 | } else { |
479 | - $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
479 | + $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted); |
|
480 | 480 | } |
481 | 481 | } else { |
482 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
482 | + $amount_formatted = $amount_formatted.$mny->sign; |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | // filter to allow global setting of display_code |
486 | 486 | $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
487 | 487 | |
488 | 488 | // add currency code ? |
489 | - $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
489 | + $amount_formatted = $display_code ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>' : $amount_formatted; |
|
490 | 490 | } |
491 | 491 | // filter results |
492 | 492 | $amount_formatted = apply_filters( |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | $plural, |
524 | 524 | $schema |
525 | 525 | ); |
526 | - return $status[ $status_id ]; |
|
526 | + return $status[$status_id]; |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | |
@@ -540,19 +540,19 @@ discard block |
||
540 | 540 | public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '') |
541 | 541 | { |
542 | 542 | $icon_html = ''; |
543 | - if (! empty($icon)) { |
|
543 | + if ( ! empty($icon)) { |
|
544 | 544 | $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
545 | 545 | $dashicons = array_filter($dashicons); |
546 | 546 | $count = count($dashicons); |
547 | 547 | $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
548 | 548 | foreach ($dashicons as $dashicon) { |
549 | 549 | $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
550 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
550 | + $icon_html .= '<span class="'.$type.$dashicon.'"></span>'; |
|
551 | 551 | } |
552 | 552 | $icon_html .= $count > 1 ? '</span>' : ''; |
553 | 553 | } |
554 | - $label = ! empty($icon) ? $icon_html . $label : $label; |
|
555 | - $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
554 | + $label = ! empty($icon) ? $icon_html.$label : $label; |
|
555 | + $button = '<a id="'.sanitize_title_with_dashes($label).'" href="'.esc_url($url).'" class="'.$class.'" title="'.$title.'">'.$label.'</a>'; |
|
556 | 556 | return $button; |
557 | 557 | } |
558 | 558 | |
@@ -575,24 +575,24 @@ discard block |
||
575 | 575 | $help_text = false |
576 | 576 | ) { |
577 | 577 | |
578 | - if (! $page) { |
|
578 | + if ( ! $page) { |
|
579 | 579 | $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page; |
580 | 580 | } |
581 | 581 | |
582 | - if (! $action) { |
|
582 | + if ( ! $action) { |
|
583 | 583 | $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action; |
584 | 584 | } |
585 | 585 | |
586 | 586 | $action = empty($action) ? 'default' : $action; |
587 | 587 | |
588 | 588 | |
589 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
589 | + $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id; |
|
590 | 590 | $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
591 | 591 | $help_text = ! $help_text ? '' : $help_text; |
592 | - return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__( |
|
592 | + return '<a id="'.$help_tab_lnk.'" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'.$icon.'" title="'.esc_attr__( |
|
593 | 593 | 'Click to open the \'Help\' tab for more information about this feature.', |
594 | 594 | 'event_espresso' |
595 | - ) . '" > ' . $help_text . ' </a>'; |
|
595 | + ).'" > '.$help_text.' </a>'; |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | |
@@ -609,11 +609,11 @@ discard block |
||
609 | 609 | $id = $tour->get_slug(); |
610 | 610 | $stops = $tour->get_stops(); |
611 | 611 | |
612 | - $content = '<ol style="display:none" id="' . $id . '">'; |
|
612 | + $content = '<ol style="display:none" id="'.$id.'">'; |
|
613 | 613 | |
614 | 614 | foreach ($stops as $stop) { |
615 | - $data_id = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
616 | - $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
615 | + $data_id = ! empty($stop['id']) ? ' data-id="'.$stop['id'].'"' : ''; |
|
616 | + $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="'.$stop['class'].'"' : ''; |
|
617 | 617 | |
618 | 618 | // if container is set to modal then let's make sure we set the options accordingly |
619 | 619 | if (empty($data_id) && empty($data_class)) { |
@@ -621,15 +621,15 @@ discard block |
||
621 | 621 | $stop['options']['expose'] = true; |
622 | 622 | } |
623 | 623 | |
624 | - $custom_class = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
625 | - $button_text = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
624 | + $custom_class = ! empty($stop['custom_class']) ? ' class="'.$stop['custom_class'].'"' : ''; |
|
625 | + $button_text = ! empty($stop['button_text']) ? ' data-button="'.$stop['button_text'].'"' : ''; |
|
626 | 626 | $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
627 | 627 | |
628 | 628 | // options |
629 | 629 | if (isset($stop['options']) && is_array($stop['options'])) { |
630 | 630 | $options = ' data-options="'; |
631 | 631 | foreach ($stop['options'] as $option => $value) { |
632 | - $options .= $option . ':' . $value . ';'; |
|
632 | + $options .= $option.':'.$value.';'; |
|
633 | 633 | } |
634 | 634 | $options .= '"'; |
635 | 635 | } else { |
@@ -637,7 +637,7 @@ discard block |
||
637 | 637 | } |
638 | 638 | |
639 | 639 | // let's put all together |
640 | - $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
640 | + $content .= '<li'.$data_id.$data_class.$custom_class.$button_text.$options.'>'.$inner_content.'</li>'; |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | $content .= '</ol>'; |
@@ -661,7 +661,7 @@ discard block |
||
661 | 661 | */ |
662 | 662 | public static function status_legend($status_array, $active_status = '') |
663 | 663 | { |
664 | - if (! is_array($status_array)) { |
|
664 | + if ( ! is_array($status_array)) { |
|
665 | 665 | throw new EE_Error(esc_html__( |
666 | 666 | 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
667 | 667 | 'event_espresso' |
@@ -670,25 +670,25 @@ discard block |
||
670 | 670 | |
671 | 671 | $setup_array = array(); |
672 | 672 | foreach ($status_array as $item => $status) { |
673 | - $setup_array[ $item ] = array( |
|
674 | - 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
673 | + $setup_array[$item] = array( |
|
674 | + 'class' => 'ee-status-legend ee-status-legend-'.$status, |
|
675 | 675 | 'desc' => EEH_Template::pretty_status($status, false, 'sentence'), |
676 | 676 | 'status' => $status, |
677 | 677 | ); |
678 | 678 | } |
679 | 679 | |
680 | - $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
681 | - $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n"; |
|
682 | - $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
680 | + $content = '<div class="ee-list-table-legend-container">'."\n"; |
|
681 | + $content .= '<h4 class="status-legend-title">'.esc_html__('Status Legend', 'event_espresso').'</h4>'."\n"; |
|
682 | + $content .= '<dl class="ee-list-table-legend">'."\n\t"; |
|
683 | 683 | foreach ($setup_array as $item => $details) { |
684 | 684 | $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
685 | - $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
686 | - $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
687 | - $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
688 | - $content .= '</dt>' . "\n"; |
|
685 | + $content .= '<dt id="ee-legend-item-tooltip-'.$item.'"'.$active_class.'>'."\n\t\t"; |
|
686 | + $content .= '<span class="'.$details['class'].'"></span>'."\n\t\t"; |
|
687 | + $content .= '<span class="ee-legend-description">'.$details['desc'].'</span>'."\n\t"; |
|
688 | + $content .= '</dt>'."\n"; |
|
689 | 689 | } |
690 | - $content .= '</dl>' . "\n"; |
|
691 | - $content .= '</div>' . "\n"; |
|
690 | + $content .= '</dl>'."\n"; |
|
691 | + $content .= '</div>'."\n"; |
|
692 | 692 | return $content; |
693 | 693 | } |
694 | 694 | |
@@ -833,8 +833,8 @@ discard block |
||
833 | 833 | ); |
834 | 834 | } else { |
835 | 835 | $items_label = array( |
836 | - 'single' => '1 ' . esc_html($items_label['single']), |
|
837 | - 'plural' => '%s ' . esc_html($items_label['plural']), |
|
836 | + 'single' => '1 '.esc_html($items_label['single']), |
|
837 | + 'plural' => '%s '.esc_html($items_label['plural']), |
|
838 | 838 | ); |
839 | 839 | } |
840 | 840 | |
@@ -846,7 +846,7 @@ discard block |
||
846 | 846 | |
847 | 847 | $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
848 | 848 | |
849 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
849 | + $output = '<span class="displaying-num">'.$item_label.'</span>'; |
|
850 | 850 | |
851 | 851 | if ($current === 1) { |
852 | 852 | $disable_first = ' disabled'; |
@@ -857,7 +857,7 @@ discard block |
||
857 | 857 | |
858 | 858 | $page_links[] = sprintf( |
859 | 859 | "<a class='%s' title='%s' href='%s'>%s</a>", |
860 | - 'first-page' . $disable_first, |
|
860 | + 'first-page'.$disable_first, |
|
861 | 861 | esc_attr__('Go to the first page', 'event_espresso'), |
862 | 862 | esc_url(remove_query_arg($paged_arg_name, $url)), |
863 | 863 | '«' |
@@ -865,13 +865,13 @@ discard block |
||
865 | 865 | |
866 | 866 | $page_links[] = sprintf( |
867 | 867 | '<a class="%s" title="%s" href="%s">%s</a>', |
868 | - 'prev-page' . $disable_first, |
|
868 | + 'prev-page'.$disable_first, |
|
869 | 869 | esc_attr__('Go to the previous page', 'event_espresso'), |
870 | 870 | esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
871 | 871 | '‹' |
872 | 872 | ); |
873 | 873 | |
874 | - if (! $show_num_field) { |
|
874 | + if ( ! $show_num_field) { |
|
875 | 875 | $html_current_page = $current; |
876 | 876 | } else { |
877 | 877 | $html_current_page = sprintf( |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | '<span class="total-pages">%s</span>', |
887 | 887 | number_format_i18n($total_pages) |
888 | 888 | ); |
889 | - $page_links[] = sprintf( |
|
889 | + $page_links[] = sprintf( |
|
890 | 890 | _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'), |
891 | 891 | $html_current_page, |
892 | 892 | $html_total_pages, |
@@ -896,7 +896,7 @@ discard block |
||
896 | 896 | |
897 | 897 | $page_links[] = sprintf( |
898 | 898 | '<a class="%s" title="%s" href="%s">%s</a>', |
899 | - 'next-page' . $disable_last, |
|
899 | + 'next-page'.$disable_last, |
|
900 | 900 | esc_attr__('Go to the next page', 'event_espresso'), |
901 | 901 | esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
902 | 902 | '›' |
@@ -904,13 +904,13 @@ discard block |
||
904 | 904 | |
905 | 905 | $page_links[] = sprintf( |
906 | 906 | '<a class="%s" title="%s" href="%s">%s</a>', |
907 | - 'last-page' . $disable_last, |
|
907 | + 'last-page'.$disable_last, |
|
908 | 908 | esc_attr__('Go to the last page', 'event_espresso'), |
909 | 909 | esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
910 | 910 | '»' |
911 | 911 | ); |
912 | 912 | |
913 | - $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
913 | + $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>'; |
|
914 | 914 | // set page class |
915 | 915 | if ($total_pages) { |
916 | 916 | $page_class = $total_pages < 2 ? ' one-page' : ''; |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | $page_class = ' no-pages'; |
919 | 919 | } |
920 | 920 | |
921 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
921 | + return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>'; |
|
922 | 922 | } |
923 | 923 | |
924 | 924 | |
@@ -930,7 +930,7 @@ discard block |
||
930 | 930 | public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array()) |
931 | 931 | { |
932 | 932 | $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
933 | - if (! $admin && |
|
933 | + if ( ! $admin && |
|
934 | 934 | ! apply_filters( |
935 | 935 | 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
936 | 936 | EE_Registry::instance()->CFG->admin->show_reg_footer |
@@ -955,7 +955,7 @@ discard block |
||
955 | 955 | ); |
956 | 956 | $powered_by = apply_filters( |
957 | 957 | 'FHEE__EEH_Template__powered_by_event_espresso_text', |
958 | - $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
958 | + $admin ? 'Event Espresso - '.EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
959 | 959 | ); |
960 | 960 | $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
961 | 961 | $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
@@ -980,7 +980,7 @@ discard block |
||
980 | 980 | |
981 | 981 | |
982 | 982 | |
983 | -if (! function_exists('espresso_pagination')) { |
|
983 | +if ( ! function_exists('espresso_pagination')) { |
|
984 | 984 | /** |
985 | 985 | * espresso_pagination |
986 | 986 | * |
@@ -1008,6 +1008,6 @@ discard block |
||
1008 | 1008 | 'add_fragment' => '', |
1009 | 1009 | ) |
1010 | 1010 | ); |
1011 | - echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
1011 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : ''; |
|
1012 | 1012 | } |
1013 | 1013 | } |
1014 | 1014 | \ No newline at end of file |
@@ -24,666 +24,666 @@ |
||
24 | 24 | class EEH_File extends EEH_Base implements EEHI_File |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var string $_credentials_form |
|
29 | - */ |
|
30 | - private static $_credentials_form; |
|
31 | - |
|
32 | - protected static $_wp_filesystem_direct; |
|
33 | - |
|
34 | - /** |
|
35 | - * @param string|null $filepath the filepath we want to work in. If its in the |
|
36 | - * wp uploads directory, we'll want to just use the filesystem directly. |
|
37 | - * If not provided, we have to assume its not in the uploads directory |
|
38 | - * @throws EE_Error if filesystem credentials are required |
|
39 | - * @return WP_Filesystem_Base |
|
40 | - */ |
|
41 | - private static function _get_wp_filesystem($filepath = null) |
|
42 | - { |
|
43 | - if (apply_filters( |
|
44 | - 'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct', |
|
45 | - $filepath && EEH_File::is_in_uploads_folder($filepath), |
|
46 | - $filepath |
|
47 | - ) ) { |
|
48 | - if (! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) { |
|
49 | - require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); |
|
50 | - $method = 'direct'; |
|
51 | - $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method); |
|
52 | - // check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem() |
|
53 | - if (! defined('FS_CHMOD_DIR')) { |
|
54 | - define('FS_CHMOD_DIR', ( fileperms(ABSPATH) & 0777 | 0755 )); |
|
55 | - } |
|
56 | - if (! defined('FS_CHMOD_FILE')) { |
|
57 | - define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644 )); |
|
58 | - } |
|
59 | - require_once($wp_filesystem_direct_file); |
|
60 | - EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array()); |
|
61 | - } |
|
62 | - return EEH_File::$_wp_filesystem_direct; |
|
63 | - } |
|
64 | - global $wp_filesystem; |
|
65 | - // no filesystem setup ??? |
|
66 | - if (! $wp_filesystem instanceof WP_Filesystem_Base) { |
|
67 | - // if some eager beaver's just trying to get in there too early... |
|
68 | - // let them do it, because we are one of those eager beavers! :P |
|
69 | - /** |
|
70 | - * more explanations are probably merited. http://codex.wordpress.org/Filesystem_API#Initializing_WP_Filesystem_Base |
|
71 | - * says WP_Filesystem should be used after 'wp_loaded', but currently EE's activation process |
|
72 | - * is setup to mostly happen on 'init', and refactoring to have it happen on |
|
73 | - * 'wp_loaded' is too much work on a BETA milestone. |
|
74 | - * So this fix is expected to work if the WP files are owned by the server user, |
|
75 | - * but probably not if the user needs to enter their FTP credentials to modify files |
|
76 | - * and there may be troubles if the WP files are owned by a different user |
|
77 | - * than the server user. But both of these issues should exist in 4.4 and earlier too |
|
78 | - */ |
|
79 | - if (false && ! did_action('wp_loaded')) { |
|
80 | - $msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'); |
|
81 | - if (WP_DEBUG) { |
|
82 | - $msg .= '<br />' . __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
83 | - } |
|
84 | - throw new EE_Error($msg); |
|
85 | - } else { |
|
86 | - // should be loaded if we are past the wp_loaded hook... |
|
87 | - if (! function_exists('WP_Filesystem')) { |
|
88 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
89 | - require_once(ABSPATH . 'wp-admin/includes/template.php'); |
|
90 | - } |
|
91 | - // turn on output buffering so that we can capture the credentials form |
|
92 | - ob_start(); |
|
93 | - $credentials = request_filesystem_credentials(''); |
|
94 | - // store credentials form for the time being |
|
95 | - EEH_File::$_credentials_form = ob_get_clean(); |
|
96 | - // basically check for direct or previously configured access |
|
97 | - if (! WP_Filesystem($credentials)) { |
|
98 | - // if credentials do NOT exist |
|
99 | - if ($credentials === false) { |
|
100 | - add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999); |
|
101 | - throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso')); |
|
102 | - } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { |
|
103 | - add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999); |
|
104 | - throw new EE_Error( |
|
105 | - sprintf( |
|
106 | - __('WP Filesystem Error: $1%s', 'event_espresso'), |
|
107 | - $wp_filesystem->errors->get_error_message() |
|
108 | - ) |
|
109 | - ); |
|
110 | - } |
|
111 | - } |
|
112 | - } |
|
113 | - } |
|
114 | - return $wp_filesystem; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * display_request_filesystem_credentials_form |
|
119 | - */ |
|
120 | - public static function display_request_filesystem_credentials_form() |
|
121 | - { |
|
122 | - if (! empty(EEH_File::$_credentials_form)) { |
|
123 | - echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>'; |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * verify_filepath_and_permissions |
|
131 | - * checks that a file is readable and has sufficient file permissions set to access |
|
132 | - * |
|
133 | - * @access public |
|
134 | - * @param string $full_file_path - full server path to the folder or file |
|
135 | - * @param string $file_name - name of file if checking a file |
|
136 | - * @param string $file_ext - file extension (ie: "php") if checking a file |
|
137 | - * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages |
|
138 | - * @throws EE_Error if filesystem credentials are required |
|
139 | - * @return bool |
|
140 | - */ |
|
141 | - public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '') |
|
142 | - { |
|
143 | - // load WP_Filesystem and set file permissions |
|
144 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
145 | - $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
146 | - if (! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
147 | - $file_name = ! empty($type_of_file) ? $file_name . ' ' . $type_of_file : $file_name; |
|
148 | - $file_name .= ! empty($file_ext) ? ' file' : ' folder'; |
|
149 | - $msg = sprintf( |
|
150 | - __('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'), |
|
151 | - $file_name, |
|
152 | - '<br />' |
|
153 | - ); |
|
154 | - if (EEH_File::exists($full_file_path)) { |
|
155 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file); |
|
156 | - } else { |
|
157 | - // no file permissions means the file was not found |
|
158 | - $msg .= sprintf( |
|
159 | - __('Please ensure the following path is correct: "%s".', 'event_espresso'), |
|
160 | - $full_file_path |
|
161 | - ); |
|
162 | - } |
|
163 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
164 | - throw new EE_Error($msg . '||' . $msg); |
|
165 | - } |
|
166 | - return false; |
|
167 | - } |
|
168 | - return true; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * _permissions_error_for_unreadable_filepath - attempts to determine why permissions are set incorrectly for a file or folder |
|
175 | - * |
|
176 | - * @access private |
|
177 | - * @param string $full_file_path - full server path to the folder or file |
|
178 | - * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages |
|
179 | - * @throws EE_Error if filesystem credentials are required |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '') |
|
183 | - { |
|
184 | - // load WP_Filesystem and set file permissions |
|
185 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
186 | - // check file permissions |
|
187 | - $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
188 | - if ($perms) { |
|
189 | - // file permissions exist, but way be set incorrectly |
|
190 | - $type_of_file = ! empty($type_of_file) ? $type_of_file . ' ' : ''; |
|
191 | - $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder'; |
|
192 | - return sprintf( |
|
193 | - __('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'), |
|
194 | - $type_of_file, |
|
195 | - $perms |
|
196 | - ); |
|
197 | - } else { |
|
198 | - // file exists but file permissions could not be read ?!?! |
|
199 | - return sprintf( |
|
200 | - __('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'), |
|
201 | - $full_file_path |
|
202 | - ); |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * ensure_folder_exists_and_is_writable |
|
210 | - * ensures that a folder exists and is writable, will attempt to create folder if it does not exist |
|
211 | - * Also ensures all the parent folders exist, and if not tries to create them. |
|
212 | - * Also, if this function creates the folder, adds a .htaccess file and index.html file |
|
213 | - * @param string $folder |
|
214 | - * @throws EE_Error if the folder exists and is writeable, but for some reason we |
|
215 | - * can't write to it |
|
216 | - * @return bool false if folder isn't writable; true if it exists and is writeable, |
|
217 | - */ |
|
218 | - public static function ensure_folder_exists_and_is_writable($folder = '') |
|
219 | - { |
|
220 | - if (empty($folder)) { |
|
221 | - return false; |
|
222 | - } |
|
223 | - // remove ending / |
|
224 | - $folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\')); |
|
225 | - $parent_folder = EEH_File::get_parent_folder($folder); |
|
226 | - // add / to folder |
|
227 | - $folder = EEH_File::end_with_directory_separator($folder); |
|
228 | - $wp_filesystem = EEH_File::_get_wp_filesystem($folder); |
|
229 | - if (! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
230 | - // ok so it doesn't exist. Does its parent? Can we write to it? |
|
231 | - if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
232 | - return false; |
|
233 | - } |
|
234 | - if (! EEH_File::verify_is_writable($parent_folder, 'folder')) { |
|
235 | - return false; |
|
236 | - } else { |
|
237 | - if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
238 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
239 | - $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder); |
|
240 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder); |
|
241 | - throw new EE_Error($msg); |
|
242 | - } |
|
243 | - return false; |
|
244 | - } |
|
245 | - EEH_File::add_index_file($folder); |
|
246 | - } |
|
247 | - } elseif (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
248 | - return false; |
|
249 | - } |
|
250 | - return true; |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * verify_is_writable - checks if a file or folder is writable |
|
257 | - * @param string $full_path - full server path to file or folder |
|
258 | - * @param string $file_or_folder - whether checking a file or folder |
|
259 | - * @throws EE_Error if filesystem credentials are required |
|
260 | - * @return bool |
|
261 | - */ |
|
262 | - public static function verify_is_writable($full_path = '', $file_or_folder = 'folder') |
|
263 | - { |
|
264 | - // load WP_Filesystem and set file permissions |
|
265 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_path); |
|
266 | - $full_path = EEH_File::standardise_directory_separators($full_path); |
|
267 | - if (! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) { |
|
268 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
269 | - $msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder); |
|
270 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path); |
|
271 | - throw new EE_Error($msg); |
|
272 | - } |
|
273 | - return false; |
|
274 | - } |
|
275 | - return true; |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * ensure_file_exists_and_is_writable |
|
282 | - * ensures that a file exists and is writable, will attempt to create file if it does not exist. |
|
283 | - * Also ensures all the parent folders exist, and if not tries to create them. |
|
284 | - * @param string $full_file_path |
|
285 | - * @throws EE_Error if filesystem credentials are required |
|
286 | - * @return bool |
|
287 | - */ |
|
288 | - public static function ensure_file_exists_and_is_writable($full_file_path = '') |
|
289 | - { |
|
290 | - // load WP_Filesystem and set file permissions |
|
291 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
292 | - $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
293 | - $parent_folder = EEH_File::get_parent_folder($full_file_path); |
|
294 | - if (! EEH_File::exists($full_file_path)) { |
|
295 | - if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
296 | - return false; |
|
297 | - } |
|
298 | - if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
299 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
300 | - $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path); |
|
301 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
302 | - throw new EE_Error($msg); |
|
303 | - } |
|
304 | - return false; |
|
305 | - } |
|
306 | - } |
|
307 | - if (! EEH_File::verify_is_writable($full_file_path, 'file')) { |
|
308 | - return false; |
|
309 | - } |
|
310 | - return true; |
|
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * Gets the parent folder. If provided with file, gets the folder that contains it. |
|
315 | - * If provided a folder, gets its parent folder. |
|
316 | - * @param string $file_or_folder_path |
|
317 | - * @return string parent folder, ENDING with a directory separator |
|
318 | - */ |
|
319 | - public static function get_parent_folder($file_or_folder_path) |
|
320 | - { |
|
321 | - // find the last /, ignoring a / on the very end |
|
322 | - // eg if given "/var/something/somewhere/", we want to get "somewhere"'s |
|
323 | - // parent folder, "/var/something/" |
|
324 | - $ds = strlen($file_or_folder_path) > 1 |
|
325 | - ? strrpos($file_or_folder_path, '/', -2) |
|
326 | - : strlen($file_or_folder_path); |
|
327 | - return substr($file_or_folder_path, 0, $ds + 1); |
|
328 | - } |
|
329 | - |
|
330 | - // public static function ensure_folder_exists_recursively( $folder ) { |
|
331 | - // |
|
332 | - // } |
|
333 | - |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * get_file_contents |
|
338 | - * @param string $full_file_path |
|
339 | - * @throws EE_Error if filesystem credentials are required |
|
340 | - * @return string |
|
341 | - */ |
|
342 | - public static function get_file_contents($full_file_path = '') |
|
343 | - { |
|
344 | - $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
345 | - if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) { |
|
346 | - // load WP_Filesystem and set file permissions |
|
347 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
348 | - return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
349 | - } |
|
350 | - return ''; |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * write_file |
|
357 | - * @param string $full_file_path |
|
358 | - * @param string $file_contents - the content to be written to the file |
|
359 | - * @param string $file_type |
|
360 | - * @throws EE_Error if filesystem credentials are required |
|
361 | - * @return bool |
|
362 | - */ |
|
363 | - public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') |
|
364 | - { |
|
365 | - $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
366 | - $file_type = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : ''; |
|
367 | - $folder = EEH_File::remove_filename_from_filepath($full_file_path); |
|
368 | - if (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
369 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
370 | - $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path); |
|
371 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
372 | - throw new EE_Error($msg); |
|
373 | - } |
|
374 | - return false; |
|
375 | - } |
|
376 | - // load WP_Filesystem and set file permissions |
|
377 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
378 | - // write the file |
|
379 | - if (! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) { |
|
380 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
381 | - $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path); |
|
382 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f'); |
|
383 | - throw new EE_Error($msg); |
|
384 | - } |
|
385 | - return false; |
|
386 | - } |
|
387 | - return true; |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * Wrapper for WP_Filesystem_Base::delete |
|
392 | - * |
|
393 | - * @param string $filepath |
|
394 | - * @param boolean $recursive |
|
395 | - * @param boolean|string $type 'd' for directory, 'f' for file |
|
396 | - * @throws EE_Error if filesystem credentials are required |
|
397 | - * @return boolean |
|
398 | - */ |
|
399 | - public static function delete($filepath, $recursive = false, $type = false) |
|
400 | - { |
|
401 | - $wp_filesystem = EEH_File::_get_wp_filesystem(); |
|
402 | - return $wp_filesystem->delete($filepath, $recursive, $type) ? true : false; |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * exists |
|
409 | - * checks if a file exists using the WP filesystem |
|
410 | - * @param string $full_file_path |
|
411 | - * @throws EE_Error if filesystem credentials are required |
|
412 | - * @return bool |
|
413 | - */ |
|
414 | - public static function exists($full_file_path = '') |
|
415 | - { |
|
416 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
417 | - return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? true : false; |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * is_readable |
|
424 | - * checks if a file is_readable using the WP filesystem |
|
425 | - * |
|
426 | - * @param string $full_file_path |
|
427 | - * @throws EE_Error if filesystem credentials are required |
|
428 | - * @return bool |
|
429 | - */ |
|
430 | - public static function is_readable($full_file_path = '') |
|
431 | - { |
|
432 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
433 | - if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
434 | - return true; |
|
435 | - } else { |
|
436 | - return false; |
|
437 | - } |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * remove_filename_from_filepath |
|
444 | - * given a full path to a file including the filename itself, this removes the filename and returns the path, up to, but NOT including the filename OR slash |
|
445 | - * |
|
446 | - * @param string $full_file_path |
|
447 | - * @return string |
|
448 | - */ |
|
449 | - public static function remove_filename_from_filepath($full_file_path = '') |
|
450 | - { |
|
451 | - return pathinfo($full_file_path, PATHINFO_DIRNAME); |
|
452 | - } |
|
453 | - |
|
454 | - |
|
455 | - /** |
|
456 | - * get_filename_from_filepath. Arguably the same as basename() |
|
457 | - * |
|
458 | - * @param string $full_file_path |
|
459 | - * @return string |
|
460 | - */ |
|
461 | - public static function get_filename_from_filepath($full_file_path = '') |
|
462 | - { |
|
463 | - return pathinfo($full_file_path, PATHINFO_BASENAME); |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * get_file_extension |
|
469 | - * |
|
470 | - * @param string $full_file_path |
|
471 | - * @return string |
|
472 | - */ |
|
473 | - public static function get_file_extension($full_file_path = '') |
|
474 | - { |
|
475 | - return pathinfo($full_file_path, PATHINFO_EXTENSION); |
|
476 | - } |
|
477 | - |
|
478 | - |
|
479 | - |
|
480 | - /** |
|
481 | - * add_htaccess_deny_from_all so the webserver cannot access this folder |
|
482 | - * @param string $folder |
|
483 | - * @throws EE_Error if filesystem credentials are required |
|
484 | - * @return bool |
|
485 | - */ |
|
486 | - public static function add_htaccess_deny_from_all($folder = '') |
|
487 | - { |
|
488 | - $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
489 | - if (! EEH_File::exists($folder . '.htaccess')) { |
|
490 | - if (! EEH_File::write_to_file($folder . '.htaccess', 'deny from all', '.htaccess')) { |
|
491 | - return false; |
|
492 | - } |
|
493 | - } |
|
494 | - |
|
495 | - return true; |
|
496 | - } |
|
497 | - |
|
498 | - /** |
|
499 | - * Adds an index file to this folder, so folks can't list all the file's contents |
|
500 | - * @param string $folder |
|
501 | - * @throws EE_Error if filesystem credentials are required |
|
502 | - * @return boolean |
|
503 | - */ |
|
504 | - public static function add_index_file($folder) |
|
505 | - { |
|
506 | - $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
507 | - if (! EEH_File::exists($folder . 'index.php')) { |
|
508 | - if (! EEH_File::write_to_file($folder . 'index.php', 'You are not permitted to read from this folder', '.php')) { |
|
509 | - return false; |
|
510 | - } |
|
511 | - } |
|
512 | - return true; |
|
513 | - } |
|
514 | - |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * Given that the file in $file_path has the normal name, (ie, CLASSNAME.whatever.php), |
|
519 | - * extract that classname. |
|
520 | - * @param string $file_path |
|
521 | - * @return string |
|
522 | - */ |
|
523 | - public static function get_classname_from_filepath_with_standard_filename($file_path) |
|
524 | - { |
|
525 | - // extract file from path |
|
526 | - $filename = basename($file_path); |
|
527 | - // now remove the first period and everything after |
|
528 | - $pos_of_first_period = strpos($filename, '.'); |
|
529 | - return substr($filename, 0, $pos_of_first_period); |
|
530 | - } |
|
531 | - |
|
532 | - |
|
533 | - |
|
534 | - /** |
|
535 | - * standardise_directory_separators |
|
536 | - * convert all directory separators in a file path. |
|
537 | - * @param string $file_path |
|
538 | - * @return string |
|
539 | - */ |
|
540 | - public static function standardise_directory_separators($file_path) |
|
541 | - { |
|
542 | - return str_replace(array( '\\', '/' ), '/', $file_path); |
|
543 | - } |
|
544 | - |
|
545 | - |
|
546 | - |
|
547 | - /** |
|
548 | - * end_with_directory_separator |
|
549 | - * ensures that file path ends with '/' |
|
550 | - * @param string $file_path |
|
551 | - * @return string |
|
552 | - */ |
|
553 | - public static function end_with_directory_separator($file_path) |
|
554 | - { |
|
555 | - return rtrim($file_path, '/\\') . '/'; |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - |
|
560 | - /** |
|
561 | - * shorthand for both EEH_FIle::end_with_directory_separator AND EEH_File::standardise_directory_separators |
|
562 | - * @param $file_path |
|
563 | - * @return string |
|
564 | - */ |
|
565 | - public static function standardise_and_end_with_directory_separator($file_path) |
|
566 | - { |
|
567 | - return self::end_with_directory_separator(self::standardise_directory_separators($file_path)); |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - |
|
572 | - /** |
|
573 | - * takes the folder name (with or without trailing slash) and finds the files it in, |
|
574 | - * and what the class's name inside of each should be. |
|
575 | - * @param array $folder_paths |
|
576 | - * @param boolean $index_numerically if TRUE, the returned array will be indexed numerically; |
|
577 | - * if FALSE (Default), returned array will be indexed by the filenames minus extensions. |
|
578 | - * Set it TRUE if you know there are files in the directory with the same name but different extensions |
|
579 | - * @throws EE_Error if filesystem credentials are required |
|
580 | - * @return array if $index_numerically == TRUE keys are numeric , |
|
581 | - * if $index_numerically == FALSE (Default) keys are what the class names SHOULD be; |
|
582 | - * and values are their filepaths |
|
583 | - */ |
|
584 | - public static function get_contents_of_folders($folder_paths = array(), $index_numerically = false) |
|
585 | - { |
|
586 | - $class_to_folder_path = array(); |
|
587 | - foreach ($folder_paths as $folder_path) { |
|
588 | - $folder_path = self::standardise_and_end_with_directory_separator($folder_path); |
|
589 | - // load WP_Filesystem and set file permissions |
|
590 | - $files_in_folder = glob($folder_path . '*'); |
|
591 | - $class_to_folder_path = array(); |
|
592 | - if ($files_in_folder) { |
|
593 | - foreach ($files_in_folder as $file_path) { |
|
594 | - // only add files, not folders |
|
595 | - if (! is_dir($file_path)) { |
|
596 | - if ($index_numerically) { |
|
597 | - $class_to_folder_path[] = $file_path; |
|
598 | - } else { |
|
599 | - $classname = self::get_classname_from_filepath_with_standard_filename($file_path); |
|
600 | - $class_to_folder_path[ $classname ] = $file_path; |
|
601 | - } |
|
602 | - } |
|
603 | - } |
|
604 | - } |
|
605 | - } |
|
606 | - return $class_to_folder_path; |
|
607 | - } |
|
608 | - |
|
609 | - |
|
610 | - |
|
611 | - /** |
|
612 | - * Copies a file. Mostly a wrapper of WP_Filesystem::copy |
|
613 | - * @param string $source_file |
|
614 | - * @param string $destination_file |
|
615 | - * @param boolean $overwrite |
|
616 | - * @throws EE_Error if filesystem credentials are required |
|
617 | - * @return boolean success |
|
618 | - */ |
|
619 | - public static function copy($source_file, $destination_file, $overwrite = false) |
|
620 | - { |
|
621 | - $full_source_path = EEH_File::standardise_directory_separators($source_file); |
|
622 | - if (! EEH_File::exists($full_source_path)) { |
|
623 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
624 | - $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path); |
|
625 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path); |
|
626 | - throw new EE_Error($msg); |
|
627 | - } |
|
628 | - return false; |
|
629 | - } |
|
630 | - |
|
631 | - $full_dest_path = EEH_File::standardise_directory_separators($destination_file); |
|
632 | - $folder = EEH_File::remove_filename_from_filepath($full_dest_path); |
|
633 | - EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
634 | - if (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
635 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
636 | - $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path); |
|
637 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path); |
|
638 | - throw new EE_Error($msg); |
|
639 | - } |
|
640 | - return false; |
|
641 | - } |
|
642 | - |
|
643 | - // load WP_Filesystem and set file permissions |
|
644 | - $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file); |
|
645 | - // write the file |
|
646 | - if (! $wp_filesystem->copy( |
|
647 | - EEH_File::convert_local_filepath_to_remote_filepath($full_source_path), |
|
648 | - EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path), |
|
649 | - $overwrite |
|
650 | - )) { |
|
651 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
652 | - $msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path); |
|
653 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f'); |
|
654 | - throw new EE_Error($msg); |
|
655 | - } |
|
656 | - return false; |
|
657 | - } |
|
658 | - return true; |
|
659 | - } |
|
660 | - |
|
661 | - /** |
|
662 | - * Reports whether or not the filepath is in the EE uploads folder or not |
|
663 | - * @param string $filepath |
|
664 | - * @return boolean |
|
665 | - */ |
|
666 | - public static function is_in_uploads_folder($filepath) |
|
667 | - { |
|
668 | - $uploads = wp_upload_dir(); |
|
669 | - return strpos($filepath, $uploads['basedir']) === 0 ? true : false; |
|
670 | - } |
|
671 | - |
|
672 | - /** |
|
673 | - * Given a "local" filepath (what you probably thought was the only filepath), |
|
674 | - * converts it into a "remote" filepath (the filepath the currently-in-use |
|
675 | - * $wp_filesystem needs to use access the folder or file). |
|
676 | - * See http://wordpress.stackexchange.com/questions/124900/using-wp-filesystem-in-plugins |
|
677 | - * @param WP_Filesystem_Base $wp_filesystem we aren't initially sure which one |
|
678 | - * is in use, so you need to provide it |
|
679 | - * @param string $local_filepath the filepath to the folder/file locally |
|
680 | - * @throws EE_Error if filesystem credentials are required |
|
681 | - * @return string the remote filepath (eg the filepath the filesystem method, eg |
|
682 | - * ftp or ssh, will use to access the folder |
|
683 | - */ |
|
684 | - public static function convert_local_filepath_to_remote_filepath($local_filepath) |
|
685 | - { |
|
686 | - $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath); |
|
687 | - return str_replace(WP_CONTENT_DIR . '/', $wp_filesystem->wp_content_dir(), $local_filepath); |
|
688 | - } |
|
27 | + /** |
|
28 | + * @var string $_credentials_form |
|
29 | + */ |
|
30 | + private static $_credentials_form; |
|
31 | + |
|
32 | + protected static $_wp_filesystem_direct; |
|
33 | + |
|
34 | + /** |
|
35 | + * @param string|null $filepath the filepath we want to work in. If its in the |
|
36 | + * wp uploads directory, we'll want to just use the filesystem directly. |
|
37 | + * If not provided, we have to assume its not in the uploads directory |
|
38 | + * @throws EE_Error if filesystem credentials are required |
|
39 | + * @return WP_Filesystem_Base |
|
40 | + */ |
|
41 | + private static function _get_wp_filesystem($filepath = null) |
|
42 | + { |
|
43 | + if (apply_filters( |
|
44 | + 'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct', |
|
45 | + $filepath && EEH_File::is_in_uploads_folder($filepath), |
|
46 | + $filepath |
|
47 | + ) ) { |
|
48 | + if (! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) { |
|
49 | + require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); |
|
50 | + $method = 'direct'; |
|
51 | + $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method); |
|
52 | + // check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem() |
|
53 | + if (! defined('FS_CHMOD_DIR')) { |
|
54 | + define('FS_CHMOD_DIR', ( fileperms(ABSPATH) & 0777 | 0755 )); |
|
55 | + } |
|
56 | + if (! defined('FS_CHMOD_FILE')) { |
|
57 | + define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644 )); |
|
58 | + } |
|
59 | + require_once($wp_filesystem_direct_file); |
|
60 | + EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array()); |
|
61 | + } |
|
62 | + return EEH_File::$_wp_filesystem_direct; |
|
63 | + } |
|
64 | + global $wp_filesystem; |
|
65 | + // no filesystem setup ??? |
|
66 | + if (! $wp_filesystem instanceof WP_Filesystem_Base) { |
|
67 | + // if some eager beaver's just trying to get in there too early... |
|
68 | + // let them do it, because we are one of those eager beavers! :P |
|
69 | + /** |
|
70 | + * more explanations are probably merited. http://codex.wordpress.org/Filesystem_API#Initializing_WP_Filesystem_Base |
|
71 | + * says WP_Filesystem should be used after 'wp_loaded', but currently EE's activation process |
|
72 | + * is setup to mostly happen on 'init', and refactoring to have it happen on |
|
73 | + * 'wp_loaded' is too much work on a BETA milestone. |
|
74 | + * So this fix is expected to work if the WP files are owned by the server user, |
|
75 | + * but probably not if the user needs to enter their FTP credentials to modify files |
|
76 | + * and there may be troubles if the WP files are owned by a different user |
|
77 | + * than the server user. But both of these issues should exist in 4.4 and earlier too |
|
78 | + */ |
|
79 | + if (false && ! did_action('wp_loaded')) { |
|
80 | + $msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'); |
|
81 | + if (WP_DEBUG) { |
|
82 | + $msg .= '<br />' . __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
83 | + } |
|
84 | + throw new EE_Error($msg); |
|
85 | + } else { |
|
86 | + // should be loaded if we are past the wp_loaded hook... |
|
87 | + if (! function_exists('WP_Filesystem')) { |
|
88 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
89 | + require_once(ABSPATH . 'wp-admin/includes/template.php'); |
|
90 | + } |
|
91 | + // turn on output buffering so that we can capture the credentials form |
|
92 | + ob_start(); |
|
93 | + $credentials = request_filesystem_credentials(''); |
|
94 | + // store credentials form for the time being |
|
95 | + EEH_File::$_credentials_form = ob_get_clean(); |
|
96 | + // basically check for direct or previously configured access |
|
97 | + if (! WP_Filesystem($credentials)) { |
|
98 | + // if credentials do NOT exist |
|
99 | + if ($credentials === false) { |
|
100 | + add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999); |
|
101 | + throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso')); |
|
102 | + } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { |
|
103 | + add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999); |
|
104 | + throw new EE_Error( |
|
105 | + sprintf( |
|
106 | + __('WP Filesystem Error: $1%s', 'event_espresso'), |
|
107 | + $wp_filesystem->errors->get_error_message() |
|
108 | + ) |
|
109 | + ); |
|
110 | + } |
|
111 | + } |
|
112 | + } |
|
113 | + } |
|
114 | + return $wp_filesystem; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * display_request_filesystem_credentials_form |
|
119 | + */ |
|
120 | + public static function display_request_filesystem_credentials_form() |
|
121 | + { |
|
122 | + if (! empty(EEH_File::$_credentials_form)) { |
|
123 | + echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>'; |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * verify_filepath_and_permissions |
|
131 | + * checks that a file is readable and has sufficient file permissions set to access |
|
132 | + * |
|
133 | + * @access public |
|
134 | + * @param string $full_file_path - full server path to the folder or file |
|
135 | + * @param string $file_name - name of file if checking a file |
|
136 | + * @param string $file_ext - file extension (ie: "php") if checking a file |
|
137 | + * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages |
|
138 | + * @throws EE_Error if filesystem credentials are required |
|
139 | + * @return bool |
|
140 | + */ |
|
141 | + public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '') |
|
142 | + { |
|
143 | + // load WP_Filesystem and set file permissions |
|
144 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
145 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
146 | + if (! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
147 | + $file_name = ! empty($type_of_file) ? $file_name . ' ' . $type_of_file : $file_name; |
|
148 | + $file_name .= ! empty($file_ext) ? ' file' : ' folder'; |
|
149 | + $msg = sprintf( |
|
150 | + __('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'), |
|
151 | + $file_name, |
|
152 | + '<br />' |
|
153 | + ); |
|
154 | + if (EEH_File::exists($full_file_path)) { |
|
155 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file); |
|
156 | + } else { |
|
157 | + // no file permissions means the file was not found |
|
158 | + $msg .= sprintf( |
|
159 | + __('Please ensure the following path is correct: "%s".', 'event_espresso'), |
|
160 | + $full_file_path |
|
161 | + ); |
|
162 | + } |
|
163 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
164 | + throw new EE_Error($msg . '||' . $msg); |
|
165 | + } |
|
166 | + return false; |
|
167 | + } |
|
168 | + return true; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * _permissions_error_for_unreadable_filepath - attempts to determine why permissions are set incorrectly for a file or folder |
|
175 | + * |
|
176 | + * @access private |
|
177 | + * @param string $full_file_path - full server path to the folder or file |
|
178 | + * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages |
|
179 | + * @throws EE_Error if filesystem credentials are required |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '') |
|
183 | + { |
|
184 | + // load WP_Filesystem and set file permissions |
|
185 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
186 | + // check file permissions |
|
187 | + $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
188 | + if ($perms) { |
|
189 | + // file permissions exist, but way be set incorrectly |
|
190 | + $type_of_file = ! empty($type_of_file) ? $type_of_file . ' ' : ''; |
|
191 | + $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder'; |
|
192 | + return sprintf( |
|
193 | + __('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'), |
|
194 | + $type_of_file, |
|
195 | + $perms |
|
196 | + ); |
|
197 | + } else { |
|
198 | + // file exists but file permissions could not be read ?!?! |
|
199 | + return sprintf( |
|
200 | + __('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'), |
|
201 | + $full_file_path |
|
202 | + ); |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * ensure_folder_exists_and_is_writable |
|
210 | + * ensures that a folder exists and is writable, will attempt to create folder if it does not exist |
|
211 | + * Also ensures all the parent folders exist, and if not tries to create them. |
|
212 | + * Also, if this function creates the folder, adds a .htaccess file and index.html file |
|
213 | + * @param string $folder |
|
214 | + * @throws EE_Error if the folder exists and is writeable, but for some reason we |
|
215 | + * can't write to it |
|
216 | + * @return bool false if folder isn't writable; true if it exists and is writeable, |
|
217 | + */ |
|
218 | + public static function ensure_folder_exists_and_is_writable($folder = '') |
|
219 | + { |
|
220 | + if (empty($folder)) { |
|
221 | + return false; |
|
222 | + } |
|
223 | + // remove ending / |
|
224 | + $folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\')); |
|
225 | + $parent_folder = EEH_File::get_parent_folder($folder); |
|
226 | + // add / to folder |
|
227 | + $folder = EEH_File::end_with_directory_separator($folder); |
|
228 | + $wp_filesystem = EEH_File::_get_wp_filesystem($folder); |
|
229 | + if (! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
230 | + // ok so it doesn't exist. Does its parent? Can we write to it? |
|
231 | + if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
232 | + return false; |
|
233 | + } |
|
234 | + if (! EEH_File::verify_is_writable($parent_folder, 'folder')) { |
|
235 | + return false; |
|
236 | + } else { |
|
237 | + if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
238 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
239 | + $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder); |
|
240 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder); |
|
241 | + throw new EE_Error($msg); |
|
242 | + } |
|
243 | + return false; |
|
244 | + } |
|
245 | + EEH_File::add_index_file($folder); |
|
246 | + } |
|
247 | + } elseif (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
248 | + return false; |
|
249 | + } |
|
250 | + return true; |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * verify_is_writable - checks if a file or folder is writable |
|
257 | + * @param string $full_path - full server path to file or folder |
|
258 | + * @param string $file_or_folder - whether checking a file or folder |
|
259 | + * @throws EE_Error if filesystem credentials are required |
|
260 | + * @return bool |
|
261 | + */ |
|
262 | + public static function verify_is_writable($full_path = '', $file_or_folder = 'folder') |
|
263 | + { |
|
264 | + // load WP_Filesystem and set file permissions |
|
265 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_path); |
|
266 | + $full_path = EEH_File::standardise_directory_separators($full_path); |
|
267 | + if (! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) { |
|
268 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
269 | + $msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder); |
|
270 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path); |
|
271 | + throw new EE_Error($msg); |
|
272 | + } |
|
273 | + return false; |
|
274 | + } |
|
275 | + return true; |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * ensure_file_exists_and_is_writable |
|
282 | + * ensures that a file exists and is writable, will attempt to create file if it does not exist. |
|
283 | + * Also ensures all the parent folders exist, and if not tries to create them. |
|
284 | + * @param string $full_file_path |
|
285 | + * @throws EE_Error if filesystem credentials are required |
|
286 | + * @return bool |
|
287 | + */ |
|
288 | + public static function ensure_file_exists_and_is_writable($full_file_path = '') |
|
289 | + { |
|
290 | + // load WP_Filesystem and set file permissions |
|
291 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
292 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
293 | + $parent_folder = EEH_File::get_parent_folder($full_file_path); |
|
294 | + if (! EEH_File::exists($full_file_path)) { |
|
295 | + if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
296 | + return false; |
|
297 | + } |
|
298 | + if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
299 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
300 | + $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path); |
|
301 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
302 | + throw new EE_Error($msg); |
|
303 | + } |
|
304 | + return false; |
|
305 | + } |
|
306 | + } |
|
307 | + if (! EEH_File::verify_is_writable($full_file_path, 'file')) { |
|
308 | + return false; |
|
309 | + } |
|
310 | + return true; |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * Gets the parent folder. If provided with file, gets the folder that contains it. |
|
315 | + * If provided a folder, gets its parent folder. |
|
316 | + * @param string $file_or_folder_path |
|
317 | + * @return string parent folder, ENDING with a directory separator |
|
318 | + */ |
|
319 | + public static function get_parent_folder($file_or_folder_path) |
|
320 | + { |
|
321 | + // find the last /, ignoring a / on the very end |
|
322 | + // eg if given "/var/something/somewhere/", we want to get "somewhere"'s |
|
323 | + // parent folder, "/var/something/" |
|
324 | + $ds = strlen($file_or_folder_path) > 1 |
|
325 | + ? strrpos($file_or_folder_path, '/', -2) |
|
326 | + : strlen($file_or_folder_path); |
|
327 | + return substr($file_or_folder_path, 0, $ds + 1); |
|
328 | + } |
|
329 | + |
|
330 | + // public static function ensure_folder_exists_recursively( $folder ) { |
|
331 | + // |
|
332 | + // } |
|
333 | + |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * get_file_contents |
|
338 | + * @param string $full_file_path |
|
339 | + * @throws EE_Error if filesystem credentials are required |
|
340 | + * @return string |
|
341 | + */ |
|
342 | + public static function get_file_contents($full_file_path = '') |
|
343 | + { |
|
344 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
345 | + if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) { |
|
346 | + // load WP_Filesystem and set file permissions |
|
347 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
348 | + return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
349 | + } |
|
350 | + return ''; |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * write_file |
|
357 | + * @param string $full_file_path |
|
358 | + * @param string $file_contents - the content to be written to the file |
|
359 | + * @param string $file_type |
|
360 | + * @throws EE_Error if filesystem credentials are required |
|
361 | + * @return bool |
|
362 | + */ |
|
363 | + public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') |
|
364 | + { |
|
365 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
366 | + $file_type = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : ''; |
|
367 | + $folder = EEH_File::remove_filename_from_filepath($full_file_path); |
|
368 | + if (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
369 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
370 | + $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path); |
|
371 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
372 | + throw new EE_Error($msg); |
|
373 | + } |
|
374 | + return false; |
|
375 | + } |
|
376 | + // load WP_Filesystem and set file permissions |
|
377 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
378 | + // write the file |
|
379 | + if (! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) { |
|
380 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
381 | + $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path); |
|
382 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f'); |
|
383 | + throw new EE_Error($msg); |
|
384 | + } |
|
385 | + return false; |
|
386 | + } |
|
387 | + return true; |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * Wrapper for WP_Filesystem_Base::delete |
|
392 | + * |
|
393 | + * @param string $filepath |
|
394 | + * @param boolean $recursive |
|
395 | + * @param boolean|string $type 'd' for directory, 'f' for file |
|
396 | + * @throws EE_Error if filesystem credentials are required |
|
397 | + * @return boolean |
|
398 | + */ |
|
399 | + public static function delete($filepath, $recursive = false, $type = false) |
|
400 | + { |
|
401 | + $wp_filesystem = EEH_File::_get_wp_filesystem(); |
|
402 | + return $wp_filesystem->delete($filepath, $recursive, $type) ? true : false; |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * exists |
|
409 | + * checks if a file exists using the WP filesystem |
|
410 | + * @param string $full_file_path |
|
411 | + * @throws EE_Error if filesystem credentials are required |
|
412 | + * @return bool |
|
413 | + */ |
|
414 | + public static function exists($full_file_path = '') |
|
415 | + { |
|
416 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
417 | + return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? true : false; |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * is_readable |
|
424 | + * checks if a file is_readable using the WP filesystem |
|
425 | + * |
|
426 | + * @param string $full_file_path |
|
427 | + * @throws EE_Error if filesystem credentials are required |
|
428 | + * @return bool |
|
429 | + */ |
|
430 | + public static function is_readable($full_file_path = '') |
|
431 | + { |
|
432 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
433 | + if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
434 | + return true; |
|
435 | + } else { |
|
436 | + return false; |
|
437 | + } |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * remove_filename_from_filepath |
|
444 | + * given a full path to a file including the filename itself, this removes the filename and returns the path, up to, but NOT including the filename OR slash |
|
445 | + * |
|
446 | + * @param string $full_file_path |
|
447 | + * @return string |
|
448 | + */ |
|
449 | + public static function remove_filename_from_filepath($full_file_path = '') |
|
450 | + { |
|
451 | + return pathinfo($full_file_path, PATHINFO_DIRNAME); |
|
452 | + } |
|
453 | + |
|
454 | + |
|
455 | + /** |
|
456 | + * get_filename_from_filepath. Arguably the same as basename() |
|
457 | + * |
|
458 | + * @param string $full_file_path |
|
459 | + * @return string |
|
460 | + */ |
|
461 | + public static function get_filename_from_filepath($full_file_path = '') |
|
462 | + { |
|
463 | + return pathinfo($full_file_path, PATHINFO_BASENAME); |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * get_file_extension |
|
469 | + * |
|
470 | + * @param string $full_file_path |
|
471 | + * @return string |
|
472 | + */ |
|
473 | + public static function get_file_extension($full_file_path = '') |
|
474 | + { |
|
475 | + return pathinfo($full_file_path, PATHINFO_EXTENSION); |
|
476 | + } |
|
477 | + |
|
478 | + |
|
479 | + |
|
480 | + /** |
|
481 | + * add_htaccess_deny_from_all so the webserver cannot access this folder |
|
482 | + * @param string $folder |
|
483 | + * @throws EE_Error if filesystem credentials are required |
|
484 | + * @return bool |
|
485 | + */ |
|
486 | + public static function add_htaccess_deny_from_all($folder = '') |
|
487 | + { |
|
488 | + $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
489 | + if (! EEH_File::exists($folder . '.htaccess')) { |
|
490 | + if (! EEH_File::write_to_file($folder . '.htaccess', 'deny from all', '.htaccess')) { |
|
491 | + return false; |
|
492 | + } |
|
493 | + } |
|
494 | + |
|
495 | + return true; |
|
496 | + } |
|
497 | + |
|
498 | + /** |
|
499 | + * Adds an index file to this folder, so folks can't list all the file's contents |
|
500 | + * @param string $folder |
|
501 | + * @throws EE_Error if filesystem credentials are required |
|
502 | + * @return boolean |
|
503 | + */ |
|
504 | + public static function add_index_file($folder) |
|
505 | + { |
|
506 | + $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
507 | + if (! EEH_File::exists($folder . 'index.php')) { |
|
508 | + if (! EEH_File::write_to_file($folder . 'index.php', 'You are not permitted to read from this folder', '.php')) { |
|
509 | + return false; |
|
510 | + } |
|
511 | + } |
|
512 | + return true; |
|
513 | + } |
|
514 | + |
|
515 | + |
|
516 | + |
|
517 | + /** |
|
518 | + * Given that the file in $file_path has the normal name, (ie, CLASSNAME.whatever.php), |
|
519 | + * extract that classname. |
|
520 | + * @param string $file_path |
|
521 | + * @return string |
|
522 | + */ |
|
523 | + public static function get_classname_from_filepath_with_standard_filename($file_path) |
|
524 | + { |
|
525 | + // extract file from path |
|
526 | + $filename = basename($file_path); |
|
527 | + // now remove the first period and everything after |
|
528 | + $pos_of_first_period = strpos($filename, '.'); |
|
529 | + return substr($filename, 0, $pos_of_first_period); |
|
530 | + } |
|
531 | + |
|
532 | + |
|
533 | + |
|
534 | + /** |
|
535 | + * standardise_directory_separators |
|
536 | + * convert all directory separators in a file path. |
|
537 | + * @param string $file_path |
|
538 | + * @return string |
|
539 | + */ |
|
540 | + public static function standardise_directory_separators($file_path) |
|
541 | + { |
|
542 | + return str_replace(array( '\\', '/' ), '/', $file_path); |
|
543 | + } |
|
544 | + |
|
545 | + |
|
546 | + |
|
547 | + /** |
|
548 | + * end_with_directory_separator |
|
549 | + * ensures that file path ends with '/' |
|
550 | + * @param string $file_path |
|
551 | + * @return string |
|
552 | + */ |
|
553 | + public static function end_with_directory_separator($file_path) |
|
554 | + { |
|
555 | + return rtrim($file_path, '/\\') . '/'; |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + |
|
560 | + /** |
|
561 | + * shorthand for both EEH_FIle::end_with_directory_separator AND EEH_File::standardise_directory_separators |
|
562 | + * @param $file_path |
|
563 | + * @return string |
|
564 | + */ |
|
565 | + public static function standardise_and_end_with_directory_separator($file_path) |
|
566 | + { |
|
567 | + return self::end_with_directory_separator(self::standardise_directory_separators($file_path)); |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + |
|
572 | + /** |
|
573 | + * takes the folder name (with or without trailing slash) and finds the files it in, |
|
574 | + * and what the class's name inside of each should be. |
|
575 | + * @param array $folder_paths |
|
576 | + * @param boolean $index_numerically if TRUE, the returned array will be indexed numerically; |
|
577 | + * if FALSE (Default), returned array will be indexed by the filenames minus extensions. |
|
578 | + * Set it TRUE if you know there are files in the directory with the same name but different extensions |
|
579 | + * @throws EE_Error if filesystem credentials are required |
|
580 | + * @return array if $index_numerically == TRUE keys are numeric , |
|
581 | + * if $index_numerically == FALSE (Default) keys are what the class names SHOULD be; |
|
582 | + * and values are their filepaths |
|
583 | + */ |
|
584 | + public static function get_contents_of_folders($folder_paths = array(), $index_numerically = false) |
|
585 | + { |
|
586 | + $class_to_folder_path = array(); |
|
587 | + foreach ($folder_paths as $folder_path) { |
|
588 | + $folder_path = self::standardise_and_end_with_directory_separator($folder_path); |
|
589 | + // load WP_Filesystem and set file permissions |
|
590 | + $files_in_folder = glob($folder_path . '*'); |
|
591 | + $class_to_folder_path = array(); |
|
592 | + if ($files_in_folder) { |
|
593 | + foreach ($files_in_folder as $file_path) { |
|
594 | + // only add files, not folders |
|
595 | + if (! is_dir($file_path)) { |
|
596 | + if ($index_numerically) { |
|
597 | + $class_to_folder_path[] = $file_path; |
|
598 | + } else { |
|
599 | + $classname = self::get_classname_from_filepath_with_standard_filename($file_path); |
|
600 | + $class_to_folder_path[ $classname ] = $file_path; |
|
601 | + } |
|
602 | + } |
|
603 | + } |
|
604 | + } |
|
605 | + } |
|
606 | + return $class_to_folder_path; |
|
607 | + } |
|
608 | + |
|
609 | + |
|
610 | + |
|
611 | + /** |
|
612 | + * Copies a file. Mostly a wrapper of WP_Filesystem::copy |
|
613 | + * @param string $source_file |
|
614 | + * @param string $destination_file |
|
615 | + * @param boolean $overwrite |
|
616 | + * @throws EE_Error if filesystem credentials are required |
|
617 | + * @return boolean success |
|
618 | + */ |
|
619 | + public static function copy($source_file, $destination_file, $overwrite = false) |
|
620 | + { |
|
621 | + $full_source_path = EEH_File::standardise_directory_separators($source_file); |
|
622 | + if (! EEH_File::exists($full_source_path)) { |
|
623 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
624 | + $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path); |
|
625 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path); |
|
626 | + throw new EE_Error($msg); |
|
627 | + } |
|
628 | + return false; |
|
629 | + } |
|
630 | + |
|
631 | + $full_dest_path = EEH_File::standardise_directory_separators($destination_file); |
|
632 | + $folder = EEH_File::remove_filename_from_filepath($full_dest_path); |
|
633 | + EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
634 | + if (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
635 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
636 | + $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path); |
|
637 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path); |
|
638 | + throw new EE_Error($msg); |
|
639 | + } |
|
640 | + return false; |
|
641 | + } |
|
642 | + |
|
643 | + // load WP_Filesystem and set file permissions |
|
644 | + $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file); |
|
645 | + // write the file |
|
646 | + if (! $wp_filesystem->copy( |
|
647 | + EEH_File::convert_local_filepath_to_remote_filepath($full_source_path), |
|
648 | + EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path), |
|
649 | + $overwrite |
|
650 | + )) { |
|
651 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
652 | + $msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path); |
|
653 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f'); |
|
654 | + throw new EE_Error($msg); |
|
655 | + } |
|
656 | + return false; |
|
657 | + } |
|
658 | + return true; |
|
659 | + } |
|
660 | + |
|
661 | + /** |
|
662 | + * Reports whether or not the filepath is in the EE uploads folder or not |
|
663 | + * @param string $filepath |
|
664 | + * @return boolean |
|
665 | + */ |
|
666 | + public static function is_in_uploads_folder($filepath) |
|
667 | + { |
|
668 | + $uploads = wp_upload_dir(); |
|
669 | + return strpos($filepath, $uploads['basedir']) === 0 ? true : false; |
|
670 | + } |
|
671 | + |
|
672 | + /** |
|
673 | + * Given a "local" filepath (what you probably thought was the only filepath), |
|
674 | + * converts it into a "remote" filepath (the filepath the currently-in-use |
|
675 | + * $wp_filesystem needs to use access the folder or file). |
|
676 | + * See http://wordpress.stackexchange.com/questions/124900/using-wp-filesystem-in-plugins |
|
677 | + * @param WP_Filesystem_Base $wp_filesystem we aren't initially sure which one |
|
678 | + * is in use, so you need to provide it |
|
679 | + * @param string $local_filepath the filepath to the folder/file locally |
|
680 | + * @throws EE_Error if filesystem credentials are required |
|
681 | + * @return string the remote filepath (eg the filepath the filesystem method, eg |
|
682 | + * ftp or ssh, will use to access the folder |
|
683 | + */ |
|
684 | + public static function convert_local_filepath_to_remote_filepath($local_filepath) |
|
685 | + { |
|
686 | + $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath); |
|
687 | + return str_replace(WP_CONTENT_DIR . '/', $wp_filesystem->wp_content_dir(), $local_filepath); |
|
688 | + } |
|
689 | 689 | } |
@@ -44,17 +44,17 @@ discard block |
||
44 | 44 | 'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct', |
45 | 45 | $filepath && EEH_File::is_in_uploads_folder($filepath), |
46 | 46 | $filepath |
47 | - ) ) { |
|
48 | - if (! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) { |
|
49 | - require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); |
|
47 | + )) { |
|
48 | + if ( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) { |
|
49 | + require_once(ABSPATH.'wp-admin/includes/class-wp-filesystem-base.php'); |
|
50 | 50 | $method = 'direct'; |
51 | - $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method); |
|
51 | + $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH.'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method); |
|
52 | 52 | // check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem() |
53 | - if (! defined('FS_CHMOD_DIR')) { |
|
54 | - define('FS_CHMOD_DIR', ( fileperms(ABSPATH) & 0777 | 0755 )); |
|
53 | + if ( ! defined('FS_CHMOD_DIR')) { |
|
54 | + define('FS_CHMOD_DIR', (fileperms(ABSPATH) & 0777 | 0755)); |
|
55 | 55 | } |
56 | - if (! defined('FS_CHMOD_FILE')) { |
|
57 | - define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644 )); |
|
56 | + if ( ! defined('FS_CHMOD_FILE')) { |
|
57 | + define('FS_CHMOD_FILE', (fileperms(ABSPATH.'index.php') & 0777 | 0644)); |
|
58 | 58 | } |
59 | 59 | require_once($wp_filesystem_direct_file); |
60 | 60 | EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array()); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | } |
64 | 64 | global $wp_filesystem; |
65 | 65 | // no filesystem setup ??? |
66 | - if (! $wp_filesystem instanceof WP_Filesystem_Base) { |
|
66 | + if ( ! $wp_filesystem instanceof WP_Filesystem_Base) { |
|
67 | 67 | // if some eager beaver's just trying to get in there too early... |
68 | 68 | // let them do it, because we are one of those eager beavers! :P |
69 | 69 | /** |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | if (false && ! did_action('wp_loaded')) { |
80 | 80 | $msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'); |
81 | 81 | if (WP_DEBUG) { |
82 | - $msg .= '<br />' . __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
82 | + $msg .= '<br />'.__('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
83 | 83 | } |
84 | 84 | throw new EE_Error($msg); |
85 | 85 | } else { |
86 | 86 | // should be loaded if we are past the wp_loaded hook... |
87 | - if (! function_exists('WP_Filesystem')) { |
|
88 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
89 | - require_once(ABSPATH . 'wp-admin/includes/template.php'); |
|
87 | + if ( ! function_exists('WP_Filesystem')) { |
|
88 | + require_once(ABSPATH.'wp-admin/includes/file.php'); |
|
89 | + require_once(ABSPATH.'wp-admin/includes/template.php'); |
|
90 | 90 | } |
91 | 91 | // turn on output buffering so that we can capture the credentials form |
92 | 92 | ob_start(); |
@@ -94,13 +94,13 @@ discard block |
||
94 | 94 | // store credentials form for the time being |
95 | 95 | EEH_File::$_credentials_form = ob_get_clean(); |
96 | 96 | // basically check for direct or previously configured access |
97 | - if (! WP_Filesystem($credentials)) { |
|
97 | + if ( ! WP_Filesystem($credentials)) { |
|
98 | 98 | // if credentials do NOT exist |
99 | 99 | if ($credentials === false) { |
100 | - add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999); |
|
100 | + add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999); |
|
101 | 101 | throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso')); |
102 | 102 | } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { |
103 | - add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999); |
|
103 | + add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999); |
|
104 | 104 | throw new EE_Error( |
105 | 105 | sprintf( |
106 | 106 | __('WP Filesystem Error: $1%s', 'event_espresso'), |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public static function display_request_filesystem_credentials_form() |
121 | 121 | { |
122 | - if (! empty(EEH_File::$_credentials_form)) { |
|
123 | - echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>'; |
|
122 | + if ( ! empty(EEH_File::$_credentials_form)) { |
|
123 | + echo '<div class="updated espresso-notices-attention"><p>'.EEH_File::$_credentials_form.'</p></div>'; |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
@@ -143,8 +143,8 @@ discard block |
||
143 | 143 | // load WP_Filesystem and set file permissions |
144 | 144 | $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
145 | 145 | $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
146 | - if (! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
147 | - $file_name = ! empty($type_of_file) ? $file_name . ' ' . $type_of_file : $file_name; |
|
146 | + if ( ! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
147 | + $file_name = ! empty($type_of_file) ? $file_name.' '.$type_of_file : $file_name; |
|
148 | 148 | $file_name .= ! empty($file_ext) ? ' file' : ' folder'; |
149 | 149 | $msg = sprintf( |
150 | 150 | __('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'), |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | ); |
162 | 162 | } |
163 | 163 | if (defined('WP_DEBUG') && WP_DEBUG) { |
164 | - throw new EE_Error($msg . '||' . $msg); |
|
164 | + throw new EE_Error($msg.'||'.$msg); |
|
165 | 165 | } |
166 | 166 | return false; |
167 | 167 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
188 | 188 | if ($perms) { |
189 | 189 | // file permissions exist, but way be set incorrectly |
190 | - $type_of_file = ! empty($type_of_file) ? $type_of_file . ' ' : ''; |
|
190 | + $type_of_file = ! empty($type_of_file) ? $type_of_file.' ' : ''; |
|
191 | 191 | $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder'; |
192 | 192 | return sprintf( |
193 | 193 | __('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'), |
@@ -226,15 +226,15 @@ discard block |
||
226 | 226 | // add / to folder |
227 | 227 | $folder = EEH_File::end_with_directory_separator($folder); |
228 | 228 | $wp_filesystem = EEH_File::_get_wp_filesystem($folder); |
229 | - if (! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
229 | + if ( ! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
230 | 230 | // ok so it doesn't exist. Does its parent? Can we write to it? |
231 | - if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
231 | + if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
232 | 232 | return false; |
233 | 233 | } |
234 | - if (! EEH_File::verify_is_writable($parent_folder, 'folder')) { |
|
234 | + if ( ! EEH_File::verify_is_writable($parent_folder, 'folder')) { |
|
235 | 235 | return false; |
236 | 236 | } else { |
237 | - if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
237 | + if ( ! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
238 | 238 | if (defined('WP_DEBUG') && WP_DEBUG) { |
239 | 239 | $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder); |
240 | 240 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder); |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | } |
245 | 245 | EEH_File::add_index_file($folder); |
246 | 246 | } |
247 | - } elseif (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
247 | + } elseif ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
248 | 248 | return false; |
249 | 249 | } |
250 | 250 | return true; |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | // load WP_Filesystem and set file permissions |
265 | 265 | $wp_filesystem = EEH_File::_get_wp_filesystem($full_path); |
266 | 266 | $full_path = EEH_File::standardise_directory_separators($full_path); |
267 | - if (! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) { |
|
267 | + if ( ! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) { |
|
268 | 268 | if (defined('WP_DEBUG') && WP_DEBUG) { |
269 | 269 | $msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder); |
270 | 270 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path); |
@@ -291,11 +291,11 @@ discard block |
||
291 | 291 | $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
292 | 292 | $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
293 | 293 | $parent_folder = EEH_File::get_parent_folder($full_file_path); |
294 | - if (! EEH_File::exists($full_file_path)) { |
|
295 | - if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
294 | + if ( ! EEH_File::exists($full_file_path)) { |
|
295 | + if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
296 | 296 | return false; |
297 | 297 | } |
298 | - if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
298 | + if ( ! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
299 | 299 | if (defined('WP_DEBUG') && WP_DEBUG) { |
300 | 300 | $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path); |
301 | 301 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | return false; |
305 | 305 | } |
306 | 306 | } |
307 | - if (! EEH_File::verify_is_writable($full_file_path, 'file')) { |
|
307 | + if ( ! EEH_File::verify_is_writable($full_file_path, 'file')) { |
|
308 | 308 | return false; |
309 | 309 | } |
310 | 310 | return true; |
@@ -363,9 +363,9 @@ discard block |
||
363 | 363 | public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') |
364 | 364 | { |
365 | 365 | $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
366 | - $file_type = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : ''; |
|
366 | + $file_type = ! empty($file_type) ? rtrim($file_type, ' ').' ' : ''; |
|
367 | 367 | $folder = EEH_File::remove_filename_from_filepath($full_file_path); |
368 | - if (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
368 | + if ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
369 | 369 | if (defined('WP_DEBUG') && WP_DEBUG) { |
370 | 370 | $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path); |
371 | 371 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | // load WP_Filesystem and set file permissions |
377 | 377 | $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
378 | 378 | // write the file |
379 | - if (! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) { |
|
379 | + if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) { |
|
380 | 380 | if (defined('WP_DEBUG') && WP_DEBUG) { |
381 | 381 | $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path); |
382 | 382 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f'); |
@@ -486,8 +486,8 @@ discard block |
||
486 | 486 | public static function add_htaccess_deny_from_all($folder = '') |
487 | 487 | { |
488 | 488 | $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
489 | - if (! EEH_File::exists($folder . '.htaccess')) { |
|
490 | - if (! EEH_File::write_to_file($folder . '.htaccess', 'deny from all', '.htaccess')) { |
|
489 | + if ( ! EEH_File::exists($folder.'.htaccess')) { |
|
490 | + if ( ! EEH_File::write_to_file($folder.'.htaccess', 'deny from all', '.htaccess')) { |
|
491 | 491 | return false; |
492 | 492 | } |
493 | 493 | } |
@@ -504,8 +504,8 @@ discard block |
||
504 | 504 | public static function add_index_file($folder) |
505 | 505 | { |
506 | 506 | $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
507 | - if (! EEH_File::exists($folder . 'index.php')) { |
|
508 | - if (! EEH_File::write_to_file($folder . 'index.php', 'You are not permitted to read from this folder', '.php')) { |
|
507 | + if ( ! EEH_File::exists($folder.'index.php')) { |
|
508 | + if ( ! EEH_File::write_to_file($folder.'index.php', 'You are not permitted to read from this folder', '.php')) { |
|
509 | 509 | return false; |
510 | 510 | } |
511 | 511 | } |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | */ |
540 | 540 | public static function standardise_directory_separators($file_path) |
541 | 541 | { |
542 | - return str_replace(array( '\\', '/' ), '/', $file_path); |
|
542 | + return str_replace(array('\\', '/'), '/', $file_path); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | */ |
553 | 553 | public static function end_with_directory_separator($file_path) |
554 | 554 | { |
555 | - return rtrim($file_path, '/\\') . '/'; |
|
555 | + return rtrim($file_path, '/\\').'/'; |
|
556 | 556 | } |
557 | 557 | |
558 | 558 | |
@@ -587,17 +587,17 @@ discard block |
||
587 | 587 | foreach ($folder_paths as $folder_path) { |
588 | 588 | $folder_path = self::standardise_and_end_with_directory_separator($folder_path); |
589 | 589 | // load WP_Filesystem and set file permissions |
590 | - $files_in_folder = glob($folder_path . '*'); |
|
590 | + $files_in_folder = glob($folder_path.'*'); |
|
591 | 591 | $class_to_folder_path = array(); |
592 | 592 | if ($files_in_folder) { |
593 | 593 | foreach ($files_in_folder as $file_path) { |
594 | 594 | // only add files, not folders |
595 | - if (! is_dir($file_path)) { |
|
595 | + if ( ! is_dir($file_path)) { |
|
596 | 596 | if ($index_numerically) { |
597 | 597 | $class_to_folder_path[] = $file_path; |
598 | 598 | } else { |
599 | 599 | $classname = self::get_classname_from_filepath_with_standard_filename($file_path); |
600 | - $class_to_folder_path[ $classname ] = $file_path; |
|
600 | + $class_to_folder_path[$classname] = $file_path; |
|
601 | 601 | } |
602 | 602 | } |
603 | 603 | } |
@@ -619,7 +619,7 @@ discard block |
||
619 | 619 | public static function copy($source_file, $destination_file, $overwrite = false) |
620 | 620 | { |
621 | 621 | $full_source_path = EEH_File::standardise_directory_separators($source_file); |
622 | - if (! EEH_File::exists($full_source_path)) { |
|
622 | + if ( ! EEH_File::exists($full_source_path)) { |
|
623 | 623 | if (defined('WP_DEBUG') && WP_DEBUG) { |
624 | 624 | $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path); |
625 | 625 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path); |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | $full_dest_path = EEH_File::standardise_directory_separators($destination_file); |
632 | 632 | $folder = EEH_File::remove_filename_from_filepath($full_dest_path); |
633 | 633 | EEH_File::ensure_folder_exists_and_is_writable($folder); |
634 | - if (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
634 | + if ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
635 | 635 | if (defined('WP_DEBUG') && WP_DEBUG) { |
636 | 636 | $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path); |
637 | 637 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path); |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | // load WP_Filesystem and set file permissions |
644 | 644 | $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file); |
645 | 645 | // write the file |
646 | - if (! $wp_filesystem->copy( |
|
646 | + if ( ! $wp_filesystem->copy( |
|
647 | 647 | EEH_File::convert_local_filepath_to_remote_filepath($full_source_path), |
648 | 648 | EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path), |
649 | 649 | $overwrite |
@@ -684,6 +684,6 @@ discard block |
||
684 | 684 | public static function convert_local_filepath_to_remote_filepath($local_filepath) |
685 | 685 | { |
686 | 686 | $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath); |
687 | - return str_replace(WP_CONTENT_DIR . '/', $wp_filesystem->wp_content_dir(), $local_filepath); |
|
687 | + return str_replace(WP_CONTENT_DIR.'/', $wp_filesystem->wp_content_dir(), $local_filepath); |
|
688 | 688 | } |
689 | 689 | } |
@@ -15,296 +15,296 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * instance of the EE_System object |
|
20 | - * |
|
21 | - * @var $_instance |
|
22 | - * @access private |
|
23 | - */ |
|
24 | - private static $_instance = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * $_autoloaders |
|
28 | - * @var array $_autoloaders |
|
29 | - * @access private |
|
30 | - */ |
|
31 | - private static $_autoloaders; |
|
32 | - |
|
33 | - /** |
|
34 | - * set to "paths" to display autoloader class => path mappings |
|
35 | - * set to "times" to display autoloader loading times |
|
36 | - * set to "all" to display both |
|
37 | - * |
|
38 | - * @var string $debug |
|
39 | - * @access private |
|
40 | - */ |
|
41 | - public static $debug = false; |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * class constructor |
|
46 | - * |
|
47 | - * @access private |
|
48 | - * @return \EEH_Autoloader |
|
49 | - * @throws Exception |
|
50 | - */ |
|
51 | - private function __construct() |
|
52 | - { |
|
53 | - if (self::$_autoloaders === null) { |
|
54 | - self::$_autoloaders = array(); |
|
55 | - $this->_register_custom_autoloaders(); |
|
56 | - spl_autoload_register(array( $this, 'espresso_autoloader' )); |
|
57 | - } |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @access public |
|
64 | - * @return EEH_Autoloader |
|
65 | - */ |
|
66 | - public static function instance() |
|
67 | - { |
|
68 | - // check if class object is instantiated |
|
69 | - if (! self::$_instance instanceof EEH_Autoloader) { |
|
70 | - self::$_instance = new self(); |
|
71 | - } |
|
72 | - return self::$_instance; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * espresso_autoloader |
|
79 | - * |
|
80 | - * @access public |
|
81 | - * @param $class_name |
|
82 | - * @internal param $className |
|
83 | - * @internal param string $class_name - simple class name ie: session |
|
84 | - * @return void |
|
85 | - */ |
|
86 | - public static function espresso_autoloader($class_name) |
|
87 | - { |
|
88 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
89 | - require_once(self::$_autoloaders[ $class_name ]); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * register_autoloader |
|
97 | - * |
|
98 | - * @access public |
|
99 | - * @param array | string $class_paths - array of key => value pairings between class names and paths |
|
100 | - * @param bool $read_check true if we need to check whether the file is readable or not. |
|
101 | - * @param bool $debug **deprecated** |
|
102 | - * @throws \EE_Error |
|
103 | - */ |
|
104 | - public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
|
105 | - { |
|
106 | - $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths ); |
|
107 | - foreach ($class_paths as $class => $path) { |
|
108 | - // skip all files that are not PHP |
|
109 | - if (substr($path, strlen($path) - 3) !== 'php') { |
|
110 | - continue; |
|
111 | - } |
|
112 | - // don't give up! you gotta... |
|
113 | - // get some class |
|
114 | - if (empty($class)) { |
|
115 | - throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path)); |
|
116 | - } |
|
117 | - // one day you will find the path young grasshopper |
|
118 | - if (empty($path)) { |
|
119 | - throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class)); |
|
120 | - } |
|
121 | - // is file readable ? |
|
122 | - if ($read_check && ! is_readable($path)) { |
|
123 | - throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); |
|
124 | - } |
|
125 | - if (! isset(self::$_autoloaders[ $class ])) { |
|
126 | - self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path); |
|
127 | - if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) { |
|
128 | - EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * get_autoloaders |
|
139 | - * |
|
140 | - * @access public |
|
141 | - * @return array |
|
142 | - */ |
|
143 | - public static function get_autoloaders() |
|
144 | - { |
|
145 | - return self::$_autoloaders; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * register core, model and class 'autoloaders' |
|
151 | - * |
|
152 | - * @access private |
|
153 | - * @return void |
|
154 | - * @throws EE_Error |
|
155 | - */ |
|
156 | - private function _register_custom_autoloaders() |
|
157 | - { |
|
158 | - EEH_Autoloader::$debug = ''; |
|
159 | - \EEH_Autoloader::register_helpers_autoloaders(); |
|
160 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
161 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
|
162 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
|
163 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
|
164 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
|
165 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
|
166 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
167 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
168 | - EEH_Debug_Tools::instance()->show_times(); |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * register core, model and class 'autoloaders' |
|
176 | - * |
|
177 | - * @access public |
|
178 | - */ |
|
179 | - public static function register_helpers_autoloaders() |
|
180 | - { |
|
181 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * register core, model and class 'autoloaders' |
|
189 | - * |
|
190 | - * @access public |
|
191 | - * @return void |
|
192 | - */ |
|
193 | - public static function register_form_sections_autoloaders() |
|
194 | - { |
|
195 | - // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true ); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * register core, model and class 'autoloaders' |
|
201 | - * |
|
202 | - * @access public |
|
203 | - * @return void |
|
204 | - * @throws EE_Error |
|
205 | - */ |
|
206 | - public static function register_line_item_display_autoloaders() |
|
207 | - { |
|
208 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * register core, model and class 'autoloaders' |
|
214 | - * |
|
215 | - * @access public |
|
216 | - * @return void |
|
217 | - * @throws EE_Error |
|
218 | - */ |
|
219 | - public static function register_line_item_filter_autoloaders() |
|
220 | - { |
|
221 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * register template part 'autoloaders' |
|
227 | - * |
|
228 | - * @access public |
|
229 | - * @return void |
|
230 | - * @throws EE_Error |
|
231 | - */ |
|
232 | - public static function register_template_part_autoloaders() |
|
233 | - { |
|
234 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @return void |
|
240 | - * @throws EE_Error |
|
241 | - */ |
|
242 | - public static function register_business_classes() |
|
243 | - { |
|
244 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business'); |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * Assumes all the files in this folder have the normal naming scheme (namely that their classname |
|
251 | - * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list. |
|
252 | - * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly. |
|
253 | - * Yes this has to scan the directory for files, but it only does it once -- not on EACH |
|
254 | - * time the autoloader is used |
|
255 | - * |
|
256 | - * @param string $folder name, with or without trailing /, doesn't matter |
|
257 | - * @param bool $recursive |
|
258 | - * @param bool $debug **deprecated** |
|
259 | - * @throws \EE_Error |
|
260 | - */ |
|
261 | - public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false) |
|
262 | - { |
|
263 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) { |
|
264 | - EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
|
265 | - } |
|
266 | - // make sure last char is a / |
|
267 | - $folder .= $folder[ strlen($folder)-1 ] !== '/' ? '/' : ''; |
|
268 | - $class_to_filepath_map = array(); |
|
269 | - $exclude = array( 'index' ); |
|
270 | - // get all the files in that folder that end in php |
|
271 | - $filepaths = glob($folder.'*'); |
|
272 | - |
|
273 | - if (empty($filepaths)) { |
|
274 | - return; |
|
275 | - } |
|
276 | - |
|
277 | - foreach ($filepaths as $filepath) { |
|
278 | - if (substr($filepath, -4, 4) === '.php') { |
|
279 | - $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
|
280 | - if (! in_array($class_name, $exclude)) { |
|
281 | - $class_to_filepath_map [ $class_name ] = $filepath; |
|
282 | - } |
|
283 | - } elseif ($recursive) { |
|
284 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
|
285 | - } |
|
286 | - } |
|
287 | - // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories. |
|
288 | - self::register_autoloader($class_to_filepath_map, false, $debug); |
|
289 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
290 | - EEH_Debug_Tools::instance()->stop_timer(basename($folder)); |
|
291 | - } |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * add_alias |
|
298 | - * register additional autoloader based on variation of the classname for an existing autoloader |
|
299 | - * |
|
300 | - * @access public |
|
301 | - * @param string $class_name - simple class name ie: EE_Session |
|
302 | - * @param string $alias - variation on class name ie: EE_session, session, etc |
|
303 | - */ |
|
304 | - public static function add_alias($class_name, $alias) |
|
305 | - { |
|
306 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
307 | - self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
308 | - } |
|
309 | - } |
|
18 | + /** |
|
19 | + * instance of the EE_System object |
|
20 | + * |
|
21 | + * @var $_instance |
|
22 | + * @access private |
|
23 | + */ |
|
24 | + private static $_instance = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * $_autoloaders |
|
28 | + * @var array $_autoloaders |
|
29 | + * @access private |
|
30 | + */ |
|
31 | + private static $_autoloaders; |
|
32 | + |
|
33 | + /** |
|
34 | + * set to "paths" to display autoloader class => path mappings |
|
35 | + * set to "times" to display autoloader loading times |
|
36 | + * set to "all" to display both |
|
37 | + * |
|
38 | + * @var string $debug |
|
39 | + * @access private |
|
40 | + */ |
|
41 | + public static $debug = false; |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * class constructor |
|
46 | + * |
|
47 | + * @access private |
|
48 | + * @return \EEH_Autoloader |
|
49 | + * @throws Exception |
|
50 | + */ |
|
51 | + private function __construct() |
|
52 | + { |
|
53 | + if (self::$_autoloaders === null) { |
|
54 | + self::$_autoloaders = array(); |
|
55 | + $this->_register_custom_autoloaders(); |
|
56 | + spl_autoload_register(array( $this, 'espresso_autoloader' )); |
|
57 | + } |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @access public |
|
64 | + * @return EEH_Autoloader |
|
65 | + */ |
|
66 | + public static function instance() |
|
67 | + { |
|
68 | + // check if class object is instantiated |
|
69 | + if (! self::$_instance instanceof EEH_Autoloader) { |
|
70 | + self::$_instance = new self(); |
|
71 | + } |
|
72 | + return self::$_instance; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * espresso_autoloader |
|
79 | + * |
|
80 | + * @access public |
|
81 | + * @param $class_name |
|
82 | + * @internal param $className |
|
83 | + * @internal param string $class_name - simple class name ie: session |
|
84 | + * @return void |
|
85 | + */ |
|
86 | + public static function espresso_autoloader($class_name) |
|
87 | + { |
|
88 | + if (isset(self::$_autoloaders[ $class_name ])) { |
|
89 | + require_once(self::$_autoloaders[ $class_name ]); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * register_autoloader |
|
97 | + * |
|
98 | + * @access public |
|
99 | + * @param array | string $class_paths - array of key => value pairings between class names and paths |
|
100 | + * @param bool $read_check true if we need to check whether the file is readable or not. |
|
101 | + * @param bool $debug **deprecated** |
|
102 | + * @throws \EE_Error |
|
103 | + */ |
|
104 | + public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
|
105 | + { |
|
106 | + $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths ); |
|
107 | + foreach ($class_paths as $class => $path) { |
|
108 | + // skip all files that are not PHP |
|
109 | + if (substr($path, strlen($path) - 3) !== 'php') { |
|
110 | + continue; |
|
111 | + } |
|
112 | + // don't give up! you gotta... |
|
113 | + // get some class |
|
114 | + if (empty($class)) { |
|
115 | + throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path)); |
|
116 | + } |
|
117 | + // one day you will find the path young grasshopper |
|
118 | + if (empty($path)) { |
|
119 | + throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class)); |
|
120 | + } |
|
121 | + // is file readable ? |
|
122 | + if ($read_check && ! is_readable($path)) { |
|
123 | + throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); |
|
124 | + } |
|
125 | + if (! isset(self::$_autoloaders[ $class ])) { |
|
126 | + self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path); |
|
127 | + if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) { |
|
128 | + EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * get_autoloaders |
|
139 | + * |
|
140 | + * @access public |
|
141 | + * @return array |
|
142 | + */ |
|
143 | + public static function get_autoloaders() |
|
144 | + { |
|
145 | + return self::$_autoloaders; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * register core, model and class 'autoloaders' |
|
151 | + * |
|
152 | + * @access private |
|
153 | + * @return void |
|
154 | + * @throws EE_Error |
|
155 | + */ |
|
156 | + private function _register_custom_autoloaders() |
|
157 | + { |
|
158 | + EEH_Autoloader::$debug = ''; |
|
159 | + \EEH_Autoloader::register_helpers_autoloaders(); |
|
160 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
161 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
|
162 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
|
163 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
|
164 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
|
165 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
|
166 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
167 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
168 | + EEH_Debug_Tools::instance()->show_times(); |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * register core, model and class 'autoloaders' |
|
176 | + * |
|
177 | + * @access public |
|
178 | + */ |
|
179 | + public static function register_helpers_autoloaders() |
|
180 | + { |
|
181 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * register core, model and class 'autoloaders' |
|
189 | + * |
|
190 | + * @access public |
|
191 | + * @return void |
|
192 | + */ |
|
193 | + public static function register_form_sections_autoloaders() |
|
194 | + { |
|
195 | + // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true ); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * register core, model and class 'autoloaders' |
|
201 | + * |
|
202 | + * @access public |
|
203 | + * @return void |
|
204 | + * @throws EE_Error |
|
205 | + */ |
|
206 | + public static function register_line_item_display_autoloaders() |
|
207 | + { |
|
208 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * register core, model and class 'autoloaders' |
|
214 | + * |
|
215 | + * @access public |
|
216 | + * @return void |
|
217 | + * @throws EE_Error |
|
218 | + */ |
|
219 | + public static function register_line_item_filter_autoloaders() |
|
220 | + { |
|
221 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * register template part 'autoloaders' |
|
227 | + * |
|
228 | + * @access public |
|
229 | + * @return void |
|
230 | + * @throws EE_Error |
|
231 | + */ |
|
232 | + public static function register_template_part_autoloaders() |
|
233 | + { |
|
234 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @return void |
|
240 | + * @throws EE_Error |
|
241 | + */ |
|
242 | + public static function register_business_classes() |
|
243 | + { |
|
244 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business'); |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * Assumes all the files in this folder have the normal naming scheme (namely that their classname |
|
251 | + * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list. |
|
252 | + * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly. |
|
253 | + * Yes this has to scan the directory for files, but it only does it once -- not on EACH |
|
254 | + * time the autoloader is used |
|
255 | + * |
|
256 | + * @param string $folder name, with or without trailing /, doesn't matter |
|
257 | + * @param bool $recursive |
|
258 | + * @param bool $debug **deprecated** |
|
259 | + * @throws \EE_Error |
|
260 | + */ |
|
261 | + public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false) |
|
262 | + { |
|
263 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) { |
|
264 | + EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
|
265 | + } |
|
266 | + // make sure last char is a / |
|
267 | + $folder .= $folder[ strlen($folder)-1 ] !== '/' ? '/' : ''; |
|
268 | + $class_to_filepath_map = array(); |
|
269 | + $exclude = array( 'index' ); |
|
270 | + // get all the files in that folder that end in php |
|
271 | + $filepaths = glob($folder.'*'); |
|
272 | + |
|
273 | + if (empty($filepaths)) { |
|
274 | + return; |
|
275 | + } |
|
276 | + |
|
277 | + foreach ($filepaths as $filepath) { |
|
278 | + if (substr($filepath, -4, 4) === '.php') { |
|
279 | + $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
|
280 | + if (! in_array($class_name, $exclude)) { |
|
281 | + $class_to_filepath_map [ $class_name ] = $filepath; |
|
282 | + } |
|
283 | + } elseif ($recursive) { |
|
284 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
|
285 | + } |
|
286 | + } |
|
287 | + // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories. |
|
288 | + self::register_autoloader($class_to_filepath_map, false, $debug); |
|
289 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
290 | + EEH_Debug_Tools::instance()->stop_timer(basename($folder)); |
|
291 | + } |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * add_alias |
|
298 | + * register additional autoloader based on variation of the classname for an existing autoloader |
|
299 | + * |
|
300 | + * @access public |
|
301 | + * @param string $class_name - simple class name ie: EE_Session |
|
302 | + * @param string $alias - variation on class name ie: EE_session, session, etc |
|
303 | + */ |
|
304 | + public static function add_alias($class_name, $alias) |
|
305 | + { |
|
306 | + if (isset(self::$_autoloaders[ $class_name ])) { |
|
307 | + self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
308 | + } |
|
309 | + } |
|
310 | 310 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | if (self::$_autoloaders === null) { |
54 | 54 | self::$_autoloaders = array(); |
55 | 55 | $this->_register_custom_autoloaders(); |
56 | - spl_autoload_register(array( $this, 'espresso_autoloader' )); |
|
56 | + spl_autoload_register(array($this, 'espresso_autoloader')); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public static function instance() |
67 | 67 | { |
68 | 68 | // check if class object is instantiated |
69 | - if (! self::$_instance instanceof EEH_Autoloader) { |
|
69 | + if ( ! self::$_instance instanceof EEH_Autoloader) { |
|
70 | 70 | self::$_instance = new self(); |
71 | 71 | } |
72 | 72 | return self::$_instance; |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public static function espresso_autoloader($class_name) |
87 | 87 | { |
88 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
89 | - require_once(self::$_autoloaders[ $class_name ]); |
|
88 | + if (isset(self::$_autoloaders[$class_name])) { |
|
89 | + require_once(self::$_autoloaders[$class_name]); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
105 | 105 | { |
106 | - $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths ); |
|
106 | + $class_paths = is_array($class_paths) ? $class_paths : array($class_paths); |
|
107 | 107 | foreach ($class_paths as $class => $path) { |
108 | 108 | // skip all files that are not PHP |
109 | 109 | if (substr($path, strlen($path) - 3) !== 'php') { |
@@ -122,10 +122,10 @@ discard block |
||
122 | 122 | if ($read_check && ! is_readable($path)) { |
123 | 123 | throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); |
124 | 124 | } |
125 | - if (! isset(self::$_autoloaders[ $class ])) { |
|
126 | - self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path); |
|
127 | - if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) { |
|
128 | - EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
125 | + if ( ! isset(self::$_autoloaders[$class])) { |
|
126 | + self::$_autoloaders[$class] = str_replace(array('/', '\\'), '/', $path); |
|
127 | + if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) { |
|
128 | + EEH_Debug_Tools::printr(self::$_autoloaders[$class], $class, __FILE__, __LINE__); |
|
129 | 129 | } |
130 | 130 | } |
131 | 131 | } |
@@ -157,13 +157,13 @@ discard block |
||
157 | 157 | { |
158 | 158 | EEH_Autoloader::$debug = ''; |
159 | 159 | \EEH_Autoloader::register_helpers_autoloaders(); |
160 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
160 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'interfaces'); |
|
161 | 161 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
162 | 162 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
163 | 163 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
164 | 164 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
165 | 165 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
166 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
166 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'messages'); |
|
167 | 167 | if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
168 | 168 | EEH_Debug_Tools::instance()->show_times(); |
169 | 169 | } |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | */ |
206 | 206 | public static function register_line_item_display_autoloaders() |
207 | 207 | { |
208 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
208 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_display', true); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | */ |
219 | 219 | public static function register_line_item_filter_autoloaders() |
220 | 220 | { |
221 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
221 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_filters', true); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | */ |
232 | 232 | public static function register_template_part_autoloaders() |
233 | 233 | { |
234 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
234 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'template_parts', true); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | */ |
242 | 242 | public static function register_business_classes() |
243 | 243 | { |
244 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business'); |
|
244 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'business'); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | |
@@ -264,9 +264,9 @@ discard block |
||
264 | 264 | EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
265 | 265 | } |
266 | 266 | // make sure last char is a / |
267 | - $folder .= $folder[ strlen($folder)-1 ] !== '/' ? '/' : ''; |
|
267 | + $folder .= $folder[strlen($folder) - 1] !== '/' ? '/' : ''; |
|
268 | 268 | $class_to_filepath_map = array(); |
269 | - $exclude = array( 'index' ); |
|
269 | + $exclude = array('index'); |
|
270 | 270 | // get all the files in that folder that end in php |
271 | 271 | $filepaths = glob($folder.'*'); |
272 | 272 | |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | foreach ($filepaths as $filepath) { |
278 | 278 | if (substr($filepath, -4, 4) === '.php') { |
279 | 279 | $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
280 | - if (! in_array($class_name, $exclude)) { |
|
281 | - $class_to_filepath_map [ $class_name ] = $filepath; |
|
280 | + if ( ! in_array($class_name, $exclude)) { |
|
281 | + $class_to_filepath_map [$class_name] = $filepath; |
|
282 | 282 | } |
283 | 283 | } elseif ($recursive) { |
284 | 284 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
@@ -303,8 +303,8 @@ discard block |
||
303 | 303 | */ |
304 | 304 | public static function add_alias($class_name, $alias) |
305 | 305 | { |
306 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
307 | - self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
306 | + if (isset(self::$_autoloaders[$class_name])) { |
|
307 | + self::$_autoloaders[$alias] = self::$_autoloaders[$class_name]; |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 | } |
@@ -15,232 +15,232 @@ discard block |
||
15 | 15 | class EEH_Activation implements ResettableInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * constant used to indicate a cron task is no longer in use |
|
20 | - */ |
|
21 | - const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
22 | - |
|
23 | - /** |
|
24 | - * WP_User->ID |
|
25 | - * |
|
26 | - * @var int |
|
27 | - */ |
|
28 | - private static $_default_creator_id; |
|
29 | - |
|
30 | - /** |
|
31 | - * indicates whether or not we've already verified core's default data during this request, |
|
32 | - * because after migrations are done, any addons activated while in maintenance mode |
|
33 | - * will want to setup their own default data, and they might hook into core's default data |
|
34 | - * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
35 | - * This prevents doing that for EVERY single addon. |
|
36 | - * |
|
37 | - * @var boolean |
|
38 | - */ |
|
39 | - protected static $_initialized_db_content_already_in_this_request = false; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
43 | - */ |
|
44 | - private static $table_analysis; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
48 | - */ |
|
49 | - private static $table_manager; |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @return \EventEspresso\core\services\database\TableAnalysis |
|
54 | - */ |
|
55 | - public static function getTableAnalysis() |
|
56 | - { |
|
57 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
58 | - self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
59 | - } |
|
60 | - return self::$table_analysis; |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * @return \EventEspresso\core\services\database\TableManager |
|
66 | - */ |
|
67 | - public static function getTableManager() |
|
68 | - { |
|
69 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
70 | - self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
71 | - } |
|
72 | - return self::$table_manager; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * _ensure_table_name_has_prefix |
|
78 | - * |
|
79 | - * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
80 | - * @access public |
|
81 | - * @static |
|
82 | - * @param $table_name |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public static function ensure_table_name_has_prefix($table_name) |
|
86 | - { |
|
87 | - return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * system_initialization |
|
93 | - * ensures the EE configuration settings are loaded with at least default options set |
|
94 | - * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
95 | - * |
|
96 | - * @access public |
|
97 | - * @static |
|
98 | - * @return void |
|
99 | - */ |
|
100 | - public static function system_initialization() |
|
101 | - { |
|
102 | - EEH_Activation::reset_and_update_config(); |
|
103 | - // which is fired BEFORE activation of plugin anyways |
|
104 | - EEH_Activation::verify_default_pages_exist(); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Sets the database schema and creates folders. This should |
|
110 | - * be called on plugin activation and reactivation |
|
111 | - * |
|
112 | - * @return boolean success, whether the database and folders are setup properly |
|
113 | - * @throws \EE_Error |
|
114 | - */ |
|
115 | - public static function initialize_db_and_folders() |
|
116 | - { |
|
117 | - return EEH_Activation::create_database_tables(); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * assuming we have an up-to-date database schema, this will populate it |
|
123 | - * with default and initial data. This should be called |
|
124 | - * upon activation of a new plugin, reactivation, and at the end |
|
125 | - * of running migration scripts |
|
126 | - * |
|
127 | - * @throws \EE_Error |
|
128 | - */ |
|
129 | - public static function initialize_db_content() |
|
130 | - { |
|
131 | - // let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
132 | - if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
133 | - return; |
|
134 | - } |
|
135 | - EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
136 | - |
|
137 | - EEH_Activation::initialize_system_questions(); |
|
138 | - EEH_Activation::insert_default_status_codes(); |
|
139 | - EEH_Activation::generate_default_message_templates(); |
|
140 | - EEH_Activation::create_no_ticket_prices_array(); |
|
141 | - |
|
142 | - EEH_Activation::validate_messages_system(); |
|
143 | - EEH_Activation::insert_default_payment_methods(); |
|
144 | - // in case we've |
|
145 | - EEH_Activation::remove_cron_tasks(); |
|
146 | - EEH_Activation::create_cron_tasks(); |
|
147 | - // remove all TXN locks since that is being done via extra meta now |
|
148 | - delete_option('ee_locked_transactions'); |
|
149 | - // also, check for CAF default db content |
|
150 | - do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
151 | - // also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
152 | - // which users really won't care about on initial activation |
|
153 | - EE_Error::overwrite_success(); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
159 | - * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
160 | - * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
161 | - * (null) |
|
162 | - * |
|
163 | - * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
164 | - * 'old' (only returns ones that should no longer be used),or 'all', |
|
165 | - * @return array |
|
166 | - * @throws \EE_Error |
|
167 | - */ |
|
168 | - public static function get_cron_tasks($which_to_include) |
|
169 | - { |
|
170 | - $cron_tasks = apply_filters( |
|
171 | - 'FHEE__EEH_Activation__get_cron_tasks', |
|
172 | - array( |
|
173 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
174 | - // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
|
175 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
176 | - // there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
177 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
178 | - ) |
|
179 | - ); |
|
180 | - if ($which_to_include === 'old') { |
|
181 | - $cron_tasks = array_filter( |
|
182 | - $cron_tasks, |
|
183 | - function ($value) { |
|
184 | - return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
185 | - } |
|
186 | - ); |
|
187 | - } elseif ($which_to_include === 'current') { |
|
188 | - $cron_tasks = array_filter($cron_tasks); |
|
189 | - } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
190 | - throw new EE_Error( |
|
191 | - sprintf( |
|
192 | - __( |
|
193 | - 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
194 | - 'event_espresso' |
|
195 | - ), |
|
196 | - $which_to_include |
|
197 | - ) |
|
198 | - ); |
|
199 | - } |
|
200 | - return $cron_tasks; |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
206 | - * |
|
207 | - * @throws \EE_Error |
|
208 | - */ |
|
209 | - public static function create_cron_tasks() |
|
210 | - { |
|
211 | - |
|
212 | - foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
213 | - if (! wp_next_scheduled($hook_name)) { |
|
214 | - /** |
|
215 | - * This allows client code to define the initial start timestamp for this schedule. |
|
216 | - */ |
|
217 | - if (is_array($frequency) |
|
218 | - && count($frequency) === 2 |
|
219 | - && isset($frequency[0], $frequency[1]) |
|
220 | - ) { |
|
221 | - $start_timestamp = $frequency[0]; |
|
222 | - $frequency = $frequency[1]; |
|
223 | - } else { |
|
224 | - $start_timestamp = time(); |
|
225 | - } |
|
226 | - wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
227 | - } |
|
228 | - } |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * Remove the currently-existing and now-removed cron tasks. |
|
234 | - * |
|
235 | - * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
236 | - * @throws \EE_Error |
|
237 | - */ |
|
238 | - public static function remove_cron_tasks($remove_all = true) |
|
239 | - { |
|
240 | - $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
241 | - $crons = _get_cron_array(); |
|
242 | - $crons = is_array($crons) ? $crons : array(); |
|
243 | - /* reminder of what $crons look like: |
|
18 | + /** |
|
19 | + * constant used to indicate a cron task is no longer in use |
|
20 | + */ |
|
21 | + const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
22 | + |
|
23 | + /** |
|
24 | + * WP_User->ID |
|
25 | + * |
|
26 | + * @var int |
|
27 | + */ |
|
28 | + private static $_default_creator_id; |
|
29 | + |
|
30 | + /** |
|
31 | + * indicates whether or not we've already verified core's default data during this request, |
|
32 | + * because after migrations are done, any addons activated while in maintenance mode |
|
33 | + * will want to setup their own default data, and they might hook into core's default data |
|
34 | + * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
35 | + * This prevents doing that for EVERY single addon. |
|
36 | + * |
|
37 | + * @var boolean |
|
38 | + */ |
|
39 | + protected static $_initialized_db_content_already_in_this_request = false; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
43 | + */ |
|
44 | + private static $table_analysis; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
48 | + */ |
|
49 | + private static $table_manager; |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @return \EventEspresso\core\services\database\TableAnalysis |
|
54 | + */ |
|
55 | + public static function getTableAnalysis() |
|
56 | + { |
|
57 | + if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
58 | + self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
59 | + } |
|
60 | + return self::$table_analysis; |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * @return \EventEspresso\core\services\database\TableManager |
|
66 | + */ |
|
67 | + public static function getTableManager() |
|
68 | + { |
|
69 | + if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
70 | + self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
71 | + } |
|
72 | + return self::$table_manager; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * _ensure_table_name_has_prefix |
|
78 | + * |
|
79 | + * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
80 | + * @access public |
|
81 | + * @static |
|
82 | + * @param $table_name |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public static function ensure_table_name_has_prefix($table_name) |
|
86 | + { |
|
87 | + return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * system_initialization |
|
93 | + * ensures the EE configuration settings are loaded with at least default options set |
|
94 | + * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
95 | + * |
|
96 | + * @access public |
|
97 | + * @static |
|
98 | + * @return void |
|
99 | + */ |
|
100 | + public static function system_initialization() |
|
101 | + { |
|
102 | + EEH_Activation::reset_and_update_config(); |
|
103 | + // which is fired BEFORE activation of plugin anyways |
|
104 | + EEH_Activation::verify_default_pages_exist(); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Sets the database schema and creates folders. This should |
|
110 | + * be called on plugin activation and reactivation |
|
111 | + * |
|
112 | + * @return boolean success, whether the database and folders are setup properly |
|
113 | + * @throws \EE_Error |
|
114 | + */ |
|
115 | + public static function initialize_db_and_folders() |
|
116 | + { |
|
117 | + return EEH_Activation::create_database_tables(); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * assuming we have an up-to-date database schema, this will populate it |
|
123 | + * with default and initial data. This should be called |
|
124 | + * upon activation of a new plugin, reactivation, and at the end |
|
125 | + * of running migration scripts |
|
126 | + * |
|
127 | + * @throws \EE_Error |
|
128 | + */ |
|
129 | + public static function initialize_db_content() |
|
130 | + { |
|
131 | + // let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
132 | + if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
133 | + return; |
|
134 | + } |
|
135 | + EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
136 | + |
|
137 | + EEH_Activation::initialize_system_questions(); |
|
138 | + EEH_Activation::insert_default_status_codes(); |
|
139 | + EEH_Activation::generate_default_message_templates(); |
|
140 | + EEH_Activation::create_no_ticket_prices_array(); |
|
141 | + |
|
142 | + EEH_Activation::validate_messages_system(); |
|
143 | + EEH_Activation::insert_default_payment_methods(); |
|
144 | + // in case we've |
|
145 | + EEH_Activation::remove_cron_tasks(); |
|
146 | + EEH_Activation::create_cron_tasks(); |
|
147 | + // remove all TXN locks since that is being done via extra meta now |
|
148 | + delete_option('ee_locked_transactions'); |
|
149 | + // also, check for CAF default db content |
|
150 | + do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
151 | + // also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
152 | + // which users really won't care about on initial activation |
|
153 | + EE_Error::overwrite_success(); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
159 | + * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
160 | + * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
161 | + * (null) |
|
162 | + * |
|
163 | + * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
164 | + * 'old' (only returns ones that should no longer be used),or 'all', |
|
165 | + * @return array |
|
166 | + * @throws \EE_Error |
|
167 | + */ |
|
168 | + public static function get_cron_tasks($which_to_include) |
|
169 | + { |
|
170 | + $cron_tasks = apply_filters( |
|
171 | + 'FHEE__EEH_Activation__get_cron_tasks', |
|
172 | + array( |
|
173 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
174 | + // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
|
175 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
176 | + // there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
177 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
178 | + ) |
|
179 | + ); |
|
180 | + if ($which_to_include === 'old') { |
|
181 | + $cron_tasks = array_filter( |
|
182 | + $cron_tasks, |
|
183 | + function ($value) { |
|
184 | + return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
185 | + } |
|
186 | + ); |
|
187 | + } elseif ($which_to_include === 'current') { |
|
188 | + $cron_tasks = array_filter($cron_tasks); |
|
189 | + } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
190 | + throw new EE_Error( |
|
191 | + sprintf( |
|
192 | + __( |
|
193 | + 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
194 | + 'event_espresso' |
|
195 | + ), |
|
196 | + $which_to_include |
|
197 | + ) |
|
198 | + ); |
|
199 | + } |
|
200 | + return $cron_tasks; |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
206 | + * |
|
207 | + * @throws \EE_Error |
|
208 | + */ |
|
209 | + public static function create_cron_tasks() |
|
210 | + { |
|
211 | + |
|
212 | + foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
213 | + if (! wp_next_scheduled($hook_name)) { |
|
214 | + /** |
|
215 | + * This allows client code to define the initial start timestamp for this schedule. |
|
216 | + */ |
|
217 | + if (is_array($frequency) |
|
218 | + && count($frequency) === 2 |
|
219 | + && isset($frequency[0], $frequency[1]) |
|
220 | + ) { |
|
221 | + $start_timestamp = $frequency[0]; |
|
222 | + $frequency = $frequency[1]; |
|
223 | + } else { |
|
224 | + $start_timestamp = time(); |
|
225 | + } |
|
226 | + wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
227 | + } |
|
228 | + } |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * Remove the currently-existing and now-removed cron tasks. |
|
234 | + * |
|
235 | + * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
236 | + * @throws \EE_Error |
|
237 | + */ |
|
238 | + public static function remove_cron_tasks($remove_all = true) |
|
239 | + { |
|
240 | + $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
241 | + $crons = _get_cron_array(); |
|
242 | + $crons = is_array($crons) ? $crons : array(); |
|
243 | + /* reminder of what $crons look like: |
|
244 | 244 | * Top-level keys are timestamps, and their values are arrays. |
245 | 245 | * The 2nd level arrays have keys with each of the cron task hook names to run at that time |
246 | 246 | * and their values are arrays. |
@@ -257,909 +257,909 @@ discard block |
||
257 | 257 | * ... |
258 | 258 | * ... |
259 | 259 | */ |
260 | - $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
261 | - foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
262 | - if (is_array($hooks_to_fire_at_time)) { |
|
263 | - foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
264 | - if (isset($ee_cron_tasks_to_remove[ $hook_name ]) |
|
265 | - && is_array($ee_cron_tasks_to_remove[ $hook_name ]) |
|
266 | - ) { |
|
267 | - unset($crons[ $timestamp ][ $hook_name ]); |
|
268 | - } |
|
269 | - } |
|
270 | - // also take care of any empty cron timestamps. |
|
271 | - if (empty($hooks_to_fire_at_time)) { |
|
272 | - unset($crons[ $timestamp ]); |
|
273 | - } |
|
274 | - } |
|
275 | - } |
|
276 | - _set_cron_array($crons); |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * CPT_initialization |
|
282 | - * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
283 | - * |
|
284 | - * @access public |
|
285 | - * @static |
|
286 | - * @return void |
|
287 | - */ |
|
288 | - public static function CPT_initialization() |
|
289 | - { |
|
290 | - // register Custom Post Types |
|
291 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
292 | - flush_rewrite_rules(); |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * reset_and_update_config |
|
299 | - * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
300 | - * If there is old calendar config data saved, then it will get converted on activation. |
|
301 | - * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
302 | - * |
|
303 | - * @access public |
|
304 | - * @static |
|
305 | - * @return void |
|
306 | - */ |
|
307 | - public static function reset_and_update_config() |
|
308 | - { |
|
309 | - do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
310 | - add_filter( |
|
311 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
312 | - array('EEH_Activation', 'migrate_old_config_data'), |
|
313 | - 10, |
|
314 | - 3 |
|
315 | - ); |
|
316 | - // EE_Config::reset(); |
|
317 | - if (! EE_Config::logging_enabled()) { |
|
318 | - delete_option(EE_Config::LOG_NAME); |
|
319 | - } |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * load_calendar_config |
|
325 | - * |
|
326 | - * @access public |
|
327 | - * @return void |
|
328 | - */ |
|
329 | - public static function load_calendar_config() |
|
330 | - { |
|
331 | - // grab array of all plugin folders and loop thru it |
|
332 | - $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR); |
|
333 | - if (empty($plugins)) { |
|
334 | - return; |
|
335 | - } |
|
336 | - foreach ($plugins as $plugin_path) { |
|
337 | - // grab plugin folder name from path |
|
338 | - $plugin = basename($plugin_path); |
|
339 | - // drill down to Espresso plugins |
|
340 | - // then to calendar related plugins |
|
341 | - if (strpos($plugin, 'espresso') !== false |
|
342 | - || strpos($plugin, 'Espresso') !== false |
|
343 | - || strpos($plugin, 'ee4') !== false |
|
344 | - || strpos($plugin, 'EE4') !== false |
|
345 | - || strpos($plugin, 'calendar') !== false |
|
346 | - ) { |
|
347 | - // this is what we are looking for |
|
348 | - $calendar_config = $plugin_path . '/EE_Calendar_Config.php'; |
|
349 | - // does it exist in this folder ? |
|
350 | - if (is_readable($calendar_config)) { |
|
351 | - // YEAH! let's load it |
|
352 | - require_once($calendar_config); |
|
353 | - } |
|
354 | - } |
|
355 | - } |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * _migrate_old_config_data |
|
362 | - * |
|
363 | - * @access public |
|
364 | - * @param array|stdClass $settings |
|
365 | - * @param string $config |
|
366 | - * @param \EE_Config $EE_Config |
|
367 | - * @return \stdClass |
|
368 | - */ |
|
369 | - public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
370 | - { |
|
371 | - $convert_from_array = array('addons'); |
|
372 | - // in case old settings were saved as an array |
|
373 | - if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
374 | - // convert existing settings to an object |
|
375 | - $config_array = $settings; |
|
376 | - $settings = new stdClass(); |
|
377 | - foreach ($config_array as $key => $value) { |
|
378 | - if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
379 | - $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
380 | - } else { |
|
381 | - $settings->{$key} = $value; |
|
382 | - } |
|
383 | - } |
|
384 | - add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
385 | - } |
|
386 | - return $settings; |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * deactivate_event_espresso |
|
392 | - * |
|
393 | - * @access public |
|
394 | - * @static |
|
395 | - * @return void |
|
396 | - */ |
|
397 | - public static function deactivate_event_espresso() |
|
398 | - { |
|
399 | - // check permissions |
|
400 | - if (current_user_can('activate_plugins')) { |
|
401 | - deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
402 | - } |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * verify_default_pages_exist |
|
409 | - * |
|
410 | - * @access public |
|
411 | - * @static |
|
412 | - * @return void |
|
413 | - * @throws InvalidDataTypeException |
|
414 | - */ |
|
415 | - public static function verify_default_pages_exist() |
|
416 | - { |
|
417 | - $critical_page_problem = false; |
|
418 | - $critical_pages = array( |
|
419 | - array( |
|
420 | - 'id' => 'reg_page_id', |
|
421 | - 'name' => __('Registration Checkout', 'event_espresso'), |
|
422 | - 'post' => null, |
|
423 | - 'code' => 'ESPRESSO_CHECKOUT', |
|
424 | - ), |
|
425 | - array( |
|
426 | - 'id' => 'txn_page_id', |
|
427 | - 'name' => __('Transactions', 'event_espresso'), |
|
428 | - 'post' => null, |
|
429 | - 'code' => 'ESPRESSO_TXN_PAGE', |
|
430 | - ), |
|
431 | - array( |
|
432 | - 'id' => 'thank_you_page_id', |
|
433 | - 'name' => __('Thank You', 'event_espresso'), |
|
434 | - 'post' => null, |
|
435 | - 'code' => 'ESPRESSO_THANK_YOU', |
|
436 | - ), |
|
437 | - array( |
|
438 | - 'id' => 'cancel_page_id', |
|
439 | - 'name' => __('Registration Cancelled', 'event_espresso'), |
|
440 | - 'post' => null, |
|
441 | - 'code' => 'ESPRESSO_CANCELLED', |
|
442 | - ), |
|
443 | - ); |
|
444 | - $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
445 | - foreach ($critical_pages as $critical_page) { |
|
446 | - // is critical page ID set in config ? |
|
447 | - if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
448 | - // attempt to find post by ID |
|
449 | - $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
450 | - } |
|
451 | - // no dice? |
|
452 | - if ($critical_page['post'] === null) { |
|
453 | - // attempt to find post by title |
|
454 | - $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
455 | - // still nothing? |
|
456 | - if ($critical_page['post'] === null) { |
|
457 | - $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
458 | - // REALLY? Still nothing ??!?!? |
|
459 | - if ($critical_page['post'] === null) { |
|
460 | - $msg = __( |
|
461 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
462 | - 'event_espresso' |
|
463 | - ); |
|
464 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
465 | - break; |
|
466 | - } |
|
467 | - } |
|
468 | - } |
|
469 | - // check that Post ID matches critical page ID in config |
|
470 | - if (isset($critical_page['post']->ID) |
|
471 | - && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
472 | - ) { |
|
473 | - // update Config with post ID |
|
474 | - $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
475 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
476 | - $msg = __( |
|
477 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
478 | - 'event_espresso' |
|
479 | - ); |
|
480 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
481 | - } |
|
482 | - } |
|
483 | - $critical_page_problem = |
|
484 | - ! isset($critical_page['post']->post_status) |
|
485 | - || $critical_page['post']->post_status !== 'publish' |
|
486 | - || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
487 | - ? true |
|
488 | - : $critical_page_problem; |
|
489 | - } |
|
490 | - if ($critical_page_problem) { |
|
491 | - new PersistentAdminNotice( |
|
492 | - 'critical_page_problem', |
|
493 | - sprintf( |
|
494 | - esc_html__( |
|
495 | - 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
496 | - 'event_espresso' |
|
497 | - ), |
|
498 | - '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
499 | - . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
500 | - . '</a>' |
|
501 | - ) |
|
502 | - ); |
|
503 | - } |
|
504 | - if (EE_Error::has_notices()) { |
|
505 | - EE_Error::get_notices(false, true, true); |
|
506 | - } |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - |
|
511 | - /** |
|
512 | - * Returns the first post which uses the specified shortcode |
|
513 | - * |
|
514 | - * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
515 | - * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
516 | - * "[ESPRESSO_THANK_YOU" |
|
517 | - * (we don't search for the closing shortcode bracket because they might have added |
|
518 | - * parameter to the shortcode |
|
519 | - * @return WP_Post or NULl |
|
520 | - */ |
|
521 | - public static function get_page_by_ee_shortcode($ee_shortcode) |
|
522 | - { |
|
523 | - global $wpdb; |
|
524 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
525 | - $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
526 | - if ($post_id) { |
|
527 | - return get_post($post_id); |
|
528 | - } else { |
|
529 | - return null; |
|
530 | - } |
|
531 | - } |
|
532 | - |
|
533 | - |
|
534 | - /** |
|
535 | - * This function generates a post for critical espresso pages |
|
536 | - * |
|
537 | - * @access public |
|
538 | - * @static |
|
539 | - * @param array $critical_page |
|
540 | - * @return array |
|
541 | - */ |
|
542 | - public static function create_critical_page($critical_page) |
|
543 | - { |
|
544 | - |
|
545 | - $post_args = array( |
|
546 | - 'post_title' => $critical_page['name'], |
|
547 | - 'post_status' => 'publish', |
|
548 | - 'post_type' => 'page', |
|
549 | - 'comment_status' => 'closed', |
|
550 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
551 | - ); |
|
552 | - |
|
553 | - $post_id = wp_insert_post($post_args); |
|
554 | - if (! $post_id) { |
|
555 | - $msg = sprintf( |
|
556 | - __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
557 | - $critical_page['name'] |
|
558 | - ); |
|
559 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
560 | - return $critical_page; |
|
561 | - } |
|
562 | - // get newly created post's details |
|
563 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
564 | - $msg = sprintf( |
|
565 | - __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
566 | - $critical_page['name'] |
|
567 | - ); |
|
568 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
569 | - } |
|
570 | - |
|
571 | - return $critical_page; |
|
572 | - } |
|
573 | - |
|
574 | - |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
579 | - * The role being used to check is filterable. |
|
580 | - * |
|
581 | - * @since 4.6.0 |
|
582 | - * @global WPDB $wpdb |
|
583 | - * @return mixed null|int WP_user ID or NULL |
|
584 | - */ |
|
585 | - public static function get_default_creator_id() |
|
586 | - { |
|
587 | - global $wpdb; |
|
588 | - if (! empty(self::$_default_creator_id)) { |
|
589 | - return self::$_default_creator_id; |
|
590 | - }/**/ |
|
591 | - $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
592 | - // let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
593 | - $pre_filtered_id = apply_filters( |
|
594 | - 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
595 | - false, |
|
596 | - $role_to_check |
|
597 | - ); |
|
598 | - if ($pre_filtered_id !== false) { |
|
599 | - return (int) $pre_filtered_id; |
|
600 | - } |
|
601 | - $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
602 | - $query = $wpdb->prepare( |
|
603 | - "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
604 | - '%' . $role_to_check . '%' |
|
605 | - ); |
|
606 | - $user_id = $wpdb->get_var($query); |
|
607 | - $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
608 | - if ($user_id && (int) $user_id) { |
|
609 | - self::$_default_creator_id = (int) $user_id; |
|
610 | - return self::$_default_creator_id; |
|
611 | - } else { |
|
612 | - return null; |
|
613 | - } |
|
614 | - } |
|
615 | - |
|
616 | - |
|
617 | - |
|
618 | - /** |
|
619 | - * used by EE and EE addons during plugin activation to create tables. |
|
620 | - * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
621 | - * but includes extra logic regarding activations. |
|
622 | - * |
|
623 | - * @access public |
|
624 | - * @static |
|
625 | - * @param string $table_name without the $wpdb->prefix |
|
626 | - * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
627 | - * table query) |
|
628 | - * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
629 | - * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
630 | - * and new once this function is done (ie, you really do want to CREATE a |
|
631 | - * table, and expect it to be empty once you're done) leave as FALSE when |
|
632 | - * you just want to verify the table exists and matches this definition |
|
633 | - * (and if it HAS data in it you want to leave it be) |
|
634 | - * @return void |
|
635 | - * @throws EE_Error if there are database errors |
|
636 | - */ |
|
637 | - public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
638 | - { |
|
639 | - if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
640 | - return; |
|
641 | - } |
|
642 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
643 | - if (! function_exists('dbDelta')) { |
|
644 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
645 | - } |
|
646 | - $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
647 | - $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
648 | - // do we need to first delete an existing version of this table ? |
|
649 | - if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
650 | - // ok, delete the table... but ONLY if it's empty |
|
651 | - $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
652 | - // table is NOT empty, are you SURE you want to delete this table ??? |
|
653 | - if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
654 | - \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
655 | - } elseif (! $deleted_safely) { |
|
656 | - // so we should be more cautious rather than just dropping tables so easily |
|
657 | - error_log( |
|
658 | - sprintf( |
|
659 | - __( |
|
660 | - 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
661 | - 'event_espresso' |
|
662 | - ), |
|
663 | - $wp_table_name, |
|
664 | - '<br/>', |
|
665 | - 'espresso_db_update' |
|
666 | - ) |
|
667 | - ); |
|
668 | - } |
|
669 | - } |
|
670 | - $engine = str_replace('ENGINE=', '', $engine); |
|
671 | - \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
672 | - } |
|
673 | - |
|
674 | - |
|
675 | - |
|
676 | - /** |
|
677 | - * add_column_if_it_doesn't_exist |
|
678 | - * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
679 | - * |
|
680 | - * @access public |
|
681 | - * @static |
|
682 | - * @deprecated instead use TableManager::addColumn() |
|
683 | - * @param string $table_name (without "wp_", eg "esp_attendee" |
|
684 | - * @param string $column_name |
|
685 | - * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
686 | - * 'VARCHAR(10)' |
|
687 | - * @return bool|int |
|
688 | - */ |
|
689 | - public static function add_column_if_it_doesnt_exist( |
|
690 | - $table_name, |
|
691 | - $column_name, |
|
692 | - $column_info = 'INT UNSIGNED NOT NULL' |
|
693 | - ) { |
|
694 | - return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
695 | - } |
|
696 | - |
|
697 | - |
|
698 | - /** |
|
699 | - * get_fields_on_table |
|
700 | - * Gets all the fields on the database table. |
|
701 | - * |
|
702 | - * @access public |
|
703 | - * @deprecated instead use TableManager::getTableColumns() |
|
704 | - * @static |
|
705 | - * @param string $table_name , without prefixed $wpdb->prefix |
|
706 | - * @return array of database column names |
|
707 | - */ |
|
708 | - public static function get_fields_on_table($table_name = null) |
|
709 | - { |
|
710 | - return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
711 | - } |
|
712 | - |
|
713 | - |
|
714 | - /** |
|
715 | - * db_table_is_empty |
|
716 | - * |
|
717 | - * @access public\ |
|
718 | - * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
719 | - * @static |
|
720 | - * @param string $table_name |
|
721 | - * @return bool |
|
722 | - */ |
|
723 | - public static function db_table_is_empty($table_name) |
|
724 | - { |
|
725 | - return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
726 | - } |
|
727 | - |
|
728 | - |
|
729 | - /** |
|
730 | - * delete_db_table_if_empty |
|
731 | - * |
|
732 | - * @access public |
|
733 | - * @static |
|
734 | - * @param string $table_name |
|
735 | - * @return bool | int |
|
736 | - */ |
|
737 | - public static function delete_db_table_if_empty($table_name) |
|
738 | - { |
|
739 | - if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
740 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
741 | - } |
|
742 | - return false; |
|
743 | - } |
|
744 | - |
|
745 | - |
|
746 | - /** |
|
747 | - * delete_unused_db_table |
|
748 | - * |
|
749 | - * @access public |
|
750 | - * @static |
|
751 | - * @deprecated instead use TableManager::dropTable() |
|
752 | - * @param string $table_name |
|
753 | - * @return bool | int |
|
754 | - */ |
|
755 | - public static function delete_unused_db_table($table_name) |
|
756 | - { |
|
757 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
758 | - } |
|
759 | - |
|
760 | - |
|
761 | - /** |
|
762 | - * drop_index |
|
763 | - * |
|
764 | - * @access public |
|
765 | - * @static |
|
766 | - * @deprecated instead use TableManager::dropIndex() |
|
767 | - * @param string $table_name |
|
768 | - * @param string $index_name |
|
769 | - * @return bool | int |
|
770 | - */ |
|
771 | - public static function drop_index($table_name, $index_name) |
|
772 | - { |
|
773 | - return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
774 | - } |
|
775 | - |
|
776 | - |
|
777 | - |
|
778 | - /** |
|
779 | - * create_database_tables |
|
780 | - * |
|
781 | - * @access public |
|
782 | - * @static |
|
783 | - * @throws EE_Error |
|
784 | - * @return boolean success (whether database is setup properly or not) |
|
785 | - */ |
|
786 | - public static function create_database_tables() |
|
787 | - { |
|
788 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
789 | - // find the migration script that sets the database to be compatible with the code |
|
790 | - $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
791 | - if ($dms_name) { |
|
792 | - $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
793 | - $current_data_migration_script->set_migrating(false); |
|
794 | - $current_data_migration_script->schema_changes_before_migration(); |
|
795 | - $current_data_migration_script->schema_changes_after_migration(); |
|
796 | - if ($current_data_migration_script->get_errors()) { |
|
797 | - if (WP_DEBUG) { |
|
798 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
799 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
800 | - } |
|
801 | - } else { |
|
802 | - EE_Error::add_error( |
|
803 | - __( |
|
804 | - 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
260 | + $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
261 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
262 | + if (is_array($hooks_to_fire_at_time)) { |
|
263 | + foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
264 | + if (isset($ee_cron_tasks_to_remove[ $hook_name ]) |
|
265 | + && is_array($ee_cron_tasks_to_remove[ $hook_name ]) |
|
266 | + ) { |
|
267 | + unset($crons[ $timestamp ][ $hook_name ]); |
|
268 | + } |
|
269 | + } |
|
270 | + // also take care of any empty cron timestamps. |
|
271 | + if (empty($hooks_to_fire_at_time)) { |
|
272 | + unset($crons[ $timestamp ]); |
|
273 | + } |
|
274 | + } |
|
275 | + } |
|
276 | + _set_cron_array($crons); |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * CPT_initialization |
|
282 | + * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
283 | + * |
|
284 | + * @access public |
|
285 | + * @static |
|
286 | + * @return void |
|
287 | + */ |
|
288 | + public static function CPT_initialization() |
|
289 | + { |
|
290 | + // register Custom Post Types |
|
291 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
292 | + flush_rewrite_rules(); |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * reset_and_update_config |
|
299 | + * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
300 | + * If there is old calendar config data saved, then it will get converted on activation. |
|
301 | + * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
302 | + * |
|
303 | + * @access public |
|
304 | + * @static |
|
305 | + * @return void |
|
306 | + */ |
|
307 | + public static function reset_and_update_config() |
|
308 | + { |
|
309 | + do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
310 | + add_filter( |
|
311 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
312 | + array('EEH_Activation', 'migrate_old_config_data'), |
|
313 | + 10, |
|
314 | + 3 |
|
315 | + ); |
|
316 | + // EE_Config::reset(); |
|
317 | + if (! EE_Config::logging_enabled()) { |
|
318 | + delete_option(EE_Config::LOG_NAME); |
|
319 | + } |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * load_calendar_config |
|
325 | + * |
|
326 | + * @access public |
|
327 | + * @return void |
|
328 | + */ |
|
329 | + public static function load_calendar_config() |
|
330 | + { |
|
331 | + // grab array of all plugin folders and loop thru it |
|
332 | + $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR); |
|
333 | + if (empty($plugins)) { |
|
334 | + return; |
|
335 | + } |
|
336 | + foreach ($plugins as $plugin_path) { |
|
337 | + // grab plugin folder name from path |
|
338 | + $plugin = basename($plugin_path); |
|
339 | + // drill down to Espresso plugins |
|
340 | + // then to calendar related plugins |
|
341 | + if (strpos($plugin, 'espresso') !== false |
|
342 | + || strpos($plugin, 'Espresso') !== false |
|
343 | + || strpos($plugin, 'ee4') !== false |
|
344 | + || strpos($plugin, 'EE4') !== false |
|
345 | + || strpos($plugin, 'calendar') !== false |
|
346 | + ) { |
|
347 | + // this is what we are looking for |
|
348 | + $calendar_config = $plugin_path . '/EE_Calendar_Config.php'; |
|
349 | + // does it exist in this folder ? |
|
350 | + if (is_readable($calendar_config)) { |
|
351 | + // YEAH! let's load it |
|
352 | + require_once($calendar_config); |
|
353 | + } |
|
354 | + } |
|
355 | + } |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * _migrate_old_config_data |
|
362 | + * |
|
363 | + * @access public |
|
364 | + * @param array|stdClass $settings |
|
365 | + * @param string $config |
|
366 | + * @param \EE_Config $EE_Config |
|
367 | + * @return \stdClass |
|
368 | + */ |
|
369 | + public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
370 | + { |
|
371 | + $convert_from_array = array('addons'); |
|
372 | + // in case old settings were saved as an array |
|
373 | + if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
374 | + // convert existing settings to an object |
|
375 | + $config_array = $settings; |
|
376 | + $settings = new stdClass(); |
|
377 | + foreach ($config_array as $key => $value) { |
|
378 | + if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
379 | + $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
380 | + } else { |
|
381 | + $settings->{$key} = $value; |
|
382 | + } |
|
383 | + } |
|
384 | + add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
385 | + } |
|
386 | + return $settings; |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * deactivate_event_espresso |
|
392 | + * |
|
393 | + * @access public |
|
394 | + * @static |
|
395 | + * @return void |
|
396 | + */ |
|
397 | + public static function deactivate_event_espresso() |
|
398 | + { |
|
399 | + // check permissions |
|
400 | + if (current_user_can('activate_plugins')) { |
|
401 | + deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
402 | + } |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * verify_default_pages_exist |
|
409 | + * |
|
410 | + * @access public |
|
411 | + * @static |
|
412 | + * @return void |
|
413 | + * @throws InvalidDataTypeException |
|
414 | + */ |
|
415 | + public static function verify_default_pages_exist() |
|
416 | + { |
|
417 | + $critical_page_problem = false; |
|
418 | + $critical_pages = array( |
|
419 | + array( |
|
420 | + 'id' => 'reg_page_id', |
|
421 | + 'name' => __('Registration Checkout', 'event_espresso'), |
|
422 | + 'post' => null, |
|
423 | + 'code' => 'ESPRESSO_CHECKOUT', |
|
424 | + ), |
|
425 | + array( |
|
426 | + 'id' => 'txn_page_id', |
|
427 | + 'name' => __('Transactions', 'event_espresso'), |
|
428 | + 'post' => null, |
|
429 | + 'code' => 'ESPRESSO_TXN_PAGE', |
|
430 | + ), |
|
431 | + array( |
|
432 | + 'id' => 'thank_you_page_id', |
|
433 | + 'name' => __('Thank You', 'event_espresso'), |
|
434 | + 'post' => null, |
|
435 | + 'code' => 'ESPRESSO_THANK_YOU', |
|
436 | + ), |
|
437 | + array( |
|
438 | + 'id' => 'cancel_page_id', |
|
439 | + 'name' => __('Registration Cancelled', 'event_espresso'), |
|
440 | + 'post' => null, |
|
441 | + 'code' => 'ESPRESSO_CANCELLED', |
|
442 | + ), |
|
443 | + ); |
|
444 | + $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
445 | + foreach ($critical_pages as $critical_page) { |
|
446 | + // is critical page ID set in config ? |
|
447 | + if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
448 | + // attempt to find post by ID |
|
449 | + $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
450 | + } |
|
451 | + // no dice? |
|
452 | + if ($critical_page['post'] === null) { |
|
453 | + // attempt to find post by title |
|
454 | + $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
455 | + // still nothing? |
|
456 | + if ($critical_page['post'] === null) { |
|
457 | + $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
458 | + // REALLY? Still nothing ??!?!? |
|
459 | + if ($critical_page['post'] === null) { |
|
460 | + $msg = __( |
|
461 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
462 | + 'event_espresso' |
|
463 | + ); |
|
464 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
465 | + break; |
|
466 | + } |
|
467 | + } |
|
468 | + } |
|
469 | + // check that Post ID matches critical page ID in config |
|
470 | + if (isset($critical_page['post']->ID) |
|
471 | + && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
472 | + ) { |
|
473 | + // update Config with post ID |
|
474 | + $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
475 | + if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
476 | + $msg = __( |
|
477 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
478 | + 'event_espresso' |
|
479 | + ); |
|
480 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
481 | + } |
|
482 | + } |
|
483 | + $critical_page_problem = |
|
484 | + ! isset($critical_page['post']->post_status) |
|
485 | + || $critical_page['post']->post_status !== 'publish' |
|
486 | + || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
487 | + ? true |
|
488 | + : $critical_page_problem; |
|
489 | + } |
|
490 | + if ($critical_page_problem) { |
|
491 | + new PersistentAdminNotice( |
|
492 | + 'critical_page_problem', |
|
493 | + sprintf( |
|
494 | + esc_html__( |
|
495 | + 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
496 | + 'event_espresso' |
|
497 | + ), |
|
498 | + '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
499 | + . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
500 | + . '</a>' |
|
501 | + ) |
|
502 | + ); |
|
503 | + } |
|
504 | + if (EE_Error::has_notices()) { |
|
505 | + EE_Error::get_notices(false, true, true); |
|
506 | + } |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + |
|
511 | + /** |
|
512 | + * Returns the first post which uses the specified shortcode |
|
513 | + * |
|
514 | + * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
515 | + * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
516 | + * "[ESPRESSO_THANK_YOU" |
|
517 | + * (we don't search for the closing shortcode bracket because they might have added |
|
518 | + * parameter to the shortcode |
|
519 | + * @return WP_Post or NULl |
|
520 | + */ |
|
521 | + public static function get_page_by_ee_shortcode($ee_shortcode) |
|
522 | + { |
|
523 | + global $wpdb; |
|
524 | + $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
525 | + $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
526 | + if ($post_id) { |
|
527 | + return get_post($post_id); |
|
528 | + } else { |
|
529 | + return null; |
|
530 | + } |
|
531 | + } |
|
532 | + |
|
533 | + |
|
534 | + /** |
|
535 | + * This function generates a post for critical espresso pages |
|
536 | + * |
|
537 | + * @access public |
|
538 | + * @static |
|
539 | + * @param array $critical_page |
|
540 | + * @return array |
|
541 | + */ |
|
542 | + public static function create_critical_page($critical_page) |
|
543 | + { |
|
544 | + |
|
545 | + $post_args = array( |
|
546 | + 'post_title' => $critical_page['name'], |
|
547 | + 'post_status' => 'publish', |
|
548 | + 'post_type' => 'page', |
|
549 | + 'comment_status' => 'closed', |
|
550 | + 'post_content' => '[' . $critical_page['code'] . ']', |
|
551 | + ); |
|
552 | + |
|
553 | + $post_id = wp_insert_post($post_args); |
|
554 | + if (! $post_id) { |
|
555 | + $msg = sprintf( |
|
556 | + __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
557 | + $critical_page['name'] |
|
558 | + ); |
|
559 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
560 | + return $critical_page; |
|
561 | + } |
|
562 | + // get newly created post's details |
|
563 | + if (! $critical_page['post'] = get_post($post_id)) { |
|
564 | + $msg = sprintf( |
|
565 | + __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
566 | + $critical_page['name'] |
|
567 | + ); |
|
568 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
569 | + } |
|
570 | + |
|
571 | + return $critical_page; |
|
572 | + } |
|
573 | + |
|
574 | + |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
579 | + * The role being used to check is filterable. |
|
580 | + * |
|
581 | + * @since 4.6.0 |
|
582 | + * @global WPDB $wpdb |
|
583 | + * @return mixed null|int WP_user ID or NULL |
|
584 | + */ |
|
585 | + public static function get_default_creator_id() |
|
586 | + { |
|
587 | + global $wpdb; |
|
588 | + if (! empty(self::$_default_creator_id)) { |
|
589 | + return self::$_default_creator_id; |
|
590 | + }/**/ |
|
591 | + $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
592 | + // let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
593 | + $pre_filtered_id = apply_filters( |
|
594 | + 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
595 | + false, |
|
596 | + $role_to_check |
|
597 | + ); |
|
598 | + if ($pre_filtered_id !== false) { |
|
599 | + return (int) $pre_filtered_id; |
|
600 | + } |
|
601 | + $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
602 | + $query = $wpdb->prepare( |
|
603 | + "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
604 | + '%' . $role_to_check . '%' |
|
605 | + ); |
|
606 | + $user_id = $wpdb->get_var($query); |
|
607 | + $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
608 | + if ($user_id && (int) $user_id) { |
|
609 | + self::$_default_creator_id = (int) $user_id; |
|
610 | + return self::$_default_creator_id; |
|
611 | + } else { |
|
612 | + return null; |
|
613 | + } |
|
614 | + } |
|
615 | + |
|
616 | + |
|
617 | + |
|
618 | + /** |
|
619 | + * used by EE and EE addons during plugin activation to create tables. |
|
620 | + * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
621 | + * but includes extra logic regarding activations. |
|
622 | + * |
|
623 | + * @access public |
|
624 | + * @static |
|
625 | + * @param string $table_name without the $wpdb->prefix |
|
626 | + * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
627 | + * table query) |
|
628 | + * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
629 | + * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
630 | + * and new once this function is done (ie, you really do want to CREATE a |
|
631 | + * table, and expect it to be empty once you're done) leave as FALSE when |
|
632 | + * you just want to verify the table exists and matches this definition |
|
633 | + * (and if it HAS data in it you want to leave it be) |
|
634 | + * @return void |
|
635 | + * @throws EE_Error if there are database errors |
|
636 | + */ |
|
637 | + public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
638 | + { |
|
639 | + if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
640 | + return; |
|
641 | + } |
|
642 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
643 | + if (! function_exists('dbDelta')) { |
|
644 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
645 | + } |
|
646 | + $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
647 | + $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
648 | + // do we need to first delete an existing version of this table ? |
|
649 | + if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
650 | + // ok, delete the table... but ONLY if it's empty |
|
651 | + $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
652 | + // table is NOT empty, are you SURE you want to delete this table ??? |
|
653 | + if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
654 | + \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
655 | + } elseif (! $deleted_safely) { |
|
656 | + // so we should be more cautious rather than just dropping tables so easily |
|
657 | + error_log( |
|
658 | + sprintf( |
|
659 | + __( |
|
660 | + 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
661 | + 'event_espresso' |
|
662 | + ), |
|
663 | + $wp_table_name, |
|
664 | + '<br/>', |
|
665 | + 'espresso_db_update' |
|
666 | + ) |
|
667 | + ); |
|
668 | + } |
|
669 | + } |
|
670 | + $engine = str_replace('ENGINE=', '', $engine); |
|
671 | + \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
672 | + } |
|
673 | + |
|
674 | + |
|
675 | + |
|
676 | + /** |
|
677 | + * add_column_if_it_doesn't_exist |
|
678 | + * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
679 | + * |
|
680 | + * @access public |
|
681 | + * @static |
|
682 | + * @deprecated instead use TableManager::addColumn() |
|
683 | + * @param string $table_name (without "wp_", eg "esp_attendee" |
|
684 | + * @param string $column_name |
|
685 | + * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
686 | + * 'VARCHAR(10)' |
|
687 | + * @return bool|int |
|
688 | + */ |
|
689 | + public static function add_column_if_it_doesnt_exist( |
|
690 | + $table_name, |
|
691 | + $column_name, |
|
692 | + $column_info = 'INT UNSIGNED NOT NULL' |
|
693 | + ) { |
|
694 | + return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
695 | + } |
|
696 | + |
|
697 | + |
|
698 | + /** |
|
699 | + * get_fields_on_table |
|
700 | + * Gets all the fields on the database table. |
|
701 | + * |
|
702 | + * @access public |
|
703 | + * @deprecated instead use TableManager::getTableColumns() |
|
704 | + * @static |
|
705 | + * @param string $table_name , without prefixed $wpdb->prefix |
|
706 | + * @return array of database column names |
|
707 | + */ |
|
708 | + public static function get_fields_on_table($table_name = null) |
|
709 | + { |
|
710 | + return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
711 | + } |
|
712 | + |
|
713 | + |
|
714 | + /** |
|
715 | + * db_table_is_empty |
|
716 | + * |
|
717 | + * @access public\ |
|
718 | + * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
719 | + * @static |
|
720 | + * @param string $table_name |
|
721 | + * @return bool |
|
722 | + */ |
|
723 | + public static function db_table_is_empty($table_name) |
|
724 | + { |
|
725 | + return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
726 | + } |
|
727 | + |
|
728 | + |
|
729 | + /** |
|
730 | + * delete_db_table_if_empty |
|
731 | + * |
|
732 | + * @access public |
|
733 | + * @static |
|
734 | + * @param string $table_name |
|
735 | + * @return bool | int |
|
736 | + */ |
|
737 | + public static function delete_db_table_if_empty($table_name) |
|
738 | + { |
|
739 | + if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
740 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
741 | + } |
|
742 | + return false; |
|
743 | + } |
|
744 | + |
|
745 | + |
|
746 | + /** |
|
747 | + * delete_unused_db_table |
|
748 | + * |
|
749 | + * @access public |
|
750 | + * @static |
|
751 | + * @deprecated instead use TableManager::dropTable() |
|
752 | + * @param string $table_name |
|
753 | + * @return bool | int |
|
754 | + */ |
|
755 | + public static function delete_unused_db_table($table_name) |
|
756 | + { |
|
757 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
758 | + } |
|
759 | + |
|
760 | + |
|
761 | + /** |
|
762 | + * drop_index |
|
763 | + * |
|
764 | + * @access public |
|
765 | + * @static |
|
766 | + * @deprecated instead use TableManager::dropIndex() |
|
767 | + * @param string $table_name |
|
768 | + * @param string $index_name |
|
769 | + * @return bool | int |
|
770 | + */ |
|
771 | + public static function drop_index($table_name, $index_name) |
|
772 | + { |
|
773 | + return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
774 | + } |
|
775 | + |
|
776 | + |
|
777 | + |
|
778 | + /** |
|
779 | + * create_database_tables |
|
780 | + * |
|
781 | + * @access public |
|
782 | + * @static |
|
783 | + * @throws EE_Error |
|
784 | + * @return boolean success (whether database is setup properly or not) |
|
785 | + */ |
|
786 | + public static function create_database_tables() |
|
787 | + { |
|
788 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
789 | + // find the migration script that sets the database to be compatible with the code |
|
790 | + $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
791 | + if ($dms_name) { |
|
792 | + $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
793 | + $current_data_migration_script->set_migrating(false); |
|
794 | + $current_data_migration_script->schema_changes_before_migration(); |
|
795 | + $current_data_migration_script->schema_changes_after_migration(); |
|
796 | + if ($current_data_migration_script->get_errors()) { |
|
797 | + if (WP_DEBUG) { |
|
798 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
799 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
800 | + } |
|
801 | + } else { |
|
802 | + EE_Error::add_error( |
|
803 | + __( |
|
804 | + 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
805 | 805 | deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', |
806 | - 'event_espresso' |
|
807 | - ) |
|
808 | - ); |
|
809 | - } |
|
810 | - return false; |
|
811 | - } |
|
812 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
813 | - } else { |
|
814 | - EE_Error::add_error( |
|
815 | - __( |
|
816 | - 'Could not determine most up-to-date data migration script from which to pull database schema |
|
806 | + 'event_espresso' |
|
807 | + ) |
|
808 | + ); |
|
809 | + } |
|
810 | + return false; |
|
811 | + } |
|
812 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
813 | + } else { |
|
814 | + EE_Error::add_error( |
|
815 | + __( |
|
816 | + 'Could not determine most up-to-date data migration script from which to pull database schema |
|
817 | 817 | structure. So database is probably not setup properly', |
818 | - 'event_espresso' |
|
819 | - ), |
|
820 | - __FILE__, |
|
821 | - __FUNCTION__, |
|
822 | - __LINE__ |
|
823 | - ); |
|
824 | - return false; |
|
825 | - } |
|
826 | - return true; |
|
827 | - } |
|
828 | - |
|
829 | - |
|
830 | - |
|
831 | - /** |
|
832 | - * initialize_system_questions |
|
833 | - * |
|
834 | - * @access public |
|
835 | - * @static |
|
836 | - * @return void |
|
837 | - */ |
|
838 | - public static function initialize_system_questions() |
|
839 | - { |
|
840 | - // QUESTION GROUPS |
|
841 | - global $wpdb; |
|
842 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
843 | - $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
844 | - // what we have |
|
845 | - $question_groups = $wpdb->get_col($SQL); |
|
846 | - // check the response |
|
847 | - $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
848 | - // what we should have |
|
849 | - $QSG_systems = array(1, 2); |
|
850 | - // loop thru what we should have and compare to what we have |
|
851 | - foreach ($QSG_systems as $QSG_system) { |
|
852 | - // reset values array |
|
853 | - $QSG_values = array(); |
|
854 | - // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
855 | - if (! in_array("$QSG_system", $question_groups)) { |
|
856 | - // add it |
|
857 | - switch ($QSG_system) { |
|
858 | - case 1: |
|
859 | - $QSG_values = array( |
|
860 | - 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
861 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
862 | - 'QSG_desc' => '', |
|
863 | - 'QSG_order' => 1, |
|
864 | - 'QSG_show_group_name' => 1, |
|
865 | - 'QSG_show_group_desc' => 1, |
|
866 | - 'QSG_system' => EEM_Question_Group::system_personal, |
|
867 | - 'QSG_deleted' => 0, |
|
868 | - ); |
|
869 | - break; |
|
870 | - case 2: |
|
871 | - $QSG_values = array( |
|
872 | - 'QSG_name' => __('Address Information', 'event_espresso'), |
|
873 | - 'QSG_identifier' => 'address-information-' . time(), |
|
874 | - 'QSG_desc' => '', |
|
875 | - 'QSG_order' => 2, |
|
876 | - 'QSG_show_group_name' => 1, |
|
877 | - 'QSG_show_group_desc' => 1, |
|
878 | - 'QSG_system' => EEM_Question_Group::system_address, |
|
879 | - 'QSG_deleted' => 0, |
|
880 | - ); |
|
881 | - break; |
|
882 | - } |
|
883 | - // make sure we have some values before inserting them |
|
884 | - if (! empty($QSG_values)) { |
|
885 | - // insert system question |
|
886 | - $wpdb->insert( |
|
887 | - $table_name, |
|
888 | - $QSG_values, |
|
889 | - array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
890 | - ); |
|
891 | - $QSG_IDs[ $QSG_system ] = $wpdb->insert_id; |
|
892 | - } |
|
893 | - } |
|
894 | - } |
|
895 | - // QUESTIONS |
|
896 | - global $wpdb; |
|
897 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
898 | - $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
899 | - // what we have |
|
900 | - $questions = $wpdb->get_col($SQL); |
|
901 | - // what we should have |
|
902 | - $QST_systems = array( |
|
903 | - 'fname', |
|
904 | - 'lname', |
|
905 | - 'email', |
|
906 | - 'address', |
|
907 | - 'address2', |
|
908 | - 'city', |
|
909 | - 'country', |
|
910 | - 'state', |
|
911 | - 'zip', |
|
912 | - 'phone', |
|
913 | - ); |
|
914 | - $order_for_group_1 = 1; |
|
915 | - $order_for_group_2 = 1; |
|
916 | - // loop thru what we should have and compare to what we have |
|
917 | - foreach ($QST_systems as $QST_system) { |
|
918 | - // reset values array |
|
919 | - $QST_values = array(); |
|
920 | - // if we don't have what we should have |
|
921 | - if (! in_array($QST_system, $questions)) { |
|
922 | - // add it |
|
923 | - switch ($QST_system) { |
|
924 | - case 'fname': |
|
925 | - $QST_values = array( |
|
926 | - 'QST_display_text' => __('First Name', 'event_espresso'), |
|
927 | - 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
928 | - 'QST_system' => 'fname', |
|
929 | - 'QST_type' => 'TEXT', |
|
930 | - 'QST_required' => 1, |
|
931 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
932 | - 'QST_order' => 1, |
|
933 | - 'QST_admin_only' => 0, |
|
934 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
935 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
936 | - 'QST_deleted' => 0, |
|
937 | - ); |
|
938 | - break; |
|
939 | - case 'lname': |
|
940 | - $QST_values = array( |
|
941 | - 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
942 | - 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
943 | - 'QST_system' => 'lname', |
|
944 | - 'QST_type' => 'TEXT', |
|
945 | - 'QST_required' => 1, |
|
946 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
947 | - 'QST_order' => 2, |
|
948 | - 'QST_admin_only' => 0, |
|
949 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
950 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
951 | - 'QST_deleted' => 0, |
|
952 | - ); |
|
953 | - break; |
|
954 | - case 'email': |
|
955 | - $QST_values = array( |
|
956 | - 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
957 | - 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
958 | - 'QST_system' => 'email', |
|
959 | - 'QST_type' => 'EMAIL', |
|
960 | - 'QST_required' => 1, |
|
961 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
962 | - 'QST_order' => 3, |
|
963 | - 'QST_admin_only' => 0, |
|
964 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
965 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
966 | - 'QST_deleted' => 0, |
|
967 | - ); |
|
968 | - break; |
|
969 | - case 'address': |
|
970 | - $QST_values = array( |
|
971 | - 'QST_display_text' => __('Address', 'event_espresso'), |
|
972 | - 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
973 | - 'QST_system' => 'address', |
|
974 | - 'QST_type' => 'TEXT', |
|
975 | - 'QST_required' => 0, |
|
976 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
977 | - 'QST_order' => 4, |
|
978 | - 'QST_admin_only' => 0, |
|
979 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
980 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
981 | - 'QST_deleted' => 0, |
|
982 | - ); |
|
983 | - break; |
|
984 | - case 'address2': |
|
985 | - $QST_values = array( |
|
986 | - 'QST_display_text' => __('Address2', 'event_espresso'), |
|
987 | - 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
988 | - 'QST_system' => 'address2', |
|
989 | - 'QST_type' => 'TEXT', |
|
990 | - 'QST_required' => 0, |
|
991 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
992 | - 'QST_order' => 5, |
|
993 | - 'QST_admin_only' => 0, |
|
994 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
995 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
996 | - 'QST_deleted' => 0, |
|
997 | - ); |
|
998 | - break; |
|
999 | - case 'city': |
|
1000 | - $QST_values = array( |
|
1001 | - 'QST_display_text' => __('City', 'event_espresso'), |
|
1002 | - 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
1003 | - 'QST_system' => 'city', |
|
1004 | - 'QST_type' => 'TEXT', |
|
1005 | - 'QST_required' => 0, |
|
1006 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1007 | - 'QST_order' => 6, |
|
1008 | - 'QST_admin_only' => 0, |
|
1009 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1010 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1011 | - 'QST_deleted' => 0, |
|
1012 | - ); |
|
1013 | - break; |
|
1014 | - case 'country': |
|
1015 | - $QST_values = array( |
|
1016 | - 'QST_display_text' => __('Country', 'event_espresso'), |
|
1017 | - 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
1018 | - 'QST_system' => 'country', |
|
1019 | - 'QST_type' => 'COUNTRY', |
|
1020 | - 'QST_required' => 0, |
|
1021 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1022 | - 'QST_order' => 7, |
|
1023 | - 'QST_admin_only' => 0, |
|
1024 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1025 | - 'QST_deleted' => 0, |
|
1026 | - ); |
|
1027 | - break; |
|
1028 | - case 'state': |
|
1029 | - $QST_values = array( |
|
1030 | - 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
1031 | - 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
1032 | - 'QST_system' => 'state', |
|
1033 | - 'QST_type' => 'STATE', |
|
1034 | - 'QST_required' => 0, |
|
1035 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1036 | - 'QST_order' => 8, |
|
1037 | - 'QST_admin_only' => 0, |
|
1038 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1039 | - 'QST_deleted' => 0, |
|
1040 | - ); |
|
1041 | - break; |
|
1042 | - case 'zip': |
|
1043 | - $QST_values = array( |
|
1044 | - 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
1045 | - 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
1046 | - 'QST_system' => 'zip', |
|
1047 | - 'QST_type' => 'TEXT', |
|
1048 | - 'QST_required' => 0, |
|
1049 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1050 | - 'QST_order' => 9, |
|
1051 | - 'QST_admin_only' => 0, |
|
1052 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1053 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1054 | - 'QST_deleted' => 0, |
|
1055 | - ); |
|
1056 | - break; |
|
1057 | - case 'phone': |
|
1058 | - $QST_values = array( |
|
1059 | - 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
1060 | - 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
1061 | - 'QST_system' => 'phone', |
|
1062 | - 'QST_type' => 'TEXT', |
|
1063 | - 'QST_required' => 0, |
|
1064 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1065 | - 'QST_order' => 10, |
|
1066 | - 'QST_admin_only' => 0, |
|
1067 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1068 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1069 | - 'QST_deleted' => 0, |
|
1070 | - ); |
|
1071 | - break; |
|
1072 | - } |
|
1073 | - if (! empty($QST_values)) { |
|
1074 | - // insert system question |
|
1075 | - $wpdb->insert( |
|
1076 | - $table_name, |
|
1077 | - $QST_values, |
|
1078 | - array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
1079 | - ); |
|
1080 | - $QST_ID = $wpdb->insert_id; |
|
1081 | - // QUESTION GROUP QUESTIONS |
|
1082 | - if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
1083 | - $system_question_we_want = EEM_Question_Group::system_personal; |
|
1084 | - } else { |
|
1085 | - $system_question_we_want = EEM_Question_Group::system_address; |
|
1086 | - } |
|
1087 | - if (isset($QSG_IDs[ $system_question_we_want ])) { |
|
1088 | - $QSG_ID = $QSG_IDs[ $system_question_we_want ]; |
|
1089 | - } else { |
|
1090 | - $id_col = EEM_Question_Group::instance() |
|
1091 | - ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
1092 | - if (is_array($id_col)) { |
|
1093 | - $QSG_ID = reset($id_col); |
|
1094 | - } else { |
|
1095 | - // ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
1096 | - EE_Log::instance()->log( |
|
1097 | - __FILE__, |
|
1098 | - __FUNCTION__, |
|
1099 | - sprintf( |
|
1100 | - __( |
|
1101 | - 'Could not associate question %1$s to a question group because no system question |
|
818 | + 'event_espresso' |
|
819 | + ), |
|
820 | + __FILE__, |
|
821 | + __FUNCTION__, |
|
822 | + __LINE__ |
|
823 | + ); |
|
824 | + return false; |
|
825 | + } |
|
826 | + return true; |
|
827 | + } |
|
828 | + |
|
829 | + |
|
830 | + |
|
831 | + /** |
|
832 | + * initialize_system_questions |
|
833 | + * |
|
834 | + * @access public |
|
835 | + * @static |
|
836 | + * @return void |
|
837 | + */ |
|
838 | + public static function initialize_system_questions() |
|
839 | + { |
|
840 | + // QUESTION GROUPS |
|
841 | + global $wpdb; |
|
842 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
843 | + $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
844 | + // what we have |
|
845 | + $question_groups = $wpdb->get_col($SQL); |
|
846 | + // check the response |
|
847 | + $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
848 | + // what we should have |
|
849 | + $QSG_systems = array(1, 2); |
|
850 | + // loop thru what we should have and compare to what we have |
|
851 | + foreach ($QSG_systems as $QSG_system) { |
|
852 | + // reset values array |
|
853 | + $QSG_values = array(); |
|
854 | + // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
855 | + if (! in_array("$QSG_system", $question_groups)) { |
|
856 | + // add it |
|
857 | + switch ($QSG_system) { |
|
858 | + case 1: |
|
859 | + $QSG_values = array( |
|
860 | + 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
861 | + 'QSG_identifier' => 'personal-information-' . time(), |
|
862 | + 'QSG_desc' => '', |
|
863 | + 'QSG_order' => 1, |
|
864 | + 'QSG_show_group_name' => 1, |
|
865 | + 'QSG_show_group_desc' => 1, |
|
866 | + 'QSG_system' => EEM_Question_Group::system_personal, |
|
867 | + 'QSG_deleted' => 0, |
|
868 | + ); |
|
869 | + break; |
|
870 | + case 2: |
|
871 | + $QSG_values = array( |
|
872 | + 'QSG_name' => __('Address Information', 'event_espresso'), |
|
873 | + 'QSG_identifier' => 'address-information-' . time(), |
|
874 | + 'QSG_desc' => '', |
|
875 | + 'QSG_order' => 2, |
|
876 | + 'QSG_show_group_name' => 1, |
|
877 | + 'QSG_show_group_desc' => 1, |
|
878 | + 'QSG_system' => EEM_Question_Group::system_address, |
|
879 | + 'QSG_deleted' => 0, |
|
880 | + ); |
|
881 | + break; |
|
882 | + } |
|
883 | + // make sure we have some values before inserting them |
|
884 | + if (! empty($QSG_values)) { |
|
885 | + // insert system question |
|
886 | + $wpdb->insert( |
|
887 | + $table_name, |
|
888 | + $QSG_values, |
|
889 | + array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
890 | + ); |
|
891 | + $QSG_IDs[ $QSG_system ] = $wpdb->insert_id; |
|
892 | + } |
|
893 | + } |
|
894 | + } |
|
895 | + // QUESTIONS |
|
896 | + global $wpdb; |
|
897 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
898 | + $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
899 | + // what we have |
|
900 | + $questions = $wpdb->get_col($SQL); |
|
901 | + // what we should have |
|
902 | + $QST_systems = array( |
|
903 | + 'fname', |
|
904 | + 'lname', |
|
905 | + 'email', |
|
906 | + 'address', |
|
907 | + 'address2', |
|
908 | + 'city', |
|
909 | + 'country', |
|
910 | + 'state', |
|
911 | + 'zip', |
|
912 | + 'phone', |
|
913 | + ); |
|
914 | + $order_for_group_1 = 1; |
|
915 | + $order_for_group_2 = 1; |
|
916 | + // loop thru what we should have and compare to what we have |
|
917 | + foreach ($QST_systems as $QST_system) { |
|
918 | + // reset values array |
|
919 | + $QST_values = array(); |
|
920 | + // if we don't have what we should have |
|
921 | + if (! in_array($QST_system, $questions)) { |
|
922 | + // add it |
|
923 | + switch ($QST_system) { |
|
924 | + case 'fname': |
|
925 | + $QST_values = array( |
|
926 | + 'QST_display_text' => __('First Name', 'event_espresso'), |
|
927 | + 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
928 | + 'QST_system' => 'fname', |
|
929 | + 'QST_type' => 'TEXT', |
|
930 | + 'QST_required' => 1, |
|
931 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
932 | + 'QST_order' => 1, |
|
933 | + 'QST_admin_only' => 0, |
|
934 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
935 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
936 | + 'QST_deleted' => 0, |
|
937 | + ); |
|
938 | + break; |
|
939 | + case 'lname': |
|
940 | + $QST_values = array( |
|
941 | + 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
942 | + 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
943 | + 'QST_system' => 'lname', |
|
944 | + 'QST_type' => 'TEXT', |
|
945 | + 'QST_required' => 1, |
|
946 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
947 | + 'QST_order' => 2, |
|
948 | + 'QST_admin_only' => 0, |
|
949 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
950 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
951 | + 'QST_deleted' => 0, |
|
952 | + ); |
|
953 | + break; |
|
954 | + case 'email': |
|
955 | + $QST_values = array( |
|
956 | + 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
957 | + 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
958 | + 'QST_system' => 'email', |
|
959 | + 'QST_type' => 'EMAIL', |
|
960 | + 'QST_required' => 1, |
|
961 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
962 | + 'QST_order' => 3, |
|
963 | + 'QST_admin_only' => 0, |
|
964 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
965 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
966 | + 'QST_deleted' => 0, |
|
967 | + ); |
|
968 | + break; |
|
969 | + case 'address': |
|
970 | + $QST_values = array( |
|
971 | + 'QST_display_text' => __('Address', 'event_espresso'), |
|
972 | + 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
973 | + 'QST_system' => 'address', |
|
974 | + 'QST_type' => 'TEXT', |
|
975 | + 'QST_required' => 0, |
|
976 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
977 | + 'QST_order' => 4, |
|
978 | + 'QST_admin_only' => 0, |
|
979 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
980 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
981 | + 'QST_deleted' => 0, |
|
982 | + ); |
|
983 | + break; |
|
984 | + case 'address2': |
|
985 | + $QST_values = array( |
|
986 | + 'QST_display_text' => __('Address2', 'event_espresso'), |
|
987 | + 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
988 | + 'QST_system' => 'address2', |
|
989 | + 'QST_type' => 'TEXT', |
|
990 | + 'QST_required' => 0, |
|
991 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
992 | + 'QST_order' => 5, |
|
993 | + 'QST_admin_only' => 0, |
|
994 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
995 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
996 | + 'QST_deleted' => 0, |
|
997 | + ); |
|
998 | + break; |
|
999 | + case 'city': |
|
1000 | + $QST_values = array( |
|
1001 | + 'QST_display_text' => __('City', 'event_espresso'), |
|
1002 | + 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
1003 | + 'QST_system' => 'city', |
|
1004 | + 'QST_type' => 'TEXT', |
|
1005 | + 'QST_required' => 0, |
|
1006 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1007 | + 'QST_order' => 6, |
|
1008 | + 'QST_admin_only' => 0, |
|
1009 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1010 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1011 | + 'QST_deleted' => 0, |
|
1012 | + ); |
|
1013 | + break; |
|
1014 | + case 'country': |
|
1015 | + $QST_values = array( |
|
1016 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
1017 | + 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
1018 | + 'QST_system' => 'country', |
|
1019 | + 'QST_type' => 'COUNTRY', |
|
1020 | + 'QST_required' => 0, |
|
1021 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1022 | + 'QST_order' => 7, |
|
1023 | + 'QST_admin_only' => 0, |
|
1024 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1025 | + 'QST_deleted' => 0, |
|
1026 | + ); |
|
1027 | + break; |
|
1028 | + case 'state': |
|
1029 | + $QST_values = array( |
|
1030 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
1031 | + 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
1032 | + 'QST_system' => 'state', |
|
1033 | + 'QST_type' => 'STATE', |
|
1034 | + 'QST_required' => 0, |
|
1035 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1036 | + 'QST_order' => 8, |
|
1037 | + 'QST_admin_only' => 0, |
|
1038 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1039 | + 'QST_deleted' => 0, |
|
1040 | + ); |
|
1041 | + break; |
|
1042 | + case 'zip': |
|
1043 | + $QST_values = array( |
|
1044 | + 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
1045 | + 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
1046 | + 'QST_system' => 'zip', |
|
1047 | + 'QST_type' => 'TEXT', |
|
1048 | + 'QST_required' => 0, |
|
1049 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1050 | + 'QST_order' => 9, |
|
1051 | + 'QST_admin_only' => 0, |
|
1052 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1053 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1054 | + 'QST_deleted' => 0, |
|
1055 | + ); |
|
1056 | + break; |
|
1057 | + case 'phone': |
|
1058 | + $QST_values = array( |
|
1059 | + 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
1060 | + 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
1061 | + 'QST_system' => 'phone', |
|
1062 | + 'QST_type' => 'TEXT', |
|
1063 | + 'QST_required' => 0, |
|
1064 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1065 | + 'QST_order' => 10, |
|
1066 | + 'QST_admin_only' => 0, |
|
1067 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1068 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1069 | + 'QST_deleted' => 0, |
|
1070 | + ); |
|
1071 | + break; |
|
1072 | + } |
|
1073 | + if (! empty($QST_values)) { |
|
1074 | + // insert system question |
|
1075 | + $wpdb->insert( |
|
1076 | + $table_name, |
|
1077 | + $QST_values, |
|
1078 | + array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
1079 | + ); |
|
1080 | + $QST_ID = $wpdb->insert_id; |
|
1081 | + // QUESTION GROUP QUESTIONS |
|
1082 | + if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
1083 | + $system_question_we_want = EEM_Question_Group::system_personal; |
|
1084 | + } else { |
|
1085 | + $system_question_we_want = EEM_Question_Group::system_address; |
|
1086 | + } |
|
1087 | + if (isset($QSG_IDs[ $system_question_we_want ])) { |
|
1088 | + $QSG_ID = $QSG_IDs[ $system_question_we_want ]; |
|
1089 | + } else { |
|
1090 | + $id_col = EEM_Question_Group::instance() |
|
1091 | + ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
1092 | + if (is_array($id_col)) { |
|
1093 | + $QSG_ID = reset($id_col); |
|
1094 | + } else { |
|
1095 | + // ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
1096 | + EE_Log::instance()->log( |
|
1097 | + __FILE__, |
|
1098 | + __FUNCTION__, |
|
1099 | + sprintf( |
|
1100 | + __( |
|
1101 | + 'Could not associate question %1$s to a question group because no system question |
|
1102 | 1102 | group existed', |
1103 | - 'event_espresso' |
|
1104 | - ), |
|
1105 | - $QST_ID |
|
1106 | - ), |
|
1107 | - 'error' |
|
1108 | - ); |
|
1109 | - continue; |
|
1110 | - } |
|
1111 | - } |
|
1112 | - // add system questions to groups |
|
1113 | - $wpdb->insert( |
|
1114 | - \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
1115 | - array( |
|
1116 | - 'QSG_ID' => $QSG_ID, |
|
1117 | - 'QST_ID' => $QST_ID, |
|
1118 | - 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
1119 | - ), |
|
1120 | - array('%d', '%d', '%d') |
|
1121 | - ); |
|
1122 | - } |
|
1123 | - } |
|
1124 | - } |
|
1125 | - } |
|
1126 | - |
|
1127 | - |
|
1128 | - /** |
|
1129 | - * Makes sure the default payment method (Invoice) is active. |
|
1130 | - * This used to be done automatically as part of constructing the old gateways config |
|
1131 | - * |
|
1132 | - * @throws \EE_Error |
|
1133 | - */ |
|
1134 | - public static function insert_default_payment_methods() |
|
1135 | - { |
|
1136 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1137 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
1138 | - EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
1139 | - } else { |
|
1140 | - EEM_Payment_Method::instance()->verify_button_urls(); |
|
1141 | - } |
|
1142 | - } |
|
1143 | - |
|
1144 | - /** |
|
1145 | - * insert_default_status_codes |
|
1146 | - * |
|
1147 | - * @access public |
|
1148 | - * @static |
|
1149 | - * @return void |
|
1150 | - */ |
|
1151 | - public static function insert_default_status_codes() |
|
1152 | - { |
|
1153 | - |
|
1154 | - global $wpdb; |
|
1155 | - |
|
1156 | - if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
1157 | - $table_name = EEM_Status::instance()->table(); |
|
1158 | - |
|
1159 | - $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
1160 | - $wpdb->query($SQL); |
|
1161 | - |
|
1162 | - $SQL = "INSERT INTO $table_name |
|
1103 | + 'event_espresso' |
|
1104 | + ), |
|
1105 | + $QST_ID |
|
1106 | + ), |
|
1107 | + 'error' |
|
1108 | + ); |
|
1109 | + continue; |
|
1110 | + } |
|
1111 | + } |
|
1112 | + // add system questions to groups |
|
1113 | + $wpdb->insert( |
|
1114 | + \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
1115 | + array( |
|
1116 | + 'QSG_ID' => $QSG_ID, |
|
1117 | + 'QST_ID' => $QST_ID, |
|
1118 | + 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
1119 | + ), |
|
1120 | + array('%d', '%d', '%d') |
|
1121 | + ); |
|
1122 | + } |
|
1123 | + } |
|
1124 | + } |
|
1125 | + } |
|
1126 | + |
|
1127 | + |
|
1128 | + /** |
|
1129 | + * Makes sure the default payment method (Invoice) is active. |
|
1130 | + * This used to be done automatically as part of constructing the old gateways config |
|
1131 | + * |
|
1132 | + * @throws \EE_Error |
|
1133 | + */ |
|
1134 | + public static function insert_default_payment_methods() |
|
1135 | + { |
|
1136 | + if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1137 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
1138 | + EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
1139 | + } else { |
|
1140 | + EEM_Payment_Method::instance()->verify_button_urls(); |
|
1141 | + } |
|
1142 | + } |
|
1143 | + |
|
1144 | + /** |
|
1145 | + * insert_default_status_codes |
|
1146 | + * |
|
1147 | + * @access public |
|
1148 | + * @static |
|
1149 | + * @return void |
|
1150 | + */ |
|
1151 | + public static function insert_default_status_codes() |
|
1152 | + { |
|
1153 | + |
|
1154 | + global $wpdb; |
|
1155 | + |
|
1156 | + if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
1157 | + $table_name = EEM_Status::instance()->table(); |
|
1158 | + |
|
1159 | + $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
1160 | + $wpdb->query($SQL); |
|
1161 | + |
|
1162 | + $SQL = "INSERT INTO $table_name |
|
1163 | 1163 | (STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES |
1164 | 1164 | ('ACT', 'ACTIVE', 'event', 0, NULL, 1), |
1165 | 1165 | ('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0), |
@@ -1199,457 +1199,457 @@ discard block |
||
1199 | 1199 | ('MID', 'IDLE', 'message', 0, NULL, 1), |
1200 | 1200 | ('MRS', 'RESEND', 'message', 0, NULL, 1), |
1201 | 1201 | ('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);"; |
1202 | - $wpdb->query($SQL); |
|
1203 | - } |
|
1204 | - } |
|
1205 | - |
|
1206 | - |
|
1207 | - /** |
|
1208 | - * generate_default_message_templates |
|
1209 | - * |
|
1210 | - * @static |
|
1211 | - * @throws EE_Error |
|
1212 | - * @return bool true means new templates were created. |
|
1213 | - * false means no templates were created. |
|
1214 | - * This is NOT an error flag. To check for errors you will want |
|
1215 | - * to use either EE_Error or a try catch for an EE_Error exception. |
|
1216 | - */ |
|
1217 | - public static function generate_default_message_templates() |
|
1218 | - { |
|
1219 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1220 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1221 | - /* |
|
1202 | + $wpdb->query($SQL); |
|
1203 | + } |
|
1204 | + } |
|
1205 | + |
|
1206 | + |
|
1207 | + /** |
|
1208 | + * generate_default_message_templates |
|
1209 | + * |
|
1210 | + * @static |
|
1211 | + * @throws EE_Error |
|
1212 | + * @return bool true means new templates were created. |
|
1213 | + * false means no templates were created. |
|
1214 | + * This is NOT an error flag. To check for errors you will want |
|
1215 | + * to use either EE_Error or a try catch for an EE_Error exception. |
|
1216 | + */ |
|
1217 | + public static function generate_default_message_templates() |
|
1218 | + { |
|
1219 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1220 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1221 | + /* |
|
1222 | 1222 | * This first method is taking care of ensuring any default messengers |
1223 | 1223 | * that should be made active and have templates generated are done. |
1224 | 1224 | */ |
1225 | - $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
1226 | - $message_resource_manager |
|
1227 | - ); |
|
1228 | - /** |
|
1229 | - * This method is verifying there are no NEW default message types |
|
1230 | - * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
1231 | - */ |
|
1232 | - $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1233 | - $message_resource_manager |
|
1234 | - ); |
|
1235 | - // after all is done, let's persist these changes to the db. |
|
1236 | - $message_resource_manager->update_has_activated_messengers_option(); |
|
1237 | - $message_resource_manager->update_active_messengers_option(); |
|
1238 | - // will return true if either of these are true. Otherwise will return false. |
|
1239 | - return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
1240 | - } |
|
1241 | - |
|
1242 | - |
|
1243 | - |
|
1244 | - /** |
|
1245 | - * @param \EE_Message_Resource_Manager $message_resource_manager |
|
1246 | - * @return array|bool |
|
1247 | - * @throws \EE_Error |
|
1248 | - */ |
|
1249 | - protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1250 | - EE_Message_Resource_Manager $message_resource_manager |
|
1251 | - ) { |
|
1252 | - /** @type EE_messenger[] $active_messengers */ |
|
1253 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
1254 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1255 | - $templates_created = false; |
|
1256 | - foreach ($active_messengers as $active_messenger) { |
|
1257 | - $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
1258 | - $default_message_type_names_to_activate = array(); |
|
1259 | - // looping through each default message type reported by the messenger |
|
1260 | - // and setup the actual message types to activate. |
|
1261 | - foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
1262 | - // if already active or has already been activated before we skip |
|
1263 | - // (otherwise we might reactivate something user's intentionally deactivated.) |
|
1264 | - // we also skip if the message type is not installed. |
|
1265 | - if ($message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1266 | - $default_message_type_name_for_messenger, |
|
1267 | - $active_messenger->name |
|
1268 | - ) |
|
1269 | - || $message_resource_manager->is_message_type_active_for_messenger( |
|
1270 | - $active_messenger->name, |
|
1271 | - $default_message_type_name_for_messenger |
|
1272 | - ) |
|
1273 | - || ! isset($installed_message_types[ $default_message_type_name_for_messenger ]) |
|
1274 | - ) { |
|
1275 | - continue; |
|
1276 | - } |
|
1277 | - $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
1278 | - } |
|
1279 | - // let's activate! |
|
1280 | - $message_resource_manager->ensure_message_types_are_active( |
|
1281 | - $default_message_type_names_to_activate, |
|
1282 | - $active_messenger->name, |
|
1283 | - false |
|
1284 | - ); |
|
1285 | - // activate the templates for these message types |
|
1286 | - if (! empty($default_message_type_names_to_activate)) { |
|
1287 | - $templates_created = EEH_MSG_Template::generate_new_templates( |
|
1288 | - $active_messenger->name, |
|
1289 | - $default_message_type_names_for_messenger, |
|
1290 | - '', |
|
1291 | - true |
|
1292 | - ); |
|
1293 | - } |
|
1294 | - } |
|
1295 | - return $templates_created; |
|
1296 | - } |
|
1297 | - |
|
1298 | - |
|
1299 | - |
|
1300 | - /** |
|
1301 | - * This will activate and generate default messengers and default message types for those messengers. |
|
1302 | - * |
|
1303 | - * @param EE_message_Resource_Manager $message_resource_manager |
|
1304 | - * @return array|bool True means there were default messengers and message type templates generated. |
|
1305 | - * False means that there were no templates generated |
|
1306 | - * (which could simply mean there are no default message types for a messenger). |
|
1307 | - * @throws EE_Error |
|
1308 | - */ |
|
1309 | - protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
1310 | - EE_Message_Resource_Manager $message_resource_manager |
|
1311 | - ) { |
|
1312 | - /** @type EE_messenger[] $messengers_to_generate */ |
|
1313 | - $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
1314 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1315 | - $templates_generated = false; |
|
1316 | - foreach ($messengers_to_generate as $messenger_to_generate) { |
|
1317 | - $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
1318 | - // verify the default message types match an installed message type. |
|
1319 | - foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
1320 | - if (! isset($installed_message_types[ $name ]) |
|
1321 | - || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1322 | - $name, |
|
1323 | - $messenger_to_generate->name |
|
1324 | - ) |
|
1325 | - ) { |
|
1326 | - unset($default_message_type_names_for_messenger[ $key ]); |
|
1327 | - } |
|
1328 | - } |
|
1329 | - // in previous iterations, the active_messengers option in the db |
|
1330 | - // needed updated before calling create templates. however with the changes this may not be necessary. |
|
1331 | - // This comment is left here just in case we discover that we _do_ need to update before |
|
1332 | - // passing off to create templates (after the refactor is done). |
|
1333 | - // @todo remove this comment when determined not necessary. |
|
1334 | - $message_resource_manager->activate_messenger( |
|
1335 | - $messenger_to_generate->name, |
|
1336 | - $default_message_type_names_for_messenger, |
|
1337 | - false |
|
1338 | - ); |
|
1339 | - // create any templates needing created (or will reactivate templates already generated as necessary). |
|
1340 | - if (! empty($default_message_type_names_for_messenger)) { |
|
1341 | - $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
1342 | - $messenger_to_generate->name, |
|
1343 | - $default_message_type_names_for_messenger, |
|
1344 | - '', |
|
1345 | - true |
|
1346 | - ); |
|
1347 | - } |
|
1348 | - } |
|
1349 | - return $templates_generated; |
|
1350 | - } |
|
1351 | - |
|
1352 | - |
|
1353 | - /** |
|
1354 | - * This returns the default messengers to generate templates for on activation of EE. |
|
1355 | - * It considers: |
|
1356 | - * - whether a messenger is already active in the db. |
|
1357 | - * - whether a messenger has been made active at any time in the past. |
|
1358 | - * |
|
1359 | - * @static |
|
1360 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
1361 | - * @return EE_messenger[] |
|
1362 | - */ |
|
1363 | - protected static function _get_default_messengers_to_generate_on_activation( |
|
1364 | - EE_Message_Resource_Manager $message_resource_manager |
|
1365 | - ) { |
|
1366 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
1367 | - $installed_messengers = $message_resource_manager->installed_messengers(); |
|
1368 | - $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
1369 | - |
|
1370 | - $messengers_to_generate = array(); |
|
1371 | - foreach ($installed_messengers as $installed_messenger) { |
|
1372 | - // if installed messenger is a messenger that should be activated on install |
|
1373 | - // and is not already active |
|
1374 | - // and has never been activated |
|
1375 | - if (! $installed_messenger->activate_on_install |
|
1376 | - || isset($active_messengers[ $installed_messenger->name ]) |
|
1377 | - || isset($has_activated[ $installed_messenger->name ]) |
|
1378 | - ) { |
|
1379 | - continue; |
|
1380 | - } |
|
1381 | - $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger; |
|
1382 | - } |
|
1383 | - return $messengers_to_generate; |
|
1384 | - } |
|
1385 | - |
|
1386 | - |
|
1387 | - /** |
|
1388 | - * This simply validates active message types to ensure they actually match installed |
|
1389 | - * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
1390 | - * rows are set inactive. |
|
1391 | - * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
1392 | - * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
1393 | - * are still handled in here. |
|
1394 | - * |
|
1395 | - * @since 4.3.1 |
|
1396 | - * @return void |
|
1397 | - */ |
|
1398 | - public static function validate_messages_system() |
|
1399 | - { |
|
1400 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1401 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1402 | - $message_resource_manager->validate_active_message_types_are_installed(); |
|
1403 | - do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
1404 | - } |
|
1405 | - |
|
1406 | - |
|
1407 | - /** |
|
1408 | - * create_no_ticket_prices_array |
|
1409 | - * |
|
1410 | - * @access public |
|
1411 | - * @static |
|
1412 | - * @return void |
|
1413 | - */ |
|
1414 | - public static function create_no_ticket_prices_array() |
|
1415 | - { |
|
1416 | - // this creates an array for tracking events that have no active ticket prices created |
|
1417 | - // this allows us to warn admins of the situation so that it can be corrected |
|
1418 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
1419 | - if (! $espresso_no_ticket_prices) { |
|
1420 | - add_option('ee_no_ticket_prices', array(), '', false); |
|
1421 | - } |
|
1422 | - } |
|
1423 | - |
|
1424 | - |
|
1425 | - /** |
|
1426 | - * plugin_deactivation |
|
1427 | - * |
|
1428 | - * @access public |
|
1429 | - * @static |
|
1430 | - * @return void |
|
1431 | - */ |
|
1432 | - public static function plugin_deactivation() |
|
1433 | - { |
|
1434 | - } |
|
1435 | - |
|
1436 | - |
|
1437 | - /** |
|
1438 | - * Finds all our EE4 custom post types, and deletes them and their associated data |
|
1439 | - * (like post meta or term relations) |
|
1440 | - * |
|
1441 | - * @global wpdb $wpdb |
|
1442 | - * @throws \EE_Error |
|
1443 | - */ |
|
1444 | - public static function delete_all_espresso_cpt_data() |
|
1445 | - { |
|
1446 | - global $wpdb; |
|
1447 | - // get all the CPT post_types |
|
1448 | - $ee_post_types = array(); |
|
1449 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1450 | - if (method_exists($model_name, 'instance')) { |
|
1451 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
1452 | - if ($model_obj instanceof EEM_CPT_Base) { |
|
1453 | - $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
1454 | - } |
|
1455 | - } |
|
1456 | - } |
|
1457 | - // get all our CPTs |
|
1458 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1459 | - $cpt_ids = $wpdb->get_col($query); |
|
1460 | - // delete each post meta and term relations too |
|
1461 | - foreach ($cpt_ids as $post_id) { |
|
1462 | - wp_delete_post($post_id, true); |
|
1463 | - } |
|
1464 | - } |
|
1465 | - |
|
1466 | - /** |
|
1467 | - * Deletes all EE custom tables |
|
1468 | - * |
|
1469 | - * @return array |
|
1470 | - */ |
|
1471 | - public static function drop_espresso_tables() |
|
1472 | - { |
|
1473 | - $tables = array(); |
|
1474 | - // load registry |
|
1475 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1476 | - if (method_exists($model_name, 'instance')) { |
|
1477 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
1478 | - if ($model_obj instanceof EEM_Base) { |
|
1479 | - foreach ($model_obj->get_tables() as $table) { |
|
1480 | - if (strpos($table->get_table_name(), 'esp_') |
|
1481 | - && |
|
1482 | - ( |
|
1483 | - is_main_site()// main site? nuke them all |
|
1484 | - || ! $table->is_global()// not main site,but not global either. nuke it |
|
1485 | - ) |
|
1486 | - ) { |
|
1487 | - $tables[ $table->get_table_name() ] = $table->get_table_name(); |
|
1488 | - } |
|
1489 | - } |
|
1490 | - } |
|
1491 | - } |
|
1492 | - } |
|
1493 | - |
|
1494 | - // there are some tables whose models were removed. |
|
1495 | - // they should be removed when removing all EE core's data |
|
1496 | - $tables_without_models = array( |
|
1497 | - 'esp_promotion', |
|
1498 | - 'esp_promotion_applied', |
|
1499 | - 'esp_promotion_object', |
|
1500 | - 'esp_promotion_rule', |
|
1501 | - 'esp_rule', |
|
1502 | - ); |
|
1503 | - foreach ($tables_without_models as $table) { |
|
1504 | - $tables[ $table ] = $table; |
|
1505 | - } |
|
1506 | - return \EEH_Activation::getTableManager()->dropTables($tables); |
|
1507 | - } |
|
1508 | - |
|
1509 | - |
|
1510 | - |
|
1511 | - /** |
|
1512 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
1513 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
1514 | - * Returns the list actually deleted |
|
1515 | - * |
|
1516 | - * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
1517 | - * @global WPDB $wpdb |
|
1518 | - * @param array $table_names |
|
1519 | - * @return array of table names which we deleted |
|
1520 | - */ |
|
1521 | - public static function drop_tables($table_names) |
|
1522 | - { |
|
1523 | - return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
1524 | - } |
|
1525 | - |
|
1526 | - |
|
1527 | - |
|
1528 | - /** |
|
1529 | - * plugin_uninstall |
|
1530 | - * |
|
1531 | - * @access public |
|
1532 | - * @static |
|
1533 | - * @param bool $remove_all |
|
1534 | - * @return void |
|
1535 | - */ |
|
1536 | - public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
1537 | - { |
|
1538 | - global $wpdb; |
|
1539 | - self::drop_espresso_tables(); |
|
1540 | - $wp_options_to_delete = array( |
|
1541 | - 'ee_no_ticket_prices' => true, |
|
1542 | - 'ee_active_messengers' => true, |
|
1543 | - 'ee_has_activated_messenger' => true, |
|
1544 | - RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true, |
|
1545 | - 'ee_config' => false, |
|
1546 | - 'ee_data_migration_current_db_state' => true, |
|
1547 | - 'ee_data_migration_mapping_' => false, |
|
1548 | - 'ee_data_migration_script_' => false, |
|
1549 | - 'ee_data_migrations' => true, |
|
1550 | - 'ee_dms_map' => false, |
|
1551 | - 'ee_notices' => true, |
|
1552 | - 'lang_file_check_' => false, |
|
1553 | - 'ee_maintenance_mode' => true, |
|
1554 | - 'ee_ueip_optin' => true, |
|
1555 | - 'ee_ueip_has_notified' => true, |
|
1556 | - 'ee_plugin_activation_errors' => true, |
|
1557 | - 'ee_id_mapping_from' => false, |
|
1558 | - 'espresso_persistent_admin_notices' => true, |
|
1559 | - 'ee_encryption_key' => true, |
|
1560 | - 'pue_force_upgrade_' => false, |
|
1561 | - 'pue_json_error_' => false, |
|
1562 | - 'pue_install_key_' => false, |
|
1563 | - 'pue_verification_error_' => false, |
|
1564 | - 'pu_dismissed_upgrade_' => false, |
|
1565 | - 'external_updates-' => false, |
|
1566 | - 'ee_extra_data' => true, |
|
1567 | - 'ee_ssn_' => false, |
|
1568 | - 'ee_rss_' => false, |
|
1569 | - 'ee_rte_n_tx_' => false, |
|
1570 | - 'ee_pers_admin_notices' => true, |
|
1571 | - 'ee_job_parameters_' => false, |
|
1572 | - 'ee_upload_directories_incomplete' => true, |
|
1573 | - 'ee_verified_db_collations' => true, |
|
1574 | - ); |
|
1575 | - if (is_main_site()) { |
|
1576 | - $wp_options_to_delete['ee_network_config'] = true; |
|
1577 | - } |
|
1578 | - $undeleted_options = array(); |
|
1579 | - foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
1580 | - if ($no_wildcard) { |
|
1581 | - if (! delete_option($option_name)) { |
|
1582 | - $undeleted_options[] = $option_name; |
|
1583 | - } |
|
1584 | - } else { |
|
1585 | - $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
1586 | - foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
1587 | - if (! delete_option($option_name_from_wildcard)) { |
|
1588 | - $undeleted_options[] = $option_name_from_wildcard; |
|
1589 | - } |
|
1590 | - } |
|
1591 | - } |
|
1592 | - } |
|
1593 | - // also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
1594 | - remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
1595 | - if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
1596 | - $db_update_sans_ee4 = array(); |
|
1597 | - foreach ($espresso_db_update as $version => $times_activated) { |
|
1598 | - if ((string) $version[0] === '3') {// if its NON EE4 |
|
1599 | - $db_update_sans_ee4[ $version ] = $times_activated; |
|
1600 | - } |
|
1601 | - } |
|
1602 | - update_option('espresso_db_update', $db_update_sans_ee4); |
|
1603 | - } |
|
1604 | - $errors = ''; |
|
1605 | - if (! empty($undeleted_options)) { |
|
1606 | - $errors .= sprintf( |
|
1607 | - __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
1608 | - '<br/>', |
|
1609 | - implode(',<br/>', $undeleted_options) |
|
1610 | - ); |
|
1611 | - } |
|
1612 | - if (! empty($errors)) { |
|
1613 | - EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
1614 | - } |
|
1615 | - } |
|
1616 | - |
|
1617 | - /** |
|
1618 | - * Gets the mysql error code from the last used query by wpdb |
|
1619 | - * |
|
1620 | - * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
1621 | - */ |
|
1622 | - public static function last_wpdb_error_code() |
|
1623 | - { |
|
1624 | - // phpcs:disable PHPCompatibility.PHP.RemovedExtensions.mysql_DeprecatedRemoved |
|
1625 | - global $wpdb; |
|
1626 | - if ($wpdb->use_mysqli) { |
|
1627 | - return mysqli_errno($wpdb->dbh); |
|
1628 | - } else { |
|
1629 | - return mysql_errno($wpdb->dbh); |
|
1630 | - } |
|
1631 | - // phpcs:enable |
|
1632 | - } |
|
1633 | - |
|
1634 | - /** |
|
1635 | - * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
1636 | - * |
|
1637 | - * @global wpdb $wpdb |
|
1638 | - * @deprecated instead use TableAnalysis::tableExists() |
|
1639 | - * @param string $table_name with or without $wpdb->prefix |
|
1640 | - * @return boolean |
|
1641 | - */ |
|
1642 | - public static function table_exists($table_name) |
|
1643 | - { |
|
1644 | - return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
1645 | - } |
|
1646 | - |
|
1647 | - /** |
|
1648 | - * Resets the cache on EEH_Activation |
|
1649 | - */ |
|
1650 | - public static function reset() |
|
1651 | - { |
|
1652 | - self::$_default_creator_id = null; |
|
1653 | - self::$_initialized_db_content_already_in_this_request = false; |
|
1654 | - } |
|
1225 | + $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
1226 | + $message_resource_manager |
|
1227 | + ); |
|
1228 | + /** |
|
1229 | + * This method is verifying there are no NEW default message types |
|
1230 | + * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
1231 | + */ |
|
1232 | + $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1233 | + $message_resource_manager |
|
1234 | + ); |
|
1235 | + // after all is done, let's persist these changes to the db. |
|
1236 | + $message_resource_manager->update_has_activated_messengers_option(); |
|
1237 | + $message_resource_manager->update_active_messengers_option(); |
|
1238 | + // will return true if either of these are true. Otherwise will return false. |
|
1239 | + return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
1240 | + } |
|
1241 | + |
|
1242 | + |
|
1243 | + |
|
1244 | + /** |
|
1245 | + * @param \EE_Message_Resource_Manager $message_resource_manager |
|
1246 | + * @return array|bool |
|
1247 | + * @throws \EE_Error |
|
1248 | + */ |
|
1249 | + protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1250 | + EE_Message_Resource_Manager $message_resource_manager |
|
1251 | + ) { |
|
1252 | + /** @type EE_messenger[] $active_messengers */ |
|
1253 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
1254 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1255 | + $templates_created = false; |
|
1256 | + foreach ($active_messengers as $active_messenger) { |
|
1257 | + $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
1258 | + $default_message_type_names_to_activate = array(); |
|
1259 | + // looping through each default message type reported by the messenger |
|
1260 | + // and setup the actual message types to activate. |
|
1261 | + foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
1262 | + // if already active or has already been activated before we skip |
|
1263 | + // (otherwise we might reactivate something user's intentionally deactivated.) |
|
1264 | + // we also skip if the message type is not installed. |
|
1265 | + if ($message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1266 | + $default_message_type_name_for_messenger, |
|
1267 | + $active_messenger->name |
|
1268 | + ) |
|
1269 | + || $message_resource_manager->is_message_type_active_for_messenger( |
|
1270 | + $active_messenger->name, |
|
1271 | + $default_message_type_name_for_messenger |
|
1272 | + ) |
|
1273 | + || ! isset($installed_message_types[ $default_message_type_name_for_messenger ]) |
|
1274 | + ) { |
|
1275 | + continue; |
|
1276 | + } |
|
1277 | + $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
1278 | + } |
|
1279 | + // let's activate! |
|
1280 | + $message_resource_manager->ensure_message_types_are_active( |
|
1281 | + $default_message_type_names_to_activate, |
|
1282 | + $active_messenger->name, |
|
1283 | + false |
|
1284 | + ); |
|
1285 | + // activate the templates for these message types |
|
1286 | + if (! empty($default_message_type_names_to_activate)) { |
|
1287 | + $templates_created = EEH_MSG_Template::generate_new_templates( |
|
1288 | + $active_messenger->name, |
|
1289 | + $default_message_type_names_for_messenger, |
|
1290 | + '', |
|
1291 | + true |
|
1292 | + ); |
|
1293 | + } |
|
1294 | + } |
|
1295 | + return $templates_created; |
|
1296 | + } |
|
1297 | + |
|
1298 | + |
|
1299 | + |
|
1300 | + /** |
|
1301 | + * This will activate and generate default messengers and default message types for those messengers. |
|
1302 | + * |
|
1303 | + * @param EE_message_Resource_Manager $message_resource_manager |
|
1304 | + * @return array|bool True means there were default messengers and message type templates generated. |
|
1305 | + * False means that there were no templates generated |
|
1306 | + * (which could simply mean there are no default message types for a messenger). |
|
1307 | + * @throws EE_Error |
|
1308 | + */ |
|
1309 | + protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
1310 | + EE_Message_Resource_Manager $message_resource_manager |
|
1311 | + ) { |
|
1312 | + /** @type EE_messenger[] $messengers_to_generate */ |
|
1313 | + $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
1314 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1315 | + $templates_generated = false; |
|
1316 | + foreach ($messengers_to_generate as $messenger_to_generate) { |
|
1317 | + $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
1318 | + // verify the default message types match an installed message type. |
|
1319 | + foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
1320 | + if (! isset($installed_message_types[ $name ]) |
|
1321 | + || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1322 | + $name, |
|
1323 | + $messenger_to_generate->name |
|
1324 | + ) |
|
1325 | + ) { |
|
1326 | + unset($default_message_type_names_for_messenger[ $key ]); |
|
1327 | + } |
|
1328 | + } |
|
1329 | + // in previous iterations, the active_messengers option in the db |
|
1330 | + // needed updated before calling create templates. however with the changes this may not be necessary. |
|
1331 | + // This comment is left here just in case we discover that we _do_ need to update before |
|
1332 | + // passing off to create templates (after the refactor is done). |
|
1333 | + // @todo remove this comment when determined not necessary. |
|
1334 | + $message_resource_manager->activate_messenger( |
|
1335 | + $messenger_to_generate->name, |
|
1336 | + $default_message_type_names_for_messenger, |
|
1337 | + false |
|
1338 | + ); |
|
1339 | + // create any templates needing created (or will reactivate templates already generated as necessary). |
|
1340 | + if (! empty($default_message_type_names_for_messenger)) { |
|
1341 | + $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
1342 | + $messenger_to_generate->name, |
|
1343 | + $default_message_type_names_for_messenger, |
|
1344 | + '', |
|
1345 | + true |
|
1346 | + ); |
|
1347 | + } |
|
1348 | + } |
|
1349 | + return $templates_generated; |
|
1350 | + } |
|
1351 | + |
|
1352 | + |
|
1353 | + /** |
|
1354 | + * This returns the default messengers to generate templates for on activation of EE. |
|
1355 | + * It considers: |
|
1356 | + * - whether a messenger is already active in the db. |
|
1357 | + * - whether a messenger has been made active at any time in the past. |
|
1358 | + * |
|
1359 | + * @static |
|
1360 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
1361 | + * @return EE_messenger[] |
|
1362 | + */ |
|
1363 | + protected static function _get_default_messengers_to_generate_on_activation( |
|
1364 | + EE_Message_Resource_Manager $message_resource_manager |
|
1365 | + ) { |
|
1366 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
1367 | + $installed_messengers = $message_resource_manager->installed_messengers(); |
|
1368 | + $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
1369 | + |
|
1370 | + $messengers_to_generate = array(); |
|
1371 | + foreach ($installed_messengers as $installed_messenger) { |
|
1372 | + // if installed messenger is a messenger that should be activated on install |
|
1373 | + // and is not already active |
|
1374 | + // and has never been activated |
|
1375 | + if (! $installed_messenger->activate_on_install |
|
1376 | + || isset($active_messengers[ $installed_messenger->name ]) |
|
1377 | + || isset($has_activated[ $installed_messenger->name ]) |
|
1378 | + ) { |
|
1379 | + continue; |
|
1380 | + } |
|
1381 | + $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger; |
|
1382 | + } |
|
1383 | + return $messengers_to_generate; |
|
1384 | + } |
|
1385 | + |
|
1386 | + |
|
1387 | + /** |
|
1388 | + * This simply validates active message types to ensure they actually match installed |
|
1389 | + * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
1390 | + * rows are set inactive. |
|
1391 | + * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
1392 | + * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
1393 | + * are still handled in here. |
|
1394 | + * |
|
1395 | + * @since 4.3.1 |
|
1396 | + * @return void |
|
1397 | + */ |
|
1398 | + public static function validate_messages_system() |
|
1399 | + { |
|
1400 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1401 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1402 | + $message_resource_manager->validate_active_message_types_are_installed(); |
|
1403 | + do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
1404 | + } |
|
1405 | + |
|
1406 | + |
|
1407 | + /** |
|
1408 | + * create_no_ticket_prices_array |
|
1409 | + * |
|
1410 | + * @access public |
|
1411 | + * @static |
|
1412 | + * @return void |
|
1413 | + */ |
|
1414 | + public static function create_no_ticket_prices_array() |
|
1415 | + { |
|
1416 | + // this creates an array for tracking events that have no active ticket prices created |
|
1417 | + // this allows us to warn admins of the situation so that it can be corrected |
|
1418 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
1419 | + if (! $espresso_no_ticket_prices) { |
|
1420 | + add_option('ee_no_ticket_prices', array(), '', false); |
|
1421 | + } |
|
1422 | + } |
|
1423 | + |
|
1424 | + |
|
1425 | + /** |
|
1426 | + * plugin_deactivation |
|
1427 | + * |
|
1428 | + * @access public |
|
1429 | + * @static |
|
1430 | + * @return void |
|
1431 | + */ |
|
1432 | + public static function plugin_deactivation() |
|
1433 | + { |
|
1434 | + } |
|
1435 | + |
|
1436 | + |
|
1437 | + /** |
|
1438 | + * Finds all our EE4 custom post types, and deletes them and their associated data |
|
1439 | + * (like post meta or term relations) |
|
1440 | + * |
|
1441 | + * @global wpdb $wpdb |
|
1442 | + * @throws \EE_Error |
|
1443 | + */ |
|
1444 | + public static function delete_all_espresso_cpt_data() |
|
1445 | + { |
|
1446 | + global $wpdb; |
|
1447 | + // get all the CPT post_types |
|
1448 | + $ee_post_types = array(); |
|
1449 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1450 | + if (method_exists($model_name, 'instance')) { |
|
1451 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
1452 | + if ($model_obj instanceof EEM_CPT_Base) { |
|
1453 | + $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
1454 | + } |
|
1455 | + } |
|
1456 | + } |
|
1457 | + // get all our CPTs |
|
1458 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1459 | + $cpt_ids = $wpdb->get_col($query); |
|
1460 | + // delete each post meta and term relations too |
|
1461 | + foreach ($cpt_ids as $post_id) { |
|
1462 | + wp_delete_post($post_id, true); |
|
1463 | + } |
|
1464 | + } |
|
1465 | + |
|
1466 | + /** |
|
1467 | + * Deletes all EE custom tables |
|
1468 | + * |
|
1469 | + * @return array |
|
1470 | + */ |
|
1471 | + public static function drop_espresso_tables() |
|
1472 | + { |
|
1473 | + $tables = array(); |
|
1474 | + // load registry |
|
1475 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1476 | + if (method_exists($model_name, 'instance')) { |
|
1477 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
1478 | + if ($model_obj instanceof EEM_Base) { |
|
1479 | + foreach ($model_obj->get_tables() as $table) { |
|
1480 | + if (strpos($table->get_table_name(), 'esp_') |
|
1481 | + && |
|
1482 | + ( |
|
1483 | + is_main_site()// main site? nuke them all |
|
1484 | + || ! $table->is_global()// not main site,but not global either. nuke it |
|
1485 | + ) |
|
1486 | + ) { |
|
1487 | + $tables[ $table->get_table_name() ] = $table->get_table_name(); |
|
1488 | + } |
|
1489 | + } |
|
1490 | + } |
|
1491 | + } |
|
1492 | + } |
|
1493 | + |
|
1494 | + // there are some tables whose models were removed. |
|
1495 | + // they should be removed when removing all EE core's data |
|
1496 | + $tables_without_models = array( |
|
1497 | + 'esp_promotion', |
|
1498 | + 'esp_promotion_applied', |
|
1499 | + 'esp_promotion_object', |
|
1500 | + 'esp_promotion_rule', |
|
1501 | + 'esp_rule', |
|
1502 | + ); |
|
1503 | + foreach ($tables_without_models as $table) { |
|
1504 | + $tables[ $table ] = $table; |
|
1505 | + } |
|
1506 | + return \EEH_Activation::getTableManager()->dropTables($tables); |
|
1507 | + } |
|
1508 | + |
|
1509 | + |
|
1510 | + |
|
1511 | + /** |
|
1512 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
1513 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
1514 | + * Returns the list actually deleted |
|
1515 | + * |
|
1516 | + * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
1517 | + * @global WPDB $wpdb |
|
1518 | + * @param array $table_names |
|
1519 | + * @return array of table names which we deleted |
|
1520 | + */ |
|
1521 | + public static function drop_tables($table_names) |
|
1522 | + { |
|
1523 | + return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
1524 | + } |
|
1525 | + |
|
1526 | + |
|
1527 | + |
|
1528 | + /** |
|
1529 | + * plugin_uninstall |
|
1530 | + * |
|
1531 | + * @access public |
|
1532 | + * @static |
|
1533 | + * @param bool $remove_all |
|
1534 | + * @return void |
|
1535 | + */ |
|
1536 | + public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
1537 | + { |
|
1538 | + global $wpdb; |
|
1539 | + self::drop_espresso_tables(); |
|
1540 | + $wp_options_to_delete = array( |
|
1541 | + 'ee_no_ticket_prices' => true, |
|
1542 | + 'ee_active_messengers' => true, |
|
1543 | + 'ee_has_activated_messenger' => true, |
|
1544 | + RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true, |
|
1545 | + 'ee_config' => false, |
|
1546 | + 'ee_data_migration_current_db_state' => true, |
|
1547 | + 'ee_data_migration_mapping_' => false, |
|
1548 | + 'ee_data_migration_script_' => false, |
|
1549 | + 'ee_data_migrations' => true, |
|
1550 | + 'ee_dms_map' => false, |
|
1551 | + 'ee_notices' => true, |
|
1552 | + 'lang_file_check_' => false, |
|
1553 | + 'ee_maintenance_mode' => true, |
|
1554 | + 'ee_ueip_optin' => true, |
|
1555 | + 'ee_ueip_has_notified' => true, |
|
1556 | + 'ee_plugin_activation_errors' => true, |
|
1557 | + 'ee_id_mapping_from' => false, |
|
1558 | + 'espresso_persistent_admin_notices' => true, |
|
1559 | + 'ee_encryption_key' => true, |
|
1560 | + 'pue_force_upgrade_' => false, |
|
1561 | + 'pue_json_error_' => false, |
|
1562 | + 'pue_install_key_' => false, |
|
1563 | + 'pue_verification_error_' => false, |
|
1564 | + 'pu_dismissed_upgrade_' => false, |
|
1565 | + 'external_updates-' => false, |
|
1566 | + 'ee_extra_data' => true, |
|
1567 | + 'ee_ssn_' => false, |
|
1568 | + 'ee_rss_' => false, |
|
1569 | + 'ee_rte_n_tx_' => false, |
|
1570 | + 'ee_pers_admin_notices' => true, |
|
1571 | + 'ee_job_parameters_' => false, |
|
1572 | + 'ee_upload_directories_incomplete' => true, |
|
1573 | + 'ee_verified_db_collations' => true, |
|
1574 | + ); |
|
1575 | + if (is_main_site()) { |
|
1576 | + $wp_options_to_delete['ee_network_config'] = true; |
|
1577 | + } |
|
1578 | + $undeleted_options = array(); |
|
1579 | + foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
1580 | + if ($no_wildcard) { |
|
1581 | + if (! delete_option($option_name)) { |
|
1582 | + $undeleted_options[] = $option_name; |
|
1583 | + } |
|
1584 | + } else { |
|
1585 | + $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
1586 | + foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
1587 | + if (! delete_option($option_name_from_wildcard)) { |
|
1588 | + $undeleted_options[] = $option_name_from_wildcard; |
|
1589 | + } |
|
1590 | + } |
|
1591 | + } |
|
1592 | + } |
|
1593 | + // also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
1594 | + remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
1595 | + if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
1596 | + $db_update_sans_ee4 = array(); |
|
1597 | + foreach ($espresso_db_update as $version => $times_activated) { |
|
1598 | + if ((string) $version[0] === '3') {// if its NON EE4 |
|
1599 | + $db_update_sans_ee4[ $version ] = $times_activated; |
|
1600 | + } |
|
1601 | + } |
|
1602 | + update_option('espresso_db_update', $db_update_sans_ee4); |
|
1603 | + } |
|
1604 | + $errors = ''; |
|
1605 | + if (! empty($undeleted_options)) { |
|
1606 | + $errors .= sprintf( |
|
1607 | + __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
1608 | + '<br/>', |
|
1609 | + implode(',<br/>', $undeleted_options) |
|
1610 | + ); |
|
1611 | + } |
|
1612 | + if (! empty($errors)) { |
|
1613 | + EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
1614 | + } |
|
1615 | + } |
|
1616 | + |
|
1617 | + /** |
|
1618 | + * Gets the mysql error code from the last used query by wpdb |
|
1619 | + * |
|
1620 | + * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
1621 | + */ |
|
1622 | + public static function last_wpdb_error_code() |
|
1623 | + { |
|
1624 | + // phpcs:disable PHPCompatibility.PHP.RemovedExtensions.mysql_DeprecatedRemoved |
|
1625 | + global $wpdb; |
|
1626 | + if ($wpdb->use_mysqli) { |
|
1627 | + return mysqli_errno($wpdb->dbh); |
|
1628 | + } else { |
|
1629 | + return mysql_errno($wpdb->dbh); |
|
1630 | + } |
|
1631 | + // phpcs:enable |
|
1632 | + } |
|
1633 | + |
|
1634 | + /** |
|
1635 | + * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
1636 | + * |
|
1637 | + * @global wpdb $wpdb |
|
1638 | + * @deprecated instead use TableAnalysis::tableExists() |
|
1639 | + * @param string $table_name with or without $wpdb->prefix |
|
1640 | + * @return boolean |
|
1641 | + */ |
|
1642 | + public static function table_exists($table_name) |
|
1643 | + { |
|
1644 | + return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
1645 | + } |
|
1646 | + |
|
1647 | + /** |
|
1648 | + * Resets the cache on EEH_Activation |
|
1649 | + */ |
|
1650 | + public static function reset() |
|
1651 | + { |
|
1652 | + self::$_default_creator_id = null; |
|
1653 | + self::$_initialized_db_content_already_in_this_request = false; |
|
1654 | + } |
|
1655 | 1655 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public static function getTableAnalysis() |
56 | 56 | { |
57 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
57 | + if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
58 | 58 | self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
59 | 59 | } |
60 | 60 | return self::$table_analysis; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public static function getTableManager() |
68 | 68 | { |
69 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
69 | + if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
70 | 70 | self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
71 | 71 | } |
72 | 72 | return self::$table_manager; |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | if ($which_to_include === 'old') { |
181 | 181 | $cron_tasks = array_filter( |
182 | 182 | $cron_tasks, |
183 | - function ($value) { |
|
183 | + function($value) { |
|
184 | 184 | return $value === EEH_Activation::cron_task_no_longer_in_use; |
185 | 185 | } |
186 | 186 | ); |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | { |
211 | 211 | |
212 | 212 | foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
213 | - if (! wp_next_scheduled($hook_name)) { |
|
213 | + if ( ! wp_next_scheduled($hook_name)) { |
|
214 | 214 | /** |
215 | 215 | * This allows client code to define the initial start timestamp for this schedule. |
216 | 216 | */ |
@@ -261,15 +261,15 @@ discard block |
||
261 | 261 | foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
262 | 262 | if (is_array($hooks_to_fire_at_time)) { |
263 | 263 | foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
264 | - if (isset($ee_cron_tasks_to_remove[ $hook_name ]) |
|
265 | - && is_array($ee_cron_tasks_to_remove[ $hook_name ]) |
|
264 | + if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
265 | + && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
266 | 266 | ) { |
267 | - unset($crons[ $timestamp ][ $hook_name ]); |
|
267 | + unset($crons[$timestamp][$hook_name]); |
|
268 | 268 | } |
269 | 269 | } |
270 | 270 | // also take care of any empty cron timestamps. |
271 | 271 | if (empty($hooks_to_fire_at_time)) { |
272 | - unset($crons[ $timestamp ]); |
|
272 | + unset($crons[$timestamp]); |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | } |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | 3 |
315 | 315 | ); |
316 | 316 | // EE_Config::reset(); |
317 | - if (! EE_Config::logging_enabled()) { |
|
317 | + if ( ! EE_Config::logging_enabled()) { |
|
318 | 318 | delete_option(EE_Config::LOG_NAME); |
319 | 319 | } |
320 | 320 | } |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | public static function load_calendar_config() |
330 | 330 | { |
331 | 331 | // grab array of all plugin folders and loop thru it |
332 | - $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR); |
|
332 | + $plugins = glob(WP_PLUGIN_DIR.'/*', GLOB_ONLYDIR); |
|
333 | 333 | if (empty($plugins)) { |
334 | 334 | return; |
335 | 335 | } |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | || strpos($plugin, 'calendar') !== false |
346 | 346 | ) { |
347 | 347 | // this is what we are looking for |
348 | - $calendar_config = $plugin_path . '/EE_Calendar_Config.php'; |
|
348 | + $calendar_config = $plugin_path.'/EE_Calendar_Config.php'; |
|
349 | 349 | // does it exist in this folder ? |
350 | 350 | if (is_readable($calendar_config)) { |
351 | 351 | // YEAH! let's load it |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | ) { |
473 | 473 | // update Config with post ID |
474 | 474 | $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
475 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
475 | + if ( ! EE_Config::instance()->update_espresso_config(false, false)) { |
|
476 | 476 | $msg = __( |
477 | 477 | 'The Event Espresso critical page configuration settings could not be updated.', |
478 | 478 | 'event_espresso' |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
496 | 496 | 'event_espresso' |
497 | 497 | ), |
498 | - '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
498 | + '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">' |
|
499 | 499 | . __('Event Espresso Critical Pages Settings', 'event_espresso') |
500 | 500 | . '</a>' |
501 | 501 | ) |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | public static function get_page_by_ee_shortcode($ee_shortcode) |
522 | 522 | { |
523 | 523 | global $wpdb; |
524 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
524 | + $shortcode_and_opening_bracket = '['.$ee_shortcode; |
|
525 | 525 | $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
526 | 526 | if ($post_id) { |
527 | 527 | return get_post($post_id); |
@@ -547,11 +547,11 @@ discard block |
||
547 | 547 | 'post_status' => 'publish', |
548 | 548 | 'post_type' => 'page', |
549 | 549 | 'comment_status' => 'closed', |
550 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
550 | + 'post_content' => '['.$critical_page['code'].']', |
|
551 | 551 | ); |
552 | 552 | |
553 | 553 | $post_id = wp_insert_post($post_args); |
554 | - if (! $post_id) { |
|
554 | + if ( ! $post_id) { |
|
555 | 555 | $msg = sprintf( |
556 | 556 | __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
557 | 557 | $critical_page['name'] |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | return $critical_page; |
561 | 561 | } |
562 | 562 | // get newly created post's details |
563 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
563 | + if ( ! $critical_page['post'] = get_post($post_id)) { |
|
564 | 564 | $msg = sprintf( |
565 | 565 | __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
566 | 566 | $critical_page['name'] |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | public static function get_default_creator_id() |
586 | 586 | { |
587 | 587 | global $wpdb; |
588 | - if (! empty(self::$_default_creator_id)) { |
|
588 | + if ( ! empty(self::$_default_creator_id)) { |
|
589 | 589 | return self::$_default_creator_id; |
590 | 590 | }/**/ |
591 | 591 | $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
602 | 602 | $query = $wpdb->prepare( |
603 | 603 | "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
604 | - '%' . $role_to_check . '%' |
|
604 | + '%'.$role_to_check.'%' |
|
605 | 605 | ); |
606 | 606 | $user_id = $wpdb->get_var($query); |
607 | 607 | $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
@@ -640,8 +640,8 @@ discard block |
||
640 | 640 | return; |
641 | 641 | } |
642 | 642 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
643 | - if (! function_exists('dbDelta')) { |
|
644 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
643 | + if ( ! function_exists('dbDelta')) { |
|
644 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
645 | 645 | } |
646 | 646 | $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
647 | 647 | $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
@@ -650,9 +650,9 @@ discard block |
||
650 | 650 | // ok, delete the table... but ONLY if it's empty |
651 | 651 | $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
652 | 652 | // table is NOT empty, are you SURE you want to delete this table ??? |
653 | - if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
653 | + if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
654 | 654 | \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
655 | - } elseif (! $deleted_safely) { |
|
655 | + } elseif ( ! $deleted_safely) { |
|
656 | 656 | // so we should be more cautious rather than just dropping tables so easily |
657 | 657 | error_log( |
658 | 658 | sprintf( |
@@ -852,13 +852,13 @@ discard block |
||
852 | 852 | // reset values array |
853 | 853 | $QSG_values = array(); |
854 | 854 | // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
855 | - if (! in_array("$QSG_system", $question_groups)) { |
|
855 | + if ( ! in_array("$QSG_system", $question_groups)) { |
|
856 | 856 | // add it |
857 | 857 | switch ($QSG_system) { |
858 | 858 | case 1: |
859 | 859 | $QSG_values = array( |
860 | 860 | 'QSG_name' => __('Personal Information', 'event_espresso'), |
861 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
861 | + 'QSG_identifier' => 'personal-information-'.time(), |
|
862 | 862 | 'QSG_desc' => '', |
863 | 863 | 'QSG_order' => 1, |
864 | 864 | 'QSG_show_group_name' => 1, |
@@ -870,7 +870,7 @@ discard block |
||
870 | 870 | case 2: |
871 | 871 | $QSG_values = array( |
872 | 872 | 'QSG_name' => __('Address Information', 'event_espresso'), |
873 | - 'QSG_identifier' => 'address-information-' . time(), |
|
873 | + 'QSG_identifier' => 'address-information-'.time(), |
|
874 | 874 | 'QSG_desc' => '', |
875 | 875 | 'QSG_order' => 2, |
876 | 876 | 'QSG_show_group_name' => 1, |
@@ -881,14 +881,14 @@ discard block |
||
881 | 881 | break; |
882 | 882 | } |
883 | 883 | // make sure we have some values before inserting them |
884 | - if (! empty($QSG_values)) { |
|
884 | + if ( ! empty($QSG_values)) { |
|
885 | 885 | // insert system question |
886 | 886 | $wpdb->insert( |
887 | 887 | $table_name, |
888 | 888 | $QSG_values, |
889 | 889 | array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
890 | 890 | ); |
891 | - $QSG_IDs[ $QSG_system ] = $wpdb->insert_id; |
|
891 | + $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
892 | 892 | } |
893 | 893 | } |
894 | 894 | } |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | // reset values array |
919 | 919 | $QST_values = array(); |
920 | 920 | // if we don't have what we should have |
921 | - if (! in_array($QST_system, $questions)) { |
|
921 | + if ( ! in_array($QST_system, $questions)) { |
|
922 | 922 | // add it |
923 | 923 | switch ($QST_system) { |
924 | 924 | case 'fname': |
@@ -1070,7 +1070,7 @@ discard block |
||
1070 | 1070 | ); |
1071 | 1071 | break; |
1072 | 1072 | } |
1073 | - if (! empty($QST_values)) { |
|
1073 | + if ( ! empty($QST_values)) { |
|
1074 | 1074 | // insert system question |
1075 | 1075 | $wpdb->insert( |
1076 | 1076 | $table_name, |
@@ -1084,8 +1084,8 @@ discard block |
||
1084 | 1084 | } else { |
1085 | 1085 | $system_question_we_want = EEM_Question_Group::system_address; |
1086 | 1086 | } |
1087 | - if (isset($QSG_IDs[ $system_question_we_want ])) { |
|
1088 | - $QSG_ID = $QSG_IDs[ $system_question_we_want ]; |
|
1087 | + if (isset($QSG_IDs[$system_question_we_want])) { |
|
1088 | + $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
1089 | 1089 | } else { |
1090 | 1090 | $id_col = EEM_Question_Group::instance() |
1091 | 1091 | ->get_col(array(array('QSG_system' => $system_question_we_want))); |
@@ -1133,7 +1133,7 @@ discard block |
||
1133 | 1133 | */ |
1134 | 1134 | public static function insert_default_payment_methods() |
1135 | 1135 | { |
1136 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1136 | + if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1137 | 1137 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
1138 | 1138 | EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
1139 | 1139 | } else { |
@@ -1270,7 +1270,7 @@ discard block |
||
1270 | 1270 | $active_messenger->name, |
1271 | 1271 | $default_message_type_name_for_messenger |
1272 | 1272 | ) |
1273 | - || ! isset($installed_message_types[ $default_message_type_name_for_messenger ]) |
|
1273 | + || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
1274 | 1274 | ) { |
1275 | 1275 | continue; |
1276 | 1276 | } |
@@ -1283,7 +1283,7 @@ discard block |
||
1283 | 1283 | false |
1284 | 1284 | ); |
1285 | 1285 | // activate the templates for these message types |
1286 | - if (! empty($default_message_type_names_to_activate)) { |
|
1286 | + if ( ! empty($default_message_type_names_to_activate)) { |
|
1287 | 1287 | $templates_created = EEH_MSG_Template::generate_new_templates( |
1288 | 1288 | $active_messenger->name, |
1289 | 1289 | $default_message_type_names_for_messenger, |
@@ -1317,13 +1317,13 @@ discard block |
||
1317 | 1317 | $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
1318 | 1318 | // verify the default message types match an installed message type. |
1319 | 1319 | foreach ($default_message_type_names_for_messenger as $key => $name) { |
1320 | - if (! isset($installed_message_types[ $name ]) |
|
1320 | + if ( ! isset($installed_message_types[$name]) |
|
1321 | 1321 | || $message_resource_manager->has_message_type_been_activated_for_messenger( |
1322 | 1322 | $name, |
1323 | 1323 | $messenger_to_generate->name |
1324 | 1324 | ) |
1325 | 1325 | ) { |
1326 | - unset($default_message_type_names_for_messenger[ $key ]); |
|
1326 | + unset($default_message_type_names_for_messenger[$key]); |
|
1327 | 1327 | } |
1328 | 1328 | } |
1329 | 1329 | // in previous iterations, the active_messengers option in the db |
@@ -1337,7 +1337,7 @@ discard block |
||
1337 | 1337 | false |
1338 | 1338 | ); |
1339 | 1339 | // create any templates needing created (or will reactivate templates already generated as necessary). |
1340 | - if (! empty($default_message_type_names_for_messenger)) { |
|
1340 | + if ( ! empty($default_message_type_names_for_messenger)) { |
|
1341 | 1341 | $templates_generated = EEH_MSG_Template::generate_new_templates( |
1342 | 1342 | $messenger_to_generate->name, |
1343 | 1343 | $default_message_type_names_for_messenger, |
@@ -1372,13 +1372,13 @@ discard block |
||
1372 | 1372 | // if installed messenger is a messenger that should be activated on install |
1373 | 1373 | // and is not already active |
1374 | 1374 | // and has never been activated |
1375 | - if (! $installed_messenger->activate_on_install |
|
1376 | - || isset($active_messengers[ $installed_messenger->name ]) |
|
1377 | - || isset($has_activated[ $installed_messenger->name ]) |
|
1375 | + if ( ! $installed_messenger->activate_on_install |
|
1376 | + || isset($active_messengers[$installed_messenger->name]) |
|
1377 | + || isset($has_activated[$installed_messenger->name]) |
|
1378 | 1378 | ) { |
1379 | 1379 | continue; |
1380 | 1380 | } |
1381 | - $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger; |
|
1381 | + $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
1382 | 1382 | } |
1383 | 1383 | return $messengers_to_generate; |
1384 | 1384 | } |
@@ -1416,7 +1416,7 @@ discard block |
||
1416 | 1416 | // this creates an array for tracking events that have no active ticket prices created |
1417 | 1417 | // this allows us to warn admins of the situation so that it can be corrected |
1418 | 1418 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
1419 | - if (! $espresso_no_ticket_prices) { |
|
1419 | + if ( ! $espresso_no_ticket_prices) { |
|
1420 | 1420 | add_option('ee_no_ticket_prices', array(), '', false); |
1421 | 1421 | } |
1422 | 1422 | } |
@@ -1455,7 +1455,7 @@ discard block |
||
1455 | 1455 | } |
1456 | 1456 | } |
1457 | 1457 | // get all our CPTs |
1458 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1458 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")"; |
|
1459 | 1459 | $cpt_ids = $wpdb->get_col($query); |
1460 | 1460 | // delete each post meta and term relations too |
1461 | 1461 | foreach ($cpt_ids as $post_id) { |
@@ -1484,7 +1484,7 @@ discard block |
||
1484 | 1484 | || ! $table->is_global()// not main site,but not global either. nuke it |
1485 | 1485 | ) |
1486 | 1486 | ) { |
1487 | - $tables[ $table->get_table_name() ] = $table->get_table_name(); |
|
1487 | + $tables[$table->get_table_name()] = $table->get_table_name(); |
|
1488 | 1488 | } |
1489 | 1489 | } |
1490 | 1490 | } |
@@ -1501,7 +1501,7 @@ discard block |
||
1501 | 1501 | 'esp_rule', |
1502 | 1502 | ); |
1503 | 1503 | foreach ($tables_without_models as $table) { |
1504 | - $tables[ $table ] = $table; |
|
1504 | + $tables[$table] = $table; |
|
1505 | 1505 | } |
1506 | 1506 | return \EEH_Activation::getTableManager()->dropTables($tables); |
1507 | 1507 | } |
@@ -1578,13 +1578,13 @@ discard block |
||
1578 | 1578 | $undeleted_options = array(); |
1579 | 1579 | foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
1580 | 1580 | if ($no_wildcard) { |
1581 | - if (! delete_option($option_name)) { |
|
1581 | + if ( ! delete_option($option_name)) { |
|
1582 | 1582 | $undeleted_options[] = $option_name; |
1583 | 1583 | } |
1584 | 1584 | } else { |
1585 | 1585 | $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
1586 | 1586 | foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
1587 | - if (! delete_option($option_name_from_wildcard)) { |
|
1587 | + if ( ! delete_option($option_name_from_wildcard)) { |
|
1588 | 1588 | $undeleted_options[] = $option_name_from_wildcard; |
1589 | 1589 | } |
1590 | 1590 | } |
@@ -1596,20 +1596,20 @@ discard block |
||
1596 | 1596 | $db_update_sans_ee4 = array(); |
1597 | 1597 | foreach ($espresso_db_update as $version => $times_activated) { |
1598 | 1598 | if ((string) $version[0] === '3') {// if its NON EE4 |
1599 | - $db_update_sans_ee4[ $version ] = $times_activated; |
|
1599 | + $db_update_sans_ee4[$version] = $times_activated; |
|
1600 | 1600 | } |
1601 | 1601 | } |
1602 | 1602 | update_option('espresso_db_update', $db_update_sans_ee4); |
1603 | 1603 | } |
1604 | 1604 | $errors = ''; |
1605 | - if (! empty($undeleted_options)) { |
|
1605 | + if ( ! empty($undeleted_options)) { |
|
1606 | 1606 | $errors .= sprintf( |
1607 | 1607 | __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
1608 | 1608 | '<br/>', |
1609 | 1609 | implode(',<br/>', $undeleted_options) |
1610 | 1610 | ); |
1611 | 1611 | } |
1612 | - if (! empty($errors)) { |
|
1612 | + if ( ! empty($errors)) { |
|
1613 | 1613 | EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
1614 | 1614 | } |
1615 | 1615 | } |