PluginProbe
Virtue/Ascend/Pinnacle Toolkit / 4.9.12.2
Virtue/Ascend/Pinnacle Toolkit v4.9.12.2
4.9.12.2 trunk 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.7 All 48 releases
virtue-toolkit / widgets / class-kad-image-widget.php

class-kad-image-widget.php in Virtue/Ascend/Pinnacle Toolkit 4.9.12.2, at widgets/class-kad-image-widget.php

106 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Pinacle Image Widget for compatiblity
4 */
5
6 if ( ! class_exists( 'kad_image_widget' ) ) {
7 class kad_image_widget extends WP_Widget{
8
9 private static $instance = 0;
10 public function __construct() {
11 $widget_ops = array('classname' => 'kadence_simple_image', 'description' => __('This allows for an image and a simple about text.', 'virtue-toolkit'));
12 parent::__construct('kadence_simple_image', __('Pinnacle: Image', 'virtue-toolkit'), $widget_ops);
13 }
14
15 public function widget($args, $instance){
16 extract( $args );
17 if (!empty($instance['image_link_open']) && $instance['image_link_open'] == "none") {
18 $uselink = false;
19 $link = '';
20 $linktype = '';
21 } else if(empty($instance['image_link_open']) || $instance['image_link_open'] == "lightbox") {
22 $uselink = true;
23 $link = esc_url($instance['image_uri']);
24 $linktype = 'data-rel="lightbox"';
25 } else if($instance['image_link_open'] == "_blank") {
26 $uselink = true;
27 if(!empty($instance['image_link'])) {$link = $instance['image_link'];} else {$link = esc_url($instance['image_uri']);}
28 $linktype = 'target="_blank"';
29 } else if($instance['image_link_open'] == "_self") {
30 $uselink = true;
31 if(!empty($instance['image_link'])) {$link = $instance['image_link'];} else {$link = esc_url($instance['image_uri']);}
32 $linktype = 'target="_self"';
33 }
34 $image_id = attachment_url_to_postid( $instance['image_uri'] );
35 if(isset($image_id) && $image_id != '0') {
36 $alt_text = get_post_meta($image_id, '_wp_attachment_image_alt', true);
37 } else {
38 $alt_text = '';
39 }
40 ?>
41 <?php echo $before_widget; ?>
42 <div class="kad_img_upload_widget">
43 <?php if($uselink == true) {echo '<a href="'.esc_url($link).'" '.$linktype.'>';} ?>
44 <img src="<?php echo esc_url($instance['image_uri']); ?>" alt="<?php echo esc_attr($alt_text); ?>" />
45 <?php if($uselink == true) {echo '</a>'; }?>
46 <?php if(!empty($instance['text'])) { ?> <p class="kadence_image_widget_caption"><?php echo esc_html($instance['text']); ?></p><?php }?>
47 </div>
48
49 <?php echo $after_widget; ?>
50 <?php }
51
52 public function update($new_instance, $old_instance) {
53 $instance = $old_instance;
54 $instance['text'] = strip_tags( $new_instance['text'] );
55 $instance['image_uri'] = strip_tags( $new_instance['image_uri'] );
56 $instance['image_link'] = $new_instance['image_link'];
57 $instance['image_link_open'] = $new_instance['image_link_open'];
58
59 return $instance;
60 }
61
62 public function form($instance){
63 $image_uri = isset($instance['image_uri']) ? esc_attr($instance['image_uri']) : '';
64 $image_link = isset($instance['image_link']) ? esc_attr($instance['image_link']) : '';
65 if (isset($instance['image_link_open'])) { $image_link_open = esc_attr($instance['image_link_open']); } else {$image_link_open = 'lightbox';}
66 $link_options = array();
67 $link_options_array = array();
68 $link_options[] = array("slug" => "lightbox", "name" => __('Lightbox', 'virtue-toolkit'));
69 $link_options[] = array("slug" => "_blank", "name" => __('New Window', 'virtue-toolkit'));
70 $link_options[] = array("slug" => "_self", "name" => __('Same Window', 'virtue-toolkit'));
71 $link_options[] = array("slug" => "none", "name" => __('No Link', 'virtue-toolkit'));
72
73 foreach ($link_options as $link_option) {
74 if ($image_link_open == $link_option['slug']) { $selected=' selected="selected"';} else { $selected=""; }
75 $link_options_array[] = '<option value="' . $link_option['slug'] .'"' . $selected . '>' . $link_option['name'] . '</option>';
76 }
77 ?>
78 <div class="kad_img_upload_widget">
79 <p>
80 <img class="kad_custom_media_image" src="<?php if(!empty($instance['image_uri'])){echo $instance['image_uri'];} ?>" style="margin:0;padding:0;max-width:100px;display:block" />
81 </p>
82 <p>
83 <label for="<?php echo $this->get_field_id('image_uri'); ?>"><?php _e('Image URL', 'virtue-toolkit'); ?></label><br />
84 <input type="text" class="widefat kad_custom_media_url" name="<?php echo $this->get_field_name('image_uri'); ?>" id="<?php echo $this->get_field_id('image_uri'); ?>" value="<?php echo $image_uri; ?>">
85 <input type="button" value="<?php _e('Upload', 'virtue-toolkit'); ?>" class="button kad_custom_media_upload" id="kad_custom_image_uploader" />
86 </p>
87 <p>
88 <label for="<?php echo $this->get_field_id('image_link_open'); ?>"><?php _e('Image opens in', 'virtue-toolkit'); ?></label><br />
89 <select id="<?php echo $this->get_field_id('image_link_open'); ?>" name="<?php echo $this->get_field_name('image_link_open'); ?>"><?php echo implode('', $link_options_array);?></select>
90 </p>
91 <p>
92 <label for="<?php echo $this->get_field_id('image_link'); ?>"><?php _e('Image Link (optional)', 'virtue-toolkit'); ?></label><br />
93 <input type="text" class="widefat kad_img_widget_link" name="<?php echo $this->get_field_name('image_link'); ?>" id="<?php echo $this->get_field_id('image_link'); ?>" value="<?php echo $image_link; ?>">
94 </p>
95 <p>
96 <label for="<?php echo $this->get_field_id('text'); ?>"><?php _e('Text/Caption (optional)', 'virtue-toolkit'); ?></label><br />
97 <textarea name="<?php echo $this->get_field_name('text'); ?>" id="<?php echo $this->get_field_id('text'); ?>" class="widefat" ><?php if(!empty($instance['text'])) echo $instance['text']; ?></textarea>
98 </p>
99 </div>
100 <?php
101 }
102
103
104 }
105
106 }