@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php 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 | - ); ?> |
|
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 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
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.3.9'); |
|
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 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.43.rc.015'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.43.rc.015'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\services\shortcodes\ShortcodesManager; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -19,1411 +19,1411 @@ discard block |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
24 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
25 | - */ |
|
26 | - const req_type_normal = 0; |
|
27 | - |
|
28 | - /** |
|
29 | - * Indicates this is a brand new installation of EE so we should install |
|
30 | - * tables and default data etc |
|
31 | - */ |
|
32 | - const req_type_new_activation = 1; |
|
33 | - |
|
34 | - /** |
|
35 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
36 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
37 | - * and that default data is setup too |
|
38 | - */ |
|
39 | - const req_type_reactivation = 2; |
|
40 | - |
|
41 | - /** |
|
42 | - * indicates that EE has been upgraded since its previous request. |
|
43 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
44 | - */ |
|
45 | - const req_type_upgrade = 3; |
|
46 | - |
|
47 | - /** |
|
48 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
49 | - */ |
|
50 | - const req_type_downgrade = 4; |
|
51 | - |
|
52 | - /** |
|
53 | - * @deprecated since version 4.6.0.dev.006 |
|
54 | - * Now whenever a new_activation is detected the request type is still just |
|
55 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
56 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
57 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
58 | - * (Specifically, when the migration manager indicates migrations are finished |
|
59 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
60 | - */ |
|
61 | - const req_type_activation_but_not_installed = 5; |
|
62 | - |
|
63 | - /** |
|
64 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
65 | - */ |
|
66 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * instance of the EE_System object |
|
71 | - * |
|
72 | - * @var $_instance |
|
73 | - * @access private |
|
74 | - */ |
|
75 | - private static $_instance = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * @type EE_Registry $Registry |
|
79 | - * @access protected |
|
80 | - */ |
|
81 | - protected $registry; |
|
82 | - |
|
83 | - /** |
|
84 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
85 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
86 | - * |
|
87 | - * @var int |
|
88 | - */ |
|
89 | - private $_req_type; |
|
90 | - |
|
91 | - /** |
|
92 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
93 | - * |
|
94 | - * @var boolean |
|
95 | - */ |
|
96 | - private $_major_version_change = false; |
|
97 | - |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @singleton method used to instantiate class object |
|
102 | - * @access public |
|
103 | - * @param \EE_Registry $Registry |
|
104 | - * @return \EE_System |
|
105 | - */ |
|
106 | - public static function instance(EE_Registry $Registry = null) |
|
107 | - { |
|
108 | - // check if class object is instantiated |
|
109 | - if ( ! self::$_instance instanceof EE_System) { |
|
110 | - self::$_instance = new self($Registry); |
|
111 | - } |
|
112 | - return self::$_instance; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * resets the instance and returns it |
|
119 | - * |
|
120 | - * @return EE_System |
|
121 | - */ |
|
122 | - public static function reset() |
|
123 | - { |
|
124 | - self::$_instance->_req_type = null; |
|
125 | - //make sure none of the old hooks are left hanging around |
|
126 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
127 | - //we need to reset the migration manager in order for it to detect DMSs properly |
|
128 | - EE_Data_Migration_Manager::reset(); |
|
129 | - self::instance()->detect_activations_or_upgrades(); |
|
130 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
131 | - return self::instance(); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * sets hooks for running rest of system |
|
138 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
139 | - * starting EE Addons from any other point may lead to problems |
|
140 | - * |
|
141 | - * @access private |
|
142 | - * @param \EE_Registry $Registry |
|
143 | - */ |
|
144 | - private function __construct(EE_Registry $Registry) |
|
145 | - { |
|
146 | - $this->registry = $Registry; |
|
147 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
148 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
149 | - add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
150 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
151 | - // because the newly-activated addon didn't get a chance to run at all |
|
152 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
153 | - // detect whether install or upgrade |
|
154 | - add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
155 | - 3); |
|
156 | - // load EE_Config, EE_Textdomain, etc |
|
157 | - add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
158 | - // load EE_Config, EE_Textdomain, etc |
|
159 | - add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
160 | - array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
161 | - // you wanna get going? I wanna get going... let's get going! |
|
162 | - add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
163 | - //other housekeeping |
|
164 | - //exclude EE critical pages from wp_list_pages |
|
165 | - add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
166 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
167 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
168 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * load_espresso_addons |
|
175 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
176 | - * this is hooked into both: |
|
177 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
178 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
179 | - * and the WP 'activate_plugin' hookpoint |
|
180 | - * |
|
181 | - * @access public |
|
182 | - * @return void |
|
183 | - */ |
|
184 | - public function load_espresso_addons() |
|
185 | - { |
|
186 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
187 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
188 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
189 | - //load and setup EE_Capabilities |
|
190 | - $this->registry->load_core('Capabilities'); |
|
191 | - //caps need to be initialized on every request so that capability maps are set. |
|
192 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
193 | - $this->registry->CAP->init_caps(); |
|
194 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
195 | - //if the WP API basic auth plugin isn't already loaded, load it now. |
|
196 | - //We want it for mobile apps. Just include the entire plugin |
|
197 | - //also, don't load the basic auth when a plugin is getting activated, because |
|
198 | - //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
199 | - //and causes a fatal error |
|
200 | - if ( ! function_exists('json_basic_auth_handler') |
|
201 | - && ! function_exists('json_basic_auth_error') |
|
202 | - && ! ( |
|
203 | - isset($_GET['action']) |
|
204 | - && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
205 | - ) |
|
206 | - && ! ( |
|
207 | - isset($_GET['activate']) |
|
208 | - && $_GET['activate'] === 'true' |
|
209 | - ) |
|
210 | - ) { |
|
211 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
212 | - } |
|
213 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * detect_activations_or_upgrades |
|
220 | - * Checks for activation or upgrade of core first; |
|
221 | - * then also checks if any registered addons have been activated or upgraded |
|
222 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
223 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
224 | - * |
|
225 | - * @access public |
|
226 | - * @return void |
|
227 | - */ |
|
228 | - public function detect_activations_or_upgrades() |
|
229 | - { |
|
230 | - //first off: let's make sure to handle core |
|
231 | - $this->detect_if_activation_or_upgrade(); |
|
232 | - foreach ($this->registry->addons as $addon) { |
|
233 | - //detect teh request type for that addon |
|
234 | - $addon->detect_activation_or_upgrade(); |
|
235 | - } |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * detect_if_activation_or_upgrade |
|
242 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
243 | - * and either setting up the DB or setting up maintenance mode etc. |
|
244 | - * |
|
245 | - * @access public |
|
246 | - * @return void |
|
247 | - */ |
|
248 | - public function detect_if_activation_or_upgrade() |
|
249 | - { |
|
250 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
251 | - // load M-Mode class |
|
252 | - $this->registry->load_core('Maintenance_Mode'); |
|
253 | - // check if db has been updated, or if its a brand-new installation |
|
254 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
255 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
256 | - //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
257 | - switch ($request_type) { |
|
258 | - case EE_System::req_type_new_activation: |
|
259 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
260 | - $this->_handle_core_version_change($espresso_db_update); |
|
261 | - break; |
|
262 | - case EE_System::req_type_reactivation: |
|
263 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
264 | - $this->_handle_core_version_change($espresso_db_update); |
|
265 | - break; |
|
266 | - case EE_System::req_type_upgrade: |
|
267 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
268 | - //migrations may be required now that we've upgraded |
|
269 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
270 | - $this->_handle_core_version_change($espresso_db_update); |
|
271 | - // echo "done upgrade";die; |
|
272 | - break; |
|
273 | - case EE_System::req_type_downgrade: |
|
274 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
275 | - //its possible migrations are no longer required |
|
276 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
277 | - $this->_handle_core_version_change($espresso_db_update); |
|
278 | - break; |
|
279 | - case EE_System::req_type_normal: |
|
280 | - default: |
|
281 | - // $this->_maybe_redirect_to_ee_about(); |
|
282 | - break; |
|
283 | - } |
|
284 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * Updates the list of installed versions and sets hooks for |
|
291 | - * initializing the database later during the request |
|
292 | - * |
|
293 | - * @param array $espresso_db_update |
|
294 | - */ |
|
295 | - protected function _handle_core_version_change($espresso_db_update) |
|
296 | - { |
|
297 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
298 | - //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
299 | - add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
300 | - array($this, 'initialize_db_if_no_migrations_required')); |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
307 | - * information about what versions of EE have been installed and activated, |
|
308 | - * NOT necessarily the state of the database |
|
309 | - * |
|
310 | - * @param null $espresso_db_update |
|
311 | - * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
312 | - * from the options table |
|
313 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
314 | - */ |
|
315 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
316 | - { |
|
317 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
318 | - if ( ! $espresso_db_update) { |
|
319 | - $espresso_db_update = get_option('espresso_db_update'); |
|
320 | - } |
|
321 | - // check that option is an array |
|
322 | - if ( ! is_array($espresso_db_update)) { |
|
323 | - // if option is FALSE, then it never existed |
|
324 | - if ($espresso_db_update === false) { |
|
325 | - // make $espresso_db_update an array and save option with autoload OFF |
|
326 | - $espresso_db_update = array(); |
|
327 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
328 | - } else { |
|
329 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
330 | - $espresso_db_update = array($espresso_db_update => array()); |
|
331 | - update_option('espresso_db_update', $espresso_db_update); |
|
332 | - } |
|
333 | - } else { |
|
334 | - $corrected_db_update = array(); |
|
335 | - //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
336 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
337 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
338 | - //the key is an int, and the value IS NOT an array |
|
339 | - //so it must be numerically-indexed, where values are versions installed... |
|
340 | - //fix it! |
|
341 | - $version_string = $should_be_array; |
|
342 | - $corrected_db_update[$version_string] = array('unknown-date'); |
|
343 | - } else { |
|
344 | - //ok it checks out |
|
345 | - $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
346 | - } |
|
347 | - } |
|
348 | - $espresso_db_update = $corrected_db_update; |
|
349 | - update_option('espresso_db_update', $espresso_db_update); |
|
350 | - } |
|
351 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
352 | - return $espresso_db_update; |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
359 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
360 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
361 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
362 | - * so that it will be done when migrations are finished |
|
363 | - * |
|
364 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
365 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
366 | - * This is a resource-intensive job |
|
367 | - * so we prefer to only do it when necessary |
|
368 | - * @return void |
|
369 | - */ |
|
370 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
371 | - { |
|
372 | - $request_type = $this->detect_req_type(); |
|
373 | - //only initialize system if we're not in maintenance mode. |
|
374 | - if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
375 | - update_option('ee_flush_rewrite_rules', true); |
|
376 | - if ($verify_schema) { |
|
377 | - EEH_Activation::initialize_db_and_folders(); |
|
378 | - } |
|
379 | - EEH_Activation::initialize_db_content(); |
|
380 | - EEH_Activation::system_initialization(); |
|
381 | - if ($initialize_addons_too) { |
|
382 | - $this->initialize_addons(); |
|
383 | - } |
|
384 | - } else { |
|
385 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
386 | - } |
|
387 | - if ($request_type === EE_System::req_type_new_activation |
|
388 | - || $request_type === EE_System::req_type_reactivation |
|
389 | - || ( |
|
390 | - $request_type === EE_System::req_type_upgrade |
|
391 | - && $this->is_major_version_change() |
|
392 | - ) |
|
393 | - ) { |
|
394 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
395 | - } |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * Initializes the db for all registered addons |
|
402 | - */ |
|
403 | - public function initialize_addons() |
|
404 | - { |
|
405 | - //foreach registered addon, make sure its db is up-to-date too |
|
406 | - foreach ($this->registry->addons as $addon) { |
|
407 | - $addon->initialize_db_if_no_migrations_required(); |
|
408 | - } |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
415 | - * |
|
416 | - * @param array $version_history |
|
417 | - * @param string $current_version_to_add version to be added to the version history |
|
418 | - * @return boolean success as to whether or not this option was changed |
|
419 | - */ |
|
420 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
421 | - { |
|
422 | - if ( ! $version_history) { |
|
423 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
424 | - } |
|
425 | - if ($current_version_to_add == null) { |
|
426 | - $current_version_to_add = espresso_version(); |
|
427 | - } |
|
428 | - $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
429 | - // re-save |
|
430 | - return update_option('espresso_db_update', $version_history); |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * Detects if the current version indicated in the has existed in the list of |
|
437 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
438 | - * |
|
439 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
440 | - * If not supplied, fetches it from the options table. |
|
441 | - * Also, caches its result so later parts of the code can also know whether |
|
442 | - * there's been an update or not. This way we can add the current version to |
|
443 | - * espresso_db_update, but still know if this is a new install or not |
|
444 | - * @return int one of the constants on EE_System::req_type_ |
|
445 | - */ |
|
446 | - public function detect_req_type($espresso_db_update = null) |
|
447 | - { |
|
448 | - if ($this->_req_type === null) { |
|
449 | - $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
450 | - : $this->fix_espresso_db_upgrade_option(); |
|
451 | - $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, |
|
452 | - 'ee_espresso_activation', espresso_version()); |
|
453 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
454 | - } |
|
455 | - return $this->_req_type; |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - |
|
460 | - /** |
|
461 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
462 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
463 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
464 | - * |
|
465 | - * @param $activation_history |
|
466 | - * @return bool |
|
467 | - */ |
|
468 | - protected function _detect_major_version_change($activation_history) |
|
469 | - { |
|
470 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
471 | - $previous_version_parts = explode('.', $previous_version); |
|
472 | - $current_version_parts = explode('.', espresso_version()); |
|
473 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
474 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
475 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
476 | - ); |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * Returns true if either the major or minor version of EE changed during this request. |
|
483 | - * 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 |
|
484 | - * |
|
485 | - * @return bool |
|
486 | - */ |
|
487 | - public function is_major_version_change() |
|
488 | - { |
|
489 | - return $this->_major_version_change; |
|
490 | - } |
|
491 | - |
|
492 | - |
|
493 | - |
|
494 | - /** |
|
495 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
496 | - * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily |
|
497 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
498 | - * just activated to (for core that will always be espresso_version()) |
|
499 | - * |
|
500 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
501 | - * ee plugin. for core that's 'espresso_db_update' |
|
502 | - * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to |
|
503 | - * indicate that this plugin was just activated |
|
504 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
505 | - * espresso_version()) |
|
506 | - * @return int one of the constants on EE_System::req_type_* |
|
507 | - */ |
|
508 | - public static function detect_req_type_given_activation_history( |
|
509 | - $activation_history_for_addon, |
|
510 | - $activation_indicator_option_name, |
|
511 | - $version_to_upgrade_to |
|
512 | - ) { |
|
513 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
514 | - if ($activation_history_for_addon) { |
|
515 | - //it exists, so this isn't a completely new install |
|
516 | - //check if this version already in that list of previously installed versions |
|
517 | - if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
518 | - //it a version we haven't seen before |
|
519 | - if ($version_is_higher === 1) { |
|
520 | - $req_type = EE_System::req_type_upgrade; |
|
521 | - } else { |
|
522 | - $req_type = EE_System::req_type_downgrade; |
|
523 | - } |
|
524 | - delete_option($activation_indicator_option_name); |
|
525 | - } else { |
|
526 | - // its not an update. maybe a reactivation? |
|
527 | - if (get_option($activation_indicator_option_name, false)) { |
|
528 | - if ($version_is_higher === -1) { |
|
529 | - $req_type = EE_System::req_type_downgrade; |
|
530 | - } elseif ($version_is_higher === 0) { |
|
531 | - //we've seen this version before, but it's an activation. must be a reactivation |
|
532 | - $req_type = EE_System::req_type_reactivation; |
|
533 | - } else {//$version_is_higher === 1 |
|
534 | - $req_type = EE_System::req_type_upgrade; |
|
535 | - } |
|
536 | - delete_option($activation_indicator_option_name); |
|
537 | - } else { |
|
538 | - //we've seen this version before and the activation indicate doesn't show it was just activated |
|
539 | - if ($version_is_higher === -1) { |
|
540 | - $req_type = EE_System::req_type_downgrade; |
|
541 | - } elseif ($version_is_higher === 0) { |
|
542 | - //we've seen this version before and it's not an activation. its normal request |
|
543 | - $req_type = EE_System::req_type_normal; |
|
544 | - } else {//$version_is_higher === 1 |
|
545 | - $req_type = EE_System::req_type_upgrade; |
|
546 | - } |
|
547 | - } |
|
548 | - } |
|
549 | - } else { |
|
550 | - //brand new install |
|
551 | - $req_type = EE_System::req_type_new_activation; |
|
552 | - delete_option($activation_indicator_option_name); |
|
553 | - } |
|
554 | - return $req_type; |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
561 | - * the $activation_history_for_addon |
|
562 | - * |
|
563 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
564 | - * sometimes containing 'unknown-date' |
|
565 | - * @param string $version_to_upgrade_to (current version) |
|
566 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
567 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
568 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
569 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
570 | - */ |
|
571 | - protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
572 | - { |
|
573 | - //find the most recently-activated version |
|
574 | - $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
575 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
576 | - } |
|
577 | - |
|
578 | - |
|
579 | - |
|
580 | - /** |
|
581 | - * Gets the most recently active version listed in the activation history, |
|
582 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
583 | - * |
|
584 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
585 | - * sometimes containing 'unknown-date' |
|
586 | - * @return string |
|
587 | - */ |
|
588 | - protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
589 | - { |
|
590 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
591 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
592 | - if (is_array($activation_history)) { |
|
593 | - foreach ($activation_history as $version => $times_activated) { |
|
594 | - //check there is a record of when this version was activated. Otherwise, |
|
595 | - //mark it as unknown |
|
596 | - if ( ! $times_activated) { |
|
597 | - $times_activated = array('unknown-date'); |
|
598 | - } |
|
599 | - if (is_string($times_activated)) { |
|
600 | - $times_activated = array($times_activated); |
|
601 | - } |
|
602 | - foreach ($times_activated as $an_activation) { |
|
603 | - if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
604 | - $most_recently_active_version = $version; |
|
605 | - $most_recently_active_version_activation = $an_activation == 'unknown-date' |
|
606 | - ? '1970-01-01 00:00:00' : $an_activation; |
|
607 | - } |
|
608 | - } |
|
609 | - } |
|
610 | - } |
|
611 | - return $most_recently_active_version; |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * This redirects to the about EE page after activation |
|
618 | - * |
|
619 | - * @return void |
|
620 | - */ |
|
621 | - public function redirect_to_about_ee() |
|
622 | - { |
|
623 | - $notices = EE_Error::get_notices(false); |
|
624 | - //if current user is an admin and it's not an ajax or rest request |
|
625 | - if ( |
|
626 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
627 | - && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
628 | - && ! isset($notices['errors']) |
|
629 | - && apply_filters( |
|
630 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
631 | - $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
632 | - ) |
|
633 | - ) { |
|
634 | - $query_params = array('page' => 'espresso_about'); |
|
635 | - if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
636 | - $query_params['new_activation'] = true; |
|
637 | - } |
|
638 | - if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
639 | - $query_params['reactivation'] = true; |
|
640 | - } |
|
641 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
642 | - wp_safe_redirect($url); |
|
643 | - exit(); |
|
644 | - } |
|
645 | - } |
|
646 | - |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * load_core_configuration |
|
651 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
652 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
653 | - * |
|
654 | - * @return void |
|
655 | - */ |
|
656 | - public function load_core_configuration() |
|
657 | - { |
|
658 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
659 | - $this->registry->load_core('EE_Load_Textdomain'); |
|
660 | - //load textdomain |
|
661 | - EE_Load_Textdomain::load_textdomain(); |
|
662 | - // load and setup EE_Config and EE_Network_Config |
|
663 | - $this->registry->load_core('Config'); |
|
664 | - $this->registry->load_core('Network_Config'); |
|
665 | - // setup autoloaders |
|
666 | - // enable logging? |
|
667 | - if ($this->registry->CFG->admin->use_full_logging) { |
|
668 | - $this->registry->load_core('Log'); |
|
669 | - } |
|
670 | - // check for activation errors |
|
671 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
672 | - if ($activation_errors) { |
|
673 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
674 | - update_option('ee_plugin_activation_errors', false); |
|
675 | - } |
|
676 | - // get model names |
|
677 | - $this->_parse_model_names(); |
|
678 | - //load caf stuff a chance to play during the activation process too. |
|
679 | - $this->_maybe_brew_regular(); |
|
680 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
681 | - } |
|
682 | - |
|
683 | - |
|
684 | - |
|
685 | - /** |
|
686 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
687 | - * |
|
688 | - * @return void |
|
689 | - */ |
|
690 | - private function _parse_model_names() |
|
691 | - { |
|
692 | - //get all the files in the EE_MODELS folder that end in .model.php |
|
693 | - $models = glob(EE_MODELS . '*.model.php'); |
|
694 | - $model_names = array(); |
|
695 | - $non_abstract_db_models = array(); |
|
696 | - foreach ($models as $model) { |
|
697 | - // get model classname |
|
698 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
699 | - $short_name = str_replace('EEM_', '', $classname); |
|
700 | - $reflectionClass = new ReflectionClass($classname); |
|
701 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
702 | - $non_abstract_db_models[$short_name] = $classname; |
|
703 | - } |
|
704 | - $model_names[$short_name] = $classname; |
|
705 | - } |
|
706 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
707 | - $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
708 | - $non_abstract_db_models); |
|
709 | - } |
|
710 | - |
|
711 | - |
|
712 | - |
|
713 | - /** |
|
714 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
715 | - * that need to be setup before our EE_System launches. |
|
716 | - * |
|
717 | - * @return void |
|
718 | - */ |
|
719 | - private function _maybe_brew_regular() |
|
720 | - { |
|
721 | - if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
722 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
723 | - } |
|
724 | - } |
|
725 | - |
|
726 | - |
|
727 | - |
|
728 | - /** |
|
729 | - * register_shortcodes_modules_and_widgets |
|
730 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
731 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
732 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
733 | - * |
|
734 | - * @access public |
|
735 | - * @return void |
|
736 | - */ |
|
737 | - public function register_shortcodes_modules_and_widgets() |
|
738 | - { |
|
739 | - try { |
|
740 | - // load, register, and add shortcodes the new way |
|
741 | - new ShortcodesManager( |
|
742 | - // and the old way, but we'll put it under control of the new system |
|
743 | - EE_Config::getLegacyShortcodesManager() |
|
744 | - ); |
|
745 | - } catch (Exception $exception) { |
|
746 | - new ExceptionStackTraceDisplay($exception); |
|
747 | - } |
|
748 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
749 | - // check for addons using old hookpoint |
|
750 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
751 | - $this->_incompatible_addon_error(); |
|
752 | - } |
|
753 | - } |
|
754 | - |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * _incompatible_addon_error |
|
759 | - * |
|
760 | - * @access public |
|
761 | - * @return void |
|
762 | - */ |
|
763 | - private function _incompatible_addon_error() |
|
764 | - { |
|
765 | - // get array of classes hooking into here |
|
766 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
767 | - if ( ! empty($class_names)) { |
|
768 | - $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
769 | - 'event_espresso'); |
|
770 | - $msg .= '<ul>'; |
|
771 | - foreach ($class_names as $class_name) { |
|
772 | - $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
773 | - $class_name) . '</b></li>'; |
|
774 | - } |
|
775 | - $msg .= '</ul>'; |
|
776 | - $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
777 | - 'event_espresso'); |
|
778 | - // save list of incompatible addons to wp-options for later use |
|
779 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
780 | - if (is_admin()) { |
|
781 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
782 | - } |
|
783 | - } |
|
784 | - } |
|
785 | - |
|
786 | - |
|
787 | - |
|
788 | - /** |
|
789 | - * brew_espresso |
|
790 | - * begins the process of setting hooks for initializing EE in the correct order |
|
791 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
|
792 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
793 | - * |
|
794 | - * @return void |
|
795 | - */ |
|
796 | - public function brew_espresso() |
|
797 | - { |
|
798 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
799 | - // load some final core systems |
|
800 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
801 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
802 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
803 | - add_action('init', array($this, 'load_controllers'), 7); |
|
804 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
805 | - add_action('init', array($this, 'initialize'), 10); |
|
806 | - add_action('init', array($this, 'initialize_last'), 100); |
|
807 | - add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
808 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
809 | - // pew pew pew |
|
810 | - $this->registry->load_core('PUE'); |
|
811 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
812 | - } |
|
813 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
814 | - } |
|
815 | - |
|
816 | - |
|
817 | - |
|
818 | - /** |
|
819 | - * set_hooks_for_core |
|
820 | - * |
|
821 | - * @access public |
|
822 | - * @return void |
|
823 | - */ |
|
824 | - public function set_hooks_for_core() |
|
825 | - { |
|
826 | - $this->_deactivate_incompatible_addons(); |
|
827 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
828 | - } |
|
829 | - |
|
830 | - |
|
831 | - |
|
832 | - /** |
|
833 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
834 | - * deactivates any addons considered incompatible with the current version of EE |
|
835 | - */ |
|
836 | - private function _deactivate_incompatible_addons() |
|
837 | - { |
|
838 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
839 | - if ( ! empty($incompatible_addons)) { |
|
840 | - $active_plugins = get_option('active_plugins', array()); |
|
841 | - foreach ($active_plugins as $active_plugin) { |
|
842 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
843 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
844 | - unset($_GET['activate']); |
|
845 | - espresso_deactivate_plugin($active_plugin); |
|
846 | - } |
|
847 | - } |
|
848 | - } |
|
849 | - } |
|
850 | - } |
|
851 | - |
|
852 | - |
|
853 | - |
|
854 | - /** |
|
855 | - * perform_activations_upgrades_and_migrations |
|
856 | - * |
|
857 | - * @access public |
|
858 | - * @return void |
|
859 | - */ |
|
860 | - public function perform_activations_upgrades_and_migrations() |
|
861 | - { |
|
862 | - //first check if we had previously attempted to setup EE's directories but failed |
|
863 | - if (EEH_Activation::upload_directories_incomplete()) { |
|
864 | - EEH_Activation::create_upload_directories(); |
|
865 | - } |
|
866 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
867 | - } |
|
868 | - |
|
869 | - |
|
870 | - |
|
871 | - /** |
|
872 | - * load_CPTs_and_session |
|
873 | - * |
|
874 | - * @access public |
|
875 | - * @return void |
|
876 | - */ |
|
877 | - public function load_CPTs_and_session() |
|
878 | - { |
|
879 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
880 | - // register Custom Post Types |
|
881 | - $this->registry->load_core('Register_CPTs'); |
|
882 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
883 | - } |
|
884 | - |
|
885 | - |
|
886 | - |
|
887 | - /** |
|
888 | - * load_controllers |
|
889 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
890 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
891 | - * time |
|
892 | - * |
|
893 | - * @access public |
|
894 | - * @return void |
|
895 | - */ |
|
896 | - public function load_controllers() |
|
897 | - { |
|
898 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
899 | - // let's get it started |
|
900 | - if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
901 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
902 | - $this->registry->load_core('Front_Controller'); |
|
903 | - } else if ( ! EE_FRONT_AJAX) { |
|
904 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
905 | - EE_Registry::instance()->load_core('Admin'); |
|
906 | - } |
|
907 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
908 | - } |
|
909 | - |
|
910 | - |
|
911 | - |
|
912 | - /** |
|
913 | - * core_loaded_and_ready |
|
914 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
915 | - * |
|
916 | - * @access public |
|
917 | - * @return void |
|
918 | - */ |
|
919 | - public function core_loaded_and_ready() |
|
920 | - { |
|
921 | - $this->registry->load_core('Session'); |
|
922 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
923 | - // load_espresso_template_tags |
|
924 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
925 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
926 | - } |
|
927 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
928 | - $this->registry->create('EventEspresso\core\services\assets\Registry'); |
|
929 | - } |
|
930 | - |
|
931 | - |
|
932 | - |
|
933 | - /** |
|
934 | - * initialize |
|
935 | - * this is the best place to begin initializing client code |
|
936 | - * |
|
937 | - * @access public |
|
938 | - * @return void |
|
939 | - */ |
|
940 | - public function initialize() |
|
941 | - { |
|
942 | - do_action('AHEE__EE_System__initialize'); |
|
943 | - } |
|
944 | - |
|
945 | - |
|
946 | - |
|
947 | - /** |
|
948 | - * initialize_last |
|
949 | - * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
950 | - * initialize has done so |
|
951 | - * |
|
952 | - * @access public |
|
953 | - * @return void |
|
954 | - */ |
|
955 | - public function initialize_last() |
|
956 | - { |
|
957 | - do_action('AHEE__EE_System__initialize_last'); |
|
958 | - } |
|
959 | - |
|
960 | - |
|
961 | - |
|
962 | - /** |
|
963 | - * set_hooks_for_shortcodes_modules_and_addons |
|
964 | - * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
965 | - * this happens at the very beginning of the wp_loaded hookpoint |
|
966 | - * |
|
967 | - * @access public |
|
968 | - * @return void |
|
969 | - */ |
|
970 | - public function set_hooks_for_shortcodes_modules_and_addons() |
|
971 | - { |
|
972 | - // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
973 | - } |
|
974 | - |
|
975 | - |
|
976 | - |
|
977 | - /** |
|
978 | - * do_not_cache |
|
979 | - * sets no cache headers and defines no cache constants for WP plugins |
|
980 | - * |
|
981 | - * @access public |
|
982 | - * @return void |
|
983 | - */ |
|
984 | - public static function do_not_cache() |
|
985 | - { |
|
986 | - // set no cache constants |
|
987 | - if ( ! defined('DONOTCACHEPAGE')) { |
|
988 | - define('DONOTCACHEPAGE', true); |
|
989 | - } |
|
990 | - if ( ! defined('DONOTCACHCEOBJECT')) { |
|
991 | - define('DONOTCACHCEOBJECT', true); |
|
992 | - } |
|
993 | - if ( ! defined('DONOTCACHEDB')) { |
|
994 | - define('DONOTCACHEDB', true); |
|
995 | - } |
|
996 | - // add no cache headers |
|
997 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
998 | - // plus a little extra for nginx and Google Chrome |
|
999 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1000 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1001 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1002 | - } |
|
1003 | - |
|
1004 | - |
|
1005 | - |
|
1006 | - /** |
|
1007 | - * extra_nocache_headers |
|
1008 | - * |
|
1009 | - * @access public |
|
1010 | - * @param $headers |
|
1011 | - * @return array |
|
1012 | - */ |
|
1013 | - public static function extra_nocache_headers($headers) |
|
1014 | - { |
|
1015 | - // for NGINX |
|
1016 | - $headers['X-Accel-Expires'] = 0; |
|
1017 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1018 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1019 | - return $headers; |
|
1020 | - } |
|
1021 | - |
|
1022 | - |
|
1023 | - |
|
1024 | - /** |
|
1025 | - * nocache_headers |
|
1026 | - * |
|
1027 | - * @access public |
|
1028 | - * @return void |
|
1029 | - */ |
|
1030 | - public static function nocache_headers() |
|
1031 | - { |
|
1032 | - nocache_headers(); |
|
1033 | - } |
|
1034 | - |
|
1035 | - |
|
1036 | - |
|
1037 | - /** |
|
1038 | - * espresso_toolbar_items |
|
1039 | - * |
|
1040 | - * @access public |
|
1041 | - * @param WP_Admin_Bar $admin_bar |
|
1042 | - * @return void |
|
1043 | - */ |
|
1044 | - public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
1045 | - { |
|
1046 | - // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
1047 | - if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
1048 | - || defined('DOING_AJAX') |
|
1049 | - || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
1050 | - ) { |
|
1051 | - return; |
|
1052 | - } |
|
1053 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1054 | - $menu_class = 'espresso_menu_item_class'; |
|
1055 | - //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
1056 | - //because they're only defined in each of their respective constructors |
|
1057 | - //and this might be a frontend request, in which case they aren't available |
|
1058 | - $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
1059 | - $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
1060 | - $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
1061 | - //Top Level |
|
1062 | - $admin_bar->add_menu(array( |
|
1063 | - 'id' => 'espresso-toolbar', |
|
1064 | - 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
1065 | - . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
1066 | - . '</span>', |
|
1067 | - 'href' => $events_admin_url, |
|
1068 | - 'meta' => array( |
|
1069 | - 'title' => __('Event Espresso', 'event_espresso'), |
|
1070 | - 'class' => $menu_class . 'first', |
|
1071 | - ), |
|
1072 | - )); |
|
1073 | - //Events |
|
1074 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
1075 | - $admin_bar->add_menu(array( |
|
1076 | - 'id' => 'espresso-toolbar-events', |
|
1077 | - 'parent' => 'espresso-toolbar', |
|
1078 | - 'title' => __('Events', 'event_espresso'), |
|
1079 | - 'href' => $events_admin_url, |
|
1080 | - 'meta' => array( |
|
1081 | - 'title' => __('Events', 'event_espresso'), |
|
1082 | - 'target' => '', |
|
1083 | - 'class' => $menu_class, |
|
1084 | - ), |
|
1085 | - )); |
|
1086 | - } |
|
1087 | - if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
1088 | - //Events Add New |
|
1089 | - $admin_bar->add_menu(array( |
|
1090 | - 'id' => 'espresso-toolbar-events-new', |
|
1091 | - 'parent' => 'espresso-toolbar-events', |
|
1092 | - 'title' => __('Add New', 'event_espresso'), |
|
1093 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
1094 | - 'meta' => array( |
|
1095 | - 'title' => __('Add New', 'event_espresso'), |
|
1096 | - 'target' => '', |
|
1097 | - 'class' => $menu_class, |
|
1098 | - ), |
|
1099 | - )); |
|
1100 | - } |
|
1101 | - if (is_single() && (get_post_type() == 'espresso_events')) { |
|
1102 | - //Current post |
|
1103 | - global $post; |
|
1104 | - if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
1105 | - 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
1106 | - ) { |
|
1107 | - //Events Edit Current Event |
|
1108 | - $admin_bar->add_menu(array( |
|
1109 | - 'id' => 'espresso-toolbar-events-edit', |
|
1110 | - 'parent' => 'espresso-toolbar-events', |
|
1111 | - 'title' => __('Edit Event', 'event_espresso'), |
|
1112 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
1113 | - $events_admin_url), |
|
1114 | - 'meta' => array( |
|
1115 | - 'title' => __('Edit Event', 'event_espresso'), |
|
1116 | - 'target' => '', |
|
1117 | - 'class' => $menu_class, |
|
1118 | - ), |
|
1119 | - )); |
|
1120 | - } |
|
1121 | - } |
|
1122 | - //Events View |
|
1123 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1124 | - 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
1125 | - ) { |
|
1126 | - $admin_bar->add_menu(array( |
|
1127 | - 'id' => 'espresso-toolbar-events-view', |
|
1128 | - 'parent' => 'espresso-toolbar-events', |
|
1129 | - 'title' => __('View', 'event_espresso'), |
|
1130 | - 'href' => $events_admin_url, |
|
1131 | - 'meta' => array( |
|
1132 | - 'title' => __('View', 'event_espresso'), |
|
1133 | - 'target' => '', |
|
1134 | - 'class' => $menu_class, |
|
1135 | - ), |
|
1136 | - )); |
|
1137 | - } |
|
1138 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
1139 | - //Events View All |
|
1140 | - $admin_bar->add_menu(array( |
|
1141 | - 'id' => 'espresso-toolbar-events-all', |
|
1142 | - 'parent' => 'espresso-toolbar-events-view', |
|
1143 | - 'title' => __('All', 'event_espresso'), |
|
1144 | - 'href' => $events_admin_url, |
|
1145 | - 'meta' => array( |
|
1146 | - 'title' => __('All', 'event_espresso'), |
|
1147 | - 'target' => '', |
|
1148 | - 'class' => $menu_class, |
|
1149 | - ), |
|
1150 | - )); |
|
1151 | - } |
|
1152 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1153 | - 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
1154 | - ) { |
|
1155 | - //Events View Today |
|
1156 | - $admin_bar->add_menu(array( |
|
1157 | - 'id' => 'espresso-toolbar-events-today', |
|
1158 | - 'parent' => 'espresso-toolbar-events-view', |
|
1159 | - 'title' => __('Today', 'event_espresso'), |
|
1160 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1161 | - $events_admin_url), |
|
1162 | - 'meta' => array( |
|
1163 | - 'title' => __('Today', 'event_espresso'), |
|
1164 | - 'target' => '', |
|
1165 | - 'class' => $menu_class, |
|
1166 | - ), |
|
1167 | - )); |
|
1168 | - } |
|
1169 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1170 | - 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
1171 | - ) { |
|
1172 | - //Events View This Month |
|
1173 | - $admin_bar->add_menu(array( |
|
1174 | - 'id' => 'espresso-toolbar-events-month', |
|
1175 | - 'parent' => 'espresso-toolbar-events-view', |
|
1176 | - 'title' => __('This Month', 'event_espresso'), |
|
1177 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1178 | - $events_admin_url), |
|
1179 | - 'meta' => array( |
|
1180 | - 'title' => __('This Month', 'event_espresso'), |
|
1181 | - 'target' => '', |
|
1182 | - 'class' => $menu_class, |
|
1183 | - ), |
|
1184 | - )); |
|
1185 | - } |
|
1186 | - //Registration Overview |
|
1187 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1188 | - 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
1189 | - ) { |
|
1190 | - $admin_bar->add_menu(array( |
|
1191 | - 'id' => 'espresso-toolbar-registrations', |
|
1192 | - 'parent' => 'espresso-toolbar', |
|
1193 | - 'title' => __('Registrations', 'event_espresso'), |
|
1194 | - 'href' => $reg_admin_url, |
|
1195 | - 'meta' => array( |
|
1196 | - 'title' => __('Registrations', 'event_espresso'), |
|
1197 | - 'target' => '', |
|
1198 | - 'class' => $menu_class, |
|
1199 | - ), |
|
1200 | - )); |
|
1201 | - } |
|
1202 | - //Registration Overview Today |
|
1203 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1204 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
1205 | - ) { |
|
1206 | - $admin_bar->add_menu(array( |
|
1207 | - 'id' => 'espresso-toolbar-registrations-today', |
|
1208 | - 'parent' => 'espresso-toolbar-registrations', |
|
1209 | - 'title' => __('Today', 'event_espresso'), |
|
1210 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1211 | - $reg_admin_url), |
|
1212 | - 'meta' => array( |
|
1213 | - 'title' => __('Today', 'event_espresso'), |
|
1214 | - 'target' => '', |
|
1215 | - 'class' => $menu_class, |
|
1216 | - ), |
|
1217 | - )); |
|
1218 | - } |
|
1219 | - //Registration Overview Today Completed |
|
1220 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1221 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
1222 | - ) { |
|
1223 | - $admin_bar->add_menu(array( |
|
1224 | - 'id' => 'espresso-toolbar-registrations-today-approved', |
|
1225 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1226 | - 'title' => __('Approved', 'event_espresso'), |
|
1227 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1228 | - 'action' => 'default', |
|
1229 | - 'status' => 'today', |
|
1230 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1231 | - ), $reg_admin_url), |
|
1232 | - 'meta' => array( |
|
1233 | - 'title' => __('Approved', 'event_espresso'), |
|
1234 | - 'target' => '', |
|
1235 | - 'class' => $menu_class, |
|
1236 | - ), |
|
1237 | - )); |
|
1238 | - } |
|
1239 | - //Registration Overview Today Pending\ |
|
1240 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1241 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
1242 | - ) { |
|
1243 | - $admin_bar->add_menu(array( |
|
1244 | - 'id' => 'espresso-toolbar-registrations-today-pending', |
|
1245 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1246 | - 'title' => __('Pending', 'event_espresso'), |
|
1247 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1248 | - 'action' => 'default', |
|
1249 | - 'status' => 'today', |
|
1250 | - 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
1251 | - ), $reg_admin_url), |
|
1252 | - 'meta' => array( |
|
1253 | - 'title' => __('Pending Payment', 'event_espresso'), |
|
1254 | - 'target' => '', |
|
1255 | - 'class' => $menu_class, |
|
1256 | - ), |
|
1257 | - )); |
|
1258 | - } |
|
1259 | - //Registration Overview Today Incomplete |
|
1260 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1261 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
1262 | - ) { |
|
1263 | - $admin_bar->add_menu(array( |
|
1264 | - 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
1265 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1266 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1267 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1268 | - 'action' => 'default', |
|
1269 | - 'status' => 'today', |
|
1270 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1271 | - ), $reg_admin_url), |
|
1272 | - 'meta' => array( |
|
1273 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1274 | - 'target' => '', |
|
1275 | - 'class' => $menu_class, |
|
1276 | - ), |
|
1277 | - )); |
|
1278 | - } |
|
1279 | - //Registration Overview Today Incomplete |
|
1280 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1281 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
1282 | - ) { |
|
1283 | - $admin_bar->add_menu(array( |
|
1284 | - 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
1285 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1286 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1287 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1288 | - 'action' => 'default', |
|
1289 | - 'status' => 'today', |
|
1290 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1291 | - ), $reg_admin_url), |
|
1292 | - 'meta' => array( |
|
1293 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1294 | - 'target' => '', |
|
1295 | - 'class' => $menu_class, |
|
1296 | - ), |
|
1297 | - )); |
|
1298 | - } |
|
1299 | - //Registration Overview This Month |
|
1300 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1301 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
1302 | - ) { |
|
1303 | - $admin_bar->add_menu(array( |
|
1304 | - 'id' => 'espresso-toolbar-registrations-month', |
|
1305 | - 'parent' => 'espresso-toolbar-registrations', |
|
1306 | - 'title' => __('This Month', 'event_espresso'), |
|
1307 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1308 | - $reg_admin_url), |
|
1309 | - 'meta' => array( |
|
1310 | - 'title' => __('This Month', 'event_espresso'), |
|
1311 | - 'target' => '', |
|
1312 | - 'class' => $menu_class, |
|
1313 | - ), |
|
1314 | - )); |
|
1315 | - } |
|
1316 | - //Registration Overview This Month Approved |
|
1317 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1318 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
1319 | - ) { |
|
1320 | - $admin_bar->add_menu(array( |
|
1321 | - 'id' => 'espresso-toolbar-registrations-month-approved', |
|
1322 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1323 | - 'title' => __('Approved', 'event_espresso'), |
|
1324 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1325 | - 'action' => 'default', |
|
1326 | - 'status' => 'month', |
|
1327 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1328 | - ), $reg_admin_url), |
|
1329 | - 'meta' => array( |
|
1330 | - 'title' => __('Approved', 'event_espresso'), |
|
1331 | - 'target' => '', |
|
1332 | - 'class' => $menu_class, |
|
1333 | - ), |
|
1334 | - )); |
|
1335 | - } |
|
1336 | - //Registration Overview This Month Pending |
|
1337 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1338 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
1339 | - ) { |
|
1340 | - $admin_bar->add_menu(array( |
|
1341 | - 'id' => 'espresso-toolbar-registrations-month-pending', |
|
1342 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1343 | - 'title' => __('Pending', 'event_espresso'), |
|
1344 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1345 | - 'action' => 'default', |
|
1346 | - 'status' => 'month', |
|
1347 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1348 | - ), $reg_admin_url), |
|
1349 | - 'meta' => array( |
|
1350 | - 'title' => __('Pending', 'event_espresso'), |
|
1351 | - 'target' => '', |
|
1352 | - 'class' => $menu_class, |
|
1353 | - ), |
|
1354 | - )); |
|
1355 | - } |
|
1356 | - //Registration Overview This Month Not Approved |
|
1357 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1358 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
1359 | - ) { |
|
1360 | - $admin_bar->add_menu(array( |
|
1361 | - 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
1362 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1363 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1364 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1365 | - 'action' => 'default', |
|
1366 | - 'status' => 'month', |
|
1367 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1368 | - ), $reg_admin_url), |
|
1369 | - 'meta' => array( |
|
1370 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1371 | - 'target' => '', |
|
1372 | - 'class' => $menu_class, |
|
1373 | - ), |
|
1374 | - )); |
|
1375 | - } |
|
1376 | - //Registration Overview This Month Cancelled |
|
1377 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1378 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
1379 | - ) { |
|
1380 | - $admin_bar->add_menu(array( |
|
1381 | - 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
1382 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1383 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1384 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1385 | - 'action' => 'default', |
|
1386 | - 'status' => 'month', |
|
1387 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1388 | - ), $reg_admin_url), |
|
1389 | - 'meta' => array( |
|
1390 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1391 | - 'target' => '', |
|
1392 | - 'class' => $menu_class, |
|
1393 | - ), |
|
1394 | - )); |
|
1395 | - } |
|
1396 | - //Extensions & Services |
|
1397 | - if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
1398 | - 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
1399 | - ) { |
|
1400 | - $admin_bar->add_menu(array( |
|
1401 | - 'id' => 'espresso-toolbar-extensions-and-services', |
|
1402 | - 'parent' => 'espresso-toolbar', |
|
1403 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
1404 | - 'href' => $extensions_admin_url, |
|
1405 | - 'meta' => array( |
|
1406 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
1407 | - 'target' => '', |
|
1408 | - 'class' => $menu_class, |
|
1409 | - ), |
|
1410 | - )); |
|
1411 | - } |
|
1412 | - } |
|
1413 | - |
|
1414 | - |
|
1415 | - |
|
1416 | - /** |
|
1417 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1418 | - * never returned with the function. |
|
1419 | - * |
|
1420 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
1421 | - * @return array |
|
1422 | - */ |
|
1423 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
1424 | - { |
|
1425 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1426 | - } |
|
22 | + /** |
|
23 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
24 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
25 | + */ |
|
26 | + const req_type_normal = 0; |
|
27 | + |
|
28 | + /** |
|
29 | + * Indicates this is a brand new installation of EE so we should install |
|
30 | + * tables and default data etc |
|
31 | + */ |
|
32 | + const req_type_new_activation = 1; |
|
33 | + |
|
34 | + /** |
|
35 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
36 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
37 | + * and that default data is setup too |
|
38 | + */ |
|
39 | + const req_type_reactivation = 2; |
|
40 | + |
|
41 | + /** |
|
42 | + * indicates that EE has been upgraded since its previous request. |
|
43 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
44 | + */ |
|
45 | + const req_type_upgrade = 3; |
|
46 | + |
|
47 | + /** |
|
48 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
49 | + */ |
|
50 | + const req_type_downgrade = 4; |
|
51 | + |
|
52 | + /** |
|
53 | + * @deprecated since version 4.6.0.dev.006 |
|
54 | + * Now whenever a new_activation is detected the request type is still just |
|
55 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
56 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
57 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
58 | + * (Specifically, when the migration manager indicates migrations are finished |
|
59 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
60 | + */ |
|
61 | + const req_type_activation_but_not_installed = 5; |
|
62 | + |
|
63 | + /** |
|
64 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
65 | + */ |
|
66 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * instance of the EE_System object |
|
71 | + * |
|
72 | + * @var $_instance |
|
73 | + * @access private |
|
74 | + */ |
|
75 | + private static $_instance = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * @type EE_Registry $Registry |
|
79 | + * @access protected |
|
80 | + */ |
|
81 | + protected $registry; |
|
82 | + |
|
83 | + /** |
|
84 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
85 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
86 | + * |
|
87 | + * @var int |
|
88 | + */ |
|
89 | + private $_req_type; |
|
90 | + |
|
91 | + /** |
|
92 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
93 | + * |
|
94 | + * @var boolean |
|
95 | + */ |
|
96 | + private $_major_version_change = false; |
|
97 | + |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @singleton method used to instantiate class object |
|
102 | + * @access public |
|
103 | + * @param \EE_Registry $Registry |
|
104 | + * @return \EE_System |
|
105 | + */ |
|
106 | + public static function instance(EE_Registry $Registry = null) |
|
107 | + { |
|
108 | + // check if class object is instantiated |
|
109 | + if ( ! self::$_instance instanceof EE_System) { |
|
110 | + self::$_instance = new self($Registry); |
|
111 | + } |
|
112 | + return self::$_instance; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * resets the instance and returns it |
|
119 | + * |
|
120 | + * @return EE_System |
|
121 | + */ |
|
122 | + public static function reset() |
|
123 | + { |
|
124 | + self::$_instance->_req_type = null; |
|
125 | + //make sure none of the old hooks are left hanging around |
|
126 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
127 | + //we need to reset the migration manager in order for it to detect DMSs properly |
|
128 | + EE_Data_Migration_Manager::reset(); |
|
129 | + self::instance()->detect_activations_or_upgrades(); |
|
130 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
131 | + return self::instance(); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * sets hooks for running rest of system |
|
138 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
139 | + * starting EE Addons from any other point may lead to problems |
|
140 | + * |
|
141 | + * @access private |
|
142 | + * @param \EE_Registry $Registry |
|
143 | + */ |
|
144 | + private function __construct(EE_Registry $Registry) |
|
145 | + { |
|
146 | + $this->registry = $Registry; |
|
147 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
148 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
149 | + add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
150 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
151 | + // because the newly-activated addon didn't get a chance to run at all |
|
152 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
153 | + // detect whether install or upgrade |
|
154 | + add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
155 | + 3); |
|
156 | + // load EE_Config, EE_Textdomain, etc |
|
157 | + add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
158 | + // load EE_Config, EE_Textdomain, etc |
|
159 | + add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
160 | + array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
161 | + // you wanna get going? I wanna get going... let's get going! |
|
162 | + add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
163 | + //other housekeeping |
|
164 | + //exclude EE critical pages from wp_list_pages |
|
165 | + add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
166 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
167 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
168 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * load_espresso_addons |
|
175 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
176 | + * this is hooked into both: |
|
177 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
178 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
179 | + * and the WP 'activate_plugin' hookpoint |
|
180 | + * |
|
181 | + * @access public |
|
182 | + * @return void |
|
183 | + */ |
|
184 | + public function load_espresso_addons() |
|
185 | + { |
|
186 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
187 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
188 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
189 | + //load and setup EE_Capabilities |
|
190 | + $this->registry->load_core('Capabilities'); |
|
191 | + //caps need to be initialized on every request so that capability maps are set. |
|
192 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
193 | + $this->registry->CAP->init_caps(); |
|
194 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
195 | + //if the WP API basic auth plugin isn't already loaded, load it now. |
|
196 | + //We want it for mobile apps. Just include the entire plugin |
|
197 | + //also, don't load the basic auth when a plugin is getting activated, because |
|
198 | + //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
199 | + //and causes a fatal error |
|
200 | + if ( ! function_exists('json_basic_auth_handler') |
|
201 | + && ! function_exists('json_basic_auth_error') |
|
202 | + && ! ( |
|
203 | + isset($_GET['action']) |
|
204 | + && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
205 | + ) |
|
206 | + && ! ( |
|
207 | + isset($_GET['activate']) |
|
208 | + && $_GET['activate'] === 'true' |
|
209 | + ) |
|
210 | + ) { |
|
211 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
212 | + } |
|
213 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * detect_activations_or_upgrades |
|
220 | + * Checks for activation or upgrade of core first; |
|
221 | + * then also checks if any registered addons have been activated or upgraded |
|
222 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
223 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
224 | + * |
|
225 | + * @access public |
|
226 | + * @return void |
|
227 | + */ |
|
228 | + public function detect_activations_or_upgrades() |
|
229 | + { |
|
230 | + //first off: let's make sure to handle core |
|
231 | + $this->detect_if_activation_or_upgrade(); |
|
232 | + foreach ($this->registry->addons as $addon) { |
|
233 | + //detect teh request type for that addon |
|
234 | + $addon->detect_activation_or_upgrade(); |
|
235 | + } |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * detect_if_activation_or_upgrade |
|
242 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
243 | + * and either setting up the DB or setting up maintenance mode etc. |
|
244 | + * |
|
245 | + * @access public |
|
246 | + * @return void |
|
247 | + */ |
|
248 | + public function detect_if_activation_or_upgrade() |
|
249 | + { |
|
250 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
251 | + // load M-Mode class |
|
252 | + $this->registry->load_core('Maintenance_Mode'); |
|
253 | + // check if db has been updated, or if its a brand-new installation |
|
254 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
255 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
256 | + //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
257 | + switch ($request_type) { |
|
258 | + case EE_System::req_type_new_activation: |
|
259 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
260 | + $this->_handle_core_version_change($espresso_db_update); |
|
261 | + break; |
|
262 | + case EE_System::req_type_reactivation: |
|
263 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
264 | + $this->_handle_core_version_change($espresso_db_update); |
|
265 | + break; |
|
266 | + case EE_System::req_type_upgrade: |
|
267 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
268 | + //migrations may be required now that we've upgraded |
|
269 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
270 | + $this->_handle_core_version_change($espresso_db_update); |
|
271 | + // echo "done upgrade";die; |
|
272 | + break; |
|
273 | + case EE_System::req_type_downgrade: |
|
274 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
275 | + //its possible migrations are no longer required |
|
276 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
277 | + $this->_handle_core_version_change($espresso_db_update); |
|
278 | + break; |
|
279 | + case EE_System::req_type_normal: |
|
280 | + default: |
|
281 | + // $this->_maybe_redirect_to_ee_about(); |
|
282 | + break; |
|
283 | + } |
|
284 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * Updates the list of installed versions and sets hooks for |
|
291 | + * initializing the database later during the request |
|
292 | + * |
|
293 | + * @param array $espresso_db_update |
|
294 | + */ |
|
295 | + protected function _handle_core_version_change($espresso_db_update) |
|
296 | + { |
|
297 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
298 | + //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
299 | + add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
300 | + array($this, 'initialize_db_if_no_migrations_required')); |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
307 | + * information about what versions of EE have been installed and activated, |
|
308 | + * NOT necessarily the state of the database |
|
309 | + * |
|
310 | + * @param null $espresso_db_update |
|
311 | + * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
312 | + * from the options table |
|
313 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
314 | + */ |
|
315 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
316 | + { |
|
317 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
318 | + if ( ! $espresso_db_update) { |
|
319 | + $espresso_db_update = get_option('espresso_db_update'); |
|
320 | + } |
|
321 | + // check that option is an array |
|
322 | + if ( ! is_array($espresso_db_update)) { |
|
323 | + // if option is FALSE, then it never existed |
|
324 | + if ($espresso_db_update === false) { |
|
325 | + // make $espresso_db_update an array and save option with autoload OFF |
|
326 | + $espresso_db_update = array(); |
|
327 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
328 | + } else { |
|
329 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
330 | + $espresso_db_update = array($espresso_db_update => array()); |
|
331 | + update_option('espresso_db_update', $espresso_db_update); |
|
332 | + } |
|
333 | + } else { |
|
334 | + $corrected_db_update = array(); |
|
335 | + //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
336 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
337 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
338 | + //the key is an int, and the value IS NOT an array |
|
339 | + //so it must be numerically-indexed, where values are versions installed... |
|
340 | + //fix it! |
|
341 | + $version_string = $should_be_array; |
|
342 | + $corrected_db_update[$version_string] = array('unknown-date'); |
|
343 | + } else { |
|
344 | + //ok it checks out |
|
345 | + $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
346 | + } |
|
347 | + } |
|
348 | + $espresso_db_update = $corrected_db_update; |
|
349 | + update_option('espresso_db_update', $espresso_db_update); |
|
350 | + } |
|
351 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
352 | + return $espresso_db_update; |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
359 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
360 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
361 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
362 | + * so that it will be done when migrations are finished |
|
363 | + * |
|
364 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
365 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
366 | + * This is a resource-intensive job |
|
367 | + * so we prefer to only do it when necessary |
|
368 | + * @return void |
|
369 | + */ |
|
370 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
371 | + { |
|
372 | + $request_type = $this->detect_req_type(); |
|
373 | + //only initialize system if we're not in maintenance mode. |
|
374 | + if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
375 | + update_option('ee_flush_rewrite_rules', true); |
|
376 | + if ($verify_schema) { |
|
377 | + EEH_Activation::initialize_db_and_folders(); |
|
378 | + } |
|
379 | + EEH_Activation::initialize_db_content(); |
|
380 | + EEH_Activation::system_initialization(); |
|
381 | + if ($initialize_addons_too) { |
|
382 | + $this->initialize_addons(); |
|
383 | + } |
|
384 | + } else { |
|
385 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
386 | + } |
|
387 | + if ($request_type === EE_System::req_type_new_activation |
|
388 | + || $request_type === EE_System::req_type_reactivation |
|
389 | + || ( |
|
390 | + $request_type === EE_System::req_type_upgrade |
|
391 | + && $this->is_major_version_change() |
|
392 | + ) |
|
393 | + ) { |
|
394 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
395 | + } |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * Initializes the db for all registered addons |
|
402 | + */ |
|
403 | + public function initialize_addons() |
|
404 | + { |
|
405 | + //foreach registered addon, make sure its db is up-to-date too |
|
406 | + foreach ($this->registry->addons as $addon) { |
|
407 | + $addon->initialize_db_if_no_migrations_required(); |
|
408 | + } |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
415 | + * |
|
416 | + * @param array $version_history |
|
417 | + * @param string $current_version_to_add version to be added to the version history |
|
418 | + * @return boolean success as to whether or not this option was changed |
|
419 | + */ |
|
420 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
421 | + { |
|
422 | + if ( ! $version_history) { |
|
423 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
424 | + } |
|
425 | + if ($current_version_to_add == null) { |
|
426 | + $current_version_to_add = espresso_version(); |
|
427 | + } |
|
428 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
429 | + // re-save |
|
430 | + return update_option('espresso_db_update', $version_history); |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * Detects if the current version indicated in the has existed in the list of |
|
437 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
438 | + * |
|
439 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
440 | + * If not supplied, fetches it from the options table. |
|
441 | + * Also, caches its result so later parts of the code can also know whether |
|
442 | + * there's been an update or not. This way we can add the current version to |
|
443 | + * espresso_db_update, but still know if this is a new install or not |
|
444 | + * @return int one of the constants on EE_System::req_type_ |
|
445 | + */ |
|
446 | + public function detect_req_type($espresso_db_update = null) |
|
447 | + { |
|
448 | + if ($this->_req_type === null) { |
|
449 | + $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
450 | + : $this->fix_espresso_db_upgrade_option(); |
|
451 | + $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, |
|
452 | + 'ee_espresso_activation', espresso_version()); |
|
453 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
454 | + } |
|
455 | + return $this->_req_type; |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + |
|
460 | + /** |
|
461 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
462 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
463 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
464 | + * |
|
465 | + * @param $activation_history |
|
466 | + * @return bool |
|
467 | + */ |
|
468 | + protected function _detect_major_version_change($activation_history) |
|
469 | + { |
|
470 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
471 | + $previous_version_parts = explode('.', $previous_version); |
|
472 | + $current_version_parts = explode('.', espresso_version()); |
|
473 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
474 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
475 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
476 | + ); |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * Returns true if either the major or minor version of EE changed during this request. |
|
483 | + * 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 |
|
484 | + * |
|
485 | + * @return bool |
|
486 | + */ |
|
487 | + public function is_major_version_change() |
|
488 | + { |
|
489 | + return $this->_major_version_change; |
|
490 | + } |
|
491 | + |
|
492 | + |
|
493 | + |
|
494 | + /** |
|
495 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
496 | + * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily |
|
497 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
498 | + * just activated to (for core that will always be espresso_version()) |
|
499 | + * |
|
500 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
501 | + * ee plugin. for core that's 'espresso_db_update' |
|
502 | + * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to |
|
503 | + * indicate that this plugin was just activated |
|
504 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
505 | + * espresso_version()) |
|
506 | + * @return int one of the constants on EE_System::req_type_* |
|
507 | + */ |
|
508 | + public static function detect_req_type_given_activation_history( |
|
509 | + $activation_history_for_addon, |
|
510 | + $activation_indicator_option_name, |
|
511 | + $version_to_upgrade_to |
|
512 | + ) { |
|
513 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
514 | + if ($activation_history_for_addon) { |
|
515 | + //it exists, so this isn't a completely new install |
|
516 | + //check if this version already in that list of previously installed versions |
|
517 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
518 | + //it a version we haven't seen before |
|
519 | + if ($version_is_higher === 1) { |
|
520 | + $req_type = EE_System::req_type_upgrade; |
|
521 | + } else { |
|
522 | + $req_type = EE_System::req_type_downgrade; |
|
523 | + } |
|
524 | + delete_option($activation_indicator_option_name); |
|
525 | + } else { |
|
526 | + // its not an update. maybe a reactivation? |
|
527 | + if (get_option($activation_indicator_option_name, false)) { |
|
528 | + if ($version_is_higher === -1) { |
|
529 | + $req_type = EE_System::req_type_downgrade; |
|
530 | + } elseif ($version_is_higher === 0) { |
|
531 | + //we've seen this version before, but it's an activation. must be a reactivation |
|
532 | + $req_type = EE_System::req_type_reactivation; |
|
533 | + } else {//$version_is_higher === 1 |
|
534 | + $req_type = EE_System::req_type_upgrade; |
|
535 | + } |
|
536 | + delete_option($activation_indicator_option_name); |
|
537 | + } else { |
|
538 | + //we've seen this version before and the activation indicate doesn't show it was just activated |
|
539 | + if ($version_is_higher === -1) { |
|
540 | + $req_type = EE_System::req_type_downgrade; |
|
541 | + } elseif ($version_is_higher === 0) { |
|
542 | + //we've seen this version before and it's not an activation. its normal request |
|
543 | + $req_type = EE_System::req_type_normal; |
|
544 | + } else {//$version_is_higher === 1 |
|
545 | + $req_type = EE_System::req_type_upgrade; |
|
546 | + } |
|
547 | + } |
|
548 | + } |
|
549 | + } else { |
|
550 | + //brand new install |
|
551 | + $req_type = EE_System::req_type_new_activation; |
|
552 | + delete_option($activation_indicator_option_name); |
|
553 | + } |
|
554 | + return $req_type; |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
561 | + * the $activation_history_for_addon |
|
562 | + * |
|
563 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
564 | + * sometimes containing 'unknown-date' |
|
565 | + * @param string $version_to_upgrade_to (current version) |
|
566 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
567 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
568 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
569 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
570 | + */ |
|
571 | + protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
572 | + { |
|
573 | + //find the most recently-activated version |
|
574 | + $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
575 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
576 | + } |
|
577 | + |
|
578 | + |
|
579 | + |
|
580 | + /** |
|
581 | + * Gets the most recently active version listed in the activation history, |
|
582 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
583 | + * |
|
584 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
585 | + * sometimes containing 'unknown-date' |
|
586 | + * @return string |
|
587 | + */ |
|
588 | + protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
589 | + { |
|
590 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
591 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
592 | + if (is_array($activation_history)) { |
|
593 | + foreach ($activation_history as $version => $times_activated) { |
|
594 | + //check there is a record of when this version was activated. Otherwise, |
|
595 | + //mark it as unknown |
|
596 | + if ( ! $times_activated) { |
|
597 | + $times_activated = array('unknown-date'); |
|
598 | + } |
|
599 | + if (is_string($times_activated)) { |
|
600 | + $times_activated = array($times_activated); |
|
601 | + } |
|
602 | + foreach ($times_activated as $an_activation) { |
|
603 | + if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
604 | + $most_recently_active_version = $version; |
|
605 | + $most_recently_active_version_activation = $an_activation == 'unknown-date' |
|
606 | + ? '1970-01-01 00:00:00' : $an_activation; |
|
607 | + } |
|
608 | + } |
|
609 | + } |
|
610 | + } |
|
611 | + return $most_recently_active_version; |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * This redirects to the about EE page after activation |
|
618 | + * |
|
619 | + * @return void |
|
620 | + */ |
|
621 | + public function redirect_to_about_ee() |
|
622 | + { |
|
623 | + $notices = EE_Error::get_notices(false); |
|
624 | + //if current user is an admin and it's not an ajax or rest request |
|
625 | + if ( |
|
626 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
627 | + && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
628 | + && ! isset($notices['errors']) |
|
629 | + && apply_filters( |
|
630 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
631 | + $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
632 | + ) |
|
633 | + ) { |
|
634 | + $query_params = array('page' => 'espresso_about'); |
|
635 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
636 | + $query_params['new_activation'] = true; |
|
637 | + } |
|
638 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
639 | + $query_params['reactivation'] = true; |
|
640 | + } |
|
641 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
642 | + wp_safe_redirect($url); |
|
643 | + exit(); |
|
644 | + } |
|
645 | + } |
|
646 | + |
|
647 | + |
|
648 | + |
|
649 | + /** |
|
650 | + * load_core_configuration |
|
651 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
652 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
653 | + * |
|
654 | + * @return void |
|
655 | + */ |
|
656 | + public function load_core_configuration() |
|
657 | + { |
|
658 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
659 | + $this->registry->load_core('EE_Load_Textdomain'); |
|
660 | + //load textdomain |
|
661 | + EE_Load_Textdomain::load_textdomain(); |
|
662 | + // load and setup EE_Config and EE_Network_Config |
|
663 | + $this->registry->load_core('Config'); |
|
664 | + $this->registry->load_core('Network_Config'); |
|
665 | + // setup autoloaders |
|
666 | + // enable logging? |
|
667 | + if ($this->registry->CFG->admin->use_full_logging) { |
|
668 | + $this->registry->load_core('Log'); |
|
669 | + } |
|
670 | + // check for activation errors |
|
671 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
672 | + if ($activation_errors) { |
|
673 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
674 | + update_option('ee_plugin_activation_errors', false); |
|
675 | + } |
|
676 | + // get model names |
|
677 | + $this->_parse_model_names(); |
|
678 | + //load caf stuff a chance to play during the activation process too. |
|
679 | + $this->_maybe_brew_regular(); |
|
680 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
681 | + } |
|
682 | + |
|
683 | + |
|
684 | + |
|
685 | + /** |
|
686 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
687 | + * |
|
688 | + * @return void |
|
689 | + */ |
|
690 | + private function _parse_model_names() |
|
691 | + { |
|
692 | + //get all the files in the EE_MODELS folder that end in .model.php |
|
693 | + $models = glob(EE_MODELS . '*.model.php'); |
|
694 | + $model_names = array(); |
|
695 | + $non_abstract_db_models = array(); |
|
696 | + foreach ($models as $model) { |
|
697 | + // get model classname |
|
698 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
699 | + $short_name = str_replace('EEM_', '', $classname); |
|
700 | + $reflectionClass = new ReflectionClass($classname); |
|
701 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
702 | + $non_abstract_db_models[$short_name] = $classname; |
|
703 | + } |
|
704 | + $model_names[$short_name] = $classname; |
|
705 | + } |
|
706 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
707 | + $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
708 | + $non_abstract_db_models); |
|
709 | + } |
|
710 | + |
|
711 | + |
|
712 | + |
|
713 | + /** |
|
714 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
715 | + * that need to be setup before our EE_System launches. |
|
716 | + * |
|
717 | + * @return void |
|
718 | + */ |
|
719 | + private function _maybe_brew_regular() |
|
720 | + { |
|
721 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
722 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
723 | + } |
|
724 | + } |
|
725 | + |
|
726 | + |
|
727 | + |
|
728 | + /** |
|
729 | + * register_shortcodes_modules_and_widgets |
|
730 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
731 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
732 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
733 | + * |
|
734 | + * @access public |
|
735 | + * @return void |
|
736 | + */ |
|
737 | + public function register_shortcodes_modules_and_widgets() |
|
738 | + { |
|
739 | + try { |
|
740 | + // load, register, and add shortcodes the new way |
|
741 | + new ShortcodesManager( |
|
742 | + // and the old way, but we'll put it under control of the new system |
|
743 | + EE_Config::getLegacyShortcodesManager() |
|
744 | + ); |
|
745 | + } catch (Exception $exception) { |
|
746 | + new ExceptionStackTraceDisplay($exception); |
|
747 | + } |
|
748 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
749 | + // check for addons using old hookpoint |
|
750 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
751 | + $this->_incompatible_addon_error(); |
|
752 | + } |
|
753 | + } |
|
754 | + |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * _incompatible_addon_error |
|
759 | + * |
|
760 | + * @access public |
|
761 | + * @return void |
|
762 | + */ |
|
763 | + private function _incompatible_addon_error() |
|
764 | + { |
|
765 | + // get array of classes hooking into here |
|
766 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
767 | + if ( ! empty($class_names)) { |
|
768 | + $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
769 | + 'event_espresso'); |
|
770 | + $msg .= '<ul>'; |
|
771 | + foreach ($class_names as $class_name) { |
|
772 | + $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
773 | + $class_name) . '</b></li>'; |
|
774 | + } |
|
775 | + $msg .= '</ul>'; |
|
776 | + $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
777 | + 'event_espresso'); |
|
778 | + // save list of incompatible addons to wp-options for later use |
|
779 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
780 | + if (is_admin()) { |
|
781 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
782 | + } |
|
783 | + } |
|
784 | + } |
|
785 | + |
|
786 | + |
|
787 | + |
|
788 | + /** |
|
789 | + * brew_espresso |
|
790 | + * begins the process of setting hooks for initializing EE in the correct order |
|
791 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
|
792 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
793 | + * |
|
794 | + * @return void |
|
795 | + */ |
|
796 | + public function brew_espresso() |
|
797 | + { |
|
798 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
799 | + // load some final core systems |
|
800 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
801 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
802 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
803 | + add_action('init', array($this, 'load_controllers'), 7); |
|
804 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
805 | + add_action('init', array($this, 'initialize'), 10); |
|
806 | + add_action('init', array($this, 'initialize_last'), 100); |
|
807 | + add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
808 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
809 | + // pew pew pew |
|
810 | + $this->registry->load_core('PUE'); |
|
811 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
812 | + } |
|
813 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
814 | + } |
|
815 | + |
|
816 | + |
|
817 | + |
|
818 | + /** |
|
819 | + * set_hooks_for_core |
|
820 | + * |
|
821 | + * @access public |
|
822 | + * @return void |
|
823 | + */ |
|
824 | + public function set_hooks_for_core() |
|
825 | + { |
|
826 | + $this->_deactivate_incompatible_addons(); |
|
827 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
828 | + } |
|
829 | + |
|
830 | + |
|
831 | + |
|
832 | + /** |
|
833 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
834 | + * deactivates any addons considered incompatible with the current version of EE |
|
835 | + */ |
|
836 | + private function _deactivate_incompatible_addons() |
|
837 | + { |
|
838 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
839 | + if ( ! empty($incompatible_addons)) { |
|
840 | + $active_plugins = get_option('active_plugins', array()); |
|
841 | + foreach ($active_plugins as $active_plugin) { |
|
842 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
843 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
844 | + unset($_GET['activate']); |
|
845 | + espresso_deactivate_plugin($active_plugin); |
|
846 | + } |
|
847 | + } |
|
848 | + } |
|
849 | + } |
|
850 | + } |
|
851 | + |
|
852 | + |
|
853 | + |
|
854 | + /** |
|
855 | + * perform_activations_upgrades_and_migrations |
|
856 | + * |
|
857 | + * @access public |
|
858 | + * @return void |
|
859 | + */ |
|
860 | + public function perform_activations_upgrades_and_migrations() |
|
861 | + { |
|
862 | + //first check if we had previously attempted to setup EE's directories but failed |
|
863 | + if (EEH_Activation::upload_directories_incomplete()) { |
|
864 | + EEH_Activation::create_upload_directories(); |
|
865 | + } |
|
866 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
867 | + } |
|
868 | + |
|
869 | + |
|
870 | + |
|
871 | + /** |
|
872 | + * load_CPTs_and_session |
|
873 | + * |
|
874 | + * @access public |
|
875 | + * @return void |
|
876 | + */ |
|
877 | + public function load_CPTs_and_session() |
|
878 | + { |
|
879 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
880 | + // register Custom Post Types |
|
881 | + $this->registry->load_core('Register_CPTs'); |
|
882 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
883 | + } |
|
884 | + |
|
885 | + |
|
886 | + |
|
887 | + /** |
|
888 | + * load_controllers |
|
889 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
890 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
891 | + * time |
|
892 | + * |
|
893 | + * @access public |
|
894 | + * @return void |
|
895 | + */ |
|
896 | + public function load_controllers() |
|
897 | + { |
|
898 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
899 | + // let's get it started |
|
900 | + if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
901 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
902 | + $this->registry->load_core('Front_Controller'); |
|
903 | + } else if ( ! EE_FRONT_AJAX) { |
|
904 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
905 | + EE_Registry::instance()->load_core('Admin'); |
|
906 | + } |
|
907 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
908 | + } |
|
909 | + |
|
910 | + |
|
911 | + |
|
912 | + /** |
|
913 | + * core_loaded_and_ready |
|
914 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
915 | + * |
|
916 | + * @access public |
|
917 | + * @return void |
|
918 | + */ |
|
919 | + public function core_loaded_and_ready() |
|
920 | + { |
|
921 | + $this->registry->load_core('Session'); |
|
922 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
923 | + // load_espresso_template_tags |
|
924 | + if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
925 | + require_once(EE_PUBLIC . 'template_tags.php'); |
|
926 | + } |
|
927 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
928 | + $this->registry->create('EventEspresso\core\services\assets\Registry'); |
|
929 | + } |
|
930 | + |
|
931 | + |
|
932 | + |
|
933 | + /** |
|
934 | + * initialize |
|
935 | + * this is the best place to begin initializing client code |
|
936 | + * |
|
937 | + * @access public |
|
938 | + * @return void |
|
939 | + */ |
|
940 | + public function initialize() |
|
941 | + { |
|
942 | + do_action('AHEE__EE_System__initialize'); |
|
943 | + } |
|
944 | + |
|
945 | + |
|
946 | + |
|
947 | + /** |
|
948 | + * initialize_last |
|
949 | + * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
950 | + * initialize has done so |
|
951 | + * |
|
952 | + * @access public |
|
953 | + * @return void |
|
954 | + */ |
|
955 | + public function initialize_last() |
|
956 | + { |
|
957 | + do_action('AHEE__EE_System__initialize_last'); |
|
958 | + } |
|
959 | + |
|
960 | + |
|
961 | + |
|
962 | + /** |
|
963 | + * set_hooks_for_shortcodes_modules_and_addons |
|
964 | + * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
965 | + * this happens at the very beginning of the wp_loaded hookpoint |
|
966 | + * |
|
967 | + * @access public |
|
968 | + * @return void |
|
969 | + */ |
|
970 | + public function set_hooks_for_shortcodes_modules_and_addons() |
|
971 | + { |
|
972 | + // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
973 | + } |
|
974 | + |
|
975 | + |
|
976 | + |
|
977 | + /** |
|
978 | + * do_not_cache |
|
979 | + * sets no cache headers and defines no cache constants for WP plugins |
|
980 | + * |
|
981 | + * @access public |
|
982 | + * @return void |
|
983 | + */ |
|
984 | + public static function do_not_cache() |
|
985 | + { |
|
986 | + // set no cache constants |
|
987 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
988 | + define('DONOTCACHEPAGE', true); |
|
989 | + } |
|
990 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
991 | + define('DONOTCACHCEOBJECT', true); |
|
992 | + } |
|
993 | + if ( ! defined('DONOTCACHEDB')) { |
|
994 | + define('DONOTCACHEDB', true); |
|
995 | + } |
|
996 | + // add no cache headers |
|
997 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
998 | + // plus a little extra for nginx and Google Chrome |
|
999 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1000 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1001 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1002 | + } |
|
1003 | + |
|
1004 | + |
|
1005 | + |
|
1006 | + /** |
|
1007 | + * extra_nocache_headers |
|
1008 | + * |
|
1009 | + * @access public |
|
1010 | + * @param $headers |
|
1011 | + * @return array |
|
1012 | + */ |
|
1013 | + public static function extra_nocache_headers($headers) |
|
1014 | + { |
|
1015 | + // for NGINX |
|
1016 | + $headers['X-Accel-Expires'] = 0; |
|
1017 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1018 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1019 | + return $headers; |
|
1020 | + } |
|
1021 | + |
|
1022 | + |
|
1023 | + |
|
1024 | + /** |
|
1025 | + * nocache_headers |
|
1026 | + * |
|
1027 | + * @access public |
|
1028 | + * @return void |
|
1029 | + */ |
|
1030 | + public static function nocache_headers() |
|
1031 | + { |
|
1032 | + nocache_headers(); |
|
1033 | + } |
|
1034 | + |
|
1035 | + |
|
1036 | + |
|
1037 | + /** |
|
1038 | + * espresso_toolbar_items |
|
1039 | + * |
|
1040 | + * @access public |
|
1041 | + * @param WP_Admin_Bar $admin_bar |
|
1042 | + * @return void |
|
1043 | + */ |
|
1044 | + public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
1045 | + { |
|
1046 | + // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
1047 | + if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
1048 | + || defined('DOING_AJAX') |
|
1049 | + || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
1050 | + ) { |
|
1051 | + return; |
|
1052 | + } |
|
1053 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1054 | + $menu_class = 'espresso_menu_item_class'; |
|
1055 | + //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
1056 | + //because they're only defined in each of their respective constructors |
|
1057 | + //and this might be a frontend request, in which case they aren't available |
|
1058 | + $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
1059 | + $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
1060 | + $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
1061 | + //Top Level |
|
1062 | + $admin_bar->add_menu(array( |
|
1063 | + 'id' => 'espresso-toolbar', |
|
1064 | + 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
1065 | + . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
1066 | + . '</span>', |
|
1067 | + 'href' => $events_admin_url, |
|
1068 | + 'meta' => array( |
|
1069 | + 'title' => __('Event Espresso', 'event_espresso'), |
|
1070 | + 'class' => $menu_class . 'first', |
|
1071 | + ), |
|
1072 | + )); |
|
1073 | + //Events |
|
1074 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
1075 | + $admin_bar->add_menu(array( |
|
1076 | + 'id' => 'espresso-toolbar-events', |
|
1077 | + 'parent' => 'espresso-toolbar', |
|
1078 | + 'title' => __('Events', 'event_espresso'), |
|
1079 | + 'href' => $events_admin_url, |
|
1080 | + 'meta' => array( |
|
1081 | + 'title' => __('Events', 'event_espresso'), |
|
1082 | + 'target' => '', |
|
1083 | + 'class' => $menu_class, |
|
1084 | + ), |
|
1085 | + )); |
|
1086 | + } |
|
1087 | + if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
1088 | + //Events Add New |
|
1089 | + $admin_bar->add_menu(array( |
|
1090 | + 'id' => 'espresso-toolbar-events-new', |
|
1091 | + 'parent' => 'espresso-toolbar-events', |
|
1092 | + 'title' => __('Add New', 'event_espresso'), |
|
1093 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
1094 | + 'meta' => array( |
|
1095 | + 'title' => __('Add New', 'event_espresso'), |
|
1096 | + 'target' => '', |
|
1097 | + 'class' => $menu_class, |
|
1098 | + ), |
|
1099 | + )); |
|
1100 | + } |
|
1101 | + if (is_single() && (get_post_type() == 'espresso_events')) { |
|
1102 | + //Current post |
|
1103 | + global $post; |
|
1104 | + if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
1105 | + 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
1106 | + ) { |
|
1107 | + //Events Edit Current Event |
|
1108 | + $admin_bar->add_menu(array( |
|
1109 | + 'id' => 'espresso-toolbar-events-edit', |
|
1110 | + 'parent' => 'espresso-toolbar-events', |
|
1111 | + 'title' => __('Edit Event', 'event_espresso'), |
|
1112 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
1113 | + $events_admin_url), |
|
1114 | + 'meta' => array( |
|
1115 | + 'title' => __('Edit Event', 'event_espresso'), |
|
1116 | + 'target' => '', |
|
1117 | + 'class' => $menu_class, |
|
1118 | + ), |
|
1119 | + )); |
|
1120 | + } |
|
1121 | + } |
|
1122 | + //Events View |
|
1123 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1124 | + 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
1125 | + ) { |
|
1126 | + $admin_bar->add_menu(array( |
|
1127 | + 'id' => 'espresso-toolbar-events-view', |
|
1128 | + 'parent' => 'espresso-toolbar-events', |
|
1129 | + 'title' => __('View', 'event_espresso'), |
|
1130 | + 'href' => $events_admin_url, |
|
1131 | + 'meta' => array( |
|
1132 | + 'title' => __('View', 'event_espresso'), |
|
1133 | + 'target' => '', |
|
1134 | + 'class' => $menu_class, |
|
1135 | + ), |
|
1136 | + )); |
|
1137 | + } |
|
1138 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
1139 | + //Events View All |
|
1140 | + $admin_bar->add_menu(array( |
|
1141 | + 'id' => 'espresso-toolbar-events-all', |
|
1142 | + 'parent' => 'espresso-toolbar-events-view', |
|
1143 | + 'title' => __('All', 'event_espresso'), |
|
1144 | + 'href' => $events_admin_url, |
|
1145 | + 'meta' => array( |
|
1146 | + 'title' => __('All', 'event_espresso'), |
|
1147 | + 'target' => '', |
|
1148 | + 'class' => $menu_class, |
|
1149 | + ), |
|
1150 | + )); |
|
1151 | + } |
|
1152 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1153 | + 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
1154 | + ) { |
|
1155 | + //Events View Today |
|
1156 | + $admin_bar->add_menu(array( |
|
1157 | + 'id' => 'espresso-toolbar-events-today', |
|
1158 | + 'parent' => 'espresso-toolbar-events-view', |
|
1159 | + 'title' => __('Today', 'event_espresso'), |
|
1160 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1161 | + $events_admin_url), |
|
1162 | + 'meta' => array( |
|
1163 | + 'title' => __('Today', 'event_espresso'), |
|
1164 | + 'target' => '', |
|
1165 | + 'class' => $menu_class, |
|
1166 | + ), |
|
1167 | + )); |
|
1168 | + } |
|
1169 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1170 | + 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
1171 | + ) { |
|
1172 | + //Events View This Month |
|
1173 | + $admin_bar->add_menu(array( |
|
1174 | + 'id' => 'espresso-toolbar-events-month', |
|
1175 | + 'parent' => 'espresso-toolbar-events-view', |
|
1176 | + 'title' => __('This Month', 'event_espresso'), |
|
1177 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1178 | + $events_admin_url), |
|
1179 | + 'meta' => array( |
|
1180 | + 'title' => __('This Month', 'event_espresso'), |
|
1181 | + 'target' => '', |
|
1182 | + 'class' => $menu_class, |
|
1183 | + ), |
|
1184 | + )); |
|
1185 | + } |
|
1186 | + //Registration Overview |
|
1187 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1188 | + 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
1189 | + ) { |
|
1190 | + $admin_bar->add_menu(array( |
|
1191 | + 'id' => 'espresso-toolbar-registrations', |
|
1192 | + 'parent' => 'espresso-toolbar', |
|
1193 | + 'title' => __('Registrations', 'event_espresso'), |
|
1194 | + 'href' => $reg_admin_url, |
|
1195 | + 'meta' => array( |
|
1196 | + 'title' => __('Registrations', 'event_espresso'), |
|
1197 | + 'target' => '', |
|
1198 | + 'class' => $menu_class, |
|
1199 | + ), |
|
1200 | + )); |
|
1201 | + } |
|
1202 | + //Registration Overview Today |
|
1203 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1204 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
1205 | + ) { |
|
1206 | + $admin_bar->add_menu(array( |
|
1207 | + 'id' => 'espresso-toolbar-registrations-today', |
|
1208 | + 'parent' => 'espresso-toolbar-registrations', |
|
1209 | + 'title' => __('Today', 'event_espresso'), |
|
1210 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1211 | + $reg_admin_url), |
|
1212 | + 'meta' => array( |
|
1213 | + 'title' => __('Today', 'event_espresso'), |
|
1214 | + 'target' => '', |
|
1215 | + 'class' => $menu_class, |
|
1216 | + ), |
|
1217 | + )); |
|
1218 | + } |
|
1219 | + //Registration Overview Today Completed |
|
1220 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1221 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
1222 | + ) { |
|
1223 | + $admin_bar->add_menu(array( |
|
1224 | + 'id' => 'espresso-toolbar-registrations-today-approved', |
|
1225 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1226 | + 'title' => __('Approved', 'event_espresso'), |
|
1227 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1228 | + 'action' => 'default', |
|
1229 | + 'status' => 'today', |
|
1230 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1231 | + ), $reg_admin_url), |
|
1232 | + 'meta' => array( |
|
1233 | + 'title' => __('Approved', 'event_espresso'), |
|
1234 | + 'target' => '', |
|
1235 | + 'class' => $menu_class, |
|
1236 | + ), |
|
1237 | + )); |
|
1238 | + } |
|
1239 | + //Registration Overview Today Pending\ |
|
1240 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1241 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
1242 | + ) { |
|
1243 | + $admin_bar->add_menu(array( |
|
1244 | + 'id' => 'espresso-toolbar-registrations-today-pending', |
|
1245 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1246 | + 'title' => __('Pending', 'event_espresso'), |
|
1247 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1248 | + 'action' => 'default', |
|
1249 | + 'status' => 'today', |
|
1250 | + 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
1251 | + ), $reg_admin_url), |
|
1252 | + 'meta' => array( |
|
1253 | + 'title' => __('Pending Payment', 'event_espresso'), |
|
1254 | + 'target' => '', |
|
1255 | + 'class' => $menu_class, |
|
1256 | + ), |
|
1257 | + )); |
|
1258 | + } |
|
1259 | + //Registration Overview Today Incomplete |
|
1260 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1261 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
1262 | + ) { |
|
1263 | + $admin_bar->add_menu(array( |
|
1264 | + 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
1265 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1266 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1267 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1268 | + 'action' => 'default', |
|
1269 | + 'status' => 'today', |
|
1270 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1271 | + ), $reg_admin_url), |
|
1272 | + 'meta' => array( |
|
1273 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1274 | + 'target' => '', |
|
1275 | + 'class' => $menu_class, |
|
1276 | + ), |
|
1277 | + )); |
|
1278 | + } |
|
1279 | + //Registration Overview Today Incomplete |
|
1280 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1281 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
1282 | + ) { |
|
1283 | + $admin_bar->add_menu(array( |
|
1284 | + 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
1285 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1286 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1287 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1288 | + 'action' => 'default', |
|
1289 | + 'status' => 'today', |
|
1290 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1291 | + ), $reg_admin_url), |
|
1292 | + 'meta' => array( |
|
1293 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1294 | + 'target' => '', |
|
1295 | + 'class' => $menu_class, |
|
1296 | + ), |
|
1297 | + )); |
|
1298 | + } |
|
1299 | + //Registration Overview This Month |
|
1300 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1301 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
1302 | + ) { |
|
1303 | + $admin_bar->add_menu(array( |
|
1304 | + 'id' => 'espresso-toolbar-registrations-month', |
|
1305 | + 'parent' => 'espresso-toolbar-registrations', |
|
1306 | + 'title' => __('This Month', 'event_espresso'), |
|
1307 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1308 | + $reg_admin_url), |
|
1309 | + 'meta' => array( |
|
1310 | + 'title' => __('This Month', 'event_espresso'), |
|
1311 | + 'target' => '', |
|
1312 | + 'class' => $menu_class, |
|
1313 | + ), |
|
1314 | + )); |
|
1315 | + } |
|
1316 | + //Registration Overview This Month Approved |
|
1317 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1318 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
1319 | + ) { |
|
1320 | + $admin_bar->add_menu(array( |
|
1321 | + 'id' => 'espresso-toolbar-registrations-month-approved', |
|
1322 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1323 | + 'title' => __('Approved', 'event_espresso'), |
|
1324 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1325 | + 'action' => 'default', |
|
1326 | + 'status' => 'month', |
|
1327 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1328 | + ), $reg_admin_url), |
|
1329 | + 'meta' => array( |
|
1330 | + 'title' => __('Approved', 'event_espresso'), |
|
1331 | + 'target' => '', |
|
1332 | + 'class' => $menu_class, |
|
1333 | + ), |
|
1334 | + )); |
|
1335 | + } |
|
1336 | + //Registration Overview This Month Pending |
|
1337 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1338 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
1339 | + ) { |
|
1340 | + $admin_bar->add_menu(array( |
|
1341 | + 'id' => 'espresso-toolbar-registrations-month-pending', |
|
1342 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1343 | + 'title' => __('Pending', 'event_espresso'), |
|
1344 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1345 | + 'action' => 'default', |
|
1346 | + 'status' => 'month', |
|
1347 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1348 | + ), $reg_admin_url), |
|
1349 | + 'meta' => array( |
|
1350 | + 'title' => __('Pending', 'event_espresso'), |
|
1351 | + 'target' => '', |
|
1352 | + 'class' => $menu_class, |
|
1353 | + ), |
|
1354 | + )); |
|
1355 | + } |
|
1356 | + //Registration Overview This Month Not Approved |
|
1357 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1358 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
1359 | + ) { |
|
1360 | + $admin_bar->add_menu(array( |
|
1361 | + 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
1362 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1363 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1364 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1365 | + 'action' => 'default', |
|
1366 | + 'status' => 'month', |
|
1367 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1368 | + ), $reg_admin_url), |
|
1369 | + 'meta' => array( |
|
1370 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1371 | + 'target' => '', |
|
1372 | + 'class' => $menu_class, |
|
1373 | + ), |
|
1374 | + )); |
|
1375 | + } |
|
1376 | + //Registration Overview This Month Cancelled |
|
1377 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1378 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
1379 | + ) { |
|
1380 | + $admin_bar->add_menu(array( |
|
1381 | + 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
1382 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1383 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1384 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1385 | + 'action' => 'default', |
|
1386 | + 'status' => 'month', |
|
1387 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1388 | + ), $reg_admin_url), |
|
1389 | + 'meta' => array( |
|
1390 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1391 | + 'target' => '', |
|
1392 | + 'class' => $menu_class, |
|
1393 | + ), |
|
1394 | + )); |
|
1395 | + } |
|
1396 | + //Extensions & Services |
|
1397 | + if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
1398 | + 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
1399 | + ) { |
|
1400 | + $admin_bar->add_menu(array( |
|
1401 | + 'id' => 'espresso-toolbar-extensions-and-services', |
|
1402 | + 'parent' => 'espresso-toolbar', |
|
1403 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
1404 | + 'href' => $extensions_admin_url, |
|
1405 | + 'meta' => array( |
|
1406 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
1407 | + 'target' => '', |
|
1408 | + 'class' => $menu_class, |
|
1409 | + ), |
|
1410 | + )); |
|
1411 | + } |
|
1412 | + } |
|
1413 | + |
|
1414 | + |
|
1415 | + |
|
1416 | + /** |
|
1417 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1418 | + * never returned with the function. |
|
1419 | + * |
|
1420 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
1421 | + * @return array |
|
1422 | + */ |
|
1423 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
1424 | + { |
|
1425 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1426 | + } |
|
1427 | 1427 | |
1428 | 1428 | |
1429 | 1429 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\widgets\EspressoWidget; |
4 | 4 | |
5 | 5 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
6 | - exit('No direct script access allowed'); |
|
6 | + exit('No direct script access allowed'); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | /** |
@@ -26,385 +26,385 @@ discard block |
||
26 | 26 | final class EE_Front_Controller |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * @var string $_template_path |
|
31 | - */ |
|
32 | - private $_template_path; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string $_template |
|
36 | - */ |
|
37 | - private $_template; |
|
38 | - |
|
39 | - /** |
|
40 | - * @type EE_Registry $Registry |
|
41 | - */ |
|
42 | - protected $Registry; |
|
43 | - |
|
44 | - /** |
|
45 | - * @type EE_Request_Handler $Request_Handler |
|
46 | - */ |
|
47 | - protected $Request_Handler; |
|
48 | - |
|
49 | - /** |
|
50 | - * @type EE_Module_Request_Router $Module_Request_Router |
|
51 | - */ |
|
52 | - protected $Module_Request_Router; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * class constructor |
|
57 | - * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
58 | - * |
|
59 | - * @access public |
|
60 | - * @param \EE_Registry $Registry |
|
61 | - * @param \EE_Request_Handler $Request_Handler |
|
62 | - * @param \EE_Module_Request_Router $Module_Request_Router |
|
63 | - */ |
|
64 | - public function __construct( |
|
65 | - EE_Registry $Registry, |
|
66 | - EE_Request_Handler $Request_Handler, |
|
67 | - EE_Module_Request_Router $Module_Request_Router |
|
68 | - ) { |
|
69 | - $this->Registry = $Registry; |
|
70 | - $this->Request_Handler = $Request_Handler; |
|
71 | - $this->Module_Request_Router = $Module_Request_Router; |
|
72 | - // determine how to integrate WP_Query with the EE models |
|
73 | - add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
74 | - // load other resources and begin to actually run shortcodes and modules |
|
75 | - add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
76 | - // analyse the incoming WP request |
|
77 | - add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
78 | - // process request with module factory |
|
79 | - add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
80 | - // before headers sent |
|
81 | - add_action('wp', array($this, 'wp'), 5); |
|
82 | - // primarily used to process any content shortcodes |
|
83 | - add_action('template_redirect', array($this, 'templateRedirect'), 999); |
|
84 | - // header |
|
85 | - add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
86 | - add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
87 | - add_filter('template_include', array($this, 'template_include'), 1); |
|
88 | - // display errors |
|
89 | - add_action('loop_start', array($this, 'display_errors'), 2); |
|
90 | - // the content |
|
91 | - // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
92 | - //exclude our private cpt comments |
|
93 | - add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
94 | - //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
95 | - add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
96 | - // action hook EE |
|
97 | - do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
98 | - // for checking that browser cookies are enabled |
|
99 | - if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
|
100 | - setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @return EE_Request_Handler |
|
107 | - */ |
|
108 | - public function Request_Handler() |
|
109 | - { |
|
110 | - return $this->Request_Handler; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @return EE_Module_Request_Router |
|
116 | - */ |
|
117 | - public function Module_Request_Router() |
|
118 | - { |
|
119 | - return $this->Module_Request_Router; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @return LegacyShortcodesManager |
|
126 | - */ |
|
127 | - public function getLegacyShortcodesManager() |
|
128 | - { |
|
129 | - return EE_Config::getLegacyShortcodesManager(); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
137 | - |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * filter_wp_comments |
|
142 | - * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
143 | - * widgets/queries done on frontend |
|
144 | - * |
|
145 | - * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
146 | - * @return array array of comment clauses with modifications. |
|
147 | - */ |
|
148 | - public function filter_wp_comments($clauses) |
|
149 | - { |
|
150 | - global $wpdb; |
|
151 | - if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
152 | - $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
153 | - foreach ($cpts as $cpt => $details) { |
|
154 | - $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
155 | - } |
|
156 | - } |
|
157 | - return $clauses; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * employ_CPT_Strategy |
|
163 | - * |
|
164 | - * @access public |
|
165 | - * @return void |
|
166 | - */ |
|
167 | - public function employ_CPT_Strategy() |
|
168 | - { |
|
169 | - if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
170 | - $this->Registry->load_core('CPT_Strategy'); |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
177 | - * |
|
178 | - * @param string $url incoming url |
|
179 | - * @return string final assembled url |
|
180 | - */ |
|
181 | - public function maybe_force_admin_ajax_ssl($url) |
|
182 | - { |
|
183 | - if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
184 | - $url = str_replace('http://', 'https://', $url); |
|
185 | - } |
|
186 | - return $url; |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
199 | - * default priority init phases have run |
|
200 | - * |
|
201 | - * @access public |
|
202 | - * @return void |
|
203 | - */ |
|
204 | - public function wp_loaded() |
|
205 | - { |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - |
|
210 | - |
|
211 | - |
|
212 | - /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
213 | - /** |
|
214 | - * _get_request |
|
215 | - * |
|
216 | - * @access public |
|
217 | - * @param WP $WP |
|
218 | - * @return void |
|
219 | - */ |
|
220 | - public function get_request(WP $WP) |
|
221 | - { |
|
222 | - do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
223 | - $this->Request_Handler->parse_request($WP); |
|
224 | - do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
231 | - * |
|
232 | - * @access public |
|
233 | - * @param WP_Query $WP_Query |
|
234 | - * @return void |
|
235 | - */ |
|
236 | - public function pre_get_posts($WP_Query) |
|
237 | - { |
|
238 | - // only load Module_Request_Router if this is the main query |
|
239 | - if ( |
|
240 | - $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
241 | - && $WP_Query->is_main_query() |
|
242 | - ) { |
|
243 | - // cycle thru module routes |
|
244 | - while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
245 | - // determine module and method for route |
|
246 | - $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
247 | - if ($module instanceof EED_Module) { |
|
248 | - // get registered view for route |
|
249 | - $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
250 | - // grab module name |
|
251 | - $module_name = $module->module_name(); |
|
252 | - // map the module to the module objects |
|
253 | - $this->Registry->modules->{$module_name} = $module; |
|
254 | - } |
|
255 | - } |
|
256 | - } |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - |
|
261 | - |
|
262 | - |
|
263 | - /*********************************************** WP HOOK ***********************************************/ |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * wp - basically last chance to do stuff before headers sent |
|
268 | - * |
|
269 | - * @access public |
|
270 | - * @return void |
|
271 | - */ |
|
272 | - public function wp() |
|
273 | - { |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - |
|
278 | - /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
279 | - |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * callback for the "template_redirect" hook point |
|
284 | - * checks sidebars for EE widgets |
|
285 | - * loads resources and assets accordingly |
|
286 | - * |
|
287 | - * @return void |
|
288 | - */ |
|
289 | - public function templateRedirect() |
|
290 | - { |
|
291 | - global $wp_query; |
|
292 | - if (empty($wp_query->posts)){ |
|
293 | - return; |
|
294 | - } |
|
295 | - // if we already know this is an espresso page, then load assets |
|
296 | - $load_assets = $this->Request_Handler->is_espresso_page(); |
|
297 | - // if we are already loading assets then just move along, otherwise check for widgets |
|
298 | - $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
|
299 | - if ( $load_assets){ |
|
300 | - add_action('wp_enqueue_scripts', array($this, 'enqueueStyle'), 10); |
|
301 | - add_action('wp_print_footer_scripts', array($this, 'enqueueScripts'), 10); |
|
302 | - } |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * builds list of active widgets then scans active sidebars looking for them |
|
309 | - * returns true is an EE widget is found in an active sidebar |
|
310 | - * Please Note: this does NOT mean that the sidebar or widget |
|
311 | - * is actually in use in a given template, as that is unfortunately not known |
|
312 | - * until a sidebar and it's widgets are actually loaded |
|
313 | - * |
|
314 | - * @return boolean |
|
315 | - */ |
|
316 | - private function espresso_widgets_in_active_sidebars() |
|
317 | - { |
|
318 | - $espresso_widgets = array(); |
|
319 | - foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
320 | - $id_base = EspressoWidget::getIdBase($widget_class); |
|
321 | - if (is_active_widget(false, false, $id_base)) { |
|
322 | - $espresso_widgets[] = $id_base; |
|
323 | - } |
|
324 | - } |
|
325 | - $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
326 | - foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) { |
|
327 | - if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
328 | - foreach ($sidebar_widgets as $sidebar_widget) { |
|
329 | - foreach ($espresso_widgets as $espresso_widget) { |
|
330 | - if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
331 | - return true; |
|
332 | - } |
|
333 | - } |
|
334 | - } |
|
335 | - } |
|
336 | - } |
|
337 | - return false; |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * header_meta_tag |
|
345 | - * |
|
346 | - * @access public |
|
347 | - * @return void |
|
348 | - */ |
|
349 | - public function header_meta_tag() |
|
350 | - { |
|
351 | - print( |
|
352 | - apply_filters( |
|
353 | - 'FHEE__EE_Front_Controller__header_meta_tag', |
|
354 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
355 | - ); |
|
356 | - |
|
357 | - //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
358 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
359 | - //also exclude all critical pages from indexing |
|
360 | - if ( |
|
361 | - ( |
|
362 | - is_tax('espresso_event_type') |
|
363 | - && get_option( 'blog_public' ) !== '0' |
|
364 | - ) |
|
365 | - || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
366 | - ) { |
|
367 | - print( |
|
368 | - apply_filters( |
|
369 | - 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
370 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
371 | - ) |
|
372 | - ); |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - |
|
378 | - /** |
|
379 | - * wp_print_scripts |
|
380 | - * |
|
381 | - * @return void |
|
382 | - */ |
|
383 | - public function wp_print_scripts() |
|
384 | - { |
|
385 | - global $post; |
|
386 | - if ( |
|
387 | - isset($post->EE_Event) |
|
388 | - && $post->EE_Event instanceof EE_Event |
|
389 | - && get_post_type() === 'espresso_events' |
|
390 | - && is_singular() |
|
391 | - ) { |
|
392 | - \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
393 | - } |
|
394 | - } |
|
395 | - |
|
396 | - |
|
397 | - |
|
398 | - public function enqueueStyle() |
|
399 | - { |
|
400 | - wp_enqueue_style('espresso_default'); |
|
401 | - wp_enqueue_style('espresso_custom_css'); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - |
|
406 | - |
|
407 | - /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
|
29 | + /** |
|
30 | + * @var string $_template_path |
|
31 | + */ |
|
32 | + private $_template_path; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string $_template |
|
36 | + */ |
|
37 | + private $_template; |
|
38 | + |
|
39 | + /** |
|
40 | + * @type EE_Registry $Registry |
|
41 | + */ |
|
42 | + protected $Registry; |
|
43 | + |
|
44 | + /** |
|
45 | + * @type EE_Request_Handler $Request_Handler |
|
46 | + */ |
|
47 | + protected $Request_Handler; |
|
48 | + |
|
49 | + /** |
|
50 | + * @type EE_Module_Request_Router $Module_Request_Router |
|
51 | + */ |
|
52 | + protected $Module_Request_Router; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * class constructor |
|
57 | + * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
58 | + * |
|
59 | + * @access public |
|
60 | + * @param \EE_Registry $Registry |
|
61 | + * @param \EE_Request_Handler $Request_Handler |
|
62 | + * @param \EE_Module_Request_Router $Module_Request_Router |
|
63 | + */ |
|
64 | + public function __construct( |
|
65 | + EE_Registry $Registry, |
|
66 | + EE_Request_Handler $Request_Handler, |
|
67 | + EE_Module_Request_Router $Module_Request_Router |
|
68 | + ) { |
|
69 | + $this->Registry = $Registry; |
|
70 | + $this->Request_Handler = $Request_Handler; |
|
71 | + $this->Module_Request_Router = $Module_Request_Router; |
|
72 | + // determine how to integrate WP_Query with the EE models |
|
73 | + add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
74 | + // load other resources and begin to actually run shortcodes and modules |
|
75 | + add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
76 | + // analyse the incoming WP request |
|
77 | + add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
78 | + // process request with module factory |
|
79 | + add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
80 | + // before headers sent |
|
81 | + add_action('wp', array($this, 'wp'), 5); |
|
82 | + // primarily used to process any content shortcodes |
|
83 | + add_action('template_redirect', array($this, 'templateRedirect'), 999); |
|
84 | + // header |
|
85 | + add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
86 | + add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
87 | + add_filter('template_include', array($this, 'template_include'), 1); |
|
88 | + // display errors |
|
89 | + add_action('loop_start', array($this, 'display_errors'), 2); |
|
90 | + // the content |
|
91 | + // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
92 | + //exclude our private cpt comments |
|
93 | + add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
94 | + //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
95 | + add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
96 | + // action hook EE |
|
97 | + do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
98 | + // for checking that browser cookies are enabled |
|
99 | + if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
|
100 | + setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @return EE_Request_Handler |
|
107 | + */ |
|
108 | + public function Request_Handler() |
|
109 | + { |
|
110 | + return $this->Request_Handler; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @return EE_Module_Request_Router |
|
116 | + */ |
|
117 | + public function Module_Request_Router() |
|
118 | + { |
|
119 | + return $this->Module_Request_Router; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @return LegacyShortcodesManager |
|
126 | + */ |
|
127 | + public function getLegacyShortcodesManager() |
|
128 | + { |
|
129 | + return EE_Config::getLegacyShortcodesManager(); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
137 | + |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * filter_wp_comments |
|
142 | + * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
143 | + * widgets/queries done on frontend |
|
144 | + * |
|
145 | + * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
146 | + * @return array array of comment clauses with modifications. |
|
147 | + */ |
|
148 | + public function filter_wp_comments($clauses) |
|
149 | + { |
|
150 | + global $wpdb; |
|
151 | + if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
152 | + $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
153 | + foreach ($cpts as $cpt => $details) { |
|
154 | + $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
155 | + } |
|
156 | + } |
|
157 | + return $clauses; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * employ_CPT_Strategy |
|
163 | + * |
|
164 | + * @access public |
|
165 | + * @return void |
|
166 | + */ |
|
167 | + public function employ_CPT_Strategy() |
|
168 | + { |
|
169 | + if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
170 | + $this->Registry->load_core('CPT_Strategy'); |
|
171 | + } |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
177 | + * |
|
178 | + * @param string $url incoming url |
|
179 | + * @return string final assembled url |
|
180 | + */ |
|
181 | + public function maybe_force_admin_ajax_ssl($url) |
|
182 | + { |
|
183 | + if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
184 | + $url = str_replace('http://', 'https://', $url); |
|
185 | + } |
|
186 | + return $url; |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
199 | + * default priority init phases have run |
|
200 | + * |
|
201 | + * @access public |
|
202 | + * @return void |
|
203 | + */ |
|
204 | + public function wp_loaded() |
|
205 | + { |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + |
|
210 | + |
|
211 | + |
|
212 | + /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
213 | + /** |
|
214 | + * _get_request |
|
215 | + * |
|
216 | + * @access public |
|
217 | + * @param WP $WP |
|
218 | + * @return void |
|
219 | + */ |
|
220 | + public function get_request(WP $WP) |
|
221 | + { |
|
222 | + do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
223 | + $this->Request_Handler->parse_request($WP); |
|
224 | + do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
231 | + * |
|
232 | + * @access public |
|
233 | + * @param WP_Query $WP_Query |
|
234 | + * @return void |
|
235 | + */ |
|
236 | + public function pre_get_posts($WP_Query) |
|
237 | + { |
|
238 | + // only load Module_Request_Router if this is the main query |
|
239 | + if ( |
|
240 | + $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
241 | + && $WP_Query->is_main_query() |
|
242 | + ) { |
|
243 | + // cycle thru module routes |
|
244 | + while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
245 | + // determine module and method for route |
|
246 | + $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
247 | + if ($module instanceof EED_Module) { |
|
248 | + // get registered view for route |
|
249 | + $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
250 | + // grab module name |
|
251 | + $module_name = $module->module_name(); |
|
252 | + // map the module to the module objects |
|
253 | + $this->Registry->modules->{$module_name} = $module; |
|
254 | + } |
|
255 | + } |
|
256 | + } |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + |
|
261 | + |
|
262 | + |
|
263 | + /*********************************************** WP HOOK ***********************************************/ |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * wp - basically last chance to do stuff before headers sent |
|
268 | + * |
|
269 | + * @access public |
|
270 | + * @return void |
|
271 | + */ |
|
272 | + public function wp() |
|
273 | + { |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + |
|
278 | + /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
279 | + |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * callback for the "template_redirect" hook point |
|
284 | + * checks sidebars for EE widgets |
|
285 | + * loads resources and assets accordingly |
|
286 | + * |
|
287 | + * @return void |
|
288 | + */ |
|
289 | + public function templateRedirect() |
|
290 | + { |
|
291 | + global $wp_query; |
|
292 | + if (empty($wp_query->posts)){ |
|
293 | + return; |
|
294 | + } |
|
295 | + // if we already know this is an espresso page, then load assets |
|
296 | + $load_assets = $this->Request_Handler->is_espresso_page(); |
|
297 | + // if we are already loading assets then just move along, otherwise check for widgets |
|
298 | + $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
|
299 | + if ( $load_assets){ |
|
300 | + add_action('wp_enqueue_scripts', array($this, 'enqueueStyle'), 10); |
|
301 | + add_action('wp_print_footer_scripts', array($this, 'enqueueScripts'), 10); |
|
302 | + } |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * builds list of active widgets then scans active sidebars looking for them |
|
309 | + * returns true is an EE widget is found in an active sidebar |
|
310 | + * Please Note: this does NOT mean that the sidebar or widget |
|
311 | + * is actually in use in a given template, as that is unfortunately not known |
|
312 | + * until a sidebar and it's widgets are actually loaded |
|
313 | + * |
|
314 | + * @return boolean |
|
315 | + */ |
|
316 | + private function espresso_widgets_in_active_sidebars() |
|
317 | + { |
|
318 | + $espresso_widgets = array(); |
|
319 | + foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
320 | + $id_base = EspressoWidget::getIdBase($widget_class); |
|
321 | + if (is_active_widget(false, false, $id_base)) { |
|
322 | + $espresso_widgets[] = $id_base; |
|
323 | + } |
|
324 | + } |
|
325 | + $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
326 | + foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) { |
|
327 | + if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
328 | + foreach ($sidebar_widgets as $sidebar_widget) { |
|
329 | + foreach ($espresso_widgets as $espresso_widget) { |
|
330 | + if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
331 | + return true; |
|
332 | + } |
|
333 | + } |
|
334 | + } |
|
335 | + } |
|
336 | + } |
|
337 | + return false; |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * header_meta_tag |
|
345 | + * |
|
346 | + * @access public |
|
347 | + * @return void |
|
348 | + */ |
|
349 | + public function header_meta_tag() |
|
350 | + { |
|
351 | + print( |
|
352 | + apply_filters( |
|
353 | + 'FHEE__EE_Front_Controller__header_meta_tag', |
|
354 | + '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
355 | + ); |
|
356 | + |
|
357 | + //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
358 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
359 | + //also exclude all critical pages from indexing |
|
360 | + if ( |
|
361 | + ( |
|
362 | + is_tax('espresso_event_type') |
|
363 | + && get_option( 'blog_public' ) !== '0' |
|
364 | + ) |
|
365 | + || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
366 | + ) { |
|
367 | + print( |
|
368 | + apply_filters( |
|
369 | + 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
370 | + '<meta name="robots" content="noindex,follow" />' . "\n" |
|
371 | + ) |
|
372 | + ); |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + |
|
378 | + /** |
|
379 | + * wp_print_scripts |
|
380 | + * |
|
381 | + * @return void |
|
382 | + */ |
|
383 | + public function wp_print_scripts() |
|
384 | + { |
|
385 | + global $post; |
|
386 | + if ( |
|
387 | + isset($post->EE_Event) |
|
388 | + && $post->EE_Event instanceof EE_Event |
|
389 | + && get_post_type() === 'espresso_events' |
|
390 | + && is_singular() |
|
391 | + ) { |
|
392 | + \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
393 | + } |
|
394 | + } |
|
395 | + |
|
396 | + |
|
397 | + |
|
398 | + public function enqueueStyle() |
|
399 | + { |
|
400 | + wp_enqueue_style('espresso_default'); |
|
401 | + wp_enqueue_style('espresso_custom_css'); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + |
|
406 | + |
|
407 | + /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
|
408 | 408 | |
409 | 409 | |
410 | 410 | |
@@ -415,108 +415,108 @@ discard block |
||
415 | 415 | // * @param $the_content |
416 | 416 | // * @return string |
417 | 417 | // */ |
418 | - // public function the_content( $the_content ) { |
|
419 | - // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
420 | - // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
421 | - // } |
|
422 | - // return $the_content; |
|
423 | - // } |
|
424 | - |
|
425 | - |
|
426 | - |
|
427 | - /*********************************************** WP_FOOTER ***********************************************/ |
|
428 | - |
|
429 | - |
|
430 | - |
|
431 | - public function enqueueScripts() |
|
432 | - { |
|
433 | - wp_enqueue_script('espresso_core'); |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * display_errors |
|
440 | - * |
|
441 | - * @access public |
|
442 | - * @return void |
|
443 | - * @throws DomainException |
|
444 | - */ |
|
445 | - public function display_errors() |
|
446 | - { |
|
447 | - static $shown_already = false; |
|
448 | - do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
449 | - if ( |
|
450 | - ! $shown_already |
|
451 | - && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
452 | - && is_main_query() |
|
453 | - && ! is_feed() |
|
454 | - && in_the_loop() |
|
455 | - && $this->Request_Handler->is_espresso_page() |
|
456 | - ) { |
|
457 | - echo EE_Error::get_notices(); |
|
458 | - $shown_already = true; |
|
459 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
460 | - } |
|
461 | - do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
462 | - } |
|
463 | - |
|
464 | - |
|
465 | - |
|
466 | - |
|
467 | - |
|
468 | - /*********************************************** UTILITIES ***********************************************/ |
|
469 | - /** |
|
470 | - * template_include |
|
471 | - * |
|
472 | - * @access public |
|
473 | - * @param string $template_include_path |
|
474 | - * @return string |
|
475 | - */ |
|
476 | - public function template_include($template_include_path = null) |
|
477 | - { |
|
478 | - if ($this->Request_Handler->is_espresso_page()) { |
|
479 | - $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
480 | - $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
481 | - $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
482 | - $this->_template = basename($this->_template_path); |
|
483 | - return $this->_template_path; |
|
484 | - } |
|
485 | - return $template_include_path; |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * get_selected_template |
|
491 | - * |
|
492 | - * @access public |
|
493 | - * @param bool $with_path |
|
494 | - * @return string |
|
495 | - */ |
|
496 | - public function get_selected_template($with_path = false) |
|
497 | - { |
|
498 | - return $with_path ? $this->_template_path : $this->_template; |
|
499 | - } |
|
500 | - |
|
501 | - |
|
502 | - |
|
503 | - /** |
|
504 | - * @deprecated 4.9.26 |
|
505 | - * @param string $shortcode_class |
|
506 | - * @param \WP $wp |
|
507 | - */ |
|
508 | - public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
509 | - { |
|
510 | - \EE_Error::doing_it_wrong( |
|
511 | - __METHOD__, |
|
512 | - __( |
|
513 | - 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
514 | - 'event_espresso' |
|
515 | - ), |
|
516 | - '4.9.26' |
|
517 | - ); |
|
518 | - $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
519 | - } |
|
418 | + // public function the_content( $the_content ) { |
|
419 | + // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
420 | + // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
421 | + // } |
|
422 | + // return $the_content; |
|
423 | + // } |
|
424 | + |
|
425 | + |
|
426 | + |
|
427 | + /*********************************************** WP_FOOTER ***********************************************/ |
|
428 | + |
|
429 | + |
|
430 | + |
|
431 | + public function enqueueScripts() |
|
432 | + { |
|
433 | + wp_enqueue_script('espresso_core'); |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * display_errors |
|
440 | + * |
|
441 | + * @access public |
|
442 | + * @return void |
|
443 | + * @throws DomainException |
|
444 | + */ |
|
445 | + public function display_errors() |
|
446 | + { |
|
447 | + static $shown_already = false; |
|
448 | + do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
449 | + if ( |
|
450 | + ! $shown_already |
|
451 | + && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
452 | + && is_main_query() |
|
453 | + && ! is_feed() |
|
454 | + && in_the_loop() |
|
455 | + && $this->Request_Handler->is_espresso_page() |
|
456 | + ) { |
|
457 | + echo EE_Error::get_notices(); |
|
458 | + $shown_already = true; |
|
459 | + EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
460 | + } |
|
461 | + do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
462 | + } |
|
463 | + |
|
464 | + |
|
465 | + |
|
466 | + |
|
467 | + |
|
468 | + /*********************************************** UTILITIES ***********************************************/ |
|
469 | + /** |
|
470 | + * template_include |
|
471 | + * |
|
472 | + * @access public |
|
473 | + * @param string $template_include_path |
|
474 | + * @return string |
|
475 | + */ |
|
476 | + public function template_include($template_include_path = null) |
|
477 | + { |
|
478 | + if ($this->Request_Handler->is_espresso_page()) { |
|
479 | + $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
480 | + $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
481 | + $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
482 | + $this->_template = basename($this->_template_path); |
|
483 | + return $this->_template_path; |
|
484 | + } |
|
485 | + return $template_include_path; |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * get_selected_template |
|
491 | + * |
|
492 | + * @access public |
|
493 | + * @param bool $with_path |
|
494 | + * @return string |
|
495 | + */ |
|
496 | + public function get_selected_template($with_path = false) |
|
497 | + { |
|
498 | + return $with_path ? $this->_template_path : $this->_template; |
|
499 | + } |
|
500 | + |
|
501 | + |
|
502 | + |
|
503 | + /** |
|
504 | + * @deprecated 4.9.26 |
|
505 | + * @param string $shortcode_class |
|
506 | + * @param \WP $wp |
|
507 | + */ |
|
508 | + public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
509 | + { |
|
510 | + \EE_Error::doing_it_wrong( |
|
511 | + __METHOD__, |
|
512 | + __( |
|
513 | + 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
514 | + 'event_espresso' |
|
515 | + ), |
|
516 | + '4.9.26' |
|
517 | + ); |
|
518 | + $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
519 | + } |
|
520 | 520 | |
521 | 521 | } |
522 | 522 | // End of file EE_Front_Controller.core.php |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | do_action('AHEE__EE_Front_Controller__construct__done', $this); |
98 | 98 | // for checking that browser cookies are enabled |
99 | 99 | if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
100 | - setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
100 | + setcookie('ee_cookie_test', uniqid('ect', true), time() + DAY_IN_SECONDS, '/'); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
@@ -289,14 +289,14 @@ discard block |
||
289 | 289 | public function templateRedirect() |
290 | 290 | { |
291 | 291 | global $wp_query; |
292 | - if (empty($wp_query->posts)){ |
|
292 | + if (empty($wp_query->posts)) { |
|
293 | 293 | return; |
294 | 294 | } |
295 | 295 | // if we already know this is an espresso page, then load assets |
296 | 296 | $load_assets = $this->Request_Handler->is_espresso_page(); |
297 | 297 | // if we are already loading assets then just move along, otherwise check for widgets |
298 | 298 | $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
299 | - if ( $load_assets){ |
|
299 | + if ($load_assets) { |
|
300 | 300 | add_action('wp_enqueue_scripts', array($this, 'enqueueStyle'), 10); |
301 | 301 | add_action('wp_print_footer_scripts', array($this, 'enqueueScripts'), 10); |
302 | 302 | } |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | print( |
352 | 352 | apply_filters( |
353 | 353 | 'FHEE__EE_Front_Controller__header_meta_tag', |
354 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
354 | + '<meta name="generator" content="Event Espresso Version '.EVENT_ESPRESSO_VERSION."\" />\n") |
|
355 | 355 | ); |
356 | 356 | |
357 | 357 | //let's exclude all event type taxonomy term archive pages from search engine indexing |
@@ -360,14 +360,14 @@ discard block |
||
360 | 360 | if ( |
361 | 361 | ( |
362 | 362 | is_tax('espresso_event_type') |
363 | - && get_option( 'blog_public' ) !== '0' |
|
363 | + && get_option('blog_public') !== '0' |
|
364 | 364 | ) |
365 | 365 | || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
366 | 366 | ) { |
367 | 367 | print( |
368 | 368 | apply_filters( |
369 | 369 | 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
370 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
370 | + '<meta name="robots" content="noindex,follow" />'."\n" |
|
371 | 371 | ) |
372 | 372 | ); |
373 | 373 | } |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | ) { |
457 | 457 | echo EE_Error::get_notices(); |
458 | 458 | $shown_already = true; |
459 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
459 | + EEH_Template::display_template(EE_TEMPLATES.'espresso-ajax-notices.template.php'); |
|
460 | 460 | } |
461 | 461 | do_action('AHEE__EE_Front_Controller__display_errors__end'); |
462 | 462 | } |