Show only author's posts, media & comments, but Admin sees all. (3 posts)

  1. haagsekak
    Posted 3 years ago #

    I found a hack (see code below) that forces the user to only see their own posts and media, but the user can still see all comments.
    Can someone be so kind and look at the code and advise how I can include the comments as well. Thank you for your help.

    NOTE: this code was added to the functions.php which resides in /wp-content/themes/twentyeleven-child/wp-admin/functions.php

    function posts_for_current_author($query) {
    global $user_level;

    if($query->is_admin && $user_level < 5) {
    global $user_ID;
    $query->set('author', $user_ID);

    return $query;
    add_filter('pre_get_posts', 'posts_for_current_author');
    This hack was provided by t31os.

    Any assistance is much appreciated.

  2. aarapov
    Posted 3 years ago #

    @haagsekak, try this one.

    function wps_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', 'wps_get_comment_list_by_user');
  3. haagsekak
    Posted 3 years ago #

    @aarpov, thank you for your reply. I will implement the code and let you know how it went.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.