Skip to content

Users: Allow is_multi_author() to check specific post types and statuses. - #16418

Draft
ankit-addweb wants to merge 1 commit into
WordPress:trunkfrom
ankit-addweb:fix/24284-is-multi-author-args
Draft

ankit-addweb wants to merge 1 commit into
WordPress:trunkfrom
ankit-addweb:fix/24284-is-multi-author-args

Conversation

@ankit-addweb

@ankit-addweb ankit-addweb commented Dec 3, 2026 •

Copy link
Copy Markdown

Allows is_multi_author() to check post types and post statuses other than the hardcoded post / publish, so sites built on pages or custom post types no longer always get false.

Trac ticket: https://core.trac.wordpress.org/ticket/24284

What changed

  • is_multi_author() now takes an optional $args array:
    • post_type (string|string[]), default 'post'.
    • post_status (string|string[]), default 'publish'.
  • Calls with no arguments behave exactly as before, including using the existing is_multi_author transient.
  • The query uses $wpdb->prepare() with IN (...) placeholders. Values go through sanitize_key(), and empty values fall back to the defaults. (The 2013 patch built raw SQL from its arguments.)
  • Custom arguments get their own transient, keyed on a hash of the sorted values. The keys are tracked in an is_multi_author_keys transient, and __clear_multi_author_cache() (hooked to transition_post_status) now clears them too.
  • The is_multi_author filter receives the parsed arguments as a second parameter. Existing one-argument callbacks are unaffected.

Why optional args, not a new default

Making the default query cover all public post types would change the result for existing sites. For example, a site whose pages have a second author would flip from false to true. An opt-in argument avoids that.

Testing

New tests in tests/phpunit/tests/user/isMultiAuthor.php:

  • post type argument (single and array)
  • post status argument
  • custom-argument cache cleared on status transition
  • empty arguments fall back to the defaults
npm run test:php -- --filter Tests_User_IsMultiAuthor
npm run test:php -- --group user,author

Results: Tests_User_IsMultiAuthor 9 tests, 21 assertions, all passing. user and author groups: 1471 tests, 4768 assertions, no failures (single site), and 1533 tests, 5236 assertions, no failures (multisite). The 5 warnings are existing PHPUnit 9 deprecation notices in unrelated tests.

Notes for reviewers

  • The is_multi_author_keys tracking transient is only there so the custom caches can be cleared. If that's too much, the alternative is to skip caching for non-default arguments. Happy to change.
  • The full test suite has not been run.
  • @since 7.3.0 assumes this lands in 7.3.

…ses.

Adds an optional `$args` array with `post_type` and `post_status` to `is_multi_author()`. Defaults remain `post` and `publish`, so existing behavior and the existing transient are unchanged. Custom arguments use a prepared query and their own transients, which are cleared on `transition_post_status`. The `is_multi_author` filter now receives the parsed arguments as a second parameter.

Props sainathpoojary, alex-ye.
Fixes #24284.
@ankit-addweb
ankit-addweb force-pushed the fix/24284-is-multi-author-args branch from 8cbe882 to 9d4512a Compare December 3, 2026 06:01
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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