Last active
August 29, 2015 14:08
-
-
Save leewillis77/18a04eef8f6305711ca4 to your computer and use it in GitHub Desktop.
Hook/Filter arg best practice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Consider the following hook | |
do_action( 'my_swanky_hook', $a, $b, $c ); | |
/* | |
* I would traditionally attach as follows: | |
*/ | |
function my_swanky_hook_handler( $a, $b, $c ) { | |
// Code here, that only actually uses $a | |
} | |
add_action( 'my_swanky_hook', 'my_swanky_hook_handler', 10, 3 ); | |
/* | |
* However, given that $b and $c aren't used, is the following preferred: | |
*/ | |
function my_swanky_hook_handler( $a ) { | |
// Code here, that only actually uses $a | |
} | |
add_action( 'my_swanky_hook', 'my_swanky_hook_handler', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment