From 4d9b3dc5cb1c2abd39e417d1b430752c2eec0036 Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Wed, 8 Jul 2020 18:46:26 +1000 Subject: [PATCH] Search: Fix attribute defaults (#23777) * Search: Fix attribute defaults Prior to d26842b, the Search block's label and buttonText attributes defaulted to `__( 'Search' )`. This meant that adding a Search block to a post or page resulted in `` being inserted into the HTML. In d26842b, the defaults were removed so that Search could use a block.json file. The default values were instead implemented using a default block variation. This, however, meant that Search blocks added prior to d26842b would render with a blank label and button. This fix is to default label and buttonText to `__( 'Search' )` in the render_callback. Care must be taken here to permit these attributes to be '' in which case the label and/or button are hidden. * Try to trick GitHub into re-running tests --- packages/block-library/src/search/index.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/block-library/src/search/index.php b/packages/block-library/src/search/index.php index 5cc9a7dfa9577..55f0cadf0fe07 100644 --- a/packages/block-library/src/search/index.php +++ b/packages/block-library/src/search/index.php @@ -15,6 +15,18 @@ function render_block_core_search( $attributes ) { static $instance_id = 0; + // Older versions of the Search block defaulted the label and buttonText + // attributes to `__( 'Search' )` meaning that many posts contain ``. Support these by defaulting an undefined label and + // buttonText to `__( 'Search' )`. + $attributes = wp_parse_args( + $attributes, + array( + 'label' => __( 'Search' ), + 'buttonText' => __( 'Search' ), + ) + ); + $input_id = 'wp-block-search__input-' . ++$instance_id; $label_markup = ''; $button_markup = '';