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