Repository navigation
Users: Defer loading capability/role data for authordata lookups - #13825
spacedmonkey wants to merge 6 commits into
Conversation
|
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:
|
Adds get_authordata(), a lighter-weight alternative to get_userdata() for contexts (author archives, the Loop's $authordata global, permalinks) that only need display data and never check capabilities or roles. Capability and role data is now loaded lazily on WP_User via a new short_init flag, only when has_cap(), get_role_caps(), or a role/capability mutator is called. See #58001. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
a47fb2b to
b74e3eb
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. |
westonruter
left a comment
There was a problem hiding this comment.
A couple drive-by suggestions to fix the PHPStan errors being raised.
| $id = (int) $post->ID; | ||
|
|
||
| $authordata = get_userdata( $post->post_author ); | ||
| $authordata = get_authordata( $post->post_author ); |
There was a problem hiding this comment.
| $authordata = get_authordata( $post->post_author ); | |
| $authordata = get_authordata( (int) $post->post_author ); |
| $author = ''; | ||
| if ( str_contains( $permalink, '%author%' ) ) { | ||
| $authordata = get_userdata( $post->post_author ); | ||
| $authordata = get_authordata( $post->post_author ); |
There was a problem hiding this comment.
| $authordata = get_authordata( $post->post_author ); | |
| $authordata = get_authordata( (int) $post->post_author ); |
Also casts post_author to int when calling get_authordata(), per review feedback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… data. Extracts the capability loading logic shared by `for_site()` and the lazy loader into a public `load_capabilities()` method, allowing callers to force capability data to load immediately or to reload it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
get_authordata(), a lighter-weight alternative toget_userdata()for contexts that only need display data (name, avatar, bio, etc.) and never check capabilities or roles, such as author archives and the$authordataglobal set up in the Loop.$caps,$roles,$allcaps) on the returnedWP_Useris no longer queried eagerly; it's loaded transparently on first access viahas_cap(),get_role_caps(), or any of the role/capability mutator methods, via a new privateWP_User::$short_initflag.get_the_modified_author(),get_the_author_meta(),get_author_posts_url(),wp_list_authors(),WP_Query,WP::handle_404(), andget_permalink()to useget_authordata()instead ofget_userdata()where only display data is needed.Trac ticket: https://core.trac.wordpress.org/ticket/58001
Test plan
phpunittests intests/phpunit/tests/user/getAuthordata.php,tests/phpunit/tests/query/generatePostdata.php, andtests/phpunit/tests/query/setupPostdata.phppass$authordataglobal🤖 Generated with Claude Code