WordPress.org

Ready to get started?Download WordPress

Forums

Co-Authors Plus
authors shall only see their own posts (where they are co-author) (4 posts)

  1. Stickhead
    Member
    Posted 1 year ago #

    Hey guys,

    first of all thanks for the good work! :)

    I would like to modify the wordpress backend in a way, so that users of a certain role can only see their own posts (and documents for that matter; I am using WP document revisions for that). There are not really any plugins for that (at least ones that are still maintained), however I found this piece of code that I put into my functions.php:

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

    However, this piece of code doesn't seem to work with coauthors plus: even though a certain user with the role "Editor" is coauthor of a post/document, he can not see the post. Since I am (unfortunately) a php/wordpress noob, I can't figure it out...

    I would be very happy for any suggestions,

    thanks for the Help,

    Stickhead

    http://wordpress.org/extend/plugins/co-authors-plus/

  2. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    Can you instead try this?

    $wp_query->set( 'author_name', $current_user->user_nicename );

  3. Miatsu
    Member
    Posted 1 year ago #

    Hey,

    I've got the same problem, I wanted the author to only see and edit their own posts and own media. I find this code that you can place at the beginning of your functions.php

    //restrict authors to only being able to view media that they've uploaded
    	function ik_eyes_only( $wp_query ) {
    		//are we looking at the Media Library or the Posts list?
    		if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false
    		|| strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false ) {
    			//user level 5 converts to Editor
    			if ( !current_user_can( 'level_5' ) ) {
    				//restrict the query to current user
    				global $current_user;
    				$wp_query->set( 'author', $current_user->id );
    			}
    		}
    	}
    	//filter media library & posts list for authors
    	add_filter('parse_query', 'ik_eyes_only' );

    I hope it will help!

  4. Stickhead
    Member
    Posted 1 year ago #

    Hey, I havent had the chance yet to check it out, but will do as soon as I have time! Anyway, thanks for the code!

    Cheers, Stefan

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic