Find out if post was just updated on post edit screen
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');
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