Make WordPress Core

Ticket #42814: 42814.4.diff

File 42814.4.diff, 8.5 KB (added by spacedmonkey, 6 years ago)
  • src/wp-includes/class-wp-query.php

     
    41334133                        return;
    41344134                }
    41354135
     4136                $elements = $this->generate_postdata( $post );
     4137                if( false === $elements ){
     4138                        return;
     4139                }
     4140
     4141                $id = $elements['id'];
     4142                $authordata = $elements['authordata'];
     4143                $currentday = $elements['currentday'];
     4144                $currentmonth  = $elements['currentmonth'];
     4145                $page  = $elements['page'];
     4146                $pages = $elements['pages'];
     4147                $multipage = $elements['multipage'];
     4148                $more = $elements['more'];
     4149                $numpages  = $elements['numpages'];
     4150
     4151                return true;
     4152        }
     4153
     4154        /**
     4155         * Generate post data.
     4156         *
     4157         * @param WP_Post|object|int $post WP_Post instance or Post ID/object.
     4158         * @return array  $elements Elements of post
     4159         */
     4160        public function generate_postdata( $post ) {
     4161
     4162                if ( ! ( $post instanceof WP_Post ) ) {
     4163                        $post = get_post( $post );
     4164                }
     4165
     4166                if ( ! $post ) {
     4167                        return false;
     4168                }
     4169
    41364170                $id = (int) $post->ID;
    41374171
    41384172                $authordata = get_userdata( $post->post_author );
     
    42094243                 */
    42104244                do_action_ref_array( 'the_post', array( &$post, &$this ) );
    42114245
    4212                 return true;
     4246                $elements = compact( $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages );
     4247
     4248                return $elements;
    42134249        }
    42144250        /**
    42154251         * After looping through a nested query, this function
  • src/wp-includes/default-filters.php

     
    170170add_filter( 'the_excerpt', 'convert_chars' );
    171171add_filter( 'the_excerpt', 'wpautop' );
    172172add_filter( 'the_excerpt', 'shortcode_unautop' );
    173 add_filter( 'get_the_excerpt', 'wp_trim_excerpt' );
     173add_filter( 'get_the_excerpt', 'wp_trim_excerpt', 10, 2 );
    174174
    175175add_filter( 'the_post_thumbnail_caption', 'wptexturize' );
    176176add_filter( 'the_post_thumbnail_caption', 'convert_smilies' );
  • src/wp-includes/formatting.php

     
    36253625 * The ' […]' string can be modified by plugins/themes using the {@see 'excerpt_more'} filter
    36263626 *
    36273627 * @since 1.5.0
     3628 * @since 5.0.0 Added '$post' param
    36283629 *
    36293630 * @param string $text Optional. The excerpt. If set to empty, an excerpt is generated.
     3631 * @param WP_Post|object|int $post Optional. WP_Post instance or Post ID/object. Default is null.
    36303632 * @return string The excerpt.
    36313633 */
    3632 function wp_trim_excerpt( $text = '' ) {
     3634function wp_trim_excerpt( $text = '', $post = null ) {
    36333635        $raw_excerpt = $text;
    36343636        if ( '' == $text ) {
    3635                 $text = get_the_content( '' );
     3637            $post = get_post( $post );
     3638                $text = get_the_content( '', false, $post );
    36363639
    36373640                $text = strip_shortcodes( $text );
    36383641
  • src/wp-includes/post-template.php

     
    230230 * Display the post content.
    231231 *
    232232 * @since 0.71
     233 * @since 5.0.0 Added '$post' param
    233234 *
    234235 * @param string $more_link_text Optional. Content for when there is more text.
    235236 * @param bool   $strip_teaser   Optional. Strip teaser content before the more text. Default is false.
     237 * @param WP_Post|object|int $post Optional. WP_Post instance or Post ID/object. Default is null.
    236238 */
    237 function the_content( $more_link_text = null, $strip_teaser = false ) {
    238         $content = get_the_content( $more_link_text, $strip_teaser );
     239function the_content( $more_link_text = null, $strip_teaser = false, $post = null ) {
     240        $content = get_the_content( $more_link_text, $strip_teaser, $post );
    239241
    240242        /**
    241243         * Filters the post content.
     
    253255 * Retrieve the post content.
    254256 *
    255257 * @since 0.71
     258 * @since 5.0.0 Added '$post' param
    256259 *
    257260 * @global int   $page      Page number of a single post/page.
    258261 * @global int   $more      Boolean indicator for whether single post/page is being viewed.
     
    263266 *
    264267 * @param string $more_link_text Optional. Content for when there is more text.
    265268 * @param bool   $strip_teaser   Optional. Strip teaser content before the more text. Default is false.
     269 * @param WP_Post|object|int $post Optional. WP_Post instance or Post ID/object. Default is null.
    266270 * @return string
    267271 */
    268 function get_the_content( $more_link_text = null, $strip_teaser = false ) {
     272function get_the_content( $more_link_text = null, $strip_teaser = false, $post = null ) {
    269273        global $page, $more, $preview, $pages, $multipage;
    270274
    271         $post = get_post();
    272275
     276        $_post = get_post( $post );
     277
     278        if ( ! ( $_post instanceof WP_Post ) ) {
     279                return '';
     280        }
     281
     282        if ( null === $post ) {
     283                $elements = compact( $page, $more, $preview, $pages, $multipage );
     284        } else {
     285                $elements = generate_postdata( $_post );
     286        }
     287
     288
    273289        if ( null === $more_link_text ) {
    274290                $more_link_text = sprintf(
    275291                        '<span aria-label="%1$s">%2$s</span>',
    276292                        sprintf(
    277                                 /* translators: %s: Name of current post */
     293                        /* translators: %s: Name of current post */
    278294                                __( 'Continue reading %s' ),
    279                                 the_title_attribute( array( 'echo' => false ) )
     295                                the_title_attribute( array( 'echo' => false, 'post' => $_post, ) )
    280296                        ),
    281297                        __( '(more&hellip;)' )
    282298                );
     
    286302        $has_teaser = false;
    287303
    288304        // If post password required and it doesn't match the cookie.
    289         if ( post_password_required( $post ) ) {
    290                 return get_the_password_form( $post );
     305        if ( post_password_required( $_post ) ) {
     306                return get_the_password_form( $_post );
    291307        }
    292308
    293         if ( $page > count( $pages ) ) { // if the requested page doesn't exist
    294                 $page = count( $pages ); // give them the highest numbered page that DOES exist
     309        if ( $elements['page'] > count( $elements['pages'] ) ) { // if the requested page doesn't exist
     310                $elements['page'] = count( $elements['pages'] ); // give them the highest numbered page that DOES exist
    295311        }
    296312
    297         $content = $pages[ $page - 1 ];
     313        $content = $elements['pages'][ $elements['page'] - 1 ];
    298314        if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
    299315                $content = explode( $matches[0], $content, 2 );
    300316                if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) {
     
    306322                $content = array( $content );
    307323        }
    308324
    309         if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) ) {
     325        if ( false !== strpos( $_post->post_content, '<!--noteaser-->' ) && ( ! $elements['multipage'] || $elements['page'] == 1 ) ) {
    310326                $strip_teaser = true;
    311327        }
    312328
    313329        $teaser = $content[0];
    314330
    315         if ( $more && $strip_teaser && $has_teaser ) {
     331        if ( $elements['more'] && $strip_teaser && $has_teaser ) {
    316332                $teaser = '';
    317333        }
    318334
     
    319335        $output .= $teaser;
    320336
    321337        if ( count( $content ) > 1 ) {
    322                 if ( $more ) {
    323                         $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1];
     338                if ( $elements['more'] ) {
     339                        $output .= '<span id="more-' . $_post->ID . '"></span>' . $content[1];
    324340                } else {
    325341                        if ( ! empty( $more_link_text ) ) {
    326342
     
    332348                                 * @param string $more_link_element Read More link element.
    333349                                 * @param string $more_link_text    Read More text.
    334350                                 */
    335                                 $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
     351                                $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink( $_post ) . "#more-{$_post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
    336352                        }
    337353                        $output = force_balance_tags( $output );
    338354                }
    339355        }
    340356
    341         if ( $preview ) { // Preview fix for JavaScript bug with foreign languages.
     357        if ( $elements['preview'] ) { // Preview fix for JavaScript bug with foreign languages.
    342358                $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output );
    343359        }
    344360
  • src/wp-includes/query.php

     
    11111111
    11121112        return false;
    11131113}
     1114
     1115/**
     1116 * Generate post data.
     1117 *
     1118 * @since 5.0.0
     1119 *
     1120 * @global WP_Query $wp_query Global WP_Query instance.
     1121 *
     1122 * @param WP_Post|object|int $post WP_Post instance or Post ID/object.
     1123 * @return bool True when finished.
     1124 */
     1125function generate_postdata( $post ) {
     1126        global $wp_query;
     1127
     1128        if ( ! empty( $wp_query ) && $wp_query instanceof WP_Query ) {
     1129                return $wp_query->generate_postdata( $post );
     1130        }
     1131
     1132        return false;
     1133}