W3cubDocs

/WordPress

WP_Roles::init_roles()

Initializes all of the available roles.

Source

public function init_roles() {
	if ( empty( $this->roles ) ) {
		return;
	}

	$this->role_objects = array();
	$this->role_names   = array();
	foreach ( array_keys( $this->roles ) as $role ) {
		$this->role_objects[ $role ] = new WP_Role( $role, $this->roles[ $role ]['capabilities'] );
		$this->role_names[ $role ]   = $this->roles[ $role ]['name'];
	}

	/**
	 * Fires after the roles have been initialized, allowing plugins to add their own roles.
	 *
	 * @since 4.7.0
	 *
	 * @param WP_Roles $wp_roles A reference to the WP_Roles object.
	 */
	do_action( 'wp_roles_init', $this );
}

Hooks

do_action( ‘wp_roles_init’, WP_Roles $wp_roles )

Fires after the roles have been initialized, allowing plugins to add their own roles.

Changelog

Version Description
4.9.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_roles/init_roles