Skip to content

Commit

Permalink
Search: Fix attribute defaults (#23777)
Browse files Browse the repository at this point in the history
* 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 `<!-- wp:search /-->` 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
  • Loading branch information
noisysocks authored and youknowriad committed Jul 13, 2020
1 parent d2b0cff commit 4d9b3dc
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/block-library/src/search/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<!--
// wp:search /-->`. 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 = '';
Expand Down

0 comments on commit 4d9b3dc

Please sign in to comment.