Whats a proper way to send a warning/error in a transition_post_status hook?
-
I have an issue i am unsure what the best way to solving it is. I even am uncertain if the used hook is the right one for the task. Basically my goal is the following: I want to check every post if it changes status and in case the new status is set to publish i want to perform a few conditional checks. If certain conditions are met the status should be changed to publish if the conditions aren’t met the status shouldn’t be updated and an warning/error/admin_notices should be shown.
I haven’t figured out the conditional logic yet completely but even if i check only for the new status and place an
echo
,var_dump
or aadmin_notices
function call inside i get “Cannot modify header information” cuz the http page headers are already sent.function abc_attachment_check( $new_status, $old_status, $post ) { if( $new_status === 'publish' ) { $media = abc_attachments( $post->ID ); var_dump($media); } } add_action( 'transition_post_status', 'abc_attachment_check', 10, 3 );
So my question is is the
transition_post_status
action the apropriate hook or should i go with another one? and what would be a proper way to go with the warning and error message call and display? Cuz i am kind of lost what the best choice would be. :/ Thanks Ralf
- The topic ‘Whats a proper way to send a warning/error in a transition_post_status hook?’ is closed to new replies.