Title: WP_Roles::init_roles
Published: November 20, 2017
Last modified: February 24, 2026

---

# WP_Roles::init_roles()

## In this article

 * [Source](https://developer.wordpress.org/reference/classes/wp_roles/init_roles/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/classes/wp_roles/init_roles/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/classes/wp_roles/init_roles/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_roles/init_roles/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_roles/init_roles/?output_format=md#wp--skip-link--target)

Initializes all of the available roles.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_roles/init_roles/?output_format=md#source)󠁿

    ```php
    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 );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-roles.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-roles.php#L306)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-roles.php#L306-L326)

## 󠀁[Hooks](https://developer.wordpress.org/reference/classes/wp_roles/init_roles/?output_format=md#hooks)󠁿

 [do_action( ‘wp_roles_init’, WP_Roles $wp_roles )](https://developer.wordpress.org/reference/hooks/wp_roles_init/)

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

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_roles/init_roles/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Role::__construct()](https://developer.wordpress.org/reference/classes/wp_role/__construct/)`wp-includes/class-wp-role.php` |

Constructor – Set up object properties.

  | 
| [do_action()](https://developer.wordpress.org/reference/functions/do_action/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to an action hook.

  |

| Used by | Description | 
| [WP_Roles::for_site()](https://developer.wordpress.org/reference/classes/wp_roles/for_site/)`wp-includes/class-wp-roles.php` |

Sets the site to operate on. Defaults to the current site.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_roles/init_roles/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.9.0](https://developer.wordpress.org/reference/since/4.9.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_roles%2Finit_roles%2F)
before being able to contribute a note or feedback.