Bird
0
0

What will the following code output if the current user has the 'edit_posts' capability?

medium📝 component behavior Q13 of 15
Wordpress - WordPress Settings and Configuration
What will the following code output if the current user has the 'edit_posts' capability?
if (current_user_can('edit_posts')) {
  echo 'Can edit posts';
} else {
  echo 'Cannot edit posts';
}
ACannot edit posts
BSyntax error
CNo output
DCan edit posts
Step-by-Step Solution
Solution:
  1. Step 1: Understand current_user_can() behavior

    This function checks if the current user has a specific capability.
  2. Step 2: Analyze the condition

    If the user has 'edit_posts', the code echoes 'Can edit posts'.
  3. Final Answer:

    Can edit posts -> Option D
  4. Quick Check:

    Has capability = prints confirmation [OK]
Quick Trick: current_user_can() returns true if user has capability [OK]
Common Mistakes:
  • Assuming it returns false always
  • Confusing capability names
  • Expecting syntax errors from correct code

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes