Ticket #46829: 46829.3.diff
| File 46829.3.diff, 6.8 KB (added by , 7 years ago) |
|---|
-
src/wp-admin/includes/class-walker-nav-menu-edit.php
120 120 <div class="menu-item-handle"> 121 121 <span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' ); ?></span></span> 122 122 <span class="item-controls"> 123 <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>123 <span class="item-type"><?php echo $item->type_label; ?></span> 124 124 <span class="item-order hide-if-js"> 125 125 <?php 126 126 printf( -
src/wp-includes/class-wp-customize-nav-menus.php
146 146 return new WP_Error( 'nav_menus_invalid_post_type' ); 147 147 } 148 148 149 /* 150 * If we're dealing with pages, let's prioritize the Front Page, 151 * Posts Page and Privacy Policy Page at the top of the list. 152 */ 153 $important_pages = array(); 154 $suppress_page_ids = array(); 149 155 if ( 0 === $page && 'page' === $object ) { 150 // Add "Home" link. Treat as a page, but switch to custom on add. 151 $items[] = array( 152 'id' => 'home', 153 'title' => _x( 'Home', 'nav menu home label' ), 154 'type' => 'custom', 155 'type_label' => __( 'Custom Link' ), 156 'object' => '', 157 'url' => home_url(), 158 ); 156 // Insert Front Page or custom Home link. 157 $front_page = 'page' == get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0; 158 159 if ( ! empty( $front_page ) ) { 160 $front_page_obj = get_post( $front_page ); 161 162 $important_pages[] = $front_page_obj; 163 $suppress_page_ids[] = $front_page_obj->ID; 164 } else { 165 // Add "Home" link. Treat as a page, but switch to custom on add. 166 $items[] = array( 167 'id' => 'home', 168 'title' => _x( 'Home', 'nav menu home label' ), 169 'type' => 'custom', 170 'type_label' => __( 'Custom Link' ), 171 'object' => '', 172 'url' => home_url(), 173 ); 174 } 175 176 // Insert Posts Page. 177 $posts_page = 'page' == get_option( 'show_on_front' ) ? (int) get_option( 'page_for_posts' ) : 0; 178 179 if ( ! empty( $posts_page ) ) { 180 $posts_page_obj = get_post( $posts_page ); 181 182 $important_pages[] = $posts_page_obj; 183 $suppress_page_ids[] = $posts_page_obj->ID; 184 } 185 186 // Insert Privacy Policy Page. 187 $privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); 188 189 if ( ! empty( $privacy_policy_page_id ) ) { 190 $privacy_policy_page = get_post( $privacy_policy_page_id ); 191 if ( $privacy_policy_page instanceof WP_Post && 'publish' === $privacy_policy_page->post_status ) { 192 $important_pages[] = $privacy_policy_page; 193 $suppress_page_ids[] = $privacy_policy_page->ID; 194 } 195 } 196 159 197 } elseif ( 'post' !== $object && 0 === $page && $post_type->has_archive ) { 160 198 // Add a post type archive link. 161 199 $items[] = array( … … 179 217 } 180 218 } 181 219 220 $args = array( 221 'numberposts' => 10, 222 'offset' => 10 * $page, 223 'orderby' => 'date', 224 'order' => 'DESC', 225 'post_type' => $object, 226 ); 227 228 // Add suppression array to arguments for get_posts. 229 if ( ! empty( $suppress_page_ids ) ) { 230 $args['post__not_in'] = $suppress_page_ids; 231 } 232 182 233 $posts = array_merge( 183 234 $posts, 184 get_posts( 185 array( 186 'numberposts' => 10, 187 'offset' => 10 * $page, 188 'orderby' => 'date', 189 'order' => 'DESC', 190 'post_type' => $object, 191 ) 192 ) 235 $important_pages, 236 get_posts( $args ) 193 237 ); 194 238 195 239 foreach ( $posts as $post ) { … … 198 242 /* translators: %d: ID of a post. */ 199 243 $post_title = sprintf( __( '#%d (no title)' ), $post->ID ); 200 244 } 245 $post_type_label = get_post_type_object( $post->post_type )->labels->singular_name; 246 $post_states = get_post_states( $post ); 247 if ( ! empty( $post_states ) ) { 248 $post_type_label = implode( ',', get_post_states( $post ) ); 249 } 201 250 $items[] = array( 202 251 'id' => "post-{$post->ID}", 203 252 'title' => html_entity_decode( $post_title, ENT_QUOTES, get_bloginfo( 'charset' ) ), 204 253 'type' => 'post_type', 205 'type_label' => get_post_type_object( $post->post_type )->labels->singular_name,254 'type_label' => $post_type_label, 206 255 'object' => $post->post_type, 207 256 'object_id' => intval( $post->ID ), 208 257 'url' => get_permalink( intval( $post->ID ) ), … … 351 400 /* translators: %d: ID of a post. */ 352 401 $post_title = sprintf( __( '#%d (no title)' ), $post->ID ); 353 402 } 403 $post_type_label = $post_type_objects[ $post->post_type ]->labels->singular_name; 404 $post_states = get_post_states( $post ); 405 if ( ! empty( $post_states ) ) { 406 $post_type_label = implode( ',', get_post_states( $post ) ); 407 } 354 408 $items[] = array( 355 409 'id' => 'post-' . $post->ID, 356 410 'title' => html_entity_decode( $post_title, ENT_QUOTES, get_bloginfo( 'charset' ) ), 357 411 'type' => 'post_type', 358 'type_label' => $post_type_ objects[ $post->post_type ]->labels->singular_name,412 'type_label' => $post_type_label, 359 413 'object' => $post->post_type, 360 414 'object_id' => intval( $post->ID ), 361 415 'url' => get_permalink( intval( $post->ID ) ), … … 390 444 391 445 // Add "Home" link if search term matches. Treat as a page, but switch to custom on add. 392 446 if ( isset( $args['s'] ) ) { 393 $title = _x( 'Home', 'nav menu home label' ); 394 $matches = function_exists( 'mb_stripos' ) ? false !== mb_stripos( $title, $args['s'] ) : false !== stripos( $title, $args['s'] ); 395 if ( $matches ) { 396 $items[] = array( 397 'id' => 'home', 398 'title' => $title, 399 'type' => 'custom', 400 'type_label' => __( 'Custom Link' ), 401 'object' => '', 402 'url' => home_url(), 403 ); 447 // Only insert custom Home link if there's no Front page 448 $front_page = 'page' == get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0; 449 450 if ( empty( $front_page ) ) { 451 $title = _x( 'Home', 'nav menu home label' ); 452 $matches = function_exists( 'mb_stripos' ) ? false !== mb_stripos( $title, $args['s'] ) : false !== stripos( $title, $args['s'] ); 453 if ( $matches ) { 454 $items[] = array( 455 'id' => 'home', 456 'title' => $title, 457 'type' => 'custom', 458 'type_label' => __( 'Custom Link' ), 459 'object' => '', 460 'url' => home_url(), 461 ); 462 } 404 463 } 405 464 } 406 465