WordPress.org

Ready to get started?Download WordPress

Forums

Edit role capabilities for multiple custom post types (1 post)

  1. kristinachilds
    Member
    Posted 1 year ago #

    I was able to get the first CPT registered and added to administrator and editor roles, but for some reason doing the same thing for a 2nd CPT isn't working and I can't figure out why.

    The registration

    function register_clubs_post_type() {
      $labels = array(
        'name' => __( 'clubs' ),
        'singular_name' => __( 'club' ),
        'add_new' => __( 'Add club','club' ),
        'add_new_item' => __( 'Add New club' ),
        'edit_item' => __( 'Edit club' ),
        'new_item' => __( 'New club' ),
        'view_item' => __( 'View club' ),
        'search_items' => __( 'Search clubs' ),
        'not_found' => __( 'No clubs Found' ),
        'not_found_in_trash' => __( 'No clubs In Trash' ),
        'parent_item_colon' => ''
      );
    
      $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'has_archive' => true,
        'supports' => array( 'title','editor','excerpt','custom-fields','thumbnail' ),
        'rewrite' => array('slug' => 'clubs','with_front' => false),
        'hierarchical' => false,
        'capability_type' => 'clubs',
        'map_meta_cap' => true
      ); 
    
      register_post_type( 'clubs', $args );
    }
    add_action( 'init', 'register_clubs_post_type',0 );

    The role editor of the old CPT that worked like a charm

    if ( is_admin() && '1' == $_GET['reload_caps'] ) {
    		$administrator     = get_role('administrator');
    		$artists_relations = get_role('artists_relations');
    		$editor = get_role('editor');
    
    		$administrator->add_cap( 'assign_custom_taxes' );
    		$artists_relations->add_cap( 'assign_custom_taxes' );
    		$editor->add_cap( 'assign_custom_taxes' );
    
    		foreach ( array('publish','delete','delete_others','delete_private','delete_published','edit','edit_others','edit_private','edit_published','read','read_private',"manage_categories") as $cap ) {
    			$administrator->add_cap('{$cap}_artists' );
    			$artists_relations->add_cap( '{$cap}_artists');
    			$editor->add_cap( '{$cap}_artists' );
    		}

    Modified for this new registration (artist removed completely)

    foreach ( array('publish','delete','delete_others','delete_private','delete_published','edit','edit_others','edit_private','edit_published','read','read_private',"manage_categories") as $cap ) {
    			$administrator->add_cap('{$cap}_clubs' );
    			$artists_relations->add_cap( '{$cap}_clubs');
    			$editor->add_cap( '{$cap}_clubs' );
    		}

    Why would one work and the other doesn't? Does anyone know how I can get the roles edited for this CPT?

    If i comment out the capability_type line it shows up just fine, but with it active no role can see it.

Topic Closed

This topic has been closed to new replies.

About this Topic