| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | /**
|
|---|
| 4 | * Menu management issue
|
|---|
| 5 | *
|
|---|
| 6 | * When registering:
|
|---|
| 7 | * a post type, that the current user has no rights to manage
|
|---|
| 8 | * a custom taxonomy for that custom post type, that the current user has rights to manage
|
|---|
| 9 | * then the taxonomy that the current user can manage is not generating an admin menu entry.
|
|---|
| 10 | * If you add another taxonomy to that post type which the current user can manage, the admin menu is generated.
|
|---|
| 11 | *
|
|---|
| 12 | * See note at the end of ek_register_objects() for details on how to test.
|
|---|
| 13 | */
|
|---|
| 14 |
|
|---|
| 15 | function ek_register_objects() {
|
|---|
| 16 |
|
|---|
| 17 | $labels_cpt = array(
|
|---|
| 18 | 'name' => _x( 'Post Types', 'Post Type General Name', 'text_domain' ),
|
|---|
| 19 | 'singular_name' => _x( 'Post Type', 'Post Type Singular Name', 'text_domain' ),
|
|---|
| 20 | 'menu_name' => __( 'Post Types', 'text_domain' ),
|
|---|
| 21 | 'name_admin_bar' => __( 'Post Type', 'text_domain' ),
|
|---|
| 22 | 'archives' => __( 'Item Archives', 'text_domain' ),
|
|---|
| 23 | 'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),
|
|---|
| 24 | 'all_items' => __( 'All Items', 'text_domain' ),
|
|---|
| 25 | 'add_new_item' => __( 'Add New Item', 'text_domain' ),
|
|---|
| 26 | 'add_new' => __( 'Add New', 'text_domain' ),
|
|---|
| 27 | 'new_item' => __( 'New Item', 'text_domain' ),
|
|---|
| 28 | 'edit_item' => __( 'Edit Item', 'text_domain' ),
|
|---|
| 29 | 'update_item' => __( 'Update Item', 'text_domain' ),
|
|---|
| 30 | 'view_item' => __( 'View Item', 'text_domain' ),
|
|---|
| 31 | 'search_items' => __( 'Search Item', 'text_domain' ),
|
|---|
| 32 | 'not_found' => __( 'Not found', 'text_domain' ),
|
|---|
| 33 | 'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),
|
|---|
| 34 | 'featured_image' => __( 'Featured Image', 'text_domain' ),
|
|---|
| 35 | 'set_featured_image' => __( 'Set featured image', 'text_domain' ),
|
|---|
| 36 | 'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
|
|---|
| 37 | 'use_featured_image' => __( 'Use as featured image', 'text_domain' ),
|
|---|
| 38 | 'insert_into_item' => __( 'Insert into item', 'text_domain' ),
|
|---|
| 39 | 'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),
|
|---|
| 40 | 'items_list' => __( 'Items list', 'text_domain' ),
|
|---|
| 41 | 'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
|
|---|
| 42 | 'filter_items_list' => __( 'Filter items list', 'text_domain' ),
|
|---|
| 43 | );
|
|---|
| 44 | $capabilities_cpt = array(
|
|---|
| 45 | 'edit_post' => 'edit_ekpost',
|
|---|
| 46 | 'read_post' => 'read_ekpost',
|
|---|
| 47 | 'delete_post' => 'delete_ekpost',
|
|---|
| 48 | 'edit_posts' => 'edit_ekposts',
|
|---|
| 49 | 'edit_others_posts' => 'edit_others_ekposts',
|
|---|
| 50 | 'publish_posts' => 'publish_ekposts',
|
|---|
| 51 | 'read_private_posts' => 'read_private_ekposts',
|
|---|
| 52 | );
|
|---|
| 53 | $args_cpt = array(
|
|---|
| 54 | 'label' => __( 'Post Type', 'text_domain' ),
|
|---|
| 55 | 'description' => __( 'Post Type Description', 'text_domain' ),
|
|---|
| 56 | 'labels' => $labels_cpt,
|
|---|
| 57 | 'supports' => array( ),
|
|---|
| 58 | 'hierarchical' => false,
|
|---|
| 59 | 'public' => true,
|
|---|
| 60 | 'show_ui' => true,
|
|---|
| 61 | 'show_in_menu' => true,
|
|---|
| 62 | 'menu_position' => 5,
|
|---|
| 63 | 'show_in_admin_bar' => true,
|
|---|
| 64 | 'show_in_nav_menus' => true,
|
|---|
| 65 | 'can_export' => true,
|
|---|
| 66 | 'has_archive' => true,
|
|---|
| 67 | 'exclude_from_search' => false,
|
|---|
| 68 | 'publicly_queryable' => true,
|
|---|
| 69 | 'capabilities' => $capabilities_cpt,
|
|---|
| 70 | );
|
|---|
| 71 |
|
|---|
| 72 | $labels_ct_one = array(
|
|---|
| 73 | 'name' => _x( 'Taxonomies One', 'Taxonomy General Name', 'text_domain' ),
|
|---|
| 74 | 'singular_name' => _x( 'Taxonomy One', 'Taxonomy Singular Name', 'text_domain' ),
|
|---|
| 75 | 'menu_name' => __( 'Taxonomy One', 'text_domain' ),
|
|---|
| 76 | 'all_items' => __( 'All Items', 'text_domain' ),
|
|---|
| 77 | 'parent_item' => __( 'Parent Item', 'text_domain' ),
|
|---|
| 78 | 'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),
|
|---|
| 79 | 'new_item_name' => __( 'New Item Name', 'text_domain' ),
|
|---|
| 80 | 'add_new_item' => __( 'Add New Item', 'text_domain' ),
|
|---|
| 81 | 'edit_item' => __( 'Edit Item', 'text_domain' ),
|
|---|
| 82 | 'update_item' => __( 'Update Item', 'text_domain' ),
|
|---|
| 83 | 'view_item' => __( 'View Item', 'text_domain' ),
|
|---|
| 84 | 'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ),
|
|---|
| 85 | 'add_or_remove_items' => __( 'Add or remove items', 'text_domain' ),
|
|---|
| 86 | 'choose_from_most_used' => __( 'Choose from the most used', 'text_domain' ),
|
|---|
| 87 | 'popular_items' => __( 'Popular Items', 'text_domain' ),
|
|---|
| 88 | 'search_items' => __( 'Search Items', 'text_domain' ),
|
|---|
| 89 | 'not_found' => __( 'Not Found', 'text_domain' ),
|
|---|
| 90 | 'no_terms' => __( 'No items', 'text_domain' ),
|
|---|
| 91 | 'items_list' => __( 'Items list', 'text_domain' ),
|
|---|
| 92 | 'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
|
|---|
| 93 | );
|
|---|
| 94 | $args_ct_one = array(
|
|---|
| 95 | 'labels' => $labels_ct_one,
|
|---|
| 96 | 'hierarchical' => false,
|
|---|
| 97 | 'public' => true,
|
|---|
| 98 | 'show_ui' => true,
|
|---|
| 99 | 'show_admin_column' => true,
|
|---|
| 100 | 'show_in_nav_menus' => true,
|
|---|
| 101 | 'show_tagcloud' => true,
|
|---|
| 102 | );
|
|---|
| 103 |
|
|---|
| 104 | $labels_ct_two = array(
|
|---|
| 105 | 'name' => _x( 'Taxonomies Two', 'Taxonomy General Name', 'text_domain' ),
|
|---|
| 106 | 'singular_name' => _x( 'Taxonomy Two', 'Taxonomy Singular Name', 'text_domain' ),
|
|---|
| 107 | 'menu_name' => __( 'Taxonomy Two', 'text_domain' ),
|
|---|
| 108 | 'all_items' => __( 'All Items', 'text_domain' ),
|
|---|
| 109 | 'parent_item' => __( 'Parent Item', 'text_domain' ),
|
|---|
| 110 | 'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),
|
|---|
| 111 | 'new_item_name' => __( 'New Item Name', 'text_domain' ),
|
|---|
| 112 | 'add_new_item' => __( 'Add New Item', 'text_domain' ),
|
|---|
| 113 | 'edit_item' => __( 'Edit Item', 'text_domain' ),
|
|---|
| 114 | 'update_item' => __( 'Update Item', 'text_domain' ),
|
|---|
| 115 | 'view_item' => __( 'View Item', 'text_domain' ),
|
|---|
| 116 | 'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ),
|
|---|
| 117 | 'add_or_remove_items' => __( 'Add or remove items', 'text_domain' ),
|
|---|
| 118 | 'choose_from_most_used' => __( 'Choose from the most used', 'text_domain' ),
|
|---|
| 119 | 'popular_items' => __( 'Popular Items', 'text_domain' ),
|
|---|
| 120 | 'search_items' => __( 'Search Items', 'text_domain' ),
|
|---|
| 121 | 'not_found' => __( 'Not Found', 'text_domain' ),
|
|---|
| 122 | 'no_terms' => __( 'No items', 'text_domain' ),
|
|---|
| 123 | 'items_list' => __( 'Items list', 'text_domain' ),
|
|---|
| 124 | 'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
|
|---|
| 125 | );
|
|---|
| 126 | $args_ct_two = array(
|
|---|
| 127 | 'labels' => $labels_ct_two,
|
|---|
| 128 | 'hierarchical' => false,
|
|---|
| 129 | 'public' => true,
|
|---|
| 130 | 'show_ui' => true,
|
|---|
| 131 | 'show_admin_column' => true,
|
|---|
| 132 | 'show_in_nav_menus' => true,
|
|---|
| 133 | 'show_tagcloud' => true,
|
|---|
| 134 | );
|
|---|
| 135 |
|
|---|
| 136 | /**
|
|---|
| 137 | * Try the following combinations with a user with editor role visiting the backend:
|
|---|
| 138 | * Registering the post type and taxonomy ek_tax_one displays no admin menu for any registered item.
|
|---|
| 139 | * It should register an admin menu for ek_tax_one
|
|---|
| 140 | * You can always access the admin page for managing terms directly on /wp-admin/edit-tags.php?taxonomy=ek_tax_one&post_type=ek_post_type
|
|---|
| 141 | * Registering the post type and taxonomies ek_tax_one and ek_tax_two displays an admin menu for any registered item
|
|---|
| 142 | */
|
|---|
| 143 |
|
|---|
| 144 | register_post_type( 'ek_post_type', $args_cpt );
|
|---|
| 145 | register_taxonomy( 'ek_tax_one', array( 'ek_post_type' ), $args_ct_one );
|
|---|
| 146 | //register_taxonomy( 'ek_tax_two', array( 'ek_post_type' ), $args_ct_two );
|
|---|
| 147 |
|
|---|
| 148 | }
|
|---|
| 149 | add_action( 'init', 'ek_register_objects', 0 );
|
|---|