Skip to content

Instantly share code, notes, and snippets.

@gagimilicevic
Created September 11, 2019 18:56
Show Gist options
  • Save gagimilicevic/477c719e67a2d27c53ddf531b5124df8 to your computer and use it in GitHub Desktop.
Save gagimilicevic/477c719e67a2d27c53ddf531b5124df8 to your computer and use it in GitHub Desktop.
Return value from add_action function
// 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