'widget_image', 'description' => esc_html__( 'Image Widget', 'passport' ) ); parent::__construct( 'passport_image_widget', esc_html__( 'Passport Image Widget', 'passport' ), $widget_ops ); $this->alt_option_name = 'widget_image'; add_action( 'admin_enqueue_scripts', array( $this, 'upload_scripts' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'passport_widget_inline_style' ) ); } /** * Styling the widget */ public function passport_widget_inline_style() { $i = 0; $widget_options = get_option( $this->option_name ); $custom_widget_css = ''; if( is_array( $widget_options ) && count( $widget_options ) > 0 ) { foreach ( $widget_options as $key => $widget_option ) { $widget_width_option = isset( $widget_option['width'] ) ? $widget_option['width'] : ''; $widget_height_option = isset( $widget_option['height'] ) ? $widget_option['height'] : ''; $widget_btn_color_option = isset( $widget_option['btn_color'] ) ? $widget_option['btn_color'] : ''; $widget_opacity_option = isset( $widget_option['opacity'] ) ? $widget_option['opacity'] : ''; if ( isset( $widget_min_height_option ) || isset( $widget_btn_color_option ) || isset( $widget_opacity_option ) ) { $custom_widget_css .= "#{$this->id_base}-{$key} figcaption {"; $custom_widget_css .= ! empty( $widget_height_option ) ? 'min-height:'. $widget_height_option .'px;' : ''; $custom_widget_css .= "}"; $custom_widget_css .= "#{$this->id_base}-{$key} .img-btn {"; $custom_widget_css .= ! empty( $widget_btn_color_option ) ? 'background-color:'. $widget_btn_color_option .';' :'background-color: #333333;'; $custom_widget_css .= ! empty( $widget_btn_color_option ) ? 'border-color:'. $widget_btn_color_option .';' :'border-color: #333333;'; $custom_widget_css .= "}"; $custom_widget_css .= "#{$this->id_base}-{$key} img {"; $custom_widget_css .= ! empty( $widget_width_option ) ? 'width:'. $widget_width_option .'px;' : ''; $custom_widget_css .= ! empty( $widget_height_option ) ? 'height:'. $widget_height_option .'px;' : ''; $custom_widget_css .= ! empty( $widget_opacity_option ) ? 'opacity:'. $widget_opacity_option .';' :'opacity: 1.0;'; $custom_widget_css .= "}"; } $i++; } } wp_add_inline_style( PASSPORT_THEME_SLUG . '-custom-style', $custom_widget_css ); } /** * Upload the Javascripts for the media uploader */ function upload_scripts( $instance ) { wp_register_script( PASSPORT_THEME_SLUG . '-wp-media-upload', get_template_directory_uri().'/assets/js/wp-media-uploadjs', array( 'jquery' ), PASSPORT_VERSION, true ); wp_enqueue_script( PASSPORT_THEME_SLUG . '-wp-media-upload' ); } // Creating widget front-end // This is where the action happens public function widget( $args, $instance ) { global $_wp_additional_image_sizes; $widget_image = ! empty( $instance['widget_image'] ) ? $instance['widget_image'] : ''; $link = ! empty( $instance['link']) ? $instance['link'] : ''; $alt = ! empty( $instance['alt']) ? $instance['alt'] : ''; $caption = ! empty( $instance['caption']) ? $instance['caption'] : ''; $text_btn = ! empty( $instance['text_btn']) ? $instance['text_btn'] : ''; $target = ! empty( $instance['target']) ? $instance['target'] : '_blank'; ?>
<?php echo esc_attr( $alt ); ?>
'', 'width' => '', 'height' => '', 'opacity' => '1.0', 'link' => '', 'alt' => '', 'caption' => '', 'text_btn' => '', 'target' => '_blank', 'btn_color' => '#333333' ) ); $widget_image = $instance['widget_image']; $width = $instance['width']; $height = $instance['height']; $opacity = $instance['opacity']; $link = $instance['link']; $alt = $instance['alt']; $caption = $instance['caption']; $text_btn = $instance['text_btn']; $target = $instance['target']; $btn_color = $instance['btn_color']; // Widget admin form ?>

x (px) : x