wordpress add new user role code example
Example 1: wordpress make custom role
add_role(
'staff_member',
__( 'Staff Member' ),
array(
'read' => true,
'delete_posts' => true,
'delete_published_posts' => true,
'edit_posts' => true,
'publish_posts' => true,
'upload_files' => true,
'edit_pages' => true,
'edit_published_pages' => true,
'publish_pages' => true,
'delete_published_pages' => false,
)
);
Example 2: from user id to user role wordpress
$user_meta = get_userdata( $user_id );
$user_roles = $user_meta->roles;
Example 3: update user role wordpress
$wp_user_object = new WP_User($current_user->ID);
$wp_user_object->set_role('editor');