@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,60 +10,60 @@ discard block |
||
10 | 10 | class GetPaid_Form_Item extends WPInv_Item { |
11 | 11 | |
12 | 12 | /** |
13 | - * Stores a custom description for the item. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $custom_description = ''; |
|
18 | - |
|
19 | - /** |
|
20 | - * Stores the item quantity. |
|
21 | - * |
|
22 | - * @var int |
|
23 | - */ |
|
24 | - protected $quantity = 1; |
|
25 | - |
|
26 | - /** |
|
27 | - * Stores the item meta. |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $meta = array(); |
|
32 | - |
|
33 | - /** |
|
34 | - * Is this item required? |
|
35 | - * |
|
36 | - * @var int |
|
37 | - */ |
|
38 | - protected $is_required = true; |
|
39 | - |
|
40 | - /** |
|
41 | - * Are quantities allowed? |
|
42 | - * |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - protected $allow_quantities = false; |
|
46 | - |
|
47 | - /** |
|
48 | - * Associated invoice. |
|
49 | - * |
|
50 | - * @var int |
|
51 | - */ |
|
52 | - public $invoice_id = 0; |
|
53 | - |
|
54 | - /** |
|
55 | - * Item discount. |
|
56 | - * |
|
57 | - * @var float |
|
58 | - */ |
|
59 | - public $item_discount = 0; |
|
60 | - |
|
61 | - /** |
|
62 | - * Item tax. |
|
63 | - * |
|
64 | - * @var float |
|
65 | - */ |
|
66 | - public $item_tax = 0; |
|
13 | + * Stores a custom description for the item. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $custom_description = ''; |
|
18 | + |
|
19 | + /** |
|
20 | + * Stores the item quantity. |
|
21 | + * |
|
22 | + * @var int |
|
23 | + */ |
|
24 | + protected $quantity = 1; |
|
25 | + |
|
26 | + /** |
|
27 | + * Stores the item meta. |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $meta = array(); |
|
32 | + |
|
33 | + /** |
|
34 | + * Is this item required? |
|
35 | + * |
|
36 | + * @var int |
|
37 | + */ |
|
38 | + protected $is_required = true; |
|
39 | + |
|
40 | + /** |
|
41 | + * Are quantities allowed? |
|
42 | + * |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + protected $allow_quantities = false; |
|
46 | + |
|
47 | + /** |
|
48 | + * Associated invoice. |
|
49 | + * |
|
50 | + * @var int |
|
51 | + */ |
|
52 | + public $invoice_id = 0; |
|
53 | + |
|
54 | + /** |
|
55 | + * Item discount. |
|
56 | + * |
|
57 | + * @var float |
|
58 | + */ |
|
59 | + public $item_discount = 0; |
|
60 | + |
|
61 | + /** |
|
62 | + * Item tax. |
|
63 | + * |
|
64 | + * @var float |
|
65 | + */ |
|
66 | + public $item_tax = 0; |
|
67 | 67 | |
68 | 68 | /* |
69 | 69 | |-------------------------------------------------------------------------- |
@@ -81,208 +81,208 @@ discard block |
||
81 | 81 | */ |
82 | 82 | |
83 | 83 | /** |
84 | - * Get the item name. |
|
85 | - * |
|
86 | - * @since 1.0.19 |
|
87 | - * @param string $context View or edit context. |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function get_name( $context = 'view' ) { |
|
91 | - $name = parent::get_name( $context ); |
|
92 | - return $name . wpinv_get_item_suffix( $this ); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Get the item description. |
|
97 | - * |
|
98 | - * @since 1.0.19 |
|
99 | - * @param string $context View or edit context. |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function get_description( $context = 'view' ) { |
|
103 | - |
|
104 | - if ( ! empty( $this->custom_description ) ) { |
|
105 | - return $this->custom_description; |
|
106 | - } |
|
107 | - |
|
108 | - return parent::get_description( $context ); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Returns the sub total. |
|
113 | - * |
|
114 | - * @since 1.0.19 |
|
115 | - * @param string $context View or edit context. |
|
116 | - * @return int |
|
117 | - */ |
|
118 | - public function get_sub_total( $context = 'view' ) { |
|
119 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Returns the recurring sub total. |
|
124 | - * |
|
125 | - * @since 1.0.19 |
|
126 | - * @param string $context View or edit context. |
|
127 | - * @return int |
|
128 | - */ |
|
129 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
130 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * @deprecated |
|
135 | - */ |
|
136 | - public function get_qantity( $context = 'view' ) { |
|
137 | - return $this->get_quantity( $context ); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Get the item quantity. |
|
142 | - * |
|
143 | - * @since 1.0.19 |
|
144 | - * @param string $context View or edit context. |
|
145 | - * @return int |
|
146 | - */ |
|
147 | - public function get_quantity( $context = 'view' ) { |
|
148 | - $quantity = (int) $this->quantity; |
|
149 | - |
|
150 | - if ( empty( $quantity ) || 1 > $quantity ) { |
|
151 | - $quantity = 1; |
|
152 | - } |
|
153 | - |
|
154 | - if ( 'view' == $context ) { |
|
155 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
156 | - } |
|
157 | - |
|
158 | - return $quantity; |
|
159 | - |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Get the item meta data. |
|
164 | - * |
|
165 | - * @since 1.0.19 |
|
166 | - * @param string $context View or edit context. |
|
167 | - * @return meta |
|
168 | - */ |
|
169 | - public function get_item_meta( $context = 'view' ) { |
|
170 | - $meta = $this->meta; |
|
171 | - |
|
172 | - if ( 'view' == $context ) { |
|
173 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
174 | - } |
|
175 | - |
|
176 | - return $meta; |
|
177 | - |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Returns whether or not customers can update the item quantity. |
|
182 | - * |
|
183 | - * @since 1.0.19 |
|
184 | - * @param string $context View or edit context. |
|
185 | - * @return bool |
|
186 | - */ |
|
187 | - public function get_allow_quantities( $context = 'view' ) { |
|
188 | - $allow_quantities = (bool) $this->allow_quantities; |
|
189 | - |
|
190 | - if ( 'view' == $context ) { |
|
191 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
192 | - } |
|
193 | - |
|
194 | - return $allow_quantities; |
|
195 | - |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Returns whether or not the item is required. |
|
200 | - * |
|
201 | - * @since 1.0.19 |
|
202 | - * @param string $context View or edit context. |
|
203 | - * @return bool |
|
204 | - */ |
|
205 | - public function get_is_required( $context = 'view' ) { |
|
206 | - $is_required = (bool) $this->is_required; |
|
207 | - |
|
208 | - if ( 'view' == $context ) { |
|
209 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
210 | - } |
|
211 | - |
|
212 | - return $is_required; |
|
213 | - |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Prepares form data for use. |
|
218 | - * |
|
219 | - * @since 1.0.19 |
|
220 | - * @return array |
|
221 | - */ |
|
222 | - public function prepare_data_for_use() { |
|
223 | - |
|
224 | - return array( |
|
225 | - 'title' => sanitize_text_field( $this->get_name() ), |
|
226 | - 'id' => $this->get_id(), |
|
227 | - 'price' => $this->get_price(), |
|
228 | - 'recurring' => $this->is_recurring(), |
|
229 | - 'description' => $this->get_description(), |
|
230 | - 'allow_quantities' => $this->allows_quantities(), |
|
231 | - 'required' => $this->is_required(), |
|
232 | - ); |
|
233 | - |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Prepares form data for ajax use. |
|
238 | - * |
|
239 | - * @since 1.0.19 |
|
240 | - * @return array |
|
241 | - */ |
|
242 | - public function prepare_data_for_invoice_edit_ajax() { |
|
243 | - |
|
244 | - return array( |
|
245 | - 'id' => $this->get_id(), |
|
246 | - 'texts' => array( |
|
247 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
248 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
249 | - 'item-quantity' => absint( $this->get_quantity() ), |
|
250 | - 'item-price' => wpinv_price( wpinv_format_amount ( $this->get_price() ) ), |
|
251 | - 'item-total' => wpinv_price( wpinv_format_amount( $this->get_sub_total() ) ), |
|
252 | - ), |
|
253 | - 'inputs' => array( |
|
254 | - 'item-id' => $this->get_id(), |
|
255 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
256 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
257 | - 'item-quantity' => absint( $this->get_quantity() ), |
|
258 | - 'item-price' => $this->get_price(), |
|
259 | - ) |
|
260 | - ); |
|
261 | - |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Prepares form data for saving (cart_details). |
|
266 | - * |
|
267 | - * @since 1.0.19 |
|
268 | - * @return array |
|
269 | - */ |
|
270 | - public function prepare_data_for_saving() { |
|
271 | - |
|
272 | - return array( |
|
273 | - 'post_id' => $this->invoice_id, |
|
274 | - 'item_id' => $this->get_id(), |
|
275 | - 'item_name' => sanitize_text_field( $this->get_name() ), |
|
276 | - 'item_description' => $this->get_description(), |
|
277 | - 'tax' => $this->item_tax, |
|
278 | - 'item_price' => $this->get_price(), |
|
279 | - 'quantity' => (int) $this->get_quantity(), |
|
280 | - 'discount' => $this->item_discount, |
|
281 | - 'subtotal' => $this->get_sub_total(), |
|
282 | - 'price' => $this->get_sub_total() + $this->item_tax + $this->item_discount, |
|
283 | - 'meta' => $this->get_item_meta(), |
|
84 | + * Get the item name. |
|
85 | + * |
|
86 | + * @since 1.0.19 |
|
87 | + * @param string $context View or edit context. |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function get_name( $context = 'view' ) { |
|
91 | + $name = parent::get_name( $context ); |
|
92 | + return $name . wpinv_get_item_suffix( $this ); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Get the item description. |
|
97 | + * |
|
98 | + * @since 1.0.19 |
|
99 | + * @param string $context View or edit context. |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function get_description( $context = 'view' ) { |
|
103 | + |
|
104 | + if ( ! empty( $this->custom_description ) ) { |
|
105 | + return $this->custom_description; |
|
106 | + } |
|
107 | + |
|
108 | + return parent::get_description( $context ); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Returns the sub total. |
|
113 | + * |
|
114 | + * @since 1.0.19 |
|
115 | + * @param string $context View or edit context. |
|
116 | + * @return int |
|
117 | + */ |
|
118 | + public function get_sub_total( $context = 'view' ) { |
|
119 | + return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Returns the recurring sub total. |
|
124 | + * |
|
125 | + * @since 1.0.19 |
|
126 | + * @param string $context View or edit context. |
|
127 | + * @return int |
|
128 | + */ |
|
129 | + public function get_recurring_sub_total( $context = 'view' ) { |
|
130 | + return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * @deprecated |
|
135 | + */ |
|
136 | + public function get_qantity( $context = 'view' ) { |
|
137 | + return $this->get_quantity( $context ); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Get the item quantity. |
|
142 | + * |
|
143 | + * @since 1.0.19 |
|
144 | + * @param string $context View or edit context. |
|
145 | + * @return int |
|
146 | + */ |
|
147 | + public function get_quantity( $context = 'view' ) { |
|
148 | + $quantity = (int) $this->quantity; |
|
149 | + |
|
150 | + if ( empty( $quantity ) || 1 > $quantity ) { |
|
151 | + $quantity = 1; |
|
152 | + } |
|
153 | + |
|
154 | + if ( 'view' == $context ) { |
|
155 | + return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
156 | + } |
|
157 | + |
|
158 | + return $quantity; |
|
159 | + |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Get the item meta data. |
|
164 | + * |
|
165 | + * @since 1.0.19 |
|
166 | + * @param string $context View or edit context. |
|
167 | + * @return meta |
|
168 | + */ |
|
169 | + public function get_item_meta( $context = 'view' ) { |
|
170 | + $meta = $this->meta; |
|
171 | + |
|
172 | + if ( 'view' == $context ) { |
|
173 | + return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
174 | + } |
|
175 | + |
|
176 | + return $meta; |
|
177 | + |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Returns whether or not customers can update the item quantity. |
|
182 | + * |
|
183 | + * @since 1.0.19 |
|
184 | + * @param string $context View or edit context. |
|
185 | + * @return bool |
|
186 | + */ |
|
187 | + public function get_allow_quantities( $context = 'view' ) { |
|
188 | + $allow_quantities = (bool) $this->allow_quantities; |
|
189 | + |
|
190 | + if ( 'view' == $context ) { |
|
191 | + return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
192 | + } |
|
193 | + |
|
194 | + return $allow_quantities; |
|
195 | + |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Returns whether or not the item is required. |
|
200 | + * |
|
201 | + * @since 1.0.19 |
|
202 | + * @param string $context View or edit context. |
|
203 | + * @return bool |
|
204 | + */ |
|
205 | + public function get_is_required( $context = 'view' ) { |
|
206 | + $is_required = (bool) $this->is_required; |
|
207 | + |
|
208 | + if ( 'view' == $context ) { |
|
209 | + return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
210 | + } |
|
211 | + |
|
212 | + return $is_required; |
|
213 | + |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Prepares form data for use. |
|
218 | + * |
|
219 | + * @since 1.0.19 |
|
220 | + * @return array |
|
221 | + */ |
|
222 | + public function prepare_data_for_use() { |
|
223 | + |
|
224 | + return array( |
|
225 | + 'title' => sanitize_text_field( $this->get_name() ), |
|
226 | + 'id' => $this->get_id(), |
|
227 | + 'price' => $this->get_price(), |
|
228 | + 'recurring' => $this->is_recurring(), |
|
229 | + 'description' => $this->get_description(), |
|
230 | + 'allow_quantities' => $this->allows_quantities(), |
|
231 | + 'required' => $this->is_required(), |
|
232 | + ); |
|
233 | + |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Prepares form data for ajax use. |
|
238 | + * |
|
239 | + * @since 1.0.19 |
|
240 | + * @return array |
|
241 | + */ |
|
242 | + public function prepare_data_for_invoice_edit_ajax() { |
|
243 | + |
|
244 | + return array( |
|
245 | + 'id' => $this->get_id(), |
|
246 | + 'texts' => array( |
|
247 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
248 | + 'item-description' => wp_kses_post( $this->get_description() ), |
|
249 | + 'item-quantity' => absint( $this->get_quantity() ), |
|
250 | + 'item-price' => wpinv_price( wpinv_format_amount ( $this->get_price() ) ), |
|
251 | + 'item-total' => wpinv_price( wpinv_format_amount( $this->get_sub_total() ) ), |
|
252 | + ), |
|
253 | + 'inputs' => array( |
|
254 | + 'item-id' => $this->get_id(), |
|
255 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
256 | + 'item-description' => wp_kses_post( $this->get_description() ), |
|
257 | + 'item-quantity' => absint( $this->get_quantity() ), |
|
258 | + 'item-price' => $this->get_price(), |
|
259 | + ) |
|
260 | + ); |
|
261 | + |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Prepares form data for saving (cart_details). |
|
266 | + * |
|
267 | + * @since 1.0.19 |
|
268 | + * @return array |
|
269 | + */ |
|
270 | + public function prepare_data_for_saving() { |
|
271 | + |
|
272 | + return array( |
|
273 | + 'post_id' => $this->invoice_id, |
|
274 | + 'item_id' => $this->get_id(), |
|
275 | + 'item_name' => sanitize_text_field( $this->get_name() ), |
|
276 | + 'item_description' => $this->get_description(), |
|
277 | + 'tax' => $this->item_tax, |
|
278 | + 'item_price' => $this->get_price(), |
|
279 | + 'quantity' => (int) $this->get_quantity(), |
|
280 | + 'discount' => $this->item_discount, |
|
281 | + 'subtotal' => $this->get_sub_total(), |
|
282 | + 'price' => $this->get_sub_total() + $this->item_tax + $this->item_discount, |
|
283 | + 'meta' => $this->get_item_meta(), |
|
284 | 284 | ); |
285 | - } |
|
285 | + } |
|
286 | 286 | |
287 | 287 | /* |
288 | 288 | |-------------------------------------------------------------------------- |
@@ -294,70 +294,70 @@ discard block |
||
294 | 294 | | object. |
295 | 295 | */ |
296 | 296 | |
297 | - /** |
|
298 | - * Set the item qantity. |
|
299 | - * |
|
300 | - * @since 1.0.19 |
|
301 | - * @param int $quantity The item quantity. |
|
302 | - */ |
|
303 | - public function set_quantity( $quantity ) { |
|
304 | - |
|
305 | - if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
306 | - $quantity = 1; |
|
307 | - } |
|
308 | - |
|
309 | - $this->quantity = $quantity; |
|
310 | - |
|
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * Set the item meta data. |
|
315 | - * |
|
316 | - * @since 1.0.19 |
|
317 | - * @param array $meta The item meta data. |
|
318 | - */ |
|
319 | - public function set_item_meta( $meta ) { |
|
320 | - $this->meta = maybe_unserialize( $meta ); |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Set whether or not the quantities are allowed. |
|
325 | - * |
|
326 | - * @since 1.0.19 |
|
327 | - * @param bool $allow_quantities |
|
328 | - */ |
|
329 | - public function set_allow_quantities( $allow_quantities ) { |
|
330 | - $this->allow_quantities = (bool) $allow_quantities; |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Set whether or not the item is required. |
|
335 | - * |
|
336 | - * @since 1.0.19 |
|
337 | - * @param bool $is_required |
|
338 | - */ |
|
339 | - public function set_is_required( $is_required ) { |
|
340 | - $this->is_required = (bool) $is_required; |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Sets the custom item description. |
|
345 | - * |
|
346 | - * @since 1.0.19 |
|
347 | - * @param string $description |
|
348 | - */ |
|
349 | - public function set_custom_description( $description ) { |
|
350 | - $this->custom_description = $description; |
|
351 | - } |
|
297 | + /** |
|
298 | + * Set the item qantity. |
|
299 | + * |
|
300 | + * @since 1.0.19 |
|
301 | + * @param int $quantity The item quantity. |
|
302 | + */ |
|
303 | + public function set_quantity( $quantity ) { |
|
304 | + |
|
305 | + if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
306 | + $quantity = 1; |
|
307 | + } |
|
308 | + |
|
309 | + $this->quantity = $quantity; |
|
310 | + |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * Set the item meta data. |
|
315 | + * |
|
316 | + * @since 1.0.19 |
|
317 | + * @param array $meta The item meta data. |
|
318 | + */ |
|
319 | + public function set_item_meta( $meta ) { |
|
320 | + $this->meta = maybe_unserialize( $meta ); |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Set whether or not the quantities are allowed. |
|
325 | + * |
|
326 | + * @since 1.0.19 |
|
327 | + * @param bool $allow_quantities |
|
328 | + */ |
|
329 | + public function set_allow_quantities( $allow_quantities ) { |
|
330 | + $this->allow_quantities = (bool) $allow_quantities; |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Set whether or not the item is required. |
|
335 | + * |
|
336 | + * @since 1.0.19 |
|
337 | + * @param bool $is_required |
|
338 | + */ |
|
339 | + public function set_is_required( $is_required ) { |
|
340 | + $this->is_required = (bool) $is_required; |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * Sets the custom item description. |
|
345 | + * |
|
346 | + * @since 1.0.19 |
|
347 | + * @param string $description |
|
348 | + */ |
|
349 | + public function set_custom_description( $description ) { |
|
350 | + $this->custom_description = $description; |
|
351 | + } |
|
352 | 352 | |
353 | 353 | /** |
354 | 354 | * We do not want to save items to the database. |
355 | 355 | * |
356 | - * @return int item id |
|
356 | + * @return int item id |
|
357 | 357 | */ |
358 | 358 | public function save( $data = array() ) { |
359 | 359 | return $this->get_id(); |
360 | - } |
|
360 | + } |
|
361 | 361 | |
362 | 362 | /* |
363 | 363 | |-------------------------------------------------------------------------- |
@@ -369,23 +369,23 @@ discard block |
||
369 | 369 | */ |
370 | 370 | |
371 | 371 | /** |
372 | - * Checks whether the item has enabled dynamic pricing. |
|
373 | - * |
|
374 | - * @since 1.0.19 |
|
375 | - * @return bool |
|
376 | - */ |
|
377 | - public function is_required() { |
|
372 | + * Checks whether the item has enabled dynamic pricing. |
|
373 | + * |
|
374 | + * @since 1.0.19 |
|
375 | + * @return bool |
|
376 | + */ |
|
377 | + public function is_required() { |
|
378 | 378 | return (bool) $this->get_is_required(); |
379 | - } |
|
380 | - |
|
381 | - /** |
|
382 | - * Checks whether users can edit the quantities. |
|
383 | - * |
|
384 | - * @since 1.0.19 |
|
385 | - * @return bool |
|
386 | - */ |
|
387 | - public function allows_quantities() { |
|
379 | + } |
|
380 | + |
|
381 | + /** |
|
382 | + * Checks whether users can edit the quantities. |
|
383 | + * |
|
384 | + * @since 1.0.19 |
|
385 | + * @return bool |
|
386 | + */ |
|
387 | + public function allows_quantities() { |
|
388 | 388 | return (bool) $this->get_allow_quantities(); |
389 | - } |
|
389 | + } |
|
390 | 390 | |
391 | 391 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | * @param string $context View or edit context. |
88 | 88 | * @return string |
89 | 89 | */ |
90 | - public function get_name( $context = 'view' ) { |
|
91 | - $name = parent::get_name( $context ); |
|
92 | - return $name . wpinv_get_item_suffix( $this ); |
|
90 | + public function get_name($context = 'view') { |
|
91 | + $name = parent::get_name($context); |
|
92 | + return $name . wpinv_get_item_suffix($this); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | * @param string $context View or edit context. |
100 | 100 | * @return string |
101 | 101 | */ |
102 | - public function get_description( $context = 'view' ) { |
|
102 | + public function get_description($context = 'view') { |
|
103 | 103 | |
104 | - if ( ! empty( $this->custom_description ) ) { |
|
104 | + if (!empty($this->custom_description)) { |
|
105 | 105 | return $this->custom_description; |
106 | 106 | } |
107 | 107 | |
108 | - return parent::get_description( $context ); |
|
108 | + return parent::get_description($context); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | * @param string $context View or edit context. |
116 | 116 | * @return int |
117 | 117 | */ |
118 | - public function get_sub_total( $context = 'view' ) { |
|
119 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
118 | + public function get_sub_total($context = 'view') { |
|
119 | + return $this->get_quantity($context) * $this->get_initial_price($context); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -126,15 +126,15 @@ discard block |
||
126 | 126 | * @param string $context View or edit context. |
127 | 127 | * @return int |
128 | 128 | */ |
129 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
130 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
129 | + public function get_recurring_sub_total($context = 'view') { |
|
130 | + return $this->get_quantity($context) * $this->get_price($context); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
134 | 134 | * @deprecated |
135 | 135 | */ |
136 | - public function get_qantity( $context = 'view' ) { |
|
137 | - return $this->get_quantity( $context ); |
|
136 | + public function get_qantity($context = 'view') { |
|
137 | + return $this->get_quantity($context); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -144,15 +144,15 @@ discard block |
||
144 | 144 | * @param string $context View or edit context. |
145 | 145 | * @return int |
146 | 146 | */ |
147 | - public function get_quantity( $context = 'view' ) { |
|
147 | + public function get_quantity($context = 'view') { |
|
148 | 148 | $quantity = (int) $this->quantity; |
149 | 149 | |
150 | - if ( empty( $quantity ) || 1 > $quantity ) { |
|
150 | + if (empty($quantity) || 1 > $quantity) { |
|
151 | 151 | $quantity = 1; |
152 | 152 | } |
153 | 153 | |
154 | - if ( 'view' == $context ) { |
|
155 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
154 | + if ('view' == $context) { |
|
155 | + return apply_filters('getpaid_payment_form_item_quantity', $quantity, $this); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | return $quantity; |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | * @param string $context View or edit context. |
167 | 167 | * @return meta |
168 | 168 | */ |
169 | - public function get_item_meta( $context = 'view' ) { |
|
169 | + public function get_item_meta($context = 'view') { |
|
170 | 170 | $meta = $this->meta; |
171 | 171 | |
172 | - if ( 'view' == $context ) { |
|
173 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
172 | + if ('view' == $context) { |
|
173 | + return apply_filters('getpaid_payment_form_item_meta', $meta, $this); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | return $meta; |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | * @param string $context View or edit context. |
185 | 185 | * @return bool |
186 | 186 | */ |
187 | - public function get_allow_quantities( $context = 'view' ) { |
|
187 | + public function get_allow_quantities($context = 'view') { |
|
188 | 188 | $allow_quantities = (bool) $this->allow_quantities; |
189 | 189 | |
190 | - if ( 'view' == $context ) { |
|
191 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
190 | + if ('view' == $context) { |
|
191 | + return apply_filters('getpaid_payment_form_item_allow_quantities', $allow_quantities, $this); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | return $allow_quantities; |
@@ -202,11 +202,11 @@ discard block |
||
202 | 202 | * @param string $context View or edit context. |
203 | 203 | * @return bool |
204 | 204 | */ |
205 | - public function get_is_required( $context = 'view' ) { |
|
205 | + public function get_is_required($context = 'view') { |
|
206 | 206 | $is_required = (bool) $this->is_required; |
207 | 207 | |
208 | - if ( 'view' == $context ) { |
|
209 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
208 | + if ('view' == $context) { |
|
209 | + return apply_filters('getpaid_payment_form_item_is_required', $is_required, $this); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | return $is_required; |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | public function prepare_data_for_use() { |
223 | 223 | |
224 | 224 | return array( |
225 | - 'title' => sanitize_text_field( $this->get_name() ), |
|
225 | + 'title' => sanitize_text_field($this->get_name()), |
|
226 | 226 | 'id' => $this->get_id(), |
227 | 227 | 'price' => $this->get_price(), |
228 | 228 | 'recurring' => $this->is_recurring(), |
@@ -244,17 +244,17 @@ discard block |
||
244 | 244 | return array( |
245 | 245 | 'id' => $this->get_id(), |
246 | 246 | 'texts' => array( |
247 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
248 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
249 | - 'item-quantity' => absint( $this->get_quantity() ), |
|
250 | - 'item-price' => wpinv_price( wpinv_format_amount ( $this->get_price() ) ), |
|
251 | - 'item-total' => wpinv_price( wpinv_format_amount( $this->get_sub_total() ) ), |
|
247 | + 'item-name' => sanitize_text_field($this->get_name()), |
|
248 | + 'item-description' => wp_kses_post($this->get_description()), |
|
249 | + 'item-quantity' => absint($this->get_quantity()), |
|
250 | + 'item-price' => wpinv_price(wpinv_format_amount($this->get_price())), |
|
251 | + 'item-total' => wpinv_price(wpinv_format_amount($this->get_sub_total())), |
|
252 | 252 | ), |
253 | 253 | 'inputs' => array( |
254 | 254 | 'item-id' => $this->get_id(), |
255 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
256 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
257 | - 'item-quantity' => absint( $this->get_quantity() ), |
|
255 | + 'item-name' => sanitize_text_field($this->get_name()), |
|
256 | + 'item-description' => wp_kses_post($this->get_description()), |
|
257 | + 'item-quantity' => absint($this->get_quantity()), |
|
258 | 258 | 'item-price' => $this->get_price(), |
259 | 259 | ) |
260 | 260 | ); |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | return array( |
273 | 273 | 'post_id' => $this->invoice_id, |
274 | 274 | 'item_id' => $this->get_id(), |
275 | - 'item_name' => sanitize_text_field( $this->get_name() ), |
|
275 | + 'item_name' => sanitize_text_field($this->get_name()), |
|
276 | 276 | 'item_description' => $this->get_description(), |
277 | 277 | 'tax' => $this->item_tax, |
278 | 278 | 'item_price' => $this->get_price(), |
@@ -300,9 +300,9 @@ discard block |
||
300 | 300 | * @since 1.0.19 |
301 | 301 | * @param int $quantity The item quantity. |
302 | 302 | */ |
303 | - public function set_quantity( $quantity ) { |
|
303 | + public function set_quantity($quantity) { |
|
304 | 304 | |
305 | - if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
305 | + if (empty($quantity) || !is_numeric($quantity)) { |
|
306 | 306 | $quantity = 1; |
307 | 307 | } |
308 | 308 | |
@@ -316,8 +316,8 @@ discard block |
||
316 | 316 | * @since 1.0.19 |
317 | 317 | * @param array $meta The item meta data. |
318 | 318 | */ |
319 | - public function set_item_meta( $meta ) { |
|
320 | - $this->meta = maybe_unserialize( $meta ); |
|
319 | + public function set_item_meta($meta) { |
|
320 | + $this->meta = maybe_unserialize($meta); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | * @since 1.0.19 |
327 | 327 | * @param bool $allow_quantities |
328 | 328 | */ |
329 | - public function set_allow_quantities( $allow_quantities ) { |
|
329 | + public function set_allow_quantities($allow_quantities) { |
|
330 | 330 | $this->allow_quantities = (bool) $allow_quantities; |
331 | 331 | } |
332 | 332 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | * @since 1.0.19 |
337 | 337 | * @param bool $is_required |
338 | 338 | */ |
339 | - public function set_is_required( $is_required ) { |
|
339 | + public function set_is_required($is_required) { |
|
340 | 340 | $this->is_required = (bool) $is_required; |
341 | 341 | } |
342 | 342 | |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | * @since 1.0.19 |
347 | 347 | * @param string $description |
348 | 348 | */ |
349 | - public function set_custom_description( $description ) { |
|
349 | + public function set_custom_description($description) { |
|
350 | 350 | $this->custom_description = $description; |
351 | 351 | } |
352 | 352 | |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @return int item id |
357 | 357 | */ |
358 | - public function save( $data = array() ) { |
|
358 | + public function save($data = array()) { |
|
359 | 359 | return $this->get_id(); |
360 | 360 | } |
361 | 361 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -14,179 +14,179 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class GetPaid_Payment_Form_Data_Store extends GetPaid_Data_Store_WP { |
16 | 16 | |
17 | - /** |
|
18 | - * Data stored in meta keys, but not considered "meta" for a form. |
|
19 | - * |
|
20 | - * @since 1.0.19 |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $internal_meta_keys = array( |
|
24 | - 'wpinv_form_elements', |
|
25 | - 'wpinv_form_items', |
|
26 | - 'wpinv_form_earned', |
|
27 | - 'wpinv_form_refunded', |
|
28 | - 'wpinv_form_cancelled', |
|
29 | - 'wpinv_form_failed' |
|
30 | - ); |
|
31 | - |
|
32 | - /** |
|
33 | - * A map of meta keys to data props. |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $meta_key_to_props = array( |
|
40 | - 'wpinv_form_elements' => 'elements', |
|
41 | - 'wpinv_form_items' => 'items', |
|
42 | - 'wpinv_form_earned' => 'earned', |
|
43 | - 'wpinv_form_refunded' => 'refunded', |
|
44 | - 'wpinv_form_cancelled' => 'cancelled', |
|
45 | - 'wpinv_form_failed' => 'failed', |
|
46 | - ); |
|
47 | - |
|
48 | - /* |
|
17 | + /** |
|
18 | + * Data stored in meta keys, but not considered "meta" for a form. |
|
19 | + * |
|
20 | + * @since 1.0.19 |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $internal_meta_keys = array( |
|
24 | + 'wpinv_form_elements', |
|
25 | + 'wpinv_form_items', |
|
26 | + 'wpinv_form_earned', |
|
27 | + 'wpinv_form_refunded', |
|
28 | + 'wpinv_form_cancelled', |
|
29 | + 'wpinv_form_failed' |
|
30 | + ); |
|
31 | + |
|
32 | + /** |
|
33 | + * A map of meta keys to data props. |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $meta_key_to_props = array( |
|
40 | + 'wpinv_form_elements' => 'elements', |
|
41 | + 'wpinv_form_items' => 'items', |
|
42 | + 'wpinv_form_earned' => 'earned', |
|
43 | + 'wpinv_form_refunded' => 'refunded', |
|
44 | + 'wpinv_form_cancelled' => 'cancelled', |
|
45 | + 'wpinv_form_failed' => 'failed', |
|
46 | + ); |
|
47 | + |
|
48 | + /* |
|
49 | 49 | |-------------------------------------------------------------------------- |
50 | 50 | | CRUD Methods |
51 | 51 | |-------------------------------------------------------------------------- |
52 | 52 | */ |
53 | 53 | |
54 | - /** |
|
55 | - * Method to create a new form in the database. |
|
56 | - * |
|
57 | - * @param GetPaid_Payment_Form $form Form object. |
|
58 | - */ |
|
59 | - public function create( &$form ) { |
|
60 | - $form->set_version( WPINV_VERSION ); |
|
61 | - $form->set_date_created( current_time('mysql') ); |
|
62 | - |
|
63 | - // Create a new post. |
|
64 | - $id = wp_insert_post( |
|
65 | - apply_filters( |
|
66 | - 'getpaid_new_payment_form_data', |
|
67 | - array( |
|
68 | - 'post_date' => $form->get_date_created( 'edit' ), |
|
69 | - 'post_type' => 'wpi_payment_form', |
|
70 | - 'post_status' => $this->get_post_status( $form ), |
|
71 | - 'ping_status' => 'closed', |
|
72 | - 'post_author' => $form->get_author( 'edit' ), |
|
73 | - 'post_title' => $form->get_name( 'edit' ), |
|
74 | - ) |
|
75 | - ), |
|
76 | - true |
|
77 | - ); |
|
78 | - |
|
79 | - if ( $id && ! is_wp_error( $id ) ) { |
|
80 | - $form->set_id( $id ); |
|
81 | - $this->update_post_meta( $form ); |
|
82 | - $form->save_meta_data(); |
|
83 | - $form->apply_changes(); |
|
84 | - $this->clear_caches( $form ); |
|
85 | - do_action( 'getpaid_create_payment_form', $form->get_id(), $form ); |
|
86 | - return true; |
|
87 | - } |
|
88 | - |
|
89 | - if ( is_wp_error( $id ) ) { |
|
90 | - $form->last_error = $id->get_error_message(); |
|
91 | - } |
|
92 | - |
|
93 | - return false; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Method to read a form from the database. |
|
98 | - * |
|
99 | - * @param GetPaid_Payment_Form $form Form object. |
|
100 | - * |
|
101 | - */ |
|
102 | - public function read( &$form ) { |
|
103 | - |
|
104 | - $form->set_defaults(); |
|
105 | - $form_object = get_post( $form->get_id() ); |
|
106 | - |
|
107 | - if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) { |
|
108 | - $form->last_error = __( 'Invalid form.', 'invoicing' ); |
|
109 | - $form->set_id( 0 ); |
|
110 | - return false; |
|
111 | - } |
|
112 | - |
|
113 | - $form->set_props( |
|
114 | - array( |
|
115 | - 'date_created' => 0 < $form_object->post_date ? $form_object->post_date : null, |
|
116 | - 'date_modified' => 0 < $form_object->post_modified ? $form_object->post_modified : null, |
|
117 | - 'status' => $form_object->post_status, |
|
118 | - 'name' => $form_object->post_title, |
|
119 | - 'author' => $form_object->post_author, |
|
120 | - ) |
|
121 | - ); |
|
122 | - |
|
123 | - $this->read_object_data( $form, $form_object ); |
|
124 | - $form->read_meta_data(); |
|
125 | - $form->set_object_read( true ); |
|
126 | - do_action( 'getpaid_read_payment_form', $form->get_id(), $form ); |
|
127 | - |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Method to update a form in the database. |
|
132 | - * |
|
133 | - * @param GetPaid_Payment_Form $form Form object. |
|
134 | - */ |
|
135 | - public function update( &$form ) { |
|
136 | - $form->save_meta_data(); |
|
137 | - $form->set_version( WPINV_VERSION ); |
|
138 | - |
|
139 | - if ( null === $form->get_date_created( 'edit' ) ) { |
|
140 | - $form->set_date_created( current_time('mysql') ); |
|
141 | - } |
|
142 | - |
|
143 | - // Grab the current status so we can compare. |
|
144 | - $previous_status = get_post_status( $form->get_id() ); |
|
145 | - |
|
146 | - $changes = $form->get_changes(); |
|
147 | - |
|
148 | - // Only update the post when the post data changes. |
|
149 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
150 | - $post_data = array( |
|
151 | - 'post_date' => $form->get_date_created( 'edit' ), |
|
152 | - 'post_status' => $form->get_status( 'edit' ), |
|
153 | - 'post_title' => $form->get_name( 'edit' ), |
|
154 | - 'post_author' => $form->get_author( 'edit' ), |
|
155 | - 'post_modified' => $form->get_date_modified( 'edit' ), |
|
156 | - ); |
|
157 | - |
|
158 | - /** |
|
159 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
160 | - * to update data, since wp_update_post spawns more calls to the |
|
161 | - * save_post action. |
|
162 | - * |
|
163 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
164 | - * or an update purely from CRUD. |
|
165 | - */ |
|
166 | - if ( doing_action( 'save_post' ) ) { |
|
167 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) ); |
|
168 | - clean_post_cache( $form->get_id() ); |
|
169 | - } else { |
|
170 | - wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) ); |
|
171 | - } |
|
172 | - $form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
173 | - } |
|
174 | - $this->update_post_meta( $form ); |
|
175 | - $form->apply_changes(); |
|
176 | - $this->clear_caches( $form ); |
|
177 | - |
|
178 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
179 | - $new_status = $form->get_status( 'edit' ); |
|
180 | - |
|
181 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
182 | - do_action( 'getpaid_new_payment_form', $form->get_id(), $form ); |
|
183 | - } else { |
|
184 | - do_action( 'getpaid_update_payment_form', $form->get_id(), $form ); |
|
185 | - } |
|
186 | - |
|
187 | - } |
|
188 | - |
|
189 | - /* |
|
54 | + /** |
|
55 | + * Method to create a new form in the database. |
|
56 | + * |
|
57 | + * @param GetPaid_Payment_Form $form Form object. |
|
58 | + */ |
|
59 | + public function create( &$form ) { |
|
60 | + $form->set_version( WPINV_VERSION ); |
|
61 | + $form->set_date_created( current_time('mysql') ); |
|
62 | + |
|
63 | + // Create a new post. |
|
64 | + $id = wp_insert_post( |
|
65 | + apply_filters( |
|
66 | + 'getpaid_new_payment_form_data', |
|
67 | + array( |
|
68 | + 'post_date' => $form->get_date_created( 'edit' ), |
|
69 | + 'post_type' => 'wpi_payment_form', |
|
70 | + 'post_status' => $this->get_post_status( $form ), |
|
71 | + 'ping_status' => 'closed', |
|
72 | + 'post_author' => $form->get_author( 'edit' ), |
|
73 | + 'post_title' => $form->get_name( 'edit' ), |
|
74 | + ) |
|
75 | + ), |
|
76 | + true |
|
77 | + ); |
|
78 | + |
|
79 | + if ( $id && ! is_wp_error( $id ) ) { |
|
80 | + $form->set_id( $id ); |
|
81 | + $this->update_post_meta( $form ); |
|
82 | + $form->save_meta_data(); |
|
83 | + $form->apply_changes(); |
|
84 | + $this->clear_caches( $form ); |
|
85 | + do_action( 'getpaid_create_payment_form', $form->get_id(), $form ); |
|
86 | + return true; |
|
87 | + } |
|
88 | + |
|
89 | + if ( is_wp_error( $id ) ) { |
|
90 | + $form->last_error = $id->get_error_message(); |
|
91 | + } |
|
92 | + |
|
93 | + return false; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Method to read a form from the database. |
|
98 | + * |
|
99 | + * @param GetPaid_Payment_Form $form Form object. |
|
100 | + * |
|
101 | + */ |
|
102 | + public function read( &$form ) { |
|
103 | + |
|
104 | + $form->set_defaults(); |
|
105 | + $form_object = get_post( $form->get_id() ); |
|
106 | + |
|
107 | + if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) { |
|
108 | + $form->last_error = __( 'Invalid form.', 'invoicing' ); |
|
109 | + $form->set_id( 0 ); |
|
110 | + return false; |
|
111 | + } |
|
112 | + |
|
113 | + $form->set_props( |
|
114 | + array( |
|
115 | + 'date_created' => 0 < $form_object->post_date ? $form_object->post_date : null, |
|
116 | + 'date_modified' => 0 < $form_object->post_modified ? $form_object->post_modified : null, |
|
117 | + 'status' => $form_object->post_status, |
|
118 | + 'name' => $form_object->post_title, |
|
119 | + 'author' => $form_object->post_author, |
|
120 | + ) |
|
121 | + ); |
|
122 | + |
|
123 | + $this->read_object_data( $form, $form_object ); |
|
124 | + $form->read_meta_data(); |
|
125 | + $form->set_object_read( true ); |
|
126 | + do_action( 'getpaid_read_payment_form', $form->get_id(), $form ); |
|
127 | + |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Method to update a form in the database. |
|
132 | + * |
|
133 | + * @param GetPaid_Payment_Form $form Form object. |
|
134 | + */ |
|
135 | + public function update( &$form ) { |
|
136 | + $form->save_meta_data(); |
|
137 | + $form->set_version( WPINV_VERSION ); |
|
138 | + |
|
139 | + if ( null === $form->get_date_created( 'edit' ) ) { |
|
140 | + $form->set_date_created( current_time('mysql') ); |
|
141 | + } |
|
142 | + |
|
143 | + // Grab the current status so we can compare. |
|
144 | + $previous_status = get_post_status( $form->get_id() ); |
|
145 | + |
|
146 | + $changes = $form->get_changes(); |
|
147 | + |
|
148 | + // Only update the post when the post data changes. |
|
149 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
150 | + $post_data = array( |
|
151 | + 'post_date' => $form->get_date_created( 'edit' ), |
|
152 | + 'post_status' => $form->get_status( 'edit' ), |
|
153 | + 'post_title' => $form->get_name( 'edit' ), |
|
154 | + 'post_author' => $form->get_author( 'edit' ), |
|
155 | + 'post_modified' => $form->get_date_modified( 'edit' ), |
|
156 | + ); |
|
157 | + |
|
158 | + /** |
|
159 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
160 | + * to update data, since wp_update_post spawns more calls to the |
|
161 | + * save_post action. |
|
162 | + * |
|
163 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
164 | + * or an update purely from CRUD. |
|
165 | + */ |
|
166 | + if ( doing_action( 'save_post' ) ) { |
|
167 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) ); |
|
168 | + clean_post_cache( $form->get_id() ); |
|
169 | + } else { |
|
170 | + wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) ); |
|
171 | + } |
|
172 | + $form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
173 | + } |
|
174 | + $this->update_post_meta( $form ); |
|
175 | + $form->apply_changes(); |
|
176 | + $this->clear_caches( $form ); |
|
177 | + |
|
178 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
179 | + $new_status = $form->get_status( 'edit' ); |
|
180 | + |
|
181 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
182 | + do_action( 'getpaid_new_payment_form', $form->get_id(), $form ); |
|
183 | + } else { |
|
184 | + do_action( 'getpaid_update_payment_form', $form->get_id(), $form ); |
|
185 | + } |
|
186 | + |
|
187 | + } |
|
188 | + |
|
189 | + /* |
|
190 | 190 | |-------------------------------------------------------------------------- |
191 | 191 | | Additional Methods |
192 | 192 | |-------------------------------------------------------------------------- |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * GetPaid_Payment_Form_Data_Store class file. |
4 | 4 | * |
5 | 5 | */ |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -56,37 +56,37 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @param GetPaid_Payment_Form $form Form object. |
58 | 58 | */ |
59 | - public function create( &$form ) { |
|
60 | - $form->set_version( WPINV_VERSION ); |
|
61 | - $form->set_date_created( current_time('mysql') ); |
|
59 | + public function create(&$form) { |
|
60 | + $form->set_version(WPINV_VERSION); |
|
61 | + $form->set_date_created(current_time('mysql')); |
|
62 | 62 | |
63 | 63 | // Create a new post. |
64 | 64 | $id = wp_insert_post( |
65 | 65 | apply_filters( |
66 | 66 | 'getpaid_new_payment_form_data', |
67 | 67 | array( |
68 | - 'post_date' => $form->get_date_created( 'edit' ), |
|
68 | + 'post_date' => $form->get_date_created('edit'), |
|
69 | 69 | 'post_type' => 'wpi_payment_form', |
70 | - 'post_status' => $this->get_post_status( $form ), |
|
70 | + 'post_status' => $this->get_post_status($form), |
|
71 | 71 | 'ping_status' => 'closed', |
72 | - 'post_author' => $form->get_author( 'edit' ), |
|
73 | - 'post_title' => $form->get_name( 'edit' ), |
|
72 | + 'post_author' => $form->get_author('edit'), |
|
73 | + 'post_title' => $form->get_name('edit'), |
|
74 | 74 | ) |
75 | 75 | ), |
76 | 76 | true |
77 | 77 | ); |
78 | 78 | |
79 | - if ( $id && ! is_wp_error( $id ) ) { |
|
80 | - $form->set_id( $id ); |
|
81 | - $this->update_post_meta( $form ); |
|
79 | + if ($id && !is_wp_error($id)) { |
|
80 | + $form->set_id($id); |
|
81 | + $this->update_post_meta($form); |
|
82 | 82 | $form->save_meta_data(); |
83 | 83 | $form->apply_changes(); |
84 | - $this->clear_caches( $form ); |
|
85 | - do_action( 'getpaid_create_payment_form', $form->get_id(), $form ); |
|
84 | + $this->clear_caches($form); |
|
85 | + do_action('getpaid_create_payment_form', $form->get_id(), $form); |
|
86 | 86 | return true; |
87 | 87 | } |
88 | 88 | |
89 | - if ( is_wp_error( $id ) ) { |
|
89 | + if (is_wp_error($id)) { |
|
90 | 90 | $form->last_error = $id->get_error_message(); |
91 | 91 | } |
92 | 92 | |
@@ -99,14 +99,14 @@ discard block |
||
99 | 99 | * @param GetPaid_Payment_Form $form Form object. |
100 | 100 | * |
101 | 101 | */ |
102 | - public function read( &$form ) { |
|
102 | + public function read(&$form) { |
|
103 | 103 | |
104 | 104 | $form->set_defaults(); |
105 | - $form_object = get_post( $form->get_id() ); |
|
105 | + $form_object = get_post($form->get_id()); |
|
106 | 106 | |
107 | - if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) { |
|
108 | - $form->last_error = __( 'Invalid form.', 'invoicing' ); |
|
109 | - $form->set_id( 0 ); |
|
107 | + if (!$form->get_id() || !$form_object || $form_object->post_type != 'wpi_payment_form') { |
|
108 | + $form->last_error = __('Invalid form.', 'invoicing'); |
|
109 | + $form->set_id(0); |
|
110 | 110 | return false; |
111 | 111 | } |
112 | 112 | |
@@ -120,10 +120,10 @@ discard block |
||
120 | 120 | ) |
121 | 121 | ); |
122 | 122 | |
123 | - $this->read_object_data( $form, $form_object ); |
|
123 | + $this->read_object_data($form, $form_object); |
|
124 | 124 | $form->read_meta_data(); |
125 | - $form->set_object_read( true ); |
|
126 | - do_action( 'getpaid_read_payment_form', $form->get_id(), $form ); |
|
125 | + $form->set_object_read(true); |
|
126 | + do_action('getpaid_read_payment_form', $form->get_id(), $form); |
|
127 | 127 | |
128 | 128 | } |
129 | 129 | |
@@ -132,27 +132,27 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @param GetPaid_Payment_Form $form Form object. |
134 | 134 | */ |
135 | - public function update( &$form ) { |
|
135 | + public function update(&$form) { |
|
136 | 136 | $form->save_meta_data(); |
137 | - $form->set_version( WPINV_VERSION ); |
|
137 | + $form->set_version(WPINV_VERSION); |
|
138 | 138 | |
139 | - if ( null === $form->get_date_created( 'edit' ) ) { |
|
140 | - $form->set_date_created( current_time('mysql') ); |
|
139 | + if (null === $form->get_date_created('edit')) { |
|
140 | + $form->set_date_created(current_time('mysql')); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | // Grab the current status so we can compare. |
144 | - $previous_status = get_post_status( $form->get_id() ); |
|
144 | + $previous_status = get_post_status($form->get_id()); |
|
145 | 145 | |
146 | 146 | $changes = $form->get_changes(); |
147 | 147 | |
148 | 148 | // Only update the post when the post data changes. |
149 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
149 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author'), array_keys($changes))) { |
|
150 | 150 | $post_data = array( |
151 | - 'post_date' => $form->get_date_created( 'edit' ), |
|
152 | - 'post_status' => $form->get_status( 'edit' ), |
|
153 | - 'post_title' => $form->get_name( 'edit' ), |
|
154 | - 'post_author' => $form->get_author( 'edit' ), |
|
155 | - 'post_modified' => $form->get_date_modified( 'edit' ), |
|
151 | + 'post_date' => $form->get_date_created('edit'), |
|
152 | + 'post_status' => $form->get_status('edit'), |
|
153 | + 'post_title' => $form->get_name('edit'), |
|
154 | + 'post_author' => $form->get_author('edit'), |
|
155 | + 'post_modified' => $form->get_date_modified('edit'), |
|
156 | 156 | ); |
157 | 157 | |
158 | 158 | /** |
@@ -163,25 +163,25 @@ discard block |
||
163 | 163 | * This ensures hooks are fired by either WP itself (admin screen save), |
164 | 164 | * or an update purely from CRUD. |
165 | 165 | */ |
166 | - if ( doing_action( 'save_post' ) ) { |
|
167 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) ); |
|
168 | - clean_post_cache( $form->get_id() ); |
|
166 | + if (doing_action('save_post')) { |
|
167 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $form->get_id())); |
|
168 | + clean_post_cache($form->get_id()); |
|
169 | 169 | } else { |
170 | - wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) ); |
|
170 | + wp_update_post(array_merge(array('ID' => $form->get_id()), $post_data)); |
|
171 | 171 | } |
172 | - $form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
172 | + $form->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
173 | 173 | } |
174 | - $this->update_post_meta( $form ); |
|
174 | + $this->update_post_meta($form); |
|
175 | 175 | $form->apply_changes(); |
176 | - $this->clear_caches( $form ); |
|
176 | + $this->clear_caches($form); |
|
177 | 177 | |
178 | 178 | // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
179 | - $new_status = $form->get_status( 'edit' ); |
|
179 | + $new_status = $form->get_status('edit'); |
|
180 | 180 | |
181 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
182 | - do_action( 'getpaid_new_payment_form', $form->get_id(), $form ); |
|
181 | + if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) { |
|
182 | + do_action('getpaid_new_payment_form', $form->get_id(), $form); |
|
183 | 183 | } else { |
184 | - do_action( 'getpaid_update_payment_form', $form->get_id(), $form ); |
|
184 | + do_action('getpaid_update_payment_form', $form->get_id(), $form); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -15,196 +15,196 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Discount_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 | - '_wpi_discount_code', |
|
26 | - '_wpi_discount_amount', |
|
27 | - '_wpi_discount_start', |
|
28 | - '_wpi_discount_expiration', |
|
29 | - '_wpi_discount_type', |
|
30 | - '_wpi_discount_uses', |
|
31 | - '_wpi_discount_is_single_use', |
|
32 | - '_wpi_discount_items', |
|
33 | - '_wpi_discount_excluded_items', |
|
34 | - '_wpi_discount_max_uses', |
|
35 | - '_wpi_discount_is_recurring', |
|
36 | - '_wpi_discount_min_total', |
|
37 | - '_wpi_discount_max_total', |
|
38 | - ); |
|
39 | - |
|
40 | - /** |
|
41 | - * A map of meta keys to data props. |
|
42 | - * |
|
43 | - * @since 1.0.19 |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - protected $meta_key_to_props = array( |
|
48 | - '_wpi_discount_code' => 'code', |
|
49 | - '_wpi_discount_amount' => 'amount', |
|
50 | - '_wpi_discount_start' => 'start', |
|
51 | - '_wpi_discount_expiration' => 'expiration', |
|
52 | - '_wpi_discount_type' => 'type', |
|
53 | - '_wpi_discount_uses' => 'uses', |
|
54 | - '_wpi_discount_is_single_use' => 'is_single_use', |
|
55 | - '_wpi_discount_items' => 'items', |
|
56 | - '_wpi_discount_excluded_items' => 'excluded_items', |
|
57 | - '_wpi_discount_max_uses' => 'max_uses', |
|
58 | - '_wpi_discount_is_recurring' => 'is_recurring', |
|
59 | - '_wpi_discount_min_total' => 'min_total', |
|
60 | - '_wpi_discount_max_total' => 'max_total', |
|
61 | - ); |
|
62 | - |
|
63 | - /* |
|
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 | + '_wpi_discount_code', |
|
26 | + '_wpi_discount_amount', |
|
27 | + '_wpi_discount_start', |
|
28 | + '_wpi_discount_expiration', |
|
29 | + '_wpi_discount_type', |
|
30 | + '_wpi_discount_uses', |
|
31 | + '_wpi_discount_is_single_use', |
|
32 | + '_wpi_discount_items', |
|
33 | + '_wpi_discount_excluded_items', |
|
34 | + '_wpi_discount_max_uses', |
|
35 | + '_wpi_discount_is_recurring', |
|
36 | + '_wpi_discount_min_total', |
|
37 | + '_wpi_discount_max_total', |
|
38 | + ); |
|
39 | + |
|
40 | + /** |
|
41 | + * A map of meta keys to data props. |
|
42 | + * |
|
43 | + * @since 1.0.19 |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + protected $meta_key_to_props = array( |
|
48 | + '_wpi_discount_code' => 'code', |
|
49 | + '_wpi_discount_amount' => 'amount', |
|
50 | + '_wpi_discount_start' => 'start', |
|
51 | + '_wpi_discount_expiration' => 'expiration', |
|
52 | + '_wpi_discount_type' => 'type', |
|
53 | + '_wpi_discount_uses' => 'uses', |
|
54 | + '_wpi_discount_is_single_use' => 'is_single_use', |
|
55 | + '_wpi_discount_items' => 'items', |
|
56 | + '_wpi_discount_excluded_items' => 'excluded_items', |
|
57 | + '_wpi_discount_max_uses' => 'max_uses', |
|
58 | + '_wpi_discount_is_recurring' => 'is_recurring', |
|
59 | + '_wpi_discount_min_total' => 'min_total', |
|
60 | + '_wpi_discount_max_total' => 'max_total', |
|
61 | + ); |
|
62 | + |
|
63 | + /* |
|
64 | 64 | |-------------------------------------------------------------------------- |
65 | 65 | | CRUD Methods |
66 | 66 | |-------------------------------------------------------------------------- |
67 | 67 | */ |
68 | 68 | |
69 | - /** |
|
70 | - * Method to create a new discount in the database. |
|
71 | - * |
|
72 | - * @param WPInv_Discount $discount Discount object. |
|
73 | - */ |
|
74 | - public function create( &$discount ) { |
|
75 | - $discount->set_version( WPINV_VERSION ); |
|
76 | - $discount->set_date_created( current_time('mysql') ); |
|
77 | - |
|
78 | - // Create a new post. |
|
79 | - $id = wp_insert_post( |
|
80 | - apply_filters( |
|
81 | - 'getpaid_new_discount_data', |
|
82 | - array( |
|
83 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
84 | - 'post_type' => 'wpi_discount', |
|
85 | - 'post_status' => $this->get_post_status( $discount ), |
|
86 | - 'ping_status' => 'closed', |
|
87 | - 'post_author' => $discount->get_author( 'edit' ), |
|
88 | - 'post_title' => $discount->get_name( 'edit' ), |
|
89 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
90 | - ) |
|
91 | - ), |
|
92 | - true |
|
93 | - ); |
|
94 | - |
|
95 | - if ( $id && ! is_wp_error( $id ) ) { |
|
96 | - $discount->set_id( $id ); |
|
97 | - $this->update_post_meta( $discount ); |
|
98 | - $discount->save_meta_data(); |
|
99 | - $discount->apply_changes(); |
|
100 | - $this->clear_caches( $discount ); |
|
101 | - do_action( 'getpaid_new_discount', $discount->get_id(), $discount ); |
|
102 | - return true; |
|
103 | - } |
|
104 | - |
|
105 | - if ( is_wp_error( $id ) ) { |
|
106 | - $discount->last_error = $id->get_error_message(); |
|
107 | - } |
|
108 | - |
|
109 | - return false; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Method to read a discount from the database. |
|
114 | - * |
|
115 | - * @param WPInv_Discount $discount Discount object. |
|
116 | - * |
|
117 | - */ |
|
118 | - public function read( &$discount ) { |
|
119 | - |
|
120 | - $discount->set_defaults(); |
|
121 | - $discount_object = get_post( $discount->get_id() ); |
|
122 | - |
|
123 | - if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) { |
|
124 | - $discount->last_error = __( 'Invalid discount.', 'invoicing' ); |
|
125 | - $discount->set_id( 0 ); |
|
126 | - return false; |
|
127 | - } |
|
128 | - |
|
129 | - $discount->set_props( |
|
130 | - array( |
|
131 | - 'date_created' => 0 < $discount_object->post_date ? $discount_object->post_date : null, |
|
132 | - 'date_modified' => 0 < $discount_object->post_modified ? $discount_object->post_modified : null, |
|
133 | - 'status' => $discount_object->post_status, |
|
134 | - 'name' => $discount_object->post_title, |
|
135 | - 'author' => $discount_object->post_author, |
|
136 | - 'description' => $discount_object->post_excerpt, |
|
137 | - ) |
|
138 | - ); |
|
139 | - |
|
140 | - $this->read_object_data( $discount, $discount_object ); |
|
141 | - $discount->read_meta_data(); |
|
142 | - $discount->set_object_read( true ); |
|
143 | - do_action( 'getpaid_read_discount', $discount->get_id(), $discount ); |
|
144 | - |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Method to update a discount in the database. |
|
149 | - * |
|
150 | - * @param WPInv_Discount $discount Discount object. |
|
151 | - */ |
|
152 | - public function update( &$discount ) { |
|
153 | - $discount->save_meta_data(); |
|
154 | - $discount->set_version( WPINV_VERSION ); |
|
155 | - |
|
156 | - if ( null === $discount->get_date_created( 'edit' ) ) { |
|
157 | - $discount->set_date_created( current_time('mysql') ); |
|
158 | - } |
|
159 | - |
|
160 | - // Grab the current status so we can compare. |
|
161 | - $previous_status = get_post_status( $discount->get_id() ); |
|
162 | - |
|
163 | - $changes = $discount->get_changes(); |
|
164 | - |
|
165 | - // Only update the post when the post data changes. |
|
166 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) { |
|
167 | - $post_data = array( |
|
168 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
169 | - 'post_status' => $discount->get_status( 'edit' ), |
|
170 | - 'post_title' => $discount->get_name( 'edit' ), |
|
171 | - 'post_author' => $discount->get_author( 'edit' ), |
|
172 | - 'post_modified' => $discount->get_date_modified( 'edit' ), |
|
173 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
174 | - ); |
|
175 | - |
|
176 | - /** |
|
177 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
178 | - * to update data, since wp_update_post spawns more calls to the |
|
179 | - * save_post action. |
|
180 | - * |
|
181 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
182 | - * or an update purely from CRUD. |
|
183 | - */ |
|
184 | - if ( doing_action( 'save_post' ) ) { |
|
185 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) ); |
|
186 | - clean_post_cache( $discount->get_id() ); |
|
187 | - } else { |
|
188 | - wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) ); |
|
189 | - } |
|
190 | - $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
191 | - } |
|
192 | - $this->update_post_meta( $discount ); |
|
193 | - $discount->apply_changes(); |
|
194 | - $this->clear_caches( $discount ); |
|
195 | - |
|
196 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
197 | - $new_status = $discount->get_status( 'edit' ); |
|
198 | - |
|
199 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
200 | - do_action( 'getpaid_new_discount', $discount->get_id(), $discount ); |
|
201 | - } else { |
|
202 | - do_action( 'getpaid_update_discount', $discount->get_id(), $discount ); |
|
203 | - } |
|
204 | - |
|
205 | - } |
|
206 | - |
|
207 | - /* |
|
69 | + /** |
|
70 | + * Method to create a new discount in the database. |
|
71 | + * |
|
72 | + * @param WPInv_Discount $discount Discount object. |
|
73 | + */ |
|
74 | + public function create( &$discount ) { |
|
75 | + $discount->set_version( WPINV_VERSION ); |
|
76 | + $discount->set_date_created( current_time('mysql') ); |
|
77 | + |
|
78 | + // Create a new post. |
|
79 | + $id = wp_insert_post( |
|
80 | + apply_filters( |
|
81 | + 'getpaid_new_discount_data', |
|
82 | + array( |
|
83 | + 'post_date' => $discount->get_date_created( 'edit' ), |
|
84 | + 'post_type' => 'wpi_discount', |
|
85 | + 'post_status' => $this->get_post_status( $discount ), |
|
86 | + 'ping_status' => 'closed', |
|
87 | + 'post_author' => $discount->get_author( 'edit' ), |
|
88 | + 'post_title' => $discount->get_name( 'edit' ), |
|
89 | + 'post_excerpt' => $discount->get_description( 'edit' ), |
|
90 | + ) |
|
91 | + ), |
|
92 | + true |
|
93 | + ); |
|
94 | + |
|
95 | + if ( $id && ! is_wp_error( $id ) ) { |
|
96 | + $discount->set_id( $id ); |
|
97 | + $this->update_post_meta( $discount ); |
|
98 | + $discount->save_meta_data(); |
|
99 | + $discount->apply_changes(); |
|
100 | + $this->clear_caches( $discount ); |
|
101 | + do_action( 'getpaid_new_discount', $discount->get_id(), $discount ); |
|
102 | + return true; |
|
103 | + } |
|
104 | + |
|
105 | + if ( is_wp_error( $id ) ) { |
|
106 | + $discount->last_error = $id->get_error_message(); |
|
107 | + } |
|
108 | + |
|
109 | + return false; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Method to read a discount from the database. |
|
114 | + * |
|
115 | + * @param WPInv_Discount $discount Discount object. |
|
116 | + * |
|
117 | + */ |
|
118 | + public function read( &$discount ) { |
|
119 | + |
|
120 | + $discount->set_defaults(); |
|
121 | + $discount_object = get_post( $discount->get_id() ); |
|
122 | + |
|
123 | + if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) { |
|
124 | + $discount->last_error = __( 'Invalid discount.', 'invoicing' ); |
|
125 | + $discount->set_id( 0 ); |
|
126 | + return false; |
|
127 | + } |
|
128 | + |
|
129 | + $discount->set_props( |
|
130 | + array( |
|
131 | + 'date_created' => 0 < $discount_object->post_date ? $discount_object->post_date : null, |
|
132 | + 'date_modified' => 0 < $discount_object->post_modified ? $discount_object->post_modified : null, |
|
133 | + 'status' => $discount_object->post_status, |
|
134 | + 'name' => $discount_object->post_title, |
|
135 | + 'author' => $discount_object->post_author, |
|
136 | + 'description' => $discount_object->post_excerpt, |
|
137 | + ) |
|
138 | + ); |
|
139 | + |
|
140 | + $this->read_object_data( $discount, $discount_object ); |
|
141 | + $discount->read_meta_data(); |
|
142 | + $discount->set_object_read( true ); |
|
143 | + do_action( 'getpaid_read_discount', $discount->get_id(), $discount ); |
|
144 | + |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Method to update a discount in the database. |
|
149 | + * |
|
150 | + * @param WPInv_Discount $discount Discount object. |
|
151 | + */ |
|
152 | + public function update( &$discount ) { |
|
153 | + $discount->save_meta_data(); |
|
154 | + $discount->set_version( WPINV_VERSION ); |
|
155 | + |
|
156 | + if ( null === $discount->get_date_created( 'edit' ) ) { |
|
157 | + $discount->set_date_created( current_time('mysql') ); |
|
158 | + } |
|
159 | + |
|
160 | + // Grab the current status so we can compare. |
|
161 | + $previous_status = get_post_status( $discount->get_id() ); |
|
162 | + |
|
163 | + $changes = $discount->get_changes(); |
|
164 | + |
|
165 | + // Only update the post when the post data changes. |
|
166 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) { |
|
167 | + $post_data = array( |
|
168 | + 'post_date' => $discount->get_date_created( 'edit' ), |
|
169 | + 'post_status' => $discount->get_status( 'edit' ), |
|
170 | + 'post_title' => $discount->get_name( 'edit' ), |
|
171 | + 'post_author' => $discount->get_author( 'edit' ), |
|
172 | + 'post_modified' => $discount->get_date_modified( 'edit' ), |
|
173 | + 'post_excerpt' => $discount->get_description( 'edit' ), |
|
174 | + ); |
|
175 | + |
|
176 | + /** |
|
177 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
178 | + * to update data, since wp_update_post spawns more calls to the |
|
179 | + * save_post action. |
|
180 | + * |
|
181 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
182 | + * or an update purely from CRUD. |
|
183 | + */ |
|
184 | + if ( doing_action( 'save_post' ) ) { |
|
185 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) ); |
|
186 | + clean_post_cache( $discount->get_id() ); |
|
187 | + } else { |
|
188 | + wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) ); |
|
189 | + } |
|
190 | + $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
191 | + } |
|
192 | + $this->update_post_meta( $discount ); |
|
193 | + $discount->apply_changes(); |
|
194 | + $this->clear_caches( $discount ); |
|
195 | + |
|
196 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
197 | + $new_status = $discount->get_status( 'edit' ); |
|
198 | + |
|
199 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
200 | + do_action( 'getpaid_new_discount', $discount->get_id(), $discount ); |
|
201 | + } else { |
|
202 | + do_action( 'getpaid_update_discount', $discount->get_id(), $discount ); |
|
203 | + } |
|
204 | + |
|
205 | + } |
|
206 | + |
|
207 | + /* |
|
208 | 208 | |-------------------------------------------------------------------------- |
209 | 209 | | Additional Methods |
210 | 210 | |-------------------------------------------------------------------------- |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * GetPaid_Discount_Data_Store class file. |
5 | 5 | * |
6 | 6 | */ |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if (!defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -71,38 +71,38 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @param WPInv_Discount $discount Discount object. |
73 | 73 | */ |
74 | - public function create( &$discount ) { |
|
75 | - $discount->set_version( WPINV_VERSION ); |
|
76 | - $discount->set_date_created( current_time('mysql') ); |
|
74 | + public function create(&$discount) { |
|
75 | + $discount->set_version(WPINV_VERSION); |
|
76 | + $discount->set_date_created(current_time('mysql')); |
|
77 | 77 | |
78 | 78 | // Create a new post. |
79 | 79 | $id = wp_insert_post( |
80 | 80 | apply_filters( |
81 | 81 | 'getpaid_new_discount_data', |
82 | 82 | array( |
83 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
83 | + 'post_date' => $discount->get_date_created('edit'), |
|
84 | 84 | 'post_type' => 'wpi_discount', |
85 | - 'post_status' => $this->get_post_status( $discount ), |
|
85 | + 'post_status' => $this->get_post_status($discount), |
|
86 | 86 | 'ping_status' => 'closed', |
87 | - 'post_author' => $discount->get_author( 'edit' ), |
|
88 | - 'post_title' => $discount->get_name( 'edit' ), |
|
89 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
87 | + 'post_author' => $discount->get_author('edit'), |
|
88 | + 'post_title' => $discount->get_name('edit'), |
|
89 | + 'post_excerpt' => $discount->get_description('edit'), |
|
90 | 90 | ) |
91 | 91 | ), |
92 | 92 | true |
93 | 93 | ); |
94 | 94 | |
95 | - if ( $id && ! is_wp_error( $id ) ) { |
|
96 | - $discount->set_id( $id ); |
|
97 | - $this->update_post_meta( $discount ); |
|
95 | + if ($id && !is_wp_error($id)) { |
|
96 | + $discount->set_id($id); |
|
97 | + $this->update_post_meta($discount); |
|
98 | 98 | $discount->save_meta_data(); |
99 | 99 | $discount->apply_changes(); |
100 | - $this->clear_caches( $discount ); |
|
101 | - do_action( 'getpaid_new_discount', $discount->get_id(), $discount ); |
|
100 | + $this->clear_caches($discount); |
|
101 | + do_action('getpaid_new_discount', $discount->get_id(), $discount); |
|
102 | 102 | return true; |
103 | 103 | } |
104 | 104 | |
105 | - if ( is_wp_error( $id ) ) { |
|
105 | + if (is_wp_error($id)) { |
|
106 | 106 | $discount->last_error = $id->get_error_message(); |
107 | 107 | } |
108 | 108 | |
@@ -115,14 +115,14 @@ discard block |
||
115 | 115 | * @param WPInv_Discount $discount Discount object. |
116 | 116 | * |
117 | 117 | */ |
118 | - public function read( &$discount ) { |
|
118 | + public function read(&$discount) { |
|
119 | 119 | |
120 | 120 | $discount->set_defaults(); |
121 | - $discount_object = get_post( $discount->get_id() ); |
|
121 | + $discount_object = get_post($discount->get_id()); |
|
122 | 122 | |
123 | - if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) { |
|
124 | - $discount->last_error = __( 'Invalid discount.', 'invoicing' ); |
|
125 | - $discount->set_id( 0 ); |
|
123 | + if (!$discount->get_id() || !$discount_object || $discount_object->post_type != 'wpi_discount') { |
|
124 | + $discount->last_error = __('Invalid discount.', 'invoicing'); |
|
125 | + $discount->set_id(0); |
|
126 | 126 | return false; |
127 | 127 | } |
128 | 128 | |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | ) |
138 | 138 | ); |
139 | 139 | |
140 | - $this->read_object_data( $discount, $discount_object ); |
|
140 | + $this->read_object_data($discount, $discount_object); |
|
141 | 141 | $discount->read_meta_data(); |
142 | - $discount->set_object_read( true ); |
|
143 | - do_action( 'getpaid_read_discount', $discount->get_id(), $discount ); |
|
142 | + $discount->set_object_read(true); |
|
143 | + do_action('getpaid_read_discount', $discount->get_id(), $discount); |
|
144 | 144 | |
145 | 145 | } |
146 | 146 | |
@@ -149,28 +149,28 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @param WPInv_Discount $discount Discount object. |
151 | 151 | */ |
152 | - public function update( &$discount ) { |
|
152 | + public function update(&$discount) { |
|
153 | 153 | $discount->save_meta_data(); |
154 | - $discount->set_version( WPINV_VERSION ); |
|
154 | + $discount->set_version(WPINV_VERSION); |
|
155 | 155 | |
156 | - if ( null === $discount->get_date_created( 'edit' ) ) { |
|
157 | - $discount->set_date_created( current_time('mysql') ); |
|
156 | + if (null === $discount->get_date_created('edit')) { |
|
157 | + $discount->set_date_created(current_time('mysql')); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | // Grab the current status so we can compare. |
161 | - $previous_status = get_post_status( $discount->get_id() ); |
|
161 | + $previous_status = get_post_status($discount->get_id()); |
|
162 | 162 | |
163 | 163 | $changes = $discount->get_changes(); |
164 | 164 | |
165 | 165 | // Only update the post when the post data changes. |
166 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) { |
|
166 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt'), array_keys($changes))) { |
|
167 | 167 | $post_data = array( |
168 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
169 | - 'post_status' => $discount->get_status( 'edit' ), |
|
170 | - 'post_title' => $discount->get_name( 'edit' ), |
|
171 | - 'post_author' => $discount->get_author( 'edit' ), |
|
172 | - 'post_modified' => $discount->get_date_modified( 'edit' ), |
|
173 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
168 | + 'post_date' => $discount->get_date_created('edit'), |
|
169 | + 'post_status' => $discount->get_status('edit'), |
|
170 | + 'post_title' => $discount->get_name('edit'), |
|
171 | + 'post_author' => $discount->get_author('edit'), |
|
172 | + 'post_modified' => $discount->get_date_modified('edit'), |
|
173 | + 'post_excerpt' => $discount->get_description('edit'), |
|
174 | 174 | ); |
175 | 175 | |
176 | 176 | /** |
@@ -181,25 +181,25 @@ discard block |
||
181 | 181 | * This ensures hooks are fired by either WP itself (admin screen save), |
182 | 182 | * or an update purely from CRUD. |
183 | 183 | */ |
184 | - if ( doing_action( 'save_post' ) ) { |
|
185 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) ); |
|
186 | - clean_post_cache( $discount->get_id() ); |
|
184 | + if (doing_action('save_post')) { |
|
185 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $discount->get_id())); |
|
186 | + clean_post_cache($discount->get_id()); |
|
187 | 187 | } else { |
188 | - wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) ); |
|
188 | + wp_update_post(array_merge(array('ID' => $discount->get_id()), $post_data)); |
|
189 | 189 | } |
190 | - $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
190 | + $discount->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
191 | 191 | } |
192 | - $this->update_post_meta( $discount ); |
|
192 | + $this->update_post_meta($discount); |
|
193 | 193 | $discount->apply_changes(); |
194 | - $this->clear_caches( $discount ); |
|
194 | + $this->clear_caches($discount); |
|
195 | 195 | |
196 | 196 | // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
197 | - $new_status = $discount->get_status( 'edit' ); |
|
197 | + $new_status = $discount->get_status('edit'); |
|
198 | 198 | |
199 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
200 | - do_action( 'getpaid_new_discount', $discount->get_id(), $discount ); |
|
199 | + if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) { |
|
200 | + do_action('getpaid_new_discount', $discount->get_id(), $discount); |
|
201 | 201 | } else { |
202 | - do_action( 'getpaid_update_discount', $discount->get_id(), $discount ); |
|
202 | + do_action('getpaid_update_discount', $discount->get_id(), $discount); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | } |
@@ -9,7 +9,7 @@ discard block |
||
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 |
||
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 $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 | - try { |
|
141 | - $this->__construct( absint( $this->id ) ); |
|
142 | - } catch ( Exception $e ) { |
|
143 | - $this->set_id( 0 ); |
|
144 | - $this->set_object_read( true ); |
|
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 ) { |
|
215 | - $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
216 | - $this->set_id( 0 ); |
|
217 | - return true; |
|
218 | - } |
|
219 | - return false; |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Save should create or update based on object existence. |
|
224 | - * |
|
225 | - * @since 1.0.19 |
|
226 | - * @return int |
|
227 | - */ |
|
228 | - public function save() { |
|
229 | - if ( ! $this->data_store ) { |
|
230 | - return $this->get_id(); |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Trigger action before saving to the DB. Allows you to adjust object props before save. |
|
235 | - * |
|
236 | - * @param GetPaid_Data $this The object being saved. |
|
237 | - * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
238 | - */ |
|
239 | - do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
240 | - |
|
241 | - if ( $this->get_id() ) { |
|
242 | - $this->data_store->update( $this ); |
|
243 | - } else { |
|
244 | - $this->data_store->create( $this ); |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Trigger action after saving to the DB. |
|
249 | - * |
|
250 | - * @param GetPaid_Data $this The object being saved. |
|
251 | - * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
252 | - */ |
|
253 | - do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
254 | - |
|
255 | - return $this->get_id(); |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Change data to JSON format. |
|
260 | - * |
|
261 | - * @since 1.0.19 |
|
262 | - * @return string Data in JSON format. |
|
263 | - */ |
|
264 | - public function __toString() { |
|
265 | - return wp_json_encode( $this->get_data() ); |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * Returns all data for this object. |
|
270 | - * |
|
271 | - * @since 1.0.19 |
|
272 | - * @return array |
|
273 | - */ |
|
274 | - public function get_data() { |
|
275 | - return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Returns array of expected data keys for this object. |
|
280 | - * |
|
281 | - * @since 1.0.19 |
|
282 | - * @return array |
|
283 | - */ |
|
284 | - public function get_data_keys() { |
|
285 | - return array_keys( $this->data ); |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Returns all "extra" data keys for an object (for sub objects like item types). |
|
290 | - * |
|
291 | - * @since 1.0.19 |
|
292 | - * @return array |
|
293 | - */ |
|
294 | - public function get_extra_data_keys() { |
|
295 | - return array_keys( $this->extra_data ); |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Filter null meta values from array. |
|
300 | - * |
|
301 | - * @since 1.0.19 |
|
302 | - * @param mixed $meta Meta value to check. |
|
303 | - * @return bool |
|
304 | - */ |
|
305 | - protected function filter_null_meta( $meta ) { |
|
306 | - return ! is_null( $meta->value ); |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * Get All Meta Data. |
|
311 | - * |
|
312 | - * @since 1.0.19 |
|
313 | - * @return array of objects. |
|
314 | - */ |
|
315 | - public function get_meta_data() { |
|
316 | - $this->maybe_read_meta_data(); |
|
317 | - return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * Check if the key is an internal one. |
|
322 | - * |
|
323 | - * @since 1.0.19 |
|
324 | - * @param string $key Key to check. |
|
325 | - * @return bool true if it's an internal key, false otherwise |
|
326 | - */ |
|
327 | - protected function is_internal_meta_key( $key ) { |
|
328 | - $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
329 | - |
|
330 | - if ( ! $internal_meta_key ) { |
|
331 | - return false; |
|
332 | - } |
|
333 | - |
|
334 | - $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
335 | - |
|
336 | - if ( ! $has_setter_or_getter ) { |
|
337 | - return false; |
|
338 | - } |
|
339 | - |
|
340 | - /* translators: %s: $key Key to check */ |
|
341 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
342 | - |
|
343 | - return true; |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Magic method for setting data fields. |
|
348 | - * |
|
349 | - * This method does not update custom fields in the database. |
|
350 | - * |
|
351 | - * @since 1.0.19 |
|
352 | - * @access public |
|
353 | - * |
|
354 | - */ |
|
355 | - public function __set( $key, $value ) { |
|
356 | - |
|
357 | - if ( 'id' == strtolower( $key ) ) { |
|
358 | - return $this->set_id( $value ); |
|
359 | - } |
|
360 | - |
|
361 | - if ( method_exists( $this, "set_$key") ) { |
|
362 | - |
|
363 | - /* translators: %s: $key Key to set */ |
|
364 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
365 | - |
|
366 | - call_user_func( array( $this, "set_$key" ), $value ); |
|
367 | - } else { |
|
368 | - $this->set_prop( $key, $value ); |
|
369 | - } |
|
370 | - |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
24 | + /** |
|
25 | + * ID for this object. |
|
26 | + * |
|
27 | + * @since 1.0.19 |
|
28 | + * @var int |
|
29 | + */ |
|
30 | + protected $id = 0; |
|
31 | + |
|
32 | + /** |
|
33 | + * Core data for this object. Name value pairs (name + default value). |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $data = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * Core data changes for this object. |
|
42 | + * |
|
43 | + * @since 1.0.19 |
|
44 | + * @var array |
|
45 | + */ |
|
46 | + protected $changes = array(); |
|
47 | + |
|
48 | + /** |
|
49 | + * This is false until the object is read from the DB. |
|
50 | + * |
|
51 | + * @since 1.0.19 |
|
52 | + * @var bool |
|
53 | + */ |
|
54 | + protected $object_read = false; |
|
55 | + |
|
56 | + /** |
|
57 | + * This is the name of this object type. |
|
58 | + * |
|
59 | + * @since 1.0.19 |
|
60 | + * @var string |
|
61 | + */ |
|
62 | + protected $object_type = 'data'; |
|
63 | + |
|
64 | + /** |
|
65 | + * Extra data for this object. Name value pairs (name + default value). |
|
66 | + * Used as a standard way for sub classes (like item types) to add |
|
67 | + * additional information to an inherited class. |
|
68 | + * |
|
69 | + * @since 1.0.19 |
|
70 | + * @var array |
|
71 | + */ |
|
72 | + protected $extra_data = array(); |
|
73 | + |
|
74 | + /** |
|
75 | + * Set to _data on construct so we can track and reset data if needed. |
|
76 | + * |
|
77 | + * @since 1.0.19 |
|
78 | + * @var array |
|
79 | + */ |
|
80 | + protected $default_data = array(); |
|
81 | + |
|
82 | + /** |
|
83 | + * Contains a reference to the data store for this class. |
|
84 | + * |
|
85 | + * @since 1.0.19 |
|
86 | + * @var GetPaid_Data_Store |
|
87 | + */ |
|
88 | + protected $data_store; |
|
89 | + |
|
90 | + /** |
|
91 | + * Stores meta in cache for future reads. |
|
92 | + * A group must be set to to enable caching. |
|
93 | + * |
|
94 | + * @since 1.0.19 |
|
95 | + * @var string |
|
96 | + */ |
|
97 | + protected $cache_group = ''; |
|
98 | + |
|
99 | + /** |
|
100 | + * Stores the last error. |
|
101 | + * |
|
102 | + * @since 1.0.19 |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + public $last_error = ''; |
|
106 | + |
|
107 | + /** |
|
108 | + * Stores additional meta data. |
|
109 | + * |
|
110 | + * @since 1.0.19 |
|
111 | + * @var array |
|
112 | + */ |
|
113 | + protected $meta_data = null; |
|
114 | + |
|
115 | + /** |
|
116 | + * Default constructor. |
|
117 | + * |
|
118 | + * @param int|object|array $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 | + try { |
|
141 | + $this->__construct( absint( $this->id ) ); |
|
142 | + } catch ( Exception $e ) { |
|
143 | + $this->set_id( 0 ); |
|
144 | + $this->set_object_read( true ); |
|
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 ) { |
|
215 | + $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
216 | + $this->set_id( 0 ); |
|
217 | + return true; |
|
218 | + } |
|
219 | + return false; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Save should create or update based on object existence. |
|
224 | + * |
|
225 | + * @since 1.0.19 |
|
226 | + * @return int |
|
227 | + */ |
|
228 | + public function save() { |
|
229 | + if ( ! $this->data_store ) { |
|
230 | + return $this->get_id(); |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Trigger action before saving to the DB. Allows you to adjust object props before save. |
|
235 | + * |
|
236 | + * @param GetPaid_Data $this The object being saved. |
|
237 | + * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
238 | + */ |
|
239 | + do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
240 | + |
|
241 | + if ( $this->get_id() ) { |
|
242 | + $this->data_store->update( $this ); |
|
243 | + } else { |
|
244 | + $this->data_store->create( $this ); |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Trigger action after saving to the DB. |
|
249 | + * |
|
250 | + * @param GetPaid_Data $this The object being saved. |
|
251 | + * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
252 | + */ |
|
253 | + do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
254 | + |
|
255 | + return $this->get_id(); |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Change data to JSON format. |
|
260 | + * |
|
261 | + * @since 1.0.19 |
|
262 | + * @return string Data in JSON format. |
|
263 | + */ |
|
264 | + public function __toString() { |
|
265 | + return wp_json_encode( $this->get_data() ); |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * Returns all data for this object. |
|
270 | + * |
|
271 | + * @since 1.0.19 |
|
272 | + * @return array |
|
273 | + */ |
|
274 | + public function get_data() { |
|
275 | + return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Returns array of expected data keys for this object. |
|
280 | + * |
|
281 | + * @since 1.0.19 |
|
282 | + * @return array |
|
283 | + */ |
|
284 | + public function get_data_keys() { |
|
285 | + return array_keys( $this->data ); |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Returns all "extra" data keys for an object (for sub objects like item types). |
|
290 | + * |
|
291 | + * @since 1.0.19 |
|
292 | + * @return array |
|
293 | + */ |
|
294 | + public function get_extra_data_keys() { |
|
295 | + return array_keys( $this->extra_data ); |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Filter null meta values from array. |
|
300 | + * |
|
301 | + * @since 1.0.19 |
|
302 | + * @param mixed $meta Meta value to check. |
|
303 | + * @return bool |
|
304 | + */ |
|
305 | + protected function filter_null_meta( $meta ) { |
|
306 | + return ! is_null( $meta->value ); |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * Get All Meta Data. |
|
311 | + * |
|
312 | + * @since 1.0.19 |
|
313 | + * @return array of objects. |
|
314 | + */ |
|
315 | + public function get_meta_data() { |
|
316 | + $this->maybe_read_meta_data(); |
|
317 | + return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * Check if the key is an internal one. |
|
322 | + * |
|
323 | + * @since 1.0.19 |
|
324 | + * @param string $key Key to check. |
|
325 | + * @return bool true if it's an internal key, false otherwise |
|
326 | + */ |
|
327 | + protected function is_internal_meta_key( $key ) { |
|
328 | + $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
329 | + |
|
330 | + if ( ! $internal_meta_key ) { |
|
331 | + return false; |
|
332 | + } |
|
333 | + |
|
334 | + $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
335 | + |
|
336 | + if ( ! $has_setter_or_getter ) { |
|
337 | + return false; |
|
338 | + } |
|
339 | + |
|
340 | + /* translators: %s: $key Key to check */ |
|
341 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
342 | + |
|
343 | + return true; |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Magic method for setting data fields. |
|
348 | + * |
|
349 | + * This method does not update custom fields in the database. |
|
350 | + * |
|
351 | + * @since 1.0.19 |
|
352 | + * @access public |
|
353 | + * |
|
354 | + */ |
|
355 | + public function __set( $key, $value ) { |
|
356 | + |
|
357 | + if ( 'id' == strtolower( $key ) ) { |
|
358 | + return $this->set_id( $value ); |
|
359 | + } |
|
360 | + |
|
361 | + if ( method_exists( $this, "set_$key") ) { |
|
362 | + |
|
363 | + /* translators: %s: $key Key to set */ |
|
364 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
365 | + |
|
366 | + call_user_func( array( $this, "set_$key" ), $value ); |
|
367 | + } else { |
|
368 | + $this->set_prop( $key, $value ); |
|
369 | + } |
|
370 | + |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | 374 | * Margic method for retrieving a property. |
375 | 375 | */ |
376 | 376 | public function __get( $key ) { |
@@ -378,10 +378,10 @@ discard block |
||
378 | 378 | // Check if we have a helper method for that. |
379 | 379 | if ( method_exists( $this, 'get_' . $key ) ) { |
380 | 380 | |
381 | - if ( 'post_type' != $key ) { |
|
382 | - /* translators: %s: $key Key to set */ |
|
383 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
384 | - } |
|
381 | + if ( 'post_type' != $key ) { |
|
382 | + /* translators: %s: $key Key to set */ |
|
383 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
384 | + } |
|
385 | 385 | |
386 | 386 | return call_user_func( array( $this, 'get_' . $key ) ); |
387 | 387 | } |
@@ -391,497 +391,497 @@ discard block |
||
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 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
411 | - $function = 'get_' . $key; |
|
412 | - |
|
413 | - if ( is_callable( array( $this, $function ) ) ) { |
|
414 | - return $this->{$function}(); |
|
415 | - } |
|
416 | - } |
|
417 | - |
|
418 | - // Read the meta data if not yet read. |
|
419 | - $this->maybe_read_meta_data(); |
|
420 | - $meta_data = $this->get_meta_data(); |
|
421 | - $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
422 | - $value = $single ? '' : array(); |
|
423 | - |
|
424 | - if ( ! empty( $array_keys ) ) { |
|
425 | - // 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()). |
|
426 | - if ( $single ) { |
|
427 | - $value = $meta_data[ current( $array_keys ) ]->value; |
|
428 | - } else { |
|
429 | - $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
430 | - } |
|
431 | - } |
|
432 | - |
|
433 | - if ( 'view' === $context ) { |
|
434 | - $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
435 | - } |
|
436 | - |
|
437 | - return $value; |
|
438 | - } |
|
439 | - |
|
440 | - /** |
|
441 | - * See if meta data exists, since get_meta always returns a '' or array(). |
|
442 | - * |
|
443 | - * @since 1.0.19 |
|
444 | - * @param string $key Meta Key. |
|
445 | - * @return boolean |
|
446 | - */ |
|
447 | - public function meta_exists( $key = '' ) { |
|
448 | - $this->maybe_read_meta_data(); |
|
449 | - $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
450 | - return in_array( $key, $array_keys, true ); |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * Set all meta data from array. |
|
455 | - * |
|
456 | - * @since 1.0.19 |
|
457 | - * @param array $data Key/Value pairs. |
|
458 | - */ |
|
459 | - public function set_meta_data( $data ) { |
|
460 | - if ( ! empty( $data ) && is_array( $data ) ) { |
|
461 | - $this->maybe_read_meta_data(); |
|
462 | - foreach ( $data as $meta ) { |
|
463 | - $meta = (array) $meta; |
|
464 | - if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
465 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
466 | - array( |
|
467 | - 'id' => $meta['id'], |
|
468 | - 'key' => $meta['key'], |
|
469 | - 'value' => $meta['value'], |
|
470 | - ) |
|
471 | - ); |
|
472 | - } |
|
473 | - } |
|
474 | - } |
|
475 | - } |
|
476 | - |
|
477 | - /** |
|
478 | - * Add meta data. |
|
479 | - * |
|
480 | - * @since 1.0.19 |
|
481 | - * |
|
482 | - * @param string $key Meta key. |
|
483 | - * @param string|array $value Meta value. |
|
484 | - * @param bool $unique Should this be a unique key?. |
|
485 | - */ |
|
486 | - public function add_meta_data( $key, $value, $unique = false ) { |
|
487 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
488 | - $function = 'set_' . $key; |
|
489 | - |
|
490 | - if ( is_callable( array( $this, $function ) ) ) { |
|
491 | - return $this->{$function}( $value ); |
|
492 | - } |
|
493 | - } |
|
494 | - |
|
495 | - $this->maybe_read_meta_data(); |
|
496 | - if ( $unique ) { |
|
497 | - $this->delete_meta_data( $key ); |
|
498 | - } |
|
499 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
500 | - array( |
|
501 | - 'key' => $key, |
|
502 | - 'value' => $value, |
|
503 | - ) |
|
504 | - ); |
|
505 | - } |
|
506 | - |
|
507 | - /** |
|
508 | - * Update meta data by key or ID, if provided. |
|
509 | - * |
|
510 | - * @since 1.0.19 |
|
511 | - * |
|
512 | - * @param string $key Meta key. |
|
513 | - * @param string|array $value Meta value. |
|
514 | - * @param int $meta_id Meta ID. |
|
515 | - */ |
|
516 | - public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
517 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
518 | - $function = 'set_' . $key; |
|
519 | - |
|
520 | - if ( is_callable( array( $this, $function ) ) ) { |
|
521 | - return $this->{$function}( $value ); |
|
522 | - } |
|
523 | - } |
|
524 | - |
|
525 | - $this->maybe_read_meta_data(); |
|
526 | - |
|
527 | - $array_key = false; |
|
528 | - |
|
529 | - if ( $meta_id ) { |
|
530 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
531 | - $array_key = $array_keys ? current( $array_keys ) : false; |
|
532 | - } else { |
|
533 | - // Find matches by key. |
|
534 | - $matches = array(); |
|
535 | - foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
536 | - if ( $meta->key === $key ) { |
|
537 | - $matches[] = $meta_data_array_key; |
|
538 | - } |
|
539 | - } |
|
540 | - |
|
541 | - if ( ! empty( $matches ) ) { |
|
542 | - // Set matches to null so only one key gets the new value. |
|
543 | - foreach ( $matches as $meta_data_array_key ) { |
|
544 | - $this->meta_data[ $meta_data_array_key ]->value = null; |
|
545 | - } |
|
546 | - $array_key = current( $matches ); |
|
547 | - } |
|
548 | - } |
|
549 | - |
|
550 | - if ( false !== $array_key ) { |
|
551 | - $meta = $this->meta_data[ $array_key ]; |
|
552 | - $meta->key = $key; |
|
553 | - $meta->value = $value; |
|
554 | - } else { |
|
555 | - $this->add_meta_data( $key, $value, true ); |
|
556 | - } |
|
557 | - } |
|
558 | - |
|
559 | - /** |
|
560 | - * Delete meta data. |
|
561 | - * |
|
562 | - * @since 1.0.19 |
|
563 | - * @param string $key Meta key. |
|
564 | - */ |
|
565 | - public function delete_meta_data( $key ) { |
|
566 | - $this->maybe_read_meta_data(); |
|
567 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
568 | - |
|
569 | - if ( $array_keys ) { |
|
570 | - foreach ( $array_keys as $array_key ) { |
|
571 | - $this->meta_data[ $array_key ]->value = null; |
|
572 | - } |
|
573 | - } |
|
574 | - } |
|
575 | - |
|
576 | - /** |
|
577 | - * Delete meta data. |
|
578 | - * |
|
579 | - * @since 1.0.19 |
|
580 | - * @param int $mid Meta ID. |
|
581 | - */ |
|
582 | - public function delete_meta_data_by_mid( $mid ) { |
|
583 | - $this->maybe_read_meta_data(); |
|
584 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
585 | - |
|
586 | - if ( $array_keys ) { |
|
587 | - foreach ( $array_keys as $array_key ) { |
|
588 | - $this->meta_data[ $array_key ]->value = null; |
|
589 | - } |
|
590 | - } |
|
591 | - } |
|
592 | - |
|
593 | - /** |
|
594 | - * Read meta data if null. |
|
595 | - * |
|
596 | - * @since 1.0.19 |
|
597 | - */ |
|
598 | - protected function maybe_read_meta_data() { |
|
599 | - if ( is_null( $this->meta_data ) ) { |
|
600 | - $this->read_meta_data(); |
|
601 | - } |
|
602 | - } |
|
603 | - |
|
604 | - /** |
|
605 | - * Read Meta Data from the database. Ignore any internal properties. |
|
606 | - * Uses it's own caches because get_metadata does not provide meta_ids. |
|
607 | - * |
|
608 | - * @since 1.0.19 |
|
609 | - * @param bool $force_read True to force a new DB read (and update cache). |
|
610 | - */ |
|
611 | - public function read_meta_data( $force_read = false ) { |
|
612 | - $this->meta_data = array(); |
|
613 | - $cache_loaded = false; |
|
614 | - |
|
615 | - if ( ! $this->get_id() ) { |
|
616 | - return; |
|
617 | - } |
|
618 | - |
|
619 | - if ( ! $this->data_store ) { |
|
620 | - return; |
|
621 | - } |
|
622 | - |
|
623 | - if ( ! empty( $this->cache_group ) ) { |
|
624 | - $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(); |
|
625 | - } |
|
626 | - |
|
627 | - if ( ! $force_read ) { |
|
628 | - if ( ! empty( $this->cache_group ) ) { |
|
629 | - $cached_meta = wp_cache_get( $cache_key, $this->cache_group ); |
|
630 | - $cache_loaded = ! empty( $cached_meta ); |
|
631 | - } |
|
632 | - } |
|
633 | - |
|
634 | - $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this ); |
|
635 | - if ( $raw_meta_data ) { |
|
636 | - foreach ( $raw_meta_data as $meta ) { |
|
637 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
638 | - array( |
|
639 | - 'id' => (int) $meta->meta_id, |
|
640 | - 'key' => $meta->meta_key, |
|
641 | - 'value' => maybe_unserialize( $meta->meta_value ), |
|
642 | - ) |
|
643 | - ); |
|
644 | - } |
|
645 | - |
|
646 | - if ( ! $cache_loaded && ! empty( $this->cache_group ) ) { |
|
647 | - wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
648 | - } |
|
649 | - } |
|
650 | - } |
|
651 | - |
|
652 | - /** |
|
653 | - * Update Meta Data in the database. |
|
654 | - * |
|
655 | - * @since 1.0.19 |
|
656 | - */ |
|
657 | - public function save_meta_data() { |
|
658 | - if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
659 | - return; |
|
660 | - } |
|
661 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
662 | - if ( is_null( $meta->value ) ) { |
|
663 | - if ( ! empty( $meta->id ) ) { |
|
664 | - $this->data_store->delete_meta( $this, $meta ); |
|
665 | - unset( $this->meta_data[ $array_key ] ); |
|
666 | - } |
|
667 | - } elseif ( empty( $meta->id ) ) { |
|
668 | - $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
669 | - $meta->apply_changes(); |
|
670 | - } else { |
|
671 | - if ( $meta->get_changes() ) { |
|
672 | - $this->data_store->update_meta( $this, $meta ); |
|
673 | - $meta->apply_changes(); |
|
674 | - } |
|
675 | - } |
|
676 | - } |
|
677 | - if ( ! empty( $this->cache_group ) ) { |
|
678 | - $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(); |
|
679 | - wp_cache_delete( $cache_key, $this->cache_group ); |
|
680 | - } |
|
681 | - } |
|
682 | - |
|
683 | - /** |
|
684 | - * Set ID. |
|
685 | - * |
|
686 | - * @since 1.0.19 |
|
687 | - * @param int $id ID. |
|
688 | - */ |
|
689 | - public function set_id( $id ) { |
|
690 | - $this->id = absint( $id ); |
|
691 | - } |
|
692 | - |
|
693 | - /** |
|
694 | - * Sets item status. |
|
695 | - * |
|
696 | - * @since 1.0.19 |
|
697 | - * @param string $status New status. |
|
698 | - * @return array details of change. |
|
699 | - */ |
|
700 | - 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 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
411 | + $function = 'get_' . $key; |
|
412 | + |
|
413 | + if ( is_callable( array( $this, $function ) ) ) { |
|
414 | + return $this->{$function}(); |
|
415 | + } |
|
416 | + } |
|
417 | + |
|
418 | + // Read the meta data if not yet read. |
|
419 | + $this->maybe_read_meta_data(); |
|
420 | + $meta_data = $this->get_meta_data(); |
|
421 | + $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
422 | + $value = $single ? '' : array(); |
|
423 | + |
|
424 | + if ( ! empty( $array_keys ) ) { |
|
425 | + // 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()). |
|
426 | + if ( $single ) { |
|
427 | + $value = $meta_data[ current( $array_keys ) ]->value; |
|
428 | + } else { |
|
429 | + $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
430 | + } |
|
431 | + } |
|
432 | + |
|
433 | + if ( 'view' === $context ) { |
|
434 | + $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
435 | + } |
|
436 | + |
|
437 | + return $value; |
|
438 | + } |
|
439 | + |
|
440 | + /** |
|
441 | + * See if meta data exists, since get_meta always returns a '' or array(). |
|
442 | + * |
|
443 | + * @since 1.0.19 |
|
444 | + * @param string $key Meta Key. |
|
445 | + * @return boolean |
|
446 | + */ |
|
447 | + public function meta_exists( $key = '' ) { |
|
448 | + $this->maybe_read_meta_data(); |
|
449 | + $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
450 | + return in_array( $key, $array_keys, true ); |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * Set all meta data from array. |
|
455 | + * |
|
456 | + * @since 1.0.19 |
|
457 | + * @param array $data Key/Value pairs. |
|
458 | + */ |
|
459 | + public function set_meta_data( $data ) { |
|
460 | + if ( ! empty( $data ) && is_array( $data ) ) { |
|
461 | + $this->maybe_read_meta_data(); |
|
462 | + foreach ( $data as $meta ) { |
|
463 | + $meta = (array) $meta; |
|
464 | + if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
465 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
466 | + array( |
|
467 | + 'id' => $meta['id'], |
|
468 | + 'key' => $meta['key'], |
|
469 | + 'value' => $meta['value'], |
|
470 | + ) |
|
471 | + ); |
|
472 | + } |
|
473 | + } |
|
474 | + } |
|
475 | + } |
|
476 | + |
|
477 | + /** |
|
478 | + * Add meta data. |
|
479 | + * |
|
480 | + * @since 1.0.19 |
|
481 | + * |
|
482 | + * @param string $key Meta key. |
|
483 | + * @param string|array $value Meta value. |
|
484 | + * @param bool $unique Should this be a unique key?. |
|
485 | + */ |
|
486 | + public function add_meta_data( $key, $value, $unique = false ) { |
|
487 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
488 | + $function = 'set_' . $key; |
|
489 | + |
|
490 | + if ( is_callable( array( $this, $function ) ) ) { |
|
491 | + return $this->{$function}( $value ); |
|
492 | + } |
|
493 | + } |
|
494 | + |
|
495 | + $this->maybe_read_meta_data(); |
|
496 | + if ( $unique ) { |
|
497 | + $this->delete_meta_data( $key ); |
|
498 | + } |
|
499 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
500 | + array( |
|
501 | + 'key' => $key, |
|
502 | + 'value' => $value, |
|
503 | + ) |
|
504 | + ); |
|
505 | + } |
|
506 | + |
|
507 | + /** |
|
508 | + * Update meta data by key or ID, if provided. |
|
509 | + * |
|
510 | + * @since 1.0.19 |
|
511 | + * |
|
512 | + * @param string $key Meta key. |
|
513 | + * @param string|array $value Meta value. |
|
514 | + * @param int $meta_id Meta ID. |
|
515 | + */ |
|
516 | + public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
517 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
518 | + $function = 'set_' . $key; |
|
519 | + |
|
520 | + if ( is_callable( array( $this, $function ) ) ) { |
|
521 | + return $this->{$function}( $value ); |
|
522 | + } |
|
523 | + } |
|
524 | + |
|
525 | + $this->maybe_read_meta_data(); |
|
526 | + |
|
527 | + $array_key = false; |
|
528 | + |
|
529 | + if ( $meta_id ) { |
|
530 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
531 | + $array_key = $array_keys ? current( $array_keys ) : false; |
|
532 | + } else { |
|
533 | + // Find matches by key. |
|
534 | + $matches = array(); |
|
535 | + foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
536 | + if ( $meta->key === $key ) { |
|
537 | + $matches[] = $meta_data_array_key; |
|
538 | + } |
|
539 | + } |
|
540 | + |
|
541 | + if ( ! empty( $matches ) ) { |
|
542 | + // Set matches to null so only one key gets the new value. |
|
543 | + foreach ( $matches as $meta_data_array_key ) { |
|
544 | + $this->meta_data[ $meta_data_array_key ]->value = null; |
|
545 | + } |
|
546 | + $array_key = current( $matches ); |
|
547 | + } |
|
548 | + } |
|
549 | + |
|
550 | + if ( false !== $array_key ) { |
|
551 | + $meta = $this->meta_data[ $array_key ]; |
|
552 | + $meta->key = $key; |
|
553 | + $meta->value = $value; |
|
554 | + } else { |
|
555 | + $this->add_meta_data( $key, $value, true ); |
|
556 | + } |
|
557 | + } |
|
558 | + |
|
559 | + /** |
|
560 | + * Delete meta data. |
|
561 | + * |
|
562 | + * @since 1.0.19 |
|
563 | + * @param string $key Meta key. |
|
564 | + */ |
|
565 | + public function delete_meta_data( $key ) { |
|
566 | + $this->maybe_read_meta_data(); |
|
567 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
568 | + |
|
569 | + if ( $array_keys ) { |
|
570 | + foreach ( $array_keys as $array_key ) { |
|
571 | + $this->meta_data[ $array_key ]->value = null; |
|
572 | + } |
|
573 | + } |
|
574 | + } |
|
575 | + |
|
576 | + /** |
|
577 | + * Delete meta data. |
|
578 | + * |
|
579 | + * @since 1.0.19 |
|
580 | + * @param int $mid Meta ID. |
|
581 | + */ |
|
582 | + public function delete_meta_data_by_mid( $mid ) { |
|
583 | + $this->maybe_read_meta_data(); |
|
584 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
585 | + |
|
586 | + if ( $array_keys ) { |
|
587 | + foreach ( $array_keys as $array_key ) { |
|
588 | + $this->meta_data[ $array_key ]->value = null; |
|
589 | + } |
|
590 | + } |
|
591 | + } |
|
592 | + |
|
593 | + /** |
|
594 | + * Read meta data if null. |
|
595 | + * |
|
596 | + * @since 1.0.19 |
|
597 | + */ |
|
598 | + protected function maybe_read_meta_data() { |
|
599 | + if ( is_null( $this->meta_data ) ) { |
|
600 | + $this->read_meta_data(); |
|
601 | + } |
|
602 | + } |
|
603 | + |
|
604 | + /** |
|
605 | + * Read Meta Data from the database. Ignore any internal properties. |
|
606 | + * Uses it's own caches because get_metadata does not provide meta_ids. |
|
607 | + * |
|
608 | + * @since 1.0.19 |
|
609 | + * @param bool $force_read True to force a new DB read (and update cache). |
|
610 | + */ |
|
611 | + public function read_meta_data( $force_read = false ) { |
|
612 | + $this->meta_data = array(); |
|
613 | + $cache_loaded = false; |
|
614 | + |
|
615 | + if ( ! $this->get_id() ) { |
|
616 | + return; |
|
617 | + } |
|
618 | + |
|
619 | + if ( ! $this->data_store ) { |
|
620 | + return; |
|
621 | + } |
|
622 | + |
|
623 | + if ( ! empty( $this->cache_group ) ) { |
|
624 | + $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(); |
|
625 | + } |
|
626 | + |
|
627 | + if ( ! $force_read ) { |
|
628 | + if ( ! empty( $this->cache_group ) ) { |
|
629 | + $cached_meta = wp_cache_get( $cache_key, $this->cache_group ); |
|
630 | + $cache_loaded = ! empty( $cached_meta ); |
|
631 | + } |
|
632 | + } |
|
633 | + |
|
634 | + $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this ); |
|
635 | + if ( $raw_meta_data ) { |
|
636 | + foreach ( $raw_meta_data as $meta ) { |
|
637 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
638 | + array( |
|
639 | + 'id' => (int) $meta->meta_id, |
|
640 | + 'key' => $meta->meta_key, |
|
641 | + 'value' => maybe_unserialize( $meta->meta_value ), |
|
642 | + ) |
|
643 | + ); |
|
644 | + } |
|
645 | + |
|
646 | + if ( ! $cache_loaded && ! empty( $this->cache_group ) ) { |
|
647 | + wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
648 | + } |
|
649 | + } |
|
650 | + } |
|
651 | + |
|
652 | + /** |
|
653 | + * Update Meta Data in the database. |
|
654 | + * |
|
655 | + * @since 1.0.19 |
|
656 | + */ |
|
657 | + public function save_meta_data() { |
|
658 | + if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
659 | + return; |
|
660 | + } |
|
661 | + foreach ( $this->meta_data as $array_key => $meta ) { |
|
662 | + if ( is_null( $meta->value ) ) { |
|
663 | + if ( ! empty( $meta->id ) ) { |
|
664 | + $this->data_store->delete_meta( $this, $meta ); |
|
665 | + unset( $this->meta_data[ $array_key ] ); |
|
666 | + } |
|
667 | + } elseif ( empty( $meta->id ) ) { |
|
668 | + $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
669 | + $meta->apply_changes(); |
|
670 | + } else { |
|
671 | + if ( $meta->get_changes() ) { |
|
672 | + $this->data_store->update_meta( $this, $meta ); |
|
673 | + $meta->apply_changes(); |
|
674 | + } |
|
675 | + } |
|
676 | + } |
|
677 | + if ( ! empty( $this->cache_group ) ) { |
|
678 | + $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(); |
|
679 | + wp_cache_delete( $cache_key, $this->cache_group ); |
|
680 | + } |
|
681 | + } |
|
682 | + |
|
683 | + /** |
|
684 | + * Set ID. |
|
685 | + * |
|
686 | + * @since 1.0.19 |
|
687 | + * @param int $id ID. |
|
688 | + */ |
|
689 | + public function set_id( $id ) { |
|
690 | + $this->id = absint( $id ); |
|
691 | + } |
|
692 | + |
|
693 | + /** |
|
694 | + * Sets item status. |
|
695 | + * |
|
696 | + * @since 1.0.19 |
|
697 | + * @param string $status New status. |
|
698 | + * @return array details of change. |
|
699 | + */ |
|
700 | + public function set_status( $status ) { |
|
701 | 701 | $old_status = $this->get_status(); |
702 | 702 | |
703 | - $this->set_prop( 'status', $status ); |
|
704 | - |
|
705 | - return array( |
|
706 | - 'from' => $old_status, |
|
707 | - 'to' => $status, |
|
708 | - ); |
|
709 | - } |
|
710 | - |
|
711 | - /** |
|
712 | - * Set all props to default values. |
|
713 | - * |
|
714 | - * @since 1.0.19 |
|
715 | - */ |
|
716 | - public function set_defaults() { |
|
717 | - $this->data = $this->default_data; |
|
718 | - $this->changes = array(); |
|
719 | - $this->set_object_read( false ); |
|
720 | - } |
|
721 | - |
|
722 | - /** |
|
723 | - * Set object read property. |
|
724 | - * |
|
725 | - * @since 1.0.19 |
|
726 | - * @param boolean $read Should read?. |
|
727 | - */ |
|
728 | - public function set_object_read( $read = true ) { |
|
729 | - $this->object_read = (bool) $read; |
|
730 | - } |
|
731 | - |
|
732 | - /** |
|
733 | - * Get object read property. |
|
734 | - * |
|
735 | - * @since 1.0.19 |
|
736 | - * @return boolean |
|
737 | - */ |
|
738 | - public function get_object_read() { |
|
739 | - return (bool) $this->object_read; |
|
740 | - } |
|
741 | - |
|
742 | - /** |
|
743 | - * Set a collection of props in one go, collect any errors, and return the result. |
|
744 | - * Only sets using public methods. |
|
745 | - * |
|
746 | - * @since 1.0.19 |
|
747 | - * |
|
748 | - * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
749 | - * @param string $context In what context to run this. |
|
750 | - * |
|
751 | - * @return bool|WP_Error |
|
752 | - */ |
|
753 | - public function set_props( $props, $context = 'set' ) { |
|
754 | - $errors = false; |
|
755 | - |
|
756 | - foreach ( $props as $prop => $value ) { |
|
757 | - try { |
|
758 | - /** |
|
759 | - * Checks if the prop being set is allowed, and the value is not null. |
|
760 | - */ |
|
761 | - if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
762 | - continue; |
|
763 | - } |
|
764 | - $setter = "set_$prop"; |
|
765 | - |
|
766 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
767 | - $this->{$setter}( $value ); |
|
768 | - } |
|
769 | - } catch ( Exception $e ) { |
|
770 | - if ( ! $errors ) { |
|
771 | - $errors = new WP_Error(); |
|
772 | - } |
|
773 | - $errors->add( $e->getCode(), $e->getMessage() ); |
|
774 | - $this->last_error = $e->getMessage(); |
|
775 | - } |
|
776 | - } |
|
777 | - |
|
778 | - return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
779 | - } |
|
780 | - |
|
781 | - /** |
|
782 | - * Sets a prop for a setter method. |
|
783 | - * |
|
784 | - * This stores changes in a special array so we can track what needs saving |
|
785 | - * the the DB later. |
|
786 | - * |
|
787 | - * @since 1.0.19 |
|
788 | - * @param string $prop Name of prop to set. |
|
789 | - * @param mixed $value Value of the prop. |
|
790 | - */ |
|
791 | - protected function set_prop( $prop, $value ) { |
|
792 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
793 | - if ( true === $this->object_read ) { |
|
794 | - if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
795 | - $this->changes[ $prop ] = maybe_unserialize( $value ); |
|
796 | - } |
|
797 | - } else { |
|
798 | - $this->data[ $prop ] = maybe_unserialize( $value ); |
|
799 | - } |
|
800 | - } |
|
801 | - } |
|
802 | - |
|
803 | - /** |
|
804 | - * Return data changes only. |
|
805 | - * |
|
806 | - * @since 1.0.19 |
|
807 | - * @return array |
|
808 | - */ |
|
809 | - public function get_changes() { |
|
810 | - return $this->changes; |
|
811 | - } |
|
812 | - |
|
813 | - /** |
|
814 | - * Merge changes with data and clear. |
|
815 | - * |
|
816 | - * @since 1.0.19 |
|
817 | - */ |
|
818 | - public function apply_changes() { |
|
819 | - $this->data = array_replace_recursive( $this->data, $this->changes ); |
|
820 | - $this->changes = array(); |
|
821 | - } |
|
822 | - |
|
823 | - /** |
|
824 | - * Prefix for action and filter hooks on data. |
|
825 | - * |
|
826 | - * @since 1.0.19 |
|
827 | - * @return string |
|
828 | - */ |
|
829 | - protected function get_hook_prefix() { |
|
830 | - return 'wpinv_get_' . $this->object_type . '_'; |
|
831 | - } |
|
832 | - |
|
833 | - /** |
|
834 | - * Gets a prop for a getter method. |
|
835 | - * |
|
836 | - * Gets the value from either current pending changes, or the data itself. |
|
837 | - * Context controls what happens to the value before it's returned. |
|
838 | - * |
|
839 | - * @since 1.0.19 |
|
840 | - * @param string $prop Name of prop to get. |
|
841 | - * @param string $context What the value is for. Valid values are view and edit. |
|
842 | - * @return mixed |
|
843 | - */ |
|
844 | - protected function get_prop( $prop, $context = 'view' ) { |
|
845 | - $value = null; |
|
846 | - |
|
847 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
848 | - $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
849 | - |
|
850 | - if ( 'view' === $context ) { |
|
851 | - $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
852 | - } |
|
853 | - } |
|
854 | - |
|
855 | - return $value; |
|
856 | - } |
|
857 | - |
|
858 | - /** |
|
859 | - * Sets a date prop whilst handling formatting and datetime objects. |
|
860 | - * |
|
861 | - * @since 1.0.19 |
|
862 | - * @param string $prop Name of prop to set. |
|
863 | - * @param string|integer $value Value of the prop. |
|
864 | - */ |
|
865 | - protected function set_date_prop( $prop, $value ) { |
|
866 | - |
|
867 | - if ( empty( $value ) ) { |
|
868 | - $this->set_prop( $prop, null ); |
|
869 | - return; |
|
870 | - } |
|
871 | - $this->set_prop( $prop, $value ); |
|
872 | - |
|
873 | - } |
|
874 | - |
|
875 | - /** |
|
876 | - * When invalid data is found, throw an exception unless reading from the DB. |
|
877 | - * |
|
878 | - * @throws Exception Data Exception. |
|
879 | - * @since 1.0.19 |
|
880 | - * @param string $code Error code. |
|
881 | - * @param string $message Error message. |
|
882 | - */ |
|
883 | - protected function error( $code, $message ) { |
|
884 | - throw new Exception( $message, $code ); |
|
885 | - } |
|
703 | + $this->set_prop( 'status', $status ); |
|
704 | + |
|
705 | + return array( |
|
706 | + 'from' => $old_status, |
|
707 | + 'to' => $status, |
|
708 | + ); |
|
709 | + } |
|
710 | + |
|
711 | + /** |
|
712 | + * Set all props to default values. |
|
713 | + * |
|
714 | + * @since 1.0.19 |
|
715 | + */ |
|
716 | + public function set_defaults() { |
|
717 | + $this->data = $this->default_data; |
|
718 | + $this->changes = array(); |
|
719 | + $this->set_object_read( false ); |
|
720 | + } |
|
721 | + |
|
722 | + /** |
|
723 | + * Set object read property. |
|
724 | + * |
|
725 | + * @since 1.0.19 |
|
726 | + * @param boolean $read Should read?. |
|
727 | + */ |
|
728 | + public function set_object_read( $read = true ) { |
|
729 | + $this->object_read = (bool) $read; |
|
730 | + } |
|
731 | + |
|
732 | + /** |
|
733 | + * Get object read property. |
|
734 | + * |
|
735 | + * @since 1.0.19 |
|
736 | + * @return boolean |
|
737 | + */ |
|
738 | + public function get_object_read() { |
|
739 | + return (bool) $this->object_read; |
|
740 | + } |
|
741 | + |
|
742 | + /** |
|
743 | + * Set a collection of props in one go, collect any errors, and return the result. |
|
744 | + * Only sets using public methods. |
|
745 | + * |
|
746 | + * @since 1.0.19 |
|
747 | + * |
|
748 | + * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
749 | + * @param string $context In what context to run this. |
|
750 | + * |
|
751 | + * @return bool|WP_Error |
|
752 | + */ |
|
753 | + public function set_props( $props, $context = 'set' ) { |
|
754 | + $errors = false; |
|
755 | + |
|
756 | + foreach ( $props as $prop => $value ) { |
|
757 | + try { |
|
758 | + /** |
|
759 | + * Checks if the prop being set is allowed, and the value is not null. |
|
760 | + */ |
|
761 | + if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
762 | + continue; |
|
763 | + } |
|
764 | + $setter = "set_$prop"; |
|
765 | + |
|
766 | + if ( is_callable( array( $this, $setter ) ) ) { |
|
767 | + $this->{$setter}( $value ); |
|
768 | + } |
|
769 | + } catch ( Exception $e ) { |
|
770 | + if ( ! $errors ) { |
|
771 | + $errors = new WP_Error(); |
|
772 | + } |
|
773 | + $errors->add( $e->getCode(), $e->getMessage() ); |
|
774 | + $this->last_error = $e->getMessage(); |
|
775 | + } |
|
776 | + } |
|
777 | + |
|
778 | + return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
779 | + } |
|
780 | + |
|
781 | + /** |
|
782 | + * Sets a prop for a setter method. |
|
783 | + * |
|
784 | + * This stores changes in a special array so we can track what needs saving |
|
785 | + * the the DB later. |
|
786 | + * |
|
787 | + * @since 1.0.19 |
|
788 | + * @param string $prop Name of prop to set. |
|
789 | + * @param mixed $value Value of the prop. |
|
790 | + */ |
|
791 | + protected function set_prop( $prop, $value ) { |
|
792 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
793 | + if ( true === $this->object_read ) { |
|
794 | + if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
795 | + $this->changes[ $prop ] = maybe_unserialize( $value ); |
|
796 | + } |
|
797 | + } else { |
|
798 | + $this->data[ $prop ] = maybe_unserialize( $value ); |
|
799 | + } |
|
800 | + } |
|
801 | + } |
|
802 | + |
|
803 | + /** |
|
804 | + * Return data changes only. |
|
805 | + * |
|
806 | + * @since 1.0.19 |
|
807 | + * @return array |
|
808 | + */ |
|
809 | + public function get_changes() { |
|
810 | + return $this->changes; |
|
811 | + } |
|
812 | + |
|
813 | + /** |
|
814 | + * Merge changes with data and clear. |
|
815 | + * |
|
816 | + * @since 1.0.19 |
|
817 | + */ |
|
818 | + public function apply_changes() { |
|
819 | + $this->data = array_replace_recursive( $this->data, $this->changes ); |
|
820 | + $this->changes = array(); |
|
821 | + } |
|
822 | + |
|
823 | + /** |
|
824 | + * Prefix for action and filter hooks on data. |
|
825 | + * |
|
826 | + * @since 1.0.19 |
|
827 | + * @return string |
|
828 | + */ |
|
829 | + protected function get_hook_prefix() { |
|
830 | + return 'wpinv_get_' . $this->object_type . '_'; |
|
831 | + } |
|
832 | + |
|
833 | + /** |
|
834 | + * Gets a prop for a getter method. |
|
835 | + * |
|
836 | + * Gets the value from either current pending changes, or the data itself. |
|
837 | + * Context controls what happens to the value before it's returned. |
|
838 | + * |
|
839 | + * @since 1.0.19 |
|
840 | + * @param string $prop Name of prop to get. |
|
841 | + * @param string $context What the value is for. Valid values are view and edit. |
|
842 | + * @return mixed |
|
843 | + */ |
|
844 | + protected function get_prop( $prop, $context = 'view' ) { |
|
845 | + $value = null; |
|
846 | + |
|
847 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
848 | + $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
849 | + |
|
850 | + if ( 'view' === $context ) { |
|
851 | + $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
852 | + } |
|
853 | + } |
|
854 | + |
|
855 | + return $value; |
|
856 | + } |
|
857 | + |
|
858 | + /** |
|
859 | + * Sets a date prop whilst handling formatting and datetime objects. |
|
860 | + * |
|
861 | + * @since 1.0.19 |
|
862 | + * @param string $prop Name of prop to set. |
|
863 | + * @param string|integer $value Value of the prop. |
|
864 | + */ |
|
865 | + protected function set_date_prop( $prop, $value ) { |
|
866 | + |
|
867 | + if ( empty( $value ) ) { |
|
868 | + $this->set_prop( $prop, null ); |
|
869 | + return; |
|
870 | + } |
|
871 | + $this->set_prop( $prop, $value ); |
|
872 | + |
|
873 | + } |
|
874 | + |
|
875 | + /** |
|
876 | + * When invalid data is found, throw an exception unless reading from the DB. |
|
877 | + * |
|
878 | + * @throws Exception Data Exception. |
|
879 | + * @since 1.0.19 |
|
880 | + * @param string $code Error code. |
|
881 | + * @param string $message Error message. |
|
882 | + */ |
|
883 | + protected function error( $code, $message ) { |
|
884 | + throw new Exception( $message, $code ); |
|
885 | + } |
|
886 | 886 | |
887 | 887 | } |
@@ -8,7 +8,7 @@ discard block |
||
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 |
||
117 | 117 | * |
118 | 118 | * @param int|object|array $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 |
||
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 | /** |
@@ -138,10 +138,10 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function __wakeup() { |
140 | 140 | try { |
141 | - $this->__construct( absint( $this->id ) ); |
|
142 | - } catch ( Exception $e ) { |
|
143 | - $this->set_id( 0 ); |
|
144 | - $this->set_object_read( true ); |
|
141 | + $this->__construct(absint($this->id)); |
|
142 | + } catch (Exception $e) { |
|
143 | + $this->set_id(0); |
|
144 | + $this->set_object_read(true); |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
@@ -152,11 +152,11 @@ discard block |
||
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 |
||
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 |
||
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 ) { |
|
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) { |
|
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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.', 'getpaid' ), $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.', 'getpaid'), $key), '1.0.19'); |
|
342 | 342 | |
343 | 343 | return true; |
344 | 344 | } |
@@ -352,20 +352,20 @@ discard block |
||
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.', 'getpaid' ), $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.', 'getpaid'), $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 |
||
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.', 'getpaid' ), $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.', 'getpaid'), $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,13 +404,13 @@ discard block |
||
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 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
410 | + if ($this->is_internal_meta_key($key)) { |
|
411 | 411 | $function = 'get_' . $key; |
412 | 412 | |
413 | - if ( is_callable( array( $this, $function ) ) ) { |
|
413 | + if (is_callable(array($this, $function))) { |
|
414 | 414 | return $this->{$function}(); |
415 | 415 | } |
416 | 416 | } |
@@ -418,20 +418,20 @@ discard block |
||
418 | 418 | // Read the meta data if not yet read. |
419 | 419 | $this->maybe_read_meta_data(); |
420 | 420 | $meta_data = $this->get_meta_data(); |
421 | - $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
421 | + $array_keys = array_keys(wp_list_pluck($meta_data, 'key'), $key, true); |
|
422 | 422 | $value = $single ? '' : array(); |
423 | 423 | |
424 | - if ( ! empty( $array_keys ) ) { |
|
424 | + if (!empty($array_keys)) { |
|
425 | 425 | // 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()). |
426 | - if ( $single ) { |
|
427 | - $value = $meta_data[ current( $array_keys ) ]->value; |
|
426 | + if ($single) { |
|
427 | + $value = $meta_data[current($array_keys)]->value; |
|
428 | 428 | } else { |
429 | - $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
429 | + $value = array_intersect_key($meta_data, array_flip($array_keys)); |
|
430 | 430 | } |
431 | 431 | } |
432 | 432 | |
433 | - if ( 'view' === $context ) { |
|
434 | - $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
433 | + if ('view' === $context) { |
|
434 | + $value = apply_filters($this->get_hook_prefix() . $key, $value, $this); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | return $value; |
@@ -444,10 +444,10 @@ discard block |
||
444 | 444 | * @param string $key Meta Key. |
445 | 445 | * @return boolean |
446 | 446 | */ |
447 | - public function meta_exists( $key = '' ) { |
|
447 | + public function meta_exists($key = '') { |
|
448 | 448 | $this->maybe_read_meta_data(); |
449 | - $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
450 | - return in_array( $key, $array_keys, true ); |
|
449 | + $array_keys = wp_list_pluck($this->get_meta_data(), 'key'); |
|
450 | + return in_array($key, $array_keys, true); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
@@ -456,12 +456,12 @@ discard block |
||
456 | 456 | * @since 1.0.19 |
457 | 457 | * @param array $data Key/Value pairs. |
458 | 458 | */ |
459 | - public function set_meta_data( $data ) { |
|
460 | - if ( ! empty( $data ) && is_array( $data ) ) { |
|
459 | + public function set_meta_data($data) { |
|
460 | + if (!empty($data) && is_array($data)) { |
|
461 | 461 | $this->maybe_read_meta_data(); |
462 | - foreach ( $data as $meta ) { |
|
462 | + foreach ($data as $meta) { |
|
463 | 463 | $meta = (array) $meta; |
464 | - if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
464 | + if (isset($meta['key'], $meta['value'], $meta['id'])) { |
|
465 | 465 | $this->meta_data[] = new GetPaid_Meta_Data( |
466 | 466 | array( |
467 | 467 | 'id' => $meta['id'], |
@@ -483,18 +483,18 @@ discard block |
||
483 | 483 | * @param string|array $value Meta value. |
484 | 484 | * @param bool $unique Should this be a unique key?. |
485 | 485 | */ |
486 | - public function add_meta_data( $key, $value, $unique = false ) { |
|
487 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
486 | + public function add_meta_data($key, $value, $unique = false) { |
|
487 | + if ($this->is_internal_meta_key($key)) { |
|
488 | 488 | $function = 'set_' . $key; |
489 | 489 | |
490 | - if ( is_callable( array( $this, $function ) ) ) { |
|
491 | - return $this->{$function}( $value ); |
|
490 | + if (is_callable(array($this, $function))) { |
|
491 | + return $this->{$function}($value); |
|
492 | 492 | } |
493 | 493 | } |
494 | 494 | |
495 | 495 | $this->maybe_read_meta_data(); |
496 | - if ( $unique ) { |
|
497 | - $this->delete_meta_data( $key ); |
|
496 | + if ($unique) { |
|
497 | + $this->delete_meta_data($key); |
|
498 | 498 | } |
499 | 499 | $this->meta_data[] = new GetPaid_Meta_Data( |
500 | 500 | array( |
@@ -513,12 +513,12 @@ discard block |
||
513 | 513 | * @param string|array $value Meta value. |
514 | 514 | * @param int $meta_id Meta ID. |
515 | 515 | */ |
516 | - public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
517 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
516 | + public function update_meta_data($key, $value, $meta_id = 0) { |
|
517 | + if ($this->is_internal_meta_key($key)) { |
|
518 | 518 | $function = 'set_' . $key; |
519 | 519 | |
520 | - if ( is_callable( array( $this, $function ) ) ) { |
|
521 | - return $this->{$function}( $value ); |
|
520 | + if (is_callable(array($this, $function))) { |
|
521 | + return $this->{$function}($value); |
|
522 | 522 | } |
523 | 523 | } |
524 | 524 | |
@@ -526,33 +526,33 @@ discard block |
||
526 | 526 | |
527 | 527 | $array_key = false; |
528 | 528 | |
529 | - if ( $meta_id ) { |
|
530 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
531 | - $array_key = $array_keys ? current( $array_keys ) : false; |
|
529 | + if ($meta_id) { |
|
530 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), $meta_id, true); |
|
531 | + $array_key = $array_keys ? current($array_keys) : false; |
|
532 | 532 | } else { |
533 | 533 | // Find matches by key. |
534 | 534 | $matches = array(); |
535 | - foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
536 | - if ( $meta->key === $key ) { |
|
535 | + foreach ($this->meta_data as $meta_data_array_key => $meta) { |
|
536 | + if ($meta->key === $key) { |
|
537 | 537 | $matches[] = $meta_data_array_key; |
538 | 538 | } |
539 | 539 | } |
540 | 540 | |
541 | - if ( ! empty( $matches ) ) { |
|
541 | + if (!empty($matches)) { |
|
542 | 542 | // Set matches to null so only one key gets the new value. |
543 | - foreach ( $matches as $meta_data_array_key ) { |
|
544 | - $this->meta_data[ $meta_data_array_key ]->value = null; |
|
543 | + foreach ($matches as $meta_data_array_key) { |
|
544 | + $this->meta_data[$meta_data_array_key]->value = null; |
|
545 | 545 | } |
546 | - $array_key = current( $matches ); |
|
546 | + $array_key = current($matches); |
|
547 | 547 | } |
548 | 548 | } |
549 | 549 | |
550 | - if ( false !== $array_key ) { |
|
551 | - $meta = $this->meta_data[ $array_key ]; |
|
550 | + if (false !== $array_key) { |
|
551 | + $meta = $this->meta_data[$array_key]; |
|
552 | 552 | $meta->key = $key; |
553 | 553 | $meta->value = $value; |
554 | 554 | } else { |
555 | - $this->add_meta_data( $key, $value, true ); |
|
555 | + $this->add_meta_data($key, $value, true); |
|
556 | 556 | } |
557 | 557 | } |
558 | 558 | |
@@ -562,13 +562,13 @@ discard block |
||
562 | 562 | * @since 1.0.19 |
563 | 563 | * @param string $key Meta key. |
564 | 564 | */ |
565 | - public function delete_meta_data( $key ) { |
|
565 | + public function delete_meta_data($key) { |
|
566 | 566 | $this->maybe_read_meta_data(); |
567 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
567 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'key'), $key, true); |
|
568 | 568 | |
569 | - if ( $array_keys ) { |
|
570 | - foreach ( $array_keys as $array_key ) { |
|
571 | - $this->meta_data[ $array_key ]->value = null; |
|
569 | + if ($array_keys) { |
|
570 | + foreach ($array_keys as $array_key) { |
|
571 | + $this->meta_data[$array_key]->value = null; |
|
572 | 572 | } |
573 | 573 | } |
574 | 574 | } |
@@ -579,13 +579,13 @@ discard block |
||
579 | 579 | * @since 1.0.19 |
580 | 580 | * @param int $mid Meta ID. |
581 | 581 | */ |
582 | - public function delete_meta_data_by_mid( $mid ) { |
|
582 | + public function delete_meta_data_by_mid($mid) { |
|
583 | 583 | $this->maybe_read_meta_data(); |
584 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
584 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), (int) $mid, true); |
|
585 | 585 | |
586 | - if ( $array_keys ) { |
|
587 | - foreach ( $array_keys as $array_key ) { |
|
588 | - $this->meta_data[ $array_key ]->value = null; |
|
586 | + if ($array_keys) { |
|
587 | + foreach ($array_keys as $array_key) { |
|
588 | + $this->meta_data[$array_key]->value = null; |
|
589 | 589 | } |
590 | 590 | } |
591 | 591 | } |
@@ -596,7 +596,7 @@ discard block |
||
596 | 596 | * @since 1.0.19 |
597 | 597 | */ |
598 | 598 | protected function maybe_read_meta_data() { |
599 | - if ( is_null( $this->meta_data ) ) { |
|
599 | + if (is_null($this->meta_data)) { |
|
600 | 600 | $this->read_meta_data(); |
601 | 601 | } |
602 | 602 | } |
@@ -608,43 +608,43 @@ discard block |
||
608 | 608 | * @since 1.0.19 |
609 | 609 | * @param bool $force_read True to force a new DB read (and update cache). |
610 | 610 | */ |
611 | - public function read_meta_data( $force_read = false ) { |
|
611 | + public function read_meta_data($force_read = false) { |
|
612 | 612 | $this->meta_data = array(); |
613 | 613 | $cache_loaded = false; |
614 | 614 | |
615 | - if ( ! $this->get_id() ) { |
|
615 | + if (!$this->get_id()) { |
|
616 | 616 | return; |
617 | 617 | } |
618 | 618 | |
619 | - if ( ! $this->data_store ) { |
|
619 | + if (!$this->data_store) { |
|
620 | 620 | return; |
621 | 621 | } |
622 | 622 | |
623 | - if ( ! empty( $this->cache_group ) ) { |
|
624 | - $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(); |
|
623 | + if (!empty($this->cache_group)) { |
|
624 | + $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(); |
|
625 | 625 | } |
626 | 626 | |
627 | - if ( ! $force_read ) { |
|
628 | - if ( ! empty( $this->cache_group ) ) { |
|
629 | - $cached_meta = wp_cache_get( $cache_key, $this->cache_group ); |
|
630 | - $cache_loaded = ! empty( $cached_meta ); |
|
627 | + if (!$force_read) { |
|
628 | + if (!empty($this->cache_group)) { |
|
629 | + $cached_meta = wp_cache_get($cache_key, $this->cache_group); |
|
630 | + $cache_loaded = !empty($cached_meta); |
|
631 | 631 | } |
632 | 632 | } |
633 | 633 | |
634 | - $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this ); |
|
635 | - if ( $raw_meta_data ) { |
|
636 | - foreach ( $raw_meta_data as $meta ) { |
|
634 | + $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta($this); |
|
635 | + if ($raw_meta_data) { |
|
636 | + foreach ($raw_meta_data as $meta) { |
|
637 | 637 | $this->meta_data[] = new GetPaid_Meta_Data( |
638 | 638 | array( |
639 | 639 | 'id' => (int) $meta->meta_id, |
640 | 640 | 'key' => $meta->meta_key, |
641 | - 'value' => maybe_unserialize( $meta->meta_value ), |
|
641 | + 'value' => maybe_unserialize($meta->meta_value), |
|
642 | 642 | ) |
643 | 643 | ); |
644 | 644 | } |
645 | 645 | |
646 | - if ( ! $cache_loaded && ! empty( $this->cache_group ) ) { |
|
647 | - wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
646 | + if (!$cache_loaded && !empty($this->cache_group)) { |
|
647 | + wp_cache_set($cache_key, $raw_meta_data, $this->cache_group); |
|
648 | 648 | } |
649 | 649 | } |
650 | 650 | } |
@@ -655,28 +655,28 @@ discard block |
||
655 | 655 | * @since 1.0.19 |
656 | 656 | */ |
657 | 657 | public function save_meta_data() { |
658 | - if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
658 | + if (!$this->data_store || is_null($this->meta_data)) { |
|
659 | 659 | return; |
660 | 660 | } |
661 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
662 | - if ( is_null( $meta->value ) ) { |
|
663 | - if ( ! empty( $meta->id ) ) { |
|
664 | - $this->data_store->delete_meta( $this, $meta ); |
|
665 | - unset( $this->meta_data[ $array_key ] ); |
|
661 | + foreach ($this->meta_data as $array_key => $meta) { |
|
662 | + if (is_null($meta->value)) { |
|
663 | + if (!empty($meta->id)) { |
|
664 | + $this->data_store->delete_meta($this, $meta); |
|
665 | + unset($this->meta_data[$array_key]); |
|
666 | 666 | } |
667 | - } elseif ( empty( $meta->id ) ) { |
|
668 | - $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
667 | + } elseif (empty($meta->id)) { |
|
668 | + $meta->id = $this->data_store->add_meta($this, $meta); |
|
669 | 669 | $meta->apply_changes(); |
670 | 670 | } else { |
671 | - if ( $meta->get_changes() ) { |
|
672 | - $this->data_store->update_meta( $this, $meta ); |
|
671 | + if ($meta->get_changes()) { |
|
672 | + $this->data_store->update_meta($this, $meta); |
|
673 | 673 | $meta->apply_changes(); |
674 | 674 | } |
675 | 675 | } |
676 | 676 | } |
677 | - if ( ! empty( $this->cache_group ) ) { |
|
678 | - $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(); |
|
679 | - wp_cache_delete( $cache_key, $this->cache_group ); |
|
677 | + if (!empty($this->cache_group)) { |
|
678 | + $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(); |
|
679 | + wp_cache_delete($cache_key, $this->cache_group); |
|
680 | 680 | } |
681 | 681 | } |
682 | 682 | |
@@ -686,8 +686,8 @@ discard block |
||
686 | 686 | * @since 1.0.19 |
687 | 687 | * @param int $id ID. |
688 | 688 | */ |
689 | - public function set_id( $id ) { |
|
690 | - $this->id = absint( $id ); |
|
689 | + public function set_id($id) { |
|
690 | + $this->id = absint($id); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | /** |
@@ -697,10 +697,10 @@ discard block |
||
697 | 697 | * @param string $status New status. |
698 | 698 | * @return array details of change. |
699 | 699 | */ |
700 | - public function set_status( $status ) { |
|
700 | + public function set_status($status) { |
|
701 | 701 | $old_status = $this->get_status(); |
702 | 702 | |
703 | - $this->set_prop( 'status', $status ); |
|
703 | + $this->set_prop('status', $status); |
|
704 | 704 | |
705 | 705 | return array( |
706 | 706 | 'from' => $old_status, |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | public function set_defaults() { |
717 | 717 | $this->data = $this->default_data; |
718 | 718 | $this->changes = array(); |
719 | - $this->set_object_read( false ); |
|
719 | + $this->set_object_read(false); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | /** |
@@ -725,7 +725,7 @@ discard block |
||
725 | 725 | * @since 1.0.19 |
726 | 726 | * @param boolean $read Should read?. |
727 | 727 | */ |
728 | - public function set_object_read( $read = true ) { |
|
728 | + public function set_object_read($read = true) { |
|
729 | 729 | $this->object_read = (bool) $read; |
730 | 730 | } |
731 | 731 | |
@@ -750,32 +750,32 @@ discard block |
||
750 | 750 | * |
751 | 751 | * @return bool|WP_Error |
752 | 752 | */ |
753 | - public function set_props( $props, $context = 'set' ) { |
|
753 | + public function set_props($props, $context = 'set') { |
|
754 | 754 | $errors = false; |
755 | 755 | |
756 | - foreach ( $props as $prop => $value ) { |
|
756 | + foreach ($props as $prop => $value) { |
|
757 | 757 | try { |
758 | 758 | /** |
759 | 759 | * Checks if the prop being set is allowed, and the value is not null. |
760 | 760 | */ |
761 | - if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
761 | + if (is_null($value) || in_array($prop, array('prop', 'date_prop', 'meta_data'), true)) { |
|
762 | 762 | continue; |
763 | 763 | } |
764 | 764 | $setter = "set_$prop"; |
765 | 765 | |
766 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
767 | - $this->{$setter}( $value ); |
|
766 | + if (is_callable(array($this, $setter))) { |
|
767 | + $this->{$setter}($value); |
|
768 | 768 | } |
769 | - } catch ( Exception $e ) { |
|
770 | - if ( ! $errors ) { |
|
769 | + } catch (Exception $e) { |
|
770 | + if (!$errors) { |
|
771 | 771 | $errors = new WP_Error(); |
772 | 772 | } |
773 | - $errors->add( $e->getCode(), $e->getMessage() ); |
|
773 | + $errors->add($e->getCode(), $e->getMessage()); |
|
774 | 774 | $this->last_error = $e->getMessage(); |
775 | 775 | } |
776 | 776 | } |
777 | 777 | |
778 | - return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
778 | + return $errors && count($errors->get_error_codes()) ? $errors : true; |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | /** |
@@ -788,14 +788,14 @@ discard block |
||
788 | 788 | * @param string $prop Name of prop to set. |
789 | 789 | * @param mixed $value Value of the prop. |
790 | 790 | */ |
791 | - protected function set_prop( $prop, $value ) { |
|
792 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
793 | - if ( true === $this->object_read ) { |
|
794 | - if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
795 | - $this->changes[ $prop ] = maybe_unserialize( $value ); |
|
791 | + protected function set_prop($prop, $value) { |
|
792 | + if (array_key_exists($prop, $this->data)) { |
|
793 | + if (true === $this->object_read) { |
|
794 | + if ($value !== $this->data[$prop] || array_key_exists($prop, $this->changes)) { |
|
795 | + $this->changes[$prop] = maybe_unserialize($value); |
|
796 | 796 | } |
797 | 797 | } else { |
798 | - $this->data[ $prop ] = maybe_unserialize( $value ); |
|
798 | + $this->data[$prop] = maybe_unserialize($value); |
|
799 | 799 | } |
800 | 800 | } |
801 | 801 | } |
@@ -816,7 +816,7 @@ discard block |
||
816 | 816 | * @since 1.0.19 |
817 | 817 | */ |
818 | 818 | public function apply_changes() { |
819 | - $this->data = array_replace_recursive( $this->data, $this->changes ); |
|
819 | + $this->data = array_replace_recursive($this->data, $this->changes); |
|
820 | 820 | $this->changes = array(); |
821 | 821 | } |
822 | 822 | |
@@ -841,14 +841,14 @@ discard block |
||
841 | 841 | * @param string $context What the value is for. Valid values are view and edit. |
842 | 842 | * @return mixed |
843 | 843 | */ |
844 | - protected function get_prop( $prop, $context = 'view' ) { |
|
844 | + protected function get_prop($prop, $context = 'view') { |
|
845 | 845 | $value = null; |
846 | 846 | |
847 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
848 | - $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
847 | + if (array_key_exists($prop, $this->data)) { |
|
848 | + $value = array_key_exists($prop, $this->changes) ? $this->changes[$prop] : $this->data[$prop]; |
|
849 | 849 | |
850 | - if ( 'view' === $context ) { |
|
851 | - $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
850 | + if ('view' === $context) { |
|
851 | + $value = apply_filters($this->get_hook_prefix() . $prop, $value, $this); |
|
852 | 852 | } |
853 | 853 | } |
854 | 854 | |
@@ -862,13 +862,13 @@ discard block |
||
862 | 862 | * @param string $prop Name of prop to set. |
863 | 863 | * @param string|integer $value Value of the prop. |
864 | 864 | */ |
865 | - protected function set_date_prop( $prop, $value ) { |
|
865 | + protected function set_date_prop($prop, $value) { |
|
866 | 866 | |
867 | - if ( empty( $value ) ) { |
|
868 | - $this->set_prop( $prop, null ); |
|
867 | + if (empty($value)) { |
|
868 | + $this->set_prop($prop, null); |
|
869 | 869 | return; |
870 | 870 | } |
871 | - $this->set_prop( $prop, $value ); |
|
871 | + $this->set_prop($prop, $value); |
|
872 | 872 | |
873 | 873 | } |
874 | 874 | |
@@ -880,8 +880,8 @@ discard block |
||
880 | 880 | * @param string $code Error code. |
881 | 881 | * @param string $message Error message. |
882 | 882 | */ |
883 | - protected function error( $code, $message ) { |
|
884 | - throw new Exception( $message, $code ); |
|
883 | + protected function error($code, $message) { |
|
884 | + throw new Exception($message, $code); |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -14,228 +14,228 @@ discard block |
||
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_recurring', |
|
35 | - '_wpinv_recurring_period', |
|
36 | - '_wpinv_recurring_interval', |
|
37 | - '_wpinv_recurring_limit', |
|
38 | - '_wpinv_free_trial', |
|
39 | - '_wpinv_trial_period', |
|
40 | - '_wpinv_trial_interval' |
|
41 | - ); |
|
42 | - |
|
43 | - /** |
|
44 | - * A map of meta keys to data props. |
|
45 | - * |
|
46 | - * @since 1.0.19 |
|
47 | - * |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - protected $meta_key_to_props = array( |
|
51 | - '_wpinv_price' => 'price', |
|
52 | - '_wpinv_vat_rule' => 'vat_rule', |
|
53 | - '_wpinv_vat_class' => 'vat_class', |
|
54 | - '_wpinv_type' => 'type', |
|
55 | - '_wpinv_custom_id' => 'custom_id', |
|
56 | - '_wpinv_custom_name' => 'custom_name', |
|
57 | - '_wpinv_custom_singular_name' => 'custom_singular_name', |
|
58 | - '_wpinv_editable' => 'is_editable', |
|
59 | - '_wpinv_dynamic_pricing' => 'is_dynamic_pricing', |
|
60 | - '_minimum_price' => 'minimum_price', |
|
61 | - '_wpinv_custom_name' => 'custom_name', |
|
62 | - '_wpinv_is_recurring' => 'is_recurring', |
|
63 | - '_wpinv_recurring_period' => 'recurring_period', |
|
64 | - '_wpinv_recurring_interval' => 'recurring_interval', |
|
65 | - '_wpinv_recurring_limit' => 'recurring_limit', |
|
66 | - '_wpinv_free_trial' => 'is_free_trial', |
|
67 | - '_wpinv_trial_period' => 'trial_period', |
|
68 | - '_wpinv_trial_interval' => 'trial_interval', |
|
69 | - '_wpinv_version' => 'version', |
|
70 | - ); |
|
71 | - |
|
72 | - /* |
|
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_recurring', |
|
35 | + '_wpinv_recurring_period', |
|
36 | + '_wpinv_recurring_interval', |
|
37 | + '_wpinv_recurring_limit', |
|
38 | + '_wpinv_free_trial', |
|
39 | + '_wpinv_trial_period', |
|
40 | + '_wpinv_trial_interval' |
|
41 | + ); |
|
42 | + |
|
43 | + /** |
|
44 | + * A map of meta keys to data props. |
|
45 | + * |
|
46 | + * @since 1.0.19 |
|
47 | + * |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + protected $meta_key_to_props = array( |
|
51 | + '_wpinv_price' => 'price', |
|
52 | + '_wpinv_vat_rule' => 'vat_rule', |
|
53 | + '_wpinv_vat_class' => 'vat_class', |
|
54 | + '_wpinv_type' => 'type', |
|
55 | + '_wpinv_custom_id' => 'custom_id', |
|
56 | + '_wpinv_custom_name' => 'custom_name', |
|
57 | + '_wpinv_custom_singular_name' => 'custom_singular_name', |
|
58 | + '_wpinv_editable' => 'is_editable', |
|
59 | + '_wpinv_dynamic_pricing' => 'is_dynamic_pricing', |
|
60 | + '_minimum_price' => 'minimum_price', |
|
61 | + '_wpinv_custom_name' => 'custom_name', |
|
62 | + '_wpinv_is_recurring' => 'is_recurring', |
|
63 | + '_wpinv_recurring_period' => 'recurring_period', |
|
64 | + '_wpinv_recurring_interval' => 'recurring_interval', |
|
65 | + '_wpinv_recurring_limit' => 'recurring_limit', |
|
66 | + '_wpinv_free_trial' => 'is_free_trial', |
|
67 | + '_wpinv_trial_period' => 'trial_period', |
|
68 | + '_wpinv_trial_interval' => 'trial_interval', |
|
69 | + '_wpinv_version' => 'version', |
|
70 | + ); |
|
71 | + |
|
72 | + /* |
|
73 | 73 | |-------------------------------------------------------------------------- |
74 | 74 | | CRUD Methods |
75 | 75 | |-------------------------------------------------------------------------- |
76 | 76 | */ |
77 | 77 | |
78 | - /** |
|
79 | - * Method to create a new item in the database. |
|
80 | - * |
|
81 | - * @param WPInv_Item $item Item object. |
|
82 | - */ |
|
83 | - public function create( &$item ) { |
|
84 | - $item->set_version( WPINV_VERSION ); |
|
85 | - $item->set_date_created( current_time('mysql') ); |
|
86 | - |
|
87 | - // Create a new post. |
|
88 | - $id = wp_insert_post( |
|
89 | - apply_filters( |
|
90 | - 'getpaid_new_item_data', |
|
91 | - array( |
|
92 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
93 | - 'post_type' => 'wpi_item', |
|
94 | - 'post_status' => $this->get_post_status( $item ), |
|
95 | - 'ping_status' => 'closed', |
|
96 | - 'post_author' => $item->get_author( 'edit' ), |
|
97 | - 'post_title' => $item->get_name( 'edit' ), |
|
98 | - 'post_parent' => 0, |
|
99 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
100 | - ) |
|
101 | - ), |
|
102 | - true |
|
103 | - ); |
|
104 | - |
|
105 | - if ( $id && ! is_wp_error( $id ) ) { |
|
106 | - $item->set_id( $id ); |
|
107 | - $this->update_post_meta( $item ); |
|
108 | - $item->save_meta_data(); |
|
109 | - $item->apply_changes(); |
|
110 | - $this->clear_caches( $item ); |
|
111 | - do_action( 'getpaid_new_item', $item->get_id(), $item ); |
|
112 | - return true; |
|
113 | - } |
|
114 | - |
|
115 | - if ( is_wp_error( $id ) ) { |
|
116 | - $item->last_error = $id->get_error_message(); |
|
117 | - } |
|
78 | + /** |
|
79 | + * Method to create a new item in the database. |
|
80 | + * |
|
81 | + * @param WPInv_Item $item Item object. |
|
82 | + */ |
|
83 | + public function create( &$item ) { |
|
84 | + $item->set_version( WPINV_VERSION ); |
|
85 | + $item->set_date_created( current_time('mysql') ); |
|
86 | + |
|
87 | + // Create a new post. |
|
88 | + $id = wp_insert_post( |
|
89 | + apply_filters( |
|
90 | + 'getpaid_new_item_data', |
|
91 | + array( |
|
92 | + 'post_date' => $item->get_date_created( 'edit' ), |
|
93 | + 'post_type' => 'wpi_item', |
|
94 | + 'post_status' => $this->get_post_status( $item ), |
|
95 | + 'ping_status' => 'closed', |
|
96 | + 'post_author' => $item->get_author( 'edit' ), |
|
97 | + 'post_title' => $item->get_name( 'edit' ), |
|
98 | + 'post_parent' => 0, |
|
99 | + 'post_excerpt' => $item->get_description( 'edit' ), |
|
100 | + ) |
|
101 | + ), |
|
102 | + true |
|
103 | + ); |
|
104 | + |
|
105 | + if ( $id && ! is_wp_error( $id ) ) { |
|
106 | + $item->set_id( $id ); |
|
107 | + $this->update_post_meta( $item ); |
|
108 | + $item->save_meta_data(); |
|
109 | + $item->apply_changes(); |
|
110 | + $this->clear_caches( $item ); |
|
111 | + do_action( 'getpaid_new_item', $item->get_id(), $item ); |
|
112 | + return true; |
|
113 | + } |
|
114 | + |
|
115 | + if ( is_wp_error( $id ) ) { |
|
116 | + $item->last_error = $id->get_error_message(); |
|
117 | + } |
|
118 | 118 | |
119 | - return false; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Method to read an item from the database. |
|
124 | - * |
|
125 | - * @param WPInv_Item $item Item object. |
|
126 | - * |
|
127 | - */ |
|
128 | - public function read( &$item ) { |
|
129 | - |
|
130 | - $item->set_defaults(); |
|
131 | - $item_object = get_post( $item->get_id() ); |
|
132 | - |
|
133 | - if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
134 | - $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
135 | - $item->set_id( 0 ); |
|
136 | - return false; |
|
137 | - } |
|
138 | - |
|
139 | - $item->set_props( |
|
140 | - array( |
|
141 | - 'parent_id' => $item_object->post_parent, |
|
142 | - 'date_created' => 0 < $item_object->post_date ? $item_object->post_date : null, |
|
143 | - 'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null, |
|
144 | - 'status' => $item_object->post_status, |
|
145 | - 'name' => $item_object->post_title, |
|
146 | - 'description' => $item_object->post_excerpt, |
|
147 | - 'author' => $item_object->post_author, |
|
148 | - ) |
|
149 | - ); |
|
150 | - |
|
151 | - $this->read_object_data( $item, $item_object ); |
|
152 | - $item->read_meta_data(); |
|
153 | - $item->set_object_read( true ); |
|
154 | - do_action( 'getpaid_read_item', $item->get_id(), $item ); |
|
155 | - |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Method to update an item in the database. |
|
160 | - * |
|
161 | - * @param WPInv_Item $item Item object. |
|
162 | - */ |
|
163 | - public function update( &$item ) { |
|
164 | - $item->save_meta_data(); |
|
165 | - $item->set_version( WPINV_VERSION ); |
|
166 | - |
|
167 | - if ( null === $item->get_date_created( 'edit' ) ) { |
|
168 | - $item->set_date_created( current_time('mysql') ); |
|
169 | - } |
|
170 | - |
|
171 | - // Grab the current status so we can compare. |
|
172 | - $previous_status = get_post_status( $item->get_id() ); |
|
173 | - |
|
174 | - $changes = $item->get_changes(); |
|
175 | - |
|
176 | - // Only update the post when the post data changes. |
|
177 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
178 | - $post_data = array( |
|
179 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
180 | - 'post_status' => $item->get_status( 'edit' ), |
|
181 | - 'post_parent' => $item->get_parent_id( 'edit' ), |
|
182 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
183 | - 'post_modified' => $item->get_date_modified( 'edit' ), |
|
184 | - 'post_title' => $item->get_name( 'edit' ), |
|
185 | - 'post_author' => $item->get_author( 'edit' ), |
|
186 | - ); |
|
187 | - |
|
188 | - /** |
|
189 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
190 | - * to update data, since wp_update_post spawns more calls to the |
|
191 | - * save_post action. |
|
192 | - * |
|
193 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
194 | - * or an update purely from CRUD. |
|
195 | - */ |
|
196 | - if ( doing_action( 'save_post' ) ) { |
|
197 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
198 | - clean_post_cache( $item->get_id() ); |
|
199 | - } else { |
|
200 | - wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
201 | - } |
|
202 | - $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
203 | - } |
|
204 | - $this->update_post_meta( $item ); |
|
205 | - $item->apply_changes(); |
|
206 | - $this->clear_caches( $item ); |
|
207 | - |
|
208 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
209 | - $new_status = $item->get_status( 'edit' ); |
|
210 | - |
|
211 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
212 | - do_action( 'getpaid_new_item', $item->get_id(), $item ); |
|
213 | - } else { |
|
214 | - do_action( 'getpaid_update_item', $item->get_id(), $item ); |
|
215 | - } |
|
216 | - |
|
217 | - } |
|
218 | - |
|
219 | - /* |
|
119 | + return false; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Method to read an item from the database. |
|
124 | + * |
|
125 | + * @param WPInv_Item $item Item object. |
|
126 | + * |
|
127 | + */ |
|
128 | + public function read( &$item ) { |
|
129 | + |
|
130 | + $item->set_defaults(); |
|
131 | + $item_object = get_post( $item->get_id() ); |
|
132 | + |
|
133 | + if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
134 | + $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
135 | + $item->set_id( 0 ); |
|
136 | + return false; |
|
137 | + } |
|
138 | + |
|
139 | + $item->set_props( |
|
140 | + array( |
|
141 | + 'parent_id' => $item_object->post_parent, |
|
142 | + 'date_created' => 0 < $item_object->post_date ? $item_object->post_date : null, |
|
143 | + 'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null, |
|
144 | + 'status' => $item_object->post_status, |
|
145 | + 'name' => $item_object->post_title, |
|
146 | + 'description' => $item_object->post_excerpt, |
|
147 | + 'author' => $item_object->post_author, |
|
148 | + ) |
|
149 | + ); |
|
150 | + |
|
151 | + $this->read_object_data( $item, $item_object ); |
|
152 | + $item->read_meta_data(); |
|
153 | + $item->set_object_read( true ); |
|
154 | + do_action( 'getpaid_read_item', $item->get_id(), $item ); |
|
155 | + |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Method to update an item in the database. |
|
160 | + * |
|
161 | + * @param WPInv_Item $item Item object. |
|
162 | + */ |
|
163 | + public function update( &$item ) { |
|
164 | + $item->save_meta_data(); |
|
165 | + $item->set_version( WPINV_VERSION ); |
|
166 | + |
|
167 | + if ( null === $item->get_date_created( 'edit' ) ) { |
|
168 | + $item->set_date_created( current_time('mysql') ); |
|
169 | + } |
|
170 | + |
|
171 | + // Grab the current status so we can compare. |
|
172 | + $previous_status = get_post_status( $item->get_id() ); |
|
173 | + |
|
174 | + $changes = $item->get_changes(); |
|
175 | + |
|
176 | + // Only update the post when the post data changes. |
|
177 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
178 | + $post_data = array( |
|
179 | + 'post_date' => $item->get_date_created( 'edit' ), |
|
180 | + 'post_status' => $item->get_status( 'edit' ), |
|
181 | + 'post_parent' => $item->get_parent_id( 'edit' ), |
|
182 | + 'post_excerpt' => $item->get_description( 'edit' ), |
|
183 | + 'post_modified' => $item->get_date_modified( 'edit' ), |
|
184 | + 'post_title' => $item->get_name( 'edit' ), |
|
185 | + 'post_author' => $item->get_author( 'edit' ), |
|
186 | + ); |
|
187 | + |
|
188 | + /** |
|
189 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
190 | + * to update data, since wp_update_post spawns more calls to the |
|
191 | + * save_post action. |
|
192 | + * |
|
193 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
194 | + * or an update purely from CRUD. |
|
195 | + */ |
|
196 | + if ( doing_action( 'save_post' ) ) { |
|
197 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
198 | + clean_post_cache( $item->get_id() ); |
|
199 | + } else { |
|
200 | + wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
201 | + } |
|
202 | + $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
203 | + } |
|
204 | + $this->update_post_meta( $item ); |
|
205 | + $item->apply_changes(); |
|
206 | + $this->clear_caches( $item ); |
|
207 | + |
|
208 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
209 | + $new_status = $item->get_status( 'edit' ); |
|
210 | + |
|
211 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
212 | + do_action( 'getpaid_new_item', $item->get_id(), $item ); |
|
213 | + } else { |
|
214 | + do_action( 'getpaid_update_item', $item->get_id(), $item ); |
|
215 | + } |
|
216 | + |
|
217 | + } |
|
218 | + |
|
219 | + /* |
|
220 | 220 | |-------------------------------------------------------------------------- |
221 | 221 | | Additional Methods |
222 | 222 | |-------------------------------------------------------------------------- |
223 | 223 | */ |
224 | 224 | |
225 | - /** |
|
226 | - * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class. |
|
227 | - * |
|
228 | - * @param WPInv_Item $item WPInv_Item object. |
|
229 | - * @since 1.0.19 |
|
230 | - */ |
|
231 | - protected function update_post_meta( &$item ) { |
|
225 | + /** |
|
226 | + * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class. |
|
227 | + * |
|
228 | + * @param WPInv_Item $item WPInv_Item object. |
|
229 | + * @since 1.0.19 |
|
230 | + */ |
|
231 | + protected function update_post_meta( &$item ) { |
|
232 | 232 | |
233 | - // Ensure that we have a custom id. |
|
233 | + // Ensure that we have a custom id. |
|
234 | 234 | if ( ! $item->get_custom_id() ) { |
235 | 235 | $item->set_custom_id( $item->get_id() ); |
236 | - } |
|
236 | + } |
|
237 | 237 | |
238 | - parent::update_post_meta( $item ); |
|
239 | - } |
|
238 | + parent::update_post_meta( $item ); |
|
239 | + } |
|
240 | 240 | |
241 | 241 | } |
@@ -3,7 +3,7 @@ discard block |
||
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 | |
@@ -80,39 +80,39 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @param WPInv_Item $item Item object. |
82 | 82 | */ |
83 | - public function create( &$item ) { |
|
84 | - $item->set_version( WPINV_VERSION ); |
|
85 | - $item->set_date_created( current_time('mysql') ); |
|
83 | + public function create(&$item) { |
|
84 | + $item->set_version(WPINV_VERSION); |
|
85 | + $item->set_date_created(current_time('mysql')); |
|
86 | 86 | |
87 | 87 | // Create a new post. |
88 | 88 | $id = wp_insert_post( |
89 | 89 | apply_filters( |
90 | 90 | 'getpaid_new_item_data', |
91 | 91 | array( |
92 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
92 | + 'post_date' => $item->get_date_created('edit'), |
|
93 | 93 | 'post_type' => 'wpi_item', |
94 | - 'post_status' => $this->get_post_status( $item ), |
|
94 | + 'post_status' => $this->get_post_status($item), |
|
95 | 95 | 'ping_status' => 'closed', |
96 | - 'post_author' => $item->get_author( 'edit' ), |
|
97 | - 'post_title' => $item->get_name( 'edit' ), |
|
96 | + 'post_author' => $item->get_author('edit'), |
|
97 | + 'post_title' => $item->get_name('edit'), |
|
98 | 98 | 'post_parent' => 0, |
99 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
99 | + 'post_excerpt' => $item->get_description('edit'), |
|
100 | 100 | ) |
101 | 101 | ), |
102 | 102 | true |
103 | 103 | ); |
104 | 104 | |
105 | - if ( $id && ! is_wp_error( $id ) ) { |
|
106 | - $item->set_id( $id ); |
|
107 | - $this->update_post_meta( $item ); |
|
105 | + if ($id && !is_wp_error($id)) { |
|
106 | + $item->set_id($id); |
|
107 | + $this->update_post_meta($item); |
|
108 | 108 | $item->save_meta_data(); |
109 | 109 | $item->apply_changes(); |
110 | - $this->clear_caches( $item ); |
|
111 | - do_action( 'getpaid_new_item', $item->get_id(), $item ); |
|
110 | + $this->clear_caches($item); |
|
111 | + do_action('getpaid_new_item', $item->get_id(), $item); |
|
112 | 112 | return true; |
113 | 113 | } |
114 | 114 | |
115 | - if ( is_wp_error( $id ) ) { |
|
115 | + if (is_wp_error($id)) { |
|
116 | 116 | $item->last_error = $id->get_error_message(); |
117 | 117 | } |
118 | 118 | |
@@ -125,14 +125,14 @@ discard block |
||
125 | 125 | * @param WPInv_Item $item Item object. |
126 | 126 | * |
127 | 127 | */ |
128 | - public function read( &$item ) { |
|
128 | + public function read(&$item) { |
|
129 | 129 | |
130 | 130 | $item->set_defaults(); |
131 | - $item_object = get_post( $item->get_id() ); |
|
131 | + $item_object = get_post($item->get_id()); |
|
132 | 132 | |
133 | - if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
134 | - $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
135 | - $item->set_id( 0 ); |
|
133 | + if (!$item->get_id() || !$item_object || $item_object->post_type != 'wpi_item') { |
|
134 | + $item->last_error = __('Invalid item.', 'invoicing'); |
|
135 | + $item->set_id(0); |
|
136 | 136 | return false; |
137 | 137 | } |
138 | 138 | |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | ) |
149 | 149 | ); |
150 | 150 | |
151 | - $this->read_object_data( $item, $item_object ); |
|
151 | + $this->read_object_data($item, $item_object); |
|
152 | 152 | $item->read_meta_data(); |
153 | - $item->set_object_read( true ); |
|
154 | - do_action( 'getpaid_read_item', $item->get_id(), $item ); |
|
153 | + $item->set_object_read(true); |
|
154 | + do_action('getpaid_read_item', $item->get_id(), $item); |
|
155 | 155 | |
156 | 156 | } |
157 | 157 | |
@@ -160,29 +160,29 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @param WPInv_Item $item Item object. |
162 | 162 | */ |
163 | - public function update( &$item ) { |
|
163 | + public function update(&$item) { |
|
164 | 164 | $item->save_meta_data(); |
165 | - $item->set_version( WPINV_VERSION ); |
|
165 | + $item->set_version(WPINV_VERSION); |
|
166 | 166 | |
167 | - if ( null === $item->get_date_created( 'edit' ) ) { |
|
168 | - $item->set_date_created( current_time('mysql') ); |
|
167 | + if (null === $item->get_date_created('edit')) { |
|
168 | + $item->set_date_created(current_time('mysql')); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | // Grab the current status so we can compare. |
172 | - $previous_status = get_post_status( $item->get_id() ); |
|
172 | + $previous_status = get_post_status($item->get_id()); |
|
173 | 173 | |
174 | 174 | $changes = $item->get_changes(); |
175 | 175 | |
176 | 176 | // Only update the post when the post data changes. |
177 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
177 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author'), array_keys($changes))) { |
|
178 | 178 | $post_data = array( |
179 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
180 | - 'post_status' => $item->get_status( 'edit' ), |
|
181 | - 'post_parent' => $item->get_parent_id( 'edit' ), |
|
182 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
183 | - 'post_modified' => $item->get_date_modified( 'edit' ), |
|
184 | - 'post_title' => $item->get_name( 'edit' ), |
|
185 | - 'post_author' => $item->get_author( 'edit' ), |
|
179 | + 'post_date' => $item->get_date_created('edit'), |
|
180 | + 'post_status' => $item->get_status('edit'), |
|
181 | + 'post_parent' => $item->get_parent_id('edit'), |
|
182 | + 'post_excerpt' => $item->get_description('edit'), |
|
183 | + 'post_modified' => $item->get_date_modified('edit'), |
|
184 | + 'post_title' => $item->get_name('edit'), |
|
185 | + 'post_author' => $item->get_author('edit'), |
|
186 | 186 | ); |
187 | 187 | |
188 | 188 | /** |
@@ -193,25 +193,25 @@ discard block |
||
193 | 193 | * This ensures hooks are fired by either WP itself (admin screen save), |
194 | 194 | * or an update purely from CRUD. |
195 | 195 | */ |
196 | - if ( doing_action( 'save_post' ) ) { |
|
197 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
198 | - clean_post_cache( $item->get_id() ); |
|
196 | + if (doing_action('save_post')) { |
|
197 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $item->get_id())); |
|
198 | + clean_post_cache($item->get_id()); |
|
199 | 199 | } else { |
200 | - wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
200 | + wp_update_post(array_merge(array('ID' => $item->get_id()), $post_data)); |
|
201 | 201 | } |
202 | - $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
202 | + $item->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
203 | 203 | } |
204 | - $this->update_post_meta( $item ); |
|
204 | + $this->update_post_meta($item); |
|
205 | 205 | $item->apply_changes(); |
206 | - $this->clear_caches( $item ); |
|
206 | + $this->clear_caches($item); |
|
207 | 207 | |
208 | 208 | // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
209 | - $new_status = $item->get_status( 'edit' ); |
|
209 | + $new_status = $item->get_status('edit'); |
|
210 | 210 | |
211 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
212 | - do_action( 'getpaid_new_item', $item->get_id(), $item ); |
|
211 | + if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) { |
|
212 | + do_action('getpaid_new_item', $item->get_id(), $item); |
|
213 | 213 | } else { |
214 | - do_action( 'getpaid_update_item', $item->get_id(), $item ); |
|
214 | + do_action('getpaid_update_item', $item->get_id(), $item); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | } |
@@ -228,14 +228,14 @@ discard block |
||
228 | 228 | * @param WPInv_Item $item WPInv_Item object. |
229 | 229 | * @since 1.0.19 |
230 | 230 | */ |
231 | - protected function update_post_meta( &$item ) { |
|
231 | + protected function update_post_meta(&$item) { |
|
232 | 232 | |
233 | 233 | // Ensure that we have a custom id. |
234 | - if ( ! $item->get_custom_id() ) { |
|
235 | - $item->set_custom_id( $item->get_id() ); |
|
234 | + if (!$item->get_custom_id()) { |
|
235 | + $item->set_custom_id($item->get_id()); |
|
236 | 236 | } |
237 | 237 | |
238 | - parent::update_post_meta( $item ); |
|
238 | + parent::update_post_meta($item); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -15,490 +15,490 @@ discard block |
||
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_taxes', |
|
27 | - '_wpinv_fees', |
|
28 | - '_wpinv_discounts', |
|
29 | - '_wpinv_submission_id', |
|
30 | - '_wpinv_payment_form', |
|
31 | - '_wpinv_is_viewed', |
|
32 | - 'wpinv_email_cc', |
|
33 | - 'wpinv_template' |
|
34 | - ); |
|
35 | - |
|
36 | - /** |
|
37 | - * A map of meta keys to data props. |
|
38 | - * |
|
39 | - * @since 1.0.19 |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - protected $meta_key_to_props = array( |
|
44 | - '_wpinv_subscr_profile_id' => 'subscription_id', |
|
45 | - '_wpinv_taxes' => 'taxes', |
|
46 | - '_wpinv_fees' => 'fees', |
|
47 | - '_wpinv_discounts' => 'discounts', |
|
48 | - '_wpinv_submission_id' => 'submission_id', |
|
49 | - '_wpinv_payment_form' => 'payment_form', |
|
50 | - '_wpinv_is_viewed' => 'is_viewed', |
|
51 | - 'wpinv_email_cc' => 'email_cc', |
|
52 | - 'wpinv_template' => 'template', |
|
53 | - ); |
|
54 | - |
|
55 | - /** |
|
56 | - * A map of database fields to data props. |
|
57 | - * |
|
58 | - * @since 1.0.19 |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - protected $database_fields_to_props = array( |
|
63 | - 'post_id' => 'id', |
|
64 | - 'number' => 'number', |
|
65 | - 'currency' => 'currency', |
|
66 | - 'key' => 'key', |
|
67 | - 'type' => 'type', |
|
68 | - 'mode' => 'mode', |
|
69 | - 'user_ip' => 'user_ip', |
|
70 | - 'first_name' => 'first_name', |
|
71 | - 'last_name' => 'last_name', |
|
72 | - 'address' => 'address', |
|
73 | - 'city' => 'city', |
|
74 | - 'state' => 'state', |
|
75 | - 'country' => 'country', |
|
76 | - 'zip' => 'zip', |
|
77 | - 'zip' => 'zip', |
|
78 | - 'adddress_confirmed' => 'address_confirmed', |
|
79 | - 'gateway' => 'gateway', |
|
80 | - 'transaction_id' => 'transaction_id', |
|
81 | - 'currency' => 'currency', |
|
82 | - 'subtotal' => 'subtotal', |
|
83 | - 'tax' => 'total_tax', |
|
84 | - 'fees_total' => 'total_fees', |
|
85 | - 'discount' => 'total_discount', |
|
86 | - 'total' => 'total', |
|
87 | - 'discount_code' => 'discount_code', |
|
88 | - 'disable_taxes' => 'disable_taxes', |
|
89 | - 'due_date' => 'due_date', |
|
90 | - 'completed_date' => 'completed_date', |
|
91 | - 'company' => 'company', |
|
92 | - 'vat_number' => 'vat_number', |
|
93 | - 'vat_rate' => 'vat_rate', |
|
94 | - ); |
|
95 | - |
|
96 | - /* |
|
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_taxes', |
|
27 | + '_wpinv_fees', |
|
28 | + '_wpinv_discounts', |
|
29 | + '_wpinv_submission_id', |
|
30 | + '_wpinv_payment_form', |
|
31 | + '_wpinv_is_viewed', |
|
32 | + 'wpinv_email_cc', |
|
33 | + 'wpinv_template' |
|
34 | + ); |
|
35 | + |
|
36 | + /** |
|
37 | + * A map of meta keys to data props. |
|
38 | + * |
|
39 | + * @since 1.0.19 |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + protected $meta_key_to_props = array( |
|
44 | + '_wpinv_subscr_profile_id' => 'subscription_id', |
|
45 | + '_wpinv_taxes' => 'taxes', |
|
46 | + '_wpinv_fees' => 'fees', |
|
47 | + '_wpinv_discounts' => 'discounts', |
|
48 | + '_wpinv_submission_id' => 'submission_id', |
|
49 | + '_wpinv_payment_form' => 'payment_form', |
|
50 | + '_wpinv_is_viewed' => 'is_viewed', |
|
51 | + 'wpinv_email_cc' => 'email_cc', |
|
52 | + 'wpinv_template' => 'template', |
|
53 | + ); |
|
54 | + |
|
55 | + /** |
|
56 | + * A map of database fields to data props. |
|
57 | + * |
|
58 | + * @since 1.0.19 |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + protected $database_fields_to_props = array( |
|
63 | + 'post_id' => 'id', |
|
64 | + 'number' => 'number', |
|
65 | + 'currency' => 'currency', |
|
66 | + 'key' => 'key', |
|
67 | + 'type' => 'type', |
|
68 | + 'mode' => 'mode', |
|
69 | + 'user_ip' => 'user_ip', |
|
70 | + 'first_name' => 'first_name', |
|
71 | + 'last_name' => 'last_name', |
|
72 | + 'address' => 'address', |
|
73 | + 'city' => 'city', |
|
74 | + 'state' => 'state', |
|
75 | + 'country' => 'country', |
|
76 | + 'zip' => 'zip', |
|
77 | + 'zip' => 'zip', |
|
78 | + 'adddress_confirmed' => 'address_confirmed', |
|
79 | + 'gateway' => 'gateway', |
|
80 | + 'transaction_id' => 'transaction_id', |
|
81 | + 'currency' => 'currency', |
|
82 | + 'subtotal' => 'subtotal', |
|
83 | + 'tax' => 'total_tax', |
|
84 | + 'fees_total' => 'total_fees', |
|
85 | + 'discount' => 'total_discount', |
|
86 | + 'total' => 'total', |
|
87 | + 'discount_code' => 'discount_code', |
|
88 | + 'disable_taxes' => 'disable_taxes', |
|
89 | + 'due_date' => 'due_date', |
|
90 | + 'completed_date' => 'completed_date', |
|
91 | + 'company' => 'company', |
|
92 | + 'vat_number' => 'vat_number', |
|
93 | + 'vat_rate' => 'vat_rate', |
|
94 | + ); |
|
95 | + |
|
96 | + /* |
|
97 | 97 | |-------------------------------------------------------------------------- |
98 | 98 | | CRUD Methods |
99 | 99 | |-------------------------------------------------------------------------- |
100 | 100 | */ |
101 | - /** |
|
102 | - * Method to create a new invoice in the database. |
|
103 | - * |
|
104 | - * @param WPInv_Invoice $invoice Invoice object. |
|
105 | - */ |
|
106 | - public function create( &$invoice ) { |
|
107 | - $invoice->set_version( WPINV_VERSION ); |
|
108 | - $invoice->set_date_created( current_time('mysql') ); |
|
109 | - |
|
110 | - // Ensure both the key and number are set. |
|
111 | - $invoice->get_key(); |
|
112 | - $invoice->get_number(); |
|
113 | - |
|
114 | - // Create a new post. |
|
115 | - $id = wp_insert_post( |
|
116 | - apply_filters( |
|
117 | - 'getpaid_new_invoice_data', |
|
118 | - array( |
|
119 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
120 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
121 | - 'post_status' => $this->get_post_status( $invoice ), |
|
122 | - 'ping_status' => 'closed', |
|
123 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
124 | - 'post_title' => $invoice->get_number( 'edit' ), |
|
125 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
126 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
127 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
128 | - ) |
|
129 | - ), |
|
130 | - true |
|
131 | - ); |
|
132 | - |
|
133 | - if ( $id && ! is_wp_error( $id ) ) { |
|
134 | - $invoice->set_id( $id ); |
|
135 | - getpaid_save_invoice_user_address( $invoice ); |
|
136 | - $this->save_special_fields( $invoice ); |
|
137 | - $this->save_items( $invoice ); |
|
138 | - $this->update_post_meta( $invoice ); |
|
139 | - $invoice->save_meta_data(); |
|
140 | - $invoice->apply_changes(); |
|
141 | - $this->clear_caches( $invoice ); |
|
142 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
143 | - return true; |
|
144 | - } |
|
145 | - |
|
146 | - if ( is_wp_error( $id ) ) { |
|
147 | - $invoice->last_error = $id->get_error_message(); |
|
148 | - } |
|
149 | - |
|
150 | - return false; |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Method to read an invoice from the database. |
|
155 | - * |
|
156 | - * @param WPInv_Invoice $invoice Invoice object. |
|
157 | - * |
|
158 | - */ |
|
159 | - public function read( &$invoice ) { |
|
160 | - |
|
161 | - $invoice->set_defaults(); |
|
162 | - $invoice_object = get_post( $invoice->get_id() ); |
|
163 | - |
|
164 | - if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
165 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
166 | - $invoice->set_id( 0 ); |
|
167 | - return false; |
|
168 | - } |
|
169 | - |
|
170 | - $invoice->set_props( |
|
171 | - array( |
|
172 | - 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
173 | - 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
174 | - 'status' => $invoice_object->post_status, |
|
175 | - 'author' => $invoice_object->post_author, |
|
176 | - 'description' => $invoice_object->post_excerpt, |
|
177 | - 'parent_id' => $invoice_object->post_parent, |
|
178 | - 'name' => $invoice_object->post_title, |
|
179 | - 'path' => $invoice_object->post_name, |
|
180 | - 'post_type' => $invoice_object->post_type, |
|
181 | - ) |
|
182 | - ); |
|
183 | - |
|
184 | - $invoice->set_type( $invoice_object->post_type ); |
|
185 | - |
|
186 | - $this->read_object_data( $invoice, $invoice_object ); |
|
187 | - $this->add_special_fields( $invoice ); |
|
188 | - $this->add_items( $invoice ); |
|
189 | - $invoice->read_meta_data(); |
|
190 | - $invoice->set_object_read( true ); |
|
191 | - do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
192 | - |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Method to update an invoice in the database. |
|
197 | - * |
|
198 | - * @param WPInv_Invoice $invoice Invoice object. |
|
199 | - */ |
|
200 | - public function update( &$invoice ) { |
|
201 | - $invoice->save_meta_data(); |
|
202 | - $invoice->set_version( WPINV_VERSION ); |
|
203 | - |
|
204 | - if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
205 | - $invoice->set_date_created( current_time('mysql') ); |
|
206 | - } |
|
207 | - |
|
208 | - // Ensure both the key and number are set. |
|
209 | - $invoice->get_key(); |
|
210 | - $invoice->get_number(); |
|
211 | - |
|
212 | - // Grab the current status so we can compare. |
|
213 | - $previous_status = get_post_status( $invoice->get_id() ); |
|
214 | - |
|
215 | - $changes = $invoice->get_changes(); |
|
216 | - |
|
217 | - // Only update the post when the post data changes. |
|
218 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
219 | - $post_data = array( |
|
220 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
221 | - 'post_status' => $invoice->get_status( 'edit' ), |
|
222 | - 'post_title' => $invoice->get_name( 'edit' ), |
|
223 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
224 | - 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
225 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
226 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
227 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
228 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
229 | - ); |
|
230 | - |
|
231 | - /** |
|
232 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
233 | - * to update data, since wp_update_post spawns more calls to the |
|
234 | - * save_post action. |
|
235 | - * |
|
236 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
237 | - * or an update purely from CRUD. |
|
238 | - */ |
|
239 | - if ( doing_action( 'save_post' ) ) { |
|
240 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
241 | - clean_post_cache( $invoice->get_id() ); |
|
242 | - } else { |
|
243 | - wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
244 | - } |
|
245 | - $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
246 | - } |
|
247 | - $this->update_post_meta( $invoice ); |
|
248 | - $this->save_special_fields( $invoice ); |
|
249 | - $this->save_items( $invoice ); |
|
250 | - $invoice->apply_changes(); |
|
251 | - getpaid_save_invoice_user_address( $invoice ); |
|
252 | - $this->clear_caches( $invoice ); |
|
253 | - |
|
254 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
255 | - $new_status = $invoice->get_status( 'edit' ); |
|
256 | - |
|
257 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
258 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
259 | - } else { |
|
260 | - do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
261 | - } |
|
262 | - |
|
263 | - } |
|
264 | - |
|
265 | - /* |
|
101 | + /** |
|
102 | + * Method to create a new invoice in the database. |
|
103 | + * |
|
104 | + * @param WPInv_Invoice $invoice Invoice object. |
|
105 | + */ |
|
106 | + public function create( &$invoice ) { |
|
107 | + $invoice->set_version( WPINV_VERSION ); |
|
108 | + $invoice->set_date_created( current_time('mysql') ); |
|
109 | + |
|
110 | + // Ensure both the key and number are set. |
|
111 | + $invoice->get_key(); |
|
112 | + $invoice->get_number(); |
|
113 | + |
|
114 | + // Create a new post. |
|
115 | + $id = wp_insert_post( |
|
116 | + apply_filters( |
|
117 | + 'getpaid_new_invoice_data', |
|
118 | + array( |
|
119 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
120 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
121 | + 'post_status' => $this->get_post_status( $invoice ), |
|
122 | + 'ping_status' => 'closed', |
|
123 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
124 | + 'post_title' => $invoice->get_number( 'edit' ), |
|
125 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
126 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
127 | + 'post_name' => $invoice->get_path( 'edit' ), |
|
128 | + ) |
|
129 | + ), |
|
130 | + true |
|
131 | + ); |
|
132 | + |
|
133 | + if ( $id && ! is_wp_error( $id ) ) { |
|
134 | + $invoice->set_id( $id ); |
|
135 | + getpaid_save_invoice_user_address( $invoice ); |
|
136 | + $this->save_special_fields( $invoice ); |
|
137 | + $this->save_items( $invoice ); |
|
138 | + $this->update_post_meta( $invoice ); |
|
139 | + $invoice->save_meta_data(); |
|
140 | + $invoice->apply_changes(); |
|
141 | + $this->clear_caches( $invoice ); |
|
142 | + do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
143 | + return true; |
|
144 | + } |
|
145 | + |
|
146 | + if ( is_wp_error( $id ) ) { |
|
147 | + $invoice->last_error = $id->get_error_message(); |
|
148 | + } |
|
149 | + |
|
150 | + return false; |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Method to read an invoice from the database. |
|
155 | + * |
|
156 | + * @param WPInv_Invoice $invoice Invoice object. |
|
157 | + * |
|
158 | + */ |
|
159 | + public function read( &$invoice ) { |
|
160 | + |
|
161 | + $invoice->set_defaults(); |
|
162 | + $invoice_object = get_post( $invoice->get_id() ); |
|
163 | + |
|
164 | + if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
165 | + $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
166 | + $invoice->set_id( 0 ); |
|
167 | + return false; |
|
168 | + } |
|
169 | + |
|
170 | + $invoice->set_props( |
|
171 | + array( |
|
172 | + 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
173 | + 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
174 | + 'status' => $invoice_object->post_status, |
|
175 | + 'author' => $invoice_object->post_author, |
|
176 | + 'description' => $invoice_object->post_excerpt, |
|
177 | + 'parent_id' => $invoice_object->post_parent, |
|
178 | + 'name' => $invoice_object->post_title, |
|
179 | + 'path' => $invoice_object->post_name, |
|
180 | + 'post_type' => $invoice_object->post_type, |
|
181 | + ) |
|
182 | + ); |
|
183 | + |
|
184 | + $invoice->set_type( $invoice_object->post_type ); |
|
185 | + |
|
186 | + $this->read_object_data( $invoice, $invoice_object ); |
|
187 | + $this->add_special_fields( $invoice ); |
|
188 | + $this->add_items( $invoice ); |
|
189 | + $invoice->read_meta_data(); |
|
190 | + $invoice->set_object_read( true ); |
|
191 | + do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
192 | + |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Method to update an invoice in the database. |
|
197 | + * |
|
198 | + * @param WPInv_Invoice $invoice Invoice object. |
|
199 | + */ |
|
200 | + public function update( &$invoice ) { |
|
201 | + $invoice->save_meta_data(); |
|
202 | + $invoice->set_version( WPINV_VERSION ); |
|
203 | + |
|
204 | + if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
205 | + $invoice->set_date_created( current_time('mysql') ); |
|
206 | + } |
|
207 | + |
|
208 | + // Ensure both the key and number are set. |
|
209 | + $invoice->get_key(); |
|
210 | + $invoice->get_number(); |
|
211 | + |
|
212 | + // Grab the current status so we can compare. |
|
213 | + $previous_status = get_post_status( $invoice->get_id() ); |
|
214 | + |
|
215 | + $changes = $invoice->get_changes(); |
|
216 | + |
|
217 | + // Only update the post when the post data changes. |
|
218 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
219 | + $post_data = array( |
|
220 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
221 | + 'post_status' => $invoice->get_status( 'edit' ), |
|
222 | + 'post_title' => $invoice->get_name( 'edit' ), |
|
223 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
224 | + 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
225 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
226 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
227 | + 'post_name' => $invoice->get_path( 'edit' ), |
|
228 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
229 | + ); |
|
230 | + |
|
231 | + /** |
|
232 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
233 | + * to update data, since wp_update_post spawns more calls to the |
|
234 | + * save_post action. |
|
235 | + * |
|
236 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
237 | + * or an update purely from CRUD. |
|
238 | + */ |
|
239 | + if ( doing_action( 'save_post' ) ) { |
|
240 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
241 | + clean_post_cache( $invoice->get_id() ); |
|
242 | + } else { |
|
243 | + wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
244 | + } |
|
245 | + $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
246 | + } |
|
247 | + $this->update_post_meta( $invoice ); |
|
248 | + $this->save_special_fields( $invoice ); |
|
249 | + $this->save_items( $invoice ); |
|
250 | + $invoice->apply_changes(); |
|
251 | + getpaid_save_invoice_user_address( $invoice ); |
|
252 | + $this->clear_caches( $invoice ); |
|
253 | + |
|
254 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
255 | + $new_status = $invoice->get_status( 'edit' ); |
|
256 | + |
|
257 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
258 | + do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
259 | + } else { |
|
260 | + do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
261 | + } |
|
262 | + |
|
263 | + } |
|
264 | + |
|
265 | + /* |
|
266 | 266 | |-------------------------------------------------------------------------- |
267 | 267 | | Additional Methods |
268 | 268 | |-------------------------------------------------------------------------- |
269 | 269 | */ |
270 | 270 | |
271 | - /** |
|
271 | + /** |
|
272 | 272 | * Retrieves special fields and adds to the invoice. |
273 | - * |
|
274 | - * @param WPInv_Invoice $invoice Invoice object. |
|
273 | + * |
|
274 | + * @param WPInv_Invoice $invoice Invoice object. |
|
275 | 275 | */ |
276 | 276 | public function add_special_fields( &$invoice ) { |
277 | - global $wpdb; |
|
277 | + global $wpdb; |
|
278 | 278 | |
279 | - // Maybe retrieve from the cache. |
|
280 | - $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
279 | + // Maybe retrieve from the cache. |
|
280 | + $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
281 | 281 | |
282 | - // If not found, retrieve from the db. |
|
283 | - if ( false === $data ) { |
|
284 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
282 | + // If not found, retrieve from the db. |
|
283 | + if ( false === $data ) { |
|
284 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
285 | 285 | |
286 | - $data = $wpdb->get_row( |
|
287 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
288 | - ARRAY_A |
|
289 | - ); |
|
286 | + $data = $wpdb->get_row( |
|
287 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
288 | + ARRAY_A |
|
289 | + ); |
|
290 | 290 | |
291 | - // Update the cache with our data |
|
292 | - wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
291 | + // Update the cache with our data |
|
292 | + wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
293 | 293 | |
294 | - } |
|
294 | + } |
|
295 | 295 | |
296 | - // Abort if the data does not exist. |
|
297 | - if ( empty( $data ) ) { |
|
298 | - return; |
|
299 | - } |
|
296 | + // Abort if the data does not exist. |
|
297 | + if ( empty( $data ) ) { |
|
298 | + return; |
|
299 | + } |
|
300 | 300 | |
301 | - $props = array(); |
|
301 | + $props = array(); |
|
302 | 302 | |
303 | - foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
303 | + foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
304 | 304 | |
305 | - if ( $db_field == 'post_id' ) { |
|
306 | - continue; |
|
307 | - } |
|
308 | - |
|
309 | - $props[ $prop ] = $data[ $db_field ]; |
|
310 | - } |
|
311 | - |
|
312 | - $invoice->set_props( $props ); |
|
313 | - |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Gets a list of special fields that need updated based on change state |
|
318 | - * or if they are present in the database or not. |
|
319 | - * |
|
320 | - * @param WPInv_Invoice $invoice The Invoice object. |
|
321 | - * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
322 | - */ |
|
323 | - protected function get_special_fields_to_update( $invoice ) { |
|
324 | - $fields_to_update = array(); |
|
325 | - $changed_props = $invoice->get_changes(); |
|
326 | - |
|
327 | - // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
328 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
329 | - if ( array_key_exists( $prop, $changed_props ) ) { |
|
330 | - $fields_to_update[ $database_field ] = $prop; |
|
331 | - } |
|
332 | - } |
|
333 | - |
|
334 | - return $fields_to_update; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
339 | - * |
|
340 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
341 | - * @since 1.0.19 |
|
342 | - */ |
|
343 | - protected function update_special_fields( &$invoice ) { |
|
344 | - global $wpdb; |
|
345 | - |
|
346 | - $updated_props = array(); |
|
347 | - $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
348 | - |
|
349 | - foreach ( $fields_to_update as $database_field => $prop ) { |
|
350 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
351 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
352 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
353 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
354 | - } |
|
355 | - |
|
356 | - if ( ! empty( $updated_props ) ) { |
|
357 | - |
|
358 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
359 | - $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
360 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
361 | - do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
362 | - |
|
363 | - } |
|
364 | - |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Helper method that inserts special fields to the database. |
|
369 | - * |
|
370 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
371 | - * @since 1.0.19 |
|
372 | - */ |
|
373 | - protected function insert_special_fields( &$invoice ) { |
|
374 | - global $wpdb; |
|
375 | - |
|
376 | - $updated_props = array(); |
|
377 | - |
|
378 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
379 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
380 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
381 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
382 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
383 | - } |
|
384 | - |
|
385 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
386 | - $wpdb->insert( $table, $updated_props ); |
|
387 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
388 | - do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
389 | - |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
305 | + if ( $db_field == 'post_id' ) { |
|
306 | + continue; |
|
307 | + } |
|
308 | + |
|
309 | + $props[ $prop ] = $data[ $db_field ]; |
|
310 | + } |
|
311 | + |
|
312 | + $invoice->set_props( $props ); |
|
313 | + |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Gets a list of special fields that need updated based on change state |
|
318 | + * or if they are present in the database or not. |
|
319 | + * |
|
320 | + * @param WPInv_Invoice $invoice The Invoice object. |
|
321 | + * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
322 | + */ |
|
323 | + protected function get_special_fields_to_update( $invoice ) { |
|
324 | + $fields_to_update = array(); |
|
325 | + $changed_props = $invoice->get_changes(); |
|
326 | + |
|
327 | + // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
328 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
329 | + if ( array_key_exists( $prop, $changed_props ) ) { |
|
330 | + $fields_to_update[ $database_field ] = $prop; |
|
331 | + } |
|
332 | + } |
|
333 | + |
|
334 | + return $fields_to_update; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
339 | + * |
|
340 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
341 | + * @since 1.0.19 |
|
342 | + */ |
|
343 | + protected function update_special_fields( &$invoice ) { |
|
344 | + global $wpdb; |
|
345 | + |
|
346 | + $updated_props = array(); |
|
347 | + $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
348 | + |
|
349 | + foreach ( $fields_to_update as $database_field => $prop ) { |
|
350 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
351 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
352 | + $value = is_bool( $value ) ? ( int ) $value : $value; |
|
353 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
354 | + } |
|
355 | + |
|
356 | + if ( ! empty( $updated_props ) ) { |
|
357 | + |
|
358 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
359 | + $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
360 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
361 | + do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
362 | + |
|
363 | + } |
|
364 | + |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Helper method that inserts special fields to the database. |
|
369 | + * |
|
370 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
371 | + * @since 1.0.19 |
|
372 | + */ |
|
373 | + protected function insert_special_fields( &$invoice ) { |
|
374 | + global $wpdb; |
|
375 | + |
|
376 | + $updated_props = array(); |
|
377 | + |
|
378 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
379 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
380 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
381 | + $value = is_bool( $value ) ? ( int ) $value : $value; |
|
382 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
383 | + } |
|
384 | + |
|
385 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
386 | + $wpdb->insert( $table, $updated_props ); |
|
387 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
388 | + do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
389 | + |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | 393 | * Saves all special fields. |
394 | - * |
|
395 | - * @param WPInv_Invoice $invoice Invoice object. |
|
394 | + * |
|
395 | + * @param WPInv_Invoice $invoice Invoice object. |
|
396 | 396 | */ |
397 | 397 | public function save_special_fields( $invoice ) { |
398 | - global $wpdb; |
|
398 | + global $wpdb; |
|
399 | 399 | |
400 | - // The invoices table. |
|
401 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
402 | - $id = (int) $invoice->get_id(); |
|
400 | + // The invoices table. |
|
401 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
402 | + $id = (int) $invoice->get_id(); |
|
403 | 403 | |
404 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
404 | + if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
405 | 405 | |
406 | - $this->update_special_fields( $invoice ); |
|
406 | + $this->update_special_fields( $invoice ); |
|
407 | 407 | |
408 | - } else { |
|
408 | + } else { |
|
409 | 409 | |
410 | - $this->insert_special_fields( $invoice ); |
|
410 | + $this->insert_special_fields( $invoice ); |
|
411 | 411 | |
412 | - } |
|
412 | + } |
|
413 | 413 | |
414 | - } |
|
414 | + } |
|
415 | 415 | |
416 | - /** |
|
416 | + /** |
|
417 | 417 | * Set's up cart details. |
418 | - * |
|
419 | - * @param WPInv_Invoice $invoice Invoice object. |
|
418 | + * |
|
419 | + * @param WPInv_Invoice $invoice Invoice object. |
|
420 | 420 | */ |
421 | 421 | public function add_items( &$invoice ) { |
422 | - global $wpdb; |
|
422 | + global $wpdb; |
|
423 | 423 | |
424 | - // Maybe retrieve from the cache. |
|
425 | - $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
424 | + // Maybe retrieve from the cache. |
|
425 | + $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
426 | 426 | |
427 | - // If not found, retrieve from the db. |
|
428 | - if ( false === $items ) { |
|
429 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
427 | + // If not found, retrieve from the db. |
|
428 | + if ( false === $items ) { |
|
429 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
430 | 430 | |
431 | - $items = $wpdb->get_results( |
|
432 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
433 | - ); |
|
431 | + $items = $wpdb->get_results( |
|
432 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
433 | + ); |
|
434 | 434 | |
435 | - // Update the cache with our data |
|
436 | - wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
435 | + // Update the cache with our data |
|
436 | + wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
437 | 437 | |
438 | - } |
|
438 | + } |
|
439 | 439 | |
440 | - // Abort if no items found. |
|
440 | + // Abort if no items found. |
|
441 | 441 | if ( empty( $items ) ) { |
442 | 442 | return; |
443 | - } |
|
443 | + } |
|
444 | 444 | |
445 | - foreach ( $items as $item_data ) { |
|
446 | - $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
445 | + foreach ( $items as $item_data ) { |
|
446 | + $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
447 | 447 | |
448 | - // Set item data. |
|
449 | - $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
450 | - $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
451 | - $item->set_name( $item_data->item_name ); |
|
452 | - $item->set_description( $item_data->item_description ); |
|
453 | - $item->set_price( $item_data->item_price ); |
|
454 | - $item->set_quantity( $item_data->quantity ); |
|
455 | - $item->set_item_meta( $item_data->meta ); |
|
448 | + // Set item data. |
|
449 | + $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
450 | + $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
451 | + $item->set_name( $item_data->item_name ); |
|
452 | + $item->set_description( $item_data->item_description ); |
|
453 | + $item->set_price( $item_data->item_price ); |
|
454 | + $item->set_quantity( $item_data->quantity ); |
|
455 | + $item->set_item_meta( $item_data->meta ); |
|
456 | 456 | |
457 | - $invoice->add_item( $item ); |
|
458 | - } |
|
457 | + $invoice->add_item( $item ); |
|
458 | + } |
|
459 | 459 | |
460 | - } |
|
460 | + } |
|
461 | 461 | |
462 | - /** |
|
462 | + /** |
|
463 | 463 | * Saves cart details. |
464 | - * |
|
465 | - * @param WPInv_Invoice $invoice Invoice object. |
|
464 | + * |
|
465 | + * @param WPInv_Invoice $invoice Invoice object. |
|
466 | 466 | */ |
467 | 467 | public function save_items( $invoice ) { |
468 | 468 | |
469 | - // Delete previously existing items. |
|
470 | - $this->delete_items( $invoice ); |
|
469 | + // Delete previously existing items. |
|
470 | + $this->delete_items( $invoice ); |
|
471 | 471 | |
472 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
472 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
473 | 473 | |
474 | - foreach ( $invoice->get_cart_details() as $item_data ) { |
|
475 | - $item_data = array_map( 'maybe_serialize', $item_data ); |
|
476 | - $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
477 | - } |
|
474 | + foreach ( $invoice->get_cart_details() as $item_data ) { |
|
475 | + $item_data = array_map( 'maybe_serialize', $item_data ); |
|
476 | + $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
477 | + } |
|
478 | 478 | |
479 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
480 | - do_action( "getpaid_invoice_save_items", $invoice ); |
|
479 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
480 | + do_action( "getpaid_invoice_save_items", $invoice ); |
|
481 | 481 | |
482 | - } |
|
482 | + } |
|
483 | 483 | |
484 | - /** |
|
484 | + /** |
|
485 | 485 | * Deletes an invoice's cart details from the database. |
486 | - * |
|
487 | - * @param WPInv_Invoice $invoice Invoice object. |
|
486 | + * |
|
487 | + * @param WPInv_Invoice $invoice Invoice object. |
|
488 | 488 | */ |
489 | 489 | public function delete_items( $invoice ) { |
490 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
491 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
492 | - } |
|
490 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
491 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
492 | + } |
|
493 | 493 | |
494 | - /** |
|
494 | + /** |
|
495 | 495 | * Deletes an invoice's special fields from the database. |
496 | - * |
|
497 | - * @param WPInv_Invoice $invoice Invoice object. |
|
496 | + * |
|
497 | + * @param WPInv_Invoice $invoice Invoice object. |
|
498 | 498 | */ |
499 | 499 | public function delete_special_fields( $invoice ) { |
500 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
501 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
500 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
501 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | } |
@@ -4,7 +4,7 @@ discard block |
||
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 | |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @param WPInv_Invoice $invoice Invoice object. |
105 | 105 | */ |
106 | - public function create( &$invoice ) { |
|
107 | - $invoice->set_version( WPINV_VERSION ); |
|
108 | - $invoice->set_date_created( current_time('mysql') ); |
|
106 | + public function create(&$invoice) { |
|
107 | + $invoice->set_version(WPINV_VERSION); |
|
108 | + $invoice->set_date_created(current_time('mysql')); |
|
109 | 109 | |
110 | 110 | // Ensure both the key and number are set. |
111 | 111 | $invoice->get_key(); |
@@ -116,34 +116,34 @@ discard block |
||
116 | 116 | apply_filters( |
117 | 117 | 'getpaid_new_invoice_data', |
118 | 118 | array( |
119 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
120 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
121 | - 'post_status' => $this->get_post_status( $invoice ), |
|
119 | + 'post_date' => $invoice->get_date_created('edit'), |
|
120 | + 'post_type' => $invoice->get_post_type('edit'), |
|
121 | + 'post_status' => $this->get_post_status($invoice), |
|
122 | 122 | 'ping_status' => 'closed', |
123 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
124 | - 'post_title' => $invoice->get_number( 'edit' ), |
|
125 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
126 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
127 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
123 | + 'post_author' => $invoice->get_user_id('edit'), |
|
124 | + 'post_title' => $invoice->get_number('edit'), |
|
125 | + 'post_excerpt' => $invoice->get_description('edit'), |
|
126 | + 'post_parent' => $invoice->get_parent_id('edit'), |
|
127 | + 'post_name' => $invoice->get_path('edit'), |
|
128 | 128 | ) |
129 | 129 | ), |
130 | 130 | true |
131 | 131 | ); |
132 | 132 | |
133 | - if ( $id && ! is_wp_error( $id ) ) { |
|
134 | - $invoice->set_id( $id ); |
|
135 | - getpaid_save_invoice_user_address( $invoice ); |
|
136 | - $this->save_special_fields( $invoice ); |
|
137 | - $this->save_items( $invoice ); |
|
138 | - $this->update_post_meta( $invoice ); |
|
133 | + if ($id && !is_wp_error($id)) { |
|
134 | + $invoice->set_id($id); |
|
135 | + getpaid_save_invoice_user_address($invoice); |
|
136 | + $this->save_special_fields($invoice); |
|
137 | + $this->save_items($invoice); |
|
138 | + $this->update_post_meta($invoice); |
|
139 | 139 | $invoice->save_meta_data(); |
140 | 140 | $invoice->apply_changes(); |
141 | - $this->clear_caches( $invoice ); |
|
142 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
141 | + $this->clear_caches($invoice); |
|
142 | + do_action('getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice); |
|
143 | 143 | return true; |
144 | 144 | } |
145 | 145 | |
146 | - if ( is_wp_error( $id ) ) { |
|
146 | + if (is_wp_error($id)) { |
|
147 | 147 | $invoice->last_error = $id->get_error_message(); |
148 | 148 | } |
149 | 149 | |
@@ -156,14 +156,14 @@ discard block |
||
156 | 156 | * @param WPInv_Invoice $invoice Invoice object. |
157 | 157 | * |
158 | 158 | */ |
159 | - public function read( &$invoice ) { |
|
159 | + public function read(&$invoice) { |
|
160 | 160 | |
161 | 161 | $invoice->set_defaults(); |
162 | - $invoice_object = get_post( $invoice->get_id() ); |
|
162 | + $invoice_object = get_post($invoice->get_id()); |
|
163 | 163 | |
164 | - if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
165 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
166 | - $invoice->set_id( 0 ); |
|
164 | + if (!$invoice->get_id() || !$invoice_object || !getpaid_is_invoice_post_type($invoice_object->post_type)) { |
|
165 | + $invoice->last_error = __('Invalid invoice.', 'invoicing'); |
|
166 | + $invoice->set_id(0); |
|
167 | 167 | return false; |
168 | 168 | } |
169 | 169 | |
@@ -181,14 +181,14 @@ discard block |
||
181 | 181 | ) |
182 | 182 | ); |
183 | 183 | |
184 | - $invoice->set_type( $invoice_object->post_type ); |
|
184 | + $invoice->set_type($invoice_object->post_type); |
|
185 | 185 | |
186 | - $this->read_object_data( $invoice, $invoice_object ); |
|
187 | - $this->add_special_fields( $invoice ); |
|
188 | - $this->add_items( $invoice ); |
|
186 | + $this->read_object_data($invoice, $invoice_object); |
|
187 | + $this->add_special_fields($invoice); |
|
188 | + $this->add_items($invoice); |
|
189 | 189 | $invoice->read_meta_data(); |
190 | - $invoice->set_object_read( true ); |
|
191 | - do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
190 | + $invoice->set_object_read(true); |
|
191 | + do_action('getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice); |
|
192 | 192 | |
193 | 193 | } |
194 | 194 | |
@@ -197,12 +197,12 @@ discard block |
||
197 | 197 | * |
198 | 198 | * @param WPInv_Invoice $invoice Invoice object. |
199 | 199 | */ |
200 | - public function update( &$invoice ) { |
|
200 | + public function update(&$invoice) { |
|
201 | 201 | $invoice->save_meta_data(); |
202 | - $invoice->set_version( WPINV_VERSION ); |
|
202 | + $invoice->set_version(WPINV_VERSION); |
|
203 | 203 | |
204 | - if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
205 | - $invoice->set_date_created( current_time('mysql') ); |
|
204 | + if (null === $invoice->get_date_created('edit')) { |
|
205 | + $invoice->set_date_created(current_time('mysql')); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | // Ensure both the key and number are set. |
@@ -210,22 +210,22 @@ discard block |
||
210 | 210 | $invoice->get_number(); |
211 | 211 | |
212 | 212 | // Grab the current status so we can compare. |
213 | - $previous_status = get_post_status( $invoice->get_id() ); |
|
213 | + $previous_status = get_post_status($invoice->get_id()); |
|
214 | 214 | |
215 | 215 | $changes = $invoice->get_changes(); |
216 | 216 | |
217 | 217 | // Only update the post when the post data changes. |
218 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
218 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path'), array_keys($changes))) { |
|
219 | 219 | $post_data = array( |
220 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
221 | - 'post_status' => $invoice->get_status( 'edit' ), |
|
222 | - 'post_title' => $invoice->get_name( 'edit' ), |
|
223 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
224 | - 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
225 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
226 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
227 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
228 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
220 | + 'post_date' => $invoice->get_date_created('edit'), |
|
221 | + 'post_status' => $invoice->get_status('edit'), |
|
222 | + 'post_title' => $invoice->get_name('edit'), |
|
223 | + 'post_author' => $invoice->get_user_id('edit'), |
|
224 | + 'post_modified' => $invoice->get_date_modified('edit'), |
|
225 | + 'post_excerpt' => $invoice->get_description('edit'), |
|
226 | + 'post_parent' => $invoice->get_parent_id('edit'), |
|
227 | + 'post_name' => $invoice->get_path('edit'), |
|
228 | + 'post_type' => $invoice->get_post_type('edit'), |
|
229 | 229 | ); |
230 | 230 | |
231 | 231 | /** |
@@ -236,28 +236,28 @@ discard block |
||
236 | 236 | * This ensures hooks are fired by either WP itself (admin screen save), |
237 | 237 | * or an update purely from CRUD. |
238 | 238 | */ |
239 | - if ( doing_action( 'save_post' ) ) { |
|
240 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
241 | - clean_post_cache( $invoice->get_id() ); |
|
239 | + if (doing_action('save_post')) { |
|
240 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $invoice->get_id())); |
|
241 | + clean_post_cache($invoice->get_id()); |
|
242 | 242 | } else { |
243 | - wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
243 | + wp_update_post(array_merge(array('ID' => $invoice->get_id()), $post_data)); |
|
244 | 244 | } |
245 | - $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
245 | + $invoice->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
246 | 246 | } |
247 | - $this->update_post_meta( $invoice ); |
|
248 | - $this->save_special_fields( $invoice ); |
|
249 | - $this->save_items( $invoice ); |
|
247 | + $this->update_post_meta($invoice); |
|
248 | + $this->save_special_fields($invoice); |
|
249 | + $this->save_items($invoice); |
|
250 | 250 | $invoice->apply_changes(); |
251 | - getpaid_save_invoice_user_address( $invoice ); |
|
252 | - $this->clear_caches( $invoice ); |
|
251 | + getpaid_save_invoice_user_address($invoice); |
|
252 | + $this->clear_caches($invoice); |
|
253 | 253 | |
254 | 254 | // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
255 | - $new_status = $invoice->get_status( 'edit' ); |
|
255 | + $new_status = $invoice->get_status('edit'); |
|
256 | 256 | |
257 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
258 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
257 | + if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) { |
|
258 | + do_action('getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice); |
|
259 | 259 | } else { |
260 | - do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
260 | + do_action('getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | } |
@@ -273,43 +273,43 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @param WPInv_Invoice $invoice Invoice object. |
275 | 275 | */ |
276 | - public function add_special_fields( &$invoice ) { |
|
276 | + public function add_special_fields(&$invoice) { |
|
277 | 277 | global $wpdb; |
278 | 278 | |
279 | 279 | // Maybe retrieve from the cache. |
280 | - $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
280 | + $data = wp_cache_get($invoice->get_id(), 'getpaid_invoice_special_fields'); |
|
281 | 281 | |
282 | 282 | // If not found, retrieve from the db. |
283 | - if ( false === $data ) { |
|
284 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
283 | + if (false === $data) { |
|
284 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
285 | 285 | |
286 | 286 | $data = $wpdb->get_row( |
287 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
287 | + $wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id()), |
|
288 | 288 | ARRAY_A |
289 | 289 | ); |
290 | 290 | |
291 | 291 | // Update the cache with our data |
292 | - wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
292 | + wp_cache_set($invoice->get_id(), $data, 'getpaid_invoice_special_fields'); |
|
293 | 293 | |
294 | 294 | } |
295 | 295 | |
296 | 296 | // Abort if the data does not exist. |
297 | - if ( empty( $data ) ) { |
|
297 | + if (empty($data)) { |
|
298 | 298 | return; |
299 | 299 | } |
300 | 300 | |
301 | 301 | $props = array(); |
302 | 302 | |
303 | - foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
303 | + foreach ($this->database_fields_to_props as $db_field => $prop) { |
|
304 | 304 | |
305 | - if ( $db_field == 'post_id' ) { |
|
305 | + if ($db_field == 'post_id') { |
|
306 | 306 | continue; |
307 | 307 | } |
308 | 308 | |
309 | - $props[ $prop ] = $data[ $db_field ]; |
|
309 | + $props[$prop] = $data[$db_field]; |
|
310 | 310 | } |
311 | 311 | |
312 | - $invoice->set_props( $props ); |
|
312 | + $invoice->set_props($props); |
|
313 | 313 | |
314 | 314 | } |
315 | 315 | |
@@ -320,14 +320,14 @@ discard block |
||
320 | 320 | * @param WPInv_Invoice $invoice The Invoice object. |
321 | 321 | * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
322 | 322 | */ |
323 | - protected function get_special_fields_to_update( $invoice ) { |
|
323 | + protected function get_special_fields_to_update($invoice) { |
|
324 | 324 | $fields_to_update = array(); |
325 | - $changed_props = $invoice->get_changes(); |
|
325 | + $changed_props = $invoice->get_changes(); |
|
326 | 326 | |
327 | 327 | // Props should be updated if they are a part of the $changed array or don't exist yet. |
328 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
329 | - if ( array_key_exists( $prop, $changed_props ) ) { |
|
330 | - $fields_to_update[ $database_field ] = $prop; |
|
328 | + foreach ($this->database_fields_to_props as $database_field => $prop) { |
|
329 | + if (array_key_exists($prop, $changed_props)) { |
|
330 | + $fields_to_update[$database_field] = $prop; |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | |
@@ -340,25 +340,25 @@ discard block |
||
340 | 340 | * @param WPInv_Invoice $invoice WPInv_Invoice object. |
341 | 341 | * @since 1.0.19 |
342 | 342 | */ |
343 | - protected function update_special_fields( &$invoice ) { |
|
343 | + protected function update_special_fields(&$invoice) { |
|
344 | 344 | global $wpdb; |
345 | 345 | |
346 | 346 | $updated_props = array(); |
347 | - $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
347 | + $fields_to_update = $this->get_special_fields_to_update($invoice); |
|
348 | 348 | |
349 | - foreach ( $fields_to_update as $database_field => $prop ) { |
|
350 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
351 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
352 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
353 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
349 | + foreach ($fields_to_update as $database_field => $prop) { |
|
350 | + $value = $invoice->{"get_$prop"}('edit'); |
|
351 | + $value = is_string($value) ? wp_slash($value) : $value; |
|
352 | + $value = is_bool($value) ? (int) $value : $value; |
|
353 | + $updated_props[$database_field] = maybe_serialize($value); |
|
354 | 354 | } |
355 | 355 | |
356 | - if ( ! empty( $updated_props ) ) { |
|
356 | + if (!empty($updated_props)) { |
|
357 | 357 | |
358 | 358 | $table = $wpdb->prefix . 'getpaid_invoices'; |
359 | - $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
360 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
361 | - do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
359 | + $wpdb->update($table, $updated_props, array('post_id' => $invoice->get_id())); |
|
360 | + wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields'); |
|
361 | + do_action("getpaid_invoice_update_database_fields", $invoice, $updated_props); |
|
362 | 362 | |
363 | 363 | } |
364 | 364 | |
@@ -370,22 +370,22 @@ discard block |
||
370 | 370 | * @param WPInv_Invoice $invoice WPInv_Invoice object. |
371 | 371 | * @since 1.0.19 |
372 | 372 | */ |
373 | - protected function insert_special_fields( &$invoice ) { |
|
373 | + protected function insert_special_fields(&$invoice) { |
|
374 | 374 | global $wpdb; |
375 | 375 | |
376 | - $updated_props = array(); |
|
376 | + $updated_props = array(); |
|
377 | 377 | |
378 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
379 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
380 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
381 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
382 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
378 | + foreach ($this->database_fields_to_props as $database_field => $prop) { |
|
379 | + $value = $invoice->{"get_$prop"}('edit'); |
|
380 | + $value = is_string($value) ? wp_slash($value) : $value; |
|
381 | + $value = is_bool($value) ? (int) $value : $value; |
|
382 | + $updated_props[$database_field] = maybe_serialize($value); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | $table = $wpdb->prefix . 'getpaid_invoices'; |
386 | - $wpdb->insert( $table, $updated_props ); |
|
387 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
388 | - do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
386 | + $wpdb->insert($table, $updated_props); |
|
387 | + wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields'); |
|
388 | + do_action("getpaid_invoice_insert_database_fields", $invoice, $updated_props); |
|
389 | 389 | |
390 | 390 | } |
391 | 391 | |
@@ -394,20 +394,20 @@ discard block |
||
394 | 394 | * |
395 | 395 | * @param WPInv_Invoice $invoice Invoice object. |
396 | 396 | */ |
397 | - public function save_special_fields( $invoice ) { |
|
397 | + public function save_special_fields($invoice) { |
|
398 | 398 | global $wpdb; |
399 | 399 | |
400 | 400 | // The invoices table. |
401 | 401 | $table = $wpdb->prefix . 'getpaid_invoices'; |
402 | 402 | $id = (int) $invoice->get_id(); |
403 | 403 | |
404 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
404 | + if ($wpdb->get_var("SELECT `post_id` FROM $table WHERE `post_id`= $id")) { |
|
405 | 405 | |
406 | - $this->update_special_fields( $invoice ); |
|
406 | + $this->update_special_fields($invoice); |
|
407 | 407 | |
408 | 408 | } else { |
409 | 409 | |
410 | - $this->insert_special_fields( $invoice ); |
|
410 | + $this->insert_special_fields($invoice); |
|
411 | 411 | |
412 | 412 | } |
413 | 413 | |
@@ -418,43 +418,43 @@ discard block |
||
418 | 418 | * |
419 | 419 | * @param WPInv_Invoice $invoice Invoice object. |
420 | 420 | */ |
421 | - public function add_items( &$invoice ) { |
|
421 | + public function add_items(&$invoice) { |
|
422 | 422 | global $wpdb; |
423 | 423 | |
424 | 424 | // Maybe retrieve from the cache. |
425 | - $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
425 | + $items = wp_cache_get($invoice->get_id(), 'getpaid_invoice_cart_details'); |
|
426 | 426 | |
427 | 427 | // If not found, retrieve from the db. |
428 | - if ( false === $items ) { |
|
429 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
428 | + if (false === $items) { |
|
429 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
430 | 430 | |
431 | 431 | $items = $wpdb->get_results( |
432 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
432 | + $wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id()) |
|
433 | 433 | ); |
434 | 434 | |
435 | 435 | // Update the cache with our data |
436 | - wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
436 | + wp_cache_set($invoice->get_id(), $items, 'getpaid_invoice_cart_details'); |
|
437 | 437 | |
438 | 438 | } |
439 | 439 | |
440 | 440 | // Abort if no items found. |
441 | - if ( empty( $items ) ) { |
|
441 | + if (empty($items)) { |
|
442 | 442 | return; |
443 | 443 | } |
444 | 444 | |
445 | - foreach ( $items as $item_data ) { |
|
446 | - $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
445 | + foreach ($items as $item_data) { |
|
446 | + $item = new GetPaid_Form_Item($item_data->item_id); |
|
447 | 447 | |
448 | 448 | // Set item data. |
449 | - $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
450 | - $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
451 | - $item->set_name( $item_data->item_name ); |
|
452 | - $item->set_description( $item_data->item_description ); |
|
453 | - $item->set_price( $item_data->item_price ); |
|
454 | - $item->set_quantity( $item_data->quantity ); |
|
455 | - $item->set_item_meta( $item_data->meta ); |
|
456 | - |
|
457 | - $invoice->add_item( $item ); |
|
449 | + $item->item_tax = wpinv_sanitize_amount($item_data->tax); |
|
450 | + $item->item_discount = wpinv_sanitize_amount($item_data->discount); |
|
451 | + $item->set_name($item_data->item_name); |
|
452 | + $item->set_description($item_data->item_description); |
|
453 | + $item->set_price($item_data->item_price); |
|
454 | + $item->set_quantity($item_data->quantity); |
|
455 | + $item->set_item_meta($item_data->meta); |
|
456 | + |
|
457 | + $invoice->add_item($item); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | } |
@@ -464,20 +464,20 @@ discard block |
||
464 | 464 | * |
465 | 465 | * @param WPInv_Invoice $invoice Invoice object. |
466 | 466 | */ |
467 | - public function save_items( $invoice ) { |
|
467 | + public function save_items($invoice) { |
|
468 | 468 | |
469 | 469 | // Delete previously existing items. |
470 | - $this->delete_items( $invoice ); |
|
470 | + $this->delete_items($invoice); |
|
471 | 471 | |
472 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
472 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
473 | 473 | |
474 | - foreach ( $invoice->get_cart_details() as $item_data ) { |
|
475 | - $item_data = array_map( 'maybe_serialize', $item_data ); |
|
476 | - $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
474 | + foreach ($invoice->get_cart_details() as $item_data) { |
|
475 | + $item_data = array_map('maybe_serialize', $item_data); |
|
476 | + $GLOBALS['wpdb']->insert($table, $item_data); |
|
477 | 477 | } |
478 | 478 | |
479 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
480 | - do_action( "getpaid_invoice_save_items", $invoice ); |
|
479 | + wp_cache_delete($invoice->get_id(), 'getpaid_invoice_cart_details'); |
|
480 | + do_action("getpaid_invoice_save_items", $invoice); |
|
481 | 481 | |
482 | 482 | } |
483 | 483 | |
@@ -486,9 +486,9 @@ discard block |
||
486 | 486 | * |
487 | 487 | * @param WPInv_Invoice $invoice Invoice object. |
488 | 488 | */ |
489 | - public function delete_items( $invoice ) { |
|
490 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
491 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
489 | + public function delete_items($invoice) { |
|
490 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
491 | + return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id())); |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | /** |
@@ -496,9 +496,9 @@ discard block |
||
496 | 496 | * |
497 | 497 | * @param WPInv_Invoice $invoice Invoice object. |
498 | 498 | */ |
499 | - public function delete_special_fields( $invoice ) { |
|
500 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
501 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
499 | + public function delete_special_fields($invoice) { |
|
500 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
501 | + return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id())); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | } |
@@ -7,46 +7,46 @@ |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | |
15 | 15 | function wpinv_get_default_labels() { |
16 | 16 | $defaults = array( |
17 | - 'singular' => __( 'Invoice', 'invoicing' ), |
|
18 | - 'plural' => __( 'Invoices', 'invoicing' ) |
|
17 | + 'singular' => __('Invoice', 'invoicing'), |
|
18 | + 'plural' => __('Invoices', 'invoicing') |
|
19 | 19 | ); |
20 | 20 | |
21 | - return apply_filters( 'wpinv_default_invoices_name', $defaults ); |
|
21 | + return apply_filters('wpinv_default_invoices_name', $defaults); |
|
22 | 22 | } |
23 | 23 | |
24 | -function wpinv_get_label_singular( $lowercase = false ) { |
|
24 | +function wpinv_get_label_singular($lowercase = false) { |
|
25 | 25 | $defaults = wpinv_get_default_labels(); |
26 | 26 | |
27 | - return ($lowercase) ? strtolower( $defaults['singular'] ) : $defaults['singular']; |
|
27 | + return ($lowercase) ? strtolower($defaults['singular']) : $defaults['singular']; |
|
28 | 28 | } |
29 | 29 | |
30 | -function wpinv_get_label_plural( $lowercase = false ) { |
|
30 | +function wpinv_get_label_plural($lowercase = false) { |
|
31 | 31 | $defaults = wpinv_get_default_labels(); |
32 | 32 | |
33 | - return ( $lowercase ) ? strtolower( $defaults['plural'] ) : $defaults['plural']; |
|
33 | + return ($lowercase) ? strtolower($defaults['plural']) : $defaults['plural']; |
|
34 | 34 | } |
35 | 35 | |
36 | -function wpinv_change_default_title( $title ) { |
|
37 | - if ( !is_admin() ) { |
|
36 | +function wpinv_change_default_title($title) { |
|
37 | + if (!is_admin()) { |
|
38 | 38 | $label = wpinv_get_label_singular(); |
39 | - $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label ); |
|
39 | + $title = sprintf(__('Enter %s name here', 'invoicing'), $label); |
|
40 | 40 | return $title; |
41 | 41 | } |
42 | 42 | |
43 | 43 | $screen = get_current_screen(); |
44 | 44 | |
45 | - if ( 'wpi_invoice' == $screen->post_type ) { |
|
45 | + if ('wpi_invoice' == $screen->post_type) { |
|
46 | 46 | $label = wpinv_get_label_singular(); |
47 | - $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label ); |
|
47 | + $title = sprintf(__('Enter %s name here', 'invoicing'), $label); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | return $title; |
51 | 51 | } |
52 | -add_filter( 'enter_title_here', 'wpinv_change_default_title' ); |
|
52 | +add_filter('enter_title_here', 'wpinv_change_default_title'); |
@@ -159,11 +159,11 @@ discard block |
||
159 | 159 | */ |
160 | 160 | function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) { |
161 | 161 | |
162 | - if ( current_user_can( 'manage_options' ) ) { |
|
163 | - return 'manage_options'; |
|
164 | - }; |
|
162 | + if ( current_user_can( 'manage_options' ) ) { |
|
163 | + return 'manage_options'; |
|
164 | + }; |
|
165 | 165 | |
166 | - return $capalibilty; |
|
166 | + return $capalibilty; |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -185,10 +185,10 @@ discard block |
||
185 | 185 | function wpinv_create_user( $email ) { |
186 | 186 | |
187 | 187 | // Prepare user values. |
188 | - $args = array( |
|
189 | - 'user_login' => wpinv_generate_user_name( $email ), |
|
190 | - 'user_pass' => wp_generate_password(), |
|
191 | - 'user_email' => $email, |
|
188 | + $args = array( |
|
189 | + 'user_login' => wpinv_generate_user_name( $email ), |
|
190 | + 'user_pass' => wp_generate_password(), |
|
191 | + 'user_email' => $email, |
|
192 | 192 | 'role' => 'subscriber', |
193 | 193 | ); |
194 | 194 | |
@@ -205,20 +205,20 @@ discard block |
||
205 | 205 | function wpinv_generate_user_name( $prefix = '' ) { |
206 | 206 | |
207 | 207 | // If prefix is an email, retrieve the part before the email. |
208 | - $prefix = strtok( $prefix, '@' ); |
|
208 | + $prefix = strtok( $prefix, '@' ); |
|
209 | 209 | |
210 | - // Trim to 4 characters max. |
|
211 | - $prefix = sanitize_user( $prefix ); |
|
210 | + // Trim to 4 characters max. |
|
211 | + $prefix = sanitize_user( $prefix ); |
|
212 | 212 | |
213 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
214 | - if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
215 | - $prefix = 'gtp'; |
|
216 | - } |
|
213 | + $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
214 | + if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
215 | + $prefix = 'gtp'; |
|
216 | + } |
|
217 | 217 | |
218 | - $username = $prefix . '_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
219 | - if ( username_exists( $username ) ) { |
|
220 | - return wpinv_generate_user_name( $username ); |
|
221 | - } |
|
218 | + $username = $prefix . '_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
219 | + if ( username_exists( $username ) ) { |
|
220 | + return wpinv_generate_user_name( $username ); |
|
221 | + } |
|
222 | 222 | |
223 | 223 | return $username; |
224 | 224 | } |
@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'publish', $orderby = 'ID', $order = 'DESC' ) { |
|
6 | - if ( empty( $user ) ) { |
|
5 | +function wpinv_get_users_invoices($user = 0, $number = 20, $pagination = false, $status = 'publish', $orderby = 'ID', $order = 'DESC') { |
|
6 | + if (empty($user)) { |
|
7 | 7 | $user = get_current_user_id(); |
8 | 8 | } |
9 | 9 | |
10 | - if ( empty( $user ) ) { |
|
10 | + if (empty($user)) { |
|
11 | 11 | return false; |
12 | 12 | } |
13 | 13 | |
14 | - $args = apply_filters( 'wpinv_get_users_invoices_args', array( 'user' => $user, 'limit' => $number, 'status' => $status, 'paginate' => $pagination, 'orderby' => $orderby, 'order' => $order ) ); |
|
14 | + $args = apply_filters('wpinv_get_users_invoices_args', array('user' => $user, 'limit' => $number, 'status' => $status, 'paginate' => $pagination, 'orderby' => $orderby, 'order' => $order)); |
|
15 | 15 | |
16 | - return wpinv_get_invoices( $args ); |
|
16 | + return wpinv_get_invoices($args); |
|
17 | 17 | } |
18 | 18 | |
19 | -function wpinv_dropdown_users( $args = '' ) { |
|
19 | +function wpinv_dropdown_users($args = '') { |
|
20 | 20 | $defaults = array( |
21 | 21 | 'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '', |
22 | 22 | 'orderby' => 'display_name', 'order' => 'ASC', |
@@ -27,18 +27,18 @@ discard block |
||
27 | 27 | 'option_none_value' => -1 |
28 | 28 | ); |
29 | 29 | |
30 | - $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; |
|
30 | + $defaults['selected'] = is_author() ? get_query_var('author') : 0; |
|
31 | 31 | |
32 | - $r = wp_parse_args( $args, $defaults ); |
|
32 | + $r = wp_parse_args($args, $defaults); |
|
33 | 33 | |
34 | - $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) ); |
|
34 | + $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who')); |
|
35 | 35 | |
36 | - $fields = array( 'ID', 'user_login', 'user_email' ); |
|
36 | + $fields = array('ID', 'user_login', 'user_email'); |
|
37 | 37 | |
38 | - $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name'; |
|
39 | - if ( 'display_name_with_login' === $show ) { |
|
38 | + $show = !empty($r['show']) ? $r['show'] : 'display_name'; |
|
39 | + if ('display_name_with_login' === $show) { |
|
40 | 40 | $fields[] = 'display_name'; |
41 | - } else if ( 'display_name_with_email' === $show ) { |
|
41 | + } else if ('display_name_with_email' === $show) { |
|
42 | 42 | $fields[] = 'display_name'; |
43 | 43 | } else { |
44 | 44 | $fields[] = $show; |
@@ -50,99 +50,99 @@ discard block |
||
50 | 50 | $show_option_none = $r['show_option_none']; |
51 | 51 | $option_none_value = $r['option_none_value']; |
52 | 52 | |
53 | - $query_args = apply_filters( 'wpinv_dropdown_users_args', $query_args, $r ); |
|
53 | + $query_args = apply_filters('wpinv_dropdown_users_args', $query_args, $r); |
|
54 | 54 | |
55 | - $users = get_users( $query_args ); |
|
55 | + $users = get_users($query_args); |
|
56 | 56 | |
57 | 57 | $output = ''; |
58 | - if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) { |
|
59 | - $name = esc_attr( $r['name'] ); |
|
60 | - if ( $r['multi'] && ! $r['id'] ) { |
|
58 | + if (!empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) { |
|
59 | + $name = esc_attr($r['name']); |
|
60 | + if ($r['multi'] && !$r['id']) { |
|
61 | 61 | $id = ''; |
62 | 62 | } else { |
63 | - $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'"; |
|
63 | + $id = $r['id'] ? " id='" . esc_attr($r['id']) . "'" : " id='$name'"; |
|
64 | 64 | } |
65 | 65 | $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n"; |
66 | 66 | |
67 | - if ( $show_option_all ) { |
|
67 | + if ($show_option_all) { |
|
68 | 68 | $output .= "\t<option value='0'>$show_option_all</option>\n"; |
69 | 69 | } |
70 | 70 | |
71 | - if ( $show_option_none ) { |
|
72 | - $_selected = selected( $option_none_value, $r['selected'], false ); |
|
73 | - $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n"; |
|
71 | + if ($show_option_none) { |
|
72 | + $_selected = selected($option_none_value, $r['selected'], false); |
|
73 | + $output .= "\t<option value='" . esc_attr($option_none_value) . "'$_selected>$show_option_none</option>\n"; |
|
74 | 74 | } |
75 | 75 | |
76 | - if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) { |
|
76 | + if ($r['include_selected'] && ($r['selected'] > 0)) { |
|
77 | 77 | $found_selected = false; |
78 | 78 | $r['selected'] = (int) $r['selected']; |
79 | - foreach ( (array) $users as $user ) { |
|
79 | + foreach ((array) $users as $user) { |
|
80 | 80 | $user->ID = (int) $user->ID; |
81 | - if ( $user->ID === $r['selected'] ) { |
|
81 | + if ($user->ID === $r['selected']) { |
|
82 | 82 | $found_selected = true; |
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
86 | - if ( ! $found_selected ) { |
|
87 | - $users[] = get_userdata( $r['selected'] ); |
|
86 | + if (!$found_selected) { |
|
87 | + $users[] = get_userdata($r['selected']); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
91 | - foreach ( (array) $users as $user ) { |
|
92 | - if ( 'display_name_with_login' === $show ) { |
|
91 | + foreach ((array) $users as $user) { |
|
92 | + if ('display_name_with_login' === $show) { |
|
93 | 93 | /* translators: 1: display name, 2: user_login */ |
94 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login ); |
|
95 | - } elseif ( 'display_name_with_email' === $show ) { |
|
94 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login); |
|
95 | + } elseif ('display_name_with_email' === $show) { |
|
96 | 96 | /* translators: 1: display name, 2: user_email */ |
97 | - if ( $user->display_name == $user->user_email ) { |
|
97 | + if ($user->display_name == $user->user_email) { |
|
98 | 98 | $display = $user->display_name; |
99 | 99 | } else { |
100 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_email ); |
|
100 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_email); |
|
101 | 101 | } |
102 | - } elseif ( ! empty( $user->$show ) ) { |
|
102 | + } elseif (!empty($user->$show)) { |
|
103 | 103 | $display = $user->$show; |
104 | 104 | } else { |
105 | 105 | $display = '(' . $user->user_login . ')'; |
106 | 106 | } |
107 | 107 | |
108 | - $_selected = selected( $user->ID, $r['selected'], false ); |
|
109 | - $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n"; |
|
108 | + $_selected = selected($user->ID, $r['selected'], false); |
|
109 | + $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n"; |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | $output .= "</select>"; |
113 | 113 | } |
114 | 114 | |
115 | - $html = apply_filters( 'wpinv_dropdown_users', $output ); |
|
115 | + $html = apply_filters('wpinv_dropdown_users', $output); |
|
116 | 116 | |
117 | - if ( $r['echo'] ) { |
|
117 | + if ($r['echo']) { |
|
118 | 118 | echo $html; |
119 | 119 | } |
120 | 120 | return $html; |
121 | 121 | } |
122 | 122 | |
123 | -function wpinv_guest_redirect( $redirect_to, $user_id = 0 ) { |
|
124 | - if ( (int)wpinv_get_option( 'guest_checkout' ) && $user_id > 0 ) { |
|
125 | - wpinv_login_user( $user_id ); |
|
123 | +function wpinv_guest_redirect($redirect_to, $user_id = 0) { |
|
124 | + if ((int) wpinv_get_option('guest_checkout') && $user_id > 0) { |
|
125 | + wpinv_login_user($user_id); |
|
126 | 126 | } else { |
127 | - $redirect_to = wp_login_url( $redirect_to ); |
|
127 | + $redirect_to = wp_login_url($redirect_to); |
|
128 | 128 | } |
129 | 129 | |
130 | - $redirect_to = apply_filters( 'wpinv_invoice_link_guest_redirect', $redirect_to, $user_id ); |
|
130 | + $redirect_to = apply_filters('wpinv_invoice_link_guest_redirect', $redirect_to, $user_id); |
|
131 | 131 | |
132 | - wp_redirect( $redirect_to ); |
|
132 | + wp_redirect($redirect_to); |
|
133 | 133 | } |
134 | 134 | |
135 | -function wpinv_login_user( $user_id ) { |
|
136 | - if ( is_user_logged_in() ) { |
|
135 | +function wpinv_login_user($user_id) { |
|
136 | + if (is_user_logged_in()) { |
|
137 | 137 | return true; |
138 | 138 | } |
139 | 139 | |
140 | - $user = get_user_by( 'id', $user_id ); |
|
140 | + $user = get_user_by('id', $user_id); |
|
141 | 141 | |
142 | - if ( !empty( $user ) && !is_wp_error( $user ) && !empty( $user->user_login ) ) { |
|
143 | - wp_set_current_user( $user_id, $user->user_login ); |
|
144 | - wp_set_auth_cookie( $user_id ); |
|
145 | - do_action( 'wp_login', $user->user_login ); |
|
142 | + if (!empty($user) && !is_wp_error($user) && !empty($user->user_login)) { |
|
143 | + wp_set_current_user($user_id, $user->user_login); |
|
144 | + wp_set_auth_cookie($user_id); |
|
145 | + do_action('wp_login', $user->user_login); |
|
146 | 146 | |
147 | 147 | return true; |
148 | 148 | } |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | * @return string capability to check against |
158 | 158 | * @param string $capalibilty Optional. The alternative capability to check against. |
159 | 159 | */ |
160 | -function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) { |
|
160 | +function wpinv_get_capability($capalibilty = 'manage_invoicing') { |
|
161 | 161 | |
162 | - if ( current_user_can( 'manage_options' ) ) { |
|
162 | + if (current_user_can('manage_options')) { |
|
163 | 163 | return 'manage_options'; |
164 | 164 | }; |
165 | 165 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * @return bool |
174 | 174 | */ |
175 | 175 | function wpinv_current_user_can_manage_invoicing() { |
176 | - return current_user_can( wpinv_get_capability() ); |
|
176 | + return current_user_can(wpinv_get_capability()); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -182,17 +182,17 @@ discard block |
||
182 | 182 | * @since 1.0.19 |
183 | 183 | * @return int|WP_Error |
184 | 184 | */ |
185 | -function wpinv_create_user( $email ) { |
|
185 | +function wpinv_create_user($email) { |
|
186 | 186 | |
187 | 187 | // Prepare user values. |
188 | 188 | $args = array( |
189 | - 'user_login' => wpinv_generate_user_name( $email ), |
|
189 | + 'user_login' => wpinv_generate_user_name($email), |
|
190 | 190 | 'user_pass' => wp_generate_password(), |
191 | 191 | 'user_email' => $email, |
192 | 192 | 'role' => 'subscriber', |
193 | 193 | ); |
194 | 194 | |
195 | - return wp_insert_user( $args ); |
|
195 | + return wp_insert_user($args); |
|
196 | 196 | |
197 | 197 | } |
198 | 198 | |
@@ -202,22 +202,22 @@ discard block |
||
202 | 202 | * @since 1.0.19 |
203 | 203 | * @return bool|WP_User |
204 | 204 | */ |
205 | -function wpinv_generate_user_name( $prefix = '' ) { |
|
205 | +function wpinv_generate_user_name($prefix = '') { |
|
206 | 206 | |
207 | 207 | // If prefix is an email, retrieve the part before the email. |
208 | - $prefix = strtok( $prefix, '@' ); |
|
208 | + $prefix = strtok($prefix, '@'); |
|
209 | 209 | |
210 | 210 | // Trim to 4 characters max. |
211 | - $prefix = sanitize_user( $prefix ); |
|
211 | + $prefix = sanitize_user($prefix); |
|
212 | 212 | |
213 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
214 | - if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
213 | + $illegal_logins = (array) apply_filters('illegal_user_logins', array()); |
|
214 | + if (empty($prefix) || in_array(strtolower($prefix), array_map('strtolower', $illegal_logins), true)) { |
|
215 | 215 | $prefix = 'gtp'; |
216 | 216 | } |
217 | 217 | |
218 | - $username = $prefix . '_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
219 | - if ( username_exists( $username ) ) { |
|
220 | - return wpinv_generate_user_name( $username ); |
|
218 | + $username = $prefix . '_' . zeroise(wp_rand(0, 9999), 4); |
|
219 | + if (username_exists($username)) { |
|
220 | + return wpinv_generate_user_name($username); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | return $username; |
@@ -7,206 +7,206 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_get_payment_gateways() { |
15 | 15 | // Default, built-in gateways |
16 | 16 | $gateways = array( |
17 | 17 | 'paypal' => array( |
18 | - 'admin_label' => __( 'PayPal Standard', 'invoicing' ), |
|
19 | - 'checkout_label' => __( 'PayPal Standard', 'invoicing' ), |
|
18 | + 'admin_label' => __('PayPal Standard', 'invoicing'), |
|
19 | + 'checkout_label' => __('PayPal Standard', 'invoicing'), |
|
20 | 20 | 'ordering' => 1, |
21 | 21 | ), |
22 | 22 | 'authorizenet' => array( |
23 | - 'admin_label' => __( 'Authorize.Net (AIM)', 'invoicing' ), |
|
24 | - 'checkout_label' => __( 'Authorize.Net - Credit Card / Debit Card', 'invoicing' ), |
|
23 | + 'admin_label' => __('Authorize.Net (AIM)', 'invoicing'), |
|
24 | + 'checkout_label' => __('Authorize.Net - Credit Card / Debit Card', 'invoicing'), |
|
25 | 25 | 'ordering' => 4, |
26 | 26 | ), |
27 | 27 | 'worldpay' => array( |
28 | - 'admin_label' => __( 'Worldpay', 'invoicing' ), |
|
29 | - 'checkout_label' => __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ), |
|
28 | + 'admin_label' => __('Worldpay', 'invoicing'), |
|
29 | + 'checkout_label' => __('Worldpay - Credit Card / Debit Card', 'invoicing'), |
|
30 | 30 | 'ordering' => 5, |
31 | 31 | ), |
32 | 32 | 'bank_transfer' => array( |
33 | - 'admin_label' => __( 'Pre Bank Transfer', 'invoicing' ), |
|
34 | - 'checkout_label' => __( 'Pre Bank Transfer', 'invoicing' ), |
|
33 | + 'admin_label' => __('Pre Bank Transfer', 'invoicing'), |
|
34 | + 'checkout_label' => __('Pre Bank Transfer', 'invoicing'), |
|
35 | 35 | 'ordering' => 11, |
36 | 36 | ), |
37 | 37 | 'manual' => array( |
38 | - 'admin_label' => __( 'Manual Payment', 'invoicing' ), |
|
39 | - 'checkout_label' => __( 'Manual Payment', 'invoicing' ), |
|
38 | + 'admin_label' => __('Manual Payment', 'invoicing'), |
|
39 | + 'checkout_label' => __('Manual Payment', 'invoicing'), |
|
40 | 40 | 'ordering' => 12, |
41 | 41 | ), |
42 | 42 | ); |
43 | 43 | |
44 | - return apply_filters( 'wpinv_payment_gateways', $gateways ); |
|
44 | + return apply_filters('wpinv_payment_gateways', $gateways); |
|
45 | 45 | } |
46 | 46 | |
47 | -function wpinv_payment_gateway_titles( $all_gateways ) { |
|
47 | +function wpinv_payment_gateway_titles($all_gateways) { |
|
48 | 48 | global $wpinv_options; |
49 | 49 | |
50 | 50 | $gateways = array(); |
51 | - foreach ( $all_gateways as $key => $gateway ) { |
|
52 | - if ( !empty( $wpinv_options[$key . '_title'] ) ) { |
|
53 | - $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' ); |
|
51 | + foreach ($all_gateways as $key => $gateway) { |
|
52 | + if (!empty($wpinv_options[$key . '_title'])) { |
|
53 | + $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing'); |
|
54 | 54 | } |
55 | 55 | |
56 | - $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' ); |
|
56 | + $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : ''); |
|
57 | 57 | } |
58 | 58 | |
59 | - asort( $gateways ); |
|
59 | + asort($gateways); |
|
60 | 60 | |
61 | - foreach ( $gateways as $gateway => $key ) { |
|
61 | + foreach ($gateways as $gateway => $key) { |
|
62 | 62 | $gateways[$gateway] = $all_gateways[$gateway]; |
63 | 63 | } |
64 | 64 | |
65 | 65 | return $gateways; |
66 | 66 | } |
67 | -add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 ); |
|
67 | +add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1); |
|
68 | 68 | |
69 | -function wpinv_get_enabled_payment_gateways( $sort = false ) { |
|
69 | +function wpinv_get_enabled_payment_gateways($sort = false) { |
|
70 | 70 | $gateways = wpinv_get_payment_gateways(); |
71 | - $enabled = wpinv_get_option( 'gateways', false ); |
|
71 | + $enabled = wpinv_get_option('gateways', false); |
|
72 | 72 | |
73 | 73 | $gateway_list = array(); |
74 | 74 | |
75 | - foreach ( $gateways as $key => $gateway ) { |
|
76 | - if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) { |
|
77 | - $gateway_list[ $key ] = $gateway; |
|
75 | + foreach ($gateways as $key => $gateway) { |
|
76 | + if (isset($enabled[$key]) && $enabled[$key] == 1) { |
|
77 | + $gateway_list[$key] = $gateway; |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | - if ( true === $sort ) { |
|
82 | - uasort( $gateway_list, 'wpinv_sort_gateway_order' ); |
|
81 | + if (true === $sort) { |
|
82 | + uasort($gateway_list, 'wpinv_sort_gateway_order'); |
|
83 | 83 | |
84 | 84 | // Reorder our gateways so the default is first |
85 | 85 | $default_gateway_id = wpinv_get_default_gateway(); |
86 | 86 | |
87 | - if ( wpinv_is_gateway_active( $default_gateway_id ) ) { |
|
88 | - $default_gateway = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] ); |
|
89 | - unset( $gateway_list[ $default_gateway_id ] ); |
|
87 | + if (wpinv_is_gateway_active($default_gateway_id)) { |
|
88 | + $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]); |
|
89 | + unset($gateway_list[$default_gateway_id]); |
|
90 | 90 | |
91 | - $gateway_list = array_merge( $default_gateway, $gateway_list ); |
|
91 | + $gateway_list = array_merge($default_gateway, $gateway_list); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | - return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list ); |
|
95 | + return apply_filters('wpinv_enabled_payment_gateways', $gateway_list); |
|
96 | 96 | } |
97 | 97 | |
98 | -function wpinv_sort_gateway_order( $a, $b ) { |
|
98 | +function wpinv_sort_gateway_order($a, $b) { |
|
99 | 99 | return $a['ordering'] - $b['ordering']; |
100 | 100 | } |
101 | 101 | |
102 | -function wpinv_is_gateway_active( $gateway ) { |
|
102 | +function wpinv_is_gateway_active($gateway) { |
|
103 | 103 | $gateways = wpinv_get_enabled_payment_gateways(); |
104 | 104 | |
105 | - $ret = is_array($gateways) && $gateway ? array_key_exists( $gateway, $gateways ) : false; |
|
105 | + $ret = is_array($gateways) && $gateway ? array_key_exists($gateway, $gateways) : false; |
|
106 | 106 | |
107 | - return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways ); |
|
107 | + return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | function wpinv_get_default_gateway() { |
111 | - $default = wpinv_get_option( 'default_gateway', 'paypal' ); |
|
111 | + $default = wpinv_get_option('default_gateway', 'paypal'); |
|
112 | 112 | |
113 | - if ( !wpinv_is_gateway_active( $default ) ) { |
|
113 | + if (!wpinv_is_gateway_active($default)) { |
|
114 | 114 | $gateways = wpinv_get_enabled_payment_gateways(); |
115 | - $gateways = array_keys( $gateways ); |
|
116 | - $default = reset( $gateways ); |
|
115 | + $gateways = array_keys($gateways); |
|
116 | + $default = reset($gateways); |
|
117 | 117 | } |
118 | 118 | |
119 | - return apply_filters( 'wpinv_default_gateway', $default ); |
|
119 | + return apply_filters('wpinv_default_gateway', $default); |
|
120 | 120 | } |
121 | 121 | |
122 | -function wpinv_get_gateway_admin_label( $gateway ) { |
|
122 | +function wpinv_get_gateway_admin_label($gateway) { |
|
123 | 123 | $gateways = wpinv_get_payment_gateways(); |
124 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway; |
|
125 | - $payment = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false; |
|
124 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway; |
|
125 | + $payment = isset($_GET['id']) ? absint($_GET['id']) : false; |
|
126 | 126 | |
127 | - if( $gateway == 'manual' && $payment ) { |
|
128 | - if( !( (float)wpinv_payment_total( $payment ) > 0 ) ) { |
|
129 | - $label = __( 'Free Purchase', 'invoicing' ); |
|
127 | + if ($gateway == 'manual' && $payment) { |
|
128 | + if (!((float) wpinv_payment_total($payment) > 0)) { |
|
129 | + $label = __('Free Purchase', 'invoicing'); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | - return apply_filters( 'wpinv_gateway_admin_label', $label, $gateway ); |
|
133 | + return apply_filters('wpinv_gateway_admin_label', $label, $gateway); |
|
134 | 134 | } |
135 | 135 | |
136 | -function wpinv_get_gateway_description( $gateway ) { |
|
136 | +function wpinv_get_gateway_description($gateway) { |
|
137 | 137 | global $wpinv_options; |
138 | 138 | |
139 | - $description = isset( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : ''; |
|
139 | + $description = isset($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : ''; |
|
140 | 140 | |
141 | - return apply_filters( 'wpinv_gateway_description', $description, $gateway ); |
|
141 | + return apply_filters('wpinv_gateway_description', $description, $gateway); |
|
142 | 142 | } |
143 | 143 | |
144 | -function wpinv_get_gateway_button_label( $gateway ) { |
|
145 | - return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' ); |
|
144 | +function wpinv_get_gateway_button_label($gateway) { |
|
145 | + return apply_filters('wpinv_gateway_' . $gateway . '_button_label', ''); |
|
146 | 146 | } |
147 | 147 | |
148 | -function wpinv_get_gateway_checkout_label( $gateway ) { |
|
148 | +function wpinv_get_gateway_checkout_label($gateway) { |
|
149 | 149 | $gateways = wpinv_get_payment_gateways(); |
150 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway; |
|
150 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway; |
|
151 | 151 | |
152 | - if( $gateway == 'manual' ) { |
|
153 | - $label = __( 'Manual Payment', 'invoicing' ); |
|
152 | + if ($gateway == 'manual') { |
|
153 | + $label = __('Manual Payment', 'invoicing'); |
|
154 | 154 | } |
155 | 155 | |
156 | - return apply_filters( 'wpinv_gateway_checkout_label', $label, $gateway ); |
|
156 | + return apply_filters('wpinv_gateway_checkout_label', $label, $gateway); |
|
157 | 157 | } |
158 | 158 | |
159 | -function wpinv_settings_sections_gateways( $settings ) { |
|
159 | +function wpinv_settings_sections_gateways($settings) { |
|
160 | 160 | $gateways = wpinv_get_payment_gateways(); |
161 | 161 | |
162 | 162 | if (!empty($gateways)) { |
163 | - foreach ($gateways as $key => $gateway) { |
|
163 | + foreach ($gateways as $key => $gateway) { |
|
164 | 164 | $settings[$key] = $gateway['admin_label']; |
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | 168 | return $settings; |
169 | 169 | } |
170 | -add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 ); |
|
170 | +add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1); |
|
171 | 171 | |
172 | -function wpinv_settings_gateways( $settings ) { |
|
172 | +function wpinv_settings_gateways($settings) { |
|
173 | 173 | $gateways = wpinv_get_payment_gateways(); |
174 | 174 | |
175 | 175 | if (!empty($gateways)) { |
176 | - foreach ($gateways as $key => $gateway) { |
|
176 | + foreach ($gateways as $key => $gateway) { |
|
177 | 177 | $setting = array(); |
178 | 178 | $setting[$key . '_header'] = array( |
179 | 179 | 'id' => 'gateway_header', |
180 | - 'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>', |
|
180 | + 'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>', |
|
181 | 181 | 'custom' => $key, |
182 | 182 | 'type' => 'gateway_header', |
183 | 183 | ); |
184 | 184 | $setting[$key . '_active'] = array( |
185 | 185 | 'id' => $key . '_active', |
186 | - 'name' => __( 'Active', 'invoicing' ), |
|
187 | - 'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ), |
|
186 | + 'name' => __('Active', 'invoicing'), |
|
187 | + 'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']), |
|
188 | 188 | 'type' => 'checkbox', |
189 | 189 | ); |
190 | 190 | |
191 | 191 | $setting[$key . '_title'] = array( |
192 | 192 | 'id' => $key . '_title', |
193 | - 'name' => __( 'Title', 'invoicing' ), |
|
194 | - 'desc' => __( 'This controls the title which the user sees during checkout.', 'invoicing' ), |
|
193 | + 'name' => __('Title', 'invoicing'), |
|
194 | + 'desc' => __('This controls the title which the user sees during checkout.', 'invoicing'), |
|
195 | 195 | 'type' => 'text', |
196 | 196 | 'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : '' |
197 | 197 | ); |
198 | 198 | |
199 | 199 | $setting[$key . '_desc'] = array( |
200 | 200 | 'id' => $key . '_desc', |
201 | - 'name' => __( 'Description', 'invoicing' ), |
|
202 | - 'desc' => __( 'This controls the description which the user sees during checkout.', 'invoicing' ), |
|
201 | + 'name' => __('Description', 'invoicing'), |
|
202 | + 'desc' => __('This controls the description which the user sees during checkout.', 'invoicing'), |
|
203 | 203 | 'type' => 'text', |
204 | 204 | 'size' => 'large' |
205 | 205 | ); |
206 | 206 | |
207 | 207 | $setting[$key . '_ordering'] = array( |
208 | 208 | 'id' => $key . '_ordering', |
209 | - 'name' => __( 'Display Order', 'invoicing' ), |
|
209 | + 'name' => __('Display Order', 'invoicing'), |
|
210 | 210 | 'type' => 'number', |
211 | 211 | 'size' => 'small', |
212 | 212 | 'std' => isset($gateway['ordering']) ? $gateway['ordering'] : '10', |
@@ -215,8 +215,8 @@ discard block |
||
215 | 215 | 'step' => '1' |
216 | 216 | ); |
217 | 217 | |
218 | - $setting = apply_filters( 'wpinv_gateway_settings', $setting, $key ); |
|
219 | - $setting = apply_filters( 'wpinv_gateway_settings_' . $key, $setting ); |
|
218 | + $setting = apply_filters('wpinv_gateway_settings', $setting, $key); |
|
219 | + $setting = apply_filters('wpinv_gateway_settings_' . $key, $setting); |
|
220 | 220 | |
221 | 221 | $settings[$key] = $setting; |
222 | 222 | } |
@@ -224,106 +224,106 @@ discard block |
||
224 | 224 | |
225 | 225 | return $settings; |
226 | 226 | } |
227 | -add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 ); |
|
227 | +add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1); |
|
228 | 228 | |
229 | -function wpinv_gateway_header_callback( $args ) { |
|
230 | - echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />'; |
|
229 | +function wpinv_gateway_header_callback($args) { |
|
230 | + echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />'; |
|
231 | 231 | } |
232 | 232 | |
233 | -function wpinv_get_gateway_supports( $gateway ) { |
|
233 | +function wpinv_get_gateway_supports($gateway) { |
|
234 | 234 | $gateways = wpinv_get_enabled_payment_gateways(); |
235 | - $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array(); |
|
236 | - return apply_filters( 'wpinv_gateway_supports', $supports, $gateway ); |
|
235 | + $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array(); |
|
236 | + return apply_filters('wpinv_gateway_supports', $supports, $gateway); |
|
237 | 237 | } |
238 | 238 | |
239 | -function wpinv_gateway_supports_buy_now( $gateway ) { |
|
240 | - $supports = wpinv_get_gateway_supports( $gateway ); |
|
241 | - $ret = in_array( 'buy_now', $supports ); |
|
242 | - return apply_filters( 'wpinv_gateway_supports_buy_now', $ret, $gateway ); |
|
239 | +function wpinv_gateway_supports_buy_now($gateway) { |
|
240 | + $supports = wpinv_get_gateway_supports($gateway); |
|
241 | + $ret = in_array('buy_now', $supports); |
|
242 | + return apply_filters('wpinv_gateway_supports_buy_now', $ret, $gateway); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | function wpinv_shop_supports_buy_now() { |
246 | 246 | $gateways = wpinv_get_enabled_payment_gateways(); |
247 | 247 | $ret = false; |
248 | 248 | |
249 | - if ( !wpinv_use_taxes() && $gateways ) { |
|
250 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
251 | - if ( wpinv_gateway_supports_buy_now( $gateway_id ) ) { |
|
249 | + if (!wpinv_use_taxes() && $gateways) { |
|
250 | + foreach ($gateways as $gateway_id => $gateway) { |
|
251 | + if (wpinv_gateway_supports_buy_now($gateway_id)) { |
|
252 | 252 | $ret = true; |
253 | 253 | break; |
254 | 254 | } |
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
258 | - return apply_filters( 'wpinv_shop_supports_buy_now', $ret ); |
|
258 | + return apply_filters('wpinv_shop_supports_buy_now', $ret); |
|
259 | 259 | } |
260 | 260 | |
261 | -function wpinv_send_to_gateway( $gateway, $payment_data ) { |
|
262 | - $payment_data['gateway_nonce'] = wp_create_nonce( 'wpi-gateway' ); |
|
261 | +function wpinv_send_to_gateway($gateway, $payment_data) { |
|
262 | + $payment_data['gateway_nonce'] = wp_create_nonce('wpi-gateway'); |
|
263 | 263 | |
264 | 264 | // $gateway must match the ID used when registering the gateway |
265 | - do_action( 'wpinv_gateway_' . $gateway, $payment_data ); |
|
265 | + do_action('wpinv_gateway_' . $gateway, $payment_data); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | function wpinv_show_gateways() { |
269 | 269 | $gateways = wpinv_get_enabled_payment_gateways(); |
270 | 270 | $show_gateways = false; |
271 | 271 | |
272 | - $chosen_gateway = isset( $_GET['payment-mode'] ) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode'] ) : false; |
|
272 | + $chosen_gateway = isset($_GET['payment-mode']) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode']) : false; |
|
273 | 273 | |
274 | - if ( count( $gateways ) > 1 && empty( $chosen_gateway ) ) { |
|
274 | + if (count($gateways) > 1 && empty($chosen_gateway)) { |
|
275 | 275 | $show_gateways = true; |
276 | - if ( wpinv_get_cart_total() <= 0 ) { |
|
276 | + if (wpinv_get_cart_total() <= 0) { |
|
277 | 277 | $show_gateways = false; |
278 | 278 | } |
279 | 279 | } |
280 | 280 | |
281 | - if ( !$show_gateways && wpinv_cart_has_recurring_item() ) { |
|
281 | + if (!$show_gateways && wpinv_cart_has_recurring_item()) { |
|
282 | 282 | $show_gateways = true; |
283 | 283 | } |
284 | 284 | |
285 | - return apply_filters( 'wpinv_show_gateways', $show_gateways ); |
|
285 | + return apply_filters('wpinv_show_gateways', $show_gateways); |
|
286 | 286 | } |
287 | 287 | |
288 | -function wpinv_get_chosen_gateway( $invoice_id = 0 ) { |
|
289 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
288 | +function wpinv_get_chosen_gateway($invoice_id = 0) { |
|
289 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
290 | 290 | |
291 | 291 | $chosen = false; |
292 | - if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
292 | + if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) { |
|
293 | 293 | $chosen = $invoice->get_gateway(); |
294 | 294 | } |
295 | 295 | |
296 | - $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
296 | + $chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen; |
|
297 | 297 | |
298 | - if ( false !== $chosen ) { |
|
299 | - $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
298 | + if (false !== $chosen) { |
|
299 | + $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen); |
|
300 | 300 | } |
301 | 301 | |
302 | - if ( ! empty ( $chosen ) ) { |
|
303 | - $enabled_gateway = urldecode( $chosen ); |
|
304 | - } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
302 | + if (!empty ($chosen)) { |
|
303 | + $enabled_gateway = urldecode($chosen); |
|
304 | + } else if (!empty($invoice) && (float) $invoice->get_subtotal() <= 0) { |
|
305 | 305 | $enabled_gateway = 'manual'; |
306 | 306 | } else { |
307 | 307 | $enabled_gateway = wpinv_get_default_gateway(); |
308 | 308 | } |
309 | 309 | |
310 | - if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) { |
|
311 | - if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){ |
|
310 | + if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) { |
|
311 | + if (wpinv_is_gateway_active(wpinv_get_default_gateway())) { |
|
312 | 312 | $enabled_gateway = wpinv_get_default_gateway(); |
313 | - }else{ |
|
313 | + } else { |
|
314 | 314 | $enabled_gateway = $gateways[0]; |
315 | 315 | } |
316 | 316 | |
317 | 317 | } |
318 | 318 | |
319 | - return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
319 | + return apply_filters('wpinv_chosen_gateway', $enabled_gateway); |
|
320 | 320 | } |
321 | 321 | |
322 | -function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) { |
|
323 | - return wpinv_error_log( $message, $title ); |
|
322 | +function wpinv_record_gateway_error($title = '', $message = '', $parent = 0) { |
|
323 | + return wpinv_error_log($message, $title); |
|
324 | 324 | } |
325 | 325 | |
326 | -function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
|
326 | +function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') { |
|
327 | 327 | $ret = 0; |
328 | 328 | $args = array( |
329 | 329 | 'meta_key' => '_wpinv_gateway', |
@@ -334,48 +334,48 @@ discard block |
||
334 | 334 | 'fields' => 'ids' |
335 | 335 | ); |
336 | 336 | |
337 | - $payments = new WP_Query( $args ); |
|
337 | + $payments = new WP_Query($args); |
|
338 | 338 | |
339 | - if( $payments ) |
|
339 | + if ($payments) |
|
340 | 340 | $ret = $payments->post_count; |
341 | 341 | return $ret; |
342 | 342 | } |
343 | 343 | |
344 | -function wpinv_settings_update_gateways( $input ) { |
|
344 | +function wpinv_settings_update_gateways($input) { |
|
345 | 345 | global $wpinv_options; |
346 | 346 | |
347 | - if ( !empty( $input['save_gateway'] ) ) { |
|
348 | - $gateways = wpinv_get_option( 'gateways', false ); |
|
347 | + if (!empty($input['save_gateway'])) { |
|
348 | + $gateways = wpinv_get_option('gateways', false); |
|
349 | 349 | $gateways = !empty($gateways) ? $gateways : array(); |
350 | 350 | $gateway = $input['save_gateway']; |
351 | 351 | |
352 | - if ( !empty( $input[$gateway . '_active'] ) ) { |
|
352 | + if (!empty($input[$gateway . '_active'])) { |
|
353 | 353 | $gateways[$gateway] = 1; |
354 | 354 | } else { |
355 | - if ( isset( $gateways[$gateway] ) ) { |
|
356 | - unset( $gateways[$gateway] ); |
|
355 | + if (isset($gateways[$gateway])) { |
|
356 | + unset($gateways[$gateway]); |
|
357 | 357 | } |
358 | 358 | } |
359 | 359 | |
360 | 360 | $input['gateways'] = $gateways; |
361 | 361 | } |
362 | 362 | |
363 | - if ( !empty( $input['default_gateway'] ) ) { |
|
363 | + if (!empty($input['default_gateway'])) { |
|
364 | 364 | $gateways = wpinv_get_payment_gateways(); |
365 | 365 | |
366 | - foreach ( $gateways as $key => $gateway ) { |
|
367 | - $active = 0; |
|
368 | - if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) { |
|
366 | + foreach ($gateways as $key => $gateway) { |
|
367 | + $active = 0; |
|
368 | + if (!empty($input['gateways']) && !empty($input['gateways'][$key])) { |
|
369 | 369 | $active = 1; |
370 | 370 | } |
371 | 371 | |
372 | 372 | $input[$key . '_active'] = $active; |
373 | 373 | |
374 | - if ( empty( $wpinv_options[$key . '_title'] ) ) { |
|
374 | + if (empty($wpinv_options[$key . '_title'])) { |
|
375 | 375 | $input[$key . '_title'] = $gateway['checkout_label']; |
376 | 376 | } |
377 | 377 | |
378 | - if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) { |
|
378 | + if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) { |
|
379 | 379 | $input[$key . '_ordering'] = $gateway['ordering']; |
380 | 380 | } |
381 | 381 | } |
@@ -383,27 +383,27 @@ discard block |
||
383 | 383 | |
384 | 384 | return $input; |
385 | 385 | } |
386 | -add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 ); |
|
386 | +add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1); |
|
387 | 387 | |
388 | 388 | // PayPal Standard settings |
389 | -function wpinv_gateway_settings_paypal( $setting ) { |
|
390 | - $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing' ); |
|
391 | - $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
|
389 | +function wpinv_gateway_settings_paypal($setting) { |
|
390 | + $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __('( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing'); |
|
391 | + $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing'); |
|
392 | 392 | |
393 | 393 | $setting['paypal_sandbox'] = array( |
394 | 394 | 'type' => 'checkbox', |
395 | 395 | 'id' => 'paypal_sandbox', |
396 | - 'name' => __( 'PayPal Sandbox', 'invoicing' ), |
|
397 | - 'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ), |
|
396 | + 'name' => __('PayPal Sandbox', 'invoicing'), |
|
397 | + 'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'), |
|
398 | 398 | 'std' => 1 |
399 | 399 | ); |
400 | 400 | |
401 | 401 | $setting['paypal_email'] = array( |
402 | 402 | 'type' => 'text', |
403 | 403 | 'id' => 'paypal_email', |
404 | - 'name' => __( 'PayPal Email', 'invoicing' ), |
|
405 | - 'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ), |
|
406 | - 'std' => __( '[email protected]', 'invoicing' ), |
|
404 | + 'name' => __('PayPal Email', 'invoicing'), |
|
405 | + 'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'), |
|
406 | + 'std' => __('[email protected]', 'invoicing'), |
|
407 | 407 | ); |
408 | 408 | /* |
409 | 409 | $setting['paypal_ipn_url'] = array( |
@@ -417,139 +417,139 @@ discard block |
||
417 | 417 | |
418 | 418 | return $setting; |
419 | 419 | } |
420 | -add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 ); |
|
420 | +add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1); |
|
421 | 421 | |
422 | 422 | // Pre Bank Transfer settings |
423 | -function wpinv_gateway_settings_bank_transfer( $setting ) { |
|
424 | - $setting['bank_transfer_desc']['std'] = __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ); |
|
423 | +function wpinv_gateway_settings_bank_transfer($setting) { |
|
424 | + $setting['bank_transfer_desc']['std'] = __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'); |
|
425 | 425 | |
426 | 426 | $setting['bank_transfer_ac_name'] = array( |
427 | 427 | 'type' => 'text', |
428 | 428 | 'id' => 'bank_transfer_ac_name', |
429 | - 'name' => __( 'Account Name', 'invoicing' ), |
|
430 | - 'desc' => __( 'Enter the bank account name to which you want to transfer payment.', 'invoicing' ), |
|
431 | - 'std' => __( 'Mr. John Martin', 'invoicing' ), |
|
429 | + 'name' => __('Account Name', 'invoicing'), |
|
430 | + 'desc' => __('Enter the bank account name to which you want to transfer payment.', 'invoicing'), |
|
431 | + 'std' => __('Mr. John Martin', 'invoicing'), |
|
432 | 432 | ); |
433 | 433 | |
434 | 434 | $setting['bank_transfer_ac_no'] = array( |
435 | 435 | 'type' => 'text', |
436 | 436 | 'id' => 'bank_transfer_ac_no', |
437 | - 'name' => __( 'Account Number', 'invoicing' ), |
|
438 | - 'desc' => __( 'Enter your bank account number.', 'invoicing' ), |
|
439 | - 'std' => __( 'TEST1234567890', 'invoicing' ), |
|
437 | + 'name' => __('Account Number', 'invoicing'), |
|
438 | + 'desc' => __('Enter your bank account number.', 'invoicing'), |
|
439 | + 'std' => __('TEST1234567890', 'invoicing'), |
|
440 | 440 | ); |
441 | 441 | |
442 | 442 | $setting['bank_transfer_bank_name'] = array( |
443 | 443 | 'type' => 'text', |
444 | 444 | 'id' => 'bank_transfer_bank_name', |
445 | - 'name' => __( 'Bank Name', 'invoicing' ), |
|
446 | - 'desc' => __( 'Enter the bank name to which you want to transfer payment.', 'invoicing' ), |
|
447 | - 'std' => __( 'ICICI Bank', 'invoicing' ), |
|
445 | + 'name' => __('Bank Name', 'invoicing'), |
|
446 | + 'desc' => __('Enter the bank name to which you want to transfer payment.', 'invoicing'), |
|
447 | + 'std' => __('ICICI Bank', 'invoicing'), |
|
448 | 448 | ); |
449 | 449 | |
450 | 450 | $setting['bank_transfer_ifsc'] = array( |
451 | 451 | 'type' => 'text', |
452 | 452 | 'id' => 'bank_transfer_ifsc', |
453 | - 'name' => __( 'IFSC Code', 'invoicing' ), |
|
454 | - 'desc' => __( 'Enter your bank IFSC code.', 'invoicing' ), |
|
455 | - 'std' => __( 'ICIC0001234', 'invoicing' ), |
|
453 | + 'name' => __('IFSC Code', 'invoicing'), |
|
454 | + 'desc' => __('Enter your bank IFSC code.', 'invoicing'), |
|
455 | + 'std' => __('ICIC0001234', 'invoicing'), |
|
456 | 456 | ); |
457 | 457 | |
458 | 458 | $setting['bank_transfer_iban'] = array( |
459 | 459 | 'type' => 'text', |
460 | 460 | 'id' => 'bank_transfer_iban', |
461 | - 'name' => __( 'IBAN', 'invoicing' ), |
|
462 | - 'desc' => __( 'Enter your International Bank Account Number(IBAN).', 'invoicing' ), |
|
463 | - 'std' => __( 'GB29NWBK60161331926819', 'invoicing' ), |
|
461 | + 'name' => __('IBAN', 'invoicing'), |
|
462 | + 'desc' => __('Enter your International Bank Account Number(IBAN).', 'invoicing'), |
|
463 | + 'std' => __('GB29NWBK60161331926819', 'invoicing'), |
|
464 | 464 | ); |
465 | 465 | |
466 | 466 | $setting['bank_transfer_bic'] = array( |
467 | 467 | 'type' => 'text', |
468 | 468 | 'id' => 'bank_transfer_bic', |
469 | - 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
|
470 | - 'std' => __( 'ICICGB2L129', 'invoicing' ), |
|
469 | + 'name' => __('BIC/Swift Code', 'invoicing'), |
|
470 | + 'std' => __('ICICGB2L129', 'invoicing'), |
|
471 | 471 | ); |
472 | 472 | |
473 | 473 | $setting['bank_transfer_sort_code'] = array( |
474 | 474 | 'type' => 'text', |
475 | 475 | 'id' => 'bank_transfer_sort_code', |
476 | - 'name' => __( 'Sort Code', 'invoicing' ), |
|
477 | - 'std' => __( '12-34-56', 'invoicing' ), |
|
476 | + 'name' => __('Sort Code', 'invoicing'), |
|
477 | + 'std' => __('12-34-56', 'invoicing'), |
|
478 | 478 | ); |
479 | 479 | |
480 | 480 | $setting['bank_transfer_info'] = array( |
481 | 481 | 'id' => 'bank_transfer_info', |
482 | - 'name' => __( 'Instructions', 'invoicing' ), |
|
483 | - 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
482 | + 'name' => __('Instructions', 'invoicing'), |
|
483 | + 'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'), |
|
484 | 484 | 'type' => 'textarea', |
485 | - 'std' => __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ), |
|
485 | + 'std' => __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'), |
|
486 | 486 | 'cols' => 37, |
487 | 487 | 'rows' => 5 |
488 | 488 | ); |
489 | 489 | |
490 | 490 | return $setting; |
491 | 491 | } |
492 | -add_filter( 'wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1 ); |
|
492 | +add_filter('wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1); |
|
493 | 493 | |
494 | 494 | // Authorize.Net settings |
495 | -function wpinv_gateway_settings_authorizenet( $setting ) { |
|
496 | - $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing' ); |
|
497 | - $setting['authorizenet_desc']['std'] = __( 'Pay using a Authorize.Net to process Credit card / Debit card transactions.', 'invoicing' ); |
|
495 | +function wpinv_gateway_settings_authorizenet($setting) { |
|
496 | + $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __('( Supported Currencies: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing'); |
|
497 | + $setting['authorizenet_desc']['std'] = __('Pay using a Authorize.Net to process Credit card / Debit card transactions.', 'invoicing'); |
|
498 | 498 | |
499 | 499 | $setting['authorizenet_sandbox'] = array( |
500 | 500 | 'type' => 'checkbox', |
501 | 501 | 'id' => 'authorizenet_sandbox', |
502 | - 'name' => __( 'Authorize.Net Test Mode', 'invoicing' ), |
|
503 | - 'desc' => __( 'Enable Authorize.Net test mode to test payments.', 'invoicing' ), |
|
502 | + 'name' => __('Authorize.Net Test Mode', 'invoicing'), |
|
503 | + 'desc' => __('Enable Authorize.Net test mode to test payments.', 'invoicing'), |
|
504 | 504 | 'std' => 1 |
505 | 505 | ); |
506 | 506 | |
507 | 507 | $setting['authorizenet_login_id'] = array( |
508 | 508 | 'type' => 'text', |
509 | 509 | 'id' => 'authorizenet_login_id', |
510 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
511 | - 'desc' => __( 'API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing' ), |
|
510 | + 'name' => __('API Login ID', 'invoicing'), |
|
511 | + 'desc' => __('API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing'), |
|
512 | 512 | 'std' => '2j4rBekUnD', |
513 | 513 | ); |
514 | 514 | |
515 | 515 | $setting['authorizenet_transaction_key'] = array( |
516 | 516 | 'type' => 'text', |
517 | 517 | 'id' => 'authorizenet_transaction_key', |
518 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
519 | - 'desc' => __( 'Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing' ), |
|
518 | + 'name' => __('Transaction Key', 'invoicing'), |
|
519 | + 'desc' => __('Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing'), |
|
520 | 520 | 'std' => '4vyBUOJgR74679xa', |
521 | 521 | ); |
522 | 522 | |
523 | 523 | $setting['authorizenet_md5_hash'] = array( |
524 | 524 | 'type' => 'text', |
525 | 525 | 'id' => 'authorizenet_md5_hash', |
526 | - 'name' => __( 'MD5-Hash', 'invoicing' ), |
|
527 | - 'desc' => __( 'The MD5 Hash security feature allows to authenticate transaction responses from the Authorize.Net for recurring payments. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing' ), |
|
526 | + 'name' => __('MD5-Hash', 'invoicing'), |
|
527 | + 'desc' => __('The MD5 Hash security feature allows to authenticate transaction responses from the Authorize.Net for recurring payments. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing'), |
|
528 | 528 | 'std' => '', |
529 | 529 | ); |
530 | 530 | |
531 | 531 | $setting['authorizenet_transaction_type'] = array( |
532 | 532 | 'id' => 'authorizenet_transaction_type', |
533 | - 'name' => __( 'Transaction Type', 'invoicing' ), |
|
534 | - 'desc' => __( 'Choose transaction type.', 'invoicing' ), |
|
533 | + 'name' => __('Transaction Type', 'invoicing'), |
|
534 | + 'desc' => __('Choose transaction type.', 'invoicing'), |
|
535 | 535 | 'type' => 'select', |
536 | 536 | 'class' => 'wpi_select2', |
537 | 537 | 'options' => array( |
538 | - 'authorize_capture' => __( 'Authorize And Capture', 'invoicing' ), |
|
539 | - 'authorize_only' => __( 'Authorize Only', 'invoicing' ), |
|
538 | + 'authorize_capture' => __('Authorize And Capture', 'invoicing'), |
|
539 | + 'authorize_only' => __('Authorize Only', 'invoicing'), |
|
540 | 540 | ), |
541 | 541 | 'std' => 'authorize_capture' |
542 | 542 | ); |
543 | 543 | |
544 | 544 | $setting['authorizenet_transaction_type_recurring'] = array( |
545 | 545 | 'id' => 'authorizenet_transaction_type_recurring', |
546 | - 'name' => __( 'Transaction Type for Recurring', 'invoicing' ), |
|
547 | - 'desc' => __( 'Choose transaction type for recurring payments.', 'invoicing' ), |
|
546 | + 'name' => __('Transaction Type for Recurring', 'invoicing'), |
|
547 | + 'desc' => __('Choose transaction type for recurring payments.', 'invoicing'), |
|
548 | 548 | 'type' => 'select', |
549 | 549 | 'class' => 'wpi_select2', |
550 | 550 | 'options' => array( |
551 | - 'authorize_capture' => __( 'Authorize And Capture', 'invoicing' ), |
|
552 | - 'authorize_only' => __( 'Authorize Only', 'invoicing' ), |
|
551 | + 'authorize_capture' => __('Authorize And Capture', 'invoicing'), |
|
552 | + 'authorize_only' => __('Authorize Only', 'invoicing'), |
|
553 | 553 | ), |
554 | 554 | 'std' => 'authorize_only' |
555 | 555 | ); |
@@ -557,9 +557,9 @@ discard block |
||
557 | 557 | $setting['authorizenet_ipn_url'] = array( |
558 | 558 | 'type' => 'ipn_url', |
559 | 559 | 'id' => 'authorizenet_ipn_url', |
560 | - 'name' => __( 'Silent Post URL', 'invoicing' ), |
|
561 | - 'std' => wpinv_get_ipn_url( 'authorizenet' ), |
|
562 | - 'desc' => __( 'If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing' ), |
|
560 | + 'name' => __('Silent Post URL', 'invoicing'), |
|
561 | + 'std' => wpinv_get_ipn_url('authorizenet'), |
|
562 | + 'desc' => __('If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing'), |
|
563 | 563 | 'size' => 'large', |
564 | 564 | 'custom' => 'authorizenet', |
565 | 565 | 'readonly' => true |
@@ -567,26 +567,26 @@ discard block |
||
567 | 567 | |
568 | 568 | return $setting; |
569 | 569 | } |
570 | -add_filter( 'wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1 ); |
|
570 | +add_filter('wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1); |
|
571 | 571 | |
572 | 572 | // Worldpay settings |
573 | -function wpinv_gateway_settings_worldpay( $setting ) { |
|
574 | - $setting['worldpay_active']['desc'] = $setting['worldpay_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, ARS, CAD, CHF, DKK, EUR, HKD, MYR, GBP, NZD, NOK, SGD, LKR, SEK, TRY, USD, ZAR )', 'invoicing' ); |
|
575 | - $setting['worldpay_desc']['std'] = __( 'Pay using a Worldpay account to process Credit card / Debit card transactions.', 'invoicing' ); |
|
573 | +function wpinv_gateway_settings_worldpay($setting) { |
|
574 | + $setting['worldpay_active']['desc'] = $setting['worldpay_active']['desc'] . ' ' . __('( Supported Currencies: AUD, ARS, CAD, CHF, DKK, EUR, HKD, MYR, GBP, NZD, NOK, SGD, LKR, SEK, TRY, USD, ZAR )', 'invoicing'); |
|
575 | + $setting['worldpay_desc']['std'] = __('Pay using a Worldpay account to process Credit card / Debit card transactions.', 'invoicing'); |
|
576 | 576 | |
577 | 577 | $setting['worldpay_sandbox'] = array( |
578 | 578 | 'type' => 'checkbox', |
579 | 579 | 'id' => 'worldpay_sandbox', |
580 | - 'name' => __( 'Worldpay Test Mode', 'invoicing' ), |
|
581 | - 'desc' => __( 'This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing' ), |
|
580 | + 'name' => __('Worldpay Test Mode', 'invoicing'), |
|
581 | + 'desc' => __('This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing'), |
|
582 | 582 | 'std' => 1 |
583 | 583 | ); |
584 | 584 | |
585 | 585 | $setting['worldpay_instId'] = array( |
586 | 586 | 'type' => 'text', |
587 | 587 | 'id' => 'worldpay_instId', |
588 | - 'name' => __( 'Installation Id', 'invoicing' ), |
|
589 | - 'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ), |
|
588 | + 'name' => __('Installation Id', 'invoicing'), |
|
589 | + 'desc' => __('Your installation id. Ex: 211616', 'invoicing'), |
|
590 | 590 | 'std' => '211616', |
591 | 591 | ); |
592 | 592 | /* |
@@ -602,9 +602,9 @@ discard block |
||
602 | 602 | $setting['worldpay_ipn_url'] = array( |
603 | 603 | 'type' => 'ipn_url', |
604 | 604 | 'id' => 'worldpay_ipn_url', |
605 | - 'name' => __( 'Worldpay Callback Url', 'invoicing' ), |
|
606 | - 'std' => wpinv_get_ipn_url( 'worldpay' ), |
|
607 | - 'desc' => wp_sprintf( __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing' ), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url( 'worldpay' ) . '</font>', '<font style="color:#000;font-style:normal"><wpdisplay item=MC_callback></font>' ), |
|
605 | + 'name' => __('Worldpay Callback Url', 'invoicing'), |
|
606 | + 'std' => wpinv_get_ipn_url('worldpay'), |
|
607 | + 'desc' => wp_sprintf(__('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing'), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url('worldpay') . '</font>', '<font style="color:#000;font-style:normal"><wpdisplay item=MC_callback></font>'), |
|
608 | 608 | 'size' => 'large', |
609 | 609 | 'custom' => 'worldpay', |
610 | 610 | 'readonly' => true |
@@ -612,99 +612,99 @@ discard block |
||
612 | 612 | |
613 | 613 | return $setting; |
614 | 614 | } |
615 | -add_filter( 'wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1 ); |
|
615 | +add_filter('wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1); |
|
616 | 616 | |
617 | -function wpinv_ipn_url_callback( $args ) { |
|
618 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
617 | +function wpinv_ipn_url_callback($args) { |
|
618 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
619 | 619 | |
620 | 620 | $attrs = $args['readonly'] ? ' readonly' : ''; |
621 | 621 | |
622 | - $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">'; |
|
623 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
622 | + $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">'; |
|
623 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
624 | 624 | |
625 | 625 | echo $html; |
626 | 626 | } |
627 | 627 | |
628 | -function wpinv_is_test_mode( $gateway = '' ) { |
|
629 | - if ( empty( $gateway ) ) { |
|
628 | +function wpinv_is_test_mode($gateway = '') { |
|
629 | + if (empty($gateway)) { |
|
630 | 630 | return false; |
631 | 631 | } |
632 | 632 | |
633 | - $is_test_mode = wpinv_get_option( $gateway . '_sandbox', false ); |
|
633 | + $is_test_mode = wpinv_get_option($gateway . '_sandbox', false); |
|
634 | 634 | |
635 | - return apply_filters( 'wpinv_is_test_mode', $is_test_mode, $gateway ); |
|
635 | + return apply_filters('wpinv_is_test_mode', $is_test_mode, $gateway); |
|
636 | 636 | } |
637 | 637 | |
638 | -function wpinv_get_ipn_url( $gateway = '', $args = array() ) { |
|
639 | - $data = array( 'wpi-listener' => 'IPN' ); |
|
638 | +function wpinv_get_ipn_url($gateway = '', $args = array()) { |
|
639 | + $data = array('wpi-listener' => 'IPN'); |
|
640 | 640 | |
641 | - if ( !empty( $gateway ) ) { |
|
642 | - $data['wpi-gateway'] = wpinv_sanitize_key( $gateway ); |
|
641 | + if (!empty($gateway)) { |
|
642 | + $data['wpi-gateway'] = wpinv_sanitize_key($gateway); |
|
643 | 643 | } |
644 | 644 | |
645 | - $args = !empty( $args ) && is_array( $args ) ? array_merge( $data, $args ) : $data; |
|
645 | + $args = !empty($args) && is_array($args) ? array_merge($data, $args) : $data; |
|
646 | 646 | |
647 | - $ipn_url = add_query_arg( $args, home_url( 'index.php' ) ); |
|
647 | + $ipn_url = add_query_arg($args, home_url('index.php')); |
|
648 | 648 | |
649 | - return apply_filters( 'wpinv_ipn_url', $ipn_url ); |
|
649 | + return apply_filters('wpinv_ipn_url', $ipn_url); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | function wpinv_listen_for_payment_ipn() { |
653 | 653 | // Regular PayPal IPN |
654 | - if ( isset( $_GET['wpi-listener'] ) && $_GET['wpi-listener'] == 'IPN' ) { |
|
655 | - do_action( 'wpinv_verify_payment_ipn' ); |
|
654 | + if (isset($_GET['wpi-listener']) && $_GET['wpi-listener'] == 'IPN') { |
|
655 | + do_action('wpinv_verify_payment_ipn'); |
|
656 | 656 | |
657 | - if ( !empty( $_GET['wpi-gateway'] ) ) { |
|
658 | - wpinv_error_log( sanitize_text_field( $_GET['wpi-gateway'] ), 'WP Invoicing IPN', __FILE__, __LINE__ ); |
|
659 | - do_action( 'wpinv_verify_' . sanitize_text_field( $_GET['wpi-gateway'] ) . '_ipn' ); |
|
657 | + if (!empty($_GET['wpi-gateway'])) { |
|
658 | + wpinv_error_log(sanitize_text_field($_GET['wpi-gateway']), 'WP Invoicing IPN', __FILE__, __LINE__); |
|
659 | + do_action('wpinv_verify_' . sanitize_text_field($_GET['wpi-gateway']) . '_ipn'); |
|
660 | 660 | } |
661 | 661 | } |
662 | 662 | } |
663 | -add_action( 'init', 'wpinv_listen_for_payment_ipn' ); |
|
663 | +add_action('init', 'wpinv_listen_for_payment_ipn'); |
|
664 | 664 | |
665 | 665 | function wpinv_get_bank_instructions() { |
666 | - $bank_instructions = wpinv_get_option( 'bank_transfer_info' ); |
|
666 | + $bank_instructions = wpinv_get_option('bank_transfer_info'); |
|
667 | 667 | |
668 | - return apply_filters( 'wpinv_bank_instructions', $bank_instructions ); |
|
668 | + return apply_filters('wpinv_bank_instructions', $bank_instructions); |
|
669 | 669 | } |
670 | 670 | |
671 | -function wpinv_get_bank_info( $filtered = false ) { |
|
671 | +function wpinv_get_bank_info($filtered = false) { |
|
672 | 672 | $bank_fields = array( |
673 | - 'bank_transfer_ac_name' => __( 'Account Name', 'invoicing' ), |
|
674 | - 'bank_transfer_ac_no' => __( 'Account Number', 'invoicing' ), |
|
675 | - 'bank_transfer_bank_name' => __( 'Bank Name', 'invoicing' ), |
|
676 | - 'bank_transfer_ifsc' => __( 'IFSC code', 'invoicing' ), |
|
677 | - 'bank_transfer_iban' => __( 'IBAN', 'invoicing' ), |
|
678 | - 'bank_transfer_bic' => __( 'BIC/Swift code', 'invoicing' ), |
|
679 | - 'bank_transfer_sort_code' => __( 'Sort Code', 'invoicing' ) |
|
673 | + 'bank_transfer_ac_name' => __('Account Name', 'invoicing'), |
|
674 | + 'bank_transfer_ac_no' => __('Account Number', 'invoicing'), |
|
675 | + 'bank_transfer_bank_name' => __('Bank Name', 'invoicing'), |
|
676 | + 'bank_transfer_ifsc' => __('IFSC code', 'invoicing'), |
|
677 | + 'bank_transfer_iban' => __('IBAN', 'invoicing'), |
|
678 | + 'bank_transfer_bic' => __('BIC/Swift code', 'invoicing'), |
|
679 | + 'bank_transfer_sort_code' => __('Sort Code', 'invoicing') |
|
680 | 680 | ); |
681 | 681 | |
682 | 682 | $bank_info = array(); |
683 | - foreach ( $bank_fields as $field => $label ) { |
|
684 | - if ( $filtered && !( $value = wpinv_get_option( $field ) ) ) { |
|
683 | + foreach ($bank_fields as $field => $label) { |
|
684 | + if ($filtered && !($value = wpinv_get_option($field))) { |
|
685 | 685 | continue; |
686 | 686 | } |
687 | 687 | |
688 | - $bank_info[$field] = array( 'label' => $label, 'value' => $value ); |
|
688 | + $bank_info[$field] = array('label' => $label, 'value' => $value); |
|
689 | 689 | } |
690 | 690 | |
691 | - return apply_filters( 'wpinv_bank_info', $bank_info, $filtered ); |
|
691 | + return apply_filters('wpinv_bank_info', $bank_info, $filtered); |
|
692 | 692 | } |
693 | 693 | |
694 | -function wpinv_get_post_data( $method = 'request' ) { |
|
694 | +function wpinv_get_post_data($method = 'request') { |
|
695 | 695 | $data = array(); |
696 | 696 | $request = $_REQUEST; |
697 | 697 | |
698 | - if ( $method == 'post' ) { |
|
699 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
698 | + if ($method == 'post') { |
|
699 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
700 | 700 | return $data; |
701 | 701 | } |
702 | 702 | |
703 | 703 | $request = $_POST; |
704 | 704 | } |
705 | 705 | |
706 | - if ( $method == 'get' ) { |
|
707 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) { |
|
706 | + if ($method == 'get') { |
|
707 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET') { |
|
708 | 708 | return $data; |
709 | 709 | } |
710 | 710 | |
@@ -715,11 +715,11 @@ discard block |
||
715 | 715 | $post_data = ''; |
716 | 716 | |
717 | 717 | // Fallback just in case post_max_size is lower than needed |
718 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
719 | - $post_data = file_get_contents( 'php://input' ); |
|
718 | + if (ini_get('allow_url_fopen')) { |
|
719 | + $post_data = file_get_contents('php://input'); |
|
720 | 720 | } else { |
721 | 721 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
722 | - ini_set( 'post_max_size', '12M' ); |
|
722 | + ini_set('post_max_size', '12M'); |
|
723 | 723 | } |
724 | 724 | // Start the encoded data collection with notification command |
725 | 725 | $encoded_data = 'cmd=_notify-validate'; |
@@ -728,33 +728,33 @@ discard block |
||
728 | 728 | $arg_separator = wpinv_get_php_arg_separator_output(); |
729 | 729 | |
730 | 730 | // Verify there is a post_data |
731 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
731 | + if ($post_data || strlen($post_data) > 0) { |
|
732 | 732 | // Append the data |
733 | 733 | $encoded_data .= $arg_separator . $post_data; |
734 | 734 | } else { |
735 | 735 | // Check if POST is empty |
736 | - if ( empty( $request ) ) { |
|
736 | + if (empty($request)) { |
|
737 | 737 | // Nothing to do |
738 | 738 | return; |
739 | 739 | } else { |
740 | 740 | // Loop through each POST |
741 | - foreach ( $request as $key => $value ) { |
|
741 | + foreach ($request as $key => $value) { |
|
742 | 742 | // Encode the value and append the data |
743 | - $encoded_data .= $arg_separator . "$key=" . urlencode( $value ); |
|
743 | + $encoded_data .= $arg_separator . "$key=" . urlencode($value); |
|
744 | 744 | } |
745 | 745 | } |
746 | 746 | } |
747 | 747 | |
748 | 748 | // Convert collected post data to an array |
749 | - wp_parse_str( $encoded_data, $data ); |
|
749 | + wp_parse_str($encoded_data, $data); |
|
750 | 750 | |
751 | - foreach ( $data as $key => $value ) { |
|
752 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
753 | - $new_key = str_replace( '&', '&', $key ); |
|
754 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
751 | + foreach ($data as $key => $value) { |
|
752 | + if (false !== strpos($key, 'amp;')) { |
|
753 | + $new_key = str_replace('&', '&', $key); |
|
754 | + $new_key = str_replace('amp;', '&', $new_key); |
|
755 | 755 | |
756 | - unset( $data[ $key ] ); |
|
757 | - $data[ $new_key ] = sanitize_text_field( $value ); |
|
756 | + unset($data[$key]); |
|
757 | + $data[$new_key] = sanitize_text_field($value); |
|
758 | 758 | } |
759 | 759 | } |
760 | 760 | |
@@ -764,26 +764,26 @@ discard block |
||
764 | 764 | /** |
765 | 765 | * Checks if a given gateway supports subscription payments. |
766 | 766 | */ |
767 | -function wpinv_gateway_support_subscription( $gateway ) { |
|
767 | +function wpinv_gateway_support_subscription($gateway) { |
|
768 | 768 | $supports = false; |
769 | 769 | |
770 | - if ( wpinv_is_gateway_active( $gateway ) ) { |
|
771 | - $supports = apply_filters( 'wpinv_' . $gateway . '_support_subscription', $supports ); |
|
772 | - $supports = apply_filters( 'getapid_gateway_support_subscription', $supports, $gateway ); |
|
770 | + if (wpinv_is_gateway_active($gateway)) { |
|
771 | + $supports = apply_filters('wpinv_' . $gateway . '_support_subscription', $supports); |
|
772 | + $supports = apply_filters('getapid_gateway_support_subscription', $supports, $gateway); |
|
773 | 773 | } |
774 | 774 | |
775 | 775 | return $supports; |
776 | 776 | } |
777 | 777 | |
778 | -function wpinv_payment_gateways_on_cart( $gateways = array() ) { |
|
779 | - if ( !empty( $gateways ) && wpinv_cart_has_recurring_item() ) { |
|
780 | - foreach ( $gateways as $gateway => $info ) { |
|
781 | - if ( !wpinv_gateway_support_subscription( $gateway ) ) { |
|
782 | - unset( $gateways[$gateway] ); |
|
778 | +function wpinv_payment_gateways_on_cart($gateways = array()) { |
|
779 | + if (!empty($gateways) && wpinv_cart_has_recurring_item()) { |
|
780 | + foreach ($gateways as $gateway => $info) { |
|
781 | + if (!wpinv_gateway_support_subscription($gateway)) { |
|
782 | + unset($gateways[$gateway]); |
|
783 | 783 | } |
784 | 784 | } |
785 | 785 | } |
786 | 786 | |
787 | 787 | return $gateways; |
788 | 788 | } |
789 | -add_filter( 'wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1 ); |
|
790 | 789 | \ No newline at end of file |
790 | +add_filter('wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1); |
|
791 | 791 | \ No newline at end of file |