Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions src/wp-includes/class-wp-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,27 +231,51 @@
*/
public static function get_instance( $post_id ) {
global $wpdb;

Check failure on line 234 in src/wp-includes/class-wp-post.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Whitespace found at end of line
$post_id = (int) $post_id;

Check failure on line 236 in src/wp-includes/class-wp-post.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Whitespace found at end of line
/**
* Filters the returned value for WP_Post::get_instance().
*
* Allows plugins/themes to return a faux or virtual WP_Post object
* before WordPress queries the database.
*
* Returning a non-null value short-circuits the normal execution.
*
* @since 6.x.x
*
* @param WP_Post|object|null $post A custom/faux post object or null.
* @param int $post_id Requested post ID.
*/
$pre = apply_filters( 'pre_wp_post_get_instance', null, $post_id );

Check failure on line 251 in src/wp-includes/class-wp-post.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Whitespace found at end of line
if ( null !== $pre ) {
// Ensure the result is a proper WP_Post object.
return ( $pre instanceof WP_Post ) ? $pre : new WP_Post( $pre );
}

Check failure on line 256 in src/wp-includes/class-wp-post.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Whitespace found at end of line
// Existing logic (unchanged)
if ( $post_id <= 0 ) {
return false;
}

Check failure on line 261 in src/wp-includes/class-wp-post.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Whitespace found at end of line
$_post = wp_cache_get( $post_id, 'posts' );

Check failure on line 263 in src/wp-includes/class-wp-post.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Whitespace found at end of line
if ( ! $_post ) {
$_post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id ) );

$_post = $wpdb->get_row(
$wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id )
);

Check failure on line 268 in src/wp-includes/class-wp-post.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Whitespace found at end of line
if ( ! $_post ) {
return false;
}

Check failure on line 272 in src/wp-includes/class-wp-post.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Whitespace found at end of line
$_post = sanitize_post( $_post, 'raw' );
wp_cache_add( $_post->ID, $_post, 'posts' );
} elseif ( empty( $_post->filter ) || 'raw' !== $_post->filter ) {
$_post = sanitize_post( $_post, 'raw' );
}

Check failure on line 278 in src/wp-includes/class-wp-post.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Whitespace found at end of line
return new WP_Post( $_post );
}

Expand Down
Loading