@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -15,517 +15,517 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP { |
17 | 17 | |
18 | - /** |
|
19 | - * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | - * |
|
21 | - * @since 1.0.19 |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $internal_meta_keys = array( |
|
25 | - '_wpinv_subscr_profile_id', |
|
26 | - '_wpinv_subscription_id', |
|
27 | - '_wpinv_taxes', |
|
28 | - '_wpinv_fees', |
|
29 | - '_wpinv_discounts', |
|
30 | - '_wpinv_submission_id', |
|
31 | - '_wpinv_payment_form', |
|
32 | - '_wpinv_is_viewed', |
|
33 | - 'wpinv_email_cc', |
|
34 | - 'wpinv_template' |
|
35 | - ); |
|
36 | - |
|
37 | - /** |
|
38 | - * A map of meta keys to data props. |
|
39 | - * |
|
40 | - * @since 1.0.19 |
|
41 | - * |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - protected $meta_key_to_props = array( |
|
45 | - '_wpinv_subscr_profile_id' => 'remote_subscription_id', |
|
46 | - '_wpinv_subscription_id' => 'subscription_id', |
|
47 | - '_wpinv_taxes' => 'taxes', |
|
48 | - '_wpinv_fees' => 'fees', |
|
49 | - '_wpinv_discounts' => 'discounts', |
|
50 | - '_wpinv_submission_id' => 'submission_id', |
|
51 | - '_wpinv_payment_form' => 'payment_form', |
|
52 | - '_wpinv_is_viewed' => 'is_viewed', |
|
53 | - 'wpinv_email_cc' => 'email_cc', |
|
54 | - 'wpinv_template' => 'template', |
|
55 | - ); |
|
56 | - |
|
57 | - /** |
|
58 | - * A map of database fields to data props. |
|
59 | - * |
|
60 | - * @since 1.0.19 |
|
61 | - * |
|
62 | - * @var array |
|
63 | - */ |
|
64 | - protected $database_fields_to_props = array( |
|
65 | - 'post_id' => 'id', |
|
66 | - 'number' => 'number', |
|
67 | - 'currency' => 'currency', |
|
68 | - 'key' => 'key', |
|
69 | - 'type' => 'type', |
|
70 | - 'mode' => 'mode', |
|
71 | - 'user_ip' => 'user_ip', |
|
72 | - 'first_name' => 'first_name', |
|
73 | - 'last_name' => 'last_name', |
|
74 | - 'address' => 'address', |
|
75 | - 'city' => 'city', |
|
76 | - 'state' => 'state', |
|
77 | - 'country' => 'country', |
|
78 | - 'zip' => 'zip', |
|
79 | - 'zip' => 'zip', |
|
80 | - 'adddress_confirmed' => 'address_confirmed', |
|
81 | - 'gateway' => 'gateway', |
|
82 | - 'transaction_id' => 'transaction_id', |
|
83 | - 'currency' => 'currency', |
|
84 | - 'subtotal' => 'subtotal', |
|
85 | - 'tax' => 'total_tax', |
|
86 | - 'fees_total' => 'total_fees', |
|
87 | - 'discount' => 'total_discount', |
|
88 | - 'total' => 'total', |
|
89 | - 'discount_code' => 'discount_code', |
|
90 | - 'disable_taxes' => 'disable_taxes', |
|
91 | - 'due_date' => 'due_date', |
|
92 | - 'completed_date' => 'completed_date', |
|
93 | - 'company' => 'company', |
|
94 | - 'vat_number' => 'vat_number', |
|
95 | - 'vat_rate' => 'vat_rate', |
|
96 | - ); |
|
97 | - |
|
98 | - /* |
|
18 | + /** |
|
19 | + * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | + * |
|
21 | + * @since 1.0.19 |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $internal_meta_keys = array( |
|
25 | + '_wpinv_subscr_profile_id', |
|
26 | + '_wpinv_subscription_id', |
|
27 | + '_wpinv_taxes', |
|
28 | + '_wpinv_fees', |
|
29 | + '_wpinv_discounts', |
|
30 | + '_wpinv_submission_id', |
|
31 | + '_wpinv_payment_form', |
|
32 | + '_wpinv_is_viewed', |
|
33 | + 'wpinv_email_cc', |
|
34 | + 'wpinv_template' |
|
35 | + ); |
|
36 | + |
|
37 | + /** |
|
38 | + * A map of meta keys to data props. |
|
39 | + * |
|
40 | + * @since 1.0.19 |
|
41 | + * |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + protected $meta_key_to_props = array( |
|
45 | + '_wpinv_subscr_profile_id' => 'remote_subscription_id', |
|
46 | + '_wpinv_subscription_id' => 'subscription_id', |
|
47 | + '_wpinv_taxes' => 'taxes', |
|
48 | + '_wpinv_fees' => 'fees', |
|
49 | + '_wpinv_discounts' => 'discounts', |
|
50 | + '_wpinv_submission_id' => 'submission_id', |
|
51 | + '_wpinv_payment_form' => 'payment_form', |
|
52 | + '_wpinv_is_viewed' => 'is_viewed', |
|
53 | + 'wpinv_email_cc' => 'email_cc', |
|
54 | + 'wpinv_template' => 'template', |
|
55 | + ); |
|
56 | + |
|
57 | + /** |
|
58 | + * A map of database fields to data props. |
|
59 | + * |
|
60 | + * @since 1.0.19 |
|
61 | + * |
|
62 | + * @var array |
|
63 | + */ |
|
64 | + protected $database_fields_to_props = array( |
|
65 | + 'post_id' => 'id', |
|
66 | + 'number' => 'number', |
|
67 | + 'currency' => 'currency', |
|
68 | + 'key' => 'key', |
|
69 | + 'type' => 'type', |
|
70 | + 'mode' => 'mode', |
|
71 | + 'user_ip' => 'user_ip', |
|
72 | + 'first_name' => 'first_name', |
|
73 | + 'last_name' => 'last_name', |
|
74 | + 'address' => 'address', |
|
75 | + 'city' => 'city', |
|
76 | + 'state' => 'state', |
|
77 | + 'country' => 'country', |
|
78 | + 'zip' => 'zip', |
|
79 | + 'zip' => 'zip', |
|
80 | + 'adddress_confirmed' => 'address_confirmed', |
|
81 | + 'gateway' => 'gateway', |
|
82 | + 'transaction_id' => 'transaction_id', |
|
83 | + 'currency' => 'currency', |
|
84 | + 'subtotal' => 'subtotal', |
|
85 | + 'tax' => 'total_tax', |
|
86 | + 'fees_total' => 'total_fees', |
|
87 | + 'discount' => 'total_discount', |
|
88 | + 'total' => 'total', |
|
89 | + 'discount_code' => 'discount_code', |
|
90 | + 'disable_taxes' => 'disable_taxes', |
|
91 | + 'due_date' => 'due_date', |
|
92 | + 'completed_date' => 'completed_date', |
|
93 | + 'company' => 'company', |
|
94 | + 'vat_number' => 'vat_number', |
|
95 | + 'vat_rate' => 'vat_rate', |
|
96 | + ); |
|
97 | + |
|
98 | + /* |
|
99 | 99 | |-------------------------------------------------------------------------- |
100 | 100 | | CRUD Methods |
101 | 101 | |-------------------------------------------------------------------------- |
102 | 102 | */ |
103 | 103 | |
104 | - /** |
|
105 | - * Method to create a new invoice in the database. |
|
106 | - * |
|
107 | - * @param WPInv_Invoice $invoice Invoice object. |
|
108 | - */ |
|
109 | - public function create( &$invoice ) { |
|
110 | - $invoice->set_version( WPINV_VERSION ); |
|
111 | - $invoice->set_date_created( current_time('mysql') ); |
|
112 | - |
|
113 | - // Create a new post. |
|
114 | - $id = wp_insert_post( |
|
115 | - apply_filters( |
|
116 | - 'getpaid_new_invoice_data', |
|
117 | - array( |
|
118 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
119 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
120 | - 'post_status' => $this->get_post_status( $invoice ), |
|
121 | - 'ping_status' => 'closed', |
|
122 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
123 | - 'post_title' => $invoice->get_title( 'edit' ), |
|
124 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
125 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
126 | - ) |
|
127 | - ), |
|
128 | - true |
|
129 | - ); |
|
130 | - |
|
131 | - if ( $id && ! is_wp_error( $id ) ) { |
|
132 | - |
|
133 | - // Update the new id and regenerate a title. |
|
134 | - $invoice->set_id( $id ); |
|
135 | - |
|
136 | - $invoice->maybe_set_number(); |
|
137 | - |
|
138 | - wp_update_post( |
|
139 | - array( |
|
140 | - 'ID' => $invoice->get_id(), |
|
141 | - 'post_title' => $invoice->get_number( 'edit' ), |
|
142 | - 'post_name' => $invoice->get_path( 'edit' ) |
|
143 | - ) |
|
144 | - ); |
|
145 | - |
|
146 | - // Save special fields and items. |
|
147 | - $this->save_special_fields( $invoice ); |
|
148 | - $this->save_items( $invoice ); |
|
149 | - |
|
150 | - // Update meta data. |
|
151 | - $this->update_post_meta( $invoice ); |
|
152 | - $invoice->save_meta_data(); |
|
153 | - |
|
154 | - // Apply changes. |
|
155 | - $invoice->apply_changes(); |
|
156 | - $this->clear_caches( $invoice ); |
|
157 | - |
|
158 | - // Fires after a new invoice is created. |
|
159 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice ); |
|
160 | - return true; |
|
161 | - } |
|
162 | - |
|
163 | - if ( is_wp_error( $id ) ) { |
|
164 | - $invoice->last_error = $id->get_error_message(); |
|
165 | - } |
|
166 | - |
|
167 | - return false; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Method to read an invoice from the database. |
|
172 | - * |
|
173 | - * @param WPInv_Invoice $invoice Invoice object. |
|
174 | - * |
|
175 | - */ |
|
176 | - public function read( &$invoice ) { |
|
177 | - |
|
178 | - $invoice->set_defaults(); |
|
179 | - $invoice_object = get_post( $invoice->get_id() ); |
|
180 | - |
|
181 | - if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
182 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
183 | - $invoice->set_id( 0 ); |
|
184 | - return false; |
|
185 | - } |
|
186 | - |
|
187 | - $invoice->set_props( |
|
188 | - array( |
|
189 | - 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
190 | - 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
191 | - 'status' => $invoice_object->post_status, |
|
192 | - 'author' => $invoice_object->post_author, |
|
193 | - 'description' => $invoice_object->post_excerpt, |
|
194 | - 'parent_id' => $invoice_object->post_parent, |
|
195 | - 'name' => $invoice_object->post_title, |
|
196 | - 'path' => $invoice_object->post_name, |
|
197 | - 'post_type' => $invoice_object->post_type, |
|
198 | - ) |
|
199 | - ); |
|
200 | - |
|
201 | - $invoice->set_type( $invoice_object->post_type ); |
|
202 | - |
|
203 | - $this->read_object_data( $invoice, $invoice_object ); |
|
204 | - $this->add_special_fields( $invoice ); |
|
205 | - $this->add_items( $invoice ); |
|
206 | - $invoice->read_meta_data(); |
|
207 | - $invoice->set_object_read( true ); |
|
208 | - do_action( 'getpaid_read_' . $invoice->get_type(), $invoice ); |
|
209 | - |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Method to update an invoice in the database. |
|
214 | - * |
|
215 | - * @param WPInv_Invoice $invoice Invoice object. |
|
216 | - */ |
|
217 | - public function update( &$invoice ) { |
|
218 | - $invoice->save_meta_data(); |
|
219 | - $invoice->set_version( WPINV_VERSION ); |
|
220 | - |
|
221 | - if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
222 | - $invoice->set_date_created( current_time('mysql') ); |
|
223 | - } |
|
224 | - |
|
225 | - // Ensure both the key and number are set. |
|
226 | - $invoice->get_path(); |
|
227 | - |
|
228 | - // Grab the current status so we can compare. |
|
229 | - $previous_status = get_post_status( $invoice->get_id() ); |
|
230 | - |
|
231 | - $changes = $invoice->get_changes(); |
|
232 | - |
|
233 | - // Only update the post when the post data changes. |
|
234 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
235 | - $post_data = array( |
|
236 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
237 | - 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
238 | - 'post_status' => $invoice->get_status( 'edit' ), |
|
239 | - 'post_title' => $invoice->get_name( 'edit' ), |
|
240 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
241 | - 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
242 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
243 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
244 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
245 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
246 | - ); |
|
247 | - |
|
248 | - /** |
|
249 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
250 | - * to update data, since wp_update_post spawns more calls to the |
|
251 | - * save_post action. |
|
252 | - * |
|
253 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
254 | - * or an update purely from CRUD. |
|
255 | - */ |
|
256 | - if ( doing_action( 'save_post' ) ) { |
|
257 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
258 | - clean_post_cache( $invoice->get_id() ); |
|
259 | - } else { |
|
260 | - wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
261 | - } |
|
262 | - $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
263 | - } |
|
264 | - |
|
265 | - // Update meta data. |
|
266 | - $this->update_post_meta( $invoice ); |
|
267 | - |
|
268 | - // Save special fields and items. |
|
269 | - $this->save_special_fields( $invoice ); |
|
270 | - $this->save_items( $invoice ); |
|
271 | - |
|
272 | - // Apply the changes. |
|
273 | - $invoice->apply_changes(); |
|
274 | - |
|
275 | - // Clear caches. |
|
276 | - $this->clear_caches( $invoice ); |
|
277 | - |
|
278 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
279 | - $new_status = $invoice->get_status( 'edit' ); |
|
280 | - |
|
281 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
282 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice ); |
|
283 | - } else { |
|
284 | - do_action( 'getpaid_update_' . $invoice->get_type(), $invoice ); |
|
285 | - } |
|
286 | - |
|
287 | - } |
|
288 | - |
|
289 | - /* |
|
104 | + /** |
|
105 | + * Method to create a new invoice in the database. |
|
106 | + * |
|
107 | + * @param WPInv_Invoice $invoice Invoice object. |
|
108 | + */ |
|
109 | + public function create( &$invoice ) { |
|
110 | + $invoice->set_version( WPINV_VERSION ); |
|
111 | + $invoice->set_date_created( current_time('mysql') ); |
|
112 | + |
|
113 | + // Create a new post. |
|
114 | + $id = wp_insert_post( |
|
115 | + apply_filters( |
|
116 | + 'getpaid_new_invoice_data', |
|
117 | + array( |
|
118 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
119 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
120 | + 'post_status' => $this->get_post_status( $invoice ), |
|
121 | + 'ping_status' => 'closed', |
|
122 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
123 | + 'post_title' => $invoice->get_title( 'edit' ), |
|
124 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
125 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
126 | + ) |
|
127 | + ), |
|
128 | + true |
|
129 | + ); |
|
130 | + |
|
131 | + if ( $id && ! is_wp_error( $id ) ) { |
|
132 | + |
|
133 | + // Update the new id and regenerate a title. |
|
134 | + $invoice->set_id( $id ); |
|
135 | + |
|
136 | + $invoice->maybe_set_number(); |
|
137 | + |
|
138 | + wp_update_post( |
|
139 | + array( |
|
140 | + 'ID' => $invoice->get_id(), |
|
141 | + 'post_title' => $invoice->get_number( 'edit' ), |
|
142 | + 'post_name' => $invoice->get_path( 'edit' ) |
|
143 | + ) |
|
144 | + ); |
|
145 | + |
|
146 | + // Save special fields and items. |
|
147 | + $this->save_special_fields( $invoice ); |
|
148 | + $this->save_items( $invoice ); |
|
149 | + |
|
150 | + // Update meta data. |
|
151 | + $this->update_post_meta( $invoice ); |
|
152 | + $invoice->save_meta_data(); |
|
153 | + |
|
154 | + // Apply changes. |
|
155 | + $invoice->apply_changes(); |
|
156 | + $this->clear_caches( $invoice ); |
|
157 | + |
|
158 | + // Fires after a new invoice is created. |
|
159 | + do_action( 'getpaid_new_' . $invoice->get_type(), $invoice ); |
|
160 | + return true; |
|
161 | + } |
|
162 | + |
|
163 | + if ( is_wp_error( $id ) ) { |
|
164 | + $invoice->last_error = $id->get_error_message(); |
|
165 | + } |
|
166 | + |
|
167 | + return false; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Method to read an invoice from the database. |
|
172 | + * |
|
173 | + * @param WPInv_Invoice $invoice Invoice object. |
|
174 | + * |
|
175 | + */ |
|
176 | + public function read( &$invoice ) { |
|
177 | + |
|
178 | + $invoice->set_defaults(); |
|
179 | + $invoice_object = get_post( $invoice->get_id() ); |
|
180 | + |
|
181 | + if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
182 | + $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
183 | + $invoice->set_id( 0 ); |
|
184 | + return false; |
|
185 | + } |
|
186 | + |
|
187 | + $invoice->set_props( |
|
188 | + array( |
|
189 | + 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
190 | + 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
191 | + 'status' => $invoice_object->post_status, |
|
192 | + 'author' => $invoice_object->post_author, |
|
193 | + 'description' => $invoice_object->post_excerpt, |
|
194 | + 'parent_id' => $invoice_object->post_parent, |
|
195 | + 'name' => $invoice_object->post_title, |
|
196 | + 'path' => $invoice_object->post_name, |
|
197 | + 'post_type' => $invoice_object->post_type, |
|
198 | + ) |
|
199 | + ); |
|
200 | + |
|
201 | + $invoice->set_type( $invoice_object->post_type ); |
|
202 | + |
|
203 | + $this->read_object_data( $invoice, $invoice_object ); |
|
204 | + $this->add_special_fields( $invoice ); |
|
205 | + $this->add_items( $invoice ); |
|
206 | + $invoice->read_meta_data(); |
|
207 | + $invoice->set_object_read( true ); |
|
208 | + do_action( 'getpaid_read_' . $invoice->get_type(), $invoice ); |
|
209 | + |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Method to update an invoice in the database. |
|
214 | + * |
|
215 | + * @param WPInv_Invoice $invoice Invoice object. |
|
216 | + */ |
|
217 | + public function update( &$invoice ) { |
|
218 | + $invoice->save_meta_data(); |
|
219 | + $invoice->set_version( WPINV_VERSION ); |
|
220 | + |
|
221 | + if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
222 | + $invoice->set_date_created( current_time('mysql') ); |
|
223 | + } |
|
224 | + |
|
225 | + // Ensure both the key and number are set. |
|
226 | + $invoice->get_path(); |
|
227 | + |
|
228 | + // Grab the current status so we can compare. |
|
229 | + $previous_status = get_post_status( $invoice->get_id() ); |
|
230 | + |
|
231 | + $changes = $invoice->get_changes(); |
|
232 | + |
|
233 | + // Only update the post when the post data changes. |
|
234 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
235 | + $post_data = array( |
|
236 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
237 | + 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
238 | + 'post_status' => $invoice->get_status( 'edit' ), |
|
239 | + 'post_title' => $invoice->get_name( 'edit' ), |
|
240 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
241 | + 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
242 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
243 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
244 | + 'post_name' => $invoice->get_path( 'edit' ), |
|
245 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
246 | + ); |
|
247 | + |
|
248 | + /** |
|
249 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
250 | + * to update data, since wp_update_post spawns more calls to the |
|
251 | + * save_post action. |
|
252 | + * |
|
253 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
254 | + * or an update purely from CRUD. |
|
255 | + */ |
|
256 | + if ( doing_action( 'save_post' ) ) { |
|
257 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
258 | + clean_post_cache( $invoice->get_id() ); |
|
259 | + } else { |
|
260 | + wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
261 | + } |
|
262 | + $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
263 | + } |
|
264 | + |
|
265 | + // Update meta data. |
|
266 | + $this->update_post_meta( $invoice ); |
|
267 | + |
|
268 | + // Save special fields and items. |
|
269 | + $this->save_special_fields( $invoice ); |
|
270 | + $this->save_items( $invoice ); |
|
271 | + |
|
272 | + // Apply the changes. |
|
273 | + $invoice->apply_changes(); |
|
274 | + |
|
275 | + // Clear caches. |
|
276 | + $this->clear_caches( $invoice ); |
|
277 | + |
|
278 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
279 | + $new_status = $invoice->get_status( 'edit' ); |
|
280 | + |
|
281 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
282 | + do_action( 'getpaid_new_' . $invoice->get_type(), $invoice ); |
|
283 | + } else { |
|
284 | + do_action( 'getpaid_update_' . $invoice->get_type(), $invoice ); |
|
285 | + } |
|
286 | + |
|
287 | + } |
|
288 | + |
|
289 | + /* |
|
290 | 290 | |-------------------------------------------------------------------------- |
291 | 291 | | Additional Methods |
292 | 292 | |-------------------------------------------------------------------------- |
293 | 293 | */ |
294 | 294 | |
295 | - /** |
|
295 | + /** |
|
296 | 296 | * Retrieves special fields and adds to the invoice. |
297 | - * |
|
298 | - * @param WPInv_Invoice $invoice Invoice object. |
|
297 | + * |
|
298 | + * @param WPInv_Invoice $invoice Invoice object. |
|
299 | 299 | */ |
300 | 300 | public function add_special_fields( &$invoice ) { |
301 | - global $wpdb; |
|
301 | + global $wpdb; |
|
302 | 302 | |
303 | - // Maybe retrieve from the cache. |
|
304 | - $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
303 | + // Maybe retrieve from the cache. |
|
304 | + $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
305 | 305 | |
306 | - // If not found, retrieve from the db. |
|
307 | - if ( false === $data ) { |
|
308 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
306 | + // If not found, retrieve from the db. |
|
307 | + if ( false === $data ) { |
|
308 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
309 | 309 | |
310 | - $data = $wpdb->get_row( |
|
311 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
312 | - ARRAY_A |
|
313 | - ); |
|
310 | + $data = $wpdb->get_row( |
|
311 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
312 | + ARRAY_A |
|
313 | + ); |
|
314 | 314 | |
315 | - // Update the cache with our data |
|
316 | - wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
315 | + // Update the cache with our data |
|
316 | + wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
317 | 317 | |
318 | - } |
|
318 | + } |
|
319 | 319 | |
320 | - // Abort if the data does not exist. |
|
321 | - if ( empty( $data ) ) { |
|
322 | - $invoice->set_object_read( true ); |
|
323 | - $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
324 | - return; |
|
325 | - } |
|
320 | + // Abort if the data does not exist. |
|
321 | + if ( empty( $data ) ) { |
|
322 | + $invoice->set_object_read( true ); |
|
323 | + $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
324 | + return; |
|
325 | + } |
|
326 | 326 | |
327 | - $props = array(); |
|
327 | + $props = array(); |
|
328 | 328 | |
329 | - foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
329 | + foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
330 | 330 | |
331 | - if ( $db_field == 'post_id' ) { |
|
332 | - continue; |
|
333 | - } |
|
334 | - |
|
335 | - $props[ $prop ] = $data[ $db_field ]; |
|
336 | - } |
|
337 | - |
|
338 | - $invoice->set_props( $props ); |
|
339 | - |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Gets a list of special fields that need updated based on change state |
|
344 | - * or if they are present in the database or not. |
|
345 | - * |
|
346 | - * @param WPInv_Invoice $invoice The Invoice object. |
|
347 | - * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
348 | - */ |
|
349 | - protected function get_special_fields_to_update( $invoice ) { |
|
350 | - $fields_to_update = array(); |
|
351 | - $changed_props = $invoice->get_changes(); |
|
352 | - |
|
353 | - // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
354 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
355 | - if ( array_key_exists( $prop, $changed_props ) ) { |
|
356 | - $fields_to_update[ $database_field ] = $prop; |
|
357 | - } |
|
358 | - } |
|
359 | - |
|
360 | - return $fields_to_update; |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
365 | - * |
|
366 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
367 | - * @since 1.0.19 |
|
368 | - */ |
|
369 | - protected function update_special_fields( &$invoice ) { |
|
370 | - global $wpdb; |
|
371 | - |
|
372 | - $updated_props = array(); |
|
373 | - $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
374 | - |
|
375 | - foreach ( $fields_to_update as $database_field => $prop ) { |
|
376 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
377 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
378 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
379 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
380 | - } |
|
381 | - |
|
382 | - if ( ! empty( $updated_props ) ) { |
|
383 | - |
|
384 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
385 | - $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
386 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
387 | - do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
388 | - |
|
389 | - } |
|
390 | - |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Helper method that inserts special fields to the database. |
|
395 | - * |
|
396 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
397 | - * @since 1.0.19 |
|
398 | - */ |
|
399 | - protected function insert_special_fields( &$invoice ) { |
|
400 | - global $wpdb; |
|
401 | - |
|
402 | - $updated_props = array(); |
|
403 | - |
|
404 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
405 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
406 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
407 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
408 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
409 | - } |
|
410 | - |
|
411 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
412 | - $wpdb->insert( $table, $updated_props ); |
|
413 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
414 | - do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
415 | - |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
331 | + if ( $db_field == 'post_id' ) { |
|
332 | + continue; |
|
333 | + } |
|
334 | + |
|
335 | + $props[ $prop ] = $data[ $db_field ]; |
|
336 | + } |
|
337 | + |
|
338 | + $invoice->set_props( $props ); |
|
339 | + |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Gets a list of special fields that need updated based on change state |
|
344 | + * or if they are present in the database or not. |
|
345 | + * |
|
346 | + * @param WPInv_Invoice $invoice The Invoice object. |
|
347 | + * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
348 | + */ |
|
349 | + protected function get_special_fields_to_update( $invoice ) { |
|
350 | + $fields_to_update = array(); |
|
351 | + $changed_props = $invoice->get_changes(); |
|
352 | + |
|
353 | + // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
354 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
355 | + if ( array_key_exists( $prop, $changed_props ) ) { |
|
356 | + $fields_to_update[ $database_field ] = $prop; |
|
357 | + } |
|
358 | + } |
|
359 | + |
|
360 | + return $fields_to_update; |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
365 | + * |
|
366 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
367 | + * @since 1.0.19 |
|
368 | + */ |
|
369 | + protected function update_special_fields( &$invoice ) { |
|
370 | + global $wpdb; |
|
371 | + |
|
372 | + $updated_props = array(); |
|
373 | + $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
374 | + |
|
375 | + foreach ( $fields_to_update as $database_field => $prop ) { |
|
376 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
377 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
378 | + $value = is_bool( $value ) ? ( int ) $value : $value; |
|
379 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
380 | + } |
|
381 | + |
|
382 | + if ( ! empty( $updated_props ) ) { |
|
383 | + |
|
384 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
385 | + $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
386 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
387 | + do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
388 | + |
|
389 | + } |
|
390 | + |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Helper method that inserts special fields to the database. |
|
395 | + * |
|
396 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
397 | + * @since 1.0.19 |
|
398 | + */ |
|
399 | + protected function insert_special_fields( &$invoice ) { |
|
400 | + global $wpdb; |
|
401 | + |
|
402 | + $updated_props = array(); |
|
403 | + |
|
404 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
405 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
406 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
407 | + $value = is_bool( $value ) ? ( int ) $value : $value; |
|
408 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
409 | + } |
|
410 | + |
|
411 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
412 | + $wpdb->insert( $table, $updated_props ); |
|
413 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
414 | + do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
415 | + |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | 419 | * Saves all special fields. |
420 | - * |
|
421 | - * @param WPInv_Invoice $invoice Invoice object. |
|
420 | + * |
|
421 | + * @param WPInv_Invoice $invoice Invoice object. |
|
422 | 422 | */ |
423 | 423 | public function save_special_fields( & $invoice ) { |
424 | - global $wpdb; |
|
424 | + global $wpdb; |
|
425 | 425 | |
426 | - // The invoices table. |
|
427 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
428 | - $id = (int) $invoice->get_id(); |
|
429 | - $invoice->maybe_set_key(); |
|
426 | + // The invoices table. |
|
427 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
428 | + $id = (int) $invoice->get_id(); |
|
429 | + $invoice->maybe_set_key(); |
|
430 | 430 | |
431 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
431 | + if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
432 | 432 | |
433 | - $this->update_special_fields( $invoice ); |
|
433 | + $this->update_special_fields( $invoice ); |
|
434 | 434 | |
435 | - } else { |
|
435 | + } else { |
|
436 | 436 | |
437 | - $this->insert_special_fields( $invoice ); |
|
437 | + $this->insert_special_fields( $invoice ); |
|
438 | 438 | |
439 | - } |
|
439 | + } |
|
440 | 440 | |
441 | - } |
|
441 | + } |
|
442 | 442 | |
443 | - /** |
|
443 | + /** |
|
444 | 444 | * Set's up cart details. |
445 | - * |
|
446 | - * @param WPInv_Invoice $invoice Invoice object. |
|
445 | + * |
|
446 | + * @param WPInv_Invoice $invoice Invoice object. |
|
447 | 447 | */ |
448 | 448 | public function add_items( &$invoice ) { |
449 | - global $wpdb; |
|
449 | + global $wpdb; |
|
450 | 450 | |
451 | - // Maybe retrieve from the cache. |
|
452 | - $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
451 | + // Maybe retrieve from the cache. |
|
452 | + $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
453 | 453 | |
454 | - // If not found, retrieve from the db. |
|
455 | - if ( false === $items ) { |
|
456 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
454 | + // If not found, retrieve from the db. |
|
455 | + if ( false === $items ) { |
|
456 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
457 | 457 | |
458 | - $items = $wpdb->get_results( |
|
459 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
460 | - ); |
|
458 | + $items = $wpdb->get_results( |
|
459 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
460 | + ); |
|
461 | 461 | |
462 | - // Update the cache with our data |
|
463 | - wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
462 | + // Update the cache with our data |
|
463 | + wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
464 | 464 | |
465 | - } |
|
465 | + } |
|
466 | 466 | |
467 | - // Abort if no items found. |
|
467 | + // Abort if no items found. |
|
468 | 468 | if ( empty( $items ) ) { |
469 | 469 | return; |
470 | - } |
|
470 | + } |
|
471 | 471 | |
472 | - foreach ( $items as $item_data ) { |
|
473 | - $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
472 | + foreach ( $items as $item_data ) { |
|
473 | + $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
474 | 474 | |
475 | - // Set item data. |
|
476 | - $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
477 | - $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
478 | - $item->set_name( $item_data->item_name ); |
|
479 | - $item->set_description( $item_data->item_description ); |
|
480 | - $item->set_price( $item_data->item_price ); |
|
481 | - $item->set_quantity( $item_data->quantity ); |
|
482 | - $item->set_item_meta( $item_data->meta ); |
|
475 | + // Set item data. |
|
476 | + $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
477 | + $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
478 | + $item->set_name( $item_data->item_name ); |
|
479 | + $item->set_description( $item_data->item_description ); |
|
480 | + $item->set_price( $item_data->item_price ); |
|
481 | + $item->set_quantity( $item_data->quantity ); |
|
482 | + $item->set_item_meta( $item_data->meta ); |
|
483 | 483 | |
484 | - $invoice->add_item( $item ); |
|
485 | - } |
|
484 | + $invoice->add_item( $item ); |
|
485 | + } |
|
486 | 486 | |
487 | - } |
|
487 | + } |
|
488 | 488 | |
489 | - /** |
|
489 | + /** |
|
490 | 490 | * Saves cart details. |
491 | - * |
|
492 | - * @param WPInv_Invoice $invoice Invoice object. |
|
491 | + * |
|
492 | + * @param WPInv_Invoice $invoice Invoice object. |
|
493 | 493 | */ |
494 | 494 | public function save_items( $invoice ) { |
495 | 495 | |
496 | - // Delete previously existing items. |
|
497 | - $this->delete_items( $invoice ); |
|
496 | + // Delete previously existing items. |
|
497 | + $this->delete_items( $invoice ); |
|
498 | 498 | |
499 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
499 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
500 | 500 | |
501 | - foreach ( $invoice->get_cart_details() as $item_data ) { |
|
502 | - $item_data = array_map( 'maybe_serialize', $item_data ); |
|
503 | - $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
504 | - } |
|
501 | + foreach ( $invoice->get_cart_details() as $item_data ) { |
|
502 | + $item_data = array_map( 'maybe_serialize', $item_data ); |
|
503 | + $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
504 | + } |
|
505 | 505 | |
506 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
507 | - do_action( "getpaid_invoice_save_items", $invoice ); |
|
506 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
507 | + do_action( "getpaid_invoice_save_items", $invoice ); |
|
508 | 508 | |
509 | - } |
|
509 | + } |
|
510 | 510 | |
511 | - /** |
|
511 | + /** |
|
512 | 512 | * Deletes an invoice's cart details from the database. |
513 | - * |
|
514 | - * @param WPInv_Invoice $invoice Invoice object. |
|
513 | + * |
|
514 | + * @param WPInv_Invoice $invoice Invoice object. |
|
515 | 515 | */ |
516 | 516 | public function delete_items( $invoice ) { |
517 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
518 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
519 | - } |
|
517 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
518 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
519 | + } |
|
520 | 520 | |
521 | - /** |
|
521 | + /** |
|
522 | 522 | * Deletes an invoice's special fields from the database. |
523 | - * |
|
524 | - * @param WPInv_Invoice $invoice Invoice object. |
|
523 | + * |
|
524 | + * @param WPInv_Invoice $invoice Invoice object. |
|
525 | 525 | */ |
526 | 526 | public function delete_special_fields( $invoice ) { |
527 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
528 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
527 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
528 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * GetPaid_Invoice_Data_Store class file. |
5 | 5 | * |
6 | 6 | */ |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if (!defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -106,61 +106,61 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @param WPInv_Invoice $invoice Invoice object. |
108 | 108 | */ |
109 | - public function create( &$invoice ) { |
|
110 | - $invoice->set_version( WPINV_VERSION ); |
|
111 | - $invoice->set_date_created( current_time('mysql') ); |
|
109 | + public function create(&$invoice) { |
|
110 | + $invoice->set_version(WPINV_VERSION); |
|
111 | + $invoice->set_date_created(current_time('mysql')); |
|
112 | 112 | |
113 | 113 | // Create a new post. |
114 | 114 | $id = wp_insert_post( |
115 | 115 | apply_filters( |
116 | 116 | 'getpaid_new_invoice_data', |
117 | 117 | array( |
118 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
119 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
120 | - 'post_status' => $this->get_post_status( $invoice ), |
|
118 | + 'post_date' => $invoice->get_date_created('edit'), |
|
119 | + 'post_type' => $invoice->get_post_type('edit'), |
|
120 | + 'post_status' => $this->get_post_status($invoice), |
|
121 | 121 | 'ping_status' => 'closed', |
122 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
123 | - 'post_title' => $invoice->get_title( 'edit' ), |
|
124 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
125 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
122 | + 'post_author' => $invoice->get_user_id('edit'), |
|
123 | + 'post_title' => $invoice->get_title('edit'), |
|
124 | + 'post_excerpt' => $invoice->get_description('edit'), |
|
125 | + 'post_parent' => $invoice->get_parent_id('edit'), |
|
126 | 126 | ) |
127 | 127 | ), |
128 | 128 | true |
129 | 129 | ); |
130 | 130 | |
131 | - if ( $id && ! is_wp_error( $id ) ) { |
|
131 | + if ($id && !is_wp_error($id)) { |
|
132 | 132 | |
133 | 133 | // Update the new id and regenerate a title. |
134 | - $invoice->set_id( $id ); |
|
134 | + $invoice->set_id($id); |
|
135 | 135 | |
136 | 136 | $invoice->maybe_set_number(); |
137 | 137 | |
138 | 138 | wp_update_post( |
139 | 139 | array( |
140 | 140 | 'ID' => $invoice->get_id(), |
141 | - 'post_title' => $invoice->get_number( 'edit' ), |
|
142 | - 'post_name' => $invoice->get_path( 'edit' ) |
|
141 | + 'post_title' => $invoice->get_number('edit'), |
|
142 | + 'post_name' => $invoice->get_path('edit') |
|
143 | 143 | ) |
144 | 144 | ); |
145 | 145 | |
146 | 146 | // Save special fields and items. |
147 | - $this->save_special_fields( $invoice ); |
|
148 | - $this->save_items( $invoice ); |
|
147 | + $this->save_special_fields($invoice); |
|
148 | + $this->save_items($invoice); |
|
149 | 149 | |
150 | 150 | // Update meta data. |
151 | - $this->update_post_meta( $invoice ); |
|
151 | + $this->update_post_meta($invoice); |
|
152 | 152 | $invoice->save_meta_data(); |
153 | 153 | |
154 | 154 | // Apply changes. |
155 | 155 | $invoice->apply_changes(); |
156 | - $this->clear_caches( $invoice ); |
|
156 | + $this->clear_caches($invoice); |
|
157 | 157 | |
158 | 158 | // Fires after a new invoice is created. |
159 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice ); |
|
159 | + do_action('getpaid_new_' . $invoice->get_type(), $invoice); |
|
160 | 160 | return true; |
161 | 161 | } |
162 | 162 | |
163 | - if ( is_wp_error( $id ) ) { |
|
163 | + if (is_wp_error($id)) { |
|
164 | 164 | $invoice->last_error = $id->get_error_message(); |
165 | 165 | } |
166 | 166 | |
@@ -173,14 +173,14 @@ discard block |
||
173 | 173 | * @param WPInv_Invoice $invoice Invoice object. |
174 | 174 | * |
175 | 175 | */ |
176 | - public function read( &$invoice ) { |
|
176 | + public function read(&$invoice) { |
|
177 | 177 | |
178 | 178 | $invoice->set_defaults(); |
179 | - $invoice_object = get_post( $invoice->get_id() ); |
|
179 | + $invoice_object = get_post($invoice->get_id()); |
|
180 | 180 | |
181 | - if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
182 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
183 | - $invoice->set_id( 0 ); |
|
181 | + if (!$invoice->get_id() || !$invoice_object || !getpaid_is_invoice_post_type($invoice_object->post_type)) { |
|
182 | + $invoice->last_error = __('Invalid invoice.', 'invoicing'); |
|
183 | + $invoice->set_id(0); |
|
184 | 184 | return false; |
185 | 185 | } |
186 | 186 | |
@@ -198,14 +198,14 @@ discard block |
||
198 | 198 | ) |
199 | 199 | ); |
200 | 200 | |
201 | - $invoice->set_type( $invoice_object->post_type ); |
|
201 | + $invoice->set_type($invoice_object->post_type); |
|
202 | 202 | |
203 | - $this->read_object_data( $invoice, $invoice_object ); |
|
204 | - $this->add_special_fields( $invoice ); |
|
205 | - $this->add_items( $invoice ); |
|
203 | + $this->read_object_data($invoice, $invoice_object); |
|
204 | + $this->add_special_fields($invoice); |
|
205 | + $this->add_items($invoice); |
|
206 | 206 | $invoice->read_meta_data(); |
207 | - $invoice->set_object_read( true ); |
|
208 | - do_action( 'getpaid_read_' . $invoice->get_type(), $invoice ); |
|
207 | + $invoice->set_object_read(true); |
|
208 | + do_action('getpaid_read_' . $invoice->get_type(), $invoice); |
|
209 | 209 | |
210 | 210 | } |
211 | 211 | |
@@ -214,35 +214,35 @@ discard block |
||
214 | 214 | * |
215 | 215 | * @param WPInv_Invoice $invoice Invoice object. |
216 | 216 | */ |
217 | - public function update( &$invoice ) { |
|
217 | + public function update(&$invoice) { |
|
218 | 218 | $invoice->save_meta_data(); |
219 | - $invoice->set_version( WPINV_VERSION ); |
|
219 | + $invoice->set_version(WPINV_VERSION); |
|
220 | 220 | |
221 | - if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
222 | - $invoice->set_date_created( current_time('mysql') ); |
|
221 | + if (null === $invoice->get_date_created('edit')) { |
|
222 | + $invoice->set_date_created(current_time('mysql')); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | // Ensure both the key and number are set. |
226 | 226 | $invoice->get_path(); |
227 | 227 | |
228 | 228 | // Grab the current status so we can compare. |
229 | - $previous_status = get_post_status( $invoice->get_id() ); |
|
229 | + $previous_status = get_post_status($invoice->get_id()); |
|
230 | 230 | |
231 | 231 | $changes = $invoice->get_changes(); |
232 | 232 | |
233 | 233 | // Only update the post when the post data changes. |
234 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
234 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path'), array_keys($changes))) { |
|
235 | 235 | $post_data = array( |
236 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
237 | - 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
238 | - 'post_status' => $invoice->get_status( 'edit' ), |
|
239 | - 'post_title' => $invoice->get_name( 'edit' ), |
|
240 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
241 | - 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
242 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
243 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
244 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
245 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
236 | + 'post_date' => $invoice->get_date_created('edit'), |
|
237 | + 'post_date_gmt' => $invoice->get_date_created_gmt('edit'), |
|
238 | + 'post_status' => $invoice->get_status('edit'), |
|
239 | + 'post_title' => $invoice->get_name('edit'), |
|
240 | + 'post_author' => $invoice->get_user_id('edit'), |
|
241 | + 'post_modified' => $invoice->get_date_modified('edit'), |
|
242 | + 'post_excerpt' => $invoice->get_description('edit'), |
|
243 | + 'post_parent' => $invoice->get_parent_id('edit'), |
|
244 | + 'post_name' => $invoice->get_path('edit'), |
|
245 | + 'post_type' => $invoice->get_post_type('edit'), |
|
246 | 246 | ); |
247 | 247 | |
248 | 248 | /** |
@@ -253,35 +253,35 @@ discard block |
||
253 | 253 | * This ensures hooks are fired by either WP itself (admin screen save), |
254 | 254 | * or an update purely from CRUD. |
255 | 255 | */ |
256 | - if ( doing_action( 'save_post' ) ) { |
|
257 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
258 | - clean_post_cache( $invoice->get_id() ); |
|
256 | + if (doing_action('save_post')) { |
|
257 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $invoice->get_id())); |
|
258 | + clean_post_cache($invoice->get_id()); |
|
259 | 259 | } else { |
260 | - wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
260 | + wp_update_post(array_merge(array('ID' => $invoice->get_id()), $post_data)); |
|
261 | 261 | } |
262 | - $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
262 | + $invoice->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | // Update meta data. |
266 | - $this->update_post_meta( $invoice ); |
|
266 | + $this->update_post_meta($invoice); |
|
267 | 267 | |
268 | 268 | // Save special fields and items. |
269 | - $this->save_special_fields( $invoice ); |
|
270 | - $this->save_items( $invoice ); |
|
269 | + $this->save_special_fields($invoice); |
|
270 | + $this->save_items($invoice); |
|
271 | 271 | |
272 | 272 | // Apply the changes. |
273 | 273 | $invoice->apply_changes(); |
274 | 274 | |
275 | 275 | // Clear caches. |
276 | - $this->clear_caches( $invoice ); |
|
276 | + $this->clear_caches($invoice); |
|
277 | 277 | |
278 | 278 | // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
279 | - $new_status = $invoice->get_status( 'edit' ); |
|
279 | + $new_status = $invoice->get_status('edit'); |
|
280 | 280 | |
281 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
282 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice ); |
|
281 | + if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) { |
|
282 | + do_action('getpaid_new_' . $invoice->get_type(), $invoice); |
|
283 | 283 | } else { |
284 | - do_action( 'getpaid_update_' . $invoice->get_type(), $invoice ); |
|
284 | + do_action('getpaid_update_' . $invoice->get_type(), $invoice); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | } |
@@ -297,45 +297,45 @@ discard block |
||
297 | 297 | * |
298 | 298 | * @param WPInv_Invoice $invoice Invoice object. |
299 | 299 | */ |
300 | - public function add_special_fields( &$invoice ) { |
|
300 | + public function add_special_fields(&$invoice) { |
|
301 | 301 | global $wpdb; |
302 | 302 | |
303 | 303 | // Maybe retrieve from the cache. |
304 | - $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
304 | + $data = wp_cache_get($invoice->get_id(), 'getpaid_invoice_special_fields'); |
|
305 | 305 | |
306 | 306 | // If not found, retrieve from the db. |
307 | - if ( false === $data ) { |
|
308 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
307 | + if (false === $data) { |
|
308 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
309 | 309 | |
310 | 310 | $data = $wpdb->get_row( |
311 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
311 | + $wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id()), |
|
312 | 312 | ARRAY_A |
313 | 313 | ); |
314 | 314 | |
315 | 315 | // Update the cache with our data |
316 | - wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
316 | + wp_cache_set($invoice->get_id(), $data, 'getpaid_invoice_special_fields'); |
|
317 | 317 | |
318 | 318 | } |
319 | 319 | |
320 | 320 | // Abort if the data does not exist. |
321 | - if ( empty( $data ) ) { |
|
322 | - $invoice->set_object_read( true ); |
|
323 | - $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
321 | + if (empty($data)) { |
|
322 | + $invoice->set_object_read(true); |
|
323 | + $invoice->set_props(wpinv_get_user_address($invoice->get_user_id())); |
|
324 | 324 | return; |
325 | 325 | } |
326 | 326 | |
327 | 327 | $props = array(); |
328 | 328 | |
329 | - foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
329 | + foreach ($this->database_fields_to_props as $db_field => $prop) { |
|
330 | 330 | |
331 | - if ( $db_field == 'post_id' ) { |
|
331 | + if ($db_field == 'post_id') { |
|
332 | 332 | continue; |
333 | 333 | } |
334 | 334 | |
335 | - $props[ $prop ] = $data[ $db_field ]; |
|
335 | + $props[$prop] = $data[$db_field]; |
|
336 | 336 | } |
337 | 337 | |
338 | - $invoice->set_props( $props ); |
|
338 | + $invoice->set_props($props); |
|
339 | 339 | |
340 | 340 | } |
341 | 341 | |
@@ -346,14 +346,14 @@ discard block |
||
346 | 346 | * @param WPInv_Invoice $invoice The Invoice object. |
347 | 347 | * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
348 | 348 | */ |
349 | - protected function get_special_fields_to_update( $invoice ) { |
|
349 | + protected function get_special_fields_to_update($invoice) { |
|
350 | 350 | $fields_to_update = array(); |
351 | - $changed_props = $invoice->get_changes(); |
|
351 | + $changed_props = $invoice->get_changes(); |
|
352 | 352 | |
353 | 353 | // Props should be updated if they are a part of the $changed array or don't exist yet. |
354 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
355 | - if ( array_key_exists( $prop, $changed_props ) ) { |
|
356 | - $fields_to_update[ $database_field ] = $prop; |
|
354 | + foreach ($this->database_fields_to_props as $database_field => $prop) { |
|
355 | + if (array_key_exists($prop, $changed_props)) { |
|
356 | + $fields_to_update[$database_field] = $prop; |
|
357 | 357 | } |
358 | 358 | } |
359 | 359 | |
@@ -366,25 +366,25 @@ discard block |
||
366 | 366 | * @param WPInv_Invoice $invoice WPInv_Invoice object. |
367 | 367 | * @since 1.0.19 |
368 | 368 | */ |
369 | - protected function update_special_fields( &$invoice ) { |
|
369 | + protected function update_special_fields(&$invoice) { |
|
370 | 370 | global $wpdb; |
371 | 371 | |
372 | 372 | $updated_props = array(); |
373 | - $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
373 | + $fields_to_update = $this->get_special_fields_to_update($invoice); |
|
374 | 374 | |
375 | - foreach ( $fields_to_update as $database_field => $prop ) { |
|
376 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
377 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
378 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
379 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
375 | + foreach ($fields_to_update as $database_field => $prop) { |
|
376 | + $value = $invoice->{"get_$prop"}('edit'); |
|
377 | + $value = is_string($value) ? wp_slash($value) : $value; |
|
378 | + $value = is_bool($value) ? (int) $value : $value; |
|
379 | + $updated_props[$database_field] = maybe_serialize($value); |
|
380 | 380 | } |
381 | 381 | |
382 | - if ( ! empty( $updated_props ) ) { |
|
382 | + if (!empty($updated_props)) { |
|
383 | 383 | |
384 | 384 | $table = $wpdb->prefix . 'getpaid_invoices'; |
385 | - $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
386 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
387 | - do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
385 | + $wpdb->update($table, $updated_props, array('post_id' => $invoice->get_id())); |
|
386 | + wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields'); |
|
387 | + do_action("getpaid_invoice_update_database_fields", $invoice, $updated_props); |
|
388 | 388 | |
389 | 389 | } |
390 | 390 | |
@@ -396,22 +396,22 @@ discard block |
||
396 | 396 | * @param WPInv_Invoice $invoice WPInv_Invoice object. |
397 | 397 | * @since 1.0.19 |
398 | 398 | */ |
399 | - protected function insert_special_fields( &$invoice ) { |
|
399 | + protected function insert_special_fields(&$invoice) { |
|
400 | 400 | global $wpdb; |
401 | 401 | |
402 | - $updated_props = array(); |
|
402 | + $updated_props = array(); |
|
403 | 403 | |
404 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
405 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
406 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
407 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
408 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
404 | + foreach ($this->database_fields_to_props as $database_field => $prop) { |
|
405 | + $value = $invoice->{"get_$prop"}('edit'); |
|
406 | + $value = is_string($value) ? wp_slash($value) : $value; |
|
407 | + $value = is_bool($value) ? (int) $value : $value; |
|
408 | + $updated_props[$database_field] = maybe_serialize($value); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | $table = $wpdb->prefix . 'getpaid_invoices'; |
412 | - $wpdb->insert( $table, $updated_props ); |
|
413 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
414 | - do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
412 | + $wpdb->insert($table, $updated_props); |
|
413 | + wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields'); |
|
414 | + do_action("getpaid_invoice_insert_database_fields", $invoice, $updated_props); |
|
415 | 415 | |
416 | 416 | } |
417 | 417 | |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | * |
421 | 421 | * @param WPInv_Invoice $invoice Invoice object. |
422 | 422 | */ |
423 | - public function save_special_fields( & $invoice ) { |
|
423 | + public function save_special_fields(& $invoice) { |
|
424 | 424 | global $wpdb; |
425 | 425 | |
426 | 426 | // The invoices table. |
@@ -428,13 +428,13 @@ discard block |
||
428 | 428 | $id = (int) $invoice->get_id(); |
429 | 429 | $invoice->maybe_set_key(); |
430 | 430 | |
431 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
431 | + if ($wpdb->get_var("SELECT `post_id` FROM $table WHERE `post_id`= $id")) { |
|
432 | 432 | |
433 | - $this->update_special_fields( $invoice ); |
|
433 | + $this->update_special_fields($invoice); |
|
434 | 434 | |
435 | 435 | } else { |
436 | 436 | |
437 | - $this->insert_special_fields( $invoice ); |
|
437 | + $this->insert_special_fields($invoice); |
|
438 | 438 | |
439 | 439 | } |
440 | 440 | |
@@ -445,43 +445,43 @@ discard block |
||
445 | 445 | * |
446 | 446 | * @param WPInv_Invoice $invoice Invoice object. |
447 | 447 | */ |
448 | - public function add_items( &$invoice ) { |
|
448 | + public function add_items(&$invoice) { |
|
449 | 449 | global $wpdb; |
450 | 450 | |
451 | 451 | // Maybe retrieve from the cache. |
452 | - $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
452 | + $items = wp_cache_get($invoice->get_id(), 'getpaid_invoice_cart_details'); |
|
453 | 453 | |
454 | 454 | // If not found, retrieve from the db. |
455 | - if ( false === $items ) { |
|
456 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
455 | + if (false === $items) { |
|
456 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
457 | 457 | |
458 | 458 | $items = $wpdb->get_results( |
459 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
459 | + $wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id()) |
|
460 | 460 | ); |
461 | 461 | |
462 | 462 | // Update the cache with our data |
463 | - wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
463 | + wp_cache_set($invoice->get_id(), $items, 'getpaid_invoice_cart_details'); |
|
464 | 464 | |
465 | 465 | } |
466 | 466 | |
467 | 467 | // Abort if no items found. |
468 | - if ( empty( $items ) ) { |
|
468 | + if (empty($items)) { |
|
469 | 469 | return; |
470 | 470 | } |
471 | 471 | |
472 | - foreach ( $items as $item_data ) { |
|
473 | - $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
472 | + foreach ($items as $item_data) { |
|
473 | + $item = new GetPaid_Form_Item($item_data->item_id); |
|
474 | 474 | |
475 | 475 | // Set item data. |
476 | - $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
477 | - $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
478 | - $item->set_name( $item_data->item_name ); |
|
479 | - $item->set_description( $item_data->item_description ); |
|
480 | - $item->set_price( $item_data->item_price ); |
|
481 | - $item->set_quantity( $item_data->quantity ); |
|
482 | - $item->set_item_meta( $item_data->meta ); |
|
483 | - |
|
484 | - $invoice->add_item( $item ); |
|
476 | + $item->item_tax = wpinv_sanitize_amount($item_data->tax); |
|
477 | + $item->item_discount = wpinv_sanitize_amount($item_data->discount); |
|
478 | + $item->set_name($item_data->item_name); |
|
479 | + $item->set_description($item_data->item_description); |
|
480 | + $item->set_price($item_data->item_price); |
|
481 | + $item->set_quantity($item_data->quantity); |
|
482 | + $item->set_item_meta($item_data->meta); |
|
483 | + |
|
484 | + $invoice->add_item($item); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | } |
@@ -491,20 +491,20 @@ discard block |
||
491 | 491 | * |
492 | 492 | * @param WPInv_Invoice $invoice Invoice object. |
493 | 493 | */ |
494 | - public function save_items( $invoice ) { |
|
494 | + public function save_items($invoice) { |
|
495 | 495 | |
496 | 496 | // Delete previously existing items. |
497 | - $this->delete_items( $invoice ); |
|
497 | + $this->delete_items($invoice); |
|
498 | 498 | |
499 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
499 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
500 | 500 | |
501 | - foreach ( $invoice->get_cart_details() as $item_data ) { |
|
502 | - $item_data = array_map( 'maybe_serialize', $item_data ); |
|
503 | - $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
501 | + foreach ($invoice->get_cart_details() as $item_data) { |
|
502 | + $item_data = array_map('maybe_serialize', $item_data); |
|
503 | + $GLOBALS['wpdb']->insert($table, $item_data); |
|
504 | 504 | } |
505 | 505 | |
506 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
507 | - do_action( "getpaid_invoice_save_items", $invoice ); |
|
506 | + wp_cache_delete($invoice->get_id(), 'getpaid_invoice_cart_details'); |
|
507 | + do_action("getpaid_invoice_save_items", $invoice); |
|
508 | 508 | |
509 | 509 | } |
510 | 510 | |
@@ -513,9 +513,9 @@ discard block |
||
513 | 513 | * |
514 | 514 | * @param WPInv_Invoice $invoice Invoice object. |
515 | 515 | */ |
516 | - public function delete_items( $invoice ) { |
|
517 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
518 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
516 | + public function delete_items($invoice) { |
|
517 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
518 | + return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id())); |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | /** |
@@ -523,9 +523,9 @@ discard block |
||
523 | 523 | * |
524 | 524 | * @param WPInv_Invoice $invoice Invoice object. |
525 | 525 | */ |
526 | - public function delete_special_fields( $invoice ) { |
|
527 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
528 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
526 | + public function delete_special_fields($invoice) { |
|
527 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
528 | + return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id())); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | } |
@@ -40,86 +40,86 @@ discard block |
||
40 | 40 | <tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>"> |
41 | 41 | <?php |
42 | 42 | |
43 | - foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : |
|
43 | + foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : |
|
44 | 44 | |
45 | - $column_id = sanitize_html_class( $column_id ); |
|
46 | - $class = empty( $column_name['class'] ) ? '' : sanitize_html_class( $column_name['class'] ); |
|
45 | + $column_id = sanitize_html_class( $column_id ); |
|
46 | + $class = empty( $column_name['class'] ) ? '' : sanitize_html_class( $column_name['class'] ); |
|
47 | 47 | |
48 | - echo "<td class='$column_id $class'>"; |
|
49 | - switch ( $column_id ) { |
|
48 | + echo "<td class='$column_id $class'>"; |
|
49 | + switch ( $column_id ) { |
|
50 | 50 | |
51 | - case 'invoice-number': |
|
52 | - echo wpinv_invoice_link( $invoice ); |
|
53 | - break; |
|
51 | + case 'invoice-number': |
|
52 | + echo wpinv_invoice_link( $invoice ); |
|
53 | + break; |
|
54 | 54 | |
55 | - case 'created-date': |
|
56 | - echo date_i18n( get_option( 'date_format' ), strtotime( $invoice->get_date_created() ) ); |
|
57 | - break; |
|
55 | + case 'created-date': |
|
56 | + echo date_i18n( get_option( 'date_format' ), strtotime( $invoice->get_date_created() ) ); |
|
57 | + break; |
|
58 | 58 | |
59 | - case 'payment-date': |
|
59 | + case 'payment-date': |
|
60 | 60 | |
61 | - if ( $invoice->needs_payment() ) { |
|
62 | - echo "—"; |
|
63 | - } else { |
|
64 | - echo date_i18n( get_option( 'date_format' ), strtotime( $invoice->get_date_completed() ) ); |
|
65 | - } |
|
61 | + if ( $invoice->needs_payment() ) { |
|
62 | + echo "—"; |
|
63 | + } else { |
|
64 | + echo date_i18n( get_option( 'date_format' ), strtotime( $invoice->get_date_completed() ) ); |
|
65 | + } |
|
66 | 66 | |
67 | - break; |
|
67 | + break; |
|
68 | 68 | |
69 | - case 'invoice-status': |
|
70 | - echo $invoice->get_status_label_html(); |
|
69 | + case 'invoice-status': |
|
70 | + echo $invoice->get_status_label_html(); |
|
71 | 71 | |
72 | - break; |
|
72 | + break; |
|
73 | 73 | |
74 | - case 'invoice-total': |
|
75 | - echo wpinv_price( wpinv_format_amount( $invoice->get_total() ) ); |
|
74 | + case 'invoice-total': |
|
75 | + echo wpinv_price( wpinv_format_amount( $invoice->get_total() ) ); |
|
76 | 76 | |
77 | - break; |
|
77 | + break; |
|
78 | 78 | |
79 | - case 'invoice-actions': |
|
79 | + case 'invoice-actions': |
|
80 | 80 | |
81 | - $actions = array( |
|
81 | + $actions = array( |
|
82 | 82 | |
83 | - 'pay' => array( |
|
84 | - 'url' => $invoice->get_checkout_payment_url(), |
|
85 | - 'name' => __( 'Pay Now', 'invoicing' ), |
|
83 | + 'pay' => array( |
|
84 | + 'url' => $invoice->get_checkout_payment_url(), |
|
85 | + 'name' => __( 'Pay Now', 'invoicing' ), |
|
86 | 86 | 'class' => 'btn-success' |
87 | - ), |
|
87 | + ), |
|
88 | 88 | |
89 | 89 | 'print' => array( |
90 | - 'url' => $invoice->get_view_url(), |
|
91 | - 'name' => __( 'View Invoice', 'invoicing' ), |
|
90 | + 'url' => $invoice->get_view_url(), |
|
91 | + 'name' => __( 'View Invoice', 'invoicing' ), |
|
92 | 92 | 'class' => 'btn-secondary', |
93 | 93 | 'attrs' => 'target="_blank"' |
94 | - ) |
|
95 | - ); |
|
94 | + ) |
|
95 | + ); |
|
96 | 96 | |
97 | - if ( ! $invoice->needs_payment() ) { |
|
98 | - unset( $actions['pay'] ); |
|
99 | - } |
|
97 | + if ( ! $invoice->needs_payment() ) { |
|
98 | + unset( $actions['pay'] ); |
|
99 | + } |
|
100 | 100 | |
101 | - $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ); |
|
101 | + $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ); |
|
102 | 102 | |
103 | - foreach ( $actions as $key => $action ) { |
|
104 | - $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; |
|
105 | - echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm btn-block ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>'; |
|
106 | - } |
|
103 | + foreach ( $actions as $key => $action ) { |
|
104 | + $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; |
|
105 | + echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm btn-block ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>'; |
|
106 | + } |
|
107 | 107 | |
108 | - break; |
|
108 | + break; |
|
109 | 109 | |
110 | - default: |
|
111 | - do_action( "wpinv_user_invoices_column_$column_id", $invoice ); |
|
112 | - break; |
|
110 | + default: |
|
111 | + do_action( "wpinv_user_invoices_column_$column_id", $invoice ); |
|
112 | + break; |
|
113 | 113 | |
114 | 114 | |
115 | - } |
|
115 | + } |
|
116 | 116 | |
117 | - do_action( "wpinv_user_invoices_column_after_$column_id", $invoice ); |
|
117 | + do_action( "wpinv_user_invoices_column_after_$column_id", $invoice ); |
|
118 | 118 | |
119 | - echo '</td>'; |
|
119 | + echo '</td>'; |
|
120 | 120 | |
121 | - endforeach; |
|
122 | - ?> |
|
121 | + endforeach; |
|
122 | + ?> |
|
123 | 123 | </tr> |
124 | 124 | |
125 | 125 | <?php endforeach; ?> |
@@ -132,14 +132,14 @@ discard block |
||
132 | 132 | <?php if ( 1 < $invoices->max_num_pages ) : ?> |
133 | 133 | <div class="invoicing-Pagination"> |
134 | 134 | <?php |
135 | - $big = 999999; |
|
136 | - |
|
137 | - echo paginate_links( array( |
|
138 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
139 | - 'format' => '?paged=%#%', |
|
140 | - 'total' => $invoices->max_num_pages, |
|
141 | - ) ); |
|
142 | - ?> |
|
135 | + $big = 999999; |
|
136 | + |
|
137 | + echo paginate_links( array( |
|
138 | + 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
139 | + 'format' => '?paged=%#%', |
|
140 | + 'total' => $invoices->max_num_pages, |
|
141 | + ) ); |
|
142 | + ?> |
|
143 | 143 | </div> |
144 | 144 | <?php endif; ?> |
145 | 145 |
@@ -7,13 +7,13 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | // Current page. |
13 | -$current_page = empty( $_GET[ 'page' ] ) ? 1 : absint( $_GET[ 'page' ] ); |
|
13 | +$current_page = empty($_GET['page']) ? 1 : absint($_GET['page']); |
|
14 | 14 | |
15 | 15 | // Fires before displaying user invoices. |
16 | -do_action( 'wpinv_before_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages ); |
|
16 | +do_action('wpinv_before_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages); |
|
17 | 17 | |
18 | 18 | ?> |
19 | 19 | |
@@ -23,9 +23,9 @@ discard block |
||
23 | 23 | <thead> |
24 | 24 | <tr> |
25 | 25 | |
26 | - <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?> |
|
27 | - <th class="<?php echo sanitize_html_class( $column_id ); ?> <?php echo ( ! empty( $column_name['class'] ) ? sanitize_html_class( $column_name['class'] ) : '');?> border-bottom-0"> |
|
28 | - <span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span> |
|
26 | + <?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?> |
|
27 | + <th class="<?php echo sanitize_html_class($column_id); ?> <?php echo (!empty($column_name['class']) ? sanitize_html_class($column_name['class']) : ''); ?> border-bottom-0"> |
|
28 | + <span class="nobr"><?php echo esc_html($column_name['title']); ?></span> |
|
29 | 29 | </th> |
30 | 30 | <?php endforeach; ?> |
31 | 31 | |
@@ -35,33 +35,33 @@ discard block |
||
35 | 35 | |
36 | 36 | |
37 | 37 | <tbody> |
38 | - <?php foreach ( $invoices->invoices as $invoice ) : ?> |
|
38 | + <?php foreach ($invoices->invoices as $invoice) : ?> |
|
39 | 39 | |
40 | 40 | <tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>"> |
41 | 41 | <?php |
42 | 42 | |
43 | - foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : |
|
43 | + foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : |
|
44 | 44 | |
45 | - $column_id = sanitize_html_class( $column_id ); |
|
46 | - $class = empty( $column_name['class'] ) ? '' : sanitize_html_class( $column_name['class'] ); |
|
45 | + $column_id = sanitize_html_class($column_id); |
|
46 | + $class = empty($column_name['class']) ? '' : sanitize_html_class($column_name['class']); |
|
47 | 47 | |
48 | 48 | echo "<td class='$column_id $class'>"; |
49 | - switch ( $column_id ) { |
|
49 | + switch ($column_id) { |
|
50 | 50 | |
51 | 51 | case 'invoice-number': |
52 | - echo wpinv_invoice_link( $invoice ); |
|
52 | + echo wpinv_invoice_link($invoice); |
|
53 | 53 | break; |
54 | 54 | |
55 | 55 | case 'created-date': |
56 | - echo date_i18n( get_option( 'date_format' ), strtotime( $invoice->get_date_created() ) ); |
|
56 | + echo date_i18n(get_option('date_format'), strtotime($invoice->get_date_created())); |
|
57 | 57 | break; |
58 | 58 | |
59 | 59 | case 'payment-date': |
60 | 60 | |
61 | - if ( $invoice->needs_payment() ) { |
|
61 | + if ($invoice->needs_payment()) { |
|
62 | 62 | echo "—"; |
63 | 63 | } else { |
64 | - echo date_i18n( get_option( 'date_format' ), strtotime( $invoice->get_date_completed() ) ); |
|
64 | + echo date_i18n(get_option('date_format'), strtotime($invoice->get_date_completed())); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | break; |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | break; |
73 | 73 | |
74 | 74 | case 'invoice-total': |
75 | - echo wpinv_price( wpinv_format_amount( $invoice->get_total() ) ); |
|
75 | + echo wpinv_price(wpinv_format_amount($invoice->get_total())); |
|
76 | 76 | |
77 | 77 | break; |
78 | 78 | |
@@ -82,39 +82,39 @@ discard block |
||
82 | 82 | |
83 | 83 | 'pay' => array( |
84 | 84 | 'url' => $invoice->get_checkout_payment_url(), |
85 | - 'name' => __( 'Pay Now', 'invoicing' ), |
|
85 | + 'name' => __('Pay Now', 'invoicing'), |
|
86 | 86 | 'class' => 'btn-success' |
87 | 87 | ), |
88 | 88 | |
89 | 89 | 'print' => array( |
90 | 90 | 'url' => $invoice->get_view_url(), |
91 | - 'name' => __( 'View Invoice', 'invoicing' ), |
|
91 | + 'name' => __('View Invoice', 'invoicing'), |
|
92 | 92 | 'class' => 'btn-secondary', |
93 | 93 | 'attrs' => 'target="_blank"' |
94 | 94 | ) |
95 | 95 | ); |
96 | 96 | |
97 | - if ( ! $invoice->needs_payment() ) { |
|
98 | - unset( $actions['pay'] ); |
|
97 | + if (!$invoice->needs_payment()) { |
|
98 | + unset($actions['pay']); |
|
99 | 99 | } |
100 | 100 | |
101 | - $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ); |
|
101 | + $actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice); |
|
102 | 102 | |
103 | - foreach ( $actions as $key => $action ) { |
|
103 | + foreach ($actions as $key => $action) { |
|
104 | 104 | $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; |
105 | - echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm btn-block ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>'; |
|
105 | + echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm btn-block ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>'; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | break; |
109 | 109 | |
110 | 110 | default: |
111 | - do_action( "wpinv_user_invoices_column_$column_id", $invoice ); |
|
111 | + do_action("wpinv_user_invoices_column_$column_id", $invoice); |
|
112 | 112 | break; |
113 | 113 | |
114 | 114 | |
115 | 115 | } |
116 | 116 | |
117 | - do_action( "wpinv_user_invoices_column_after_$column_id", $invoice ); |
|
117 | + do_action("wpinv_user_invoices_column_after_$column_id", $invoice); |
|
118 | 118 | |
119 | 119 | echo '</td>'; |
120 | 120 | |
@@ -127,20 +127,20 @@ discard block |
||
127 | 127 | </tbody> |
128 | 128 | </table> |
129 | 129 | |
130 | - <?php do_action( 'wpinv_before_user_invoices_pagination' ); ?> |
|
130 | + <?php do_action('wpinv_before_user_invoices_pagination'); ?> |
|
131 | 131 | |
132 | - <?php if ( 1 < $invoices->max_num_pages ) : ?> |
|
132 | + <?php if (1 < $invoices->max_num_pages) : ?> |
|
133 | 133 | <div class="invoicing-Pagination"> |
134 | 134 | <?php |
135 | 135 | $big = 999999; |
136 | 136 | |
137 | - echo paginate_links( array( |
|
138 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
137 | + echo paginate_links(array( |
|
138 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
139 | 139 | 'format' => '?paged=%#%', |
140 | 140 | 'total' => $invoices->max_num_pages, |
141 | - ) ); |
|
141 | + )); |
|
142 | 142 | ?> |
143 | 143 | </div> |
144 | 144 | <?php endif; ?> |
145 | 145 | |
146 | -<?php do_action( 'wpinv_after_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages ); ?> |
|
146 | +<?php do_action('wpinv_after_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages); ?> |