Return to Snippet

Revision: 69915
at October 8, 2015 05:51 by julian90


Initial Code
<?php
/*
Plugin Name: UTMOST CO. WIDGETS
Description: Site specific code changes for utmostco.com
*/
/* Start Adding Functions Below this Line */

/* VIDEO MODAL START */

class UtmostVideoModalWidget extends WP_Widget {
    public function __construct() {
        $widget_options = array(
            'classname'    => 'utmost-video-modal-widget',
            'description'  => 'A modal that autoplays videos.'
        );

        parent::WP_Widget('utmost-video-modal-widget', 'Utmost Video Modal', $widget_options);
    }

    /**
     * Outputs the content of the widget
     *
     * @param array $args
     * @param array $instance
     */
    public function widget( $args, $instance ) {
        extract( $args, EXTR_SKIP );
        $videoId = (isset( $instance['videoId'] )) ? esc_attr($instance['videoId']) : '';
        $videoThumbnail = (isset( $instance['videoThumbnail'] )) ? esc_attr($instance['videoThumbnail']) : '';

        if ( (isset( $instance['videoThumbnail'] )) ? esc_attr($instance['videoThumbnail']) : '' ) { ?>

          <a href="https://www.youtube.com/watch?v=<?php echo $videoId; ?>"   rel="wp-video-lightbox"class="modal-click">
            <img src="<?php echo $videoThumbnail; ?>"          
          </a>

        <?php 
        } else {
        ?>

        <a href="https://www.youtube.com/watch?v=<?php echo $videoId; ?>" style="width: 100%; height: auto; margin: 0; border: none;" rel="wp-video-lightbox"class="modal-click">
            <img style="width: 100%; height: auto; margin: 0; border: none;"src="http://img.youtube.com/vi/<?php echo $videoId; ?>/mqdefault.jpg">
        </a>
        
    <?php
      }
    }

    /**
     * Outputs the options form on admin
     *
     * @param array $instance The widget options
     */
    public function form( $instance ) {
        ?>
        <div>
            <label style="display: block; margin-top:15px;" for="<?php echo $this->get_field_id('videoId');?>">
                Video ID
            </label>
            <br />
            <input style="width:100%; margin-bottom:15px;" id="<?php echo $this->get_field_id('videoId');?>"
                   name="<?php echo $this->get_field_name('videoId');?>"
                   value="<?php echo esc_attr($instance['videoId']); ?>" /><br>
            <label style="display: block; margin-bottom:15px;" for="<?php echo $this->get_field_id('videoId');?>">
                Modal Thumbnail<br>
                Creates a text link that is clicked to launch the modal.<br>
                (Leave this field blank to use default YouTube thumbnail.)
            </label>
            <input style="width:100%; margin-bottom:15px;" id="<?php echo $this->get_field_id('videoThumbnail');?>"
                   name="<?php echo $this->get_field_name('videoThumbnail');?>"
                   value="<?php echo esc_attr($instance['videoThumbnail']); ?>" />
        </div>
    <?php
    }
}

function utmost_video_modal_widget_init() {
    register_widget('UtmostVideoModalWidget');
}
add_action('widgets_init', 'utmost_video_modal_widget_init');

/* VIDEO MODAL END */




/* Stop Adding Functions Below this Line */
?>

Initial URL

                                

Initial Description
A plugin that adds widget functionality to a third-party video modal plugin. The widget accepts a YouTube video ID and a thumbnail URL of the user's choice. It then generates a thumbnail link that launches a video modal via the third-party plugin. Optionally, if the user chooses to leave the thumbnail field blank, the default YouTube video thumbnail is used as the anchor to launch the modal.

Initial Title
WordPress Video Modal Widget

Initial Tags
php, plugin, wordpress

Initial Language
PHP