In WordPress, users have different roles with specific capabilities. Consider a user assigned the 'Editor' role. What will happen if this user attempts to delete a published post?
Think about the default capabilities assigned to the Editor role in WordPress.
Editors have the capability to delete published posts, but only those they authored. They cannot delete published posts by other authors.
You want to add a custom capability named 'edit_special_content' to the 'Author' role in WordPress. Which code snippet does this correctly?
Remember that role slugs are lowercase and you need to get the role object before adding capabilities.
The correct way is to get the role object with the exact slug 'author' (lowercase), then call add_cap on it.
Consider the following code snippet executed in a WordPress environment where the current user has the 'Contributor' role:
if (current_user_can('publish_posts')) {
echo 'Can publish';
} else {
echo 'Cannot publish';
}What will be printed?
if (current_user_can('publish_posts')) { echo 'Can publish'; } else { echo 'Cannot publish'; }
Check the default capabilities of the 'Contributor' role regarding publishing posts.
Contributors can write and edit their own posts but cannot publish them. So current_user_can('publish_posts') returns false.
Given this code snippet, why does the custom capability not get added to the 'custom_role'?
add_action('init', function() {
$role = get_role('custom_role');
$role->add_cap('manage_special_feature');
});add_action('init', function() { $role = get_role('custom_role'); $role->add_cap('manage_special_feature'); });
Check if the role 'custom_role' exists before adding capabilities.
If 'custom_role' is not registered before this code runs, get_role returns null. Calling add_cap on null causes failure.
Explain the process WordPress uses internally to decide if a user has permission to perform an action like 'edit_post'. Which of the following best describes this process?
Think about how roles and capabilities relate to permissions.
WordPress uses capabilities assigned to roles or users to determine permissions. Actions require specific capabilities, and current_user_can() checks these.