| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace FilterEverything\Filter; |
| 5 |
|
| 6 |
if ( ! defined('WPINC') ) { |
| 7 |
wp_die(); |
| 8 |
} |
| 9 |
|
| 10 |
class Shortcodes |
| 11 |
{ |
| 12 |
function __construct(){ |
| 13 |
add_shortcode( 'fe_open_widget', '__return_false' ); |
| 14 |
add_shortcode( 'fe_open_button', '__return_false' ); |
| 15 |
add_shortcode( 'fe_chips', [$this, 'chipsShortcode'] ); |
| 16 |
add_shortcode( 'fe_sort', [$this, 'sortingShortcode'] ); |
| 17 |
add_shortcode( 'fe_widget', [$this, 'widgetFilterEverything'] ); |
| 18 |
} |
| 19 |
|
| 20 |
public function chipsShortcode( $atts ) |
| 21 |
{ |
| 22 |
ob_start(); |
| 23 |
|
| 24 |
$showReset = true; |
| 25 |
$setIds = []; |
| 26 |
$classes = []; |
| 27 |
|
| 28 |
if( isset( $atts['reset'] ) && $atts['reset'] === 'no' ){ |
| 29 |
$showReset = false; |
| 30 |
} |
| 31 |
|
| 32 |
if( isset( $atts['mobile'] ) && $atts['mobile'] ){ |
| 33 |
$classes[] = 'wpc-show-on-mobile'; |
| 34 |
} |
| 35 |
|
| 36 |
if( isset( $atts['id'] ) ){ |
| 37 |
$atts['id'] = preg_replace('/[^\d\,]?/', '', $atts['id']); |
| 38 |
$setIds = explode( ",", $atts['id'] ); |
| 39 |
} |
| 40 |
|
| 41 |
flrt_show_selected_terms($showReset, $setIds, $classes); |
| 42 |
|
| 43 |
$html = ob_get_clean(); |
| 44 |
|
| 45 |
return $html; |
| 46 |
} |
| 47 |
|
| 48 |
public function widgetFilterEverything( $atts ) |
| 49 |
{ |
| 50 |
ob_start(); |
| 51 |
|
| 52 |
$arguments = []; |
| 53 |
|
| 54 |
$arguments['title'] = isset( $atts['title'] ) ? $atts['title'] : ''; |
| 55 |
|
| 56 |
if( isset( $atts['id'] ) ){ |
| 57 |
$arguments['id'] = preg_replace('/[^\d]?/', '', $atts['id'] ); |
| 58 |
} |
| 59 |
|
| 60 |
if( isset( $atts['show_chips'] ) || isset( $atts['show_selected'] ) ){ |
| 61 |
$arguments['chips'] = 1; |
| 62 |
} |
| 63 |
|
| 64 |
if( isset( $atts['show_count'] ) ){ |
| 65 |
$arguments['show_count'] = 1; |
| 66 |
} |
| 67 |
|
| 68 |
the_widget('\FilterEverything\Filter\FiltersWidget', $arguments ); |
| 69 |
|
| 70 |
$html = ob_get_clean(); |
| 71 |
return $html; |
| 72 |
} |
| 73 |
|
| 74 |
public function sortingShortcode( $atts ) |
| 75 |
{ |
| 76 |
ob_start(); |
| 77 |
$debug_mode = flrt_is_debug_mode(); |
| 78 |
$all_widgets = get_option( 'widget_wpc_sorting_widget' ); |
| 79 |
$possible_ids = []; |
| 80 |
$arguments = []; |
| 81 |
$widget_id = 0; |
| 82 |
|
| 83 |
if( isset( $atts['id'] ) ){ |
| 84 |
$widget_id = preg_replace('/[^\d]?/', '', $atts['id'] ); |
| 85 |
}else{ |
| 86 |
|
| 87 |
if( is_array( $all_widgets ) && $debug_mode ){ |
| 88 |
foreach ( $all_widgets as $id => $widget_args ){ |
| 89 |
if( ! isset( $widget_args['title'] ) ){ |
| 90 |
continue; |
| 91 |
} |
| 92 |
|
| 93 |
$possible_ids[ $id ] = $widget_args['title'] ? $widget_args['title'] : esc_html__( 'No title','filter-everything' ); |
| 94 |
} |
| 95 |
|
| 96 |
if( ! empty( $possible_ids ) ){ |
| 97 |
$first_id = key( $possible_ids ); |
| 98 |
echo '<p class="wpc-debug-message">'; |
| 99 |
echo esc_html__('Please, specify desired Sorting widget by adding id parameter to the shortcode.', 'filter-everything'); |
| 100 |
echo '<br />'; |
| 101 |
|
| 102 |
foreach ( $possible_ids as $id => $title ){ |
| 103 |
echo sprintf( esc_html__('Use «%d» as id for widget with title «%s»','filter-everything' ), $id, $title ); |
| 104 |
echo '<br />'; |
| 105 |
} |
| 106 |
|
| 107 |
echo '</p>'; |
| 108 |
}else{ |
| 109 |
esc_html_e('There are no Sorting widget yet. Create it please first.','filter-everything' ); |
| 110 |
} |
| 111 |
|
| 112 |
flrt_debug_title(); |
| 113 |
|
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
if( isset( $all_widgets[$widget_id] ) ){ |
| 118 |
$arguments = $all_widgets[$widget_id]; |
| 119 |
the_widget('\FilterEverything\Filter\SortingWidget', $arguments ); |
| 120 |
}else{ |
| 121 |
esc_html_e('Wrong Sorting widget id. Please, specify correct.','filter-everything' ); |
| 122 |
} |
| 123 |
|
| 124 |
$html = ob_get_clean(); |
| 125 |
|
| 126 |
return $html; |
| 127 |
} |
| 128 |
|
| 129 |
} |