• Resolved eduardasm

    (@eduardasm)


    Hello,
    I have a custom post type company and would like to have a user role with capability to see and edit in admin only those companies, that were assigned by administrator.

    For custom post type I’ve set custom capability “companies” and granted all access to administrators.

    For subscriber role I’ve set capabilities edit_companies, edit_other_companies and edit_published_companies.

    Now subsciber can see and edit ALL companies in admin, but I want to allow him to edit only assigned companies. I use Advanced Custom Field plugin and have created relational field user to be able to select user from subscribers. So how can I connect posts meta key “user” to capabilities?

Viewing 3 replies - 1 through 3 (of 3 total)
  • To allow users to only be able to edit their own “companies”, remove the edit_other_companies capability from the role. That should keep them from editing other user’s companies.

    To keep them from creating new companies, you’d have to set the create_posts capability up when registering your post type capabilities. You’d set it to something like create_companies but only give that to administrators.

    As for actually hiding the companies that a user cannot edit, that would take a custom-built plugin. It’s not hard to build. Shoot me an email if you’re interested in talking it over.

    Thread Starter eduardasm

    (@eduardasm)

    Thanks for quick reply. I was using Custom Post Type UI plugin for creating custom post type, but it does not offer to customize capabilities. Then I have registered it manualy:
    add_action(‘init’, ‘register_company_post_type_function’);
    function register_company_post_type_function() {
    $labels = array(
    ‘name’ => __(‘Companies’, ”),
    ‘singular_name’ => __(‘Company’, ”),
    );
    $args = array(
    ‘label’ => __(‘Companies’, ”),
    ‘labels’ => $labels,
    ‘description’ => ”,
    ‘public’ => true,
    ‘publicly_queryable’ => true,
    ‘show_ui’ => true,
    ‘show_in_rest’ => false,
    ‘rest_base’ => ”,
    ‘has_archive’ => ‘imones’,
    ‘show_in_menu’ => true,
    ‘exclude_from_search’ => false,
    ‘hierarchical’ => false,
    ‘rewrite’ => array( ‘slug’ => ‘imone’, ‘with_front’ => true ),
    ‘query_var’ => true,
    ‘supports’ => array( ‘title’, ‘editor’, ‘thumbnail’, ‘excerpt’, ‘author’ ),
    ‘taxonomies’ => array( ‘heading_category’, ‘company_category’, ‘company_country’ ),
    ‘capability_type’ => ‘company’,
    ‘capabilities’ => array(
    ‘edit_post’ => ‘edit_company’,
    ‘edit_posts’ => ‘edit_companys’,
    ‘edit_published_post’ => ‘edit_published_company’,
    ‘edit_published_posts’ => ‘edit_published_companys’,
    ‘edit_other_post’ => ‘edit_published_company’,
    ‘edit_other_posts’ => ‘edit_published_companys’,
    ‘edit_private_post’ => ‘edit_private_company’,
    ‘edit_private_posts’ => ‘edit_private_companys’,
    ‘create_post’ => ‘create_company’,
    ‘create_posts’ => ‘create_companys’,
    ‘publish_post’ => ‘publish_company’,
    ‘publish_posts’ => ‘publish_companys’,
    ‘copy_post’ => ‘copy_company’,
    ‘copy_posts’ => ‘copy_companys’,
    ‘delete_post’ => ‘delete_company’,
    ‘delete_posts’ => ‘delete_companys’,
    ‘delete_published_post’ => ‘delete_published_company’,
    ‘delete_published_posts’ => ‘delete_published_companys’,
    ‘delete_other_post’ => ‘delete_other_company’,
    ‘delete_other_posts’ => ‘delete_other_companys’,
    ‘delete_private_post’ => ‘delete_private_company’,
    ‘delete_private_posts’ => ‘delete_private_companys’,
    ),
    ‘map_meta_cap’ => true,
    );
    register_post_type(‘company’, $args);
    }

    Using Members plugin I’ve created role Manager and granted following capabilities for Companies:
    edit_company
    edit_companies
    edit_published_company
    edit_published_companies
    publish_company
    publish_companies

    For Administrator I’ve granted all.

    After doing this, logged in as Manager I could see Companies on admin menu, but still could not access edit.php?post_type=company page. Only after I granted edit_posts capability to Members I could access this page, but at the same time Manager got access to Posts and Tools admin menu. How can I hide these from Managers – they should see only Companies and Profile.

    @eduardasm I am having exactly the same problem. Did you manage to find a solution?

    Cheers,

    Andrew

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Allow to see and edit in admin only assigned posts’ is closed to new replies.