WP_Roles::remove_role() WordPress Method

The WP_Roles::remove_role() method is used to remove a role from a WordPress installation. This method takes a single parameter, which is the name of the role to be removed.

WP_Roles::remove_role( string $role ) #

Remove role by name.


Parameters

$role

(string)(Required)Role name.


Top ↑

Source

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

	public function remove_role( $role ) {
		if ( ! isset( $this->role_objects[ $role ] ) ) {
			return;
		}

		unset( $this->role_objects[ $role ] );
		unset( $this->role_names[ $role ] );
		unset( $this->roles[ $role ] );

		if ( $this->use_db ) {
			update_option( $this->role_key, $this->roles );
		}

		if ( get_option( 'default_role' ) == $role ) {
			update_option( 'default_role', 'subscriber' );
		}
	}


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.