Admin Notification after save_post, when ajax saving in gutenberg


How can I display an admin notification?

I want to do some actions on the save_post_post action and want to inform the admin about the success and details about the action after that.

I tried so far:

add_action('save_post_post', "do_Stuff");

function do_stuff( $postId ){

    //do stuff and create some $msg;

     set_transient( 'temporary_message', $msg, 60*60*12 );
     add_action( 'admin_notices', 'show_notice');


function show_notice(){
    <div class="notice notice-error">
        <p>Fehler: <?=get_transient( 'temporary_message' )?></p>

The Thing is, this notification is not shown, because the browser does not reload after saving, because the saving happens via ajax … my save_post_post hook is called.

I already tried to create and output some JSON, as I get an error-admin-notification if I output any text, that my JSON is invalid. But When I send JSON and inspect the network traffic in Chrome, I don’t see any response and .. the earlier error is still there.

How can I show an Admin Notification anyways?

, , helle 3 years 2020-04-01T12:52:43-05:00 0 Answers 94 views 0

Leave an answer