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

274 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.5.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 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.5.2' );
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\WooCommerce\WooCommerce()
121 );
122
123 Features::factory()->register_feature(
124 new Feature\Facets\Facets()
125 );
126
127 Features::factory()->register_feature(
128 new Feature\RelatedPosts\RelatedPosts()
129 );
130
131 Features::factory()->register_feature(
132 new Feature\SearchOrdering\SearchOrdering()
133 );
134
135 Features::factory()->register_feature(
136 new Feature\ProtectedContent\ProtectedContent()
137 );
138
139 Features::factory()->register_feature(
140 new Feature\Documents\Documents()
141 );
142
143 Features::factory()->register_feature(
144 new Feature\Comments\Comments()
145 );
146
147 /**
148 * Filter whether the Users feature should be registered or not.
149 *
150 * The Users feature is going to be migrated to ElasticPress Labs. If EP Labs is enabled
151 * and in a more recent version, it will change this to false and load its own version
152 * of the Users feature.
153 *
154 * @hook ep_user_register_feature
155 * @since 4.5.0
156 * @param {bool} $version Version
157 * @return {bool} New version
158 */
159 if ( apply_filters( 'ep_user_register_feature', true ) ) {
160 Features::factory()->register_feature(
161 new Feature\Users\Users()
162 );
163 }
164
165 Features::factory()->register_feature(
166 new Feature\Terms\Terms()
167 );
168
169 /**
170 * Register search algorithms
171 */
172 SearchAlgorithms::factory()->register( new SearchAlgorithm\DefaultAlgorithm() );
173 SearchAlgorithms::factory()->register( new SearchAlgorithm\Version_350() );
174 SearchAlgorithms::factory()->register( new SearchAlgorithm\Version_400() );
175
176 /**
177 * Filter the query logger object
178 *
179 * @since 4.4.0
180 * @hook ep_query_logger
181 * @param {QueryLogger} $query_logger Default query logger
182 * @return {QueryLogger} New query logger
183 */
184 $query_logger = apply_filters( 'ep_query_logger', new \ElasticPress\QueryLogger() );
185 if ( method_exists( $query_logger, 'setup' ) ) {
186 $query_logger->setup();
187 }
188 }
189 add_action( 'plugins_loaded', __NAMESPACE__ . '\register_indexable_posts' );
190
191 /**
192 * Set the availability of dashboard sync functionality. Defaults to true (enabled).
193 *
194 * Sync can be disabled by defining EP_DASHBOARD_SYNC as false in wp-config.php.
195 * NOTE: Must be defined BEFORE `require_once(ABSPATH . 'wp-settings.php');` in wp-config.php.
196 *
197 * @since 2.3
198 */
199 if ( ! defined( 'EP_DASHBOARD_SYNC' ) ) {
200 define( 'EP_DASHBOARD_SYNC', true );
201 }
202
203 /**
204 * Setup installer
205 */
206 Installer::factory();
207
208 /**
209 * Setup screen
210 */
211 Screen::factory();
212
213 /**
214 * Setup dashboard
215 */
216 require_once __DIR__ . '/includes/dashboard.php';
217 Dashboard\setup();
218
219 /**
220 * WP CLI Commands
221 */
222 if ( defined( 'WP_CLI' ) && WP_CLI ) {
223 WP_CLI::add_command( 'elasticpress', __NAMESPACE__ . '\Command' );
224 }
225
226 /**
227 * Setup upgrades
228 */
229 Upgrades::factory();
230
231 /**
232 * Handle upgrades. Certain version require a re-sync on upgrade.
233 * Deprecated in favor of `\ElasticPress\Upgrades::factory()`.
234 *
235 * @since 2.2
236 */
237 function handle_upgrades() {
238 _deprecated_function( __CLASS__, '3.5.2', '\ElasticPress\Upgrades::factory()' );
239 }
240
241 /**
242 * Load text domain and handle debugging
243 *
244 * @since 2.2
245 */
246 function setup_misc() {
247 load_plugin_textdomain( 'elasticpress', false, basename( __DIR__ ) . '/lang' ); // Load any available translations first.
248
249 if ( is_user_logged_in() && ! defined( 'WP_EP_DEBUG' ) ) {
250 require_once ABSPATH . 'wp-admin/includes/plugin.php';
251 define( 'WP_EP_DEBUG', is_plugin_active( 'debug-bar-elasticpress/debug-bar-elasticpress.php' ) );
252 }
253 }
254 add_action( 'plugins_loaded', __NAMESPACE__ . '\setup_misc' );
255
256 /**
257 * Set up role(s) with EP capability
258 */
259 function setup_roles() {
260 // add custom capabilities to admin role
261 $role = get_role( 'administrator' );
262
263 $role->add_cap( Utils\get_capability() );
264 }
265 register_activation_hook( __FILE__, __NAMESPACE__ . '\setup_roles' );
266
267 /**
268 * Fires after Elasticpress plugin is loaded
269 *
270 * @since 2.0
271 * @hook elasticpress_loaded
272 */
273 do_action( 'elasticpress_loaded' );
274