← All changes
|
includes/widgets/Woo_Archive_Banner/Woo_Archive_Banner.php
+33
-5
51.1.78
→
51.1.86
View file →
| @@ -32,9 +32,9 @@ | ||
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | public function get_icon(): string |
| 35 | 35 | { |
| 36 | - return 'eicon-banner'; | |
| 36 | + return 'king-addons-icon king-addons-woo-archive-banner'; | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | public function get_categories(): array |
| 40 | 40 | { |
| @@ -60,8 +60,9 @@ | ||
| 60 | 60 | 'image', |
| 61 | 61 | [ |
| 62 | 62 | 'label' => esc_html__('Image', 'king-addons'), |
| 63 | 63 | 'type' => Controls_Manager::MEDIA, |
| 64 | + 'dynamic' => ['active' => true], | |
| 64 | 65 | 'default' => [ |
| 65 | 66 | 'url' => Utils::get_placeholder_image_src(), |
| 66 | 67 | ], |
| 67 | 68 | ] |
| @@ -79,8 +80,9 @@ | ||
| 79 | 80 | 'title', |
| 80 | 81 | [ |
| 81 | 82 | 'label' => esc_html__('Title', 'king-addons'), |
| 82 | 83 | 'type' => Controls_Manager::TEXT, |
| 84 | + 'dynamic' => ['active' => true], | |
| 83 | 85 | 'default' => esc_html__('Archive Banner', 'king-addons'), |
| 84 | 86 | ] |
| 85 | 87 | ); |
| 86 | 88 | |
| @@ -88,8 +90,9 @@ | ||
| 88 | 90 | 'description', |
| 89 | 91 | [ |
| 90 | 92 | 'label' => esc_html__('Description', 'king-addons'), |
| 91 | 93 | 'type' => Controls_Manager::TEXTAREA, |
| 94 | + 'dynamic' => ['active' => true], | |
| 92 | 95 | 'default' => esc_html__('Highlight your category or shop with a banner.', 'king-addons'), |
| 93 | 96 | ] |
| 94 | 97 | ); |
| 95 | 98 | |
| @@ -97,8 +100,9 @@ | ||
| 97 | 100 | 'button_text', |
| 98 | 101 | [ |
| 99 | 102 | 'label' => esc_html__('Button Text', 'king-addons'), |
| 100 | 103 | 'type' => Controls_Manager::TEXT, |
| 104 | + 'dynamic' => ['active' => true], | |
| 101 | 105 | 'default' => '', |
| 102 | 106 | ] |
| 103 | 107 | ); |
| 104 | 108 | |
| @@ -106,8 +110,9 @@ | ||
| 106 | 110 | 'button_url', |
| 107 | 111 | [ |
| 108 | 112 | 'label' => esc_html__('Button URL', 'king-addons'), |
| 109 | 113 | 'type' => Controls_Manager::URL, |
| 114 | + 'dynamic' => ['active' => true], | |
| 110 | 115 | 'placeholder' => 'https://', |
| 111 | 116 | ] |
| 112 | 117 | ); |
| 113 | 118 | |
| @@ -224,9 +229,18 @@ | ||
| 224 | 229 | $term_img_id = get_term_meta($term->term_id, 'banner_image', true); |
| 225 | 230 | $term_title = get_term_meta($term->term_id, 'banner_title', true); |
| 226 | 231 | $term_desc = get_term_meta($term->term_id, 'banner_desc', true); |
| 227 | 232 | if ($term_img_id) { |
| 228 | - $img_html = Group_Control_Image_Size::get_attachment_image_html($settings, 'image_size', $term_img_id); | |
| 233 | + // The third argument is the name of a settings key, not an | |
| 234 | + // attachment id - passing the id made Elementor look up | |
| 235 | + // $settings[128], warn, and return nothing. Feed it a synthetic | |
| 236 | + // key so the chosen image size still applies. | |
| 237 | + $img_settings = $settings; | |
| 238 | + $img_settings['ka_term_banner_image'] = [ | |
| 239 | + 'id' => (int) $term_img_id, | |
| 240 | + 'url' => wp_get_attachment_image_url((int) $term_img_id, 'full') ?: '', | |
| 241 | + ]; | |
| 242 | + $img_html = Group_Control_Image_Size::get_attachment_image_html($img_settings, 'image_size', 'ka_term_banner_image'); | |
| 229 | 243 | } |
| 230 | 244 | if ($term_title) { |
| 231 | 245 | $title = $term_title; |
| 232 | 246 | } |
| @@ -254,11 +268,23 @@ | ||
| 254 | 268 | } |
| 255 | 269 | } |
| 256 | 270 | |
| 257 | 271 | if (empty($img_html) && !empty($settings['image']['id'])) { |
| 258 | - $img_html = Group_Control_Image_Size::get_attachment_image_html($settings, 'image_size', $settings['image']['id']); | |
| 272 | + $img_html = Group_Control_Image_Size::get_attachment_image_html($settings, 'image_size', 'image'); | |
| 259 | 273 | } |
| 260 | 274 | |
| 275 | + // With no image, title, description or button there is nothing but an | |
| 276 | + // empty shell - which in the editor looks like the widget failed. | |
| 277 | + $has_button = !empty($settings['button_text']) && !empty($settings['button_url']['url']); | |
| 278 | + if (!$img_html && '' === trim((string) $title) && '' === trim((string) $desc) && !$has_button) { | |
| 279 | + if (\Elementor\Plugin::$instance->editor->is_edit_mode()) { | |
| 280 | + echo '<div class="king-addons-woo-builder-notice">' | |
| 281 | + . esc_html__('Set a title, description, image or button for the banner.', 'king-addons') | |
| 282 | + . '</div>'; | |
| 283 | + } | |
| 284 | + return; | |
| 285 | + } | |
| 286 | + | |
| 261 | 287 | echo '<div class="ka-woo-archive-banner">'; |
| 262 | 288 | if ($img_html) { |
| 263 | 289 | echo '<div class="ka-woo-archive-banner__image">' . $img_html . '</div>'; |
| 264 | 290 | } |
| @@ -268,10 +294,12 @@ | ||
| 268 | 294 | } |
| 269 | 295 | if ($desc) { |
| 270 | 296 | echo '<div class="ka-woo-archive-banner__desc">' . wp_kses_post($desc) . '</div>'; |
| 271 | 297 | } |
| 272 | - if (!empty($settings['button_text']) && !empty($settings['button_url']['url'])) { | |
| 273 | - $target = $settings['button_url']['is_external'] ? ' target="_blank" rel="noopener noreferrer"' : ''; | |
| 298 | + if ($has_button) { | |
| 299 | + // is_external is absent until the author opens the link options, so | |
| 300 | + // reading it directly warned on a plain URL. | |
| 301 | + $target = !empty($settings['button_url']['is_external']) ? ' target="_blank" rel="noopener noreferrer"' : ''; | |
| 274 | 302 | echo '<a class="ka-woo-archive-banner__btn" href="' . esc_url($settings['button_url']['url']) . '"' . $target . '>' . esc_html($settings['button_text']) . '</a>'; |
| 275 | 303 | } |
| 276 | 304 | echo '</div>'; |
| 277 | 305 | echo '</div>'; |