| 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 post content without the chosen piece of media (video, image, etc). |
| 457 | * |
| 458 | * @uses twentythirteen_get_split_content |
| 459 | * |
| 460 | * @print HTML |
| 461 | */ |
| 462 | function twentythirteen_split_content() { |
| 463 | echo twentythirteen_get_split_content( 'rest' ); |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * Finds first media piece in a given post. |
| 468 | * |
| 469 | * 1. Find a URL or media embed in post format meta. |
| 470 | * 2. Find a source element in post content. |
| 471 | * 3. Find an embed in post content. |
| 472 | * 4. Find an attachment. |
| 473 | * |
| 474 | * @param string $return Whether to return the URL or the filtered content. |
| 475 | * @return string Either URL of the first media piece found, or the rest of the content without the piece. |
| 476 | */ |
| 477 | function twentythirteen_get_split_content( $return = 'url' ) { |
| 478 | $format = get_post_format(); |
| 479 | $post_meta = get_post_format_meta( get_the_ID() ); |
| 480 | $post_content = get_the_content(); |
| 481 | |
| 482 | $media_url = $post_meta['url']; |
| 483 | |
| 484 | if ( empty( $media_url ) ) { |
| 485 | $media_url = $post_meta['media']; |
| 486 | |
| 487 | if ( empty( $media_url ) ) { |
| 488 | $media_url = get_content_video( $post_content, true ); |
| 489 | |
| 490 | if ( empty( $media_url ) ) { |
| 491 | $media_url = get_embedded_video( $post_content, true ); |
| 492 | |
| 493 | if ( empty( $media_url ) ) |
| 494 | $media_url = get_attached_video( get_the_ID() ); |
| 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | if ( 'rest' === $return ) |
| 500 | return $post_content; |
| 501 | |
| 502 | return $media_url; |
| 503 | } |
| 504 | |