WordPress.org

Ready to get started?Download WordPress

Forums

edit_others_... capability on custom post type (3 posts)

  1. Bev
    Member
    Posted 2 years ago #

    For my custom post type (notices), I would like a user to be able to add/edit/delete their own posts, but not those of others. I defined a custom capability and disabled "edit_others_notices".

    It seems to me there are 2 problems:

    - The user is presented with the option to edit others notices, but when they go to save they get an error message. There should be no option to edit in the first place.
    - Users can delete others notices. Shouldn't this be disabled due to the lack of edit_others_notices?

  2. Bev
    Member
    Posted 2 years ago #

    New problem - users can also undelete others' trashed posts. If the trashed post was published it will be restored as published even if the user cannot publish this post type.

  3. Bev
    Member
    Posted 2 years ago #

    Well I found a hacky fix to hide the problem. On a user with no edit_others_notices permission I can hide the subsubsub menu at the top and then the user can't access the others' posts.

    The code:

    // ****************************
    // Hide the top menu from users with no permission to edit_others_notices
    // ****************************
    add_filter( 'views_edit-notices' , 'hide_notice_menu', 10, 1);
    
    function hide_notice_menu ( $views) {
    if ( !current_user_can('edit_others_notices') )
            return '';
    
    return $views;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.