Make WordPress Core

Ticket #42814: 42814.3.diff

File 42814.3.diff, 7.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 -1 as passed to get_post.
    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 = -1 ) {
     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 -1 as passed to get_post.
    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 = -1 ) {
    269273        global $page, $more, $preview, $pages, $multipage;
    270274
    271         $post = get_post();
    272275
     276        if ( -1 === $post ) {
     277                $post = get_post();
     278                $elements = compact( $page, $more, $preview, $pages, $multipage );
     279        } else {
     280                $post = get_post( $post );
     281                $elements = generate_postdata( $post );
     282        }
     283
     284        if( $post instanceof WP_Post || ! is_array( $elements ) ) {
     285                return '';
     286        }
     287
    273288        if ( null === $more_link_text ) {
    274289                $more_link_text = sprintf(
    275290                        '<span aria-label="%1$s">%2$s</span>',
     
    290305                return get_the_password_form( $post );
    291306        }
    292307
    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
     308        if ( $elements['page'] > count( $elements['pages'] ) ) { // if the requested page doesn't exist
     309                $elements['page'] = count( $elements['pages'] ); // give them the highest numbered page that DOES exist
    295310        }
    296311
    297         $content = $pages[ $page - 1 ];
     312        $content = $elements['pages'][ $elements['page'] - 1 ];
    298313        if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
    299314                $content = explode( $matches[0], $content, 2 );
    300315                if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) {
     
    306321                $content = array( $content );
    307322        }
    308323
    309         if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) ) {
     324        if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $elements['multipage'] || $elements['page'] == 1 ) ) {
    310325                $strip_teaser = true;
    311326        }
    312327
    313328        $teaser = $content[0];
    314329
    315         if ( $more && $strip_teaser && $has_teaser ) {
     330        if ( $elements['more'] && $strip_teaser && $has_teaser ) {
    316331                $teaser = '';
    317332        }
    318333
     
    319334        $output .= $teaser;
    320335
    321336        if ( count( $content ) > 1 ) {
    322                 if ( $more ) {
     337                if ( $elements['more'] ) {
    323338                        $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1];
    324339                } else {
    325340                        if ( ! empty( $more_link_text ) ) {
     
    338353                }
    339354        }
    340355
    341         if ( $preview ) { // Preview fix for JavaScript bug with foreign languages.
     356        if ( $elements['preview'] ) { // Preview fix for JavaScript bug with foreign languages.
    342357                $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output );
    343358        }
    344359
  • 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}