Make WordPress Core

Ticket #56689: 56689.diff

File 56689.diff, 2.4 KB (added by SergeyBiryukov, 2 years ago)
  • src/wp-includes/post.php

     
    56745674 * Retrieves a page given its path.
    56755675 *
    56765676 * @since 2.1.0
    5677  *
    5678  * @global wpdb $wpdb WordPress database abstraction object.
    5679  *
    56805677 * @param string       $page_path Page path.
    56815678 * @param string       $output    Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which
    56825679 *                                correspond to a WP_Post object, an associative array, or a numeric array,
     
    56855682 * @return WP_Post|array|null WP_Post (or array) on success, or null on failure.
    56865683 */
    56875684function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) {
    5688         global $wpdb;
    5689 
    56905685        $last_changed = wp_cache_get_last_changed( 'posts' );
    56915686
    56925687        $hash      = md5( $page_path . serialize( $post_type ) );
     
    57065701        $page_path     = str_replace( '%20', ' ', $page_path );
    57075702        $parts         = explode( '/', trim( $page_path, '/' ) );
    57085703        $parts         = array_map( 'sanitize_title_for_query', $parts );
    5709         $escaped_parts = esc_sql( $parts );
    57105704
    5711         $in_string = "'" . implode( "','", $escaped_parts ) . "'";
    5712 
    57135705        if ( is_array( $post_type ) ) {
    57145706                $post_types = $post_type;
    57155707        } else {
     
    57165708                $post_types = array( $post_type, 'attachment' );
    57175709        }
    57185710
    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         ";
     5711        $args = array(
     5712                'post_name__in'          => $parts,
     5713                'post_type'              => $post_types,
     5714                'post_status'            => 'all',
     5715                'posts_per_page'         => -1,
     5716                'update_post_term_cache' => false,
     5717                'update_post_meta_cache' => false,
     5718                'no_found_rows'          => true,
     5719                'orderby'                => 'none',
     5720        );
    57275721
    5728         $pages = $wpdb->get_results( $sql, OBJECT_K );
     5722        $query = new WP_Query( $args );
     5723        $posts = $query->get_posts();
     5724        $pages = array();
    57295725
     5726        foreach ( $posts as $post ) {
     5727                $pages[ $post->ID ] = $post;
     5728        }
     5729
    57305730        $revparts = array_reverse( $parts );
    57315731
    57325732        $foundid = 0;
    5733         foreach ( (array) $pages as $page ) {
     5733        foreach ( $pages as $page ) {
    57345734                if ( $page->post_name == $revparts[0] ) {
    57355735                        $count = 0;
    57365736                        $p     = $page;