WordPress.org

Make WordPress Core

Ticket #24330: 24330.diff

File 24330.diff, 3.9 KB (added by ryan, 11 months ago)

Pass the post ID down the the_content() stack. Add phpdoc for the_content filter explaining portability issues of the ID arg

  • wp-includes/default-filters.php

     
    136136add_filter( 'the_title', 'trim'          ); 
    137137add_filter( 'the_title', '_post_formats_title', 10, 2 ); 
    138138 
    139 add_filter( 'the_content', 'post_formats_compat', 7 ); 
     139add_filter( 'the_content', 'post_formats_compat', 7, 2 ); 
    140140add_filter( 'the_content', 'wptexturize'            ); 
    141141add_filter( 'the_content', 'convert_smilies'        ); 
    142142add_filter( 'the_content', 'convert_chars'          ); 
  • wp-includes/post-template.php

     
    160160 * 
    161161 * @param string $more_link_text Optional. Content for when there is more text. 
    162162 * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false. 
     163 * @param int $id Optional. A post id. Defaults to the current post when in The Loop, undefined otherwise. 
    163164 */ 
    164 function the_content( $more_link_text = null, $strip_teaser = false ) { 
    165         $content = apply_filters( 'the_content', get_the_content( $more_link_text, $strip_teaser ) ); 
     165function the_content( $more_link_text = null, $strip_teaser = false, $id = 0 ) { 
     166        $post = get_post( $id ); 
     167        /* 
     168         * Filter: the_content 
     169         * 
     170         * param string Post content as returned by get_the_content() 
     171         * param int The ID of the post to which the content belongs. This was introduced 
     172         *           in 3.6.0 and is not reliably passed by all plugins and themes that 
     173         *           directly apply the_content. As such, it is not considered portable. 
     174         */ 
     175        $content = apply_filters( 'the_content', get_the_content( $more_link_text, $strip_teaser, $id ), $post->ID ); 
    166176        echo str_replace( ']]>', ']]>', $content ); 
    167177} 
    168178 
     
    173183 * 
    174184 * @param string $more_link_text Optional. Content for when there is more text. 
    175185 * @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false. 
     186 * @param int $id Optional. A post id. Defaults to the current post when in The Loop, undefined otherwise. 
    176187 * @return string 
    177188 */ 
    178 function get_the_content( $more_link_text = null, $strip_teaser = false ) { 
     189function get_the_content( $more_link_text = null, $strip_teaser = false, $id = 0 ) { 
    179190        global $more, $page, $pages, $multipage, $preview; 
    180191 
    181         $post = get_post(); 
     192        $post = get_post( $id ); 
    182193 
    183194        if ( null === $more_link_text ) 
    184195                $more_link_text = __( '(more…)' ); 
     
    187198        $has_teaser = false; 
    188199 
    189200        // If post password required and it doesn't match the cookie. 
    190         if ( post_password_required() ) 
     201        if ( post_password_required( $post ) ) 
    191202                return get_the_password_form(); 
    192203 
    193204        if ( $page > count( $pages ) ) // if the requested page doesn't exist 
     
    12251236 * 
    12261237 * @since 1.0.0 
    12271238 * @uses apply_filters() Calls 'the_password_form' filter on output. 
    1228  * 
     1239 * @param int $id Optional. A post id. Defaults to the current post when in The Loop, undefined otherwise. 
    12291240 * @return string HTML content for password form for password protected post. 
    12301241 */ 
    1231 function get_the_password_form() { 
     1242function get_the_password_form( $id = 0 ) { 
    12321243        $post = get_post(); 
    12331244        $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID ); 
    12341245        $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post"> 
  • wp-includes/comment.php

     
    17491749        } 
    17501750 
    17511751        if ( empty($post->post_excerpt) ) 
    1752                 $excerpt = apply_filters('the_content', $post->post_content); 
     1752                $excerpt = apply_filters('the_content', $post->post_content, $post->ID); 
    17531753        else 
    17541754                $excerpt = apply_filters('the_excerpt', $post->post_excerpt); 
    17551755        $excerpt = str_replace(']]>', ']]&gt;', $excerpt);