| 1 |
<?php |
| 2 |
namespace Easyel\EasyElements\Widgets; |
| 3 |
use Elementor\Widget_Base; |
| 4 |
use Elementor\Controls_Manager; |
| 5 |
use Elementor\Group_Control_Typography; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; |
| 9 |
} |
| 10 |
|
| 11 |
class Easyel_Free_Post_Tags_Widget extends \Elementor\Widget_Base { |
| 12 |
|
| 13 |
public function get_name() { |
| 14 |
return 'eel-post-tags'; |
| 15 |
} |
| 16 |
|
| 17 |
public function get_title() { |
| 18 |
return __( 'Current Post Tags', 'easy-elements' ); |
| 19 |
} |
| 20 |
|
| 21 |
public function get_icon() { |
| 22 |
return 'easyicon easyelIcon-post-tag'; |
| 23 |
} |
| 24 |
|
| 25 |
public function get_categories() { |
| 26 |
return [ 'easyelements_category' ]; |
| 27 |
} |
| 28 |
|
| 29 |
public function get_keywords() { |
| 30 |
return [ 'tags', 'post tags', 'meta', 'taxonomy', 'blog', 'text' ]; |
| 31 |
} |
| 32 |
|
| 33 |
public function get_style_depends() { |
| 34 |
return [ |
| 35 |
'eel-post-tags', |
| 36 |
]; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
protected function register_controls() { |
| 41 |
|
| 42 |
$this->start_controls_section( |
| 43 |
'tags_content', |
| 44 |
[ |
| 45 |
'label' => __( 'Tags', 'easy-elements' ), |
| 46 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 47 |
] |
| 48 |
); |
| 49 |
|
| 50 |
$this->add_control( |
| 51 |
'show_label', |
| 52 |
[ |
| 53 |
'label' => __( 'Show Label', 'easy-elements' ), |
| 54 |
'type' => Controls_Manager::SWITCHER, |
| 55 |
'label_on' => __( 'Yes', 'easy-elements' ), |
| 56 |
'label_off' => __( 'No', 'easy-elements' ), |
| 57 |
'default' => 'yes', |
| 58 |
] |
| 59 |
); |
| 60 |
|
| 61 |
$this->add_control( |
| 62 |
'label_text', |
| 63 |
[ |
| 64 |
'label' => __( 'Label Text', 'easy-elements' ), |
| 65 |
'type' => Controls_Manager::TEXT, |
| 66 |
'default' => __( 'Tags:', 'easy-elements' ), |
| 67 |
'condition' => [ |
| 68 |
'show_label' => 'yes', |
| 69 |
], |
| 70 |
] |
| 71 |
); |
| 72 |
|
| 73 |
$this->end_controls_section(); |
| 74 |
|
| 75 |
$this->start_controls_section( |
| 76 |
'title_style', |
| 77 |
[ |
| 78 |
'label' => __( 'Title Label', 'easy-elements' ), |
| 79 |
'tab' => Controls_Manager::TAB_STYLE, |
| 80 |
] |
| 81 |
); |
| 82 |
|
| 83 |
$this->add_control( |
| 84 |
'title_color', |
| 85 |
[ |
| 86 |
'label' => __( 'Color', 'easy-elements' ), |
| 87 |
'type' => Controls_Manager::COLOR, |
| 88 |
'selectors' => [ |
| 89 |
'{{WRAPPER}} .eel-post-tags-widget .eel-tags-label' => 'color: {{VALUE}};', |
| 90 |
], |
| 91 |
] |
| 92 |
); |
| 93 |
|
| 94 |
$this->add_responsive_control( |
| 95 |
'title_margin', |
| 96 |
[ |
| 97 |
'label' => __( 'Margin', 'easy-elements' ), |
| 98 |
'type' => Controls_Manager::DIMENSIONS, |
| 99 |
'size_units' => [ 'px', '%', 'em' ], |
| 100 |
'selectors' => [ |
| 101 |
'{{WRAPPER}} .eel-post-tags-widget .eel-tags-label' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 102 |
], |
| 103 |
] |
| 104 |
); |
| 105 |
|
| 106 |
$this->add_group_control( |
| 107 |
Group_Control_Typography::get_type(), |
| 108 |
[ |
| 109 |
'name' => 'title_typography', |
| 110 |
'selector' => '{{WRAPPER}} .eel-post-tags-widget .eel-tags-label', |
| 111 |
] |
| 112 |
); |
| 113 |
|
| 114 |
$this->end_controls_section(); |
| 115 |
|
| 116 |
$this->start_controls_section( |
| 117 |
'tags_style', |
| 118 |
[ |
| 119 |
'label' => __( 'Tag', 'easy-elements' ), |
| 120 |
'tab' => Controls_Manager::TAB_STYLE, |
| 121 |
] |
| 122 |
); |
| 123 |
|
| 124 |
$this->add_group_control( |
| 125 |
Group_Control_Typography::get_type(), |
| 126 |
[ |
| 127 |
'name' => 'tags_typography', |
| 128 |
'selector' => '{{WRAPPER}} .eel-post-tags-widget a', |
| 129 |
] |
| 130 |
); |
| 131 |
|
| 132 |
$this->start_controls_tabs( 'tabs_tag_style' ); |
| 133 |
|
| 134 |
// Normal Tab |
| 135 |
$this->start_controls_tab( |
| 136 |
'tab_tag_normal', |
| 137 |
[ |
| 138 |
'label' => __( 'Normal', 'easy-elements' ), |
| 139 |
] |
| 140 |
); |
| 141 |
|
| 142 |
$this->add_control( |
| 143 |
'tags_color', |
| 144 |
[ |
| 145 |
'label' => __( 'Text Color', 'easy-elements' ), |
| 146 |
'type' => Controls_Manager::COLOR, |
| 147 |
'selectors' => [ |
| 148 |
'{{WRAPPER}} .eel-post-tags-widget a' => 'color: {{VALUE}};', |
| 149 |
], |
| 150 |
] |
| 151 |
); |
| 152 |
|
| 153 |
$this->add_group_control( |
| 154 |
\Elementor\Group_Control_Background::get_type(), |
| 155 |
[ |
| 156 |
'name' => 'tags__bg_color', |
| 157 |
'label' => __('Background', 'easy-elements'), |
| 158 |
'types' => ['classic', 'gradient'], |
| 159 |
'selector' => '{{WRAPPER}} .eel-post-tags-widget a', |
| 160 |
] |
| 161 |
); |
| 162 |
|
| 163 |
$this->end_controls_tab(); |
| 164 |
|
| 165 |
// Hover Tab |
| 166 |
$this->start_controls_tab( |
| 167 |
'tab_tag_hover', |
| 168 |
[ |
| 169 |
'label' => __( 'Hover', 'easy-elements' ), |
| 170 |
] |
| 171 |
); |
| 172 |
|
| 173 |
$this->add_control( |
| 174 |
'tags_hover_color', |
| 175 |
[ |
| 176 |
'label' => __( 'Text Color', 'easy-elements' ), |
| 177 |
'type' => Controls_Manager::COLOR, |
| 178 |
'selectors' => [ |
| 179 |
'{{WRAPPER}} .eel-post-tags-widget a:hover' => 'color: {{VALUE}};', |
| 180 |
], |
| 181 |
] |
| 182 |
); |
| 183 |
|
| 184 |
$this->add_group_control( |
| 185 |
\Elementor\Group_Control_Background::get_type(), |
| 186 |
[ |
| 187 |
'name' => 'tags_hover_bg_color', |
| 188 |
'label' => __('Background', 'easy-elements'), |
| 189 |
'types' => ['classic', 'gradient'], |
| 190 |
'selector' => '{{WRAPPER}} .eel-post-tags-widget a:hover', |
| 191 |
] |
| 192 |
); |
| 193 |
|
| 194 |
$this->end_controls_tab(); |
| 195 |
|
| 196 |
$this->end_controls_tabs(); |
| 197 |
|
| 198 |
$this->add_responsive_control( |
| 199 |
'tags_margin', |
| 200 |
[ |
| 201 |
'label' => __( 'Margin', 'easy-elements' ), |
| 202 |
'type' => Controls_Manager::DIMENSIONS, |
| 203 |
'size_units' => [ 'px', '%', 'em' ], |
| 204 |
'selectors' => [ |
| 205 |
'{{WRAPPER}} .eel-post-tags-widget a' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 206 |
], |
| 207 |
] |
| 208 |
); |
| 209 |
|
| 210 |
$this->add_responsive_control( |
| 211 |
'tags_padding', |
| 212 |
[ |
| 213 |
'label' => __( 'Padding', 'easy-elements' ), |
| 214 |
'type' => Controls_Manager::DIMENSIONS, |
| 215 |
'size_units' => [ 'px', '%', 'em' ], |
| 216 |
'selectors' => [ |
| 217 |
'{{WRAPPER}} .eel-post-tags-widget a' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 218 |
], |
| 219 |
] |
| 220 |
); |
| 221 |
|
| 222 |
$this->end_controls_section(); |
| 223 |
|
| 224 |
} |
| 225 |
|
| 226 |
protected function render() { |
| 227 |
// Password protected post check |
| 228 |
if ( post_password_required() ) { |
| 229 |
return; |
| 230 |
} |
| 231 |
|
| 232 |
$settings = $this->get_settings_for_display(); |
| 233 |
|
| 234 |
$post_id = function_exists('easyel_get_prepared_post_id') |
| 235 |
? easyel_get_prepared_post_id() |
| 236 |
: get_the_ID(); |
| 237 |
|
| 238 |
$post_obj = get_post( $post_id ); |
| 239 |
if ( ! $post_obj instanceof \WP_Post ) { |
| 240 |
return; |
| 241 |
} |
| 242 |
|
| 243 |
// Setup global post for template functions |
| 244 |
global $post; |
| 245 |
$original_post = $post; |
| 246 |
$post = $post_obj; |
| 247 |
setup_postdata( $post ); |
| 248 |
|
| 249 |
$tags = get_the_tags(); |
| 250 |
if ( ! $tags || is_wp_error( $tags ) ) { |
| 251 |
wp_reset_postdata(); |
| 252 |
$post = $original_post; |
| 253 |
return; |
| 254 |
} |
| 255 |
|
| 256 |
echo '<div class="eel-post-tags-widget">'; |
| 257 |
|
| 258 |
if ( 'yes' === ( $settings['show_label'] ?? 'no' ) && ! empty( $settings['label_text'] ) ) { |
| 259 |
echo '<span class="eel-tags-label">' . esc_html( $settings['label_text'] ) . '</span> '; |
| 260 |
} |
| 261 |
|
| 262 |
foreach ( $tags as $tag ) { |
| 263 |
$tag_link = get_tag_link( $tag->term_id ); |
| 264 |
echo '<a href="' . esc_url( $tag_link ) . '" rel="tag">' . esc_html( $tag->name ) . '</a> '; |
| 265 |
} |
| 266 |
|
| 267 |
echo '</div>'; |
| 268 |
|
| 269 |
// Reset global post |
| 270 |
wp_reset_postdata(); |
| 271 |
$post = $original_post; |
| 272 |
} |
| 273 |
|
| 274 |
} |