| | 580 | |
| | 581 | /** |
| | 582 | * Echoes the first found video from current post. |
| | 583 | * |
| | 584 | * @uses twentythirteen_get_first_post_video |
| | 585 | * |
| | 586 | * @print string HTML |
| | 587 | */ |
| | 588 | function twentythirteen_first_post_video() { |
| | 589 | $first_video = twentythirteen_get_first_post_video(); |
| | 590 | |
| | 591 | if ( ! empty( $first_video ) ) |
| | 592 | echo apply_filters( 'the_content', $first_video ); |
| | 593 | } |
| | 594 | |
| | 595 | /** |
| | 596 | * Finds first video from a given post. |
| | 597 | * |
| | 598 | * 1. Tries for a video source element in post content. |
| | 599 | * 2. Tries for a video embed in post content. |
| | 600 | * 3. Tries for an attached video. |
| | 601 | * |
| | 602 | * @todo If content_ or embedded_ are true, make sure the post content gets filtered without the video |
| | 603 | * |
| | 604 | * @param object $post |
| | 605 | * @return string Video URL |
| | 606 | */ |
| | 607 | function twentythirteen_get_first_post_video() { |
| | 608 | global $post; |
| | 609 | |
| | 610 | $the_content = $post->post_content; |
| | 611 | $first_video = ''; |
| | 612 | |
| | 613 | $content_video = get_content_video( $the_content, true ); |
| | 614 | // @todo If valid, need to make sure the_content gets filtered without the video |
| | 615 | |
| | 616 | if ( ! empty( $content_video ) ) |
| | 617 | $post->post_content = $the_content; |
| | 618 | |
| | 619 | if ( empty( $content_video ) ) { |
| | 620 | $first_video = get_embedded_video( $the_content, true ); |
| | 621 | // @todo If valid, need to make sure the_content gets filtered without the video |
| | 622 | |
| | 623 | if ( empty( $first_video ) ) |
| | 624 | $first_video = get_attached_video( $post ); |
| | 625 | } |
| | 626 | |
| | 627 | if ( is_array( $first_video ) ) |
| | 628 | $first_video = $first_video[0]; |
| | 629 | |
| | 630 | return $first_video; |
| | 631 | } |
| | 632 | No newline at end of file |