Repository navigation
Users: Allow is_multi_author() to check specific post types and statuses. - #16418
ankit-addweb wants to merge 2 commits into
Conversation
…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.
8cbe882 to
9d4512a
Compare
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Allows
is_multi_author()to check post types and post statuses other than the hardcodedpost/publish, so sites built on pages or custom post types no longer always getfalse.Trac ticket: https://core.trac.wordpress.org/ticket/24284
What changed
is_multi_author()now takes an optional$argsarray:post_type(string|string[]), default'post'.post_status(string|string[]), default'publish'.is_multi_authortransient.$wpdb->prepare()withIN (...)placeholders. Values go throughsanitize_key(), and empty values fall back to the defaults. (The 2013 patch built raw SQL from its arguments.)is_multi_author_keystransient, and__clear_multi_author_cache()(hooked totransition_post_status) now clears them too.is_multi_authorfilter 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
falsetotrue. An opt-in argument avoids that.Testing
New tests in
tests/phpunit/tests/user/isMultiAuthor.php:Results:
Tests_User_IsMultiAuthor9 tests, 21 assertions, all passing.userandauthorgroups: 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
is_multi_author_keystracking 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.@since 7.3.0assumes this lands in 7.3.