I have the following functions:
function test($post_id){
do_action('test_action',$post_id);
echo $post_id;
}
add_action('test_action',function($post_id){
if ( $post_id == 2 ) //Stop test function execution
}
Using the function hooked to add_action
, how to stop the execution of test()
function without adding any code to test()
. In the above example, if $post_id == 2
, the echo $post_id;
code should not run in test()
.
return
, or you can wrap the code in a conditionaladd_action
hook, how to stop the execution oftest()
function with containsdo_action
. In the above example, if$post_id == 2
, theecho $post_id;
code should not run intest()
exit
but that would stop absolutely everything else from continuing.