Posts, Post Types: Set post filter in update_post_cache().

Ensure the post cache is primed with raw sanitized data. This resolves an inconsistency between how posts retrieved via `get_post()` vs `WP_Query` are cached.

This prevents `sanitize_post( $post, 'raw' )` being run multiple times on a cached post. This can happen over 20 times per post on some page loads so avoiding this will provide a noticeable performance boost.

Props Cybr, SergeyBiryukov, peterwilsoncc, hellofromTonya, costdev.
Fixes #50567.



git-svn-id: https://develop.svn.wordpress.org/trunk@53042 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Wilson
2022-04-01 03:16:33 +00:00
parent 16baa38779
commit b1b305b826
3 changed files with 145 additions and 1 deletions
+1 -1
View File
@@ -247,7 +247,7 @@ final class WP_Post {
$_post = sanitize_post( $_post, 'raw' );
wp_cache_add( $_post->ID, $_post, 'posts' );
} elseif ( empty( $_post->filter ) ) {
} elseif ( empty( $_post->filter ) || 'raw' !== $_post->filter ) {
$_post = sanitize_post( $_post, 'raw' );
}