PluginProbe
Filter Everything — WordPress & WooCommerce Filters / trunk
Filter Everything — WordPress & WooCommerce Filters vtrunk
1.9.6 1.9.5 1.9.4 1.9.3 1.9.2.2 1.9.2.1 trunk 1.2.1 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.1 1.4.4 1.4.5 1.4.8 1.4.9 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 1.6.3 All 51 releases
filter-everything / src / Admin / Shortcodes.php

Shortcodes.php in Filter Everything — WordPress & WooCommerce Filters trunk, at src/Admin/Shortcodes.php

174 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace FilterEverything\Filter;
5
6 if ( ! defined('ABSPATH') ) {
7 exit;
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 add_shortcode( 'fe_posts_found', [ $this, 'postsFound' ] );
19 }
20
21 public function chipsShortcode( $atts )
22 {
23 ob_start();
24
25 $showReset = true;
26 $setIds = [];
27 $classes = [];
28
29 if( isset( $atts['reset'] ) && $atts['reset'] === 'no' ){
30 $showReset = false;
31 }
32
33 if( isset( $atts['mobile'] ) && $atts['mobile'] ){
34 $classes[] = 'wpc-show-on-mobile';
35 }
36
37 if( isset( $atts['id'] ) ){
38 $atts['id'] = preg_replace('/[^\d\,]?/', '', $atts['id']);
39 $setIds = explode( ",", $atts['id'] );
40 }
41
42 flrt_show_selected_terms( $showReset, $setIds, $classes );
43
44 $html = ob_get_clean();
45
46 return $html;
47 }
48
49 public function widgetFilterEverything( $atts )
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 if( isset( $atts['horizontal'] ) ){
69 $arguments['horizontal'] = 1;
70 }
71
72 if( isset( $atts['columns'] ) ){
73 $count = intval( $atts['columns'] );
74
75 if ( $count > 5 ) {
76 $arguments['cols_count'] = 5;
77 } elseif ( $count < 2 ) {
78 $arguments['cols_count'] = 3;
79 } else {
80 $arguments['cols_count'] = $count;
81 }
82 }
83
84 the_widget('\FilterEverything\Filter\FiltersWidget', $arguments );
85
86 $html = ob_get_clean();
87 return $html;
88 }
89
90 public function sortingShortcode( $atts )
91 {
92 ob_start();
93 $debug_mode = flrt_is_debug_mode();
94 $all_widgets = get_option( 'widget_wpc_sorting_widget' );
95 $possible_ids = [];
96 $arguments = [];
97 $widget_id = 0;
98
99 if( isset( $atts['id'] ) ){
100 $widget_id = preg_replace('/[^\d]?/', '', $atts['id'] );
101 }else{
102
103 if( is_array( $all_widgets ) && $debug_mode ){
104 foreach ( $all_widgets as $id => $widget_args ){
105 if( ! isset( $widget_args['title'] ) ){
106 continue;
107 }
108
109 $possible_ids[ $id ] = $widget_args['title'] ? $widget_args['title'] : esc_html__( 'No title','filter-everything' );
110 }
111
112 if( ! empty( $possible_ids ) ){
113 $first_id = key( $possible_ids );
114 echo '<p class="wpc-debug-message">';
115 echo esc_html__('Please, specify desired Sorting widget by adding the id parameter to the shortcode.', 'filter-everything');
116 echo '<br />';
117
118 foreach ( $possible_ids as $id => $title ){
119 echo sprintf( esc_html__('Use «%d» as the id for the widget with the title «%s»','filter-everything' ), $id, $title );
120 echo '<br />';
121 }
122
123 echo '</p>';
124 }else{
125 esc_html_e('There are no Sorting widgets on this site yet. Please, create it first.','filter-everything' );
126 }
127
128 flrt_debug_title();
129
130 }
131 }
132
133 if( isset( $all_widgets[$widget_id] ) ){
134 $arguments = $all_widgets[$widget_id];
135 the_widget('\FilterEverything\Filter\SortingWidget', $arguments );
136 }else{
137 esc_html_e('Wrong Sorting widget id. Please, specify the correct.','filter-everything' );
138 }
139
140 $html = ob_get_clean();
141
142 return $html;
143 }
144
145 public function postsFound( $atts )
146 {
147 $set_id = 0;
148 $all = false;
149 $wpManager = Container::instance()->getWpManager();
150
151 if ( isset( $atts['all'] ) && $atts['all'] ){
152 if ( $wpManager->getQueryVar('wpc_is_filter_request') ){
153 $all = true;
154 }
155 }
156
157 if ( isset( $atts['sid'] ) ){
158 $set_id = preg_replace('/[^\d]?/', '', $atts['sid'] );
159 } else {
160 $sets = $wpManager->getQueryVar( 'wpc_page_related_set_ids', [] );
161 if ( isset( $sets[0]['ID'] ) && $sets[0]['ID'] ) {
162 $set_id = $sets[0]['ID'];
163 }
164 }
165
166 ob_start();
167
168 flrt_posts_found( $set_id, $all );
169
170 $html = ob_get_clean();
171 return $html;
172 }
173
174 }