diff --git wp-includes/default-filters.php wp-includes/default-filters.php index 7d47e45..706fedb 100644 --- wp-includes/default-filters.php +++ wp-includes/default-filters.php @@ -132,12 +132,13 @@ add_filter( 'the_title', 'wptexturize' ); add_filter( 'the_title', 'convert_chars' ); add_filter( 'the_title', 'trim' ); -add_filter( 'the_content', 'wptexturize' ); -add_filter( 'the_content', 'convert_smilies' ); -add_filter( 'the_content', 'convert_chars' ); -add_filter( 'the_content', 'wpautop' ); -add_filter( 'the_content', 'shortcode_unautop' ); -add_filter( 'the_content', 'prepend_attachment' ); +add_filter( 'the_content', 'post_formats_compat', 7 ); +add_filter( 'the_content', 'wptexturize' ); +add_filter( 'the_content', 'convert_smilies' ); +add_filter( 'the_content', 'convert_chars' ); +add_filter( 'the_content', 'wpautop' ); +add_filter( 'the_content', 'shortcode_unautop' ); +add_filter( 'the_content', 'prepend_attachment' ); add_filter( 'the_excerpt', 'wptexturize' ); add_filter( 'the_excerpt', 'convert_smilies' ); diff --git wp-includes/formatting.php wp-includes/formatting.php index 83f5269..f49cf51 100644 --- wp-includes/formatting.php +++ wp-includes/formatting.php @@ -1802,6 +1802,190 @@ function convert_smilies($text) { } /** + * Return the class for a post format content wrapper + * + * @since 3.6.0 + * + * @param string $format + */ +function get_post_format_content_class( $format ) { + return apply_filters( 'post_format_content_class', $format . '-post-format-content', $format ); +} + +/** + * Ouput the class for a post format content wrapper + * + * @since 3.6.0 + * + * @param string $format + */ +function post_format_content_class( $format ) { + echo get_post_format_content_class( $format ); +} + +/** + * Provide fallback behavior for Posts that have associated post format + * + * @since 3.6.0 + * + * @param string $content + */ +function post_formats_compat( $content, $id = 0 ) { + $post = empty( $id ) ? get_post() : get_post( $id ); + if ( empty( $post ) ) + return $content; + + $format = get_post_format( $post ); + if ( empty( $format ) ) + return $content; + + if ( current_theme_supports( 'post-formats', $format ) ) + return $content; + + $defaults = array( + 'position' => 'after', + 'tag' => 'div', + 'class' => get_post_format_content_class( $format ), + 'chat_tag' => 'span', + 'chat_tag_class' => 'chat-line', + 'chat_delimiter' => PHP_EOL, + 'link_class' => '', + 'image_class' => '', + 'gallery' => '[gallery]', + 'audio' => '[audio]', + 'video' => '[video]' + ); + + $args = apply_filters( 'post_format_compat', array() ); + $compat = wp_parse_args( $args, $defaults ); + + $show_content = true; + $format_output = ''; + $meta = get_post_format_meta( $post->ID ); + + switch ( $format ) { + case 'chat': + $show_content = false; + $lines = explode( $compat['chat_delimiter'], $content ); + foreach ( $lines as $line ) + $format_output .= sprintf( '<%1$s class="%2$s">%3$s%1$s>', $compat['chat_tag'], $compat['chat_tag_class'], $line ); + break; + + case 'link': + $compat['tag'] = ''; + + if ( ! empty( $meta['url'] ) ) { + $format_output .= sprintf( + '%s', + empty( $compat['link_class'] ) ? '' : sprintf( 'class="%s" ', $compat['link_class'] ), + esc_url( $meta['url'] ), + empty( $post->post_title ) ? esc_url( $meta['url'] ) : apply_filters( 'the_title', $post->post_title ) + ); + } + break; + + case 'quote': + if ( ! empty( $meta['quote'] ) ) { + $format_output .= sprintf( '
%s', $meta['quote'] ); + if ( ! empty( $meta['quote_source'] ) ) { + $format_output .= sprintf( + '%s', + ! empty( $meta['url'] ) ? + sprintf( '%s', esc_url( $meta['url'] ), $meta['quote_source'] ) : + $meta['quote_source'] + ); + } + } + break; + + case 'image': + if ( ! empty( $meta['image'] ) ) { + $image = is_numeric( $meta['image'] ) ? wp_get_attachment_url( $meta['image'] ) : $meta['image']; + + $esc_image_url = preg_quote( $image, '#' ); + if ( ! empty( $image ) && ! preg_match( "#src=['\"]{$esc_image_url}#", $content ) ) { + $image_html = sprintf( + '', + empty( $compat['image_class'] ) ? '' : sprintf( 'class="%s" ', $compat['image_class'] ), + $image + ); + if ( empty( $meta['url'] ) ) { + $format_output .= $image_html; + } else { + $format_output .= sprintf( + '%s', + esc_url( $meta['url'] ), + $image_html + ); + } + } + } + break; + + case 'gallery': + $matches = preg_match( '/' . get_shortcode_regex() . '/s', $content ); + if ( ! $matches || 'gallery' !== $matches[2] ) { + if ( empty( $meta['gallery'] ) && ! empty( $compat['gallery'] ) ) { + $format_output .= $compat['gallery']; + } elseif ( ! empty( $meta['gallery'] ) ) { + $format_output .= $meta['gallery']; + } + } + break; + + case 'video': + case 'audio': + $shortcode_regex = '/' . get_shortcode_regex() . '/s'; + $matches = preg_match( $shortcode_regex, $content ); + if ( ! $matches || $format !== $matches[2] ) { + if ( empty( $meta['media'] ) && ! empty( $compat[$format] ) ) { + $format_output .= $compat[$format]; + } elseif ( ! empty( $meta['media'] ) ) { + // the metadata is a shortcode or an embed code + if ( preg_match( $shortcode_regex, $meta['media'] ) || preg_match( '#<[^>]+>#', $meta['media'] ) ) { + $format_output .= $meta['media']; + } else { + $mime_type = wp_check_filetype( $meta['media'] ); + // URL that can be shortcode'd + if ( ! empty( $mime_type['type'] ) + && ( ( 'video' === $format && 'video/mp4' === $mime_type['type'] ) + || ( 'audio' === $format && 'audio/mpeg' === $mime_type['type'] ) ) ) { + $format_output .= sprintf( '[%s src="%s"]', $format, esc_url( $meta['media'] ) ); + // URL that isn't embeddable outputs string + } else { + $format_output .= sprintf( '[embed]%s[/embed]', $meta['media'] ); + } + } + } + } + break; + case 'standard': + case 'status': + case 'aside': + default: + return $content; + break; + } + + $output = ''; + if ( ! empty( $compat['tag'] ) ) + $output .= sprintf( '<%s class="%s">', $compat['tag'], $compat['class'] ); + + if ( ! empty( $content ) && $show_content && 'before' !== $compat['position'] ) + $output .= $content . PHP_EOL . PHP_EOL; + + $output .= $format_output; + + if ( ! empty( $content ) && $show_content && 'before' === $compat['position'] ) + $output .= PHP_EOL . PHP_EOL . $content; + + if ( ! empty( $compat['tag'] ) ) + $output .= sprintf( '%s>', $compat['tag'] );; + + return $output; +} + +/** * Verifies that an email is valid. * * Does not grok i18n domains. Not RFC compliant. diff --git wp-includes/post.php wp-includes/post.php index 716447f..b36c208 100644 --- wp-includes/post.php +++ wp-includes/post.php @@ -1899,6 +1899,30 @@ function get_post_custom_values( $key = '', $post_id = 0 ) { } /** + * Retrieve metadata for current post format + * + * @since 3.6.0 + * + * @param int $post_id + * @return null + */ +function get_post_format_meta( $post_id = 0 ) { + $keys = get_post_custom( $post_id ); + if ( empty( $keys ) ) + return null; + + $values = array(); + foreach ( $keys as $key => $value ) { + if ( 0 === strpos( $key, '_wp_format_' ) ) { + $slug = str_replace( '_wp_format_', '', $key ); + $values[$slug] = $value[0]; + } + } + + return $values; +} + +/** * Check if post is sticky. * * Sticky posts should remain at the top of The Loop. If the post ID is not