Changeset 24021 for trunk/wp-includes/post-formats.php
- Timestamp:
- 04/17/2013 08:57:44 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/post-formats.php
r23992 r24021 82 82 */ 83 83 function get_post_format_meta( $post_id = 0 ) { 84 $values = array( 85 'quote' => '', 86 'quote_source' => '', 87 'url' => '', 88 'image' => '', 89 'gallery' => '', 90 'audio' => '', 91 'video' => '', 84 $meta = get_post_meta( $post_id ); 85 $keys = array( 'quote', 'quote_source_name', 'quote_source_url', 'link_url', 'gallery', 'audio_embed', 'video_embed', 'url', 'image' ); 86 87 if ( empty( $meta ) ) 88 return array_fill_keys( $keys, '' ); 89 90 $upgrade = array( 91 '_wp_format_quote_source' => 'quote_source_name', 92 '_wp_format_audio' => 'audio_embed', 93 '_wp_format_video' => 'video_embed' 92 94 ); 93 95 94 foreach ( $values as $key => $value ) 95 $values[$key] = get_post_meta( $post_id, '_wp_format_' . $key, true ); 96 $format = get_post_format( $post_id ); 97 if ( ! empty( $format ) ) { 98 switch ( $format ) { 99 case 'link': 100 $upgrade['_wp_format_url'] = 'link_url'; 101 break; 102 case 'quote': 103 $upgrade['_wp_format_url'] = 'quote_source_url'; 104 break; 105 } 106 } 107 108 $upgrade_keys = array_keys( $upgrade ); 109 foreach ( $meta as $key => $values ) { 110 if ( ! in_array( $key, $upgrade_keys ) ) 111 continue; 112 update_post_meta( $post_id, '_format_' . $upgrade[$key], reset( $values ) ); 113 delete_post_meta( $post_id, $key ); 114 } 115 116 $values = array(); 117 118 foreach ( $keys as $key ) { 119 $value = get_post_meta( $post_id, '_format_' . $key, true ); 120 $values[$key] = empty( $value ) ? '' : $value; 121 } 96 122 97 123 return $values; … … 325 351 $compat['position'] = 'before'; 326 352 327 if ( ! empty( $meta[' url'] ) ) {328 $esc_url = preg_quote( $meta[' url'], '#' );353 if ( ! empty( $meta['link_url'] ) ) { 354 $esc_url = preg_quote( $meta['link_url'], '#' ); 329 355 // Make sure the same URL isn't in the post (modified/extended versions allowed) 330 356 if ( ! preg_match( '#' . $esc_url . '[^/&\?]?#', $content ) ) { 331 $url = $meta[' url'];357 $url = $meta['link_url']; 332 358 } else { 333 359 $url = get_content_url( $content, true ); … … 345 371 empty( $compat['link_class'] ) ? '' : sprintf( 'class="%s" ', esc_attr( $compat['link_class'] ) ), 346 372 esc_url( $url ), 347 empty( $post->post_title ) ? esc_url( $meta[' url'] ) : apply_filters( 'the_title', $post->post_title, $post->ID )373 empty( $post->post_title ) ? esc_url( $meta['link_url'] ) : apply_filters( 'the_title', $post->post_title, $post->ID ) 348 374 ); 349 375 } … … 376 402 if ( ! empty( $meta['quote'] ) && ! stristr( $content, $meta['quote'] ) ) { 377 403 $quote = sprintf( '<blockquote>%s</blockquote>', wpautop( $meta['quote'] ) ); 378 if ( ! empty( $meta['quote_source '] ) ) {379 $source = ( empty( $meta[' url'] ) ) ? $meta['quote_source'] : sprintf( '<a href="%s">%s</a>', esc_url( $meta['url'] ), $meta['quote_source'] );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'] ); 380 406 $quote .= sprintf( '<figcaption class="quote-caption">%s</figcaption>', $source ); 381 407 } … … 386 412 case 'video': 387 413 case 'audio': 388 if ( ! has_shortcode( $post->post_content, $format ) && ! empty( $meta[$format] ) ) { 414 if ( ! has_shortcode( $post->post_content, $format ) && ! empty( $meta[$format . '_embed'] ) ) { 415 $value = $meta[$format . '_embed']; 389 416 // the metadata is an attachment ID 390 if ( is_numeric( $ meta[$format]) ) {391 $url = wp_get_attachment_url( $ meta[$format]);417 if ( is_numeric( $value ) ) { 418 $url = wp_get_attachment_url( $value ); 392 419 $format_output .= sprintf( '[%s src="%s"]', $format, $url ); 393 420 // the metadata is a shortcode or an embed code 394 } elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $ meta[$format] ) || preg_match( '#<[^>]+>#', $meta[$format]) ) {395 $format_output .= $ meta[$format];396 } elseif ( ! stristr( $content, $ meta[$format]) ) {421 } elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $value ) || preg_match( '#<[^>]+>#', $value ) ) { 422 $format_output .= $value; 423 } elseif ( ! stristr( $content, $value ) ) { 397 424 // attempt to embed the URL 398 $format_output .= sprintf( '[embed]%s[/embed]', $ meta[$format]);425 $format_output .= sprintf( '[embed]%s[/embed]', $value ); 399 426 } 400 427 } … … 708 735 return ''; 709 736 710 if ( in_array( get_post_format( $post->ID ), array( 'image', 'link', 'quote' ) ) ) { 737 $format = get_post_format( $post->ID ); 738 if ( in_array( $format, array( 'image', 'link', 'quote' ) ) ) { 711 739 $meta = get_post_format_meta( $post->ID ); 712 if ( ! empty( $meta['url'] ) ) 713 return apply_filters( 'get_the_post_format_url', esc_url_raw( $meta['url'] ), $post ); 740 $meta_link = ''; 741 742 switch ( $format ) { 743 case 'link': 744 if ( ! empty( $meta['link_url'] ) ) 745 $meta_link = $meta['link_url']; 746 break; 747 case 'image': 748 if ( ! empty( $meta['url'] ) ) 749 $meta_link = $meta['url']; 750 break; 751 case 'quote': 752 if ( ! empty( $meta['quote_source_url'] ) ) 753 $meta_link = $meta['quote_source_url']; 754 break; 755 } 756 757 if ( ! empty( $meta_link ) ) 758 return apply_filters( 'get_the_post_format_url', esc_url_raw( $meta_link ), $post ); 714 759 } 715 760
Note: See TracChangeset
for help on using the changeset viewer.