plugins – Remove all messages, when untrash a post

Question

I’m trying to replace default untrash message to my own with error class. admin_notices do everything as expected, but even if I return empty messages array in bulk_post_updated_messages filter, I’m still see notice, but with empty content with Edit link.

enter image description here

According to wp-admin/edit.php, messages generating based on $bulk_counts, but bulk_post_updated_messages filter returns $bulk_messages only and even if I change this array, nothing happened. How to access $bulk_counts?

$bulk_messages = apply_filters( 'bulk_post_updated_messages', $bulk_messages, $bulk_counts );
$bulk_counts   = array_filter( $bulk_counts );

...

// If we have a bulk message to issue:
$messages = array();
foreach ( $bulk_counts as $message => $count ) {
    if ( isset( $bulk_messages[ $post_type ][ $message ] ) ) {
        $messages[] = sprintf( $bulk_messages[ $post_type ][ $message ], number_format_i18n( $count ) );
    } elseif ( isset( $bulk_messages['post'][ $message ] ) ) {
        $messages[] = sprintf( $bulk_messages['post'][ $message ], number_format_i18n( $count ) );
    }

    if ( 'trashed' === $message && isset( $_REQUEST['ids'] ) ) {
        $ids        = preg_replace( '/[^0-9,]/', '', $_REQUEST['ids'] );
        $messages[] = '<a href="' . esc_url( wp_nonce_url( "edit.php?post_type=$post_type&doaction=undo&action=untrash&ids=$ids", 'bulk-posts' ) ) . '">' . __( 'Undo' ) . '</a>';
    }

    if ( 'untrashed' === $message && isset( $_REQUEST['ids'] ) ) {
        $ids = explode( ',', $_REQUEST['ids'] );

        if ( 1 === count( $ids ) && current_user_can( 'edit_post', $ids[0] ) ) {
            $messages[] = sprintf(
                '<a href="%1$s">%2$s</a>',
                esc_url( get_edit_post_link( $ids[0] ) ),
                esc_html( get_post_type_object( get_post_type( $ids[0] ) )->labels->edit_item )
            );
        }
    }
}

0
user3013494 5 months 2022-05-09T10:26:44-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse