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/classes/Feature/Search/Weighting.php +66 -6 5.0.25.3.5 View file →
@@ -36,8 +36,9 @@
36 36 add_action( 'admin_menu', [ $this, 'add_weighting_submenu_page' ], 15 );
37 37 add_filter( 'ep_formatted_args', [ $this, 'do_weighting' ], 20, 2 ); // After date decay, etc are injected
38 38 add_filter( 'ep_query_weighting_fields', [ $this, 'adjust_weight_for_cross_fields' ], 10, 5 );
39 39 add_action( 'rest_api_init', [ $this, 'register_rest_routes' ] );
40 + add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
40 41 }
41 42
42 43 /**
43 44 * Returns a grouping of all the fields that support weighting for the post type
@@ -350,11 +351,12 @@
350 351 *
351 352 * @param string $post_type Current post type we're rendering
352 353 * @param array $field Current field to render
353 354 * @param array $current_values Current stored weighting values
355 + *
354 356 * @deprecated
355 357 */
356 - public function render_settings_section( $post_type, $field, $current_values ) {
358 + public function render_settings_section( $post_type, $field, $current_values ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
357 359 _doing_it_wrong(
358 360 __METHOD__,
359 361 esc_html( 'Weighting sections display are now handled via React components.' ),
360 362 'ElasticPress 5.0.0'
@@ -380,9 +382,9 @@
380 382 *
381 383 * @param string $redirect_url Redirect URL.
382 384 * @deprecated
383 385 */
384 - protected function redirect( $redirect_url ) {
386 + protected function redirect( $redirect_url ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed,Generic.CodeAnalysis.UnusedFunctionParameter.Found
385 387 _doing_it_wrong(
386 388 __METHOD__,
387 389 esc_html( 'Weighting settings are now updated using the REST API, and do not redirect server-side.' ),
388 390 'ElasticPress 5.0.0'
@@ -396,9 +398,9 @@
396 398 * @return void
397 399 * @since 3.4.1
398 400 * @deprecated
399 401 */
400 - public function save_weighting_configuration( $settings ) {
402 + public function save_weighting_configuration( $settings ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed,Generic.CodeAnalysis.UnusedFunctionParameter.Found
401 403 _doing_it_wrong(
402 404 __METHOD__,
403 405 esc_html( 'Weighting sections display are now handled via React components.' ),
404 406 'ElasticPress 5.0.0'
@@ -417,9 +419,9 @@
417 419 'weighting',
418 420 [
419 421 'callback' => [ $this, 'update_weighting' ],
420 422 'methods' => 'POST',
421 - 'permission_callback' => function() {
423 + 'permission_callback' => function () {
422 424 return current_user_can( Utils\get_capability() );
423 425 },
424 426 ]
425 427 );
@@ -425,8 +427,66 @@
425 427 );
426 428 }
427 429
428 430 /**
431 + * Enqueue scripts and styles.
432 + *
433 + * @since 5.3.3
434 + * @return void
435 + */
436 + public function admin_enqueue_scripts() {
437 + if ( 'weighting' !== \ElasticPress\Screen::factory()->get_current_screen() ) {
438 + return;
439 + }
440 +
441 + wp_enqueue_style(
442 + 'ep_weighting_styles',
443 + EP_URL . 'dist/css/weighting-script.css',
444 + [ 'wp-components', 'wp-edit-post' ],
445 + Utils\get_asset_info( 'weighting-script', 'version' )
446 + );
447 +
448 + wp_enqueue_script(
449 + 'ep_weighting_script',
450 + EP_URL . 'dist/js/weighting-script.js',
451 + Utils\get_asset_info( 'weighting-script', 'dependencies' ),
452 + Utils\get_asset_info( 'weighting-script', 'version' ),
453 + true
454 + );
455 +
456 + $api_url = esc_url_raw( rest_url( 'elasticpress/v1/weighting' ) );
457 + $meta_mode = $this->get_meta_mode();
458 + $weightable_fields = $this->get_weightable_fields();
459 + $weighting_configuration = $this->get_weighting_configuration_with_defaults();
460 +
461 + /**
462 + * Filter weighting dashboard options.
463 + *
464 + * @hook ep_weighting_options
465 + * @param {array} $data Weighting dashboard options
466 + * @return {array} New options array
467 + * @since 5.1.0
468 + */
469 + $data = apply_filters(
470 + 'ep_weighting_options',
471 + [
472 + 'apiUrl' => $api_url,
473 + 'metaMode' => $meta_mode,
474 + 'weightableFields' => $weightable_fields,
475 + 'weightingConfiguration' => $weighting_configuration,
476 + ]
477 + );
478 +
479 + wp_localize_script(
480 + 'ep_weighting_script',
481 + 'epWeighting',
482 + $data
483 + );
484 +
485 + wp_set_script_translations( 'ep_weighting_script', 'elasticpress' );
486 + }
487 +
488 + /**
429 489 * Handles processing the new weighting values and saving them.
430 490 *
431 491 * @param \WP_Rest_Request $request REST API request.
432 492 * @return array
@@ -512,9 +572,9 @@
512 572 }
513 573 }
514 574
515 575 foreach ( $fieldset['fields'] as $key => $field ) {
516 - if ( isset( $weights[ $field ] ) && false !== $weights[ $field ]['enabled'] ) {
576 + if ( isset( $weights[ $field ]['enabled'] ) && false !== $weights[ $field ]['enabled'] ) {
517 577 $weight = (int) $weights[ $field ]['weight'];
518 578
519 579 if ( 0 !== $weight ) {
520 580 if ( 'author_name' === $field ) {
@@ -614,9 +674,9 @@
614 674 $fields = array_diff_key( $weights, $ignore_keys );
615 675
616 676 $found_enabled = false;
617 677 foreach ( $fields as $field ) {
618 - if ( filter_var( $field['enabled'], FILTER_VALIDATE_BOOLEAN ) ) {
678 + if ( isset( $field['enabled'] ) && filter_var( $field['enabled'], FILTER_VALIDATE_BOOLEAN ) ) {
619 679 $found_enabled = true;
620 680 break;
621 681 }
622 682 }