Make WordPress Core


Ignore:
Timestamp:
05/20/2013 11:05:50 AM (11 years ago)
Author:
ryan
Message:
  • Introduce wp_parse_post_content() and use it in setup_postdata(), get_the_content(), and get_the_remaining_content().
  • Add a post ID argument to the_content(), get_the_content(), the_remaining_content(), and get_the_remaining_content().
  • Pass the post ID to the the_content filter.
  • Remove the format_pages global.
  • Declare format_content and split_content as vars in WP_Post.
  • phpdoc for the the_content filter that documents the new ID argument and denotes it as not-so-portable.

Props gcorne, DrewAPicture, duck_, aaroncampbell
see #24330

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post-template.php

    r24207 r24301  
    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  */
    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 ) );
     163 * @param int $id Optional. A post id. Defaults to the current post when in The Loop, undefined otherwise.
     164 */
     165function the_content( $more_link_text = null, $strip_teaser = false, $id = 0 ) {
     166    $post = get_post( $id );
     167
     168    /*
     169     * Filter: the_content
     170     *
     171     * param string Post content as returned by get_the_content()
     172     * param int The ID of the post to which the content belongs. This was introduced
     173     *           in 3.6.0 and is not reliably passed by all plugins and themes that
     174     *           directly apply the_content. As such, it is not considered portable.
     175     */
     176    $content = apply_filters( 'the_content', get_the_content( $more_link_text, $strip_teaser, $post->ID ), $post->ID );
    166177    echo str_replace( ']]>', ']]>', $content );
    167178}
     
    174185 * @param string $more_link_text Optional. Content for when there is more text.
    175186 * @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false.
     187 * @param int $id Optional. A post id. Defaults to the current post when in The Loop, undefined otherwise.
    176188 * @return string
    177189 */
    178 function get_the_content( $more_link_text = null, $strip_teaser = false ) {
    179     global $more, $page, $pages, $multipage, $preview;
    180 
    181     $post = get_post();
     190function get_the_content( $more_link_text = null, $strip_teaser = false, $id = 0 ) {
     191    global $page, $more, $preview;
     192
     193    $post = get_post( $id );
     194    // Avoid parsing again if the post is the same one parsed by setup_postdata().
     195    // The extract() will set up $pages and $multipage.
     196    if ( $post->ID != $GLOBALS['id'] )
     197        extract( wp_parse_post_content( $post, false ) );
     198    else
     199        global $pages, $multipage;
    182200
    183201    if ( null === $more_link_text )
     
    188206
    189207    // If post password required and it doesn't match the cookie.
    190     if ( post_password_required() )
    191         return get_the_password_form();
     208    if ( post_password_required( $post ) )
     209        return get_the_password_form( $post );
    192210
    193211    if ( $page > count( $pages ) ) // if the requested page doesn't exist
     
    567585 * @since 2.7.0
    568586 *
    569  * @param int|object $post An optional post. Global $post used if not provided.
     587 * @param int|WP_Post $post An optional post. Global $post used if not provided.
    570588 * @return bool false if a password is not required or the correct password cookie is present, true otherwise.
    571589 */
     
    12261244 * @since 1.0.0
    12271245 * @uses apply_filters() Calls 'the_password_form' filter on output.
    1228  *
     1246 * @param int|WP_Post $post Optional. A post id or post object. Defaults to the current post when in The Loop, undefined otherwise.
    12291247 * @return string HTML content for password form for password protected post.
    12301248 */
    1231 function get_the_password_form() {
    1232     $post = get_post();
     1249function get_the_password_form( $post = 0 ) {
     1250    $post = get_post( $post );
    12331251    $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );
    12341252    $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
Note: See TracChangeset for help on using the changeset viewer.