CPT with User Roles

Support General CPT with User Roles

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #44950
    shmaltzshmaltz
    Participant

    I created a CPT "meal" using the Metabox UI and I want to create a user role that will allow the user to only create and edit (not delete) "meal" posts that they created.

    I am using the following code, but the Meal posts menu item doesn't show up for that user.

    How can I make this work?

    
    function create_meal_contributor_role() {
        add_role('meal_contributor', 'Meal Contributor', array('read' => true));
    
        $role = get_role('meal_contributor');
    
        $role->add_cap('read_meal_posts');
        $role->add_cap('edit_meal_posts');
        $role->add_cap('edit_published_meal_posts');
        $role->add_cap('publish_meal_posts');
        $role->add_cap('delete_meal_posts', false);
    }
    add_action('init', 'create_meal_contributor_role');
    
    #44968
    PeterPeter
    Moderator

    Hello,

    If you remove your custom code, does the user see the Meal menu item? I'm not sure exactly what the issue is with capabilities, but you can try to use the plugin User Role Editor to manage the capabilities with UI and check/uncheck some of them.
    https://wordpress.org/plugins/user-role-editor/

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.