Version Description
( 2021-04-12 ) = * Add - Royal theme integration * Update - Aurum theme integration * Update - Ultimate Member plugin support * Dev - Add deleted_post hook for index table sync * Dev - Add aws_js_seamless_searchbox_markup filter
Download this release
Release Info
Developer | Mihail Barinov |
Plugin | Advanced Woo Search |
Version | 2.25 |
Comparing to | |
See all releases |
Code changes from version 2.24 to 2.25
- advanced-woo-search.php +2 -2
- includes/class-aws-integrations.php +101 -59
- includes/class-aws-table.php +23 -0
- includes/modules/class-aws-um.php +270 -0
- readme.txt +8 -1
advanced-woo-search.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
/*
|
4 |
Plugin Name: Advanced Woo Search
|
5 |
Description: Advance ajax WooCommerce product search.
|
6 |
-
Version: 2.
|
7 |
Author: ILLID
|
8 |
Author URI: https://advanced-woo-search.com/
|
9 |
Text Domain: advanced-woo-search
|
@@ -96,7 +96,7 @@ final class AWS_Main {
|
|
96 |
*/
|
97 |
private function define_constants() {
|
98 |
|
99 |
-
$this->define( 'AWS_VERSION', '2.
|
100 |
|
101 |
$this->define( 'AWS_DIR', plugin_dir_path( AWS_FILE ) );
|
102 |
$this->define( 'AWS_URL', plugin_dir_url( AWS_FILE ) );
|
3 |
/*
|
4 |
Plugin Name: Advanced Woo Search
|
5 |
Description: Advance ajax WooCommerce product search.
|
6 |
+
Version: 2.25
|
7 |
Author: ILLID
|
8 |
Author URI: https://advanced-woo-search.com/
|
9 |
Text Domain: advanced-woo-search
|
96 |
*/
|
97 |
private function define_constants() {
|
98 |
|
99 |
+
$this->define( 'AWS_VERSION', '2.25' );
|
100 |
|
101 |
$this->define( 'AWS_DIR', plugin_dir_path( AWS_FILE ) );
|
102 |
$this->define( 'AWS_URL', plugin_dir_url( AWS_FILE ) );
|
includes/class-aws-integrations.php
CHANGED
@@ -155,6 +155,8 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
|
|
155 |
if ( 'Aurum' === $this->current_theme ) {
|
156 |
add_filter( 'aurum_show_search_field_on_mobile', '__return_false' );
|
157 |
add_filter( 'wp_nav_menu', array( $this, 'aurum_mobile_menu' ), 10, 2 );
|
|
|
|
|
158 |
}
|
159 |
|
160 |
if ( 'Fury' === $this->current_theme ) {
|
@@ -176,6 +178,10 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
|
|
176 |
add_action( 'wp_head', array( $this, 'salient_wp_head' ) );
|
177 |
}
|
178 |
|
|
|
|
|
|
|
|
|
179 |
}
|
180 |
|
181 |
add_action( 'wp_head', array( $this, 'head_js_integration' ) );
|
@@ -185,11 +191,6 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
|
|
185 |
add_filter( 'aws_search_results_products', array( $this, 'wholesale_hide_products' ) );
|
186 |
}
|
187 |
|
188 |
-
// Ultimate Member plugin hide certain products
|
189 |
-
if ( class_exists( 'UM_Functions' ) ) {
|
190 |
-
add_filter( 'aws_search_results_products', array( $this, 'um_hide_products' ) );
|
191 |
-
}
|
192 |
-
|
193 |
// Search Exclude plugin
|
194 |
if ( class_exists( 'SearchExclude' ) ) {
|
195 |
add_filter( 'aws_index_product_ids', array( $this, 'search_exclude_filter' ) );
|
@@ -305,6 +306,11 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
|
|
305 |
include_once( AWS_DIR . '/includes/modules/class-aws-woof-filter.php' );
|
306 |
}
|
307 |
|
|
|
|
|
|
|
|
|
|
|
308 |
}
|
309 |
|
310 |
/*
|
@@ -1060,6 +1066,52 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
|
|
1060 |
return $nav_menu;
|
1061 |
}
|
1062 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1063 |
/*
|
1064 |
* Fury theme markup change
|
1065 |
*/
|
@@ -1211,6 +1263,30 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
|
|
1211 |
</style>
|
1212 |
<?php }
|
1213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1214 |
/*
|
1215 |
* Exclude product categories
|
1216 |
*/
|
@@ -1394,6 +1470,15 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
|
|
1394 |
$selectors[] = '#search-box form';
|
1395 |
}
|
1396 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1397 |
// WCFM - WooCommerce Multivendor Marketplace
|
1398 |
if ( class_exists( 'WCFMmp' ) ) {
|
1399 |
$selectors[] = '#wcfmmp-store .woocommerce-product-search';
|
@@ -1421,6 +1506,16 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
|
|
1421 |
|
1422 |
$forms_selector = implode( ',', $forms );
|
1423 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1424 |
?>
|
1425 |
|
1426 |
<script>
|
@@ -1428,7 +1523,7 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
|
|
1428 |
window.addEventListener('load', function() {
|
1429 |
var forms = document.querySelectorAll("<?php echo $forms_selector; ?>");
|
1430 |
|
1431 |
-
var awsFormHtml = <?php echo json_encode(
|
1432 |
|
1433 |
if ( forms ) {
|
1434 |
|
@@ -1513,59 +1608,6 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
|
|
1513 |
|
1514 |
}
|
1515 |
|
1516 |
-
/*
|
1517 |
-
* Ultimate Member hide products
|
1518 |
-
*/
|
1519 |
-
public function um_hide_products( $products ) {
|
1520 |
-
|
1521 |
-
foreach( $products as $key => $product ) {
|
1522 |
-
|
1523 |
-
$um_content_restriction = get_post_meta( $product['id'], 'um_content_restriction', true );
|
1524 |
-
|
1525 |
-
if ( $um_content_restriction && is_array( $um_content_restriction ) && ! empty( $um_content_restriction ) ) {
|
1526 |
-
|
1527 |
-
$um_custom_access_settings = isset( $um_content_restriction['_um_custom_access_settings'] ) ? $um_content_restriction['_um_custom_access_settings'] : false;
|
1528 |
-
$um_access_hide_from_queries = isset( $um_content_restriction['_um_access_hide_from_queries'] ) ? $um_content_restriction['_um_access_hide_from_queries'] : false;
|
1529 |
-
|
1530 |
-
if ( $um_custom_access_settings && $um_custom_access_settings === '1' && $um_access_hide_from_queries && $um_access_hide_from_queries === '1' ) {
|
1531 |
-
|
1532 |
-
$um_accessible = isset( $um_content_restriction['_um_accessible'] ) ? $um_content_restriction['_um_accessible'] : false;
|
1533 |
-
|
1534 |
-
if ( $um_accessible ) {
|
1535 |
-
|
1536 |
-
if ( $um_accessible === '1' && is_user_logged_in() ) {
|
1537 |
-
unset( $products[$key] );
|
1538 |
-
}
|
1539 |
-
elseif ( $um_accessible === '2' && ! is_user_logged_in() ) {
|
1540 |
-
unset( $products[$key] );
|
1541 |
-
}
|
1542 |
-
elseif ( $um_accessible === '2' && is_user_logged_in() ) {
|
1543 |
-
|
1544 |
-
$um_access_roles = isset( $um_content_restriction['_um_access_roles'] ) ? $um_content_restriction['_um_access_roles'] : false;
|
1545 |
-
|
1546 |
-
if ( $um_access_roles && is_array( $um_access_roles ) && ! empty( $um_access_roles ) ) {
|
1547 |
-
$user = wp_get_current_user();
|
1548 |
-
$role = ( array ) $user->roles;
|
1549 |
-
$user_role = $role[0];
|
1550 |
-
if ( $user_role && $user_role !== 'administrator' && ! isset( $um_access_roles[$user_role] ) ) {
|
1551 |
-
unset( $products[$key] );
|
1552 |
-
}
|
1553 |
-
}
|
1554 |
-
|
1555 |
-
}
|
1556 |
-
|
1557 |
-
}
|
1558 |
-
|
1559 |
-
}
|
1560 |
-
|
1561 |
-
}
|
1562 |
-
|
1563 |
-
}
|
1564 |
-
|
1565 |
-
return $products;
|
1566 |
-
|
1567 |
-
}
|
1568 |
-
|
1569 |
/*
|
1570 |
* Remove products that was excluded with Search Exclude plugin ( https://wordpress.org/plugins/search-exclude/ )
|
1571 |
*/
|
155 |
if ( 'Aurum' === $this->current_theme ) {
|
156 |
add_filter( 'aurum_show_search_field_on_mobile', '__return_false' );
|
157 |
add_filter( 'wp_nav_menu', array( $this, 'aurum_mobile_menu' ), 10, 2 );
|
158 |
+
add_filter( 'aws_js_seamless_searchbox_markup', array( $this, 'aurum_seamless_searchbox_markup' ), 1 );
|
159 |
+
add_action( 'wp_head', array( $this, 'aurum_wp_head' ) );
|
160 |
}
|
161 |
|
162 |
if ( 'Fury' === $this->current_theme ) {
|
178 |
add_action( 'wp_head', array( $this, 'salient_wp_head' ) );
|
179 |
}
|
180 |
|
181 |
+
if ( 'Royal' === $this->current_theme ) {
|
182 |
+
add_action( 'wp_head', array( $this, 'royal_wp_head' ) );
|
183 |
+
}
|
184 |
+
|
185 |
}
|
186 |
|
187 |
add_action( 'wp_head', array( $this, 'head_js_integration' ) );
|
191 |
add_filter( 'aws_search_results_products', array( $this, 'wholesale_hide_products' ) );
|
192 |
}
|
193 |
|
|
|
|
|
|
|
|
|
|
|
194 |
// Search Exclude plugin
|
195 |
if ( class_exists( 'SearchExclude' ) ) {
|
196 |
add_filter( 'aws_index_product_ids', array( $this, 'search_exclude_filter' ) );
|
306 |
include_once( AWS_DIR . '/includes/modules/class-aws-woof-filter.php' );
|
307 |
}
|
308 |
|
309 |
+
// Ultimate Member plugin hide certain products
|
310 |
+
if ( class_exists( 'UM_Functions' ) ) {
|
311 |
+
include_once( AWS_DIR . '/includes/modules/class-aws-um.php' );
|
312 |
+
}
|
313 |
+
|
314 |
}
|
315 |
|
316 |
/*
|
1066 |
return $nav_menu;
|
1067 |
}
|
1068 |
|
1069 |
+
/*
|
1070 |
+
* Aurum theme markup for seamless js integration
|
1071 |
+
*/
|
1072 |
+
public function aurum_seamless_searchbox_markup( $markup ) {
|
1073 |
+
|
1074 |
+
if ( function_exists( 'lab_get_svg' ) ) {
|
1075 |
+
$button = '<a href="#" class="search-btn">' . lab_get_svg( "images/search.svg" ) . '<span class="sr-only">' . __( "Search", "aurum" ) .'</span></a>';
|
1076 |
+
$markup = preg_replace( '/(<form[\S\s]*?>)/i', '${1}<div class="search-input-env">', $markup );
|
1077 |
+
$markup = str_replace( '</form>', '</div></form>', $markup );
|
1078 |
+
$markup = str_replace( '</form>', $button . '</form>', $markup );
|
1079 |
+
$markup = str_replace( 'aws-search-form', 'aws-search-form search-form', $markup );
|
1080 |
+
$markup = str_replace( 'aws-search-field', 'aws-search-field search-input', $markup );
|
1081 |
+
$markup = preg_replace( '/(<div class="aws-search-btn aws-form-btn">[\S\s]*?<\/div>)/i', '', $markup );
|
1082 |
+
}
|
1083 |
+
|
1084 |
+
return $markup;
|
1085 |
+
|
1086 |
+
}
|
1087 |
+
|
1088 |
+
/*
|
1089 |
+
* Aurum theme scripts
|
1090 |
+
*/
|
1091 |
+
public function aurum_wp_head() { ?>
|
1092 |
+
|
1093 |
+
<script>
|
1094 |
+
window.addEventListener("load", function() {
|
1095 |
+
window.setTimeout(function(){
|
1096 |
+
var forms = document.querySelectorAll(".search-btn");
|
1097 |
+
if ( forms ) {
|
1098 |
+
for (var i = 0; i < forms.length; i++) {
|
1099 |
+
forms[i].addEventListener("click", function() {
|
1100 |
+
var links = document.querySelectorAll(".header-links .search-form");
|
1101 |
+
if ( links ) {
|
1102 |
+
for (var i = 0; i < links.length; i++) {
|
1103 |
+
links[i].className += " input-visible";
|
1104 |
+
}
|
1105 |
+
}
|
1106 |
+
}, false);
|
1107 |
+
}
|
1108 |
+
}
|
1109 |
+
}, 1000);
|
1110 |
+
}, false);
|
1111 |
+
</script>
|
1112 |
+
|
1113 |
+
<?php }
|
1114 |
+
|
1115 |
/*
|
1116 |
* Fury theme markup change
|
1117 |
*/
|
1263 |
</style>
|
1264 |
<?php }
|
1265 |
|
1266 |
+
/*
|
1267 |
+
* Royal theme styles
|
1268 |
+
*/
|
1269 |
+
public function royal_wp_head() { ?>
|
1270 |
+
<style>
|
1271 |
+
.et-search-trigger.search-dropdown .aws-container {
|
1272 |
+
position: absolute;
|
1273 |
+
width: 325px;
|
1274 |
+
top: 55px;
|
1275 |
+
z-index: 1001;
|
1276 |
+
right: -12px;
|
1277 |
+
}
|
1278 |
+
.et-search-trigger.search-dropdown .aws-container .aws-search-form,
|
1279 |
+
.et-search-trigger.search-dropdown:hover .aws-container .aws-search-form{
|
1280 |
+
top: 0;
|
1281 |
+
right: 0;
|
1282 |
+
height: auto;
|
1283 |
+
}
|
1284 |
+
#searchModal .aws-container {
|
1285 |
+
margin: 30px 30px 20px;
|
1286 |
+
}
|
1287 |
+
</style>
|
1288 |
+
<?php }
|
1289 |
+
|
1290 |
/*
|
1291 |
* Exclude product categories
|
1292 |
*/
|
1470 |
$selectors[] = '#search-box form';
|
1471 |
}
|
1472 |
|
1473 |
+
if ( 'Aurum' === $this->current_theme ) {
|
1474 |
+
$selectors[] = '.header-links .search-form';
|
1475 |
+
}
|
1476 |
+
|
1477 |
+
if ( 'Royal' === $this->current_theme ) {
|
1478 |
+
$selectors[] = '.header-search form';
|
1479 |
+
$selectors[] = '#searchModal form';
|
1480 |
+
}
|
1481 |
+
|
1482 |
// WCFM - WooCommerce Multivendor Marketplace
|
1483 |
if ( class_exists( 'WCFMmp' ) ) {
|
1484 |
$selectors[] = '#wcfmmp-store .woocommerce-product-search';
|
1506 |
|
1507 |
$forms_selector = implode( ',', $forms );
|
1508 |
|
1509 |
+
$form_html = str_replace( 'aws-container', 'aws-container aws-js-seamless', aws_get_search_form( false ) );
|
1510 |
+
|
1511 |
+
/**
|
1512 |
+
* Filter seamless integrations default form markup
|
1513 |
+
* @since 2.25
|
1514 |
+
* @param string $form_html Form html output
|
1515 |
+
* @param array $forms Array of css selectors
|
1516 |
+
*/
|
1517 |
+
$form_html = apply_filters( 'aws_js_seamless_searchbox_markup', $form_html, $forms );
|
1518 |
+
|
1519 |
?>
|
1520 |
|
1521 |
<script>
|
1523 |
window.addEventListener('load', function() {
|
1524 |
var forms = document.querySelectorAll("<?php echo $forms_selector; ?>");
|
1525 |
|
1526 |
+
var awsFormHtml = <?php echo json_encode( $form_html ); ?>;
|
1527 |
|
1528 |
if ( forms ) {
|
1529 |
|
1608 |
|
1609 |
}
|
1610 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1611 |
/*
|
1612 |
* Remove products that was excluded with Search Exclude plugin ( https://wordpress.org/plugins/search-exclude/ )
|
1613 |
*/
|
includes/class-aws-table.php
CHANGED
@@ -31,6 +31,7 @@ if ( ! class_exists( 'AWS_Table' ) ) :
|
|
31 |
$this->table_name = $wpdb->prefix . AWS_INDEX_TABLE_NAME;
|
32 |
|
33 |
add_action( 'wp_insert_post', array( $this, 'product_changed' ), 10, 3 );
|
|
|
34 |
|
35 |
add_action( 'create_term', array( &$this, 'term_changed' ), 10, 3 );
|
36 |
add_action( 'delete_term', array( &$this, 'term_changed' ), 10, 3 );
|
@@ -495,6 +496,28 @@ if ( ! class_exists( 'AWS_Table' ) ) :
|
|
495 |
|
496 |
}
|
497 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
498 |
/*
|
499 |
* Fires when products variations are changed
|
500 |
*/
|
31 |
$this->table_name = $wpdb->prefix . AWS_INDEX_TABLE_NAME;
|
32 |
|
33 |
add_action( 'wp_insert_post', array( $this, 'product_changed' ), 10, 3 );
|
34 |
+
add_action( 'delete_post', array( $this, 'product_deleted' ), 10, 2 );
|
35 |
|
36 |
add_action( 'create_term', array( &$this, 'term_changed' ), 10, 3 );
|
37 |
add_action( 'delete_term', array( &$this, 'term_changed' ), 10, 3 );
|
496 |
|
497 |
}
|
498 |
|
499 |
+
/*
|
500 |
+
* Product removed hook
|
501 |
+
*/
|
502 |
+
public function product_deleted( $post_id, $post = false ) {
|
503 |
+
|
504 |
+
$slug = 'product';
|
505 |
+
|
506 |
+
if ( $post && $slug != $post->post_type ) {
|
507 |
+
return;
|
508 |
+
}
|
509 |
+
|
510 |
+
if ( ! $post ) {
|
511 |
+
$post_type = get_post_type( $post_id );
|
512 |
+
if ( $post_type && $slug != $post_type ) {
|
513 |
+
return;
|
514 |
+
}
|
515 |
+
}
|
516 |
+
|
517 |
+
$this->update_table( $post_id );
|
518 |
+
|
519 |
+
}
|
520 |
+
|
521 |
/*
|
522 |
* Fires when products variations are changed
|
523 |
*/
|
includes/modules/class-aws-um.php
ADDED
@@ -0,0 +1,270 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Ultimate Member plugin
|
4 |
+
*/
|
5 |
+
|
6 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
7 |
+
exit; // Exit if accessed directly.
|
8 |
+
}
|
9 |
+
|
10 |
+
if ( ! class_exists( 'AWS_UM' ) ) :
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class
|
14 |
+
*/
|
15 |
+
class AWS_UM {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Main AWS_UM Instance
|
19 |
+
*
|
20 |
+
* Ensures only one instance of AWS_UM is loaded or can be loaded.
|
21 |
+
*
|
22 |
+
* @static
|
23 |
+
* @return AWS_UM - Main instance
|
24 |
+
*/
|
25 |
+
protected static $_instance = null;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Main AWS_UM Instance
|
29 |
+
*
|
30 |
+
* Ensures only one instance of AWS_UM is loaded or can be loaded.
|
31 |
+
*
|
32 |
+
* @static
|
33 |
+
* @return AWS_UM - Main instance
|
34 |
+
*/
|
35 |
+
public static function instance() {
|
36 |
+
if ( is_null( self::$_instance ) ) {
|
37 |
+
self::$_instance = new self();
|
38 |
+
}
|
39 |
+
return self::$_instance;
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Constructor
|
44 |
+
*/
|
45 |
+
public function __construct() {
|
46 |
+
|
47 |
+
add_filter( 'aws_exclude_products', array( $this, 'exclude_products' ) );
|
48 |
+
|
49 |
+
add_filter( 'aws_search_tax_results', array( $this, 'exclude_tax' ), 10, 2 );
|
50 |
+
|
51 |
+
}
|
52 |
+
|
53 |
+
/*
|
54 |
+
* Restrict products
|
55 |
+
*/
|
56 |
+
public function exclude_products( $products_ids ) {
|
57 |
+
|
58 |
+
$restricted_products_by_terms = $this->get_restricted_products_by_terms();
|
59 |
+
|
60 |
+
$restricted_products = get_posts( array(
|
61 |
+
'posts_per_page' => -1,
|
62 |
+
'fields' => 'ids',
|
63 |
+
'post_type' => 'product',
|
64 |
+
'post_status' => 'publish',
|
65 |
+
'ignore_sticky_posts' => true,
|
66 |
+
'suppress_filters' => true,
|
67 |
+
'has_password' => false,
|
68 |
+
'no_found_rows' => 1,
|
69 |
+
'orderby' => 'ID',
|
70 |
+
'order' => 'DESC',
|
71 |
+
'lang' => '',
|
72 |
+
'meta_query' => array(
|
73 |
+
array(
|
74 |
+
'key' => 'um_content_restriction',
|
75 |
+
'compare' => 'EXISTS',
|
76 |
+
)
|
77 |
+
)
|
78 |
+
) );
|
79 |
+
|
80 |
+
if ( $restricted_products ) {
|
81 |
+
foreach( $restricted_products as $restricted_product_id ) {
|
82 |
+
|
83 |
+
$um_content_restriction = get_post_meta( $restricted_product_id, 'um_content_restriction', true );
|
84 |
+
|
85 |
+
$is_restricted = $this->is_restricted( $um_content_restriction );
|
86 |
+
|
87 |
+
if ( $is_restricted ) {
|
88 |
+
$products_ids[] = $restricted_product_id;
|
89 |
+
}
|
90 |
+
|
91 |
+
}
|
92 |
+
}
|
93 |
+
|
94 |
+
if ( ! empty( $restricted_products_by_terms ) ) {
|
95 |
+
$products_ids = array_merge($products_ids, $restricted_products_by_terms);
|
96 |
+
|
97 |
+
}
|
98 |
+
|
99 |
+
return $products_ids;
|
100 |
+
|
101 |
+
}
|
102 |
+
|
103 |
+
/*
|
104 |
+
* Restrict taxonomies
|
105 |
+
*/
|
106 |
+
public function exclude_tax( $result_array, $taxonomy ) {
|
107 |
+
|
108 |
+
$new_result_array = array();
|
109 |
+
|
110 |
+
foreach ( $result_array as $result_tax_name => $result_tax ) {
|
111 |
+
foreach ( $result_tax as $tax_key => $tax_item ) {
|
112 |
+
$um_content_restriction = get_term_meta( $tax_item['id'], 'um_content_restriction', true );
|
113 |
+
$is_restricted = $this->is_restricted( $um_content_restriction );
|
114 |
+
if ( $is_restricted ) {
|
115 |
+
continue;
|
116 |
+
}
|
117 |
+
$new_result_array[$result_tax_name][] = $tax_item;
|
118 |
+
}
|
119 |
+
}
|
120 |
+
|
121 |
+
return $new_result_array;
|
122 |
+
|
123 |
+
}
|
124 |
+
|
125 |
+
/*
|
126 |
+
* Check is product/term is restricted for current user
|
127 |
+
*/
|
128 |
+
private function is_restricted( $um_content_restriction ) {
|
129 |
+
|
130 |
+
if ( $um_content_restriction && is_array( $um_content_restriction ) && ! empty( $um_content_restriction ) ) {
|
131 |
+
|
132 |
+
$um_custom_access_settings = isset( $um_content_restriction['_um_custom_access_settings'] ) ? $um_content_restriction['_um_custom_access_settings'] : false;
|
133 |
+
$um_access_hide_from_queries = isset( $um_content_restriction['_um_access_hide_from_queries'] ) ? $um_content_restriction['_um_access_hide_from_queries'] : false;
|
134 |
+
|
135 |
+
if ( $um_custom_access_settings && $um_custom_access_settings === '1' && $um_access_hide_from_queries && $um_access_hide_from_queries === '1' ) {
|
136 |
+
|
137 |
+
$um_accessible = isset( $um_content_restriction['_um_accessible'] ) ? $um_content_restriction['_um_accessible'] : false;
|
138 |
+
|
139 |
+
if ( $um_accessible ) {
|
140 |
+
|
141 |
+
if ( $um_accessible === '1' && is_user_logged_in() ) {
|
142 |
+
return true;
|
143 |
+
}
|
144 |
+
elseif ( $um_accessible === '2' && ! is_user_logged_in() ) {
|
145 |
+
return true;
|
146 |
+
}
|
147 |
+
elseif ( $um_accessible === '2' && is_user_logged_in() ) {
|
148 |
+
|
149 |
+
$um_access_roles = isset( $um_content_restriction['_um_access_roles'] ) ? $um_content_restriction['_um_access_roles'] : false;
|
150 |
+
|
151 |
+
if ( $um_access_roles && is_array( $um_access_roles ) && ! empty( $um_access_roles ) ) {
|
152 |
+
$user = wp_get_current_user();
|
153 |
+
$role = ( array ) $user->roles;
|
154 |
+
$user_role = $role[0];
|
155 |
+
if ( $user_role && $user_role !== 'administrator' && ! isset( $um_access_roles[$user_role] ) ) {
|
156 |
+
return true;
|
157 |
+
}
|
158 |
+
}
|
159 |
+
|
160 |
+
}
|
161 |
+
|
162 |
+
}
|
163 |
+
|
164 |
+
}
|
165 |
+
|
166 |
+
}
|
167 |
+
|
168 |
+
return false;
|
169 |
+
|
170 |
+
}
|
171 |
+
|
172 |
+
/*
|
173 |
+
* Get restricted products by restricted terms
|
174 |
+
*/
|
175 |
+
private function get_restricted_products_by_terms() {
|
176 |
+
|
177 |
+
$restricted_products = array();
|
178 |
+
$restricted_terms = $this->get_restricted_terms();
|
179 |
+
|
180 |
+
if ( $restricted_terms && ! empty( $restricted_terms ) ) {
|
181 |
+
|
182 |
+
$args = array(
|
183 |
+
'posts_per_page' => -1,
|
184 |
+
'fields' => 'ids',
|
185 |
+
'post_type' => 'product',
|
186 |
+
'post_status' => 'publish',
|
187 |
+
'ignore_sticky_posts' => true,
|
188 |
+
'suppress_filters' => true,
|
189 |
+
'has_password' => false,
|
190 |
+
'no_found_rows' => 1,
|
191 |
+
'orderby' => 'ID',
|
192 |
+
'order' => 'DESC',
|
193 |
+
'lang' => '',
|
194 |
+
) ;
|
195 |
+
|
196 |
+
$args['tax_query']['relation'] = 'OR';
|
197 |
+
|
198 |
+
foreach ( $restricted_terms as $restricted_tax_name => $restricted_tax ) {
|
199 |
+
$args['tax_query'][] = array(
|
200 |
+
'taxonomy' => $restricted_tax_name,
|
201 |
+
'field' => 'id',
|
202 |
+
'terms' => $restricted_tax,
|
203 |
+
);
|
204 |
+
}
|
205 |
+
|
206 |
+
$restricted_products = get_posts( $args );
|
207 |
+
|
208 |
+
}
|
209 |
+
|
210 |
+
return $restricted_products;
|
211 |
+
|
212 |
+
}
|
213 |
+
|
214 |
+
/*
|
215 |
+
* Get restricted terms
|
216 |
+
*/
|
217 |
+
private function get_restricted_terms() {
|
218 |
+
|
219 |
+
$restricted_terms_arr = array();
|
220 |
+
|
221 |
+
if ( function_exists( 'UM' ) ) {
|
222 |
+
|
223 |
+
$restricted_taxonomies_option = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
|
224 |
+
$restricted_taxonomies = array();
|
225 |
+
if ( $restricted_taxonomies_option && is_array( $restricted_taxonomies_option ) ) {
|
226 |
+
foreach( $restricted_taxonomies_option as $restricted_taxonomy => $restricted_taxonomy_val ) {
|
227 |
+
if ( $restricted_taxonomy_val ) {
|
228 |
+
$restricted_taxonomies[] = $restricted_taxonomy;
|
229 |
+
}
|
230 |
+
}
|
231 |
+
}
|
232 |
+
|
233 |
+
if ( ! empty( $restricted_taxonomies ) ) {
|
234 |
+
|
235 |
+
$restricted_terms = get_terms( array(
|
236 |
+
'taxonomy' => $restricted_taxonomies,
|
237 |
+
'hide_empty' => false,
|
238 |
+
'lang' => '',
|
239 |
+
'meta_query' => array(
|
240 |
+
array(
|
241 |
+
'key' => 'um_content_restriction',
|
242 |
+
'compare' => 'EXISTS',
|
243 |
+
)
|
244 |
+
)
|
245 |
+
) );
|
246 |
+
|
247 |
+
if ( $restricted_terms ) {
|
248 |
+
foreach( $restricted_terms as $restricted_term ) {
|
249 |
+
$um_content_restriction = get_term_meta( $restricted_term->term_id, 'um_content_restriction', true );
|
250 |
+
$is_restricted = $this->is_restricted( $um_content_restriction );
|
251 |
+
if ( $is_restricted ) {
|
252 |
+
$restricted_terms_arr[$restricted_term->taxonomy][] = $restricted_term->term_id;
|
253 |
+
}
|
254 |
+
|
255 |
+
}
|
256 |
+
}
|
257 |
+
|
258 |
+
|
259 |
+
}
|
260 |
+
}
|
261 |
+
|
262 |
+
return $restricted_terms_arr;
|
263 |
+
|
264 |
+
}
|
265 |
+
|
266 |
+
}
|
267 |
+
|
268 |
+
endif;
|
269 |
+
|
270 |
+
AWS_UM::instance();
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
|
|
4 |
Tags: widget, plugin, woocommerce, search, product search, woocommerce search, ajax search, live search, custom search, ajax, shortcode, better search, relevance search, relevant search, search by sku, search plugin, shop, store, wordpress search, wp ajax search, wp search, wp search plugin, sidebar, ecommerce, merketing, products, category search, instant-search, search highlight, woocommerce advanced search, woocommerce live search, WooCommerce Plugin, woocommerce product search
|
5 |
Requires at least: 4.0
|
6 |
Tested up to: 5.7
|
7 |
-
Stable tag: 2.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -167,6 +167,13 @@ Yep. This plugin is always compatible with the latest version of Woocommerce?
|
|
167 |
|
168 |
== Changelog ==
|
169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
= 2.24 ( 2021-03-25 ) =
|
171 |
* Fix - Parent theme name detection
|
172 |
* Dev - Update helper functions
|
4 |
Tags: widget, plugin, woocommerce, search, product search, woocommerce search, ajax search, live search, custom search, ajax, shortcode, better search, relevance search, relevant search, search by sku, search plugin, shop, store, wordpress search, wp ajax search, wp search, wp search plugin, sidebar, ecommerce, merketing, products, category search, instant-search, search highlight, woocommerce advanced search, woocommerce live search, WooCommerce Plugin, woocommerce product search
|
5 |
Requires at least: 4.0
|
6 |
Tested up to: 5.7
|
7 |
+
Stable tag: 2.25
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
167 |
|
168 |
== Changelog ==
|
169 |
|
170 |
+
= 2.25 ( 2021-04-12 ) =
|
171 |
+
* Add - Royal theme integration
|
172 |
+
* Update - Aurum theme integration
|
173 |
+
* Update - Ultimate Member plugin support
|
174 |
+
* Dev - Add deleted_post hook for index table sync
|
175 |
+
* Dev - Add aws_js_seamless_searchbox_markup filter
|
176 |
+
|
177 |
= 2.24 ( 2021-03-25 ) =
|
178 |
* Fix - Parent theme name detection
|
179 |
* Dev - Update helper functions
|