Created
September 12, 2012 15:12
-
-
Save BFTrick/3707273 to your computer and use it in GitHub Desktop.
WordPress Hooks Demo
This file contains 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
/*------------------------------------- | |
/ 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.