学习完本教程后,您将知道如何在仪表板帖子中禁用(或删除)“所有帖子,已发布和已删除邮件”。WP_Posts_List_Table类扩展了WP_List_Table,并且在WP_List_Table :: views()方法中,我们具有以下动态视图过滤器:
/**
* Filter the list of available list table views.
*
* The dynamic portion of the hook name, `$this->screen->id`, refers
* to the ID of the current screen, usually a string.
*
* @since 3.5.0
*
* @param array $views An array of available list table views.
*/
$views = apply_filters( “views_{$this->screen->id}”, $views );
因此,我们可以使用生成的views_edit-post过滤器来调整发布列表表格的视图。
如何禁用(或删除)仪表板帖子中的“所有帖子,已发布和已删除邮件”
让我们删除非管理员用户的全部,发布,将来,即时贴,草稿,待处理和回收站。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
/**
* Remove the ‘all’, ‘publish’, ‘future’, ‘sticky’, ‘draft’, ‘pending’, ‘trash’
* views for non-admins
*/
add_filter( ‘views_edit-post’, function( $views )
{
if( current_user_can( ‘manage_options’ ) )
return $views;
$remove_views = [ ‘all’,‘publish’,‘future’,‘sticky’,‘draft’,‘pending’,‘trash’ ];
foreach( (array) $remove_views as $view )
{
if( isset( $views[$view] ) )
unset( $views[$view] );
}
return $views;
} );
|
之前
后
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/260170.html