WordPress.org

Forums

[resolved] taxonomies custom post types for member not display (3 posts)

  1. Julien
    Member
    Posted 1 year ago #

    Hello,

    Im trying to create some custom post types inside a plugin and a member role with capabilities but maybe something wrong.

    So, I wrote this :

    if ( ! function_exists('voyages_type') ) {
    
    function voyages_type() {
    
    	$labels = array(
    		'name'                => _x( 'Voyages', 'Post Type General Name' ),
    		'singular_name'       => _x( 'Voyage', 'Post Type Singular Name' ),
    		'menu_name'           => __( 'Voyages' ),
    		'parent_item_colon'   => __( 'Parent Item:' ),
    		'all_items'           => __( 'All Items' ),
    		'view_item'           => __( 'View Item' ),
    		'add_new_item'        => __( 'Add New Item' ),
    		'add_new'             => __( 'Add New' ),
    		'edit_item'           => __( 'Edit Item' ),
    		'update_item'         => __( 'Update Item' ),
    		'search_items'        => __( 'Search Item' ),
    		'not_found'           => __( 'Not found' ),
    		'not_found_in_trash'  => __( 'Not found in Trash' ),
    	);
    	$rewrite = array(
    		'slug'                => 'voyages',
    		'with_front'          => true,
    		'pages'               => true,
    		'feeds'               => true,
    	);
    	$capabilities = array(
    		'edit_post'           => 'edit_voyage',
    		'read_post'           => 'read_voyage',
    		'delete_post'         => 'delete_voyage',
    		'edit_posts'          => 'edit_voyages',
    		'edit_others_posts'   => 'edit_others_voyages',
    		'publish_posts'       => 'publish_voyages',
    		'read_private_posts'  => 'read_private_voyages',
    	);
    	$args = array(
    		'label'               => __( 'voyage_post_type' ),
    		'description'         => __( 'Voyage Description' ),
    		'labels'              => $labels,
    		'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes', 'post-formats', ),
    		'taxonomies'          => array( 'category', 'post_tag' ),
    		'hierarchical'        => true,
    		'public'              => true,
    		'show_ui'             => true,
    		'show_in_menu'        => true,
    		'show_in_nav_menus'   => true,
    		'show_in_admin_bar'   => true,
    		'menu_position'       => 5,
    		'menu_icon'           => 'dashicons-admin-site',
    		'can_export'          => true,
    		'has_archive'         => true,
    		'exclude_from_search' => false,
    		'publicly_queryable'  => true,
    		'query_var'			  => true,
    		'rewrite'             => $rewrite,
    		'capabilities'        => $capabilities,
    		'capability_type'     => array("voyage", "voyages"),
    		'map_meta_cap'        => true,
    	);
    	register_post_type( 'voyage_post_type', $args );
    }
    add_action( 'init', 'voyages_type', 0 );
    
    }
    
    function add_voyages_caps_to_admin() {
    	$caps = array(
    		'read',
    		'read_voyages',
    		'read_private_voyages',
    		'edit_voyages',
    		'edit_private_voyages',
    		'edit_published_voyages',
    		'edit_others_voyages',
    		'publish_voyages',
    		'delete_voyages',
    		'delete_private_voyages',
    		'delete_published_voyages',
    		'delete_others_voyages',
    	);
    	$roles = array(
    		get_role( 'administrator' ),
    		get_role( 'editor' ),
    		get_role( 'contributor' ),
    		get_role( 'author' ),
    		get_role( 'client' ),
    	);
    	foreach ($roles as $role) {
    		foreach ($caps as $cap) {
    			$role->add_cap( $cap );
    		}
    	}
    }
    add_action( 'after_setup_theme', 'add_voyages_caps_to_admin' );

    The problem is :
    I can see like post, everything (category and tag) when im logging as ADMIN but when im logging as "client" role, I can'T see category and tag. I don't know why.

    SOmeone can help me please ?

    Thank you

  2. bcworkz
    Member
    Posted 1 year ago #

    The "client" role must have 'manage_categories' capability in order to access the category and tag admin screens. It is unrelated to what post type capabilities they may have. There is no default behavior where clients can simply view the screens and not manage the taxonomies.

  3. Julien
    Member
    Posted 1 year ago #

    thank you !

Topic Closed

This topic has been closed to new replies.

About this Topic