Question

Is it possible to add an admin_notice to the post.php edit screen in the admin– only if the post was just updated.

function my_admin_notice(){
    global $pagenow;
    if ( $pagenow == 'post.php' ) {
        // Check if the post was just updated...
        echo '<div class="notice notice-warning is-dismissible">
            <p>This is my custom post-was-just-updated admin notice.</p>
        </div>';
    }
}
add_action('admin_notices', 'my_admin_notice');
Was it helpful?

Solution

I figured it out by looking in WP Core. When you update a post it actually takes you back to the edit posts screen (post.php) with a GET parameter of message=1. And then it erases that parameter from the url with javascript quickly. So you can find out if posts were uploaded in a plugin by checking:

if ($_GET['message'] == 1) {
  // do something because the post was just updated
}
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top