Make WordPress Core


Ignore:
Timestamp:
07/18/2023 07:17:23 AM (2 years ago)
Author:
isabel_brison
Message:

Editor: update npm packages with second round of bug fixes for 6.3 RC1.

Includes miscellaneous bug fixes for 6.3 RC1.

Props ramonopoly, mukesh27.
Fixes #58804.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks/search.php

    r56065 r56255  
    99 * Dynamically renders the `core/search` block.
    1010 *
    11  * @param array $attributes The block attributes.
     11 * @param array    $attributes The block attributes.
     12 * @param string   $content    The saved content.
     13 * @param WP_Block $block      The parsed block.
    1214 *
    1315 * @return string The search block markup.
    1416 */
    15 function render_block_core_search( $attributes ) {
     17function render_block_core_search( $attributes, $content, $block ) {
    1618    // Older versions of the Search block defaulted the label and buttonText
    1719    // attributes to `__( 'Search' )` meaning that many posts contain `<!--
     
    7173        $input->set_attribute( 'value', get_search_query() );
    7274        $input->set_attribute( 'placeholder', $attributes['placeholder'] );
    73         if ( 'button-only' === $button_position && 'expand-searchfield' === $button_behavior ) {
     75
     76        $is_expandable_searchfield = 'button-only' === $button_position && 'expand-searchfield' === $button_behavior;
     77        if ( $is_expandable_searchfield ) {
    7478            $input->set_attribute( 'aria-hidden', 'true' );
    7579            $input->set_attribute( 'tabindex', '-1' );
    76             wp_enqueue_script( 'wp-block--search-view', plugins_url( 'search/view.min.js', __FILE__ ) );
     80        }
     81
     82        // If the script already exists, there is no point in removing it from viewScript.
     83        $view_js_file = 'wp-block-search-view';
     84        if ( ! wp_script_is( $view_js_file ) ) {
     85            $script_handles = $block->block_type->view_script_handles;
     86
     87            // If the script is not needed, and it is still in the `view_script_handles`, remove it.
     88            if ( ! $is_expandable_searchfield && in_array( $view_js_file, $script_handles, true ) ) {
     89                $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
     90            }
     91            // If the script is needed, but it was previously removed, add it again.
     92            if ( $is_expandable_searchfield && ! in_array( $view_js_file, $script_handles, true ) ) {
     93                $block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) );
     94            }
    7795        }
    7896    }
Note: See TracChangeset for help on using the changeset viewer.