Ticket #46829: 46829.5.diff
| File 46829.5.diff, 6.2 KB (added by , 6 years ago) |
|---|
-
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 if ( ! empty( $front_page ) ) { 159 $front_page_obj = get_post( $front_page ); 160 $important_pages[] = $front_page_obj; 161 $suppress_page_ids[] = $front_page_obj->ID; 162 } else { 163 // Add "Home" link. Treat as a page, but switch to custom on add. 164 $items[] = array( 165 'id' => 'home', 166 'title' => _x( 'Home', 'nav menu home label' ), 167 'type' => 'custom', 168 'type_label' => __( 'Custom Link' ), 169 'object' => '', 170 'url' => home_url(), 171 ); 172 } 173 174 // Insert Posts Page. 175 $posts_page = 'page' == get_option( 'show_on_front' ) ? (int) get_option( 'page_for_posts' ) : 0; 176 if ( ! empty( $posts_page ) ) { 177 $posts_page_obj = get_post( $posts_page ); 178 $important_pages[] = $posts_page_obj; 179 $suppress_page_ids[] = $posts_page_obj->ID; 180 } 181 182 // Insert Privacy Policy Page. 183 $privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); 184 if ( ! empty( $privacy_policy_page_id ) ) { 185 $privacy_policy_page = get_post( $privacy_policy_page_id ); 186 if ( $privacy_policy_page instanceof WP_Post && 'publish' === $privacy_policy_page->post_status ) { 187 $important_pages[] = $privacy_policy_page; 188 $suppress_page_ids[] = $privacy_policy_page->ID; 189 } 190 } 191 159 192 } elseif ( 'post' !== $object && 0 === $page && $post_type->has_archive ) { 160 193 // Add a post type archive link. 161 194 $items[] = array( … … 179 212 } 180 213 } 181 214 215 $args = array( 216 'numberposts' => 10, 217 'offset' => 10 * $page, 218 'orderby' => 'date', 219 'order' => 'DESC', 220 'post_type' => $object, 221 ); 222 223 // Add suppression array to arguments for get_posts. 224 if ( ! empty( $suppress_page_ids ) ) { 225 $args['post__not_in'] = $suppress_page_ids; 226 } 227 182 228 $posts = array_merge( 183 229 $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 ) 230 $important_pages, 231 get_posts( $args ) 193 232 ); 194 233 195 234 foreach ( $posts as $post ) { … … 198 237 /* translators: %d: ID of a post. */ 199 238 $post_title = sprintf( __( '#%d (no title)' ), $post->ID ); 200 239 } 240 241 $post_type_label = get_post_type_object( $post->post_type )->labels->singular_name; 242 $post_states = get_post_states( $post ); 243 if ( ! empty( $post_states ) ) { 244 $post_type_label = implode( ',', $post_states ); 245 } 246 201 247 $items[] = array( 202 248 'id' => "post-{$post->ID}", 203 249 'title' => html_entity_decode( $post_title, ENT_QUOTES, get_bloginfo( 'charset' ) ), 204 250 'type' => 'post_type', 205 'type_label' => get_post_type_object( $post->post_type )->labels->singular_name,251 'type_label' => $post_type_label, 206 252 'object' => $post->post_type, 207 253 'object_id' => intval( $post->ID ), 208 254 'url' => get_permalink( intval( $post->ID ) ), … … 224 270 'pad_counts' => false, 225 271 ) 226 272 ); 273 227 274 if ( is_wp_error( $terms ) ) { 228 275 return $terms; 229 276 } … … 351 398 /* translators: %d: ID of a post. */ 352 399 $post_title = sprintf( __( '#%d (no title)' ), $post->ID ); 353 400 } 401 402 $post_type_label = $post_type_objects[ $post->post_type ]->labels->singular_name; 403 $post_states = get_post_states( $post ); 404 if ( ! empty( $post_states ) ) { 405 $post_type_label = implode( ',', $post_states ); 406 } 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 if ( empty( $front_page ) ) { 450 $title = _x( 'Home', 'nav menu home label' ); 451 $matches = function_exists( 'mb_stripos' ) ? false !== mb_stripos( $title, $args['s'] ) : false !== stripos( $title, $args['s'] ); 452 if ( $matches ) { 453 $items[] = array( 454 'id' => 'home', 455 'title' => $title, 456 'type' => 'custom', 457 'type_label' => __( 'Custom Link' ), 458 'object' => '', 459 'url' => home_url(), 460 ); 461 } 404 462 } 405 463 } 406 464