PluginProbe
ElasticPress / 5.3.2
ElasticPress v5.3.2
5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 5.1.0 All 107 releases
elasticpress / elasticpress.php

elasticpress.php in ElasticPress 5.3.2, at elasticpress.php

321 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: ElasticPress
4 * Plugin URI: https://github.com/10up/ElasticPress
5 * Description: A fast and flexible search and query engine for WordPress.
6 * Version: 5.3.2
7 * Requires at least: 6.2
8 * Requires PHP: 7.4
9 * Author: 10up
10 * Author URI: https://10up.com
11 * License: GPL v2 or later
12 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
13 * Text Domain: elasticpress
14 * Domain Path: /lang
15 *
16 * This program derives work from Alley Interactive's SearchPress
17 * and Automattic's VIP search plugin:
18 *
19 * Copyright (C) 2012-2013 Automattic
20 * Copyright (C) 2013 SearchPress
21 *
22 * @package elasticpress
23 */
24
25 namespace ElasticPress;
26
27 use WP_CLI;
28
29 if ( ! defined( 'ABSPATH' ) ) {
30 exit; // Exit if accessed directly.
31 }
32
33 define( 'EP_URL', plugin_dir_url( __FILE__ ) );
34 define( 'EP_PATH', plugin_dir_path( __FILE__ ) );
35 define( 'EP_FILE', plugin_basename( __FILE__ ) );
36 define( 'EP_VERSION', '5.3.2' );
37
38 define( 'EP_PHP_VERSION_MIN', '7.4' );
39
40 if ( ! version_compare( phpversion(), EP_PHP_VERSION_MIN, '>=' ) ) {
41 add_action(
42 'admin_notices',
43 function () {
44 ?>
45 <div class="notice notice-error">
46 <p>
47 <?php
48 echo wp_kses_post(
49 sprintf(
50 /* translators: %s: Minimum required PHP version */
51 __( 'ElasticPress requires PHP version %s or later. Please upgrade PHP or disable the plugin.', 'elasticpress' ),
52 EP_PHP_VERSION_MIN
53 )
54 );
55 ?>
56 </p>
57 </div>
58 <?php
59 }
60 );
61 return;
62 }
63
64 // Require Composer autoloader if it exists.
65 if ( file_exists( __DIR__ . '/vendor-prefixed/autoload.php' ) ) {
66 require_once __DIR__ . '/vendor-prefixed/autoload.php';
67 }
68
69 /**
70 * PSR-4-ish autoloading
71 *
72 * @since 2.6
73 */
74 spl_autoload_register(
75 function ( $class_name ) {
76 // project-specific namespace prefix.
77 $prefix = 'ElasticPress\\';
78
79 // base directory for the namespace prefix.
80 $base_dir = __DIR__ . '/includes/classes/';
81
82 // does the class use the namespace prefix?
83 $len = strlen( $prefix );
84
85 if ( strncmp( $prefix, $class_name, $len ) !== 0 ) {
86 return;
87 }
88
89 $relative_class = substr( $class_name, $len );
90
91 $file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php';
92
93 // if the file exists, require it.
94 if ( file_exists( $file ) ) {
95 require $file;
96 }
97 }
98 );
99
100 /**
101 * We compare the current ES version to this compatibility version number. Compatibility is true when:
102 *
103 * EP_ES_VERSION_MIN <= YOUR ES VERSION <= EP_ES_VERSION_MAX
104 *
105 * We don't check minor releases so if your ES version if 7.10.1, we consider that 7.10 in our comparison.
106 *
107 * @since 2.2
108 */
109 define( 'EP_ES_VERSION_MAX', '9.999' );
110 define( 'EP_ES_VERSION_MIN', '5.2' );
111
112 require_once __DIR__ . '/includes/compat.php';
113 require_once __DIR__ . '/includes/utils.php';
114 require_once __DIR__ . '/includes/health-check.php';
115
116 // Define a constant if we're network activated to allow plugin to respond accordingly.
117 $network_activated = Utils\is_network_activated( EP_FILE );
118
119 if ( $network_activated ) {
120 define( 'EP_IS_NETWORK', true );
121 }
122
123 /**
124 * Return the ElasticPress container
125 *
126 * @since 4.7.0
127 * @return Container
128 */
129 function get_container() {
130 static $container = null;
131
132 if ( ! $container ) {
133 $container = new Container();
134 }
135
136 return $container;
137 }
138
139 /**
140 * Sets up the indexables and features.
141 *
142 * @return void
143 */
144 function register_indexable_posts() {
145 /**
146 * Handle indexables
147 */
148 Indexables::factory()->register( new Indexable\Post\Post() );
149
150 /**
151 * Handle features
152 */
153 Features::factory()->register_feature(
154 new Feature\Search\Search()
155 );
156
157 Features::factory()->register_feature(
158 new Feature\InstantResults\InstantResults()
159 );
160
161 Features::factory()->register_feature(
162 new Feature\Autosuggest\Autosuggest()
163 );
164
165 Features::factory()->register_feature(
166 new Feature\DidYouMean\DidYouMean()
167 );
168
169 Features::factory()->register_feature(
170 new Feature\WooCommerce\WooCommerce()
171 );
172
173 Features::factory()->register_feature(
174 new Feature\Facets\Facets()
175 );
176
177 Features::factory()->register_feature(
178 new Feature\RelatedPosts\RelatedPosts()
179 );
180
181 Features::factory()->register_feature(
182 new Feature\SearchOrdering\SearchOrdering()
183 );
184
185 Features::factory()->register_feature(
186 new Feature\ProtectedContent\ProtectedContent()
187 );
188
189 Features::factory()->register_feature(
190 new Feature\Documents\Documents()
191 );
192
193 Features::factory()->register_feature(
194 new Feature\AcfRepeater\AcfRepeater()
195 );
196
197 Features::factory()->register_feature(
198 new Feature\Comments\Comments()
199 );
200
201 Features::factory()->register_feature(
202 new Feature\Terms\Terms()
203 );
204
205 /**
206 * Register search algorithms
207 */
208 SearchAlgorithms::factory()->register( new SearchAlgorithm\DefaultAlgorithm() );
209 SearchAlgorithms::factory()->register( new SearchAlgorithm\Version_350() );
210 SearchAlgorithms::factory()->register( new SearchAlgorithm\Version_400() );
211
212 /**
213 * Filter the query logger object
214 *
215 * @since 4.4.0
216 * @hook ep_query_logger
217 * @param {QueryLogger} $query_logger Default query logger
218 * @return {QueryLogger} New query logger
219 */
220 $query_logger = apply_filters( 'ep_query_logger', new \ElasticPress\QueryLogger() );
221 get_container()->set( '\ElasticPress\QueryLogger', $query_logger, true );
222
223 get_container()->set( '\ElasticPress\AdminBar', new \ElasticPress\AdminBar(), true );
224 get_container()->set( '\ElasticPress\BlockTemplateUtils', new \ElasticPress\BlockTemplateUtils(), true );
225 get_container()->set( '\ElasticPress\ElasticPressIo', new \ElasticPress\ElasticPressIo() );
226 get_container()->set( '\ElasticPress\ElementorUtils', new \ElasticPress\ElementorUtils(), true );
227 }
228 add_action( 'plugins_loaded', __NAMESPACE__ . '\register_indexable_posts' );
229
230 /**
231 * Set the availability of dashboard sync functionality. Defaults to true (enabled).
232 *
233 * Sync can be disabled by defining EP_DASHBOARD_SYNC as false in wp-config.php.
234 * NOTE: Must be defined BEFORE `require_once(ABSPATH . 'wp-settings.php');` in wp-config.php.
235 *
236 * @since 2.3
237 */
238 if ( ! defined( 'EP_DASHBOARD_SYNC' ) ) {
239 define( 'EP_DASHBOARD_SYNC', true );
240 }
241
242 /**
243 * Setup installer
244 */
245 Installer::factory();
246
247 /**
248 * Setup screen
249 */
250 Screen::factory();
251
252 /**
253 * Setup dashboard
254 */
255 require_once __DIR__ . '/includes/dashboard.php';
256 Dashboard\setup();
257
258 /**
259 * WP CLI Commands
260 */
261 if ( defined( 'WP_CLI' ) && WP_CLI ) {
262 WP_CLI::add_command( 'elasticpress', __NAMESPACE__ . '\Command' );
263 }
264
265 /**
266 * Setup upgrades
267 */
268 Upgrades::factory();
269
270 /**
271 * Handle upgrades. Certain version require a re-sync on upgrade.
272 * Deprecated in favor of `\ElasticPress\Upgrades::factory()`.
273 *
274 * @since 2.2
275 */
276 function handle_upgrades() {
277 _deprecated_function( __CLASS__, '3.5.2', '\ElasticPress\Upgrades::factory()' );
278 }
279
280 /**
281 * Load text domain and handle debugging
282 *
283 * @since 2.2
284 */
285 function setup_misc() {
286 if ( is_user_logged_in() && ! defined( 'WP_EP_DEBUG' ) ) {
287 require_once ABSPATH . 'wp-admin/includes/plugin.php';
288 define( 'WP_EP_DEBUG', is_plugin_active( 'debug-bar-elasticpress/debug-bar-elasticpress.php' ) );
289 }
290 }
291 add_action( 'plugins_loaded', __NAMESPACE__ . '\setup_misc' );
292
293 /**
294 * Load text domain
295 *
296 * @since 5.1.4
297 */
298 function i18n() {
299 load_plugin_textdomain( 'elasticpress', false, basename( __DIR__ ) . '/lang' );
300 }
301 add_action( 'init', __NAMESPACE__ . '\i18n' );
302
303 /**
304 * Set up role(s) with EP capability
305 */
306 function setup_roles() {
307 // add custom capabilities to admin role
308 $role = get_role( 'administrator' );
309
310 $role->add_cap( Utils\get_capability() );
311 }
312 register_activation_hook( __FILE__, __NAMESPACE__ . '\setup_roles' );
313
314 /**
315 * Fires after Elasticpress plugin is loaded
316 *
317 * @since 2.0
318 * @hook elasticpress_loaded
319 */
320 do_action( 'elasticpress_loaded' );
321