| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 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.10/wp-content/plugins/woocommerce/src/Internal/Customers/ |
Upload File : |
<?php
declare( strict_types = 1 );
namespace Automattic\WooCommerce\Internal\Customers;
use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
use Automattic\WooCommerce\Utilities\OrderUtil;
/**
* Internal API for searching users/customers: no backward compatibility obligation.
*/
final class SearchService {
/**
* Searches users having the billing email (when applicable lookup orders as well) as specified and returns their id.
*
* @param string[] $emails Emails to search for.
*
* @return int[]
*/
public function find_user_ids_by_billing_email_for_coupons_usage_lookup( array $emails ): array {
$emails = array_unique( array_map( 'strtolower', array_map( 'sanitize_email', $emails ) ) );
$include_user_ids = array();
if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
global $wpdb;
// phpcs:disable WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$placeholders = implode( ', ', array_fill( 0, count( $emails ), '%s' ) );
$include_user_ids = $wpdb->get_col(
$wpdb->prepare(
"SELECT DISTINCT customer_id FROM %i WHERE billing_email IN ($placeholders)",
OrdersTableDataStore::get_orders_table_name(),
...$emails
)
);
// phpcs:enable
if ( array() === $include_user_ids ) {
return array();
}
}
$users_query = new \WP_User_Query(
array(
'fields' => 'ID',
'include' => $include_user_ids,
'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
array(
'key' => 'billing_email',
'value' => $emails,
'compare' => 'IN',
),
),
)
);
return array_map( 'intval', array_unique( $users_query->get_results() ) );
}
}