Bird
0
0

Given this code snippet:

medium📝 Predict Output Q5 of 15
Wordpress - WordPress Settings and Configuration
Given this code snippet:
$role = get_role('editor');
if ($role->has_cap('delete_posts')) {
  echo 'Can delete posts';
} else {
  echo 'Cannot delete posts';
}

What will it output?
ACan delete posts
BCannot delete posts
CFatal error: Call to undefined method
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand get_role() and has_cap()

    get_role('editor') returns the editor role object; has_cap() checks if role has capability.
  2. Step 2: Check if editor role has 'delete_posts'

    By default, editors can delete posts, so has_cap returns true.
  3. Final Answer:

    Can delete posts -> Option A
  4. Quick Check:

    Editor role has delete_posts capability [OK]
Quick Trick: Editor role includes delete_posts capability by default [OK]
Common Mistakes:
  • Assuming editor cannot delete posts
  • Confusing method names
  • Thinking get_role returns user object

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes