WordPress.org

Make WordPress Core

Ticket #47824: 47824.3.diff

File 47824.3.diff, 1.7 KB (added by dontdream, 23 months ago)

In this version, get_the_content() avoids using globals altogether.

  • src/wp-includes/post-template.php

     
    261261 * @since 0.71
    262262 * @since 5.2.0 Added the `$post` parameter.
    263263 *
    264  * @global int   $page      Page number of a single post/page.
    265  * @global int   $more      Boolean indicator for whether single post/page is being viewed.
    266  * @global bool  $preview   Whether post/page is in preview mode.
    267  * @global array $pages     Array of all pages in post/page. Each array element contains
    268  *                          part of the content separated by the `<!--nextpage-->` tag.
    269  * @global int   $multipage Boolean indicator for whether multiple pages are in play.
    270  *
    271264 * @param string             $more_link_text Optional. Content for when there is more text.
    272265 * @param bool               $strip_teaser   Optional. Strip teaser content before the more text. Default is false.
    273266 * @param WP_Post|object|int $post           Optional. WP_Post instance or Post ID/object. Default is null.
     
    274267 * @return string
    275268 */
    276269function get_the_content( $more_link_text = null, $strip_teaser = false, $post = null ) {
    277         global $page, $more, $preview, $pages, $multipage;
    278 
    279270        $_post = get_post( $post );
    280271
    281272        if ( ! ( $_post instanceof WP_Post ) ) {
     
    282273                return '';
    283274        }
    284275
    285         if ( null === $post ) {
    286                 $elements = compact( 'page', 'more', 'preview', 'pages', 'multipage' );
    287         } else {
    288                 $elements = generate_postdata( $_post );
    289         }
     276        $elements = generate_postdata( $_post );
    290277
    291278        if ( null === $more_link_text ) {
    292279                $more_link_text = sprintf(