Skip to content

Instantly share code, notes, and snippets.

@leewillis77
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leewillis77/18a04eef8f6305711ca4 to your computer and use it in GitHub Desktop.
Save leewillis77/18a04eef8f6305711ca4 to your computer and use it in GitHub Desktop.
Hook/Filter arg best practice
<?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