Make WordPress Core

Ticket #36879: 36879.0.diff

File 36879.0.diff, 1.4 KB (added by westonruter, 9 years ago)
  • src/wp-includes/class-wp-post.php

    diff --git src/wp-includes/class-wp-post.php src/wp-includes/class-wp-post.php
    index 5904e58..ec6f96d 100644
    final class WP_Post { 
    211211                global $wpdb;
    212212
    213213                $post_id = (int) $post_id;
    214                 if ( ! $post_id )
     214                if ( ! $post_id ) {
    215215                        return false;
     216                }
    216217
    217218                $_post = wp_cache_get( $post_id, 'posts' );
    218219
    219220                if ( ! $_post ) {
    220221                        $_post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id ) );
    221222
    222                         if ( ! $_post )
    223                                 return false;
    224 
    225                         $_post = sanitize_post( $_post, 'raw' );
    226                         wp_cache_add( $_post->ID, $_post, 'posts' );
     223                        if ( ! $_post ) {
     224                                $_post = false;
     225                        } else {
     226                                $_post = sanitize_post( $_post, 'raw' );
     227                                wp_cache_add( $_post->ID, $_post, 'posts' );
     228                        }
    227229                } elseif ( empty( $_post->filter ) ) {
    228230                        $_post = sanitize_post( $_post, 'raw' );
    229231                }
    230232
     233                if ( is_customize_preview() ) {
     234
     235                        /**
     236                         * Filter post data instance in Customizer, the return value of `WP_Post::get_instance()`.
     237                         *
     238                         * The filtered value will be added to
     239                         *
     240                         * @since 4.6
     241                         *
     242                         * @param object|false $_post   Post data, or false if it was not found in the database.
     243                         * @param int          $post_id Post ID.
     244                         */
     245                        $_post = apply_filters( 'customize_preview_post_instance', $_post, $post_id );
     246                }
     247
     248                if ( false === $_post ) {
     249                        return $_post;
     250                }
     251
    231252                return new WP_Post( $_post );
    232253        }
    233254