PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 2.3.0
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v2.3.0
2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 1.8.1 All 42 releases
sellkit / includes / functions.php

functions.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 2.3.0, at includes/functions.php

177 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! function_exists( 'sellkit_update_option' ) ) {
3 /**
4 * Update option from options storage.
5 *
6 * @param string $option Option name.
7 * @param mixed $value Update value.
8 *
9 * @return boolean False if value was not updated and true if value was updated.
10 */
11 function sellkit_update_option( $option, $value ) {
12 $options = get_option( 'sellkit', [] );
13
14 // No need to update the same value.
15 if ( isset( $options[ $option ] ) && $value === $options[ $option ] ) {
16 return false;
17 }
18
19 // Update the option.
20 $options[ $option ] = $value;
21 update_option( 'sellkit', $options );
22
23 return true;
24 }
25 }
26
27 if ( ! function_exists( 'sellkit_get_option' ) ) {
28 /**
29 * Get option from options storage.
30 *
31 * @param string $option Option name.
32 * @param boolean $default Default value.
33 *
34 * @return mixed Value set for the option.
35 */
36 function sellkit_get_option( $option, $default = false ) {
37 $options = get_option( 'sellkit', [] );
38
39 if ( ! isset( $options[ $option ] ) ) {
40 return $default;
41 }
42
43 return $options[ $option ];
44 }
45 }
46
47 if ( ! function_exists( 'sellkit_htmlspecialchars' ) ) {
48 /**
49 * Sellkit html special chars is created because FILTER_SANITIZE_STRING is deprecated.
50 *
51 * @since 1.2.1
52 * @param string $input_type Type of input.
53 * @param string $param Parameter key.
54 */
55 function sellkit_htmlspecialchars( $input_type, $param ) {
56 $value = '';
57
58 if ( INPUT_GET === $input_type ) {
59 $value = ! empty( $_GET[ $param ] ) ? htmlspecialchars( $_GET[ $param ] ) : ''; //phpcs:ignore
60 }
61
62 if ( INPUT_POST === $input_type ) {
63 $value = ! empty( $_POST[ $param ] ) ? htmlspecialchars( $_POST[ $param ] ) : ''; //phpcs:ignore
64 }
65
66 if ( INPUT_COOKIE === $input_type ) {
67 $value = ! empty( $_COOKIE[ $param ] ) ? htmlspecialchars( $_COOKIE[ $param ] ) : ''; //phpcs:ignore
68 }
69
70 return $value;
71 }
72 }
73
74 /**
75 * Delete option from options storage.
76 *
77 * @param string $option Option name.
78 *
79 * @return boolean False if value was not deleted and true if value was deleted.
80 */
81 function sellkit_delete_option( $option ) {
82 $options = get_option( 'sellkit', [] );
83
84 // Option not exist.
85 if ( ! isset( $options[ $option ] ) ) {
86 return false;
87 }
88
89 // Remove the option.
90 unset( $options[ $option ] );
91 update_option( 'sellkit', $options );
92
93 return true;
94 }
95
96 /**
97 * Get multi-select values.
98 *
99 * @since 1.1.0
100 * @param array $array Multi select data.
101 * @return array
102 */
103 function sellkit_get_multi_select_values( $array ) {
104 $values = [];
105
106 foreach ( $array as $item ) {
107 $values[] = $item['value'];
108 }
109
110 return $values;
111 }
112
113 /**
114 * Checks conditions validation.
115 *
116 * @since 1.1.0
117 * @SuppressWarnings(PHPMD.NPathComplexity)
118 * @param array $conditions Conditions data.
119 */
120 function sellkit_conditions_validation( $conditions ) {
121 $is_valid = true;
122
123 if ( empty( $conditions ) ) {
124 return true;
125 }
126
127 $first_condition = reset( $conditions );
128 $condition_type = ! empty( $first_condition['type'] ) ? $first_condition['type'] : 'and';
129
130 if ( 'or' === $condition_type ) {
131 $is_valid = false;
132 }
133
134 foreach ( $conditions as $condition ) {
135 if ( is_array( $condition['condition_value'] ) && ! empty( $condition['condition_value'][0]['value'] ) ) {
136 $condition['condition_value'] = sellkit_get_multi_select_values( $condition['condition_value'] );
137 }
138
139 $result = sellkit_condition_match( $condition['condition_subject'], $condition['condition_operator'], $condition['condition_value'] );
140
141 if ( is_wp_error( $result ) ) {
142 continue;
143 }
144
145 if ( ! $result ) {
146 $is_valid = false;
147 }
148
149 if ( $result && 'or' === $condition_type ) {
150 $is_valid = true;
151 break;
152 }
153 }
154
155 if ( true === $is_valid ) {
156 return true;
157 }
158
159 return false;
160 }
161
162 if ( ! function_exists( 'array_key_last' ) ) {
163 /**
164 * Adds support for array_key_last function for lower php than 7.3.0 & WP lower than 5.9.0.
165 *
166 * @param array $array array.
167 */
168 function array_key_last( $array ) {
169 if ( empty( $array ) ) {
170 return null;
171 }
172
173 end( $array );
174 return key( $array );
175 }
176 }
177