Don't cache filtered post objects. Set filter when getting sample permalink. Props brianwhite. fixes #8526 for trunk

git-svn-id: https://develop.svn.wordpress.org/trunk@10213 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-12-16 23:50:39 +00:00
parent fcc53e993b
commit 97a6c04681
3 changed files with 14 additions and 2 deletions

View File

@ -909,6 +909,8 @@ function get_sample_permalink($id, $title=null, $name = null) {
$post->post_name = sanitize_title($name? $name : $title, $post->ID);
}
$post->filter = 'sample';
$permalink = get_permalink($post, true);
// Handle page hierarchy
@ -926,6 +928,8 @@ function get_sample_permalink($id, $title=null, $name = null) {
$post->post_status = $original_status;
$post->post_date = $original_date;
$post->post_name = $original_name;
unset($post->filter);
return $permalink;
}

View File

@ -92,7 +92,10 @@ function get_permalink($id = 0, $leavename = false) {
$leavename? '' : '%pagename%',
);
$post = &get_post($id);
if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter )
$post = $id;
else
$post = &get_post($id);
if ( empty($post->ID) ) return false;

View File

@ -215,11 +215,13 @@ function &get_post(&$post, $output = OBJECT, $filter = 'raw') {
$_post = & $GLOBALS['post'];
else
return $null;
} elseif ( is_object($post) ) {
} elseif ( is_object($post) && empty($post->filter) ) {
_get_post_ancestors($post);
wp_cache_add($post->ID, $post, 'posts');
$_post = &$post;
} else {
if ( is_object($post) )
$post = $post->ID;
$post = (int) $post;
if ( ! $_post = wp_cache_get($post, 'posts') ) {
$_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post));
@ -792,12 +794,15 @@ function sanitize_post($post, $context = 'display') {
$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 {
if ( !isset($post['ID']) )
$post['ID'] = 0;
foreach ( array_keys($post) as $field )
$post[$field] = sanitize_post_field($field, $post[$field], $post['ID'], $context);
$post['filter'] = $context;
}
return $post;
}