Improve sanitize_post() performance. Perform raw filtering only once. Add filter check to eliminate double filtering. Props johanee. fixes #10972 see #10801
git-svn-id: https://develop.svn.wordpress.org/trunk@12062 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
395f0b9e2d
commit
83ad1ab1a8
@ -232,8 +232,8 @@ function &get_post(&$post, $output = OBJECT, $filter = 'raw') {
|
||||
return $null;
|
||||
} elseif ( is_object($post) && empty($post->filter) ) {
|
||||
_get_post_ancestors($post);
|
||||
wp_cache_add($post->ID, $post, 'posts');
|
||||
$_post = &$post;
|
||||
$_post = sanitize_post($post, 'raw');
|
||||
wp_cache_add($post->ID, $_post, 'posts');
|
||||
} else {
|
||||
if ( is_object($post) )
|
||||
$post = $post->ID;
|
||||
@ -243,10 +243,12 @@ function &get_post(&$post, $output = OBJECT, $filter = 'raw') {
|
||||
if ( ! $_post )
|
||||
return $null;
|
||||
_get_post_ancestors($_post);
|
||||
$_post = sanitize_post($_post, 'raw');
|
||||
wp_cache_add($_post->ID, $_post, 'posts');
|
||||
}
|
||||
}
|
||||
|
||||
if ($filter != 'raw')
|
||||
$_post = sanitize_post($_post, $filter);
|
||||
|
||||
if ( $output == OBJECT ) {
|
||||
@ -817,12 +819,18 @@ function is_sticky($post_id = null) {
|
||||
*/
|
||||
function sanitize_post($post, $context = 'display') {
|
||||
if ( is_object($post) ) {
|
||||
// Check if post already filtered for this context
|
||||
if ( isset($post->filter) && $context == $post->filter )
|
||||
return $post;
|
||||
if ( !isset($post->ID) )
|
||||
$post->ID = 0;
|
||||
foreach ( array_keys(get_object_vars($post)) as $field )
|
||||
$post->$field = sanitize_post_field($field, $post->$field, $post->ID, $context);
|
||||
$post->filter = $context;
|
||||
} else {
|
||||
// Check if post already filtered for this context
|
||||
if ( isset($post['filter']) && $context == $post['filter'] )
|
||||
return $post;
|
||||
if ( !isset($post['ID']) )
|
||||
$post['ID'] = 0;
|
||||
foreach ( array_keys($post) as $field )
|
||||
@ -2450,6 +2458,12 @@ function &get_pages($args = '') {
|
||||
return $pages;
|
||||
}
|
||||
|
||||
// Sanitize before caching so it'll only get done once
|
||||
$num_pages = count($pages);
|
||||
for ($i = 0; $i < $num_pages; $i++) {
|
||||
$pages[$i] = sanitize_post($pages[$i], 'raw');
|
||||
}
|
||||
|
||||
// Update cache.
|
||||
update_page_cache($pages);
|
||||
|
||||
@ -2465,8 +2479,7 @@ function &get_pages($args = '') {
|
||||
foreach ( $children as $child )
|
||||
$excludes[] = $child->ID;
|
||||
$excludes[] = $exclude;
|
||||
$total = count($pages);
|
||||
for ( $i = 0; $i < $total; $i++ ) {
|
||||
for ( $i = 0; $i < $num_pages; $i++ ) {
|
||||
if ( in_array($pages[$i]->ID, $excludes) )
|
||||
unset($pages[$i]);
|
||||
}
|
||||
|
@ -2360,9 +2360,15 @@ class WP_Query {
|
||||
if ( !$q['suppress_filters'] )
|
||||
$this->posts = apply_filters('the_posts', $this->posts);
|
||||
|
||||
$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');
|
||||
}
|
||||
|
||||
update_post_caches($this->posts);
|
||||
|
||||
$this->post_count = count($this->posts);
|
||||
if ($this->post_count > 0) {
|
||||
$this->post = $this->posts[0];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user