WC_Install::create_roles()public staticWC 1.0

Create roles and capabilities.

Method of the class: WC_Install{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = WC_Install::create_roles();

WC_Install::create_roles() code WC 9.3.3

public static function create_roles() {
	global $wp_roles;

	if ( ! class_exists( 'WP_Roles' ) ) {
		return;
	}

	if ( ! isset( $wp_roles ) ) {
		$wp_roles = new WP_Roles(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
	}

	// Dummy gettext calls to get strings in the catalog.
	/* translators: user role */
	_x( 'Customer', 'User role', 'woocommerce' );
	/* translators: user role */
	_x( 'Shop manager', 'User role', 'woocommerce' );

	// Customer role.
	add_role(
		'customer',
		'Customer',
		array(
			'read' => true,
		)
	);

	// Shop manager role.
	add_role(
		'shop_manager',
		'Shop manager',
		array(
			'level_9'                => true,
			'level_8'                => true,
			'level_7'                => true,
			'level_6'                => true,
			'level_5'                => true,
			'level_4'                => true,
			'level_3'                => true,
			'level_2'                => true,
			'level_1'                => true,
			'level_0'                => true,
			'read'                   => true,
			'read_private_pages'     => true,
			'read_private_posts'     => true,
			'edit_posts'             => true,
			'edit_pages'             => true,
			'edit_published_posts'   => true,
			'edit_published_pages'   => true,
			'edit_private_pages'     => true,
			'edit_private_posts'     => true,
			'edit_others_posts'      => true,
			'edit_others_pages'      => true,
			'publish_posts'          => true,
			'publish_pages'          => true,
			'delete_posts'           => true,
			'delete_pages'           => true,
			'delete_private_pages'   => true,
			'delete_private_posts'   => true,
			'delete_published_pages' => true,
			'delete_published_posts' => true,
			'delete_others_posts'    => true,
			'delete_others_pages'    => true,
			'manage_categories'      => true,
			'manage_links'           => true,
			'moderate_comments'      => true,
			'upload_files'           => true,
			'export'                 => true,
			'import'                 => true,
			'list_users'             => true,
			'edit_theme_options'     => true,
		)
	);

	$capabilities = self::get_core_capabilities();

	foreach ( $capabilities as $cap_group ) {
		foreach ( $cap_group as $cap ) {
			$wp_roles->add_cap( 'shop_manager', $cap );
			$wp_roles->add_cap( 'administrator', $cap );
		}
	}
}