@@ -13,30 +13,30 @@ discard block |
||
13 | 13 | class GetPaid_Manual_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'manual'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
34 | - public $order = 11; |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | + public $order = 11; |
|
35 | 35 | |
36 | 36 | /** |
37 | - * Class constructor. |
|
38 | - */ |
|
39 | - public function __construct() { |
|
37 | + * Class constructor. |
|
38 | + */ |
|
39 | + public function __construct() { |
|
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | 42 | $this->title = __( 'Test Gateway', 'invoicing' ); |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | - * Process Payment. |
|
50 | - * |
|
51 | - * |
|
52 | - * @param WPInv_Invoice $invoice Invoice. |
|
53 | - * @param array $submission_data Posted checkout fields. |
|
54 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
55 | - * @return array |
|
56 | - */ |
|
57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
49 | + * Process Payment. |
|
50 | + * |
|
51 | + * |
|
52 | + * @param WPInv_Invoice $invoice Invoice. |
|
53 | + * @param array $submission_data Posted checkout fields. |
|
54 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
55 | + * @return array |
|
56 | + */ |
|
57 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
58 | 58 | |
59 | 59 | // Mark it as paid. |
60 | 60 | $invoice->mark_paid(); |
@@ -85,12 +85,12 @@ discard block |
||
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
88 | - * (Maybe) renews a manual subscription profile. |
|
89 | - * |
|
90 | - * |
|
88 | + * (Maybe) renews a manual subscription profile. |
|
89 | + * |
|
90 | + * |
|
91 | 91 | * @param WPInv_Subscription $subscription |
92 | - */ |
|
93 | - public function maybe_renew_subscription( $subscription ) { |
|
92 | + */ |
|
93 | + public function maybe_renew_subscription( $subscription ) { |
|
94 | 94 | |
95 | 95 | // Ensure its our subscription && it's active. |
96 | 96 | if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
@@ -110,13 +110,13 @@ discard block |
||
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
113 | - * Processes invoice addons. |
|
114 | - * |
|
115 | - * @param WPInv_Invoice $invoice |
|
116 | - * @param GetPaid_Form_Item[] $items |
|
117 | - * @return WPInv_Invoice |
|
118 | - */ |
|
119 | - public function process_addons( $invoice, $items ) { |
|
113 | + * Processes invoice addons. |
|
114 | + * |
|
115 | + * @param WPInv_Invoice $invoice |
|
116 | + * @param GetPaid_Form_Item[] $items |
|
117 | + * @return WPInv_Invoice |
|
118 | + */ |
|
119 | + public function process_addons( $invoice, $items ) { |
|
120 | 120 | |
121 | 121 | foreach ( $items as $item ) { |
122 | 122 | $invoice->add_item( $item ); |
@@ -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|string $read ID to load from the DB (optional) or already queried data. |
|
119 | - */ |
|
120 | - public function __construct( $read = 0 ) { |
|
121 | - $this->data = array_merge( $this->data, $this->extra_data ); |
|
122 | - $this->default_data = $this->data; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Only store the object ID to avoid serializing the data object instance. |
|
127 | - * |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - public function __sleep() { |
|
131 | - return array( 'id' ); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Re-run the constructor with the object ID. |
|
136 | - * |
|
137 | - * If the object no longer exists, remove the ID. |
|
138 | - */ |
|
139 | - public function __wakeup() { |
|
140 | - $this->__construct( absint( $this->id ) ); |
|
141 | - |
|
142 | - if ( ! empty( $this->last_error ) ) { |
|
143 | - $this->set_id( 0 ); |
|
144 | - } |
|
145 | - |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * When the object is cloned, make sure meta is duplicated correctly. |
|
150 | - * |
|
151 | - * @since 1.0.19 |
|
152 | - */ |
|
153 | - public function __clone() { |
|
154 | - $this->maybe_read_meta_data(); |
|
155 | - if ( ! empty( $this->meta_data ) ) { |
|
156 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
157 | - $this->meta_data[ $array_key ] = clone $meta; |
|
158 | - if ( ! empty( $meta->id ) ) { |
|
159 | - $this->meta_data[ $array_key ]->id = null; |
|
160 | - } |
|
161 | - } |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Get the data store. |
|
167 | - * |
|
168 | - * @since 1.0.19 |
|
169 | - * @return object |
|
170 | - */ |
|
171 | - public function get_data_store() { |
|
172 | - return $this->data_store; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Get the object type. |
|
177 | - * |
|
178 | - * @since 1.0.19 |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - public function get_object_type() { |
|
182 | - return $this->object_type; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Returns the unique ID for this object. |
|
187 | - * |
|
188 | - * @since 1.0.19 |
|
189 | - * @return int |
|
190 | - */ |
|
191 | - public function get_id() { |
|
192 | - return $this->id; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Get form status. |
|
197 | - * |
|
198 | - * @since 1.0.19 |
|
199 | - * @param string $context View or edit context. |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public function get_status( $context = 'view' ) { |
|
203 | - return $this->get_prop( 'status', $context ); |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Delete an object, set the ID to 0, and return result. |
|
208 | - * |
|
209 | - * @since 1.0.19 |
|
210 | - * @param bool $force_delete Should the data be deleted permanently. |
|
211 | - * @return bool result |
|
212 | - */ |
|
213 | - public function delete( $force_delete = false ) { |
|
214 | - if ( $this->data_store && $this->exists() ) { |
|
215 | - $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
216 | - $this->set_id( 0 ); |
|
217 | - return true; |
|
218 | - } |
|
219 | - return false; |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Save should create or update based on object existence. |
|
224 | - * |
|
225 | - * @since 1.0.19 |
|
226 | - * @return int |
|
227 | - */ |
|
228 | - public function save() { |
|
229 | - if ( ! $this->data_store ) { |
|
230 | - return $this->get_id(); |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Trigger action before saving to the DB. Allows you to adjust object props before save. |
|
235 | - * |
|
236 | - * @param GetPaid_Data $this The object being saved. |
|
237 | - * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
238 | - */ |
|
239 | - do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
240 | - |
|
241 | - if ( $this->get_id() ) { |
|
242 | - $this->data_store->update( $this ); |
|
243 | - } else { |
|
244 | - $this->data_store->create( $this ); |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Trigger action after saving to the DB. |
|
249 | - * |
|
250 | - * @param GetPaid_Data $this The object being saved. |
|
251 | - * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
252 | - */ |
|
253 | - do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
254 | - |
|
255 | - return $this->get_id(); |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Change data to JSON format. |
|
260 | - * |
|
261 | - * @since 1.0.19 |
|
262 | - * @return string Data in JSON format. |
|
263 | - */ |
|
264 | - public function __toString() { |
|
265 | - return wp_json_encode( $this->get_data() ); |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * Returns all data for this object. |
|
270 | - * |
|
271 | - * @since 1.0.19 |
|
272 | - * @return array |
|
273 | - */ |
|
274 | - public function get_data() { |
|
275 | - return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Returns array of expected data keys for this object. |
|
280 | - * |
|
281 | - * @since 1.0.19 |
|
282 | - * @return array |
|
283 | - */ |
|
284 | - public function get_data_keys() { |
|
285 | - return array_keys( $this->data ); |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Returns all "extra" data keys for an object (for sub objects like item types). |
|
290 | - * |
|
291 | - * @since 1.0.19 |
|
292 | - * @return array |
|
293 | - */ |
|
294 | - public function get_extra_data_keys() { |
|
295 | - return array_keys( $this->extra_data ); |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Filter null meta values from array. |
|
300 | - * |
|
301 | - * @since 1.0.19 |
|
302 | - * @param mixed $meta Meta value to check. |
|
303 | - * @return bool |
|
304 | - */ |
|
305 | - protected function filter_null_meta( $meta ) { |
|
306 | - return ! is_null( $meta->value ); |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * Get All Meta Data. |
|
311 | - * |
|
312 | - * @since 1.0.19 |
|
313 | - * @return array of objects. |
|
314 | - */ |
|
315 | - public function get_meta_data() { |
|
316 | - $this->maybe_read_meta_data(); |
|
317 | - return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * Check if the key is an internal one. |
|
322 | - * |
|
323 | - * @since 1.0.19 |
|
324 | - * @param string $key Key to check. |
|
325 | - * @return bool true if it's an internal key, false otherwise |
|
326 | - */ |
|
327 | - protected function is_internal_meta_key( $key ) { |
|
328 | - $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
329 | - |
|
330 | - if ( ! $internal_meta_key ) { |
|
331 | - return false; |
|
332 | - } |
|
333 | - |
|
334 | - $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
335 | - |
|
336 | - if ( ! $has_setter_or_getter ) { |
|
337 | - return false; |
|
338 | - } |
|
339 | - |
|
340 | - /* translators: %s: $key Key to check */ |
|
341 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
342 | - |
|
343 | - return true; |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Magic method for setting data fields. |
|
348 | - * |
|
349 | - * This method does not update custom fields in the database. |
|
350 | - * |
|
351 | - * @since 1.0.19 |
|
352 | - * @access public |
|
353 | - * |
|
354 | - */ |
|
355 | - public function __set( $key, $value ) { |
|
356 | - |
|
357 | - if ( 'id' == strtolower( $key ) ) { |
|
358 | - return $this->set_id( $value ); |
|
359 | - } |
|
360 | - |
|
361 | - if ( method_exists( $this, "set_$key") ) { |
|
362 | - |
|
363 | - /* translators: %s: $key Key to set */ |
|
364 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
365 | - |
|
366 | - call_user_func( array( $this, "set_$key" ), $value ); |
|
367 | - } else { |
|
368 | - $this->set_prop( $key, $value ); |
|
369 | - } |
|
370 | - |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
24 | + /** |
|
25 | + * ID for this object. |
|
26 | + * |
|
27 | + * @since 1.0.19 |
|
28 | + * @var int |
|
29 | + */ |
|
30 | + protected $id = 0; |
|
31 | + |
|
32 | + /** |
|
33 | + * Core data for this object. Name value pairs (name + default value). |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $data = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * Core data changes for this object. |
|
42 | + * |
|
43 | + * @since 1.0.19 |
|
44 | + * @var array |
|
45 | + */ |
|
46 | + protected $changes = array(); |
|
47 | + |
|
48 | + /** |
|
49 | + * This is false until the object is read from the DB. |
|
50 | + * |
|
51 | + * @since 1.0.19 |
|
52 | + * @var bool |
|
53 | + */ |
|
54 | + protected $object_read = false; |
|
55 | + |
|
56 | + /** |
|
57 | + * This is the name of this object type. |
|
58 | + * |
|
59 | + * @since 1.0.19 |
|
60 | + * @var string |
|
61 | + */ |
|
62 | + protected $object_type = 'data'; |
|
63 | + |
|
64 | + /** |
|
65 | + * Extra data for this object. Name value pairs (name + default value). |
|
66 | + * Used as a standard way for sub classes (like item types) to add |
|
67 | + * additional information to an inherited class. |
|
68 | + * |
|
69 | + * @since 1.0.19 |
|
70 | + * @var array |
|
71 | + */ |
|
72 | + protected $extra_data = array(); |
|
73 | + |
|
74 | + /** |
|
75 | + * Set to _data on construct so we can track and reset data if needed. |
|
76 | + * |
|
77 | + * @since 1.0.19 |
|
78 | + * @var array |
|
79 | + */ |
|
80 | + protected $default_data = array(); |
|
81 | + |
|
82 | + /** |
|
83 | + * Contains a reference to the data store for this class. |
|
84 | + * |
|
85 | + * @since 1.0.19 |
|
86 | + * @var GetPaid_Data_Store |
|
87 | + */ |
|
88 | + protected $data_store; |
|
89 | + |
|
90 | + /** |
|
91 | + * Stores meta in cache for future reads. |
|
92 | + * A group must be set to to enable caching. |
|
93 | + * |
|
94 | + * @since 1.0.19 |
|
95 | + * @var string |
|
96 | + */ |
|
97 | + protected $cache_group = ''; |
|
98 | + |
|
99 | + /** |
|
100 | + * Stores the last error. |
|
101 | + * |
|
102 | + * @since 1.0.19 |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + public $last_error = ''; |
|
106 | + |
|
107 | + /** |
|
108 | + * Stores additional meta data. |
|
109 | + * |
|
110 | + * @since 1.0.19 |
|
111 | + * @var array |
|
112 | + */ |
|
113 | + protected $meta_data = null; |
|
114 | + |
|
115 | + /** |
|
116 | + * Default constructor. |
|
117 | + * |
|
118 | + * @param int|object|array|string $read ID to load from the DB (optional) or already queried data. |
|
119 | + */ |
|
120 | + public function __construct( $read = 0 ) { |
|
121 | + $this->data = array_merge( $this->data, $this->extra_data ); |
|
122 | + $this->default_data = $this->data; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Only store the object ID to avoid serializing the data object instance. |
|
127 | + * |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + public function __sleep() { |
|
131 | + return array( 'id' ); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Re-run the constructor with the object ID. |
|
136 | + * |
|
137 | + * If the object no longer exists, remove the ID. |
|
138 | + */ |
|
139 | + public function __wakeup() { |
|
140 | + $this->__construct( absint( $this->id ) ); |
|
141 | + |
|
142 | + if ( ! empty( $this->last_error ) ) { |
|
143 | + $this->set_id( 0 ); |
|
144 | + } |
|
145 | + |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * When the object is cloned, make sure meta is duplicated correctly. |
|
150 | + * |
|
151 | + * @since 1.0.19 |
|
152 | + */ |
|
153 | + public function __clone() { |
|
154 | + $this->maybe_read_meta_data(); |
|
155 | + if ( ! empty( $this->meta_data ) ) { |
|
156 | + foreach ( $this->meta_data as $array_key => $meta ) { |
|
157 | + $this->meta_data[ $array_key ] = clone $meta; |
|
158 | + if ( ! empty( $meta->id ) ) { |
|
159 | + $this->meta_data[ $array_key ]->id = null; |
|
160 | + } |
|
161 | + } |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Get the data store. |
|
167 | + * |
|
168 | + * @since 1.0.19 |
|
169 | + * @return object |
|
170 | + */ |
|
171 | + public function get_data_store() { |
|
172 | + return $this->data_store; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Get the object type. |
|
177 | + * |
|
178 | + * @since 1.0.19 |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + public function get_object_type() { |
|
182 | + return $this->object_type; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Returns the unique ID for this object. |
|
187 | + * |
|
188 | + * @since 1.0.19 |
|
189 | + * @return int |
|
190 | + */ |
|
191 | + public function get_id() { |
|
192 | + return $this->id; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Get form status. |
|
197 | + * |
|
198 | + * @since 1.0.19 |
|
199 | + * @param string $context View or edit context. |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public function get_status( $context = 'view' ) { |
|
203 | + return $this->get_prop( 'status', $context ); |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Delete an object, set the ID to 0, and return result. |
|
208 | + * |
|
209 | + * @since 1.0.19 |
|
210 | + * @param bool $force_delete Should the data be deleted permanently. |
|
211 | + * @return bool result |
|
212 | + */ |
|
213 | + public function delete( $force_delete = false ) { |
|
214 | + if ( $this->data_store && $this->exists() ) { |
|
215 | + $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
216 | + $this->set_id( 0 ); |
|
217 | + return true; |
|
218 | + } |
|
219 | + return false; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Save should create or update based on object existence. |
|
224 | + * |
|
225 | + * @since 1.0.19 |
|
226 | + * @return int |
|
227 | + */ |
|
228 | + public function save() { |
|
229 | + if ( ! $this->data_store ) { |
|
230 | + return $this->get_id(); |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Trigger action before saving to the DB. Allows you to adjust object props before save. |
|
235 | + * |
|
236 | + * @param GetPaid_Data $this The object being saved. |
|
237 | + * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
238 | + */ |
|
239 | + do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
240 | + |
|
241 | + if ( $this->get_id() ) { |
|
242 | + $this->data_store->update( $this ); |
|
243 | + } else { |
|
244 | + $this->data_store->create( $this ); |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Trigger action after saving to the DB. |
|
249 | + * |
|
250 | + * @param GetPaid_Data $this The object being saved. |
|
251 | + * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
252 | + */ |
|
253 | + do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
254 | + |
|
255 | + return $this->get_id(); |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Change data to JSON format. |
|
260 | + * |
|
261 | + * @since 1.0.19 |
|
262 | + * @return string Data in JSON format. |
|
263 | + */ |
|
264 | + public function __toString() { |
|
265 | + return wp_json_encode( $this->get_data() ); |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * Returns all data for this object. |
|
270 | + * |
|
271 | + * @since 1.0.19 |
|
272 | + * @return array |
|
273 | + */ |
|
274 | + public function get_data() { |
|
275 | + return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Returns array of expected data keys for this object. |
|
280 | + * |
|
281 | + * @since 1.0.19 |
|
282 | + * @return array |
|
283 | + */ |
|
284 | + public function get_data_keys() { |
|
285 | + return array_keys( $this->data ); |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Returns all "extra" data keys for an object (for sub objects like item types). |
|
290 | + * |
|
291 | + * @since 1.0.19 |
|
292 | + * @return array |
|
293 | + */ |
|
294 | + public function get_extra_data_keys() { |
|
295 | + return array_keys( $this->extra_data ); |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Filter null meta values from array. |
|
300 | + * |
|
301 | + * @since 1.0.19 |
|
302 | + * @param mixed $meta Meta value to check. |
|
303 | + * @return bool |
|
304 | + */ |
|
305 | + protected function filter_null_meta( $meta ) { |
|
306 | + return ! is_null( $meta->value ); |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * Get All Meta Data. |
|
311 | + * |
|
312 | + * @since 1.0.19 |
|
313 | + * @return array of objects. |
|
314 | + */ |
|
315 | + public function get_meta_data() { |
|
316 | + $this->maybe_read_meta_data(); |
|
317 | + return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * Check if the key is an internal one. |
|
322 | + * |
|
323 | + * @since 1.0.19 |
|
324 | + * @param string $key Key to check. |
|
325 | + * @return bool true if it's an internal key, false otherwise |
|
326 | + */ |
|
327 | + protected function is_internal_meta_key( $key ) { |
|
328 | + $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
329 | + |
|
330 | + if ( ! $internal_meta_key ) { |
|
331 | + return false; |
|
332 | + } |
|
333 | + |
|
334 | + $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
335 | + |
|
336 | + if ( ! $has_setter_or_getter ) { |
|
337 | + return false; |
|
338 | + } |
|
339 | + |
|
340 | + /* translators: %s: $key Key to check */ |
|
341 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
342 | + |
|
343 | + return true; |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Magic method for setting data fields. |
|
348 | + * |
|
349 | + * This method does not update custom fields in the database. |
|
350 | + * |
|
351 | + * @since 1.0.19 |
|
352 | + * @access public |
|
353 | + * |
|
354 | + */ |
|
355 | + public function __set( $key, $value ) { |
|
356 | + |
|
357 | + if ( 'id' == strtolower( $key ) ) { |
|
358 | + return $this->set_id( $value ); |
|
359 | + } |
|
360 | + |
|
361 | + if ( method_exists( $this, "set_$key") ) { |
|
362 | + |
|
363 | + /* translators: %s: $key Key to set */ |
|
364 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
365 | + |
|
366 | + call_user_func( array( $this, "set_$key" ), $value ); |
|
367 | + } else { |
|
368 | + $this->set_prop( $key, $value ); |
|
369 | + } |
|
370 | + |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | 374 | * Margic method for retrieving a property. |
375 | 375 | */ |
376 | 376 | public function __get( $key ) { |
@@ -378,10 +378,10 @@ discard block |
||
378 | 378 | // Check if we have a helper method for that. |
379 | 379 | if ( method_exists( $this, 'get_' . $key ) ) { |
380 | 380 | |
381 | - if ( 'post_type' != $key ) { |
|
382 | - /* translators: %s: $key Key to set */ |
|
383 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
384 | - } |
|
381 | + if ( 'post_type' != $key ) { |
|
382 | + /* translators: %s: $key Key to set */ |
|
383 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
384 | + } |
|
385 | 385 | |
386 | 386 | return call_user_func( array( $this, 'get_' . $key ) ); |
387 | 387 | } |
@@ -391,515 +391,515 @@ 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 | - $_key = str_replace( '_wpinv', '', $key ); |
|
411 | - $_key = str_replace( 'wpinv', '', $_key ); |
|
412 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
413 | - $function = 'get_' . $_key; |
|
414 | - |
|
415 | - if ( is_callable( array( $this, $function ) ) ) { |
|
416 | - return $this->{$function}(); |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - // Read the meta data if not yet read. |
|
421 | - $this->maybe_read_meta_data(); |
|
422 | - $meta_data = $this->get_meta_data(); |
|
423 | - $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
424 | - $value = $single ? '' : array(); |
|
425 | - |
|
426 | - if ( ! empty( $array_keys ) ) { |
|
427 | - // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
|
428 | - if ( $single ) { |
|
429 | - $value = $meta_data[ current( $array_keys ) ]->value; |
|
430 | - } else { |
|
431 | - $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
432 | - } |
|
433 | - } |
|
434 | - |
|
435 | - if ( 'view' === $context ) { |
|
436 | - $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
437 | - } |
|
438 | - |
|
439 | - return $value; |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * See if meta data exists, since get_meta always returns a '' or array(). |
|
444 | - * |
|
445 | - * @since 1.0.19 |
|
446 | - * @param string $key Meta Key. |
|
447 | - * @return boolean |
|
448 | - */ |
|
449 | - public function meta_exists( $key = '' ) { |
|
450 | - $this->maybe_read_meta_data(); |
|
451 | - $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
452 | - return in_array( $key, $array_keys, true ); |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Set all meta data from array. |
|
457 | - * |
|
458 | - * @since 1.0.19 |
|
459 | - * @param array $data Key/Value pairs. |
|
460 | - */ |
|
461 | - public function set_meta_data( $data ) { |
|
462 | - if ( ! empty( $data ) && is_array( $data ) ) { |
|
463 | - $this->maybe_read_meta_data(); |
|
464 | - foreach ( $data as $meta ) { |
|
465 | - $meta = (array) $meta; |
|
466 | - if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
467 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
468 | - array( |
|
469 | - 'id' => $meta['id'], |
|
470 | - 'key' => $meta['key'], |
|
471 | - 'value' => $meta['value'], |
|
472 | - ) |
|
473 | - ); |
|
474 | - } |
|
475 | - } |
|
476 | - } |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * Add meta data. |
|
481 | - * |
|
482 | - * @since 1.0.19 |
|
483 | - * |
|
484 | - * @param string $key Meta key. |
|
485 | - * @param string|array $value Meta value. |
|
486 | - * @param bool $unique Should this be a unique key?. |
|
487 | - */ |
|
488 | - public function add_meta_data( $key, $value, $unique = false ) { |
|
489 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
490 | - $function = 'set_' . $key; |
|
491 | - |
|
492 | - if ( is_callable( array( $this, $function ) ) ) { |
|
493 | - return $this->{$function}( $value ); |
|
494 | - } |
|
495 | - } |
|
496 | - |
|
497 | - $this->maybe_read_meta_data(); |
|
498 | - if ( $unique ) { |
|
499 | - $this->delete_meta_data( $key ); |
|
500 | - } |
|
501 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
502 | - array( |
|
503 | - 'key' => $key, |
|
504 | - 'value' => $value, |
|
505 | - ) |
|
506 | - ); |
|
507 | - |
|
508 | - $this->save(); |
|
509 | - } |
|
510 | - |
|
511 | - /** |
|
512 | - * Update meta data by key or ID, if provided. |
|
513 | - * |
|
514 | - * @since 1.0.19 |
|
515 | - * |
|
516 | - * @param string $key Meta key. |
|
517 | - * @param string|array $value Meta value. |
|
518 | - * @param int $meta_id Meta ID. |
|
519 | - */ |
|
520 | - public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
521 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
522 | - $function = 'set_' . $key; |
|
523 | - |
|
524 | - if ( is_callable( array( $this, $function ) ) ) { |
|
525 | - return $this->{$function}( $value ); |
|
526 | - } |
|
527 | - } |
|
528 | - |
|
529 | - $this->maybe_read_meta_data(); |
|
530 | - |
|
531 | - $array_key = false; |
|
532 | - |
|
533 | - if ( $meta_id ) { |
|
534 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
535 | - $array_key = $array_keys ? current( $array_keys ) : false; |
|
536 | - } else { |
|
537 | - // Find matches by key. |
|
538 | - $matches = array(); |
|
539 | - foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
540 | - if ( $meta->key === $key ) { |
|
541 | - $matches[] = $meta_data_array_key; |
|
542 | - } |
|
543 | - } |
|
544 | - |
|
545 | - if ( ! empty( $matches ) ) { |
|
546 | - // Set matches to null so only one key gets the new value. |
|
547 | - foreach ( $matches as $meta_data_array_key ) { |
|
548 | - $this->meta_data[ $meta_data_array_key ]->value = null; |
|
549 | - } |
|
550 | - $array_key = current( $matches ); |
|
551 | - } |
|
552 | - } |
|
553 | - |
|
554 | - if ( false !== $array_key ) { |
|
555 | - $meta = $this->meta_data[ $array_key ]; |
|
556 | - $meta->key = $key; |
|
557 | - $meta->value = $value; |
|
558 | - } else { |
|
559 | - $this->add_meta_data( $key, $value, true ); |
|
560 | - } |
|
561 | - } |
|
562 | - |
|
563 | - /** |
|
564 | - * Delete meta data. |
|
565 | - * |
|
566 | - * @since 1.0.19 |
|
567 | - * @param string $key Meta key. |
|
568 | - */ |
|
569 | - public function delete_meta_data( $key ) { |
|
570 | - $this->maybe_read_meta_data(); |
|
571 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
572 | - |
|
573 | - if ( $array_keys ) { |
|
574 | - foreach ( $array_keys as $array_key ) { |
|
575 | - $this->meta_data[ $array_key ]->value = null; |
|
576 | - } |
|
577 | - } |
|
578 | - } |
|
579 | - |
|
580 | - /** |
|
581 | - * Delete meta data. |
|
582 | - * |
|
583 | - * @since 1.0.19 |
|
584 | - * @param int $mid Meta ID. |
|
585 | - */ |
|
586 | - public function delete_meta_data_by_mid( $mid ) { |
|
587 | - $this->maybe_read_meta_data(); |
|
588 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
589 | - |
|
590 | - if ( $array_keys ) { |
|
591 | - foreach ( $array_keys as $array_key ) { |
|
592 | - $this->meta_data[ $array_key ]->value = null; |
|
593 | - } |
|
594 | - } |
|
595 | - } |
|
596 | - |
|
597 | - /** |
|
598 | - * Read meta data if null. |
|
599 | - * |
|
600 | - * @since 1.0.19 |
|
601 | - */ |
|
602 | - protected function maybe_read_meta_data() { |
|
603 | - if ( is_null( $this->meta_data ) ) { |
|
604 | - $this->read_meta_data(); |
|
605 | - } |
|
606 | - } |
|
607 | - |
|
608 | - /** |
|
609 | - * Read Meta Data from the database. Ignore any internal properties. |
|
610 | - * Uses it's own caches because get_metadata does not provide meta_ids. |
|
611 | - * |
|
612 | - * @since 1.0.19 |
|
613 | - * @param bool $force_read True to force a new DB read (and update cache). |
|
614 | - */ |
|
615 | - public function read_meta_data( $force_read = false ) { |
|
616 | - |
|
617 | - // Reset meta data. |
|
618 | - $this->meta_data = array(); |
|
619 | - |
|
620 | - // Maybe abort early. |
|
621 | - if ( ! $this->get_id() || ! $this->data_store ) { |
|
622 | - return; |
|
623 | - } |
|
624 | - |
|
625 | - // Only read from cache if the cache key is set. |
|
626 | - $cache_key = null; |
|
627 | - if ( ! $force_read && ! empty( $this->cache_group ) ) { |
|
628 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
629 | - $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group ); |
|
630 | - } |
|
631 | - |
|
632 | - // Should we force read? |
|
633 | - if ( empty( $raw_meta_data ) ) { |
|
634 | - $raw_meta_data = $this->data_store->read_meta( $this ); |
|
635 | - |
|
636 | - if ( ! empty( $cache_key ) ) { |
|
637 | - wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
638 | - } |
|
639 | - |
|
640 | - } |
|
641 | - |
|
642 | - // Set meta data. |
|
643 | - if ( is_array( $raw_meta_data ) ) { |
|
644 | - |
|
645 | - foreach ( $raw_meta_data as $meta ) { |
|
646 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
647 | - array( |
|
648 | - 'id' => (int) $meta->meta_id, |
|
649 | - 'key' => $meta->meta_key, |
|
650 | - 'value' => maybe_unserialize( $meta->meta_value ), |
|
651 | - ) |
|
652 | - ); |
|
653 | - } |
|
654 | - |
|
655 | - } |
|
656 | - |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * Update Meta Data in the database. |
|
661 | - * |
|
662 | - * @since 1.0.19 |
|
663 | - */ |
|
664 | - public function save_meta_data() { |
|
665 | - if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
666 | - return; |
|
667 | - } |
|
668 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
669 | - if ( is_null( $meta->value ) ) { |
|
670 | - if ( ! empty( $meta->id ) ) { |
|
671 | - $this->data_store->delete_meta( $this, $meta ); |
|
672 | - unset( $this->meta_data[ $array_key ] ); |
|
673 | - } |
|
674 | - } elseif ( empty( $meta->id ) ) { |
|
675 | - $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
676 | - $meta->apply_changes(); |
|
677 | - } else { |
|
678 | - if ( $meta->get_changes() ) { |
|
679 | - $this->data_store->update_meta( $this, $meta ); |
|
680 | - $meta->apply_changes(); |
|
681 | - } |
|
682 | - } |
|
683 | - } |
|
684 | - if ( ! empty( $this->cache_group ) ) { |
|
685 | - $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(); |
|
686 | - wp_cache_delete( $cache_key, $this->cache_group ); |
|
687 | - } |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Set ID. |
|
692 | - * |
|
693 | - * @since 1.0.19 |
|
694 | - * @param int $id ID. |
|
695 | - */ |
|
696 | - public function set_id( $id ) { |
|
697 | - $this->id = absint( $id ); |
|
698 | - } |
|
699 | - |
|
700 | - /** |
|
701 | - * Sets item status. |
|
702 | - * |
|
703 | - * @since 1.0.19 |
|
704 | - * @param string $status New status. |
|
705 | - * @return array details of change. |
|
706 | - */ |
|
707 | - public function set_status( $status ) { |
|
394 | + return $this->get_prop( $key ); |
|
395 | + |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Get Meta Data by Key. |
|
400 | + * |
|
401 | + * @since 1.0.19 |
|
402 | + * @param string $key Meta Key. |
|
403 | + * @param bool $single return first found meta with key, or all with $key. |
|
404 | + * @param string $context What the value is for. Valid values are view and edit. |
|
405 | + * @return mixed |
|
406 | + */ |
|
407 | + public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
408 | + |
|
409 | + // Check if this is an internal meta key. |
|
410 | + $_key = str_replace( '_wpinv', '', $key ); |
|
411 | + $_key = str_replace( 'wpinv', '', $_key ); |
|
412 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
413 | + $function = 'get_' . $_key; |
|
414 | + |
|
415 | + if ( is_callable( array( $this, $function ) ) ) { |
|
416 | + return $this->{$function}(); |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + // Read the meta data if not yet read. |
|
421 | + $this->maybe_read_meta_data(); |
|
422 | + $meta_data = $this->get_meta_data(); |
|
423 | + $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
424 | + $value = $single ? '' : array(); |
|
425 | + |
|
426 | + if ( ! empty( $array_keys ) ) { |
|
427 | + // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
|
428 | + if ( $single ) { |
|
429 | + $value = $meta_data[ current( $array_keys ) ]->value; |
|
430 | + } else { |
|
431 | + $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
432 | + } |
|
433 | + } |
|
434 | + |
|
435 | + if ( 'view' === $context ) { |
|
436 | + $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
437 | + } |
|
438 | + |
|
439 | + return $value; |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * See if meta data exists, since get_meta always returns a '' or array(). |
|
444 | + * |
|
445 | + * @since 1.0.19 |
|
446 | + * @param string $key Meta Key. |
|
447 | + * @return boolean |
|
448 | + */ |
|
449 | + public function meta_exists( $key = '' ) { |
|
450 | + $this->maybe_read_meta_data(); |
|
451 | + $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
452 | + return in_array( $key, $array_keys, true ); |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Set all meta data from array. |
|
457 | + * |
|
458 | + * @since 1.0.19 |
|
459 | + * @param array $data Key/Value pairs. |
|
460 | + */ |
|
461 | + public function set_meta_data( $data ) { |
|
462 | + if ( ! empty( $data ) && is_array( $data ) ) { |
|
463 | + $this->maybe_read_meta_data(); |
|
464 | + foreach ( $data as $meta ) { |
|
465 | + $meta = (array) $meta; |
|
466 | + if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
467 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
468 | + array( |
|
469 | + 'id' => $meta['id'], |
|
470 | + 'key' => $meta['key'], |
|
471 | + 'value' => $meta['value'], |
|
472 | + ) |
|
473 | + ); |
|
474 | + } |
|
475 | + } |
|
476 | + } |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * Add meta data. |
|
481 | + * |
|
482 | + * @since 1.0.19 |
|
483 | + * |
|
484 | + * @param string $key Meta key. |
|
485 | + * @param string|array $value Meta value. |
|
486 | + * @param bool $unique Should this be a unique key?. |
|
487 | + */ |
|
488 | + public function add_meta_data( $key, $value, $unique = false ) { |
|
489 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
490 | + $function = 'set_' . $key; |
|
491 | + |
|
492 | + if ( is_callable( array( $this, $function ) ) ) { |
|
493 | + return $this->{$function}( $value ); |
|
494 | + } |
|
495 | + } |
|
496 | + |
|
497 | + $this->maybe_read_meta_data(); |
|
498 | + if ( $unique ) { |
|
499 | + $this->delete_meta_data( $key ); |
|
500 | + } |
|
501 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
502 | + array( |
|
503 | + 'key' => $key, |
|
504 | + 'value' => $value, |
|
505 | + ) |
|
506 | + ); |
|
507 | + |
|
508 | + $this->save(); |
|
509 | + } |
|
510 | + |
|
511 | + /** |
|
512 | + * Update meta data by key or ID, if provided. |
|
513 | + * |
|
514 | + * @since 1.0.19 |
|
515 | + * |
|
516 | + * @param string $key Meta key. |
|
517 | + * @param string|array $value Meta value. |
|
518 | + * @param int $meta_id Meta ID. |
|
519 | + */ |
|
520 | + public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
521 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
522 | + $function = 'set_' . $key; |
|
523 | + |
|
524 | + if ( is_callable( array( $this, $function ) ) ) { |
|
525 | + return $this->{$function}( $value ); |
|
526 | + } |
|
527 | + } |
|
528 | + |
|
529 | + $this->maybe_read_meta_data(); |
|
530 | + |
|
531 | + $array_key = false; |
|
532 | + |
|
533 | + if ( $meta_id ) { |
|
534 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
535 | + $array_key = $array_keys ? current( $array_keys ) : false; |
|
536 | + } else { |
|
537 | + // Find matches by key. |
|
538 | + $matches = array(); |
|
539 | + foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
540 | + if ( $meta->key === $key ) { |
|
541 | + $matches[] = $meta_data_array_key; |
|
542 | + } |
|
543 | + } |
|
544 | + |
|
545 | + if ( ! empty( $matches ) ) { |
|
546 | + // Set matches to null so only one key gets the new value. |
|
547 | + foreach ( $matches as $meta_data_array_key ) { |
|
548 | + $this->meta_data[ $meta_data_array_key ]->value = null; |
|
549 | + } |
|
550 | + $array_key = current( $matches ); |
|
551 | + } |
|
552 | + } |
|
553 | + |
|
554 | + if ( false !== $array_key ) { |
|
555 | + $meta = $this->meta_data[ $array_key ]; |
|
556 | + $meta->key = $key; |
|
557 | + $meta->value = $value; |
|
558 | + } else { |
|
559 | + $this->add_meta_data( $key, $value, true ); |
|
560 | + } |
|
561 | + } |
|
562 | + |
|
563 | + /** |
|
564 | + * Delete meta data. |
|
565 | + * |
|
566 | + * @since 1.0.19 |
|
567 | + * @param string $key Meta key. |
|
568 | + */ |
|
569 | + public function delete_meta_data( $key ) { |
|
570 | + $this->maybe_read_meta_data(); |
|
571 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
572 | + |
|
573 | + if ( $array_keys ) { |
|
574 | + foreach ( $array_keys as $array_key ) { |
|
575 | + $this->meta_data[ $array_key ]->value = null; |
|
576 | + } |
|
577 | + } |
|
578 | + } |
|
579 | + |
|
580 | + /** |
|
581 | + * Delete meta data. |
|
582 | + * |
|
583 | + * @since 1.0.19 |
|
584 | + * @param int $mid Meta ID. |
|
585 | + */ |
|
586 | + public function delete_meta_data_by_mid( $mid ) { |
|
587 | + $this->maybe_read_meta_data(); |
|
588 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
589 | + |
|
590 | + if ( $array_keys ) { |
|
591 | + foreach ( $array_keys as $array_key ) { |
|
592 | + $this->meta_data[ $array_key ]->value = null; |
|
593 | + } |
|
594 | + } |
|
595 | + } |
|
596 | + |
|
597 | + /** |
|
598 | + * Read meta data if null. |
|
599 | + * |
|
600 | + * @since 1.0.19 |
|
601 | + */ |
|
602 | + protected function maybe_read_meta_data() { |
|
603 | + if ( is_null( $this->meta_data ) ) { |
|
604 | + $this->read_meta_data(); |
|
605 | + } |
|
606 | + } |
|
607 | + |
|
608 | + /** |
|
609 | + * Read Meta Data from the database. Ignore any internal properties. |
|
610 | + * Uses it's own caches because get_metadata does not provide meta_ids. |
|
611 | + * |
|
612 | + * @since 1.0.19 |
|
613 | + * @param bool $force_read True to force a new DB read (and update cache). |
|
614 | + */ |
|
615 | + public function read_meta_data( $force_read = false ) { |
|
616 | + |
|
617 | + // Reset meta data. |
|
618 | + $this->meta_data = array(); |
|
619 | + |
|
620 | + // Maybe abort early. |
|
621 | + if ( ! $this->get_id() || ! $this->data_store ) { |
|
622 | + return; |
|
623 | + } |
|
624 | + |
|
625 | + // Only read from cache if the cache key is set. |
|
626 | + $cache_key = null; |
|
627 | + if ( ! $force_read && ! empty( $this->cache_group ) ) { |
|
628 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
629 | + $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group ); |
|
630 | + } |
|
631 | + |
|
632 | + // Should we force read? |
|
633 | + if ( empty( $raw_meta_data ) ) { |
|
634 | + $raw_meta_data = $this->data_store->read_meta( $this ); |
|
635 | + |
|
636 | + if ( ! empty( $cache_key ) ) { |
|
637 | + wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
638 | + } |
|
639 | + |
|
640 | + } |
|
641 | + |
|
642 | + // Set meta data. |
|
643 | + if ( is_array( $raw_meta_data ) ) { |
|
644 | + |
|
645 | + foreach ( $raw_meta_data as $meta ) { |
|
646 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
647 | + array( |
|
648 | + 'id' => (int) $meta->meta_id, |
|
649 | + 'key' => $meta->meta_key, |
|
650 | + 'value' => maybe_unserialize( $meta->meta_value ), |
|
651 | + ) |
|
652 | + ); |
|
653 | + } |
|
654 | + |
|
655 | + } |
|
656 | + |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * Update Meta Data in the database. |
|
661 | + * |
|
662 | + * @since 1.0.19 |
|
663 | + */ |
|
664 | + public function save_meta_data() { |
|
665 | + if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
666 | + return; |
|
667 | + } |
|
668 | + foreach ( $this->meta_data as $array_key => $meta ) { |
|
669 | + if ( is_null( $meta->value ) ) { |
|
670 | + if ( ! empty( $meta->id ) ) { |
|
671 | + $this->data_store->delete_meta( $this, $meta ); |
|
672 | + unset( $this->meta_data[ $array_key ] ); |
|
673 | + } |
|
674 | + } elseif ( empty( $meta->id ) ) { |
|
675 | + $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
676 | + $meta->apply_changes(); |
|
677 | + } else { |
|
678 | + if ( $meta->get_changes() ) { |
|
679 | + $this->data_store->update_meta( $this, $meta ); |
|
680 | + $meta->apply_changes(); |
|
681 | + } |
|
682 | + } |
|
683 | + } |
|
684 | + if ( ! empty( $this->cache_group ) ) { |
|
685 | + $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(); |
|
686 | + wp_cache_delete( $cache_key, $this->cache_group ); |
|
687 | + } |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Set ID. |
|
692 | + * |
|
693 | + * @since 1.0.19 |
|
694 | + * @param int $id ID. |
|
695 | + */ |
|
696 | + public function set_id( $id ) { |
|
697 | + $this->id = absint( $id ); |
|
698 | + } |
|
699 | + |
|
700 | + /** |
|
701 | + * Sets item status. |
|
702 | + * |
|
703 | + * @since 1.0.19 |
|
704 | + * @param string $status New status. |
|
705 | + * @return array details of change. |
|
706 | + */ |
|
707 | + public function set_status( $status ) { |
|
708 | 708 | $old_status = $this->get_status(); |
709 | 709 | |
710 | - $this->set_prop( 'status', $status ); |
|
711 | - |
|
712 | - return array( |
|
713 | - 'from' => $old_status, |
|
714 | - 'to' => $status, |
|
715 | - ); |
|
716 | - } |
|
717 | - |
|
718 | - /** |
|
719 | - * Set all props to default values. |
|
720 | - * |
|
721 | - * @since 1.0.19 |
|
722 | - */ |
|
723 | - public function set_defaults() { |
|
724 | - $this->data = $this->default_data; |
|
725 | - $this->changes = array(); |
|
726 | - $this->set_object_read( false ); |
|
727 | - } |
|
728 | - |
|
729 | - /** |
|
730 | - * Set object read property. |
|
731 | - * |
|
732 | - * @since 1.0.19 |
|
733 | - * @param boolean $read Should read?. |
|
734 | - */ |
|
735 | - public function set_object_read( $read = true ) { |
|
736 | - $this->object_read = (bool) $read; |
|
737 | - } |
|
738 | - |
|
739 | - /** |
|
740 | - * Get object read property. |
|
741 | - * |
|
742 | - * @since 1.0.19 |
|
743 | - * @return boolean |
|
744 | - */ |
|
745 | - public function get_object_read() { |
|
746 | - return (bool) $this->object_read; |
|
747 | - } |
|
748 | - |
|
749 | - /** |
|
750 | - * Set a collection of props in one go, collect any errors, and return the result. |
|
751 | - * Only sets using public methods. |
|
752 | - * |
|
753 | - * @since 1.0.19 |
|
754 | - * |
|
755 | - * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
756 | - * @param string $context In what context to run this. |
|
757 | - * |
|
758 | - * @return bool|WP_Error |
|
759 | - */ |
|
760 | - public function set_props( $props, $context = 'set' ) { |
|
761 | - $errors = false; |
|
762 | - |
|
763 | - $props = wp_unslash( $props ); |
|
764 | - foreach ( $props as $prop => $value ) { |
|
765 | - try { |
|
766 | - /** |
|
767 | - * Checks if the prop being set is allowed, and the value is not null. |
|
768 | - */ |
|
769 | - if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
770 | - continue; |
|
771 | - } |
|
772 | - $setter = "set_$prop"; |
|
773 | - |
|
774 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
775 | - $this->{$setter}( $value ); |
|
776 | - } |
|
777 | - } catch ( Exception $e ) { |
|
778 | - if ( ! $errors ) { |
|
779 | - $errors = new WP_Error(); |
|
780 | - } |
|
781 | - $errors->add( $e->getCode(), $e->getMessage() ); |
|
782 | - $this->last_error = $e->getMessage(); |
|
783 | - } |
|
784 | - } |
|
785 | - |
|
786 | - return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
787 | - } |
|
788 | - |
|
789 | - /** |
|
790 | - * Sets a prop for a setter method. |
|
791 | - * |
|
792 | - * This stores changes in a special array so we can track what needs saving |
|
793 | - * the the DB later. |
|
794 | - * |
|
795 | - * @since 1.0.19 |
|
796 | - * @param string $prop Name of prop to set. |
|
797 | - * @param mixed $value Value of the prop. |
|
798 | - */ |
|
799 | - protected function set_prop( $prop, $value ) { |
|
800 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
801 | - if ( true === $this->object_read ) { |
|
802 | - if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
803 | - $this->changes[ $prop ] = $value; |
|
804 | - } |
|
805 | - } else { |
|
806 | - $this->data[ $prop ] = $value; |
|
807 | - } |
|
808 | - } |
|
809 | - } |
|
810 | - |
|
811 | - /** |
|
812 | - * Return data changes only. |
|
813 | - * |
|
814 | - * @since 1.0.19 |
|
815 | - * @return array |
|
816 | - */ |
|
817 | - public function get_changes() { |
|
818 | - return $this->changes; |
|
819 | - } |
|
820 | - |
|
821 | - /** |
|
822 | - * Merge changes with data and clear. |
|
823 | - * |
|
824 | - * @since 1.0.19 |
|
825 | - */ |
|
826 | - public function apply_changes() { |
|
827 | - $this->data = array_replace( $this->data, $this->changes ); |
|
828 | - $this->changes = array(); |
|
829 | - } |
|
830 | - |
|
831 | - /** |
|
832 | - * Prefix for action and filter hooks on data. |
|
833 | - * |
|
834 | - * @since 1.0.19 |
|
835 | - * @return string |
|
836 | - */ |
|
837 | - protected function get_hook_prefix() { |
|
838 | - return 'wpinv_get_' . $this->object_type . '_'; |
|
839 | - } |
|
840 | - |
|
841 | - /** |
|
842 | - * Gets a prop for a getter method. |
|
843 | - * |
|
844 | - * Gets the value from either current pending changes, or the data itself. |
|
845 | - * Context controls what happens to the value before it's returned. |
|
846 | - * |
|
847 | - * @since 1.0.19 |
|
848 | - * @param string $prop Name of prop to get. |
|
849 | - * @param string $context What the value is for. Valid values are view and edit. |
|
850 | - * @return mixed |
|
851 | - */ |
|
852 | - protected function get_prop( $prop, $context = 'view' ) { |
|
853 | - $value = null; |
|
854 | - |
|
855 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
856 | - $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
857 | - |
|
858 | - if ( 'view' === $context ) { |
|
859 | - $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
860 | - } |
|
861 | - } |
|
862 | - |
|
863 | - return $value; |
|
864 | - } |
|
865 | - |
|
866 | - /** |
|
867 | - * Sets a date prop whilst handling formatting and datetime objects. |
|
868 | - * |
|
869 | - * @since 1.0.19 |
|
870 | - * @param string $prop Name of prop to set. |
|
871 | - * @param string|integer $value Value of the prop. |
|
872 | - */ |
|
873 | - protected function set_date_prop( $prop, $value ) { |
|
874 | - |
|
875 | - if ( empty( $value ) ) { |
|
876 | - $this->set_prop( $prop, null ); |
|
877 | - return; |
|
878 | - } |
|
879 | - $this->set_prop( $prop, $value ); |
|
880 | - |
|
881 | - } |
|
882 | - |
|
883 | - /** |
|
884 | - * When invalid data is found, throw an exception unless reading from the DB. |
|
885 | - * |
|
886 | - * @since 1.0.19 |
|
887 | - * @param string $code Error code. |
|
888 | - * @param string $message Error message. |
|
889 | - */ |
|
890 | - protected function error( $code, $message ) { |
|
891 | - $this->last_error = $message; |
|
892 | - } |
|
893 | - |
|
894 | - /** |
|
895 | - * Checks if the object is saved in the database |
|
896 | - * |
|
897 | - * @since 1.0.19 |
|
898 | - * @return bool |
|
899 | - */ |
|
900 | - public function exists() { |
|
901 | - $id = $this->get_id(); |
|
902 | - return ! empty( $id ); |
|
903 | - } |
|
710 | + $this->set_prop( 'status', $status ); |
|
711 | + |
|
712 | + return array( |
|
713 | + 'from' => $old_status, |
|
714 | + 'to' => $status, |
|
715 | + ); |
|
716 | + } |
|
717 | + |
|
718 | + /** |
|
719 | + * Set all props to default values. |
|
720 | + * |
|
721 | + * @since 1.0.19 |
|
722 | + */ |
|
723 | + public function set_defaults() { |
|
724 | + $this->data = $this->default_data; |
|
725 | + $this->changes = array(); |
|
726 | + $this->set_object_read( false ); |
|
727 | + } |
|
728 | + |
|
729 | + /** |
|
730 | + * Set object read property. |
|
731 | + * |
|
732 | + * @since 1.0.19 |
|
733 | + * @param boolean $read Should read?. |
|
734 | + */ |
|
735 | + public function set_object_read( $read = true ) { |
|
736 | + $this->object_read = (bool) $read; |
|
737 | + } |
|
738 | + |
|
739 | + /** |
|
740 | + * Get object read property. |
|
741 | + * |
|
742 | + * @since 1.0.19 |
|
743 | + * @return boolean |
|
744 | + */ |
|
745 | + public function get_object_read() { |
|
746 | + return (bool) $this->object_read; |
|
747 | + } |
|
748 | + |
|
749 | + /** |
|
750 | + * Set a collection of props in one go, collect any errors, and return the result. |
|
751 | + * Only sets using public methods. |
|
752 | + * |
|
753 | + * @since 1.0.19 |
|
754 | + * |
|
755 | + * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
756 | + * @param string $context In what context to run this. |
|
757 | + * |
|
758 | + * @return bool|WP_Error |
|
759 | + */ |
|
760 | + public function set_props( $props, $context = 'set' ) { |
|
761 | + $errors = false; |
|
762 | + |
|
763 | + $props = wp_unslash( $props ); |
|
764 | + foreach ( $props as $prop => $value ) { |
|
765 | + try { |
|
766 | + /** |
|
767 | + * Checks if the prop being set is allowed, and the value is not null. |
|
768 | + */ |
|
769 | + if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
770 | + continue; |
|
771 | + } |
|
772 | + $setter = "set_$prop"; |
|
773 | + |
|
774 | + if ( is_callable( array( $this, $setter ) ) ) { |
|
775 | + $this->{$setter}( $value ); |
|
776 | + } |
|
777 | + } catch ( Exception $e ) { |
|
778 | + if ( ! $errors ) { |
|
779 | + $errors = new WP_Error(); |
|
780 | + } |
|
781 | + $errors->add( $e->getCode(), $e->getMessage() ); |
|
782 | + $this->last_error = $e->getMessage(); |
|
783 | + } |
|
784 | + } |
|
785 | + |
|
786 | + return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
787 | + } |
|
788 | + |
|
789 | + /** |
|
790 | + * Sets a prop for a setter method. |
|
791 | + * |
|
792 | + * This stores changes in a special array so we can track what needs saving |
|
793 | + * the the DB later. |
|
794 | + * |
|
795 | + * @since 1.0.19 |
|
796 | + * @param string $prop Name of prop to set. |
|
797 | + * @param mixed $value Value of the prop. |
|
798 | + */ |
|
799 | + protected function set_prop( $prop, $value ) { |
|
800 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
801 | + if ( true === $this->object_read ) { |
|
802 | + if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
803 | + $this->changes[ $prop ] = $value; |
|
804 | + } |
|
805 | + } else { |
|
806 | + $this->data[ $prop ] = $value; |
|
807 | + } |
|
808 | + } |
|
809 | + } |
|
810 | + |
|
811 | + /** |
|
812 | + * Return data changes only. |
|
813 | + * |
|
814 | + * @since 1.0.19 |
|
815 | + * @return array |
|
816 | + */ |
|
817 | + public function get_changes() { |
|
818 | + return $this->changes; |
|
819 | + } |
|
820 | + |
|
821 | + /** |
|
822 | + * Merge changes with data and clear. |
|
823 | + * |
|
824 | + * @since 1.0.19 |
|
825 | + */ |
|
826 | + public function apply_changes() { |
|
827 | + $this->data = array_replace( $this->data, $this->changes ); |
|
828 | + $this->changes = array(); |
|
829 | + } |
|
830 | + |
|
831 | + /** |
|
832 | + * Prefix for action and filter hooks on data. |
|
833 | + * |
|
834 | + * @since 1.0.19 |
|
835 | + * @return string |
|
836 | + */ |
|
837 | + protected function get_hook_prefix() { |
|
838 | + return 'wpinv_get_' . $this->object_type . '_'; |
|
839 | + } |
|
840 | + |
|
841 | + /** |
|
842 | + * Gets a prop for a getter method. |
|
843 | + * |
|
844 | + * Gets the value from either current pending changes, or the data itself. |
|
845 | + * Context controls what happens to the value before it's returned. |
|
846 | + * |
|
847 | + * @since 1.0.19 |
|
848 | + * @param string $prop Name of prop to get. |
|
849 | + * @param string $context What the value is for. Valid values are view and edit. |
|
850 | + * @return mixed |
|
851 | + */ |
|
852 | + protected function get_prop( $prop, $context = 'view' ) { |
|
853 | + $value = null; |
|
854 | + |
|
855 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
856 | + $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
857 | + |
|
858 | + if ( 'view' === $context ) { |
|
859 | + $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
860 | + } |
|
861 | + } |
|
862 | + |
|
863 | + return $value; |
|
864 | + } |
|
865 | + |
|
866 | + /** |
|
867 | + * Sets a date prop whilst handling formatting and datetime objects. |
|
868 | + * |
|
869 | + * @since 1.0.19 |
|
870 | + * @param string $prop Name of prop to set. |
|
871 | + * @param string|integer $value Value of the prop. |
|
872 | + */ |
|
873 | + protected function set_date_prop( $prop, $value ) { |
|
874 | + |
|
875 | + if ( empty( $value ) ) { |
|
876 | + $this->set_prop( $prop, null ); |
|
877 | + return; |
|
878 | + } |
|
879 | + $this->set_prop( $prop, $value ); |
|
880 | + |
|
881 | + } |
|
882 | + |
|
883 | + /** |
|
884 | + * When invalid data is found, throw an exception unless reading from the DB. |
|
885 | + * |
|
886 | + * @since 1.0.19 |
|
887 | + * @param string $code Error code. |
|
888 | + * @param string $message Error message. |
|
889 | + */ |
|
890 | + protected function error( $code, $message ) { |
|
891 | + $this->last_error = $message; |
|
892 | + } |
|
893 | + |
|
894 | + /** |
|
895 | + * Checks if the object is saved in the database |
|
896 | + * |
|
897 | + * @since 1.0.19 |
|
898 | + * @return bool |
|
899 | + */ |
|
900 | + public function exists() { |
|
901 | + $id = $this->get_id(); |
|
902 | + return ! empty( $id ); |
|
903 | + } |
|
904 | 904 | |
905 | 905 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | add_ThickBox(); |
10 | 10 | ?> |
@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | <?php if ( $tabs ){ ?> |
15 | 15 | <nav class="nav-tab-wrapper wpi-nav-tab-wrapper"> |
16 | 16 | <?php |
17 | - foreach ( $tabs as $name => $label ) { |
|
18 | - echo '<a href="' . admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>'; |
|
19 | - } |
|
20 | - do_action( 'wpi_addons_tabs' ); |
|
21 | - ?> |
|
17 | + foreach ( $tabs as $name => $label ) { |
|
18 | + echo '<a href="' . admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>'; |
|
19 | + } |
|
20 | + do_action( 'wpi_addons_tabs' ); |
|
21 | + ?> |
|
22 | 22 | </nav> |
23 | 23 | |
24 | 24 | <?php |
25 | 25 | |
26 | - if($current_tab == 'membership'){ |
|
26 | + if($current_tab == 'membership'){ |
|
27 | 27 | |
28 | - ?> |
|
28 | + ?> |
|
29 | 29 | |
30 | 30 | <div class="wpi-membership-tab-conatiner"> |
31 | 31 | <div class="membership-content"> |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | <h2><?php _e("Have a membership key?","invoicing");?></h2> |
37 | 37 | <p> |
38 | 38 | <?php |
39 | - $wpeu_admin = new External_Updates_Admin('wpinvoicing.com','1'); |
|
40 | - echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership',array(95, 106, 108,12351)); |
|
41 | - ?> |
|
39 | + $wpeu_admin = new External_Updates_Admin('wpinvoicing.com','1'); |
|
40 | + echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership',array(95, 106, 108,12351)); |
|
41 | + ?> |
|
42 | 42 | </p> |
43 | 43 | <?php }?> |
44 | 44 | |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | <div class="feature-list"> |
49 | 49 | <ul> |
50 | 50 | <?php |
51 | - $addon_obj = new WPInv_Admin_Addons(); |
|
52 | - if ($addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
53 | - foreach ( $addons as $addon ) { |
|
54 | - echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
55 | - } |
|
56 | - } |
|
57 | - ?> |
|
51 | + $addon_obj = new WPInv_Admin_Addons(); |
|
52 | + if ($addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
53 | + foreach ( $addons as $addon ) { |
|
54 | + echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
55 | + } |
|
56 | + } |
|
57 | + ?> |
|
58 | 58 | </ul> |
59 | 59 | |
60 | 60 | <div class="feature-cta"> |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | <h3><?php _e("Included Gateways:","invoicing");?></h3> |
66 | 66 | <ul> |
67 | 67 | <?php |
68 | - if ($addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
69 | - foreach ( $addons as $addon ) { |
|
70 | - echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
71 | - } |
|
72 | - } |
|
73 | - ?> |
|
68 | + if ($addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
69 | + foreach ( $addons as $addon ) { |
|
70 | + echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
71 | + } |
|
72 | + } |
|
73 | + ?> |
|
74 | 74 | </ul> |
75 | 75 | </div> |
76 | 76 | |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | <div class="testimonial-content"> |
82 | 82 | <div class="t-image"> |
83 | 83 | <?php |
84 | - echo '<img src="' . plugins_url( 'images/t-image2.png', dirname(__FILE__) ) . '" > '; |
|
85 | - ?> |
|
84 | + echo '<img src="' . plugins_url( 'images/t-image2.png', dirname(__FILE__) ) . '" > '; |
|
85 | + ?> |
|
86 | 86 | </div> |
87 | 87 | <div class="t-content"> |
88 | 88 | <p> |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | <div class="testimonial-content"> |
102 | 102 | <div class="t-image"> |
103 | 103 | <?php |
104 | - echo '<img src="' . plugins_url( 'images/t-image1.png', dirname(__FILE__) ) . '" > '; |
|
105 | - ?> |
|
104 | + echo '<img src="' . plugins_url( 'images/t-image1.png', dirname(__FILE__) ) . '" > '; |
|
105 | + ?> |
|
106 | 106 | </div> |
107 | 107 | <div class="t-content"> |
108 | 108 | <p> |
@@ -126,21 +126,21 @@ discard block |
||
126 | 126 | </div> |
127 | 127 | </div> |
128 | 128 | <?php |
129 | - }else{ |
|
130 | - $installed_plugins = get_plugins(); |
|
129 | + }else{ |
|
130 | + $installed_plugins = get_plugins(); |
|
131 | 131 | $addon_obj = new WPInv_Admin_Addons(); |
132 | - if ($addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
133 | - //print_r($addons); |
|
134 | - ?> |
|
132 | + if ($addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
133 | + //print_r($addons); |
|
134 | + ?> |
|
135 | 135 | <ul class="wpi-products"><?php foreach ( $addons as $addon ) : |
136 | 136 | if(965==$addon->info->id){continue;}// don't show quote add on |
137 | - ?><li class="wpi-product"> |
|
137 | + ?><li class="wpi-product"> |
|
138 | 138 | <div class="wpi-product-title"> |
139 | 139 | <h3><?php |
140 | - if ( ! empty( $addon->info->excerpt) ){ |
|
141 | - echo wpi_help_tip( $addon->info->excerpt ); |
|
142 | - } |
|
143 | - echo esc_html( $addon->info->title ); ?></h3> |
|
140 | + if ( ! empty( $addon->info->excerpt) ){ |
|
141 | + echo wpi_help_tip( $addon->info->excerpt ); |
|
142 | + } |
|
143 | + echo esc_html( $addon->info->title ); ?></h3> |
|
144 | 144 | </div> |
145 | 145 | |
146 | 146 | <span class="wpi-product-image"> |
@@ -148,32 +148,32 @@ discard block |
||
148 | 148 | <img src="<?php echo esc_attr( $addon->info->thumbnail ); ?>"/> |
149 | 149 | <?php endif; |
150 | 150 | |
151 | - if ( 'stripe-payment-gateway' == $addon->info->slug ) { |
|
152 | - $addon->info->slug = 'getpaid-stripe-payments'; |
|
153 | - $addon->info->link = 'https://wordpress.org/plugins/getpaid-stripe-payments/'; |
|
154 | - } |
|
155 | - |
|
156 | - if(isset($addon->info->link) && substr( $addon->info->link, 0, 21 ) === "https://wordpress.org"){ |
|
157 | - echo '<a href="'.admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug).'&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
158 | - echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
159 | - echo '</a>'; |
|
160 | - }elseif(isset($addon->info->link) && ( substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com" || substr( $addon->info->link, 0, 21 ) === "https://wpgetpaid.com" ) ){ |
|
161 | - if(defined('WP_EASY_UPDATES_ACTIVE')){ |
|
162 | - $url = admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug.'&width=770&height=660&item_id='.$addon->info->id.'&update_url=https://wpgetpaid.com&TB_iframe=true'); |
|
163 | - }else{ |
|
164 | - // if installed show activation link |
|
165 | - if(isset($installed_plugins['wp-easy-updates/external-updates.php'])){ |
|
166 | - $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
|
167 | - }else{ |
|
168 | - $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
|
169 | - } |
|
170 | - } |
|
171 | - echo '<a href="'.$url.'" class="thickbox">'; |
|
172 | - echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
173 | - echo '</a>'; |
|
174 | - } |
|
175 | - |
|
176 | - ?> |
|
151 | + if ( 'stripe-payment-gateway' == $addon->info->slug ) { |
|
152 | + $addon->info->slug = 'getpaid-stripe-payments'; |
|
153 | + $addon->info->link = 'https://wordpress.org/plugins/getpaid-stripe-payments/'; |
|
154 | + } |
|
155 | + |
|
156 | + if(isset($addon->info->link) && substr( $addon->info->link, 0, 21 ) === "https://wordpress.org"){ |
|
157 | + echo '<a href="'.admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug).'&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
158 | + echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
159 | + echo '</a>'; |
|
160 | + }elseif(isset($addon->info->link) && ( substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com" || substr( $addon->info->link, 0, 21 ) === "https://wpgetpaid.com" ) ){ |
|
161 | + if(defined('WP_EASY_UPDATES_ACTIVE')){ |
|
162 | + $url = admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug.'&width=770&height=660&item_id='.$addon->info->id.'&update_url=https://wpgetpaid.com&TB_iframe=true'); |
|
163 | + }else{ |
|
164 | + // if installed show activation link |
|
165 | + if(isset($installed_plugins['wp-easy-updates/external-updates.php'])){ |
|
166 | + $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
|
167 | + }else{ |
|
168 | + $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
|
169 | + } |
|
170 | + } |
|
171 | + echo '<a href="'.$url.'" class="thickbox">'; |
|
172 | + echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
173 | + echo '</a>'; |
|
174 | + } |
|
175 | + |
|
176 | + ?> |
|
177 | 177 | |
178 | 178 | </span> |
179 | 179 | |
@@ -181,15 +181,15 @@ discard block |
||
181 | 181 | <span class="wpi-product-button"> |
182 | 182 | <?php |
183 | 183 | $addon_obj->output_button( $addon ); |
184 | - ?> |
|
184 | + ?> |
|
185 | 185 | </span> |
186 | 186 | |
187 | 187 | <span class="wpi-price"><?php //print_r($addon); //echo wp_kses_post( $addon->price ); ?></span></li><?php endforeach; ?></ul> |
188 | 188 | <?php endif; |
189 | - } |
|
189 | + } |
|
190 | 190 | |
191 | - } |
|
192 | - ?> |
|
191 | + } |
|
192 | + ?> |
|
193 | 193 | |
194 | 194 | |
195 | 195 | <div class="clearfix" ></div> |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | <input class="wpeu-licence-key" type="text" placeholder="<?php _e("Enter your licence key",'invoicing');?>"> <button class="button-primary wpeu-licence-popup-button" ><?php _e("Install",'invoicing');?></button> |
209 | 209 | <br> |
210 | 210 | <?php |
211 | - echo sprintf( __('%sFind your licence key here%s OR %sBuy one here%s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">','</a>','<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">','</a>' ); |
|
212 | - ?> |
|
211 | + echo sprintf( __('%sFind your licence key here%s OR %sBuy one here%s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">','</a>','<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">','</a>' ); |
|
212 | + ?> |
|
213 | 213 | </span> |
214 | 214 | </div> |
215 | 215 |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | |
14 | 14 | |
15 | 15 | function wpinv_get_default_country() { |
16 | - $country = wpinv_get_option( 'default_country', 'UK' ); |
|
16 | + $country = wpinv_get_option( 'default_country', 'UK' ); |
|
17 | 17 | |
18 | - return apply_filters( 'wpinv_default_country', $country ); |
|
18 | + return apply_filters( 'wpinv_default_country', $country ); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | function wpinv_sanitize_country( $country ) { |
38 | 38 | |
39 | - // Enure the country is specified |
|
39 | + // Enure the country is specified |
|
40 | 40 | if ( empty( $country ) ) { |
41 | 41 | $country = wpinv_get_default_country(); |
42 | 42 | } |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | function wpinv_get_default_state() { |
69 | - $state = wpinv_get_option( 'default_state', '' ); |
|
69 | + $state = wpinv_get_option( 'default_state', '' ); |
|
70 | 70 | |
71 | - return apply_filters( 'wpinv_default_state', $state ); |
|
71 | + return apply_filters( 'wpinv_default_state', $state ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | function wpinv_state_name( $state_code = '', $country_code = '' ) { |
@@ -305,11 +305,11 @@ discard block |
||
305 | 305 | |
306 | 306 | $country = wpinv_sanitize_country( $country ); |
307 | 307 | |
308 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
309 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
310 | - return $continent_code; |
|
311 | - } |
|
312 | - } |
|
308 | + foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
309 | + if ( false !== array_search( $country, $countries, true ) ) { |
|
310 | + return $continent_code; |
|
311 | + } |
|
312 | + } |
|
313 | 313 | |
314 | 314 | return ''; |
315 | 315 | |
@@ -601,33 +601,33 @@ discard block |
||
601 | 601 | } |
602 | 602 | |
603 | 603 | function wpinv_get_states_field() { |
604 | - if( empty( $_POST['country'] ) ) { |
|
605 | - $_POST['country'] = wpinv_get_default_country(); |
|
606 | - } |
|
607 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
604 | + if( empty( $_POST['country'] ) ) { |
|
605 | + $_POST['country'] = wpinv_get_default_country(); |
|
606 | + } |
|
607 | + $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
608 | 608 | |
609 | - if( !empty( $states ) ) { |
|
610 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
609 | + if( !empty( $states ) ) { |
|
610 | + $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
611 | 611 | |
612 | 612 | $class = isset( $_POST['class'] ) ? esc_attr( $_POST['class'] ) : ''; |
613 | 613 | $class .= " $sanitized_field_name getpaid_js_field-state custom-select wpinv-select wpi_select2"; |
614 | 614 | |
615 | 615 | $args = array( |
616 | - 'name' => $sanitized_field_name, |
|
617 | - 'id' => $sanitized_field_name, |
|
618 | - 'class' => implode( ' ', array_unique( explode( ' ', $class ) ) ), |
|
619 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
620 | - 'show_option_all' => false, |
|
621 | - 'show_option_none' => false |
|
622 | - ); |
|
623 | - |
|
624 | - $response = wpinv_html_select( $args ); |
|
625 | - |
|
626 | - } else { |
|
627 | - $response = 'nostates'; |
|
628 | - } |
|
616 | + 'name' => $sanitized_field_name, |
|
617 | + 'id' => $sanitized_field_name, |
|
618 | + 'class' => implode( ' ', array_unique( explode( ' ', $class ) ) ), |
|
619 | + 'options' => array_merge( array( '' => '' ), $states ), |
|
620 | + 'show_option_all' => false, |
|
621 | + 'show_option_none' => false |
|
622 | + ); |
|
623 | + |
|
624 | + $response = wpinv_html_select( $args ); |
|
625 | + |
|
626 | + } else { |
|
627 | + $response = 'nostates'; |
|
628 | + } |
|
629 | 629 | |
630 | - return $response; |
|
630 | + return $response; |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
@@ -645,46 +645,46 @@ discard block |
||
645 | 645 | */ |
646 | 646 | function wpinv_get_address_formats() { |
647 | 647 | |
648 | - return apply_filters( 'wpinv_localisation_address_formats', |
|
649 | - array( |
|
650 | - 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
|
651 | - 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
|
652 | - 'AT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
653 | - 'BE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
654 | - 'CA' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}} {{zip}}\n{{country}}", |
|
655 | - 'CH' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
656 | - 'CL' => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}", |
|
657 | - 'CN' => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}", |
|
658 | - 'CZ' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
659 | - 'DE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
660 | - 'EE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
661 | - 'FI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
662 | - 'DK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
663 | - 'FR' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}", |
|
664 | - 'HK' => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}", |
|
665 | - 'HU' => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}", |
|
666 | - 'IN' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}", |
|
667 | - 'IS' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
668 | - 'IT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}", |
|
669 | - 'JP' => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}", |
|
670 | - 'TW' => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}", |
|
671 | - 'LI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
672 | - 'NL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
673 | - 'NZ' => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}", |
|
674 | - 'NO' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
675 | - 'PL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
676 | - 'PT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
677 | - 'SK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
678 | - 'RS' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
679 | - 'SI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
680 | - 'ES' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}", |
|
681 | - 'SE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
682 | - 'TR' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}", |
|
683 | - 'UG' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}", |
|
684 | - 'US' => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}", |
|
685 | - 'VN' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}", |
|
686 | - ) |
|
687 | - ); |
|
648 | + return apply_filters( 'wpinv_localisation_address_formats', |
|
649 | + array( |
|
650 | + 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
|
651 | + 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
|
652 | + 'AT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
653 | + 'BE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
654 | + 'CA' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}} {{zip}}\n{{country}}", |
|
655 | + 'CH' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
656 | + 'CL' => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}", |
|
657 | + 'CN' => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}", |
|
658 | + 'CZ' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
659 | + 'DE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
660 | + 'EE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
661 | + 'FI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
662 | + 'DK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
663 | + 'FR' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}", |
|
664 | + 'HK' => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}", |
|
665 | + 'HU' => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}", |
|
666 | + 'IN' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}", |
|
667 | + 'IS' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
668 | + 'IT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}", |
|
669 | + 'JP' => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}", |
|
670 | + 'TW' => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}", |
|
671 | + 'LI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
672 | + 'NL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
673 | + 'NZ' => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}", |
|
674 | + 'NO' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
675 | + 'PL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
676 | + 'PT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
677 | + 'SK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
678 | + 'RS' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
679 | + 'SI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
680 | + 'ES' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}", |
|
681 | + 'SE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
682 | + 'TR' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}", |
|
683 | + 'UG' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}", |
|
684 | + 'US' => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}", |
|
685 | + 'VN' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}", |
|
686 | + ) |
|
687 | + ); |
|
688 | 688 | } |
689 | 689 | |
690 | 690 | /** |
@@ -701,21 +701,21 @@ discard block |
||
701 | 701 | } |
702 | 702 | |
703 | 703 | // Get all formats. |
704 | - $formats = wpinv_get_address_formats(); |
|
704 | + $formats = wpinv_get_address_formats(); |
|
705 | 705 | |
706 | - // Get format for the specified country. |
|
707 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
706 | + // Get format for the specified country. |
|
707 | + $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
708 | 708 | |
709 | 709 | /** |
710 | - * Filters the address format to use on Invoices. |
|
710 | + * Filters the address format to use on Invoices. |
|
711 | 711 | * |
712 | 712 | * New lines will be replaced by a `br` element. Double new lines will be replaced by a paragraph. HTML tags are allowed. |
713 | - * |
|
714 | - * @since 1.0.13 |
|
715 | - * |
|
716 | - * @param string $format The address format to use. |
|
713 | + * |
|
714 | + * @since 1.0.13 |
|
715 | + * |
|
716 | + * @param string $format The address format to use. |
|
717 | 717 | * @param string $country The country who's address format is being retrieved. |
718 | - */ |
|
718 | + */ |
|
719 | 719 | return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
720 | 720 | } |
721 | 721 | |
@@ -736,8 +736,8 @@ discard block |
||
736 | 736 | 'country' => '', |
737 | 737 | 'zip' => '', |
738 | 738 | 'first_name' => '', |
739 | - 'last_name' => '', |
|
740 | - 'company' => '', |
|
739 | + 'last_name' => '', |
|
740 | + 'company' => '', |
|
741 | 741 | ); |
742 | 742 | |
743 | 743 | $args = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' ); |
@@ -758,14 +758,14 @@ discard block |
||
758 | 758 | $args['country_code']= $country; |
759 | 759 | |
760 | 760 | /** |
761 | - * Filters the address format replacements to use on Invoices. |
|
761 | + * Filters the address format replacements to use on Invoices. |
|
762 | 762 | * |
763 | - * |
|
764 | - * @since 1.0.13 |
|
765 | - * |
|
766 | - * @param array $replacements The address replacements to use. |
|
763 | + * |
|
764 | + * @since 1.0.13 |
|
765 | + * |
|
766 | + * @param array $replacements The address replacements to use. |
|
767 | 767 | * @param array $billing_details The billing details to use. |
768 | - */ |
|
768 | + */ |
|
769 | 769 | $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
770 | 770 | |
771 | 771 | $return = array(); |
@@ -788,5 +788,5 @@ discard block |
||
788 | 788 | * @return string |
789 | 789 | */ |
790 | 790 | function wpinv_trim_formatted_address_line( $line ) { |
791 | - return trim( $line, ', ' ); |
|
791 | + return trim( $line, ', ' ); |
|
792 | 792 | } |
793 | 793 | \ No newline at end of file |
@@ -20,13 +20,13 @@ |
||
20 | 20 | <title><?php esc_html_e( 'GetPaid › Setup Wizard', 'invoicing' ); ?></title> |
21 | 21 | <?php |
22 | 22 | getpaid_admin()->enqeue_scripts(); |
23 | - wp_enqueue_style( 'font-awesome', 'https://use.fontawesome.com/releases/v5.13.0/css/all.css', array(), 'v5.13.0' ); |
|
24 | - wp_print_styles( 'select2' ); |
|
23 | + wp_enqueue_style( 'font-awesome', 'https://use.fontawesome.com/releases/v5.13.0/css/all.css', array(), 'v5.13.0' ); |
|
24 | + wp_print_styles( 'select2' ); |
|
25 | 25 | wp_print_scripts( 'select2' ); |
26 | - wp_print_scripts( 'wpinv-admin-script' ); |
|
26 | + wp_print_scripts( 'wpinv-admin-script' ); |
|
27 | 27 | do_action( 'admin_print_styles' ); |
28 | 28 | do_action( 'admin_head' ); |
29 | - ?> |
|
29 | + ?> |
|
30 | 30 | <style> |
31 | 31 | body, p{ |
32 | 32 | font-size: 16px; |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | 'getpaid-nonce', |
58 | 58 | 'getpaid-nonce' |
59 | 59 | ); |
60 | - $anchor = __( 'Deactivate', 'invoicing' ); |
|
61 | - $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
60 | + $anchor = __( 'Deactivate', 'invoicing' ); |
|
61 | + $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
62 | 62 | $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
63 | 63 | |
64 | 64 | } else if( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | 'getpaid-nonce', |
74 | 74 | 'getpaid-nonce' |
75 | 75 | ); |
76 | - $anchor = __( 'Activate', 'invoicing' ); |
|
77 | - $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
76 | + $anchor = __( 'Activate', 'invoicing' ); |
|
77 | + $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
78 | 78 | $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
79 | 79 | |
80 | 80 | } |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | 'getpaid-nonce' |
92 | 92 | ) |
93 | 93 | ); |
94 | - $anchor = __( 'Delete', 'invoicing' ); |
|
95 | - $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
94 | + $anchor = __( 'Delete', 'invoicing' ); |
|
95 | + $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
96 | 96 | $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
97 | 97 | |
98 | 98 | $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -319,10 +319,10 @@ discard block |
||
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
322 | - * Output the metabox. |
|
323 | - * |
|
324 | - * @param WP_Post $post |
|
325 | - */ |
|
322 | + * Output the metabox. |
|
323 | + * |
|
324 | + * @param WP_Post $post |
|
325 | + */ |
|
326 | 326 | public static function output2( $post ) { |
327 | 327 | |
328 | 328 | // Prepare the invoice. |
@@ -15,12 +15,12 @@ discard block |
||
15 | 15 | */ |
16 | 16 | |
17 | 17 | if ( ! defined( 'ABSPATH' ) ) { |
18 | - exit; |
|
18 | + exit; |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | if ( ! class_exists( 'AyeCode_Deactivation_Survey' ) ) { |
22 | - // include the class if needed |
|
23 | - include_once( dirname( __FILE__ ) . "/wp-deactivation-survey.php" ); |
|
22 | + // include the class if needed |
|
23 | + include_once( dirname( __FILE__ ) . "/wp-deactivation-survey.php" ); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | |
@@ -36,6 +36,6 @@ discard block |
||
36 | 36 | //}); |
37 | 37 | |
38 | 38 | AyeCode_Deactivation_Survey::instance(array( |
39 | - 'slug' => 'ayecode-deactivation-survey-testing', |
|
40 | - 'version' => '1.0.0' |
|
39 | + 'slug' => 'ayecode-deactivation-survey-testing', |
|
40 | + 'version' => '1.0.0' |
|
41 | 41 | )); |
42 | 42 | \ No newline at end of file |
@@ -20,228 +20,228 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class GetPaid_Installer { |
22 | 22 | |
23 | - /** |
|
24 | - * Upgrades the install. |
|
25 | - * |
|
26 | - * @param string $upgrade_from The current invoicing version. |
|
27 | - */ |
|
28 | - public function upgrade_db( $upgrade_from ) { |
|
29 | - |
|
30 | - // Save the current invoicing version. |
|
31 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | - |
|
33 | - // Setup the invoice Custom Post Type. |
|
34 | - GetPaid_Post_Types::register_post_types(); |
|
35 | - |
|
36 | - // Clear the permalinks |
|
37 | - flush_rewrite_rules(); |
|
38 | - |
|
39 | - // Maybe create new/missing pages. |
|
40 | - $this->create_pages(); |
|
41 | - |
|
42 | - // Maybe re(add) admin capabilities. |
|
43 | - $this->add_capabilities(); |
|
44 | - |
|
45 | - // Maybe create the default payment form. |
|
46 | - wpinv_get_default_payment_form(); |
|
47 | - |
|
48 | - // Create any missing database tables. |
|
49 | - $method = "upgrade_from_$upgrade_from"; |
|
50 | - |
|
51 | - $installed = get_option( 'gepaid_installed_on' ); |
|
52 | - |
|
53 | - if ( empty( $installed ) ) { |
|
54 | - update_option( 'gepaid_installed_on', time() ); |
|
55 | - } |
|
56 | - |
|
57 | - if ( method_exists( $this, $method ) ) { |
|
58 | - $this->$method(); |
|
59 | - } |
|
60 | - |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Do a fresh install. |
|
65 | - * |
|
66 | - */ |
|
67 | - public function upgrade_from_0() { |
|
68 | - $this->create_subscriptions_table(); |
|
69 | - $this->create_invoices_table(); |
|
70 | - $this->create_invoice_items_table(); |
|
71 | - |
|
72 | - // Save default tax rates. |
|
73 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Upgrade to 0.0.5 |
|
78 | - * |
|
79 | - */ |
|
80 | - public function upgrade_from_004() { |
|
81 | - global $wpdb; |
|
82 | - |
|
83 | - // Invoices. |
|
84 | - $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
85 | - if ( ! empty( $results ) ) { |
|
86 | - $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
87 | - |
|
88 | - // Clean post cache |
|
89 | - foreach ( $results as $row ) { |
|
90 | - clean_post_cache( $row->ID ); |
|
91 | - } |
|
92 | - |
|
93 | - } |
|
94 | - |
|
95 | - // Item meta key changes |
|
96 | - $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
97 | - $results = $wpdb->get_results( $query ); |
|
98 | - |
|
99 | - if ( ! empty( $results ) ) { |
|
100 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
101 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
102 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
103 | - |
|
104 | - foreach ( $results as $row ) { |
|
105 | - clean_post_cache( $row->post_id ); |
|
106 | - } |
|
107 | - |
|
108 | - } |
|
109 | - |
|
110 | - $this->upgrade_from_102(); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Upgrade to 1.0.3 |
|
115 | - * |
|
116 | - */ |
|
117 | - public function upgrade_from_102() { |
|
118 | - $this->create_subscriptions_table(); |
|
119 | - $this->upgrade_from_118(); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Upgrade to version 2.0.0. |
|
124 | - * |
|
125 | - */ |
|
126 | - public function upgrade_from_118() { |
|
127 | - $this->create_invoices_table(); |
|
128 | - $this->create_invoice_items_table(); |
|
129 | - $this->migrate_old_invoices(); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Upgrade to version 2.0.8. |
|
134 | - * |
|
135 | - */ |
|
136 | - public function upgrade_from_207() { |
|
137 | - global $wpdb; |
|
138 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" ); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Give administrators the capability to manage GetPaid. |
|
143 | - * |
|
144 | - */ |
|
145 | - public function add_capabilities() { |
|
146 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Retreives GetPaid pages. |
|
151 | - * |
|
152 | - */ |
|
153 | - public static function get_pages() { |
|
154 | - |
|
155 | - return apply_filters( |
|
156 | - 'wpinv_create_pages', |
|
157 | - array( |
|
158 | - |
|
159 | - // Checkout page. |
|
160 | - 'checkout_page' => array( |
|
161 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
162 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
163 | - 'content' => ' |
|
23 | + /** |
|
24 | + * Upgrades the install. |
|
25 | + * |
|
26 | + * @param string $upgrade_from The current invoicing version. |
|
27 | + */ |
|
28 | + public function upgrade_db( $upgrade_from ) { |
|
29 | + |
|
30 | + // Save the current invoicing version. |
|
31 | + update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | + |
|
33 | + // Setup the invoice Custom Post Type. |
|
34 | + GetPaid_Post_Types::register_post_types(); |
|
35 | + |
|
36 | + // Clear the permalinks |
|
37 | + flush_rewrite_rules(); |
|
38 | + |
|
39 | + // Maybe create new/missing pages. |
|
40 | + $this->create_pages(); |
|
41 | + |
|
42 | + // Maybe re(add) admin capabilities. |
|
43 | + $this->add_capabilities(); |
|
44 | + |
|
45 | + // Maybe create the default payment form. |
|
46 | + wpinv_get_default_payment_form(); |
|
47 | + |
|
48 | + // Create any missing database tables. |
|
49 | + $method = "upgrade_from_$upgrade_from"; |
|
50 | + |
|
51 | + $installed = get_option( 'gepaid_installed_on' ); |
|
52 | + |
|
53 | + if ( empty( $installed ) ) { |
|
54 | + update_option( 'gepaid_installed_on', time() ); |
|
55 | + } |
|
56 | + |
|
57 | + if ( method_exists( $this, $method ) ) { |
|
58 | + $this->$method(); |
|
59 | + } |
|
60 | + |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Do a fresh install. |
|
65 | + * |
|
66 | + */ |
|
67 | + public function upgrade_from_0() { |
|
68 | + $this->create_subscriptions_table(); |
|
69 | + $this->create_invoices_table(); |
|
70 | + $this->create_invoice_items_table(); |
|
71 | + |
|
72 | + // Save default tax rates. |
|
73 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Upgrade to 0.0.5 |
|
78 | + * |
|
79 | + */ |
|
80 | + public function upgrade_from_004() { |
|
81 | + global $wpdb; |
|
82 | + |
|
83 | + // Invoices. |
|
84 | + $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
85 | + if ( ! empty( $results ) ) { |
|
86 | + $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
87 | + |
|
88 | + // Clean post cache |
|
89 | + foreach ( $results as $row ) { |
|
90 | + clean_post_cache( $row->ID ); |
|
91 | + } |
|
92 | + |
|
93 | + } |
|
94 | + |
|
95 | + // Item meta key changes |
|
96 | + $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
97 | + $results = $wpdb->get_results( $query ); |
|
98 | + |
|
99 | + if ( ! empty( $results ) ) { |
|
100 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
101 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
102 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
103 | + |
|
104 | + foreach ( $results as $row ) { |
|
105 | + clean_post_cache( $row->post_id ); |
|
106 | + } |
|
107 | + |
|
108 | + } |
|
109 | + |
|
110 | + $this->upgrade_from_102(); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Upgrade to 1.0.3 |
|
115 | + * |
|
116 | + */ |
|
117 | + public function upgrade_from_102() { |
|
118 | + $this->create_subscriptions_table(); |
|
119 | + $this->upgrade_from_118(); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Upgrade to version 2.0.0. |
|
124 | + * |
|
125 | + */ |
|
126 | + public function upgrade_from_118() { |
|
127 | + $this->create_invoices_table(); |
|
128 | + $this->create_invoice_items_table(); |
|
129 | + $this->migrate_old_invoices(); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Upgrade to version 2.0.8. |
|
134 | + * |
|
135 | + */ |
|
136 | + public function upgrade_from_207() { |
|
137 | + global $wpdb; |
|
138 | + $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" ); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Give administrators the capability to manage GetPaid. |
|
143 | + * |
|
144 | + */ |
|
145 | + public function add_capabilities() { |
|
146 | + $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Retreives GetPaid pages. |
|
151 | + * |
|
152 | + */ |
|
153 | + public static function get_pages() { |
|
154 | + |
|
155 | + return apply_filters( |
|
156 | + 'wpinv_create_pages', |
|
157 | + array( |
|
158 | + |
|
159 | + // Checkout page. |
|
160 | + 'checkout_page' => array( |
|
161 | + 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
162 | + 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
163 | + 'content' => ' |
|
164 | 164 | <!-- wp:shortcode --> |
165 | 165 | [wpinv_checkout] |
166 | 166 | <!-- /wp:shortcode --> |
167 | 167 | ', |
168 | - 'parent' => '', |
|
169 | - ), |
|
170 | - |
|
171 | - // Invoice history page. |
|
172 | - 'invoice_history_page' => array( |
|
173 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
174 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
175 | - 'content' => ' |
|
168 | + 'parent' => '', |
|
169 | + ), |
|
170 | + |
|
171 | + // Invoice history page. |
|
172 | + 'invoice_history_page' => array( |
|
173 | + 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
174 | + 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
175 | + 'content' => ' |
|
176 | 176 | <!-- wp:shortcode --> |
177 | 177 | [wpinv_history] |
178 | 178 | <!-- /wp:shortcode --> |
179 | 179 | ', |
180 | - 'parent' => '', |
|
181 | - ), |
|
182 | - |
|
183 | - // Success page content. |
|
184 | - 'success_page' => array( |
|
185 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
186 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
187 | - 'content' => ' |
|
180 | + 'parent' => '', |
|
181 | + ), |
|
182 | + |
|
183 | + // Success page content. |
|
184 | + 'success_page' => array( |
|
185 | + 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
186 | + 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
187 | + 'content' => ' |
|
188 | 188 | <!-- wp:shortcode --> |
189 | 189 | [wpinv_receipt] |
190 | 190 | <!-- /wp:shortcode --> |
191 | 191 | ', |
192 | - 'parent' => 'gp-checkout', |
|
193 | - ), |
|
194 | - |
|
195 | - // Failure page content. |
|
196 | - 'failure_page' => array( |
|
197 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
198 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
199 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
200 | - 'parent' => 'gp-checkout', |
|
201 | - ), |
|
202 | - |
|
203 | - // Subscriptions history page. |
|
204 | - 'invoice_subscription_page' => array( |
|
205 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
206 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
207 | - 'content' => ' |
|
192 | + 'parent' => 'gp-checkout', |
|
193 | + ), |
|
194 | + |
|
195 | + // Failure page content. |
|
196 | + 'failure_page' => array( |
|
197 | + 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
198 | + 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
199 | + 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
200 | + 'parent' => 'gp-checkout', |
|
201 | + ), |
|
202 | + |
|
203 | + // Subscriptions history page. |
|
204 | + 'invoice_subscription_page' => array( |
|
205 | + 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
206 | + 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
207 | + 'content' => ' |
|
208 | 208 | <!-- wp:shortcode --> |
209 | 209 | [wpinv_subscriptions] |
210 | 210 | <!-- /wp:shortcode --> |
211 | 211 | ', |
212 | - 'parent' => '', |
|
213 | - ), |
|
212 | + 'parent' => '', |
|
213 | + ), |
|
214 | 214 | |
215 | - ) |
|
216 | - ); |
|
215 | + ) |
|
216 | + ); |
|
217 | 217 | |
218 | - } |
|
218 | + } |
|
219 | 219 | |
220 | - /** |
|
221 | - * Re-create GetPaid pages. |
|
222 | - * |
|
223 | - */ |
|
224 | - public function create_pages() { |
|
220 | + /** |
|
221 | + * Re-create GetPaid pages. |
|
222 | + * |
|
223 | + */ |
|
224 | + public function create_pages() { |
|
225 | 225 | |
226 | - foreach ( self::get_pages() as $key => $page ) { |
|
227 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
228 | - } |
|
226 | + foreach ( self::get_pages() as $key => $page ) { |
|
227 | + wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
228 | + } |
|
229 | 229 | |
230 | - } |
|
230 | + } |
|
231 | 231 | |
232 | - /** |
|
233 | - * Create subscriptions table. |
|
234 | - * |
|
235 | - */ |
|
236 | - public function create_subscriptions_table() { |
|
232 | + /** |
|
233 | + * Create subscriptions table. |
|
234 | + * |
|
235 | + */ |
|
236 | + public function create_subscriptions_table() { |
|
237 | 237 | |
238 | - global $wpdb; |
|
238 | + global $wpdb; |
|
239 | 239 | |
240 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
240 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
241 | 241 | |
242 | - // Create tables. |
|
243 | - $charset_collate = $wpdb->get_charset_collate(); |
|
244 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
242 | + // Create tables. |
|
243 | + $charset_collate = $wpdb->get_charset_collate(); |
|
244 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
245 | 245 | id bigint(20) unsigned NOT NULL auto_increment, |
246 | 246 | customer_id bigint(20) NOT NULL, |
247 | 247 | frequency int(11) NOT NULL DEFAULT '1', |
@@ -264,22 +264,22 @@ discard block |
||
264 | 264 | KEY customer_and_status (customer_id, status) |
265 | 265 | ) $charset_collate;"; |
266 | 266 | |
267 | - dbDelta( $sql ); |
|
267 | + dbDelta( $sql ); |
|
268 | 268 | |
269 | - } |
|
269 | + } |
|
270 | 270 | |
271 | - /** |
|
272 | - * Create invoices table. |
|
273 | - * |
|
274 | - */ |
|
275 | - public function create_invoices_table() { |
|
276 | - global $wpdb; |
|
271 | + /** |
|
272 | + * Create invoices table. |
|
273 | + * |
|
274 | + */ |
|
275 | + public function create_invoices_table() { |
|
276 | + global $wpdb; |
|
277 | 277 | |
278 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
278 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
279 | 279 | |
280 | - // Create tables. |
|
281 | - $charset_collate = $wpdb->get_charset_collate(); |
|
282 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
280 | + // Create tables. |
|
281 | + $charset_collate = $wpdb->get_charset_collate(); |
|
282 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
283 | 283 | post_id BIGINT(20) NOT NULL, |
284 | 284 | `number` VARCHAR(100), |
285 | 285 | `key` VARCHAR(100), |
@@ -315,22 +315,22 @@ discard block |
||
315 | 315 | KEY `key` (`key`) |
316 | 316 | ) $charset_collate;"; |
317 | 317 | |
318 | - dbDelta( $sql ); |
|
318 | + dbDelta( $sql ); |
|
319 | 319 | |
320 | - } |
|
320 | + } |
|
321 | 321 | |
322 | - /** |
|
323 | - * Create invoice items table. |
|
324 | - * |
|
325 | - */ |
|
326 | - public function create_invoice_items_table() { |
|
327 | - global $wpdb; |
|
322 | + /** |
|
323 | + * Create invoice items table. |
|
324 | + * |
|
325 | + */ |
|
326 | + public function create_invoice_items_table() { |
|
327 | + global $wpdb; |
|
328 | 328 | |
329 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
329 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
330 | 330 | |
331 | - // Create tables. |
|
332 | - $charset_collate = $wpdb->get_charset_collate(); |
|
333 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
331 | + // Create tables. |
|
332 | + $charset_collate = $wpdb->get_charset_collate(); |
|
333 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
334 | 334 | ID BIGINT(20) NOT NULL AUTO_INCREMENT, |
335 | 335 | post_id BIGINT(20) NOT NULL, |
336 | 336 | item_id BIGINT(20) NOT NULL, |
@@ -352,159 +352,159 @@ discard block |
||
352 | 352 | KEY post_id (post_id) |
353 | 353 | ) $charset_collate;"; |
354 | 354 | |
355 | - dbDelta( $sql ); |
|
356 | - |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Migrates old invoices to new invoices. |
|
361 | - * |
|
362 | - */ |
|
363 | - public function migrate_old_invoices() { |
|
364 | - global $wpdb; |
|
365 | - |
|
366 | - $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
367 | - $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
368 | - $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
369 | - $invoices = array_unique( |
|
370 | - get_posts( |
|
371 | - array( |
|
372 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
373 | - 'posts_per_page' => -1, |
|
374 | - 'fields' => 'ids', |
|
375 | - 'post_status' => array_keys( get_post_stati() ), |
|
376 | - 'exclude' => (array) $migrated, |
|
377 | - ) |
|
378 | - ) |
|
379 | - ); |
|
380 | - |
|
381 | - // Abort if we do not have any invoices. |
|
382 | - if ( empty( $invoices ) ) { |
|
383 | - return; |
|
384 | - } |
|
385 | - |
|
386 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
387 | - |
|
388 | - $invoice_rows = array(); |
|
389 | - foreach ( $invoices as $invoice ) { |
|
390 | - |
|
391 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
392 | - |
|
393 | - if ( empty( $invoice->ID ) ) { |
|
394 | - return; |
|
395 | - } |
|
396 | - |
|
397 | - $fields = array ( |
|
398 | - 'post_id' => $invoice->ID, |
|
399 | - 'number' => $invoice->get_number(), |
|
400 | - 'key' => $invoice->get_key(), |
|
401 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
402 | - 'mode' => $invoice->mode, |
|
403 | - 'user_ip' => $invoice->get_ip(), |
|
404 | - 'first_name' => $invoice->get_first_name(), |
|
405 | - 'last_name' => $invoice->get_last_name(), |
|
406 | - 'address' => $invoice->get_address(), |
|
407 | - 'city' => $invoice->city, |
|
408 | - 'state' => $invoice->state, |
|
409 | - 'country' => $invoice->country, |
|
410 | - 'zip' => $invoice->zip, |
|
411 | - 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
412 | - 'gateway' => $invoice->get_gateway(), |
|
413 | - 'transaction_id' => $invoice->get_transaction_id(), |
|
414 | - 'currency' => $invoice->get_currency(), |
|
415 | - 'subtotal' => $invoice->get_subtotal(), |
|
416 | - 'tax' => $invoice->get_tax(), |
|
417 | - 'fees_total' => $invoice->get_fees_total(), |
|
418 | - 'total' => $invoice->get_total(), |
|
419 | - 'discount' => $invoice->get_discount(), |
|
420 | - 'discount_code' => $invoice->get_discount_code(), |
|
421 | - 'disable_taxes' => $invoice->disable_taxes, |
|
422 | - 'due_date' => $invoice->get_due_date(), |
|
423 | - 'completed_date' => $invoice->get_completed_date(), |
|
424 | - 'company' => $invoice->company, |
|
425 | - 'vat_number' => $invoice->vat_number, |
|
426 | - 'vat_rate' => $invoice->vat_rate, |
|
427 | - 'custom_meta' => $invoice->payment_meta |
|
428 | - ); |
|
429 | - |
|
430 | - foreach ( $fields as $key => $val ) { |
|
431 | - if ( is_null( $val ) ) { |
|
432 | - $val = ''; |
|
433 | - } |
|
434 | - $val = maybe_serialize( $val ); |
|
435 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
436 | - } |
|
437 | - |
|
438 | - $fields = implode( ', ', $fields ); |
|
439 | - $invoice_rows[] = "($fields)"; |
|
440 | - |
|
441 | - $item_rows = array(); |
|
442 | - $item_columns = array(); |
|
443 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
444 | - $fields = array( |
|
445 | - 'post_id' => $invoice->ID, |
|
446 | - 'item_id' => $details['id'], |
|
447 | - 'item_name' => $details['name'], |
|
448 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
449 | - 'vat_rate' => $details['vat_rate'], |
|
450 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
451 | - 'tax' => $details['tax'], |
|
452 | - 'item_price' => $details['item_price'], |
|
453 | - 'custom_price' => $details['custom_price'], |
|
454 | - 'quantity' => $details['quantity'], |
|
455 | - 'discount' => $details['discount'], |
|
456 | - 'subtotal' => $details['subtotal'], |
|
457 | - 'price' => $details['price'], |
|
458 | - 'meta' => $details['meta'], |
|
459 | - 'fees' => $details['fees'], |
|
460 | - ); |
|
461 | - |
|
462 | - $item_columns = array_keys ( $fields ); |
|
463 | - |
|
464 | - foreach ( $fields as $key => $val ) { |
|
465 | - if ( is_null( $val ) ) { |
|
466 | - $val = ''; |
|
467 | - } |
|
468 | - $val = maybe_serialize( $val ); |
|
469 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
470 | - } |
|
471 | - |
|
472 | - $fields = implode( ', ', $fields ); |
|
473 | - $item_rows[] = "($fields)"; |
|
474 | - } |
|
475 | - |
|
476 | - $item_rows = implode( ', ', $item_rows ); |
|
477 | - $item_columns = implode( ', ', $item_columns ); |
|
478 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
479 | - } |
|
480 | - |
|
481 | - if ( empty( $invoice_rows ) ) { |
|
482 | - return; |
|
483 | - } |
|
484 | - |
|
485 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
486 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
487 | - |
|
488 | - } |
|
489 | - |
|
490 | - /** |
|
491 | - * Migrates old invoices to new invoices. |
|
492 | - * |
|
493 | - */ |
|
494 | - public static function rename_gateways_label() { |
|
495 | - global $wpdb; |
|
496 | - |
|
497 | - foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
498 | - |
|
499 | - $wpdb->update( |
|
500 | - $wpdb->prefix . 'getpaid_invoices', |
|
501 | - array( 'gateway' => $gateway ), |
|
502 | - array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
503 | - '%s', |
|
504 | - '%s' |
|
505 | - ); |
|
506 | - |
|
507 | - } |
|
508 | - } |
|
355 | + dbDelta( $sql ); |
|
356 | + |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Migrates old invoices to new invoices. |
|
361 | + * |
|
362 | + */ |
|
363 | + public function migrate_old_invoices() { |
|
364 | + global $wpdb; |
|
365 | + |
|
366 | + $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
367 | + $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
368 | + $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
369 | + $invoices = array_unique( |
|
370 | + get_posts( |
|
371 | + array( |
|
372 | + 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
373 | + 'posts_per_page' => -1, |
|
374 | + 'fields' => 'ids', |
|
375 | + 'post_status' => array_keys( get_post_stati() ), |
|
376 | + 'exclude' => (array) $migrated, |
|
377 | + ) |
|
378 | + ) |
|
379 | + ); |
|
380 | + |
|
381 | + // Abort if we do not have any invoices. |
|
382 | + if ( empty( $invoices ) ) { |
|
383 | + return; |
|
384 | + } |
|
385 | + |
|
386 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
387 | + |
|
388 | + $invoice_rows = array(); |
|
389 | + foreach ( $invoices as $invoice ) { |
|
390 | + |
|
391 | + $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
392 | + |
|
393 | + if ( empty( $invoice->ID ) ) { |
|
394 | + return; |
|
395 | + } |
|
396 | + |
|
397 | + $fields = array ( |
|
398 | + 'post_id' => $invoice->ID, |
|
399 | + 'number' => $invoice->get_number(), |
|
400 | + 'key' => $invoice->get_key(), |
|
401 | + 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
402 | + 'mode' => $invoice->mode, |
|
403 | + 'user_ip' => $invoice->get_ip(), |
|
404 | + 'first_name' => $invoice->get_first_name(), |
|
405 | + 'last_name' => $invoice->get_last_name(), |
|
406 | + 'address' => $invoice->get_address(), |
|
407 | + 'city' => $invoice->city, |
|
408 | + 'state' => $invoice->state, |
|
409 | + 'country' => $invoice->country, |
|
410 | + 'zip' => $invoice->zip, |
|
411 | + 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
412 | + 'gateway' => $invoice->get_gateway(), |
|
413 | + 'transaction_id' => $invoice->get_transaction_id(), |
|
414 | + 'currency' => $invoice->get_currency(), |
|
415 | + 'subtotal' => $invoice->get_subtotal(), |
|
416 | + 'tax' => $invoice->get_tax(), |
|
417 | + 'fees_total' => $invoice->get_fees_total(), |
|
418 | + 'total' => $invoice->get_total(), |
|
419 | + 'discount' => $invoice->get_discount(), |
|
420 | + 'discount_code' => $invoice->get_discount_code(), |
|
421 | + 'disable_taxes' => $invoice->disable_taxes, |
|
422 | + 'due_date' => $invoice->get_due_date(), |
|
423 | + 'completed_date' => $invoice->get_completed_date(), |
|
424 | + 'company' => $invoice->company, |
|
425 | + 'vat_number' => $invoice->vat_number, |
|
426 | + 'vat_rate' => $invoice->vat_rate, |
|
427 | + 'custom_meta' => $invoice->payment_meta |
|
428 | + ); |
|
429 | + |
|
430 | + foreach ( $fields as $key => $val ) { |
|
431 | + if ( is_null( $val ) ) { |
|
432 | + $val = ''; |
|
433 | + } |
|
434 | + $val = maybe_serialize( $val ); |
|
435 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
436 | + } |
|
437 | + |
|
438 | + $fields = implode( ', ', $fields ); |
|
439 | + $invoice_rows[] = "($fields)"; |
|
440 | + |
|
441 | + $item_rows = array(); |
|
442 | + $item_columns = array(); |
|
443 | + foreach ( $invoice->get_cart_details() as $details ) { |
|
444 | + $fields = array( |
|
445 | + 'post_id' => $invoice->ID, |
|
446 | + 'item_id' => $details['id'], |
|
447 | + 'item_name' => $details['name'], |
|
448 | + 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
449 | + 'vat_rate' => $details['vat_rate'], |
|
450 | + 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
451 | + 'tax' => $details['tax'], |
|
452 | + 'item_price' => $details['item_price'], |
|
453 | + 'custom_price' => $details['custom_price'], |
|
454 | + 'quantity' => $details['quantity'], |
|
455 | + 'discount' => $details['discount'], |
|
456 | + 'subtotal' => $details['subtotal'], |
|
457 | + 'price' => $details['price'], |
|
458 | + 'meta' => $details['meta'], |
|
459 | + 'fees' => $details['fees'], |
|
460 | + ); |
|
461 | + |
|
462 | + $item_columns = array_keys ( $fields ); |
|
463 | + |
|
464 | + foreach ( $fields as $key => $val ) { |
|
465 | + if ( is_null( $val ) ) { |
|
466 | + $val = ''; |
|
467 | + } |
|
468 | + $val = maybe_serialize( $val ); |
|
469 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
470 | + } |
|
471 | + |
|
472 | + $fields = implode( ', ', $fields ); |
|
473 | + $item_rows[] = "($fields)"; |
|
474 | + } |
|
475 | + |
|
476 | + $item_rows = implode( ', ', $item_rows ); |
|
477 | + $item_columns = implode( ', ', $item_columns ); |
|
478 | + $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
479 | + } |
|
480 | + |
|
481 | + if ( empty( $invoice_rows ) ) { |
|
482 | + return; |
|
483 | + } |
|
484 | + |
|
485 | + $invoice_rows = implode( ', ', $invoice_rows ); |
|
486 | + $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
487 | + |
|
488 | + } |
|
489 | + |
|
490 | + /** |
|
491 | + * Migrates old invoices to new invoices. |
|
492 | + * |
|
493 | + */ |
|
494 | + public static function rename_gateways_label() { |
|
495 | + global $wpdb; |
|
496 | + |
|
497 | + foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
498 | + |
|
499 | + $wpdb->update( |
|
500 | + $wpdb->prefix . 'getpaid_invoices', |
|
501 | + array( 'gateway' => $gateway ), |
|
502 | + array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
503 | + '%s', |
|
504 | + '%s' |
|
505 | + ); |
|
506 | + |
|
507 | + } |
|
508 | + } |
|
509 | 509 | |
510 | 510 | } |