Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to remove our custom search html block with the code search block #113

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions mu-plugins/blocks/global-header-footer/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
add_action( 'wp_head', __NAMESPACE__ . '\preload_google_fonts' );
add_filter( 'style_loader_src', __NAMESPACE__ . '\update_google_fonts_url', 10, 2 );
add_filter( 'render_block_core/navigation-link', __NAMESPACE__ . '\swap_submenu_arrow_svg' );
add_filter( 'render_block_core/search', __NAMESPACE__ . '\swap_header_search_action', 10, 2 );

/**
* Register block types
Expand Down Expand Up @@ -1044,3 +1045,22 @@ function( $val, $key ) use ( &$urls ) {
function swap_submenu_arrow_svg( $block_content ) {
return str_replace( block_core_navigation_link_render_submenu_icon(), "<svg width='10' height='7' viewBox='0 0 10 7' stroke-width='1.2' xmlns='http://www.w3.org/2000/svg'><path d='M0.416667 1.33325L5 5.49992L9.58331 1.33325'></path></svg>", $block_content );
}

/**
* Replace the search action url with the custom attribute.
*
* @param string $block_content The block content about to be appended.
* @param array $block The block details.
* @return string The filtered block content.
*/
function swap_header_search_action( $block_content, $block ) {
if ( ! empty( $block['attrs']['formAction'] ) ) {
$block_content = str_replace(
'action="' . esc_url( home_url('/') ) . '"',
'action="' . esc_url( $block['attrs']['formAction'] ) . '"',
$block_content
);
}

return $block_content;
}
38 changes: 1 addition & 37 deletions mu-plugins/blocks/global-header-footer/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,43 +98,7 @@
<!-- wp:navigation-link {"label":"<?php echo esc_html_x( 'Search', 'button label', 'wporg' ); ?>","url":"#","kind":"custom","isTopLevelLink":false} -->
<!-- wp:html -->
<li>
<!--
This markup is forked from the `wp:search` block. The only reason we're not using that, is because the
`action` URL can't be customized.

@link https://github.com/WordPress/gutenberg/issues/35572

The only things that changed were:

1) The instance ID was changed to `99`, to make it likely to be unique.
2) Internationalizing the labels. See https://github.com/WordPress/gutenberg/issues/36061 and
related issues for a possible future alternative.

If that issue is ever resolved, we should be able to replace this with the Search block, without having
to change any CSS.
-->
<form
role="search"
method="get"
action="https://wordpress.org/search/do-search.php"
class="wp-block-search__button-outside wp-block-search__text-button global-header__search-form wp-block-search"
>
<label for="wp-block-search__input-99" class="wp-block-search__label">
<?php echo esc_html_x( 'Search', 'button label', 'wporg' ); ?>
</label>
<div class="wp-block-search__inside-wrapper">
<input
type="search"
id="wp-block-search__input-99"
class="wp-block-search__input"
name="s"
value=""
placeholder="<?php echo esc_attr_x( 'Search WP.org...', 'input field placeholder', 'wporg' ); ?>"
required=""
>
<button type="submit" class="wp-block-search__button" aria-label="<?php echo esc_attr_x( 'Submit search', 'button label', 'wporg' ); ?>"></button>
</div>
</form>
<!-- wp:search <?php echo wp_json_encode( [ 'label' => _x( 'Search', 'button label', 'wporg' ), 'placeholder' => _x( 'Search WP.org...', 'input field placeholder', 'wporg' ), 'buttonText' => _x( 'Submit search', 'button label', 'wporg' ), 'formAction' => 'https://wordpress.org/search/do-search.php' ] ); ?> /-->
</li>
<!-- /wp:html -->
<!-- /wp:navigation-link -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

& .has-child:hover .wp-block-navigation-item__content,
& .has-child:focus-within .wp-block-navigation-item__content,
&:not(.has-background) .wp-block-navigation__submenu-container .global-header__search-form {
&:not(.has-background) .wp-block-navigation__submenu-container .wp-block-search {
background-color: var(--wp--preset--color--darker-grey);
}

Expand All @@ -86,7 +86,7 @@
}
}

& .global-header__search-form {
& .wp-block-search {
margin-top: 0;

@media (--tablet) {
Expand Down