Changeset 56255 for trunk/src/wp-includes/blocks/search.php
- Timestamp:
- 07/18/2023 07:17:23 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/search.php
r56065 r56255 9 9 * Dynamically renders the `core/search` block. 10 10 * 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. 12 14 * 13 15 * @return string The search block markup. 14 16 */ 15 function render_block_core_search( $attributes ) {17 function render_block_core_search( $attributes, $content, $block ) { 16 18 // Older versions of the Search block defaulted the label and buttonText 17 19 // attributes to `__( 'Search' )` meaning that many posts contain `<!-- … … 71 73 $input->set_attribute( 'value', get_search_query() ); 72 74 $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 ) { 74 78 $input->set_attribute( 'aria-hidden', 'true' ); 75 79 $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 } 77 95 } 78 96 }
Note: See TracChangeset
for help on using the changeset viewer.