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-grid.php +100 -51 1.0.13 → 1.3.18 View file →
@@ -49,12 +49,19 @@
49 49 public function get_styles()
50 50 {
51 51 $styles = [
52 52 'advanced-post-grid',
53 + 'legacy-grid',
54 + 'post-meta',
55 + 'filters' => [
56 + 'condition' => [
57 + 'post_filtering' => 'yes',
58 + ],
59 + ],
53 60 'animation', // hover animations
54 61 'entrance', // entrance basic style
55 62 ];
56 - if(!class_exists('\UiCore\Core') && !class_exists('\UiCoreAnimate\Base')){
63 + if (!class_exists('\UiCore\Core') && !class_exists('\UiCoreAnimate\Base')) {
57 64 $styles['e-animations'] = [ // entrance animations
58 65 'external' => true,
59 66 ];
60 67 }
@@ -59,8 +66,30 @@
59 66 ];
60 67 }
61 68 return $styles;
62 69 }
70 +
71 + /**
72 + * Adds `woocommerce` classname so rating can inherit woo styles and
73 + * also follow theme option styles instead of plain text.
74 + */
75 + protected function add_render_attributes()
76 + {
77 + parent::add_render_attributes();
78 +
79 + if (class_exists('WooCommerce') && \is_woocommerce()) {
80 + return;
81 + }
82 +
83 + $this->add_render_attribute(
84 + '_wrapper',
85 + 'class',
86 + [
87 + 'woocommerce',
88 + $this->get_html_wrapper_class(),
89 + ]
90 + );
91 + }
63 92 public function get_scripts()
64 93 {
65 94 return [
66 95 'masonry' => [
@@ -79,20 +108,25 @@
79 108 ]
80 109 ]
81 110 ];
82 111 }
112 + public function has_widget_inner_wrapper(): bool
113 + {
114 + // TODO: remove after Optmized Markup experiment is merged to the core
115 + return ! \Elementor\Plugin::$instance->experiments->is_feature_active('e_optimized_markup');
116 + }
83 117
84 118 private function filter_missing_taxonomies($settings)
85 119 {
86 120 // Check if is an "Advanced Product.." widget, since this widget is extended by other(s)
87 121 $slug = strpos($this->get_name(), 'product') !== false ?
88 - 'product-filter_post_type' :
89 - 'posts-filter_post_type';
122 + 'product-filter_post_type' :
123 + 'posts-filter_post_type';
90 124
91 125 $taxonomy_filter_args = [
92 126 'show_in_nav_menus' => true,
93 127 ];
94 - if ( !empty($settings[$slug]) ) {
128 + if (!empty($settings[$slug])) {
95 129 $taxonomy_filter_args['object_type'] = [$settings[$slug]];
96 130 }
97 131
98 132 $taxonomies = get_taxonomies($taxonomy_filter_args, 'objects');
@@ -98,10 +132,10 @@
98 132 $taxonomies = get_taxonomies($taxonomy_filter_args, 'objects');
99 133
100 134 foreach ($taxonomies as $taxonomy => $object) {
101 135 $controll_id = 'posts-filter_' . $taxonomy . '_ids';
102 - \error_log($controll_id);
103 - \error_log(print_r($settings[$controll_id], true));
136 + //error_log($controll_id);
137 + //error_log(print_r($settings[$controll_id], true));
104 138
105 139 if (!isset($settings[$controll_id]) || empty($settings[$controll_id])) {
106 140 continue;
107 141 }
@@ -141,9 +175,9 @@
141 175 [
142 176 'label' => esc_html__('Grid', 'uicore-elements'),
143 177 ]
144 178 );
145 - $this->TRAIT_register_grid_layout_controls();
179 + $this->TRAIT_register_grid_layout_controls();
146 180 $this->end_controls_section();
147 181
148 182 $this->TRAIT_register_post_item_controls();
149 183 $this->TRAIT_register_post_button_controls();
@@ -166,21 +200,21 @@
166 200 'label' => __('Animations', 'uicore-elements'),
167 201 'tab' => Controls_Manager::TAB_STYLE,
168 202 ]
169 203 );
170 - $this->TRAIT_register_entrance_animations_controls();
171 - $this->TRAIT_register_hover_animation_control(
172 - 'Item Hover Animation',
173 - [],
174 - ['underline'],
175 - 'anim_item'
176 - );
177 - $this->TRAIT_register_post_animation_controls();
204 + $this->TRAIT_register_entrance_animations_controls();
205 + $this->TRAIT_register_hover_animation_control(
206 + 'Item Hover Animation',
207 + [],
208 + ['underline'],
209 + 'anim_item'
210 + );
211 + $this->TRAIT_register_post_animation_controls();
178 212 $this->end_controls_section();
179 213
180 214 // Update masonry from component to a legacy version
181 215 $this->update_control('masonry', [
182 - 'label' => __( 'Masonry', 'uicore-elements' ),
216 + 'label' => __('Masonry', 'uicore-elements'),
183 217 'type' => Controls_Manager::SWITCHER,
184 218 'frontend_available' => true,
185 219 'default' => 'no',
186 220 'return_value' => 'ui-e-maso',
@@ -191,11 +225,9 @@
191 225 'selectors' => [],
192 226 ]);
193 227 }
194 228
195 - function content_template()
196 - {
197 - }
229 + function content_template() {}
198 230
199 231 /**
200 232 * Renders the widget content using AJAX.
201 233 *
@@ -202,28 +234,30 @@
202 234 * This method retrieves the widget settings; set up the query, and renders each post item.
203 235 * If no posts are found, it returns false. After rendering, it resets the query and returns the output.
204 236 *
205 237 * @param array|false $current_query The current query args, or false if the widget isn't set to use the current query.
238 + * @param int $pageID The ID of the page where the widget is located.
206 239 *
207 240 * @return string|false The rendered widget content or false if no posts are found.
208 - */
241 + */
209 242 public function render_ajax($current_query)
210 243 {
211 -
212 244 // Get settings and post type
213 245 $settings = $this->get_settings();
246 + $loop = 0;
214 247
215 - $this->TRAIT_query_posts( $settings, $current_query );
248 + $this->TRAIT_query_posts($settings, $current_query);
216 249 $wp_query = $this->get_query();
217 250
218 - if (!$wp_query->have_posts()) {
219 - return false;
251 + if (!$wp_query || !$wp_query->have_posts()) {
252 + $markup = '';
220 253 }
221 254
222 255 \ob_start();
223 256 while ($wp_query->have_posts()) {
224 257 $wp_query->the_post();
225 - $this->TRAIT_render_item(false, true);
258 + $this->TRAIT_render_item($loop, false, true);
259 + $loop++;
226 260 }
227 261 $markup = \ob_get_clean();
228 262
229 263 return [
@@ -232,8 +266,11 @@
232 266 }
233 267
234 268 protected function render()
235 269 {
270 + // Get current post ID
271 + $post_id = get_the_ID();
272 +
236 273 // Get query args, settings and post type slug
237 274 global $wp_query;
238 275 $default_query = $wp_query;
239 276 $settings = $this->get_settings();
@@ -238,13 +275,11 @@
238 275 $default_query = $wp_query;
239 276 $settings = $this->get_settings();
240 277
241 278 // Build query
242 - $this->TRAIT_query_posts( $settings, $wp_query->query );
279 + $this->TRAIT_query_posts($settings, $wp_query->query);
243 280 $wp_query = $this->get_query();
244 281
245 - $this->TRAIT_set_meta_font_size_to_svg($settings); // SVG icon experiment font-size adjustment
246 -
247 282 // Store widget settings in a transient
248 283 $ID = strval($this->get_ID());
249 284 set_transient('ui_elements_widgetdata_' . $ID, $settings, \MONTH_IN_SECONDS);
250 285
@@ -251,43 +286,57 @@
251 286 // Get the quantity of items and creates a loop control
252 287 $items = $settings['item_limit']['size'];
253 288 $loops = 0;
254 289
290 + // Set masonry class
291 + $masonry = $this->is_option('masonry', 'yes')
292 + ? 'ui-e-maso'
293 + : '';
294 +
255 295 $this->TRAIT_render_filters($settings);
256 296
257 297 // No posts found
258 298 if (!$wp_query->have_posts()) {
259 - echo '<p style="text-align:center">' . __('No posts found.', 'uicore-elements') . '</p>';
299 + echo '<p style="text-align:center">' . esc_html__('No posts found.', 'uicore-elements') . '</p>';
260 300 } else {
261 301
262 - ?>
263 - <div class="ui-e-adv-grid">
264 - <?php
265 - while ($wp_query->have_posts()) {
302 +?>
303 + <div class="ui-e-adv-grid <?php echo esc_attr($masonry); ?>">
304 + <?php
305 + while ($wp_query->have_posts()) {
266 306
267 - // sticky posts disregards posts per page, so ending the loop if $items == $loop forces the query respects the users item limit
268 - if ($settings['sticky'] && $items == $loops) {
269 - break;
270 - }
307 + // sticky posts disregards posts per page, so ending the loop if $items == $loop forces the query respects the users item limit
308 + if ($settings['sticky'] && $items == $loops) {
309 + break;
310 + }
271 311
272 - $wp_query->the_post();
273 - $this->TRAIT_render_item(false, true);
312 + $wp_query->the_post();
313 + $this->TRAIT_render_item($loops, false, true);
274 314
275 - $loops++;
276 - }
277 - ?>
278 - </div>
279 - <?php
315 + $loops++;
316 + }
317 + ?>
318 + </div>
319 +<?php
280 320
281 - $this->TRAIT_render_pagination($settings);
321 + $this->TRAIT_render_pagination($settings, $post_id);
282 322
283 - if( $settings['pagination'] == 'yes' && $settings['pagination_type'] == 'load_more' && $settings['posts-filter_post_type'] == 'current' ) {
323 + if (
324 + $this->is_option('pagination', 'yes') &&
325 + $this->is_option('pagination_type', 'load_more') &&
326 + $this->is_option('posts-filter_post_type', 'current')
327 + ) {
284 328
285 - echo '<script>';
286 - echo 'window.ui_total_pages_' . esc_html($ID) . ' = "none";'; // add none to avoid ajax errors for lack of value, but posts don't need it
287 - echo 'window.ui_query_' . esc_html($ID) . ' = ' . \json_encode($wp_query) . ';';
288 - echo '</script>';
289 - }
329 + // Build the public query args the ajax request script passes to rest api
330 + $public_query = array();
331 + $public_query['query']['post_type'] = get_post_type();
332 + $public_query['query_vars'] = $wp_query->query_vars;
333 +
334 + echo '<script>';
335 + echo 'window.ui_total_pages_' . esc_html($ID) . ' = "none";'; // add none to avoid ajax errors for lack of value, but posts don't need it
336 + echo 'window.ui_query_' . esc_html($ID) . ' = ' . \json_encode($public_query) . ';';
337 + echo '</script>';
338 + }
290 339 }
291 340
292 341 //reset query
293 342 wp_reset_query();