Ticket #37782: 37782.4.diff
File 37782.4.diff, 7.6 KB (added by , 6 years ago) |
---|
-
src/wp-admin/css/nav-menus.css
409 409 margin-top: -4px; 410 410 } 411 411 412 .menu-item-title .post-state { 413 font-weight: 600; 414 } 415 412 416 /* Nav Menu */ 413 417 #menu-container .inside { 414 418 padding-bottom: 10px; -
src/wp-admin/includes/class-walker-nav-menu-checklist.php
94 94 } elseif ( isset( $item->post_type ) ) { 95 95 /** This filter is documented in wp-includes/post-template.php */ 96 96 $title = apply_filters( 'the_title', $item->post_title, $item->ID ); 97 if ( ! empty( $item->front_or_home ) && _x( 'Home', 'nav menu home label' ) !== $title ) { 98 /* translators: %s: front page title */ 99 $title = sprintf( _x( 'Home: %s', 'nav menu front page title' ), $title ); 100 } 97 98 /** Append post states */ 99 $title .= _post_states( $item, false ); 101 100 } 102 101 103 102 $output .= isset( $title ) ? esc_html( $title ) : esc_html( $item->title ); -
src/wp-admin/includes/nav-menu.php
354 354 $args = array_merge( $args, (array) $box['args']->_default_query ); 355 355 } 356 356 357 /* 358 * If we're dealing with pages, let's prioritize the front page, 359 * posts page and privacy 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 $front_page = 'page' == get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0; 366 $posts_page = 'page' == get_option( 'show_on_front' ) ? (int) get_option( 'page_for_posts' ) : 0; 367 368 $privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); 369 $privacy_policy_page_available = false; 370 371 if ( ! empty( $privacy_policy_page_id ) ) { 372 $privacy_policy_page = get_post( $privacy_policy_page_id ); 373 $privacy_policy_page_available = ( $privacy_policy_page instanceof WP_Post && $privacy_policy_page->post_status === 'publish' ); 374 } 375 376 /* 377 * Insert Front Page or custom home link. 378 */ 379 $front_page_obj = null; 380 if ( ! empty( $front_page ) ) { 381 $front_page_obj = get_post( $front_page ); 382 $front_page_obj->front_or_home = true; 383 384 $suppress_page_ids[] = $front_page_obj->ID; 385 } else { 386 $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval( $_nav_menu_placeholder ) - 1 : -1; 387 $front_page_obj = (object) array( 388 'front_or_home' => true, 389 'ID' => 0, 390 'object_id' => $_nav_menu_placeholder, 391 'post_content' => '', 392 'post_excerpt' => '', 393 'post_parent' => '', 394 'post_title' => _x( 'Home', 'nav menu home label' ), 395 'post_type' => 'nav_menu_item', 396 'type' => 'custom', 397 'url' => home_url( '/' ), 398 ); 399 } 400 $important_pages[] = $front_page_obj; 401 402 403 /* 404 * Insert Posts Page. 405 */ 406 if ( ! empty( $posts_page ) ) { 407 $posts_page_obj = get_post( $posts_page ); 408 $posts_page_obj->posts_page = true; 409 410 $important_pages[] = $posts_page_obj; 411 $suppress_page_ids[] = $posts_page_obj->ID; 412 } 413 414 /* 415 * Insert Privacy Page. 416 */ 417 if ( $privacy_policy_page_available ) { 418 $privacy_policy_page_obj = get_post( $privacy_policy_page_id ); 419 $privacy_policy_page_obj->privacy_policy_page = true; 420 421 $important_pages[] = $privacy_policy_page_obj; 422 $suppress_page_ids[] = $privacy_policy_page_obj->ID; 423 } 424 425 /* 426 * Add suppression array to arguments for WP_Query 427 */ 428 if ( ! empty( $suppress_page_ids ) ) { 429 $args['post__not_in'] = $suppress_page_ids; 430 } 431 } 432 357 433 // @todo transient caching of these results with proper invalidation on updating of a post of this type 358 434 $get_posts = new WP_Query; 359 435 $posts = $get_posts->query( $args ); 436 437 /** Only suppress and insert when more than just important pages available */ 360 438 if ( ! $get_posts->post_count ) { 361 echo '<p>' . __( 'No items.' ) . '</p>'; 362 return; 439 if ( ! empty( $important_pages ) ) { 440 unset($args['post__not_in']); 441 $get_posts = new WP_Query; 442 $posts = $get_posts->query( $args ); 443 } else { 444 echo '<p>' . __( 'No items.' ) . '</p>'; 445 return; 446 } 447 } else { 448 if ( ! empty( $important_pages ) ) { 449 $posts = array_merge( $important_pages, $posts ); 450 } 363 451 } 364 452 365 453 $num_pages = $get_posts->max_num_pages; … … 520 608 <?php 521 609 $args['walker'] = $walker; 522 610 523 /*524 * If we're dealing with pages, let's put a checkbox for the front525 * page at the top of the list.526 */527 if ( 'page' == $post_type_name ) {528 $front_page = 'page' == get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0;529 if ( ! empty( $front_page ) ) {530 $front_page_obj = get_post( $front_page );531 $front_page_obj->front_or_home = true;532 array_unshift( $posts, $front_page_obj );533 } else {534 $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval( $_nav_menu_placeholder ) - 1 : -1;535 array_unshift(536 $posts,537 (object) array(538 'front_or_home' => true,539 'ID' => 0,540 'object_id' => $_nav_menu_placeholder,541 'post_content' => '',542 'post_excerpt' => '',543 'post_parent' => '',544 'post_title' => _x( 'Home', 'nav menu home label' ),545 'post_type' => 'nav_menu_item',546 'type' => 'custom',547 'url' => home_url( '/' ),548 )549 );550 }551 }552 553 611 $post_type = get_post_type_object( $post_type_name ); 554 612 555 613 if ( $post_type->has_archive ) { -
src/wp-admin/includes/template.php
1871 1871 /** 1872 1872 * @param WP_Post $post 1873 1873 */ 1874 function _post_states( $post ) { 1874 function _post_states( $post, $echo = true ) { 1875 $post_states = get_post_states( $post ); 1876 $post_states_string = ''; 1877 1878 if ( ! empty( $post_states ) ) { 1879 $state_count = count( $post_states ); 1880 $i = 0; 1881 $post_states_string .= ' — '; 1882 foreach ( $post_states as $state ) { 1883 ++$i; 1884 ( $i == $state_count ) ? $sep = '' : $sep = ', '; 1885 $post_states_string .= "<span class='post-state'>$state$sep</span>"; 1886 } 1887 } 1888 1889 if ( $echo ) { 1890 echo $post_states_string; 1891 } 1892 return $post_states_string; 1893 } 1894 1895 /** 1896 * @param WP_Post $post 1897 * 1898 * @return array $post_states array of translated post states 1899 * 1900 * @since X.X.X 1901 */ 1902 function get_post_states( $post ) { 1875 1903 $post_states = array(); 1876 1904 if ( isset( $_REQUEST['post_status'] ) ) { 1877 1905 $post_status = $_REQUEST['post_status']; … … 1928 1956 * @param string[] $post_states An array of post display states. 1929 1957 * @param WP_Post $post The current post object. 1930 1958 */ 1931 $post_states = apply_filters( 'display_post_states', $post_states, $post ); 1932 1933 if ( ! empty( $post_states ) ) { 1934 $state_count = count( $post_states ); 1935 $i = 0; 1936 echo ' — '; 1937 foreach ( $post_states as $state ) { 1938 ++$i; 1939 ( $i == $state_count ) ? $sep = '' : $sep = ', '; 1940 echo "<span class='post-state'>$state$sep</span>"; 1941 } 1942 } 1943 1959 return apply_filters( 'display_post_states', $post_states, $post ); 1944 1960 } 1945 1961 1946 1962 /**