function gutenberg_render_block_core_search in Gutenberg 8
Same name and namespace in other branches
- 8.2 vendor/gutenberg/block-library/blocks/search.php \gutenberg_render_block_core_search()
Dynamically renders the `core/search` block.
Parameters
array $attributes The block attributes.:
Return value
string The search block markup.
1 string reference to 'gutenberg_render_block_core_search'
- gutenberg_register_block_core_search in vendor/
gutenberg/ block-library/ blocks/ search.php - Registers the `core/search` block on the server.
File
- vendor/
gutenberg/ block-library/ blocks/ search.php, line 15
Code
function gutenberg_render_block_core_search($attributes) {
static $instance_id = 0;
$input_id = 'wp-block-search__input-' . ++$instance_id;
$label_markup = '';
$button_markup = '';
if (!empty($attributes['label'])) {
$label_markup = sprintf('<label for="%s" class="wp-block-search__label">%s</label>', $input_id, $attributes['label']);
}
$input_markup = sprintf('<input type="search" id="%s" class="wp-block-search__input" name="s" value="%s" placeholder="%s" />', $input_id, esc_attr(get_search_query()), esc_attr($attributes['placeholder']));
if (!empty($attributes['buttonText'])) {
$button_markup = sprintf('<button type="submit" class="wp-block-search__button">%s</button>', $attributes['buttonText']);
}
$class = 'wp-block-search';
if (isset($attributes['className'])) {
$class .= ' ' . $attributes['className'];
}
if (isset($attributes['align'])) {
$class .= ' align' . $attributes['align'];
}
return sprintf('<form class="%s" role="search" method="get" action="%s">%s</form>', $class, esc_url(home_url('/')), $label_markup . $input_markup . $button_markup);
}