对于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' );
以上代码排除了对管理员的限制,也就是管理员是可以看到所有人的文章的。