| Server IP : 38.190.208.107 / Your IP : 216.73.217.51 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.9/wp-content/themes/woodmart/inc/modules/search/query/ |
Upload File : |
<?php
/**
* Search query class.
*
* @package woodmart
*/
namespace XTS\Modules\Search\Query;
use XTS\Singleton;
/**
* Search query class.
*/
class Search_Query extends Singleton {
/**
* Init.
*/
public function init() {
add_filter( 'posts_search', array( $this, 'extend_search_query' ), 10, 2 );
}
/**
* Change default search query.
*
* @param string $search The search query.
* @param object $query The WP_Query object.
*
* @return string
*/
public function extend_search_query( $search, $query ) {
global $wpdb;
if ( ! woodmart_woocommerce_installed() || empty( $search ) ) {
return $search;
}
$is_main_search = ! is_admin() && $query->is_search() && $query->is_main_query();
$is_ajax_search = is_ajax() && isset( $_REQUEST['action'] ) && isset( $_REQUEST['query'] ) && isset( $_REQUEST['post_type'] ) && ! empty( $_REQUEST['query'] ) && 'woodmart_ajax_search' === $_REQUEST['action']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$post_type = $is_ajax_search ? sanitize_text_field( wp_unslash( $_REQUEST['post_type'] ) ) : $query->get( 'post_type' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$post_types = (array) $post_type;
if ( ! in_array( 'product', $post_types, true ) ) {
return $search;
}
if ( $is_main_search || $is_ajax_search ) {
$search_term = $is_ajax_search ? sanitize_text_field( wp_unslash( $_REQUEST['query'] ) ) : $query->get( 's' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( woodmart_get_opt( 'search_synonyms' ) ) {
$search_with_synonyms = Search_With_Synonyms::get_instance();
$search = $search_with_synonyms->extend_query( $search, $search_term );
}
if ( apply_filters( 'woodmart_search_by_sku', woodmart_get_opt( 'search_by_sku' ) ) ) {
$search_with_sku = Search_With_Sku::get_instance();
$search = $search_with_sku->extend_query( $search, $search_term );
}
if (
woodmart_get_opt( 'search_by_product_categories' ) ||
woodmart_get_opt( 'search_by_product_tag' ) ||
woodmart_get_opt( 'search_by_product_attributes' ) ||
woodmart_get_opt( 'search_by_product_brands' )
) {
$search_with_taxonomies = Search_With_Taxonomies::get_instance();
$search = $search_with_taxonomies->extend_query( $search, $search_term );
}
}
return $search;
}
}
Search_Query::get_instance();