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

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