I have a custom post type we have had active for a few months now and managed with the wordpress admin user. We decided to implement different levels of "vendor" with various fields available to them using the Advanced Custom Fields plugin.

I added the "capabilities" section below to the post type so i could manage capabilities with the "User role editor" plugin, however as soon as this code is added no user can upload and attached files, this is the error i get: "Sorry, you are not allowed to attach files to this post."

I can attach pre-uploaded files, and i can also attach files when i remove the capabilities code however then i cannot manage capabilities on a per-role basis.

Also the admin user is no longer capable of editing the existing vendor entries. I believe i need to set some roles in the theme functions file but i am not aware of which ones. I have enabled "upload files" capability for the user roles in question.

Code of the vendors registration is below:

function vendor() {

    $labels = array(
        'name'                  => _x( 'Vendors', 'Post Type General Name', 'vendor_text_domain' ),
        'singular_name'         => _x( 'Vendor', 'Post Type Singular Name', 'vendor_text_domain' ),
        'menu_name'             => __( 'Vendors', 'vendor_text_domain' ),
        'name_admin_bar'        => __( 'Vendors', 'vendor_text_domain' ),
        'archives'              => __( 'Vendor Archives', 'vendor_text_domain' ),
        'parent_item_colon'     => __( 'Parent Item:', 'vendor_text_domain' ),
        'all_items'             => __( 'All Vendors', 'vendor_text_domain' ),
        'add_new_item'          => __( 'Add New Vendor', 'vendor_text_domain' ),
        'add_new'               => __( 'Add New', 'vendor_text_domain' ),
        'new_item'              => __( 'New Vendor', 'vendor_text_domain' ),
        'edit_item'             => __( 'Edit Vendor', 'vendor_text_domain' ),
        'update_item'           => __( 'Update Vendor', 'vendor_text_domain' ),
        'view_item'             => __( 'View Vendor', 'vendor_text_domain' ),
        'search_items'          => __( 'Search Vendor', 'vendor_text_domain' ),
        'not_found'             => __( 'Not found', 'vendor_text_domain' ),
        'not_found_in_trash'    => __( 'Not found in Trash', 'vendor_text_domain' ),
        'featured_image'        => __( 'Featured Image', 'vendor_text_domain' ),
        'set_featured_image'    => __( 'Set featured image', 'vendor_text_domain' ),
        'remove_featured_image' => __( 'Remove featured image', 'vendor_text_domain' ),
        'use_featured_image'    => __( 'Use as featured image', 'vendor_text_domain' ),
        'insert_into_item'      => __( 'Insert into item', 'vendor_text_domain' ),
        'uploaded_to_this_item' => __( 'Uploaded to this item', 'vendor_text_domain' ),
        'items_list'            => __( 'Vendor list', 'vendor_text_domain' ),
        'items_list_navigation' => __( 'Vendor list navigation', 'vendor_text_domain' ),
        'filter_items_list'     => __( 'Filter items list', 'vendor_text_domain' ),
    $args = array(
        'label'                 => __( 'Vendor', 'vendor_text_domain' ),
        'description'           => __( 'Individual Vendors', 'vendor_text_domain' ),
        'labels'                => $labels,
        'supports'              => array( 'title', 'editor', 'thumbnail', 'revisions', 'page-attributes', ),
        'taxonomies'            => array( 'post_tag' ),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 5,
        'menu_icon'             => 'dashicons-store',
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'upload_files'          => true,
        'has_archive'           => true,        
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'capability_type'       => 'post',
        'capabilities' => array(
          'edit_post'          => 'edit_vendor', 
          'read_post'          => 'read_vendor', 
          'delete_post'        => 'delete_vendor', 
          'edit_posts'         => 'edit_vendors', 
          'edit_others_posts'  => 'edit_others_vendors', 
          'publish_posts'      => 'publish_vendors',       
          'read_private_posts' => 'read_private_vendors', 
          'create_posts'       => 'create_vendor', 
          'upload_files'       => 'upload_vendor_files'
    register_post_type( 'vendor', $args );

You have assigned custom capabilities to post type, but did you assigned these capabilities to user roles or users? This is not done automatically, and adding custom caps to post types doesn't add those caps to the roles or users. You have two solutions:

  1. Register post type without the 'capabilities' options, and it will fall back to default capabilities used by posts or pages.
  2. Use some User Roles editor plugin to assign these new 'vendor' based capabilities to user roles you want to allow using them.
  • Thanks for your help Milan, i have assigned those capabilities to 3 roles inside the "User role editor" plugin. Unfortunately that has not helped and not even the admin user can attach media to the post when the array of capabilities is added in the functions.php file. – Paul Cullen Oct 2 '17 at 13:16
  • I have tested and use something like this before, and I can confirm that it works fine. I am not sure why it is not working for you. – Milan Petrovic Oct 2 '17 at 13:35
  • Ok ill leave all permissions as they are for now and disable all plugins, check if there is a conflict present there. – Paul Cullen Oct 2 '17 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.