PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.1.4
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.1.4
2.7.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 All 43 releases
sellkit / includes / functions.php

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

128 lines 2.7 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 /**
48 * Delete option from options storage.
49 *
50 * @param string $option Option name.
51 *
52 * @return boolean False if value was not deleted and true if value was deleted.
53 */
54 function sellkit_delete_option( $option ) {
55 $options = get_option( 'sellkit', [] );
56
57 // Option not exist.
58 if ( ! isset( $options[ $option ] ) ) {
59 return false;
60 }
61
62 // Remove the option.
63 unset( $options[ $option ] );
64 update_option( 'sellkit', $options );
65
66 return true;
67 }
68
69 /**
70 * Get multi-select values.
71 *
72 * @since 1.1.0
73 * @param array $array Multi select data.
74 * @return array
75 */
76 function sellkit_get_multi_select_values( $array ) {
77 $values = [];
78
79 foreach ( $array as $item ) {
80 $values[] = $item['value'];
81 }
82
83 return $values;
84 }
85
86 /**
87 * Checks conditions validation.
88 *
89 * @since 1.1.0
90 * @SuppressWarnings(PHPMD.NPathComplexity)
91 * @param array $conditions Conditions data.
92 */
93 function sellkit_conditions_validation( $conditions ) {
94 $is_valid = true;
95 $condition_type = ! empty( $conditions[1]['type'] ) ? $conditions[1]['type'] : 'and';
96
97 if ( 'or' === $condition_type ) {
98 $is_valid = false;
99 }
100
101 foreach ( $conditions as $condition ) {
102 if ( is_array( $condition['condition_value'] ) && ! empty( $condition['condition_value'][0]['value'] ) ) {
103 $condition['condition_value'] = sellkit_get_multi_select_values( $condition['condition_value'] );
104 }
105
106 $result = sellkit_condition_match( $condition['condition_subject'], $condition['condition_operator'], $condition['condition_value'] );
107
108 if ( is_wp_error( $result ) ) {
109 continue;
110 }
111
112 if ( ! $result ) {
113 $is_valid = false;
114 }
115
116 if ( $result && 'or' === $condition_type ) {
117 $is_valid = true;
118 break;
119 }
120 }
121
122 if ( true === $is_valid ) {
123 return true;
124 }
125
126 return false;
127 }
128