PluginProbe ʕ •ᴥ•ʔ
Post Grid, Slider & Carousel Ultimate – with Shortcode, Gutenberg Block & Elementor Widget / trunk
Post Grid, Slider & Carousel Ultimate – with Shortcode, Gutenberg Block & Elementor Widget vtrunk
trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.7 1.3.8 1.4.0 1.4.1 1.4.2 1.4.3 1.6.0 1.6.1 1.6.10 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7 1.8
post-grid-carousel-ultimate / includes / classes / shortcode.php
post-grid-carousel-ultimate / includes / classes Last commit date
ajax.php 1 month ago custom-post.php 3 years ago metabox.php 2 years ago migration.php 2 years ago resize.php 3 years ago settings.php 4 years ago shortcode.php 1 year ago widget.php 4 years ago
shortcode.php
337 lines
1 <?php
2
3 if( !defined('ABSPATH')) { die('Direct access not allow');}
4
5
6 class PGCU_Shortcode
7 {
8
9 public function __construct() {
10 //add shortcode hoke
11 add_shortcode( "pgcu", array( $this,"shortcode_for_post_grid_carousel") );
12 add_shortcode( "PGCU", array( $this,"shortcode_for_post_grid_carousel") );
13 add_shortcode( "post_grid_carousel", array( $this,"shortcode_for_post_grid_carousel") );
14
15 }
16
17 //method for shortcode
18 public function shortcode_for_post_grid_carousel($atts, $content) {
19
20 ob_start();
21 $atts = shortcode_atts(
22 array(
23 'id' =>'',
24 'layout' => '',
25 'theme' => '',
26 'display_header_title' => '',
27 'header_title' => '',
28 'header_position' => '',
29 'display_title' => '',
30 'post_type' => '',
31 'post_from' => '',
32 'total_posts' => '',
33 'display_content' => '',
34 'content_word_limit' => '',
35 'display_read_more' => '',
36 'read_more_type' => '',
37 'display_author' => '',
38 'display_date' => '',
39 'display_term' => '',
40 'term_from' => '',
41 'g_column' => '',
42 'g_tablet' => '',
43 'g_mobile' => '',
44 'display_pagination' => '',
45 'pagination_type' => '',
46 'autoplay' => '',
47 'repeat_post' => '',
48 'pause_hover' => '',
49 'marquee' => '',
50 'post_column' => '',
51 'post_column_laptop' => '',
52 'post_column_tablet' => '',
53 'post_column_mobile' => '',
54 'c_autoplay_speed' => '',
55 'c_autoplay_time' => '',
56 'scrool_direction' => '',
57 'navigation' => '',
58 'navigation_position' => '',
59 'g_sort' => '',
60 'image_resize_crop' => '',
61 'image_width' => '',
62 'image_hight' => '',
63 ), $atts );
64
65 $post_id = ! empty( $atts['id'] ) ? absint( $atts['id'] ) : '';
66 $data = get_post_meta( $post_id, 'gc', true );
67 $data = ! is_array( $data ) ? post_grid_and_carousel_ultimate::json_decoded( $data ) : $data;
68 $value = is_array( $data ) ? $data : array();
69 extract( $value );
70
71 $rand = rand();
72
73 $layout = ! empty( $layout ) ? sanitize_text_field( $layout ) : 'carousel';
74 $theme = ! empty( $theme ) ? sanitize_text_field( $theme ) : 'theme-1';
75
76 $post_type = ! empty( $post_type ) ? sanitize_text_field( $post_type ) : 'post';
77 $term_from = ! empty( $term_from ) ? sanitize_text_field( $term_from ) : 'category';
78 $display_term = ! empty( $display_term ) ? sanitize_text_field( $display_term ) : 'yes';
79 $display_title = ! empty( $display_title ) ? sanitize_text_field( $display_title ) : 'yes';
80 $display_header_title = ! empty( $display_header_title ) ? sanitize_text_field( $display_header_title ) : 'no';
81 $header_title = ! empty( $header_title ) ? sanitize_text_field( $header_title ) : '';
82 $display_content = ! empty( $display_content ) ? sanitize_text_field( $display_content ) : 'yes';
83 $content_word_limit = ! empty( $content_word_limit ) ? sanitize_text_field( $content_word_limit ) : '16';
84 $display_read_more = ! empty( $display_read_more ) ? sanitize_text_field( $display_read_more ) : 'yes';
85 $read_more_text = ! empty( $read_more_text ) ? sanitize_text_field( $read_more_text ) : 'Read More';
86 $read_more_type = ! empty( $read_more_type ) ? sanitize_text_field( $read_more_type ) : 'link';
87 $display_author = ! empty( $display_author ) ? sanitize_text_field( $display_author ) : 'yes';
88 $display_date = ! empty( $display_date ) ? sanitize_text_field( $display_date ) : 'yes';
89 $post_from = ! empty( $post_from ) ? sanitize_text_field( $post_from ) : '';
90 $total_posts = ! empty( $total_posts ) ? sanitize_text_field( $total_posts ) : 12;
91
92 $image_resize_crop = ! empty( $image_resize_crop ) ? sanitize_text_field( $image_resize_crop ) : "yes";
93 $image_width = ! empty( $image_width ) ? sanitize_text_field( $image_width ) : 300;
94 $image_hight = ! empty( $image_hight ) ? sanitize_text_field( $image_hight ) : 290;
95
96 $navigation = ! empty( $navigation ) ? sanitize_text_field( $navigation ) : 'yes';
97 $navigation_position = ! empty( $navigation_position ) ? sanitize_text_field( $navigation_position ) : 'middle';
98 $navigation_arrow_color = ! empty( $navigation_arrow_color ) ? sanitize_text_field( $navigation_arrow_color ) : '#030517';
99 $navigation_arrow_hover_color = ! empty( $navigation_arrow_hover_color ) ? sanitize_text_field( $navigation_arrow_hover_color ) : '#fff';
100 $navigation_back_color = ! empty( $navigation_back_color ) ? sanitize_text_field( $navigation_back_color ) : '#f5f5f5';
101 $navigation_back_hover_color = ! empty( $navigation_back_hover_color ) ? sanitize_text_field( $navigation_back_hover_color ) : '#F31C1C';
102 $navigation_border_color = ! empty( $navigation_border_color ) ? sanitize_text_field( $navigation_border_color ) : '#f5f5f5';
103 $navigation_border_hover_color = ! empty( $navigation_border_hover_color ) ? sanitize_text_field( $navigation_border_hover_color ) : '#F31C1C';
104
105 $autoplay = ! empty( $autoplay ) ? sanitize_text_field( $autoplay ) : 'yes';
106 $pause_hover = ! empty( $pause_hover ) ? sanitize_text_field( $pause_hover ) : 'no';
107 $repeat_post = ! empty( $repeat_post ) ? sanitize_text_field( $repeat_post ) : 'yes';
108 $c_autoplay_speed = ! empty( $c_autoplay_speed ) ? sanitize_text_field( $c_autoplay_speed ) : '2000';
109 $c_autoplay_time = ! empty( $c_autoplay_time ) ? sanitize_text_field( $c_autoplay_time ) : '2000';
110
111 $post_column = ! empty( $post_column ) ? sanitize_text_field( $post_column ) : '3';
112 $post_column_laptop = ! empty( $post_column_laptop ) ? sanitize_text_field( $post_column_laptop ) : '3';
113 $post_column_tablet = ! empty( $post_column_tablet ) ? sanitize_text_field( $post_column_tablet ) : '2';
114 $post_column_mobile = ! empty( $post_column_mobile ) ? sanitize_text_field( $post_column_mobile ) : '1';
115
116 $g_column = ! empty( $g_column ) ? sanitize_text_field( $g_column ) : '3';
117 $g_tablet = ! empty( $g_tablet ) ? sanitize_text_field( $g_tablet ) : '2';
118 $g_mobile = ! empty( $g_mobile ) ? sanitize_text_field( $g_mobile ) : '1';
119
120 //grid pagination settings
121 $display_pagination = ! empty( $display_pagination ) ? sanitize_text_field( $display_pagination ) : 'yes';
122 $pagi_color = ! empty( $pagi_color ) ? sanitize_text_field( $pagi_color ) : '#333';
123 $pagi_border_color = ! empty( $pagi_border_color ) ? sanitize_text_field( $pagi_border_color ) : '#e4e4e4';
124 $pagi_back_color = ! empty( $pagi_back_color ) ? sanitize_text_field( $pagi_back_color ) : '#fff';
125
126 $pagi_hover_color = ! empty( $pagi_hover_color ) ? sanitize_text_field( $pagi_hover_color ) : '#fff';
127 $pagi_hover_border_color = ! empty( $pagi_hover_border_color ) ? sanitize_text_field( $pagi_hover_border_color ) : '#ff5500';
128 $pagi_hover_back_color = ! empty( $pagi_hover_back_color ) ? sanitize_text_field( $pagi_hover_back_color ) : '#ff5500';
129 $pagi_active_color = ! empty( $pagi_active_color ) ? sanitize_text_field( $pagi_active_color ) : '#fff';
130 $pagi_active_border_color = ! empty( $pagi_active_border_color ) ? sanitize_text_field( $pagi_active_border_color ) : '#ff5500';
131 $pagi_active_back_color = ! empty( $pagi_active_back_color ) ? sanitize_text_field( $pagi_active_back_color ) : '#ff5500';
132
133 $sortable_menu_text_color = ! empty( $sortable_menu_text_color ) ? sanitize_text_field( $sortable_menu_text_color ) : '#4F515A';
134 $sortable_menu_active_back_color = ! empty( $sortable_menu_active_back_color ) ? sanitize_text_field( $sortable_menu_active_back_color ) : '#030213';
135 $sortable_menu_active__text_color = ! empty( $sortable_menu_active__text_color ) ? sanitize_text_field( $sortable_menu_active__text_color ) : '#ffffff';
136
137 $header_title_color = ! empty( $header_title_color ) ? sanitize_text_field( $header_title_color ) : '#030213';
138 $post_title_color = ! empty( $post_title_color ) ? sanitize_text_field( $post_title_color ) : '#030213';
139 $post_title_hover_color = ! empty( $post_title_hover_color ) ? sanitize_text_field( $post_title_hover_color ) : '#F31C1C';
140 $post_content_color = ! empty( $post_content_color ) ? sanitize_text_field( $post_content_color ) : '#63666D';
141 $read_more_color = ! empty( $read_more_color ) ? sanitize_text_field( $read_more_color ) : '#030213';
142 $read_more_hover_color = ! empty( $read_more_hover_color ) ? sanitize_text_field( $read_more_hover_color ) : '#F31C1C';
143 $read_more_button_color = ! empty( $read_more_button_color ) ? sanitize_text_field( $read_more_button_color ) : '#030213';
144 $read_more_button_hover_color = ! empty( $read_more_button_hover_color ) ? sanitize_text_field( $read_more_button_hover_color ) : '#ffffff';
145 $read_more_button_background_color = ! empty( $read_more_button_background_color ) ? sanitize_text_field( $read_more_button_background_color ) : '#EFEFEF';
146 $read_more_button_background_hover_color = ! empty( $read_more_button_background_hover_color ) ? sanitize_text_field( $read_more_button_background_hover_color ) : '#030213';
147
148 // shortcode $atts
149 $layout = ! empty( $atts['layout'] ) ? sanitize_text_field( $atts['layout'] ) : $layout;
150 $theme = ! empty( $atts['theme'] ) ? sanitize_text_field( $atts['theme'] ) : $theme;
151 $display_header_title = ! empty( $atts['display_header_title'] ) ? sanitize_text_field( $atts['display_header_title'] ) : $display_header_title;
152 $header_position = ! empty( $atts['header_position'] ) ? sanitize_text_field( $atts['header_position'] ) : 'middle';
153 $header_title = ! empty( $atts['header_title'] ) ? sanitize_text_field( $atts['header_title'] ) : $header_title;
154 $display_title = ! empty( $atts['display_title'] ) ? sanitize_text_field( $atts['display_title'] ) : $display_title;
155 $post_type = ! empty( $atts['post_type'] ) ? sanitize_text_field( $atts['post_type'] ) : $post_type;
156 $post_from = ! empty( $atts['post_from'] ) ? sanitize_text_field( $atts['post_from'] ) : $post_from;
157 $total_posts = ! empty( $atts['total_posts'] ) ? sanitize_text_field( $atts['total_posts'] ) : $total_posts;
158 $display_content = ! empty( $atts['display_content'] ) ? sanitize_text_field( $atts['display_content'] ) : $display_content;
159 $content_word_limit = ! empty( $atts['content_word_limit'] ) ? sanitize_text_field( $atts['content_word_limit'] ) : $content_word_limit;
160 $display_read_more = ! empty( $atts['display_read_more'] ) ? sanitize_text_field( $atts['display_read_more'] ) : $display_read_more;
161 $read_more_type = ! empty( $atts['read_more_type'] ) ? sanitize_text_field( $atts['read_more_type'] ) : $read_more_type;
162 $display_author = ! empty( $atts['display_author'] ) ? sanitize_text_field( $atts['display_author'] ) : $display_author;
163 $display_date = ! empty( $atts['display_date'] ) ? sanitize_text_field( $atts['display_date'] ) : $display_date;
164 $display_term = ! empty( $atts['display_term'] ) ? sanitize_text_field( $atts['display_term'] ) : $display_term;
165 $term_from = ! empty( $atts['term_from'] ) ? sanitize_text_field( $atts['term_from'] ) : $term_from;
166 $g_column = ! empty( $atts['g_column'] ) ? sanitize_text_field( $atts['g_column'] ) : $g_column;
167 $g_tablet = ! empty( $atts['g_tablet'] ) ? sanitize_text_field( $atts['g_tablet'] ) : $g_tablet;
168 $g_mobile = ! empty( $atts['g_mobile'] ) ? sanitize_text_field( $atts['g_mobile'] ) : $g_mobile;
169 $display_pagination = ! empty( $atts['display_pagination'] ) ? sanitize_text_field( $atts['display_pagination'] ) : $display_pagination;
170 $autoplay = ! empty( $atts['autoplay'] ) ? sanitize_text_field( $atts['autoplay'] ) : $autoplay;
171 $repeat_post = ! empty( $atts['repeat_post'] ) ? sanitize_text_field( $atts['repeat_post'] ) : $repeat_post;
172 $pause_hover = ! empty( $atts['pause_hover'] ) ? sanitize_text_field( $atts['pause_hover'] ) : $pause_hover;
173 $post_column = ! empty( $atts['post_column'] ) ? sanitize_text_field( $atts['post_column'] ) : $post_column;
174 $post_column_laptop = ! empty( $atts['post_column_laptop'] ) ? sanitize_text_field( $atts['post_column_laptop'] ) : $post_column_laptop;
175 $post_column_tablet = ! empty( $atts['post_column_tablet'] ) ? sanitize_text_field( $atts['post_column_tablet'] ) : $post_column_tablet;
176 $post_column_mobile = ! empty( $atts['post_column_mobile'] ) ? sanitize_text_field( $atts['post_column_mobile'] ) : $post_column_mobile;
177 $c_autoplay_speed = ! empty( $atts['c_autoplay_speed'] ) ? sanitize_text_field( $atts['c_autoplay_speed'] ) : $c_autoplay_speed;
178 $c_autoplay_time = ! empty( $atts['c_autoplay_time'] ) ? sanitize_text_field( $atts['c_autoplay_time'] ) : $c_autoplay_time;
179 $navigation = ! empty( $atts['navigation'] ) ? sanitize_text_field( $atts['navigation'] ) : $navigation;
180 $navigation_position = ! empty( $atts['navigation_position'] ) ? sanitize_text_field( $atts['navigation_position'] ) : $navigation_position;
181 $image_resize_crop = ! empty( $atts['image_resize_crop'] ) ? sanitize_text_field( $atts['image_resize_crop'] ) : $image_resize_crop;
182 $image_width = ! empty( $atts['image_width'] ) ? sanitize_text_field( $atts['image_width'] ) : $image_width;
183 $image_hight = ! empty( $atts['image_hight'] ) ? sanitize_text_field( $atts['image_hight'] ) : $image_hight;
184
185 $allowed_themes = ['theme-1', 'theme-2', 'theme-3', 'theme-3']; // Define allowed themes
186 $theme = in_array($theme, $allowed_themes) ? $theme : 'theme-1';
187
188 $post_from = ! empty( $post_from ) ? $post_from : 'latest';
189 $paged = pgcu_get_paged_num();
190
191 $g_sort = ! empty( $g_sort ) ? $g_sort : 'category';
192 $terms = get_terms( array(
193 'taxonomy' => $g_sort,
194 'hide_empty' => false,
195 ) );
196
197
198 $args = array();
199 $common_args = [
200 'post_type' => $post_type,
201 'posts_per_page' => ( ! empty( $total_posts ) ? $total_posts : -1 ),
202 'status' => 'published',
203 'paged' => $paged
204
205 ];
206 if ( 'latest' == $post_from ) { $args = $common_args; }
207 elseif ('older' == $post_from) {
208 $older_args = [
209 'orderby' => 'date',
210 'order' => 'ASC',
211 ];
212 $args = array_merge($common_args, $older_args);
213 }else {
214 $args = $common_args;
215 }
216
217 $posts = new WP_Query( $args );
218
219 wp_localize_script( 'pgcu-ajax', 'pgcu_ajax', array(
220 'ajaxurl' => admin_url( 'admin-ajax.php' ), // WordPress AJAX
221 'query' => json_encode( $posts->query_vars ), // everything about your loop is here
222 ) );
223
224 $header_class = '';
225
226 if( 'middle' == $header_position ) {
227 $header_class = 'pgcu-posts__header--middle';
228 } elseif( 'right' == $header_position ) {
229 $header_class = 'pgcu-posts__header--right';
230 }
231
232 if( $posts->have_posts() ) { ?>
233 <?php if( 'yes' == $display_header_title ) { ?>
234 <div class="pgcu-posts__header <?php echo esc_attr( $header_class ); ?>" style="
235 --pgcu-headerFontSize: 24px;
236 --pgcu-headerFontColor: <?php echo esc_attr( $header_title_color ); ?>;
237 ">
238 <h2><?php echo esc_html( $header_title ); ?></h2>
239 </div>
240 <?php } ?>
241 <div class="pgcu-posts pgcu-<?php echo esc_attr( $theme ); ?> <?php echo ( 'carousel' == $layout ) ? 'pgcu-carousel' : ''; ?>"
242 <?php if( 'carousel' == $layout ) { ?>
243 data-pgcu-items="4"
244 data-pgcu-margin="30"
245 data-pgcu-loop="<?php echo ( 'yes' == $repeat_post ) ? 'true' : 'false'; ?>"
246 data-pgcu-perslide="2"
247 data-pgcu-speed="<?php echo esc_attr( $c_autoplay_speed ); ?>"
248 data-pgcu-autoplay='
249 <?php if( 'yes' == $autoplay ) { ?>
250 {
251 "delay": "<?php echo esc_attr( $c_autoplay_time ); ?>",
252 "pauseOnMouseEnter": <?php echo ( 'yes' == $pause_hover ) ? "true" : "false"; ?>,
253 "disableOnInteraction": false,
254 "stopOnLastSlide": true,
255 "reverseDirection": false
256 }
257 <?php } else { ?>
258 false
259 <?php } ?>
260 ' data-pgcu-responsive='{
261 "0": {"slidesPerView": "<?php echo esc_attr( $post_column_mobile ); ?>", "spaceBetween": "20", "slidesPerGroup":"1"},
262 "768": {"slidesPerView": "<?php echo esc_attr( $post_column_tablet ); ?>", "spaceBetween": "30", "slidesPerGroup":"1"},
263 "992": {"slidesPerView": "<?php echo esc_attr( $post_column_laptop ); ?>", "spaceBetween": "30", "slidesPerGroup":"1"},
264 "1200": {"slidesPerView": "<?php echo esc_attr( $post_column ); ?>", "spaceBetween": "30", "slidesPerGroup":"1"}
265 }'
266 <?php } ?>
267 >
268
269 <?php
270 if( 'isotope' == $layout ) {
271 include PGCU_INC_DIR . 'templates/sortable/sortable.php';
272 } elseif( 'yes' == $navigation && 'carousel' == $layout && ( 'top-left' == $navigation_position || 'top-right' == $navigation_position ) ) {
273 include PGCU_INC_DIR . 'templates/navigation/navigation.php';
274 }
275
276 ?>
277
278
279 <div class="<?php echo ( 'carousel' == $layout) ? 'swiper-wrapper' : 'pgcu-row pgcu-column-' . esc_attr( $g_column ) . ' pgcu-column-md-' . esc_attr( $g_tablet ) . ' pgcu-column-sm-' . esc_attr( $g_mobile ) . ''; ?>" style="
280 --pgcu-titleColor: <?php echo esc_attr( $post_title_color ); ?>;
281 --pgcu-titleColorHover: <?php echo esc_attr( $post_title_hover_color ); ?>;
282 --pgcu-excerptColor: <?php echo esc_attr( $post_content_color ); ?>;
283 --pgcu-readMoreColor: <?php echo esc_attr( $read_more_color ); ?>;
284 --pgcu-readMoreColorHover: <?php echo esc_attr( $read_more_hover_color ); ?>;
285 --pgcu-buttonFontSize: 14px;
286 --pgcu-buttonColor: <?php echo esc_attr( $read_more_button_color ); ?>;
287 --pgcu-buttonColorHover: <?php echo esc_attr( $read_more_button_hover_color ); ?>;
288 --pgcu-buttonBg: <?php echo esc_attr( $read_more_button_background_color ); ?>;
289 --pgcu-buttonBgHover: <?php echo esc_attr( $read_more_button_background_hover_color ); ?>;
290 ">
291
292 <?php
293 while( $posts->have_posts() ) : $posts->the_post();
294
295 $thumb = get_post_thumbnail_id();
296 // crop the image if the cropping is enabled.
297 if( 'yes' === $image_resize_crop ){
298 $pgcu_img = pgcu_image_cropping( $thumb, $image_width, $image_hight, true, 100 )['url'];
299 }else{
300 $aazz_thumb = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID()), 'large' );
301 $pgcu_img = $aazz_thumb['0'];
302 }
303
304 $get_terms = get_the_terms( get_the_ID(), $term_from );
305 $post_views = get_post_meta( get_the_id(), '_pgcu_post_views_count', true );
306
307 include PGCU_INC_DIR . 'templates/' . $theme . '.php';
308
309 endwhile;
310 ?>
311
312 </div>
313
314 <?php
315 if( 'yes' == $navigation && 'carousel' == $layout && ( 'middle' == $navigation_position || 'bottom-left' == $navigation_position || 'bottom-right' == $navigation_position ) ) {
316 include PGCU_INC_DIR . 'templates/navigation/navigation.php';
317 }elseif( 'grid' == $layout && 'yes' == $display_pagination ) {
318 include PGCU_INC_DIR . 'templates/pagination/pagination.php';
319 }
320 ?>
321
322 </div>
323
324
325 <?php
326
327 }
328
329 $true = ob_get_clean();
330 return $true;
331 }
332
333
334
335 }//end class
336
337