使用过滤器,我们可以防止Trash
正在打印的链接
如果用户试图直接访问URL,则使用该操作重定向回“发布列表”页面(/wp-admin/edit.php?post_status=trash&post_type=post
).
add_filter( \'views_edit-post\', \'wpse_74488_remove_trash_link\' );
add_action( \'admin_head-edit.php\', \'wpse_74488_block_trash_access\' );
function wpse_74488_remove_trash_link( $views )
{
if( !current_user_can( \'delete_plugins\' ) )
unset( $views[\'trash\'] );
return $views;
}
function wpse_74488_block_trash_access()
{
global $current_screen;
if(
\'post\' != $current_screen->post_type
|| \'trash\' != $_GET[\'post_status\']
)
return;
if( !current_user_can( \'delete_plugins\' ) )
{
wp_redirect( admin_url() . \'edit.php\' );
exit;
}
}