PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.13.1
WpStream – Live Streaming, Video on Demand, Pay Per View v4.13.1
4.14.1 4.14.0 4.13.2 4.13.1 4.13 4.12.5 4.12.4 4.12.3 4.12.2 4.12.1 4.12 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5 4.5.1 4.5.11 4.5.11.1 4.5.11.2 4.5.11.4 4.5.11.5 4.5.11.6 All 181 releases
wpstream / hello-wpstream / framework / shortcodes-functions.php

shortcodes-functions.php in WpStream – Live Streaming, Video on Demand, Pay Per View 4.13.1, at hello-wpstream/framework/shortcodes-functions.php

596 lines 23.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Shortcodes functions
4 *
5 * @package wpstream-theme
6 */
7
8 add_action( 'wp_ajax_nopriv_wpstream_shortcode_with_top_bar_load_more_function', 'wpstream_shortcode_with_top_bar_load_more_function' );
9 add_action( 'wp_ajax_wpstream_shortcode_with_top_bar_load_more_function', 'wpstream_shortcode_with_top_bar_load_more_function' );
10 if ( ! function_exists( 'wpstream_shortcode_with_top_bar_load_more_function' ) ) {
11 /**
12 * Shortcode load more
13 */
14 function wpstream_shortcode_with_top_bar_load_more_function() {
15 // Verify nonce.
16 // if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'shortcode_nonce_ajax_action' ) ) {
17 // wp_send_json_error( 'Nonce verification failed.', 403 );
18 // }
19
20 $attributes = array();
21 $attributes['paged'] = isset( $_POST['paged'] ) ? intval( $_POST['paged'] ) : 0;
22 $attributes['type'] = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
23 $attributes['category_ids'] = isset( $_POST['category_ids'] ) ? sanitize_text_field( wp_unslash( $_POST['category_ids'] ) ) : '';
24 $attributes['wpstream_category_ids'] = isset( $_POST['wpstream_category_ids'] ) ? sanitize_text_field( wp_unslash( $_POST['wpstream_category_ids'] ) ) : '';
25 $attributes['movie_ratings_ids'] = isset( $_POST['movie_ratings_ids'] ) ? sanitize_text_field( wp_unslash( $_POST['movie_ratings_ids'] ) ) : '';
26 $attributes['actors_ids'] = isset( $_POST['actors_ids'] ) ? sanitize_text_field( wp_unslash( $_POST['actors_ids'] ) ) : '';
27 $attributes['number'] = isset( $_POST['number'] ) ? intval( $_POST['number'] ) : 0;
28 $attributes['rownumber'] = isset( $_POST['rownumber'] ) ? intval( $_POST['rownumber'] ) : 0;
29 $attributes['sort_by'] = isset( $_POST['sort_by'] ) ? intval( $_POST['sort_by'] ) : 0;
30 $attributes['pagination_type'] = isset( $_POST['pagination_type'] ) ? intval( $_POST['pagination_type'] ) : 0;
31 $attributes['is_ajax_request'] = isset( $_POST['is_ajax'] ) ? intval( $_POST['is_ajax'] ) : 0;
32 $attributes['current_page'] = isset( $_POST['current_page'] ) ? intval( $_POST['current_page'] ) : 0;
33 $attributes['video_card'] = isset( $_POST['video_card'] ) ? intval( $_POST['video_card'] ) : 1;
34 wpstream_theme_recent_items_top_bar( $attributes );
35 }
36 }
37
38
39
40 /**
41 * Shortcodes functions
42 *
43 * @package wpstream-theme
44 */
45
46 add_action( 'wp_ajax_nopriv_wpstream_shortcode_load_more_function', 'wpstream_shortcode_load_more_function' );
47 add_action( 'wp_ajax_wpstream_shortcode_load_more_function', 'wpstream_shortcode_load_more_function' );
48 if ( ! function_exists( 'wpstream_shortcode_load_more_function' ) ) {
49 /**
50 * Shortcode load more
51 */
52 function wpstream_shortcode_load_more_function() {
53 // Verify nonce.
54 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'shortcode_nonce_ajax_action' ) ) {
55 wp_send_json_error( 'Nonce verification failed.', 403 );
56 }
57
58 $attributes = array();
59 $attributes['paged'] = isset( $_POST['paged'] ) ? intval( $_POST['paged'] ) : 0;
60 $attributes['type'] = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
61 $attributes['category_ids'] = isset( $_POST['category_ids'] ) ? sanitize_text_field( wp_unslash( $_POST['category_ids'] ) ) : '';
62 $attributes['wpstream_category_ids'] = isset( $_POST['wpstream_category_ids'] ) ? sanitize_text_field( wp_unslash( $_POST['wpstream_category_ids'] ) ) : '';
63 $attributes['movie_ratings_ids'] = isset( $_POST['movie_ratings_ids'] ) ? sanitize_text_field( wp_unslash( $_POST['movie_ratings_ids'] ) ) : '';
64 $attributes['actors_ids'] = isset( $_POST['actors_ids'] ) ? sanitize_text_field( wp_unslash( $_POST['actors_ids'] ) ) : '';
65 $attributes['number'] = isset( $_POST['number'] ) ? intval( $_POST['number'] ) : 0;
66 $attributes['rownumber'] = isset( $_POST['rownumber'] ) ? intval( $_POST['rownumber'] ) : 0;
67 $attributes['sort_by'] = isset( $_POST['sort_by'] ) ? intval( $_POST['sort_by'] ) : 0;
68 $attributes['pagination_type'] = isset( $_POST['pagination_type'] ) ? intval( $_POST['pagination_type'] ) : 0;
69 $attributes['is_ajax_request'] = isset( $_POST['is_ajax'] ) ? intval( $_POST['is_ajax'] ) : 0;
70 $attributes['current_page'] = isset( $_POST['current_page'] ) ? intval( $_POST['current_page'] ) : 0;
71 $attributes['video_uid'] = isset( $_POST['video_uid'] ) ? sanitize_text_field( $_POST['video_uid'] ) : 0;
72 $attributes['video_card'] = isset( $_POST['video_card'] ) ? sanitize_text_field( $_POST['video_card'] ) : 1;
73 wpstream_item_list_shortcodes( $attributes );
74 }
75 }
76
77
78 /**
79 * Shortcodes functions
80 *
81 * @package wpstream-theme
82 */
83
84 add_action( 'wp_ajax_nopriv_wpstream_shortcode_load_more_blog_list_function', 'wpstream_shortcode_load_more_blog_list_function' );
85 add_action( 'wp_ajax_wpstream_shortcode_load_more_blog_list_function', 'wpstream_shortcode_load_more_blog_list_function' );
86 if ( ! function_exists( 'wpstream_shortcode_load_more_blog_list_function' ) ) {
87 /**
88 * Shortcode load more
89 */
90 function wpstream_shortcode_load_more_blog_list_function() {
91 // Verify nonce.
92 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'shortcode_nonce_ajax_action' ) ) {
93 wp_send_json_error( 'Nonce verification failed.', 403 );
94 }
95
96 $attributes = array();
97 $attributes['paged'] = isset( $_POST['paged'] ) ? intval( $_POST['paged'] ) : 0;
98 $attributes['type'] = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
99 $attributes['category_ids'] = isset( $_POST['category_ids'] ) ? sanitize_text_field( wp_unslash( $_POST['category_ids'] ) ) : '';
100 $attributes['number'] = isset( $_POST['number'] ) ? intval( $_POST['number'] ) : 0;
101 $attributes['rownumber'] = isset( $_POST['rownumber'] ) ? intval( $_POST['rownumber'] ) : 0;
102 $attributes['sort_by'] = isset( $_POST['sort_by'] ) ? intval( $_POST['sort_by'] ) : 0;
103 $attributes['pagination_type'] = isset( $_POST['pagination_type'] ) ? intval( $_POST['pagination_type'] ) : 0;
104 $attributes['is_ajax_request'] = isset( $_POST['is_ajax'] ) ? intval( $_POST['is_ajax'] ) : 0;
105 $attributes['current_page'] = isset( $_POST['current_page'] ) ? intval( $_POST['current_page'] ) : 0;
106 $attributes['blog_uid'] = isset( $_POST['blog_uid'] ) ? sanitize_text_field( $_POST['blog_uid'] ) : '';
107
108 wpstream_blog_list_shortcodes( $attributes );
109 }
110 }
111
112 /**
113 * Populates attributes from $_GET array if 'from_ajax' is set to 'yes'.
114 *
115 * @param array $attributes Array of attributes.
116 * @return array Populated attributes.
117 */
118 function wpstream_populate_from_get( $attributes ) {
119 if ( isset( $_GET['from_ajax'] ) && 'yes' === $_GET['from_ajax'] ) {
120 if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['nonce'] ) ), 'shortcode_nonce_ajax_action' ) ) {
121 // Nonce verification failed.
122 return $attributes;
123 }
124
125 $attributes['type'] = isset( $_GET['type'] ) ? sanitize_text_field( wp_unslash( $_GET['type'] ) ) : '';
126 $attributes['category_ids'] = isset( $_GET['category_ids'] ) ? sanitize_text_field( wp_unslash( $_GET['category_ids'] ) ) : '';
127 $attributes['wpstream_category_ids'] = isset( $_GET['wpstream_category_ids'] ) ? sanitize_text_field( wp_unslash( $_GET['wpstream_category_ids'] ) ) : '';
128 $attributes['movie_ratings_ids'] = isset( $_GET['movie_ratings_ids'] ) ? sanitize_text_field( wp_unslash( $_GET['movie_ratings_ids'] ) ) : '';
129 $attributes['actors_ids'] = isset( $_GET['actors_ids'] ) ? sanitize_text_field( wp_unslash( $_GET['actors_ids'] ) ) : '';
130 $attributes['sort_by'] = isset( $_GET['sort_by'] ) ? sanitize_text_field( wp_unslash( $_GET['sort_by'] ) ) : '';
131 }
132
133 return $attributes;
134 }
135
136
137 if ( ! function_exists( 'wpstream_return_item_list_elementor' ) ) {
138 /**
139 * Returns a list of items for use in Elementor.
140 *
141 * @param WP_Query $query The WordPress query to retrieve items.
142 * @param string $items_column_class CSS class for the columns where the items will be placed.
143 */
144 function wpstream_return_item_list_elementor( $query, $items_column_class ) {
145 $overwrite_wpstream_cols_name = $items_column_class;
146
147 if ( $query->found_posts > 0 ) {
148 include WPSTREAM_PLUGIN_PATH . '/hello-wpstream/template-parts/single/video-loop-content.php';
149 }
150 }
151 }
152
153
154 if ( ! function_exists( 'wpstream_return_item_list_pagination' ) ) {
155 /**
156 * Returns the pagination for the item list.
157 *
158 * @param WP_Query $query The WordPress query used to retrieve items.
159 * @param int $pagination Type of pagination (1 for "Load More" button, 2 for standard pagination).
160 */
161 function wpstream_return_item_list_pagination( $query, $pagination,$uid='' ) {
162
163 if ( $query->found_posts > 0 ) {
164 print wpstream_add_pagination( $query, $pagination ,$uid); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
165 } else {
166 print '<div class="wpstream-pagination">' . esc_html__( 'There are no items', 'hello-wpstream' ) . '</div>';
167 }
168 }
169 }
170
171 if ( ! function_exists( 'wpstream_return_ajax_elements' ) ) {
172 /**
173 * Returns the HTML elements for AJAX response.
174 *
175 * @param WP_Query $query The WordPress query used to retrieve items.
176 * @param string $items_column_class The CSS class for the items column.
177 * @return array An array containing the post count and HTML content.
178 */
179 function wpstream_return_ajax_elements( $query, $items_column_class,$unit='',$card_type=1 ) {
180 $overwrite_wpstream_cols_name = $items_column_class;
181
182 ob_start();
183 $card_grid_class_overwrite =$items_column_class;
184 if ( $query->found_posts > 0 ) {
185 while ( $query->have_posts() ) {
186 $query->the_post();
187 if ( 'blog' === $unit ) {
188 $blog_unit_card_type = wpstream_blog_post_card_selector(0);
189 include WPSTREAM_PLUGIN_PATH . 'hello-wpstream/' . $blog_unit_card_type;
190 } else {
191 $unit_card_type = wpstream_video_item_card_selector(intval($card_type));
192 include WPSTREAM_PLUGIN_PATH . 'hello-wpstream/' . $unit_card_type;
193 }
194 }
195 }
196 $html = ob_get_contents();
197 ob_end_clean();
198
199 return array(
200 'post_count' => $query->post_count,
201 'html' => $html,
202 );
203 }
204 }
205
206 if ( ! function_exists( 'wpstream_add_pagination' ) ) {
207 /**
208 * Generates pagination HTML based on the pagination type.
209 *
210 * @param WP_Query $query The WordPress query object.
211 * @param int $pagination The pagination type.
212 * @return string The generated pagination HTML.
213 */
214 function wpstream_add_pagination( $query, $pagination,$uid='' ) {
215 $return_string = '';
216
217 if ( 1 === intval($pagination) ) {
218 $return_string = '<div class="wpstream_load_more_wrapper wpstream-pagination"><button type="button" class="btn btn-primary wpstream_load_more">' . esc_html__( 'Load More', 'hello-wpstream' ) . '</button></div>';
219 } elseif ( 2 === intval($pagination) ) {
220 ob_start();
221 // wpstream_shortcode_pagination( $query->max_num_pages ,2,'',$uid);
222 $return_string = ob_get_contents();
223 ob_end_clean();
224 }
225
226 return $return_string;
227 }
228 }
229
230 if ( ! function_exists( 'wpstream_compose_ajax_holder_data' ) ) {
231 /**
232 * Composes the HTML data attributes for the AJAX holder shortcode.
233 *
234 * @param array $attributes The attributes for the AJAX holder shortcode.
235 * @return string The composed HTML data attributes.
236 */
237 function wpstream_compose_ajax_holder_data( $attributes ) {
238
239 $video_card=1;
240 if(isset($attributes['video_card'])){
241 $video_card = intval($attributes['video_card']);
242 }
243
244 $return_string = '<div class="wpstream_ajax_holder_shortcode" style="display:none" data-video-card="'.esc_attr($video_card).'" data-current-page="' . get_the_ID() . '" data-paged="1" ';
245 foreach ( $attributes as $key => $value ) {
246
247 $data_key_name = str_replace( '_', '-', $key );
248 $return_string .= ' data-' . esc_attr( $data_key_name ) . '="';
249 if ( is_array( $value ) ) {
250 $return_string .= wp_json_encode( $value );
251 } else {
252 $return_string .= sanitize_text_field( $value );
253 }
254 $return_string .= '"';
255 }
256
257 $return_string .= '></div>';
258 return $return_string;
259 }
260 }
261
262
263 /*
264 * Wpstream shortcode input to tax
265 *
266 *
267 */
268
269 if ( ! function_exists( 'wpstream_item_list_shortcodes_input_to_tax' ) ) {
270 /**
271 * Item list shortcodes
272 */
273 function wpstream_item_list_shortcodes_input_to_tax() {
274 return array(
275 'actors_ids' => 'wpstream_actors',
276 'movie_ratings_ids' => 'wpstream_movie_rating',
277 'wpstream_category_ids' => 'wpstream_category',
278 'category_ids' => 'category',
279 'post_tag_ids' => 'post_tag',
280 );
281 }
282 }
283 /*
284 * Wpstream filter bar - shortcode
285 *
286 *
287 */
288
289 if ( ! function_exists( 'wpstream_filter_bar_blog_posts' ) ) {
290 /**
291 * Generates the filter bar HTML content based on the provided attributes.
292 *
293 * @param array $attributes_data The attributes data for generating the filter bar.
294 * @return string The HTML content of the filter bar.
295 */
296 function wpstream_filter_bar_blog_posts( $attributes_data ) {
297 $return_string = '';
298 $attributes = $attributes_data;
299 ob_start();
300 include WPSTREAM_PLUGIN_PATH . 'hello-wpstream/template-parts/shortcodes/blog-list-filters.php';
301 $filters = ob_get_contents();
302 ob_end_clean();
303
304 $return_string .= $filters;
305 return $return_string;
306 }
307 }
308
309
310
311
312 /*
313 * Wpstream filter bar - shortcode
314 *
315 *
316 */
317
318 if ( ! function_exists( 'wpstream_filter_bar' ) ) {
319 /**
320 * Generates the filter bar HTML content based on the provided attributes.
321 *
322 * @param array $attributes_data The attributes data for generating the filter bar.
323 * @return string The HTML content of the filter bar.
324 */
325 function wpstream_filter_bar( $attributes_data ) {
326 $return_string = '';
327 $attributes = $attributes_data;
328 ob_start();
329 include WPSTREAM_PLUGIN_PATH . 'hello-wpstream/template-parts/shortcodes/property-list-filters.php';
330 $filters = ob_get_contents();
331 ob_end_clean();
332
333 $return_string .= $filters;
334 return $return_string;
335 }
336 }
337
338 if ( ! function_exists( 'wpstream_taxonomy_terms_dropdown' ) ) {
339 /**
340 * Generates a dropdown select element for a taxonomy's terms.
341 *
342 * @param string $taxonomy The taxonomy to retrieve terms from.
343 * @param string $selected_term_slug Optional. The slug of the selected term. Default is ''.
344 * @param array $attributes Optional. Additional attributes for the select element. Default is an empty array.
345 * @return string The HTML markup for the dropdown select element.
346 */
347 function wpstream_taxonomy_terms_dropdown( $taxonomy, $selected_term_slug = '', $attributes = '' ) {
348 if ( ! taxonomy_exists( $taxonomy ) ) {
349 return '';
350 }
351
352 // Initialize $selected_term_slug based on $_GET if it's not provided.
353 switch ( $taxonomy ) {
354 case 'category':
355 $selected_term_slug = isset( $_GET['category_ids'] ) ? sanitize_text_field( wp_unslash( $_GET['category_ids'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
356 break;
357 case 'wpstream_actors':
358 $selected_term_slug = isset( $_GET['actors_ids'] ) ? sanitize_text_field( wp_unslash( $_GET['actors_ids'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
359 break;
360 case 'wpstream_category':
361 $selected_term_slug = isset( $_GET['wpstream_category_ids'] ) ? sanitize_text_field( wp_unslash( $_GET['wpstream_category_ids'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
362 break;
363 case 'wpstream_movie_rating':
364 $selected_term_slug = isset( $_GET['movie_ratings_ids'] ) ? sanitize_text_field( wp_unslash( $_GET['movie_ratings_ids'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
365 break;
366 }
367
368 $args = array(
369 'taxonomy' => $taxonomy,
370 'hide_empty' => false, // This will include terms with 0 posts.
371 );
372 $terms = get_terms( $args );
373
374 // Start the markup for our select element.
375 $output = '<select name="' . esc_attr( $taxonomy ) . '" class="wpstream_dropdown_select wpstream_dropdown_select_trigger_ajax" id="wpstream_dropdown_' . esc_attr( $taxonomy ) . '">';
376
377 // Add a default option (optional).
378 $output .= '<option value="">';
379 if ( isset( $attributes[ 'label_' . $taxonomy ] ) ) {
380 $output .= $attributes[ 'label_' . $taxonomy ];
381 } else {
382 $output .= esc_html_e( 'Select term', 'hello-wpstream' );
383 }
384
385 $output .= '</option>';
386
387 // Check if we have any terms.
388 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
389 foreach ( $terms as $term ) {
390 // Check if this term is the selected term.
391 $selected = selected( $selected_term_slug, $term->term_id, false );
392
393 // Add an option for the term.
394 $output .= sprintf(
395 '<option value="%s"%s>%s</option>',
396 esc_attr( $term->term_id ),
397 $selected,
398 esc_html( $term->name )
399 );
400 }
401 }
402
403 // Close the select element.
404 $output .= '</select>';
405
406 // Return the generated dropdown.
407 return $output;
408 }
409 }
410
411
412 if ( ! function_exists( 'wpstream_taxonomy_terms_dropdown_bootstrap' ) ) {
413 /**
414 * Generates a dropdown select element for a taxonomy's terms.
415 *
416 * @param string $taxonomy The taxonomy to retrieve terms from.
417 * @param string $selected_term_slug Optional. The slug of the selected term. Default is ''.
418 * @param array $attributes Optional. Additional attributes for the select element. Default is an empty array.
419 * @return string The HTML markup for the dropdown select element.
420 */
421 function wpstream_taxonomy_terms_dropdown_bootstrap( $taxonomy, $selected_term_slug = '', $attributes = '' ) {
422 if ( ! taxonomy_exists( $taxonomy ) ) {
423 return '';
424 }
425
426 // Initialize $selected_term_slug based on $_GET if it's not provided.
427 switch ( $taxonomy ) {
428 case 'category':
429 $selected_term_slug = isset( $_GET['category_ids'] ) ? sanitize_text_field( wp_unslash( $_GET['category_ids'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
430 break;
431 case 'wpstream_actors':
432 $selected_term_slug = isset( $_GET['actors_ids'] ) ? sanitize_text_field( wp_unslash( $_GET['actors_ids'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
433 break;
434 case 'wpstream_category':
435 $selected_term_slug = isset( $_GET['wpstream_category_ids'] ) ? sanitize_text_field( wp_unslash( $_GET['wpstream_category_ids'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
436 break;
437 case 'wpstream_movie_rating':
438 $selected_term_slug = isset( $_GET['movie_ratings_ids'] ) ? sanitize_text_field( wp_unslash( $_GET['movie_ratings_ids'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
439 break;
440 }
441
442 $args = array(
443 'taxonomy' => $taxonomy,
444 'hide_empty' => false, // This will include terms with 0 posts.
445 );
446 $terms = get_terms( $args );
447
448 $values = array();
449 $label = '';
450 $name = esc_attr( $taxonomy );
451 $class = 'wpstream_dropdown_select wpstream_dropdown_select_trigger_ajax wpstream_dropdown_select_'.$name;
452 $id = 'wpstream_dropdown_' . esc_attr( $taxonomy );
453
454
455 if ( isset( $attributes[ 'label_' . $taxonomy ] ) ) {
456 $label .= $attributes[ 'label_' . $taxonomy ];
457 } else {
458 $label .= esc_html_e( 'Select term', 'hello-wpstream' );
459 }
460
461
462
463
464 // Check if we have any terms.
465 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
466 foreach ( $terms as $term ) {
467 $values[$term->term_id]=$term->name;
468 }
469 }
470
471 $output = wpstream_create_custom_dropdown( $values,$name, $class, $id, $label,$selected_term_slug);
472 // Return the generated dropdown.
473 return $output;
474 }
475 }
476
477
478
479 /*
480 * Filter BLog Post list
481 *
482 */
483
484 if ( ! function_exists( 'wpstream_taxonomy_terms_dropdown_blog_post_list' ) ) {
485 /**
486 * Generates a dropdown select element for a taxonomy's terms.
487 *
488 * @param string $taxonomy The taxonomy to retrieve terms from.
489 * @param string $selected_term_slug Optional. The slug of the selected term. Default is ''.
490 * @param array $attributes Optional. Additional attributes for the select element. Default is an empty array.
491 * @return string The HTML markup for the dropdown select element.
492 */
493 function wpstream_taxonomy_terms_dropdown_blog_post_list( $taxonomy, $selected_term_slug = '', $attributes = '' ) {
494 if ( ! taxonomy_exists( $taxonomy ) ) {
495 return '';
496 }
497
498 $selected_term_slug = isset( $_GET['category_ids'] ) ? sanitize_text_field( wp_unslash( $_GET['category_ids'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
499
500 $args = array(
501 'taxonomy' => $taxonomy,
502 'hide_empty' => false, // This will include terms with 0 posts.
503 );
504 $terms = get_terms( $args );
505
506 // Start the markup for our select element.
507 $output = '<select name="' . esc_attr( $taxonomy ) . '" class="wpstream_dropdown_select wpstream_dropdown_select_trigger_ajax_blog_list" id="wpstream_dropdown_' . esc_attr( $taxonomy ) . '">';
508
509 // Add a default option (optional).
510 $output .= '<option value="">';
511 if ( isset( $attributes[ 'label_' . $taxonomy ] ) ) {
512 $output .= $attributes[ 'label_' . $taxonomy ];
513 } else {
514 $output .= esc_html_e( 'Select term', 'hello-wpstream' );
515 }
516
517 $output .= '</option>';
518
519 // Check if we have any terms.
520 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
521 foreach ( $terms as $term ) {
522 // Check if this term is the selected term.
523 $selected = selected( $selected_term_slug, $term->term_id, false );
524
525 // Add an option for the term.
526 $output .= sprintf(
527 '<option value="%s"%s>%s</option>',
528 esc_attr( $term->term_id ),
529 $selected,
530 esc_html( $term->name )
531 );
532 }
533 }
534
535 // Close the select element.
536 $output .= '</select>';
537
538 // Return the generated dropdown.
539 return $output;
540 }
541 }
542 /*
543 * Filter BLog Post list with Bootstrea
544 *
545 */
546
547 if ( ! function_exists( 'wpstream_taxonomy_terms_dropdown_blog_post_list_with_bootstrap' ) ) {
548 /**
549 * Generates a dropdown select element for a taxonomy's terms.
550 *
551 * @param string $taxonomy The taxonomy to retrieve terms from.
552 * @param string $selected_term_slug Optional. The slug of the selected term. Default is ''.
553 * @param array $attributes Optional. Additional attributes for the select element. Default is an empty array.
554 * @return string The HTML markup for the dropdown select element.
555 */
556 function wpstream_taxonomy_terms_dropdown_blog_post_list_with_bootstrap( $taxonomy, $selected_term_slug = '', $attributes = '' ) {
557 if ( ! taxonomy_exists( $taxonomy ) ) {
558 return '';
559 }
560
561 $selected_term_slug = isset( $_GET['category_ids'] ) ? sanitize_text_field( wp_unslash( $_GET['category_ids'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
562
563 $args = array(
564 'taxonomy' => $taxonomy,
565 'hide_empty' => false, // This will include terms with 0 posts.
566 );
567 $terms = get_terms( $args );
568 $values = array();
569 $label = '';
570 $name = esc_attr( $taxonomy );
571 $class = 'wpstream_dropdown_select wpstream_dropdown_select_trigger_ajax_blog_list wpstream_blog_dropdown_' . esc_attr( $taxonomy );
572 $id = 'wpstream_dropdown_' . esc_attr( $taxonomy );
573
574 // Start the markup for our select element.
575 //$output = '<select name="' . esc_attr( $taxonomy ) . '" class="wpstream_dropdown_select wpstream_dropdown_select_trigger_ajax_blog_list" id="wpstream_dropdown_' . esc_attr( $taxonomy ) . '">';
576
577 // Add a default option (optional).
578
579 if ( isset( $attributes[ 'label_' . $taxonomy ] ) ) {
580 $label .= $attributes[ 'label_' . $taxonomy ];
581 } else {
582 $label .= esc_html_e( 'Select term', 'hello-wpstream' );
583 }
584
585 // Check if we have any terms.
586 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
587 foreach ( $terms as $term ) {
588 $values[$term->term_id]=$term->name;
589 }
590 }
591 $output = wpstream_create_custom_dropdown( $values,$name, $class, $id, $label,$selected_term_slug);
592 // Return the generated dropdown.
593 return $output;
594 }
595 }
596