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

git-svn-id: http://core.svn.wordpress.org/trunk@24034 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Mark Jaquith 2013-04-18 18:07:58 +00:00
parent f5f52827c9
commit 2d382c1a5c
5 changed files with 89 additions and 16 deletions

View File

@ -172,7 +172,7 @@ if ( post_type_supports( $post_type, 'post-formats' ) && apply_filters( 'show_po
'description' => __( 'Use the editor to compose a status update. What’s new?' ) 'description' => __( 'Use the editor to compose a status update. What’s new?' )
), ),
'quote' => array ( 'quote' => array (
'description' => __( 'Copy a quotation into the box below. Add a source and URL if you have them.' ) 'description' => __( 'Add a source and URL if you have them. Use the editor to compose the quote.' )
), ),
'aside' => array ( 'aside' => array (
'description' => __( 'Use the editor to share a quick thought or side topic.' ) 'description' => __( 'Use the editor to share a quick thought or side topic.' )

View File

@ -9,11 +9,6 @@ $format_meta = get_post_format_meta( $post_ID );
<input type="hidden" name="post_format" id="post_format" value="<?php echo esc_attr( $post_format ); ?>" /> <input type="hidden" name="post_format" id="post_format" value="<?php echo esc_attr( $post_format ); ?>" />
<div class="field wp-format-quote">
<label for="wp_format_quote"><?php _e( 'Quote' ); ?></label>
<textarea id="wp_format_quote" name="_format_quote" class="widefat"><?php echo esc_textarea( $format_meta['quote'] ); ?></textarea>
</div>
<div class="field wp-format-quote"> <div class="field wp-format-quote">
<label for="wp_format_quote_source"><?php _e( 'Quote source' ); ?></label> <label for="wp_format_quote_source"><?php _e( 'Quote source' ); ?></label>
<input type="text" id="wp_format_quote_source" name="_format_quote_source_name" value="<?php echo esc_attr( $format_meta['quote_source_name'] ); ?>" class="widefat" /> <input type="text" id="wp_format_quote_source" name="_format_quote_source_name" value="<?php echo esc_attr( $format_meta['quote_source_name'] ); ?>" class="widefat" />

View File

@ -399,14 +399,11 @@ function post_formats_compat( $content, $id = 0 ) {
break; break;
case 'quote': case 'quote':
if ( ! empty( $meta['quote'] ) && ! stristr( $content, $meta['quote'] ) ) { $quote = get_the_post_format_quote( $post );
$quote = sprintf( '<blockquote>%s</blockquote>', wpautop( $meta['quote'] ) );
if ( ! empty( $meta['quote_source_name'] ) ) { // Replace the existing quote in-place.
$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'] ); if ( ! empty( $quote ) )
$quote .= sprintf( '<figcaption class="quote-caption">%s</figcaption>', $source ); get_content_quote( $content, true, $quote );
}
$format_output .= sprintf( '<figure class="quote">%s</figure>', $quote );
}
break; break;
case 'video': case 'video':
@ -679,6 +676,83 @@ function the_post_format_chat() {
echo $output; echo $output;
} }
/**
* Get the first <blockquote> from the $content string passed by reference.
*
* If $content does not have a blockquote, assume the whole string
* is the quote.
*
* @since 3.6.0
*
* @param string $content A string which might contain chat data, passed by reference.
* @param bool $remove (optional) Whether to remove the quote from the content.
* @param string $replace (optional) Content to replace the quote content with if $remove is set to true.
* @return string The quote content.
*/
function get_content_quote( &$content, $remove = false, $replace = '' ) {
if ( empty( $content ) )
return '';
$matches = array();
if ( ! preg_match( '/<blockquote[^>]*>(.+?)<\/blockquote>/is', $content, $matches ) ) {
$quote = $content;
if ( $remove || ! empty( $replace ) )
$content = $replace;
return $quote;
}
if ( $remove || ! empty( $replace ) )
$content = preg_replace( '/<blockquote[^>]*>(.+?)<\/blockquote>/is', addcslashes( $replace, '\\$' ), $content, 1 );
return $matches[1];
}
/**
* Get a quote from the post content and set split_content for future use.
*
* @since 3.6.0
*
* @uses get_content_quote()
*
* @param object $post (optional) A reference to the post object, falls back to get_post().
* @return string The quote html.
*/
function get_the_post_format_quote( &$post = null ) {
if ( empty( $post ) )
$post = get_post();
if ( empty( $post ) )
return '';
$content = $post->post_content;
$quote = get_content_quote( $content, true );
$post->split_content = $content;
if ( ! empty( $quote ) )
$quote = sprintf( '<blockquote>%s</blockquote>', wpautop( $quote ) );
$meta = get_post_format_meta( $post->ID );
if ( ! empty( $meta['quote_source_name'] ) ) {
$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'] );
$quote .= sprintf( '<figcaption class="quote-caption">%s</figcaption>', $source );
}
if ( ! empty( $quote ) )
$quote = sprintf( '<figure class="quote">%s</figure>', $quote );
return $quote;
}
/**
* Outputs the post format quote.
*
* @since 3.6.0
*/
function the_post_format_quote() {
echo get_the_post_format_quote();
}
/** /**
* Extract a URL from passed content, if possible * Extract a URL from passed content, if possible
* Checks for a URL on the first line of the content or the first encountered href attribute. * Checks for a URL on the first line of the content or the first encountered href attribute.

View File

@ -3694,7 +3694,7 @@ function setup_postdata($post) {
$more = 1; $more = 1;
$split_content = $content = $post->post_content; $split_content = $content = $post->post_content;
$format = get_post_format( $post ); $format = get_post_format( $post );
if ( $format && in_array( $format, array( 'image', 'audio', 'video' ) ) ) { if ( $format && in_array( $format, array( 'image', 'audio', 'video', 'quote' ) ) ) {
switch ( $format ) { switch ( $format ) {
case 'image': case 'image':
get_the_post_format_image( 'full', $post ); get_the_post_format_image( 'full', $post );
@ -3711,6 +3711,11 @@ function setup_postdata($post) {
if ( isset( $post->split_content ) ) if ( isset( $post->split_content ) )
$split_content = $post->split_content; $split_content = $post->split_content;
break; break;
case 'quote':
get_the_post_format_quote( $post );
if ( isset( $post->split_content ) )
$split_content = $post->split_content;
break;
} }
} }

View File

@ -72,7 +72,6 @@ function _wp_post_revision_meta_keys() {
'_format_link_url', '_format_link_url',
'_format_quote_source_url', '_format_quote_source_url',
'_format_quote_source_name', '_format_quote_source_name',
'_format_quote',
'_format_image', '_format_image',
'_format_gallery', '_format_gallery',
'_format_audio_embed', '_format_audio_embed',