Completed
Branch BUG/shortcodes-in-ajax-request... (8e7f9f)
by
unknown
59:21 queued 44:38
created
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
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.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.64.rc.000');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.64.rc.000');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.
core/services/assets/Registry.php 1 patch
Indentation   +573 added lines, -573 removed lines patch added patch discarded remove patch
@@ -23,584 +23,584 @@
 block discarded – undo
23 23
 class Registry
24 24
 {
25 25
 
26
-    const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
27
-
28
-    /**
29
-     * @var AssetCollection $assets
30
-     */
31
-    protected $assets;
32
-
33
-    /**
34
-     * @var I18nRegistry
35
-     */
36
-    private $i18n_registry;
37
-
38
-    /**
39
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
40
-     *
41
-     * @var array
42
-     */
43
-    protected $jsdata = array();
44
-
45
-    /**
46
-     * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
47
-     * page source.
48
-     *
49
-     * @var array
50
-     */
51
-    private $script_handles_with_data = array();
52
-
53
-    /**
54
-     * Holds the manifest data obtained from registered manifest files.
55
-     * Manifests are maps of asset chunk name to actual built asset file names.
56
-     * Shape of this array is:
57
-     * array(
58
-     *  'some_namespace_slug' => array(
59
-     *      'some_chunk_name' => array(
60
-     *          'js' => 'filename.js'
61
-     *          'css' => 'filename.js'
62
-     *      ),
63
-     *      'url_base' => 'https://baseurl.com/to/assets
64
-     *  )
65
-     * )
66
-     *
67
-     * @var array
68
-     */
69
-    private $manifest_data = array();
70
-
71
-
72
-    /**
73
-     * Registry constructor.
74
-     * Hooking into WP actions for script registry.
75
-     *
76
-     * @param AssetCollection $assets
77
-     * @param I18nRegistry    $i18n_registry
78
-     */
79
-    public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
80
-    {
81
-        $this->assets = $assets;
82
-        $this->i18n_registry = $i18n_registry;
83
-        add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
84
-        add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
85
-        add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
86
-        add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
87
-        add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4);
88
-        add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4);
89
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
90
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
91
-    }
92
-
93
-
94
-    /**
95
-     * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
96
-     * translation handling.
97
-     *
98
-     * @return I18nRegistry
99
-     */
100
-    public function getI18nRegistry()
101
-    {
102
-        return $this->i18n_registry;
103
-    }
104
-
105
-
106
-    /**
107
-     * Callback for the wp_enqueue_scripts actions used to register assets.
108
-     *
109
-     * @since 4.9.62.p
110
-     * @throws Exception
111
-     */
112
-    public function registerScriptsAndStyles()
113
-    {
114
-        try {
115
-            $this->registerScripts($this->assets->getJavascriptAssets());
116
-            $this->registerStyles($this->assets->getStylesheetAssets());
117
-        } catch (Exception $exception) {
118
-            new ExceptionStackTraceDisplay($exception);
119
-        }
120
-    }
121
-
122
-
123
-    /**
124
-     * Registers JS assets with WP core
125
-     *
126
-     * @since 4.9.62.p
127
-     * @param JavascriptAsset[] $scripts
128
-     * @throws AssetRegistrationException
129
-     * @throws InvalidDataTypeException
130
-     */
131
-    public function registerScripts(array $scripts)
132
-    {
133
-        foreach ($scripts as $script) {
134
-            // skip to next script if this has already been done
135
-            if ($script->isRegistered()) {
136
-                continue;
137
-            }
138
-            do_action(
139
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
140
-                $script
141
-            );
142
-            $registered = wp_register_script(
143
-                $script->handle(),
144
-                $script->source(),
145
-                $script->dependencies(),
146
-                $script->version(),
147
-                $script->loadInFooter()
148
-            );
149
-            if (! $registered && $this->debug()) {
150
-                throw new AssetRegistrationException($script->handle());
151
-            }
152
-            $script->setRegistered($registered);
153
-            if ($script->requiresTranslation()) {
154
-                $this->registerTranslation($script->handle());
155
-            }
156
-            do_action(
157
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
158
-                $script
159
-            );
160
-        }
161
-    }
162
-
163
-
164
-    /**
165
-     * Registers CSS assets with WP core
166
-     *
167
-     * @since 4.9.62.p
168
-     * @param StylesheetAsset[] $styles
169
-     * @throws InvalidDataTypeException
170
-     */
171
-    public function registerStyles(array $styles)
172
-    {
173
-        foreach ($styles as $style) {
174
-            // skip to next style if this has already been done
175
-            if ($style->isRegistered()) {
176
-                continue;
177
-            }
178
-            do_action(
179
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
180
-                $style
181
-            );
182
-            wp_register_style(
183
-                $style->handle(),
184
-                $style->source(),
185
-                $style->dependencies(),
186
-                $style->version(),
187
-                $style->media()
188
-            );
189
-            $style->setRegistered();
190
-            do_action(
191
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
192
-                $style
193
-            );
194
-        }
195
-    }
196
-
197
-
198
-    /**
199
-     * Call back for the script print in frontend and backend.
200
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
201
-     *
202
-     * @since 4.9.31.rc.015
203
-     */
204
-    public function enqueueData()
205
-    {
206
-        $this->removeAlreadyRegisteredDataForScriptHandles();
207
-        wp_add_inline_script(
208
-            'eejs-core',
209
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
210
-            'before'
211
-        );
212
-        $scripts = $this->assets->getJavascriptAssetsWithData();
213
-        foreach ($scripts as $script) {
214
-            $this->addRegisteredScriptHandlesWithData($script->handle());
215
-            if ($script->hasInlineDataCallback()) {
216
-                $localize = $script->inlineDataCallback();
217
-                $localize();
218
-            }
219
-        }
220
-    }
221
-
222
-
223
-    /**
224
-     * Used to add data to eejs.data object.
225
-     * Note:  Overriding existing data is not allowed.
226
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
227
-     * If the data you add is something like this:
228
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
229
-     * It will be exposed in the page source as:
230
-     *  eejs.data.my_plugin_data.foo == gar
231
-     *
232
-     * @param string       $key   Key used to access your data
233
-     * @param string|array $value Value to attach to key
234
-     * @throws InvalidArgumentException
235
-     */
236
-    public function addData($key, $value)
237
-    {
238
-        if ($this->verifyDataNotExisting($key)) {
239
-            $this->jsdata[ $key ] = $value;
240
-        }
241
-    }
242
-
243
-
244
-    /**
245
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
246
-     * elements in an array.
247
-     * When you use this method, the value you include will be appended to the end of an array on $key.
248
-     * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
249
-     * object like this, eejs.data.test = [ my_data,
250
-     * ]
251
-     * If there has already been a scalar value attached to the data object given key, then
252
-     * this will throw an exception.
253
-     *
254
-     * @param string       $key   Key to attach data to.
255
-     * @param string|array $value Value being registered.
256
-     * @throws InvalidArgumentException
257
-     */
258
-    public function pushData($key, $value)
259
-    {
260
-        if (isset($this->jsdata[ $key ])
261
-            && ! is_array($this->jsdata[ $key ])
262
-        ) {
263
-            if (! $this->debug()) {
264
-                return;
265
-            }
266
-            throw new InvalidArgumentException(
267
-                sprintf(
268
-                    __(
269
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
26
+	const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
27
+
28
+	/**
29
+	 * @var AssetCollection $assets
30
+	 */
31
+	protected $assets;
32
+
33
+	/**
34
+	 * @var I18nRegistry
35
+	 */
36
+	private $i18n_registry;
37
+
38
+	/**
39
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
40
+	 *
41
+	 * @var array
42
+	 */
43
+	protected $jsdata = array();
44
+
45
+	/**
46
+	 * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
47
+	 * page source.
48
+	 *
49
+	 * @var array
50
+	 */
51
+	private $script_handles_with_data = array();
52
+
53
+	/**
54
+	 * Holds the manifest data obtained from registered manifest files.
55
+	 * Manifests are maps of asset chunk name to actual built asset file names.
56
+	 * Shape of this array is:
57
+	 * array(
58
+	 *  'some_namespace_slug' => array(
59
+	 *      'some_chunk_name' => array(
60
+	 *          'js' => 'filename.js'
61
+	 *          'css' => 'filename.js'
62
+	 *      ),
63
+	 *      'url_base' => 'https://baseurl.com/to/assets
64
+	 *  )
65
+	 * )
66
+	 *
67
+	 * @var array
68
+	 */
69
+	private $manifest_data = array();
70
+
71
+
72
+	/**
73
+	 * Registry constructor.
74
+	 * Hooking into WP actions for script registry.
75
+	 *
76
+	 * @param AssetCollection $assets
77
+	 * @param I18nRegistry    $i18n_registry
78
+	 */
79
+	public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
80
+	{
81
+		$this->assets = $assets;
82
+		$this->i18n_registry = $i18n_registry;
83
+		add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
84
+		add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
85
+		add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
86
+		add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
87
+		add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4);
88
+		add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4);
89
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
90
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
91
+	}
92
+
93
+
94
+	/**
95
+	 * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
96
+	 * translation handling.
97
+	 *
98
+	 * @return I18nRegistry
99
+	 */
100
+	public function getI18nRegistry()
101
+	{
102
+		return $this->i18n_registry;
103
+	}
104
+
105
+
106
+	/**
107
+	 * Callback for the wp_enqueue_scripts actions used to register assets.
108
+	 *
109
+	 * @since 4.9.62.p
110
+	 * @throws Exception
111
+	 */
112
+	public function registerScriptsAndStyles()
113
+	{
114
+		try {
115
+			$this->registerScripts($this->assets->getJavascriptAssets());
116
+			$this->registerStyles($this->assets->getStylesheetAssets());
117
+		} catch (Exception $exception) {
118
+			new ExceptionStackTraceDisplay($exception);
119
+		}
120
+	}
121
+
122
+
123
+	/**
124
+	 * Registers JS assets with WP core
125
+	 *
126
+	 * @since 4.9.62.p
127
+	 * @param JavascriptAsset[] $scripts
128
+	 * @throws AssetRegistrationException
129
+	 * @throws InvalidDataTypeException
130
+	 */
131
+	public function registerScripts(array $scripts)
132
+	{
133
+		foreach ($scripts as $script) {
134
+			// skip to next script if this has already been done
135
+			if ($script->isRegistered()) {
136
+				continue;
137
+			}
138
+			do_action(
139
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
140
+				$script
141
+			);
142
+			$registered = wp_register_script(
143
+				$script->handle(),
144
+				$script->source(),
145
+				$script->dependencies(),
146
+				$script->version(),
147
+				$script->loadInFooter()
148
+			);
149
+			if (! $registered && $this->debug()) {
150
+				throw new AssetRegistrationException($script->handle());
151
+			}
152
+			$script->setRegistered($registered);
153
+			if ($script->requiresTranslation()) {
154
+				$this->registerTranslation($script->handle());
155
+			}
156
+			do_action(
157
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
158
+				$script
159
+			);
160
+		}
161
+	}
162
+
163
+
164
+	/**
165
+	 * Registers CSS assets with WP core
166
+	 *
167
+	 * @since 4.9.62.p
168
+	 * @param StylesheetAsset[] $styles
169
+	 * @throws InvalidDataTypeException
170
+	 */
171
+	public function registerStyles(array $styles)
172
+	{
173
+		foreach ($styles as $style) {
174
+			// skip to next style if this has already been done
175
+			if ($style->isRegistered()) {
176
+				continue;
177
+			}
178
+			do_action(
179
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
180
+				$style
181
+			);
182
+			wp_register_style(
183
+				$style->handle(),
184
+				$style->source(),
185
+				$style->dependencies(),
186
+				$style->version(),
187
+				$style->media()
188
+			);
189
+			$style->setRegistered();
190
+			do_action(
191
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
192
+				$style
193
+			);
194
+		}
195
+	}
196
+
197
+
198
+	/**
199
+	 * Call back for the script print in frontend and backend.
200
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
201
+	 *
202
+	 * @since 4.9.31.rc.015
203
+	 */
204
+	public function enqueueData()
205
+	{
206
+		$this->removeAlreadyRegisteredDataForScriptHandles();
207
+		wp_add_inline_script(
208
+			'eejs-core',
209
+			'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
210
+			'before'
211
+		);
212
+		$scripts = $this->assets->getJavascriptAssetsWithData();
213
+		foreach ($scripts as $script) {
214
+			$this->addRegisteredScriptHandlesWithData($script->handle());
215
+			if ($script->hasInlineDataCallback()) {
216
+				$localize = $script->inlineDataCallback();
217
+				$localize();
218
+			}
219
+		}
220
+	}
221
+
222
+
223
+	/**
224
+	 * Used to add data to eejs.data object.
225
+	 * Note:  Overriding existing data is not allowed.
226
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
227
+	 * If the data you add is something like this:
228
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
229
+	 * It will be exposed in the page source as:
230
+	 *  eejs.data.my_plugin_data.foo == gar
231
+	 *
232
+	 * @param string       $key   Key used to access your data
233
+	 * @param string|array $value Value to attach to key
234
+	 * @throws InvalidArgumentException
235
+	 */
236
+	public function addData($key, $value)
237
+	{
238
+		if ($this->verifyDataNotExisting($key)) {
239
+			$this->jsdata[ $key ] = $value;
240
+		}
241
+	}
242
+
243
+
244
+	/**
245
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
246
+	 * elements in an array.
247
+	 * When you use this method, the value you include will be appended to the end of an array on $key.
248
+	 * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
249
+	 * object like this, eejs.data.test = [ my_data,
250
+	 * ]
251
+	 * If there has already been a scalar value attached to the data object given key, then
252
+	 * this will throw an exception.
253
+	 *
254
+	 * @param string       $key   Key to attach data to.
255
+	 * @param string|array $value Value being registered.
256
+	 * @throws InvalidArgumentException
257
+	 */
258
+	public function pushData($key, $value)
259
+	{
260
+		if (isset($this->jsdata[ $key ])
261
+			&& ! is_array($this->jsdata[ $key ])
262
+		) {
263
+			if (! $this->debug()) {
264
+				return;
265
+			}
266
+			throw new InvalidArgumentException(
267
+				sprintf(
268
+					__(
269
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
270 270
                          push values to this data element when it is an array.',
271
-                        'event_espresso'
272
-                    ),
273
-                    $key,
274
-                    __METHOD__
275
-                )
276
-            );
277
-        }
278
-        $this->jsdata[ $key ][] = $value;
279
-    }
280
-
281
-
282
-    /**
283
-     * Used to set content used by javascript for a template.
284
-     * Note: Overrides of existing registered templates are not allowed.
285
-     *
286
-     * @param string $template_reference
287
-     * @param string $template_content
288
-     * @throws InvalidArgumentException
289
-     */
290
-    public function addTemplate($template_reference, $template_content)
291
-    {
292
-        if (! isset($this->jsdata['templates'])) {
293
-            $this->jsdata['templates'] = array();
294
-        }
295
-        //no overrides allowed.
296
-        if (isset($this->jsdata['templates'][ $template_reference ])) {
297
-            if (! $this->debug()) {
298
-                return;
299
-            }
300
-            throw new InvalidArgumentException(
301
-                sprintf(
302
-                    __(
303
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
304
-                        'event_espresso'
305
-                    ),
306
-                    $template_reference
307
-                )
308
-            );
309
-        }
310
-        $this->jsdata['templates'][ $template_reference ] = $template_content;
311
-    }
312
-
313
-
314
-    /**
315
-     * Retrieve the template content already registered for the given reference.
316
-     *
317
-     * @param string $template_reference
318
-     * @return string
319
-     */
320
-    public function getTemplate($template_reference)
321
-    {
322
-        return isset($this->jsdata['templates'][ $template_reference ])
323
-            ? $this->jsdata['templates'][ $template_reference ]
324
-            : '';
325
-    }
326
-
327
-
328
-    /**
329
-     * Retrieve registered data.
330
-     *
331
-     * @param string $key Name of key to attach data to.
332
-     * @return mixed                If there is no for the given key, then false is returned.
333
-     */
334
-    public function getData($key)
335
-    {
336
-        return isset($this->jsdata[ $key ])
337
-            ? $this->jsdata[ $key ]
338
-            : false;
339
-    }
340
-
341
-
342
-    /**
343
-     * Verifies whether the given data exists already on the jsdata array.
344
-     * Overriding data is not allowed.
345
-     *
346
-     * @param string $key Index for data.
347
-     * @return bool        If valid then return true.
348
-     * @throws InvalidArgumentException if data already exists.
349
-     */
350
-    protected function verifyDataNotExisting($key)
351
-    {
352
-        if (isset($this->jsdata[ $key ])) {
353
-            if (! $this->debug()) {
354
-                return false;
355
-            }
356
-            if (is_array($this->jsdata[ $key ])) {
357
-                throw new InvalidArgumentException(
358
-                    sprintf(
359
-                        __(
360
-                            'The value for %1$s already exists in the Registry::eejs object.
271
+						'event_espresso'
272
+					),
273
+					$key,
274
+					__METHOD__
275
+				)
276
+			);
277
+		}
278
+		$this->jsdata[ $key ][] = $value;
279
+	}
280
+
281
+
282
+	/**
283
+	 * Used to set content used by javascript for a template.
284
+	 * Note: Overrides of existing registered templates are not allowed.
285
+	 *
286
+	 * @param string $template_reference
287
+	 * @param string $template_content
288
+	 * @throws InvalidArgumentException
289
+	 */
290
+	public function addTemplate($template_reference, $template_content)
291
+	{
292
+		if (! isset($this->jsdata['templates'])) {
293
+			$this->jsdata['templates'] = array();
294
+		}
295
+		//no overrides allowed.
296
+		if (isset($this->jsdata['templates'][ $template_reference ])) {
297
+			if (! $this->debug()) {
298
+				return;
299
+			}
300
+			throw new InvalidArgumentException(
301
+				sprintf(
302
+					__(
303
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
304
+						'event_espresso'
305
+					),
306
+					$template_reference
307
+				)
308
+			);
309
+		}
310
+		$this->jsdata['templates'][ $template_reference ] = $template_content;
311
+	}
312
+
313
+
314
+	/**
315
+	 * Retrieve the template content already registered for the given reference.
316
+	 *
317
+	 * @param string $template_reference
318
+	 * @return string
319
+	 */
320
+	public function getTemplate($template_reference)
321
+	{
322
+		return isset($this->jsdata['templates'][ $template_reference ])
323
+			? $this->jsdata['templates'][ $template_reference ]
324
+			: '';
325
+	}
326
+
327
+
328
+	/**
329
+	 * Retrieve registered data.
330
+	 *
331
+	 * @param string $key Name of key to attach data to.
332
+	 * @return mixed                If there is no for the given key, then false is returned.
333
+	 */
334
+	public function getData($key)
335
+	{
336
+		return isset($this->jsdata[ $key ])
337
+			? $this->jsdata[ $key ]
338
+			: false;
339
+	}
340
+
341
+
342
+	/**
343
+	 * Verifies whether the given data exists already on the jsdata array.
344
+	 * Overriding data is not allowed.
345
+	 *
346
+	 * @param string $key Index for data.
347
+	 * @return bool        If valid then return true.
348
+	 * @throws InvalidArgumentException if data already exists.
349
+	 */
350
+	protected function verifyDataNotExisting($key)
351
+	{
352
+		if (isset($this->jsdata[ $key ])) {
353
+			if (! $this->debug()) {
354
+				return false;
355
+			}
356
+			if (is_array($this->jsdata[ $key ])) {
357
+				throw new InvalidArgumentException(
358
+					sprintf(
359
+						__(
360
+							'The value for %1$s already exists in the Registry::eejs object.
361 361
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
362 362
                             %2$s method to push your value to the array.',
363
-                            'event_espresso'
364
-                        ),
365
-                        $key,
366
-                        'pushData()'
367
-                    )
368
-                );
369
-            }
370
-            throw new InvalidArgumentException(
371
-                sprintf(
372
-                    __(
373
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
363
+							'event_espresso'
364
+						),
365
+						$key,
366
+						'pushData()'
367
+					)
368
+				);
369
+			}
370
+			throw new InvalidArgumentException(
371
+				sprintf(
372
+					__(
373
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
374 374
                         allowed.  Consider attaching your value to a different key',
375
-                        'event_espresso'
376
-                    ),
377
-                    $key
378
-                )
379
-            );
380
-        }
381
-        return true;
382
-    }
383
-
384
-
385
-    /**
386
-     * Get the actual asset path for asset manifests.
387
-     * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
388
-     *
389
-     * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
390
-     *                           asset file location.
391
-     * @param string $chunk_name
392
-     * @param string $asset_type
393
-     * @return string
394
-     * @since 4.9.59.p
395
-     */
396
-    public function getAssetUrl($namespace, $chunk_name, $asset_type)
397
-    {
398
-        $url = isset(
399
-            $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
400
-            $this->manifest_data[ $namespace ]['url_base']
401
-        )
402
-            ? $this->manifest_data[ $namespace ]['url_base']
403
-              . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
404
-            : $chunk_name;
405
-        return apply_filters(
406
-            'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
407
-            $url,
408
-            $namespace,
409
-            $chunk_name,
410
-            $asset_type
411
-        );
412
-    }
413
-
414
-
415
-    /**
416
-     * Return the url to a js file for the given namespace and chunk name.
417
-     *
418
-     * @param string $namespace
419
-     * @param string $chunk_name
420
-     * @return string
421
-     */
422
-    public function getJsUrl($namespace, $chunk_name)
423
-    {
424
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
425
-    }
426
-
427
-
428
-    /**
429
-     * Return the url to a css file for the given namespace and chunk name.
430
-     *
431
-     * @param string $namespace
432
-     * @param string $chunk_name
433
-     * @return string
434
-     */
435
-    public function getCssUrl($namespace, $chunk_name)
436
-    {
437
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
438
-    }
439
-
440
-
441
-    /**
442
-     * @since 4.9.62.p
443
-     * @throws InvalidArgumentException
444
-     * @throws InvalidFilePathException
445
-     */
446
-    public function registerManifestFiles()
447
-    {
448
-        $manifest_files = $this->assets->getManifestFiles();
449
-        foreach ($manifest_files as $manifest_file) {
450
-            $this->registerManifestFile(
451
-                $manifest_file->assetNamespace(),
452
-                $manifest_file->urlBase(),
453
-                $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST
454
-            );
455
-        }
456
-    }
457
-
458
-
459
-    /**
460
-     * Used to register a js/css manifest file with the registered_manifest_files property.
461
-     *
462
-     * @param string $namespace     Provided to associate the manifest file with a specific namespace.
463
-     * @param string $url_base      The url base for the manifest file location.
464
-     * @param string $manifest_file The absolute path to the manifest file.
465
-     * @throws InvalidArgumentException
466
-     * @throws InvalidFilePathException
467
-     * @since 4.9.59.p
468
-     */
469
-    public function registerManifestFile($namespace, $url_base, $manifest_file)
470
-    {
471
-        if (isset($this->manifest_data[ $namespace ])) {
472
-            if (! $this->debug()) {
473
-                return;
474
-            }
475
-            throw new InvalidArgumentException(
476
-                sprintf(
477
-                    esc_html__(
478
-                        'The namespace for this manifest file has already been registered, choose a namespace other than %s',
479
-                        'event_espresso'
480
-                    ),
481
-                    $namespace
482
-                )
483
-            );
484
-        }
485
-        if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
486
-            if (is_admin()) {
487
-                EE_Error::add_error(
488
-                    sprintf(
489
-                        esc_html__(
490
-                            'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
491
-                            'event_espresso'
492
-                        ),
493
-                        'Event Espresso',
494
-                        $url_base,
495
-                        'plugins_url',
496
-                        'WP_PLUGIN_URL'
497
-                    ),
498
-                    __FILE__,
499
-                    __FUNCTION__,
500
-                    __LINE__
501
-                );
502
-            }
503
-            return;
504
-        }
505
-        $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
506
-        if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
507
-            $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
508
-        }
509
-    }
510
-
511
-
512
-    /**
513
-     * Decodes json from the provided manifest file.
514
-     *
515
-     * @since 4.9.59.p
516
-     * @param string $manifest_file Path to manifest file.
517
-     * @return array
518
-     * @throws InvalidFilePathException
519
-     */
520
-    private function decodeManifestFile($manifest_file)
521
-    {
522
-        if (! file_exists($manifest_file)) {
523
-            throw new InvalidFilePathException($manifest_file);
524
-        }
525
-        return json_decode(file_get_contents($manifest_file), true);
526
-    }
527
-
528
-
529
-    /**
530
-     * This is used to set registered script handles that have data.
531
-     *
532
-     * @param string $script_handle
533
-     */
534
-    private function addRegisteredScriptHandlesWithData($script_handle)
535
-    {
536
-        $this->script_handles_with_data[ $script_handle ] = $script_handle;
537
-    }
538
-
539
-
540
-    /**i
375
+						'event_espresso'
376
+					),
377
+					$key
378
+				)
379
+			);
380
+		}
381
+		return true;
382
+	}
383
+
384
+
385
+	/**
386
+	 * Get the actual asset path for asset manifests.
387
+	 * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
388
+	 *
389
+	 * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
390
+	 *                           asset file location.
391
+	 * @param string $chunk_name
392
+	 * @param string $asset_type
393
+	 * @return string
394
+	 * @since 4.9.59.p
395
+	 */
396
+	public function getAssetUrl($namespace, $chunk_name, $asset_type)
397
+	{
398
+		$url = isset(
399
+			$this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
400
+			$this->manifest_data[ $namespace ]['url_base']
401
+		)
402
+			? $this->manifest_data[ $namespace ]['url_base']
403
+			  . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
404
+			: $chunk_name;
405
+		return apply_filters(
406
+			'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
407
+			$url,
408
+			$namespace,
409
+			$chunk_name,
410
+			$asset_type
411
+		);
412
+	}
413
+
414
+
415
+	/**
416
+	 * Return the url to a js file for the given namespace and chunk name.
417
+	 *
418
+	 * @param string $namespace
419
+	 * @param string $chunk_name
420
+	 * @return string
421
+	 */
422
+	public function getJsUrl($namespace, $chunk_name)
423
+	{
424
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
425
+	}
426
+
427
+
428
+	/**
429
+	 * Return the url to a css file for the given namespace and chunk name.
430
+	 *
431
+	 * @param string $namespace
432
+	 * @param string $chunk_name
433
+	 * @return string
434
+	 */
435
+	public function getCssUrl($namespace, $chunk_name)
436
+	{
437
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
438
+	}
439
+
440
+
441
+	/**
442
+	 * @since 4.9.62.p
443
+	 * @throws InvalidArgumentException
444
+	 * @throws InvalidFilePathException
445
+	 */
446
+	public function registerManifestFiles()
447
+	{
448
+		$manifest_files = $this->assets->getManifestFiles();
449
+		foreach ($manifest_files as $manifest_file) {
450
+			$this->registerManifestFile(
451
+				$manifest_file->assetNamespace(),
452
+				$manifest_file->urlBase(),
453
+				$manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST
454
+			);
455
+		}
456
+	}
457
+
458
+
459
+	/**
460
+	 * Used to register a js/css manifest file with the registered_manifest_files property.
461
+	 *
462
+	 * @param string $namespace     Provided to associate the manifest file with a specific namespace.
463
+	 * @param string $url_base      The url base for the manifest file location.
464
+	 * @param string $manifest_file The absolute path to the manifest file.
465
+	 * @throws InvalidArgumentException
466
+	 * @throws InvalidFilePathException
467
+	 * @since 4.9.59.p
468
+	 */
469
+	public function registerManifestFile($namespace, $url_base, $manifest_file)
470
+	{
471
+		if (isset($this->manifest_data[ $namespace ])) {
472
+			if (! $this->debug()) {
473
+				return;
474
+			}
475
+			throw new InvalidArgumentException(
476
+				sprintf(
477
+					esc_html__(
478
+						'The namespace for this manifest file has already been registered, choose a namespace other than %s',
479
+						'event_espresso'
480
+					),
481
+					$namespace
482
+				)
483
+			);
484
+		}
485
+		if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
486
+			if (is_admin()) {
487
+				EE_Error::add_error(
488
+					sprintf(
489
+						esc_html__(
490
+							'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
491
+							'event_espresso'
492
+						),
493
+						'Event Espresso',
494
+						$url_base,
495
+						'plugins_url',
496
+						'WP_PLUGIN_URL'
497
+					),
498
+					__FILE__,
499
+					__FUNCTION__,
500
+					__LINE__
501
+				);
502
+			}
503
+			return;
504
+		}
505
+		$this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
506
+		if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
507
+			$this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
508
+		}
509
+	}
510
+
511
+
512
+	/**
513
+	 * Decodes json from the provided manifest file.
514
+	 *
515
+	 * @since 4.9.59.p
516
+	 * @param string $manifest_file Path to manifest file.
517
+	 * @return array
518
+	 * @throws InvalidFilePathException
519
+	 */
520
+	private function decodeManifestFile($manifest_file)
521
+	{
522
+		if (! file_exists($manifest_file)) {
523
+			throw new InvalidFilePathException($manifest_file);
524
+		}
525
+		return json_decode(file_get_contents($manifest_file), true);
526
+	}
527
+
528
+
529
+	/**
530
+	 * This is used to set registered script handles that have data.
531
+	 *
532
+	 * @param string $script_handle
533
+	 */
534
+	private function addRegisteredScriptHandlesWithData($script_handle)
535
+	{
536
+		$this->script_handles_with_data[ $script_handle ] = $script_handle;
537
+	}
538
+
539
+
540
+	/**i
541 541
      * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
542 542
      * Dependency stored in WP_Scripts if its set.
543 543
      */
544
-    private function removeAlreadyRegisteredDataForScriptHandles()
545
-    {
546
-        if (empty($this->script_handles_with_data)) {
547
-            return;
548
-        }
549
-        foreach ($this->script_handles_with_data as $script_handle) {
550
-            $this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
551
-        }
552
-    }
553
-
554
-
555
-    /**
556
-     * Removes any data dependency registered in WP_Scripts if its set.
557
-     *
558
-     * @param string $script_handle
559
-     */
560
-    private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
561
-    {
562
-        if (isset($this->script_handles_with_data[ $script_handle ])) {
563
-            global $wp_scripts;
564
-            $unset_handle = false;
565
-            if ($wp_scripts->get_data($script_handle, 'data')) {
566
-                unset($wp_scripts->registered[ $script_handle ]->extra['data']);
567
-                $unset_handle = true;
568
-            }
569
-            //deal with inline_scripts
570
-            if ($wp_scripts->get_data($script_handle, 'before')) {
571
-                unset($wp_scripts->registered[ $script_handle ]->extra['before']);
572
-                $unset_handle = true;
573
-            }
574
-            if ($wp_scripts->get_data($script_handle, 'after')) {
575
-                unset($wp_scripts->registered[ $script_handle ]->extra['after']);
576
-            }
577
-            if ($unset_handle) {
578
-                unset($this->script_handles_with_data[ $script_handle ]);
579
-            }
580
-        }
581
-    }
582
-
583
-
584
-    /**
585
-     * register translations for a registered script
586
-     *
587
-     * @param string $handle
588
-     */
589
-    public function registerTranslation($handle)
590
-    {
591
-        $this->i18n_registry->registerScriptI18n($handle);
592
-    }
593
-
594
-
595
-    /**
596
-     * @since 4.9.63.p
597
-     * @return bool
598
-     */
599
-    private function debug()
600
-    {
601
-        return apply_filters(
602
-            'FHEE__EventEspresso_core_services_assets_Registry__debug',
603
-            defined('EE_DEBUG') && EE_DEBUG
604
-        );
605
-    }
544
+	private function removeAlreadyRegisteredDataForScriptHandles()
545
+	{
546
+		if (empty($this->script_handles_with_data)) {
547
+			return;
548
+		}
549
+		foreach ($this->script_handles_with_data as $script_handle) {
550
+			$this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
551
+		}
552
+	}
553
+
554
+
555
+	/**
556
+	 * Removes any data dependency registered in WP_Scripts if its set.
557
+	 *
558
+	 * @param string $script_handle
559
+	 */
560
+	private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
561
+	{
562
+		if (isset($this->script_handles_with_data[ $script_handle ])) {
563
+			global $wp_scripts;
564
+			$unset_handle = false;
565
+			if ($wp_scripts->get_data($script_handle, 'data')) {
566
+				unset($wp_scripts->registered[ $script_handle ]->extra['data']);
567
+				$unset_handle = true;
568
+			}
569
+			//deal with inline_scripts
570
+			if ($wp_scripts->get_data($script_handle, 'before')) {
571
+				unset($wp_scripts->registered[ $script_handle ]->extra['before']);
572
+				$unset_handle = true;
573
+			}
574
+			if ($wp_scripts->get_data($script_handle, 'after')) {
575
+				unset($wp_scripts->registered[ $script_handle ]->extra['after']);
576
+			}
577
+			if ($unset_handle) {
578
+				unset($this->script_handles_with_data[ $script_handle ]);
579
+			}
580
+		}
581
+	}
582
+
583
+
584
+	/**
585
+	 * register translations for a registered script
586
+	 *
587
+	 * @param string $handle
588
+	 */
589
+	public function registerTranslation($handle)
590
+	{
591
+		$this->i18n_registry->registerScriptI18n($handle);
592
+	}
593
+
594
+
595
+	/**
596
+	 * @since 4.9.63.p
597
+	 * @return bool
598
+	 */
599
+	private function debug()
600
+	{
601
+		return apply_filters(
602
+			'FHEE__EventEspresso_core_services_assets_Registry__debug',
603
+			defined('EE_DEBUG') && EE_DEBUG
604
+		);
605
+	}
606 606
 }
Please login to merge, or discard this patch.
core/services/assets/AssetCollection.php 1 patch
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -21,201 +21,201 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * AssetCollection constructor
26
-     *
27
-     * @throws InvalidInterfaceException
28
-     */
29
-    public function __construct()
30
-    {
31
-        parent::__construct('EventEspresso\core\domain\values\assets\Asset');
32
-    }
33
-
34
-
35
-    /**
36
-     * @return StylesheetAsset[]
37
-     * @since 4.9.62.p
38
-     */
39
-    public function getStylesheetAssets()
40
-    {
41
-        return $this->getAssetsOfType(Asset::TYPE_CSS);
42
-    }
43
-
44
-
45
-    /**
46
-     * @return JavascriptAsset[]
47
-     * @since 4.9.62.p
48
-     */
49
-    public function getJavascriptAssets()
50
-    {
51
-        return $this->getAssetsOfType(Asset::TYPE_JS);
52
-    }
53
-
54
-
55
-    /**
56
-     * @return ManifestFile[]
57
-     * @since 4.9.62.p
58
-     */
59
-    public function getManifestFiles()
60
-    {
61
-        return $this->getAssetsOfType(Asset::TYPE_MANIFEST);
62
-    }
63
-
64
-
65
-    /**
66
-     * @param $type
67
-     * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[]
68
-     * @since 4.9.62.p
69
-     */
70
-    protected function getAssetsOfType($type)
71
-    {
72
-        $files = array();
73
-        $this->rewind();
74
-        while ($this->valid()) {
75
-            /** @var Asset $asset */
76
-            $asset = $this->current();
77
-            if ($asset->type() === $type) {
78
-                $files[ $asset->handle() ] = $asset;
79
-            }
80
-            $this->next();
81
-        }
82
-        $this->rewind();
83
-        return $files;
84
-    }
85
-
86
-
87
-    /**
88
-     * @return JavascriptAsset[]
89
-     * @since 4.9.62.p
90
-     */
91
-    public function getJavascriptAssetsWithData()
92
-    {
93
-        $files = array();
94
-        $this->rewind();
95
-        while ($this->valid()) {
96
-            /** @var JavascriptAsset $asset */
97
-            $asset = $this->current();
98
-            if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
-                $files[ $asset->handle() ] = $asset;
100
-            }
101
-            $this->next();
102
-        }
103
-        $this->rewind();
104
-        return $files;
105
-    }
106
-
107
-
108
-    /**
109
-     * has
110
-     * returns TRUE or FALSE
111
-     * depending on whether the object is within the Collection
112
-     * based on the supplied $identifier and type
113
-     *
114
-     * @param  mixed $identifier
115
-     * @param string $type
116
-     * @return bool
117
-     * @since 4.9.63.p
118
-     */
119
-    public function hasAssetOfType($identifier, $type = Asset::TYPE_JS)
120
-    {
121
-        $this->rewind();
122
-        while ($this->valid()) {
123
-            if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
124
-                $this->rewind();
125
-                return true;
126
-            }
127
-            $this->next();
128
-        }
129
-        return false;
130
-    }
131
-
132
-
133
-    /**
134
-     * has
135
-     * returns TRUE or FALSE
136
-     * depending on whether the Stylesheet Asset is within the Collection
137
-     * based on the supplied $identifier
138
-     *
139
-     * @param  mixed $identifier
140
-     * @return bool
141
-     * @since 4.9.63.p
142
-     */
143
-    public function hasStylesheetAsset($identifier)
144
-    {
145
-        return $this->hasAssetOfType($identifier, Asset::TYPE_CSS);
146
-    }
147
-
148
-
149
-    /**
150
-     * has
151
-     * returns TRUE or FALSE
152
-     * depending on whether the Javascript Asset is within the Collection
153
-     * based on the supplied $identifier
154
-     *
155
-     * @param  mixed $identifier
156
-     * @return bool
157
-     * @since 4.9.63.p
158
-     */
159
-    public function hasJavascriptAsset($identifier)
160
-    {
161
-        return $this->hasAssetOfType($identifier, Asset::TYPE_JS);
162
-    }
163
-
164
-    /**
165
-     * has
166
-     * returns TRUE or FALSE
167
-     * depending on whether the object is within the Collection
168
-     * based on the supplied $identifier and type
169
-     *
170
-     * @param  mixed $identifier
171
-     * @param string $type
172
-     * @return JavascriptAsset|StylesheetAsset
173
-     * @since 4.9.63.p
174
-     */
175
-    public function getAssetOfType($identifier, $type = Asset::TYPE_JS)
176
-    {
177
-        $this->rewind();
178
-        while ($this->valid()) {
179
-            if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
180
-                /** @var JavascriptAsset|StylesheetAsset $object */
181
-                $object = $this->current();
182
-                $this->rewind();
183
-                return $object;
184
-            }
185
-            $this->next();
186
-        }
187
-        return null;
188
-    }
189
-
190
-
191
-    /**
192
-     * has
193
-     * returns TRUE or FALSE
194
-     * depending on whether the Stylesheet Asset is within the Collection
195
-     * based on the supplied $identifier
196
-     *
197
-     * @param  mixed $identifier
198
-     * @return StylesheetAsset
199
-     * @since 4.9.63.p
200
-     */
201
-    public function getStylesheetAsset($identifier)
202
-    {
203
-        return $this->getAssetOfType($identifier, Asset::TYPE_CSS);
204
-    }
205
-
206
-
207
-    /**
208
-     * has
209
-     * returns TRUE or FALSE
210
-     * depending on whether the Javascript Asset is within the Collection
211
-     * based on the supplied $identifier
212
-     *
213
-     * @param  mixed $identifier
214
-     * @return JavascriptAsset
215
-     * @since 4.9.63.p
216
-     */
217
-    public function getJavascriptAsset($identifier)
218
-    {
219
-        return $this->getAssetOfType($identifier, Asset::TYPE_JS);
220
-    }
24
+	/**
25
+	 * AssetCollection constructor
26
+	 *
27
+	 * @throws InvalidInterfaceException
28
+	 */
29
+	public function __construct()
30
+	{
31
+		parent::__construct('EventEspresso\core\domain\values\assets\Asset');
32
+	}
33
+
34
+
35
+	/**
36
+	 * @return StylesheetAsset[]
37
+	 * @since 4.9.62.p
38
+	 */
39
+	public function getStylesheetAssets()
40
+	{
41
+		return $this->getAssetsOfType(Asset::TYPE_CSS);
42
+	}
43
+
44
+
45
+	/**
46
+	 * @return JavascriptAsset[]
47
+	 * @since 4.9.62.p
48
+	 */
49
+	public function getJavascriptAssets()
50
+	{
51
+		return $this->getAssetsOfType(Asset::TYPE_JS);
52
+	}
53
+
54
+
55
+	/**
56
+	 * @return ManifestFile[]
57
+	 * @since 4.9.62.p
58
+	 */
59
+	public function getManifestFiles()
60
+	{
61
+		return $this->getAssetsOfType(Asset::TYPE_MANIFEST);
62
+	}
63
+
64
+
65
+	/**
66
+	 * @param $type
67
+	 * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[]
68
+	 * @since 4.9.62.p
69
+	 */
70
+	protected function getAssetsOfType($type)
71
+	{
72
+		$files = array();
73
+		$this->rewind();
74
+		while ($this->valid()) {
75
+			/** @var Asset $asset */
76
+			$asset = $this->current();
77
+			if ($asset->type() === $type) {
78
+				$files[ $asset->handle() ] = $asset;
79
+			}
80
+			$this->next();
81
+		}
82
+		$this->rewind();
83
+		return $files;
84
+	}
85
+
86
+
87
+	/**
88
+	 * @return JavascriptAsset[]
89
+	 * @since 4.9.62.p
90
+	 */
91
+	public function getJavascriptAssetsWithData()
92
+	{
93
+		$files = array();
94
+		$this->rewind();
95
+		while ($this->valid()) {
96
+			/** @var JavascriptAsset $asset */
97
+			$asset = $this->current();
98
+			if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
+				$files[ $asset->handle() ] = $asset;
100
+			}
101
+			$this->next();
102
+		}
103
+		$this->rewind();
104
+		return $files;
105
+	}
106
+
107
+
108
+	/**
109
+	 * has
110
+	 * returns TRUE or FALSE
111
+	 * depending on whether the object is within the Collection
112
+	 * based on the supplied $identifier and type
113
+	 *
114
+	 * @param  mixed $identifier
115
+	 * @param string $type
116
+	 * @return bool
117
+	 * @since 4.9.63.p
118
+	 */
119
+	public function hasAssetOfType($identifier, $type = Asset::TYPE_JS)
120
+	{
121
+		$this->rewind();
122
+		while ($this->valid()) {
123
+			if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
124
+				$this->rewind();
125
+				return true;
126
+			}
127
+			$this->next();
128
+		}
129
+		return false;
130
+	}
131
+
132
+
133
+	/**
134
+	 * has
135
+	 * returns TRUE or FALSE
136
+	 * depending on whether the Stylesheet Asset is within the Collection
137
+	 * based on the supplied $identifier
138
+	 *
139
+	 * @param  mixed $identifier
140
+	 * @return bool
141
+	 * @since 4.9.63.p
142
+	 */
143
+	public function hasStylesheetAsset($identifier)
144
+	{
145
+		return $this->hasAssetOfType($identifier, Asset::TYPE_CSS);
146
+	}
147
+
148
+
149
+	/**
150
+	 * has
151
+	 * returns TRUE or FALSE
152
+	 * depending on whether the Javascript Asset is within the Collection
153
+	 * based on the supplied $identifier
154
+	 *
155
+	 * @param  mixed $identifier
156
+	 * @return bool
157
+	 * @since 4.9.63.p
158
+	 */
159
+	public function hasJavascriptAsset($identifier)
160
+	{
161
+		return $this->hasAssetOfType($identifier, Asset::TYPE_JS);
162
+	}
163
+
164
+	/**
165
+	 * has
166
+	 * returns TRUE or FALSE
167
+	 * depending on whether the object is within the Collection
168
+	 * based on the supplied $identifier and type
169
+	 *
170
+	 * @param  mixed $identifier
171
+	 * @param string $type
172
+	 * @return JavascriptAsset|StylesheetAsset
173
+	 * @since 4.9.63.p
174
+	 */
175
+	public function getAssetOfType($identifier, $type = Asset::TYPE_JS)
176
+	{
177
+		$this->rewind();
178
+		while ($this->valid()) {
179
+			if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
180
+				/** @var JavascriptAsset|StylesheetAsset $object */
181
+				$object = $this->current();
182
+				$this->rewind();
183
+				return $object;
184
+			}
185
+			$this->next();
186
+		}
187
+		return null;
188
+	}
189
+
190
+
191
+	/**
192
+	 * has
193
+	 * returns TRUE or FALSE
194
+	 * depending on whether the Stylesheet Asset is within the Collection
195
+	 * based on the supplied $identifier
196
+	 *
197
+	 * @param  mixed $identifier
198
+	 * @return StylesheetAsset
199
+	 * @since 4.9.63.p
200
+	 */
201
+	public function getStylesheetAsset($identifier)
202
+	{
203
+		return $this->getAssetOfType($identifier, Asset::TYPE_CSS);
204
+	}
205
+
206
+
207
+	/**
208
+	 * has
209
+	 * returns TRUE or FALSE
210
+	 * depending on whether the Javascript Asset is within the Collection
211
+	 * based on the supplied $identifier
212
+	 *
213
+	 * @param  mixed $identifier
214
+	 * @return JavascriptAsset
215
+	 * @since 4.9.63.p
216
+	 */
217
+	public function getJavascriptAsset($identifier)
218
+	{
219
+		return $this->getAssetOfType($identifier, Asset::TYPE_JS);
220
+	}
221 221
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin.core.php 1 patch
Indentation   +958 added lines, -958 removed lines patch added patch discarded remove patch
@@ -20,487 +20,487 @@  discard block
 block discarded – undo
20 20
 final class EE_Admin implements InterminableInterface
21 21
 {
22 22
 
23
-    /**
24
-     * @var EE_Admin $_instance
25
-     */
26
-    private static $_instance;
27
-
28
-    /**
29
-     * @var PersistentAdminNoticeManager $persistent_admin_notice_manager
30
-     */
31
-    private $persistent_admin_notice_manager;
32
-
33
-    /**
34
-     * @var LoaderInterface
35
-     */
36
-    protected $loader;
37
-
38
-    /**
39
-     * @singleton method used to instantiate class object
40
-     * @return EE_Admin
41
-     * @throws EE_Error
42
-     */
43
-    public static function instance()
44
-    {
45
-        // check if class object is instantiated
46
-        if (! self::$_instance instanceof EE_Admin) {
47
-            self::$_instance = new self();
48
-        }
49
-        return self::$_instance;
50
-    }
51
-
52
-
53
-    /**
54
-     * @return EE_Admin
55
-     * @throws EE_Error
56
-     */
57
-    public static function reset()
58
-    {
59
-        self::$_instance = null;
60
-        return self::instance();
61
-    }
62
-
63
-
64
-    /**
65
-     * class constructor
66
-     *
67
-     * @throws EE_Error
68
-     * @throws InvalidDataTypeException
69
-     * @throws InvalidInterfaceException
70
-     * @throws InvalidArgumentException
71
-     */
72
-    protected function __construct()
73
-    {
74
-        // define global EE_Admin constants
75
-        $this->_define_all_constants();
76
-        // set autoloaders for our admin page classes based on included path information
77
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
78
-        // admin hooks
79
-        add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
80
-        // load EE_Request_Handler early
81
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request'));
82
-        add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
83
-        add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2);
84
-        add_action('wp_loaded', array($this, 'wp_loaded'), 100);
85
-        add_action('admin_init', array($this, 'admin_init'), 100);
86
-        add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20);
87
-        add_action('admin_notices', array($this, 'display_admin_notices'), 10);
88
-        add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
89
-        add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
90
-        add_filter('admin_footer_text', array($this, 'espresso_admin_footer'));
91
-        add_action('load-plugins.php', array($this, 'hookIntoWpPluginsPage'));
92
-        // reset Environment config (we only do this on admin page loads);
93
-        EE_Registry::instance()->CFG->environment->recheck_values();
94
-        do_action('AHEE__EE_Admin__loaded');
95
-    }
96
-
97
-
98
-    /**
99
-     * _define_all_constants
100
-     * define constants that are set globally for all admin pages
101
-     *
102
-     * @return void
103
-     */
104
-    private function _define_all_constants()
105
-    {
106
-        if (! defined('EE_ADMIN_URL')) {
107
-            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
108
-            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
109
-            define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS);
110
-            define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
111
-            define('WP_AJAX_URL', admin_url('admin-ajax.php'));
112
-        }
113
-    }
114
-
115
-
116
-    /**
117
-     * filter_plugin_actions - adds links to the Plugins page listing
118
-     *
119
-     * @param    array  $links
120
-     * @param    string $plugin
121
-     * @return    array
122
-     */
123
-    public function filter_plugin_actions($links, $plugin)
124
-    {
125
-        // set $main_file in stone
126
-        static $main_file;
127
-        // if $main_file is not set yet
128
-        if (! $main_file) {
129
-            $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
130
-        }
131
-        if ($plugin === $main_file) {
132
-            // compare current plugin to this one
133
-            if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
134
-                $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
135
-                                    . ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
136
-                                    . esc_html__('Maintenance Mode Active', 'event_espresso')
137
-                                    . '</a>';
138
-                array_unshift($links, $maintenance_link);
139
-            } else {
140
-                $org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
141
-                                     . esc_html__('Settings', 'event_espresso')
142
-                                     . '</a>';
143
-                $events_link = '<a href="admin.php?page=espresso_events">'
144
-                               . esc_html__('Events', 'event_espresso')
145
-                               . '</a>';
146
-                // add before other links
147
-                array_unshift($links, $org_settings_link, $events_link);
148
-            }
149
-        }
150
-        return $links;
151
-    }
152
-
153
-
154
-    /**
155
-     * _get_request
156
-     *
157
-     * @return void
158
-     * @throws EE_Error
159
-     * @throws InvalidArgumentException
160
-     * @throws InvalidDataTypeException
161
-     * @throws InvalidInterfaceException
162
-     * @throws ReflectionException
163
-     */
164
-    public function get_request()
165
-    {
166
-        EE_Registry::instance()->load_core('Request_Handler');
167
-        EE_Registry::instance()->load_core('CPT_Strategy');
168
-    }
169
-
170
-
171
-    /**
172
-     * hide_admin_pages_except_maintenance_mode
173
-     *
174
-     * @param array $admin_page_folder_names
175
-     * @return array
176
-     */
177
-    public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
178
-    {
179
-        return array(
180
-            'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
181
-            'about'       => EE_ADMIN_PAGES . 'about' . DS,
182
-            'support'     => EE_ADMIN_PAGES . 'support' . DS,
183
-        );
184
-    }
185
-
186
-
187
-    /**
188
-     * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
189
-     * EE_Front_Controller's init phases have run
190
-     *
191
-     * @return void
192
-     * @throws EE_Error
193
-     * @throws InvalidArgumentException
194
-     * @throws InvalidDataTypeException
195
-     * @throws InvalidInterfaceException
196
-     * @throws ReflectionException
197
-     * @throws ServiceNotFoundException
198
-     */
199
-    public function init()
200
-    {
201
-        // only enable most of the EE_Admin IF we're not in full maintenance mode
202
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
203
-            $this->initModelsReady();
204
-        }
205
-        // run the admin page factory but ONLY if we are doing an ee admin ajax request
206
-        if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
207
-            try {
208
-                // this loads the controller for the admin pages which will setup routing etc
209
-                EE_Registry::instance()->load_core('Admin_Page_Loader');
210
-            } catch (EE_Error $e) {
211
-                $e->get_error();
212
-            }
213
-        }
214
-        add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
215
-        // make sure our CPTs and custom taxonomy metaboxes get shown for first time users
216
-        add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
217
-        add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
218
-        // exclude EE critical pages from all nav menus and wp_list_pages
219
-        add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
220
-    }
221
-
222
-
223
-    /**
224
-     * Gets the loader (and if it wasn't previously set, sets it)
225
-     * @return LoaderInterface
226
-     * @throws InvalidArgumentException
227
-     * @throws InvalidDataTypeException
228
-     * @throws InvalidInterfaceException
229
-     */
230
-    protected function getLoader()
231
-    {
232
-        if (! $this->loader instanceof LoaderInterface) {
233
-            $this->loader = LoaderFactory::getLoader();
234
-        }
235
-        return $this->loader;
236
-    }
237
-
238
-
239
-    /**
240
-     * Method that's fired on admin requests (including admin ajax) but only when the models are usable
241
-     * (ie, the site isn't in maintenance mode)
242
-     * @since 4.9.63.p
243
-     * @return void
244
-     */
245
-    protected function initModelsReady()
246
-    {
247
-        // ok so we want to enable the entire admin
248
-        $this->persistent_admin_notice_manager = $this->getLoader()->getShared(
249
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
250
-        );
251
-        $this->persistent_admin_notice_manager->setReturnUrl(
252
-            EE_Admin_Page::add_query_args_and_nonce(
253
-                array(
254
-                    'page'   => EE_Registry::instance()->REQ->get('page', ''),
255
-                    'action' => EE_Registry::instance()->REQ->get('action', ''),
256
-                ),
257
-                EE_ADMIN_URL
258
-            )
259
-        );
260
-        $this->maybeSetDatetimeWarningNotice();
261
-        // at a glance dashboard widget
262
-        add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
263
-        // filter for get_edit_post_link used on comments for custom post types
264
-        add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
265
-    }
266
-
267
-
268
-    /**
269
-     *    get_persistent_admin_notices
270
-     *
271
-     * @access    public
272
-     * @return void
273
-     * @throws EE_Error
274
-     * @throws InvalidArgumentException
275
-     * @throws InvalidDataTypeException
276
-     * @throws InvalidInterfaceException
277
-     */
278
-    public function maybeSetDatetimeWarningNotice()
279
-    {
280
-        // add dismissable notice for datetime changes.  Only valid if site does not have a timezone_string set.
281
-        // @todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
282
-        // with this.  But after enough time (indeterminate at this point) we can just remove this notice.
283
-        // this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
284
-        if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true)
285
-            && ! get_option('timezone_string')
286
-            && EEM_Event::instance()->count() > 0
287
-        ) {
288
-            new PersistentAdminNotice(
289
-                'datetime_fix_notice',
290
-                sprintf(
291
-                    esc_html__(
292
-                        '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times.  Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.',
293
-                        'event_espresso'
294
-                    ),
295
-                    '<strong>',
296
-                    '</strong>',
297
-                    '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
298
-                    '</a>',
299
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
300
-                        array(
301
-                            'page'   => 'espresso_maintenance_settings',
302
-                            'action' => 'datetime_tools',
303
-                        ),
304
-                        admin_url('admin.php')
305
-                    ) . '">'
306
-                ),
307
-                false,
308
-                'manage_options',
309
-                'datetime_fix_persistent_notice'
310
-            );
311
-        }
312
-    }
313
-
314
-
315
-    /**
316
-     * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
317
-     * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
318
-     * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
319
-     * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
320
-     * normal property on the post_type object.  It's found ONLY in this particular context.
321
-     *
322
-     * @param WP_Post $post_type WP post type object
323
-     * @return WP_Post
324
-     * @throws InvalidArgumentException
325
-     * @throws InvalidDataTypeException
326
-     * @throws InvalidInterfaceException
327
-     */
328
-    public function remove_pages_from_nav_menu($post_type)
329
-    {
330
-        // if this isn't the "pages" post type let's get out
331
-        if ($post_type->name !== 'page') {
332
-            return $post_type;
333
-        }
334
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
335
-        $post_type->_default_query = array(
336
-            'post__not_in' => $critical_pages,
337
-        );
338
-        return $post_type;
339
-    }
340
-
341
-
342
-    /**
343
-     * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
344
-     * metaboxes get shown as well
345
-     *
346
-     * @return void
347
-     */
348
-    public function enable_hidden_ee_nav_menu_metaboxes()
349
-    {
350
-        global $wp_meta_boxes, $pagenow;
351
-        if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
352
-            return;
353
-        }
354
-        $user = wp_get_current_user();
355
-        // has this been done yet?
356
-        if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
357
-            return;
358
-        }
359
-
360
-        $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID);
361
-        $initial_meta_boxes = apply_filters(
362
-            'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
363
-            array(
364
-                'nav-menu-theme-locations',
365
-                'add-page',
366
-                'add-custom-links',
367
-                'add-category',
368
-                'add-espresso_events',
369
-                'add-espresso_venues',
370
-                'add-espresso_event_categories',
371
-                'add-espresso_venue_categories',
372
-                'add-post-type-post',
373
-                'add-post-type-page',
374
-            )
375
-        );
376
-
377
-        if (is_array($hidden_meta_boxes)) {
378
-            foreach ($hidden_meta_boxes as $key => $meta_box_id) {
379
-                if (in_array($meta_box_id, $initial_meta_boxes, true)) {
380
-                    unset($hidden_meta_boxes[ $key ]);
381
-                }
382
-            }
383
-        }
384
-        update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
385
-        update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
386
-    }
387
-
388
-
389
-    /**
390
-     * This method simply registers custom nav menu boxes for "nav_menus.php route"
391
-     * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
392
-     *
393
-     * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
394
-     *         addons etc.
395
-     * @return void
396
-     */
397
-    public function register_custom_nav_menu_boxes()
398
-    {
399
-        add_meta_box(
400
-            'add-extra-nav-menu-pages',
401
-            esc_html__('Event Espresso Pages', 'event_espresso'),
402
-            array($this, 'ee_cpt_archive_pages'),
403
-            'nav-menus',
404
-            'side',
405
-            'core'
406
-        );
407
-    }
408
-
409
-
410
-    /**
411
-     * Use this to edit the post link for our cpts so that the edit link points to the correct page.
412
-     *
413
-     * @since   4.3.0
414
-     * @param string $link the original link generated by wp
415
-     * @param int    $id   post id
416
-     * @return string  the (maybe) modified link
417
-     */
418
-    public function modify_edit_post_link($link, $id)
419
-    {
420
-        if (! $post = get_post($id)) {
421
-            return $link;
422
-        }
423
-        if ($post->post_type === 'espresso_attendees') {
424
-            $query_args = array(
425
-                'action' => 'edit_attendee',
426
-                'post'   => $id,
427
-            );
428
-            return EEH_URL::add_query_args_and_nonce(
429
-                $query_args,
430
-                admin_url('admin.php?page=espresso_registrations')
431
-            );
432
-        }
433
-        return $link;
434
-    }
435
-
436
-
437
-    public function ee_cpt_archive_pages()
438
-    {
439
-        global $nav_menu_selected_id;
440
-        $db_fields = false;
441
-        $walker = new Walker_Nav_Menu_Checklist($db_fields);
442
-        $current_tab = 'event-archives';
443
-        $removed_args = array(
444
-            'action',
445
-            'customlink-tab',
446
-            'edit-menu-item',
447
-            'menu-item',
448
-            'page-tab',
449
-            '_wpnonce',
450
-        );
451
-        ?>
23
+	/**
24
+	 * @var EE_Admin $_instance
25
+	 */
26
+	private static $_instance;
27
+
28
+	/**
29
+	 * @var PersistentAdminNoticeManager $persistent_admin_notice_manager
30
+	 */
31
+	private $persistent_admin_notice_manager;
32
+
33
+	/**
34
+	 * @var LoaderInterface
35
+	 */
36
+	protected $loader;
37
+
38
+	/**
39
+	 * @singleton method used to instantiate class object
40
+	 * @return EE_Admin
41
+	 * @throws EE_Error
42
+	 */
43
+	public static function instance()
44
+	{
45
+		// check if class object is instantiated
46
+		if (! self::$_instance instanceof EE_Admin) {
47
+			self::$_instance = new self();
48
+		}
49
+		return self::$_instance;
50
+	}
51
+
52
+
53
+	/**
54
+	 * @return EE_Admin
55
+	 * @throws EE_Error
56
+	 */
57
+	public static function reset()
58
+	{
59
+		self::$_instance = null;
60
+		return self::instance();
61
+	}
62
+
63
+
64
+	/**
65
+	 * class constructor
66
+	 *
67
+	 * @throws EE_Error
68
+	 * @throws InvalidDataTypeException
69
+	 * @throws InvalidInterfaceException
70
+	 * @throws InvalidArgumentException
71
+	 */
72
+	protected function __construct()
73
+	{
74
+		// define global EE_Admin constants
75
+		$this->_define_all_constants();
76
+		// set autoloaders for our admin page classes based on included path information
77
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
78
+		// admin hooks
79
+		add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
80
+		// load EE_Request_Handler early
81
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request'));
82
+		add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
83
+		add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2);
84
+		add_action('wp_loaded', array($this, 'wp_loaded'), 100);
85
+		add_action('admin_init', array($this, 'admin_init'), 100);
86
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20);
87
+		add_action('admin_notices', array($this, 'display_admin_notices'), 10);
88
+		add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
89
+		add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
90
+		add_filter('admin_footer_text', array($this, 'espresso_admin_footer'));
91
+		add_action('load-plugins.php', array($this, 'hookIntoWpPluginsPage'));
92
+		// reset Environment config (we only do this on admin page loads);
93
+		EE_Registry::instance()->CFG->environment->recheck_values();
94
+		do_action('AHEE__EE_Admin__loaded');
95
+	}
96
+
97
+
98
+	/**
99
+	 * _define_all_constants
100
+	 * define constants that are set globally for all admin pages
101
+	 *
102
+	 * @return void
103
+	 */
104
+	private function _define_all_constants()
105
+	{
106
+		if (! defined('EE_ADMIN_URL')) {
107
+			define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
108
+			define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
109
+			define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS);
110
+			define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
111
+			define('WP_AJAX_URL', admin_url('admin-ajax.php'));
112
+		}
113
+	}
114
+
115
+
116
+	/**
117
+	 * filter_plugin_actions - adds links to the Plugins page listing
118
+	 *
119
+	 * @param    array  $links
120
+	 * @param    string $plugin
121
+	 * @return    array
122
+	 */
123
+	public function filter_plugin_actions($links, $plugin)
124
+	{
125
+		// set $main_file in stone
126
+		static $main_file;
127
+		// if $main_file is not set yet
128
+		if (! $main_file) {
129
+			$main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
130
+		}
131
+		if ($plugin === $main_file) {
132
+			// compare current plugin to this one
133
+			if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
134
+				$maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
135
+									. ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
136
+									. esc_html__('Maintenance Mode Active', 'event_espresso')
137
+									. '</a>';
138
+				array_unshift($links, $maintenance_link);
139
+			} else {
140
+				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
141
+									 . esc_html__('Settings', 'event_espresso')
142
+									 . '</a>';
143
+				$events_link = '<a href="admin.php?page=espresso_events">'
144
+							   . esc_html__('Events', 'event_espresso')
145
+							   . '</a>';
146
+				// add before other links
147
+				array_unshift($links, $org_settings_link, $events_link);
148
+			}
149
+		}
150
+		return $links;
151
+	}
152
+
153
+
154
+	/**
155
+	 * _get_request
156
+	 *
157
+	 * @return void
158
+	 * @throws EE_Error
159
+	 * @throws InvalidArgumentException
160
+	 * @throws InvalidDataTypeException
161
+	 * @throws InvalidInterfaceException
162
+	 * @throws ReflectionException
163
+	 */
164
+	public function get_request()
165
+	{
166
+		EE_Registry::instance()->load_core('Request_Handler');
167
+		EE_Registry::instance()->load_core('CPT_Strategy');
168
+	}
169
+
170
+
171
+	/**
172
+	 * hide_admin_pages_except_maintenance_mode
173
+	 *
174
+	 * @param array $admin_page_folder_names
175
+	 * @return array
176
+	 */
177
+	public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
178
+	{
179
+		return array(
180
+			'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
181
+			'about'       => EE_ADMIN_PAGES . 'about' . DS,
182
+			'support'     => EE_ADMIN_PAGES . 'support' . DS,
183
+		);
184
+	}
185
+
186
+
187
+	/**
188
+	 * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
189
+	 * EE_Front_Controller's init phases have run
190
+	 *
191
+	 * @return void
192
+	 * @throws EE_Error
193
+	 * @throws InvalidArgumentException
194
+	 * @throws InvalidDataTypeException
195
+	 * @throws InvalidInterfaceException
196
+	 * @throws ReflectionException
197
+	 * @throws ServiceNotFoundException
198
+	 */
199
+	public function init()
200
+	{
201
+		// only enable most of the EE_Admin IF we're not in full maintenance mode
202
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
203
+			$this->initModelsReady();
204
+		}
205
+		// run the admin page factory but ONLY if we are doing an ee admin ajax request
206
+		if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
207
+			try {
208
+				// this loads the controller for the admin pages which will setup routing etc
209
+				EE_Registry::instance()->load_core('Admin_Page_Loader');
210
+			} catch (EE_Error $e) {
211
+				$e->get_error();
212
+			}
213
+		}
214
+		add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
215
+		// make sure our CPTs and custom taxonomy metaboxes get shown for first time users
216
+		add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
217
+		add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
218
+		// exclude EE critical pages from all nav menus and wp_list_pages
219
+		add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
220
+	}
221
+
222
+
223
+	/**
224
+	 * Gets the loader (and if it wasn't previously set, sets it)
225
+	 * @return LoaderInterface
226
+	 * @throws InvalidArgumentException
227
+	 * @throws InvalidDataTypeException
228
+	 * @throws InvalidInterfaceException
229
+	 */
230
+	protected function getLoader()
231
+	{
232
+		if (! $this->loader instanceof LoaderInterface) {
233
+			$this->loader = LoaderFactory::getLoader();
234
+		}
235
+		return $this->loader;
236
+	}
237
+
238
+
239
+	/**
240
+	 * Method that's fired on admin requests (including admin ajax) but only when the models are usable
241
+	 * (ie, the site isn't in maintenance mode)
242
+	 * @since 4.9.63.p
243
+	 * @return void
244
+	 */
245
+	protected function initModelsReady()
246
+	{
247
+		// ok so we want to enable the entire admin
248
+		$this->persistent_admin_notice_manager = $this->getLoader()->getShared(
249
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
250
+		);
251
+		$this->persistent_admin_notice_manager->setReturnUrl(
252
+			EE_Admin_Page::add_query_args_and_nonce(
253
+				array(
254
+					'page'   => EE_Registry::instance()->REQ->get('page', ''),
255
+					'action' => EE_Registry::instance()->REQ->get('action', ''),
256
+				),
257
+				EE_ADMIN_URL
258
+			)
259
+		);
260
+		$this->maybeSetDatetimeWarningNotice();
261
+		// at a glance dashboard widget
262
+		add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
263
+		// filter for get_edit_post_link used on comments for custom post types
264
+		add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
265
+	}
266
+
267
+
268
+	/**
269
+	 *    get_persistent_admin_notices
270
+	 *
271
+	 * @access    public
272
+	 * @return void
273
+	 * @throws EE_Error
274
+	 * @throws InvalidArgumentException
275
+	 * @throws InvalidDataTypeException
276
+	 * @throws InvalidInterfaceException
277
+	 */
278
+	public function maybeSetDatetimeWarningNotice()
279
+	{
280
+		// add dismissable notice for datetime changes.  Only valid if site does not have a timezone_string set.
281
+		// @todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
282
+		// with this.  But after enough time (indeterminate at this point) we can just remove this notice.
283
+		// this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
284
+		if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true)
285
+			&& ! get_option('timezone_string')
286
+			&& EEM_Event::instance()->count() > 0
287
+		) {
288
+			new PersistentAdminNotice(
289
+				'datetime_fix_notice',
290
+				sprintf(
291
+					esc_html__(
292
+						'%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times.  Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.',
293
+						'event_espresso'
294
+					),
295
+					'<strong>',
296
+					'</strong>',
297
+					'<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
298
+					'</a>',
299
+					'<a href="' . EE_Admin_Page::add_query_args_and_nonce(
300
+						array(
301
+							'page'   => 'espresso_maintenance_settings',
302
+							'action' => 'datetime_tools',
303
+						),
304
+						admin_url('admin.php')
305
+					) . '">'
306
+				),
307
+				false,
308
+				'manage_options',
309
+				'datetime_fix_persistent_notice'
310
+			);
311
+		}
312
+	}
313
+
314
+
315
+	/**
316
+	 * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
317
+	 * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
318
+	 * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
319
+	 * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
320
+	 * normal property on the post_type object.  It's found ONLY in this particular context.
321
+	 *
322
+	 * @param WP_Post $post_type WP post type object
323
+	 * @return WP_Post
324
+	 * @throws InvalidArgumentException
325
+	 * @throws InvalidDataTypeException
326
+	 * @throws InvalidInterfaceException
327
+	 */
328
+	public function remove_pages_from_nav_menu($post_type)
329
+	{
330
+		// if this isn't the "pages" post type let's get out
331
+		if ($post_type->name !== 'page') {
332
+			return $post_type;
333
+		}
334
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
335
+		$post_type->_default_query = array(
336
+			'post__not_in' => $critical_pages,
337
+		);
338
+		return $post_type;
339
+	}
340
+
341
+
342
+	/**
343
+	 * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
344
+	 * metaboxes get shown as well
345
+	 *
346
+	 * @return void
347
+	 */
348
+	public function enable_hidden_ee_nav_menu_metaboxes()
349
+	{
350
+		global $wp_meta_boxes, $pagenow;
351
+		if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
352
+			return;
353
+		}
354
+		$user = wp_get_current_user();
355
+		// has this been done yet?
356
+		if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
357
+			return;
358
+		}
359
+
360
+		$hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID);
361
+		$initial_meta_boxes = apply_filters(
362
+			'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
363
+			array(
364
+				'nav-menu-theme-locations',
365
+				'add-page',
366
+				'add-custom-links',
367
+				'add-category',
368
+				'add-espresso_events',
369
+				'add-espresso_venues',
370
+				'add-espresso_event_categories',
371
+				'add-espresso_venue_categories',
372
+				'add-post-type-post',
373
+				'add-post-type-page',
374
+			)
375
+		);
376
+
377
+		if (is_array($hidden_meta_boxes)) {
378
+			foreach ($hidden_meta_boxes as $key => $meta_box_id) {
379
+				if (in_array($meta_box_id, $initial_meta_boxes, true)) {
380
+					unset($hidden_meta_boxes[ $key ]);
381
+				}
382
+			}
383
+		}
384
+		update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
385
+		update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
386
+	}
387
+
388
+
389
+	/**
390
+	 * This method simply registers custom nav menu boxes for "nav_menus.php route"
391
+	 * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
392
+	 *
393
+	 * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
394
+	 *         addons etc.
395
+	 * @return void
396
+	 */
397
+	public function register_custom_nav_menu_boxes()
398
+	{
399
+		add_meta_box(
400
+			'add-extra-nav-menu-pages',
401
+			esc_html__('Event Espresso Pages', 'event_espresso'),
402
+			array($this, 'ee_cpt_archive_pages'),
403
+			'nav-menus',
404
+			'side',
405
+			'core'
406
+		);
407
+	}
408
+
409
+
410
+	/**
411
+	 * Use this to edit the post link for our cpts so that the edit link points to the correct page.
412
+	 *
413
+	 * @since   4.3.0
414
+	 * @param string $link the original link generated by wp
415
+	 * @param int    $id   post id
416
+	 * @return string  the (maybe) modified link
417
+	 */
418
+	public function modify_edit_post_link($link, $id)
419
+	{
420
+		if (! $post = get_post($id)) {
421
+			return $link;
422
+		}
423
+		if ($post->post_type === 'espresso_attendees') {
424
+			$query_args = array(
425
+				'action' => 'edit_attendee',
426
+				'post'   => $id,
427
+			);
428
+			return EEH_URL::add_query_args_and_nonce(
429
+				$query_args,
430
+				admin_url('admin.php?page=espresso_registrations')
431
+			);
432
+		}
433
+		return $link;
434
+	}
435
+
436
+
437
+	public function ee_cpt_archive_pages()
438
+	{
439
+		global $nav_menu_selected_id;
440
+		$db_fields = false;
441
+		$walker = new Walker_Nav_Menu_Checklist($db_fields);
442
+		$current_tab = 'event-archives';
443
+		$removed_args = array(
444
+			'action',
445
+			'customlink-tab',
446
+			'edit-menu-item',
447
+			'menu-item',
448
+			'page-tab',
449
+			'_wpnonce',
450
+		);
451
+		?>
452 452
         <div id="posttype-extra-nav-menu-pages" class="posttypediv">
453 453
             <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs">
454 454
                 <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>>
455 455
                     <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives"
456 456
                        href="<?php
457
-                        if ($nav_menu_selected_id) {
458
-                            echo esc_url(
459
-                                add_query_arg(
460
-                                    'extra-nav-menu-pages-tab',
461
-                                    'event-archives',
462
-                                    remove_query_arg($removed_args)
463
-                                )
464
-                            );
465
-                        }
466
-                        ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
457
+						if ($nav_menu_selected_id) {
458
+							echo esc_url(
459
+								add_query_arg(
460
+									'extra-nav-menu-pages-tab',
461
+									'event-archives',
462
+									remove_query_arg($removed_args)
463
+								)
464
+							);
465
+						}
466
+						?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
467 467
                         <?php _e('Event Archive Pages', 'event_espresso'); ?>
468 468
                     </a>
469 469
                 </li>
470 470
             </ul><!-- .posttype-tabs -->
471 471
 
472 472
             <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php
473
-            echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
474
-            ?>">
473
+			echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
474
+			?>">
475 475
                 <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear">
476 476
                     <?php
477
-                    $pages = $this->_get_extra_nav_menu_pages_items();
478
-                    $args['walker'] = $walker;
479
-                    echo walk_nav_menu_tree(
480
-                        array_map(
481
-                            array($this, '_setup_extra_nav_menu_pages_items'),
482
-                            $pages
483
-                        ),
484
-                        0,
485
-                        (object) $args
486
-                    );
487
-                    ?>
477
+					$pages = $this->_get_extra_nav_menu_pages_items();
478
+					$args['walker'] = $walker;
479
+					echo walk_nav_menu_tree(
480
+						array_map(
481
+							array($this, '_setup_extra_nav_menu_pages_items'),
482
+							$pages
483
+						),
484
+						0,
485
+						(object) $args
486
+					);
487
+					?>
488 488
                 </ul>
489 489
             </div><!-- /.tabs-panel -->
490 490
 
491 491
             <p class="button-controls">
492 492
                 <span class="list-controls">
493 493
                     <a href="<?php
494
-                             echo esc_url(
495
-                                 add_query_arg(
496
-                                     array(
497
-                                         'extra-nav-menu-pages-tab' => 'event-archives',
498
-                                         'selectall'                => 1,
499
-                                     ),
500
-                                     remove_query_arg($removed_args)
501
-                                 )
502
-                             );
503
-                        ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All', 'event_espresso'); ?></a>
494
+							 echo esc_url(
495
+								 add_query_arg(
496
+									 array(
497
+										 'extra-nav-menu-pages-tab' => 'event-archives',
498
+										 'selectall'                => 1,
499
+									 ),
500
+									 remove_query_arg($removed_args)
501
+								 )
502
+							 );
503
+						?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All', 'event_espresso'); ?></a>
504 504
                 </span>
505 505
                 <span class="add-to-menu">
506 506
                     <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?>
@@ -513,500 +513,500 @@  discard block
 block discarded – undo
513 513
 
514 514
         </div><!-- /.posttypediv -->
515 515
         <?php
516
-    }
517
-
518
-
519
-    /**
520
-     * Returns an array of event archive nav items.
521
-     *
522
-     * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
523
-     *        method we use for getting the extra nav menu items
524
-     * @return array
525
-     */
526
-    private function _get_extra_nav_menu_pages_items()
527
-    {
528
-        $menuitems[] = array(
529
-            'title'       => esc_html__('Event List', 'event_espresso'),
530
-            'url'         => get_post_type_archive_link('espresso_events'),
531
-            'description' => esc_html__('Archive page for all events.', 'event_espresso'),
532
-        );
533
-        return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
534
-    }
535
-
536
-
537
-    /**
538
-     * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
539
-     * the properties and converts it to the menu item object.
540
-     *
541
-     * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
542
-     * @param $menu_item_values
543
-     * @return stdClass
544
-     */
545
-    private function _setup_extra_nav_menu_pages_items($menu_item_values)
546
-    {
547
-        $menu_item = new stdClass();
548
-        $keys = array(
549
-            'ID'               => 0,
550
-            'db_id'            => 0,
551
-            'menu_item_parent' => 0,
552
-            'object_id'        => -1,
553
-            'post_parent'      => 0,
554
-            'type'             => 'custom',
555
-            'object'           => '',
556
-            'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
557
-            'title'            => '',
558
-            'url'              => '',
559
-            'target'           => '',
560
-            'attr_title'       => '',
561
-            'description'      => '',
562
-            'classes'          => array(),
563
-            'xfn'              => '',
564
-        );
565
-
566
-        foreach ($keys as $key => $value) {
567
-            $menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value;
568
-        }
569
-        return $menu_item;
570
-    }
571
-
572
-
573
-    /**
574
-     * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
575
-     * EE_Admin_Page route is called.
576
-     *
577
-     * @return void
578
-     */
579
-    public function route_admin_request()
580
-    {
581
-    }
582
-
583
-
584
-    /**
585
-     * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
586
-     *
587
-     * @return void
588
-     */
589
-    public function wp_loaded()
590
-    {
591
-    }
592
-
593
-
594
-    /**
595
-     * admin_init
596
-     *
597
-     * @return void
598
-     * @throws EE_Error
599
-     * @throws InvalidArgumentException
600
-     * @throws InvalidDataTypeException
601
-     * @throws InvalidInterfaceException
602
-     * @throws ReflectionException
603
-     */
604
-    public function admin_init()
605
-    {
606
-        /**
607
-         * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
608
-         * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
609
-         * - check if doing post processing.
610
-         * - check if doing post processing of one of EE CPTs
611
-         * - instantiate the corresponding EE CPT model for the post_type being processed.
612
-         */
613
-        if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
614
-            /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
615
-            $custom_post_types = $this->getLoader()->getShared(
616
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
617
-            );
618
-            $custom_post_types->getCustomPostTypeModels($_POST['post_type']);
619
-        }
620
-
621
-
622
-        /**
623
-         * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
624
-         * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
625
-         * Pages" tab in the EE General Settings Admin page.
626
-         * This is for user-proofing.
627
-         */
628
-        add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
629
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
630
-            $this->adminInitModelsReady();
631
-        }
632
-    }
633
-
634
-
635
-    /**
636
-     * Runs on admin_init but only if models are usable (ie, we're not in maintenanc emode)
637
-     */
638
-    protected function adminInitModelsReady()
639
-    {
640
-        if (function_exists('wp_add_privacy_policy_content')) {
641
-            $this->getLoader()->getShared('EventEspresso\core\services\privacy\policy\PrivacyPolicyManager');
642
-        }
643
-    }
644
-
645
-
646
-    /**
647
-     * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
648
-     *
649
-     * @param string $output Current output.
650
-     * @return string
651
-     * @throws InvalidArgumentException
652
-     * @throws InvalidDataTypeException
653
-     * @throws InvalidInterfaceException
654
-     */
655
-    public function modify_dropdown_pages($output)
656
-    {
657
-        // get critical pages
658
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
659
-
660
-        // split current output by line break for easier parsing.
661
-        $split_output = explode("\n", $output);
662
-
663
-        // loop through to remove any critical pages from the array.
664
-        foreach ($critical_pages as $page_id) {
665
-            $needle = 'value="' . $page_id . '"';
666
-            foreach ($split_output as $key => $haystack) {
667
-                if (strpos($haystack, $needle) !== false) {
668
-                    unset($split_output[ $key ]);
669
-                }
670
-            }
671
-        }
672
-        // replace output with the new contents
673
-        return implode("\n", $split_output);
674
-    }
675
-
676
-
677
-    /**
678
-     * enqueue all admin scripts that need loaded for admin pages
679
-     *
680
-     * @return void
681
-     */
682
-    public function enqueue_admin_scripts()
683
-    {
684
-        // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
685
-        // Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
686
-        // calls.
687
-        wp_enqueue_script(
688
-            'ee-inject-wp',
689
-            EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
690
-            array('jquery'),
691
-            EVENT_ESPRESSO_VERSION,
692
-            true
693
-        );
694
-        // register cookie script for future dependencies
695
-        wp_register_script(
696
-            'jquery-cookie',
697
-            EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
698
-            array('jquery'),
699
-            '2.1',
700
-            true
701
-        );
702
-        // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again
703
-        // via: add_filter('FHEE_load_joyride', '__return_true' );
704
-        if (apply_filters('FHEE_load_joyride', false)) {
705
-            // joyride style
706
-            wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
707
-            wp_register_style(
708
-                'ee-joyride-css',
709
-                EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
710
-                array('joyride-css'),
711
-                EVENT_ESPRESSO_VERSION
712
-            );
713
-            wp_register_script(
714
-                'joyride-modernizr',
715
-                EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
716
-                array(),
717
-                '2.1',
718
-                true
719
-            );
720
-            // joyride JS
721
-            wp_register_script(
722
-                'jquery-joyride',
723
-                EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
724
-                array('jquery-cookie', 'joyride-modernizr'),
725
-                '2.1',
726
-                true
727
-            );
728
-            // wanna go for a joyride?
729
-            wp_enqueue_style('ee-joyride-css');
730
-            wp_enqueue_script('jquery-joyride');
731
-        }
732
-    }
733
-
734
-
735
-    /**
736
-     * display_admin_notices
737
-     *
738
-     * @return void
739
-     */
740
-    public function display_admin_notices()
741
-    {
742
-        echo EE_Error::get_notices();
743
-    }
744
-
745
-
746
-    /**
747
-     * @param array $elements
748
-     * @return array
749
-     * @throws EE_Error
750
-     * @throws InvalidArgumentException
751
-     * @throws InvalidDataTypeException
752
-     * @throws InvalidInterfaceException
753
-     */
754
-    public function dashboard_glance_items($elements)
755
-    {
756
-        $elements = is_array($elements) ? $elements : array($elements);
757
-        $events = EEM_Event::instance()->count();
758
-        $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(
759
-            array('page' => 'espresso_events'),
760
-            admin_url('admin.php')
761
-        );
762
-        $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events, 'event_espresso'), number_format_i18n($events));
763
-        $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso');
764
-        $registrations = EEM_Registration::instance()->count(
765
-            array(
766
-                array(
767
-                    'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
768
-                ),
769
-            )
770
-        );
771
-        $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(
772
-            array('page' => 'espresso_registrations'),
773
-            admin_url('admin.php')
774
-        );
775
-        $items['registrations']['text'] = sprintf(
776
-            _n('%s Registration', '%s Registrations', $registrations, 'event_espresso'),
777
-            number_format_i18n($registrations)
778
-        );
779
-        $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
780
-
781
-        $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
782
-
783
-        foreach ($items as $type => $item_properties) {
784
-            $elements[] = sprintf(
785
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
786
-                $item_properties['url'],
787
-                $item_properties['title'],
788
-                $item_properties['text']
789
-            );
790
-        }
791
-        return $elements;
792
-    }
793
-
794
-
795
-    /**
796
-     * check_for_invalid_datetime_formats
797
-     * if an admin changes their date or time format settings on the WP General Settings admin page, verify that
798
-     * their selected format can be parsed by PHP
799
-     *
800
-     * @param    $value
801
-     * @param    $option
802
-     * @throws EE_Error
803
-     * @return    string
804
-     */
805
-    public function check_for_invalid_datetime_formats($value, $option)
806
-    {
807
-        // check for date_format or time_format
808
-        switch ($option) {
809
-            case 'date_format':
810
-                $date_time_format = $value . ' ' . get_option('time_format');
811
-                break;
812
-            case 'time_format':
813
-                $date_time_format = get_option('date_format') . ' ' . $value;
814
-                break;
815
-            default:
816
-                $date_time_format = false;
817
-        }
818
-        // do we have a date_time format to check ?
819
-        if ($date_time_format) {
820
-            $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
821
-
822
-            if (is_array($error_msg)) {
823
-                $msg = '<p>'
824
-                       . sprintf(
825
-                           esc_html__(
826
-                               'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
827
-                               'event_espresso'
828
-                           ),
829
-                           date($date_time_format),
830
-                           $date_time_format
831
-                       )
832
-                       . '</p><p><ul>';
833
-
834
-
835
-                foreach ($error_msg as $error) {
836
-                    $msg .= '<li>' . $error . '</li>';
837
-                }
838
-
839
-                $msg .= '</ul></p><p>'
840
-                        . sprintf(
841
-                            esc_html__(
842
-                                '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
843
-                                'event_espresso'
844
-                            ),
845
-                            '<span style="color:#D54E21;">',
846
-                            '</span>'
847
-                        )
848
-                        . '</p>';
849
-
850
-                // trigger WP settings error
851
-                add_settings_error(
852
-                    'date_format',
853
-                    'date_format',
854
-                    $msg
855
-                );
856
-
857
-                // set format to something valid
858
-                switch ($option) {
859
-                    case 'date_format':
860
-                        $value = 'F j, Y';
861
-                        break;
862
-                    case 'time_format':
863
-                        $value = 'g:i a';
864
-                        break;
865
-                }
866
-            }
867
-        }
868
-        return $value;
869
-    }
870
-
871
-
872
-    /**
873
-     * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
874
-     *
875
-     * @param $content
876
-     * @return    string
877
-     */
878
-    public function its_eSpresso($content)
879
-    {
880
-        return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
881
-    }
882
-
883
-
884
-    /**
885
-     * espresso_admin_footer
886
-     *
887
-     * @return    string
888
-     */
889
-    public function espresso_admin_footer()
890
-    {
891
-        return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
892
-    }
893
-
894
-
895
-    /**
896
-     * static method for registering ee admin page.
897
-     * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
898
-     *
899
-     * @since      4.3.0
900
-     * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
901
-     * @see        EE_Register_Admin_Page::register()
902
-     * @param       $page_basename
903
-     * @param       $page_path
904
-     * @param array $config
905
-     * @return void
906
-     * @throws EE_Error
907
-     */
908
-    public static function register_ee_admin_page($page_basename, $page_path, $config = array())
909
-    {
910
-        EE_Error::doing_it_wrong(
911
-            __METHOD__,
912
-            sprintf(
913
-                esc_html__(
914
-                    'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
915
-                    'event_espresso'
916
-                ),
917
-                $page_basename
918
-            ),
919
-            '4.3'
920
-        );
921
-        if (class_exists('EE_Register_Admin_Page')) {
922
-            $config['page_path'] = $page_path;
923
-        }
924
-        EE_Register_Admin_Page::register($page_basename, $config);
925
-    }
926
-
927
-
928
-    /**
929
-     * @deprecated 4.8.41
930
-     * @param  int      $post_ID
931
-     * @param  \WP_Post $post
932
-     * @return void
933
-     */
934
-    public static function parse_post_content_on_save($post_ID, $post)
935
-    {
936
-        EE_Error::doing_it_wrong(
937
-            __METHOD__,
938
-            esc_html__('Usage is deprecated', 'event_espresso'),
939
-            '4.8.41'
940
-        );
941
-    }
942
-
943
-
944
-    /**
945
-     * @deprecated 4.8.41
946
-     * @param  $option
947
-     * @param  $old_value
948
-     * @param  $value
949
-     * @return void
950
-     */
951
-    public function reset_page_for_posts_on_change($option, $old_value, $value)
952
-    {
953
-        EE_Error::doing_it_wrong(
954
-            __METHOD__,
955
-            esc_html__('Usage is deprecated', 'event_espresso'),
956
-            '4.8.41'
957
-        );
958
-    }
959
-
960
-
961
-    /**
962
-     * @deprecated 4.9.27
963
-     * @return void
964
-     */
965
-    public function get_persistent_admin_notices()
966
-    {
967
-        EE_Error::doing_it_wrong(
968
-            __METHOD__,
969
-            sprintf(
970
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
971
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
972
-            ),
973
-            '4.9.27'
974
-        );
975
-    }
976
-
977
-
978
-    /**
979
-     * @deprecated 4.9.27
980
-     * @throws InvalidInterfaceException
981
-     * @throws InvalidDataTypeException
982
-     * @throws DomainException
983
-     */
984
-    public function dismiss_ee_nag_notice_callback()
985
-    {
986
-        EE_Error::doing_it_wrong(
987
-            __METHOD__,
988
-            sprintf(
989
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
990
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
991
-            ),
992
-            '4.9.27'
993
-        );
994
-        $this->persistent_admin_notice_manager->dismissNotice();
995
-    }
996
-
997
-
998
-    /**
999
-     * Callback on load-plugins.php hook for setting up anything hooking into the wp plugins page.
1000
-     *
1001
-     * @throws InvalidArgumentException
1002
-     * @throws InvalidDataTypeException
1003
-     * @throws InvalidInterfaceException
1004
-     */
1005
-    public function hookIntoWpPluginsPage()
1006
-    {
1007
-        $this->getLoader()->getShared('EventEspresso\core\domain\services\admin\ExitModal');
1008
-        $this->getLoader()
1009
-                     ->getShared('EventEspresso\core\domain\services\admin\PluginUpsells')
1010
-                     ->decafUpsells();
1011
-    }
516
+	}
517
+
518
+
519
+	/**
520
+	 * Returns an array of event archive nav items.
521
+	 *
522
+	 * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
523
+	 *        method we use for getting the extra nav menu items
524
+	 * @return array
525
+	 */
526
+	private function _get_extra_nav_menu_pages_items()
527
+	{
528
+		$menuitems[] = array(
529
+			'title'       => esc_html__('Event List', 'event_espresso'),
530
+			'url'         => get_post_type_archive_link('espresso_events'),
531
+			'description' => esc_html__('Archive page for all events.', 'event_espresso'),
532
+		);
533
+		return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
534
+	}
535
+
536
+
537
+	/**
538
+	 * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
539
+	 * the properties and converts it to the menu item object.
540
+	 *
541
+	 * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
542
+	 * @param $menu_item_values
543
+	 * @return stdClass
544
+	 */
545
+	private function _setup_extra_nav_menu_pages_items($menu_item_values)
546
+	{
547
+		$menu_item = new stdClass();
548
+		$keys = array(
549
+			'ID'               => 0,
550
+			'db_id'            => 0,
551
+			'menu_item_parent' => 0,
552
+			'object_id'        => -1,
553
+			'post_parent'      => 0,
554
+			'type'             => 'custom',
555
+			'object'           => '',
556
+			'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
557
+			'title'            => '',
558
+			'url'              => '',
559
+			'target'           => '',
560
+			'attr_title'       => '',
561
+			'description'      => '',
562
+			'classes'          => array(),
563
+			'xfn'              => '',
564
+		);
565
+
566
+		foreach ($keys as $key => $value) {
567
+			$menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value;
568
+		}
569
+		return $menu_item;
570
+	}
571
+
572
+
573
+	/**
574
+	 * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
575
+	 * EE_Admin_Page route is called.
576
+	 *
577
+	 * @return void
578
+	 */
579
+	public function route_admin_request()
580
+	{
581
+	}
582
+
583
+
584
+	/**
585
+	 * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
586
+	 *
587
+	 * @return void
588
+	 */
589
+	public function wp_loaded()
590
+	{
591
+	}
592
+
593
+
594
+	/**
595
+	 * admin_init
596
+	 *
597
+	 * @return void
598
+	 * @throws EE_Error
599
+	 * @throws InvalidArgumentException
600
+	 * @throws InvalidDataTypeException
601
+	 * @throws InvalidInterfaceException
602
+	 * @throws ReflectionException
603
+	 */
604
+	public function admin_init()
605
+	{
606
+		/**
607
+		 * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
608
+		 * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
609
+		 * - check if doing post processing.
610
+		 * - check if doing post processing of one of EE CPTs
611
+		 * - instantiate the corresponding EE CPT model for the post_type being processed.
612
+		 */
613
+		if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
614
+			/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
615
+			$custom_post_types = $this->getLoader()->getShared(
616
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
617
+			);
618
+			$custom_post_types->getCustomPostTypeModels($_POST['post_type']);
619
+		}
620
+
621
+
622
+		/**
623
+		 * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
624
+		 * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
625
+		 * Pages" tab in the EE General Settings Admin page.
626
+		 * This is for user-proofing.
627
+		 */
628
+		add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
629
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
630
+			$this->adminInitModelsReady();
631
+		}
632
+	}
633
+
634
+
635
+	/**
636
+	 * Runs on admin_init but only if models are usable (ie, we're not in maintenanc emode)
637
+	 */
638
+	protected function adminInitModelsReady()
639
+	{
640
+		if (function_exists('wp_add_privacy_policy_content')) {
641
+			$this->getLoader()->getShared('EventEspresso\core\services\privacy\policy\PrivacyPolicyManager');
642
+		}
643
+	}
644
+
645
+
646
+	/**
647
+	 * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
648
+	 *
649
+	 * @param string $output Current output.
650
+	 * @return string
651
+	 * @throws InvalidArgumentException
652
+	 * @throws InvalidDataTypeException
653
+	 * @throws InvalidInterfaceException
654
+	 */
655
+	public function modify_dropdown_pages($output)
656
+	{
657
+		// get critical pages
658
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
659
+
660
+		// split current output by line break for easier parsing.
661
+		$split_output = explode("\n", $output);
662
+
663
+		// loop through to remove any critical pages from the array.
664
+		foreach ($critical_pages as $page_id) {
665
+			$needle = 'value="' . $page_id . '"';
666
+			foreach ($split_output as $key => $haystack) {
667
+				if (strpos($haystack, $needle) !== false) {
668
+					unset($split_output[ $key ]);
669
+				}
670
+			}
671
+		}
672
+		// replace output with the new contents
673
+		return implode("\n", $split_output);
674
+	}
675
+
676
+
677
+	/**
678
+	 * enqueue all admin scripts that need loaded for admin pages
679
+	 *
680
+	 * @return void
681
+	 */
682
+	public function enqueue_admin_scripts()
683
+	{
684
+		// this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
685
+		// Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
686
+		// calls.
687
+		wp_enqueue_script(
688
+			'ee-inject-wp',
689
+			EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
690
+			array('jquery'),
691
+			EVENT_ESPRESSO_VERSION,
692
+			true
693
+		);
694
+		// register cookie script for future dependencies
695
+		wp_register_script(
696
+			'jquery-cookie',
697
+			EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
698
+			array('jquery'),
699
+			'2.1',
700
+			true
701
+		);
702
+		// joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again
703
+		// via: add_filter('FHEE_load_joyride', '__return_true' );
704
+		if (apply_filters('FHEE_load_joyride', false)) {
705
+			// joyride style
706
+			wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
707
+			wp_register_style(
708
+				'ee-joyride-css',
709
+				EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
710
+				array('joyride-css'),
711
+				EVENT_ESPRESSO_VERSION
712
+			);
713
+			wp_register_script(
714
+				'joyride-modernizr',
715
+				EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
716
+				array(),
717
+				'2.1',
718
+				true
719
+			);
720
+			// joyride JS
721
+			wp_register_script(
722
+				'jquery-joyride',
723
+				EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
724
+				array('jquery-cookie', 'joyride-modernizr'),
725
+				'2.1',
726
+				true
727
+			);
728
+			// wanna go for a joyride?
729
+			wp_enqueue_style('ee-joyride-css');
730
+			wp_enqueue_script('jquery-joyride');
731
+		}
732
+	}
733
+
734
+
735
+	/**
736
+	 * display_admin_notices
737
+	 *
738
+	 * @return void
739
+	 */
740
+	public function display_admin_notices()
741
+	{
742
+		echo EE_Error::get_notices();
743
+	}
744
+
745
+
746
+	/**
747
+	 * @param array $elements
748
+	 * @return array
749
+	 * @throws EE_Error
750
+	 * @throws InvalidArgumentException
751
+	 * @throws InvalidDataTypeException
752
+	 * @throws InvalidInterfaceException
753
+	 */
754
+	public function dashboard_glance_items($elements)
755
+	{
756
+		$elements = is_array($elements) ? $elements : array($elements);
757
+		$events = EEM_Event::instance()->count();
758
+		$items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(
759
+			array('page' => 'espresso_events'),
760
+			admin_url('admin.php')
761
+		);
762
+		$items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events, 'event_espresso'), number_format_i18n($events));
763
+		$items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso');
764
+		$registrations = EEM_Registration::instance()->count(
765
+			array(
766
+				array(
767
+					'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
768
+				),
769
+			)
770
+		);
771
+		$items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(
772
+			array('page' => 'espresso_registrations'),
773
+			admin_url('admin.php')
774
+		);
775
+		$items['registrations']['text'] = sprintf(
776
+			_n('%s Registration', '%s Registrations', $registrations, 'event_espresso'),
777
+			number_format_i18n($registrations)
778
+		);
779
+		$items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
780
+
781
+		$items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
782
+
783
+		foreach ($items as $type => $item_properties) {
784
+			$elements[] = sprintf(
785
+				'<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
786
+				$item_properties['url'],
787
+				$item_properties['title'],
788
+				$item_properties['text']
789
+			);
790
+		}
791
+		return $elements;
792
+	}
793
+
794
+
795
+	/**
796
+	 * check_for_invalid_datetime_formats
797
+	 * if an admin changes their date or time format settings on the WP General Settings admin page, verify that
798
+	 * their selected format can be parsed by PHP
799
+	 *
800
+	 * @param    $value
801
+	 * @param    $option
802
+	 * @throws EE_Error
803
+	 * @return    string
804
+	 */
805
+	public function check_for_invalid_datetime_formats($value, $option)
806
+	{
807
+		// check for date_format or time_format
808
+		switch ($option) {
809
+			case 'date_format':
810
+				$date_time_format = $value . ' ' . get_option('time_format');
811
+				break;
812
+			case 'time_format':
813
+				$date_time_format = get_option('date_format') . ' ' . $value;
814
+				break;
815
+			default:
816
+				$date_time_format = false;
817
+		}
818
+		// do we have a date_time format to check ?
819
+		if ($date_time_format) {
820
+			$error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
821
+
822
+			if (is_array($error_msg)) {
823
+				$msg = '<p>'
824
+					   . sprintf(
825
+						   esc_html__(
826
+							   'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
827
+							   'event_espresso'
828
+						   ),
829
+						   date($date_time_format),
830
+						   $date_time_format
831
+					   )
832
+					   . '</p><p><ul>';
833
+
834
+
835
+				foreach ($error_msg as $error) {
836
+					$msg .= '<li>' . $error . '</li>';
837
+				}
838
+
839
+				$msg .= '</ul></p><p>'
840
+						. sprintf(
841
+							esc_html__(
842
+								'%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
843
+								'event_espresso'
844
+							),
845
+							'<span style="color:#D54E21;">',
846
+							'</span>'
847
+						)
848
+						. '</p>';
849
+
850
+				// trigger WP settings error
851
+				add_settings_error(
852
+					'date_format',
853
+					'date_format',
854
+					$msg
855
+				);
856
+
857
+				// set format to something valid
858
+				switch ($option) {
859
+					case 'date_format':
860
+						$value = 'F j, Y';
861
+						break;
862
+					case 'time_format':
863
+						$value = 'g:i a';
864
+						break;
865
+				}
866
+			}
867
+		}
868
+		return $value;
869
+	}
870
+
871
+
872
+	/**
873
+	 * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
874
+	 *
875
+	 * @param $content
876
+	 * @return    string
877
+	 */
878
+	public function its_eSpresso($content)
879
+	{
880
+		return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
881
+	}
882
+
883
+
884
+	/**
885
+	 * espresso_admin_footer
886
+	 *
887
+	 * @return    string
888
+	 */
889
+	public function espresso_admin_footer()
890
+	{
891
+		return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
892
+	}
893
+
894
+
895
+	/**
896
+	 * static method for registering ee admin page.
897
+	 * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
898
+	 *
899
+	 * @since      4.3.0
900
+	 * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
901
+	 * @see        EE_Register_Admin_Page::register()
902
+	 * @param       $page_basename
903
+	 * @param       $page_path
904
+	 * @param array $config
905
+	 * @return void
906
+	 * @throws EE_Error
907
+	 */
908
+	public static function register_ee_admin_page($page_basename, $page_path, $config = array())
909
+	{
910
+		EE_Error::doing_it_wrong(
911
+			__METHOD__,
912
+			sprintf(
913
+				esc_html__(
914
+					'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
915
+					'event_espresso'
916
+				),
917
+				$page_basename
918
+			),
919
+			'4.3'
920
+		);
921
+		if (class_exists('EE_Register_Admin_Page')) {
922
+			$config['page_path'] = $page_path;
923
+		}
924
+		EE_Register_Admin_Page::register($page_basename, $config);
925
+	}
926
+
927
+
928
+	/**
929
+	 * @deprecated 4.8.41
930
+	 * @param  int      $post_ID
931
+	 * @param  \WP_Post $post
932
+	 * @return void
933
+	 */
934
+	public static function parse_post_content_on_save($post_ID, $post)
935
+	{
936
+		EE_Error::doing_it_wrong(
937
+			__METHOD__,
938
+			esc_html__('Usage is deprecated', 'event_espresso'),
939
+			'4.8.41'
940
+		);
941
+	}
942
+
943
+
944
+	/**
945
+	 * @deprecated 4.8.41
946
+	 * @param  $option
947
+	 * @param  $old_value
948
+	 * @param  $value
949
+	 * @return void
950
+	 */
951
+	public function reset_page_for_posts_on_change($option, $old_value, $value)
952
+	{
953
+		EE_Error::doing_it_wrong(
954
+			__METHOD__,
955
+			esc_html__('Usage is deprecated', 'event_espresso'),
956
+			'4.8.41'
957
+		);
958
+	}
959
+
960
+
961
+	/**
962
+	 * @deprecated 4.9.27
963
+	 * @return void
964
+	 */
965
+	public function get_persistent_admin_notices()
966
+	{
967
+		EE_Error::doing_it_wrong(
968
+			__METHOD__,
969
+			sprintf(
970
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
971
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
972
+			),
973
+			'4.9.27'
974
+		);
975
+	}
976
+
977
+
978
+	/**
979
+	 * @deprecated 4.9.27
980
+	 * @throws InvalidInterfaceException
981
+	 * @throws InvalidDataTypeException
982
+	 * @throws DomainException
983
+	 */
984
+	public function dismiss_ee_nag_notice_callback()
985
+	{
986
+		EE_Error::doing_it_wrong(
987
+			__METHOD__,
988
+			sprintf(
989
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
990
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
991
+			),
992
+			'4.9.27'
993
+		);
994
+		$this->persistent_admin_notice_manager->dismissNotice();
995
+	}
996
+
997
+
998
+	/**
999
+	 * Callback on load-plugins.php hook for setting up anything hooking into the wp plugins page.
1000
+	 *
1001
+	 * @throws InvalidArgumentException
1002
+	 * @throws InvalidDataTypeException
1003
+	 * @throws InvalidInterfaceException
1004
+	 */
1005
+	public function hookIntoWpPluginsPage()
1006
+	{
1007
+		$this->getLoader()->getShared('EventEspresso\core\domain\services\admin\ExitModal');
1008
+		$this->getLoader()
1009
+					 ->getShared('EventEspresso\core\domain\services\admin\PluginUpsells')
1010
+					 ->decafUpsells();
1011
+	}
1012 1012
 }
Please login to merge, or discard this patch.
core/CPTs/EE_CPT_Event_Strategy.core.php 1 patch
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -13,252 +13,252 @@
 block discarded – undo
13 13
 class EE_CPT_Event_Strategy
14 14
 {
15 15
 
16
-    /**
17
-     * the current page, if it utilizes CPTs
18
-     *
19
-     * @var object $CPT
20
-     */
21
-    protected $CPT;
16
+	/**
17
+	 * the current page, if it utilizes CPTs
18
+	 *
19
+	 * @var object $CPT
20
+	 */
21
+	protected $CPT;
22 22
 
23 23
 
24
-    /**
25
-     * @param WP_Query $wp_query
26
-     * @param array    $CPT
27
-     */
28
-    public function __construct($wp_query, $CPT = array())
29
-    {
30
-        if ($wp_query instanceof WP_Query) {
31
-            $WP_Query = $wp_query;
32
-            $this->CPT = $CPT;
33
-        } else {
34
-            $WP_Query = isset($wp_query['WP_Query']) ? $wp_query['WP_Query'] : null;
35
-            $this->CPT = isset($wp_query['CPT']) ? $wp_query['CPT'] : null;
36
-        }
37
-        // !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
38
-        // here's the list of available filters in the WP_Query object
39
-        // 'posts_where'
40
-        // 'posts_where_paged'
41
-        // 'posts_groupby'
42
-        // 'posts_join_paged'
43
-        // 'posts_orderby'
44
-        // 'posts_distinct'
45
-        // 'post_limits'
46
-        // 'posts_fields'
47
-        // 'posts_join'
48
-        $this->_add_filters();
49
-        if ($WP_Query instanceof WP_Query) {
50
-            $WP_Query->is_espresso_event_single = is_singular()
51
-                                                  && isset($WP_Query->query->post_type)
52
-                                                  && $WP_Query->query->post_type === 'espresso_events';
53
-            $WP_Query->is_espresso_event_archive = is_post_type_archive('espresso_events');
54
-            $WP_Query->is_espresso_event_taxonomy = is_tax('espresso_event_categories');
55
-        }
56
-    }
24
+	/**
25
+	 * @param WP_Query $wp_query
26
+	 * @param array    $CPT
27
+	 */
28
+	public function __construct($wp_query, $CPT = array())
29
+	{
30
+		if ($wp_query instanceof WP_Query) {
31
+			$WP_Query = $wp_query;
32
+			$this->CPT = $CPT;
33
+		} else {
34
+			$WP_Query = isset($wp_query['WP_Query']) ? $wp_query['WP_Query'] : null;
35
+			$this->CPT = isset($wp_query['CPT']) ? $wp_query['CPT'] : null;
36
+		}
37
+		// !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
38
+		// here's the list of available filters in the WP_Query object
39
+		// 'posts_where'
40
+		// 'posts_where_paged'
41
+		// 'posts_groupby'
42
+		// 'posts_join_paged'
43
+		// 'posts_orderby'
44
+		// 'posts_distinct'
45
+		// 'post_limits'
46
+		// 'posts_fields'
47
+		// 'posts_join'
48
+		$this->_add_filters();
49
+		if ($WP_Query instanceof WP_Query) {
50
+			$WP_Query->is_espresso_event_single = is_singular()
51
+												  && isset($WP_Query->query->post_type)
52
+												  && $WP_Query->query->post_type === 'espresso_events';
53
+			$WP_Query->is_espresso_event_archive = is_post_type_archive('espresso_events');
54
+			$WP_Query->is_espresso_event_taxonomy = is_tax('espresso_event_categories');
55
+		}
56
+	}
57 57
 
58 58
 
59
-    /**
60
-     * When an instance of this class is created, we add our filters
61
-     * (which will get removed in case the next call to get_posts ISN'T
62
-     * for event CPTs)
63
-     */
64
-    protected function _add_filters()
65
-    {
66
-        add_filter('posts_fields', array($this, 'posts_fields'), 1, 2);
67
-        add_filter('posts_join', array($this, 'posts_join'), 1, 2);
68
-        add_filter('posts_where', array($this, 'posts_where'), 10, 2);
69
-        // add_filter( 'the_posts', array( $this, 'the_posts' ), 1, 2 );
70
-        add_filter('posts_orderby', array($this, 'posts_orderby'), 1, 2);
71
-        add_filter('posts_groupby', array($this, 'posts_groupby'), 1, 2);
72
-        add_action('posts_selection', array($this, 'remove_filters'));
73
-    }
59
+	/**
60
+	 * When an instance of this class is created, we add our filters
61
+	 * (which will get removed in case the next call to get_posts ISN'T
62
+	 * for event CPTs)
63
+	 */
64
+	protected function _add_filters()
65
+	{
66
+		add_filter('posts_fields', array($this, 'posts_fields'), 1, 2);
67
+		add_filter('posts_join', array($this, 'posts_join'), 1, 2);
68
+		add_filter('posts_where', array($this, 'posts_where'), 10, 2);
69
+		// add_filter( 'the_posts', array( $this, 'the_posts' ), 1, 2 );
70
+		add_filter('posts_orderby', array($this, 'posts_orderby'), 1, 2);
71
+		add_filter('posts_groupby', array($this, 'posts_groupby'), 1, 2);
72
+		add_action('posts_selection', array($this, 'remove_filters'));
73
+	}
74 74
 
75 75
 
76
-    /**
77
-     * public access to _remove_filters()
78
-     *
79
-     * @since 4.9.63.p
80
-     */
81
-    public function remove_filters()
82
-    {
83
-        $this->_remove_filters();
84
-    }
76
+	/**
77
+	 * public access to _remove_filters()
78
+	 *
79
+	 * @since 4.9.63.p
80
+	 */
81
+	public function remove_filters()
82
+	{
83
+		$this->_remove_filters();
84
+	}
85 85
 
86 86
 
87
-    /**
88
-     * Should eb called when the last filter or hook is fired for this CPT strategy.
89
-     * This is to avoid applying this CPT strategy for other posts or CPTs (eg,
90
-     * we don't want to join to the datetime table when querying for venues, do we!?)
91
-     */
92
-    protected function _remove_filters()
93
-    {
94
-        remove_filter('posts_fields', array($this, 'posts_fields'), 1);
95
-        remove_filter('posts_join', array($this, 'posts_join'), 1);
96
-        remove_filter('posts_where', array($this, 'posts_where'), 10);
97
-        // remove_filter( 'the_posts', array( $this, 'the_posts' ), 1 );
98
-        remove_filter('posts_orderby', array($this, 'posts_orderby'), 1);
99
-        remove_filter('posts_groupby', array($this, 'posts_groupby'), 1);
100
-        remove_action('posts_selection', array($this, 'remove_filters'));
101
-    }
87
+	/**
88
+	 * Should eb called when the last filter or hook is fired for this CPT strategy.
89
+	 * This is to avoid applying this CPT strategy for other posts or CPTs (eg,
90
+	 * we don't want to join to the datetime table when querying for venues, do we!?)
91
+	 */
92
+	protected function _remove_filters()
93
+	{
94
+		remove_filter('posts_fields', array($this, 'posts_fields'), 1);
95
+		remove_filter('posts_join', array($this, 'posts_join'), 1);
96
+		remove_filter('posts_where', array($this, 'posts_where'), 10);
97
+		// remove_filter( 'the_posts', array( $this, 'the_posts' ), 1 );
98
+		remove_filter('posts_orderby', array($this, 'posts_orderby'), 1);
99
+		remove_filter('posts_groupby', array($this, 'posts_groupby'), 1);
100
+		remove_action('posts_selection', array($this, 'remove_filters'));
101
+	}
102 102
 
103 103
 
104
-    /**
105
-     * @param string   $SQL
106
-     * @param WP_Query $wp_query
107
-     * @return    string
108
-     * @throws EE_Error
109
-     * @throws InvalidArgumentException
110
-     * @throws InvalidDataTypeException
111
-     * @throws InvalidInterfaceException
112
-     */
113
-    public function posts_fields($SQL, WP_Query $wp_query)
114
-    {
115
-        if ($wp_query instanceof WP_Query
116
-            &&
117
-            (
118
-                $wp_query->is_espresso_event_single
119
-                || $wp_query->is_espresso_event_archive
120
-                || $wp_query->is_espresso_event_taxonomy
121
-            )
122
-        ) {
123
-            // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement
124
-            $SQL .= ', ' . EEM_Datetime::instance()->table() . '.* ';
125
-            if ($wp_query->is_espresso_event_archive || $wp_query->is_espresso_event_taxonomy) {
126
-                // because we only want to retrieve the next upcoming datetime for each event:
127
-                // add something like:
128
-                // ", MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date "
129
-                // to WP Query SELECT statement
130
-                $SQL .= ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ';
131
-            }
132
-        }
133
-        return $SQL;
134
-    }
104
+	/**
105
+	 * @param string   $SQL
106
+	 * @param WP_Query $wp_query
107
+	 * @return    string
108
+	 * @throws EE_Error
109
+	 * @throws InvalidArgumentException
110
+	 * @throws InvalidDataTypeException
111
+	 * @throws InvalidInterfaceException
112
+	 */
113
+	public function posts_fields($SQL, WP_Query $wp_query)
114
+	{
115
+		if ($wp_query instanceof WP_Query
116
+			&&
117
+			(
118
+				$wp_query->is_espresso_event_single
119
+				|| $wp_query->is_espresso_event_archive
120
+				|| $wp_query->is_espresso_event_taxonomy
121
+			)
122
+		) {
123
+			// adds something like ", wp_esp_datetime.* " to WP Query SELECT statement
124
+			$SQL .= ', ' . EEM_Datetime::instance()->table() . '.* ';
125
+			if ($wp_query->is_espresso_event_archive || $wp_query->is_espresso_event_taxonomy) {
126
+				// because we only want to retrieve the next upcoming datetime for each event:
127
+				// add something like:
128
+				// ", MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date "
129
+				// to WP Query SELECT statement
130
+				$SQL .= ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ';
131
+			}
132
+		}
133
+		return $SQL;
134
+	}
135 135
 
136 136
 
137
-    /**
138
-     * @param string   $SQL
139
-     * @param WP_Query $wp_query
140
-     * @return string
141
-     * @throws EE_Error
142
-     * @throws InvalidArgumentException
143
-     * @throws InvalidDataTypeException
144
-     * @throws InvalidInterfaceException
145
-     */
146
-    public function posts_join($SQL, WP_Query $wp_query)
147
-    {
148
-        if ($wp_query instanceof WP_Query
149
-            &&
150
-            (
151
-                $wp_query->is_espresso_event_single
152
-                || $wp_query->is_espresso_event_archive
153
-                || $wp_query->is_espresso_event_taxonomy
154
-            )
155
-        ) {
156
-            // adds something like:
157
-            // " LEFT JOIN wp_esp_datetime ON ( wp_esp_datetime.EVT_ID = wp_posts.ID ) "
158
-            // to WP Query JOIN statement
159
-            $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table()
160
-                    . '.ID = ' . EEM_Datetime::instance()->table() . '.'
161
-                    . EEM_Event::instance()->primary_key_name() . ' ) ';
162
-        }
163
-        return $SQL;
164
-    }
137
+	/**
138
+	 * @param string   $SQL
139
+	 * @param WP_Query $wp_query
140
+	 * @return string
141
+	 * @throws EE_Error
142
+	 * @throws InvalidArgumentException
143
+	 * @throws InvalidDataTypeException
144
+	 * @throws InvalidInterfaceException
145
+	 */
146
+	public function posts_join($SQL, WP_Query $wp_query)
147
+	{
148
+		if ($wp_query instanceof WP_Query
149
+			&&
150
+			(
151
+				$wp_query->is_espresso_event_single
152
+				|| $wp_query->is_espresso_event_archive
153
+				|| $wp_query->is_espresso_event_taxonomy
154
+			)
155
+		) {
156
+			// adds something like:
157
+			// " LEFT JOIN wp_esp_datetime ON ( wp_esp_datetime.EVT_ID = wp_posts.ID ) "
158
+			// to WP Query JOIN statement
159
+			$SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table()
160
+					. '.ID = ' . EEM_Datetime::instance()->table() . '.'
161
+					. EEM_Event::instance()->primary_key_name() . ' ) ';
162
+		}
163
+		return $SQL;
164
+	}
165 165
 
166 166
 
167
-    /**
168
-     * @param string   $SQL
169
-     * @param WP_Query $wp_query
170
-     * @return string
171
-     * @throws EE_Error
172
-     * @throws InvalidArgumentException
173
-     * @throws InvalidDataTypeException
174
-     * @throws InvalidInterfaceException
175
-     */
176
-    public function posts_where($SQL, WP_Query $wp_query)
177
-    {
178
-        if ($wp_query instanceof WP_Query
179
-            &&
180
-            (
181
-                $wp_query->is_espresso_event_archive
182
-                || $wp_query->is_espresso_event_taxonomy
183
-            )
184
-        ) {
185
-            if (! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive)
186
-                || ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events)
187
-                || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events
188
-            ) {
189
-                $SQL .= ' AND ' . EEM_Datetime::instance()->table() . ".DTT_EVT_end > '"
190
-                        . current_time('mysql', true) . "' ";
191
-            }
192
-        }
193
-        return $SQL;
194
-    }
167
+	/**
168
+	 * @param string   $SQL
169
+	 * @param WP_Query $wp_query
170
+	 * @return string
171
+	 * @throws EE_Error
172
+	 * @throws InvalidArgumentException
173
+	 * @throws InvalidDataTypeException
174
+	 * @throws InvalidInterfaceException
175
+	 */
176
+	public function posts_where($SQL, WP_Query $wp_query)
177
+	{
178
+		if ($wp_query instanceof WP_Query
179
+			&&
180
+			(
181
+				$wp_query->is_espresso_event_archive
182
+				|| $wp_query->is_espresso_event_taxonomy
183
+			)
184
+		) {
185
+			if (! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive)
186
+				|| ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events)
187
+				|| ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events
188
+			) {
189
+				$SQL .= ' AND ' . EEM_Datetime::instance()->table() . ".DTT_EVT_end > '"
190
+						. current_time('mysql', true) . "' ";
191
+			}
192
+		}
193
+		return $SQL;
194
+	}
195 195
 
196 196
 
197
-    /**
198
-     * @param string   $SQL
199
-     * @param WP_Query $wp_query
200
-     * @return string
201
-     */
202
-    public function posts_orderby($SQL, WP_Query $wp_query)
203
-    {
204
-        if ($wp_query instanceof WP_Query
205
-            &&
206
-            (
207
-                $wp_query->is_espresso_event_archive
208
-                || $wp_query->is_espresso_event_taxonomy
209
-            )
210
-        ) {
211
-            $SQL = ' event_start_date ASC ';
212
-        }
213
-        return $SQL;
214
-    }
197
+	/**
198
+	 * @param string   $SQL
199
+	 * @param WP_Query $wp_query
200
+	 * @return string
201
+	 */
202
+	public function posts_orderby($SQL, WP_Query $wp_query)
203
+	{
204
+		if ($wp_query instanceof WP_Query
205
+			&&
206
+			(
207
+				$wp_query->is_espresso_event_archive
208
+				|| $wp_query->is_espresso_event_taxonomy
209
+			)
210
+		) {
211
+			$SQL = ' event_start_date ASC ';
212
+		}
213
+		return $SQL;
214
+	}
215 215
 
216 216
 
217
-    /**
218
-     * @param string   $SQL
219
-     * @param WP_Query $wp_query
220
-     * @return string
221
-     */
222
-    public function posts_groupby($SQL, WP_Query $wp_query)
223
-    {
224
-        if ($wp_query instanceof WP_Query
225
-            &&
226
-            (
227
-                $wp_query->is_espresso_event_archive
228
-                || $wp_query->is_espresso_event_taxonomy
229
-            )
230
-        ) {
231
-            // TODO: add event list option for displaying ALL datetimes in event list or only primary datetime (default)
232
-            // we're joining to the datetimes table, where there can be MANY datetimes for a single event,
233
-            // but we want to only show each event only once
234
-            // (whereas if we didn't group them by the post's ID, then we would end up with many repeats)
235
-            global $wpdb;
236
-            $SQL = $wpdb->posts . '.ID ';
237
-        }
238
-        return $SQL;
239
-    }
217
+	/**
218
+	 * @param string   $SQL
219
+	 * @param WP_Query $wp_query
220
+	 * @return string
221
+	 */
222
+	public function posts_groupby($SQL, WP_Query $wp_query)
223
+	{
224
+		if ($wp_query instanceof WP_Query
225
+			&&
226
+			(
227
+				$wp_query->is_espresso_event_archive
228
+				|| $wp_query->is_espresso_event_taxonomy
229
+			)
230
+		) {
231
+			// TODO: add event list option for displaying ALL datetimes in event list or only primary datetime (default)
232
+			// we're joining to the datetimes table, where there can be MANY datetimes for a single event,
233
+			// but we want to only show each event only once
234
+			// (whereas if we didn't group them by the post's ID, then we would end up with many repeats)
235
+			global $wpdb;
236
+			$SQL = $wpdb->posts . '.ID ';
237
+		}
238
+		return $SQL;
239
+	}
240 240
 
241 241
 
242
-    /**
243
-     * @param array    $posts
244
-     * @param WP_Query $wp_query
245
-     * @return array
246
-     */
247
-    public function the_posts($posts, WP_Query $wp_query)
248
-    {
249
-        return $posts;
250
-    }
242
+	/**
243
+	 * @param array    $posts
244
+	 * @param WP_Query $wp_query
245
+	 * @return array
246
+	 */
247
+	public function the_posts($posts, WP_Query $wp_query)
248
+	{
249
+		return $posts;
250
+	}
251 251
 
252 252
 
253
-    /**
254
-     * @param null $meta_value
255
-     * @param      $post_id
256
-     * @param      $meta_key
257
-     * @param      $single
258
-     * @return    string
259
-     */
260
-    public function get_EE_post_type_metadata($meta_value = null, $post_id, $meta_key, $single)
261
-    {
262
-        return $meta_value;
263
-    }
253
+	/**
254
+	 * @param null $meta_value
255
+	 * @param      $post_id
256
+	 * @param      $meta_key
257
+	 * @param      $single
258
+	 * @return    string
259
+	 */
260
+	public function get_EE_post_type_metadata($meta_value = null, $post_id, $meta_key, $single)
261
+	{
262
+		return $meta_value;
263
+	}
264 264
 }
Please login to merge, or discard this patch.
core/CPTs/CptQueryModifier.php 1 patch
Indentation   +565 added lines, -565 removed lines patch added patch discarded remove patch
@@ -28,569 +28,569 @@
 block discarded – undo
28 28
 class CptQueryModifier
29 29
 {
30 30
 
31
-    /**
32
-     * @var string $post_type
33
-     */
34
-    protected $post_type = '';
35
-
36
-    /**
37
-     * CPT details from CustomPostTypeDefinitions for specific post type
38
-     *
39
-     * @var array $cpt_details
40
-     */
41
-    protected $cpt_details = array();
42
-
43
-    /**
44
-     * @var EE_Table_Base[] $model_tables
45
-     */
46
-    protected $model_tables = array();
47
-
48
-    /**
49
-     * @var array $taxonomies
50
-     */
51
-    protected $taxonomies = array();
52
-
53
-    /**
54
-     * meta table for the related CPT
55
-     *
56
-     * @var EE_Secondary_Table $meta_table
57
-     */
58
-    protected $meta_table;
59
-
60
-    /**
61
-     * EEM_CPT_Base model for the related CPT
62
-     *
63
-     * @var EEM_CPT_Base $model
64
-     */
65
-    protected $model;
66
-
67
-    /**
68
-     * @var EE_Request_Handler $request_handler
69
-     */
70
-    protected $request_handler;
71
-
72
-    /**
73
-     * @var WP_Query $wp_query
74
-     */
75
-    protected $wp_query;
76
-
77
-    /**
78
-     * @var LoaderInterface $loader
79
-     */
80
-    protected $loader;
81
-
82
-    /**
83
-     * @var RequestInterface $request
84
-     */
85
-    protected $request;
86
-
87
-
88
-    /**
89
-     * CptQueryModifier constructor
90
-     *
91
-     * @param string             $post_type
92
-     * @param array              $cpt_details
93
-     * @param WP_Query           $WP_Query
94
-     * @param EE_Request_Handler $request_handler
95
-     * @param RequestInterface   $request
96
-     * @param LoaderInterface    $loader
97
-     * @throws EE_Error
98
-     */
99
-    public function __construct(
100
-        $post_type,
101
-        array $cpt_details,
102
-        WP_Query $WP_Query,
103
-        EE_Request_Handler $request_handler,
104
-        RequestInterface $request,
105
-        LoaderInterface $loader
106
-    ) {
107
-        $this->loader = $loader;
108
-        $this->request = $request;
109
-        $this->request_handler = $request_handler;
110
-        $this->setWpQuery($WP_Query);
111
-        $this->setPostType($post_type);
112
-        $this->setCptDetails($cpt_details);
113
-        $this->init();
114
-    }
115
-
116
-
117
-    /**
118
-     * @return string
119
-     */
120
-    public function postType()
121
-    {
122
-        return $this->post_type;
123
-    }
124
-
125
-
126
-    /**
127
-     * @param string $post_type
128
-     */
129
-    protected function setPostType($post_type)
130
-    {
131
-        $this->post_type = $post_type;
132
-    }
133
-
134
-
135
-    /**
136
-     * @return array
137
-     */
138
-    public function cptDetails()
139
-    {
140
-        return $this->cpt_details;
141
-    }
142
-
143
-
144
-    /**
145
-     * @param array $cpt_details
146
-     */
147
-    protected function setCptDetails($cpt_details)
148
-    {
149
-        $this->cpt_details = $cpt_details;
150
-    }
151
-
152
-
153
-    /**
154
-     * @return EE_Table_Base[]
155
-     */
156
-    public function modelTables()
157
-    {
158
-        return $this->model_tables;
159
-    }
160
-
161
-
162
-    /**
163
-     * @param EE_Table_Base[] $model_tables
164
-     */
165
-    protected function setModelTables($model_tables)
166
-    {
167
-        $this->model_tables = $model_tables;
168
-    }
169
-
170
-
171
-    /**
172
-     * @return array
173
-     * @throws InvalidArgumentException
174
-     * @throws InvalidDataTypeException
175
-     * @throws InvalidInterfaceException
176
-     */
177
-    public function taxonomies()
178
-    {
179
-        if (empty($this->taxonomies)) {
180
-            $this->initializeTaxonomies();
181
-        }
182
-        return $this->taxonomies;
183
-    }
184
-
185
-
186
-    /**
187
-     * @param array $taxonomies
188
-     */
189
-    protected function setTaxonomies(array $taxonomies)
190
-    {
191
-        $this->taxonomies = $taxonomies;
192
-    }
193
-
194
-
195
-    /**
196
-     * @return EE_Secondary_Table
197
-     */
198
-    public function metaTable()
199
-    {
200
-        return $this->meta_table;
201
-    }
202
-
203
-
204
-    /**
205
-     * @param EE_Secondary_Table $meta_table
206
-     */
207
-    public function setMetaTable(EE_Secondary_Table $meta_table)
208
-    {
209
-        $this->meta_table = $meta_table;
210
-    }
211
-
212
-
213
-    /**
214
-     * @return EEM_Base
215
-     */
216
-    public function model()
217
-    {
218
-        return $this->model;
219
-    }
220
-
221
-
222
-    /**
223
-     * @param EEM_Base $CPT_model
224
-     */
225
-    protected function setModel(EEM_Base $CPT_model)
226
-    {
227
-        $this->model = $CPT_model;
228
-    }
229
-
230
-
231
-    /**
232
-     * @deprecated 4.9.63.p
233
-     * @return EE_Request_Handler
234
-     */
235
-    public function request()
236
-    {
237
-        return $this->request_handler;
238
-    }
239
-
240
-
241
-
242
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
243
-
244
-
245
-    /**
246
-     * @return WP_Query
247
-     */
248
-    public function WpQuery()
249
-    {
250
-        return $this->wp_query;
251
-    }
252
-    // phpcs:enable
253
-
254
-
255
-    /**
256
-     * @param WP_Query $wp_query
257
-     */
258
-    public function setWpQuery(WP_Query $wp_query)
259
-    {
260
-        $this->wp_query = $wp_query;
261
-    }
262
-
263
-
264
-    /**
265
-     * @return void
266
-     * @throws InvalidDataTypeException
267
-     * @throws InvalidInterfaceException
268
-     * @throws InvalidArgumentException
269
-     */
270
-    protected function initializeTaxonomies()
271
-    {
272
-        // check if taxonomies have already been set and that this CPT has taxonomies registered for it
273
-        if (empty($this->taxonomies)
274
-            && isset($this->cpt_details['args']['taxonomies'])
275
-        ) {
276
-            // if so then grab them, but we want the taxonomy name as the key
277
-            $taxonomies = array_flip($this->cpt_details['args']['taxonomies']);
278
-            // then grab the list of ALL taxonomies
279
-            /** @var \EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions
280
-             * $taxonomy_definitions
281
-             */
282
-            $taxonomy_definitions = $this->loader->getShared(
283
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'
284
-            );
285
-            $all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions();
286
-            foreach ($taxonomies as $taxonomy => &$details) {
287
-                // add details to our taxonomies if they exist
288
-                $details = isset($all_taxonomies[ $taxonomy ])
289
-                    ? $all_taxonomies[ $taxonomy ]
290
-                    : array();
291
-            }
292
-            // ALWAYS unset() variables that were passed by reference
293
-            unset($details);
294
-            $this->setTaxonomies($taxonomies);
295
-        }
296
-    }
297
-
298
-
299
-    /**
300
-     * @since 4.9.63.p
301
-     * @throws EE_Error
302
-     */
303
-    protected function init()
304
-    {
305
-        $this->setAdditionalCptDetails();
306
-        $this->setRequestVarsIfCpt();
307
-        // convert post_type to model name
308
-        $model_name = str_replace('EE_', '', $this->cpt_details['class_name']);
309
-        // load all tables related to CPT
310
-        $this->setupModelsAndTables($model_name);
311
-        // load and instantiate CPT_*_Strategy
312
-        $CPT_Strategy = $this->cptStrategyClass($model_name);
313
-        // !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
314
-        // here's the list of available filters in the WP_Query object
315
-        // 'posts_where_paged'
316
-        // 'posts_groupby'
317
-        // 'posts_join_paged'
318
-        // 'posts_orderby'
319
-        // 'posts_distinct'
320
-        // 'post_limits'
321
-        // 'posts_fields'
322
-        // 'posts_join'
323
-        add_filter('posts_fields', array($this, 'postsFields'));
324
-        add_filter('posts_join', array($this, 'postsJoin'));
325
-        add_filter(
326
-            'get_' . $this->post_type . '_metadata',
327
-            array($CPT_Strategy, 'get_EE_post_type_metadata'),
328
-            1,
329
-            4
330
-        );
331
-        add_filter('the_posts', array($this, 'thePosts'), 1, 1);
332
-        if ($this->wp_query->is_main_query()) {
333
-            add_filter('get_edit_post_link', array($this, 'getEditPostLink'), 10, 2);
334
-            $this->addTemplateFilters();
335
-        }
336
-    }
337
-
338
-
339
-    /**
340
-     * sets some basic query vars that pertain to the CPT
341
-     *
342
-     * @access protected
343
-     * @return void
344
-     */
345
-    protected function setAdditionalCptDetails()
346
-    {
347
-        // the post or category or term that is triggering EE
348
-        $this->cpt_details['espresso_page'] = $this->request_handler->is_espresso_page();
349
-        // requested post name
350
-        $this->cpt_details['post_name'] = $this->request->getRequestParam('post_name');
351
-        // add support for viewing 'private', 'draft', or 'pending' posts
352
-        if (isset($this->wp_query->query_vars['p'])
353
-            && $this->wp_query->query_vars['p'] !== 0
354
-            && is_user_logged_in()
355
-            && current_user_can('edit_post', $this->wp_query->query_vars['p'])
356
-        ) {
357
-            // we can just inject directly into the WP_Query object
358
-            $this->wp_query->query['post_status'] = array('publish', 'private', 'draft', 'pending');
359
-            // now set the main 'ee' request var so that the appropriate module can load the appropriate template(s)
360
-            $this->request->setRequestParam('ee', $this->cpt_details['singular_slug']);
361
-        }
362
-    }
363
-
364
-
365
-    /**
366
-     * Checks if we're on a EE-CPT archive-or-single page, and if we've never set the EE request var.
367
-     * If so, sets the 'ee' request variable
368
-     * so other parts of EE can know what CPT is getting queried.
369
-     * To Mike's knowledge, this must be called from during or after the pre_get_posts hook
370
-     * in order for is_archive() and is_single() methods to work properly.
371
-     *
372
-     * @return void
373
-     */
374
-    public function setRequestVarsIfCpt()
375
-    {
376
-        // check if ee action var has been set
377
-        if (! $this->request->requestParamIsSet('ee')) {
378
-            // check that route exists for CPT archive slug
379
-            if (is_archive() && EE_Config::get_route($this->cpt_details['plural_slug'])) {
380
-                // ie: set "ee" to "events"
381
-                $this->request->setRequestParam('ee', $this->cpt_details['plural_slug']);
382
-                // or does it match a single page CPT like /event/
383
-            } elseif (is_single() && EE_Config::get_route($this->cpt_details['singular_slug'])) {
384
-                // ie: set "ee" to "event"
385
-                $this->request->setRequestParam('ee', $this->cpt_details['singular_slug']);
386
-            }
387
-        }
388
-    }
389
-
390
-
391
-    /**
392
-     * setupModelsAndTables
393
-     *
394
-     * @access protected
395
-     * @param string $model_name
396
-     * @throws EE_Error
397
-     */
398
-    protected function setupModelsAndTables($model_name)
399
-    {
400
-        // get CPT table data via CPT Model
401
-        $full_model_name = strpos($model_name, 'EEM_') !== 0
402
-            ? 'EEM_' . $model_name
403
-            : $model_name;
404
-        $model = $this->loader->getShared($full_model_name);
405
-        if (! $model instanceof EEM_Base) {
406
-            throw new EE_Error(
407
-                sprintf(
408
-                    __(
409
-                        'The "%1$s" model could not be loaded.',
410
-                        'event_espresso'
411
-                    ),
412
-                    $full_model_name
413
-                )
414
-            );
415
-        }
416
-        $this->setModel($model);
417
-        $this->setModelTables($this->model->get_tables());
418
-        $meta_model = $model_name . '_Meta';
419
-        // is there a Meta Table for this CPT?
420
-        if (isset($this->cpt_details['tables'][ $meta_model ])
421
-            && $this->cpt_details['tables'][ $meta_model ] instanceof EE_Secondary_Table
422
-        ) {
423
-            $this->setMetaTable($this->cpt_details['tables'][ $meta_model ]);
424
-        }
425
-    }
426
-
427
-
428
-    /**
429
-     * cptStrategyClass
430
-     *
431
-     * @access protected
432
-     * @param  string $model_name
433
-     * @return string
434
-     */
435
-    protected function cptStrategyClass($model_name)
436
-    {
437
-        // creates classname like:  CPT_Event_Strategy
438
-        $CPT_Strategy_class_name = 'EE_CPT_' . $model_name . '_Strategy';
439
-        // load and instantiate
440
-        $CPT_Strategy = $this->loader->getShared(
441
-            $CPT_Strategy_class_name,
442
-            array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
443
-        );
444
-        if ($CPT_Strategy === null) {
445
-            $CPT_Strategy = $this->loader->getShared(
446
-                'EE_CPT_Default_Strategy',
447
-                array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
448
-            );
449
-        }
450
-        return $CPT_Strategy;
451
-    }
452
-
453
-
454
-    /**
455
-     * postsFields
456
-     *
457
-     * @access public
458
-     * @param  $SQL
459
-     * @return string
460
-     */
461
-    public function postsFields($SQL)
462
-    {
463
-        // does this CPT have a meta table ?
464
-        if ($this->meta_table instanceof EE_Secondary_Table) {
465
-            // adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement
466
-            $SQL .= ', ' . $this->meta_table->get_table_name() . '.* ';
467
-        }
468
-        remove_filter('posts_fields', array($this, 'postsFields'));
469
-        return $SQL;
470
-    }
471
-
472
-
473
-    /**
474
-     * postsJoin
475
-     *
476
-     * @access public
477
-     * @param  $SQL
478
-     * @return string
479
-     */
480
-    public function postsJoin($SQL)
481
-    {
482
-        // does this CPT have a meta table ?
483
-        if ($this->meta_table instanceof EE_Secondary_Table) {
484
-            global $wpdb;
485
-            // adds something like " LEFT JOIN wp_esp_event_meta ON ( wp_esp_event_meta.EVT_ID = wp_posts.ID ) " to WP Query JOIN statement
486
-            $SQL .= ' LEFT JOIN '
487
-                    . $this->meta_table->get_table_name()
488
-                    . ' ON ( '
489
-                    . $this->meta_table->get_table_name()
490
-                    . '.'
491
-                    . $this->meta_table->get_fk_on_table()
492
-                    . ' = '
493
-                    . $wpdb->posts
494
-                    . '.ID ) ';
495
-        }
496
-        remove_filter('posts_join', array($this, 'postsJoin'));
497
-        return $SQL;
498
-    }
499
-
500
-
501
-    /**
502
-     * thePosts
503
-     *
504
-     * @access public
505
-     * @param  WP_Post[] $posts
506
-     * @return WP_Post[]
507
-     */
508
-    public function thePosts($posts)
509
-    {
510
-        $CPT_class = $this->cpt_details['class_name'];
511
-        // loop thru posts
512
-        if (is_array($posts) && $this->model instanceof EEM_CPT_Base) {
513
-            foreach ($posts as $key => $post) {
514
-                if ($post->post_type === $this->post_type) {
515
-                    $post->{$CPT_class} = $this->model->instantiate_class_from_post_object($post);
516
-                }
517
-            }
518
-        }
519
-        remove_filter('the_posts', array($this, 'thePosts'), 1);
520
-        return $posts;
521
-    }
522
-
523
-
524
-    /**
525
-     * @param $url
526
-     * @param $ID
527
-     * @return string
528
-     */
529
-    public function getEditPostLink($url, $ID)
530
-    {
531
-        // need to make sure we only edit links if our cpt
532
-        global $post;
533
-        // notice if the cpt is registered with `show_ee_ui` set to false, we take that to mean that the WordPress core ui
534
-        // for interacting with the CPT is desired and there is no EE UI for interacting with the CPT in the admin.
535
-        if (! $post instanceof WP_Post
536
-            || $post->post_type !== $this->post_type
537
-            || (
538
-                isset($this->cpt_details['args']['show_ee_ui'])
539
-                && ! $this->cpt_details['args']['show_ee_ui']
540
-            )
541
-        ) {
542
-            return $url;
543
-        }
544
-        // k made it here so all is good.
545
-        return wp_nonce_url(
546
-            add_query_arg(
547
-                array('page' => $this->post_type, 'post' => $ID, 'action' => 'edit'),
548
-                admin_url('admin.php')
549
-            ),
550
-            'edit',
551
-            'edit_nonce'
552
-        );
553
-    }
554
-
555
-
556
-    /**
557
-     * Execute any template filters.
558
-     * This method is only called if in main query.
559
-     *
560
-     * @return void
561
-     */
562
-    public function addTemplateFilters()
563
-    {
564
-        // if requested cpt supports page_templates and it's the main query
565
-        if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
566
-            // then let's hook into the appropriate query_template hook
567
-            add_filter('single_template', array($this, 'singleCptTemplate'));
568
-        }
569
-    }
570
-
571
-
572
-    /**
573
-     * Callback for single_template wp filter.
574
-     * This is used to load the set page_template for a single ee cpt if its set.  If "default" then we load the normal
575
-     * hierarchy.
576
-     *
577
-     * @access public
578
-     * @param string $current_template Existing default template path derived for this page call.
579
-     * @return string the path to the full template file.
580
-     */
581
-    public function singleCptTemplate($current_template)
582
-    {
583
-        $object = get_queried_object();
584
-        // does this called object HAVE a page template set that is something other than the default.
585
-        $template = get_post_meta($object->ID, '_wp_page_template', true);
586
-        // exit early if default or not set or invalid path (accounts for theme changes)
587
-        if ($template === 'default'
588
-            || empty($template)
589
-            || ! is_readable(get_stylesheet_directory() . '/' . $template)
590
-        ) {
591
-            return $current_template;
592
-        }
593
-        // made it here so we SHOULD be able to just locate the template and then return it.
594
-        return locate_template(array($template));
595
-    }
31
+	/**
32
+	 * @var string $post_type
33
+	 */
34
+	protected $post_type = '';
35
+
36
+	/**
37
+	 * CPT details from CustomPostTypeDefinitions for specific post type
38
+	 *
39
+	 * @var array $cpt_details
40
+	 */
41
+	protected $cpt_details = array();
42
+
43
+	/**
44
+	 * @var EE_Table_Base[] $model_tables
45
+	 */
46
+	protected $model_tables = array();
47
+
48
+	/**
49
+	 * @var array $taxonomies
50
+	 */
51
+	protected $taxonomies = array();
52
+
53
+	/**
54
+	 * meta table for the related CPT
55
+	 *
56
+	 * @var EE_Secondary_Table $meta_table
57
+	 */
58
+	protected $meta_table;
59
+
60
+	/**
61
+	 * EEM_CPT_Base model for the related CPT
62
+	 *
63
+	 * @var EEM_CPT_Base $model
64
+	 */
65
+	protected $model;
66
+
67
+	/**
68
+	 * @var EE_Request_Handler $request_handler
69
+	 */
70
+	protected $request_handler;
71
+
72
+	/**
73
+	 * @var WP_Query $wp_query
74
+	 */
75
+	protected $wp_query;
76
+
77
+	/**
78
+	 * @var LoaderInterface $loader
79
+	 */
80
+	protected $loader;
81
+
82
+	/**
83
+	 * @var RequestInterface $request
84
+	 */
85
+	protected $request;
86
+
87
+
88
+	/**
89
+	 * CptQueryModifier constructor
90
+	 *
91
+	 * @param string             $post_type
92
+	 * @param array              $cpt_details
93
+	 * @param WP_Query           $WP_Query
94
+	 * @param EE_Request_Handler $request_handler
95
+	 * @param RequestInterface   $request
96
+	 * @param LoaderInterface    $loader
97
+	 * @throws EE_Error
98
+	 */
99
+	public function __construct(
100
+		$post_type,
101
+		array $cpt_details,
102
+		WP_Query $WP_Query,
103
+		EE_Request_Handler $request_handler,
104
+		RequestInterface $request,
105
+		LoaderInterface $loader
106
+	) {
107
+		$this->loader = $loader;
108
+		$this->request = $request;
109
+		$this->request_handler = $request_handler;
110
+		$this->setWpQuery($WP_Query);
111
+		$this->setPostType($post_type);
112
+		$this->setCptDetails($cpt_details);
113
+		$this->init();
114
+	}
115
+
116
+
117
+	/**
118
+	 * @return string
119
+	 */
120
+	public function postType()
121
+	{
122
+		return $this->post_type;
123
+	}
124
+
125
+
126
+	/**
127
+	 * @param string $post_type
128
+	 */
129
+	protected function setPostType($post_type)
130
+	{
131
+		$this->post_type = $post_type;
132
+	}
133
+
134
+
135
+	/**
136
+	 * @return array
137
+	 */
138
+	public function cptDetails()
139
+	{
140
+		return $this->cpt_details;
141
+	}
142
+
143
+
144
+	/**
145
+	 * @param array $cpt_details
146
+	 */
147
+	protected function setCptDetails($cpt_details)
148
+	{
149
+		$this->cpt_details = $cpt_details;
150
+	}
151
+
152
+
153
+	/**
154
+	 * @return EE_Table_Base[]
155
+	 */
156
+	public function modelTables()
157
+	{
158
+		return $this->model_tables;
159
+	}
160
+
161
+
162
+	/**
163
+	 * @param EE_Table_Base[] $model_tables
164
+	 */
165
+	protected function setModelTables($model_tables)
166
+	{
167
+		$this->model_tables = $model_tables;
168
+	}
169
+
170
+
171
+	/**
172
+	 * @return array
173
+	 * @throws InvalidArgumentException
174
+	 * @throws InvalidDataTypeException
175
+	 * @throws InvalidInterfaceException
176
+	 */
177
+	public function taxonomies()
178
+	{
179
+		if (empty($this->taxonomies)) {
180
+			$this->initializeTaxonomies();
181
+		}
182
+		return $this->taxonomies;
183
+	}
184
+
185
+
186
+	/**
187
+	 * @param array $taxonomies
188
+	 */
189
+	protected function setTaxonomies(array $taxonomies)
190
+	{
191
+		$this->taxonomies = $taxonomies;
192
+	}
193
+
194
+
195
+	/**
196
+	 * @return EE_Secondary_Table
197
+	 */
198
+	public function metaTable()
199
+	{
200
+		return $this->meta_table;
201
+	}
202
+
203
+
204
+	/**
205
+	 * @param EE_Secondary_Table $meta_table
206
+	 */
207
+	public function setMetaTable(EE_Secondary_Table $meta_table)
208
+	{
209
+		$this->meta_table = $meta_table;
210
+	}
211
+
212
+
213
+	/**
214
+	 * @return EEM_Base
215
+	 */
216
+	public function model()
217
+	{
218
+		return $this->model;
219
+	}
220
+
221
+
222
+	/**
223
+	 * @param EEM_Base $CPT_model
224
+	 */
225
+	protected function setModel(EEM_Base $CPT_model)
226
+	{
227
+		$this->model = $CPT_model;
228
+	}
229
+
230
+
231
+	/**
232
+	 * @deprecated 4.9.63.p
233
+	 * @return EE_Request_Handler
234
+	 */
235
+	public function request()
236
+	{
237
+		return $this->request_handler;
238
+	}
239
+
240
+
241
+
242
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
243
+
244
+
245
+	/**
246
+	 * @return WP_Query
247
+	 */
248
+	public function WpQuery()
249
+	{
250
+		return $this->wp_query;
251
+	}
252
+	// phpcs:enable
253
+
254
+
255
+	/**
256
+	 * @param WP_Query $wp_query
257
+	 */
258
+	public function setWpQuery(WP_Query $wp_query)
259
+	{
260
+		$this->wp_query = $wp_query;
261
+	}
262
+
263
+
264
+	/**
265
+	 * @return void
266
+	 * @throws InvalidDataTypeException
267
+	 * @throws InvalidInterfaceException
268
+	 * @throws InvalidArgumentException
269
+	 */
270
+	protected function initializeTaxonomies()
271
+	{
272
+		// check if taxonomies have already been set and that this CPT has taxonomies registered for it
273
+		if (empty($this->taxonomies)
274
+			&& isset($this->cpt_details['args']['taxonomies'])
275
+		) {
276
+			// if so then grab them, but we want the taxonomy name as the key
277
+			$taxonomies = array_flip($this->cpt_details['args']['taxonomies']);
278
+			// then grab the list of ALL taxonomies
279
+			/** @var \EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions
280
+			 * $taxonomy_definitions
281
+			 */
282
+			$taxonomy_definitions = $this->loader->getShared(
283
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'
284
+			);
285
+			$all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions();
286
+			foreach ($taxonomies as $taxonomy => &$details) {
287
+				// add details to our taxonomies if they exist
288
+				$details = isset($all_taxonomies[ $taxonomy ])
289
+					? $all_taxonomies[ $taxonomy ]
290
+					: array();
291
+			}
292
+			// ALWAYS unset() variables that were passed by reference
293
+			unset($details);
294
+			$this->setTaxonomies($taxonomies);
295
+		}
296
+	}
297
+
298
+
299
+	/**
300
+	 * @since 4.9.63.p
301
+	 * @throws EE_Error
302
+	 */
303
+	protected function init()
304
+	{
305
+		$this->setAdditionalCptDetails();
306
+		$this->setRequestVarsIfCpt();
307
+		// convert post_type to model name
308
+		$model_name = str_replace('EE_', '', $this->cpt_details['class_name']);
309
+		// load all tables related to CPT
310
+		$this->setupModelsAndTables($model_name);
311
+		// load and instantiate CPT_*_Strategy
312
+		$CPT_Strategy = $this->cptStrategyClass($model_name);
313
+		// !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
314
+		// here's the list of available filters in the WP_Query object
315
+		// 'posts_where_paged'
316
+		// 'posts_groupby'
317
+		// 'posts_join_paged'
318
+		// 'posts_orderby'
319
+		// 'posts_distinct'
320
+		// 'post_limits'
321
+		// 'posts_fields'
322
+		// 'posts_join'
323
+		add_filter('posts_fields', array($this, 'postsFields'));
324
+		add_filter('posts_join', array($this, 'postsJoin'));
325
+		add_filter(
326
+			'get_' . $this->post_type . '_metadata',
327
+			array($CPT_Strategy, 'get_EE_post_type_metadata'),
328
+			1,
329
+			4
330
+		);
331
+		add_filter('the_posts', array($this, 'thePosts'), 1, 1);
332
+		if ($this->wp_query->is_main_query()) {
333
+			add_filter('get_edit_post_link', array($this, 'getEditPostLink'), 10, 2);
334
+			$this->addTemplateFilters();
335
+		}
336
+	}
337
+
338
+
339
+	/**
340
+	 * sets some basic query vars that pertain to the CPT
341
+	 *
342
+	 * @access protected
343
+	 * @return void
344
+	 */
345
+	protected function setAdditionalCptDetails()
346
+	{
347
+		// the post or category or term that is triggering EE
348
+		$this->cpt_details['espresso_page'] = $this->request_handler->is_espresso_page();
349
+		// requested post name
350
+		$this->cpt_details['post_name'] = $this->request->getRequestParam('post_name');
351
+		// add support for viewing 'private', 'draft', or 'pending' posts
352
+		if (isset($this->wp_query->query_vars['p'])
353
+			&& $this->wp_query->query_vars['p'] !== 0
354
+			&& is_user_logged_in()
355
+			&& current_user_can('edit_post', $this->wp_query->query_vars['p'])
356
+		) {
357
+			// we can just inject directly into the WP_Query object
358
+			$this->wp_query->query['post_status'] = array('publish', 'private', 'draft', 'pending');
359
+			// now set the main 'ee' request var so that the appropriate module can load the appropriate template(s)
360
+			$this->request->setRequestParam('ee', $this->cpt_details['singular_slug']);
361
+		}
362
+	}
363
+
364
+
365
+	/**
366
+	 * Checks if we're on a EE-CPT archive-or-single page, and if we've never set the EE request var.
367
+	 * If so, sets the 'ee' request variable
368
+	 * so other parts of EE can know what CPT is getting queried.
369
+	 * To Mike's knowledge, this must be called from during or after the pre_get_posts hook
370
+	 * in order for is_archive() and is_single() methods to work properly.
371
+	 *
372
+	 * @return void
373
+	 */
374
+	public function setRequestVarsIfCpt()
375
+	{
376
+		// check if ee action var has been set
377
+		if (! $this->request->requestParamIsSet('ee')) {
378
+			// check that route exists for CPT archive slug
379
+			if (is_archive() && EE_Config::get_route($this->cpt_details['plural_slug'])) {
380
+				// ie: set "ee" to "events"
381
+				$this->request->setRequestParam('ee', $this->cpt_details['plural_slug']);
382
+				// or does it match a single page CPT like /event/
383
+			} elseif (is_single() && EE_Config::get_route($this->cpt_details['singular_slug'])) {
384
+				// ie: set "ee" to "event"
385
+				$this->request->setRequestParam('ee', $this->cpt_details['singular_slug']);
386
+			}
387
+		}
388
+	}
389
+
390
+
391
+	/**
392
+	 * setupModelsAndTables
393
+	 *
394
+	 * @access protected
395
+	 * @param string $model_name
396
+	 * @throws EE_Error
397
+	 */
398
+	protected function setupModelsAndTables($model_name)
399
+	{
400
+		// get CPT table data via CPT Model
401
+		$full_model_name = strpos($model_name, 'EEM_') !== 0
402
+			? 'EEM_' . $model_name
403
+			: $model_name;
404
+		$model = $this->loader->getShared($full_model_name);
405
+		if (! $model instanceof EEM_Base) {
406
+			throw new EE_Error(
407
+				sprintf(
408
+					__(
409
+						'The "%1$s" model could not be loaded.',
410
+						'event_espresso'
411
+					),
412
+					$full_model_name
413
+				)
414
+			);
415
+		}
416
+		$this->setModel($model);
417
+		$this->setModelTables($this->model->get_tables());
418
+		$meta_model = $model_name . '_Meta';
419
+		// is there a Meta Table for this CPT?
420
+		if (isset($this->cpt_details['tables'][ $meta_model ])
421
+			&& $this->cpt_details['tables'][ $meta_model ] instanceof EE_Secondary_Table
422
+		) {
423
+			$this->setMetaTable($this->cpt_details['tables'][ $meta_model ]);
424
+		}
425
+	}
426
+
427
+
428
+	/**
429
+	 * cptStrategyClass
430
+	 *
431
+	 * @access protected
432
+	 * @param  string $model_name
433
+	 * @return string
434
+	 */
435
+	protected function cptStrategyClass($model_name)
436
+	{
437
+		// creates classname like:  CPT_Event_Strategy
438
+		$CPT_Strategy_class_name = 'EE_CPT_' . $model_name . '_Strategy';
439
+		// load and instantiate
440
+		$CPT_Strategy = $this->loader->getShared(
441
+			$CPT_Strategy_class_name,
442
+			array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
443
+		);
444
+		if ($CPT_Strategy === null) {
445
+			$CPT_Strategy = $this->loader->getShared(
446
+				'EE_CPT_Default_Strategy',
447
+				array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
448
+			);
449
+		}
450
+		return $CPT_Strategy;
451
+	}
452
+
453
+
454
+	/**
455
+	 * postsFields
456
+	 *
457
+	 * @access public
458
+	 * @param  $SQL
459
+	 * @return string
460
+	 */
461
+	public function postsFields($SQL)
462
+	{
463
+		// does this CPT have a meta table ?
464
+		if ($this->meta_table instanceof EE_Secondary_Table) {
465
+			// adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement
466
+			$SQL .= ', ' . $this->meta_table->get_table_name() . '.* ';
467
+		}
468
+		remove_filter('posts_fields', array($this, 'postsFields'));
469
+		return $SQL;
470
+	}
471
+
472
+
473
+	/**
474
+	 * postsJoin
475
+	 *
476
+	 * @access public
477
+	 * @param  $SQL
478
+	 * @return string
479
+	 */
480
+	public function postsJoin($SQL)
481
+	{
482
+		// does this CPT have a meta table ?
483
+		if ($this->meta_table instanceof EE_Secondary_Table) {
484
+			global $wpdb;
485
+			// adds something like " LEFT JOIN wp_esp_event_meta ON ( wp_esp_event_meta.EVT_ID = wp_posts.ID ) " to WP Query JOIN statement
486
+			$SQL .= ' LEFT JOIN '
487
+					. $this->meta_table->get_table_name()
488
+					. ' ON ( '
489
+					. $this->meta_table->get_table_name()
490
+					. '.'
491
+					. $this->meta_table->get_fk_on_table()
492
+					. ' = '
493
+					. $wpdb->posts
494
+					. '.ID ) ';
495
+		}
496
+		remove_filter('posts_join', array($this, 'postsJoin'));
497
+		return $SQL;
498
+	}
499
+
500
+
501
+	/**
502
+	 * thePosts
503
+	 *
504
+	 * @access public
505
+	 * @param  WP_Post[] $posts
506
+	 * @return WP_Post[]
507
+	 */
508
+	public function thePosts($posts)
509
+	{
510
+		$CPT_class = $this->cpt_details['class_name'];
511
+		// loop thru posts
512
+		if (is_array($posts) && $this->model instanceof EEM_CPT_Base) {
513
+			foreach ($posts as $key => $post) {
514
+				if ($post->post_type === $this->post_type) {
515
+					$post->{$CPT_class} = $this->model->instantiate_class_from_post_object($post);
516
+				}
517
+			}
518
+		}
519
+		remove_filter('the_posts', array($this, 'thePosts'), 1);
520
+		return $posts;
521
+	}
522
+
523
+
524
+	/**
525
+	 * @param $url
526
+	 * @param $ID
527
+	 * @return string
528
+	 */
529
+	public function getEditPostLink($url, $ID)
530
+	{
531
+		// need to make sure we only edit links if our cpt
532
+		global $post;
533
+		// notice if the cpt is registered with `show_ee_ui` set to false, we take that to mean that the WordPress core ui
534
+		// for interacting with the CPT is desired and there is no EE UI for interacting with the CPT in the admin.
535
+		if (! $post instanceof WP_Post
536
+			|| $post->post_type !== $this->post_type
537
+			|| (
538
+				isset($this->cpt_details['args']['show_ee_ui'])
539
+				&& ! $this->cpt_details['args']['show_ee_ui']
540
+			)
541
+		) {
542
+			return $url;
543
+		}
544
+		// k made it here so all is good.
545
+		return wp_nonce_url(
546
+			add_query_arg(
547
+				array('page' => $this->post_type, 'post' => $ID, 'action' => 'edit'),
548
+				admin_url('admin.php')
549
+			),
550
+			'edit',
551
+			'edit_nonce'
552
+		);
553
+	}
554
+
555
+
556
+	/**
557
+	 * Execute any template filters.
558
+	 * This method is only called if in main query.
559
+	 *
560
+	 * @return void
561
+	 */
562
+	public function addTemplateFilters()
563
+	{
564
+		// if requested cpt supports page_templates and it's the main query
565
+		if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
566
+			// then let's hook into the appropriate query_template hook
567
+			add_filter('single_template', array($this, 'singleCptTemplate'));
568
+		}
569
+	}
570
+
571
+
572
+	/**
573
+	 * Callback for single_template wp filter.
574
+	 * This is used to load the set page_template for a single ee cpt if its set.  If "default" then we load the normal
575
+	 * hierarchy.
576
+	 *
577
+	 * @access public
578
+	 * @param string $current_template Existing default template path derived for this page call.
579
+	 * @return string the path to the full template file.
580
+	 */
581
+	public function singleCptTemplate($current_template)
582
+	{
583
+		$object = get_queried_object();
584
+		// does this called object HAVE a page template set that is something other than the default.
585
+		$template = get_post_meta($object->ID, '_wp_page_template', true);
586
+		// exit early if default or not set or invalid path (accounts for theme changes)
587
+		if ($template === 'default'
588
+			|| empty($template)
589
+			|| ! is_readable(get_stylesheet_directory() . '/' . $template)
590
+		) {
591
+			return $current_template;
592
+		}
593
+		// made it here so we SHOULD be able to just locate the template and then return it.
594
+		return locate_template(array($template));
595
+	}
596 596
 }
Please login to merge, or discard this patch.