Make WordPress Core

Changeset 4625


Ignore:
Timestamp:
12/07/2006 03:10:47 AM (20 years ago)
Author:
markjaquith
Message:

get_page() logic re-ordering and inline comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r4624 r4625  
    929929                        wp_cache_add($_page->ID, $_page, 'pages');
    930930                } else {
     931                        // shouldn't we just return NULL at this point? ~ Mark
    931932                        $_page = null;
    932933                }
    … …  
    937938                $_page = $page;
    938939        } else {
    939                 if ( isset($GLOBALS['page']->ID) && ($page == $GLOBALS['page']->ID) ) {
    940                         $_page = & $GLOBALS['page'];
    941                         wp_cache_add($_page->ID, $_page, 'pages');
    942                 } elseif ( isset($GLOBALS['post_cache'][$blog_id][$page]) ) {
    943                         return get_post($page, $output);
    944                 } elseif ( $_page = wp_cache_get($page, 'pages') ) {
    945                         // Got it.
    946                 } else {
    947                         $query = "SELECT * FROM $wpdb->posts WHERE ID= '$page' LIMIT 1";
    948                         $_page = & $wpdb->get_row($query);
    949                         if ( 'post' == $_page->post_type )
    950                                 return get_post($_page, $output);
    951                         wp_cache_add($_page->ID, $_page, 'pages');
    952                 }
    953         }
     940                // first, check the cache
     941                if ( ! ( $_page = wp_cache_get($page, 'pages') ) ) {
     942                        // not in the page cache?
     943                        if ( isset($GLOBALS['page']->ID) && ($page == $GLOBALS['page']->ID) ) { // for is_page() views
     944                                // I don't think this code ever gets executed ~ Mark
     945                                $_page = & $GLOBALS['page'];
     946                                wp_cache_add($_page->ID, $_page, 'pages');
     947                        } elseif ( isset($GLOBALS['post_cache'][$blog_id][$page]) ) { // it's actually a page, and is cached
     948                                return get_post($page, $output);
     949                        } else { // it's not in any caches, so off to the DB we go
     950                                // Why are we using assignment for this query?
     951                                $_page = & $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID= '$page' LIMIT 1");
     952                                if ( 'post' == $_page->post_type )
     953                                        return get_post($_page, $output);
     954                                // Potential issue: we're not checking to see if the post_type = 'page'
     955                                // So all non-'post' posts will get cached as pages.
     956                                wp_cache_add($_page->ID, $_page, 'pages');
     957                        }
     958                }
     959        }
     960
     961        // at this point, one way or another, $_post contains the page object
    954962
    955963        if ( $output == OBJECT ) {
Note: See TracChangeset for help on using the changeset viewer.