PluginProbe
ElasticPress / 5.0.2
ElasticPress v5.0.2
5.3.5 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 All 108 releases
elasticpress / elasticpress.php

elasticpress.php in ElasticPress 5.0.2, at elasticpress.php

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