Completed
Branch BUG/event-object-ajax-requests (a288b5)
by
unknown
44:34 queued 29:56
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/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.
core/admin/EE_Admin.core.php 1 patch
Indentation   +957 added lines, -957 removed lines patch added patch discarded remove patch
@@ -20,486 +20,486 @@  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
-    }
168
-
169
-
170
-    /**
171
-     * hide_admin_pages_except_maintenance_mode
172
-     *
173
-     * @param array $admin_page_folder_names
174
-     * @return array
175
-     */
176
-    public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
177
-    {
178
-        return array(
179
-            'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
180
-            'about'       => EE_ADMIN_PAGES . 'about' . DS,
181
-            'support'     => EE_ADMIN_PAGES . 'support' . DS,
182
-        );
183
-    }
184
-
185
-
186
-    /**
187
-     * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
188
-     * EE_Front_Controller's init phases have run
189
-     *
190
-     * @return void
191
-     * @throws EE_Error
192
-     * @throws InvalidArgumentException
193
-     * @throws InvalidDataTypeException
194
-     * @throws InvalidInterfaceException
195
-     * @throws ReflectionException
196
-     * @throws ServiceNotFoundException
197
-     */
198
-    public function init()
199
-    {
200
-        // only enable most of the EE_Admin IF we're not in full maintenance mode
201
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
202
-            $this->initModelsReady();
203
-        }
204
-        // run the admin page factory but ONLY if we are doing an ee admin ajax request
205
-        if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
206
-            try {
207
-                // this loads the controller for the admin pages which will setup routing etc
208
-                EE_Registry::instance()->load_core('Admin_Page_Loader');
209
-            } catch (EE_Error $e) {
210
-                $e->get_error();
211
-            }
212
-        }
213
-        add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
214
-        // make sure our CPTs and custom taxonomy metaboxes get shown for first time users
215
-        add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
216
-        add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
217
-        // exclude EE critical pages from all nav menus and wp_list_pages
218
-        add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
219
-    }
220
-
221
-
222
-    /**
223
-     * Gets the loader (and if it wasn't previously set, sets it)
224
-     * @return LoaderInterface
225
-     * @throws InvalidArgumentException
226
-     * @throws InvalidDataTypeException
227
-     * @throws InvalidInterfaceException
228
-     */
229
-    protected function getLoader()
230
-    {
231
-        if (! $this->loader instanceof LoaderInterface) {
232
-            $this->loader = LoaderFactory::getLoader();
233
-        }
234
-        return $this->loader;
235
-    }
236
-
237
-
238
-    /**
239
-     * Method that's fired on admin requests (including admin ajax) but only when the models are usable
240
-     * (ie, the site isn't in maintenance mode)
241
-     * @since 4.9.63.p
242
-     * @return void
243
-     */
244
-    protected function initModelsReady()
245
-    {
246
-        // ok so we want to enable the entire admin
247
-        $this->persistent_admin_notice_manager = $this->getLoader()->getShared(
248
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
249
-        );
250
-        $this->persistent_admin_notice_manager->setReturnUrl(
251
-            EE_Admin_Page::add_query_args_and_nonce(
252
-                array(
253
-                    'page'   => EE_Registry::instance()->REQ->get('page', ''),
254
-                    'action' => EE_Registry::instance()->REQ->get('action', ''),
255
-                ),
256
-                EE_ADMIN_URL
257
-            )
258
-        );
259
-        $this->maybeSetDatetimeWarningNotice();
260
-        // at a glance dashboard widget
261
-        add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
262
-        // filter for get_edit_post_link used on comments for custom post types
263
-        add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
264
-    }
265
-
266
-
267
-    /**
268
-     *    get_persistent_admin_notices
269
-     *
270
-     * @access    public
271
-     * @return void
272
-     * @throws EE_Error
273
-     * @throws InvalidArgumentException
274
-     * @throws InvalidDataTypeException
275
-     * @throws InvalidInterfaceException
276
-     */
277
-    public function maybeSetDatetimeWarningNotice()
278
-    {
279
-        // add dismissable notice for datetime changes.  Only valid if site does not have a timezone_string set.
280
-        // @todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
281
-        // with this.  But after enough time (indeterminate at this point) we can just remove this notice.
282
-        // this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
283
-        if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true)
284
-            && ! get_option('timezone_string')
285
-            && EEM_Event::instance()->count() > 0
286
-        ) {
287
-            new PersistentAdminNotice(
288
-                'datetime_fix_notice',
289
-                sprintf(
290
-                    esc_html__(
291
-                        '%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.',
292
-                        'event_espresso'
293
-                    ),
294
-                    '<strong>',
295
-                    '</strong>',
296
-                    '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
297
-                    '</a>',
298
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
299
-                        array(
300
-                            'page'   => 'espresso_maintenance_settings',
301
-                            'action' => 'datetime_tools',
302
-                        ),
303
-                        admin_url('admin.php')
304
-                    ) . '">'
305
-                ),
306
-                false,
307
-                'manage_options',
308
-                'datetime_fix_persistent_notice'
309
-            );
310
-        }
311
-    }
312
-
313
-
314
-    /**
315
-     * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
316
-     * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
317
-     * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
318
-     * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
319
-     * normal property on the post_type object.  It's found ONLY in this particular context.
320
-     *
321
-     * @param WP_Post $post_type WP post type object
322
-     * @return WP_Post
323
-     * @throws InvalidArgumentException
324
-     * @throws InvalidDataTypeException
325
-     * @throws InvalidInterfaceException
326
-     */
327
-    public function remove_pages_from_nav_menu($post_type)
328
-    {
329
-        // if this isn't the "pages" post type let's get out
330
-        if ($post_type->name !== 'page') {
331
-            return $post_type;
332
-        }
333
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
334
-        $post_type->_default_query = array(
335
-            'post__not_in' => $critical_pages,
336
-        );
337
-        return $post_type;
338
-    }
339
-
340
-
341
-    /**
342
-     * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
343
-     * metaboxes get shown as well
344
-     *
345
-     * @return void
346
-     */
347
-    public function enable_hidden_ee_nav_menu_metaboxes()
348
-    {
349
-        global $wp_meta_boxes, $pagenow;
350
-        if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
351
-            return;
352
-        }
353
-        $user = wp_get_current_user();
354
-        // has this been done yet?
355
-        if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
356
-            return;
357
-        }
358
-
359
-        $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID);
360
-        $initial_meta_boxes = apply_filters(
361
-            'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
362
-            array(
363
-                'nav-menu-theme-locations',
364
-                'add-page',
365
-                'add-custom-links',
366
-                'add-category',
367
-                'add-espresso_events',
368
-                'add-espresso_venues',
369
-                'add-espresso_event_categories',
370
-                'add-espresso_venue_categories',
371
-                'add-post-type-post',
372
-                'add-post-type-page',
373
-            )
374
-        );
375
-
376
-        if (is_array($hidden_meta_boxes)) {
377
-            foreach ($hidden_meta_boxes as $key => $meta_box_id) {
378
-                if (in_array($meta_box_id, $initial_meta_boxes, true)) {
379
-                    unset($hidden_meta_boxes[ $key ]);
380
-                }
381
-            }
382
-        }
383
-        update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
384
-        update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
385
-    }
386
-
387
-
388
-    /**
389
-     * This method simply registers custom nav menu boxes for "nav_menus.php route"
390
-     * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
391
-     *
392
-     * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
393
-     *         addons etc.
394
-     * @return void
395
-     */
396
-    public function register_custom_nav_menu_boxes()
397
-    {
398
-        add_meta_box(
399
-            'add-extra-nav-menu-pages',
400
-            esc_html__('Event Espresso Pages', 'event_espresso'),
401
-            array($this, 'ee_cpt_archive_pages'),
402
-            'nav-menus',
403
-            'side',
404
-            'core'
405
-        );
406
-    }
407
-
408
-
409
-    /**
410
-     * Use this to edit the post link for our cpts so that the edit link points to the correct page.
411
-     *
412
-     * @since   4.3.0
413
-     * @param string $link the original link generated by wp
414
-     * @param int    $id   post id
415
-     * @return string  the (maybe) modified link
416
-     */
417
-    public function modify_edit_post_link($link, $id)
418
-    {
419
-        if (! $post = get_post($id)) {
420
-            return $link;
421
-        }
422
-        if ($post->post_type === 'espresso_attendees') {
423
-            $query_args = array(
424
-                'action' => 'edit_attendee',
425
-                'post'   => $id,
426
-            );
427
-            return EEH_URL::add_query_args_and_nonce(
428
-                $query_args,
429
-                admin_url('admin.php?page=espresso_registrations')
430
-            );
431
-        }
432
-        return $link;
433
-    }
434
-
435
-
436
-    public function ee_cpt_archive_pages()
437
-    {
438
-        global $nav_menu_selected_id;
439
-        $db_fields = false;
440
-        $walker = new Walker_Nav_Menu_Checklist($db_fields);
441
-        $current_tab = 'event-archives';
442
-        $removed_args = array(
443
-            'action',
444
-            'customlink-tab',
445
-            'edit-menu-item',
446
-            'menu-item',
447
-            'page-tab',
448
-            '_wpnonce',
449
-        );
450
-        ?>
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
+	}
168
+
169
+
170
+	/**
171
+	 * hide_admin_pages_except_maintenance_mode
172
+	 *
173
+	 * @param array $admin_page_folder_names
174
+	 * @return array
175
+	 */
176
+	public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
177
+	{
178
+		return array(
179
+			'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
180
+			'about'       => EE_ADMIN_PAGES . 'about' . DS,
181
+			'support'     => EE_ADMIN_PAGES . 'support' . DS,
182
+		);
183
+	}
184
+
185
+
186
+	/**
187
+	 * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
188
+	 * EE_Front_Controller's init phases have run
189
+	 *
190
+	 * @return void
191
+	 * @throws EE_Error
192
+	 * @throws InvalidArgumentException
193
+	 * @throws InvalidDataTypeException
194
+	 * @throws InvalidInterfaceException
195
+	 * @throws ReflectionException
196
+	 * @throws ServiceNotFoundException
197
+	 */
198
+	public function init()
199
+	{
200
+		// only enable most of the EE_Admin IF we're not in full maintenance mode
201
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
202
+			$this->initModelsReady();
203
+		}
204
+		// run the admin page factory but ONLY if we are doing an ee admin ajax request
205
+		if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
206
+			try {
207
+				// this loads the controller for the admin pages which will setup routing etc
208
+				EE_Registry::instance()->load_core('Admin_Page_Loader');
209
+			} catch (EE_Error $e) {
210
+				$e->get_error();
211
+			}
212
+		}
213
+		add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
214
+		// make sure our CPTs and custom taxonomy metaboxes get shown for first time users
215
+		add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
216
+		add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
217
+		// exclude EE critical pages from all nav menus and wp_list_pages
218
+		add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
219
+	}
220
+
221
+
222
+	/**
223
+	 * Gets the loader (and if it wasn't previously set, sets it)
224
+	 * @return LoaderInterface
225
+	 * @throws InvalidArgumentException
226
+	 * @throws InvalidDataTypeException
227
+	 * @throws InvalidInterfaceException
228
+	 */
229
+	protected function getLoader()
230
+	{
231
+		if (! $this->loader instanceof LoaderInterface) {
232
+			$this->loader = LoaderFactory::getLoader();
233
+		}
234
+		return $this->loader;
235
+	}
236
+
237
+
238
+	/**
239
+	 * Method that's fired on admin requests (including admin ajax) but only when the models are usable
240
+	 * (ie, the site isn't in maintenance mode)
241
+	 * @since 4.9.63.p
242
+	 * @return void
243
+	 */
244
+	protected function initModelsReady()
245
+	{
246
+		// ok so we want to enable the entire admin
247
+		$this->persistent_admin_notice_manager = $this->getLoader()->getShared(
248
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
249
+		);
250
+		$this->persistent_admin_notice_manager->setReturnUrl(
251
+			EE_Admin_Page::add_query_args_and_nonce(
252
+				array(
253
+					'page'   => EE_Registry::instance()->REQ->get('page', ''),
254
+					'action' => EE_Registry::instance()->REQ->get('action', ''),
255
+				),
256
+				EE_ADMIN_URL
257
+			)
258
+		);
259
+		$this->maybeSetDatetimeWarningNotice();
260
+		// at a glance dashboard widget
261
+		add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
262
+		// filter for get_edit_post_link used on comments for custom post types
263
+		add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
264
+	}
265
+
266
+
267
+	/**
268
+	 *    get_persistent_admin_notices
269
+	 *
270
+	 * @access    public
271
+	 * @return void
272
+	 * @throws EE_Error
273
+	 * @throws InvalidArgumentException
274
+	 * @throws InvalidDataTypeException
275
+	 * @throws InvalidInterfaceException
276
+	 */
277
+	public function maybeSetDatetimeWarningNotice()
278
+	{
279
+		// add dismissable notice for datetime changes.  Only valid if site does not have a timezone_string set.
280
+		// @todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
281
+		// with this.  But after enough time (indeterminate at this point) we can just remove this notice.
282
+		// this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
283
+		if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true)
284
+			&& ! get_option('timezone_string')
285
+			&& EEM_Event::instance()->count() > 0
286
+		) {
287
+			new PersistentAdminNotice(
288
+				'datetime_fix_notice',
289
+				sprintf(
290
+					esc_html__(
291
+						'%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.',
292
+						'event_espresso'
293
+					),
294
+					'<strong>',
295
+					'</strong>',
296
+					'<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
297
+					'</a>',
298
+					'<a href="' . EE_Admin_Page::add_query_args_and_nonce(
299
+						array(
300
+							'page'   => 'espresso_maintenance_settings',
301
+							'action' => 'datetime_tools',
302
+						),
303
+						admin_url('admin.php')
304
+					) . '">'
305
+				),
306
+				false,
307
+				'manage_options',
308
+				'datetime_fix_persistent_notice'
309
+			);
310
+		}
311
+	}
312
+
313
+
314
+	/**
315
+	 * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
316
+	 * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
317
+	 * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
318
+	 * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
319
+	 * normal property on the post_type object.  It's found ONLY in this particular context.
320
+	 *
321
+	 * @param WP_Post $post_type WP post type object
322
+	 * @return WP_Post
323
+	 * @throws InvalidArgumentException
324
+	 * @throws InvalidDataTypeException
325
+	 * @throws InvalidInterfaceException
326
+	 */
327
+	public function remove_pages_from_nav_menu($post_type)
328
+	{
329
+		// if this isn't the "pages" post type let's get out
330
+		if ($post_type->name !== 'page') {
331
+			return $post_type;
332
+		}
333
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
334
+		$post_type->_default_query = array(
335
+			'post__not_in' => $critical_pages,
336
+		);
337
+		return $post_type;
338
+	}
339
+
340
+
341
+	/**
342
+	 * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
343
+	 * metaboxes get shown as well
344
+	 *
345
+	 * @return void
346
+	 */
347
+	public function enable_hidden_ee_nav_menu_metaboxes()
348
+	{
349
+		global $wp_meta_boxes, $pagenow;
350
+		if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
351
+			return;
352
+		}
353
+		$user = wp_get_current_user();
354
+		// has this been done yet?
355
+		if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
356
+			return;
357
+		}
358
+
359
+		$hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID);
360
+		$initial_meta_boxes = apply_filters(
361
+			'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
362
+			array(
363
+				'nav-menu-theme-locations',
364
+				'add-page',
365
+				'add-custom-links',
366
+				'add-category',
367
+				'add-espresso_events',
368
+				'add-espresso_venues',
369
+				'add-espresso_event_categories',
370
+				'add-espresso_venue_categories',
371
+				'add-post-type-post',
372
+				'add-post-type-page',
373
+			)
374
+		);
375
+
376
+		if (is_array($hidden_meta_boxes)) {
377
+			foreach ($hidden_meta_boxes as $key => $meta_box_id) {
378
+				if (in_array($meta_box_id, $initial_meta_boxes, true)) {
379
+					unset($hidden_meta_boxes[ $key ]);
380
+				}
381
+			}
382
+		}
383
+		update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
384
+		update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
385
+	}
386
+
387
+
388
+	/**
389
+	 * This method simply registers custom nav menu boxes for "nav_menus.php route"
390
+	 * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
391
+	 *
392
+	 * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
393
+	 *         addons etc.
394
+	 * @return void
395
+	 */
396
+	public function register_custom_nav_menu_boxes()
397
+	{
398
+		add_meta_box(
399
+			'add-extra-nav-menu-pages',
400
+			esc_html__('Event Espresso Pages', 'event_espresso'),
401
+			array($this, 'ee_cpt_archive_pages'),
402
+			'nav-menus',
403
+			'side',
404
+			'core'
405
+		);
406
+	}
407
+
408
+
409
+	/**
410
+	 * Use this to edit the post link for our cpts so that the edit link points to the correct page.
411
+	 *
412
+	 * @since   4.3.0
413
+	 * @param string $link the original link generated by wp
414
+	 * @param int    $id   post id
415
+	 * @return string  the (maybe) modified link
416
+	 */
417
+	public function modify_edit_post_link($link, $id)
418
+	{
419
+		if (! $post = get_post($id)) {
420
+			return $link;
421
+		}
422
+		if ($post->post_type === 'espresso_attendees') {
423
+			$query_args = array(
424
+				'action' => 'edit_attendee',
425
+				'post'   => $id,
426
+			);
427
+			return EEH_URL::add_query_args_and_nonce(
428
+				$query_args,
429
+				admin_url('admin.php?page=espresso_registrations')
430
+			);
431
+		}
432
+		return $link;
433
+	}
434
+
435
+
436
+	public function ee_cpt_archive_pages()
437
+	{
438
+		global $nav_menu_selected_id;
439
+		$db_fields = false;
440
+		$walker = new Walker_Nav_Menu_Checklist($db_fields);
441
+		$current_tab = 'event-archives';
442
+		$removed_args = array(
443
+			'action',
444
+			'customlink-tab',
445
+			'edit-menu-item',
446
+			'menu-item',
447
+			'page-tab',
448
+			'_wpnonce',
449
+		);
450
+		?>
451 451
         <div id="posttype-extra-nav-menu-pages" class="posttypediv">
452 452
             <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs">
453 453
                 <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>>
454 454
                     <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives"
455 455
                        href="<?php
456
-                        if ($nav_menu_selected_id) {
457
-                            echo esc_url(
458
-                                add_query_arg(
459
-                                    'extra-nav-menu-pages-tab',
460
-                                    'event-archives',
461
-                                    remove_query_arg($removed_args)
462
-                                )
463
-                            );
464
-                        }
465
-                        ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
456
+						if ($nav_menu_selected_id) {
457
+							echo esc_url(
458
+								add_query_arg(
459
+									'extra-nav-menu-pages-tab',
460
+									'event-archives',
461
+									remove_query_arg($removed_args)
462
+								)
463
+							);
464
+						}
465
+						?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
466 466
                         <?php _e('Event Archive Pages', 'event_espresso'); ?>
467 467
                     </a>
468 468
                 </li>
469 469
             </ul><!-- .posttype-tabs -->
470 470
 
471 471
             <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php
472
-            echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
473
-            ?>">
472
+			echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
473
+			?>">
474 474
                 <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear">
475 475
                     <?php
476
-                    $pages = $this->_get_extra_nav_menu_pages_items();
477
-                    $args['walker'] = $walker;
478
-                    echo walk_nav_menu_tree(
479
-                        array_map(
480
-                            array($this, '_setup_extra_nav_menu_pages_items'),
481
-                            $pages
482
-                        ),
483
-                        0,
484
-                        (object) $args
485
-                    );
486
-                    ?>
476
+					$pages = $this->_get_extra_nav_menu_pages_items();
477
+					$args['walker'] = $walker;
478
+					echo walk_nav_menu_tree(
479
+						array_map(
480
+							array($this, '_setup_extra_nav_menu_pages_items'),
481
+							$pages
482
+						),
483
+						0,
484
+						(object) $args
485
+					);
486
+					?>
487 487
                 </ul>
488 488
             </div><!-- /.tabs-panel -->
489 489
 
490 490
             <p class="button-controls">
491 491
                 <span class="list-controls">
492 492
                     <a href="<?php
493
-                             echo esc_url(
494
-                                 add_query_arg(
495
-                                     array(
496
-                                         'extra-nav-menu-pages-tab' => 'event-archives',
497
-                                         'selectall'                => 1,
498
-                                     ),
499
-                                     remove_query_arg($removed_args)
500
-                                 )
501
-                             );
502
-                        ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All', 'event_espresso'); ?></a>
493
+							 echo esc_url(
494
+								 add_query_arg(
495
+									 array(
496
+										 'extra-nav-menu-pages-tab' => 'event-archives',
497
+										 'selectall'                => 1,
498
+									 ),
499
+									 remove_query_arg($removed_args)
500
+								 )
501
+							 );
502
+						?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All', 'event_espresso'); ?></a>
503 503
                 </span>
504 504
                 <span class="add-to-menu">
505 505
                     <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?>
@@ -512,500 +512,500 @@  discard block
 block discarded – undo
512 512
 
513 513
         </div><!-- /.posttypediv -->
514 514
         <?php
515
-    }
516
-
517
-
518
-    /**
519
-     * Returns an array of event archive nav items.
520
-     *
521
-     * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
522
-     *        method we use for getting the extra nav menu items
523
-     * @return array
524
-     */
525
-    private function _get_extra_nav_menu_pages_items()
526
-    {
527
-        $menuitems[] = array(
528
-            'title'       => esc_html__('Event List', 'event_espresso'),
529
-            'url'         => get_post_type_archive_link('espresso_events'),
530
-            'description' => esc_html__('Archive page for all events.', 'event_espresso'),
531
-        );
532
-        return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
533
-    }
534
-
535
-
536
-    /**
537
-     * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
538
-     * the properties and converts it to the menu item object.
539
-     *
540
-     * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
541
-     * @param $menu_item_values
542
-     * @return stdClass
543
-     */
544
-    private function _setup_extra_nav_menu_pages_items($menu_item_values)
545
-    {
546
-        $menu_item = new stdClass();
547
-        $keys = array(
548
-            'ID'               => 0,
549
-            'db_id'            => 0,
550
-            'menu_item_parent' => 0,
551
-            'object_id'        => -1,
552
-            'post_parent'      => 0,
553
-            'type'             => 'custom',
554
-            'object'           => '',
555
-            'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
556
-            'title'            => '',
557
-            'url'              => '',
558
-            'target'           => '',
559
-            'attr_title'       => '',
560
-            'description'      => '',
561
-            'classes'          => array(),
562
-            'xfn'              => '',
563
-        );
564
-
565
-        foreach ($keys as $key => $value) {
566
-            $menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value;
567
-        }
568
-        return $menu_item;
569
-    }
570
-
571
-
572
-    /**
573
-     * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
574
-     * EE_Admin_Page route is called.
575
-     *
576
-     * @return void
577
-     */
578
-    public function route_admin_request()
579
-    {
580
-    }
581
-
582
-
583
-    /**
584
-     * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
585
-     *
586
-     * @return void
587
-     */
588
-    public function wp_loaded()
589
-    {
590
-    }
591
-
592
-
593
-    /**
594
-     * admin_init
595
-     *
596
-     * @return void
597
-     * @throws EE_Error
598
-     * @throws InvalidArgumentException
599
-     * @throws InvalidDataTypeException
600
-     * @throws InvalidInterfaceException
601
-     * @throws ReflectionException
602
-     */
603
-    public function admin_init()
604
-    {
605
-        /**
606
-         * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
607
-         * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
608
-         * - check if doing post processing.
609
-         * - check if doing post processing of one of EE CPTs
610
-         * - instantiate the corresponding EE CPT model for the post_type being processed.
611
-         */
612
-        if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
613
-            /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
614
-            $custom_post_types = $this->getLoader()->getShared(
615
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
616
-            );
617
-            $custom_post_types->getCustomPostTypeModels($_POST['post_type']);
618
-        }
619
-
620
-
621
-        /**
622
-         * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
623
-         * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
624
-         * Pages" tab in the EE General Settings Admin page.
625
-         * This is for user-proofing.
626
-         */
627
-        add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
628
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
629
-            $this->adminInitModelsReady();
630
-        }
631
-    }
632
-
633
-
634
-    /**
635
-     * Runs on admin_init but only if models are usable (ie, we're not in maintenanc emode)
636
-     */
637
-    protected function adminInitModelsReady()
638
-    {
639
-        if (function_exists('wp_add_privacy_policy_content')) {
640
-            $this->getLoader()->getShared('EventEspresso\core\services\privacy\policy\PrivacyPolicyManager');
641
-        }
642
-    }
643
-
644
-
645
-    /**
646
-     * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
647
-     *
648
-     * @param string $output Current output.
649
-     * @return string
650
-     * @throws InvalidArgumentException
651
-     * @throws InvalidDataTypeException
652
-     * @throws InvalidInterfaceException
653
-     */
654
-    public function modify_dropdown_pages($output)
655
-    {
656
-        // get critical pages
657
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
658
-
659
-        // split current output by line break for easier parsing.
660
-        $split_output = explode("\n", $output);
661
-
662
-        // loop through to remove any critical pages from the array.
663
-        foreach ($critical_pages as $page_id) {
664
-            $needle = 'value="' . $page_id . '"';
665
-            foreach ($split_output as $key => $haystack) {
666
-                if (strpos($haystack, $needle) !== false) {
667
-                    unset($split_output[ $key ]);
668
-                }
669
-            }
670
-        }
671
-        // replace output with the new contents
672
-        return implode("\n", $split_output);
673
-    }
674
-
675
-
676
-    /**
677
-     * enqueue all admin scripts that need loaded for admin pages
678
-     *
679
-     * @return void
680
-     */
681
-    public function enqueue_admin_scripts()
682
-    {
683
-        // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
684
-        // Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
685
-        // calls.
686
-        wp_enqueue_script(
687
-            'ee-inject-wp',
688
-            EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
689
-            array('jquery'),
690
-            EVENT_ESPRESSO_VERSION,
691
-            true
692
-        );
693
-        // register cookie script for future dependencies
694
-        wp_register_script(
695
-            'jquery-cookie',
696
-            EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
697
-            array('jquery'),
698
-            '2.1',
699
-            true
700
-        );
701
-        // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again
702
-        // via: add_filter('FHEE_load_joyride', '__return_true' );
703
-        if (apply_filters('FHEE_load_joyride', false)) {
704
-            // joyride style
705
-            wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
706
-            wp_register_style(
707
-                'ee-joyride-css',
708
-                EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
709
-                array('joyride-css'),
710
-                EVENT_ESPRESSO_VERSION
711
-            );
712
-            wp_register_script(
713
-                'joyride-modernizr',
714
-                EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
715
-                array(),
716
-                '2.1',
717
-                true
718
-            );
719
-            // joyride JS
720
-            wp_register_script(
721
-                'jquery-joyride',
722
-                EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
723
-                array('jquery-cookie', 'joyride-modernizr'),
724
-                '2.1',
725
-                true
726
-            );
727
-            // wanna go for a joyride?
728
-            wp_enqueue_style('ee-joyride-css');
729
-            wp_enqueue_script('jquery-joyride');
730
-        }
731
-    }
732
-
733
-
734
-    /**
735
-     * display_admin_notices
736
-     *
737
-     * @return void
738
-     */
739
-    public function display_admin_notices()
740
-    {
741
-        echo EE_Error::get_notices();
742
-    }
743
-
744
-
745
-    /**
746
-     * @param array $elements
747
-     * @return array
748
-     * @throws EE_Error
749
-     * @throws InvalidArgumentException
750
-     * @throws InvalidDataTypeException
751
-     * @throws InvalidInterfaceException
752
-     */
753
-    public function dashboard_glance_items($elements)
754
-    {
755
-        $elements = is_array($elements) ? $elements : array($elements);
756
-        $events = EEM_Event::instance()->count();
757
-        $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(
758
-            array('page' => 'espresso_events'),
759
-            admin_url('admin.php')
760
-        );
761
-        $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events, 'event_espresso'), number_format_i18n($events));
762
-        $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso');
763
-        $registrations = EEM_Registration::instance()->count(
764
-            array(
765
-                array(
766
-                    'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
767
-                ),
768
-            )
769
-        );
770
-        $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(
771
-            array('page' => 'espresso_registrations'),
772
-            admin_url('admin.php')
773
-        );
774
-        $items['registrations']['text'] = sprintf(
775
-            _n('%s Registration', '%s Registrations', $registrations, 'event_espresso'),
776
-            number_format_i18n($registrations)
777
-        );
778
-        $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
779
-
780
-        $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
781
-
782
-        foreach ($items as $type => $item_properties) {
783
-            $elements[] = sprintf(
784
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
785
-                $item_properties['url'],
786
-                $item_properties['title'],
787
-                $item_properties['text']
788
-            );
789
-        }
790
-        return $elements;
791
-    }
792
-
793
-
794
-    /**
795
-     * check_for_invalid_datetime_formats
796
-     * if an admin changes their date or time format settings on the WP General Settings admin page, verify that
797
-     * their selected format can be parsed by PHP
798
-     *
799
-     * @param    $value
800
-     * @param    $option
801
-     * @throws EE_Error
802
-     * @return    string
803
-     */
804
-    public function check_for_invalid_datetime_formats($value, $option)
805
-    {
806
-        // check for date_format or time_format
807
-        switch ($option) {
808
-            case 'date_format':
809
-                $date_time_format = $value . ' ' . get_option('time_format');
810
-                break;
811
-            case 'time_format':
812
-                $date_time_format = get_option('date_format') . ' ' . $value;
813
-                break;
814
-            default:
815
-                $date_time_format = false;
816
-        }
817
-        // do we have a date_time format to check ?
818
-        if ($date_time_format) {
819
-            $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
820
-
821
-            if (is_array($error_msg)) {
822
-                $msg = '<p>'
823
-                       . sprintf(
824
-                           esc_html__(
825
-                               'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
826
-                               'event_espresso'
827
-                           ),
828
-                           date($date_time_format),
829
-                           $date_time_format
830
-                       )
831
-                       . '</p><p><ul>';
832
-
833
-
834
-                foreach ($error_msg as $error) {
835
-                    $msg .= '<li>' . $error . '</li>';
836
-                }
837
-
838
-                $msg .= '</ul></p><p>'
839
-                        . sprintf(
840
-                            esc_html__(
841
-                                '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
842
-                                'event_espresso'
843
-                            ),
844
-                            '<span style="color:#D54E21;">',
845
-                            '</span>'
846
-                        )
847
-                        . '</p>';
848
-
849
-                // trigger WP settings error
850
-                add_settings_error(
851
-                    'date_format',
852
-                    'date_format',
853
-                    $msg
854
-                );
855
-
856
-                // set format to something valid
857
-                switch ($option) {
858
-                    case 'date_format':
859
-                        $value = 'F j, Y';
860
-                        break;
861
-                    case 'time_format':
862
-                        $value = 'g:i a';
863
-                        break;
864
-                }
865
-            }
866
-        }
867
-        return $value;
868
-    }
869
-
870
-
871
-    /**
872
-     * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
873
-     *
874
-     * @param $content
875
-     * @return    string
876
-     */
877
-    public function its_eSpresso($content)
878
-    {
879
-        return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
880
-    }
881
-
882
-
883
-    /**
884
-     * espresso_admin_footer
885
-     *
886
-     * @return    string
887
-     */
888
-    public function espresso_admin_footer()
889
-    {
890
-        return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
891
-    }
892
-
893
-
894
-    /**
895
-     * static method for registering ee admin page.
896
-     * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
897
-     *
898
-     * @since      4.3.0
899
-     * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
900
-     * @see        EE_Register_Admin_Page::register()
901
-     * @param       $page_basename
902
-     * @param       $page_path
903
-     * @param array $config
904
-     * @return void
905
-     * @throws EE_Error
906
-     */
907
-    public static function register_ee_admin_page($page_basename, $page_path, $config = array())
908
-    {
909
-        EE_Error::doing_it_wrong(
910
-            __METHOD__,
911
-            sprintf(
912
-                esc_html__(
913
-                    'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
914
-                    'event_espresso'
915
-                ),
916
-                $page_basename
917
-            ),
918
-            '4.3'
919
-        );
920
-        if (class_exists('EE_Register_Admin_Page')) {
921
-            $config['page_path'] = $page_path;
922
-        }
923
-        EE_Register_Admin_Page::register($page_basename, $config);
924
-    }
925
-
926
-
927
-    /**
928
-     * @deprecated 4.8.41
929
-     * @param  int      $post_ID
930
-     * @param  \WP_Post $post
931
-     * @return void
932
-     */
933
-    public static function parse_post_content_on_save($post_ID, $post)
934
-    {
935
-        EE_Error::doing_it_wrong(
936
-            __METHOD__,
937
-            esc_html__('Usage is deprecated', 'event_espresso'),
938
-            '4.8.41'
939
-        );
940
-    }
941
-
942
-
943
-    /**
944
-     * @deprecated 4.8.41
945
-     * @param  $option
946
-     * @param  $old_value
947
-     * @param  $value
948
-     * @return void
949
-     */
950
-    public function reset_page_for_posts_on_change($option, $old_value, $value)
951
-    {
952
-        EE_Error::doing_it_wrong(
953
-            __METHOD__,
954
-            esc_html__('Usage is deprecated', 'event_espresso'),
955
-            '4.8.41'
956
-        );
957
-    }
958
-
959
-
960
-    /**
961
-     * @deprecated 4.9.27
962
-     * @return void
963
-     */
964
-    public function get_persistent_admin_notices()
965
-    {
966
-        EE_Error::doing_it_wrong(
967
-            __METHOD__,
968
-            sprintf(
969
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
970
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
971
-            ),
972
-            '4.9.27'
973
-        );
974
-    }
975
-
976
-
977
-    /**
978
-     * @deprecated 4.9.27
979
-     * @throws InvalidInterfaceException
980
-     * @throws InvalidDataTypeException
981
-     * @throws DomainException
982
-     */
983
-    public function dismiss_ee_nag_notice_callback()
984
-    {
985
-        EE_Error::doing_it_wrong(
986
-            __METHOD__,
987
-            sprintf(
988
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
989
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
990
-            ),
991
-            '4.9.27'
992
-        );
993
-        $this->persistent_admin_notice_manager->dismissNotice();
994
-    }
995
-
996
-
997
-    /**
998
-     * Callback on load-plugins.php hook for setting up anything hooking into the wp plugins page.
999
-     *
1000
-     * @throws InvalidArgumentException
1001
-     * @throws InvalidDataTypeException
1002
-     * @throws InvalidInterfaceException
1003
-     */
1004
-    public function hookIntoWpPluginsPage()
1005
-    {
1006
-        $this->getLoader()->getShared('EventEspresso\core\domain\services\admin\ExitModal');
1007
-        $this->getLoader()
1008
-                     ->getShared('EventEspresso\core\domain\services\admin\PluginUpsells')
1009
-                     ->decafUpsells();
1010
-    }
515
+	}
516
+
517
+
518
+	/**
519
+	 * Returns an array of event archive nav items.
520
+	 *
521
+	 * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
522
+	 *        method we use for getting the extra nav menu items
523
+	 * @return array
524
+	 */
525
+	private function _get_extra_nav_menu_pages_items()
526
+	{
527
+		$menuitems[] = array(
528
+			'title'       => esc_html__('Event List', 'event_espresso'),
529
+			'url'         => get_post_type_archive_link('espresso_events'),
530
+			'description' => esc_html__('Archive page for all events.', 'event_espresso'),
531
+		);
532
+		return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
533
+	}
534
+
535
+
536
+	/**
537
+	 * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
538
+	 * the properties and converts it to the menu item object.
539
+	 *
540
+	 * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
541
+	 * @param $menu_item_values
542
+	 * @return stdClass
543
+	 */
544
+	private function _setup_extra_nav_menu_pages_items($menu_item_values)
545
+	{
546
+		$menu_item = new stdClass();
547
+		$keys = array(
548
+			'ID'               => 0,
549
+			'db_id'            => 0,
550
+			'menu_item_parent' => 0,
551
+			'object_id'        => -1,
552
+			'post_parent'      => 0,
553
+			'type'             => 'custom',
554
+			'object'           => '',
555
+			'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
556
+			'title'            => '',
557
+			'url'              => '',
558
+			'target'           => '',
559
+			'attr_title'       => '',
560
+			'description'      => '',
561
+			'classes'          => array(),
562
+			'xfn'              => '',
563
+		);
564
+
565
+		foreach ($keys as $key => $value) {
566
+			$menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value;
567
+		}
568
+		return $menu_item;
569
+	}
570
+
571
+
572
+	/**
573
+	 * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
574
+	 * EE_Admin_Page route is called.
575
+	 *
576
+	 * @return void
577
+	 */
578
+	public function route_admin_request()
579
+	{
580
+	}
581
+
582
+
583
+	/**
584
+	 * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
585
+	 *
586
+	 * @return void
587
+	 */
588
+	public function wp_loaded()
589
+	{
590
+	}
591
+
592
+
593
+	/**
594
+	 * admin_init
595
+	 *
596
+	 * @return void
597
+	 * @throws EE_Error
598
+	 * @throws InvalidArgumentException
599
+	 * @throws InvalidDataTypeException
600
+	 * @throws InvalidInterfaceException
601
+	 * @throws ReflectionException
602
+	 */
603
+	public function admin_init()
604
+	{
605
+		/**
606
+		 * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
607
+		 * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
608
+		 * - check if doing post processing.
609
+		 * - check if doing post processing of one of EE CPTs
610
+		 * - instantiate the corresponding EE CPT model for the post_type being processed.
611
+		 */
612
+		if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
613
+			/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
614
+			$custom_post_types = $this->getLoader()->getShared(
615
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
616
+			);
617
+			$custom_post_types->getCustomPostTypeModels($_POST['post_type']);
618
+		}
619
+
620
+
621
+		/**
622
+		 * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
623
+		 * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
624
+		 * Pages" tab in the EE General Settings Admin page.
625
+		 * This is for user-proofing.
626
+		 */
627
+		add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
628
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
629
+			$this->adminInitModelsReady();
630
+		}
631
+	}
632
+
633
+
634
+	/**
635
+	 * Runs on admin_init but only if models are usable (ie, we're not in maintenanc emode)
636
+	 */
637
+	protected function adminInitModelsReady()
638
+	{
639
+		if (function_exists('wp_add_privacy_policy_content')) {
640
+			$this->getLoader()->getShared('EventEspresso\core\services\privacy\policy\PrivacyPolicyManager');
641
+		}
642
+	}
643
+
644
+
645
+	/**
646
+	 * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
647
+	 *
648
+	 * @param string $output Current output.
649
+	 * @return string
650
+	 * @throws InvalidArgumentException
651
+	 * @throws InvalidDataTypeException
652
+	 * @throws InvalidInterfaceException
653
+	 */
654
+	public function modify_dropdown_pages($output)
655
+	{
656
+		// get critical pages
657
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
658
+
659
+		// split current output by line break for easier parsing.
660
+		$split_output = explode("\n", $output);
661
+
662
+		// loop through to remove any critical pages from the array.
663
+		foreach ($critical_pages as $page_id) {
664
+			$needle = 'value="' . $page_id . '"';
665
+			foreach ($split_output as $key => $haystack) {
666
+				if (strpos($haystack, $needle) !== false) {
667
+					unset($split_output[ $key ]);
668
+				}
669
+			}
670
+		}
671
+		// replace output with the new contents
672
+		return implode("\n", $split_output);
673
+	}
674
+
675
+
676
+	/**
677
+	 * enqueue all admin scripts that need loaded for admin pages
678
+	 *
679
+	 * @return void
680
+	 */
681
+	public function enqueue_admin_scripts()
682
+	{
683
+		// this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
684
+		// Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
685
+		// calls.
686
+		wp_enqueue_script(
687
+			'ee-inject-wp',
688
+			EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
689
+			array('jquery'),
690
+			EVENT_ESPRESSO_VERSION,
691
+			true
692
+		);
693
+		// register cookie script for future dependencies
694
+		wp_register_script(
695
+			'jquery-cookie',
696
+			EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
697
+			array('jquery'),
698
+			'2.1',
699
+			true
700
+		);
701
+		// joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again
702
+		// via: add_filter('FHEE_load_joyride', '__return_true' );
703
+		if (apply_filters('FHEE_load_joyride', false)) {
704
+			// joyride style
705
+			wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
706
+			wp_register_style(
707
+				'ee-joyride-css',
708
+				EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
709
+				array('joyride-css'),
710
+				EVENT_ESPRESSO_VERSION
711
+			);
712
+			wp_register_script(
713
+				'joyride-modernizr',
714
+				EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
715
+				array(),
716
+				'2.1',
717
+				true
718
+			);
719
+			// joyride JS
720
+			wp_register_script(
721
+				'jquery-joyride',
722
+				EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
723
+				array('jquery-cookie', 'joyride-modernizr'),
724
+				'2.1',
725
+				true
726
+			);
727
+			// wanna go for a joyride?
728
+			wp_enqueue_style('ee-joyride-css');
729
+			wp_enqueue_script('jquery-joyride');
730
+		}
731
+	}
732
+
733
+
734
+	/**
735
+	 * display_admin_notices
736
+	 *
737
+	 * @return void
738
+	 */
739
+	public function display_admin_notices()
740
+	{
741
+		echo EE_Error::get_notices();
742
+	}
743
+
744
+
745
+	/**
746
+	 * @param array $elements
747
+	 * @return array
748
+	 * @throws EE_Error
749
+	 * @throws InvalidArgumentException
750
+	 * @throws InvalidDataTypeException
751
+	 * @throws InvalidInterfaceException
752
+	 */
753
+	public function dashboard_glance_items($elements)
754
+	{
755
+		$elements = is_array($elements) ? $elements : array($elements);
756
+		$events = EEM_Event::instance()->count();
757
+		$items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(
758
+			array('page' => 'espresso_events'),
759
+			admin_url('admin.php')
760
+		);
761
+		$items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events, 'event_espresso'), number_format_i18n($events));
762
+		$items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso');
763
+		$registrations = EEM_Registration::instance()->count(
764
+			array(
765
+				array(
766
+					'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
767
+				),
768
+			)
769
+		);
770
+		$items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(
771
+			array('page' => 'espresso_registrations'),
772
+			admin_url('admin.php')
773
+		);
774
+		$items['registrations']['text'] = sprintf(
775
+			_n('%s Registration', '%s Registrations', $registrations, 'event_espresso'),
776
+			number_format_i18n($registrations)
777
+		);
778
+		$items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
779
+
780
+		$items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
781
+
782
+		foreach ($items as $type => $item_properties) {
783
+			$elements[] = sprintf(
784
+				'<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
785
+				$item_properties['url'],
786
+				$item_properties['title'],
787
+				$item_properties['text']
788
+			);
789
+		}
790
+		return $elements;
791
+	}
792
+
793
+
794
+	/**
795
+	 * check_for_invalid_datetime_formats
796
+	 * if an admin changes their date or time format settings on the WP General Settings admin page, verify that
797
+	 * their selected format can be parsed by PHP
798
+	 *
799
+	 * @param    $value
800
+	 * @param    $option
801
+	 * @throws EE_Error
802
+	 * @return    string
803
+	 */
804
+	public function check_for_invalid_datetime_formats($value, $option)
805
+	{
806
+		// check for date_format or time_format
807
+		switch ($option) {
808
+			case 'date_format':
809
+				$date_time_format = $value . ' ' . get_option('time_format');
810
+				break;
811
+			case 'time_format':
812
+				$date_time_format = get_option('date_format') . ' ' . $value;
813
+				break;
814
+			default:
815
+				$date_time_format = false;
816
+		}
817
+		// do we have a date_time format to check ?
818
+		if ($date_time_format) {
819
+			$error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
820
+
821
+			if (is_array($error_msg)) {
822
+				$msg = '<p>'
823
+					   . sprintf(
824
+						   esc_html__(
825
+							   'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
826
+							   'event_espresso'
827
+						   ),
828
+						   date($date_time_format),
829
+						   $date_time_format
830
+					   )
831
+					   . '</p><p><ul>';
832
+
833
+
834
+				foreach ($error_msg as $error) {
835
+					$msg .= '<li>' . $error . '</li>';
836
+				}
837
+
838
+				$msg .= '</ul></p><p>'
839
+						. sprintf(
840
+							esc_html__(
841
+								'%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
842
+								'event_espresso'
843
+							),
844
+							'<span style="color:#D54E21;">',
845
+							'</span>'
846
+						)
847
+						. '</p>';
848
+
849
+				// trigger WP settings error
850
+				add_settings_error(
851
+					'date_format',
852
+					'date_format',
853
+					$msg
854
+				);
855
+
856
+				// set format to something valid
857
+				switch ($option) {
858
+					case 'date_format':
859
+						$value = 'F j, Y';
860
+						break;
861
+					case 'time_format':
862
+						$value = 'g:i a';
863
+						break;
864
+				}
865
+			}
866
+		}
867
+		return $value;
868
+	}
869
+
870
+
871
+	/**
872
+	 * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
873
+	 *
874
+	 * @param $content
875
+	 * @return    string
876
+	 */
877
+	public function its_eSpresso($content)
878
+	{
879
+		return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
880
+	}
881
+
882
+
883
+	/**
884
+	 * espresso_admin_footer
885
+	 *
886
+	 * @return    string
887
+	 */
888
+	public function espresso_admin_footer()
889
+	{
890
+		return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
891
+	}
892
+
893
+
894
+	/**
895
+	 * static method for registering ee admin page.
896
+	 * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
897
+	 *
898
+	 * @since      4.3.0
899
+	 * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
900
+	 * @see        EE_Register_Admin_Page::register()
901
+	 * @param       $page_basename
902
+	 * @param       $page_path
903
+	 * @param array $config
904
+	 * @return void
905
+	 * @throws EE_Error
906
+	 */
907
+	public static function register_ee_admin_page($page_basename, $page_path, $config = array())
908
+	{
909
+		EE_Error::doing_it_wrong(
910
+			__METHOD__,
911
+			sprintf(
912
+				esc_html__(
913
+					'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
914
+					'event_espresso'
915
+				),
916
+				$page_basename
917
+			),
918
+			'4.3'
919
+		);
920
+		if (class_exists('EE_Register_Admin_Page')) {
921
+			$config['page_path'] = $page_path;
922
+		}
923
+		EE_Register_Admin_Page::register($page_basename, $config);
924
+	}
925
+
926
+
927
+	/**
928
+	 * @deprecated 4.8.41
929
+	 * @param  int      $post_ID
930
+	 * @param  \WP_Post $post
931
+	 * @return void
932
+	 */
933
+	public static function parse_post_content_on_save($post_ID, $post)
934
+	{
935
+		EE_Error::doing_it_wrong(
936
+			__METHOD__,
937
+			esc_html__('Usage is deprecated', 'event_espresso'),
938
+			'4.8.41'
939
+		);
940
+	}
941
+
942
+
943
+	/**
944
+	 * @deprecated 4.8.41
945
+	 * @param  $option
946
+	 * @param  $old_value
947
+	 * @param  $value
948
+	 * @return void
949
+	 */
950
+	public function reset_page_for_posts_on_change($option, $old_value, $value)
951
+	{
952
+		EE_Error::doing_it_wrong(
953
+			__METHOD__,
954
+			esc_html__('Usage is deprecated', 'event_espresso'),
955
+			'4.8.41'
956
+		);
957
+	}
958
+
959
+
960
+	/**
961
+	 * @deprecated 4.9.27
962
+	 * @return void
963
+	 */
964
+	public function get_persistent_admin_notices()
965
+	{
966
+		EE_Error::doing_it_wrong(
967
+			__METHOD__,
968
+			sprintf(
969
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
970
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
971
+			),
972
+			'4.9.27'
973
+		);
974
+	}
975
+
976
+
977
+	/**
978
+	 * @deprecated 4.9.27
979
+	 * @throws InvalidInterfaceException
980
+	 * @throws InvalidDataTypeException
981
+	 * @throws DomainException
982
+	 */
983
+	public function dismiss_ee_nag_notice_callback()
984
+	{
985
+		EE_Error::doing_it_wrong(
986
+			__METHOD__,
987
+			sprintf(
988
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
989
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
990
+			),
991
+			'4.9.27'
992
+		);
993
+		$this->persistent_admin_notice_manager->dismissNotice();
994
+	}
995
+
996
+
997
+	/**
998
+	 * Callback on load-plugins.php hook for setting up anything hooking into the wp plugins page.
999
+	 *
1000
+	 * @throws InvalidArgumentException
1001
+	 * @throws InvalidDataTypeException
1002
+	 * @throws InvalidInterfaceException
1003
+	 */
1004
+	public function hookIntoWpPluginsPage()
1005
+	{
1006
+		$this->getLoader()->getShared('EventEspresso\core\domain\services\admin\ExitModal');
1007
+		$this->getLoader()
1008
+					 ->getShared('EventEspresso\core\domain\services\admin\PluginUpsells')
1009
+					 ->decafUpsells();
1010
+	}
1011 1011
 }
Please login to merge, or discard this patch.