没有叫胡克的post_trashed_messages
, 但有一个bulk_post_updated_messages
hook 可用于更改批量操作更新消息:
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 );
或者,要针对特定的post类型,请将键设置为post type(
$bulk_messages[\'<post type slug>\']
) &mdash;在下面的示例中,post类型slug为
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 );
此外,正如您在上面所看到的,我建议您让用户(和/或您自己)知道有多少帖子被删除。所以利用
$bulk_counts[\'trashed\']
而不是简单地说“已成功删除”…:)
更新以回复您的评论,“如何删除撤消按钮”,我看不到这方面的过滤器,但您可以使用CSS直观地隐藏按钮:(只需更改my_cpt
至正确的(柱式)段塞。)body.edit-php.post-type-my_cpt #message a[href*="&doaction=undo&action=untrash"] {
display: none;
}