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