WP_User::level_reduction() WordPress Method

The WP_User::level_reduction() function is used to lower a user's privileges by one level.

WP_User::level_reduction( int $max, string $item ) #

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.


Top ↑

Parameters

$max

(int)(Required)Max level of user.

$item

(string)(Required)Level capability name.


Top ↑

Return

(int) Max Level.


Top ↑

Source

File: wp-includes/class-wp-user.php

	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;
		}
	}

Top ↑

Changelog

Changelog
VersionDescription
2.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.