@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.10.33.rc.003'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.10.33.rc.003'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
141 | 141 | \ No newline at end of file |
@@ -20,1429 +20,1429 @@ |
||
20 | 20 | class General_Settings_Admin_Page extends EE_Admin_Page |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var EE_Core_Config |
|
25 | - */ |
|
26 | - public $core_config; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * Initialize basic properties. |
|
31 | - */ |
|
32 | - protected function _init_page_props() |
|
33 | - { |
|
34 | - $this->page_slug = GEN_SET_PG_SLUG; |
|
35 | - $this->page_label = GEN_SET_LABEL; |
|
36 | - $this->_admin_base_url = GEN_SET_ADMIN_URL; |
|
37 | - $this->_admin_base_path = GEN_SET_ADMIN; |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * Set ajax hooks |
|
43 | - */ |
|
44 | - protected function _ajax_hooks() |
|
45 | - { |
|
46 | - add_action('wp_ajax_espresso_display_country_settings', [$this, 'display_country_settings']); |
|
47 | - add_action('wp_ajax_espresso_display_country_states', [$this, 'display_country_states']); |
|
48 | - add_action('wp_ajax_espresso_delete_state', [$this, 'delete_state'], 10, 3); |
|
49 | - add_action('wp_ajax_espresso_add_new_state', [$this, 'add_new_state']); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * More page properties initialization. |
|
55 | - */ |
|
56 | - protected function _define_page_props() |
|
57 | - { |
|
58 | - $this->_admin_page_title = GEN_SET_LABEL; |
|
59 | - $this->_labels = ['publishbox' => esc_html__('Update Settings', 'event_espresso')]; |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * Set page routes property. |
|
65 | - */ |
|
66 | - protected function _set_page_routes() |
|
67 | - { |
|
68 | - $this->_page_routes = [ |
|
69 | - 'critical_pages' => [ |
|
70 | - 'func' => '_espresso_page_settings', |
|
71 | - 'capability' => 'manage_options', |
|
72 | - ], |
|
73 | - 'update_espresso_page_settings' => [ |
|
74 | - 'func' => '_update_espresso_page_settings', |
|
75 | - 'capability' => 'manage_options', |
|
76 | - 'noheader' => true, |
|
77 | - ], |
|
78 | - 'default' => [ |
|
79 | - 'func' => '_your_organization_settings', |
|
80 | - 'capability' => 'manage_options', |
|
81 | - ], |
|
82 | - |
|
83 | - 'update_your_organization_settings' => [ |
|
84 | - 'func' => '_update_your_organization_settings', |
|
85 | - 'capability' => 'manage_options', |
|
86 | - 'noheader' => true, |
|
87 | - ], |
|
88 | - |
|
89 | - 'admin_option_settings' => [ |
|
90 | - 'func' => '_admin_option_settings', |
|
91 | - 'capability' => 'manage_options', |
|
92 | - ], |
|
93 | - |
|
94 | - 'update_admin_option_settings' => [ |
|
95 | - 'func' => '_update_admin_option_settings', |
|
96 | - 'capability' => 'manage_options', |
|
97 | - 'noheader' => true, |
|
98 | - ], |
|
99 | - |
|
100 | - 'country_settings' => [ |
|
101 | - 'func' => '_country_settings', |
|
102 | - 'capability' => 'manage_options', |
|
103 | - ], |
|
104 | - |
|
105 | - 'update_country_settings' => [ |
|
106 | - 'func' => '_update_country_settings', |
|
107 | - 'capability' => 'manage_options', |
|
108 | - 'noheader' => true, |
|
109 | - ], |
|
110 | - |
|
111 | - 'display_country_settings' => [ |
|
112 | - 'func' => 'display_country_settings', |
|
113 | - 'capability' => 'manage_options', |
|
114 | - 'noheader' => true, |
|
115 | - ], |
|
116 | - |
|
117 | - 'add_new_state' => [ |
|
118 | - 'func' => 'add_new_state', |
|
119 | - 'capability' => 'manage_options', |
|
120 | - 'noheader' => true, |
|
121 | - ], |
|
122 | - |
|
123 | - 'delete_state' => [ |
|
124 | - 'func' => 'delete_state', |
|
125 | - 'capability' => 'manage_options', |
|
126 | - 'noheader' => true, |
|
127 | - ], |
|
128 | - 'privacy_settings' => [ |
|
129 | - 'func' => 'privacySettings', |
|
130 | - 'capability' => 'manage_options', |
|
131 | - ], |
|
132 | - 'update_privacy_settings' => [ |
|
133 | - 'func' => 'updatePrivacySettings', |
|
134 | - 'capability' => 'manage_options', |
|
135 | - 'noheader' => true, |
|
136 | - 'headers_sent_route' => 'privacy_settings', |
|
137 | - ], |
|
138 | - ]; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * Set page configuration property |
|
144 | - */ |
|
145 | - protected function _set_page_config() |
|
146 | - { |
|
147 | - $this->_page_config = [ |
|
148 | - 'critical_pages' => [ |
|
149 | - 'nav' => [ |
|
150 | - 'label' => esc_html__('Critical Pages', 'event_espresso'), |
|
151 | - 'order' => 50, |
|
152 | - ], |
|
153 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
154 | - 'help_tabs' => [ |
|
155 | - 'general_settings_critical_pages_help_tab' => [ |
|
156 | - 'title' => esc_html__('Critical Pages', 'event_espresso'), |
|
157 | - 'filename' => 'general_settings_critical_pages', |
|
158 | - ], |
|
159 | - ], |
|
160 | - 'require_nonce' => false, |
|
161 | - ], |
|
162 | - 'default' => [ |
|
163 | - 'nav' => [ |
|
164 | - 'label' => esc_html__('Your Organization', 'event_espresso'), |
|
165 | - 'order' => 20, |
|
166 | - ], |
|
167 | - 'help_tabs' => [ |
|
168 | - 'general_settings_your_organization_help_tab' => [ |
|
169 | - 'title' => esc_html__('Your Organization', 'event_espresso'), |
|
170 | - 'filename' => 'general_settings_your_organization', |
|
171 | - ], |
|
172 | - ], |
|
173 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
174 | - 'require_nonce' => false, |
|
175 | - ], |
|
176 | - 'admin_option_settings' => [ |
|
177 | - 'nav' => [ |
|
178 | - 'label' => esc_html__('Admin Options', 'event_espresso'), |
|
179 | - 'order' => 60, |
|
180 | - ], |
|
181 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
182 | - 'help_tabs' => [ |
|
183 | - 'general_settings_admin_options_help_tab' => [ |
|
184 | - 'title' => esc_html__('Admin Options', 'event_espresso'), |
|
185 | - 'filename' => 'general_settings_admin_options', |
|
186 | - ], |
|
187 | - ], |
|
188 | - 'require_nonce' => false, |
|
189 | - ], |
|
190 | - 'country_settings' => [ |
|
191 | - 'nav' => [ |
|
192 | - 'label' => esc_html__('Countries', 'event_espresso'), |
|
193 | - 'order' => 70, |
|
194 | - ], |
|
195 | - 'help_tabs' => [ |
|
196 | - 'general_settings_countries_help_tab' => [ |
|
197 | - 'title' => esc_html__('Countries', 'event_espresso'), |
|
198 | - 'filename' => 'general_settings_countries', |
|
199 | - ], |
|
200 | - ], |
|
201 | - 'require_nonce' => false, |
|
202 | - ], |
|
203 | - 'privacy_settings' => [ |
|
204 | - 'nav' => [ |
|
205 | - 'label' => esc_html__('Privacy', 'event_espresso'), |
|
206 | - 'order' => 80, |
|
207 | - ], |
|
208 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
209 | - 'require_nonce' => false, |
|
210 | - ], |
|
211 | - ]; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - protected function _add_screen_options() |
|
216 | - { |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - protected function _add_feature_pointers() |
|
221 | - { |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * Enqueue global scripts and styles for all routes in the General Settings Admin Pages. |
|
227 | - */ |
|
228 | - public function load_scripts_styles() |
|
229 | - { |
|
230 | - // styles |
|
231 | - wp_enqueue_style('espresso-ui-theme'); |
|
232 | - // scripts |
|
233 | - wp_enqueue_script('ee_admin_js'); |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * Execute logic running on `admin_init` |
|
239 | - */ |
|
240 | - public function admin_init() |
|
241 | - { |
|
242 | - $this->core_config = EE_Registry::instance()->CFG->core; |
|
243 | - |
|
244 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags( |
|
245 | - esc_html__( |
|
246 | - 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
247 | - 'event_espresso' |
|
248 | - ) |
|
249 | - ); |
|
250 | - EE_Registry::$i18n_js_strings['error_occurred'] = wp_strip_all_tags( |
|
251 | - esc_html__( |
|
252 | - 'An error occurred! Please refresh the page and try again.', |
|
253 | - 'event_espresso' |
|
254 | - ) |
|
255 | - ); |
|
256 | - EE_Registry::$i18n_js_strings['confirm_delete_state'] = wp_strip_all_tags( |
|
257 | - esc_html__( |
|
258 | - 'Are you sure you want to delete this State / Province?', |
|
259 | - 'event_espresso' |
|
260 | - ) |
|
261 | - ); |
|
262 | - EE_Registry::$i18n_js_strings['ajax_url'] = admin_url( |
|
263 | - 'admin-ajax.php?page=espresso_general_settings', |
|
264 | - is_ssl() ? 'https://' : 'http://' |
|
265 | - ); |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - public function admin_notices() |
|
270 | - { |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - public function admin_footer_scripts() |
|
275 | - { |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * Enqueue scripts and styles for the default route. |
|
281 | - */ |
|
282 | - public function load_scripts_styles_default() |
|
283 | - { |
|
284 | - // styles |
|
285 | - wp_enqueue_style('thickbox'); |
|
286 | - // scripts |
|
287 | - wp_enqueue_script('media-upload'); |
|
288 | - wp_enqueue_script('thickbox'); |
|
289 | - wp_register_script( |
|
290 | - 'organization_settings', |
|
291 | - GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
292 | - ['jquery', 'media-upload', 'thickbox'], |
|
293 | - EVENT_ESPRESSO_VERSION, |
|
294 | - true |
|
295 | - ); |
|
296 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION); |
|
297 | - wp_enqueue_script('organization_settings'); |
|
298 | - wp_enqueue_style('organization-css'); |
|
299 | - $confirm_image_delete = [ |
|
300 | - 'text' => wp_strip_all_tags( |
|
301 | - esc_html__( |
|
302 | - 'Do you really want to delete this image? Please remember to save your settings to complete the removal.', |
|
303 | - 'event_espresso' |
|
304 | - ) |
|
305 | - ), |
|
306 | - ]; |
|
307 | - wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete); |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * Enqueue scripts and styles for the country settings route. |
|
313 | - */ |
|
314 | - public function load_scripts_styles_country_settings() |
|
315 | - { |
|
316 | - // scripts |
|
317 | - wp_register_script( |
|
318 | - 'gen_settings_countries', |
|
319 | - GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
320 | - ['ee_admin_js'], |
|
321 | - EVENT_ESPRESSO_VERSION, |
|
322 | - true |
|
323 | - ); |
|
324 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION); |
|
325 | - wp_enqueue_script('gen_settings_countries'); |
|
326 | - wp_enqueue_style('organization-css'); |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /************* Espresso Pages *************/ |
|
331 | - /** |
|
332 | - * _espresso_page_settings |
|
333 | - * |
|
334 | - * @throws EE_Error |
|
335 | - * @throws DomainException |
|
336 | - * @throws DomainException |
|
337 | - * @throws InvalidDataTypeException |
|
338 | - * @throws InvalidArgumentException |
|
339 | - */ |
|
340 | - protected function _espresso_page_settings() |
|
341 | - { |
|
342 | - // Check to make sure all of the main pages are set up properly, |
|
343 | - // if not create the default pages and display an admin notice |
|
344 | - EEH_Activation::verify_default_pages_exist(); |
|
345 | - $this->_transient_garbage_collection(); |
|
346 | - |
|
347 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
348 | - |
|
349 | - $this->_template_args['reg_page_id'] = $this->core_config->reg_page_id ?? null; |
|
350 | - $this->_template_args['reg_page_obj'] = isset($this->core_config->reg_page_id) |
|
351 | - ? get_post($this->core_config->reg_page_id) |
|
352 | - : false; |
|
353 | - |
|
354 | - $this->_template_args['txn_page_id'] = $this->core_config->txn_page_id ?? null; |
|
355 | - $this->_template_args['txn_page_obj'] = isset($this->core_config->txn_page_id) |
|
356 | - ? get_post($this->core_config->txn_page_id) |
|
357 | - : false; |
|
358 | - |
|
359 | - $this->_template_args['thank_you_page_id'] = $this->core_config->thank_you_page_id ?? null; |
|
360 | - $this->_template_args['thank_you_page_obj'] = isset($this->core_config->thank_you_page_id) |
|
361 | - ? get_post($this->core_config->thank_you_page_id) |
|
362 | - : false; |
|
363 | - |
|
364 | - $this->_template_args['cancel_page_id'] = $this->core_config->cancel_page_id ?? null; |
|
365 | - $this->_template_args['cancel_page_obj'] = isset($this->core_config->cancel_page_id) |
|
366 | - ? get_post($this->core_config->cancel_page_id) |
|
367 | - : false; |
|
368 | - |
|
369 | - $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
|
370 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
371 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
372 | - GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
373 | - $this->_template_args, |
|
374 | - true |
|
375 | - ); |
|
376 | - $this->display_admin_page_with_sidebar(); |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * Handler for updating espresso page settings. |
|
382 | - * |
|
383 | - * @throws EE_Error |
|
384 | - */ |
|
385 | - protected function _update_espresso_page_settings() |
|
386 | - { |
|
387 | - // capture incoming request data && set page IDs |
|
388 | - $this->core_config->reg_page_id = $this->request->getRequestParam( |
|
389 | - 'reg_page_id', |
|
390 | - $this->core_config->reg_page_id, |
|
391 | - DataType::INT |
|
392 | - ); |
|
393 | - $this->core_config->txn_page_id = $this->request->getRequestParam( |
|
394 | - 'txn_page_id', |
|
395 | - $this->core_config->txn_page_id, |
|
396 | - DataType::INT |
|
397 | - ); |
|
398 | - $this->core_config->thank_you_page_id = $this->request->getRequestParam( |
|
399 | - 'thank_you_page_id', |
|
400 | - $this->core_config->thank_you_page_id, |
|
401 | - DataType::INT |
|
402 | - ); |
|
403 | - $this->core_config->cancel_page_id = $this->request->getRequestParam( |
|
404 | - 'cancel_page_id', |
|
405 | - $this->core_config->cancel_page_id, |
|
406 | - DataType::INT |
|
407 | - ); |
|
408 | - |
|
409 | - $this->core_config = apply_filters( |
|
410 | - 'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core', |
|
411 | - $this->core_config, |
|
412 | - $this->request->requestParams() |
|
413 | - ); |
|
414 | - |
|
415 | - $what = esc_html__('Critical Pages & Shortcodes', 'event_espresso'); |
|
416 | - $this->_redirect_after_action( |
|
417 | - $this->_update_espresso_configuration( |
|
418 | - $what, |
|
419 | - $this->core_config, |
|
420 | - __FILE__, |
|
421 | - __FUNCTION__, |
|
422 | - __LINE__ |
|
423 | - ), |
|
424 | - $what, |
|
425 | - '', |
|
426 | - [ |
|
427 | - 'action' => 'critical_pages', |
|
428 | - ], |
|
429 | - true |
|
430 | - ); |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - /************* Your Organization *************/ |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * @throws DomainException |
|
439 | - * @throws EE_Error |
|
440 | - * @throws InvalidArgumentException |
|
441 | - * @throws InvalidDataTypeException |
|
442 | - * @throws InvalidInterfaceException |
|
443 | - */ |
|
444 | - protected function _your_organization_settings() |
|
445 | - { |
|
446 | - $this->_template_args['admin_page_content'] = ''; |
|
447 | - try { |
|
448 | - /** @var OrganizationSettings $organization_settings_form */ |
|
449 | - $organization_settings_form = $this->loader->getShared(OrganizationSettings::class); |
|
450 | - |
|
451 | - $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
452 | - $organization_settings_form->display(), |
|
453 | - '', |
|
454 | - 'padding' |
|
455 | - ); |
|
456 | - } catch (Exception $e) { |
|
457 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
458 | - } |
|
459 | - $this->_set_add_edit_form_tags('update_your_organization_settings'); |
|
460 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
461 | - $this->display_admin_page_with_sidebar(); |
|
462 | - } |
|
463 | - |
|
464 | - |
|
465 | - /** |
|
466 | - * Handler for updating organization settings. |
|
467 | - * |
|
468 | - * @throws EE_Error |
|
469 | - */ |
|
470 | - protected function _update_your_organization_settings() |
|
471 | - { |
|
472 | - try { |
|
473 | - /** @var OrganizationSettings $organization_settings_form */ |
|
474 | - $organization_settings_form = $this->loader->getShared(OrganizationSettings::class); |
|
475 | - |
|
476 | - $success = $organization_settings_form->process($this->request->requestParams()); |
|
477 | - |
|
478 | - EE_Registry::instance()->CFG = apply_filters( |
|
479 | - 'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG', |
|
480 | - EE_Registry::instance()->CFG |
|
481 | - ); |
|
482 | - } catch (Exception $e) { |
|
483 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
484 | - $success = false; |
|
485 | - } |
|
486 | - |
|
487 | - if ($success) { |
|
488 | - $success = $this->_update_espresso_configuration( |
|
489 | - esc_html__('Your Organization Settings', 'event_espresso'), |
|
490 | - EE_Registry::instance()->CFG, |
|
491 | - __FILE__, |
|
492 | - __FUNCTION__, |
|
493 | - __LINE__ |
|
494 | - ); |
|
495 | - } |
|
496 | - |
|
497 | - $this->_redirect_after_action($success, '', '', ['action' => 'default'], true); |
|
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - |
|
502 | - /************* Admin Options *************/ |
|
503 | - |
|
504 | - |
|
505 | - /** |
|
506 | - * _admin_option_settings |
|
507 | - * |
|
508 | - * @throws EE_Error |
|
509 | - * @throws LogicException |
|
510 | - */ |
|
511 | - protected function _admin_option_settings() |
|
512 | - { |
|
513 | - $this->_template_args['admin_page_content'] = ''; |
|
514 | - try { |
|
515 | - $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
516 | - // still need this for the old school form in Extend_General_Settings_Admin_Page |
|
517 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
518 | - // also need to account for the do_action that was in the old template |
|
519 | - $admin_options_settings_form->setTemplateArgs($this->_template_args); |
|
520 | - $this->_template_args['admin_page_content'] = $admin_options_settings_form->display(); |
|
521 | - } catch (Exception $e) { |
|
522 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
523 | - } |
|
524 | - $this->_set_add_edit_form_tags('update_admin_option_settings'); |
|
525 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
526 | - $this->display_admin_page_with_sidebar(); |
|
527 | - } |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * _update_admin_option_settings |
|
532 | - * |
|
533 | - * @throws EE_Error |
|
534 | - * @throws InvalidDataTypeException |
|
535 | - * @throws InvalidFormSubmissionException |
|
536 | - * @throws InvalidArgumentException |
|
537 | - * @throws LogicException |
|
538 | - */ |
|
539 | - protected function _update_admin_option_settings() |
|
540 | - { |
|
541 | - try { |
|
542 | - $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
543 | - $admin_options_settings_form->process( |
|
544 | - $this->request->getRequestParam( |
|
545 | - $admin_options_settings_form->slug(), |
|
546 | - [], |
|
547 | - DataType::OBJECT // need to change this to ARRAY after min PHP version gets bumped to 7+ |
|
548 | - ) |
|
549 | - ); |
|
550 | - EE_Registry::instance()->CFG->admin = apply_filters( |
|
551 | - 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
|
552 | - EE_Registry::instance()->CFG->admin |
|
553 | - ); |
|
554 | - } catch (Exception $e) { |
|
555 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
556 | - } |
|
557 | - $this->_redirect_after_action( |
|
558 | - apply_filters( |
|
559 | - 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', |
|
560 | - $this->_update_espresso_configuration( |
|
561 | - esc_html__('Admin Options', 'event_espresso'), |
|
562 | - EE_Registry::instance()->CFG->admin, |
|
563 | - __FILE__, |
|
564 | - __FUNCTION__, |
|
565 | - __LINE__ |
|
566 | - ) |
|
567 | - ), |
|
568 | - esc_html__('Admin Options', 'event_espresso'), |
|
569 | - 'updated', |
|
570 | - ['action' => 'admin_option_settings'] |
|
571 | - ); |
|
572 | - } |
|
573 | - |
|
574 | - |
|
575 | - /************* Countries *************/ |
|
576 | - |
|
577 | - |
|
578 | - /** |
|
579 | - * @param string|null $default |
|
580 | - * @return string |
|
581 | - */ |
|
582 | - protected function getCountryISO(?string $default = null): string |
|
583 | - { |
|
584 | - $default = $default ?? $this->getCountryIsoForSite(); |
|
585 | - $CNT_ISO = $this->request->getRequestParam('country', $default); |
|
586 | - $CNT_ISO = $this->request->getRequestParam('CNT_ISO', $CNT_ISO); |
|
587 | - return strtoupper($CNT_ISO); |
|
588 | - } |
|
589 | - |
|
590 | - |
|
591 | - /** |
|
592 | - * @return string |
|
593 | - */ |
|
594 | - protected function getCountryIsoForSite(): string |
|
595 | - { |
|
596 | - return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
597 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
598 | - : 'US'; |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * @param string $CNT_ISO |
|
604 | - * @param EE_Country|null $country |
|
605 | - * @return EE_Base_Class|EE_Country |
|
606 | - * @throws EE_Error |
|
607 | - * @throws InvalidArgumentException |
|
608 | - * @throws InvalidDataTypeException |
|
609 | - * @throws InvalidInterfaceException |
|
610 | - * @throws ReflectionException |
|
611 | - */ |
|
612 | - protected function verifyOrGetCountryFromIso(string $CNT_ISO, ?EE_Country $country = null) |
|
613 | - { |
|
614 | - /** @var EE_Country $country */ |
|
615 | - return $country instanceof EE_Country && $country->ID() === $CNT_ISO |
|
616 | - ? $country |
|
617 | - : EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
618 | - } |
|
619 | - |
|
620 | - |
|
621 | - /** |
|
622 | - * Output Country Settings view. |
|
623 | - * |
|
624 | - * @throws DomainException |
|
625 | - * @throws EE_Error |
|
626 | - * @throws InvalidArgumentException |
|
627 | - * @throws InvalidDataTypeException |
|
628 | - * @throws InvalidInterfaceException |
|
629 | - * @throws ReflectionException |
|
630 | - */ |
|
631 | - protected function _country_settings() |
|
632 | - { |
|
633 | - $CNT_ISO = $this->getCountryISO(); |
|
634 | - |
|
635 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
636 | - $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
637 | - EE_Question::new_instance( |
|
638 | - [ |
|
639 | - 'QST_ID' => 0, |
|
640 | - 'QST_display_text' => esc_html__('Select Country', 'event_espresso'), |
|
641 | - 'QST_system' => 'admin-country', |
|
642 | - ] |
|
643 | - ), |
|
644 | - EE_Answer::new_instance( |
|
645 | - [ |
|
646 | - 'ANS_ID' => 0, |
|
647 | - 'ANS_value' => $CNT_ISO, |
|
648 | - ] |
|
649 | - ), |
|
650 | - [ |
|
651 | - 'input_id' => 'country', |
|
652 | - 'input_name' => 'country', |
|
653 | - 'input_prefix' => '', |
|
654 | - 'append_qstn_id' => false, |
|
655 | - ] |
|
656 | - ); |
|
657 | - |
|
658 | - $country = $this->verifyOrGetCountryFromIso($CNT_ISO); |
|
659 | - add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10); |
|
660 | - add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10); |
|
661 | - $this->_template_args['country_details_settings'] = $this->display_country_settings( |
|
662 | - $country->ID(), |
|
663 | - $country |
|
664 | - ); |
|
665 | - $this->_template_args['country_states_settings'] = $this->display_country_states( |
|
666 | - $country->ID(), |
|
667 | - $country |
|
668 | - ); |
|
669 | - $this->_template_args['CNT_name_for_site'] = $country->name(); |
|
670 | - |
|
671 | - $this->_set_add_edit_form_tags('update_country_settings'); |
|
672 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
673 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
674 | - GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
675 | - $this->_template_args, |
|
676 | - true |
|
677 | - ); |
|
678 | - $this->display_admin_page_with_no_sidebar(); |
|
679 | - } |
|
680 | - |
|
681 | - |
|
682 | - /** |
|
683 | - * @param string $CNT_ISO |
|
684 | - * @param EE_Country|null $country |
|
685 | - * @return string |
|
686 | - * @throws DomainException |
|
687 | - * @throws EE_Error |
|
688 | - * @throws InvalidArgumentException |
|
689 | - * @throws InvalidDataTypeException |
|
690 | - * @throws InvalidInterfaceException |
|
691 | - * @throws ReflectionException |
|
692 | - */ |
|
693 | - public function display_country_settings(string $CNT_ISO = '', ?EE_Country $country = null): string |
|
694 | - { |
|
695 | - $CNT_ISO = $this->getCountryISO($CNT_ISO); |
|
696 | - $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
|
697 | - |
|
698 | - if (! $CNT_ISO) { |
|
699 | - return ''; |
|
700 | - } |
|
701 | - |
|
702 | - // for ajax |
|
703 | - remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
704 | - remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
705 | - add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10, 2); |
|
706 | - add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10, 2); |
|
707 | - $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
708 | - $CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site; |
|
709 | - $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled; |
|
710 | - |
|
711 | - $country_input_types = [ |
|
712 | - 'CNT_active' => [ |
|
713 | - 'type' => 'RADIO_BTN', |
|
714 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
715 | - 'class' => '', |
|
716 | - 'options' => $this->_yes_no_values, |
|
717 | - 'use_desc_4_label' => true, |
|
718 | - ], |
|
719 | - 'CNT_ISO' => [ |
|
720 | - 'type' => 'TEXT', |
|
721 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
722 | - 'class' => 'small-text', |
|
723 | - ], |
|
724 | - 'CNT_ISO3' => [ |
|
725 | - 'type' => 'TEXT', |
|
726 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
727 | - 'class' => 'small-text', |
|
728 | - ], |
|
729 | - // 'RGN_ID' => [ |
|
730 | - // 'type' => 'TEXT', |
|
731 | - // 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
732 | - // 'class' => 'ee-input-size--small', |
|
733 | - // ], |
|
734 | - 'CNT_name' => [ |
|
735 | - 'type' => 'TEXT', |
|
736 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
737 | - 'class' => 'regular-text', |
|
738 | - ], |
|
739 | - 'CNT_cur_code' => [ |
|
740 | - 'type' => 'TEXT', |
|
741 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
742 | - 'class' => 'small-text', |
|
743 | - 'disabled' => $CNT_cur_disabled, |
|
744 | - ], |
|
745 | - 'CNT_cur_single' => [ |
|
746 | - 'type' => 'TEXT', |
|
747 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
748 | - 'class' => 'medium-text', |
|
749 | - 'disabled' => $CNT_cur_disabled, |
|
750 | - ], |
|
751 | - 'CNT_cur_plural' => [ |
|
752 | - 'type' => 'TEXT', |
|
753 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
754 | - 'class' => 'medium-text', |
|
755 | - 'disabled' => $CNT_cur_disabled, |
|
756 | - ], |
|
757 | - 'CNT_cur_sign' => [ |
|
758 | - 'type' => 'TEXT', |
|
759 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
760 | - 'class' => 'small-text', |
|
761 | - 'htmlentities' => false, |
|
762 | - 'disabled' => $CNT_cur_disabled, |
|
763 | - ], |
|
764 | - 'CNT_cur_sign_b4' => [ |
|
765 | - 'type' => 'RADIO_BTN', |
|
766 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
767 | - 'class' => '', |
|
768 | - 'options' => $this->_yes_no_values, |
|
769 | - 'use_desc_4_label' => true, |
|
770 | - 'disabled' => $CNT_cur_disabled, |
|
771 | - ], |
|
772 | - 'CNT_cur_dec_plc' => [ |
|
773 | - 'type' => 'RADIO_BTN', |
|
774 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
775 | - 'class' => '', |
|
776 | - 'options' => [ |
|
777 | - ['id' => 0, 'text' => ''], |
|
778 | - ['id' => 1, 'text' => ''], |
|
779 | - ['id' => 2, 'text' => ''], |
|
780 | - ['id' => 3, 'text' => ''], |
|
781 | - ], |
|
782 | - 'disabled' => $CNT_cur_disabled, |
|
783 | - ], |
|
784 | - 'CNT_cur_dec_mrk' => [ |
|
785 | - 'type' => 'RADIO_BTN', |
|
786 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
787 | - 'class' => '', |
|
788 | - 'options' => [ |
|
789 | - [ |
|
790 | - 'id' => ',', |
|
791 | - 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
792 | - ], |
|
793 | - ['id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')], |
|
794 | - ], |
|
795 | - 'use_desc_4_label' => true, |
|
796 | - 'disabled' => $CNT_cur_disabled, |
|
797 | - ], |
|
798 | - 'CNT_cur_thsnds' => [ |
|
799 | - 'type' => 'RADIO_BTN', |
|
800 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
801 | - 'class' => '', |
|
802 | - 'options' => [ |
|
803 | - [ |
|
804 | - 'id' => ',', |
|
805 | - 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
806 | - ], |
|
807 | - [ |
|
808 | - 'id' => '.', |
|
809 | - 'text' => esc_html__('. (decimal)', 'event_espresso'), |
|
810 | - ], |
|
811 | - [ |
|
812 | - 'id' => ' ', |
|
813 | - 'text' => esc_html__('(space)', 'event_espresso'), |
|
814 | - ], |
|
815 | - ], |
|
816 | - 'use_desc_4_label' => true, |
|
817 | - 'disabled' => $CNT_cur_disabled, |
|
818 | - ], |
|
819 | - 'CNT_tel_code' => [ |
|
820 | - 'type' => 'TEXT', |
|
821 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
822 | - 'class' => 'small-text', |
|
823 | - ], |
|
824 | - 'CNT_is_EU' => [ |
|
825 | - 'type' => 'RADIO_BTN', |
|
826 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
827 | - 'class' => '', |
|
828 | - 'options' => $this->_yes_no_values, |
|
829 | - 'use_desc_4_label' => true, |
|
830 | - ], |
|
831 | - ]; |
|
832 | - $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
833 | - $country, |
|
834 | - $country_input_types |
|
835 | - ); |
|
836 | - $country_details_settings = EEH_Template::display_template( |
|
837 | - GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
838 | - $this->_template_args, |
|
839 | - true |
|
840 | - ); |
|
841 | - |
|
842 | - if (defined('DOING_AJAX')) { |
|
843 | - $notices = EE_Error::get_notices(false, false, false); |
|
844 | - echo wp_json_encode( |
|
845 | - [ |
|
846 | - 'return_data' => $country_details_settings, |
|
847 | - 'success' => $notices['success'], |
|
848 | - 'errors' => $notices['errors'], |
|
849 | - ] |
|
850 | - ); |
|
851 | - die(); |
|
852 | - } |
|
853 | - return $country_details_settings; |
|
854 | - } |
|
855 | - |
|
856 | - |
|
857 | - /** |
|
858 | - * @param string $CNT_ISO |
|
859 | - * @param EE_Country|null $country |
|
860 | - * @return string |
|
861 | - * @throws DomainException |
|
862 | - * @throws EE_Error |
|
863 | - * @throws InvalidArgumentException |
|
864 | - * @throws InvalidDataTypeException |
|
865 | - * @throws InvalidInterfaceException |
|
866 | - * @throws ReflectionException |
|
867 | - */ |
|
868 | - public function display_country_states(string $CNT_ISO = '', ?EE_Country $country = null): string |
|
869 | - { |
|
870 | - $CNT_ISO = $this->getCountryISO($CNT_ISO); |
|
871 | - if (! $CNT_ISO) { |
|
872 | - return ''; |
|
873 | - } |
|
874 | - // for ajax |
|
875 | - remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
876 | - remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
877 | - add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'state_form_field_label_wrap'], 10, 2); |
|
878 | - add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'state_form_field_input__wrap'], 10); |
|
879 | - $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]); |
|
880 | - if (empty($states)) { |
|
881 | - /** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */ |
|
882 | - $countrySubRegionDao = $this->loader->getShared( |
|
883 | - 'EventEspresso\core\services\address\CountrySubRegionDao' |
|
884 | - ); |
|
885 | - if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) { |
|
886 | - $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
887 | - if ($countrySubRegionDao->saveCountrySubRegions($country)) { |
|
888 | - $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]); |
|
889 | - } |
|
890 | - } |
|
891 | - } |
|
892 | - if (is_array($states)) { |
|
893 | - foreach ($states as $STA_ID => $state) { |
|
894 | - if ($state instanceof EE_State) { |
|
895 | - $inputs = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
896 | - $state, |
|
897 | - [ |
|
898 | - 'STA_abbrev' => [ |
|
899 | - 'type' => 'TEXT', |
|
900 | - 'label' => esc_html__('Code', 'event_espresso'), |
|
901 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
902 | - 'class' => 'small-text', |
|
903 | - 'add_mobile_label' => true, |
|
904 | - ], |
|
905 | - 'STA_name' => [ |
|
906 | - 'type' => 'TEXT', |
|
907 | - 'label' => esc_html__('Name', 'event_espresso'), |
|
908 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
909 | - 'class' => 'regular-text', |
|
910 | - 'add_mobile_label' => true, |
|
911 | - ], |
|
912 | - 'STA_active' => [ |
|
913 | - 'type' => 'RADIO_BTN', |
|
914 | - 'label' => esc_html__( |
|
915 | - 'State Appears in Dropdown Select Lists', |
|
916 | - 'event_espresso' |
|
917 | - ), |
|
918 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
919 | - 'options' => $this->_yes_no_values, |
|
920 | - 'use_desc_4_label' => true, |
|
921 | - 'add_mobile_label' => true, |
|
922 | - ], |
|
923 | - ] |
|
924 | - ); |
|
925 | - |
|
926 | - $delete_state_url = EE_Admin_Page::add_query_args_and_nonce( |
|
927 | - [ |
|
928 | - 'action' => 'delete_state', |
|
929 | - 'STA_ID' => $STA_ID, |
|
930 | - 'CNT_ISO' => $CNT_ISO, |
|
931 | - 'STA_abbrev' => $state->abbrev(), |
|
932 | - ], |
|
933 | - GEN_SET_ADMIN_URL |
|
934 | - ); |
|
935 | - |
|
936 | - $this->_template_args['states'][ $STA_ID ]['inputs'] = $inputs; |
|
937 | - $this->_template_args['states'][ $STA_ID ]['delete_state_url'] = $delete_state_url; |
|
938 | - } |
|
939 | - } |
|
940 | - } else { |
|
941 | - $this->_template_args['states'] = false; |
|
942 | - } |
|
943 | - |
|
944 | - $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
945 | - ['action' => 'add_new_state'], |
|
946 | - GEN_SET_ADMIN_URL |
|
947 | - ); |
|
948 | - |
|
949 | - $state_details_settings = EEH_Template::display_template( |
|
950 | - GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
951 | - $this->_template_args, |
|
952 | - true |
|
953 | - ); |
|
954 | - |
|
955 | - if (defined('DOING_AJAX')) { |
|
956 | - $notices = EE_Error::get_notices(false, false, false); |
|
957 | - echo wp_json_encode( |
|
958 | - [ |
|
959 | - 'return_data' => $state_details_settings, |
|
960 | - 'success' => $notices['success'], |
|
961 | - 'errors' => $notices['errors'], |
|
962 | - ] |
|
963 | - ); |
|
964 | - die(); |
|
965 | - } |
|
966 | - return $state_details_settings; |
|
967 | - } |
|
968 | - |
|
969 | - |
|
970 | - /** |
|
971 | - * @return void |
|
972 | - * @throws EE_Error |
|
973 | - * @throws InvalidArgumentException |
|
974 | - * @throws InvalidDataTypeException |
|
975 | - * @throws InvalidInterfaceException |
|
976 | - * @throws ReflectionException |
|
977 | - */ |
|
978 | - public function add_new_state() |
|
979 | - { |
|
980 | - $success = true; |
|
981 | - $CNT_ISO = $this->getCountryISO(''); |
|
982 | - if (! $CNT_ISO) { |
|
983 | - EE_Error::add_error( |
|
984 | - esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
985 | - __FILE__, |
|
986 | - __FUNCTION__, |
|
987 | - __LINE__ |
|
988 | - ); |
|
989 | - $success = false; |
|
990 | - } |
|
991 | - $STA_abbrev = $this->request->getRequestParam('STA_abbrev'); |
|
992 | - if (! $STA_abbrev) { |
|
993 | - EE_Error::add_error( |
|
994 | - esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
|
995 | - __FILE__, |
|
996 | - __FUNCTION__, |
|
997 | - __LINE__ |
|
998 | - ); |
|
999 | - $success = false; |
|
1000 | - } |
|
1001 | - $STA_name = $this->request->getRequestParam('STA_name'); |
|
1002 | - if (! $STA_name) { |
|
1003 | - EE_Error::add_error( |
|
1004 | - esc_html__('No State name or an invalid State name was received.', 'event_espresso'), |
|
1005 | - __FILE__, |
|
1006 | - __FUNCTION__, |
|
1007 | - __LINE__ |
|
1008 | - ); |
|
1009 | - $success = false; |
|
1010 | - } |
|
1011 | - |
|
1012 | - if ($success) { |
|
1013 | - $cols_n_values = [ |
|
1014 | - 'CNT_ISO' => $CNT_ISO, |
|
1015 | - 'STA_abbrev' => $STA_abbrev, |
|
1016 | - 'STA_name' => $STA_name, |
|
1017 | - 'STA_active' => true, |
|
1018 | - ]; |
|
1019 | - $success = EEM_State::instance()->insert($cols_n_values); |
|
1020 | - EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso')); |
|
1021 | - } |
|
1022 | - |
|
1023 | - if (defined('DOING_AJAX')) { |
|
1024 | - $notices = EE_Error::get_notices(false, false, false); |
|
1025 | - echo wp_json_encode(array_merge($notices, ['return_data' => $CNT_ISO])); |
|
1026 | - die(); |
|
1027 | - } else { |
|
1028 | - $this->_redirect_after_action( |
|
1029 | - $success, |
|
1030 | - esc_html__('State', 'event_espresso'), |
|
1031 | - 'added', |
|
1032 | - ['action' => 'country_settings'] |
|
1033 | - ); |
|
1034 | - } |
|
1035 | - } |
|
1036 | - |
|
1037 | - |
|
1038 | - /** |
|
1039 | - * @return void |
|
1040 | - * @throws EE_Error |
|
1041 | - * @throws InvalidArgumentException |
|
1042 | - * @throws InvalidDataTypeException |
|
1043 | - * @throws InvalidInterfaceException |
|
1044 | - * @throws ReflectionException |
|
1045 | - */ |
|
1046 | - public function delete_state() |
|
1047 | - { |
|
1048 | - $CNT_ISO = $this->getCountryISO(); |
|
1049 | - $STA_ID = $this->request->getRequestParam('STA_ID'); |
|
1050 | - $STA_abbrev = $this->request->getRequestParam('STA_abbrev'); |
|
1051 | - |
|
1052 | - if (! $STA_ID) { |
|
1053 | - EE_Error::add_error( |
|
1054 | - esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'), |
|
1055 | - __FILE__, |
|
1056 | - __FUNCTION__, |
|
1057 | - __LINE__ |
|
1058 | - ); |
|
1059 | - return; |
|
1060 | - } |
|
1061 | - |
|
1062 | - $success = EEM_State::instance()->delete_by_ID($STA_ID); |
|
1063 | - if ($success !== false) { |
|
1064 | - do_action( |
|
1065 | - 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
1066 | - $CNT_ISO, |
|
1067 | - $STA_ID, |
|
1068 | - ['STA_abbrev' => $STA_abbrev] |
|
1069 | - ); |
|
1070 | - EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso')); |
|
1071 | - } |
|
1072 | - if (defined('DOING_AJAX')) { |
|
1073 | - $notices = EE_Error::get_notices(false); |
|
1074 | - $notices['return_data'] = true; |
|
1075 | - echo wp_json_encode($notices); |
|
1076 | - die(); |
|
1077 | - } else { |
|
1078 | - $this->_redirect_after_action( |
|
1079 | - $success, |
|
1080 | - esc_html__('State', 'event_espresso'), |
|
1081 | - 'deleted', |
|
1082 | - ['action' => 'country_settings'] |
|
1083 | - ); |
|
1084 | - } |
|
1085 | - } |
|
1086 | - |
|
1087 | - |
|
1088 | - /** |
|
1089 | - * _update_country_settings |
|
1090 | - * |
|
1091 | - * @return void |
|
1092 | - * @throws EE_Error |
|
1093 | - * @throws InvalidArgumentException |
|
1094 | - * @throws InvalidDataTypeException |
|
1095 | - * @throws InvalidInterfaceException |
|
1096 | - * @throws ReflectionException |
|
1097 | - */ |
|
1098 | - protected function _update_country_settings() |
|
1099 | - { |
|
1100 | - $CNT_ISO = $this->getCountryISO(); |
|
1101 | - if (! $CNT_ISO) { |
|
1102 | - EE_Error::add_error( |
|
1103 | - esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
1104 | - __FILE__, |
|
1105 | - __FUNCTION__, |
|
1106 | - __LINE__ |
|
1107 | - ); |
|
1108 | - return; |
|
1109 | - } |
|
1110 | - |
|
1111 | - $country = $this->verifyOrGetCountryFromIso($CNT_ISO); |
|
1112 | - |
|
1113 | - $cols_n_values = []; |
|
1114 | - $cols_n_values['CNT_ISO3'] = strtoupper( |
|
1115 | - $this->request->getRequestParam('cntry', $country->ISO3()) |
|
1116 | - ); |
|
1117 | - $cols_n_values['CNT_name'] = $this->request->getRequestParam( |
|
1118 | - "cntry[$CNT_ISO][CNT_name]", |
|
1119 | - $country->name() |
|
1120 | - ); |
|
1121 | - $cols_n_values['CNT_cur_code'] = strtoupper( |
|
1122 | - $this->request->getRequestParam( |
|
1123 | - "cntry[$CNT_ISO][CNT_cur_code]", |
|
1124 | - $country->currency_code() |
|
1125 | - ) |
|
1126 | - ); |
|
1127 | - $cols_n_values['CNT_cur_single'] = $this->request->getRequestParam( |
|
1128 | - "cntry[$CNT_ISO][CNT_cur_single]", |
|
1129 | - $country->currency_name_single() |
|
1130 | - ); |
|
1131 | - $cols_n_values['CNT_cur_plural'] = $this->request->getRequestParam( |
|
1132 | - "cntry[$CNT_ISO][CNT_cur_plural]", |
|
1133 | - $country->currency_name_plural() |
|
1134 | - ); |
|
1135 | - $cols_n_values['CNT_cur_sign'] = $this->request->getRequestParam( |
|
1136 | - "cntry[$CNT_ISO][CNT_cur_sign]", |
|
1137 | - $country->currency_sign() |
|
1138 | - ); |
|
1139 | - $cols_n_values['CNT_cur_sign_b4'] = $this->request->getRequestParam( |
|
1140 | - "cntry[$CNT_ISO][CNT_cur_sign_b4]", |
|
1141 | - $country->currency_sign_before(), |
|
1142 | - DataType::BOOL |
|
1143 | - ); |
|
1144 | - $cols_n_values['CNT_cur_dec_plc'] = $this->request->getRequestParam( |
|
1145 | - "cntry[$CNT_ISO][CNT_cur_dec_plc]", |
|
1146 | - $country->currency_decimal_places() |
|
1147 | - ); |
|
1148 | - $cols_n_values['CNT_cur_dec_mrk'] = $this->request->getRequestParam( |
|
1149 | - "cntry[$CNT_ISO][CNT_cur_dec_mrk]", |
|
1150 | - $country->currency_decimal_mark() |
|
1151 | - ); |
|
1152 | - $cols_n_values['CNT_cur_thsnds'] = $this->request->getRequestParam( |
|
1153 | - "cntry[$CNT_ISO][CNT_cur_thsnds]", |
|
1154 | - $country->currency_thousands_separator() |
|
1155 | - ); |
|
1156 | - $cols_n_values['CNT_tel_code'] = $this->request->getRequestParam( |
|
1157 | - "cntry[$CNT_ISO][CNT_tel_code]", |
|
1158 | - $country->telephoneCode() |
|
1159 | - ); |
|
1160 | - $cols_n_values['CNT_active'] = $this->request->getRequestParam( |
|
1161 | - "cntry[$CNT_ISO][CNT_active]", |
|
1162 | - $country->isActive(), |
|
1163 | - DataType::BOOL |
|
1164 | - ); |
|
1165 | - |
|
1166 | - // allow filtering of country data |
|
1167 | - $cols_n_values = apply_filters( |
|
1168 | - 'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values', |
|
1169 | - $cols_n_values |
|
1170 | - ); |
|
1171 | - |
|
1172 | - // where values |
|
1173 | - $where_cols_n_values = [['CNT_ISO' => $CNT_ISO]]; |
|
1174 | - // run the update |
|
1175 | - $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values); |
|
1176 | - |
|
1177 | - // allow filtering of states data |
|
1178 | - $states = apply_filters( |
|
1179 | - 'FHEE__General_Settings_Admin_Page___update_country_settings__states', |
|
1180 | - $this->request->getRequestParam('states', [], DataType::STRING, true) |
|
1181 | - ); |
|
1182 | - |
|
1183 | - if (! empty($states) && $success !== false) { |
|
1184 | - // loop thru state data ( looks like : states[75][STA_name] ) |
|
1185 | - foreach ($states as $STA_ID => $state) { |
|
1186 | - $cols_n_values = [ |
|
1187 | - 'CNT_ISO' => $CNT_ISO, |
|
1188 | - 'STA_abbrev' => sanitize_text_field($state['STA_abbrev']), |
|
1189 | - 'STA_name' => sanitize_text_field($state['STA_name']), |
|
1190 | - 'STA_active' => filter_var($state['STA_active'], FILTER_VALIDATE_BOOLEAN), |
|
1191 | - ]; |
|
1192 | - // where values |
|
1193 | - $where_cols_n_values = [['STA_ID' => $STA_ID]]; |
|
1194 | - // run the update |
|
1195 | - $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values); |
|
1196 | - if ($success !== false) { |
|
1197 | - do_action( |
|
1198 | - 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
1199 | - $CNT_ISO, |
|
1200 | - $STA_ID, |
|
1201 | - $cols_n_values |
|
1202 | - ); |
|
1203 | - } |
|
1204 | - } |
|
1205 | - } |
|
1206 | - // check if country being edited matches org option country, and if so, then update EE_Config with new settings |
|
1207 | - if ( |
|
1208 | - isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
1209 | - && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO |
|
1210 | - ) { |
|
1211 | - EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO); |
|
1212 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
1213 | - } |
|
1214 | - |
|
1215 | - if ($success !== false) { |
|
1216 | - EE_Error::add_success( |
|
1217 | - esc_html__('Country Settings updated successfully.', 'event_espresso') |
|
1218 | - ); |
|
1219 | - } |
|
1220 | - $this->_redirect_after_action( |
|
1221 | - $success, |
|
1222 | - '', |
|
1223 | - '', |
|
1224 | - ['action' => 'country_settings', 'country' => $CNT_ISO], |
|
1225 | - true |
|
1226 | - ); |
|
1227 | - } |
|
1228 | - |
|
1229 | - |
|
1230 | - /** |
|
1231 | - * form_form_field_label_wrap |
|
1232 | - * |
|
1233 | - * @param string $label |
|
1234 | - * @return string |
|
1235 | - */ |
|
1236 | - public function country_form_field_label_wrap(string $label): string |
|
1237 | - { |
|
1238 | - return ' |
|
23 | + /** |
|
24 | + * @var EE_Core_Config |
|
25 | + */ |
|
26 | + public $core_config; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * Initialize basic properties. |
|
31 | + */ |
|
32 | + protected function _init_page_props() |
|
33 | + { |
|
34 | + $this->page_slug = GEN_SET_PG_SLUG; |
|
35 | + $this->page_label = GEN_SET_LABEL; |
|
36 | + $this->_admin_base_url = GEN_SET_ADMIN_URL; |
|
37 | + $this->_admin_base_path = GEN_SET_ADMIN; |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * Set ajax hooks |
|
43 | + */ |
|
44 | + protected function _ajax_hooks() |
|
45 | + { |
|
46 | + add_action('wp_ajax_espresso_display_country_settings', [$this, 'display_country_settings']); |
|
47 | + add_action('wp_ajax_espresso_display_country_states', [$this, 'display_country_states']); |
|
48 | + add_action('wp_ajax_espresso_delete_state', [$this, 'delete_state'], 10, 3); |
|
49 | + add_action('wp_ajax_espresso_add_new_state', [$this, 'add_new_state']); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * More page properties initialization. |
|
55 | + */ |
|
56 | + protected function _define_page_props() |
|
57 | + { |
|
58 | + $this->_admin_page_title = GEN_SET_LABEL; |
|
59 | + $this->_labels = ['publishbox' => esc_html__('Update Settings', 'event_espresso')]; |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * Set page routes property. |
|
65 | + */ |
|
66 | + protected function _set_page_routes() |
|
67 | + { |
|
68 | + $this->_page_routes = [ |
|
69 | + 'critical_pages' => [ |
|
70 | + 'func' => '_espresso_page_settings', |
|
71 | + 'capability' => 'manage_options', |
|
72 | + ], |
|
73 | + 'update_espresso_page_settings' => [ |
|
74 | + 'func' => '_update_espresso_page_settings', |
|
75 | + 'capability' => 'manage_options', |
|
76 | + 'noheader' => true, |
|
77 | + ], |
|
78 | + 'default' => [ |
|
79 | + 'func' => '_your_organization_settings', |
|
80 | + 'capability' => 'manage_options', |
|
81 | + ], |
|
82 | + |
|
83 | + 'update_your_organization_settings' => [ |
|
84 | + 'func' => '_update_your_organization_settings', |
|
85 | + 'capability' => 'manage_options', |
|
86 | + 'noheader' => true, |
|
87 | + ], |
|
88 | + |
|
89 | + 'admin_option_settings' => [ |
|
90 | + 'func' => '_admin_option_settings', |
|
91 | + 'capability' => 'manage_options', |
|
92 | + ], |
|
93 | + |
|
94 | + 'update_admin_option_settings' => [ |
|
95 | + 'func' => '_update_admin_option_settings', |
|
96 | + 'capability' => 'manage_options', |
|
97 | + 'noheader' => true, |
|
98 | + ], |
|
99 | + |
|
100 | + 'country_settings' => [ |
|
101 | + 'func' => '_country_settings', |
|
102 | + 'capability' => 'manage_options', |
|
103 | + ], |
|
104 | + |
|
105 | + 'update_country_settings' => [ |
|
106 | + 'func' => '_update_country_settings', |
|
107 | + 'capability' => 'manage_options', |
|
108 | + 'noheader' => true, |
|
109 | + ], |
|
110 | + |
|
111 | + 'display_country_settings' => [ |
|
112 | + 'func' => 'display_country_settings', |
|
113 | + 'capability' => 'manage_options', |
|
114 | + 'noheader' => true, |
|
115 | + ], |
|
116 | + |
|
117 | + 'add_new_state' => [ |
|
118 | + 'func' => 'add_new_state', |
|
119 | + 'capability' => 'manage_options', |
|
120 | + 'noheader' => true, |
|
121 | + ], |
|
122 | + |
|
123 | + 'delete_state' => [ |
|
124 | + 'func' => 'delete_state', |
|
125 | + 'capability' => 'manage_options', |
|
126 | + 'noheader' => true, |
|
127 | + ], |
|
128 | + 'privacy_settings' => [ |
|
129 | + 'func' => 'privacySettings', |
|
130 | + 'capability' => 'manage_options', |
|
131 | + ], |
|
132 | + 'update_privacy_settings' => [ |
|
133 | + 'func' => 'updatePrivacySettings', |
|
134 | + 'capability' => 'manage_options', |
|
135 | + 'noheader' => true, |
|
136 | + 'headers_sent_route' => 'privacy_settings', |
|
137 | + ], |
|
138 | + ]; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * Set page configuration property |
|
144 | + */ |
|
145 | + protected function _set_page_config() |
|
146 | + { |
|
147 | + $this->_page_config = [ |
|
148 | + 'critical_pages' => [ |
|
149 | + 'nav' => [ |
|
150 | + 'label' => esc_html__('Critical Pages', 'event_espresso'), |
|
151 | + 'order' => 50, |
|
152 | + ], |
|
153 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
154 | + 'help_tabs' => [ |
|
155 | + 'general_settings_critical_pages_help_tab' => [ |
|
156 | + 'title' => esc_html__('Critical Pages', 'event_espresso'), |
|
157 | + 'filename' => 'general_settings_critical_pages', |
|
158 | + ], |
|
159 | + ], |
|
160 | + 'require_nonce' => false, |
|
161 | + ], |
|
162 | + 'default' => [ |
|
163 | + 'nav' => [ |
|
164 | + 'label' => esc_html__('Your Organization', 'event_espresso'), |
|
165 | + 'order' => 20, |
|
166 | + ], |
|
167 | + 'help_tabs' => [ |
|
168 | + 'general_settings_your_organization_help_tab' => [ |
|
169 | + 'title' => esc_html__('Your Organization', 'event_espresso'), |
|
170 | + 'filename' => 'general_settings_your_organization', |
|
171 | + ], |
|
172 | + ], |
|
173 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
174 | + 'require_nonce' => false, |
|
175 | + ], |
|
176 | + 'admin_option_settings' => [ |
|
177 | + 'nav' => [ |
|
178 | + 'label' => esc_html__('Admin Options', 'event_espresso'), |
|
179 | + 'order' => 60, |
|
180 | + ], |
|
181 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
182 | + 'help_tabs' => [ |
|
183 | + 'general_settings_admin_options_help_tab' => [ |
|
184 | + 'title' => esc_html__('Admin Options', 'event_espresso'), |
|
185 | + 'filename' => 'general_settings_admin_options', |
|
186 | + ], |
|
187 | + ], |
|
188 | + 'require_nonce' => false, |
|
189 | + ], |
|
190 | + 'country_settings' => [ |
|
191 | + 'nav' => [ |
|
192 | + 'label' => esc_html__('Countries', 'event_espresso'), |
|
193 | + 'order' => 70, |
|
194 | + ], |
|
195 | + 'help_tabs' => [ |
|
196 | + 'general_settings_countries_help_tab' => [ |
|
197 | + 'title' => esc_html__('Countries', 'event_espresso'), |
|
198 | + 'filename' => 'general_settings_countries', |
|
199 | + ], |
|
200 | + ], |
|
201 | + 'require_nonce' => false, |
|
202 | + ], |
|
203 | + 'privacy_settings' => [ |
|
204 | + 'nav' => [ |
|
205 | + 'label' => esc_html__('Privacy', 'event_espresso'), |
|
206 | + 'order' => 80, |
|
207 | + ], |
|
208 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
209 | + 'require_nonce' => false, |
|
210 | + ], |
|
211 | + ]; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + protected function _add_screen_options() |
|
216 | + { |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + protected function _add_feature_pointers() |
|
221 | + { |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * Enqueue global scripts and styles for all routes in the General Settings Admin Pages. |
|
227 | + */ |
|
228 | + public function load_scripts_styles() |
|
229 | + { |
|
230 | + // styles |
|
231 | + wp_enqueue_style('espresso-ui-theme'); |
|
232 | + // scripts |
|
233 | + wp_enqueue_script('ee_admin_js'); |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * Execute logic running on `admin_init` |
|
239 | + */ |
|
240 | + public function admin_init() |
|
241 | + { |
|
242 | + $this->core_config = EE_Registry::instance()->CFG->core; |
|
243 | + |
|
244 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags( |
|
245 | + esc_html__( |
|
246 | + 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
247 | + 'event_espresso' |
|
248 | + ) |
|
249 | + ); |
|
250 | + EE_Registry::$i18n_js_strings['error_occurred'] = wp_strip_all_tags( |
|
251 | + esc_html__( |
|
252 | + 'An error occurred! Please refresh the page and try again.', |
|
253 | + 'event_espresso' |
|
254 | + ) |
|
255 | + ); |
|
256 | + EE_Registry::$i18n_js_strings['confirm_delete_state'] = wp_strip_all_tags( |
|
257 | + esc_html__( |
|
258 | + 'Are you sure you want to delete this State / Province?', |
|
259 | + 'event_espresso' |
|
260 | + ) |
|
261 | + ); |
|
262 | + EE_Registry::$i18n_js_strings['ajax_url'] = admin_url( |
|
263 | + 'admin-ajax.php?page=espresso_general_settings', |
|
264 | + is_ssl() ? 'https://' : 'http://' |
|
265 | + ); |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + public function admin_notices() |
|
270 | + { |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + public function admin_footer_scripts() |
|
275 | + { |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * Enqueue scripts and styles for the default route. |
|
281 | + */ |
|
282 | + public function load_scripts_styles_default() |
|
283 | + { |
|
284 | + // styles |
|
285 | + wp_enqueue_style('thickbox'); |
|
286 | + // scripts |
|
287 | + wp_enqueue_script('media-upload'); |
|
288 | + wp_enqueue_script('thickbox'); |
|
289 | + wp_register_script( |
|
290 | + 'organization_settings', |
|
291 | + GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
292 | + ['jquery', 'media-upload', 'thickbox'], |
|
293 | + EVENT_ESPRESSO_VERSION, |
|
294 | + true |
|
295 | + ); |
|
296 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION); |
|
297 | + wp_enqueue_script('organization_settings'); |
|
298 | + wp_enqueue_style('organization-css'); |
|
299 | + $confirm_image_delete = [ |
|
300 | + 'text' => wp_strip_all_tags( |
|
301 | + esc_html__( |
|
302 | + 'Do you really want to delete this image? Please remember to save your settings to complete the removal.', |
|
303 | + 'event_espresso' |
|
304 | + ) |
|
305 | + ), |
|
306 | + ]; |
|
307 | + wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete); |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * Enqueue scripts and styles for the country settings route. |
|
313 | + */ |
|
314 | + public function load_scripts_styles_country_settings() |
|
315 | + { |
|
316 | + // scripts |
|
317 | + wp_register_script( |
|
318 | + 'gen_settings_countries', |
|
319 | + GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
320 | + ['ee_admin_js'], |
|
321 | + EVENT_ESPRESSO_VERSION, |
|
322 | + true |
|
323 | + ); |
|
324 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION); |
|
325 | + wp_enqueue_script('gen_settings_countries'); |
|
326 | + wp_enqueue_style('organization-css'); |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /************* Espresso Pages *************/ |
|
331 | + /** |
|
332 | + * _espresso_page_settings |
|
333 | + * |
|
334 | + * @throws EE_Error |
|
335 | + * @throws DomainException |
|
336 | + * @throws DomainException |
|
337 | + * @throws InvalidDataTypeException |
|
338 | + * @throws InvalidArgumentException |
|
339 | + */ |
|
340 | + protected function _espresso_page_settings() |
|
341 | + { |
|
342 | + // Check to make sure all of the main pages are set up properly, |
|
343 | + // if not create the default pages and display an admin notice |
|
344 | + EEH_Activation::verify_default_pages_exist(); |
|
345 | + $this->_transient_garbage_collection(); |
|
346 | + |
|
347 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
348 | + |
|
349 | + $this->_template_args['reg_page_id'] = $this->core_config->reg_page_id ?? null; |
|
350 | + $this->_template_args['reg_page_obj'] = isset($this->core_config->reg_page_id) |
|
351 | + ? get_post($this->core_config->reg_page_id) |
|
352 | + : false; |
|
353 | + |
|
354 | + $this->_template_args['txn_page_id'] = $this->core_config->txn_page_id ?? null; |
|
355 | + $this->_template_args['txn_page_obj'] = isset($this->core_config->txn_page_id) |
|
356 | + ? get_post($this->core_config->txn_page_id) |
|
357 | + : false; |
|
358 | + |
|
359 | + $this->_template_args['thank_you_page_id'] = $this->core_config->thank_you_page_id ?? null; |
|
360 | + $this->_template_args['thank_you_page_obj'] = isset($this->core_config->thank_you_page_id) |
|
361 | + ? get_post($this->core_config->thank_you_page_id) |
|
362 | + : false; |
|
363 | + |
|
364 | + $this->_template_args['cancel_page_id'] = $this->core_config->cancel_page_id ?? null; |
|
365 | + $this->_template_args['cancel_page_obj'] = isset($this->core_config->cancel_page_id) |
|
366 | + ? get_post($this->core_config->cancel_page_id) |
|
367 | + : false; |
|
368 | + |
|
369 | + $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
|
370 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
371 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
372 | + GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
373 | + $this->_template_args, |
|
374 | + true |
|
375 | + ); |
|
376 | + $this->display_admin_page_with_sidebar(); |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * Handler for updating espresso page settings. |
|
382 | + * |
|
383 | + * @throws EE_Error |
|
384 | + */ |
|
385 | + protected function _update_espresso_page_settings() |
|
386 | + { |
|
387 | + // capture incoming request data && set page IDs |
|
388 | + $this->core_config->reg_page_id = $this->request->getRequestParam( |
|
389 | + 'reg_page_id', |
|
390 | + $this->core_config->reg_page_id, |
|
391 | + DataType::INT |
|
392 | + ); |
|
393 | + $this->core_config->txn_page_id = $this->request->getRequestParam( |
|
394 | + 'txn_page_id', |
|
395 | + $this->core_config->txn_page_id, |
|
396 | + DataType::INT |
|
397 | + ); |
|
398 | + $this->core_config->thank_you_page_id = $this->request->getRequestParam( |
|
399 | + 'thank_you_page_id', |
|
400 | + $this->core_config->thank_you_page_id, |
|
401 | + DataType::INT |
|
402 | + ); |
|
403 | + $this->core_config->cancel_page_id = $this->request->getRequestParam( |
|
404 | + 'cancel_page_id', |
|
405 | + $this->core_config->cancel_page_id, |
|
406 | + DataType::INT |
|
407 | + ); |
|
408 | + |
|
409 | + $this->core_config = apply_filters( |
|
410 | + 'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core', |
|
411 | + $this->core_config, |
|
412 | + $this->request->requestParams() |
|
413 | + ); |
|
414 | + |
|
415 | + $what = esc_html__('Critical Pages & Shortcodes', 'event_espresso'); |
|
416 | + $this->_redirect_after_action( |
|
417 | + $this->_update_espresso_configuration( |
|
418 | + $what, |
|
419 | + $this->core_config, |
|
420 | + __FILE__, |
|
421 | + __FUNCTION__, |
|
422 | + __LINE__ |
|
423 | + ), |
|
424 | + $what, |
|
425 | + '', |
|
426 | + [ |
|
427 | + 'action' => 'critical_pages', |
|
428 | + ], |
|
429 | + true |
|
430 | + ); |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + /************* Your Organization *************/ |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * @throws DomainException |
|
439 | + * @throws EE_Error |
|
440 | + * @throws InvalidArgumentException |
|
441 | + * @throws InvalidDataTypeException |
|
442 | + * @throws InvalidInterfaceException |
|
443 | + */ |
|
444 | + protected function _your_organization_settings() |
|
445 | + { |
|
446 | + $this->_template_args['admin_page_content'] = ''; |
|
447 | + try { |
|
448 | + /** @var OrganizationSettings $organization_settings_form */ |
|
449 | + $organization_settings_form = $this->loader->getShared(OrganizationSettings::class); |
|
450 | + |
|
451 | + $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
452 | + $organization_settings_form->display(), |
|
453 | + '', |
|
454 | + 'padding' |
|
455 | + ); |
|
456 | + } catch (Exception $e) { |
|
457 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
458 | + } |
|
459 | + $this->_set_add_edit_form_tags('update_your_organization_settings'); |
|
460 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
461 | + $this->display_admin_page_with_sidebar(); |
|
462 | + } |
|
463 | + |
|
464 | + |
|
465 | + /** |
|
466 | + * Handler for updating organization settings. |
|
467 | + * |
|
468 | + * @throws EE_Error |
|
469 | + */ |
|
470 | + protected function _update_your_organization_settings() |
|
471 | + { |
|
472 | + try { |
|
473 | + /** @var OrganizationSettings $organization_settings_form */ |
|
474 | + $organization_settings_form = $this->loader->getShared(OrganizationSettings::class); |
|
475 | + |
|
476 | + $success = $organization_settings_form->process($this->request->requestParams()); |
|
477 | + |
|
478 | + EE_Registry::instance()->CFG = apply_filters( |
|
479 | + 'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG', |
|
480 | + EE_Registry::instance()->CFG |
|
481 | + ); |
|
482 | + } catch (Exception $e) { |
|
483 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
484 | + $success = false; |
|
485 | + } |
|
486 | + |
|
487 | + if ($success) { |
|
488 | + $success = $this->_update_espresso_configuration( |
|
489 | + esc_html__('Your Organization Settings', 'event_espresso'), |
|
490 | + EE_Registry::instance()->CFG, |
|
491 | + __FILE__, |
|
492 | + __FUNCTION__, |
|
493 | + __LINE__ |
|
494 | + ); |
|
495 | + } |
|
496 | + |
|
497 | + $this->_redirect_after_action($success, '', '', ['action' => 'default'], true); |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + |
|
502 | + /************* Admin Options *************/ |
|
503 | + |
|
504 | + |
|
505 | + /** |
|
506 | + * _admin_option_settings |
|
507 | + * |
|
508 | + * @throws EE_Error |
|
509 | + * @throws LogicException |
|
510 | + */ |
|
511 | + protected function _admin_option_settings() |
|
512 | + { |
|
513 | + $this->_template_args['admin_page_content'] = ''; |
|
514 | + try { |
|
515 | + $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
516 | + // still need this for the old school form in Extend_General_Settings_Admin_Page |
|
517 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
518 | + // also need to account for the do_action that was in the old template |
|
519 | + $admin_options_settings_form->setTemplateArgs($this->_template_args); |
|
520 | + $this->_template_args['admin_page_content'] = $admin_options_settings_form->display(); |
|
521 | + } catch (Exception $e) { |
|
522 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
523 | + } |
|
524 | + $this->_set_add_edit_form_tags('update_admin_option_settings'); |
|
525 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
526 | + $this->display_admin_page_with_sidebar(); |
|
527 | + } |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * _update_admin_option_settings |
|
532 | + * |
|
533 | + * @throws EE_Error |
|
534 | + * @throws InvalidDataTypeException |
|
535 | + * @throws InvalidFormSubmissionException |
|
536 | + * @throws InvalidArgumentException |
|
537 | + * @throws LogicException |
|
538 | + */ |
|
539 | + protected function _update_admin_option_settings() |
|
540 | + { |
|
541 | + try { |
|
542 | + $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
543 | + $admin_options_settings_form->process( |
|
544 | + $this->request->getRequestParam( |
|
545 | + $admin_options_settings_form->slug(), |
|
546 | + [], |
|
547 | + DataType::OBJECT // need to change this to ARRAY after min PHP version gets bumped to 7+ |
|
548 | + ) |
|
549 | + ); |
|
550 | + EE_Registry::instance()->CFG->admin = apply_filters( |
|
551 | + 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
|
552 | + EE_Registry::instance()->CFG->admin |
|
553 | + ); |
|
554 | + } catch (Exception $e) { |
|
555 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
556 | + } |
|
557 | + $this->_redirect_after_action( |
|
558 | + apply_filters( |
|
559 | + 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', |
|
560 | + $this->_update_espresso_configuration( |
|
561 | + esc_html__('Admin Options', 'event_espresso'), |
|
562 | + EE_Registry::instance()->CFG->admin, |
|
563 | + __FILE__, |
|
564 | + __FUNCTION__, |
|
565 | + __LINE__ |
|
566 | + ) |
|
567 | + ), |
|
568 | + esc_html__('Admin Options', 'event_espresso'), |
|
569 | + 'updated', |
|
570 | + ['action' => 'admin_option_settings'] |
|
571 | + ); |
|
572 | + } |
|
573 | + |
|
574 | + |
|
575 | + /************* Countries *************/ |
|
576 | + |
|
577 | + |
|
578 | + /** |
|
579 | + * @param string|null $default |
|
580 | + * @return string |
|
581 | + */ |
|
582 | + protected function getCountryISO(?string $default = null): string |
|
583 | + { |
|
584 | + $default = $default ?? $this->getCountryIsoForSite(); |
|
585 | + $CNT_ISO = $this->request->getRequestParam('country', $default); |
|
586 | + $CNT_ISO = $this->request->getRequestParam('CNT_ISO', $CNT_ISO); |
|
587 | + return strtoupper($CNT_ISO); |
|
588 | + } |
|
589 | + |
|
590 | + |
|
591 | + /** |
|
592 | + * @return string |
|
593 | + */ |
|
594 | + protected function getCountryIsoForSite(): string |
|
595 | + { |
|
596 | + return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
597 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
598 | + : 'US'; |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * @param string $CNT_ISO |
|
604 | + * @param EE_Country|null $country |
|
605 | + * @return EE_Base_Class|EE_Country |
|
606 | + * @throws EE_Error |
|
607 | + * @throws InvalidArgumentException |
|
608 | + * @throws InvalidDataTypeException |
|
609 | + * @throws InvalidInterfaceException |
|
610 | + * @throws ReflectionException |
|
611 | + */ |
|
612 | + protected function verifyOrGetCountryFromIso(string $CNT_ISO, ?EE_Country $country = null) |
|
613 | + { |
|
614 | + /** @var EE_Country $country */ |
|
615 | + return $country instanceof EE_Country && $country->ID() === $CNT_ISO |
|
616 | + ? $country |
|
617 | + : EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
618 | + } |
|
619 | + |
|
620 | + |
|
621 | + /** |
|
622 | + * Output Country Settings view. |
|
623 | + * |
|
624 | + * @throws DomainException |
|
625 | + * @throws EE_Error |
|
626 | + * @throws InvalidArgumentException |
|
627 | + * @throws InvalidDataTypeException |
|
628 | + * @throws InvalidInterfaceException |
|
629 | + * @throws ReflectionException |
|
630 | + */ |
|
631 | + protected function _country_settings() |
|
632 | + { |
|
633 | + $CNT_ISO = $this->getCountryISO(); |
|
634 | + |
|
635 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
636 | + $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
637 | + EE_Question::new_instance( |
|
638 | + [ |
|
639 | + 'QST_ID' => 0, |
|
640 | + 'QST_display_text' => esc_html__('Select Country', 'event_espresso'), |
|
641 | + 'QST_system' => 'admin-country', |
|
642 | + ] |
|
643 | + ), |
|
644 | + EE_Answer::new_instance( |
|
645 | + [ |
|
646 | + 'ANS_ID' => 0, |
|
647 | + 'ANS_value' => $CNT_ISO, |
|
648 | + ] |
|
649 | + ), |
|
650 | + [ |
|
651 | + 'input_id' => 'country', |
|
652 | + 'input_name' => 'country', |
|
653 | + 'input_prefix' => '', |
|
654 | + 'append_qstn_id' => false, |
|
655 | + ] |
|
656 | + ); |
|
657 | + |
|
658 | + $country = $this->verifyOrGetCountryFromIso($CNT_ISO); |
|
659 | + add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10); |
|
660 | + add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10); |
|
661 | + $this->_template_args['country_details_settings'] = $this->display_country_settings( |
|
662 | + $country->ID(), |
|
663 | + $country |
|
664 | + ); |
|
665 | + $this->_template_args['country_states_settings'] = $this->display_country_states( |
|
666 | + $country->ID(), |
|
667 | + $country |
|
668 | + ); |
|
669 | + $this->_template_args['CNT_name_for_site'] = $country->name(); |
|
670 | + |
|
671 | + $this->_set_add_edit_form_tags('update_country_settings'); |
|
672 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
673 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
674 | + GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
675 | + $this->_template_args, |
|
676 | + true |
|
677 | + ); |
|
678 | + $this->display_admin_page_with_no_sidebar(); |
|
679 | + } |
|
680 | + |
|
681 | + |
|
682 | + /** |
|
683 | + * @param string $CNT_ISO |
|
684 | + * @param EE_Country|null $country |
|
685 | + * @return string |
|
686 | + * @throws DomainException |
|
687 | + * @throws EE_Error |
|
688 | + * @throws InvalidArgumentException |
|
689 | + * @throws InvalidDataTypeException |
|
690 | + * @throws InvalidInterfaceException |
|
691 | + * @throws ReflectionException |
|
692 | + */ |
|
693 | + public function display_country_settings(string $CNT_ISO = '', ?EE_Country $country = null): string |
|
694 | + { |
|
695 | + $CNT_ISO = $this->getCountryISO($CNT_ISO); |
|
696 | + $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
|
697 | + |
|
698 | + if (! $CNT_ISO) { |
|
699 | + return ''; |
|
700 | + } |
|
701 | + |
|
702 | + // for ajax |
|
703 | + remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
704 | + remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
705 | + add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10, 2); |
|
706 | + add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10, 2); |
|
707 | + $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
708 | + $CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site; |
|
709 | + $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled; |
|
710 | + |
|
711 | + $country_input_types = [ |
|
712 | + 'CNT_active' => [ |
|
713 | + 'type' => 'RADIO_BTN', |
|
714 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
715 | + 'class' => '', |
|
716 | + 'options' => $this->_yes_no_values, |
|
717 | + 'use_desc_4_label' => true, |
|
718 | + ], |
|
719 | + 'CNT_ISO' => [ |
|
720 | + 'type' => 'TEXT', |
|
721 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
722 | + 'class' => 'small-text', |
|
723 | + ], |
|
724 | + 'CNT_ISO3' => [ |
|
725 | + 'type' => 'TEXT', |
|
726 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
727 | + 'class' => 'small-text', |
|
728 | + ], |
|
729 | + // 'RGN_ID' => [ |
|
730 | + // 'type' => 'TEXT', |
|
731 | + // 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
732 | + // 'class' => 'ee-input-size--small', |
|
733 | + // ], |
|
734 | + 'CNT_name' => [ |
|
735 | + 'type' => 'TEXT', |
|
736 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
737 | + 'class' => 'regular-text', |
|
738 | + ], |
|
739 | + 'CNT_cur_code' => [ |
|
740 | + 'type' => 'TEXT', |
|
741 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
742 | + 'class' => 'small-text', |
|
743 | + 'disabled' => $CNT_cur_disabled, |
|
744 | + ], |
|
745 | + 'CNT_cur_single' => [ |
|
746 | + 'type' => 'TEXT', |
|
747 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
748 | + 'class' => 'medium-text', |
|
749 | + 'disabled' => $CNT_cur_disabled, |
|
750 | + ], |
|
751 | + 'CNT_cur_plural' => [ |
|
752 | + 'type' => 'TEXT', |
|
753 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
754 | + 'class' => 'medium-text', |
|
755 | + 'disabled' => $CNT_cur_disabled, |
|
756 | + ], |
|
757 | + 'CNT_cur_sign' => [ |
|
758 | + 'type' => 'TEXT', |
|
759 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
760 | + 'class' => 'small-text', |
|
761 | + 'htmlentities' => false, |
|
762 | + 'disabled' => $CNT_cur_disabled, |
|
763 | + ], |
|
764 | + 'CNT_cur_sign_b4' => [ |
|
765 | + 'type' => 'RADIO_BTN', |
|
766 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
767 | + 'class' => '', |
|
768 | + 'options' => $this->_yes_no_values, |
|
769 | + 'use_desc_4_label' => true, |
|
770 | + 'disabled' => $CNT_cur_disabled, |
|
771 | + ], |
|
772 | + 'CNT_cur_dec_plc' => [ |
|
773 | + 'type' => 'RADIO_BTN', |
|
774 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
775 | + 'class' => '', |
|
776 | + 'options' => [ |
|
777 | + ['id' => 0, 'text' => ''], |
|
778 | + ['id' => 1, 'text' => ''], |
|
779 | + ['id' => 2, 'text' => ''], |
|
780 | + ['id' => 3, 'text' => ''], |
|
781 | + ], |
|
782 | + 'disabled' => $CNT_cur_disabled, |
|
783 | + ], |
|
784 | + 'CNT_cur_dec_mrk' => [ |
|
785 | + 'type' => 'RADIO_BTN', |
|
786 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
787 | + 'class' => '', |
|
788 | + 'options' => [ |
|
789 | + [ |
|
790 | + 'id' => ',', |
|
791 | + 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
792 | + ], |
|
793 | + ['id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')], |
|
794 | + ], |
|
795 | + 'use_desc_4_label' => true, |
|
796 | + 'disabled' => $CNT_cur_disabled, |
|
797 | + ], |
|
798 | + 'CNT_cur_thsnds' => [ |
|
799 | + 'type' => 'RADIO_BTN', |
|
800 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
801 | + 'class' => '', |
|
802 | + 'options' => [ |
|
803 | + [ |
|
804 | + 'id' => ',', |
|
805 | + 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
806 | + ], |
|
807 | + [ |
|
808 | + 'id' => '.', |
|
809 | + 'text' => esc_html__('. (decimal)', 'event_espresso'), |
|
810 | + ], |
|
811 | + [ |
|
812 | + 'id' => ' ', |
|
813 | + 'text' => esc_html__('(space)', 'event_espresso'), |
|
814 | + ], |
|
815 | + ], |
|
816 | + 'use_desc_4_label' => true, |
|
817 | + 'disabled' => $CNT_cur_disabled, |
|
818 | + ], |
|
819 | + 'CNT_tel_code' => [ |
|
820 | + 'type' => 'TEXT', |
|
821 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
822 | + 'class' => 'small-text', |
|
823 | + ], |
|
824 | + 'CNT_is_EU' => [ |
|
825 | + 'type' => 'RADIO_BTN', |
|
826 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
827 | + 'class' => '', |
|
828 | + 'options' => $this->_yes_no_values, |
|
829 | + 'use_desc_4_label' => true, |
|
830 | + ], |
|
831 | + ]; |
|
832 | + $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
833 | + $country, |
|
834 | + $country_input_types |
|
835 | + ); |
|
836 | + $country_details_settings = EEH_Template::display_template( |
|
837 | + GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
838 | + $this->_template_args, |
|
839 | + true |
|
840 | + ); |
|
841 | + |
|
842 | + if (defined('DOING_AJAX')) { |
|
843 | + $notices = EE_Error::get_notices(false, false, false); |
|
844 | + echo wp_json_encode( |
|
845 | + [ |
|
846 | + 'return_data' => $country_details_settings, |
|
847 | + 'success' => $notices['success'], |
|
848 | + 'errors' => $notices['errors'], |
|
849 | + ] |
|
850 | + ); |
|
851 | + die(); |
|
852 | + } |
|
853 | + return $country_details_settings; |
|
854 | + } |
|
855 | + |
|
856 | + |
|
857 | + /** |
|
858 | + * @param string $CNT_ISO |
|
859 | + * @param EE_Country|null $country |
|
860 | + * @return string |
|
861 | + * @throws DomainException |
|
862 | + * @throws EE_Error |
|
863 | + * @throws InvalidArgumentException |
|
864 | + * @throws InvalidDataTypeException |
|
865 | + * @throws InvalidInterfaceException |
|
866 | + * @throws ReflectionException |
|
867 | + */ |
|
868 | + public function display_country_states(string $CNT_ISO = '', ?EE_Country $country = null): string |
|
869 | + { |
|
870 | + $CNT_ISO = $this->getCountryISO($CNT_ISO); |
|
871 | + if (! $CNT_ISO) { |
|
872 | + return ''; |
|
873 | + } |
|
874 | + // for ajax |
|
875 | + remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
876 | + remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
877 | + add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'state_form_field_label_wrap'], 10, 2); |
|
878 | + add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'state_form_field_input__wrap'], 10); |
|
879 | + $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]); |
|
880 | + if (empty($states)) { |
|
881 | + /** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */ |
|
882 | + $countrySubRegionDao = $this->loader->getShared( |
|
883 | + 'EventEspresso\core\services\address\CountrySubRegionDao' |
|
884 | + ); |
|
885 | + if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) { |
|
886 | + $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
887 | + if ($countrySubRegionDao->saveCountrySubRegions($country)) { |
|
888 | + $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]); |
|
889 | + } |
|
890 | + } |
|
891 | + } |
|
892 | + if (is_array($states)) { |
|
893 | + foreach ($states as $STA_ID => $state) { |
|
894 | + if ($state instanceof EE_State) { |
|
895 | + $inputs = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
896 | + $state, |
|
897 | + [ |
|
898 | + 'STA_abbrev' => [ |
|
899 | + 'type' => 'TEXT', |
|
900 | + 'label' => esc_html__('Code', 'event_espresso'), |
|
901 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
902 | + 'class' => 'small-text', |
|
903 | + 'add_mobile_label' => true, |
|
904 | + ], |
|
905 | + 'STA_name' => [ |
|
906 | + 'type' => 'TEXT', |
|
907 | + 'label' => esc_html__('Name', 'event_espresso'), |
|
908 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
909 | + 'class' => 'regular-text', |
|
910 | + 'add_mobile_label' => true, |
|
911 | + ], |
|
912 | + 'STA_active' => [ |
|
913 | + 'type' => 'RADIO_BTN', |
|
914 | + 'label' => esc_html__( |
|
915 | + 'State Appears in Dropdown Select Lists', |
|
916 | + 'event_espresso' |
|
917 | + ), |
|
918 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
919 | + 'options' => $this->_yes_no_values, |
|
920 | + 'use_desc_4_label' => true, |
|
921 | + 'add_mobile_label' => true, |
|
922 | + ], |
|
923 | + ] |
|
924 | + ); |
|
925 | + |
|
926 | + $delete_state_url = EE_Admin_Page::add_query_args_and_nonce( |
|
927 | + [ |
|
928 | + 'action' => 'delete_state', |
|
929 | + 'STA_ID' => $STA_ID, |
|
930 | + 'CNT_ISO' => $CNT_ISO, |
|
931 | + 'STA_abbrev' => $state->abbrev(), |
|
932 | + ], |
|
933 | + GEN_SET_ADMIN_URL |
|
934 | + ); |
|
935 | + |
|
936 | + $this->_template_args['states'][ $STA_ID ]['inputs'] = $inputs; |
|
937 | + $this->_template_args['states'][ $STA_ID ]['delete_state_url'] = $delete_state_url; |
|
938 | + } |
|
939 | + } |
|
940 | + } else { |
|
941 | + $this->_template_args['states'] = false; |
|
942 | + } |
|
943 | + |
|
944 | + $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
945 | + ['action' => 'add_new_state'], |
|
946 | + GEN_SET_ADMIN_URL |
|
947 | + ); |
|
948 | + |
|
949 | + $state_details_settings = EEH_Template::display_template( |
|
950 | + GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
951 | + $this->_template_args, |
|
952 | + true |
|
953 | + ); |
|
954 | + |
|
955 | + if (defined('DOING_AJAX')) { |
|
956 | + $notices = EE_Error::get_notices(false, false, false); |
|
957 | + echo wp_json_encode( |
|
958 | + [ |
|
959 | + 'return_data' => $state_details_settings, |
|
960 | + 'success' => $notices['success'], |
|
961 | + 'errors' => $notices['errors'], |
|
962 | + ] |
|
963 | + ); |
|
964 | + die(); |
|
965 | + } |
|
966 | + return $state_details_settings; |
|
967 | + } |
|
968 | + |
|
969 | + |
|
970 | + /** |
|
971 | + * @return void |
|
972 | + * @throws EE_Error |
|
973 | + * @throws InvalidArgumentException |
|
974 | + * @throws InvalidDataTypeException |
|
975 | + * @throws InvalidInterfaceException |
|
976 | + * @throws ReflectionException |
|
977 | + */ |
|
978 | + public function add_new_state() |
|
979 | + { |
|
980 | + $success = true; |
|
981 | + $CNT_ISO = $this->getCountryISO(''); |
|
982 | + if (! $CNT_ISO) { |
|
983 | + EE_Error::add_error( |
|
984 | + esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
985 | + __FILE__, |
|
986 | + __FUNCTION__, |
|
987 | + __LINE__ |
|
988 | + ); |
|
989 | + $success = false; |
|
990 | + } |
|
991 | + $STA_abbrev = $this->request->getRequestParam('STA_abbrev'); |
|
992 | + if (! $STA_abbrev) { |
|
993 | + EE_Error::add_error( |
|
994 | + esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
|
995 | + __FILE__, |
|
996 | + __FUNCTION__, |
|
997 | + __LINE__ |
|
998 | + ); |
|
999 | + $success = false; |
|
1000 | + } |
|
1001 | + $STA_name = $this->request->getRequestParam('STA_name'); |
|
1002 | + if (! $STA_name) { |
|
1003 | + EE_Error::add_error( |
|
1004 | + esc_html__('No State name or an invalid State name was received.', 'event_espresso'), |
|
1005 | + __FILE__, |
|
1006 | + __FUNCTION__, |
|
1007 | + __LINE__ |
|
1008 | + ); |
|
1009 | + $success = false; |
|
1010 | + } |
|
1011 | + |
|
1012 | + if ($success) { |
|
1013 | + $cols_n_values = [ |
|
1014 | + 'CNT_ISO' => $CNT_ISO, |
|
1015 | + 'STA_abbrev' => $STA_abbrev, |
|
1016 | + 'STA_name' => $STA_name, |
|
1017 | + 'STA_active' => true, |
|
1018 | + ]; |
|
1019 | + $success = EEM_State::instance()->insert($cols_n_values); |
|
1020 | + EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso')); |
|
1021 | + } |
|
1022 | + |
|
1023 | + if (defined('DOING_AJAX')) { |
|
1024 | + $notices = EE_Error::get_notices(false, false, false); |
|
1025 | + echo wp_json_encode(array_merge($notices, ['return_data' => $CNT_ISO])); |
|
1026 | + die(); |
|
1027 | + } else { |
|
1028 | + $this->_redirect_after_action( |
|
1029 | + $success, |
|
1030 | + esc_html__('State', 'event_espresso'), |
|
1031 | + 'added', |
|
1032 | + ['action' => 'country_settings'] |
|
1033 | + ); |
|
1034 | + } |
|
1035 | + } |
|
1036 | + |
|
1037 | + |
|
1038 | + /** |
|
1039 | + * @return void |
|
1040 | + * @throws EE_Error |
|
1041 | + * @throws InvalidArgumentException |
|
1042 | + * @throws InvalidDataTypeException |
|
1043 | + * @throws InvalidInterfaceException |
|
1044 | + * @throws ReflectionException |
|
1045 | + */ |
|
1046 | + public function delete_state() |
|
1047 | + { |
|
1048 | + $CNT_ISO = $this->getCountryISO(); |
|
1049 | + $STA_ID = $this->request->getRequestParam('STA_ID'); |
|
1050 | + $STA_abbrev = $this->request->getRequestParam('STA_abbrev'); |
|
1051 | + |
|
1052 | + if (! $STA_ID) { |
|
1053 | + EE_Error::add_error( |
|
1054 | + esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'), |
|
1055 | + __FILE__, |
|
1056 | + __FUNCTION__, |
|
1057 | + __LINE__ |
|
1058 | + ); |
|
1059 | + return; |
|
1060 | + } |
|
1061 | + |
|
1062 | + $success = EEM_State::instance()->delete_by_ID($STA_ID); |
|
1063 | + if ($success !== false) { |
|
1064 | + do_action( |
|
1065 | + 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
1066 | + $CNT_ISO, |
|
1067 | + $STA_ID, |
|
1068 | + ['STA_abbrev' => $STA_abbrev] |
|
1069 | + ); |
|
1070 | + EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso')); |
|
1071 | + } |
|
1072 | + if (defined('DOING_AJAX')) { |
|
1073 | + $notices = EE_Error::get_notices(false); |
|
1074 | + $notices['return_data'] = true; |
|
1075 | + echo wp_json_encode($notices); |
|
1076 | + die(); |
|
1077 | + } else { |
|
1078 | + $this->_redirect_after_action( |
|
1079 | + $success, |
|
1080 | + esc_html__('State', 'event_espresso'), |
|
1081 | + 'deleted', |
|
1082 | + ['action' => 'country_settings'] |
|
1083 | + ); |
|
1084 | + } |
|
1085 | + } |
|
1086 | + |
|
1087 | + |
|
1088 | + /** |
|
1089 | + * _update_country_settings |
|
1090 | + * |
|
1091 | + * @return void |
|
1092 | + * @throws EE_Error |
|
1093 | + * @throws InvalidArgumentException |
|
1094 | + * @throws InvalidDataTypeException |
|
1095 | + * @throws InvalidInterfaceException |
|
1096 | + * @throws ReflectionException |
|
1097 | + */ |
|
1098 | + protected function _update_country_settings() |
|
1099 | + { |
|
1100 | + $CNT_ISO = $this->getCountryISO(); |
|
1101 | + if (! $CNT_ISO) { |
|
1102 | + EE_Error::add_error( |
|
1103 | + esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
1104 | + __FILE__, |
|
1105 | + __FUNCTION__, |
|
1106 | + __LINE__ |
|
1107 | + ); |
|
1108 | + return; |
|
1109 | + } |
|
1110 | + |
|
1111 | + $country = $this->verifyOrGetCountryFromIso($CNT_ISO); |
|
1112 | + |
|
1113 | + $cols_n_values = []; |
|
1114 | + $cols_n_values['CNT_ISO3'] = strtoupper( |
|
1115 | + $this->request->getRequestParam('cntry', $country->ISO3()) |
|
1116 | + ); |
|
1117 | + $cols_n_values['CNT_name'] = $this->request->getRequestParam( |
|
1118 | + "cntry[$CNT_ISO][CNT_name]", |
|
1119 | + $country->name() |
|
1120 | + ); |
|
1121 | + $cols_n_values['CNT_cur_code'] = strtoupper( |
|
1122 | + $this->request->getRequestParam( |
|
1123 | + "cntry[$CNT_ISO][CNT_cur_code]", |
|
1124 | + $country->currency_code() |
|
1125 | + ) |
|
1126 | + ); |
|
1127 | + $cols_n_values['CNT_cur_single'] = $this->request->getRequestParam( |
|
1128 | + "cntry[$CNT_ISO][CNT_cur_single]", |
|
1129 | + $country->currency_name_single() |
|
1130 | + ); |
|
1131 | + $cols_n_values['CNT_cur_plural'] = $this->request->getRequestParam( |
|
1132 | + "cntry[$CNT_ISO][CNT_cur_plural]", |
|
1133 | + $country->currency_name_plural() |
|
1134 | + ); |
|
1135 | + $cols_n_values['CNT_cur_sign'] = $this->request->getRequestParam( |
|
1136 | + "cntry[$CNT_ISO][CNT_cur_sign]", |
|
1137 | + $country->currency_sign() |
|
1138 | + ); |
|
1139 | + $cols_n_values['CNT_cur_sign_b4'] = $this->request->getRequestParam( |
|
1140 | + "cntry[$CNT_ISO][CNT_cur_sign_b4]", |
|
1141 | + $country->currency_sign_before(), |
|
1142 | + DataType::BOOL |
|
1143 | + ); |
|
1144 | + $cols_n_values['CNT_cur_dec_plc'] = $this->request->getRequestParam( |
|
1145 | + "cntry[$CNT_ISO][CNT_cur_dec_plc]", |
|
1146 | + $country->currency_decimal_places() |
|
1147 | + ); |
|
1148 | + $cols_n_values['CNT_cur_dec_mrk'] = $this->request->getRequestParam( |
|
1149 | + "cntry[$CNT_ISO][CNT_cur_dec_mrk]", |
|
1150 | + $country->currency_decimal_mark() |
|
1151 | + ); |
|
1152 | + $cols_n_values['CNT_cur_thsnds'] = $this->request->getRequestParam( |
|
1153 | + "cntry[$CNT_ISO][CNT_cur_thsnds]", |
|
1154 | + $country->currency_thousands_separator() |
|
1155 | + ); |
|
1156 | + $cols_n_values['CNT_tel_code'] = $this->request->getRequestParam( |
|
1157 | + "cntry[$CNT_ISO][CNT_tel_code]", |
|
1158 | + $country->telephoneCode() |
|
1159 | + ); |
|
1160 | + $cols_n_values['CNT_active'] = $this->request->getRequestParam( |
|
1161 | + "cntry[$CNT_ISO][CNT_active]", |
|
1162 | + $country->isActive(), |
|
1163 | + DataType::BOOL |
|
1164 | + ); |
|
1165 | + |
|
1166 | + // allow filtering of country data |
|
1167 | + $cols_n_values = apply_filters( |
|
1168 | + 'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values', |
|
1169 | + $cols_n_values |
|
1170 | + ); |
|
1171 | + |
|
1172 | + // where values |
|
1173 | + $where_cols_n_values = [['CNT_ISO' => $CNT_ISO]]; |
|
1174 | + // run the update |
|
1175 | + $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values); |
|
1176 | + |
|
1177 | + // allow filtering of states data |
|
1178 | + $states = apply_filters( |
|
1179 | + 'FHEE__General_Settings_Admin_Page___update_country_settings__states', |
|
1180 | + $this->request->getRequestParam('states', [], DataType::STRING, true) |
|
1181 | + ); |
|
1182 | + |
|
1183 | + if (! empty($states) && $success !== false) { |
|
1184 | + // loop thru state data ( looks like : states[75][STA_name] ) |
|
1185 | + foreach ($states as $STA_ID => $state) { |
|
1186 | + $cols_n_values = [ |
|
1187 | + 'CNT_ISO' => $CNT_ISO, |
|
1188 | + 'STA_abbrev' => sanitize_text_field($state['STA_abbrev']), |
|
1189 | + 'STA_name' => sanitize_text_field($state['STA_name']), |
|
1190 | + 'STA_active' => filter_var($state['STA_active'], FILTER_VALIDATE_BOOLEAN), |
|
1191 | + ]; |
|
1192 | + // where values |
|
1193 | + $where_cols_n_values = [['STA_ID' => $STA_ID]]; |
|
1194 | + // run the update |
|
1195 | + $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values); |
|
1196 | + if ($success !== false) { |
|
1197 | + do_action( |
|
1198 | + 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
1199 | + $CNT_ISO, |
|
1200 | + $STA_ID, |
|
1201 | + $cols_n_values |
|
1202 | + ); |
|
1203 | + } |
|
1204 | + } |
|
1205 | + } |
|
1206 | + // check if country being edited matches org option country, and if so, then update EE_Config with new settings |
|
1207 | + if ( |
|
1208 | + isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
1209 | + && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO |
|
1210 | + ) { |
|
1211 | + EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO); |
|
1212 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
1213 | + } |
|
1214 | + |
|
1215 | + if ($success !== false) { |
|
1216 | + EE_Error::add_success( |
|
1217 | + esc_html__('Country Settings updated successfully.', 'event_espresso') |
|
1218 | + ); |
|
1219 | + } |
|
1220 | + $this->_redirect_after_action( |
|
1221 | + $success, |
|
1222 | + '', |
|
1223 | + '', |
|
1224 | + ['action' => 'country_settings', 'country' => $CNT_ISO], |
|
1225 | + true |
|
1226 | + ); |
|
1227 | + } |
|
1228 | + |
|
1229 | + |
|
1230 | + /** |
|
1231 | + * form_form_field_label_wrap |
|
1232 | + * |
|
1233 | + * @param string $label |
|
1234 | + * @return string |
|
1235 | + */ |
|
1236 | + public function country_form_field_label_wrap(string $label): string |
|
1237 | + { |
|
1238 | + return ' |
|
1239 | 1239 | <tr> |
1240 | 1240 | <th> |
1241 | 1241 | ' . $label . ' |
1242 | 1242 | </th>'; |
1243 | - } |
|
1244 | - |
|
1245 | - |
|
1246 | - /** |
|
1247 | - * form_form_field_input__wrap |
|
1248 | - * |
|
1249 | - * @param string $input |
|
1250 | - * @return string |
|
1251 | - */ |
|
1252 | - public function country_form_field_input__wrap(string $input): string |
|
1253 | - { |
|
1254 | - return ' |
|
1243 | + } |
|
1244 | + |
|
1245 | + |
|
1246 | + /** |
|
1247 | + * form_form_field_input__wrap |
|
1248 | + * |
|
1249 | + * @param string $input |
|
1250 | + * @return string |
|
1251 | + */ |
|
1252 | + public function country_form_field_input__wrap(string $input): string |
|
1253 | + { |
|
1254 | + return ' |
|
1255 | 1255 | <td class="general-settings-country-input-td"> |
1256 | 1256 | ' . $input . ' |
1257 | 1257 | </td> |
1258 | 1258 | </tr>'; |
1259 | - } |
|
1260 | - |
|
1261 | - |
|
1262 | - /** |
|
1263 | - * form_form_field_label_wrap |
|
1264 | - * |
|
1265 | - * @param string $label |
|
1266 | - * @param string $required_text |
|
1267 | - * @return string |
|
1268 | - */ |
|
1269 | - public function state_form_field_label_wrap(string $label, string $required_text): string |
|
1270 | - { |
|
1271 | - return $required_text; |
|
1272 | - } |
|
1273 | - |
|
1274 | - |
|
1275 | - /** |
|
1276 | - * form_form_field_input__wrap |
|
1277 | - * |
|
1278 | - * @param string $input |
|
1279 | - * @return string |
|
1280 | - */ |
|
1281 | - public function state_form_field_input__wrap(string $input): string |
|
1282 | - { |
|
1283 | - return ' |
|
1259 | + } |
|
1260 | + |
|
1261 | + |
|
1262 | + /** |
|
1263 | + * form_form_field_label_wrap |
|
1264 | + * |
|
1265 | + * @param string $label |
|
1266 | + * @param string $required_text |
|
1267 | + * @return string |
|
1268 | + */ |
|
1269 | + public function state_form_field_label_wrap(string $label, string $required_text): string |
|
1270 | + { |
|
1271 | + return $required_text; |
|
1272 | + } |
|
1273 | + |
|
1274 | + |
|
1275 | + /** |
|
1276 | + * form_form_field_input__wrap |
|
1277 | + * |
|
1278 | + * @param string $input |
|
1279 | + * @return string |
|
1280 | + */ |
|
1281 | + public function state_form_field_input__wrap(string $input): string |
|
1282 | + { |
|
1283 | + return ' |
|
1284 | 1284 | <td class="general-settings-country-state-input-td"> |
1285 | 1285 | ' . $input . ' |
1286 | 1286 | </td>'; |
1287 | - } |
|
1288 | - |
|
1289 | - |
|
1290 | - /***********/ |
|
1291 | - |
|
1292 | - |
|
1293 | - /** |
|
1294 | - * displays edit and view links for critical EE pages |
|
1295 | - * |
|
1296 | - * @param int $ee_page_id |
|
1297 | - * @return string |
|
1298 | - */ |
|
1299 | - public static function edit_view_links(int $ee_page_id): string |
|
1300 | - { |
|
1301 | - $edit_url = add_query_arg( |
|
1302 | - ['post' => $ee_page_id, 'action' => 'edit'], |
|
1303 | - admin_url('post.php') |
|
1304 | - ); |
|
1305 | - $links = '<a href="' . esc_url_raw($edit_url) . '" >' . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
1306 | - $links .= ' | '; |
|
1307 | - $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>'; |
|
1308 | - |
|
1309 | - return $links; |
|
1310 | - } |
|
1311 | - |
|
1312 | - |
|
1313 | - /** |
|
1314 | - * displays page and shortcode status for critical EE pages |
|
1315 | - * |
|
1316 | - * @param WP_Post $ee_page |
|
1317 | - * @param string $shortcode |
|
1318 | - * @return string |
|
1319 | - */ |
|
1320 | - public static function page_and_shortcode_status(WP_Post $ee_page, string $shortcode): string |
|
1321 | - { |
|
1322 | - // page status |
|
1323 | - if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') { |
|
1324 | - $pg_colour = 'green'; |
|
1325 | - $pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), ' ', ' '); |
|
1326 | - } else { |
|
1327 | - $pg_colour = 'red'; |
|
1328 | - $pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), ' ', ' '); |
|
1329 | - } |
|
1330 | - |
|
1331 | - // shortcode status |
|
1332 | - if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) { |
|
1333 | - $sc_colour = 'green'; |
|
1334 | - $sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), ' '); |
|
1335 | - } else { |
|
1336 | - $sc_colour = 'red'; |
|
1337 | - $sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), ' '); |
|
1338 | - } |
|
1339 | - |
|
1340 | - return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' |
|
1341 | - . $pg_status |
|
1342 | - . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>'; |
|
1343 | - } |
|
1344 | - |
|
1345 | - |
|
1346 | - /** |
|
1347 | - * generates a dropdown of all parent pages - copied from WP core |
|
1348 | - * |
|
1349 | - * @param int $default |
|
1350 | - * @param int $parent |
|
1351 | - * @param int $level |
|
1352 | - * @param bool $echo |
|
1353 | - * @return string; |
|
1354 | - */ |
|
1355 | - public static function page_settings_dropdown( |
|
1356 | - int $default = 0, |
|
1357 | - int $parent = 0, |
|
1358 | - int $level = 0, |
|
1359 | - bool $echo = true |
|
1360 | - ): string { |
|
1361 | - global $wpdb; |
|
1362 | - $items = $wpdb->get_results( |
|
1363 | - $wpdb->prepare( |
|
1364 | - "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order", |
|
1365 | - $parent |
|
1366 | - ) |
|
1367 | - ); |
|
1368 | - $output = ''; |
|
1369 | - |
|
1370 | - if ($items) { |
|
1371 | - $level = absint($level); |
|
1372 | - foreach ($items as $item) { |
|
1373 | - $ID = absint($item->ID); |
|
1374 | - $post_title = wp_strip_all_tags($item->post_title); |
|
1375 | - $pad = str_repeat(' ', $level * 3); |
|
1376 | - $option = "\n\t"; |
|
1377 | - $option .= '<option class="level-' . $level . '" '; |
|
1378 | - $option .= 'value="' . $ID . '" '; |
|
1379 | - $option .= $ID === absint($default) ? ' selected' : ''; |
|
1380 | - $option .= '>'; |
|
1381 | - $option .= "$pad {$post_title}"; |
|
1382 | - $option .= '</option>'; |
|
1383 | - $output .= $option; |
|
1384 | - ob_start(); |
|
1385 | - parent_dropdown($default, $item->ID, $level + 1); |
|
1386 | - $output .= ob_get_clean(); |
|
1387 | - } |
|
1388 | - } |
|
1389 | - if ($echo) { |
|
1390 | - echo wp_kses($output, AllowedTags::getWithFormTags()); |
|
1391 | - return ''; |
|
1392 | - } |
|
1393 | - return $output; |
|
1394 | - } |
|
1395 | - |
|
1396 | - |
|
1397 | - /** |
|
1398 | - * Loads the scripts for the privacy settings form |
|
1399 | - */ |
|
1400 | - public function load_scripts_styles_privacy_settings() |
|
1401 | - { |
|
1402 | - $form_handler = $this->loader->getShared( |
|
1403 | - 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' |
|
1404 | - ); |
|
1405 | - $form_handler->enqueueStylesAndScripts(); |
|
1406 | - } |
|
1407 | - |
|
1408 | - |
|
1409 | - /** |
|
1410 | - * display the privacy settings form |
|
1411 | - * |
|
1412 | - * @throws EE_Error |
|
1413 | - */ |
|
1414 | - public function privacySettings() |
|
1415 | - { |
|
1416 | - $this->_set_add_edit_form_tags('update_privacy_settings'); |
|
1417 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
1418 | - $form_handler = $this->loader->getShared( |
|
1419 | - 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' |
|
1420 | - ); |
|
1421 | - $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
1422 | - $form_handler->display(), |
|
1423 | - '', |
|
1424 | - 'padding' |
|
1425 | - ); |
|
1426 | - $this->display_admin_page_with_sidebar(); |
|
1427 | - } |
|
1428 | - |
|
1429 | - |
|
1430 | - /** |
|
1431 | - * Update the privacy settings from form data |
|
1432 | - * |
|
1433 | - * @throws EE_Error |
|
1434 | - */ |
|
1435 | - public function updatePrivacySettings() |
|
1436 | - { |
|
1437 | - $form_handler = $this->loader->getShared( |
|
1438 | - 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' |
|
1439 | - ); |
|
1440 | - $success = $form_handler->process($this->get_request_data()); |
|
1441 | - $this->_redirect_after_action( |
|
1442 | - $success, |
|
1443 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
1444 | - 'updated', |
|
1445 | - ['action' => 'privacy_settings'] |
|
1446 | - ); |
|
1447 | - } |
|
1287 | + } |
|
1288 | + |
|
1289 | + |
|
1290 | + /***********/ |
|
1291 | + |
|
1292 | + |
|
1293 | + /** |
|
1294 | + * displays edit and view links for critical EE pages |
|
1295 | + * |
|
1296 | + * @param int $ee_page_id |
|
1297 | + * @return string |
|
1298 | + */ |
|
1299 | + public static function edit_view_links(int $ee_page_id): string |
|
1300 | + { |
|
1301 | + $edit_url = add_query_arg( |
|
1302 | + ['post' => $ee_page_id, 'action' => 'edit'], |
|
1303 | + admin_url('post.php') |
|
1304 | + ); |
|
1305 | + $links = '<a href="' . esc_url_raw($edit_url) . '" >' . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
1306 | + $links .= ' | '; |
|
1307 | + $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>'; |
|
1308 | + |
|
1309 | + return $links; |
|
1310 | + } |
|
1311 | + |
|
1312 | + |
|
1313 | + /** |
|
1314 | + * displays page and shortcode status for critical EE pages |
|
1315 | + * |
|
1316 | + * @param WP_Post $ee_page |
|
1317 | + * @param string $shortcode |
|
1318 | + * @return string |
|
1319 | + */ |
|
1320 | + public static function page_and_shortcode_status(WP_Post $ee_page, string $shortcode): string |
|
1321 | + { |
|
1322 | + // page status |
|
1323 | + if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') { |
|
1324 | + $pg_colour = 'green'; |
|
1325 | + $pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), ' ', ' '); |
|
1326 | + } else { |
|
1327 | + $pg_colour = 'red'; |
|
1328 | + $pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), ' ', ' '); |
|
1329 | + } |
|
1330 | + |
|
1331 | + // shortcode status |
|
1332 | + if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) { |
|
1333 | + $sc_colour = 'green'; |
|
1334 | + $sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), ' '); |
|
1335 | + } else { |
|
1336 | + $sc_colour = 'red'; |
|
1337 | + $sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), ' '); |
|
1338 | + } |
|
1339 | + |
|
1340 | + return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' |
|
1341 | + . $pg_status |
|
1342 | + . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>'; |
|
1343 | + } |
|
1344 | + |
|
1345 | + |
|
1346 | + /** |
|
1347 | + * generates a dropdown of all parent pages - copied from WP core |
|
1348 | + * |
|
1349 | + * @param int $default |
|
1350 | + * @param int $parent |
|
1351 | + * @param int $level |
|
1352 | + * @param bool $echo |
|
1353 | + * @return string; |
|
1354 | + */ |
|
1355 | + public static function page_settings_dropdown( |
|
1356 | + int $default = 0, |
|
1357 | + int $parent = 0, |
|
1358 | + int $level = 0, |
|
1359 | + bool $echo = true |
|
1360 | + ): string { |
|
1361 | + global $wpdb; |
|
1362 | + $items = $wpdb->get_results( |
|
1363 | + $wpdb->prepare( |
|
1364 | + "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order", |
|
1365 | + $parent |
|
1366 | + ) |
|
1367 | + ); |
|
1368 | + $output = ''; |
|
1369 | + |
|
1370 | + if ($items) { |
|
1371 | + $level = absint($level); |
|
1372 | + foreach ($items as $item) { |
|
1373 | + $ID = absint($item->ID); |
|
1374 | + $post_title = wp_strip_all_tags($item->post_title); |
|
1375 | + $pad = str_repeat(' ', $level * 3); |
|
1376 | + $option = "\n\t"; |
|
1377 | + $option .= '<option class="level-' . $level . '" '; |
|
1378 | + $option .= 'value="' . $ID . '" '; |
|
1379 | + $option .= $ID === absint($default) ? ' selected' : ''; |
|
1380 | + $option .= '>'; |
|
1381 | + $option .= "$pad {$post_title}"; |
|
1382 | + $option .= '</option>'; |
|
1383 | + $output .= $option; |
|
1384 | + ob_start(); |
|
1385 | + parent_dropdown($default, $item->ID, $level + 1); |
|
1386 | + $output .= ob_get_clean(); |
|
1387 | + } |
|
1388 | + } |
|
1389 | + if ($echo) { |
|
1390 | + echo wp_kses($output, AllowedTags::getWithFormTags()); |
|
1391 | + return ''; |
|
1392 | + } |
|
1393 | + return $output; |
|
1394 | + } |
|
1395 | + |
|
1396 | + |
|
1397 | + /** |
|
1398 | + * Loads the scripts for the privacy settings form |
|
1399 | + */ |
|
1400 | + public function load_scripts_styles_privacy_settings() |
|
1401 | + { |
|
1402 | + $form_handler = $this->loader->getShared( |
|
1403 | + 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' |
|
1404 | + ); |
|
1405 | + $form_handler->enqueueStylesAndScripts(); |
|
1406 | + } |
|
1407 | + |
|
1408 | + |
|
1409 | + /** |
|
1410 | + * display the privacy settings form |
|
1411 | + * |
|
1412 | + * @throws EE_Error |
|
1413 | + */ |
|
1414 | + public function privacySettings() |
|
1415 | + { |
|
1416 | + $this->_set_add_edit_form_tags('update_privacy_settings'); |
|
1417 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
1418 | + $form_handler = $this->loader->getShared( |
|
1419 | + 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' |
|
1420 | + ); |
|
1421 | + $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
1422 | + $form_handler->display(), |
|
1423 | + '', |
|
1424 | + 'padding' |
|
1425 | + ); |
|
1426 | + $this->display_admin_page_with_sidebar(); |
|
1427 | + } |
|
1428 | + |
|
1429 | + |
|
1430 | + /** |
|
1431 | + * Update the privacy settings from form data |
|
1432 | + * |
|
1433 | + * @throws EE_Error |
|
1434 | + */ |
|
1435 | + public function updatePrivacySettings() |
|
1436 | + { |
|
1437 | + $form_handler = $this->loader->getShared( |
|
1438 | + 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' |
|
1439 | + ); |
|
1440 | + $success = $form_handler->process($this->get_request_data()); |
|
1441 | + $this->_redirect_after_action( |
|
1442 | + $success, |
|
1443 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
1444 | + 'updated', |
|
1445 | + ['action' => 'privacy_settings'] |
|
1446 | + ); |
|
1447 | + } |
|
1448 | 1448 | } |
@@ -13,283 +13,283 @@ |
||
13 | 13 | class AllowedTags |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var array[] |
|
18 | - */ |
|
19 | - private static $attributes = [ |
|
20 | - 'accept-charset' => 1, |
|
21 | - 'action' => 1, |
|
22 | - 'alt' => 1, |
|
23 | - 'allow' => 1, |
|
24 | - 'allowfullscreen' => 1, |
|
25 | - 'align' => 1, |
|
26 | - 'aria-*' => 1, |
|
27 | - 'autocomplete' => 1, |
|
28 | - 'checked' => 1, |
|
29 | - 'class' => 1, |
|
30 | - 'cols' => 1, |
|
31 | - 'content' => 1, |
|
32 | - 'data-*' => 1, |
|
33 | - 'dir' => 1, |
|
34 | - 'disabled' => 1, |
|
35 | - 'enctype' => 1, |
|
36 | - 'for' => 1, |
|
37 | - 'frameborder' => 1, |
|
38 | - 'height' => 1, |
|
39 | - 'href' => 1, |
|
40 | - 'id' => 1, |
|
41 | - 'itemprop' => 1, |
|
42 | - 'itemscope' => 1, |
|
43 | - 'itemtype' => 1, |
|
44 | - 'label' => 1, |
|
45 | - 'lang' => 1, |
|
46 | - 'max' => 1, |
|
47 | - 'maxlength' => 1, |
|
48 | - 'method' => 1, |
|
49 | - 'min' => 1, |
|
50 | - 'multiple' => 1, |
|
51 | - 'name' => 1, |
|
52 | - 'novalidate' => 1, |
|
53 | - 'placeholder' => 1, |
|
54 | - 'readonly' => 1, |
|
55 | - 'rel' => 1, |
|
56 | - 'required' => 1, |
|
57 | - 'rows' => 1, |
|
58 | - 'selected' => 1, |
|
59 | - 'src' => 1, |
|
60 | - 'size' => 1, |
|
61 | - 'style' => 1, |
|
62 | - 'step' => 1, |
|
63 | - 'tabindex' => 1, |
|
64 | - 'target' => 1, |
|
65 | - 'title' => 1, |
|
66 | - 'type' => 1, |
|
67 | - 'value' => 1, |
|
68 | - 'width' => 1, |
|
69 | - 'topmargin' => 1, |
|
70 | - 'leftmargin' => 1, |
|
71 | - 'marginheight' => 1, |
|
72 | - 'marginwidth' => 1, |
|
73 | - 'property' => 1, |
|
74 | - 'bgcolor' => 1, |
|
75 | - 'media' => 1, |
|
76 | - 'cellpadding' => 1, |
|
77 | - 'cellspacing' => 1, |
|
78 | - 'border' => 1, |
|
79 | - ]; |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @var array |
|
84 | - */ |
|
85 | - private static $tags = [ |
|
86 | - 'a', |
|
87 | - 'abbr', |
|
88 | - 'b', |
|
89 | - 'br', |
|
90 | - 'code', |
|
91 | - 'div', |
|
92 | - 'em', |
|
93 | - 'h1', |
|
94 | - 'h2', |
|
95 | - 'h3', |
|
96 | - 'h4', |
|
97 | - 'h5', |
|
98 | - 'h6', |
|
99 | - 'hr', |
|
100 | - 'i', |
|
101 | - 'img', |
|
102 | - 'li', |
|
103 | - 'ol', |
|
104 | - 'p', |
|
105 | - 'pre', |
|
106 | - 'small', |
|
107 | - 'span', |
|
108 | - 'strong', |
|
109 | - 'table', |
|
110 | - 'td', |
|
111 | - 'tr', |
|
112 | - 'ul', |
|
113 | - ]; |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @var array |
|
118 | - */ |
|
119 | - private static $allowed_tags; |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @var array |
|
124 | - */ |
|
125 | - private static $allowed_with_embed_tags; |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @var array |
|
130 | - */ |
|
131 | - private static $allowed_with_form_tags; |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @var array |
|
136 | - */ |
|
137 | - private static $allowed_with_script_and_style_tags; |
|
138 | - |
|
139 | - /** |
|
140 | - * @var array |
|
141 | - */ |
|
142 | - private static $allowed_with_full_tags; |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * merges additional tags and attributes into the WP post tags |
|
147 | - */ |
|
148 | - private static function initializeAllowedTags() |
|
149 | - { |
|
150 | - $allowed_post_tags = wp_kses_allowed_html('post'); |
|
151 | - $allowed_tags = []; |
|
152 | - foreach (AllowedTags::$tags as $tag) { |
|
153 | - $allowed_tags[ $tag ] = AllowedTags::$attributes; |
|
154 | - } |
|
155 | - AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * merges embed tags and attributes into the EE all tags |
|
161 | - */ |
|
162 | - private static function initializeWithEmbedTags() |
|
163 | - { |
|
164 | - $all_tags = AllowedTags::getAllowedTags(); |
|
165 | - $embed_tags = [ |
|
166 | - 'iframe' => AllowedTags::$attributes |
|
167 | - ]; |
|
168 | - AllowedTags::$allowed_with_embed_tags = array_merge_recursive($all_tags, $embed_tags); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * merges form tags and attributes into the EE all tags |
|
174 | - */ |
|
175 | - private static function initializeWithFormTags() |
|
176 | - { |
|
177 | - $all_tags = AllowedTags::getAllowedTags(); |
|
178 | - $form_tags = [ |
|
179 | - 'form' => AllowedTags::$attributes, |
|
180 | - 'label' => AllowedTags::$attributes, |
|
181 | - 'input' => AllowedTags::$attributes, |
|
182 | - 'select' => AllowedTags::$attributes, |
|
183 | - 'option' => AllowedTags::$attributes, |
|
184 | - 'optgroup' => AllowedTags::$attributes, |
|
185 | - 'textarea' => AllowedTags::$attributes, |
|
186 | - 'button' => AllowedTags::$attributes, |
|
187 | - 'fieldset' => AllowedTags::$attributes, |
|
188 | - 'output' => AllowedTags::$attributes, |
|
189 | - ]; |
|
190 | - AllowedTags::$allowed_with_form_tags = array_merge_recursive($all_tags, $form_tags); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * merges form script and style tags and attributes into the EE all tags |
|
196 | - */ |
|
197 | - private static function initializeWithScriptAndStyleTags() |
|
198 | - { |
|
199 | - $all_tags = AllowedTags::getAllowedTags(); |
|
200 | - $script_and_style_tags = [ |
|
201 | - 'script' => AllowedTags::$attributes, |
|
202 | - 'style' => AllowedTags::$attributes, |
|
203 | - 'link' => AllowedTags::$attributes, |
|
204 | - 'noscript' => AllowedTags::$attributes, |
|
205 | - ]; |
|
206 | - AllowedTags::$allowed_with_script_and_style_tags = array_merge_recursive($all_tags, $script_and_style_tags); |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * merges all head and body tags and attributes into the EE all tags |
|
211 | - */ |
|
212 | - private static function initializeWithFullTags() |
|
213 | - { |
|
214 | - $all_tags = AllowedTags::getAllowedTags(); |
|
215 | - $full_tags = [ |
|
216 | - 'script' => AllowedTags::$attributes, |
|
217 | - 'style' => AllowedTags::$attributes, |
|
218 | - 'link' => AllowedTags::$attributes, |
|
219 | - 'title' => AllowedTags::$attributes, |
|
220 | - 'meta' => AllowedTags::$attributes, |
|
221 | - 'iframe' => AllowedTags::$attributes, |
|
222 | - 'form' => AllowedTags::$attributes, |
|
223 | - 'label' => AllowedTags::$attributes, |
|
224 | - 'input' => AllowedTags::$attributes, |
|
225 | - 'select' => AllowedTags::$attributes, |
|
226 | - 'option' => AllowedTags::$attributes, |
|
227 | - 'optgroup' => AllowedTags::$attributes, |
|
228 | - 'textarea' => AllowedTags::$attributes, |
|
229 | - 'button' => AllowedTags::$attributes, |
|
230 | - 'fieldset' => AllowedTags::$attributes, |
|
231 | - 'output' => AllowedTags::$attributes, |
|
232 | - 'noscript' => AllowedTags::$attributes, |
|
233 | - ]; |
|
234 | - AllowedTags::$allowed_with_full_tags = array_merge_recursive($all_tags, $full_tags); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @return array[] |
|
240 | - */ |
|
241 | - public static function getAllowedTags() |
|
242 | - { |
|
243 | - if (empty(AllowedTags::$allowed_tags)) { |
|
244 | - AllowedTags::initializeAllowedTags(); |
|
245 | - } |
|
246 | - return AllowedTags::$allowed_tags; |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @return array[] |
|
252 | - */ |
|
253 | - public static function getWithEmbedTags() |
|
254 | - { |
|
255 | - if (empty(AllowedTags::$allowed_with_embed_tags)) { |
|
256 | - AllowedTags::initializeWithEmbedTags(); |
|
257 | - } |
|
258 | - return AllowedTags::$allowed_with_embed_tags; |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * @return array[] |
|
264 | - */ |
|
265 | - public static function getWithFormTags() |
|
266 | - { |
|
267 | - if (empty(AllowedTags::$allowed_with_form_tags)) { |
|
268 | - AllowedTags::initializeWithFormTags(); |
|
269 | - } |
|
270 | - return AllowedTags::$allowed_with_form_tags; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * @return array[] |
|
276 | - */ |
|
277 | - public static function getWithScriptAndStyleTags() |
|
278 | - { |
|
279 | - if (empty(AllowedTags::$allowed_with_script_and_style_tags)) { |
|
280 | - AllowedTags::initializeWithScriptAndStyleTags(); |
|
281 | - } |
|
282 | - return AllowedTags::$allowed_with_script_and_style_tags; |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * @return array[] |
|
287 | - */ |
|
288 | - public static function getWithFullTags() |
|
289 | - { |
|
290 | - if (empty(AllowedTags::$allowed_with_full_tags)) { |
|
291 | - AllowedTags::initializeWithFullTags(); |
|
292 | - } |
|
293 | - return AllowedTags::$allowed_with_full_tags; |
|
294 | - } |
|
16 | + /** |
|
17 | + * @var array[] |
|
18 | + */ |
|
19 | + private static $attributes = [ |
|
20 | + 'accept-charset' => 1, |
|
21 | + 'action' => 1, |
|
22 | + 'alt' => 1, |
|
23 | + 'allow' => 1, |
|
24 | + 'allowfullscreen' => 1, |
|
25 | + 'align' => 1, |
|
26 | + 'aria-*' => 1, |
|
27 | + 'autocomplete' => 1, |
|
28 | + 'checked' => 1, |
|
29 | + 'class' => 1, |
|
30 | + 'cols' => 1, |
|
31 | + 'content' => 1, |
|
32 | + 'data-*' => 1, |
|
33 | + 'dir' => 1, |
|
34 | + 'disabled' => 1, |
|
35 | + 'enctype' => 1, |
|
36 | + 'for' => 1, |
|
37 | + 'frameborder' => 1, |
|
38 | + 'height' => 1, |
|
39 | + 'href' => 1, |
|
40 | + 'id' => 1, |
|
41 | + 'itemprop' => 1, |
|
42 | + 'itemscope' => 1, |
|
43 | + 'itemtype' => 1, |
|
44 | + 'label' => 1, |
|
45 | + 'lang' => 1, |
|
46 | + 'max' => 1, |
|
47 | + 'maxlength' => 1, |
|
48 | + 'method' => 1, |
|
49 | + 'min' => 1, |
|
50 | + 'multiple' => 1, |
|
51 | + 'name' => 1, |
|
52 | + 'novalidate' => 1, |
|
53 | + 'placeholder' => 1, |
|
54 | + 'readonly' => 1, |
|
55 | + 'rel' => 1, |
|
56 | + 'required' => 1, |
|
57 | + 'rows' => 1, |
|
58 | + 'selected' => 1, |
|
59 | + 'src' => 1, |
|
60 | + 'size' => 1, |
|
61 | + 'style' => 1, |
|
62 | + 'step' => 1, |
|
63 | + 'tabindex' => 1, |
|
64 | + 'target' => 1, |
|
65 | + 'title' => 1, |
|
66 | + 'type' => 1, |
|
67 | + 'value' => 1, |
|
68 | + 'width' => 1, |
|
69 | + 'topmargin' => 1, |
|
70 | + 'leftmargin' => 1, |
|
71 | + 'marginheight' => 1, |
|
72 | + 'marginwidth' => 1, |
|
73 | + 'property' => 1, |
|
74 | + 'bgcolor' => 1, |
|
75 | + 'media' => 1, |
|
76 | + 'cellpadding' => 1, |
|
77 | + 'cellspacing' => 1, |
|
78 | + 'border' => 1, |
|
79 | + ]; |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @var array |
|
84 | + */ |
|
85 | + private static $tags = [ |
|
86 | + 'a', |
|
87 | + 'abbr', |
|
88 | + 'b', |
|
89 | + 'br', |
|
90 | + 'code', |
|
91 | + 'div', |
|
92 | + 'em', |
|
93 | + 'h1', |
|
94 | + 'h2', |
|
95 | + 'h3', |
|
96 | + 'h4', |
|
97 | + 'h5', |
|
98 | + 'h6', |
|
99 | + 'hr', |
|
100 | + 'i', |
|
101 | + 'img', |
|
102 | + 'li', |
|
103 | + 'ol', |
|
104 | + 'p', |
|
105 | + 'pre', |
|
106 | + 'small', |
|
107 | + 'span', |
|
108 | + 'strong', |
|
109 | + 'table', |
|
110 | + 'td', |
|
111 | + 'tr', |
|
112 | + 'ul', |
|
113 | + ]; |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @var array |
|
118 | + */ |
|
119 | + private static $allowed_tags; |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @var array |
|
124 | + */ |
|
125 | + private static $allowed_with_embed_tags; |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @var array |
|
130 | + */ |
|
131 | + private static $allowed_with_form_tags; |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @var array |
|
136 | + */ |
|
137 | + private static $allowed_with_script_and_style_tags; |
|
138 | + |
|
139 | + /** |
|
140 | + * @var array |
|
141 | + */ |
|
142 | + private static $allowed_with_full_tags; |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * merges additional tags and attributes into the WP post tags |
|
147 | + */ |
|
148 | + private static function initializeAllowedTags() |
|
149 | + { |
|
150 | + $allowed_post_tags = wp_kses_allowed_html('post'); |
|
151 | + $allowed_tags = []; |
|
152 | + foreach (AllowedTags::$tags as $tag) { |
|
153 | + $allowed_tags[ $tag ] = AllowedTags::$attributes; |
|
154 | + } |
|
155 | + AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * merges embed tags and attributes into the EE all tags |
|
161 | + */ |
|
162 | + private static function initializeWithEmbedTags() |
|
163 | + { |
|
164 | + $all_tags = AllowedTags::getAllowedTags(); |
|
165 | + $embed_tags = [ |
|
166 | + 'iframe' => AllowedTags::$attributes |
|
167 | + ]; |
|
168 | + AllowedTags::$allowed_with_embed_tags = array_merge_recursive($all_tags, $embed_tags); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * merges form tags and attributes into the EE all tags |
|
174 | + */ |
|
175 | + private static function initializeWithFormTags() |
|
176 | + { |
|
177 | + $all_tags = AllowedTags::getAllowedTags(); |
|
178 | + $form_tags = [ |
|
179 | + 'form' => AllowedTags::$attributes, |
|
180 | + 'label' => AllowedTags::$attributes, |
|
181 | + 'input' => AllowedTags::$attributes, |
|
182 | + 'select' => AllowedTags::$attributes, |
|
183 | + 'option' => AllowedTags::$attributes, |
|
184 | + 'optgroup' => AllowedTags::$attributes, |
|
185 | + 'textarea' => AllowedTags::$attributes, |
|
186 | + 'button' => AllowedTags::$attributes, |
|
187 | + 'fieldset' => AllowedTags::$attributes, |
|
188 | + 'output' => AllowedTags::$attributes, |
|
189 | + ]; |
|
190 | + AllowedTags::$allowed_with_form_tags = array_merge_recursive($all_tags, $form_tags); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * merges form script and style tags and attributes into the EE all tags |
|
196 | + */ |
|
197 | + private static function initializeWithScriptAndStyleTags() |
|
198 | + { |
|
199 | + $all_tags = AllowedTags::getAllowedTags(); |
|
200 | + $script_and_style_tags = [ |
|
201 | + 'script' => AllowedTags::$attributes, |
|
202 | + 'style' => AllowedTags::$attributes, |
|
203 | + 'link' => AllowedTags::$attributes, |
|
204 | + 'noscript' => AllowedTags::$attributes, |
|
205 | + ]; |
|
206 | + AllowedTags::$allowed_with_script_and_style_tags = array_merge_recursive($all_tags, $script_and_style_tags); |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * merges all head and body tags and attributes into the EE all tags |
|
211 | + */ |
|
212 | + private static function initializeWithFullTags() |
|
213 | + { |
|
214 | + $all_tags = AllowedTags::getAllowedTags(); |
|
215 | + $full_tags = [ |
|
216 | + 'script' => AllowedTags::$attributes, |
|
217 | + 'style' => AllowedTags::$attributes, |
|
218 | + 'link' => AllowedTags::$attributes, |
|
219 | + 'title' => AllowedTags::$attributes, |
|
220 | + 'meta' => AllowedTags::$attributes, |
|
221 | + 'iframe' => AllowedTags::$attributes, |
|
222 | + 'form' => AllowedTags::$attributes, |
|
223 | + 'label' => AllowedTags::$attributes, |
|
224 | + 'input' => AllowedTags::$attributes, |
|
225 | + 'select' => AllowedTags::$attributes, |
|
226 | + 'option' => AllowedTags::$attributes, |
|
227 | + 'optgroup' => AllowedTags::$attributes, |
|
228 | + 'textarea' => AllowedTags::$attributes, |
|
229 | + 'button' => AllowedTags::$attributes, |
|
230 | + 'fieldset' => AllowedTags::$attributes, |
|
231 | + 'output' => AllowedTags::$attributes, |
|
232 | + 'noscript' => AllowedTags::$attributes, |
|
233 | + ]; |
|
234 | + AllowedTags::$allowed_with_full_tags = array_merge_recursive($all_tags, $full_tags); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @return array[] |
|
240 | + */ |
|
241 | + public static function getAllowedTags() |
|
242 | + { |
|
243 | + if (empty(AllowedTags::$allowed_tags)) { |
|
244 | + AllowedTags::initializeAllowedTags(); |
|
245 | + } |
|
246 | + return AllowedTags::$allowed_tags; |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @return array[] |
|
252 | + */ |
|
253 | + public static function getWithEmbedTags() |
|
254 | + { |
|
255 | + if (empty(AllowedTags::$allowed_with_embed_tags)) { |
|
256 | + AllowedTags::initializeWithEmbedTags(); |
|
257 | + } |
|
258 | + return AllowedTags::$allowed_with_embed_tags; |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * @return array[] |
|
264 | + */ |
|
265 | + public static function getWithFormTags() |
|
266 | + { |
|
267 | + if (empty(AllowedTags::$allowed_with_form_tags)) { |
|
268 | + AllowedTags::initializeWithFormTags(); |
|
269 | + } |
|
270 | + return AllowedTags::$allowed_with_form_tags; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * @return array[] |
|
276 | + */ |
|
277 | + public static function getWithScriptAndStyleTags() |
|
278 | + { |
|
279 | + if (empty(AllowedTags::$allowed_with_script_and_style_tags)) { |
|
280 | + AllowedTags::initializeWithScriptAndStyleTags(); |
|
281 | + } |
|
282 | + return AllowedTags::$allowed_with_script_and_style_tags; |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * @return array[] |
|
287 | + */ |
|
288 | + public static function getWithFullTags() |
|
289 | + { |
|
290 | + if (empty(AllowedTags::$allowed_with_full_tags)) { |
|
291 | + AllowedTags::initializeWithFullTags(); |
|
292 | + } |
|
293 | + return AllowedTags::$allowed_with_full_tags; |
|
294 | + } |
|
295 | 295 | } |
@@ -27,1357 +27,1357 @@ |
||
27 | 27 | final class EE_System implements ResettableInterface |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
32 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
33 | - */ |
|
34 | - const req_type_normal = 0; |
|
35 | - |
|
36 | - /** |
|
37 | - * Indicates this is a brand new installation of EE so we should install |
|
38 | - * tables and default data etc |
|
39 | - */ |
|
40 | - const req_type_new_activation = 1; |
|
41 | - |
|
42 | - /** |
|
43 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
44 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
45 | - * and that default data is setup too |
|
46 | - */ |
|
47 | - const req_type_reactivation = 2; |
|
48 | - |
|
49 | - /** |
|
50 | - * indicates that EE has been upgraded since its previous request. |
|
51 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
52 | - */ |
|
53 | - const req_type_upgrade = 3; |
|
54 | - |
|
55 | - /** |
|
56 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
57 | - */ |
|
58 | - const req_type_downgrade = 4; |
|
59 | - |
|
60 | - /** |
|
61 | - * @deprecated since version 4.6.0.dev.006 |
|
62 | - * Now whenever a new_activation is detected the request type is still just |
|
63 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
64 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
65 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
66 | - * (Specifically, when the migration manager indicates migrations are finished |
|
67 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
68 | - */ |
|
69 | - const req_type_activation_but_not_installed = 5; |
|
70 | - |
|
71 | - /** |
|
72 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
73 | - */ |
|
74 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
75 | - |
|
76 | - /** |
|
77 | - * @var EE_System $_instance |
|
78 | - */ |
|
79 | - private static $_instance; |
|
80 | - |
|
81 | - /** |
|
82 | - * @var EE_Registry $registry |
|
83 | - */ |
|
84 | - private $registry; |
|
85 | - |
|
86 | - /** |
|
87 | - * @var LoaderInterface $loader |
|
88 | - */ |
|
89 | - private $loader; |
|
90 | - |
|
91 | - /** |
|
92 | - * @var EE_Capabilities $capabilities |
|
93 | - */ |
|
94 | - private $capabilities; |
|
95 | - |
|
96 | - /** |
|
97 | - * @var RequestInterface $request |
|
98 | - */ |
|
99 | - private $request; |
|
100 | - |
|
101 | - /** |
|
102 | - * @var EE_Maintenance_Mode $maintenance_mode |
|
103 | - */ |
|
104 | - private $maintenance_mode; |
|
105 | - |
|
106 | - /** |
|
107 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
108 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
109 | - * |
|
110 | - * @var int $_req_type |
|
111 | - */ |
|
112 | - private $_req_type; |
|
113 | - |
|
114 | - /** |
|
115 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
116 | - * |
|
117 | - * @var boolean $_major_version_change |
|
118 | - */ |
|
119 | - private $_major_version_change = false; |
|
120 | - |
|
121 | - /** |
|
122 | - * A Context DTO dedicated solely to identifying the current request type. |
|
123 | - * |
|
124 | - * @var RequestTypeContextCheckerInterface $request_type |
|
125 | - */ |
|
126 | - private $request_type; |
|
127 | - |
|
128 | - /** |
|
129 | - * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes |
|
130 | - */ |
|
131 | - private $register_custom_post_types; |
|
132 | - |
|
133 | - /** |
|
134 | - * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies |
|
135 | - */ |
|
136 | - private $register_custom_taxonomies; |
|
137 | - |
|
138 | - /** |
|
139 | - * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms |
|
140 | - */ |
|
141 | - private $register_custom_taxonomy_terms; |
|
142 | - |
|
143 | - /** |
|
144 | - * @singleton method used to instantiate class object |
|
145 | - * @param EE_Registry|null $registry |
|
146 | - * @param LoaderInterface|null $loader |
|
147 | - * @param RequestInterface|null $request |
|
148 | - * @param EE_Maintenance_Mode|null $maintenance_mode |
|
149 | - * @return EE_System |
|
150 | - */ |
|
151 | - public static function instance( |
|
152 | - EE_Registry $registry = null, |
|
153 | - LoaderInterface $loader = null, |
|
154 | - RequestInterface $request = null, |
|
155 | - EE_Maintenance_Mode $maintenance_mode = null |
|
156 | - ) { |
|
157 | - // check if class object is instantiated |
|
158 | - if (! self::$_instance instanceof EE_System) { |
|
159 | - self::$_instance = new self($registry, $loader, $request, $maintenance_mode); |
|
160 | - } |
|
161 | - return self::$_instance; |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * resets the instance and returns it |
|
167 | - * |
|
168 | - * @return EE_System |
|
169 | - */ |
|
170 | - public static function reset() |
|
171 | - { |
|
172 | - self::$_instance->_req_type = null; |
|
173 | - // make sure none of the old hooks are left hanging around |
|
174 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
175 | - // we need to reset the migration manager in order for it to detect DMSs properly |
|
176 | - EE_Data_Migration_Manager::reset(); |
|
177 | - self::instance()->detect_activations_or_upgrades(); |
|
178 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
179 | - return self::instance(); |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * sets hooks for running rest of system |
|
185 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
186 | - * starting EE Addons from any other point may lead to problems |
|
187 | - * |
|
188 | - * @param EE_Registry $registry |
|
189 | - * @param LoaderInterface $loader |
|
190 | - * @param RequestInterface $request |
|
191 | - * @param EE_Maintenance_Mode $maintenance_mode |
|
192 | - */ |
|
193 | - private function __construct( |
|
194 | - EE_Registry $registry, |
|
195 | - LoaderInterface $loader, |
|
196 | - RequestInterface $request, |
|
197 | - EE_Maintenance_Mode $maintenance_mode |
|
198 | - ) { |
|
199 | - $this->registry = $registry; |
|
200 | - $this->loader = $loader; |
|
201 | - $this->request = $request; |
|
202 | - $this->maintenance_mode = $maintenance_mode; |
|
203 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
204 | - add_action( |
|
205 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
206 | - array($this, 'loadCapabilities'), |
|
207 | - 5 |
|
208 | - ); |
|
209 | - add_action( |
|
210 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
211 | - array($this, 'loadCommandBus'), |
|
212 | - 7 |
|
213 | - ); |
|
214 | - add_action( |
|
215 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
216 | - array($this, 'loadPluginApi'), |
|
217 | - 9 |
|
218 | - ); |
|
219 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
220 | - add_action( |
|
221 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
222 | - array($this, 'load_espresso_addons') |
|
223 | - ); |
|
224 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
225 | - // because the newly-activated addon didn't get a chance to run at all |
|
226 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
227 | - // detect whether install or upgrade |
|
228 | - add_action( |
|
229 | - 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
230 | - array($this, 'detect_activations_or_upgrades'), |
|
231 | - 3 |
|
232 | - ); |
|
233 | - // load EE_Config, EE_Textdomain, etc |
|
234 | - add_action( |
|
235 | - 'AHEE__EE_Bootstrap__load_core_configuration', |
|
236 | - array($this, 'load_core_configuration'), |
|
237 | - 5 |
|
238 | - ); |
|
239 | - // load specifications for matching routes to current request |
|
240 | - add_action( |
|
241 | - 'AHEE__EE_Bootstrap__load_core_configuration', |
|
242 | - array($this, 'loadRouteMatchSpecifications') |
|
243 | - ); |
|
244 | - // load specifications for custom post types |
|
245 | - add_action( |
|
246 | - 'AHEE__EE_Bootstrap__load_core_configuration', |
|
247 | - array($this, 'loadCustomPostTypes') |
|
248 | - ); |
|
249 | - // load EE_Config, EE_Textdomain, etc |
|
250 | - add_action( |
|
251 | - 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
252 | - array($this, 'register_shortcodes_modules_and_widgets'), |
|
253 | - 7 |
|
254 | - ); |
|
255 | - // you wanna get going? I wanna get going... let's get going! |
|
256 | - add_action( |
|
257 | - 'AHEE__EE_Bootstrap__brew_espresso', |
|
258 | - array($this, 'brew_espresso'), |
|
259 | - 9 |
|
260 | - ); |
|
261 | - // other housekeeping |
|
262 | - // exclude EE critical pages from wp_list_pages |
|
263 | - add_filter( |
|
264 | - 'wp_list_pages_excludes', |
|
265 | - array($this, 'remove_pages_from_wp_list_pages'), |
|
266 | - 10 |
|
267 | - ); |
|
268 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
269 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
270 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * load and setup EE_Capabilities |
|
276 | - * |
|
277 | - * @return void |
|
278 | - * @throws EE_Error |
|
279 | - */ |
|
280 | - public function loadCapabilities() |
|
281 | - { |
|
282 | - $this->capabilities = $this->loader->getShared('EE_Capabilities'); |
|
283 | - add_action( |
|
284 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
285 | - function () { |
|
286 | - LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
287 | - } |
|
288 | - ); |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * create and cache the CommandBus, and also add middleware |
|
294 | - * The CapChecker middleware requires the use of EE_Capabilities |
|
295 | - * which is why we need to load the CommandBus after Caps are set up |
|
296 | - * |
|
297 | - * @return void |
|
298 | - * @throws EE_Error |
|
299 | - */ |
|
300 | - public function loadCommandBus() |
|
301 | - { |
|
302 | - $this->loader->getShared( |
|
303 | - 'CommandBusInterface', |
|
304 | - array( |
|
305 | - null, |
|
306 | - apply_filters( |
|
307 | - 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
308 | - array( |
|
309 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
310 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
311 | - ) |
|
312 | - ), |
|
313 | - ) |
|
314 | - ); |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * @return void |
|
320 | - * @throws EE_Error |
|
321 | - */ |
|
322 | - public function loadPluginApi() |
|
323 | - { |
|
324 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
325 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
326 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * @param string $addon_name |
|
332 | - * @param string $version_constant |
|
333 | - * @param string $min_version_required |
|
334 | - * @param string $load_callback |
|
335 | - * @param string $plugin_file_constant |
|
336 | - * @return void |
|
337 | - */ |
|
338 | - private function deactivateIncompatibleAddon( |
|
339 | - $addon_name, |
|
340 | - $version_constant, |
|
341 | - $min_version_required, |
|
342 | - $load_callback, |
|
343 | - $plugin_file_constant |
|
344 | - ) { |
|
345 | - if (! defined($version_constant)) { |
|
346 | - return; |
|
347 | - } |
|
348 | - $addon_version = constant($version_constant); |
|
349 | - if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
|
350 | - remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
|
351 | - if (! function_exists('deactivate_plugins')) { |
|
352 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
353 | - } |
|
354 | - deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
|
355 | - $this->request->unSetRequestParams(['activate', 'activate-multi'], true); |
|
356 | - EE_Error::add_error( |
|
357 | - sprintf( |
|
358 | - esc_html__( |
|
359 | - 'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.', |
|
360 | - 'event_espresso' |
|
361 | - ), |
|
362 | - $addon_name, |
|
363 | - $min_version_required |
|
364 | - ), |
|
365 | - __FILE__, |
|
366 | - __FUNCTION__ . "({$addon_name})", |
|
367 | - __LINE__ |
|
368 | - ); |
|
369 | - EE_Error::get_notices(false, true); |
|
370 | - } |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * load_espresso_addons |
|
376 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
377 | - * this is hooked into both: |
|
378 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
379 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
380 | - * and the WP 'activate_plugin' hook point |
|
381 | - * |
|
382 | - * @access public |
|
383 | - * @return void |
|
384 | - */ |
|
385 | - public function load_espresso_addons() |
|
386 | - { |
|
387 | - $this->deactivateIncompatibleAddon( |
|
388 | - 'Wait Lists', |
|
389 | - 'EE_WAIT_LISTS_VERSION', |
|
390 | - '1.0.0.beta.074', |
|
391 | - 'load_espresso_wait_lists', |
|
392 | - 'EE_WAIT_LISTS_PLUGIN_FILE' |
|
393 | - ); |
|
394 | - $this->deactivateIncompatibleAddon( |
|
395 | - 'Automated Upcoming Event Notifications', |
|
396 | - 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION', |
|
397 | - '1.0.0.beta.091', |
|
398 | - 'load_espresso_automated_upcoming_event_notification', |
|
399 | - 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE' |
|
400 | - ); |
|
401 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
402 | - // if the WP API basic auth plugin isn't already loaded, load it now. |
|
403 | - // We want it for mobile apps. Just include the entire plugin |
|
404 | - // also, don't load the basic auth when a plugin is getting activated, because |
|
405 | - // it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
406 | - // and causes a fatal error |
|
407 | - if ( |
|
408 | - ($this->request->isWordPressApi() || $this->request->isApi()) |
|
409 | - && $this->request->getRequestParam('activate') !== 'true' |
|
410 | - && ! function_exists('json_basic_auth_handler') |
|
411 | - && ! function_exists('json_basic_auth_error') |
|
412 | - && ! in_array( |
|
413 | - $this->request->getRequestParam('action'), |
|
414 | - array('activate', 'activate-selected'), |
|
415 | - true |
|
416 | - ) |
|
417 | - ) { |
|
418 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php'; |
|
419 | - } |
|
420 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * detect_activations_or_upgrades |
|
426 | - * Checks for activation or upgrade of core first; |
|
427 | - * then also checks if any registered addons have been activated or upgraded |
|
428 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
429 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
430 | - * |
|
431 | - * @access public |
|
432 | - * @return void |
|
433 | - */ |
|
434 | - public function detect_activations_or_upgrades() |
|
435 | - { |
|
436 | - // first off: let's make sure to handle core |
|
437 | - $this->detect_if_activation_or_upgrade(); |
|
438 | - foreach ($this->registry->addons as $addon) { |
|
439 | - if ($addon instanceof EE_Addon) { |
|
440 | - // detect teh request type for that addon |
|
441 | - $addon->detect_req_type(); |
|
442 | - } |
|
443 | - } |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * detect_if_activation_or_upgrade |
|
449 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
450 | - * and either setting up the DB or setting up maintenance mode etc. |
|
451 | - * |
|
452 | - * @access public |
|
453 | - * @return void |
|
454 | - */ |
|
455 | - public function detect_if_activation_or_upgrade() |
|
456 | - { |
|
457 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
458 | - // check if db has been updated, or if its a brand-new installation |
|
459 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
460 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
461 | - // EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
462 | - switch ($request_type) { |
|
463 | - case EE_System::req_type_new_activation: |
|
464 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
465 | - $this->_handle_core_version_change($espresso_db_update); |
|
466 | - break; |
|
467 | - case EE_System::req_type_reactivation: |
|
468 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
469 | - $this->_handle_core_version_change($espresso_db_update); |
|
470 | - break; |
|
471 | - case EE_System::req_type_upgrade: |
|
472 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
473 | - // migrations may be required now that we've upgraded |
|
474 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
475 | - $this->_handle_core_version_change($espresso_db_update); |
|
476 | - break; |
|
477 | - case EE_System::req_type_downgrade: |
|
478 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
479 | - // its possible migrations are no longer required |
|
480 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
481 | - $this->_handle_core_version_change($espresso_db_update); |
|
482 | - break; |
|
483 | - case EE_System::req_type_normal: |
|
484 | - default: |
|
485 | - break; |
|
486 | - } |
|
487 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * Updates the list of installed versions and sets hooks for |
|
493 | - * initializing the database later during the request |
|
494 | - * |
|
495 | - * @param array $espresso_db_update |
|
496 | - */ |
|
497 | - private function _handle_core_version_change($espresso_db_update) |
|
498 | - { |
|
499 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
500 | - // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
501 | - add_action( |
|
502 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
503 | - array($this, 'initialize_db_if_no_migrations_required') |
|
504 | - ); |
|
505 | - } |
|
506 | - |
|
507 | - |
|
508 | - /** |
|
509 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
510 | - * information about what versions of EE have been installed and activated, |
|
511 | - * NOT necessarily the state of the database |
|
512 | - * |
|
513 | - * @param mixed $espresso_db_update the value of the WordPress option. |
|
514 | - * If not supplied, fetches it from the options table |
|
515 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
516 | - */ |
|
517 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
518 | - { |
|
519 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
520 | - if (! $espresso_db_update) { |
|
521 | - $espresso_db_update = get_option('espresso_db_update'); |
|
522 | - } |
|
523 | - // check that option is an array |
|
524 | - if (! is_array($espresso_db_update)) { |
|
525 | - // if option is FALSE, then it never existed |
|
526 | - if ($espresso_db_update === false) { |
|
527 | - // make $espresso_db_update an array and save option with autoload OFF |
|
528 | - $espresso_db_update = array(); |
|
529 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
530 | - } else { |
|
531 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
532 | - $espresso_db_update = array($espresso_db_update => array()); |
|
533 | - update_option('espresso_db_update', $espresso_db_update); |
|
534 | - } |
|
535 | - } else { |
|
536 | - $corrected_db_update = array(); |
|
537 | - // if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
538 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
539 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
540 | - // the key is an int, and the value IS NOT an array |
|
541 | - // so it must be numerically-indexed, where values are versions installed... |
|
542 | - // fix it! |
|
543 | - $version_string = $should_be_array; |
|
544 | - $corrected_db_update[ $version_string ] = array('unknown-date'); |
|
545 | - } else { |
|
546 | - // ok it checks out |
|
547 | - $corrected_db_update[ $should_be_version_string ] = $should_be_array; |
|
548 | - } |
|
549 | - } |
|
550 | - $espresso_db_update = $corrected_db_update; |
|
551 | - update_option('espresso_db_update', $espresso_db_update); |
|
552 | - } |
|
553 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
554 | - return $espresso_db_update; |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
560 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
561 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
562 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
563 | - * so that it will be done when migrations are finished |
|
564 | - * |
|
565 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
566 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
567 | - * This is a resource-intensive job |
|
568 | - * so we prefer to only do it when necessary |
|
569 | - * @return void |
|
570 | - * @throws EE_Error |
|
571 | - */ |
|
572 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
573 | - { |
|
574 | - $request_type = $this->detect_req_type(); |
|
575 | - // only initialize system if we're not in maintenance mode. |
|
576 | - if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
577 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
578 | - $rewrite_rules = $this->loader->getShared( |
|
579 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
580 | - ); |
|
581 | - $rewrite_rules->flush(); |
|
582 | - if ($verify_schema) { |
|
583 | - EEH_Activation::initialize_db_and_folders(); |
|
584 | - } |
|
585 | - EEH_Activation::initialize_db_content(); |
|
586 | - EEH_Activation::system_initialization(); |
|
587 | - if ($initialize_addons_too) { |
|
588 | - $this->initialize_addons(); |
|
589 | - } |
|
590 | - } else { |
|
591 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
592 | - } |
|
593 | - if ( |
|
594 | - $request_type === EE_System::req_type_new_activation |
|
595 | - || $request_type === EE_System::req_type_reactivation |
|
596 | - || ( |
|
597 | - $request_type === EE_System::req_type_upgrade |
|
598 | - && $this->is_major_version_change() |
|
599 | - ) |
|
600 | - ) { |
|
601 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
602 | - } |
|
603 | - } |
|
604 | - |
|
605 | - |
|
606 | - /** |
|
607 | - * Initializes the db for all registered addons |
|
608 | - * |
|
609 | - * @throws EE_Error |
|
610 | - */ |
|
611 | - public function initialize_addons() |
|
612 | - { |
|
613 | - // foreach registered addon, make sure its db is up-to-date too |
|
614 | - foreach ($this->registry->addons as $addon) { |
|
615 | - if ($addon instanceof EE_Addon) { |
|
616 | - $addon->initialize_db_if_no_migrations_required(); |
|
617 | - } |
|
618 | - } |
|
619 | - } |
|
620 | - |
|
621 | - |
|
622 | - /** |
|
623 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
624 | - * |
|
625 | - * @param array $version_history |
|
626 | - * @param string $current_version_to_add version to be added to the version history |
|
627 | - * @return boolean success as to whether or not this option was changed |
|
628 | - */ |
|
629 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
630 | - { |
|
631 | - if (! $version_history) { |
|
632 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
633 | - } |
|
634 | - if ($current_version_to_add === null) { |
|
635 | - $current_version_to_add = espresso_version(); |
|
636 | - } |
|
637 | - $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
638 | - // re-save |
|
639 | - return update_option('espresso_db_update', $version_history); |
|
640 | - } |
|
641 | - |
|
642 | - |
|
643 | - /** |
|
644 | - * Detects if the current version indicated in the has existed in the list of |
|
645 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
646 | - * |
|
647 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
648 | - * If not supplied, fetches it from the options table. |
|
649 | - * Also, caches its result so later parts of the code can also know whether |
|
650 | - * there's been an update or not. This way we can add the current version to |
|
651 | - * espresso_db_update, but still know if this is a new install or not |
|
652 | - * @return int one of the constants on EE_System::req_type_ |
|
653 | - */ |
|
654 | - public function detect_req_type($espresso_db_update = null) |
|
655 | - { |
|
656 | - if ($this->_req_type === null) { |
|
657 | - $espresso_db_update = ! empty($espresso_db_update) |
|
658 | - ? $espresso_db_update |
|
659 | - : $this->fix_espresso_db_upgrade_option(); |
|
660 | - $this->_req_type = EE_System::detect_req_type_given_activation_history( |
|
661 | - $espresso_db_update, |
|
662 | - 'ee_espresso_activation', |
|
663 | - espresso_version() |
|
664 | - ); |
|
665 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
666 | - $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal); |
|
667 | - } |
|
668 | - return $this->_req_type; |
|
669 | - } |
|
670 | - |
|
671 | - |
|
672 | - /** |
|
673 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
674 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
675 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
676 | - * |
|
677 | - * @param $activation_history |
|
678 | - * @return bool |
|
679 | - */ |
|
680 | - private function _detect_major_version_change($activation_history) |
|
681 | - { |
|
682 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
683 | - $previous_version_parts = explode('.', $previous_version); |
|
684 | - $current_version_parts = explode('.', espresso_version()); |
|
685 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
686 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
687 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
688 | - ); |
|
689 | - } |
|
690 | - |
|
691 | - |
|
692 | - /** |
|
693 | - * Returns true if either the major or minor version of EE changed during this request. |
|
694 | - * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
695 | - * |
|
696 | - * @return bool |
|
697 | - */ |
|
698 | - public function is_major_version_change() |
|
699 | - { |
|
700 | - return $this->_major_version_change; |
|
701 | - } |
|
702 | - |
|
703 | - |
|
704 | - /** |
|
705 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
706 | - * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
707 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
708 | - * just activated to (for core that will always be espresso_version()) |
|
709 | - * |
|
710 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
711 | - * ee plugin. for core that's 'espresso_db_update' |
|
712 | - * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
713 | - * indicate that this plugin was just activated |
|
714 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
715 | - * espresso_version()) |
|
716 | - * @return int one of the constants on EE_System::req_type_* |
|
717 | - */ |
|
718 | - public static function detect_req_type_given_activation_history( |
|
719 | - $activation_history_for_addon, |
|
720 | - $activation_indicator_option_name, |
|
721 | - $version_to_upgrade_to |
|
722 | - ) { |
|
723 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
724 | - if ($activation_history_for_addon) { |
|
725 | - // it exists, so this isn't a completely new install |
|
726 | - // check if this version already in that list of previously installed versions |
|
727 | - if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { |
|
728 | - // it a version we haven't seen before |
|
729 | - if ($version_is_higher === 1) { |
|
730 | - $req_type = EE_System::req_type_upgrade; |
|
731 | - } else { |
|
732 | - $req_type = EE_System::req_type_downgrade; |
|
733 | - } |
|
734 | - delete_option($activation_indicator_option_name); |
|
735 | - } else { |
|
736 | - // its not an update. maybe a reactivation? |
|
737 | - if (get_option($activation_indicator_option_name, false)) { |
|
738 | - if ($version_is_higher === -1) { |
|
739 | - $req_type = EE_System::req_type_downgrade; |
|
740 | - } elseif ($version_is_higher === 0) { |
|
741 | - // we've seen this version before, but it's an activation. must be a reactivation |
|
742 | - $req_type = EE_System::req_type_reactivation; |
|
743 | - } else {// $version_is_higher === 1 |
|
744 | - $req_type = EE_System::req_type_upgrade; |
|
745 | - } |
|
746 | - delete_option($activation_indicator_option_name); |
|
747 | - } else { |
|
748 | - // we've seen this version before and the activation indicate doesn't show it was just activated |
|
749 | - if ($version_is_higher === -1) { |
|
750 | - $req_type = EE_System::req_type_downgrade; |
|
751 | - } elseif ($version_is_higher === 0) { |
|
752 | - // we've seen this version before and it's not an activation. its normal request |
|
753 | - $req_type = EE_System::req_type_normal; |
|
754 | - } else {// $version_is_higher === 1 |
|
755 | - $req_type = EE_System::req_type_upgrade; |
|
756 | - } |
|
757 | - } |
|
758 | - } |
|
759 | - } else { |
|
760 | - // brand new install |
|
761 | - $req_type = EE_System::req_type_new_activation; |
|
762 | - delete_option($activation_indicator_option_name); |
|
763 | - } |
|
764 | - return $req_type; |
|
765 | - } |
|
766 | - |
|
767 | - |
|
768 | - /** |
|
769 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
770 | - * the $activation_history_for_addon |
|
771 | - * |
|
772 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
773 | - * sometimes containing 'unknown-date' |
|
774 | - * @param string $version_to_upgrade_to (current version) |
|
775 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
776 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
777 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
778 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
779 | - */ |
|
780 | - private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
781 | - { |
|
782 | - // find the most recently-activated version |
|
783 | - $most_recently_active_version = |
|
784 | - EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
785 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
786 | - } |
|
787 | - |
|
788 | - |
|
789 | - /** |
|
790 | - * Gets the most recently active version listed in the activation history, |
|
791 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
792 | - * |
|
793 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
794 | - * sometimes containing 'unknown-date' |
|
795 | - * @return string |
|
796 | - */ |
|
797 | - private static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
798 | - { |
|
799 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
800 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
801 | - if (is_array($activation_history)) { |
|
802 | - foreach ($activation_history as $version => $times_activated) { |
|
803 | - // check there is a record of when this version was activated. Otherwise, |
|
804 | - // mark it as unknown |
|
805 | - if (! $times_activated) { |
|
806 | - $times_activated = array('unknown-date'); |
|
807 | - } |
|
808 | - if (is_string($times_activated)) { |
|
809 | - $times_activated = array($times_activated); |
|
810 | - } |
|
811 | - foreach ($times_activated as $an_activation) { |
|
812 | - if ( |
|
813 | - $an_activation !== 'unknown-date' |
|
814 | - && $an_activation |
|
815 | - > $most_recently_active_version_activation |
|
816 | - ) { |
|
817 | - $most_recently_active_version = $version; |
|
818 | - $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
819 | - ? '1970-01-01 00:00:00' |
|
820 | - : $an_activation; |
|
821 | - } |
|
822 | - } |
|
823 | - } |
|
824 | - } |
|
825 | - return $most_recently_active_version; |
|
826 | - } |
|
827 | - |
|
828 | - |
|
829 | - /** |
|
830 | - * This redirects to the about EE page after activation |
|
831 | - * |
|
832 | - * @return void |
|
833 | - */ |
|
834 | - public function redirect_to_about_ee() |
|
835 | - { |
|
836 | - $notices = EE_Error::get_notices(false); |
|
837 | - // if current user is an admin and it's not an ajax or rest request |
|
838 | - if ( |
|
839 | - ! isset($notices['errors']) |
|
840 | - && $this->request->isAdmin() |
|
841 | - && apply_filters( |
|
842 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
843 | - $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
844 | - ) |
|
845 | - ) { |
|
846 | - $query_params = array('page' => 'espresso_about'); |
|
847 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
848 | - $query_params['new_activation'] = true; |
|
849 | - } |
|
850 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
851 | - $query_params['reactivation'] = true; |
|
852 | - } |
|
853 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
854 | - wp_safe_redirect($url); |
|
855 | - exit(); |
|
856 | - } |
|
857 | - } |
|
858 | - |
|
859 | - |
|
860 | - /** |
|
861 | - * load_core_configuration |
|
862 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
863 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
864 | - * |
|
865 | - * @return void |
|
866 | - * @throws ReflectionException |
|
867 | - * @throws Exception |
|
868 | - */ |
|
869 | - public function load_core_configuration() |
|
870 | - { |
|
871 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
872 | - $this->loader->getShared('EE_Load_Textdomain'); |
|
873 | - // load textdomain |
|
874 | - EE_Load_Textdomain::load_textdomain(); |
|
875 | - // load caf stuff a chance to play during the activation process too. |
|
876 | - $this->_maybe_brew_regular(); |
|
877 | - // load and setup EE_Config and EE_Network_Config |
|
878 | - $config = $this->loader->getShared('EE_Config'); |
|
879 | - $this->loader->getShared('EE_Network_Config'); |
|
880 | - // setup autoloaders |
|
881 | - // enable logging? |
|
882 | - if ($config->admin->use_remote_logging) { |
|
883 | - $this->loader->getShared('EE_Log'); |
|
884 | - } |
|
885 | - // check for activation errors |
|
886 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
887 | - if ($activation_errors) { |
|
888 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
889 | - update_option('ee_plugin_activation_errors', false); |
|
890 | - } |
|
891 | - // get model names |
|
892 | - $this->_parse_model_names(); |
|
893 | - // configure custom post type definitions |
|
894 | - $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'); |
|
895 | - $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'); |
|
896 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
897 | - } |
|
898 | - |
|
899 | - |
|
900 | - /** |
|
901 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
902 | - * |
|
903 | - * @return void |
|
904 | - * @throws ReflectionException |
|
905 | - */ |
|
906 | - private function _parse_model_names() |
|
907 | - { |
|
908 | - // get all the files in the EE_MODELS folder that end in .model.php |
|
909 | - $models = glob(EE_MODELS . '*.model.php'); |
|
910 | - $model_names = array(); |
|
911 | - $non_abstract_db_models = array(); |
|
912 | - foreach ($models as $model) { |
|
913 | - // get model classname |
|
914 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
915 | - $short_name = str_replace('EEM_', '', $classname); |
|
916 | - $reflectionClass = new ReflectionClass($classname); |
|
917 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
918 | - $non_abstract_db_models[ $short_name ] = $classname; |
|
919 | - } |
|
920 | - $model_names[ $short_name ] = $classname; |
|
921 | - } |
|
922 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
923 | - $this->registry->non_abstract_db_models = apply_filters( |
|
924 | - 'FHEE__EE_System__parse_implemented_model_names', |
|
925 | - $non_abstract_db_models |
|
926 | - ); |
|
927 | - } |
|
928 | - |
|
929 | - |
|
930 | - /** |
|
931 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
932 | - * that need to be setup before our EE_System launches. |
|
933 | - * |
|
934 | - * @return void |
|
935 | - * @throws DomainException |
|
936 | - * @throws InvalidArgumentException |
|
937 | - * @throws InvalidDataTypeException |
|
938 | - * @throws InvalidInterfaceException |
|
939 | - * @throws InvalidClassException |
|
940 | - * @throws InvalidFilePathException |
|
941 | - */ |
|
942 | - private function _maybe_brew_regular() |
|
943 | - { |
|
944 | - /** @var Domain $domain */ |
|
945 | - $domain = DomainFactory::getShared( |
|
946 | - new FullyQualifiedName( |
|
947 | - 'EventEspresso\core\domain\Domain' |
|
948 | - ), |
|
949 | - array( |
|
950 | - new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
951 | - Version::fromString(espresso_version()), |
|
952 | - ) |
|
953 | - ); |
|
954 | - if ($domain->isCaffeinated()) { |
|
955 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
956 | - } |
|
957 | - } |
|
958 | - |
|
959 | - |
|
960 | - /** |
|
961 | - * @since 4.9.71.p |
|
962 | - * @throws Exception |
|
963 | - */ |
|
964 | - public function loadRouteMatchSpecifications() |
|
965 | - { |
|
966 | - try { |
|
967 | - $this->loader->getShared( |
|
968 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' |
|
969 | - ); |
|
970 | - } catch (Exception $exception) { |
|
971 | - new ExceptionStackTraceDisplay($exception); |
|
972 | - } |
|
973 | - do_action('AHEE__EE_System__loadRouteMatchSpecifications'); |
|
974 | - } |
|
975 | - |
|
976 | - |
|
977 | - /** |
|
978 | - * loading CPT related classes earlier so that their definitions are available |
|
979 | - * but not performing any actual registration with WP core until load_CPTs_and_session() is called |
|
980 | - * |
|
981 | - * @since 4.10.21.p |
|
982 | - */ |
|
983 | - public function loadCustomPostTypes() |
|
984 | - { |
|
985 | - $this->register_custom_taxonomies = $this->loader->getShared( |
|
986 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' |
|
987 | - ); |
|
988 | - $this->register_custom_post_types = $this->loader->getShared( |
|
989 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' |
|
990 | - ); |
|
991 | - $this->register_custom_taxonomy_terms = $this->loader->getShared( |
|
992 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms' |
|
993 | - ); |
|
994 | - // integrate WP_Query with the EE models |
|
995 | - $this->loader->getShared('EE_CPT_Strategy'); |
|
996 | - // load legacy EE_Request_Handler in case add-ons still need it |
|
997 | - $this->loader->getShared('EE_Request_Handler'); |
|
998 | - } |
|
999 | - |
|
1000 | - |
|
1001 | - /** |
|
1002 | - * register_shortcodes_modules_and_widgets |
|
1003 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
1004 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
1005 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
1006 | - * |
|
1007 | - * @access public |
|
1008 | - * @return void |
|
1009 | - * @throws Exception |
|
1010 | - */ |
|
1011 | - public function register_shortcodes_modules_and_widgets() |
|
1012 | - { |
|
1013 | - if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAjax()) { |
|
1014 | - // load, register, and add shortcodes the new way |
|
1015 | - $this->loader->getShared('EventEspresso\core\services\shortcodes\ShortcodesManager'); |
|
1016 | - } |
|
1017 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
1018 | - // check for addons using old hook point |
|
1019 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
1020 | - $this->_incompatible_addon_error(); |
|
1021 | - } |
|
1022 | - } |
|
1023 | - |
|
1024 | - |
|
1025 | - /** |
|
1026 | - * _incompatible_addon_error |
|
1027 | - * |
|
1028 | - * @access public |
|
1029 | - * @return void |
|
1030 | - */ |
|
1031 | - private function _incompatible_addon_error() |
|
1032 | - { |
|
1033 | - // get array of classes hooking into here |
|
1034 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
1035 | - 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
1036 | - ); |
|
1037 | - if (! empty($class_names)) { |
|
1038 | - $msg = esc_html__( |
|
1039 | - 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
1040 | - 'event_espresso' |
|
1041 | - ); |
|
1042 | - $msg .= '<ul>'; |
|
1043 | - foreach ($class_names as $class_name) { |
|
1044 | - $msg .= '<li><b>Event Espresso - ' |
|
1045 | - . str_replace( |
|
1046 | - array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), |
|
1047 | - '', |
|
1048 | - $class_name |
|
1049 | - ) . '</b></li>'; |
|
1050 | - } |
|
1051 | - $msg .= '</ul>'; |
|
1052 | - $msg .= esc_html__( |
|
1053 | - 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
1054 | - 'event_espresso' |
|
1055 | - ); |
|
1056 | - // save list of incompatible addons to wp-options for later use |
|
1057 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
1058 | - if (is_admin()) { |
|
1059 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1060 | - } |
|
1061 | - } |
|
1062 | - } |
|
1063 | - |
|
1064 | - |
|
1065 | - /** |
|
1066 | - * brew_espresso |
|
1067 | - * begins the process of setting hooks for initializing EE in the correct order |
|
1068 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
1069 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
1070 | - * |
|
1071 | - * @return void |
|
1072 | - */ |
|
1073 | - public function brew_espresso() |
|
1074 | - { |
|
1075 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
1076 | - // load some final core systems |
|
1077 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
1078 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
1079 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
1080 | - add_action('init', array($this, 'load_controllers'), 7); |
|
1081 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
1082 | - add_action('init', array($this, 'initialize'), 10); |
|
1083 | - add_action('init', array($this, 'initialize_last'), 100); |
|
1084 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
1085 | - // pew pew pew |
|
1086 | - $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService'); |
|
1087 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
1088 | - } |
|
1089 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
1090 | - } |
|
1091 | - |
|
1092 | - |
|
1093 | - /** |
|
1094 | - * set_hooks_for_core |
|
1095 | - * |
|
1096 | - * @access public |
|
1097 | - * @return void |
|
1098 | - * @throws EE_Error |
|
1099 | - */ |
|
1100 | - public function set_hooks_for_core() |
|
1101 | - { |
|
1102 | - $this->_deactivate_incompatible_addons(); |
|
1103 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
1104 | - $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan'); |
|
1105 | - // caps need to be initialized on every request so that capability maps are set. |
|
1106 | - // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
1107 | - $this->registry->CAP->init_caps(); |
|
1108 | - } |
|
1109 | - |
|
1110 | - |
|
1111 | - /** |
|
1112 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
1113 | - * deactivates any addons considered incompatible with the current version of EE |
|
1114 | - */ |
|
1115 | - private function _deactivate_incompatible_addons() |
|
1116 | - { |
|
1117 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
1118 | - if (! empty($incompatible_addons)) { |
|
1119 | - $active_plugins = get_option('active_plugins', array()); |
|
1120 | - foreach ($active_plugins as $active_plugin) { |
|
1121 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
1122 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
1123 | - $this->request->unSetRequestParams(['activate'], true); |
|
1124 | - espresso_deactivate_plugin($active_plugin); |
|
1125 | - } |
|
1126 | - } |
|
1127 | - } |
|
1128 | - } |
|
1129 | - } |
|
1130 | - |
|
1131 | - |
|
1132 | - /** |
|
1133 | - * perform_activations_upgrades_and_migrations |
|
1134 | - * |
|
1135 | - * @access public |
|
1136 | - * @return void |
|
1137 | - */ |
|
1138 | - public function perform_activations_upgrades_and_migrations() |
|
1139 | - { |
|
1140 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
1141 | - } |
|
1142 | - |
|
1143 | - |
|
1144 | - /** |
|
1145 | - * @return void |
|
1146 | - * @throws DomainException |
|
1147 | - */ |
|
1148 | - public function load_CPTs_and_session() |
|
1149 | - { |
|
1150 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
1151 | - $this->register_custom_taxonomies->registerCustomTaxonomies(); |
|
1152 | - $this->register_custom_post_types->registerCustomPostTypes(); |
|
1153 | - $this->register_custom_taxonomy_terms->registerCustomTaxonomyTerms(); |
|
1154 | - // load legacy Custom Post Types and Taxonomies |
|
1155 | - $this->loader->getShared('EE_Register_CPTs'); |
|
1156 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
1157 | - } |
|
1158 | - |
|
1159 | - |
|
1160 | - /** |
|
1161 | - * load_controllers |
|
1162 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
1163 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
1164 | - * time |
|
1165 | - * |
|
1166 | - * @access public |
|
1167 | - * @return void |
|
1168 | - */ |
|
1169 | - public function load_controllers() |
|
1170 | - { |
|
1171 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
1172 | - // let's get it started |
|
1173 | - if ( |
|
1174 | - ! $this->maintenance_mode->level() |
|
1175 | - && ($this->request->isFrontend() || $this->request->isFrontAjax()) |
|
1176 | - ) { |
|
1177 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
1178 | - $this->loader->getShared('EE_Front_Controller'); |
|
1179 | - } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) { |
|
1180 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
1181 | - $this->loader->getShared('EE_Admin'); |
|
1182 | - } elseif ($this->request->isWordPressHeartbeat()) { |
|
1183 | - $this->loader->getShared('EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat'); |
|
1184 | - } |
|
1185 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
1186 | - } |
|
1187 | - |
|
1188 | - |
|
1189 | - /** |
|
1190 | - * core_loaded_and_ready |
|
1191 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
1192 | - * |
|
1193 | - * @access public |
|
1194 | - * @return void |
|
1195 | - * @throws Exception |
|
1196 | - */ |
|
1197 | - public function core_loaded_and_ready() |
|
1198 | - { |
|
1199 | - if ( |
|
1200 | - $this->request->isAdmin() |
|
1201 | - || $this->request->isFrontend() |
|
1202 | - || $this->request->isIframe() |
|
1203 | - || $this->request->isWordPressApi() |
|
1204 | - ) { |
|
1205 | - try { |
|
1206 | - $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
1207 | - $this->loader->getShared('EventEspresso\core\domain\services\assets\CoreAssetManager'); |
|
1208 | - if ($this->canLoadBlocks()) { |
|
1209 | - $this->loader->getShared( |
|
1210 | - 'EventEspresso\core\services\editor\BlockRegistrationManager' |
|
1211 | - ); |
|
1212 | - } |
|
1213 | - } catch (Exception $exception) { |
|
1214 | - new ExceptionStackTraceDisplay($exception); |
|
1215 | - } |
|
1216 | - } |
|
1217 | - if ( |
|
1218 | - $this->request->isAdmin() |
|
1219 | - || $this->request->isEeAjax() |
|
1220 | - || $this->request->isFrontend() |
|
1221 | - ) { |
|
1222 | - $this->loader->getShared('EE_Session'); |
|
1223 | - } |
|
1224 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
1225 | - // always load template tags, because it's faster than checking if it's a front-end request, and many page |
|
1226 | - // builders require these even on the front-end |
|
1227 | - require_once EE_PUBLIC . 'template_tags.php'; |
|
1228 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
1229 | - } |
|
1230 | - |
|
1231 | - |
|
1232 | - /** |
|
1233 | - * initialize |
|
1234 | - * this is the best place to begin initializing client code |
|
1235 | - * |
|
1236 | - * @access public |
|
1237 | - * @return void |
|
1238 | - */ |
|
1239 | - public function initialize() |
|
1240 | - { |
|
1241 | - do_action('AHEE__EE_System__initialize'); |
|
1242 | - add_filter( |
|
1243 | - 'safe_style_css', |
|
1244 | - function ($styles) { |
|
1245 | - $styles[] = 'display'; |
|
1246 | - $styles[] = 'visibility'; |
|
1247 | - $styles[] = 'position'; |
|
1248 | - $styles[] = 'top'; |
|
1249 | - $styles[] = 'right'; |
|
1250 | - $styles[] = 'bottom'; |
|
1251 | - $styles[] = 'left'; |
|
1252 | - $styles[] = 'resize'; |
|
1253 | - $styles[] = 'max-width'; |
|
1254 | - $styles[] = 'max-height'; |
|
1255 | - return $styles; |
|
1256 | - } |
|
1257 | - ); |
|
1258 | - } |
|
1259 | - |
|
1260 | - |
|
1261 | - /** |
|
1262 | - * initialize_last |
|
1263 | - * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
1264 | - * initialize has done so |
|
1265 | - * |
|
1266 | - * @access public |
|
1267 | - * @return void |
|
1268 | - */ |
|
1269 | - public function initialize_last() |
|
1270 | - { |
|
1271 | - do_action('AHEE__EE_System__initialize_last'); |
|
1272 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
1273 | - $rewrite_rules = $this->loader->getShared( |
|
1274 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
1275 | - ); |
|
1276 | - $rewrite_rules->flushRewriteRules(); |
|
1277 | - add_action('admin_bar_init', array($this, 'addEspressoToolbar')); |
|
1278 | - if ( |
|
1279 | - ($this->request->isAjax() || $this->request->isAdmin()) |
|
1280 | - && $this->maintenance_mode->models_can_query() |
|
1281 | - ) { |
|
1282 | - $this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager'); |
|
1283 | - $this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager'); |
|
1284 | - } |
|
1285 | - } |
|
1286 | - |
|
1287 | - |
|
1288 | - /** |
|
1289 | - * @return void |
|
1290 | - * @throws EE_Error |
|
1291 | - */ |
|
1292 | - public function addEspressoToolbar() |
|
1293 | - { |
|
1294 | - $this->loader->getShared( |
|
1295 | - 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
1296 | - array($this->registry->CAP) |
|
1297 | - ); |
|
1298 | - } |
|
1299 | - |
|
1300 | - |
|
1301 | - /** |
|
1302 | - * do_not_cache |
|
1303 | - * sets no cache headers and defines no cache constants for WP plugins |
|
1304 | - * |
|
1305 | - * @access public |
|
1306 | - * @return void |
|
1307 | - */ |
|
1308 | - public static function do_not_cache() |
|
1309 | - { |
|
1310 | - // set no cache constants |
|
1311 | - if (! defined('DONOTCACHEPAGE')) { |
|
1312 | - define('DONOTCACHEPAGE', true); |
|
1313 | - } |
|
1314 | - if (! defined('DONOTCACHCEOBJECT')) { |
|
1315 | - define('DONOTCACHCEOBJECT', true); |
|
1316 | - } |
|
1317 | - if (! defined('DONOTCACHEDB')) { |
|
1318 | - define('DONOTCACHEDB', true); |
|
1319 | - } |
|
1320 | - // add no cache headers |
|
1321 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
1322 | - // plus a little extra for nginx and Google Chrome |
|
1323 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1324 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1325 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1326 | - } |
|
1327 | - |
|
1328 | - |
|
1329 | - /** |
|
1330 | - * extra_nocache_headers |
|
1331 | - * |
|
1332 | - * @access public |
|
1333 | - * @param $headers |
|
1334 | - * @return array |
|
1335 | - */ |
|
1336 | - public static function extra_nocache_headers($headers) |
|
1337 | - { |
|
1338 | - // for NGINX |
|
1339 | - $headers['X-Accel-Expires'] = 0; |
|
1340 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1341 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1342 | - return $headers; |
|
1343 | - } |
|
1344 | - |
|
1345 | - |
|
1346 | - /** |
|
1347 | - * nocache_headers |
|
1348 | - * |
|
1349 | - * @access public |
|
1350 | - * @return void |
|
1351 | - */ |
|
1352 | - public static function nocache_headers() |
|
1353 | - { |
|
1354 | - nocache_headers(); |
|
1355 | - } |
|
1356 | - |
|
1357 | - |
|
1358 | - /** |
|
1359 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1360 | - * never returned with the function. |
|
1361 | - * |
|
1362 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
1363 | - * @return array |
|
1364 | - */ |
|
1365 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
1366 | - { |
|
1367 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1368 | - } |
|
1369 | - |
|
1370 | - |
|
1371 | - /** |
|
1372 | - * Return whether blocks can be registered/loaded or not. |
|
1373 | - * @return bool |
|
1374 | - */ |
|
1375 | - private function canLoadBlocks() |
|
1376 | - { |
|
1377 | - return apply_filters('FHEE__EE_System__canLoadBlocks', true) |
|
1378 | - && function_exists('register_block_type') |
|
1379 | - // don't load blocks if in the Divi page builder editor context |
|
1380 | - // @see https://github.com/eventespresso/event-espresso-core/issues/814 |
|
1381 | - && ! $this->request->getRequestParam('et_fb', false); |
|
1382 | - } |
|
30 | + /** |
|
31 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
32 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
33 | + */ |
|
34 | + const req_type_normal = 0; |
|
35 | + |
|
36 | + /** |
|
37 | + * Indicates this is a brand new installation of EE so we should install |
|
38 | + * tables and default data etc |
|
39 | + */ |
|
40 | + const req_type_new_activation = 1; |
|
41 | + |
|
42 | + /** |
|
43 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
44 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
45 | + * and that default data is setup too |
|
46 | + */ |
|
47 | + const req_type_reactivation = 2; |
|
48 | + |
|
49 | + /** |
|
50 | + * indicates that EE has been upgraded since its previous request. |
|
51 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
52 | + */ |
|
53 | + const req_type_upgrade = 3; |
|
54 | + |
|
55 | + /** |
|
56 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
57 | + */ |
|
58 | + const req_type_downgrade = 4; |
|
59 | + |
|
60 | + /** |
|
61 | + * @deprecated since version 4.6.0.dev.006 |
|
62 | + * Now whenever a new_activation is detected the request type is still just |
|
63 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
64 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
65 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
66 | + * (Specifically, when the migration manager indicates migrations are finished |
|
67 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
68 | + */ |
|
69 | + const req_type_activation_but_not_installed = 5; |
|
70 | + |
|
71 | + /** |
|
72 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
73 | + */ |
|
74 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
75 | + |
|
76 | + /** |
|
77 | + * @var EE_System $_instance |
|
78 | + */ |
|
79 | + private static $_instance; |
|
80 | + |
|
81 | + /** |
|
82 | + * @var EE_Registry $registry |
|
83 | + */ |
|
84 | + private $registry; |
|
85 | + |
|
86 | + /** |
|
87 | + * @var LoaderInterface $loader |
|
88 | + */ |
|
89 | + private $loader; |
|
90 | + |
|
91 | + /** |
|
92 | + * @var EE_Capabilities $capabilities |
|
93 | + */ |
|
94 | + private $capabilities; |
|
95 | + |
|
96 | + /** |
|
97 | + * @var RequestInterface $request |
|
98 | + */ |
|
99 | + private $request; |
|
100 | + |
|
101 | + /** |
|
102 | + * @var EE_Maintenance_Mode $maintenance_mode |
|
103 | + */ |
|
104 | + private $maintenance_mode; |
|
105 | + |
|
106 | + /** |
|
107 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
108 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
109 | + * |
|
110 | + * @var int $_req_type |
|
111 | + */ |
|
112 | + private $_req_type; |
|
113 | + |
|
114 | + /** |
|
115 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
116 | + * |
|
117 | + * @var boolean $_major_version_change |
|
118 | + */ |
|
119 | + private $_major_version_change = false; |
|
120 | + |
|
121 | + /** |
|
122 | + * A Context DTO dedicated solely to identifying the current request type. |
|
123 | + * |
|
124 | + * @var RequestTypeContextCheckerInterface $request_type |
|
125 | + */ |
|
126 | + private $request_type; |
|
127 | + |
|
128 | + /** |
|
129 | + * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes |
|
130 | + */ |
|
131 | + private $register_custom_post_types; |
|
132 | + |
|
133 | + /** |
|
134 | + * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies |
|
135 | + */ |
|
136 | + private $register_custom_taxonomies; |
|
137 | + |
|
138 | + /** |
|
139 | + * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms |
|
140 | + */ |
|
141 | + private $register_custom_taxonomy_terms; |
|
142 | + |
|
143 | + /** |
|
144 | + * @singleton method used to instantiate class object |
|
145 | + * @param EE_Registry|null $registry |
|
146 | + * @param LoaderInterface|null $loader |
|
147 | + * @param RequestInterface|null $request |
|
148 | + * @param EE_Maintenance_Mode|null $maintenance_mode |
|
149 | + * @return EE_System |
|
150 | + */ |
|
151 | + public static function instance( |
|
152 | + EE_Registry $registry = null, |
|
153 | + LoaderInterface $loader = null, |
|
154 | + RequestInterface $request = null, |
|
155 | + EE_Maintenance_Mode $maintenance_mode = null |
|
156 | + ) { |
|
157 | + // check if class object is instantiated |
|
158 | + if (! self::$_instance instanceof EE_System) { |
|
159 | + self::$_instance = new self($registry, $loader, $request, $maintenance_mode); |
|
160 | + } |
|
161 | + return self::$_instance; |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * resets the instance and returns it |
|
167 | + * |
|
168 | + * @return EE_System |
|
169 | + */ |
|
170 | + public static function reset() |
|
171 | + { |
|
172 | + self::$_instance->_req_type = null; |
|
173 | + // make sure none of the old hooks are left hanging around |
|
174 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
175 | + // we need to reset the migration manager in order for it to detect DMSs properly |
|
176 | + EE_Data_Migration_Manager::reset(); |
|
177 | + self::instance()->detect_activations_or_upgrades(); |
|
178 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
179 | + return self::instance(); |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * sets hooks for running rest of system |
|
185 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
186 | + * starting EE Addons from any other point may lead to problems |
|
187 | + * |
|
188 | + * @param EE_Registry $registry |
|
189 | + * @param LoaderInterface $loader |
|
190 | + * @param RequestInterface $request |
|
191 | + * @param EE_Maintenance_Mode $maintenance_mode |
|
192 | + */ |
|
193 | + private function __construct( |
|
194 | + EE_Registry $registry, |
|
195 | + LoaderInterface $loader, |
|
196 | + RequestInterface $request, |
|
197 | + EE_Maintenance_Mode $maintenance_mode |
|
198 | + ) { |
|
199 | + $this->registry = $registry; |
|
200 | + $this->loader = $loader; |
|
201 | + $this->request = $request; |
|
202 | + $this->maintenance_mode = $maintenance_mode; |
|
203 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
204 | + add_action( |
|
205 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
206 | + array($this, 'loadCapabilities'), |
|
207 | + 5 |
|
208 | + ); |
|
209 | + add_action( |
|
210 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
211 | + array($this, 'loadCommandBus'), |
|
212 | + 7 |
|
213 | + ); |
|
214 | + add_action( |
|
215 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
216 | + array($this, 'loadPluginApi'), |
|
217 | + 9 |
|
218 | + ); |
|
219 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
220 | + add_action( |
|
221 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
222 | + array($this, 'load_espresso_addons') |
|
223 | + ); |
|
224 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
225 | + // because the newly-activated addon didn't get a chance to run at all |
|
226 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
227 | + // detect whether install or upgrade |
|
228 | + add_action( |
|
229 | + 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
230 | + array($this, 'detect_activations_or_upgrades'), |
|
231 | + 3 |
|
232 | + ); |
|
233 | + // load EE_Config, EE_Textdomain, etc |
|
234 | + add_action( |
|
235 | + 'AHEE__EE_Bootstrap__load_core_configuration', |
|
236 | + array($this, 'load_core_configuration'), |
|
237 | + 5 |
|
238 | + ); |
|
239 | + // load specifications for matching routes to current request |
|
240 | + add_action( |
|
241 | + 'AHEE__EE_Bootstrap__load_core_configuration', |
|
242 | + array($this, 'loadRouteMatchSpecifications') |
|
243 | + ); |
|
244 | + // load specifications for custom post types |
|
245 | + add_action( |
|
246 | + 'AHEE__EE_Bootstrap__load_core_configuration', |
|
247 | + array($this, 'loadCustomPostTypes') |
|
248 | + ); |
|
249 | + // load EE_Config, EE_Textdomain, etc |
|
250 | + add_action( |
|
251 | + 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
252 | + array($this, 'register_shortcodes_modules_and_widgets'), |
|
253 | + 7 |
|
254 | + ); |
|
255 | + // you wanna get going? I wanna get going... let's get going! |
|
256 | + add_action( |
|
257 | + 'AHEE__EE_Bootstrap__brew_espresso', |
|
258 | + array($this, 'brew_espresso'), |
|
259 | + 9 |
|
260 | + ); |
|
261 | + // other housekeeping |
|
262 | + // exclude EE critical pages from wp_list_pages |
|
263 | + add_filter( |
|
264 | + 'wp_list_pages_excludes', |
|
265 | + array($this, 'remove_pages_from_wp_list_pages'), |
|
266 | + 10 |
|
267 | + ); |
|
268 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
269 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
270 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * load and setup EE_Capabilities |
|
276 | + * |
|
277 | + * @return void |
|
278 | + * @throws EE_Error |
|
279 | + */ |
|
280 | + public function loadCapabilities() |
|
281 | + { |
|
282 | + $this->capabilities = $this->loader->getShared('EE_Capabilities'); |
|
283 | + add_action( |
|
284 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
285 | + function () { |
|
286 | + LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
287 | + } |
|
288 | + ); |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * create and cache the CommandBus, and also add middleware |
|
294 | + * The CapChecker middleware requires the use of EE_Capabilities |
|
295 | + * which is why we need to load the CommandBus after Caps are set up |
|
296 | + * |
|
297 | + * @return void |
|
298 | + * @throws EE_Error |
|
299 | + */ |
|
300 | + public function loadCommandBus() |
|
301 | + { |
|
302 | + $this->loader->getShared( |
|
303 | + 'CommandBusInterface', |
|
304 | + array( |
|
305 | + null, |
|
306 | + apply_filters( |
|
307 | + 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
308 | + array( |
|
309 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
310 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
311 | + ) |
|
312 | + ), |
|
313 | + ) |
|
314 | + ); |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * @return void |
|
320 | + * @throws EE_Error |
|
321 | + */ |
|
322 | + public function loadPluginApi() |
|
323 | + { |
|
324 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
325 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
326 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * @param string $addon_name |
|
332 | + * @param string $version_constant |
|
333 | + * @param string $min_version_required |
|
334 | + * @param string $load_callback |
|
335 | + * @param string $plugin_file_constant |
|
336 | + * @return void |
|
337 | + */ |
|
338 | + private function deactivateIncompatibleAddon( |
|
339 | + $addon_name, |
|
340 | + $version_constant, |
|
341 | + $min_version_required, |
|
342 | + $load_callback, |
|
343 | + $plugin_file_constant |
|
344 | + ) { |
|
345 | + if (! defined($version_constant)) { |
|
346 | + return; |
|
347 | + } |
|
348 | + $addon_version = constant($version_constant); |
|
349 | + if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
|
350 | + remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
|
351 | + if (! function_exists('deactivate_plugins')) { |
|
352 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
353 | + } |
|
354 | + deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
|
355 | + $this->request->unSetRequestParams(['activate', 'activate-multi'], true); |
|
356 | + EE_Error::add_error( |
|
357 | + sprintf( |
|
358 | + esc_html__( |
|
359 | + 'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.', |
|
360 | + 'event_espresso' |
|
361 | + ), |
|
362 | + $addon_name, |
|
363 | + $min_version_required |
|
364 | + ), |
|
365 | + __FILE__, |
|
366 | + __FUNCTION__ . "({$addon_name})", |
|
367 | + __LINE__ |
|
368 | + ); |
|
369 | + EE_Error::get_notices(false, true); |
|
370 | + } |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * load_espresso_addons |
|
376 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
377 | + * this is hooked into both: |
|
378 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
379 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
380 | + * and the WP 'activate_plugin' hook point |
|
381 | + * |
|
382 | + * @access public |
|
383 | + * @return void |
|
384 | + */ |
|
385 | + public function load_espresso_addons() |
|
386 | + { |
|
387 | + $this->deactivateIncompatibleAddon( |
|
388 | + 'Wait Lists', |
|
389 | + 'EE_WAIT_LISTS_VERSION', |
|
390 | + '1.0.0.beta.074', |
|
391 | + 'load_espresso_wait_lists', |
|
392 | + 'EE_WAIT_LISTS_PLUGIN_FILE' |
|
393 | + ); |
|
394 | + $this->deactivateIncompatibleAddon( |
|
395 | + 'Automated Upcoming Event Notifications', |
|
396 | + 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION', |
|
397 | + '1.0.0.beta.091', |
|
398 | + 'load_espresso_automated_upcoming_event_notification', |
|
399 | + 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE' |
|
400 | + ); |
|
401 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
402 | + // if the WP API basic auth plugin isn't already loaded, load it now. |
|
403 | + // We want it for mobile apps. Just include the entire plugin |
|
404 | + // also, don't load the basic auth when a plugin is getting activated, because |
|
405 | + // it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
406 | + // and causes a fatal error |
|
407 | + if ( |
|
408 | + ($this->request->isWordPressApi() || $this->request->isApi()) |
|
409 | + && $this->request->getRequestParam('activate') !== 'true' |
|
410 | + && ! function_exists('json_basic_auth_handler') |
|
411 | + && ! function_exists('json_basic_auth_error') |
|
412 | + && ! in_array( |
|
413 | + $this->request->getRequestParam('action'), |
|
414 | + array('activate', 'activate-selected'), |
|
415 | + true |
|
416 | + ) |
|
417 | + ) { |
|
418 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php'; |
|
419 | + } |
|
420 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * detect_activations_or_upgrades |
|
426 | + * Checks for activation or upgrade of core first; |
|
427 | + * then also checks if any registered addons have been activated or upgraded |
|
428 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
429 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
430 | + * |
|
431 | + * @access public |
|
432 | + * @return void |
|
433 | + */ |
|
434 | + public function detect_activations_or_upgrades() |
|
435 | + { |
|
436 | + // first off: let's make sure to handle core |
|
437 | + $this->detect_if_activation_or_upgrade(); |
|
438 | + foreach ($this->registry->addons as $addon) { |
|
439 | + if ($addon instanceof EE_Addon) { |
|
440 | + // detect teh request type for that addon |
|
441 | + $addon->detect_req_type(); |
|
442 | + } |
|
443 | + } |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * detect_if_activation_or_upgrade |
|
449 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
450 | + * and either setting up the DB or setting up maintenance mode etc. |
|
451 | + * |
|
452 | + * @access public |
|
453 | + * @return void |
|
454 | + */ |
|
455 | + public function detect_if_activation_or_upgrade() |
|
456 | + { |
|
457 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
458 | + // check if db has been updated, or if its a brand-new installation |
|
459 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
460 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
461 | + // EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
462 | + switch ($request_type) { |
|
463 | + case EE_System::req_type_new_activation: |
|
464 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
465 | + $this->_handle_core_version_change($espresso_db_update); |
|
466 | + break; |
|
467 | + case EE_System::req_type_reactivation: |
|
468 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
469 | + $this->_handle_core_version_change($espresso_db_update); |
|
470 | + break; |
|
471 | + case EE_System::req_type_upgrade: |
|
472 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
473 | + // migrations may be required now that we've upgraded |
|
474 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
475 | + $this->_handle_core_version_change($espresso_db_update); |
|
476 | + break; |
|
477 | + case EE_System::req_type_downgrade: |
|
478 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
479 | + // its possible migrations are no longer required |
|
480 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
481 | + $this->_handle_core_version_change($espresso_db_update); |
|
482 | + break; |
|
483 | + case EE_System::req_type_normal: |
|
484 | + default: |
|
485 | + break; |
|
486 | + } |
|
487 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * Updates the list of installed versions and sets hooks for |
|
493 | + * initializing the database later during the request |
|
494 | + * |
|
495 | + * @param array $espresso_db_update |
|
496 | + */ |
|
497 | + private function _handle_core_version_change($espresso_db_update) |
|
498 | + { |
|
499 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
500 | + // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
501 | + add_action( |
|
502 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
503 | + array($this, 'initialize_db_if_no_migrations_required') |
|
504 | + ); |
|
505 | + } |
|
506 | + |
|
507 | + |
|
508 | + /** |
|
509 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
510 | + * information about what versions of EE have been installed and activated, |
|
511 | + * NOT necessarily the state of the database |
|
512 | + * |
|
513 | + * @param mixed $espresso_db_update the value of the WordPress option. |
|
514 | + * If not supplied, fetches it from the options table |
|
515 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
516 | + */ |
|
517 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
518 | + { |
|
519 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
520 | + if (! $espresso_db_update) { |
|
521 | + $espresso_db_update = get_option('espresso_db_update'); |
|
522 | + } |
|
523 | + // check that option is an array |
|
524 | + if (! is_array($espresso_db_update)) { |
|
525 | + // if option is FALSE, then it never existed |
|
526 | + if ($espresso_db_update === false) { |
|
527 | + // make $espresso_db_update an array and save option with autoload OFF |
|
528 | + $espresso_db_update = array(); |
|
529 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
530 | + } else { |
|
531 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
532 | + $espresso_db_update = array($espresso_db_update => array()); |
|
533 | + update_option('espresso_db_update', $espresso_db_update); |
|
534 | + } |
|
535 | + } else { |
|
536 | + $corrected_db_update = array(); |
|
537 | + // if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
538 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
539 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
540 | + // the key is an int, and the value IS NOT an array |
|
541 | + // so it must be numerically-indexed, where values are versions installed... |
|
542 | + // fix it! |
|
543 | + $version_string = $should_be_array; |
|
544 | + $corrected_db_update[ $version_string ] = array('unknown-date'); |
|
545 | + } else { |
|
546 | + // ok it checks out |
|
547 | + $corrected_db_update[ $should_be_version_string ] = $should_be_array; |
|
548 | + } |
|
549 | + } |
|
550 | + $espresso_db_update = $corrected_db_update; |
|
551 | + update_option('espresso_db_update', $espresso_db_update); |
|
552 | + } |
|
553 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
554 | + return $espresso_db_update; |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
560 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
561 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
562 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
563 | + * so that it will be done when migrations are finished |
|
564 | + * |
|
565 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
566 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
567 | + * This is a resource-intensive job |
|
568 | + * so we prefer to only do it when necessary |
|
569 | + * @return void |
|
570 | + * @throws EE_Error |
|
571 | + */ |
|
572 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
573 | + { |
|
574 | + $request_type = $this->detect_req_type(); |
|
575 | + // only initialize system if we're not in maintenance mode. |
|
576 | + if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
577 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
578 | + $rewrite_rules = $this->loader->getShared( |
|
579 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
580 | + ); |
|
581 | + $rewrite_rules->flush(); |
|
582 | + if ($verify_schema) { |
|
583 | + EEH_Activation::initialize_db_and_folders(); |
|
584 | + } |
|
585 | + EEH_Activation::initialize_db_content(); |
|
586 | + EEH_Activation::system_initialization(); |
|
587 | + if ($initialize_addons_too) { |
|
588 | + $this->initialize_addons(); |
|
589 | + } |
|
590 | + } else { |
|
591 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
592 | + } |
|
593 | + if ( |
|
594 | + $request_type === EE_System::req_type_new_activation |
|
595 | + || $request_type === EE_System::req_type_reactivation |
|
596 | + || ( |
|
597 | + $request_type === EE_System::req_type_upgrade |
|
598 | + && $this->is_major_version_change() |
|
599 | + ) |
|
600 | + ) { |
|
601 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
602 | + } |
|
603 | + } |
|
604 | + |
|
605 | + |
|
606 | + /** |
|
607 | + * Initializes the db for all registered addons |
|
608 | + * |
|
609 | + * @throws EE_Error |
|
610 | + */ |
|
611 | + public function initialize_addons() |
|
612 | + { |
|
613 | + // foreach registered addon, make sure its db is up-to-date too |
|
614 | + foreach ($this->registry->addons as $addon) { |
|
615 | + if ($addon instanceof EE_Addon) { |
|
616 | + $addon->initialize_db_if_no_migrations_required(); |
|
617 | + } |
|
618 | + } |
|
619 | + } |
|
620 | + |
|
621 | + |
|
622 | + /** |
|
623 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
624 | + * |
|
625 | + * @param array $version_history |
|
626 | + * @param string $current_version_to_add version to be added to the version history |
|
627 | + * @return boolean success as to whether or not this option was changed |
|
628 | + */ |
|
629 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
630 | + { |
|
631 | + if (! $version_history) { |
|
632 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
633 | + } |
|
634 | + if ($current_version_to_add === null) { |
|
635 | + $current_version_to_add = espresso_version(); |
|
636 | + } |
|
637 | + $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
638 | + // re-save |
|
639 | + return update_option('espresso_db_update', $version_history); |
|
640 | + } |
|
641 | + |
|
642 | + |
|
643 | + /** |
|
644 | + * Detects if the current version indicated in the has existed in the list of |
|
645 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
646 | + * |
|
647 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
648 | + * If not supplied, fetches it from the options table. |
|
649 | + * Also, caches its result so later parts of the code can also know whether |
|
650 | + * there's been an update or not. This way we can add the current version to |
|
651 | + * espresso_db_update, but still know if this is a new install or not |
|
652 | + * @return int one of the constants on EE_System::req_type_ |
|
653 | + */ |
|
654 | + public function detect_req_type($espresso_db_update = null) |
|
655 | + { |
|
656 | + if ($this->_req_type === null) { |
|
657 | + $espresso_db_update = ! empty($espresso_db_update) |
|
658 | + ? $espresso_db_update |
|
659 | + : $this->fix_espresso_db_upgrade_option(); |
|
660 | + $this->_req_type = EE_System::detect_req_type_given_activation_history( |
|
661 | + $espresso_db_update, |
|
662 | + 'ee_espresso_activation', |
|
663 | + espresso_version() |
|
664 | + ); |
|
665 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
666 | + $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal); |
|
667 | + } |
|
668 | + return $this->_req_type; |
|
669 | + } |
|
670 | + |
|
671 | + |
|
672 | + /** |
|
673 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
674 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
675 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
676 | + * |
|
677 | + * @param $activation_history |
|
678 | + * @return bool |
|
679 | + */ |
|
680 | + private function _detect_major_version_change($activation_history) |
|
681 | + { |
|
682 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
683 | + $previous_version_parts = explode('.', $previous_version); |
|
684 | + $current_version_parts = explode('.', espresso_version()); |
|
685 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
686 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
687 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
688 | + ); |
|
689 | + } |
|
690 | + |
|
691 | + |
|
692 | + /** |
|
693 | + * Returns true if either the major or minor version of EE changed during this request. |
|
694 | + * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
695 | + * |
|
696 | + * @return bool |
|
697 | + */ |
|
698 | + public function is_major_version_change() |
|
699 | + { |
|
700 | + return $this->_major_version_change; |
|
701 | + } |
|
702 | + |
|
703 | + |
|
704 | + /** |
|
705 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
706 | + * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
707 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
708 | + * just activated to (for core that will always be espresso_version()) |
|
709 | + * |
|
710 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
711 | + * ee plugin. for core that's 'espresso_db_update' |
|
712 | + * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
713 | + * indicate that this plugin was just activated |
|
714 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
715 | + * espresso_version()) |
|
716 | + * @return int one of the constants on EE_System::req_type_* |
|
717 | + */ |
|
718 | + public static function detect_req_type_given_activation_history( |
|
719 | + $activation_history_for_addon, |
|
720 | + $activation_indicator_option_name, |
|
721 | + $version_to_upgrade_to |
|
722 | + ) { |
|
723 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
724 | + if ($activation_history_for_addon) { |
|
725 | + // it exists, so this isn't a completely new install |
|
726 | + // check if this version already in that list of previously installed versions |
|
727 | + if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { |
|
728 | + // it a version we haven't seen before |
|
729 | + if ($version_is_higher === 1) { |
|
730 | + $req_type = EE_System::req_type_upgrade; |
|
731 | + } else { |
|
732 | + $req_type = EE_System::req_type_downgrade; |
|
733 | + } |
|
734 | + delete_option($activation_indicator_option_name); |
|
735 | + } else { |
|
736 | + // its not an update. maybe a reactivation? |
|
737 | + if (get_option($activation_indicator_option_name, false)) { |
|
738 | + if ($version_is_higher === -1) { |
|
739 | + $req_type = EE_System::req_type_downgrade; |
|
740 | + } elseif ($version_is_higher === 0) { |
|
741 | + // we've seen this version before, but it's an activation. must be a reactivation |
|
742 | + $req_type = EE_System::req_type_reactivation; |
|
743 | + } else {// $version_is_higher === 1 |
|
744 | + $req_type = EE_System::req_type_upgrade; |
|
745 | + } |
|
746 | + delete_option($activation_indicator_option_name); |
|
747 | + } else { |
|
748 | + // we've seen this version before and the activation indicate doesn't show it was just activated |
|
749 | + if ($version_is_higher === -1) { |
|
750 | + $req_type = EE_System::req_type_downgrade; |
|
751 | + } elseif ($version_is_higher === 0) { |
|
752 | + // we've seen this version before and it's not an activation. its normal request |
|
753 | + $req_type = EE_System::req_type_normal; |
|
754 | + } else {// $version_is_higher === 1 |
|
755 | + $req_type = EE_System::req_type_upgrade; |
|
756 | + } |
|
757 | + } |
|
758 | + } |
|
759 | + } else { |
|
760 | + // brand new install |
|
761 | + $req_type = EE_System::req_type_new_activation; |
|
762 | + delete_option($activation_indicator_option_name); |
|
763 | + } |
|
764 | + return $req_type; |
|
765 | + } |
|
766 | + |
|
767 | + |
|
768 | + /** |
|
769 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
770 | + * the $activation_history_for_addon |
|
771 | + * |
|
772 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
773 | + * sometimes containing 'unknown-date' |
|
774 | + * @param string $version_to_upgrade_to (current version) |
|
775 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
776 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
777 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
778 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
779 | + */ |
|
780 | + private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
781 | + { |
|
782 | + // find the most recently-activated version |
|
783 | + $most_recently_active_version = |
|
784 | + EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
785 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
786 | + } |
|
787 | + |
|
788 | + |
|
789 | + /** |
|
790 | + * Gets the most recently active version listed in the activation history, |
|
791 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
792 | + * |
|
793 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
794 | + * sometimes containing 'unknown-date' |
|
795 | + * @return string |
|
796 | + */ |
|
797 | + private static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
798 | + { |
|
799 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
800 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
801 | + if (is_array($activation_history)) { |
|
802 | + foreach ($activation_history as $version => $times_activated) { |
|
803 | + // check there is a record of when this version was activated. Otherwise, |
|
804 | + // mark it as unknown |
|
805 | + if (! $times_activated) { |
|
806 | + $times_activated = array('unknown-date'); |
|
807 | + } |
|
808 | + if (is_string($times_activated)) { |
|
809 | + $times_activated = array($times_activated); |
|
810 | + } |
|
811 | + foreach ($times_activated as $an_activation) { |
|
812 | + if ( |
|
813 | + $an_activation !== 'unknown-date' |
|
814 | + && $an_activation |
|
815 | + > $most_recently_active_version_activation |
|
816 | + ) { |
|
817 | + $most_recently_active_version = $version; |
|
818 | + $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
819 | + ? '1970-01-01 00:00:00' |
|
820 | + : $an_activation; |
|
821 | + } |
|
822 | + } |
|
823 | + } |
|
824 | + } |
|
825 | + return $most_recently_active_version; |
|
826 | + } |
|
827 | + |
|
828 | + |
|
829 | + /** |
|
830 | + * This redirects to the about EE page after activation |
|
831 | + * |
|
832 | + * @return void |
|
833 | + */ |
|
834 | + public function redirect_to_about_ee() |
|
835 | + { |
|
836 | + $notices = EE_Error::get_notices(false); |
|
837 | + // if current user is an admin and it's not an ajax or rest request |
|
838 | + if ( |
|
839 | + ! isset($notices['errors']) |
|
840 | + && $this->request->isAdmin() |
|
841 | + && apply_filters( |
|
842 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
843 | + $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
844 | + ) |
|
845 | + ) { |
|
846 | + $query_params = array('page' => 'espresso_about'); |
|
847 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
848 | + $query_params['new_activation'] = true; |
|
849 | + } |
|
850 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
851 | + $query_params['reactivation'] = true; |
|
852 | + } |
|
853 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
854 | + wp_safe_redirect($url); |
|
855 | + exit(); |
|
856 | + } |
|
857 | + } |
|
858 | + |
|
859 | + |
|
860 | + /** |
|
861 | + * load_core_configuration |
|
862 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
863 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
864 | + * |
|
865 | + * @return void |
|
866 | + * @throws ReflectionException |
|
867 | + * @throws Exception |
|
868 | + */ |
|
869 | + public function load_core_configuration() |
|
870 | + { |
|
871 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
872 | + $this->loader->getShared('EE_Load_Textdomain'); |
|
873 | + // load textdomain |
|
874 | + EE_Load_Textdomain::load_textdomain(); |
|
875 | + // load caf stuff a chance to play during the activation process too. |
|
876 | + $this->_maybe_brew_regular(); |
|
877 | + // load and setup EE_Config and EE_Network_Config |
|
878 | + $config = $this->loader->getShared('EE_Config'); |
|
879 | + $this->loader->getShared('EE_Network_Config'); |
|
880 | + // setup autoloaders |
|
881 | + // enable logging? |
|
882 | + if ($config->admin->use_remote_logging) { |
|
883 | + $this->loader->getShared('EE_Log'); |
|
884 | + } |
|
885 | + // check for activation errors |
|
886 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
887 | + if ($activation_errors) { |
|
888 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
889 | + update_option('ee_plugin_activation_errors', false); |
|
890 | + } |
|
891 | + // get model names |
|
892 | + $this->_parse_model_names(); |
|
893 | + // configure custom post type definitions |
|
894 | + $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'); |
|
895 | + $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'); |
|
896 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
897 | + } |
|
898 | + |
|
899 | + |
|
900 | + /** |
|
901 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
902 | + * |
|
903 | + * @return void |
|
904 | + * @throws ReflectionException |
|
905 | + */ |
|
906 | + private function _parse_model_names() |
|
907 | + { |
|
908 | + // get all the files in the EE_MODELS folder that end in .model.php |
|
909 | + $models = glob(EE_MODELS . '*.model.php'); |
|
910 | + $model_names = array(); |
|
911 | + $non_abstract_db_models = array(); |
|
912 | + foreach ($models as $model) { |
|
913 | + // get model classname |
|
914 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
915 | + $short_name = str_replace('EEM_', '', $classname); |
|
916 | + $reflectionClass = new ReflectionClass($classname); |
|
917 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
918 | + $non_abstract_db_models[ $short_name ] = $classname; |
|
919 | + } |
|
920 | + $model_names[ $short_name ] = $classname; |
|
921 | + } |
|
922 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
923 | + $this->registry->non_abstract_db_models = apply_filters( |
|
924 | + 'FHEE__EE_System__parse_implemented_model_names', |
|
925 | + $non_abstract_db_models |
|
926 | + ); |
|
927 | + } |
|
928 | + |
|
929 | + |
|
930 | + /** |
|
931 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
932 | + * that need to be setup before our EE_System launches. |
|
933 | + * |
|
934 | + * @return void |
|
935 | + * @throws DomainException |
|
936 | + * @throws InvalidArgumentException |
|
937 | + * @throws InvalidDataTypeException |
|
938 | + * @throws InvalidInterfaceException |
|
939 | + * @throws InvalidClassException |
|
940 | + * @throws InvalidFilePathException |
|
941 | + */ |
|
942 | + private function _maybe_brew_regular() |
|
943 | + { |
|
944 | + /** @var Domain $domain */ |
|
945 | + $domain = DomainFactory::getShared( |
|
946 | + new FullyQualifiedName( |
|
947 | + 'EventEspresso\core\domain\Domain' |
|
948 | + ), |
|
949 | + array( |
|
950 | + new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
951 | + Version::fromString(espresso_version()), |
|
952 | + ) |
|
953 | + ); |
|
954 | + if ($domain->isCaffeinated()) { |
|
955 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
956 | + } |
|
957 | + } |
|
958 | + |
|
959 | + |
|
960 | + /** |
|
961 | + * @since 4.9.71.p |
|
962 | + * @throws Exception |
|
963 | + */ |
|
964 | + public function loadRouteMatchSpecifications() |
|
965 | + { |
|
966 | + try { |
|
967 | + $this->loader->getShared( |
|
968 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' |
|
969 | + ); |
|
970 | + } catch (Exception $exception) { |
|
971 | + new ExceptionStackTraceDisplay($exception); |
|
972 | + } |
|
973 | + do_action('AHEE__EE_System__loadRouteMatchSpecifications'); |
|
974 | + } |
|
975 | + |
|
976 | + |
|
977 | + /** |
|
978 | + * loading CPT related classes earlier so that their definitions are available |
|
979 | + * but not performing any actual registration with WP core until load_CPTs_and_session() is called |
|
980 | + * |
|
981 | + * @since 4.10.21.p |
|
982 | + */ |
|
983 | + public function loadCustomPostTypes() |
|
984 | + { |
|
985 | + $this->register_custom_taxonomies = $this->loader->getShared( |
|
986 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' |
|
987 | + ); |
|
988 | + $this->register_custom_post_types = $this->loader->getShared( |
|
989 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' |
|
990 | + ); |
|
991 | + $this->register_custom_taxonomy_terms = $this->loader->getShared( |
|
992 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms' |
|
993 | + ); |
|
994 | + // integrate WP_Query with the EE models |
|
995 | + $this->loader->getShared('EE_CPT_Strategy'); |
|
996 | + // load legacy EE_Request_Handler in case add-ons still need it |
|
997 | + $this->loader->getShared('EE_Request_Handler'); |
|
998 | + } |
|
999 | + |
|
1000 | + |
|
1001 | + /** |
|
1002 | + * register_shortcodes_modules_and_widgets |
|
1003 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
1004 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
1005 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
1006 | + * |
|
1007 | + * @access public |
|
1008 | + * @return void |
|
1009 | + * @throws Exception |
|
1010 | + */ |
|
1011 | + public function register_shortcodes_modules_and_widgets() |
|
1012 | + { |
|
1013 | + if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAjax()) { |
|
1014 | + // load, register, and add shortcodes the new way |
|
1015 | + $this->loader->getShared('EventEspresso\core\services\shortcodes\ShortcodesManager'); |
|
1016 | + } |
|
1017 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
1018 | + // check for addons using old hook point |
|
1019 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
1020 | + $this->_incompatible_addon_error(); |
|
1021 | + } |
|
1022 | + } |
|
1023 | + |
|
1024 | + |
|
1025 | + /** |
|
1026 | + * _incompatible_addon_error |
|
1027 | + * |
|
1028 | + * @access public |
|
1029 | + * @return void |
|
1030 | + */ |
|
1031 | + private function _incompatible_addon_error() |
|
1032 | + { |
|
1033 | + // get array of classes hooking into here |
|
1034 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
1035 | + 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
1036 | + ); |
|
1037 | + if (! empty($class_names)) { |
|
1038 | + $msg = esc_html__( |
|
1039 | + 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
1040 | + 'event_espresso' |
|
1041 | + ); |
|
1042 | + $msg .= '<ul>'; |
|
1043 | + foreach ($class_names as $class_name) { |
|
1044 | + $msg .= '<li><b>Event Espresso - ' |
|
1045 | + . str_replace( |
|
1046 | + array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), |
|
1047 | + '', |
|
1048 | + $class_name |
|
1049 | + ) . '</b></li>'; |
|
1050 | + } |
|
1051 | + $msg .= '</ul>'; |
|
1052 | + $msg .= esc_html__( |
|
1053 | + 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
1054 | + 'event_espresso' |
|
1055 | + ); |
|
1056 | + // save list of incompatible addons to wp-options for later use |
|
1057 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
1058 | + if (is_admin()) { |
|
1059 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1060 | + } |
|
1061 | + } |
|
1062 | + } |
|
1063 | + |
|
1064 | + |
|
1065 | + /** |
|
1066 | + * brew_espresso |
|
1067 | + * begins the process of setting hooks for initializing EE in the correct order |
|
1068 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
1069 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
1070 | + * |
|
1071 | + * @return void |
|
1072 | + */ |
|
1073 | + public function brew_espresso() |
|
1074 | + { |
|
1075 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
1076 | + // load some final core systems |
|
1077 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
1078 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
1079 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
1080 | + add_action('init', array($this, 'load_controllers'), 7); |
|
1081 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
1082 | + add_action('init', array($this, 'initialize'), 10); |
|
1083 | + add_action('init', array($this, 'initialize_last'), 100); |
|
1084 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
1085 | + // pew pew pew |
|
1086 | + $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService'); |
|
1087 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
1088 | + } |
|
1089 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
1090 | + } |
|
1091 | + |
|
1092 | + |
|
1093 | + /** |
|
1094 | + * set_hooks_for_core |
|
1095 | + * |
|
1096 | + * @access public |
|
1097 | + * @return void |
|
1098 | + * @throws EE_Error |
|
1099 | + */ |
|
1100 | + public function set_hooks_for_core() |
|
1101 | + { |
|
1102 | + $this->_deactivate_incompatible_addons(); |
|
1103 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
1104 | + $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan'); |
|
1105 | + // caps need to be initialized on every request so that capability maps are set. |
|
1106 | + // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
1107 | + $this->registry->CAP->init_caps(); |
|
1108 | + } |
|
1109 | + |
|
1110 | + |
|
1111 | + /** |
|
1112 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
1113 | + * deactivates any addons considered incompatible with the current version of EE |
|
1114 | + */ |
|
1115 | + private function _deactivate_incompatible_addons() |
|
1116 | + { |
|
1117 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
1118 | + if (! empty($incompatible_addons)) { |
|
1119 | + $active_plugins = get_option('active_plugins', array()); |
|
1120 | + foreach ($active_plugins as $active_plugin) { |
|
1121 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
1122 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
1123 | + $this->request->unSetRequestParams(['activate'], true); |
|
1124 | + espresso_deactivate_plugin($active_plugin); |
|
1125 | + } |
|
1126 | + } |
|
1127 | + } |
|
1128 | + } |
|
1129 | + } |
|
1130 | + |
|
1131 | + |
|
1132 | + /** |
|
1133 | + * perform_activations_upgrades_and_migrations |
|
1134 | + * |
|
1135 | + * @access public |
|
1136 | + * @return void |
|
1137 | + */ |
|
1138 | + public function perform_activations_upgrades_and_migrations() |
|
1139 | + { |
|
1140 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
1141 | + } |
|
1142 | + |
|
1143 | + |
|
1144 | + /** |
|
1145 | + * @return void |
|
1146 | + * @throws DomainException |
|
1147 | + */ |
|
1148 | + public function load_CPTs_and_session() |
|
1149 | + { |
|
1150 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
1151 | + $this->register_custom_taxonomies->registerCustomTaxonomies(); |
|
1152 | + $this->register_custom_post_types->registerCustomPostTypes(); |
|
1153 | + $this->register_custom_taxonomy_terms->registerCustomTaxonomyTerms(); |
|
1154 | + // load legacy Custom Post Types and Taxonomies |
|
1155 | + $this->loader->getShared('EE_Register_CPTs'); |
|
1156 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
1157 | + } |
|
1158 | + |
|
1159 | + |
|
1160 | + /** |
|
1161 | + * load_controllers |
|
1162 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
1163 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
1164 | + * time |
|
1165 | + * |
|
1166 | + * @access public |
|
1167 | + * @return void |
|
1168 | + */ |
|
1169 | + public function load_controllers() |
|
1170 | + { |
|
1171 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
1172 | + // let's get it started |
|
1173 | + if ( |
|
1174 | + ! $this->maintenance_mode->level() |
|
1175 | + && ($this->request->isFrontend() || $this->request->isFrontAjax()) |
|
1176 | + ) { |
|
1177 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
1178 | + $this->loader->getShared('EE_Front_Controller'); |
|
1179 | + } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) { |
|
1180 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
1181 | + $this->loader->getShared('EE_Admin'); |
|
1182 | + } elseif ($this->request->isWordPressHeartbeat()) { |
|
1183 | + $this->loader->getShared('EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat'); |
|
1184 | + } |
|
1185 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
1186 | + } |
|
1187 | + |
|
1188 | + |
|
1189 | + /** |
|
1190 | + * core_loaded_and_ready |
|
1191 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
1192 | + * |
|
1193 | + * @access public |
|
1194 | + * @return void |
|
1195 | + * @throws Exception |
|
1196 | + */ |
|
1197 | + public function core_loaded_and_ready() |
|
1198 | + { |
|
1199 | + if ( |
|
1200 | + $this->request->isAdmin() |
|
1201 | + || $this->request->isFrontend() |
|
1202 | + || $this->request->isIframe() |
|
1203 | + || $this->request->isWordPressApi() |
|
1204 | + ) { |
|
1205 | + try { |
|
1206 | + $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
1207 | + $this->loader->getShared('EventEspresso\core\domain\services\assets\CoreAssetManager'); |
|
1208 | + if ($this->canLoadBlocks()) { |
|
1209 | + $this->loader->getShared( |
|
1210 | + 'EventEspresso\core\services\editor\BlockRegistrationManager' |
|
1211 | + ); |
|
1212 | + } |
|
1213 | + } catch (Exception $exception) { |
|
1214 | + new ExceptionStackTraceDisplay($exception); |
|
1215 | + } |
|
1216 | + } |
|
1217 | + if ( |
|
1218 | + $this->request->isAdmin() |
|
1219 | + || $this->request->isEeAjax() |
|
1220 | + || $this->request->isFrontend() |
|
1221 | + ) { |
|
1222 | + $this->loader->getShared('EE_Session'); |
|
1223 | + } |
|
1224 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
1225 | + // always load template tags, because it's faster than checking if it's a front-end request, and many page |
|
1226 | + // builders require these even on the front-end |
|
1227 | + require_once EE_PUBLIC . 'template_tags.php'; |
|
1228 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
1229 | + } |
|
1230 | + |
|
1231 | + |
|
1232 | + /** |
|
1233 | + * initialize |
|
1234 | + * this is the best place to begin initializing client code |
|
1235 | + * |
|
1236 | + * @access public |
|
1237 | + * @return void |
|
1238 | + */ |
|
1239 | + public function initialize() |
|
1240 | + { |
|
1241 | + do_action('AHEE__EE_System__initialize'); |
|
1242 | + add_filter( |
|
1243 | + 'safe_style_css', |
|
1244 | + function ($styles) { |
|
1245 | + $styles[] = 'display'; |
|
1246 | + $styles[] = 'visibility'; |
|
1247 | + $styles[] = 'position'; |
|
1248 | + $styles[] = 'top'; |
|
1249 | + $styles[] = 'right'; |
|
1250 | + $styles[] = 'bottom'; |
|
1251 | + $styles[] = 'left'; |
|
1252 | + $styles[] = 'resize'; |
|
1253 | + $styles[] = 'max-width'; |
|
1254 | + $styles[] = 'max-height'; |
|
1255 | + return $styles; |
|
1256 | + } |
|
1257 | + ); |
|
1258 | + } |
|
1259 | + |
|
1260 | + |
|
1261 | + /** |
|
1262 | + * initialize_last |
|
1263 | + * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
1264 | + * initialize has done so |
|
1265 | + * |
|
1266 | + * @access public |
|
1267 | + * @return void |
|
1268 | + */ |
|
1269 | + public function initialize_last() |
|
1270 | + { |
|
1271 | + do_action('AHEE__EE_System__initialize_last'); |
|
1272 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
1273 | + $rewrite_rules = $this->loader->getShared( |
|
1274 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
1275 | + ); |
|
1276 | + $rewrite_rules->flushRewriteRules(); |
|
1277 | + add_action('admin_bar_init', array($this, 'addEspressoToolbar')); |
|
1278 | + if ( |
|
1279 | + ($this->request->isAjax() || $this->request->isAdmin()) |
|
1280 | + && $this->maintenance_mode->models_can_query() |
|
1281 | + ) { |
|
1282 | + $this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager'); |
|
1283 | + $this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager'); |
|
1284 | + } |
|
1285 | + } |
|
1286 | + |
|
1287 | + |
|
1288 | + /** |
|
1289 | + * @return void |
|
1290 | + * @throws EE_Error |
|
1291 | + */ |
|
1292 | + public function addEspressoToolbar() |
|
1293 | + { |
|
1294 | + $this->loader->getShared( |
|
1295 | + 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
1296 | + array($this->registry->CAP) |
|
1297 | + ); |
|
1298 | + } |
|
1299 | + |
|
1300 | + |
|
1301 | + /** |
|
1302 | + * do_not_cache |
|
1303 | + * sets no cache headers and defines no cache constants for WP plugins |
|
1304 | + * |
|
1305 | + * @access public |
|
1306 | + * @return void |
|
1307 | + */ |
|
1308 | + public static function do_not_cache() |
|
1309 | + { |
|
1310 | + // set no cache constants |
|
1311 | + if (! defined('DONOTCACHEPAGE')) { |
|
1312 | + define('DONOTCACHEPAGE', true); |
|
1313 | + } |
|
1314 | + if (! defined('DONOTCACHCEOBJECT')) { |
|
1315 | + define('DONOTCACHCEOBJECT', true); |
|
1316 | + } |
|
1317 | + if (! defined('DONOTCACHEDB')) { |
|
1318 | + define('DONOTCACHEDB', true); |
|
1319 | + } |
|
1320 | + // add no cache headers |
|
1321 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
1322 | + // plus a little extra for nginx and Google Chrome |
|
1323 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1324 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1325 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1326 | + } |
|
1327 | + |
|
1328 | + |
|
1329 | + /** |
|
1330 | + * extra_nocache_headers |
|
1331 | + * |
|
1332 | + * @access public |
|
1333 | + * @param $headers |
|
1334 | + * @return array |
|
1335 | + */ |
|
1336 | + public static function extra_nocache_headers($headers) |
|
1337 | + { |
|
1338 | + // for NGINX |
|
1339 | + $headers['X-Accel-Expires'] = 0; |
|
1340 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1341 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1342 | + return $headers; |
|
1343 | + } |
|
1344 | + |
|
1345 | + |
|
1346 | + /** |
|
1347 | + * nocache_headers |
|
1348 | + * |
|
1349 | + * @access public |
|
1350 | + * @return void |
|
1351 | + */ |
|
1352 | + public static function nocache_headers() |
|
1353 | + { |
|
1354 | + nocache_headers(); |
|
1355 | + } |
|
1356 | + |
|
1357 | + |
|
1358 | + /** |
|
1359 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1360 | + * never returned with the function. |
|
1361 | + * |
|
1362 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
1363 | + * @return array |
|
1364 | + */ |
|
1365 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
1366 | + { |
|
1367 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1368 | + } |
|
1369 | + |
|
1370 | + |
|
1371 | + /** |
|
1372 | + * Return whether blocks can be registered/loaded or not. |
|
1373 | + * @return bool |
|
1374 | + */ |
|
1375 | + private function canLoadBlocks() |
|
1376 | + { |
|
1377 | + return apply_filters('FHEE__EE_System__canLoadBlocks', true) |
|
1378 | + && function_exists('register_block_type') |
|
1379 | + // don't load blocks if in the Divi page builder editor context |
|
1380 | + // @see https://github.com/eventespresso/event-espresso-core/issues/814 |
|
1381 | + && ! $this->request->getRequestParam('et_fb', false); |
|
1382 | + } |
|
1383 | 1383 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | EE_Maintenance_Mode $maintenance_mode = null |
156 | 156 | ) { |
157 | 157 | // check if class object is instantiated |
158 | - if (! self::$_instance instanceof EE_System) { |
|
158 | + if ( ! self::$_instance instanceof EE_System) { |
|
159 | 159 | self::$_instance = new self($registry, $loader, $request, $maintenance_mode); |
160 | 160 | } |
161 | 161 | return self::$_instance; |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | $this->capabilities = $this->loader->getShared('EE_Capabilities'); |
283 | 283 | add_action( |
284 | 284 | 'AHEE__EE_Capabilities__init_caps__before_initialization', |
285 | - function () { |
|
285 | + function() { |
|
286 | 286 | LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
287 | 287 | } |
288 | 288 | ); |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | { |
324 | 324 | // set autoloaders for all of the classes implementing EEI_Plugin_API |
325 | 325 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
326 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
326 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api'); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | |
@@ -342,14 +342,14 @@ discard block |
||
342 | 342 | $load_callback, |
343 | 343 | $plugin_file_constant |
344 | 344 | ) { |
345 | - if (! defined($version_constant)) { |
|
345 | + if ( ! defined($version_constant)) { |
|
346 | 346 | return; |
347 | 347 | } |
348 | 348 | $addon_version = constant($version_constant); |
349 | 349 | if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
350 | 350 | remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
351 | - if (! function_exists('deactivate_plugins')) { |
|
352 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
351 | + if ( ! function_exists('deactivate_plugins')) { |
|
352 | + require_once ABSPATH.'wp-admin/includes/plugin.php'; |
|
353 | 353 | } |
354 | 354 | deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
355 | 355 | $this->request->unSetRequestParams(['activate', 'activate-multi'], true); |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | $min_version_required |
364 | 364 | ), |
365 | 365 | __FILE__, |
366 | - __FUNCTION__ . "({$addon_name})", |
|
366 | + __FUNCTION__."({$addon_name})", |
|
367 | 367 | __LINE__ |
368 | 368 | ); |
369 | 369 | EE_Error::get_notices(false, true); |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | true |
416 | 416 | ) |
417 | 417 | ) { |
418 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php'; |
|
418 | + include_once EE_THIRD_PARTY.'wp-api-basic-auth/basic-auth.php'; |
|
419 | 419 | } |
420 | 420 | do_action('AHEE__EE_System__load_espresso_addons__complete'); |
421 | 421 | } |
@@ -517,11 +517,11 @@ discard block |
||
517 | 517 | private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
518 | 518 | { |
519 | 519 | do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
520 | - if (! $espresso_db_update) { |
|
520 | + if ( ! $espresso_db_update) { |
|
521 | 521 | $espresso_db_update = get_option('espresso_db_update'); |
522 | 522 | } |
523 | 523 | // check that option is an array |
524 | - if (! is_array($espresso_db_update)) { |
|
524 | + if ( ! is_array($espresso_db_update)) { |
|
525 | 525 | // if option is FALSE, then it never existed |
526 | 526 | if ($espresso_db_update === false) { |
527 | 527 | // make $espresso_db_update an array and save option with autoload OFF |
@@ -541,10 +541,10 @@ discard block |
||
541 | 541 | // so it must be numerically-indexed, where values are versions installed... |
542 | 542 | // fix it! |
543 | 543 | $version_string = $should_be_array; |
544 | - $corrected_db_update[ $version_string ] = array('unknown-date'); |
|
544 | + $corrected_db_update[$version_string] = array('unknown-date'); |
|
545 | 545 | } else { |
546 | 546 | // ok it checks out |
547 | - $corrected_db_update[ $should_be_version_string ] = $should_be_array; |
|
547 | + $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
548 | 548 | } |
549 | 549 | } |
550 | 550 | $espresso_db_update = $corrected_db_update; |
@@ -628,13 +628,13 @@ discard block |
||
628 | 628 | */ |
629 | 629 | public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
630 | 630 | { |
631 | - if (! $version_history) { |
|
631 | + if ( ! $version_history) { |
|
632 | 632 | $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
633 | 633 | } |
634 | 634 | if ($current_version_to_add === null) { |
635 | 635 | $current_version_to_add = espresso_version(); |
636 | 636 | } |
637 | - $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
637 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
638 | 638 | // re-save |
639 | 639 | return update_option('espresso_db_update', $version_history); |
640 | 640 | } |
@@ -724,7 +724,7 @@ discard block |
||
724 | 724 | if ($activation_history_for_addon) { |
725 | 725 | // it exists, so this isn't a completely new install |
726 | 726 | // check if this version already in that list of previously installed versions |
727 | - if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { |
|
727 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
728 | 728 | // it a version we haven't seen before |
729 | 729 | if ($version_is_higher === 1) { |
730 | 730 | $req_type = EE_System::req_type_upgrade; |
@@ -802,7 +802,7 @@ discard block |
||
802 | 802 | foreach ($activation_history as $version => $times_activated) { |
803 | 803 | // check there is a record of when this version was activated. Otherwise, |
804 | 804 | // mark it as unknown |
805 | - if (! $times_activated) { |
|
805 | + if ( ! $times_activated) { |
|
806 | 806 | $times_activated = array('unknown-date'); |
807 | 807 | } |
808 | 808 | if (is_string($times_activated)) { |
@@ -906,7 +906,7 @@ discard block |
||
906 | 906 | private function _parse_model_names() |
907 | 907 | { |
908 | 908 | // get all the files in the EE_MODELS folder that end in .model.php |
909 | - $models = glob(EE_MODELS . '*.model.php'); |
|
909 | + $models = glob(EE_MODELS.'*.model.php'); |
|
910 | 910 | $model_names = array(); |
911 | 911 | $non_abstract_db_models = array(); |
912 | 912 | foreach ($models as $model) { |
@@ -915,9 +915,9 @@ discard block |
||
915 | 915 | $short_name = str_replace('EEM_', '', $classname); |
916 | 916 | $reflectionClass = new ReflectionClass($classname); |
917 | 917 | if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
918 | - $non_abstract_db_models[ $short_name ] = $classname; |
|
918 | + $non_abstract_db_models[$short_name] = $classname; |
|
919 | 919 | } |
920 | - $model_names[ $short_name ] = $classname; |
|
920 | + $model_names[$short_name] = $classname; |
|
921 | 921 | } |
922 | 922 | $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
923 | 923 | $this->registry->non_abstract_db_models = apply_filters( |
@@ -952,7 +952,7 @@ discard block |
||
952 | 952 | ) |
953 | 953 | ); |
954 | 954 | if ($domain->isCaffeinated()) { |
955 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
955 | + require_once EE_CAFF_PATH.'brewing_regular.php'; |
|
956 | 956 | } |
957 | 957 | } |
958 | 958 | |
@@ -1034,7 +1034,7 @@ discard block |
||
1034 | 1034 | $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
1035 | 1035 | 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
1036 | 1036 | ); |
1037 | - if (! empty($class_names)) { |
|
1037 | + if ( ! empty($class_names)) { |
|
1038 | 1038 | $msg = esc_html__( |
1039 | 1039 | 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
1040 | 1040 | 'event_espresso' |
@@ -1046,7 +1046,7 @@ discard block |
||
1046 | 1046 | array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), |
1047 | 1047 | '', |
1048 | 1048 | $class_name |
1049 | - ) . '</b></li>'; |
|
1049 | + ).'</b></li>'; |
|
1050 | 1050 | } |
1051 | 1051 | $msg .= '</ul>'; |
1052 | 1052 | $msg .= esc_html__( |
@@ -1115,7 +1115,7 @@ discard block |
||
1115 | 1115 | private function _deactivate_incompatible_addons() |
1116 | 1116 | { |
1117 | 1117 | $incompatible_addons = get_option('ee_incompatible_addons', array()); |
1118 | - if (! empty($incompatible_addons)) { |
|
1118 | + if ( ! empty($incompatible_addons)) { |
|
1119 | 1119 | $active_plugins = get_option('active_plugins', array()); |
1120 | 1120 | foreach ($active_plugins as $active_plugin) { |
1121 | 1121 | foreach ($incompatible_addons as $incompatible_addon) { |
@@ -1224,7 +1224,7 @@ discard block |
||
1224 | 1224 | do_action('AHEE__EE_System__core_loaded_and_ready'); |
1225 | 1225 | // always load template tags, because it's faster than checking if it's a front-end request, and many page |
1226 | 1226 | // builders require these even on the front-end |
1227 | - require_once EE_PUBLIC . 'template_tags.php'; |
|
1227 | + require_once EE_PUBLIC.'template_tags.php'; |
|
1228 | 1228 | do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
1229 | 1229 | } |
1230 | 1230 | |
@@ -1241,7 +1241,7 @@ discard block |
||
1241 | 1241 | do_action('AHEE__EE_System__initialize'); |
1242 | 1242 | add_filter( |
1243 | 1243 | 'safe_style_css', |
1244 | - function ($styles) { |
|
1244 | + function($styles) { |
|
1245 | 1245 | $styles[] = 'display'; |
1246 | 1246 | $styles[] = 'visibility'; |
1247 | 1247 | $styles[] = 'position'; |
@@ -1308,13 +1308,13 @@ discard block |
||
1308 | 1308 | public static function do_not_cache() |
1309 | 1309 | { |
1310 | 1310 | // set no cache constants |
1311 | - if (! defined('DONOTCACHEPAGE')) { |
|
1311 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
1312 | 1312 | define('DONOTCACHEPAGE', true); |
1313 | 1313 | } |
1314 | - if (! defined('DONOTCACHCEOBJECT')) { |
|
1314 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
1315 | 1315 | define('DONOTCACHCEOBJECT', true); |
1316 | 1316 | } |
1317 | - if (! defined('DONOTCACHEDB')) { |
|
1317 | + if ( ! defined('DONOTCACHEDB')) { |
|
1318 | 1318 | define('DONOTCACHEDB', true); |
1319 | 1319 | } |
1320 | 1320 | // add no cache headers |