public function search()
{
if (!isset($this->args['s'])) {
return;
}
$search = trim($this->args['s']);
if (empty($search)) {
return;
}
$is_email = is_email($search) || strpos($search, '@') !== false;
$is_user = strpos($search, strtolower('user:')) !== false;
if (!empty($this->args['search_in_notes'])) {
$notes = give_get_payment_notes(0, $search);
if (!empty($notes)) {
$payment_ids = wp_list_pluck((array) $notes, 'comment_post_ID');
$this->__set('post__in', $payment_ids);
}
$this->__unset('s');
} elseif ($is_email || strlen($search) == 32) {
$key = $is_email ? '_give_payment_user_email' : '_give_payment_purchase_key';
$search_meta = array('key' => $key, 'value' => $search, 'compare' => 'LIKE');
$this->__set('meta_query', $search_meta);
$this->__unset('s');
} elseif ($is_user) {
$search_meta = array('key' => '_give_payment_user_id', 'value' => trim(str_replace('user:', '', strtolower($search))));
$this->__set('meta_query', $search_meta);
if (give_get_option('enable_sequential')) {
$search_meta = array('key' => '_give_payment_number', 'value' => $search, 'compare' => 'LIKE');
$this->__set('meta_query', $search_meta);
$this->args['meta_query']['relation'] = 'OR';
}
$this->__unset('s');
} elseif (give_get_option('enable_sequential') && (false !== strpos($search, give_get_option('sequential_prefix')) || false !== strpos($search, give_get_option('sequential_postfix')))) {
$search_meta = array('key' => '_give_payment_number', 'value' => $search, 'compare' => 'LIKE');
$this->__set('meta_query', $search_meta);
$this->__unset('s');
} elseif (is_numeric($search)) {
$post = get_post($search);
if (is_object($post) && $post->post_type == 'give_payment') {
$arr = array();
$arr[] = $search;
$this->__set('post__in', $arr);
$this->__unset('s');
}
} elseif ('#' == substr($search, 0, 1)) {
$search = str_replace('#:', '', $search);
$search = str_replace('#', '', $search);
$this->__set('give_forms', $search);
$this->__unset('s');
} else {
$this->__set('s', $search);
}
}