Make WordPress Core

Ticket #36905: 36905.patch

File 36905.patch, 1.2 KB (added by spacedmonkey, 8 years ago)
  • src/wp-includes/post.php

     
    43274327function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) {
    43284328        global $wpdb;
    43294329
     4330        $last_changed = wp_cache_get( 'last_changed', 'posts' );
     4331        if ( false === $last_changed ) {
     4332                $last_changed = microtime();
     4333                wp_cache_set( 'last_changed', $last_changed, 'posts' );
     4334        }
     4335
     4336        $hash      = md5( $page_title . serialize( $post_type ) );
     4337        $cache_key = "get_page_by_title:$hash:$last_changed";
     4338        $cached    = wp_cache_get( $cache_key, 'posts' );
     4339        if ( false !== $cached ) {
     4340                // Special case: '0' is a bad `$page_path`.
     4341                if ( '0' === $cached || 0 === $cached ) {
     4342                        return;
     4343                } else {
     4344                        return get_post( $cached, $output );
     4345                }
     4346        }
     4347
    43304348        if ( is_array( $post_type ) ) {
    43314349                $post_type = esc_sql( $post_type );
    43324350                $post_type_in_string = "'" . implode( "','", $post_type ) . "'";
     
    43474365
    43484366        $page = $wpdb->get_var( $sql );
    43494367
     4368        // We cache misses as well as hits.
     4369        wp_cache_set( $cache_key, $page, 'posts' );
     4370
    43504371        if ( $page ) {
    43514372                return get_post( $page, $output );
    43524373        }