PluginProbe
ElasticPress / 4.7.2
ElasticPress v4.7.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 4.7.2, at elasticpress.php

323 lines 7.6 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: 4.7.2
7 * Requires at least: 5.6
8 * Requires PHP: 7.0
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', '4.7.2' );
36
37 define( 'EP_PHP_VERSION_MIN', '7.0' );
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 /**
197 * Filter whether the Users feature should be registered or not.
198 *
199 * The Users feature is going to be migrated to ElasticPress Labs. If EP Labs is enabled
200 * and in a more recent version, it will change this to false and load its own version
201 * of the Users feature.
202 *
203 * @hook ep_user_register_feature
204 * @since 4.5.0
205 * @param {bool} $version Version
206 * @return {bool} New version
207 */
208 if ( apply_filters( 'ep_user_register_feature', true ) ) {
209 Features::factory()->register_feature(
210 new Feature\Users\Users()
211 );
212 }
213
214 Features::factory()->register_feature(
215 new Feature\Terms\Terms()
216 );
217
218 /**
219 * Register search algorithms
220 */
221 SearchAlgorithms::factory()->register( new SearchAlgorithm\DefaultAlgorithm() );
222 SearchAlgorithms::factory()->register( new SearchAlgorithm\Version_350() );
223 SearchAlgorithms::factory()->register( new SearchAlgorithm\Version_400() );
224
225 /**
226 * Filter the query logger object
227 *
228 * @since 4.4.0
229 * @hook ep_query_logger
230 * @param {QueryLogger} $query_logger Default query logger
231 * @return {QueryLogger} New query logger
232 */
233 $query_logger = apply_filters( 'ep_query_logger', new \ElasticPress\QueryLogger() );
234 get_container()->set( '\ElasticPress\QueryLogger', $query_logger, true );
235
236 get_container()->set( '\ElasticPress\BlockTemplateUtils', new \ElasticPress\BlockTemplateUtils(), true );
237 }
238 add_action( 'plugins_loaded', __NAMESPACE__ . '\register_indexable_posts' );
239
240 /**
241 * Set the availability of dashboard sync functionality. Defaults to true (enabled).
242 *
243 * Sync can be disabled by defining EP_DASHBOARD_SYNC as false in wp-config.php.
244 * NOTE: Must be defined BEFORE `require_once(ABSPATH . 'wp-settings.php');` in wp-config.php.
245 *
246 * @since 2.3
247 */
248 if ( ! defined( 'EP_DASHBOARD_SYNC' ) ) {
249 define( 'EP_DASHBOARD_SYNC', true );
250 }
251
252 /**
253 * Setup installer
254 */
255 Installer::factory();
256
257 /**
258 * Setup screen
259 */
260 Screen::factory();
261
262 /**
263 * Setup dashboard
264 */
265 require_once __DIR__ . '/includes/dashboard.php';
266 Dashboard\setup();
267
268 /**
269 * WP CLI Commands
270 */
271 if ( defined( 'WP_CLI' ) && WP_CLI ) {
272 WP_CLI::add_command( 'elasticpress', __NAMESPACE__ . '\Command' );
273 }
274
275 /**
276 * Setup upgrades
277 */
278 Upgrades::factory();
279
280 /**
281 * Handle upgrades. Certain version require a re-sync on upgrade.
282 * Deprecated in favor of `\ElasticPress\Upgrades::factory()`.
283 *
284 * @since 2.2
285 */
286 function handle_upgrades() {
287 _deprecated_function( __CLASS__, '3.5.2', '\ElasticPress\Upgrades::factory()' );
288 }
289
290 /**
291 * Load text domain and handle debugging
292 *
293 * @since 2.2
294 */
295 function setup_misc() {
296 load_plugin_textdomain( 'elasticpress', false, basename( __DIR__ ) . '/lang' ); // Load any available translations first.
297
298 if ( is_user_logged_in() && ! defined( 'WP_EP_DEBUG' ) ) {
299 require_once ABSPATH . 'wp-admin/includes/plugin.php';
300 define( 'WP_EP_DEBUG', is_plugin_active( 'debug-bar-elasticpress/debug-bar-elasticpress.php' ) );
301 }
302 }
303 add_action( 'plugins_loaded', __NAMESPACE__ . '\setup_misc' );
304
305 /**
306 * Set up role(s) with EP capability
307 */
308 function setup_roles() {
309 // add custom capabilities to admin role
310 $role = get_role( 'administrator' );
311
312 $role->add_cap( Utils\get_capability() );
313 }
314 register_activation_hook( __FILE__, __NAMESPACE__ . '\setup_roles' );
315
316 /**
317 * Fires after Elasticpress plugin is loaded
318 *
319 * @since 2.0
320 * @hook elasticpress_loaded
321 */
322 do_action( 'elasticpress_loaded' );
323