PluginProbe
Filter Everything — WordPress & WooCommerce Filters / 1.2.4
Filter Everything — WordPress & WooCommerce Filters v1.2.4
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 / Plugin.php

Plugin.php in Filter Everything — WordPress & WooCommerce Filters 1.2.4, at src/Plugin.php

703 lines 31.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FilterEverything\Filter;
4
5 if ( ! defined('WPINC') ) {
6 wp_die();
7 }
8
9 use FilterEverything\Filter\Shortcodes;
10 use FilterEverything\Filter\Pro\PluginPro;
11
12 class Plugin
13 {
14 private $wpManager;
15
16 public function __construct()
17 {
18 $this->wpManager = Container::instance()->getWpManager();
19 $this->wpManager->init();
20 $this->register_hooks();
21
22 new Shortcodes();
23
24 if( defined('FLRT_FILTERS_PRO') && FLRT_FILTERS_PRO ){
25 new PluginPro();
26 }
27
28 if( is_admin() ){
29 new Admin();
30 }
31 }
32
33 public function register_hooks(){
34 $postData = Container::instance()->getThePost();
35
36 if( ! is_admin() ){
37 add_filter( 'do_parse_request', array( $this->wpManager, 'customParseRequest' ), 10, 3 );
38 add_action( 'parse_request', array( $this->wpManager, 'parseRequest' ) );
39 add_action( 'pre_get_posts', array( $this->wpManager, 'addFilterQueryToWpQuery' ), 9999 );
40
41 add_filter( 'posts_where', [ $this->wpManager, 'fixPostsWhereForSearch' ], 10, 2 );
42 add_action( 'pre_get_posts', array( $this->wpManager, 'fixSearchPostType' ), 9999 );
43
44 add_action( 'template_redirect', [ $this, 'prepareEntities' ] );
45 }
46
47 add_action( 'body_class', array( $this, 'bodyClass' ) );
48
49 add_action( 'admin_print_styles', array( $this, 'includeAdminCss' ) );
50 add_action( 'admin_print_scripts', array( $this, 'includeAdminJs' ) );
51
52 // Do not include JS, if this page is admin or can't contain filters
53 if( ! is_admin() ){
54 add_action( 'wp_print_styles', array( $this, 'includeFrontCss' ) );
55 add_action( 'wp_print_scripts', array( $this, 'includeFrontJs' ) );
56 add_action( 'wp_print_styles', array( $this, 'inlineFrontCss' ) );
57 }
58
59 add_action( 'wp_footer', [$this, 'footerHtml'] );
60
61 if( ! defined('FLRT_FILTERS_PRO') ) {
62 add_action( 'wp_head', array($this, 'noIndexFilterPages'), 1 );
63 add_filter( 'wpc_filter_set_default_fields', [ $this, 'addAvailableInProFields' ], 10, 2 );
64 add_filter( 'wpc_pre_save_set_fields', [ $this, 'unsetAvailableInProFields' ] );
65 }
66
67 // Disable single search result redirect
68 add_filter( 'woocommerce_redirect_single_search_result', '__return_false' );
69
70 }
71
72 public function prepareEntities()
73 {
74 $wpManager = Container::instance()->getWpManager();
75 $em = Container::instance()->getEntityManager();
76 $sets = $wpManager->getQueryVar('wpc_page_related_set_ids');
77
78 if( $sets ){
79 foreach( $sets as $set ){
80 $em->prepareEntitiesToDisplay( array( $set ) );
81 }
82 }
83 }
84
85
86 public function addAvailableInProFields( $fields, $filterSet )
87 {
88 foreach ( $fields as $key => $attributes ){
89 // Always insert regular 'old' field
90 $new_fields[$key] = $attributes;
91
92 if( $key === 'post_name' ){
93
94 $new_fields['instead_post_name'] = array(
95 'type' => 'Text',
96 'label' => esc_html__('Location', 'filter-everything'),
97 'name' => $filterSet->generateFieldName('instead_post_name'),
98 'id' => $filterSet->generateFieldId('instead_post_name'),
99 'class' => 'wpc-field-instead-of-location',
100 'default' => '',
101 'readonly' => 'readonly',
102 'placeholder' => esc_html__('Available in PRO', 'filter-everything'),
103 'instructions' => esc_html__('Specify page(s) where to show this Filter Set', 'filter-everything'),
104 'settings' => true
105 );
106
107 $new_fields['instead_wp_filter_query'] = array(
108 'type' => 'Text',
109 'label' => esc_html__('Query', 'filter-everything'),
110 'name' => $filterSet->generateFieldName('instead_wp_filter_query'),
111 'id' => $filterSet->generateFieldId('instead_wp_filter_query'),
112 'class' => 'wpc-field-instead-wp-filter-query',
113 'default' => '',
114 'readonly' => 'readonly',
115 'placeholder' => esc_html__('Available in PRO', 'filter-everything'),
116 'instructions' => esc_html__('Select WP Query, that should be filtered', 'filter-everything'),
117 'tooltip' => esc_html__( 'The page selected in the Location field can contain multiple WP Queries associated with the desired Post type. They can be responsible for the work of widgets, posts and even nav menus. Please, try experimentally determining which WP Query is responsible for displaying the posts you want to filter.', 'filter-everything' ),
118 'settings' => true
119 );
120
121 }
122
123 if( $key === 'show_count' ){
124
125 $new_fields['instead_custom_posts_container'] = array(
126 'type' => 'Text',
127 'label' => esc_html__('CSS ID or Class of Posts Container', 'filter-everything'),
128 'name' => $filterSet->generateFieldName('instead_custom_posts_container'),
129 'id' => $filterSet->generateFieldId('instead_custom_posts_container'),
130 'class' => 'wpc-field-instead-custom-posts-container',
131 'default' => '',
132 'readonly' => 'readonly',
133 'placeholder' => esc_html__('Available in PRO', 'filter-everything'),
134 'instructions' => esc_html__('Specify individual CSS selector of Posts Container for AJAX', 'filter-everything'),
135 'settings' => true
136 );
137
138 }
139
140 }
141
142 return $new_fields;
143 }
144
145 public function unsetAvailableInProFields( $setFields )
146 {
147 unset( $setFields['instead_post_name'], $setFields['instead_custom_posts_container'] );
148
149 return $setFields;
150 }
151
152 public function noIndexFilterPages()
153 {
154 if( flrt_is_filter_request() ){
155 $robots['index'] = 'noindex';
156 $robots['follow'] = 'nofollow';
157 $content = implode(', ', $robots );
158 echo sprintf('<meta name="robots" content="%s">', $content)."\r\n";
159 }
160 }
161
162 public function inlineFrontCss()
163 {
164 if( ! $this->wpManager->getQueryVar('allowed_filter_page') ) {
165 return false;
166 }
167
168 $maxHeight = flrt_get_option('container_height');
169 $color = flrt_get_option( 'primary_color', flrt_default_theme_color() );
170 $move_to_top = flrt_get_option('try_move_to_top_sidebar');
171 $wpc_mobile_width = flrt_get_mobile_width();
172
173 // Experimental Options
174 $custom_css = flrt_get_experimental_option('custom_css');
175 $use_loader = flrt_get_experimental_option('use_loader');
176 $dark_overlay = flrt_get_experimental_option('dark_overlay');
177 $styled_inputs = flrt_get_experimental_option('styled_inputs');
178 $use_select2 = flrt_get_experimental_option('select2_dropdowns');
179 $contrastColor = false;
180
181 $css = '';
182
183 if( $maxHeight ){
184 $css .= '.wpc-filters-section:not(.wpc-filter-post_meta_num,.wpc-filter-layout-dropdown) .wpc-filter-content:not(.wpc-filter-has-hierarchy){
185 max-height: '.$maxHeight.'px;
186 overflow-y: auto;
187 }'."\r\n";
188 }
189
190 if( $color ){
191 $contrastColor = flrt_get_contrast_color($color);
192 $css .= '.ui-slider-horizontal .ui-slider-range{
193 background-color: '.$color.';
194 }
195 '."\r\n";
196
197 $css .= '.wpc-spinner:after {
198 border-top-color: '.$color.';
199 }'."\r\n";
200
201 $css .= '.theme-Avada .wpc-filter-product_visibility .star-rating:before,
202 .wpc-filter-product_visibility .star-rating span:before{
203 color: '.$color.';
204 }'."\r\n";
205
206 $css .= '.theme-twentyfourteen .widget-area input.wpc-label-input:checked+label span.wpc-filter-label-wrapper,
207 .widget-area input.wpc-label-input:checked+label span.wpc-filter-label-wrapper,
208 .wpc-filters-widget-main-wrapper input.wpc-label-input:checked+label span.wpc-filter-label-wrapper{
209 background-color: '.$color.';
210 }'."\r\n";
211
212 $css .= '.widget-area input.wpc-label-input:checked+label,
213 input.wpc-label-input:checked+label{
214 border-color: '.$color.';
215 }'."\r\n";
216
217 $css .= '#secondary .wpc-filters-labels li.wpc-term-item input:checked+label a,
218 #secondary .widget-area input.wpc-label-input:checked+label span.wpc-filter-label-wrapper,
219 .widget-area input.wpc-label-input:checked+label span.wpc-filter-label-wrapper,
220 .wpc-filters-widget-main-wrapper input.wpc-label-input:checked+label span.wpc-filter-label-wrapper,
221 .widget-area .wpc-filters-labels li.wpc-term-item input:checked+label a,
222 .wpc-filters-widget-main-wrapper .wpc-filters-labels li.wpc-term-item input:checked+label a,
223 body .wpc-filters-labels li.wpc-term-item input:checked+label a,
224 body#colibri .wpc-filters-labels li.wpc-term-item input:checked+label a,
225 body#colibri .widget-area input.wpc-label-input:checked+label span.wpc-filter-label-wrapper{
226 color: '.$contrastColor.';
227 }'."\r\n";
228
229 $css .= '#secondary .wpc-filter-chips-list li.wpc-filter-chip:not(.wpc-chip-reset-all) a,
230 .widget-area .widget .wpc-filter-chips-list li.wpc-filter-chip:not(.wpc-chip-reset-all) a,
231 body .wpc-filter-chips-list li.wpc-filter-chip:not(.wpc-chip-reset-all) a,
232 body#colibri .wpc-filter-chips-list li.wpc-filter-chip:not(.wpc-chip-reset-all) a,
233 .wpc-filter-chips-list li.wpc-filter-chip:not(.wpc-chip-reset-all) a{
234 background-color: '.$color.';
235 color: '.$contrastColor.';
236 border-color: '.$color.';
237 }'."\r\n";
238
239 $css .= '.widget-area .widget .wpc-filter-chips-list li.wpc-filter-chip:not(.wpc-chip-reset-all) a:hover,
240 .wpc-filter-chips-list li.wpc-filter-chip:not(.wpc-chip-reset-all) a:hover{
241 opacity: 0.9;
242 }'."\r\n";
243
244 $css .= '.widget-area .widget .wpc-filter-chips-list li.wpc-filter-chip:not(.wpc-chip-reset-all) a:active,
245 .wpc-filter-chips-list li.wpc-filter-chip:not(.wpc-chip-reset-all) a:active{
246 opacity: 0.75;
247 }'."\r\n";
248
249 $css .= '.wpc-filter-chips-list a:hover .wpc-chip-remove-icon,
250 .widget-area .widget .wpc-filter-chips-list a:hover .wpc-chip-remove-icon{
251 color: '.$contrastColor.';
252 }'."\r\n";
253
254 $css .= '.star-rating span,
255 .star-rating span:before{
256 color: '.$color.';
257 }'."\r\n";
258
259 $css .= '@media screen and (min-width: '.$wpc_mobile_width.'px) {'."\r\n";
260 $css .= '.theme-twentyfourteen .widget-area input.wpc-label-input+label:hover span.wpc-filter-label-wrapper,
261 .widget-area input.wpc-label-input+label:hover span.wpc-filter-label-wrapper,
262 .wpc-filters-widget-main-wrapper input.wpc-label-input+label:hover span.wpc-filter-label-wrapper{
263 color: '.$contrastColor.';
264 background-color: '.$color.';
265 }'."\r\n";
266 $css .= '#secondary .wpc-filters-labels li.wpc-term-item input+label:hover a,
267 body .wpc-filters-labels li.wpc-term-item input+label:hover a,
268 body#colibri .wpc-filters-labels li.wpc-term-item input+label:hover a,
269 .widget-area .wpc-filters-labels li.wpc-term-item input+label:hover a,
270 .wpc-filters-widget-main-wrapper .wpc-filters-labels li.wpc-term-item input+label:hover a{
271 color: '.$contrastColor.';
272 }'."\r\n";
273 $css .= '.widget-area input.wpc-label-input+label:hover,
274 .wpc-filters-widget-main-wrapper input.wpc-label-input+label:hover{
275 border-color: '.$color.';
276 }'."\r\n";
277 $css .= '}'."\r\n";
278 }
279 if( $styled_inputs ){
280 $styled_color = $color ? $color : '#0570e2';
281 $contrastColor = $contrastColor ? $contrastColor : flrt_get_contrast_color($styled_color);
282
283 $css .= '.wpc-filters-widget-main-wrapper input[type=checkbox],
284 .wpc-filters-widget-main-wrapper input[type=radio]{
285 -webkit-appearance: none;
286 -moz-appearance: none;
287 position: relative;
288 width: 20px;
289 height: 20px;
290 border: 2px solid #bdbdbd;
291 border: 2px solid #ccd0dc;
292 background: #ffffff;
293 border-radius: 5px;
294 min-width: 20px;
295 }
296 .wpc-filters-widget-main-wrapper input[type=checkbox]:after {
297 content: "";
298 opacity: 0;
299 display: block;
300 left: 5px;
301 top: 2px;
302 position: absolute;
303 width: 4px;
304 height: 8px;
305 border: 2px solid '.$styled_color.';
306 border-top: 0;
307 border-left: 0;
308 transform: rotate(45deg);
309 box-sizing: content-box;
310 }
311 .wpc-filters-widget-main-wrapper input[type=radio]:after {
312 content: "";
313 opacity: 0;
314 display: block;
315 left: 4px;
316 top: 4px;
317 position: absolute;
318 width: 8px;
319 height: 8px;
320 border-radius: 50%;
321 background: '.$styled_color.';
322 box-sizing: content-box;
323 }
324 .wpc-filters-widget-main-wrapper input[type=radio]:checked,
325 .wpc-filters-widget-main-wrapper input[type=checkbox]:checked {
326 border-color: '.$styled_color.';
327 }
328 .wpc-filters-widget-main-wrapper .wpc-term-count-0:not(.wpc-has-not-empty-children) input[type=checkbox]:after,
329 .wpc-filters-widget-main-wrapper .wpc-term-count-0:not(.wpc-has-not-empty-children) input[type=checkbox],
330 .wpc-filters-widget-main-wrapper .wpc-term-count-0:not(.wpc-has-not-empty-children) input[type=radio]{
331 border-color: #d8d8d8;
332 }
333 .wpc-filters-widget-main-wrapper .wpc-term-count-0:not(.wpc-has-not-empty-children) input[type=radio]:after{
334 background-color: #d8d8d8;
335 }
336 .wpc-filters-widget-main-wrapper input[type=radio]:checked:after,
337 .wpc-filters-widget-main-wrapper input[type=checkbox]:checked:after {
338 opacity: 1;
339 }
340 .wpc-filters-widget-main-wrapper input[type=radio] {
341 border-radius: 50%;
342 }
343
344 @media screen and (min-width: 768px) {
345 .wpc-filters-widget-main-wrapper input[type=radio]:hover,
346 .wpc-filters-widget-main-wrapper input[type=checkbox]:hover{
347 border-color: '.$styled_color.';
348 }
349 .wpc-filters-widget-main-wrapper .wpc-term-count-0:not(.wpc-has-not-empty-children) input[type=radio]:hover,
350 .wpc-filters-widget-main-wrapper .wpc-term-count-0:not(.wpc-has-not-empty-children) input[type=checkbox]:hover{
351 border-color: #c3c3c3;
352 }
353 }';
354 }
355
356 if( $use_select2 ){
357 $styled_color = $color ? $color : '#0570e2';
358 $contrastColor = $contrastColor ? $contrastColor : flrt_get_contrast_color($styled_color);
359
360 $css .= '.wpc-filter-content select{
361 padding: 6px 12px 6px 14px;
362 border-color: #ccd0dc;
363 border-radius: 3px;
364 color: inherit;
365 -webkit-appearance: none;
366 }
367 .select2-container--default .wpc-filter-everything-dropdown .select2-results__option--highlighted[aria-selected],
368 .select2-container--default .wpc-filter-everything-dropdown .select2-results__option--highlighted[data-selected]{
369 background-color: '.$styled_color.';
370 color: '.$contrastColor.';
371 }
372 ';
373 }
374
375 if( $move_to_top ){
376 $css .= '@media screen and (max-width: '.$wpc_mobile_width.'px) {'."\r\n";
377
378 $css .= 'body #main,
379 body #content .col-full,
380 .woocommerce-page .content-has-sidebar,
381 .woocommerce-page .has-one-sidebar,
382 .woocommerce-page #main-sidebar-container,
383 .woocommerce-page .theme-page-wrapper,
384 .woocommerce-page #content-area,
385 .theme-jevelin.woocommerce-page .woocomerce-styling,
386 .woocommerce-page .content_wrapper,
387 .woocommerce-page #col-mask,
388 body #main-content .content-area {
389 -js-display: flex;
390 display: -webkit-box;
391 display: -webkit-flex;
392 display: -moz-box;
393 display: -ms-flexbox;
394 display: flex;
395 -webkit-box-orient: vertical;
396 -moz-box-orient: vertical;
397 -webkit-flex-direction: column;
398 -ms-flex-direction: column;
399 flex-direction: column;
400 }
401 body #primary,
402 .woocommerce-page .has-one-sidebar > section,
403 .woocommerce-page .theme-content,
404 .woocommerce-page #left-area,
405 .woocommerce-page #content,
406 .woocommerce-page .sections_group,
407 .woocommerce-page .content-box,
408 body #main-sidebar-container #main {
409 -webkit-box-ordinal-group: 2;
410 -moz-box-ordinal-group: 2;
411 -ms-flex-order: 2;
412 -webkit-order: 2;
413 order: 2;
414 }
415 body #secondary,
416 .woocommerce-page .has-one-sidebar > aside,
417 body aside#mk-sidebar,
418 .woocommerce-page #sidebar,
419 .woocommerce-page .sidebar,
420 body #main-sidebar-container #sidebar {
421 -webkit-box-ordinal-group: 1;
422 -moz-box-ordinal-group: 1;
423 -ms-flex-order: 1;
424 -webkit-order: 1;
425 order: 1;
426 }
427
428 /*second method first method solve issue theme specific*/
429 .woocommerce-page:not(.single,.page) .btWithSidebar.btSidebarLeft .btContentHolder,
430 body .theme-generatepress.woocommerce #content {
431 display: table;
432 }
433 body .btContent,
434 body .theme-generatepress.woocommerce #primary {
435 display: table-footer-group;
436 }
437 body .btSidebar,
438 body .theme-generatepress.woocommerce #left-sidebar {
439 display: table-header-group;
440 }'."\r\n";
441 $css .= '}'."\r\n";
442 }
443
444 if( $use_loader ){
445 $css .= '@media screen and (min-width: '.$wpc_mobile_width.'px) {'."\r\n";
446 $css .= 'html.is-active .wpc-spinner{
447 display: block;
448 }';
449 $css .= '}'."\r\n";
450 }
451
452 if( $dark_overlay ){
453 $css .= '@media screen and (min-width: '.$wpc_mobile_width.'px) {'."\r\n";
454 $css .= 'html.is-active .wpc-filters-overlay{
455 opacity: .15;
456 background: #000000;
457 }';
458 $css .= '}'."\r\n";
459 }
460
461 if( $custom_css ){
462 $css .= $custom_css."\r\n";
463 }
464
465
466 $wp_upload_dir = wp_upload_dir();
467 $upload_dir_baseurl = $wp_upload_dir['baseurl'];
468 $upload_dir_basepath = $wp_upload_dir['basedir'];
469
470 $cache_dir = $upload_dir_basepath . '/cache/filter-everything/';
471
472 if ( ! file_exists( $cache_dir ) ) {
473 mkdir($cache_dir, 0777, true);
474 chmod($cache_dir, 0777);
475 }
476
477 $filename = md5( $css ) . '.css';
478
479 $fileurl = $upload_dir_baseurl .'/cache/filter-everything/' . $filename;
480 $filepath = $cache_dir . $filename;
481
482 if ( $css !== '' ) {
483 if ( ! file_exists( $filepath ) ) {
484 file_put_contents( $filepath, $css );
485 }
486
487 if( file_exists( $filepath ) ){
488 wp_enqueue_style('wpc-filter-everything-custom', $fileurl );
489 }
490 }
491
492 }
493
494 public function bodyClass( $classes )
495 {
496 if( flrt_get_option('show_open_close_button') === 'on' ){
497 $classes[] = 'wpc_show_open_close_button';
498 }
499
500 return $classes;
501 }
502
503 public static function activate()
504 {
505 if ( ! get_option('wpc_filter_settings') ) {
506 $defaultOptions = array(
507 'primary_color' => '#0570e2',
508 'container_height' => '350',
509 'show_open_close_button' => '',
510 'show_terms_in_content' => 'on',
511 'widget_debug_messages' => 'on'
512 );
513
514 // PRO default options
515 if( defined('FLRT_FILTERS_PRO') && FLRT_FILTERS_PRO ){
516 $defaultOptions['show_bottom_widget'] = 'on';
517 }
518
519 add_option('wpc_filter_settings', $defaultOptions );
520 }
521
522 if( ! get_option( 'wpc_filter_experimental' ) ){
523
524 $defaultExperimentalOptions = array(
525 'use_loader' => 'on',
526 'use_wait_cursor' => 'on',
527 'dark_overlay' => 'on',
528 'auto_scroll' => '',
529 'styled_inputs' => '',
530 'select2_dropdowns' => ''
531 );
532
533 add_option('wpc_filter_experimental', $defaultExperimentalOptions );
534 }
535 }
536
537 /**
538 * Clears all plugin data: options and posts
539 */
540 public static function uninstall()
541 {
542 delete_option('wpc_filter_settings' );
543 delete_option('wpc_indexing_deep_settings' );
544 delete_option('wpc_filter_permalinks' );
545 delete_option('wpc_seo_rules_settings' );
546 delete_option('wpc_filter_experimental' );
547
548 $postTypes = array(
549 FLRT_FILTERS_SET_POST_TYPE,
550 FLRT_FILTERS_POST_TYPE
551 );
552
553 if( defined( 'FLRT_SEO_RULES_POST_TYPE' ) ){
554 $postTypes[] = FLRT_SEO_RULES_POST_TYPE;
555 }
556
557 $filterPosts = new \WP_Query(
558 array(
559 'posts_per_page' => -1,
560 'post_status' => array('any'),
561 'post_type' => $postTypes,
562 'fields' => 'ids'
563 )
564 );
565
566 $filterPostsIds = $filterPosts->get_posts();
567
568 if( ! empty( $filterPostsIds ) ){
569 foreach ($filterPostsIds as $post_id) {
570 wp_delete_post( $post_id, true );
571 }
572 }
573 }
574
575 public static function switchTheme() {
576 flrt_remove_option('posts_container');
577 flrt_remove_option('primary_color');
578 }
579
580 public function includeAdminCss()
581 {
582 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
583 $ver = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? rand(0, 1000) : FLRT_PLUGIN_VER;
584 wp_enqueue_style( 'wpc-filter-everything-admin', FLRT_PLUGIN_URL . 'assets/css/filter-everything-admin'.$suffix.'.css', ['wp-color-picker'], $ver );
585 }
586
587 public function includeAdminJs()
588 {
589 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
590 $ver = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? rand(0, 1000) : FLRT_PLUGIN_VER;
591
592 wp_register_script( 'jquery-tiptip', FLRT_PLUGIN_URL . 'assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js', array( 'jquery' ), $ver, true );
593 wp_enqueue_script('jquery-tiptip');
594
595 wp_enqueue_script('wpc-filters-admin', FLRT_PLUGIN_URL . 'assets/js/wpc-filters-common-admin' . $suffix . '.js', array('jquery', 'jquery-ui-sortable', 'wp-color-picker'), $ver );
596
597 $l10n = array(
598 'prefixesOrderAvailableInPro' => __( 'Editing the order of URL prefixes is available in PRO version', 'filter-everything' ),
599 );
600 wp_localize_script( 'wpc-filters-admin', 'wpcFiltersAdminCommon', $l10n );
601 }
602
603 public function includeFrontCss()
604 {
605 if( ! $this->wpManager->getQueryVar('allowed_filter_page') ) {
606 if( flrt_get_option( 'widget_debug_messages' ) !== 'on' ){
607 return false;
608 }
609 }
610
611 $suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
612 $ver = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? rand(0, 1000) : FLRT_PLUGIN_VER;
613 wp_enqueue_style('wpc-filter-everything', FLRT_PLUGIN_URL . 'assets/css/filter-everything' . $suffix . '.css', [], $ver);
614
615 }
616
617 public function footerHtml()
618 {
619 if( $this->wpManager->getQueryVar( 'allowed_filter_page' ) ){
620 echo '<div class="wpc-filters-overlay"></div>'."\r\n";
621 }
622 }
623
624 public function includeFrontJs()
625 {
626 if( ! $this->wpManager->getQueryVar('allowed_filter_page') ) {
627 if( flrt_get_option( 'widget_debug_messages' ) !== 'on' ){
628 return false;
629 }
630 }
631
632 $showBottomWidget = 'no';
633 $ajaxEnabled = false;
634 $autoScroll = false;
635 $waitCursor = false;
636 $wpcUseSelect2 = false;
637 $autoScrollOffset = apply_filters( 'wpc_auto_scroll_offset', 150 );
638 $wpc_mobile_width = flrt_get_mobile_width();
639 $per_page = [];
640 $sets = $this->wpManager->getQueryVar('wpc_page_related_set_ids');
641
642 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
643 $ver = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? rand(0, 1000) : FLRT_PLUGIN_VER;
644
645 if( flrt_get_option('show_bottom_widget') === 'on' ) {
646 $showBottomWidget = 'yes';
647 }
648
649 if( flrt_get_option('enable_ajax') === 'on' ){
650 $ajaxEnabled = true;
651 }
652
653 if( flrt_get_experimental_option('auto_scroll') === 'on' ){
654 $autoScroll = true;
655 }
656
657 if( flrt_get_experimental_option( 'use_wait_cursor' ) === 'on' ){
658 $waitCursor = true;
659 }
660
661 foreach( $sets as $set ){
662 if( $set['filtered_post_type'] === 'product' && function_exists('wc_get_default_products_per_row') ){
663 $numberposts = apply_filters( 'loop_shop_per_page', wc_get_default_products_per_row() * wc_get_default_product_rows_per_page() );
664 }else{
665 $numberposts = get_option( 'posts_per_page' );
666 }
667
668 $per_page[ $set['ID'] ] = intval($numberposts);
669 }
670
671 $wpcPostContainers = apply_filters( 'wpc_posts_containers', flrt_get_option( 'posts_container', flrt_default_posts_container() ) );
672
673 wp_register_script( 'wc-jquery-ui-touchpunch', FLRT_PLUGIN_URL . 'assets/js/jquery-ui-touch-punch/jquery-ui-touch-punch'.$suffix.'.js', [], $ver, true );
674 wp_enqueue_script('wpc-filter-everything', FLRT_PLUGIN_URL . 'assets/js/filter-everything'.$suffix.'.js', array('jquery', 'jquery-ui-slider', 'wc-jquery-ui-touchpunch'), $ver, true );
675
676 if( flrt_get_experimental_option('select2_dropdowns') === 'on' ){
677 $select2ver = '4.1.0';
678 $wpcUseSelect2 = 'yes';
679 wp_enqueue_script( 'select2', FLRT_PLUGIN_URL . "assets/js/select2/select2".$suffix.".js", array('jquery'), $select2ver );
680 wp_enqueue_style('select2', FLRT_PLUGIN_URL . "assets/css/select2/select2".$suffix.".css", '', $select2ver );
681
682 }
683
684 wp_localize_script( 'wpc-filter-everything', 'wpcFilterFront',
685 array(
686 'ajaxUrl' => admin_url('admin-ajax.php'),
687 'wpcAjaxEnabled' => $ajaxEnabled,
688 'wpcStatusCookieName' => FLRT_STATUS_COOKIE_NAME,
689 'wpcHierarchyListCookieName' => FLRT_HIERARCHY_LIST_COOKIE_NAME,
690 'wpcWidgetStatusCookieName' => FLRT_OPEN_CLOSE_BUTTON_COOKIE_NAME,
691 'wpcMobileWidth' => $wpc_mobile_width,
692 'showBottomWidget' => $showBottomWidget,
693 '_nonce' => wp_create_nonce('wpcNonceFront'),
694 'wpcPostContainers' => $wpcPostContainers,
695 'wpcAutoScroll' => $autoScroll,
696 'wpcAutoScrollOffset' => $autoScrollOffset,
697 'wpcWaitCursor' => $waitCursor,
698 'wpcPostsPerPage' => $per_page,
699 'wpcUseSelect2' => $wpcUseSelect2
700 )
701 );
702 }
703 }