I tried to set up an action hook with transition_post_status
. Inside I wanted to set up a few conditional statements. To see if everything works I wanted to place a debug statement. Problem is as soon as I set an echo statement i get the output alongside two warning messages:
Error
Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/sandbox/wp-content/plugins/media-meta-require/media-meta-require.php:193) in /Applications/MAMP/htdocs/sandbox/wp-admin/post.php on line 233
Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/sandbox/wp-content/plugins/media-meta-require/media-meta-require.php:193) in /Applications/MAMP/htdocs/sandbox/wp-includes/pluggable.php on line 1178
The error turns up no matter how I call the Error string. With a plain echo string:
function mmr_attachment_check( $new_status, $old_status, $post ) {
if( $new_status === 'publish' ) {
echo 'Error';
}
}
add_action( 'transition_post_status', 'mmr_attachment_check', 10, 3 );
With an echo containing html elements:
function mmr_attachment_check( $new_status, $old_status, $post ) {
if( $new_status === 'publish' ) {
echo '<div class="error"><p>Error</p></div>';
}
}
add_action( 'transition_post_status', 'mmr_attachment_check', 10, 3 );
or if i call an external function:
function mmr_attachment_check( $new_status, $old_status, $post ) {
if( $new_status === 'publish' ) {
mmr_admin_notice();
}
}
add_action( 'transition_post_status', 'mmr_attachment_check', 10, 3 );
function mmr_admin_notice() {
global $pagenow;
if( $pagenow == 'post.php') {
echo '<div class="error"><p>Error</p></div>';
}
}
as soon as i comment out the echo related line it passes without an error. i've also consulted the wp troubleshooting document regarding that problem. But i can't find any whitespaces or alikes which might cause that behaviour in my example. :/