From 5110778ce0a8536815bd6cf806e3640ef3e4ba2b Mon Sep 17 00:00:00 2001 From: Akeda Bagus Date: Mon, 28 Sep 2026 20:21:28 +0700 Subject: [PATCH 1/2] Pattern directory theme: keep the curation and sort filters when searching Searching from `?curation=all` dropped the filter and only returned curated patterns. The search form now carries the current curation and sorting, like it already did for the category. The header search is left alone. See #709. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../inc/block-config.php | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/public_html/wp-content/themes/wporg-pattern-directory-2024/inc/block-config.php b/public_html/wp-content/themes/wporg-pattern-directory-2024/inc/block-config.php index 913e5a10..9f8877cb 100644 --- a/public_html/wp-content/themes/wporg-pattern-directory-2024/inc/block-config.php +++ b/public_html/wp-content/themes/wporg-pattern-directory-2024/inc/block-config.php @@ -18,7 +18,7 @@ add_filter( 'wporg_query_filter_options_sort', __NAMESPACE__ . '\get_sort_options' ); add_action( 'wporg_query_filter_in_form', __NAMESPACE__ . '\inject_other_filters' ); add_filter( 'wporg_favorite_button_settings', __NAMESPACE__ . '\get_favorite_settings', 10, 2 ); -add_filter( 'render_block_core/search', __NAMESPACE__ . '\inject_category_search_block' ); +add_filter( 'render_block_core/search', __NAMESPACE__ . '\inject_filters_search_block' ); add_filter( 'wporg_block_navigation_menus', __NAMESPACE__ . '\add_site_navigation_menus' ); add_filter( 'render_block_core/query-title', __NAMESPACE__ . '\update_archive_title', 10, 2 ); add_filter( 'render_block_core/site-title', __NAMESPACE__ . '\update_site_title' ); @@ -315,24 +315,37 @@ function get_favorite_settings( $settings, $post_id ) { } /** - * Inject the current category into the search form. + * Inject the current category, curation, and sorting into the pattern search form. + * + * Without these, a search resets the filters to their defaults, e.g. searching + * from `?curation=all` only returns curated patterns. * * @param string $block_content Search block markup. * * @return string */ -function inject_category_search_block( $block_content ) { +function inject_filters_search_block( $block_content ) { global $wp_query; - $category_inputs = ''; - $query_var = 'pattern-categories'; - if ( isset( $wp_query->query[ $query_var ] ) ) { + + // Leave other search forms alone, such as the global header search, which submits to wordpress.org/search. + $form = new \WP_HTML_Tag_Processor( $block_content ); + if ( ! $form->next_tag( 'form' ) || untrailingslashit( (string) $form->get_attribute( 'action' ) ) !== untrailingslashit( home_url() ) ) { + return $block_content; + } + + $filter_inputs = ''; + $query_vars = array( 'pattern-categories', 'curation', 'order', 'orderby' ); + foreach ( $query_vars as $query_var ) { + if ( ! isset( $wp_query->query[ $query_var ] ) ) { + continue; + } $values = (array) $wp_query->query[ $query_var ]; foreach ( $values as $value ) { - $category_inputs .= sprintf( '', esc_attr( $query_var ), esc_attr( $value ) ); + $filter_inputs .= sprintf( '', esc_attr( $query_var ), esc_attr( $value ) ); } } - return str_replace( '', $category_inputs . '', $block_content ); + return str_replace( '', $filter_inputs . '', $block_content ); } /** From 484d34030b6a5c47ee959f021b46322e2136b8e7 Mon Sep 17 00:00:00 2001 From: Akeda Bagus Date: Mon, 28 Sep 2026 21:07:14 +0700 Subject: [PATCH 2/2] Skip search blocks with a custom form action The global header search was only skipped because the mu-plugin swaps its action before this filter runs. Checking `formAction` keeps it skipped whatever order the filters run in. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../inc/block-config.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/public_html/wp-content/themes/wporg-pattern-directory-2024/inc/block-config.php b/public_html/wp-content/themes/wporg-pattern-directory-2024/inc/block-config.php index 9f8877cb..bfab4828 100644 --- a/public_html/wp-content/themes/wporg-pattern-directory-2024/inc/block-config.php +++ b/public_html/wp-content/themes/wporg-pattern-directory-2024/inc/block-config.php @@ -18,7 +18,7 @@ add_filter( 'wporg_query_filter_options_sort', __NAMESPACE__ . '\get_sort_options' ); add_action( 'wporg_query_filter_in_form', __NAMESPACE__ . '\inject_other_filters' ); add_filter( 'wporg_favorite_button_settings', __NAMESPACE__ . '\get_favorite_settings', 10, 2 ); -add_filter( 'render_block_core/search', __NAMESPACE__ . '\inject_filters_search_block' ); +add_filter( 'render_block_core/search', __NAMESPACE__ . '\inject_filters_search_block', 10, 2 ); add_filter( 'wporg_block_navigation_menus', __NAMESPACE__ . '\add_site_navigation_menus' ); add_filter( 'render_block_core/query-title', __NAMESPACE__ . '\update_archive_title', 10, 2 ); add_filter( 'render_block_core/site-title', __NAMESPACE__ . '\update_site_title' ); @@ -321,13 +321,19 @@ function get_favorite_settings( $settings, $post_id ) { * from `?curation=all` only returns curated patterns. * * @param string $block_content Search block markup. + * @param array $block Parsed search block. * * @return string */ -function inject_filters_search_block( $block_content ) { +function inject_filters_search_block( $block_content, $block ) { global $wp_query; - // Leave other search forms alone, such as the global header search, which submits to wordpress.org/search. + // Leave other search forms alone. The global header search sets `formAction` to submit to wordpress.org/search, + // and checking the attribute doesn't depend on the mu-plugin swapping the action before this filter runs. + if ( ! empty( $block['attrs']['formAction'] ) ) { + return $block_content; + } + $form = new \WP_HTML_Tag_Processor( $block_content ); if ( ! $form->next_tag( 'form' ) || untrailingslashit( (string) $form->get_attribute( 'action' ) ) !== untrailingslashit( home_url() ) ) { return $block_content;