--- a/wp/wp-includes/revision.php Fri Sep 05 18:40:08 2025 +0200
+++ b/wp/wp-includes/revision.php Fri Sep 05 18:52:52 2025 +0200
@@ -270,42 +270,34 @@
*
* @since 2.6.0
*
- * @global wpdb $wpdb WordPress database abstraction object.
- *
* @param int $post_id The post ID.
* @param int $user_id Optional. The post author ID. Default 0.
* @return WP_Post|false The autosaved data or false on failure or when no autosave exists.
*/
function wp_get_post_autosave( $post_id, $user_id = 0 ) {
- global $wpdb;
-
- $autosave_name = $post_id . '-autosave-v1';
- $user_id_query = ( 0 !== $user_id ) ? "AND post_author = $user_id" : null;
-
- // Construct the autosave query.
- $autosave_query = "
- SELECT *
- FROM $wpdb->posts
- WHERE post_parent = %d
- AND post_type = 'revision'
- AND post_status = 'inherit'
- AND post_name = %s " . $user_id_query . '
- ORDER BY post_date DESC
- LIMIT 1';
-
- $autosave = $wpdb->get_results(
- $wpdb->prepare(
- $autosave_query,
- $post_id,
- $autosave_name
- )
+ $args = array(
+ 'post_type' => 'revision',
+ 'post_status' => 'inherit',
+ 'post_parent' => $post_id,
+ 'name' => $post_id . '-autosave-v1',
+ 'posts_per_page' => 1,
+ 'orderby' => 'date',
+ 'order' => 'DESC',
+ 'fields' => 'ids',
+ 'no_found_rows' => true,
);
- if ( ! $autosave ) {
+ if ( 0 !== $user_id ) {
+ $args['author'] = $user_id;
+ }
+
+ $query = new WP_Query( $args );
+
+ if ( ! $query->have_posts() ) {
return false;
}
- return get_post( $autosave[0] );
+ return get_post( $query->posts[0] );
}
/**
@@ -1107,24 +1099,24 @@
* @param mixed $value Meta value to filter.
* @param int $object_id Object ID.
* @param string $meta_key Meta key to filter a value for.
- * @param bool $single Whether to return a single value. Default false.
+ * @param bool $single Whether to return a single value.
* @return mixed Original meta value if the meta key isn't revisioned, the object doesn't exist,
* the post type is a revision or the post ID doesn't match the object ID.
* Otherwise, the revisioned meta value is returned for the preview.
*/
function _wp_preview_meta_filter( $value, $object_id, $meta_key, $single ) {
+ $post = get_post();
- $post = get_post();
- if (
- empty( $post ) ||
- $post->ID !== $object_id ||
- ! in_array( $meta_key, wp_post_revision_meta_keys( $post->post_type ), true ) ||
- 'revision' === $post->post_type
+ if ( empty( $post )
+ || $post->ID !== $object_id
+ || ! in_array( $meta_key, wp_post_revision_meta_keys( $post->post_type ), true )
+ || 'revision' === $post->post_type
) {
return $value;
}
$preview = wp_get_post_autosave( $post->ID );
+
if ( false === $preview ) {
return $value;
}