Support » Plugins » Show only author's posts, media & comments, but Admin sees all.

  • 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);
    unset($user_ID);
    }
    unset($user_level);

    return $query;
    }
    add_filter(‘pre_get_posts’, ‘posts_for_current_author’);
    —————————————————————
    This hack was provided by t31os.

    Any assistance is much appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • @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');
    }

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show only author's posts, media & comments, but Admin sees all.’ is closed to new replies.