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

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