Changeset 24387
- Timestamp:
- 05/30/2013 05:55:22 PM (11 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/default-filters.php
r24301 r24387 137 137 add_filter( 'the_title', '_post_formats_title', 10, 2 ); 138 138 139 add_filter( 'the_content', 'post_formats_compat', 7, 2 ); 140 add_filter( 'the_content', 'wptexturize' ); 141 add_filter( 'the_content', 'convert_smilies' ); 142 add_filter( 'the_content', 'convert_chars' ); 143 add_filter( 'the_content', 'wpautop' ); 144 add_filter( 'the_content', 'shortcode_unautop' ); 145 add_filter( 'the_content', 'prepend_attachment' ); 139 add_filter( 'the_content', 'wptexturize' ); 140 add_filter( 'the_content', 'convert_smilies' ); 141 add_filter( 'the_content', 'convert_chars' ); 142 add_filter( 'the_content', 'wpautop' ); 143 add_filter( 'the_content', 'shortcode_unautop' ); 144 add_filter( 'the_content', 'prepend_attachment' ); 146 145 147 146 add_filter( 'the_excerpt', 'wptexturize' ); -
trunk/wp-includes/post-formats.php
r24353 r24387 285 285 } 286 286 add_filter( 'wp_get_object_terms', '_post_format_wp_get_object_terms' ); 287 288 /**289 * Return the class for a post format content wrapper290 *291 * @since 3.6.0292 *293 * @param string $format The post format slug, such as status, quote, image, gallery, etc.294 * @return string Filtered post format content class.295 */296 function get_post_format_content_class( $format ) {297 return apply_filters( 'post_format_content_class', 'post-format-content', $format );298 }299 300 /**301 * Output the class for a post format content wrapper302 *303 * @since 3.6.0304 *305 * @param string $format The post format slug, such as status, quote, image, gallery, etc.306 */307 function post_format_content_class( $format ) {308 echo get_post_format_content_class( $format );309 }310 311 /**312 * Provide fallback behavior for Posts that have associated post format313 *314 * @since 3.6.0315 *316 * @uses get_post_format_meta()317 *318 * @param string $content The post content.319 * @param int $post_id (optional) The post ID.320 * @return string Formatted output based on associated post format.321 */322 function post_formats_compat( $content, $post_id = 0 ) {323 if ( ! $post = get_post( $post_id ) )324 return $content;325 326 $format = get_post_format( $post );327 if ( empty( $format ) || in_array( $format, array( 'status', 'aside', 'chat', 'gallery' ) ) )328 return $content;329 330 if ( current_theme_supports( 'structured-post-formats', $format ) )331 return $content;332 333 $defaults = array(334 'position' => 'after',335 'tag' => 'div',336 'class' => get_post_format_content_class( $format ),337 'link_class' => '',338 );339 340 $args = apply_filters( 'post_format_compat', array() );341 $compat = wp_parse_args( $args, $defaults );342 343 $show_content = true;344 $format_output = '';345 $meta = get_post_format_meta( $post->ID );346 347 switch ( $format ) {348 case 'link':349 if ( ! empty( $meta['link_url'] ) ) {350 $esc_url = preg_quote( $meta['link_url'], '#' );351 // Make sure the same URL isn't in the post (modified/extended versions allowed)352 if ( ! preg_match( '#' . $esc_url . '[^/&\?]?#', $content ) ) {353 $url = $meta['link_url'];354 } else {355 $url = get_content_url( $content, true );356 }357 } else {358 $content_before = $content;359 $url = get_content_url( $content, true );360 if ( $content_before == $content )361 $url = '';362 }363 364 if ( ! empty( $url ) ) {365 $format_output .= sprintf(366 '<a %shref="%s">%s</a>',367 empty( $compat['link_class'] ) ? '' : sprintf( 'class="%s" ', esc_attr( $compat['link_class'] ) ),368 esc_url( $url ),369 empty( $post->post_title ) ? esc_url( $url ) : apply_filters( 'the_title', $post->post_title, $post->ID )370 );371 }372 break;373 374 case 'image':375 if ( ! empty( $meta['image'] ) ) {376 377 if ( has_shortcode( $meta['image'], 'caption' ) ) {378 // wrap <img> in <a>379 if ( ! empty( $meta['url'] ) && false === strpos( $meta['image'], '<a ' ) ) {380 $meta['image'] = preg_replace(381 '#(<img[^>]+>)#',382 sprintf( '<a href="%s">$1</a>', esc_url( $meta['url'] ) ),383 $meta['image']384 );385 }386 $format_output .= do_shortcode( $meta['image'] );387 } else {388 389 if ( is_numeric( $meta['image'] ) ) {390 $image = wp_get_attachment_image( absint( $meta['image'] ), 'full' );391 } elseif ( ! preg_match( '#<[^>]+>#', $meta['image'] ) ) {392 // not HTML, assume URL393 $image = sprintf(394 '<img %ssrc="%s" alt="" />',395 empty( $compat['image_class'] ) ? '' : sprintf( 'class="%s" ', esc_attr( $compat['image_class'] ) ),396 esc_url( $meta['image'] )397 );398 } else {399 // assume HTML400 $image = $meta['image'];401 }402 403 if ( ! empty( $meta['url'] ) && false === strpos( $image, '<a ' ) ) {404 $format_output .= sprintf(405 '<a href="%s">%s</a>',406 esc_url( $meta['url'] ),407 $image408 );409 } else {410 $format_output .= $image;411 }412 }413 }414 break;415 416 case 'quote':417 $quote = get_the_post_format_quote( $post );418 419 // Replace the existing quote in-place.420 if ( ! empty( $quote ) )421 get_content_quote( $content, true, $quote );422 break;423 424 case 'video':425 case 'audio':426 if ( ! has_shortcode( $post->post_content, $format ) && ! empty( $meta[$format . '_embed'] ) ) {427 $value = $meta[$format . '_embed'];428 // the metadata is an attachment ID429 if ( is_numeric( $value ) ) {430 $url = wp_get_attachment_url( $value );431 $format_output .= sprintf( '[%s src="%s"]', $format, $url );432 // the metadata is a shortcode or an embed code433 } elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $value ) || preg_match( '#<[^>]+>#', $value ) ) {434 $format_output .= $value;435 } elseif ( ! stristr( $content, $value ) ) {436 // attempt to embed the URL437 $format_output .= sprintf( '[embed]%s[/embed]', $value );438 }439 }440 break;441 default:442 return $content;443 break;444 }445 446 if ( empty( $format_output ) )447 return $content;448 449 $output = '';450 451 if ( ! empty( $content ) && $show_content && 'before' !== $compat['position'] )452 $output .= $content . "\n\n";453 454 if ( ! empty( $compat['tag'] ) )455 $output .= sprintf( '<%s class="%s">', tag_escape( $compat['tag'] ), esc_attr( $compat['class'] ) );456 457 $output .= "\n\n" . $format_output;458 459 if ( ! empty( $compat['tag'] ) )460 $output .= sprintf( '</%s>', tag_escape( $compat['tag'] ) );461 462 if ( ! empty( $content ) && $show_content && 'before' === $compat['position'] )463 $output .= "\n\n" . $content;464 465 return $output;466 }467 287 468 288 /**
Note: See TracChangeset
for help on using the changeset viewer.