Complete the code to get the current user's role in WordPress.
$user = wp_get_current_user(); $role = $user->[1][0];
The roles property of the user object contains an array of roles assigned to the user. Accessing the first element gives the primary role.
Complete the code to check if the current user has the 'editor' role.
if (in_array('[1]', wp_get_current_user()->roles)) { // User is an editor }
The in_array function checks if 'editor' is in the current user's roles array.
Fix the error in the code to add a custom capability 'edit_reports' to the 'editor' role.
$role = get_role('[1]'); $role->add_cap('edit_reports');
The get_role function requires the exact role slug. To add a capability to editors, use 'editor'.
Fill both blanks to remove the 'delete_posts' capability from the 'author' role.
$role = get_role('[1]'); $role->[2]('delete_posts');
add_cap instead of remove_capTo remove a capability, get the role object and call remove_cap with the capability name.
Fill all three blanks to create a new role 'manager' with 'read', 'edit_posts', and 'publish_posts' capabilities.
add_role('[1]', 'Manager', array( '[2]' => true, '[3]' => true, 'publish_posts' => true ));
The add_role function creates a new role with a slug, display name, and capabilities array. Here, 'manager' is the slug, and the capabilities include 'read' and 'edit_posts'.