How to show a notice to admin after “publish_post” ?

[ad_1]

I am developing a WordPress plugin.

Everything works properly, but I don’t know how to display a message to the admin:

function example_send_notifications( $post_id ) {
// do something (it works)

// then I need to display a success or failure message to the admin in the editor
// e.g. show_admin_message( ‘Notifications sent!’ );
}
add_action( ‘publish_post’, ‘example_send_notifications’, 10, 1 );

How can I achieve that (**display a message to the admin in the Gutenberg editor**)?

I would like the message to have a style similar to the “Post published” toast message that is displayed by WP in the bottom left corner.

[ad_2]
2 Comments
  1. I found the problem:

    [https://developer.wordpress.org/block-editor/how-to-guides/notices/])

    It seems that I need to use Javascript for Gutenberg.

    I still don’t understand how to use that JavaScript code from the `publish_post` callback..

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer