Skip to content

Instantly share code, notes, and snippets.

@BFTrick
Created September 12, 2012 15:12
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 BFTrick/3707273 to your computer and use it in GitHub Desktop.
Save BFTrick/3707273 to your computer and use it in GitHub Desktop.
WordPress Hooks Demo
/*-------------------------------------
/ WordPress Hooks Demo (whd)
-------------------------------------*/
//base function
function whd_a_plus_b(){
$a = 2;
$b = 3;
$a = apply_filters( 'whd_modify_a', $a ); // a = 8
$b = apply_filters( 'whd_modify_b', $b ); // b = 15
echo $a+$b;
}
//modify the variable a
function whd_modify_a_filter($oldValue){
return 4*$oldValue;
}
//modify the variable b
function whd_modify_b_filter($oldValue){
return 5*$oldValue;
}
//add the filters
add_filter( "whd_modify_a", "whd_modify_a_filter" );
add_filter( "whd_modify_b", "whd_modify_b_filter" );
//call the main function
whd_a_plus_b();
exit();
@BFTrick
Copy link
Author

BFTrick commented Sep 12, 2012

Put this code snippet in your WordPress functions.php file.

Feel free to comment out lines 27 and 28 to see the effect the filters have on the variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment