WordPress.org

Make WordPress Core

Ticket #14145: 14145.diff

File 14145.diff, 4.1 KB (added by nacin, 4 years ago)
  • wp-includes/post.php

     
    778778 * - 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. 
    779779 * - publicly_queryable - Whether post_type queries can be performed from the front page.  Defaults to whatever public is set as. 
    780780 * - 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 * - show_in_menu - Where to show the post type in the admin menu. True for a top level menu, false for no menu, or can be a top level page like 'tools.php' or 'edit.php?post_type='post'. Post type must be show_ui. 
    781782 * - menu_position - The position in the menu order the post type should appear. Defaults to the bottom. 
    782783 * - menu_icon - The url to the icon to be used for this menu. Defaults to use the posts icon. 
    783784 * - capability_type - The post type to use for checking read, edit, and delete capabilities. Defaults to "post". 
     
    814815                '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'capabilities' => array(), 'hierarchical' => false, 
    815816                'public' => false, 'rewrite' => true, 'query_var' => true, 'supports' => array(), 'register_meta_box_cb' => null, 
    816817                'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null, 
    817                 'permalink_epmask' => EP_PERMALINK, 'can_export' => true, 'show_in_nav_menus' => null 
     818                'permalink_epmask' => EP_PERMALINK, 'can_export' => true, 'show_in_nav_menus' => null, 'show_in_menu' => null, 
    818819        ); 
    819820        $args = wp_parse_args($args, $defaults); 
    820821        $args = (object) $args; 
     
    830831        if ( null === $args->show_ui ) 
    831832                $args->show_ui = $args->public; 
    832833 
     834        // If not set, default to the setting for show_ui. 
     835        if ( null === $args->show_in_menu ) 
     836                $args->show_in_menu = $args->show_ui; 
     837 
    833838        // Whether to show this type in nav-menus.php.  Defaults to the setting for public. 
    834839        if ( null === $args->show_in_nav_menus ) 
    835840                $args->show_in_nav_menus = $args->public; 
     
    963968 * Builds an object with custom-something object (post type, taxonomy) labels out of a custom-something object 
    964969 * 
    965970 * @access private 
     971 * @since 3.0.0 
    966972 */ 
    967973function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) { 
    968974 
     
    978984} 
    979985 
    980986/** 
     987 * Adds submenus for post types. 
     988 * 
     989 * @access private 
     990 * @since 3.0.0 
     991 */  
     992function _add_post_type_submenus() { 
     993        foreach ( get_post_types( array( 'show_ui' => true ) ) as $ptype ) { 
     994                $ptype_obj = get_post_type_object( $ptype ); 
     995                // Submenus only. 
     996                if ( ! $ptype_obj->show_in_menu || $ptype_obj->show_in_menu === true ) 
     997                        continue; 
     998                add_submenu_page( $ptype_obj->show_in_menu, $ptype_obj->labels->name, $ptype_obj->labels->name, $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype" ); 
     999        } 
     1000} 
     1001add_action( 'admin_menu', '_add_post_type_submenus' ); 
     1002 
     1003/** 
    9811004 * Register support of certain features for a post type. 
    9821005 * 
    9831006 * All features are directly associated with a functional area of the edit screen, such as the 
  • wp-admin/menu.php

     
    121121 
    122122$_wp_last_object_menu = 25; // The index of the last top-level menu in the object menu group 
    123123 
    124 foreach ( (array) get_post_types( array('show_ui' => true, '_builtin' => false) ) as $ptype ) { 
     124foreach ( (array) get_post_types( array('show_ui' => true, '_builtin' => false, 'show_in_menu' => true ) ) as $ptype ) { 
    125125        $ptype_obj = get_post_type_object( $ptype ); 
     126        // Check if it should be a submenu. 
     127        if ( $ptype_obj->show_in_menu !== true ) 
     128                continue; 
    126129        $ptype_menu_position = is_int( $ptype_obj->menu_position ) ? $ptype_obj->menu_position : ++$_wp_last_object_menu; // If we're to use $_wp_last_object_menu, increment it first. 
    127130        $ptype_for_id = sanitize_html_class( $ptype ); 
    128131        if ( is_string( $ptype_obj->menu_icon ) ) {