Passed
Push — master ( d8912d...4b0495 )
by Brian
05:06
created
includes/class-wpinv-discount.php 1 patch
Indentation   +1261 added lines, -1261 removed lines patch added patch discarded remove patch
@@ -15,30 +15,30 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class WPInv_Discount extends GetPaid_Data  {
17 17
 
18
-	/**
19
-	 * Which data store to load.
20
-	 *
21
-	 * @var string
22
-	 */
18
+    /**
19
+     * Which data store to load.
20
+     *
21
+     * @var string
22
+     */
23 23
     protected $data_store_name = 'discount';
24 24
 
25 25
     /**
26
-	 * This is the name of this object type.
27
-	 *
28
-	 * @var string
29
-	 */
30
-	protected $object_type = 'discount';
31
-
32
-	/**
33
-	 * Discount Data array. This is the core item data exposed in APIs.
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array(
39
-		'status'               => 'draft',
40
-		'version'              => '',
41
-		'date_created'         => null,
26
+     * This is the name of this object type.
27
+     *
28
+     * @var string
29
+     */
30
+    protected $object_type = 'discount';
31
+
32
+    /**
33
+     * Discount Data array. This is the core item data exposed in APIs.
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array(
39
+        'status'               => 'draft',
40
+        'version'              => '',
41
+        'date_created'         => null,
42 42
         'date_modified'        => null,
43 43
         'name'                 => 'no-name',
44 44
         'description'          => '',
@@ -58,144 +58,144 @@  discard block
 block discarded – undo
58 58
         'amount'               => null,
59 59
     );
60 60
 
61
-	/**
62
-	 * Stores meta in cache for future reads.
63
-	 *
64
-	 * A group must be set to to enable caching.
65
-	 *
66
-	 * @var string
67
-	 */
68
-	protected $cache_group = 'getpaid_discounts';
61
+    /**
62
+     * Stores meta in cache for future reads.
63
+     *
64
+     * A group must be set to to enable caching.
65
+     *
66
+     * @var string
67
+     */
68
+    protected $cache_group = 'getpaid_discounts';
69 69
 
70 70
     /**
71 71
      * Stores a reference to the original WP_Post object
72 72
      *
73 73
      * @var WP_Post
74 74
      */
75
-	protected $post = null;
76
-
77
-	/**
78
-	 * Get the discount if ID is passed, otherwise the discount is new and empty.
79
-	 *
80
-	 * @param int|array|string|WPInv_Discount|WP_Post $discount discount data, object, ID or code.
81
-	 */
82
-	public function __construct( $discount = 0 ) {
83
-		parent::__construct( $discount );
84
-
85
-		if ( is_numeric( $discount ) && 'wpi_discount' === get_post_type( $discount ) ) {
86
-			$this->set_id( $discount );
87
-		} elseif ( $discount instanceof self ) {
88
-			$this->set_id( $discount->get_id() );
89
-		} elseif ( ! empty( $discount->ID ) ) {
90
-			$this->set_id( $discount->ID );
91
-		} elseif ( is_array( $discount ) ) {
92
-			$this->set_props( $discount );
93
-
94
-			if ( isset( $discount['ID'] ) ) {
95
-				$this->set_id( $discount['ID'] );
96
-			}
97
-
98
-		} elseif ( is_scalar( $discount ) && $discount = self::get_discount_id_by_code( $discount ) ) {
99
-			$this->set_id( $discount );
100
-		} else {
101
-			$this->set_object_read( true );
102
-		}
75
+    protected $post = null;
76
+
77
+    /**
78
+     * Get the discount if ID is passed, otherwise the discount is new and empty.
79
+     *
80
+     * @param int|array|string|WPInv_Discount|WP_Post $discount discount data, object, ID or code.
81
+     */
82
+    public function __construct( $discount = 0 ) {
83
+        parent::__construct( $discount );
84
+
85
+        if ( is_numeric( $discount ) && 'wpi_discount' === get_post_type( $discount ) ) {
86
+            $this->set_id( $discount );
87
+        } elseif ( $discount instanceof self ) {
88
+            $this->set_id( $discount->get_id() );
89
+        } elseif ( ! empty( $discount->ID ) ) {
90
+            $this->set_id( $discount->ID );
91
+        } elseif ( is_array( $discount ) ) {
92
+            $this->set_props( $discount );
93
+
94
+            if ( isset( $discount['ID'] ) ) {
95
+                $this->set_id( $discount['ID'] );
96
+            }
97
+
98
+        } elseif ( is_scalar( $discount ) && $discount = self::get_discount_id_by_code( $discount ) ) {
99
+            $this->set_id( $discount );
100
+        } else {
101
+            $this->set_object_read( true );
102
+        }
103 103
 
104 104
         // Load the datastore.
105
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
105
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
106 106
 
107
-		if ( $this->get_id() > 0 ) {
107
+        if ( $this->get_id() > 0 ) {
108 108
             $this->post = get_post( $this->get_id() );
109 109
             $this->ID   = $this->get_id();
110
-			$this->data_store->read( $this );
110
+            $this->data_store->read( $this );
111
+        }
112
+
113
+    }
114
+
115
+    /**
116
+     * Fetch a discount from the db/cache
117
+     *
118
+     *
119
+     * @static
120
+     * @param string $field The field to query against: 'ID', 'discount_code'
121
+     * @param string|int $value The field value
122
+     * @deprecated
123
+     * @since 1.0.15
124
+     * @return array|bool array of discount details on success. False otherwise.
125
+     */
126
+    public static function get_data_by( $field, $value ) {
127
+
128
+        if ( 'id' == strtolower( $field ) ) {
129
+            // Make sure the value is numeric to avoid casting objects, for example,
130
+            // to int 1.
131
+            if ( ! is_numeric( $value ) )
132
+                return false;
133
+            $value = intval( $value );
134
+            if ( $value < 1 )
135
+                return false;
136
+        }
137
+
138
+        if ( ! $value || ! is_string( $field ) ) {
139
+            return false;
140
+        }
141
+
142
+        $field = trim( $field );
143
+
144
+        // prepare query args
145
+        switch ( strtolower( $field ) ) {
146
+            case 'id':
147
+                $discount_id = $value;
148
+                $args		 = array( 'include' => array( $value ) );
149
+                break;
150
+            case 'discount_code':
151
+            case 'code':
152
+                $value       = trim( $value );
153
+                $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' );
154
+                $args		 = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value );
155
+                break;
156
+            case 'name':
157
+                $discount_id = 0;
158
+                $args		 = array( 'name' => trim( $value ) );
159
+                break;
160
+            default:
161
+                $args		 = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value );
162
+                if ( ! is_array( $args ) ) {
163
+                    return apply_filters( "wpinv_discount_get_data_by_$field", false, $value );
164
+                }
165
+
166
+        }
167
+
168
+        // Check if there is a cached value.
169
+        if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) {
170
+            return $discount;
171
+        }
172
+
173
+        $args = array_merge(
174
+            $args,
175
+            array(
176
+                'post_type'      => 'wpi_discount',
177
+                'posts_per_page' => 1,
178
+                'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
179
+            )
180
+        );
181
+
182
+        $discount = get_posts( $args );
183
+
184
+        if( empty( $discount ) ) {
185
+            return false;
111 186
         }
112 187
 
113
-	}
114
-
115
-	/**
116
-	 * Fetch a discount from the db/cache
117
-	 *
118
-	 *
119
-	 * @static
120
-	 * @param string $field The field to query against: 'ID', 'discount_code'
121
-	 * @param string|int $value The field value
122
-	 * @deprecated
123
-	 * @since 1.0.15
124
-	 * @return array|bool array of discount details on success. False otherwise.
125
-	 */
126
-	public static function get_data_by( $field, $value ) {
127
-
128
-		if ( 'id' == strtolower( $field ) ) {
129
-			// Make sure the value is numeric to avoid casting objects, for example,
130
-			// to int 1.
131
-			if ( ! is_numeric( $value ) )
132
-				return false;
133
-			$value = intval( $value );
134
-			if ( $value < 1 )
135
-				return false;
136
-		}
137
-
138
-		if ( ! $value || ! is_string( $field ) ) {
139
-			return false;
140
-		}
141
-
142
-		$field = trim( $field );
143
-
144
-		// prepare query args
145
-		switch ( strtolower( $field ) ) {
146
-			case 'id':
147
-				$discount_id = $value;
148
-				$args		 = array( 'include' => array( $value ) );
149
-				break;
150
-			case 'discount_code':
151
-			case 'code':
152
-				$value       = trim( $value );
153
-				$discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' );
154
-				$args		 = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value );
155
-				break;
156
-			case 'name':
157
-				$discount_id = 0;
158
-				$args		 = array( 'name' => trim( $value ) );
159
-				break;
160
-			default:
161
-				$args		 = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value );
162
-				if ( ! is_array( $args ) ) {
163
-					return apply_filters( "wpinv_discount_get_data_by_$field", false, $value );
164
-				}
165
-
166
-		}
167
-
168
-		// Check if there is a cached value.
169
-		if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) {
170
-			return $discount;
171
-		}
172
-
173
-		$args = array_merge(
174
-			$args,
175
-			array(
176
-				'post_type'      => 'wpi_discount',
177
-				'posts_per_page' => 1,
178
-				'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
179
-			)
180
-		);
181
-
182
-		$discount = get_posts( $args );
183
-
184
-		if( empty( $discount ) ) {
185
-			return false;
186
-		}
187
-
188
-		$discount = $discount[0];
189
-
190
-		// Prepare the return data.
191
-		$return = array(
188
+        $discount = $discount[0];
189
+
190
+        // Prepare the return data.
191
+        $return = array(
192 192
             'ID'                          => $discount->ID,
193 193
             'code'                        => get_post_meta( $discount->ID, '_wpi_discount_code', true ),
194 194
             'amount'                      => get_post_meta( $discount->ID, '_wpi_discount_amount', true ),
195 195
             'date_created'                => $discount->post_date,
196
-			'date_modified'               => $discount->post_modified,
197
-			'status'               		  => $discount->post_status,
198
-			'start'                  	  => get_post_meta( $discount->ID, '_wpi_discount_start', true ),
196
+            'date_modified'               => $discount->post_modified,
197
+            'status'               		  => $discount->post_status,
198
+            'start'                  	  => get_post_meta( $discount->ID, '_wpi_discount_start', true ),
199 199
             'expiration'                  => get_post_meta( $discount->ID, '_wpi_discount_expiration', true ),
200 200
             'type'               		  => get_post_meta( $discount->ID, '_wpi_discount_type', true ),
201 201
             'description'                 => $discount->post_excerpt,
@@ -209,77 +209,77 @@  discard block
 block discarded – undo
209 209
             'max_total'                   => get_post_meta( $discount->ID, '_wpi_discount_max_total', true ),
210 210
         );
211 211
 
212
-		$return = apply_filters( 'wpinv_discount_properties', $return );
213
-
214
-		// Update the cache with our data
215
-		wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' );
216
-		wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' );
217
-
218
-		return $return;
219
-	}
220
-
221
-	/**
222
-	 * Given a discount code, it returns a discount id.
223
-	 *
224
-	 *
225
-	 * @static
226
-	 * @param string $discount_code
227
-	 * @since 1.0.15
228
-	 * @return int
229
-	 */
230
-	public static function get_discount_id_by_code( $discount_code ) {
231
-
232
-		// Trim the code.
233
-		$discount_code = trim( $discount_code );
234
-
235
-		// Ensure a value has been passed.
236
-		if ( empty( $discount_code ) ) {
237
-			return 0;
238
-		}
239
-
240
-		// Maybe retrieve from the cache.
241
-		$discount_id   = wp_cache_get( $discount_code, 'getpaid_discount_codes' );
242
-		if ( ! empty( $discount_id ) ) {
243
-			return $discount_id;
244
-		}
245
-
246
-		// Fetch the first discount codes.
247
-		$discounts = get_posts(
248
-			array(
249
-				'meta_key'       => '_wpi_discount_code',
250
-				'meta_value'     => $discount_code,
251
-				'post_type'      => 'wpi_discount',
252
-				'posts_per_page' => 1,
253
-				'post_status'    => array( 'publish', 'pending', 'draft', 'expired' ),
254
-				'fields'         => 'ids',
255
-			)
256
-		);
257
-
258
-		if ( empty( $discounts ) ) {
259
-			return 0;
260
-		}
261
-
262
-		$discount_id = $discounts[0];
263
-
264
-		// Update the cache with our data
265
-		wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' );
266
-
267
-		return $discount_id;
268
-	}
269
-
270
-	/**
271
-	 * Magic method for checking the existence of a certain custom field.
272
-	 *
273
-	 * @since 1.0.15
274
-	 * @access public
275
-	 *
276
-	 * @return bool Whether the given discount field is set.
277
-	 */
278
-	public function __isset( $key ){
279
-		return isset( $this->data[$key] ) || method_exists( $this, "get_$key");
280
-	}
281
-
282
-	/*
212
+        $return = apply_filters( 'wpinv_discount_properties', $return );
213
+
214
+        // Update the cache with our data
215
+        wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' );
216
+        wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' );
217
+
218
+        return $return;
219
+    }
220
+
221
+    /**
222
+     * Given a discount code, it returns a discount id.
223
+     *
224
+     *
225
+     * @static
226
+     * @param string $discount_code
227
+     * @since 1.0.15
228
+     * @return int
229
+     */
230
+    public static function get_discount_id_by_code( $discount_code ) {
231
+
232
+        // Trim the code.
233
+        $discount_code = trim( $discount_code );
234
+
235
+        // Ensure a value has been passed.
236
+        if ( empty( $discount_code ) ) {
237
+            return 0;
238
+        }
239
+
240
+        // Maybe retrieve from the cache.
241
+        $discount_id   = wp_cache_get( $discount_code, 'getpaid_discount_codes' );
242
+        if ( ! empty( $discount_id ) ) {
243
+            return $discount_id;
244
+        }
245
+
246
+        // Fetch the first discount codes.
247
+        $discounts = get_posts(
248
+            array(
249
+                'meta_key'       => '_wpi_discount_code',
250
+                'meta_value'     => $discount_code,
251
+                'post_type'      => 'wpi_discount',
252
+                'posts_per_page' => 1,
253
+                'post_status'    => array( 'publish', 'pending', 'draft', 'expired' ),
254
+                'fields'         => 'ids',
255
+            )
256
+        );
257
+
258
+        if ( empty( $discounts ) ) {
259
+            return 0;
260
+        }
261
+
262
+        $discount_id = $discounts[0];
263
+
264
+        // Update the cache with our data
265
+        wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' );
266
+
267
+        return $discount_id;
268
+    }
269
+
270
+    /**
271
+     * Magic method for checking the existence of a certain custom field.
272
+     *
273
+     * @since 1.0.15
274
+     * @access public
275
+     *
276
+     * @return bool Whether the given discount field is set.
277
+     */
278
+    public function __isset( $key ){
279
+        return isset( $this->data[$key] ) || method_exists( $this, "get_$key");
280
+    }
281
+
282
+    /*
283 283
 	|--------------------------------------------------------------------------
284 284
 	| CRUD methods
285 285
 	|--------------------------------------------------------------------------
@@ -294,430 +294,430 @@  discard block
 block discarded – undo
294 294
 	|--------------------------------------------------------------------------
295 295
 	*/
296 296
 
297
-	/**
298
-	 * Get discount status.
299
-	 *
300
-	 * @since 1.0.19
301
-	 * @param  string $context View or edit context.
302
-	 * @return string
303
-	 */
304
-	public function get_status( $context = 'view' ) {
305
-		return $this->get_prop( 'status', $context );
297
+    /**
298
+     * Get discount status.
299
+     *
300
+     * @since 1.0.19
301
+     * @param  string $context View or edit context.
302
+     * @return string
303
+     */
304
+    public function get_status( $context = 'view' ) {
305
+        return $this->get_prop( 'status', $context );
306 306
     }
307 307
 
308 308
     /**
309
-	 * Get plugin version when the discount was created.
310
-	 *
311
-	 * @since 1.0.19
312
-	 * @param  string $context View or edit context.
313
-	 * @return string
314
-	 */
315
-	public function get_version( $context = 'view' ) {
316
-		return $this->get_prop( 'version', $context );
309
+     * Get plugin version when the discount was created.
310
+     *
311
+     * @since 1.0.19
312
+     * @param  string $context View or edit context.
313
+     * @return string
314
+     */
315
+    public function get_version( $context = 'view' ) {
316
+        return $this->get_prop( 'version', $context );
317 317
     }
318 318
 
319 319
     /**
320
-	 * Get date when the discount was created.
321
-	 *
322
-	 * @since 1.0.19
323
-	 * @param  string $context View or edit context.
324
-	 * @return string
325
-	 */
326
-	public function get_date_created( $context = 'view' ) {
327
-		return $this->get_prop( 'date_created', $context );
320
+     * Get date when the discount was created.
321
+     *
322
+     * @since 1.0.19
323
+     * @param  string $context View or edit context.
324
+     * @return string
325
+     */
326
+    public function get_date_created( $context = 'view' ) {
327
+        return $this->get_prop( 'date_created', $context );
328 328
     }
329 329
 
330 330
     /**
331
-	 * Get GMT date when the discount was created.
332
-	 *
333
-	 * @since 1.0.19
334
-	 * @param  string $context View or edit context.
335
-	 * @return string
336
-	 */
337
-	public function get_date_created_gmt( $context = 'view' ) {
331
+     * Get GMT date when the discount was created.
332
+     *
333
+     * @since 1.0.19
334
+     * @param  string $context View or edit context.
335
+     * @return string
336
+     */
337
+    public function get_date_created_gmt( $context = 'view' ) {
338 338
         $date = $this->get_date_created( $context );
339 339
 
340 340
         if ( $date ) {
341 341
             $date = get_gmt_from_date( $date );
342 342
         }
343
-		return $date;
343
+        return $date;
344 344
     }
345 345
 
346 346
     /**
347
-	 * Get date when the discount was last modified.
348
-	 *
349
-	 * @since 1.0.19
350
-	 * @param  string $context View or edit context.
351
-	 * @return string
352
-	 */
353
-	public function get_date_modified( $context = 'view' ) {
354
-		return $this->get_prop( 'date_modified', $context );
347
+     * Get date when the discount was last modified.
348
+     *
349
+     * @since 1.0.19
350
+     * @param  string $context View or edit context.
351
+     * @return string
352
+     */
353
+    public function get_date_modified( $context = 'view' ) {
354
+        return $this->get_prop( 'date_modified', $context );
355 355
     }
356 356
 
357 357
     /**
358
-	 * Get GMT date when the discount was last modified.
359
-	 *
360
-	 * @since 1.0.19
361
-	 * @param  string $context View or edit context.
362
-	 * @return string
363
-	 */
364
-	public function get_date_modified_gmt( $context = 'view' ) {
358
+     * Get GMT date when the discount was last modified.
359
+     *
360
+     * @since 1.0.19
361
+     * @param  string $context View or edit context.
362
+     * @return string
363
+     */
364
+    public function get_date_modified_gmt( $context = 'view' ) {
365 365
         $date = $this->get_date_modified( $context );
366 366
 
367 367
         if ( $date ) {
368 368
             $date = get_gmt_from_date( $date );
369 369
         }
370
-		return $date;
370
+        return $date;
371 371
     }
372 372
 
373 373
     /**
374
-	 * Get the discount name.
375
-	 *
376
-	 * @since 1.0.19
377
-	 * @param  string $context View or edit context.
378
-	 * @return string
379
-	 */
380
-	public function get_name( $context = 'view' ) {
381
-		return $this->get_prop( 'name', $context );
374
+     * Get the discount name.
375
+     *
376
+     * @since 1.0.19
377
+     * @param  string $context View or edit context.
378
+     * @return string
379
+     */
380
+    public function get_name( $context = 'view' ) {
381
+        return $this->get_prop( 'name', $context );
382 382
     }
383 383
 
384 384
     /**
385
-	 * Alias of self::get_name().
386
-	 *
387
-	 * @since 1.0.19
388
-	 * @param  string $context View or edit context.
389
-	 * @return string
390
-	 */
391
-	public function get_title( $context = 'view' ) {
392
-		return $this->get_name( $context );
385
+     * Alias of self::get_name().
386
+     *
387
+     * @since 1.0.19
388
+     * @param  string $context View or edit context.
389
+     * @return string
390
+     */
391
+    public function get_title( $context = 'view' ) {
392
+        return $this->get_name( $context );
393 393
     }
394 394
 
395 395
     /**
396
-	 * Get the discount description.
397
-	 *
398
-	 * @since 1.0.19
399
-	 * @param  string $context View or edit context.
400
-	 * @return string
401
-	 */
402
-	public function get_description( $context = 'view' ) {
403
-		return $this->get_prop( 'description', $context );
396
+     * Get the discount description.
397
+     *
398
+     * @since 1.0.19
399
+     * @param  string $context View or edit context.
400
+     * @return string
401
+     */
402
+    public function get_description( $context = 'view' ) {
403
+        return $this->get_prop( 'description', $context );
404 404
     }
405 405
 
406 406
     /**
407
-	 * Alias of self::get_description().
408
-	 *
409
-	 * @since 1.0.19
410
-	 * @param  string $context View or edit context.
411
-	 * @return string
412
-	 */
413
-	public function get_excerpt( $context = 'view' ) {
414
-		return $this->get_description( $context );
407
+     * Alias of self::get_description().
408
+     *
409
+     * @since 1.0.19
410
+     * @param  string $context View or edit context.
411
+     * @return string
412
+     */
413
+    public function get_excerpt( $context = 'view' ) {
414
+        return $this->get_description( $context );
415 415
     }
416 416
 
417 417
     /**
418
-	 * Alias of self::get_description().
419
-	 *
420
-	 * @since 1.0.19
421
-	 * @param  string $context View or edit context.
422
-	 * @return string
423
-	 */
424
-	public function get_summary( $context = 'view' ) {
425
-		return $this->get_description( $context );
418
+     * Alias of self::get_description().
419
+     *
420
+     * @since 1.0.19
421
+     * @param  string $context View or edit context.
422
+     * @return string
423
+     */
424
+    public function get_summary( $context = 'view' ) {
425
+        return $this->get_description( $context );
426 426
     }
427 427
 
428 428
     /**
429
-	 * Get the owner of the discount.
430
-	 *
431
-	 * @since 1.0.19
432
-	 * @param  string $context View or edit context.
433
-	 * @return string
434
-	 */
435
-	public function get_author( $context = 'view' ) {
436
-		return (int) $this->get_prop( 'author', $context );
437
-	}
429
+     * Get the owner of the discount.
430
+     *
431
+     * @since 1.0.19
432
+     * @param  string $context View or edit context.
433
+     * @return string
434
+     */
435
+    public function get_author( $context = 'view' ) {
436
+        return (int) $this->get_prop( 'author', $context );
437
+    }
438 438
 	
439
-	/**
440
-	 * Get the discount code.
441
-	 *
442
-	 * @since 1.0.19
443
-	 * @param  string $context View or edit context.
444
-	 * @return string
445
-	 */
446
-	public function get_code( $context = 'view' ) {
447
-		return $this->get_prop( 'code', $context );
448
-	}
439
+    /**
440
+     * Get the discount code.
441
+     *
442
+     * @since 1.0.19
443
+     * @param  string $context View or edit context.
444
+     * @return string
445
+     */
446
+    public function get_code( $context = 'view' ) {
447
+        return $this->get_prop( 'code', $context );
448
+    }
449 449
 	
450
-	/**
451
-	 * Alias for self::get_code().
452
-	 *
453
-	 * @since 1.0.19
454
-	 * @param  string $context View or edit context.
455
-	 * @return string
456
-	 */
457
-	public function get_coupon_code( $context = 'view' ) {
458
-		return $this->get_code( $context );
459
-	}
450
+    /**
451
+     * Alias for self::get_code().
452
+     *
453
+     * @since 1.0.19
454
+     * @param  string $context View or edit context.
455
+     * @return string
456
+     */
457
+    public function get_coupon_code( $context = 'view' ) {
458
+        return $this->get_code( $context );
459
+    }
460 460
 	
461
-	/**
462
-	 * Alias for self::get_code().
463
-	 *
464
-	 * @since 1.0.19
465
-	 * @param  string $context View or edit context.
466
-	 * @return string
467
-	 */
468
-	public function get_discount_code( $context = 'view' ) {
469
-		return $this->get_code( $context );
470
-	}
461
+    /**
462
+     * Alias for self::get_code().
463
+     *
464
+     * @since 1.0.19
465
+     * @param  string $context View or edit context.
466
+     * @return string
467
+     */
468
+    public function get_discount_code( $context = 'view' ) {
469
+        return $this->get_code( $context );
470
+    }
471 471
 	
472
-	/**
473
-	 * Get the discount's amount.
474
-	 *
475
-	 * @since 1.0.19
476
-	 * @param  string $context View or edit context.
477
-	 * @return float
478
-	 */
479
-	public function get_amount( $context = 'view' ) {
480
-		return $this->get_prop( 'amount', $context );
481
-	}
482
-
483
-	/**
484
-	 * Get the discount's formated amount/rate.
485
-	 *
486
-	 * @since 1.0.19
487
-	 * @return string
488
-	 */
489
-	public function get_formatted_amount() {
490
-
491
-		if ( $this->is_type( 'flat' ) ) {
492
-			$rate = wpinv_price( $this->get_amount() );
493
-		} else {
494
-			$rate = $this->get_amount() . '%';
495
-		}
496
-
497
-		return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() );
498
-	}
472
+    /**
473
+     * Get the discount's amount.
474
+     *
475
+     * @since 1.0.19
476
+     * @param  string $context View or edit context.
477
+     * @return float
478
+     */
479
+    public function get_amount( $context = 'view' ) {
480
+        return $this->get_prop( 'amount', $context );
481
+    }
482
+
483
+    /**
484
+     * Get the discount's formated amount/rate.
485
+     *
486
+     * @since 1.0.19
487
+     * @return string
488
+     */
489
+    public function get_formatted_amount() {
490
+
491
+        if ( $this->is_type( 'flat' ) ) {
492
+            $rate = wpinv_price( $this->get_amount() );
493
+        } else {
494
+            $rate = $this->get_amount() . '%';
495
+        }
496
+
497
+        return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() );
498
+    }
499 499
 	
500
-	/**
501
-	 * Get the discount's start date.
502
-	 *
503
-	 * @since 1.0.19
504
-	 * @param  string $context View or edit context.
505
-	 * @return string
506
-	 */
507
-	public function get_start( $context = 'view' ) {
508
-		return $this->get_prop( 'start', $context );
509
-	}
500
+    /**
501
+     * Get the discount's start date.
502
+     *
503
+     * @since 1.0.19
504
+     * @param  string $context View or edit context.
505
+     * @return string
506
+     */
507
+    public function get_start( $context = 'view' ) {
508
+        return $this->get_prop( 'start', $context );
509
+    }
510 510
 	
511
-	/**
512
-	 * Alias for self::get_start().
513
-	 *
514
-	 * @since 1.0.19
515
-	 * @param  string $context View or edit context.
516
-	 * @return string
517
-	 */
518
-	public function get_start_date( $context = 'view' ) {
519
-		return $this->get_start( $context );
520
-	}
511
+    /**
512
+     * Alias for self::get_start().
513
+     *
514
+     * @since 1.0.19
515
+     * @param  string $context View or edit context.
516
+     * @return string
517
+     */
518
+    public function get_start_date( $context = 'view' ) {
519
+        return $this->get_start( $context );
520
+    }
521 521
 	
522
-	/**
523
-	 * Get the discount's expiration date.
524
-	 *
525
-	 * @since 1.0.19
526
-	 * @param  string $context View or edit context.
527
-	 * @return string
528
-	 */
529
-	public function get_expiration( $context = 'view' ) {
530
-		return $this->get_prop( 'expiration', $context );
531
-	}
522
+    /**
523
+     * Get the discount's expiration date.
524
+     *
525
+     * @since 1.0.19
526
+     * @param  string $context View or edit context.
527
+     * @return string
528
+     */
529
+    public function get_expiration( $context = 'view' ) {
530
+        return $this->get_prop( 'expiration', $context );
531
+    }
532 532
 	
533
-	/**
534
-	 * Alias for self::get_expiration().
535
-	 *
536
-	 * @since 1.0.19
537
-	 * @param  string $context View or edit context.
538
-	 * @return string
539
-	 */
540
-	public function get_expiration_date( $context = 'view' ) {
541
-		return $this->get_expiration( $context );
542
-	}
543
-
544
-	/**
545
-	 * Alias for self::get_expiration().
546
-	 *
547
-	 * @since 1.0.19
548
-	 * @param  string $context View or edit context.
549
-	 * @return string
550
-	 */
551
-	public function get_end_date( $context = 'view' ) {
552
-		return $this->get_expiration( $context );
553
-	}
533
+    /**
534
+     * Alias for self::get_expiration().
535
+     *
536
+     * @since 1.0.19
537
+     * @param  string $context View or edit context.
538
+     * @return string
539
+     */
540
+    public function get_expiration_date( $context = 'view' ) {
541
+        return $this->get_expiration( $context );
542
+    }
543
+
544
+    /**
545
+     * Alias for self::get_expiration().
546
+     *
547
+     * @since 1.0.19
548
+     * @param  string $context View or edit context.
549
+     * @return string
550
+     */
551
+    public function get_end_date( $context = 'view' ) {
552
+        return $this->get_expiration( $context );
553
+    }
554 554
 	
555
-	/**
556
-	 * Get the discount's type.
557
-	 *
558
-	 * @since 1.0.19
559
-	 * @param  string $context View or edit context.
560
-	 * @return string
561
-	 */
562
-	public function get_type( $context = 'view' ) {
563
-		return $this->get_prop( 'type', $context );
564
-	}
565
-
566
-	/**
567
-	 * Get the number of times a discount has been used.
568
-	 *
569
-	 * @since 1.0.19
570
-	 * @param  string $context View or edit context.
571
-	 * @return int
572
-	 */
573
-	public function get_uses( $context = 'view' ) {
574
-		return (int) $this->get_prop( 'uses', $context );
575
-	}
576
-
577
-	/**
578
-	 * Get the discount's usage, i.e uses / max uses.
579
-	 *
580
-	 * @since 1.0.19
581
-	 * @return string
582
-	 */
583
-	public function get_usage() {
584
-
585
-		if ( ! $this->has_limit() ) {
586
-			return $this->get_uses() . ' / ' . ' &infin;';
587
-		}
588
-
589
-		return $this->get_uses() . ' / ' . (int) $this->get_max_uses();
590
-
591
-	}
592
-
593
-	/**
594
-	 * Get the maximum number of time a discount can be used.
595
-	 *
596
-	 * @since 1.0.19
597
-	 * @param  string $context View or edit context.
598
-	 * @return int
599
-	 */
600
-	public function get_max_uses( $context = 'view' ) {
601
-		$max_uses = $this->get_prop( 'max_uses', $context );
602
-		return empty( $max_uses ) ? null : $max_uses;
603
-	}
604
-
605
-	/**
606
-	 * Checks if this is a single use discount or not.
607
-	 *
608
-	 * @since 1.0.19
609
-	 * @param  string $context View or edit context.
610
-	 * @return bool
611
-	 */
612
-	public function get_is_single_use( $context = 'view' ) {
613
-		return $this->get_prop( 'is_single_use', $context );
614
-	}
615
-
616
-	/**
617
-	 * Get the items that can be used with this discount.
618
-	 *
619
-	 * @since 1.0.19
620
-	 * @param  string $context View or edit context.
621
-	 * @return array
622
-	 */
623
-	public function get_items( $context = 'view' ) {
624
-		return wpinv_parse_list( $this->get_prop( 'items', $context ) );
625
-	}
626
-
627
-	/**
628
-	 * Alias for self::get_items().
629
-	 *
630
-	 * @since 1.0.19
631
-	 * @param  string $context View or edit context.
632
-	 * @return array
633
-	 */
634
-	public function get_allowed_items( $context = 'view' ) {
635
-		return $this->get_items( $context );
636
-	}
637
-
638
-	/**
639
-	 * Get the items that are not allowed to use this discount.
640
-	 *
641
-	 * @since 1.0.19
642
-	 * @param  string $context View or edit context.
643
-	 * @return array
644
-	 */
645
-	public function get_excluded_items( $context = 'view' ) {
646
-		return wpinv_parse_list( $this->get_prop( 'excluded_items', $context ) );
647
-	}
648
-
649
-	/**
650
-	 * Checks if this is a recurring discount or not.
651
-	 *
652
-	 * @since 1.0.19
653
-	 * @param  string $context View or edit context.
654
-	 * @return int|string|bool
655
-	 */
656
-	public function get_is_recurring( $context = 'view' ) {
657
-		return $this->get_prop( 'is_recurring', $context );
658
-	}
659
-
660
-	/**
661
-	 * Get's the minimum total amount allowed for this discount.
662
-	 *
663
-	 * @since 1.0.19
664
-	 * @param  string $context View or edit context.
665
-	 * @return float
666
-	 */
667
-	public function get_min_total( $context = 'view' ) {
668
-		$minimum = $this->get_prop( 'min_total', $context );
669
-		return empty( $minimum ) ? null : $minimum;
670
-	}
671
-
672
-	/**
673
-	 * Alias for self::get_min_total().
674
-	 *
675
-	 * @since 1.0.19
676
-	 * @param  string $context View or edit context.
677
-	 * @return float
678
-	 */
679
-	public function get_minimum_total( $context = 'view' ) {
680
-		return $this->get_min_total( $context );
681
-	}
682
-
683
-	/**
684
-	 * Get's the maximum total amount allowed for this discount.
685
-	 *
686
-	 * @since 1.0.19
687
-	 * @param  string $context View or edit context.
688
-	 * @return float
689
-	 */
690
-	public function get_max_total( $context = 'view' ) {
691
-		$maximum = $this->get_prop( 'max_total', $context );
692
-		return empty( $maximum ) ? null : $maximum;
693
-	}
694
-
695
-	/**
696
-	 * Alias for self::get_max_total().
697
-	 *
698
-	 * @since 1.0.19
699
-	 * @param  string $context View or edit context.
700
-	 * @return float
701
-	 */
702
-	public function get_maximum_total( $context = 'view' ) {
703
-		return $this->get_max_total( $context );
704
-	}
705
-
706
-	/**
707
-	 * Magic method for accessing discount properties.
708
-	 *
709
-	 * @since 1.0.15
710
-	 * @access public
711
-	 *
712
-	 * @param string $key Discount data to retrieve
713
-	 * @param  string $context View or edit context.
714
-	 * @return mixed Value of the given discount property (if set).
715
-	 */
716
-	public function get( $key, $context = 'view' ) {
555
+    /**
556
+     * Get the discount's type.
557
+     *
558
+     * @since 1.0.19
559
+     * @param  string $context View or edit context.
560
+     * @return string
561
+     */
562
+    public function get_type( $context = 'view' ) {
563
+        return $this->get_prop( 'type', $context );
564
+    }
565
+
566
+    /**
567
+     * Get the number of times a discount has been used.
568
+     *
569
+     * @since 1.0.19
570
+     * @param  string $context View or edit context.
571
+     * @return int
572
+     */
573
+    public function get_uses( $context = 'view' ) {
574
+        return (int) $this->get_prop( 'uses', $context );
575
+    }
576
+
577
+    /**
578
+     * Get the discount's usage, i.e uses / max uses.
579
+     *
580
+     * @since 1.0.19
581
+     * @return string
582
+     */
583
+    public function get_usage() {
584
+
585
+        if ( ! $this->has_limit() ) {
586
+            return $this->get_uses() . ' / ' . ' &infin;';
587
+        }
588
+
589
+        return $this->get_uses() . ' / ' . (int) $this->get_max_uses();
590
+
591
+    }
592
+
593
+    /**
594
+     * Get the maximum number of time a discount can be used.
595
+     *
596
+     * @since 1.0.19
597
+     * @param  string $context View or edit context.
598
+     * @return int
599
+     */
600
+    public function get_max_uses( $context = 'view' ) {
601
+        $max_uses = $this->get_prop( 'max_uses', $context );
602
+        return empty( $max_uses ) ? null : $max_uses;
603
+    }
604
+
605
+    /**
606
+     * Checks if this is a single use discount or not.
607
+     *
608
+     * @since 1.0.19
609
+     * @param  string $context View or edit context.
610
+     * @return bool
611
+     */
612
+    public function get_is_single_use( $context = 'view' ) {
613
+        return $this->get_prop( 'is_single_use', $context );
614
+    }
615
+
616
+    /**
617
+     * Get the items that can be used with this discount.
618
+     *
619
+     * @since 1.0.19
620
+     * @param  string $context View or edit context.
621
+     * @return array
622
+     */
623
+    public function get_items( $context = 'view' ) {
624
+        return wpinv_parse_list( $this->get_prop( 'items', $context ) );
625
+    }
626
+
627
+    /**
628
+     * Alias for self::get_items().
629
+     *
630
+     * @since 1.0.19
631
+     * @param  string $context View or edit context.
632
+     * @return array
633
+     */
634
+    public function get_allowed_items( $context = 'view' ) {
635
+        return $this->get_items( $context );
636
+    }
637
+
638
+    /**
639
+     * Get the items that are not allowed to use this discount.
640
+     *
641
+     * @since 1.0.19
642
+     * @param  string $context View or edit context.
643
+     * @return array
644
+     */
645
+    public function get_excluded_items( $context = 'view' ) {
646
+        return wpinv_parse_list( $this->get_prop( 'excluded_items', $context ) );
647
+    }
648
+
649
+    /**
650
+     * Checks if this is a recurring discount or not.
651
+     *
652
+     * @since 1.0.19
653
+     * @param  string $context View or edit context.
654
+     * @return int|string|bool
655
+     */
656
+    public function get_is_recurring( $context = 'view' ) {
657
+        return $this->get_prop( 'is_recurring', $context );
658
+    }
659
+
660
+    /**
661
+     * Get's the minimum total amount allowed for this discount.
662
+     *
663
+     * @since 1.0.19
664
+     * @param  string $context View or edit context.
665
+     * @return float
666
+     */
667
+    public function get_min_total( $context = 'view' ) {
668
+        $minimum = $this->get_prop( 'min_total', $context );
669
+        return empty( $minimum ) ? null : $minimum;
670
+    }
671
+
672
+    /**
673
+     * Alias for self::get_min_total().
674
+     *
675
+     * @since 1.0.19
676
+     * @param  string $context View or edit context.
677
+     * @return float
678
+     */
679
+    public function get_minimum_total( $context = 'view' ) {
680
+        return $this->get_min_total( $context );
681
+    }
682
+
683
+    /**
684
+     * Get's the maximum total amount allowed for this discount.
685
+     *
686
+     * @since 1.0.19
687
+     * @param  string $context View or edit context.
688
+     * @return float
689
+     */
690
+    public function get_max_total( $context = 'view' ) {
691
+        $maximum = $this->get_prop( 'max_total', $context );
692
+        return empty( $maximum ) ? null : $maximum;
693
+    }
694
+
695
+    /**
696
+     * Alias for self::get_max_total().
697
+     *
698
+     * @since 1.0.19
699
+     * @param  string $context View or edit context.
700
+     * @return float
701
+     */
702
+    public function get_maximum_total( $context = 'view' ) {
703
+        return $this->get_max_total( $context );
704
+    }
705
+
706
+    /**
707
+     * Magic method for accessing discount properties.
708
+     *
709
+     * @since 1.0.15
710
+     * @access public
711
+     *
712
+     * @param string $key Discount data to retrieve
713
+     * @param  string $context View or edit context.
714
+     * @return mixed Value of the given discount property (if set).
715
+     */
716
+    public function get( $key, $context = 'view' ) {
717 717
         return $this->get_prop( $key, $context );
718
-	}
718
+    }
719 719
 
720
-	/*
720
+    /*
721 721
 	|--------------------------------------------------------------------------
722 722
 	| Setters
723 723
 	|--------------------------------------------------------------------------
@@ -727,41 +727,41 @@  discard block
 block discarded – undo
727 727
 	| object.
728 728
 	*/
729 729
 	
730
-	/**
731
-	 * Sets discount status.
732
-	 *
733
-	 * @since 1.0.19
734
-	 * @param  string $status New status.
735
-	 * @return array details of change.
736
-	 */
737
-	public function set_status( $status ) {
730
+    /**
731
+     * Sets discount status.
732
+     *
733
+     * @since 1.0.19
734
+     * @param  string $status New status.
735
+     * @return array details of change.
736
+     */
737
+    public function set_status( $status ) {
738 738
         $old_status = $this->get_status();
739 739
 
740 740
         $this->set_prop( 'status', $status );
741 741
 
742
-		return array(
743
-			'from' => $old_status,
744
-			'to'   => $status,
745
-		);
742
+        return array(
743
+            'from' => $old_status,
744
+            'to'   => $status,
745
+        );
746 746
     }
747 747
 
748 748
     /**
749
-	 * Set plugin version when the discount was created.
750
-	 *
751
-	 * @since 1.0.19
752
-	 */
753
-	public function set_version( $value ) {
754
-		$this->set_prop( 'version', $value );
749
+     * Set plugin version when the discount was created.
750
+     *
751
+     * @since 1.0.19
752
+     */
753
+    public function set_version( $value ) {
754
+        $this->set_prop( 'version', $value );
755 755
     }
756 756
 
757 757
     /**
758
-	 * Set date when the discount was created.
759
-	 *
760
-	 * @since 1.0.19
761
-	 * @param string $value Value to set.
758
+     * Set date when the discount was created.
759
+     *
760
+     * @since 1.0.19
761
+     * @param string $value Value to set.
762 762
      * @return bool Whether or not the date was set.
763
-	 */
764
-	public function set_date_created( $value ) {
763
+     */
764
+    public function set_date_created( $value ) {
765 765
         $date = strtotime( $value );
766 766
 
767 767
         if ( $date ) {
@@ -774,13 +774,13 @@  discard block
 block discarded – undo
774 774
     }
775 775
 
776 776
     /**
777
-	 * Set date when the discount was last modified.
778
-	 *
779
-	 * @since 1.0.19
780
-	 * @param string $value Value to set.
777
+     * Set date when the discount was last modified.
778
+     *
779
+     * @since 1.0.19
780
+     * @param string $value Value to set.
781 781
      * @return bool Whether or not the date was set.
782
-	 */
783
-	public function set_date_modified( $value ) {
782
+     */
783
+    public function set_date_modified( $value ) {
784 784
         $date = strtotime( $value );
785 785
 
786 786
         if ( $date ) {
@@ -793,324 +793,324 @@  discard block
 block discarded – undo
793 793
     }
794 794
 
795 795
     /**
796
-	 * Set the discount name.
797
-	 *
798
-	 * @since 1.0.19
799
-	 * @param  string $value New name.
800
-	 */
801
-	public function set_name( $value ) {
796
+     * Set the discount name.
797
+     *
798
+     * @since 1.0.19
799
+     * @param  string $value New name.
800
+     */
801
+    public function set_name( $value ) {
802 802
         $name = sanitize_text_field( $value );
803
-		$this->set_prop( 'name', $name );
803
+        $this->set_prop( 'name', $name );
804 804
     }
805 805
 
806 806
     /**
807
-	 * Alias of self::set_name().
808
-	 *
809
-	 * @since 1.0.19
810
-	 * @param  string $value New name.
811
-	 */
812
-	public function set_title( $value ) {
813
-		$this->set_name( $value );
807
+     * Alias of self::set_name().
808
+     *
809
+     * @since 1.0.19
810
+     * @param  string $value New name.
811
+     */
812
+    public function set_title( $value ) {
813
+        $this->set_name( $value );
814 814
     }
815 815
 
816 816
     /**
817
-	 * Set the discount description.
818
-	 *
819
-	 * @since 1.0.19
820
-	 * @param  string $value New description.
821
-	 */
822
-	public function set_description( $value ) {
817
+     * Set the discount description.
818
+     *
819
+     * @since 1.0.19
820
+     * @param  string $value New description.
821
+     */
822
+    public function set_description( $value ) {
823 823
         $description = wp_kses_post( $value );
824
-		return $this->set_prop( 'description', $description );
824
+        return $this->set_prop( 'description', $description );
825 825
     }
826 826
 
827 827
     /**
828
-	 * Alias of self::set_description().
829
-	 *
830
-	 * @since 1.0.19
831
-	 * @param  string $value New description.
832
-	 */
833
-	public function set_excerpt( $value ) {
834
-		$this->set_description( $value );
828
+     * Alias of self::set_description().
829
+     *
830
+     * @since 1.0.19
831
+     * @param  string $value New description.
832
+     */
833
+    public function set_excerpt( $value ) {
834
+        $this->set_description( $value );
835 835
     }
836 836
 
837 837
     /**
838
-	 * Alias of self::set_description().
839
-	 *
840
-	 * @since 1.0.19
841
-	 * @param  string $value New description.
842
-	 */
843
-	public function set_summary( $value ) {
844
-		$this->set_description( $value );
838
+     * Alias of self::set_description().
839
+     *
840
+     * @since 1.0.19
841
+     * @param  string $value New description.
842
+     */
843
+    public function set_summary( $value ) {
844
+        $this->set_description( $value );
845 845
     }
846 846
 
847 847
     /**
848
-	 * Set the owner of the discount.
849
-	 *
850
-	 * @since 1.0.19
851
-	 * @param  int $value New author.
852
-	 */
853
-	public function set_author( $value ) {
854
-		$this->set_prop( 'author', (int) $value );
855
-	}
848
+     * Set the owner of the discount.
849
+     *
850
+     * @since 1.0.19
851
+     * @param  int $value New author.
852
+     */
853
+    public function set_author( $value ) {
854
+        $this->set_prop( 'author', (int) $value );
855
+    }
856 856
 	
857
-	/**
858
-	 * Sets the discount code.
859
-	 *
860
-	 * @since 1.0.19
861
-	 * @param string $value New discount code.
862
-	 */
863
-	public function set_code( $value ) {
864
-		$code = sanitize_text_field( $value );
865
-		$this->set_prop( 'code', $code );
866
-	}
857
+    /**
858
+     * Sets the discount code.
859
+     *
860
+     * @since 1.0.19
861
+     * @param string $value New discount code.
862
+     */
863
+    public function set_code( $value ) {
864
+        $code = sanitize_text_field( $value );
865
+        $this->set_prop( 'code', $code );
866
+    }
867 867
 	
868
-	/**
869
-	 * Alias of self::set_code().
870
-	 *
871
-	 * @since 1.0.19
872
-	 * @param string $value New discount code.
873
-	 */
874
-	public function set_coupon_code( $value ) {
875
-		$this->set_code( $value );
876
-	}
868
+    /**
869
+     * Alias of self::set_code().
870
+     *
871
+     * @since 1.0.19
872
+     * @param string $value New discount code.
873
+     */
874
+    public function set_coupon_code( $value ) {
875
+        $this->set_code( $value );
876
+    }
877 877
 	
878
-	/**
879
-	 * Alias of self::set_code().
880
-	 *
881
-	 * @since 1.0.19
882
-	 * @param string $value New discount code.
883
-	 */
884
-	public function set_discount_code( $value ) {
885
-		$this->set_code( $value );
886
-	}
878
+    /**
879
+     * Alias of self::set_code().
880
+     *
881
+     * @since 1.0.19
882
+     * @param string $value New discount code.
883
+     */
884
+    public function set_discount_code( $value ) {
885
+        $this->set_code( $value );
886
+    }
887 887
 	
888
-	/**
889
-	 * Sets the discount amount.
890
-	 *
891
-	 * @since 1.0.19
892
-	 * @param float $value New discount code.
893
-	 */
894
-	public function set_amount( $value ) {
895
-		$amount = floatval( wpinv_sanitize_amount( $value ) );
896
-		$this->set_prop( 'amount', $amount );
897
-	}
898
-
899
-	/**
900
-	 * Sets the discount's start date.
901
-	 *
902
-	 * @since 1.0.19
903
-	 * @param float $value New start date.
904
-	 */
905
-	public function set_start( $value ) {
906
-		$date = strtotime( $value );
888
+    /**
889
+     * Sets the discount amount.
890
+     *
891
+     * @since 1.0.19
892
+     * @param float $value New discount code.
893
+     */
894
+    public function set_amount( $value ) {
895
+        $amount = floatval( wpinv_sanitize_amount( $value ) );
896
+        $this->set_prop( 'amount', $amount );
897
+    }
907 898
 
908
-        if ( $date ) {
909
-            $this->set_prop( 'start', date( 'Y-m-d H:i', $date ) );
910
-            return true;
911
-		}
899
+    /**
900
+     * Sets the discount's start date.
901
+     *
902
+     * @since 1.0.19
903
+     * @param float $value New start date.
904
+     */
905
+    public function set_start( $value ) {
906
+        $date = strtotime( $value );
907
+
908
+        if ( $date ) {
909
+            $this->set_prop( 'start', date( 'Y-m-d H:i', $date ) );
910
+            return true;
911
+        }
912 912
 		
913
-		$this->set_prop( 'start', '' );
913
+        $this->set_prop( 'start', '' );
914 914
 
915 915
         return false;
916
-	}
917
-
918
-	/**
919
-	 * Alias of self::set_start().
920
-	 *
921
-	 * @since 1.0.19
922
-	 * @param string $value New start date.
923
-	 */
924
-	public function set_start_date( $value ) {
925
-		$this->set_start( $value );
926
-	}
927
-
928
-	/**
929
-	 * Sets the discount's expiration date.
930
-	 *
931
-	 * @since 1.0.19
932
-	 * @param float $value New expiration date.
933
-	 */
934
-	public function set_expiration( $value ) {
935
-		$date = strtotime( $value );
916
+    }
917
+
918
+    /**
919
+     * Alias of self::set_start().
920
+     *
921
+     * @since 1.0.19
922
+     * @param string $value New start date.
923
+     */
924
+    public function set_start_date( $value ) {
925
+        $this->set_start( $value );
926
+    }
927
+
928
+    /**
929
+     * Sets the discount's expiration date.
930
+     *
931
+     * @since 1.0.19
932
+     * @param float $value New expiration date.
933
+     */
934
+    public function set_expiration( $value ) {
935
+        $date = strtotime( $value );
936 936
 
937 937
         if ( $date ) {
938 938
             $this->set_prop( 'expiration', date( 'Y-m-d H:i', $date ) );
939 939
             return true;
940 940
         }
941 941
 
942
-		$this->set_prop( 'expiration', '' );
942
+        $this->set_prop( 'expiration', '' );
943 943
         return false;
944
-	}
945
-
946
-	/**
947
-	 * Alias of self::set_expiration().
948
-	 *
949
-	 * @since 1.0.19
950
-	 * @param string $value New expiration date.
951
-	 */
952
-	public function set_expiration_date( $value ) {
953
-		$this->set_expiration( $value );
954
-	}
955
-
956
-	/**
957
-	 * Alias of self::set_expiration().
958
-	 *
959
-	 * @since 1.0.19
960
-	 * @param string $value New expiration date.
961
-	 */
962
-	public function set_end_date( $value ) {
963
-		$this->set_expiration( $value );
964
-	}
965
-
966
-	/**
967
-	 * Sets the discount type.
968
-	 *
969
-	 * @since 1.0.19
970
-	 * @param string $value New discount type.
971
-	 */
972
-	public function set_type( $value ) {
973
-		if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) {
974
-			$this->set_prop( 'type', sanitize_text_field( $value ) );
975
-		}
976
-	}
977
-
978
-	/**
979
-	 * Sets the number of times a discount has been used.
980
-	 *
981
-	 * @since 1.0.19
982
-	 * @param int $value usage count.
983
-	 */
984
-	public function set_uses( $value ) {
985
-
986
-		$value = (int) $value;
987
-
988
-		if ( $value < 0 ) {
989
-			$value = 0;
990
-		}
991
-
992
-		$this->set_prop( 'uses', (int) $value );
993
-	}
994
-
995
-	/**
996
-	 * Sets the maximum number of times a discount can be used.
997
-	 *
998
-	 * @since 1.0.19
999
-	 * @param int $value maximum usage count.
1000
-	 */
1001
-	public function set_max_uses( $value ) {
1002
-		$this->set_prop( 'max_uses', absint( $value ) );
1003
-	}
1004
-
1005
-	/**
1006
-	 * Sets if this is a single use discount or not.
1007
-	 *
1008
-	 * @since 1.0.19
1009
-	 * @param int|bool $value is single use.
1010
-	 */
1011
-	public function set_is_single_use( $value ) {
1012
-		$this->set_prop( 'is_single_use', (bool) $value );
1013
-	}
1014
-
1015
-	/**
1016
-	 * Sets the items that can be used with this discount.
1017
-	 *
1018
-	 * @since 1.0.19
1019
-	 * @param array $value items.
1020
-	 */
1021
-	public function set_items( $value ) {
1022
-		$this->set_prop( 'items', wpinv_parse_list( $value ) );
1023
-	}
1024
-
1025
-	/**
1026
-	 * Alias for self::set_items().
1027
-	 *
1028
-	 * @since 1.0.19
1029
-	 * @param array $value items.
1030
-	 */
1031
-	public function set_allowed_items( $value ) {
1032
-		$this->set_items( $value );
1033
-	}
1034
-
1035
-	/**
1036
-	 * Sets the items that can not be used with this discount.
1037
-	 *
1038
-	 * @since 1.0.19
1039
-	 * @param array $value items.
1040
-	 */
1041
-	public function set_excluded_items( $value ) {
1042
-		$this->set_prop( 'excluded_items', wpinv_parse_list( $value ) );
1043
-	}
1044
-
1045
-	/**
1046
-	 * Sets if this is a recurring discounts or not.
1047
-	 *
1048
-	 * @since 1.0.19
1049
-	 * @param int|bool $value is recurring.
1050
-	 */
1051
-	public function set_is_recurring( $value ) {
1052
-		$this->set_prop( 'is_recurring', (bool) $value );
1053
-	}
1054
-
1055
-	/**
1056
-	 * Sets the minimum total that can not be used with this discount.
1057
-	 *
1058
-	 * @since 1.0.19
1059
-	 * @param float $value minimum total.
1060
-	 */
1061
-	public function set_min_total( $value ) {
1062
-		$this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) );
1063
-	}
1064
-
1065
-	/**
1066
-	 * Alias for self::set_min_total().
1067
-	 *
1068
-	 * @since 1.0.19
1069
-	 * @param float $value minimum total.
1070
-	 */
1071
-	public function set_minimum_total( $value ) {
1072
-		$this->set_min_total( $value );
1073
-	}
1074
-
1075
-	/**
1076
-	 * Sets the maximum total that can not be used with this discount.
1077
-	 *
1078
-	 * @since 1.0.19
1079
-	 * @param float $value maximum total.
1080
-	 */
1081
-	public function set_max_total( $value ) {
1082
-		$this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) );
1083
-	}
1084
-
1085
-	/**
1086
-	 * Alias for self::set_max_total().
1087
-	 *
1088
-	 * @since 1.0.19
1089
-	 * @param float $value maximum total.
1090
-	 */
1091
-	public function set_maximum_total( $value ) {
1092
-		$this->set_max_total( $value );
1093
-	}
1094
-
1095
-	/**
1096
-	 * @deprecated
1097
-	 */
1098
-	public function refresh(){}
1099
-
1100
-	/**
1101
-	 * @deprecated
1102
-	 *
1103
-	 */
1104
-	public function update_status( $status = 'publish' ){
1105
-
1106
-		if ( $this->exists() && $this->get_status() != $status ) {
1107
-			$this->set_status( $status );
1108
-			$this->save();
1109
-		}
1110
-
1111
-	}
1112
-
1113
-	/*
944
+    }
945
+
946
+    /**
947
+     * Alias of self::set_expiration().
948
+     *
949
+     * @since 1.0.19
950
+     * @param string $value New expiration date.
951
+     */
952
+    public function set_expiration_date( $value ) {
953
+        $this->set_expiration( $value );
954
+    }
955
+
956
+    /**
957
+     * Alias of self::set_expiration().
958
+     *
959
+     * @since 1.0.19
960
+     * @param string $value New expiration date.
961
+     */
962
+    public function set_end_date( $value ) {
963
+        $this->set_expiration( $value );
964
+    }
965
+
966
+    /**
967
+     * Sets the discount type.
968
+     *
969
+     * @since 1.0.19
970
+     * @param string $value New discount type.
971
+     */
972
+    public function set_type( $value ) {
973
+        if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) {
974
+            $this->set_prop( 'type', sanitize_text_field( $value ) );
975
+        }
976
+    }
977
+
978
+    /**
979
+     * Sets the number of times a discount has been used.
980
+     *
981
+     * @since 1.0.19
982
+     * @param int $value usage count.
983
+     */
984
+    public function set_uses( $value ) {
985
+
986
+        $value = (int) $value;
987
+
988
+        if ( $value < 0 ) {
989
+            $value = 0;
990
+        }
991
+
992
+        $this->set_prop( 'uses', (int) $value );
993
+    }
994
+
995
+    /**
996
+     * Sets the maximum number of times a discount can be used.
997
+     *
998
+     * @since 1.0.19
999
+     * @param int $value maximum usage count.
1000
+     */
1001
+    public function set_max_uses( $value ) {
1002
+        $this->set_prop( 'max_uses', absint( $value ) );
1003
+    }
1004
+
1005
+    /**
1006
+     * Sets if this is a single use discount or not.
1007
+     *
1008
+     * @since 1.0.19
1009
+     * @param int|bool $value is single use.
1010
+     */
1011
+    public function set_is_single_use( $value ) {
1012
+        $this->set_prop( 'is_single_use', (bool) $value );
1013
+    }
1014
+
1015
+    /**
1016
+     * Sets the items that can be used with this discount.
1017
+     *
1018
+     * @since 1.0.19
1019
+     * @param array $value items.
1020
+     */
1021
+    public function set_items( $value ) {
1022
+        $this->set_prop( 'items', wpinv_parse_list( $value ) );
1023
+    }
1024
+
1025
+    /**
1026
+     * Alias for self::set_items().
1027
+     *
1028
+     * @since 1.0.19
1029
+     * @param array $value items.
1030
+     */
1031
+    public function set_allowed_items( $value ) {
1032
+        $this->set_items( $value );
1033
+    }
1034
+
1035
+    /**
1036
+     * Sets the items that can not be used with this discount.
1037
+     *
1038
+     * @since 1.0.19
1039
+     * @param array $value items.
1040
+     */
1041
+    public function set_excluded_items( $value ) {
1042
+        $this->set_prop( 'excluded_items', wpinv_parse_list( $value ) );
1043
+    }
1044
+
1045
+    /**
1046
+     * Sets if this is a recurring discounts or not.
1047
+     *
1048
+     * @since 1.0.19
1049
+     * @param int|bool $value is recurring.
1050
+     */
1051
+    public function set_is_recurring( $value ) {
1052
+        $this->set_prop( 'is_recurring', (bool) $value );
1053
+    }
1054
+
1055
+    /**
1056
+     * Sets the minimum total that can not be used with this discount.
1057
+     *
1058
+     * @since 1.0.19
1059
+     * @param float $value minimum total.
1060
+     */
1061
+    public function set_min_total( $value ) {
1062
+        $this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) );
1063
+    }
1064
+
1065
+    /**
1066
+     * Alias for self::set_min_total().
1067
+     *
1068
+     * @since 1.0.19
1069
+     * @param float $value minimum total.
1070
+     */
1071
+    public function set_minimum_total( $value ) {
1072
+        $this->set_min_total( $value );
1073
+    }
1074
+
1075
+    /**
1076
+     * Sets the maximum total that can not be used with this discount.
1077
+     *
1078
+     * @since 1.0.19
1079
+     * @param float $value maximum total.
1080
+     */
1081
+    public function set_max_total( $value ) {
1082
+        $this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) );
1083
+    }
1084
+
1085
+    /**
1086
+     * Alias for self::set_max_total().
1087
+     *
1088
+     * @since 1.0.19
1089
+     * @param float $value maximum total.
1090
+     */
1091
+    public function set_maximum_total( $value ) {
1092
+        $this->set_max_total( $value );
1093
+    }
1094
+
1095
+    /**
1096
+     * @deprecated
1097
+     */
1098
+    public function refresh(){}
1099
+
1100
+    /**
1101
+     * @deprecated
1102
+     *
1103
+     */
1104
+    public function update_status( $status = 'publish' ){
1105
+
1106
+        if ( $this->exists() && $this->get_status() != $status ) {
1107
+            $this->set_status( $status );
1108
+            $this->save();
1109
+        }
1110
+
1111
+    }
1112
+
1113
+    /*
1114 1114
 	|--------------------------------------------------------------------------
1115 1115
 	| Conditionals
1116 1116
 	|--------------------------------------------------------------------------
@@ -1119,263 +1119,263 @@  discard block
 block discarded – undo
1119 1119
 	|
1120 1120
 	*/
1121 1121
 
1122
-	/**
1123
-	 * Checks whether a discount exists in the database or not
1124
-	 *
1125
-	 * @since 1.0.15
1126
-	 */
1127
-	public function exists(){
1128
-		$id = $this->get_id();
1129
-		return ! empty( $id );
1130
-	}
1131
-
1132
-	/**
1133
-	 * Checks the discount type.
1134
-	 *
1135
-	 *
1136
-	 * @param  string $type the discount type to check against
1137
-	 * @since 1.0.15
1138
-	 * @return bool
1139
-	 */
1140
-	public function is_type( $type ) {
1141
-		return $this->get_type() == $type;
1142
-	}
1143
-
1144
-	/**
1145
-	 * Checks whether the discount is published or not
1146
-	 *
1147
-	 * @since 1.0.15
1148
-	 * @return bool
1149
-	 */
1150
-	public function is_active() {
1151
-		return $this->get_status() == 'publish';
1152
-	}
1153
-
1154
-	/**
1155
-	 * Checks whether the discount has max uses
1156
-	 *
1157
-	 * @since 1.0.15
1158
-	 * @return bool
1159
-	 */
1160
-	public function has_limit() {
1161
-		$limit = $this->get_max_uses();
1162
-		return ! empty( $limit );
1163
-	}
1164
-
1165
-	/**
1166
-	 * Checks whether the discount has ever been used.
1167
-	 *
1168
-	 * @since 1.0.15
1169
-	 * @return bool
1170
-	 */
1171
-	public function has_uses() {
1172
-		return $this->get_uses() > 0;
1173
-	}
1174
-
1175
-	/**
1176
-	 * Checks whether the discount is has exided the usage limit or not
1177
-	 *
1178
-	 * @since 1.0.15
1179
-	 * @return bool
1180
-	 */
1181
-	public function has_exceeded_limit() {
1182
-
1183
-		if ( ! $this->has_limit() || ! $this->has_uses() ) {
1184
-			$exceeded = false ;
1185
-		} else {
1186
-			$exceeded = (int) $this->get_max_uses() <= $this->get_uses();
1187
-		}
1188
-
1189
-		return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->get_id(), $this, $this->get_code() );
1190
-	}
1191
-
1192
-	/**
1193
-	 * Checks whether the discount has an expiration date.
1194
-	 *
1195
-	 * @since 1.0.15
1196
-	 * @return bool
1197
-	 */
1198
-	public function has_expiration_date() {
1199
-		$date = $this->get_expiration_date();
1200
-		return ! empty( $date );
1201
-	}
1202
-
1203
-	/**
1204
-	 * Checks if the discount is expired
1205
-	 *
1206
-	 * @since 1.0.15
1207
-	 * @return bool
1208
-	 */
1209
-	public function is_expired() {
1210
-		$expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false;
1211
-		return apply_filters( 'wpinv_is_discount_expired', $expired, $this->get_id(), $this, $this->get_code() );
1212
-	}
1213
-
1214
-	/**
1215
-	 * Checks whether the discount has a start date.
1216
-	 *
1217
-	 * @since 1.0.15
1218
-	 * @return bool
1219
-	 */
1220
-	public function has_start_date() {
1221
-		$date = $this->get_start_date();
1222
-		return ! empty( $date );
1223
-	}
1224
-
1225
-	/**
1226
-	 * Checks the discount start date.
1227
-	 *
1228
-	 * @since 1.0.15
1229
-	 * @return bool
1230
-	 */
1231
-	public function has_started() {
1232
-		$started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() );
1233
-		return apply_filters( 'wpinv_is_discount_started', $started, $this->get_id(), $this, $this->get_code() );
1234
-	}
1235
-
1236
-	/**
1237
-	 * Checks the discount has allowed items or not.
1238
-	 *
1239
-	 * @since 1.0.15
1240
-	 * @return bool
1241
-	 */
1242
-	public function has_allowed_items() {
1243
-		$allowed_items = $this->get_allowed_items();
1244
-		return ! empty( $allowed_items );
1245
-	}
1246
-
1247
-	/**
1248
-	 * Checks the discount has excluded items or not.
1249
-	 *
1250
-	 * @since 1.0.15
1251
-	 * @return bool
1252
-	 */
1253
-	public function has_excluded_items() {
1254
-		$excluded_items = $this->get_excluded_items();
1255
-		return ! empty( $excluded_items );
1256
-	}
1257
-
1258
-	/**
1259
-	 * Check if a discount is valid for a given item id.
1260
-	 *
1261
-	 * @param  int|int[]  $item_ids
1262
-	 * @since 1.0.15
1263
-	 * @return boolean
1264
-	 */
1265
-	public function is_valid_for_items( $item_ids ) {
1266
-
1267
-		$item_ids = wp_parse_id_list( $item_ids );
1268
-		$included = array_intersect( $item_ids, $this->get_allowed_items() );
1269
-		$excluded = array_intersect( $item_ids, $this->get_excluded_items() );
1270
-
1271
-		if ( $this->has_excluded_items() && ! empty( $excluded ) ) {
1272
-			return false;
1273
-		}
1274
-
1275
-		if ( $this->has_allowed_items() && empty( $included ) ) {
1276
-			return false;
1277
-		}
1278
-
1279
-		return true;
1280
-	}
1281
-
1282
-	/**
1283
-	 * Check if a discount is valid for the given amount
1284
-	 *
1285
-	 * @param  float  $amount The amount to check against
1286
-	 * @since 1.0.15
1287
-	 * @return boolean
1288
-	 */
1289
-	public function is_valid_for_amount( $amount ) {
1290
-		return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount );
1291
-	}
1292
-
1293
-	/**
1294
-	 * Checks if the minimum amount is set
1295
-	 *
1296
-	 * @since 1.0.15
1297
-	 * @return boolean
1298
-	 */
1299
-	public function has_minimum_amount() {
1300
-		$minimum = $this->get_minimum_total();
1301
-		return ! empty( $minimum );
1302
-	}
1303
-
1304
-	/**
1305
-	 * Checks if the minimum amount is met
1306
-	 *
1307
-	 * @param  float  $amount The amount to check against
1308
-	 * @since 1.0.15
1309
-	 * @return boolean
1310
-	 */
1311
-	public function is_minimum_amount_met( $amount ) {
1312
-		$amount = floatval( wpinv_sanitize_amount( $amount ) );
1313
-		$min_met= ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) );
1314
-		return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->get_id(), $this, $this->get_code(), $amount );
1315
-	}
1316
-
1317
-	/**
1318
-	 * Checks if the maximum amount is set
1319
-	 *
1320
-	 * @since 1.0.15
1321
-	 * @return boolean
1322
-	 */
1323
-	public function has_maximum_amount() {
1324
-		$maximum = $this->get_maximum_total();
1325
-		return ! empty( $maximum );
1326
-	}
1327
-
1328
-	/**
1329
-	 * Checks if the maximum amount is met
1330
-	 *
1331
-	 * @param  float  $amount The amount to check against
1332
-	 * @since 1.0.15
1333
-	 * @return boolean
1334
-	 */
1335
-	public function is_maximum_amount_met( $amount ) {
1336
-		$amount = floatval( wpinv_sanitize_amount( $amount ) );
1337
-		$max_met= ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) );
1338
-		return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->get_id(), $this, $this->get_code(), $amount );
1339
-	}
1340
-
1341
-	/**
1342
-	 * Checks if the discount is recurring.
1343
-	 *
1344
-	 * @since 1.0.15
1345
-	 * @return boolean
1346
-	 */
1347
-	public function is_recurring() {
1348
-		$recurring = $this->get_is_recurring();
1349
-		return ! empty( $recurring );
1350
-	}
1351
-
1352
-	/**
1353
-	 * Checks if the discount is single use.
1354
-	 *
1355
-	 * @since 1.0.15
1356
-	 * @return boolean
1357
-	 */
1358
-	public function is_single_use() {
1359
-		$usage = $this->get_is_single_use();
1360
-		return ! empty( $usage );
1361
-	}
1362
-
1363
-	/**
1364
-	 * Check if a discount is valid for the given user
1365
-	 *
1366
-	 * @param  int|string  $user
1367
-	 * @since 1.0.15
1368
-	 * @return boolean
1369
-	 */
1370
-	public function is_valid_for_user( $user ) {
1371
-
1372
-		// Ensure that the discount is single use.
1373
-		if ( empty( $user ) || ! $this->is_single_use() ) {
1374
-			return true;
1375
-		}
1376
-
1377
-		// Prepare the user id.
1378
-		$user_id = 0;
1122
+    /**
1123
+     * Checks whether a discount exists in the database or not
1124
+     *
1125
+     * @since 1.0.15
1126
+     */
1127
+    public function exists(){
1128
+        $id = $this->get_id();
1129
+        return ! empty( $id );
1130
+    }
1131
+
1132
+    /**
1133
+     * Checks the discount type.
1134
+     *
1135
+     *
1136
+     * @param  string $type the discount type to check against
1137
+     * @since 1.0.15
1138
+     * @return bool
1139
+     */
1140
+    public function is_type( $type ) {
1141
+        return $this->get_type() == $type;
1142
+    }
1143
+
1144
+    /**
1145
+     * Checks whether the discount is published or not
1146
+     *
1147
+     * @since 1.0.15
1148
+     * @return bool
1149
+     */
1150
+    public function is_active() {
1151
+        return $this->get_status() == 'publish';
1152
+    }
1153
+
1154
+    /**
1155
+     * Checks whether the discount has max uses
1156
+     *
1157
+     * @since 1.0.15
1158
+     * @return bool
1159
+     */
1160
+    public function has_limit() {
1161
+        $limit = $this->get_max_uses();
1162
+        return ! empty( $limit );
1163
+    }
1164
+
1165
+    /**
1166
+     * Checks whether the discount has ever been used.
1167
+     *
1168
+     * @since 1.0.15
1169
+     * @return bool
1170
+     */
1171
+    public function has_uses() {
1172
+        return $this->get_uses() > 0;
1173
+    }
1174
+
1175
+    /**
1176
+     * Checks whether the discount is has exided the usage limit or not
1177
+     *
1178
+     * @since 1.0.15
1179
+     * @return bool
1180
+     */
1181
+    public function has_exceeded_limit() {
1182
+
1183
+        if ( ! $this->has_limit() || ! $this->has_uses() ) {
1184
+            $exceeded = false ;
1185
+        } else {
1186
+            $exceeded = (int) $this->get_max_uses() <= $this->get_uses();
1187
+        }
1188
+
1189
+        return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->get_id(), $this, $this->get_code() );
1190
+    }
1191
+
1192
+    /**
1193
+     * Checks whether the discount has an expiration date.
1194
+     *
1195
+     * @since 1.0.15
1196
+     * @return bool
1197
+     */
1198
+    public function has_expiration_date() {
1199
+        $date = $this->get_expiration_date();
1200
+        return ! empty( $date );
1201
+    }
1202
+
1203
+    /**
1204
+     * Checks if the discount is expired
1205
+     *
1206
+     * @since 1.0.15
1207
+     * @return bool
1208
+     */
1209
+    public function is_expired() {
1210
+        $expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false;
1211
+        return apply_filters( 'wpinv_is_discount_expired', $expired, $this->get_id(), $this, $this->get_code() );
1212
+    }
1213
+
1214
+    /**
1215
+     * Checks whether the discount has a start date.
1216
+     *
1217
+     * @since 1.0.15
1218
+     * @return bool
1219
+     */
1220
+    public function has_start_date() {
1221
+        $date = $this->get_start_date();
1222
+        return ! empty( $date );
1223
+    }
1224
+
1225
+    /**
1226
+     * Checks the discount start date.
1227
+     *
1228
+     * @since 1.0.15
1229
+     * @return bool
1230
+     */
1231
+    public function has_started() {
1232
+        $started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() );
1233
+        return apply_filters( 'wpinv_is_discount_started', $started, $this->get_id(), $this, $this->get_code() );
1234
+    }
1235
+
1236
+    /**
1237
+     * Checks the discount has allowed items or not.
1238
+     *
1239
+     * @since 1.0.15
1240
+     * @return bool
1241
+     */
1242
+    public function has_allowed_items() {
1243
+        $allowed_items = $this->get_allowed_items();
1244
+        return ! empty( $allowed_items );
1245
+    }
1246
+
1247
+    /**
1248
+     * Checks the discount has excluded items or not.
1249
+     *
1250
+     * @since 1.0.15
1251
+     * @return bool
1252
+     */
1253
+    public function has_excluded_items() {
1254
+        $excluded_items = $this->get_excluded_items();
1255
+        return ! empty( $excluded_items );
1256
+    }
1257
+
1258
+    /**
1259
+     * Check if a discount is valid for a given item id.
1260
+     *
1261
+     * @param  int|int[]  $item_ids
1262
+     * @since 1.0.15
1263
+     * @return boolean
1264
+     */
1265
+    public function is_valid_for_items( $item_ids ) {
1266
+
1267
+        $item_ids = wp_parse_id_list( $item_ids );
1268
+        $included = array_intersect( $item_ids, $this->get_allowed_items() );
1269
+        $excluded = array_intersect( $item_ids, $this->get_excluded_items() );
1270
+
1271
+        if ( $this->has_excluded_items() && ! empty( $excluded ) ) {
1272
+            return false;
1273
+        }
1274
+
1275
+        if ( $this->has_allowed_items() && empty( $included ) ) {
1276
+            return false;
1277
+        }
1278
+
1279
+        return true;
1280
+    }
1281
+
1282
+    /**
1283
+     * Check if a discount is valid for the given amount
1284
+     *
1285
+     * @param  float  $amount The amount to check against
1286
+     * @since 1.0.15
1287
+     * @return boolean
1288
+     */
1289
+    public function is_valid_for_amount( $amount ) {
1290
+        return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount );
1291
+    }
1292
+
1293
+    /**
1294
+     * Checks if the minimum amount is set
1295
+     *
1296
+     * @since 1.0.15
1297
+     * @return boolean
1298
+     */
1299
+    public function has_minimum_amount() {
1300
+        $minimum = $this->get_minimum_total();
1301
+        return ! empty( $minimum );
1302
+    }
1303
+
1304
+    /**
1305
+     * Checks if the minimum amount is met
1306
+     *
1307
+     * @param  float  $amount The amount to check against
1308
+     * @since 1.0.15
1309
+     * @return boolean
1310
+     */
1311
+    public function is_minimum_amount_met( $amount ) {
1312
+        $amount = floatval( wpinv_sanitize_amount( $amount ) );
1313
+        $min_met= ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) );
1314
+        return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->get_id(), $this, $this->get_code(), $amount );
1315
+    }
1316
+
1317
+    /**
1318
+     * Checks if the maximum amount is set
1319
+     *
1320
+     * @since 1.0.15
1321
+     * @return boolean
1322
+     */
1323
+    public function has_maximum_amount() {
1324
+        $maximum = $this->get_maximum_total();
1325
+        return ! empty( $maximum );
1326
+    }
1327
+
1328
+    /**
1329
+     * Checks if the maximum amount is met
1330
+     *
1331
+     * @param  float  $amount The amount to check against
1332
+     * @since 1.0.15
1333
+     * @return boolean
1334
+     */
1335
+    public function is_maximum_amount_met( $amount ) {
1336
+        $amount = floatval( wpinv_sanitize_amount( $amount ) );
1337
+        $max_met= ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) );
1338
+        return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->get_id(), $this, $this->get_code(), $amount );
1339
+    }
1340
+
1341
+    /**
1342
+     * Checks if the discount is recurring.
1343
+     *
1344
+     * @since 1.0.15
1345
+     * @return boolean
1346
+     */
1347
+    public function is_recurring() {
1348
+        $recurring = $this->get_is_recurring();
1349
+        return ! empty( $recurring );
1350
+    }
1351
+
1352
+    /**
1353
+     * Checks if the discount is single use.
1354
+     *
1355
+     * @since 1.0.15
1356
+     * @return boolean
1357
+     */
1358
+    public function is_single_use() {
1359
+        $usage = $this->get_is_single_use();
1360
+        return ! empty( $usage );
1361
+    }
1362
+
1363
+    /**
1364
+     * Check if a discount is valid for the given user
1365
+     *
1366
+     * @param  int|string  $user
1367
+     * @since 1.0.15
1368
+     * @return boolean
1369
+     */
1370
+    public function is_valid_for_user( $user ) {
1371
+
1372
+        // Ensure that the discount is single use.
1373
+        if ( empty( $user ) || ! $this->is_single_use() ) {
1374
+            return true;
1375
+        }
1376
+
1377
+        // Prepare the user id.
1378
+        $user_id = 0;
1379 1379
         if ( is_numeric( $user ) ) {
1380 1380
             $user_id = absint( $user );
1381 1381
         } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
@@ -1384,117 +1384,117 @@  discard block
 block discarded – undo
1384 1384
             $user_id = $user_data->ID;
1385 1385
         }
1386 1386
 
1387
-		// Ensure that we have a user.
1388
-		if ( empty( $user_id ) ) {
1389
-			return true;
1390
-		}
1387
+        // Ensure that we have a user.
1388
+        if ( empty( $user_id ) ) {
1389
+            return true;
1390
+        }
1391 1391
 
1392
-		// Get all payments with matching user id.
1392
+        // Get all payments with matching user id.
1393 1393
         $payments = wpinv_get_invoices( array( 'user' => $user_id, 'limit' => false, 'paginate' => false ) );
1394
-		$code     = strtolower( $this->get_code() );
1395
-
1396
-		// For each payment...
1397
-		foreach ( $payments as $payment ) {
1398
-
1399
-			// Only check for paid invoices.
1400
-			if ( $payment->is_paid() && strtolower( $payment->get_discount_code() ) == $code ) {
1401
-				return false;
1402
-			}
1403
-
1404
-		}
1405
-
1406
-		return true;
1407
-	}
1408
-
1409
-	/**
1410
-	 * Deletes the discount from the database
1411
-	 *
1412
-	 * @since 1.0.15
1413
-	 * @return boolean
1414
-	 */
1415
-	public function remove() {
1416
-		return $this->delete();
1417
-	}
1418
-
1419
-	/**
1420
-	 * Increases a discount's usage.
1421
-	 *
1422
-	 * @since 1.0.15
1423
-	 * @param int $by The number of usages to increas by.
1424
-	 * @return int
1425
-	 */
1426
-	public function increase_usage( $by = 1 ) {
1427
-
1428
-		// Abort if zero.
1429
-		if ( empty( $by ) ) {
1430
-			return;
1431
-		}
1432
-
1433
-		// Increase the usage.
1434
-		$this->set_uses( $this->get_uses() + (int) $by );
1435
-
1436
-		// Save the discount.
1437
-		$this->save();
1438
-
1439
-		// Fire relevant hooks.
1440
-		if( (int) $by > 0 ) {
1441
-			do_action( 'wpinv_discount_increase_use_count', $this->get_uses(), $this->get_id(), $this->get_code(),  absint( $by ) );
1442
-		} else {
1443
-			do_action( 'wpinv_discount_decrease_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) );
1444
-		}
1445
-
1446
-		// Return the number of times the discount has been used.
1447
-		return $this->get_uses();
1448
-	}
1449
-
1450
-	/**
1451
-	 * Alias of self::__toString()
1452
-	 *
1453
-	 * @since 1.0.15
1454
-	 * @return string|false
1455
-	 */
1456
-	public function get_data_as_json() {
1457
-		return $this->__toString();
1458
-	}
1459
-
1460
-	/**
1461
-	 * Returns a discount's discounted amount.
1462
-	 *
1463
-	 * @since 1.0.15
1464
-	 * @param float $amount
1465
-	 * @return float
1466
-	 */
1467
-	public function get_discounted_amount( $amount ) {
1468
-
1469
-		// Convert amount to float.
1470
-		$amount = (float) $amount;
1471
-
1472
-		// Get discount amount.
1473
-		$discount_amount = $this->get_amount();
1474
-
1475
-		if ( empty( $discount_amount ) ) {
1476
-			return 0;
1477
-		}
1478
-
1479
-		// Format the amount.
1480
-		$discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) );
1394
+        $code     = strtolower( $this->get_code() );
1395
+
1396
+        // For each payment...
1397
+        foreach ( $payments as $payment ) {
1398
+
1399
+            // Only check for paid invoices.
1400
+            if ( $payment->is_paid() && strtolower( $payment->get_discount_code() ) == $code ) {
1401
+                return false;
1402
+            }
1403
+
1404
+        }
1405
+
1406
+        return true;
1407
+    }
1408
+
1409
+    /**
1410
+     * Deletes the discount from the database
1411
+     *
1412
+     * @since 1.0.15
1413
+     * @return boolean
1414
+     */
1415
+    public function remove() {
1416
+        return $this->delete();
1417
+    }
1418
+
1419
+    /**
1420
+     * Increases a discount's usage.
1421
+     *
1422
+     * @since 1.0.15
1423
+     * @param int $by The number of usages to increas by.
1424
+     * @return int
1425
+     */
1426
+    public function increase_usage( $by = 1 ) {
1427
+
1428
+        // Abort if zero.
1429
+        if ( empty( $by ) ) {
1430
+            return;
1431
+        }
1432
+
1433
+        // Increase the usage.
1434
+        $this->set_uses( $this->get_uses() + (int) $by );
1435
+
1436
+        // Save the discount.
1437
+        $this->save();
1438
+
1439
+        // Fire relevant hooks.
1440
+        if( (int) $by > 0 ) {
1441
+            do_action( 'wpinv_discount_increase_use_count', $this->get_uses(), $this->get_id(), $this->get_code(),  absint( $by ) );
1442
+        } else {
1443
+            do_action( 'wpinv_discount_decrease_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) );
1444
+        }
1445
+
1446
+        // Return the number of times the discount has been used.
1447
+        return $this->get_uses();
1448
+    }
1449
+
1450
+    /**
1451
+     * Alias of self::__toString()
1452
+     *
1453
+     * @since 1.0.15
1454
+     * @return string|false
1455
+     */
1456
+    public function get_data_as_json() {
1457
+        return $this->__toString();
1458
+    }
1459
+
1460
+    /**
1461
+     * Returns a discount's discounted amount.
1462
+     *
1463
+     * @since 1.0.15
1464
+     * @param float $amount
1465
+     * @return float
1466
+     */
1467
+    public function get_discounted_amount( $amount ) {
1468
+
1469
+        // Convert amount to float.
1470
+        $amount = (float) $amount;
1471
+
1472
+        // Get discount amount.
1473
+        $discount_amount = $this->get_amount();
1474
+
1475
+        if ( empty( $discount_amount ) ) {
1476
+            return 0;
1477
+        }
1478
+
1479
+        // Format the amount.
1480
+        $discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) );
1481 1481
 		
1482
-		// If this is a percentage discount.
1483
-		if ( $this->is_type( 'percent' ) ) {
1482
+        // If this is a percentage discount.
1483
+        if ( $this->is_type( 'percent' ) ) {
1484 1484
             $discount_amount = $amount * ( $discount_amount / 100 );
1485
-		}
1485
+        }
1486 1486
 
1487
-		// Discount can not be less than zero...
1488
-		if ( $discount_amount < 0 ) {
1489
-			$discount_amount = 0;
1490
-		}
1487
+        // Discount can not be less than zero...
1488
+        if ( $discount_amount < 0 ) {
1489
+            $discount_amount = 0;
1490
+        }
1491 1491
 
1492
-		// ... or more than the amount.
1493
-		if ( $discount_amount > $amount ) {
1494
-			$discount_amount = $amount;
1495
-		}
1492
+        // ... or more than the amount.
1493
+        if ( $discount_amount > $amount ) {
1494
+            $discount_amount = $amount;
1495
+        }
1496 1496
 
1497
-		return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this );
1498
-	}
1497
+        return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this );
1498
+    }
1499 1499
 
1500 1500
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-post-types-admin.php 1 patch
Indentation   +639 added lines, -639 removed lines patch added patch discarded remove patch
@@ -13,646 +13,646 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Post_Types_Admin {
14 14
 
15 15
     /**
16
-	 * Hook in methods.
17
-	 */
18
-	public static function init() {
19
-
20
-		// Init metaboxes.
21
-		GetPaid_Metaboxes::init();
22
-
23
-		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
-
26
-		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
29
-
30
-		// Invoice table columns.
31
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
-
34
-		// Items table columns.
35
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
36
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
37
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
38
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
39
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
40
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
41
-
42
-		// Payment forms columns.
43
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
44
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
45
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
46
-
47
-		// Discount table columns.
48
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
49
-		add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
50
-
51
-		// Deleting posts.
52
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
53
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
54
-	}
55
-
56
-	/**
57
-	 * Post updated messages.
58
-	 */
59
-	public static function post_updated_messages( $messages ) {
60
-		global $post;
61
-
62
-		$messages['wpi_discount'] = array(
63
-			0   => '',
64
-			1   => __( 'Discount updated.', 'invoicing' ),
65
-			2   => __( 'Custom field updated.', 'invoicing' ),
66
-			3   => __( 'Custom field deleted.', 'invoicing' ),
67
-			4   => __( 'Discount updated.', 'invoicing' ),
68
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
69
-			6   => __( 'Discount updated.', 'invoicing' ),
70
-			7   => __( 'Discount saved.', 'invoicing' ),
71
-			8   => __( 'Discount submitted.', 'invoicing' ),
72
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
73
-			10  => __( 'Discount draft updated.', 'invoicing' ),
74
-		);
75
-
76
-		$messages['wpi_payment_form'] = array(
77
-			0   => '',
78
-			1   => __( 'Payment Form updated.', 'invoicing' ),
79
-			2   => __( 'Custom field updated.', 'invoicing' ),
80
-			3   => __( 'Custom field deleted.', 'invoicing' ),
81
-			4   => __( 'Payment Form updated.', 'invoicing' ),
82
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
83
-			6   => __( 'Payment Form updated.', 'invoicing' ),
84
-			7   => __( 'Payment Form saved.', 'invoicing' ),
85
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
86
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
87
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
88
-		);
89
-
90
-		return $messages;
91
-
92
-	}
93
-
94
-	/**
95
-	 * Post row actions.
96
-	 */
97
-	public static function post_row_actions( $actions, $post ) {
98
-
99
-		$post = get_post( $post );
100
-
101
-		// We do not want to edit the default payment form.
102
-		if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
103
-			unset( $actions['trash'] );
104
-			unset( $actions['inline hide-if-no-js'] );
105
-		}
106
-
107
-		return $actions;
108
-	}
109
-
110
-	/**
16
+     * Hook in methods.
17
+     */
18
+    public static function init() {
19
+
20
+        // Init metaboxes.
21
+        GetPaid_Metaboxes::init();
22
+
23
+        // Filter the post updated messages.
24
+        add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
+
26
+        // Filter post actions.
27
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
29
+
30
+        // Invoice table columns.
31
+        add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
+        add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
+
34
+        // Items table columns.
35
+        add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
36
+        add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
37
+        add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
38
+        add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
39
+        add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
40
+        add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
41
+
42
+        // Payment forms columns.
43
+        add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
44
+        add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
45
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
46
+
47
+        // Discount table columns.
48
+        add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
49
+        add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
50
+
51
+        // Deleting posts.
52
+        add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
53
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
54
+    }
55
+
56
+    /**
57
+     * Post updated messages.
58
+     */
59
+    public static function post_updated_messages( $messages ) {
60
+        global $post;
61
+
62
+        $messages['wpi_discount'] = array(
63
+            0   => '',
64
+            1   => __( 'Discount updated.', 'invoicing' ),
65
+            2   => __( 'Custom field updated.', 'invoicing' ),
66
+            3   => __( 'Custom field deleted.', 'invoicing' ),
67
+            4   => __( 'Discount updated.', 'invoicing' ),
68
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
69
+            6   => __( 'Discount updated.', 'invoicing' ),
70
+            7   => __( 'Discount saved.', 'invoicing' ),
71
+            8   => __( 'Discount submitted.', 'invoicing' ),
72
+            9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
73
+            10  => __( 'Discount draft updated.', 'invoicing' ),
74
+        );
75
+
76
+        $messages['wpi_payment_form'] = array(
77
+            0   => '',
78
+            1   => __( 'Payment Form updated.', 'invoicing' ),
79
+            2   => __( 'Custom field updated.', 'invoicing' ),
80
+            3   => __( 'Custom field deleted.', 'invoicing' ),
81
+            4   => __( 'Payment Form updated.', 'invoicing' ),
82
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
83
+            6   => __( 'Payment Form updated.', 'invoicing' ),
84
+            7   => __( 'Payment Form saved.', 'invoicing' ),
85
+            8   => __( 'Payment Form submitted.', 'invoicing' ),
86
+            9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
87
+            10  => __( 'Payment Form draft updated.', 'invoicing' ),
88
+        );
89
+
90
+        return $messages;
91
+
92
+    }
93
+
94
+    /**
95
+     * Post row actions.
96
+     */
97
+    public static function post_row_actions( $actions, $post ) {
98
+
99
+        $post = get_post( $post );
100
+
101
+        // We do not want to edit the default payment form.
102
+        if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
103
+            unset( $actions['trash'] );
104
+            unset( $actions['inline hide-if-no-js'] );
105
+        }
106
+
107
+        return $actions;
108
+    }
109
+
110
+    /**
111 111
      * Remove bulk edit option from admin side quote listing
112 112
      *
113 113
      * @since    1.0.0
114 114
      * @param array $actions post actions
115
-	 * @param WP_Post $post
115
+     * @param WP_Post $post
116 116
      * @return array $actions actions without edit option
117 117
      */
118 118
     public static function filter_invoice_row_actions( $actions, $post ) {
119 119
 
120 120
         if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
121 121
 
122
-			$actions = array();
123
-			$invoice = new WPInv_Invoice( $post );
124
-
125
-			$actions['edit'] =  sprintf(
126
-				'<a href="%1$s">%2$s</a>',
127
-				esc_url( get_edit_post_link( $invoice->get_id() ) ),
128
-				esc_html( __( 'Edit', 'invoicing' ) )
129
-			);
130
-
131
-			if ( ! $invoice->is_draft() ) {
132
-
133
-				$actions['view'] =  sprintf(
134
-					'<a href="%1$s">%2$s</a>',
135
-					esc_url( $invoice->get_view_url() ),
136
-					sprintf(
137
-						esc_html( __( 'View %s', 'invoicing' ) ),
138
-						getpaid_get_post_type_label( $invoice->get_post_type(), false )
139
-					)
140
-				);
141
-
142
-				$actions['send'] =  sprintf(
143
-					'<a href="%1$s">%2$s</a>',
144
-					esc_url(
145
-						wp_nonce_url(
146
-							add_query_arg(
147
-								array(
148
-									'getpaid-admin-action' => 'send_invoice',
149
-									'invoice_id'           => $invoice->get_id()
150
-								)
151
-							),
152
-							'getpaid-nonce',
153
-							'getpaid-nonce'
154
-						)
155
-					),
156
-					esc_html( __( 'Send to Customer', 'invoicing' ) )
157
-				);
158
-
159
-			}
122
+            $actions = array();
123
+            $invoice = new WPInv_Invoice( $post );
124
+
125
+            $actions['edit'] =  sprintf(
126
+                '<a href="%1$s">%2$s</a>',
127
+                esc_url( get_edit_post_link( $invoice->get_id() ) ),
128
+                esc_html( __( 'Edit', 'invoicing' ) )
129
+            );
130
+
131
+            if ( ! $invoice->is_draft() ) {
132
+
133
+                $actions['view'] =  sprintf(
134
+                    '<a href="%1$s">%2$s</a>',
135
+                    esc_url( $invoice->get_view_url() ),
136
+                    sprintf(
137
+                        esc_html( __( 'View %s', 'invoicing' ) ),
138
+                        getpaid_get_post_type_label( $invoice->get_post_type(), false )
139
+                    )
140
+                );
141
+
142
+                $actions['send'] =  sprintf(
143
+                    '<a href="%1$s">%2$s</a>',
144
+                    esc_url(
145
+                        wp_nonce_url(
146
+                            add_query_arg(
147
+                                array(
148
+                                    'getpaid-admin-action' => 'send_invoice',
149
+                                    'invoice_id'           => $invoice->get_id()
150
+                                )
151
+                            ),
152
+                            'getpaid-nonce',
153
+                            'getpaid-nonce'
154
+                        )
155
+                    ),
156
+                    esc_html( __( 'Send to Customer', 'invoicing' ) )
157
+                );
158
+
159
+            }
160 160
 
161 161
         }
162 162
 
163 163
         return $actions;
164
-	}
165
-
166
-	/**
167
-	 * Returns an array of invoice table columns.
168
-	 */
169
-	public static function invoice_columns( $columns ) {
170
-
171
-		$columns = array(
172
-			'cb'                => $columns['cb'],
173
-			'number'            => __( 'Invoice', 'invoicing' ),
174
-			'customer'          => __( 'Customer', 'invoicing' ),
175
-			'invoice_date'      => __( 'Created', 'invoicing' ),
176
-			'payment_date'      => __( 'Completed', 'invoicing' ),
177
-			'amount'            => __( 'Amount', 'invoicing' ),
178
-			'recurring'         => __( 'Recurring', 'invoicing' ),
179
-			'status'            => __( 'Status', 'invoicing' ),
180
-		);
181
-
182
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
183
-	}
184
-
185
-	/**
186
-	 * Displays invoice table columns.
187
-	 */
188
-	public static function display_invoice_columns( $column_name, $post_id ) {
189
-
190
-		$invoice = new WPInv_Invoice( $post_id );
191
-
192
-		switch ( $column_name ) {
193
-
194
-			case 'invoice_date' :
195
-				$date_time = esc_attr( $invoice->get_created_date() );
196
-				$date      = getpaid_format_date_value( $date_time, "&mdash;", true );
197
-				echo "<span title='$date_time'>$date</span>";
198
-				break;
199
-
200
-			case 'payment_date' :
201
-
202
-				if ( $invoice->is_paid() ) {
203
-					$date_time = esc_attr( $invoice->get_completed_date() );
204
-					$date      = getpaid_format_date_value( $date_time, "&mdash;", true );
205
-					echo "<span title='$date_time'>$date</span>";
206
-				} else {
207
-					echo "&mdash;";
208
-				}
164
+    }
165
+
166
+    /**
167
+     * Returns an array of invoice table columns.
168
+     */
169
+    public static function invoice_columns( $columns ) {
170
+
171
+        $columns = array(
172
+            'cb'                => $columns['cb'],
173
+            'number'            => __( 'Invoice', 'invoicing' ),
174
+            'customer'          => __( 'Customer', 'invoicing' ),
175
+            'invoice_date'      => __( 'Created', 'invoicing' ),
176
+            'payment_date'      => __( 'Completed', 'invoicing' ),
177
+            'amount'            => __( 'Amount', 'invoicing' ),
178
+            'recurring'         => __( 'Recurring', 'invoicing' ),
179
+            'status'            => __( 'Status', 'invoicing' ),
180
+        );
181
+
182
+        return apply_filters( 'wpi_invoice_table_columns', $columns );
183
+    }
184
+
185
+    /**
186
+     * Displays invoice table columns.
187
+     */
188
+    public static function display_invoice_columns( $column_name, $post_id ) {
189
+
190
+        $invoice = new WPInv_Invoice( $post_id );
191
+
192
+        switch ( $column_name ) {
193
+
194
+            case 'invoice_date' :
195
+                $date_time = esc_attr( $invoice->get_created_date() );
196
+                $date      = getpaid_format_date_value( $date_time, "&mdash;", true );
197
+                echo "<span title='$date_time'>$date</span>";
198
+                break;
199
+
200
+            case 'payment_date' :
201
+
202
+                if ( $invoice->is_paid() ) {
203
+                    $date_time = esc_attr( $invoice->get_completed_date() );
204
+                    $date      = getpaid_format_date_value( $date_time, "&mdash;", true );
205
+                    echo "<span title='$date_time'>$date</span>";
206
+                } else {
207
+                    echo "&mdash;";
208
+                }
209 209
 				
210
-				break;
210
+                break;
211 211
 
212
-			case 'amount' :
212
+            case 'amount' :
213 213
 
214
-				$amount = $invoice->get_total();
215
-				$formated_amount = wpinv_price( $amount, $invoice->get_currency() );
214
+                $amount = $invoice->get_total();
215
+                $formated_amount = wpinv_price( $amount, $invoice->get_currency() );
216 216
 
217
-				if ( $invoice->is_refunded() ) {
218
-					$refunded_amount = wpinv_price( 0, $invoice->get_currency() );
219
-					echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
220
-				} else {
217
+                if ( $invoice->is_refunded() ) {
218
+                    $refunded_amount = wpinv_price( 0, $invoice->get_currency() );
219
+                    echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
220
+                } else {
221 221
 
222
-					$discount = $invoice->get_total_discount();
222
+                    $discount = $invoice->get_total_discount();
223 223
 
224
-					if ( ! empty( $discount ) ) {
225
-						$new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() );
226
-						echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
227
-					} else {
228
-						echo $formated_amount;
229
-					}
224
+                    if ( ! empty( $discount ) ) {
225
+                        $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() );
226
+                        echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
227
+                    } else {
228
+                        echo $formated_amount;
229
+                    }
230 230
 
231
-				}
231
+                }
232 232
 
233
-				break;
233
+                break;
234 234
 
235
-			case 'status' :
236
-				$status       = sanitize_text_field( $invoice->get_status() );
237
-				$status_label = sanitize_text_field( $invoice->get_status_nicename() );
235
+            case 'status' :
236
+                $status       = sanitize_text_field( $invoice->get_status() );
237
+                $status_label = sanitize_text_field( $invoice->get_status_nicename() );
238 238
 
239
-				// If it is paid, show the gateway title.
240
-				if ( $invoice->is_paid() ) {
241
-					$gateway = sanitize_text_field( $invoice->get_gateway_title() );
242
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
239
+                // If it is paid, show the gateway title.
240
+                if ( $invoice->is_paid() ) {
241
+                    $gateway = sanitize_text_field( $invoice->get_gateway_title() );
242
+                    $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
243 243
 
244
-					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
245
-				} else {
246
-					echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
247
-				}
244
+                    echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
245
+                } else {
246
+                    echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
247
+                }
248 248
 
249
-				// If it is not paid, display the overdue and view status.
250
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
249
+                // If it is not paid, display the overdue and view status.
250
+                if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
251 251
 
252
-					// Invoice view status.
253
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
254
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
255
-					} else {
256
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
257
-					}
252
+                    // Invoice view status.
253
+                    if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
254
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
255
+                    } else {
256
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
257
+                    }
258 258
 
259
-					// Display the overview status.
260
-					if ( wpinv_get_option( 'overdue_active' ) ) {
261
-						$due_date = $invoice->get_due_date();
262
-						$fomatted = getpaid_format_date( $due_date );
259
+                    // Display the overview status.
260
+                    if ( wpinv_get_option( 'overdue_active' ) ) {
261
+                        $due_date = $invoice->get_due_date();
262
+                        $fomatted = getpaid_format_date( $due_date );
263 263
 
264
-						if ( ! empty( $fomatted ) ) {
265
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
266
-							echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
267
-						}
268
-					}
264
+                        if ( ! empty( $fomatted ) ) {
265
+                            $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
266
+                            echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
267
+                        }
268
+                    }
269 269
 
270
-				}
270
+                }
271 271
 
272
-				break;
272
+                break;
273 273
 
274
-			case 'recurring':
274
+            case 'recurring':
275 275
 
276
-				if ( $invoice->is_recurring() ) {
277
-					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
278
-				} else {
279
-					echo '<i class="fa fa-times" style="color:#616161;"></i>';
280
-				}
281
-				break;
276
+                if ( $invoice->is_recurring() ) {
277
+                    echo '<i class="fa fa-check" style="color:#43850a;"></i>';
278
+                } else {
279
+                    echo '<i class="fa fa-times" style="color:#616161;"></i>';
280
+                }
281
+                break;
282 282
 
283
-			case 'number' :
283
+            case 'number' :
284 284
 
285
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
286
-				$invoice_number  = sanitize_text_field( $invoice->get_number() );
287
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
285
+                $edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
286
+                $invoice_number  = sanitize_text_field( $invoice->get_number() );
287
+                $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
288 288
 
289
-				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
289
+                echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
290 290
 
291
-				break;
291
+                break;
292 292
 
293
-			case 'customer' :
293
+            case 'customer' :
294 294
 	
295
-				$customer_name = $invoice->get_user_full_name();
295
+                $customer_name = $invoice->get_user_full_name();
296 296
 	
297
-				if ( empty( $customer_name ) ) {
298
-					$customer_name = $invoice->get_email();
299
-				}
297
+                if ( empty( $customer_name ) ) {
298
+                    $customer_name = $invoice->get_email();
299
+                }
300 300
 	
301
-				if ( ! empty( $customer_name ) ) {
302
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
303
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
304
-					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
305
-				} else {
306
-					echo '<div>&mdash;</div>';
307
-				}
301
+                if ( ! empty( $customer_name ) ) {
302
+                    $customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
303
+                    $view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
304
+                    echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
305
+                } else {
306
+                    echo '<div>&mdash;</div>';
307
+                }
308 308
 
309
-				break;
309
+                break;
310 310
 
311
-		}
311
+        }
312 312
 
313
-	}
313
+    }
314 314
 
315
-	/**
316
-	 * Returns an array of payment forms table columns.
317
-	 */
318
-	public static function payment_form_columns( $columns ) {
315
+    /**
316
+     * Returns an array of payment forms table columns.
317
+     */
318
+    public static function payment_form_columns( $columns ) {
319 319
 
320
-		$columns = array(
321
-			'cb'                => $columns['cb'],
322
-			'title'             => __( 'Name', 'invoicing' ),
323
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
324
-			'earnings'          => __( 'Revenue', 'invoicing' ),
325
-			'refunds'           => __( 'Refunded', 'invoicing' ),
326
-			'items'             => __( 'Items', 'invoicing' ),
327
-			'date'              => __( 'Date', 'invoicing' ),
328
-		);
320
+        $columns = array(
321
+            'cb'                => $columns['cb'],
322
+            'title'             => __( 'Name', 'invoicing' ),
323
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
324
+            'earnings'          => __( 'Revenue', 'invoicing' ),
325
+            'refunds'           => __( 'Refunded', 'invoicing' ),
326
+            'items'             => __( 'Items', 'invoicing' ),
327
+            'date'              => __( 'Date', 'invoicing' ),
328
+        );
329 329
 
330
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
330
+        return apply_filters( 'wpi_payment_form_table_columns', $columns );
331 331
 
332
-	}
332
+    }
333 333
 
334
-	/**
335
-	 * Displays payment form table columns.
336
-	 */
337
-	public static function display_payment_form_columns( $column_name, $post_id ) {
334
+    /**
335
+     * Displays payment form table columns.
336
+     */
337
+    public static function display_payment_form_columns( $column_name, $post_id ) {
338 338
 
339
-		// Retrieve the payment form.
340
-		$form = new GetPaid_Payment_Form( $post_id );
339
+        // Retrieve the payment form.
340
+        $form = new GetPaid_Payment_Form( $post_id );
341 341
 
342
-		switch ( $column_name ) {
342
+        switch ( $column_name ) {
343 343
 
344
-			case 'earnings' :
345
-				echo wpinv_price( $form->get_earned() );
346
-				break;
344
+            case 'earnings' :
345
+                echo wpinv_price( $form->get_earned() );
346
+                break;
347 347
 
348
-			case 'refunds' :
349
-				echo wpinv_price( $form->get_refunded() );
350
-				break;
348
+            case 'refunds' :
349
+                echo wpinv_price( $form->get_refunded() );
350
+                break;
351 351
 
352
-			case 'refunds' :
353
-				echo wpinv_price( $form->get_refunded() );
354
-				break;
352
+            case 'refunds' :
353
+                echo wpinv_price( $form->get_refunded() );
354
+                break;
355 355
 
356
-			case 'shortcode' :
356
+            case 'shortcode' :
357 357
 
358
-				if ( $form->is_default() ) {
359
-					echo '&mdash;';
360
-				} else {
361
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
362
-				}
358
+                if ( $form->is_default() ) {
359
+                    echo '&mdash;';
360
+                } else {
361
+                    echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
362
+                }
363 363
 
364
-				break;
364
+                break;
365 365
 
366
-			case 'items' :
366
+            case 'items' :
367 367
 
368
-				$items = $form->get_items();
368
+                $items = $form->get_items();
369 369
 
370
-				if ( $form->is_default() || empty( $items ) ) {
371
-					echo '&mdash;';
372
-					return;
373
-				}
370
+                if ( $form->is_default() || empty( $items ) ) {
371
+                    echo '&mdash;';
372
+                    return;
373
+                }
374 374
 
375
-				$_items = array();
375
+                $_items = array();
376 376
 
377
-				foreach ( $items as $item ) {
378
-					$url = $item->get_edit_url();
377
+                foreach ( $items as $item ) {
378
+                    $url = $item->get_edit_url();
379 379
 
380
-					if ( empty( $url ) ) {
381
-						$_items[] = sanitize_text_field( $item->get_name() );
382
-					} else {
383
-						$_items[] = sprintf(
384
-							'<a href="%s">%s</a>',
385
-							esc_url( $url ),
386
-							sanitize_text_field( $item->get_name() )
387
-						);
388
-					}
380
+                    if ( empty( $url ) ) {
381
+                        $_items[] = sanitize_text_field( $item->get_name() );
382
+                    } else {
383
+                        $_items[] = sprintf(
384
+                            '<a href="%s">%s</a>',
385
+                            esc_url( $url ),
386
+                            sanitize_text_field( $item->get_name() )
387
+                        );
388
+                    }
389 389
 
390
-				}
390
+                }
391 391
 
392
-				echo implode( '<br>', $_items );
392
+                echo implode( '<br>', $_items );
393 393
 
394
-				break;
394
+                break;
395 395
 
396
-		}
396
+        }
397 397
 
398
-	}
398
+    }
399 399
 
400
-	/**
401
-	 * Filters post states.
402
-	 */
403
-	public static function filter_payment_form_state( $post_states, $post ) {
400
+    /**
401
+     * Filters post states.
402
+     */
403
+    public static function filter_payment_form_state( $post_states, $post ) {
404 404
 
405
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
406
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
407
-		}
405
+        if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
406
+            $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
407
+        }
408 408
 	
409
-		return $post_states;
410
-
411
-	}
412
-
413
-	/**
414
-	 * Returns an array of coupon table columns.
415
-	 */
416
-	public static function discount_columns( $columns ) {
417
-
418
-		$columns = array(
419
-			'cb'                => $columns['cb'],
420
-			'title'             => __( 'Name', 'invoicing' ),
421
-			'code'              => __( 'Code', 'invoicing' ),
422
-			'amount'            => __( 'Amount', 'invoicing' ),
423
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
424
-			'start_date'        => __( 'Start Date', 'invoicing' ),
425
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
426
-		);
427
-
428
-		return apply_filters( 'wpi_discount_table_columns', $columns );
429
-	}
430
-
431
-	/**
432
-	 * Filters post states.
433
-	 */
434
-	public static function filter_discount_state( $post_states, $post ) {
435
-
436
-		if ( 'wpi_discount' == $post->post_type ) {
437
-
438
-			$discount = new WPInv_Discount( $post );
439
-
440
-			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
441
-
442
-			if ( $status != 'publish' ) {
443
-				return array(
444
-					'discount_status' => wpinv_discount_status( $status ),
445
-				);
446
-			}
447
-
448
-			return array();
449
-
450
-		}
451
-
452
-		return $post_states;
453
-
454
-	}
455
-
456
-	/**
457
-	 * Returns an array of items table columns.
458
-	 */
459
-	public static function item_columns( $columns ) {
460
-
461
-		$columns = array(
462
-			'cb'                => $columns['cb'],
463
-			'title'             => __( 'Name', 'invoicing' ),
464
-			'price'             => __( 'Price', 'invoicing' ),
465
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
466
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
467
-			'type'              => __( 'Type', 'invoicing' ),
468
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
469
-		);
470
-
471
-		if ( ! wpinv_use_taxes() ) {
472
-			unset( $columns['vat_rule'] );
473
-			unset( $columns['vat_class'] );
474
-		}
475
-
476
-		return apply_filters( 'wpi_item_table_columns', $columns );
477
-	}
478
-
479
-	/**
480
-	 * Returns an array of sortable items table columns.
481
-	 */
482
-	public static function sortable_item_columns( $columns ) {
483
-
484
-		return array_merge(
485
-			$columns,
486
-			array(
487
-				'price'     => 'price',
488
-				'vat_rule'  => 'vat_rule',
489
-				'vat_class' => 'vat_class',
490
-				'type'      => 'type',
491
-			)
492
-		);
493
-
494
-	}
495
-
496
-	/**
497
-	 * Displays items table columns.
498
-	 */
499
-	public static function display_item_columns( $column_name, $post_id ) {
409
+        return $post_states;
410
+
411
+    }
412
+
413
+    /**
414
+     * Returns an array of coupon table columns.
415
+     */
416
+    public static function discount_columns( $columns ) {
417
+
418
+        $columns = array(
419
+            'cb'                => $columns['cb'],
420
+            'title'             => __( 'Name', 'invoicing' ),
421
+            'code'              => __( 'Code', 'invoicing' ),
422
+            'amount'            => __( 'Amount', 'invoicing' ),
423
+            'usage'             => __( 'Usage / Limit', 'invoicing' ),
424
+            'start_date'        => __( 'Start Date', 'invoicing' ),
425
+            'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
426
+        );
427
+
428
+        return apply_filters( 'wpi_discount_table_columns', $columns );
429
+    }
430
+
431
+    /**
432
+     * Filters post states.
433
+     */
434
+    public static function filter_discount_state( $post_states, $post ) {
435
+
436
+        if ( 'wpi_discount' == $post->post_type ) {
437
+
438
+            $discount = new WPInv_Discount( $post );
439
+
440
+            $status = $discount->is_expired() ? 'expired' : $discount->get_status();
441
+
442
+            if ( $status != 'publish' ) {
443
+                return array(
444
+                    'discount_status' => wpinv_discount_status( $status ),
445
+                );
446
+            }
447
+
448
+            return array();
449
+
450
+        }
451
+
452
+        return $post_states;
453
+
454
+    }
455
+
456
+    /**
457
+     * Returns an array of items table columns.
458
+     */
459
+    public static function item_columns( $columns ) {
460
+
461
+        $columns = array(
462
+            'cb'                => $columns['cb'],
463
+            'title'             => __( 'Name', 'invoicing' ),
464
+            'price'             => __( 'Price', 'invoicing' ),
465
+            'vat_rule'          => __( 'VAT rule', 'invoicing' ),
466
+            'vat_class'         => __( 'VAT class', 'invoicing' ),
467
+            'type'              => __( 'Type', 'invoicing' ),
468
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
469
+        );
470
+
471
+        if ( ! wpinv_use_taxes() ) {
472
+            unset( $columns['vat_rule'] );
473
+            unset( $columns['vat_class'] );
474
+        }
475
+
476
+        return apply_filters( 'wpi_item_table_columns', $columns );
477
+    }
478
+
479
+    /**
480
+     * Returns an array of sortable items table columns.
481
+     */
482
+    public static function sortable_item_columns( $columns ) {
483
+
484
+        return array_merge(
485
+            $columns,
486
+            array(
487
+                'price'     => 'price',
488
+                'vat_rule'  => 'vat_rule',
489
+                'vat_class' => 'vat_class',
490
+                'type'      => 'type',
491
+            )
492
+        );
493
+
494
+    }
495
+
496
+    /**
497
+     * Displays items table columns.
498
+     */
499
+    public static function display_item_columns( $column_name, $post_id ) {
500 500
  
501
-		$item = new WPInv_Item( $post_id );
501
+        $item = new WPInv_Item( $post_id );
502 502
 
503
-		switch ( $column_name ) {
503
+        switch ( $column_name ) {
504 504
 
505
-			case 'price' :
505
+            case 'price' :
506 506
 
507
-				if ( ! $item->is_recurring() ) {
508
-					echo $item->get_the_price();
509
-					break;
510
-				}
507
+                if ( ! $item->is_recurring() ) {
508
+                    echo $item->get_the_price();
509
+                    break;
510
+                }
511 511
 
512
-				$price = wp_sprintf(
513
-					__( '%s / %s', 'invoicing' ),
514
-					$item->get_the_price(),
515
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
516
-				);
512
+                $price = wp_sprintf(
513
+                    __( '%s / %s', 'invoicing' ),
514
+                    $item->get_the_price(),
515
+                    getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
516
+                );
517 517
 
518
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
519
-					echo $price;
520
-					break;
521
-				}
518
+                if ( $item->get_the_price() == $item->get_the_initial_price() ) {
519
+                    echo $price;
520
+                    break;
521
+                }
522 522
 
523
-				echo $item->get_the_initial_price();
523
+                echo $item->get_the_initial_price();
524 524
 
525
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
526
-				break;
525
+                echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
526
+                break;
527 527
 
528
-			case 'vat_rule' :
529
-				echo getpaid_get_tax_rule_label( $item->get_vat_rule() );
530
-				break;
528
+            case 'vat_rule' :
529
+                echo getpaid_get_tax_rule_label( $item->get_vat_rule() );
530
+                break;
531 531
 
532
-			case 'vat_class' :
533
-				echo getpaid_get_tax_class_label( $item->get_vat_class() );
534
-				break;
532
+            case 'vat_class' :
533
+                echo getpaid_get_tax_class_label( $item->get_vat_class() );
534
+                break;
535 535
 
536
-			case 'shortcode' :
537
-				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
538
-				break;
536
+            case 'shortcode' :
537
+                echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
538
+                break;
539 539
 
540
-			case 'type' :
541
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
542
-				break;
540
+            case 'type' :
541
+                echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
542
+                break;
543 543
 
544
-		}
544
+        }
545 545
 
546
-	}
546
+    }
547 547
 
548
-	/**
549
-	 * Lets users filter items using taxes.
550
-	 */
551
-	public static function add_item_filters( $post_type ) {
548
+    /**
549
+     * Lets users filter items using taxes.
550
+     */
551
+    public static function add_item_filters( $post_type ) {
552 552
 
553
-		// Abort if we're not dealing with items.
554
-		if ( $post_type != 'wpi_item' ) {
555
-			return;
556
-		}
553
+        // Abort if we're not dealing with items.
554
+        if ( $post_type != 'wpi_item' ) {
555
+            return;
556
+        }
557 557
 
558
-		// Filter by vat rules.
559
-		if ( wpinv_use_taxes() ) {
558
+        // Filter by vat rules.
559
+        if ( wpinv_use_taxes() ) {
560 560
 	
561
-			// Sanitize selected vat rule.
562
-			$vat_rule   = '';
563
-			$vat_rules  = getpaid_get_tax_rules();
564
-			if ( isset( $_GET['vat_rule'] ) ) {
565
-				$vat_rule   =  $_GET['vat_rule'];
566
-			}
567
-
568
-			// Filter by VAT rule.
569
-			echo wpinv_html_select(
570
-				array(
571
-					'options'          => array_merge(
572
-						array(
573
-							'' => __( 'All VAT rules', 'invoicing' )
574
-						),
575
-						$vat_rules
576
-					),
577
-					'name'             => 'vat_rule',
578
-					'id'               => 'vat_rule',
579
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
580
-					'show_option_all'  => false,
581
-					'show_option_none' => false,
582
-				)
583
-			);
584
-
585
-			// Filter by VAT class.
561
+            // Sanitize selected vat rule.
562
+            $vat_rule   = '';
563
+            $vat_rules  = getpaid_get_tax_rules();
564
+            if ( isset( $_GET['vat_rule'] ) ) {
565
+                $vat_rule   =  $_GET['vat_rule'];
566
+            }
567
+
568
+            // Filter by VAT rule.
569
+            echo wpinv_html_select(
570
+                array(
571
+                    'options'          => array_merge(
572
+                        array(
573
+                            '' => __( 'All VAT rules', 'invoicing' )
574
+                        ),
575
+                        $vat_rules
576
+                    ),
577
+                    'name'             => 'vat_rule',
578
+                    'id'               => 'vat_rule',
579
+                    'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
580
+                    'show_option_all'  => false,
581
+                    'show_option_none' => false,
582
+                )
583
+            );
584
+
585
+            // Filter by VAT class.
586 586
 	
587
-			// Sanitize selected vat rule.
588
-			$vat_class   = '';
589
-			$vat_classes = getpaid_get_tax_classes();
590
-			if ( isset( $_GET['vat_class'] ) ) {
591
-				$vat_class   =  $_GET['vat_class'];
592
-			}
593
-
594
-			echo wpinv_html_select(
595
-				array(
596
-					'options'          => array_merge(
597
-						array(
598
-							'' => __( 'All VAT classes', 'invoicing' )
599
-						),
600
-						$vat_classes
601
-					),
602
-					'name'             => 'vat_class',
603
-					'id'               => 'vat_class',
604
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
605
-					'show_option_all'  => false,
606
-					'show_option_none' => false,
607
-				)
608
-			);
609
-
610
-		}
611
-
612
-		// Filter by item type.
613
-		$type   = '';
614
-		if ( isset( $_GET['type'] ) ) {
615
-			$type   =  $_GET['type'];
616
-		}
617
-
618
-		echo wpinv_html_select(
619
-			array(
620
-				'options'          => array_merge(
621
-					array(
622
-						'' => __( 'All item types', 'invoicing' )
623
-					),
624
-					wpinv_get_item_types()
625
-				),
626
-				'name'             => 'type',
627
-				'id'               => 'type',
628
-				'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
629
-				'show_option_all'  => false,
630
-				'show_option_none' => false,
631
-			)
632
-		);
633
-
634
-	}
635
-
636
-	/**
637
-	 * Filters the item query.
638
-	 */
639
-	public static function filter_item_query( $query ) {
640
-
641
-		// modify the query only if it admin and main query.
642
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
643
-			return $query;
644
-		}
645
-
646
-		// we want to modify the query for our items.
647
-		if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){
648
-			return $query;
649
-		}
650
-
651
-		if ( empty( $query->query_vars['meta_query'] ) ) {
652
-			$query->query_vars['meta_query'] = array();
653
-		}
654
-
655
-		// Filter vat rule type
587
+            // Sanitize selected vat rule.
588
+            $vat_class   = '';
589
+            $vat_classes = getpaid_get_tax_classes();
590
+            if ( isset( $_GET['vat_class'] ) ) {
591
+                $vat_class   =  $_GET['vat_class'];
592
+            }
593
+
594
+            echo wpinv_html_select(
595
+                array(
596
+                    'options'          => array_merge(
597
+                        array(
598
+                            '' => __( 'All VAT classes', 'invoicing' )
599
+                        ),
600
+                        $vat_classes
601
+                    ),
602
+                    'name'             => 'vat_class',
603
+                    'id'               => 'vat_class',
604
+                    'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
605
+                    'show_option_all'  => false,
606
+                    'show_option_none' => false,
607
+                )
608
+            );
609
+
610
+        }
611
+
612
+        // Filter by item type.
613
+        $type   = '';
614
+        if ( isset( $_GET['type'] ) ) {
615
+            $type   =  $_GET['type'];
616
+        }
617
+
618
+        echo wpinv_html_select(
619
+            array(
620
+                'options'          => array_merge(
621
+                    array(
622
+                        '' => __( 'All item types', 'invoicing' )
623
+                    ),
624
+                    wpinv_get_item_types()
625
+                ),
626
+                'name'             => 'type',
627
+                'id'               => 'type',
628
+                'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
629
+                'show_option_all'  => false,
630
+                'show_option_none' => false,
631
+            )
632
+        );
633
+
634
+    }
635
+
636
+    /**
637
+     * Filters the item query.
638
+     */
639
+    public static function filter_item_query( $query ) {
640
+
641
+        // modify the query only if it admin and main query.
642
+        if ( ! ( is_admin() && $query->is_main_query() ) ){ 
643
+            return $query;
644
+        }
645
+
646
+        // we want to modify the query for our items.
647
+        if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){
648
+            return $query;
649
+        }
650
+
651
+        if ( empty( $query->query_vars['meta_query'] ) ) {
652
+            $query->query_vars['meta_query'] = array();
653
+        }
654
+
655
+        // Filter vat rule type
656 656
         if ( ! empty( $_GET['vat_rule'] ) ) {
657 657
             $query->query_vars['meta_query'][] = array(
658 658
                 'key'     => '_wpinv_vat_rule',
@@ -677,94 +677,94 @@  discard block
 block discarded – undo
677 677
                 'value'   => sanitize_text_field( $_GET['type'] ),
678 678
                 'compare' => '='
679 679
             );
680
-		}
681
-
682
-	}
683
-
684
-	/**
685
-	 * Reorders items.
686
-	 */
687
-	public static function reorder_items( $vars ) {
688
-		global $typenow;
689
-
690
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
691
-			return $vars;
692
-		}
693
-
694
-		// By item type.
695
-		if ( 'type' == $vars['orderby'] ) {
696
-			return array_merge(
697
-				$vars,
698
-				array(
699
-					'meta_key' => '_wpinv_type',
700
-					'orderby'  => 'meta_value'
701
-				)
702
-			);
703
-		}
704
-
705
-		// By vat class.
706
-		if ( 'vat_class' == $vars['orderby'] ) {
707
-			return array_merge(
708
-				$vars,
709
-				array(
710
-					'meta_key' => '_wpinv_vat_class',
711
-					'orderby'  => 'meta_value'
712
-				)
713
-			);
714
-		}
715
-
716
-		// By vat rule.
717
-		if ( 'vat_rule' == $vars['orderby'] ) {
718
-			return array_merge(
719
-				$vars,
720
-				array(
721
-					'meta_key' => '_wpinv_vat_rule',
722
-					'orderby'  => 'meta_value'
723
-				)
724
-			);
725
-		}
726
-
727
-		// By price.
728
-		if ( 'price' == $vars['orderby'] ) {
729
-			return array_merge(
730
-				$vars,
731
-				array(
732
-					'meta_key' => '_wpinv_price',
733
-					'orderby'  => 'meta_value_num'
734
-				)
735
-			);
736
-		}
737
-
738
-		return $vars;
739
-
740
-	}
741
-
742
-	/**
743
-	 * Fired when deleting a post.
744
-	 */
745
-	public static function delete_post( $post_id ) {
746
-
747
-		switch ( get_post_type( $post_id ) ) {
748
-
749
-			case 'wpi_item' :
750
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
751
-				break;
752
-
753
-			case 'wpi_payment_form' :
754
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
755
-				break;
756
-
757
-			case 'wpi_discount' :
758
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
759
-				break;
760
-
761
-			case 'wpi_invoice' :
762
-				$invoice = new WPInv_Invoice( $post_id );
763
-				do_action( "getpaid_before_delete_invoice", $invoice );
764
-				$invoice->get_data_store()->delete_items( $invoice );
765
-				$invoice->get_data_store()->delete_special_fields( $invoice );
766
-				break;
767
-		}
768
-	}
680
+        }
681
+
682
+    }
683
+
684
+    /**
685
+     * Reorders items.
686
+     */
687
+    public static function reorder_items( $vars ) {
688
+        global $typenow;
689
+
690
+        if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
691
+            return $vars;
692
+        }
693
+
694
+        // By item type.
695
+        if ( 'type' == $vars['orderby'] ) {
696
+            return array_merge(
697
+                $vars,
698
+                array(
699
+                    'meta_key' => '_wpinv_type',
700
+                    'orderby'  => 'meta_value'
701
+                )
702
+            );
703
+        }
704
+
705
+        // By vat class.
706
+        if ( 'vat_class' == $vars['orderby'] ) {
707
+            return array_merge(
708
+                $vars,
709
+                array(
710
+                    'meta_key' => '_wpinv_vat_class',
711
+                    'orderby'  => 'meta_value'
712
+                )
713
+            );
714
+        }
715
+
716
+        // By vat rule.
717
+        if ( 'vat_rule' == $vars['orderby'] ) {
718
+            return array_merge(
719
+                $vars,
720
+                array(
721
+                    'meta_key' => '_wpinv_vat_rule',
722
+                    'orderby'  => 'meta_value'
723
+                )
724
+            );
725
+        }
726
+
727
+        // By price.
728
+        if ( 'price' == $vars['orderby'] ) {
729
+            return array_merge(
730
+                $vars,
731
+                array(
732
+                    'meta_key' => '_wpinv_price',
733
+                    'orderby'  => 'meta_value_num'
734
+                )
735
+            );
736
+        }
737
+
738
+        return $vars;
739
+
740
+    }
741
+
742
+    /**
743
+     * Fired when deleting a post.
744
+     */
745
+    public static function delete_post( $post_id ) {
746
+
747
+        switch ( get_post_type( $post_id ) ) {
748
+
749
+            case 'wpi_item' :
750
+                do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
751
+                break;
752
+
753
+            case 'wpi_payment_form' :
754
+                do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
755
+                break;
756
+
757
+            case 'wpi_discount' :
758
+                do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
759
+                break;
760
+
761
+            case 'wpi_invoice' :
762
+                $invoice = new WPInv_Invoice( $post_id );
763
+                do_action( "getpaid_before_delete_invoice", $invoice );
764
+                $invoice->get_data_store()->delete_items( $invoice );
765
+                $invoice->get_data_store()->delete_special_fields( $invoice );
766
+                break;
767
+        }
768
+    }
769 769
 
770 770
 }
Please login to merge, or discard this patch.
includes/data/eu-states.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -9,31 +9,31 @@
 block discarded – undo
9 9
 defined( 'ABSPATH' ) || exit;
10 10
 
11 11
 return array(
12
-	'AT',
13
-	'BE',
14
-	'BG',
15
-	'HR',
16
-	'CY',
17
-	'CZ',
18
-	'DK',
19
-	'EE',
20
-	'FI',
21
-	'FR',
22
-	'DE',
23
-	'GR',
24
-	'HU',
25
-	'IE',
26
-	'IT',
27
-	'LV',
28
-	'LT',
29
-	'LU',
30
-	'MT',
31
-	'NL',
32
-	'PL',
33
-	'PT',
34
-	'RO',
35
-	'SK',
36
-	'SI',
37
-	'ES',
38
-	'SE'
12
+    'AT',
13
+    'BE',
14
+    'BG',
15
+    'HR',
16
+    'CY',
17
+    'CZ',
18
+    'DK',
19
+    'EE',
20
+    'FI',
21
+    'FR',
22
+    'DE',
23
+    'GR',
24
+    'HU',
25
+    'IE',
26
+    'IT',
27
+    'LV',
28
+    'LT',
29
+    'LU',
30
+    'MT',
31
+    'NL',
32
+    'PL',
33
+    'PT',
34
+    'RO',
35
+    'SK',
36
+    'SI',
37
+    'ES',
38
+    'SE'
39 39
 );
Please login to merge, or discard this patch.
includes/user-functions.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -34,11 +34,11 @@  discard block
 block discarded – undo
34 34
  */
35 35
 function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) {
36 36
 
37
-	if ( current_user_can( 'manage_options' ) ) {
38
-		return 'manage_options';
39
-	};
37
+    if ( current_user_can( 'manage_options' ) ) {
38
+        return 'manage_options';
39
+    };
40 40
 
41
-	return $capalibilty;
41
+    return $capalibilty;
42 42
 }
43 43
 
44 44
 /**
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
     // Prepare user values.
63 63
     $prefix = preg_replace( '/\s+/', '', $prefix );
64 64
     $prefix = empty( $prefix ) ? $email : $prefix;
65
-	$args   = array(
66
-		'user_login' => wpinv_generate_user_name( $prefix ),
67
-		'user_pass'  => wp_generate_password(),
68
-		'user_email' => $email,
65
+    $args   = array(
66
+        'user_login' => wpinv_generate_user_name( $prefix ),
67
+        'user_pass'  => wp_generate_password(),
68
+        'user_email' => $email,
69 69
         'role'       => 'subscriber',
70 70
     );
71 71
 
@@ -82,16 +82,16 @@  discard block
 block discarded – undo
82 82
 function wpinv_generate_user_name( $prefix = '' ) {
83 83
 
84 84
     // If prefix is an email, retrieve the part before the email.
85
-	$prefix = strtok( $prefix, '@' );
85
+    $prefix = strtok( $prefix, '@' );
86 86
     $prefix = trim( $prefix, '.' );
87 87
 
88
-	// Sanitize the username.
89
-	$prefix = sanitize_user( $prefix, true );
88
+    // Sanitize the username.
89
+    $prefix = sanitize_user( $prefix, true );
90 90
 
91
-	$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
92
-	if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) {
93
-		$prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 );
94
-	}
91
+    $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
92
+    if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) {
93
+        $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 );
94
+    }
95 95
 
96 96
     $username = $prefix;
97 97
     $postfix  = 2;
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 1 patch
Indentation   +777 added lines, -777 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,187 +10,187 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form_Submission {
11 11
 
12 12
     /**
13
-	 * Submission ID
14
-	 *
15
-	 * @var string
16
-	 */
17
-	public $id = null;
18
-
19
-	/**
20
-	 * The raw submission data.
21
-	 *
22
-	 * @var array
23
-	 */
24
-	protected $data = null;
25
-
26
-	/**
27
-	 * Submission totals
28
-	 *
29
-	 * @var array
30
-	 */
31
-	protected $totals = array(
32
-
33
-		'subtotal'      => array(
34
-			'initial'   => 0,
35
-			'recurring' => 0,
36
-		),
37
-
38
-		'discount'      => array(
39
-			'initial'   => 0,
40
-			'recurring' => 0,
41
-		),
42
-
43
-		'fees'          => array(
44
-			'initial'   => 0,
45
-			'recurring' => 0,
46
-		),
47
-
48
-		'taxes'         => array(
49
-			'initial'   => 0,
50
-			'recurring' => 0,
51
-		),
52
-
53
-	);
54
-
55
-	/**
56
-	 * Sets the associated payment form.
57
-	 *
58
-	 * @var GetPaid_Payment_Form
59
-	 */
13
+     * Submission ID
14
+     *
15
+     * @var string
16
+     */
17
+    public $id = null;
18
+
19
+    /**
20
+     * The raw submission data.
21
+     *
22
+     * @var array
23
+     */
24
+    protected $data = null;
25
+
26
+    /**
27
+     * Submission totals
28
+     *
29
+     * @var array
30
+     */
31
+    protected $totals = array(
32
+
33
+        'subtotal'      => array(
34
+            'initial'   => 0,
35
+            'recurring' => 0,
36
+        ),
37
+
38
+        'discount'      => array(
39
+            'initial'   => 0,
40
+            'recurring' => 0,
41
+        ),
42
+
43
+        'fees'          => array(
44
+            'initial'   => 0,
45
+            'recurring' => 0,
46
+        ),
47
+
48
+        'taxes'         => array(
49
+            'initial'   => 0,
50
+            'recurring' => 0,
51
+        ),
52
+
53
+    );
54
+
55
+    /**
56
+     * Sets the associated payment form.
57
+     *
58
+     * @var GetPaid_Payment_Form
59
+     */
60 60
     protected $payment_form = null;
61 61
 
62 62
     /**
63
-	 * The country for the submission.
64
-	 *
65
-	 * @var string
66
-	 */
67
-	public $country = null;
68
-
69
-    /**
70
-	 * The state for the submission.
71
-	 *
72
-	 * @since 1.0.19
73
-	 * @var string
74
-	 */
75
-	public $state = null;
76
-
77
-	/**
78
-	 * The invoice associated with the submission.
79
-	 *
80
-	 * @var WPInv_Invoice
81
-	 */
82
-	protected $invoice = null;
83
-
84
-	/**
85
-	 * The recurring item for the submission.
86
-	 *
87
-	 * @var int
88
-	 */
89
-	public $has_recurring = 0;
90
-
91
-	/**
92
-	 * An array of fees for the submission.
93
-	 *
94
-	 * @var array
95
-	 */
96
-	protected $fees = array();
97
-
98
-	/**
99
-	 * An array of discounts for the submission.
100
-	 *
101
-	 * @var array
102
-	 */
103
-	protected $discounts = array();
104
-
105
-	/**
106
-	 * An array of taxes for the submission.
107
-	 *
108
-	 * @var array
109
-	 */
110
-	protected $taxes = array();
111
-
112
-	/**
113
-	 * An array of items for the submission.
114
-	 *
115
-	 * @var GetPaid_Form_Item[]
116
-	 */
117
-	protected $items = array();
118
-
119
-	/**
120
-	 * The last error.
121
-	 *
122
-	 * @var string
123
-	 */
124
-	public $last_error = null;
125
-
126
-    /**
127
-	 * Class constructor.
128
-	 *
129
-	 */
130
-	public function __construct() {
131
-
132
-		// Set the state and country to the default state and country.
133
-		$this->country = wpinv_default_billing_country();
134
-		$this->state   = wpinv_get_default_state();
135
-
136
-		// Do we have an actual submission?
137
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
138
-			$this->load_data( $_POST );
139
-		}
140
-
141
-	}
142
-
143
-	/**
144
-	 * Loads submission data.
145
-	 *
146
-	 * @param array $data
147
-	 */
148
-	public function load_data( $data ) {
149
-
150
-		// Remove slashes from the submitted data...
151
-		$data       = wp_unslash( $data );
152
-
153
-		// Allow plugins to filter the data.
154
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
155
-
156
-		// Cache it...
157
-		$this->data = $data;
158
-
159
-		// Then generate a unique id from the data.
160
-		$this->id   = md5( wp_json_encode( $data ) );
161
-
162
-		// Finally, process the submission.
163
-		try {
164
-
165
-			// Each process is passed an instance of the class (with reference)
166
-			// and should throw an Exception whenever it encounters one.
167
-			$processors = apply_filters(
168
-				'getpaid_payment_form_submission_processors',
169
-				array(
170
-					array( $this, 'process_payment_form' ),
171
-					array( $this, 'process_invoice' ),
172
-					array( $this, 'process_fees' ),
173
-					array( $this, 'process_items' ),
174
-					array( $this, 'process_discount' ),
175
-					array( $this, 'process_taxes' ),
176
-				),
177
-				$this		
178
-			);
179
-
180
-			foreach ( $processors as $processor ) {
181
-				call_user_func_array( $processor, array( &$this ) );
182
-			}
183
-
184
-		} catch ( Exception $e ) {
185
-			$this->last_error = $e->getMessage();
186
-		}
187
-
188
-		// Fired when we are done processing a submission.
189
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
190
-
191
-	}
192
-
193
-	/*
63
+     * The country for the submission.
64
+     *
65
+     * @var string
66
+     */
67
+    public $country = null;
68
+
69
+    /**
70
+     * The state for the submission.
71
+     *
72
+     * @since 1.0.19
73
+     * @var string
74
+     */
75
+    public $state = null;
76
+
77
+    /**
78
+     * The invoice associated with the submission.
79
+     *
80
+     * @var WPInv_Invoice
81
+     */
82
+    protected $invoice = null;
83
+
84
+    /**
85
+     * The recurring item for the submission.
86
+     *
87
+     * @var int
88
+     */
89
+    public $has_recurring = 0;
90
+
91
+    /**
92
+     * An array of fees for the submission.
93
+     *
94
+     * @var array
95
+     */
96
+    protected $fees = array();
97
+
98
+    /**
99
+     * An array of discounts for the submission.
100
+     *
101
+     * @var array
102
+     */
103
+    protected $discounts = array();
104
+
105
+    /**
106
+     * An array of taxes for the submission.
107
+     *
108
+     * @var array
109
+     */
110
+    protected $taxes = array();
111
+
112
+    /**
113
+     * An array of items for the submission.
114
+     *
115
+     * @var GetPaid_Form_Item[]
116
+     */
117
+    protected $items = array();
118
+
119
+    /**
120
+     * The last error.
121
+     *
122
+     * @var string
123
+     */
124
+    public $last_error = null;
125
+
126
+    /**
127
+     * Class constructor.
128
+     *
129
+     */
130
+    public function __construct() {
131
+
132
+        // Set the state and country to the default state and country.
133
+        $this->country = wpinv_default_billing_country();
134
+        $this->state   = wpinv_get_default_state();
135
+
136
+        // Do we have an actual submission?
137
+        if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
138
+            $this->load_data( $_POST );
139
+        }
140
+
141
+    }
142
+
143
+    /**
144
+     * Loads submission data.
145
+     *
146
+     * @param array $data
147
+     */
148
+    public function load_data( $data ) {
149
+
150
+        // Remove slashes from the submitted data...
151
+        $data       = wp_unslash( $data );
152
+
153
+        // Allow plugins to filter the data.
154
+        $data       = apply_filters( 'getpaid_submission_data', $data, $this );
155
+
156
+        // Cache it...
157
+        $this->data = $data;
158
+
159
+        // Then generate a unique id from the data.
160
+        $this->id   = md5( wp_json_encode( $data ) );
161
+
162
+        // Finally, process the submission.
163
+        try {
164
+
165
+            // Each process is passed an instance of the class (with reference)
166
+            // and should throw an Exception whenever it encounters one.
167
+            $processors = apply_filters(
168
+                'getpaid_payment_form_submission_processors',
169
+                array(
170
+                    array( $this, 'process_payment_form' ),
171
+                    array( $this, 'process_invoice' ),
172
+                    array( $this, 'process_fees' ),
173
+                    array( $this, 'process_items' ),
174
+                    array( $this, 'process_discount' ),
175
+                    array( $this, 'process_taxes' ),
176
+                ),
177
+                $this		
178
+            );
179
+
180
+            foreach ( $processors as $processor ) {
181
+                call_user_func_array( $processor, array( &$this ) );
182
+            }
183
+
184
+        } catch ( Exception $e ) {
185
+            $this->last_error = $e->getMessage();
186
+        }
187
+
188
+        // Fired when we are done processing a submission.
189
+        do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
190
+
191
+    }
192
+
193
+    /*
194 194
 	|--------------------------------------------------------------------------
195 195
 	| Payment Forms.
196 196
 	|--------------------------------------------------------------------------
@@ -199,39 +199,39 @@  discard block
 block discarded – undo
199 199
 	| submission has an active payment form etc.
200 200
     */
201 201
 
202
-	/**
203
-	 * Prepares the submission's payment form.
204
-	 *
205
-	 * @since 1.0.19
206
-	 */
207
-	public function process_payment_form() {
202
+    /**
203
+     * Prepares the submission's payment form.
204
+     *
205
+     * @since 1.0.19
206
+     */
207
+    public function process_payment_form() {
208 208
 
209
-		// Every submission needs an active payment form.
210
-		if ( empty( $this->data['form_id'] ) ) {
211
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
212
-		}
209
+        // Every submission needs an active payment form.
210
+        if ( empty( $this->data['form_id'] ) ) {
211
+            throw new Exception( __( 'Missing payment form', 'invoicing' ) );
212
+        }
213 213
 
214
-		// Fetch the payment form.
215
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
214
+        // Fetch the payment form.
215
+        $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
216 216
 
217
-		if ( ! $this->payment_form->is_active() ) {
218
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
219
-		}
217
+        if ( ! $this->payment_form->is_active() ) {
218
+            throw new Exception( __( 'Payment form not active', 'invoicing' ) );
219
+        }
220 220
 
221
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
222
-	}
221
+        do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
222
+    }
223 223
 
224 224
     /**
225
-	 * Returns the payment form.
226
-	 *
227
-	 * @since 1.0.19
228
-	 * @return GetPaid_Payment_Form
229
-	 */
230
-	public function get_payment_form() {
231
-		return $this->payment_form;
232
-	}
225
+     * Returns the payment form.
226
+     *
227
+     * @since 1.0.19
228
+     * @return GetPaid_Payment_Form
229
+     */
230
+    public function get_payment_form() {
231
+        return $this->payment_form;
232
+    }
233 233
 
234
-	/*
234
+    /*
235 235
 	|--------------------------------------------------------------------------
236 236
 	| Invoices.
237 237
 	|--------------------------------------------------------------------------
@@ -240,61 +240,61 @@  discard block
 block discarded – undo
240 240
 	| might be for an existing invoice.
241 241
 	*/
242 242
 
243
-	/**
244
-	 * Prepares the submission's invoice.
245
-	 *
246
-	 * @since 1.0.19
247
-	 */
248
-	public function process_invoice() {
243
+    /**
244
+     * Prepares the submission's invoice.
245
+     *
246
+     * @since 1.0.19
247
+     */
248
+    public function process_invoice() {
249 249
 
250
-		// Abort if there is no invoice.
251
-		if ( empty( $this->data['invoice_id'] ) ) {
252
-			return;
253
-		}
250
+        // Abort if there is no invoice.
251
+        if ( empty( $this->data['invoice_id'] ) ) {
252
+            return;
253
+        }
254 254
 
255
-		// If the submission is for an existing invoice, ensure that it exists
256
-		// and that it is not paid for.
257
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
255
+        // If the submission is for an existing invoice, ensure that it exists
256
+        // and that it is not paid for.
257
+        $invoice = wpinv_get_invoice( $this->data['invoice_id'] );
258 258
 
259 259
         if ( empty( $invoice ) ) {
260
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
261
-		}
262
-
263
-		if ( $invoice->is_paid() ) {
264
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
265
-		}
266
-
267
-		$this->payment_form->set_items( $invoice->get_items() );
268
-		$this->payment_form->invoice = $invoice;
269
-
270
-		$this->country = $invoice->get_country();
271
-		$this->state   = $invoice->get_state();
272
-		$this->invoice = $invoice;
273
-
274
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
275
-	}
276
-
277
-	/**
278
-	 * Returns the associated invoice.
279
-	 *
280
-	 * @since 1.0.19
281
-	 * @return WPInv_Invoice
282
-	 */
283
-	public function get_invoice() {
284
-		return $this->invoice;
285
-	}
286
-
287
-	/**
288
-	 * Checks whether there is an invoice associated with this submission.
289
-	 *
290
-	 * @since 1.0.19
291
-	 * @return bool
292
-	 */
293
-	public function has_invoice() {
294
-		return ! empty( $this->invoice );
295
-	}
296
-
297
-	/*
260
+            throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
261
+        }
262
+
263
+        if ( $invoice->is_paid() ) {
264
+            throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
265
+        }
266
+
267
+        $this->payment_form->set_items( $invoice->get_items() );
268
+        $this->payment_form->invoice = $invoice;
269
+
270
+        $this->country = $invoice->get_country();
271
+        $this->state   = $invoice->get_state();
272
+        $this->invoice = $invoice;
273
+
274
+        do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
275
+    }
276
+
277
+    /**
278
+     * Returns the associated invoice.
279
+     *
280
+     * @since 1.0.19
281
+     * @return WPInv_Invoice
282
+     */
283
+    public function get_invoice() {
284
+        return $this->invoice;
285
+    }
286
+
287
+    /**
288
+     * Checks whether there is an invoice associated with this submission.
289
+     *
290
+     * @since 1.0.19
291
+     * @return bool
292
+     */
293
+    public function has_invoice() {
294
+        return ! empty( $this->invoice );
295
+    }
296
+
297
+    /*
298 298
 	|--------------------------------------------------------------------------
299 299
 	| Items.
300 300
 	|--------------------------------------------------------------------------
@@ -303,115 +303,115 @@  discard block
 block discarded – undo
303 303
 	| recurring item. But can have an unlimited number of non-recurring items.
304 304
 	*/
305 305
 
306
-	/**
307
-	 * Prepares the submission's items.
308
-	 *
309
-	 * @since 1.0.19
310
-	 */
311
-	public function process_items() {
312
-
313
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
314
-
315
-		foreach ( $processor->items as $item ) {
316
-			$this->add_item( $item );
317
-		}
318
-
319
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
320
-	}
321
-
322
-	/**
323
-	 * Adds an item to the submission.
324
-	 *
325
-	 * @since 1.0.19
326
-	 * @param GetPaid_Form_Item $item
327
-	 */
328
-	public function add_item( $item ) {
329
-
330
-		// Make sure that it is available for purchase.
331
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
332
-			return;
333
-		}
334
-
335
-		// Each submission can only contain one recurring item.
336
-		if ( $item->is_recurring() ) {
337
-
338
-			if ( $this->has_recurring != 0 ) {
339
-				throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
340
-			}
341
-
342
-			$this->has_recurring = $item->get_id();
343
-
344
-		}
345
-
346
-		// Update the items and totals.
347
-		$this->items[ $item->get_id() ]         = $item;
348
-		$this->totals['subtotal']['initial']   += $item->get_sub_total();
349
-		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
350
-
351
-	}
352
-
353
-	/**
354
-	 * Removes a specific item.
355
-	 * 
356
-	 * You should not call this method after the discounts and taxes
357
-	 * have been calculated.
358
-	 *
359
-	 * @since 1.0.19
360
-	 */
361
-	public function remove_item( $item_id ) {
362
-
363
-		if ( isset( $this->items[ $item_id ] ) ) {
364
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
365
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
366
-
367
-			if ( $this->items[ $item_id ]->is_recurring() ) {
368
-				$this->has_recurring = 0;
369
-			}
370
-
371
-			unset( $this->items[ $item_id ] );
372
-		}
373
-
374
-	}
375
-
376
-	/**
377
-	 * Returns the subtotal.
378
-	 *
379
-	 * @since 1.0.19
380
-	 */
381
-	public function get_subtotal() {
382
-
383
-		if ( wpinv_prices_include_tax() ) {
384
-			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
385
-		}
386
-
387
-		return $this->totals['subtotal']['initial'];
388
-	}
389
-
390
-	/**
391
-	 * Returns the recurring subtotal.
392
-	 *
393
-	 * @since 1.0.19
394
-	 */
395
-	public function get_recurring_subtotal() {
396
-
397
-		if ( wpinv_prices_include_tax() ) {
398
-			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
399
-		}
400
-
401
-		return $this->totals['subtotal']['recurring'];
402
-	}
403
-
404
-	/**
405
-	 * Returns all items.
406
-	 *
407
-	 * @since 1.0.19
408
-	 * @return GetPaid_Form_Item[]
409
-	 */
410
-	public function get_items() {
411
-		return $this->items;
412
-	}
413
-
414
-	/*
306
+    /**
307
+     * Prepares the submission's items.
308
+     *
309
+     * @since 1.0.19
310
+     */
311
+    public function process_items() {
312
+
313
+        $processor = new GetPaid_Payment_Form_Submission_Items( $this );
314
+
315
+        foreach ( $processor->items as $item ) {
316
+            $this->add_item( $item );
317
+        }
318
+
319
+        do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
320
+    }
321
+
322
+    /**
323
+     * Adds an item to the submission.
324
+     *
325
+     * @since 1.0.19
326
+     * @param GetPaid_Form_Item $item
327
+     */
328
+    public function add_item( $item ) {
329
+
330
+        // Make sure that it is available for purchase.
331
+        if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
332
+            return;
333
+        }
334
+
335
+        // Each submission can only contain one recurring item.
336
+        if ( $item->is_recurring() ) {
337
+
338
+            if ( $this->has_recurring != 0 ) {
339
+                throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
340
+            }
341
+
342
+            $this->has_recurring = $item->get_id();
343
+
344
+        }
345
+
346
+        // Update the items and totals.
347
+        $this->items[ $item->get_id() ]         = $item;
348
+        $this->totals['subtotal']['initial']   += $item->get_sub_total();
349
+        $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
350
+
351
+    }
352
+
353
+    /**
354
+     * Removes a specific item.
355
+     * 
356
+     * You should not call this method after the discounts and taxes
357
+     * have been calculated.
358
+     *
359
+     * @since 1.0.19
360
+     */
361
+    public function remove_item( $item_id ) {
362
+
363
+        if ( isset( $this->items[ $item_id ] ) ) {
364
+            $this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
365
+            $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
366
+
367
+            if ( $this->items[ $item_id ]->is_recurring() ) {
368
+                $this->has_recurring = 0;
369
+            }
370
+
371
+            unset( $this->items[ $item_id ] );
372
+        }
373
+
374
+    }
375
+
376
+    /**
377
+     * Returns the subtotal.
378
+     *
379
+     * @since 1.0.19
380
+     */
381
+    public function get_subtotal() {
382
+
383
+        if ( wpinv_prices_include_tax() ) {
384
+            return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
385
+        }
386
+
387
+        return $this->totals['subtotal']['initial'];
388
+    }
389
+
390
+    /**
391
+     * Returns the recurring subtotal.
392
+     *
393
+     * @since 1.0.19
394
+     */
395
+    public function get_recurring_subtotal() {
396
+
397
+        if ( wpinv_prices_include_tax() ) {
398
+            return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
399
+        }
400
+
401
+        return $this->totals['subtotal']['recurring'];
402
+    }
403
+
404
+    /**
405
+     * Returns all items.
406
+     *
407
+     * @since 1.0.19
408
+     * @return GetPaid_Form_Item[]
409
+     */
410
+    public function get_items() {
411
+        return $this->items;
412
+    }
413
+
414
+    /*
415 415
 	|--------------------------------------------------------------------------
416 416
 	| Taxes
417 417
 	|--------------------------------------------------------------------------
@@ -420,128 +420,128 @@  discard block
 block discarded – undo
420 420
 	| or only one-time.
421 421
     */
422 422
 
423
-	/**
424
-	 * Prepares the submission's taxes.
425
-	 *
426
-	 * @since 1.0.19
427
-	 */
428
-	public function process_taxes() {
429
-
430
-		// Abort if we're not using taxes.
431
-		if ( ! $this->use_taxes() ) {
432
-			return;
433
-		}
434
-
435
-		// If a custom country && state has been passed in, use it to calculate taxes.
436
-		$country = $this->get_field( 'wpinv_country', 'billing' );
437
-		if ( ! empty( $country ) ) {
438
-			$this->country = $country;
439
-		}
440
-
441
-		$state = $this->get_field( 'wpinv_state', 'billing' );
442
-		if ( ! empty( $state ) ) {
443
-			$this->state = $state;
444
-		}
445
-
446
-		// Confirm if the provided country and the ip country are similar.
447
-		$address_confirmed = $this->get_field( 'confirm-address' );
448
-		if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
449
-			throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
450
-		}
451
-
452
-		// Abort if the country is not taxable.
453
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
454
-			return;
455
-		}
456
-
457
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
458
-
459
-		foreach ( $processor->taxes as $tax ) {
460
-			$this->add_tax( $tax );
461
-		}
462
-
463
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
464
-	}
465
-
466
-	/**
467
-	 * Adds a tax to the submission.
468
-	 *
469
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
470
-	 * @since 1.0.19
471
-	 */
472
-	public function add_tax( $tax ) {
473
-
474
-		if ( wpinv_round_tax_per_tax_rate() ) {
475
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
476
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
477
-		}
478
-
479
-		$this->taxes[ $tax['name'] ]         = $tax;
480
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
481
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
482
-
483
-	}
484
-
485
-	/**
486
-	 * Removes a specific tax.
487
-	 *
488
-	 * @since 1.0.19
489
-	 */
490
-	public function remove_tax( $tax_name ) {
491
-
492
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
493
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
494
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
495
-			unset( $this->taxes[ $tax_name ] );
496
-		}
497
-
498
-	}
499
-
500
-	/**
501
-	 * Whether or not we'll use taxes for the submission.
502
-	 *
503
-	 * @since 1.0.19
504
-	 */
505
-	public function use_taxes() {
506
-
507
-		$use_taxes = wpinv_use_taxes();
508
-
509
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
510
-			$use_taxes = false;
511
-		}
512
-
513
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
514
-
515
-	}
516
-
517
-	/**
518
-	 * Returns the tax.
519
-	 *
520
-	 * @since 1.0.19
521
-	 */
522
-	public function get_tax() {
523
-		return $this->totals['taxes']['initial'];
524
-	}
525
-
526
-	/**
527
-	 * Returns the recurring tax.
528
-	 *
529
-	 * @since 1.0.19
530
-	 */
531
-	public function get_recurring_tax() {
532
-		return $this->totals['taxes']['recurring'];
533
-	}
534
-
535
-	/**
536
-	 * Returns all taxes.
537
-	 *
538
-	 * @since 1.0.19
539
-	 */
540
-	public function get_taxes() {
541
-		return $this->taxes;
542
-	}
543
-
544
-	/*
423
+    /**
424
+     * Prepares the submission's taxes.
425
+     *
426
+     * @since 1.0.19
427
+     */
428
+    public function process_taxes() {
429
+
430
+        // Abort if we're not using taxes.
431
+        if ( ! $this->use_taxes() ) {
432
+            return;
433
+        }
434
+
435
+        // If a custom country && state has been passed in, use it to calculate taxes.
436
+        $country = $this->get_field( 'wpinv_country', 'billing' );
437
+        if ( ! empty( $country ) ) {
438
+            $this->country = $country;
439
+        }
440
+
441
+        $state = $this->get_field( 'wpinv_state', 'billing' );
442
+        if ( ! empty( $state ) ) {
443
+            $this->state = $state;
444
+        }
445
+
446
+        // Confirm if the provided country and the ip country are similar.
447
+        $address_confirmed = $this->get_field( 'confirm-address' );
448
+        if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
449
+            throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
450
+        }
451
+
452
+        // Abort if the country is not taxable.
453
+        if ( ! wpinv_is_country_taxable( $this->country ) ) {
454
+            return;
455
+        }
456
+
457
+        $processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
458
+
459
+        foreach ( $processor->taxes as $tax ) {
460
+            $this->add_tax( $tax );
461
+        }
462
+
463
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
464
+    }
465
+
466
+    /**
467
+     * Adds a tax to the submission.
468
+     *
469
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
470
+     * @since 1.0.19
471
+     */
472
+    public function add_tax( $tax ) {
473
+
474
+        if ( wpinv_round_tax_per_tax_rate() ) {
475
+            $tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
476
+            $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
477
+        }
478
+
479
+        $this->taxes[ $tax['name'] ]         = $tax;
480
+        $this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
481
+        $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
482
+
483
+    }
484
+
485
+    /**
486
+     * Removes a specific tax.
487
+     *
488
+     * @since 1.0.19
489
+     */
490
+    public function remove_tax( $tax_name ) {
491
+
492
+        if ( isset( $this->taxes[ $tax_name ] ) ) {
493
+            $this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
494
+            $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
495
+            unset( $this->taxes[ $tax_name ] );
496
+        }
497
+
498
+    }
499
+
500
+    /**
501
+     * Whether or not we'll use taxes for the submission.
502
+     *
503
+     * @since 1.0.19
504
+     */
505
+    public function use_taxes() {
506
+
507
+        $use_taxes = wpinv_use_taxes();
508
+
509
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
510
+            $use_taxes = false;
511
+        }
512
+
513
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
514
+
515
+    }
516
+
517
+    /**
518
+     * Returns the tax.
519
+     *
520
+     * @since 1.0.19
521
+     */
522
+    public function get_tax() {
523
+        return $this->totals['taxes']['initial'];
524
+    }
525
+
526
+    /**
527
+     * Returns the recurring tax.
528
+     *
529
+     * @since 1.0.19
530
+     */
531
+    public function get_recurring_tax() {
532
+        return $this->totals['taxes']['recurring'];
533
+    }
534
+
535
+    /**
536
+     * Returns all taxes.
537
+     *
538
+     * @since 1.0.19
539
+     */
540
+    public function get_taxes() {
541
+        return $this->taxes;
542
+    }
543
+
544
+    /*
545 545
 	|--------------------------------------------------------------------------
546 546
 	| Discounts
547 547
 	|--------------------------------------------------------------------------
@@ -550,99 +550,99 @@  discard block
 block discarded – undo
550 550
 	| or only one-time. They also do not have to come from a discount code.
551 551
     */
552 552
 
553
-	/**
554
-	 * Prepares the submission's discount.
555
-	 *
556
-	 * @since 1.0.19
557
-	 */
558
-	public function process_discount() {
559
-
560
-		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
561
-		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
562
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
563
-
564
-		foreach ( $processor->discounts as $discount ) {
565
-			$this->add_discount( $discount );
566
-		}
567
-
568
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
569
-	}
570
-
571
-	/**
572
-	 * Adds a discount to the submission.
573
-	 *
574
-	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
575
-	 * @since 1.0.19
576
-	 */
577
-	public function add_discount( $discount ) {
578
-		$this->discounts[ $discount['name'] ]   = $discount;
579
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
580
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
581
-	}
582
-
583
-	/**
584
-	 * Removes a discount from the submission.
585
-	 *
586
-	 * @since 1.0.19
587
-	 */
588
-	public function remove_discount( $name ) {
589
-
590
-		if ( isset( $this->discounts[ $name ] ) ) {
591
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
592
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
593
-			unset( $this->discounts[ $name ] );
594
-		}
595
-
596
-	}
597
-
598
-	/**
599
-	 * Checks whether there is a discount code associated with this submission.
600
-	 *
601
-	 * @since 1.0.19
602
-	 * @return bool
603
-	 */
604
-	public function has_discount_code() {
605
-		return ! empty( $this->discounts['discount_code'] );
606
-	}
607
-
608
-	/**
609
-	 * Returns the discount code.
610
-	 *
611
-	 * @since 1.0.19
612
-	 * @return string
613
-	 */
614
-	public function get_discount_code() {
615
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
616
-	}
617
-
618
-	/**
619
-	 * Returns the discount.
620
-	 *
621
-	 * @since 1.0.19
622
-	 */
623
-	public function get_discount() {
624
-		return $this->totals['discount']['initial'];
625
-	}
626
-
627
-	/**
628
-	 * Returns the recurring discount.
629
-	 *
630
-	 * @since 1.0.19
631
-	 */
632
-	public function get_recurring_discount() {
633
-		return $this->totals['discount']['recurring'];
634
-	}
635
-
636
-	/**
637
-	 * Returns all discounts.
638
-	 *
639
-	 * @since 1.0.19
640
-	 */
641
-	public function get_discounts() {
642
-		return $this->discounts;
643
-	}
644
-
645
-	/*
553
+    /**
554
+     * Prepares the submission's discount.
555
+     *
556
+     * @since 1.0.19
557
+     */
558
+    public function process_discount() {
559
+
560
+        $initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
561
+        $recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
562
+        $processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
563
+
564
+        foreach ( $processor->discounts as $discount ) {
565
+            $this->add_discount( $discount );
566
+        }
567
+
568
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
569
+    }
570
+
571
+    /**
572
+     * Adds a discount to the submission.
573
+     *
574
+     * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
575
+     * @since 1.0.19
576
+     */
577
+    public function add_discount( $discount ) {
578
+        $this->discounts[ $discount['name'] ]   = $discount;
579
+        $this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
580
+        $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
581
+    }
582
+
583
+    /**
584
+     * Removes a discount from the submission.
585
+     *
586
+     * @since 1.0.19
587
+     */
588
+    public function remove_discount( $name ) {
589
+
590
+        if ( isset( $this->discounts[ $name ] ) ) {
591
+            $this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
592
+            $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
593
+            unset( $this->discounts[ $name ] );
594
+        }
595
+
596
+    }
597
+
598
+    /**
599
+     * Checks whether there is a discount code associated with this submission.
600
+     *
601
+     * @since 1.0.19
602
+     * @return bool
603
+     */
604
+    public function has_discount_code() {
605
+        return ! empty( $this->discounts['discount_code'] );
606
+    }
607
+
608
+    /**
609
+     * Returns the discount code.
610
+     *
611
+     * @since 1.0.19
612
+     * @return string
613
+     */
614
+    public function get_discount_code() {
615
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
616
+    }
617
+
618
+    /**
619
+     * Returns the discount.
620
+     *
621
+     * @since 1.0.19
622
+     */
623
+    public function get_discount() {
624
+        return $this->totals['discount']['initial'];
625
+    }
626
+
627
+    /**
628
+     * Returns the recurring discount.
629
+     *
630
+     * @since 1.0.19
631
+     */
632
+    public function get_recurring_discount() {
633
+        return $this->totals['discount']['recurring'];
634
+    }
635
+
636
+    /**
637
+     * Returns all discounts.
638
+     *
639
+     * @since 1.0.19
640
+     */
641
+    public function get_discounts() {
642
+        return $this->discounts;
643
+    }
644
+
645
+    /*
646 646
 	|--------------------------------------------------------------------------
647 647
 	| Fees
648 648
 	|--------------------------------------------------------------------------
@@ -652,89 +652,89 @@  discard block
 block discarded – undo
652 652
 	| fees.
653 653
     */
654 654
 
655
-	/**
656
-	 * Prepares the submission's fees.
657
-	 *
658
-	 * @since 1.0.19
659
-	 */
660
-	public function process_fees() {
661
-
662
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
663
-
664
-		foreach ( $fees_processor->fees as $fee ) {
665
-			$this->add_fee( $fee );
666
-		}
667
-
668
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
669
-	}
670
-
671
-	/**
672
-	 * Adds a fee to the submission.
673
-	 *
674
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
675
-	 * @since 1.0.19
676
-	 */
677
-	public function add_fee( $fee ) {
678
-
679
-		$this->fees[ $fee['name'] ]         = $fee;
680
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
681
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
682
-
683
-	}
684
-
685
-	/**
686
-	 * Removes a fee from the submission.
687
-	 *
688
-	 * @since 1.0.19
689
-	 */
690
-	public function remove_fee( $name ) {
691
-
692
-		if ( isset( $this->fees[ $name ] ) ) {
693
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
694
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
695
-			unset( $this->fees[ $name ] );
696
-		}
697
-
698
-	}
699
-
700
-	/**
701
-	 * Returns the fees.
702
-	 *
703
-	 * @since 1.0.19
704
-	 */
705
-	public function get_fee() {
706
-		return $this->totals['fees']['initial'];
707
-	}
708
-
709
-	/**
710
-	 * Returns the recurring fees.
711
-	 *
712
-	 * @since 1.0.19
713
-	 */
714
-	public function get_recurring_fee() {
715
-		return $this->totals['fees']['recurring'];
716
-	}
717
-
718
-	/**
719
-	 * Returns all fees.
720
-	 *
721
-	 * @since 1.0.19
722
-	 */
723
-	public function get_fees() {
724
-		return $this->fees;
725
-	}
726
-
727
-	/**
728
-	 * Checks if there are any fees for the form.
729
-	 *
730
-	 * @return bool
731
-	 * @since 1.0.19
732
-	 */
733
-	public function has_fees() {
734
-		return count( $this->fees ) !== 0;
735
-	}
736
-
737
-	/*
655
+    /**
656
+     * Prepares the submission's fees.
657
+     *
658
+     * @since 1.0.19
659
+     */
660
+    public function process_fees() {
661
+
662
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
663
+
664
+        foreach ( $fees_processor->fees as $fee ) {
665
+            $this->add_fee( $fee );
666
+        }
667
+
668
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
669
+    }
670
+
671
+    /**
672
+     * Adds a fee to the submission.
673
+     *
674
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
675
+     * @since 1.0.19
676
+     */
677
+    public function add_fee( $fee ) {
678
+
679
+        $this->fees[ $fee['name'] ]         = $fee;
680
+        $this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
681
+        $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
682
+
683
+    }
684
+
685
+    /**
686
+     * Removes a fee from the submission.
687
+     *
688
+     * @since 1.0.19
689
+     */
690
+    public function remove_fee( $name ) {
691
+
692
+        if ( isset( $this->fees[ $name ] ) ) {
693
+            $this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
694
+            $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
695
+            unset( $this->fees[ $name ] );
696
+        }
697
+
698
+    }
699
+
700
+    /**
701
+     * Returns the fees.
702
+     *
703
+     * @since 1.0.19
704
+     */
705
+    public function get_fee() {
706
+        return $this->totals['fees']['initial'];
707
+    }
708
+
709
+    /**
710
+     * Returns the recurring fees.
711
+     *
712
+     * @since 1.0.19
713
+     */
714
+    public function get_recurring_fee() {
715
+        return $this->totals['fees']['recurring'];
716
+    }
717
+
718
+    /**
719
+     * Returns all fees.
720
+     *
721
+     * @since 1.0.19
722
+     */
723
+    public function get_fees() {
724
+        return $this->fees;
725
+    }
726
+
727
+    /**
728
+     * Checks if there are any fees for the form.
729
+     *
730
+     * @return bool
731
+     * @since 1.0.19
732
+     */
733
+    public function has_fees() {
734
+        return count( $this->fees ) !== 0;
735
+    }
736
+
737
+    /*
738 738
 	|--------------------------------------------------------------------------
739 739
 	| MISC
740 740
 	|--------------------------------------------------------------------------
@@ -742,119 +742,119 @@  discard block
 block discarded – undo
742 742
 	| Extra submission functions.
743 743
     */
744 744
 
745
-	/**
746
-	 * Checks if this is the initial fetch.
747
-	 *
748
-	 * @return bool
749
-	 * @since 1.0.19
750
-	 */
751
-	public function is_initial_fetch() {
752
-		return empty( $this->data['initial_state'] );
753
-	}
754
-
755
-	/**
756
-	 * Returns the total amount to collect for this submission.
757
-	 *
758
-	 * @since 1.0.19
759
-	 */
760
-	public function get_total() {
761
-		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
762
-		return max( $total, 0 );
763
-	}
764
-
765
-	/**
766
-	 * Returns the recurring total amount to collect for this submission.
767
-	 *
768
-	 * @since 1.0.19
769
-	 */
770
-	public function get_recurring_total() {
771
-		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
772
-		return max( $total, 0 );
773
-	}
774
-
775
-	/**
776
-	 * Whether payment details should be collected for this submission.
777
-	 *
778
-	 * @since 1.0.19
779
-	 */
780
-	public function should_collect_payment_details() {
781
-		$initial   = $this->get_total();
782
-		$recurring = $this->get_recurring_total();
783
-
784
-		if ( $this->has_recurring == 0 ) {
785
-			$recurring = 0;
786
-		}
787
-
788
-		$collect = $initial > 0 || $recurring > 0;
789
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
790
-	}
791
-
792
-	/**
793
-	 * Returns the billing email of the user.
794
-	 *
795
-	 * @since 1.0.19
796
-	 */
797
-	public function get_billing_email() {
798
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
799
-	}
800
-
801
-	/**
802
-	 * Checks if the submitter has a billing email.
803
-	 *
804
-	 * @since 1.0.19
805
-	 */
806
-	public function has_billing_email() {
807
-		$billing_email = $this->get_billing_email();
808
-		return ! empty( $billing_email ) && is_email( $billing_email );
809
-	}
810
-
811
-	/**
812
-	 * Returns the appropriate currency for the submission.
813
-	 *
814
-	 * @since 1.0.19
815
-	 * @return string
816
-	 */
817
-	public function get_currency() {
818
-		return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
819
-    }
820
-
821
-    /**
822
-	 * Returns the raw submission data.
823
-	 *
824
-	 * @since 1.0.19
825
-	 * @return array
826
-	 */
827
-	public function get_data() {
828
-		return $this->data;
829
-	}
830
-
831
-	/**
832
-	 * Returns a field from the submission data
833
-	 *
834
-	 * @param string $field
835
-	 * @since 1.0.19
836
-	 * @return mixed|null
837
-	 */
838
-	public function get_field( $field, $sub_array_key = null ) {
839
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
840
-	}
841
-
842
-	/**
843
-	 * Checks if a required field is set.
844
-	 *
845
-	 * @since 1.0.19
846
-	 */
847
-	public function is_required_field_set( $field ) {
848
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
849
-	}
850
-
851
-	/**
852
-	 * Formats an amount
853
-	 *
854
-	 * @since 1.0.19
855
-	 */
856
-	public function format_amount( $amount ) {
857
-		return wpinv_price( $amount, $this->get_currency() );
858
-	}
745
+    /**
746
+     * Checks if this is the initial fetch.
747
+     *
748
+     * @return bool
749
+     * @since 1.0.19
750
+     */
751
+    public function is_initial_fetch() {
752
+        return empty( $this->data['initial_state'] );
753
+    }
754
+
755
+    /**
756
+     * Returns the total amount to collect for this submission.
757
+     *
758
+     * @since 1.0.19
759
+     */
760
+    public function get_total() {
761
+        $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
762
+        return max( $total, 0 );
763
+    }
764
+
765
+    /**
766
+     * Returns the recurring total amount to collect for this submission.
767
+     *
768
+     * @since 1.0.19
769
+     */
770
+    public function get_recurring_total() {
771
+        $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
772
+        return max( $total, 0 );
773
+    }
774
+
775
+    /**
776
+     * Whether payment details should be collected for this submission.
777
+     *
778
+     * @since 1.0.19
779
+     */
780
+    public function should_collect_payment_details() {
781
+        $initial   = $this->get_total();
782
+        $recurring = $this->get_recurring_total();
783
+
784
+        if ( $this->has_recurring == 0 ) {
785
+            $recurring = 0;
786
+        }
787
+
788
+        $collect = $initial > 0 || $recurring > 0;
789
+        return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
790
+    }
791
+
792
+    /**
793
+     * Returns the billing email of the user.
794
+     *
795
+     * @since 1.0.19
796
+     */
797
+    public function get_billing_email() {
798
+        return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
799
+    }
800
+
801
+    /**
802
+     * Checks if the submitter has a billing email.
803
+     *
804
+     * @since 1.0.19
805
+     */
806
+    public function has_billing_email() {
807
+        $billing_email = $this->get_billing_email();
808
+        return ! empty( $billing_email ) && is_email( $billing_email );
809
+    }
810
+
811
+    /**
812
+     * Returns the appropriate currency for the submission.
813
+     *
814
+     * @since 1.0.19
815
+     * @return string
816
+     */
817
+    public function get_currency() {
818
+        return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
819
+    }
820
+
821
+    /**
822
+     * Returns the raw submission data.
823
+     *
824
+     * @since 1.0.19
825
+     * @return array
826
+     */
827
+    public function get_data() {
828
+        return $this->data;
829
+    }
830
+
831
+    /**
832
+     * Returns a field from the submission data
833
+     *
834
+     * @param string $field
835
+     * @since 1.0.19
836
+     * @return mixed|null
837
+     */
838
+    public function get_field( $field, $sub_array_key = null ) {
839
+        return getpaid_get_array_field( $this->data, $field, $sub_array_key );
840
+    }
841
+
842
+    /**
843
+     * Checks if a required field is set.
844
+     *
845
+     * @since 1.0.19
846
+     */
847
+    public function is_required_field_set( $field ) {
848
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
849
+    }
850
+
851
+    /**
852
+     * Formats an amount
853
+     *
854
+     * @since 1.0.19
855
+     */
856
+    public function format_amount( $amount ) {
857
+        return wpinv_price( $amount, $this->get_currency() );
858
+    }
859 859
 
860 860
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-bank-transfer-gateway.php 1 patch
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -13,30 +13,30 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Bank_Transfer_Gateway extends GetPaid_Payment_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'bank_transfer';
21 21
 
22
-	/**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
27
-	protected $supports = array( 'addons' );
22
+    /**
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27
+    protected $supports = array( 'addons' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
34
-	public $order = 8;
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34
+    public $order = 8;
35 35
 
36 36
     /**
37
-	 * Class constructor.
38
-	 */
39
-	public function __construct() {
37
+     * Class constructor.
38
+     */
39
+    public function __construct() {
40 40
         parent::__construct();
41 41
 
42 42
         $this->title                = __( 'Direct bank transfer', 'invoicing' );
@@ -44,23 +44,23 @@  discard block
 block discarded – undo
44 44
         $this->checkout_button_text = __( 'Proceed', 'invoicing' );
45 45
         $this->instructions         = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) );
46 46
 
47
-		add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) );
48
-		add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 );
49
-		add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 );
50
-		add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 );
47
+        add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) );
48
+        add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 );
49
+        add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 );
50
+        add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 );
51 51
 
52 52
     }
53 53
 
54 54
     /**
55
-	 * Process Payment.
56
-	 *
57
-	 *
58
-	 * @param WPInv_Invoice $invoice Invoice.
59
-	 * @param array $submission_data Posted checkout fields.
60
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
61
-	 * @return array
62
-	 */
63
-	public function process_payment( $invoice, $submission_data, $submission ) {
55
+     * Process Payment.
56
+     *
57
+     *
58
+     * @param WPInv_Invoice $invoice Invoice.
59
+     * @param array $submission_data Posted checkout fields.
60
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
61
+     * @return array
62
+     */
63
+    public function process_payment( $invoice, $submission_data, $submission ) {
64 64
 
65 65
         // Add a transaction id.
66 66
         $invoice->set_transaction_id( $invoice->generate_key('trans_') );
@@ -81,66 +81,66 @@  discard block
 block discarded – undo
81 81
     }
82 82
 
83 83
     /**
84
-	 * Output for the order received page.
85
-	 *
86
-	 * @param WPInv_Invoice $invoice Invoice.
87
-	 */
88
-	public function thankyou_page( $invoice ) {
84
+     * Output for the order received page.
85
+     *
86
+     * @param WPInv_Invoice $invoice Invoice.
87
+     */
88
+    public function thankyou_page( $invoice ) {
89 89
 
90 90
         if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
91 91
 
92
-			echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL;
92
+            echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL;
93 93
 
94 94
             if ( ! empty( $this->instructions ) ) {
95 95
                 echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) );
96
-			}
96
+            }
97 97
 
98
-			$this->bank_details( $invoice );
98
+            $this->bank_details( $invoice );
99 99
 
100
-			echo '</div>';
100
+            echo '</div>';
101 101
 
102 102
         }
103 103
 
104
-	}
104
+    }
105 105
 
106 106
     /**
107
-	 * Add content to the WPI emails.
108
-	 *
109
-	 * @param WPInv_Invoice $invoice Invoice.
110
-	 * @param string     $email_type Email format: plain text or HTML.
111
-	 * @param bool     $sent_to_admin Sent to admin.
112
-	 */
113
-	public function email_instructions( $invoice, $email_type, $sent_to_admin ) {
107
+     * Add content to the WPI emails.
108
+     *
109
+     * @param WPInv_Invoice $invoice Invoice.
110
+     * @param string     $email_type Email format: plain text or HTML.
111
+     * @param bool     $sent_to_admin Sent to admin.
112
+     */
113
+    public function email_instructions( $invoice, $email_type, $sent_to_admin ) {
114 114
 
115
-		if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
115
+        if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
116 116
 
117
-			echo '<div class="wpi-email-row getpaid-bank-transfer-details">';
117
+            echo '<div class="wpi-email-row getpaid-bank-transfer-details">';
118 118
 
119
-			if ( $this->instructions ) {
120
-				echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
119
+            if ( $this->instructions ) {
120
+                echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
121 121
             }
122 122
 
123
-			$this->bank_details( $invoice );
123
+            $this->bank_details( $invoice );
124 124
 			
125
-			echo '</div>';
125
+            echo '</div>';
126 126
 
127
-		}
127
+        }
128 128
 
129 129
     }
130 130
     
131 131
     /**
132
-	 * Get bank details and place into a list format.
133
-	 *
134
-	 * @param WPInv_Invoice $invoice Invoice.
135
-	 */
136
-	protected function bank_details( $invoice ) {
132
+     * Get bank details and place into a list format.
133
+     *
134
+     * @param WPInv_Invoice $invoice Invoice.
135
+     */
136
+    protected function bank_details( $invoice ) {
137 137
 
138
-		// Get the invoice country and country $locale.
139
-		$country = $invoice->get_country();
140
-		$locale  = $this->get_country_locale();
138
+        // Get the invoice country and country $locale.
139
+        $country = $invoice->get_country();
140
+        $locale  = $this->get_country_locale();
141 141
 
142
-		// Get sortcode label in the $locale array and use appropriate one.
143
-		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
142
+        // Get sortcode label in the $locale array and use appropriate one.
143
+        $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
144 144
 
145 145
         $bank_fields = array(
146 146
             'ac_name'     => __( 'Account Name', 'invoicing' ),
@@ -169,144 +169,144 @@  discard block
 block discarded – undo
169 169
             return;
170 170
         }
171 171
 
172
-		echo '<h3 class="getpaid-bank-transfer-title"> ' . apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) . '</h3>' . PHP_EOL;
172
+        echo '<h3 class="getpaid-bank-transfer-title"> ' . apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) . '</h3>' . PHP_EOL;
173 173
 
174
-		echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL;
174
+        echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL;
175 175
 
176
-		foreach ( $bank_info as $key => $data ) {
176
+        foreach ( $bank_info as $key => $data ) {
177 177
 
178
-			$key   = sanitize_html_class( $key );
179
-			$label = wp_kses_post( $data['label'] );
180
-			$value = wp_kses_post( wptexturize( $data['value'] ) );
178
+            $key   = sanitize_html_class( $key );
179
+            $label = wp_kses_post( $data['label'] );
180
+            $value = wp_kses_post( wptexturize( $data['value'] ) );
181 181
 
182
-			echo "<tr class='getpaid-bank-transfer-$key'><th class='font-weight-bold'>$label</th><td class='w-75'>$value</td></tr>" . PHP_EOL;
183
-		}
182
+            echo "<tr class='getpaid-bank-transfer-$key'><th class='font-weight-bold'>$label</th><td class='w-75'>$value</td></tr>" . PHP_EOL;
183
+        }
184 184
 
185
-		echo '</table>';
185
+        echo '</table>';
186 186
 
187 187
     }
188 188
     
189 189
     /**
190
-	 * Get country locale if localized.
191
-	 *
192
-	 * @return array
193
-	 */
194
-	public function get_country_locale() {
195
-
196
-		if ( empty( $this->locale ) ) {
197
-
198
-			// Locale information to be used - only those that are not 'Sort Code'.
199
-			$this->locale = apply_filters(
200
-				'getpaid_get_bank_transfer_locale',
201
-				array(
202
-					'AU' => array(
203
-						'sortcode' => array(
204
-							'label' => __( 'BSB', 'invoicing' ),
205
-						),
206
-					),
207
-					'CA' => array(
208
-						'sortcode' => array(
209
-							'label' => __( 'Bank transit number', 'invoicing' ),
210
-						),
211
-					),
212
-					'IN' => array(
213
-						'sortcode' => array(
214
-							'label' => __( 'IFSC', 'invoicing' ),
215
-						),
216
-					),
217
-					'IT' => array(
218
-						'sortcode' => array(
219
-							'label' => __( 'Branch sort', 'invoicing' ),
220
-						),
221
-					),
222
-					'NZ' => array(
223
-						'sortcode' => array(
224
-							'label' => __( 'Bank code', 'invoicing' ),
225
-						),
226
-					),
227
-					'SE' => array(
228
-						'sortcode' => array(
229
-							'label' => __( 'Bank code', 'invoicing' ),
230
-						),
231
-					),
232
-					'US' => array(
233
-						'sortcode' => array(
234
-							'label' => __( 'Routing number', 'invoicing' ),
235
-						),
236
-					),
237
-					'ZA' => array(
238
-						'sortcode' => array(
239
-							'label' => __( 'Branch code', 'invoicing' ),
240
-						),
241
-					),
242
-				)
243
-			);
244
-
245
-		}
246
-
247
-		return $this->locale;
248
-
249
-	}
250
-
251
-	/**
252
-	 * Filters the gateway settings.
253
-	 * 
254
-	 * @param array $admin_settings
255
-	 */
256
-	public function admin_settings( $admin_settings ) {
190
+     * Get country locale if localized.
191
+     *
192
+     * @return array
193
+     */
194
+    public function get_country_locale() {
195
+
196
+        if ( empty( $this->locale ) ) {
197
+
198
+            // Locale information to be used - only those that are not 'Sort Code'.
199
+            $this->locale = apply_filters(
200
+                'getpaid_get_bank_transfer_locale',
201
+                array(
202
+                    'AU' => array(
203
+                        'sortcode' => array(
204
+                            'label' => __( 'BSB', 'invoicing' ),
205
+                        ),
206
+                    ),
207
+                    'CA' => array(
208
+                        'sortcode' => array(
209
+                            'label' => __( 'Bank transit number', 'invoicing' ),
210
+                        ),
211
+                    ),
212
+                    'IN' => array(
213
+                        'sortcode' => array(
214
+                            'label' => __( 'IFSC', 'invoicing' ),
215
+                        ),
216
+                    ),
217
+                    'IT' => array(
218
+                        'sortcode' => array(
219
+                            'label' => __( 'Branch sort', 'invoicing' ),
220
+                        ),
221
+                    ),
222
+                    'NZ' => array(
223
+                        'sortcode' => array(
224
+                            'label' => __( 'Bank code', 'invoicing' ),
225
+                        ),
226
+                    ),
227
+                    'SE' => array(
228
+                        'sortcode' => array(
229
+                            'label' => __( 'Bank code', 'invoicing' ),
230
+                        ),
231
+                    ),
232
+                    'US' => array(
233
+                        'sortcode' => array(
234
+                            'label' => __( 'Routing number', 'invoicing' ),
235
+                        ),
236
+                    ),
237
+                    'ZA' => array(
238
+                        'sortcode' => array(
239
+                            'label' => __( 'Branch code', 'invoicing' ),
240
+                        ),
241
+                    ),
242
+                )
243
+            );
244
+
245
+        }
246
+
247
+        return $this->locale;
248
+
249
+    }
250
+
251
+    /**
252
+     * Filters the gateway settings.
253
+     * 
254
+     * @param array $admin_settings
255
+     */
256
+    public function admin_settings( $admin_settings ) {
257 257
 
258 258
         $admin_settings['bank_transfer_desc']['std']    = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' );
259
-		$admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' );
259
+        $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' );
260 260
 
261
-		$locale  = $this->get_country_locale();
261
+        $locale  = $this->get_country_locale();
262 262
 
263
-		// Get sortcode label in the $locale array and use appropriate one.
264
-		$country  = wpinv_default_billing_country();
265
-		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
263
+        // Get sortcode label in the $locale array and use appropriate one.
264
+        $country  = wpinv_default_billing_country();
265
+        $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
266 266
 
267
-		$admin_settings['bank_transfer_ac_name'] = array(
267
+        $admin_settings['bank_transfer_ac_name'] = array(
268 268
             'type' => 'text',
269 269
             'id'   => 'bank_transfer_ac_name',
270 270
             'name' => __( 'Account Name', 'invoicing' ),
271
-		);
271
+        );
272 272
 		
273
-		$admin_settings['bank_transfer_ac_no'] = array(
273
+        $admin_settings['bank_transfer_ac_no'] = array(
274 274
             'type' => 'text',
275 275
             'id'   => 'bank_transfer_ac_no',
276 276
             'name' => __( 'Account Number', 'invoicing' ),
277
-		);
277
+        );
278 278
 		
279
-		$admin_settings['bank_transfer_bank_name'] = array(
279
+        $admin_settings['bank_transfer_bank_name'] = array(
280 280
             'type' => 'text',
281 281
             'id'   => 'bank_transfer_bank_name',
282 282
             'name' => __( 'Bank Name', 'invoicing' ),
283
-		);
283
+        );
284 284
 
285
-		$admin_settings['bank_transfer_ifsc'] = array(
285
+        $admin_settings['bank_transfer_ifsc'] = array(
286 286
             'type' => 'text',
287 287
             'id'   => 'bank_transfer_ifsc',
288 288
             'name' => __( 'IFSC Code', 'invoicing' ),
289
-		);
289
+        );
290 290
 
291
-		$admin_settings['bank_transfer_iban'] = array(
291
+        $admin_settings['bank_transfer_iban'] = array(
292 292
             'type' => 'text',
293 293
             'id'   => 'bank_transfer_iban',
294 294
             'name' => __( 'IBAN', 'invoicing' ),
295
-		);
295
+        );
296 296
 
297
-		$admin_settings['bank_transfer_bic'] = array(
297
+        $admin_settings['bank_transfer_bic'] = array(
298 298
             'type' => 'text',
299 299
             'id'   => 'bank_transfer_bic',
300 300
             'name' => __( 'BIC/Swift Code', 'invoicing' ),
301
-		);
301
+        );
302 302
 		
303
-		$admin_settings['bank_transfer_sort_code'] = array(
304
-			'type' => 'text',
305
-			'id'   => 'bank_transfer_sort_code',
306
-			'name' => $sortcode,
307
-		);
303
+        $admin_settings['bank_transfer_sort_code'] = array(
304
+            'type' => 'text',
305
+            'id'   => 'bank_transfer_sort_code',
306
+            'name' => $sortcode,
307
+        );
308 308
 
309
-		$admin_settings['bank_transfer_info'] = array(
309
+        $admin_settings['bank_transfer_info'] = array(
310 310
             'id'   => 'bank_transfer_info',
311 311
             'name' => __( 'Instructions', 'invoicing' ),
312 312
             'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
@@ -316,17 +316,17 @@  discard block
 block discarded – undo
316 316
             'rows' => 5
317 317
         );
318 318
 
319
-		return $admin_settings;
320
-	}
319
+        return $admin_settings;
320
+    }
321 321
 
322
-	/**
323
-	 * Processes invoice addons.
324
-	 *
325
-	 * @param WPInv_Invoice $invoice
326
-	 * @param GetPaid_Form_Item[] $items
327
-	 * @return WPInv_Invoice
328
-	 */
329
-	public function process_addons( $invoice, $items ) {
322
+    /**
323
+     * Processes invoice addons.
324
+     *
325
+     * @param WPInv_Invoice $invoice
326
+     * @param GetPaid_Form_Item[] $items
327
+     * @return WPInv_Invoice
328
+     */
329
+    public function process_addons( $invoice, $items ) {
330 330
 
331 331
         foreach ( $items as $item ) {
332 332
             $invoice->add_item( $item );
@@ -334,6 +334,6 @@  discard block
 block discarded – undo
334 334
 
335 335
         $invoice->recalculate_total();
336 336
         $invoice->save();
337
-	}
337
+    }
338 338
 
339 339
 }
Please login to merge, or discard this patch.
templates/payment-forms/cart-item.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -24,64 +24,64 @@  discard block
 block discarded – undo
24 24
 
25 25
 				<?php
26 26
 
27
-					// Fires before printing a line item column.
28
-					do_action( "getpaid_form_cart_item_before_$key", $item, $form );
27
+                    // Fires before printing a line item column.
28
+                    do_action( "getpaid_form_cart_item_before_$key", $item, $form );
29 29
 
30
-					// Item name.
31
-					if ( 'name' == $key ) {
30
+                    // Item name.
31
+                    if ( 'name' == $key ) {
32 32
 
33
-						// Display the name.
34
-						echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>';
33
+                        // Display the name.
34
+                        echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>';
35 35
 
36
-						// And an optional description.
36
+                        // And an optional description.
37 37
                         $description = $item->get_description();
38 38
 
39 39
                         if ( ! empty( $description ) ) {
40 40
                             $description = wp_kses_post( $description );
41 41
                             echo "<small class='form-text text-muted pr-2 m-0'>$description</small>";
42
-						}
42
+                        }
43 43
 
44
-						// Price help text.
44
+                        // Price help text.
45 45
                         $description = getpaid_item_recurring_price_help_text( $item, $currency );
46 46
                         if ( $description ) {
47 47
                             echo "<small class='getpaid-form-item-price-desc form-text text-muted pr-2 m-0'>$description</small>";
48
-						}
48
+                        }
49 49
 
50
-					}
50
+                    }
51 51
 
52
-					// Item price.
53
-					if ( 'price' == $key ) {
52
+                    // Item price.
53
+                    if ( 'price' == $key ) {
54 54
 
55
-						// Set the currency position.
56
-						$position = wpinv_currency_position();
55
+                        // Set the currency position.
56
+                        $position = wpinv_currency_position();
57 57
 
58
-						if ( $position == 'left_space' ) {
59
-							$position = 'left';
60
-						}
58
+                        if ( $position == 'left_space' ) {
59
+                            $position = 'left';
60
+                        }
61 61
 
62
-						if ( $position == 'right_space' ) {
63
-							$position = 'right';
64
-						}
62
+                        if ( $position == 'right_space' ) {
63
+                            $position = 'right';
64
+                        }
65 65
 
66
-						if ( $item->user_can_set_their_price() ) {
67
-							$price            = max( (float) $item->get_price(), (float) $item->get_minimum_price() );
68
-							$minimum          = (float) $item->get_minimum_price();
69
-							$validate_minimum = '';
70
-							$class            = '';
71
-							$data_minimum     = '';
66
+                        if ( $item->user_can_set_their_price() ) {
67
+                            $price            = max( (float) $item->get_price(), (float) $item->get_minimum_price() );
68
+                            $minimum          = (float) $item->get_minimum_price();
69
+                            $validate_minimum = '';
70
+                            $class            = '';
71
+                            $data_minimum     = '';
72 72
 
73
-							if ( $minimum > 0 ) {
74
-								$validate_minimum = sprintf(
75
-									esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ),
76
-									sanitize_text_field( wpinv_price( $minimum, $currency ) )
77
-								);
73
+                            if ( $minimum > 0 ) {
74
+                                $validate_minimum = sprintf(
75
+                                    esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ),
76
+                                    sanitize_text_field( wpinv_price( $minimum, $currency ) )
77
+                                );
78 78
 
79
-								$class = 'getpaid-validate-minimum-amount';
79
+                                $class = 'getpaid-validate-minimum-amount';
80 80
 
81
-								$data_minimum     = "data-minimum-amount='$minimum'";
82
-							}
81
+                                $data_minimum     = "data-minimum-amount='$minimum'";
82
+                            }
83 83
 
84
-							?>
84
+                            ?>
85 85
 								<div class="input-group input-group-sm">
86 86
 									<?php if( 'left' == $position ) : ?>
87 87
 										<div class="input-group-prepend">
@@ -105,37 +105,37 @@  discard block
 block discarded – undo
105 105
 								</div>
106 106
 
107 107
 							<?php
108
-						} else {
109
-							echo wpinv_price( $item->get_price(), $currency );
110
-							?>
108
+                        } else {
109
+                            echo wpinv_price( $item->get_price(), $currency );
110
+                            ?>
111 111
 								<input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'>
112 112
 							<?php
113
-						}
114
-					}
113
+                        }
114
+                    }
115 115
 
116
-					// Item quantity.
117
-					if ( 'quantity' == $key ) {
116
+                    // Item quantity.
117
+                    if ( 'quantity' == $key ) {
118 118
 
119
-						if ( $item->allows_quantities() ) {
120
-							?>
119
+                        if ( $item->allows_quantities() ) {
120
+                            ?>
121 121
 								<input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type='text' style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity(); ?>' min='1' required>
122 122
 							<?php
123
-						} else {
124
-							echo (float) $item->get_quantity();
125
-							echo '&nbsp;&nbsp;&nbsp;';
126
-							?>
123
+                        } else {
124
+                            echo (float) $item->get_quantity();
125
+                            echo '&nbsp;&nbsp;&nbsp;';
126
+                            ?>
127 127
 								<input type='hidden' name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' class='getpaid-item-quantity-input' value='<?php echo (float) $item->get_quantity(); ?>'>
128 128
 							<?php
129
-						}
130
-					}
129
+                        }
130
+                    }
131 131
 
132
-					// Item sub total.
133
-					if ( 'subtotal' == $key ) {
134
-						echo wpinv_price( $item->get_sub_total(), $currency );
135
-					}
132
+                    // Item sub total.
133
+                    if ( 'subtotal' == $key ) {
134
+                        echo wpinv_price( $item->get_sub_total(), $currency );
135
+                    }
136 136
 
137
-					do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
138
-				?>
137
+                    do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
138
+                ?>
139 139
 
140 140
 			</div>
141 141
 
Please login to merge, or discard this patch.
vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@
 block discarded – undo
7 7
  * Bail if we are not in WP.
8 8
  */
9 9
 if ( ! defined( 'ABSPATH' ) ) {
10
-	exit;
10
+    exit;
11 11
 }
12 12
 
13 13
 /**
14 14
  * Set the version only if its the current newest while loading.
15 15
  */
16 16
 add_action('after_setup_theme', function () {
17
-	global $ayecode_ui_version,$ayecode_ui_file_key;
18
-	$this_version = "0.1.43";
19
-	if(version_compare($this_version , $ayecode_ui_version, '>')){
20
-		$ayecode_ui_version = $this_version ;
21
-		$ayecode_ui_file_key = wp_hash( __FILE__ );
22
-	}
17
+    global $ayecode_ui_version,$ayecode_ui_file_key;
18
+    $this_version = "0.1.43";
19
+    if(version_compare($this_version , $ayecode_ui_version, '>')){
20
+        $ayecode_ui_version = $this_version ;
21
+        $ayecode_ui_file_key = wp_hash( __FILE__ );
22
+    }
23 23
 },0);
24 24
 
25 25
 /**
26 26
  * Load this version of WP Bootstrap Settings only if the file hash is the current one.
27 27
  */
28 28
 add_action('after_setup_theme', function () {
29
-	global $ayecode_ui_file_key;
30
-	if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){
31
-		include_once( dirname( __FILE__ ) . '/includes/class-aui.php' );
32
-		include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' );
33
-	}
29
+    global $ayecode_ui_file_key;
30
+    if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){
31
+        include_once( dirname( __FILE__ ) . '/includes/class-aui.php' );
32
+        include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' );
33
+    }
34 34
 },1);
35 35
 
36 36
 /**
37 37
  * Add the function that calls the class.
38 38
  */
39 39
 if(!function_exists('aui')){
40
-	function aui(){
41
-		if(!class_exists("AUI",false)){
42
-			return false;
43
-		}
44
-		return AUI::instance();
45
-	}
40
+    function aui(){
41
+        if(!class_exists("AUI",false)){
42
+            return false;
43
+        }
44
+        return AUI::instance();
45
+    }
46 46
 }
47 47
\ No newline at end of file
Please login to merge, or discard this patch.
vendor/ayecode/wp-ayecode-ui/includes/ayecode-ui-settings.php 1 patch
Indentation   +935 added lines, -935 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * Bail if we are not in WP.
14 14
  */
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -21,235 +21,235 @@  discard block
 block discarded – undo
21 21
  */
22 22
 if ( ! class_exists( 'AyeCode_UI_Settings' ) ) {
23 23
 
24
-	/**
25
-	 * A Class to be able to change settings for Font Awesome.
26
-	 *
27
-	 * Class AyeCode_UI_Settings
28
-	 * @ver 1.0.0
29
-	 * @todo decide how to implement textdomain
30
-	 */
31
-	class AyeCode_UI_Settings {
32
-
33
-		/**
34
-		 * Class version version.
35
-		 *
36
-		 * @var string
37
-		 */
38
-		public $version = '0.1.43';
39
-
40
-		/**
41
-		 * Class textdomain.
42
-		 *
43
-		 * @var string
44
-		 */
45
-		public $textdomain = 'aui';
46
-
47
-		/**
48
-		 * Latest version of Bootstrap at time of publish published.
49
-		 *
50
-		 * @var string
51
-		 */
52
-		public $latest = "4.5.3";
53
-
54
-		/**
55
-		 * Current version of select2 being used.
56
-		 *
57
-		 * @var string
58
-		 */
59
-		public $select2_version = "4.0.11";
60
-
61
-		/**
62
-		 * The title.
63
-		 *
64
-		 * @var string
65
-		 */
66
-		public $name = 'AyeCode UI';
67
-
68
-		/**
69
-		 * The relative url to the assets.
70
-		 *
71
-		 * @var string
72
-		 */
73
-		public $url = '';
74
-
75
-		/**
76
-		 * Holds the settings values.
77
-		 *
78
-		 * @var array
79
-		 */
80
-		private $settings;
81
-
82
-		/**
83
-		 * AyeCode_UI_Settings instance.
84
-		 *
85
-		 * @access private
86
-		 * @since  1.0.0
87
-		 * @var    AyeCode_UI_Settings There can be only one!
88
-		 */
89
-		private static $instance = null;
90
-
91
-		/**
92
-		 * Main AyeCode_UI_Settings Instance.
93
-		 *
94
-		 * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded.
95
-		 *
96
-		 * @since 1.0.0
97
-		 * @static
98
-		 * @return AyeCode_UI_Settings - Main instance.
99
-		 */
100
-		public static function instance() {
101
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) {
102
-
103
-				self::$instance = new AyeCode_UI_Settings;
104
-
105
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
106
-
107
-				if ( is_admin() ) {
108
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
109
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
110
-
111
-					// Maybe show example page
112
-					add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) );
113
-				}
24
+    /**
25
+     * A Class to be able to change settings for Font Awesome.
26
+     *
27
+     * Class AyeCode_UI_Settings
28
+     * @ver 1.0.0
29
+     * @todo decide how to implement textdomain
30
+     */
31
+    class AyeCode_UI_Settings {
32
+
33
+        /**
34
+         * Class version version.
35
+         *
36
+         * @var string
37
+         */
38
+        public $version = '0.1.43';
39
+
40
+        /**
41
+         * Class textdomain.
42
+         *
43
+         * @var string
44
+         */
45
+        public $textdomain = 'aui';
46
+
47
+        /**
48
+         * Latest version of Bootstrap at time of publish published.
49
+         *
50
+         * @var string
51
+         */
52
+        public $latest = "4.5.3";
53
+
54
+        /**
55
+         * Current version of select2 being used.
56
+         *
57
+         * @var string
58
+         */
59
+        public $select2_version = "4.0.11";
60
+
61
+        /**
62
+         * The title.
63
+         *
64
+         * @var string
65
+         */
66
+        public $name = 'AyeCode UI';
67
+
68
+        /**
69
+         * The relative url to the assets.
70
+         *
71
+         * @var string
72
+         */
73
+        public $url = '';
74
+
75
+        /**
76
+         * Holds the settings values.
77
+         *
78
+         * @var array
79
+         */
80
+        private $settings;
81
+
82
+        /**
83
+         * AyeCode_UI_Settings instance.
84
+         *
85
+         * @access private
86
+         * @since  1.0.0
87
+         * @var    AyeCode_UI_Settings There can be only one!
88
+         */
89
+        private static $instance = null;
90
+
91
+        /**
92
+         * Main AyeCode_UI_Settings Instance.
93
+         *
94
+         * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded.
95
+         *
96
+         * @since 1.0.0
97
+         * @static
98
+         * @return AyeCode_UI_Settings - Main instance.
99
+         */
100
+        public static function instance() {
101
+            if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) {
102
+
103
+                self::$instance = new AyeCode_UI_Settings;
104
+
105
+                add_action( 'init', array( self::$instance, 'init' ) ); // set settings
106
+
107
+                if ( is_admin() ) {
108
+                    add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
109
+                    add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
110
+
111
+                    // Maybe show example page
112
+                    add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) );
113
+                }
114 114
 
115
-				add_action( 'customize_register', array( self::$instance, 'customizer_settings' ));
116
-
117
-				do_action( 'ayecode_ui_settings_loaded' );
118
-			}
119
-
120
-			return self::$instance;
121
-		}
122
-
123
-		/**
124
-		 * Setup some constants.
125
-		 */
126
-		public function constants(){
127
-			define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be");
128
-			define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d');
129
-			if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL);
130
-			if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL);
131
-		}
132
-
133
-		/**
134
-		 * Initiate the settings and add the required action hooks.
135
-		 */
136
-		public function init() {
137
-			$this->constants();
138
-			$this->settings = $this->get_settings();
139
-			$this->url = $this->get_url();
140
-
141
-			/**
142
-			 * Maybe load CSS
143
-			 *
144
-			 * We load super early in case there is a theme version that might change the colors
145
-			 */
146
-			if ( $this->settings['css'] ) {
147
-				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
148
-			}
149
-			if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) {
150
-				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
151
-			}
152
-
153
-			// maybe load JS
154
-			if ( $this->settings['js'] ) {
155
-				$priority = $this->is_bs3_compat() ? 100 : 1;
156
-				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority );
157
-			}
158
-			if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) {
159
-				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
160
-			}
161
-
162
-			// Maybe set the HTML font size
163
-			if ( $this->settings['html_font_size'] ) {
164
-				add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 );
165
-			}
166
-
167
-
168
-		}
169
-
170
-		/**
171
-		 * Check if we should load the admin scripts or not.
172
-		 *
173
-		 * @return bool
174
-		 */
175
-		public function load_admin_scripts(){
176
-			$result = true;
177
-
178
-			// check if specifically disabled
179
-			if(!empty($this->settings['disable_admin'])){
180
-				$url_parts = explode("\n",$this->settings['disable_admin']);
181
-				foreach($url_parts as $part){
182
-					if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){
183
-						return false; // return early, no point checking further
184
-					}
185
-				}
186
-			}
187
-
188
-			return $result;
189
-		}
190
-
191
-		/**
192
-		 * Add a html font size to the footer.
193
-		 */
194
-		public function html_font_size(){
195
-			$this->settings = $this->get_settings();
196
-			echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>";
197
-		}
198
-
199
-		/**
200
-		 * Check if the current admin screen should load scripts.
201
-		 * 
202
-		 * @return bool
203
-		 */
204
-		public function is_aui_screen(){
205
-			$load = false;
206
-			// check if we should load or not
207
-			if ( is_admin() ) {
208
-				// Only enable on set pages
209
-				$aui_screens = array(
210
-					'page',
211
-					'post',
212
-					'settings_page_ayecode-ui-settings'
213
-				);
214
-				$screen_ids = apply_filters( 'aui_screen_ids', $aui_screens );
215
-
216
-				$screen = get_current_screen();
115
+                add_action( 'customize_register', array( self::$instance, 'customizer_settings' ));
116
+
117
+                do_action( 'ayecode_ui_settings_loaded' );
118
+            }
119
+
120
+            return self::$instance;
121
+        }
122
+
123
+        /**
124
+         * Setup some constants.
125
+         */
126
+        public function constants(){
127
+            define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be");
128
+            define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d');
129
+            if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL);
130
+            if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL);
131
+        }
132
+
133
+        /**
134
+         * Initiate the settings and add the required action hooks.
135
+         */
136
+        public function init() {
137
+            $this->constants();
138
+            $this->settings = $this->get_settings();
139
+            $this->url = $this->get_url();
140
+
141
+            /**
142
+             * Maybe load CSS
143
+             *
144
+             * We load super early in case there is a theme version that might change the colors
145
+             */
146
+            if ( $this->settings['css'] ) {
147
+                add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
148
+            }
149
+            if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) {
150
+                add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
151
+            }
152
+
153
+            // maybe load JS
154
+            if ( $this->settings['js'] ) {
155
+                $priority = $this->is_bs3_compat() ? 100 : 1;
156
+                add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority );
157
+            }
158
+            if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) {
159
+                add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
160
+            }
161
+
162
+            // Maybe set the HTML font size
163
+            if ( $this->settings['html_font_size'] ) {
164
+                add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 );
165
+            }
166
+
167
+
168
+        }
169
+
170
+        /**
171
+         * Check if we should load the admin scripts or not.
172
+         *
173
+         * @return bool
174
+         */
175
+        public function load_admin_scripts(){
176
+            $result = true;
177
+
178
+            // check if specifically disabled
179
+            if(!empty($this->settings['disable_admin'])){
180
+                $url_parts = explode("\n",$this->settings['disable_admin']);
181
+                foreach($url_parts as $part){
182
+                    if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){
183
+                        return false; // return early, no point checking further
184
+                    }
185
+                }
186
+            }
187
+
188
+            return $result;
189
+        }
190
+
191
+        /**
192
+         * Add a html font size to the footer.
193
+         */
194
+        public function html_font_size(){
195
+            $this->settings = $this->get_settings();
196
+            echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>";
197
+        }
198
+
199
+        /**
200
+         * Check if the current admin screen should load scripts.
201
+         * 
202
+         * @return bool
203
+         */
204
+        public function is_aui_screen(){
205
+            $load = false;
206
+            // check if we should load or not
207
+            if ( is_admin() ) {
208
+                // Only enable on set pages
209
+                $aui_screens = array(
210
+                    'page',
211
+                    'post',
212
+                    'settings_page_ayecode-ui-settings'
213
+                );
214
+                $screen_ids = apply_filters( 'aui_screen_ids', $aui_screens );
215
+
216
+                $screen = get_current_screen();
217 217
 
218 218
 //				echo '###'.$screen->id;
219 219
 				
220
-				if ( $screen && in_array( $screen->id, $screen_ids ) ) {
221
-					$load = true;
222
-				}
223
-			}
220
+                if ( $screen && in_array( $screen->id, $screen_ids ) ) {
221
+                    $load = true;
222
+                }
223
+            }
224 224
 
225
-			return $load;
226
-		}
225
+            return $load;
226
+        }
227 227
 
228
-		/**
229
-		 * Adds the styles.
230
-		 */
231
-		public function enqueue_style() {
228
+        /**
229
+         * Adds the styles.
230
+         */
231
+        public function enqueue_style() {
232 232
 
233
-			if( is_admin() && !$this->is_aui_screen()){
234
-				// don't add wp-admin scripts if not requested to
235
-			}else{
236
-				$css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend';
233
+            if( is_admin() && !$this->is_aui_screen()){
234
+                // don't add wp-admin scripts if not requested to
235
+            }else{
236
+                $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend';
237 237
 
238
-				$rtl = is_rtl() ? '-rtl' : '';
238
+                $rtl = is_rtl() ? '-rtl' : '';
239 239
 
240
-				if($this->settings[$css_setting]){
241
-					$compatibility = $this->settings[$css_setting]=='core' ? false : true;
242
-					$url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css';
243
-					wp_register_style( 'ayecode-ui', $url, array(), $this->latest );
244
-					wp_enqueue_style( 'ayecode-ui' );
240
+                if($this->settings[$css_setting]){
241
+                    $compatibility = $this->settings[$css_setting]=='core' ? false : true;
242
+                    $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css';
243
+                    wp_register_style( 'ayecode-ui', $url, array(), $this->latest );
244
+                    wp_enqueue_style( 'ayecode-ui' );
245 245
 
246
-					// flatpickr
247
-					wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest );
246
+                    // flatpickr
247
+                    wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest );
248 248
 
249 249
 
250
-					// fix some wp-admin issues
251
-					if(is_admin()){
252
-						$custom_css = "
250
+                    // fix some wp-admin issues
251
+                    if(is_admin()){
252
+                        $custom_css = "
253 253
                 body{
254 254
                     background-color: #f1f1f1;
255 255
                     font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif;
@@ -285,32 +285,32 @@  discard block
 block discarded – undo
285 285
 				}
286 286
                 ";
287 287
 
288
-						// @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377
289
-						$custom_css .= "
288
+                        // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377
289
+                        $custom_css .= "
290 290
 						.edit-post-sidebar input[type=color].components-text-control__input{
291 291
 						    padding: 0;
292 292
 						}
293 293
 					";
294
-						wp_add_inline_style( 'ayecode-ui', $custom_css );
295
-					}
294
+                        wp_add_inline_style( 'ayecode-ui', $custom_css );
295
+                    }
296 296
 
297
-					// custom changes
298
-					wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) );
297
+                    // custom changes
298
+                    wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) );
299 299
 
300
-				}
301
-			}
300
+                }
301
+            }
302 302
 
303 303
 
304
-		}
304
+        }
305 305
 
306
-		/**
307
-		 * Get inline script used if bootstrap enqueued
308
-		 *
309
-		 * If this remains small then its best to use this than to add another JS file.
310
-		 */
311
-		public function inline_script(){
312
-			ob_start();
313
-			?>
306
+        /**
307
+         * Get inline script used if bootstrap enqueued
308
+         *
309
+         * If this remains small then its best to use this than to add another JS file.
310
+         */
311
+        public function inline_script(){
312
+            ob_start();
313
+            ?>
314 314
 			<script>
315 315
 				
316 316
 				/**
@@ -802,27 +802,27 @@  discard block
 block discarded – undo
802 802
 
803 803
 			</script>
804 804
 			<?php
805
-			$output = ob_get_clean();
805
+            $output = ob_get_clean();
806 806
 
807
-			/*
807
+            /*
808 808
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
809 809
 			 */
810
-			return str_replace( array(
811
-				'<script>',
812
-				'</script>'
813
-			), '', $output );
814
-		}
815
-
816
-
817
-		/**
818
-		 * JS to help with conflict issues with other plugins and themes using bootstrap v3.
819
-		 *
820
-		 * @TODO we may need this when other conflicts arrise.
821
-		 * @return mixed
822
-		 */
823
-		public static function bs3_compat_js() {
824
-			ob_start();
825
-			?>
810
+            return str_replace( array(
811
+                '<script>',
812
+                '</script>'
813
+            ), '', $output );
814
+        }
815
+
816
+
817
+        /**
818
+         * JS to help with conflict issues with other plugins and themes using bootstrap v3.
819
+         *
820
+         * @TODO we may need this when other conflicts arrise.
821
+         * @return mixed
822
+         */
823
+        public static function bs3_compat_js() {
824
+            ob_start();
825
+            ?>
826 826
 			<script>
827 827
 				<?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?>
828 828
 				/* With Avada builder */
@@ -830,20 +830,20 @@  discard block
 block discarded – undo
830 830
 				<?php } ?>
831 831
 			</script>
832 832
 			<?php
833
-			return str_replace( array(
834
-				'<script>',
835
-				'</script>'
836
-			), '', ob_get_clean());
837
-		}
838
-
839
-		/**
840
-		 * Get inline script used if bootstrap file browser enqueued.
841
-		 *
842
-		 * If this remains small then its best to use this than to add another JS file.
843
-		 */
844
-		public function inline_script_file_browser(){
845
-			ob_start();
846
-			?>
833
+            return str_replace( array(
834
+                '<script>',
835
+                '</script>'
836
+            ), '', ob_get_clean());
837
+        }
838
+
839
+        /**
840
+         * Get inline script used if bootstrap file browser enqueued.
841
+         *
842
+         * If this remains small then its best to use this than to add another JS file.
843
+         */
844
+        public function inline_script_file_browser(){
845
+            ob_start();
846
+            ?>
847 847
 			<script>
848 848
 				// run on doc ready
849 849
 				jQuery(document).ready(function () {
@@ -851,192 +851,192 @@  discard block
 block discarded – undo
851 851
 				});
852 852
 			</script>
853 853
 			<?php
854
-			$output = ob_get_clean();
854
+            $output = ob_get_clean();
855 855
 
856
-			/*
856
+            /*
857 857
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
858 858
 			 */
859
-			return str_replace( array(
860
-				'<script>',
861
-				'</script>'
862
-			), '', $output );
863
-		}
864
-
865
-		/**
866
-		 * Adds the Font Awesome JS.
867
-		 */
868
-		public function enqueue_scripts() {
869
-
870
-			if( is_admin() && !$this->is_aui_screen()){
871
-				// don't add wp-admin scripts if not requested to
872
-			}else {
873
-
874
-				$js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
875
-
876
-				// select2
877
-				wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version );
878
-
879
-				// flatpickr
880
-				wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest );
881
-
882
-				// Bootstrap file browser
883
-				wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version );
884
-				wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() );
885
-
886
-				$load_inline = false;
887
-
888
-				if ( $this->settings[ $js_setting ] == 'core-popper' ) {
889
-					// Bootstrap bundle
890
-					$url = $this->url . 'assets/js/bootstrap.bundle.min.js';
891
-					wp_register_script( 'bootstrap-js-bundle', $url, array(
892
-						'select2',
893
-						'jquery'
894
-					), $this->latest, $this->is_bs3_compat() );
895
-					// if in admin then add to footer for compatibility.
896
-					is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' );
897
-					$script = $this->inline_script();
898
-					wp_add_inline_script( 'bootstrap-js-bundle', $script );
899
-				} elseif ( $this->settings[ $js_setting ] == 'popper' ) {
900
-					$url = $this->url . 'assets/js/popper.min.js';
901
-					wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->latest );
902
-					wp_enqueue_script( 'bootstrap-js-popper' );
903
-					$load_inline = true;
904
-				} else {
905
-					$load_inline = true;
906
-				}
859
+            return str_replace( array(
860
+                '<script>',
861
+                '</script>'
862
+            ), '', $output );
863
+        }
864
+
865
+        /**
866
+         * Adds the Font Awesome JS.
867
+         */
868
+        public function enqueue_scripts() {
869
+
870
+            if( is_admin() && !$this->is_aui_screen()){
871
+                // don't add wp-admin scripts if not requested to
872
+            }else {
873
+
874
+                $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
875
+
876
+                // select2
877
+                wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version );
878
+
879
+                // flatpickr
880
+                wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest );
881
+
882
+                // Bootstrap file browser
883
+                wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version );
884
+                wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() );
885
+
886
+                $load_inline = false;
887
+
888
+                if ( $this->settings[ $js_setting ] == 'core-popper' ) {
889
+                    // Bootstrap bundle
890
+                    $url = $this->url . 'assets/js/bootstrap.bundle.min.js';
891
+                    wp_register_script( 'bootstrap-js-bundle', $url, array(
892
+                        'select2',
893
+                        'jquery'
894
+                    ), $this->latest, $this->is_bs3_compat() );
895
+                    // if in admin then add to footer for compatibility.
896
+                    is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' );
897
+                    $script = $this->inline_script();
898
+                    wp_add_inline_script( 'bootstrap-js-bundle', $script );
899
+                } elseif ( $this->settings[ $js_setting ] == 'popper' ) {
900
+                    $url = $this->url . 'assets/js/popper.min.js';
901
+                    wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->latest );
902
+                    wp_enqueue_script( 'bootstrap-js-popper' );
903
+                    $load_inline = true;
904
+                } else {
905
+                    $load_inline = true;
906
+                }
907 907
 
908
-				// Load needed inline scripts by faking the loading of a script if the main script is not being loaded
909
-				if ( $load_inline ) {
910
-					wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) );
911
-					wp_enqueue_script( 'bootstrap-dummy' );
912
-					$script = $this->inline_script();
913
-					wp_add_inline_script( 'bootstrap-dummy', $script );
914
-				}
915
-			}
916
-
917
-		}
918
-
919
-		/**
920
-		 * Enqueue flatpickr if called.
921
-		 */
922
-		public function enqueue_flatpickr(){
923
-			wp_enqueue_style( 'flatpickr' );
924
-			wp_enqueue_script( 'flatpickr' );
925
-		}
926
-
927
-		/**
928
-		 * Get the url path to the current folder.
929
-		 *
930
-		 * @return string
931
-		 */
932
-		public function get_url() {
933
-
934
-			$url = '';
935
-			// check if we are inside a plugin
936
-			$file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) );
937
-
938
-			// add check in-case user has changed wp-content dir name.
939
-			$wp_content_folder_name = basename(WP_CONTENT_DIR);
940
-			$dir_parts = explode("/$wp_content_folder_name/",$file_dir);
941
-			$url_parts = explode("/$wp_content_folder_name/",plugins_url());
942
-
943
-			if(!empty($url_parts[0]) && !empty($dir_parts[1])){
944
-				$url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] );
945
-			}
946
-
947
-			return $url;
948
-		}
949
-
950
-		/**
951
-		 * Register the database settings with WordPress.
952
-		 */
953
-		public function register_settings() {
954
-			register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' );
955
-		}
956
-
957
-		/**
958
-		 * Add the WordPress settings menu item.
959
-		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
960
-		 */
961
-		public function menu_item() {
962
-			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
963
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
964
-				$this,
965
-				'settings_page'
966
-			) );
967
-		}
968
-
969
-		/**
970
-		 * Get a list of themes and their default JS settings.
971
-		 *
972
-		 * @return array
973
-		 */
974
-		public function theme_js_settings(){
975
-			return array(
976
-				'ayetheme' => 'popper',
977
-				'listimia' => 'required',
978
-				'listimia_backend' => 'core-popper',
979
-				//'avada'    => 'required', // removed as we now add compatibility
980
-			);
981
-		}
982
-
983
-		/**
984
-		 * Get the current Font Awesome output settings.
985
-		 *
986
-		 * @return array The array of settings.
987
-		 */
988
-		public function get_settings() {
989
-
990
-			$db_settings = get_option( 'ayecode-ui-settings' );
991
-			$js_default = 'core-popper';
992
-			$js_default_backend = $js_default;
993
-
994
-			// maybe set defaults (if no settings set)
995
-			if(empty($db_settings)){
996
-				$active_theme = strtolower( get_template() ); // active parent theme.
997
-				$theme_js_settings = self::theme_js_settings();
998
-				if(isset($theme_js_settings[$active_theme])){
999
-					$js_default = $theme_js_settings[$active_theme];
1000
-					$js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default;
1001
-				}
1002
-			}
1003
-
1004
-			$defaults = array(
1005
-				'css'       => 'compatibility', // core, compatibility
1006
-				'js'        => $js_default, // js to load, core-popper, popper
1007
-				'html_font_size'        => '16', // js to load, core-popper, popper
1008
-				'css_backend'       => 'compatibility', // core, compatibility
1009
-				'js_backend'        => $js_default_backend, // js to load, core-popper, popper
1010
-				'disable_admin'     =>  '', // URL snippets to disable loading on admin
1011
-			);
1012
-
1013
-			$settings = wp_parse_args( $db_settings, $defaults );
1014
-
1015
-			/**
1016
-			 * Filter the Bootstrap settings.
1017
-			 *
1018
-			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
1019
-			 */
1020
-			return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults );
1021
-		}
1022
-
1023
-
1024
-		/**
1025
-		 * The settings page html output.
1026
-		 */
1027
-		public function settings_page() {
1028
-			if ( ! current_user_can( 'manage_options' ) ) {
1029
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) );
1030
-			}
1031
-			?>
908
+                // Load needed inline scripts by faking the loading of a script if the main script is not being loaded
909
+                if ( $load_inline ) {
910
+                    wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) );
911
+                    wp_enqueue_script( 'bootstrap-dummy' );
912
+                    $script = $this->inline_script();
913
+                    wp_add_inline_script( 'bootstrap-dummy', $script );
914
+                }
915
+            }
916
+
917
+        }
918
+
919
+        /**
920
+         * Enqueue flatpickr if called.
921
+         */
922
+        public function enqueue_flatpickr(){
923
+            wp_enqueue_style( 'flatpickr' );
924
+            wp_enqueue_script( 'flatpickr' );
925
+        }
926
+
927
+        /**
928
+         * Get the url path to the current folder.
929
+         *
930
+         * @return string
931
+         */
932
+        public function get_url() {
933
+
934
+            $url = '';
935
+            // check if we are inside a plugin
936
+            $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) );
937
+
938
+            // add check in-case user has changed wp-content dir name.
939
+            $wp_content_folder_name = basename(WP_CONTENT_DIR);
940
+            $dir_parts = explode("/$wp_content_folder_name/",$file_dir);
941
+            $url_parts = explode("/$wp_content_folder_name/",plugins_url());
942
+
943
+            if(!empty($url_parts[0]) && !empty($dir_parts[1])){
944
+                $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] );
945
+            }
946
+
947
+            return $url;
948
+        }
949
+
950
+        /**
951
+         * Register the database settings with WordPress.
952
+         */
953
+        public function register_settings() {
954
+            register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' );
955
+        }
956
+
957
+        /**
958
+         * Add the WordPress settings menu item.
959
+         * @since 1.0.10 Calling function name direct will fail theme check so we don't.
960
+         */
961
+        public function menu_item() {
962
+            $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
963
+            call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
964
+                $this,
965
+                'settings_page'
966
+            ) );
967
+        }
968
+
969
+        /**
970
+         * Get a list of themes and their default JS settings.
971
+         *
972
+         * @return array
973
+         */
974
+        public function theme_js_settings(){
975
+            return array(
976
+                'ayetheme' => 'popper',
977
+                'listimia' => 'required',
978
+                'listimia_backend' => 'core-popper',
979
+                //'avada'    => 'required', // removed as we now add compatibility
980
+            );
981
+        }
982
+
983
+        /**
984
+         * Get the current Font Awesome output settings.
985
+         *
986
+         * @return array The array of settings.
987
+         */
988
+        public function get_settings() {
989
+
990
+            $db_settings = get_option( 'ayecode-ui-settings' );
991
+            $js_default = 'core-popper';
992
+            $js_default_backend = $js_default;
993
+
994
+            // maybe set defaults (if no settings set)
995
+            if(empty($db_settings)){
996
+                $active_theme = strtolower( get_template() ); // active parent theme.
997
+                $theme_js_settings = self::theme_js_settings();
998
+                if(isset($theme_js_settings[$active_theme])){
999
+                    $js_default = $theme_js_settings[$active_theme];
1000
+                    $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default;
1001
+                }
1002
+            }
1003
+
1004
+            $defaults = array(
1005
+                'css'       => 'compatibility', // core, compatibility
1006
+                'js'        => $js_default, // js to load, core-popper, popper
1007
+                'html_font_size'        => '16', // js to load, core-popper, popper
1008
+                'css_backend'       => 'compatibility', // core, compatibility
1009
+                'js_backend'        => $js_default_backend, // js to load, core-popper, popper
1010
+                'disable_admin'     =>  '', // URL snippets to disable loading on admin
1011
+            );
1012
+
1013
+            $settings = wp_parse_args( $db_settings, $defaults );
1014
+
1015
+            /**
1016
+             * Filter the Bootstrap settings.
1017
+             *
1018
+             * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
1019
+             */
1020
+            return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults );
1021
+        }
1022
+
1023
+
1024
+        /**
1025
+         * The settings page html output.
1026
+         */
1027
+        public function settings_page() {
1028
+            if ( ! current_user_can( 'manage_options' ) ) {
1029
+                wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) );
1030
+            }
1031
+            ?>
1032 1032
 			<div class="wrap">
1033 1033
 				<h1><?php echo $this->name; ?></h1>
1034 1034
 				<p><?php _e("Here you can adjust settings if you are having compatibility issues.","aui");?></p>
1035 1035
 				<form method="post" action="options.php">
1036 1036
 					<?php
1037
-					settings_fields( 'ayecode-ui-settings' );
1038
-					do_settings_sections( 'ayecode-ui-settings' );
1039
-					?>
1037
+                    settings_fields( 'ayecode-ui-settings' );
1038
+                    do_settings_sections( 'ayecode-ui-settings' );
1039
+                    ?>
1040 1040
 
1041 1041
 					<h2><?php _e( 'Frontend', 'aui' ); ?></h2>
1042 1042
 					<table class="form-table wpbs-table-settings">
@@ -1116,60 +1116,60 @@  discard block
 block discarded – undo
1116 1116
 					</table>
1117 1117
 
1118 1118
 					<?php
1119
-					submit_button();
1120
-					?>
1119
+                    submit_button();
1120
+                    ?>
1121 1121
 				</form>
1122 1122
 
1123 1123
 				<div id="wpbs-version"><?php echo $this->version; ?></div>
1124 1124
 			</div>
1125 1125
 
1126 1126
 			<?php
1127
-		}
1128
-
1129
-		public function customizer_settings($wp_customize){
1130
-			$wp_customize->add_section('aui_settings', array(
1131
-				'title'    => __('AyeCode UI','aui'),
1132
-				'priority' => 120,
1133
-			));
1134
-
1135
-			//  =============================
1136
-			//  = Color Picker              =
1137
-			//  =============================
1138
-			$wp_customize->add_setting('aui_options[color_primary]', array(
1139
-				'default'           => AUI_PRIMARY_COLOR,
1140
-				'sanitize_callback' => 'sanitize_hex_color',
1141
-				'capability'        => 'edit_theme_options',
1142
-				'type'              => 'option',
1143
-				'transport'         => 'refresh',
1144
-			));
1145
-			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
1146
-				'label'    => __('Primary Color','aui'),
1147
-				'section'  => 'aui_settings',
1148
-				'settings' => 'aui_options[color_primary]',
1149
-			)));
1150
-
1151
-			$wp_customize->add_setting('aui_options[color_secondary]', array(
1152
-				'default'           => '#6c757d',
1153
-				'sanitize_callback' => 'sanitize_hex_color',
1154
-				'capability'        => 'edit_theme_options',
1155
-				'type'              => 'option',
1156
-				'transport'         => 'refresh',
1157
-			));
1158
-			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
1159
-				'label'    => __('Secondary Color','aui'),
1160
-				'section'  => 'aui_settings',
1161
-				'settings' => 'aui_options[color_secondary]',
1162
-			)));
1163
-		}
1164
-
1165
-		/**
1166
-		 * CSS to help with conflict issues with other plugins and themes using bootstrap v3.
1167
-		 *
1168
-		 * @return mixed
1169
-		 */
1170
-		public static function bs3_compat_css() {
1171
-			ob_start();
1172
-			?>
1127
+        }
1128
+
1129
+        public function customizer_settings($wp_customize){
1130
+            $wp_customize->add_section('aui_settings', array(
1131
+                'title'    => __('AyeCode UI','aui'),
1132
+                'priority' => 120,
1133
+            ));
1134
+
1135
+            //  =============================
1136
+            //  = Color Picker              =
1137
+            //  =============================
1138
+            $wp_customize->add_setting('aui_options[color_primary]', array(
1139
+                'default'           => AUI_PRIMARY_COLOR,
1140
+                'sanitize_callback' => 'sanitize_hex_color',
1141
+                'capability'        => 'edit_theme_options',
1142
+                'type'              => 'option',
1143
+                'transport'         => 'refresh',
1144
+            ));
1145
+            $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
1146
+                'label'    => __('Primary Color','aui'),
1147
+                'section'  => 'aui_settings',
1148
+                'settings' => 'aui_options[color_primary]',
1149
+            )));
1150
+
1151
+            $wp_customize->add_setting('aui_options[color_secondary]', array(
1152
+                'default'           => '#6c757d',
1153
+                'sanitize_callback' => 'sanitize_hex_color',
1154
+                'capability'        => 'edit_theme_options',
1155
+                'type'              => 'option',
1156
+                'transport'         => 'refresh',
1157
+            ));
1158
+            $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
1159
+                'label'    => __('Secondary Color','aui'),
1160
+                'section'  => 'aui_settings',
1161
+                'settings' => 'aui_options[color_secondary]',
1162
+            )));
1163
+        }
1164
+
1165
+        /**
1166
+         * CSS to help with conflict issues with other plugins and themes using bootstrap v3.
1167
+         *
1168
+         * @return mixed
1169
+         */
1170
+        public static function bs3_compat_css() {
1171
+            ob_start();
1172
+            ?>
1173 1173
 			<style>
1174 1174
 			/* Bootstrap 3 compatibility */
1175 1175
 			body.modal-open .modal-backdrop.show:not(.in) {opacity:0.5;}
@@ -1195,467 +1195,467 @@  discard block
 block discarded – undo
1195 1195
 			<?php } ?>
1196 1196
 			</style>
1197 1197
 			<?php
1198
-			return str_replace( array(
1199
-				'<style>',
1200
-				'</style>'
1201
-			), '', ob_get_clean());
1202
-		}
1198
+            return str_replace( array(
1199
+                '<style>',
1200
+                '</style>'
1201
+            ), '', ob_get_clean());
1202
+        }
1203 1203
 
1204 1204
 
1205
-		public static function custom_css($compatibility = true) {
1206
-			$settings = get_option('aui_options');
1205
+        public static function custom_css($compatibility = true) {
1206
+            $settings = get_option('aui_options');
1207 1207
 
1208
-			ob_start();
1208
+            ob_start();
1209 1209
 
1210
-			$primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR;
1211
-			$secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR;
1212
-				//AUI_PRIMARY_COLOR_ORIGINAL
1213
-			?>
1210
+            $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR;
1211
+            $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR;
1212
+                //AUI_PRIMARY_COLOR_ORIGINAL
1213
+            ?>
1214 1214
 			<style>
1215 1215
 				<?php
1216 1216
 
1217
-					// BS v3 compat
1218
-					if( self::is_bs3_compat() ){
1219
-					    echo self::bs3_compat_css();
1220
-					}
1217
+                    // BS v3 compat
1218
+                    if( self::is_bs3_compat() ){
1219
+                        echo self::bs3_compat_css();
1220
+                    }
1221 1221
 
1222
-					if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){
1223
-						echo self::css_primary($primary_color,$compatibility);
1224
-					}
1222
+                    if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){
1223
+                        echo self::css_primary($primary_color,$compatibility);
1224
+                    }
1225 1225
 
1226
-					if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){
1227
-						echo self::css_secondary($settings['color_secondary'],$compatibility);
1228
-					}
1226
+                    if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){
1227
+                        echo self::css_secondary($settings['color_secondary'],$compatibility);
1228
+                    }
1229 1229
 
1230
-					// Set admin bar z-index lower when modal is open.
1231
-					echo ' body.modal-open #wpadminbar{z-index:999}';
1230
+                    // Set admin bar z-index lower when modal is open.
1231
+                    echo ' body.modal-open #wpadminbar{z-index:999}';
1232 1232
                 ?>
1233 1233
 			</style>
1234 1234
 			<?php
1235 1235
 
1236 1236
 
1237
-			/*
1237
+            /*
1238 1238
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1239 1239
 			 */
1240
-			return str_replace( array(
1241
-				'<style>',
1242
-				'</style>'
1243
-			), '', ob_get_clean());
1244
-		}
1245
-
1246
-		/**
1247
-		 * Check if we should add booststrap 3 compatibility changes.
1248
-		 *
1249
-		 * @return bool
1250
-		 */
1251
-		public static function is_bs3_compat(){
1252
-			return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION');
1253
-		}
1254
-
1255
-		public static function css_primary($color_code,$compatibility){;
1256
-			$color_code = sanitize_hex_color($color_code);
1257
-			if(!$color_code){return '';}
1258
-			/**
1259
-			 * c = color, b = background color, o = border-color, f = fill
1260
-			 */
1261
-			$selectors = array(
1262
-				'a' => array('c'),
1263
-				'.btn-primary' => array('b','o'),
1264
-				'.btn-primary.disabled' => array('b','o'),
1265
-				'.btn-primary:disabled' => array('b','o'),
1266
-				'.btn-outline-primary' => array('c','o'),
1267
-				'.btn-outline-primary:hover' => array('b','o'),
1268
-				'.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'),
1269
-				'.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'),
1270
-				'.show>.btn-outline-primary.dropdown-toggle' => array('b','o'),
1271
-				'.btn-link' => array('c'),
1272
-				'.dropdown-item.active' => array('b'),
1273
-				'.custom-control-input:checked~.custom-control-label::before' => array('b','o'),
1274
-				'.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'),
1240
+            return str_replace( array(
1241
+                '<style>',
1242
+                '</style>'
1243
+            ), '', ob_get_clean());
1244
+        }
1245
+
1246
+        /**
1247
+         * Check if we should add booststrap 3 compatibility changes.
1248
+         *
1249
+         * @return bool
1250
+         */
1251
+        public static function is_bs3_compat(){
1252
+            return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION');
1253
+        }
1254
+
1255
+        public static function css_primary($color_code,$compatibility){;
1256
+            $color_code = sanitize_hex_color($color_code);
1257
+            if(!$color_code){return '';}
1258
+            /**
1259
+             * c = color, b = background color, o = border-color, f = fill
1260
+             */
1261
+            $selectors = array(
1262
+                'a' => array('c'),
1263
+                '.btn-primary' => array('b','o'),
1264
+                '.btn-primary.disabled' => array('b','o'),
1265
+                '.btn-primary:disabled' => array('b','o'),
1266
+                '.btn-outline-primary' => array('c','o'),
1267
+                '.btn-outline-primary:hover' => array('b','o'),
1268
+                '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'),
1269
+                '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'),
1270
+                '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'),
1271
+                '.btn-link' => array('c'),
1272
+                '.dropdown-item.active' => array('b'),
1273
+                '.custom-control-input:checked~.custom-control-label::before' => array('b','o'),
1274
+                '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'),
1275 1275
 //				'.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules...
1276 1276
 //				'.custom-range::-moz-range-thumb' => array('b'),
1277 1277
 //				'.custom-range::-ms-thumb' => array('b'),
1278
-				'.nav-pills .nav-link.active' => array('b'),
1279
-				'.nav-pills .show>.nav-link' => array('b'),
1280
-				'.page-link' => array('c'),
1281
-				'.page-item.active .page-link' => array('b','o'),
1282
-				'.badge-primary' => array('b'),
1283
-				'.alert-primary' => array('b','o'),
1284
-				'.progress-bar' => array('b'),
1285
-				'.list-group-item.active' => array('b','o'),
1286
-				'.bg-primary' => array('b','f'),
1287
-				'.btn-link.btn-primary' => array('c'),
1288
-				'.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'),
1289
-			);
1290
-
1291
-			$important_selectors = array(
1292
-				'.bg-primary' => array('b','f'),
1293
-				'.border-primary' => array('o'),
1294
-				'.text-primary' => array('c'),
1295
-			);
1296
-
1297
-			$color = array();
1298
-			$color_i = array();
1299
-			$background = array();
1300
-			$background_i = array();
1301
-			$border = array();
1302
-			$border_i = array();
1303
-			$fill = array();
1304
-			$fill_i = array();
1305
-
1306
-			$output = '';
1307
-
1308
-			// build rules into each type
1309
-			foreach($selectors as $selector => $types){
1310
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1311
-				$types = array_combine($types,$types);
1312
-				if(isset($types['c'])){$color[] = $selector;}
1313
-				if(isset($types['b'])){$background[] = $selector;}
1314
-				if(isset($types['o'])){$border[] = $selector;}
1315
-				if(isset($types['f'])){$fill[] = $selector;}
1316
-			}
1317
-
1318
-			// build rules into each type
1319
-			foreach($important_selectors as $selector => $types){
1320
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1321
-				$types = array_combine($types,$types);
1322
-				if(isset($types['c'])){$color_i[] = $selector;}
1323
-				if(isset($types['b'])){$background_i[] = $selector;}
1324
-				if(isset($types['o'])){$border_i[] = $selector;}
1325
-				if(isset($types['f'])){$fill_i[] = $selector;}
1326
-			}
1327
-
1328
-			// add any color rules
1329
-			if(!empty($color)){
1330
-				$output .= implode(",",$color) . "{color: $color_code;} ";
1331
-			}
1332
-			if(!empty($color_i)){
1333
-				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1334
-			}
1335
-
1336
-			// add any background color rules
1337
-			if(!empty($background)){
1338
-				$output .= implode(",",$background) . "{background-color: $color_code;} ";
1339
-			}
1340
-			if(!empty($background_i)){
1341
-				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1342
-			}
1343
-
1344
-			// add any border color rules
1345
-			if(!empty($border)){
1346
-				$output .= implode(",",$border) . "{border-color: $color_code;} ";
1347
-			}
1348
-			if(!empty($border_i)){
1349
-				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1350
-			}
1351
-
1352
-			// add any fill color rules
1353
-			if(!empty($fill)){
1354
-				$output .= implode(",",$fill) . "{fill: $color_code;} ";
1355
-			}
1356
-			if(!empty($fill_i)){
1357
-				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1358
-			}
1359
-
1360
-
1361
-			$prefix = $compatibility ? ".bsui " : "";
1362
-
1363
-			// darken
1364
-			$darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1365
-			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1366
-			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1367
-
1368
-			// lighten
1369
-			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1370
-
1371
-			// opacity see https://css-tricks.com/8-digit-hex-codes/
1372
-			$op_25 = $color_code."40"; // 25% opacity
1373
-
1374
-
1375
-			// button states
1376
-			$output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1377
-			$output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1378
-			$output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1379
-			$output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1380
-
1381
-
1382
-			// dropdown's
1383
-			$output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
1384
-
1385
-
1386
-			// input states
1387
-			$output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} ";
1388
-
1389
-			// page link
1390
-			$output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1391
-
1392
-			return $output;
1393
-		}
1394
-
1395
-		public static function css_secondary($color_code,$compatibility){;
1396
-			$color_code = sanitize_hex_color($color_code);
1397
-			if(!$color_code){return '';}
1398
-			/**
1399
-			 * c = color, b = background color, o = border-color, f = fill
1400
-			 */
1401
-			$selectors = array(
1402
-				'.btn-secondary' => array('b','o'),
1403
-				'.btn-secondary.disabled' => array('b','o'),
1404
-				'.btn-secondary:disabled' => array('b','o'),
1405
-				'.btn-outline-secondary' => array('c','o'),
1406
-				'.btn-outline-secondary:hover' => array('b','o'),
1407
-				'.btn-outline-secondary.disabled' => array('c'),
1408
-				'.btn-outline-secondary:disabled' => array('c'),
1409
-				'.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'),
1410
-				'.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'),
1411
-				'.btn-outline-secondary.dropdown-toggle' => array('b','o'),
1412
-				'.badge-secondary' => array('b'),
1413
-				'.alert-secondary' => array('b','o'),
1414
-				'.btn-link.btn-secondary' => array('c'),
1415
-			);
1416
-
1417
-			$important_selectors = array(
1418
-				'.bg-secondary' => array('b','f'),
1419
-				'.border-secondary' => array('o'),
1420
-				'.text-secondary' => array('c'),
1421
-			);
1422
-
1423
-			$color = array();
1424
-			$color_i = array();
1425
-			$background = array();
1426
-			$background_i = array();
1427
-			$border = array();
1428
-			$border_i = array();
1429
-			$fill = array();
1430
-			$fill_i = array();
1431
-
1432
-			$output = '';
1433
-
1434
-			// build rules into each type
1435
-			foreach($selectors as $selector => $types){
1436
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1437
-				$types = array_combine($types,$types);
1438
-				if(isset($types['c'])){$color[] = $selector;}
1439
-				if(isset($types['b'])){$background[] = $selector;}
1440
-				if(isset($types['o'])){$border[] = $selector;}
1441
-				if(isset($types['f'])){$fill[] = $selector;}
1442
-			}
1443
-
1444
-			// build rules into each type
1445
-			foreach($important_selectors as $selector => $types){
1446
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1447
-				$types = array_combine($types,$types);
1448
-				if(isset($types['c'])){$color_i[] = $selector;}
1449
-				if(isset($types['b'])){$background_i[] = $selector;}
1450
-				if(isset($types['o'])){$border_i[] = $selector;}
1451
-				if(isset($types['f'])){$fill_i[] = $selector;}
1452
-			}
1453
-
1454
-			// add any color rules
1455
-			if(!empty($color)){
1456
-				$output .= implode(",",$color) . "{color: $color_code;} ";
1457
-			}
1458
-			if(!empty($color_i)){
1459
-				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1460
-			}
1461
-
1462
-			// add any background color rules
1463
-			if(!empty($background)){
1464
-				$output .= implode(",",$background) . "{background-color: $color_code;} ";
1465
-			}
1466
-			if(!empty($background_i)){
1467
-				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1468
-			}
1469
-
1470
-			// add any border color rules
1471
-			if(!empty($border)){
1472
-				$output .= implode(",",$border) . "{border-color: $color_code;} ";
1473
-			}
1474
-			if(!empty($border_i)){
1475
-				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1476
-			}
1477
-
1478
-			// add any fill color rules
1479
-			if(!empty($fill)){
1480
-				$output .= implode(",",$fill) . "{fill: $color_code;} ";
1481
-			}
1482
-			if(!empty($fill_i)){
1483
-				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1484
-			}
1485
-
1486
-
1487
-			$prefix = $compatibility ? ".bsui " : "";
1488
-
1489
-			// darken
1490
-			$darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1491
-			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1492
-			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1493
-
1494
-			// lighten
1495
-			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1496
-
1497
-			// opacity see https://css-tricks.com/8-digit-hex-codes/
1498
-			$op_25 = $color_code."40"; // 25% opacity
1499
-
1500
-
1501
-			// button states
1502
-			$output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1503
-			$output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1504
-			$output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1505
-			$output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1506
-
1507
-
1508
-			return $output;
1509
-		}
1510
-
1511
-		/**
1512
-		 * Increases or decreases the brightness of a color by a percentage of the current brightness.
1513
-		 *
1514
-		 * @param   string  $hexCode        Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF`
1515
-		 * @param   float   $adjustPercent  A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker.
1516
-		 *
1517
-		 * @return  string
1518
-		 */
1519
-		public static function css_hex_lighten_darken($hexCode, $adjustPercent) {
1520
-			$hexCode = ltrim($hexCode, '#');
1521
-
1522
-			if (strlen($hexCode) == 3) {
1523
-				$hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
1524
-			}
1525
-
1526
-			$hexCode = array_map('hexdec', str_split($hexCode, 2));
1527
-
1528
-			foreach ($hexCode as & $color) {
1529
-				$adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
1530
-				$adjustAmount = ceil($adjustableLimit * $adjustPercent);
1531
-
1532
-				$color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT);
1533
-			}
1534
-
1535
-			return '#' . implode($hexCode);
1536
-		}
1537
-
1538
-		/**
1539
-		 * Check if we should display examples.
1540
-		 */
1541
-		public function maybe_show_examples(){
1542
-			if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){
1543
-				echo "<head>";
1544
-				wp_head();
1545
-				echo "</head>";
1546
-				echo "<body>";
1547
-				echo $this->get_examples();
1548
-				echo "</body>";
1549
-				exit;
1550
-			}
1551
-		}
1552
-
1553
-		/**
1554
-		 * Get developer examples.
1555
-		 *
1556
-		 * @return string
1557
-		 */
1558
-		public function get_examples(){
1559
-			$output = '';
1560
-
1561
-
1562
-			// open form
1563
-			$output .= "<form class='p-5 m-5 border rounded'>";
1564
-
1565
-			// input example
1566
-			$output .= aui()->input(array(
1567
-				'type'  =>  'text',
1568
-				'id'    =>  'text-example',
1569
-				'name'    =>  'text-example',
1570
-				'placeholder'   => 'text placeholder',
1571
-				'title'   => 'Text input example',
1572
-				'value' =>  '',
1573
-				'required'  => false,
1574
-				'help_text' => 'help text',
1575
-				'label' => 'Text input example label'
1576
-			));
1577
-
1578
-			// input example
1579
-			$output .= aui()->input(array(
1580
-				'type'  =>  'url',
1581
-				'id'    =>  'text-example2',
1582
-				'name'    =>  'text-example',
1583
-				'placeholder'   => 'url placeholder',
1584
-				'title'   => 'Text input example',
1585
-				'value' =>  '',
1586
-				'required'  => false,
1587
-				'help_text' => 'help text',
1588
-				'label' => 'Text input example label'
1589
-			));
1590
-
1591
-			// checkbox example
1592
-			$output .= aui()->input(array(
1593
-				'type'  =>  'checkbox',
1594
-				'id'    =>  'checkbox-example',
1595
-				'name'    =>  'checkbox-example',
1596
-				'placeholder'   => 'checkbox-example',
1597
-				'title'   => 'Checkbox example',
1598
-				'value' =>  '1',
1599
-				'checked'   => true,
1600
-				'required'  => false,
1601
-				'help_text' => 'help text',
1602
-				'label' => 'Checkbox checked'
1603
-			));
1604
-
1605
-			// checkbox example
1606
-			$output .= aui()->input(array(
1607
-				'type'  =>  'checkbox',
1608
-				'id'    =>  'checkbox-example2',
1609
-				'name'    =>  'checkbox-example2',
1610
-				'placeholder'   => 'checkbox-example',
1611
-				'title'   => 'Checkbox example',
1612
-				'value' =>  '1',
1613
-				'checked'   => false,
1614
-				'required'  => false,
1615
-				'help_text' => 'help text',
1616
-				'label' => 'Checkbox un-checked'
1617
-			));
1618
-
1619
-			// switch example
1620
-			$output .= aui()->input(array(
1621
-				'type'  =>  'checkbox',
1622
-				'id'    =>  'switch-example',
1623
-				'name'    =>  'switch-example',
1624
-				'placeholder'   => 'checkbox-example',
1625
-				'title'   => 'Switch example',
1626
-				'value' =>  '1',
1627
-				'checked'   => true,
1628
-				'switch'    => true,
1629
-				'required'  => false,
1630
-				'help_text' => 'help text',
1631
-				'label' => 'Switch on'
1632
-			));
1633
-
1634
-			// switch example
1635
-			$output .= aui()->input(array(
1636
-				'type'  =>  'checkbox',
1637
-				'id'    =>  'switch-example2',
1638
-				'name'    =>  'switch-example2',
1639
-				'placeholder'   => 'checkbox-example',
1640
-				'title'   => 'Switch example',
1641
-				'value' =>  '1',
1642
-				'checked'   => false,
1643
-				'switch'    => true,
1644
-				'required'  => false,
1645
-				'help_text' => 'help text',
1646
-				'label' => 'Switch off'
1647
-			));
1648
-
1649
-			// close form
1650
-			$output .= "</form>";
1651
-
1652
-			return $output;
1653
-		}
1654
-
1655
-	}
1656
-
1657
-	/**
1658
-	 * Run the class if found.
1659
-	 */
1660
-	AyeCode_UI_Settings::instance();
1278
+                '.nav-pills .nav-link.active' => array('b'),
1279
+                '.nav-pills .show>.nav-link' => array('b'),
1280
+                '.page-link' => array('c'),
1281
+                '.page-item.active .page-link' => array('b','o'),
1282
+                '.badge-primary' => array('b'),
1283
+                '.alert-primary' => array('b','o'),
1284
+                '.progress-bar' => array('b'),
1285
+                '.list-group-item.active' => array('b','o'),
1286
+                '.bg-primary' => array('b','f'),
1287
+                '.btn-link.btn-primary' => array('c'),
1288
+                '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'),
1289
+            );
1290
+
1291
+            $important_selectors = array(
1292
+                '.bg-primary' => array('b','f'),
1293
+                '.border-primary' => array('o'),
1294
+                '.text-primary' => array('c'),
1295
+            );
1296
+
1297
+            $color = array();
1298
+            $color_i = array();
1299
+            $background = array();
1300
+            $background_i = array();
1301
+            $border = array();
1302
+            $border_i = array();
1303
+            $fill = array();
1304
+            $fill_i = array();
1305
+
1306
+            $output = '';
1307
+
1308
+            // build rules into each type
1309
+            foreach($selectors as $selector => $types){
1310
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
1311
+                $types = array_combine($types,$types);
1312
+                if(isset($types['c'])){$color[] = $selector;}
1313
+                if(isset($types['b'])){$background[] = $selector;}
1314
+                if(isset($types['o'])){$border[] = $selector;}
1315
+                if(isset($types['f'])){$fill[] = $selector;}
1316
+            }
1317
+
1318
+            // build rules into each type
1319
+            foreach($important_selectors as $selector => $types){
1320
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
1321
+                $types = array_combine($types,$types);
1322
+                if(isset($types['c'])){$color_i[] = $selector;}
1323
+                if(isset($types['b'])){$background_i[] = $selector;}
1324
+                if(isset($types['o'])){$border_i[] = $selector;}
1325
+                if(isset($types['f'])){$fill_i[] = $selector;}
1326
+            }
1327
+
1328
+            // add any color rules
1329
+            if(!empty($color)){
1330
+                $output .= implode(",",$color) . "{color: $color_code;} ";
1331
+            }
1332
+            if(!empty($color_i)){
1333
+                $output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1334
+            }
1335
+
1336
+            // add any background color rules
1337
+            if(!empty($background)){
1338
+                $output .= implode(",",$background) . "{background-color: $color_code;} ";
1339
+            }
1340
+            if(!empty($background_i)){
1341
+                $output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1342
+            }
1343
+
1344
+            // add any border color rules
1345
+            if(!empty($border)){
1346
+                $output .= implode(",",$border) . "{border-color: $color_code;} ";
1347
+            }
1348
+            if(!empty($border_i)){
1349
+                $output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1350
+            }
1351
+
1352
+            // add any fill color rules
1353
+            if(!empty($fill)){
1354
+                $output .= implode(",",$fill) . "{fill: $color_code;} ";
1355
+            }
1356
+            if(!empty($fill_i)){
1357
+                $output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1358
+            }
1359
+
1360
+
1361
+            $prefix = $compatibility ? ".bsui " : "";
1362
+
1363
+            // darken
1364
+            $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1365
+            $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1366
+            $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1367
+
1368
+            // lighten
1369
+            $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1370
+
1371
+            // opacity see https://css-tricks.com/8-digit-hex-codes/
1372
+            $op_25 = $color_code."40"; // 25% opacity
1373
+
1374
+
1375
+            // button states
1376
+            $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1377
+            $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1378
+            $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1379
+            $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1380
+
1381
+
1382
+            // dropdown's
1383
+            $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
1384
+
1385
+
1386
+            // input states
1387
+            $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} ";
1388
+
1389
+            // page link
1390
+            $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1391
+
1392
+            return $output;
1393
+        }
1394
+
1395
+        public static function css_secondary($color_code,$compatibility){;
1396
+            $color_code = sanitize_hex_color($color_code);
1397
+            if(!$color_code){return '';}
1398
+            /**
1399
+             * c = color, b = background color, o = border-color, f = fill
1400
+             */
1401
+            $selectors = array(
1402
+                '.btn-secondary' => array('b','o'),
1403
+                '.btn-secondary.disabled' => array('b','o'),
1404
+                '.btn-secondary:disabled' => array('b','o'),
1405
+                '.btn-outline-secondary' => array('c','o'),
1406
+                '.btn-outline-secondary:hover' => array('b','o'),
1407
+                '.btn-outline-secondary.disabled' => array('c'),
1408
+                '.btn-outline-secondary:disabled' => array('c'),
1409
+                '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'),
1410
+                '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'),
1411
+                '.btn-outline-secondary.dropdown-toggle' => array('b','o'),
1412
+                '.badge-secondary' => array('b'),
1413
+                '.alert-secondary' => array('b','o'),
1414
+                '.btn-link.btn-secondary' => array('c'),
1415
+            );
1416
+
1417
+            $important_selectors = array(
1418
+                '.bg-secondary' => array('b','f'),
1419
+                '.border-secondary' => array('o'),
1420
+                '.text-secondary' => array('c'),
1421
+            );
1422
+
1423
+            $color = array();
1424
+            $color_i = array();
1425
+            $background = array();
1426
+            $background_i = array();
1427
+            $border = array();
1428
+            $border_i = array();
1429
+            $fill = array();
1430
+            $fill_i = array();
1431
+
1432
+            $output = '';
1433
+
1434
+            // build rules into each type
1435
+            foreach($selectors as $selector => $types){
1436
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
1437
+                $types = array_combine($types,$types);
1438
+                if(isset($types['c'])){$color[] = $selector;}
1439
+                if(isset($types['b'])){$background[] = $selector;}
1440
+                if(isset($types['o'])){$border[] = $selector;}
1441
+                if(isset($types['f'])){$fill[] = $selector;}
1442
+            }
1443
+
1444
+            // build rules into each type
1445
+            foreach($important_selectors as $selector => $types){
1446
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
1447
+                $types = array_combine($types,$types);
1448
+                if(isset($types['c'])){$color_i[] = $selector;}
1449
+                if(isset($types['b'])){$background_i[] = $selector;}
1450
+                if(isset($types['o'])){$border_i[] = $selector;}
1451
+                if(isset($types['f'])){$fill_i[] = $selector;}
1452
+            }
1453
+
1454
+            // add any color rules
1455
+            if(!empty($color)){
1456
+                $output .= implode(",",$color) . "{color: $color_code;} ";
1457
+            }
1458
+            if(!empty($color_i)){
1459
+                $output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1460
+            }
1461
+
1462
+            // add any background color rules
1463
+            if(!empty($background)){
1464
+                $output .= implode(",",$background) . "{background-color: $color_code;} ";
1465
+            }
1466
+            if(!empty($background_i)){
1467
+                $output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1468
+            }
1469
+
1470
+            // add any border color rules
1471
+            if(!empty($border)){
1472
+                $output .= implode(",",$border) . "{border-color: $color_code;} ";
1473
+            }
1474
+            if(!empty($border_i)){
1475
+                $output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1476
+            }
1477
+
1478
+            // add any fill color rules
1479
+            if(!empty($fill)){
1480
+                $output .= implode(",",$fill) . "{fill: $color_code;} ";
1481
+            }
1482
+            if(!empty($fill_i)){
1483
+                $output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1484
+            }
1485
+
1486
+
1487
+            $prefix = $compatibility ? ".bsui " : "";
1488
+
1489
+            // darken
1490
+            $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1491
+            $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1492
+            $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1493
+
1494
+            // lighten
1495
+            $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1496
+
1497
+            // opacity see https://css-tricks.com/8-digit-hex-codes/
1498
+            $op_25 = $color_code."40"; // 25% opacity
1499
+
1500
+
1501
+            // button states
1502
+            $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1503
+            $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1504
+            $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1505
+            $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1506
+
1507
+
1508
+            return $output;
1509
+        }
1510
+
1511
+        /**
1512
+         * Increases or decreases the brightness of a color by a percentage of the current brightness.
1513
+         *
1514
+         * @param   string  $hexCode        Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF`
1515
+         * @param   float   $adjustPercent  A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker.
1516
+         *
1517
+         * @return  string
1518
+         */
1519
+        public static function css_hex_lighten_darken($hexCode, $adjustPercent) {
1520
+            $hexCode = ltrim($hexCode, '#');
1521
+
1522
+            if (strlen($hexCode) == 3) {
1523
+                $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
1524
+            }
1525
+
1526
+            $hexCode = array_map('hexdec', str_split($hexCode, 2));
1527
+
1528
+            foreach ($hexCode as & $color) {
1529
+                $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
1530
+                $adjustAmount = ceil($adjustableLimit * $adjustPercent);
1531
+
1532
+                $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT);
1533
+            }
1534
+
1535
+            return '#' . implode($hexCode);
1536
+        }
1537
+
1538
+        /**
1539
+         * Check if we should display examples.
1540
+         */
1541
+        public function maybe_show_examples(){
1542
+            if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){
1543
+                echo "<head>";
1544
+                wp_head();
1545
+                echo "</head>";
1546
+                echo "<body>";
1547
+                echo $this->get_examples();
1548
+                echo "</body>";
1549
+                exit;
1550
+            }
1551
+        }
1552
+
1553
+        /**
1554
+         * Get developer examples.
1555
+         *
1556
+         * @return string
1557
+         */
1558
+        public function get_examples(){
1559
+            $output = '';
1560
+
1561
+
1562
+            // open form
1563
+            $output .= "<form class='p-5 m-5 border rounded'>";
1564
+
1565
+            // input example
1566
+            $output .= aui()->input(array(
1567
+                'type'  =>  'text',
1568
+                'id'    =>  'text-example',
1569
+                'name'    =>  'text-example',
1570
+                'placeholder'   => 'text placeholder',
1571
+                'title'   => 'Text input example',
1572
+                'value' =>  '',
1573
+                'required'  => false,
1574
+                'help_text' => 'help text',
1575
+                'label' => 'Text input example label'
1576
+            ));
1577
+
1578
+            // input example
1579
+            $output .= aui()->input(array(
1580
+                'type'  =>  'url',
1581
+                'id'    =>  'text-example2',
1582
+                'name'    =>  'text-example',
1583
+                'placeholder'   => 'url placeholder',
1584
+                'title'   => 'Text input example',
1585
+                'value' =>  '',
1586
+                'required'  => false,
1587
+                'help_text' => 'help text',
1588
+                'label' => 'Text input example label'
1589
+            ));
1590
+
1591
+            // checkbox example
1592
+            $output .= aui()->input(array(
1593
+                'type'  =>  'checkbox',
1594
+                'id'    =>  'checkbox-example',
1595
+                'name'    =>  'checkbox-example',
1596
+                'placeholder'   => 'checkbox-example',
1597
+                'title'   => 'Checkbox example',
1598
+                'value' =>  '1',
1599
+                'checked'   => true,
1600
+                'required'  => false,
1601
+                'help_text' => 'help text',
1602
+                'label' => 'Checkbox checked'
1603
+            ));
1604
+
1605
+            // checkbox example
1606
+            $output .= aui()->input(array(
1607
+                'type'  =>  'checkbox',
1608
+                'id'    =>  'checkbox-example2',
1609
+                'name'    =>  'checkbox-example2',
1610
+                'placeholder'   => 'checkbox-example',
1611
+                'title'   => 'Checkbox example',
1612
+                'value' =>  '1',
1613
+                'checked'   => false,
1614
+                'required'  => false,
1615
+                'help_text' => 'help text',
1616
+                'label' => 'Checkbox un-checked'
1617
+            ));
1618
+
1619
+            // switch example
1620
+            $output .= aui()->input(array(
1621
+                'type'  =>  'checkbox',
1622
+                'id'    =>  'switch-example',
1623
+                'name'    =>  'switch-example',
1624
+                'placeholder'   => 'checkbox-example',
1625
+                'title'   => 'Switch example',
1626
+                'value' =>  '1',
1627
+                'checked'   => true,
1628
+                'switch'    => true,
1629
+                'required'  => false,
1630
+                'help_text' => 'help text',
1631
+                'label' => 'Switch on'
1632
+            ));
1633
+
1634
+            // switch example
1635
+            $output .= aui()->input(array(
1636
+                'type'  =>  'checkbox',
1637
+                'id'    =>  'switch-example2',
1638
+                'name'    =>  'switch-example2',
1639
+                'placeholder'   => 'checkbox-example',
1640
+                'title'   => 'Switch example',
1641
+                'value' =>  '1',
1642
+                'checked'   => false,
1643
+                'switch'    => true,
1644
+                'required'  => false,
1645
+                'help_text' => 'help text',
1646
+                'label' => 'Switch off'
1647
+            ));
1648
+
1649
+            // close form
1650
+            $output .= "</form>";
1651
+
1652
+            return $output;
1653
+        }
1654
+
1655
+    }
1656
+
1657
+    /**
1658
+     * Run the class if found.
1659
+     */
1660
+    AyeCode_UI_Settings::instance();
1661 1661
 }
1662 1662
\ No newline at end of file
Please login to merge, or discard this patch.