Skip to content

Author filter - #23

Open
mattheu wants to merge 1 commit into
mainfrom
author-filter
Open

Author filter#23
mattheu wants to merge 1 commit into
mainfrom
author-filter

Conversation

@mattheu

@mattheu mattheu commented May 22, 2025

Copy link
Copy Markdown
Member

First pass at an author filter.

Open WordPress Playground Preview

@mattheu
mattheu marked this pull request as ready for review October 21, 2025 10:39

Copy link
Copy Markdown
Collaborator

Triage pass over the open PRs. @mattheu this one is a genuinely wanted feature and it's the closest of the open PRs to mergeable — it rebases onto current main with no source conflicts, once the four build/author/* files are dropped (build/ was removed from the repository in c1aabe0; built files are generated at release time and gitignored now).

There is one real bug and a batch of drift to fix up before it lands.

Blocking

$tax_query is no longer initialised. The diff removes $tax_query = []; from pre_get_posts_transpose_query_vars():

 	$prefix = $query->is_main_query() ? 'query-' : "query-{$query_id}-";
-	$tax_query = [];
 	$valid_keys = [
+		'author' => '',

but the function still ends with if ( ! empty( $tax_query ) ) {. On any query where no taxonomy filter is active — i.e. most page loads — that's an undefined variable warning, on every single query the plugin touches. It looks like an accidental deletion while adding the 'author' key; restoring the line is all that's needed.

Drift since May 2025

The block's wiring no longer matches the conventions in main:

  • "apiVersion": 2 → should be 3. Both shipped blocks are on 3, and v2 is what triggers the editor warning reported in API v2 and some strange issues with WP 6.9 RC #33.
  • "viewScriptModule": "query-filter-author-view-script-module" — that handle doesn't exist and nothing registers it. The taxonomy block owns the shared module (file:./view.js), and the post-type block reuses it by handle. This should do the same: "viewScriptModule": "query-filter-taxonomy-view-script-module". As written, actions.navigate never binds and the select does nothing on the front end.
  • "style": "query-filter-view" — that shared style handle was removed in 0ae2777. Should be "style": "file:./index.css", as the other two blocks now do.

Smaller notes

  • if ( $block->context['query']['inherit'] ) appears twice in render.php without an empty() guard — that's exactly the warning from Warning: Undefined array key “inherit” in /wp-content/plugins/query-filter/build/taxonomy/render.php on line 10 #15, which main has since fixed in the other blocks. Please use empty() and flip the branches.
  • $_GET[ $query_var ] goes into selected() unsanitised. Not an output path, but WPCS will flag it, and the author value reaching $query->set( 'author', ... ) should be integer-validated — WP's author query var accepts comma lists and negative IDs for exclusion, so a hand-crafted ?query-1-author=-5 currently changes the query's meaning rather than filtering to one author.
  • Feature parity: the taxonomy block has grown displayType (select/radio/checkbox), layoutDirection, includeTerms/excludeTerms, and maxVisibleTerms/showAllLabel. The author block is select-only. Not a blocker for a first pass, but worth deciding whether it ships without them or whether the display-type controls get factored out for reuse first — the latter is probably the better shape given the post-type block will want the same treatment.
  • Leftover scaffolding comments to remove: // Changed from query-post_type (×2).
  • Typo in the block description: "wihin" → "within".
  • No test coverage. There's a Playwright + Playground harness in tests/ now, so an e2e that asserts filtering by author narrows the loop would be the natural thing to add.

Happy to do the rebase and the mechanical fixes (build files, apiVersion, module/style handles, empty() guards, $tax_query) if you'd rather not pick it back up — just say and I'll push to the branch. The display-type parity question is a design call I'd leave to you.


Generated by Claude Code

Copy link
Copy Markdown
Collaborator

Rebased this branch onto current main (565aa7a) and force-pushed — 2afdd050527236. Your commit and authorship are preserved; the only change to the diff is that the four build/author/* files are dropped, since build/ is generated at release time now. @mattheu you'll need to reset your local copy of the branch.

The PR is mergeable_state: clean and 0 commits behind main, so it's reviewable as-is. The blocking $tax_query issue and the block.json drift from my earlier comment are all still outstanding — I've re-verified the $tax_query one against the rebased branch and it stands: inc/namespace.php line 168 still reads if ( ! empty( $tax_query ) ) with no initialisation above it.

Note that #15 and #50 have both been fixed on main since — worth reading how src/post-type/render.php now handles the inherit context key, since the author block wants the same treatment:

// The query block's own attribute default carries `inherit`, but markup that
// predates it (or a nested/synced pattern) reaches render with the key absent.
$inherit = ! empty( $block->context['query']['inherit'] );

Generated by Claude Code

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

Playwright — PHP 8.2 / WP 6.8

failed  2 failed
passed  25 passed

Details

stats  27 tests across 7 suites
duration  6 minutes, 49 seconds
commit  0527236

Failed tests

chromium › editor.spec.js › Editor previews › the taxonomy select preview renders without a React warning
chromium › editor.spec.js › Editor previews › the checkbox preview renders without a React warning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants