Changeset 33366
- Timestamp:
- 07/22/2015 08:28:03 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/customize-nav-menus.js
r33346 r33366 19 19 api.Menus.data = { 20 20 nonce: '', 21 itemTypes: { 22 taxonomies: {}, 23 postTypes: {} 24 }, 21 itemTypes: [], 25 22 l10n: {}, 26 23 menuItemTransport: 'postMessage', … … 281 278 282 279 // Render the template for each item by type. 283 _.each( api.Menus.data.itemTypes, function( typeObjects, type ) { 284 _.each( typeObjects, function( typeObject, slug ) { 285 if ( 'postTypes' === type ) { 286 type = 'post_type'; 287 } else if ( 'taxonomies' === type ) { 288 type = 'taxonomy'; 289 } 290 self.pages[ slug ] = 0; // @todo should prefix with type 291 self.loadItems( slug, type ); 292 } ); 280 _.each( api.Menus.data.itemTypes, function( itemType ) { 281 self.pages[ itemType.type + ':' + itemType.object ] = 0; 282 self.loadItems( itemType.type, itemType.object ); // @todo we need to combine these Ajax requests. 293 283 } ); 294 284 }, 295 285 296 286 // Load available menu items. 297 loadItems: function( type, obj _type) {298 var self = this, params, request, itemTemplate ;287 loadItems: function( type, object ) { 288 var self = this, params, request, itemTemplate, availableMenuItemContainer; 299 289 itemTemplate = wp.template( 'available-menu-item' ); 300 290 301 if ( 0 > self.pages[ type] ) {291 if ( -1 === self.pages[ type + ':' + object ] ) { 302 292 return; 303 293 } 304 $( '#available-menu-items-' + type + ' .accordion-section-title' ).addClass( 'loading' ); 294 availableMenuItemContainer = $( '#available-menu-items-' + type + '-' + object ); 295 availableMenuItemContainer.find( '.accordion-section-title' ).addClass( 'loading' ); 305 296 self.loading = true; 306 297 params = { … … 308 299 'wp_customize': 'on', 309 300 'type': type, 310 'obj _type': obj_type,311 'page': self.pages[ type ]301 'object': object, 302 'page': self.pages[ type + ':' + object ] 312 303 }; 313 304 request = wp.ajax.post( 'load-available-menu-items-customizer', params ); … … 317 308 items = data.items; 318 309 if ( 0 === items.length ) { 319 if ( 0 === self.pages[ type ] ) {320 $( '#available-menu-items-' + type )310 if ( 0 === self.pages[ type + ':' + object ] ) { 311 availableMenuItemContainer 321 312 .addClass( 'cannot-expand' ) 322 313 .removeClass( 'loading' ) … … 324 315 .prop( 'tabIndex', -1 ); 325 316 } 326 self.pages[ type ] = -1;317 self.pages[ type + ':' + object ] = -1; 327 318 return; 328 319 } 329 320 items = new api.Menus.AvailableItemCollection( items ); // @todo Why is this collection created and then thrown away? 330 321 self.collection.add( items.models ); 331 typeInner = $( '#available-menu-items-' + type + '.accordion-section-content' );332 items.each(function( menu _item ) {333 typeInner.append( itemTemplate( menu _item.attributes ) );322 typeInner = availableMenuItemContainer.find( '.accordion-section-content' ); 323 items.each(function( menuItem ) { 324 typeInner.append( itemTemplate( menuItem.attributes ) ); 334 325 }); 335 self.pages[ type ] = self.pages[ type ] +1;326 self.pages[ type + ':' + object ] += 1; 336 327 }); 337 328 request.fail(function( data ) { … … 341 332 }); 342 333 request.always(function() { 343 $( '#available-menu-items-' + type + '.accordion-section-title' ).removeClass( 'loading' );334 availableMenuItemContainer.find( '.accordion-section-title' ).removeClass( 'loading' ); 344 335 self.loading = false; 345 336 }); … … 1276 1267 1277 1268 control.params.el_classes = containerClasses.join( ' ' ); 1278 control.params.item_type_label = api.Menus.getTypeLabel( settingValue.type, settingValue.object );1269 control.params.item_type_label = settingValue.type_label; 1279 1270 control.params.item_type = settingValue.type; 1280 1271 control.params.url = settingValue.url; … … 2553 2544 2554 2545 /** 2555 * Given a menu item type & object, get the label associated with it.2556 *2557 * @param {string} type2558 * @param {string} object2559 * @return {string}2560 */2561 api.Menus.getTypeLabel = function( type, object ) {2562 var label,2563 data = api.Menus.data;2564 2565 if ( 'post_type' === type ) {2566 if ( data.itemTypes.postTypes[ object ] ) {2567 label = data.itemTypes.postTypes[ object ].label;2568 } else {2569 label = data.l10n.postTypeLabel;2570 }2571 } else if ( 'taxonomy' === type ) {2572 if ( data.itemTypes.taxonomies[ object ] ) {2573 label = data.itemTypes.taxonomies[ object ].label;2574 } else {2575 label = data.l10n.taxonomyTermLabel;2576 }2577 } else {2578 label = data.l10n.custom_label;2579 }2580 2581 return label;2582 };2583 2584 /**2585 2546 * Given a menu item ID, get the control associated with it. 2586 2547 * -
trunk/src/wp-includes/class-wp-customize-control.php
r33346 r33366 1740 1740 1741 1741 <div class="menu-item-actions description-thin submitbox"> 1742 <# if ( 'custom' != data.item_type && '' != data.original_title ) { #>1742 <# if ( ( 'post_type' === data.item_type || 'taxonomy' === data.item_type ) && '' !== data.original_title ) { #> 1743 1743 <p class="link-to-original"> 1744 1744 <?php printf( __( 'Original: %s' ), '<a class="original-link" href="{{ data.url }}">{{ data.original_title }}</a>' ); ?> -
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 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 --> -
trunk/src/wp-includes/class-wp-customize-setting.php
r33256 r33366 969 969 'post_type', 970 970 'to_ping', 971 'type_label',972 971 ); 973 972 foreach ( $irrelevant_properties as $property ) { … … 1144 1143 1145 1144 if ( ! isset( $post->type_label ) ) { 1146 $post->type_label = null; 1147 } 1145 if ( 'post_type' === $post->type ) { 1146 $object = get_post_type_object( $post->object ); 1147 if ( $object ) { 1148 $post->type_label = $object->labels->singular_name; 1149 } else { 1150 $post->type_label = $post->object; 1151 } 1152 } elseif ( 'taxonomy' == $post->type ) { 1153 $object = get_taxonomy( $post->object ); 1154 if ( $object ) { 1155 $post->type_label = $object->labels->singular_name; 1156 } else { 1157 $post->type_label = $post->object; 1158 } 1159 } else { 1160 $post->type_label = __( 'Custom Link' ); 1161 } 1162 } 1163 1148 1164 return $post; 1149 1165 } -
trunk/tests/phpunit/tests/ajax/CustomizeMenus.php
r33322 r33366 123 123 array( 124 124 'success' => false, 125 'data' => 'nav_menus_missing_ obj_type_or_type_parameter',125 'data' => 'nav_menus_missing_type_or_object_parameter', 126 126 ), 127 127 ), … … 173 173 array( 174 174 array( 175 'obj_type' => '',176 175 'type' => '', 176 'object' => '', 177 177 ), 178 178 array( 179 179 'success' => false, 180 'data' => 'nav_menus_missing_ obj_type_or_type_parameter',180 'data' => 'nav_menus_missing_type_or_object_parameter', 181 181 ), 182 182 ), … … 184 184 array( 185 185 array( 186 ' obj_type'=> '',187 ' type'=> 'post',186 'type' => '', 187 'object' => 'post', 188 188 ), 189 189 array( 190 190 'success' => false, 191 'data' => 'nav_menus_missing_ obj_type_or_type_parameter',191 'data' => 'nav_menus_missing_type_or_object_parameter', 192 192 ), 193 193 ), … … 195 195 array( 196 196 array( 197 ' obj_type'=> '',198 ' type'=> 'post',197 'type' => '', 198 'object' => 'post', 199 199 ), 200 200 array( 201 201 'success' => false, 202 'data' => 'nav_menus_missing_ obj_type_or_type_parameter',202 'data' => 'nav_menus_missing_type_or_object_parameter', 203 203 ), 204 204 ), … … 206 206 array( 207 207 array( 208 ' obj_type'=> 'post_type',209 ' type'=> 'invalid',208 'type' => 'post_type', 209 'object' => 'invalid', 210 210 ), 211 211 array( … … 260 260 array( 261 261 array( 262 ' obj_type'=> 'post_type',263 ' type'=> 'post',262 'type' => 'post_type', 263 'object' => 'post', 264 264 ), 265 265 true, … … 267 267 array( 268 268 array( 269 ' obj_type'=> 'post_type',270 ' type'=> 'page',269 'type' => 'post_type', 270 'object' => 'page', 271 271 ), 272 272 true, … … 274 274 array( 275 275 array( 276 ' obj_type'=> 'post_type',277 ' type'=> 'custom',276 'type' => 'post_type', 277 'object' => 'custom', 278 278 ), 279 279 false, … … 281 281 array( 282 282 array( 283 ' obj_type'=> 'taxonomy',284 ' type'=> 'post_tag',283 'type' => 'taxonomy', 284 'object' => 'post_tag', 285 285 ), 286 286 true, … … 364 364 array( 365 365 array( 366 ' obj_type'=> 'post_type',367 ' type'=> 'post',368 ), 369 ), 370 array( 371 array( 372 ' obj_type'=> 'post_type',373 ' type'=> 'page',374 ), 375 ), 376 array( 377 array( 378 ' obj_type'=> 'taxonomy',379 ' type'=> 'post_tag',366 'type' => 'post_type', 367 'object' => 'post', 368 ), 369 ), 370 array( 371 array( 372 'type' => 'post_type', 373 'object' => 'page', 374 ), 375 ), 376 array( 377 array( 378 'type' => 'taxonomy', 379 'object' => 'post_tag', 380 380 ), 381 381 ), -
trunk/tests/phpunit/tests/customize/nav-menu-item-setting.php
r32806 r33366 36 36 $wp_customize = null; 37 37 parent::clean_up_global_scope(); 38 } 39 40 /** 41 * Filter to add a custom menu item type label. 42 * 43 * @param object $menu_item Menu item. 44 * @return object 45 */ 46 function filter_type_label( $menu_item ) { 47 if ( 'custom_type' === $menu_item->type ) { 48 $menu_item->type_label = 'Custom Label'; 49 } 50 51 return $menu_item; 38 52 } 39 53 … … 207 221 208 222 /** 223 * Test value method with a custom object. 224 * 225 * @see WP_Customize_Nav_Menu_Item_Setting::value() 226 */ 227 function test_custom_type_label() { 228 do_action( 'customize_register', $this->wp_customize ); 229 add_filter( 'wp_setup_nav_menu_item', array( $this, 'filter_type_label' ) ); 230 231 $menu_id = wp_create_nav_menu( 'Menu' ); 232 $item_id = wp_update_nav_menu_item( $menu_id, 0, array( 233 'menu-item-type' => 'custom_type', 234 'menu-item-object' => 'custom_object', 235 'menu-item-title' => 'Cool beans', 236 'menu-item-status' => 'publish', 237 ) ); 238 239 $post = get_post( $item_id ); 240 $menu_item = wp_setup_nav_menu_item( $post ); 241 242 $setting_id = "nav_menu_item[$item_id]"; 243 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); 244 245 $value = $setting->value(); 246 $this->assertEquals( $menu_item->type_label, 'Custom Label' ); 247 $this->assertEquals( $menu_item->type_label, $value['type_label'] ); 248 } 249 250 /** 209 251 * Test value method returns zero for nav_menu_term_id when previewing a new menu. 210 252 * -
trunk/tests/phpunit/tests/customize/nav-menus.php
r33322 r33366 39 39 40 40 /** 41 * Filter to add custom menu item types. 42 * 43 * @param array $items Menu item types. 44 * @return array Menu item types. 45 */ 46 function filter_item_types( $items ) { 47 $items[] = array( 48 'title' => 'Custom', 49 'type' => 'custom_type', 50 'object' => 'custom_object', 51 ); 52 53 return $items; 54 } 55 56 /** 57 * Filter to add custom menu items. 58 * 59 * @param array $items The menu items. 60 * @param string $type The object type (e.g. taxonomy). 61 * @param string $object The object name (e.g. category). 62 * @return array Menu items. 63 */ 64 function filter_items( $items, $type, $object ) { 65 $items[] = array( 66 'id' => 'custom-1', 67 'title' => 'Cool beans', 68 'type' => $type, 69 'type_label' => 'Custom Label', 70 'object' => $object, 71 'url' => home_url( '/cool-beans/' ), 72 'classes' => 'custom-menu-item cool-beans', 73 ); 74 75 return $items; 76 } 77 78 /** 41 79 * Test constructor. 42 80 * … … 204 242 205 243 $items = $menus->load_available_items_query( 'taxonomy', 'category', 0 ); 244 $this->assertContains( $expected, $items ); 245 } 246 247 /** 248 * Test the load_available_items_query method returns custom item. 249 * 250 * @see WP_Customize_Nav_Menus::load_available_items_query() 251 */ 252 function test_load_available_items_query_returns_custom_item() { 253 add_filter( 'customize_nav_menu_available_item_types', array( $this, 'filter_item_types' ) ); 254 add_filter( 'customize_nav_menu_available_items', array( $this, 'filter_items' ), 10, 4 ); 255 $menus = new WP_Customize_Nav_Menus( $this->wp_customize ); 256 257 // Expected menu item array. 258 $expected = array( 259 'id' => 'custom-1', 260 'title' => 'Cool beans', 261 'type' => 'custom_type', 262 'type_label' => 'Custom Label', 263 'object' => 'custom_object', 264 'url' => home_url( '/cool-beans/' ), 265 'classes' => 'custom-menu-item cool-beans', 266 ); 267 268 $items = $menus->load_available_items_query( 'custom_type', 'custom_object', 0 ); 206 269 $this->assertContains( $expected, $items ); 207 270 } … … 362 425 363 426 $menus = new WP_Customize_Nav_Menus( $this->wp_customize ); 364 $expected = array( 365 'postTypes' => array( 366 'post' => array( 'label' => 'Post' ), 367 'page' => array( 'label' => 'Page' ), 368 ), 369 'taxonomies' => array( 370 'category' => array( 'label' => 'Category' ), 371 'post_tag' => array( 'label' => 'Tag' ), 372 ), 373 ); 427 428 $expected = array( 429 array( 'title' => 'Post', 'type' => 'post_type', 'object' => 'post' ), 430 array( 'title' => 'Page', 'type' => 'post_type', 'object' => 'page' ), 431 array( 'title' => 'Category', 'type' => 'taxonomy', 'object' => 'category' ), 432 array( 'title' => 'Tag', 'type' => 'taxonomy', 'object' => 'post_tag' ), 433 ); 434 374 435 if ( current_theme_supports( 'post-formats' ) ) { 375 $expected[ 'taxonomies']['post_format'] = array( 'label' => 'Format' );436 $expected[] = array( 'title' => 'Format', 'type' => 'taxonomy', 'object' => 'post_format' ); 376 437 } 438 377 439 $this->assertEquals( $expected, $menus->available_item_types() ); 378 440 379 441 register_taxonomy( 'wptests_tax', array( 'post' ), array( 'labels' => array( 'name' => 'Foo' ) ) ); 380 $expected = array( 381 'postTypes' => array( 382 'post' => array( 'label' => 'Post' ), 383 'page' => array( 'label' => 'Page' ), 384 ), 385 'taxonomies' => array( 386 'category' => array( 'label' => 'Category' ), 387 'post_tag' => array( 'label' => 'Tag' ), 388 'wptests_tax' => array( 'label' => 'Foo' ), 389 ), 390 ); 391 if ( current_theme_supports( 'post-formats' ) ) { 392 $wptests_tax = array_pop( $expected['taxonomies'] ); 393 $expected['taxonomies']['post_format'] = array( 'label' => 'Format' ); 394 $expected['taxonomies']['wptests_tax'] = $wptests_tax; 395 } 442 $expected[] = array( 'title' => 'Foo', 'type' => 'taxonomy', 'object' => 'wptests_tax' ); 443 396 444 $this->assertEquals( $expected, $menus->available_item_types() ); 445 446 $expected[] = array( 'title' => 'Custom', 'type' => 'custom_type', 'object' => 'custom_object' ); 447 448 add_filter( 'customize_nav_menu_available_item_types', array( $this, 'filter_item_types' ) ); 449 $this->assertEquals( $expected, $menus->available_item_types() ); 450 remove_filter( 'customize_nav_menu_available_item_types', array( $this, 'filter_item_types' ) ); 397 451 398 452 } … … 428 482 */ 429 483 function test_available_items_template() { 484 add_filter( 'customize_nav_menu_available_item_types', array( $this, 'filter_item_types' ) ); 430 485 do_action( 'customize_register', $this->wp_customize ); 431 486 $menus = new WP_Customize_Nav_Menus( $this->wp_customize ); … … 442 497 if ( $post_types ) { 443 498 foreach ( $post_types as $type ) { 444 $this->assertContains( 'available-menu-items-' . esc_attr( $type->name ), $template ); 445 $this->assertContains( '<h4 class="accordion-section-title">' . esc_html( $type->label ), $template ); 446 $this->assertContains( 'data-type="' . esc_attr( $type->name ) . '" data-obj_type="post_type"', $template ); 499 $this->assertContains( 'available-menu-items-post_type-' . esc_attr( $type->name ), $template ); 500 $this->assertContains( '<h4 class="accordion-section-title">' . esc_html( $type->labels->singular_name ), $template ); 501 $this->assertContains( 'data-type="post_type"', $template ); 502 $this->assertContains( 'data-object="' . esc_attr( $type->name ) . '"', $template ); 447 503 } 448 504 } … … 451 507 if ( $taxonomies ) { 452 508 foreach ( $taxonomies as $tax ) { 453 $this->assertContains( 'available-menu-items-' . esc_attr( $tax->name ), $template ); 454 $this->assertContains( '<h4 class="accordion-section-title">' . esc_html( $tax->label ), $template ); 455 $this->assertContains( 'data-type="' . esc_attr( $tax->name ) . '" data-obj_type="taxonomy"', $template ); 509 $this->assertContains( 'available-menu-items-taxonomy-' . esc_attr( $tax->name ), $template ); 510 $this->assertContains( '<h4 class="accordion-section-title">' . esc_html( $tax->labels->singular_name ), $template ); 511 $this->assertContains( 'data-type="taxonomy"', $template ); 512 $this->assertContains( 'data-object="' . esc_attr( $tax->name ) . '"', $template ); 456 513 } 457 514 } 515 516 $this->assertContains( 'available-menu-items-custom_type', $template ); 517 $this->assertContains( '<h4 class="accordion-section-title">Custom', $template ); 518 $this->assertContains( 'data-type="custom_type"', $template ); 519 $this->assertContains( 'data-object="custom_object"', $template ); 458 520 } 459 521
Note: See TracChangeset
for help on using the changeset viewer.