Passed
Push — master ( 94b139...e2bf3a )
by Brian
18:33 queued 04:38
created
includes/data-stores/class-getpaid-invoice-data-store.php 1 patch
Indentation   +467 added lines, -467 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,537 +15,537 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP {
17 17
 
18
-	/**
19
-	 * Data stored in meta keys, but not considered "meta" for a discount.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $internal_meta_keys = array(
25
-		'_wpinv_subscr_profile_id',
26
-		'_wpinv_subscription_id',
27
-		'_wpinv_taxes',
28
-		'_wpinv_fees',
29
-		'_wpinv_discounts',
30
-		'_wpinv_submission_id',
31
-		'_wpinv_payment_form',
32
-		'_wpinv_is_viewed',
33
-		'wpinv_email_cc',
34
-		'wpinv_template',
35
-		'wpinv_created_via'
36
-	);
37
-
38
-	/**
39
-	 * A map of meta keys to data props.
40
-	 *
41
-	 * @since 1.0.19
42
-	 *
43
-	 * @var array
44
-	 */
45
-	protected $meta_key_to_props = array(
46
-		'_wpinv_subscr_profile_id' => 'remote_subscription_id',
47
-		'_wpinv_subscription_id'   => 'subscription_id',
48
-		'_wpinv_taxes'             => 'taxes',
49
-		'_wpinv_fees'              => 'fees',
50
-		'_wpinv_discounts'         => 'discounts',
51
-		'_wpinv_submission_id'     => 'submission_id',
52
-		'_wpinv_payment_form'      => 'payment_form',
53
-		'_wpinv_is_viewed'         => 'is_viewed',
54
-		'wpinv_email_cc'           => 'email_cc',
55
-		'wpinv_template'           => 'template',
56
-		'wpinv_created_via'        => 'created_via',
57
-	);
58
-
59
-	/**
60
-	 * A map of database fields to data props.
61
-	 *
62
-	 * @since 1.0.19
63
-	 *
64
-	 * @var array
65
-	 */
66
-	protected $database_fields_to_props = array(
67
-		'post_id'            => 'id',
68
-		'number'             => 'number',
69
-		'currency'           => 'currency',
70
-		'key'                => 'key',
71
-		'type'               => 'type',
72
-		'mode'               => 'mode',
73
-		'user_ip'            => 'user_ip',
74
-		'first_name'         => 'first_name',
75
-		'last_name'          => 'last_name',
76
-		'address'            => 'address',
77
-		'city'               => 'city',
78
-		'state'              => 'state',
79
-		'country'            => 'country',
80
-		'zip'                => 'zip',
81
-		'zip'                => 'zip',
82
-		'adddress_confirmed' => 'address_confirmed',
83
-		'gateway'            => 'gateway',
84
-		'transaction_id'     => 'transaction_id',
85
-		'currency'           => 'currency',
86
-		'subtotal'           => 'subtotal',
87
-		'tax'                => 'total_tax',
88
-		'fees_total'         => 'total_fees',
89
-		'discount'           => 'total_discount',
90
-		'total'              => 'total',
91
-		'discount_code'      => 'discount_code',
92
-		'disable_taxes'      => 'disable_taxes',
93
-		'due_date'           => 'due_date',
94
-		'completed_date'     => 'completed_date',
95
-		'company'            => 'company',
96
-		'vat_number'         => 'vat_number',
97
-		'vat_rate'           => 'vat_rate',
98
-	);
99
-
100
-	/*
18
+    /**
19
+     * Data stored in meta keys, but not considered "meta" for a discount.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $internal_meta_keys = array(
25
+        '_wpinv_subscr_profile_id',
26
+        '_wpinv_subscription_id',
27
+        '_wpinv_taxes',
28
+        '_wpinv_fees',
29
+        '_wpinv_discounts',
30
+        '_wpinv_submission_id',
31
+        '_wpinv_payment_form',
32
+        '_wpinv_is_viewed',
33
+        'wpinv_email_cc',
34
+        'wpinv_template',
35
+        'wpinv_created_via'
36
+    );
37
+
38
+    /**
39
+     * A map of meta keys to data props.
40
+     *
41
+     * @since 1.0.19
42
+     *
43
+     * @var array
44
+     */
45
+    protected $meta_key_to_props = array(
46
+        '_wpinv_subscr_profile_id' => 'remote_subscription_id',
47
+        '_wpinv_subscription_id'   => 'subscription_id',
48
+        '_wpinv_taxes'             => 'taxes',
49
+        '_wpinv_fees'              => 'fees',
50
+        '_wpinv_discounts'         => 'discounts',
51
+        '_wpinv_submission_id'     => 'submission_id',
52
+        '_wpinv_payment_form'      => 'payment_form',
53
+        '_wpinv_is_viewed'         => 'is_viewed',
54
+        'wpinv_email_cc'           => 'email_cc',
55
+        'wpinv_template'           => 'template',
56
+        'wpinv_created_via'        => 'created_via',
57
+    );
58
+
59
+    /**
60
+     * A map of database fields to data props.
61
+     *
62
+     * @since 1.0.19
63
+     *
64
+     * @var array
65
+     */
66
+    protected $database_fields_to_props = array(
67
+        'post_id'            => 'id',
68
+        'number'             => 'number',
69
+        'currency'           => 'currency',
70
+        'key'                => 'key',
71
+        'type'               => 'type',
72
+        'mode'               => 'mode',
73
+        'user_ip'            => 'user_ip',
74
+        'first_name'         => 'first_name',
75
+        'last_name'          => 'last_name',
76
+        'address'            => 'address',
77
+        'city'               => 'city',
78
+        'state'              => 'state',
79
+        'country'            => 'country',
80
+        'zip'                => 'zip',
81
+        'zip'                => 'zip',
82
+        'adddress_confirmed' => 'address_confirmed',
83
+        'gateway'            => 'gateway',
84
+        'transaction_id'     => 'transaction_id',
85
+        'currency'           => 'currency',
86
+        'subtotal'           => 'subtotal',
87
+        'tax'                => 'total_tax',
88
+        'fees_total'         => 'total_fees',
89
+        'discount'           => 'total_discount',
90
+        'total'              => 'total',
91
+        'discount_code'      => 'discount_code',
92
+        'disable_taxes'      => 'disable_taxes',
93
+        'due_date'           => 'due_date',
94
+        'completed_date'     => 'completed_date',
95
+        'company'            => 'company',
96
+        'vat_number'         => 'vat_number',
97
+        'vat_rate'           => 'vat_rate',
98
+    );
99
+
100
+    /*
101 101
 	|--------------------------------------------------------------------------
102 102
 	| CRUD Methods
103 103
 	|--------------------------------------------------------------------------
104 104
 	*/
105 105
 
106
-	/**
107
-	 * Method to create a new invoice in the database.
108
-	 *
109
-	 * @param WPInv_Invoice $invoice Invoice object.
110
-	 */
111
-	public function create( &$invoice ) {
112
-		$invoice->set_version( WPINV_VERSION );
113
-		$invoice->set_date_created( current_time('mysql') );
114
-
115
-		// Create a new post.
116
-		$id = wp_insert_post(
117
-			apply_filters(
118
-				'getpaid_new_invoice_data',
119
-				array(
120
-					'post_date'     => $invoice->get_date_created( 'edit' ),
121
-					'post_type'     => $invoice->get_post_type( 'edit' ),
122
-					'post_status'   => $this->get_post_status( $invoice ),
123
-					'ping_status'   => 'closed',
124
-					'post_author'   => $invoice->get_user_id( 'edit' ),
125
-					'post_title'    => $invoice->get_title( 'edit' ),
126
-					'post_excerpt'  => $invoice->get_description( 'edit' ),
127
-					'post_parent'   => $invoice->get_parent_id( 'edit' ),
128
-				)
129
-			),
130
-			true
131
-		);
132
-
133
-		if ( $id && ! is_wp_error( $id ) ) {
134
-
135
-			// Update the new id and regenerate a title.
136
-			$invoice->set_id( $id );
137
-
138
-			$invoice->maybe_set_number();
139
-
140
-			wp_update_post(
141
-				array(
142
-					'ID'         => $invoice->get_id(),
143
-					'post_title' => $invoice->get_number( 'edit' ),
144
-					'post_name'  => $invoice->get_path( 'edit' )
145
-				)
146
-			);
147
-
148
-			// Save special fields and items.
149
-			$this->save_special_fields( $invoice );
150
-			$this->save_items( $invoice );
151
-
152
-			// Update meta data.
153
-			$this->update_post_meta( $invoice );
154
-			$invoice->save_meta_data();
155
-
156
-			// Apply changes.
157
-			$invoice->apply_changes();
158
-			$this->clear_caches( $invoice );
159
-
160
-			// Fires after a new invoice is created.
161
-			do_action( 'getpaid_new_invoice', $invoice );
162
-			return true;
163
-		}
164
-
165
-		if ( is_wp_error( $id ) ) {
166
-			$invoice->last_error = $id->get_error_message();
167
-		}
168
-
169
-		return false;
170
-	}
171
-
172
-	/**
173
-	 * Method to read an invoice from the database.
174
-	 *
175
-	 * @param WPInv_Invoice $invoice Invoice object.
176
-	 *
177
-	 */
178
-	public function read( &$invoice ) {
179
-
180
-		$invoice->set_defaults();
181
-		$invoice_object = get_post( $invoice->get_id() );
182
-
183
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
184
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
185
-			$invoice->set_id( 0 );
186
-			return false;
187
-		}
188
-
189
-		$invoice->set_props(
190
-			array(
191
-				'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
192
-				'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
193
-				'status'        => $invoice_object->post_status,
194
-				'author'        => $invoice_object->post_author,
195
-				'description'   => $invoice_object->post_excerpt,
196
-				'parent_id'     => $invoice_object->post_parent,
197
-				'name'          => $invoice_object->post_title,
198
-				'path'          => $invoice_object->post_name,
199
-				'post_type'     => $invoice_object->post_type,
200
-			)
201
-		);
202
-
203
-		$invoice->set_type( $invoice_object->post_type );
204
-
205
-		$this->read_object_data( $invoice, $invoice_object );
206
-		$this->add_special_fields( $invoice );
207
-		$this->add_items( $invoice );
208
-		$invoice->read_meta_data();
209
-		$invoice->set_object_read( true );
210
-		do_action( 'getpaid_read_invoice', $invoice );
211
-
212
-	}
213
-
214
-	/**
215
-	 * Method to update an invoice in the database.
216
-	 *
217
-	 * @param WPInv_Invoice $invoice Invoice object.
218
-	 */
219
-	public function update( &$invoice ) {
220
-		$invoice->save_meta_data();
221
-		$invoice->set_version( WPINV_VERSION );
222
-
223
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
224
-			$invoice->set_date_created(  current_time('mysql') );
225
-		}
226
-
227
-		// Ensure both the key and number are set.
228
-		$invoice->get_path();
229
-
230
-		// Grab the current status so we can compare.
231
-		$previous_status = get_post_status( $invoice->get_id() );
232
-
233
-		$changes = $invoice->get_changes();
234
-
235
-		// Only update the post when the post data changes.
236
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
237
-			$post_data = array(
238
-				'post_date'         => $invoice->get_date_created( 'edit' ),
239
-				'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
240
-				'post_status'       => $invoice->get_status( 'edit' ),
241
-				'post_title'        => $invoice->get_name( 'edit' ),
242
-				'post_author'       => $invoice->get_user_id( 'edit' ),
243
-				'post_modified'     => $invoice->get_date_modified( 'edit' ),
244
-				'post_excerpt'      => $invoice->get_description( 'edit' ),
245
-				'post_parent'       => $invoice->get_parent_id( 'edit' ),
246
-				'post_name'         => $invoice->get_path( 'edit' ),
247
-				'post_type'         => $invoice->get_post_type( 'edit' ),
248
-			);
249
-
250
-			/**
251
-			 * When updating this object, to prevent infinite loops, use $wpdb
252
-			 * to update data, since wp_update_post spawns more calls to the
253
-			 * save_post action.
254
-			 *
255
-			 * This ensures hooks are fired by either WP itself (admin screen save),
256
-			 * or an update purely from CRUD.
257
-			 */
258
-			if ( doing_action( 'save_post' ) ) {
259
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
260
-				clean_post_cache( $invoice->get_id() );
261
-			} else {
262
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
263
-			}
264
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
265
-		}
266
-
267
-		// Update meta data.
268
-		$this->update_post_meta( $invoice );
269
-
270
-		// Save special fields and items.
271
-		$this->save_special_fields( $invoice );
272
-		$this->save_items( $invoice );
273
-
274
-		// Apply the changes.
275
-		$invoice->apply_changes();
276
-
277
-		// Clear caches.
278
-		$this->clear_caches( $invoice );
279
-
280
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
281
-		$new_status = $invoice->get_status( 'edit' );
282
-
283
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
284
-			do_action( 'getpaid_new_invoice', $invoice );
285
-		} else {
286
-			do_action( 'getpaid_update_invoice', $invoice );
287
-		}
288
-
289
-	}
290
-
291
-	/*
106
+    /**
107
+     * Method to create a new invoice in the database.
108
+     *
109
+     * @param WPInv_Invoice $invoice Invoice object.
110
+     */
111
+    public function create( &$invoice ) {
112
+        $invoice->set_version( WPINV_VERSION );
113
+        $invoice->set_date_created( current_time('mysql') );
114
+
115
+        // Create a new post.
116
+        $id = wp_insert_post(
117
+            apply_filters(
118
+                'getpaid_new_invoice_data',
119
+                array(
120
+                    'post_date'     => $invoice->get_date_created( 'edit' ),
121
+                    'post_type'     => $invoice->get_post_type( 'edit' ),
122
+                    'post_status'   => $this->get_post_status( $invoice ),
123
+                    'ping_status'   => 'closed',
124
+                    'post_author'   => $invoice->get_user_id( 'edit' ),
125
+                    'post_title'    => $invoice->get_title( 'edit' ),
126
+                    'post_excerpt'  => $invoice->get_description( 'edit' ),
127
+                    'post_parent'   => $invoice->get_parent_id( 'edit' ),
128
+                )
129
+            ),
130
+            true
131
+        );
132
+
133
+        if ( $id && ! is_wp_error( $id ) ) {
134
+
135
+            // Update the new id and regenerate a title.
136
+            $invoice->set_id( $id );
137
+
138
+            $invoice->maybe_set_number();
139
+
140
+            wp_update_post(
141
+                array(
142
+                    'ID'         => $invoice->get_id(),
143
+                    'post_title' => $invoice->get_number( 'edit' ),
144
+                    'post_name'  => $invoice->get_path( 'edit' )
145
+                )
146
+            );
147
+
148
+            // Save special fields and items.
149
+            $this->save_special_fields( $invoice );
150
+            $this->save_items( $invoice );
151
+
152
+            // Update meta data.
153
+            $this->update_post_meta( $invoice );
154
+            $invoice->save_meta_data();
155
+
156
+            // Apply changes.
157
+            $invoice->apply_changes();
158
+            $this->clear_caches( $invoice );
159
+
160
+            // Fires after a new invoice is created.
161
+            do_action( 'getpaid_new_invoice', $invoice );
162
+            return true;
163
+        }
164
+
165
+        if ( is_wp_error( $id ) ) {
166
+            $invoice->last_error = $id->get_error_message();
167
+        }
168
+
169
+        return false;
170
+    }
171
+
172
+    /**
173
+     * Method to read an invoice from the database.
174
+     *
175
+     * @param WPInv_Invoice $invoice Invoice object.
176
+     *
177
+     */
178
+    public function read( &$invoice ) {
179
+
180
+        $invoice->set_defaults();
181
+        $invoice_object = get_post( $invoice->get_id() );
182
+
183
+        if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
184
+            $invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
185
+            $invoice->set_id( 0 );
186
+            return false;
187
+        }
188
+
189
+        $invoice->set_props(
190
+            array(
191
+                'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
192
+                'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
193
+                'status'        => $invoice_object->post_status,
194
+                'author'        => $invoice_object->post_author,
195
+                'description'   => $invoice_object->post_excerpt,
196
+                'parent_id'     => $invoice_object->post_parent,
197
+                'name'          => $invoice_object->post_title,
198
+                'path'          => $invoice_object->post_name,
199
+                'post_type'     => $invoice_object->post_type,
200
+            )
201
+        );
202
+
203
+        $invoice->set_type( $invoice_object->post_type );
204
+
205
+        $this->read_object_data( $invoice, $invoice_object );
206
+        $this->add_special_fields( $invoice );
207
+        $this->add_items( $invoice );
208
+        $invoice->read_meta_data();
209
+        $invoice->set_object_read( true );
210
+        do_action( 'getpaid_read_invoice', $invoice );
211
+
212
+    }
213
+
214
+    /**
215
+     * Method to update an invoice in the database.
216
+     *
217
+     * @param WPInv_Invoice $invoice Invoice object.
218
+     */
219
+    public function update( &$invoice ) {
220
+        $invoice->save_meta_data();
221
+        $invoice->set_version( WPINV_VERSION );
222
+
223
+        if ( null === $invoice->get_date_created( 'edit' ) ) {
224
+            $invoice->set_date_created(  current_time('mysql') );
225
+        }
226
+
227
+        // Ensure both the key and number are set.
228
+        $invoice->get_path();
229
+
230
+        // Grab the current status so we can compare.
231
+        $previous_status = get_post_status( $invoice->get_id() );
232
+
233
+        $changes = $invoice->get_changes();
234
+
235
+        // Only update the post when the post data changes.
236
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
237
+            $post_data = array(
238
+                'post_date'         => $invoice->get_date_created( 'edit' ),
239
+                'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
240
+                'post_status'       => $invoice->get_status( 'edit' ),
241
+                'post_title'        => $invoice->get_name( 'edit' ),
242
+                'post_author'       => $invoice->get_user_id( 'edit' ),
243
+                'post_modified'     => $invoice->get_date_modified( 'edit' ),
244
+                'post_excerpt'      => $invoice->get_description( 'edit' ),
245
+                'post_parent'       => $invoice->get_parent_id( 'edit' ),
246
+                'post_name'         => $invoice->get_path( 'edit' ),
247
+                'post_type'         => $invoice->get_post_type( 'edit' ),
248
+            );
249
+
250
+            /**
251
+             * When updating this object, to prevent infinite loops, use $wpdb
252
+             * to update data, since wp_update_post spawns more calls to the
253
+             * save_post action.
254
+             *
255
+             * This ensures hooks are fired by either WP itself (admin screen save),
256
+             * or an update purely from CRUD.
257
+             */
258
+            if ( doing_action( 'save_post' ) ) {
259
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
260
+                clean_post_cache( $invoice->get_id() );
261
+            } else {
262
+                wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
263
+            }
264
+            $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
265
+        }
266
+
267
+        // Update meta data.
268
+        $this->update_post_meta( $invoice );
269
+
270
+        // Save special fields and items.
271
+        $this->save_special_fields( $invoice );
272
+        $this->save_items( $invoice );
273
+
274
+        // Apply the changes.
275
+        $invoice->apply_changes();
276
+
277
+        // Clear caches.
278
+        $this->clear_caches( $invoice );
279
+
280
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
281
+        $new_status = $invoice->get_status( 'edit' );
282
+
283
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
284
+            do_action( 'getpaid_new_invoice', $invoice );
285
+        } else {
286
+            do_action( 'getpaid_update_invoice', $invoice );
287
+        }
288
+
289
+    }
290
+
291
+    /*
292 292
 	|--------------------------------------------------------------------------
293 293
 	| Additional Methods
294 294
 	|--------------------------------------------------------------------------
295 295
 	*/
296 296
 
297
-	/**
297
+    /**
298 298
      * Retrieves special fields and adds to the invoice.
299
-	 *
300
-	 * @param WPInv_Invoice $invoice Invoice object.
299
+     *
300
+     * @param WPInv_Invoice $invoice Invoice object.
301 301
      */
302 302
     public function add_special_fields( &$invoice ) {
303
-		global $wpdb;
303
+        global $wpdb;
304 304
 
305
-		// Maybe retrieve from the cache.
306
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
305
+        // Maybe retrieve from the cache.
306
+        $data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
307 307
 
308
-		// If not found, retrieve from the db.
309
-		if ( false === $data ) {
310
-			$table =  $wpdb->prefix . 'getpaid_invoices';
308
+        // If not found, retrieve from the db.
309
+        if ( false === $data ) {
310
+            $table =  $wpdb->prefix . 'getpaid_invoices';
311 311
 
312
-			$data  = $wpdb->get_row(
313
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
314
-				ARRAY_A
315
-			);
312
+            $data  = $wpdb->get_row(
313
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
314
+                ARRAY_A
315
+            );
316 316
 
317
-			// Update the cache with our data
318
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
317
+            // Update the cache with our data
318
+            wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
319 319
 
320
-		}
320
+        }
321 321
 
322
-		// Abort if the data does not exist.
323
-		if ( empty( $data ) ) {
324
-			$invoice->set_object_read( true );
325
-			$invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
326
-			return;
327
-		}
322
+        // Abort if the data does not exist.
323
+        if ( empty( $data ) ) {
324
+            $invoice->set_object_read( true );
325
+            $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
326
+            return;
327
+        }
328 328
 
329
-		$props = array();
329
+        $props = array();
330 330
 
331
-		foreach ( $this->database_fields_to_props as $db_field => $prop ) {
331
+        foreach ( $this->database_fields_to_props as $db_field => $prop ) {
332 332
 			
333
-			if ( $db_field == 'post_id' ) {
334
-				continue;
335
-			}
336
-
337
-			$props[ $prop ] = $data[ $db_field ];
338
-		}
339
-
340
-		$invoice->set_props( $props );
341
-
342
-	}
343
-
344
-	/**
345
-	 * Gets a list of special fields that need updated based on change state
346
-	 * or if they are present in the database or not.
347
-	 *
348
-	 * @param  WPInv_Invoice $invoice       The Invoice object.
349
-	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
350
-	 */
351
-	protected function get_special_fields_to_update( $invoice ) {
352
-		$fields_to_update = array();
353
-		$changed_props   = $invoice->get_changes();
354
-
355
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
356
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
357
-			if ( array_key_exists( $prop, $changed_props ) ) {
358
-				$fields_to_update[ $database_field ] = $prop;
359
-			}
360
-		}
361
-
362
-		return $fields_to_update;
363
-	}
364
-
365
-	/**
366
-	 * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
367
-	 *
368
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
369
-	 * @since 1.0.19
370
-	 */
371
-	protected function update_special_fields( &$invoice ) {
372
-		global $wpdb;
373
-
374
-		$updated_props    = array();
375
-		$fields_to_update = $this->get_special_fields_to_update( $invoice );
376
-
377
-		foreach ( $fields_to_update as $database_field => $prop ) {
378
-			$value = $invoice->{"get_$prop"}( 'edit' );
379
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
380
-			$value = is_bool( $value ) ? ( int ) $value : $value;
381
-			$updated_props[ $database_field ] = maybe_serialize( $value );
382
-		}
383
-
384
-		if ( ! empty( $updated_props ) ) {
385
-
386
-			$table = $wpdb->prefix . 'getpaid_invoices';
387
-			$wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
388
-			wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
389
-			do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
390
-
391
-		}
392
-
393
-	}
394
-
395
-	/**
396
-	 * Helper method that inserts special fields to the database.
397
-	 *
398
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
399
-	 * @since 1.0.19
400
-	 */
401
-	protected function insert_special_fields( &$invoice ) {
402
-		global $wpdb;
403
-
404
-		$updated_props   = array();
405
-
406
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
407
-			$value = $invoice->{"get_$prop"}( 'edit' );
408
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
409
-			$value = is_bool( $value ) ? ( int ) $value : $value;
410
-			$updated_props[ $database_field ] = maybe_serialize( $value );
411
-		}
412
-
413
-		$table = $wpdb->prefix . 'getpaid_invoices';
414
-		$wpdb->insert( $table, $updated_props );
415
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
416
-		do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
417
-
418
-	}
419
-
420
-	/**
333
+            if ( $db_field == 'post_id' ) {
334
+                continue;
335
+            }
336
+
337
+            $props[ $prop ] = $data[ $db_field ];
338
+        }
339
+
340
+        $invoice->set_props( $props );
341
+
342
+    }
343
+
344
+    /**
345
+     * Gets a list of special fields that need updated based on change state
346
+     * or if they are present in the database or not.
347
+     *
348
+     * @param  WPInv_Invoice $invoice       The Invoice object.
349
+     * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
350
+     */
351
+    protected function get_special_fields_to_update( $invoice ) {
352
+        $fields_to_update = array();
353
+        $changed_props   = $invoice->get_changes();
354
+
355
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
356
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
357
+            if ( array_key_exists( $prop, $changed_props ) ) {
358
+                $fields_to_update[ $database_field ] = $prop;
359
+            }
360
+        }
361
+
362
+        return $fields_to_update;
363
+    }
364
+
365
+    /**
366
+     * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
367
+     *
368
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
369
+     * @since 1.0.19
370
+     */
371
+    protected function update_special_fields( &$invoice ) {
372
+        global $wpdb;
373
+
374
+        $updated_props    = array();
375
+        $fields_to_update = $this->get_special_fields_to_update( $invoice );
376
+
377
+        foreach ( $fields_to_update as $database_field => $prop ) {
378
+            $value = $invoice->{"get_$prop"}( 'edit' );
379
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
380
+            $value = is_bool( $value ) ? ( int ) $value : $value;
381
+            $updated_props[ $database_field ] = maybe_serialize( $value );
382
+        }
383
+
384
+        if ( ! empty( $updated_props ) ) {
385
+
386
+            $table = $wpdb->prefix . 'getpaid_invoices';
387
+            $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
388
+            wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
389
+            do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
390
+
391
+        }
392
+
393
+    }
394
+
395
+    /**
396
+     * Helper method that inserts special fields to the database.
397
+     *
398
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
399
+     * @since 1.0.19
400
+     */
401
+    protected function insert_special_fields( &$invoice ) {
402
+        global $wpdb;
403
+
404
+        $updated_props   = array();
405
+
406
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
407
+            $value = $invoice->{"get_$prop"}( 'edit' );
408
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
409
+            $value = is_bool( $value ) ? ( int ) $value : $value;
410
+            $updated_props[ $database_field ] = maybe_serialize( $value );
411
+        }
412
+
413
+        $table = $wpdb->prefix . 'getpaid_invoices';
414
+        $wpdb->insert( $table, $updated_props );
415
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
416
+        do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
417
+
418
+    }
419
+
420
+    /**
421 421
      * Saves all special fields.
422
-	 *
423
-	 * @param WPInv_Invoice $invoice Invoice object.
422
+     *
423
+     * @param WPInv_Invoice $invoice Invoice object.
424 424
      */
425 425
     public function save_special_fields( & $invoice ) {
426
-		global $wpdb;
426
+        global $wpdb;
427 427
 
428
-		// The invoices table.
429
-		$table = $wpdb->prefix . 'getpaid_invoices';
430
-		$id    = (int) $invoice->get_id();
431
-		$invoice->maybe_set_key();
428
+        // The invoices table.
429
+        $table = $wpdb->prefix . 'getpaid_invoices';
430
+        $id    = (int) $invoice->get_id();
431
+        $invoice->maybe_set_key();
432 432
 
433
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
433
+        if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
434 434
 
435
-			$this->update_special_fields( $invoice );
435
+            $this->update_special_fields( $invoice );
436 436
 
437
-		} else {
437
+        } else {
438 438
 
439
-			$this->insert_special_fields( $invoice );
439
+            $this->insert_special_fields( $invoice );
440 440
 
441
-		}
441
+        }
442 442
 
443
-	}
443
+    }
444 444
 
445
-	/**
445
+    /**
446 446
      * Set's up cart details.
447
-	 *
448
-	 * @param WPInv_Invoice $invoice Invoice object.
447
+     *
448
+     * @param WPInv_Invoice $invoice Invoice object.
449 449
      */
450 450
     public function add_items( &$invoice ) {
451
-		global $wpdb;
451
+        global $wpdb;
452 452
 
453
-		// Maybe retrieve from the cache.
454
-		$items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
453
+        // Maybe retrieve from the cache.
454
+        $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
455 455
 
456
-		// If not found, retrieve from the db.
457
-		if ( false === $items ) {
458
-			$table =  $wpdb->prefix . 'getpaid_invoice_items';
456
+        // If not found, retrieve from the db.
457
+        if ( false === $items ) {
458
+            $table =  $wpdb->prefix . 'getpaid_invoice_items';
459 459
 
460
-			$items = $wpdb->get_results(
461
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
462
-			);
460
+            $items = $wpdb->get_results(
461
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
462
+            );
463 463
 
464
-			// Update the cache with our data
465
-			wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
464
+            // Update the cache with our data
465
+            wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
466 466
 
467
-		}
467
+        }
468 468
 
469
-		// Abort if no items found.
469
+        // Abort if no items found.
470 470
         if ( empty( $items ) ) {
471 471
             return;
472
-		}
472
+        }
473 473
 
474
-		foreach ( $items as $item_data ) {
475
-			$item = new GetPaid_Form_Item( $item_data->item_id );
474
+        foreach ( $items as $item_data ) {
475
+            $item = new GetPaid_Form_Item( $item_data->item_id );
476 476
 
477
-			// Set item data.
478
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
479
-			$item->item_discount = wpinv_sanitize_amount( $item_data->discount );
480
-			$item->set_name( $item_data->item_name );
481
-			$item->set_description( $item_data->item_description );
482
-			$item->set_price( $item_data->item_price );
483
-			$item->set_quantity( $item_data->quantity );
484
-			$item->set_item_meta( $item_data->meta );
477
+            // Set item data.
478
+            $item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
479
+            $item->item_discount = wpinv_sanitize_amount( $item_data->discount );
480
+            $item->set_name( $item_data->item_name );
481
+            $item->set_description( $item_data->item_description );
482
+            $item->set_price( $item_data->item_price );
483
+            $item->set_quantity( $item_data->quantity );
484
+            $item->set_item_meta( $item_data->meta );
485 485
 
486
-			$invoice->add_item( $item );
487
-		}
486
+            $invoice->add_item( $item );
487
+        }
488 488
 
489
-	}
489
+    }
490 490
 
491
-	/**
491
+    /**
492 492
      * Saves cart details.
493
-	 *
494
-	 * @param WPInv_Invoice $invoice Invoice object.
493
+     *
494
+     * @param WPInv_Invoice $invoice Invoice object.
495 495
      */
496 496
     public function save_items( $invoice ) {
497 497
 
498
-		// Delete previously existing items.
499
-		$this->delete_items( $invoice );
498
+        // Delete previously existing items.
499
+        $this->delete_items( $invoice );
500 500
 
501
-		$table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
501
+        $table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
502 502
 
503
-		foreach ( $invoice->get_cart_details() as $item_data ) {
504
-			$item_data = array_map( 'maybe_serialize', $item_data );
505
-			$GLOBALS['wpdb']->insert( $table, $item_data );
506
-		}
503
+        foreach ( $invoice->get_cart_details() as $item_data ) {
504
+            $item_data = array_map( 'maybe_serialize', $item_data );
505
+            $GLOBALS['wpdb']->insert( $table, $item_data );
506
+        }
507 507
 
508
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
509
-		do_action( "getpaid_invoice_save_items", $invoice );
508
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
509
+        do_action( "getpaid_invoice_save_items", $invoice );
510 510
 
511
-	}
511
+    }
512 512
 
513
-	/**
513
+    /**
514 514
      * Deletes an invoice's cart details from the database.
515
-	 *
516
-	 * @param WPInv_Invoice $invoice Invoice object.
515
+     *
516
+     * @param WPInv_Invoice $invoice Invoice object.
517 517
      */
518 518
     public function delete_items( $invoice ) {
519
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
520
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
521
-	}
519
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
520
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
521
+    }
522 522
 
523
-	/**
523
+    /**
524 524
      * Deletes an invoice's special fields from the database.
525
-	 *
526
-	 * @param WPInv_Invoice $invoice Invoice object.
525
+     *
526
+     * @param WPInv_Invoice $invoice Invoice object.
527 527
      */
528 528
     public function delete_special_fields( $invoice ) {
529
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
530
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
531
-	}
529
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
530
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
531
+    }
532 532
 	
533
-	/**
534
-	 * Get the status to save to the post object.
535
-	 *
536
-	 *
537
-	 * @since 1.0.19
538
-	 * @param  WPInv_Invoice $object GetPaid_Data object.
539
-	 * @return string
540
-	 */
541
-	protected function get_post_status( $object ) {
542
-		$object_status = $object->get_status( 'edit' );
543
-
544
-		if ( ! $object_status ) {
545
-			$object_status = $object->get_default_status();
546
-		}
547
-
548
-		return $object_status;
549
-	}
533
+    /**
534
+     * Get the status to save to the post object.
535
+     *
536
+     *
537
+     * @since 1.0.19
538
+     * @param  WPInv_Invoice $object GetPaid_Data object.
539
+     * @return string
540
+     */
541
+    protected function get_post_status( $object ) {
542
+        $object_status = $object->get_status( 'edit' );
543
+
544
+        if ( ! $object_status ) {
545
+            $object_status = $object->get_default_status();
546
+        }
547
+
548
+        return $object_status;
549
+    }
550 550
 
551 551
 }
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
141 141
  */
142 142
 function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
143
-	return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path );
143
+    return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path );
144 144
 }
145 145
 
146 146
 /**
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
  * @return string
159 159
  */
160 160
 function wpinv_get_theme_template_dir_name() {
161
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
161
+    return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
162 162
 }
163 163
 
164 164
 /**
@@ -175,122 +175,122 @@  discard block
 block discarded – undo
175 175
 }
176 176
 
177 177
 function wpinv_get_template_part( $slug, $name = null, $load = true ) {
178
-	do_action( 'get_template_part_' . $slug, $slug, $name );
178
+    do_action( 'get_template_part_' . $slug, $slug, $name );
179 179
 
180
-	// Setup possible parts
181
-	$templates = array();
182
-	if ( isset( $name ) )
183
-		$templates[] = $slug . '-' . $name . '.php';
184
-	$templates[] = $slug . '.php';
180
+    // Setup possible parts
181
+    $templates = array();
182
+    if ( isset( $name ) )
183
+        $templates[] = $slug . '-' . $name . '.php';
184
+    $templates[] = $slug . '.php';
185 185
 
186
-	// Allow template parts to be filtered
187
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
186
+    // Allow template parts to be filtered
187
+    $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
188 188
 
189
-	// Return the part that is found
190
-	return wpinv_locate_tmpl( $templates, $load, false );
189
+    // Return the part that is found
190
+    return wpinv_locate_tmpl( $templates, $load, false );
191 191
 }
192 192
 
193 193
 function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
194
-	// No file found yet
195
-	$located = false;
194
+    // No file found yet
195
+    $located = false;
196 196
 
197
-	// Try to find a template file
198
-	foreach ( (array)$template_names as $template_name ) {
197
+    // Try to find a template file
198
+    foreach ( (array)$template_names as $template_name ) {
199 199
 
200
-		// Continue if template is empty
201
-		if ( empty( $template_name ) )
202
-			continue;
200
+        // Continue if template is empty
201
+        if ( empty( $template_name ) )
202
+            continue;
203 203
 
204
-		// Trim off any slashes from the template name
205
-		$template_name = ltrim( $template_name, '/' );
204
+        // Trim off any slashes from the template name
205
+        $template_name = ltrim( $template_name, '/' );
206 206
 
207
-		// try locating this template file by looping through the template paths
208
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
207
+        // try locating this template file by looping through the template paths
208
+        foreach( wpinv_get_theme_template_paths() as $template_path ) {
209 209
 
210
-			if( file_exists( $template_path . $template_name ) ) {
211
-				$located = $template_path . $template_name;
212
-				break;
213
-			}
214
-		}
210
+            if( file_exists( $template_path . $template_name ) ) {
211
+                $located = $template_path . $template_name;
212
+                break;
213
+            }
214
+        }
215 215
 
216
-		if( !empty( $located ) ) {
217
-			break;
218
-		}
219
-	}
216
+        if( !empty( $located ) ) {
217
+            break;
218
+        }
219
+    }
220 220
 
221
-	if ( ( true == $load ) && ! empty( $located ) )
222
-		load_template( $located, $require_once );
221
+    if ( ( true == $load ) && ! empty( $located ) )
222
+        load_template( $located, $require_once );
223 223
 
224
-	return $located;
224
+    return $located;
225 225
 }
226 226
 
227 227
 function wpinv_get_theme_template_paths() {
228
-	$template_dir = wpinv_get_theme_template_dir_name();
228
+    $template_dir = wpinv_get_theme_template_dir_name();
229 229
 
230
-	$file_paths = array(
231
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
232
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
233
-		100 => wpinv_get_templates_dir()
234
-	);
230
+    $file_paths = array(
231
+        1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
232
+        10 => trailingslashit( get_template_directory() ) . $template_dir,
233
+        100 => wpinv_get_templates_dir()
234
+    );
235 235
 
236
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
236
+    $file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
237 237
 
238
-	// sort the file paths based on priority
239
-	ksort( $file_paths, SORT_NUMERIC );
238
+    // sort the file paths based on priority
239
+    ksort( $file_paths, SORT_NUMERIC );
240 240
 
241
-	return array_map( 'trailingslashit', $file_paths );
241
+    return array_map( 'trailingslashit', $file_paths );
242 242
 }
243 243
 
244 244
 function wpinv_checkout_meta_tags() {
245 245
 
246
-	$pages   = array();
247
-	$pages[] = wpinv_get_option( 'success_page' );
248
-	$pages[] = wpinv_get_option( 'failure_page' );
249
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
250
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
246
+    $pages   = array();
247
+    $pages[] = wpinv_get_option( 'success_page' );
248
+    $pages[] = wpinv_get_option( 'failure_page' );
249
+    $pages[] = wpinv_get_option( 'invoice_history_page' );
250
+    $pages[] = wpinv_get_option( 'invoice_subscription_page' );
251 251
 
252
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
253
-		return;
254
-	}
252
+    if( !wpinv_is_checkout() && !is_page( $pages ) ) {
253
+        return;
254
+    }
255 255
 
256
-	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
256
+    echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
257 257
 }
258 258
 add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
259 259
 
260 260
 function wpinv_add_body_classes( $class ) {
261
-	$classes = (array)$class;
261
+    $classes = (array)$class;
262 262
 
263
-	if( wpinv_is_checkout() ) {
264
-		$classes[] = 'wpinv-checkout';
265
-		$classes[] = 'wpinv-page';
266
-	}
263
+    if( wpinv_is_checkout() ) {
264
+        $classes[] = 'wpinv-checkout';
265
+        $classes[] = 'wpinv-page';
266
+    }
267 267
 
268
-	if( wpinv_is_success_page() ) {
269
-		$classes[] = 'wpinv-success';
270
-		$classes[] = 'wpinv-page';
271
-	}
268
+    if( wpinv_is_success_page() ) {
269
+        $classes[] = 'wpinv-success';
270
+        $classes[] = 'wpinv-page';
271
+    }
272 272
 
273
-	if( wpinv_is_failed_transaction_page() ) {
274
-		$classes[] = 'wpinv-failed-transaction';
275
-		$classes[] = 'wpinv-page';
276
-	}
273
+    if( wpinv_is_failed_transaction_page() ) {
274
+        $classes[] = 'wpinv-failed-transaction';
275
+        $classes[] = 'wpinv-page';
276
+    }
277 277
 
278
-	if( wpinv_is_invoice_history_page() ) {
279
-		$classes[] = 'wpinv-history';
280
-		$classes[] = 'wpinv-page';
281
-	}
278
+    if( wpinv_is_invoice_history_page() ) {
279
+        $classes[] = 'wpinv-history';
280
+        $classes[] = 'wpinv-page';
281
+    }
282 282
 
283
-	if( wpinv_is_subscriptions_history_page() ) {
284
-		$classes[] = 'wpinv-subscription';
285
-		$classes[] = 'wpinv-page';
286
-	}
283
+    if( wpinv_is_subscriptions_history_page() ) {
284
+        $classes[] = 'wpinv-subscription';
285
+        $classes[] = 'wpinv-page';
286
+    }
287 287
 
288
-	if( wpinv_is_test_mode() ) {
289
-		$classes[] = 'wpinv-test-mode';
290
-		$classes[] = 'wpinv-page';
291
-	}
288
+    if( wpinv_is_test_mode() ) {
289
+        $classes[] = 'wpinv-test-mode';
290
+        $classes[] = 'wpinv-page';
291
+    }
292 292
 
293
-	return array_unique( $classes );
293
+    return array_unique( $classes );
294 294
 }
295 295
 add_filter( 'body_class', 'wpinv_add_body_classes' );
296 296
 
@@ -859,21 +859,21 @@  discard block
 block discarded – undo
859 859
 
860 860
     $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
861 861
     
862
-	// Remove unavailable tags.
862
+    // Remove unavailable tags.
863 863
     $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address );
864 864
 
865 865
     // Clean up white space.
866
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
866
+    $formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
867 867
     $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
868 868
     
869 869
     // Break newlines apart and remove empty lines/trim commas and white space.
870
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
870
+    $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
871 871
 
872 872
     // Add html breaks.
873
-	$formatted_address = implode( $separator, $formatted_address );
873
+    $formatted_address = implode( $separator, $formatted_address );
874 874
 
875
-	// We're done!
876
-	return $formatted_address;
875
+    // We're done!
876
+    return $formatted_address;
877 877
     
878 878
 }
879 879
 
@@ -1075,7 +1075,7 @@  discard block
 block discarded – undo
1075 1075
 }
1076 1076
 
1077 1077
 function wpinv_empty_cart_message() {
1078
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1078
+    return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1079 1079
 }
1080 1080
 
1081 1081
 /**
@@ -1343,10 +1343,10 @@  discard block
 block discarded – undo
1343 1343
 
1344 1344
     if ( 0 == count( $form->get_items() ) ) {
1345 1345
         echo aui()->alert(
1346
-			array(
1347
-				'type'    => 'warning',
1348
-				'content' => __( 'No published items found', 'invoicing' ),
1349
-			)
1346
+            array(
1347
+                'type'    => 'warning',
1348
+                'content' => __( 'No published items found', 'invoicing' ),
1349
+            )
1350 1350
         );
1351 1351
         return;
1352 1352
     }
@@ -1364,21 +1364,21 @@  discard block
 block discarded – undo
1364 1364
     $invoice = wpinv_get_invoice( $invoice_id );
1365 1365
 
1366 1366
     if ( empty( $invoice ) ) {
1367
-		echo aui()->alert(
1368
-			array(
1369
-				'type'    => 'warning',
1370
-				'content' => __( 'Invoice not found', 'invoicing' ),
1371
-			)
1367
+        echo aui()->alert(
1368
+            array(
1369
+                'type'    => 'warning',
1370
+                'content' => __( 'Invoice not found', 'invoicing' ),
1371
+            )
1372 1372
         );
1373 1373
         return;
1374 1374
     }
1375 1375
 
1376 1376
     if ( $invoice->is_paid() ) {
1377
-		echo aui()->alert(
1378
-			array(
1379
-				'type'    => 'warning',
1380
-				'content' => __( 'Invoice has already been paid', 'invoicing' ),
1381
-			)
1377
+        echo aui()->alert(
1378
+            array(
1379
+                'type'    => 'warning',
1380
+                'content' => __( 'Invoice has already been paid', 'invoicing' ),
1381
+            )
1382 1382
         );
1383 1383
         return;
1384 1384
     }
@@ -1440,7 +1440,7 @@  discard block
 block discarded – undo
1440 1440
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; 
1441 1441
     }
1442 1442
 	
1443
-	if ( ! empty( $items ) ) {
1443
+    if ( ! empty( $items ) ) {
1444 1444
         $items  = esc_attr( $items );
1445 1445
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; 
1446 1446
     }
Please login to merge, or discard this patch.
ayecode/wp-ayecode-ui/includes/components/class-aui-component-input.php 1 patch
Indentation   +1002 added lines, -1002 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined( 'ABSPATH' ) ) {
4
-	exit; // Exit if accessed directly
4
+    exit; // Exit if accessed directly
5 5
 }
6 6
 
7 7
 /**
@@ -11,1012 +11,1012 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class AUI_Component_Input {
13 13
 
14
-	/**
15
-	 * Build the component.
16
-	 *
17
-	 * @param array $args
18
-	 *
19
-	 * @return string The rendered component.
20
-	 */
21
-	public static function input($args = array()){
22
-		$defaults = array(
23
-			'type'       => 'text',
24
-			'name'       => '',
25
-			'class'      => '',
26
-			'wrap_class' => '',
27
-			'id'         => '',
28
-			'placeholder'=> '',
29
-			'title'      => '',
30
-			'value'      => '',
31
-			'required'   => false,
32
-			'label'      => '',
33
-			'label_after'=> false,
34
-			'label_class'=> '',
35
-			'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
36
-			'help_text'  => '',
37
-			'validation_text'   => '',
38
-			'validation_pattern' => '',
39
-			'no_wrap'    => false,
40
-			'input_group_right' => '',
41
-			'input_group_left' => '',
42
-			'input_group_right_inside' => false, // forces the input group inside the input
43
-			'input_group_left_inside' => false, // forces the input group inside the input
44
-			'step'       => '',
45
-			'switch'     => false, // to show checkbox as a switch
46
-			'checked'   => false, // set a checkbox or radio as selected
47
-			'password_toggle' => true, // toggle view/hide password
48
-			'element_require'   => '', // [%element_id%] == "1"
49
-			'extra_attributes'  => array() // an array of extra attributes
50
-		);
51
-
52
-		/**
53
-		 * Parse incoming $args into an array and merge it with $defaults
54
-		 */
55
-		$args   = wp_parse_args( $args, $defaults );
56
-		$output = '';
57
-		if ( ! empty( $args['type'] ) ) {
58
-			// hidden label option needs to be empty
59
-			$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
60
-
61
-			$type = sanitize_html_class( $args['type'] );
62
-
63
-			$help_text = '';
64
-			$label = '';
65
-			$label_after = $args['label_after'];
66
-			$label_args = array(
67
-				'title'=> $args['label'],
68
-				'for'=> $args['id'],
69
-				'class' => $args['label_class']." ",
70
-				'label_type' => $args['label_type']
71
-			);
72
-
73
-			// floating labels need label after
74
-			if( $args['label_type'] == 'floating' && $type != 'checkbox' ){
75
-				$label_after = true;
76
-				$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
77
-			}
78
-
79
-			// Some special sauce for files
80
-			if($type=='file' ){
81
-				$label_after = true; // if type file we need the label after
82
-				$args['class'] .= ' custom-file-input ';
83
-			}elseif($type=='checkbox'){
84
-				$label_after = true; // if type file we need the label after
85
-				$args['class'] .= ' custom-control-input ';
86
-			}elseif($type=='datepicker' || $type=='timepicker'){
87
-				$type = 'text';
88
-				//$args['class'] .= ' aui-flatpickr bg-initial ';
89
-				$args['class'] .= ' bg-initial ';
90
-
91
-				$args['extra_attributes']['data-aui-init'] = 'flatpickr';
92
-				// enqueue the script
93
-				$aui_settings = AyeCode_UI_Settings::instance();
94
-				$aui_settings->enqueue_flatpickr();
95
-			}
96
-
97
-
98
-			// open/type
99
-			$output .= '<input type="' . $type . '" ';
100
-
101
-			// name
102
-			if(!empty($args['name'])){
103
-				$output .= ' name="'.esc_attr($args['name']).'" ';
104
-			}
105
-
106
-			// id
107
-			if(!empty($args['id'])){
108
-				$output .= ' id="'.sanitize_html_class($args['id']).'" ';
109
-			}
110
-
111
-			// placeholder
112
-			if(isset($args['placeholder']) && '' != $args['placeholder'] ){
113
-				$output .= ' placeholder="'.esc_attr($args['placeholder']).'" ';
114
-			}
115
-
116
-			// title
117
-			if(!empty($args['title'])){
118
-				$output .= ' title="'.esc_attr($args['title']).'" ';
119
-			}
120
-
121
-			// value
122
-			if(!empty($args['value'])){
123
-				$output .= ' value="'.sanitize_text_field($args['value']).'" ';
124
-			}
125
-
126
-			// checked, for radio and checkboxes
127
-			if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){
128
-				$output .= ' checked ';
129
-			}
130
-
131
-			// validation text
132
-			if(!empty($args['validation_text'])){
133
-				$output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" ';
134
-				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
135
-			}
136
-
137
-			// validation_pattern
138
-			if(!empty($args['validation_pattern'])){
139
-				$output .= ' pattern="'.$args['validation_pattern'].'" ';
140
-			}
141
-
142
-			// step (for numbers)
143
-			if(!empty($args['step'])){
144
-				$output .= ' step="'.$args['step'].'" ';
145
-			}
146
-
147
-			// required
148
-			if(!empty($args['required'])){
149
-				$output .= ' required ';
150
-			}
151
-
152
-			// class
153
-			$class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
154
-			$output .= ' class="form-control '.$class.'" ';
155
-
156
-			// data-attributes
157
-			$output .= AUI_Component_Helper::data_attributes($args);
158
-
159
-			// extra attributes
160
-			if(!empty($args['extra_attributes'])){
161
-				$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
162
-			}
163
-
164
-			// close
165
-			$output .= ' >';
166
-
167
-
168
-			// label
169
-			if(!empty($args['label'])){
170
-				if($type == 'file'){$label_args['class'] .= 'custom-file-label';}
171
-				elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';}
172
-				$label = self::label( $label_args, $type );
173
-			}
174
-
175
-			// help text
176
-			if(!empty($args['help_text'])){
177
-				$help_text = AUI_Component_Helper::help_text($args['help_text']);
178
-			}
179
-
180
-
181
-			// set help text in the correct possition
182
-			if($label_after){
183
-				$output .= $label . $help_text;
184
-			}
185
-
186
-			// some input types need a separate wrap
187
-			if($type == 'file') {
188
-				$output = self::wrap( array(
189
-					'content' => $output,
190
-					'class'   => 'form-group custom-file'
191
-				) );
192
-			}elseif($type == 'checkbox'){
193
-				$wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox';
194
-				$output = self::wrap( array(
195
-					'content' => $output,
196
-					'class'   => 'custom-control '.$wrap_class
197
-				) );
198
-
199
-				if($args['label_type']=='horizontal'){
200
-					$output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>';
201
-				}
202
-			}elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){
203
-
204
-
205
-				// allow password field to toggle view
206
-				$args['input_group_right'] = '<span class="input-group-text c-pointer px-3" 
14
+    /**
15
+     * Build the component.
16
+     *
17
+     * @param array $args
18
+     *
19
+     * @return string The rendered component.
20
+     */
21
+    public static function input($args = array()){
22
+        $defaults = array(
23
+            'type'       => 'text',
24
+            'name'       => '',
25
+            'class'      => '',
26
+            'wrap_class' => '',
27
+            'id'         => '',
28
+            'placeholder'=> '',
29
+            'title'      => '',
30
+            'value'      => '',
31
+            'required'   => false,
32
+            'label'      => '',
33
+            'label_after'=> false,
34
+            'label_class'=> '',
35
+            'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
36
+            'help_text'  => '',
37
+            'validation_text'   => '',
38
+            'validation_pattern' => '',
39
+            'no_wrap'    => false,
40
+            'input_group_right' => '',
41
+            'input_group_left' => '',
42
+            'input_group_right_inside' => false, // forces the input group inside the input
43
+            'input_group_left_inside' => false, // forces the input group inside the input
44
+            'step'       => '',
45
+            'switch'     => false, // to show checkbox as a switch
46
+            'checked'   => false, // set a checkbox or radio as selected
47
+            'password_toggle' => true, // toggle view/hide password
48
+            'element_require'   => '', // [%element_id%] == "1"
49
+            'extra_attributes'  => array() // an array of extra attributes
50
+        );
51
+
52
+        /**
53
+         * Parse incoming $args into an array and merge it with $defaults
54
+         */
55
+        $args   = wp_parse_args( $args, $defaults );
56
+        $output = '';
57
+        if ( ! empty( $args['type'] ) ) {
58
+            // hidden label option needs to be empty
59
+            $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
60
+
61
+            $type = sanitize_html_class( $args['type'] );
62
+
63
+            $help_text = '';
64
+            $label = '';
65
+            $label_after = $args['label_after'];
66
+            $label_args = array(
67
+                'title'=> $args['label'],
68
+                'for'=> $args['id'],
69
+                'class' => $args['label_class']." ",
70
+                'label_type' => $args['label_type']
71
+            );
72
+
73
+            // floating labels need label after
74
+            if( $args['label_type'] == 'floating' && $type != 'checkbox' ){
75
+                $label_after = true;
76
+                $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
77
+            }
78
+
79
+            // Some special sauce for files
80
+            if($type=='file' ){
81
+                $label_after = true; // if type file we need the label after
82
+                $args['class'] .= ' custom-file-input ';
83
+            }elseif($type=='checkbox'){
84
+                $label_after = true; // if type file we need the label after
85
+                $args['class'] .= ' custom-control-input ';
86
+            }elseif($type=='datepicker' || $type=='timepicker'){
87
+                $type = 'text';
88
+                //$args['class'] .= ' aui-flatpickr bg-initial ';
89
+                $args['class'] .= ' bg-initial ';
90
+
91
+                $args['extra_attributes']['data-aui-init'] = 'flatpickr';
92
+                // enqueue the script
93
+                $aui_settings = AyeCode_UI_Settings::instance();
94
+                $aui_settings->enqueue_flatpickr();
95
+            }
96
+
97
+
98
+            // open/type
99
+            $output .= '<input type="' . $type . '" ';
100
+
101
+            // name
102
+            if(!empty($args['name'])){
103
+                $output .= ' name="'.esc_attr($args['name']).'" ';
104
+            }
105
+
106
+            // id
107
+            if(!empty($args['id'])){
108
+                $output .= ' id="'.sanitize_html_class($args['id']).'" ';
109
+            }
110
+
111
+            // placeholder
112
+            if(isset($args['placeholder']) && '' != $args['placeholder'] ){
113
+                $output .= ' placeholder="'.esc_attr($args['placeholder']).'" ';
114
+            }
115
+
116
+            // title
117
+            if(!empty($args['title'])){
118
+                $output .= ' title="'.esc_attr($args['title']).'" ';
119
+            }
120
+
121
+            // value
122
+            if(!empty($args['value'])){
123
+                $output .= ' value="'.sanitize_text_field($args['value']).'" ';
124
+            }
125
+
126
+            // checked, for radio and checkboxes
127
+            if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){
128
+                $output .= ' checked ';
129
+            }
130
+
131
+            // validation text
132
+            if(!empty($args['validation_text'])){
133
+                $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" ';
134
+                $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
135
+            }
136
+
137
+            // validation_pattern
138
+            if(!empty($args['validation_pattern'])){
139
+                $output .= ' pattern="'.$args['validation_pattern'].'" ';
140
+            }
141
+
142
+            // step (for numbers)
143
+            if(!empty($args['step'])){
144
+                $output .= ' step="'.$args['step'].'" ';
145
+            }
146
+
147
+            // required
148
+            if(!empty($args['required'])){
149
+                $output .= ' required ';
150
+            }
151
+
152
+            // class
153
+            $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
154
+            $output .= ' class="form-control '.$class.'" ';
155
+
156
+            // data-attributes
157
+            $output .= AUI_Component_Helper::data_attributes($args);
158
+
159
+            // extra attributes
160
+            if(!empty($args['extra_attributes'])){
161
+                $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
162
+            }
163
+
164
+            // close
165
+            $output .= ' >';
166
+
167
+
168
+            // label
169
+            if(!empty($args['label'])){
170
+                if($type == 'file'){$label_args['class'] .= 'custom-file-label';}
171
+                elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';}
172
+                $label = self::label( $label_args, $type );
173
+            }
174
+
175
+            // help text
176
+            if(!empty($args['help_text'])){
177
+                $help_text = AUI_Component_Helper::help_text($args['help_text']);
178
+            }
179
+
180
+
181
+            // set help text in the correct possition
182
+            if($label_after){
183
+                $output .= $label . $help_text;
184
+            }
185
+
186
+            // some input types need a separate wrap
187
+            if($type == 'file') {
188
+                $output = self::wrap( array(
189
+                    'content' => $output,
190
+                    'class'   => 'form-group custom-file'
191
+                ) );
192
+            }elseif($type == 'checkbox'){
193
+                $wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox';
194
+                $output = self::wrap( array(
195
+                    'content' => $output,
196
+                    'class'   => 'custom-control '.$wrap_class
197
+                ) );
198
+
199
+                if($args['label_type']=='horizontal'){
200
+                    $output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>';
201
+                }
202
+            }elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){
203
+
204
+
205
+                // allow password field to toggle view
206
+                $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" 
207 207
 onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\');
208 208
 var $eli = jQuery(this).parent().parent().find(\'input\');
209 209
 if($el.hasClass(\'fa-eye\'))
210 210
 {$eli.attr(\'type\',\'text\');}
211 211
 else{$eli.attr(\'type\',\'password\');}"
212 212
 ><i class="far fa-fw fa-eye-slash"></i></span>';
213
-			}
214
-
215
-			// input group wraps
216
-			if($args['input_group_left'] || $args['input_group_right']){
217
-				$w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : '';
218
-				if($args['input_group_left']){
219
-					$output = self::wrap( array(
220
-						'content' => $output,
221
-						'class'   => $args['input_group_left_inside'] ? 'input-group-inside position-relative'.$w100  : 'input-group',
222
-						'input_group_left' => $args['input_group_left'],
223
-						'input_group_left_inside'    => $args['input_group_left_inside']
224
-					) );
225
-				}
226
-				if($args['input_group_right']){
227
-					$output = self::wrap( array(
228
-						'content' => $output,
229
-						'class'   => $args['input_group_right_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group',
230
-						'input_group_right' => $args['input_group_right'],
231
-						'input_group_right_inside'    => $args['input_group_right_inside']
232
-					) );
233
-				}
234
-
235
-			}
236
-
237
-			if(!$label_after){
238
-				$output .= $help_text;
239
-			}
240
-
241
-
242
-			if($args['label_type']=='horizontal' && $type != 'checkbox'){
243
-				$output = self::wrap( array(
244
-					'content' => $output,
245
-					'class'   => 'col-sm-10',
246
-				) );
247
-			}
248
-
249
-			if(!$label_after){
250
-				$output = $label . $output;
251
-			}
252
-
253
-			// wrap
254
-			if(!$args['no_wrap']){
255
-
256
-				$form_group_class = $args['label_type']=='floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group';
257
-				$wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class;
258
-				$wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class;
259
-				$output = self::wrap(array(
260
-					'content' => $output,
261
-					'class'   => $wrap_class,
262
-					'element_require'   => $args['element_require'],
263
-					'argument_id'  => $args['id']
264
-				));
265
-			}
266
-
267
-
268
-
269
-		}
270
-
271
-		return $output;
272
-	}
273
-
274
-	/**
275
-	 * Build the component.
276
-	 *
277
-	 * @param array $args
278
-	 *
279
-	 * @return string The rendered component.
280
-	 */
281
-	public static function textarea($args = array()){
282
-		$defaults = array(
283
-			'name'       => '',
284
-			'class'      => '',
285
-			'wrap_class' => '',
286
-			'id'         => '',
287
-			'placeholder'=> '',
288
-			'title'      => '',
289
-			'value'      => '',
290
-			'required'   => false,
291
-			'label'      => '',
292
-			'label_after'=> false,
293
-			'label_class'      => '',
294
-			'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
295
-			'help_text'  => '',
296
-			'validation_text'   => '',
297
-			'validation_pattern' => '',
298
-			'no_wrap'    => false,
299
-			'rows'      => '',
300
-			'wysiwyg'   => false,
301
-			'element_require'   => '', // [%element_id%] == "1"
302
-		);
303
-
304
-		/**
305
-		 * Parse incoming $args into an array and merge it with $defaults
306
-		 */
307
-		$args   = wp_parse_args( $args, $defaults );
308
-		$output = '';
309
-
310
-		// hidden label option needs to be empty
311
-		$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
312
-
313
-		// floating labels don't work with wysiwyg so set it as top
314
-		if($args['label_type'] == 'floating' && !empty($args['wysiwyg'])){
315
-			$args['label_type'] = 'top';
316
-		}
317
-
318
-		$label_after = $args['label_after'];
319
-
320
-		// floating labels need label after
321
-		if( $args['label_type'] == 'floating' && empty($args['wysiwyg']) ){
322
-			$label_after = true;
323
-			$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
324
-		}
325
-
326
-		// label
327
-		if(!empty($args['label']) && is_array($args['label'])){
328
-		}elseif(!empty($args['label']) && !$label_after){
329
-			$label_args = array(
330
-				'title'=> $args['label'],
331
-				'for'=> $args['id'],
332
-				'class' => $args['label_class']." ",
333
-				'label_type' => $args['label_type']
334
-			);
335
-			$output .= self::label( $label_args );
336
-		}
337
-
338
-		// maybe horizontal label
339
-		if($args['label_type']=='horizontal'){
340
-			$output .= '<div class="col-sm-10">';
341
-		}
342
-
343
-		if(!empty($args['wysiwyg'])){
344
-			ob_start();
345
-			$content = $args['value'];
346
-			$editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor';
347
-			$settings = array(
348
-				'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4,
349
-				'quicktags'     => false,
350
-				'media_buttons' => false,
351
-				'editor_class'  => 'form-control',
352
-				'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']),
353
-				'teeny'         => true,
354
-			);
355
-
356
-			// maybe set settings if array
357
-			if(is_array($args['wysiwyg'])){
358
-				$settings  = wp_parse_args( $args['wysiwyg'], $settings );
359
-			}
360
-
361
-			wp_editor( $content, $editor_id, $settings );
362
-			$output .= ob_get_clean();
363
-		}else{
364
-
365
-			// open
366
-			$output .= '<textarea ';
367
-
368
-			// name
369
-			if(!empty($args['name'])){
370
-				$output .= ' name="'.sanitize_html_class($args['name']).'" ';
371
-			}
372
-
373
-			// id
374
-			if(!empty($args['id'])){
375
-				$output .= ' id="'.sanitize_html_class($args['id']).'" ';
376
-			}
377
-
378
-			// placeholder
379
-			if(isset($args['placeholder']) && '' != $args['placeholder']){
380
-				$output .= ' placeholder="'.esc_attr($args['placeholder']).'" ';
381
-			}
382
-
383
-			// title
384
-			if(!empty($args['title'])){
385
-				$output .= ' title="'.esc_attr($args['title']).'" ';
386
-			}
387
-
388
-			// validation text
389
-			if(!empty($args['validation_text'])){
390
-				$output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" ';
391
-				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
392
-			}
393
-
394
-			// validation_pattern
395
-			if(!empty($args['validation_pattern'])){
396
-				$output .= ' pattern="'.$args['validation_pattern'].'" ';
397
-			}
398
-
399
-			// required
400
-			if(!empty($args['required'])){
401
-				$output .= ' required ';
402
-			}
403
-
404
-			// rows
405
-			if(!empty($args['rows'])){
406
-				$output .= ' rows="'.absint($args['rows']).'" ';
407
-			}
408
-
409
-
410
-			// class
411
-			$class = !empty($args['class']) ? $args['class'] : '';
412
-			$output .= ' class="form-control '.$class.'" ';
413
-
414
-
415
-			// close tag
416
-			$output .= ' >';
417
-
418
-			// value
419
-			if(!empty($args['value'])){
420
-				$output .= sanitize_textarea_field($args['value']);
421
-			}
422
-
423
-			// closing tag
424
-			$output .= '</textarea>';
425
-
426
-		}
427
-
428
-		if(!empty($args['label']) && $label_after){
429
-			$label_args = array(
430
-				'title'=> $args['label'],
431
-				'for'=> $args['id'],
432
-				'class' => $args['label_class']." ",
433
-				'label_type' => $args['label_type']
434
-			);
435
-			$output .= self::label( $label_args );
436
-		}
437
-
438
-		// help text
439
-		if(!empty($args['help_text'])){
440
-			$output .= AUI_Component_Helper::help_text($args['help_text']);
441
-		}
442
-
443
-		// maybe horizontal label
444
-		if($args['label_type']=='horizontal'){
445
-			$output .= '</div>';
446
-		}
447
-
448
-
449
-		// wrap
450
-		if(!$args['no_wrap']){
451
-			$form_group_class = $args['label_type']=='floating' ? 'form-label-group' : 'form-group';
452
-			$wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class;
453
-			$wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class;
454
-			$output = self::wrap(array(
455
-				'content' => $output,
456
-				'class'   => $wrap_class,
457
-				'element_require'   => $args['element_require'],
458
-				'argument_id'  => $args['id']
459
-			));
460
-		}
461
-
462
-
463
-		return $output;
464
-	}
465
-
466
-	public static function label($args = array(), $type = ''){
467
-		//<label for="exampleInputEmail1">Email address</label>
468
-		$defaults = array(
469
-			'title'       => 'div',
470
-			'for'      => '',
471
-			'class'      => '',
472
-			'label_type'    => '', // empty = hidden, top, horizontal
473
-		);
474
-
475
-		/**
476
-		 * Parse incoming $args into an array and merge it with $defaults
477
-		 */
478
-		$args   = wp_parse_args( $args, $defaults );
479
-		$output = '';
480
-
481
-		if($args['title']){
482
-
483
-			// maybe hide labels //@todo set a global option for visibility class
484
-			if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){
485
-				$class = $args['class'];
486
-			}else{
487
-				$class = 'sr-only '.$args['class'];
488
-			}
489
-
490
-			// maybe horizontal
491
-			if($args['label_type']=='horizontal' && $type != 'checkbox'){
492
-				$class .= ' col-sm-2 col-form-label';
493
-			}
494
-
495
-			// open
496
-			$output .= '<label ';
497
-
498
-			// for
499
-			if(!empty($args['for'])){
500
-				$output .= ' for="'.sanitize_text_field($args['for']).'" ';
501
-			}
502
-
503
-			// class
504
-			$class = $class ? AUI_Component_Helper::esc_classes( $class ) : '';
505
-			$output .= ' class="'.$class.'" ';
506
-
507
-			// close
508
-			$output .= '>';
509
-
510
-
511
-			// title, don't escape fully as can contain html
512
-			if(!empty($args['title'])){
513
-				$output .= wp_kses_post($args['title']);
514
-			}
515
-
516
-			// close wrap
517
-			$output .= '</label>';
518
-
519
-
520
-		}
521
-
522
-
523
-		return $output;
524
-	}
525
-
526
-	/**
527
-	 * Wrap some content in a HTML wrapper.
528
-	 *
529
-	 * @param array $args
530
-	 *
531
-	 * @return string
532
-	 */
533
-	public static function wrap($args = array()){
534
-		$defaults = array(
535
-			'type'       => 'div',
536
-			'class'      => 'form-group',
537
-			'content'   => '',
538
-			'input_group_left' => '',
539
-			'input_group_right' => '',
540
-			'input_group_left_inside' => false,
541
-			'input_group_right_inside' => false,
542
-			'element_require'   => '',
543
-			'argument_id'   => '',
544
-		);
545
-
546
-		/**
547
-		 * Parse incoming $args into an array and merge it with $defaults
548
-		 */
549
-		$args   = wp_parse_args( $args, $defaults );
550
-		$output = '';
551
-		if($args['type']){
552
-
553
-			// open
554
-			$output .= '<'.sanitize_html_class($args['type']);
555
-
556
-			// element require
557
-			if(!empty($args['element_require'])){
558
-				$output .= AUI_Component_Helper::element_require($args['element_require']);
559
-				$args['class'] .= " aui-conditional-field";
560
-			}
561
-
562
-			// argument_id
563
-			if( !empty($args['argument_id']) ){
564
-				$output .= ' data-argument="'.esc_attr($args['argument_id']).'"';
565
-			}
566
-
567
-			// class
568
-			$class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
569
-			$output .= ' class="'.$class.'" ';
570
-
571
-			// close wrap
572
-			$output .= ' >';
573
-
574
-
575
-			// Input group left
576
-			if(!empty($args['input_group_left'])){
577
-				$position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : '';
578
-				$input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>';
579
-				$output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>';
580
-			}
581
-
582
-			// content
583
-			$output .= $args['content'];
584
-
585
-			// Input group right
586
-			if(!empty($args['input_group_right'])){
587
-				$position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : '';
588
-				$input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>';
589
-				$output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>';
590
-			}
591
-
592
-
593
-			// close wrap
594
-			$output .= '</'.sanitize_html_class($args['type']).'>';
595
-
596
-
597
-		}else{
598
-			$output = $args['content'];
599
-		}
600
-
601
-		return $output;
602
-	}
603
-
604
-	/**
605
-	 * Build the component.
606
-	 *
607
-	 * @param array $args
608
-	 *
609
-	 * @return string The rendered component.
610
-	 */
611
-	public static function select($args = array()){
612
-		$defaults = array(
613
-			'class'      => '',
614
-			'wrap_class' => '',
615
-			'id'         => '',
616
-			'title'      => '',
617
-			'value'      => '', // can be an array or a string
618
-			'required'   => false,
619
-			'label'      => '',
620
-			'label_after'=> false,
621
-			'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
622
-			'label_class'      => '',
623
-			'help_text'  => '',
624
-			'placeholder'=> '',
625
-			'options'    => array(), // array or string
626
-			'icon'       => '',
627
-			'multiple'   => false,
628
-			'select2'    => false,
629
-			'no_wrap'    => false,
630
-			'element_require'   => '', // [%element_id%] == "1"
631
-			'extra_attributes'  => array(), // an array of extra attributes
632
-		);
633
-
634
-		/**
635
-		 * Parse incoming $args into an array and merge it with $defaults
636
-		 */
637
-		$args   = wp_parse_args( $args, $defaults );
638
-		$output = '';
639
-
640
-		// for now lets hide floating labels
641
-		if( $args['label_type'] == 'floating' ){$args['label_type'] = 'hidden';}
642
-
643
-		// hidden label option needs to be empty
644
-		$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
645
-
646
-
647
-		$label_after = $args['label_after'];
648
-
649
-		// floating labels need label after
650
-		if( $args['label_type'] == 'floating' ){
651
-			$label_after = true;
652
-			$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
653
-		}
654
-
655
-		// Maybe setup select2
656
-		$is_select2 = false;
657
-		if(!empty($args['select2'])){
658
-			$args['class'] .= ' aui-select2';
659
-			$is_select2 = true;
660
-		}elseif( strpos($args['class'], 'aui-select2') !== false){
661
-			$is_select2 = true;
662
-		}
663
-
664
-		// select2 tags
665
-		if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equals needed here for some reason
666
-			$args['data-tags'] = 'true';
667
-			$args['data-token-separators'] = "[',']";
668
-			$args['multiple'] = true;
669
-		}
670
-
671
-		// select2 placeholder
672
-		if($is_select2 && isset($args['placeholder']) && '' != $args['placeholder'] && empty($args['data-placeholder'])){
673
-			$args['data-placeholder'] = esc_attr($args['placeholder']);
674
-			$args['data-allow-clear'] = isset($args['data-allow-clear']) ? (bool) $args['data-allow-clear'] : true;
675
-		}
676
-
677
-		// label
678
-		if(!empty($args['label']) && is_array($args['label'])){
679
-		}elseif(!empty($args['label']) && !$label_after){
680
-			$label_args = array(
681
-				'title'=> $args['label'],
682
-				'for'=> $args['id'],
683
-				'class' => $args['label_class']." ",
684
-				'label_type' => $args['label_type']
685
-			);
686
-			$output .= self::label($label_args);
687
-		}
688
-
689
-		// maybe horizontal label
690
-		if($args['label_type']=='horizontal'){
691
-			$output .= '<div class="col-sm-10">';
692
-		}
693
-
694
-		// open/type
695
-		$output .= '<select ';
696
-
697
-		// style
698
-		if($is_select2){
699
-			$output .= " style='width:100%;' ";
700
-		}
701
-
702
-		// element require
703
-		if(!empty($args['element_require'])){
704
-			$output .= AUI_Component_Helper::element_require($args['element_require']);
705
-			$args['class'] .= " aui-conditional-field";
706
-		}
707
-
708
-		// class
709
-		$class = !empty($args['class']) ? $args['class'] : '';
710
-		$output .= AUI_Component_Helper::class_attr('custom-select '.$class);
711
-
712
-		// name
713
-		if(!empty($args['name'])){
714
-			$output .= AUI_Component_Helper::name($args['name'],$args['multiple']);
715
-		}
716
-
717
-		// id
718
-		if(!empty($args['id'])){
719
-			$output .= AUI_Component_Helper::id($args['id']);
720
-		}
721
-
722
-		// title
723
-		if(!empty($args['title'])){
724
-			$output .= AUI_Component_Helper::title($args['title']);
725
-		}
726
-
727
-		// data-attributes
728
-		$output .= AUI_Component_Helper::data_attributes($args);
729
-
730
-		// aria-attributes
731
-		$output .= AUI_Component_Helper::aria_attributes($args);
732
-
733
-		// extra attributes
734
-		if(!empty($args['extra_attributes'])){
735
-			$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
736
-		}
737
-
738
-		// required
739
-		if(!empty($args['required'])){
740
-			$output .= ' required ';
741
-		}
742
-
743
-		// multiple
744
-		if(!empty($args['multiple'])){
745
-			$output .= ' multiple ';
746
-		}
747
-
748
-		// close opening tag
749
-		$output .= ' >';
750
-
751
-		// placeholder
752
-		if(isset($args['placeholder']) && '' != $args['placeholder'] && !$is_select2){
753
-			$output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>';
754
-		}elseif($is_select2 && !empty($args['placeholder'])){
755
-			$output .= "<option></option>"; // select2 needs an empty select to fill the placeholder
756
-		}
757
-
758
-		// Options
759
-		if(!empty($args['options'])){
760
-
761
-			if(!is_array($args['options'])){
762
-				$output .= $args['options']; // not the preferred way but an option
763
-			}else{
764
-				foreach($args['options'] as $val => $name){
765
-					$selected = '';
766
-					if(is_array($name)){
767
-						if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) {
768
-							$option_label = isset($name['label']) ? $name['label'] : '';
769
-
770
-							$output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>';
771
-						} else {
772
-							$option_label = isset($name['label']) ? $name['label'] : '';
773
-							$option_value = isset($name['value']) ? $name['value'] : '';
774
-							if(!empty($args['multiple']) && !empty($args['value']) && is_array($args['value']) ){
775
-								$selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : "";
776
-							} elseif(!empty($args['value'])) {
777
-								$selected = selected($option_value,stripslashes_deep($args['value']), false);
778
-							}
779
-
780
-							$output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>';
781
-						}
782
-					}else{
783
-						if(!empty($args['value'])){
784
-							if(is_array($args['value'])){
785
-								$selected = in_array($val,$args['value']) ? 'selected="selected"' : '';
786
-							} elseif(!empty($args['value'])) {
787
-								$selected = selected( $args['value'], $val, false);
788
-							}
789
-						}
790
-						$output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>';
791
-					}
792
-				}
793
-			}
794
-
795
-		}
796
-
797
-		// closing tag
798
-		$output .= '</select>';
799
-
800
-		if(!empty($args['label']) && $label_after){
801
-			$label_args = array(
802
-				'title'=> $args['label'],
803
-				'for'=> $args['id'],
804
-				'class' => $args['label_class']." ",
805
-				'label_type' => $args['label_type']
806
-			);
807
-			$output .= self::label($label_args);
808
-		}
809
-
810
-		// help text
811
-		if(!empty($args['help_text'])){
812
-			$output .= AUI_Component_Helper::help_text($args['help_text']);
813
-		}
814
-
815
-		// maybe horizontal label
816
-		if($args['label_type']=='horizontal'){
817
-			$output .= '</div>';
818
-		}
819
-
820
-
821
-		// wrap
822
-		if(!$args['no_wrap']){
823
-			$wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
824
-			$wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class;
825
-			$output = self::wrap(array(
826
-				'content' => $output,
827
-				'class'   => $wrap_class,
828
-				'element_require'   => $args['element_require'],
829
-				'argument_id'  => $args['id']
830
-			));
831
-		}
832
-
833
-
834
-		return $output;
835
-	}
836
-
837
-	/**
838
-	 * Build the component.
839
-	 *
840
-	 * @param array $args
841
-	 *
842
-	 * @return string The rendered component.
843
-	 */
844
-	public static function radio($args = array()){
845
-		$defaults = array(
846
-			'class'      => '',
847
-			'wrap_class' => '',
848
-			'id'         => '',
849
-			'title'      => '',
850
-			'horizontal' => false, // sets the lable horizontal
851
-			'value'      => '',
852
-			'label'      => '',
853
-			'label_class'=> '',
854
-			'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
855
-			'inline'     => true,
856
-			'required'   => false,
857
-			'options'    => array(),
858
-			'icon'       => '',
859
-			'no_wrap'    => false,
860
-			'element_require'   => '', // [%element_id%] == "1"
861
-			'extra_attributes'  => array() // an array of extra attributes
862
-		);
863
-
864
-		/**
865
-		 * Parse incoming $args into an array and merge it with $defaults
866
-		 */
867
-		$args   = wp_parse_args( $args, $defaults );
868
-
869
-		// for now lets use horizontal for floating
870
-		if( $args['label_type'] == 'floating' ){$args['label_type'] = 'horizontal';}
871
-
872
-		$label_args = array(
873
-			'title'=> $args['label'],
874
-			'class' => $args['label_class']." pt-0 ",
875
-			'label_type' => $args['label_type']
876
-		);
877
-
878
-		$output = '';
879
-
880
-
881
-
882
-		// label before
883
-		if(!empty($args['label'])){
884
-			$output .= self::label( $label_args, 'radio' );
885
-		}
886
-
887
-		// maybe horizontal label
888
-		if($args['label_type']=='horizontal'){
889
-			$output .= '<div class="col-sm-10">';
890
-		}
891
-
892
-		if(!empty($args['options'])){
893
-			$count = 0;
894
-			foreach($args['options'] as $value => $label){
895
-				$option_args = $args;
896
-				$option_args['value'] = $value;
897
-				$option_args['label'] = $label;
898
-				$option_args['checked'] = $value == $args['value'] ? true : false;
899
-				$output .= self::radio_option($option_args,$count);
900
-				$count++;
901
-			}
902
-		}
903
-
904
-		// maybe horizontal label
905
-		if($args['label_type']=='horizontal'){
906
-			$output .= '</div>';
907
-		}
908
-
909
-
910
-		// wrap
911
-		$wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
912
-		$wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class;
913
-		$output = self::wrap(array(
914
-			'content' => $output,
915
-			'class'   => $wrap_class,
916
-			'element_require'   => $args['element_require'],
917
-			'argument_id'  => $args['id']
918
-		));
919
-
920
-
921
-		return $output;
922
-	}
923
-
924
-	/**
925
-	 * Build the component.
926
-	 *
927
-	 * @param array $args
928
-	 *
929
-	 * @return string The rendered component.
930
-	 */
931
-	public static function radio_option($args = array(),$count = ''){
932
-		$defaults = array(
933
-			'class'      => '',
934
-			'id'         => '',
935
-			'title'      => '',
936
-			'value'      => '',
937
-			'required'   => false,
938
-			'inline'     => true,
939
-			'label'      => '',
940
-			'options'    => array(),
941
-			'icon'       => '',
942
-			'no_wrap'    => false,
943
-			'extra_attributes'  => array() // an array of extra attributes
944
-		);
945
-
946
-		/**
947
-		 * Parse incoming $args into an array and merge it with $defaults
948
-		 */
949
-		$args   = wp_parse_args( $args, $defaults );
950
-
951
-		$output = '';
952
-
953
-		// open/type
954
-		$output .= '<input type="radio"';
955
-
956
-		// class
957
-		$output .= ' class="form-check-input" ';
958
-
959
-		// name
960
-		if(!empty($args['name'])){
961
-			$output .= AUI_Component_Helper::name($args['name']);
962
-		}
963
-
964
-		// id
965
-		if(!empty($args['id'])){
966
-			$output .= AUI_Component_Helper::id($args['id'].$count);
967
-		}
968
-
969
-		// title
970
-		if(!empty($args['title'])){
971
-			$output .= AUI_Component_Helper::title($args['title']);
972
-		}
973
-
974
-		// value
975
-		if(isset($args['value'])){
976
-			$output .= ' value="'.sanitize_text_field($args['value']).'" ';
977
-		}
978
-
979
-		// checked, for radio and checkboxes
980
-		if( $args['checked'] ){
981
-			$output .= ' checked ';
982
-		}
983
-
984
-		// data-attributes
985
-		$output .= AUI_Component_Helper::data_attributes($args);
986
-
987
-		// aria-attributes
988
-		$output .= AUI_Component_Helper::aria_attributes($args);
989
-
990
-		// extra attributes
991
-		if(!empty($args['extra_attributes'])){
992
-			$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
993
-		}
994
-
995
-		// required
996
-		if(!empty($args['required'])){
997
-			$output .= ' required ';
998
-		}
999
-
1000
-		// close opening tag
1001
-		$output .= ' >';
1002
-
1003
-		// label
1004
-		if(!empty($args['label']) && is_array($args['label'])){
1005
-		}elseif(!empty($args['label'])){
1006
-			$output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio');
1007
-		}
1008
-
1009
-		// wrap
1010
-		if(!$args['no_wrap']){
1011
-			$wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check';
1012
-			$output = self::wrap(array(
1013
-				'content' => $output,
1014
-				'class' => $wrap_class
1015
-			));
1016
-		}
1017
-
1018
-
1019
-		return $output;
1020
-	}
213
+            }
214
+
215
+            // input group wraps
216
+            if($args['input_group_left'] || $args['input_group_right']){
217
+                $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : '';
218
+                if($args['input_group_left']){
219
+                    $output = self::wrap( array(
220
+                        'content' => $output,
221
+                        'class'   => $args['input_group_left_inside'] ? 'input-group-inside position-relative'.$w100  : 'input-group',
222
+                        'input_group_left' => $args['input_group_left'],
223
+                        'input_group_left_inside'    => $args['input_group_left_inside']
224
+                    ) );
225
+                }
226
+                if($args['input_group_right']){
227
+                    $output = self::wrap( array(
228
+                        'content' => $output,
229
+                        'class'   => $args['input_group_right_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group',
230
+                        'input_group_right' => $args['input_group_right'],
231
+                        'input_group_right_inside'    => $args['input_group_right_inside']
232
+                    ) );
233
+                }
234
+
235
+            }
236
+
237
+            if(!$label_after){
238
+                $output .= $help_text;
239
+            }
240
+
241
+
242
+            if($args['label_type']=='horizontal' && $type != 'checkbox'){
243
+                $output = self::wrap( array(
244
+                    'content' => $output,
245
+                    'class'   => 'col-sm-10',
246
+                ) );
247
+            }
248
+
249
+            if(!$label_after){
250
+                $output = $label . $output;
251
+            }
252
+
253
+            // wrap
254
+            if(!$args['no_wrap']){
255
+
256
+                $form_group_class = $args['label_type']=='floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group';
257
+                $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class;
258
+                $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class;
259
+                $output = self::wrap(array(
260
+                    'content' => $output,
261
+                    'class'   => $wrap_class,
262
+                    'element_require'   => $args['element_require'],
263
+                    'argument_id'  => $args['id']
264
+                ));
265
+            }
266
+
267
+
268
+
269
+        }
270
+
271
+        return $output;
272
+    }
273
+
274
+    /**
275
+     * Build the component.
276
+     *
277
+     * @param array $args
278
+     *
279
+     * @return string The rendered component.
280
+     */
281
+    public static function textarea($args = array()){
282
+        $defaults = array(
283
+            'name'       => '',
284
+            'class'      => '',
285
+            'wrap_class' => '',
286
+            'id'         => '',
287
+            'placeholder'=> '',
288
+            'title'      => '',
289
+            'value'      => '',
290
+            'required'   => false,
291
+            'label'      => '',
292
+            'label_after'=> false,
293
+            'label_class'      => '',
294
+            'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
295
+            'help_text'  => '',
296
+            'validation_text'   => '',
297
+            'validation_pattern' => '',
298
+            'no_wrap'    => false,
299
+            'rows'      => '',
300
+            'wysiwyg'   => false,
301
+            'element_require'   => '', // [%element_id%] == "1"
302
+        );
303
+
304
+        /**
305
+         * Parse incoming $args into an array and merge it with $defaults
306
+         */
307
+        $args   = wp_parse_args( $args, $defaults );
308
+        $output = '';
309
+
310
+        // hidden label option needs to be empty
311
+        $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
312
+
313
+        // floating labels don't work with wysiwyg so set it as top
314
+        if($args['label_type'] == 'floating' && !empty($args['wysiwyg'])){
315
+            $args['label_type'] = 'top';
316
+        }
317
+
318
+        $label_after = $args['label_after'];
319
+
320
+        // floating labels need label after
321
+        if( $args['label_type'] == 'floating' && empty($args['wysiwyg']) ){
322
+            $label_after = true;
323
+            $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
324
+        }
325
+
326
+        // label
327
+        if(!empty($args['label']) && is_array($args['label'])){
328
+        }elseif(!empty($args['label']) && !$label_after){
329
+            $label_args = array(
330
+                'title'=> $args['label'],
331
+                'for'=> $args['id'],
332
+                'class' => $args['label_class']." ",
333
+                'label_type' => $args['label_type']
334
+            );
335
+            $output .= self::label( $label_args );
336
+        }
337
+
338
+        // maybe horizontal label
339
+        if($args['label_type']=='horizontal'){
340
+            $output .= '<div class="col-sm-10">';
341
+        }
342
+
343
+        if(!empty($args['wysiwyg'])){
344
+            ob_start();
345
+            $content = $args['value'];
346
+            $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor';
347
+            $settings = array(
348
+                'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4,
349
+                'quicktags'     => false,
350
+                'media_buttons' => false,
351
+                'editor_class'  => 'form-control',
352
+                'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']),
353
+                'teeny'         => true,
354
+            );
355
+
356
+            // maybe set settings if array
357
+            if(is_array($args['wysiwyg'])){
358
+                $settings  = wp_parse_args( $args['wysiwyg'], $settings );
359
+            }
360
+
361
+            wp_editor( $content, $editor_id, $settings );
362
+            $output .= ob_get_clean();
363
+        }else{
364
+
365
+            // open
366
+            $output .= '<textarea ';
367
+
368
+            // name
369
+            if(!empty($args['name'])){
370
+                $output .= ' name="'.sanitize_html_class($args['name']).'" ';
371
+            }
372
+
373
+            // id
374
+            if(!empty($args['id'])){
375
+                $output .= ' id="'.sanitize_html_class($args['id']).'" ';
376
+            }
377
+
378
+            // placeholder
379
+            if(isset($args['placeholder']) && '' != $args['placeholder']){
380
+                $output .= ' placeholder="'.esc_attr($args['placeholder']).'" ';
381
+            }
382
+
383
+            // title
384
+            if(!empty($args['title'])){
385
+                $output .= ' title="'.esc_attr($args['title']).'" ';
386
+            }
387
+
388
+            // validation text
389
+            if(!empty($args['validation_text'])){
390
+                $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" ';
391
+                $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
392
+            }
393
+
394
+            // validation_pattern
395
+            if(!empty($args['validation_pattern'])){
396
+                $output .= ' pattern="'.$args['validation_pattern'].'" ';
397
+            }
398
+
399
+            // required
400
+            if(!empty($args['required'])){
401
+                $output .= ' required ';
402
+            }
403
+
404
+            // rows
405
+            if(!empty($args['rows'])){
406
+                $output .= ' rows="'.absint($args['rows']).'" ';
407
+            }
408
+
409
+
410
+            // class
411
+            $class = !empty($args['class']) ? $args['class'] : '';
412
+            $output .= ' class="form-control '.$class.'" ';
413
+
414
+
415
+            // close tag
416
+            $output .= ' >';
417
+
418
+            // value
419
+            if(!empty($args['value'])){
420
+                $output .= sanitize_textarea_field($args['value']);
421
+            }
422
+
423
+            // closing tag
424
+            $output .= '</textarea>';
425
+
426
+        }
427
+
428
+        if(!empty($args['label']) && $label_after){
429
+            $label_args = array(
430
+                'title'=> $args['label'],
431
+                'for'=> $args['id'],
432
+                'class' => $args['label_class']." ",
433
+                'label_type' => $args['label_type']
434
+            );
435
+            $output .= self::label( $label_args );
436
+        }
437
+
438
+        // help text
439
+        if(!empty($args['help_text'])){
440
+            $output .= AUI_Component_Helper::help_text($args['help_text']);
441
+        }
442
+
443
+        // maybe horizontal label
444
+        if($args['label_type']=='horizontal'){
445
+            $output .= '</div>';
446
+        }
447
+
448
+
449
+        // wrap
450
+        if(!$args['no_wrap']){
451
+            $form_group_class = $args['label_type']=='floating' ? 'form-label-group' : 'form-group';
452
+            $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class;
453
+            $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class;
454
+            $output = self::wrap(array(
455
+                'content' => $output,
456
+                'class'   => $wrap_class,
457
+                'element_require'   => $args['element_require'],
458
+                'argument_id'  => $args['id']
459
+            ));
460
+        }
461
+
462
+
463
+        return $output;
464
+    }
465
+
466
+    public static function label($args = array(), $type = ''){
467
+        //<label for="exampleInputEmail1">Email address</label>
468
+        $defaults = array(
469
+            'title'       => 'div',
470
+            'for'      => '',
471
+            'class'      => '',
472
+            'label_type'    => '', // empty = hidden, top, horizontal
473
+        );
474
+
475
+        /**
476
+         * Parse incoming $args into an array and merge it with $defaults
477
+         */
478
+        $args   = wp_parse_args( $args, $defaults );
479
+        $output = '';
480
+
481
+        if($args['title']){
482
+
483
+            // maybe hide labels //@todo set a global option for visibility class
484
+            if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){
485
+                $class = $args['class'];
486
+            }else{
487
+                $class = 'sr-only '.$args['class'];
488
+            }
489
+
490
+            // maybe horizontal
491
+            if($args['label_type']=='horizontal' && $type != 'checkbox'){
492
+                $class .= ' col-sm-2 col-form-label';
493
+            }
494
+
495
+            // open
496
+            $output .= '<label ';
497
+
498
+            // for
499
+            if(!empty($args['for'])){
500
+                $output .= ' for="'.sanitize_text_field($args['for']).'" ';
501
+            }
502
+
503
+            // class
504
+            $class = $class ? AUI_Component_Helper::esc_classes( $class ) : '';
505
+            $output .= ' class="'.$class.'" ';
506
+
507
+            // close
508
+            $output .= '>';
509
+
510
+
511
+            // title, don't escape fully as can contain html
512
+            if(!empty($args['title'])){
513
+                $output .= wp_kses_post($args['title']);
514
+            }
515
+
516
+            // close wrap
517
+            $output .= '</label>';
518
+
519
+
520
+        }
521
+
522
+
523
+        return $output;
524
+    }
525
+
526
+    /**
527
+     * Wrap some content in a HTML wrapper.
528
+     *
529
+     * @param array $args
530
+     *
531
+     * @return string
532
+     */
533
+    public static function wrap($args = array()){
534
+        $defaults = array(
535
+            'type'       => 'div',
536
+            'class'      => 'form-group',
537
+            'content'   => '',
538
+            'input_group_left' => '',
539
+            'input_group_right' => '',
540
+            'input_group_left_inside' => false,
541
+            'input_group_right_inside' => false,
542
+            'element_require'   => '',
543
+            'argument_id'   => '',
544
+        );
545
+
546
+        /**
547
+         * Parse incoming $args into an array and merge it with $defaults
548
+         */
549
+        $args   = wp_parse_args( $args, $defaults );
550
+        $output = '';
551
+        if($args['type']){
552
+
553
+            // open
554
+            $output .= '<'.sanitize_html_class($args['type']);
555
+
556
+            // element require
557
+            if(!empty($args['element_require'])){
558
+                $output .= AUI_Component_Helper::element_require($args['element_require']);
559
+                $args['class'] .= " aui-conditional-field";
560
+            }
561
+
562
+            // argument_id
563
+            if( !empty($args['argument_id']) ){
564
+                $output .= ' data-argument="'.esc_attr($args['argument_id']).'"';
565
+            }
566
+
567
+            // class
568
+            $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
569
+            $output .= ' class="'.$class.'" ';
570
+
571
+            // close wrap
572
+            $output .= ' >';
573
+
574
+
575
+            // Input group left
576
+            if(!empty($args['input_group_left'])){
577
+                $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : '';
578
+                $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>';
579
+                $output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>';
580
+            }
581
+
582
+            // content
583
+            $output .= $args['content'];
584
+
585
+            // Input group right
586
+            if(!empty($args['input_group_right'])){
587
+                $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : '';
588
+                $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>';
589
+                $output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>';
590
+            }
591
+
592
+
593
+            // close wrap
594
+            $output .= '</'.sanitize_html_class($args['type']).'>';
595
+
596
+
597
+        }else{
598
+            $output = $args['content'];
599
+        }
600
+
601
+        return $output;
602
+    }
603
+
604
+    /**
605
+     * Build the component.
606
+     *
607
+     * @param array $args
608
+     *
609
+     * @return string The rendered component.
610
+     */
611
+    public static function select($args = array()){
612
+        $defaults = array(
613
+            'class'      => '',
614
+            'wrap_class' => '',
615
+            'id'         => '',
616
+            'title'      => '',
617
+            'value'      => '', // can be an array or a string
618
+            'required'   => false,
619
+            'label'      => '',
620
+            'label_after'=> false,
621
+            'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
622
+            'label_class'      => '',
623
+            'help_text'  => '',
624
+            'placeholder'=> '',
625
+            'options'    => array(), // array or string
626
+            'icon'       => '',
627
+            'multiple'   => false,
628
+            'select2'    => false,
629
+            'no_wrap'    => false,
630
+            'element_require'   => '', // [%element_id%] == "1"
631
+            'extra_attributes'  => array(), // an array of extra attributes
632
+        );
633
+
634
+        /**
635
+         * Parse incoming $args into an array and merge it with $defaults
636
+         */
637
+        $args   = wp_parse_args( $args, $defaults );
638
+        $output = '';
639
+
640
+        // for now lets hide floating labels
641
+        if( $args['label_type'] == 'floating' ){$args['label_type'] = 'hidden';}
642
+
643
+        // hidden label option needs to be empty
644
+        $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
645
+
646
+
647
+        $label_after = $args['label_after'];
648
+
649
+        // floating labels need label after
650
+        if( $args['label_type'] == 'floating' ){
651
+            $label_after = true;
652
+            $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
653
+        }
654
+
655
+        // Maybe setup select2
656
+        $is_select2 = false;
657
+        if(!empty($args['select2'])){
658
+            $args['class'] .= ' aui-select2';
659
+            $is_select2 = true;
660
+        }elseif( strpos($args['class'], 'aui-select2') !== false){
661
+            $is_select2 = true;
662
+        }
663
+
664
+        // select2 tags
665
+        if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equals needed here for some reason
666
+            $args['data-tags'] = 'true';
667
+            $args['data-token-separators'] = "[',']";
668
+            $args['multiple'] = true;
669
+        }
670
+
671
+        // select2 placeholder
672
+        if($is_select2 && isset($args['placeholder']) && '' != $args['placeholder'] && empty($args['data-placeholder'])){
673
+            $args['data-placeholder'] = esc_attr($args['placeholder']);
674
+            $args['data-allow-clear'] = isset($args['data-allow-clear']) ? (bool) $args['data-allow-clear'] : true;
675
+        }
676
+
677
+        // label
678
+        if(!empty($args['label']) && is_array($args['label'])){
679
+        }elseif(!empty($args['label']) && !$label_after){
680
+            $label_args = array(
681
+                'title'=> $args['label'],
682
+                'for'=> $args['id'],
683
+                'class' => $args['label_class']." ",
684
+                'label_type' => $args['label_type']
685
+            );
686
+            $output .= self::label($label_args);
687
+        }
688
+
689
+        // maybe horizontal label
690
+        if($args['label_type']=='horizontal'){
691
+            $output .= '<div class="col-sm-10">';
692
+        }
693
+
694
+        // open/type
695
+        $output .= '<select ';
696
+
697
+        // style
698
+        if($is_select2){
699
+            $output .= " style='width:100%;' ";
700
+        }
701
+
702
+        // element require
703
+        if(!empty($args['element_require'])){
704
+            $output .= AUI_Component_Helper::element_require($args['element_require']);
705
+            $args['class'] .= " aui-conditional-field";
706
+        }
707
+
708
+        // class
709
+        $class = !empty($args['class']) ? $args['class'] : '';
710
+        $output .= AUI_Component_Helper::class_attr('custom-select '.$class);
711
+
712
+        // name
713
+        if(!empty($args['name'])){
714
+            $output .= AUI_Component_Helper::name($args['name'],$args['multiple']);
715
+        }
716
+
717
+        // id
718
+        if(!empty($args['id'])){
719
+            $output .= AUI_Component_Helper::id($args['id']);
720
+        }
721
+
722
+        // title
723
+        if(!empty($args['title'])){
724
+            $output .= AUI_Component_Helper::title($args['title']);
725
+        }
726
+
727
+        // data-attributes
728
+        $output .= AUI_Component_Helper::data_attributes($args);
729
+
730
+        // aria-attributes
731
+        $output .= AUI_Component_Helper::aria_attributes($args);
732
+
733
+        // extra attributes
734
+        if(!empty($args['extra_attributes'])){
735
+            $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
736
+        }
737
+
738
+        // required
739
+        if(!empty($args['required'])){
740
+            $output .= ' required ';
741
+        }
742
+
743
+        // multiple
744
+        if(!empty($args['multiple'])){
745
+            $output .= ' multiple ';
746
+        }
747
+
748
+        // close opening tag
749
+        $output .= ' >';
750
+
751
+        // placeholder
752
+        if(isset($args['placeholder']) && '' != $args['placeholder'] && !$is_select2){
753
+            $output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>';
754
+        }elseif($is_select2 && !empty($args['placeholder'])){
755
+            $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder
756
+        }
757
+
758
+        // Options
759
+        if(!empty($args['options'])){
760
+
761
+            if(!is_array($args['options'])){
762
+                $output .= $args['options']; // not the preferred way but an option
763
+            }else{
764
+                foreach($args['options'] as $val => $name){
765
+                    $selected = '';
766
+                    if(is_array($name)){
767
+                        if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) {
768
+                            $option_label = isset($name['label']) ? $name['label'] : '';
769
+
770
+                            $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>';
771
+                        } else {
772
+                            $option_label = isset($name['label']) ? $name['label'] : '';
773
+                            $option_value = isset($name['value']) ? $name['value'] : '';
774
+                            if(!empty($args['multiple']) && !empty($args['value']) && is_array($args['value']) ){
775
+                                $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : "";
776
+                            } elseif(!empty($args['value'])) {
777
+                                $selected = selected($option_value,stripslashes_deep($args['value']), false);
778
+                            }
779
+
780
+                            $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>';
781
+                        }
782
+                    }else{
783
+                        if(!empty($args['value'])){
784
+                            if(is_array($args['value'])){
785
+                                $selected = in_array($val,$args['value']) ? 'selected="selected"' : '';
786
+                            } elseif(!empty($args['value'])) {
787
+                                $selected = selected( $args['value'], $val, false);
788
+                            }
789
+                        }
790
+                        $output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>';
791
+                    }
792
+                }
793
+            }
794
+
795
+        }
796
+
797
+        // closing tag
798
+        $output .= '</select>';
799
+
800
+        if(!empty($args['label']) && $label_after){
801
+            $label_args = array(
802
+                'title'=> $args['label'],
803
+                'for'=> $args['id'],
804
+                'class' => $args['label_class']." ",
805
+                'label_type' => $args['label_type']
806
+            );
807
+            $output .= self::label($label_args);
808
+        }
809
+
810
+        // help text
811
+        if(!empty($args['help_text'])){
812
+            $output .= AUI_Component_Helper::help_text($args['help_text']);
813
+        }
814
+
815
+        // maybe horizontal label
816
+        if($args['label_type']=='horizontal'){
817
+            $output .= '</div>';
818
+        }
819
+
820
+
821
+        // wrap
822
+        if(!$args['no_wrap']){
823
+            $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
824
+            $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class;
825
+            $output = self::wrap(array(
826
+                'content' => $output,
827
+                'class'   => $wrap_class,
828
+                'element_require'   => $args['element_require'],
829
+                'argument_id'  => $args['id']
830
+            ));
831
+        }
832
+
833
+
834
+        return $output;
835
+    }
836
+
837
+    /**
838
+     * Build the component.
839
+     *
840
+     * @param array $args
841
+     *
842
+     * @return string The rendered component.
843
+     */
844
+    public static function radio($args = array()){
845
+        $defaults = array(
846
+            'class'      => '',
847
+            'wrap_class' => '',
848
+            'id'         => '',
849
+            'title'      => '',
850
+            'horizontal' => false, // sets the lable horizontal
851
+            'value'      => '',
852
+            'label'      => '',
853
+            'label_class'=> '',
854
+            'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
855
+            'inline'     => true,
856
+            'required'   => false,
857
+            'options'    => array(),
858
+            'icon'       => '',
859
+            'no_wrap'    => false,
860
+            'element_require'   => '', // [%element_id%] == "1"
861
+            'extra_attributes'  => array() // an array of extra attributes
862
+        );
863
+
864
+        /**
865
+         * Parse incoming $args into an array and merge it with $defaults
866
+         */
867
+        $args   = wp_parse_args( $args, $defaults );
868
+
869
+        // for now lets use horizontal for floating
870
+        if( $args['label_type'] == 'floating' ){$args['label_type'] = 'horizontal';}
871
+
872
+        $label_args = array(
873
+            'title'=> $args['label'],
874
+            'class' => $args['label_class']." pt-0 ",
875
+            'label_type' => $args['label_type']
876
+        );
877
+
878
+        $output = '';
879
+
880
+
881
+
882
+        // label before
883
+        if(!empty($args['label'])){
884
+            $output .= self::label( $label_args, 'radio' );
885
+        }
886
+
887
+        // maybe horizontal label
888
+        if($args['label_type']=='horizontal'){
889
+            $output .= '<div class="col-sm-10">';
890
+        }
891
+
892
+        if(!empty($args['options'])){
893
+            $count = 0;
894
+            foreach($args['options'] as $value => $label){
895
+                $option_args = $args;
896
+                $option_args['value'] = $value;
897
+                $option_args['label'] = $label;
898
+                $option_args['checked'] = $value == $args['value'] ? true : false;
899
+                $output .= self::radio_option($option_args,$count);
900
+                $count++;
901
+            }
902
+        }
903
+
904
+        // maybe horizontal label
905
+        if($args['label_type']=='horizontal'){
906
+            $output .= '</div>';
907
+        }
908
+
909
+
910
+        // wrap
911
+        $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
912
+        $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class;
913
+        $output = self::wrap(array(
914
+            'content' => $output,
915
+            'class'   => $wrap_class,
916
+            'element_require'   => $args['element_require'],
917
+            'argument_id'  => $args['id']
918
+        ));
919
+
920
+
921
+        return $output;
922
+    }
923
+
924
+    /**
925
+     * Build the component.
926
+     *
927
+     * @param array $args
928
+     *
929
+     * @return string The rendered component.
930
+     */
931
+    public static function radio_option($args = array(),$count = ''){
932
+        $defaults = array(
933
+            'class'      => '',
934
+            'id'         => '',
935
+            'title'      => '',
936
+            'value'      => '',
937
+            'required'   => false,
938
+            'inline'     => true,
939
+            'label'      => '',
940
+            'options'    => array(),
941
+            'icon'       => '',
942
+            'no_wrap'    => false,
943
+            'extra_attributes'  => array() // an array of extra attributes
944
+        );
945
+
946
+        /**
947
+         * Parse incoming $args into an array and merge it with $defaults
948
+         */
949
+        $args   = wp_parse_args( $args, $defaults );
950
+
951
+        $output = '';
952
+
953
+        // open/type
954
+        $output .= '<input type="radio"';
955
+
956
+        // class
957
+        $output .= ' class="form-check-input" ';
958
+
959
+        // name
960
+        if(!empty($args['name'])){
961
+            $output .= AUI_Component_Helper::name($args['name']);
962
+        }
963
+
964
+        // id
965
+        if(!empty($args['id'])){
966
+            $output .= AUI_Component_Helper::id($args['id'].$count);
967
+        }
968
+
969
+        // title
970
+        if(!empty($args['title'])){
971
+            $output .= AUI_Component_Helper::title($args['title']);
972
+        }
973
+
974
+        // value
975
+        if(isset($args['value'])){
976
+            $output .= ' value="'.sanitize_text_field($args['value']).'" ';
977
+        }
978
+
979
+        // checked, for radio and checkboxes
980
+        if( $args['checked'] ){
981
+            $output .= ' checked ';
982
+        }
983
+
984
+        // data-attributes
985
+        $output .= AUI_Component_Helper::data_attributes($args);
986
+
987
+        // aria-attributes
988
+        $output .= AUI_Component_Helper::aria_attributes($args);
989
+
990
+        // extra attributes
991
+        if(!empty($args['extra_attributes'])){
992
+            $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
993
+        }
994
+
995
+        // required
996
+        if(!empty($args['required'])){
997
+            $output .= ' required ';
998
+        }
999
+
1000
+        // close opening tag
1001
+        $output .= ' >';
1002
+
1003
+        // label
1004
+        if(!empty($args['label']) && is_array($args['label'])){
1005
+        }elseif(!empty($args['label'])){
1006
+            $output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio');
1007
+        }
1008
+
1009
+        // wrap
1010
+        if(!$args['no_wrap']){
1011
+            $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check';
1012
+            $output = self::wrap(array(
1013
+                'content' => $output,
1014
+                'class' => $wrap_class
1015
+            ));
1016
+        }
1017
+
1018
+
1019
+        return $output;
1020
+    }
1021 1021
 
1022 1022
 }
1023 1023
\ No newline at end of file
Please login to merge, or discard this patch.
ayecode/wp-ayecode-ui/includes/components/class-aui-component-helper.php 1 patch
Indentation   +246 added lines, -246 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined( 'ABSPATH' ) ) {
4
-	exit; // Exit if accessed directly
4
+    exit; // Exit if accessed directly
5 5
 }
6 6
 
7 7
 /**
@@ -11,250 +11,250 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class AUI_Component_Helper {
13 13
 
14
-	/**
15
-	 * A component helper for generating a input name.
16
-	 *
17
-	 * @param $text
18
-	 * @param $multiple bool If the name is set to be multiple but no brackets found then we add some.
19
-	 *
20
-	 * @return string
21
-	 */
22
-	public static function name($text,$multiple = false){
23
-		$output = '';
24
-
25
-		if($text){
26
-			$is_multiple = strpos($text, '[') === false && $multiple  ? '[]' : '';
27
-			$output = ' name="'.esc_attr($text).$is_multiple.'" ';
28
-		}
29
-
30
-		return $output;
31
-	}
32
-
33
-	/**
34
-	 * A component helper for generating a item id.
35
-	 *
36
-	 * @param $text string The text to be used as the value.
37
-	 *
38
-	 * @return string The sanitized item.
39
-	 */
40
-	public static function id($text){
41
-		$output = '';
42
-
43
-		if($text){
44
-			$output = ' id="'.sanitize_html_class($text).'" ';
45
-		}
46
-
47
-		return $output;
48
-	}
49
-
50
-	/**
51
-	 * A component helper for generating a item title.
52
-	 *
53
-	 * @param $text string The text to be used as the value.
54
-	 *
55
-	 * @return string The sanitized item.
56
-	 */
57
-	public static function title($text){
58
-		$output = '';
59
-
60
-		if($text){
61
-			$output = ' title="'.esc_attr($text).'" ';
62
-		}
63
-
64
-		return $output;
65
-	}
66
-
67
-	/**
68
-	 * A component helper for generating a item value.
69
-	 *
70
-	 * @param $text string The text to be used as the value.
71
-	 *
72
-	 * @return string The sanitized item.
73
-	 */
74
-	public static function value($text){
75
-		$output = '';
76
-
77
-		if($text){
78
-			$output = ' value="'.sanitize_text_field($text).'" ';
79
-		}
80
-
81
-		return $output;
82
-	}
83
-
84
-	/**
85
-	 * A component helper for generating a item class attribute.
86
-	 *
87
-	 * @param $text string The text to be used as the value.
88
-	 *
89
-	 * @return string The sanitized item.
90
-	 */
91
-	public static function class_attr($text){
92
-		$output = '';
93
-
94
-		if($text){
95
-			$classes = self::esc_classes($text);
96
-			if(!empty($classes)){
97
-				$output = ' class="'.$classes.'" ';
98
-			}
99
-		}
100
-
101
-		return $output;
102
-	}
103
-
104
-	/**
105
-	 * Escape a string of classes.
106
-	 *
107
-	 * @param $text
108
-	 *
109
-	 * @return string
110
-	 */
111
-	public static function esc_classes($text){
112
-		$output = '';
113
-
114
-		if($text){
115
-			$classes = explode(" ",$text);
116
-			$classes = array_map("trim",$classes);
117
-			$classes = array_map("sanitize_html_class",$classes);
118
-			if(!empty($classes)){
119
-				$output = implode(" ",$classes);
120
-			}
121
-		}
122
-
123
-		return $output;
124
-
125
-	}
126
-
127
-	/**
128
-	 * @param $args
129
-	 *
130
-	 * @return string
131
-	 */
132
-	public static function data_attributes($args){
133
-		$output = '';
134
-
135
-		if(!empty($args)){
136
-
137
-			foreach($args as $key => $val){
138
-				if(substr( $key, 0, 5 ) === "data-"){
139
-					$output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" ';
140
-				}
141
-			}
142
-		}
143
-
144
-		return $output;
145
-	}
146
-
147
-	/**
148
-	 * @param $args
149
-	 *
150
-	 * @return string
151
-	 */
152
-	public static function aria_attributes($args){
153
-		$output = '';
154
-
155
-		if(!empty($args)){
156
-
157
-			foreach($args as $key => $val){
158
-				if(substr( $key, 0, 5 ) === "aria-"){
159
-					$output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" ';
160
-				}
161
-			}
162
-		}
163
-
164
-		return $output;
165
-	}
166
-
167
-	/**
168
-	 * Build a font awesome icon from a class.
169
-	 *
170
-	 * @param $class
171
-	 * @param bool $space_after
172
-	 * @param array $extra_attributes An array of extra attributes.
173
-	 *
174
-	 * @return string
175
-	 */
176
-	public static function icon($class,$space_after = false, $extra_attributes = array()){
177
-		$output = '';
178
-
179
-		if($class){
180
-			$classes = self::esc_classes($class);
181
-			if(!empty($classes)){
182
-				$output = '<i class="'.$classes.'" ';
183
-				// extra attributes
184
-				if(!empty($extra_attributes)){
185
-					$output .= AUI_Component_Helper::extra_attributes($extra_attributes);
186
-				}
187
-				$output .= '></i>';
188
-				if($space_after){
189
-					$output .= " ";
190
-				}
191
-			}
192
-		}
193
-
194
-		return $output;
195
-	}
196
-
197
-	/**
198
-	 * @param $args
199
-	 *
200
-	 * @return string
201
-	 */
202
-	public static function extra_attributes($args){
203
-		$output = '';
204
-
205
-		if(!empty($args)){
206
-
207
-			if( is_array($args) ){
208
-				foreach($args as $key => $val){
209
-					$output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" ';
210
-				}
211
-			}else{
212
-				$output .= ' '.$args.' ';
213
-			}
214
-
215
-		}
216
-
217
-		return $output;
218
-	}
219
-
220
-	/**
221
-	 * @param $args
222
-	 *
223
-	 * @return string
224
-	 */
225
-	public static function help_text($text){
226
-		$output = '';
227
-
228
-		if($text){
229
-			$output .= '<small class="form-text text-muted">'.wp_kses_post($text).'</small>';
230
-		}
231
-
232
-
233
-		return $output;
234
-	}
235
-
236
-	/**
237
-	 * Replace element require context with JS.
238
-	 *
239
-	 * @param $input
240
-	 *
241
-	 * @return string|void
242
-	 */
243
-	public static function element_require( $input ) {
244
-
245
-		$input = str_replace( "'", '"', $input );// we only want double quotes
246
-
247
-		$output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array(
248
-			"jQuery(form).find('[data-argument=\"",
249
-			"\"]').find('input,select,textarea').val()",
250
-			"\"]').find('input:checked').val()",
251
-		), $input ) );
252
-
253
-		if($output){
254
-			$output = ' data-element-require="'.$output.'" ';
255
-		}
256
-
257
-		return $output;
258
-	}
14
+    /**
15
+     * A component helper for generating a input name.
16
+     *
17
+     * @param $text
18
+     * @param $multiple bool If the name is set to be multiple but no brackets found then we add some.
19
+     *
20
+     * @return string
21
+     */
22
+    public static function name($text,$multiple = false){
23
+        $output = '';
24
+
25
+        if($text){
26
+            $is_multiple = strpos($text, '[') === false && $multiple  ? '[]' : '';
27
+            $output = ' name="'.esc_attr($text).$is_multiple.'" ';
28
+        }
29
+
30
+        return $output;
31
+    }
32
+
33
+    /**
34
+     * A component helper for generating a item id.
35
+     *
36
+     * @param $text string The text to be used as the value.
37
+     *
38
+     * @return string The sanitized item.
39
+     */
40
+    public static function id($text){
41
+        $output = '';
42
+
43
+        if($text){
44
+            $output = ' id="'.sanitize_html_class($text).'" ';
45
+        }
46
+
47
+        return $output;
48
+    }
49
+
50
+    /**
51
+     * A component helper for generating a item title.
52
+     *
53
+     * @param $text string The text to be used as the value.
54
+     *
55
+     * @return string The sanitized item.
56
+     */
57
+    public static function title($text){
58
+        $output = '';
59
+
60
+        if($text){
61
+            $output = ' title="'.esc_attr($text).'" ';
62
+        }
63
+
64
+        return $output;
65
+    }
66
+
67
+    /**
68
+     * A component helper for generating a item value.
69
+     *
70
+     * @param $text string The text to be used as the value.
71
+     *
72
+     * @return string The sanitized item.
73
+     */
74
+    public static function value($text){
75
+        $output = '';
76
+
77
+        if($text){
78
+            $output = ' value="'.sanitize_text_field($text).'" ';
79
+        }
80
+
81
+        return $output;
82
+    }
83
+
84
+    /**
85
+     * A component helper for generating a item class attribute.
86
+     *
87
+     * @param $text string The text to be used as the value.
88
+     *
89
+     * @return string The sanitized item.
90
+     */
91
+    public static function class_attr($text){
92
+        $output = '';
93
+
94
+        if($text){
95
+            $classes = self::esc_classes($text);
96
+            if(!empty($classes)){
97
+                $output = ' class="'.$classes.'" ';
98
+            }
99
+        }
100
+
101
+        return $output;
102
+    }
103
+
104
+    /**
105
+     * Escape a string of classes.
106
+     *
107
+     * @param $text
108
+     *
109
+     * @return string
110
+     */
111
+    public static function esc_classes($text){
112
+        $output = '';
113
+
114
+        if($text){
115
+            $classes = explode(" ",$text);
116
+            $classes = array_map("trim",$classes);
117
+            $classes = array_map("sanitize_html_class",$classes);
118
+            if(!empty($classes)){
119
+                $output = implode(" ",$classes);
120
+            }
121
+        }
122
+
123
+        return $output;
124
+
125
+    }
126
+
127
+    /**
128
+     * @param $args
129
+     *
130
+     * @return string
131
+     */
132
+    public static function data_attributes($args){
133
+        $output = '';
134
+
135
+        if(!empty($args)){
136
+
137
+            foreach($args as $key => $val){
138
+                if(substr( $key, 0, 5 ) === "data-"){
139
+                    $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" ';
140
+                }
141
+            }
142
+        }
143
+
144
+        return $output;
145
+    }
146
+
147
+    /**
148
+     * @param $args
149
+     *
150
+     * @return string
151
+     */
152
+    public static function aria_attributes($args){
153
+        $output = '';
154
+
155
+        if(!empty($args)){
156
+
157
+            foreach($args as $key => $val){
158
+                if(substr( $key, 0, 5 ) === "aria-"){
159
+                    $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" ';
160
+                }
161
+            }
162
+        }
163
+
164
+        return $output;
165
+    }
166
+
167
+    /**
168
+     * Build a font awesome icon from a class.
169
+     *
170
+     * @param $class
171
+     * @param bool $space_after
172
+     * @param array $extra_attributes An array of extra attributes.
173
+     *
174
+     * @return string
175
+     */
176
+    public static function icon($class,$space_after = false, $extra_attributes = array()){
177
+        $output = '';
178
+
179
+        if($class){
180
+            $classes = self::esc_classes($class);
181
+            if(!empty($classes)){
182
+                $output = '<i class="'.$classes.'" ';
183
+                // extra attributes
184
+                if(!empty($extra_attributes)){
185
+                    $output .= AUI_Component_Helper::extra_attributes($extra_attributes);
186
+                }
187
+                $output .= '></i>';
188
+                if($space_after){
189
+                    $output .= " ";
190
+                }
191
+            }
192
+        }
193
+
194
+        return $output;
195
+    }
196
+
197
+    /**
198
+     * @param $args
199
+     *
200
+     * @return string
201
+     */
202
+    public static function extra_attributes($args){
203
+        $output = '';
204
+
205
+        if(!empty($args)){
206
+
207
+            if( is_array($args) ){
208
+                foreach($args as $key => $val){
209
+                    $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" ';
210
+                }
211
+            }else{
212
+                $output .= ' '.$args.' ';
213
+            }
214
+
215
+        }
216
+
217
+        return $output;
218
+    }
219
+
220
+    /**
221
+     * @param $args
222
+     *
223
+     * @return string
224
+     */
225
+    public static function help_text($text){
226
+        $output = '';
227
+
228
+        if($text){
229
+            $output .= '<small class="form-text text-muted">'.wp_kses_post($text).'</small>';
230
+        }
231
+
232
+
233
+        return $output;
234
+    }
235
+
236
+    /**
237
+     * Replace element require context with JS.
238
+     *
239
+     * @param $input
240
+     *
241
+     * @return string|void
242
+     */
243
+    public static function element_require( $input ) {
244
+
245
+        $input = str_replace( "'", '"', $input );// we only want double quotes
246
+
247
+        $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array(
248
+            "jQuery(form).find('[data-argument=\"",
249
+            "\"]').find('input,select,textarea').val()",
250
+            "\"]').find('input:checked').val()",
251
+        ), $input ) );
252
+
253
+        if($output){
254
+            $output = ' data-element-require="'.$output.'" ';
255
+        }
256
+
257
+        return $output;
258
+    }
259 259
 
260 260
 }
261 261
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-address-functions.php 1 patch
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -13,9 +13,9 @@  discard block
 block discarded – undo
13 13
 
14 14
 
15 15
 function wpinv_get_default_country() {
16
-	$country = wpinv_get_option( 'default_country', 'UK' );
16
+    $country = wpinv_get_option( 'default_country', 'UK' );
17 17
 
18
-	return apply_filters( 'wpinv_default_country', $country );
18
+    return apply_filters( 'wpinv_default_country', $country );
19 19
 }
20 20
 
21 21
 /**
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
  */
27 27
 function wpinv_sanitize_country( $country ) {
28 28
 
29
-	// Enure the country is specified
29
+    // Enure the country is specified
30 30
     if ( empty( $country ) ) {
31 31
         $country = wpinv_get_default_country();
32 32
     }
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
 }
57 57
 
58 58
 function wpinv_get_default_state() {
59
-	$state = wpinv_get_option( 'default_state', '' );
59
+    $state = wpinv_get_option( 'default_state', '' );
60 60
 
61
-	return apply_filters( 'wpinv_default_state', $state );
61
+    return apply_filters( 'wpinv_default_state', $state );
62 62
 }
63 63
 
64 64
 function wpinv_state_name( $state_code = '', $country_code = '' ) {
@@ -288,11 +288,11 @@  discard block
 block discarded – undo
288 288
 
289 289
     $country = wpinv_sanitize_country( $country );
290 290
     
291
-	foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
292
-		if ( false !== array_search( $country, $countries, true ) ) {
293
-			return $continent_code;
294
-		}
295
-	}
291
+    foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
292
+        if ( false !== array_search( $country, $countries, true ) ) {
293
+            return $continent_code;
294
+        }
295
+    }
296 296
 
297 297
     return '';
298 298
     
@@ -584,30 +584,30 @@  discard block
 block discarded – undo
584 584
 }
585 585
 
586 586
 function wpinv_get_states_field() {
587
-	if( empty( $_POST['country'] ) ) {
588
-		$_POST['country'] = wpinv_get_default_country();
589
-	}
590
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
587
+    if( empty( $_POST['country'] ) ) {
588
+        $_POST['country'] = wpinv_get_default_country();
589
+    }
590
+    $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
591 591
 
592
-	if( !empty( $states ) ) {
593
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
592
+    if( !empty( $states ) ) {
593
+        $sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
594 594
         
595 595
         $args = array(
596
-			'name'    => $sanitized_field_name,
597
-			'id'      => $sanitized_field_name,
598
-			'class'   => $sanitized_field_name . 'custom-select wpinv-select wpi_select2',
599
-			'options' => array_merge( array( '' => '' ), $states ),
600
-			'show_option_all'  => false,
601
-			'show_option_none' => false
602
-		);
603
-
604
-		$response = wpinv_html_select( $args );
605
-
606
-	} else {
607
-		$response = 'nostates';
608
-	}
596
+            'name'    => $sanitized_field_name,
597
+            'id'      => $sanitized_field_name,
598
+            'class'   => $sanitized_field_name . 'custom-select wpinv-select wpi_select2',
599
+            'options' => array_merge( array( '' => '' ), $states ),
600
+            'show_option_all'  => false,
601
+            'show_option_none' => false
602
+        );
603
+
604
+        $response = wpinv_html_select( $args );
605
+
606
+    } else {
607
+        $response = 'nostates';
608
+    }
609 609
 
610
-	return $response;
610
+    return $response;
611 611
 }
612 612
 
613 613
 function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
@@ -625,46 +625,46 @@  discard block
 block discarded – undo
625 625
  */
626 626
 function wpinv_get_address_formats() {
627 627
 
628
-		return apply_filters( 'wpinv_localisation_address_formats',
629
-			array(
630
-				'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
631
-				'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
632
-				'AT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
633
-				'BE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
634
-				'CA'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}}&nbsp;&nbsp;{{zip}}\n{{country}}",
635
-				'CH'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
636
-				'CL'      => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}",
637
-				'CN'      => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}",
638
-				'CZ'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
639
-				'DE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
640
-				'EE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
641
-				'FI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
642
-				'DK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
643
-				'FR'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}",
644
-				'HK'      => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}",
645
-				'HU'      => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}",
646
-				'IN'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}",
647
-				'IS'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
648
-				'IT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}",
649
-				'JP'      => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}",
650
-				'TW'      => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}",
651
-				'LI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
652
-				'NL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
653
-				'NZ'      => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}",
654
-				'NO'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
655
-				'PL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
656
-				'PT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
657
-				'SK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
658
-				'RS'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
659
-				'SI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
660
-				'ES'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}",
661
-				'SE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
662
-				'TR'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}",
663
-				'UG'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}",
664
-				'US'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}",
665
-				'VN'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}",
666
-			)
667
-		);
628
+        return apply_filters( 'wpinv_localisation_address_formats',
629
+            array(
630
+                'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
631
+                'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
632
+                'AT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
633
+                'BE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
634
+                'CA'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}}&nbsp;&nbsp;{{zip}}\n{{country}}",
635
+                'CH'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
636
+                'CL'      => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}",
637
+                'CN'      => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}",
638
+                'CZ'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
639
+                'DE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
640
+                'EE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
641
+                'FI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
642
+                'DK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
643
+                'FR'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}",
644
+                'HK'      => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}",
645
+                'HU'      => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}",
646
+                'IN'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}",
647
+                'IS'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
648
+                'IT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}",
649
+                'JP'      => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}",
650
+                'TW'      => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}",
651
+                'LI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
652
+                'NL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
653
+                'NZ'      => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}",
654
+                'NO'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
655
+                'PL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
656
+                'PT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
657
+                'SK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
658
+                'RS'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
659
+                'SI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
660
+                'ES'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}",
661
+                'SE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
662
+                'TR'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}",
663
+                'UG'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}",
664
+                'US'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}",
665
+                'VN'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}",
666
+            )
667
+        );
668 668
 }
669 669
 
670 670
 /**
@@ -681,21 +681,21 @@  discard block
 block discarded – undo
681 681
     }
682 682
 
683 683
     // Get all formats.
684
-	$formats = wpinv_get_address_formats();
684
+    $formats = wpinv_get_address_formats();
685 685
 
686
-	// Get format for the specified country.
687
-	$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
686
+    // Get format for the specified country.
687
+    $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
688 688
     
689 689
     /**
690
-	 * Filters the address format to use on Invoices.
690
+     * Filters the address format to use on Invoices.
691 691
      * 
692 692
      * New lines will be replaced by a `br` element. Double new lines will be replaced by a paragraph. HTML tags are allowed.
693
-	 *
694
-	 * @since 1.0.13
695
-	 *
696
-	 * @param string $format  The address format to use.
693
+     *
694
+     * @since 1.0.13
695
+     *
696
+     * @param string $format  The address format to use.
697 697
      * @param string $country The country who's address format is being retrieved.
698
-	 */
698
+     */
699 699
     return apply_filters( 'wpinv_get_full_address_format', $format, $country );
700 700
 }
701 701
 
@@ -716,8 +716,8 @@  discard block
 block discarded – undo
716 716
         'country'           => '',
717 717
         'zip'               => '',
718 718
         'first_name'        => '',
719
-		'last_name'         => '',
720
-		'company'           => '',
719
+        'last_name'         => '',
720
+        'company'           => '',
721 721
     );
722 722
 
723 723
     $args    = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' );
@@ -738,14 +738,14 @@  discard block
 block discarded – undo
738 738
     $args['country_code']= $country;
739 739
 
740 740
     /**
741
-	 * Filters the address format replacements to use on Invoices.
741
+     * Filters the address format replacements to use on Invoices.
742 742
      * 
743
-	 *
744
-	 * @since 1.0.13
745
-	 *
746
-	 * @param array $replacements  The address replacements to use.
743
+     *
744
+     * @since 1.0.13
745
+     *
746
+     * @param array $replacements  The address replacements to use.
747 747
      * @param array $billing_details  The billing details to use.
748
-	 */
748
+     */
749 749
     $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details );
750 750
 
751 751
     $return = array();
@@ -768,5 +768,5 @@  discard block
 block discarded – undo
768 768
  * @return string
769 769
  */
770 770
 function wpinv_trim_formatted_address_line( $line ) {
771
-	return trim( $line, ', ' );
771
+    return trim( $line, ', ' );
772 772
 }
773 773
\ No newline at end of file
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data.php 1 patch
Indentation   +860 added lines, -860 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  */
10 10
 
11 11
 if ( ! defined( 'ABSPATH' ) ) {
12
-	exit;
12
+    exit;
13 13
 }
14 14
 
15 15
 /**
@@ -21,356 +21,356 @@  discard block
 block discarded – undo
21 21
  */
22 22
 abstract class GetPaid_Data {
23 23
 
24
-	/**
25
-	 * ID for this object.
26
-	 *
27
-	 * @since 1.0.19
28
-	 * @var int
29
-	 */
30
-	protected $id = 0;
31
-
32
-	/**
33
-	 * Core data for this object. Name value pairs (name + default value).
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array();
39
-
40
-	/**
41
-	 * Core data changes for this object.
42
-	 *
43
-	 * @since 1.0.19
44
-	 * @var array
45
-	 */
46
-	protected $changes = array();
47
-
48
-	/**
49
-	 * This is false until the object is read from the DB.
50
-	 *
51
-	 * @since 1.0.19
52
-	 * @var bool
53
-	 */
54
-	protected $object_read = false;
55
-
56
-	/**
57
-	 * This is the name of this object type.
58
-	 *
59
-	 * @since 1.0.19
60
-	 * @var string
61
-	 */
62
-	protected $object_type = 'data';
63
-
64
-	/**
65
-	 * Extra data for this object. Name value pairs (name + default value).
66
-	 * Used as a standard way for sub classes (like item types) to add
67
-	 * additional information to an inherited class.
68
-	 *
69
-	 * @since 1.0.19
70
-	 * @var array
71
-	 */
72
-	protected $extra_data = array();
73
-
74
-	/**
75
-	 * Set to _data on construct so we can track and reset data if needed.
76
-	 *
77
-	 * @since 1.0.19
78
-	 * @var array
79
-	 */
80
-	protected $default_data = array();
81
-
82
-	/**
83
-	 * Contains a reference to the data store for this class.
84
-	 *
85
-	 * @since 1.0.19
86
-	 * @var GetPaid_Data_Store
87
-	 */
88
-	protected $data_store;
89
-
90
-	/**
91
-	 * Stores meta in cache for future reads.
92
-	 * A group must be set to to enable caching.
93
-	 *
94
-	 * @since 1.0.19
95
-	 * @var string
96
-	 */
97
-	protected $cache_group = '';
98
-
99
-	/**
100
-	 * Stores the last error.
101
-	 *
102
-	 * @since 1.0.19
103
-	 * @var string
104
-	 */
105
-	public $last_error = '';
106
-
107
-	/**
108
-	 * Stores additional meta data.
109
-	 *
110
-	 * @since 1.0.19
111
-	 * @var array
112
-	 */
113
-	protected $meta_data = null;
114
-
115
-	/**
116
-	 * Default constructor.
117
-	 *
118
-	 * @param int|object|array|string $read ID to load from the DB (optional) or already queried data.
119
-	 */
120
-	public function __construct( $read = 0 ) {
121
-		$this->data         = array_merge( $this->data, $this->extra_data );
122
-		$this->default_data = $this->data;
123
-	}
124
-
125
-	/**
126
-	 * Only store the object ID to avoid serializing the data object instance.
127
-	 *
128
-	 * @return array
129
-	 */
130
-	public function __sleep() {
131
-		return array( 'id' );
132
-	}
133
-
134
-	/**
135
-	 * Re-run the constructor with the object ID.
136
-	 *
137
-	 * If the object no longer exists, remove the ID.
138
-	 */
139
-	public function __wakeup() {
140
-		$this->__construct( absint( $this->id ) );
141
-
142
-		if ( ! empty( $this->last_error ) ) {
143
-			$this->set_id( 0 );
144
-		}
145
-
146
-	}
147
-
148
-	/**
149
-	 * When the object is cloned, make sure meta is duplicated correctly.
150
-	 *
151
-	 * @since 1.0.19
152
-	 */
153
-	public function __clone() {
154
-		$this->maybe_read_meta_data();
155
-		if ( ! empty( $this->meta_data ) ) {
156
-			foreach ( $this->meta_data as $array_key => $meta ) {
157
-				$this->meta_data[ $array_key ] = clone $meta;
158
-				if ( ! empty( $meta->id ) ) {
159
-					$this->meta_data[ $array_key ]->id = null;
160
-				}
161
-			}
162
-		}
163
-	}
164
-
165
-	/**
166
-	 * Get the data store.
167
-	 *
168
-	 * @since  1.0.19
169
-	 * @return object
170
-	 */
171
-	public function get_data_store() {
172
-		return $this->data_store;
173
-	}
174
-
175
-	/**
176
-	 * Get the object type.
177
-	 *
178
-	 * @since  1.0.19
179
-	 * @return string
180
-	 */
181
-	public function get_object_type() {
182
-		return $this->object_type;
183
-	}
184
-
185
-	/**
186
-	 * Returns the unique ID for this object.
187
-	 *
188
-	 * @since  1.0.19
189
-	 * @return int
190
-	 */
191
-	public function get_id() {
192
-		return $this->id;
193
-	}
194
-
195
-	/**
196
-	 * Get form status.
197
-	 *
198
-	 * @since 1.0.19
199
-	 * @param  string $context View or edit context.
200
-	 * @return string
201
-	 */
202
-	public function get_status( $context = 'view' ) {
203
-		return $this->get_prop( 'status', $context );
204
-    }
205
-
206
-	/**
207
-	 * Delete an object, set the ID to 0, and return result.
208
-	 *
209
-	 * @since  1.0.19
210
-	 * @param  bool $force_delete Should the data be deleted permanently.
211
-	 * @return bool result
212
-	 */
213
-	public function delete( $force_delete = false ) {
214
-		if ( $this->data_store && $this->get_id() ) {
215
-			$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
-			$this->set_id( 0 );
217
-			return true;
218
-		}
219
-		return false;
220
-	}
221
-
222
-	/**
223
-	 * Save should create or update based on object existence.
224
-	 *
225
-	 * @since  1.0.19
226
-	 * @return int
227
-	 */
228
-	public function save() {
229
-		if ( ! $this->data_store ) {
230
-			return $this->get_id();
231
-		}
232
-
233
-		/**
234
-		 * Trigger action before saving to the DB. Allows you to adjust object props before save.
235
-		 *
236
-		 * @param GetPaid_Data          $this The object being saved.
237
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238
-		 */
239
-		do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
240
-
241
-		if ( $this->get_id() ) {
242
-			$this->data_store->update( $this );
243
-		} else {
244
-			$this->data_store->create( $this );
245
-		}
246
-
247
-		/**
248
-		 * Trigger action after saving to the DB.
249
-		 *
250
-		 * @param GetPaid_Data          $this The object being saved.
251
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252
-		 */
253
-		do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
254
-
255
-		return $this->get_id();
256
-	}
257
-
258
-	/**
259
-	 * Change data to JSON format.
260
-	 *
261
-	 * @since  1.0.19
262
-	 * @return string Data in JSON format.
263
-	 */
264
-	public function __toString() {
265
-		return wp_json_encode( $this->get_data() );
266
-	}
267
-
268
-	/**
269
-	 * Returns all data for this object.
270
-	 *
271
-	 * @since  1.0.19
272
-	 * @return array
273
-	 */
274
-	public function get_data() {
275
-		return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
276
-	}
277
-
278
-	/**
279
-	 * Returns array of expected data keys for this object.
280
-	 *
281
-	 * @since   1.0.19
282
-	 * @return array
283
-	 */
284
-	public function get_data_keys() {
285
-		return array_keys( $this->data );
286
-	}
287
-
288
-	/**
289
-	 * Returns all "extra" data keys for an object (for sub objects like item types).
290
-	 *
291
-	 * @since  1.0.19
292
-	 * @return array
293
-	 */
294
-	public function get_extra_data_keys() {
295
-		return array_keys( $this->extra_data );
296
-	}
297
-
298
-	/**
299
-	 * Filter null meta values from array.
300
-	 *
301
-	 * @since  1.0.19
302
-	 * @param mixed $meta Meta value to check.
303
-	 * @return bool
304
-	 */
305
-	protected function filter_null_meta( $meta ) {
306
-		return ! is_null( $meta->value );
307
-	}
308
-
309
-	/**
310
-	 * Get All Meta Data.
311
-	 *
312
-	 * @since 1.0.19
313
-	 * @return array of objects.
314
-	 */
315
-	public function get_meta_data() {
316
-		$this->maybe_read_meta_data();
317
-		return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
318
-	}
319
-
320
-	/**
321
-	 * Check if the key is an internal one.
322
-	 *
323
-	 * @since  1.0.19
324
-	 * @param  string $key Key to check.
325
-	 * @return bool   true if it's an internal key, false otherwise
326
-	 */
327
-	protected function is_internal_meta_key( $key ) {
328
-		$internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
329
-
330
-		if ( ! $internal_meta_key ) {
331
-			return false;
332
-		}
333
-
334
-		$has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
335
-
336
-		if ( ! $has_setter_or_getter ) {
337
-			return false;
338
-		}
339
-
340
-		/* translators: %s: $key Key to check */
341
-		getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
342
-
343
-		return true;
344
-	}
345
-
346
-	/**
347
-	 * Magic method for setting data fields.
348
-	 *
349
-	 * This method does not update custom fields in the database.
350
-	 *
351
-	 * @since 1.0.19
352
-	 * @access public
353
-	 *
354
-	 */
355
-	public function __set( $key, $value ) {
356
-
357
-		if ( 'id' == strtolower( $key ) ) {
358
-			return $this->set_id( $value );
359
-		}
360
-
361
-		if ( method_exists( $this, "set_$key") ) {
362
-
363
-			/* translators: %s: $key Key to set */
364
-			getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
365
-
366
-			call_user_func( array( $this, "set_$key" ), $value );
367
-		} else {
368
-			$this->set_prop( $key, $value );
369
-		}
370
-
371
-	}
372
-
373
-	/**
24
+    /**
25
+     * ID for this object.
26
+     *
27
+     * @since 1.0.19
28
+     * @var int
29
+     */
30
+    protected $id = 0;
31
+
32
+    /**
33
+     * Core data for this object. Name value pairs (name + default value).
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array();
39
+
40
+    /**
41
+     * Core data changes for this object.
42
+     *
43
+     * @since 1.0.19
44
+     * @var array
45
+     */
46
+    protected $changes = array();
47
+
48
+    /**
49
+     * This is false until the object is read from the DB.
50
+     *
51
+     * @since 1.0.19
52
+     * @var bool
53
+     */
54
+    protected $object_read = false;
55
+
56
+    /**
57
+     * This is the name of this object type.
58
+     *
59
+     * @since 1.0.19
60
+     * @var string
61
+     */
62
+    protected $object_type = 'data';
63
+
64
+    /**
65
+     * Extra data for this object. Name value pairs (name + default value).
66
+     * Used as a standard way for sub classes (like item types) to add
67
+     * additional information to an inherited class.
68
+     *
69
+     * @since 1.0.19
70
+     * @var array
71
+     */
72
+    protected $extra_data = array();
73
+
74
+    /**
75
+     * Set to _data on construct so we can track and reset data if needed.
76
+     *
77
+     * @since 1.0.19
78
+     * @var array
79
+     */
80
+    protected $default_data = array();
81
+
82
+    /**
83
+     * Contains a reference to the data store for this class.
84
+     *
85
+     * @since 1.0.19
86
+     * @var GetPaid_Data_Store
87
+     */
88
+    protected $data_store;
89
+
90
+    /**
91
+     * Stores meta in cache for future reads.
92
+     * A group must be set to to enable caching.
93
+     *
94
+     * @since 1.0.19
95
+     * @var string
96
+     */
97
+    protected $cache_group = '';
98
+
99
+    /**
100
+     * Stores the last error.
101
+     *
102
+     * @since 1.0.19
103
+     * @var string
104
+     */
105
+    public $last_error = '';
106
+
107
+    /**
108
+     * Stores additional meta data.
109
+     *
110
+     * @since 1.0.19
111
+     * @var array
112
+     */
113
+    protected $meta_data = null;
114
+
115
+    /**
116
+     * Default constructor.
117
+     *
118
+     * @param int|object|array|string $read ID to load from the DB (optional) or already queried data.
119
+     */
120
+    public function __construct( $read = 0 ) {
121
+        $this->data         = array_merge( $this->data, $this->extra_data );
122
+        $this->default_data = $this->data;
123
+    }
124
+
125
+    /**
126
+     * Only store the object ID to avoid serializing the data object instance.
127
+     *
128
+     * @return array
129
+     */
130
+    public function __sleep() {
131
+        return array( 'id' );
132
+    }
133
+
134
+    /**
135
+     * Re-run the constructor with the object ID.
136
+     *
137
+     * If the object no longer exists, remove the ID.
138
+     */
139
+    public function __wakeup() {
140
+        $this->__construct( absint( $this->id ) );
141
+
142
+        if ( ! empty( $this->last_error ) ) {
143
+            $this->set_id( 0 );
144
+        }
145
+
146
+    }
147
+
148
+    /**
149
+     * When the object is cloned, make sure meta is duplicated correctly.
150
+     *
151
+     * @since 1.0.19
152
+     */
153
+    public function __clone() {
154
+        $this->maybe_read_meta_data();
155
+        if ( ! empty( $this->meta_data ) ) {
156
+            foreach ( $this->meta_data as $array_key => $meta ) {
157
+                $this->meta_data[ $array_key ] = clone $meta;
158
+                if ( ! empty( $meta->id ) ) {
159
+                    $this->meta_data[ $array_key ]->id = null;
160
+                }
161
+            }
162
+        }
163
+    }
164
+
165
+    /**
166
+     * Get the data store.
167
+     *
168
+     * @since  1.0.19
169
+     * @return object
170
+     */
171
+    public function get_data_store() {
172
+        return $this->data_store;
173
+    }
174
+
175
+    /**
176
+     * Get the object type.
177
+     *
178
+     * @since  1.0.19
179
+     * @return string
180
+     */
181
+    public function get_object_type() {
182
+        return $this->object_type;
183
+    }
184
+
185
+    /**
186
+     * Returns the unique ID for this object.
187
+     *
188
+     * @since  1.0.19
189
+     * @return int
190
+     */
191
+    public function get_id() {
192
+        return $this->id;
193
+    }
194
+
195
+    /**
196
+     * Get form status.
197
+     *
198
+     * @since 1.0.19
199
+     * @param  string $context View or edit context.
200
+     * @return string
201
+     */
202
+    public function get_status( $context = 'view' ) {
203
+        return $this->get_prop( 'status', $context );
204
+    }
205
+
206
+    /**
207
+     * Delete an object, set the ID to 0, and return result.
208
+     *
209
+     * @since  1.0.19
210
+     * @param  bool $force_delete Should the data be deleted permanently.
211
+     * @return bool result
212
+     */
213
+    public function delete( $force_delete = false ) {
214
+        if ( $this->data_store && $this->get_id() ) {
215
+            $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
+            $this->set_id( 0 );
217
+            return true;
218
+        }
219
+        return false;
220
+    }
221
+
222
+    /**
223
+     * Save should create or update based on object existence.
224
+     *
225
+     * @since  1.0.19
226
+     * @return int
227
+     */
228
+    public function save() {
229
+        if ( ! $this->data_store ) {
230
+            return $this->get_id();
231
+        }
232
+
233
+        /**
234
+         * Trigger action before saving to the DB. Allows you to adjust object props before save.
235
+         *
236
+         * @param GetPaid_Data          $this The object being saved.
237
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238
+         */
239
+        do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
240
+
241
+        if ( $this->get_id() ) {
242
+            $this->data_store->update( $this );
243
+        } else {
244
+            $this->data_store->create( $this );
245
+        }
246
+
247
+        /**
248
+         * Trigger action after saving to the DB.
249
+         *
250
+         * @param GetPaid_Data          $this The object being saved.
251
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252
+         */
253
+        do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
254
+
255
+        return $this->get_id();
256
+    }
257
+
258
+    /**
259
+     * Change data to JSON format.
260
+     *
261
+     * @since  1.0.19
262
+     * @return string Data in JSON format.
263
+     */
264
+    public function __toString() {
265
+        return wp_json_encode( $this->get_data() );
266
+    }
267
+
268
+    /**
269
+     * Returns all data for this object.
270
+     *
271
+     * @since  1.0.19
272
+     * @return array
273
+     */
274
+    public function get_data() {
275
+        return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
276
+    }
277
+
278
+    /**
279
+     * Returns array of expected data keys for this object.
280
+     *
281
+     * @since   1.0.19
282
+     * @return array
283
+     */
284
+    public function get_data_keys() {
285
+        return array_keys( $this->data );
286
+    }
287
+
288
+    /**
289
+     * Returns all "extra" data keys for an object (for sub objects like item types).
290
+     *
291
+     * @since  1.0.19
292
+     * @return array
293
+     */
294
+    public function get_extra_data_keys() {
295
+        return array_keys( $this->extra_data );
296
+    }
297
+
298
+    /**
299
+     * Filter null meta values from array.
300
+     *
301
+     * @since  1.0.19
302
+     * @param mixed $meta Meta value to check.
303
+     * @return bool
304
+     */
305
+    protected function filter_null_meta( $meta ) {
306
+        return ! is_null( $meta->value );
307
+    }
308
+
309
+    /**
310
+     * Get All Meta Data.
311
+     *
312
+     * @since 1.0.19
313
+     * @return array of objects.
314
+     */
315
+    public function get_meta_data() {
316
+        $this->maybe_read_meta_data();
317
+        return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
318
+    }
319
+
320
+    /**
321
+     * Check if the key is an internal one.
322
+     *
323
+     * @since  1.0.19
324
+     * @param  string $key Key to check.
325
+     * @return bool   true if it's an internal key, false otherwise
326
+     */
327
+    protected function is_internal_meta_key( $key ) {
328
+        $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
329
+
330
+        if ( ! $internal_meta_key ) {
331
+            return false;
332
+        }
333
+
334
+        $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
335
+
336
+        if ( ! $has_setter_or_getter ) {
337
+            return false;
338
+        }
339
+
340
+        /* translators: %s: $key Key to check */
341
+        getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
342
+
343
+        return true;
344
+    }
345
+
346
+    /**
347
+     * Magic method for setting data fields.
348
+     *
349
+     * This method does not update custom fields in the database.
350
+     *
351
+     * @since 1.0.19
352
+     * @access public
353
+     *
354
+     */
355
+    public function __set( $key, $value ) {
356
+
357
+        if ( 'id' == strtolower( $key ) ) {
358
+            return $this->set_id( $value );
359
+        }
360
+
361
+        if ( method_exists( $this, "set_$key") ) {
362
+
363
+            /* translators: %s: $key Key to set */
364
+            getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
365
+
366
+            call_user_func( array( $this, "set_$key" ), $value );
367
+        } else {
368
+            $this->set_prop( $key, $value );
369
+        }
370
+
371
+    }
372
+
373
+    /**
374 374
      * Margic method for retrieving a property.
375 375
      */
376 376
     public function __get( $key ) {
@@ -378,10 +378,10 @@  discard block
 block discarded – undo
378 378
         // Check if we have a helper method for that.
379 379
         if ( method_exists( $this, 'get_' . $key ) ) {
380 380
 
381
-			if ( 'post_type' != $key ) {
382
-				/* translators: %s: $key Key to set */
383
-				getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
384
-			}
381
+            if ( 'post_type' != $key ) {
382
+                /* translators: %s: $key Key to set */
383
+                getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
384
+            }
385 385
 
386 386
             return call_user_func( array( $this, 'get_' . $key ) );
387 387
         }
@@ -391,512 +391,512 @@  discard block
 block discarded – undo
391 391
             return $this->post->$key;
392 392
         }
393 393
 
394
-		return $this->get_prop( $key );
395
-
396
-    }
397
-
398
-	/**
399
-	 * Get Meta Data by Key.
400
-	 *
401
-	 * @since  1.0.19
402
-	 * @param  string $key Meta Key.
403
-	 * @param  bool   $single return first found meta with key, or all with $key.
404
-	 * @param  string $context What the value is for. Valid values are view and edit.
405
-	 * @return mixed
406
-	 */
407
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
408
-
409
-		// Check if this is an internal meta key.
410
-		$_key = str_replace( '_wpinv', '', $key );
411
-		$_key = str_replace( 'wpinv', '', $_key );
412
-		if ( $this->is_internal_meta_key( $_key ) ) {
413
-			$function = 'get_' . $_key;
414
-
415
-			if ( is_callable( array( $this, $function ) ) ) {
416
-				return $this->{$function}();
417
-			}
418
-		}
419
-
420
-		// Read the meta data if not yet read.
421
-		$this->maybe_read_meta_data();
422
-		$meta_data  = $this->get_meta_data();
423
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
424
-		$value      = $single ? '' : array();
425
-
426
-		if ( ! empty( $array_keys ) ) {
427
-			// We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
428
-			if ( $single ) {
429
-				$value = $meta_data[ current( $array_keys ) ]->value;
430
-			} else {
431
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
432
-			}
433
-		}
434
-
435
-		if ( 'view' === $context ) {
436
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
437
-		}
438
-
439
-		return $value;
440
-	}
441
-
442
-	/**
443
-	 * See if meta data exists, since get_meta always returns a '' or array().
444
-	 *
445
-	 * @since  1.0.19
446
-	 * @param  string $key Meta Key.
447
-	 * @return boolean
448
-	 */
449
-	public function meta_exists( $key = '' ) {
450
-		$this->maybe_read_meta_data();
451
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
452
-		return in_array( $key, $array_keys, true );
453
-	}
454
-
455
-	/**
456
-	 * Set all meta data from array.
457
-	 *
458
-	 * @since 1.0.19
459
-	 * @param array $data Key/Value pairs.
460
-	 */
461
-	public function set_meta_data( $data ) {
462
-		if ( ! empty( $data ) && is_array( $data ) ) {
463
-			$this->maybe_read_meta_data();
464
-			foreach ( $data as $meta ) {
465
-				$meta = (array) $meta;
466
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
467
-					$this->meta_data[] = new GetPaid_Meta_Data(
468
-						array(
469
-							'id'    => $meta['id'],
470
-							'key'   => $meta['key'],
471
-							'value' => $meta['value'],
472
-						)
473
-					);
474
-				}
475
-			}
476
-		}
477
-	}
478
-
479
-	/**
480
-	 * Add meta data.
481
-	 *
482
-	 * @since 1.0.19
483
-	 *
484
-	 * @param string       $key Meta key.
485
-	 * @param string|array $value Meta value.
486
-	 * @param bool         $unique Should this be a unique key?.
487
-	 */
488
-	public function add_meta_data( $key, $value, $unique = false ) {
489
-		if ( $this->is_internal_meta_key( $key ) ) {
490
-			$function = 'set_' . $key;
491
-
492
-			if ( is_callable( array( $this, $function ) ) ) {
493
-				return $this->{$function}( $value );
494
-			}
495
-		}
496
-
497
-		$this->maybe_read_meta_data();
498
-		if ( $unique ) {
499
-			$this->delete_meta_data( $key );
500
-		}
501
-		$this->meta_data[] = new GetPaid_Meta_Data(
502
-			array(
503
-				'key'   => $key,
504
-				'value' => $value,
505
-			)
506
-		);
507
-	}
508
-
509
-	/**
510
-	 * Update meta data by key or ID, if provided.
511
-	 *
512
-	 * @since  1.0.19
513
-	 *
514
-	 * @param  string       $key Meta key.
515
-	 * @param  string|array $value Meta value.
516
-	 * @param  int          $meta_id Meta ID.
517
-	 */
518
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
519
-		if ( $this->is_internal_meta_key( $key ) ) {
520
-			$function = 'set_' . $key;
521
-
522
-			if ( is_callable( array( $this, $function ) ) ) {
523
-				return $this->{$function}( $value );
524
-			}
525
-		}
526
-
527
-		$this->maybe_read_meta_data();
528
-
529
-		$array_key = false;
530
-
531
-		if ( $meta_id ) {
532
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
533
-			$array_key  = $array_keys ? current( $array_keys ) : false;
534
-		} else {
535
-			// Find matches by key.
536
-			$matches = array();
537
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
538
-				if ( $meta->key === $key ) {
539
-					$matches[] = $meta_data_array_key;
540
-				}
541
-			}
542
-
543
-			if ( ! empty( $matches ) ) {
544
-				// Set matches to null so only one key gets the new value.
545
-				foreach ( $matches as $meta_data_array_key ) {
546
-					$this->meta_data[ $meta_data_array_key ]->value = null;
547
-				}
548
-				$array_key = current( $matches );
549
-			}
550
-		}
551
-
552
-		if ( false !== $array_key ) {
553
-			$meta        = $this->meta_data[ $array_key ];
554
-			$meta->key   = $key;
555
-			$meta->value = $value;
556
-		} else {
557
-			$this->add_meta_data( $key, $value, true );
558
-		}
559
-	}
560
-
561
-	/**
562
-	 * Delete meta data.
563
-	 *
564
-	 * @since 1.0.19
565
-	 * @param string $key Meta key.
566
-	 */
567
-	public function delete_meta_data( $key ) {
568
-		$this->maybe_read_meta_data();
569
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
570
-
571
-		if ( $array_keys ) {
572
-			foreach ( $array_keys as $array_key ) {
573
-				$this->meta_data[ $array_key ]->value = null;
574
-			}
575
-		}
576
-	}
577
-
578
-	/**
579
-	 * Delete meta data.
580
-	 *
581
-	 * @since 1.0.19
582
-	 * @param int $mid Meta ID.
583
-	 */
584
-	public function delete_meta_data_by_mid( $mid ) {
585
-		$this->maybe_read_meta_data();
586
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
587
-
588
-		if ( $array_keys ) {
589
-			foreach ( $array_keys as $array_key ) {
590
-				$this->meta_data[ $array_key ]->value = null;
591
-			}
592
-		}
593
-	}
594
-
595
-	/**
596
-	 * Read meta data if null.
597
-	 *
598
-	 * @since 1.0.19
599
-	 */
600
-	protected function maybe_read_meta_data() {
601
-		if ( is_null( $this->meta_data ) ) {
602
-			$this->read_meta_data();
603
-		}
604
-	}
605
-
606
-	/**
607
-	 * Read Meta Data from the database. Ignore any internal properties.
608
-	 * Uses it's own caches because get_metadata does not provide meta_ids.
609
-	 *
610
-	 * @since 1.0.19
611
-	 * @param bool $force_read True to force a new DB read (and update cache).
612
-	 */
613
-	public function read_meta_data( $force_read = false ) {
614
-
615
-		// Reset meta data.
616
-		$this->meta_data = array();
617
-
618
-		// Maybe abort early.
619
-		if ( ! $this->get_id() || ! $this->data_store ) {
620
-			return;
621
-		}
622
-
623
-		// Only read from cache if the cache key is set.
624
-		$cache_key = null;
625
-		if ( ! $force_read && ! empty( $this->cache_group ) ) {
626
-			$cache_key     = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
627
-			$raw_meta_data = wp_cache_get( $cache_key, $this->cache_group );
628
-		}
629
-
630
-		// Should we force read?
631
-		if ( empty( $raw_meta_data ) ) {
632
-			$raw_meta_data = $this->data_store->read_meta( $this );
633
-
634
-			if ( ! empty( $cache_key ) ) {
635
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
636
-			}
637
-
638
-		}
639
-
640
-		// Set meta data.
641
-		if ( is_array( $raw_meta_data ) ) {
642
-
643
-			foreach ( $raw_meta_data as $meta ) {
644
-				$this->meta_data[] = new GetPaid_Meta_Data(
645
-					array(
646
-						'id'    => (int) $meta->meta_id,
647
-						'key'   => $meta->meta_key,
648
-						'value' => maybe_unserialize( $meta->meta_value ),
649
-					)
650
-				);
651
-			}
652
-
653
-		}
654
-
655
-	}
656
-
657
-	/**
658
-	 * Update Meta Data in the database.
659
-	 *
660
-	 * @since 1.0.19
661
-	 */
662
-	public function save_meta_data() {
663
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
664
-			return;
665
-		}
666
-		foreach ( $this->meta_data as $array_key => $meta ) {
667
-			if ( is_null( $meta->value ) ) {
668
-				if ( ! empty( $meta->id ) ) {
669
-					$this->data_store->delete_meta( $this, $meta );
670
-					unset( $this->meta_data[ $array_key ] );
671
-				}
672
-			} elseif ( empty( $meta->id ) ) {
673
-				$meta->id = $this->data_store->add_meta( $this, $meta );
674
-				$meta->apply_changes();
675
-			} else {
676
-				if ( $meta->get_changes() ) {
677
-					$this->data_store->update_meta( $this, $meta );
678
-					$meta->apply_changes();
679
-				}
680
-			}
681
-		}
682
-		if ( ! empty( $this->cache_group ) ) {
683
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
684
-			wp_cache_delete( $cache_key, $this->cache_group );
685
-		}
686
-	}
687
-
688
-	/**
689
-	 * Set ID.
690
-	 *
691
-	 * @since 1.0.19
692
-	 * @param int $id ID.
693
-	 */
694
-	public function set_id( $id ) {
695
-		$this->id = absint( $id );
696
-	}
697
-
698
-	/**
699
-	 * Sets item status.
700
-	 *
701
-	 * @since 1.0.19
702
-	 * @param string $status New status.
703
-	 * @return array details of change.
704
-	 */
705
-	public function set_status( $status ) {
394
+        return $this->get_prop( $key );
395
+
396
+    }
397
+
398
+    /**
399
+     * Get Meta Data by Key.
400
+     *
401
+     * @since  1.0.19
402
+     * @param  string $key Meta Key.
403
+     * @param  bool   $single return first found meta with key, or all with $key.
404
+     * @param  string $context What the value is for. Valid values are view and edit.
405
+     * @return mixed
406
+     */
407
+    public function get_meta( $key = '', $single = true, $context = 'view' ) {
408
+
409
+        // Check if this is an internal meta key.
410
+        $_key = str_replace( '_wpinv', '', $key );
411
+        $_key = str_replace( 'wpinv', '', $_key );
412
+        if ( $this->is_internal_meta_key( $_key ) ) {
413
+            $function = 'get_' . $_key;
414
+
415
+            if ( is_callable( array( $this, $function ) ) ) {
416
+                return $this->{$function}();
417
+            }
418
+        }
419
+
420
+        // Read the meta data if not yet read.
421
+        $this->maybe_read_meta_data();
422
+        $meta_data  = $this->get_meta_data();
423
+        $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
424
+        $value      = $single ? '' : array();
425
+
426
+        if ( ! empty( $array_keys ) ) {
427
+            // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
428
+            if ( $single ) {
429
+                $value = $meta_data[ current( $array_keys ) ]->value;
430
+            } else {
431
+                $value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
432
+            }
433
+        }
434
+
435
+        if ( 'view' === $context ) {
436
+            $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
437
+        }
438
+
439
+        return $value;
440
+    }
441
+
442
+    /**
443
+     * See if meta data exists, since get_meta always returns a '' or array().
444
+     *
445
+     * @since  1.0.19
446
+     * @param  string $key Meta Key.
447
+     * @return boolean
448
+     */
449
+    public function meta_exists( $key = '' ) {
450
+        $this->maybe_read_meta_data();
451
+        $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
452
+        return in_array( $key, $array_keys, true );
453
+    }
454
+
455
+    /**
456
+     * Set all meta data from array.
457
+     *
458
+     * @since 1.0.19
459
+     * @param array $data Key/Value pairs.
460
+     */
461
+    public function set_meta_data( $data ) {
462
+        if ( ! empty( $data ) && is_array( $data ) ) {
463
+            $this->maybe_read_meta_data();
464
+            foreach ( $data as $meta ) {
465
+                $meta = (array) $meta;
466
+                if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
467
+                    $this->meta_data[] = new GetPaid_Meta_Data(
468
+                        array(
469
+                            'id'    => $meta['id'],
470
+                            'key'   => $meta['key'],
471
+                            'value' => $meta['value'],
472
+                        )
473
+                    );
474
+                }
475
+            }
476
+        }
477
+    }
478
+
479
+    /**
480
+     * Add meta data.
481
+     *
482
+     * @since 1.0.19
483
+     *
484
+     * @param string       $key Meta key.
485
+     * @param string|array $value Meta value.
486
+     * @param bool         $unique Should this be a unique key?.
487
+     */
488
+    public function add_meta_data( $key, $value, $unique = false ) {
489
+        if ( $this->is_internal_meta_key( $key ) ) {
490
+            $function = 'set_' . $key;
491
+
492
+            if ( is_callable( array( $this, $function ) ) ) {
493
+                return $this->{$function}( $value );
494
+            }
495
+        }
496
+
497
+        $this->maybe_read_meta_data();
498
+        if ( $unique ) {
499
+            $this->delete_meta_data( $key );
500
+        }
501
+        $this->meta_data[] = new GetPaid_Meta_Data(
502
+            array(
503
+                'key'   => $key,
504
+                'value' => $value,
505
+            )
506
+        );
507
+    }
508
+
509
+    /**
510
+     * Update meta data by key or ID, if provided.
511
+     *
512
+     * @since  1.0.19
513
+     *
514
+     * @param  string       $key Meta key.
515
+     * @param  string|array $value Meta value.
516
+     * @param  int          $meta_id Meta ID.
517
+     */
518
+    public function update_meta_data( $key, $value, $meta_id = 0 ) {
519
+        if ( $this->is_internal_meta_key( $key ) ) {
520
+            $function = 'set_' . $key;
521
+
522
+            if ( is_callable( array( $this, $function ) ) ) {
523
+                return $this->{$function}( $value );
524
+            }
525
+        }
526
+
527
+        $this->maybe_read_meta_data();
528
+
529
+        $array_key = false;
530
+
531
+        if ( $meta_id ) {
532
+            $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
533
+            $array_key  = $array_keys ? current( $array_keys ) : false;
534
+        } else {
535
+            // Find matches by key.
536
+            $matches = array();
537
+            foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
538
+                if ( $meta->key === $key ) {
539
+                    $matches[] = $meta_data_array_key;
540
+                }
541
+            }
542
+
543
+            if ( ! empty( $matches ) ) {
544
+                // Set matches to null so only one key gets the new value.
545
+                foreach ( $matches as $meta_data_array_key ) {
546
+                    $this->meta_data[ $meta_data_array_key ]->value = null;
547
+                }
548
+                $array_key = current( $matches );
549
+            }
550
+        }
551
+
552
+        if ( false !== $array_key ) {
553
+            $meta        = $this->meta_data[ $array_key ];
554
+            $meta->key   = $key;
555
+            $meta->value = $value;
556
+        } else {
557
+            $this->add_meta_data( $key, $value, true );
558
+        }
559
+    }
560
+
561
+    /**
562
+     * Delete meta data.
563
+     *
564
+     * @since 1.0.19
565
+     * @param string $key Meta key.
566
+     */
567
+    public function delete_meta_data( $key ) {
568
+        $this->maybe_read_meta_data();
569
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
570
+
571
+        if ( $array_keys ) {
572
+            foreach ( $array_keys as $array_key ) {
573
+                $this->meta_data[ $array_key ]->value = null;
574
+            }
575
+        }
576
+    }
577
+
578
+    /**
579
+     * Delete meta data.
580
+     *
581
+     * @since 1.0.19
582
+     * @param int $mid Meta ID.
583
+     */
584
+    public function delete_meta_data_by_mid( $mid ) {
585
+        $this->maybe_read_meta_data();
586
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
587
+
588
+        if ( $array_keys ) {
589
+            foreach ( $array_keys as $array_key ) {
590
+                $this->meta_data[ $array_key ]->value = null;
591
+            }
592
+        }
593
+    }
594
+
595
+    /**
596
+     * Read meta data if null.
597
+     *
598
+     * @since 1.0.19
599
+     */
600
+    protected function maybe_read_meta_data() {
601
+        if ( is_null( $this->meta_data ) ) {
602
+            $this->read_meta_data();
603
+        }
604
+    }
605
+
606
+    /**
607
+     * Read Meta Data from the database. Ignore any internal properties.
608
+     * Uses it's own caches because get_metadata does not provide meta_ids.
609
+     *
610
+     * @since 1.0.19
611
+     * @param bool $force_read True to force a new DB read (and update cache).
612
+     */
613
+    public function read_meta_data( $force_read = false ) {
614
+
615
+        // Reset meta data.
616
+        $this->meta_data = array();
617
+
618
+        // Maybe abort early.
619
+        if ( ! $this->get_id() || ! $this->data_store ) {
620
+            return;
621
+        }
622
+
623
+        // Only read from cache if the cache key is set.
624
+        $cache_key = null;
625
+        if ( ! $force_read && ! empty( $this->cache_group ) ) {
626
+            $cache_key     = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
627
+            $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group );
628
+        }
629
+
630
+        // Should we force read?
631
+        if ( empty( $raw_meta_data ) ) {
632
+            $raw_meta_data = $this->data_store->read_meta( $this );
633
+
634
+            if ( ! empty( $cache_key ) ) {
635
+                wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
636
+            }
637
+
638
+        }
639
+
640
+        // Set meta data.
641
+        if ( is_array( $raw_meta_data ) ) {
642
+
643
+            foreach ( $raw_meta_data as $meta ) {
644
+                $this->meta_data[] = new GetPaid_Meta_Data(
645
+                    array(
646
+                        'id'    => (int) $meta->meta_id,
647
+                        'key'   => $meta->meta_key,
648
+                        'value' => maybe_unserialize( $meta->meta_value ),
649
+                    )
650
+                );
651
+            }
652
+
653
+        }
654
+
655
+    }
656
+
657
+    /**
658
+     * Update Meta Data in the database.
659
+     *
660
+     * @since 1.0.19
661
+     */
662
+    public function save_meta_data() {
663
+        if ( ! $this->data_store || is_null( $this->meta_data ) ) {
664
+            return;
665
+        }
666
+        foreach ( $this->meta_data as $array_key => $meta ) {
667
+            if ( is_null( $meta->value ) ) {
668
+                if ( ! empty( $meta->id ) ) {
669
+                    $this->data_store->delete_meta( $this, $meta );
670
+                    unset( $this->meta_data[ $array_key ] );
671
+                }
672
+            } elseif ( empty( $meta->id ) ) {
673
+                $meta->id = $this->data_store->add_meta( $this, $meta );
674
+                $meta->apply_changes();
675
+            } else {
676
+                if ( $meta->get_changes() ) {
677
+                    $this->data_store->update_meta( $this, $meta );
678
+                    $meta->apply_changes();
679
+                }
680
+            }
681
+        }
682
+        if ( ! empty( $this->cache_group ) ) {
683
+            $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
684
+            wp_cache_delete( $cache_key, $this->cache_group );
685
+        }
686
+    }
687
+
688
+    /**
689
+     * Set ID.
690
+     *
691
+     * @since 1.0.19
692
+     * @param int $id ID.
693
+     */
694
+    public function set_id( $id ) {
695
+        $this->id = absint( $id );
696
+    }
697
+
698
+    /**
699
+     * Sets item status.
700
+     *
701
+     * @since 1.0.19
702
+     * @param string $status New status.
703
+     * @return array details of change.
704
+     */
705
+    public function set_status( $status ) {
706 706
         $old_status = $this->get_status();
707 707
 
708
-		$this->set_prop( 'status', $status );
709
-
710
-		return array(
711
-			'from' => $old_status,
712
-			'to'   => $status,
713
-		);
714
-    }
715
-
716
-	/**
717
-	 * Set all props to default values.
718
-	 *
719
-	 * @since 1.0.19
720
-	 */
721
-	public function set_defaults() {
722
-		$this->data    = $this->default_data;
723
-		$this->changes = array();
724
-		$this->set_object_read( false );
725
-	}
726
-
727
-	/**
728
-	 * Set object read property.
729
-	 *
730
-	 * @since 1.0.19
731
-	 * @param boolean $read Should read?.
732
-	 */
733
-	public function set_object_read( $read = true ) {
734
-		$this->object_read = (bool) $read;
735
-	}
736
-
737
-	/**
738
-	 * Get object read property.
739
-	 *
740
-	 * @since  1.0.19
741
-	 * @return boolean
742
-	 */
743
-	public function get_object_read() {
744
-		return (bool) $this->object_read;
745
-	}
746
-
747
-	/**
748
-	 * Set a collection of props in one go, collect any errors, and return the result.
749
-	 * Only sets using public methods.
750
-	 *
751
-	 * @since  1.0.19
752
-	 *
753
-	 * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
754
-	 * @param string $context In what context to run this.
755
-	 *
756
-	 * @return bool|WP_Error
757
-	 */
758
-	public function set_props( $props, $context = 'set' ) {
759
-		$errors = false;
760
-
761
-		foreach ( $props as $prop => $value ) {
762
-			try {
763
-				/**
764
-				 * Checks if the prop being set is allowed, and the value is not null.
765
-				 */
766
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
767
-					continue;
768
-				}
769
-				$setter = "set_$prop";
770
-
771
-				if ( is_callable( array( $this, $setter ) ) ) {
772
-					$this->{$setter}( $value );
773
-				}
774
-			} catch ( Exception $e ) {
775
-				if ( ! $errors ) {
776
-					$errors = new WP_Error();
777
-				}
778
-				$errors->add( $e->getCode(), $e->getMessage() );
779
-				$this->last_error = $e->getMessage();
780
-			}
781
-		}
782
-
783
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
784
-	}
785
-
786
-	/**
787
-	 * Sets a prop for a setter method.
788
-	 *
789
-	 * This stores changes in a special array so we can track what needs saving
790
-	 * the the DB later.
791
-	 *
792
-	 * @since 1.0.19
793
-	 * @param string $prop Name of prop to set.
794
-	 * @param mixed  $value Value of the prop.
795
-	 */
796
-	protected function set_prop( $prop, $value ) {
797
-		if ( array_key_exists( $prop, $this->data ) ) {
798
-			if ( true === $this->object_read ) {
799
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
800
-					$this->changes[ $prop ] = $value;
801
-				}
802
-			} else {
803
-				$this->data[ $prop ] = $value;
804
-			}
805
-		}
806
-	}
807
-
808
-	/**
809
-	 * Return data changes only.
810
-	 *
811
-	 * @since 1.0.19
812
-	 * @return array
813
-	 */
814
-	public function get_changes() {
815
-		return $this->changes;
816
-	}
817
-
818
-	/**
819
-	 * Merge changes with data and clear.
820
-	 *
821
-	 * @since 1.0.19
822
-	 */
823
-	public function apply_changes() {
824
-		$this->data    = array_replace_recursive( $this->data, $this->changes );
825
-		$this->changes = array();
826
-	}
827
-
828
-	/**
829
-	 * Prefix for action and filter hooks on data.
830
-	 *
831
-	 * @since  1.0.19
832
-	 * @return string
833
-	 */
834
-	protected function get_hook_prefix() {
835
-		return 'wpinv_get_' . $this->object_type . '_';
836
-	}
837
-
838
-	/**
839
-	 * Gets a prop for a getter method.
840
-	 *
841
-	 * Gets the value from either current pending changes, or the data itself.
842
-	 * Context controls what happens to the value before it's returned.
843
-	 *
844
-	 * @since  1.0.19
845
-	 * @param  string $prop Name of prop to get.
846
-	 * @param  string $context What the value is for. Valid values are view and edit.
847
-	 * @return mixed
848
-	 */
849
-	protected function get_prop( $prop, $context = 'view' ) {
850
-		$value = null;
851
-
852
-		if ( array_key_exists( $prop, $this->data ) ) {
853
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
854
-
855
-			if ( 'view' === $context ) {
856
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
857
-			}
858
-		}
859
-
860
-		return $value;
861
-	}
862
-
863
-	/**
864
-	 * Sets a date prop whilst handling formatting and datetime objects.
865
-	 *
866
-	 * @since 1.0.19
867
-	 * @param string         $prop Name of prop to set.
868
-	 * @param string|integer $value Value of the prop.
869
-	 */
870
-	protected function set_date_prop( $prop, $value ) {
871
-
872
-		if ( empty( $value ) ) {
873
-			$this->set_prop( $prop, null );
874
-			return;
875
-		}
876
-		$this->set_prop( $prop, $value );
877
-
878
-	}
879
-
880
-	/**
881
-	 * When invalid data is found, throw an exception unless reading from the DB.
882
-	 *
883
-	 * @since 1.0.19
884
-	 * @param string $code             Error code.
885
-	 * @param string $message          Error message.
886
-	 */
887
-	protected function error( $code, $message ) {
888
-		$this->last_error = $message;
889
-	}
890
-
891
-	/**
892
-	 * Checks if the object is saved in the database
893
-	 *
894
-	 * @since 1.0.19
895
-	 * @return bool
896
-	 */
897
-	public function exists() {
898
-		$id = $this->get_id();
899
-		return ! empty( $id );
900
-	}
708
+        $this->set_prop( 'status', $status );
709
+
710
+        return array(
711
+            'from' => $old_status,
712
+            'to'   => $status,
713
+        );
714
+    }
715
+
716
+    /**
717
+     * Set all props to default values.
718
+     *
719
+     * @since 1.0.19
720
+     */
721
+    public function set_defaults() {
722
+        $this->data    = $this->default_data;
723
+        $this->changes = array();
724
+        $this->set_object_read( false );
725
+    }
726
+
727
+    /**
728
+     * Set object read property.
729
+     *
730
+     * @since 1.0.19
731
+     * @param boolean $read Should read?.
732
+     */
733
+    public function set_object_read( $read = true ) {
734
+        $this->object_read = (bool) $read;
735
+    }
736
+
737
+    /**
738
+     * Get object read property.
739
+     *
740
+     * @since  1.0.19
741
+     * @return boolean
742
+     */
743
+    public function get_object_read() {
744
+        return (bool) $this->object_read;
745
+    }
746
+
747
+    /**
748
+     * Set a collection of props in one go, collect any errors, and return the result.
749
+     * Only sets using public methods.
750
+     *
751
+     * @since  1.0.19
752
+     *
753
+     * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
754
+     * @param string $context In what context to run this.
755
+     *
756
+     * @return bool|WP_Error
757
+     */
758
+    public function set_props( $props, $context = 'set' ) {
759
+        $errors = false;
760
+
761
+        foreach ( $props as $prop => $value ) {
762
+            try {
763
+                /**
764
+                 * Checks if the prop being set is allowed, and the value is not null.
765
+                 */
766
+                if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
767
+                    continue;
768
+                }
769
+                $setter = "set_$prop";
770
+
771
+                if ( is_callable( array( $this, $setter ) ) ) {
772
+                    $this->{$setter}( $value );
773
+                }
774
+            } catch ( Exception $e ) {
775
+                if ( ! $errors ) {
776
+                    $errors = new WP_Error();
777
+                }
778
+                $errors->add( $e->getCode(), $e->getMessage() );
779
+                $this->last_error = $e->getMessage();
780
+            }
781
+        }
782
+
783
+        return $errors && count( $errors->get_error_codes() ) ? $errors : true;
784
+    }
785
+
786
+    /**
787
+     * Sets a prop for a setter method.
788
+     *
789
+     * This stores changes in a special array so we can track what needs saving
790
+     * the the DB later.
791
+     *
792
+     * @since 1.0.19
793
+     * @param string $prop Name of prop to set.
794
+     * @param mixed  $value Value of the prop.
795
+     */
796
+    protected function set_prop( $prop, $value ) {
797
+        if ( array_key_exists( $prop, $this->data ) ) {
798
+            if ( true === $this->object_read ) {
799
+                if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
800
+                    $this->changes[ $prop ] = $value;
801
+                }
802
+            } else {
803
+                $this->data[ $prop ] = $value;
804
+            }
805
+        }
806
+    }
807
+
808
+    /**
809
+     * Return data changes only.
810
+     *
811
+     * @since 1.0.19
812
+     * @return array
813
+     */
814
+    public function get_changes() {
815
+        return $this->changes;
816
+    }
817
+
818
+    /**
819
+     * Merge changes with data and clear.
820
+     *
821
+     * @since 1.0.19
822
+     */
823
+    public function apply_changes() {
824
+        $this->data    = array_replace_recursive( $this->data, $this->changes );
825
+        $this->changes = array();
826
+    }
827
+
828
+    /**
829
+     * Prefix for action and filter hooks on data.
830
+     *
831
+     * @since  1.0.19
832
+     * @return string
833
+     */
834
+    protected function get_hook_prefix() {
835
+        return 'wpinv_get_' . $this->object_type . '_';
836
+    }
837
+
838
+    /**
839
+     * Gets a prop for a getter method.
840
+     *
841
+     * Gets the value from either current pending changes, or the data itself.
842
+     * Context controls what happens to the value before it's returned.
843
+     *
844
+     * @since  1.0.19
845
+     * @param  string $prop Name of prop to get.
846
+     * @param  string $context What the value is for. Valid values are view and edit.
847
+     * @return mixed
848
+     */
849
+    protected function get_prop( $prop, $context = 'view' ) {
850
+        $value = null;
851
+
852
+        if ( array_key_exists( $prop, $this->data ) ) {
853
+            $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
854
+
855
+            if ( 'view' === $context ) {
856
+                $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
857
+            }
858
+        }
859
+
860
+        return $value;
861
+    }
862
+
863
+    /**
864
+     * Sets a date prop whilst handling formatting and datetime objects.
865
+     *
866
+     * @since 1.0.19
867
+     * @param string         $prop Name of prop to set.
868
+     * @param string|integer $value Value of the prop.
869
+     */
870
+    protected function set_date_prop( $prop, $value ) {
871
+
872
+        if ( empty( $value ) ) {
873
+            $this->set_prop( $prop, null );
874
+            return;
875
+        }
876
+        $this->set_prop( $prop, $value );
877
+
878
+    }
879
+
880
+    /**
881
+     * When invalid data is found, throw an exception unless reading from the DB.
882
+     *
883
+     * @since 1.0.19
884
+     * @param string $code             Error code.
885
+     * @param string $message          Error message.
886
+     */
887
+    protected function error( $code, $message ) {
888
+        $this->last_error = $message;
889
+    }
890
+
891
+    /**
892
+     * Checks if the object is saved in the database
893
+     *
894
+     * @since 1.0.19
895
+     * @return bool
896
+     */
897
+    public function exists() {
898
+        $id = $this->get_id();
899
+        return ! empty( $id );
900
+    }
901 901
 
902 902
 }
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
                         'getpaid-nonce'
64 64
                     )
65 65
                 );
66
-		$anchor = __( 'Deactivate', 'invoicing' );
67
-		$title  = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' );
66
+        $anchor = __( 'Deactivate', 'invoicing' );
67
+        $title  = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' );
68 68
         $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
69 69
 
70 70
     } else if( in_array( strtolower( $discount->post_status ),  array( 'pending', 'draft' ) ) ) {
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
                 'getpaid-nonce'
82 82
             )
83 83
         );
84
-		$anchor = __( 'Activate', 'invoicing' );
85
-		$title  = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' );
84
+        $anchor = __( 'Activate', 'invoicing' );
85
+        $title  = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' );
86 86
         $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
87 87
 
88 88
     }
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
             'getpaid-nonce'
100 100
         )
101 101
     );
102
-	$anchor = __( 'Delete', 'invoicing' );
103
-	$title  = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' );
102
+    $anchor = __( 'Delete', 'invoicing' );
103
+    $title  = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' );
104 104
     $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
105 105
 
106 106
     $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
Please login to merge, or discard this patch.
includes/admin/wpinv-admin-functions.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@
 block discarded – undo
56 56
 }
57 57
 
58 58
 function wpinv_admin_messages() {
59
-	settings_errors( 'wpinv-notices' );
59
+    settings_errors( 'wpinv-notices' );
60 60
 }
61 61
 add_action( 'admin_notices', 'wpinv_admin_messages' );
62 62
 
Please login to merge, or discard this patch.
includes/class-getpaid-daily-maintenance.php 1 patch
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -12,108 +12,108 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Daily_Maintenance {
14 14
 
15
-	/**
16
-	 * Class constructor.
17
-	 */
18
-	public function __construct(){
19
-
20
-		// Clear deprecated events.
21
-		add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
22
-
23
-		// (Maybe) schedule a cron that runs daily.
24
-		add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
25
-
26
-		// Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
-		add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
-		add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
30
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
31
-
32
-	}
33
-
34
-	/**
35
-	 * Schedules a cron to run every day at 7 a.m
36
-	 *
37
-	 */
38
-	public function maybe_create_scheduled_event() {
39
-
40
-		if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
41
-			$timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
42
-			wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
43
-		}
44
-
45
-	}
46
-
47
-	/**
48
-	 * Clears deprecated events.
49
-	 *
50
-	 */
51
-	public function maybe_clear_deprecated_events() {
52
-
53
-		if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
54
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
55
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
56
-			update_option( 'wpinv_cleared_old_events', 1 );
57
-		}
58
-
59
-	}
60
-
61
-	/**
62
-	 * Fires the old hook for backwards compatibility.
63
-	 *
64
-	 */
65
-	public function backwards_compat() {
66
-		do_action( 'wpinv_register_schedule_event_daily' );
67
-	}
68
-
69
-	/**
70
-	 * Expires expired subscriptions.
71
-	 *
72
-	 */
73
-	public function maybe_expire_subscriptions() {
74
-
75
-		// Fetch expired subscriptions (skips those that expire today).
76
-		$args  = array(
77
-			'number'             => -1,
78
-			'count_total'        => false,
79
-			'status'             => 'trialling active failing cancelled',
80
-			'date_expires_query' => array(
81
-				'before'    => 'today',
82
-				'inclusive' => false,
83
-			),
84
-		);
85
-
86
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
87
-
88
-		foreach ( $subscriptions->get_results() as $subscription ) {
89
-			if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) {
90
-				$subscription->set_status( 'expired' );
91
-				$subscription->save();
92
-			}
93
-		}
94
-
95
-	}
96
-
97
-	/**
98
-	 * Logs cron runs.
99
-	 *
100
-	 */
101
-	public function log_cron_run() {
102
-		wpinv_error_log( 'GetPaid Daily Cron' );
103
-	}
104
-
105
-	/**
106
-	 * Updates GeoIP databases.
107
-	 *
108
-	 */
109
-	public function maybe_update_geoip_databases() {
110
-		$updated = get_transient( 'getpaid_updated_geoip_databases' );
111
-
112
-		if ( false === $updated ) {
113
-			set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
114
-			do_action( 'getpaid_update_geoip_databases' );
115
-		}
116
-
117
-	}
15
+    /**
16
+     * Class constructor.
17
+     */
18
+    public function __construct(){
19
+
20
+        // Clear deprecated events.
21
+        add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
22
+
23
+        // (Maybe) schedule a cron that runs daily.
24
+        add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
25
+
26
+        // Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
+        add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
+        add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
+        add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
30
+        add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
31
+
32
+    }
33
+
34
+    /**
35
+     * Schedules a cron to run every day at 7 a.m
36
+     *
37
+     */
38
+    public function maybe_create_scheduled_event() {
39
+
40
+        if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
41
+            $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
42
+            wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
43
+        }
44
+
45
+    }
46
+
47
+    /**
48
+     * Clears deprecated events.
49
+     *
50
+     */
51
+    public function maybe_clear_deprecated_events() {
52
+
53
+        if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
54
+            wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
55
+            wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
56
+            update_option( 'wpinv_cleared_old_events', 1 );
57
+        }
58
+
59
+    }
60
+
61
+    /**
62
+     * Fires the old hook for backwards compatibility.
63
+     *
64
+     */
65
+    public function backwards_compat() {
66
+        do_action( 'wpinv_register_schedule_event_daily' );
67
+    }
68
+
69
+    /**
70
+     * Expires expired subscriptions.
71
+     *
72
+     */
73
+    public function maybe_expire_subscriptions() {
74
+
75
+        // Fetch expired subscriptions (skips those that expire today).
76
+        $args  = array(
77
+            'number'             => -1,
78
+            'count_total'        => false,
79
+            'status'             => 'trialling active failing cancelled',
80
+            'date_expires_query' => array(
81
+                'before'    => 'today',
82
+                'inclusive' => false,
83
+            ),
84
+        );
85
+
86
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
87
+
88
+        foreach ( $subscriptions->get_results() as $subscription ) {
89
+            if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) {
90
+                $subscription->set_status( 'expired' );
91
+                $subscription->save();
92
+            }
93
+        }
94
+
95
+    }
96
+
97
+    /**
98
+     * Logs cron runs.
99
+     *
100
+     */
101
+    public function log_cron_run() {
102
+        wpinv_error_log( 'GetPaid Daily Cron' );
103
+    }
104
+
105
+    /**
106
+     * Updates GeoIP databases.
107
+     *
108
+     */
109
+    public function maybe_update_geoip_databases() {
110
+        $updated = get_transient( 'getpaid_updated_geoip_databases' );
111
+
112
+        if ( false === $updated ) {
113
+            set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
114
+            do_action( 'getpaid_update_geoip_databases' );
115
+        }
116
+
117
+    }
118 118
 
119 119
 }
Please login to merge, or discard this patch.