WordPress.org

Make WordPress Core

Changeset 24034


Ignore:
Timestamp:
04/18/13 18:07:58 (12 months ago)
Author:
markjaquith
Message:

Post Formats: use the content body for the body of the Quote post format.

  • Searchable, better editing tools
  • Less cluttered Post Format UI

props kovshenin, DrewAPicture. see #24009

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-form-advanced.php

    r24026 r24034  
    173173        ), 
    174174        'quote' => array ( 
    175             'description' => __( 'Copy a quotation into the box below. Add a source and URL if you have them.' ) 
     175            'description' => __( 'Add a source and URL if you have them. Use the editor to compose the quote.' ) 
    176176        ), 
    177177        'aside' => array ( 
  • trunk/wp-admin/includes/post-formats.php

    r24024 r24034  
    99 
    1010    <input type="hidden" name="post_format" id="post_format" value="<?php echo esc_attr( $post_format ); ?>" /> 
    11  
    12     <div class="field wp-format-quote"> 
    13         <label for="wp_format_quote"><?php _e( 'Quote' ); ?></label> 
    14         <textarea id="wp_format_quote" name="_format_quote" class="widefat"><?php echo esc_textarea( $format_meta['quote'] ); ?></textarea> 
    15     </div> 
    1611 
    1712    <div class="field wp-format-quote"> 
  • trunk/wp-includes/post-formats.php

    r24021 r24034  
    400400 
    401401        case 'quote': 
    402             if ( ! empty( $meta['quote'] ) && ! stristr( $content, $meta['quote'] ) ) { 
    403                 $quote = sprintf( '<blockquote>%s</blockquote>', wpautop( $meta['quote'] ) ); 
    404                 if ( ! empty( $meta['quote_source_name'] ) ) { 
    405                     $source = ( empty( $meta['quote_source_url'] ) ) ? $meta['quote_source_name'] : sprintf( '<a href="%s">%s</a>', esc_url( $meta['quote_source_url'] ), $meta['quote_source_name'] ); 
    406                     $quote .= sprintf( '<figcaption class="quote-caption">%s</figcaption>', $source ); 
    407                 } 
    408                 $format_output .= sprintf( '<figure class="quote">%s</figure>', $quote ); 
    409             } 
     402            $quote = get_the_post_format_quote( $post ); 
     403 
     404            // Replace the existing quote in-place. 
     405            if ( ! empty( $quote ) ) 
     406                get_content_quote( $content, true, $quote ); 
    410407            break; 
    411408 
     
    681678 
    682679/** 
     680 * Get the first <blockquote> from the $content string passed by reference. 
     681 * 
     682 * If $content does not have a blockquote, assume the whole string 
     683 * is the quote. 
     684 * 
     685 * @since 3.6.0 
     686 * 
     687 * @param string $content A string which might contain chat data, passed by reference. 
     688 * @param bool $remove (optional) Whether to remove the quote from the content. 
     689 * @param string $replace (optional) Content to replace the quote content with if $remove is set to true. 
     690 * @return string The quote content. 
     691 */ 
     692function get_content_quote( &$content, $remove = false, $replace = '' ) { 
     693    if ( empty( $content ) ) 
     694        return ''; 
     695 
     696    $matches = array(); 
     697    if ( ! preg_match( '/<blockquote[^>]*>(.+?)<\/blockquote>/is', $content, $matches ) ) { 
     698        $quote = $content; 
     699        if ( $remove || ! empty( $replace ) ) 
     700            $content = $replace; 
     701        return $quote; 
     702    } 
     703 
     704    if ( $remove || ! empty( $replace ) ) 
     705        $content = preg_replace( '/<blockquote[^>]*>(.+?)<\/blockquote>/is', addcslashes( $replace, '\\$' ), $content, 1 ); 
     706 
     707    return $matches[1]; 
     708} 
     709 
     710/** 
     711 * Get a quote from the post content and set split_content for future use. 
     712 * 
     713 * @since 3.6.0 
     714 * 
     715 * @uses get_content_quote() 
     716 * 
     717 * @param object $post (optional) A reference to the post object, falls back to get_post(). 
     718 * @return string The quote html. 
     719 */ 
     720function get_the_post_format_quote( &$post = null ) { 
     721    if ( empty( $post ) ) 
     722        $post = get_post(); 
     723 
     724    if ( empty( $post ) ) 
     725        return ''; 
     726 
     727    $content = $post->post_content; 
     728    $quote = get_content_quote( $content, true ); 
     729    $post->split_content = $content; 
     730 
     731    if ( ! empty( $quote ) ) 
     732        $quote = sprintf( '<blockquote>%s</blockquote>', wpautop( $quote ) ); 
     733 
     734    $meta = get_post_format_meta( $post->ID ); 
     735 
     736    if ( ! empty( $meta['quote_source_name'] ) ) { 
     737        $source = ( empty( $meta['quote_source_url'] ) ) ? $meta['quote_source_name'] : sprintf( '<a href="%s">%s</a>', esc_url( $meta['quote_source_url'] ), $meta['quote_source_name'] ); 
     738        $quote .= sprintf( '<figcaption class="quote-caption">%s</figcaption>', $source ); 
     739    } 
     740 
     741    if ( ! empty( $quote ) ) 
     742        $quote = sprintf( '<figure class="quote">%s</figure>', $quote ); 
     743 
     744    return $quote; 
     745} 
     746 
     747/** 
     748 * Outputs the post format quote. 
     749 * 
     750 * @since 3.6.0 
     751 */ 
     752function the_post_format_quote() { 
     753    echo get_the_post_format_quote(); 
     754} 
     755 
     756/** 
    683757 * Extract a URL from passed content, if possible 
    684758 * Checks for a URL on the first line of the content or the first encountered href attribute. 
  • trunk/wp-includes/query.php

    r23984 r24034  
    36953695    $split_content = $content = $post->post_content; 
    36963696    $format = get_post_format( $post ); 
    3697     if ( $format && in_array( $format, array( 'image', 'audio', 'video' ) ) ) { 
     3697    if ( $format && in_array( $format, array( 'image', 'audio', 'video', 'quote' ) ) ) { 
    36983698        switch ( $format ) { 
    36993699        case 'image': 
     
    37123712                $split_content = $post->split_content; 
    37133713            break; 
     3714        case 'quote': 
     3715            get_the_post_format_quote( $post ); 
     3716            if ( isset( $post->split_content ) ) 
     3717                $split_content = $post->split_content; 
     3718            break; 
    37143719        } 
    37153720    } 
  • trunk/wp-includes/revision.php

    r24025 r24034  
    7373        '_format_quote_source_url', 
    7474        '_format_quote_source_name', 
    75         '_format_quote', 
    7675        '_format_image', 
    7776        '_format_gallery', 
Note: See TracChangeset for help on using the changeset viewer.