Preserve filters when searching on events page#1674
Open
dd32 wants to merge 1 commit intoWordPress:productionfrom
Open
Preserve filters when searching on events page#1674dd32 wants to merge 1 commit intoWordPress:productionfrom
dd32 wants to merge 1 commit intoWordPress:productionfrom
Conversation
6 tasks
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
cf6bf2b to
dabb3c8
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the wporg-events-2023 theme so that submitting the Search block on event listing pages keeps users on the events page and preserves any active event filters by modifying the rendered search form output.
Changes:
- Hook into
render_block_core/searchto rewrite the search form action URL and inject active filter values as hidden inputs. - Add a new PHPUnit test suite and theme-specific test bootstrap for the events theme.
- Add integration tests covering hidden input injection and basic action URL rewriting behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| public_html/wp-content/themes/wporg-events-2023/inc/events-query.php | Adds a render filter for the Search block and implements hidden filter injection + form action rewriting. |
| public_html/wp-content/themes/wporg-events-2023/tests/test-events-query.php | Adds tests for the new search-form modification behavior. |
| public_html/wp-content/themes/wporg-events-2023/tests/bootstrap.php | Adds a theme test bootstrap to load the required theme code for tests. |
| phpunit.xml.dist | Registers a new PHPUnit testsuite for the events theme tests. |
| phpunit-bootstrap.php | Loads the events theme test bootstrap in the global PHPUnit bootstrap sequence. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+363
to
+370
| // Update the form action to stay on the events page rather than going to | ||
| // the default WordPress search results page. | ||
| $action_url = build_form_action_url(); | ||
| $block_content = preg_replace( | ||
| '/action="[^"]*"/', | ||
| 'action="' . esc_url( $action_url ) . '"', | ||
| $block_content | ||
| ); |
Comment on lines
+120
to
+123
| // The action should no longer be the original example.org URL. | ||
| $this->assertStringNotContainsString( 'action="http://example.org/"', $result ); | ||
| // It should contain an action attribute with a URL pointing to the post. | ||
| $this->assertMatchesRegularExpression( '/action="https?:\/\/[^"]+?"/', $result ); |
Comment on lines
+9
to
+62
| /** | ||
| * @group wporg-events-2023 | ||
| * | ||
| * @coversDefaultClass \WordPressdotorg\Events_2023 | ||
| */ | ||
| class Test_Events_Query extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * Sample search form HTML to use in tests. | ||
| * | ||
| * @var string | ||
| */ | ||
| private $sample_form = '<form role="search" method="get" action="http://example.org/" class="wp-block-search__button-outside"><label class="wp-block-search__label" for="wp-block-search__input-1">Search</label><div class="wp-block-search__inside-wrapper"><input class="wp-block-search__input" id="wp-block-search__input-1" placeholder="" value="" name="s" /><button aria-label="Search" class="wp-block-search__button" type="submit">Search</button></div></form>'; | ||
|
|
||
| /** | ||
| * Clean up query vars after each test. | ||
| */ | ||
| public function tear_down(): void { | ||
| global $wp_query; | ||
|
|
||
| set_query_var( 'event_type', '' ); | ||
| set_query_var( 'format_type', '' ); | ||
| set_query_var( 'month', '' ); | ||
| set_query_var( 'country', '' ); | ||
|
|
||
| parent::tear_down(); | ||
| } | ||
|
|
||
| /** | ||
| * Test that hidden inputs are injected when active filters exist. | ||
| * | ||
| * @covers ::inject_filters_into_search_form | ||
| */ | ||
| public function test_injects_hidden_inputs_for_active_filters(): void { | ||
| set_query_var( 'event_type', array( 'meetup' ) ); | ||
| set_query_var( 'country', array( 'US' ) ); | ||
|
|
||
| $result = \WordPressdotorg\Events_2023\inject_filters_into_search_form( $this->sample_form ); | ||
|
|
||
| $this->assertStringContainsString( | ||
| '<input type="hidden" name="event_type[]" value="meetup" />', | ||
| $result | ||
| ); | ||
| $this->assertStringContainsString( | ||
| '<input type="hidden" name="country[]" value="US" />', | ||
| $result | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that multiple values for a single filter produce multiple hidden inputs. | ||
| * | ||
| * @covers ::inject_filters_into_search_form | ||
| */ |
| require_once WP_PLUGIN_DIR . '/wordcamp-payments-network/tests/bootstrap.php'; | ||
| require_once SUT_WPMU_PLUGIN_DIR . '/tests/bootstrap.php'; | ||
| require_once WP_PLUGIN_DIR . '/wordcamp-coming-soon-page/tests/bootstrap.php'; | ||
| require_once SUT_WP_CONTENT_DIR . '/themes/wporg-events-2023/tests/bootstrap.php'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
render_block_core/searchfilter to change the search form action URL and inject active filter values as hidden inputsTest plan
Fixes #1167
Generated with Claude Code