Performance: Hook priority and arguments
This concept affects how quickly and efficiently WordPress executes hooked functions during page load and user interactions.
add_action('init', 'light_function', 5, 1); function light_function($a) { // simple logic }
add_action('init', 'heavy_function', 10, 5); function heavy_function($a, $b, $c, $d, $e) { // complex logic }
| Pattern | Function Calls | Arguments Processed | Execution Delay | Verdict |
|---|---|---|---|---|
| Default priority (10) with many args | Many | Many | Higher delay | [X] Bad |
| Lower priority number (5) with fewer args | Fewer | Few | Lower delay | [OK] Good |
add_action or add_filter?my_function to the init action hook with priority 15 and accepting 2 arguments?function first_func($arg) {
return $arg . ' first';
}
function second_func($arg) {
return $arg . ' second';
}
add_filter('test_hook', 'first_func', 20, 1);
add_filter('test_hook', 'second_func', 10, 1);
$result = apply_filters('test_hook', 'Run');
echo $result;function my_filter($a, $b) {
return $a + $b;
}
add_filter('calc', 'my_filter', 10, 1);
$result = apply_filters('calc', 5, 10);
echo $result;modify_text. The first function should run before the second and both accept 3 arguments. Which is the correct way to add them?Pass the test and this pattern moves unknown