• Resolved vinnyegc

    (@vinnyegc)


    Hello, I have a custom user role named Franchisee, (gtt_franchisee) I also have a custom post type named Locations (location).

    The Post type has 2 capabilities for the location pages, edit_locations and edit_published_locations.

    When I try to edit anything it doesnt work, I can update but it goes live and not set for review. However if I give that same user role only edit_page for the default page post type, it works fine and I can submit for review. How do I get this to work properly?

    Here is a screen shot of my user role permissions for my Locations post type.
    https://ibb.co/e9w7wo

    This is default Pages post type.
    https://ibb.co/jmwU98

    Thank you in advance.

    • This topic was modified 6 years, 8 months ago by vinnyegc.
Viewing 15 replies - 1 through 15 (of 27 total)
  • Plugin Author jamiechong

    (@jamiechong)

    You can add filters to override the permissions. See revisionize.php

    https://github.com/jamiechong/revisionize/blob/master/revisionize.php#L423-L429

    Also see line Line 451.

    The filters are:

    revisionize_user_can_revisionize
    revisionize_user_can_publish_revision
    revisionize_is_create_enabled

    Thread Starter vinnyegc

    (@vinnyegc)

    Hi Jamie,

    Can you explain how to get it this to work? I tried adding
    current_user_can('edit_locations')
    to the filter. That doesnt seem to work though.

    Plugin Author jamiechong

    (@jamiechong)

    Did you do something similar for all three filters? You will need to add logic to handle your locations capabilities. Post the full code of the filters you added so I can see what you did.

    • This reply was modified 6 years, 8 months ago by jamiechong.
    Thread Starter vinnyegc

    (@vinnyegc)

    i just copied out the the user_can_revisionize() function from your gist, and added to it.

    function user_can_revisionize() {
      return apply_filters('revisionize_user_can_revisionize', current_user_can('edit_posts') || current_user_can('edit_pages') || current_user_can('edit_locations'));
    }
    Plugin Author jamiechong

    (@jamiechong)

    Sorry, that won’t work. I assumed you were a developer and knew how to add wordpress filters correctly.

    https://codex.www.ads-software.com/Plugin_API

    At this stage I can’t offer more assistance than this.

    Thread Starter vinnyegc

    (@vinnyegc)

    I do understand how filters work, but what logic would I need to write and hook to that filter to make it the submit for review button to show up instead of the update button.

    like I said if I give my custom role the edit_pages capability it works perfectly, but not on my CPT.

    This is what I need for CPT

    https://ibb.co/ny4KBo
    (Screenshot from Pages)

    Thread Starter vinnyegc

    (@vinnyegc)

    Also I failed to mention I did purchase the Contributor Can addon for this reason.

    Plugin Author jamiechong

    (@jamiechong)

    Regardless, the code you provided is dead wrong. That is not how to add a filter.

    You might be interested in this add-on https://revisionize.pro/downloads/contributors-can/

    However it still won’t work for your custom defined capabilities.

    Thread Starter vinnyegc

    (@vinnyegc)

    Yes I understand its wrong and I did buy that addon because it says it works with CPT but it doesnt seem like it does work with CPT the same way it does for Pages.

    Plugin Author jamiechong

    (@jamiechong)

    The problem shouldn’t be with the CPT – it sounds like you create custom capabilities? If so, this is likely the problem.

    Thread Starter vinnyegc

    (@vinnyegc)

    Its not a custom capability, it is the default capabilities for a CPT. If I set it to edit_locations (location being the slug of the custom post type) I can view but cant edit, if add the edit_published_locations I can edit, but I can not submit for review.

    However with Pages, if I give this role edit_pages, I can edit all pages (even published) and submit for review. It should work this way correct?

    Plugin Author jamiechong

    (@jamiechong)

    I will try to reproduce this on my dev system. How did you create your CPT? with code? Or with some other plugin? Please provide details.

    Thread Starter vinnyegc

    (@vinnyegc)

    Code.

    // Locations
    function location_cpt() {
    
    	$labels = array(
    		'name'                  => _x( 'Locations', 'Post Type General Name', 'granite' ),
    		'singular_name'         => _x( 'Location', 'Post Type Singular Name', 'granite' ),
    		'menu_name'             => __( 'Locations', 'granite' ),
    		'name_admin_bar'        => __( 'Location', 'granite' ),
    		'archives'              => __( 'Location Archives', 'granite' ),
    		'attributes'            => __( 'Location Attributes', 'granite' ),
    		'parent_item_colon'     => __( 'Parent Location:', 'granite' ),
    		'all_items'             => __( 'All Locations', 'granite' ),
    		'add_new_item'          => __( 'Add New Location', 'granite' ),
    		'add_new'               => __( 'Add New', 'granite' ),
    		'new_item'              => __( 'New Location', 'granite' ),
    		'edit_item'             => __( 'Edit Location', 'granite' ),
    		'update_item'           => __( 'Update Location', 'granite' ),
    		'view_item'             => __( 'View Location', 'granite' ),
    		'view_items'            => __( 'View Locations', 'granite' ),
    		'search_items'          => __( 'Search Location', 'granite' ),
    		'not_found'             => __( 'Not found', 'granite' ),
    		'not_found_in_trash'    => __( 'Not found in Trash', 'granite' ),
    		'featured_image'        => __( 'Featured Image', 'granite' ),
    		'set_featured_image'    => __( 'Set featured image', 'granite' ),
    		'remove_featured_image' => __( 'Remove featured image', 'granite' ),
    		'use_featured_image'    => __( 'Use as featured image', 'granite' ),
    		'insert_into_item'      => __( 'Insert into Location', 'granite' ),
    		'uploaded_to_this_item' => __( 'Uploaded to this Location', 'granite' ),
    		'items_list'            => __( 'Locations list', 'granite' ),
    		'items_list_navigation' => __( 'Locations list navigation', 'granite' ),
    		'filter_items_list'     => __( 'Filter locations list', 'granite' ),
    	);
    	$args = array(
    		'label'                 => __( 'Location', 'granite' ),
    		'description'           => __( 'All location information', 'granite' ),
    		'labels'                => $labels,
    		'supports'              => array( 'title', 'editor', 'page-attributes', 'author', 'revisions' ),
    		'hierarchical'          => true,
    		'public'                => true,
    		'show_ui'               => true,
    		'show_in_menu'          => true,
    		'menu_position'         => 10.2,
    		'menu_icon'             => 'dashicons-location',
    		'show_in_admin_bar'     => true,
    		'show_in_nav_menus'     => true,
    		'can_export'            => true,
    		'has_archive'           => 'locations',
    		'exclude_from_search'   => false,
    		'publicly_queryable'    => true,
    		'capability_type'       => 'page',
    		'show_in_rest'          => true,
    	);
    	register_post_type( 'location', $args );
    
    }
    add_action( 'init', 'location_cpt', 0 );

    I am using User Role Editor Pro plugin to control capabilities to my roles though.

    Plugin Author jamiechong

    (@jamiechong)

    Show me the caps set for location.

    Plugin Author jamiechong

    (@jamiechong)

    Without any caps overwritten by URE, everything is working fine on my end for a contributor making a revision and submitting it for review…

Viewing 15 replies - 1 through 15 (of 27 total)
  • The topic ‘Custom User Role and CPT’ is closed to new replies.