Bird
0
0

You want to run a function log_user only once when WordPress initializes, but only if another plugin has already hooked check_license to init. How can you do this?

hard📝 Application Q8 of 15
Wordpress - WordPress Hooks System
You want to run a function log_user only once when WordPress initializes, but only if another plugin has already hooked check_license to init. How can you do this?
AHook <code>log_user</code> to <code>init</code> with priority 1 to run before <code>check_license</code>.
BCall <code>log_user</code> directly before <code>add_action</code> for <code>check_license</code>.
CUse <code>remove_action('init', 'check_license');</code> then add <code>log_user</code>.
DUse <code>add_action('init', 'log_user', 20);</code> and check if <code>check_license</code> is hooked with <code>has_action('init', 'check_license')</code> inside <code>log_user</code>.
Step-by-Step Solution
Solution:
  1. Step 1: Understand hook priorities and checking hooks

    Using priority 20 ensures log_user runs after default priority 10 where check_license is likely hooked.
  2. Step 2: Use has_action inside log_user

    Inside log_user, check if check_license is hooked before running code.
  3. Final Answer:

    Use add_action with priority 20 and check has_action inside log_user. -> Option D
  4. Quick Check:

    Use priority and has_action to conditionally run [OK]
Quick Trick: Use has_action to check hooks and priority to order execution [OK]
Common Mistakes:
  • Calling functions directly instead of hooking
  • Removing needed hooks mistakenly
  • Using wrong priority to run before dependent hooks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes