widget_cssclass = 'blogmarks_youtube_video'; $this->widget_description = __( 'Displays youtube video form your channel.', 'blogmarks' ); $this->widget_id = 'blogmarks_youtube_video'; $this->widget_name = __( 'Blogmarks: Youtube Video', 'blogmarks' ); $this->settings = array( 'title' => array( 'type' => 'text', 'label' => __( 'Title', 'blogmarks' ), ), 'channel_url' => array( 'type' => 'url', 'label' => __( 'Channel URL:', 'blogmarks' ), 'desc' => __('Please make sure to provide a complete URL that includes either "http://" or "https://" to ensure the widget operates correctly.', 'blogmarks'), ), 'channel_name' => array( 'type' => 'text', 'label' => __( 'Channel Name:', 'blogmarks' ), ), 'video_url' => array( 'type' => 'url', 'label' => __( 'Video URL:', 'blogmarks' ), 'desc' => __('Please make sure to provide a complete URL that includes either "http://" or "https://" to ensure the widget operates correctly.', 'blogmarks'), ), ); parent::__construct(); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) ); } /** * Output widget. * * @see WP_Widget * * @param array $args * @param array $instance */ public function widget( $args, $instance ) { ob_start(); $channel_url = isset( $instance['channel_url'] ) ? $instance['channel_url'] : $this->settings['channel_url']['std']; $channel_name = isset( $instance['channel_name'] ) ? $instance['channel_name'] : $this->settings['channel_name']['std']; $video_url = isset( $instance['video_url'] ) ? $instance['video_url'] : $this->settings['video_url']['std']; $this->widget_start( $args, $instance ); ?>
widget_end( $args ); echo ob_get_clean(); } public function enqueue_assets() { if ( is_active_widget( false, false, $this->id_base ) ) { $file_prefix = is_rtl() ? '-rtl' : ''; $css_file = get_template_directory() . '/include/widgets/assets/youtube-video' . $file_prefix . '.css'; if ( file_exists( $css_file ) ) { $styles = wp_strip_all_tags( file_get_contents( $css_file ) ); wp_add_inline_style( 'blogmarks-style', $styles ); } } } }