PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.3.18
UiCore Elements – Free widgets and templates for Elementor v1.3.18
1.3.18 1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 All 42 releases
← All changes | includes/widgets/theme-builder/post-meta.php +142 -126 1.2.1 → 1.3.18 View file →
@@ -1,11 +1,12 @@
1 1 <?php
2 +
2 3 namespace UiCoreElements\Widgets\ThemeBuilder;
3 4
4 -use Elementor\Widget_Base;
5 +use UiCoreElements\UiCoreWidget;
5 6 use Elementor\Controls_Manager;
7 +use UiCoreElements\Utils\Meta_Trait;
6 8 use UiCoreElements\Helper;
7 -use UiCoreElements\Utils\Meta_Trait;
8 9
9 10 defined('ABSPATH') || exit();
10 11
11 12 /**
@@ -12,155 +13,170 @@
12 13 * The Title widget.
13 14 *
14 15 * @since 1.0.0
15 16 */
16 -class PostMeta extends Widget_Base {
17 +class PostMeta extends UiCoreWidget
18 +{
17 19
18 - use Meta_Trait;
20 + use Meta_Trait;
19 21
20 - public function get_name() {
21 - return 'uicore-post-meta';
22 - }
23 - public function get_title() {
24 - return esc_html__( 'Post Meta', 'uicore-elements' );
25 - }
26 - public function get_icon() {
27 - return 'eicon-post-info ui-e-widget';
28 - }
29 - public function get_categories() {
30 - return ['uicore', 'uicore-theme-builder' ];
31 - }
32 -
33 - public function get_style_depends() {
34 - return [ 'post-meta' ];
35 - }
36 - public function get_keywords() {
37 - return [ 'post', 'meta', 'info' ];
38 - }
39 - // TODO: remove or set as false, after 3.30, when the full deprecation of widget innet wrapper is ready
40 - public function has_widget_inner_wrapper(): bool {
41 - return true;
22 + public function get_name()
23 + {
24 + return 'uicore-post-meta';
42 25 }
26 + public function get_title()
27 + {
28 + return esc_html__('Post Meta', 'uicore-elements');
29 + }
30 + public function get_icon()
31 + {
32 + return 'eicon-post-info ui-e-widget';
33 + }
34 + public function get_categories()
35 + {
36 + return ['uicore', 'uicore-theme-builder'];
37 + }
38 + public function get_styles()
39 + {
40 + return ['post-meta'];
41 + }
42 + public function get_scripts()
43 + {
44 + return [];
45 + }
46 + public function get_keywords()
47 + {
48 + return ['post', 'meta', 'info'];
49 + }
50 + public function has_widget_inner_wrapper(): bool
51 + {
52 + // TODO: remove after Optmized Markup experiment is merged to the core
53 + return ! \Elementor\Plugin::$instance->experiments->is_feature_active('e_optimized_markup');
54 + }
43 55
44 - protected function register_controls() {
45 - $this->start_controls_section(
46 - 'section_content',
47 - [
48 - 'label' => esc_html__( 'Content', 'uicore-elements' ),
49 - ]
50 - );
56 + protected function register_controls()
57 + {
58 + $this->start_controls_section(
59 + 'section_content',
60 + [
61 + 'label' => esc_html__('Content', 'uicore-elements'),
62 + ]
63 + );
51 64
52 - $this->add_control('meta_list',[
53 - 'label' => esc_html__( 'Meta Data', 'uicore-elements' ),
54 - 'type' => \Elementor\Controls_Manager::REPEATER,
55 - 'fields' => $this->get_meta_content_controls(),
56 - 'default' => [
57 - [
58 - 'type' => 'author'
59 - ],
60 - ],
61 - 'title_field' => '<span style="text-transform: capitalize">{{{ type }}}</span>',
62 - 'prevent_empty' => false,
63 - 'separator'=> 'before'
64 - ]
65 - );
66 - $this->add_responsive_control('content_align',
67 - [
68 - 'label' => esc_html__( 'Content Alignment', 'uicore-elements' ),
69 - 'type' => Controls_Manager::CHOOSE,
70 - 'options' => [
71 - 'left' => [
72 - 'title' => esc_html__( 'Left', 'uicore-elements' ),
73 - 'icon' => 'eicon-text-align-left',
74 - ],
75 - 'center' => [
76 - 'title' => esc_html__( 'Center', 'uicore-elements' ),
77 - 'icon' => 'eicon-text-align-center',
78 - ],
79 - ],
80 - 'selectors' => [
81 - '{{WRAPPER}}' => 'text-align: {{VALUE}};',
82 - ],
83 - ]
84 - );
85 - $this->end_controls_section();
65 + $this->add_control(
66 + 'meta_list',
67 + [
68 + 'label' => esc_html__('Meta Data', 'uicore-elements'),
69 + 'type' => \Elementor\Controls_Manager::REPEATER,
70 + 'fields' => $this->get_meta_content_controls(),
71 + 'default' => [
72 + [
73 + 'type' => 'author'
74 + ],
75 + ],
76 + 'title_field' => '<span style="text-transform: capitalize">{{{ type }}}</span>',
77 + 'prevent_empty' => false,
78 + 'separator' => 'before'
79 + ]
80 + );
81 + $this->add_responsive_control(
82 + 'content_align',
83 + [
84 + 'label' => esc_html__('Content Alignment', 'uicore-elements'),
85 + 'type' => Controls_Manager::CHOOSE,
86 + 'options' => [
87 + 'left' => [
88 + 'title' => esc_html__('Left', 'uicore-elements'),
89 + 'icon' => 'eicon-text-align-left',
90 + ],
91 + 'center' => [
92 + 'title' => esc_html__('Center', 'uicore-elements'),
93 + 'icon' => 'eicon-text-align-center',
94 + ],
95 + ],
96 + 'selectors' => [
97 + '{{WRAPPER}}' => 'text-align: {{VALUE}};',
98 + ],
99 + ]
100 + );
101 + $this->end_controls_section();
86 102
87 - $this->start_controls_section(
88 - 'section_meta_style',
89 - [
90 - 'label' => esc_html__( 'Style', 'uicore-elements' ),
91 - 'tab' => Controls_Manager::TAB_STYLE,
92 - ]
93 - );
94 - $this->get_meta_style_controls();
95 - $this->end_controls_section();
103 + $this->start_controls_section(
104 + 'section_meta_style',
105 + [
106 + 'label' => esc_html__('Style', 'uicore-elements'),
107 + 'tab' => Controls_Manager::TAB_STYLE,
108 + ]
109 + );
110 + $this->get_meta_style_controls();
111 + $this->end_controls_section();
112 + }
96 113
97 - }
114 + protected function display_dummy_text($meta_list)
115 + {
116 + echo '<div class="ui-e-post-meta ui-e-tb-meta">';
117 + foreach ($meta_list as $meta) {
118 + if ($meta['type'] != 'none') {
98 119
99 - /**
100 - * Match each meta icon size (if SVG) with the correspondent font size set by the user.
101 - *
102 - * Based on the post component similar function.
103 - */
104 - function set_meta_font_size_to_svg()
105 - {
106 - // Required specifically for SVG icons
107 - if( \Elementor\Plugin::$instance->experiments->is_feature_active('e_font_icon_svg') == false ){
108 - return;
109 - }
120 + $dummy_content = [
121 + 'excerpt' => esc_html__('This is a sample post excerpt. It provides a brief summary of the article, giving readers a quick preview of the content before they click through to read the full post.', 'uicore-elements'),
122 + 'comment' => rand(1, 5),
123 + 'reading time' => rand(1, 5)
124 + ];
110 125
111 - $font_size = $this->get_settings_for_display('tb-meta_meta_typography_font_size');
112 - $default_size = '16px';
126 + // Print dummy content, if available
127 + if (array_key_exists($meta['type'], $dummy_content)) {
128 + $content = $dummy_content[$meta['type']];
113 129
114 - // Check if theres font-size set.
115 - $size = isset( $font_size ) ? $font_size : $default_size;
130 + // The content printing is the same from display_meta() and should follow up future changes
131 + $wrapper = '<div class="ui-e-meta-item">';
132 + $prefix = $meta['before'] ? '<span>' . esc_html($meta['before']) . '</span>' : '';
133 + $suffix = $meta['after'] ? '<span class="ui-e-meta-after">' . esc_html($meta['after']) . '</span>' : '';
116 134
117 - // Check if the font-size value is not empty (user might customize other infos but not the font-size)
118 - $size = !empty( $size['size'] )
119 - ? $size['size'] . $size['unit']
120 - : $default_size;
135 + ob_start();
136 + \Elementor\Icons_Manager::render_icon($meta['icon'], ['aria-hidden' => 'true', 'class' => 'ui-e-meta-icon'], 'span');
137 + $icon = ob_get_clean();
121 138
122 - // Creates the css variable
123 - $metas_css = '--post_meta-font-size: ' . esc_html($size) . ';';
139 + if (!empty($content)) {
140 + echo $wrapper . Helper::esc_svg($icon) . $prefix . $content . $suffix . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
141 + }
142 + } else {
143 + $this->display_meta($meta);
144 + }
124 145
125 - // print it on the main widget wrapper
126 - $this->add_render_attribute(
127 - '_wrapper',
128 - 'style',
129 - $metas_css
130 - );
146 + if (next($meta_list) && $this->get_settings_for_display('tb-meta_meta_separator')) {
147 + echo '<span class="ui-e-separator">' . esc_html($this->get_settings_for_display('tb-meta_meta_separator')) . '</span>';
148 + }
149 + }
150 + }
151 + echo '</div>';
131 152 }
132 153
133 - protected function render() {
154 + protected function render()
155 + {
156 + $meta_list = $this->get_settings_for_display('meta_list');
134 157
135 - if( !\Elementor\Plugin::$instance->editor->is_edit_mode() ) {
136 - $title = wp_title(null,false);
137 - $title = $title ? $title : get_bloginfo('name');
138 - }else{
139 - $title = __( 'This is a dummy title.', 'uicore-elements' );
158 + if (!isset($meta_list[0]) || $meta_list[0]['type'] == '') {
159 + return;
140 160 }
141 161
142 - $this->set_meta_font_size_to_svg();
143 -
144 - $meta_list = $this->get_settings_for_display( 'meta_list' );
145 - if(!isset($meta_list[0]) || $meta_list[0]['type'] == ''){
162 + if ($this->is_edit_mode()) {
163 + $this->display_dummy_text($meta_list);
146 164 return;
147 165 }
148 166
149 - echo '<div class="ui-e-post-meta ui-e-tb-meta">';
150 - foreach ($meta_list as $meta) {
151 - if($meta['type'] != 'none'){
152 - $this->display_meta($meta);
167 + echo '<div class="ui-e-post-meta ui-e-tb-meta">';
168 + foreach ($meta_list as $meta) {
169 + if ($meta['type'] != 'none') {
170 + $this->display_meta($meta);
153 171
154 - if( next( $meta_list ) && $this->get_settings_for_display( 'tb-meta_meta_separator' ) ) {
155 - echo '<span class="ui-e-separator">'.esc_html($this->get_settings_for_display('tb-meta_meta_separator' )).'</span>';
156 - }
172 + if (next($meta_list) && $this->get_settings_for_display('tb-meta_meta_separator')) {
173 + echo '<span class="ui-e-separator">' . esc_html($this->get_settings_for_display('tb-meta_meta_separator')) . '</span>';
157 174 }
158 175 }
159 - echo '</div>';
176 + }
177 + echo '</div>';
178 + }
160 179
161 - }
162 -
163 - protected function content_template() {
164 - }
180 + protected function content_template() {}
165 181 }
166 182 \Elementor\Plugin::instance()->widgets_manager->register(new PostMeta());