By default add_action()
only passes one parameter, not all three. Change your function to:
add_action( 'transition_post_status', function ( $new_status, $old_status, $post ) {
if( 'publish' == $new_status && 'publish' != $old_status ) {
wp_die('STOP');
}
}, 10, 3 );
Edited to add:
The transition_post_status
hook fires after the post transition from future to publish has occurred, and calling wp_die() will not display ‘STOP’ for scheduled posts. Instead you will just prevent the remaining actions in wp_transition_post_status()
from being processed.
Future posts are published with background scheduled events via wp_cron, so calling a function like var_dump()
or print_r()
will not be useful for debugging. Instead try using add_option()
, wp_mail()
, or XDebug bookmarks: jetbrains.com/phpstorm/help/configuring-xdebug.html