Admin Notices don't display on the admin screen for certain post

I want to make a featured image required. For starters i am trying to show an error message after update or post buttons are pressed. The problem is that the notices which i try to include don't show up. For example

function my_admin_notice(){
    global $pagenow;
    if ( $pagenow == 'post.php' ) {
        echo 'div class="updated"
             pThis notice only appears on the plugins page./p
         /div';
    }
}
add_action('admin_notices', 'my_admin_notice');

Whatever notice i try to display in specific post admin screen it doesn't show. Could the problem be in the new Gutenberg editor?

Edit: Yes, when Gutenberg is active the notices don't show up. If i add filter to block the editor, then the messages are displayed. So, how can i make notices to shows in the Gutenberg editor too?

Topic notices post-thumbnails theme-development posts Wordpress

Category Web


I found the answer. Notices in the Block Editor would require JavaScript code.

   ( function( wp ) {
    wp.data.dispatch('core/notices').createNotice(
        'error', // Can be one of: success, info, warning, error.
        'Error Message.', // Text string to display.
        {
            isDismissible: true, // Whether the user can dismiss the notice.
            // Any actions the user can perform.
            actions: [
                {
                    url: '#',
                    label: 'View post'
                }
            ]
        }
    );
} )( window.wp );

Link: https://developer.wordpress.org/block-editor/tutorials/notices/

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.