| 1 |
<?php |
| 2 |
namespace Easyel\EasyElements\Widgets; |
| 3 |
use Elementor\Widget_Base; |
| 4 |
use Elementor\Controls_Manager; |
| 5 |
use Elementor\Group_Control_Typography; |
| 6 |
use Elementor\Group_Control_Box_Shadow; |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 9 |
|
| 10 |
|
| 11 |
class Easyel_Free_Post_Author_Info_Widget extends Widget_Base { |
| 12 |
public function get_name() { |
| 13 |
return 'eel-post-author-info'; |
| 14 |
} |
| 15 |
|
| 16 |
public function get_title() { |
| 17 |
return __( 'Post Author Info', 'easy-elements' ); |
| 18 |
} |
| 19 |
|
| 20 |
public function get_icon() { |
| 21 |
return 'easyicon easyelIcon-author'; |
| 22 |
} |
| 23 |
|
| 24 |
public function get_categories() { |
| 25 |
return [ 'easyelements_category' ]; |
| 26 |
} |
| 27 |
|
| 28 |
public function get_keywords() { |
| 29 |
return [ 'author', 'meta', 'post', 'blog', 'text' ]; |
| 30 |
} |
| 31 |
|
| 32 |
public function get_style_depends() { |
| 33 |
return [ |
| 34 |
'eel-post-author-info', |
| 35 |
]; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
protected function register_controls() { |
| 40 |
|
| 41 |
$this->start_controls_section( |
| 42 |
'author_content', |
| 43 |
[ |
| 44 |
'label' => __( 'Author Info', 'easy-elements' ), |
| 45 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 46 |
] |
| 47 |
); |
| 48 |
|
| 49 |
$this->add_control( |
| 50 |
'show_avatar', |
| 51 |
[ |
| 52 |
'label' => __( 'Show Avatar', 'easy-elements' ), |
| 53 |
'type' => Controls_Manager::SWITCHER, |
| 54 |
'label_on' => __( 'Yes', 'easy-elements' ), |
| 55 |
'label_off' => __( 'No', 'easy-elements' ), |
| 56 |
'default' => 'yes', |
| 57 |
] |
| 58 |
); |
| 59 |
|
| 60 |
$this->add_control( |
| 61 |
'show_bio', |
| 62 |
[ |
| 63 |
'label' => __( 'Show Bio', 'easy-elements' ), |
| 64 |
'type' => Controls_Manager::SWITCHER, |
| 65 |
'label_on' => __( 'Yes', 'easy-elements' ), |
| 66 |
'label_off' => __( 'No', 'easy-elements' ), |
| 67 |
'default' => 'yes', |
| 68 |
] |
| 69 |
); |
| 70 |
|
| 71 |
$this->add_control( |
| 72 |
'show_post_count', |
| 73 |
[ |
| 74 |
'label' => __( 'Show Total Posts', 'easy-elements' ), |
| 75 |
'type' => Controls_Manager::SWITCHER, |
| 76 |
'label_on' => __( 'Yes', 'easy-elements' ), |
| 77 |
'label_off' => __( 'No', 'easy-elements' ), |
| 78 |
'default' => 'yes', |
| 79 |
] |
| 80 |
); |
| 81 |
|
| 82 |
$this->add_responsive_control( |
| 83 |
'count_middle_space', |
| 84 |
[ |
| 85 |
'label' => __( 'Spacing', 'easy-elements' ), |
| 86 |
'type' => Controls_Manager::SLIDER, |
| 87 |
'size_units' => [ 'px', '%', 'em' ], |
| 88 |
'range' => [ |
| 89 |
'px' => [ |
| 90 |
'min' => 0, |
| 91 |
'max' => 100, |
| 92 |
], |
| 93 |
], |
| 94 |
'selectors' => [ |
| 95 |
'{{WRAPPER}} .eel-author-info .eel-author-description' => 'padding-left: {{SIZE}}{{UNIT}};', |
| 96 |
], |
| 97 |
] |
| 98 |
); |
| 99 |
|
| 100 |
|
| 101 |
$this->end_controls_section(); |
| 102 |
|
| 103 |
// Style Name |
| 104 |
$this->start_controls_section( |
| 105 |
'author_style', |
| 106 |
[ |
| 107 |
'label' => __( 'Name', 'easy-elements' ), |
| 108 |
'tab' => Controls_Manager::TAB_STYLE, |
| 109 |
] |
| 110 |
); |
| 111 |
|
| 112 |
$this->add_group_control( |
| 113 |
Group_Control_Typography::get_type(), |
| 114 |
[ |
| 115 |
'name' => 'author_typography', |
| 116 |
'selector' => '{{WRAPPER}} .eel-author-info .eel-author-name', |
| 117 |
] |
| 118 |
); |
| 119 |
|
| 120 |
$this->add_control( |
| 121 |
'author_text_color', |
| 122 |
[ |
| 123 |
'label' => __( 'Text Color', 'easy-elements' ), |
| 124 |
'type' => Controls_Manager::COLOR, |
| 125 |
'selectors' => [ |
| 126 |
'{{WRAPPER}} .eel-author-info .eel-author-name' => 'color: {{VALUE}};', |
| 127 |
], |
| 128 |
] |
| 129 |
); |
| 130 |
|
| 131 |
$this->add_responsive_control( |
| 132 |
'author_margin', |
| 133 |
[ |
| 134 |
'label' => __( 'Margin', 'easy-elements' ), |
| 135 |
'type' => Controls_Manager::DIMENSIONS, |
| 136 |
'size_units' => [ 'px', '%', 'em' ], |
| 137 |
'selectors' => [ |
| 138 |
'{{WRAPPER}} .eel-author-info .eel-author-name' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 139 |
], |
| 140 |
] |
| 141 |
); |
| 142 |
$this->end_controls_section(); |
| 143 |
|
| 144 |
|
| 145 |
// Style Description |
| 146 |
$this->start_controls_section( |
| 147 |
'bio_style', |
| 148 |
[ |
| 149 |
'label' => __( 'Biographical Info', 'easy-elements' ), |
| 150 |
'tab' => Controls_Manager::TAB_STYLE, |
| 151 |
] |
| 152 |
); |
| 153 |
|
| 154 |
$this->add_group_control( |
| 155 |
Group_Control_Typography::get_type(), |
| 156 |
[ |
| 157 |
'name' => 'bio_typography', |
| 158 |
'selector' => '{{WRAPPER}} .eel-author-info .eel-author-bio', |
| 159 |
] |
| 160 |
); |
| 161 |
|
| 162 |
$this->add_control( |
| 163 |
'bio_text_color', |
| 164 |
[ |
| 165 |
'label' => __( 'Text Color', 'easy-elements' ), |
| 166 |
'type' => Controls_Manager::COLOR, |
| 167 |
'selectors' => [ |
| 168 |
'{{WRAPPER}} .eel-author-info .eel-author-bio' => 'color: {{VALUE}};', |
| 169 |
], |
| 170 |
] |
| 171 |
); |
| 172 |
|
| 173 |
$this->add_responsive_control( |
| 174 |
'bio_margin', |
| 175 |
[ |
| 176 |
'label' => __( 'Margin', 'easy-elements' ), |
| 177 |
'type' => Controls_Manager::DIMENSIONS, |
| 178 |
'size_units' => [ 'px', '%', 'em' ], |
| 179 |
'selectors' => [ |
| 180 |
'{{WRAPPER}} .eel-author-info .eel-author-bio' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 181 |
], |
| 182 |
] |
| 183 |
); |
| 184 |
$this->end_controls_section(); |
| 185 |
|
| 186 |
// Style Count |
| 187 |
$this->start_controls_section( |
| 188 |
'count_style', |
| 189 |
[ |
| 190 |
'label' => __( 'Post Count', 'easy-elements' ), |
| 191 |
'tab' => Controls_Manager::TAB_STYLE, |
| 192 |
] |
| 193 |
); |
| 194 |
|
| 195 |
$this->add_group_control( |
| 196 |
Group_Control_Typography::get_type(), |
| 197 |
[ |
| 198 |
'name' => 'count_typography', |
| 199 |
'selector' => '{{WRAPPER}} .eel-author-post-count', |
| 200 |
] |
| 201 |
); |
| 202 |
|
| 203 |
$this->add_control( |
| 204 |
'count_text_color', |
| 205 |
[ |
| 206 |
'label' => __( 'Text Color', 'easy-elements' ), |
| 207 |
'type' => Controls_Manager::COLOR, |
| 208 |
'selectors' => [ |
| 209 |
'{{WRAPPER}} .eel-author-post-count' => 'color: {{VALUE}};', |
| 210 |
], |
| 211 |
] |
| 212 |
); |
| 213 |
|
| 214 |
$this->add_responsive_control( |
| 215 |
'count_margin', |
| 216 |
[ |
| 217 |
'label' => __( 'Margin', 'easy-elements' ), |
| 218 |
'type' => Controls_Manager::DIMENSIONS, |
| 219 |
'size_units' => [ 'px', '%', 'em' ], |
| 220 |
'selectors' => [ |
| 221 |
'{{WRAPPER}} .eel-author-post-count' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 222 |
], |
| 223 |
] |
| 224 |
); |
| 225 |
$this->end_controls_section(); |
| 226 |
} |
| 227 |
|
| 228 |
protected function render() { |
| 229 |
$settings = $this->get_settings_for_display(); |
| 230 |
|
| 231 |
$post_id = function_exists('easyel_get_prepared_post_id') |
| 232 |
? easyel_get_prepared_post_id() |
| 233 |
: get_the_ID(); |
| 234 |
|
| 235 |
$post_obj = get_post( $post_id ); |
| 236 |
if ( ! $post_obj instanceof \WP_Post ) { |
| 237 |
echo '<p>' . esc_html__('No valid post found.', 'easy-elements') . '</p>'; |
| 238 |
return; |
| 239 |
} |
| 240 |
|
| 241 |
global $post; |
| 242 |
$original_post = $post; |
| 243 |
$post = $post_obj; |
| 244 |
setup_postdata( $post ); |
| 245 |
|
| 246 |
$author_id = $post->post_author; |
| 247 |
$author_name = get_the_author_meta( 'display_name', $author_id ); |
| 248 |
|
| 249 |
echo '<div class="eel-author-info">'; |
| 250 |
|
| 251 |
echo '<div class="eel-author-image">'; |
| 252 |
if ( 'yes' === $settings['show_avatar'] ) { |
| 253 |
echo get_avatar( $author_id, 96, '', $author_name, ['class' => 'eel-author-avatar'] ); |
| 254 |
} |
| 255 |
echo '</div>'; |
| 256 |
|
| 257 |
echo '<div class="eel-author-description">'; |
| 258 |
|
| 259 |
echo '<h4 class="eel-author-name">' . esc_html( $author_name ) . '</h4>'; |
| 260 |
|
| 261 |
if ( 'yes' === $settings['show_bio'] ) { |
| 262 |
$bio = get_the_author_meta('description', $author_id); |
| 263 |
if ( $bio ) { |
| 264 |
echo '<p class="eel-author-bio">' . esc_html( $bio ) . '</p>'; |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
// Total posts |
| 269 |
if ( 'yes' === $settings['show_post_count'] ) { |
| 270 |
$post_count = (int) count_user_posts( $author_id, 'post' ); |
| 271 |
echo '<span class="eel-author-post-count">' . |
| 272 |
/* translators: %d: number of posts */ |
| 273 |
esc_html( sprintf( _n( '%d post', '%d posts', $post_count, 'easy-elements' ), $post_count ) ) . |
| 274 |
'</span>'; |
| 275 |
} |
| 276 |
|
| 277 |
echo '</div>'; |
| 278 |
echo '</div>'; |
| 279 |
|
| 280 |
wp_reset_postdata(); |
| 281 |
$post = $original_post; |
| 282 |
} |
| 283 |
|
| 284 |
} |
| 285 |
|