Make WordPress Core

Ticket #23620: 23620.diff

File 23620.diff, 2.3 KB (added by lancewillett, 12 years ago)
  • wp-content/themes/twentythirteen/functions.php

     
    577577 * Adds support for a custom header image.
    578578 */
    579579require( get_template_directory() . '/inc/custom-header.php' );
     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 */
     588function 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 */
     607function 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
  • wp-content/themes/twentythirteen/content-video.php

     
    1010
    1111<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    1212        <header class="entry-header">
     13                <?php twentythirteen_first_post_video(); ?>
     14
    1315                <?php if ( is_single() ) : ?>
    1416                <h1 class="entry-title"><?php the_title(); ?></h1>
    1517                <?php else : ?>