Ticket #12541: register_post_type_submenu_arg.diff
File register_post_type_submenu_arg.diff, 8.8 KB (added by , 14 years ago) |
---|
-
wp-includes/post.php
18 18 register_post_type( 'post', array( 'label' => __('Posts'), 19 19 'singular_label' => __('Post'), 20 20 'public' => true, 21 'show_ui' => false, 21 'show_ui' => true, 22 'menu_position' => 5, 22 23 '_builtin' => true, 23 24 '_edit_link' => 'post.php?post=%d', 24 25 'capability_type' => 'post', … … 31 32 register_post_type( 'page', array( 'label' => __('Pages'), 32 33 'singular_label' => __('Page'), 33 34 'public' => true, 34 'show_ui' => false, 35 'show_ui' => true, 36 'menu_position' => 20, 37 'menu_class' => 'menu-icon-pages', 35 38 '_builtin' => true, 36 39 '_edit_link' => 'post.php?post=%d', 37 40 'capability_type' => 'page', … … 43 46 44 47 register_post_type( 'attachment', array('label' => __('Media'), 45 48 'public' => true, 46 'show_ui' => false, 49 'show_ui' => true, 50 'menu_position' => 10, 51 'menu_class' => 'menu-icon-media', 47 52 '_builtin' => true, 48 53 '_edit_link' => 'media.php?attachment_id=%d', 49 54 'capability_type' => 'post', 50 55 'hierarchical' => false, 51 56 'rewrite' => false, 52 57 'query_var' => false, 58 'menu_slug' => 'upload.php', 59 'submenu' => array( 5 => array( 60 'menu_title' => __('Library'), 61 'capability' => 'upload_files', 62 'menu_slug' => 'upload.php', 63 ), 10 => array( 64 'menu_title' => _x('Add New', 'file'), 65 'capability' => 'upload_files', 66 'menu_slug' => 'media-new.php', 67 ), 68 ), 53 69 ) ); 54 70 55 71 register_post_type( 'revision', array( 'label' => __('Revisions'), … … 762 778 * exclude_from_search - Whether to exclude posts with this post type from search results. Defaults to true if the type is not public, false if the type is public. 763 779 * publicly_queryable - Whether post_type queries can be performed from the front page. Defaults to whatever public is set as. 764 780 * show_ui - Whether to generate a default UI for managing this post type. Defaults to true if the type is public, false if the type is not public. 781 * menu_position - The position in the menu order the post type should appear 782 * menu_class - The menu class to apply to the post type to allow for a custom icon. Defaults to the posts icon. 783 * menu_slug - The menu's page slug. Defaults to 'edit.php?post_type=%s'. 784 * submenu - Customize the submenu items for the post type. Defaults to Edit, and Add New. 765 785 * inherit_type - The post type from which to inherit the edit link and capability type. Defaults to none. 766 786 * capability_type - The post type to use for checking read, edit, and delete capabilities. Defaults to "post". 767 787 * edit_cap - The capability that controls editing a particular object of this post type. Defaults to "edit_$capability_type" (edit_post). … … 790 810 $wp_post_types = array(); 791 811 792 812 // Args prefixed with an underscore are reserved for internal use. 793 $defaults = array('label' => false, 'singular_label' => false, 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, 'rewrite' => true, 'query_var' => true, 'supports' => array(), 'register_meta_box_cb' => null, 'taxonomies' => array(), 'show_ui' => null ); 813 $defaults = array('label' => false, 'singular_label' => false, 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, 'rewrite' => true, 'query_var' => true, 'supports' => array(), 'register_meta_box_cb' => null, 'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_class' => null, 'menu_slug' => 'edit.php?post_type=%s' ); 814 815 $defaults['submenu'] = array( 816 5 => array( 817 'menu_title' => __('Edit'), 818 'capability' => 'edit_posts', 819 'menu_slug' => 'edit.php?post_type=%s', 820 ), 821 10 => array( 822 'menu_title' => _x('Add New', 'post'), 823 'capability' => 'edit_posts', 824 'menu_slug' => 'post-new.php?post_type=%s', 825 ), 826 ); 827 794 828 $args = wp_parse_args($args, $defaults); 795 829 $args = (object) $args; 796 830 -
wp-admin/menu.php
79 79 80 80 $menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' ); 81 81 82 $menu[5] = array( __('Posts'), 'edit_posts', 'edit.php', '', 'open-if-no-js menu-top menu-icon-posts', 'menu-posts', 'div' );83 $submenu['edit.php'][5] = array( __('Edit'), 'edit_posts', 'edit.php' );84 /* translators: add new post */85 $submenu['edit.php'][10] = array( _x('Add New', 'post'), 'edit_posts', 'post-new.php' );86 87 $i = 15;88 foreach ( $wp_taxonomies as $tax ) {89 if ( ! $tax->show_ui || ! in_array('post', (array) $tax->object_type, true) )90 continue;91 92 $submenu['edit.php'][$i++] = array( esc_attr($tax->label), $tax->manage_cap, 'edit-tags.php?taxonomy=' . $tax->name );93 }94 unset($tax);95 96 $menu[10] = array( __('Media'), 'upload_files', 'upload.php', '', 'menu-top menu-icon-media', 'menu-media', 'div' );97 $submenu['upload.php'][5] = array( __('Library'), 'upload_files', 'upload.php');98 /* translators: add new file */99 $submenu['upload.php'][10] = array( _x('Add New', 'file'), 'upload_files', 'media-new.php');100 101 82 $menu[15] = array( __('Links'), 'manage_links', 'link-manager.php', '', 'menu-top menu-icon-links', 'menu-links', 'div' ); 102 83 $submenu['link-manager.php'][5] = array( __('Edit'), 'manage_links', 'link-manager.php' ); 103 84 /* translators: add new links */ 104 85 $submenu['link-manager.php'][10] = array( _x('Add New', 'link'), 'manage_links', 'link-add.php' ); 105 86 $submenu['link-manager.php'][15] = array( __('Link Categories'), 'manage_categories', 'edit-link-categories.php' ); 106 87 107 $menu[20] = array( __('Pages'), 'edit_pages', 'edit.php?post_type=page', '', 'menu-top menu-icon-pages', 'menu-pages', 'div' );108 $submenu['edit.php?post_type=page'][5] = array( __('Edit'), 'edit_pages', 'edit.php?post_type=page' );109 /* translators: add new page */110 $submenu['edit.php?post_type=page'][10] = array( _x('Add New', 'page'), 'edit_pages', 'post-new.php?post_type=page' );111 112 88 $menu[25] = array( sprintf( __('Comments %s'), "<span id='awaiting-mod' class='count-$awaiting_mod'><span class='pending-count'>" . number_format_i18n($awaiting_mod) . "</span></span>" ), 'edit_posts', 'edit-comments.php', '', 'menu-top menu-icon-comments', 'menu-comments', 'div' ); 113 89 114 90 $_wp_last_object_menu = 25; // The index of the last top-level menu in the object menu group … … 117 93 $_wp_last_object_menu++; 118 94 $ptype_obj = get_post_type_object($ptype); 119 95 120 $menu[$_wp_last_object_menu] = array(esc_attr($ptype_obj->label), $ptype_obj->edit_type_cap, "edit.php?post_type=$ptype", '', 'menu-top menu-icon-posts', 'menu-' . sanitize_html_class($ptype), 'div'); 121 $submenu["edit.php?post_type=$ptype"][5] = array( __('Edit'), 'edit_posts', "edit.php?post_type=$ptype"); 122 /* translators: add new custom post type */ 123 $submenu["edit.php?post_type=$ptype"][10] = array( _x('Add New', 'post'), 'edit_posts', "post-new.php?post_type=$ptype" ); 96 $ptype_menu_position = is_int($ptype_obj->menu_position) ? $ptype_obj->menu_position : $_wp_last_object_menu; 97 $ptype_menu_class = is_string( $ptype_obj->menu_class ) ? $ptype_obj->menu_class : 'menu-icon-posts'; 98 99 $ptype_menu_slug = esc_url_raw( sprintf( $ptype_obj->menu_slug, $ptype ) ); 100 101 $menu[$ptype_menu_position] = array(esc_attr($ptype_obj->label), $ptype_obj->edit_type_cap, $ptype_menu_slug, '', 'menu-top ' . $ptype_menu_class, 'menu-' . sanitize_html_class($ptype), 'div'); 102 103 if ( is_array($ptype_obj->submenu) ) { 104 foreach ( $ptype_obj->submenu as $key => $_submenu ) { 105 $submenu[$ptype_menu_slug][$key] = array( $_submenu['menu_title'], $_submenu['capability'], sprintf( $_submenu['menu_slug'], $ptype ) ); 106 } 107 } 124 108 125 109 $i = 15; 126 110 foreach ( $wp_taxonomies as $tax ) { 127 111 if ( ! $tax->show_ui || ! in_array($ptype, (array) $tax->object_type, true) ) 128 112 continue; 129 113 130 $submenu[ "edit.php?post_type=$ptype"][$i++] = array( esc_attr($tax->label), $tax->manage_cap, "edit-tags.php?taxonomy=$tax->name&post_type=$ptype" );114 $submenu[$ptype_menu_slug][$i++] = array( esc_attr($tax->label), $tax->manage_cap, "edit-tags.php?taxonomy=$tax->name&post_type=$ptype" ); 131 115 } 132 116 } 133 unset($ptype, $ptype_obj );117 unset($ptype, $ptype_obj, $ptype_menu_position, $ptype_menu_class, $ptype_menu_slug); 134 118 135 119 $menu[59] = array( '', 'read', 'separator2', '', 'wp-menu-separator' ); 136 120