Changeset 46309 for trunk/src/wp-admin/includes/nav-menu.php
- Timestamp:
- 09/25/2019 09:51:00 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/nav-menu.php
r46240 r46309 355 355 } 356 356 357 /* 358 * If we're dealing with pages, let's prioritize the Front Page, 359 * Posts Page and Privacy Policy Page at the top of the list. 360 */ 361 $important_pages = array(); 362 if ( 'page' == $post_type_name ) { 363 $suppress_page_ids = array(); 364 365 // Insert Front Page or custom Home link. 366 $front_page = 'page' == get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0; 367 368 $front_page_obj = null; 369 if ( ! empty( $front_page ) ) { 370 $front_page_obj = get_post( $front_page ); 371 $front_page_obj->front_or_home = true; 372 373 $important_pages[] = $front_page_obj; 374 $suppress_page_ids[] = $front_page_obj->ID; 375 } else { 376 $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval( $_nav_menu_placeholder ) - 1 : -1; 377 $front_page_obj = (object) array( 378 'front_or_home' => true, 379 'ID' => 0, 380 'object_id' => $_nav_menu_placeholder, 381 'post_content' => '', 382 'post_excerpt' => '', 383 'post_parent' => '', 384 'post_title' => _x( 'Home', 'nav menu home label' ), 385 'post_type' => 'nav_menu_item', 386 'type' => 'custom', 387 'url' => home_url( '/' ), 388 ); 389 390 $important_pages[] = $front_page_obj; 391 } 392 393 // Insert Posts Page. 394 $posts_page = 'page' == get_option( 'show_on_front' ) ? (int) get_option( 'page_for_posts' ) : 0; 395 396 if ( ! empty( $posts_page ) ) { 397 $posts_page_obj = get_post( $posts_page ); 398 $posts_page_obj->posts_page = true; 399 400 $important_pages[] = $posts_page_obj; 401 $suppress_page_ids[] = $posts_page_obj->ID; 402 } 403 404 // Insert Privacy Policy Page. 405 $privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); 406 407 if ( ! empty( $privacy_policy_page_id ) ) { 408 $privacy_policy_page = get_post( $privacy_policy_page_id ); 409 if ( $privacy_policy_page instanceof WP_Post && 'publish' === $privacy_policy_page->post_status ) { 410 $privacy_policy_page->privacy_policy_page = true; 411 412 $important_pages[] = $privacy_policy_page; 413 $suppress_page_ids[] = $privacy_policy_page->ID; 414 } 415 } 416 417 // Add suppression array to arguments for WP_Query. 418 if ( ! empty( $suppress_page_ids ) ) { 419 $args['post__not_in'] = $suppress_page_ids; 420 } 421 } 422 357 423 // @todo transient caching of these results with proper invalidation on updating of a post of this type 358 424 $get_posts = new WP_Query; 359 425 $posts = $get_posts->query( $args ); 426 427 // Only suppress and insert when more than just suppression pages available. 360 428 if ( ! $get_posts->post_count ) { 361 echo '<p>' . __( 'No items.' ) . '</p>'; 362 return; 429 if ( ! empty( $suppress_page_ids ) ) { 430 unset( $args['post__not_in'] ); 431 $get_posts = new WP_Query; 432 $posts = $get_posts->query( $args ); 433 } else { 434 echo '<p>' . __( 'No items.' ) . '</p>'; 435 return; 436 } 437 } elseif ( ! empty( $important_pages ) ) { 438 $posts = array_merge( $important_pages, $posts ); 363 439 } 364 440 … … 523 599 $args['walker'] = $walker; 524 600 525 /*526 * If we're dealing with pages, let's put a checkbox for the front527 * page at the top of the list.528 */529 if ( 'page' == $post_type_name ) {530 $front_page = 'page' == get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0;531 if ( ! empty( $front_page ) ) {532 $front_page_obj = get_post( $front_page );533 $front_page_obj->front_or_home = true;534 array_unshift( $posts, $front_page_obj );535 } else {536 $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval( $_nav_menu_placeholder ) - 1 : -1;537 array_unshift(538 $posts,539 (object) array(540 'front_or_home' => true,541 'ID' => 0,542 'object_id' => $_nav_menu_placeholder,543 'post_content' => '',544 'post_excerpt' => '',545 'post_parent' => '',546 'post_title' => _x( 'Home', 'nav menu home label' ),547 'post_type' => 'nav_menu_item',548 'type' => 'custom',549 'url' => home_url( '/' ),550 )551 );552 }553 }554 555 601 $post_type = get_post_type_object( $post_type_name ); 556 602
Note: See TracChangeset
for help on using the changeset viewer.