Bird
0
0

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

medium📝 Predict Output Q4 of 15
Wordpress - WordPress Settings and Configuration
What will the following code output if the current user has the 'publish_posts' capability?
if (current_user_can('publish_posts')) {
  echo 'Can publish';
} else {
  echo 'Cannot publish';
}
ACannot publish
BCan publish
CError: function not found
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand current_user_can() behavior

    This function returns true if the user has the specified capability.
  2. Step 2: Analyze the if condition

    If the user has 'publish_posts', the code echoes 'Can publish'.
  3. Final Answer:

    Can publish -> Option B
  4. Quick Check:

    User has capability = output 'Can publish' [OK]
Quick Trick: If user has capability, current_user_can() returns true [OK]
Common Mistakes:
  • Assuming function returns capability name
  • Confusing echo output
  • Thinking function causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes