Making WordPress.org

Ticket #976: 976.diff

File 976.diff, 2.0 KB (added by nathanshubert, 10 years ago)
  • functions.php

    diff --git functions.php functions.php
    index 24cc677..8a3e4f4 100644
    class WordPressTV_Theme { 
    1313                        require_once get_template_directory() . '/plugins/wordpresstv-rest/wordpresstv-rest.php';
    1414                        require_once get_template_directory() . '/plugins/wordpresstv-anon-upload/anon-upload.php';
    1515                        require_once get_template_directory() . '/plugins/wordpresstv-upload-subtitles/wordpresstv-upload-subtitles.php';
     16                        require_once get_template_directory() . '/plugins/wordpresstv-twitter-player/wordpresstv-twitter-player.php';
    1617
    1718                        add_action( 'after_setup_theme', array( $this, 'setup' ) );
    1819                }
  • new file plugins/wordpresstv-twitter-player/wordpresstv-twitter-player.php

    diff --git plugins/wordpresstv-twitter-player/wordpresstv-twitter-player.php plugins/wordpresstv-twitter-player/wordpresstv-twitter-player.php
    new file mode 100644
    index 0000000..28cf8c4
    - +  
     1<?php
     2
     3/**
     4 * Add Twitter card player
     5 *
     6 */
     7
     8class WordPressTV_TwitterPlayer {
     9
     10        function __construct() {
     11
     12                global $wp_query;
     13                $post = $wp_query->post;
     14                $atts = shortcode_parse_atts($post->post_content);
     15                $video_id = false;
     16                $output = false;
     17
     18                preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER );
     19
     20                // Loop through matched shortcodes
     21                foreach ( $matches as $match ) {
     22                        // Check for wpvideo
     23                        if ( isset($match[2]) && $match[2] == 'wpvideo' ) {
     24                                $video_id = isset($match[3]) ? $match[3] : false;
     25                        }                       
     26                }
     27
     28                // If an ID was found print twitter:card tags
     29                if ( $video_id ) {
     30                        $output = '<meta name="twitter:player" content="https://videopress.com/v/' . $video_id . '?autoplay=0" />';
     31
     32                        // This meta value should be the mp4 value from VideoPress
     33                        $output .= '<meta name="twitter:player:stream" content="" />';
     34                }
     35
     36                if ( $output ) {
     37                        echo $output;
     38                }
     39
     40        }
     41
     42}
     43
     44function wptv_twitterplayer_init() {
     45        $WordPressTV_TwitterPlayer = new WordPressTV_TwitterPlayer();
     46}
     47
     48add_action( 'wp_head', 'wptv_twitterplayer_init' );