From d7a17b96e93ac21b9f57d19e131d07547e54b513 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 30 Sep 2011 19:06:18 +0000 Subject: [PATCH] Avoid refetching a post in get_post() when passed a post object that has already been raw sanitized. Clean up sanitize loop. Props scribu. fixes #18822 git-svn-id: http://svn.automattic.com/wordpress/trunk@18846 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 2 ++ wp-includes/query.php | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 94f916ec7..994de88dc 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -381,6 +381,8 @@ function &get_post(&$post, $output = OBJECT, $filter = 'raw') { _get_post_ancestors($post); $_post = sanitize_post($post, 'raw'); wp_cache_add($post->ID, $_post, 'posts'); + } elseif ( is_object($post) && 'raw' == $post->filter ) { + $_post = $post; } else { if ( is_object($post) ) $post_id = $post->ID; diff --git a/wp-includes/query.php b/wp-includes/query.php index 34864b94f..1887a6f0a 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -2745,9 +2745,9 @@ class WP_Query { $this->post_count = count($this->posts); - // Sanitize before caching so it'll only get done once - for ( $i = 0; $i < $this->post_count; $i++ ) { - $this->posts[$i] = sanitize_post($this->posts[$i], 'raw'); + // Always sanitize + foreach ( $this->posts as $i => $post ) { + $this->posts[$i] = sanitize_post( $post, 'raw' ); } if ( $q['cache_results'] )