@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
179 | 179 | |
180 | 180 | // Register autoloader. |
181 | - try { |
|
182 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
183 | - } catch ( Exception $e ) { |
|
184 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
181 | + try { |
|
182 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
183 | + } catch ( Exception $e ) { |
|
184 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | require_once( WPINV_PLUGIN_DIR . 'includes/class-getpaid-post-types.php' ); |
@@ -206,11 +206,11 @@ discard block |
||
206 | 206 | require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
207 | 207 | require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
208 | 208 | require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
209 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
210 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
211 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
212 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
213 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
209 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
210 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
211 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
212 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
213 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
214 | 214 | require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
215 | 215 | require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
216 | 216 | require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
@@ -272,48 +272,48 @@ discard block |
||
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
275 | - * Class autoloader |
|
276 | - * |
|
277 | - * @param string $class_name The name of the class to load. |
|
278 | - * @access public |
|
279 | - * @since 1.0.19 |
|
280 | - * @return void |
|
281 | - */ |
|
282 | - public function autoload( $class_name ) { |
|
283 | - |
|
284 | - // Normalize the class name... |
|
285 | - $class_name = strtolower( $class_name ); |
|
286 | - |
|
287 | - // ... and make sure it is our class. |
|
288 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
289 | - return; |
|
290 | - } |
|
291 | - |
|
292 | - // Next, prepare the file name from the class. |
|
293 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
294 | - |
|
295 | - // And an array of possible locations in order of importance. |
|
296 | - $locations = array( |
|
297 | - 'includes', |
|
275 | + * Class autoloader |
|
276 | + * |
|
277 | + * @param string $class_name The name of the class to load. |
|
278 | + * @access public |
|
279 | + * @since 1.0.19 |
|
280 | + * @return void |
|
281 | + */ |
|
282 | + public function autoload( $class_name ) { |
|
283 | + |
|
284 | + // Normalize the class name... |
|
285 | + $class_name = strtolower( $class_name ); |
|
286 | + |
|
287 | + // ... and make sure it is our class. |
|
288 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
289 | + return; |
|
290 | + } |
|
291 | + |
|
292 | + // Next, prepare the file name from the class. |
|
293 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
294 | + |
|
295 | + // And an array of possible locations in order of importance. |
|
296 | + $locations = array( |
|
297 | + 'includes', |
|
298 | 298 | 'includes/data-stores', |
299 | 299 | 'includes/gateways', |
300 | 300 | 'includes/admin', |
301 | 301 | 'includes/admin/meta-boxes' |
302 | - ); |
|
302 | + ); |
|
303 | 303 | |
304 | - // Base path of the classes. |
|
305 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
304 | + // Base path of the classes. |
|
305 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
306 | 306 | |
307 | - foreach ( $locations as $location ) { |
|
307 | + foreach ( $locations as $location ) { |
|
308 | 308 | |
309 | - if ( file_exists( "$plugin_path/$location/$file_name" ) ) { |
|
310 | - include "$plugin_path/$location/$file_name"; |
|
311 | - break; |
|
312 | - } |
|
309 | + if ( file_exists( "$plugin_path/$location/$file_name" ) ) { |
|
310 | + include "$plugin_path/$location/$file_name"; |
|
311 | + break; |
|
312 | + } |
|
313 | 313 | |
314 | - } |
|
314 | + } |
|
315 | 315 | |
316 | - } |
|
316 | + } |
|
317 | 317 | |
318 | 318 | /** |
319 | 319 | * Inits hooks etc. |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
424 | 424 | wp_enqueue_style( 'jquery-ui-css' ); |
425 | 425 | wp_deregister_style( 'yoast-seo-select2' ); |
426 | - wp_deregister_style( 'yoast-seo-monorepo' ); |
|
426 | + wp_deregister_style( 'yoast-seo-monorepo' ); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | if ( $page == 'wpinv-subscriptions' ) { |
438 | 438 | wp_enqueue_script( 'jquery-ui-datepicker' ); |
439 | 439 | wp_deregister_style( 'yoast-seo-select2' ); |
440 | - wp_deregister_style( 'yoast-seo-monorepo' ); |
|
440 | + wp_deregister_style( 'yoast-seo-monorepo' ); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
@@ -606,19 +606,19 @@ discard block |
||
606 | 606 | require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
607 | 607 | } |
608 | 608 | |
609 | - /** |
|
610 | - * Register widgets |
|
611 | - * |
|
612 | - */ |
|
613 | - public function register_widgets() { |
|
614 | - register_widget( "WPInv_Checkout_Widget" ); |
|
615 | - register_widget( "WPInv_History_Widget" ); |
|
616 | - register_widget( "WPInv_Receipt_Widget" ); |
|
617 | - register_widget( "WPInv_Subscriptions_Widget" ); |
|
618 | - register_widget( "WPInv_Buy_Item_Widget" ); |
|
609 | + /** |
|
610 | + * Register widgets |
|
611 | + * |
|
612 | + */ |
|
613 | + public function register_widgets() { |
|
614 | + register_widget( "WPInv_Checkout_Widget" ); |
|
615 | + register_widget( "WPInv_History_Widget" ); |
|
616 | + register_widget( "WPInv_Receipt_Widget" ); |
|
617 | + register_widget( "WPInv_Subscriptions_Widget" ); |
|
618 | + register_widget( "WPInv_Buy_Item_Widget" ); |
|
619 | 619 | register_widget( "WPInv_Messages_Widget" ); |
620 | 620 | register_widget( 'WPInv_GetPaid_Widget' ); |
621 | - } |
|
621 | + } |
|
622 | 622 | |
623 | 623 | /** |
624 | 624 | * Remove our pages from yoast sitemaps. |
@@ -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,507 +15,507 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP { |
17 | 17 | |
18 | - /** |
|
19 | - * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | - * |
|
21 | - * @since 1.0.19 |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $internal_meta_keys = array( |
|
25 | - '_wpinv_subscr_profile_id', |
|
26 | - '_wpinv_taxes', |
|
27 | - '_wpinv_fees', |
|
28 | - '_wpinv_discounts', |
|
29 | - '_wpinv_submission_id', |
|
30 | - '_wpinv_payment_form', |
|
31 | - '_wpinv_is_viewed', |
|
32 | - 'wpinv_email_cc', |
|
33 | - 'wpinv_template' |
|
34 | - ); |
|
35 | - |
|
36 | - /** |
|
37 | - * A map of meta keys to data props. |
|
38 | - * |
|
39 | - * @since 1.0.19 |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - protected $meta_key_to_props = array( |
|
44 | - '_wpinv_subscr_profile_id' => 'subscription_id', |
|
45 | - '_wpinv_taxes' => 'taxes', |
|
46 | - '_wpinv_fees' => 'fees', |
|
47 | - '_wpinv_discounts' => 'discounts', |
|
48 | - '_wpinv_submission_id' => 'submission_id', |
|
49 | - '_wpinv_payment_form' => 'payment_form', |
|
50 | - '_wpinv_is_viewed' => 'is_viewed', |
|
51 | - 'wpinv_email_cc' => 'email_cc', |
|
52 | - 'wpinv_template' => 'template', |
|
53 | - ); |
|
54 | - |
|
55 | - /** |
|
56 | - * A map of database fields to data props. |
|
57 | - * |
|
58 | - * @since 1.0.19 |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - protected $database_fields_to_props = array( |
|
63 | - 'post_id' => 'id', |
|
64 | - 'number' => 'number', |
|
65 | - 'currency' => 'currency', |
|
66 | - 'key' => 'key', |
|
67 | - 'type' => 'type', |
|
68 | - 'mode' => 'mode', |
|
69 | - 'user_ip' => 'user_ip', |
|
70 | - 'first_name' => 'first_name', |
|
71 | - 'last_name' => 'last_name', |
|
72 | - 'address' => 'address', |
|
73 | - 'city' => 'city', |
|
74 | - 'state' => 'state', |
|
75 | - 'country' => 'country', |
|
76 | - 'zip' => 'zip', |
|
77 | - 'zip' => 'zip', |
|
78 | - 'adddress_confirmed' => 'address_confirmed', |
|
79 | - 'gateway' => 'gateway', |
|
80 | - 'transaction_id' => 'transaction_id', |
|
81 | - 'currency' => 'currency', |
|
82 | - 'subtotal' => 'subtotal', |
|
83 | - 'tax' => 'total_tax', |
|
84 | - 'fees_total' => 'total_fees', |
|
85 | - 'discount' => 'total_discount', |
|
86 | - 'total' => 'total', |
|
87 | - 'discount_code' => 'discount_code', |
|
88 | - 'disable_taxes' => 'disable_taxes', |
|
89 | - 'due_date' => 'due_date', |
|
90 | - 'completed_date' => 'completed_date', |
|
91 | - 'company' => 'company', |
|
92 | - 'vat_number' => 'vat_number', |
|
93 | - 'vat_rate' => 'vat_rate', |
|
94 | - ); |
|
95 | - |
|
96 | - /* |
|
18 | + /** |
|
19 | + * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | + * |
|
21 | + * @since 1.0.19 |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $internal_meta_keys = array( |
|
25 | + '_wpinv_subscr_profile_id', |
|
26 | + '_wpinv_taxes', |
|
27 | + '_wpinv_fees', |
|
28 | + '_wpinv_discounts', |
|
29 | + '_wpinv_submission_id', |
|
30 | + '_wpinv_payment_form', |
|
31 | + '_wpinv_is_viewed', |
|
32 | + 'wpinv_email_cc', |
|
33 | + 'wpinv_template' |
|
34 | + ); |
|
35 | + |
|
36 | + /** |
|
37 | + * A map of meta keys to data props. |
|
38 | + * |
|
39 | + * @since 1.0.19 |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + protected $meta_key_to_props = array( |
|
44 | + '_wpinv_subscr_profile_id' => 'subscription_id', |
|
45 | + '_wpinv_taxes' => 'taxes', |
|
46 | + '_wpinv_fees' => 'fees', |
|
47 | + '_wpinv_discounts' => 'discounts', |
|
48 | + '_wpinv_submission_id' => 'submission_id', |
|
49 | + '_wpinv_payment_form' => 'payment_form', |
|
50 | + '_wpinv_is_viewed' => 'is_viewed', |
|
51 | + 'wpinv_email_cc' => 'email_cc', |
|
52 | + 'wpinv_template' => 'template', |
|
53 | + ); |
|
54 | + |
|
55 | + /** |
|
56 | + * A map of database fields to data props. |
|
57 | + * |
|
58 | + * @since 1.0.19 |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + protected $database_fields_to_props = array( |
|
63 | + 'post_id' => 'id', |
|
64 | + 'number' => 'number', |
|
65 | + 'currency' => 'currency', |
|
66 | + 'key' => 'key', |
|
67 | + 'type' => 'type', |
|
68 | + 'mode' => 'mode', |
|
69 | + 'user_ip' => 'user_ip', |
|
70 | + 'first_name' => 'first_name', |
|
71 | + 'last_name' => 'last_name', |
|
72 | + 'address' => 'address', |
|
73 | + 'city' => 'city', |
|
74 | + 'state' => 'state', |
|
75 | + 'country' => 'country', |
|
76 | + 'zip' => 'zip', |
|
77 | + 'zip' => 'zip', |
|
78 | + 'adddress_confirmed' => 'address_confirmed', |
|
79 | + 'gateway' => 'gateway', |
|
80 | + 'transaction_id' => 'transaction_id', |
|
81 | + 'currency' => 'currency', |
|
82 | + 'subtotal' => 'subtotal', |
|
83 | + 'tax' => 'total_tax', |
|
84 | + 'fees_total' => 'total_fees', |
|
85 | + 'discount' => 'total_discount', |
|
86 | + 'total' => 'total', |
|
87 | + 'discount_code' => 'discount_code', |
|
88 | + 'disable_taxes' => 'disable_taxes', |
|
89 | + 'due_date' => 'due_date', |
|
90 | + 'completed_date' => 'completed_date', |
|
91 | + 'company' => 'company', |
|
92 | + 'vat_number' => 'vat_number', |
|
93 | + 'vat_rate' => 'vat_rate', |
|
94 | + ); |
|
95 | + |
|
96 | + /* |
|
97 | 97 | |-------------------------------------------------------------------------- |
98 | 98 | | CRUD Methods |
99 | 99 | |-------------------------------------------------------------------------- |
100 | 100 | */ |
101 | - /** |
|
102 | - * Method to create a new invoice in the database. |
|
103 | - * |
|
104 | - * @param WPInv_Invoice $invoice Invoice object. |
|
105 | - */ |
|
106 | - public function create( &$invoice ) { |
|
107 | - $invoice->set_version( WPINV_VERSION ); |
|
108 | - $invoice->set_date_created( current_time('mysql') ); |
|
109 | - |
|
110 | - // Create a new post. |
|
111 | - $id = wp_insert_post( |
|
112 | - apply_filters( |
|
113 | - 'getpaid_new_invoice_data', |
|
114 | - array( |
|
115 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
116 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
117 | - 'post_status' => $this->get_post_status( $invoice ), |
|
118 | - 'ping_status' => 'closed', |
|
119 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
120 | - 'post_title' => $invoice->get_title( 'edit' ), |
|
121 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
122 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
123 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
124 | - ) |
|
125 | - ), |
|
126 | - true |
|
127 | - ); |
|
128 | - |
|
129 | - if ( $id && ! is_wp_error( $id ) ) { |
|
130 | - |
|
131 | - // Update the new id and regenerate a title. |
|
132 | - $invoice->set_id( $id ); |
|
133 | - wp_update_post( array( 'ID' => $invoice->get_id(), 'post_title' => $invoice->get_number( 'edit' ) ) ); |
|
134 | - |
|
135 | - // Ensure both the key and number are set. |
|
136 | - $invoice->get_key(); |
|
137 | - $invoice->get_number(); |
|
138 | - |
|
139 | - // Save special fields and items. |
|
140 | - $this->save_special_fields( $invoice ); |
|
141 | - $this->save_items( $invoice ); |
|
142 | - |
|
143 | - // Update meta data. |
|
144 | - $this->update_post_meta( $invoice ); |
|
145 | - $invoice->save_meta_data(); |
|
146 | - |
|
147 | - // Apply changes. |
|
148 | - $invoice->apply_changes(); |
|
149 | - $this->clear_caches( $invoice ); |
|
150 | - |
|
151 | - // Fires after a new invoice is created. |
|
152 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
153 | - return true; |
|
154 | - } |
|
155 | - |
|
156 | - if ( is_wp_error( $id ) ) { |
|
157 | - $invoice->last_error = $id->get_error_message(); |
|
158 | - } |
|
159 | - |
|
160 | - return false; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Method to read an invoice from the database. |
|
165 | - * |
|
166 | - * @param WPInv_Invoice $invoice Invoice object. |
|
167 | - * |
|
168 | - */ |
|
169 | - public function read( &$invoice ) { |
|
170 | - |
|
171 | - $invoice->set_defaults(); |
|
172 | - $invoice_object = get_post( $invoice->get_id() ); |
|
173 | - |
|
174 | - if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
175 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
176 | - $invoice->set_id( 0 ); |
|
177 | - return false; |
|
178 | - } |
|
179 | - |
|
180 | - $invoice->set_props( |
|
181 | - array( |
|
182 | - 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
183 | - 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
184 | - 'status' => $invoice_object->post_status, |
|
185 | - 'author' => $invoice_object->post_author, |
|
186 | - 'description' => $invoice_object->post_excerpt, |
|
187 | - 'parent_id' => $invoice_object->post_parent, |
|
188 | - 'name' => $invoice_object->post_title, |
|
189 | - 'path' => $invoice_object->post_name, |
|
190 | - 'post_type' => $invoice_object->post_type, |
|
191 | - ) |
|
192 | - ); |
|
193 | - |
|
194 | - $invoice->set_type( $invoice_object->post_type ); |
|
195 | - |
|
196 | - $this->read_object_data( $invoice, $invoice_object ); |
|
197 | - $this->add_special_fields( $invoice ); |
|
198 | - $this->add_items( $invoice ); |
|
199 | - $invoice->read_meta_data(); |
|
200 | - $invoice->set_object_read( true ); |
|
201 | - do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
202 | - |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Method to update an invoice in the database. |
|
207 | - * |
|
208 | - * @param WPInv_Invoice $invoice Invoice object. |
|
209 | - */ |
|
210 | - public function update( &$invoice ) { |
|
211 | - $invoice->save_meta_data(); |
|
212 | - $invoice->set_version( WPINV_VERSION ); |
|
213 | - |
|
214 | - if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
215 | - $invoice->set_date_created( current_time('mysql') ); |
|
216 | - } |
|
217 | - |
|
218 | - // Ensure both the key and number are set. |
|
219 | - $invoice->get_key(); |
|
220 | - $invoice->get_number(); |
|
221 | - |
|
222 | - // Grab the current status so we can compare. |
|
223 | - $previous_status = get_post_status( $invoice->get_id() ); |
|
224 | - |
|
225 | - $changes = $invoice->get_changes(); |
|
226 | - |
|
227 | - // Only update the post when the post data changes. |
|
228 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
229 | - $post_data = array( |
|
230 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
231 | - 'post_status' => $invoice->get_status( 'edit' ), |
|
232 | - 'post_title' => $invoice->get_name( 'edit' ), |
|
233 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
234 | - 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
235 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
236 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
237 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
238 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
239 | - ); |
|
240 | - |
|
241 | - /** |
|
242 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
243 | - * to update data, since wp_update_post spawns more calls to the |
|
244 | - * save_post action. |
|
245 | - * |
|
246 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
247 | - * or an update purely from CRUD. |
|
248 | - */ |
|
249 | - if ( doing_action( 'save_post' ) ) { |
|
250 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
251 | - clean_post_cache( $invoice->get_id() ); |
|
252 | - } else { |
|
253 | - wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
254 | - } |
|
255 | - $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
256 | - } |
|
257 | - |
|
258 | - // Update meta data. |
|
259 | - $this->update_post_meta( $invoice ); |
|
260 | - |
|
261 | - // Save special fields and items. |
|
262 | - $this->save_special_fields( $invoice ); |
|
263 | - $this->save_items( $invoice ); |
|
264 | - |
|
265 | - // Apply the changes. |
|
266 | - $invoice->apply_changes(); |
|
267 | - |
|
268 | - // Clear caches. |
|
269 | - $this->clear_caches( $invoice ); |
|
270 | - |
|
271 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
272 | - $new_status = $invoice->get_status( 'edit' ); |
|
273 | - |
|
274 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
275 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
276 | - } else { |
|
277 | - do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
278 | - } |
|
279 | - |
|
280 | - } |
|
281 | - |
|
282 | - /* |
|
101 | + /** |
|
102 | + * Method to create a new invoice in the database. |
|
103 | + * |
|
104 | + * @param WPInv_Invoice $invoice Invoice object. |
|
105 | + */ |
|
106 | + public function create( &$invoice ) { |
|
107 | + $invoice->set_version( WPINV_VERSION ); |
|
108 | + $invoice->set_date_created( current_time('mysql') ); |
|
109 | + |
|
110 | + // Create a new post. |
|
111 | + $id = wp_insert_post( |
|
112 | + apply_filters( |
|
113 | + 'getpaid_new_invoice_data', |
|
114 | + array( |
|
115 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
116 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
117 | + 'post_status' => $this->get_post_status( $invoice ), |
|
118 | + 'ping_status' => 'closed', |
|
119 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
120 | + 'post_title' => $invoice->get_title( 'edit' ), |
|
121 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
122 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
123 | + 'post_name' => $invoice->get_path( 'edit' ), |
|
124 | + ) |
|
125 | + ), |
|
126 | + true |
|
127 | + ); |
|
128 | + |
|
129 | + if ( $id && ! is_wp_error( $id ) ) { |
|
130 | + |
|
131 | + // Update the new id and regenerate a title. |
|
132 | + $invoice->set_id( $id ); |
|
133 | + wp_update_post( array( 'ID' => $invoice->get_id(), 'post_title' => $invoice->get_number( 'edit' ) ) ); |
|
134 | + |
|
135 | + // Ensure both the key and number are set. |
|
136 | + $invoice->get_key(); |
|
137 | + $invoice->get_number(); |
|
138 | + |
|
139 | + // Save special fields and items. |
|
140 | + $this->save_special_fields( $invoice ); |
|
141 | + $this->save_items( $invoice ); |
|
142 | + |
|
143 | + // Update meta data. |
|
144 | + $this->update_post_meta( $invoice ); |
|
145 | + $invoice->save_meta_data(); |
|
146 | + |
|
147 | + // Apply changes. |
|
148 | + $invoice->apply_changes(); |
|
149 | + $this->clear_caches( $invoice ); |
|
150 | + |
|
151 | + // Fires after a new invoice is created. |
|
152 | + do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
153 | + return true; |
|
154 | + } |
|
155 | + |
|
156 | + if ( is_wp_error( $id ) ) { |
|
157 | + $invoice->last_error = $id->get_error_message(); |
|
158 | + } |
|
159 | + |
|
160 | + return false; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Method to read an invoice from the database. |
|
165 | + * |
|
166 | + * @param WPInv_Invoice $invoice Invoice object. |
|
167 | + * |
|
168 | + */ |
|
169 | + public function read( &$invoice ) { |
|
170 | + |
|
171 | + $invoice->set_defaults(); |
|
172 | + $invoice_object = get_post( $invoice->get_id() ); |
|
173 | + |
|
174 | + if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
175 | + $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
176 | + $invoice->set_id( 0 ); |
|
177 | + return false; |
|
178 | + } |
|
179 | + |
|
180 | + $invoice->set_props( |
|
181 | + array( |
|
182 | + 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
183 | + 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
184 | + 'status' => $invoice_object->post_status, |
|
185 | + 'author' => $invoice_object->post_author, |
|
186 | + 'description' => $invoice_object->post_excerpt, |
|
187 | + 'parent_id' => $invoice_object->post_parent, |
|
188 | + 'name' => $invoice_object->post_title, |
|
189 | + 'path' => $invoice_object->post_name, |
|
190 | + 'post_type' => $invoice_object->post_type, |
|
191 | + ) |
|
192 | + ); |
|
193 | + |
|
194 | + $invoice->set_type( $invoice_object->post_type ); |
|
195 | + |
|
196 | + $this->read_object_data( $invoice, $invoice_object ); |
|
197 | + $this->add_special_fields( $invoice ); |
|
198 | + $this->add_items( $invoice ); |
|
199 | + $invoice->read_meta_data(); |
|
200 | + $invoice->set_object_read( true ); |
|
201 | + do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
202 | + |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Method to update an invoice in the database. |
|
207 | + * |
|
208 | + * @param WPInv_Invoice $invoice Invoice object. |
|
209 | + */ |
|
210 | + public function update( &$invoice ) { |
|
211 | + $invoice->save_meta_data(); |
|
212 | + $invoice->set_version( WPINV_VERSION ); |
|
213 | + |
|
214 | + if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
215 | + $invoice->set_date_created( current_time('mysql') ); |
|
216 | + } |
|
217 | + |
|
218 | + // Ensure both the key and number are set. |
|
219 | + $invoice->get_key(); |
|
220 | + $invoice->get_number(); |
|
221 | + |
|
222 | + // Grab the current status so we can compare. |
|
223 | + $previous_status = get_post_status( $invoice->get_id() ); |
|
224 | + |
|
225 | + $changes = $invoice->get_changes(); |
|
226 | + |
|
227 | + // Only update the post when the post data changes. |
|
228 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
229 | + $post_data = array( |
|
230 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
231 | + 'post_status' => $invoice->get_status( 'edit' ), |
|
232 | + 'post_title' => $invoice->get_name( 'edit' ), |
|
233 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
234 | + 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
235 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
236 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
237 | + 'post_name' => $invoice->get_path( 'edit' ), |
|
238 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
239 | + ); |
|
240 | + |
|
241 | + /** |
|
242 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
243 | + * to update data, since wp_update_post spawns more calls to the |
|
244 | + * save_post action. |
|
245 | + * |
|
246 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
247 | + * or an update purely from CRUD. |
|
248 | + */ |
|
249 | + if ( doing_action( 'save_post' ) ) { |
|
250 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
251 | + clean_post_cache( $invoice->get_id() ); |
|
252 | + } else { |
|
253 | + wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
254 | + } |
|
255 | + $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
256 | + } |
|
257 | + |
|
258 | + // Update meta data. |
|
259 | + $this->update_post_meta( $invoice ); |
|
260 | + |
|
261 | + // Save special fields and items. |
|
262 | + $this->save_special_fields( $invoice ); |
|
263 | + $this->save_items( $invoice ); |
|
264 | + |
|
265 | + // Apply the changes. |
|
266 | + $invoice->apply_changes(); |
|
267 | + |
|
268 | + // Clear caches. |
|
269 | + $this->clear_caches( $invoice ); |
|
270 | + |
|
271 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
272 | + $new_status = $invoice->get_status( 'edit' ); |
|
273 | + |
|
274 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
275 | + do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
276 | + } else { |
|
277 | + do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
278 | + } |
|
279 | + |
|
280 | + } |
|
281 | + |
|
282 | + /* |
|
283 | 283 | |-------------------------------------------------------------------------- |
284 | 284 | | Additional Methods |
285 | 285 | |-------------------------------------------------------------------------- |
286 | 286 | */ |
287 | 287 | |
288 | - /** |
|
288 | + /** |
|
289 | 289 | * Retrieves special fields and adds to the invoice. |
290 | - * |
|
291 | - * @param WPInv_Invoice $invoice Invoice object. |
|
290 | + * |
|
291 | + * @param WPInv_Invoice $invoice Invoice object. |
|
292 | 292 | */ |
293 | 293 | public function add_special_fields( &$invoice ) { |
294 | - global $wpdb; |
|
294 | + global $wpdb; |
|
295 | 295 | |
296 | - // Maybe retrieve from the cache. |
|
297 | - $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
296 | + // Maybe retrieve from the cache. |
|
297 | + $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
298 | 298 | |
299 | - // If not found, retrieve from the db. |
|
300 | - if ( false === $data ) { |
|
301 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
299 | + // If not found, retrieve from the db. |
|
300 | + if ( false === $data ) { |
|
301 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
302 | 302 | |
303 | - $data = $wpdb->get_row( |
|
304 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
305 | - ARRAY_A |
|
306 | - ); |
|
303 | + $data = $wpdb->get_row( |
|
304 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
305 | + ARRAY_A |
|
306 | + ); |
|
307 | 307 | |
308 | - // Update the cache with our data |
|
309 | - wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
308 | + // Update the cache with our data |
|
309 | + wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
310 | 310 | |
311 | - } |
|
311 | + } |
|
312 | 312 | |
313 | - // Abort if the data does not exist. |
|
314 | - if ( empty( $data ) ) { |
|
315 | - return; |
|
316 | - } |
|
313 | + // Abort if the data does not exist. |
|
314 | + if ( empty( $data ) ) { |
|
315 | + return; |
|
316 | + } |
|
317 | 317 | |
318 | - $props = array(); |
|
318 | + $props = array(); |
|
319 | 319 | |
320 | - foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
320 | + foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
321 | 321 | |
322 | - if ( $db_field == 'post_id' ) { |
|
323 | - continue; |
|
324 | - } |
|
325 | - |
|
326 | - $props[ $prop ] = $data[ $db_field ]; |
|
327 | - } |
|
328 | - |
|
329 | - $invoice->set_props( $props ); |
|
330 | - |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Gets a list of special fields that need updated based on change state |
|
335 | - * or if they are present in the database or not. |
|
336 | - * |
|
337 | - * @param WPInv_Invoice $invoice The Invoice object. |
|
338 | - * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
339 | - */ |
|
340 | - protected function get_special_fields_to_update( $invoice ) { |
|
341 | - $fields_to_update = array(); |
|
342 | - $changed_props = $invoice->get_changes(); |
|
343 | - |
|
344 | - // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
345 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
346 | - if ( array_key_exists( $prop, $changed_props ) ) { |
|
347 | - $fields_to_update[ $database_field ] = $prop; |
|
348 | - } |
|
349 | - } |
|
350 | - |
|
351 | - return $fields_to_update; |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
356 | - * |
|
357 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
358 | - * @since 1.0.19 |
|
359 | - */ |
|
360 | - protected function update_special_fields( &$invoice ) { |
|
361 | - global $wpdb; |
|
362 | - |
|
363 | - $updated_props = array(); |
|
364 | - $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
365 | - |
|
366 | - foreach ( $fields_to_update as $database_field => $prop ) { |
|
367 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
368 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
369 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
370 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
371 | - } |
|
372 | - |
|
373 | - if ( ! empty( $updated_props ) ) { |
|
374 | - |
|
375 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
376 | - $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
377 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
378 | - do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
379 | - |
|
380 | - } |
|
381 | - |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Helper method that inserts special fields to the database. |
|
386 | - * |
|
387 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
388 | - * @since 1.0.19 |
|
389 | - */ |
|
390 | - protected function insert_special_fields( &$invoice ) { |
|
391 | - global $wpdb; |
|
392 | - |
|
393 | - $updated_props = array(); |
|
394 | - |
|
395 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
396 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
397 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
398 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
399 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
400 | - } |
|
401 | - |
|
402 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
403 | - $wpdb->insert( $table, $updated_props ); |
|
404 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
405 | - do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
406 | - |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
322 | + if ( $db_field == 'post_id' ) { |
|
323 | + continue; |
|
324 | + } |
|
325 | + |
|
326 | + $props[ $prop ] = $data[ $db_field ]; |
|
327 | + } |
|
328 | + |
|
329 | + $invoice->set_props( $props ); |
|
330 | + |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Gets a list of special fields that need updated based on change state |
|
335 | + * or if they are present in the database or not. |
|
336 | + * |
|
337 | + * @param WPInv_Invoice $invoice The Invoice object. |
|
338 | + * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
339 | + */ |
|
340 | + protected function get_special_fields_to_update( $invoice ) { |
|
341 | + $fields_to_update = array(); |
|
342 | + $changed_props = $invoice->get_changes(); |
|
343 | + |
|
344 | + // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
345 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
346 | + if ( array_key_exists( $prop, $changed_props ) ) { |
|
347 | + $fields_to_update[ $database_field ] = $prop; |
|
348 | + } |
|
349 | + } |
|
350 | + |
|
351 | + return $fields_to_update; |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
356 | + * |
|
357 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
358 | + * @since 1.0.19 |
|
359 | + */ |
|
360 | + protected function update_special_fields( &$invoice ) { |
|
361 | + global $wpdb; |
|
362 | + |
|
363 | + $updated_props = array(); |
|
364 | + $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
365 | + |
|
366 | + foreach ( $fields_to_update as $database_field => $prop ) { |
|
367 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
368 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
369 | + $value = is_bool( $value ) ? ( int ) $value : $value; |
|
370 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
371 | + } |
|
372 | + |
|
373 | + if ( ! empty( $updated_props ) ) { |
|
374 | + |
|
375 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
376 | + $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
377 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
378 | + do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
379 | + |
|
380 | + } |
|
381 | + |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Helper method that inserts special fields to the database. |
|
386 | + * |
|
387 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
388 | + * @since 1.0.19 |
|
389 | + */ |
|
390 | + protected function insert_special_fields( &$invoice ) { |
|
391 | + global $wpdb; |
|
392 | + |
|
393 | + $updated_props = array(); |
|
394 | + |
|
395 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
396 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
397 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
398 | + $value = is_bool( $value ) ? ( int ) $value : $value; |
|
399 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
400 | + } |
|
401 | + |
|
402 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
403 | + $wpdb->insert( $table, $updated_props ); |
|
404 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
405 | + do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
406 | + |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | 410 | * Saves all special fields. |
411 | - * |
|
412 | - * @param WPInv_Invoice $invoice Invoice object. |
|
411 | + * |
|
412 | + * @param WPInv_Invoice $invoice Invoice object. |
|
413 | 413 | */ |
414 | 414 | public function save_special_fields( $invoice ) { |
415 | - global $wpdb; |
|
415 | + global $wpdb; |
|
416 | 416 | |
417 | - // The invoices table. |
|
418 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
419 | - $id = (int) $invoice->get_id(); |
|
417 | + // The invoices table. |
|
418 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
419 | + $id = (int) $invoice->get_id(); |
|
420 | 420 | |
421 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
421 | + if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
422 | 422 | |
423 | - $this->update_special_fields( $invoice ); |
|
423 | + $this->update_special_fields( $invoice ); |
|
424 | 424 | |
425 | - } else { |
|
425 | + } else { |
|
426 | 426 | |
427 | - $this->insert_special_fields( $invoice ); |
|
427 | + $this->insert_special_fields( $invoice ); |
|
428 | 428 | |
429 | - } |
|
429 | + } |
|
430 | 430 | |
431 | - } |
|
431 | + } |
|
432 | 432 | |
433 | - /** |
|
433 | + /** |
|
434 | 434 | * Set's up cart details. |
435 | - * |
|
436 | - * @param WPInv_Invoice $invoice Invoice object. |
|
435 | + * |
|
436 | + * @param WPInv_Invoice $invoice Invoice object. |
|
437 | 437 | */ |
438 | 438 | public function add_items( &$invoice ) { |
439 | - global $wpdb; |
|
439 | + global $wpdb; |
|
440 | 440 | |
441 | - // Maybe retrieve from the cache. |
|
442 | - $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
441 | + // Maybe retrieve from the cache. |
|
442 | + $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
443 | 443 | |
444 | - // If not found, retrieve from the db. |
|
445 | - if ( false === $items ) { |
|
446 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
444 | + // If not found, retrieve from the db. |
|
445 | + if ( false === $items ) { |
|
446 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
447 | 447 | |
448 | - $items = $wpdb->get_results( |
|
449 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
450 | - ); |
|
448 | + $items = $wpdb->get_results( |
|
449 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
450 | + ); |
|
451 | 451 | |
452 | - // Update the cache with our data |
|
453 | - wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
452 | + // Update the cache with our data |
|
453 | + wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
454 | 454 | |
455 | - } |
|
455 | + } |
|
456 | 456 | |
457 | - // Abort if no items found. |
|
457 | + // Abort if no items found. |
|
458 | 458 | if ( empty( $items ) ) { |
459 | 459 | return; |
460 | - } |
|
460 | + } |
|
461 | 461 | |
462 | - foreach ( $items as $item_data ) { |
|
463 | - $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
462 | + foreach ( $items as $item_data ) { |
|
463 | + $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
464 | 464 | |
465 | - // Set item data. |
|
466 | - $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
467 | - $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
468 | - $item->set_name( $item_data->item_name ); |
|
469 | - $item->set_description( $item_data->item_description ); |
|
470 | - $item->set_price( $item_data->item_price ); |
|
471 | - $item->set_quantity( $item_data->quantity ); |
|
472 | - $item->set_item_meta( $item_data->meta ); |
|
465 | + // Set item data. |
|
466 | + $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
467 | + $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
468 | + $item->set_name( $item_data->item_name ); |
|
469 | + $item->set_description( $item_data->item_description ); |
|
470 | + $item->set_price( $item_data->item_price ); |
|
471 | + $item->set_quantity( $item_data->quantity ); |
|
472 | + $item->set_item_meta( $item_data->meta ); |
|
473 | 473 | |
474 | - $invoice->add_item( $item ); |
|
475 | - } |
|
474 | + $invoice->add_item( $item ); |
|
475 | + } |
|
476 | 476 | |
477 | - } |
|
477 | + } |
|
478 | 478 | |
479 | - /** |
|
479 | + /** |
|
480 | 480 | * Saves cart details. |
481 | - * |
|
482 | - * @param WPInv_Invoice $invoice Invoice object. |
|
481 | + * |
|
482 | + * @param WPInv_Invoice $invoice Invoice object. |
|
483 | 483 | */ |
484 | 484 | public function save_items( $invoice ) { |
485 | 485 | |
486 | - // Delete previously existing items. |
|
487 | - $this->delete_items( $invoice ); |
|
486 | + // Delete previously existing items. |
|
487 | + $this->delete_items( $invoice ); |
|
488 | 488 | |
489 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
489 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
490 | 490 | |
491 | - foreach ( $invoice->get_cart_details() as $item_data ) { |
|
492 | - $item_data = array_map( 'maybe_serialize', $item_data ); |
|
493 | - $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
494 | - } |
|
491 | + foreach ( $invoice->get_cart_details() as $item_data ) { |
|
492 | + $item_data = array_map( 'maybe_serialize', $item_data ); |
|
493 | + $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
494 | + } |
|
495 | 495 | |
496 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
497 | - do_action( "getpaid_invoice_save_items", $invoice ); |
|
496 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
497 | + do_action( "getpaid_invoice_save_items", $invoice ); |
|
498 | 498 | |
499 | - } |
|
499 | + } |
|
500 | 500 | |
501 | - /** |
|
501 | + /** |
|
502 | 502 | * Deletes an invoice's cart details from the database. |
503 | - * |
|
504 | - * @param WPInv_Invoice $invoice Invoice object. |
|
503 | + * |
|
504 | + * @param WPInv_Invoice $invoice Invoice object. |
|
505 | 505 | */ |
506 | 506 | public function delete_items( $invoice ) { |
507 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
508 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
509 | - } |
|
507 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
508 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
509 | + } |
|
510 | 510 | |
511 | - /** |
|
511 | + /** |
|
512 | 512 | * Deletes an invoice's special fields 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_special_fields( $invoice ) { |
517 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
518 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
517 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
518 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | } |
@@ -31,36 +31,36 @@ discard block |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | function wpinv_can_checkout() { |
34 | - $can_checkout = true; // Always true for now |
|
34 | + $can_checkout = true; // Always true for now |
|
35 | 35 | |
36 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
36 | + return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | function wpinv_get_success_page_uri() { |
40 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
41 | - $page_id = absint( $page_id ); |
|
40 | + $page_id = wpinv_get_option( 'success_page', 0 ); |
|
41 | + $page_id = absint( $page_id ); |
|
42 | 42 | |
43 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
43 | + return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | function wpinv_get_history_page_uri() { |
47 | - $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
48 | - $page_id = absint( $page_id ); |
|
47 | + $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
48 | + $page_id = absint( $page_id ); |
|
49 | 49 | |
50 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
50 | + return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | function wpinv_is_success_page() { |
54 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
55 | - $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
54 | + $is_success_page = wpinv_get_option( 'success_page', false ); |
|
55 | + $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
56 | 56 | |
57 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
57 | + return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | function wpinv_is_invoice_history_page() { |
61 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
62 | - $ret = $ret ? is_page( $ret ) : false; |
|
63 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
61 | + $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
62 | + $ret = $ret ? is_page( $ret ) : false; |
|
63 | + return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | function wpinv_is_subscriptions_history_page() { |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | } |
84 | 84 | |
85 | 85 | function wpinv_send_to_failed_page( $args = null ) { |
86 | - $redirect = wpinv_get_failed_transaction_uri(); |
|
86 | + $redirect = wpinv_get_failed_transaction_uri(); |
|
87 | 87 | |
88 | 88 | if ( !empty( $args ) ) { |
89 | 89 | // Check for backward compatibility |
@@ -103,73 +103,73 @@ discard block |
||
103 | 103 | } |
104 | 104 | |
105 | 105 | function wpinv_get_checkout_uri( $args = array() ) { |
106 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
107 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
106 | + $uri = wpinv_get_option( 'checkout_page', false ); |
|
107 | + $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
108 | 108 | |
109 | - if ( !empty( $args ) ) { |
|
110 | - // Check for backward compatibility |
|
111 | - if ( is_string( $args ) ) |
|
112 | - $args = str_replace( '?', '', $args ); |
|
109 | + if ( !empty( $args ) ) { |
|
110 | + // Check for backward compatibility |
|
111 | + if ( is_string( $args ) ) |
|
112 | + $args = str_replace( '?', '', $args ); |
|
113 | 113 | |
114 | - $args = wp_parse_args( $args ); |
|
114 | + $args = wp_parse_args( $args ); |
|
115 | 115 | |
116 | - $uri = add_query_arg( $args, $uri ); |
|
117 | - } |
|
116 | + $uri = add_query_arg( $args, $uri ); |
|
117 | + } |
|
118 | 118 | |
119 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
119 | + $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
120 | 120 | |
121 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
121 | + $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
122 | 122 | |
123 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
124 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
125 | - } |
|
123 | + if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
124 | + $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
125 | + } |
|
126 | 126 | |
127 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
127 | + return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | function wpinv_send_back_to_checkout( $args = array() ) { |
131 | - $redirect = wpinv_get_checkout_uri(); |
|
131 | + $redirect = wpinv_get_checkout_uri(); |
|
132 | 132 | |
133 | - if ( ! empty( $args ) ) { |
|
134 | - // Check for backward compatibility |
|
135 | - if ( is_string( $args ) ) |
|
136 | - $args = str_replace( '?', '', $args ); |
|
133 | + if ( ! empty( $args ) ) { |
|
134 | + // Check for backward compatibility |
|
135 | + if ( is_string( $args ) ) |
|
136 | + $args = str_replace( '?', '', $args ); |
|
137 | 137 | |
138 | - $args = wp_parse_args( $args ); |
|
138 | + $args = wp_parse_args( $args ); |
|
139 | 139 | |
140 | - $redirect = add_query_arg( $args, $redirect ); |
|
141 | - } |
|
140 | + $redirect = add_query_arg( $args, $redirect ); |
|
141 | + } |
|
142 | 142 | |
143 | 143 | do_action( 'wpinv_pre_send_back_to_checkout', $args ); |
144 | - wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) ); |
|
145 | - exit; |
|
144 | + wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) ); |
|
145 | + exit; |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | function wpinv_get_success_page_url( $query_string = null ) { |
149 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
150 | - $success_page = get_permalink( $success_page ); |
|
149 | + $success_page = wpinv_get_option( 'success_page', 0 ); |
|
150 | + $success_page = get_permalink( $success_page ); |
|
151 | 151 | |
152 | - if ( $query_string ) |
|
153 | - $success_page .= $query_string; |
|
152 | + if ( $query_string ) |
|
153 | + $success_page .= $query_string; |
|
154 | 154 | |
155 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
155 | + return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | function wpinv_get_failed_transaction_uri( $extras = false ) { |
159 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
160 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
159 | + $uri = wpinv_get_option( 'failure_page', '' ); |
|
160 | + $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
161 | 161 | |
162 | - if ( $extras ) |
|
163 | - $uri .= $extras; |
|
162 | + if ( $extras ) |
|
163 | + $uri .= $extras; |
|
164 | 164 | |
165 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
165 | + return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | function wpinv_is_failed_transaction_page() { |
169 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
170 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
169 | + $ret = wpinv_get_option( 'failure_page', false ); |
|
170 | + $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
171 | 171 | |
172 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
172 | + return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | function wpinv_transaction_query( $type = 'start' ) { |
@@ -244,36 +244,36 @@ discard block |
||
244 | 244 | $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
245 | 245 | |
246 | 246 | if ( $require_billing_details ) { |
247 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
248 | - $required_fields['first_name'] = array( |
|
249 | - 'error_id' => 'invalid_first_name', |
|
250 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
251 | - ); |
|
252 | - } |
|
253 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
254 | - $required_fields['address'] = array( |
|
255 | - 'error_id' => 'invalid_address', |
|
256 | - 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
257 | - ); |
|
258 | - } |
|
259 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
260 | - $required_fields['city'] = array( |
|
261 | - 'error_id' => 'invalid_city', |
|
262 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
263 | - ); |
|
264 | - } |
|
265 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
266 | - $required_fields['state'] = array( |
|
267 | - 'error_id' => 'invalid_state', |
|
268 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
269 | - ); |
|
270 | - } |
|
271 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
272 | - $required_fields['country'] = array( |
|
273 | - 'error_id' => 'invalid_country', |
|
274 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
275 | - ); |
|
276 | - } |
|
247 | + if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
248 | + $required_fields['first_name'] = array( |
|
249 | + 'error_id' => 'invalid_first_name', |
|
250 | + 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
251 | + ); |
|
252 | + } |
|
253 | + if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
254 | + $required_fields['address'] = array( |
|
255 | + 'error_id' => 'invalid_address', |
|
256 | + 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
257 | + ); |
|
258 | + } |
|
259 | + if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
260 | + $required_fields['city'] = array( |
|
261 | + 'error_id' => 'invalid_city', |
|
262 | + 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
263 | + ); |
|
264 | + } |
|
265 | + if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
266 | + $required_fields['state'] = array( |
|
267 | + 'error_id' => 'invalid_state', |
|
268 | + 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
269 | + ); |
|
270 | + } |
|
271 | + if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
272 | + $required_fields['country'] = array( |
|
273 | + 'error_id' => 'invalid_country', |
|
274 | + 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
275 | + ); |
|
276 | + } |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
@@ -30,6 +30,6 @@ |
||
30 | 30 | 'label_type' => 'vertical', |
31 | 31 | 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
32 | 32 | 'input_group_right' => $position == 'right' ? wpinv_currency_symbol( $form->get_currency() ) : '', |
33 | - 'input_group_left' => $position == 'left' ? wpinv_currency_symbol( $form->get_currency() ) : '', |
|
33 | + 'input_group_left' => $position == 'left' ? wpinv_currency_symbol( $form->get_currency() ) : '', |
|
34 | 34 | ) |
35 | 35 | ); |