Changeset 39138
- Timestamp:
- 11/04/2016 07:23:49 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/customize-nav-menus.js
r39137 r39138 303 303 $section.addClass( 'loading' ); 304 304 self.loading = true; 305 params = { 305 306 params = api.previewer.query( { excludeCustomizedSaved: true } ); 307 _.extend( params, { 306 308 'customize-menus-nonce': api.settings.nonce['customize-menus'], 307 309 'wp_customize': 'on', 308 310 'search': self.searchTerm, 309 311 'page': page 310 } ;312 } ); 311 313 312 314 self.currentRequest = wp.ajax.post( 'search-available-menu-items-customizer', params ); … … 379 381 */ 380 382 loadItems: function( itemTypes, deprecated ) { 381 var self = this, _itemTypes, requestItemTypes = [], request, itemTemplate, availableMenuItemContainers = {};383 var self = this, _itemTypes, requestItemTypes = [], params, request, itemTemplate, availableMenuItemContainers = {}; 382 384 itemTemplate = wp.template( 'available-menu-item' ); 383 385 … … 409 411 410 412 self.loading = true; 411 request = wp.ajax.post( 'load-available-menu-items-customizer', { 413 414 params = api.previewer.query( { excludeCustomizedSaved: true } ); 415 _.extend( params, { 412 416 'customize-menus-nonce': api.settings.nonce['customize-menus'], 413 417 'wp_customize': 'on', 414 418 'item_types': requestItemTypes 415 419 } ); 420 421 request = wp.ajax.post( 'load-available-menu-items-customizer', params ); 416 422 417 423 request.done(function( data ) { -
trunk/src/wp-includes/class-wp-customize-nav-menus.php
r39137 r39138 175 175 } 176 176 177 $posts = get_posts( array( 177 // Prepend posts with nav_menus_created_posts on first page. 178 $posts = array(); 179 if ( 0 === $page && $this->manager->get_setting( 'nav_menus_created_posts' ) ) { 180 foreach ( $this->manager->get_setting( 'nav_menus_created_posts' )->value() as $post_id ) { 181 $auto_draft_post = get_post( $post_id ); 182 if ( $post_type->name === $auto_draft_post->post_type ) { 183 $posts[] = $auto_draft_post; 184 } 185 } 186 } 187 188 $posts = array_merge( $posts, get_posts( array( 178 189 'numberposts' => 10, 179 190 'offset' => 10 * $page, … … 181 192 'order' => 'DESC', 182 193 'post_type' => $object, 183 ) ); 194 ) ) ); 195 184 196 foreach ( $posts as $post ) { 185 197 $post_title = $post->post_title; … … 306 318 } 307 319 320 $posts = array(); 321 322 // Prepend list of posts with nav_menus_created_posts search results on first page. 323 $nav_menus_created_posts_setting = $this->manager->get_setting( 'nav_menus_created_posts' ); 324 if ( 1 === $args['pagenum'] && $nav_menus_created_posts_setting && count( $nav_menus_created_posts_setting ) > 0 ) { 325 $stub_post_query = new WP_Query( array_merge( 326 $query, 327 array( 328 'post_status' => 'auto-draft', 329 'post__in' => $nav_menus_created_posts_setting->value(), 330 'posts_per_page' => -1, 331 ) 332 ) ); 333 $posts = array_merge( $posts, $stub_post_query->posts ); 334 } 335 308 336 // Query posts. 309 337 $get_posts = new WP_Query( $query ); 310 311 // Check if any posts were found. 312 if ( $get_posts->post_count ) { 313 foreach ( $get_posts->posts as $post ) { 314 $post_title = $post->post_title; 315 if ( '' === $post_title ) { 316 /* translators: %d: ID of a post */ 317 $post_title = sprintf( __( '#%d (no title)' ), $post->ID ); 318 } 319 $items[] = array( 320 'id' => 'post-' . $post->ID, 321 'title' => html_entity_decode( $post_title, ENT_QUOTES, get_bloginfo( 'charset' ) ), 322 'type' => 'post_type', 323 'type_label' => $post_type_objects[ $post->post_type ]->labels->singular_name, 324 'object' => $post->post_type, 325 'object_id' => intval( $post->ID ), 326 'url' => get_permalink( intval( $post->ID ) ), 327 ); 328 } 338 $posts = array_merge( $posts, $get_posts->posts ); 339 340 // Create items for posts. 341 foreach ( $posts as $post ) { 342 $post_title = $post->post_title; 343 if ( '' === $post_title ) { 344 /* translators: %d: ID of a post */ 345 $post_title = sprintf( __( '#%d (no title)' ), $post->ID ); 346 } 347 $items[] = array( 348 'id' => 'post-' . $post->ID, 349 'title' => html_entity_decode( $post_title, ENT_QUOTES, get_bloginfo( 'charset' ) ), 350 'type' => 'post_type', 351 'type_label' => $post_type_objects[ $post->post_type ]->labels->singular_name, 352 'object' => $post->post_type, 353 'object_id' => intval( $post->ID ), 354 'url' => get_permalink( intval( $post->ID ) ), 355 ); 329 356 } 330 357 -
trunk/tests/phpunit/tests/ajax/CustomizeMenus.php
r39137 r39138 323 323 */ 324 324 function test2_ajax_load_available_items_structure( $post_args ) { 325 do_action( 'customize_register', $this->wp_customize ); 325 326 326 327 $expected_keys = array( … … 337 338 self::factory()->term->create_many( 5 ); 338 339 self::factory()->post->create_many( 5, array( 'post_type' => 'page' ) ); 340 $auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post( array( 'post_title' => 'Test Auto Draft', 'post_type' => 'post' ) ); 341 $this->wp_customize->set_post_value( 'nav_menus_created_posts', array( $auto_draft_post->ID ) ); 342 $this->wp_customize->get_setting( 'nav_menus_created_posts' )->preview(); 339 343 340 344 $_POST = array_merge( array( … … 372 376 } 373 377 } 378 } elseif ( 'post' === $test_item['object'] ) { 379 $item_ids = wp_list_pluck( $response['data']['items']['post_type:post'], 'id' ); 380 $this->assertContains( 'post-' . $auto_draft_post->ID, $item_ids ); 374 381 } 375 382 } … … 498 505 */ 499 506 function test_ajax_search_available_items_results( $post_args, $expected_results ) { 507 do_action( 'customize_register', $this->wp_customize ); 500 508 501 509 self::factory()->post->create_many( 5, array( 'post_title' => 'Test Post' ) ); 510 $included_auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post( array( 'post_title' => 'Test Included Auto Draft', 'post_type' => 'post' ) ); 511 $excluded_auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post( array( 'post_title' => 'Excluded Auto Draft', 'post_type' => 'post' ) ); 512 $this->wp_customize->set_post_value( 'nav_menus_created_posts', array( $included_auto_draft_post->ID, $excluded_auto_draft_post->ID ) ); 513 $this->wp_customize->get_setting( 'nav_menus_created_posts' )->preview(); 502 514 503 515 $_POST = array_merge( array( … … 512 524 if ( isset( $post_args['search'] ) && 'test' === $post_args['search'] ) { 513 525 $this->assertsame( true, $response['success'] ); 514 $this->assertSame( 5, count( $response['data']['items'] ) ); 526 $this->assertSame( 6, count( $response['data']['items'] ) ); 527 $item_ids = wp_list_pluck( $response['data']['items'], 'id' ); 528 $this->assertContains( 'post-' . $included_auto_draft_post->ID, $item_ids ); 529 $this->assertNotContains( 'post-' . $excluded_auto_draft_post->ID, $item_ids ); 515 530 } else { 516 531 $this->assertSame( $expected_results, $response ); 517 532 } 518 519 533 } 520 534
Note: See TracChangeset
for help on using the changeset viewer.