PluginProbe
ElasticPress / 5.3.5
ElasticPress v5.3.5
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
← All changes | includes/dashboard.php +75 -130 4.7.25.3.5 View file →
@@ -7,14 +7,15 @@
7 7 */
8 8
9 9 namespace ElasticPress\Dashboard;
10 10
11 -use ElasticPress\Utils;
11 +use ElasticPress\AdminNotices;
12 12 use ElasticPress\Elasticsearch;
13 13 use ElasticPress\Features;
14 -use ElasticPress\AdminNotices;
14 +use ElasticPress\Installer;
15 15 use ElasticPress\Screen;
16 16 use ElasticPress\Stats;
17 +use ElasticPress\Utils;
17 18
18 19 if ( ! defined( 'ABSPATH' ) ) {
19 20 exit; // Exit if accessed directly.
20 21 }
@@ -27,15 +28,13 @@
27 28 function setup() {
28 29 if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { // Must be network admin in multisite.
29 30 add_action( 'network_admin_menu', __NAMESPACE__ . '\action_admin_menu' );
30 31 add_action( 'admin_bar_menu', __NAMESPACE__ . '\action_network_admin_bar_menu', 50 );
31 - } else {
32 - add_action( 'admin_menu', __NAMESPACE__ . '\action_admin_menu' );
33 32 }
34 33
34 + add_action( 'admin_menu', __NAMESPACE__ . '\action_admin_menu' );
35 35 add_action( 'wp_ajax_ep_save_feature', __NAMESPACE__ . '\action_wp_ajax_ep_save_feature' );
36 36 add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\action_admin_enqueue_dashboard_scripts' );
37 - add_action( 'admin_init', __NAMESPACE__ . '\action_admin_init' );
38 37 add_action( 'admin_init', __NAMESPACE__ . '\maybe_clear_es_info_cache' );
39 38 add_action( 'admin_init', __NAMESPACE__ . '\maybe_skip_install' );
40 39 add_action( 'wp_ajax_ep_notice_dismiss', __NAMESPACE__ . '\action_wp_ajax_ep_notice_dismiss' );
41 40 add_action( 'admin_notices', __NAMESPACE__ . '\maybe_notice' );
@@ -44,10 +43,10 @@
44 43 add_filter( 'network_admin_plugin_action_links', __NAMESPACE__ . '\filter_plugin_action_links', 10, 2 );
45 44 add_action( 'ep_add_query_log', __NAMESPACE__ . '\log_version_query_error' );
46 45 add_filter( 'ep_analyzer_language', __NAMESPACE__ . '\use_language_in_setting', 10, 2 );
47 46 add_filter( 'wp_kses_allowed_html', __NAMESPACE__ . '\filter_allowed_html', 10, 2 );
48 - add_action( 'rest_api_init', __NAMESPACE__ . '\setup_endpoint' );
49 47 add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\block_assets' );
48 + add_action( 'init', __NAMESPACE__ . '\register_react_jsx_runtime', 1 );
50 49
51 50 if ( version_compare( get_bloginfo( 'version' ), '5.8', '>=' ) ) {
52 51 add_action( 'block_categories_all', __NAMESPACE__ . '\block_categories' );
53 52 } else {
@@ -71,8 +70,29 @@
71 70 }
72 71 }
73 72
74 73 /**
74 + * Register the `react-jsx-runtime` script handle on WordPress versions that
75 + * do not ship it. WordPress added it in 6.6; 10up-toolkit emits it as a
76 + * dependency of the React admin and Instant Results bundles, and without the
77 + * handle those scripts never print on WordPress 6.2.
78 + *
79 + * @since 5.3.4
80 + * @return void
81 + */
82 +function register_react_jsx_runtime() {
83 + if ( wp_script_is( 'react-jsx-runtime', 'registered' ) ) {
84 + return;
85 + }
86 +
87 + wp_register_script( 'react-jsx-runtime', false, [ 'react' ], '18', true );
88 + wp_add_inline_script(
89 + 'react-jsx-runtime',
90 + 'window.ReactJSXRuntime=window.ReactJSXRuntime||{Fragment:window.React.Fragment,jsx:function(type,config,maybeKey){var props=Object.assign({},config);if(maybeKey!==undefined){props.key=maybeKey;}return window.React.createElement(type,props);},jsxs:function(type,config,maybeKey){var props=Object.assign({},config);if(maybeKey!==undefined){props.key=maybeKey;}return window.React.createElement(type,props);}};'
91 + );
92 +}
93 +
94 +/**
75 95 * Add ep-html kses context
76 96 *
77 97 * @param array $allowedtags HTML tags
78 98 * @param string $context Context string
@@ -188,9 +208,9 @@
188 208 if ( ! is_admin() && ! is_network_admin() ) {
189 209 return;
190 210 }
191 211
192 - if ( empty( $_GET['ep-skip-install'] ) || empty( $_GET['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['nonce'] ), 'ep-skip-install' ) || ! in_array( Screen::factory()->get_current_screen(), [ 'install' ], true ) ) { // phpcs:ignore WordPress.Security.NonceVerification
212 + if ( empty( $_GET['ep-skip-install'] ) || empty( $_GET['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['nonce'] ), 'ep-skip-install' ) || ! in_array( Screen::factory()->get_current_screen(), [ 'install' ], true ) ) {
193 213 return;
194 214 }
195 215
196 216 if ( ! empty( $_GET['ep-skip-features'] ) ) {
@@ -222,9 +242,13 @@
222 242 if ( ! is_admin() && ! is_network_admin() ) {
223 243 return;
224 244 }
225 245
226 - if ( empty( $_GET['ep-retry'] ) && ! in_array( Screen::factory()->get_current_screen(), [ 'dashboard', 'settings', 'install' ], true ) ) { // phpcs:ignore WordPress.Security.NonceVerification
246 + $isset_retry = ! empty( $_GET['ep-retry'] ) &&
247 + ! empty( $_GET['ep_retry_nonce'] ) &&
248 + wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['ep_retry_nonce'] ) ), 'ep_retry_nonce' );
249 +
250 + if ( ! $isset_retry && ! in_array( Screen::factory()->get_current_screen(), [ 'dashboard', 'settings', 'install' ], true ) ) {
227 251 return;
228 252 }
229 253
230 254 if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
@@ -232,10 +256,10 @@
232 256 } else {
233 257 delete_transient( 'ep_es_info' );
234 258 }
235 259
236 - if ( ! empty( $_GET['ep-retry'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
237 - wp_safe_redirect( remove_query_arg( 'ep-retry' ) );
260 + if ( $isset_retry ) {
261 + wp_safe_redirect( remove_query_arg( [ 'ep-retry', 'ep_retry_nonce' ] ) );
238 262 exit();
239 263 }
240 264 }
241 265
@@ -295,17 +319,10 @@
295 319 * @param bool $force Force ES info hard lookup.
296 320 * @since 3.0
297 321 */
298 322 function maybe_notice( $force = false ) {
299 - // Admins only.
300 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
301 - if ( ! is_super_admin() || ! is_network_admin() ) {
302 - return false;
303 - }
304 - } else {
305 - if ( is_network_admin() || ! current_user_can( Utils\get_capability() ) ) {
306 - return false;
307 - }
323 + if ( ! current_user_can( Utils\get_capability() ) ) {
324 + return false;
308 325 }
309 326
310 327 /**
311 328 * Filter how long results of Elasticsearch version query are stored
@@ -330,13 +347,14 @@
330 347
331 348 $notices = AdminNotices::factory()->get_notices();
332 349
333 350 foreach ( $notices as $notice_key => $notice ) {
351 + $class = 'notice notice-' . $notice['type'];
352 + if ( $notice['dismiss'] ) {
353 + $class .= ' is-dismissible';
354 + }
334 355 ?>
335 - <div data-ep-notice="<?php echo esc_attr( $notice_key ); ?>" class="notice notice-<?php echo esc_attr( $notice['type'] ); ?> <?php
336 - if ( $notice['dismiss'] ) :
337 - ?>
338 - is-dismissible<?php endif; ?>">
356 + <div data-ep-notice="<?php echo esc_attr( $notice_key ); ?>" class="<?php echo esc_attr( $class ); ?>">
339 357 <p>
340 358 <?php echo wp_kses( $notice['html'], 'ep-html' ); ?>
341 359 </p>
342 360 </div>
@@ -452,9 +470,19 @@
452 470
453 471 wp_localize_script( 'ep_admin_sites_scripts', 'epsa', $data );
454 472 }
455 473
456 - if ( in_array( Screen::factory()->get_current_screen(), [ 'dashboard', 'settings', 'install', 'health', 'weighting', 'synonyms', 'sync', 'status-report' ], true ) ) {
474 + $general_ep_screens = [ 'dashboard', 'settings', 'install', 'health', 'weighting', 'synonyms', 'sync', 'status-report' ];
475 + /**
476 + * Filter the query logger object
477 + *
478 + * @since 5.3.3
479 + * @hook elasticpress_general_ep_screens
480 + * @param {array} $general_ep_screens The general ElasticPress screens.
481 + * @return {array} The filtered general ElasticPress screens.
482 + */
483 + $general_ep_screens = apply_filters( 'elasticpress_general_ep_screens', $general_ep_screens );
484 + if ( in_array( Screen::factory()->get_current_screen(), $general_ep_screens, true ) ) {
457 485 wp_enqueue_style(
458 486 'ep_admin_styles',
459 487 EP_URL . 'dist/css/dashboard-styles.css',
460 488 Utils\get_asset_info( 'dashboard-styles', 'dependencies' ),
@@ -470,20 +498,8 @@
470 498
471 499 wp_set_script_translations( 'ep_admin_script', 'elasticpress' );
472 500 }
473 501
474 - if ( in_array( Screen::factory()->get_current_screen(), [ 'weighting', 'install' ], true ) ) {
475 - wp_enqueue_script(
476 - 'ep_weighting_script',
477 - EP_URL . 'dist/js/weighting-script.js',
478 - Utils\get_asset_info( 'weighting-script', 'dependencies' ),
479 - Utils\get_asset_info( 'weighting-script', 'version' ),
480 - true
481 - );
482 -
483 - wp_set_script_translations( 'ep_weighting_script', 'elasticpress' );
484 - }
485 -
486 502 if ( in_array( Screen::factory()->get_current_screen(), [ 'dashboard', 'install' ], true ) ) {
487 503 wp_enqueue_script(
488 504 'ep_dashboard_scripts',
489 505 EP_URL . 'dist/js/dashboard-script.js',
@@ -493,11 +509,9 @@
493 509 );
494 510
495 511 wp_set_script_translations( 'ep_dashboard_scripts', 'elasticpress' );
496 512
497 - $sync_url = ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) ?
498 - network_admin_url( 'admin.php?page=elasticpress-sync&do_sync' ) :
499 - admin_url( 'admin.php?page=elasticpress-sync&do_sync' );
513 + $sync_url = Utils\get_sync_url( true );
500 514
501 515 $skip_url = ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) ?
502 516 network_admin_url( 'admin.php?page=elasticpress' ) :
503 517 admin_url( 'admin.php?page=elasticpress' );
@@ -516,20 +530,8 @@
516 530
517 531 wp_localize_script( 'ep_dashboard_scripts', 'epDash', $data );
518 532 }
519 533
520 - if ( in_array( Screen::factory()->get_current_screen(), [ 'settings' ], true ) ) {
521 - wp_enqueue_script(
522 - 'ep_settings_scripts',
523 - EP_URL . 'dist/js/settings-script.js',
524 - Utils\get_asset_info( 'settings-script', 'dependencies' ),
525 - Utils\get_asset_info( 'settings-script', 'version' ),
526 - true
527 - );
528 -
529 - wp_set_script_translations( 'ep_settings_scripts', 'elasticpress' );
530 - }
531 -
532 534 if ( in_array( Screen::factory()->get_current_screen(), [ 'health' ], true ) && ! empty( Utils\get_host() ) ) {
533 535 Stats::factory()->build_stats();
534 536
535 537 $data = Stats::factory()->get_localized();
@@ -563,73 +565,18 @@
563 565 array(
564 566 'nonce' => wp_create_nonce( 'ep_admin_nonce' ),
565 567 )
566 568 );
567 -}
568 569
569 -/**
570 - * Admin-init actions
571 - *
572 - * Sets up Settings API.
573 - *
574 - * @since 1.9
575 - * @return void
576 - */
577 -function action_admin_init() {
578 - $post = wp_unslash( $_POST );
579 -
580 - // Save options for multisite.
581 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK && isset( $post['ep_language'] ) ) {
582 - check_admin_referer( 'elasticpress-options' );
583 -
584 - $language = sanitize_text_field( $post['ep_language'] );
585 - Utils\update_option( 'ep_language', $language );
586 -
587 - if ( isset( $post['ep_host'] ) ) {
588 - $host = esc_url_raw( trim( $post['ep_host'] ) );
589 - Utils\update_option( 'ep_host', $host );
590 - }
591 -
592 - if ( isset( $post['ep_credentials'] ) ) {
593 - $credentials = ( isset( $post['ep_credentials'] ) ) ? Utils\sanitize_credentials( $post['ep_credentials'] ) : [
594 - 'username' => '',
595 - 'token' => '',
596 - ];
597 -
598 - Utils\update_option( 'ep_credentials', $credentials );
599 - }
600 -
601 - if ( isset( $post['ep_bulk_setting'] ) ) {
602 - Utils\update_option( 'ep_bulk_setting', intval( $post['ep_bulk_setting'] ) );
603 - }
604 - } else {
605 - register_setting( 'elasticpress', 'ep_host', 'esc_url_raw' );
606 - register_setting( 'elasticpress', 'ep_credentials', 'ep_sanitize_credentials' );
607 - register_setting( 'elasticpress', 'ep_language', 'sanitize_text_field' );
608 - register_setting(
609 - 'elasticpress',
610 - 'ep_bulk_setting',
611 - [
612 - 'type' => 'integer',
613 - 'sanitize_callback' => __NAMESPACE__ . '\sanitize_bulk_settings',
614 - ]
615 - );
616 - }
570 + wp_enqueue_style(
571 + 'ep_general_styles',
572 + EP_URL . 'dist/css/general-styles.css',
573 + Utils\get_asset_info( 'general-styles', 'dependencies' ),
574 + Utils\get_asset_info( 'general-styles', 'version' )
575 + );
617 576 }
618 577
619 578 /**
620 - * Sanitize bulk settings.
621 - *
622 - * @param int $bulk_settings Number of bulk content items
623 - * @return int
624 - */
625 -function sanitize_bulk_settings( $bulk_settings = 350 ) {
626 - $bulk_settings = absint( $bulk_settings );
627 -
628 - return ( 0 === $bulk_settings ) ? 350 : $bulk_settings;
629 -}
630 -
631 -/**
632 579 * Output current ElasticPress dashboard screen
633 580 *
634 581 * @since 3.0
635 582 */
@@ -645,8 +592,17 @@
645 592 * @since 1.9
646 593 * @return void
647 594 */
648 595 function action_admin_menu() {
596 + Installer::factory()->calculate_install_status();
597 + if ( true !== Installer::factory()->get_install_status() && ! Utils\is_top_level_admin_context() ) {
598 + return;
599 + }
600 +
601 + if ( ! Utils\is_site_indexable() && ! is_network_admin() ) {
602 + return;
603 + }
604 +
649 605 $capability = ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) ? Utils\get_network_capability() : Utils\get_capability();
650 606
651 607 add_menu_page(
652 608 'ElasticPress',
@@ -653,11 +609,15 @@
653 609 'ElasticPress',
654 610 $capability,
655 611 'elasticpress',
656 612 __NAMESPACE__ . '\resolve_screen',
657 - 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9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wYXRoIGQ9Ik0zNi41LDQuN0MxOS40LDQuNyw1LjYsMTguNiw1LjYsMzUuN2MwLDEwLDQuNywxOC45LDEyLjEsMjQuNWw0LjUtNC41YzAuMS0wLjEsMC4xLTAuMiwwLjItMC4zbDAuNy0wLjdsNi40LTYuNGMyLjEsMS4yLDQuNSwxLjksNy4xLDEuOWM4LDAsMTQuNS02LjUsMTQuNS0xNC41cy02LjUtMTQuNS0xNC41LTE0LjVTMjIsMjcuNiwyMiwzNS42YzAsMi44LDAuOCw1LjMsMi4xLDcuNWwtNi40LDYuNGMtMi45LTMuOS00LjYtOC43LTQuNi0xMy45YzAtMTIuOSwxMC41LTIzLjQsMjMuNC0yMy40czIzLjQsMTAuNSwyMy40LDIzLjRTNDkuNCw1OSwzNi41LDU5Yy0yLjEsMC00LjEtMC4zLTYtMC44bC0wLjYsMC42bC01LjIsNS40YzMuNiwxLjUsNy42LDIuMywxMS44LDIuM2MxNy4xLDAsMzAuOS0xMy45LDMwLjktMzAuOVM1My42LDQuNywzNi41LDQuN3oiIGZpbGw9IiNhN2FhYWQiLz48L3N2Zz4='
658 614 );
659 615
616 + if ( ! Utils\is_top_level_admin_context() ) {
617 + return;
618 + }
619 +
660 620 add_submenu_page(
661 621 'elasticpress',
662 622 esc_html__( 'ElasticPress Features', 'elasticpress' ),
663 623 esc_html__( 'Features', 'elasticpress' ),
@@ -712,9 +672,9 @@
712 672 * @since 4.7.0
713 673 * @param string $format Format of the return ('locales' or 'elasticsearch' )
714 674 * @return array
715 675 */
716 -function get_available_languages( string $format = 'elasticsearch' ) : array {
676 +function get_available_languages( string $format = 'elasticsearch' ): array {
717 677 /**
718 678 * Filter available languages in Elasticsearch.
719 679 *
720 680 * The returned array should follow the format `Elasticsearch analyzer name => [ WordPress language package names ]`.
@@ -952,23 +912,8 @@
952 912 return wp_send_json_success( $data );
953 913 }
954 914
955 915 /**
956 - * Registers the API endpoint
957 - */
958 -function setup_endpoint() {
959 - register_rest_route(
960 - 'elasticpress/v1',
961 - 'indexing_status',
962 - [
963 - 'methods' => 'GET',
964 - 'callback' => __NAMESPACE__ . '\handle_indexing_status',
965 - 'permission_callback' => '__return_true',
966 - ]
967 - );
968 -}
969 -
970 -/**
971 916 * Handle the fetch for indexing status
972 917 */
973 918 function handle_indexing_status() {
974 919 $indexing_status = \ElasticPress\Utils\get_indexing_status();
@@ -1009,9 +954,9 @@
1009 954 'title' => 'ElasticPress',
1010 955 ];
1011 956
1012 957 return $block_categories;
1013 -};
958 +}
1014 959
1015 960 /**
1016 961 * Enqueue shared block editor assets.
1017 962 *