@@ -33,173 +33,173 @@ discard block |
||
33 | 33 | */ |
34 | 34 | class WPInv_Discount { |
35 | 35 | |
36 | - /** |
|
37 | - * Discount ID. |
|
38 | - * |
|
39 | - * @since 1.0.15 |
|
40 | - * @var integer|null |
|
41 | - */ |
|
42 | - public $ID = null; |
|
43 | - |
|
44 | - /** |
|
45 | - * Old discount status. |
|
46 | - * |
|
47 | - * @since 1.0.15 |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - public $old_status = 'draft'; |
|
36 | + /** |
|
37 | + * Discount ID. |
|
38 | + * |
|
39 | + * @since 1.0.15 |
|
40 | + * @var integer|null |
|
41 | + */ |
|
42 | + public $ID = null; |
|
43 | + |
|
44 | + /** |
|
45 | + * Old discount status. |
|
46 | + * |
|
47 | + * @since 1.0.15 |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + public $old_status = 'draft'; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Data array. |
|
54 | - * |
|
55 | - * @since 1.0.15 |
|
56 | - * @var array |
|
57 | - */ |
|
58 | - protected $data = array(); |
|
59 | - |
|
60 | - /** |
|
61 | - * Discount constructor. |
|
62 | - * |
|
63 | - * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
|
64 | - * @since 1.0.15 |
|
65 | - */ |
|
66 | - public function __construct( $discount = array() ) { |
|
52 | + /** |
|
53 | + * Data array. |
|
54 | + * |
|
55 | + * @since 1.0.15 |
|
56 | + * @var array |
|
57 | + */ |
|
58 | + protected $data = array(); |
|
59 | + |
|
60 | + /** |
|
61 | + * Discount constructor. |
|
62 | + * |
|
63 | + * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
|
64 | + * @since 1.0.15 |
|
65 | + */ |
|
66 | + public function __construct( $discount = array() ) { |
|
67 | 67 | |
68 | 68 | // If the discount is an instance of this class... |
69 | - if ( $discount instanceof WPInv_Discount ) { |
|
70 | - $this->init( $discount->data ); |
|
71 | - return; |
|
69 | + if ( $discount instanceof WPInv_Discount ) { |
|
70 | + $this->init( $discount->data ); |
|
71 | + return; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | // If the discount is an array of discount details... |
75 | 75 | if ( is_array( $discount ) ) { |
76 | - $this->init( $discount ); |
|
77 | - return; |
|
78 | - } |
|
76 | + $this->init( $discount ); |
|
77 | + return; |
|
78 | + } |
|
79 | 79 | |
80 | - // Try fetching the discount by its post id. |
|
81 | - $data = false; |
|
80 | + // Try fetching the discount by its post id. |
|
81 | + $data = false; |
|
82 | 82 | |
83 | - if ( ! empty( $discount ) && is_numeric( $discount ) ) { |
|
84 | - $discount = absint( $discount ); |
|
85 | - $data = self::get_data_by( 'id', $discount ); |
|
86 | - } |
|
87 | - |
|
88 | - if ( is_array( $data ) ) { |
|
89 | - $this->init( $data ); |
|
90 | - return; |
|
91 | - } |
|
83 | + if ( ! empty( $discount ) && is_numeric( $discount ) ) { |
|
84 | + $discount = absint( $discount ); |
|
85 | + $data = self::get_data_by( 'id', $discount ); |
|
86 | + } |
|
87 | + |
|
88 | + if ( is_array( $data ) ) { |
|
89 | + $this->init( $data ); |
|
90 | + return; |
|
91 | + } |
|
92 | 92 | |
93 | - // Try fetching the discount by its discount code. |
|
94 | - if ( ! empty( $discount ) && is_string( $discount ) ) { |
|
95 | - $data = self::get_data_by( 'discount_code', $discount ); |
|
96 | - } |
|
97 | - |
|
98 | - if ( is_array( $data ) ) { |
|
99 | - $this->init( $data ); |
|
100 | - return; |
|
101 | - } |
|
93 | + // Try fetching the discount by its discount code. |
|
94 | + if ( ! empty( $discount ) && is_string( $discount ) ) { |
|
95 | + $data = self::get_data_by( 'discount_code', $discount ); |
|
96 | + } |
|
97 | + |
|
98 | + if ( is_array( $data ) ) { |
|
99 | + $this->init( $data ); |
|
100 | + return; |
|
101 | + } |
|
102 | 102 | |
103 | - // If we are here then the discount does not exist. |
|
104 | - $this->init( array() ); |
|
105 | - } |
|
103 | + // If we are here then the discount does not exist. |
|
104 | + $this->init( array() ); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Sets up object properties |
|
109 | - * |
|
110 | - * @since 1.0.15 |
|
111 | - * @param array $data An array containing the discount's data |
|
112 | - */ |
|
113 | - public function init( $data ) { |
|
114 | - $data = self::sanitize_discount_data( $data ); |
|
115 | - $this->data = $data; |
|
116 | - $this->old_status = $data['status']; |
|
117 | - $this->ID = $data['ID']; |
|
118 | - } |
|
107 | + /** |
|
108 | + * Sets up object properties |
|
109 | + * |
|
110 | + * @since 1.0.15 |
|
111 | + * @param array $data An array containing the discount's data |
|
112 | + */ |
|
113 | + public function init( $data ) { |
|
114 | + $data = self::sanitize_discount_data( $data ); |
|
115 | + $this->data = $data; |
|
116 | + $this->old_status = $data['status']; |
|
117 | + $this->ID = $data['ID']; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Fetch a discount from the db/cache |
|
122 | - * |
|
123 | - * |
|
124 | - * @static |
|
125 | - * @param string $field The field to query against: 'ID', 'discount_code' |
|
126 | - * @param string|int $value The field value |
|
127 | - * @since 1.0.15 |
|
128 | - * @return array|bool array of discount details on success. False otherwise. |
|
129 | - */ |
|
130 | - public static function get_data_by( $field, $value ) { |
|
131 | - |
|
132 | - if ( 'id' == strtolower( $field ) ) { |
|
133 | - // Make sure the value is numeric to avoid casting objects, for example, |
|
134 | - // to int 1. |
|
135 | - if ( ! is_numeric( $value ) ) |
|
136 | - return false; |
|
137 | - $value = intval( $value ); |
|
138 | - if ( $value < 1 ) |
|
139 | - return false; |
|
140 | - } |
|
141 | - |
|
142 | - if ( ! $value || ! is_string( $field ) ) { |
|
143 | - return false; |
|
144 | - } |
|
120 | + /** |
|
121 | + * Fetch a discount from the db/cache |
|
122 | + * |
|
123 | + * |
|
124 | + * @static |
|
125 | + * @param string $field The field to query against: 'ID', 'discount_code' |
|
126 | + * @param string|int $value The field value |
|
127 | + * @since 1.0.15 |
|
128 | + * @return array|bool array of discount details on success. False otherwise. |
|
129 | + */ |
|
130 | + public static function get_data_by( $field, $value ) { |
|
131 | + |
|
132 | + if ( 'id' == strtolower( $field ) ) { |
|
133 | + // Make sure the value is numeric to avoid casting objects, for example, |
|
134 | + // to int 1. |
|
135 | + if ( ! is_numeric( $value ) ) |
|
136 | + return false; |
|
137 | + $value = intval( $value ); |
|
138 | + if ( $value < 1 ) |
|
139 | + return false; |
|
140 | + } |
|
141 | + |
|
142 | + if ( ! $value || ! is_string( $field ) ) { |
|
143 | + return false; |
|
144 | + } |
|
145 | 145 | |
146 | - $field = trim( $field ); |
|
147 | - |
|
148 | - // prepare query args |
|
149 | - switch ( strtolower( $field ) ) { |
|
150 | - case 'id': |
|
151 | - $discount_id = $value; |
|
152 | - $args = array( 'include' => array( $value ) ); |
|
153 | - break; |
|
154 | - case 'discount_code': |
|
155 | - case 'code': |
|
156 | - $value = trim( $value ); |
|
157 | - $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' ); |
|
158 | - $args = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value ); |
|
159 | - break; |
|
160 | - case 'name': |
|
161 | - $discount_id = 0; |
|
162 | - $args = array( 'name' => trim( $value ) ); |
|
163 | - break; |
|
164 | - default: |
|
165 | - $args = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value ); |
|
166 | - if ( ! is_array( $args ) ) { |
|
167 | - return apply_filters( "wpinv_discount_get_data_by_$field", false, $value ); |
|
168 | - } |
|
169 | - |
|
170 | - } |
|
171 | - |
|
172 | - // Check if there is a cached value. |
|
173 | - if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) { |
|
174 | - return $discount; |
|
175 | - } |
|
176 | - |
|
177 | - $args = array_merge( |
|
178 | - $args, |
|
179 | - array( |
|
180 | - 'post_type' => 'wpi_discount', |
|
181 | - 'posts_per_page' => 1, |
|
182 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
183 | - ) |
|
184 | - ); |
|
185 | - |
|
186 | - $discount = get_posts( $args ); |
|
146 | + $field = trim( $field ); |
|
147 | + |
|
148 | + // prepare query args |
|
149 | + switch ( strtolower( $field ) ) { |
|
150 | + case 'id': |
|
151 | + $discount_id = $value; |
|
152 | + $args = array( 'include' => array( $value ) ); |
|
153 | + break; |
|
154 | + case 'discount_code': |
|
155 | + case 'code': |
|
156 | + $value = trim( $value ); |
|
157 | + $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' ); |
|
158 | + $args = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value ); |
|
159 | + break; |
|
160 | + case 'name': |
|
161 | + $discount_id = 0; |
|
162 | + $args = array( 'name' => trim( $value ) ); |
|
163 | + break; |
|
164 | + default: |
|
165 | + $args = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value ); |
|
166 | + if ( ! is_array( $args ) ) { |
|
167 | + return apply_filters( "wpinv_discount_get_data_by_$field", false, $value ); |
|
168 | + } |
|
169 | + |
|
170 | + } |
|
171 | + |
|
172 | + // Check if there is a cached value. |
|
173 | + if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) { |
|
174 | + return $discount; |
|
175 | + } |
|
176 | + |
|
177 | + $args = array_merge( |
|
178 | + $args, |
|
179 | + array( |
|
180 | + 'post_type' => 'wpi_discount', |
|
181 | + 'posts_per_page' => 1, |
|
182 | + 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
183 | + ) |
|
184 | + ); |
|
185 | + |
|
186 | + $discount = get_posts( $args ); |
|
187 | 187 | |
188 | - if( empty( $discount ) ) { |
|
189 | - return false; |
|
190 | - } |
|
188 | + if( empty( $discount ) ) { |
|
189 | + return false; |
|
190 | + } |
|
191 | 191 | |
192 | - $discount = $discount[0]; |
|
192 | + $discount = $discount[0]; |
|
193 | 193 | |
194 | - // Prepare the return data. |
|
195 | - $return = array( |
|
194 | + // Prepare the return data. |
|
195 | + $return = array( |
|
196 | 196 | 'ID' => $discount->ID, |
197 | 197 | 'code' => get_post_meta( $discount->ID, '_wpi_discount_code', true ), |
198 | 198 | 'amount' => get_post_meta( $discount->ID, '_wpi_discount_amount', true ), |
199 | 199 | 'date_created' => $discount->post_date, |
200 | - 'date_modified' => $discount->post_modified, |
|
201 | - 'status' => $discount->post_status, |
|
202 | - 'start' => get_post_meta( $discount->ID, '_wpi_discount_start', true ), |
|
200 | + 'date_modified' => $discount->post_modified, |
|
201 | + 'status' => $discount->post_status, |
|
202 | + 'start' => get_post_meta( $discount->ID, '_wpi_discount_start', true ), |
|
203 | 203 | 'expiration' => get_post_meta( $discount->ID, '_wpi_discount_expiration', true ), |
204 | 204 | 'type' => get_post_meta( $discount->ID, '_wpi_discount_type', true ), |
205 | 205 | 'description' => $discount->post_excerpt, |
@@ -213,38 +213,38 @@ discard block |
||
213 | 213 | 'max_total' => get_post_meta( $discount->ID, '_wpi_discount_max_total', true ), |
214 | 214 | ); |
215 | 215 | |
216 | - $return = self::sanitize_discount_data( $return ); |
|
217 | - $return = apply_filters( 'wpinv_discount_properties', $return ); |
|
216 | + $return = self::sanitize_discount_data( $return ); |
|
217 | + $return = apply_filters( 'wpinv_discount_properties', $return ); |
|
218 | 218 | |
219 | - // Update the cache with our data |
|
220 | - wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' ); |
|
221 | - wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' ); |
|
219 | + // Update the cache with our data |
|
220 | + wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' ); |
|
221 | + wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' ); |
|
222 | 222 | |
223 | - return $return; |
|
224 | - } |
|
223 | + return $return; |
|
224 | + } |
|
225 | 225 | |
226 | - /** |
|
227 | - * Sanitizes discount data |
|
228 | - * |
|
229 | - * @static |
|
230 | - * @since 1.0.15 |
|
231 | - * @access public |
|
232 | - * |
|
233 | - * @return array the sanitized data |
|
234 | - */ |
|
235 | - public static function sanitize_discount_data( $data ) { |
|
226 | + /** |
|
227 | + * Sanitizes discount data |
|
228 | + * |
|
229 | + * @static |
|
230 | + * @since 1.0.15 |
|
231 | + * @access public |
|
232 | + * |
|
233 | + * @return array the sanitized data |
|
234 | + */ |
|
235 | + public static function sanitize_discount_data( $data ) { |
|
236 | 236 | |
237 | - $allowed_discount_types = array_keys( wpinv_get_discount_types() ); |
|
237 | + $allowed_discount_types = array_keys( wpinv_get_discount_types() ); |
|
238 | 238 | |
239 | - $return = array( |
|
239 | + $return = array( |
|
240 | 240 | 'ID' => null, |
241 | 241 | 'code' => '', |
242 | 242 | 'amount' => 0, |
243 | 243 | 'date_created' => current_time('mysql'), |
244 | 244 | 'date_modified' => current_time('mysql'), |
245 | - 'expiration' => null, |
|
246 | - 'start' => current_time('mysql'), |
|
247 | - 'status' => 'draft', |
|
245 | + 'expiration' => null, |
|
246 | + 'start' => current_time('mysql'), |
|
247 | + 'status' => 'draft', |
|
248 | 248 | 'type' => 'percent', |
249 | 249 | 'description' => '', |
250 | 250 | 'uses' => 0, |
@@ -254,426 +254,426 @@ discard block |
||
254 | 254 | 'max_uses' => 0, |
255 | 255 | 'is_recurring' => false, |
256 | 256 | 'min_total' => '', |
257 | - 'max_total' => '', |
|
258 | - ); |
|
257 | + 'max_total' => '', |
|
258 | + ); |
|
259 | 259 | |
260 | 260 | |
261 | - // Arrays only please. |
|
262 | - if ( ! is_array( $data ) ) { |
|
261 | + // Arrays only please. |
|
262 | + if ( ! is_array( $data ) ) { |
|
263 | 263 | return $return; |
264 | 264 | } |
265 | 265 | |
266 | - // If an id is provided, ensure it is a valid discount. |
|
266 | + // If an id is provided, ensure it is a valid discount. |
|
267 | 267 | if ( ! empty( $data['ID'] ) && ( ! is_numeric( $data['ID'] ) || 'wpi_discount' !== get_post_type( $data['ID'] ) ) ) { |
268 | 268 | return $return; |
269 | - } |
|
269 | + } |
|
270 | 270 | |
271 | 271 | $return = array_merge( $return, $data ); |
272 | 272 | |
273 | 273 | // Sanitize some keys. |
274 | 274 | $return['amount'] = wpinv_sanitize_amount( $return['amount'] ); |
275 | - $return['is_single_use'] = (bool) $return['is_single_use']; |
|
276 | - $return['is_recurring'] = (bool) $return['is_recurring']; |
|
277 | - $return['uses'] = (int) $return['uses']; |
|
278 | - $return['max_uses'] = (int) $return['max_uses']; |
|
279 | - $return['min_total'] = wpinv_sanitize_amount( $return['min_total'] ); |
|
275 | + $return['is_single_use'] = (bool) $return['is_single_use']; |
|
276 | + $return['is_recurring'] = (bool) $return['is_recurring']; |
|
277 | + $return['uses'] = (int) $return['uses']; |
|
278 | + $return['max_uses'] = (int) $return['max_uses']; |
|
279 | + $return['min_total'] = wpinv_sanitize_amount( $return['min_total'] ); |
|
280 | 280 | $return['max_total'] = wpinv_sanitize_amount( $return['max_total'] ); |
281 | 281 | |
282 | - // Trim all values. |
|
283 | - $return = wpinv_clean( $return ); |
|
282 | + // Trim all values. |
|
283 | + $return = wpinv_clean( $return ); |
|
284 | 284 | |
285 | - // Ensure the discount type is supported. |
|
285 | + // Ensure the discount type is supported. |
|
286 | 286 | if ( ! in_array( $return['type'], $allowed_discount_types, true ) ) { |
287 | 287 | $return['type'] = 'percent'; |
288 | - } |
|
289 | - $return['type_name'] = wpinv_get_discount_type_name( $return['type'] ); |
|
288 | + } |
|
289 | + $return['type_name'] = wpinv_get_discount_type_name( $return['type'] ); |
|
290 | 290 | |
291 | - // Do not offer more than a 100% discount. |
|
292 | - if ( $return['type'] == 'percent' && (float) $return['amount'] > 100 ) { |
|
293 | - $return['amount'] = 100; |
|
294 | - } |
|
295 | - |
|
296 | - // Format dates. |
|
297 | - foreach( wpinv_parse_list( 'date_created date_modified expiration start') as $prop ) { |
|
298 | - if( ! empty( $return[$prop] ) ) { |
|
299 | - $return[$prop] = date_i18n( 'Y-m-d H:i:s', strtotime( $return[$prop] ) ); |
|
300 | - } |
|
301 | - } |
|
302 | - |
|
303 | - // Formart items. |
|
304 | - foreach( array( 'excluded_items', 'items' ) as $prop ) { |
|
305 | - |
|
306 | - if( ! empty( $return[$prop] ) ) { |
|
307 | - // Ensure that the property is an array of non-empty integers. |
|
308 | - $return[$prop] = array_filter( array_map( 'intval', wpinv_parse_list( $return[$prop] ) ) ); |
|
309 | - } else { |
|
310 | - $return[$prop] = array(); |
|
311 | - } |
|
312 | - |
|
313 | - } |
|
291 | + // Do not offer more than a 100% discount. |
|
292 | + if ( $return['type'] == 'percent' && (float) $return['amount'] > 100 ) { |
|
293 | + $return['amount'] = 100; |
|
294 | + } |
|
295 | + |
|
296 | + // Format dates. |
|
297 | + foreach( wpinv_parse_list( 'date_created date_modified expiration start') as $prop ) { |
|
298 | + if( ! empty( $return[$prop] ) ) { |
|
299 | + $return[$prop] = date_i18n( 'Y-m-d H:i:s', strtotime( $return[$prop] ) ); |
|
300 | + } |
|
301 | + } |
|
302 | + |
|
303 | + // Formart items. |
|
304 | + foreach( array( 'excluded_items', 'items' ) as $prop ) { |
|
305 | + |
|
306 | + if( ! empty( $return[$prop] ) ) { |
|
307 | + // Ensure that the property is an array of non-empty integers. |
|
308 | + $return[$prop] = array_filter( array_map( 'intval', wpinv_parse_list( $return[$prop] ) ) ); |
|
309 | + } else { |
|
310 | + $return[$prop] = array(); |
|
311 | + } |
|
312 | + |
|
313 | + } |
|
314 | 314 | |
315 | - return apply_filters( 'wpinv_sanitize_discount_data', $return, $data ); |
|
316 | - } |
|
315 | + return apply_filters( 'wpinv_sanitize_discount_data', $return, $data ); |
|
316 | + } |
|
317 | 317 | |
318 | - /** |
|
319 | - * Magic method for checking the existence of a certain custom field. |
|
320 | - * |
|
321 | - * @since 1.0.15 |
|
322 | - * @access public |
|
323 | - * |
|
324 | - * @return bool Whether the given discount field is set. |
|
325 | - */ |
|
326 | - public function __isset( $key ){ |
|
327 | - return isset( $this->data[$key] ) || method_exists( $this, "get_$key"); |
|
328 | - } |
|
318 | + /** |
|
319 | + * Magic method for checking the existence of a certain custom field. |
|
320 | + * |
|
321 | + * @since 1.0.15 |
|
322 | + * @access public |
|
323 | + * |
|
324 | + * @return bool Whether the given discount field is set. |
|
325 | + */ |
|
326 | + public function __isset( $key ){ |
|
327 | + return isset( $this->data[$key] ) || method_exists( $this, "get_$key"); |
|
328 | + } |
|
329 | 329 | |
330 | - /** |
|
331 | - * Magic method for accessing discount properties. |
|
332 | - * |
|
333 | - * @since 1.0.15 |
|
334 | - * @access public |
|
335 | - * |
|
336 | - * @param string $key Discount data to retrieve |
|
337 | - * @return mixed Value of the given discount property (if set). |
|
338 | - */ |
|
339 | - public function __get( $key ) { |
|
340 | - return $this->get( $key ); |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Magic method for accessing discount properties. |
|
345 | - * |
|
346 | - * @since 1.0.15 |
|
347 | - * @access public |
|
348 | - * |
|
349 | - * @param string $key Discount data to retrieve |
|
350 | - * @return mixed Value of the given discount property (if set). |
|
351 | - */ |
|
352 | - public function get( $key ) { |
|
330 | + /** |
|
331 | + * Magic method for accessing discount properties. |
|
332 | + * |
|
333 | + * @since 1.0.15 |
|
334 | + * @access public |
|
335 | + * |
|
336 | + * @param string $key Discount data to retrieve |
|
337 | + * @return mixed Value of the given discount property (if set). |
|
338 | + */ |
|
339 | + public function __get( $key ) { |
|
340 | + return $this->get( $key ); |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * Magic method for accessing discount properties. |
|
345 | + * |
|
346 | + * @since 1.0.15 |
|
347 | + * @access public |
|
348 | + * |
|
349 | + * @param string $key Discount data to retrieve |
|
350 | + * @return mixed Value of the given discount property (if set). |
|
351 | + */ |
|
352 | + public function get( $key ) { |
|
353 | 353 | |
354 | - if ( $key == 'id' ) { |
|
355 | - $key = 'ID'; |
|
356 | - } |
|
354 | + if ( $key == 'id' ) { |
|
355 | + $key = 'ID'; |
|
356 | + } |
|
357 | 357 | |
358 | - if( method_exists( $this, "get_$key") ) { |
|
359 | - $value = call_user_func( array( $this, "get_$key" ) ); |
|
360 | - } else if( isset( $this->data[$key] ) ) { |
|
361 | - $value = $this->data[$key]; |
|
362 | - } else { |
|
363 | - $value = null; |
|
364 | - } |
|
358 | + if( method_exists( $this, "get_$key") ) { |
|
359 | + $value = call_user_func( array( $this, "get_$key" ) ); |
|
360 | + } else if( isset( $this->data[$key] ) ) { |
|
361 | + $value = $this->data[$key]; |
|
362 | + } else { |
|
363 | + $value = null; |
|
364 | + } |
|
365 | 365 | |
366 | - /** |
|
367 | - * Filters a discount's property value. |
|
368 | - * |
|
369 | - * The dynamic part ($key) can be any property name e.g items, code, type etc. |
|
370 | - * |
|
371 | - * @param mixed $value The property's value. |
|
372 | - * @param int $ID The discount's ID. |
|
373 | - * @param WPInv_Discount $discount The discount object. |
|
374 | - * @param string $code The discount's discount code. |
|
375 | - * @param array $data The discount's data array. |
|
376 | - */ |
|
377 | - return apply_filters( "wpinv_get_discount_{$key}", $value, $this->ID, $this, $this->data['code'], $this->data ); |
|
378 | - |
|
379 | - } |
|
366 | + /** |
|
367 | + * Filters a discount's property value. |
|
368 | + * |
|
369 | + * The dynamic part ($key) can be any property name e.g items, code, type etc. |
|
370 | + * |
|
371 | + * @param mixed $value The property's value. |
|
372 | + * @param int $ID The discount's ID. |
|
373 | + * @param WPInv_Discount $discount The discount object. |
|
374 | + * @param string $code The discount's discount code. |
|
375 | + * @param array $data The discount's data array. |
|
376 | + */ |
|
377 | + return apply_filters( "wpinv_get_discount_{$key}", $value, $this->ID, $this, $this->data['code'], $this->data ); |
|
378 | + |
|
379 | + } |
|
380 | 380 | |
381 | - /** |
|
382 | - * Magic method for setting discount fields. |
|
383 | - * |
|
384 | - * This method does not update custom fields in the database. |
|
385 | - * |
|
386 | - * @since 1.0.15 |
|
387 | - * @access public |
|
388 | - * |
|
389 | - */ |
|
390 | - public function __set( $key, $value ) { |
|
381 | + /** |
|
382 | + * Magic method for setting discount fields. |
|
383 | + * |
|
384 | + * This method does not update custom fields in the database. |
|
385 | + * |
|
386 | + * @since 1.0.15 |
|
387 | + * @access public |
|
388 | + * |
|
389 | + */ |
|
390 | + public function __set( $key, $value ) { |
|
391 | 391 | |
392 | - if ( 'id' == strtolower( $key ) ) { |
|
392 | + if ( 'id' == strtolower( $key ) ) { |
|
393 | 393 | |
394 | - $this->ID = $value; |
|
395 | - $this->data['ID'] = $value; |
|
396 | - return; |
|
394 | + $this->ID = $value; |
|
395 | + $this->data['ID'] = $value; |
|
396 | + return; |
|
397 | 397 | |
398 | - } |
|
398 | + } |
|
399 | 399 | |
400 | - /** |
|
401 | - * Filters a discount's property value before it is saved. |
|
402 | - * |
|
403 | - * |
|
404 | - * |
|
405 | - * The dynamic part ($key) can be any property name e.g items, code, type etc. |
|
406 | - * |
|
407 | - * @param mixed $value The property's value. |
|
408 | - * @param int $ID The discount's ID. |
|
409 | - * @param WPInv_Discount $discount The discount object. |
|
410 | - * @param string $code The discount's discount code. |
|
411 | - * @param array $data The discount's data array. |
|
412 | - */ |
|
413 | - $value = apply_filters( "wpinv_set_discount_{$key}", $value, $this->ID, $this, $this->code, $this->data ); |
|
414 | - |
|
415 | - if( method_exists( $this, "set_$key") ) { |
|
416 | - call_user_func( array( $this, "set_$key" ), $value ); |
|
417 | - } else { |
|
418 | - $this->data[$key] = $value; |
|
419 | - } |
|
400 | + /** |
|
401 | + * Filters a discount's property value before it is saved. |
|
402 | + * |
|
403 | + * |
|
404 | + * |
|
405 | + * The dynamic part ($key) can be any property name e.g items, code, type etc. |
|
406 | + * |
|
407 | + * @param mixed $value The property's value. |
|
408 | + * @param int $ID The discount's ID. |
|
409 | + * @param WPInv_Discount $discount The discount object. |
|
410 | + * @param string $code The discount's discount code. |
|
411 | + * @param array $data The discount's data array. |
|
412 | + */ |
|
413 | + $value = apply_filters( "wpinv_set_discount_{$key}", $value, $this->ID, $this, $this->code, $this->data ); |
|
414 | + |
|
415 | + if( method_exists( $this, "set_$key") ) { |
|
416 | + call_user_func( array( $this, "set_$key" ), $value ); |
|
417 | + } else { |
|
418 | + $this->data[$key] = $value; |
|
419 | + } |
|
420 | 420 | |
421 | - } |
|
421 | + } |
|
422 | 422 | |
423 | - /** |
|
424 | - * Saves (or updates) a discount to the database |
|
425 | - * |
|
426 | - * @since 1.0.15 |
|
427 | - * @access public |
|
428 | - * @return bool |
|
429 | - * |
|
430 | - */ |
|
431 | - public function save(){ |
|
423 | + /** |
|
424 | + * Saves (or updates) a discount to the database |
|
425 | + * |
|
426 | + * @since 1.0.15 |
|
427 | + * @access public |
|
428 | + * @return bool |
|
429 | + * |
|
430 | + */ |
|
431 | + public function save(){ |
|
432 | 432 | |
433 | - $data = self::sanitize_discount_data( $this->data ); |
|
433 | + $data = self::sanitize_discount_data( $this->data ); |
|
434 | 434 | |
435 | - // Should we create a new post? |
|
436 | - if( ! $data[ 'ID' ] ) { |
|
435 | + // Should we create a new post? |
|
436 | + if( ! $data[ 'ID' ] ) { |
|
437 | 437 | |
438 | - $id = wp_insert_post( array( |
|
439 | - 'post_status' => $data['status'], |
|
440 | - 'post_type' => 'wpi_discount', |
|
441 | - 'post_excerpt' => $data['description'], |
|
442 | - ) ); |
|
438 | + $id = wp_insert_post( array( |
|
439 | + 'post_status' => $data['status'], |
|
440 | + 'post_type' => 'wpi_discount', |
|
441 | + 'post_excerpt' => $data['description'], |
|
442 | + ) ); |
|
443 | 443 | |
444 | - if( empty( $id ) ) { |
|
445 | - return false; |
|
446 | - } |
|
444 | + if( empty( $id ) ) { |
|
445 | + return false; |
|
446 | + } |
|
447 | 447 | |
448 | - $data[ 'ID' ] = (int) $id; |
|
449 | - $this->ID = $data[ 'ID' ]; |
|
450 | - $this->data['ID'] = $data[ 'ID' ]; |
|
448 | + $data[ 'ID' ] = (int) $id; |
|
449 | + $this->ID = $data[ 'ID' ]; |
|
450 | + $this->data['ID'] = $data[ 'ID' ]; |
|
451 | 451 | |
452 | - } else { |
|
453 | - $this->update_status( $data['status'] ); |
|
454 | - } |
|
452 | + } else { |
|
453 | + $this->update_status( $data['status'] ); |
|
454 | + } |
|
455 | 455 | |
456 | - $meta = apply_filters( 'wpinv_update_discount', $data, $this->ID, $this ); |
|
456 | + $meta = apply_filters( 'wpinv_update_discount', $data, $this->ID, $this ); |
|
457 | 457 | |
458 | - do_action( 'wpinv_pre_update_discount', $meta, $this->ID, $this ); |
|
458 | + do_action( 'wpinv_pre_update_discount', $meta, $this->ID, $this ); |
|
459 | 459 | |
460 | - foreach( wpinv_parse_list( 'ID date_created date_modified status description type_name' ) as $prop ) { |
|
461 | - if ( isset( $meta[$prop] ) ) { |
|
462 | - unset( $meta[$prop] ); |
|
463 | - } |
|
464 | - } |
|
460 | + foreach( wpinv_parse_list( 'ID date_created date_modified status description type_name' ) as $prop ) { |
|
461 | + if ( isset( $meta[$prop] ) ) { |
|
462 | + unset( $meta[$prop] ); |
|
463 | + } |
|
464 | + } |
|
465 | 465 | |
466 | - if( isset( $meta['uses'] ) && empty( $meta['uses'] ) ) { |
|
467 | - unset( $meta['uses'] ); |
|
468 | - } |
|
466 | + if( isset( $meta['uses'] ) && empty( $meta['uses'] ) ) { |
|
467 | + unset( $meta['uses'] ); |
|
468 | + } |
|
469 | 469 | |
470 | - // Save the metadata. |
|
471 | - foreach( $meta as $key => $value ) { |
|
472 | - update_post_meta( $this->ID, "_wpi_discount_$key", $value ); |
|
473 | - } |
|
470 | + // Save the metadata. |
|
471 | + foreach( $meta as $key => $value ) { |
|
472 | + update_post_meta( $this->ID, "_wpi_discount_$key", $value ); |
|
473 | + } |
|
474 | 474 | |
475 | - $this->refresh(); |
|
475 | + $this->refresh(); |
|
476 | 476 | |
477 | - do_action( 'wpinv_post_update_discount', $meta, $this->ID ); |
|
477 | + do_action( 'wpinv_post_update_discount', $meta, $this->ID ); |
|
478 | 478 | |
479 | - return true; |
|
480 | - } |
|
479 | + return true; |
|
480 | + } |
|
481 | 481 | |
482 | - /** |
|
483 | - * Refreshes the discount data. |
|
484 | - * |
|
485 | - * @since 1.0.15 |
|
486 | - * @access public |
|
487 | - * @return bool |
|
488 | - * |
|
489 | - */ |
|
490 | - public function refresh(){ |
|
482 | + /** |
|
483 | + * Refreshes the discount data. |
|
484 | + * |
|
485 | + * @since 1.0.15 |
|
486 | + * @access public |
|
487 | + * @return bool |
|
488 | + * |
|
489 | + */ |
|
490 | + public function refresh(){ |
|
491 | 491 | |
492 | - // Empty the cache for this discount. |
|
493 | - wp_cache_delete( $this->ID, 'WPInv_Discounts' ); |
|
494 | - wp_cache_delete( $this->get( 'code' ), 'WPInv_Discount_Codes' ); |
|
492 | + // Empty the cache for this discount. |
|
493 | + wp_cache_delete( $this->ID, 'WPInv_Discounts' ); |
|
494 | + wp_cache_delete( $this->get( 'code' ), 'WPInv_Discount_Codes' ); |
|
495 | 495 | |
496 | - $data = self::get_data_by( 'id', $this->ID ); |
|
497 | - if( is_array( $data ) ) { |
|
498 | - $this->init( $data ); |
|
499 | - } else { |
|
500 | - $this->init( array() ); |
|
501 | - } |
|
496 | + $data = self::get_data_by( 'id', $this->ID ); |
|
497 | + if( is_array( $data ) ) { |
|
498 | + $this->init( $data ); |
|
499 | + } else { |
|
500 | + $this->init( array() ); |
|
501 | + } |
|
502 | 502 | |
503 | - } |
|
503 | + } |
|
504 | 504 | |
505 | - /** |
|
506 | - * Saves (or updates) a discount to the database |
|
507 | - * |
|
508 | - * @since 1.0.15 |
|
509 | - * @access public |
|
510 | - * @return bool |
|
511 | - * |
|
512 | - */ |
|
513 | - public function update_status( $status = 'publish' ){ |
|
505 | + /** |
|
506 | + * Saves (or updates) a discount to the database |
|
507 | + * |
|
508 | + * @since 1.0.15 |
|
509 | + * @access public |
|
510 | + * @return bool |
|
511 | + * |
|
512 | + */ |
|
513 | + public function update_status( $status = 'publish' ){ |
|
514 | 514 | |
515 | 515 | |
516 | - if ( $this->exists() && $this->old_status != $status ) { |
|
516 | + if ( $this->exists() && $this->old_status != $status ) { |
|
517 | 517 | |
518 | - do_action( 'wpinv_pre_update_discount_status', $this->ID, $this->old_status, $status ); |
|
519 | - $updated = wp_update_post( array( 'ID' => $this->ID, 'post_status' => $status ) ); |
|
520 | - do_action( 'wpinv_post_update_discount_status', $this->ID, $this->old_status, $status ); |
|
518 | + do_action( 'wpinv_pre_update_discount_status', $this->ID, $this->old_status, $status ); |
|
519 | + $updated = wp_update_post( array( 'ID' => $this->ID, 'post_status' => $status ) ); |
|
520 | + do_action( 'wpinv_post_update_discount_status', $this->ID, $this->old_status, $status ); |
|
521 | 521 | |
522 | - $this->refresh(); |
|
522 | + $this->refresh(); |
|
523 | 523 | |
524 | - return $updated !== 0; |
|
524 | + return $updated !== 0; |
|
525 | 525 | |
526 | - } |
|
526 | + } |
|
527 | 527 | |
528 | - return false; |
|
529 | - } |
|
528 | + return false; |
|
529 | + } |
|
530 | 530 | |
531 | 531 | |
532 | - /** |
|
533 | - * Checks whether a discount exists in the database or not |
|
534 | - * |
|
535 | - * @since 1.0.15 |
|
536 | - */ |
|
537 | - public function exists(){ |
|
538 | - return ! empty( $this->ID ); |
|
539 | - } |
|
532 | + /** |
|
533 | + * Checks whether a discount exists in the database or not |
|
534 | + * |
|
535 | + * @since 1.0.15 |
|
536 | + */ |
|
537 | + public function exists(){ |
|
538 | + return ! empty( $this->ID ); |
|
539 | + } |
|
540 | 540 | |
541 | - // Boolean methods |
|
541 | + // Boolean methods |
|
542 | 542 | |
543 | - /** |
|
544 | - * Checks the discount type. |
|
545 | - * |
|
546 | - * |
|
547 | - * @param string $type the discount type to check against |
|
548 | - * @since 1.0.15 |
|
549 | - * @return bool |
|
550 | - */ |
|
551 | - public function is_type( $type ) { |
|
552 | - return $this->type == $type; |
|
553 | - } |
|
543 | + /** |
|
544 | + * Checks the discount type. |
|
545 | + * |
|
546 | + * |
|
547 | + * @param string $type the discount type to check against |
|
548 | + * @since 1.0.15 |
|
549 | + * @return bool |
|
550 | + */ |
|
551 | + public function is_type( $type ) { |
|
552 | + return $this->type == $type; |
|
553 | + } |
|
554 | 554 | |
555 | - /** |
|
556 | - * Checks whether the discount is published or not |
|
557 | - * |
|
558 | - * @since 1.0.15 |
|
559 | - * @return bool |
|
560 | - */ |
|
561 | - public function is_active() { |
|
562 | - return $this->status == 'publish'; |
|
563 | - } |
|
555 | + /** |
|
556 | + * Checks whether the discount is published or not |
|
557 | + * |
|
558 | + * @since 1.0.15 |
|
559 | + * @return bool |
|
560 | + */ |
|
561 | + public function is_active() { |
|
562 | + return $this->status == 'publish'; |
|
563 | + } |
|
564 | 564 | |
565 | - /** |
|
566 | - * Checks whether the discount is has exided the usage limit or not |
|
567 | - * |
|
568 | - * @since 1.0.15 |
|
569 | - * @return bool |
|
570 | - */ |
|
571 | - public function has_exceeded_limit() { |
|
572 | - if( empty( $this->max_uses ) || empty( $this->uses ) ) { |
|
573 | - return false ; |
|
574 | - } |
|
565 | + /** |
|
566 | + * Checks whether the discount is has exided the usage limit or not |
|
567 | + * |
|
568 | + * @since 1.0.15 |
|
569 | + * @return bool |
|
570 | + */ |
|
571 | + public function has_exceeded_limit() { |
|
572 | + if( empty( $this->max_uses ) || empty( $this->uses ) ) { |
|
573 | + return false ; |
|
574 | + } |
|
575 | 575 | |
576 | - $exceeded = $this->uses >= $this->max_uses; |
|
577 | - return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->ID, $this, $this->code ); |
|
578 | - } |
|
576 | + $exceeded = $this->uses >= $this->max_uses; |
|
577 | + return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->ID, $this, $this->code ); |
|
578 | + } |
|
579 | 579 | |
580 | - /** |
|
581 | - * Checks if the discount is expired |
|
582 | - * |
|
583 | - * @since 1.0.15 |
|
584 | - * @return bool |
|
585 | - */ |
|
586 | - public function is_expired() { |
|
587 | - $expired = empty ( $this->expiration ) ? false : current_time( 'timestamp' ) > strtotime( $this->expiration ); |
|
588 | - return apply_filters( 'wpinv_is_discount_expired', $expired, $this->ID, $this, $this->code ); |
|
589 | - } |
|
590 | - |
|
591 | - /** |
|
592 | - * Checks the discount start date. |
|
593 | - * |
|
594 | - * @since 1.0.15 |
|
595 | - * @return bool |
|
596 | - */ |
|
597 | - public function has_started() { |
|
598 | - $started = empty ( $this->start ) ? true : current_time( 'timestamp' ) > strtotime( $this->start ); |
|
599 | - return apply_filters( 'wpinv_is_discount_started', $started, $this->ID, $this, $this->code ); |
|
600 | - } |
|
580 | + /** |
|
581 | + * Checks if the discount is expired |
|
582 | + * |
|
583 | + * @since 1.0.15 |
|
584 | + * @return bool |
|
585 | + */ |
|
586 | + public function is_expired() { |
|
587 | + $expired = empty ( $this->expiration ) ? false : current_time( 'timestamp' ) > strtotime( $this->expiration ); |
|
588 | + return apply_filters( 'wpinv_is_discount_expired', $expired, $this->ID, $this, $this->code ); |
|
589 | + } |
|
590 | + |
|
591 | + /** |
|
592 | + * Checks the discount start date. |
|
593 | + * |
|
594 | + * @since 1.0.15 |
|
595 | + * @return bool |
|
596 | + */ |
|
597 | + public function has_started() { |
|
598 | + $started = empty ( $this->start ) ? true : current_time( 'timestamp' ) > strtotime( $this->start ); |
|
599 | + return apply_filters( 'wpinv_is_discount_started', $started, $this->ID, $this, $this->code ); |
|
600 | + } |
|
601 | 601 | |
602 | - /** |
|
603 | - * Check if a discount is valid for a given item id. |
|
604 | - * |
|
605 | - * @param int|int[] $item_ids |
|
606 | - * @since 1.0.15 |
|
607 | - * @return boolean |
|
608 | - */ |
|
609 | - public function is_valid_for_items( $item_ids ) { |
|
602 | + /** |
|
603 | + * Check if a discount is valid for a given item id. |
|
604 | + * |
|
605 | + * @param int|int[] $item_ids |
|
606 | + * @since 1.0.15 |
|
607 | + * @return boolean |
|
608 | + */ |
|
609 | + public function is_valid_for_items( $item_ids ) { |
|
610 | 610 | |
611 | - $item_ids = array_map( 'intval', wpinv_parse_list( $item_ids ) ); |
|
612 | - $included = array_intersect( $item_ids, $this->items ); |
|
613 | - $excluded = array_intersect( $item_ids, $this->excluded_items ); |
|
614 | - |
|
615 | - if( ! empty( $this->excluded_items ) && ! empty( $excluded ) ) { |
|
616 | - return false; |
|
617 | - } |
|
618 | - |
|
619 | - if( ! empty( $this->items ) && empty( $included ) ) { |
|
620 | - return false; |
|
621 | - } |
|
622 | - return true; |
|
623 | - } |
|
611 | + $item_ids = array_map( 'intval', wpinv_parse_list( $item_ids ) ); |
|
612 | + $included = array_intersect( $item_ids, $this->items ); |
|
613 | + $excluded = array_intersect( $item_ids, $this->excluded_items ); |
|
614 | + |
|
615 | + if( ! empty( $this->excluded_items ) && ! empty( $excluded ) ) { |
|
616 | + return false; |
|
617 | + } |
|
618 | + |
|
619 | + if( ! empty( $this->items ) && empty( $included ) ) { |
|
620 | + return false; |
|
621 | + } |
|
622 | + return true; |
|
623 | + } |
|
624 | 624 | |
625 | - /** |
|
626 | - * Check if a discount is valid for the given amount |
|
627 | - * |
|
628 | - * @param float $amount The amount to check against |
|
629 | - * @since 1.0.15 |
|
630 | - * @return boolean |
|
631 | - */ |
|
632 | - public function is_valid_for_amount( $amount ) { |
|
633 | - return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount ); |
|
634 | - } |
|
635 | - |
|
636 | - /** |
|
637 | - * Checks if the minimum amount is met |
|
638 | - * |
|
639 | - * @param float $amount The amount to check against |
|
640 | - * @since 1.0.15 |
|
641 | - * @return boolean |
|
642 | - */ |
|
643 | - public function is_minimum_amount_met( $amount ) { |
|
644 | - $amount = floatval( $amount ); |
|
645 | - $min_met= ! ( $this->min_total > 0 && $amount < $this->min_total ); |
|
646 | - return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->ID, $this, $this->code, $amount ); |
|
647 | - } |
|
648 | - |
|
649 | - /** |
|
650 | - * Checks if the maximum amount is met |
|
651 | - * |
|
652 | - * @param float $amount The amount to check against |
|
653 | - * @since 1.0.15 |
|
654 | - * @return boolean |
|
655 | - */ |
|
656 | - public function is_maximum_amount_met( $amount ) { |
|
657 | - $amount = floatval( $amount ); |
|
658 | - $max_met= ! ( $this->max_total > 0 && $amount > $this->max_total ); |
|
659 | - return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->ID, $this, $this->code, $amount ); |
|
660 | - } |
|
661 | - |
|
662 | - /** |
|
663 | - * Check if a discount is valid for the given user |
|
664 | - * |
|
665 | - * @param int|string $user |
|
666 | - * @since 1.0.15 |
|
667 | - * @return boolean |
|
668 | - */ |
|
669 | - public function is_valid_for_user( $user ) { |
|
670 | - global $wpi_checkout_id; |
|
671 | - |
|
672 | - if( empty( $user ) || empty( $this->is_single_use ) ) { |
|
673 | - return true; |
|
674 | - } |
|
675 | - |
|
676 | - $user_id = 0; |
|
625 | + /** |
|
626 | + * Check if a discount is valid for the given amount |
|
627 | + * |
|
628 | + * @param float $amount The amount to check against |
|
629 | + * @since 1.0.15 |
|
630 | + * @return boolean |
|
631 | + */ |
|
632 | + public function is_valid_for_amount( $amount ) { |
|
633 | + return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount ); |
|
634 | + } |
|
635 | + |
|
636 | + /** |
|
637 | + * Checks if the minimum amount is met |
|
638 | + * |
|
639 | + * @param float $amount The amount to check against |
|
640 | + * @since 1.0.15 |
|
641 | + * @return boolean |
|
642 | + */ |
|
643 | + public function is_minimum_amount_met( $amount ) { |
|
644 | + $amount = floatval( $amount ); |
|
645 | + $min_met= ! ( $this->min_total > 0 && $amount < $this->min_total ); |
|
646 | + return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->ID, $this, $this->code, $amount ); |
|
647 | + } |
|
648 | + |
|
649 | + /** |
|
650 | + * Checks if the maximum amount is met |
|
651 | + * |
|
652 | + * @param float $amount The amount to check against |
|
653 | + * @since 1.0.15 |
|
654 | + * @return boolean |
|
655 | + */ |
|
656 | + public function is_maximum_amount_met( $amount ) { |
|
657 | + $amount = floatval( $amount ); |
|
658 | + $max_met= ! ( $this->max_total > 0 && $amount > $this->max_total ); |
|
659 | + return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->ID, $this, $this->code, $amount ); |
|
660 | + } |
|
661 | + |
|
662 | + /** |
|
663 | + * Check if a discount is valid for the given user |
|
664 | + * |
|
665 | + * @param int|string $user |
|
666 | + * @since 1.0.15 |
|
667 | + * @return boolean |
|
668 | + */ |
|
669 | + public function is_valid_for_user( $user ) { |
|
670 | + global $wpi_checkout_id; |
|
671 | + |
|
672 | + if( empty( $user ) || empty( $this->is_single_use ) ) { |
|
673 | + return true; |
|
674 | + } |
|
675 | + |
|
676 | + $user_id = 0; |
|
677 | 677 | if ( is_int( $user ) ) { |
678 | 678 | $user_id = absint( $user ); |
679 | 679 | } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
@@ -682,164 +682,164 @@ discard block |
||
682 | 682 | $user_id = $user_data->ID; |
683 | 683 | } else if ( absint( $user ) > 0 ) { |
684 | 684 | $user_id = absint( $user ); |
685 | - } |
|
685 | + } |
|
686 | 686 | |
687 | - if ( empty( $user_id ) ) { |
|
688 | - return true; |
|
689 | - } |
|
687 | + if ( empty( $user_id ) ) { |
|
688 | + return true; |
|
689 | + } |
|
690 | 690 | |
691 | - // Get all payments with matching user id |
|
691 | + // Get all payments with matching user id |
|
692 | 692 | $payments = wpinv_get_invoices( array( 'user' => $user_id, 'limit' => false ) ); |
693 | - $code = strtolower( $this->code ); |
|
693 | + $code = strtolower( $this->code ); |
|
694 | 694 | |
695 | - foreach ( $payments as $payment ) { |
|
695 | + foreach ( $payments as $payment ) { |
|
696 | 696 | |
697 | - // Don't count discount used for current invoice checkout. |
|
698 | - if ( ! empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) { |
|
699 | - continue; |
|
700 | - } |
|
697 | + // Don't count discount used for current invoice checkout. |
|
698 | + if ( ! empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) { |
|
699 | + continue; |
|
700 | + } |
|
701 | 701 | |
702 | - if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) { |
|
703 | - continue; |
|
704 | - } |
|
705 | - |
|
706 | - $discounts = $payment->get_discounts( true ); |
|
707 | - if ( empty( $discounts ) ) { |
|
708 | - continue; |
|
709 | - } |
|
710 | - |
|
711 | - $discounts = array_map( 'strtolower', wpinv_parse_list( $discounts ) ); |
|
712 | - if ( ! empty( $discounts ) && in_array( $code, $discounts ) ) { |
|
713 | - return false; |
|
714 | - } |
|
715 | - } |
|
716 | - |
|
717 | - return true; |
|
718 | - } |
|
719 | - |
|
720 | - /** |
|
721 | - * Deletes the discount from the database |
|
722 | - * |
|
723 | - * @since 1.0.15 |
|
724 | - * @return boolean |
|
725 | - */ |
|
726 | - public function remove() { |
|
727 | - |
|
728 | - if ( empty( $this->ID ) ) { |
|
729 | - return true; |
|
730 | - } |
|
731 | - |
|
732 | - do_action( 'wpinv_pre_delete_discount', $this->ID, $this->data ); |
|
733 | - wp_cache_delete( $this->ID, 'WPInv_Discounts' ); |
|
734 | - wp_delete_post( $this->ID, true ); |
|
735 | - wp_cache_delete( $this->code, 'WPInv_Discount_Codes' ); |
|
736 | - do_action( 'wpinv_post_delete_discount', $this->ID, $this->data ); |
|
737 | - |
|
738 | - $this->ID = null; |
|
739 | - $this->data['id'] = null; |
|
740 | - return true; |
|
741 | - } |
|
742 | - |
|
743 | - /** |
|
744 | - * Increases a discount's usage. |
|
745 | - * |
|
746 | - * @since 1.0.15 |
|
747 | - * @param int $by The number of usages to increas by. |
|
748 | - * @return int |
|
749 | - */ |
|
750 | - public function increase_usage( $by = 1 ) { |
|
751 | - |
|
752 | - $this->uses = $this->uses + $by; |
|
753 | - |
|
754 | - if( $this->uses < 0 ) { |
|
755 | - $this->uses = 0; |
|
756 | - update_post_meta( $this->ID, "_wpi_discount_uses", 0 ); |
|
757 | - } |
|
758 | - |
|
759 | - $this->save(); |
|
760 | - |
|
761 | - if( $by > 0 ) { |
|
762 | - do_action( 'wpinv_discount_increase_use_count', $this->uses, $this->ID, $this->code, $by ); |
|
763 | - } else { |
|
764 | - do_action( 'wpinv_discount_decrease_use_count', $this->uses, $this->ID, $this->code, absint( $by ) ); |
|
765 | - } |
|
702 | + if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) { |
|
703 | + continue; |
|
704 | + } |
|
705 | + |
|
706 | + $discounts = $payment->get_discounts( true ); |
|
707 | + if ( empty( $discounts ) ) { |
|
708 | + continue; |
|
709 | + } |
|
710 | + |
|
711 | + $discounts = array_map( 'strtolower', wpinv_parse_list( $discounts ) ); |
|
712 | + if ( ! empty( $discounts ) && in_array( $code, $discounts ) ) { |
|
713 | + return false; |
|
714 | + } |
|
715 | + } |
|
716 | + |
|
717 | + return true; |
|
718 | + } |
|
719 | + |
|
720 | + /** |
|
721 | + * Deletes the discount from the database |
|
722 | + * |
|
723 | + * @since 1.0.15 |
|
724 | + * @return boolean |
|
725 | + */ |
|
726 | + public function remove() { |
|
727 | + |
|
728 | + if ( empty( $this->ID ) ) { |
|
729 | + return true; |
|
730 | + } |
|
731 | + |
|
732 | + do_action( 'wpinv_pre_delete_discount', $this->ID, $this->data ); |
|
733 | + wp_cache_delete( $this->ID, 'WPInv_Discounts' ); |
|
734 | + wp_delete_post( $this->ID, true ); |
|
735 | + wp_cache_delete( $this->code, 'WPInv_Discount_Codes' ); |
|
736 | + do_action( 'wpinv_post_delete_discount', $this->ID, $this->data ); |
|
737 | + |
|
738 | + $this->ID = null; |
|
739 | + $this->data['id'] = null; |
|
740 | + return true; |
|
741 | + } |
|
742 | + |
|
743 | + /** |
|
744 | + * Increases a discount's usage. |
|
745 | + * |
|
746 | + * @since 1.0.15 |
|
747 | + * @param int $by The number of usages to increas by. |
|
748 | + * @return int |
|
749 | + */ |
|
750 | + public function increase_usage( $by = 1 ) { |
|
751 | + |
|
752 | + $this->uses = $this->uses + $by; |
|
753 | + |
|
754 | + if( $this->uses < 0 ) { |
|
755 | + $this->uses = 0; |
|
756 | + update_post_meta( $this->ID, "_wpi_discount_uses", 0 ); |
|
757 | + } |
|
758 | + |
|
759 | + $this->save(); |
|
760 | + |
|
761 | + if( $by > 0 ) { |
|
762 | + do_action( 'wpinv_discount_increase_use_count', $this->uses, $this->ID, $this->code, $by ); |
|
763 | + } else { |
|
764 | + do_action( 'wpinv_discount_decrease_use_count', $this->uses, $this->ID, $this->code, absint( $by ) ); |
|
765 | + } |
|
766 | 766 | |
767 | - return $this->uses; |
|
768 | - } |
|
769 | - |
|
770 | - /** |
|
771 | - * Retrieves discount data |
|
772 | - * |
|
773 | - * @since 1.0.15 |
|
774 | - * @return array |
|
775 | - */ |
|
776 | - public function get_data() { |
|
777 | - $return = array(); |
|
778 | - foreach( array_keys( $this->data ) as $key ) { |
|
779 | - $return[ $key ] = $this->get( $key ); |
|
780 | - } |
|
781 | - return $return; |
|
782 | - } |
|
783 | - |
|
784 | - /** |
|
785 | - * Retrieves discount data as json |
|
786 | - * |
|
787 | - * @since 1.0.15 |
|
788 | - * @return string|false |
|
789 | - */ |
|
790 | - public function get_data_as_json() { |
|
791 | - return wp_json_encode( $this->get_data() ); |
|
792 | - } |
|
793 | - |
|
794 | - /** |
|
795 | - * Checks if a discount can only be used once per user. |
|
796 | - * |
|
797 | - * @since 1.0.15 |
|
798 | - * @return bool |
|
799 | - */ |
|
800 | - public function get_is_single_use() { |
|
801 | - return (bool) apply_filters( 'wpinv_is_discount_single_use', $this->data['is_single_use'], $this->ID, $this, $this->code ); |
|
802 | - } |
|
803 | - |
|
804 | - /** |
|
805 | - * Checks if a discount is recurring. |
|
806 | - * |
|
807 | - * @since 1.0.15 |
|
808 | - * @return bool |
|
809 | - */ |
|
810 | - public function get_is_recurring() { |
|
811 | - return (bool) apply_filters( 'wpinv_is_discount_recurring', $this->data['is_recurring'], $this->ID, $this->code, $this ); |
|
812 | - } |
|
813 | - |
|
814 | - /** |
|
815 | - * Returns a discount's included items. |
|
816 | - * |
|
817 | - * @since 1.0.15 |
|
818 | - * @return array |
|
819 | - */ |
|
820 | - public function get_items() { |
|
821 | - return wpinv_parse_list( apply_filters( 'wpinv_get_discount_item_reqs', $this->data['items'], $this->ID, $this, $this->code ) ); |
|
822 | - } |
|
823 | - |
|
824 | - /** |
|
825 | - * Returns a discount's discounted amount. |
|
826 | - * |
|
827 | - * @since 1.0.15 |
|
828 | - * @return float |
|
829 | - */ |
|
830 | - public function get_discounted_amount( $amount ) { |
|
831 | - |
|
832 | - if ( $this->type == 'flat' ) { |
|
767 | + return $this->uses; |
|
768 | + } |
|
769 | + |
|
770 | + /** |
|
771 | + * Retrieves discount data |
|
772 | + * |
|
773 | + * @since 1.0.15 |
|
774 | + * @return array |
|
775 | + */ |
|
776 | + public function get_data() { |
|
777 | + $return = array(); |
|
778 | + foreach( array_keys( $this->data ) as $key ) { |
|
779 | + $return[ $key ] = $this->get( $key ); |
|
780 | + } |
|
781 | + return $return; |
|
782 | + } |
|
783 | + |
|
784 | + /** |
|
785 | + * Retrieves discount data as json |
|
786 | + * |
|
787 | + * @since 1.0.15 |
|
788 | + * @return string|false |
|
789 | + */ |
|
790 | + public function get_data_as_json() { |
|
791 | + return wp_json_encode( $this->get_data() ); |
|
792 | + } |
|
793 | + |
|
794 | + /** |
|
795 | + * Checks if a discount can only be used once per user. |
|
796 | + * |
|
797 | + * @since 1.0.15 |
|
798 | + * @return bool |
|
799 | + */ |
|
800 | + public function get_is_single_use() { |
|
801 | + return (bool) apply_filters( 'wpinv_is_discount_single_use', $this->data['is_single_use'], $this->ID, $this, $this->code ); |
|
802 | + } |
|
803 | + |
|
804 | + /** |
|
805 | + * Checks if a discount is recurring. |
|
806 | + * |
|
807 | + * @since 1.0.15 |
|
808 | + * @return bool |
|
809 | + */ |
|
810 | + public function get_is_recurring() { |
|
811 | + return (bool) apply_filters( 'wpinv_is_discount_recurring', $this->data['is_recurring'], $this->ID, $this->code, $this ); |
|
812 | + } |
|
813 | + |
|
814 | + /** |
|
815 | + * Returns a discount's included items. |
|
816 | + * |
|
817 | + * @since 1.0.15 |
|
818 | + * @return array |
|
819 | + */ |
|
820 | + public function get_items() { |
|
821 | + return wpinv_parse_list( apply_filters( 'wpinv_get_discount_item_reqs', $this->data['items'], $this->ID, $this, $this->code ) ); |
|
822 | + } |
|
823 | + |
|
824 | + /** |
|
825 | + * Returns a discount's discounted amount. |
|
826 | + * |
|
827 | + * @since 1.0.15 |
|
828 | + * @return float |
|
829 | + */ |
|
830 | + public function get_discounted_amount( $amount ) { |
|
831 | + |
|
832 | + if ( $this->type == 'flat' ) { |
|
833 | 833 | $amount = $amount - $this->amount; |
834 | - } else { |
|
834 | + } else { |
|
835 | 835 | $amount = $amount - ( $amount * ( $this->amount / 100 ) ); |
836 | - } |
|
836 | + } |
|
837 | 837 | |
838 | - if ( $amount < 0 ) { |
|
839 | - $amount = 0; |
|
840 | - } |
|
838 | + if ( $amount < 0 ) { |
|
839 | + $amount = 0; |
|
840 | + } |
|
841 | 841 | |
842 | - return apply_filters( 'wpinv_discounted_amount', $amount, $this->ID, $this, $this->code, $this->amount ); |
|
843 | - } |
|
842 | + return apply_filters( 'wpinv_discounted_amount', $amount, $this->ID, $this, $this->code, $this->amount ); |
|
843 | + } |
|
844 | 844 | |
845 | 845 | } |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | } |
701 | 701 | |
702 | 702 | function wpinv_get_php_arg_separator_output() { |
703 | - return ini_get( 'arg_separator.output' ); |
|
703 | + return ini_get( 'arg_separator.output' ); |
|
704 | 704 | } |
705 | 705 | |
706 | 706 | function wpinv_rgb_from_hex( $color ) { |
@@ -1038,11 +1038,11 @@ discard block |
||
1038 | 1038 | * @return array Sanitized array of values. |
1039 | 1039 | */ |
1040 | 1040 | function wpinv_parse_list( $list ) { |
1041 | - if ( ! is_array( $list ) ) { |
|
1042 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
1043 | - } |
|
1041 | + if ( ! is_array( $list ) ) { |
|
1042 | + return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
1043 | + } |
|
1044 | 1044 | |
1045 | - return $list; |
|
1045 | + return $list; |
|
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | /** |
@@ -1062,9 +1062,9 @@ discard block |
||
1062 | 1062 | } |
1063 | 1063 | |
1064 | 1064 | $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
1065 | - wp_cache_set( "wpinv-$key", $data, 'wpinv' ); |
|
1065 | + wp_cache_set( "wpinv-$key", $data, 'wpinv' ); |
|
1066 | 1066 | |
1067 | - return $data; |
|
1067 | + return $data; |
|
1068 | 1068 | } |
1069 | 1069 | |
1070 | 1070 | /** |
@@ -1093,17 +1093,17 @@ discard block |
||
1093 | 1093 | */ |
1094 | 1094 | function wpinv_clean( $var ) { |
1095 | 1095 | |
1096 | - if ( is_array( $var ) ) { |
|
1097 | - return array_map( 'wpinv_clean', $var ); |
|
1096 | + if ( is_array( $var ) ) { |
|
1097 | + return array_map( 'wpinv_clean', $var ); |
|
1098 | 1098 | } |
1099 | 1099 | |
1100 | 1100 | if ( is_object( $var ) ) { |
1101 | - $object_vars = get_object_vars( $var ); |
|
1102 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
1103 | - $var->$property_name = wpinv_clean( $property_value ); |
|
1101 | + $object_vars = get_object_vars( $var ); |
|
1102 | + foreach ( $object_vars as $property_name => $property_value ) { |
|
1103 | + $var->$property_name = wpinv_clean( $property_value ); |
|
1104 | 1104 | } |
1105 | 1105 | return $var; |
1106 | - } |
|
1106 | + } |
|
1107 | 1107 | |
1108 | 1108 | return is_string( $var ) ? sanitize_text_field( $var ) : $var; |
1109 | 1109 | } |
1110 | 1110 | \ No newline at end of file |
@@ -1,271 +1,271 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; |
|
4 | + exit; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | if ( ! class_exists( "AyeCode_Connect_Helper" ) ) { |
8 | - /** |
|
9 | - * Allow the quick setup and connection of our AyeCode Connect plugin. |
|
10 | - * |
|
11 | - * Class AyeCode_Connect_Helper |
|
12 | - */ |
|
13 | - class AyeCode_Connect_Helper { |
|
14 | - |
|
15 | - // Hold the version number |
|
16 | - var $version = "1.0.3"; |
|
17 | - |
|
18 | - // Hold the default strings. |
|
19 | - var $strings = array(); |
|
20 | - |
|
21 | - // Hold the default pages. |
|
22 | - var $pages = array(); |
|
23 | - |
|
24 | - /** |
|
25 | - * The constructor. |
|
26 | - * |
|
27 | - * AyeCode_Connect_Helper constructor. |
|
28 | - * |
|
29 | - * @param array $strings |
|
30 | - * @param array $pages |
|
31 | - */ |
|
32 | - public function __construct( $strings = array(), $pages = array() ) { |
|
33 | - |
|
34 | - // Only fire if not localhost and the current user has the right permissions. |
|
35 | - if ( ! $this->is_localhost() && current_user_can( 'manage_options' ) ) { |
|
36 | - |
|
37 | - |
|
38 | - // set default strings |
|
39 | - $default_strings = array( |
|
40 | - 'connect_title' => __( "Thanks for choosing an AyeCode Product!" ), |
|
41 | - 'connect_external' => __( "Please confirm you wish to connect your site?" ), |
|
42 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s" ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>" ), |
|
43 | - 'connect_button' => __( "Connect Site" ), |
|
44 | - 'connecting_button' => __( "Connecting..." ), |
|
45 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost." ), |
|
46 | - 'error' => __( "Something went wrong, please refresh and try again." ), |
|
47 | - ); |
|
48 | - $this->strings = array_merge( $default_strings, $strings ); |
|
49 | - |
|
50 | - |
|
51 | - // set default pages |
|
52 | - $default_pages = array(); |
|
53 | - $this->pages = array_merge( $default_pages, $pages ); |
|
54 | - |
|
55 | - // maybe show connect site notice |
|
56 | - add_action( 'admin_notices', array( $this, 'ayecode_connect_install_notice' ) ); |
|
57 | - |
|
58 | - // add ajax action if not already added |
|
59 | - if ( ! has_action( 'wp_ajax_ayecode_connect_helper' ) ) { |
|
60 | - add_action( 'wp_ajax_ayecode_connect_helper', array( $this, 'ayecode_connect_install' ) ); |
|
61 | - } |
|
62 | - } |
|
63 | - |
|
64 | - // add ajax action if not already added |
|
65 | - if ( ! has_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed' ) ) { |
|
66 | - add_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed', array( $this, 'ayecode_connect_helper_installed' ) ); |
|
67 | - } |
|
68 | - |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Give a way to check we can connect via a external redirect. |
|
73 | - */ |
|
74 | - public function ayecode_connect_helper_installed(){ |
|
75 | - $active = array( |
|
76 | - 'gd' => defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION,'2.0.0.79','>') ? 1 : 0, |
|
77 | - 'uwp' => defined('USERSWP_VERSION') && version_compare(USERSWP_VERSION,'1.2.1.5','>') ? 1 : 0, |
|
78 | - 'wpi' => defined('WPINV_VERSION') && version_compare(WPINV_VERSION,'1.0.14','>') ? 1 : 0, |
|
79 | - ); |
|
80 | - wp_send_json_success( $active ); |
|
81 | - wp_die(); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Get slug from path |
|
86 | - * |
|
87 | - * @param string $key |
|
88 | - * |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - private function format_plugin_slug( $key ) { |
|
92 | - $slug = explode( '/', $key ); |
|
93 | - $slug = explode( '.', end( $slug ) ); |
|
94 | - |
|
95 | - return $slug[0]; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Install and activate the AyeCode Connect Plugin |
|
100 | - */ |
|
101 | - public function ayecode_connect_install() { |
|
102 | - |
|
103 | - // bail if localhost |
|
104 | - if ( $this->is_localhost() ) { |
|
105 | - wp_send_json_error( $this->strings['error_localhost'] ); |
|
106 | - } |
|
107 | - |
|
108 | - // Explicitly clear the event. |
|
109 | - wp_clear_scheduled_hook( 'geodir_plugin_background_installer', func_get_args() ); |
|
110 | - |
|
111 | - $success = true; |
|
112 | - $plugin_slug = "ayecode-connect"; |
|
113 | - if ( ! empty( $plugin_slug ) ) { |
|
114 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
115 | - require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); |
|
116 | - require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
|
117 | - require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
118 | - |
|
119 | - WP_Filesystem(); |
|
120 | - |
|
121 | - $skin = new Automatic_Upgrader_Skin; |
|
122 | - $upgrader = new WP_Upgrader( $skin ); |
|
123 | - $installed_plugins = array_map( array( $this, 'format_plugin_slug' ), array_keys( get_plugins() ) ); |
|
124 | - $plugin_slug = $plugin_slug; |
|
125 | - $plugin = $plugin_slug . '/' . $plugin_slug . '.php'; |
|
126 | - $installed = false; |
|
127 | - $activate = false; |
|
128 | - |
|
129 | - // See if the plugin is installed already |
|
130 | - if ( in_array( $plugin_slug, $installed_plugins ) ) { |
|
131 | - $installed = true; |
|
132 | - $activate = ! is_plugin_active( $plugin ); |
|
133 | - } |
|
134 | - |
|
135 | - // Install this thing! |
|
136 | - if ( ! $installed ) { |
|
137 | - |
|
138 | - // Suppress feedback |
|
139 | - ob_start(); |
|
140 | - |
|
141 | - try { |
|
142 | - $plugin_information = plugins_api( 'plugin_information', array( |
|
143 | - 'slug' => $plugin_slug, |
|
144 | - 'fields' => array( |
|
145 | - 'short_description' => false, |
|
146 | - 'sections' => false, |
|
147 | - 'requires' => false, |
|
148 | - 'rating' => false, |
|
149 | - 'ratings' => false, |
|
150 | - 'downloaded' => false, |
|
151 | - 'last_updated' => false, |
|
152 | - 'added' => false, |
|
153 | - 'tags' => false, |
|
154 | - 'homepage' => false, |
|
155 | - 'donate_link' => false, |
|
156 | - 'author_profile' => false, |
|
157 | - 'author' => false, |
|
158 | - ), |
|
159 | - ) ); |
|
160 | - |
|
161 | - if ( is_wp_error( $plugin_information ) ) { |
|
162 | - throw new Exception( $plugin_information->get_error_message() ); |
|
163 | - } |
|
164 | - |
|
165 | - $package = $plugin_information->download_link; |
|
166 | - $download = $upgrader->download_package( $package ); |
|
167 | - |
|
168 | - if ( is_wp_error( $download ) ) { |
|
169 | - throw new Exception( $download->get_error_message() ); |
|
170 | - } |
|
171 | - |
|
172 | - $working_dir = $upgrader->unpack_package( $download, true ); |
|
173 | - |
|
174 | - if ( is_wp_error( $working_dir ) ) { |
|
175 | - throw new Exception( $working_dir->get_error_message() ); |
|
176 | - } |
|
177 | - |
|
178 | - $result = $upgrader->install_package( array( |
|
179 | - 'source' => $working_dir, |
|
180 | - 'destination' => WP_PLUGIN_DIR, |
|
181 | - 'clear_destination' => false, |
|
182 | - 'abort_if_destination_exists' => false, |
|
183 | - 'clear_working' => true, |
|
184 | - 'hook_extra' => array( |
|
185 | - 'type' => 'plugin', |
|
186 | - 'action' => 'install', |
|
187 | - ), |
|
188 | - ) ); |
|
189 | - |
|
190 | - if ( is_wp_error( $result ) ) { |
|
191 | - throw new Exception( $result->get_error_message() ); |
|
192 | - } |
|
193 | - |
|
194 | - $activate = true; |
|
195 | - |
|
196 | - } catch ( Exception $e ) { |
|
197 | - $success = false; |
|
198 | - } |
|
199 | - |
|
200 | - // Discard feedback |
|
201 | - ob_end_clean(); |
|
202 | - } |
|
203 | - |
|
204 | - wp_clean_plugins_cache(); |
|
205 | - |
|
206 | - // Activate this thing |
|
207 | - if ( $activate ) { |
|
208 | - try { |
|
209 | - $result = activate_plugin( $plugin ); |
|
210 | - |
|
211 | - if ( is_wp_error( $result ) ) { |
|
212 | - $success = false; |
|
213 | - } else { |
|
214 | - $success = true; |
|
215 | - } |
|
216 | - } catch ( Exception $e ) { |
|
217 | - $success = false; |
|
218 | - } |
|
219 | - } |
|
220 | - } |
|
221 | - |
|
222 | - if ( $success && function_exists( 'ayecode_connect_args' ) ) { |
|
223 | - ayecode_connect();// init |
|
224 | - $args = ayecode_connect_args(); |
|
225 | - $client = new AyeCode_Connect( $args ); |
|
226 | - $redirect_to = ! empty( $_POST['redirect_to'] ) ? esc_url_raw( $_POST['redirect_to'] ) : ''; |
|
227 | - $redirect = $client->build_connect_url( $redirect_to ); |
|
228 | - wp_send_json_success( array( 'connect_url' => $redirect ) ); |
|
229 | - } else { |
|
230 | - wp_send_json_error( $this->strings['error_localhost'] ); |
|
231 | - } |
|
232 | - wp_die(); |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Check if maybe localhost. |
|
237 | - * |
|
238 | - * @return bool |
|
239 | - */ |
|
240 | - public function is_localhost() { |
|
241 | - $localhost = false; |
|
242 | - |
|
243 | - $host = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : ''; |
|
244 | - $localhost_domains = array( |
|
245 | - 'localhost', |
|
246 | - 'localhost.localdomain', |
|
247 | - '127.0.0.1', |
|
248 | - '::1' |
|
249 | - ); |
|
250 | - |
|
251 | - if ( in_array( $host, $localhost_domains ) ) { |
|
252 | - $localhost = true; |
|
253 | - } |
|
254 | - |
|
255 | - return $localhost; |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Show notice to connect site. |
|
260 | - */ |
|
261 | - public function ayecode_connect_install_notice() { |
|
262 | - if ( $this->maybe_show() ) { |
|
263 | - $connect_title_string = $this->strings['connect_title']; |
|
264 | - $connect_external_string = $this->strings['connect_external']; |
|
265 | - $connect_string = $this->strings['connect']; |
|
266 | - $connect_button_string = $this->strings['connect_button']; |
|
267 | - $connecting_button_string = $this->strings['connecting_button']; |
|
268 | - ?> |
|
8 | + /** |
|
9 | + * Allow the quick setup and connection of our AyeCode Connect plugin. |
|
10 | + * |
|
11 | + * Class AyeCode_Connect_Helper |
|
12 | + */ |
|
13 | + class AyeCode_Connect_Helper { |
|
14 | + |
|
15 | + // Hold the version number |
|
16 | + var $version = "1.0.3"; |
|
17 | + |
|
18 | + // Hold the default strings. |
|
19 | + var $strings = array(); |
|
20 | + |
|
21 | + // Hold the default pages. |
|
22 | + var $pages = array(); |
|
23 | + |
|
24 | + /** |
|
25 | + * The constructor. |
|
26 | + * |
|
27 | + * AyeCode_Connect_Helper constructor. |
|
28 | + * |
|
29 | + * @param array $strings |
|
30 | + * @param array $pages |
|
31 | + */ |
|
32 | + public function __construct( $strings = array(), $pages = array() ) { |
|
33 | + |
|
34 | + // Only fire if not localhost and the current user has the right permissions. |
|
35 | + if ( ! $this->is_localhost() && current_user_can( 'manage_options' ) ) { |
|
36 | + |
|
37 | + |
|
38 | + // set default strings |
|
39 | + $default_strings = array( |
|
40 | + 'connect_title' => __( "Thanks for choosing an AyeCode Product!" ), |
|
41 | + 'connect_external' => __( "Please confirm you wish to connect your site?" ), |
|
42 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s" ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>" ), |
|
43 | + 'connect_button' => __( "Connect Site" ), |
|
44 | + 'connecting_button' => __( "Connecting..." ), |
|
45 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost." ), |
|
46 | + 'error' => __( "Something went wrong, please refresh and try again." ), |
|
47 | + ); |
|
48 | + $this->strings = array_merge( $default_strings, $strings ); |
|
49 | + |
|
50 | + |
|
51 | + // set default pages |
|
52 | + $default_pages = array(); |
|
53 | + $this->pages = array_merge( $default_pages, $pages ); |
|
54 | + |
|
55 | + // maybe show connect site notice |
|
56 | + add_action( 'admin_notices', array( $this, 'ayecode_connect_install_notice' ) ); |
|
57 | + |
|
58 | + // add ajax action if not already added |
|
59 | + if ( ! has_action( 'wp_ajax_ayecode_connect_helper' ) ) { |
|
60 | + add_action( 'wp_ajax_ayecode_connect_helper', array( $this, 'ayecode_connect_install' ) ); |
|
61 | + } |
|
62 | + } |
|
63 | + |
|
64 | + // add ajax action if not already added |
|
65 | + if ( ! has_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed' ) ) { |
|
66 | + add_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed', array( $this, 'ayecode_connect_helper_installed' ) ); |
|
67 | + } |
|
68 | + |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Give a way to check we can connect via a external redirect. |
|
73 | + */ |
|
74 | + public function ayecode_connect_helper_installed(){ |
|
75 | + $active = array( |
|
76 | + 'gd' => defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION,'2.0.0.79','>') ? 1 : 0, |
|
77 | + 'uwp' => defined('USERSWP_VERSION') && version_compare(USERSWP_VERSION,'1.2.1.5','>') ? 1 : 0, |
|
78 | + 'wpi' => defined('WPINV_VERSION') && version_compare(WPINV_VERSION,'1.0.14','>') ? 1 : 0, |
|
79 | + ); |
|
80 | + wp_send_json_success( $active ); |
|
81 | + wp_die(); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Get slug from path |
|
86 | + * |
|
87 | + * @param string $key |
|
88 | + * |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + private function format_plugin_slug( $key ) { |
|
92 | + $slug = explode( '/', $key ); |
|
93 | + $slug = explode( '.', end( $slug ) ); |
|
94 | + |
|
95 | + return $slug[0]; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Install and activate the AyeCode Connect Plugin |
|
100 | + */ |
|
101 | + public function ayecode_connect_install() { |
|
102 | + |
|
103 | + // bail if localhost |
|
104 | + if ( $this->is_localhost() ) { |
|
105 | + wp_send_json_error( $this->strings['error_localhost'] ); |
|
106 | + } |
|
107 | + |
|
108 | + // Explicitly clear the event. |
|
109 | + wp_clear_scheduled_hook( 'geodir_plugin_background_installer', func_get_args() ); |
|
110 | + |
|
111 | + $success = true; |
|
112 | + $plugin_slug = "ayecode-connect"; |
|
113 | + if ( ! empty( $plugin_slug ) ) { |
|
114 | + require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
115 | + require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); |
|
116 | + require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
|
117 | + require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
118 | + |
|
119 | + WP_Filesystem(); |
|
120 | + |
|
121 | + $skin = new Automatic_Upgrader_Skin; |
|
122 | + $upgrader = new WP_Upgrader( $skin ); |
|
123 | + $installed_plugins = array_map( array( $this, 'format_plugin_slug' ), array_keys( get_plugins() ) ); |
|
124 | + $plugin_slug = $plugin_slug; |
|
125 | + $plugin = $plugin_slug . '/' . $plugin_slug . '.php'; |
|
126 | + $installed = false; |
|
127 | + $activate = false; |
|
128 | + |
|
129 | + // See if the plugin is installed already |
|
130 | + if ( in_array( $plugin_slug, $installed_plugins ) ) { |
|
131 | + $installed = true; |
|
132 | + $activate = ! is_plugin_active( $plugin ); |
|
133 | + } |
|
134 | + |
|
135 | + // Install this thing! |
|
136 | + if ( ! $installed ) { |
|
137 | + |
|
138 | + // Suppress feedback |
|
139 | + ob_start(); |
|
140 | + |
|
141 | + try { |
|
142 | + $plugin_information = plugins_api( 'plugin_information', array( |
|
143 | + 'slug' => $plugin_slug, |
|
144 | + 'fields' => array( |
|
145 | + 'short_description' => false, |
|
146 | + 'sections' => false, |
|
147 | + 'requires' => false, |
|
148 | + 'rating' => false, |
|
149 | + 'ratings' => false, |
|
150 | + 'downloaded' => false, |
|
151 | + 'last_updated' => false, |
|
152 | + 'added' => false, |
|
153 | + 'tags' => false, |
|
154 | + 'homepage' => false, |
|
155 | + 'donate_link' => false, |
|
156 | + 'author_profile' => false, |
|
157 | + 'author' => false, |
|
158 | + ), |
|
159 | + ) ); |
|
160 | + |
|
161 | + if ( is_wp_error( $plugin_information ) ) { |
|
162 | + throw new Exception( $plugin_information->get_error_message() ); |
|
163 | + } |
|
164 | + |
|
165 | + $package = $plugin_information->download_link; |
|
166 | + $download = $upgrader->download_package( $package ); |
|
167 | + |
|
168 | + if ( is_wp_error( $download ) ) { |
|
169 | + throw new Exception( $download->get_error_message() ); |
|
170 | + } |
|
171 | + |
|
172 | + $working_dir = $upgrader->unpack_package( $download, true ); |
|
173 | + |
|
174 | + if ( is_wp_error( $working_dir ) ) { |
|
175 | + throw new Exception( $working_dir->get_error_message() ); |
|
176 | + } |
|
177 | + |
|
178 | + $result = $upgrader->install_package( array( |
|
179 | + 'source' => $working_dir, |
|
180 | + 'destination' => WP_PLUGIN_DIR, |
|
181 | + 'clear_destination' => false, |
|
182 | + 'abort_if_destination_exists' => false, |
|
183 | + 'clear_working' => true, |
|
184 | + 'hook_extra' => array( |
|
185 | + 'type' => 'plugin', |
|
186 | + 'action' => 'install', |
|
187 | + ), |
|
188 | + ) ); |
|
189 | + |
|
190 | + if ( is_wp_error( $result ) ) { |
|
191 | + throw new Exception( $result->get_error_message() ); |
|
192 | + } |
|
193 | + |
|
194 | + $activate = true; |
|
195 | + |
|
196 | + } catch ( Exception $e ) { |
|
197 | + $success = false; |
|
198 | + } |
|
199 | + |
|
200 | + // Discard feedback |
|
201 | + ob_end_clean(); |
|
202 | + } |
|
203 | + |
|
204 | + wp_clean_plugins_cache(); |
|
205 | + |
|
206 | + // Activate this thing |
|
207 | + if ( $activate ) { |
|
208 | + try { |
|
209 | + $result = activate_plugin( $plugin ); |
|
210 | + |
|
211 | + if ( is_wp_error( $result ) ) { |
|
212 | + $success = false; |
|
213 | + } else { |
|
214 | + $success = true; |
|
215 | + } |
|
216 | + } catch ( Exception $e ) { |
|
217 | + $success = false; |
|
218 | + } |
|
219 | + } |
|
220 | + } |
|
221 | + |
|
222 | + if ( $success && function_exists( 'ayecode_connect_args' ) ) { |
|
223 | + ayecode_connect();// init |
|
224 | + $args = ayecode_connect_args(); |
|
225 | + $client = new AyeCode_Connect( $args ); |
|
226 | + $redirect_to = ! empty( $_POST['redirect_to'] ) ? esc_url_raw( $_POST['redirect_to'] ) : ''; |
|
227 | + $redirect = $client->build_connect_url( $redirect_to ); |
|
228 | + wp_send_json_success( array( 'connect_url' => $redirect ) ); |
|
229 | + } else { |
|
230 | + wp_send_json_error( $this->strings['error_localhost'] ); |
|
231 | + } |
|
232 | + wp_die(); |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Check if maybe localhost. |
|
237 | + * |
|
238 | + * @return bool |
|
239 | + */ |
|
240 | + public function is_localhost() { |
|
241 | + $localhost = false; |
|
242 | + |
|
243 | + $host = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : ''; |
|
244 | + $localhost_domains = array( |
|
245 | + 'localhost', |
|
246 | + 'localhost.localdomain', |
|
247 | + '127.0.0.1', |
|
248 | + '::1' |
|
249 | + ); |
|
250 | + |
|
251 | + if ( in_array( $host, $localhost_domains ) ) { |
|
252 | + $localhost = true; |
|
253 | + } |
|
254 | + |
|
255 | + return $localhost; |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Show notice to connect site. |
|
260 | + */ |
|
261 | + public function ayecode_connect_install_notice() { |
|
262 | + if ( $this->maybe_show() ) { |
|
263 | + $connect_title_string = $this->strings['connect_title']; |
|
264 | + $connect_external_string = $this->strings['connect_external']; |
|
265 | + $connect_string = $this->strings['connect']; |
|
266 | + $connect_button_string = $this->strings['connect_button']; |
|
267 | + $connecting_button_string = $this->strings['connecting_button']; |
|
268 | + ?> |
|
269 | 269 | <div class="notice notice-info acch-notice"> |
270 | 270 | <span class="acch-float-left"> |
271 | 271 | <svg width="61px" height="61px" viewBox="0 0 61 61" version="1.1" |
@@ -304,8 +304,8 @@ discard block |
||
304 | 304 | <h3 class="acch-title"><?php echo esc_attr( $connect_title_string ); ?></h3> |
305 | 305 | <p> |
306 | 306 | <?php |
307 | - echo $connect_string; |
|
308 | - ?> |
|
307 | + echo $connect_string; |
|
308 | + ?> |
|
309 | 309 | </p> |
310 | 310 | </span> |
311 | 311 | |
@@ -318,9 +318,9 @@ discard block |
||
318 | 318 | </div> |
319 | 319 | |
320 | 320 | <?php |
321 | - // only include the popup HTML if needed. |
|
322 | - if ( ! empty( $_REQUEST['external-connect-request'] ) ) { |
|
323 | - ?> |
|
321 | + // only include the popup HTML if needed. |
|
322 | + if ( ! empty( $_REQUEST['external-connect-request'] ) ) { |
|
323 | + ?> |
|
324 | 324 | <div id="ayecode-connect-helper-external-confirm" style="display:none;"> |
325 | 325 | <div class="noticex notice-info acch-notice" style="border: none;"> |
326 | 326 | <span class="acch-float-left"> |
@@ -369,23 +369,23 @@ discard block |
||
369 | 369 | </div> |
370 | 370 | </div> |
371 | 371 | <?php |
372 | - } |
|
373 | - |
|
374 | - // add required scripts |
|
375 | - $this->script(); |
|
376 | - } |
|
377 | - } |
|
378 | - |
|
379 | - /** |
|
380 | - * Get the JS Script. |
|
381 | - */ |
|
382 | - public function script() { |
|
383 | - |
|
384 | - // add thickbox if external request is requested |
|
385 | - if ( ! empty( $_REQUEST['external-connect-request'] ) ) { |
|
386 | - add_thickbox(); |
|
387 | - } |
|
388 | - ?> |
|
372 | + } |
|
373 | + |
|
374 | + // add required scripts |
|
375 | + $this->script(); |
|
376 | + } |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * Get the JS Script. |
|
381 | + */ |
|
382 | + public function script() { |
|
383 | + |
|
384 | + // add thickbox if external request is requested |
|
385 | + if ( ! empty( $_REQUEST['external-connect-request'] ) ) { |
|
386 | + add_thickbox(); |
|
387 | + } |
|
388 | + ?> |
|
389 | 389 | <style> |
390 | 390 | .acch-title { |
391 | 391 | margin: 0; |
@@ -454,43 +454,43 @@ discard block |
||
454 | 454 | |
455 | 455 | |
456 | 456 | <?php |
457 | - // add thickbox if external request is requested |
|
458 | - if(! empty( $_REQUEST['external-connect-request'] )) { |
|
459 | - ?> |
|
457 | + // add thickbox if external request is requested |
|
458 | + if(! empty( $_REQUEST['external-connect-request'] )) { |
|
459 | + ?> |
|
460 | 460 | jQuery(function () { |
461 | 461 | setTimeout(function () { |
462 | 462 | tb_show("AyeCode Connect", "?TB_inline?width=300&height=80&inlineId=ayecode-connect-helper-external-confirm"); |
463 | 463 | }, 200); |
464 | 464 | }); |
465 | 465 | <?php |
466 | - } |
|
467 | - ?> |
|
466 | + } |
|
467 | + ?> |
|
468 | 468 | |
469 | 469 | </script> |
470 | 470 | <?php |
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * Decide what pages to show on. |
|
475 | - * |
|
476 | - * @return bool |
|
477 | - */ |
|
478 | - public function maybe_show() { |
|
479 | - $show = false; |
|
480 | - |
|
481 | - // check if on a page set to show |
|
482 | - if ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $this->pages ) ) { |
|
483 | - |
|
484 | - // check if not active and connected |
|
485 | - if ( ! defined( 'AYECODE_CONNECT_VERSION' ) || ! get_option( 'ayecode_connect_blog_token' ) ) { |
|
486 | - $show = true; |
|
487 | - } |
|
471 | + } |
|
472 | + |
|
473 | + /** |
|
474 | + * Decide what pages to show on. |
|
475 | + * |
|
476 | + * @return bool |
|
477 | + */ |
|
478 | + public function maybe_show() { |
|
479 | + $show = false; |
|
480 | + |
|
481 | + // check if on a page set to show |
|
482 | + if ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $this->pages ) ) { |
|
483 | + |
|
484 | + // check if not active and connected |
|
485 | + if ( ! defined( 'AYECODE_CONNECT_VERSION' ) || ! get_option( 'ayecode_connect_blog_token' ) ) { |
|
486 | + $show = true; |
|
487 | + } |
|
488 | 488 | |
489 | - } |
|
489 | + } |
|
490 | 490 | |
491 | - return $show; |
|
492 | - } |
|
491 | + return $show; |
|
492 | + } |
|
493 | 493 | |
494 | - } |
|
494 | + } |
|
495 | 495 | |
496 | 496 | } |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | } |
701 | 701 | |
702 | 702 | function wpinv_get_payment_key( $invoice_id = 0 ) { |
703 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
703 | + $invoice = new WPInv_Invoice( $invoice_id ); |
|
704 | 704 | return $invoice->get_key(); |
705 | 705 | } |
706 | 706 | |
@@ -950,7 +950,7 @@ discard block |
||
950 | 950 | return false; |
951 | 951 | } |
952 | 952 | $invoice = wpinv_get_invoice_cart(); |
953 | - if ( empty( $invoice ) ) { |
|
953 | + if ( empty( $invoice ) ) { |
|
954 | 954 | return false; |
955 | 955 | } |
956 | 956 | |
@@ -1247,20 +1247,20 @@ discard block |
||
1247 | 1247 | } |
1248 | 1248 | |
1249 | 1249 | function wpinv_checkout_get_cc_info() { |
1250 | - $cc_info = array(); |
|
1251 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
1252 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
1253 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
1254 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
1255 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
1256 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
1257 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
1258 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
1259 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
1260 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
1261 | - |
|
1262 | - // Return cc info |
|
1263 | - return $cc_info; |
|
1250 | + $cc_info = array(); |
|
1251 | + $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
1252 | + $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
1253 | + $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
1254 | + $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
1255 | + $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
1256 | + $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
1257 | + $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
1258 | + $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
1259 | + $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
1260 | + $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
1261 | + |
|
1262 | + // Return cc info |
|
1263 | + return $cc_info; |
|
1264 | 1264 | } |
1265 | 1265 | |
1266 | 1266 | function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
@@ -1467,7 +1467,7 @@ discard block |
||
1467 | 1467 | $required_fields = wpinv_checkout_required_fields(); |
1468 | 1468 | |
1469 | 1469 | // Loop through required fields and show error messages |
1470 | - if ( !empty( $required_fields ) ) { |
|
1470 | + if ( !empty( $required_fields ) ) { |
|
1471 | 1471 | foreach ( $required_fields as $field_name => $value ) { |
1472 | 1472 | if ( in_array( $value, $required_fields ) && empty( $_POST[ $field_name ] ) ) { |
1473 | 1473 | wpinv_set_error( $value['error_id'], $value['error_message'] ); |
@@ -1570,7 +1570,7 @@ discard block |
||
1570 | 1570 | } |
1571 | 1571 | |
1572 | 1572 | function wpinv_get_checkout_session() { |
1573 | - global $wpi_session; |
|
1573 | + global $wpi_session; |
|
1574 | 1574 | |
1575 | 1575 | return $wpi_session->get( 'wpinv_checkout' ); |
1576 | 1576 | } |
@@ -1651,7 +1651,7 @@ discard block |
||
1651 | 1651 | $response['data']['taxf'] = $invoice->get_tax( true ); |
1652 | 1652 | $response['data']['total'] = $invoice->get_total(); |
1653 | 1653 | $response['data']['totalf'] = $invoice->get_total( true ); |
1654 | - $response['data']['free'] = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false; |
|
1654 | + $response['data']['free'] = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false; |
|
1655 | 1655 | |
1656 | 1656 | wp_send_json( $response ); |
1657 | 1657 | } |
@@ -1936,57 +1936,57 @@ discard block |
||
1936 | 1936 | } |
1937 | 1937 | |
1938 | 1938 | function wpinv_get_invoice_id_by_key( $key ) { |
1939 | - global $wpdb; |
|
1939 | + global $wpdb; |
|
1940 | 1940 | |
1941 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
1941 | + $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
1942 | 1942 | |
1943 | - if ( $invoice_id != NULL ) |
|
1944 | - return $invoice_id; |
|
1943 | + if ( $invoice_id != NULL ) |
|
1944 | + return $invoice_id; |
|
1945 | 1945 | |
1946 | - return 0; |
|
1946 | + return 0; |
|
1947 | 1947 | } |
1948 | 1948 | |
1949 | 1949 | function wpinv_can_view_receipt( $invoice_key = '' ) { |
1950 | - $return = false; |
|
1950 | + $return = false; |
|
1951 | 1951 | |
1952 | - if ( empty( $invoice_key ) ) { |
|
1953 | - return $return; |
|
1954 | - } |
|
1952 | + if ( empty( $invoice_key ) ) { |
|
1953 | + return $return; |
|
1954 | + } |
|
1955 | 1955 | |
1956 | - global $wpinv_receipt_args; |
|
1956 | + global $wpinv_receipt_args; |
|
1957 | 1957 | |
1958 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1959 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
1960 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
1961 | - } |
|
1958 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1959 | + if ( isset( $_GET['invoice-id'] ) ) { |
|
1960 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
1961 | + } |
|
1962 | 1962 | |
1963 | - if ( empty( $wpinv_receipt_args['id'] ) ) { |
|
1964 | - return $return; |
|
1965 | - } |
|
1963 | + if ( empty( $wpinv_receipt_args['id'] ) ) { |
|
1964 | + return $return; |
|
1965 | + } |
|
1966 | 1966 | |
1967 | - $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] ); |
|
1968 | - if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) { |
|
1969 | - return $return; |
|
1970 | - } |
|
1967 | + $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] ); |
|
1968 | + if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) { |
|
1969 | + return $return; |
|
1970 | + } |
|
1971 | 1971 | |
1972 | - if ( is_user_logged_in() ) { |
|
1973 | - if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) { |
|
1974 | - $return = true; |
|
1975 | - } |
|
1976 | - } |
|
1972 | + if ( is_user_logged_in() ) { |
|
1973 | + if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) { |
|
1974 | + $return = true; |
|
1975 | + } |
|
1976 | + } |
|
1977 | 1977 | |
1978 | - $session = wpinv_get_checkout_session(); |
|
1979 | - if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) { |
|
1980 | - $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
1978 | + $session = wpinv_get_checkout_session(); |
|
1979 | + if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) { |
|
1980 | + $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
1981 | 1981 | |
1982 | - if ( wpinv_require_login_to_checkout() ) { |
|
1983 | - $return = $return && $check_key === $invoice_key; |
|
1984 | - } else { |
|
1985 | - $return = $check_key === $invoice_key; |
|
1986 | - } |
|
1987 | - } |
|
1982 | + if ( wpinv_require_login_to_checkout() ) { |
|
1983 | + $return = $return && $check_key === $invoice_key; |
|
1984 | + } else { |
|
1985 | + $return = $check_key === $invoice_key; |
|
1986 | + } |
|
1987 | + } |
|
1988 | 1988 | |
1989 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
1989 | + return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
1990 | 1990 | } |
1991 | 1991 | |
1992 | 1992 | function wpinv_pay_for_invoice() { |
@@ -2296,14 +2296,14 @@ discard block |
||
2296 | 2296 | |
2297 | 2297 | if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) { |
2298 | 2298 | $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : ''; |
2299 | - global $post; |
|
2299 | + global $post; |
|
2300 | 2300 | |
2301 | 2301 | if(!empty($invoice_key)){ |
2302 | - $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
2302 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
2303 | 2303 | } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) { |
2304 | - $invoice_id = $post->ID; |
|
2304 | + $invoice_id = $post->ID; |
|
2305 | 2305 | } else { |
2306 | - return; |
|
2306 | + return; |
|
2307 | 2307 | } |
2308 | 2308 | |
2309 | 2309 | $invoice = new WPInv_Invoice($invoice_id); |
@@ -2312,17 +2312,17 @@ discard block |
||
2312 | 2312 | return; |
2313 | 2313 | } |
2314 | 2314 | |
2315 | - if ( is_user_logged_in() ) { |
|
2316 | - if ( (int)$invoice->get_user_id() === get_current_user_id() ) { |
|
2317 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2318 | - } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2319 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2320 | - } |
|
2321 | - } else { |
|
2322 | - if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2323 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2324 | - } |
|
2325 | - } |
|
2315 | + if ( is_user_logged_in() ) { |
|
2316 | + if ( (int)$invoice->get_user_id() === get_current_user_id() ) { |
|
2317 | + update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2318 | + } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2319 | + update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2320 | + } |
|
2321 | + } else { |
|
2322 | + if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2323 | + update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2324 | + } |
|
2325 | + } |
|
2326 | 2326 | } |
2327 | 2327 | |
2328 | 2328 | } |
@@ -368,69 +368,69 @@ discard block |
||
368 | 368 | } |
369 | 369 | |
370 | 370 | function wpinv_get_pages( $with_slug = false, $default_label = NULL ) { |
371 | - $pages_options = array(); |
|
371 | + $pages_options = array(); |
|
372 | 372 | |
373 | - if( $default_label !== NULL && $default_label !== false ) { |
|
374 | - $pages_options = array( '' => $default_label ); // Blank option |
|
375 | - } |
|
373 | + if( $default_label !== NULL && $default_label !== false ) { |
|
374 | + $pages_options = array( '' => $default_label ); // Blank option |
|
375 | + } |
|
376 | 376 | |
377 | - $pages = get_pages(); |
|
378 | - if ( $pages ) { |
|
379 | - foreach ( $pages as $page ) { |
|
380 | - $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
377 | + $pages = get_pages(); |
|
378 | + if ( $pages ) { |
|
379 | + foreach ( $pages as $page ) { |
|
380 | + $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
381 | 381 | $pages_options[ $page->ID ] = $title; |
382 | - } |
|
383 | - } |
|
382 | + } |
|
383 | + } |
|
384 | 384 | |
385 | - return $pages_options; |
|
385 | + return $pages_options; |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | function wpinv_header_callback( $args ) { |
389 | - if ( !empty( $args['desc'] ) ) { |
|
389 | + if ( !empty( $args['desc'] ) ) { |
|
390 | 390 | echo $args['desc']; |
391 | 391 | } |
392 | 392 | } |
393 | 393 | |
394 | 394 | function wpinv_hidden_callback( $args ) { |
395 | - global $wpinv_options; |
|
396 | - |
|
397 | - if ( isset( $args['set_value'] ) ) { |
|
398 | - $value = $args['set_value']; |
|
399 | - } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
400 | - $value = $wpinv_options[ $args['id'] ]; |
|
401 | - } else { |
|
402 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
403 | - } |
|
404 | - |
|
405 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
406 | - $args['readonly'] = true; |
|
407 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
408 | - $name = ''; |
|
409 | - } else { |
|
410 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
411 | - } |
|
412 | - |
|
413 | - $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
395 | + global $wpinv_options; |
|
396 | + |
|
397 | + if ( isset( $args['set_value'] ) ) { |
|
398 | + $value = $args['set_value']; |
|
399 | + } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
400 | + $value = $wpinv_options[ $args['id'] ]; |
|
401 | + } else { |
|
402 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
403 | + } |
|
404 | + |
|
405 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
406 | + $args['readonly'] = true; |
|
407 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
408 | + $name = ''; |
|
409 | + } else { |
|
410 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
411 | + } |
|
412 | + |
|
413 | + $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
414 | 414 | |
415 | - echo $html; |
|
415 | + echo $html; |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | function wpinv_checkbox_callback( $args ) { |
419 | - global $wpinv_options; |
|
419 | + global $wpinv_options; |
|
420 | 420 | |
421 | 421 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
422 | 422 | |
423 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
424 | - $name = ''; |
|
425 | - } else { |
|
426 | - $name = 'name="wpinv_settings[' . $sanitize_id . ']"'; |
|
427 | - } |
|
423 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
424 | + $name = ''; |
|
425 | + } else { |
|
426 | + $name = 'name="wpinv_settings[' . $sanitize_id . ']"'; |
|
427 | + } |
|
428 | 428 | |
429 | - $checked = isset( $wpinv_options[ $args['id'] ] ) ? checked( 1, $wpinv_options[ $args['id'] ], false ) : ''; |
|
430 | - $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>'; |
|
431 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
429 | + $checked = isset( $wpinv_options[ $args['id'] ] ) ? checked( 1, $wpinv_options[ $args['id'] ], false ) : ''; |
|
430 | + $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>'; |
|
431 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
432 | 432 | |
433 | - echo $html; |
|
433 | + echo $html; |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | function wpinv_checkout_fields_callback( $args ) { |
@@ -438,260 +438,260 @@ discard block |
||
438 | 438 | } |
439 | 439 | |
440 | 440 | function wpinv_multicheck_callback( $args ) { |
441 | - global $wpinv_options; |
|
441 | + global $wpinv_options; |
|
442 | 442 | |
443 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
444 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
443 | + $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
444 | + $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
445 | 445 | |
446 | - if ( ! empty( $args['options'] ) ) { |
|
447 | - echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
|
446 | + if ( ! empty( $args['options'] ) ) { |
|
447 | + echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
|
448 | 448 | foreach( $args['options'] as $key => $option ): |
449 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
450 | - if ( isset( $wpinv_options[$args['id']][$sanitize_key] ) ) { |
|
451 | - $enabled = $sanitize_key; |
|
452 | - } else { |
|
453 | - $enabled = NULL; |
|
454 | - } |
|
455 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
456 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
457 | - endforeach; |
|
458 | - echo '</div>'; |
|
459 | - echo '<p class="description">' . $args['desc'] . '</p>'; |
|
460 | - } |
|
449 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
450 | + if ( isset( $wpinv_options[$args['id']][$sanitize_key] ) ) { |
|
451 | + $enabled = $sanitize_key; |
|
452 | + } else { |
|
453 | + $enabled = NULL; |
|
454 | + } |
|
455 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
456 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
457 | + endforeach; |
|
458 | + echo '</div>'; |
|
459 | + echo '<p class="description">' . $args['desc'] . '</p>'; |
|
460 | + } |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | function wpinv_payment_icons_callback( $args ) { |
464 | - global $wpinv_options; |
|
464 | + global $wpinv_options; |
|
465 | 465 | |
466 | 466 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
467 | 467 | |
468 | - if ( ! empty( $args['options'] ) ) { |
|
469 | - foreach( $args['options'] as $key => $option ) { |
|
468 | + if ( ! empty( $args['options'] ) ) { |
|
469 | + foreach( $args['options'] as $key => $option ) { |
|
470 | 470 | $sanitize_key = wpinv_sanitize_key( $key ); |
471 | 471 | |
472 | - if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
473 | - $enabled = $option; |
|
474 | - } else { |
|
475 | - $enabled = NULL; |
|
476 | - } |
|
477 | - |
|
478 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
479 | - |
|
480 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
481 | - |
|
482 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
483 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
484 | - } else { |
|
485 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
486 | - |
|
487 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
488 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
489 | - } else { |
|
490 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
491 | - $content_dir = WP_CONTENT_DIR; |
|
492 | - |
|
493 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
494 | - // Replaces backslashes with forward slashes for Windows systems |
|
495 | - $image = wp_normalize_path( $image ); |
|
496 | - $content_dir = wp_normalize_path( $content_dir ); |
|
497 | - } |
|
498 | - |
|
499 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
500 | - } |
|
501 | - |
|
502 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
503 | - } |
|
504 | - echo $option . '</label>'; |
|
505 | - } |
|
506 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
507 | - } |
|
472 | + if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
473 | + $enabled = $option; |
|
474 | + } else { |
|
475 | + $enabled = NULL; |
|
476 | + } |
|
477 | + |
|
478 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
479 | + |
|
480 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
481 | + |
|
482 | + if ( wpinv_string_is_image_url( $key ) ) { |
|
483 | + echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
484 | + } else { |
|
485 | + $card = strtolower( str_replace( ' ', '', $option ) ); |
|
486 | + |
|
487 | + if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
488 | + $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
489 | + } else { |
|
490 | + $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
491 | + $content_dir = WP_CONTENT_DIR; |
|
492 | + |
|
493 | + if ( function_exists( 'wp_normalize_path' ) ) { |
|
494 | + // Replaces backslashes with forward slashes for Windows systems |
|
495 | + $image = wp_normalize_path( $image ); |
|
496 | + $content_dir = wp_normalize_path( $content_dir ); |
|
497 | + } |
|
498 | + |
|
499 | + $image = str_replace( $content_dir, content_url(), $image ); |
|
500 | + } |
|
501 | + |
|
502 | + echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
503 | + } |
|
504 | + echo $option . '</label>'; |
|
505 | + } |
|
506 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
507 | + } |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | function wpinv_radio_callback( $args ) { |
511 | - global $wpinv_options; |
|
511 | + global $wpinv_options; |
|
512 | 512 | |
513 | 513 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
514 | 514 | |
515 | 515 | foreach ( $args['options'] as $key => $option ) : |
516 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
516 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
517 | 517 | |
518 | 518 | $checked = false; |
519 | 519 | |
520 | - if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) |
|
521 | - $checked = true; |
|
522 | - elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) |
|
523 | - $checked = true; |
|
520 | + if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) |
|
521 | + $checked = true; |
|
522 | + elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) |
|
523 | + $checked = true; |
|
524 | 524 | |
525 | - echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/> '; |
|
526 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>'; |
|
527 | - endforeach; |
|
525 | + echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/> '; |
|
526 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>'; |
|
527 | + endforeach; |
|
528 | 528 | |
529 | - echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
529 | + echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | function wpinv_gateways_callback( $args ) { |
533 | - global $wpinv_options; |
|
533 | + global $wpinv_options; |
|
534 | 534 | |
535 | 535 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
536 | 536 | |
537 | - foreach ( $args['options'] as $key => $option ) : |
|
538 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
537 | + foreach ( $args['options'] as $key => $option ) : |
|
538 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
539 | 539 | |
540 | 540 | if ( isset( $wpinv_options['gateways'][ $key ] ) ) |
541 | - $enabled = '1'; |
|
542 | - else |
|
543 | - $enabled = null; |
|
541 | + $enabled = '1'; |
|
542 | + else |
|
543 | + $enabled = null; |
|
544 | 544 | |
545 | - echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
546 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
547 | - endforeach; |
|
545 | + echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
546 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
547 | + endforeach; |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | function wpinv_gateway_select_callback($args) { |
551 | - global $wpinv_options; |
|
551 | + global $wpinv_options; |
|
552 | 552 | |
553 | 553 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
554 | 554 | $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
555 | 555 | |
556 | - echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
556 | + echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
557 | 557 | |
558 | - foreach ( $args['options'] as $key => $option ) : |
|
559 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
558 | + foreach ( $args['options'] as $key => $option ) : |
|
559 | + if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
560 | 560 | $selected = selected( $key, $args['selected'], false ); |
561 | 561 | } else { |
562 | 562 | $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : ''; |
563 | 563 | } |
564 | - echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
565 | - endforeach; |
|
564 | + echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
565 | + endforeach; |
|
566 | 566 | |
567 | - echo '</select>'; |
|
568 | - echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
567 | + echo '</select>'; |
|
568 | + echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
569 | 569 | } |
570 | 570 | |
571 | 571 | function wpinv_text_callback( $args ) { |
572 | - global $wpinv_options; |
|
572 | + global $wpinv_options; |
|
573 | 573 | |
574 | 574 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
575 | 575 | |
576 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
577 | - $value = $wpinv_options[ $args['id'] ]; |
|
578 | - } else { |
|
579 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
580 | - } |
|
581 | - |
|
582 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
583 | - $args['readonly'] = true; |
|
584 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
585 | - $name = ''; |
|
586 | - } else { |
|
587 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
588 | - } |
|
589 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
590 | - |
|
591 | - $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
|
592 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
593 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
594 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
595 | - |
|
596 | - echo $html; |
|
576 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
577 | + $value = $wpinv_options[ $args['id'] ]; |
|
578 | + } else { |
|
579 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
580 | + } |
|
581 | + |
|
582 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
583 | + $args['readonly'] = true; |
|
584 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
585 | + $name = ''; |
|
586 | + } else { |
|
587 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
588 | + } |
|
589 | + $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
590 | + |
|
591 | + $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
|
592 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
593 | + $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
594 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
595 | + |
|
596 | + echo $html; |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | function wpinv_number_callback( $args ) { |
600 | - global $wpinv_options; |
|
600 | + global $wpinv_options; |
|
601 | 601 | |
602 | 602 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
603 | 603 | |
604 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
605 | - $value = $wpinv_options[ $args['id'] ]; |
|
606 | - } else { |
|
607 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
608 | - } |
|
609 | - |
|
610 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
611 | - $args['readonly'] = true; |
|
612 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
613 | - $name = ''; |
|
614 | - } else { |
|
615 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
616 | - } |
|
617 | - |
|
618 | - $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
619 | - $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
620 | - $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
621 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
622 | - |
|
623 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
624 | - $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
625 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
626 | - |
|
627 | - echo $html; |
|
604 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
605 | + $value = $wpinv_options[ $args['id'] ]; |
|
606 | + } else { |
|
607 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
608 | + } |
|
609 | + |
|
610 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
611 | + $args['readonly'] = true; |
|
612 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
613 | + $name = ''; |
|
614 | + } else { |
|
615 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
616 | + } |
|
617 | + |
|
618 | + $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
619 | + $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
620 | + $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
621 | + $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
622 | + |
|
623 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
624 | + $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
625 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
626 | + |
|
627 | + echo $html; |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | function wpinv_textarea_callback( $args ) { |
631 | - global $wpinv_options; |
|
631 | + global $wpinv_options; |
|
632 | 632 | |
633 | 633 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
634 | 634 | |
635 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
636 | - $value = $wpinv_options[ $args['id'] ]; |
|
637 | - } else { |
|
638 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
639 | - } |
|
635 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
636 | + $value = $wpinv_options[ $args['id'] ]; |
|
637 | + } else { |
|
638 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
639 | + } |
|
640 | 640 | |
641 | 641 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
642 | 642 | $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
643 | 643 | |
644 | - $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
645 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
644 | + $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
645 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
646 | 646 | |
647 | - echo $html; |
|
647 | + echo $html; |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | function wpinv_password_callback( $args ) { |
651 | - global $wpinv_options; |
|
651 | + global $wpinv_options; |
|
652 | 652 | |
653 | 653 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
654 | 654 | |
655 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
656 | - $value = $wpinv_options[ $args['id'] ]; |
|
657 | - } else { |
|
658 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
659 | - } |
|
655 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
656 | + $value = $wpinv_options[ $args['id'] ]; |
|
657 | + } else { |
|
658 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
659 | + } |
|
660 | 660 | |
661 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
662 | - $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
663 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
661 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
662 | + $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
663 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
664 | 664 | |
665 | - echo $html; |
|
665 | + echo $html; |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | function wpinv_missing_callback($args) { |
669 | - printf( |
|
670 | - __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
671 | - '<strong>' . $args['id'] . '</strong>' |
|
672 | - ); |
|
669 | + printf( |
|
670 | + __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
671 | + '<strong>' . $args['id'] . '</strong>' |
|
672 | + ); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | function wpinv_select_callback($args) { |
676 | - global $wpinv_options; |
|
676 | + global $wpinv_options; |
|
677 | 677 | |
678 | 678 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
679 | 679 | |
680 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
681 | - $value = $wpinv_options[ $args['id'] ]; |
|
682 | - } else { |
|
683 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
684 | - } |
|
680 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
681 | + $value = $wpinv_options[ $args['id'] ]; |
|
682 | + } else { |
|
683 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
684 | + } |
|
685 | 685 | |
686 | 686 | if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
687 | 687 | $value = $args['selected']; |
688 | 688 | } |
689 | 689 | |
690 | - if ( isset( $args['placeholder'] ) ) { |
|
691 | - $placeholder = $args['placeholder']; |
|
692 | - } else { |
|
693 | - $placeholder = ''; |
|
694 | - } |
|
690 | + if ( isset( $args['placeholder'] ) ) { |
|
691 | + $placeholder = $args['placeholder']; |
|
692 | + } else { |
|
693 | + $placeholder = ''; |
|
694 | + } |
|
695 | 695 | |
696 | 696 | if( !empty( $args['onchange'] ) ) { |
697 | 697 | $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
@@ -701,142 +701,142 @@ discard block |
||
701 | 701 | |
702 | 702 | $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
703 | 703 | |
704 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
704 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
705 | 705 | |
706 | - foreach ( $args['options'] as $option => $name ) { |
|
707 | - $selected = selected( $option, $value, false ); |
|
708 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
709 | - } |
|
706 | + foreach ( $args['options'] as $option => $name ) { |
|
707 | + $selected = selected( $option, $value, false ); |
|
708 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
709 | + } |
|
710 | 710 | |
711 | - $html .= '</select>'; |
|
712 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
711 | + $html .= '</select>'; |
|
712 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
713 | 713 | |
714 | - echo $html; |
|
714 | + echo $html; |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | function wpinv_color_select_callback( $args ) { |
718 | - global $wpinv_options; |
|
718 | + global $wpinv_options; |
|
719 | 719 | |
720 | 720 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
721 | 721 | |
722 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
723 | - $value = $wpinv_options[ $args['id'] ]; |
|
724 | - } else { |
|
725 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
726 | - } |
|
722 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
723 | + $value = $wpinv_options[ $args['id'] ]; |
|
724 | + } else { |
|
725 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
726 | + } |
|
727 | 727 | |
728 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
728 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
729 | 729 | |
730 | - foreach ( $args['options'] as $option => $color ) { |
|
731 | - $selected = selected( $option, $value, false ); |
|
732 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
733 | - } |
|
730 | + foreach ( $args['options'] as $option => $color ) { |
|
731 | + $selected = selected( $option, $value, false ); |
|
732 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
733 | + } |
|
734 | 734 | |
735 | - $html .= '</select>'; |
|
736 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
735 | + $html .= '</select>'; |
|
736 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
737 | 737 | |
738 | - echo $html; |
|
738 | + echo $html; |
|
739 | 739 | } |
740 | 740 | |
741 | 741 | function wpinv_rich_editor_callback( $args ) { |
742 | - global $wpinv_options, $wp_version; |
|
742 | + global $wpinv_options, $wp_version; |
|
743 | 743 | |
744 | 744 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
745 | 745 | |
746 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
747 | - $value = $wpinv_options[ $args['id'] ]; |
|
746 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
747 | + $value = $wpinv_options[ $args['id'] ]; |
|
748 | 748 | |
749 | - if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
750 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
751 | - } |
|
752 | - } else { |
|
753 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
754 | - } |
|
749 | + if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
750 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
751 | + } |
|
752 | + } else { |
|
753 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
754 | + } |
|
755 | 755 | |
756 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
756 | + $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
757 | 757 | |
758 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
759 | - ob_start(); |
|
760 | - wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
761 | - $html = ob_get_clean(); |
|
762 | - } else { |
|
763 | - $html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
764 | - } |
|
758 | + if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
759 | + ob_start(); |
|
760 | + wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
761 | + $html = ob_get_clean(); |
|
762 | + } else { |
|
763 | + $html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
764 | + } |
|
765 | 765 | |
766 | - $html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
766 | + $html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
767 | 767 | |
768 | - echo $html; |
|
768 | + echo $html; |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | function wpinv_upload_callback( $args ) { |
772 | - global $wpinv_options; |
|
772 | + global $wpinv_options; |
|
773 | 773 | |
774 | 774 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
775 | 775 | |
776 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
777 | - $value = $wpinv_options[$args['id']]; |
|
778 | - } else { |
|
779 | - $value = isset($args['std']) ? $args['std'] : ''; |
|
780 | - } |
|
776 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
777 | + $value = $wpinv_options[$args['id']]; |
|
778 | + } else { |
|
779 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
780 | + } |
|
781 | 781 | |
782 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
783 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
784 | - $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
785 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
782 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
783 | + $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
784 | + $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
785 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
786 | 786 | |
787 | - echo $html; |
|
787 | + echo $html; |
|
788 | 788 | } |
789 | 789 | |
790 | 790 | function wpinv_color_callback( $args ) { |
791 | - global $wpinv_options; |
|
791 | + global $wpinv_options; |
|
792 | 792 | |
793 | 793 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
794 | 794 | |
795 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
796 | - $value = $wpinv_options[ $args['id'] ]; |
|
797 | - } else { |
|
798 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
799 | - } |
|
795 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
796 | + $value = $wpinv_options[ $args['id'] ]; |
|
797 | + } else { |
|
798 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
799 | + } |
|
800 | 800 | |
801 | - $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
801 | + $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
802 | 802 | |
803 | - $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
804 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
803 | + $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
804 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
805 | 805 | |
806 | - echo $html; |
|
806 | + echo $html; |
|
807 | 807 | } |
808 | 808 | |
809 | 809 | function wpinv_country_states_callback($args) { |
810 | - global $wpinv_options; |
|
810 | + global $wpinv_options; |
|
811 | 811 | |
812 | 812 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
813 | 813 | |
814 | - if ( isset( $args['placeholder'] ) ) { |
|
815 | - $placeholder = $args['placeholder']; |
|
816 | - } else { |
|
817 | - $placeholder = ''; |
|
818 | - } |
|
814 | + if ( isset( $args['placeholder'] ) ) { |
|
815 | + $placeholder = $args['placeholder']; |
|
816 | + } else { |
|
817 | + $placeholder = ''; |
|
818 | + } |
|
819 | 819 | |
820 | - $states = wpinv_get_country_states(); |
|
820 | + $states = wpinv_get_country_states(); |
|
821 | 821 | |
822 | - $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
823 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
822 | + $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
823 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
824 | 824 | |
825 | - foreach ( $states as $option => $name ) { |
|
826 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
827 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
828 | - } |
|
825 | + foreach ( $states as $option => $name ) { |
|
826 | + $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
827 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
828 | + } |
|
829 | 829 | |
830 | - $html .= '</select>'; |
|
831 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
830 | + $html .= '</select>'; |
|
831 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
832 | 832 | |
833 | - echo $html; |
|
833 | + echo $html; |
|
834 | 834 | } |
835 | 835 | |
836 | 836 | function wpinv_tax_rates_callback($args) { |
837 | - global $wpinv_options; |
|
838 | - $rates = wpinv_get_tax_rates(); |
|
839 | - ob_start(); ?> |
|
837 | + global $wpinv_options; |
|
838 | + $rates = wpinv_get_tax_rates(); |
|
839 | + ob_start(); ?> |
|
840 | 840 | </td><tr> |
841 | 841 | <td colspan="2" class="wpinv_tax_tdbox"> |
842 | 842 | <p><?php echo $args['desc']; ?></p> |
@@ -860,40 +860,40 @@ discard block |
||
860 | 860 | <tr> |
861 | 861 | <td class="wpinv_tax_country"> |
862 | 862 | <?php |
863 | - echo wpinv_html_select( array( |
|
864 | - 'options' => wpinv_get_country_list( true ), |
|
865 | - 'name' => 'tax_rates[' . $sanitized_key . '][country]', |
|
863 | + echo wpinv_html_select( array( |
|
864 | + 'options' => wpinv_get_country_list( true ), |
|
865 | + 'name' => 'tax_rates[' . $sanitized_key . '][country]', |
|
866 | 866 | 'id' => 'tax_rates[' . $sanitized_key . '][country]', |
867 | - 'selected' => $rate['country'], |
|
868 | - 'show_option_all' => false, |
|
869 | - 'show_option_none' => false, |
|
870 | - 'class' => 'wpinv-tax-country wpi_select2', |
|
871 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
872 | - ) ); |
|
873 | - ?> |
|
867 | + 'selected' => $rate['country'], |
|
868 | + 'show_option_all' => false, |
|
869 | + 'show_option_none' => false, |
|
870 | + 'class' => 'wpinv-tax-country wpi_select2', |
|
871 | + 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
872 | + ) ); |
|
873 | + ?> |
|
874 | 874 | </td> |
875 | 875 | <td class="wpinv_tax_state"> |
876 | 876 | <?php |
877 | - $states = wpinv_get_country_states( $rate['country'] ); |
|
878 | - if( !empty( $states ) ) { |
|
879 | - echo wpinv_html_select( array( |
|
880 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
881 | - 'name' => 'tax_rates[' . $sanitized_key . '][state]', |
|
877 | + $states = wpinv_get_country_states( $rate['country'] ); |
|
878 | + if( !empty( $states ) ) { |
|
879 | + echo wpinv_html_select( array( |
|
880 | + 'options' => array_merge( array( '' => '' ), $states ), |
|
881 | + 'name' => 'tax_rates[' . $sanitized_key . '][state]', |
|
882 | 882 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
883 | - 'selected' => $rate['state'], |
|
884 | - 'show_option_all' => false, |
|
885 | - 'show_option_none' => false, |
|
883 | + 'selected' => $rate['state'], |
|
884 | + 'show_option_all' => false, |
|
885 | + 'show_option_none' => false, |
|
886 | 886 | 'class' => 'wpi_select2', |
887 | - 'placeholder' => __( 'Choose a state', 'invoicing' ) |
|
888 | - ) ); |
|
889 | - } else { |
|
890 | - echo wpinv_html_text( array( |
|
891 | - 'name' => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'], |
|
892 | - 'value' => ! empty( $rate['state'] ) ? $rate['state'] : '', |
|
887 | + 'placeholder' => __( 'Choose a state', 'invoicing' ) |
|
888 | + ) ); |
|
889 | + } else { |
|
890 | + echo wpinv_html_text( array( |
|
891 | + 'name' => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'], |
|
892 | + 'value' => ! empty( $rate['state'] ) ? $rate['state'] : '', |
|
893 | 893 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
894 | - ) ); |
|
895 | - } |
|
896 | - ?> |
|
894 | + ) ); |
|
895 | + } |
|
896 | + ?> |
|
897 | 897 | </td> |
898 | 898 | <td class="wpinv_tax_global"> |
899 | 899 | <input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/> |
@@ -908,19 +908,19 @@ discard block |
||
908 | 908 | <tr> |
909 | 909 | <td class="wpinv_tax_country"> |
910 | 910 | <?php |
911 | - echo wpinv_html_select( array( |
|
912 | - 'options' => wpinv_get_country_list( true ), |
|
913 | - 'name' => 'tax_rates[0][country]', |
|
914 | - 'show_option_all' => false, |
|
915 | - 'show_option_none' => false, |
|
916 | - 'class' => 'wpinv-tax-country wpi_select2', |
|
917 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
918 | - ) ); ?> |
|
911 | + echo wpinv_html_select( array( |
|
912 | + 'options' => wpinv_get_country_list( true ), |
|
913 | + 'name' => 'tax_rates[0][country]', |
|
914 | + 'show_option_all' => false, |
|
915 | + 'show_option_none' => false, |
|
916 | + 'class' => 'wpinv-tax-country wpi_select2', |
|
917 | + 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
918 | + ) ); ?> |
|
919 | 919 | </td> |
920 | 920 | <td class="wpinv_tax_state"> |
921 | 921 | <?php echo wpinv_html_text( array( |
922 | - 'name' => 'tax_rates[0][state]' |
|
923 | - ) ); ?> |
|
922 | + 'name' => 'tax_rates[0][state]' |
|
923 | + ) ); ?> |
|
924 | 924 | </td> |
925 | 925 | <td class="wpinv_tax_global"> |
926 | 926 | <input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/> |
@@ -935,7 +935,7 @@ discard block |
||
935 | 935 | <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot> |
936 | 936 | </table> |
937 | 937 | <?php |
938 | - echo ob_get_clean(); |
|
938 | + echo ob_get_clean(); |
|
939 | 939 | } |
940 | 940 | |
941 | 941 | function wpinv_tools_callback($args) { |
@@ -963,15 +963,15 @@ discard block |
||
963 | 963 | } |
964 | 964 | |
965 | 965 | function wpinv_descriptive_text_callback( $args ) { |
966 | - echo wp_kses_post( $args['desc'] ); |
|
966 | + echo wp_kses_post( $args['desc'] ); |
|
967 | 967 | } |
968 | 968 | |
969 | 969 | function wpinv_hook_callback( $args ) { |
970 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
970 | + do_action( 'wpinv_' . $args['id'], $args ); |
|
971 | 971 | } |
972 | 972 | |
973 | 973 | function wpinv_set_settings_cap() { |
974 | - return wpinv_get_capability(); |
|
974 | + return wpinv_get_capability(); |
|
975 | 975 | } |
976 | 976 | add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
977 | 977 |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) { |
503 | 503 | |
504 | 504 | // Sweetalert https://sweetalert2.github.io/. |
505 | - wp_register_script( 'promise-polyfill', WPINV_PLUGIN_URL . 'assets/vendor/sweetalert/promise-polyfill.min.js', array(), '8.1.3', true ); |
|
505 | + wp_register_script( 'promise-polyfill', WPINV_PLUGIN_URL . 'assets/vendor/sweetalert/promise-polyfill.min.js', array(), '8.1.3', true ); |
|
506 | 506 | wp_register_script( 'sweetalert2', WPINV_PLUGIN_URL . 'assets/vendor/sweetalert/sweetalert2.all.min.js', array( 'promise-polyfill' ), '9.6.0', true ); |
507 | 507 | |
508 | 508 | // Vue js. |
@@ -527,9 +527,9 @@ discard block |
||
527 | 527 | ); |
528 | 528 | |
529 | 529 | // localize and enqueue the script with all of the variable inserted. |
530 | - wp_localize_script( 'wpinv-field-editor', 'wpinvFieldEditor', $params ); |
|
530 | + wp_localize_script( 'wpinv-field-editor', 'wpinvFieldEditor', $params ); |
|
531 | 531 | |
532 | - wp_enqueue_script( 'wpinv-field-editor' ); |
|
532 | + wp_enqueue_script( 'wpinv-field-editor' ); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | } |