Refactor WP_User capabilities handling:#10309
Refactor WP_User capabilities handling:#10309jonnynews wants to merge 1 commit intoWordPress:trunkfrom
WP_User capabilities handling:#10309Conversation
- Made `caps`, `roles`, and `allcaps` public to improve access flexibility. - Introduced `$short_init` to enable optimized initialization for use cases where full capability and role loading is unnecessary. - Removed redundant lazy-loading logic for these properties, simplifying the class structure. - Adjusted documentation for affected properties and methods.
|
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 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. |
| * @param bool $short_init Optional. Whether to skip initializing capabilities and roles. | ||
| */ | ||
| public function init( $data, $site_id = 0 ) { | ||
| public function init( $data, $site_id = 0, $short_init = false ) { |
There was a problem hiding this comment.
This $short_init arg isn't used anywhere?
There was a problem hiding this comment.
I mean, init() isn't being called anywhere with this argument provided, right?
| */ | ||
| private static $back_compat_keys; | ||
|
|
||
| /** |
|
@jonnynews There's a couple of failing unit tests, are you able to look at those. To ensure the caps are available when using /**
* Ensure get_object_vars includes allcaps.
*
* @ticket 58001
*
* @dataProvider data_single_site_roles_to_check
*/
public function test_get_object_vars_includes_roles( $role ) {
$user_id = self::$users[ $role ]->ID;
$user = new WP_User( $user_id );
$vars = get_object_vars( $user );
$primitive_caps = $this->getPrimitiveCapsAndRoles();
$expected = array();
foreach ( $primitive_caps as $cap => $roles ) {
if ( in_array( $role, $roles, true ) ) {
$expected[] = $cap;
}
}
$this->assertArrayHasKey( 'allcaps', $vars, 'WP_User object vars should include allcaps key.' );
$actual = $vars['allcaps'];
$actual = array_keys( $actual );
// Remove special cases.
$special_cases = array(
// Role names.
'administrator',
'editor',
'author',
'subscriber',
'contributor',
// Granted via `user_has_cap`.
'resume_plugins',
'resume_themes',
'view_site_health_checks',
// Other capabilities.
'manage_links',
'unfiltered_upload',
);
$actual = array_diff( $actual, $special_cases );
$expected = array_diff( $expected, $special_cases );
$this->assertSameSets( $expected, $actual, "User with the {$role} role should have the correct primitive capabilities in allcaps." );
} |
caps,roles, andallcapspublic to improve access flexibility.$short_initto enable optimized initialization for use cases where full capability and role loading is unnecessary.Trac ticket: https://core.trac.wordpress.org/ticket/58001
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.