Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
Wordpress - WordPress Settings and Configuration
Identify the error in this code snippet:
add_role('custom_role', 'Custom Role', [
  'read' => true,
  'edit_posts' => true
]);

if (current_user_can('custom_role')) {
  echo 'Has custom role';
}
Acurrent_user_can() cannot check roles directly
Badd_role() requires a capability array with strings, not booleans
CRole name must be capitalized
DMissing semicolon after add_role()
Step-by-Step Solution
Solution:
  1. Step 1: Understand current_user_can() usage

    current_user_can() checks capabilities, not role names.
  2. Step 2: Identify misuse of current_user_can()

    Passing a role slug to current_user_can() will not work as expected.
  3. Final Answer:

    current_user_can() cannot check roles directly -> Option A
  4. Quick Check:

    Use capabilities, not roles, with current_user_can() [OK]
Quick Trick: Check capabilities, not roles, with current_user_can() [OK]
Common Mistakes:
  • Using role slug in current_user_can()
  • Wrong capability array format
  • Ignoring function purpose

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes