Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #6083
    webdev
    Participant

    I have roles set up to create new custom post types. However, when users with these roles create a new custom post type, URE automatically only grants rights to that new type to administrators. The users creating these new types are blocked from being able to work with that type until an administrator goes in and gives their role access to it. This is slowing these users down from being able to do their work.

    I would like the URE plugin to do the following:
    If a role has rights to create new custom post types, URE automatically grants that role rights to any new custom post types created.

    #6084
    Vladimir
    Keymaster

    What plugin do you use to create new custom post types?

    #6086
    webdev
    Participant

    We’re using Toolset Types, version 3.3.5, https://toolset.com/.

    #6089
    Vladimir
    Keymaster

    I asked about plugin to clarify what permission allows to create custom post type. I don’t have access to the “Toolset Types” plugin though. This solution is not suitable in case it uses some widely used capability like ‘manage_options’

    URE adds user capabilities for custom post type (CPT) to ‘administrator’ role automatically only when “Users->User Role Editor” page is opening. I added custom filter ure_cpt_editor_roles in order to extend the list of roles to which URE will add capabilities for CPT in addition to default administrator. It will be available with the next update.

    URE page should be opened at least 1 time after new CPT was added. Will this update satisfy your needs?

    #6094
    webdev
    Participant

    That sounds okay. If I understand it correctly, I’m not sure how my users will feel about it, as it will still require them to notify an admin to go into the URE panel in order for their rights to the new custom post type to be activated (albeit automatically instead of the admin having to grant it manually).

    I will test it when it’s released and let you know if it works as expected.

    Thank you for the quick response!

    #6096
    webdev
    Participant

    As I’ve discussed this with my users, we’ve reached the conclusion that this proposed solution will not work for us. The problem is that it still requires them to get an administrator to manually go into the URE panel before they get rights to the custom post types they’ve created. They’re still blocked from using the new CPT until the administrator does this, so it’s no real improvement over our current situation.

    Ultimately what is needed is that if a role has the right to create new custom post types, it should have the right to immediately see any new CPTs created without the need for any intervention by an administrator.

    Could there be a new setting of some kind that could be set to automatically grant access to new post custom types? With that, I as an administrator could say that I want new CPTs to automatically become accessible to the roles which I choose.

    #6097
    Vladimir
    Keymaster

    You may try this solution:

    
    add_action( 'registered_post_type', 'cpt_add_edit_permissions', 10, 2 );
    
    function cpt_add_edit_permissions( $post_type, $post_type_object ) {
    
        if ( !class_exists( 'URE_Lib') ) {
            return;
        }
        
        $roles = array('administrator', 'editor');
        $lib = URE_Lib::get_instance();
        $capabilities = $lib->get_edit_post_capabilities();
        foreach( $capabilities as $capability ) {
            if ( isset( $post_type_object->cap->$capability ) ) {
                URE_Capabilities::add_cap_to_roles( $roles, $post_type_object->cap->$capability );
            }        
        }
        
    }
    

    This code automatically adds edit capabilities to roles from the all $roles array for any registered post type.
    Parameters:
    $post_type – post type slug, like ‘post’,
    $post_type_object – self commented.

    Just fill $roles array with your own roles ID, which is allowed to create new custom post types and setup this code as a must use plugin to wp-content/mu-plugins folder.

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