Created
September 11, 2019 18:56
-
-
Save gagimilicevic/477c719e67a2d27c53ddf531b5124df8 to your computer and use it in GitHub Desktop.
Return value from add_action function
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
// define action with param for result transport | |
function some_action($someParam, $transport) { | |
// do stuff | |
if($someParam > 10) { | |
$transport->return = true; | |
} else { | |
$transport->return = 5; | |
} | |
} | |
add_action('some_action', 'some_action', 10, 2); | |
// call action | |
do_action('some_action', 5, $transport = new stdClass()); | |
var_dump($transport->return); | |
// output true | |
do_action('some_action', 11, $transport = new stdClass()); | |
var_dump($transport->return); | |
// output 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment