Role/Capability: Add is_user_member_of_blog filter#11597
Role/Capability: Add is_user_member_of_blog filter#11597dd32 wants to merge 2 commits intoWordPress:trunkfrom
is_user_member_of_blog filter#11597Conversation
Allows plugins to dynamically grant or revoke a user's membership of a blog
without having to spoof `{$prefix}capabilities` user meta. The filter only
runs when both the user and blog have resolved to valid records on a
multisite install, so short-circuited calls (logged-out requests, unknown
users, archived/spammed/deleted sites) continue to return without invoking
the filter.
Props dd32.
Fixes #65096.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @user@claude.home.dd32.au. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. |
| * @since 7.1.0 | ||
| * | ||
| * @param bool $is_member Whether the user is a member of the blog. | ||
| * @param int $user_id The user ID being checked. |
There was a problem hiding this comment.
Do we needs to add Defaults to the current user. for better doc for param?
There was a problem hiding this comment.
Is that something we do on other filter doc blocks? When something is passed explicitly to a filter, it feels like defaults shouldn't be mentioned..
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. |
Trac ticket: https://core.trac.wordpress.org/ticket/65096
Summary
is_user_member_of_blogfilter so plugins can dynamically grant or revoke a user's membership of a blog without having to spoof{$prefix}capabilitiesuser meta (as WordPress.org currently does for its REST API user endpoints).@sinceis7.1.0, matchingsrc/wp-includes/version.phpontrunk.Test plan
phpunit --group ms-required tests/phpunit/tests/user/multisite.php— includes two new cases: one that forces the return value totruefor a non-member and asserts the filter's arguments, and one that asserts the filter is not called for the short-circuited paths.Disclosure: this PR (code, tests, and description) was generated by Claude Code on behalf of @dd32 and pushed before he had a chance to review. Treat it as an unreviewed AI draft — please scrutinise accordingly.