Support » Fixing WordPress » edit_others_… capability on custom post type

  • 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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.

    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;

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘edit_others_… capability on custom post type’ is closed to new replies.