| @@ -44,8 +44,9 @@ | ||
| 44 | 44 | add_action( 'ep_add_query_log', __NAMESPACE__ . '\log_version_query_error' ); |
| 45 | 45 | add_filter( 'ep_analyzer_language', __NAMESPACE__ . '\use_language_in_setting', 10, 2 ); |
| 46 | 46 | add_filter( 'wp_kses_allowed_html', __NAMESPACE__ . '\filter_allowed_html', 10, 2 ); |
| 47 | 47 | add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\block_assets' ); |
| 48 | + add_action( 'init', __NAMESPACE__ . '\register_react_jsx_runtime', 1 ); | |
| 48 | 49 | |
| 49 | 50 | if ( version_compare( get_bloginfo( 'version' ), '5.8', '>=' ) ) { |
| 50 | 51 | add_action( 'block_categories_all', __NAMESPACE__ . '\block_categories' ); |
| 51 | 52 | } else { |
| @@ -69,8 +70,29 @@ | ||
| 69 | 70 | } |
| 70 | 71 | } |
| 71 | 72 | |
| 72 | 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 | +/** | |
| 73 | 95 | * Add ep-html kses context |
| 74 | 96 | * |
| 75 | 97 | * @param array $allowedtags HTML tags |
| 76 | 98 | * @param string $context Context string |
| @@ -186,9 +208,9 @@ | ||
| 186 | 208 | if ( ! is_admin() && ! is_network_admin() ) { |
| 187 | 209 | return; |
| 188 | 210 | } |
| 189 | 211 | |
| 190 | - 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 ) ) { | |
| 191 | 213 | return; |
| 192 | 214 | } |
| 193 | 215 | |
| 194 | 216 | if ( ! empty( $_GET['ep-skip-features'] ) ) { |
| @@ -220,9 +242,13 @@ | ||
| 220 | 242 | if ( ! is_admin() && ! is_network_admin() ) { |
| 221 | 243 | return; |
| 222 | 244 | } |
| 223 | 245 | |
| 224 | - 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 ) ) { | |
| 225 | 251 | return; |
| 226 | 252 | } |
| 227 | 253 | |
| 228 | 254 | if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { |
| @@ -230,10 +256,10 @@ | ||
| 230 | 256 | } else { |
| 231 | 257 | delete_transient( 'ep_es_info' ); |
| 232 | 258 | } |
| 233 | 259 | |
| 234 | - if ( ! empty( $_GET['ep-retry'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 235 | - wp_safe_redirect( remove_query_arg( 'ep-retry' ) ); | |
| 260 | + if ( $isset_retry ) { | |
| 261 | + wp_safe_redirect( remove_query_arg( [ 'ep-retry', 'ep_retry_nonce' ] ) ); | |
| 236 | 262 | exit(); |
| 237 | 263 | } |
| 238 | 264 | } |
| 239 | 265 | |
| @@ -293,17 +319,10 @@ | ||
| 293 | 319 | * @param bool $force Force ES info hard lookup. |
| 294 | 320 | * @since 3.0 |
| 295 | 321 | */ |
| 296 | 322 | function maybe_notice( $force = false ) { |
| 297 | - // Admins only. | |
| 298 | - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { | |
| 299 | - if ( ! is_super_admin() || ! is_network_admin() ) { | |
| 300 | - return false; | |
| 301 | - } | |
| 302 | - } else { | |
| 303 | - if ( is_network_admin() || ! current_user_can( Utils\get_capability() ) ) { | |
| 304 | - return false; | |
| 305 | - } | |
| 323 | + if ( ! current_user_can( Utils\get_capability() ) ) { | |
| 324 | + return false; | |
| 306 | 325 | } |
| 307 | 326 | |
| 308 | 327 | /** |
| 309 | 328 | * Filter how long results of Elasticsearch version query are stored |
| @@ -328,13 +347,14 @@ | ||
| 328 | 347 | |
| 329 | 348 | $notices = AdminNotices::factory()->get_notices(); |
| 330 | 349 | |
| 331 | 350 | foreach ( $notices as $notice_key => $notice ) { |
| 351 | + $class = 'notice notice-' . $notice['type']; | |
| 352 | + if ( $notice['dismiss'] ) { | |
| 353 | + $class .= ' is-dismissible'; | |
| 354 | + } | |
| 332 | 355 | ?> |
| 333 | - <div data-ep-notice="<?php echo esc_attr( $notice_key ); ?>" class="notice notice-<?php echo esc_attr( $notice['type'] ); ?> <?php | |
| 334 | - if ( $notice['dismiss'] ) : | |
| 335 | - ?> | |
| 336 | - is-dismissible<?php endif; ?>"> | |
| 356 | + <div data-ep-notice="<?php echo esc_attr( $notice_key ); ?>" class="<?php echo esc_attr( $class ); ?>"> | |
| 337 | 357 | <p> |
| 338 | 358 | <?php echo wp_kses( $notice['html'], 'ep-html' ); ?> |
| 339 | 359 | </p> |
| 340 | 360 | </div> |
| @@ -450,9 +470,19 @@ | ||
| 450 | 470 | |
| 451 | 471 | wp_localize_script( 'ep_admin_sites_scripts', 'epsa', $data ); |
| 452 | 472 | } |
| 453 | 473 | |
| 454 | - 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 ) ) { | |
| 455 | 485 | wp_enqueue_style( |
| 456 | 486 | 'ep_admin_styles', |
| 457 | 487 | EP_URL . 'dist/css/dashboard-styles.css', |
| 458 | 488 | Utils\get_asset_info( 'dashboard-styles', 'dependencies' ), |
| @@ -468,46 +498,8 @@ | ||
| 468 | 498 | |
| 469 | 499 | wp_set_script_translations( 'ep_admin_script', 'elasticpress' ); |
| 470 | 500 | } |
| 471 | 501 | |
| 472 | - if ( 'weighting' === Screen::factory()->get_current_screen() ) { | |
| 473 | - | |
| 474 | - wp_enqueue_style( | |
| 475 | - 'ep_weighting_styles', | |
| 476 | - EP_URL . 'dist/css/weighting-script.css', | |
| 477 | - [ 'wp-components', 'wp-edit-post' ], | |
| 478 | - Utils\get_asset_info( 'weighting-script', 'version' ) | |
| 479 | - ); | |
| 480 | - | |
| 481 | - wp_enqueue_script( | |
| 482 | - 'ep_weighting_script', | |
| 483 | - EP_URL . 'dist/js/weighting-script.js', | |
| 484 | - Utils\get_asset_info( 'weighting-script', 'dependencies' ), | |
| 485 | - Utils\get_asset_info( 'weighting-script', 'version' ), | |
| 486 | - true | |
| 487 | - ); | |
| 488 | - | |
| 489 | - $weighting = Features::factory()->get_registered_feature( 'search' )->weighting; | |
| 490 | - | |
| 491 | - $api_url = esc_url_raw( rest_url( 'elasticpress/v1/weighting' ) ); | |
| 492 | - $meta_mode = $weighting->get_meta_mode(); | |
| 493 | - $weightable_fields = $weighting->get_weightable_fields(); | |
| 494 | - $weighting_configuration = $weighting->get_weighting_configuration_with_defaults(); | |
| 495 | - | |
| 496 | - wp_localize_script( | |
| 497 | - 'ep_weighting_script', | |
| 498 | - 'epWeighting', | |
| 499 | - array( | |
| 500 | - 'apiUrl' => $api_url, | |
| 501 | - 'metaMode' => $meta_mode, | |
| 502 | - 'weightableFields' => $weightable_fields, | |
| 503 | - 'weightingConfiguration' => $weighting_configuration, | |
| 504 | - ) | |
| 505 | - ); | |
| 506 | - | |
| 507 | - wp_set_script_translations( 'ep_weighting_script', 'elasticpress' ); | |
| 508 | - } | |
| 509 | - | |
| 510 | 502 | if ( in_array( Screen::factory()->get_current_screen(), [ 'dashboard', 'install' ], true ) ) { |
| 511 | 503 | wp_enqueue_script( |
| 512 | 504 | 'ep_dashboard_scripts', |
| 513 | 505 | EP_URL . 'dist/js/dashboard-script.js', |
| @@ -517,11 +509,9 @@ | ||
| 517 | 509 | ); |
| 518 | 510 | |
| 519 | 511 | wp_set_script_translations( 'ep_dashboard_scripts', 'elasticpress' ); |
| 520 | 512 | |
| 521 | - $sync_url = ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) ? | |
| 522 | - network_admin_url( 'admin.php?page=elasticpress-sync&do_sync' ) : | |
| 523 | - admin_url( 'admin.php?page=elasticpress-sync&do_sync' ); | |
| 513 | + $sync_url = Utils\get_sync_url( true ); | |
| 524 | 514 | |
| 525 | 515 | $skip_url = ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) ? |
| 526 | 516 | network_admin_url( 'admin.php?page=elasticpress' ) : |
| 527 | 517 | admin_url( 'admin.php?page=elasticpress' ); |
| @@ -575,8 +565,15 @@ | ||
| 575 | 565 | array( |
| 576 | 566 | 'nonce' => wp_create_nonce( 'ep_admin_nonce' ), |
| 577 | 567 | ) |
| 578 | 568 | ); |
| 569 | + | |
| 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 | + ); | |
| 579 | 576 | } |
| 580 | 577 | |
| 581 | 578 | /** |
| 582 | 579 | * Output current ElasticPress dashboard screen |
| @@ -612,9 +609,9 @@ | ||
| 612 | 609 | 'ElasticPress', |
| 613 | 610 | $capability, |
| 614 | 611 | 'elasticpress', |
| 615 | 612 | __NAMESPACE__ . '\resolve_screen', |
| 616 | - 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgNzMgNzEuMyIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgNzMgNzEuMzsiIHhtbDpzcGFjZT0icHJlc2VydmUiP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C4zbDAuNy0wLjdsNi40LTYuNGMyLjEsMS4yLDQuNSwxLjksNy4xLDEuOWM4LDAsMTQuNS02LjUsMTQuNS0xNC41cy02LjUtMTQuNS0xNC41LTE0LjVTMjIsMjcuNiwyMiwzNS42YzAsMi44LDAuOCw1LjMsMi4xLDcuNWwtNi40LDYuNGMtMi45LTMuOS00LjYtOC43LTQuNi0xMy45YzAtMTIuOSwxMC41LTIzLjQsMjMuNC0yMy40czIzLjQsMTAuNSwyMy40LDIzLjRTNDkuNCw1OSwzNi41LDU5Yy0yLjEsMC00LjEtMC4zLTYtMC44bC0wLjYsMC42bC01LjIsNS40YzMuNiwxLjUsNy42LDIuMywxMS44LDIuM2MxNy4xLDAsMzAuOS0xMy45LDMwLjktMzAuOVM1My42LDQuNywzNi41LDQuN3oiIGZpbGw9IiNhN2FhYWQiLz48L3N2Zz4=' | |
| 617 | 614 | ); |
| 618 | 615 | |
| 619 | 616 | if ( ! Utils\is_top_level_admin_context() ) { |
| 620 | 617 | return; |
| @@ -675,9 +672,9 @@ | ||
| 675 | 672 | * @since 4.7.0 |
| 676 | 673 | * @param string $format Format of the return ('locales' or 'elasticsearch' ) |
| 677 | 674 | * @return array |
| 678 | 675 | */ |
| 679 | -function get_available_languages( string $format = 'elasticsearch' ) : array { | |
| 676 | +function get_available_languages( string $format = 'elasticsearch' ): array { | |
| 680 | 677 | /** |
| 681 | 678 | * Filter available languages in Elasticsearch. |
| 682 | 679 | * |
| 683 | 680 | * The returned array should follow the format `Elasticsearch analyzer name => [ WordPress language package names ]`. |
| @@ -957,9 +954,9 @@ | ||
| 957 | 954 | 'title' => 'ElasticPress', |
| 958 | 955 | ]; |
| 959 | 956 | |
| 960 | 957 | return $block_categories; |
| 961 | -}; | |
| 958 | +} | |
| 962 | 959 | |
| 963 | 960 | /** |
| 964 | 961 | * Enqueue shared block editor assets. |
| 965 | 962 | * |