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.php

    r24238 r24301  
    567567     */
    568568    public $filter;
     569
     570    /**
     571     * Private variable used by post formats to cache parsed content.
     572     *
     573     * @since 3.6.0
     574     *
     575     * @var array
     576     * @access private
     577     */
     578    public $format_content;
     579
     580    /**
     581     * Private variable used by post formats to cache parsed content.
     582     *
     583     * @since 3.6.0
     584     *
     585     * @var string
     586     * @access private
     587     */
     588    public $split_content;
    569589
    570590    public static function get_instance( $post_id ) {
     
    49634983    }
    49644984}
     4985
     4986/**
     4987 * Parse post content for pagination
     4988 *
     4989 * @since 3.6.0
     4990 *
     4991 * @uses paginate_content()
     4992 *
     4993 * @param object $post The post object.
     4994 * @param bool $remaining Whether to parse post formats from the content. Defaults to false.
     4995 * @return array An array of values used for paginating the parsed content.
     4996 */
     4997function wp_parse_post_content( $post, $remaining = false ) {
     4998    $numpages = 1;
     4999
     5000    if ( $remaining ) {
     5001        $format = get_post_format( $post );
     5002        if ( $format && in_array( $format, array( 'image', 'audio', 'video', 'quote' ) ) ) {
     5003            // Call get_the_post_format_*() to set $post->split_content
     5004            switch ( $format ) {
     5005                case 'image':
     5006                    get_the_post_format_image( 'full', $post );
     5007                    break;
     5008                case 'audio':
     5009                    get_the_post_format_media( 'audio', $post, 1 );
     5010                    break;
     5011                case 'video':
     5012                    get_the_post_format_media( 'video', $post, 1 );
     5013                    break;
     5014                case 'quote':
     5015                    get_the_post_format_quote( $post );
     5016                    break;
     5017            }
     5018        }
     5019    }
     5020
     5021    if ( strpos( $post->post_content, '<!--nextpage-->' ) ) {
     5022        $multipage = 1;
     5023        if ( $remaining && isset( $post->split_content ) )
     5024            $pages = paginate_content( $post->split_content );
     5025        else
     5026            $pages = paginate_content( $post->post_content );
     5027        $numpages = count( $pages );
     5028    } else {
     5029        if ( $remaining && isset( $post->split_content ) )
     5030            $pages = array( $post->split_content );
     5031        else
     5032            $pages = array( $post->post_content );
     5033        $multipage = 0;
     5034    }
     5035
     5036    return compact( 'multipage', 'pages', 'numpages' );
     5037}
Note: See TracChangeset for help on using the changeset viewer.