PluginProbe
Filter Everything — WordPress & WooCommerce Filters / 1.9.2.1
Filter Everything — WordPress & WooCommerce Filters v1.9.2.1
1.9.7 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 All 52 releases
filter-everything / src / wpc-default-hooks.php

wpc-default-hooks.php in Filter Everything — WordPress & WooCommerce Filters 1.9.2.1, at src/wpc-default-hooks.php

863 lines 31.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined('ABSPATH') ) {
4 exit;
5 }
6
7 use FilterEverything\Filter\Container;
8 use \FilterEverything\Filter\PostDateEntity;
9 use \FilterEverything\Filter\ImportSettings;
10
11 // Make post type name lowercase in posts found message
12 add_filter( 'wpc_label_singular_posts_found_msg', 'mb_strtolower' );
13 add_filter( 'wpc_label_plural_posts_found_msg', 'mb_strtolower' );
14
15 add_action( 'init', 'flrt_initiate_overridden_functions' );
16 function flrt_initiate_overridden_functions()
17 {
18 // All hooks with function wrapper with function_exists()
19 add_filter('wpc_filter_post_meta_num_term_name', 'flrt_ucfirst_term_slug_name');
20 add_filter('wpc_filter_post_meta_term_name', 'flrt_ucfirst_term_slug_name');
21 add_filter('wpc_filter_tax_numeric_term_name', 'flrt_ucfirst_term_slug_name');
22 add_filter('wpc_filter_post_meta_exists_term_name', 'flrt_custom_field_exists_name');
23 add_filter('wpc_filter_post_meta_term_name', 'flrt_stock_status_term_name', 10, 2);
24 add_filter('wpc_filter_post_meta_exists_term_name', 'flrt_on_sale_term_name', 15, 2);
25 add_filter('wpc_filter_taxonomy_term_name', 'flrt_modify_taxonomy_term_name', 10, 2);
26 add_filter('wpc_filter_term_query_args', 'flrt_exclude_uncategorized_category', 10, 3);
27 add_filter('wpc_filter_get_taxonomy_terms', 'flrt_exclude_product_visibility_terms', 10, 2);
28 add_filter('wpc_filter_author_query_post_types', 'flrt_remove_author_query_post_types');
29 add_filter('wpc_filter_post_types', 'flrt_exclude_post_types');
30 add_action('wpc_after_filter_input', 'flrt_after_filter_input');
31 add_filter('wpc_filters_checkbox_term_html', 'wpc_term_brand_logo', 5, 4);
32 add_filter('wpc_filters_radio_term_html', 'wpc_term_brand_logo', 5, 4);
33 add_filter('wpc_filters_label_term_html', 'wpc_term_brand_logo', 5, 4);
34 add_filter('wpc_taxonomy_location_terms', 'flrt_remove_default_category_location', 10, 2);
35 add_filter( 'wpc_set_num_shift', 'flrt_round_numeric_values', 10, 3 );
36
37 if (!function_exists('flrt_ucfirst_term_slug_name')) {
38 function flrt_ucfirst_term_slug_name($term_name)
39 {
40 $term_name = flrt_ucfirst($term_name);
41 return $term_name;
42 }
43 }
44
45
46 if (!function_exists('flrt_custom_field_exists_name')) {
47 function flrt_custom_field_exists_name($term_name)
48 {
49 if ($term_name === 'yes') {
50 return esc_html__('Yes', 'filter-everything');
51 } else if ($term_name === 'no') {
52 return esc_html__('No', 'filter-everything');
53 }
54 return $term_name;
55 }
56 }
57
58 if (!function_exists('flrt_stock_status_term_name')) {
59 function flrt_stock_status_term_name($term_name, $e_name)
60 {
61 if ($e_name === '_stock_status') {
62 $term_name = strtolower($term_name);
63 if ($term_name === "instock") {
64 $term_name = esc_html__('In stock', 'filter-everything');
65 }
66
67 if ($term_name === "onbackorder") {
68 $term_name = esc_html__('On backorder', 'filter-everything');
69 }
70
71 if ($term_name === "outofstock") {
72 $term_name = esc_html__('Out of stock', 'filter-everything');
73 }
74 }
75
76 return $term_name;
77 }
78 }
79
80 if (!function_exists('flrt_on_sale_term_name')) {
81 function flrt_on_sale_term_name($term_name, $entity)
82 {
83 if ($entity === '_sale_price') {
84 $check_name = mb_strtolower($term_name);
85
86 if (in_array($check_name, ['yes', 'ja', 'ano', '', 'так'])) {
87 $term_name = esc_html__('On Sale', 'filter-everything');
88 }
89 if (in_array($check_name, ['no', 'nein', 'ne', 'ні'])) {
90 $term_name = esc_html__('Regular price', 'filter-everything');
91 }
92 }
93 return $term_name;
94 }
95 }
96
97
98 if (!function_exists('flrt_modify_taxonomy_term_name')) {
99 function flrt_modify_taxonomy_term_name($term_name, $e_name)
100 {
101 if (in_array($e_name, array('product_type', 'product_visibility'))) {
102 $term_name = flrt_ucfirst($term_name);
103 }
104 return $term_name;
105 }
106 }
107
108
109 if (!function_exists('flrt_exclude_uncategorized_category')) {
110 function flrt_exclude_uncategorized_category($args, $entity, $e_name)
111 {
112 if ($e_name === 'category') {
113 $args['exclude'] = array(1); // Uncategorized category
114 }
115
116 return $args;
117 }
118 }
119
120
121 if (!function_exists('flrt_exclude_product_visibility_terms')) {
122 function flrt_exclude_product_visibility_terms($terms, $e_name)
123 {
124 if ($e_name === 'product_visibility') {
125 if (is_array($terms)) {
126 foreach ($terms as $index => $term) {
127
128 if (in_array($term->slug, array('exclude-from-search', 'exclude-from-catalog'))) {
129 unset($terms[$index]);
130 }
131 }
132 }
133 }
134
135 if ($e_name === 'product_cat') {
136 if (is_array($terms)) {
137 foreach ($terms as $index => $term) {
138 if (in_array($term->slug, array('uncategorized'))) {
139 unset($terms[$index]);
140 }
141 }
142 }
143 }
144
145 return $terms;
146 }
147 }
148
149 if (!function_exists('flrt_remove_author_query_post_types')) {
150 function flrt_remove_author_query_post_types($post_types)
151 {
152 if (isset($post_types['attachment'])) {
153 unset($post_types['attachment']);
154 }
155 return $post_types;
156 }
157 }
158
159 if (!function_exists('flrt_exclude_post_types')) {
160 function flrt_exclude_post_types($post_types)
161 {
162
163 $post_types = array(
164 FLRT_FILTERS_POST_TYPE,
165 FLRT_FILTERS_SET_POST_TYPE,
166 'attachment',
167 'elementor_library',
168 'e-landing-page',
169 'jet-smart-filters',
170 'ct_template'
171 );
172
173 return $post_types;
174 }
175 }
176
177
178 if (!function_exists('flrt_after_filter_input')) {
179 function flrt_after_filter_input($attributes)
180 {
181 if (isset($attributes['class']) && $attributes['class'] === 'wpc-field-slug' && $attributes['value'] === '') {
182 echo '<p class="description">' . esc_html__('a-z, 0-9, "_" and "-" symbols supported only', 'filter-everything') . '</p>';
183 }
184
185 }
186 }
187
188 if (!function_exists('wpc_term_brand_logo')) {
189 function wpc_term_brand_logo($html, $link_attributes, $term, $filter)
190 {
191 if (!in_array($filter['e_name'], flrt_brand_filter_entities())) {
192 return $html;
193 }
194 if (!isset($term->slug)) {
195 return $html;
196 }
197 $src = flrt_get_term_brand_image($term->term_id, $filter);
198
199 $link_attributes .= ' title="' . $term->name . '"';
200
201 if ($src) {
202 $img = '<span class="wpc-term-image-wrapper"><img src="' . $src . '" alt="' . $term->name . '" /></span>';
203 $html = '<a ' . $link_attributes . '>' . $img . '<span class="wpc-term-name">' . $term->name . '</span></a>';
204 }
205
206 return $html;
207 }
208 }
209
210 if( !function_exists( 'flrt_remove_default_category_location' ) ) {
211 function flrt_remove_default_category_location( $terms, $taxonomy ){
212 $default_category = 0;
213
214 if ( $taxonomy === 'product_cat' ) {
215 $default_category = get_option( 'default_product_cat' );
216 } elseif( $taxonomy === 'category' ) {
217 $default_category = get_option('default_category');
218 }
219
220 // Remove default category from the list
221 if ( $default_category > 0 ) {
222 unset( $terms[ $default_category ] );
223 }
224
225 return $terms;
226 }
227 }
228
229 /**
230 * Fix for the LiveCanvas page builder
231 */
232 if( defined( 'LC_MU_PLUGIN_NAME' ) && LC_MU_PLUGIN_NAME === 'livecanvas-must-use-plugin.php' ) {
233 add_filter('wpc_pre_save_set_fields', 'flrt_safe_save_set_fields');
234 function flrt_safe_save_set_fields($setFields)
235 {
236
237 if (isset($setFields['wp_filter_query_vars'])) {
238 $query_vars = $setFields['wp_filter_query_vars'];
239 $new_query_vars = [];
240 $search_values = [
241 ''
242 ];
243 $replace_values = [
244 '&hellip;'
245 ];
246
247 foreach ($query_vars as $hash => $vars_serialized_str) {
248 $new_query_vars[$hash] = str_replace($search_values, $replace_values, $vars_serialized_str);
249 }
250
251 $setFields['wp_filter_query_vars'] = $new_query_vars;
252 }
253
254 return $setFields;
255 }
256 }
257
258 function flrt_round_numeric_values( $value, $entity_name, $limit )
259 {
260 if( $limit === 'min' ) {
261 $value = floor( $value );
262 } elseif ( $limit === 'max' ){
263 $value = ceil( $value );
264 }
265
266 return $value;
267 }
268
269 }
270 function flrt_chips( $showReset = false, $setIds = [] ) {
271 $templateManager = \FilterEverything\Filter\Container::instance()->getTemplateManager();
272 $wpManager = \FilterEverything\Filter\Container::instance()->getWpManager();
273
274 if( empty( $setIds ) || ! $setIds || ! is_array( $setIds ) ){
275 $relatedSetIds = $wpManager->getQueryVar('wpc_page_related_set_ids');
276
277 if( is_array( $relatedSetIds ) ) {
278 foreach ( $relatedSetIds as $set ){
279 $setIds[] = $set['ID'];
280 }
281 }
282 }
283
284 $chipsObj = new \FilterEverything\Filter\Chips( $showReset, $setIds );
285 $chips = $chipsObj->getChips();
286
287 $templateManager->includeFrontView( 'chips', array( 'chips' => $chips, 'setid' => reset($setIds) ) );
288 }
289
290 function flrt_show_selected_terms( $showReset = true, $setIds = [], $class = [] )
291 {
292 $default_class = array('wpc-custom-selected-terms');
293
294 if(! empty( $class ) && is_array($class) ){
295 $default_class = array_merge( $default_class, $class );
296 }
297
298 if( isset( $_POST['action'] ) && $_POST['action'] === 'elementor_ajax' ){
299 echo '<strong>'.esc_html__( 'Filter Everything &mdash; Chips', 'filter-everything' ).'</strong>';
300 return;
301 }
302
303 if( isset( $_GET['action'] ) && $_GET['action'] === 'elementor' ){
304 echo '<strong>'.esc_html__( 'Filter Everything &mdash; Chips', 'filter-everything' ).'</strong>';
305 return;
306 }
307
308 echo '<div class="'.implode(' ', $default_class).'">'."\r\n";
309 flrt_chips( $showReset, $setIds );
310 echo '</div>'."\r\n";
311 }
312
313 add_filter( 'wpc_dropdown_option_attr', 'flrt_parse_dropdown_value' );
314 function flrt_parse_dropdown_value( $attr ){
315 if( ! is_array( $attr ) ){
316 $new_attr = array();
317 $new_attr['label'] = $attr;
318 return $new_attr;
319 }
320
321 return $attr;
322 }
323
324 add_filter( 'wpc_unnecessary_get_parameters', 'flrt_unnecessary_get_parameters' );
325 function flrt_unnecessary_get_parameters( $params ){
326 $unnecessary_params = array(
327 'product-page' => true,
328 '_pjax' => true,
329 'cst' => true,
330 );
331
332 $get = \FilterEverything\Filter\Container::instance()->getTheGet();
333
334 if( ! empty( $get ) && is_array( $get ) ) {
335 foreach ( $get as $param_name => $param_value ) {
336 if( preg_match( '%query\-[0-9]+\-page%', $param_name ) ) {
337 $unnecessary_params[$param_name] = true;
338 }
339
340 if( preg_match( '%e\-page\-[a-zA-Z0-9]+%im', $param_name ) ) {
341 $unnecessary_params[$param_name] = true;
342 }
343 }
344 }
345
346 return array_merge( $params, $unnecessary_params );
347 }
348
349 add_filter('wpc_posts_containers', 'flrt_convert_posts_container_to_array');
350 function flrt_convert_posts_container_to_array( $container ){
351
352 if( ! is_array( $container ) ){
353 return [ 'default' => trim($container) ];
354 }
355
356 return $container;
357 }
358
359 add_filter( 'wpc_seo_title', 'do_shortcode' );
360 add_filter( 'wpc_seo_description', 'do_shortcode' );
361 add_filter( 'wpc_seo_h1', 'do_shortcode' );
362
363 /**
364 * @return int
365 * @since 1.7.1
366 */
367 function flrt_more_less_count() {
368 return apply_filters( 'wpc_more_less_count', 5 );
369 }
370 /**
371 * @return mixed|void
372 * @since 1.7.1
373 */
374 function flrt_more_less_opened() {
375 return apply_filters( 'wpc_more_less_opened', [] );
376 }
377 /**
378 * @return mixed|void
379 * @since 1.7.1
380 */
381 function flrt_folding_opened() {
382 return apply_filters( 'wpc_folding_opened', [] );
383 }
384 /**
385 * @return mixed|void
386 * @since 1.7.1
387 */
388 function flrt_hierarchy_opened() {
389 return apply_filters( 'wpc_hierarchy_opened', [] );
390 }
391 /**
392 * @param $filter
393 * @return mixed|void
394 * @since 1.7.1
395 */
396 function flrt_dropdown_default_option( $filter ) {
397 $label = sprintf( __( '- Select %s -', 'filter-everything' ), $filter['label'] );
398 if( isset( $filter['dropdown_label'] ) && $filter['dropdown_label'] ){
399 $label = $filter['dropdown_label'];
400 }
401 return apply_filters( 'wpc_dropdown_default_option', $label, $filter );
402 }
403
404 function flrt_brand_filter_entities(){
405 return apply_filters( 'wpc_brand_filter_entities', ['product_brand', 'pa_brand', 'pwb-brand', 'yith_product_brand'] );
406 }
407
408 add_filter( 'wpc_filter_classes', 'wpc_frontend_filter_classes', 10, 2 );
409 function wpc_frontend_filter_classes( $classes, $filter ){
410 if( in_array( $filter['e_name'], flrt_brand_filter_entities() ) ) {
411 $classes[] = 'wpc-filter-has-brands';
412 }
413
414 return $classes;
415 }
416
417 add_filter( 'wpc_filter_classes', 'flrt_frontend_filter_classes', 10, 2 );
418 function flrt_frontend_filter_classes( $classes, $filter ){
419 if ( $filter['show_term_names'] === 'yes' ) {
420 $classes[] = 'wpc-filter-visible-term-names';
421 } else {
422 $classes[] = 'wpc-filter-hidden-term-names';
423 }
424
425 return $classes;
426 }
427
428 //add_filter( 'wpc_filter_classes', 'flrt_same_swatches_width', 20, 4 );
429 //function flrt_same_swatches_width( $classes, $filter, $default_classes, $terms, $args ){
430 // if( in_array( 'wpc-filter-has-swatches', $classes ) ){
431 // if( ! empty( $terms ) ) {
432 // $counters = [];
433 // foreach ( $terms as $single_term ) {
434 // $counters[] = $single_term->cross_count;
435 // }
436 //
437 // $max = max( $counters );
438 // $classes[] = 'wpc-counter-width-'. strlen( (string)$max );
439 // }
440 // }
441 // return $classes;
442 //}
443
444
445 // Bricks Builder fix for Any Category Filter Set
446 add_action( 'wpc_all_set_wp_queried_posts', 'flrt_bricks_builder_category_compat', 10, 2 );
447 function flrt_bricks_builder_category_compat( $set_wp_query, $setId ){
448
449 //to check if there is Bricks Builder
450 if ( defined( 'BRICKS_VERSION' ) && BRICKS_VERSION ) {
451 $filterSet = \FilterEverything\Filter\Container::instance()->getFilterSetService();
452 $the_set = $filterSet->getSet( $setId );
453
454 if ( isset( $the_set['wp_page_type']['value'] ) && isset( $the_set['post_name']['value'] ) ){
455 if ( strpos( $the_set['wp_page_type']['value'], 'taxonomy_' ) !== false ) {
456 if ( strpos( $the_set['post_name']['value'], '-1' ) !== false ) {
457 $queried_object = get_queried_object();
458 if ( property_exists( $queried_object, 'taxonomy' ) ){
459 $set_wp_query->set( $queried_object->taxonomy, $queried_object->slug );
460 }
461 }
462 }
463 }
464 }
465
466 return $set_wp_query;
467 }
468
469 add_filter( 'wpc_chips_term_name', 'flrt_chips_labels', 10, 3 );
470 function flrt_chips_labels( $term_name, $term, $filter ) {
471 if ( in_array( $filter['entity'], ['post_meta_num', 'tax_numeric', 'post_date', 'post_meta_date'] ) ) {
472 // 'min_num_label'
473 // 'max_num_label'
474
475 if( $filter['min_num_label'] !== '' ){
476 if( ! is_null( $term ) && property_exists( $term, 'slug' ) && in_array( $term->slug, ['min', 'from'] ) ){
477 if( strpos( $filter['min_num_label'], '{value}' ) !== false ){
478 $term_name = str_replace( '{value}', $filter['values'][$term->slug], $filter['min_num_label'] );
479 }else {
480 $term_name = $filter['min_num_label'] .' '.$filter['values'][$term->slug];
481 }
482
483 }
484 }
485
486 if( $filter['max_num_label'] !== '' ){
487 if( ! is_null( $term ) && property_exists( $term, 'slug' ) && in_array( $term->slug, ['max', 'to'] ) ){
488 if( strpos( $filter['max_num_label'], '{value}' ) !== false ){
489 $term_name = str_replace( '{value}', $filter['values'][$term->slug], $filter['max_num_label'] );
490 }else {
491 $term_name = $filter['max_num_label'] .' '.$filter['values'][$term->slug];
492 }
493 }
494 }
495
496 }
497
498 return $term_name;
499 }
500
501 add_filter( 'query_loop_block_query_vars', 'flrt_query_loop_block_query_vars', 10, 2 );
502
503 function flrt_query_loop_block_query_vars( $query, $block ){
504 global $xd;
505 $xd++;
506
507 if( ! is_null( $block ) && property_exists( $block, 'parsed_block' ) ){
508 if( isset( $block->parsed_block['blockName'] ) ) {
509 if( in_array( $block->parsed_block['blockName'],
510 [
511 'core/query-pagination-previous',
512 'core/query-pagination-next',
513 'core/query-pagination-numbers',
514 ]
515 ) ){
516 $query['flrt_pagination'] = true;
517 }
518 }
519 }
520
521 return $query;
522 }
523
524 add_filter( 'wpc_settings_field_checkbox', 'flrt_collapse_widget_checkbox_handler', 10, 2 );
525 function flrt_collapse_widget_checkbox_handler( $checkbox, $args )
526 {
527 $checkbox = '<div class="flrt-checkbox-switch-wrapper">';
528 $checkbox .= '<label class="flrt-checkbox-switch"><input type="checkbox" name="%s[%s]" %s id="%s" %s>';
529 $checkbox .= '<span class="flrt-checkbox-slider"></span>';
530 $checkbox .= '</label>';
531 $checkbox .= '<span class="wpc-checkbox-placeholder">%s</span>';
532 $checkbox .= '</div>';
533 return $checkbox;
534 }
535
536 add_filter( 'wpc_input_type_checkbox', 'flrt_input_checkbox_switcher', 10, 2 );
537 function flrt_input_checkbox_switcher( $html, $attributes )
538 {
539
540 $html_wrap = '<div class="flrt-checkbox-switch-wrapper">';
541 $html_wrap .= '<label class="flrt-checkbox-switch">';
542 $html_wrap .= $html;
543 $html_wrap .= '<span class="flrt-checkbox-slider"></span>';
544 $html_wrap .= '</label>';
545 $html_wrap .= '</div>';
546
547 return $html_wrap;
548 }
549
550
551 add_filter('wpc_get_broken_builders', function ($array) {
552 return [3669169978, 339203640];
553 }, 10, 1);
554
555
556
557 if(!defined('FLRT_FILTERS_PRO')) {
558
559 add_filter('flrt_before_render_admin_select_option', 'flrt_add_data_to_option_before_render', 10, 4);
560 function flrt_add_data_to_option_before_render($option_value, $attr, $label, $disabled)
561 {
562 $attributes = ' data-link="' . flrt_reneder_preview_link($option_value, $attr) . '"';
563
564 if(is_array($disabled) && in_array($option_value, $disabled)){
565 $class = $option_value . '-disabled';
566 $attributes .= ' class="' . $class . '"';
567 }
568
569 return $attributes;
570 }
571 function flrt_reneder_preview_link($option_value, $attr)
572 {
573 $link = '';
574 if ($attr['id'] == 'wpc_set_fields-post_type') {
575 if ($option_value == 'page') {
576 $option_value = 'post';
577 }
578
579
580
581 $archive_link = get_post_type_archive_link($option_value);
582 if ($archive_link) {
583 $link = $archive_link;
584 }
585
586 if (!$archive_link) {
587 $taxonomies = get_object_taxonomies($option_value);
588
589 if (!empty($taxonomies)) {
590 $first_taxonomy = $taxonomies[0];
591 $taxonomy = get_taxonomy($first_taxonomy);
592 if (!empty($taxonomy) && !is_wp_error($taxonomy)) {
593 $terms = get_terms([
594 'taxonomy' => $taxonomy->name,
595 'number' => 1,
596 'hide_empty' => false,
597 ]);
598 if (!empty($terms) && !is_wp_error($terms)) {
599 $term_link = get_term_link($terms[0]);
600 $link = esc_url($term_link);
601 }
602 }
603 }
604 }
605 }
606 return $link;
607 }
608 }
609
610 add_filter('wpc_is_check_errors_pro', function ($filter_sets, $query) {
611 $detector_class = 'FilterEverything\\Filter\\WP_Query_Source_Detector';
612 $is_allowed_method = 'is_allowed';
613 $source_var = 'flrt_detected_source';
614
615 if (defined('FLRT_FILTERS_PRO')) {
616 if (defined('FLRT_PRO_BUILDER_KEY')) {
617 $builder_key = apply_filters('wpc_builder_key_pro', $query->get($source_var), constant('FLRT_PRO_BUILDER_KEY'));
618
619 if ($detector_class::$is_allowed_method($builder_key)) {
620 return apply_filters('wpc_is_filtered_query_pro', [], $query);
621 }
622 }
623 }
624
625 if (!defined('FLRT_FILTERS_PRO')) {
626 $builder_key = apply_filters('wpc_builder_key', $query->get($source_var), $detector_class::$builder_key);
627
628 if ($detector_class::$is_allowed_method($builder_key)) {
629 return apply_filters('wpc_is_filtered_query_free', [], $query);
630 }
631 }
632
633 return [];
634 }, 10, 2);
635
636 add_filter('wpc_set_min_max', function($min_and_max, $filter_name) {
637 global $wp_query;
638
639 if (empty($wp_query->posts)) {
640 $min_and_max = ['min' => 0, 'max' => 0];
641 return $min_and_max;
642 }
643
644 return $min_and_max;
645 }, 10, 2);
646
647 if(!function_exists('wpc_default_custom_meta_keys_filter')){
648 function wpc_default_custom_meta_keys_filter(){
649 $normalize_keys = function($data) use (&$normalize_keys) {
650 $result = [];
651 foreach ($data as $k => $v) {
652 if (is_array($v)) {
653 $v = $normalize_keys($v);
654 }
655 if (is_int($k)) {
656 $result[(string)$v] = "";
657 } else {
658 $result[$k] = $v;
659 }
660 }
661 return $result;
662 };
663
664 $product_post_meta = array(
665 '_price' => esc_html__('filter by Product price', 'filter-everything'),
666 '_stock_status' => esc_html__('filter by Product stock status', 'filter-everything'),
667 '_sale_price' => esc_html__('filter by Product sale price', 'filter-everything'),
668 '_stock' => esc_html__('filter by Product stock quantity', 'filter-everything'),
669 'total_sales' => esc_html__('filter by Product total sales', 'filter-everything'),
670 '_backorders' => esc_html__('filter by Product backorders status', 'filter-everything'),
671 '_sold_individually' => esc_html__('filter by Product sold individually status', 'filter-everything'),
672 '_downloadable' => esc_html__('filter by Product downloadable status', 'filter-everything'),
673 '_virtual' => esc_html__('filter by Product virtual status', 'filter-everything'),
674 '_length' => esc_html__('filter by Product length', 'filter-everything'),
675 '_width' => esc_html__('filter by Product width', 'filter-everything'),
676 '_height' => esc_html__('filter by Product height', 'filter-everything'),
677 '_weight' => esc_html__('filter by Product weight', 'filter-everything'),
678 '_wc_average_rating' => esc_html__('filter by Product average rating', 'filter-everything'),
679 '_thumbnail_id' => esc_html__('filter by Featured image', 'filter-everything')
680 );
681 $product_post_meta_num = array(
682 '_price' => esc_html__('filter by Product price', 'filter-everything'),
683 '_stock' => esc_html__('filter by Product stock quantity', 'filter-everything'),
684 'total_sales' => esc_html__('filter by Product total sales', 'filter-everything'),
685 '_sale_price' => esc_html__('filter by Product sale price', 'filter-everything'),
686 '_stock_status' => esc_html__('filter by Product stock status', 'filter-everything'),
687 '_length' => esc_html__('filter by Product length', 'filter-everything'),
688 '_width' => esc_html__('filter by Product width', 'filter-everything'),
689 '_height' => esc_html__('filter by Product height', 'filter-everything'),
690 '_weight' => esc_html__('filter by Product weight', 'filter-everything'),
691 '_wc_average_rating' => esc_html__('filter by Product average rating', 'filter-everything'),
692 '_backorders' => esc_html__('filter by Product backorders status', 'filter-everything'),
693 '_sold_individually' => esc_html__('filter by Product sold individually status', 'filter-everything'),
694 '_downloadable' => esc_html__('filter by Product downloadable status', 'filter-everything'),
695 '_virtual' => esc_html__('filter by Product virtual status', 'filter-everything'),
696 '_thumbnail_id' => esc_html__('filter by Featured image', 'filter-everything'),
697 );
698 $product_post_meta_exists = array(
699 '_sale_price' => esc_html__('filter by Product on sale status', 'filter-everything'),
700 '_price' => esc_html__('filter by Product price', 'filter-everything'),
701 '_stock' => esc_html__('filter by Product stock quantity', 'filter-everything'),
702 'total_sales' => esc_html__('filter by Product total sales', 'filter-everything'),
703 '_stock_status' => esc_html__('filter by Product stock status', 'filter-everything'),
704 '_length' => esc_html__('filter by Product length', 'filter-everything'),
705 '_width' => esc_html__('filter by Product width', 'filter-everything'),
706 '_height' => esc_html__('filter by Product height', 'filter-everything'),
707 '_weight' => esc_html__('filter by Product weight', 'filter-everything'),
708 '_wc_average_rating' => esc_html__('filter by Product average rating', 'filter-everything'),
709 '_backorders' => esc_html__('filter by Product backorders status', 'filter-everything'),
710 '_sold_individually' => esc_html__('filter by Product sold individually status', 'filter-everything'),
711 '_downloadable' => esc_html__('filter by Product downloadable status', 'filter-everything'),
712 '_virtual' => esc_html__('filter by Product virtual status', 'filter-everything'),
713 '_thumbnail_id' => esc_html__('filter by Featured image', 'filter-everything'),
714 );
715 $all_post_types_post_meta_exists = array('_thumbnail_id' => esc_html__('filter by Featured image', 'filter-everything'));
716 $input = array(
717 'product' => array(
718 'post_meta' => $normalize_keys($product_post_meta),
719 'post_meta_num' => $normalize_keys($product_post_meta_num),
720 'post_meta_exists' => $normalize_keys($product_post_meta_exists)
721 ),
722 'all_post_types' => array(
723 'post_meta_exists' => $normalize_keys($all_post_types_post_meta_exists)
724 ),
725 );
726
727 return $normalize_keys($input);
728 }
729 }
730
731 add_action('wp_ajax_wpc_search_meta_keys', function () {
732 check_ajax_referer('wpc-f-set-nonce', '_flrt_nonce');
733
734 if ( ! current_user_can('edit_posts') ) {
735 wp_send_json_error(['message' => __('Forbidden', 'textdomain')], 403);
736 }
737
738 global $wpdb;
739
740 $q = isset($_GET['q']) ? sanitize_text_field(wp_unslash($_GET['q'])) : '';
741 $post_type = isset($_GET['post_type']) ? sanitize_key($_GET['post_type']) : 'post';
742 $post_meta_type = isset($_GET['post_meta_type']) ? sanitize_key($_GET['post_meta_type']) : '';
743
744 $include_custom_meta_keys = [];
745
746 if (!empty($post_type) && !empty($post_meta_type) && !empty(wpc_default_custom_meta_keys_filter()[$post_type][$post_meta_type])) {
747 foreach (wpc_default_custom_meta_keys_filter()[$post_type][$post_meta_type] as $key => $value) {
748 $include_custom_meta_keys[$key] = $value;
749 }
750 }
751
752 if (!empty($post_meta_type) && !empty(wpc_default_custom_meta_keys_filter()['all_post_types'][$post_meta_type])) {
753 foreach (wpc_default_custom_meta_keys_filter()['all_post_types'][$post_meta_type] as $key => $value) {
754 $include_custom_meta_keys[$key] = $value;
755 }
756 }
757
758 $default_custom_meta_keys = $include_custom_meta_keys;
759 $include_custom_meta_keys = array_values(array_unique(array_filter($include_custom_meta_keys)));
760 if(strlen($q) > 0){
761 $include_custom_meta_keys = array_values(array_filter(
762 $include_custom_meta_keys,
763 static fn(string $key) => strncmp($key, $q, strlen($q)) === 0
764 ));
765 }
766 $default_items = array_map(static function ($k) {
767 return [
768 'id' => $k,
769 'text' => $include_custom_meta_keys[$k],
770 ];
771 }, array_keys($include_custom_meta_keys) ?: []);
772
773 if (strlen($q) < 1) {
774 wp_send_json(['items' => $default_items]);
775 }
776
777 $like = '%' . $wpdb->esc_like($q) . '%';
778 $limit = 15;
779
780 $sql = $wpdb->prepare(
781 "SELECT DISTINCT pm.meta_key
782 FROM {$wpdb->postmeta} pm
783 INNER JOIN {$wpdb->posts} p ON p.ID = pm.post_id
784 WHERE p.post_type = %s
785 AND pm.meta_key LIKE %s ORDER BY pm.meta_key ASC
786 LIMIT %d",
787 $post_type,
788 $like,
789 $limit
790 );
791
792 $keys = $wpdb->get_col($sql);
793
794 $exact_match_index = array_search($q, $keys);
795 if ($exact_match_index !== false) {
796 unset($keys[$exact_match_index]);
797 array_unshift($keys, $q);
798 }
799 $items = array_map(static function ($k) use ($default_custom_meta_keys) {
800 $text = !empty($default_custom_meta_keys[$k]) ? $default_custom_meta_keys[$k] : '';
801 return [
802 'id' => $k,
803 'text' => $text,
804 ];
805 }, $keys ?: []);
806 if (strlen($q) > 1 && count($items) < 1) {
807 $items[] = [
808 'id' => $q,
809 'text' => '',
810 ];
811 }
812
813 wp_send_json(['items' => array_merge($default_items, $items)]);
814 });
815 add_action( 'admin_post_wpc_seo_settings', function() {
816 check_admin_referer( 'wpc_seo_settings' );
817
818 $filter_permalinks = $_POST['wpc_filter_permalinks'] ?? [];
819 $seo_rules_settings = $_POST['wpc_seo_rules_settings'] ?? [];
820 $wpc_indexing_deep_settings = $_POST['wpc_indexing_deep_settings'] ?? [];
821
822 $filter_permalinks = array_map( 'sanitize_text_field', $filter_permalinks );
823 $seo_rules_settings = array_map( 'sanitize_text_field', $seo_rules_settings );
824 $wpc_indexing_deep_settings = array_map( 'sanitize_text_field', $wpc_indexing_deep_settings );
825
826 update_option( 'wpc_filter_permalinks', $filter_permalinks );
827 update_option( 'wpc_seo_rules_settings', $seo_rules_settings );
828 update_option( 'wpc_indexing_deep_settings', $wpc_indexing_deep_settings );
829
830 $redirect_url = add_query_arg( 'settings-updated', 'true', wp_get_referer() );
831 wp_safe_redirect( $redirect_url );
832 exit;
833 });
834
835 if (!defined( 'FLRT_FILTERS_PRO' ) ){
836 add_action( 'admin_footer', function () {
837 if ( ! is_admin() ) {
838 return;
839 }
840
841 $screen = get_current_screen();
842
843 if ( ! $screen ) {
844 return;
845 }
846
847 if ( $screen->post_type === 'filter-set' ) {
848 flrt_include_admin_view('pro-modal', []);
849 }
850 });
851 }
852
853
854
855 //add_filter( 'stackable/posts/post_query', 'flrt_stackable_block_query_vars', 10, 3 );
856 //function flrt_stackable_block_query_vars( $post_query, $context, $query_string ){
857 // if( is_user_logged_in() ) {
858 // var_dump( $context );
859 // var_dump( $query_string );
860 // }
861 //
862 // return $post_query;
863 //}