Support » Developing with WordPress » add_cap(“publish_posttype”) not working

  • Resolved Dave Navarro, Jr.

    (@dnavarrojr)


    I have created a post type called “teamrooms”.

    I have added the capability to “Contributor”->add_cap("publish_teamrooms") and it’s not working, Contributors can not publish teamroom posts.

    I am not sure what I am missing… Here are the completely capabilities for contributors:

    (
        [copy_posts] => 1
        [create_events] => 1
        [create_posts] => 1
        [create_teamrooms] => 1
        [delete_posts] => 1
        [delete_published_teamrooms] => 1
        [edit_events] => 1
        [edit_others_events] => 1
        [edit_others_posts] => 1
        [edit_others_teamrooms] => 1
        [edit_posts] => 1
        [edit_published_teamrooms] => 1
        [edit_teamrooms] => 1
        [level_0] => 1
        [level_1] => 1
        [publish_teamrooms] => 1
        [read] => 1
    )
Viewing 9 replies - 1 through 9 (of 9 total)
  • Tried publish_teamsroomss with no luck.

    Moderator bcworkz

    (@bcworkz)

    How are the capabilities mapped when the post type is registered? (the “capabilities” argument for register_post_type()) Be sure the role is assigned capabilities matching the registration mappings. There is no added ‘s’ unless it is specified that way in the mappings. Also in arguments for register_post_type(), “map_meta_cap” should probably be true IIRC.

    "capabilities" => array( "publish_posts" => "publish_teamrooms" ),
    "map_meta_cap" => true,

    This still doesn’t work.

    Do I have to specify all of the options, or just the ones I want to add?

    I am at a total loss

    teamrooms->cap = stdClass Object
    (
        [edit_post] => edit_teamrooms
        [read_post] => read
        [delete_post] => edit_teamrooms
        [edit_posts] => edit_teamrooms
        [edit_others_posts] => edit_teamrooms
        [publish_posts] => edit_teamrooms
        [read_private_posts] => edit_teamrooms
        [creat_posts] => edit_teamrooms
        [delete_others_posts] => edit_teamrooms
        [delete_posts] => edit_teamrooms
        [delete_private_posts] => edit_teamrooms
        [delete_published_posts] => edit_teamrooms
        [edit_published_posts] => edit_teamrooms
        [read] => read
        [read_posts] => read
        [create_posts] => edit_teamrooms
    )
    Contributor -> Array
    (
        [copy_posts] => 1
        [create_events] => 1
        [create_posts] => 1
        [create_teamrooms] => 1
        [delete_posts] => 1
        [delete_published_teamrooms] => 1
        [edit_events] => 1
        [edit_others_events] => 1
        [edit_others_posts] => 1
        [edit_others_teamrooms] => 1
        [edit_posts] => 1
        [edit_published_teamrooms] => 1
        [edit_teamrooms] => 1
        [level_0] => 1
        [level_1] => 1
        [publish_teamrooms] => 1
        [read] => 1
    )

    With that, I can’t even see any teamrooms, I get an “You don’t have permission” error.

    https://gist.github.com/dnavarrojr/245e0c032e0a10dd619c3c29ac294f9e

    If I enable map_meta_cap then I can’t access the CPT from any role.

    All I want to do is allow Contributors and Up to have the ability to add/create/delete/edit/publish this CPT.

    Okay, the plugin I posted works in a plain-vanilla install of WordPress.

    So, no I have to figure out why it doesn’t work on my site.

    I am at a total loss…

    I have deactivated all of my plugins and switched to the twenty-seventeen theme and it still doesn’t work on my dev site, but it does on the plain-vanilla WP site.

    Found the problem!! An error in the “map_meta_cap” filter. I deleted it altogether and it’s working now. Thank goodness!

    Moderator bcworkz

    (@bcworkz)

    Filter error! Nice sleuthing 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘add_cap(“publish_posttype”) not working’ is closed to new replies.