Changeset 47763 for trunk/src/wp-includes/class-wp-customize-nav-menus.php
- Timestamp:
- 05/05/2020 09:15:49 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-customize-nav-menus.php
r47747 r47763 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. … … 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 … … 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 ), … … 225 271 ) 226 272 ); 273 227 274 if ( is_wp_error( $terms ) ) { 228 275 return $terms; … … 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 ), … … 392 446 // Add "Home" link if search term matches. Treat as a page, but switch to custom on add. 393 447 if ( isset( $args['s'] ) ) { 394 $title = _x( 'Home', 'nav menu home label' ); 395 $matches = function_exists( 'mb_stripos' ) ? false !== mb_stripos( $title, $args['s'] ) : false !== stripos( $title, $args['s'] ); 396 if ( $matches ) { 397 $items[] = array( 398 'id' => 'home', 399 'title' => $title, 400 'type' => 'custom', 401 'type_label' => __( 'Custom Link' ), 402 'object' => '', 403 'url' => home_url(), 404 ); 448 // Only insert custom "Home" link if there's no Front Page 449 $front_page = 'page' == get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0; 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 } 405 463 } 406 464 }
Note: See TracChangeset
for help on using the changeset viewer.