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":
How can I do that?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI'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":
How can I do that?
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.
wpsites_admin_notice
function what is the error that has occurred?
add_settings_error(
'myUniqueIdentifyer',
esc_attr( 'settings_updated' ),
$message,
$type
);
Check
http://codex.wordpress.org/Function_Reference/add_settings_error