Challenge - 5 Problems
Hook Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output order of hooks with different priorities?
Consider these WordPress hooks added to the same action 'init' with different priorities. What will be the order of output when the 'init' action runs?
Wordpress
<?php add_action('init', function() { echo 'First'; }, 10); add_action('init', function() { echo 'Second'; }, 5); add_action('init', function() { echo 'Third'; }, 15); do_action('init'); ?>
Attempts:
2 left
💡 Hint
Lower priority numbers run earlier in WordPress hooks.
✗ Incorrect
Hooks with lower priority numbers run before those with higher numbers. Here, priority 5 runs first, then 10, then 15.
❓ state_output
intermediate2:00remaining
How many arguments does the hooked function receive?
Given this code, how many arguments will the function 'my_callback' receive when the 'save_post' action runs?
Wordpress
<?php
function my_callback($post_id, $post, $update) {
// ...
}
add_action('save_post', 'my_callback', 10, 3);
do_action('save_post', 123, (object) ['ID' => 123], true);
?>Attempts:
2 left
💡 Hint
The fourth parameter in add_action controls how many arguments are passed.
✗ Incorrect
The 'add_action' call specifies 3 arguments to pass, so the function receives all three.
📝 Syntax
advanced2:00remaining
Which option causes a syntax error in hook registration?
Which of these add_action calls will cause a syntax error?
Attempts:
2 left
💡 Hint
Check for missing commas between arguments.
✗ Incorrect
Option C is missing a comma between 'my_function' and 10, causing a syntax error.
🔧 Debug
advanced2:00remaining
Why does the hooked function not receive all arguments?
Given this code, why does 'my_callback' only receive 1 argument instead of 3?
Wordpress
<?php
function my_callback($a, $b, $c) {
var_dump(func_get_args());
}
add_action('some_hook', 'my_callback', 10, 1);
do_action('some_hook', 1, 2, 3);
?>Attempts:
2 left
💡 Hint
Check the fourth parameter of add_action.
✗ Incorrect
The fourth parameter of add_action controls how many arguments are passed to the callback. Here it is 1, so only one argument is passed.
🧠 Conceptual
expert3:00remaining
What happens if two hooks have the same priority and modify the same data?
If two functions hooked to the same filter have the same priority and both modify the input data, what determines which modification applies first?
Attempts:
2 left
💡 Hint
Think about how WordPress stores hooks internally.
✗ Incorrect
When hooks have the same priority, WordPress runs them in the order they were added. The first added runs first.