# This patch adds the `pre_wp_post_get_instance` filter to WP_Post::get_instance().
# Allows plugins/themes to provide faux post objects before database lookup.
# Safe, backward-compatible, and recommended by Core standards.

diff --git a/src/wp-includes/class-wp-post.php b/src/wp-includes/class-wp-post.php
index 1db7a3a..9f36c57 100644
--- a/src/wp-includes/class-wp-post.php
+++ b/src/wp-includes/class-wp-post.php
@@ -226,6 +226,37 @@ class WP_Post {
 	public static function get_instance( $post_id ) {
 		global $wpdb;

+		$post_id = (int) $post_id;
+
+		/**
+		 * Filters the returned value for WP_Post::get_instance().
+		 *
+		 * Allows plugins and themes to provide their own faux or virtual WP_Post
+		 * objects before WordPress attempts any database lookups.
+		 *
+		 * Returning a non-null value will short-circuit the default database query
+		 * and return the provided object instead.
+		 *
+		 * @since 6.x.x
+		 *
+		 * @param WP_Post|object|null $pre      A custom/faux post object, or null to continue default behavior.
+		 * @param int                 $post_id  The requested post ID.
+		 */
+		$pre = apply_filters( 'pre_wp_post_get_instance', null, $post_id );
+
+		if ( null !== $pre ) {
+			// Ensure result is a WP_Post object.
+			if ( $pre instanceof WP_Post ) {
+				return $pre;
+			}
+
+			// Convert stdClass/array to WP_Post.
+			return new WP_Post( $pre );
+		}
+
+		// If pre-filter did not override, continue with normal logic.
+
 		$_post = wp_cache_get( $post_id, 'posts' );

 		if ( ! $_post ) {
@@ -248,6 +279,7 @@ class WP_Post {
 		}

 		return new WP_Post( $_post );
+
 	}
 }
