show my own admin_notices after a post has been published

Add Additional ‘Published’ Notices

You can use the following to add an additional admin notice after a post has been published:

add_action('admin_notices', function(){
    $screen = get_current_screen();     

    $editPostScreen = ($screen->parent_base == 'edit' && $screen->post_type == 'post') ? true : false;
    $justPublished = (isset($_GET['message']) && $_GET['message'] == '6') ? true : false;

    if ($editPostScreen && $justPublished) {

        $class="notice notice-info";
        $message = __( 'Just published a post custom text', 'myplugin_textdomain' );
        printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) ); 

    }
});

($justPublished relies on $_GET['message']. This URL query variable is not visible in admin address bar as WordPress actually removes it from the URL with Javascript! Took me a long while to figure that out, so although you can’t see it, it actually exists!).


Edit The Default ‘Published’ Notice

You can use the following to edit the admin notice after a post has been published:

add_filter( 'post_updated_messages', function($messages){
    $messages['post'][6] = __( 'Just published a post custom text', 'myplugin_textdomain' );
    return $messages;
}, 10, 1 );

tech