| 1 |
<?php |
| 2 |
defined( 'ABSPATH' ) || exit; |
| 3 |
|
| 4 |
use Sellkit\Contact_Segmentation\Conditions; |
| 5 |
|
| 6 |
/** |
| 7 |
* Condition match wrapper. |
| 8 |
* |
| 9 |
* @since 1.1.0 |
| 10 |
* @param string $condition_name Condition name. |
| 11 |
* @param string $operator_name Condition operator. |
| 12 |
* @param mixed $condition_value Condition value. |
| 13 |
*/ |
| 14 |
function sellkit_condition_match( $condition_name, $operator_name, $condition_value ) { |
| 15 |
$condition_value = apply_filters( "sellkit_cs_conditions_value_{$condition_name}", $condition_value ); |
| 16 |
|
| 17 |
if ( ! class_exists( 'Conditions' ) ) { |
| 18 |
require_once __DIR__ . '/conditions.php'; |
| 19 |
new Conditions(); |
| 20 |
} |
| 21 |
return Conditions::match( $condition_name, $operator_name, $condition_value ); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Get all of the products, it's searchable. |
| 26 |
* |
| 27 |
* @since 1.1.0 |
| 28 |
* @param string $input_value The input value for searching. |
| 29 |
*/ |
| 30 |
function sellkit_get_products( $input_value ) { |
| 31 |
if ( ! sellkit()->has_valid_dependencies() ) { |
| 32 |
return []; |
| 33 |
} |
| 34 |
|
| 35 |
$filtered_products = []; |
| 36 |
$args = [ |
| 37 |
'post_type' => 'product', |
| 38 |
'post_status' => 'any', |
| 39 |
's' => $input_value, |
| 40 |
]; |
| 41 |
|
| 42 |
$query = new \WP_Query( $args ); |
| 43 |
|
| 44 |
if ( $query->have_posts() ) { |
| 45 |
while ( $query->have_posts() ) { |
| 46 |
$query->the_post(); |
| 47 |
$filtered_products[ get_the_ID() ] = html_entity_decode( get_the_title() ); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
return $filtered_products; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Gets the products categories. |
| 56 |
* |
| 57 |
* @since 1.1.0 |
| 58 |
* @param string $taxonomy The taxonomy. |
| 59 |
* @param string $input_value The input value. |
| 60 |
*/ |
| 61 |
function sellkit_get_terms( $taxonomy, $input_value ) { |
| 62 |
if ( ! sellkit()->has_valid_dependencies() ) { |
| 63 |
return []; |
| 64 |
} |
| 65 |
|
| 66 |
$filtered_terms = []; |
| 67 |
|
| 68 |
$args = array( |
| 69 |
'taxonomy' => $taxonomy, |
| 70 |
'number' => 20, |
| 71 |
'orderby' => 'ID', |
| 72 |
'order' => 'DESC', |
| 73 |
'hide_empty' => false, |
| 74 |
'name__like' => $input_value, |
| 75 |
); |
| 76 |
|
| 77 |
$terms = get_terms( $args ); |
| 78 |
|
| 79 |
foreach ( $terms as $term ) { |
| 80 |
$filtered_terms[ $term->term_id ] = $term->name; |
| 81 |
} |
| 82 |
|
| 83 |
return $filtered_terms; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Sellkit filter array based on a specific string. |
| 88 |
* |
| 89 |
* @since 1.1.0 |
| 90 |
* @param array $array Array of data. |
| 91 |
* @param string $string Required string. |
| 92 |
*/ |
| 93 |
function sellkit_filter_array( $array, $string ) { |
| 94 |
return array_filter( $array, function ( $country ) use ( $string ) { |
| 95 |
return strpos( strtolower( $country ), strtolower( $string ) ) !== false; |
| 96 |
} ); |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Gets Ip. |
| 101 |
* |
| 102 |
* @since 1.1.0 |
| 103 |
* @return string |
| 104 |
* phpcs:disable WordPress.Security.ValidatedSanitizedInput |
| 105 |
*/ |
| 106 |
function sellkit_get_ip() { |
| 107 |
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
| 108 |
return $_SERVER['HTTP_CLIENT_IP']; |
| 109 |
} |
| 110 |
|
| 111 |
if ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
| 112 |
return $_SERVER['HTTP_X_FORWARDED_FOR']; |
| 113 |
} |
| 114 |
|
| 115 |
return $_SERVER['REMOTE_ADDR']; |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Gets contact's column value. |
| 120 |
* |
| 121 |
* @since 1.5.0 |
| 122 |
* @param string $column Column name. |
| 123 |
* @return mixed|string|void |
| 124 |
*/ |
| 125 |
function sellkit_get_funnel_contact_value_by_column( $column ) { |
| 126 |
$results = []; |
| 127 |
$contacts = sellkit()->db->get( 'funnel_contact', [ |
| 128 |
'user_id' => get_current_user_id() |
| 129 |
] ); |
| 130 |
|
| 131 |
foreach ( $contacts as $contact ) { |
| 132 |
if ( ! empty( $contact[ $column ] ) ) { |
| 133 |
$results[] = unserialize( $contact[ $column ] )[0]; // phpcs:ignore |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
return $results; |
| 138 |
} |
| 139 |
|