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/advanced-post-carousel.php +255 -235 1.0.12 → 1.3.18 View file →
@@ -1,235 +1,255 @@
1 -<?php
2 -
3 -namespace UiCoreElements;
4 -
5 -use Elementor\Controls_Manager;
6 -use UiCoreElements\UiCoreWidget;
7 -use UiCoreElements\Utils\Carousel_Trait;
8 -use UiCoreElements\Utils\Animation_Trait;
9 -use UiCoreElements\Utils\Grid_Trait;
10 -use uicoreElements\Utils\Post_Trait;
11 -use uiCoreElements\Utils\Post_Filters_Trait;
12 -
13 -defined('ABSPATH') || exit();
14 -
15 -class AdvancedPostCarousel extends UiCoreWidget
16 -{
17 - use Carousel_Trait,
18 - Animation_Trait,
19 - Grid_Trait,
20 - Post_Filters_Trait,
21 - Post_Trait;
22 -
23 - private $_query;
24 -
25 - public function get_name()
26 - {
27 - return 'uicore-advanced-post-carousel';
28 - }
29 - public function get_categories()
30 - {
31 - return ['uicore'];
32 - }
33 - public function get_title()
34 - {
35 - return __('Advanced Post Carousel', 'uicore-elements');
36 - }
37 - public function get_icon()
38 - {
39 - return 'eicon-posts-carousel ui-e-widget';
40 - }
41 - public function get_keywords()
42 - {
43 - return ['post', 'carousel', 'slide', 'blog', 'recent', 'news'];
44 - }
45 - public function get_styles()
46 - {
47 - $styles = [
48 - 'advanced-post-carousel',
49 - 'animation', // hover animations
50 - 'entrance', // entrance basic style
51 - ];
52 - if(!class_exists('\UiCore\Core') && !class_exists('\UiCoreAnimate\Base')){
53 - $styles['e-animations'] = [ // entrance animations
54 - 'external' => true,
55 - ];
56 - }
57 - return $styles;
58 - }
59 - public function get_scripts()
60 - {
61 - return $this->TRAIT_get_scripts();
62 - }
63 -
64 - private function filter_missing_taxonomies($settings)
65 - {
66 - $taxonomy_filter_args = [
67 - 'show_in_nav_menus' => true,
68 - ];
69 - if (!empty($settings['posts-filter_post_type'])) {
70 - $taxonomy_filter_args['object_type'] = [$settings['posts-filter_post_type']];
71 - }
72 -
73 - $taxonomies = get_taxonomies($taxonomy_filter_args, 'objects');
74 -
75 - foreach ($taxonomies as $taxonomy => $object) {
76 - $controll_id = 'posts-filter_' . $taxonomy . '_ids';
77 - \error_log($controll_id);
78 - \error_log(print_r($settings[$controll_id], true));
79 -
80 - if (!isset($settings[$controll_id]) || empty($settings[$controll_id])) {
81 - continue;
82 - }
83 -
84 - //if is set check if this id still exists
85 - $settings[$controll_id] = array_filter($settings[$controll_id], function ($term_id) use ($object) {
86 - return term_exists($term_id, $object->name);
87 - });
88 -
89 - if (empty($settings[$controll_id])) {
90 - $settings[$controll_id] = null;
91 - }
92 - }
93 -
94 - return $settings;
95 - }
96 - public function on_import($element)
97 - {
98 - $element['settings'] = $this->filter_missing_taxonomies($element['settings']);
99 - return $element;
100 - }
101 - function get_query()
102 - {
103 - return $this->_query;
104 - }
105 -
106 - protected function register_controls()
107 - {
108 -
109 - // Contents and Settings
110 - $this->start_controls_section(
111 - 'section_layout',
112 - [
113 - 'label' => esc_html__('Carousel', 'uicore-elements'),
114 - ]
115 - );
116 - $this->TRAIT_register_carousel_additional_controls(); // Grid Layouts with old masonry control
117 - $this->end_controls_section();
118 -
119 - $this->start_controls_section(
120 - 'section_carousel_settings',
121 - [
122 - 'label' => __('Carousel Settings', 'uicore-elements'),
123 - ]
124 - );
125 - $this->TRAIT_register_carousel_settings_controls(); // Carousel settings
126 - $this->end_controls_section();
127 -
128 - $this->TRAIT_register_navigation_controls();
129 - $this->TRAIT_register_post_item_controls();
130 - $this->TRAIT_register_post_button_controls();
131 - $this->TRAIT_register_post_meta_controls();
132 - $this->TRAIT_register_post_query_controls();
133 - $this->TRAIT_register_filter_controls();
134 -
135 - // Styles
136 - $this->TRAIT_register_post_item_style_controls(); // instead of using carousel item style controls, we use post item and only updates some default values after. Is a better approach because advanced post widgets inherits some APG legacy codes and methods, such as setting borders and paddings on <article> instead of 'ui-e-item'
137 - $this->TRAIT_register_navigation_style_controls();
138 - $this->TRAIT_register_post_content_style_controls();
139 - $this->TRAIT_register_post_button_style_controls();
140 - $this->TRAIT_register_post_meta_style_controls();
141 - $this->TRAIT_register_filter_style_controls();
142 -
143 - $this->start_controls_section(
144 - 'section_style_animations',
145 - [
146 - 'label' => __('Animations', 'uicore-elements'),
147 - 'tab' => Controls_Manager::TAB_STYLE,
148 - ]
149 - );
150 - $this->TRAIT_register_entrance_animations_controls();
151 - $this->TRAIT_register_hover_animation_control(
152 - 'Item Hover Animation',
153 - [],
154 - ['underline'],
155 - );
156 - $this->TRAIT_register_post_animation_controls();
157 - $this->end_controls_section();
158 -
159 - // Update post component controls
160 - $this->update_control('image_size', [
161 - 'condition' => [],
162 - ]);
163 - $this->update_control('content_padding', [
164 - 'default' => [
165 - 'top' => 20,
166 - 'right' => 20,
167 - 'bottom' => 20,
168 - 'left' => 20,
169 - 'unit' => 'px',
170 - ],
171 - ]);
172 - $this->update_control('item_limit', [
173 - 'default' => [
174 - 'size' => 5,
175 - ],
176 - ]);
177 - }
178 -
179 - function content_template()
180 - {
181 - }
182 -
183 - protected function render()
184 - {
185 -
186 - // Get query args, settings and post type slug
187 - global $wp_query;
188 - $default_query = $wp_query;
189 - $settings = $this->get_settings();
190 -
191 - $this->TRAIT_query_posts( $settings, $wp_query->query );
192 - $wp_query = $this->get_query();
193 -
194 - $this->TRAIT_set_meta_font_size_to_svg($settings); // SVG icon experiment font-size adjustment
195 -
196 - // Get the quantity of items and creates a loop control
197 - $items = $settings['item_limit']['size'];
198 - $loops = 0;
199 -
200 - $this->TRAIT_render_filters($settings);
201 -
202 - // No posts found
203 - if (!$wp_query->have_posts()) {
204 - echo '<p style="text-align:center">' . __('No posts found.', 'uicore-elements') . '</p>';
205 - } else {
206 -
207 - ?>
208 - <div class="ui-e-carousel swiper">
209 - <div class='swiper-wrapper'>
210 - <?php
211 - while ($wp_query->have_posts()) {
212 -
213 - // sticky posts disregards posts per page, so ending the loop if $items == $loop forces the query respects the users item limit
214 - if ($settings['sticky'] && $items == $loops) {
215 - break;
216 - }
217 -
218 - $wp_query->the_post();
219 - $this->TRAIT_render_item(true);
220 -
221 - $loops++;
222 - }
223 - ?>
224 - </div>
225 - <?php $this->TRAIT_render_carousel_navigations(); ?>
226 - </div>
227 - <?php
228 - }
229 -
230 - //reset query
231 - wp_reset_query();
232 - $wp_query = $default_query;
233 - }
234 -}
235 -\Elementor\Plugin::instance()->widgets_manager->register(new AdvancedPostCarousel());
1 +<?php
2 +
3 +namespace UiCoreElements;
4 +
5 +use Elementor\Controls_Manager;
6 +use UiCoreElements\UiCoreWidget;
7 +use UiCoreElements\Utils\Carousel_Trait;
8 +use UiCoreElements\Utils\Animation_Trait;
9 +use UiCoreElements\Utils\Grid_Trait;
10 +use uicoreElements\Utils\Post_Trait;
11 +use uiCoreElements\Utils\Post_Filters_Trait;
12 +
13 +defined('ABSPATH') || exit();
14 +
15 +class AdvancedPostCarousel extends UiCoreWidget
16 +{
17 + use Carousel_Trait,
18 + Animation_Trait,
19 + Grid_Trait,
20 + Post_Filters_Trait,
21 + Post_Trait;
22 +
23 + private $_query;
24 +
25 + public function get_name()
26 + {
27 + return 'uicore-advanced-post-carousel';
28 + }
29 + public function get_categories()
30 + {
31 + return ['uicore'];
32 + }
33 + public function get_title()
34 + {
35 + return __('Advanced Post Carousel', 'uicore-elements');
36 + }
37 + public function get_icon()
38 + {
39 + return 'eicon-posts-carousel ui-e-widget';
40 + }
41 + public function get_keywords()
42 + {
43 + return ['post', 'carousel', 'slide', 'blog', 'recent', 'news'];
44 + }
45 + public function get_styles()
46 + {
47 + $styles = [
48 + 'advanced-post-carousel',
49 + 'carousel',
50 + 'post-meta',
51 + 'filters' => [
52 + 'condition' => [
53 + 'post_filtering' => 'yes',
54 + ]
55 + ],
56 + 'animation', // hover animations
57 + 'entrance', // entrance basic style
58 + ];
59 + if (!class_exists('\UiCore\Core') && !class_exists('\UiCoreAnimate\Base')) {
60 + $styles['e-animations'] = [ // entrance animations
61 + 'external' => true,
62 + ];
63 + }
64 + return $styles;
65 + }
66 + public function get_scripts()
67 + {
68 + return $this->TRAIT_get_carousel_scripts();
69 + }
70 + public function has_widget_inner_wrapper(): bool
71 + {
72 + // TODO: remove after Optmized Markup experiment is merged to the core
73 + return ! \Elementor\Plugin::$instance->experiments->is_feature_active('e_optimized_markup');
74 + }
75 +
76 + private function filter_missing_taxonomies($settings)
77 + {
78 + $taxonomy_filter_args = [
79 + 'show_in_nav_menus' => true,
80 + ];
81 + if (!empty($settings['posts-filter_post_type'])) {
82 + $taxonomy_filter_args['object_type'] = [$settings['posts-filter_post_type']];
83 + }
84 +
85 + $taxonomies = get_taxonomies($taxonomy_filter_args, 'objects');
86 +
87 + foreach ($taxonomies as $taxonomy => $object) {
88 + $controll_id = 'posts-filter_' . $taxonomy . '_ids';
89 + //error_log($controll_id);
90 + //error_log(print_r($settings[$controll_id], true));
91 +
92 + if (!isset($settings[$controll_id]) || empty($settings[$controll_id])) {
93 + continue;
94 + }
95 +
96 + //if is set check if this id still exists
97 + $settings[$controll_id] = array_filter($settings[$controll_id], function ($term_id) use ($object) {
98 + return term_exists($term_id, $object->name);
99 + });
100 +
101 + if (empty($settings[$controll_id])) {
102 + $settings[$controll_id] = null;
103 + }
104 + }
105 +
106 + return $settings;
107 + }
108 + public function on_import($element)
109 + {
110 + $element['settings'] = $this->filter_missing_taxonomies($element['settings']);
111 + return $element;
112 + }
113 + function get_query()
114 + {
115 + return $this->_query;
116 + }
117 +
118 + protected function register_controls()
119 + {
120 +
121 + // Contents and Settings
122 + $this->start_controls_section(
123 + 'section_layout',
124 + [
125 + 'label' => esc_html__('Carousel', 'uicore-elements'),
126 + ]
127 + );
128 + $this->TRAIT_register_carousel_additional_controls(); // Grid Layouts with old masonry control
129 + $this->end_controls_section();
130 +
131 + $this->start_controls_section(
132 + 'section_carousel_settings',
133 + [
134 + 'label' => __('Carousel Settings', 'uicore-elements'),
135 + ]
136 + );
137 + $this->TRAIT_register_carousel_settings_controls(); // Carousel settings
138 + $this->end_controls_section();
139 +
140 + $this->TRAIT_register_navigation_controls();
141 + $this->TRAIT_register_post_item_controls();
142 + $this->TRAIT_register_post_button_controls();
143 + $this->TRAIT_register_post_meta_controls();
144 + $this->TRAIT_register_post_query_controls();
145 + $this->TRAIT_register_filter_controls();
146 +
147 + // Styles
148 + $this->TRAIT_register_post_item_style_controls(); // instead of using carousel item style controls, we use post item and only updates some default values after. Is a better approach because advanced post widgets inherits some APG legacy codes and methods, such as setting borders and paddings on <article> instead of 'ui-e-item'
149 + $this->TRAIT_register_navigation_style_controls();
150 + $this->TRAIT_register_post_content_style_controls();
151 + $this->TRAIT_register_post_button_style_controls();
152 + $this->TRAIT_register_post_meta_style_controls();
153 + $this->TRAIT_register_filter_style_controls();
154 +
155 + $this->start_controls_section(
156 + 'section_style_animations',
157 + [
158 + 'label' => __('Animations', 'uicore-elements'),
159 + 'tab' => Controls_Manager::TAB_STYLE,
160 + ]
161 + );
162 + $this->TRAIT_register_entrance_animations_controls();
163 + $this->TRAIT_register_hover_animation_control(
164 + 'Item Hover Animation',
165 + [],
166 + ['underline'],
167 + );
168 + $this->TRAIT_register_post_animation_controls();
169 + $this->end_controls_section();
170 +
171 + // Update post component controls
172 + $this->update_responsive_control('image_size', [
173 + 'condition' => [],
174 + ]);
175 + $this->update_control('content_padding', [
176 + 'default' => [
177 + 'top' => 20,
178 + 'right' => 20,
179 + 'bottom' => 20,
180 + 'left' => 20,
181 + 'unit' => 'px',
182 + ],
183 + ]);
184 + $this->update_control('item_limit', [
185 + 'default' => [
186 + 'size' => 4,
187 + ],
188 + ]);
189 +
190 + // TODO: create new method to return animations list and use it throughout the plugin
191 + // Update carousel animations
192 + $this->update_control('animation_style', [
193 + 'options' => [
194 + 'circular' => esc_html__('Circular', 'uicore-elements'),
195 + 'fade_blur' => esc_html__('Fade Blur', 'uicore-elements'),
196 + 'default' => esc_html__('Default', 'uicore-elements'),
197 + ],
198 + ]);
199 + }
200 +
201 + function content_template() {}
202 +
203 + protected function render()
204 + {
205 + // Get query args, settings and post type slug
206 + global $wp_query;
207 + $default_query = $wp_query;
208 + $settings = $this->get_settings();
209 +
210 + // Get the quantity of items and creates a loop control
211 + $items = $settings['item_limit']['size'];
212 + $loops = 0;
213 +
214 + $this->TRAIT_render_center_loop_warning($items);
215 +
216 + // Build query
217 + $this->TRAIT_query_posts($settings, $wp_query->query);
218 + $wp_query = $this->get_query();
219 +
220 + $this->TRAIT_render_filters($settings);
221 +
222 + // No posts found
223 + if (!$wp_query->have_posts()) {
224 + echo '<p style="text-align:center">' . esc_html__('No posts found.', 'uicore-elements') . '</p>';
225 + } else {
226 +
227 +?>
228 + <div class="ui-e-carousel swiper">
229 + <div class='swiper-wrapper'>
230 + <?php
231 + while ($wp_query->have_posts()) {
232 +
233 + // sticky posts disregards posts per page, so ending the loop if $items == $loop forces the query respects the users item limit
234 + // if ($settings['sticky'] && $items == $loops) {
235 + // break;
236 + // }
237 +
238 + $wp_query->the_post();
239 + $this->TRAIT_render_item($loops, true);
240 +
241 + $loops++;
242 + }
243 + ?>
244 + </div>
245 + </div>
246 + <?php $this->TRAIT_render_carousel_navigations($items); ?>
247 +<?php
248 + }
249 +
250 + //reset query
251 + wp_reset_query();
252 + $wp_query = $default_query;
253 + }
254 +}
255 +\Elementor\Plugin::instance()->widgets_manager->register(new AdvancedPostCarousel());