Completed
Branch BUG-10851-events-shortcode (1f397b)
by
unknown
11:46 queued 10s
created
espresso.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
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
 block discarded – undo
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.45.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.45.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
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoEventAttendees.php 2 patches
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -29,266 +29,266 @@
 block discarded – undo
29 29
 class EspressoEventAttendees extends EspressoShortcode
30 30
 {
31 31
 
32
-    private $query_params = array(
33
-        0 => array()
34
-    );
35
-
36
-    private $template_args = array(
37
-        'contacts'      => array(),
38
-        'event'         => null,
39
-        'datetime'      => null,
40
-        'ticket'        => null,
41
-    );
42
-
43
-    /**
44
-     * the actual shortcode tag that gets registered with WordPress
45
-     *
46
-     * @return string
47
-     */
48
-    public function getTag()
49
-    {
50
-        return 'ESPRESSO_EVENT_ATTENDEES';
51
-    }
52
-
53
-
54
-
55
-    /**
56
-     * the time in seconds to cache the results of the processShortcode() method
57
-     * 0 means the processShortcode() results will NOT be cached at all
58
-     *
59
-     * @return int
60
-     */
61
-    public function cacheExpiration()
62
-    {
63
-        return 0;
64
-    }
65
-
66
-
67
-
68
-    /**
69
-     * a place for adding any initialization code that needs to run prior to wp_header().
70
-     * this may be required for shortcodes that utilize a corresponding module,
71
-     * and need to enqueue assets for that module
72
-     *
73
-     * @return void
74
-     */
75
-    public function initializeShortcode()
76
-    {
77
-        $this->shortcodeHasBeenInitialized();
78
-    }
79
-
80
-
81
-
82
-    /**
83
-     * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event.
84
-     *  [ESPRESSO_EVENT_ATTENDEES]
85
-     *  - defaults to attendees for earliest active event, or earliest upcoming event.
86
-     *
87
-     *  [ESPRESSO_EVENT_ATTENDEES event_id=123]
88
-     *  - attendees for specific event.
89
-     *
90
-     *  [ESPRESSO_EVENT_ATTENDEES datetime_id=245]
91
-     *  - attendees for a specific datetime.
92
-     *
93
-     *  [ESPRESSO_EVENT_ATTENDEES ticket_id=123]
94
-     *  - attendees for a specific ticket.
95
-     *
96
-     *  [ESPRESSO_EVENT_ATTENDEES status=all]
97
-     *  - specific registration status (use status id) or all for all attendees regardless of status.
98
-     *  Note default is to only return approved attendees
99
-     *
100
-     *  [ESPRESSO_EVENT_ATTENDEES show_gravatar=true]
101
-     *  - default is to not return gravatar.  Otherwise if this is set then return gravatar for email address given.
102
-     *
103
-     *  [ESPRESSO_EVENT_ATTENDEES display_on_archives=true]
104
-     *  - default is to not display attendees list on archive pages.
105
-     *
106
-     * Note: because of the relationship between event_id, ticket_id, and datetime_id:
107
-     * If more than one of those params is included, then preference is given to the following:
108
-     *  - event_id is used whenever its present and any others are ignored.
109
-     *  - if no event_id then datetime is used whenever its present and any others are ignored.
110
-     *  - otherwise ticket_id is used if present.
111
-     *
112
-     * @param array $attributes
113
-     * @return string
114
-     * @throws EE_Error
115
-     */
116
-    public function processShortcode($attributes = array())
117
-    {
118
-        // grab attributes and merge with defaults
119
-        $attributes = $this->getAttributes((array)$attributes);
120
-        $archive = is_archive();
121
-        $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN);
122
-        // don't display on archives unless 'display_on_archives' is true
123
-        if($archive && ! $display_on_archives) {
124
-            return '';
125
-        }
126
-        // add attributes to template args
127
-        $this->template_args['show_gravatar'] = $attributes['show_gravatar'];
128
-        // add required objects: event, datetime, and ticket
129
-        $this->template_args['event'] = $this->getEventAndQueryParams($attributes);
130
-        $this->template_args['datetime'] = $this->getDatetimeAndQueryParams($attributes);
131
-        $this->template_args['ticket'] = $this->getTicketAndQueryParams($attributes);
132
-
133
-        // if any of the above objects is invalid or missing,
134
-        // then there was an invalid parameter or the shortcode was used incorrectly
135
-        // so when WP_DEBUG is set and true, we'll show a message,
136
-        // otherwise we'll just return an empty string.
137
-         if (
138
-            ! $this->template_args['event'] instanceof EE_Event
139
-            || empty($this->query_params[0])
140
-            || ($attributes['datetime_id'] && ! $this->template_args['datetime'] instanceof EE_Datetime)
141
-            || ($attributes['ticket_id'] && ! $this->template_args['ticket'] instanceof EE_Ticket)
142
-        ) {
143
-            if (WP_DEBUG) {
144
-                return '<div class="important-notice ee-attention">'
145
-                       . esc_html__('The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly.  Please double check the arguments you used for any typos.  In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.',
146
-                        'event_espresso')
147
-                       . '</div>';
148
-            }
149
-             return '';
150
-        }
151
-        $this->setAdditionalQueryParams($attributes);
152
-        //get contacts!
153
-        $this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params);
154
-        //all set let's load up the template and return.
155
-        return EEH_Template::locate_template(
156
-            'loop-espresso_event_attendees.php',
157
-            $this->template_args
158
-        );
159
-
160
-    }
161
-
162
-
163
-
164
-    /**
165
-     * merge incoming attributes with filtered defaults
166
-     *
167
-     * @param array $attributes
168
-     * @return array
169
-     */
170
-    private function getAttributes(array $attributes)
171
-    {
172
-        return (array) apply_filters(
173
-            'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts',
174
-            $attributes + array(
175
-                'event_id'            => null,
176
-                'datetime_id'         => null,
177
-                'ticket_id'           => null,
178
-                'status'              => EEM_Registration::status_id_approved,
179
-                'show_gravatar'       => false,
180
-                'display_on_archives' => false,
181
-            )
182
-        );
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * @param array $attributes
189
-     * @return EE_Event|null
190
-     * @throws EE_Error
191
-     */
192
-    private function getEventAndQueryParams(array $attributes){
193
-        if ( ! empty($attributes['event_id'])) {
194
-            $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']);
195
-            if ($event instanceof EE_Event) {
196
-                $this->query_params[0]['Registration.EVT_ID'] = $attributes['event_id'];
197
-                return $event;
198
-            }
199
-        }
200
-        if (is_espresso_event()) {
201
-            $event = EEH_Event_View::get_event();
202
-            if ($event instanceof EE_Event) {
203
-                $this->query_params[0]['Registration.EVT_ID'] = $event->ID();
204
-                return $event;
205
-            }
206
-        }
207
-        // one last shot...
208
-        // try getting the earliest active event
209
-        $events = EEM_Event::instance()->get_active_events(array(
210
-            'limit'    => 1,
211
-            'order_by' => array('Datetime.DTT_EVT_start' => 'ASC')
212
-        ));
213
-        //  if none then get the next upcoming
214
-        $events = empty($events)
215
-            ? EEM_Event::instance()->get_upcoming_events(array(
216
-                'limit'    => 1,
217
-                'order_by' => array('Datetime.DTT_EVT_start' => 'ASC')
218
-            ))
219
-            : $events;
220
-        $event = reset($events);
221
-        if ($event instanceof EE_Event) {
222
-            $this->query_params[0]['Registration.EVT_ID'] = $event->ID();
223
-            return $event;
224
-        }
225
-        return null;
226
-    }
227
-
228
-
229
-
230
-    /**
231
-     * @param array $attributes
232
-     * @return EE_Datetime|null
233
-     */
234
-    private function getDatetimeAndQueryParams(array $attributes)
235
-    {
236
-        if ( ! empty($attributes['datetime_id'])) {
237
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']);
238
-            if ($datetime instanceof EE_Datetime) {
239
-                $this->query_params[0]['Registration.Ticket.Datetime.DTT_ID'] = $attributes['datetime_id'];
240
-                $this->query_params['default_where_conditions'] = 'this_model_only';
241
-                if ( ! $this->template_args['event'] instanceof EE_Event) {
242
-                    $this->template_args['event'] = $datetime->event();
243
-                }
244
-                return $datetime;
245
-            }
246
-        }
247
-        return null;
248
-    }
249
-
250
-
251
-
252
-    /**
253
-     * @param array $attributes
254
-     * @return \EE_Base_Class|null
255
-     * @throws EE_Error
256
-     */
257
-    private function getTicketAndQueryParams(array $attributes)
258
-    {
259
-        if ( ! empty($attributes['ticket_id']) && empty($attributes['event_id']) && empty($attributes['datetime_id'])) {
260
-            $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']);
261
-            if ($ticket instanceof EE_Ticket) {
262
-                $this->query_params[0]['Registration.TKT_ID'] = $attributes['ticket_id'];
263
-                if ( ! $this->template_args['event'] instanceof EE_Event) {
264
-                    $this->template_args['event'] = $ticket->first_datetime() instanceof EE_Datetime
265
-                        ? $ticket->first_datetime()->event()
266
-                        : null;
267
-                }
268
-                return $ticket;
269
-            }
270
-        }
271
-        return null;
272
-    }
273
-
274
-
275
-
276
-    /**
277
-     * @param array $attributes
278
-     * @throws EE_Error
279
-     */
280
-    private function setAdditionalQueryParams(array $attributes)
281
-    {
282
-        $reg_status_array = EEM_Registration::reg_status_array();
283
-        if ($attributes['status'] !== 'all' && isset($reg_status_array[$attributes['status']])) {
284
-            $this->query_params[0]['Registration.STS_ID'] = $attributes['status'];
285
-        }
286
-        $this->query_params['group_by'] = array('ATT_ID');
287
-        $this->query_params['order_by'] = (array) apply_filters(
288
-            'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by',
289
-            array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC')
290
-        );
291
-    }
32
+	private $query_params = array(
33
+		0 => array()
34
+	);
35
+
36
+	private $template_args = array(
37
+		'contacts'      => array(),
38
+		'event'         => null,
39
+		'datetime'      => null,
40
+		'ticket'        => null,
41
+	);
42
+
43
+	/**
44
+	 * the actual shortcode tag that gets registered with WordPress
45
+	 *
46
+	 * @return string
47
+	 */
48
+	public function getTag()
49
+	{
50
+		return 'ESPRESSO_EVENT_ATTENDEES';
51
+	}
52
+
53
+
54
+
55
+	/**
56
+	 * the time in seconds to cache the results of the processShortcode() method
57
+	 * 0 means the processShortcode() results will NOT be cached at all
58
+	 *
59
+	 * @return int
60
+	 */
61
+	public function cacheExpiration()
62
+	{
63
+		return 0;
64
+	}
65
+
66
+
67
+
68
+	/**
69
+	 * a place for adding any initialization code that needs to run prior to wp_header().
70
+	 * this may be required for shortcodes that utilize a corresponding module,
71
+	 * and need to enqueue assets for that module
72
+	 *
73
+	 * @return void
74
+	 */
75
+	public function initializeShortcode()
76
+	{
77
+		$this->shortcodeHasBeenInitialized();
78
+	}
79
+
80
+
81
+
82
+	/**
83
+	 * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event.
84
+	 *  [ESPRESSO_EVENT_ATTENDEES]
85
+	 *  - defaults to attendees for earliest active event, or earliest upcoming event.
86
+	 *
87
+	 *  [ESPRESSO_EVENT_ATTENDEES event_id=123]
88
+	 *  - attendees for specific event.
89
+	 *
90
+	 *  [ESPRESSO_EVENT_ATTENDEES datetime_id=245]
91
+	 *  - attendees for a specific datetime.
92
+	 *
93
+	 *  [ESPRESSO_EVENT_ATTENDEES ticket_id=123]
94
+	 *  - attendees for a specific ticket.
95
+	 *
96
+	 *  [ESPRESSO_EVENT_ATTENDEES status=all]
97
+	 *  - specific registration status (use status id) or all for all attendees regardless of status.
98
+	 *  Note default is to only return approved attendees
99
+	 *
100
+	 *  [ESPRESSO_EVENT_ATTENDEES show_gravatar=true]
101
+	 *  - default is to not return gravatar.  Otherwise if this is set then return gravatar for email address given.
102
+	 *
103
+	 *  [ESPRESSO_EVENT_ATTENDEES display_on_archives=true]
104
+	 *  - default is to not display attendees list on archive pages.
105
+	 *
106
+	 * Note: because of the relationship between event_id, ticket_id, and datetime_id:
107
+	 * If more than one of those params is included, then preference is given to the following:
108
+	 *  - event_id is used whenever its present and any others are ignored.
109
+	 *  - if no event_id then datetime is used whenever its present and any others are ignored.
110
+	 *  - otherwise ticket_id is used if present.
111
+	 *
112
+	 * @param array $attributes
113
+	 * @return string
114
+	 * @throws EE_Error
115
+	 */
116
+	public function processShortcode($attributes = array())
117
+	{
118
+		// grab attributes and merge with defaults
119
+		$attributes = $this->getAttributes((array)$attributes);
120
+		$archive = is_archive();
121
+		$display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN);
122
+		// don't display on archives unless 'display_on_archives' is true
123
+		if($archive && ! $display_on_archives) {
124
+			return '';
125
+		}
126
+		// add attributes to template args
127
+		$this->template_args['show_gravatar'] = $attributes['show_gravatar'];
128
+		// add required objects: event, datetime, and ticket
129
+		$this->template_args['event'] = $this->getEventAndQueryParams($attributes);
130
+		$this->template_args['datetime'] = $this->getDatetimeAndQueryParams($attributes);
131
+		$this->template_args['ticket'] = $this->getTicketAndQueryParams($attributes);
132
+
133
+		// if any of the above objects is invalid or missing,
134
+		// then there was an invalid parameter or the shortcode was used incorrectly
135
+		// so when WP_DEBUG is set and true, we'll show a message,
136
+		// otherwise we'll just return an empty string.
137
+		 if (
138
+			! $this->template_args['event'] instanceof EE_Event
139
+			|| empty($this->query_params[0])
140
+			|| ($attributes['datetime_id'] && ! $this->template_args['datetime'] instanceof EE_Datetime)
141
+			|| ($attributes['ticket_id'] && ! $this->template_args['ticket'] instanceof EE_Ticket)
142
+		) {
143
+			if (WP_DEBUG) {
144
+				return '<div class="important-notice ee-attention">'
145
+					   . esc_html__('The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly.  Please double check the arguments you used for any typos.  In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.',
146
+						'event_espresso')
147
+					   . '</div>';
148
+			}
149
+			 return '';
150
+		}
151
+		$this->setAdditionalQueryParams($attributes);
152
+		//get contacts!
153
+		$this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params);
154
+		//all set let's load up the template and return.
155
+		return EEH_Template::locate_template(
156
+			'loop-espresso_event_attendees.php',
157
+			$this->template_args
158
+		);
159
+
160
+	}
161
+
162
+
163
+
164
+	/**
165
+	 * merge incoming attributes with filtered defaults
166
+	 *
167
+	 * @param array $attributes
168
+	 * @return array
169
+	 */
170
+	private function getAttributes(array $attributes)
171
+	{
172
+		return (array) apply_filters(
173
+			'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts',
174
+			$attributes + array(
175
+				'event_id'            => null,
176
+				'datetime_id'         => null,
177
+				'ticket_id'           => null,
178
+				'status'              => EEM_Registration::status_id_approved,
179
+				'show_gravatar'       => false,
180
+				'display_on_archives' => false,
181
+			)
182
+		);
183
+	}
184
+
185
+
186
+
187
+	/**
188
+	 * @param array $attributes
189
+	 * @return EE_Event|null
190
+	 * @throws EE_Error
191
+	 */
192
+	private function getEventAndQueryParams(array $attributes){
193
+		if ( ! empty($attributes['event_id'])) {
194
+			$event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']);
195
+			if ($event instanceof EE_Event) {
196
+				$this->query_params[0]['Registration.EVT_ID'] = $attributes['event_id'];
197
+				return $event;
198
+			}
199
+		}
200
+		if (is_espresso_event()) {
201
+			$event = EEH_Event_View::get_event();
202
+			if ($event instanceof EE_Event) {
203
+				$this->query_params[0]['Registration.EVT_ID'] = $event->ID();
204
+				return $event;
205
+			}
206
+		}
207
+		// one last shot...
208
+		// try getting the earliest active event
209
+		$events = EEM_Event::instance()->get_active_events(array(
210
+			'limit'    => 1,
211
+			'order_by' => array('Datetime.DTT_EVT_start' => 'ASC')
212
+		));
213
+		//  if none then get the next upcoming
214
+		$events = empty($events)
215
+			? EEM_Event::instance()->get_upcoming_events(array(
216
+				'limit'    => 1,
217
+				'order_by' => array('Datetime.DTT_EVT_start' => 'ASC')
218
+			))
219
+			: $events;
220
+		$event = reset($events);
221
+		if ($event instanceof EE_Event) {
222
+			$this->query_params[0]['Registration.EVT_ID'] = $event->ID();
223
+			return $event;
224
+		}
225
+		return null;
226
+	}
227
+
228
+
229
+
230
+	/**
231
+	 * @param array $attributes
232
+	 * @return EE_Datetime|null
233
+	 */
234
+	private function getDatetimeAndQueryParams(array $attributes)
235
+	{
236
+		if ( ! empty($attributes['datetime_id'])) {
237
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']);
238
+			if ($datetime instanceof EE_Datetime) {
239
+				$this->query_params[0]['Registration.Ticket.Datetime.DTT_ID'] = $attributes['datetime_id'];
240
+				$this->query_params['default_where_conditions'] = 'this_model_only';
241
+				if ( ! $this->template_args['event'] instanceof EE_Event) {
242
+					$this->template_args['event'] = $datetime->event();
243
+				}
244
+				return $datetime;
245
+			}
246
+		}
247
+		return null;
248
+	}
249
+
250
+
251
+
252
+	/**
253
+	 * @param array $attributes
254
+	 * @return \EE_Base_Class|null
255
+	 * @throws EE_Error
256
+	 */
257
+	private function getTicketAndQueryParams(array $attributes)
258
+	{
259
+		if ( ! empty($attributes['ticket_id']) && empty($attributes['event_id']) && empty($attributes['datetime_id'])) {
260
+			$ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']);
261
+			if ($ticket instanceof EE_Ticket) {
262
+				$this->query_params[0]['Registration.TKT_ID'] = $attributes['ticket_id'];
263
+				if ( ! $this->template_args['event'] instanceof EE_Event) {
264
+					$this->template_args['event'] = $ticket->first_datetime() instanceof EE_Datetime
265
+						? $ticket->first_datetime()->event()
266
+						: null;
267
+				}
268
+				return $ticket;
269
+			}
270
+		}
271
+		return null;
272
+	}
273
+
274
+
275
+
276
+	/**
277
+	 * @param array $attributes
278
+	 * @throws EE_Error
279
+	 */
280
+	private function setAdditionalQueryParams(array $attributes)
281
+	{
282
+		$reg_status_array = EEM_Registration::reg_status_array();
283
+		if ($attributes['status'] !== 'all' && isset($reg_status_array[$attributes['status']])) {
284
+			$this->query_params[0]['Registration.STS_ID'] = $attributes['status'];
285
+		}
286
+		$this->query_params['group_by'] = array('ATT_ID');
287
+		$this->query_params['order_by'] = (array) apply_filters(
288
+			'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by',
289
+			array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC')
290
+		);
291
+	}
292 292
 
293 293
 
294 294
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -116,11 +116,11 @@  discard block
 block discarded – undo
116 116
     public function processShortcode($attributes = array())
117 117
     {
118 118
         // grab attributes and merge with defaults
119
-        $attributes = $this->getAttributes((array)$attributes);
119
+        $attributes = $this->getAttributes((array) $attributes);
120 120
         $archive = is_archive();
121 121
         $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN);
122 122
         // don't display on archives unless 'display_on_archives' is true
123
-        if($archive && ! $display_on_archives) {
123
+        if ($archive && ! $display_on_archives) {
124 124
             return '';
125 125
         }
126 126
         // add attributes to template args
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
      * @return EE_Event|null
190 190
      * @throws EE_Error
191 191
      */
192
-    private function getEventAndQueryParams(array $attributes){
192
+    private function getEventAndQueryParams(array $attributes) {
193 193
         if ( ! empty($attributes['event_id'])) {
194 194
             $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']);
195 195
             if ($event instanceof EE_Event) {
Please login to merge, or discard this patch.
core/services/shortcodes/EspressoShortcode.php 1 patch
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -23,230 +23,230 @@
 block discarded – undo
23 23
 abstract class EspressoShortcode implements ShortcodeInterface
24 24
 {
25 25
 
26
-    /**
27
-     * transient prefix
28
-     *
29
-     * @type string
30
-     */
31
-    const CACHE_TRANSIENT_PREFIX = 'ee_sc_';
32
-
33
-    /**
34
-     * @var PostRelatedCacheManager $cache_manager
35
-     */
36
-    private $cache_manager;
37
-
38
-    /**
39
-     * true if ShortcodeInterface::initializeShortcode() has been called
40
-     * if false, then that will get called before processing
41
-     *
42
-     * @var boolean $initialized
43
-     */
44
-    private $initialized = false;
45
-
46
-
47
-
48
-    /**
49
-     * EspressoShortcode constructor
50
-     *
51
-     * @param PostRelatedCacheManager $cache_manager
52
-     */
53
-    public function __construct(PostRelatedCacheManager $cache_manager)
54
-    {
55
-        $this->cache_manager = $cache_manager;
56
-    }
57
-
58
-
59
-
60
-    /**
61
-     * @return void
62
-     */
63
-    public function shortcodeHasBeenInitialized()
64
-    {
65
-        $this->initialized = true;
66
-    }
67
-
68
-
69
-
70
-    /**
71
-     * enqueues scripts then processes the shortcode
72
-     *
73
-     * @param array $attributes
74
-     * @return string
75
-     * @throws EE_Error
76
-     */
77
-    final public function processShortcodeCallback($attributes = array())
78
-    {
79
-        if ($this instanceof EnqueueAssetsInterface) {
80
-            if (is_admin()) {
81
-                $this->enqueueAdminScripts();
82
-            } else {
83
-                $this->enqueueScripts();
84
-            }
85
-        }
86
-        return $this->shortcodeContent(
87
-            $this->sanitizeAttributes((array)$attributes)
88
-        );
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * If shortcode caching is enabled for the shortcode,
95
-     * and cached results exist, then that will be returned
96
-     * else new content will be generated.
97
-     * If caching is enabled, then the new content will be cached for later.
98
-     *
99
-     * @param array $attributes
100
-     * @return mixed|string
101
-     * @throws EE_Error
102
-     */
103
-    private function shortcodeContent(array $attributes)
104
-    {
105
-        $shortcode = $this;
106
-        $post_ID = $this->currentPostID();
107
-        // something like "SC_EVENTS-123"
108
-        $cache_ID = $this->shortcodeCacheID($post_ID);
109
-        $this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID);
110
-        return $this->cache_manager->get(
111
-            $cache_ID,
112
-            // serialized attributes
113
-            wp_json_encode($attributes),
114
-            // Closure for generating content if cache is expired
115
-            function () use ($shortcode, $attributes) {
116
-                if($shortcode->initialized() === false){
117
-                    $shortcode->initializeShortcode();
118
-                }
119
-                return $shortcode->processShortcode($attributes);
120
-            },
121
-            // filterable cache expiration set by each shortcode
122
-            apply_filters(
123
-                'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration',
124
-                $this->cacheExpiration(),
125
-                $this->getTag(),
126
-                $this
127
-            )
128
-        );
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     * @return int
135
-     * @throws EE_Error
136
-     */
137
-    private function currentPostID()
138
-    {
139
-        // try to get EE_Event any way we can
140
-        $event = EEH_Event_View::get_event();
141
-        // then get some kind of ID
142
-        if ($event instanceof EE_Event) {
143
-            return $event->ID();
144
-        }
145
-        global $post;
146
-        if ($post instanceof WP_Post) {
147
-            return $post->ID;
148
-        }
149
-        return 0;
150
-    }
151
-
152
-
153
-
154
-    /**
155
-     * @param int $post_ID
156
-     * @return string
157
-     * @throws EE_Error
158
-     */
159
-    private function shortcodeCacheID($post_ID)
160
-    {
161
-        $tag = str_replace('ESPRESSO_', '', $this->getTag());
162
-        return "SC_{$tag}-{$post_ID}";
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * array for defining custom attribute sanitization callbacks,
169
-     * where keys match keys in your attributes array,
170
-     * and values represent the sanitization function you wish to be applied to that attribute.
171
-     * So for example, if you had an integer attribute named "event_id"
172
-     * that you wanted to be sanitized using absint(),
173
-     * then you would return the following:
174
-     *      array('event_id' => 'absint')
175
-     * Entering 'skip_sanitization' for the callback value
176
-     * means that no sanitization will be applied
177
-     * on the assumption that the attribute
178
-     * will be sanitized at some point... right?
179
-     * You wouldn't pass around unsanitized attributes would you?
180
-     * That would be very Tom Foolery of you!!!
181
-     *
182
-     * @return array
183
-     */
184
-    protected function customAttributeSanitizationMap()
185
-    {
186
-        return array();
187
-    }
188
-
189
-
190
-
191
-    /**
192
-     * Performs basic sanitization on shortcode attributes
193
-     * Since incoming attributes from the shortcode usage in the WP editor will all be strings,
194
-     * most attributes will by default be sanitized using the sanitize_text_field() function.
195
-     * This can be overridden using the customAttributeSanitizationMap() method (see above),
196
-     * all other attributes would be sanitized using the defaults in the switch statement below
197
-     *
198
-     * @param array $attributes
199
-     * @return array
200
-     */
201
-    private function sanitizeAttributes(array $attributes)
202
-    {
203
-        $custom_sanitization = $this->customAttributeSanitizationMap();
204
-        foreach ($attributes as $key => $value) {
205
-            // is a custom sanitization callback specified ?
206
-            if (isset($custom_sanitization[$key])) {
207
-                $callback = $custom_sanitization[$key];
208
-                if ($callback === 'skip_sanitization') {
209
-                    $attributes[$key] = $value;
210
-                    continue;
211
-                }
212
-                if (function_exists($callback)) {
213
-                    $attributes[$key] = $callback($value);
214
-                    continue;
215
-                }
216
-            }
217
-            switch (true) {
218
-                case $value === null :
219
-                case is_int($value) :
220
-                case is_float($value) :
221
-                    // typical booleans
222
-                case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) :
223
-                    $attributes[$key] = $value;
224
-                    break;
225
-                case is_string($value) :
226
-                    $attributes[$key] = sanitize_text_field($value);
227
-                    break;
228
-                case is_array($value) :
229
-                    $attributes[$key] = $this->sanitizeAttributes($value);
230
-                    break;
231
-                default :
232
-                    // only remaining data types are Object and Resource
233
-                    // which are not allowed as shortcode attributes
234
-                    $attributes[$key] = null;
235
-                    break;
236
-            }
237
-        }
238
-        return $attributes;
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * Returns whether or not this shortcode has been initialized
245
-     * @return boolean
246
-     */
247
-    public function initialized(){
248
-        return $this->initialized;
249
-    }
26
+	/**
27
+	 * transient prefix
28
+	 *
29
+	 * @type string
30
+	 */
31
+	const CACHE_TRANSIENT_PREFIX = 'ee_sc_';
32
+
33
+	/**
34
+	 * @var PostRelatedCacheManager $cache_manager
35
+	 */
36
+	private $cache_manager;
37
+
38
+	/**
39
+	 * true if ShortcodeInterface::initializeShortcode() has been called
40
+	 * if false, then that will get called before processing
41
+	 *
42
+	 * @var boolean $initialized
43
+	 */
44
+	private $initialized = false;
45
+
46
+
47
+
48
+	/**
49
+	 * EspressoShortcode constructor
50
+	 *
51
+	 * @param PostRelatedCacheManager $cache_manager
52
+	 */
53
+	public function __construct(PostRelatedCacheManager $cache_manager)
54
+	{
55
+		$this->cache_manager = $cache_manager;
56
+	}
57
+
58
+
59
+
60
+	/**
61
+	 * @return void
62
+	 */
63
+	public function shortcodeHasBeenInitialized()
64
+	{
65
+		$this->initialized = true;
66
+	}
67
+
68
+
69
+
70
+	/**
71
+	 * enqueues scripts then processes the shortcode
72
+	 *
73
+	 * @param array $attributes
74
+	 * @return string
75
+	 * @throws EE_Error
76
+	 */
77
+	final public function processShortcodeCallback($attributes = array())
78
+	{
79
+		if ($this instanceof EnqueueAssetsInterface) {
80
+			if (is_admin()) {
81
+				$this->enqueueAdminScripts();
82
+			} else {
83
+				$this->enqueueScripts();
84
+			}
85
+		}
86
+		return $this->shortcodeContent(
87
+			$this->sanitizeAttributes((array)$attributes)
88
+		);
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * If shortcode caching is enabled for the shortcode,
95
+	 * and cached results exist, then that will be returned
96
+	 * else new content will be generated.
97
+	 * If caching is enabled, then the new content will be cached for later.
98
+	 *
99
+	 * @param array $attributes
100
+	 * @return mixed|string
101
+	 * @throws EE_Error
102
+	 */
103
+	private function shortcodeContent(array $attributes)
104
+	{
105
+		$shortcode = $this;
106
+		$post_ID = $this->currentPostID();
107
+		// something like "SC_EVENTS-123"
108
+		$cache_ID = $this->shortcodeCacheID($post_ID);
109
+		$this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID);
110
+		return $this->cache_manager->get(
111
+			$cache_ID,
112
+			// serialized attributes
113
+			wp_json_encode($attributes),
114
+			// Closure for generating content if cache is expired
115
+			function () use ($shortcode, $attributes) {
116
+				if($shortcode->initialized() === false){
117
+					$shortcode->initializeShortcode();
118
+				}
119
+				return $shortcode->processShortcode($attributes);
120
+			},
121
+			// filterable cache expiration set by each shortcode
122
+			apply_filters(
123
+				'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration',
124
+				$this->cacheExpiration(),
125
+				$this->getTag(),
126
+				$this
127
+			)
128
+		);
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 * @return int
135
+	 * @throws EE_Error
136
+	 */
137
+	private function currentPostID()
138
+	{
139
+		// try to get EE_Event any way we can
140
+		$event = EEH_Event_View::get_event();
141
+		// then get some kind of ID
142
+		if ($event instanceof EE_Event) {
143
+			return $event->ID();
144
+		}
145
+		global $post;
146
+		if ($post instanceof WP_Post) {
147
+			return $post->ID;
148
+		}
149
+		return 0;
150
+	}
151
+
152
+
153
+
154
+	/**
155
+	 * @param int $post_ID
156
+	 * @return string
157
+	 * @throws EE_Error
158
+	 */
159
+	private function shortcodeCacheID($post_ID)
160
+	{
161
+		$tag = str_replace('ESPRESSO_', '', $this->getTag());
162
+		return "SC_{$tag}-{$post_ID}";
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * array for defining custom attribute sanitization callbacks,
169
+	 * where keys match keys in your attributes array,
170
+	 * and values represent the sanitization function you wish to be applied to that attribute.
171
+	 * So for example, if you had an integer attribute named "event_id"
172
+	 * that you wanted to be sanitized using absint(),
173
+	 * then you would return the following:
174
+	 *      array('event_id' => 'absint')
175
+	 * Entering 'skip_sanitization' for the callback value
176
+	 * means that no sanitization will be applied
177
+	 * on the assumption that the attribute
178
+	 * will be sanitized at some point... right?
179
+	 * You wouldn't pass around unsanitized attributes would you?
180
+	 * That would be very Tom Foolery of you!!!
181
+	 *
182
+	 * @return array
183
+	 */
184
+	protected function customAttributeSanitizationMap()
185
+	{
186
+		return array();
187
+	}
188
+
189
+
190
+
191
+	/**
192
+	 * Performs basic sanitization on shortcode attributes
193
+	 * Since incoming attributes from the shortcode usage in the WP editor will all be strings,
194
+	 * most attributes will by default be sanitized using the sanitize_text_field() function.
195
+	 * This can be overridden using the customAttributeSanitizationMap() method (see above),
196
+	 * all other attributes would be sanitized using the defaults in the switch statement below
197
+	 *
198
+	 * @param array $attributes
199
+	 * @return array
200
+	 */
201
+	private function sanitizeAttributes(array $attributes)
202
+	{
203
+		$custom_sanitization = $this->customAttributeSanitizationMap();
204
+		foreach ($attributes as $key => $value) {
205
+			// is a custom sanitization callback specified ?
206
+			if (isset($custom_sanitization[$key])) {
207
+				$callback = $custom_sanitization[$key];
208
+				if ($callback === 'skip_sanitization') {
209
+					$attributes[$key] = $value;
210
+					continue;
211
+				}
212
+				if (function_exists($callback)) {
213
+					$attributes[$key] = $callback($value);
214
+					continue;
215
+				}
216
+			}
217
+			switch (true) {
218
+				case $value === null :
219
+				case is_int($value) :
220
+				case is_float($value) :
221
+					// typical booleans
222
+				case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) :
223
+					$attributes[$key] = $value;
224
+					break;
225
+				case is_string($value) :
226
+					$attributes[$key] = sanitize_text_field($value);
227
+					break;
228
+				case is_array($value) :
229
+					$attributes[$key] = $this->sanitizeAttributes($value);
230
+					break;
231
+				default :
232
+					// only remaining data types are Object and Resource
233
+					// which are not allowed as shortcode attributes
234
+					$attributes[$key] = null;
235
+					break;
236
+			}
237
+		}
238
+		return $attributes;
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * Returns whether or not this shortcode has been initialized
245
+	 * @return boolean
246
+	 */
247
+	public function initialized(){
248
+		return $this->initialized;
249
+	}
250 250
 
251 251
 
252 252
 
Please login to merge, or discard this patch.