Passed
Pull Request — master (#785)
by
unknown
04:48
created
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 2 patches
Indentation   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -12,293 +12,293 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Refresh_Prices {
14 14
 
15
-	/**
16
-	 * Contains the response for refreshing prices.
17
-	 * @var array
18
-	 */
19
-	public $response = array();
15
+    /**
16
+     * Contains the response for refreshing prices.
17
+     * @var array
18
+     */
19
+    public $response = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$this->response = array(
29
-			'submission_id'                    => $submission->id,
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $this->response = array(
29
+            'submission_id'                    => $submission->id,
30 30
             'has_recurring'                    => $submission->has_recurring,
31
-			'has_subscription_group'           => $submission->has_subscription_group(),
32
-			'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
31
+            'has_subscription_group'           => $submission->has_subscription_group(),
32
+            'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
33 33
             'is_free'                          => ! $submission->should_collect_payment_details(),
34
-		);
35
-
36
-		$payment_form = $submission->get_payment_form();
37
-		if ( ! empty( $payment_form->invoice ) ) {
38
-			$this->response['invoice'] = $payment_form->invoice->get_id();
39
-		}
40
-
41
-		$this->add_totals( $submission );
42
-		$this->add_texts( $submission );
43
-		$this->add_items( $submission );
44
-		$this->add_fees( $submission );
45
-		$this->add_discounts( $submission );
46
-		$this->add_taxes( $submission );
47
-		$this->add_gateways( $submission );
48
-		$this->add_data( $submission );
49
-	}
50
-
51
-	/**
52
-	 * Adds totals to a response for submission refresh prices.
53
-	 *
54
-	 * @param GetPaid_Payment_Form_Submission $submission
55
-	 */
56
-	public function add_totals( $submission ) {
57
-
58
-		$this->response = array_merge(
59
-			$this->response,
60
-			array(
61
-
62
-				'totals'      => array(
63
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
64
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
65
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
66
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
67
-					'total'     => $submission->format_amount( $submission->get_total() ),
68
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
69
-				),
70
-
71
-				'recurring'   => array(
72
-					'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ),
73
-					'discount' => $submission->format_amount( $submission->get_recurring_discount() ),
74
-					'fees'     => $submission->format_amount( $submission->get_recurring_fee() ),
75
-					'tax'      => $submission->format_amount( $submission->get_recurring_tax() ),
76
-					'total'    => $submission->format_amount( $submission->get_recurring_total() ),
77
-				),
78
-
79
-				'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ),
80
-				'currency'    => $submission->get_currency(),
81
-
82
-			)
83
-		);
84
-	}
85
-
86
-	/**
87
-	 * Adds texts to a response for submission refresh prices.
88
-	 *
89
-	 * @param GetPaid_Payment_Form_Submission $submission
90
-	 */
91
-	public function add_texts( $submission ) {
92
-
93
-		$payable = $submission->format_amount( $submission->get_total() );
94
-		$groups  = getpaid_get_subscription_groups( $submission );
95
-
96
-		if ( $submission->has_recurring && 2 > count( $groups ) ) {
97
-
98
-			$recurring = new WPInv_Item( $submission->has_recurring );
99
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
100
-			$main_item = reset( $groups );
101
-
102
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
103
-				$payable = "$payable / $period";
104
-			} elseif ( $main_item ) {
105
-
106
-				$main_item = reset( $main_item );
107
-
108
-				// Calculate the next renewal date.
109
-				$_period      = $main_item->get_recurring_period( true );
110
-				$_interval    = $main_item->get_recurring_interval();
111
-
112
-				// If the subscription item has a trial period...
113
-				if ( $main_item->has_free_trial() ) {
114
-					$_period   = $main_item->get_trial_period( true );
115
-					$_interval = $main_item->get_trial_interval();
116
-				}
117
-
118
-				$payable = sprintf(
119
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
120
-					$submission->format_amount( $submission->get_total() ),
121
-					$submission->format_amount( $submission->get_recurring_total() ),
122
-					$period
123
-				);
124
-
125
-				$payable .= sprintf(
126
-					'<small class="text-muted form-text">%s</small>',
127
-					sprintf(
128
-						__( 'First renewal on %s', 'invoicing' ),
129
-						getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
130
-					)
131
-				);
132
-
133
-			} else {
134
-				$payable = sprintf(
135
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
136
-					$submission->format_amount( $submission->get_total() ),
137
-					$submission->format_amount( $submission->get_recurring_total() ),
138
-					$period
139
-				);
140
-			}
34
+        );
35
+
36
+        $payment_form = $submission->get_payment_form();
37
+        if ( ! empty( $payment_form->invoice ) ) {
38
+            $this->response['invoice'] = $payment_form->invoice->get_id();
39
+        }
40
+
41
+        $this->add_totals( $submission );
42
+        $this->add_texts( $submission );
43
+        $this->add_items( $submission );
44
+        $this->add_fees( $submission );
45
+        $this->add_discounts( $submission );
46
+        $this->add_taxes( $submission );
47
+        $this->add_gateways( $submission );
48
+        $this->add_data( $submission );
49
+    }
50
+
51
+    /**
52
+     * Adds totals to a response for submission refresh prices.
53
+     *
54
+     * @param GetPaid_Payment_Form_Submission $submission
55
+     */
56
+    public function add_totals( $submission ) {
57
+
58
+        $this->response = array_merge(
59
+            $this->response,
60
+            array(
61
+
62
+                'totals'      => array(
63
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
64
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
65
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
66
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
67
+                    'total'     => $submission->format_amount( $submission->get_total() ),
68
+                    'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
69
+                ),
70
+
71
+                'recurring'   => array(
72
+                    'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ),
73
+                    'discount' => $submission->format_amount( $submission->get_recurring_discount() ),
74
+                    'fees'     => $submission->format_amount( $submission->get_recurring_fee() ),
75
+                    'tax'      => $submission->format_amount( $submission->get_recurring_tax() ),
76
+                    'total'    => $submission->format_amount( $submission->get_recurring_total() ),
77
+                ),
78
+
79
+                'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ),
80
+                'currency'    => $submission->get_currency(),
81
+
82
+            )
83
+        );
84
+    }
85
+
86
+    /**
87
+     * Adds texts to a response for submission refresh prices.
88
+     *
89
+     * @param GetPaid_Payment_Form_Submission $submission
90
+     */
91
+    public function add_texts( $submission ) {
92
+
93
+        $payable = $submission->format_amount( $submission->get_total() );
94
+        $groups  = getpaid_get_subscription_groups( $submission );
95
+
96
+        if ( $submission->has_recurring && 2 > count( $groups ) ) {
97
+
98
+            $recurring = new WPInv_Item( $submission->has_recurring );
99
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
100
+            $main_item = reset( $groups );
101
+
102
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
103
+                $payable = "$payable / $period";
104
+            } elseif ( $main_item ) {
105
+
106
+                $main_item = reset( $main_item );
107
+
108
+                // Calculate the next renewal date.
109
+                $_period      = $main_item->get_recurring_period( true );
110
+                $_interval    = $main_item->get_recurring_interval();
111
+
112
+                // If the subscription item has a trial period...
113
+                if ( $main_item->has_free_trial() ) {
114
+                    $_period   = $main_item->get_trial_period( true );
115
+                    $_interval = $main_item->get_trial_interval();
116
+                }
117
+
118
+                $payable = sprintf(
119
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
120
+                    $submission->format_amount( $submission->get_total() ),
121
+                    $submission->format_amount( $submission->get_recurring_total() ),
122
+                    $period
123
+                );
124
+
125
+                $payable .= sprintf(
126
+                    '<small class="text-muted form-text">%s</small>',
127
+                    sprintf(
128
+                        __( 'First renewal on %s', 'invoicing' ),
129
+                        getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
130
+                    )
131
+                );
132
+
133
+            } else {
134
+                $payable = sprintf(
135
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
136
+                    $submission->format_amount( $submission->get_total() ),
137
+                    $submission->format_amount( $submission->get_recurring_total() ),
138
+                    $period
139
+                );
140
+            }
141 141
         }
142 142
 
143
-		$texts = array(
144
-			'.getpaid-checkout-total-payable' => $payable,
145
-		);
143
+        $texts = array(
144
+            '.getpaid-checkout-total-payable' => $payable,
145
+        );
146 146
 
147
-		foreach ( $submission->get_items() as $item ) {
147
+        foreach ( $submission->get_items() as $item ) {
148 148
             $item_id = $item->has_variable_pricing() ? $item->get_price_id() : $item->get_id();
149 149
 
150
-			$initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
151
-			$recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
152
-			$texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
153
-			$texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) );
150
+            $initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
151
+            $recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
152
+            $texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
153
+            $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) );
154 154
 
155
-			if ( $item->get_quantity() == 1 ) {
156
-				$texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = '';
157
-			}
155
+            if ( $item->get_quantity() == 1 ) {
156
+                $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = '';
157
+            }
158 158
         }
159 159
 
160
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
161
-	}
160
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
161
+    }
162 162
 
163
-	/**
164
-	 * Adds items to a response for submission refresh prices.
165
-	 *
166
-	 * @param GetPaid_Payment_Form_Submission $submission
167
-	 */
168
-	public function add_items( $submission ) {
163
+    /**
164
+     * Adds items to a response for submission refresh prices.
165
+     *
166
+     * @param GetPaid_Payment_Form_Submission $submission
167
+     */
168
+    public function add_items( $submission ) {
169 169
 
170
-		// Add items.
171
-		$items          = array();
172
-		$selected_items = array();
170
+        // Add items.
171
+        $items          = array();
172
+        $selected_items = array();
173 173
 
174 174
         foreach ( $submission->get_items() as $item ) {
175 175
             $item_id = $item->has_variable_pricing() ? $item->get_price_id() : $item->get_id();
176
-			$items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() );
176
+            $items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() );
177 177
 
178
-			$selected_items[ "$item_id" ] = array(
179
-				'quantity'  => $item->get_quantity(),
180
-				'price'     => $item->get_price(),
178
+            $selected_items[ "$item_id" ] = array(
179
+                'quantity'  => $item->get_quantity(),
180
+                'price'     => $item->get_price(),
181 181
                 'price_id'  => (int) $item_id,
182
-				'price_fmt' => $submission->format_amount( $item->get_price() ),
183
-			);
184
-		}
185
-
186
-		$this->response = array_merge(
187
-			$this->response,
188
-			array(
189
-				'items'          => $items,
190
-				'selected_items' => $selected_items,
191
-			)
192
-		);
193
-	}
194
-
195
-	/**
196
-	 * Adds fees to a response for submission refresh prices.
197
-	 *
198
-	 * @param GetPaid_Payment_Form_Submission $submission
199
-	 */
200
-	public function add_fees( $submission ) {
201
-
202
-		$fees = array();
182
+                'price_fmt' => $submission->format_amount( $item->get_price() ),
183
+            );
184
+        }
185
+
186
+        $this->response = array_merge(
187
+            $this->response,
188
+            array(
189
+                'items'          => $items,
190
+                'selected_items' => $selected_items,
191
+            )
192
+        );
193
+    }
194
+
195
+    /**
196
+     * Adds fees to a response for submission refresh prices.
197
+     *
198
+     * @param GetPaid_Payment_Form_Submission $submission
199
+     */
200
+    public function add_fees( $submission ) {
201
+
202
+        $fees = array();
203 203
 
204 204
         foreach ( $submission->get_fees() as $name => $data ) {
205
-			$fees[ $name ] = $submission->format_amount( $data['initial_fee'] );
206
-		}
205
+            $fees[ $name ] = $submission->format_amount( $data['initial_fee'] );
206
+        }
207 207
 
208
-		$this->response = array_merge(
209
-			$this->response,
210
-			array( 'fees' => $fees )
211
-		);
212
-	}
208
+        $this->response = array_merge(
209
+            $this->response,
210
+            array( 'fees' => $fees )
211
+        );
212
+    }
213 213
 
214
-	/**
215
-	 * Adds discounts to a response for submission refresh prices.
216
-	 *
217
-	 * @param GetPaid_Payment_Form_Submission $submission
218
-	 */
219
-	public function add_discounts( $submission ) {
214
+    /**
215
+     * Adds discounts to a response for submission refresh prices.
216
+     *
217
+     * @param GetPaid_Payment_Form_Submission $submission
218
+     */
219
+    public function add_discounts( $submission ) {
220 220
 
221
-		$discounts = array();
221
+        $discounts = array();
222 222
 
223 223
         foreach ( $submission->get_discounts() as $name => $data ) {
224
-			$discounts[ $name ] = $submission->format_amount( $data['initial_discount'] );
225
-		}
226
-
227
-		$this->response = array_merge(
228
-			$this->response,
229
-			array( 'discounts' => $discounts )
230
-		);
231
-	}
232
-
233
-	/**
234
-	 * Adds taxes to a response for submission refresh prices.
235
-	 *
236
-	 * @param GetPaid_Payment_Form_Submission $submission
237
-	 */
238
-	public function add_taxes( $submission ) {
239
-
240
-		$taxes  = array();
241
-		$markup = '';
224
+            $discounts[ $name ] = $submission->format_amount( $data['initial_discount'] );
225
+        }
226
+
227
+        $this->response = array_merge(
228
+            $this->response,
229
+            array( 'discounts' => $discounts )
230
+        );
231
+    }
232
+
233
+    /**
234
+     * Adds taxes to a response for submission refresh prices.
235
+     *
236
+     * @param GetPaid_Payment_Form_Submission $submission
237
+     */
238
+    public function add_taxes( $submission ) {
239
+
240
+        $taxes  = array();
241
+        $markup = '';
242 242
         foreach ( $submission->get_taxes() as $name => $data ) {
243
-			$name           = sanitize_text_field( $name );
244
-			$amount         = $submission->format_amount( $data['initial_tax'] );
245
-			$taxes[ $name ] = $amount;
246
-			$markup        .= "<small class='form-text'>$name : $amount</small>";
247
-		}
248
-
249
-		$this->response = array_merge(
250
-			$this->response,
251
-			array( 'taxes' => $taxes )
252
-		);
253
-	}
254
-
255
-	/**
256
-	 * Adds gateways to a response for submission refresh prices.
257
-	 *
258
-	 * @param GetPaid_Payment_Form_Submission $submission
259
-	 */
260
-	public function add_gateways( $submission ) {
261
-
262
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
263
-
264
-		if ( $this->response['has_recurring'] ) {
265
-
266
-			foreach ( $gateways as $i => $gateway ) {
267
-
268
-				if (
269
-					! getpaid_payment_gateway_supports( $gateway, 'subscription' )
270
-					|| ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
271
-					|| ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
272
-					unset( $gateways[ $i ] );
273
-				}
243
+            $name           = sanitize_text_field( $name );
244
+            $amount         = $submission->format_amount( $data['initial_tax'] );
245
+            $taxes[ $name ] = $amount;
246
+            $markup        .= "<small class='form-text'>$name : $amount</small>";
247
+        }
248
+
249
+        $this->response = array_merge(
250
+            $this->response,
251
+            array( 'taxes' => $taxes )
252
+        );
253
+    }
254
+
255
+    /**
256
+     * Adds gateways to a response for submission refresh prices.
257
+     *
258
+     * @param GetPaid_Payment_Form_Submission $submission
259
+     */
260
+    public function add_gateways( $submission ) {
261
+
262
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
263
+
264
+        if ( $this->response['has_recurring'] ) {
265
+
266
+            foreach ( $gateways as $i => $gateway ) {
267
+
268
+                if (
269
+                    ! getpaid_payment_gateway_supports( $gateway, 'subscription' )
270
+                    || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
271
+                    || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
272
+                    unset( $gateways[ $i ] );
273
+                }
274 274
             }
275 275
         }
276 276
 
277
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
278
-		$this->response = array_merge(
279
-			$this->response,
280
-			array( 'gateways' => $gateways )
281
-		);
282
-	}
283
-
284
-	/**
285
-	 * Adds data to a response for submission refresh prices.
286
-	 *
287
-	 * @param GetPaid_Payment_Form_Submission $submission
288
-	 */
289
-	public function add_data( $submission ) {
290
-
291
-		$this->response = array_merge(
292
-			$this->response,
293
-			array(
294
-				'js_data' => apply_filters(
295
-					'getpaid_submission_js_data',
296
-					array(
297
-						'is_recurring' => $this->response['has_recurring'],
298
-					),
299
-					$submission
300
-				),
301
-			)
302
-		);
303
-	}
277
+        $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
278
+        $this->response = array_merge(
279
+            $this->response,
280
+            array( 'gateways' => $gateways )
281
+        );
282
+    }
283
+
284
+    /**
285
+     * Adds data to a response for submission refresh prices.
286
+     *
287
+     * @param GetPaid_Payment_Form_Submission $submission
288
+     */
289
+    public function add_data( $submission ) {
290
+
291
+        $this->response = array_merge(
292
+            $this->response,
293
+            array(
294
+                'js_data' => apply_filters(
295
+                    'getpaid_submission_js_data',
296
+                    array(
297
+                        'is_recurring' => $this->response['has_recurring'],
298
+                    ),
299
+                    $submission
300
+                ),
301
+            )
302
+        );
303
+    }
304 304
 }
Please login to merge, or discard this patch.
Spacing   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Payment form submission refresh prices class
@@ -23,29 +23,29 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param GetPaid_Payment_Form_Submission $submission
25 25
 	 */
26
-	public function __construct( $submission ) {
26
+	public function __construct($submission) {
27 27
 
28 28
 		$this->response = array(
29 29
 			'submission_id'                    => $submission->id,
30 30
             'has_recurring'                    => $submission->has_recurring,
31 31
 			'has_subscription_group'           => $submission->has_subscription_group(),
32 32
 			'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
33
-            'is_free'                          => ! $submission->should_collect_payment_details(),
33
+            'is_free'                          => !$submission->should_collect_payment_details(),
34 34
 		);
35 35
 
36 36
 		$payment_form = $submission->get_payment_form();
37
-		if ( ! empty( $payment_form->invoice ) ) {
37
+		if (!empty($payment_form->invoice)) {
38 38
 			$this->response['invoice'] = $payment_form->invoice->get_id();
39 39
 		}
40 40
 
41
-		$this->add_totals( $submission );
42
-		$this->add_texts( $submission );
43
-		$this->add_items( $submission );
44
-		$this->add_fees( $submission );
45
-		$this->add_discounts( $submission );
46
-		$this->add_taxes( $submission );
47
-		$this->add_gateways( $submission );
48
-		$this->add_data( $submission );
41
+		$this->add_totals($submission);
42
+		$this->add_texts($submission);
43
+		$this->add_items($submission);
44
+		$this->add_fees($submission);
45
+		$this->add_discounts($submission);
46
+		$this->add_taxes($submission);
47
+		$this->add_gateways($submission);
48
+		$this->add_data($submission);
49 49
 	}
50 50
 
51 51
 	/**
@@ -53,30 +53,30 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @param GetPaid_Payment_Form_Submission $submission
55 55
 	 */
56
-	public function add_totals( $submission ) {
56
+	public function add_totals($submission) {
57 57
 
58 58
 		$this->response = array_merge(
59 59
 			$this->response,
60 60
 			array(
61 61
 
62 62
 				'totals'      => array(
63
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
64
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
65
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
66
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
67
-					'total'     => $submission->format_amount( $submission->get_total() ),
68
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
63
+					'subtotal'  => $submission->format_amount($submission->get_subtotal()),
64
+					'discount'  => $submission->format_amount($submission->get_discount()),
65
+					'fees'      => $submission->format_amount($submission->get_fee()),
66
+					'tax'       => $submission->format_amount($submission->get_tax()),
67
+					'total'     => $submission->format_amount($submission->get_total()),
68
+					'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES),
69 69
 				),
70 70
 
71 71
 				'recurring'   => array(
72
-					'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ),
73
-					'discount' => $submission->format_amount( $submission->get_recurring_discount() ),
74
-					'fees'     => $submission->format_amount( $submission->get_recurring_fee() ),
75
-					'tax'      => $submission->format_amount( $submission->get_recurring_tax() ),
76
-					'total'    => $submission->format_amount( $submission->get_recurring_total() ),
72
+					'subtotal' => $submission->format_amount($submission->get_recurring_subtotal()),
73
+					'discount' => $submission->format_amount($submission->get_recurring_discount()),
74
+					'fees'     => $submission->format_amount($submission->get_recurring_fee()),
75
+					'tax'      => $submission->format_amount($submission->get_recurring_tax()),
76
+					'total'    => $submission->format_amount($submission->get_recurring_total()),
77 77
 				),
78 78
 
79
-				'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ),
79
+				'initial_amt' => wpinv_round_amount($submission->get_total(), null, true),
80 80
 				'currency'    => $submission->get_currency(),
81 81
 
82 82
 			)
@@ -88,53 +88,53 @@  discard block
 block discarded – undo
88 88
 	 *
89 89
 	 * @param GetPaid_Payment_Form_Submission $submission
90 90
 	 */
91
-	public function add_texts( $submission ) {
91
+	public function add_texts($submission) {
92 92
 
93
-		$payable = $submission->format_amount( $submission->get_total() );
94
-		$groups  = getpaid_get_subscription_groups( $submission );
93
+		$payable = $submission->format_amount($submission->get_total());
94
+		$groups  = getpaid_get_subscription_groups($submission);
95 95
 
96
-		if ( $submission->has_recurring && 2 > count( $groups ) ) {
96
+		if ($submission->has_recurring && 2 > count($groups)) {
97 97
 
98
-			$recurring = new WPInv_Item( $submission->has_recurring );
99
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
100
-			$main_item = reset( $groups );
98
+			$recurring = new WPInv_Item($submission->has_recurring);
99
+			$period    = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), '');
100
+			$main_item = reset($groups);
101 101
 
102
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
102
+			if ($submission->get_total() == $submission->get_recurring_total()) {
103 103
 				$payable = "$payable / $period";
104
-			} elseif ( $main_item ) {
104
+			} elseif ($main_item) {
105 105
 
106
-				$main_item = reset( $main_item );
106
+				$main_item = reset($main_item);
107 107
 
108 108
 				// Calculate the next renewal date.
109
-				$_period      = $main_item->get_recurring_period( true );
109
+				$_period      = $main_item->get_recurring_period(true);
110 110
 				$_interval    = $main_item->get_recurring_interval();
111 111
 
112 112
 				// If the subscription item has a trial period...
113
-				if ( $main_item->has_free_trial() ) {
114
-					$_period   = $main_item->get_trial_period( true );
113
+				if ($main_item->has_free_trial()) {
114
+					$_period   = $main_item->get_trial_period(true);
115 115
 					$_interval = $main_item->get_trial_interval();
116 116
 				}
117 117
 
118 118
 				$payable = sprintf(
119
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
120
-					$submission->format_amount( $submission->get_total() ),
121
-					$submission->format_amount( $submission->get_recurring_total() ),
119
+					__('%1$s (renews at %2$s / %3$s)', 'invoicing'),
120
+					$submission->format_amount($submission->get_total()),
121
+					$submission->format_amount($submission->get_recurring_total()),
122 122
 					$period
123 123
 				);
124 124
 
125 125
 				$payable .= sprintf(
126 126
 					'<small class="text-muted form-text">%s</small>',
127 127
 					sprintf(
128
-						__( 'First renewal on %s', 'invoicing' ),
129
-						getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
128
+						__('First renewal on %s', 'invoicing'),
129
+						getpaid_format_date(date('Y-m-d H:i:s', strtotime("+$_interval $_period", current_time('timestamp'))))
130 130
 					)
131 131
 				);
132 132
 
133 133
 			} else {
134 134
 				$payable = sprintf(
135
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
136
-					$submission->format_amount( $submission->get_total() ),
137
-					$submission->format_amount( $submission->get_recurring_total() ),
135
+					__('%1$s (renews at %2$s / %3$s)', 'invoicing'),
136
+					$submission->format_amount($submission->get_total()),
137
+					$submission->format_amount($submission->get_recurring_total()),
138 138
 					$period
139 139
 				);
140 140
 			}
@@ -144,20 +144,20 @@  discard block
 block discarded – undo
144 144
 			'.getpaid-checkout-total-payable' => $payable,
145 145
 		);
146 146
 
147
-		foreach ( $submission->get_items() as $item ) {
147
+		foreach ($submission->get_items() as $item) {
148 148
             $item_id = $item->has_variable_pricing() ? $item->get_price_id() : $item->get_id();
149 149
 
150
-			$initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
151
-			$recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
152
-			$texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
153
-			$texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) );
150
+			$initial_price                                         = $submission->format_amount($item->get_sub_total() - $item->item_discount);
151
+			$recurring_price                                       = $submission->format_amount($item->get_recurring_sub_total() - $item->recurring_item_discount);
152
+			$texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text($item, $submission->get_currency(), $initial_price, $recurring_price);
153
+			$texts[".item-$item_id .getpaid-mobile-item-subtotal"] = sprintf(__('Subtotal: %s', 'invoicing'), $submission->format_amount($item->get_sub_total()));
154 154
 
155
-			if ( $item->get_quantity() == 1 ) {
156
-				$texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = '';
155
+			if ($item->get_quantity() == 1) {
156
+				$texts[".item-$item_id .getpaid-mobile-item-subtotal"] = '';
157 157
 			}
158 158
         }
159 159
 
160
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
160
+		$this->response = array_merge($this->response, array('texts' => $texts));
161 161
 	}
162 162
 
163 163
 	/**
@@ -165,21 +165,21 @@  discard block
 block discarded – undo
165 165
 	 *
166 166
 	 * @param GetPaid_Payment_Form_Submission $submission
167 167
 	 */
168
-	public function add_items( $submission ) {
168
+	public function add_items($submission) {
169 169
 
170 170
 		// Add items.
171 171
 		$items          = array();
172 172
 		$selected_items = array();
173 173
 
174
-        foreach ( $submission->get_items() as $item ) {
174
+        foreach ($submission->get_items() as $item) {
175 175
             $item_id = $item->has_variable_pricing() ? $item->get_price_id() : $item->get_id();
176
-			$items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() );
176
+			$items["$item_id"] = $submission->format_amount($item->get_sub_total());
177 177
 
178
-			$selected_items[ "$item_id" ] = array(
178
+			$selected_items["$item_id"] = array(
179 179
 				'quantity'  => $item->get_quantity(),
180 180
 				'price'     => $item->get_price(),
181 181
                 'price_id'  => (int) $item_id,
182
-				'price_fmt' => $submission->format_amount( $item->get_price() ),
182
+				'price_fmt' => $submission->format_amount($item->get_price()),
183 183
 			);
184 184
 		}
185 185
 
@@ -197,17 +197,17 @@  discard block
 block discarded – undo
197 197
 	 *
198 198
 	 * @param GetPaid_Payment_Form_Submission $submission
199 199
 	 */
200
-	public function add_fees( $submission ) {
200
+	public function add_fees($submission) {
201 201
 
202 202
 		$fees = array();
203 203
 
204
-        foreach ( $submission->get_fees() as $name => $data ) {
205
-			$fees[ $name ] = $submission->format_amount( $data['initial_fee'] );
204
+        foreach ($submission->get_fees() as $name => $data) {
205
+			$fees[$name] = $submission->format_amount($data['initial_fee']);
206 206
 		}
207 207
 
208 208
 		$this->response = array_merge(
209 209
 			$this->response,
210
-			array( 'fees' => $fees )
210
+			array('fees' => $fees)
211 211
 		);
212 212
 	}
213 213
 
@@ -216,17 +216,17 @@  discard block
 block discarded – undo
216 216
 	 *
217 217
 	 * @param GetPaid_Payment_Form_Submission $submission
218 218
 	 */
219
-	public function add_discounts( $submission ) {
219
+	public function add_discounts($submission) {
220 220
 
221 221
 		$discounts = array();
222 222
 
223
-        foreach ( $submission->get_discounts() as $name => $data ) {
224
-			$discounts[ $name ] = $submission->format_amount( $data['initial_discount'] );
223
+        foreach ($submission->get_discounts() as $name => $data) {
224
+			$discounts[$name] = $submission->format_amount($data['initial_discount']);
225 225
 		}
226 226
 
227 227
 		$this->response = array_merge(
228 228
 			$this->response,
229
-			array( 'discounts' => $discounts )
229
+			array('discounts' => $discounts)
230 230
 		);
231 231
 	}
232 232
 
@@ -235,20 +235,20 @@  discard block
 block discarded – undo
235 235
 	 *
236 236
 	 * @param GetPaid_Payment_Form_Submission $submission
237 237
 	 */
238
-	public function add_taxes( $submission ) {
238
+	public function add_taxes($submission) {
239 239
 
240 240
 		$taxes  = array();
241 241
 		$markup = '';
242
-        foreach ( $submission->get_taxes() as $name => $data ) {
243
-			$name           = sanitize_text_field( $name );
244
-			$amount         = $submission->format_amount( $data['initial_tax'] );
245
-			$taxes[ $name ] = $amount;
242
+        foreach ($submission->get_taxes() as $name => $data) {
243
+			$name           = sanitize_text_field($name);
244
+			$amount         = $submission->format_amount($data['initial_tax']);
245
+			$taxes[$name] = $amount;
246 246
 			$markup        .= "<small class='form-text'>$name : $amount</small>";
247 247
 		}
248 248
 
249 249
 		$this->response = array_merge(
250 250
 			$this->response,
251
-			array( 'taxes' => $taxes )
251
+			array('taxes' => $taxes)
252 252
 		);
253 253
 	}
254 254
 
@@ -257,27 +257,27 @@  discard block
 block discarded – undo
257 257
 	 *
258 258
 	 * @param GetPaid_Payment_Form_Submission $submission
259 259
 	 */
260
-	public function add_gateways( $submission ) {
260
+	public function add_gateways($submission) {
261 261
 
262
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
262
+		$gateways = array_keys(wpinv_get_enabled_payment_gateways());
263 263
 
264
-		if ( $this->response['has_recurring'] ) {
264
+		if ($this->response['has_recurring']) {
265 265
 
266
-			foreach ( $gateways as $i => $gateway ) {
266
+			foreach ($gateways as $i => $gateway) {
267 267
 
268 268
 				if (
269
-					! getpaid_payment_gateway_supports( $gateway, 'subscription' )
270
-					|| ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
271
-					|| ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
272
-					unset( $gateways[ $i ] );
269
+					!getpaid_payment_gateway_supports($gateway, 'subscription')
270
+					|| ($this->response['has_subscription_group'] && !getpaid_payment_gateway_supports($gateway, 'single_subscription_group'))
271
+					|| ($this->response['has_multiple_subscription_groups'] && !getpaid_payment_gateway_supports($gateway, 'multiple_subscription_groups')) ) {
272
+					unset($gateways[$i]);
273 273
 				}
274 274
             }
275 275
         }
276 276
 
277
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
277
+		$gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission);
278 278
 		$this->response = array_merge(
279 279
 			$this->response,
280
-			array( 'gateways' => $gateways )
280
+			array('gateways' => $gateways)
281 281
 		);
282 282
 	}
283 283
 
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 	 *
287 287
 	 * @param GetPaid_Payment_Form_Submission $submission
288 288
 	 */
289
-	public function add_data( $submission ) {
289
+	public function add_data($submission) {
290 290
 
291 291
 		$this->response = array_merge(
292 292
 			$this->response,
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form.php 2 patches
Indentation   +579 added lines, -579 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,55 +10,55 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form extends GetPaid_Data {
11 11
 
12 12
     /**
13
-	 * Which data store to load.
14
-	 *
15
-	 * @var string
16
-	 */
13
+     * Which data store to load.
14
+     *
15
+     * @var string
16
+     */
17 17
     protected $data_store_name = 'payment_form';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'payment_form';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'payment_form';
25 25
 
26 26
     /**
27
-	 * Form Data array. This is the core form data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'status'        => 'draft',
34
-		'version'       => '',
35
-		'date_created'  => null,
27
+     * Form Data array. This is the core form data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'status'        => 'draft',
34
+        'version'       => '',
35
+        'date_created'  => null,
36 36
         'date_modified' => null,
37 37
         'name'          => '',
38 38
         'author'        => 1,
39 39
         'elements'      => null,
40
-		'items'         => null,
41
-		'earned'        => 0,
42
-		'refunded'      => 0,
43
-		'cancelled'     => 0,
44
-		'failed'        => 0,
45
-	);
46
-
47
-    /**
48
-	 * Stores meta in cache for future reads.
49
-	 *
50
-	 * A group must be set to to enable caching.
51
-	 *
52
-	 * @var string
53
-	 */
54
-	protected $cache_group = 'getpaid_forms';
55
-
56
-	/**
57
-	 * Stores a reference to the invoice if the form is for an invoice..
58
-	 *
59
-	 * @var WPInv_Invoice
60
-	 */
61
-	public $invoice = 0;
40
+        'items'         => null,
41
+        'earned'        => 0,
42
+        'refunded'      => 0,
43
+        'cancelled'     => 0,
44
+        'failed'        => 0,
45
+    );
46
+
47
+    /**
48
+     * Stores meta in cache for future reads.
49
+     *
50
+     * A group must be set to to enable caching.
51
+     *
52
+     * @var string
53
+     */
54
+    protected $cache_group = 'getpaid_forms';
55
+
56
+    /**
57
+     * Stores a reference to the invoice if the form is for an invoice..
58
+     *
59
+     * @var WPInv_Invoice
60
+     */
61
+    public $invoice = 0;
62 62
 
63 63
     /**
64 64
      * Stores a reference to the original WP_Post object
@@ -68,34 +68,34 @@  discard block
 block discarded – undo
68 68
     protected $post = null;
69 69
 
70 70
     /**
71
-	 * Get the form if ID is passed, otherwise the form is new and empty.
72
-	 *
73
-	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
-	 */
75
-	public function __construct( $form = 0 ) {
76
-		parent::__construct( $form );
71
+     * Get the form if ID is passed, otherwise the form is new and empty.
72
+     *
73
+     * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
+     */
75
+    public function __construct( $form = 0 ) {
76
+        parent::__construct( $form );
77 77
 
78
-		if ( is_numeric( $form ) && $form > 0 ) {
79
-			$this->set_id( $form );
80
-		} elseif ( $form instanceof self ) {
78
+        if ( is_numeric( $form ) && $form > 0 ) {
79
+            $this->set_id( $form );
80
+        } elseif ( $form instanceof self ) {
81 81
 
82
-			$this->set_id( $form->get_id() );
83
-			$this->invoice = $form->invoice;
82
+            $this->set_id( $form->get_id() );
83
+            $this->invoice = $form->invoice;
84 84
 
85
-		} elseif ( ! empty( $form->ID ) ) {
86
-			$this->set_id( $form->ID );
87
-		} else {
88
-			$this->set_object_read( true );
89
-		}
85
+        } elseif ( ! empty( $form->ID ) ) {
86
+            $this->set_id( $form->ID );
87
+        } else {
88
+            $this->set_object_read( true );
89
+        }
90 90
 
91 91
         // Load the datastore.
92
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
92
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
93 93
 
94
-		if ( $this->get_id() > 0 ) {
94
+        if ( $this->get_id() > 0 ) {
95 95
             $this->post = get_post( $this->get_id() );
96
-			$this->data_store->read( $this );
96
+            $this->data_store->read( $this );
97 97
         }
98
-	}
98
+    }
99 99
 
100 100
     /*
101 101
 	|--------------------------------------------------------------------------
@@ -113,354 +113,354 @@  discard block
 block discarded – undo
113 113
     */
114 114
 
115 115
     /**
116
-	 * Get plugin version when the form was created.
117
-	 *
118
-	 * @since 1.0.19
119
-	 * @param  string $context View or edit context.
120
-	 * @return string
121
-	 */
122
-	public function get_version( $context = 'view' ) {
123
-		return $this->get_prop( 'version', $context );
116
+     * Get plugin version when the form was created.
117
+     *
118
+     * @since 1.0.19
119
+     * @param  string $context View or edit context.
120
+     * @return string
121
+     */
122
+    public function get_version( $context = 'view' ) {
123
+        return $this->get_prop( 'version', $context );
124 124
     }
125 125
 
126 126
     /**
127
-	 * Get date when the form was created.
128
-	 *
129
-	 * @since 1.0.19
130
-	 * @param  string $context View or edit context.
131
-	 * @return string
132
-	 */
133
-	public function get_date_created( $context = 'view' ) {
134
-		return $this->get_prop( 'date_created', $context );
127
+     * Get date when the form was created.
128
+     *
129
+     * @since 1.0.19
130
+     * @param  string $context View or edit context.
131
+     * @return string
132
+     */
133
+    public function get_date_created( $context = 'view' ) {
134
+        return $this->get_prop( 'date_created', $context );
135 135
     }
136 136
 
137 137
     /**
138
-	 * Get GMT date when the form was created.
139
-	 *
140
-	 * @since 1.0.19
141
-	 * @param  string $context View or edit context.
142
-	 * @return string
143
-	 */
144
-	public function get_date_created_gmt( $context = 'view' ) {
138
+     * Get GMT date when the form was created.
139
+     *
140
+     * @since 1.0.19
141
+     * @param  string $context View or edit context.
142
+     * @return string
143
+     */
144
+    public function get_date_created_gmt( $context = 'view' ) {
145 145
         $date = $this->get_date_created( $context );
146 146
 
147 147
         if ( $date ) {
148 148
             $date = get_gmt_from_date( $date );
149 149
         }
150
-		return $date;
150
+        return $date;
151 151
     }
152 152
 
153 153
     /**
154
-	 * Get date when the form was last modified.
155
-	 *
156
-	 * @since 1.0.19
157
-	 * @param  string $context View or edit context.
158
-	 * @return string
159
-	 */
160
-	public function get_date_modified( $context = 'view' ) {
161
-		return $this->get_prop( 'date_modified', $context );
154
+     * Get date when the form was last modified.
155
+     *
156
+     * @since 1.0.19
157
+     * @param  string $context View or edit context.
158
+     * @return string
159
+     */
160
+    public function get_date_modified( $context = 'view' ) {
161
+        return $this->get_prop( 'date_modified', $context );
162 162
     }
163 163
 
164 164
     /**
165
-	 * Get GMT date when the form was last modified.
166
-	 *
167
-	 * @since 1.0.19
168
-	 * @param  string $context View or edit context.
169
-	 * @return string
170
-	 */
171
-	public function get_date_modified_gmt( $context = 'view' ) {
165
+     * Get GMT date when the form was last modified.
166
+     *
167
+     * @since 1.0.19
168
+     * @param  string $context View or edit context.
169
+     * @return string
170
+     */
171
+    public function get_date_modified_gmt( $context = 'view' ) {
172 172
         $date = $this->get_date_modified( $context );
173 173
 
174 174
         if ( $date ) {
175 175
             $date = get_gmt_from_date( $date );
176 176
         }
177
-		return $date;
177
+        return $date;
178 178
     }
179 179
 
180 180
     /**
181
-	 * Get the form name.
182
-	 *
183
-	 * @since 1.0.19
184
-	 * @param  string $context View or edit context.
185
-	 * @return string
186
-	 */
187
-	public function get_name( $context = 'view' ) {
188
-		return $this->get_prop( 'name', $context );
181
+     * Get the form name.
182
+     *
183
+     * @since 1.0.19
184
+     * @param  string $context View or edit context.
185
+     * @return string
186
+     */
187
+    public function get_name( $context = 'view' ) {
188
+        return $this->get_prop( 'name', $context );
189 189
     }
190 190
 
191 191
     /**
192
-	 * Alias of self::get_name().
193
-	 *
194
-	 * @since 1.0.19
195
-	 * @param  string $context View or edit context.
196
-	 * @return string
197
-	 */
198
-	public function get_title( $context = 'view' ) {
199
-		return $this->get_name( $context );
200
-	}
192
+     * Alias of self::get_name().
193
+     *
194
+     * @since 1.0.19
195
+     * @param  string $context View or edit context.
196
+     * @return string
197
+     */
198
+    public function get_title( $context = 'view' ) {
199
+        return $this->get_name( $context );
200
+    }
201 201
 
202 202
     /**
203
-	 * Get the owner of the form.
204
-	 *
205
-	 * @since 1.0.19
206
-	 * @param  string $context View or edit context.
207
-	 * @return int
208
-	 */
209
-	public function get_author( $context = 'view' ) {
210
-		return (int) $this->get_prop( 'author', $context );
203
+     * Get the owner of the form.
204
+     *
205
+     * @since 1.0.19
206
+     * @param  string $context View or edit context.
207
+     * @return int
208
+     */
209
+    public function get_author( $context = 'view' ) {
210
+        return (int) $this->get_prop( 'author', $context );
211 211
     }
212 212
 
213 213
     /**
214
-	 * Get the elements that make up the form.
215
-	 *
216
-	 * @since 1.0.19
217
-	 * @param  string $context View or edit context.
218
-	 * @return array
219
-	 */
220
-	public function get_elements( $context = 'view' ) {
221
-		$elements = $this->get_prop( 'elements', $context );
214
+     * Get the elements that make up the form.
215
+     *
216
+     * @since 1.0.19
217
+     * @param  string $context View or edit context.
218
+     * @return array
219
+     */
220
+    public function get_elements( $context = 'view' ) {
221
+        $elements = $this->get_prop( 'elements', $context );
222 222
 
223
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
223
+        if ( empty( $elements ) || ! is_array( $elements ) ) {
224 224
             return wpinv_get_data( 'sample-payment-form' );
225
-		}
225
+        }
226 226
 
227
-		// Ensure that all required elements exist.
228
-		$_elements = array();
229
-		foreach ( $elements as $element ) {
227
+        // Ensure that all required elements exist.
228
+        $_elements = array();
229
+        foreach ( $elements as $element ) {
230 230
 
231
-			if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
231
+            if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
232 232
 
233
-				$_elements[] = array(
234
-					'text'    => __( 'Select Payment Method', 'invoicing' ),
235
-					'id'      => 'gtscicd',
236
-					'name'    => 'gtscicd',
237
-					'type'    => 'gateway_select',
238
-					'premade' => true,
233
+                $_elements[] = array(
234
+                    'text'    => __( 'Select Payment Method', 'invoicing' ),
235
+                    'id'      => 'gtscicd',
236
+                    'name'    => 'gtscicd',
237
+                    'type'    => 'gateway_select',
238
+                    'premade' => true,
239 239
 
240
-				);
240
+                );
241 241
 
242
-			}
242
+            }
243 243
 
244
-			$_elements[] = $element;
244
+            $_elements[] = $element;
245 245
 
246
-		}
246
+        }
247 247
 
248 248
         return $_elements;
249
-	}
250
-
251
-	/**
252
-	 * Get the items sold via the form.
253
-	 *
254
-	 * @since 1.0.19
255
-	 * @param  string $context View or edit context.
256
-	 * @param  string $return objects or arrays.
257
-	 * @return GetPaid_Form_Item[]
258
-	 */
259
-	public function get_items( $context = 'view', $return = 'objects' ) {
260
-		$items = $this->get_prop( 'items', $context );
261
-
262
-		if ( empty( $items ) || ! is_array( $items ) ) {
249
+    }
250
+
251
+    /**
252
+     * Get the items sold via the form.
253
+     *
254
+     * @since 1.0.19
255
+     * @param  string $context View or edit context.
256
+     * @param  string $return objects or arrays.
257
+     * @return GetPaid_Form_Item[]
258
+     */
259
+    public function get_items( $context = 'view', $return = 'objects' ) {
260
+        $items = $this->get_prop( 'items', $context );
261
+
262
+        if ( empty( $items ) || ! is_array( $items ) ) {
263 263
             $items = wpinv_get_data( 'sample-payment-form-items' );
264
-		}
264
+        }
265
+
266
+        // Convert the items.
267
+        $prepared = array();
268
+
269
+        foreach ( $items as $key => $value ) {
270
+
271
+            // Form items.
272
+            if ( $value instanceof GetPaid_Form_Item ) {
273
+
274
+                if ( $value->can_purchase() ) {
275
+                    $prepared[] = $value;
276
+                }
277
+
278
+                continue;
265 279
 
266
-		// Convert the items.
267
-		$prepared = array();
280
+            }
281
+
282
+            // $item_id => $quantity (buy buttons)
283
+            if ( is_numeric( $key ) && is_numeric( $value ) ) {
284
+                $item = new GetPaid_Form_Item( $key );
285
+
286
+                if ( $item->can_purchase() ) {
287
+
288
+                    $value = (float) $value;
289
+                    $item->set_quantity( $value );
290
+                    if ( 0 == $value ) {
291
+                        $item->set_quantity( 1 );
292
+                        $item->set_allow_quantities( true );
293
+                    }
294
+
295
+                    $prepared[] = $item;
296
+                }
297
+
298
+                continue;
299
+            }
268 300
 
269
-		foreach ( $items as $key => $value ) {
301
+            // Items saved via payment forms editor.
302
+            if ( is_array( $value ) && isset( $value['id'] ) ) {
270 303
 
271
-			// Form items.
272
-			if ( $value instanceof GetPaid_Form_Item ) {
304
+                $item = new GetPaid_Form_Item( $value['id'] );
273 305
 
274
-				if ( $value->can_purchase() ) {
275
-					$prepared[] = $value;
276
-				}
306
+                if ( ! $item->can_purchase() ) {
307
+                    continue;
308
+                }
277 309
 
278
-				continue;
310
+                // Sub-total (Cart items).
311
+                if ( isset( $value['subtotal'] ) ) {
312
+                    $item->set_price( $value['subtotal'] );
313
+                }
279 314
 
280
-			}
315
+                if ( isset( $value['quantity'] ) ) {
316
+                    $item->set_quantity( $value['quantity'] );
317
+                }
281 318
 
282
-			// $item_id => $quantity (buy buttons)
283
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
284
-				$item = new GetPaid_Form_Item( $key );
319
+                if ( isset( $value['allow_quantities'] ) ) {
320
+                    $item->set_allow_quantities( $value['allow_quantities'] );
321
+                }
285 322
 
286
-				if ( $item->can_purchase() ) {
323
+                if ( isset( $value['required'] ) ) {
324
+                    $item->set_is_required( $value['required'] );
325
+                }
287 326
 
288
-					$value = (float) $value;
289
-					$item->set_quantity( $value );
290
-					if ( 0 == $value ) {
291
-						$item->set_quantity( 1 );
292
-						$item->set_allow_quantities( true );
293
-					}
327
+                if ( isset( $value['description'] ) ) {
328
+                    $item->set_custom_description( $value['description'] );
329
+                }
294 330
 
295
-					$prepared[] = $item;
296
-				}
331
+                $prepared[] = $item;
332
+                continue;
297 333
 
298
-				continue;
299
-			}
334
+            }
300 335
 
301
-			// Items saved via payment forms editor.
302
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
336
+            // $item_id => array( 'price' => 10 ) (item variations)
337
+            if ( is_numeric( $key ) && is_array( $value ) ) {
338
+                $item = new GetPaid_Form_Item( $key );
303 339
 
304
-				$item = new GetPaid_Form_Item( $value['id'] );
340
+                if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
341
+                    $item->set_price( $value['price'] );
342
+                }
305 343
 
306
-				if ( ! $item->can_purchase() ) {
307
-					continue;
308
-				}
344
+                if ( $item->can_purchase() ) {
345
+                    $prepared[] = $item;
346
+                }
309 347
 
310
-				// Sub-total (Cart items).
311
-				if ( isset( $value['subtotal'] ) ) {
312
-					$item->set_price( $value['subtotal'] );
313
-				}
348
+                continue;
349
+            }
350
+        }
314 351
 
315
-				if ( isset( $value['quantity'] ) ) {
316
-					$item->set_quantity( $value['quantity'] );
317
-				}
352
+        if ( 'objects' == $return && 'view' == $context ) {
353
+            return $prepared;
354
+        }
318 355
 
319
-				if ( isset( $value['allow_quantities'] ) ) {
320
-					$item->set_allow_quantities( $value['allow_quantities'] );
321
-				}
356
+        $items = array();
357
+        foreach ( $prepared as $item ) {
358
+            $items[] = $item->prepare_data_for_use();
359
+        }
360
+
361
+        return $items;
362
+    }
322 363
 
323
-				if ( isset( $value['required'] ) ) {
324
-					$item->set_is_required( $value['required'] );
325
-				}
326
-
327
-				if ( isset( $value['description'] ) ) {
328
-					$item->set_custom_description( $value['description'] );
329
-				}
330
-
331
-				$prepared[] = $item;
332
-				continue;
333
-
334
-			}
335
-
336
-			// $item_id => array( 'price' => 10 ) (item variations)
337
-			if ( is_numeric( $key ) && is_array( $value ) ) {
338
-				$item = new GetPaid_Form_Item( $key );
339
-
340
-				if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
341
-					$item->set_price( $value['price'] );
342
-				}
343
-
344
-				if ( $item->can_purchase() ) {
345
-					$prepared[] = $item;
346
-				}
347
-
348
-				continue;
349
-			}
350
-		}
351
-
352
-		if ( 'objects' == $return && 'view' == $context ) {
353
-			return $prepared;
354
-		}
355
-
356
-		$items = array();
357
-		foreach ( $prepared as $item ) {
358
-			$items[] = $item->prepare_data_for_use();
359
-		}
360
-
361
-		return $items;
362
-	}
363
-
364
-	/**
365
-	 * Get a single item belonging to the form.
366
-	 *
367
-	 * @since 1.0.19
368
-	 * @param  int $item_id The item id to return.
369
-	 * @return GetPaid_Form_Item|bool
370
-	 */
371
-	public function get_item( $item_id ) {
372
-
373
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
374
-			return false;
375
-		}
376
-
377
-		foreach ( $this->get_items() as $item ) {
378
-			if ( $item->get_id() == (int) $item_id ) {
379
-				return $item;
380
-			}
381
-		}
382
-
383
-		return false;
384
-	}
385
-
386
-	/**
387
-	 * Gets a single element.
388
-	 *
389
-	 * @since 1.0.19
390
-	 * @param  string $element_type The element type to return.
391
-	 * @return array|bool
392
-	 */
393
-	public function get_element_type( $element_type ) {
394
-
395
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
396
-			return false;
397
-		}
398
-
399
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
400
-
401
-			if ( $element['type'] === $element_type ) {
402
-				return $element;
403
-			}
404
-		}
405
-
406
-		return false;
407
-	}
408
-
409
-	/**
410
-	 * Get the total amount earned via this form.
411
-	 *
412
-	 * @since 1.0.19
413
-	 * @param  string $context View or edit context.
414
-	 * @return float
415
-	 */
416
-	public function get_earned( $context = 'view' ) {
417
-		return $this->get_prop( 'earned', $context );
418
-	}
419
-
420
-	/**
421
-	 * Get the total amount refunded via this form.
422
-	 *
423
-	 * @since 1.0.19
424
-	 * @param  string $context View or edit context.
425
-	 * @return float
426
-	 */
427
-	public function get_refunded( $context = 'view' ) {
428
-		return $this->get_prop( 'refunded', $context );
429
-	}
430
-
431
-	/**
432
-	 * Get the total amount cancelled via this form.
433
-	 *
434
-	 * @since 1.0.19
435
-	 * @param  string $context View or edit context.
436
-	 * @return float
437
-	 */
438
-	public function get_cancelled( $context = 'view' ) {
439
-		return $this->get_prop( 'cancelled', $context );
440
-	}
441
-
442
-	/**
443
-	 * Get the total amount failed via this form.
444
-	 *
445
-	 * @since 1.0.19
446
-	 * @param  string $context View or edit context.
447
-	 * @return float
448
-	 */
449
-	public function get_failed( $context = 'view' ) {
450
-		return $this->get_prop( 'failed', $context );
451
-	}
452
-
453
-	/**
454
-	 * Get the currency.
455
-	 *
456
-	 * @since 1.0.19
457
-	 * @param  string $context View or edit context.
458
-	 * @return string
459
-	 */
460
-	public function get_currency() {
461
-		$currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
462
-		return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
463
-	}
364
+    /**
365
+     * Get a single item belonging to the form.
366
+     *
367
+     * @since 1.0.19
368
+     * @param  int $item_id The item id to return.
369
+     * @return GetPaid_Form_Item|bool
370
+     */
371
+    public function get_item( $item_id ) {
372
+
373
+        if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
374
+            return false;
375
+        }
376
+
377
+        foreach ( $this->get_items() as $item ) {
378
+            if ( $item->get_id() == (int) $item_id ) {
379
+                return $item;
380
+            }
381
+        }
382
+
383
+        return false;
384
+    }
385
+
386
+    /**
387
+     * Gets a single element.
388
+     *
389
+     * @since 1.0.19
390
+     * @param  string $element_type The element type to return.
391
+     * @return array|bool
392
+     */
393
+    public function get_element_type( $element_type ) {
394
+
395
+        if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
396
+            return false;
397
+        }
398
+
399
+        foreach ( $this->get_prop( 'elements' ) as $element ) {
400
+
401
+            if ( $element['type'] === $element_type ) {
402
+                return $element;
403
+            }
404
+        }
405
+
406
+        return false;
407
+    }
408
+
409
+    /**
410
+     * Get the total amount earned via this form.
411
+     *
412
+     * @since 1.0.19
413
+     * @param  string $context View or edit context.
414
+     * @return float
415
+     */
416
+    public function get_earned( $context = 'view' ) {
417
+        return $this->get_prop( 'earned', $context );
418
+    }
419
+
420
+    /**
421
+     * Get the total amount refunded via this form.
422
+     *
423
+     * @since 1.0.19
424
+     * @param  string $context View or edit context.
425
+     * @return float
426
+     */
427
+    public function get_refunded( $context = 'view' ) {
428
+        return $this->get_prop( 'refunded', $context );
429
+    }
430
+
431
+    /**
432
+     * Get the total amount cancelled via this form.
433
+     *
434
+     * @since 1.0.19
435
+     * @param  string $context View or edit context.
436
+     * @return float
437
+     */
438
+    public function get_cancelled( $context = 'view' ) {
439
+        return $this->get_prop( 'cancelled', $context );
440
+    }
441
+
442
+    /**
443
+     * Get the total amount failed via this form.
444
+     *
445
+     * @since 1.0.19
446
+     * @param  string $context View or edit context.
447
+     * @return float
448
+     */
449
+    public function get_failed( $context = 'view' ) {
450
+        return $this->get_prop( 'failed', $context );
451
+    }
452
+
453
+    /**
454
+     * Get the currency.
455
+     *
456
+     * @since 1.0.19
457
+     * @param  string $context View or edit context.
458
+     * @return string
459
+     */
460
+    public function get_currency() {
461
+        $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
462
+        return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
463
+    }
464 464
 
465 465
     /*
466 466
 	|--------------------------------------------------------------------------
@@ -473,22 +473,22 @@  discard block
 block discarded – undo
473 473
     */
474 474
 
475 475
     /**
476
-	 * Set plugin version when the item was created.
477
-	 *
478
-	 * @since 1.0.19
479
-	 */
480
-	public function set_version( $value ) {
481
-		$this->set_prop( 'version', $value );
476
+     * Set plugin version when the item was created.
477
+     *
478
+     * @since 1.0.19
479
+     */
480
+    public function set_version( $value ) {
481
+        $this->set_prop( 'version', $value );
482 482
     }
483 483
 
484 484
     /**
485
-	 * Set date when the item was created.
486
-	 *
487
-	 * @since 1.0.19
488
-	 * @param string $value Value to set.
485
+     * Set date when the item was created.
486
+     *
487
+     * @since 1.0.19
488
+     * @param string $value Value to set.
489 489
      * @return bool Whether or not the date was set.
490
-	 */
491
-	public function set_date_created( $value ) {
490
+     */
491
+    public function set_date_created( $value ) {
492 492
         $date = strtotime( $value );
493 493
 
494 494
         if ( $date ) {
@@ -500,13 +500,13 @@  discard block
 block discarded – undo
500 500
     }
501 501
 
502 502
     /**
503
-	 * Set date when the item was last modified.
504
-	 *
505
-	 * @since 1.0.19
506
-	 * @param string $value Value to set.
503
+     * Set date when the item was last modified.
504
+     *
505
+     * @since 1.0.19
506
+     * @param string $value Value to set.
507 507
      * @return bool Whether or not the date was set.
508
-	 */
509
-	public function set_date_modified( $value ) {
508
+     */
509
+    public function set_date_modified( $value ) {
510 510
         $date = strtotime( $value );
511 511
 
512 512
         if ( $date ) {
@@ -518,171 +518,171 @@  discard block
 block discarded – undo
518 518
     }
519 519
 
520 520
     /**
521
-	 * Set the item name.
522
-	 *
523
-	 * @since 1.0.19
524
-	 * @param  string $value New name.
525
-	 */
526
-	public function set_name( $value ) {
527
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
528
-    }
529
-
530
-    /**
531
-	 * Alias of self::set_name().
532
-	 *
533
-	 * @since 1.0.19
534
-	 * @param  string $value New name.
535
-	 */
536
-	public function set_title( $value ) {
537
-		$this->set_name( $value );
538
-    }
539
-
540
-    /**
541
-	 * Set the owner of the item.
542
-	 *
543
-	 * @since 1.0.19
544
-	 * @param  int $value New author.
545
-	 */
546
-	public function set_author( $value ) {
547
-		$this->set_prop( 'author', (int) $value );
548
-	}
549
-
550
-	/**
551
-	 * Set the form elements.
552
-	 *
553
-	 * @since 1.0.19
554
-	 * @sinve 2.3.4 Array values sanitized.
555
-	 * @param  array $value Form elements.
556
-	 */
557
-	public function set_elements( $value ) {
558
-		if ( is_array( $value ) ) {
559
-			$this->set_prop( 'elements', wp_kses_post_deep( $value ) );
560
-		}
561
-	}
562
-
563
-	/**
564
-	 * Sanitize array values.
565
-	 *
566
-	 * @param $value
567
-	 *
568
-	 * @return mixed
569
-	 */
570
-	public function sanitize_array_values( $value ) {
571
-
572
-		// sanitize
573
-		if ( ! empty( $value ) ) {
574
-
575
-			foreach ( $value as $key => $val_arr ) {
576
-
577
-				if ( is_array( $val_arr ) ) {
578
-					// check if we have sub array items.
579
-					$sub_arr = array();
580
-					foreach ( $val_arr as $key2 => $val2 ) {
581
-						if ( is_array( $val2 ) ) {
582
-							$sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 );
583
-							unset( $val_arr[ $key ][ $key2 ] );
584
-						}
585
-					}
586
-
587
-					// we allow some html in description so we sanitize it separately.
588
-					$help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : '';
589
-
590
-					// sanitize array elements
591
-					$value[ $key ] = array_map( 'sanitize_text_field', $val_arr );
592
-
593
-					// add back the description if set
594
-					if ( isset( $val_arr['description'] ) ) {
521
+     * Set the item name.
522
+     *
523
+     * @since 1.0.19
524
+     * @param  string $value New name.
525
+     */
526
+    public function set_name( $value ) {
527
+        $this->set_prop( 'name', sanitize_text_field( $value ) );
528
+    }
529
+
530
+    /**
531
+     * Alias of self::set_name().
532
+     *
533
+     * @since 1.0.19
534
+     * @param  string $value New name.
535
+     */
536
+    public function set_title( $value ) {
537
+        $this->set_name( $value );
538
+    }
539
+
540
+    /**
541
+     * Set the owner of the item.
542
+     *
543
+     * @since 1.0.19
544
+     * @param  int $value New author.
545
+     */
546
+    public function set_author( $value ) {
547
+        $this->set_prop( 'author', (int) $value );
548
+    }
549
+
550
+    /**
551
+     * Set the form elements.
552
+     *
553
+     * @since 1.0.19
554
+     * @sinve 2.3.4 Array values sanitized.
555
+     * @param  array $value Form elements.
556
+     */
557
+    public function set_elements( $value ) {
558
+        if ( is_array( $value ) ) {
559
+            $this->set_prop( 'elements', wp_kses_post_deep( $value ) );
560
+        }
561
+    }
562
+
563
+    /**
564
+     * Sanitize array values.
565
+     *
566
+     * @param $value
567
+     *
568
+     * @return mixed
569
+     */
570
+    public function sanitize_array_values( $value ) {
571
+
572
+        // sanitize
573
+        if ( ! empty( $value ) ) {
574
+
575
+            foreach ( $value as $key => $val_arr ) {
576
+
577
+                if ( is_array( $val_arr ) ) {
578
+                    // check if we have sub array items.
579
+                    $sub_arr = array();
580
+                    foreach ( $val_arr as $key2 => $val2 ) {
581
+                        if ( is_array( $val2 ) ) {
582
+                            $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 );
583
+                            unset( $val_arr[ $key ][ $key2 ] );
584
+                        }
585
+                    }
586
+
587
+                    // we allow some html in description so we sanitize it separately.
588
+                    $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : '';
589
+
590
+                    // sanitize array elements
591
+                    $value[ $key ] = array_map( 'sanitize_text_field', $val_arr );
592
+
593
+                    // add back the description if set
594
+                    if ( isset( $val_arr['description'] ) ) {
595 595
                         $value[ $key ]['description'] = $help_text;}
596 596
 
597
-					// add back sub array items after its been sanitized.
598
-					if ( ! empty( $sub_arr ) ) {
599
-						$value[ $key ] = array_merge( $value[ $key ], $sub_arr );
600
-					}
601
-				}
597
+                    // add back sub array items after its been sanitized.
598
+                    if ( ! empty( $sub_arr ) ) {
599
+                        $value[ $key ] = array_merge( $value[ $key ], $sub_arr );
600
+                    }
601
+                }
602 602
             }
603 603
         }
604 604
 
605
-		return $value;
606
-	}
607
-
608
-	/**
609
-	 * Set the form items.
610
-	 *
611
-	 * @since 1.0.19
612
-	 * @param  array $value Form elements.
613
-	 */
614
-	public function set_items( $value ) {
615
-		if ( is_array( $value ) ) {
616
-			$this->set_prop( 'items', $value );
617
-		}
618
-	}
619
-
620
-	/**
621
-	 * Set the total amount earned via this form.
622
-	 *
623
-	 * @since 1.0.19
624
-	 * @param  float $value Amount earned.
625
-	 */
626
-	public function set_earned( $value ) {
627
-		$value = max( (float) $value, 0 );
628
-		$this->set_prop( 'earned', $value );
629
-	}
630
-
631
-	/**
632
-	 * Set the total amount refunded via this form.
633
-	 *
634
-	 * @since 1.0.19
635
-	 * @param  float $value Amount refunded.
636
-	 */
637
-	public function set_refunded( $value ) {
638
-		$value = max( (float) $value, 0 );
639
-		$this->set_prop( 'refunded', $value );
640
-	}
641
-
642
-	/**
643
-	 * Set the total amount cancelled via this form.
644
-	 *
645
-	 * @since 1.0.19
646
-	 * @param  float $value Amount cancelled.
647
-	 */
648
-	public function set_cancelled( $value ) {
649
-		$value = max( (float) $value, 0 );
650
-		$this->set_prop( 'cancelled', $value );
651
-	}
652
-
653
-	/**
654
-	 * Set the total amount failed via this form.
655
-	 *
656
-	 * @since 1.0.19
657
-	 * @param  float $value Amount cancelled.
658
-	 */
659
-	public function set_failed( $value ) {
660
-		$value = max( (float) $value, 0 );
661
-		$this->set_prop( 'failed', $value );
662
-	}
605
+        return $value;
606
+    }
607
+
608
+    /**
609
+     * Set the form items.
610
+     *
611
+     * @since 1.0.19
612
+     * @param  array $value Form elements.
613
+     */
614
+    public function set_items( $value ) {
615
+        if ( is_array( $value ) ) {
616
+            $this->set_prop( 'items', $value );
617
+        }
618
+    }
619
+
620
+    /**
621
+     * Set the total amount earned via this form.
622
+     *
623
+     * @since 1.0.19
624
+     * @param  float $value Amount earned.
625
+     */
626
+    public function set_earned( $value ) {
627
+        $value = max( (float) $value, 0 );
628
+        $this->set_prop( 'earned', $value );
629
+    }
630
+
631
+    /**
632
+     * Set the total amount refunded via this form.
633
+     *
634
+     * @since 1.0.19
635
+     * @param  float $value Amount refunded.
636
+     */
637
+    public function set_refunded( $value ) {
638
+        $value = max( (float) $value, 0 );
639
+        $this->set_prop( 'refunded', $value );
640
+    }
641
+
642
+    /**
643
+     * Set the total amount cancelled via this form.
644
+     *
645
+     * @since 1.0.19
646
+     * @param  float $value Amount cancelled.
647
+     */
648
+    public function set_cancelled( $value ) {
649
+        $value = max( (float) $value, 0 );
650
+        $this->set_prop( 'cancelled', $value );
651
+    }
652
+
653
+    /**
654
+     * Set the total amount failed via this form.
655
+     *
656
+     * @since 1.0.19
657
+     * @param  float $value Amount cancelled.
658
+     */
659
+    public function set_failed( $value ) {
660
+        $value = max( (float) $value, 0 );
661
+        $this->set_prop( 'failed', $value );
662
+    }
663 663
 
664 664
     /**
665 665
      * Create an item. For backwards compatibilty.
666 666
      *
667 667
      * @deprecated
668
-	 * @return int item id
668
+     * @return int item id
669 669
      */
670 670
     public function create( $data = array() ) {
671 671
 
672
-		// Set the properties.
673
-		if ( is_array( $data ) ) {
674
-			$this->set_props( $data );
675
-		}
672
+        // Set the properties.
673
+        if ( is_array( $data ) ) {
674
+            $this->set_props( $data );
675
+        }
676 676
 
677
-		// Save the item.
678
-		return $this->save();
677
+        // Save the item.
678
+        return $this->save();
679 679
     }
680 680
 
681 681
     /**
682 682
      * Updates an item. For backwards compatibilty.
683 683
      *
684 684
      * @deprecated
685
-	 * @return int item id
685
+     * @return int item id
686 686
      */
687 687
     public function update( $data = array() ) {
688 688
         return $this->create( $data );
@@ -698,22 +698,22 @@  discard block
 block discarded – undo
698 698
 	*/
699 699
 
700 700
     /**
701
-	 * Checks whether this is the default payment form.
702
-	 *
703
-	 * @since 1.0.19
704
-	 * @return bool
705
-	 */
701
+     * Checks whether this is the default payment form.
702
+     *
703
+     * @since 1.0.19
704
+     * @return bool
705
+     */
706 706
     public function is_default() {
707 707
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
708 708
         return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
709
-	}
709
+    }
710 710
 
711 711
     /**
712
-	 * Checks whether the form is active.
713
-	 *
714
-	 * @since 1.0.19
715
-	 * @return bool
716
-	 */
712
+     * Checks whether the form is active.
713
+     *
714
+     * @since 1.0.19
715
+     * @return bool
716
+     */
717 717
     public function is_active() {
718 718
         $is_active = 0 !== (int) $this->get_id();
719 719
 
@@ -722,79 +722,79 @@  discard block
 block discarded – undo
722 722
         }
723 723
 
724 724
         return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
725
-	}
726
-
727
-	/**
728
-	 * Checks whether the form has a given item.
729
-	 *
730
-	 * @since 1.0.19
731
-	 * @return bool
732
-	 */
725
+    }
726
+
727
+    /**
728
+     * Checks whether the form has a given item.
729
+     *
730
+     * @since 1.0.19
731
+     * @return bool
732
+     */
733 733
     public function has_item( $item_id ) {
734 734
         return false !== $this->get_item( $item_id );
735
-	}
736
-
737
-	/**
738
-	 * Checks whether the form has a given element.
739
-	 *
740
-	 * @since 1.0.19
741
-	 * @return bool
742
-	 */
735
+    }
736
+
737
+    /**
738
+     * Checks whether the form has a given element.
739
+     *
740
+     * @since 1.0.19
741
+     * @return bool
742
+     */
743 743
     public function has_element_type( $element_type ) {
744 744
         return false !== $this->get_element_type( $element_type );
745
-	}
746
-
747
-	/**
748
-	 * Checks whether this form is recurring or not.
749
-	 *
750
-	 * @since 1.0.19
751
-	 * @return bool
752
-	 */
745
+    }
746
+
747
+    /**
748
+     * Checks whether this form is recurring or not.
749
+     *
750
+     * @since 1.0.19
751
+     * @return bool
752
+     */
753 753
     public function is_recurring() {
754 754
 
755
-		if ( ! empty( $this->invoice ) ) {
756
-			return $this->invoice->is_recurring();
757
-		}
755
+        if ( ! empty( $this->invoice ) ) {
756
+            return $this->invoice->is_recurring();
757
+        }
758 758
 
759
-		foreach ( $this->get_items() as $item ) {
759
+        foreach ( $this->get_items() as $item ) {
760 760
 
761
-			if ( $item->is_recurring() ) {
762
-				return true;
763
-			}
761
+            if ( $item->is_recurring() ) {
762
+                return true;
763
+            }
764 764
         }
765 765
 
766 766
         return false;
767
-	}
767
+    }
768 768
 
769
-	/**
770
-	 * Retrieves the form's html.
771
-	 *
772
-	 * @since 1.0.19
773
-	 */
769
+    /**
770
+     * Retrieves the form's html.
771
+     *
772
+     * @since 1.0.19
773
+     */
774 774
     public function get_html( $extra_markup = '' ) {
775 775
 
776
-		// Return the HTML.
777
-		return wpinv_get_template_html(
778
-			'payment-forms/form.php',
779
-			array(
780
-				'form'         => $this,
781
-				'extra_markup' => $extra_markup,
782
-			)
783
-		);
784
-	}
785
-
786
-	/**
787
-	 * Displays the payment form.
788
-	 *
789
-	 * @since 1.0.19
790
-	 */
776
+        // Return the HTML.
777
+        return wpinv_get_template_html(
778
+            'payment-forms/form.php',
779
+            array(
780
+                'form'         => $this,
781
+                'extra_markup' => $extra_markup,
782
+            )
783
+        );
784
+    }
785
+
786
+    /**
787
+     * Displays the payment form.
788
+     *
789
+     * @since 1.0.19
790
+     */
791 791
     public function display( $extra_markup = '' ) {
792
-		wpinv_get_template(
793
-			'payment-forms/form.php',
794
-			array(
795
-				'form'         => $this,
796
-				'extra_markup' => $extra_markup,
797
-			)
798
-		);
792
+        wpinv_get_template(
793
+            'payment-forms/form.php',
794
+            array(
795
+                'form'         => $this,
796
+                'extra_markup' => $extra_markup,
797
+            )
798
+        );
799 799
     }
800 800
 }
Please login to merge, or discard this patch.
Spacing   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -72,28 +72,28 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74 74
 	 */
75
-	public function __construct( $form = 0 ) {
76
-		parent::__construct( $form );
75
+	public function __construct($form = 0) {
76
+		parent::__construct($form);
77 77
 
78
-		if ( is_numeric( $form ) && $form > 0 ) {
79
-			$this->set_id( $form );
80
-		} elseif ( $form instanceof self ) {
78
+		if (is_numeric($form) && $form > 0) {
79
+			$this->set_id($form);
80
+		} elseif ($form instanceof self) {
81 81
 
82
-			$this->set_id( $form->get_id() );
82
+			$this->set_id($form->get_id());
83 83
 			$this->invoice = $form->invoice;
84 84
 
85
-		} elseif ( ! empty( $form->ID ) ) {
86
-			$this->set_id( $form->ID );
85
+		} elseif (!empty($form->ID)) {
86
+			$this->set_id($form->ID);
87 87
 		} else {
88
-			$this->set_object_read( true );
88
+			$this->set_object_read(true);
89 89
 		}
90 90
 
91 91
         // Load the datastore.
92
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
92
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
93 93
 
94
-		if ( $this->get_id() > 0 ) {
95
-            $this->post = get_post( $this->get_id() );
96
-			$this->data_store->read( $this );
94
+		if ($this->get_id() > 0) {
95
+            $this->post = get_post($this->get_id());
96
+			$this->data_store->read($this);
97 97
         }
98 98
 	}
99 99
 
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
 	 * @param  string $context View or edit context.
120 120
 	 * @return string
121 121
 	 */
122
-	public function get_version( $context = 'view' ) {
123
-		return $this->get_prop( 'version', $context );
122
+	public function get_version($context = 'view') {
123
+		return $this->get_prop('version', $context);
124 124
     }
125 125
 
126 126
     /**
@@ -130,8 +130,8 @@  discard block
 block discarded – undo
130 130
 	 * @param  string $context View or edit context.
131 131
 	 * @return string
132 132
 	 */
133
-	public function get_date_created( $context = 'view' ) {
134
-		return $this->get_prop( 'date_created', $context );
133
+	public function get_date_created($context = 'view') {
134
+		return $this->get_prop('date_created', $context);
135 135
     }
136 136
 
137 137
     /**
@@ -141,11 +141,11 @@  discard block
 block discarded – undo
141 141
 	 * @param  string $context View or edit context.
142 142
 	 * @return string
143 143
 	 */
144
-	public function get_date_created_gmt( $context = 'view' ) {
145
-        $date = $this->get_date_created( $context );
144
+	public function get_date_created_gmt($context = 'view') {
145
+        $date = $this->get_date_created($context);
146 146
 
147
-        if ( $date ) {
148
-            $date = get_gmt_from_date( $date );
147
+        if ($date) {
148
+            $date = get_gmt_from_date($date);
149 149
         }
150 150
 		return $date;
151 151
     }
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
 	 * @param  string $context View or edit context.
158 158
 	 * @return string
159 159
 	 */
160
-	public function get_date_modified( $context = 'view' ) {
161
-		return $this->get_prop( 'date_modified', $context );
160
+	public function get_date_modified($context = 'view') {
161
+		return $this->get_prop('date_modified', $context);
162 162
     }
163 163
 
164 164
     /**
@@ -168,11 +168,11 @@  discard block
 block discarded – undo
168 168
 	 * @param  string $context View or edit context.
169 169
 	 * @return string
170 170
 	 */
171
-	public function get_date_modified_gmt( $context = 'view' ) {
172
-        $date = $this->get_date_modified( $context );
171
+	public function get_date_modified_gmt($context = 'view') {
172
+        $date = $this->get_date_modified($context);
173 173
 
174
-        if ( $date ) {
175
-            $date = get_gmt_from_date( $date );
174
+        if ($date) {
175
+            $date = get_gmt_from_date($date);
176 176
         }
177 177
 		return $date;
178 178
     }
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 	 * @param  string $context View or edit context.
185 185
 	 * @return string
186 186
 	 */
187
-	public function get_name( $context = 'view' ) {
188
-		return $this->get_prop( 'name', $context );
187
+	public function get_name($context = 'view') {
188
+		return $this->get_prop('name', $context);
189 189
     }
190 190
 
191 191
     /**
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
 	 * @param  string $context View or edit context.
196 196
 	 * @return string
197 197
 	 */
198
-	public function get_title( $context = 'view' ) {
199
-		return $this->get_name( $context );
198
+	public function get_title($context = 'view') {
199
+		return $this->get_name($context);
200 200
 	}
201 201
 
202 202
     /**
@@ -206,8 +206,8 @@  discard block
 block discarded – undo
206 206
 	 * @param  string $context View or edit context.
207 207
 	 * @return int
208 208
 	 */
209
-	public function get_author( $context = 'view' ) {
210
-		return (int) $this->get_prop( 'author', $context );
209
+	public function get_author($context = 'view') {
210
+		return (int) $this->get_prop('author', $context);
211 211
     }
212 212
 
213 213
     /**
@@ -217,21 +217,21 @@  discard block
 block discarded – undo
217 217
 	 * @param  string $context View or edit context.
218 218
 	 * @return array
219 219
 	 */
220
-	public function get_elements( $context = 'view' ) {
221
-		$elements = $this->get_prop( 'elements', $context );
220
+	public function get_elements($context = 'view') {
221
+		$elements = $this->get_prop('elements', $context);
222 222
 
223
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
224
-            return wpinv_get_data( 'sample-payment-form' );
223
+		if (empty($elements) || !is_array($elements)) {
224
+            return wpinv_get_data('sample-payment-form');
225 225
 		}
226 226
 
227 227
 		// Ensure that all required elements exist.
228 228
 		$_elements = array();
229
-		foreach ( $elements as $element ) {
229
+		foreach ($elements as $element) {
230 230
 
231
-			if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
231
+			if ($element['type'] == 'pay_button' && !$this->has_element_type('gateway_select')) {
232 232
 
233 233
 				$_elements[] = array(
234
-					'text'    => __( 'Select Payment Method', 'invoicing' ),
234
+					'text'    => __('Select Payment Method', 'invoicing'),
235 235
 					'id'      => 'gtscicd',
236 236
 					'name'    => 'gtscicd',
237 237
 					'type'    => 'gateway_select',
@@ -256,22 +256,22 @@  discard block
 block discarded – undo
256 256
 	 * @param  string $return objects or arrays.
257 257
 	 * @return GetPaid_Form_Item[]
258 258
 	 */
259
-	public function get_items( $context = 'view', $return = 'objects' ) {
260
-		$items = $this->get_prop( 'items', $context );
259
+	public function get_items($context = 'view', $return = 'objects') {
260
+		$items = $this->get_prop('items', $context);
261 261
 
262
-		if ( empty( $items ) || ! is_array( $items ) ) {
263
-            $items = wpinv_get_data( 'sample-payment-form-items' );
262
+		if (empty($items) || !is_array($items)) {
263
+            $items = wpinv_get_data('sample-payment-form-items');
264 264
 		}
265 265
 
266 266
 		// Convert the items.
267 267
 		$prepared = array();
268 268
 
269
-		foreach ( $items as $key => $value ) {
269
+		foreach ($items as $key => $value) {
270 270
 
271 271
 			// Form items.
272
-			if ( $value instanceof GetPaid_Form_Item ) {
272
+			if ($value instanceof GetPaid_Form_Item) {
273 273
 
274
-				if ( $value->can_purchase() ) {
274
+				if ($value->can_purchase()) {
275 275
 					$prepared[] = $value;
276 276
 				}
277 277
 
@@ -280,16 +280,16 @@  discard block
 block discarded – undo
280 280
 			}
281 281
 
282 282
 			// $item_id => $quantity (buy buttons)
283
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
284
-				$item = new GetPaid_Form_Item( $key );
283
+			if (is_numeric($key) && is_numeric($value)) {
284
+				$item = new GetPaid_Form_Item($key);
285 285
 
286
-				if ( $item->can_purchase() ) {
286
+				if ($item->can_purchase()) {
287 287
 
288 288
 					$value = (float) $value;
289
-					$item->set_quantity( $value );
290
-					if ( 0 == $value ) {
291
-						$item->set_quantity( 1 );
292
-						$item->set_allow_quantities( true );
289
+					$item->set_quantity($value);
290
+					if (0 == $value) {
291
+						$item->set_quantity(1);
292
+						$item->set_allow_quantities(true);
293 293
 					}
294 294
 
295 295
 					$prepared[] = $item;
@@ -299,33 +299,33 @@  discard block
 block discarded – undo
299 299
 			}
300 300
 
301 301
 			// Items saved via payment forms editor.
302
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
302
+			if (is_array($value) && isset($value['id'])) {
303 303
 
304
-				$item = new GetPaid_Form_Item( $value['id'] );
304
+				$item = new GetPaid_Form_Item($value['id']);
305 305
 
306
-				if ( ! $item->can_purchase() ) {
306
+				if (!$item->can_purchase()) {
307 307
 					continue;
308 308
 				}
309 309
 
310 310
 				// Sub-total (Cart items).
311
-				if ( isset( $value['subtotal'] ) ) {
312
-					$item->set_price( $value['subtotal'] );
311
+				if (isset($value['subtotal'])) {
312
+					$item->set_price($value['subtotal']);
313 313
 				}
314 314
 
315
-				if ( isset( $value['quantity'] ) ) {
316
-					$item->set_quantity( $value['quantity'] );
315
+				if (isset($value['quantity'])) {
316
+					$item->set_quantity($value['quantity']);
317 317
 				}
318 318
 
319
-				if ( isset( $value['allow_quantities'] ) ) {
320
-					$item->set_allow_quantities( $value['allow_quantities'] );
319
+				if (isset($value['allow_quantities'])) {
320
+					$item->set_allow_quantities($value['allow_quantities']);
321 321
 				}
322 322
 
323
-				if ( isset( $value['required'] ) ) {
324
-					$item->set_is_required( $value['required'] );
323
+				if (isset($value['required'])) {
324
+					$item->set_is_required($value['required']);
325 325
 				}
326 326
 
327
-				if ( isset( $value['description'] ) ) {
328
-					$item->set_custom_description( $value['description'] );
327
+				if (isset($value['description'])) {
328
+					$item->set_custom_description($value['description']);
329 329
 				}
330 330
 
331 331
 				$prepared[] = $item;
@@ -334,14 +334,14 @@  discard block
 block discarded – undo
334 334
 			}
335 335
 
336 336
 			// $item_id => array( 'price' => 10 ) (item variations)
337
-			if ( is_numeric( $key ) && is_array( $value ) ) {
338
-				$item = new GetPaid_Form_Item( $key );
337
+			if (is_numeric($key) && is_array($value)) {
338
+				$item = new GetPaid_Form_Item($key);
339 339
 
340
-				if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
341
-					$item->set_price( $value['price'] );
340
+				if (isset($value['price']) && $item->user_can_set_their_price()) {
341
+					$item->set_price($value['price']);
342 342
 				}
343 343
 
344
-				if ( $item->can_purchase() ) {
344
+				if ($item->can_purchase()) {
345 345
 					$prepared[] = $item;
346 346
 				}
347 347
 
@@ -349,12 +349,12 @@  discard block
 block discarded – undo
349 349
 			}
350 350
 		}
351 351
 
352
-		if ( 'objects' == $return && 'view' == $context ) {
352
+		if ('objects' == $return && 'view' == $context) {
353 353
 			return $prepared;
354 354
 		}
355 355
 
356 356
 		$items = array();
357
-		foreach ( $prepared as $item ) {
357
+		foreach ($prepared as $item) {
358 358
 			$items[] = $item->prepare_data_for_use();
359 359
 		}
360 360
 
@@ -368,14 +368,14 @@  discard block
 block discarded – undo
368 368
 	 * @param  int $item_id The item id to return.
369 369
 	 * @return GetPaid_Form_Item|bool
370 370
 	 */
371
-	public function get_item( $item_id ) {
371
+	public function get_item($item_id) {
372 372
 
373
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
373
+		if (empty($item_id) || !is_numeric($item_id)) {
374 374
 			return false;
375 375
 		}
376 376
 
377
-		foreach ( $this->get_items() as $item ) {
378
-			if ( $item->get_id() == (int) $item_id ) {
377
+		foreach ($this->get_items() as $item) {
378
+			if ($item->get_id() == (int) $item_id) {
379 379
 				return $item;
380 380
 			}
381 381
 		}
@@ -390,15 +390,15 @@  discard block
 block discarded – undo
390 390
 	 * @param  string $element_type The element type to return.
391 391
 	 * @return array|bool
392 392
 	 */
393
-	public function get_element_type( $element_type ) {
393
+	public function get_element_type($element_type) {
394 394
 
395
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
395
+		if (empty($element_type) || !is_scalar($element_type)) {
396 396
 			return false;
397 397
 		}
398 398
 
399
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
399
+		foreach ($this->get_prop('elements') as $element) {
400 400
 
401
-			if ( $element['type'] === $element_type ) {
401
+			if ($element['type'] === $element_type) {
402 402
 				return $element;
403 403
 			}
404 404
 		}
@@ -413,8 +413,8 @@  discard block
 block discarded – undo
413 413
 	 * @param  string $context View or edit context.
414 414
 	 * @return float
415 415
 	 */
416
-	public function get_earned( $context = 'view' ) {
417
-		return $this->get_prop( 'earned', $context );
416
+	public function get_earned($context = 'view') {
417
+		return $this->get_prop('earned', $context);
418 418
 	}
419 419
 
420 420
 	/**
@@ -424,8 +424,8 @@  discard block
 block discarded – undo
424 424
 	 * @param  string $context View or edit context.
425 425
 	 * @return float
426 426
 	 */
427
-	public function get_refunded( $context = 'view' ) {
428
-		return $this->get_prop( 'refunded', $context );
427
+	public function get_refunded($context = 'view') {
428
+		return $this->get_prop('refunded', $context);
429 429
 	}
430 430
 
431 431
 	/**
@@ -435,8 +435,8 @@  discard block
 block discarded – undo
435 435
 	 * @param  string $context View or edit context.
436 436
 	 * @return float
437 437
 	 */
438
-	public function get_cancelled( $context = 'view' ) {
439
-		return $this->get_prop( 'cancelled', $context );
438
+	public function get_cancelled($context = 'view') {
439
+		return $this->get_prop('cancelled', $context);
440 440
 	}
441 441
 
442 442
 	/**
@@ -446,8 +446,8 @@  discard block
 block discarded – undo
446 446
 	 * @param  string $context View or edit context.
447 447
 	 * @return float
448 448
 	 */
449
-	public function get_failed( $context = 'view' ) {
450
-		return $this->get_prop( 'failed', $context );
449
+	public function get_failed($context = 'view') {
450
+		return $this->get_prop('failed', $context);
451 451
 	}
452 452
 
453 453
 	/**
@@ -458,8 +458,8 @@  discard block
 block discarded – undo
458 458
 	 * @return string
459 459
 	 */
460 460
 	public function get_currency() {
461
-		$currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
462
-		return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
461
+		$currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency();
462
+		return apply_filters('getpaid-payment-form-currency', $currency, $this);
463 463
 	}
464 464
 
465 465
     /*
@@ -477,8 +477,8 @@  discard block
 block discarded – undo
477 477
 	 *
478 478
 	 * @since 1.0.19
479 479
 	 */
480
-	public function set_version( $value ) {
481
-		$this->set_prop( 'version', $value );
480
+	public function set_version($value) {
481
+		$this->set_prop('version', $value);
482 482
     }
483 483
 
484 484
     /**
@@ -488,11 +488,11 @@  discard block
 block discarded – undo
488 488
 	 * @param string $value Value to set.
489 489
      * @return bool Whether or not the date was set.
490 490
 	 */
491
-	public function set_date_created( $value ) {
492
-        $date = strtotime( $value );
491
+	public function set_date_created($value) {
492
+        $date = strtotime($value);
493 493
 
494
-        if ( $date ) {
495
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
494
+        if ($date) {
495
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
496 496
             return true;
497 497
         }
498 498
 
@@ -506,11 +506,11 @@  discard block
 block discarded – undo
506 506
 	 * @param string $value Value to set.
507 507
      * @return bool Whether or not the date was set.
508 508
 	 */
509
-	public function set_date_modified( $value ) {
510
-        $date = strtotime( $value );
509
+	public function set_date_modified($value) {
510
+        $date = strtotime($value);
511 511
 
512
-        if ( $date ) {
513
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
512
+        if ($date) {
513
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
514 514
             return true;
515 515
         }
516 516
 
@@ -523,8 +523,8 @@  discard block
 block discarded – undo
523 523
 	 * @since 1.0.19
524 524
 	 * @param  string $value New name.
525 525
 	 */
526
-	public function set_name( $value ) {
527
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
526
+	public function set_name($value) {
527
+		$this->set_prop('name', sanitize_text_field($value));
528 528
     }
529 529
 
530 530
     /**
@@ -533,8 +533,8 @@  discard block
 block discarded – undo
533 533
 	 * @since 1.0.19
534 534
 	 * @param  string $value New name.
535 535
 	 */
536
-	public function set_title( $value ) {
537
-		$this->set_name( $value );
536
+	public function set_title($value) {
537
+		$this->set_name($value);
538 538
     }
539 539
 
540 540
     /**
@@ -543,8 +543,8 @@  discard block
 block discarded – undo
543 543
 	 * @since 1.0.19
544 544
 	 * @param  int $value New author.
545 545
 	 */
546
-	public function set_author( $value ) {
547
-		$this->set_prop( 'author', (int) $value );
546
+	public function set_author($value) {
547
+		$this->set_prop('author', (int) $value);
548 548
 	}
549 549
 
550 550
 	/**
@@ -554,9 +554,9 @@  discard block
 block discarded – undo
554 554
 	 * @sinve 2.3.4 Array values sanitized.
555 555
 	 * @param  array $value Form elements.
556 556
 	 */
557
-	public function set_elements( $value ) {
558
-		if ( is_array( $value ) ) {
559
-			$this->set_prop( 'elements', wp_kses_post_deep( $value ) );
557
+	public function set_elements($value) {
558
+		if (is_array($value)) {
559
+			$this->set_prop('elements', wp_kses_post_deep($value));
560 560
 		}
561 561
 	}
562 562
 
@@ -567,36 +567,36 @@  discard block
 block discarded – undo
567 567
 	 *
568 568
 	 * @return mixed
569 569
 	 */
570
-	public function sanitize_array_values( $value ) {
570
+	public function sanitize_array_values($value) {
571 571
 
572 572
 		// sanitize
573
-		if ( ! empty( $value ) ) {
573
+		if (!empty($value)) {
574 574
 
575
-			foreach ( $value as $key => $val_arr ) {
575
+			foreach ($value as $key => $val_arr) {
576 576
 
577
-				if ( is_array( $val_arr ) ) {
577
+				if (is_array($val_arr)) {
578 578
 					// check if we have sub array items.
579 579
 					$sub_arr = array();
580
-					foreach ( $val_arr as $key2 => $val2 ) {
581
-						if ( is_array( $val2 ) ) {
582
-							$sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 );
583
-							unset( $val_arr[ $key ][ $key2 ] );
580
+					foreach ($val_arr as $key2 => $val2) {
581
+						if (is_array($val2)) {
582
+							$sub_arr[$key2] = $this->sanitize_array_values($val2);
583
+							unset($val_arr[$key][$key2]);
584 584
 						}
585 585
 					}
586 586
 
587 587
 					// we allow some html in description so we sanitize it separately.
588
-					$help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : '';
588
+					$help_text = !empty($val_arr['description']) ? wp_kses_post($val_arr['description']) : '';
589 589
 
590 590
 					// sanitize array elements
591
-					$value[ $key ] = array_map( 'sanitize_text_field', $val_arr );
591
+					$value[$key] = array_map('sanitize_text_field', $val_arr);
592 592
 
593 593
 					// add back the description if set
594
-					if ( isset( $val_arr['description'] ) ) {
595
-                        $value[ $key ]['description'] = $help_text;}
594
+					if (isset($val_arr['description'])) {
595
+                        $value[$key]['description'] = $help_text; }
596 596
 
597 597
 					// add back sub array items after its been sanitized.
598
-					if ( ! empty( $sub_arr ) ) {
599
-						$value[ $key ] = array_merge( $value[ $key ], $sub_arr );
598
+					if (!empty($sub_arr)) {
599
+						$value[$key] = array_merge($value[$key], $sub_arr);
600 600
 					}
601 601
 				}
602 602
             }
@@ -611,9 +611,9 @@  discard block
 block discarded – undo
611 611
 	 * @since 1.0.19
612 612
 	 * @param  array $value Form elements.
613 613
 	 */
614
-	public function set_items( $value ) {
615
-		if ( is_array( $value ) ) {
616
-			$this->set_prop( 'items', $value );
614
+	public function set_items($value) {
615
+		if (is_array($value)) {
616
+			$this->set_prop('items', $value);
617 617
 		}
618 618
 	}
619 619
 
@@ -623,9 +623,9 @@  discard block
 block discarded – undo
623 623
 	 * @since 1.0.19
624 624
 	 * @param  float $value Amount earned.
625 625
 	 */
626
-	public function set_earned( $value ) {
627
-		$value = max( (float) $value, 0 );
628
-		$this->set_prop( 'earned', $value );
626
+	public function set_earned($value) {
627
+		$value = max((float) $value, 0);
628
+		$this->set_prop('earned', $value);
629 629
 	}
630 630
 
631 631
 	/**
@@ -634,9 +634,9 @@  discard block
 block discarded – undo
634 634
 	 * @since 1.0.19
635 635
 	 * @param  float $value Amount refunded.
636 636
 	 */
637
-	public function set_refunded( $value ) {
638
-		$value = max( (float) $value, 0 );
639
-		$this->set_prop( 'refunded', $value );
637
+	public function set_refunded($value) {
638
+		$value = max((float) $value, 0);
639
+		$this->set_prop('refunded', $value);
640 640
 	}
641 641
 
642 642
 	/**
@@ -645,9 +645,9 @@  discard block
 block discarded – undo
645 645
 	 * @since 1.0.19
646 646
 	 * @param  float $value Amount cancelled.
647 647
 	 */
648
-	public function set_cancelled( $value ) {
649
-		$value = max( (float) $value, 0 );
650
-		$this->set_prop( 'cancelled', $value );
648
+	public function set_cancelled($value) {
649
+		$value = max((float) $value, 0);
650
+		$this->set_prop('cancelled', $value);
651 651
 	}
652 652
 
653 653
 	/**
@@ -656,9 +656,9 @@  discard block
 block discarded – undo
656 656
 	 * @since 1.0.19
657 657
 	 * @param  float $value Amount cancelled.
658 658
 	 */
659
-	public function set_failed( $value ) {
660
-		$value = max( (float) $value, 0 );
661
-		$this->set_prop( 'failed', $value );
659
+	public function set_failed($value) {
660
+		$value = max((float) $value, 0);
661
+		$this->set_prop('failed', $value);
662 662
 	}
663 663
 
664 664
     /**
@@ -667,11 +667,11 @@  discard block
 block discarded – undo
667 667
      * @deprecated
668 668
 	 * @return int item id
669 669
      */
670
-    public function create( $data = array() ) {
670
+    public function create($data = array()) {
671 671
 
672 672
 		// Set the properties.
673
-		if ( is_array( $data ) ) {
674
-			$this->set_props( $data );
673
+		if (is_array($data)) {
674
+			$this->set_props($data);
675 675
 		}
676 676
 
677 677
 		// Save the item.
@@ -684,8 +684,8 @@  discard block
 block discarded – undo
684 684
      * @deprecated
685 685
 	 * @return int item id
686 686
      */
687
-    public function update( $data = array() ) {
688
-        return $this->create( $data );
687
+    public function update($data = array()) {
688
+        return $this->create($data);
689 689
     }
690 690
 
691 691
     /*
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
 	 */
706 706
     public function is_default() {
707 707
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
708
-        return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
708
+        return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this);
709 709
 	}
710 710
 
711 711
     /**
@@ -717,11 +717,11 @@  discard block
 block discarded – undo
717 717
     public function is_active() {
718 718
         $is_active = 0 !== (int) $this->get_id();
719 719
 
720
-        if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) {
720
+        if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') {
721 721
             $is_active = false;
722 722
         }
723 723
 
724
-        return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
724
+        return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this);
725 725
 	}
726 726
 
727 727
 	/**
@@ -730,8 +730,8 @@  discard block
 block discarded – undo
730 730
 	 * @since 1.0.19
731 731
 	 * @return bool
732 732
 	 */
733
-    public function has_item( $item_id ) {
734
-        return false !== $this->get_item( $item_id );
733
+    public function has_item($item_id) {
734
+        return false !== $this->get_item($item_id);
735 735
 	}
736 736
 
737 737
 	/**
@@ -740,8 +740,8 @@  discard block
 block discarded – undo
740 740
 	 * @since 1.0.19
741 741
 	 * @return bool
742 742
 	 */
743
-    public function has_element_type( $element_type ) {
744
-        return false !== $this->get_element_type( $element_type );
743
+    public function has_element_type($element_type) {
744
+        return false !== $this->get_element_type($element_type);
745 745
 	}
746 746
 
747 747
 	/**
@@ -752,13 +752,13 @@  discard block
 block discarded – undo
752 752
 	 */
753 753
     public function is_recurring() {
754 754
 
755
-		if ( ! empty( $this->invoice ) ) {
755
+		if (!empty($this->invoice)) {
756 756
 			return $this->invoice->is_recurring();
757 757
 		}
758 758
 
759
-		foreach ( $this->get_items() as $item ) {
759
+		foreach ($this->get_items() as $item) {
760 760
 
761
-			if ( $item->is_recurring() ) {
761
+			if ($item->is_recurring()) {
762 762
 				return true;
763 763
 			}
764 764
         }
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
 	 *
772 772
 	 * @since 1.0.19
773 773
 	 */
774
-    public function get_html( $extra_markup = '' ) {
774
+    public function get_html($extra_markup = '') {
775 775
 
776 776
 		// Return the HTML.
777 777
 		return wpinv_get_template_html(
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
 	 *
789 789
 	 * @since 1.0.19
790 790
 	 */
791
-    public function display( $extra_markup = '' ) {
791
+    public function display($extra_markup = '') {
792 792
 		wpinv_get_template(
793 793
 			'payment-forms/form.php',
794 794
 			array(
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -14,70 +14,70 @@  discard block
 block discarded – undo
14 14
 class WPInv_Ajax {
15 15
 
16 16
     /**
17
-	 * Hook in ajax handlers.
18
-	 */
19
-	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
-		self::add_ajax_events();
17
+     * Hook in ajax handlers.
18
+     */
19
+    public static function init() {
20
+        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
+        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
+        self::add_ajax_events();
23 23
     }
24 24
 
25 25
     /**
26
-	 * Set GetPaid AJAX constant and headers.
27
-	 */
28
-	public static function define_ajax() {
29
-
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
-			}
36
-			$GLOBALS['wpdb']->hide_errors();
37
-		}
26
+     * Set GetPaid AJAX constant and headers.
27
+     */
28
+    public static function define_ajax() {
29
+
30
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
+            getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
+            getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
+            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
+                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
+            }
36
+            $GLOBALS['wpdb']->hide_errors();
37
+        }
38 38
 
39 39
     }
40 40
 
41 41
     /**
42
-	 * Send headers for GetPaid Ajax Requests.
43
-	 *
44
-	 * @since 1.0.18
45
-	 */
46
-	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
48
-			send_origin_headers();
49
-			send_nosniff_header();
50
-			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
54
-		}
42
+     * Send headers for GetPaid Ajax Requests.
43
+     *
44
+     * @since 1.0.18
45
+     */
46
+    private static function wpinv_ajax_headers() {
47
+        if ( ! headers_sent() ) {
48
+            send_origin_headers();
49
+            send_nosniff_header();
50
+            nocache_headers();
51
+            header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
+            header( 'X-Robots-Tag: noindex' );
53
+            status_header( 200 );
54
+        }
55 55
     }
56 56
 
57 57
     /**
58
-	 * Check for GetPaid Ajax request and fire action.
59
-	 */
60
-	public static function do_wpinv_ajax() {
61
-		global $wp_query;
58
+     * Check for GetPaid Ajax request and fire action.
59
+     */
60
+    public static function do_wpinv_ajax() {
61
+        global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
-		}
63
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
+            $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
+        }
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+        $action = $wp_query->get( 'wpinv-ajax' );
68 68
 
69
-		if ( $action ) {
70
-			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
73
-			wp_die();
74
-		}
69
+        if ( $action ) {
70
+            self::wpinv_ajax_headers();
71
+            $action = sanitize_text_field( $action );
72
+            do_action( 'wpinv_ajax_' . $action );
73
+            wp_die();
74
+        }
75 75
 
76 76
     }
77 77
 
78 78
     /**
79
-	 * Hook in ajax methods.
80
-	 */
79
+     * Hook in ajax methods.
80
+     */
81 81
     public static function add_ajax_events() {
82 82
 
83 83
         // array( 'event' => is_frontend )
@@ -264,11 +264,11 @@  discard block
 block discarded – undo
264 264
         global $getpaid_force_checkbox;
265 265
 
266 266
         // Is the request set up correctly?
267
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
268
-			aui()->alert(
269
-				array(
270
-					'type'    => 'warning',
271
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
267
+        if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
268
+            aui()->alert(
269
+                array(
270
+                    'type'    => 'warning',
271
+                    'content' => __( 'No payment form or item provided', 'invoicing' ),
272 272
                 ),
273 273
                 true
274 274
             );
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
         }
277 277
 
278 278
         // Payment form or button?
279
-		if ( ! empty( $_GET['form'] ) ) {
279
+        if ( ! empty( $_GET['form'] ) ) {
280 280
             $form = sanitize_text_field( urldecode( $_GET['form'] ) );
281 281
 
282 282
             if ( false !== strpos( $form, '|' ) ) {
@@ -330,10 +330,10 @@  discard block
 block discarded – undo
330 330
                 getpaid_display_payment_form( $form );
331 331
             }
332 332
         } elseif ( ! empty( $_GET['invoice'] ) ) {
333
-		    getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) );
333
+            getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) );
334 334
         } else {
335
-			$items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) );
336
-		    getpaid_display_item_payment_form( $items );
335
+            $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) );
336
+            getpaid_display_item_payment_form( $items );
337 337
         }
338 338
 
339 339
         exit;
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
         if ( is_wp_error( $error ) ) {
668 668
             $alert = $error->get_error_message();
669 669
             wp_send_json_success( compact( 'alert' ) );
670
-         }
670
+            }
671 671
 
672 672
         // Update totals.
673 673
         $invoice->recalculate_total();
@@ -1111,12 +1111,12 @@  discard block
 block discarded – undo
1111 1111
     }
1112 1112
 
1113 1113
     /**
1114
-	 * Handles file uploads.
1115
-	 *
1116
-	 * @since       1.0.0
1117
-	 * @return      void
1118
-	 */
1119
-	public static function file_upload() {
1114
+     * Handles file uploads.
1115
+     *
1116
+     * @since       1.0.0
1117
+     * @return      void
1118
+     */
1119
+    public static function file_upload() {
1120 1120
 
1121 1121
         // Check nonce.
1122 1122
         check_ajax_referer( 'getpaid_form_nonce' );
@@ -1177,7 +1177,7 @@  discard block
 block discarded – undo
1177 1177
 
1178 1178
         wp_send_json_success( $response );
1179 1179
 
1180
-	}
1180
+    }
1181 1181
 
1182 1182
 }
1183 1183
 
Please login to merge, or discard this patch.
Spacing   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * WPInv_Ajax class.
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 	 * Hook in ajax handlers.
18 18
 	 */
19 19
 	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
20
+		add_action('init', array(__CLASS__, 'define_ajax'), 0);
21
+		add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
22 22
 		self::add_ajax_events();
23 23
     }
24 24
 
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	 */
28 28
 	public static function define_ajax() {
29 29
 
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+		if (!empty($_GET['wpinv-ajax'])) {
31
+			getpaid_maybe_define_constant('DOING_AJAX', true);
32
+			getpaid_maybe_define_constant('WPInv_DOING_AJAX', true);
33
+			if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
34
+				/** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
35 35
 			}
36 36
 			$GLOBALS['wpdb']->hide_errors();
37 37
 		}
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	 * @since 1.0.18
45 45
 	 */
46 46
 	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
47
+		if (!headers_sent()) {
48 48
 			send_origin_headers();
49 49
 			send_nosniff_header();
50 50
 			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
51
+			header('Content-Type: text/html; charset=' . get_option('blog_charset'));
52
+			header('X-Robots-Tag: noindex');
53
+			status_header(200);
54 54
 		}
55 55
     }
56 56
 
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
 	public static function do_wpinv_ajax() {
61 61
 		global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
63
+		if (!empty($_GET['wpinv-ajax'])) {
64
+			$wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax'])));
65 65
 		}
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+		$action = $wp_query->get('wpinv-ajax');
68 68
 
69
-		if ( $action ) {
69
+		if ($action) {
70 70
 			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
71
+			$action = sanitize_text_field($action);
72
+			do_action('wpinv_ajax_' . $action);
73 73
 			wp_die();
74 74
 		}
75 75
 
@@ -106,36 +106,36 @@  discard block
 block discarded – undo
106 106
             'file_upload'                   => true,
107 107
         );
108 108
 
109
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
110
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
111
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
109
+        foreach ($ajax_events as $ajax_event => $nopriv) {
110
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
111
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
112 112
 
113
-            if ( $nopriv ) {
114
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
115
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
116
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
113
+            if ($nopriv) {
114
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
115
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
116
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
117 117
             }
118 118
         }
119 119
     }
120 120
 
121 121
     public static function add_note() {
122
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
122
+        check_ajax_referer('add-invoice-note', '_nonce');
123 123
 
124
-        $post_id   = absint( $_POST['post_id'] );
125
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
126
-        $note_type = sanitize_text_field( $_POST['note_type'] );
124
+        $post_id   = absint($_POST['post_id']);
125
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
126
+        $note_type = sanitize_text_field($_POST['note_type']);
127 127
 
128
-        if ( ! wpinv_current_user_can( 'invoice_add_note', array( 'invoice_id' => $post_id, 'note_type' => $note_type ) ) ) {
128
+        if (!wpinv_current_user_can('invoice_add_note', array('invoice_id' => $post_id, 'note_type' => $note_type))) {
129 129
             die( -1 );
130 130
         }
131 131
 
132 132
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
133 133
 
134
-        if ( $post_id > 0 ) {
135
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
134
+        if ($post_id > 0) {
135
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
136 136
 
137
-            if ( $note_id > 0 && ! is_wp_error( $note_id ) ) {
138
-                wpinv_get_invoice_note_line_item( $note_id );
137
+            if ($note_id > 0 && !is_wp_error($note_id)) {
138
+                wpinv_get_invoice_note_line_item($note_id);
139 139
             }
140 140
         }
141 141
 
@@ -143,16 +143,16 @@  discard block
 block discarded – undo
143 143
     }
144 144
 
145 145
     public static function delete_note() {
146
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
146
+        check_ajax_referer('delete-invoice-note', '_nonce');
147 147
 
148
-        $note_id = (int)$_POST['note_id'];
148
+        $note_id = (int) $_POST['note_id'];
149 149
 
150
-        if ( ! wpinv_current_user_can( 'invoice_delete_note', array( 'note_id' => $note_id ) ) ) {
150
+        if (!wpinv_current_user_can('invoice_delete_note', array('note_id' => $note_id))) {
151 151
             die( -1 );
152 152
         }
153 153
 
154
-        if ( $note_id > 0 ) {
155
-            wp_delete_comment( $note_id, true );
154
+        if ($note_id > 0) {
155
+            wp_delete_comment($note_id, true);
156 156
         }
157 157
 
158 158
         die();
@@ -169,35 +169,35 @@  discard block
 block discarded – undo
169 169
      */
170 170
     public static function get_billing_details() {
171 171
         // Verify nonce.
172
-        check_ajax_referer( 'wpinv-nonce' );
172
+        check_ajax_referer('wpinv-nonce');
173 173
 
174 174
         // Do we have a user id?
175 175
         $user_id = (int) $_GET['user_id'];
176
-        $invoice_id = ! empty( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
176
+        $invoice_id = !empty($_REQUEST['post_id']) ? (int) $_REQUEST['post_id'] : 0;
177 177
 
178
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
178
+        if (empty($user_id) || !is_numeric($user_id)) {
179 179
             die( -1 );
180 180
         }
181 181
 
182 182
         // Can the user manage the plugin?
183
-        if ( ! wpinv_current_user_can( 'invoice_get_billing_details', array( 'user_id' => $user_id, 'invoice_id' => $invoice_id ) ) ) {
183
+        if (!wpinv_current_user_can('invoice_get_billing_details', array('user_id' => $user_id, 'invoice_id' => $invoice_id))) {
184 184
             die( -1 );
185 185
         }
186 186
 
187 187
         // Fetch the billing details.
188
-        $billing_details    = wpinv_get_user_address( $user_id );
189
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
188
+        $billing_details    = wpinv_get_user_address($user_id);
189
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
190 190
 
191 191
         // unset the user id and email.
192
-        $to_ignore = array( 'user_id', 'email' );
192
+        $to_ignore = array('user_id', 'email');
193 193
 
194
-        foreach ( $to_ignore as $key ) {
195
-            if ( isset( $billing_details[ $key ] ) ) {
196
-                unset( $billing_details[ $key ] );
194
+        foreach ($to_ignore as $key) {
195
+            if (isset($billing_details[$key])) {
196
+                unset($billing_details[$key]);
197 197
             }
198 198
         }
199 199
 
200
-        wp_send_json_success( $billing_details );
200
+        wp_send_json_success($billing_details);
201 201
 
202 202
     }
203 203
 
@@ -206,54 +206,54 @@  discard block
 block discarded – undo
206 206
      */
207 207
     public static function check_new_user_email() {
208 208
         // Verify nonce.
209
-        check_ajax_referer( 'wpinv-nonce' );
209
+        check_ajax_referer('wpinv-nonce');
210 210
 
211
-        $invoice_id = ! empty( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : 0;
211
+        $invoice_id = !empty($_REQUEST['post_id']) ? absint($_REQUEST['post_id']) : 0;
212 212
 
213
-        if ( empty( $invoice_id ) ) {
213
+        if (empty($invoice_id)) {
214 214
             die( -1 );
215 215
         }
216 216
 
217 217
         // Can the user manage the plugin?
218
-        if ( ! wpinv_current_user_can( 'invoice_check_new_user_email', array( 'invoice_id' => $invoice_id ) ) ) {
218
+        if (!wpinv_current_user_can('invoice_check_new_user_email', array('invoice_id' => $invoice_id))) {
219 219
             die( -1 );
220 220
         }
221 221
 
222 222
         // We need an email address.
223
-        if ( empty( $_GET['email'] ) ) {
224
-            esc_html_e( "Provide the new user's email address", 'invoicing' );
223
+        if (empty($_GET['email'])) {
224
+            esc_html_e("Provide the new user's email address", 'invoicing');
225 225
             exit;
226 226
         }
227 227
 
228 228
         // Ensure the email is valid.
229
-        $email = sanitize_email( $_GET['email'] );
230
-        if ( ! is_email( $email ) ) {
231
-            esc_html_e( 'Invalid email address', 'invoicing' );
229
+        $email = sanitize_email($_GET['email']);
230
+        if (!is_email($email)) {
231
+            esc_html_e('Invalid email address', 'invoicing');
232 232
             exit;
233 233
         }
234 234
 
235 235
         // And it does not exist.
236
-        $id = email_exists( $email );
237
-        if ( $id ) {
238
-            wp_send_json_success( compact( 'id' ) );
236
+        $id = email_exists($email);
237
+        if ($id) {
238
+            wp_send_json_success(compact('id'));
239 239
         }
240 240
 
241
-        wp_send_json_success( true );
241
+        wp_send_json_success(true);
242 242
     }
243 243
 
244 244
     public static function run_tool() {
245
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
245
+        check_ajax_referer('wpinv-nonce', '_nonce');
246 246
 
247
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
247
+        if (!wpinv_current_user_can_manage_invoicing()) {
248 248
             die( -1 );
249 249
         }
250 250
 
251
-        $tool = sanitize_text_field( $_POST['tool'] );
251
+        $tool = sanitize_text_field($_POST['tool']);
252 252
 
253
-        do_action( 'wpinv_run_tool' );
253
+        do_action('wpinv_run_tool');
254 254
 
255
-        if ( ! empty( $tool ) ) {
256
-            do_action( 'wpinv_tool_' . $tool );
255
+        if (!empty($tool)) {
256
+            do_action('wpinv_tool_' . $tool);
257 257
         }
258 258
     }
259 259
 
@@ -264,11 +264,11 @@  discard block
 block discarded – undo
264 264
         global $getpaid_force_checkbox;
265 265
 
266 266
         // Is the request set up correctly?
267
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
267
+		if (empty($_GET['form']) && empty($_GET['item']) && empty($_GET['invoice'])) {
268 268
 			aui()->alert(
269 269
 				array(
270 270
 					'type'    => 'warning',
271
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
271
+					'content' => __('No payment form or item provided', 'invoicing'),
272 272
                 ),
273 273
                 true
274 274
             );
@@ -276,29 +276,29 @@  discard block
 block discarded – undo
276 276
         }
277 277
 
278 278
         // Payment form or button?
279
-		if ( ! empty( $_GET['form'] ) ) {
280
-            $form = sanitize_text_field( urldecode( $_GET['form'] ) );
279
+		if (!empty($_GET['form'])) {
280
+            $form = sanitize_text_field(urldecode($_GET['form']));
281 281
 
282
-            if ( false !== strpos( $form, '|' ) ) {
283
-                $form_pos = strpos( $form, '|' );
284
-                $_items   = getpaid_convert_items_to_array( substr( $form, $form_pos + 1 ) );
285
-                $form     = substr( $form, 0, $form_pos );
282
+            if (false !== strpos($form, '|')) {
283
+                $form_pos = strpos($form, '|');
284
+                $_items   = getpaid_convert_items_to_array(substr($form, $form_pos + 1));
285
+                $form     = substr($form, 0, $form_pos);
286 286
 
287 287
                 // Retrieve appropriate payment form.
288
-                $payment_form = new GetPaid_Payment_Form( $form );
289
-                $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
288
+                $payment_form = new GetPaid_Payment_Form($form);
289
+                $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form());
290 290
 
291 291
                 $items    = array();
292 292
                 $item_ids = array();
293 293
 
294
-                foreach ( $_items as $item_id => $qty ) {
295
-                    if ( ! in_array( $item_id, $item_ids ) ) {
296
-                        $item = new GetPaid_Form_Item( $item_id );
297
-                        $item->set_quantity( $qty );
294
+                foreach ($_items as $item_id => $qty) {
295
+                    if (!in_array($item_id, $item_ids)) {
296
+                        $item = new GetPaid_Form_Item($item_id);
297
+                        $item->set_quantity($qty);
298 298
 
299
-                        if ( 0 == $qty ) {
300
-                            $item->set_allow_quantities( true );
301
-                            $item->set_is_required( false );
299
+                        if (0 == $qty) {
300
+                            $item->set_allow_quantities(true);
301
+                            $item->set_is_required(false);
302 302
                             $getpaid_force_checkbox = true;
303 303
                         }
304 304
 
@@ -307,33 +307,33 @@  discard block
 block discarded – undo
307 307
                     }
308 308
                 }
309 309
 
310
-                if ( ! $payment_form->is_default() ) {
310
+                if (!$payment_form->is_default()) {
311 311
 
312
-                    foreach ( $payment_form->get_items() as $item ) {
313
-                        if ( ! in_array( $item->get_id(), $item_ids ) ) {
312
+                    foreach ($payment_form->get_items() as $item) {
313
+                        if (!in_array($item->get_id(), $item_ids)) {
314 314
                             $item_ids[] = $item->get_id();
315 315
                             $items[]    = $item;
316 316
                         }
317 317
                     }
318 318
                 }
319 319
 
320
-                $payment_form->set_items( $items );
320
+                $payment_form->set_items($items);
321 321
 
322
-                $extra_items     = esc_attr( getpaid_convert_items_to_string( $_items ) );
323
-                $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items );
322
+                $extra_items     = esc_attr(getpaid_convert_items_to_string($_items));
323
+                $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items);
324 324
                 $extra_items     = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />";
325 325
                 $extra_items    .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />";
326
-                $payment_form->display( $extra_items );
326
+                $payment_form->display($extra_items);
327 327
                 $getpaid_force_checkbox = false;
328 328
 
329 329
             } else {
330
-                getpaid_display_payment_form( $form );
330
+                getpaid_display_payment_form($form);
331 331
             }
332
-        } elseif ( ! empty( $_GET['invoice'] ) ) {
333
-		    getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) );
332
+        } elseif (!empty($_GET['invoice'])) {
333
+		    getpaid_display_invoice_payment_form((int) urldecode($_GET['invoice']));
334 334
         } else {
335
-			$items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) );
336
-		    getpaid_display_item_payment_form( $items );
335
+			$items = getpaid_convert_items_to_array(sanitize_text_field(urldecode($_GET['item'])));
336
+		    getpaid_display_item_payment_form($items);
337 337
         }
338 338
 
339 339
         exit;
@@ -348,14 +348,14 @@  discard block
 block discarded – undo
348 348
     public static function payment_form() { 
349 349
 
350 350
         // ... form fields...
351
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
352
-            esc_html_e( 'Error: Reload the page and try again.', 'invoicing' );
351
+        if (empty($_POST['getpaid_payment_form_submission'])) {
352
+            esc_html_e('Error: Reload the page and try again.', 'invoicing');
353 353
             exit;
354 354
         }
355 355
 
356 356
         // Process the payment form.
357
-        $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' );
358
-        $checkout       = new $checkout_class( new GetPaid_Payment_Form_Submission() );
357
+        $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout');
358
+        $checkout       = new $checkout_class(new GetPaid_Payment_Form_Submission());
359 359
         $checkout->process_checkout();
360 360
 
361 361
         exit;
@@ -368,55 +368,55 @@  discard block
 block discarded – undo
368 368
      */
369 369
     public static function get_payment_form_states_field() {
370 370
 
371
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
371
+        if (empty($_GET['country']) || empty($_GET['form'])) {
372 372
             exit;
373 373
         }
374 374
 
375
-        $elements = getpaid_get_payment_form_elements( (int) $_GET['form'] );
375
+        $elements = getpaid_get_payment_form_elements((int) $_GET['form']);
376 376
 
377
-        if ( empty( $elements ) ) {
377
+        if (empty($elements)) {
378 378
             exit;
379 379
         }
380 380
 
381 381
         $address_fields = array();
382
-        foreach ( $elements as $element ) {
383
-            if ( 'address' === $element['type'] ) {
382
+        foreach ($elements as $element) {
383
+            if ('address' === $element['type']) {
384 384
                 $address_fields = $element;
385 385
                 break;
386 386
             }
387 387
         }
388 388
 
389
-        if ( empty( $address_fields ) ) {
389
+        if (empty($address_fields)) {
390 390
             exit;
391 391
         }
392 392
 
393
-        foreach ( $address_fields['fields'] as $address_field ) {
393
+        foreach ($address_fields['fields'] as $address_field) {
394 394
 
395
-            if ( 'wpinv_state' == $address_field['name'] ) {
395
+            if ('wpinv_state' == $address_field['name']) {
396 396
 
397
-                $wrap_class  = getpaid_get_form_element_grid_class( $address_field );
398
-                $wrap_class  = esc_attr( "$wrap_class getpaid-address-field-wrapper" );
399
-                $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] );
400
-                $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] );
401
-                $value       = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : '';
402
-                $label       = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] );
397
+                $wrap_class  = getpaid_get_form_element_grid_class($address_field);
398
+                $wrap_class  = esc_attr("$wrap_class getpaid-address-field-wrapper");
399
+                $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']);
400
+                $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']);
401
+                $value       = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : '';
402
+                $label       = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']);
403 403
 
404
-                if ( ! empty( $address_field['required'] ) ) {
404
+                if (!empty($address_field['required'])) {
405 405
                     $label .= "<span class='text-danger'> *</span>";
406 406
                 }
407 407
 
408 408
                 $html = getpaid_get_states_select_markup(
409
-                    sanitize_text_field( $_GET['country'] ),
409
+                    sanitize_text_field($_GET['country']),
410 410
                     $value,
411 411
                     $placeholder,
412 412
                     $label,
413 413
                     $description,
414
-                    ! empty( $address_field['required'] ),
414
+                    !empty($address_field['required']),
415 415
                     $wrap_class,
416
-                    sanitize_text_field( $_GET['name'] )
416
+                    sanitize_text_field($_GET['name'])
417 417
                 );
418 418
 
419
-                wp_send_json_success( $html );
419
+                wp_send_json_success($html);
420 420
                 exit;
421 421
 
422 422
             }
@@ -430,68 +430,68 @@  discard block
 block discarded – undo
430 430
      */
431 431
     public static function recalculate_invoice_totals() {
432 432
         // Verify nonce.
433
-        check_ajax_referer( 'wpinv-nonce' );
433
+        check_ajax_referer('wpinv-nonce');
434 434
 
435
-        $invoice_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
435
+        $invoice_id = !empty($_POST['post_id']) ? absint($_POST['post_id']) : 0;
436 436
 
437
-        if ( empty( $invoice_id ) ) {
437
+        if (empty($invoice_id)) {
438 438
             die( -1 );
439 439
         }
440 440
 
441 441
         // Can the user manage the plugin?
442
-        if ( ! wpinv_current_user_can( 'invoice_recalculate_totals', array( 'invoice_id' => $invoice_id ) ) ) {
442
+        if (!wpinv_current_user_can('invoice_recalculate_totals', array('invoice_id' => $invoice_id))) {
443 443
             die( -1 );
444 444
         }
445 445
 
446 446
         // Fetch the invoice.
447
-        $invoice = new WPInv_Invoice( $invoice_id );
447
+        $invoice = new WPInv_Invoice($invoice_id);
448 448
 
449 449
         // Ensure it exists.
450
-        if ( ! $invoice->get_id() ) {
450
+        if (!$invoice->get_id()) {
451 451
             exit;
452 452
         }
453 453
 
454 454
         // Maybe set the country, state, currency.
455
-        foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) {
456
-            if ( isset( $_POST[ $key ] ) ) {
455
+        foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) {
456
+            if (isset($_POST[$key])) {
457 457
                 $method = "set_$key";
458
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
458
+                $invoice->$method(sanitize_text_field($_POST[$key]));
459 459
             }
460 460
         }
461 461
 
462 462
         // Maybe disable taxes.
463
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
463
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
464 464
 
465 465
         // Discount code.
466
-        if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
467
-            $discount = new WPInv_Discount( $invoice->get_discount_code() );
468
-            if ( $discount->exists() ) {
469
-                $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
466
+        if (!$invoice->is_paid() && !$invoice->is_refunded()) {
467
+            $discount = new WPInv_Discount($invoice->get_discount_code());
468
+            if ($discount->exists()) {
469
+                $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
470 470
             } else {
471
-                $invoice->remove_discount( 'discount_code' );
471
+                $invoice->remove_discount('discount_code');
472 472
             }
473 473
         }
474 474
 
475 475
         // Recalculate totals.
476 476
         $invoice->recalculate_total();
477 477
 
478
-        $total        = wpinv_price( $invoice->get_total(), $invoice->get_currency() );
479
-        $suscriptions = getpaid_get_invoice_subscriptions( $invoice );
480
-        if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) {
481
-            $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() );
482
-            $total          .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>';
478
+        $total        = wpinv_price($invoice->get_total(), $invoice->get_currency());
479
+        $suscriptions = getpaid_get_invoice_subscriptions($invoice);
480
+        if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) {
481
+            $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency());
482
+            $total          .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>';
483 483
         }
484 484
 
485 485
         $totals = array(
486
-            'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ),
487
-            'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ),
488
-            'tax'      => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ),
486
+            'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()),
487
+            'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()),
488
+            'tax'      => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()),
489 489
             'total'    => $total,
490 490
         );
491 491
 
492
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
492
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
493 493
 
494
-        wp_send_json_success( compact( 'totals' ) );
494
+        wp_send_json_success(compact('totals'));
495 495
     }
496 496
 
497 497
     /**
@@ -499,35 +499,35 @@  discard block
 block discarded – undo
499 499
      */
500 500
     public static function get_invoice_items() {
501 501
         // Verify nonce.
502
-        check_ajax_referer( 'wpinv-nonce' );
502
+        check_ajax_referer('wpinv-nonce');
503 503
 
504
-        $invoice_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
504
+        $invoice_id = !empty($_POST['post_id']) ? absint($_POST['post_id']) : 0;
505 505
 
506
-        if ( empty( $invoice_id ) ) {
506
+        if (empty($invoice_id)) {
507 507
             exit;
508 508
         }
509 509
 
510 510
         // Can the user manage the plugin?
511
-        if ( ! wpinv_current_user_can( 'invoice_get_items', array( 'invoice_id' => $invoice_id ) ) ) {
511
+        if (!wpinv_current_user_can('invoice_get_items', array('invoice_id' => $invoice_id))) {
512 512
             exit;
513 513
         }
514 514
 
515 515
         // Fetch the invoice.
516
-        $invoice = new WPInv_Invoice( $invoice_id );
516
+        $invoice = new WPInv_Invoice($invoice_id);
517 517
 
518 518
         // Ensure it exists.
519
-        if ( ! $invoice->get_id() ) {
519
+        if (!$invoice->get_id()) {
520 520
             exit;
521 521
         }
522 522
 
523 523
         // Return an array of invoice items.
524 524
         $items = array();
525 525
 
526
-        foreach ( $invoice->get_items() as $item ) {
527
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() );
526
+        foreach ($invoice->get_items() as $item) {
527
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal());
528 528
         }
529 529
 
530
-        wp_send_json_success( compact( 'items' ) );
530
+        wp_send_json_success(compact('items'));
531 531
     }
532 532
 
533 533
     /**
@@ -535,57 +535,57 @@  discard block
 block discarded – undo
535 535
      */
536 536
     public static function edit_invoice_item() {
537 537
         // Verify nonce.
538
-        check_ajax_referer( 'wpinv-nonce' );
538
+        check_ajax_referer('wpinv-nonce');
539 539
 
540 540
         // We need an invoice and item details.
541
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
541
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
542 542
             exit;
543 543
         }
544 544
 
545
-        $invoice_id = absint( $_POST['post_id'] );
545
+        $invoice_id = absint($_POST['post_id']);
546 546
 
547
-        if ( empty( $invoice_id ) ) {
547
+        if (empty($invoice_id)) {
548 548
             exit;
549 549
         }
550 550
 
551 551
         // Can the user manage the plugin?
552
-        if ( ! wpinv_current_user_can( 'invoice_edit_item', array( 'invoice_id' => $invoice_id ) ) ) {
552
+        if (!wpinv_current_user_can('invoice_edit_item', array('invoice_id' => $invoice_id))) {
553 553
             exit;
554 554
         }
555 555
 
556 556
         // Fetch the invoice.
557
-        $invoice = new WPInv_Invoice( $invoice_id );
557
+        $invoice = new WPInv_Invoice($invoice_id);
558 558
 
559 559
         // Ensure it exists and its not been paid for.
560
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
560
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
561 561
             exit;
562 562
         }
563 563
 
564 564
         // Format the data.
565
-        $data = wp_kses_post_deep( wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ) );
565
+        $data = wp_kses_post_deep(wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field')));
566 566
 
567 567
         // Ensure that we have an item id.
568
-        if ( empty( $data['id'] ) ) {
568
+        if (empty($data['id'])) {
569 569
             exit;
570 570
         }
571 571
 
572 572
         // Abort if the invoice does not have the specified item.
573
-        $item = $invoice->get_item( (int) $data['id'] );
573
+        $item = $invoice->get_item((int) $data['id']);
574 574
 
575
-        if ( empty( $item ) ) {
575
+        if (empty($item)) {
576 576
             exit;
577 577
         }
578 578
 
579 579
         // Update the item.
580
-        $item->set_price( getpaid_standardize_amount( $data['price'] ) );
581
-        $item->set_name( sanitize_text_field( $data['name'] ) );
582
-        $item->set_description( wp_kses_post( $data['description'] ) );
583
-        $item->set_quantity( floatval( $data['quantity'] ) );
580
+        $item->set_price(getpaid_standardize_amount($data['price']));
581
+        $item->set_name(sanitize_text_field($data['name']));
582
+        $item->set_description(wp_kses_post($data['description']));
583
+        $item->set_quantity(floatval($data['quantity']));
584 584
 
585 585
         // Add it to the invoice.
586
-        $error = $invoice->add_item( $item );
586
+        $error = $invoice->add_item($item);
587 587
         $alert = false;
588
-        if ( is_wp_error( $error ) ) {
588
+        if (is_wp_error($error)) {
589 589
             $alert = $error->get_error_message();
590 590
         }
591 591
 
@@ -598,11 +598,11 @@  discard block
 block discarded – undo
598 598
         // Return an array of invoice items.
599 599
         $items = array();
600 600
 
601
-        foreach ( $invoice->get_items() as $item ) {
602
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
601
+        foreach ($invoice->get_items() as $item) {
602
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
603 603
         }
604 604
 
605
-        wp_send_json_success( compact( 'items', 'alert' ) );
605
+        wp_send_json_success(compact('items', 'alert'));
606 606
     }
607 607
 
608 608
     /**
@@ -610,63 +610,63 @@  discard block
 block discarded – undo
610 610
      */
611 611
     public static function create_invoice_item() {
612 612
         // Verify nonce.
613
-        check_ajax_referer( 'wpinv-nonce' );
613
+        check_ajax_referer('wpinv-nonce');
614 614
 
615 615
         // We need an invoice and item details.
616
-        if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) {
616
+        if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) {
617 617
             exit;
618 618
         }
619 619
 
620
-        $invoice_id = absint( $_POST['invoice_id'] );
620
+        $invoice_id = absint($_POST['invoice_id']);
621 621
 
622
-        if ( empty( $invoice_id ) ) {
622
+        if (empty($invoice_id)) {
623 623
             exit;
624 624
         }
625 625
 
626
-        if ( ! wpinv_current_user_can( 'invoice_create_item', array( 'invoice_id' => $invoice_id ) ) ) {
626
+        if (!wpinv_current_user_can('invoice_create_item', array('invoice_id' => $invoice_id))) {
627 627
             exit;
628 628
         }
629 629
 
630 630
         // Fetch the invoice.
631
-        $invoice = new WPInv_Invoice( $invoice_id );
631
+        $invoice = new WPInv_Invoice($invoice_id);
632 632
 
633 633
         // Ensure it exists and its not been paid for.
634
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
634
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
635 635
             exit;
636 636
         }
637 637
 
638 638
         // Format the data.
639
-        $data = wp_kses_post_deep( wp_unslash( $_POST['_wpinv_quick'] ) );
639
+        $data = wp_kses_post_deep(wp_unslash($_POST['_wpinv_quick']));
640 640
 
641 641
         $item = new WPInv_Item();
642
-        $item->set_price( getpaid_standardize_amount( $data['price'] ) );
643
-        $item->set_name( sanitize_text_field( $data['name'] ) );
644
-        $item->set_description( wp_kses_post( $data['description'] ) );
645
-        $item->set_type( sanitize_text_field( $data['type'] ) );
646
-        $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) );
647
-        $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) );
648
-        $item->set_status( 'publish' );
642
+        $item->set_price(getpaid_standardize_amount($data['price']));
643
+        $item->set_name(sanitize_text_field($data['name']));
644
+        $item->set_description(wp_kses_post($data['description']));
645
+        $item->set_type(sanitize_text_field($data['type']));
646
+        $item->set_vat_rule(sanitize_text_field($data['vat_rule']));
647
+        $item->set_vat_class(sanitize_text_field($data['vat_class']));
648
+        $item->set_status('publish');
649 649
         $item->save();
650 650
 
651
-        if ( ! $item->exists() ) {
652
-            $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' );
653
-            wp_send_json_success( compact( 'alert' ) );
651
+        if (!$item->exists()) {
652
+            $alert = __('Could not create invoice item. Please try again.', 'invoicing');
653
+            wp_send_json_success(compact('alert'));
654 654
         }
655 655
 
656
-        if ( ! empty( $data['one-time'] ) ) {
657
-            update_post_meta( $item->get_id(), '_wpinv_one_time', 'yes' );
656
+        if (!empty($data['one-time'])) {
657
+            update_post_meta($item->get_id(), '_wpinv_one_time', 'yes');
658 658
         }
659 659
 
660
-        $item = new GetPaid_Form_Item( $item->get_id() );
661
-        $item->set_quantity( floatval( $data['qty'] ) );
660
+        $item = new GetPaid_Form_Item($item->get_id());
661
+        $item->set_quantity(floatval($data['qty']));
662 662
 
663 663
         // Add it to the invoice.
664
-        $error = $invoice->add_item( $item );
664
+        $error = $invoice->add_item($item);
665 665
         $alert = false;
666 666
 
667
-        if ( is_wp_error( $error ) ) {
667
+        if (is_wp_error($error)) {
668 668
             $alert = $error->get_error_message();
669
-            wp_send_json_success( compact( 'alert' ) );
669
+            wp_send_json_success(compact('alert'));
670 670
          }
671 671
 
672 672
         // Update totals.
@@ -679,9 +679,9 @@  discard block
 block discarded – undo
679 679
         $invoice->recalculate_total();
680 680
         $invoice->save();
681 681
         ob_start();
682
-        GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice );
682
+        GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice);
683 683
         $row = ob_get_clean();
684
-        wp_send_json_success( compact( 'row' ) );
684
+        wp_send_json_success(compact('row'));
685 685
     }
686 686
 
687 687
     /**
@@ -689,37 +689,37 @@  discard block
 block discarded – undo
689 689
      */
690 690
     public static function remove_invoice_item() {
691 691
         // Verify nonce.
692
-        check_ajax_referer( 'wpinv-nonce' );
692
+        check_ajax_referer('wpinv-nonce');
693 693
 
694 694
         // We need an invoice and item.
695
-        $invoice_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
696
-        $item_id = ! empty( $_POST['item_id'] ) ? absint( $_POST['item_id'] ) : 0;
695
+        $invoice_id = !empty($_POST['post_id']) ? absint($_POST['post_id']) : 0;
696
+        $item_id = !empty($_POST['item_id']) ? absint($_POST['item_id']) : 0;
697 697
 
698
-        if ( empty( $invoice_id ) || empty( $item_id ) ) {
698
+        if (empty($invoice_id) || empty($item_id)) {
699 699
             exit;
700 700
         }
701 701
 
702 702
         // Can the user manage the plugin?
703
-        if ( ! wpinv_current_user_can( 'invoice_remove_item', array( 'invoice_id' => $invoice_id, 'item_id' => $item_id ) ) ) {
703
+        if (!wpinv_current_user_can('invoice_remove_item', array('invoice_id' => $invoice_id, 'item_id' => $item_id))) {
704 704
             exit;
705 705
         }
706 706
 
707 707
         // Fetch the invoice.
708
-        $invoice = new WPInv_Invoice( $invoice_id );
708
+        $invoice = new WPInv_Invoice($invoice_id);
709 709
 
710 710
         // Ensure it exists and its not been paid for.
711
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
711
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
712 712
             exit;
713 713
         }
714 714
 
715 715
         // Abort if the invoice does not have the specified item.
716
-        $item = $invoice->get_item( $item_id );
716
+        $item = $invoice->get_item($item_id);
717 717
 
718
-        if ( empty( $item ) ) {
718
+        if (empty($item)) {
719 719
             exit;
720 720
         }
721 721
 
722
-        $invoice->remove_item( $item_id );
722
+        $invoice->remove_item($item_id);
723 723
 
724 724
         // Update totals.
725 725
         $invoice->recalculate_total();
@@ -730,11 +730,11 @@  discard block
 block discarded – undo
730 730
         // Return an array of invoice items.
731 731
         $items = array();
732 732
 
733
-        foreach ( $invoice->get_items() as $item ) {
734
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
733
+        foreach ($invoice->get_items() as $item) {
734
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
735 735
         }
736 736
 
737
-        wp_send_json_success( compact( 'items' ) );
737
+        wp_send_json_success(compact('items'));
738 738
     }
739 739
 
740 740
     /**
@@ -742,69 +742,69 @@  discard block
 block discarded – undo
742 742
      */
743 743
     public static function recalculate_full_prices() {
744 744
         // Verify nonce.
745
-        check_ajax_referer( 'wpinv-nonce' );
745
+        check_ajax_referer('wpinv-nonce');
746 746
 
747
-        $invoice_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
747
+        $invoice_id = !empty($_POST['post_id']) ? absint($_POST['post_id']) : 0;
748 748
 
749
-        if ( empty( $invoice_id ) ) {
749
+        if (empty($invoice_id)) {
750 750
             exit;
751 751
         }
752 752
 
753
-        if ( ! wpinv_current_user_can( 'invoice_recalculate_full_prices', array( 'invoice_id' => $invoice_id ) ) ) {
753
+        if (!wpinv_current_user_can('invoice_recalculate_full_prices', array('invoice_id' => $invoice_id))) {
754 754
             exit;
755 755
         }
756 756
 
757 757
         // Fetch the invoice.
758
-        $invoice = new WPInv_Invoice( $invoice_id );
758
+        $invoice = new WPInv_Invoice($invoice_id);
759 759
         $alert   = false;
760 760
 
761 761
         // Ensure it exists and its not been paid for.
762
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
762
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
763 763
             exit;
764 764
         }
765 765
 
766
-        $invoice->set_items( array() );
766
+        $invoice->set_items(array());
767 767
 
768
-        if ( ! empty( $_POST['getpaid_items'] ) ) {
768
+        if (!empty($_POST['getpaid_items'])) {
769 769
 
770
-            foreach ( wp_kses_post_deep( wp_unslash( $_POST['getpaid_items'] ) ) as $item_id => $args ) {
771
-                $item = new GetPaid_Form_Item( $item_id );
770
+            foreach (wp_kses_post_deep(wp_unslash($_POST['getpaid_items'])) as $item_id => $args) {
771
+                $item = new GetPaid_Form_Item($item_id);
772 772
 
773
-                if ( $item->exists() ) {
774
-                    $item->set_price( getpaid_standardize_amount( $args['price'] ) );
775
-                    $item->set_quantity( floatval( $args['quantity'] ) );
776
-                    $item->set_name( sanitize_text_field( $args['name'] ) );
777
-                    $item->set_description( wp_kses_post( $args['description'] ) );
778
-                    $invoice->add_item( $item );
773
+                if ($item->exists()) {
774
+                    $item->set_price(getpaid_standardize_amount($args['price']));
775
+                    $item->set_quantity(floatval($args['quantity']));
776
+                    $item->set_name(sanitize_text_field($args['name']));
777
+                    $item->set_description(wp_kses_post($args['description']));
778
+                    $invoice->add_item($item);
779 779
                 }
780 780
             }
781 781
         }
782 782
 
783
-        $invoice->set_disable_taxes( ! empty( $_POST['disable_taxes'] ) );
783
+        $invoice->set_disable_taxes(!empty($_POST['disable_taxes']));
784 784
 
785 785
         // Maybe set the country, state, currency.
786
-        foreach ( array( 'wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code' ) as $key ) {
787
-            if ( isset( $_POST[ $key ] ) ) {
788
-                $_key   = str_replace( 'wpinv_', '', $key );
786
+        foreach (array('wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code') as $key) {
787
+            if (isset($_POST[$key])) {
788
+                $_key   = str_replace('wpinv_', '', $key);
789 789
                 $method = "set_$_key";
790
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
790
+                $invoice->$method(sanitize_text_field($_POST[$key]));
791 791
             }
792 792
         }
793 793
 
794
-        $discount = new WPInv_Discount( $invoice->get_discount_code() );
795
-        if ( $discount->exists() ) {
796
-            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
794
+        $discount = new WPInv_Discount($invoice->get_discount_code());
795
+        if ($discount->exists()) {
796
+            $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
797 797
         } else {
798
-            $invoice->remove_discount( 'discount_code' );
798
+            $invoice->remove_discount('discount_code');
799 799
         }
800 800
 
801 801
         // Save the invoice.
802 802
         $invoice->recalculate_total();
803 803
         $invoice->save();
804 804
         ob_start();
805
-        GetPaid_Meta_Box_Invoice_Items::output( get_post( $invoice->get_id() ), $invoice );
805
+        GetPaid_Meta_Box_Invoice_Items::output(get_post($invoice->get_id()), $invoice);
806 806
         $table = ob_get_clean();
807
-        wp_send_json_success( compact( 'table' ) );
807
+        wp_send_json_success(compact('table'));
808 808
     }
809 809
 
810 810
     /**
@@ -812,47 +812,47 @@  discard block
 block discarded – undo
812 812
      */
813 813
     public static function admin_add_invoice_item() {
814 814
         // Verify nonce.
815
-        check_ajax_referer( 'wpinv-nonce' );
815
+        check_ajax_referer('wpinv-nonce');
816 816
 
817 817
         // We need an invoice and item.
818
-        $invoice_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
819
-        $item_id = ! empty( $_POST['item_id'] ) ? absint( $_POST['item_id'] ) : 0;
818
+        $invoice_id = !empty($_POST['post_id']) ? absint($_POST['post_id']) : 0;
819
+        $item_id = !empty($_POST['item_id']) ? absint($_POST['item_id']) : 0;
820 820
 
821
-        if ( empty( $invoice_id ) || empty( $item_id ) ) {
821
+        if (empty($invoice_id) || empty($item_id)) {
822 822
             exit;
823 823
         }
824 824
 
825 825
         // Can the user manage the plugin?
826
-        if ( ! wpinv_current_user_can( 'invoice_add_item', array( 'invoice_id' => $invoice_id, 'item_id' => $item_id ) ) ) {
826
+        if (!wpinv_current_user_can('invoice_add_item', array('invoice_id' => $invoice_id, 'item_id' => $item_id))) {
827 827
             exit;
828 828
         }
829 829
 
830 830
         // Fetch the invoice.
831
-        $invoice = new WPInv_Invoice( $invoice_id );
831
+        $invoice = new WPInv_Invoice($invoice_id);
832 832
         $alert   = false;
833 833
 
834 834
         // Ensure it exists and its not been paid for.
835
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
835
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
836 836
             exit;
837 837
         }
838 838
 
839 839
         // Add the item.
840
-        $item  = new GetPaid_Form_Item( $item_id );
840
+        $item  = new GetPaid_Form_Item($item_id);
841 841
 
842
-        $error = $invoice->add_item( $item );
842
+        $error = $invoice->add_item($item);
843 843
 
844
-        if ( is_wp_error( $error ) ) {
844
+        if (is_wp_error($error)) {
845 845
             $alert = $error->get_error_message();
846
-            wp_send_json_success( compact( 'alert' ) );
846
+            wp_send_json_success(compact('alert'));
847 847
         }
848 848
 
849 849
         // Save the invoice.
850 850
         $invoice->recalculate_total();
851 851
         $invoice->save();
852 852
         ob_start();
853
-        GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice );
853
+        GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice);
854 854
         $row = ob_get_clean();
855
-        wp_send_json_success( compact( 'row' ) );
855
+        wp_send_json_success(compact('row'));
856 856
     }
857 857
 
858 858
     /**
@@ -860,42 +860,42 @@  discard block
 block discarded – undo
860 860
      */
861 861
     public static function add_invoice_items() {
862 862
         // Verify nonce.
863
-        check_ajax_referer( 'wpinv-nonce' );
863
+        check_ajax_referer('wpinv-nonce');
864 864
 
865
-        $invoice_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
865
+        $invoice_id = !empty($_POST['post_id']) ? absint($_POST['post_id']) : 0;
866 866
 
867 867
         // We need an invoice and items.
868
-        if ( empty( $invoice_id ) || empty( $_POST['items'] ) ) {
868
+        if (empty($invoice_id) || empty($_POST['items'])) {
869 869
             exit;
870 870
         }
871 871
 
872 872
         // Can the user manage the plugin?
873
-        if ( ! wpinv_current_user_can( 'invoice_add_items', array( 'invoice_id' => $invoice_id ) ) ) {
873
+        if (!wpinv_current_user_can('invoice_add_items', array('invoice_id' => $invoice_id))) {
874 874
             exit;
875 875
         }
876 876
 
877 877
         // Fetch the invoice.
878
-        $invoice = new WPInv_Invoice( $invoice_id );
878
+        $invoice = new WPInv_Invoice($invoice_id);
879 879
         $alert   = false;
880 880
 
881 881
         // Ensure it exists and its not been paid for.
882
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
882
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
883 883
             exit;
884 884
         }
885 885
 
886 886
         // Add the items.
887
-        foreach ( wp_kses_post_deep( wp_unslash( $_POST['items'] ) ) as $data ) {
887
+        foreach (wp_kses_post_deep(wp_unslash($_POST['items'])) as $data) {
888 888
 
889
-            $item = new GetPaid_Form_Item( (int) $data['id'] );
889
+            $item = new GetPaid_Form_Item((int) $data['id']);
890 890
 
891
-            if ( is_numeric( $data['qty'] ) && (float) $data['qty'] > 0 ) {
892
-                $item->set_quantity( floatval( $data['qty'] ) );
891
+            if (is_numeric($data['qty']) && (float) $data['qty'] > 0) {
892
+                $item->set_quantity(floatval($data['qty']));
893 893
             }
894 894
 
895
-            if ( $item->get_id() > 0 ) {
896
-                $error = $invoice->add_item( $item );
895
+            if ($item->get_id() > 0) {
896
+                $error = $invoice->add_item($item);
897 897
 
898
-                if ( is_wp_error( $error ) ) {
898
+                if (is_wp_error($error)) {
899 899
                     $alert = $error->get_error_message();
900 900
                 }
901 901
 }
@@ -908,11 +908,11 @@  discard block
 block discarded – undo
908 908
         // Return an array of invoice items.
909 909
         $items = array();
910 910
 
911
-        foreach ( $invoice->get_items() as $item ) {
912
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
911
+        foreach ($invoice->get_items() as $item) {
912
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
913 913
         }
914 914
 
915
-        wp_send_json_success( compact( 'items', 'alert' ) );
915
+        wp_send_json_success(compact('items', 'alert'));
916 916
     }
917 917
 
918 918
     /**
@@ -920,16 +920,16 @@  discard block
 block discarded – undo
920 920
      */
921 921
     public static function get_invoicing_items() {
922 922
         // Verify nonce.
923
-        check_ajax_referer( 'wpinv-nonce' );
923
+        check_ajax_referer('wpinv-nonce');
924 924
 
925 925
         // Can the user manage the plugin?
926
-        if ( ! wpinv_current_user_can( 'get_invoicing_items' ) ) {
926
+        if (!wpinv_current_user_can('get_invoicing_items')) {
927 927
             exit;
928 928
         }
929 929
 
930 930
         // We need a search term.
931
-        if ( empty( $_GET['search'] ) ) {
932
-            wp_send_json_success( array() );
931
+        if (empty($_GET['search'])) {
932
+            wp_send_json_success(array());
933 933
         }
934 934
 
935 935
         // Retrieve items.
@@ -938,8 +938,8 @@  discard block
 block discarded – undo
938 938
             'orderby'        => 'title',
939 939
             'order'          => 'ASC',
940 940
             'posts_per_page' => -1,
941
-            'post_status'    => array( 'publish' ),
942
-            's'              => sanitize_text_field( urldecode( $_GET['search'] ) ),
941
+            'post_status'    => array('publish'),
942
+            's'              => sanitize_text_field(urldecode($_GET['search'])),
943 943
             'meta_query'     => array(
944 944
                 array(
945 945
                     'key'     => '_wpinv_type',
@@ -953,25 +953,25 @@  discard block
 block discarded – undo
953 953
             ),
954 954
         );
955 955
 
956
-        if ( ! empty( $_GET['ignore'] ) ) {
957
-            $item_args['exclude'] = wp_parse_id_list( sanitize_text_field( $_GET['ignore'] ) );
956
+        if (!empty($_GET['ignore'])) {
957
+            $item_args['exclude'] = wp_parse_id_list(sanitize_text_field($_GET['ignore']));
958 958
         }
959 959
 
960
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
960
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
961 961
         $data  = array();
962 962
 
963
-        $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( (int) $_GET['post_id'] ) );
963
+        $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type((int) $_GET['post_id']));
964 964
 
965
-        foreach ( $items as $item ) {
966
-            $item      = new GetPaid_Form_Item( $item );
965
+        foreach ($items as $item) {
966
+            $item = new GetPaid_Form_Item($item);
967 967
             $data[] = array(
968 968
                 'id'        => (int) $item->get_id(),
969
-                'text'      => strip_tags( $item->get_name() ),
970
-                'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '',
969
+                'text'      => strip_tags($item->get_name()),
970
+                'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '',
971 971
             );
972 972
         }
973 973
 
974
-        wp_send_json_success( $data );
974
+        wp_send_json_success($data);
975 975
 
976 976
     }
977 977
 
@@ -980,40 +980,40 @@  discard block
 block discarded – undo
980 980
      */
981 981
     public static function get_customers() {
982 982
         // Verify nonce.
983
-        check_ajax_referer( 'wpinv-nonce' );
983
+        check_ajax_referer('wpinv-nonce');
984 984
 
985
-        $invoice_id = ! empty( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
985
+        $invoice_id = !empty($_REQUEST['post_id']) ? (int) $_REQUEST['post_id'] : 0;
986 986
 
987 987
         // Can the user manage the plugin?
988
-        if ( ! wpinv_current_user_can( 'invoice_get_customers', array( 'invoice_id' => $invoice_id ) ) ) {
988
+        if (!wpinv_current_user_can('invoice_get_customers', array('invoice_id' => $invoice_id))) {
989 989
             die( -1 );
990 990
         }
991 991
 
992 992
         // We need a search term.
993
-        if ( empty( $_GET['search'] ) ) {
994
-            wp_send_json_success( array() );
993
+        if (empty($_GET['search'])) {
994
+            wp_send_json_success(array());
995 995
         }
996 996
 
997 997
         // Retrieve customers.
998 998
 
999 999
         $customer_args = array(
1000
-            'fields'         => array( 'ID', 'user_email', 'display_name' ),
1000
+            'fields'         => array('ID', 'user_email', 'display_name'),
1001 1001
             'orderby'        => 'display_name',
1002
-            'search'         => '*' . sanitize_text_field( $_GET['search'] ) . '*',
1003
-            'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
1002
+            'search'         => '*' . sanitize_text_field($_GET['search']) . '*',
1003
+            'search_columns' => array('user_login', 'user_email', 'display_name'),
1004 1004
         );
1005 1005
 
1006
-        $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) );
1006
+        $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args));
1007 1007
         $data      = array();
1008 1008
 
1009
-        foreach ( $customers as $customer ) {
1009
+        foreach ($customers as $customer) {
1010 1010
             $data[] = array(
1011 1011
                 'id'   => (int) $customer->ID,
1012
-                'text' => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ),
1012
+                'text' => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)),
1013 1013
             );
1014 1014
         }
1015 1015
 
1016
-        wp_send_json_success( $data );
1016
+        wp_send_json_success($data);
1017 1017
 
1018 1018
     }
1019 1019
 
@@ -1023,25 +1023,25 @@  discard block
 block discarded – undo
1023 1023
     public static function get_aui_states_field() {
1024 1024
 
1025 1025
         // We need a country.
1026
-        if ( empty( $_GET['country'] ) ) {
1026
+        if (empty($_GET['country'])) {
1027 1027
             exit;
1028 1028
         }
1029 1029
 
1030
-        $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) );
1031
-        $state  = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state();
1032
-        $name   = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state';
1033
-        $class  = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm';
1030
+        $states = wpinv_get_country_states(sanitize_text_field($_GET['country']));
1031
+        $state  = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state();
1032
+        $name   = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state';
1033
+        $class  = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm';
1034 1034
 
1035
-        if ( empty( $states ) ) {
1035
+        if (empty($states)) {
1036 1036
 
1037 1037
             $html = aui()->input(
1038 1038
                 array(
1039 1039
                     'type'        => 'text',
1040 1040
                     'id'          => 'wpinv_state',
1041 1041
                     'name'        => $name,
1042
-                    'label'       => __( 'State', 'invoicing' ),
1042
+                    'label'       => __('State', 'invoicing'),
1043 1043
                     'label_type'  => 'vertical',
1044
-                    'placeholder' => __( 'State', 'invoicing' ),
1044
+                    'placeholder' => __('State', 'invoicing'),
1045 1045
                     'class'       => $class,
1046 1046
                     'value'       => $state,
1047 1047
                 )
@@ -1053,9 +1053,9 @@  discard block
 block discarded – undo
1053 1053
                 array(
1054 1054
                     'id'               => 'wpinv_state',
1055 1055
                     'name'             => $name,
1056
-                    'label'            => __( 'State', 'invoicing' ),
1056
+                    'label'            => __('State', 'invoicing'),
1057 1057
                     'label_type'       => 'vertical',
1058
-                    'placeholder'      => __( 'Select a state', 'invoicing' ),
1058
+                    'placeholder'      => __('Select a state', 'invoicing'),
1059 1059
                     'class'            => $class,
1060 1060
                     'value'            => $state,
1061 1061
                     'options'          => $states,
@@ -1069,7 +1069,7 @@  discard block
 block discarded – undo
1069 1069
         wp_send_json_success(
1070 1070
             array(
1071 1071
                 'html'   => $html,
1072
-                'select' => ! empty( $states ),
1072
+                'select' => !empty($states),
1073 1073
             )
1074 1074
         );
1075 1075
 
@@ -1083,8 +1083,8 @@  discard block
 block discarded – undo
1083 1083
     public static function payment_form_refresh_prices() {
1084 1084
 
1085 1085
         // ... form fields...
1086
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
1087
-            esc_html_e( 'Error: Reload the page and try again.', 'invoicing' );
1086
+        if (empty($_POST['getpaid_payment_form_submission'])) {
1087
+            esc_html_e('Error: Reload the page and try again.', 'invoicing');
1088 1088
             exit;
1089 1089
         }
1090 1090
 
@@ -1092,7 +1092,7 @@  discard block
 block discarded – undo
1092 1092
         $submission = new GetPaid_Payment_Form_Submission();
1093 1093
 
1094 1094
         // Do we have an error?
1095
-        if ( ! empty( $submission->last_error ) ) {
1095
+        if (!empty($submission->last_error)) {
1096 1096
             wp_send_json_error(
1097 1097
                 array(
1098 1098
                     'code'  => $submission->last_error_code,
@@ -1102,12 +1102,12 @@  discard block
 block discarded – undo
1102 1102
         }
1103 1103
 
1104 1104
         // Prepare the response.
1105
-        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission );
1105
+        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission);
1106 1106
 
1107 1107
         // Filter the response.
1108
-        $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission );
1108
+        $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission);
1109 1109
 
1110
-        wp_send_json_success( $response );
1110
+        wp_send_json_success($response);
1111 1111
     }
1112 1112
 
1113 1113
     /**
@@ -1119,63 +1119,63 @@  discard block
 block discarded – undo
1119 1119
 	public static function file_upload() {
1120 1120
 
1121 1121
         // Check nonce.
1122
-        check_ajax_referer( 'getpaid_form_nonce' );
1122
+        check_ajax_referer('getpaid_form_nonce');
1123 1123
 
1124
-        if ( empty( $_POST['form_id'] ) || empty( $_POST['field_name'] ) || empty( $_FILES['file'] ) ) {
1125
-            wp_die( esc_html_e( 'Bad Request', 'invoicing' ), 400 );
1124
+        if (empty($_POST['form_id']) || empty($_POST['field_name']) || empty($_FILES['file'])) {
1125
+            wp_die(esc_html_e('Bad Request', 'invoicing'), 400);
1126 1126
         }
1127 1127
 
1128 1128
         // Fetch form.
1129
-        $form = new GetPaid_Payment_Form( intval( $_POST['form_id'] ) );
1129
+        $form = new GetPaid_Payment_Form(intval($_POST['form_id']));
1130 1130
 
1131
-        if ( ! $form->is_active() ) {
1132
-            wp_send_json_error( __( 'Payment form not active', 'invoicing' ) );
1131
+        if (!$form->is_active()) {
1132
+            wp_send_json_error(__('Payment form not active', 'invoicing'));
1133 1133
         }
1134 1134
 
1135 1135
         // Fetch appropriate field.
1136
-        $upload_field = current( wp_list_filter( $form->get_elements(), array( 'id' => sanitize_text_field( $_POST['field_name'] ) ) ) );
1137
-        if ( empty( $upload_field ) ) {
1138
-            wp_send_json_error( __( 'Invalid upload field.', 'invoicing' ) );
1136
+        $upload_field = current(wp_list_filter($form->get_elements(), array('id' => sanitize_text_field($_POST['field_name']))));
1137
+        if (empty($upload_field)) {
1138
+            wp_send_json_error(__('Invalid upload field.', 'invoicing'));
1139 1139
         }
1140 1140
 
1141 1141
         // Prepare allowed file types.
1142
-        $file_types = isset( $upload_field['file_types'] ) ? $upload_field['file_types'] : array( 'jpg|jpeg|jpe', 'gif', 'png' );
1142
+        $file_types = isset($upload_field['file_types']) ? $upload_field['file_types'] : array('jpg|jpeg|jpe', 'gif', 'png');
1143 1143
         $all_types  = getpaid_get_allowed_mime_types();
1144 1144
         $mime_types = array();
1145 1145
 
1146
-        foreach ( $file_types as $file_type ) {
1147
-            if ( isset( $all_types[ $file_type ] ) ) {
1148
-                $mime_types[] = $all_types[ $file_type ];
1146
+        foreach ($file_types as $file_type) {
1147
+            if (isset($all_types[$file_type])) {
1148
+                $mime_types[] = $all_types[$file_type];
1149 1149
             }
1150 1150
         }
1151 1151
 
1152
-        if ( ! in_array( $_FILES['file']['type'], $mime_types ) ) {
1153
-            wp_send_json_error( __( 'Unsupported file type.', 'invoicing' ) );
1152
+        if (!in_array($_FILES['file']['type'], $mime_types)) {
1153
+            wp_send_json_error(__('Unsupported file type.', 'invoicing'));
1154 1154
         }
1155 1155
 
1156 1156
         // Upload file.
1157
-        $file_name = explode( '.', strtolower( $_FILES['file']['name'] ) );
1158
-        $file_name = uniqid( 'getpaid-' ) . '.' . array_pop( $file_name );
1157
+        $file_name = explode('.', strtolower($_FILES['file']['name']));
1158
+        $file_name = uniqid('getpaid-') . '.' . array_pop($file_name);
1159 1159
 
1160 1160
         $uploaded = wp_upload_bits(
1161 1161
             $file_name,
1162 1162
             null,
1163
-            file_get_contents( $_FILES['file']['tmp_name'] )
1163
+            file_get_contents($_FILES['file']['tmp_name'])
1164 1164
         );
1165 1165
 
1166
-        if ( ! empty( $uploaded['error'] ) ) {
1167
-            wp_send_json_error( $uploaded['error'] );
1166
+        if (!empty($uploaded['error'])) {
1167
+            wp_send_json_error($uploaded['error']);
1168 1168
         }
1169 1169
 
1170 1170
         // Retrieve response.
1171 1171
         $response = sprintf(
1172 1172
             '<input type="hidden" name="%s[%s]" value="%s" />',
1173
-            esc_attr( sanitize_text_field( $_POST['field_name'] ) ),
1174
-            esc_url( $uploaded['url'] ),
1175
-            esc_attr( sanitize_text_field( strtolower( $_FILES['file']['name'] ) ) )
1173
+            esc_attr(sanitize_text_field($_POST['field_name'])),
1174
+            esc_url($uploaded['url']),
1175
+            esc_attr(sanitize_text_field(strtolower($_FILES['file']['name'])))
1176 1176
         );
1177 1177
 
1178
-        wp_send_json_success( $response );
1178
+        wp_send_json_success($response);
1179 1179
 
1180 1180
 	}
1181 1181
 
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data.php 2 patches
Indentation   +861 added lines, -861 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->exists() ) {
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.', 'invoicing' ), $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.', 'invoicing' ), $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->exists() ) {
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.', 'invoicing' ), $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.', 'invoicing' ), $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.', 'invoicing' ), $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.', 'invoicing' ), $key ), '1.0.19' );
384
+            }
385 385
 
386 386
             return call_user_func( array( $this, 'get_' . $key ) );
387 387
         }
@@ -391,513 +391,513 @@  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
-		$this->save();
509
-	}
510
-
511
-	/**
512
-	 * Update meta data by key or ID, if provided.
513
-	 *
514
-	 * @since  1.0.19
515
-	 *
516
-	 * @param  string       $key Meta key.
517
-	 * @param  string|array $value Meta value.
518
-	 * @param  int          $meta_id Meta ID.
519
-	 */
520
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
521
-		if ( $this->is_internal_meta_key( $key ) ) {
522
-			$function = 'set_' . $key;
523
-
524
-			if ( is_callable( array( $this, $function ) ) ) {
525
-				return $this->{$function}( $value );
526
-			}
527
-		}
528
-
529
-		$this->maybe_read_meta_data();
530
-
531
-		$array_key = false;
532
-
533
-		if ( $meta_id ) {
534
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
535
-			$array_key  = $array_keys ? current( $array_keys ) : false;
536
-		} else {
537
-			// Find matches by key.
538
-			$matches = array();
539
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
540
-				if ( $meta->key === $key ) {
541
-					$matches[] = $meta_data_array_key;
542
-				}
543
-			}
544
-
545
-			if ( ! empty( $matches ) ) {
546
-				// Set matches to null so only one key gets the new value.
547
-				foreach ( $matches as $meta_data_array_key ) {
548
-					$this->meta_data[ $meta_data_array_key ]->value = null;
549
-				}
550
-				$array_key = current( $matches );
551
-			}
552
-		}
553
-
554
-		if ( false !== $array_key ) {
555
-			$meta        = $this->meta_data[ $array_key ];
556
-			$meta->key   = $key;
557
-			$meta->value = $value;
558
-		} else {
559
-			$this->add_meta_data( $key, $value, true );
560
-		}
561
-	}
562
-
563
-	/**
564
-	 * Delete meta data.
565
-	 *
566
-	 * @since 1.0.19
567
-	 * @param string $key Meta key.
568
-	 */
569
-	public function delete_meta_data( $key ) {
570
-		$this->maybe_read_meta_data();
571
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
572
-
573
-		if ( $array_keys ) {
574
-			foreach ( $array_keys as $array_key ) {
575
-				$this->meta_data[ $array_key ]->value = null;
576
-			}
577
-		}
578
-	}
579
-
580
-	/**
581
-	 * Delete meta data.
582
-	 *
583
-	 * @since 1.0.19
584
-	 * @param int $mid Meta ID.
585
-	 */
586
-	public function delete_meta_data_by_mid( $mid ) {
587
-		$this->maybe_read_meta_data();
588
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
589
-
590
-		if ( $array_keys ) {
591
-			foreach ( $array_keys as $array_key ) {
592
-				$this->meta_data[ $array_key ]->value = null;
593
-			}
594
-		}
595
-	}
596
-
597
-	/**
598
-	 * Read meta data if null.
599
-	 *
600
-	 * @since 1.0.19
601
-	 */
602
-	protected function maybe_read_meta_data() {
603
-		if ( is_null( $this->meta_data ) ) {
604
-			$this->read_meta_data();
605
-		}
606
-	}
607
-
608
-	/**
609
-	 * Read Meta Data from the database. Ignore any internal properties.
610
-	 * Uses it's own caches because get_metadata does not provide meta_ids.
611
-	 *
612
-	 * @since 1.0.19
613
-	 * @param bool $force_read True to force a new DB read (and update cache).
614
-	 */
615
-	public function read_meta_data( $force_read = false ) {
616
-
617
-		// Reset meta data.
618
-		$this->meta_data = array();
619
-
620
-		// Maybe abort early.
621
-		if ( ! $this->get_id() || ! $this->data_store ) {
622
-			return;
623
-		}
624
-
625
-		// Only read from cache if the cache key is set.
626
-		$cache_key = null;
627
-		if ( ! $force_read && ! empty( $this->cache_group ) ) {
628
-			$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();
629
-			$raw_meta_data = wp_cache_get( $cache_key, $this->cache_group );
630
-		}
631
-
632
-		// Should we force read?
633
-		if ( empty( $raw_meta_data ) ) {
634
-			$raw_meta_data = $this->data_store->read_meta( $this );
635
-
636
-			if ( ! empty( $cache_key ) ) {
637
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
638
-			}
639
-        }
640
-
641
-		// Set meta data.
642
-		if ( is_array( $raw_meta_data ) ) {
643
-
644
-			foreach ( $raw_meta_data as $meta ) {
645
-				$this->meta_data[] = new GetPaid_Meta_Data(
646
-					array(
647
-						'id'    => (int) $meta->meta_id,
648
-						'key'   => $meta->meta_key,
649
-						'value' => maybe_unserialize( $meta->meta_value ),
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
+        $this->save();
509
+    }
510
+
511
+    /**
512
+     * Update meta data by key or ID, if provided.
513
+     *
514
+     * @since  1.0.19
515
+     *
516
+     * @param  string       $key Meta key.
517
+     * @param  string|array $value Meta value.
518
+     * @param  int          $meta_id Meta ID.
519
+     */
520
+    public function update_meta_data( $key, $value, $meta_id = 0 ) {
521
+        if ( $this->is_internal_meta_key( $key ) ) {
522
+            $function = 'set_' . $key;
523
+
524
+            if ( is_callable( array( $this, $function ) ) ) {
525
+                return $this->{$function}( $value );
526
+            }
527
+        }
528
+
529
+        $this->maybe_read_meta_data();
530
+
531
+        $array_key = false;
532
+
533
+        if ( $meta_id ) {
534
+            $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
535
+            $array_key  = $array_keys ? current( $array_keys ) : false;
536
+        } else {
537
+            // Find matches by key.
538
+            $matches = array();
539
+            foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
540
+                if ( $meta->key === $key ) {
541
+                    $matches[] = $meta_data_array_key;
542
+                }
543
+            }
544
+
545
+            if ( ! empty( $matches ) ) {
546
+                // Set matches to null so only one key gets the new value.
547
+                foreach ( $matches as $meta_data_array_key ) {
548
+                    $this->meta_data[ $meta_data_array_key ]->value = null;
549
+                }
550
+                $array_key = current( $matches );
551
+            }
552
+        }
553
+
554
+        if ( false !== $array_key ) {
555
+            $meta        = $this->meta_data[ $array_key ];
556
+            $meta->key   = $key;
557
+            $meta->value = $value;
558
+        } else {
559
+            $this->add_meta_data( $key, $value, true );
560
+        }
561
+    }
562
+
563
+    /**
564
+     * Delete meta data.
565
+     *
566
+     * @since 1.0.19
567
+     * @param string $key Meta key.
568
+     */
569
+    public function delete_meta_data( $key ) {
570
+        $this->maybe_read_meta_data();
571
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
572
+
573
+        if ( $array_keys ) {
574
+            foreach ( $array_keys as $array_key ) {
575
+                $this->meta_data[ $array_key ]->value = null;
576
+            }
577
+        }
578
+    }
579
+
580
+    /**
581
+     * Delete meta data.
582
+     *
583
+     * @since 1.0.19
584
+     * @param int $mid Meta ID.
585
+     */
586
+    public function delete_meta_data_by_mid( $mid ) {
587
+        $this->maybe_read_meta_data();
588
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
589
+
590
+        if ( $array_keys ) {
591
+            foreach ( $array_keys as $array_key ) {
592
+                $this->meta_data[ $array_key ]->value = null;
593
+            }
594
+        }
595
+    }
596
+
597
+    /**
598
+     * Read meta data if null.
599
+     *
600
+     * @since 1.0.19
601
+     */
602
+    protected function maybe_read_meta_data() {
603
+        if ( is_null( $this->meta_data ) ) {
604
+            $this->read_meta_data();
605
+        }
606
+    }
607
+
608
+    /**
609
+     * Read Meta Data from the database. Ignore any internal properties.
610
+     * Uses it's own caches because get_metadata does not provide meta_ids.
611
+     *
612
+     * @since 1.0.19
613
+     * @param bool $force_read True to force a new DB read (and update cache).
614
+     */
615
+    public function read_meta_data( $force_read = false ) {
616
+
617
+        // Reset meta data.
618
+        $this->meta_data = array();
619
+
620
+        // Maybe abort early.
621
+        if ( ! $this->get_id() || ! $this->data_store ) {
622
+            return;
623
+        }
624
+
625
+        // Only read from cache if the cache key is set.
626
+        $cache_key = null;
627
+        if ( ! $force_read && ! empty( $this->cache_group ) ) {
628
+            $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();
629
+            $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group );
630
+        }
631
+
632
+        // Should we force read?
633
+        if ( empty( $raw_meta_data ) ) {
634
+            $raw_meta_data = $this->data_store->read_meta( $this );
635
+
636
+            if ( ! empty( $cache_key ) ) {
637
+                wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
638
+            }
639
+        }
640
+
641
+        // Set meta data.
642
+        if ( is_array( $raw_meta_data ) ) {
643
+
644
+            foreach ( $raw_meta_data as $meta ) {
645
+                $this->meta_data[] = new GetPaid_Meta_Data(
646
+                    array(
647
+                        'id'    => (int) $meta->meta_id,
648
+                        'key'   => $meta->meta_key,
649
+                        'value' => maybe_unserialize( $meta->meta_value ),
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
-		$props = wp_unslash( $props );
762
-		foreach ( $props as $prop => $value ) {
763
-			try {
764
-				/**
765
-				 * Checks if the prop being set is allowed, and the value is not null.
766
-				 */
767
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
768
-					continue;
769
-				}
770
-				$setter = "set_$prop";
771
-
772
-				if ( is_callable( array( $this, $setter ) ) ) {
773
-					$this->{$setter}( $value );
774
-				}
775
-			} catch ( Exception $e ) {
776
-				if ( ! $errors ) {
777
-					$errors = new WP_Error();
778
-				}
779
-				$errors->add( $e->getCode(), $e->getMessage() );
780
-				$this->last_error = $e->getMessage();
781
-			}
782
-		}
783
-
784
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
785
-	}
786
-
787
-	/**
788
-	 * Sets a prop for a setter method.
789
-	 *
790
-	 * This stores changes in a special array so we can track what needs saving
791
-	 * the the DB later.
792
-	 *
793
-	 * @since 1.0.19
794
-	 * @param string $prop Name of prop to set.
795
-	 * @param mixed  $value Value of the prop.
796
-	 */
797
-	protected function set_prop( $prop, $value ) {
798
-		if ( array_key_exists( $prop, $this->data ) ) {
799
-			if ( true === $this->object_read ) {
800
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
801
-					$this->changes[ $prop ] = $value;
802
-				}
803
-			} else {
804
-				$this->data[ $prop ] = $value;
805
-			}
806
-		}
807
-	}
808
-
809
-	/**
810
-	 * Return data changes only.
811
-	 *
812
-	 * @since 1.0.19
813
-	 * @return array
814
-	 */
815
-	public function get_changes() {
816
-		return $this->changes;
817
-	}
818
-
819
-	/**
820
-	 * Merge changes with data and clear.
821
-	 *
822
-	 * @since 1.0.19
823
-	 */
824
-	public function apply_changes() {
825
-		$this->data    = array_replace( $this->data, $this->changes );
826
-		$this->changes = array();
827
-	}
828
-
829
-	/**
830
-	 * Prefix for action and filter hooks on data.
831
-	 *
832
-	 * @since  1.0.19
833
-	 * @return string
834
-	 */
835
-	protected function get_hook_prefix() {
836
-		return 'wpinv_get_' . $this->object_type . '_';
837
-	}
838
-
839
-	/**
840
-	 * Gets a prop for a getter method.
841
-	 *
842
-	 * Gets the value from either current pending changes, or the data itself.
843
-	 * Context controls what happens to the value before it's returned.
844
-	 *
845
-	 * @since  1.0.19
846
-	 * @param  string $prop Name of prop to get.
847
-	 * @param  string $context What the value is for. Valid values are view and edit.
848
-	 * @return mixed
849
-	 */
850
-	protected function get_prop( $prop, $context = 'view' ) {
851
-		$value = null;
852
-
853
-		if ( array_key_exists( $prop, $this->data ) ) {
854
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
855
-
856
-			if ( 'view' === $context ) {
857
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
858
-			}
859
-		}
860
-
861
-		return $value;
862
-	}
863
-
864
-	/**
865
-	 * Sets a date prop whilst handling formatting and datetime objects.
866
-	 *
867
-	 * @since 1.0.19
868
-	 * @param string         $prop Name of prop to set.
869
-	 * @param string|integer $value Value of the prop.
870
-	 */
871
-	protected function set_date_prop( $prop, $value ) {
872
-
873
-		if ( empty( $value ) ) {
874
-			$this->set_prop( $prop, null );
875
-			return;
876
-		}
877
-		$this->set_prop( $prop, $value );
878
-
879
-	}
880
-
881
-	/**
882
-	 * When invalid data is found, throw an exception unless reading from the DB.
883
-	 *
884
-	 * @since 1.0.19
885
-	 * @param string $code             Error code.
886
-	 * @param string $message          Error message.
887
-	 */
888
-	protected function error( $code, $message ) {
889
-		$this->last_error = $message;
890
-	}
891
-
892
-	/**
893
-	 * Checks if the object is saved in the database
894
-	 *
895
-	 * @since 1.0.19
896
-	 * @return bool
897
-	 */
898
-	public function exists() {
899
-		$id = $this->get_id();
900
-		return ! empty( $id );
901
-	}
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
+        $props = wp_unslash( $props );
762
+        foreach ( $props as $prop => $value ) {
763
+            try {
764
+                /**
765
+                 * Checks if the prop being set is allowed, and the value is not null.
766
+                 */
767
+                if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
768
+                    continue;
769
+                }
770
+                $setter = "set_$prop";
771
+
772
+                if ( is_callable( array( $this, $setter ) ) ) {
773
+                    $this->{$setter}( $value );
774
+                }
775
+            } catch ( Exception $e ) {
776
+                if ( ! $errors ) {
777
+                    $errors = new WP_Error();
778
+                }
779
+                $errors->add( $e->getCode(), $e->getMessage() );
780
+                $this->last_error = $e->getMessage();
781
+            }
782
+        }
783
+
784
+        return $errors && count( $errors->get_error_codes() ) ? $errors : true;
785
+    }
786
+
787
+    /**
788
+     * Sets a prop for a setter method.
789
+     *
790
+     * This stores changes in a special array so we can track what needs saving
791
+     * the the DB later.
792
+     *
793
+     * @since 1.0.19
794
+     * @param string $prop Name of prop to set.
795
+     * @param mixed  $value Value of the prop.
796
+     */
797
+    protected function set_prop( $prop, $value ) {
798
+        if ( array_key_exists( $prop, $this->data ) ) {
799
+            if ( true === $this->object_read ) {
800
+                if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
801
+                    $this->changes[ $prop ] = $value;
802
+                }
803
+            } else {
804
+                $this->data[ $prop ] = $value;
805
+            }
806
+        }
807
+    }
808
+
809
+    /**
810
+     * Return data changes only.
811
+     *
812
+     * @since 1.0.19
813
+     * @return array
814
+     */
815
+    public function get_changes() {
816
+        return $this->changes;
817
+    }
818
+
819
+    /**
820
+     * Merge changes with data and clear.
821
+     *
822
+     * @since 1.0.19
823
+     */
824
+    public function apply_changes() {
825
+        $this->data    = array_replace( $this->data, $this->changes );
826
+        $this->changes = array();
827
+    }
828
+
829
+    /**
830
+     * Prefix for action and filter hooks on data.
831
+     *
832
+     * @since  1.0.19
833
+     * @return string
834
+     */
835
+    protected function get_hook_prefix() {
836
+        return 'wpinv_get_' . $this->object_type . '_';
837
+    }
838
+
839
+    /**
840
+     * Gets a prop for a getter method.
841
+     *
842
+     * Gets the value from either current pending changes, or the data itself.
843
+     * Context controls what happens to the value before it's returned.
844
+     *
845
+     * @since  1.0.19
846
+     * @param  string $prop Name of prop to get.
847
+     * @param  string $context What the value is for. Valid values are view and edit.
848
+     * @return mixed
849
+     */
850
+    protected function get_prop( $prop, $context = 'view' ) {
851
+        $value = null;
852
+
853
+        if ( array_key_exists( $prop, $this->data ) ) {
854
+            $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
855
+
856
+            if ( 'view' === $context ) {
857
+                $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
858
+            }
859
+        }
860
+
861
+        return $value;
862
+    }
863
+
864
+    /**
865
+     * Sets a date prop whilst handling formatting and datetime objects.
866
+     *
867
+     * @since 1.0.19
868
+     * @param string         $prop Name of prop to set.
869
+     * @param string|integer $value Value of the prop.
870
+     */
871
+    protected function set_date_prop( $prop, $value ) {
872
+
873
+        if ( empty( $value ) ) {
874
+            $this->set_prop( $prop, null );
875
+            return;
876
+        }
877
+        $this->set_prop( $prop, $value );
878
+
879
+    }
880
+
881
+    /**
882
+     * When invalid data is found, throw an exception unless reading from the DB.
883
+     *
884
+     * @since 1.0.19
885
+     * @param string $code             Error code.
886
+     * @param string $message          Error message.
887
+     */
888
+    protected function error( $code, $message ) {
889
+        $this->last_error = $message;
890
+    }
891
+
892
+    /**
893
+     * Checks if the object is saved in the database
894
+     *
895
+     * @since 1.0.19
896
+     * @return bool
897
+     */
898
+    public function exists() {
899
+        $id = $this->get_id();
900
+        return ! empty( $id );
901
+    }
902 902
 
903 903
 }
Please login to merge, or discard this patch.
Spacing   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  *
9 9
  */
10 10
 
11
-if ( ! defined( 'ABSPATH' ) ) {
11
+if (!defined('ABSPATH')) {
12 12
 	exit;
13 13
 }
14 14
 
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 * @param int|object|array|string $read ID to load from the DB (optional) or already queried data.
119 119
 	 */
120
-	public function __construct( $read = 0 ) {
121
-		$this->data         = array_merge( $this->data, $this->extra_data );
120
+	public function __construct($read = 0) {
121
+		$this->data         = array_merge($this->data, $this->extra_data);
122 122
 		$this->default_data = $this->data;
123 123
 	}
124 124
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 * @return array
129 129
 	 */
130 130
 	public function __sleep() {
131
-		return array( 'id' );
131
+		return array('id');
132 132
 	}
133 133
 
134 134
 	/**
@@ -137,10 +137,10 @@  discard block
 block discarded – undo
137 137
 	 * If the object no longer exists, remove the ID.
138 138
 	 */
139 139
 	public function __wakeup() {
140
-		$this->__construct( absint( $this->id ) );
140
+		$this->__construct(absint($this->id));
141 141
 
142
-		if ( ! empty( $this->last_error ) ) {
143
-			$this->set_id( 0 );
142
+		if (!empty($this->last_error)) {
143
+			$this->set_id(0);
144 144
 		}
145 145
 
146 146
 	}
@@ -152,11 +152,11 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	public function __clone() {
154 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;
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 160
 				}
161 161
 			}
162 162
 		}
@@ -199,8 +199,8 @@  discard block
 block discarded – undo
199 199
 	 * @param  string $context View or edit context.
200 200
 	 * @return string
201 201
 	 */
202
-	public function get_status( $context = 'view' ) {
203
-		return $this->get_prop( 'status', $context );
202
+	public function get_status($context = 'view') {
203
+		return $this->get_prop('status', $context);
204 204
     }
205 205
 
206 206
 	/**
@@ -210,10 +210,10 @@  discard block
 block discarded – undo
210 210
 	 * @param  bool $force_delete Should the data be deleted permanently.
211 211
 	 * @return bool result
212 212
 	 */
213
-	public function delete( $force_delete = false ) {
214
-		if ( $this->data_store && $this->exists() ) {
215
-			$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
-			$this->set_id( 0 );
213
+	public function delete($force_delete = false) {
214
+		if ($this->data_store && $this->exists()) {
215
+			$this->data_store->delete($this, array('force_delete' => $force_delete));
216
+			$this->set_id(0);
217 217
 			return true;
218 218
 		}
219 219
 		return false;
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 	 * @return int
227 227
 	 */
228 228
 	public function save() {
229
-		if ( ! $this->data_store ) {
229
+		if (!$this->data_store) {
230 230
 			return $this->get_id();
231 231
 		}
232 232
 
@@ -236,12 +236,12 @@  discard block
 block discarded – undo
236 236
 		 * @param GetPaid_Data          $this The object being saved.
237 237
 		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238 238
 		 */
239
-		do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
239
+		do_action('getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store);
240 240
 
241
-		if ( $this->get_id() ) {
242
-			$this->data_store->update( $this );
241
+		if ($this->get_id()) {
242
+			$this->data_store->update($this);
243 243
 		} else {
244
-			$this->data_store->create( $this );
244
+			$this->data_store->create($this);
245 245
 		}
246 246
 
247 247
 		/**
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 		 * @param GetPaid_Data          $this The object being saved.
251 251
 		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252 252
 		 */
253
-		do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
253
+		do_action('getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store);
254 254
 
255 255
 		return $this->get_id();
256 256
 	}
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 	 * @return string Data in JSON format.
263 263
 	 */
264 264
 	public function __toString() {
265
-		return wp_json_encode( $this->get_data() );
265
+		return wp_json_encode($this->get_data());
266 266
 	}
267 267
 
268 268
 	/**
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 	 * @return array
273 273
 	 */
274 274
 	public function get_data() {
275
-		return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
275
+		return array_merge(array('id' => $this->get_id()), $this->data, array('meta_data' => $this->get_meta_data()));
276 276
 	}
277 277
 
278 278
 	/**
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 	 * @return array
283 283
 	 */
284 284
 	public function get_data_keys() {
285
-		return array_keys( $this->data );
285
+		return array_keys($this->data);
286 286
 	}
287 287
 
288 288
 	/**
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 	 * @return array
293 293
 	 */
294 294
 	public function get_extra_data_keys() {
295
-		return array_keys( $this->extra_data );
295
+		return array_keys($this->extra_data);
296 296
 	}
297 297
 
298 298
 	/**
@@ -302,8 +302,8 @@  discard block
 block discarded – undo
302 302
 	 * @param mixed $meta Meta value to check.
303 303
 	 * @return bool
304 304
 	 */
305
-	protected function filter_null_meta( $meta ) {
306
-		return ! is_null( $meta->value );
305
+	protected function filter_null_meta($meta) {
306
+		return !is_null($meta->value);
307 307
 	}
308 308
 
309 309
 	/**
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 	 */
315 315
 	public function get_meta_data() {
316 316
 		$this->maybe_read_meta_data();
317
-		return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
317
+		return array_values(array_filter($this->meta_data, array($this, 'filter_null_meta')));
318 318
 	}
319 319
 
320 320
 	/**
@@ -324,21 +324,21 @@  discard block
 block discarded – undo
324 324
 	 * @param  string $key Key to check.
325 325
 	 * @return bool   true if it's an internal key, false otherwise
326 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 );
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 329
 
330
-		if ( ! $internal_meta_key ) {
330
+		if (!$internal_meta_key) {
331 331
 			return false;
332 332
 		}
333 333
 
334
-		$has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
334
+		$has_setter_or_getter = is_callable(array($this, 'set_' . $key)) || is_callable(array($this, 'get_' . $key));
335 335
 
336
-		if ( ! $has_setter_or_getter ) {
336
+		if (!$has_setter_or_getter) {
337 337
 			return false;
338 338
 		}
339 339
 
340 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.', 'invoicing' ), $key ), '1.0.19' );
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.', 'invoicing'), $key), '1.0.19');
342 342
 
343 343
 		return true;
344 344
 	}
@@ -352,20 +352,20 @@  discard block
 block discarded – undo
352 352
 	 * @access public
353 353
 	 *
354 354
 	 */
355
-	public function __set( $key, $value ) {
355
+	public function __set($key, $value) {
356 356
 
357
-		if ( 'id' == strtolower( $key ) ) {
358
-			return $this->set_id( $value );
357
+		if ('id' == strtolower($key)) {
358
+			return $this->set_id($value);
359 359
 		}
360 360
 
361
-		if ( method_exists( $this, "set_$key" ) ) {
361
+		if (method_exists($this, "set_$key")) {
362 362
 
363 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.', 'invoicing' ), $key ), '1.0.19' );
364
+			getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing'), $key), '1.0.19');
365 365
 
366
-			call_user_func( array( $this, "set_$key" ), $value );
366
+			call_user_func(array($this, "set_$key"), $value);
367 367
 		} else {
368
-			$this->set_prop( $key, $value );
368
+			$this->set_prop($key, $value);
369 369
 		}
370 370
 
371 371
 	}
@@ -373,25 +373,25 @@  discard block
 block discarded – undo
373 373
 	/**
374 374
      * Margic method for retrieving a property.
375 375
      */
376
-    public function __get( $key ) {
376
+    public function __get($key) {
377 377
 
378 378
         // Check if we have a helper method for that.
379
-        if ( method_exists( $this, 'get_' . $key ) ) {
379
+        if (method_exists($this, 'get_' . $key)) {
380 380
 
381
-			if ( 'post_type' != $key ) {
381
+			if ('post_type' != $key) {
382 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.', 'invoicing' ), $key ), '1.0.19' );
383
+				getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing'), $key), '1.0.19');
384 384
 			}
385 385
 
386
-            return call_user_func( array( $this, 'get_' . $key ) );
386
+            return call_user_func(array($this, 'get_' . $key));
387 387
         }
388 388
 
389 389
         // Check if the key is in the associated $post object.
390
-        if ( ! empty( $this->post ) && isset( $this->post->$key ) ) {
390
+        if (!empty($this->post) && isset($this->post->$key)) {
391 391
             return $this->post->$key;
392 392
         }
393 393
 
394
-		return $this->get_prop( $key );
394
+		return $this->get_prop($key);
395 395
 
396 396
     }
397 397
 
@@ -404,15 +404,15 @@  discard block
 block discarded – undo
404 404
 	 * @param  string $context What the value is for. Valid values are view and edit.
405 405
 	 * @return mixed
406 406
 	 */
407
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
407
+	public function get_meta($key = '', $single = true, $context = 'view') {
408 408
 
409 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 ) ) {
410
+		$_key = str_replace('_wpinv', '', $key);
411
+		$_key = str_replace('wpinv', '', $_key);
412
+		if ($this->is_internal_meta_key($key)) {
413 413
 			$function = 'get_' . $_key;
414 414
 
415
-			if ( is_callable( array( $this, $function ) ) ) {
415
+			if (is_callable(array($this, $function))) {
416 416
 				return $this->{$function}();
417 417
 			}
418 418
 		}
@@ -420,20 +420,20 @@  discard block
 block discarded – undo
420 420
 		// Read the meta data if not yet read.
421 421
 		$this->maybe_read_meta_data();
422 422
 		$meta_data  = $this->get_meta_data();
423
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
423
+		$array_keys = array_keys(wp_list_pluck($meta_data, 'key'), $key, true);
424 424
 		$value      = $single ? '' : array();
425 425
 
426
-		if ( ! empty( $array_keys ) ) {
426
+		if (!empty($array_keys)) {
427 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;
428
+			if ($single) {
429
+				$value = $meta_data[current($array_keys)]->value;
430 430
 			} else {
431
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
431
+				$value = array_intersect_key($meta_data, array_flip($array_keys));
432 432
 			}
433 433
 		}
434 434
 
435
-		if ( 'view' === $context ) {
436
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
435
+		if ('view' === $context) {
436
+			$value = apply_filters($this->get_hook_prefix() . $key, $value, $this);
437 437
 		}
438 438
 
439 439
 		return $value;
@@ -446,10 +446,10 @@  discard block
 block discarded – undo
446 446
 	 * @param  string $key Meta Key.
447 447
 	 * @return boolean
448 448
 	 */
449
-	public function meta_exists( $key = '' ) {
449
+	public function meta_exists($key = '') {
450 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 );
451
+		$array_keys = wp_list_pluck($this->get_meta_data(), 'key');
452
+		return in_array($key, $array_keys, true);
453 453
 	}
454 454
 
455 455
 	/**
@@ -458,12 +458,12 @@  discard block
 block discarded – undo
458 458
 	 * @since 1.0.19
459 459
 	 * @param array $data Key/Value pairs.
460 460
 	 */
461
-	public function set_meta_data( $data ) {
462
-		if ( ! empty( $data ) && is_array( $data ) ) {
461
+	public function set_meta_data($data) {
462
+		if (!empty($data) && is_array($data)) {
463 463
 			$this->maybe_read_meta_data();
464
-			foreach ( $data as $meta ) {
464
+			foreach ($data as $meta) {
465 465
 				$meta = (array) $meta;
466
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
466
+				if (isset($meta['key'], $meta['value'], $meta['id'])) {
467 467
 					$this->meta_data[] = new GetPaid_Meta_Data(
468 468
 						array(
469 469
 							'id'    => $meta['id'],
@@ -485,18 +485,18 @@  discard block
 block discarded – undo
485 485
 	 * @param string|array $value Meta value.
486 486
 	 * @param bool         $unique Should this be a unique key?.
487 487
 	 */
488
-	public function add_meta_data( $key, $value, $unique = false ) {
489
-		if ( $this->is_internal_meta_key( $key ) ) {
488
+	public function add_meta_data($key, $value, $unique = false) {
489
+		if ($this->is_internal_meta_key($key)) {
490 490
 			$function = 'set_' . $key;
491 491
 
492
-			if ( is_callable( array( $this, $function ) ) ) {
493
-				return $this->{$function}( $value );
492
+			if (is_callable(array($this, $function))) {
493
+				return $this->{$function}($value);
494 494
 			}
495 495
 		}
496 496
 
497 497
 		$this->maybe_read_meta_data();
498
-		if ( $unique ) {
499
-			$this->delete_meta_data( $key );
498
+		if ($unique) {
499
+			$this->delete_meta_data($key);
500 500
 		}
501 501
 		$this->meta_data[] = new GetPaid_Meta_Data(
502 502
 			array(
@@ -517,12 +517,12 @@  discard block
 block discarded – undo
517 517
 	 * @param  string|array $value Meta value.
518 518
 	 * @param  int          $meta_id Meta ID.
519 519
 	 */
520
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
521
-		if ( $this->is_internal_meta_key( $key ) ) {
520
+	public function update_meta_data($key, $value, $meta_id = 0) {
521
+		if ($this->is_internal_meta_key($key)) {
522 522
 			$function = 'set_' . $key;
523 523
 
524
-			if ( is_callable( array( $this, $function ) ) ) {
525
-				return $this->{$function}( $value );
524
+			if (is_callable(array($this, $function))) {
525
+				return $this->{$function}($value);
526 526
 			}
527 527
 		}
528 528
 
@@ -530,33 +530,33 @@  discard block
 block discarded – undo
530 530
 
531 531
 		$array_key = false;
532 532
 
533
-		if ( $meta_id ) {
534
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
535
-			$array_key  = $array_keys ? current( $array_keys ) : false;
533
+		if ($meta_id) {
534
+			$array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), $meta_id, true);
535
+			$array_key  = $array_keys ? current($array_keys) : false;
536 536
 		} else {
537 537
 			// Find matches by key.
538 538
 			$matches = array();
539
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
540
-				if ( $meta->key === $key ) {
539
+			foreach ($this->meta_data as $meta_data_array_key => $meta) {
540
+				if ($meta->key === $key) {
541 541
 					$matches[] = $meta_data_array_key;
542 542
 				}
543 543
 			}
544 544
 
545
-			if ( ! empty( $matches ) ) {
545
+			if (!empty($matches)) {
546 546
 				// Set matches to null so only one key gets the new value.
547
-				foreach ( $matches as $meta_data_array_key ) {
548
-					$this->meta_data[ $meta_data_array_key ]->value = null;
547
+				foreach ($matches as $meta_data_array_key) {
548
+					$this->meta_data[$meta_data_array_key]->value = null;
549 549
 				}
550
-				$array_key = current( $matches );
550
+				$array_key = current($matches);
551 551
 			}
552 552
 		}
553 553
 
554
-		if ( false !== $array_key ) {
555
-			$meta        = $this->meta_data[ $array_key ];
554
+		if (false !== $array_key) {
555
+			$meta        = $this->meta_data[$array_key];
556 556
 			$meta->key   = $key;
557 557
 			$meta->value = $value;
558 558
 		} else {
559
-			$this->add_meta_data( $key, $value, true );
559
+			$this->add_meta_data($key, $value, true);
560 560
 		}
561 561
 	}
562 562
 
@@ -566,13 +566,13 @@  discard block
 block discarded – undo
566 566
 	 * @since 1.0.19
567 567
 	 * @param string $key Meta key.
568 568
 	 */
569
-	public function delete_meta_data( $key ) {
569
+	public function delete_meta_data($key) {
570 570
 		$this->maybe_read_meta_data();
571
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
571
+		$array_keys = array_keys(wp_list_pluck($this->meta_data, 'key'), $key, true);
572 572
 
573
-		if ( $array_keys ) {
574
-			foreach ( $array_keys as $array_key ) {
575
-				$this->meta_data[ $array_key ]->value = null;
573
+		if ($array_keys) {
574
+			foreach ($array_keys as $array_key) {
575
+				$this->meta_data[$array_key]->value = null;
576 576
 			}
577 577
 		}
578 578
 	}
@@ -583,13 +583,13 @@  discard block
 block discarded – undo
583 583
 	 * @since 1.0.19
584 584
 	 * @param int $mid Meta ID.
585 585
 	 */
586
-	public function delete_meta_data_by_mid( $mid ) {
586
+	public function delete_meta_data_by_mid($mid) {
587 587
 		$this->maybe_read_meta_data();
588
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
588
+		$array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), (int) $mid, true);
589 589
 
590
-		if ( $array_keys ) {
591
-			foreach ( $array_keys as $array_key ) {
592
-				$this->meta_data[ $array_key ]->value = null;
590
+		if ($array_keys) {
591
+			foreach ($array_keys as $array_key) {
592
+				$this->meta_data[$array_key]->value = null;
593 593
 			}
594 594
 		}
595 595
 	}
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
 	 * @since 1.0.19
601 601
 	 */
602 602
 	protected function maybe_read_meta_data() {
603
-		if ( is_null( $this->meta_data ) ) {
603
+		if (is_null($this->meta_data)) {
604 604
 			$this->read_meta_data();
605 605
 		}
606 606
 	}
@@ -612,41 +612,41 @@  discard block
 block discarded – undo
612 612
 	 * @since 1.0.19
613 613
 	 * @param bool $force_read True to force a new DB read (and update cache).
614 614
 	 */
615
-	public function read_meta_data( $force_read = false ) {
615
+	public function read_meta_data($force_read = false) {
616 616
 
617 617
 		// Reset meta data.
618 618
 		$this->meta_data = array();
619 619
 
620 620
 		// Maybe abort early.
621
-		if ( ! $this->get_id() || ! $this->data_store ) {
621
+		if (!$this->get_id() || !$this->data_store) {
622 622
 			return;
623 623
 		}
624 624
 
625 625
 		// Only read from cache if the cache key is set.
626 626
 		$cache_key = null;
627
-		if ( ! $force_read && ! empty( $this->cache_group ) ) {
628
-			$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();
629
-			$raw_meta_data = wp_cache_get( $cache_key, $this->cache_group );
627
+		if (!$force_read && !empty($this->cache_group)) {
628
+			$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();
629
+			$raw_meta_data = wp_cache_get($cache_key, $this->cache_group);
630 630
 		}
631 631
 
632 632
 		// Should we force read?
633
-		if ( empty( $raw_meta_data ) ) {
634
-			$raw_meta_data = $this->data_store->read_meta( $this );
633
+		if (empty($raw_meta_data)) {
634
+			$raw_meta_data = $this->data_store->read_meta($this);
635 635
 
636
-			if ( ! empty( $cache_key ) ) {
637
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
636
+			if (!empty($cache_key)) {
637
+				wp_cache_set($cache_key, $raw_meta_data, $this->cache_group);
638 638
 			}
639 639
         }
640 640
 
641 641
 		// Set meta data.
642
-		if ( is_array( $raw_meta_data ) ) {
642
+		if (is_array($raw_meta_data)) {
643 643
 
644
-			foreach ( $raw_meta_data as $meta ) {
644
+			foreach ($raw_meta_data as $meta) {
645 645
 				$this->meta_data[] = new GetPaid_Meta_Data(
646 646
 					array(
647 647
 						'id'    => (int) $meta->meta_id,
648 648
 						'key'   => $meta->meta_key,
649
-						'value' => maybe_unserialize( $meta->meta_value ),
649
+						'value' => maybe_unserialize($meta->meta_value),
650 650
 					)
651 651
 				);
652 652
 			}
@@ -660,28 +660,28 @@  discard block
 block discarded – undo
660 660
 	 * @since 1.0.19
661 661
 	 */
662 662
 	public function save_meta_data() {
663
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
663
+		if (!$this->data_store || is_null($this->meta_data)) {
664 664
 			return;
665 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 ] );
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 671
 				}
672
-			} elseif ( empty( $meta->id ) ) {
673
-				$meta->id = $this->data_store->add_meta( $this, $meta );
672
+			} elseif (empty($meta->id)) {
673
+				$meta->id = $this->data_store->add_meta($this, $meta);
674 674
 				$meta->apply_changes();
675 675
 			} else {
676
-				if ( $meta->get_changes() ) {
677
-					$this->data_store->update_meta( $this, $meta );
676
+				if ($meta->get_changes()) {
677
+					$this->data_store->update_meta($this, $meta);
678 678
 					$meta->apply_changes();
679 679
 				}
680 680
 			}
681 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 );
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 685
 		}
686 686
 	}
687 687
 
@@ -691,8 +691,8 @@  discard block
 block discarded – undo
691 691
 	 * @since 1.0.19
692 692
 	 * @param int $id ID.
693 693
 	 */
694
-	public function set_id( $id ) {
695
-		$this->id = absint( $id );
694
+	public function set_id($id) {
695
+		$this->id = absint($id);
696 696
 	}
697 697
 
698 698
 	/**
@@ -702,10 +702,10 @@  discard block
 block discarded – undo
702 702
 	 * @param string $status New status.
703 703
 	 * @return array details of change.
704 704
 	 */
705
-	public function set_status( $status ) {
705
+	public function set_status($status) {
706 706
         $old_status = $this->get_status();
707 707
 
708
-		$this->set_prop( 'status', $status );
708
+		$this->set_prop('status', $status);
709 709
 
710 710
 		return array(
711 711
 			'from' => $old_status,
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
 	public function set_defaults() {
722 722
 		$this->data    = $this->default_data;
723 723
 		$this->changes = array();
724
-		$this->set_object_read( false );
724
+		$this->set_object_read(false);
725 725
 	}
726 726
 
727 727
 	/**
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
 	 * @since 1.0.19
731 731
 	 * @param boolean $read Should read?.
732 732
 	 */
733
-	public function set_object_read( $read = true ) {
733
+	public function set_object_read($read = true) {
734 734
 		$this->object_read = (bool) $read;
735 735
 	}
736 736
 
@@ -755,33 +755,33 @@  discard block
 block discarded – undo
755 755
 	 *
756 756
 	 * @return bool|WP_Error
757 757
 	 */
758
-	public function set_props( $props, $context = 'set' ) {
758
+	public function set_props($props, $context = 'set') {
759 759
 		$errors = false;
760 760
 
761
-		$props = wp_unslash( $props );
762
-		foreach ( $props as $prop => $value ) {
761
+		$props = wp_unslash($props);
762
+		foreach ($props as $prop => $value) {
763 763
 			try {
764 764
 				/**
765 765
 				 * Checks if the prop being set is allowed, and the value is not null.
766 766
 				 */
767
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
767
+				if (is_null($value) || in_array($prop, array('prop', 'date_prop', 'meta_data'), true)) {
768 768
 					continue;
769 769
 				}
770 770
 				$setter = "set_$prop";
771 771
 
772
-				if ( is_callable( array( $this, $setter ) ) ) {
773
-					$this->{$setter}( $value );
772
+				if (is_callable(array($this, $setter))) {
773
+					$this->{$setter}($value);
774 774
 				}
775
-			} catch ( Exception $e ) {
776
-				if ( ! $errors ) {
775
+			} catch (Exception $e) {
776
+				if (!$errors) {
777 777
 					$errors = new WP_Error();
778 778
 				}
779
-				$errors->add( $e->getCode(), $e->getMessage() );
779
+				$errors->add($e->getCode(), $e->getMessage());
780 780
 				$this->last_error = $e->getMessage();
781 781
 			}
782 782
 		}
783 783
 
784
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
784
+		return $errors && count($errors->get_error_codes()) ? $errors : true;
785 785
 	}
786 786
 
787 787
 	/**
@@ -794,14 +794,14 @@  discard block
 block discarded – undo
794 794
 	 * @param string $prop Name of prop to set.
795 795
 	 * @param mixed  $value Value of the prop.
796 796
 	 */
797
-	protected function set_prop( $prop, $value ) {
798
-		if ( array_key_exists( $prop, $this->data ) ) {
799
-			if ( true === $this->object_read ) {
800
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
801
-					$this->changes[ $prop ] = $value;
797
+	protected function set_prop($prop, $value) {
798
+		if (array_key_exists($prop, $this->data)) {
799
+			if (true === $this->object_read) {
800
+				if ($value !== $this->data[$prop] || array_key_exists($prop, $this->changes)) {
801
+					$this->changes[$prop] = $value;
802 802
 				}
803 803
 			} else {
804
-				$this->data[ $prop ] = $value;
804
+				$this->data[$prop] = $value;
805 805
 			}
806 806
 		}
807 807
 	}
@@ -822,7 +822,7 @@  discard block
 block discarded – undo
822 822
 	 * @since 1.0.19
823 823
 	 */
824 824
 	public function apply_changes() {
825
-		$this->data    = array_replace( $this->data, $this->changes );
825
+		$this->data    = array_replace($this->data, $this->changes);
826 826
 		$this->changes = array();
827 827
 	}
828 828
 
@@ -847,14 +847,14 @@  discard block
 block discarded – undo
847 847
 	 * @param  string $context What the value is for. Valid values are view and edit.
848 848
 	 * @return mixed
849 849
 	 */
850
-	protected function get_prop( $prop, $context = 'view' ) {
850
+	protected function get_prop($prop, $context = 'view') {
851 851
 		$value = null;
852 852
 
853
-		if ( array_key_exists( $prop, $this->data ) ) {
854
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
853
+		if (array_key_exists($prop, $this->data)) {
854
+			$value = array_key_exists($prop, $this->changes) ? $this->changes[$prop] : $this->data[$prop];
855 855
 
856
-			if ( 'view' === $context ) {
857
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
856
+			if ('view' === $context) {
857
+				$value = apply_filters($this->get_hook_prefix() . $prop, $value, $this);
858 858
 			}
859 859
 		}
860 860
 
@@ -868,13 +868,13 @@  discard block
 block discarded – undo
868 868
 	 * @param string         $prop Name of prop to set.
869 869
 	 * @param string|integer $value Value of the prop.
870 870
 	 */
871
-	protected function set_date_prop( $prop, $value ) {
871
+	protected function set_date_prop($prop, $value) {
872 872
 
873
-		if ( empty( $value ) ) {
874
-			$this->set_prop( $prop, null );
873
+		if (empty($value)) {
874
+			$this->set_prop($prop, null);
875 875
 			return;
876 876
 		}
877
-		$this->set_prop( $prop, $value );
877
+		$this->set_prop($prop, $value);
878 878
 
879 879
 	}
880 880
 
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
 	 * @param string $code             Error code.
886 886
 	 * @param string $message          Error message.
887 887
 	 */
888
-	protected function error( $code, $message ) {
888
+	protected function error($code, $message) {
889 889
 		$this->last_error = $message;
890 890
 	}
891 891
 
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
 	 */
898 898
 	public function exists() {
899 899
 		$id = $this->get_id();
900
-		return ! empty( $id );
900
+		return !empty($id);
901 901
 	}
902 902
 
903 903
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-invoice-data-store.php 2 patches
Indentation   +481 added lines, -481 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,476 +15,476 @@  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_phone',
34
-		'_wpinv_company_id',
35
-		'wpinv_shipping',
36
-		'wpinv_email_cc',
37
-		'wpinv_template',
38
-		'wpinv_created_via',
39
-	);
40
-
41
-	/**
42
-	 * A map of meta keys to data props.
43
-	 *
44
-	 * @since 1.0.19
45
-	 *
46
-	 * @var array
47
-	 */
48
-	protected $meta_key_to_props = array(
49
-		'_wpinv_subscr_profile_id' => 'remote_subscription_id',
50
-		'_wpinv_subscription_id'   => 'subscription_id',
51
-		'_wpinv_taxes'             => 'taxes',
52
-		'_wpinv_fees'              => 'fees',
53
-		'_wpinv_discounts'         => 'discounts',
54
-		'_wpinv_submission_id'     => 'submission_id',
55
-		'_wpinv_payment_form'      => 'payment_form',
56
-		'_wpinv_is_viewed'         => 'is_viewed',
57
-		'wpinv_email_cc'           => 'email_cc',
58
-		'wpinv_template'           => 'template',
59
-		'wpinv_created_via'        => 'created_via',
60
-		'_wpinv_phone'             => 'phone',
61
-		'_wpinv_company_id'        => 'company_id',
62
-		'wpinv_shipping'           => 'shipping',
63
-	);
64
-
65
-	/**
66
-	 * A map of database fields to data props.
67
-	 *
68
-	 * @since 1.0.19
69
-	 *
70
-	 * @var array
71
-	 */
72
-	protected $database_fields_to_props = array(
73
-		'post_id'            => 'id',
74
-		'number'             => 'number',
75
-		'currency'           => 'currency',
76
-		'invoice_key'        => 'key',
77
-		'type'               => 'type',
78
-		'mode'               => 'mode',
79
-		'user_ip'            => 'user_ip',
80
-		'first_name'         => 'first_name',
81
-		'last_name'          => 'last_name',
82
-		'address'            => 'address',
83
-		'city'               => 'city',
84
-		'state'              => 'state',
85
-		'country'            => 'country',
86
-		'zip'                => 'zip',
87
-		'zip'                => 'zip',
88
-		'adddress_confirmed' => 'address_confirmed',
89
-		'gateway'            => 'gateway',
90
-		'transaction_id'     => 'transaction_id',
91
-		'currency'           => 'currency',
92
-		'subtotal'           => 'subtotal',
93
-		'tax'                => 'total_tax',
94
-		'fees_total'         => 'total_fees',
95
-		'discount'           => 'total_discount',
96
-		'total'              => 'total',
97
-		'discount_code'      => 'discount_code',
98
-		'disable_taxes'      => 'disable_taxes',
99
-		'due_date'           => 'due_date',
100
-		'completed_date'     => 'completed_date',
101
-		'company'            => 'company',
102
-		'vat_number'         => 'vat_number',
103
-		'vat_rate'           => 'vat_rate',
104
-		'customer_id'        => 'customer_id',
105
-	);
106
-
107
-	/*
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_phone',
34
+        '_wpinv_company_id',
35
+        'wpinv_shipping',
36
+        'wpinv_email_cc',
37
+        'wpinv_template',
38
+        'wpinv_created_via',
39
+    );
40
+
41
+    /**
42
+     * A map of meta keys to data props.
43
+     *
44
+     * @since 1.0.19
45
+     *
46
+     * @var array
47
+     */
48
+    protected $meta_key_to_props = array(
49
+        '_wpinv_subscr_profile_id' => 'remote_subscription_id',
50
+        '_wpinv_subscription_id'   => 'subscription_id',
51
+        '_wpinv_taxes'             => 'taxes',
52
+        '_wpinv_fees'              => 'fees',
53
+        '_wpinv_discounts'         => 'discounts',
54
+        '_wpinv_submission_id'     => 'submission_id',
55
+        '_wpinv_payment_form'      => 'payment_form',
56
+        '_wpinv_is_viewed'         => 'is_viewed',
57
+        'wpinv_email_cc'           => 'email_cc',
58
+        'wpinv_template'           => 'template',
59
+        'wpinv_created_via'        => 'created_via',
60
+        '_wpinv_phone'             => 'phone',
61
+        '_wpinv_company_id'        => 'company_id',
62
+        'wpinv_shipping'           => 'shipping',
63
+    );
64
+
65
+    /**
66
+     * A map of database fields to data props.
67
+     *
68
+     * @since 1.0.19
69
+     *
70
+     * @var array
71
+     */
72
+    protected $database_fields_to_props = array(
73
+        'post_id'            => 'id',
74
+        'number'             => 'number',
75
+        'currency'           => 'currency',
76
+        'invoice_key'        => 'key',
77
+        'type'               => 'type',
78
+        'mode'               => 'mode',
79
+        'user_ip'            => 'user_ip',
80
+        'first_name'         => 'first_name',
81
+        'last_name'          => 'last_name',
82
+        'address'            => 'address',
83
+        'city'               => 'city',
84
+        'state'              => 'state',
85
+        'country'            => 'country',
86
+        'zip'                => 'zip',
87
+        'zip'                => 'zip',
88
+        'adddress_confirmed' => 'address_confirmed',
89
+        'gateway'            => 'gateway',
90
+        'transaction_id'     => 'transaction_id',
91
+        'currency'           => 'currency',
92
+        'subtotal'           => 'subtotal',
93
+        'tax'                => 'total_tax',
94
+        'fees_total'         => 'total_fees',
95
+        'discount'           => 'total_discount',
96
+        'total'              => 'total',
97
+        'discount_code'      => 'discount_code',
98
+        'disable_taxes'      => 'disable_taxes',
99
+        'due_date'           => 'due_date',
100
+        'completed_date'     => 'completed_date',
101
+        'company'            => 'company',
102
+        'vat_number'         => 'vat_number',
103
+        'vat_rate'           => 'vat_rate',
104
+        'customer_id'        => 'customer_id',
105
+    );
106
+
107
+    /*
108 108
 	|--------------------------------------------------------------------------
109 109
 	| CRUD Methods
110 110
 	|--------------------------------------------------------------------------
111 111
 	*/
112 112
 
113
-	/**
114
-	 * Method to create a new invoice in the database.
115
-	 *
116
-	 * @param WPInv_Invoice $invoice Invoice object.
117
-	 */
118
-	public function create( &$invoice ) {
119
-		$invoice->set_version( WPINV_VERSION );
120
-		$invoice->set_date_created( current_time( 'mysql' ) );
121
-
122
-		// Create a new post.
123
-		$id = wp_insert_post(
124
-			apply_filters(
125
-				'getpaid_new_invoice_data',
126
-				array(
127
-					'post_date'    => $invoice->get_date_created( 'edit' ),
128
-					'post_type'    => $invoice->get_post_type( 'edit' ),
129
-					'post_status'  => $this->get_post_status( $invoice ),
130
-					'ping_status'  => 'closed',
131
-					'post_author'  => $invoice->get_user_id( 'edit' ),
132
-					'post_title'   => $invoice->get_title( 'edit' ),
133
-					'post_excerpt' => $invoice->get_description( 'edit' ),
134
-					'post_parent'  => $invoice->get_parent_id( 'edit' ),
135
-				)
136
-			),
137
-			true
138
-		);
139
-
140
-		if ( $id && ! is_wp_error( $id ) ) {
141
-
142
-			// Update the new id and regenerate a title.
143
-			$invoice->set_id( $id );
144
-
145
-			$invoice->maybe_set_number();
146
-
147
-			wp_update_post(
148
-				array(
149
-					'ID'         => $invoice->get_id(),
150
-					'post_title' => $invoice->get_number( 'edit' ),
151
-					'post_name'  => $invoice->get_path( 'edit' ),
152
-				)
153
-			);
154
-
155
-			// Save special fields and items.
156
-			$this->save_special_fields( $invoice );
157
-			$this->save_items( $invoice );
158
-
159
-			// Update meta data.
160
-			$this->update_post_meta( $invoice );
161
-			$invoice->save_meta_data();
162
-
163
-			// Apply changes.
164
-			$invoice->apply_changes();
165
-			$this->clear_caches( $invoice );
166
-
167
-			// Fires after a new invoice is created.
168
-			do_action( 'getpaid_new_invoice', $invoice );
169
-			return true;
170
-		}
171
-
172
-		if ( is_wp_error( $id ) ) {
173
-			$invoice->last_error = $id->get_error_message();
174
-		}
175
-
176
-		return false;
177
-	}
178
-
179
-	/**
180
-	 * Method to read an invoice from the database.
181
-	 *
182
-	 * @param WPInv_Invoice $invoice Invoice object.
183
-	 *
184
-	 */
185
-	public function read( &$invoice ) {
186
-
187
-		$invoice->set_defaults();
188
-		$invoice_object = get_post( $invoice->get_id() );
189
-
190
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
191
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
192
-			$invoice->set_id( 0 );
193
-			return false;
194
-		}
195
-
196
-		$invoice->set_props(
197
-			array(
198
-				'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
199
-				'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
200
-				'status'        => $invoice_object->post_status,
201
-				'author'        => $invoice_object->post_author,
202
-				'description'   => $invoice_object->post_excerpt,
203
-				'parent_id'     => $invoice_object->post_parent,
204
-				'name'          => $invoice_object->post_title,
205
-				'path'          => $invoice_object->post_name,
206
-				'post_type'     => $invoice_object->post_type,
207
-			)
208
-		);
209
-
210
-		$invoice->set_type( $invoice_object->post_type );
211
-
212
-		$this->read_object_data( $invoice, $invoice_object );
213
-		$this->add_special_fields( $invoice );
214
-		$this->add_items( $invoice );
215
-		$invoice->read_meta_data();
216
-		$invoice->set_object_read( true );
217
-		do_action( 'getpaid_read_invoice', $invoice );
218
-	}
219
-
220
-	/**
221
-	 * Method to update an invoice in the database.
222
-	 *
223
-	 * @param WPInv_Invoice $invoice Invoice object.
224
-	 */
225
-	public function update( &$invoice ) {
226
-		$invoice->save_meta_data();
227
-		$invoice->set_version( WPINV_VERSION );
228
-
229
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
230
-			$invoice->set_date_created( current_time( 'mysql' ) );
231
-		}
232
-
233
-		// Ensure both the key and number are set.
234
-		$invoice->get_path();
235
-
236
-		// Grab the current status so we can compare.
237
-		$previous_status = get_post_status( $invoice->get_id() );
238
-
239
-		$changes = $invoice->get_changes();
240
-
241
-		// Only update the post when the post data changes.
242
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
243
-			$post_data = array(
244
-				'post_date'     => $invoice->get_date_created( 'edit' ),
245
-				'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ),
246
-				'post_status'   => $invoice->get_status( 'edit' ),
247
-				'post_title'    => $invoice->get_name( 'edit' ),
248
-				'post_author'   => $invoice->get_user_id( 'edit' ),
249
-				'post_modified' => $invoice->get_date_modified( 'edit' ),
250
-				'post_excerpt'  => $invoice->get_description( 'edit' ),
251
-				'post_parent'   => $invoice->get_parent_id( 'edit' ),
252
-				'post_name'     => $invoice->get_path( 'edit' ),
253
-				'post_type'     => $invoice->get_post_type( 'edit' ),
254
-			);
255
-
256
-			/**
257
-			 * When updating this object, to prevent infinite loops, use $wpdb
258
-			 * to update data, since wp_update_post spawns more calls to the
259
-			 * save_post action.
260
-			 *
261
-			 * This ensures hooks are fired by either WP itself (admin screen save),
262
-			 * or an update purely from CRUD.
263
-			 */
264
-			if ( doing_action( 'save_post' ) ) {
265
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
266
-				clean_post_cache( $invoice->get_id() );
267
-			} else {
268
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
269
-			}
270
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
271
-		}
272
-
273
-		// Update meta data.
274
-		$this->update_post_meta( $invoice );
275
-
276
-		// Save special fields and items.
277
-		$this->save_special_fields( $invoice );
278
-		$this->save_items( $invoice );
279
-
280
-		// Apply the changes.
281
-		$invoice->apply_changes();
282
-
283
-		// Clear caches.
284
-		$this->clear_caches( $invoice );
285
-
286
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
287
-		$new_status = $invoice->get_status( 'edit' );
288
-
289
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
290
-			do_action( 'getpaid_new_invoice', $invoice );
291
-		} else {
292
-			do_action( 'getpaid_update_invoice', $invoice );
293
-		}
294
-	}
295
-
296
-	/*
113
+    /**
114
+     * Method to create a new invoice in the database.
115
+     *
116
+     * @param WPInv_Invoice $invoice Invoice object.
117
+     */
118
+    public function create( &$invoice ) {
119
+        $invoice->set_version( WPINV_VERSION );
120
+        $invoice->set_date_created( current_time( 'mysql' ) );
121
+
122
+        // Create a new post.
123
+        $id = wp_insert_post(
124
+            apply_filters(
125
+                'getpaid_new_invoice_data',
126
+                array(
127
+                    'post_date'    => $invoice->get_date_created( 'edit' ),
128
+                    'post_type'    => $invoice->get_post_type( 'edit' ),
129
+                    'post_status'  => $this->get_post_status( $invoice ),
130
+                    'ping_status'  => 'closed',
131
+                    'post_author'  => $invoice->get_user_id( 'edit' ),
132
+                    'post_title'   => $invoice->get_title( 'edit' ),
133
+                    'post_excerpt' => $invoice->get_description( 'edit' ),
134
+                    'post_parent'  => $invoice->get_parent_id( 'edit' ),
135
+                )
136
+            ),
137
+            true
138
+        );
139
+
140
+        if ( $id && ! is_wp_error( $id ) ) {
141
+
142
+            // Update the new id and regenerate a title.
143
+            $invoice->set_id( $id );
144
+
145
+            $invoice->maybe_set_number();
146
+
147
+            wp_update_post(
148
+                array(
149
+                    'ID'         => $invoice->get_id(),
150
+                    'post_title' => $invoice->get_number( 'edit' ),
151
+                    'post_name'  => $invoice->get_path( 'edit' ),
152
+                )
153
+            );
154
+
155
+            // Save special fields and items.
156
+            $this->save_special_fields( $invoice );
157
+            $this->save_items( $invoice );
158
+
159
+            // Update meta data.
160
+            $this->update_post_meta( $invoice );
161
+            $invoice->save_meta_data();
162
+
163
+            // Apply changes.
164
+            $invoice->apply_changes();
165
+            $this->clear_caches( $invoice );
166
+
167
+            // Fires after a new invoice is created.
168
+            do_action( 'getpaid_new_invoice', $invoice );
169
+            return true;
170
+        }
171
+
172
+        if ( is_wp_error( $id ) ) {
173
+            $invoice->last_error = $id->get_error_message();
174
+        }
175
+
176
+        return false;
177
+    }
178
+
179
+    /**
180
+     * Method to read an invoice from the database.
181
+     *
182
+     * @param WPInv_Invoice $invoice Invoice object.
183
+     *
184
+     */
185
+    public function read( &$invoice ) {
186
+
187
+        $invoice->set_defaults();
188
+        $invoice_object = get_post( $invoice->get_id() );
189
+
190
+        if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
191
+            $invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
192
+            $invoice->set_id( 0 );
193
+            return false;
194
+        }
195
+
196
+        $invoice->set_props(
197
+            array(
198
+                'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
199
+                'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
200
+                'status'        => $invoice_object->post_status,
201
+                'author'        => $invoice_object->post_author,
202
+                'description'   => $invoice_object->post_excerpt,
203
+                'parent_id'     => $invoice_object->post_parent,
204
+                'name'          => $invoice_object->post_title,
205
+                'path'          => $invoice_object->post_name,
206
+                'post_type'     => $invoice_object->post_type,
207
+            )
208
+        );
209
+
210
+        $invoice->set_type( $invoice_object->post_type );
211
+
212
+        $this->read_object_data( $invoice, $invoice_object );
213
+        $this->add_special_fields( $invoice );
214
+        $this->add_items( $invoice );
215
+        $invoice->read_meta_data();
216
+        $invoice->set_object_read( true );
217
+        do_action( 'getpaid_read_invoice', $invoice );
218
+    }
219
+
220
+    /**
221
+     * Method to update an invoice in the database.
222
+     *
223
+     * @param WPInv_Invoice $invoice Invoice object.
224
+     */
225
+    public function update( &$invoice ) {
226
+        $invoice->save_meta_data();
227
+        $invoice->set_version( WPINV_VERSION );
228
+
229
+        if ( null === $invoice->get_date_created( 'edit' ) ) {
230
+            $invoice->set_date_created( current_time( 'mysql' ) );
231
+        }
232
+
233
+        // Ensure both the key and number are set.
234
+        $invoice->get_path();
235
+
236
+        // Grab the current status so we can compare.
237
+        $previous_status = get_post_status( $invoice->get_id() );
238
+
239
+        $changes = $invoice->get_changes();
240
+
241
+        // Only update the post when the post data changes.
242
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
243
+            $post_data = array(
244
+                'post_date'     => $invoice->get_date_created( 'edit' ),
245
+                'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ),
246
+                'post_status'   => $invoice->get_status( 'edit' ),
247
+                'post_title'    => $invoice->get_name( 'edit' ),
248
+                'post_author'   => $invoice->get_user_id( 'edit' ),
249
+                'post_modified' => $invoice->get_date_modified( 'edit' ),
250
+                'post_excerpt'  => $invoice->get_description( 'edit' ),
251
+                'post_parent'   => $invoice->get_parent_id( 'edit' ),
252
+                'post_name'     => $invoice->get_path( 'edit' ),
253
+                'post_type'     => $invoice->get_post_type( 'edit' ),
254
+            );
255
+
256
+            /**
257
+             * When updating this object, to prevent infinite loops, use $wpdb
258
+             * to update data, since wp_update_post spawns more calls to the
259
+             * save_post action.
260
+             *
261
+             * This ensures hooks are fired by either WP itself (admin screen save),
262
+             * or an update purely from CRUD.
263
+             */
264
+            if ( doing_action( 'save_post' ) ) {
265
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
266
+                clean_post_cache( $invoice->get_id() );
267
+            } else {
268
+                wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
269
+            }
270
+            $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
271
+        }
272
+
273
+        // Update meta data.
274
+        $this->update_post_meta( $invoice );
275
+
276
+        // Save special fields and items.
277
+        $this->save_special_fields( $invoice );
278
+        $this->save_items( $invoice );
279
+
280
+        // Apply the changes.
281
+        $invoice->apply_changes();
282
+
283
+        // Clear caches.
284
+        $this->clear_caches( $invoice );
285
+
286
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
287
+        $new_status = $invoice->get_status( 'edit' );
288
+
289
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
290
+            do_action( 'getpaid_new_invoice', $invoice );
291
+        } else {
292
+            do_action( 'getpaid_update_invoice', $invoice );
293
+        }
294
+    }
295
+
296
+    /*
297 297
 	|--------------------------------------------------------------------------
298 298
 	| Additional Methods
299 299
 	|--------------------------------------------------------------------------
300 300
 	*/
301 301
 
302
-	/**
302
+    /**
303 303
      * Retrieves special fields and adds to the invoice.
304
-	 *
305
-	 * @param WPInv_Invoice $invoice Invoice object.
304
+     *
305
+     * @param WPInv_Invoice $invoice Invoice object.
306 306
      */
307 307
     public function add_special_fields( &$invoice ) {
308
-		global $wpdb;
309
-
310
-		// Maybe retrieve from the cache.
311
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
312
-
313
-		// If not found, retrieve from the db.
314
-		if ( false === $data ) {
315
-			$table = $wpdb->prefix . 'getpaid_invoices';
316
-
317
-			$data  = $wpdb->get_row(
318
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
319
-				ARRAY_A
320
-			);
321
-
322
-			// Update the cache with our data
323
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
324
-
325
-		}
326
-
327
-		// Abort if the data does not exist.
328
-		if ( empty( $data ) ) {
329
-			$invoice->set_object_read( true );
330
-			$invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
331
-			return;
332
-		}
333
-
334
-		$props = array();
335
-
336
-		foreach ( $this->database_fields_to_props as $db_field => $prop ) {
337
-
338
-			if ( $db_field == 'post_id' ) {
339
-				continue;
340
-			}
341
-
342
-			$props[ $prop ] = $data[ $db_field ];
343
-		}
344
-
345
-		$invoice->set_props( $props );
346
-	}
347
-
348
-	/**
349
-	 * Gets a list of special fields that need updated based on change state
350
-	 * or if they are present in the database or not.
351
-	 *
352
-	 * @param  WPInv_Invoice $invoice       The Invoice object.
353
-	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
354
-	 */
355
-	protected function get_special_fields_to_update( $invoice ) {
356
-		$fields_to_update = array();
357
-		$changed_props   = $invoice->get_changes();
358
-
359
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
360
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
361
-			if ( array_key_exists( $prop, $changed_props ) ) {
362
-				$fields_to_update[ $database_field ] = $prop;
363
-			}
364
-		}
365
-
366
-		return $fields_to_update;
367
-	}
368
-
369
-	/**
370
-	 * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
371
-	 *
372
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
373
-	 * @since 1.0.19
374
-	 */
375
-	protected function update_special_fields( &$invoice ) {
376
-		global $wpdb;
377
-
378
-		$updated_props    = array();
379
-		$fields_to_update = $this->get_special_fields_to_update( $invoice );
380
-
381
-		foreach ( $fields_to_update as $database_field => $prop ) {
382
-			$value = $invoice->{"get_$prop"}( 'edit' );
383
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
384
-			$value = is_bool( $value ) ? (int) $value : $value;
385
-			$updated_props[ $database_field ] = maybe_serialize( $value );
386
-		}
387
-
388
-		if ( ! empty( $updated_props ) ) {
389
-
390
-			$table = $wpdb->prefix . 'getpaid_invoices';
391
-			$wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
392
-			wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
393
-			do_action( 'getpaid_invoice_update_database_fields', $invoice, $updated_props );
394
-
395
-		}
396
-	}
397
-
398
-	/**
399
-	 * Helper method that inserts special fields to the database.
400
-	 *
401
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
402
-	 * @since 1.0.19
403
-	 */
404
-	protected function insert_special_fields( &$invoice ) {
405
-		global $wpdb;
406
-
407
-		$updated_props   = array();
408
-
409
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
410
-			$value = $invoice->{"get_$prop"}( 'edit' );
411
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
412
-			$value = is_bool( $value ) ? (int) $value : $value;
413
-			$updated_props[ $database_field ] = maybe_serialize( $value );
414
-		}
415
-
416
-		$table = $wpdb->prefix . 'getpaid_invoices';
417
-		$wpdb->insert( $table, $updated_props );
418
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
419
-		do_action( 'getpaid_invoice_insert_database_fields', $invoice, $updated_props );
420
-	}
421
-
422
-	/**
308
+        global $wpdb;
309
+
310
+        // Maybe retrieve from the cache.
311
+        $data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
312
+
313
+        // If not found, retrieve from the db.
314
+        if ( false === $data ) {
315
+            $table = $wpdb->prefix . 'getpaid_invoices';
316
+
317
+            $data  = $wpdb->get_row(
318
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
319
+                ARRAY_A
320
+            );
321
+
322
+            // Update the cache with our data
323
+            wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
324
+
325
+        }
326
+
327
+        // Abort if the data does not exist.
328
+        if ( empty( $data ) ) {
329
+            $invoice->set_object_read( true );
330
+            $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
331
+            return;
332
+        }
333
+
334
+        $props = array();
335
+
336
+        foreach ( $this->database_fields_to_props as $db_field => $prop ) {
337
+
338
+            if ( $db_field == 'post_id' ) {
339
+                continue;
340
+            }
341
+
342
+            $props[ $prop ] = $data[ $db_field ];
343
+        }
344
+
345
+        $invoice->set_props( $props );
346
+    }
347
+
348
+    /**
349
+     * Gets a list of special fields that need updated based on change state
350
+     * or if they are present in the database or not.
351
+     *
352
+     * @param  WPInv_Invoice $invoice       The Invoice object.
353
+     * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
354
+     */
355
+    protected function get_special_fields_to_update( $invoice ) {
356
+        $fields_to_update = array();
357
+        $changed_props   = $invoice->get_changes();
358
+
359
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
360
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
361
+            if ( array_key_exists( $prop, $changed_props ) ) {
362
+                $fields_to_update[ $database_field ] = $prop;
363
+            }
364
+        }
365
+
366
+        return $fields_to_update;
367
+    }
368
+
369
+    /**
370
+     * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
371
+     *
372
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
373
+     * @since 1.0.19
374
+     */
375
+    protected function update_special_fields( &$invoice ) {
376
+        global $wpdb;
377
+
378
+        $updated_props    = array();
379
+        $fields_to_update = $this->get_special_fields_to_update( $invoice );
380
+
381
+        foreach ( $fields_to_update as $database_field => $prop ) {
382
+            $value = $invoice->{"get_$prop"}( 'edit' );
383
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
384
+            $value = is_bool( $value ) ? (int) $value : $value;
385
+            $updated_props[ $database_field ] = maybe_serialize( $value );
386
+        }
387
+
388
+        if ( ! empty( $updated_props ) ) {
389
+
390
+            $table = $wpdb->prefix . 'getpaid_invoices';
391
+            $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
392
+            wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
393
+            do_action( 'getpaid_invoice_update_database_fields', $invoice, $updated_props );
394
+
395
+        }
396
+    }
397
+
398
+    /**
399
+     * Helper method that inserts special fields to the database.
400
+     *
401
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
402
+     * @since 1.0.19
403
+     */
404
+    protected function insert_special_fields( &$invoice ) {
405
+        global $wpdb;
406
+
407
+        $updated_props   = array();
408
+
409
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
410
+            $value = $invoice->{"get_$prop"}( 'edit' );
411
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
412
+            $value = is_bool( $value ) ? (int) $value : $value;
413
+            $updated_props[ $database_field ] = maybe_serialize( $value );
414
+        }
415
+
416
+        $table = $wpdb->prefix . 'getpaid_invoices';
417
+        $wpdb->insert( $table, $updated_props );
418
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
419
+        do_action( 'getpaid_invoice_insert_database_fields', $invoice, $updated_props );
420
+    }
421
+
422
+    /**
423 423
      * Saves all special fields.
424
-	 *
425
-	 * @param WPInv_Invoice $invoice Invoice object.
424
+     *
425
+     * @param WPInv_Invoice $invoice Invoice object.
426 426
      */
427 427
     public function save_special_fields( &$invoice ) {
428
-		global $wpdb;
428
+        global $wpdb;
429 429
 
430
-		// The invoices table.
431
-		$table = $wpdb->prefix . 'getpaid_invoices';
432
-		$id    = (int) $invoice->get_id();
433
-		$invoice->maybe_set_key();
430
+        // The invoices table.
431
+        $table = $wpdb->prefix . 'getpaid_invoices';
432
+        $id    = (int) $invoice->get_id();
433
+        $invoice->maybe_set_key();
434 434
 
435
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
435
+        if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
436 436
 
437
-			$this->update_special_fields( $invoice );
437
+            $this->update_special_fields( $invoice );
438 438
 
439
-		} else {
439
+        } else {
440 440
 
441
-			$this->insert_special_fields( $invoice );
441
+            $this->insert_special_fields( $invoice );
442 442
 
443
-		}
444
-	}
443
+        }
444
+    }
445 445
 
446
-	/**
446
+    /**
447 447
      * Set's up cart details.
448
-	 *
449
-	 * @param WPInv_Invoice $invoice Invoice object.
448
+     *
449
+     * @param WPInv_Invoice $invoice Invoice object.
450 450
      */
451 451
     public function add_items( &$invoice ) {
452
-		global $wpdb;
452
+        global $wpdb;
453 453
 
454
-		// Maybe retrieve from the cache.
455
-		$items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
454
+        // Maybe retrieve from the cache.
455
+        $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
456 456
 
457
-		// If not found, retrieve from the db.
458
-		if ( false === $items ) {
459
-			$table = $wpdb->prefix . 'getpaid_invoice_items';
457
+        // If not found, retrieve from the db.
458
+        if ( false === $items ) {
459
+            $table = $wpdb->prefix . 'getpaid_invoice_items';
460 460
 
461
-			$items = $wpdb->get_results(
462
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
463
-			);
461
+            $items = $wpdb->get_results(
462
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
463
+            );
464 464
 
465
-			// Update the cache with our data
466
-			wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
465
+            // Update the cache with our data
466
+            wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
467 467
 
468
-		}
468
+        }
469 469
 
470
-		// Abort if no items found.
470
+        // Abort if no items found.
471 471
         if ( empty( $items ) ) {
472 472
             return;
473
-		}
473
+        }
474 474
 
475
-		$_items = array();
476
-		foreach ( $items as $item_data ) {
477
-			$item = new GetPaid_Form_Item( $item_data->item_id );
475
+        $_items = array();
476
+        foreach ( $items as $item_data ) {
477
+            $item = new GetPaid_Form_Item( $item_data->item_id );
478 478
 
479
-			// Set item data.
480
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
481
-			$item->item_discount = wpinv_sanitize_amount( $item_data->discount );
482
-			$item->set_name( $item_data->item_name );
483
-			$item->set_description( $item_data->item_description );
479
+            // Set item data.
480
+            $item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
481
+            $item->item_discount = wpinv_sanitize_amount( $item_data->discount );
482
+            $item->set_name( $item_data->item_name );
483
+            $item->set_description( $item_data->item_description );
484 484
             $item->set_price( $item_data->item_price );
485
-			$item->set_quantity( $item_data->quantity );
486
-			$item->set_price_id( $item_data->price_id );
487
-			$item->set_item_meta( $item_data->meta );
485
+            $item->set_quantity( $item_data->quantity );
486
+            $item->set_price_id( $item_data->price_id );
487
+            $item->set_item_meta( $item_data->meta );
488 488
 
489 489
             if ( $item->has_variable_pricing() ) {
490 490
                 $price_options = $item->get_variable_prices();
@@ -518,68 +518,68 @@  discard block
 block discarded – undo
518 518
                 }
519 519
             }
520 520
 
521
-			$_items[] = $item;
522
-		}
521
+            $_items[] = $item;
522
+        }
523 523
 
524
-		$invoice->set_items( $_items );
525
-	}
524
+        $invoice->set_items( $_items );
525
+    }
526 526
 
527
-	/**
527
+    /**
528 528
      * Saves cart details.
529
-	 *
530
-	 * @param WPInv_Invoice $invoice Invoice object.
529
+     *
530
+     * @param WPInv_Invoice $invoice Invoice object.
531 531
      */
532 532
     public function save_items( $invoice ) {
533 533
 
534
-		// Delete previously existing items.
535
-		$this->delete_items( $invoice );
534
+        // Delete previously existing items.
535
+        $this->delete_items( $invoice );
536 536
 
537
-		$table   = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
537
+        $table   = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
538 538
 
539
-		foreach ( $invoice->get_cart_details() as $item_data ) {
540
-			$item_data = array_map( 'maybe_serialize', $item_data );
541
-			$GLOBALS['wpdb']->insert( $table, $item_data );
542
-		}
539
+        foreach ( $invoice->get_cart_details() as $item_data ) {
540
+            $item_data = array_map( 'maybe_serialize', $item_data );
541
+            $GLOBALS['wpdb']->insert( $table, $item_data );
542
+        }
543 543
 
544
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
545
-		do_action( 'getpaid_invoice_save_items', $invoice );
546
-	}
544
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
545
+        do_action( 'getpaid_invoice_save_items', $invoice );
546
+    }
547 547
 
548
-	/**
548
+    /**
549 549
      * Deletes an invoice's cart details from the database.
550
-	 *
551
-	 * @param WPInv_Invoice $invoice Invoice object.
550
+     *
551
+     * @param WPInv_Invoice $invoice Invoice object.
552 552
      */
553 553
     public function delete_items( $invoice ) {
554
-		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
555
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
556
-	}
554
+        $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
555
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
556
+    }
557 557
 
558
-	/**
558
+    /**
559 559
      * Deletes an invoice's special fields from the database.
560
-	 *
561
-	 * @param WPInv_Invoice $invoice Invoice object.
560
+     *
561
+     * @param WPInv_Invoice $invoice Invoice object.
562 562
      */
563 563
     public function delete_special_fields( $invoice ) {
564
-		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
565
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
566
-	}
567
-
568
-	/**
569
-	 * Get the status to save to the post object.
570
-	 *
571
-	 *
572
-	 * @since 1.0.19
573
-	 * @param  WPInv_Invoice $object GetPaid_Data object.
574
-	 * @return string
575
-	 */
576
-	protected function get_post_status( $object ) {
577
-		$object_status = $object->get_status( 'edit' );
578
-
579
-		if ( ! $object_status ) {
580
-			$object_status = $object->get_default_status();
581
-		}
582
-
583
-		return $object_status;
584
-	}
564
+        $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
565
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
566
+    }
567
+
568
+    /**
569
+     * Get the status to save to the post object.
570
+     *
571
+     *
572
+     * @since 1.0.19
573
+     * @param  WPInv_Invoice $object GetPaid_Data object.
574
+     * @return string
575
+     */
576
+    protected function get_post_status( $object ) {
577
+        $object_status = $object->get_status( 'edit' );
578
+
579
+        if ( ! $object_status ) {
580
+            $object_status = $object->get_default_status();
581
+        }
582
+
583
+        return $object_status;
584
+    }
585 585
 }
Please login to merge, or discard this patch.
Spacing   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * GetPaid_Invoice_Data_Store class file.
5 5
  *
6 6
  */
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
 	exit;
9 9
 }
10 10
 
@@ -115,61 +115,61 @@  discard block
 block discarded – undo
115 115
 	 *
116 116
 	 * @param WPInv_Invoice $invoice Invoice object.
117 117
 	 */
118
-	public function create( &$invoice ) {
119
-		$invoice->set_version( WPINV_VERSION );
120
-		$invoice->set_date_created( current_time( 'mysql' ) );
118
+	public function create(&$invoice) {
119
+		$invoice->set_version(WPINV_VERSION);
120
+		$invoice->set_date_created(current_time('mysql'));
121 121
 
122 122
 		// Create a new post.
123 123
 		$id = wp_insert_post(
124 124
 			apply_filters(
125 125
 				'getpaid_new_invoice_data',
126 126
 				array(
127
-					'post_date'    => $invoice->get_date_created( 'edit' ),
128
-					'post_type'    => $invoice->get_post_type( 'edit' ),
129
-					'post_status'  => $this->get_post_status( $invoice ),
127
+					'post_date'    => $invoice->get_date_created('edit'),
128
+					'post_type'    => $invoice->get_post_type('edit'),
129
+					'post_status'  => $this->get_post_status($invoice),
130 130
 					'ping_status'  => 'closed',
131
-					'post_author'  => $invoice->get_user_id( 'edit' ),
132
-					'post_title'   => $invoice->get_title( 'edit' ),
133
-					'post_excerpt' => $invoice->get_description( 'edit' ),
134
-					'post_parent'  => $invoice->get_parent_id( 'edit' ),
131
+					'post_author'  => $invoice->get_user_id('edit'),
132
+					'post_title'   => $invoice->get_title('edit'),
133
+					'post_excerpt' => $invoice->get_description('edit'),
134
+					'post_parent'  => $invoice->get_parent_id('edit'),
135 135
 				)
136 136
 			),
137 137
 			true
138 138
 		);
139 139
 
140
-		if ( $id && ! is_wp_error( $id ) ) {
140
+		if ($id && !is_wp_error($id)) {
141 141
 
142 142
 			// Update the new id and regenerate a title.
143
-			$invoice->set_id( $id );
143
+			$invoice->set_id($id);
144 144
 
145 145
 			$invoice->maybe_set_number();
146 146
 
147 147
 			wp_update_post(
148 148
 				array(
149 149
 					'ID'         => $invoice->get_id(),
150
-					'post_title' => $invoice->get_number( 'edit' ),
151
-					'post_name'  => $invoice->get_path( 'edit' ),
150
+					'post_title' => $invoice->get_number('edit'),
151
+					'post_name'  => $invoice->get_path('edit'),
152 152
 				)
153 153
 			);
154 154
 
155 155
 			// Save special fields and items.
156
-			$this->save_special_fields( $invoice );
157
-			$this->save_items( $invoice );
156
+			$this->save_special_fields($invoice);
157
+			$this->save_items($invoice);
158 158
 
159 159
 			// Update meta data.
160
-			$this->update_post_meta( $invoice );
160
+			$this->update_post_meta($invoice);
161 161
 			$invoice->save_meta_data();
162 162
 
163 163
 			// Apply changes.
164 164
 			$invoice->apply_changes();
165
-			$this->clear_caches( $invoice );
165
+			$this->clear_caches($invoice);
166 166
 
167 167
 			// Fires after a new invoice is created.
168
-			do_action( 'getpaid_new_invoice', $invoice );
168
+			do_action('getpaid_new_invoice', $invoice);
169 169
 			return true;
170 170
 		}
171 171
 
172
-		if ( is_wp_error( $id ) ) {
172
+		if (is_wp_error($id)) {
173 173
 			$invoice->last_error = $id->get_error_message();
174 174
 		}
175 175
 
@@ -182,14 +182,14 @@  discard block
 block discarded – undo
182 182
 	 * @param WPInv_Invoice $invoice Invoice object.
183 183
 	 *
184 184
 	 */
185
-	public function read( &$invoice ) {
185
+	public function read(&$invoice) {
186 186
 
187 187
 		$invoice->set_defaults();
188
-		$invoice_object = get_post( $invoice->get_id() );
188
+		$invoice_object = get_post($invoice->get_id());
189 189
 
190
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
191
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
192
-			$invoice->set_id( 0 );
190
+		if (!$invoice->get_id() || !$invoice_object || !getpaid_is_invoice_post_type($invoice_object->post_type)) {
191
+			$invoice->last_error = __('Invalid invoice.', 'invoicing');
192
+			$invoice->set_id(0);
193 193
 			return false;
194 194
 		}
195 195
 
@@ -207,14 +207,14 @@  discard block
 block discarded – undo
207 207
 			)
208 208
 		);
209 209
 
210
-		$invoice->set_type( $invoice_object->post_type );
210
+		$invoice->set_type($invoice_object->post_type);
211 211
 
212
-		$this->read_object_data( $invoice, $invoice_object );
213
-		$this->add_special_fields( $invoice );
214
-		$this->add_items( $invoice );
212
+		$this->read_object_data($invoice, $invoice_object);
213
+		$this->add_special_fields($invoice);
214
+		$this->add_items($invoice);
215 215
 		$invoice->read_meta_data();
216
-		$invoice->set_object_read( true );
217
-		do_action( 'getpaid_read_invoice', $invoice );
216
+		$invoice->set_object_read(true);
217
+		do_action('getpaid_read_invoice', $invoice);
218 218
 	}
219 219
 
220 220
 	/**
@@ -222,35 +222,35 @@  discard block
 block discarded – undo
222 222
 	 *
223 223
 	 * @param WPInv_Invoice $invoice Invoice object.
224 224
 	 */
225
-	public function update( &$invoice ) {
225
+	public function update(&$invoice) {
226 226
 		$invoice->save_meta_data();
227
-		$invoice->set_version( WPINV_VERSION );
227
+		$invoice->set_version(WPINV_VERSION);
228 228
 
229
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
230
-			$invoice->set_date_created( current_time( 'mysql' ) );
229
+		if (null === $invoice->get_date_created('edit')) {
230
+			$invoice->set_date_created(current_time('mysql'));
231 231
 		}
232 232
 
233 233
 		// Ensure both the key and number are set.
234 234
 		$invoice->get_path();
235 235
 
236 236
 		// Grab the current status so we can compare.
237
-		$previous_status = get_post_status( $invoice->get_id() );
237
+		$previous_status = get_post_status($invoice->get_id());
238 238
 
239 239
 		$changes = $invoice->get_changes();
240 240
 
241 241
 		// Only update the post when the post data changes.
242
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
242
+		if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path'), array_keys($changes))) {
243 243
 			$post_data = array(
244
-				'post_date'     => $invoice->get_date_created( 'edit' ),
245
-				'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ),
246
-				'post_status'   => $invoice->get_status( 'edit' ),
247
-				'post_title'    => $invoice->get_name( 'edit' ),
248
-				'post_author'   => $invoice->get_user_id( 'edit' ),
249
-				'post_modified' => $invoice->get_date_modified( 'edit' ),
250
-				'post_excerpt'  => $invoice->get_description( 'edit' ),
251
-				'post_parent'   => $invoice->get_parent_id( 'edit' ),
252
-				'post_name'     => $invoice->get_path( 'edit' ),
253
-				'post_type'     => $invoice->get_post_type( 'edit' ),
244
+				'post_date'     => $invoice->get_date_created('edit'),
245
+				'post_date_gmt' => $invoice->get_date_created_gmt('edit'),
246
+				'post_status'   => $invoice->get_status('edit'),
247
+				'post_title'    => $invoice->get_name('edit'),
248
+				'post_author'   => $invoice->get_user_id('edit'),
249
+				'post_modified' => $invoice->get_date_modified('edit'),
250
+				'post_excerpt'  => $invoice->get_description('edit'),
251
+				'post_parent'   => $invoice->get_parent_id('edit'),
252
+				'post_name'     => $invoice->get_path('edit'),
253
+				'post_type'     => $invoice->get_post_type('edit'),
254 254
 			);
255 255
 
256 256
 			/**
@@ -261,35 +261,35 @@  discard block
 block discarded – undo
261 261
 			 * This ensures hooks are fired by either WP itself (admin screen save),
262 262
 			 * or an update purely from CRUD.
263 263
 			 */
264
-			if ( doing_action( 'save_post' ) ) {
265
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
266
-				clean_post_cache( $invoice->get_id() );
264
+			if (doing_action('save_post')) {
265
+				$GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $invoice->get_id()));
266
+				clean_post_cache($invoice->get_id());
267 267
 			} else {
268
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
268
+				wp_update_post(array_merge(array('ID' => $invoice->get_id()), $post_data));
269 269
 			}
270
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
270
+			$invoice->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
271 271
 		}
272 272
 
273 273
 		// Update meta data.
274
-		$this->update_post_meta( $invoice );
274
+		$this->update_post_meta($invoice);
275 275
 
276 276
 		// Save special fields and items.
277
-		$this->save_special_fields( $invoice );
278
-		$this->save_items( $invoice );
277
+		$this->save_special_fields($invoice);
278
+		$this->save_items($invoice);
279 279
 
280 280
 		// Apply the changes.
281 281
 		$invoice->apply_changes();
282 282
 
283 283
 		// Clear caches.
284
-		$this->clear_caches( $invoice );
284
+		$this->clear_caches($invoice);
285 285
 
286 286
 		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
287
-		$new_status = $invoice->get_status( 'edit' );
287
+		$new_status = $invoice->get_status('edit');
288 288
 
289
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
290
-			do_action( 'getpaid_new_invoice', $invoice );
289
+		if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) {
290
+			do_action('getpaid_new_invoice', $invoice);
291 291
 		} else {
292
-			do_action( 'getpaid_update_invoice', $invoice );
292
+			do_action('getpaid_update_invoice', $invoice);
293 293
 		}
294 294
 	}
295 295
 
@@ -304,45 +304,45 @@  discard block
 block discarded – undo
304 304
 	 *
305 305
 	 * @param WPInv_Invoice $invoice Invoice object.
306 306
      */
307
-    public function add_special_fields( &$invoice ) {
307
+    public function add_special_fields(&$invoice) {
308 308
 		global $wpdb;
309 309
 
310 310
 		// Maybe retrieve from the cache.
311
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
311
+		$data = wp_cache_get($invoice->get_id(), 'getpaid_invoice_special_fields');
312 312
 
313 313
 		// If not found, retrieve from the db.
314
-		if ( false === $data ) {
314
+		if (false === $data) {
315 315
 			$table = $wpdb->prefix . 'getpaid_invoices';
316 316
 
317 317
 			$data  = $wpdb->get_row(
318
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
318
+				$wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id()),
319 319
 				ARRAY_A
320 320
 			);
321 321
 
322 322
 			// Update the cache with our data
323
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
323
+			wp_cache_set($invoice->get_id(), $data, 'getpaid_invoice_special_fields');
324 324
 
325 325
 		}
326 326
 
327 327
 		// Abort if the data does not exist.
328
-		if ( empty( $data ) ) {
329
-			$invoice->set_object_read( true );
330
-			$invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
328
+		if (empty($data)) {
329
+			$invoice->set_object_read(true);
330
+			$invoice->set_props(wpinv_get_user_address($invoice->get_user_id()));
331 331
 			return;
332 332
 		}
333 333
 
334 334
 		$props = array();
335 335
 
336
-		foreach ( $this->database_fields_to_props as $db_field => $prop ) {
336
+		foreach ($this->database_fields_to_props as $db_field => $prop) {
337 337
 
338
-			if ( $db_field == 'post_id' ) {
338
+			if ($db_field == 'post_id') {
339 339
 				continue;
340 340
 			}
341 341
 
342
-			$props[ $prop ] = $data[ $db_field ];
342
+			$props[$prop] = $data[$db_field];
343 343
 		}
344 344
 
345
-		$invoice->set_props( $props );
345
+		$invoice->set_props($props);
346 346
 	}
347 347
 
348 348
 	/**
@@ -352,14 +352,14 @@  discard block
 block discarded – undo
352 352
 	 * @param  WPInv_Invoice $invoice       The Invoice object.
353 353
 	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
354 354
 	 */
355
-	protected function get_special_fields_to_update( $invoice ) {
355
+	protected function get_special_fields_to_update($invoice) {
356 356
 		$fields_to_update = array();
357
-		$changed_props   = $invoice->get_changes();
357
+		$changed_props = $invoice->get_changes();
358 358
 
359 359
 		// Props should be updated if they are a part of the $changed array or don't exist yet.
360
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
361
-			if ( array_key_exists( $prop, $changed_props ) ) {
362
-				$fields_to_update[ $database_field ] = $prop;
360
+		foreach ($this->database_fields_to_props as $database_field => $prop) {
361
+			if (array_key_exists($prop, $changed_props)) {
362
+				$fields_to_update[$database_field] = $prop;
363 363
 			}
364 364
 		}
365 365
 
@@ -372,25 +372,25 @@  discard block
 block discarded – undo
372 372
 	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
373 373
 	 * @since 1.0.19
374 374
 	 */
375
-	protected function update_special_fields( &$invoice ) {
375
+	protected function update_special_fields(&$invoice) {
376 376
 		global $wpdb;
377 377
 
378 378
 		$updated_props    = array();
379
-		$fields_to_update = $this->get_special_fields_to_update( $invoice );
379
+		$fields_to_update = $this->get_special_fields_to_update($invoice);
380 380
 
381
-		foreach ( $fields_to_update as $database_field => $prop ) {
382
-			$value = $invoice->{"get_$prop"}( 'edit' );
383
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
384
-			$value = is_bool( $value ) ? (int) $value : $value;
385
-			$updated_props[ $database_field ] = maybe_serialize( $value );
381
+		foreach ($fields_to_update as $database_field => $prop) {
382
+			$value = $invoice->{"get_$prop"}('edit');
383
+			$value = is_string($value) ? wp_slash($value) : $value;
384
+			$value = is_bool($value) ? (int) $value : $value;
385
+			$updated_props[$database_field] = maybe_serialize($value);
386 386
 		}
387 387
 
388
-		if ( ! empty( $updated_props ) ) {
388
+		if (!empty($updated_props)) {
389 389
 
390 390
 			$table = $wpdb->prefix . 'getpaid_invoices';
391
-			$wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
392
-			wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
393
-			do_action( 'getpaid_invoice_update_database_fields', $invoice, $updated_props );
391
+			$wpdb->update($table, $updated_props, array('post_id' => $invoice->get_id()));
392
+			wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields');
393
+			do_action('getpaid_invoice_update_database_fields', $invoice, $updated_props);
394 394
 
395 395
 		}
396 396
 	}
@@ -401,22 +401,22 @@  discard block
 block discarded – undo
401 401
 	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
402 402
 	 * @since 1.0.19
403 403
 	 */
404
-	protected function insert_special_fields( &$invoice ) {
404
+	protected function insert_special_fields(&$invoice) {
405 405
 		global $wpdb;
406 406
 
407
-		$updated_props   = array();
407
+		$updated_props = array();
408 408
 
409
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
410
-			$value = $invoice->{"get_$prop"}( 'edit' );
411
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
412
-			$value = is_bool( $value ) ? (int) $value : $value;
413
-			$updated_props[ $database_field ] = maybe_serialize( $value );
409
+		foreach ($this->database_fields_to_props as $database_field => $prop) {
410
+			$value = $invoice->{"get_$prop"}('edit');
411
+			$value = is_string($value) ? wp_slash($value) : $value;
412
+			$value = is_bool($value) ? (int) $value : $value;
413
+			$updated_props[$database_field] = maybe_serialize($value);
414 414
 		}
415 415
 
416 416
 		$table = $wpdb->prefix . 'getpaid_invoices';
417
-		$wpdb->insert( $table, $updated_props );
418
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
419
-		do_action( 'getpaid_invoice_insert_database_fields', $invoice, $updated_props );
417
+		$wpdb->insert($table, $updated_props);
418
+		wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields');
419
+		do_action('getpaid_invoice_insert_database_fields', $invoice, $updated_props);
420 420
 	}
421 421
 
422 422
 	/**
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
 	 *
425 425
 	 * @param WPInv_Invoice $invoice Invoice object.
426 426
      */
427
-    public function save_special_fields( &$invoice ) {
427
+    public function save_special_fields(&$invoice) {
428 428
 		global $wpdb;
429 429
 
430 430
 		// The invoices table.
@@ -432,13 +432,13 @@  discard block
 block discarded – undo
432 432
 		$id    = (int) $invoice->get_id();
433 433
 		$invoice->maybe_set_key();
434 434
 
435
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
435
+		if ($wpdb->get_var("SELECT `post_id` FROM $table WHERE `post_id`= $id")) {
436 436
 
437
-			$this->update_special_fields( $invoice );
437
+			$this->update_special_fields($invoice);
438 438
 
439 439
 		} else {
440 440
 
441
-			$this->insert_special_fields( $invoice );
441
+			$this->insert_special_fields($invoice);
442 442
 
443 443
 		}
444 444
 	}
@@ -448,71 +448,71 @@  discard block
 block discarded – undo
448 448
 	 *
449 449
 	 * @param WPInv_Invoice $invoice Invoice object.
450 450
      */
451
-    public function add_items( &$invoice ) {
451
+    public function add_items(&$invoice) {
452 452
 		global $wpdb;
453 453
 
454 454
 		// Maybe retrieve from the cache.
455
-		$items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
455
+		$items = wp_cache_get($invoice->get_id(), 'getpaid_invoice_cart_details');
456 456
 
457 457
 		// If not found, retrieve from the db.
458
-		if ( false === $items ) {
458
+		if (false === $items) {
459 459
 			$table = $wpdb->prefix . 'getpaid_invoice_items';
460 460
 
461 461
 			$items = $wpdb->get_results(
462
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
462
+				$wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id())
463 463
 			);
464 464
 
465 465
 			// Update the cache with our data
466
-			wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
466
+			wp_cache_set($invoice->get_id(), $items, 'getpaid_invoice_cart_details');
467 467
 
468 468
 		}
469 469
 
470 470
 		// Abort if no items found.
471
-        if ( empty( $items ) ) {
471
+        if (empty($items)) {
472 472
             return;
473 473
 		}
474 474
 
475 475
 		$_items = array();
476
-		foreach ( $items as $item_data ) {
477
-			$item = new GetPaid_Form_Item( $item_data->item_id );
476
+		foreach ($items as $item_data) {
477
+			$item = new GetPaid_Form_Item($item_data->item_id);
478 478
 
479 479
 			// Set item data.
480
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
481
-			$item->item_discount = wpinv_sanitize_amount( $item_data->discount );
482
-			$item->set_name( $item_data->item_name );
483
-			$item->set_description( $item_data->item_description );
484
-            $item->set_price( $item_data->item_price );
485
-			$item->set_quantity( $item_data->quantity );
486
-			$item->set_price_id( $item_data->price_id );
487
-			$item->set_item_meta( $item_data->meta );
488
-
489
-            if ( $item->has_variable_pricing() ) {
480
+			$item->item_tax      = wpinv_sanitize_amount($item_data->tax);
481
+			$item->item_discount = wpinv_sanitize_amount($item_data->discount);
482
+			$item->set_name($item_data->item_name);
483
+			$item->set_description($item_data->item_description);
484
+            $item->set_price($item_data->item_price);
485
+			$item->set_quantity($item_data->quantity);
486
+			$item->set_price_id($item_data->price_id);
487
+			$item->set_item_meta($item_data->meta);
488
+
489
+            if ($item->has_variable_pricing()) {
490 490
                 $price_options = $item->get_variable_prices();
491 491
 
492
-                if ( ! empty( $price_options ) && isset( $price_options[ $item_data->price_id ] ) ) {
493
-                    $price = $price_options[ $item_data->price_id ];
492
+                if (!empty($price_options) && isset($price_options[$item_data->price_id])) {
493
+                    $price = $price_options[$item_data->price_id];
494 494
 
495
-                    $item->set_price( (float) $price['amount'] );
495
+                    $item->set_price((float) $price['amount']);
496 496
 
497
-                    if ( isset( $price['is-recurring'] ) && 'yes' === $price['is-recurring'] ) {
498
-                        if ( isset( $price['trial-interval'], $price['trial-period'] ) && $price['trial-interval'] > 0 ) {
497
+                    if (isset($price['is-recurring']) && 'yes' === $price['is-recurring']) {
498
+                        if (isset($price['trial-interval'], $price['trial-period']) && $price['trial-interval'] > 0) {
499 499
                             $trial_interval = (int) $price['trial-interval'];
500 500
                             $trial_period = $price['trial-period'];
501 501
 
502
-                            $item->set_is_free_trial( 1 );
503
-                            $item->set_trial_interval( $trial_interval );
504
-                            $item->set_trial_period( $trial_period );
502
+                            $item->set_is_free_trial(1);
503
+                            $item->set_trial_interval($trial_interval);
504
+                            $item->set_trial_period($trial_period);
505 505
                         }
506 506
 
507
-                        if ( isset( $price['recurring-interval'], $price['recurring-period'] ) && $price['recurring-interval'] > 0 ) {
507
+                        if (isset($price['recurring-interval'], $price['recurring-period']) && $price['recurring-interval'] > 0) {
508 508
                             $recurring_interval = (int) $price['recurring-interval'];
509 509
                             $recurring_period = $price['recurring-period'];
510
-                            $recurring_limit = isset( $price['recurring-limit'] ) ? (int) $price['recurring-limit'] : 0;
510
+                            $recurring_limit = isset($price['recurring-limit']) ? (int) $price['recurring-limit'] : 0;
511 511
 
512
-                            $item->set_is_recurring( 1 );
513
-                            $item->set_recurring_interval( $recurring_interval );
514
-                            $item->set_recurring_period( $recurring_period );
515
-                            $item->set_recurring_limit( $recurring_limit );
512
+                            $item->set_is_recurring(1);
513
+                            $item->set_recurring_interval($recurring_interval);
514
+                            $item->set_recurring_period($recurring_period);
515
+                            $item->set_recurring_limit($recurring_limit);
516 516
                         }
517 517
                     }
518 518
                 }
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 			$_items[] = $item;
522 522
 		}
523 523
 
524
-		$invoice->set_items( $_items );
524
+		$invoice->set_items($_items);
525 525
 	}
526 526
 
527 527
 	/**
@@ -529,20 +529,20 @@  discard block
 block discarded – undo
529 529
 	 *
530 530
 	 * @param WPInv_Invoice $invoice Invoice object.
531 531
      */
532
-    public function save_items( $invoice ) {
532
+    public function save_items($invoice) {
533 533
 
534 534
 		// Delete previously existing items.
535
-		$this->delete_items( $invoice );
535
+		$this->delete_items($invoice);
536 536
 
537
-		$table   = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
537
+		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
538 538
 
539
-		foreach ( $invoice->get_cart_details() as $item_data ) {
540
-			$item_data = array_map( 'maybe_serialize', $item_data );
541
-			$GLOBALS['wpdb']->insert( $table, $item_data );
539
+		foreach ($invoice->get_cart_details() as $item_data) {
540
+			$item_data = array_map('maybe_serialize', $item_data);
541
+			$GLOBALS['wpdb']->insert($table, $item_data);
542 542
 		}
543 543
 
544
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
545
-		do_action( 'getpaid_invoice_save_items', $invoice );
544
+		wp_cache_delete($invoice->get_id(), 'getpaid_invoice_cart_details');
545
+		do_action('getpaid_invoice_save_items', $invoice);
546 546
 	}
547 547
 
548 548
 	/**
@@ -550,9 +550,9 @@  discard block
 block discarded – undo
550 550
 	 *
551 551
 	 * @param WPInv_Invoice $invoice Invoice object.
552 552
      */
553
-    public function delete_items( $invoice ) {
553
+    public function delete_items($invoice) {
554 554
 		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
555
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
555
+		return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id()));
556 556
 	}
557 557
 
558 558
 	/**
@@ -560,9 +560,9 @@  discard block
 block discarded – undo
560 560
 	 *
561 561
 	 * @param WPInv_Invoice $invoice Invoice object.
562 562
      */
563
-    public function delete_special_fields( $invoice ) {
563
+    public function delete_special_fields($invoice) {
564 564
 		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
565
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
565
+		return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id()));
566 566
 	}
567 567
 
568 568
 	/**
@@ -573,10 +573,10 @@  discard block
 block discarded – undo
573 573
 	 * @param  WPInv_Invoice $object GetPaid_Data object.
574 574
 	 * @return string
575 575
 	 */
576
-	protected function get_post_status( $object ) {
577
-		$object_status = $object->get_status( 'edit' );
576
+	protected function get_post_status($object) {
577
+		$object_status = $object->get_status('edit');
578 578
 
579
-		if ( ! $object_status ) {
579
+		if (!$object_status) {
580 580
 			$object_status = $object->get_default_status();
581 581
 		}
582 582
 
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-item-data-store.php 2 patches
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 if ( ! defined( 'ABSPATH' ) ) {
7
-	exit;
7
+    exit;
8 8
 }
9 9
 
10 10
 /**
@@ -14,232 +14,232 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class GetPaid_Item_Data_Store extends GetPaid_Data_Store_WP {
16 16
 
17
-	/**
18
-	 * Data stored in meta keys, but not considered "meta" for an item.
19
-	 *
20
-	 * @since 1.0.19
21
-	 * @var array
22
-	 */
23
-	protected $internal_meta_keys = array(
24
-		'_wpinv_price',
25
-		'_wpinv_vat_rule',
26
-		'_wpinv_vat_class',
27
-		'_wpinv_type',
28
-		'_wpinv_custom_id',
29
-		'_wpinv_custom_name',
30
-		'_wpinv_custom_singular_name',
31
-		'_wpinv_editable',
32
-		'_wpinv_dynamic_pricing',
33
-		'_minimum_price',
34
-		'_wpinv_is_multi_price_mode',
35
-		'_wpinv_has_variable_pricing',
17
+    /**
18
+     * Data stored in meta keys, but not considered "meta" for an item.
19
+     *
20
+     * @since 1.0.19
21
+     * @var array
22
+     */
23
+    protected $internal_meta_keys = array(
24
+        '_wpinv_price',
25
+        '_wpinv_vat_rule',
26
+        '_wpinv_vat_class',
27
+        '_wpinv_type',
28
+        '_wpinv_custom_id',
29
+        '_wpinv_custom_name',
30
+        '_wpinv_custom_singular_name',
31
+        '_wpinv_editable',
32
+        '_wpinv_dynamic_pricing',
33
+        '_minimum_price',
34
+        '_wpinv_is_multi_price_mode',
35
+        '_wpinv_has_variable_pricing',
36 36
         '_wpinv_default_price_id',
37 37
         '_wpinv_variable_prices',
38
-		'_wpinv_is_recurring',
39
-		'_wpinv_recurring_period',
40
-		'_wpinv_recurring_interval',
41
-		'_wpinv_recurring_limit',
42
-		'_wpinv_free_trial',
43
-		'_wpinv_trial_period',
44
-		'_wpinv_trial_interval',
45
-	);
46
-
47
-	/**
48
-	 * A map of meta keys to data props.
49
-	 *
50
-	 * @since 1.0.19
51
-	 *
52
-	 * @var array
53
-	 */
54
-	protected $meta_key_to_props = array(
55
-		'_wpinv_price'                => 'price',
56
-		'_wpinv_vat_rule'             => 'vat_rule',
57
-		'_wpinv_vat_class'            => 'vat_class',
58
-		'_wpinv_type'                 => 'type',
59
-		'_wpinv_custom_id'            => 'custom_id',
60
-		'_wpinv_custom_name'          => 'custom_name',
61
-		'_wpinv_custom_singular_name' => 'custom_singular_name',
62
-		'_wpinv_editable'             => 'is_editable',
63
-		'_wpinv_dynamic_pricing'      => 'is_dynamic_pricing',
64
-		'_minimum_price'              => 'minimum_price',
65
-		'_wpinv_is_multi_price_mode'  => 'is_multi_price_mode',
66
-		'_wpinv_has_variable_pricing' => 'has_variable_pricing',
38
+        '_wpinv_is_recurring',
39
+        '_wpinv_recurring_period',
40
+        '_wpinv_recurring_interval',
41
+        '_wpinv_recurring_limit',
42
+        '_wpinv_free_trial',
43
+        '_wpinv_trial_period',
44
+        '_wpinv_trial_interval',
45
+    );
46
+
47
+    /**
48
+     * A map of meta keys to data props.
49
+     *
50
+     * @since 1.0.19
51
+     *
52
+     * @var array
53
+     */
54
+    protected $meta_key_to_props = array(
55
+        '_wpinv_price'                => 'price',
56
+        '_wpinv_vat_rule'             => 'vat_rule',
57
+        '_wpinv_vat_class'            => 'vat_class',
58
+        '_wpinv_type'                 => 'type',
59
+        '_wpinv_custom_id'            => 'custom_id',
60
+        '_wpinv_custom_name'          => 'custom_name',
61
+        '_wpinv_custom_singular_name' => 'custom_singular_name',
62
+        '_wpinv_editable'             => 'is_editable',
63
+        '_wpinv_dynamic_pricing'      => 'is_dynamic_pricing',
64
+        '_minimum_price'              => 'minimum_price',
65
+        '_wpinv_is_multi_price_mode'  => 'is_multi_price_mode',
66
+        '_wpinv_has_variable_pricing' => 'has_variable_pricing',
67 67
         '_wpinv_default_price_id'     => 'default_price_id',
68 68
         '_wpinv_variable_prices'      => 'variable_prices',
69
-		'_wpinv_is_recurring'         => 'is_recurring',
70
-		'_wpinv_recurring_period'     => 'recurring_period',
71
-		'_wpinv_recurring_interval'   => 'recurring_interval',
72
-		'_wpinv_recurring_limit'      => 'recurring_limit',
73
-		'_wpinv_free_trial'           => 'is_free_trial',
74
-		'_wpinv_trial_period'         => 'trial_period',
75
-		'_wpinv_trial_interval'       => 'trial_interval',
76
-		'_wpinv_version'              => 'version',
77
-	);
78
-
79
-	/*
69
+        '_wpinv_is_recurring'         => 'is_recurring',
70
+        '_wpinv_recurring_period'     => 'recurring_period',
71
+        '_wpinv_recurring_interval'   => 'recurring_interval',
72
+        '_wpinv_recurring_limit'      => 'recurring_limit',
73
+        '_wpinv_free_trial'           => 'is_free_trial',
74
+        '_wpinv_trial_period'         => 'trial_period',
75
+        '_wpinv_trial_interval'       => 'trial_interval',
76
+        '_wpinv_version'              => 'version',
77
+    );
78
+
79
+    /*
80 80
 	|--------------------------------------------------------------------------
81 81
 	| CRUD Methods
82 82
 	|--------------------------------------------------------------------------
83 83
 	*/
84 84
 
85
-	/**
86
-	 * Method to create a new item in the database.
87
-	 *
88
-	 * @param WPInv_Item $item Item object.
89
-	 */
90
-	public function create( &$item ) {
91
-		$item->set_version( WPINV_VERSION );
92
-		$item->set_date_created( current_time( 'mysql' ) );
93
-
94
-		// Create a new post.
95
-		$id = wp_insert_post(
96
-			apply_filters(
97
-				'getpaid_new_item_data',
98
-				array(
99
-					'post_date'    => $item->get_date_created( 'edit' ),
100
-					'post_type'    => 'wpi_item',
101
-					'post_status'  => $this->get_post_status( $item ),
102
-					'ping_status'  => 'closed',
103
-					'post_author'  => $item->get_author( 'edit' ),
104
-					'post_title'   => $item->get_name( 'edit' ),
105
-					'post_parent'  => $item->get_parent_id(),
106
-					'post_excerpt' => $item->get_description( 'edit' ),
107
-				)
108
-			),
109
-			true
110
-		);
111
-
112
-		if ( $id && ! is_wp_error( $id ) ) {
113
-			$item->set_id( $id );
114
-			$this->update_post_meta( $item );
115
-			$item->save_meta_data();
116
-			$item->apply_changes();
117
-			$this->clear_caches( $item );
118
-			do_action( 'getpaid_new_item', $item );
119
-			return true;
120
-		}
121
-
122
-		if ( is_wp_error( $id ) ) {
123
-			$item->last_error = $id->get_error_message();
124
-		}
125
-
126
-		return false;
127
-	}
128
-
129
-	/**
130
-	 * Method to read an item from the database.
131
-	 *
132
-	 * @param WPInv_Item $item Item object.
133
-	 *
134
-	 */
135
-	public function read( &$item ) {
136
-
137
-		$item->set_defaults();
138
-		$item_object = get_post( $item->get_id() );
139
-
140
-		if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) {
141
-			$item->last_error = __( 'Invalid item.', 'invoicing' );
142
-			$item->set_id( 0 );
143
-			return false;
144
-		}
145
-
146
-		$item->set_props(
147
-			array(
148
-				'parent_id'     => $item_object->post_parent,
149
-				'date_created'  => 0 < $item_object->post_date ? $item_object->post_date : null,
150
-				'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null,
151
-				'status'        => $item_object->post_status,
152
-				'name'          => $item_object->post_title,
153
-				'description'   => $item_object->post_excerpt,
154
-				'author'        => $item_object->post_author,
155
-			)
156
-		);
157
-
158
-		$this->read_object_data( $item, $item_object );
159
-		$item->read_meta_data();
160
-		$item->set_object_read( true );
161
-		do_action( 'getpaid_read_item', $item );
162
-	}
163
-
164
-	/**
165
-	 * Method to update an item in the database.
166
-	 *
167
-	 * @param WPInv_Item $item Item object.
168
-	 */
169
-	public function update( &$item ) {
170
-		$item->save_meta_data();
171
-		$item->set_version( WPINV_VERSION );
172
-
173
-		if ( null === $item->get_date_created( 'edit' ) ) {
174
-			$item->set_date_created( current_time( 'mysql' ) );
175
-		}
176
-
177
-		// Grab the current status so we can compare.
178
-		$previous_status = get_post_status( $item->get_id() );
179
-
180
-		$changes = $item->get_changes();
181
-
182
-		// Only update the post when the post data changes.
183
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author' ), array_keys( $changes ) ) ) {
184
-			$post_data = array(
185
-				'post_date'     => $item->get_date_created( 'edit' ),
186
-				'post_status'   => $item->get_status( 'edit' ),
187
-				'post_parent'   => $item->get_parent_id( 'edit' ),
188
-				'post_excerpt'  => $item->get_description( 'edit' ),
189
-				'post_modified' => $item->get_date_modified( 'edit' ),
190
-				'post_title'    => $item->get_name( 'edit' ),
191
-				'post_author'   => $item->get_author( 'edit' ),
192
-			);
193
-
194
-			/**
195
-			 * When updating this object, to prevent infinite loops, use $wpdb
196
-			 * to update data, since wp_update_post spawns more calls to the
197
-			 * save_post action.
198
-			 *
199
-			 * This ensures hooks are fired by either WP itself (admin screen save),
200
-			 * or an update purely from CRUD.
201
-			 */
202
-			if ( doing_action( 'save_post' ) ) {
203
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
204
-				clean_post_cache( $item->get_id() );
205
-			} else {
206
-				wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
207
-			}
208
-			$item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
209
-		}
210
-		$this->update_post_meta( $item );
211
-		$item->apply_changes();
212
-		$this->clear_caches( $item );
213
-
214
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
215
-		$new_status = $item->get_status( 'edit' );
216
-
217
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
218
-			do_action( 'getpaid_new_item', $item );
219
-		} else {
220
-			do_action( 'getpaid_update_item', $item );
221
-		}
222
-	}
223
-
224
-	/*
85
+    /**
86
+     * Method to create a new item in the database.
87
+     *
88
+     * @param WPInv_Item $item Item object.
89
+     */
90
+    public function create( &$item ) {
91
+        $item->set_version( WPINV_VERSION );
92
+        $item->set_date_created( current_time( 'mysql' ) );
93
+
94
+        // Create a new post.
95
+        $id = wp_insert_post(
96
+            apply_filters(
97
+                'getpaid_new_item_data',
98
+                array(
99
+                    'post_date'    => $item->get_date_created( 'edit' ),
100
+                    'post_type'    => 'wpi_item',
101
+                    'post_status'  => $this->get_post_status( $item ),
102
+                    'ping_status'  => 'closed',
103
+                    'post_author'  => $item->get_author( 'edit' ),
104
+                    'post_title'   => $item->get_name( 'edit' ),
105
+                    'post_parent'  => $item->get_parent_id(),
106
+                    'post_excerpt' => $item->get_description( 'edit' ),
107
+                )
108
+            ),
109
+            true
110
+        );
111
+
112
+        if ( $id && ! is_wp_error( $id ) ) {
113
+            $item->set_id( $id );
114
+            $this->update_post_meta( $item );
115
+            $item->save_meta_data();
116
+            $item->apply_changes();
117
+            $this->clear_caches( $item );
118
+            do_action( 'getpaid_new_item', $item );
119
+            return true;
120
+        }
121
+
122
+        if ( is_wp_error( $id ) ) {
123
+            $item->last_error = $id->get_error_message();
124
+        }
125
+
126
+        return false;
127
+    }
128
+
129
+    /**
130
+     * Method to read an item from the database.
131
+     *
132
+     * @param WPInv_Item $item Item object.
133
+     *
134
+     */
135
+    public function read( &$item ) {
136
+
137
+        $item->set_defaults();
138
+        $item_object = get_post( $item->get_id() );
139
+
140
+        if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) {
141
+            $item->last_error = __( 'Invalid item.', 'invoicing' );
142
+            $item->set_id( 0 );
143
+            return false;
144
+        }
145
+
146
+        $item->set_props(
147
+            array(
148
+                'parent_id'     => $item_object->post_parent,
149
+                'date_created'  => 0 < $item_object->post_date ? $item_object->post_date : null,
150
+                'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null,
151
+                'status'        => $item_object->post_status,
152
+                'name'          => $item_object->post_title,
153
+                'description'   => $item_object->post_excerpt,
154
+                'author'        => $item_object->post_author,
155
+            )
156
+        );
157
+
158
+        $this->read_object_data( $item, $item_object );
159
+        $item->read_meta_data();
160
+        $item->set_object_read( true );
161
+        do_action( 'getpaid_read_item', $item );
162
+    }
163
+
164
+    /**
165
+     * Method to update an item in the database.
166
+     *
167
+     * @param WPInv_Item $item Item object.
168
+     */
169
+    public function update( &$item ) {
170
+        $item->save_meta_data();
171
+        $item->set_version( WPINV_VERSION );
172
+
173
+        if ( null === $item->get_date_created( 'edit' ) ) {
174
+            $item->set_date_created( current_time( 'mysql' ) );
175
+        }
176
+
177
+        // Grab the current status so we can compare.
178
+        $previous_status = get_post_status( $item->get_id() );
179
+
180
+        $changes = $item->get_changes();
181
+
182
+        // Only update the post when the post data changes.
183
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author' ), array_keys( $changes ) ) ) {
184
+            $post_data = array(
185
+                'post_date'     => $item->get_date_created( 'edit' ),
186
+                'post_status'   => $item->get_status( 'edit' ),
187
+                'post_parent'   => $item->get_parent_id( 'edit' ),
188
+                'post_excerpt'  => $item->get_description( 'edit' ),
189
+                'post_modified' => $item->get_date_modified( 'edit' ),
190
+                'post_title'    => $item->get_name( 'edit' ),
191
+                'post_author'   => $item->get_author( 'edit' ),
192
+            );
193
+
194
+            /**
195
+             * When updating this object, to prevent infinite loops, use $wpdb
196
+             * to update data, since wp_update_post spawns more calls to the
197
+             * save_post action.
198
+             *
199
+             * This ensures hooks are fired by either WP itself (admin screen save),
200
+             * or an update purely from CRUD.
201
+             */
202
+            if ( doing_action( 'save_post' ) ) {
203
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
204
+                clean_post_cache( $item->get_id() );
205
+            } else {
206
+                wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
207
+            }
208
+            $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
209
+        }
210
+        $this->update_post_meta( $item );
211
+        $item->apply_changes();
212
+        $this->clear_caches( $item );
213
+
214
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
215
+        $new_status = $item->get_status( 'edit' );
216
+
217
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
218
+            do_action( 'getpaid_new_item', $item );
219
+        } else {
220
+            do_action( 'getpaid_update_item', $item );
221
+        }
222
+    }
223
+
224
+    /*
225 225
 	|--------------------------------------------------------------------------
226 226
 	| Additional Methods
227 227
 	|--------------------------------------------------------------------------
228 228
 	*/
229 229
 
230
-	/**
231
-	 * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class.
232
-	 *
233
-	 * @param WPInv_Item $item WPInv_Item object.
234
-	 * @since 1.0.19
235
-	 */
236
-	protected function update_post_meta( &$item ) {
230
+    /**
231
+     * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class.
232
+     *
233
+     * @param WPInv_Item $item WPInv_Item object.
234
+     * @since 1.0.19
235
+     */
236
+    protected function update_post_meta( &$item ) {
237 237
 
238
-		// Ensure that we have a custom id.
238
+        // Ensure that we have a custom id.
239 239
         if ( ! $item->get_custom_id() ) {
240 240
             $item->set_custom_id( $item->get_id() );
241
-		}
241
+        }
242 242
 
243
-		parent::update_post_meta( $item );
244
-	}
243
+        parent::update_post_meta( $item );
244
+    }
245 245
 }
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * GetPaid_Item_Data_Store class file.
4 4
  *
5 5
  */
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
 	exit;
8 8
 }
9 9
 
@@ -87,39 +87,39 @@  discard block
 block discarded – undo
87 87
 	 *
88 88
 	 * @param WPInv_Item $item Item object.
89 89
 	 */
90
-	public function create( &$item ) {
91
-		$item->set_version( WPINV_VERSION );
92
-		$item->set_date_created( current_time( 'mysql' ) );
90
+	public function create(&$item) {
91
+		$item->set_version(WPINV_VERSION);
92
+		$item->set_date_created(current_time('mysql'));
93 93
 
94 94
 		// Create a new post.
95 95
 		$id = wp_insert_post(
96 96
 			apply_filters(
97 97
 				'getpaid_new_item_data',
98 98
 				array(
99
-					'post_date'    => $item->get_date_created( 'edit' ),
99
+					'post_date'    => $item->get_date_created('edit'),
100 100
 					'post_type'    => 'wpi_item',
101
-					'post_status'  => $this->get_post_status( $item ),
101
+					'post_status'  => $this->get_post_status($item),
102 102
 					'ping_status'  => 'closed',
103
-					'post_author'  => $item->get_author( 'edit' ),
104
-					'post_title'   => $item->get_name( 'edit' ),
103
+					'post_author'  => $item->get_author('edit'),
104
+					'post_title'   => $item->get_name('edit'),
105 105
 					'post_parent'  => $item->get_parent_id(),
106
-					'post_excerpt' => $item->get_description( 'edit' ),
106
+					'post_excerpt' => $item->get_description('edit'),
107 107
 				)
108 108
 			),
109 109
 			true
110 110
 		);
111 111
 
112
-		if ( $id && ! is_wp_error( $id ) ) {
113
-			$item->set_id( $id );
114
-			$this->update_post_meta( $item );
112
+		if ($id && !is_wp_error($id)) {
113
+			$item->set_id($id);
114
+			$this->update_post_meta($item);
115 115
 			$item->save_meta_data();
116 116
 			$item->apply_changes();
117
-			$this->clear_caches( $item );
118
-			do_action( 'getpaid_new_item', $item );
117
+			$this->clear_caches($item);
118
+			do_action('getpaid_new_item', $item);
119 119
 			return true;
120 120
 		}
121 121
 
122
-		if ( is_wp_error( $id ) ) {
122
+		if (is_wp_error($id)) {
123 123
 			$item->last_error = $id->get_error_message();
124 124
 		}
125 125
 
@@ -132,14 +132,14 @@  discard block
 block discarded – undo
132 132
 	 * @param WPInv_Item $item Item object.
133 133
 	 *
134 134
 	 */
135
-	public function read( &$item ) {
135
+	public function read(&$item) {
136 136
 
137 137
 		$item->set_defaults();
138
-		$item_object = get_post( $item->get_id() );
138
+		$item_object = get_post($item->get_id());
139 139
 
140
-		if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) {
141
-			$item->last_error = __( 'Invalid item.', 'invoicing' );
142
-			$item->set_id( 0 );
140
+		if (!$item->get_id() || !$item_object || $item_object->post_type != 'wpi_item') {
141
+			$item->last_error = __('Invalid item.', 'invoicing');
142
+			$item->set_id(0);
143 143
 			return false;
144 144
 		}
145 145
 
@@ -155,10 +155,10 @@  discard block
 block discarded – undo
155 155
 			)
156 156
 		);
157 157
 
158
-		$this->read_object_data( $item, $item_object );
158
+		$this->read_object_data($item, $item_object);
159 159
 		$item->read_meta_data();
160
-		$item->set_object_read( true );
161
-		do_action( 'getpaid_read_item', $item );
160
+		$item->set_object_read(true);
161
+		do_action('getpaid_read_item', $item);
162 162
 	}
163 163
 
164 164
 	/**
@@ -166,29 +166,29 @@  discard block
 block discarded – undo
166 166
 	 *
167 167
 	 * @param WPInv_Item $item Item object.
168 168
 	 */
169
-	public function update( &$item ) {
169
+	public function update(&$item) {
170 170
 		$item->save_meta_data();
171
-		$item->set_version( WPINV_VERSION );
171
+		$item->set_version(WPINV_VERSION);
172 172
 
173
-		if ( null === $item->get_date_created( 'edit' ) ) {
174
-			$item->set_date_created( current_time( 'mysql' ) );
173
+		if (null === $item->get_date_created('edit')) {
174
+			$item->set_date_created(current_time('mysql'));
175 175
 		}
176 176
 
177 177
 		// Grab the current status so we can compare.
178
-		$previous_status = get_post_status( $item->get_id() );
178
+		$previous_status = get_post_status($item->get_id());
179 179
 
180 180
 		$changes = $item->get_changes();
181 181
 
182 182
 		// Only update the post when the post data changes.
183
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author' ), array_keys( $changes ) ) ) {
183
+		if (array_intersect(array('date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author'), array_keys($changes))) {
184 184
 			$post_data = array(
185
-				'post_date'     => $item->get_date_created( 'edit' ),
186
-				'post_status'   => $item->get_status( 'edit' ),
187
-				'post_parent'   => $item->get_parent_id( 'edit' ),
188
-				'post_excerpt'  => $item->get_description( 'edit' ),
189
-				'post_modified' => $item->get_date_modified( 'edit' ),
190
-				'post_title'    => $item->get_name( 'edit' ),
191
-				'post_author'   => $item->get_author( 'edit' ),
185
+				'post_date'     => $item->get_date_created('edit'),
186
+				'post_status'   => $item->get_status('edit'),
187
+				'post_parent'   => $item->get_parent_id('edit'),
188
+				'post_excerpt'  => $item->get_description('edit'),
189
+				'post_modified' => $item->get_date_modified('edit'),
190
+				'post_title'    => $item->get_name('edit'),
191
+				'post_author'   => $item->get_author('edit'),
192 192
 			);
193 193
 
194 194
 			/**
@@ -199,25 +199,25 @@  discard block
 block discarded – undo
199 199
 			 * This ensures hooks are fired by either WP itself (admin screen save),
200 200
 			 * or an update purely from CRUD.
201 201
 			 */
202
-			if ( doing_action( 'save_post' ) ) {
203
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
204
-				clean_post_cache( $item->get_id() );
202
+			if (doing_action('save_post')) {
203
+				$GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $item->get_id()));
204
+				clean_post_cache($item->get_id());
205 205
 			} else {
206
-				wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
206
+				wp_update_post(array_merge(array('ID' => $item->get_id()), $post_data));
207 207
 			}
208
-			$item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
208
+			$item->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
209 209
 		}
210
-		$this->update_post_meta( $item );
210
+		$this->update_post_meta($item);
211 211
 		$item->apply_changes();
212
-		$this->clear_caches( $item );
212
+		$this->clear_caches($item);
213 213
 
214 214
 		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
215
-		$new_status = $item->get_status( 'edit' );
215
+		$new_status = $item->get_status('edit');
216 216
 
217
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
218
-			do_action( 'getpaid_new_item', $item );
217
+		if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) {
218
+			do_action('getpaid_new_item', $item);
219 219
 		} else {
220
-			do_action( 'getpaid_update_item', $item );
220
+			do_action('getpaid_update_item', $item);
221 221
 		}
222 222
 	}
223 223
 
@@ -233,13 +233,13 @@  discard block
 block discarded – undo
233 233
 	 * @param WPInv_Item $item WPInv_Item object.
234 234
 	 * @since 1.0.19
235 235
 	 */
236
-	protected function update_post_meta( &$item ) {
236
+	protected function update_post_meta(&$item) {
237 237
 
238 238
 		// Ensure that we have a custom id.
239
-        if ( ! $item->get_custom_id() ) {
240
-            $item->set_custom_id( $item->get_id() );
239
+        if (!$item->get_custom_id()) {
240
+            $item->set_custom_id($item->get_id());
241 241
 		}
242 242
 
243
-		parent::update_post_meta( $item );
243
+		parent::update_post_meta($item);
244 244
 	}
245 245
 }
Please login to merge, or discard this patch.
templates/payment-forms/cart-item.php 3 patches
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -58,48 +58,48 @@  discard block
 block discarded – undo
58 58
 
59 59
 				<?php
60 60
 
61
-					// Fires before printing a line item column.
62
-					do_action( "getpaid_form_cart_item_before_$key", $item, $form );
61
+                    // Fires before printing a line item column.
62
+                    do_action( "getpaid_form_cart_item_before_$key", $item, $form );
63 63
 
64
-					// Item name.
65
-					if ( 'name' === $key ) {
66
-						ob_start();
64
+                    // Item name.
65
+                    if ( 'name' === $key ) {
66
+                        ob_start();
67 67
 
68
-						// Add an optional description.
69
-						$description = $item->get_description();
68
+                        // Add an optional description.
69
+                        $description = $item->get_description();
70 70
 
71
-						if ( ! empty( $description ) ) {
72
-							echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
73
-						}
71
+                        if ( ! empty( $description ) ) {
72
+                            echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
73
+                        }
74 74
 
75
-						// Price help text.
76
-						$description = getpaid_item_recurring_price_help_text( $helper_item, $currency );
77
-						if ( $description ) {
78
-							echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
79
-						}
75
+                        // Price help text.
76
+                        $description = getpaid_item_recurring_price_help_text( $helper_item, $currency );
77
+                        if ( $description ) {
78
+                            echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
79
+                        }
80 80
 
81
-						do_action( 'getpaid_payment_form_cart_item_description', $item, $form );
81
+                        do_action( 'getpaid_payment_form_cart_item_description', $item, $form );
82 82
 
83
-						if ( wpinv_current_user_can_manage_invoicing() ) {
83
+                        if ( wpinv_current_user_can_manage_invoicing() ) {
84 84
 
85
-							edit_post_link(
86
-								__( 'Edit this item.', 'invoicing' ),
87
-								'<small class="form-text text-muted">',
88
-								'</small>',
89
-								$item->get_id(),
90
-								'text-danger'
91
-							);
85
+                            edit_post_link(
86
+                                __( 'Edit this item.', 'invoicing' ),
87
+                                '<small class="form-text text-muted">',
88
+                                '</small>',
89
+                                $item->get_id(),
90
+                                'text-danger'
91
+                            );
92 92
 
93
-						}
93
+                        }
94 94
 
95
-						$description = ob_get_clean();
95
+                        $description = ob_get_clean();
96 96
 
97
-						// Display the name.
98
-						$tootip = empty( $description ) ? '' : '&nbsp;<i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>';
97
+                        // Display the name.
98
+                        $tootip = empty( $description ) ? '' : '&nbsp;<i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>';
99 99
 
100
-						$has_featured_image = has_post_thumbnail( $item->get_id() );
100
+                        $has_featured_image = has_post_thumbnail( $item->get_id() );
101 101
 
102
-						if ( $has_featured_image || $has_variable_pricing ) {
102
+                        if ( $has_featured_image || $has_variable_pricing ) {
103 103
                             echo '<div class="d-flex align-items-center ' . ($has_featured_image ? 'getpaid-form-item-has-featured-image' : '') . '">';
104 104
                             
105 105
                             if ( $has_variable_pricing ) {
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
                                 echo '</div>';
119 119
                             }
120 120
 
121
-							echo '<div class="getpaid-form-item-name-container">';
122
-						}
121
+                            echo '<div class="getpaid-form-item-name-container">';
122
+                        }
123 123
 
124 124
                         if ( $item->has_variable_pricing() ) {
125 125
                             echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() . '&nbsp;&mdash;&nbsp;' . $price['name'] . ($helper_item->is_recurring() ? ' ' . __( '(r)', 'invoicing' ) : '') ) . wp_kses_post( $tootip ) . '</div>';
@@ -127,18 +127,18 @@  discard block
 block discarded – undo
127 127
                             echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() ) . wp_kses_post( $tootip ) . '</div>';
128 128
                         }
129 129
 
130
-						if ( ! empty( $description ) ) {
131
-							printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) );
132
-						}
133
-
134
-						if ( $item->allows_quantities() ) {
135
-							printf(
136
-								'<small class="d-sm-none text-muted form-text">%s</small>',
137
-								sprintf(
138
-									// translators: %s is the item quantity.
139
-									esc_html__( 'Qty %s', 'invoicing' ),
140
-									sprintf(
141
-										'<input
130
+                        if ( ! empty( $description ) ) {
131
+                            printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) );
132
+                        }
133
+
134
+                        if ( $item->allows_quantities() ) {
135
+                            printf(
136
+                                '<small class="d-sm-none text-muted form-text">%s</small>',
137
+                                sprintf(
138
+                                    // translators: %s is the item quantity.
139
+                                    esc_html__( 'Qty %s', 'invoicing' ),
140
+                                    sprintf(
141
+                                        '<input
142 142
 											type="number"
143 143
 											step="0.01"
144 144
 											style="width: 48px;"
@@ -147,30 +147,30 @@  discard block
 block discarded – undo
147 147
 											min="1"
148 148
 											max="%s"
149 149
 										>',
150
-										(float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(),
151
-										floatval( null !== $max_qty ? $max_qty : 1000000000000 )
152
-									)
153
-								)
154
-							);
155
-						} else {
156
-							printf(
157
-								'<small class="d-sm-none text-muted form-text">%s</small>',
158
-								sprintf(
159
-									// translators: %s is the item quantity.
160
-									esc_html__( 'Qty %s', 'invoicing' ),
161
-									(float) $item->get_quantity()
162
-								)
163
-							);
164
-						}
165
-
166
-						if ( $has_featured_image || $has_variable_pricing ) {
167
-							echo '</div>';
168
-							echo '</div>';
169
-						}
170
-					}
171
-
172
-					// Item price.
173
-					if ( 'price' === $key ) {
150
+                                        (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(),
151
+                                        floatval( null !== $max_qty ? $max_qty : 1000000000000 )
152
+                                    )
153
+                                )
154
+                            );
155
+                        } else {
156
+                            printf(
157
+                                '<small class="d-sm-none text-muted form-text">%s</small>',
158
+                                sprintf(
159
+                                    // translators: %s is the item quantity.
160
+                                    esc_html__( 'Qty %s', 'invoicing' ),
161
+                                    (float) $item->get_quantity()
162
+                                )
163
+                            );
164
+                        }
165
+
166
+                        if ( $has_featured_image || $has_variable_pricing ) {
167
+                            echo '</div>';
168
+                            echo '</div>';
169
+                        }
170
+                    }
171
+
172
+                    // Item price.
173
+                    if ( 'price' === $key ) {
174 174
 
175 175
                         // Set the currency position.
176 176
                         $position = wpinv_currency_position();
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 
182 182
                         if ( 'right_space' === $position ) {
183 183
                             $position = 'right';
184
-					    }
184
+                        }
185 185
 
186 186
                         if ( $has_variable_pricing ) { ?>
187 187
                             <span class="getpaid-items-<?php echo (int) $price_id; ?>-view-price">
@@ -258,10 +258,10 @@  discard block
 block discarded – undo
258 258
                             // translators: %s is the item subtotal.
259 259
                             sprintf( esc_html__( 'Subtotal: %s', 'invoicing' ), wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ) )
260 260
                         );
261
-					}
261
+                    }
262 262
 
263
-					// Item quantity.
264
-					if ( 'quantity' === $key ) {
263
+                    // Item quantity.
264
+                    if ( 'quantity' === $key ) {
265 265
 
266 266
                         if ( $item->allows_quantities() ) {
267 267
                             ?>
@@ -275,17 +275,17 @@  discard block
 block discarded – undo
275 275
                         }
276 276
                     }
277 277
 
278
-					// Item sub total.
279
-					if ( 'subtotal' === $key ) {
278
+                    // Item sub total.
279
+                    if ( 'subtotal' === $key ) {
280 280
                         if( $has_variable_pricing ) {
281 281
                             echo wp_kses_post( wpinv_price( $item->get_sub_total( 'view', $price_id ), $currency ) );
282 282
                         } else {
283 283
                             echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) );
284 284
                         }
285
-					}
285
+                    }
286 286
 
287
-					do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
288
-				?>
287
+                    do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
288
+                ?>
289 289
 
290 290
 			</div>
291 291
 
Please login to merge, or discard this patch.
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -216,9 +216,12 @@  discard block
 block discarded – undo
216 216
                                                 <?php echo wp_kses_post( wpinv_currency_symbol( $currency ) ); ?></span>
217 217
                                             </span>
218 218
                                         </div>
219
-                                    <?php else : ?>
219
+                                    <?php else {
220
+    : ?>
220 221
                                         <span class="input-group-text">
221
-                                            <?php echo wp_kses_post( wpinv_currency_symbol( $currency ) ); ?></span>
222
+                                            <?php echo wp_kses_post( wpinv_currency_symbol( $currency ) );
223
+}
224
+?></span>
222 225
                                         </span>
223 226
                                     <?php endif; ?>
224 227
                                 <?php endif; ?>
@@ -238,9 +241,12 @@  discard block
 block discarded – undo
238 241
                                                 <?php echo wp_kses_post( wpinv_currency_symbol( $currency ) ); ?></span>
239 242
                                             </span>
240 243
                                         </div>
241
-                                    <?php else : ?>
244
+                                    <?php else {
245
+    : ?>
242 246
                                         <span class="input-group-text">
243
-                                            <?php echo wp_kses_post( wpinv_currency_symbol( $currency ) ); ?></span>
247
+                                            <?php echo wp_kses_post( wpinv_currency_symbol( $currency ) );
248
+}
249
+?></span>
244 250
                                         </span>
245 251
                                     <?php endif; ?>
246 252
                                 <?php endif; ?>
Please login to merge, or discard this patch.
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -9,41 +9,41 @@  discard block
 block discarded – undo
9 9
  * @var GetPaid_Form_Item $item
10 10
  */
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14
-do_action( 'getpaid_before_payment_form_cart_item', $form, $item );
14
+do_action('getpaid_before_payment_form_cart_item', $form, $item);
15 15
 
16 16
 $currency = $form->get_currency();
17
-$max_qty  = wpinv_item_max_buyable_quantity( $item->get_id() );
17
+$max_qty  = wpinv_item_max_buyable_quantity($item->get_id());
18 18
 
19 19
 $has_variable_pricing = $item->has_variable_pricing();
20 20
 $price_id = $has_variable_pricing ? $variable_price_id : $item->get_id();
21 21
 
22 22
 // helper item to display subscription text.
23 23
 $helper_item = clone $item;
24
-$helper_item->set_id( 0 );
24
+$helper_item->set_id(0);
25 25
 
26
-if ( $has_variable_pricing && (isset( $price['is-recurring'] ) && 'yes' === $price['is-recurring']) ) {
27
-    $helper_item->set_price( $price['amount'] );
26
+if ($has_variable_pricing && (isset($price['is-recurring']) && 'yes' === $price['is-recurring'])) {
27
+    $helper_item->set_price($price['amount']);
28 28
 
29
-    if ( isset( $price['trial-interval'], $price['trial-period'] ) && $price['trial-interval'] > 0 ) {
29
+    if (isset($price['trial-interval'], $price['trial-period']) && $price['trial-interval'] > 0) {
30 30
         $trial_interval = (int) $price['trial-interval'];
31 31
         $trial_period = $price['trial-period'];
32 32
 
33
-        $helper_item->set_is_free_trial( 1 );
34
-        $helper_item->set_trial_interval( $trial_interval );
35
-        $helper_item->set_trial_period( $trial_period );
33
+        $helper_item->set_is_free_trial(1);
34
+        $helper_item->set_trial_interval($trial_interval);
35
+        $helper_item->set_trial_period($trial_period);
36 36
     }
37 37
 
38
-    if ( isset( $price['recurring-interval'], $price['recurring-period'] ) && $price['recurring-interval'] > 0 ) {
38
+    if (isset($price['recurring-interval'], $price['recurring-period']) && $price['recurring-interval'] > 0) {
39 39
         $recurring_interval = (int) $price['recurring-interval'];
40 40
         $recurring_period = $price['recurring-period'];
41
-        $recurring_limit = isset( $price['recurring-limit'] ) ? (int) $price['recurring-limit'] : 0;
41
+        $recurring_limit = isset($price['recurring-limit']) ? (int) $price['recurring-limit'] : 0;
42 42
 
43
-        $helper_item->set_is_recurring( 1 );
44
-        $helper_item->set_recurring_interval( $recurring_interval );
45
-        $helper_item->set_recurring_period( $recurring_period );
46
-        $helper_item->set_recurring_limit( $recurring_limit );
43
+        $helper_item->set_is_recurring(1);
44
+        $helper_item->set_recurring_interval($recurring_interval);
45
+        $helper_item->set_recurring_period($recurring_period);
46
+        $helper_item->set_recurring_limit($recurring_limit);
47 47
     }
48 48
 } 
49 49
 
@@ -52,38 +52,38 @@  discard block
 block discarded – undo
52 52
 
53 53
 	<div class="form-row row align-items-center needs-validation">
54 54
 
55
-		<?php foreach ( array_keys( $columns ) as $key ) : ?>
55
+		<?php foreach (array_keys($columns) as $key) : ?>
56 56
 
57
-			<div class="<?php echo 'name' === $key ? 'col-6' : 'col'; ?> <?php echo ( in_array( $key, array( 'subtotal', 'quantity', 'tax_rate' ), true ) ) ? 'd-none d-sm-block' : ''; ?> position-relative getpaid-form-cart-item-<?php echo esc_attr( $key ); ?> getpaid-form-cart-item-<?php echo esc_attr( $key ); ?>-<?php echo (int) $price_id; ?>">
57
+			<div class="<?php echo 'name' === $key ? 'col-6' : 'col'; ?> <?php echo (in_array($key, array('subtotal', 'quantity', 'tax_rate'), true)) ? 'd-none d-sm-block' : ''; ?> position-relative getpaid-form-cart-item-<?php echo esc_attr($key); ?> getpaid-form-cart-item-<?php echo esc_attr($key); ?>-<?php echo (int) $price_id; ?>">
58 58
 
59 59
 				<?php
60 60
 
61 61
 					// Fires before printing a line item column.
62
-					do_action( "getpaid_form_cart_item_before_$key", $item, $form );
62
+					do_action("getpaid_form_cart_item_before_$key", $item, $form);
63 63
 
64 64
 					// Item name.
65
-					if ( 'name' === $key ) {
65
+					if ('name' === $key) {
66 66
 						ob_start();
67 67
 
68 68
 						// Add an optional description.
69 69
 						$description = $item->get_description();
70 70
 
71
-						if ( ! empty( $description ) ) {
72
-							echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
71
+						if (!empty($description)) {
72
+							echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post($description) . '</small>';
73 73
 						}
74 74
 
75 75
 						// Price help text.
76
-						$description = getpaid_item_recurring_price_help_text( $helper_item, $currency );
77
-						if ( $description ) {
78
-							echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
76
+						$description = getpaid_item_recurring_price_help_text($helper_item, $currency);
77
+						if ($description) {
78
+							echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post($description) . '</small>';
79 79
 						}
80 80
 
81
-						do_action( 'getpaid_payment_form_cart_item_description', $item, $form );
81
+						do_action('getpaid_payment_form_cart_item_description', $item, $form);
82 82
 
83
-						if ( wpinv_current_user_can_manage_invoicing() ) {
83
+						if (wpinv_current_user_can_manage_invoicing()) {
84 84
 
85 85
 							edit_post_link(
86
-								__( 'Edit this item.', 'invoicing' ),
86
+								__('Edit this item.', 'invoicing'),
87 87
 								'<small class="form-text text-muted">',
88 88
 								'</small>',
89 89
 								$item->get_id(),
@@ -95,48 +95,48 @@  discard block
 block discarded – undo
95 95
 						$description = ob_get_clean();
96 96
 
97 97
 						// Display the name.
98
-						$tootip = empty( $description ) ? '' : '&nbsp;<i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>';
98
+						$tootip = empty($description) ? '' : '&nbsp;<i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>';
99 99
 
100
-						$has_featured_image = has_post_thumbnail( $item->get_id() );
100
+						$has_featured_image = has_post_thumbnail($item->get_id());
101 101
 
102
-						if ( $has_featured_image || $has_variable_pricing ) {
102
+						if ($has_featured_image || $has_variable_pricing) {
103 103
                             echo '<div class="d-flex align-items-center ' . ($has_featured_image ? 'getpaid-form-item-has-featured-image' : '') . '">';
104 104
                             
105
-                            if ( $has_variable_pricing ) {
106
-                                echo '<input type="hidden" value="' . esc_attr( $price_id ) . '" name="getpaid-items[' . (int) $price_id . '][price_id]">';
107
-                                echo '<input type="hidden" value="' . esc_attr( $item->get_id() ) . '" name="getpaid-items[' . (int) $price_id . '][item_id]">';
105
+                            if ($has_variable_pricing) {
106
+                                echo '<input type="hidden" value="' . esc_attr($price_id) . '" name="getpaid-items[' . (int) $price_id . '][price_id]">';
107
+                                echo '<input type="hidden" value="' . esc_attr($item->get_id()) . '" name="getpaid-items[' . (int) $price_id . '][item_id]">';
108 108
                                 echo '<div class="mr-2">';
109 109
                                 echo '<label class="form-label d-block w-100">';
110
-                                echo '<input class="getpaid-refresh-on-change" type="' . (true === $item->is_multi_price_mode() ? 'checkbox' : 'radio') . '" value="' . esc_attr( $price_id ) . '" name="getpaid-variable-items[]" ' . ( $item->get_default_price_id() === (int) $price_id ? 'checked' : '') . '>';
110
+                                echo '<input class="getpaid-refresh-on-change" type="' . (true === $item->is_multi_price_mode() ? 'checkbox' : 'radio') . '" value="' . esc_attr($price_id) . '" name="getpaid-variable-items[]" ' . ($item->get_default_price_id() === (int) $price_id ? 'checked' : '') . '>';
111 111
                                 echo '</label>';
112 112
                                 echo '</div>';
113 113
                             }
114 114
 
115
-                            if ( $has_featured_image ) {
115
+                            if ($has_featured_image) {
116 116
                                 echo '<div class="getpaid-form-item-image-container mr-2" style="width:85px;">';
117
-                                echo get_the_post_thumbnail( $item->get_id(), 'thumbnail', array( 'class' => 'getpaid-form-item-image mb-0' ) );
117
+                                echo get_the_post_thumbnail($item->get_id(), 'thumbnail', array('class' => 'getpaid-form-item-image mb-0'));
118 118
                                 echo '</div>';
119 119
                             }
120 120
 
121 121
 							echo '<div class="getpaid-form-item-name-container">';
122 122
 						}
123 123
 
124
-                        if ( $item->has_variable_pricing() ) {
125
-                            echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() . '&nbsp;&mdash;&nbsp;' . $price['name'] . ($helper_item->is_recurring() ? ' ' . __( '(r)', 'invoicing' ) : '') ) . wp_kses_post( $tootip ) . '</div>';
124
+                        if ($item->has_variable_pricing()) {
125
+                            echo '<div class="mb-1 font-weight-bold">' . esc_html($item->get_name() . '&nbsp;&mdash;&nbsp;' . $price['name'] . ($helper_item->is_recurring() ? ' ' . __('(r)', 'invoicing') : '')) . wp_kses_post($tootip) . '</div>';
126 126
                         } else {
127
-                            echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() ) . wp_kses_post( $tootip ) . '</div>';
127
+                            echo '<div class="mb-1 font-weight-bold">' . esc_html($item->get_name()) . wp_kses_post($tootip) . '</div>';
128 128
                         }
129 129
 
130
-						if ( ! empty( $description ) ) {
131
-							printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) );
130
+						if (!empty($description)) {
131
+							printf('<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post($description));
132 132
 						}
133 133
 
134
-						if ( $item->allows_quantities() ) {
134
+						if ($item->allows_quantities()) {
135 135
 							printf(
136 136
 								'<small class="d-sm-none text-muted form-text">%s</small>',
137 137
 								sprintf(
138 138
 									// translators: %s is the item quantity.
139
-									esc_html__( 'Qty %s', 'invoicing' ),
139
+									esc_html__('Qty %s', 'invoicing'),
140 140
 									sprintf(
141 141
 										'<input
142 142
 											type="number"
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 											max="%s"
149 149
 										>',
150 150
 										(float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(),
151
-										floatval( null !== $max_qty ? $max_qty : 1000000000000 )
151
+										floatval(null !== $max_qty ? $max_qty : 1000000000000)
152 152
 									)
153 153
 								)
154 154
 							);
@@ -157,113 +157,113 @@  discard block
 block discarded – undo
157 157
 								'<small class="d-sm-none text-muted form-text">%s</small>',
158 158
 								sprintf(
159 159
 									// translators: %s is the item quantity.
160
-									esc_html__( 'Qty %s', 'invoicing' ),
160
+									esc_html__('Qty %s', 'invoicing'),
161 161
 									(float) $item->get_quantity()
162 162
 								)
163 163
 							);
164 164
 						}
165 165
 
166
-						if ( $has_featured_image || $has_variable_pricing ) {
166
+						if ($has_featured_image || $has_variable_pricing) {
167 167
 							echo '</div>';
168 168
 							echo '</div>';
169 169
 						}
170 170
 					}
171 171
 
172 172
 					// Item price.
173
-					if ( 'price' === $key ) {
173
+					if ('price' === $key) {
174 174
 
175 175
                         // Set the currency position.
176 176
                         $position = wpinv_currency_position();
177 177
 
178
-                        if ( 'left_space' === $position ) {
178
+                        if ('left_space' === $position) {
179 179
                             $position = 'left';
180 180
                         }
181 181
 
182
-                        if ( 'right_space' === $position ) {
182
+                        if ('right_space' === $position) {
183 183
                             $position = 'right';
184 184
 					    }
185 185
 
186
-                        if ( $has_variable_pricing ) { ?>
186
+                        if ($has_variable_pricing) { ?>
187 187
                             <span class="getpaid-items-<?php echo (int) $price_id; ?>-view-price">
188
-                                <?php echo wp_kses_post( wpinv_price( $price['amount'], $currency ) ); ?>
188
+                                <?php echo wp_kses_post(wpinv_price($price['amount'], $currency)); ?>
189 189
                             </span>
190
-                            <input name='getpaid-items[<?php echo (int) $price_id; ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $price['amount'] ); ?>'>
191
-                        <?php } elseif ( $item->user_can_set_their_price() ) {
192
-                            $price            = max( (float) $item->get_price(), (float) $item->get_minimum_price() );
190
+                            <input name='getpaid-items[<?php echo (int) $price_id; ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr($price['amount']); ?>'>
191
+                        <?php } elseif ($item->user_can_set_their_price()) {
192
+                            $price            = max((float) $item->get_price(), (float) $item->get_minimum_price());
193 193
                             $minimum          = (float) $item->get_minimum_price();
194 194
                             $validate_minimum = '';
195 195
                             $class            = '';
196 196
                             $data_minimum     = '';
197 197
 
198
-                            if ( $minimum > 0 ) {
198
+                            if ($minimum > 0) {
199 199
                                 $validate_minimum = sprintf(
200 200
                                     // translators: %s is the minimum price.
201
-                                    esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ),
202
-                                    wp_strip_all_tags( wpinv_price( $minimum, $currency ) )
201
+                                    esc_attr__('The minimum allowed amount is %s', 'invoicing'),
202
+                                    wp_strip_all_tags(wpinv_price($minimum, $currency))
203 203
                                 );
204 204
 
205 205
                                 $class = 'getpaid-validate-minimum-amount';
206 206
 
207
-                                $data_minimum     = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'";
207
+                                $data_minimum = "data-minimum-amount='" . esc_attr(getpaid_unstandardize_amount($minimum)) . "'";
208 208
                             }
209 209
 
210 210
                             ?>
211 211
                             <div class="input-group input-group-sm">
212
-                                <?php if ( 'left' === $position ) : ?>
213
-                                    <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?>
212
+                                <?php if ('left' === $position) : ?>
213
+                                    <?php if (empty($GLOBALS['aui_bs5'])) : ?>
214 214
                                         <div class="input-group-prepend ">
215 215
                                             <span class="input-group-text">
216
-                                                <?php echo wp_kses_post( wpinv_currency_symbol( $currency ) ); ?></span>
216
+                                                <?php echo wp_kses_post(wpinv_currency_symbol($currency)); ?></span>
217 217
                                             </span>
218 218
                                         </div>
219 219
                                     <?php else : ?>
220 220
                                         <span class="input-group-text">
221
-                                            <?php echo wp_kses_post( wpinv_currency_symbol( $currency ) ); ?></span>
221
+                                            <?php echo wp_kses_post(wpinv_currency_symbol($currency)); ?></span>
222 222
                                         </span>
223 223
                                     <?php endif; ?>
224 224
                                 <?php endif; ?>
225 225
 
226
-                                <input type="number" step="0.01" <?php echo wp_kses_post( $data_minimum ); ?> name="getpaid-items[<?php echo (int) $item->get_id(); ?>][price]" value="<?php echo esc_attr( getpaid_unstandardize_amount( $price ) ); ?>" placeholder="<?php echo esc_attr( getpaid_unstandardize_amount( $item->get_minimum_price() ) ); ?>" class="getpaid-item-price-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border <?php echo esc_attr( $class ); ?>" style="width: 64px; line-height: 1; min-height: 35px;">
226
+                                <input type="number" step="0.01" <?php echo wp_kses_post($data_minimum); ?> name="getpaid-items[<?php echo (int) $item->get_id(); ?>][price]" value="<?php echo esc_attr(getpaid_unstandardize_amount($price)); ?>" placeholder="<?php echo esc_attr(getpaid_unstandardize_amount($item->get_minimum_price())); ?>" class="getpaid-item-price-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border <?php echo esc_attr($class); ?>" style="width: 64px; line-height: 1; min-height: 35px;">
227 227
 
228
-                                <?php if ( ! empty( $validate_minimum ) ) : ?>
228
+                                <?php if (!empty($validate_minimum)) : ?>
229 229
                                     <div class="invalid-tooltip">
230
-                                        <?php echo wp_kses_post( $validate_minimum ); ?>
230
+                                        <?php echo wp_kses_post($validate_minimum); ?>
231 231
                                     </div>
232 232
                                 <?php endif; ?>
233 233
 
234
-                                <?php if ( 'left' !== $position ) : ?>
235
-                                    <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?>
234
+                                <?php if ('left' !== $position) : ?>
235
+                                    <?php if (empty($GLOBALS['aui_bs5'])) : ?>
236 236
                                         <div class="input-group-append ">
237 237
                                             <span class="input-group-text">
238
-                                                <?php echo wp_kses_post( wpinv_currency_symbol( $currency ) ); ?></span>
238
+                                                <?php echo wp_kses_post(wpinv_currency_symbol($currency)); ?></span>
239 239
                                             </span>
240 240
                                         </div>
241 241
                                     <?php else : ?>
242 242
                                         <span class="input-group-text">
243
-                                            <?php echo wp_kses_post( wpinv_currency_symbol( $currency ) ); ?></span>
243
+                                            <?php echo wp_kses_post(wpinv_currency_symbol($currency)); ?></span>
244 244
                                         </span>
245 245
                                     <?php endif; ?>
246 246
                                 <?php endif; ?>
247 247
                             </div>
248 248
                         <?php } else { ?>
249 249
                             <span class="getpaid-items-<?php echo (int) $item->get_id(); ?>-view-price">
250
-                                <?php echo wp_kses_post( wpinv_price( $item->get_price(), $currency ) ); ?>
250
+                                <?php echo wp_kses_post(wpinv_price($item->get_price(), $currency)); ?>
251 251
                             </span>
252
-                            <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'>
252
+                            <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr($item->get_price()); ?>'>
253 253
                         <?php
254 254
                         }
255 255
 
256 256
                         printf(
257 257
                             '<small class="d-sm-none text-muted form-text getpaid-mobile-item-subtotal">%s</small>',
258 258
                             // translators: %s is the item subtotal.
259
-                            sprintf( esc_html__( 'Subtotal: %s', 'invoicing' ), wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ) )
259
+                            sprintf(esc_html__('Subtotal: %s', 'invoicing'), wp_kses_post(wpinv_price($item->get_sub_total(), $currency)))
260 260
                         );
261 261
 					}
262 262
 
263 263
 					// Item quantity.
264
-					if ( 'quantity' === $key ) {
264
+					if ('quantity' === $key) {
265 265
 
266
-                        if ( $item->allows_quantities() ) {
266
+                        if ($item->allows_quantities()) {
267 267
                             ?>
268 268
                             <input name='getpaid-items[<?php echo (int) $price_id; ?>][quantity]' type="number" step="any" style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(); ?>' min='1' <?php echo null !== $max_qty ? 'max="' . (float) $max_qty . '"' : ''; ?> required>
269 269
                         <?php } else { ?>
@@ -276,15 +276,15 @@  discard block
 block discarded – undo
276 276
                     }
277 277
 
278 278
 					// Item sub total.
279
-					if ( 'subtotal' === $key ) {
280
-                        if( $has_variable_pricing ) {
281
-                            echo wp_kses_post( wpinv_price( $item->get_sub_total( 'view', $price_id ), $currency ) );
279
+					if ('subtotal' === $key) {
280
+                        if ($has_variable_pricing) {
281
+                            echo wp_kses_post(wpinv_price($item->get_sub_total('view', $price_id), $currency));
282 282
                         } else {
283
-                            echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) );
283
+                            echo wp_kses_post(wpinv_price($item->get_sub_total(), $currency));
284 284
                         }
285 285
 					}
286 286
 
287
-					do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
287
+					do_action("getpaid_payment_form_cart_item_$key", $item, $form);
288 288
 				?>
289 289
 
290 290
 			</div>
@@ -295,4 +295,4 @@  discard block
 block discarded – undo
295 295
 
296 296
 </div>
297 297
 <?php
298
-do_action( 'getpaid_payment_form_cart_item', $form, $item );
298
+do_action('getpaid_payment_form_cart_item', $form, $item);
Please login to merge, or discard this patch.
templates/payment-forms/cart.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -47,11 +47,11 @@
 block discarded – undo
47 47
                 $prices = $item->get_variable_prices();
48 48
 
49 49
                 if ( $item->has_variable_pricing() ) {
50
-				    foreach ( $prices as $variable_price_id => $price ) {
51
-					    wpinv_get_template( 'payment-forms/cart-item.php', compact( 'form', 'item', 'variable_price_id', 'price', 'columns' ) );
50
+                    foreach ( $prices as $variable_price_id => $price ) {
51
+                        wpinv_get_template( 'payment-forms/cart-item.php', compact( 'form', 'item', 'variable_price_id', 'price', 'columns' ) );
52 52
                     }
53 53
                 } else {
54
-				    wpinv_get_template( 'payment-forms/cart-item.php', compact( 'form', 'item', 'columns' ) );
54
+                    wpinv_get_template( 'payment-forms/cart-item.php', compact( 'form', 'item', 'columns' ) );
55 55
                 }
56 56
             }
57 57
 
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -7,34 +7,34 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Cart table columns.
13 13
 $columns = array(
14
-    'name'     => __( 'Item', 'invoicing' ),
15
-    'price'    => __( 'Price', 'invoicing' ),
16
-    'quantity' => __( 'Qty', 'invoicing' ),
17
-    'subtotal' => __( 'Subtotal', 'invoicing' ),
14
+    'name'     => __('Item', 'invoicing'),
15
+    'price'    => __('Price', 'invoicing'),
16
+    'quantity' => __('Qty', 'invoicing'),
17
+    'subtotal' => __('Subtotal', 'invoicing'),
18 18
 );
19 19
 
20
-if ( ! empty( $form->invoice ) ) {
21
-    $columns = getpaid_invoice_item_columns( $form->invoice );
20
+if (!empty($form->invoice)) {
21
+    $columns = getpaid_invoice_item_columns($form->invoice);
22 22
 }
23 23
 
24
-if ( isset( $columns['tax_rate'] ) ) {
25
-    unset( $columns['tax_rate'] );
24
+if (isset($columns['tax_rate'])) {
25
+    unset($columns['tax_rate']);
26 26
 }
27 27
 
28
-$columns = apply_filters( 'getpaid_payment_form_cart_table_columns', $columns, $form );
28
+$columns = apply_filters('getpaid_payment_form_cart_table_columns', $columns, $form);
29 29
 
30 30
 ?>
31 31
     <div class="getpaid-payment-form-items-cart border form-group mb-3">
32 32
 
33 33
         <div class="getpaid-payment-form-items-cart-header font-weight-bold bg-light border-bottom py-2 px-3">
34 34
             <div class="form-row row">
35
-                <?php foreach ( $columns as $key => $label ) : ?>
36
-                    <div class="<?php echo 'name' == $key ? 'col-6' : 'col'; ?> <?php echo ( in_array( $key, array( 'subtotal', 'quantity', 'tax_rate' ) ) ) ? 'd-none d-sm-block' : ''; ?> getpaid-form-cart-item-<?php echo esc_attr( $key ); ?>">
37
-                        <span><?php echo esc_html( $label ); ?></span>
35
+                <?php foreach ($columns as $key => $label) : ?>
36
+                    <div class="<?php echo 'name' == $key ? 'col-6' : 'col'; ?> <?php echo (in_array($key, array('subtotal', 'quantity', 'tax_rate'))) ? 'd-none d-sm-block' : ''; ?> getpaid-form-cart-item-<?php echo esc_attr($key); ?>">
37
+                        <span><?php echo esc_html($label); ?></span>
38 38
                     </div>
39 39
                 <?php endforeach; ?>
40 40
             </div>
@@ -43,24 +43,24 @@  discard block
 block discarded – undo
43 43
         <?php
44 44
 
45 45
             // Display the item totals.
46
-            foreach ( $form->get_items() as $item ) {
46
+            foreach ($form->get_items() as $item) {
47 47
                 $prices = $item->get_variable_prices();
48 48
 
49
-                if ( $item->has_variable_pricing() ) {
50
-				    foreach ( $prices as $variable_price_id => $price ) {
51
-					    wpinv_get_template( 'payment-forms/cart-item.php', compact( 'form', 'item', 'variable_price_id', 'price', 'columns' ) );
49
+                if ($item->has_variable_pricing()) {
50
+				    foreach ($prices as $variable_price_id => $price) {
51
+					    wpinv_get_template('payment-forms/cart-item.php', compact('form', 'item', 'variable_price_id', 'price', 'columns'));
52 52
                     }
53 53
                 } else {
54
-				    wpinv_get_template( 'payment-forms/cart-item.php', compact( 'form', 'item', 'columns' ) );
54
+				    wpinv_get_template('payment-forms/cart-item.php', compact('form', 'item', 'columns'));
55 55
                 }
56 56
             }
57 57
 
58 58
             // Display the cart totals.
59
-            wpinv_get_template( 'payment-forms/cart-totals.php', compact( 'form' ) );
59
+            wpinv_get_template('payment-forms/cart-totals.php', compact('form'));
60 60
 
61 61
         ?>
62 62
     </div>
63 63
 
64 64
 <?php
65 65
 
66
-do_action( 'getpaid_after_payment_form_cart', $form );
66
+do_action('getpaid_after_payment_form_cart', $form);
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-taxes.php 2 patches
Indentation   +244 added lines, -244 removed lines patch added patch discarded remove patch
@@ -12,257 +12,257 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Taxes {
14 14
 
15
-	/**
16
-	 * Submission taxes.
17
-	 * @var array
18
-	 */
19
-	public $taxes = array();
20
-
21
-	/**
22
-	 * Whether or not we should skip the taxes.
23
-	 * @var bool
24
-	 */
25
-	protected $skip_taxes = false;
15
+    /**
16
+     * Submission taxes.
17
+     * @var array
18
+     */
19
+    public $taxes = array();
20
+
21
+    /**
22
+     * Whether or not we should skip the taxes.
23
+     * @var bool
24
+     */
25
+    protected $skip_taxes = false;
26
+
27
+    /**
28
+     * Class constructor
29
+     *
30
+     * @param GetPaid_Payment_Form_Submission $submission
31
+     */
32
+    public function __construct( $submission ) {
33
+        // Validate VAT number.
34
+        $this->validate_vat( $submission );
35
+
36
+        if ( $this->skip_taxes ) {
37
+            return;
38
+        }
39
+
40
+        foreach ( $submission->get_items() as $item ) {
41
+            $this->process_item_tax( $item, $submission );
42
+        }
43
+
44
+        // Process any existing invoice taxes.
45
+        if ( $submission->has_invoice() ) {
46
+            $invoice = $submission->get_invoice();
47
+            $invoice = $this->refresh_totals( $invoice, $submission );
48
+
49
+            $this->taxes = array_replace( $invoice->get_taxes(), $this->taxes );
50
+        }
51
+    }
52
+
53
+    /**
54
+     * Maybe process tax.
55
+     *
56
+     * @since 1.0.19
57
+     * @param GetPaid_Form_Item $item
58
+     * @param GetPaid_Payment_Form_Submission $submission
59
+     */
60
+    public function process_item_tax( $item, $submission ) {
61
+
62
+        $rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
63
+        $rates    = getpaid_filter_item_tax_rates( $item, $rates );
64
+        $taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
65
+        $r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
66
+
67
+        foreach ( $taxes as $name => $amount ) {
68
+            $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
69
+            $tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
70
+
71
+            $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
72
+
73
+            if ( ! isset( $this->taxes[ $name ] ) ) {
74
+                $this->taxes[ $name ] = $tax;
75
+                continue;
76
+            }
77
+
78
+            $this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
79
+            $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
80
+
81
+        }
82
+
83
+    }
26 84
 
27 85
     /**
28
-	 * Class constructor
29
-	 *
30
-	 * @param GetPaid_Payment_Form_Submission $submission
31
-	 */
32
-	public function __construct( $submission ) {
33
-		// Validate VAT number.
34
-		$this->validate_vat( $submission );
35
-
36
-		if ( $this->skip_taxes ) {
37
-			return;
38
-		}
39
-
40
-		foreach ( $submission->get_items() as $item ) {
41
-			$this->process_item_tax( $item, $submission );
42
-		}
43
-
44
-		// Process any existing invoice taxes.
45
-		if ( $submission->has_invoice() ) {
46
-			$invoice = $submission->get_invoice();
47
-			$invoice = $this->refresh_totals( $invoice, $submission );
48
-
49
-			$this->taxes = array_replace( $invoice->get_taxes(), $this->taxes );
50
-		}
51
-	}
52
-
53
-	/**
54
-	 * Maybe process tax.
55
-	 *
56
-	 * @since 1.0.19
57
-	 * @param GetPaid_Form_Item $item
58
-	 * @param GetPaid_Payment_Form_Submission $submission
59
-	 */
60
-	public function process_item_tax( $item, $submission ) {
61
-
62
-		$rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
63
-		$rates    = getpaid_filter_item_tax_rates( $item, $rates );
64
-		$taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
65
-		$r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
66
-
67
-		foreach ( $taxes as $name => $amount ) {
68
-			$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
69
-			$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
70
-
71
-			$item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
72
-
73
-			if ( ! isset( $this->taxes[ $name ] ) ) {
74
-				$this->taxes[ $name ] = $tax;
75
-				continue;
76
-			}
77
-
78
-			$this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
79
-			$this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
80
-
81
-		}
82
-
83
-	}
84
-
85
-	/**
86
-	 * Checks if the submission has a digital item.
87
-	 *
88
-	 * @param GetPaid_Payment_Form_Submission $submission
89
-	 * @since 1.0.19
90
-	 * @return bool
91
-	 */
92
-	public function has_digital_item( $submission ) {
93
-
94
-		foreach ( $submission->get_items() as $item ) {
95
-
96
-			if ( 'digital' == $item->get_vat_rule() ) {
97
-				return true;
98
-			}
86
+     * Checks if the submission has a digital item.
87
+     *
88
+     * @param GetPaid_Payment_Form_Submission $submission
89
+     * @since 1.0.19
90
+     * @return bool
91
+     */
92
+    public function has_digital_item( $submission ) {
93
+
94
+        foreach ( $submission->get_items() as $item ) {
95
+
96
+            if ( 'digital' == $item->get_vat_rule() ) {
97
+                return true;
98
+            }
99 99
 }
100 100
 
101
-		return false;
102
-	}
103
-
104
-	/**
105
-	 * Checks if this is an eu store.
106
-	 *
107
-	 * @since 1.0.19
108
-	 * @return bool
109
-	 */
110
-	public static function is_eu_store() {
111
-		return self::is_eu_country( wpinv_get_default_country() );
112
-	}
113
-
114
-	/**
115
-	 * Checks if this is an eu country.
116
-	 *
117
-	 * @param string $country
118
-	 * @since 1.0.19
119
-	 * @return bool
120
-	 */
121
-	public static function is_eu_country( $country ) {
122
-		return getpaid_is_eu_state( $country );
123
-	}
124
-
125
-	/**
126
-	 * Checks if this is an eu purchase.
127
-	 *
128
-	 * @param string $customer_country
129
-	 * @since 1.0.19
130
-	 * @return bool
131
-	 */
132
-	public static function is_eu_transaction( $customer_country ) {
133
-		return self::is_eu_country( $customer_country ) && self::is_eu_store();
134
-	}
135
-
136
-	/**
137
-	 * Retrieves the vat number.
138
-	 *
139
-	 * @param GetPaid_Payment_Form_Submission $submission
140
-	 * @since 1.0.19
141
-	 * @return string
142
-	 */
143
-	public function get_vat_number( $submission ) {
144
-
145
-		// Retrieve from the posted number.
146
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
-		if ( ! is_null( $vat_number ) ) {
148
-			return wpinv_clean( $vat_number );
149
-		}
150
-
151
-		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
152
-	}
153
-
154
-	/**
155
-	 * Retrieves the company.
156
-	 *
157
-	 * @param GetPaid_Payment_Form_Submission $submission
158
-	 * @since 1.0.19
159
-	 * @return string
160
-	 */
161
-	public function get_company( $submission ) {
162
-
163
-		// Retrieve from the posted data.
164
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
165
-		if ( ! empty( $company ) ) {
166
-			return wpinv_clean( $company );
167
-		}
168
-
169
-		// Retrieve from the invoice.
170
-		return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
171
-	}
172
-
173
-	/**
174
-	 * Checks if we require a VAT number.
175
-	 *
176
-	 * @param bool $ip_in_eu Whether the customer IP is from the EU
177
-	 * @param bool $country_in_eu Whether the customer country is from the EU
178
-	 * @since 1.0.19
179
-	 * @return string
180
-	 */
181
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
182
-
183
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
-		$prevent_b2c = ! empty( $prevent_b2c );
185
-		$is_eu       = $ip_in_eu || $country_in_eu;
186
-
187
-		return $prevent_b2c && $is_eu;
188
-	}
189
-
190
-	/**
191
-	 * Validate VAT data.
192
-	 *
193
-	 * @param GetPaid_Payment_Form_Submission $submission
194
-	 * @since 1.0.19
195
-	 */
196
-	public function validate_vat( $submission ) {
197
-
198
-		$in_eu = $this->is_eu_transaction( $submission->country );
199
-
200
-		// Abort if we are not validating vat numbers.
201
-		if ( ! $in_eu ) {
101
+        return false;
102
+    }
103
+
104
+    /**
105
+     * Checks if this is an eu store.
106
+     *
107
+     * @since 1.0.19
108
+     * @return bool
109
+     */
110
+    public static function is_eu_store() {
111
+        return self::is_eu_country( wpinv_get_default_country() );
112
+    }
113
+
114
+    /**
115
+     * Checks if this is an eu country.
116
+     *
117
+     * @param string $country
118
+     * @since 1.0.19
119
+     * @return bool
120
+     */
121
+    public static function is_eu_country( $country ) {
122
+        return getpaid_is_eu_state( $country );
123
+    }
124
+
125
+    /**
126
+     * Checks if this is an eu purchase.
127
+     *
128
+     * @param string $customer_country
129
+     * @since 1.0.19
130
+     * @return bool
131
+     */
132
+    public static function is_eu_transaction( $customer_country ) {
133
+        return self::is_eu_country( $customer_country ) && self::is_eu_store();
134
+    }
135
+
136
+    /**
137
+     * Retrieves the vat number.
138
+     *
139
+     * @param GetPaid_Payment_Form_Submission $submission
140
+     * @since 1.0.19
141
+     * @return string
142
+     */
143
+    public function get_vat_number( $submission ) {
144
+
145
+        // Retrieve from the posted number.
146
+        $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
+        if ( ! is_null( $vat_number ) ) {
148
+            return wpinv_clean( $vat_number );
149
+        }
150
+
151
+        return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
152
+    }
153
+
154
+    /**
155
+     * Retrieves the company.
156
+     *
157
+     * @param GetPaid_Payment_Form_Submission $submission
158
+     * @since 1.0.19
159
+     * @return string
160
+     */
161
+    public function get_company( $submission ) {
162
+
163
+        // Retrieve from the posted data.
164
+        $company = $submission->get_field( 'wpinv_company', 'billing' );
165
+        if ( ! empty( $company ) ) {
166
+            return wpinv_clean( $company );
167
+        }
168
+
169
+        // Retrieve from the invoice.
170
+        return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
171
+    }
172
+
173
+    /**
174
+     * Checks if we require a VAT number.
175
+     *
176
+     * @param bool $ip_in_eu Whether the customer IP is from the EU
177
+     * @param bool $country_in_eu Whether the customer country is from the EU
178
+     * @since 1.0.19
179
+     * @return string
180
+     */
181
+    public function requires_vat( $ip_in_eu, $country_in_eu ) {
182
+
183
+        $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
+        $prevent_b2c = ! empty( $prevent_b2c );
185
+        $is_eu       = $ip_in_eu || $country_in_eu;
186
+
187
+        return $prevent_b2c && $is_eu;
188
+    }
189
+
190
+    /**
191
+     * Validate VAT data.
192
+     *
193
+     * @param GetPaid_Payment_Form_Submission $submission
194
+     * @since 1.0.19
195
+     */
196
+    public function validate_vat( $submission ) {
197
+
198
+        $in_eu = $this->is_eu_transaction( $submission->country );
199
+
200
+        // Abort if we are not validating vat numbers.
201
+        if ( ! $in_eu ) {
202 202
             return;
203
-		}
203
+        }
204 204
 
205
-		// Prepare variables.
206
-		$vat_number  = $this->get_vat_number( $submission );
207
-		$ip_country  = getpaid_get_ip_country();
205
+        // Prepare variables.
206
+        $vat_number  = $this->get_vat_number( $submission );
207
+        $ip_country  = getpaid_get_ip_country();
208 208
         $is_eu       = $this->is_eu_country( $submission->country );
209 209
         $is_ip_eu    = $this->is_eu_country( $ip_country );
210 210
 
211
-		// Maybe abort early for initial fetches.
212
-		if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
213
-			return;
214
-		}
215
-
216
-		// If we're preventing business to consumer purchases,
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
218
-
219
-			// Ensure that a vat number has been specified.
220
-			throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) );
221
-
222
-		}
223
-
224
-		if ( empty( $vat_number ) ) {
225
-			return;
226
-		}
227
-
228
-		if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
229
-			throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) );
230
-		}
231
-
232
-		if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
233
-			return;
234
-		}
235
-
236
-		$this->skip_taxes = true;
237
-	}
238
-
239
-	 /**
240
-	 * Refresh totals if country or region changed in payment form.
241
-	 *
242
-	 * @since 2.8.8
243
-	 *
244
-	 * @param object $invoice Invoice object.
245
-	 * @param GetPaid_Payment_Form_Submission $submission Payment form submission object.
246
-	 * @return object Invoice object.
247
-	 */
248
-	public function refresh_totals( $invoice, $submission ) {
249
-		if ( ! ( ! empty( $_POST['action'] ) && ( $_POST['action'] == 'wpinv_payment_form_refresh_prices' || $_POST['action'] == 'wpinv_payment_form' ) && isset( $_POST['billing']['wpinv_country'] ) ) ) {
250
-			return $invoice;
251
-		}
252
-
253
-		if ( ! ( ! $invoice->is_paid() && ! $invoice->is_refunded() && ! $invoice->is_held() ) ) {
254
-			return $invoice;
255
-		}
256
-
257
-		// Maybe check the country, state.
258
-		if ( $submission->country != $invoice->get_country() || $submission->state != $invoice->get_state() ) {
259
-			$invoice->set_country( sanitize_text_field( $submission->country ) );
260
-			$invoice->set_state( sanitize_text_field( $submission->state ) );
261
-
262
-			// Recalculate totals.
263
-			$invoice->recalculate_total();
264
-		}
265
-
266
-		return $invoice;
267
-	}
211
+        // Maybe abort early for initial fetches.
212
+        if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
213
+            return;
214
+        }
215
+
216
+        // If we're preventing business to consumer purchases,
217
+        if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
218
+
219
+            // Ensure that a vat number has been specified.
220
+            throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) );
221
+
222
+        }
223
+
224
+        if ( empty( $vat_number ) ) {
225
+            return;
226
+        }
227
+
228
+        if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
229
+            throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) );
230
+        }
231
+
232
+        if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
233
+            return;
234
+        }
235
+
236
+        $this->skip_taxes = true;
237
+    }
238
+
239
+        /**
240
+         * Refresh totals if country or region changed in payment form.
241
+         *
242
+         * @since 2.8.8
243
+         *
244
+         * @param object $invoice Invoice object.
245
+         * @param GetPaid_Payment_Form_Submission $submission Payment form submission object.
246
+         * @return object Invoice object.
247
+         */
248
+    public function refresh_totals( $invoice, $submission ) {
249
+        if ( ! ( ! empty( $_POST['action'] ) && ( $_POST['action'] == 'wpinv_payment_form_refresh_prices' || $_POST['action'] == 'wpinv_payment_form' ) && isset( $_POST['billing']['wpinv_country'] ) ) ) {
250
+            return $invoice;
251
+        }
252
+
253
+        if ( ! ( ! $invoice->is_paid() && ! $invoice->is_refunded() && ! $invoice->is_held() ) ) {
254
+            return $invoice;
255
+        }
256
+
257
+        // Maybe check the country, state.
258
+        if ( $submission->country != $invoice->get_country() || $submission->state != $invoice->get_state() ) {
259
+            $invoice->set_country( sanitize_text_field( $submission->country ) );
260
+            $invoice->set_state( sanitize_text_field( $submission->state ) );
261
+
262
+            // Recalculate totals.
263
+            $invoice->recalculate_total();
264
+        }
265
+
266
+        return $invoice;
267
+    }
268 268
 }
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Payment form submission taxes class
@@ -29,24 +29,24 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @param GetPaid_Payment_Form_Submission $submission
31 31
 	 */
32
-	public function __construct( $submission ) {
32
+	public function __construct($submission) {
33 33
 		// Validate VAT number.
34
-		$this->validate_vat( $submission );
34
+		$this->validate_vat($submission);
35 35
 
36
-		if ( $this->skip_taxes ) {
36
+		if ($this->skip_taxes) {
37 37
 			return;
38 38
 		}
39 39
 
40
-		foreach ( $submission->get_items() as $item ) {
41
-			$this->process_item_tax( $item, $submission );
40
+		foreach ($submission->get_items() as $item) {
41
+			$this->process_item_tax($item, $submission);
42 42
 		}
43 43
 
44 44
 		// Process any existing invoice taxes.
45
-		if ( $submission->has_invoice() ) {
45
+		if ($submission->has_invoice()) {
46 46
 			$invoice = $submission->get_invoice();
47
-			$invoice = $this->refresh_totals( $invoice, $submission );
47
+			$invoice = $this->refresh_totals($invoice, $submission);
48 48
 
49
-			$this->taxes = array_replace( $invoice->get_taxes(), $this->taxes );
49
+			$this->taxes = array_replace($invoice->get_taxes(), $this->taxes);
50 50
 		}
51 51
 	}
52 52
 
@@ -57,26 +57,26 @@  discard block
 block discarded – undo
57 57
 	 * @param GetPaid_Form_Item $item
58 58
 	 * @param GetPaid_Payment_Form_Submission $submission
59 59
 	 */
60
-	public function process_item_tax( $item, $submission ) {
60
+	public function process_item_tax($item, $submission) {
61 61
 
62
-		$rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
63
-		$rates    = getpaid_filter_item_tax_rates( $item, $rates );
64
-		$taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
65
-		$r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
62
+		$rates    = getpaid_get_item_tax_rates($item, $submission->country, $submission->state);
63
+		$rates    = getpaid_filter_item_tax_rates($item, $rates);
64
+		$taxes    = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, false), $rates);
65
+		$r_taxes  = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, true), $rates);
66 66
 
67
-		foreach ( $taxes as $name => $amount ) {
68
-			$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
69
-			$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
67
+		foreach ($taxes as $name => $amount) {
68
+			$recurring = isset($r_taxes[$name]) ? $r_taxes[$name] : 0;
69
+			$tax       = getpaid_prepare_item_tax($item, $name, $amount, $recurring);
70 70
 
71
-			$item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
71
+			$item->item_tax += wpinv_sanitize_amount($tax['initial_tax']);
72 72
 
73
-			if ( ! isset( $this->taxes[ $name ] ) ) {
74
-				$this->taxes[ $name ] = $tax;
73
+			if (!isset($this->taxes[$name])) {
74
+				$this->taxes[$name] = $tax;
75 75
 				continue;
76 76
 			}
77 77
 
78
-			$this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
79
-			$this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
78
+			$this->taxes[$name]['initial_tax']   += $tax['initial_tax'];
79
+			$this->taxes[$name]['recurring_tax'] += $tax['recurring_tax'];
80 80
 
81 81
 		}
82 82
 
@@ -89,11 +89,11 @@  discard block
 block discarded – undo
89 89
 	 * @since 1.0.19
90 90
 	 * @return bool
91 91
 	 */
92
-	public function has_digital_item( $submission ) {
92
+	public function has_digital_item($submission) {
93 93
 
94
-		foreach ( $submission->get_items() as $item ) {
94
+		foreach ($submission->get_items() as $item) {
95 95
 
96
-			if ( 'digital' == $item->get_vat_rule() ) {
96
+			if ('digital' == $item->get_vat_rule()) {
97 97
 				return true;
98 98
 			}
99 99
 }
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	 * @return bool
109 109
 	 */
110 110
 	public static function is_eu_store() {
111
-		return self::is_eu_country( wpinv_get_default_country() );
111
+		return self::is_eu_country(wpinv_get_default_country());
112 112
 	}
113 113
 
114 114
 	/**
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
 	 * @since 1.0.19
119 119
 	 * @return bool
120 120
 	 */
121
-	public static function is_eu_country( $country ) {
122
-		return getpaid_is_eu_state( $country );
121
+	public static function is_eu_country($country) {
122
+		return getpaid_is_eu_state($country);
123 123
 	}
124 124
 
125 125
 	/**
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
 	 * @since 1.0.19
130 130
 	 * @return bool
131 131
 	 */
132
-	public static function is_eu_transaction( $customer_country ) {
133
-		return self::is_eu_country( $customer_country ) && self::is_eu_store();
132
+	public static function is_eu_transaction($customer_country) {
133
+		return self::is_eu_country($customer_country) && self::is_eu_store();
134 134
 	}
135 135
 
136 136
 	/**
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
 	 * @since 1.0.19
141 141
 	 * @return string
142 142
 	 */
143
-	public function get_vat_number( $submission ) {
143
+	public function get_vat_number($submission) {
144 144
 
145 145
 		// Retrieve from the posted number.
146
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
-		if ( ! is_null( $vat_number ) ) {
148
-			return wpinv_clean( $vat_number );
146
+		$vat_number = $submission->get_field('wpinv_vat_number', 'billing');
147
+		if (!is_null($vat_number)) {
148
+			return wpinv_clean($vat_number);
149 149
 		}
150 150
 
151 151
 		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
@@ -158,12 +158,12 @@  discard block
 block discarded – undo
158 158
 	 * @since 1.0.19
159 159
 	 * @return string
160 160
 	 */
161
-	public function get_company( $submission ) {
161
+	public function get_company($submission) {
162 162
 
163 163
 		// Retrieve from the posted data.
164
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
165
-		if ( ! empty( $company ) ) {
166
-			return wpinv_clean( $company );
164
+		$company = $submission->get_field('wpinv_company', 'billing');
165
+		if (!empty($company)) {
166
+			return wpinv_clean($company);
167 167
 		}
168 168
 
169 169
 		// Retrieve from the invoice.
@@ -178,10 +178,10 @@  discard block
 block discarded – undo
178 178
 	 * @since 1.0.19
179 179
 	 * @return string
180 180
 	 */
181
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
181
+	public function requires_vat($ip_in_eu, $country_in_eu) {
182 182
 
183
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
-		$prevent_b2c = ! empty( $prevent_b2c );
183
+		$prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase');
184
+		$prevent_b2c = !empty($prevent_b2c);
185 185
 		$is_eu       = $ip_in_eu || $country_in_eu;
186 186
 
187 187
 		return $prevent_b2c && $is_eu;
@@ -193,43 +193,43 @@  discard block
 block discarded – undo
193 193
 	 * @param GetPaid_Payment_Form_Submission $submission
194 194
 	 * @since 1.0.19
195 195
 	 */
196
-	public function validate_vat( $submission ) {
196
+	public function validate_vat($submission) {
197 197
 
198
-		$in_eu = $this->is_eu_transaction( $submission->country );
198
+		$in_eu = $this->is_eu_transaction($submission->country);
199 199
 
200 200
 		// Abort if we are not validating vat numbers.
201
-		if ( ! $in_eu ) {
201
+		if (!$in_eu) {
202 202
             return;
203 203
 		}
204 204
 
205 205
 		// Prepare variables.
206
-		$vat_number  = $this->get_vat_number( $submission );
206
+		$vat_number  = $this->get_vat_number($submission);
207 207
 		$ip_country  = getpaid_get_ip_country();
208
-        $is_eu       = $this->is_eu_country( $submission->country );
209
-        $is_ip_eu    = $this->is_eu_country( $ip_country );
208
+        $is_eu       = $this->is_eu_country($submission->country);
209
+        $is_ip_eu    = $this->is_eu_country($ip_country);
210 210
 
211 211
 		// Maybe abort early for initial fetches.
212
-		if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
212
+		if ($submission->is_initial_fetch() && empty($vat_number)) {
213 213
 			return;
214 214
 		}
215 215
 
216 216
 		// If we're preventing business to consumer purchases,
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
217
+		if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) {
218 218
 
219 219
 			// Ensure that a vat number has been specified.
220
-			throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) );
220
+			throw new GetPaid_Payment_Exception('.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __('Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing'));
221 221
 
222 222
 		}
223 223
 
224
-		if ( empty( $vat_number ) ) {
224
+		if (empty($vat_number)) {
225 225
 			return;
226 226
 		}
227 227
 
228
-		if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
229
-			throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) );
228
+		if (wpinv_should_validate_vat_number() && !wpinv_validate_vat_number($vat_number, $submission->country)) {
229
+			throw new GetPaid_Payment_Exception('.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __('Your VAT number is invalid', 'invoicing'));
230 230
 		}
231 231
 
232
-		if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
232
+		if (wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option('vat_same_country_rule', 'vat_too')) {
233 233
 			return;
234 234
 		}
235 235
 
@@ -245,19 +245,19 @@  discard block
 block discarded – undo
245 245
 	 * @param GetPaid_Payment_Form_Submission $submission Payment form submission object.
246 246
 	 * @return object Invoice object.
247 247
 	 */
248
-	public function refresh_totals( $invoice, $submission ) {
249
-		if ( ! ( ! empty( $_POST['action'] ) && ( $_POST['action'] == 'wpinv_payment_form_refresh_prices' || $_POST['action'] == 'wpinv_payment_form' ) && isset( $_POST['billing']['wpinv_country'] ) ) ) {
248
+	public function refresh_totals($invoice, $submission) {
249
+		if (!(!empty($_POST['action']) && ($_POST['action'] == 'wpinv_payment_form_refresh_prices' || $_POST['action'] == 'wpinv_payment_form') && isset($_POST['billing']['wpinv_country']))) {
250 250
 			return $invoice;
251 251
 		}
252 252
 
253
-		if ( ! ( ! $invoice->is_paid() && ! $invoice->is_refunded() && ! $invoice->is_held() ) ) {
253
+		if (!(!$invoice->is_paid() && !$invoice->is_refunded() && !$invoice->is_held())) {
254 254
 			return $invoice;
255 255
 		}
256 256
 
257 257
 		// Maybe check the country, state.
258
-		if ( $submission->country != $invoice->get_country() || $submission->state != $invoice->get_state() ) {
259
-			$invoice->set_country( sanitize_text_field( $submission->country ) );
260
-			$invoice->set_state( sanitize_text_field( $submission->state ) );
258
+		if ($submission->country != $invoice->get_country() || $submission->state != $invoice->get_state()) {
259
+			$invoice->set_country(sanitize_text_field($submission->country));
260
+			$invoice->set_state(sanitize_text_field($submission->state));
261 261
 
262 262
 			// Recalculate totals.
263 263
 			$invoice->recalculate_total();
Please login to merge, or discard this patch.