| | 439 | /** |
| | 440 | * Echoes the first found video from current post. |
| | 441 | * |
| | 442 | * @uses twentythirteen_get_split_content |
| | 443 | * |
| | 444 | * @print HTML |
| | 445 | */ |
| | 446 | function twentythirteen_post_video() { |
| | 447 | $first_video = twentythirteen_get_split_content( 'url' ); |
| | 448 | |
| | 449 | if ( is_array( $first_video ) ) |
| | 450 | $first_video = $first_video[0]; |
| | 451 | |
| | 452 | echo wp_oembed_get( $first_video ); |
| | 453 | } |
| | 454 | |
| | 455 | /** |
| | 456 | * Echoes the first found image from current post. |
| | 457 | * |
| | 458 | * @uses twentythirteen_get_split_content |
| | 459 | * |
| | 460 | * @print HTML |
| | 461 | */ |
| | 462 | function twentythirteen_post_image() { |
| | 463 | $first_image = twentythirteen_get_split_content( 'url' ); |
| | 464 | |
| | 465 | if ( is_array( $first_image ) ) |
| | 466 | $first_image = array_shift( $first_image ); |
| | 467 | |
| | 468 | if ( is_string( $first_image ) ) { |
| | 469 | echo '<img' . ' src="' . $first_image .'" alt="" />'; |
| | 470 | /* |
| | 471 | @todo Update core functions to return the image HTML instead of just the src attribute value |
| | 472 | |
| | 473 | get_content_images() |
| | 474 | get_content_image() |
| | 475 | |
| | 476 | Add an option to return <img /> HTML string instead of just the `src` attribute value. |
| | 477 | |
| | 478 | Or, return the attachment ID if the image string looks like an attachment |
| | 479 | |
| | 480 | That'd be even better -- since we could then use `wp_get_attachment_image()` to output the image instead of a) trusting the returned HTML and b) trying to build the image HTML string from scratch. |
| | 481 | */ |
| | 482 | } else if ( is_object( $first_image ) ) { |
| | 483 | echo wp_get_attachment_image( $first_image->ID, array( 724, 724 ) ); |
| | 484 | } |
| | 485 | } |
| | 486 | |
| | 487 | /** |
| | 488 | * Echoes the post content without the chosen piece of media (video, image, etc). |
| | 489 | * |
| | 490 | * @uses twentythirteen_get_split_content |
| | 491 | * |
| | 492 | * @print HTML |
| | 493 | */ |
| | 494 | function twentythirteen_split_content() { |
| | 495 | echo twentythirteen_get_split_content( 'rest' ); |
| | 496 | } |
| | 497 | |
| | 498 | /** |
| | 499 | * Finds first media piece in a given post. |
| | 500 | * |
| | 501 | * 1. Find a URL or media embed in post format meta. |
| | 502 | * 2. Find a source element in post content. |
| | 503 | * 3. Find an embed in post content. |
| | 504 | * 4. Find an attachment. |
| | 505 | * |
| | 506 | * @param string $return Whether to return the URL or the filtered content. |
| | 507 | * @return mixed string: URL of the first media piece found, or the rest of the content without the piece |
| | 508 | * or array if finding image attachments. |
| | 509 | */ |
| | 510 | function twentythirteen_get_split_content( $return = 'url' ) { |
| | 511 | $format = get_post_format(); |
| | 512 | $post_content = get_the_content(); |
| | 513 | $media_item = ''; |
| | 514 | |
| | 515 | if ( 'video' == $format ) { |
| | 516 | $post_meta = get_post_format_meta( get_the_ID() ); |
| | 517 | |
| | 518 | $media_item = $post_meta['url']; |
| | 519 | |
| | 520 | if ( empty( $media_item ) ) { |
| | 521 | $media_item = $post_meta['media']; |
| | 522 | |
| | 523 | if ( empty( $media_item ) ) { |
| | 524 | $media_item = get_content_video( $post_content, true ); |
| | 525 | |
| | 526 | if ( empty( $media_item ) ) { |
| | 527 | $media_item = get_embedded_video( $post_content, true ); |
| | 528 | |
| | 529 | if ( empty( $media_item ) ) |
| | 530 | $media_item = get_attached_video( get_the_ID() ); |
| | 531 | } |
| | 532 | } |
| | 533 | } |
| | 534 | } else if ( 'image' == $format ) { |
| | 535 | $media_item = get_content_image( $post_content, true ); |
| | 536 | |
| | 537 | if ( empty( $media_item ) ) |
| | 538 | $media_item = get_attached_images( get_the_ID() ); |
| | 539 | } |
| | 540 | |
| | 541 | if ( 'rest' === $return ) |
| | 542 | return $post_content; |
| | 543 | |
| | 544 | return $media_item; |
| | 545 | } |
| | 546 | |