Remove all messages, when untrash a post

As stated before, bulk messages output based on $bulk_counts variable and can’t be edited in admin_notices hook. This is strange, because they has their own html wrapping in wp-admin/edit.php without any actions and filters. So I dig deeper in WP core.

$bulk_counts variable generating in the wp-admin/edit.php in this line:

$bulk_counts = array(
    'updated'   => isset( $_REQUEST['updated'] ) ? absint( $_REQUEST['updated'] ) : 0,
    'locked'    => isset( $_REQUEST['locked'] ) ? absint( $_REQUEST['locked'] ) : 0,
    'deleted'   => isset( $_REQUEST['deleted'] ) ? absint( $_REQUEST['deleted'] ) : 0,
    'trashed'   => isset( $_REQUEST['trashed'] ) ? absint( $_REQUEST['trashed'] ) : 0,
    'untrashed' => isset( $_REQUEST['untrashed'] ) ? absint( $_REQUEST['untrashed'] ) : 0,
);

As we can see, untrashed key gets from the query string. If we untrash single record, this action processing in wp-admin/post.php in this code:

case 'untrash':
        check_admin_referer( 'untrash-post_' . $post_id );

        if ( ! $post ) {
            wp_die( __( 'The item you are trying to restore from the Trash no longer exists.' ) );
        }

        if ( ! $post_type_object ) {
            wp_die( __( 'Invalid post type.' ) );
        }

        if ( ! current_user_can( 'delete_post', $post_id ) ) {
            wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ) );
        }

        if ( ! wp_untrash_post( $post_id ) ) {
            wp_die( __( 'Error in restoring the item from Trash.' ) );
        }

        $sendback = add_query_arg(
            array(
                'untrashed' => 1,
                'ids'       => $post_id,
            ),
            $sendback
        );
        wp_redirect( $sendback );
        exit;

no filters and actions again, but at the end we got wp_redirect() function, which has a filter wp_redirect.

To disable messages, we must remove untrashed=1 argument and optional ids=*** with current post id. In my case I’m writing a flag in session and check this flag in wp_redirect

After redirection

'untrashed' => isset( $_REQUEST['untrashed'] ) ? absint( $_REQUEST['untrashed'] ) : 0;

part returns 0 and according to code in my initial post messages will disappear.

At this time this is the only solution which I’ve found. Any other solutions are welcomes.