WordPress企业主题定制/开发/优化

WordPress用户只能查看自己的文章与评论

首页 » WORDPRESS教程 » WordPress用户只能查看自己的文章与评论

把下面的代码复制到您的主题下面的Functions.php中。

/*只能查看自己的文章评论*/
function wpdx_get_comment_list_by_user($clauses) {
if (is_admin()) {
global $user_ID, $wpdb;
$clauses['join'] = ", wp_posts";
$clauses['where'] .= " AND wp_posts.post_author = ".$user_ID." AND wp_comments.comment_post_ID = wp_posts.ID";
};
return $clauses;
};
if(!current_user_can('edit_others_posts')) {
add_filter('comments_clauses', 'wpdx_get_comment_list_by_user');
}

/*只能查看自己发布的文章*/
function wpjam_parse_query_useronly( $wp_query ) {
if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false ) {
if ( !current_user_can( 'add_user' ) ) {
global $current_user;
$wp_query->set( 'author', $current_user->id );
}
}
}
add_filter('parse_query', 'wpjam_parse_query_useronly' );

分类与标签:

WORDPRESS教程

相关项目

  • WordPress外贸企业主题

  • 最近更新

  • 热门标签