在WordPress后台的文章列表只显示该作者自己的文章

对于WordPress多作者博客,如何让每个作者在后台只能浏览自己的文章?只需要将下面的代码添加到你主题的 functions.php 即可:

function mypo_parse_query_useronly( $wp_query ) {
    if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false ) {
        if ( !current_user_can( 'manage_options' ) ) {
            global $current_user;
            $wp_query->set( 'author', $current_user->id );
        }
    }
}
 
add_filter('parse_query', 'mypo_parse_query_useronly' );

以上代码排除了对管理员的限制,也就是管理员是可以看到所有人的文章的。

来源:

https://www.wpdaxue.com/only-display-the-author-posts-in-the-admin-post-list.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_33256.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?