3

I'm using the transition_post_status hook to perform some operations after publishing a post. In some conditions I would like to show an error message in a red box under "Edit Post" and above "Post published":

Post pushlished

How can I do that?

4

I wouldn't use that hook. Here's why

Try something like this using admin_notices.

function wpsites_admin_notice() {
$screen = get_current_screen();
if( 'post' == $screen->post_type
&& 'edit' == $screen->base ){
?>
<div class="error">
    <p><?php _e( 'Updated Demo Message!', 'wpsites' ); ?></p>
</div>
<?php
}}
add_action( 'admin_notices', 'wpsites_admin_notice' );

Untested.

  • Great! But how can I figure out in the wpsites_admin_notice function what is the error that has occurred? – User Feb 6 '14 at 17:31
  • This simply shows you how to display the message. To work out any errors is another question which you should ask or change your original question. – Brad Dalton Feb 6 '14 at 17:33
  • I've asked a new question, but it was marked as duplicate of this. Can you give me a hint? – User Feb 6 '14 at 20:09
  • You could change debug from FALSE to TRUE in your wp-config.php but not sure what errors you are trying to troubleshoot? – Brad Dalton May 20 '14 at 14:32
1
add_settings_error(
    'myUniqueIdentifyer',
    esc_attr( 'settings_updated' ),
    $message,
    $type
);

Check

http://codex.wordpress.org/Function_Reference/add_settings_error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.