Skip to content

Query: make author query reset callback self-cleaning#176

Draft
dknauss wants to merge 1 commit intohumanmade:developfrom
dknauss:codex/hm-author-query-callback-cleanup
Draft

Query: make author query reset callback self-cleaning#176
dknauss wants to merge 1 commit intohumanmade:developfrom
dknauss:codex/hm-author-query-callback-cleanup

Conversation

@dknauss
Copy link
Copy Markdown

@dknauss dknauss commented Mar 13, 2026

Authorship temporarily hooks into WordPress query processing when someone loads author-filtered content. Temporary query hooks should clean themselves up once they have done their work. In this case, the temporary hook was not removed after use over repeated queries. As a result, extra copies of that hook could pile up in memory during the request.

This is a stability and correctness fix to make the temporary hook clean itself up immediately after it handles the query it was created for. This patch keeps the existing author-query rewrite behavior intact, but fixes the callback lifecycle so repeated author-filtered queries do not leave behind extra posts_pre_query callbacks that can leak into later requests.

Summary

Make the temporary posts_pre_query callback used by author-query rewriting remove itself after it has handled the intended query.

What changed

  • scope the restore callback to the specific WP_Query instance that registered it
  • remove the callback before restoring query vars
  • keep the original query-var restoration behavior intact
  • add a regression test that confirms repeated author-filtered queries do not
    accumulate posts_pre_query callbacks

Why

The current implementation clears stored values after the query runs, but the temporary callback itself remains registered. Repeated author-filtered queries can therefore leave behind extra callbacks on posts_pre_query.

This patch keeps the callback lifecycle aligned with the query it was created for and prevents callback accumulation across later queries.

Scope

This PR is intentionally narrow and limited to query callback lifecycle cleanup.

Included:

  • inc/namespace.php
  • tests/phpunit/test-wp-query.php

Not included:

  • broader author-query behavior changes
  • post-type semantics changes
  • multisite or deletion behavior work

Verification

  • vendor/bin/phpunit --filter TestWPQuery
  • php -l inc/namespace.php
  • php -l tests/phpunit/test-wp-query.php

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.

1 participant