Fix global post stomping in get_post(). Turn get_page() into an alias of get_post(). Props westi. fixes #13753

git-svn-id: https://develop.svn.wordpress.org/trunk@15188 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2010-06-10 14:55:26 +00:00
parent d61154542c
commit 9319e06698
1 changed files with 8 additions and 15 deletions

View File

@ -369,10 +369,13 @@ function &get_post(&$post, $output = OBJECT, $filter = 'raw') {
wp_cache_add($post->ID, $_post, 'posts'); wp_cache_add($post->ID, $_post, 'posts');
} else { } else {
if ( is_object($post) ) if ( is_object($post) )
$post = $post->ID; $post_id = $post->ID;
$post = (int) $post; else
if ( ! $_post = wp_cache_get($post, 'posts') ) { $post_id = $post;
$_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post));
$post_id = (int) $post_id;
if ( ! $_post = wp_cache_get($post_id, 'posts') ) {
$_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id));
if ( ! $_post ) if ( ! $_post )
return $null; return $null;
_get_post_ancestors($_post); _get_post_ancestors($_post);
@ -2865,17 +2868,7 @@ function get_all_page_ids() {
* @return mixed Page data. * @return mixed Page data.
*/ */
function &get_page(&$page, $output = OBJECT, $filter = 'raw') { function &get_page(&$page, $output = OBJECT, $filter = 'raw') {
if ( empty($page) ) { return get_post($page, $output, $filter);
if ( isset( $GLOBALS['post'] ) && isset( $GLOBALS['post']->ID ) ) {
return get_post($GLOBALS['post'], $output, $filter);
} else {
$page = null;
return $page;
}
}
$the_page = get_post($page, $output, $filter);
return $the_page;
} }
/** /**