Changeset 55215
- Timestamp:
- 02/03/2023 04:15:55 PM (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r55207 r55215 5676 5676 * @since 2.1.0 5677 5677 * 5678 * @global wpdb $wpdb WordPress database abstraction object. 5679 * 5678 5680 * @param string $page_path Page path. 5679 5681 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which … … 5684 5686 */ 5685 5687 function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) { 5686 $page_path = rawurlencode( urldecode( $page_path ) ); 5687 $page_path = str_replace( '%2F', '/', $page_path ); 5688 $page_path = str_replace( '%20', ' ', $page_path ); 5689 $parts = explode( '/', trim( $page_path, '/' ) ); 5690 $parts = array_map( 'sanitize_title_for_query', $parts ); 5688 global $wpdb; 5689 5690 $last_changed = wp_cache_get_last_changed( 'posts' ); 5691 5692 $hash = md5( $page_path . serialize( $post_type ) ); 5693 $cache_key = "get_page_by_path:$hash:$last_changed"; 5694 $cached = wp_cache_get( $cache_key, 'posts' ); 5695 if ( false !== $cached ) { 5696 // Special case: '0' is a bad `$page_path`. 5697 if ( '0' === $cached || 0 === $cached ) { 5698 return; 5699 } else { 5700 return get_post( $cached, $output ); 5701 } 5702 } 5703 5704 $page_path = rawurlencode( urldecode( $page_path ) ); 5705 $page_path = str_replace( '%2F', '/', $page_path ); 5706 $page_path = str_replace( '%20', ' ', $page_path ); 5707 $parts = explode( '/', trim( $page_path, '/' ) ); 5708 $parts = array_map( 'sanitize_title_for_query', $parts ); 5709 $escaped_parts = esc_sql( $parts ); 5710 5711 $in_string = "'" . implode( "','", $escaped_parts ) . "'"; 5691 5712 5692 5713 if ( is_array( $post_type ) ) { … … 5696 5717 } 5697 5718 5698 $args = array( 5699 'post_name__in' => $parts, 5700 'post_type' => $post_types, 5701 'post_status' => 'all', 5702 'posts_per_page' => -1, 5703 'update_post_term_cache' => false, 5704 'update_post_meta_cache' => false, 5705 'no_found_rows' => true, 5706 'orderby' => 'none', 5707 ); 5708 5709 $query = new WP_Query( $args ); 5710 $posts = $query->get_posts(); 5711 $pages = array(); 5712 5713 foreach ( $posts as $post ) { 5714 $pages[ $post->ID ] = $post; 5715 } 5719 $post_types = esc_sql( $post_types ); 5720 $post_type_in_string = "'" . implode( "','", $post_types ) . "'"; 5721 $sql = " 5722 SELECT ID, post_name, post_parent, post_type 5723 FROM $wpdb->posts 5724 WHERE post_name IN ($in_string) 5725 AND post_type IN ($post_type_in_string) 5726 "; 5727 5728 $pages = $wpdb->get_results( $sql, OBJECT_K ); 5716 5729 5717 5730 $revparts = array_reverse( $parts ); 5718 5731 5719 5732 $foundid = 0; 5720 foreach ( $pages as $page ) {5733 foreach ( (array) $pages as $page ) { 5721 5734 if ( $page->post_name == $revparts[0] ) { 5722 5735 $count = 0; … … 5744 5757 } 5745 5758 } 5759 5760 // We cache misses as well as hits. 5761 wp_cache_set( $cache_key, $foundid, 'posts' ); 5746 5762 5747 5763 if ( $foundid ) {
Note: See TracChangeset
for help on using the changeset viewer.