• Resolved luciendub

    (@luciendub)


    I want to allow a specific user role (and administrators) to edit their own custom post type.

    I created my functions. Actually Administrator seems to have a full-access while the new role doesn’t have any access (can’t see the menu item nor access the wp-admin/edit.php?post_type=membres url)

    // Register Custom Post Type
    	function custom_membres() {
    
    		$capabilities = array(
    		 'publish_posts' => 'publish_membres',
    		 'edit_posts' => 'edit_membres',
    		 'edit_others_posts' => 'edit_others_membres',
    		 'delete_posts' => 'delete_membres',
    		 'delete_others_posts' => 'delete_others_membres',
    		 'read_private_posts' => 'read_private_membres',
    		 'edit_post' => 'edit_membres',
    		 'delete_post' => 'delete_membres',
    		 'read_post' => 'read_membres'
    		);
    
    		$labels = array(
    			'name'                => 'Membres',
    			'singular_name'       => 'Membre',
    			'menu_name'           => 'Membres',
    			'name_admin_bar'      => 'Membres',
    			'parent_item_colon'   => 'Item parent:',
    			'all_items'           => 'Tous les membres',
    			'add_new_item'        => 'Ajouter',
    			'add_new'             => 'Ajouter',
    			'new_item'            => 'Nouveau',
    			'edit_item'           => 'Modifier',
    			'update_item'         => 'Mettre à jour',
    			'view_item'           => 'Voir',
    			'search_items'        => 'Recherche',
    			'not_found'           => 'Rien trouvé',
    			'not_found_in_trash'  => 'Rien trouvé',
    		);
    		$args = array(
    			'label'               => 'Membre',
    			'description'         => 'Tous les membres',
    			'labels'              => $labels,
    			'supports'            => array( 'title', 'editor', 'author'),
    			'taxonomies'          => array(  ),
    			'hierarchical'        => true,
    			'public'              => true,
    			'show_ui'             => true,
    			'show_in_menu'        => true,
    			'menu_position'       => 5,
    			'menu_icon'           => 'dashicons-universal-access',
    			'show_in_admin_bar'   => true,
    			'show_in_nav_menus'   => true,
    			'can_export'          => true,
    			'has_archive'         => true,
    			'exclude_from_search' => false,
    			'publicly_queryable'  => true,
    			'capability_type' => 'membres',
    	        'capabilities' => $capabilities,
    
    		);
    		register_post_type( 'membres', $args );
    
    	}
    	add_action( 'init', 'custom_membres', 0 );
    
    	// Ajout des r?les et permissions pour les membres
    	add_action('admin_init','membres_add_gestionnairemembre_role',999);
    	function membres_add_gestionnairemembre_role() {
    	 add_role('gestionnairemembre',
    	          'Administrateur des membres',
    		    array(
    		        'publish_membres' => true,
    		        'edit_membres' => true,
    		        'edit_others_membres' => true,
    		        'delete_membres' => true,
    		        'delete_others_membres' => true,
    		        'read_private_membres' => true,
    		        'edit_membres' => true,
    		        'delete_membres' => true,
    		        'read_membres' => true,
    		    )
    	    );
    	}

    What should I modify?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Assign capabilities to a new role for a custom post type’ is closed to new replies.