On this page
WP_User::level_reduction( int $max, string $item ): int
Chooses the maximum level the user has.
Description
Will compare the level from the $item parameter against the $max parameter. If the item is incorrect, then just the $max parameter value will be returned.
Used to get the max level based on the capabilities the user has. This is also based on roles, so if the user is assigned the Administrator role then the capability ‘level_10’ will exist and the user will get that value.
Parameters
$maxint Required-
Max level of user.
$itemstring Required-
Level capability name.
Return
int Max Level.
Source
File: wp-includes/class-wp-user.php. View all references
public function level_reduction( $max, $item ) {
if ( preg_match( '/^level_(10|[0-9])$/i', $item, $matches ) ) {
$level = (int) $matches[1];
return max( $max, $level );
} else {
return $max;
}
}
Changelog
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_user/level_reduction