Support » Plugin: Co-Authors Plus » 2 authors, but only the first can see post

  • Resolved Iamhere

    (@iamhere)


    Hi

    Remarkable plugin, thank you.

    I have activated the plugin and have assigned 2 authors to one post.
    The first author that is listed logs in and can see the post no worries, but the second author logs in cannot see the post at all.

    I am using some code to restrict the author to only see their own post.
    I’ve disabled this but still can’t see the post with the 2nd author.

    Suggestions please?
    Thanks

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

Viewing 7 replies - 1 through 7 (of 7 total)
  • Iamhere

    (@iamhere)

    I am using some code to restrict the author to only see their own post.
    I’ve disabled this but still can’t see the post with the 2nd author.
    This is the code I am using to restrict users to their posts.

    I am pretty certain this is the culprit as when I disable this, I can see all posts and edit the co-author post.

    So the question is – how to edit this to work with multiple-authors?

    function posts_for_current_author($query) {
    	global $pagenow;
    
    	if( 'edit.php' != $pagenow || !$query->is_admin )
    	    return $query;
    
    	if( !current_user_can( 'manage_links' ) ) {
    		global $user_ID;
    		$query->set('author', $user_ID );
    	}
    
    	return $query;
    }
    add_filter('pre_get_posts', 'posts_for_current_author');

    In the above code, I also tried with commenting out

    // if( !current_user_can( ‘manage_links’ ) ) {

    But this still had no effect.

    Only commenting out the entire code above worked.
    I was then able to login as the second Author, see the post and edit it.

    However, I need to use this code to restrict the author to see only their own post (there are many authors and many posts and the authors are newbies so this is attempting to keep things easy for them when they log in) – so how to make it recognise multiple authors?

    solaceten

    (@solaceten)

    This is also something I would like to resolve as I have a similar set up and only the primary author (1st allocated) can see the post – the others see nothing.

    Is there a way to declare global $user_ID; to pick up the co-authors first? I think that would solve it, but need the correct hook to do that.
    I will experiment with this;

    $co_authors = get_coauthors( $post->ID );

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Hand Built

    ‘author_name’ would be a better query param to set than ‘author’:

    $query->set( 'author_name', wp_get_current_user()->user_login );

    Iamhere

    (@iamhere)

    Hi Daniel

    Thank you for your reply. I tried your code but it does not work.
    The second author still cannot see or edit the post.

    Any further suggestions?

    Iamhere

    (@iamhere)

    I should also mention that I am using custom post type (advanced custom fields) would that need to be taken into consideration?

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Hand Built

    You also need to set $query->is_author = true too:

    function posts_for_current_author($query) {
    	global $pagenow;
    
    	if ( 'edit.php' != $pagenow || !$query->is_admin )
    		return $query;
    
    	if ( ! current_user_can( 'manage_options' ) ) {
    		$query->is_author = true;
    		$query->set( 'author_name', wp_get_current_user()->user_nicename );
    	}
    }
    add_filter('parse_query', 'posts_for_current_author');

    What a nice man, you just saved me hours. This plugin has so much support! Brilliant!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘2 authors, but only the first can see post’ is closed to new replies.