Changeset 33366 for trunk/src/wp-includes/class-wp-customize-nav-menus.php
- Timestamp:
- 07/22/2015 08:28:03 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-customize-nav-menus.php
r33346 r33366 76 76 } 77 77 78 if ( empty( $_POST[' obj_type'] ) || empty( $_POST['type'] ) ) {79 wp_send_json_error( 'nav_menus_missing_ obj_type_or_type_parameter' );80 } 81 82 $ obj_type = sanitize_key( $_POST['obj_type'] );83 $obj _name = sanitize_key( $_POST['type'] );78 if ( empty( $_POST['type'] ) || empty( $_POST['object'] ) ) { 79 wp_send_json_error( 'nav_menus_missing_type_or_object_parameter' ); 80 } 81 82 $type = sanitize_key( $_POST['type'] ); 83 $object = sanitize_key( $_POST['object'] ); 84 84 $page = empty( $_POST['page'] ) ? 0 : absint( $_POST['page'] ); 85 $items = $this->load_available_items_query( $ obj_type, $obj_name, $page );85 $items = $this->load_available_items_query( $type, $object, $page ); 86 86 87 87 if ( is_wp_error( $items ) ) { … … 98 98 * @access public 99 99 * 100 * @param string $ obj_typeOptional. Accepts any custom object type and has built-in support for100 * @param string $type Optional. Accepts any custom object type and has built-in support for 101 101 * 'post_type' and 'taxonomy'. Default is 'post_type'. 102 * @param string $obj _nameOptional. Accepts any registered taxonomy or post type name. Default is 'page'.103 * @param int $page Optional. The page number used to generate the query offset. Default is '0'.102 * @param string $object Optional. Accepts any registered taxonomy or post type name. Default is 'page'. 103 * @param int $page Optional. The page number used to generate the query offset. Default is '0'. 104 104 * @return WP_Error|array Returns either a WP_Error object or an array of menu items. 105 105 */ 106 public function load_available_items_query( $ obj_type = 'post_type', $obj_name= 'page', $page = 0 ) {106 public function load_available_items_query( $type = 'post_type', $object = 'page', $page = 0 ) { 107 107 $items = array(); 108 108 109 if ( 'post_type' === $ obj_type ) {110 if ( ! get_post_type_object( $obj _name) ) {109 if ( 'post_type' === $type ) { 110 if ( ! get_post_type_object( $object ) ) { 111 111 return new WP_Error( 'nav_menus_invalid_post_type' ); 112 112 } 113 113 114 if ( 0 === $page && 'page' === $obj _name) {114 if ( 0 === $page && 'page' === $object ) { 115 115 // Add "Home" link. Treat as a page, but switch to custom on add. 116 116 $items[] = array( … … 129 129 'orderby' => 'date', 130 130 'order' => 'DESC', 131 'post_type' => $obj _name,131 'post_type' => $object, 132 132 ) ); 133 133 foreach ( $posts as $post ) { … … 147 147 ); 148 148 } 149 } elseif ( 'taxonomy' === $ obj_type ) {150 $terms = get_terms( $obj _name, array(149 } elseif ( 'taxonomy' === $type ) { 150 $terms = get_terms( $object, array( 151 151 'child_of' => 0, 152 152 'exclude' => '', … … 176 176 } 177 177 } 178 179 /** 180 * Filter the available menu items. 181 * 182 * @since 4.3.0 183 * 184 * @param array $items The array of menu items. 185 * @param string $type The object type. 186 * @param string $object The object name. 187 * @param int $page The current page number. 188 */ 189 $items = apply_filters( 'customize_nav_menu_available_items', $items, $type, $object, $page ); 178 190 179 191 return $items; … … 589 601 * @since 4.3.0 590 602 * @access public 603 * 604 * @return array The available menu item types. 591 605 */ 592 606 public function available_item_types() { 593 $items = array( 594 'postTypes' => array(), 595 'taxonomies' => array(), 596 ); 607 $item_types = array(); 597 608 598 609 $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' ); 599 foreach ( $post_types as $slug => $post_type ) { 600 $items['postTypes'][ $slug ] = array( 601 'label' => $post_type->labels->singular_name, 602 ); 610 if ( $post_types ) { 611 foreach ( $post_types as $slug => $post_type ) { 612 $item_types[] = array( 613 'title' => $post_type->labels->singular_name, 614 'type' => 'post_type', 615 'object' => $post_type->name, 616 ); 617 } 603 618 } 604 619 605 620 $taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'objects' ); 606 foreach ( $taxonomies as $slug => $taxonomy ) { 607 if ( 'post_format' === $taxonomy && ! current_theme_supports( 'post-formats' ) ) { 608 continue; 609 } 610 $items['taxonomies'][ $slug ] = array( 611 'label' => $taxonomy->labels->singular_name, 612 ); 613 } 614 return $items; 621 if ( $taxonomies ) { 622 foreach ( $taxonomies as $slug => $taxonomy ) { 623 if ( 'post_format' === $taxonomy && ! current_theme_supports( 'post-formats' ) ) { 624 continue; 625 } 626 $item_types[] = array( 627 'title' => $taxonomy->labels->singular_name, 628 'type' => 'taxonomy', 629 'object' => $taxonomy->name, 630 ); 631 } 632 } 633 634 /** 635 * Filter the available menu item types. 636 * 637 * @since 4.3.0 638 * 639 * @param array $item_types Custom menu item types. 640 */ 641 $item_types = apply_filters( 'customize_nav_menu_available_item_types', $item_types ); 642 643 return $item_types; 615 644 } 616 645 … … 717 746 </div> 718 747 <?php 719 720 // @todo: consider using add_meta_box/do_accordion_section and making screen-optional?721 748 // Containers for per-post-type item browsing; items added with JS. 722 $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'object' ); 723 if ( $post_types ) : 724 foreach ( $post_types as $type ) : 725 ?> 726 <div id="available-menu-items-<?php echo esc_attr( $type->name ); ?>" class="accordion-section"> 727 <h4 class="accordion-section-title"><?php echo esc_html( $type->label ); ?> <span class="spinner"></span> <span class="no-items"><?php _e( 'No items' ); ?></span> <button type="button" class="not-a-button"><span class="screen-reader-text"><?php _e( 'Toggle' ); ?></span></button></h4> 728 <ul class="accordion-section-content" data-type="<?php echo esc_attr( $type->name ); ?>" data-obj_type="post_type"></ul> 729 </div> 749 foreach ( $this->available_item_types() as $available_item_type ) { 750 $id = sprintf( 'available-menu-items-%s-%s', $available_item_type['type'], $available_item_type['object'] ); 751 ?> 752 <div id="<?php echo esc_attr( $id ); ?>" class="accordion-section"> 753 <h4 class="accordion-section-title"><?php echo esc_html( $available_item_type['title'] ); ?> <span class="no-items"><?php _e( 'No items' ); ?></span><span class="spinner"></span> <button type="button" class="not-a-button"><span class="screen-reader-text"><?php _e( 'Toggle' ); ?></span></button></h4> 754 <ul class="accordion-section-content" data-type="<?php echo esc_attr( $available_item_type['type'] ); ?>" data-object="<?php echo esc_attr( $available_item_type['object'] ); ?>"></ul> 755 </div> 730 756 <?php 731 endforeach; 732 endif; 733 734 $taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'object' ); 735 if ( $taxonomies ) : 736 foreach ( $taxonomies as $tax ) : 737 ?> 738 <div id="available-menu-items-<?php echo esc_attr( $tax->name ); ?>" class="accordion-section"> 739 <h4 class="accordion-section-title"><?php echo esc_html( $tax->label ); ?> <span class="spinner"></span> <span class="no-items"><?php _e( 'No items' ); ?></span> <button type="button" class="not-a-button"><span class="screen-reader-text"><?php _e( 'Toggle' ); ?></span></button></h4> 740 <ul class="accordion-section-content" data-type="<?php echo esc_attr( $tax->name ); ?>" data-obj_type="taxonomy"></ul> 741 </div> 742 <?php 743 endforeach; 744 endif; 757 } 745 758 ?> 746 759 </div><!-- #available-menu-items -->
Note: See TracChangeset
for help on using the changeset viewer.