So I have a custom post type called members. linked with advanced custom fields
and I’ve made it so if I delete a member from the custom post type it doesn’t move to the trash and permanently deletes it. but I still get this message:
the line I’m trying to override inside /wp-admin/edit.php
is:
'trashed' => _n( '%s post moved to the Trash.', '%s posts moved to the Trash.', $bulk_counts['trashed'] ),
the code I’ve tried inside functions.php
to change it is as follows:
add_filter( 'post_trashed_messages', function( $messages )
{
$messages['post'][2] = 'Succesfully deleted';
return $messages;
} );
1 Answer
There’s no hook named post_trashed_messages
, but there is the bulk_post_updated_messages
hook which you can use to change the bulk action updated messages:
add_filter( 'bulk_post_updated_messages', function ( $bulk_messages, $bulk_counts ) {
$bulk_messages['post']['trashed'] = _n( '%s post successfully deleted.', '%s posts successfully deleted.', $bulk_counts['trashed'] );
return $bulk_messages;
}, 10, 2 );
Or to target a specific post type, set the key to the post type slug ($bulk_messages['<post type slug>']
) — in the example below, the post type slug is my_cpt
:
add_filter( 'bulk_post_updated_messages', function ( $bulk_messages, $bulk_counts ) {
$bulk_messages['my_cpt'] = isset( $bulk_messages['my_cpt'] ) ? $bulk_messages['my_cpt'] : array();
$bulk_messages['my_cpt']['trashed'] = _n( '%s post successfully deleted.', '%s posts successfully deleted.', $bulk_counts['trashed'] );
return $bulk_messages;
}, 10, 2 );
Also, as you could see above, I suggest you to let users (and/or yourself) know how many posts were deleted. So make use of the $bulk_counts['trashed']
instead of simply saying ‘Successfully deleted’.. 🙂
UPDATE
In reply to your comment, “how to get rid of the undo button“, I don’t see a filter for that, but you can use CSS to visually hide the button: (Just change the my_cpt
to the correct (post type) slug.)
body.edit-php.post-type-my_cpt #message a[href*="&doaction=undo&action=untrash"] {
display: none;
}