js
1 year ago
about-me.php
2 years ago
contact-info.php
5 years ago
custom-header-logo.php
6 years ago
custom-header-nav.php
6 years ago
custom-links.php
4 years ago
custom-menu.php
6 years ago
facebook.php
2 years ago
flickr.php
1 day ago
instagram.php
3 years ago
mailchimp.php
2 years ago
recent-posts.php
4 years ago
social-share.php
9 months ago
social.php
2 years ago
tags.php
6 years ago
twitter.php
2 years ago
video.php
6 years ago
video.php
136 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Video widget. |
| 4 | * |
| 5 | * @package OceanWP WordPress theme |
| 6 | */ |
| 7 | |
| 8 | // Exit if accessed directly |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; |
| 11 | } |
| 12 | |
| 13 | if ( ! class_exists( 'Ocean_Extra_Video_Widget' ) ) { |
| 14 | class Ocean_Extra_Video_Widget extends WP_Widget { |
| 15 | |
| 16 | /** |
| 17 | * Register widget with WordPress. |
| 18 | * |
| 19 | * @since 1.0.0 |
| 20 | */ |
| 21 | public function __construct() { |
| 22 | parent::__construct( |
| 23 | 'ocean_video', |
| 24 | esc_html__( '» Video', 'ocean-extra' ), |
| 25 | array( |
| 26 | 'classname' => 'widget-oceanwp-video video-widget', |
| 27 | 'description' => esc_html__( 'Easily to display any type of video.', 'ocean-extra' ), |
| 28 | 'customize_selective_refresh' => true, |
| 29 | ) |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Front-end display of widget. |
| 35 | * |
| 36 | * @see WP_Widget::widget() |
| 37 | * @since 1.0.0 |
| 38 | * |
| 39 | * @param array $args Widget arguments. |
| 40 | * @param array $instance Saved values from database. |
| 41 | */ |
| 42 | public function widget( $args, $instance ) { |
| 43 | |
| 44 | $title = isset( $instance['title'] ) ? apply_filters( 'widget_title', $instance['title'] ) : ''; |
| 45 | $video_url = isset( $instance['video_url'] ) ? $instance['video_url'] : ''; |
| 46 | $description = isset( $instance['video_description'] ) ? $instance['video_description'] : ''; |
| 47 | |
| 48 | // Before widget WP hook |
| 49 | echo $args['before_widget']; |
| 50 | |
| 51 | // Show widget title |
| 52 | if ( $title ) { |
| 53 | echo $args['before_title'] . esc_html( $title ) . $args['after_title']; |
| 54 | } |
| 55 | |
| 56 | // Show video |
| 57 | if ( $video_url ) { |
| 58 | echo '<p class="responsive-video-wrap clr">'; |
| 59 | echo wp_oembed_get( $video_url, array( |
| 60 | 'width' => 270 |
| 61 | ) ); |
| 62 | echo '</p>'; |
| 63 | } else { |
| 64 | esc_html_e( 'You forgot to enter a video URL.', 'ocean-extra' ); |
| 65 | } |
| 66 | |
| 67 | // Show video description if field isn't empty |
| 68 | if ( $description ) { |
| 69 | echo '<div class="oceanwp-video-widget-description">'. do_shortcode( $description ) .'</div>'; |
| 70 | } |
| 71 | |
| 72 | // After widget WP hook |
| 73 | echo $args['after_widget']; |
| 74 | |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Sanitize widget form values as they are saved. |
| 79 | * |
| 80 | * @see WP_Widget::update() |
| 81 | * @since 1.0.0 |
| 82 | * |
| 83 | * @param array $new_instance Values just sent to be saved. |
| 84 | * @param array $old_instance Previously saved values from database. |
| 85 | * |
| 86 | * @return array Updated safe values to be saved. |
| 87 | */ |
| 88 | public function update( $new_instance, $old_instance ) { |
| 89 | $instance = $old_instance; |
| 90 | $instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : ''; |
| 91 | $instance['video_url'] = ! empty( $new_instance['video_url'] ) ? esc_url( $new_instance['video_url'] ) : ''; |
| 92 | $instance['video_description'] = ! empty( $new_instance['video_description'] ) ? strip_tags( $new_instance['video_description'] ) : ''; |
| 93 | return $instance; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Back-end widget form. |
| 98 | * |
| 99 | * @see WP_Widget::form() |
| 100 | * @since 1.0.0 |
| 101 | * |
| 102 | * @param array $instance Previously saved values from database. |
| 103 | */ |
| 104 | public function form( $instance ) { |
| 105 | |
| 106 | // Parse arguments |
| 107 | $instance = wp_parse_args((array) $instance, array( |
| 108 | 'title' => esc_attr__( 'Video', 'ocean-extra' ), |
| 109 | 'video_url' => '', |
| 110 | 'video_description' => '', |
| 111 | ) ); ?> |
| 112 | |
| 113 | <p> |
| 114 | <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title', 'ocean-extra' ); ?>:</label> |
| 115 | <input class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" /> |
| 116 | </p> |
| 117 | |
| 118 | <p> |
| 119 | <label for="<?php echo esc_attr( $this->get_field_id( 'video_url' ) ); ?>"> |
| 120 | <?php esc_html_e( 'Video URL ', 'ocean-extra' ); ?></label> |
| 121 | <input class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'video_url' ) ); ?>" type="text" value="<?php echo esc_attr( esc_url( $instance['video_url'] ) ); ?>" /> |
| 122 | <span style="display:block;padding:5px 0" class="description"><?php esc_html_e( 'Enter in a video URL that is compatible with WordPress\'s built-in oEmbed feature.', 'ocean-extra' ); ?> <a href="http://codex.wordpress.org/Embeds" target="_blank"><?php esc_html_e( 'Learn More', 'ocean-extra' ); ?></a></span> |
| 123 | </p> |
| 124 | |
| 125 | <p> |
| 126 | <label for="<?php echo esc_attr( $this->get_field_id( 'video_description' ) ); ?>"><?php esc_html_e( 'Description', 'ocean-extra' ); ?></label> |
| 127 | <textarea rows="15" id="<?php echo esc_attr( $this->get_field_id( 'video_description' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'video_description' ) ); ?>" class="widefat" style="height: 100px;"><?php if( !empty( $instance['video_description'] ) ) { echo esc_textarea( $instance['video_description'] ); } ?></textarea> |
| 128 | </p> |
| 129 | |
| 130 | <?php |
| 131 | |
| 132 | } |
| 133 | |
| 134 | } |
| 135 | } |
| 136 | register_widget( 'Ocean_Extra_Video_Widget' ); |