@@ -20,406 +20,406 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class GetPaid_Installer { |
22 | 22 | |
23 | - private static $schema = null; |
|
24 | - private static $schema_version = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * Upgrades the install. |
|
28 | - * |
|
29 | - * @param string $upgrade_from The current invoicing version. |
|
30 | - */ |
|
31 | - public function upgrade_db( $upgrade_from ) { |
|
32 | - |
|
33 | - // Save the current invoicing version. |
|
34 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
35 | - |
|
36 | - // Setup the invoice Custom Post Type. |
|
37 | - GetPaid_Post_Types::register_post_types(); |
|
38 | - |
|
39 | - // Clear the permalinks |
|
40 | - flush_rewrite_rules(); |
|
41 | - |
|
42 | - // Maybe create new/missing pages. |
|
43 | - $this->create_pages(); |
|
44 | - |
|
45 | - // Maybe re(add) admin capabilities. |
|
46 | - $this->add_capabilities(); |
|
47 | - |
|
48 | - // Maybe create the default payment form. |
|
49 | - wpinv_get_default_payment_form(); |
|
50 | - |
|
51 | - // Create any missing database tables. |
|
52 | - $method = "upgrade_from_$upgrade_from"; |
|
53 | - |
|
54 | - $installed = get_option( 'gepaid_installed_on' ); |
|
55 | - |
|
56 | - if ( empty( $installed ) ) { |
|
57 | - update_option( 'gepaid_installed_on', time() ); |
|
58 | - } |
|
59 | - |
|
60 | - if ( method_exists( $this, $method ) ) { |
|
61 | - $this->$method(); |
|
62 | - } |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Do a fresh install. |
|
67 | - * |
|
68 | - */ |
|
69 | - public function upgrade_from_0() { |
|
70 | - |
|
71 | - // Save default tax rates. |
|
72 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Upgrade to 0.0.5 |
|
77 | - * |
|
78 | - */ |
|
79 | - public function upgrade_from_004() { |
|
80 | - global $wpdb; |
|
81 | - |
|
82 | - // Invoices. |
|
83 | - $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
84 | - if ( ! empty( $results ) ) { |
|
85 | - $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
86 | - |
|
87 | - // Clean post cache |
|
88 | - foreach ( $results as $row ) { |
|
89 | - clean_post_cache( $row->ID ); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - // Item meta key changes |
|
94 | - $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
95 | - $results = $wpdb->get_results( $query ); |
|
96 | - |
|
97 | - if ( ! empty( $results ) ) { |
|
98 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
99 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
100 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
101 | - |
|
102 | - foreach ( $results as $row ) { |
|
103 | - clean_post_cache( $row->post_id ); |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - $this->upgrade_from_118(); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Upgrade to version 2.0.0. |
|
112 | - * |
|
113 | - */ |
|
114 | - public function upgrade_from_118() { |
|
115 | - $this->migrate_old_invoices(); |
|
116 | - $this->upgrade_from_279(); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Upgrade to version 2.0.0. |
|
121 | - * |
|
122 | - */ |
|
123 | - public function upgrade_from_279() { |
|
124 | - self::migrate_old_customers(); |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Give administrators the capability to manage GetPaid. |
|
129 | - * |
|
130 | - */ |
|
131 | - public function add_capabilities() { |
|
132 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Retreives GetPaid pages. |
|
137 | - * |
|
138 | - */ |
|
139 | - public static function get_pages() { |
|
140 | - |
|
141 | - return apply_filters( |
|
142 | - 'wpinv_create_pages', |
|
143 | - array( |
|
144 | - |
|
145 | - // Checkout page. |
|
146 | - 'checkout_page' => array( |
|
147 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
148 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
149 | - 'content' => ' |
|
23 | + private static $schema = null; |
|
24 | + private static $schema_version = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * Upgrades the install. |
|
28 | + * |
|
29 | + * @param string $upgrade_from The current invoicing version. |
|
30 | + */ |
|
31 | + public function upgrade_db( $upgrade_from ) { |
|
32 | + |
|
33 | + // Save the current invoicing version. |
|
34 | + update_option( 'wpinv_version', WPINV_VERSION ); |
|
35 | + |
|
36 | + // Setup the invoice Custom Post Type. |
|
37 | + GetPaid_Post_Types::register_post_types(); |
|
38 | + |
|
39 | + // Clear the permalinks |
|
40 | + flush_rewrite_rules(); |
|
41 | + |
|
42 | + // Maybe create new/missing pages. |
|
43 | + $this->create_pages(); |
|
44 | + |
|
45 | + // Maybe re(add) admin capabilities. |
|
46 | + $this->add_capabilities(); |
|
47 | + |
|
48 | + // Maybe create the default payment form. |
|
49 | + wpinv_get_default_payment_form(); |
|
50 | + |
|
51 | + // Create any missing database tables. |
|
52 | + $method = "upgrade_from_$upgrade_from"; |
|
53 | + |
|
54 | + $installed = get_option( 'gepaid_installed_on' ); |
|
55 | + |
|
56 | + if ( empty( $installed ) ) { |
|
57 | + update_option( 'gepaid_installed_on', time() ); |
|
58 | + } |
|
59 | + |
|
60 | + if ( method_exists( $this, $method ) ) { |
|
61 | + $this->$method(); |
|
62 | + } |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Do a fresh install. |
|
67 | + * |
|
68 | + */ |
|
69 | + public function upgrade_from_0() { |
|
70 | + |
|
71 | + // Save default tax rates. |
|
72 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Upgrade to 0.0.5 |
|
77 | + * |
|
78 | + */ |
|
79 | + public function upgrade_from_004() { |
|
80 | + global $wpdb; |
|
81 | + |
|
82 | + // Invoices. |
|
83 | + $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
84 | + if ( ! empty( $results ) ) { |
|
85 | + $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
86 | + |
|
87 | + // Clean post cache |
|
88 | + foreach ( $results as $row ) { |
|
89 | + clean_post_cache( $row->ID ); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + // Item meta key changes |
|
94 | + $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
95 | + $results = $wpdb->get_results( $query ); |
|
96 | + |
|
97 | + if ( ! empty( $results ) ) { |
|
98 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
99 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
100 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
101 | + |
|
102 | + foreach ( $results as $row ) { |
|
103 | + clean_post_cache( $row->post_id ); |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + $this->upgrade_from_118(); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Upgrade to version 2.0.0. |
|
112 | + * |
|
113 | + */ |
|
114 | + public function upgrade_from_118() { |
|
115 | + $this->migrate_old_invoices(); |
|
116 | + $this->upgrade_from_279(); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Upgrade to version 2.0.0. |
|
121 | + * |
|
122 | + */ |
|
123 | + public function upgrade_from_279() { |
|
124 | + self::migrate_old_customers(); |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Give administrators the capability to manage GetPaid. |
|
129 | + * |
|
130 | + */ |
|
131 | + public function add_capabilities() { |
|
132 | + $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Retreives GetPaid pages. |
|
137 | + * |
|
138 | + */ |
|
139 | + public static function get_pages() { |
|
140 | + |
|
141 | + return apply_filters( |
|
142 | + 'wpinv_create_pages', |
|
143 | + array( |
|
144 | + |
|
145 | + // Checkout page. |
|
146 | + 'checkout_page' => array( |
|
147 | + 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
148 | + 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
149 | + 'content' => ' |
|
150 | 150 | <!-- wp:shortcode --> |
151 | 151 | [wpinv_checkout] |
152 | 152 | <!-- /wp:shortcode --> |
153 | 153 | ', |
154 | - 'parent' => '', |
|
155 | - ), |
|
156 | - |
|
157 | - // Invoice history page. |
|
158 | - 'invoice_history_page' => array( |
|
159 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
160 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
161 | - 'content' => ' |
|
154 | + 'parent' => '', |
|
155 | + ), |
|
156 | + |
|
157 | + // Invoice history page. |
|
158 | + 'invoice_history_page' => array( |
|
159 | + 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
160 | + 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
161 | + 'content' => ' |
|
162 | 162 | <!-- wp:shortcode --> |
163 | 163 | [wpinv_history] |
164 | 164 | <!-- /wp:shortcode --> |
165 | 165 | ', |
166 | - 'parent' => '', |
|
167 | - ), |
|
168 | - |
|
169 | - // Success page content. |
|
170 | - 'success_page' => array( |
|
171 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
172 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
173 | - 'content' => ' |
|
166 | + 'parent' => '', |
|
167 | + ), |
|
168 | + |
|
169 | + // Success page content. |
|
170 | + 'success_page' => array( |
|
171 | + 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
172 | + 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
173 | + 'content' => ' |
|
174 | 174 | <!-- wp:shortcode --> |
175 | 175 | [wpinv_receipt] |
176 | 176 | <!-- /wp:shortcode --> |
177 | 177 | ', |
178 | - 'parent' => 'gp-checkout', |
|
179 | - ), |
|
180 | - |
|
181 | - // Failure page content. |
|
182 | - 'failure_page' => array( |
|
183 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
184 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
185 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
186 | - 'parent' => 'gp-checkout', |
|
187 | - ), |
|
188 | - |
|
189 | - // Subscriptions history page. |
|
190 | - 'invoice_subscription_page' => array( |
|
191 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
192 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
193 | - 'content' => ' |
|
178 | + 'parent' => 'gp-checkout', |
|
179 | + ), |
|
180 | + |
|
181 | + // Failure page content. |
|
182 | + 'failure_page' => array( |
|
183 | + 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
184 | + 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
185 | + 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
186 | + 'parent' => 'gp-checkout', |
|
187 | + ), |
|
188 | + |
|
189 | + // Subscriptions history page. |
|
190 | + 'invoice_subscription_page' => array( |
|
191 | + 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
192 | + 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
193 | + 'content' => ' |
|
194 | 194 | <!-- wp:shortcode --> |
195 | 195 | [wpinv_subscriptions] |
196 | 196 | <!-- /wp:shortcode --> |
197 | 197 | ', |
198 | - 'parent' => '', |
|
199 | - ), |
|
200 | - |
|
201 | - ) |
|
202 | - ); |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Re-create GetPaid pages. |
|
207 | - * |
|
208 | - */ |
|
209 | - public function create_pages() { |
|
210 | - |
|
211 | - foreach ( self::get_pages() as $key => $page ) { |
|
212 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
213 | - } |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Migrates old invoices to new invoices. |
|
218 | - * |
|
219 | - */ |
|
220 | - public function migrate_old_invoices() { |
|
221 | - global $wpdb; |
|
222 | - |
|
223 | - $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
224 | - $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
225 | - $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
226 | - $invoices = array_unique( |
|
227 | - get_posts( |
|
228 | - array( |
|
229 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
230 | - 'posts_per_page' => -1, |
|
231 | - 'fields' => 'ids', |
|
232 | - 'post_status' => array_keys( get_post_stati() ), |
|
233 | - 'exclude' => (array) $migrated, |
|
234 | - ) |
|
235 | - ) |
|
236 | - ); |
|
237 | - |
|
238 | - // Abort if we do not have any invoices. |
|
239 | - if ( empty( $invoices ) ) { |
|
240 | - return; |
|
241 | - } |
|
242 | - |
|
243 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
|
244 | - |
|
245 | - $invoice_rows = array(); |
|
246 | - foreach ( $invoices as $invoice ) { |
|
247 | - |
|
248 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
249 | - |
|
250 | - if ( empty( $invoice->ID ) ) { |
|
251 | - return; |
|
252 | - } |
|
253 | - |
|
254 | - $fields = array( |
|
255 | - 'post_id' => $invoice->ID, |
|
256 | - 'number' => $invoice->get_number(), |
|
257 | - 'key' => $invoice->get_key(), |
|
258 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
259 | - 'mode' => $invoice->mode, |
|
260 | - 'user_ip' => $invoice->get_ip(), |
|
261 | - 'first_name' => $invoice->get_first_name(), |
|
262 | - 'last_name' => $invoice->get_last_name(), |
|
263 | - 'address' => $invoice->get_address(), |
|
264 | - 'city' => $invoice->city, |
|
265 | - 'state' => $invoice->state, |
|
266 | - 'country' => $invoice->country, |
|
267 | - 'zip' => $invoice->zip, |
|
268 | - 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
269 | - 'gateway' => $invoice->get_gateway(), |
|
270 | - 'transaction_id' => $invoice->get_transaction_id(), |
|
271 | - 'currency' => $invoice->get_currency(), |
|
272 | - 'subtotal' => $invoice->get_subtotal(), |
|
273 | - 'tax' => $invoice->get_tax(), |
|
274 | - 'fees_total' => $invoice->get_fees_total(), |
|
275 | - 'total' => $invoice->get_total(), |
|
276 | - 'discount' => $invoice->get_discount(), |
|
277 | - 'discount_code' => $invoice->get_discount_code(), |
|
278 | - 'disable_taxes' => $invoice->disable_taxes, |
|
279 | - 'due_date' => $invoice->get_due_date(), |
|
280 | - 'completed_date' => $invoice->get_completed_date(), |
|
281 | - 'company' => $invoice->company, |
|
282 | - 'vat_number' => $invoice->vat_number, |
|
283 | - 'vat_rate' => $invoice->vat_rate, |
|
284 | - 'custom_meta' => $invoice->payment_meta, |
|
285 | - ); |
|
286 | - |
|
287 | - foreach ( $fields as $key => $val ) { |
|
288 | - if ( is_null( $val ) ) { |
|
289 | - $val = ''; |
|
290 | - } |
|
291 | - $val = maybe_serialize( $val ); |
|
292 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
293 | - } |
|
294 | - |
|
295 | - $fields = implode( ', ', $fields ); |
|
296 | - $invoice_rows[] = "($fields)"; |
|
297 | - |
|
298 | - $item_rows = array(); |
|
299 | - $item_columns = array(); |
|
300 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
301 | - $fields = array( |
|
302 | - 'post_id' => $invoice->ID, |
|
303 | - 'item_id' => $details['id'], |
|
304 | - 'item_name' => $details['name'], |
|
305 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
306 | - 'vat_rate' => $details['vat_rate'], |
|
307 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
308 | - 'tax' => $details['tax'], |
|
309 | - 'item_price' => $details['item_price'], |
|
310 | - 'custom_price' => $details['custom_price'], |
|
311 | - 'quantity' => $details['quantity'], |
|
312 | - 'discount' => $details['discount'], |
|
313 | - 'subtotal' => $details['subtotal'], |
|
314 | - 'price' => $details['price'], |
|
315 | - 'meta' => $details['meta'], |
|
316 | - 'fees' => $details['fees'], |
|
317 | - ); |
|
318 | - |
|
319 | - $item_columns = array_keys( $fields ); |
|
320 | - |
|
321 | - foreach ( $fields as $key => $val ) { |
|
322 | - if ( is_null( $val ) ) { |
|
323 | - $val = ''; |
|
324 | - } |
|
325 | - $val = maybe_serialize( $val ); |
|
326 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
327 | - } |
|
328 | - |
|
329 | - $fields = implode( ', ', $fields ); |
|
330 | - $item_rows[] = "($fields)"; |
|
331 | - } |
|
332 | - |
|
333 | - $item_rows = implode( ', ', $item_rows ); |
|
334 | - $item_columns = implode( ', ', $item_columns ); |
|
335 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
336 | - } |
|
337 | - |
|
338 | - if ( empty( $invoice_rows ) ) { |
|
339 | - return; |
|
340 | - } |
|
341 | - |
|
342 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
343 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Migrates old customers to new table. |
|
348 | - * |
|
349 | - */ |
|
350 | - public static function migrate_old_customers() { |
|
351 | - global $wpdb; |
|
352 | - |
|
353 | - // Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null. |
|
354 | - $invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" ); |
|
355 | - |
|
356 | - foreach ( $invoice_ids as $invoice_id ) { |
|
357 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
358 | - |
|
359 | - if ( empty( $invoice ) ) { |
|
360 | - continue; |
|
361 | - } |
|
362 | - |
|
363 | - // Fetch customer from the user ID. |
|
364 | - $user_id = $invoice->get_user_id(); |
|
365 | - |
|
366 | - if ( empty( $user_id ) ) { |
|
367 | - continue; |
|
368 | - } |
|
369 | - |
|
370 | - $customer = getpaid_get_customer_by_user_id( $user_id ); |
|
371 | - |
|
372 | - // Create if not exists. |
|
373 | - if ( empty( $customer ) ) { |
|
374 | - $customer = new GetPaid_Customer( 0 ); |
|
375 | - $customer->clone_user( $user_id ); |
|
376 | - $customer->save(); |
|
377 | - } |
|
378 | - |
|
379 | - $invoice->set_customer_id( $customer->get_id() ); |
|
380 | - $invoice->save(); |
|
381 | - } |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Migrates old invoices to new invoices. |
|
386 | - * |
|
387 | - */ |
|
388 | - public static function rename_gateways_label() { |
|
389 | - global $wpdb; |
|
390 | - |
|
391 | - foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
392 | - |
|
393 | - $wpdb->update( |
|
394 | - $wpdb->prefix . 'getpaid_invoices', |
|
395 | - array( 'gateway' => $gateway ), |
|
396 | - array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
397 | - '%s', |
|
398 | - '%s' |
|
399 | - ); |
|
400 | - |
|
401 | - } |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Returns the DB schema. |
|
406 | - * |
|
407 | - */ |
|
408 | - public static function get_db_schema() { |
|
409 | - global $wpdb; |
|
410 | - |
|
411 | - if ( ! empty( self::$schema ) ) { |
|
412 | - return self::$schema; |
|
413 | - } |
|
414 | - |
|
415 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
416 | - |
|
417 | - $charset_collate = $wpdb->get_charset_collate(); |
|
418 | - |
|
419 | - $schema = array(); |
|
420 | - |
|
421 | - // Subscriptions. |
|
422 | - $schema['subscriptions'] = "CREATE TABLE {$wpdb->prefix}wpinv_subscriptions ( |
|
198 | + 'parent' => '', |
|
199 | + ), |
|
200 | + |
|
201 | + ) |
|
202 | + ); |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Re-create GetPaid pages. |
|
207 | + * |
|
208 | + */ |
|
209 | + public function create_pages() { |
|
210 | + |
|
211 | + foreach ( self::get_pages() as $key => $page ) { |
|
212 | + wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
213 | + } |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Migrates old invoices to new invoices. |
|
218 | + * |
|
219 | + */ |
|
220 | + public function migrate_old_invoices() { |
|
221 | + global $wpdb; |
|
222 | + |
|
223 | + $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
224 | + $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
225 | + $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
226 | + $invoices = array_unique( |
|
227 | + get_posts( |
|
228 | + array( |
|
229 | + 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
230 | + 'posts_per_page' => -1, |
|
231 | + 'fields' => 'ids', |
|
232 | + 'post_status' => array_keys( get_post_stati() ), |
|
233 | + 'exclude' => (array) $migrated, |
|
234 | + ) |
|
235 | + ) |
|
236 | + ); |
|
237 | + |
|
238 | + // Abort if we do not have any invoices. |
|
239 | + if ( empty( $invoices ) ) { |
|
240 | + return; |
|
241 | + } |
|
242 | + |
|
243 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
|
244 | + |
|
245 | + $invoice_rows = array(); |
|
246 | + foreach ( $invoices as $invoice ) { |
|
247 | + |
|
248 | + $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
249 | + |
|
250 | + if ( empty( $invoice->ID ) ) { |
|
251 | + return; |
|
252 | + } |
|
253 | + |
|
254 | + $fields = array( |
|
255 | + 'post_id' => $invoice->ID, |
|
256 | + 'number' => $invoice->get_number(), |
|
257 | + 'key' => $invoice->get_key(), |
|
258 | + 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
259 | + 'mode' => $invoice->mode, |
|
260 | + 'user_ip' => $invoice->get_ip(), |
|
261 | + 'first_name' => $invoice->get_first_name(), |
|
262 | + 'last_name' => $invoice->get_last_name(), |
|
263 | + 'address' => $invoice->get_address(), |
|
264 | + 'city' => $invoice->city, |
|
265 | + 'state' => $invoice->state, |
|
266 | + 'country' => $invoice->country, |
|
267 | + 'zip' => $invoice->zip, |
|
268 | + 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
269 | + 'gateway' => $invoice->get_gateway(), |
|
270 | + 'transaction_id' => $invoice->get_transaction_id(), |
|
271 | + 'currency' => $invoice->get_currency(), |
|
272 | + 'subtotal' => $invoice->get_subtotal(), |
|
273 | + 'tax' => $invoice->get_tax(), |
|
274 | + 'fees_total' => $invoice->get_fees_total(), |
|
275 | + 'total' => $invoice->get_total(), |
|
276 | + 'discount' => $invoice->get_discount(), |
|
277 | + 'discount_code' => $invoice->get_discount_code(), |
|
278 | + 'disable_taxes' => $invoice->disable_taxes, |
|
279 | + 'due_date' => $invoice->get_due_date(), |
|
280 | + 'completed_date' => $invoice->get_completed_date(), |
|
281 | + 'company' => $invoice->company, |
|
282 | + 'vat_number' => $invoice->vat_number, |
|
283 | + 'vat_rate' => $invoice->vat_rate, |
|
284 | + 'custom_meta' => $invoice->payment_meta, |
|
285 | + ); |
|
286 | + |
|
287 | + foreach ( $fields as $key => $val ) { |
|
288 | + if ( is_null( $val ) ) { |
|
289 | + $val = ''; |
|
290 | + } |
|
291 | + $val = maybe_serialize( $val ); |
|
292 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
293 | + } |
|
294 | + |
|
295 | + $fields = implode( ', ', $fields ); |
|
296 | + $invoice_rows[] = "($fields)"; |
|
297 | + |
|
298 | + $item_rows = array(); |
|
299 | + $item_columns = array(); |
|
300 | + foreach ( $invoice->get_cart_details() as $details ) { |
|
301 | + $fields = array( |
|
302 | + 'post_id' => $invoice->ID, |
|
303 | + 'item_id' => $details['id'], |
|
304 | + 'item_name' => $details['name'], |
|
305 | + 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
306 | + 'vat_rate' => $details['vat_rate'], |
|
307 | + 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
308 | + 'tax' => $details['tax'], |
|
309 | + 'item_price' => $details['item_price'], |
|
310 | + 'custom_price' => $details['custom_price'], |
|
311 | + 'quantity' => $details['quantity'], |
|
312 | + 'discount' => $details['discount'], |
|
313 | + 'subtotal' => $details['subtotal'], |
|
314 | + 'price' => $details['price'], |
|
315 | + 'meta' => $details['meta'], |
|
316 | + 'fees' => $details['fees'], |
|
317 | + ); |
|
318 | + |
|
319 | + $item_columns = array_keys( $fields ); |
|
320 | + |
|
321 | + foreach ( $fields as $key => $val ) { |
|
322 | + if ( is_null( $val ) ) { |
|
323 | + $val = ''; |
|
324 | + } |
|
325 | + $val = maybe_serialize( $val ); |
|
326 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
327 | + } |
|
328 | + |
|
329 | + $fields = implode( ', ', $fields ); |
|
330 | + $item_rows[] = "($fields)"; |
|
331 | + } |
|
332 | + |
|
333 | + $item_rows = implode( ', ', $item_rows ); |
|
334 | + $item_columns = implode( ', ', $item_columns ); |
|
335 | + $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
336 | + } |
|
337 | + |
|
338 | + if ( empty( $invoice_rows ) ) { |
|
339 | + return; |
|
340 | + } |
|
341 | + |
|
342 | + $invoice_rows = implode( ', ', $invoice_rows ); |
|
343 | + $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Migrates old customers to new table. |
|
348 | + * |
|
349 | + */ |
|
350 | + public static function migrate_old_customers() { |
|
351 | + global $wpdb; |
|
352 | + |
|
353 | + // Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null. |
|
354 | + $invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" ); |
|
355 | + |
|
356 | + foreach ( $invoice_ids as $invoice_id ) { |
|
357 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
358 | + |
|
359 | + if ( empty( $invoice ) ) { |
|
360 | + continue; |
|
361 | + } |
|
362 | + |
|
363 | + // Fetch customer from the user ID. |
|
364 | + $user_id = $invoice->get_user_id(); |
|
365 | + |
|
366 | + if ( empty( $user_id ) ) { |
|
367 | + continue; |
|
368 | + } |
|
369 | + |
|
370 | + $customer = getpaid_get_customer_by_user_id( $user_id ); |
|
371 | + |
|
372 | + // Create if not exists. |
|
373 | + if ( empty( $customer ) ) { |
|
374 | + $customer = new GetPaid_Customer( 0 ); |
|
375 | + $customer->clone_user( $user_id ); |
|
376 | + $customer->save(); |
|
377 | + } |
|
378 | + |
|
379 | + $invoice->set_customer_id( $customer->get_id() ); |
|
380 | + $invoice->save(); |
|
381 | + } |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Migrates old invoices to new invoices. |
|
386 | + * |
|
387 | + */ |
|
388 | + public static function rename_gateways_label() { |
|
389 | + global $wpdb; |
|
390 | + |
|
391 | + foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
392 | + |
|
393 | + $wpdb->update( |
|
394 | + $wpdb->prefix . 'getpaid_invoices', |
|
395 | + array( 'gateway' => $gateway ), |
|
396 | + array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
397 | + '%s', |
|
398 | + '%s' |
|
399 | + ); |
|
400 | + |
|
401 | + } |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Returns the DB schema. |
|
406 | + * |
|
407 | + */ |
|
408 | + public static function get_db_schema() { |
|
409 | + global $wpdb; |
|
410 | + |
|
411 | + if ( ! empty( self::$schema ) ) { |
|
412 | + return self::$schema; |
|
413 | + } |
|
414 | + |
|
415 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
416 | + |
|
417 | + $charset_collate = $wpdb->get_charset_collate(); |
|
418 | + |
|
419 | + $schema = array(); |
|
420 | + |
|
421 | + // Subscriptions. |
|
422 | + $schema['subscriptions'] = "CREATE TABLE {$wpdb->prefix}wpinv_subscriptions ( |
|
423 | 423 | id bigint(20) unsigned NOT NULL auto_increment, |
424 | 424 | customer_id bigint(20) NOT NULL, |
425 | 425 | frequency int(11) NOT NULL DEFAULT '1', |
@@ -442,8 +442,8 @@ discard block |
||
442 | 442 | KEY customer_and_status (customer_id, status) |
443 | 443 | ) $charset_collate;"; |
444 | 444 | |
445 | - // Invoices. |
|
446 | - $schema['invoices'] = "CREATE TABLE {$wpdb->prefix}getpaid_invoices ( |
|
445 | + // Invoices. |
|
446 | + $schema['invoices'] = "CREATE TABLE {$wpdb->prefix}getpaid_invoices ( |
|
447 | 447 | post_id BIGINT(20) NOT NULL, |
448 | 448 | customer_id BIGINT(20) NOT NULL DEFAULT 0, |
449 | 449 | `number` VARCHAR(100), |
@@ -481,8 +481,8 @@ discard block |
||
481 | 481 | KEY invoice_key (invoice_key) |
482 | 482 | ) $charset_collate;"; |
483 | 483 | |
484 | - // Invoice items. |
|
485 | - $schema['items'] = "CREATE TABLE {$wpdb->prefix}getpaid_invoice_items ( |
|
484 | + // Invoice items. |
|
485 | + $schema['items'] = "CREATE TABLE {$wpdb->prefix}getpaid_invoice_items ( |
|
486 | 486 | ID BIGINT(20) NOT NULL AUTO_INCREMENT, |
487 | 487 | post_id BIGINT(20) NOT NULL, |
488 | 488 | item_id BIGINT(20) NOT NULL, |
@@ -504,8 +504,8 @@ discard block |
||
504 | 504 | KEY post_id (post_id) |
505 | 505 | ) $charset_collate;"; |
506 | 506 | |
507 | - // Customers. |
|
508 | - $schema['customers'] = "CREATE TABLE {$wpdb->prefix}getpaid_customers ( |
|
507 | + // Customers. |
|
508 | + $schema['customers'] = "CREATE TABLE {$wpdb->prefix}getpaid_customers ( |
|
509 | 509 | id BIGINT(20) NOT NULL AUTO_INCREMENT, |
510 | 510 | user_id BIGINT(20) NOT NULL, |
511 | 511 | email VARCHAR(100) NOT NULL, |
@@ -515,38 +515,38 @@ discard block |
||
515 | 515 | purchase_count BIGINT(20) NOT NULL DEFAULT 0, |
516 | 516 | "; |
517 | 517 | |
518 | - // Add address fields. |
|
519 | - foreach ( array_keys( getpaid_user_address_fields( true ) ) as $field ) { |
|
520 | - // Skip id, user_id and email. |
|
521 | - if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
522 | - continue; |
|
523 | - } |
|
524 | - |
|
525 | - $field = sanitize_key( $field ); |
|
526 | - $length = 100; |
|
527 | - $default = ''; |
|
528 | - |
|
529 | - // Country. |
|
530 | - if ( 'country' === $field ) { |
|
531 | - $length = 2; |
|
532 | - $default = wpinv_get_default_country(); |
|
533 | - } |
|
534 | - |
|
535 | - // State. |
|
536 | - if ( 'state' === $field ) { |
|
537 | - $default = wpinv_get_default_state(); |
|
538 | - } |
|
539 | - |
|
540 | - // Phone, zip. |
|
541 | - if ( in_array( $field, array( 'phone', 'zip' ), true ) ) { |
|
542 | - $length = 20; |
|
543 | - } |
|
544 | - |
|
545 | - $schema['customers'] .= "`$field` VARCHAR($length) NOT NULL DEFAULT '$default', |
|
518 | + // Add address fields. |
|
519 | + foreach ( array_keys( getpaid_user_address_fields( true ) ) as $field ) { |
|
520 | + // Skip id, user_id and email. |
|
521 | + if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
522 | + continue; |
|
523 | + } |
|
524 | + |
|
525 | + $field = sanitize_key( $field ); |
|
526 | + $length = 100; |
|
527 | + $default = ''; |
|
528 | + |
|
529 | + // Country. |
|
530 | + if ( 'country' === $field ) { |
|
531 | + $length = 2; |
|
532 | + $default = wpinv_get_default_country(); |
|
533 | + } |
|
534 | + |
|
535 | + // State. |
|
536 | + if ( 'state' === $field ) { |
|
537 | + $default = wpinv_get_default_state(); |
|
538 | + } |
|
539 | + |
|
540 | + // Phone, zip. |
|
541 | + if ( in_array( $field, array( 'phone', 'zip' ), true ) ) { |
|
542 | + $length = 20; |
|
543 | + } |
|
544 | + |
|
545 | + $schema['customers'] .= "`$field` VARCHAR($length) NOT NULL DEFAULT '$default', |
|
546 | 546 | "; |
547 | - } |
|
547 | + } |
|
548 | 548 | |
549 | - $schema['customers'] .= "date_created DATETIME NOT NULL, |
|
549 | + $schema['customers'] .= "date_created DATETIME NOT NULL, |
|
550 | 550 | date_modified DATETIME NOT NULL, |
551 | 551 | uuid VARCHAR(100) NOT NULL, |
552 | 552 | is_anonymized INT(2) NOT NULL DEFAULT 0, |
@@ -556,8 +556,8 @@ discard block |
||
556 | 556 | KEY email (email) |
557 | 557 | ) $charset_collate;"; |
558 | 558 | |
559 | - // Customer meta. |
|
560 | - $schema['customer_meta'] = "CREATE TABLE {$wpdb->prefix}getpaid_customer_meta ( |
|
559 | + // Customer meta. |
|
560 | + $schema['customer_meta'] = "CREATE TABLE {$wpdb->prefix}getpaid_customer_meta ( |
|
561 | 561 | meta_id BIGINT(20) NOT NULL AUTO_INCREMENT, |
562 | 562 | customer_id BIGINT(20) NOT NULL, |
563 | 563 | meta_key VARCHAR(255) NOT NULL, |
@@ -582,75 +582,75 @@ discard block |
||
582 | 582 | KEY timestamp (timestamp) |
583 | 583 | ) $charset_collate;"; |
584 | 584 | |
585 | - // Filter. |
|
586 | - $schema = apply_filters( 'getpaid_db_schema', $schema ); |
|
587 | - |
|
588 | - self::$schema = implode( "\n", array_values( $schema ) ); |
|
589 | - self::$schema_version = md5( sanitize_key( self::$schema ) ); |
|
590 | - |
|
591 | - return self::$schema; |
|
592 | - } |
|
593 | - |
|
594 | - /** |
|
595 | - * Returns the DB schema version. |
|
596 | - * |
|
597 | - */ |
|
598 | - public static function get_db_schema_version() { |
|
599 | - if ( ! empty( self::$schema_version ) ) { |
|
600 | - return self::$schema_version; |
|
601 | - } |
|
602 | - |
|
603 | - self::get_db_schema(); |
|
604 | - |
|
605 | - return self::$schema_version; |
|
606 | - } |
|
607 | - |
|
608 | - /** |
|
609 | - * Checks if the db schema is up to date. |
|
610 | - * |
|
611 | - * @return bool |
|
612 | - */ |
|
613 | - public static function is_db_schema_up_to_date() { |
|
614 | - return self::get_db_schema_version() === get_option( 'getpaid_db_schema' ); |
|
615 | - } |
|
616 | - |
|
617 | - /** |
|
618 | - * Set up the database tables which the plugin needs to function. |
|
619 | - */ |
|
620 | - public static function create_db_tables() { |
|
621 | - global $wpdb; |
|
622 | - |
|
623 | - $wpdb->hide_errors(); |
|
624 | - |
|
625 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
626 | - |
|
627 | - $schema = self::get_db_schema(); |
|
628 | - |
|
629 | - // If invoices table exists, rename key to invoice_key. |
|
630 | - $invoices_table = "{$wpdb->prefix}getpaid_invoices"; |
|
631 | - |
|
632 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) === $invoices_table ) { |
|
633 | - $fields = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}getpaid_invoices" ); |
|
634 | - |
|
635 | - foreach ( $fields as $field ) { |
|
636 | - if ( 'key' === $field->Field ) { |
|
637 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices CHANGE `key` `invoice_key` VARCHAR(100)" ); |
|
638 | - break; |
|
639 | - } |
|
640 | - } |
|
641 | - } |
|
642 | - |
|
643 | - dbDelta( $schema ); |
|
644 | - wp_cache_flush(); |
|
645 | - update_option( 'getpaid_db_schema', self::get_db_schema_version() ); |
|
646 | - } |
|
647 | - |
|
648 | - /** |
|
649 | - * Creates tables if schema is not up to date. |
|
650 | - */ |
|
651 | - public static function maybe_create_db_tables() { |
|
652 | - if ( ! self::is_db_schema_up_to_date() ) { |
|
653 | - self::create_db_tables(); |
|
654 | - } |
|
655 | - } |
|
585 | + // Filter. |
|
586 | + $schema = apply_filters( 'getpaid_db_schema', $schema ); |
|
587 | + |
|
588 | + self::$schema = implode( "\n", array_values( $schema ) ); |
|
589 | + self::$schema_version = md5( sanitize_key( self::$schema ) ); |
|
590 | + |
|
591 | + return self::$schema; |
|
592 | + } |
|
593 | + |
|
594 | + /** |
|
595 | + * Returns the DB schema version. |
|
596 | + * |
|
597 | + */ |
|
598 | + public static function get_db_schema_version() { |
|
599 | + if ( ! empty( self::$schema_version ) ) { |
|
600 | + return self::$schema_version; |
|
601 | + } |
|
602 | + |
|
603 | + self::get_db_schema(); |
|
604 | + |
|
605 | + return self::$schema_version; |
|
606 | + } |
|
607 | + |
|
608 | + /** |
|
609 | + * Checks if the db schema is up to date. |
|
610 | + * |
|
611 | + * @return bool |
|
612 | + */ |
|
613 | + public static function is_db_schema_up_to_date() { |
|
614 | + return self::get_db_schema_version() === get_option( 'getpaid_db_schema' ); |
|
615 | + } |
|
616 | + |
|
617 | + /** |
|
618 | + * Set up the database tables which the plugin needs to function. |
|
619 | + */ |
|
620 | + public static function create_db_tables() { |
|
621 | + global $wpdb; |
|
622 | + |
|
623 | + $wpdb->hide_errors(); |
|
624 | + |
|
625 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
626 | + |
|
627 | + $schema = self::get_db_schema(); |
|
628 | + |
|
629 | + // If invoices table exists, rename key to invoice_key. |
|
630 | + $invoices_table = "{$wpdb->prefix}getpaid_invoices"; |
|
631 | + |
|
632 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) === $invoices_table ) { |
|
633 | + $fields = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}getpaid_invoices" ); |
|
634 | + |
|
635 | + foreach ( $fields as $field ) { |
|
636 | + if ( 'key' === $field->Field ) { |
|
637 | + $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices CHANGE `key` `invoice_key` VARCHAR(100)" ); |
|
638 | + break; |
|
639 | + } |
|
640 | + } |
|
641 | + } |
|
642 | + |
|
643 | + dbDelta( $schema ); |
|
644 | + wp_cache_flush(); |
|
645 | + update_option( 'getpaid_db_schema', self::get_db_schema_version() ); |
|
646 | + } |
|
647 | + |
|
648 | + /** |
|
649 | + * Creates tables if schema is not up to date. |
|
650 | + */ |
|
651 | + public static function maybe_create_db_tables() { |
|
652 | + if ( ! self::is_db_schema_up_to_date() ) { |
|
653 | + self::create_db_tables(); |
|
654 | + } |
|
655 | + } |
|
656 | 656 | } |
@@ -34,12 +34,12 @@ |
||
34 | 34 | // Prepare pagination |
35 | 35 | $pagination = paginate_links( |
36 | 36 | array( |
37 | - 'base' => add_query_arg( 'paged', '%#%' ), |
|
38 | - 'format' => '', |
|
39 | - 'prev_text' => __( '«', 'invoicing' ), |
|
40 | - 'next_text' => __( '»', 'invoicing' ), |
|
41 | - 'total' => ceil( $total_logs / $per_page ), |
|
42 | - 'current' => $page, |
|
37 | + 'base' => add_query_arg( 'paged', '%#%' ), |
|
38 | + 'format' => '', |
|
39 | + 'prev_text' => __( '«', 'invoicing' ), |
|
40 | + 'next_text' => __( '»', 'invoicing' ), |
|
41 | + 'total' => ceil( $total_logs / $per_page ), |
|
42 | + 'current' => $page, |
|
43 | 43 | ) |
44 | 44 | ); |
45 | 45 |
@@ -25,14 +25,14 @@ discard block |
||
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
28 | - * Highlights sub menus. |
|
29 | - */ |
|
30 | - public function set_admin_menu_class() { |
|
31 | - global $current_screen, $parent_file, $submenu_file; |
|
28 | + * Highlights sub menus. |
|
29 | + */ |
|
30 | + public function set_admin_menu_class() { |
|
31 | + global $current_screen, $parent_file, $submenu_file; |
|
32 | 32 | |
33 | 33 | if ( ! empty( $current_screen->id ) && in_array( $current_screen->id, array( 'wpi_discount', 'wpi_payment_form', 'wpi_invoice' ) ) ) { |
34 | - $parent_file = 'wpinv'; |
|
35 | - $submenu_file = 'edit.php?post_type=' . $current_screen->id; |
|
34 | + $parent_file = 'wpinv'; |
|
35 | + $submenu_file = 'edit.php?post_type=' . $current_screen->id; |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | foreach ( wpinv_get_settings_tabs() as $tab_id => $tab_name ) { |
185 | 185 | $tab_url = add_query_arg( |
186 | 186 | array( |
187 | - 'settings-updated' => false, |
|
188 | - 'tab' => $tab_id, |
|
187 | + 'settings-updated' => false, |
|
188 | + 'tab' => $tab_id, |
|
189 | 189 | ), |
190 | 190 | 'admin.php?page=wpinv-settings' |
191 | 191 | ); |
@@ -212,9 +212,9 @@ discard block |
||
212 | 212 | ++$number; |
213 | 213 | $tab_url = add_query_arg( |
214 | 214 | array( |
215 | - 'settings-updated' => false, |
|
216 | - 'tab' => $active_tab, |
|
217 | - 'section' => $section_id, |
|
215 | + 'settings-updated' => false, |
|
216 | + 'tab' => $active_tab, |
|
217 | + 'section' => $section_id, |
|
218 | 218 | ), |
219 | 219 | admin_url( 'admin.php?page=wpinv-settings' ) |
220 | 220 | ); |
@@ -12,136 +12,136 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Daily_Maintenance { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - */ |
|
18 | - public function __construct() { |
|
19 | - |
|
20 | - // Clear deprecated events. |
|
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | - |
|
23 | - // (Maybe) schedule a cron that runs daily. |
|
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | - |
|
26 | - // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * Schedules a cron to run every day at 7 a.m |
|
36 | - * |
|
37 | - */ |
|
38 | - public function maybe_create_scheduled_event() { |
|
39 | - |
|
40 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
41 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
42 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
43 | - } |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Clears deprecated events. |
|
48 | - * |
|
49 | - */ |
|
50 | - public function maybe_clear_deprecated_events() { |
|
51 | - |
|
52 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
53 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
54 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
55 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
56 | - } |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Fires the old hook for backwards compatibility. |
|
61 | - * |
|
62 | - */ |
|
63 | - public function backwards_compat() { |
|
64 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Checks for subscriptions that are scheduled to renew. |
|
69 | - * |
|
70 | - */ |
|
71 | - public function check_renewing_subscriptions() { |
|
72 | - |
|
73 | - // Fetch subscriptions that expire today. |
|
74 | - $args = array( |
|
75 | - 'number' => -1, |
|
76 | - 'count_total' => false, |
|
77 | - 'status' => 'trialling active', |
|
78 | - 'date_expires_query' => array( |
|
79 | - array( |
|
80 | - 'year' => gmdate( 'Y' ), |
|
81 | - 'month' => gmdate( 'n' ), |
|
82 | - 'day' => gmdate( 'j' ), |
|
83 | - 'compare' => '=', |
|
84 | - ), |
|
85 | - ), |
|
86 | - ); |
|
87 | - |
|
88 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
89 | - |
|
90 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
91 | - /** @var WPInv_Subscription $subscription */ |
|
92 | - if ( $subscription->is_last_renewal() ) { |
|
93 | - $subscription->complete(); |
|
94 | - } else { |
|
95 | - do_action( 'getpaid_should_renew_subscription', $subscription, $subscription->get_parent_invoice() ); |
|
96 | - } |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Expires expired subscriptions. |
|
102 | - * |
|
103 | - */ |
|
104 | - public function maybe_expire_subscriptions() { |
|
105 | - |
|
106 | - // Fetch expired subscriptions (skips those that expire today). |
|
107 | - $args = array( |
|
108 | - 'number' => -1, |
|
109 | - 'count_total' => false, |
|
110 | - 'status' => 'trialling active failing cancelled', |
|
111 | - 'date_expires_query' => array( |
|
112 | - 'before' => 'yesterday', |
|
113 | - 'inclusive' => false, |
|
114 | - ), |
|
115 | - ); |
|
116 | - |
|
117 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
118 | - |
|
119 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
120 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
121 | - $subscription->set_status( 'expired' ); |
|
122 | - $subscription->save(); |
|
123 | - } |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Logs cron runs. |
|
129 | - * |
|
130 | - */ |
|
131 | - public function log_cron_run() { |
|
132 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Updates GeoIP databases. |
|
137 | - * |
|
138 | - */ |
|
139 | - public function maybe_update_geoip_databases() { |
|
140 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
141 | - |
|
142 | - if ( false === $updated ) { |
|
143 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
144 | - do_action( 'getpaid_update_geoip_databases' ); |
|
145 | - } |
|
146 | - } |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + */ |
|
18 | + public function __construct() { |
|
19 | + |
|
20 | + // Clear deprecated events. |
|
21 | + add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | + |
|
23 | + // (Maybe) schedule a cron that runs daily. |
|
24 | + add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | + |
|
26 | + // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | + add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | + add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | + add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * Schedules a cron to run every day at 7 a.m |
|
36 | + * |
|
37 | + */ |
|
38 | + public function maybe_create_scheduled_event() { |
|
39 | + |
|
40 | + if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
41 | + $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
42 | + wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
43 | + } |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Clears deprecated events. |
|
48 | + * |
|
49 | + */ |
|
50 | + public function maybe_clear_deprecated_events() { |
|
51 | + |
|
52 | + if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
53 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
54 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
55 | + update_option( 'wpinv_cleared_old_events', 1 ); |
|
56 | + } |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Fires the old hook for backwards compatibility. |
|
61 | + * |
|
62 | + */ |
|
63 | + public function backwards_compat() { |
|
64 | + do_action( 'wpinv_register_schedule_event_daily' ); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Checks for subscriptions that are scheduled to renew. |
|
69 | + * |
|
70 | + */ |
|
71 | + public function check_renewing_subscriptions() { |
|
72 | + |
|
73 | + // Fetch subscriptions that expire today. |
|
74 | + $args = array( |
|
75 | + 'number' => -1, |
|
76 | + 'count_total' => false, |
|
77 | + 'status' => 'trialling active', |
|
78 | + 'date_expires_query' => array( |
|
79 | + array( |
|
80 | + 'year' => gmdate( 'Y' ), |
|
81 | + 'month' => gmdate( 'n' ), |
|
82 | + 'day' => gmdate( 'j' ), |
|
83 | + 'compare' => '=', |
|
84 | + ), |
|
85 | + ), |
|
86 | + ); |
|
87 | + |
|
88 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
89 | + |
|
90 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
91 | + /** @var WPInv_Subscription $subscription */ |
|
92 | + if ( $subscription->is_last_renewal() ) { |
|
93 | + $subscription->complete(); |
|
94 | + } else { |
|
95 | + do_action( 'getpaid_should_renew_subscription', $subscription, $subscription->get_parent_invoice() ); |
|
96 | + } |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Expires expired subscriptions. |
|
102 | + * |
|
103 | + */ |
|
104 | + public function maybe_expire_subscriptions() { |
|
105 | + |
|
106 | + // Fetch expired subscriptions (skips those that expire today). |
|
107 | + $args = array( |
|
108 | + 'number' => -1, |
|
109 | + 'count_total' => false, |
|
110 | + 'status' => 'trialling active failing cancelled', |
|
111 | + 'date_expires_query' => array( |
|
112 | + 'before' => 'yesterday', |
|
113 | + 'inclusive' => false, |
|
114 | + ), |
|
115 | + ); |
|
116 | + |
|
117 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
118 | + |
|
119 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
120 | + if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
121 | + $subscription->set_status( 'expired' ); |
|
122 | + $subscription->save(); |
|
123 | + } |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Logs cron runs. |
|
129 | + * |
|
130 | + */ |
|
131 | + public function log_cron_run() { |
|
132 | + wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Updates GeoIP databases. |
|
137 | + * |
|
138 | + */ |
|
139 | + public function maybe_update_geoip_databases() { |
|
140 | + $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
141 | + |
|
142 | + if ( false === $updated ) { |
|
143 | + set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
144 | + do_action( 'getpaid_update_geoip_databases' ); |
|
145 | + } |
|
146 | + } |
|
147 | 147 | } |
@@ -291,18 +291,18 @@ |
||
291 | 291 | |
292 | 292 | $user_meta_data = array( |
293 | 293 | 'nickname', |
294 | - 'description', |
|
295 | - 'rich_editing', |
|
296 | - 'syntax_highlighting', |
|
297 | - 'comment_shortcuts', |
|
294 | + 'description', |
|
295 | + 'rich_editing', |
|
296 | + 'syntax_highlighting', |
|
297 | + 'comment_shortcuts', |
|
298 | 298 | 'admin_color', |
299 | - 'use_ssl', |
|
300 | - 'show_admin_bar_front', |
|
301 | - 'locale', |
|
302 | - 'wp_capabilities', |
|
299 | + 'use_ssl', |
|
300 | + 'show_admin_bar_front', |
|
301 | + 'locale', |
|
302 | + 'wp_capabilities', |
|
303 | 303 | 'wp_user_level', |
304 | - 'dismissed_wp_pointers', |
|
305 | - 'show_welcome_panel', |
|
304 | + 'dismissed_wp_pointers', |
|
305 | + 'show_welcome_panel', |
|
306 | 306 | ); |
307 | 307 | |
308 | 308 | /** |
@@ -14,31 +14,31 @@ discard block |
||
14 | 14 | class WPInv_Invoice extends GetPaid_Data { |
15 | 15 | |
16 | 16 | /** |
17 | - * Which data store to load. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
17 | + * Which data store to load. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | 21 | protected $data_store_name = 'invoice'; |
22 | 22 | |
23 | 23 | /** |
24 | - * This is the name of this object type. |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
24 | + * This is the name of this object type. |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | 28 | protected $object_type = 'invoice'; |
29 | 29 | |
30 | 30 | /** |
31 | - * Item Data array. This is the core item data exposed in APIs. |
|
32 | - * |
|
33 | - * @since 1.0.19 |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $data = array( |
|
37 | - 'parent_id' => 0, |
|
38 | - 'customer_id' => 0, |
|
39 | - 'status' => 'wpi-pending', |
|
40 | - 'version' => '', |
|
41 | - 'date_created' => null, |
|
31 | + * Item Data array. This is the core item data exposed in APIs. |
|
32 | + * |
|
33 | + * @since 1.0.19 |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $data = array( |
|
37 | + 'parent_id' => 0, |
|
38 | + 'customer_id' => 0, |
|
39 | + 'status' => 'wpi-pending', |
|
40 | + 'version' => '', |
|
41 | + 'date_created' => null, |
|
42 | 42 | 'date_modified' => null, |
43 | 43 | 'due_date' => null, |
44 | 44 | 'completed_date' => null, |
@@ -61,17 +61,17 @@ discard block |
||
61 | 61 | 'state' => null, |
62 | 62 | 'zip' => null, |
63 | 63 | 'company' => null, |
64 | - 'company_id' => null, |
|
64 | + 'company_id' => null, |
|
65 | 65 | 'vat_number' => null, |
66 | 66 | 'vat_rate' => null, |
67 | 67 | 'address' => null, |
68 | 68 | 'address_confirmed' => false, |
69 | 69 | 'shipping' => null, |
70 | - 'subtotal' => 0, |
|
70 | + 'subtotal' => 0, |
|
71 | 71 | 'total_discount' => 0, |
72 | 72 | 'total_tax' => 0, |
73 | - 'total_fees' => 0, |
|
74 | - 'total' => 0, |
|
73 | + 'total_fees' => 0, |
|
74 | + 'total' => 0, |
|
75 | 75 | 'fees' => array(), |
76 | 76 | 'discounts' => array(), |
77 | 77 | 'taxes' => array(), |
@@ -83,23 +83,23 @@ discard block |
||
83 | 83 | 'transaction_id' => '', |
84 | 84 | 'currency' => '', |
85 | 85 | 'disable_taxes' => false, |
86 | - 'subscription_id' => null, |
|
87 | - 'remote_subscription_id' => null, |
|
86 | + 'subscription_id' => null, |
|
87 | + 'remote_subscription_id' => null, |
|
88 | 88 | 'is_anonymized' => false, |
89 | - 'is_viewed' => false, |
|
90 | - 'email_cc' => '', |
|
91 | - 'template' => 'quantity', // hours, amount only |
|
92 | - 'created_via' => null, |
|
89 | + 'is_viewed' => false, |
|
90 | + 'email_cc' => '', |
|
91 | + 'template' => 'quantity', // hours, amount only |
|
92 | + 'created_via' => null, |
|
93 | 93 | ); |
94 | 94 | |
95 | 95 | /** |
96 | - * Stores meta in cache for future reads. |
|
97 | - * |
|
98 | - * A group must be set to to enable caching. |
|
99 | - * |
|
100 | - * @var string |
|
101 | - */ |
|
102 | - protected $cache_group = 'getpaid_invoices'; |
|
96 | + * Stores meta in cache for future reads. |
|
97 | + * |
|
98 | + * A group must be set to to enable caching. |
|
99 | + * |
|
100 | + * @var string |
|
101 | + */ |
|
102 | + protected $cache_group = 'getpaid_invoices'; |
|
103 | 103 | |
104 | 104 | /** |
105 | 105 | * Stores a reference to the original WP_Post object |
@@ -113,121 +113,121 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @var int |
115 | 115 | */ |
116 | - protected $recurring_item = null; |
|
116 | + protected $recurring_item = null; |
|
117 | 117 | |
118 | - /** |
|
118 | + /** |
|
119 | 119 | * Stores an array of item totals. |
120 | - * |
|
121 | - * e.g $totals['discount'] = array( |
|
122 | - * 'initial' => 10, |
|
123 | - * 'recurring' => 10, |
|
124 | - * ) |
|
120 | + * |
|
121 | + * e.g $totals['discount'] = array( |
|
122 | + * 'initial' => 10, |
|
123 | + * 'recurring' => 10, |
|
124 | + * ) |
|
125 | 125 | * |
126 | 126 | * @var array |
127 | 127 | */ |
128 | - protected $totals = array(); |
|
128 | + protected $totals = array(); |
|
129 | 129 | |
130 | - /** |
|
130 | + /** |
|
131 | 131 | * Tax rate. |
132 | - * |
|
132 | + * |
|
133 | 133 | * @var float |
134 | 134 | */ |
135 | - protected $tax_rate = 0; |
|
135 | + protected $tax_rate = 0; |
|
136 | 136 | |
137 | - /** |
|
138 | - * Stores the status transition information. |
|
139 | - * |
|
140 | - * @since 1.0.19 |
|
141 | - * @var bool|array |
|
142 | - */ |
|
143 | - protected $status_transition = false; |
|
137 | + /** |
|
138 | + * Stores the status transition information. |
|
139 | + * |
|
140 | + * @since 1.0.19 |
|
141 | + * @var bool|array |
|
142 | + */ |
|
143 | + protected $status_transition = false; |
|
144 | 144 | |
145 | 145 | /** |
146 | - * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
147 | - * |
|
148 | - * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
149 | - */ |
|
146 | + * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
147 | + * |
|
148 | + * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
149 | + */ |
|
150 | 150 | public function __construct( $invoice = 0 ) { |
151 | 151 | |
152 | 152 | parent::__construct( $invoice ); |
153 | 153 | |
154 | - if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) { |
|
155 | - $this->set_id( (int) $invoice ); |
|
156 | - } elseif ( $invoice instanceof self ) { |
|
157 | - $this->set_id( $invoice->get_id() ); |
|
158 | - } elseif ( ! empty( $invoice->ID ) ) { |
|
159 | - $this->set_id( $invoice->ID ); |
|
160 | - } elseif ( is_array( $invoice ) ) { |
|
161 | - $this->set_props( $invoice ); |
|
162 | - |
|
163 | - if ( isset( $invoice['ID'] ) ) { |
|
164 | - $this->set_id( $invoice['ID'] ); |
|
165 | - } |
|
154 | + if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) { |
|
155 | + $this->set_id( (int) $invoice ); |
|
156 | + } elseif ( $invoice instanceof self ) { |
|
157 | + $this->set_id( $invoice->get_id() ); |
|
158 | + } elseif ( ! empty( $invoice->ID ) ) { |
|
159 | + $this->set_id( $invoice->ID ); |
|
160 | + } elseif ( is_array( $invoice ) ) { |
|
161 | + $this->set_props( $invoice ); |
|
162 | + |
|
163 | + if ( isset( $invoice['ID'] ) ) { |
|
164 | + $this->set_id( $invoice['ID'] ); |
|
165 | + } |
|
166 | 166 | } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
167 | - $this->set_id( $invoice_id ); |
|
168 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
169 | - $this->set_id( $invoice_id ); |
|
170 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
171 | - $this->set_id( $invoice_id ); |
|
172 | - } else { |
|
173 | - $this->set_object_read( true ); |
|
174 | - } |
|
167 | + $this->set_id( $invoice_id ); |
|
168 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
169 | + $this->set_id( $invoice_id ); |
|
170 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
171 | + $this->set_id( $invoice_id ); |
|
172 | + } else { |
|
173 | + $this->set_object_read( true ); |
|
174 | + } |
|
175 | 175 | |
176 | 176 | // Load the datastore. |
177 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
177 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
178 | 178 | |
179 | - if ( $this->get_id() > 0 ) { |
|
179 | + if ( $this->get_id() > 0 ) { |
|
180 | 180 | $this->post = get_post( $this->get_id() ); |
181 | 181 | $this->ID = $this->get_id(); |
182 | - $this->data_store->read( $this ); |
|
182 | + $this->data_store->read( $this ); |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
187 | - * Given an invoice key/number, it returns its id. |
|
188 | - * |
|
189 | - * |
|
190 | - * @static |
|
191 | - * @param string $value The invoice key or number |
|
192 | - * @param string $field Either key, transaction_id or number. |
|
193 | - * @since 1.0.15 |
|
194 | - * @return int |
|
195 | - */ |
|
196 | - public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
187 | + * Given an invoice key/number, it returns its id. |
|
188 | + * |
|
189 | + * |
|
190 | + * @static |
|
191 | + * @param string $value The invoice key or number |
|
192 | + * @param string $field Either key, transaction_id or number. |
|
193 | + * @since 1.0.15 |
|
194 | + * @return int |
|
195 | + */ |
|
196 | + public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
197 | 197 | global $wpdb; |
198 | 198 | |
199 | - // Trim the value. |
|
200 | - $value = trim( $value ); |
|
199 | + // Trim the value. |
|
200 | + $value = trim( $value ); |
|
201 | 201 | |
202 | - if ( empty( $value ) ) { |
|
203 | - return 0; |
|
204 | - } |
|
202 | + if ( empty( $value ) ) { |
|
203 | + return 0; |
|
204 | + } |
|
205 | 205 | |
206 | 206 | // Valid fields. |
207 | 207 | $fields = array( 'key', 'number', 'transaction_id' ); |
208 | 208 | |
209 | - // Ensure a field has been passed. |
|
210 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
211 | - return 0; |
|
212 | - } |
|
209 | + // Ensure a field has been passed. |
|
210 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
211 | + return 0; |
|
212 | + } |
|
213 | 213 | |
214 | - // Maybe retrieve from the cache. |
|
215 | - $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
216 | - if ( false !== $invoice_id ) { |
|
217 | - return $invoice_id; |
|
218 | - } |
|
214 | + // Maybe retrieve from the cache. |
|
215 | + $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
216 | + if ( false !== $invoice_id ) { |
|
217 | + return $invoice_id; |
|
218 | + } |
|
219 | 219 | |
220 | 220 | // Fetch from the db. |
221 | 221 | $table = $wpdb->prefix . 'getpaid_invoices'; |
222 | - $db_field = 'key' === $field ? 'invoice_key' : $field; |
|
222 | + $db_field = 'key' === $field ? 'invoice_key' : $field; |
|
223 | 223 | $invoice_id = (int) $wpdb->get_var( |
224 | 224 | $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$db_field`=%s LIMIT 1", $value ) |
225 | 225 | ); |
226 | 226 | |
227 | - // Update the cache with our data |
|
228 | - wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
227 | + // Update the cache with our data |
|
228 | + wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
229 | 229 | |
230 | - return $invoice_id; |
|
230 | + return $invoice_id; |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -253,83 +253,83 @@ discard block |
||
253 | 253 | */ |
254 | 254 | |
255 | 255 | /** |
256 | - * Get parent invoice ID. |
|
257 | - * |
|
258 | - * @since 1.0.19 |
|
259 | - * @param string $context View or edit context. |
|
260 | - * @return int |
|
261 | - */ |
|
262 | - public function get_parent_id( $context = 'view' ) { |
|
263 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
256 | + * Get parent invoice ID. |
|
257 | + * |
|
258 | + * @since 1.0.19 |
|
259 | + * @param string $context View or edit context. |
|
260 | + * @return int |
|
261 | + */ |
|
262 | + public function get_parent_id( $context = 'view' ) { |
|
263 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
267 | - * Get parent invoice. |
|
268 | - * |
|
269 | - * @since 1.0.19 |
|
270 | - * @return WPInv_Invoice |
|
271 | - */ |
|
267 | + * Get parent invoice. |
|
268 | + * |
|
269 | + * @since 1.0.19 |
|
270 | + * @return WPInv_Invoice |
|
271 | + */ |
|
272 | 272 | public function get_parent_payment() { |
273 | 273 | return new WPInv_Invoice( $this->get_parent_id() ); |
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
277 | - * Alias for self::get_parent_payment(). |
|
278 | - * |
|
279 | - * @since 1.0.19 |
|
280 | - * @return WPInv_Invoice |
|
281 | - */ |
|
277 | + * Alias for self::get_parent_payment(). |
|
278 | + * |
|
279 | + * @since 1.0.19 |
|
280 | + * @return WPInv_Invoice |
|
281 | + */ |
|
282 | 282 | public function get_parent() { |
283 | 283 | return $this->get_parent_payment(); |
284 | 284 | } |
285 | 285 | |
286 | 286 | /** |
287 | - * Get invoice status. |
|
288 | - * |
|
289 | - * @since 1.0.19 |
|
290 | - * @param string $context View or edit context. |
|
291 | - * @return string |
|
292 | - */ |
|
293 | - public function get_status( $context = 'view' ) { |
|
294 | - return $this->get_prop( 'status', $context ); |
|
295 | - } |
|
287 | + * Get invoice status. |
|
288 | + * |
|
289 | + * @since 1.0.19 |
|
290 | + * @param string $context View or edit context. |
|
291 | + * @return string |
|
292 | + */ |
|
293 | + public function get_status( $context = 'view' ) { |
|
294 | + return $this->get_prop( 'status', $context ); |
|
295 | + } |
|
296 | 296 | |
297 | - /** |
|
298 | - * Retrieves an array of possible invoice statuses. |
|
299 | - * |
|
300 | - * @since 1.0.19 |
|
301 | - * @return array |
|
302 | - */ |
|
303 | - public function get_all_statuses() { |
|
304 | - return wpinv_get_invoice_statuses( true, true, $this ); |
|
297 | + /** |
|
298 | + * Retrieves an array of possible invoice statuses. |
|
299 | + * |
|
300 | + * @since 1.0.19 |
|
301 | + * @return array |
|
302 | + */ |
|
303 | + public function get_all_statuses() { |
|
304 | + return wpinv_get_invoice_statuses( true, true, $this ); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
308 | - * Get invoice status nice name. |
|
309 | - * |
|
310 | - * @since 1.0.19 |
|
311 | - * @return string |
|
312 | - */ |
|
308 | + * Get invoice status nice name. |
|
309 | + * |
|
310 | + * @since 1.0.19 |
|
311 | + * @return string |
|
312 | + */ |
|
313 | 313 | public function get_status_nicename() { |
314 | - $statuses = $this->get_all_statuses(); |
|
314 | + $statuses = $this->get_all_statuses(); |
|
315 | 315 | |
316 | 316 | $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status(); |
317 | 317 | |
318 | 318 | return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this ); |
319 | 319 | } |
320 | 320 | |
321 | - /** |
|
322 | - * Retrieves the invoice status class |
|
323 | - * |
|
324 | - * @since 1.0.19 |
|
325 | - * @return string |
|
326 | - */ |
|
327 | - public function get_status_class() { |
|
328 | - $statuses = getpaid_get_invoice_status_classes(); |
|
329 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark text-white'; |
|
330 | - } |
|
321 | + /** |
|
322 | + * Retrieves the invoice status class |
|
323 | + * |
|
324 | + * @since 1.0.19 |
|
325 | + * @return string |
|
326 | + */ |
|
327 | + public function get_status_class() { |
|
328 | + $statuses = getpaid_get_invoice_status_classes(); |
|
329 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark text-white'; |
|
330 | + } |
|
331 | 331 | |
332 | - /** |
|
332 | + /** |
|
333 | 333 | * Retrieves the invoice status label html |
334 | 334 | * |
335 | 335 | * @since 1.0.0 |
@@ -337,261 +337,261 @@ discard block |
||
337 | 337 | */ |
338 | 338 | public function get_status_label_html() { |
339 | 339 | |
340 | - $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
341 | - $status = sanitize_html_class( $this->get_status() ); |
|
342 | - $class = esc_attr( $this->get_status_class() ); |
|
343 | - |
|
344 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Get plugin version when the invoice was created. |
|
349 | - * |
|
350 | - * @since 1.0.19 |
|
351 | - * @param string $context View or edit context. |
|
352 | - * @return string |
|
353 | - */ |
|
354 | - public function get_version( $context = 'view' ) { |
|
355 | - return $this->get_prop( 'version', $context ); |
|
356 | - } |
|
357 | - |
|
358 | - /** |
|
359 | - * @deprecated |
|
360 | - */ |
|
361 | - public function get_invoice_date( $format = true ) { |
|
362 | - $date = getpaid_format_date( $this->get_date_completed() ); |
|
363 | - $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
364 | - $formatted = getpaid_format_date( $date ); |
|
365 | - |
|
366 | - if ( $format ) { |
|
367 | - return $formatted; |
|
368 | - } |
|
369 | - |
|
370 | - return empty( $formatted ) ? '' : $date; |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Get date when the invoice was created. |
|
375 | - * |
|
376 | - * @since 1.0.19 |
|
377 | - * @param string $context View or edit context. |
|
378 | - * @return string |
|
379 | - */ |
|
380 | - public function get_date_created( $context = 'view' ) { |
|
381 | - return $this->get_prop( 'date_created', $context ); |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Alias for self::get_date_created(). |
|
386 | - * |
|
387 | - * @since 1.0.19 |
|
388 | - * @param string $context View or edit context. |
|
389 | - * @return string |
|
390 | - */ |
|
391 | - public function get_created_date( $context = 'view' ) { |
|
392 | - return $this->get_date_created( $context ); |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Get GMT date when the invoice was created. |
|
397 | - * |
|
398 | - * @since 1.0.19 |
|
399 | - * @param string $context View or edit context. |
|
400 | - * @return string |
|
401 | - */ |
|
402 | - public function get_date_created_gmt( $context = 'view' ) { |
|
340 | + $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
341 | + $status = sanitize_html_class( $this->get_status() ); |
|
342 | + $class = esc_attr( $this->get_status_class() ); |
|
343 | + |
|
344 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Get plugin version when the invoice was created. |
|
349 | + * |
|
350 | + * @since 1.0.19 |
|
351 | + * @param string $context View or edit context. |
|
352 | + * @return string |
|
353 | + */ |
|
354 | + public function get_version( $context = 'view' ) { |
|
355 | + return $this->get_prop( 'version', $context ); |
|
356 | + } |
|
357 | + |
|
358 | + /** |
|
359 | + * @deprecated |
|
360 | + */ |
|
361 | + public function get_invoice_date( $format = true ) { |
|
362 | + $date = getpaid_format_date( $this->get_date_completed() ); |
|
363 | + $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
364 | + $formatted = getpaid_format_date( $date ); |
|
365 | + |
|
366 | + if ( $format ) { |
|
367 | + return $formatted; |
|
368 | + } |
|
369 | + |
|
370 | + return empty( $formatted ) ? '' : $date; |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Get date when the invoice was created. |
|
375 | + * |
|
376 | + * @since 1.0.19 |
|
377 | + * @param string $context View or edit context. |
|
378 | + * @return string |
|
379 | + */ |
|
380 | + public function get_date_created( $context = 'view' ) { |
|
381 | + return $this->get_prop( 'date_created', $context ); |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Alias for self::get_date_created(). |
|
386 | + * |
|
387 | + * @since 1.0.19 |
|
388 | + * @param string $context View or edit context. |
|
389 | + * @return string |
|
390 | + */ |
|
391 | + public function get_created_date( $context = 'view' ) { |
|
392 | + return $this->get_date_created( $context ); |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Get GMT date when the invoice was created. |
|
397 | + * |
|
398 | + * @since 1.0.19 |
|
399 | + * @param string $context View or edit context. |
|
400 | + * @return string |
|
401 | + */ |
|
402 | + public function get_date_created_gmt( $context = 'view' ) { |
|
403 | 403 | $date = $this->get_date_created( $context ); |
404 | 404 | |
405 | 405 | if ( $date ) { |
406 | 406 | $date = get_gmt_from_date( $date ); |
407 | 407 | } |
408 | - return $date; |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * Get date when the invoice was last modified. |
|
413 | - * |
|
414 | - * @since 1.0.19 |
|
415 | - * @param string $context View or edit context. |
|
416 | - * @return string |
|
417 | - */ |
|
418 | - public function get_date_modified( $context = 'view' ) { |
|
419 | - return $this->get_prop( 'date_modified', $context ); |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Alias for self::get_date_modified(). |
|
424 | - * |
|
425 | - * @since 1.0.19 |
|
426 | - * @param string $context View or edit context. |
|
427 | - * @return string |
|
428 | - */ |
|
429 | - public function get_modified_date( $context = 'view' ) { |
|
430 | - return $this->get_date_modified( $context ); |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * Get GMT date when the invoice was last modified. |
|
435 | - * |
|
436 | - * @since 1.0.19 |
|
437 | - * @param string $context View or edit context. |
|
438 | - * @return string |
|
439 | - */ |
|
440 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
408 | + return $date; |
|
409 | + } |
|
410 | + |
|
411 | + /** |
|
412 | + * Get date when the invoice was last modified. |
|
413 | + * |
|
414 | + * @since 1.0.19 |
|
415 | + * @param string $context View or edit context. |
|
416 | + * @return string |
|
417 | + */ |
|
418 | + public function get_date_modified( $context = 'view' ) { |
|
419 | + return $this->get_prop( 'date_modified', $context ); |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Alias for self::get_date_modified(). |
|
424 | + * |
|
425 | + * @since 1.0.19 |
|
426 | + * @param string $context View or edit context. |
|
427 | + * @return string |
|
428 | + */ |
|
429 | + public function get_modified_date( $context = 'view' ) { |
|
430 | + return $this->get_date_modified( $context ); |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * Get GMT date when the invoice was last modified. |
|
435 | + * |
|
436 | + * @since 1.0.19 |
|
437 | + * @param string $context View or edit context. |
|
438 | + * @return string |
|
439 | + */ |
|
440 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
441 | 441 | $date = $this->get_date_modified( $context ); |
442 | 442 | |
443 | 443 | if ( $date ) { |
444 | 444 | $date = get_gmt_from_date( $date ); |
445 | 445 | } |
446 | - return $date; |
|
446 | + return $date; |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
450 | - * Get the invoice due date. |
|
451 | - * |
|
452 | - * @since 1.0.19 |
|
453 | - * @param string $context View or edit context. |
|
454 | - * @return string |
|
455 | - */ |
|
456 | - public function get_due_date( $context = 'view' ) { |
|
457 | - return $this->get_prop( 'due_date', $context ); |
|
450 | + * Get the invoice due date. |
|
451 | + * |
|
452 | + * @since 1.0.19 |
|
453 | + * @param string $context View or edit context. |
|
454 | + * @return string |
|
455 | + */ |
|
456 | + public function get_due_date( $context = 'view' ) { |
|
457 | + return $this->get_prop( 'due_date', $context ); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | /** |
461 | - * Alias for self::get_due_date(). |
|
462 | - * |
|
463 | - * @since 1.0.19 |
|
464 | - * @param string $context View or edit context. |
|
465 | - * @return string |
|
466 | - */ |
|
467 | - public function get_date_due( $context = 'view' ) { |
|
468 | - return $this->get_due_date( $context ); |
|
461 | + * Alias for self::get_due_date(). |
|
462 | + * |
|
463 | + * @since 1.0.19 |
|
464 | + * @param string $context View or edit context. |
|
465 | + * @return string |
|
466 | + */ |
|
467 | + public function get_date_due( $context = 'view' ) { |
|
468 | + return $this->get_due_date( $context ); |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | /** |
472 | - * Get the invoice GMT due date. |
|
473 | - * |
|
474 | - * @since 1.0.19 |
|
475 | - * @param string $context View or edit context. |
|
476 | - * @return string |
|
477 | - */ |
|
478 | - public function get_due_date_gmt( $context = 'view' ) { |
|
472 | + * Get the invoice GMT due date. |
|
473 | + * |
|
474 | + * @since 1.0.19 |
|
475 | + * @param string $context View or edit context. |
|
476 | + * @return string |
|
477 | + */ |
|
478 | + public function get_due_date_gmt( $context = 'view' ) { |
|
479 | 479 | $date = $this->get_due_date( $context ); |
480 | 480 | |
481 | 481 | if ( $date ) { |
482 | 482 | $date = get_gmt_from_date( $date ); |
483 | 483 | } |
484 | - return $date; |
|
484 | + return $date; |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
488 | - * Alias for self::get_due_date_gmt(). |
|
489 | - * |
|
490 | - * @since 1.0.19 |
|
491 | - * @param string $context View or edit context. |
|
492 | - * @return string |
|
493 | - */ |
|
494 | - public function get_gmt_date_due( $context = 'view' ) { |
|
495 | - return $this->get_due_date_gmt( $context ); |
|
488 | + * Alias for self::get_due_date_gmt(). |
|
489 | + * |
|
490 | + * @since 1.0.19 |
|
491 | + * @param string $context View or edit context. |
|
492 | + * @return string |
|
493 | + */ |
|
494 | + public function get_gmt_date_due( $context = 'view' ) { |
|
495 | + return $this->get_due_date_gmt( $context ); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | /** |
499 | - * Get date when the invoice was completed. |
|
500 | - * |
|
501 | - * @since 1.0.19 |
|
502 | - * @param string $context View or edit context. |
|
503 | - * @return string |
|
504 | - */ |
|
505 | - public function get_completed_date( $context = 'view' ) { |
|
506 | - return $this->get_prop( 'completed_date', $context ); |
|
499 | + * Get date when the invoice was completed. |
|
500 | + * |
|
501 | + * @since 1.0.19 |
|
502 | + * @param string $context View or edit context. |
|
503 | + * @return string |
|
504 | + */ |
|
505 | + public function get_completed_date( $context = 'view' ) { |
|
506 | + return $this->get_prop( 'completed_date', $context ); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | /** |
510 | - * Alias for self::get_completed_date(). |
|
511 | - * |
|
512 | - * @since 1.0.19 |
|
513 | - * @param string $context View or edit context. |
|
514 | - * @return string |
|
515 | - */ |
|
516 | - public function get_date_completed( $context = 'view' ) { |
|
517 | - return $this->get_completed_date( $context ); |
|
510 | + * Alias for self::get_completed_date(). |
|
511 | + * |
|
512 | + * @since 1.0.19 |
|
513 | + * @param string $context View or edit context. |
|
514 | + * @return string |
|
515 | + */ |
|
516 | + public function get_date_completed( $context = 'view' ) { |
|
517 | + return $this->get_completed_date( $context ); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | /** |
521 | - * Get GMT date when the invoice was was completed. |
|
522 | - * |
|
523 | - * @since 1.0.19 |
|
524 | - * @param string $context View or edit context. |
|
525 | - * @return string |
|
526 | - */ |
|
527 | - public function get_completed_date_gmt( $context = 'view' ) { |
|
521 | + * Get GMT date when the invoice was was completed. |
|
522 | + * |
|
523 | + * @since 1.0.19 |
|
524 | + * @param string $context View or edit context. |
|
525 | + * @return string |
|
526 | + */ |
|
527 | + public function get_completed_date_gmt( $context = 'view' ) { |
|
528 | 528 | $date = $this->get_completed_date( $context ); |
529 | 529 | |
530 | 530 | if ( $date ) { |
531 | 531 | $date = get_gmt_from_date( $date ); |
532 | 532 | } |
533 | - return $date; |
|
533 | + return $date; |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
537 | - * Alias for self::get_completed_date_gmt(). |
|
538 | - * |
|
539 | - * @since 1.0.19 |
|
540 | - * @param string $context View or edit context. |
|
541 | - * @return string |
|
542 | - */ |
|
543 | - public function get_gmt_completed_date( $context = 'view' ) { |
|
544 | - return $this->get_completed_date_gmt( $context ); |
|
537 | + * Alias for self::get_completed_date_gmt(). |
|
538 | + * |
|
539 | + * @since 1.0.19 |
|
540 | + * @param string $context View or edit context. |
|
541 | + * @return string |
|
542 | + */ |
|
543 | + public function get_gmt_completed_date( $context = 'view' ) { |
|
544 | + return $this->get_completed_date_gmt( $context ); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
548 | - * Get the invoice number. |
|
549 | - * |
|
550 | - * @since 1.0.19 |
|
551 | - * @param string $context View or edit context. |
|
552 | - * @return string |
|
553 | - */ |
|
554 | - public function get_number( $context = 'view' ) { |
|
555 | - $number = $this->get_prop( 'number', $context ); |
|
548 | + * Get the invoice number. |
|
549 | + * |
|
550 | + * @since 1.0.19 |
|
551 | + * @param string $context View or edit context. |
|
552 | + * @return string |
|
553 | + */ |
|
554 | + public function get_number( $context = 'view' ) { |
|
555 | + $number = $this->get_prop( 'number', $context ); |
|
556 | 556 | |
557 | - if ( empty( $number ) ) { |
|
558 | - $number = $this->generate_number(); |
|
559 | - $this->set_number( $this->generate_number() ); |
|
560 | - } |
|
557 | + if ( empty( $number ) ) { |
|
558 | + $number = $this->generate_number(); |
|
559 | + $this->set_number( $this->generate_number() ); |
|
560 | + } |
|
561 | 561 | |
562 | - return $number; |
|
562 | + return $number; |
|
563 | 563 | } |
564 | 564 | |
565 | - /** |
|
566 | - * Set the invoice number. |
|
567 | - * |
|
568 | - * @since 1.0.19 |
|
569 | - */ |
|
570 | - public function maybe_set_number() { |
|
565 | + /** |
|
566 | + * Set the invoice number. |
|
567 | + * |
|
568 | + * @since 1.0.19 |
|
569 | + */ |
|
570 | + public function maybe_set_number() { |
|
571 | 571 | $number = $this->get_number(); |
572 | 572 | |
573 | 573 | if ( empty( $number ) || $this->get_id() == $number ) { |
574 | - $this->set_number( $this->generate_number() ); |
|
574 | + $this->set_number( $this->generate_number() ); |
|
575 | 575 | } |
576 | - } |
|
576 | + } |
|
577 | 577 | |
578 | 578 | /** |
579 | - * Get the invoice key. |
|
580 | - * |
|
581 | - * @since 1.0.19 |
|
582 | - * @param string $context View or edit context. |
|
583 | - * @return string |
|
584 | - */ |
|
585 | - public function get_key( $context = 'view' ) { |
|
579 | + * Get the invoice key. |
|
580 | + * |
|
581 | + * @since 1.0.19 |
|
582 | + * @param string $context View or edit context. |
|
583 | + * @return string |
|
584 | + */ |
|
585 | + public function get_key( $context = 'view' ) { |
|
586 | 586 | return $this->get_prop( 'key', $context ); |
587 | - } |
|
588 | - |
|
589 | - /** |
|
590 | - * Set the invoice key. |
|
591 | - * |
|
592 | - * @since 1.0.19 |
|
593 | - */ |
|
594 | - public function maybe_set_key() { |
|
587 | + } |
|
588 | + |
|
589 | + /** |
|
590 | + * Set the invoice key. |
|
591 | + * |
|
592 | + * @since 1.0.19 |
|
593 | + */ |
|
594 | + public function maybe_set_key() { |
|
595 | 595 | $key = $this->get_key(); |
596 | 596 | |
597 | 597 | if ( empty( $key ) ) { |
@@ -601,140 +601,140 @@ discard block |
||
601 | 601 | } |
602 | 602 | |
603 | 603 | /** |
604 | - * Get the invoice type. |
|
605 | - * |
|
606 | - * @since 1.0.19 |
|
607 | - * @param string $context View or edit context. |
|
608 | - * @return string |
|
609 | - */ |
|
610 | - public function get_type( $context = 'view' ) { |
|
604 | + * Get the invoice type. |
|
605 | + * |
|
606 | + * @since 1.0.19 |
|
607 | + * @param string $context View or edit context. |
|
608 | + * @return string |
|
609 | + */ |
|
610 | + public function get_type( $context = 'view' ) { |
|
611 | 611 | return $this->get_prop( 'type', $context ); |
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * Returns the post type name. |
|
616 | - * |
|
617 | - * @since 1.0.19 |
|
618 | - * @return string |
|
619 | - */ |
|
620 | - public function get_invoice_quote_type() { |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * Returns the post type name. |
|
616 | + * |
|
617 | + * @since 1.0.19 |
|
618 | + * @return string |
|
619 | + */ |
|
620 | + public function get_invoice_quote_type() { |
|
621 | 621 | return getpaid_get_post_type_label( $this->get_post_type(), false ); |
622 | 622 | } |
623 | 623 | |
624 | 624 | /** |
625 | - * Get the invoice post type label. |
|
626 | - * |
|
627 | - * @since 1.0.19 |
|
628 | - * @param string $context View or edit context. |
|
629 | - * @return string |
|
630 | - */ |
|
631 | - public function get_label( $context = 'view' ) { |
|
625 | + * Get the invoice post type label. |
|
626 | + * |
|
627 | + * @since 1.0.19 |
|
628 | + * @param string $context View or edit context. |
|
629 | + * @return string |
|
630 | + */ |
|
631 | + public function get_label( $context = 'view' ) { |
|
632 | 632 | return getpaid_get_post_type_label( $this->get_post_type( $context ), false ); |
633 | - } |
|
634 | - |
|
635 | - /** |
|
636 | - * Get the invoice post type. |
|
637 | - * |
|
638 | - * @since 1.0.19 |
|
639 | - * @param string $context View or edit context. |
|
640 | - * @return string |
|
641 | - */ |
|
642 | - public function get_post_type( $context = 'view' ) { |
|
633 | + } |
|
634 | + |
|
635 | + /** |
|
636 | + * Get the invoice post type. |
|
637 | + * |
|
638 | + * @since 1.0.19 |
|
639 | + * @param string $context View or edit context. |
|
640 | + * @return string |
|
641 | + */ |
|
642 | + public function get_post_type( $context = 'view' ) { |
|
643 | 643 | return $this->get_prop( 'post_type', $context ); |
644 | 644 | } |
645 | 645 | |
646 | 646 | /** |
647 | - * Get the invoice mode. |
|
648 | - * |
|
649 | - * @since 1.0.19 |
|
650 | - * @param string $context View or edit context. |
|
651 | - * @return string |
|
652 | - */ |
|
653 | - public function get_mode( $context = 'view' ) { |
|
647 | + * Get the invoice mode. |
|
648 | + * |
|
649 | + * @since 1.0.19 |
|
650 | + * @param string $context View or edit context. |
|
651 | + * @return string |
|
652 | + */ |
|
653 | + public function get_mode( $context = 'view' ) { |
|
654 | 654 | return $this->get_prop( 'mode', $context ); |
655 | 655 | } |
656 | 656 | |
657 | 657 | /** |
658 | - * Get the invoice path. |
|
659 | - * |
|
660 | - * @since 1.0.19 |
|
661 | - * @param string $context View or edit context. |
|
662 | - * @return string |
|
663 | - */ |
|
664 | - public function get_path( $context = 'view' ) { |
|
658 | + * Get the invoice path. |
|
659 | + * |
|
660 | + * @since 1.0.19 |
|
661 | + * @param string $context View or edit context. |
|
662 | + * @return string |
|
663 | + */ |
|
664 | + public function get_path( $context = 'view' ) { |
|
665 | 665 | $path = $this->get_prop( 'path', $context ); |
666 | - $prefix = $this->get_type(); |
|
666 | + $prefix = $this->get_type(); |
|
667 | 667 | |
668 | - if ( 0 !== strpos( $path, $prefix ) ) { |
|
669 | - $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
670 | - $this->set_path( $path ); |
|
671 | - } |
|
668 | + if ( 0 !== strpos( $path, $prefix ) ) { |
|
669 | + $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
670 | + $this->set_path( $path ); |
|
671 | + } |
|
672 | 672 | |
673 | - return $path; |
|
673 | + return $path; |
|
674 | 674 | } |
675 | 675 | |
676 | 676 | /** |
677 | - * Get the invoice name/title. |
|
678 | - * |
|
679 | - * @since 1.0.19 |
|
680 | - * @param string $context View or edit context. |
|
681 | - * @return string |
|
682 | - */ |
|
683 | - public function get_name( $context = 'view' ) { |
|
677 | + * Get the invoice name/title. |
|
678 | + * |
|
679 | + * @since 1.0.19 |
|
680 | + * @param string $context View or edit context. |
|
681 | + * @return string |
|
682 | + */ |
|
683 | + public function get_name( $context = 'view' ) { |
|
684 | 684 | return $this->get_prop( 'title', $context ); |
685 | 685 | } |
686 | 686 | |
687 | 687 | /** |
688 | - * Alias of self::get_name(). |
|
689 | - * |
|
690 | - * @since 1.0.19 |
|
691 | - * @param string $context View or edit context. |
|
692 | - * @return string |
|
693 | - */ |
|
694 | - public function get_title( $context = 'view' ) { |
|
695 | - return $this->get_name( $context ); |
|
688 | + * Alias of self::get_name(). |
|
689 | + * |
|
690 | + * @since 1.0.19 |
|
691 | + * @param string $context View or edit context. |
|
692 | + * @return string |
|
693 | + */ |
|
694 | + public function get_title( $context = 'view' ) { |
|
695 | + return $this->get_name( $context ); |
|
696 | 696 | } |
697 | 697 | |
698 | 698 | /** |
699 | - * Get the invoice description. |
|
700 | - * |
|
701 | - * @since 1.0.19 |
|
702 | - * @param string $context View or edit context. |
|
703 | - * @return string |
|
704 | - */ |
|
705 | - public function get_description( $context = 'view' ) { |
|
706 | - return $this->get_prop( 'description', $context ); |
|
699 | + * Get the invoice description. |
|
700 | + * |
|
701 | + * @since 1.0.19 |
|
702 | + * @param string $context View or edit context. |
|
703 | + * @return string |
|
704 | + */ |
|
705 | + public function get_description( $context = 'view' ) { |
|
706 | + return $this->get_prop( 'description', $context ); |
|
707 | 707 | } |
708 | 708 | |
709 | 709 | /** |
710 | - * Alias of self::get_description(). |
|
711 | - * |
|
712 | - * @since 1.0.19 |
|
713 | - * @param string $context View or edit context. |
|
714 | - * @return string |
|
715 | - */ |
|
716 | - public function get_excerpt( $context = 'view' ) { |
|
717 | - return $this->get_description( $context ); |
|
710 | + * Alias of self::get_description(). |
|
711 | + * |
|
712 | + * @since 1.0.19 |
|
713 | + * @param string $context View or edit context. |
|
714 | + * @return string |
|
715 | + */ |
|
716 | + public function get_excerpt( $context = 'view' ) { |
|
717 | + return $this->get_description( $context ); |
|
718 | 718 | } |
719 | 719 | |
720 | 720 | /** |
721 | - * Alias of self::get_description(). |
|
722 | - * |
|
723 | - * @since 1.0.19 |
|
724 | - * @param string $context View or edit context. |
|
725 | - * @return string |
|
726 | - */ |
|
727 | - public function get_summary( $context = 'view' ) { |
|
728 | - return $this->get_description( $context ); |
|
721 | + * Alias of self::get_description(). |
|
722 | + * |
|
723 | + * @since 1.0.19 |
|
724 | + * @param string $context View or edit context. |
|
725 | + * @return string |
|
726 | + */ |
|
727 | + public function get_summary( $context = 'view' ) { |
|
728 | + return $this->get_description( $context ); |
|
729 | 729 | } |
730 | 730 | |
731 | 731 | /** |
732 | - * Returns the user info. |
|
733 | - * |
|
734 | - * @since 1.0.19 |
|
732 | + * Returns the user info. |
|
733 | + * |
|
734 | + * @since 1.0.19 |
|
735 | 735 | * @param string $context View or edit context. |
736 | - * @return array |
|
737 | - */ |
|
736 | + * @return array |
|
737 | + */ |
|
738 | 738 | public function get_user_info( $context = 'view' ) { |
739 | 739 | |
740 | 740 | $user_info = array( |
@@ -749,682 +749,682 @@ discard block |
||
749 | 749 | 'state' => $this->get_state( $context ), |
750 | 750 | 'zip' => $this->get_zip( $context ), |
751 | 751 | 'company' => $this->get_company( $context ), |
752 | - 'company_id' => $this->get_company_id( $context ), |
|
752 | + 'company_id' => $this->get_company_id( $context ), |
|
753 | 753 | 'vat_number' => $this->get_vat_number( $context ), |
754 | 754 | 'discount' => $this->get_discount_code( $context ), |
755 | - ); |
|
755 | + ); |
|
756 | 756 | |
757 | - return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
757 | + return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
758 | 758 | } |
759 | 759 | |
760 | 760 | /** |
761 | - * Get the user id. |
|
762 | - * |
|
763 | - * @since 1.0.19 |
|
764 | - * @param string $context View or edit context. |
|
765 | - * @return int |
|
766 | - */ |
|
767 | - public function get_author( $context = 'view' ) { |
|
768 | - return (int) $this->get_prop( 'author', $context ); |
|
761 | + * Get the user id. |
|
762 | + * |
|
763 | + * @since 1.0.19 |
|
764 | + * @param string $context View or edit context. |
|
765 | + * @return int |
|
766 | + */ |
|
767 | + public function get_author( $context = 'view' ) { |
|
768 | + return (int) $this->get_prop( 'author', $context ); |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | /** |
772 | - * Alias of self::get_author(). |
|
773 | - * |
|
774 | - * @since 1.0.19 |
|
775 | - * @param string $context View or edit context. |
|
776 | - * @return int |
|
777 | - */ |
|
778 | - public function get_user_id( $context = 'view' ) { |
|
779 | - return $this->get_author( $context ); |
|
772 | + * Alias of self::get_author(). |
|
773 | + * |
|
774 | + * @since 1.0.19 |
|
775 | + * @param string $context View or edit context. |
|
776 | + * @return int |
|
777 | + */ |
|
778 | + public function get_user_id( $context = 'view' ) { |
|
779 | + return $this->get_author( $context ); |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | /** |
783 | - * Get customer ID. |
|
784 | - * |
|
785 | - * @since 1.0.19 |
|
786 | - * @param string $context View or edit context. |
|
787 | - * @return int |
|
788 | - */ |
|
789 | - public function get_customer_id( $context = 'view' ) { |
|
790 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
783 | + * Get customer ID. |
|
784 | + * |
|
785 | + * @since 1.0.19 |
|
786 | + * @param string $context View or edit context. |
|
787 | + * @return int |
|
788 | + */ |
|
789 | + public function get_customer_id( $context = 'view' ) { |
|
790 | + return (int) $this->get_prop( 'customer_id', $context ); |
|
791 | 791 | } |
792 | 792 | |
793 | 793 | /** |
794 | - * Get the customer's ip. |
|
795 | - * |
|
796 | - * @since 1.0.19 |
|
797 | - * @param string $context View or edit context. |
|
798 | - * @return string |
|
799 | - */ |
|
800 | - public function get_ip( $context = 'view' ) { |
|
801 | - return $this->get_prop( 'user_ip', $context ); |
|
794 | + * Get the customer's ip. |
|
795 | + * |
|
796 | + * @since 1.0.19 |
|
797 | + * @param string $context View or edit context. |
|
798 | + * @return string |
|
799 | + */ |
|
800 | + public function get_ip( $context = 'view' ) { |
|
801 | + return $this->get_prop( 'user_ip', $context ); |
|
802 | 802 | } |
803 | 803 | |
804 | 804 | /** |
805 | - * Alias of self::get_ip(). |
|
806 | - * |
|
807 | - * @since 1.0.19 |
|
808 | - * @param string $context View or edit context. |
|
809 | - * @return string |
|
810 | - */ |
|
811 | - public function get_user_ip( $context = 'view' ) { |
|
812 | - return $this->get_ip( $context ); |
|
805 | + * Alias of self::get_ip(). |
|
806 | + * |
|
807 | + * @since 1.0.19 |
|
808 | + * @param string $context View or edit context. |
|
809 | + * @return string |
|
810 | + */ |
|
811 | + public function get_user_ip( $context = 'view' ) { |
|
812 | + return $this->get_ip( $context ); |
|
813 | 813 | } |
814 | 814 | |
815 | 815 | /** |
816 | - * Alias of self::get_ip(). |
|
817 | - * |
|
818 | - * @since 1.0.19 |
|
819 | - * @param string $context View or edit context. |
|
820 | - * @return string |
|
821 | - */ |
|
822 | - public function get_customer_ip( $context = 'view' ) { |
|
823 | - return $this->get_ip( $context ); |
|
816 | + * Alias of self::get_ip(). |
|
817 | + * |
|
818 | + * @since 1.0.19 |
|
819 | + * @param string $context View or edit context. |
|
820 | + * @return string |
|
821 | + */ |
|
822 | + public function get_customer_ip( $context = 'view' ) { |
|
823 | + return $this->get_ip( $context ); |
|
824 | 824 | } |
825 | 825 | |
826 | 826 | /** |
827 | - * Get the customer's first name. |
|
828 | - * |
|
829 | - * @since 1.0.19 |
|
830 | - * @param string $context View or edit context. |
|
831 | - * @return string |
|
832 | - */ |
|
833 | - public function get_first_name( $context = 'view' ) { |
|
834 | - return $this->get_prop( 'first_name', $context ); |
|
827 | + * Get the customer's first name. |
|
828 | + * |
|
829 | + * @since 1.0.19 |
|
830 | + * @param string $context View or edit context. |
|
831 | + * @return string |
|
832 | + */ |
|
833 | + public function get_first_name( $context = 'view' ) { |
|
834 | + return $this->get_prop( 'first_name', $context ); |
|
835 | 835 | } |
836 | 836 | |
837 | 837 | /** |
838 | - * Alias of self::get_first_name(). |
|
839 | - * |
|
840 | - * @since 1.0.19 |
|
841 | - * @param string $context View or edit context. |
|
842 | - * @return string |
|
843 | - */ |
|
844 | - public function get_user_first_name( $context = 'view' ) { |
|
845 | - return $this->get_first_name( $context ); |
|
838 | + * Alias of self::get_first_name(). |
|
839 | + * |
|
840 | + * @since 1.0.19 |
|
841 | + * @param string $context View or edit context. |
|
842 | + * @return string |
|
843 | + */ |
|
844 | + public function get_user_first_name( $context = 'view' ) { |
|
845 | + return $this->get_first_name( $context ); |
|
846 | 846 | } |
847 | 847 | |
848 | 848 | /** |
849 | - * Alias of self::get_first_name(). |
|
850 | - * |
|
851 | - * @since 1.0.19 |
|
852 | - * @param string $context View or edit context. |
|
853 | - * @return string |
|
854 | - */ |
|
855 | - public function get_customer_first_name( $context = 'view' ) { |
|
856 | - return $this->get_first_name( $context ); |
|
849 | + * Alias of self::get_first_name(). |
|
850 | + * |
|
851 | + * @since 1.0.19 |
|
852 | + * @param string $context View or edit context. |
|
853 | + * @return string |
|
854 | + */ |
|
855 | + public function get_customer_first_name( $context = 'view' ) { |
|
856 | + return $this->get_first_name( $context ); |
|
857 | 857 | } |
858 | 858 | |
859 | 859 | /** |
860 | - * Get the customer's last name. |
|
861 | - * |
|
862 | - * @since 1.0.19 |
|
863 | - * @param string $context View or edit context. |
|
864 | - * @return string |
|
865 | - */ |
|
866 | - public function get_last_name( $context = 'view' ) { |
|
867 | - return $this->get_prop( 'last_name', $context ); |
|
860 | + * Get the customer's last name. |
|
861 | + * |
|
862 | + * @since 1.0.19 |
|
863 | + * @param string $context View or edit context. |
|
864 | + * @return string |
|
865 | + */ |
|
866 | + public function get_last_name( $context = 'view' ) { |
|
867 | + return $this->get_prop( 'last_name', $context ); |
|
868 | 868 | } |
869 | 869 | |
870 | 870 | /** |
871 | - * Alias of self::get_last_name(). |
|
872 | - * |
|
873 | - * @since 1.0.19 |
|
874 | - * @param string $context View or edit context. |
|
875 | - * @return string |
|
876 | - */ |
|
877 | - public function get_user_last_name( $context = 'view' ) { |
|
878 | - return $this->get_last_name( $context ); |
|
871 | + * Alias of self::get_last_name(). |
|
872 | + * |
|
873 | + * @since 1.0.19 |
|
874 | + * @param string $context View or edit context. |
|
875 | + * @return string |
|
876 | + */ |
|
877 | + public function get_user_last_name( $context = 'view' ) { |
|
878 | + return $this->get_last_name( $context ); |
|
879 | 879 | } |
880 | 880 | |
881 | 881 | /** |
882 | - * Alias of self::get_last_name(). |
|
883 | - * |
|
884 | - * @since 1.0.19 |
|
885 | - * @param string $context View or edit context. |
|
886 | - * @return string |
|
887 | - */ |
|
888 | - public function get_customer_last_name( $context = 'view' ) { |
|
889 | - return $this->get_last_name( $context ); |
|
890 | - } |
|
882 | + * Alias of self::get_last_name(). |
|
883 | + * |
|
884 | + * @since 1.0.19 |
|
885 | + * @param string $context View or edit context. |
|
886 | + * @return string |
|
887 | + */ |
|
888 | + public function get_customer_last_name( $context = 'view' ) { |
|
889 | + return $this->get_last_name( $context ); |
|
890 | + } |
|
891 | 891 | |
892 | 892 | /** |
893 | - * Get the customer's full name. |
|
894 | - * |
|
895 | - * @since 1.0.19 |
|
896 | - * @param string $context View or edit context. |
|
897 | - * @return string |
|
898 | - */ |
|
899 | - public function get_full_name( $context = 'view' ) { |
|
900 | - $name = trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
893 | + * Get the customer's full name. |
|
894 | + * |
|
895 | + * @since 1.0.19 |
|
896 | + * @param string $context View or edit context. |
|
897 | + * @return string |
|
898 | + */ |
|
899 | + public function get_full_name( $context = 'view' ) { |
|
900 | + $name = trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
901 | 901 | |
902 | - if ( ! $name ) { |
|
903 | - $user = get_userdata( $this->get_author( $context ) ); |
|
902 | + if ( ! $name ) { |
|
903 | + $user = get_userdata( $this->get_author( $context ) ); |
|
904 | 904 | |
905 | - if ( $user ) { |
|
906 | - $name = $user->display_name; |
|
907 | - } |
|
908 | - } |
|
905 | + if ( $user ) { |
|
906 | + $name = $user->display_name; |
|
907 | + } |
|
908 | + } |
|
909 | 909 | |
910 | - if ( ! $name ) { |
|
911 | - $name = $this->get_email( $context ); |
|
912 | - } |
|
910 | + if ( ! $name ) { |
|
911 | + $name = $this->get_email( $context ); |
|
912 | + } |
|
913 | 913 | |
914 | - return apply_filters( 'wpinv_invoice_user_full_name', $name, $this ); |
|
914 | + return apply_filters( 'wpinv_invoice_user_full_name', $name, $this ); |
|
915 | 915 | } |
916 | 916 | |
917 | 917 | /** |
918 | - * Alias of self::get_full_name(). |
|
919 | - * |
|
920 | - * @since 1.0.19 |
|
921 | - * @param string $context View or edit context. |
|
922 | - * @return string |
|
923 | - */ |
|
924 | - public function get_user_full_name( $context = 'view' ) { |
|
925 | - return $this->get_full_name( $context ); |
|
918 | + * Alias of self::get_full_name(). |
|
919 | + * |
|
920 | + * @since 1.0.19 |
|
921 | + * @param string $context View or edit context. |
|
922 | + * @return string |
|
923 | + */ |
|
924 | + public function get_user_full_name( $context = 'view' ) { |
|
925 | + return $this->get_full_name( $context ); |
|
926 | 926 | } |
927 | 927 | |
928 | 928 | /** |
929 | - * Alias of self::get_full_name(). |
|
930 | - * |
|
931 | - * @since 1.0.19 |
|
932 | - * @param string $context View or edit context. |
|
933 | - * @return string |
|
934 | - */ |
|
935 | - public function get_customer_full_name( $context = 'view' ) { |
|
936 | - return $this->get_full_name( $context ); |
|
929 | + * Alias of self::get_full_name(). |
|
930 | + * |
|
931 | + * @since 1.0.19 |
|
932 | + * @param string $context View or edit context. |
|
933 | + * @return string |
|
934 | + */ |
|
935 | + public function get_customer_full_name( $context = 'view' ) { |
|
936 | + return $this->get_full_name( $context ); |
|
937 | 937 | } |
938 | 938 | |
939 | 939 | /** |
940 | - * Get the customer's phone number. |
|
941 | - * |
|
942 | - * @since 1.0.19 |
|
943 | - * @param string $context View or edit context. |
|
944 | - * @return string |
|
945 | - */ |
|
946 | - public function get_phone( $context = 'view' ) { |
|
947 | - return $this->get_prop( 'phone', $context ); |
|
940 | + * Get the customer's phone number. |
|
941 | + * |
|
942 | + * @since 1.0.19 |
|
943 | + * @param string $context View or edit context. |
|
944 | + * @return string |
|
945 | + */ |
|
946 | + public function get_phone( $context = 'view' ) { |
|
947 | + return $this->get_prop( 'phone', $context ); |
|
948 | 948 | } |
949 | 949 | |
950 | 950 | /** |
951 | - * Alias of self::get_phone(). |
|
952 | - * |
|
953 | - * @since 1.0.19 |
|
954 | - * @param string $context View or edit context. |
|
955 | - * @return string |
|
956 | - */ |
|
957 | - public function get_phone_number( $context = 'view' ) { |
|
958 | - return $this->get_phone( $context ); |
|
951 | + * Alias of self::get_phone(). |
|
952 | + * |
|
953 | + * @since 1.0.19 |
|
954 | + * @param string $context View or edit context. |
|
955 | + * @return string |
|
956 | + */ |
|
957 | + public function get_phone_number( $context = 'view' ) { |
|
958 | + return $this->get_phone( $context ); |
|
959 | 959 | } |
960 | 960 | |
961 | 961 | /** |
962 | - * Alias of self::get_phone(). |
|
963 | - * |
|
964 | - * @since 1.0.19 |
|
965 | - * @param string $context View or edit context. |
|
966 | - * @return string |
|
967 | - */ |
|
968 | - public function get_user_phone( $context = 'view' ) { |
|
969 | - return $this->get_phone( $context ); |
|
962 | + * Alias of self::get_phone(). |
|
963 | + * |
|
964 | + * @since 1.0.19 |
|
965 | + * @param string $context View or edit context. |
|
966 | + * @return string |
|
967 | + */ |
|
968 | + public function get_user_phone( $context = 'view' ) { |
|
969 | + return $this->get_phone( $context ); |
|
970 | 970 | } |
971 | 971 | |
972 | 972 | /** |
973 | - * Alias of self::get_phone(). |
|
974 | - * |
|
975 | - * @since 1.0.19 |
|
976 | - * @param string $context View or edit context. |
|
977 | - * @return string |
|
978 | - */ |
|
979 | - public function get_customer_phone( $context = 'view' ) { |
|
980 | - return $this->get_phone( $context ); |
|
973 | + * Alias of self::get_phone(). |
|
974 | + * |
|
975 | + * @since 1.0.19 |
|
976 | + * @param string $context View or edit context. |
|
977 | + * @return string |
|
978 | + */ |
|
979 | + public function get_customer_phone( $context = 'view' ) { |
|
980 | + return $this->get_phone( $context ); |
|
981 | 981 | } |
982 | 982 | |
983 | 983 | /** |
984 | - * Get the customer's email address. |
|
985 | - * |
|
986 | - * @since 1.0.19 |
|
987 | - * @param string $context View or edit context. |
|
988 | - * @return string |
|
989 | - */ |
|
990 | - public function get_email( $context = 'view' ) { |
|
991 | - return $this->get_prop( 'email', $context ); |
|
984 | + * Get the customer's email address. |
|
985 | + * |
|
986 | + * @since 1.0.19 |
|
987 | + * @param string $context View or edit context. |
|
988 | + * @return string |
|
989 | + */ |
|
990 | + public function get_email( $context = 'view' ) { |
|
991 | + return $this->get_prop( 'email', $context ); |
|
992 | 992 | } |
993 | 993 | |
994 | 994 | /** |
995 | - * Alias of self::get_email(). |
|
996 | - * |
|
997 | - * @since 1.0.19 |
|
998 | - * @param string $context View or edit context. |
|
999 | - * @return string |
|
1000 | - */ |
|
1001 | - public function get_email_address( $context = 'view' ) { |
|
1002 | - return $this->get_email( $context ); |
|
995 | + * Alias of self::get_email(). |
|
996 | + * |
|
997 | + * @since 1.0.19 |
|
998 | + * @param string $context View or edit context. |
|
999 | + * @return string |
|
1000 | + */ |
|
1001 | + public function get_email_address( $context = 'view' ) { |
|
1002 | + return $this->get_email( $context ); |
|
1003 | 1003 | } |
1004 | 1004 | |
1005 | 1005 | /** |
1006 | - * Alias of self::get_email(). |
|
1007 | - * |
|
1008 | - * @since 1.0.19 |
|
1009 | - * @param string $context View or edit context. |
|
1010 | - * @return string |
|
1011 | - */ |
|
1012 | - public function get_user_email( $context = 'view' ) { |
|
1013 | - return $this->get_email( $context ); |
|
1006 | + * Alias of self::get_email(). |
|
1007 | + * |
|
1008 | + * @since 1.0.19 |
|
1009 | + * @param string $context View or edit context. |
|
1010 | + * @return string |
|
1011 | + */ |
|
1012 | + public function get_user_email( $context = 'view' ) { |
|
1013 | + return $this->get_email( $context ); |
|
1014 | 1014 | } |
1015 | 1015 | |
1016 | 1016 | /** |
1017 | - * Alias of self::get_email(). |
|
1018 | - * |
|
1019 | - * @since 1.0.19 |
|
1020 | - * @param string $context View or edit context. |
|
1021 | - * @return string |
|
1022 | - */ |
|
1023 | - public function get_customer_email( $context = 'view' ) { |
|
1024 | - return $this->get_email( $context ); |
|
1017 | + * Alias of self::get_email(). |
|
1018 | + * |
|
1019 | + * @since 1.0.19 |
|
1020 | + * @param string $context View or edit context. |
|
1021 | + * @return string |
|
1022 | + */ |
|
1023 | + public function get_customer_email( $context = 'view' ) { |
|
1024 | + return $this->get_email( $context ); |
|
1025 | 1025 | } |
1026 | 1026 | |
1027 | 1027 | /** |
1028 | - * Get the customer's country. |
|
1029 | - * |
|
1030 | - * @since 1.0.19 |
|
1031 | - * @param string $context View or edit context. |
|
1032 | - * @return string |
|
1033 | - */ |
|
1034 | - public function get_country( $context = 'view' ) { |
|
1035 | - $country = $this->get_prop( 'country', $context ); |
|
1036 | - return empty( $country ) ? wpinv_get_default_country() : $country; |
|
1028 | + * Get the customer's country. |
|
1029 | + * |
|
1030 | + * @since 1.0.19 |
|
1031 | + * @param string $context View or edit context. |
|
1032 | + * @return string |
|
1033 | + */ |
|
1034 | + public function get_country( $context = 'view' ) { |
|
1035 | + $country = $this->get_prop( 'country', $context ); |
|
1036 | + return empty( $country ) ? wpinv_get_default_country() : $country; |
|
1037 | 1037 | } |
1038 | 1038 | |
1039 | 1039 | /** |
1040 | - * Alias of self::get_country(). |
|
1041 | - * |
|
1042 | - * @since 1.0.19 |
|
1043 | - * @param string $context View or edit context. |
|
1044 | - * @return string |
|
1045 | - */ |
|
1046 | - public function get_user_country( $context = 'view' ) { |
|
1047 | - return $this->get_country( $context ); |
|
1040 | + * Alias of self::get_country(). |
|
1041 | + * |
|
1042 | + * @since 1.0.19 |
|
1043 | + * @param string $context View or edit context. |
|
1044 | + * @return string |
|
1045 | + */ |
|
1046 | + public function get_user_country( $context = 'view' ) { |
|
1047 | + return $this->get_country( $context ); |
|
1048 | 1048 | } |
1049 | 1049 | |
1050 | 1050 | /** |
1051 | - * Alias of self::get_country(). |
|
1052 | - * |
|
1053 | - * @since 1.0.19 |
|
1054 | - * @param string $context View or edit context. |
|
1055 | - * @return string |
|
1056 | - */ |
|
1057 | - public function get_customer_country( $context = 'view' ) { |
|
1058 | - return $this->get_country( $context ); |
|
1051 | + * Alias of self::get_country(). |
|
1052 | + * |
|
1053 | + * @since 1.0.19 |
|
1054 | + * @param string $context View or edit context. |
|
1055 | + * @return string |
|
1056 | + */ |
|
1057 | + public function get_customer_country( $context = 'view' ) { |
|
1058 | + return $this->get_country( $context ); |
|
1059 | 1059 | } |
1060 | 1060 | |
1061 | 1061 | /** |
1062 | - * Get the customer's state. |
|
1063 | - * |
|
1064 | - * @since 1.0.19 |
|
1065 | - * @param string $context View or edit context. |
|
1066 | - * @return string |
|
1067 | - */ |
|
1068 | - public function get_state( $context = 'view' ) { |
|
1069 | - $state = $this->get_prop( 'state', $context ); |
|
1070 | - return empty( $state ) ? wpinv_get_default_state() : $state; |
|
1062 | + * Get the customer's state. |
|
1063 | + * |
|
1064 | + * @since 1.0.19 |
|
1065 | + * @param string $context View or edit context. |
|
1066 | + * @return string |
|
1067 | + */ |
|
1068 | + public function get_state( $context = 'view' ) { |
|
1069 | + $state = $this->get_prop( 'state', $context ); |
|
1070 | + return empty( $state ) ? wpinv_get_default_state() : $state; |
|
1071 | 1071 | } |
1072 | 1072 | |
1073 | 1073 | /** |
1074 | - * Alias of self::get_state(). |
|
1075 | - * |
|
1076 | - * @since 1.0.19 |
|
1077 | - * @param string $context View or edit context. |
|
1078 | - * @return string |
|
1079 | - */ |
|
1080 | - public function get_user_state( $context = 'view' ) { |
|
1081 | - return $this->get_state( $context ); |
|
1074 | + * Alias of self::get_state(). |
|
1075 | + * |
|
1076 | + * @since 1.0.19 |
|
1077 | + * @param string $context View or edit context. |
|
1078 | + * @return string |
|
1079 | + */ |
|
1080 | + public function get_user_state( $context = 'view' ) { |
|
1081 | + return $this->get_state( $context ); |
|
1082 | 1082 | } |
1083 | 1083 | |
1084 | 1084 | /** |
1085 | - * Alias of self::get_state(). |
|
1086 | - * |
|
1087 | - * @since 1.0.19 |
|
1088 | - * @param string $context View or edit context. |
|
1089 | - * @return string |
|
1090 | - */ |
|
1091 | - public function get_customer_state( $context = 'view' ) { |
|
1092 | - return $this->get_state( $context ); |
|
1085 | + * Alias of self::get_state(). |
|
1086 | + * |
|
1087 | + * @since 1.0.19 |
|
1088 | + * @param string $context View or edit context. |
|
1089 | + * @return string |
|
1090 | + */ |
|
1091 | + public function get_customer_state( $context = 'view' ) { |
|
1092 | + return $this->get_state( $context ); |
|
1093 | 1093 | } |
1094 | 1094 | |
1095 | 1095 | /** |
1096 | - * Get the customer's city. |
|
1097 | - * |
|
1098 | - * @since 1.0.19 |
|
1099 | - * @param string $context View or edit context. |
|
1100 | - * @return string |
|
1101 | - */ |
|
1102 | - public function get_city( $context = 'view' ) { |
|
1103 | - return $this->get_prop( 'city', $context ); |
|
1096 | + * Get the customer's city. |
|
1097 | + * |
|
1098 | + * @since 1.0.19 |
|
1099 | + * @param string $context View or edit context. |
|
1100 | + * @return string |
|
1101 | + */ |
|
1102 | + public function get_city( $context = 'view' ) { |
|
1103 | + return $this->get_prop( 'city', $context ); |
|
1104 | 1104 | } |
1105 | 1105 | |
1106 | 1106 | /** |
1107 | - * Alias of self::get_city(). |
|
1108 | - * |
|
1109 | - * @since 1.0.19 |
|
1110 | - * @param string $context View or edit context. |
|
1111 | - * @return string |
|
1112 | - */ |
|
1113 | - public function get_user_city( $context = 'view' ) { |
|
1114 | - return $this->get_city( $context ); |
|
1107 | + * Alias of self::get_city(). |
|
1108 | + * |
|
1109 | + * @since 1.0.19 |
|
1110 | + * @param string $context View or edit context. |
|
1111 | + * @return string |
|
1112 | + */ |
|
1113 | + public function get_user_city( $context = 'view' ) { |
|
1114 | + return $this->get_city( $context ); |
|
1115 | 1115 | } |
1116 | 1116 | |
1117 | 1117 | /** |
1118 | - * Alias of self::get_city(). |
|
1119 | - * |
|
1120 | - * @since 1.0.19 |
|
1121 | - * @param string $context View or edit context. |
|
1122 | - * @return string |
|
1123 | - */ |
|
1124 | - public function get_customer_city( $context = 'view' ) { |
|
1125 | - return $this->get_city( $context ); |
|
1118 | + * Alias of self::get_city(). |
|
1119 | + * |
|
1120 | + * @since 1.0.19 |
|
1121 | + * @param string $context View or edit context. |
|
1122 | + * @return string |
|
1123 | + */ |
|
1124 | + public function get_customer_city( $context = 'view' ) { |
|
1125 | + return $this->get_city( $context ); |
|
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | /** |
1129 | - * Get the customer's zip. |
|
1130 | - * |
|
1131 | - * @since 1.0.19 |
|
1132 | - * @param string $context View or edit context. |
|
1133 | - * @return string |
|
1134 | - */ |
|
1135 | - public function get_zip( $context = 'view' ) { |
|
1136 | - return $this->get_prop( 'zip', $context ); |
|
1129 | + * Get the customer's zip. |
|
1130 | + * |
|
1131 | + * @since 1.0.19 |
|
1132 | + * @param string $context View or edit context. |
|
1133 | + * @return string |
|
1134 | + */ |
|
1135 | + public function get_zip( $context = 'view' ) { |
|
1136 | + return $this->get_prop( 'zip', $context ); |
|
1137 | 1137 | } |
1138 | 1138 | |
1139 | 1139 | /** |
1140 | - * Alias of self::get_zip(). |
|
1141 | - * |
|
1142 | - * @since 1.0.19 |
|
1143 | - * @param string $context View or edit context. |
|
1144 | - * @return string |
|
1145 | - */ |
|
1146 | - public function get_user_zip( $context = 'view' ) { |
|
1147 | - return $this->get_zip( $context ); |
|
1140 | + * Alias of self::get_zip(). |
|
1141 | + * |
|
1142 | + * @since 1.0.19 |
|
1143 | + * @param string $context View or edit context. |
|
1144 | + * @return string |
|
1145 | + */ |
|
1146 | + public function get_user_zip( $context = 'view' ) { |
|
1147 | + return $this->get_zip( $context ); |
|
1148 | + } |
|
1149 | + |
|
1150 | + /** |
|
1151 | + * Alias of self::get_zip(). |
|
1152 | + * |
|
1153 | + * @since 1.0.19 |
|
1154 | + * @param string $context View or edit context. |
|
1155 | + * @return string |
|
1156 | + */ |
|
1157 | + public function get_customer_zip( $context = 'view' ) { |
|
1158 | + return $this->get_zip( $context ); |
|
1159 | + } |
|
1160 | + |
|
1161 | + /** |
|
1162 | + * Get the customer's company. |
|
1163 | + * |
|
1164 | + * @since 1.0.19 |
|
1165 | + * @param string $context View or edit context. |
|
1166 | + * @return string |
|
1167 | + */ |
|
1168 | + public function get_company( $context = 'view' ) { |
|
1169 | + return $this->get_prop( 'company', $context ); |
|
1170 | + } |
|
1171 | + |
|
1172 | + /** |
|
1173 | + * Alias of self::get_company(). |
|
1174 | + * |
|
1175 | + * @since 1.0.19 |
|
1176 | + * @param string $context View or edit context. |
|
1177 | + * @return string |
|
1178 | + */ |
|
1179 | + public function get_user_company( $context = 'view' ) { |
|
1180 | + return $this->get_company( $context ); |
|
1181 | + } |
|
1182 | + |
|
1183 | + /** |
|
1184 | + * Alias of self::get_company(). |
|
1185 | + * |
|
1186 | + * @since 1.0.19 |
|
1187 | + * @param string $context View or edit context. |
|
1188 | + * @return string |
|
1189 | + */ |
|
1190 | + public function get_customer_company( $context = 'view' ) { |
|
1191 | + return $this->get_company( $context ); |
|
1192 | + } |
|
1193 | + |
|
1194 | + /** |
|
1195 | + * Get the customer's company id. |
|
1196 | + * |
|
1197 | + * @since 1.0.19 |
|
1198 | + * @param string $context View or edit context. |
|
1199 | + * @return string |
|
1200 | + */ |
|
1201 | + public function get_company_id( $context = 'view' ) { |
|
1202 | + return $this->get_prop( 'company_id', $context ); |
|
1203 | + } |
|
1204 | + |
|
1205 | + /** |
|
1206 | + * Get the customer's vat number. |
|
1207 | + * |
|
1208 | + * @since 1.0.19 |
|
1209 | + * @param string $context View or edit context. |
|
1210 | + * @return string |
|
1211 | + */ |
|
1212 | + public function get_vat_number( $context = 'view' ) { |
|
1213 | + return $this->get_prop( 'vat_number', $context ); |
|
1214 | + } |
|
1215 | + |
|
1216 | + /** |
|
1217 | + * Alias of self::get_vat_number(). |
|
1218 | + * |
|
1219 | + * @since 1.0.19 |
|
1220 | + * @param string $context View or edit context. |
|
1221 | + * @return string |
|
1222 | + */ |
|
1223 | + public function get_user_vat_number( $context = 'view' ) { |
|
1224 | + return $this->get_vat_number( $context ); |
|
1225 | + } |
|
1226 | + |
|
1227 | + /** |
|
1228 | + * Alias of self::get_vat_number(). |
|
1229 | + * |
|
1230 | + * @since 1.0.19 |
|
1231 | + * @param string $context View or edit context. |
|
1232 | + * @return string |
|
1233 | + */ |
|
1234 | + public function get_customer_vat_number( $context = 'view' ) { |
|
1235 | + return $this->get_vat_number( $context ); |
|
1236 | + } |
|
1237 | + |
|
1238 | + /** |
|
1239 | + * Get the customer's vat rate. |
|
1240 | + * |
|
1241 | + * @since 1.0.19 |
|
1242 | + * @param string $context View or edit context. |
|
1243 | + * @return string |
|
1244 | + */ |
|
1245 | + public function get_vat_rate( $context = 'view' ) { |
|
1246 | + return $this->get_prop( 'vat_rate', $context ); |
|
1247 | + } |
|
1248 | + |
|
1249 | + /** |
|
1250 | + * Alias of self::get_vat_rate(). |
|
1251 | + * |
|
1252 | + * @since 1.0.19 |
|
1253 | + * @param string $context View or edit context. |
|
1254 | + * @return string |
|
1255 | + */ |
|
1256 | + public function get_user_vat_rate( $context = 'view' ) { |
|
1257 | + return $this->get_vat_rate( $context ); |
|
1258 | + } |
|
1259 | + |
|
1260 | + /** |
|
1261 | + * Alias of self::get_vat_rate(). |
|
1262 | + * |
|
1263 | + * @since 1.0.19 |
|
1264 | + * @param string $context View or edit context. |
|
1265 | + * @return string |
|
1266 | + */ |
|
1267 | + public function get_customer_vat_rate( $context = 'view' ) { |
|
1268 | + return $this->get_vat_rate( $context ); |
|
1269 | + } |
|
1270 | + |
|
1271 | + /** |
|
1272 | + * Get the customer's address. |
|
1273 | + * |
|
1274 | + * @since 1.0.19 |
|
1275 | + * @param string $context View or edit context. |
|
1276 | + * @return string |
|
1277 | + */ |
|
1278 | + public function get_address( $context = 'view' ) { |
|
1279 | + return $this->get_prop( 'address', $context ); |
|
1280 | + } |
|
1281 | + |
|
1282 | + /** |
|
1283 | + * Alias of self::get_address(). |
|
1284 | + * |
|
1285 | + * @since 1.0.19 |
|
1286 | + * @param string $context View or edit context. |
|
1287 | + * @return string |
|
1288 | + */ |
|
1289 | + public function get_user_address( $context = 'view' ) { |
|
1290 | + return $this->get_address( $context ); |
|
1291 | + } |
|
1292 | + |
|
1293 | + /** |
|
1294 | + * Alias of self::get_address(). |
|
1295 | + * |
|
1296 | + * @since 1.0.19 |
|
1297 | + * @param string $context View or edit context. |
|
1298 | + * @return string |
|
1299 | + */ |
|
1300 | + public function get_customer_address( $context = 'view' ) { |
|
1301 | + return $this->get_address( $context ); |
|
1302 | + } |
|
1303 | + |
|
1304 | + /** |
|
1305 | + * Get whether the customer has viewed the invoice or not. |
|
1306 | + * |
|
1307 | + * @since 1.0.19 |
|
1308 | + * @param string $context View or edit context. |
|
1309 | + * @return bool |
|
1310 | + */ |
|
1311 | + public function get_is_viewed( $context = 'view' ) { |
|
1312 | + return (bool) $this->get_prop( 'is_viewed', $context ); |
|
1313 | + } |
|
1314 | + |
|
1315 | + /** |
|
1316 | + * Get other recipients for invoice communications. |
|
1317 | + * |
|
1318 | + * @since 1.0.19 |
|
1319 | + * @param string $context View or edit context. |
|
1320 | + * @return bool |
|
1321 | + */ |
|
1322 | + public function get_email_cc( $context = 'view' ) { |
|
1323 | + return $this->get_prop( 'email_cc', $context ); |
|
1148 | 1324 | } |
1149 | 1325 | |
1150 | 1326 | /** |
1151 | - * Alias of self::get_zip(). |
|
1152 | - * |
|
1153 | - * @since 1.0.19 |
|
1154 | - * @param string $context View or edit context. |
|
1155 | - * @return string |
|
1156 | - */ |
|
1157 | - public function get_customer_zip( $context = 'view' ) { |
|
1158 | - return $this->get_zip( $context ); |
|
1327 | + * Get invoice template. |
|
1328 | + * |
|
1329 | + * @since 1.0.19 |
|
1330 | + * @param string $context View or edit context. |
|
1331 | + * @return bool |
|
1332 | + */ |
|
1333 | + public function get_template( $context = 'view' ) { |
|
1334 | + return $this->get_prop( 'template', $context ); |
|
1159 | 1335 | } |
1160 | 1336 | |
1161 | 1337 | /** |
1162 | - * Get the customer's company. |
|
1163 | - * |
|
1164 | - * @since 1.0.19 |
|
1165 | - * @param string $context View or edit context. |
|
1166 | - * @return string |
|
1167 | - */ |
|
1168 | - public function get_company( $context = 'view' ) { |
|
1169 | - return $this->get_prop( 'company', $context ); |
|
1338 | + * Get invoice source. |
|
1339 | + * |
|
1340 | + * @since 1.0.19 |
|
1341 | + * @param string $context View or edit context. |
|
1342 | + * @return bool |
|
1343 | + */ |
|
1344 | + public function get_created_via( $context = 'view' ) { |
|
1345 | + return $this->get_prop( 'created_via', $context ); |
|
1170 | 1346 | } |
1171 | 1347 | |
1172 | 1348 | /** |
1173 | - * Alias of self::get_company(). |
|
1174 | - * |
|
1175 | - * @since 1.0.19 |
|
1176 | - * @param string $context View or edit context. |
|
1177 | - * @return string |
|
1178 | - */ |
|
1179 | - public function get_user_company( $context = 'view' ) { |
|
1180 | - return $this->get_company( $context ); |
|
1349 | + * Get whether the customer has confirmed their address. |
|
1350 | + * |
|
1351 | + * @since 1.0.19 |
|
1352 | + * @param string $context View or edit context. |
|
1353 | + * @return bool |
|
1354 | + */ |
|
1355 | + public function get_address_confirmed( $context = 'view' ) { |
|
1356 | + return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
1181 | 1357 | } |
1182 | 1358 | |
1183 | 1359 | /** |
1184 | - * Alias of self::get_company(). |
|
1185 | - * |
|
1186 | - * @since 1.0.19 |
|
1187 | - * @param string $context View or edit context. |
|
1188 | - * @return string |
|
1189 | - */ |
|
1190 | - public function get_customer_company( $context = 'view' ) { |
|
1191 | - return $this->get_company( $context ); |
|
1360 | + * Alias of self::get_address_confirmed(). |
|
1361 | + * |
|
1362 | + * @since 1.0.19 |
|
1363 | + * @param string $context View or edit context. |
|
1364 | + * @return bool |
|
1365 | + */ |
|
1366 | + public function get_user_address_confirmed( $context = 'view' ) { |
|
1367 | + return $this->get_address_confirmed( $context ); |
|
1192 | 1368 | } |
1193 | 1369 | |
1194 | - /** |
|
1195 | - * Get the customer's company id. |
|
1196 | - * |
|
1197 | - * @since 1.0.19 |
|
1198 | - * @param string $context View or edit context. |
|
1199 | - * @return string |
|
1200 | - */ |
|
1201 | - public function get_company_id( $context = 'view' ) { |
|
1202 | - return $this->get_prop( 'company_id', $context ); |
|
1370 | + /** |
|
1371 | + * Alias of self::get_address(). |
|
1372 | + * |
|
1373 | + * @since 1.0.19 |
|
1374 | + * @param string $context View or edit context. |
|
1375 | + * @return bool |
|
1376 | + */ |
|
1377 | + public function get_customer_address_confirmed( $context = 'view' ) { |
|
1378 | + return $this->get_address_confirmed( $context ); |
|
1203 | 1379 | } |
1204 | 1380 | |
1205 | 1381 | /** |
1206 | - * Get the customer's vat number. |
|
1207 | - * |
|
1208 | - * @since 1.0.19 |
|
1209 | - * @param string $context View or edit context. |
|
1210 | - * @return string |
|
1211 | - */ |
|
1212 | - public function get_vat_number( $context = 'view' ) { |
|
1213 | - return $this->get_prop( 'vat_number', $context ); |
|
1382 | + * Get the shipping address. |
|
1383 | + * |
|
1384 | + * @since 1.0.19 |
|
1385 | + * @return array|false |
|
1386 | + */ |
|
1387 | + public function get_shipping_address() { |
|
1388 | + |
|
1389 | + $shipping_address = get_post_meta( $this->get_id(), 'shipping_address', true ); |
|
1390 | + return is_array( $shipping_address ) ? $shipping_address : false; |
|
1214 | 1391 | } |
1215 | 1392 | |
1216 | 1393 | /** |
1217 | - * Alias of self::get_vat_number(). |
|
1218 | - * |
|
1219 | - * @since 1.0.19 |
|
1220 | - * @param string $context View or edit context. |
|
1221 | - * @return string |
|
1222 | - */ |
|
1223 | - public function get_user_vat_number( $context = 'view' ) { |
|
1224 | - return $this->get_vat_number( $context ); |
|
1394 | + * Check if the invoice has a shipping address. |
|
1395 | + */ |
|
1396 | + public function has_shipping_address() { |
|
1397 | + return false !== $this->get_shipping_address(); |
|
1225 | 1398 | } |
1226 | 1399 | |
1227 | 1400 | /** |
1228 | - * Alias of self::get_vat_number(). |
|
1229 | - * |
|
1230 | - * @since 1.0.19 |
|
1231 | - * @param string $context View or edit context. |
|
1232 | - * @return string |
|
1233 | - */ |
|
1234 | - public function get_customer_vat_number( $context = 'view' ) { |
|
1235 | - return $this->get_vat_number( $context ); |
|
1401 | + * Get the shipping amount. |
|
1402 | + * |
|
1403 | + * @since 1.0.19 |
|
1404 | + * @param string $context View or edit context. |
|
1405 | + * @return float |
|
1406 | + */ |
|
1407 | + public function get_shipping( $context = 'view' ) { |
|
1408 | + |
|
1409 | + if ( $context = 'view' ) { |
|
1410 | + return floatval( $this->get_prop( 'shipping', $context ) ); |
|
1411 | + } |
|
1412 | + |
|
1413 | + return $this->get_prop( 'shipping', $context ); |
|
1414 | + } |
|
1415 | + |
|
1416 | + public function has_shipping() { |
|
1417 | + return defined( 'GETPAID_SHIPPING_CALCULATOR_VERSION' ) && $this->get_prop( 'shipping', 'edit' ); |
|
1236 | 1418 | } |
1237 | 1419 | |
1238 | - /** |
|
1239 | - * Get the customer's vat rate. |
|
1240 | - * |
|
1241 | - * @since 1.0.19 |
|
1242 | - * @param string $context View or edit context. |
|
1243 | - * @return string |
|
1244 | - */ |
|
1245 | - public function get_vat_rate( $context = 'view' ) { |
|
1246 | - return $this->get_prop( 'vat_rate', $context ); |
|
1247 | - } |
|
1248 | - |
|
1249 | - /** |
|
1250 | - * Alias of self::get_vat_rate(). |
|
1251 | - * |
|
1252 | - * @since 1.0.19 |
|
1253 | - * @param string $context View or edit context. |
|
1254 | - * @return string |
|
1255 | - */ |
|
1256 | - public function get_user_vat_rate( $context = 'view' ) { |
|
1257 | - return $this->get_vat_rate( $context ); |
|
1258 | - } |
|
1259 | - |
|
1260 | - /** |
|
1261 | - * Alias of self::get_vat_rate(). |
|
1262 | - * |
|
1263 | - * @since 1.0.19 |
|
1264 | - * @param string $context View or edit context. |
|
1265 | - * @return string |
|
1266 | - */ |
|
1267 | - public function get_customer_vat_rate( $context = 'view' ) { |
|
1268 | - return $this->get_vat_rate( $context ); |
|
1269 | - } |
|
1270 | - |
|
1271 | - /** |
|
1272 | - * Get the customer's address. |
|
1273 | - * |
|
1274 | - * @since 1.0.19 |
|
1275 | - * @param string $context View or edit context. |
|
1276 | - * @return string |
|
1277 | - */ |
|
1278 | - public function get_address( $context = 'view' ) { |
|
1279 | - return $this->get_prop( 'address', $context ); |
|
1280 | - } |
|
1281 | - |
|
1282 | - /** |
|
1283 | - * Alias of self::get_address(). |
|
1284 | - * |
|
1285 | - * @since 1.0.19 |
|
1286 | - * @param string $context View or edit context. |
|
1287 | - * @return string |
|
1288 | - */ |
|
1289 | - public function get_user_address( $context = 'view' ) { |
|
1290 | - return $this->get_address( $context ); |
|
1291 | - } |
|
1292 | - |
|
1293 | - /** |
|
1294 | - * Alias of self::get_address(). |
|
1295 | - * |
|
1296 | - * @since 1.0.19 |
|
1297 | - * @param string $context View or edit context. |
|
1298 | - * @return string |
|
1299 | - */ |
|
1300 | - public function get_customer_address( $context = 'view' ) { |
|
1301 | - return $this->get_address( $context ); |
|
1302 | - } |
|
1303 | - |
|
1304 | - /** |
|
1305 | - * Get whether the customer has viewed the invoice or not. |
|
1306 | - * |
|
1307 | - * @since 1.0.19 |
|
1308 | - * @param string $context View or edit context. |
|
1309 | - * @return bool |
|
1310 | - */ |
|
1311 | - public function get_is_viewed( $context = 'view' ) { |
|
1312 | - return (bool) $this->get_prop( 'is_viewed', $context ); |
|
1313 | - } |
|
1314 | - |
|
1315 | - /** |
|
1316 | - * Get other recipients for invoice communications. |
|
1317 | - * |
|
1318 | - * @since 1.0.19 |
|
1319 | - * @param string $context View or edit context. |
|
1320 | - * @return bool |
|
1321 | - */ |
|
1322 | - public function get_email_cc( $context = 'view' ) { |
|
1323 | - return $this->get_prop( 'email_cc', $context ); |
|
1324 | - } |
|
1325 | - |
|
1326 | - /** |
|
1327 | - * Get invoice template. |
|
1328 | - * |
|
1329 | - * @since 1.0.19 |
|
1330 | - * @param string $context View or edit context. |
|
1331 | - * @return bool |
|
1332 | - */ |
|
1333 | - public function get_template( $context = 'view' ) { |
|
1334 | - return $this->get_prop( 'template', $context ); |
|
1335 | - } |
|
1336 | - |
|
1337 | - /** |
|
1338 | - * Get invoice source. |
|
1339 | - * |
|
1340 | - * @since 1.0.19 |
|
1341 | - * @param string $context View or edit context. |
|
1342 | - * @return bool |
|
1343 | - */ |
|
1344 | - public function get_created_via( $context = 'view' ) { |
|
1345 | - return $this->get_prop( 'created_via', $context ); |
|
1346 | - } |
|
1347 | - |
|
1348 | - /** |
|
1349 | - * Get whether the customer has confirmed their address. |
|
1350 | - * |
|
1351 | - * @since 1.0.19 |
|
1352 | - * @param string $context View or edit context. |
|
1353 | - * @return bool |
|
1354 | - */ |
|
1355 | - public function get_address_confirmed( $context = 'view' ) { |
|
1356 | - return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
1357 | - } |
|
1358 | - |
|
1359 | - /** |
|
1360 | - * Alias of self::get_address_confirmed(). |
|
1361 | - * |
|
1362 | - * @since 1.0.19 |
|
1363 | - * @param string $context View or edit context. |
|
1364 | - * @return bool |
|
1365 | - */ |
|
1366 | - public function get_user_address_confirmed( $context = 'view' ) { |
|
1367 | - return $this->get_address_confirmed( $context ); |
|
1368 | - } |
|
1369 | - |
|
1370 | - /** |
|
1371 | - * Alias of self::get_address(). |
|
1372 | - * |
|
1373 | - * @since 1.0.19 |
|
1374 | - * @param string $context View or edit context. |
|
1375 | - * @return bool |
|
1376 | - */ |
|
1377 | - public function get_customer_address_confirmed( $context = 'view' ) { |
|
1378 | - return $this->get_address_confirmed( $context ); |
|
1379 | - } |
|
1380 | - |
|
1381 | - /** |
|
1382 | - * Get the shipping address. |
|
1383 | - * |
|
1384 | - * @since 1.0.19 |
|
1385 | - * @return array|false |
|
1386 | - */ |
|
1387 | - public function get_shipping_address() { |
|
1388 | - |
|
1389 | - $shipping_address = get_post_meta( $this->get_id(), 'shipping_address', true ); |
|
1390 | - return is_array( $shipping_address ) ? $shipping_address : false; |
|
1391 | - } |
|
1392 | - |
|
1393 | - /** |
|
1394 | - * Check if the invoice has a shipping address. |
|
1395 | - */ |
|
1396 | - public function has_shipping_address() { |
|
1397 | - return false !== $this->get_shipping_address(); |
|
1398 | - } |
|
1399 | - |
|
1400 | - /** |
|
1401 | - * Get the shipping amount. |
|
1402 | - * |
|
1403 | - * @since 1.0.19 |
|
1404 | - * @param string $context View or edit context. |
|
1405 | - * @return float |
|
1406 | - */ |
|
1407 | - public function get_shipping( $context = 'view' ) { |
|
1408 | - |
|
1409 | - if ( $context = 'view' ) { |
|
1410 | - return floatval( $this->get_prop( 'shipping', $context ) ); |
|
1411 | - } |
|
1412 | - |
|
1413 | - return $this->get_prop( 'shipping', $context ); |
|
1414 | - } |
|
1415 | - |
|
1416 | - public function has_shipping() { |
|
1417 | - return defined( 'GETPAID_SHIPPING_CALCULATOR_VERSION' ) && $this->get_prop( 'shipping', 'edit' ); |
|
1418 | - } |
|
1419 | - |
|
1420 | - /** |
|
1421 | - * Get the invoice subtotal. |
|
1422 | - * |
|
1423 | - * @since 1.0.19 |
|
1424 | - * @param string $context View or edit context. |
|
1425 | - * @return float |
|
1426 | - */ |
|
1427 | - public function get_subtotal( $context = 'view' ) { |
|
1420 | + /** |
|
1421 | + * Get the invoice subtotal. |
|
1422 | + * |
|
1423 | + * @since 1.0.19 |
|
1424 | + * @param string $context View or edit context. |
|
1425 | + * @return float |
|
1426 | + */ |
|
1427 | + public function get_subtotal( $context = 'view' ) { |
|
1428 | 1428 | $subtotal = (float) $this->get_prop( 'subtotal', $context ); |
1429 | 1429 | |
1430 | 1430 | // Backwards compatibility. |
@@ -1436,197 +1436,197 @@ discard block |
||
1436 | 1436 | } |
1437 | 1437 | |
1438 | 1438 | /** |
1439 | - * Get the invoice discount total. |
|
1440 | - * |
|
1441 | - * @since 1.0.19 |
|
1442 | - * @param string $context View or edit context. |
|
1443 | - * @return float |
|
1444 | - */ |
|
1445 | - public function get_total_discount( $context = 'view' ) { |
|
1446 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) ); |
|
1439 | + * Get the invoice discount total. |
|
1440 | + * |
|
1441 | + * @since 1.0.19 |
|
1442 | + * @param string $context View or edit context. |
|
1443 | + * @return float |
|
1444 | + */ |
|
1445 | + public function get_total_discount( $context = 'view' ) { |
|
1446 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) ); |
|
1447 | 1447 | } |
1448 | 1448 | |
1449 | 1449 | /** |
1450 | - * Get the invoice tax total. |
|
1451 | - * |
|
1452 | - * @since 1.0.19 |
|
1453 | - * @param string $context View or edit context. |
|
1454 | - * @return float |
|
1455 | - */ |
|
1456 | - public function get_total_tax( $context = 'view' ) { |
|
1457 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) ); |
|
1458 | - } |
|
1450 | + * Get the invoice tax total. |
|
1451 | + * |
|
1452 | + * @since 1.0.19 |
|
1453 | + * @param string $context View or edit context. |
|
1454 | + * @return float |
|
1455 | + */ |
|
1456 | + public function get_total_tax( $context = 'view' ) { |
|
1457 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) ); |
|
1458 | + } |
|
1459 | 1459 | |
1460 | - /** |
|
1461 | - * @deprecated |
|
1462 | - */ |
|
1463 | - public function get_final_tax( $currency = false ) { |
|
1464 | - $tax = $this->get_total_tax(); |
|
1460 | + /** |
|
1461 | + * @deprecated |
|
1462 | + */ |
|
1463 | + public function get_final_tax( $currency = false ) { |
|
1464 | + $tax = $this->get_total_tax(); |
|
1465 | 1465 | |
1466 | 1466 | if ( $currency ) { |
1467 | - return wpinv_price( $tax, $this->get_currency() ); |
|
1467 | + return wpinv_price( $tax, $this->get_currency() ); |
|
1468 | 1468 | } |
1469 | 1469 | |
1470 | 1470 | return $tax; |
1471 | 1471 | } |
1472 | 1472 | |
1473 | 1473 | /** |
1474 | - * Get the invoice fees total. |
|
1475 | - * |
|
1476 | - * @since 1.0.19 |
|
1477 | - * @param string $context View or edit context. |
|
1478 | - * @return float |
|
1479 | - */ |
|
1480 | - public function get_total_fees( $context = 'view' ) { |
|
1481 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) ); |
|
1474 | + * Get the invoice fees total. |
|
1475 | + * |
|
1476 | + * @since 1.0.19 |
|
1477 | + * @param string $context View or edit context. |
|
1478 | + * @return float |
|
1479 | + */ |
|
1480 | + public function get_total_fees( $context = 'view' ) { |
|
1481 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) ); |
|
1482 | 1482 | } |
1483 | 1483 | |
1484 | 1484 | /** |
1485 | - * Alias for self::get_total_fees(). |
|
1486 | - * |
|
1487 | - * @since 1.0.19 |
|
1488 | - * @param string $context View or edit context. |
|
1489 | - * @return float |
|
1490 | - */ |
|
1491 | - public function get_fees_total( $context = 'view' ) { |
|
1492 | - return $this->get_total_fees( $context ); |
|
1485 | + * Alias for self::get_total_fees(). |
|
1486 | + * |
|
1487 | + * @since 1.0.19 |
|
1488 | + * @param string $context View or edit context. |
|
1489 | + * @return float |
|
1490 | + */ |
|
1491 | + public function get_fees_total( $context = 'view' ) { |
|
1492 | + return $this->get_total_fees( $context ); |
|
1493 | 1493 | } |
1494 | 1494 | |
1495 | 1495 | /** |
1496 | - * Get the invoice total. |
|
1497 | - * |
|
1498 | - * @since 1.0.19 |
|
1496 | + * Get the invoice total. |
|
1497 | + * |
|
1498 | + * @since 1.0.19 |
|
1499 | 1499 | * @return float |
1500 | - */ |
|
1501 | - public function get_total( $context = 'view' ) { |
|
1502 | - $total = $this->get_prop( 'total', $context ); |
|
1503 | - |
|
1504 | - if ( $this->has_shipping() && $context == 'view' ) { |
|
1505 | - $total = $this->get_prop( 'total', $context ) + $this->get_shipping( $context ); |
|
1506 | - } |
|
1507 | - |
|
1508 | - return wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1509 | - } |
|
1510 | - |
|
1511 | - /** |
|
1512 | - * Retrieves the non-recurring total of items. |
|
1513 | - * |
|
1514 | - * @since 2.3.0 |
|
1515 | - * @return float |
|
1516 | - */ |
|
1517 | - public function get_non_recurring_total() { |
|
1518 | - |
|
1519 | - $subtotal = 0; |
|
1520 | - foreach ( $this->get_items() as $item ) { |
|
1521 | - if ( ! $item->is_recurring() ) { |
|
1522 | - $subtotal += $item->get_sub_total(); |
|
1523 | - } |
|
1524 | - } |
|
1525 | - |
|
1526 | - foreach ( $this->get_fees() as $fee ) { |
|
1527 | - if ( empty( $fee['recurring_fee'] ) ) { |
|
1528 | - $subtotal += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
1529 | - } |
|
1530 | - } |
|
1531 | - |
|
1532 | - $subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) ); |
|
1500 | + */ |
|
1501 | + public function get_total( $context = 'view' ) { |
|
1502 | + $total = $this->get_prop( 'total', $context ); |
|
1503 | + |
|
1504 | + if ( $this->has_shipping() && $context == 'view' ) { |
|
1505 | + $total = $this->get_prop( 'total', $context ) + $this->get_shipping( $context ); |
|
1506 | + } |
|
1507 | + |
|
1508 | + return wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1509 | + } |
|
1510 | + |
|
1511 | + /** |
|
1512 | + * Retrieves the non-recurring total of items. |
|
1513 | + * |
|
1514 | + * @since 2.3.0 |
|
1515 | + * @return float |
|
1516 | + */ |
|
1517 | + public function get_non_recurring_total() { |
|
1518 | + |
|
1519 | + $subtotal = 0; |
|
1520 | + foreach ( $this->get_items() as $item ) { |
|
1521 | + if ( ! $item->is_recurring() ) { |
|
1522 | + $subtotal += $item->get_sub_total(); |
|
1523 | + } |
|
1524 | + } |
|
1525 | + |
|
1526 | + foreach ( $this->get_fees() as $fee ) { |
|
1527 | + if ( empty( $fee['recurring_fee'] ) ) { |
|
1528 | + $subtotal += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
1529 | + } |
|
1530 | + } |
|
1531 | + |
|
1532 | + $subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) ); |
|
1533 | 1533 | return apply_filters( 'wpinv_get_non_recurring_invoice_total', $subtotal, $this ); |
1534 | 1534 | } |
1535 | 1535 | |
1536 | - /** |
|
1537 | - * Get the invoice totals. |
|
1538 | - * |
|
1539 | - * @since 1.0.19 |
|
1536 | + /** |
|
1537 | + * Get the invoice totals. |
|
1538 | + * |
|
1539 | + * @since 1.0.19 |
|
1540 | 1540 | * @return array |
1541 | - */ |
|
1542 | - public function get_totals() { |
|
1543 | - return $this->totals; |
|
1541 | + */ |
|
1542 | + public function get_totals() { |
|
1543 | + return $this->totals; |
|
1544 | 1544 | } |
1545 | 1545 | |
1546 | 1546 | /** |
1547 | - * Get the initial invoice total. |
|
1548 | - * |
|
1549 | - * @since 1.0.19 |
|
1547 | + * Get the initial invoice total. |
|
1548 | + * |
|
1549 | + * @since 1.0.19 |
|
1550 | 1550 | * @param string $context View or edit context. |
1551 | 1551 | * @return float |
1552 | - */ |
|
1552 | + */ |
|
1553 | 1553 | public function get_initial_total() { |
1554 | 1554 | |
1555 | - if ( empty( $this->totals ) ) { |
|
1556 | - $this->recalculate_total(); |
|
1557 | - } |
|
1555 | + if ( empty( $this->totals ) ) { |
|
1556 | + $this->recalculate_total(); |
|
1557 | + } |
|
1558 | 1558 | |
1559 | - $tax = $this->totals['tax']['initial']; |
|
1560 | - $fee = $this->totals['fee']['initial']; |
|
1561 | - $discount = $this->totals['discount']['initial']; |
|
1562 | - $subtotal = $this->totals['subtotal']['initial']; |
|
1563 | - $total = $tax + $fee - $discount + $subtotal; |
|
1559 | + $tax = $this->totals['tax']['initial']; |
|
1560 | + $fee = $this->totals['fee']['initial']; |
|
1561 | + $discount = $this->totals['discount']['initial']; |
|
1562 | + $subtotal = $this->totals['subtotal']['initial']; |
|
1563 | + $total = $tax + $fee - $discount + $subtotal; |
|
1564 | 1564 | |
1565 | - if ( 0 > $total ) { |
|
1566 | - $total = 0; |
|
1567 | - } |
|
1565 | + if ( 0 > $total ) { |
|
1566 | + $total = 0; |
|
1567 | + } |
|
1568 | 1568 | |
1569 | - $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1569 | + $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1570 | 1570 | return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this ); |
1571 | - } |
|
1571 | + } |
|
1572 | 1572 | |
1573 | - /** |
|
1574 | - * Get the recurring invoice total. |
|
1575 | - * |
|
1576 | - * @since 1.0.19 |
|
1573 | + /** |
|
1574 | + * Get the recurring invoice total. |
|
1575 | + * |
|
1576 | + * @since 1.0.19 |
|
1577 | 1577 | * @param string $context View or edit context. |
1578 | 1578 | * @return float |
1579 | - */ |
|
1579 | + */ |
|
1580 | 1580 | public function get_recurring_total() { |
1581 | 1581 | |
1582 | - if ( empty( $this->totals ) ) { |
|
1583 | - $this->recalculate_total(); |
|
1584 | - } |
|
1582 | + if ( empty( $this->totals ) ) { |
|
1583 | + $this->recalculate_total(); |
|
1584 | + } |
|
1585 | 1585 | |
1586 | - $tax = $this->totals['tax']['recurring']; |
|
1587 | - $fee = $this->totals['fee']['recurring']; |
|
1588 | - $discount = $this->totals['discount']['recurring']; |
|
1589 | - $subtotal = $this->totals['subtotal']['recurring']; |
|
1590 | - $total = $tax + $fee - $discount + $subtotal; |
|
1586 | + $tax = $this->totals['tax']['recurring']; |
|
1587 | + $fee = $this->totals['fee']['recurring']; |
|
1588 | + $discount = $this->totals['discount']['recurring']; |
|
1589 | + $subtotal = $this->totals['subtotal']['recurring']; |
|
1590 | + $total = $tax + $fee - $discount + $subtotal; |
|
1591 | 1591 | |
1592 | - if ( 0 > $total ) { |
|
1593 | - $total = 0; |
|
1594 | - } |
|
1592 | + if ( 0 > $total ) { |
|
1593 | + $total = 0; |
|
1594 | + } |
|
1595 | 1595 | |
1596 | - $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1596 | + $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1597 | 1597 | return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this ); |
1598 | - } |
|
1598 | + } |
|
1599 | 1599 | |
1600 | - /** |
|
1601 | - * Returns recurring payment details. |
|
1602 | - * |
|
1603 | - * @since 1.0.19 |
|
1600 | + /** |
|
1601 | + * Returns recurring payment details. |
|
1602 | + * |
|
1603 | + * @since 1.0.19 |
|
1604 | 1604 | * @param string $field Optionally provide a field to return. |
1605 | - * @param string $currency Whether to include the currency. |
|
1605 | + * @param string $currency Whether to include the currency. |
|
1606 | 1606 | * @return float|string |
1607 | - */ |
|
1607 | + */ |
|
1608 | 1608 | public function get_recurring_details( $field = '', $currency = false ) { |
1609 | 1609 | |
1610 | - // Maybe recalculate totals. |
|
1611 | - if ( empty( $this->totals ) ) { |
|
1612 | - $this->recalculate_total(); |
|
1613 | - } |
|
1610 | + // Maybe recalculate totals. |
|
1611 | + if ( empty( $this->totals ) ) { |
|
1612 | + $this->recalculate_total(); |
|
1613 | + } |
|
1614 | 1614 | |
1615 | - // Prepare recurring totals. |
|
1615 | + // Prepare recurring totals. |
|
1616 | 1616 | $data = apply_filters( |
1617 | - 'wpinv_get_invoice_recurring_details', |
|
1618 | - array( |
|
1619 | - 'cart_details' => $this->get_cart_details(), |
|
1620 | - 'subtotal' => $this->totals['subtotal']['recurring'], |
|
1621 | - 'discount' => $this->totals['discount']['recurring'], |
|
1622 | - 'tax' => $this->totals['tax']['recurring'], |
|
1623 | - 'fee' => $this->totals['fee']['recurring'], |
|
1624 | - 'total' => $this->get_recurring_total(), |
|
1625 | - ), |
|
1626 | - $this, |
|
1627 | - $field, |
|
1628 | - $currency |
|
1629 | - ); |
|
1617 | + 'wpinv_get_invoice_recurring_details', |
|
1618 | + array( |
|
1619 | + 'cart_details' => $this->get_cart_details(), |
|
1620 | + 'subtotal' => $this->totals['subtotal']['recurring'], |
|
1621 | + 'discount' => $this->totals['discount']['recurring'], |
|
1622 | + 'tax' => $this->totals['tax']['recurring'], |
|
1623 | + 'fee' => $this->totals['fee']['recurring'], |
|
1624 | + 'total' => $this->get_recurring_total(), |
|
1625 | + ), |
|
1626 | + $this, |
|
1627 | + $field, |
|
1628 | + $currency |
|
1629 | + ); |
|
1630 | 1630 | |
1631 | 1631 | if ( isset( $data[ $field ] ) ) { |
1632 | 1632 | return ( $currency ? wpinv_price( $data[ $field ], $this->get_currency() ) : $data[ $field ] ); |
@@ -1636,166 +1636,166 @@ discard block |
||
1636 | 1636 | } |
1637 | 1637 | |
1638 | 1638 | /** |
1639 | - * Get the invoice fees. |
|
1640 | - * |
|
1641 | - * @since 1.0.19 |
|
1642 | - * @param string $context View or edit context. |
|
1643 | - * @return array |
|
1644 | - */ |
|
1645 | - public function get_fees( $context = 'view' ) { |
|
1646 | - return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
1639 | + * Get the invoice fees. |
|
1640 | + * |
|
1641 | + * @since 1.0.19 |
|
1642 | + * @param string $context View or edit context. |
|
1643 | + * @return array |
|
1644 | + */ |
|
1645 | + public function get_fees( $context = 'view' ) { |
|
1646 | + return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
1647 | 1647 | } |
1648 | 1648 | |
1649 | 1649 | /** |
1650 | - * Get the invoice discounts. |
|
1651 | - * |
|
1652 | - * @since 1.0.19 |
|
1653 | - * @param string $context View or edit context. |
|
1654 | - * @return array |
|
1655 | - */ |
|
1656 | - public function get_discounts( $context = 'view' ) { |
|
1657 | - return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
1650 | + * Get the invoice discounts. |
|
1651 | + * |
|
1652 | + * @since 1.0.19 |
|
1653 | + * @param string $context View or edit context. |
|
1654 | + * @return array |
|
1655 | + */ |
|
1656 | + public function get_discounts( $context = 'view' ) { |
|
1657 | + return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
1658 | 1658 | } |
1659 | 1659 | |
1660 | 1660 | /** |
1661 | - * Get the invoice taxes. |
|
1662 | - * |
|
1663 | - * @since 1.0.19 |
|
1664 | - * @param string $context View or edit context. |
|
1665 | - * @return array |
|
1666 | - */ |
|
1667 | - public function get_taxes( $context = 'view' ) { |
|
1668 | - return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
1661 | + * Get the invoice taxes. |
|
1662 | + * |
|
1663 | + * @since 1.0.19 |
|
1664 | + * @param string $context View or edit context. |
|
1665 | + * @return array |
|
1666 | + */ |
|
1667 | + public function get_taxes( $context = 'view' ) { |
|
1668 | + return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
1669 | 1669 | } |
1670 | 1670 | |
1671 | 1671 | /** |
1672 | - * Get the invoice items. |
|
1673 | - * |
|
1674 | - * @since 1.0.19 |
|
1675 | - * @param string $context View or edit context. |
|
1676 | - * @return GetPaid_Form_Item[] |
|
1677 | - */ |
|
1678 | - public function get_items( $context = 'view' ) { |
|
1672 | + * Get the invoice items. |
|
1673 | + * |
|
1674 | + * @since 1.0.19 |
|
1675 | + * @param string $context View or edit context. |
|
1676 | + * @return GetPaid_Form_Item[] |
|
1677 | + */ |
|
1678 | + public function get_items( $context = 'view' ) { |
|
1679 | 1679 | return $this->get_prop( 'items', $context ); |
1680 | - } |
|
1680 | + } |
|
1681 | 1681 | |
1682 | - /** |
|
1683 | - * Get the invoice item ids. |
|
1684 | - * |
|
1685 | - * @since 1.0.19 |
|
1686 | - * @return string |
|
1687 | - */ |
|
1688 | - public function get_item_ids() { |
|
1689 | - return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) ); |
|
1682 | + /** |
|
1683 | + * Get the invoice item ids. |
|
1684 | + * |
|
1685 | + * @since 1.0.19 |
|
1686 | + * @return string |
|
1687 | + */ |
|
1688 | + public function get_item_ids() { |
|
1689 | + return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) ); |
|
1690 | 1690 | } |
1691 | 1691 | |
1692 | 1692 | /** |
1693 | - * Get the invoice's payment form. |
|
1694 | - * |
|
1695 | - * @since 1.0.19 |
|
1696 | - * @param string $context View or edit context. |
|
1697 | - * @return int |
|
1698 | - */ |
|
1699 | - public function get_payment_form( $context = 'view' ) { |
|
1700 | - return intval( $this->get_prop( 'payment_form', $context ) ); |
|
1693 | + * Get the invoice's payment form. |
|
1694 | + * |
|
1695 | + * @since 1.0.19 |
|
1696 | + * @param string $context View or edit context. |
|
1697 | + * @return int |
|
1698 | + */ |
|
1699 | + public function get_payment_form( $context = 'view' ) { |
|
1700 | + return intval( $this->get_prop( 'payment_form', $context ) ); |
|
1701 | 1701 | } |
1702 | 1702 | |
1703 | 1703 | /** |
1704 | - * Get the invoice's submission id. |
|
1705 | - * |
|
1706 | - * @since 1.0.19 |
|
1707 | - * @param string $context View or edit context. |
|
1708 | - * @return string |
|
1709 | - */ |
|
1710 | - public function get_submission_id( $context = 'view' ) { |
|
1711 | - return $this->get_prop( 'submission_id', $context ); |
|
1704 | + * Get the invoice's submission id. |
|
1705 | + * |
|
1706 | + * @since 1.0.19 |
|
1707 | + * @param string $context View or edit context. |
|
1708 | + * @return string |
|
1709 | + */ |
|
1710 | + public function get_submission_id( $context = 'view' ) { |
|
1711 | + return $this->get_prop( 'submission_id', $context ); |
|
1712 | 1712 | } |
1713 | 1713 | |
1714 | 1714 | /** |
1715 | - * Get the invoice's discount code. |
|
1716 | - * |
|
1717 | - * @since 1.0.19 |
|
1718 | - * @param string $context View or edit context. |
|
1719 | - * @return string |
|
1720 | - */ |
|
1721 | - public function get_discount_code( $context = 'view' ) { |
|
1722 | - return $this->get_prop( 'discount_code', $context ); |
|
1715 | + * Get the invoice's discount code. |
|
1716 | + * |
|
1717 | + * @since 1.0.19 |
|
1718 | + * @param string $context View or edit context. |
|
1719 | + * @return string |
|
1720 | + */ |
|
1721 | + public function get_discount_code( $context = 'view' ) { |
|
1722 | + return $this->get_prop( 'discount_code', $context ); |
|
1723 | 1723 | } |
1724 | 1724 | |
1725 | 1725 | /** |
1726 | - * Get the invoice's gateway. |
|
1727 | - * |
|
1728 | - * @since 1.0.19 |
|
1729 | - * @param string $context View or edit context. |
|
1730 | - * @return string |
|
1731 | - */ |
|
1732 | - public function get_gateway( $context = 'view' ) { |
|
1733 | - return $this->get_prop( 'gateway', $context ); |
|
1726 | + * Get the invoice's gateway. |
|
1727 | + * |
|
1728 | + * @since 1.0.19 |
|
1729 | + * @param string $context View or edit context. |
|
1730 | + * @return string |
|
1731 | + */ |
|
1732 | + public function get_gateway( $context = 'view' ) { |
|
1733 | + return $this->get_prop( 'gateway', $context ); |
|
1734 | 1734 | } |
1735 | 1735 | |
1736 | 1736 | /** |
1737 | - * Get the invoice's gateway display title. |
|
1738 | - * |
|
1739 | - * @since 1.0.19 |
|
1740 | - * @return string |
|
1741 | - */ |
|
1737 | + * Get the invoice's gateway display title. |
|
1738 | + * |
|
1739 | + * @since 1.0.19 |
|
1740 | + * @return string |
|
1741 | + */ |
|
1742 | 1742 | public function get_gateway_title() { |
1743 | 1743 | $title = wpinv_get_gateway_checkout_label( $this->get_gateway() ); |
1744 | 1744 | return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this ); |
1745 | 1745 | } |
1746 | 1746 | |
1747 | 1747 | /** |
1748 | - * Get the invoice's transaction id. |
|
1749 | - * |
|
1750 | - * @since 1.0.19 |
|
1751 | - * @param string $context View or edit context. |
|
1752 | - * @return string |
|
1753 | - */ |
|
1754 | - public function get_transaction_id( $context = 'view' ) { |
|
1755 | - return $this->get_prop( 'transaction_id', $context ); |
|
1748 | + * Get the invoice's transaction id. |
|
1749 | + * |
|
1750 | + * @since 1.0.19 |
|
1751 | + * @param string $context View or edit context. |
|
1752 | + * @return string |
|
1753 | + */ |
|
1754 | + public function get_transaction_id( $context = 'view' ) { |
|
1755 | + return $this->get_prop( 'transaction_id', $context ); |
|
1756 | 1756 | } |
1757 | 1757 | |
1758 | 1758 | /** |
1759 | - * Get the invoice's currency. |
|
1760 | - * |
|
1761 | - * @since 1.0.19 |
|
1762 | - * @param string $context View or edit context. |
|
1763 | - * @return string |
|
1764 | - */ |
|
1765 | - public function get_currency( $context = 'view' ) { |
|
1759 | + * Get the invoice's currency. |
|
1760 | + * |
|
1761 | + * @since 1.0.19 |
|
1762 | + * @param string $context View or edit context. |
|
1763 | + * @return string |
|
1764 | + */ |
|
1765 | + public function get_currency( $context = 'view' ) { |
|
1766 | 1766 | $currency = $this->get_prop( 'currency', $context ); |
1767 | 1767 | return empty( $currency ) ? wpinv_get_currency() : $currency; |
1768 | 1768 | } |
1769 | 1769 | |
1770 | 1770 | /** |
1771 | - * Checks if we are charging taxes for this invoice. |
|
1772 | - * |
|
1773 | - * @since 1.0.19 |
|
1774 | - * @param string $context View or edit context. |
|
1775 | - * @return bool |
|
1776 | - */ |
|
1777 | - public function get_disable_taxes( $context = 'view' ) { |
|
1771 | + * Checks if we are charging taxes for this invoice. |
|
1772 | + * |
|
1773 | + * @since 1.0.19 |
|
1774 | + * @param string $context View or edit context. |
|
1775 | + * @return bool |
|
1776 | + */ |
|
1777 | + public function get_disable_taxes( $context = 'view' ) { |
|
1778 | 1778 | return (bool) $this->get_prop( 'disable_taxes', $context ); |
1779 | 1779 | } |
1780 | 1780 | |
1781 | 1781 | /** |
1782 | - * Retrieves the subscription id for an invoice. |
|
1783 | - * |
|
1784 | - * @since 1.0.19 |
|
1785 | - * @param string $context View or edit context. |
|
1786 | - * @return int |
|
1787 | - */ |
|
1782 | + * Retrieves the subscription id for an invoice. |
|
1783 | + * |
|
1784 | + * @since 1.0.19 |
|
1785 | + * @param string $context View or edit context. |
|
1786 | + * @return int |
|
1787 | + */ |
|
1788 | 1788 | public function get_subscription_id( $context = 'view' ) { |
1789 | - return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
1790 | - } |
|
1791 | - |
|
1792 | - /** |
|
1793 | - * Retrieves the remote subscription id for an invoice. |
|
1794 | - * |
|
1795 | - * @since 1.0.19 |
|
1796 | - * @param string $context View or edit context. |
|
1797 | - * @return int |
|
1798 | - */ |
|
1789 | + return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
1790 | + } |
|
1791 | + |
|
1792 | + /** |
|
1793 | + * Retrieves the remote subscription id for an invoice. |
|
1794 | + * |
|
1795 | + * @since 1.0.19 |
|
1796 | + * @param string $context View or edit context. |
|
1797 | + * @return int |
|
1798 | + */ |
|
1799 | 1799 | public function get_remote_subscription_id( $context = 'view' ) { |
1800 | 1800 | $subscription_id = $this->get_prop( 'remote_subscription_id', $context ); |
1801 | 1801 | |
@@ -1808,23 +1808,23 @@ discard block |
||
1808 | 1808 | } |
1809 | 1809 | |
1810 | 1810 | /** |
1811 | - * Get the invoice's _anonymize status. |
|
1812 | - * |
|
1813 | - * @since 2.8.22 |
|
1814 | - * @param string $context View or edit context. |
|
1815 | - * @return string |
|
1816 | - */ |
|
1817 | - public function get_is_anonymized( $context = 'view' ) { |
|
1818 | - return (bool) $this->get_prop( 'is_anonymized', $context ); |
|
1811 | + * Get the invoice's _anonymize status. |
|
1812 | + * |
|
1813 | + * @since 2.8.22 |
|
1814 | + * @param string $context View or edit context. |
|
1815 | + * @return string |
|
1816 | + */ |
|
1817 | + public function get_is_anonymized( $context = 'view' ) { |
|
1818 | + return (bool) $this->get_prop( 'is_anonymized', $context ); |
|
1819 | 1819 | } |
1820 | 1820 | |
1821 | 1821 | /** |
1822 | - * Retrieves the payment meta for an invoice. |
|
1823 | - * |
|
1824 | - * @since 1.0.19 |
|
1825 | - * @param string $context View or edit context. |
|
1826 | - * @return array |
|
1827 | - */ |
|
1822 | + * Retrieves the payment meta for an invoice. |
|
1823 | + * |
|
1824 | + * @since 1.0.19 |
|
1825 | + * @param string $context View or edit context. |
|
1826 | + * @return array |
|
1827 | + */ |
|
1828 | 1828 | public function get_payment_meta( $context = 'view' ) { |
1829 | 1829 | |
1830 | 1830 | return array( |
@@ -1843,31 +1843,31 @@ discard block |
||
1843 | 1843 | } |
1844 | 1844 | |
1845 | 1845 | /** |
1846 | - * Retrieves the cart details for an invoice. |
|
1847 | - * |
|
1848 | - * @since 1.0.19 |
|
1849 | - * @return array |
|
1850 | - */ |
|
1846 | + * Retrieves the cart details for an invoice. |
|
1847 | + * |
|
1848 | + * @since 1.0.19 |
|
1849 | + * @return array |
|
1850 | + */ |
|
1851 | 1851 | public function get_cart_details() { |
1852 | 1852 | $items = $this->get_items(); |
1853 | 1853 | $cart_details = array(); |
1854 | 1854 | |
1855 | 1855 | foreach ( $items as $item ) { |
1856 | - $item->invoice_id = $this->get_id(); |
|
1856 | + $item->invoice_id = $this->get_id(); |
|
1857 | 1857 | $cart_details[] = $item->prepare_data_for_saving(); |
1858 | 1858 | } |
1859 | 1859 | |
1860 | 1860 | return $cart_details; |
1861 | - } |
|
1861 | + } |
|
1862 | 1862 | |
1863 | - /** |
|
1864 | - * Retrieves the recurring item. |
|
1865 | - * |
|
1866 | - * @return null|GetPaid_Form_Item|int |
|
1867 | - */ |
|
1868 | - public function get_recurring( $object = false ) { |
|
1863 | + /** |
|
1864 | + * Retrieves the recurring item. |
|
1865 | + * |
|
1866 | + * @return null|GetPaid_Form_Item|int |
|
1867 | + */ |
|
1868 | + public function get_recurring( $object = false ) { |
|
1869 | 1869 | |
1870 | - // Are we returning an object? |
|
1870 | + // Are we returning an object? |
|
1871 | 1871 | if ( $object ) { |
1872 | 1872 | return $this->get_item( $this->recurring_item ); |
1873 | 1873 | } |
@@ -1875,129 +1875,129 @@ discard block |
||
1875 | 1875 | return $this->recurring_item; |
1876 | 1876 | } |
1877 | 1877 | |
1878 | - /** |
|
1879 | - * Retrieves the subscription name. |
|
1880 | - * |
|
1881 | - * @since 1.0.19 |
|
1882 | - * @return string |
|
1883 | - */ |
|
1884 | - public function get_subscription_name() { |
|
1878 | + /** |
|
1879 | + * Retrieves the subscription name. |
|
1880 | + * |
|
1881 | + * @since 1.0.19 |
|
1882 | + * @return string |
|
1883 | + */ |
|
1884 | + public function get_subscription_name() { |
|
1885 | 1885 | |
1886 | - // Retrieve the recurring name |
|
1886 | + // Retrieve the recurring name |
|
1887 | 1887 | $item = $this->get_recurring( true ); |
1888 | 1888 | |
1889 | - // Abort if it does not exist. |
|
1889 | + // Abort if it does not exist. |
|
1890 | 1890 | if ( empty( $item ) ) { |
1891 | 1891 | return ''; |
1892 | 1892 | } |
1893 | 1893 | |
1894 | - // Return the item name. |
|
1894 | + // Return the item name. |
|
1895 | 1895 | return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this ); |
1896 | - } |
|
1897 | - |
|
1898 | - /** |
|
1899 | - * Retrieves the view url. |
|
1900 | - * |
|
1901 | - * @since 1.0.19 |
|
1902 | - * @return string |
|
1903 | - */ |
|
1904 | - public function get_view_url() { |
|
1896 | + } |
|
1897 | + |
|
1898 | + /** |
|
1899 | + * Retrieves the view url. |
|
1900 | + * |
|
1901 | + * @since 1.0.19 |
|
1902 | + * @return string |
|
1903 | + */ |
|
1904 | + public function get_view_url() { |
|
1905 | 1905 | $invoice_url = get_permalink( $this->get_id() ); |
1906 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
1906 | + $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
1907 | 1907 | return apply_filters( 'wpinv_get_view_url', $invoice_url, $this ); |
1908 | - } |
|
1908 | + } |
|
1909 | 1909 | |
1910 | - /** |
|
1911 | - * Retrieves the payment url. |
|
1912 | - * |
|
1913 | - * @since 1.0.19 |
|
1914 | - * @return string |
|
1915 | - */ |
|
1916 | - public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
1910 | + /** |
|
1911 | + * Retrieves the payment url. |
|
1912 | + * |
|
1913 | + * @since 1.0.19 |
|
1914 | + * @return string |
|
1915 | + */ |
|
1916 | + public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
1917 | 1917 | |
1918 | - // Retrieve the checkout url. |
|
1918 | + // Retrieve the checkout url. |
|
1919 | 1919 | $pay_url = wpinv_get_checkout_uri(); |
1920 | 1920 | |
1921 | - // Maybe force ssl. |
|
1921 | + // Maybe force ssl. |
|
1922 | 1922 | if ( is_ssl() ) { |
1923 | 1923 | $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
1924 | 1924 | } |
1925 | 1925 | |
1926 | - // Add the invoice key. |
|
1927 | - $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
1926 | + // Add the invoice key. |
|
1927 | + $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
1928 | 1928 | |
1929 | - // (Maybe?) add a secret |
|
1929 | + // (Maybe?) add a secret |
|
1930 | 1930 | if ( $secret ) { |
1931 | 1931 | $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url ); |
1932 | 1932 | } |
1933 | 1933 | |
1934 | 1934 | return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret ); |
1935 | - } |
|
1935 | + } |
|
1936 | + |
|
1937 | + /** |
|
1938 | + * Retrieves the receipt url. |
|
1939 | + * |
|
1940 | + * @since 1.0.19 |
|
1941 | + * @return string |
|
1942 | + */ |
|
1943 | + public function get_receipt_url() { |
|
1944 | + |
|
1945 | + // Retrieve the checkout url. |
|
1946 | + $receipt_url = wpinv_get_success_page_uri(); |
|
1947 | + |
|
1948 | + // Maybe force ssl. |
|
1949 | + if ( is_ssl() ) { |
|
1950 | + $receipt_url = str_replace( 'http:', 'https:', $receipt_url ); |
|
1951 | + } |
|
1952 | + |
|
1953 | + // Add the invoice key. |
|
1954 | + $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
1955 | + |
|
1956 | + return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this ); |
|
1957 | + } |
|
1958 | + |
|
1959 | + /** |
|
1960 | + * Retrieves the remote transaction url. |
|
1961 | + * |
|
1962 | + * @since 1.6.0 |
|
1963 | + * @return string |
|
1964 | + */ |
|
1965 | + public function get_transaction_url() { |
|
1966 | + return apply_filters( 'getpaid_gateway_' . $this->get_gateway() . '_transaction_url', '', $this ); |
|
1967 | + } |
|
1968 | + |
|
1969 | + /** |
|
1970 | + * Retrieves the default status. |
|
1971 | + * |
|
1972 | + * @since 1.0.19 |
|
1973 | + * @return string |
|
1974 | + */ |
|
1975 | + public function get_default_status() { |
|
1936 | 1976 | |
1937 | - /** |
|
1938 | - * Retrieves the receipt url. |
|
1939 | - * |
|
1940 | - * @since 1.0.19 |
|
1941 | - * @return string |
|
1942 | - */ |
|
1943 | - public function get_receipt_url() { |
|
1977 | + $type = $this->get_type(); |
|
1978 | + $status = "wpi-$type-pending"; |
|
1979 | + return str_replace( '-invoice', '', $status ); |
|
1980 | + } |
|
1944 | 1981 | |
1945 | - // Retrieve the checkout url. |
|
1946 | - $receipt_url = wpinv_get_success_page_uri(); |
|
1982 | + /** |
|
1983 | + * Magic method for accessing invoice properties. |
|
1984 | + * |
|
1985 | + * @since 1.0.15 |
|
1986 | + * @access public |
|
1987 | + * |
|
1988 | + * @param string $key Discount data to retrieve |
|
1989 | + * @param string $context View or edit context. |
|
1990 | + * @return mixed Value of the given invoice property (if set). |
|
1991 | + */ |
|
1992 | + public function get( $key, $context = 'view' ) { |
|
1993 | + $method = "get_$key"; |
|
1947 | 1994 | |
1948 | - // Maybe force ssl. |
|
1949 | - if ( is_ssl() ) { |
|
1950 | - $receipt_url = str_replace( 'http:', 'https:', $receipt_url ); |
|
1995 | + if ( is_callable( array( $this, $method ) ) ) { |
|
1996 | + return $this->$method( $context ); |
|
1951 | 1997 | } |
1952 | 1998 | |
1953 | - // Add the invoice key. |
|
1954 | - $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
1955 | - |
|
1956 | - return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this ); |
|
1957 | - } |
|
1958 | - |
|
1959 | - /** |
|
1960 | - * Retrieves the remote transaction url. |
|
1961 | - * |
|
1962 | - * @since 1.6.0 |
|
1963 | - * @return string |
|
1964 | - */ |
|
1965 | - public function get_transaction_url() { |
|
1966 | - return apply_filters( 'getpaid_gateway_' . $this->get_gateway() . '_transaction_url', '', $this ); |
|
1967 | - } |
|
1968 | - |
|
1969 | - /** |
|
1970 | - * Retrieves the default status. |
|
1971 | - * |
|
1972 | - * @since 1.0.19 |
|
1973 | - * @return string |
|
1974 | - */ |
|
1975 | - public function get_default_status() { |
|
1976 | - |
|
1977 | - $type = $this->get_type(); |
|
1978 | - $status = "wpi-$type-pending"; |
|
1979 | - return str_replace( '-invoice', '', $status ); |
|
1980 | - } |
|
1981 | - |
|
1982 | - /** |
|
1983 | - * Magic method for accessing invoice properties. |
|
1984 | - * |
|
1985 | - * @since 1.0.15 |
|
1986 | - * @access public |
|
1987 | - * |
|
1988 | - * @param string $key Discount data to retrieve |
|
1989 | - * @param string $context View or edit context. |
|
1990 | - * @return mixed Value of the given invoice property (if set). |
|
1991 | - */ |
|
1992 | - public function get( $key, $context = 'view' ) { |
|
1993 | - $method = "get_$key"; |
|
1994 | - |
|
1995 | - if ( is_callable( array( $this, $method ) ) ) { |
|
1996 | - return $this->$method( $context ); |
|
1997 | - } |
|
1998 | - |
|
1999 | 1999 | return $this->get_prop( $key, $context ); |
2000 | - } |
|
2000 | + } |
|
2001 | 2001 | |
2002 | 2002 | /* |
2003 | 2003 | |-------------------------------------------------------------------------- |
@@ -2010,128 +2010,128 @@ discard block |
||
2010 | 2010 | */ |
2011 | 2011 | |
2012 | 2012 | /** |
2013 | - * Magic method for setting invoice properties. |
|
2014 | - * |
|
2015 | - * @since 1.0.19 |
|
2016 | - * @access public |
|
2017 | - * |
|
2018 | - * @param string $key Discount data to retrieve |
|
2019 | - * @param mixed $value new value. |
|
2020 | - * @return mixed Value of the given invoice property (if set). |
|
2021 | - */ |
|
2022 | - public function set( $key, $value ) { |
|
2013 | + * Magic method for setting invoice properties. |
|
2014 | + * |
|
2015 | + * @since 1.0.19 |
|
2016 | + * @access public |
|
2017 | + * |
|
2018 | + * @param string $key Discount data to retrieve |
|
2019 | + * @param mixed $value new value. |
|
2020 | + * @return mixed Value of the given invoice property (if set). |
|
2021 | + */ |
|
2022 | + public function set( $key, $value ) { |
|
2023 | 2023 | |
2024 | 2024 | $setter = "set_$key"; |
2025 | 2025 | if ( is_callable( array( $this, $setter ) ) ) { |
2026 | 2026 | $this->{$setter}( $value ); |
2027 | 2027 | } |
2028 | - } |
|
2029 | - |
|
2030 | - /** |
|
2031 | - * Sets item status. |
|
2032 | - * |
|
2033 | - * @since 1.0.19 |
|
2034 | - * @param string $new_status New status. |
|
2035 | - * @param string $note Optional note to add. |
|
2036 | - * @param bool $manual_update Is this a manual status change?. |
|
2037 | - * @return array details of change. |
|
2038 | - */ |
|
2039 | - public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
2040 | - $old_status = $this->get_status(); |
|
2041 | - |
|
2042 | - $statuses = $this->get_all_statuses(); |
|
2043 | - |
|
2044 | - if ( isset( $statuses['draft'] ) ) { |
|
2045 | - unset( $statuses['draft'] ); |
|
2046 | - } |
|
2047 | - |
|
2048 | - $this->set_prop( 'status', $new_status ); |
|
2049 | - |
|
2050 | - // If setting the status, ensure it's set to a valid status. |
|
2051 | - if ( true === $this->object_read ) { |
|
2052 | - |
|
2053 | - // Only allow valid new status. |
|
2054 | - if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
2055 | - $new_status = $this->get_default_status(); |
|
2056 | - } |
|
2057 | - |
|
2058 | - // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
2059 | - if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
2060 | - $old_status = $this->get_default_status(); |
|
2061 | - } |
|
2062 | - |
|
2063 | - // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
2064 | - if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
2065 | - $old_status = 'wpi-pending'; |
|
2066 | - } |
|
2067 | - |
|
2068 | - if ( $old_status !== $new_status ) { |
|
2069 | - $this->status_transition = array( |
|
2070 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
2071 | - 'to' => $new_status, |
|
2072 | - 'note' => $note, |
|
2073 | - 'manual' => (bool) $manual_update, |
|
2074 | - ); |
|
2075 | - |
|
2076 | - if ( $manual_update ) { |
|
2077 | - do_action( 'getpaid_' . $this->object_type . '_edit_status', $this->get_id(), $new_status ); |
|
2078 | - } |
|
2079 | - |
|
2080 | - $this->maybe_set_date_paid(); |
|
2081 | - |
|
2082 | - } |
|
2083 | - } |
|
2084 | - |
|
2085 | - return array( |
|
2086 | - 'from' => $old_status, |
|
2087 | - 'to' => $new_status, |
|
2088 | - ); |
|
2089 | - } |
|
2090 | - |
|
2091 | - /** |
|
2092 | - * Maybe set date paid. |
|
2093 | - * |
|
2094 | - * Sets the date paid variable when transitioning to the payment complete |
|
2095 | - * order status. |
|
2096 | - * |
|
2097 | - * @since 1.0.19 |
|
2098 | - */ |
|
2099 | - public function maybe_set_date_paid() { |
|
2100 | - |
|
2101 | - if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
2102 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
2103 | - } |
|
2104 | - } |
|
2105 | - |
|
2106 | - /** |
|
2107 | - * Set parent invoice ID. |
|
2108 | - * |
|
2109 | - * @since 1.0.19 |
|
2110 | - */ |
|
2111 | - public function set_parent_id( $value ) { |
|
2112 | - if ( $value && ( $value === $this->get_id() ) ) { |
|
2113 | - return; |
|
2114 | - } |
|
2115 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
2116 | - } |
|
2117 | - |
|
2118 | - /** |
|
2119 | - * Set plugin version when the invoice was created. |
|
2120 | - * |
|
2121 | - * @since 1.0.19 |
|
2122 | - */ |
|
2123 | - public function set_version( $value ) { |
|
2124 | - $this->set_prop( 'version', $value ); |
|
2125 | - } |
|
2126 | - |
|
2127 | - /** |
|
2128 | - * Set date when the invoice was created. |
|
2129 | - * |
|
2130 | - * @since 1.0.19 |
|
2131 | - * @param string $value Value to set. |
|
2028 | + } |
|
2029 | + |
|
2030 | + /** |
|
2031 | + * Sets item status. |
|
2032 | + * |
|
2033 | + * @since 1.0.19 |
|
2034 | + * @param string $new_status New status. |
|
2035 | + * @param string $note Optional note to add. |
|
2036 | + * @param bool $manual_update Is this a manual status change?. |
|
2037 | + * @return array details of change. |
|
2038 | + */ |
|
2039 | + public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
2040 | + $old_status = $this->get_status(); |
|
2041 | + |
|
2042 | + $statuses = $this->get_all_statuses(); |
|
2043 | + |
|
2044 | + if ( isset( $statuses['draft'] ) ) { |
|
2045 | + unset( $statuses['draft'] ); |
|
2046 | + } |
|
2047 | + |
|
2048 | + $this->set_prop( 'status', $new_status ); |
|
2049 | + |
|
2050 | + // If setting the status, ensure it's set to a valid status. |
|
2051 | + if ( true === $this->object_read ) { |
|
2052 | + |
|
2053 | + // Only allow valid new status. |
|
2054 | + if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
2055 | + $new_status = $this->get_default_status(); |
|
2056 | + } |
|
2057 | + |
|
2058 | + // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
2059 | + if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
2060 | + $old_status = $this->get_default_status(); |
|
2061 | + } |
|
2062 | + |
|
2063 | + // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
2064 | + if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
2065 | + $old_status = 'wpi-pending'; |
|
2066 | + } |
|
2067 | + |
|
2068 | + if ( $old_status !== $new_status ) { |
|
2069 | + $this->status_transition = array( |
|
2070 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
2071 | + 'to' => $new_status, |
|
2072 | + 'note' => $note, |
|
2073 | + 'manual' => (bool) $manual_update, |
|
2074 | + ); |
|
2075 | + |
|
2076 | + if ( $manual_update ) { |
|
2077 | + do_action( 'getpaid_' . $this->object_type . '_edit_status', $this->get_id(), $new_status ); |
|
2078 | + } |
|
2079 | + |
|
2080 | + $this->maybe_set_date_paid(); |
|
2081 | + |
|
2082 | + } |
|
2083 | + } |
|
2084 | + |
|
2085 | + return array( |
|
2086 | + 'from' => $old_status, |
|
2087 | + 'to' => $new_status, |
|
2088 | + ); |
|
2089 | + } |
|
2090 | + |
|
2091 | + /** |
|
2092 | + * Maybe set date paid. |
|
2093 | + * |
|
2094 | + * Sets the date paid variable when transitioning to the payment complete |
|
2095 | + * order status. |
|
2096 | + * |
|
2097 | + * @since 1.0.19 |
|
2098 | + */ |
|
2099 | + public function maybe_set_date_paid() { |
|
2100 | + |
|
2101 | + if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
2102 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
2103 | + } |
|
2104 | + } |
|
2105 | + |
|
2106 | + /** |
|
2107 | + * Set parent invoice ID. |
|
2108 | + * |
|
2109 | + * @since 1.0.19 |
|
2110 | + */ |
|
2111 | + public function set_parent_id( $value ) { |
|
2112 | + if ( $value && ( $value === $this->get_id() ) ) { |
|
2113 | + return; |
|
2114 | + } |
|
2115 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
2116 | + } |
|
2117 | + |
|
2118 | + /** |
|
2119 | + * Set plugin version when the invoice was created. |
|
2120 | + * |
|
2121 | + * @since 1.0.19 |
|
2122 | + */ |
|
2123 | + public function set_version( $value ) { |
|
2124 | + $this->set_prop( 'version', $value ); |
|
2125 | + } |
|
2126 | + |
|
2127 | + /** |
|
2128 | + * Set date when the invoice was created. |
|
2129 | + * |
|
2130 | + * @since 1.0.19 |
|
2131 | + * @param string $value Value to set. |
|
2132 | 2132 | * @return bool Whether or not the date was set. |
2133 | - */ |
|
2134 | - public function set_date_created( $value ) { |
|
2133 | + */ |
|
2134 | + public function set_date_created( $value ) { |
|
2135 | 2135 | $date = strtotime( $value ); |
2136 | 2136 | |
2137 | 2137 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2139,18 +2139,18 @@ discard block |
||
2139 | 2139 | return true; |
2140 | 2140 | } |
2141 | 2141 | |
2142 | - $this->set_prop( 'date_created', '' ); |
|
2143 | - return false; |
|
2142 | + $this->set_prop( 'date_created', '' ); |
|
2143 | + return false; |
|
2144 | 2144 | } |
2145 | 2145 | |
2146 | 2146 | /** |
2147 | - * Set date invoice due date. |
|
2148 | - * |
|
2149 | - * @since 1.0.19 |
|
2150 | - * @param string $value Value to set. |
|
2147 | + * Set date invoice due date. |
|
2148 | + * |
|
2149 | + * @since 1.0.19 |
|
2150 | + * @param string $value Value to set. |
|
2151 | 2151 | * @return bool Whether or not the date was set. |
2152 | - */ |
|
2153 | - public function set_due_date( $value ) { |
|
2152 | + */ |
|
2153 | + public function set_due_date( $value ) { |
|
2154 | 2154 | $date = strtotime( $value ); |
2155 | 2155 | |
2156 | 2156 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2158,28 +2158,28 @@ discard block |
||
2158 | 2158 | return true; |
2159 | 2159 | } |
2160 | 2160 | |
2161 | - $this->set_prop( 'due_date', '' ); |
|
2161 | + $this->set_prop( 'due_date', '' ); |
|
2162 | 2162 | return false; |
2163 | 2163 | } |
2164 | 2164 | |
2165 | 2165 | /** |
2166 | - * Alias of self::set_due_date(). |
|
2167 | - * |
|
2168 | - * @since 1.0.19 |
|
2169 | - * @param string $value New name. |
|
2170 | - */ |
|
2171 | - public function set_date_due( $value ) { |
|
2172 | - $this->set_due_date( $value ); |
|
2166 | + * Alias of self::set_due_date(). |
|
2167 | + * |
|
2168 | + * @since 1.0.19 |
|
2169 | + * @param string $value New name. |
|
2170 | + */ |
|
2171 | + public function set_date_due( $value ) { |
|
2172 | + $this->set_due_date( $value ); |
|
2173 | 2173 | } |
2174 | 2174 | |
2175 | 2175 | /** |
2176 | - * Set date invoice was completed. |
|
2177 | - * |
|
2178 | - * @since 1.0.19 |
|
2179 | - * @param string $value Value to set. |
|
2176 | + * Set date invoice was completed. |
|
2177 | + * |
|
2178 | + * @since 1.0.19 |
|
2179 | + * @param string $value Value to set. |
|
2180 | 2180 | * @return bool Whether or not the date was set. |
2181 | - */ |
|
2182 | - public function set_completed_date( $value ) { |
|
2181 | + */ |
|
2182 | + public function set_completed_date( $value ) { |
|
2183 | 2183 | $date = strtotime( $value ); |
2184 | 2184 | |
2185 | 2185 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2187,28 +2187,28 @@ discard block |
||
2187 | 2187 | return true; |
2188 | 2188 | } |
2189 | 2189 | |
2190 | - $this->set_prop( 'completed_date', '' ); |
|
2190 | + $this->set_prop( 'completed_date', '' ); |
|
2191 | 2191 | return false; |
2192 | 2192 | } |
2193 | 2193 | |
2194 | 2194 | /** |
2195 | - * Alias of self::set_completed_date(). |
|
2196 | - * |
|
2197 | - * @since 1.0.19 |
|
2198 | - * @param string $value New name. |
|
2199 | - */ |
|
2200 | - public function set_date_completed( $value ) { |
|
2201 | - $this->set_completed_date( $value ); |
|
2195 | + * Alias of self::set_completed_date(). |
|
2196 | + * |
|
2197 | + * @since 1.0.19 |
|
2198 | + * @param string $value New name. |
|
2199 | + */ |
|
2200 | + public function set_date_completed( $value ) { |
|
2201 | + $this->set_completed_date( $value ); |
|
2202 | 2202 | } |
2203 | 2203 | |
2204 | 2204 | /** |
2205 | - * Set date when the invoice was last modified. |
|
2206 | - * |
|
2207 | - * @since 1.0.19 |
|
2208 | - * @param string $value Value to set. |
|
2205 | + * Set date when the invoice was last modified. |
|
2206 | + * |
|
2207 | + * @since 1.0.19 |
|
2208 | + * @param string $value Value to set. |
|
2209 | 2209 | * @return bool Whether or not the date was set. |
2210 | - */ |
|
2211 | - public function set_date_modified( $value ) { |
|
2210 | + */ |
|
2211 | + public function set_date_modified( $value ) { |
|
2212 | 2212 | $date = strtotime( $value ); |
2213 | 2213 | |
2214 | 2214 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2216,809 +2216,809 @@ discard block |
||
2216 | 2216 | return true; |
2217 | 2217 | } |
2218 | 2218 | |
2219 | - $this->set_prop( 'date_modified', '' ); |
|
2219 | + $this->set_prop( 'date_modified', '' ); |
|
2220 | 2220 | return false; |
2221 | 2221 | } |
2222 | 2222 | |
2223 | 2223 | /** |
2224 | - * Set the invoice number. |
|
2225 | - * |
|
2226 | - * @since 1.0.19 |
|
2227 | - * @param string $value New number. |
|
2228 | - */ |
|
2229 | - public function set_number( $value ) { |
|
2224 | + * Set the invoice number. |
|
2225 | + * |
|
2226 | + * @since 1.0.19 |
|
2227 | + * @param string $value New number. |
|
2228 | + */ |
|
2229 | + public function set_number( $value ) { |
|
2230 | 2230 | $number = sanitize_text_field( $value ); |
2231 | - $this->set_prop( 'number', $number ); |
|
2231 | + $this->set_prop( 'number', $number ); |
|
2232 | 2232 | } |
2233 | 2233 | |
2234 | 2234 | /** |
2235 | - * Set the invoice type. |
|
2236 | - * |
|
2237 | - * @since 1.0.19 |
|
2238 | - * @param string $value Type. |
|
2239 | - */ |
|
2240 | - public function set_type( $value ) { |
|
2235 | + * Set the invoice type. |
|
2236 | + * |
|
2237 | + * @since 1.0.19 |
|
2238 | + * @param string $value Type. |
|
2239 | + */ |
|
2240 | + public function set_type( $value ) { |
|
2241 | 2241 | $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) ); |
2242 | - $this->set_prop( 'type', $type ); |
|
2243 | - } |
|
2242 | + $this->set_prop( 'type', $type ); |
|
2243 | + } |
|
2244 | 2244 | |
2245 | 2245 | /** |
2246 | - * Set the invoice post type. |
|
2247 | - * |
|
2248 | - * @since 1.0.19 |
|
2249 | - * @param string $value Post type. |
|
2250 | - */ |
|
2251 | - public function set_post_type( $value ) { |
|
2246 | + * Set the invoice post type. |
|
2247 | + * |
|
2248 | + * @since 1.0.19 |
|
2249 | + * @param string $value Post type. |
|
2250 | + */ |
|
2251 | + public function set_post_type( $value ) { |
|
2252 | 2252 | if ( getpaid_is_invoice_post_type( $value ) ) { |
2253 | - $this->set_type( $value ); |
|
2253 | + $this->set_type( $value ); |
|
2254 | 2254 | $this->set_prop( 'post_type', $value ); |
2255 | 2255 | } |
2256 | 2256 | } |
2257 | 2257 | |
2258 | 2258 | /** |
2259 | - * Set the invoice key. |
|
2260 | - * |
|
2261 | - * @since 1.0.19 |
|
2262 | - * @param string $value New key. |
|
2263 | - */ |
|
2264 | - public function set_key( $value ) { |
|
2259 | + * Set the invoice key. |
|
2260 | + * |
|
2261 | + * @since 1.0.19 |
|
2262 | + * @param string $value New key. |
|
2263 | + */ |
|
2264 | + public function set_key( $value ) { |
|
2265 | 2265 | $key = sanitize_text_field( $value ); |
2266 | - $this->set_prop( 'key', $key ); |
|
2266 | + $this->set_prop( 'key', $key ); |
|
2267 | 2267 | } |
2268 | 2268 | |
2269 | 2269 | /** |
2270 | - * Set the invoice mode. |
|
2271 | - * |
|
2272 | - * @since 1.0.19 |
|
2273 | - * @param string $value mode. |
|
2274 | - */ |
|
2275 | - public function set_mode( $value ) { |
|
2270 | + * Set the invoice mode. |
|
2271 | + * |
|
2272 | + * @since 1.0.19 |
|
2273 | + * @param string $value mode. |
|
2274 | + */ |
|
2275 | + public function set_mode( $value ) { |
|
2276 | 2276 | if ( in_array( $value, array( 'live', 'test' ) ) ) { |
2277 | 2277 | $this->set_prop( 'mode', $value ); |
2278 | 2278 | } |
2279 | 2279 | } |
2280 | 2280 | |
2281 | 2281 | /** |
2282 | - * Set the invoice path. |
|
2283 | - * |
|
2284 | - * @since 1.0.19 |
|
2285 | - * @param string $value path. |
|
2286 | - */ |
|
2287 | - public function set_path( $value ) { |
|
2282 | + * Set the invoice path. |
|
2283 | + * |
|
2284 | + * @since 1.0.19 |
|
2285 | + * @param string $value path. |
|
2286 | + */ |
|
2287 | + public function set_path( $value ) { |
|
2288 | 2288 | $this->set_prop( 'path', $value ); |
2289 | 2289 | } |
2290 | 2290 | |
2291 | 2291 | /** |
2292 | - * Set the invoice name. |
|
2293 | - * |
|
2294 | - * @since 1.0.19 |
|
2295 | - * @param string $value New name. |
|
2296 | - */ |
|
2297 | - public function set_name( $value ) { |
|
2292 | + * Set the invoice name. |
|
2293 | + * |
|
2294 | + * @since 1.0.19 |
|
2295 | + * @param string $value New name. |
|
2296 | + */ |
|
2297 | + public function set_name( $value ) { |
|
2298 | 2298 | $name = sanitize_text_field( $value ); |
2299 | - $this->set_prop( 'name', $name ); |
|
2299 | + $this->set_prop( 'name', $name ); |
|
2300 | 2300 | } |
2301 | 2301 | |
2302 | 2302 | /** |
2303 | - * Alias of self::set_name(). |
|
2304 | - * |
|
2305 | - * @since 1.0.19 |
|
2306 | - * @param string $value New name. |
|
2307 | - */ |
|
2308 | - public function set_title( $value ) { |
|
2309 | - $this->set_name( $value ); |
|
2303 | + * Alias of self::set_name(). |
|
2304 | + * |
|
2305 | + * @since 1.0.19 |
|
2306 | + * @param string $value New name. |
|
2307 | + */ |
|
2308 | + public function set_title( $value ) { |
|
2309 | + $this->set_name( $value ); |
|
2310 | 2310 | } |
2311 | 2311 | |
2312 | 2312 | /** |
2313 | - * Set the invoice description. |
|
2314 | - * |
|
2315 | - * @since 1.0.19 |
|
2316 | - * @param string $value New description. |
|
2317 | - */ |
|
2318 | - public function set_description( $value ) { |
|
2313 | + * Set the invoice description. |
|
2314 | + * |
|
2315 | + * @since 1.0.19 |
|
2316 | + * @param string $value New description. |
|
2317 | + */ |
|
2318 | + public function set_description( $value ) { |
|
2319 | 2319 | $description = wp_kses_post( $value ); |
2320 | - $this->set_prop( 'description', $description ); |
|
2320 | + $this->set_prop( 'description', $description ); |
|
2321 | + } |
|
2322 | + |
|
2323 | + /** |
|
2324 | + * Alias of self::set_description(). |
|
2325 | + * |
|
2326 | + * @since 1.0.19 |
|
2327 | + * @param string $value New description. |
|
2328 | + */ |
|
2329 | + public function set_excerpt( $value ) { |
|
2330 | + $this->set_description( $value ); |
|
2331 | + } |
|
2332 | + |
|
2333 | + /** |
|
2334 | + * Alias of self::set_description(). |
|
2335 | + * |
|
2336 | + * @since 1.0.19 |
|
2337 | + * @param string $value New description. |
|
2338 | + */ |
|
2339 | + public function set_summary( $value ) { |
|
2340 | + $this->set_description( $value ); |
|
2341 | + } |
|
2342 | + |
|
2343 | + /** |
|
2344 | + * Set the receiver of the invoice. |
|
2345 | + * |
|
2346 | + * @since 1.0.19 |
|
2347 | + * @param int $value New author. |
|
2348 | + */ |
|
2349 | + public function set_author( $value ) { |
|
2350 | + $user = get_user_by( 'id', (int) $value ); |
|
2351 | + |
|
2352 | + if ( $user && $user->ID ) { |
|
2353 | + $this->set_prop( 'author', $user->ID ); |
|
2354 | + $this->set_prop( 'email', $user->user_email ); |
|
2355 | + } |
|
2356 | + } |
|
2357 | + |
|
2358 | + /** |
|
2359 | + * Alias of self::set_author(). |
|
2360 | + * |
|
2361 | + * @since 1.0.19 |
|
2362 | + * @param int $value New user id. |
|
2363 | + */ |
|
2364 | + public function set_user_id( $value ) { |
|
2365 | + $this->set_author( $value ); |
|
2366 | + } |
|
2367 | + |
|
2368 | + /** |
|
2369 | + * Sets the customer ID. |
|
2370 | + * |
|
2371 | + * @since 1.0.19 |
|
2372 | + * @param int $value New user id. |
|
2373 | + */ |
|
2374 | + public function set_customer_id( $value ) { |
|
2375 | + $this->set_prop( 'customer_id', (int) $value ); |
|
2376 | + } |
|
2377 | + |
|
2378 | + /** |
|
2379 | + * Set the customer's ip. |
|
2380 | + * |
|
2381 | + * @since 1.0.19 |
|
2382 | + * @param string $value ip address. |
|
2383 | + */ |
|
2384 | + public function set_ip( $value ) { |
|
2385 | + $this->set_prop( 'ip', $value ); |
|
2386 | + } |
|
2387 | + |
|
2388 | + /** |
|
2389 | + * Alias of self::set_ip(). |
|
2390 | + * |
|
2391 | + * @since 1.0.19 |
|
2392 | + * @param string $value ip address. |
|
2393 | + */ |
|
2394 | + public function set_user_ip( $value ) { |
|
2395 | + $this->set_ip( $value ); |
|
2396 | + } |
|
2397 | + |
|
2398 | + /** |
|
2399 | + * Set the customer's first name. |
|
2400 | + * |
|
2401 | + * @since 1.0.19 |
|
2402 | + * @param string $value first name. |
|
2403 | + */ |
|
2404 | + public function set_first_name( $value ) { |
|
2405 | + $this->set_prop( 'first_name', $value ); |
|
2406 | + } |
|
2407 | + |
|
2408 | + /** |
|
2409 | + * Alias of self::set_first_name(). |
|
2410 | + * |
|
2411 | + * @since 1.0.19 |
|
2412 | + * @param string $value first name. |
|
2413 | + */ |
|
2414 | + public function set_user_first_name( $value ) { |
|
2415 | + $this->set_first_name( $value ); |
|
2416 | + } |
|
2417 | + |
|
2418 | + /** |
|
2419 | + * Alias of self::set_first_name(). |
|
2420 | + * |
|
2421 | + * @since 1.0.19 |
|
2422 | + * @param string $value first name. |
|
2423 | + */ |
|
2424 | + public function set_customer_first_name( $value ) { |
|
2425 | + $this->set_first_name( $value ); |
|
2426 | + } |
|
2427 | + |
|
2428 | + /** |
|
2429 | + * Set the customer's last name. |
|
2430 | + * |
|
2431 | + * @since 1.0.19 |
|
2432 | + * @param string $value last name. |
|
2433 | + */ |
|
2434 | + public function set_last_name( $value ) { |
|
2435 | + $this->set_prop( 'last_name', $value ); |
|
2436 | + } |
|
2437 | + |
|
2438 | + /** |
|
2439 | + * Alias of self::set_last_name(). |
|
2440 | + * |
|
2441 | + * @since 1.0.19 |
|
2442 | + * @param string $value last name. |
|
2443 | + */ |
|
2444 | + public function set_user_last_name( $value ) { |
|
2445 | + $this->set_last_name( $value ); |
|
2446 | + } |
|
2447 | + |
|
2448 | + /** |
|
2449 | + * Alias of self::set_last_name(). |
|
2450 | + * |
|
2451 | + * @since 1.0.19 |
|
2452 | + * @param string $value last name. |
|
2453 | + */ |
|
2454 | + public function set_customer_last_name( $value ) { |
|
2455 | + $this->set_last_name( $value ); |
|
2321 | 2456 | } |
2322 | 2457 | |
2323 | 2458 | /** |
2324 | - * Alias of self::set_description(). |
|
2325 | - * |
|
2326 | - * @since 1.0.19 |
|
2327 | - * @param string $value New description. |
|
2328 | - */ |
|
2329 | - public function set_excerpt( $value ) { |
|
2330 | - $this->set_description( $value ); |
|
2459 | + * Set the customer's phone number. |
|
2460 | + * |
|
2461 | + * @since 1.0.19 |
|
2462 | + * @param string $value phone. |
|
2463 | + */ |
|
2464 | + public function set_phone( $value ) { |
|
2465 | + $this->set_prop( 'phone', $value ); |
|
2466 | + } |
|
2467 | + |
|
2468 | + /** |
|
2469 | + * Alias of self::set_phone(). |
|
2470 | + * |
|
2471 | + * @since 1.0.19 |
|
2472 | + * @param string $value phone. |
|
2473 | + */ |
|
2474 | + public function set_user_phone( $value ) { |
|
2475 | + $this->set_phone( $value ); |
|
2476 | + } |
|
2477 | + |
|
2478 | + /** |
|
2479 | + * Alias of self::set_phone(). |
|
2480 | + * |
|
2481 | + * @since 1.0.19 |
|
2482 | + * @param string $value phone. |
|
2483 | + */ |
|
2484 | + public function set_customer_phone( $value ) { |
|
2485 | + $this->set_phone( $value ); |
|
2486 | + } |
|
2487 | + |
|
2488 | + /** |
|
2489 | + * Alias of self::set_phone(). |
|
2490 | + * |
|
2491 | + * @since 1.0.19 |
|
2492 | + * @param string $value phone. |
|
2493 | + */ |
|
2494 | + public function set_phone_number( $value ) { |
|
2495 | + $this->set_phone( $value ); |
|
2496 | + } |
|
2497 | + |
|
2498 | + /** |
|
2499 | + * Set the customer's email address. |
|
2500 | + * |
|
2501 | + * @since 1.0.19 |
|
2502 | + * @param string $value email address. |
|
2503 | + */ |
|
2504 | + public function set_email( $value ) { |
|
2505 | + $this->set_prop( 'email', $value ); |
|
2506 | + } |
|
2507 | + |
|
2508 | + /** |
|
2509 | + * Alias of self::set_email(). |
|
2510 | + * |
|
2511 | + * @since 1.0.19 |
|
2512 | + * @param string $value email address. |
|
2513 | + */ |
|
2514 | + public function set_user_email( $value ) { |
|
2515 | + $this->set_email( $value ); |
|
2331 | 2516 | } |
2332 | 2517 | |
2333 | 2518 | /** |
2334 | - * Alias of self::set_description(). |
|
2335 | - * |
|
2336 | - * @since 1.0.19 |
|
2337 | - * @param string $value New description. |
|
2338 | - */ |
|
2339 | - public function set_summary( $value ) { |
|
2340 | - $this->set_description( $value ); |
|
2519 | + * Alias of self::set_email(). |
|
2520 | + * |
|
2521 | + * @since 1.0.19 |
|
2522 | + * @param string $value email address. |
|
2523 | + */ |
|
2524 | + public function set_email_address( $value ) { |
|
2525 | + $this->set_email( $value ); |
|
2341 | 2526 | } |
2342 | 2527 | |
2343 | 2528 | /** |
2344 | - * Set the receiver of the invoice. |
|
2345 | - * |
|
2346 | - * @since 1.0.19 |
|
2347 | - * @param int $value New author. |
|
2348 | - */ |
|
2349 | - public function set_author( $value ) { |
|
2350 | - $user = get_user_by( 'id', (int) $value ); |
|
2529 | + * Alias of self::set_email(). |
|
2530 | + * |
|
2531 | + * @since 1.0.19 |
|
2532 | + * @param string $value email address. |
|
2533 | + */ |
|
2534 | + public function set_customer_email( $value ) { |
|
2535 | + $this->set_email( $value ); |
|
2536 | + } |
|
2351 | 2537 | |
2352 | - if ( $user && $user->ID ) { |
|
2353 | - $this->set_prop( 'author', $user->ID ); |
|
2354 | - $this->set_prop( 'email', $user->user_email ); |
|
2355 | - } |
|
2538 | + /** |
|
2539 | + * Set the customer's country. |
|
2540 | + * |
|
2541 | + * @since 1.0.19 |
|
2542 | + * @param string $value country. |
|
2543 | + */ |
|
2544 | + public function set_country( $value ) { |
|
2545 | + $this->set_prop( 'country', $value ); |
|
2356 | 2546 | } |
2357 | 2547 | |
2358 | 2548 | /** |
2359 | - * Alias of self::set_author(). |
|
2360 | - * |
|
2361 | - * @since 1.0.19 |
|
2362 | - * @param int $value New user id. |
|
2363 | - */ |
|
2364 | - public function set_user_id( $value ) { |
|
2365 | - $this->set_author( $value ); |
|
2549 | + * Alias of self::set_country(). |
|
2550 | + * |
|
2551 | + * @since 1.0.19 |
|
2552 | + * @param string $value country. |
|
2553 | + */ |
|
2554 | + public function set_user_country( $value ) { |
|
2555 | + $this->set_country( $value ); |
|
2366 | 2556 | } |
2367 | 2557 | |
2368 | 2558 | /** |
2369 | - * Sets the customer ID. |
|
2370 | - * |
|
2371 | - * @since 1.0.19 |
|
2372 | - * @param int $value New user id. |
|
2373 | - */ |
|
2374 | - public function set_customer_id( $value ) { |
|
2375 | - $this->set_prop( 'customer_id', (int) $value ); |
|
2559 | + * Alias of self::set_country(). |
|
2560 | + * |
|
2561 | + * @since 1.0.19 |
|
2562 | + * @param string $value country. |
|
2563 | + */ |
|
2564 | + public function set_customer_country( $value ) { |
|
2565 | + $this->set_country( $value ); |
|
2376 | 2566 | } |
2377 | 2567 | |
2378 | 2568 | /** |
2379 | - * Set the customer's ip. |
|
2380 | - * |
|
2381 | - * @since 1.0.19 |
|
2382 | - * @param string $value ip address. |
|
2383 | - */ |
|
2384 | - public function set_ip( $value ) { |
|
2385 | - $this->set_prop( 'ip', $value ); |
|
2569 | + * Set the customer's state. |
|
2570 | + * |
|
2571 | + * @since 1.0.19 |
|
2572 | + * @param string $value state. |
|
2573 | + */ |
|
2574 | + public function set_state( $value ) { |
|
2575 | + $this->set_prop( 'state', $value ); |
|
2386 | 2576 | } |
2387 | 2577 | |
2388 | 2578 | /** |
2389 | - * Alias of self::set_ip(). |
|
2390 | - * |
|
2391 | - * @since 1.0.19 |
|
2392 | - * @param string $value ip address. |
|
2393 | - */ |
|
2394 | - public function set_user_ip( $value ) { |
|
2395 | - $this->set_ip( $value ); |
|
2579 | + * Alias of self::set_state(). |
|
2580 | + * |
|
2581 | + * @since 1.0.19 |
|
2582 | + * @param string $value state. |
|
2583 | + */ |
|
2584 | + public function set_user_state( $value ) { |
|
2585 | + $this->set_state( $value ); |
|
2396 | 2586 | } |
2397 | 2587 | |
2398 | 2588 | /** |
2399 | - * Set the customer's first name. |
|
2400 | - * |
|
2401 | - * @since 1.0.19 |
|
2402 | - * @param string $value first name. |
|
2403 | - */ |
|
2404 | - public function set_first_name( $value ) { |
|
2405 | - $this->set_prop( 'first_name', $value ); |
|
2589 | + * Alias of self::set_state(). |
|
2590 | + * |
|
2591 | + * @since 1.0.19 |
|
2592 | + * @param string $value state. |
|
2593 | + */ |
|
2594 | + public function set_customer_state( $value ) { |
|
2595 | + $this->set_state( $value ); |
|
2406 | 2596 | } |
2407 | 2597 | |
2408 | 2598 | /** |
2409 | - * Alias of self::set_first_name(). |
|
2410 | - * |
|
2411 | - * @since 1.0.19 |
|
2412 | - * @param string $value first name. |
|
2413 | - */ |
|
2414 | - public function set_user_first_name( $value ) { |
|
2415 | - $this->set_first_name( $value ); |
|
2599 | + * Set the customer's city. |
|
2600 | + * |
|
2601 | + * @since 1.0.19 |
|
2602 | + * @param string $value city. |
|
2603 | + */ |
|
2604 | + public function set_city( $value ) { |
|
2605 | + $this->set_prop( 'city', $value ); |
|
2416 | 2606 | } |
2417 | 2607 | |
2418 | 2608 | /** |
2419 | - * Alias of self::set_first_name(). |
|
2420 | - * |
|
2421 | - * @since 1.0.19 |
|
2422 | - * @param string $value first name. |
|
2423 | - */ |
|
2424 | - public function set_customer_first_name( $value ) { |
|
2425 | - $this->set_first_name( $value ); |
|
2609 | + * Alias of self::set_city(). |
|
2610 | + * |
|
2611 | + * @since 1.0.19 |
|
2612 | + * @param string $value city. |
|
2613 | + */ |
|
2614 | + public function set_user_city( $value ) { |
|
2615 | + $this->set_city( $value ); |
|
2426 | 2616 | } |
2427 | 2617 | |
2428 | 2618 | /** |
2429 | - * Set the customer's last name. |
|
2430 | - * |
|
2431 | - * @since 1.0.19 |
|
2432 | - * @param string $value last name. |
|
2433 | - */ |
|
2434 | - public function set_last_name( $value ) { |
|
2435 | - $this->set_prop( 'last_name', $value ); |
|
2619 | + * Alias of self::set_city(). |
|
2620 | + * |
|
2621 | + * @since 1.0.19 |
|
2622 | + * @param string $value city. |
|
2623 | + */ |
|
2624 | + public function set_customer_city( $value ) { |
|
2625 | + $this->set_city( $value ); |
|
2436 | 2626 | } |
2437 | 2627 | |
2438 | 2628 | /** |
2439 | - * Alias of self::set_last_name(). |
|
2440 | - * |
|
2441 | - * @since 1.0.19 |
|
2442 | - * @param string $value last name. |
|
2443 | - */ |
|
2444 | - public function set_user_last_name( $value ) { |
|
2445 | - $this->set_last_name( $value ); |
|
2629 | + * Set the customer's zip code. |
|
2630 | + * |
|
2631 | + * @since 1.0.19 |
|
2632 | + * @param string $value zip. |
|
2633 | + */ |
|
2634 | + public function set_zip( $value ) { |
|
2635 | + $this->set_prop( 'zip', $value ); |
|
2446 | 2636 | } |
2447 | 2637 | |
2448 | 2638 | /** |
2449 | - * Alias of self::set_last_name(). |
|
2450 | - * |
|
2451 | - * @since 1.0.19 |
|
2452 | - * @param string $value last name. |
|
2453 | - */ |
|
2454 | - public function set_customer_last_name( $value ) { |
|
2455 | - $this->set_last_name( $value ); |
|
2639 | + * Alias of self::set_zip(). |
|
2640 | + * |
|
2641 | + * @since 1.0.19 |
|
2642 | + * @param string $value zip. |
|
2643 | + */ |
|
2644 | + public function set_user_zip( $value ) { |
|
2645 | + $this->set_zip( $value ); |
|
2456 | 2646 | } |
2457 | 2647 | |
2458 | 2648 | /** |
2459 | - * Set the customer's phone number. |
|
2460 | - * |
|
2461 | - * @since 1.0.19 |
|
2462 | - * @param string $value phone. |
|
2463 | - */ |
|
2464 | - public function set_phone( $value ) { |
|
2465 | - $this->set_prop( 'phone', $value ); |
|
2649 | + * Alias of self::set_zip(). |
|
2650 | + * |
|
2651 | + * @since 1.0.19 |
|
2652 | + * @param string $value zip. |
|
2653 | + */ |
|
2654 | + public function set_customer_zip( $value ) { |
|
2655 | + $this->set_zip( $value ); |
|
2466 | 2656 | } |
2467 | 2657 | |
2468 | 2658 | /** |
2469 | - * Alias of self::set_phone(). |
|
2470 | - * |
|
2471 | - * @since 1.0.19 |
|
2472 | - * @param string $value phone. |
|
2473 | - */ |
|
2474 | - public function set_user_phone( $value ) { |
|
2475 | - $this->set_phone( $value ); |
|
2659 | + * Set the customer's company. |
|
2660 | + * |
|
2661 | + * @since 1.0.19 |
|
2662 | + * @param string $value company. |
|
2663 | + */ |
|
2664 | + public function set_company( $value ) { |
|
2665 | + $this->set_prop( 'company', $value ); |
|
2476 | 2666 | } |
2477 | 2667 | |
2478 | 2668 | /** |
2479 | - * Alias of self::set_phone(). |
|
2480 | - * |
|
2481 | - * @since 1.0.19 |
|
2482 | - * @param string $value phone. |
|
2483 | - */ |
|
2484 | - public function set_customer_phone( $value ) { |
|
2485 | - $this->set_phone( $value ); |
|
2669 | + * Alias of self::set_company(). |
|
2670 | + * |
|
2671 | + * @since 1.0.19 |
|
2672 | + * @param string $value company. |
|
2673 | + */ |
|
2674 | + public function set_user_company( $value ) { |
|
2675 | + $this->set_company( $value ); |
|
2486 | 2676 | } |
2487 | 2677 | |
2488 | 2678 | /** |
2489 | - * Alias of self::set_phone(). |
|
2490 | - * |
|
2491 | - * @since 1.0.19 |
|
2492 | - * @param string $value phone. |
|
2493 | - */ |
|
2494 | - public function set_phone_number( $value ) { |
|
2495 | - $this->set_phone( $value ); |
|
2679 | + * Alias of self::set_company(). |
|
2680 | + * |
|
2681 | + * @since 1.0.19 |
|
2682 | + * @param string $value company. |
|
2683 | + */ |
|
2684 | + public function set_customer_company( $value ) { |
|
2685 | + $this->set_company( $value ); |
|
2496 | 2686 | } |
2497 | 2687 | |
2498 | 2688 | /** |
2499 | - * Set the customer's email address. |
|
2500 | - * |
|
2501 | - * @since 1.0.19 |
|
2502 | - * @param string $value email address. |
|
2503 | - */ |
|
2504 | - public function set_email( $value ) { |
|
2505 | - $this->set_prop( 'email', $value ); |
|
2689 | + * Set the customer's company id. |
|
2690 | + * |
|
2691 | + * @since 1.0.19 |
|
2692 | + * @param string $value company id. |
|
2693 | + */ |
|
2694 | + public function set_company_id( $value ) { |
|
2695 | + $this->set_prop( 'company_id', $value ); |
|
2506 | 2696 | } |
2507 | 2697 | |
2508 | 2698 | /** |
2509 | - * Alias of self::set_email(). |
|
2510 | - * |
|
2511 | - * @since 1.0.19 |
|
2512 | - * @param string $value email address. |
|
2513 | - */ |
|
2514 | - public function set_user_email( $value ) { |
|
2515 | - $this->set_email( $value ); |
|
2699 | + * Set the customer's var number. |
|
2700 | + * |
|
2701 | + * @since 1.0.19 |
|
2702 | + * @param string $value var number. |
|
2703 | + */ |
|
2704 | + public function set_vat_number( $value ) { |
|
2705 | + $this->set_prop( 'vat_number', $value ); |
|
2516 | 2706 | } |
2517 | 2707 | |
2518 | 2708 | /** |
2519 | - * Alias of self::set_email(). |
|
2520 | - * |
|
2521 | - * @since 1.0.19 |
|
2522 | - * @param string $value email address. |
|
2523 | - */ |
|
2524 | - public function set_email_address( $value ) { |
|
2525 | - $this->set_email( $value ); |
|
2709 | + * Alias of self::set_vat_number(). |
|
2710 | + * |
|
2711 | + * @since 1.0.19 |
|
2712 | + * @param string $value var number. |
|
2713 | + */ |
|
2714 | + public function set_user_vat_number( $value ) { |
|
2715 | + $this->set_vat_number( $value ); |
|
2526 | 2716 | } |
2527 | 2717 | |
2528 | 2718 | /** |
2529 | - * Alias of self::set_email(). |
|
2530 | - * |
|
2531 | - * @since 1.0.19 |
|
2532 | - * @param string $value email address. |
|
2533 | - */ |
|
2534 | - public function set_customer_email( $value ) { |
|
2535 | - $this->set_email( $value ); |
|
2719 | + * Alias of self::set_vat_number(). |
|
2720 | + * |
|
2721 | + * @since 1.0.19 |
|
2722 | + * @param string $value var number. |
|
2723 | + */ |
|
2724 | + public function set_customer_vat_number( $value ) { |
|
2725 | + $this->set_vat_number( $value ); |
|
2536 | 2726 | } |
2537 | 2727 | |
2538 | 2728 | /** |
2539 | - * Set the customer's country. |
|
2540 | - * |
|
2541 | - * @since 1.0.19 |
|
2542 | - * @param string $value country. |
|
2543 | - */ |
|
2544 | - public function set_country( $value ) { |
|
2545 | - $this->set_prop( 'country', $value ); |
|
2729 | + * Set the customer's vat rate. |
|
2730 | + * |
|
2731 | + * @since 1.0.19 |
|
2732 | + * @param string $value var rate. |
|
2733 | + */ |
|
2734 | + public function set_vat_rate( $value ) { |
|
2735 | + $this->set_prop( 'vat_rate', $value ); |
|
2546 | 2736 | } |
2547 | 2737 | |
2548 | 2738 | /** |
2549 | - * Alias of self::set_country(). |
|
2550 | - * |
|
2551 | - * @since 1.0.19 |
|
2552 | - * @param string $value country. |
|
2553 | - */ |
|
2554 | - public function set_user_country( $value ) { |
|
2555 | - $this->set_country( $value ); |
|
2739 | + * Alias of self::set_vat_rate(). |
|
2740 | + * |
|
2741 | + * @since 1.0.19 |
|
2742 | + * @param string $value var number. |
|
2743 | + */ |
|
2744 | + public function set_user_vat_rate( $value ) { |
|
2745 | + $this->set_vat_rate( $value ); |
|
2556 | 2746 | } |
2557 | 2747 | |
2558 | 2748 | /** |
2559 | - * Alias of self::set_country(). |
|
2560 | - * |
|
2561 | - * @since 1.0.19 |
|
2562 | - * @param string $value country. |
|
2563 | - */ |
|
2564 | - public function set_customer_country( $value ) { |
|
2565 | - $this->set_country( $value ); |
|
2749 | + * Alias of self::set_vat_rate(). |
|
2750 | + * |
|
2751 | + * @since 1.0.19 |
|
2752 | + * @param string $value var number. |
|
2753 | + */ |
|
2754 | + public function set_customer_vat_rate( $value ) { |
|
2755 | + $this->set_vat_rate( $value ); |
|
2566 | 2756 | } |
2567 | 2757 | |
2568 | 2758 | /** |
2569 | - * Set the customer's state. |
|
2570 | - * |
|
2571 | - * @since 1.0.19 |
|
2572 | - * @param string $value state. |
|
2573 | - */ |
|
2574 | - public function set_state( $value ) { |
|
2575 | - $this->set_prop( 'state', $value ); |
|
2759 | + * Set the customer's address. |
|
2760 | + * |
|
2761 | + * @since 1.0.19 |
|
2762 | + * @param string $value address. |
|
2763 | + */ |
|
2764 | + public function set_address( $value ) { |
|
2765 | + $this->set_prop( 'address', $value ); |
|
2576 | 2766 | } |
2577 | 2767 | |
2578 | 2768 | /** |
2579 | - * Alias of self::set_state(). |
|
2580 | - * |
|
2581 | - * @since 1.0.19 |
|
2582 | - * @param string $value state. |
|
2583 | - */ |
|
2584 | - public function set_user_state( $value ) { |
|
2585 | - $this->set_state( $value ); |
|
2769 | + * Alias of self::set_address(). |
|
2770 | + * |
|
2771 | + * @since 1.0.19 |
|
2772 | + * @param string $value address. |
|
2773 | + */ |
|
2774 | + public function set_user_address( $value ) { |
|
2775 | + $this->set_address( $value ); |
|
2586 | 2776 | } |
2587 | 2777 | |
2588 | 2778 | /** |
2589 | - * Alias of self::set_state(). |
|
2590 | - * |
|
2591 | - * @since 1.0.19 |
|
2592 | - * @param string $value state. |
|
2593 | - */ |
|
2594 | - public function set_customer_state( $value ) { |
|
2595 | - $this->set_state( $value ); |
|
2779 | + * Alias of self::set_address(). |
|
2780 | + * |
|
2781 | + * @since 1.0.19 |
|
2782 | + * @param string $value address. |
|
2783 | + */ |
|
2784 | + public function set_customer_address( $value ) { |
|
2785 | + $this->set_address( $value ); |
|
2596 | 2786 | } |
2597 | 2787 | |
2598 | 2788 | /** |
2599 | - * Set the customer's city. |
|
2600 | - * |
|
2601 | - * @since 1.0.19 |
|
2602 | - * @param string $value city. |
|
2603 | - */ |
|
2604 | - public function set_city( $value ) { |
|
2605 | - $this->set_prop( 'city', $value ); |
|
2789 | + * Set whether the customer has viewed the invoice or not. |
|
2790 | + * |
|
2791 | + * @since 1.0.19 |
|
2792 | + * @param int|bool $value confirmed. |
|
2793 | + */ |
|
2794 | + public function set_is_viewed( $value ) { |
|
2795 | + $this->set_prop( 'is_viewed', $value ); |
|
2606 | 2796 | } |
2607 | 2797 | |
2608 | 2798 | /** |
2609 | - * Alias of self::set_city(). |
|
2610 | - * |
|
2611 | - * @since 1.0.19 |
|
2612 | - * @param string $value city. |
|
2613 | - */ |
|
2614 | - public function set_user_city( $value ) { |
|
2615 | - $this->set_city( $value ); |
|
2799 | + * Set extra email recipients. |
|
2800 | + * |
|
2801 | + * @since 1.0.19 |
|
2802 | + * @param string $value email recipients. |
|
2803 | + */ |
|
2804 | + public function set_email_cc( $value ) { |
|
2805 | + $this->set_prop( 'email_cc', $value ); |
|
2616 | 2806 | } |
2617 | 2807 | |
2618 | 2808 | /** |
2619 | - * Alias of self::set_city(). |
|
2620 | - * |
|
2621 | - * @since 1.0.19 |
|
2622 | - * @param string $value city. |
|
2623 | - */ |
|
2624 | - public function set_customer_city( $value ) { |
|
2625 | - $this->set_city( $value ); |
|
2809 | + * Set the invoice template. |
|
2810 | + * |
|
2811 | + * @since 1.0.19 |
|
2812 | + * @param string $value template. |
|
2813 | + */ |
|
2814 | + public function set_template( $value ) { |
|
2815 | + if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
2816 | + $this->set_prop( 'template', $value ); |
|
2817 | + } |
|
2626 | 2818 | } |
2627 | 2819 | |
2628 | 2820 | /** |
2629 | - * Set the customer's zip code. |
|
2630 | - * |
|
2631 | - * @since 1.0.19 |
|
2632 | - * @param string $value zip. |
|
2633 | - */ |
|
2634 | - public function set_zip( $value ) { |
|
2635 | - $this->set_prop( 'zip', $value ); |
|
2821 | + * Set the invoice source. |
|
2822 | + * |
|
2823 | + * @since 1.0.19 |
|
2824 | + * @param string $value source. |
|
2825 | + * @deprecated |
|
2826 | + */ |
|
2827 | + public function created_via( $value ) { |
|
2828 | + $this->set_created_via( sanitize_text_field( $value ) ); |
|
2636 | 2829 | } |
2637 | 2830 | |
2638 | 2831 | /** |
2639 | - * Alias of self::set_zip(). |
|
2640 | - * |
|
2641 | - * @since 1.0.19 |
|
2642 | - * @param string $value zip. |
|
2643 | - */ |
|
2644 | - public function set_user_zip( $value ) { |
|
2645 | - $this->set_zip( $value ); |
|
2832 | + * Set the invoice source. |
|
2833 | + * |
|
2834 | + * @since 1.0.19 |
|
2835 | + * @param string $value source. |
|
2836 | + */ |
|
2837 | + public function set_created_via( $value ) { |
|
2838 | + $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
2646 | 2839 | } |
2647 | 2840 | |
2648 | 2841 | /** |
2649 | - * Alias of self::set_zip(). |
|
2650 | - * |
|
2651 | - * @since 1.0.19 |
|
2652 | - * @param string $value zip. |
|
2653 | - */ |
|
2654 | - public function set_customer_zip( $value ) { |
|
2655 | - $this->set_zip( $value ); |
|
2842 | + * Set the customer's address confirmed status. |
|
2843 | + * |
|
2844 | + * @since 1.0.19 |
|
2845 | + * @param int|bool $value confirmed. |
|
2846 | + */ |
|
2847 | + public function set_address_confirmed( $value ) { |
|
2848 | + $this->set_prop( 'address_confirmed', $value ); |
|
2656 | 2849 | } |
2657 | 2850 | |
2658 | 2851 | /** |
2659 | - * Set the customer's company. |
|
2660 | - * |
|
2661 | - * @since 1.0.19 |
|
2662 | - * @param string $value company. |
|
2663 | - */ |
|
2664 | - public function set_company( $value ) { |
|
2665 | - $this->set_prop( 'company', $value ); |
|
2852 | + * Alias of self::set_address_confirmed(). |
|
2853 | + * |
|
2854 | + * @since 1.0.19 |
|
2855 | + * @param int|bool $value confirmed. |
|
2856 | + */ |
|
2857 | + public function set_user_address_confirmed( $value ) { |
|
2858 | + $this->set_address_confirmed( $value ); |
|
2666 | 2859 | } |
2667 | 2860 | |
2668 | 2861 | /** |
2669 | - * Alias of self::set_company(). |
|
2670 | - * |
|
2671 | - * @since 1.0.19 |
|
2672 | - * @param string $value company. |
|
2673 | - */ |
|
2674 | - public function set_user_company( $value ) { |
|
2675 | - $this->set_company( $value ); |
|
2862 | + * Alias of self::set_address_confirmed(). |
|
2863 | + * |
|
2864 | + * @since 1.0.19 |
|
2865 | + * @param int|bool $value confirmed. |
|
2866 | + */ |
|
2867 | + public function set_customer_address_confirmed( $value ) { |
|
2868 | + $this->set_address_confirmed( $value ); |
|
2676 | 2869 | } |
2677 | 2870 | |
2678 | 2871 | /** |
2679 | - * Alias of self::set_company(). |
|
2680 | - * |
|
2681 | - * @since 1.0.19 |
|
2682 | - * @param string $value company. |
|
2683 | - */ |
|
2684 | - public function set_customer_company( $value ) { |
|
2685 | - $this->set_company( $value ); |
|
2686 | - } |
|
2872 | + * Set the shipping fee |
|
2873 | + * |
|
2874 | + * @since 1.0.19 |
|
2875 | + * @param float $value shipping amount. |
|
2876 | + */ |
|
2877 | + public function set_shipping( $value ) { |
|
2687 | 2878 | |
2688 | - /** |
|
2689 | - * Set the customer's company id. |
|
2690 | - * |
|
2691 | - * @since 1.0.19 |
|
2692 | - * @param string $value company id. |
|
2693 | - */ |
|
2694 | - public function set_company_id( $value ) { |
|
2695 | - $this->set_prop( 'company_id', $value ); |
|
2696 | - } |
|
2879 | + if ( ! is_numeric( $value ) ) { |
|
2880 | + return $this->set_prop( 'shipping', null ); |
|
2881 | + } |
|
2697 | 2882 | |
2698 | - /** |
|
2699 | - * Set the customer's var number. |
|
2700 | - * |
|
2701 | - * @since 1.0.19 |
|
2702 | - * @param string $value var number. |
|
2703 | - */ |
|
2704 | - public function set_vat_number( $value ) { |
|
2705 | - $this->set_prop( 'vat_number', $value ); |
|
2883 | + $this->set_prop( 'shipping', max( 0, floatval( $value ) ) ); |
|
2706 | 2884 | } |
2707 | 2885 | |
2708 | 2886 | /** |
2709 | - * Alias of self::set_vat_number(). |
|
2710 | - * |
|
2711 | - * @since 1.0.19 |
|
2712 | - * @param string $value var number. |
|
2713 | - */ |
|
2714 | - public function set_user_vat_number( $value ) { |
|
2715 | - $this->set_vat_number( $value ); |
|
2887 | + * Set the invoice sub total. |
|
2888 | + * |
|
2889 | + * @since 1.0.19 |
|
2890 | + * @param float $value sub total. |
|
2891 | + */ |
|
2892 | + public function set_subtotal( $value ) { |
|
2893 | + $this->set_prop( 'subtotal', max( 0, $value ) ); |
|
2716 | 2894 | } |
2717 | 2895 | |
2718 | 2896 | /** |
2719 | - * Alias of self::set_vat_number(). |
|
2720 | - * |
|
2721 | - * @since 1.0.19 |
|
2722 | - * @param string $value var number. |
|
2723 | - */ |
|
2724 | - public function set_customer_vat_number( $value ) { |
|
2725 | - $this->set_vat_number( $value ); |
|
2897 | + * Set the invoice total. |
|
2898 | + * |
|
2899 | + * @since 1.0.19 |
|
2900 | + * @param float $value sub total. |
|
2901 | + */ |
|
2902 | + public function set_total( $value ) { |
|
2903 | + $this->set_prop( 'total', max( 0, $value ) ); |
|
2726 | 2904 | } |
2727 | 2905 | |
2728 | 2906 | /** |
2729 | - * Set the customer's vat rate. |
|
2730 | - * |
|
2731 | - * @since 1.0.19 |
|
2732 | - * @param string $value var rate. |
|
2733 | - */ |
|
2734 | - public function set_vat_rate( $value ) { |
|
2735 | - $this->set_prop( 'vat_rate', $value ); |
|
2736 | - } |
|
2737 | - |
|
2738 | - /** |
|
2739 | - * Alias of self::set_vat_rate(). |
|
2740 | - * |
|
2741 | - * @since 1.0.19 |
|
2742 | - * @param string $value var number. |
|
2743 | - */ |
|
2744 | - public function set_user_vat_rate( $value ) { |
|
2745 | - $this->set_vat_rate( $value ); |
|
2746 | - } |
|
2747 | - |
|
2748 | - /** |
|
2749 | - * Alias of self::set_vat_rate(). |
|
2750 | - * |
|
2751 | - * @since 1.0.19 |
|
2752 | - * @param string $value var number. |
|
2753 | - */ |
|
2754 | - public function set_customer_vat_rate( $value ) { |
|
2755 | - $this->set_vat_rate( $value ); |
|
2756 | - } |
|
2757 | - |
|
2758 | - /** |
|
2759 | - * Set the customer's address. |
|
2760 | - * |
|
2761 | - * @since 1.0.19 |
|
2762 | - * @param string $value address. |
|
2763 | - */ |
|
2764 | - public function set_address( $value ) { |
|
2765 | - $this->set_prop( 'address', $value ); |
|
2766 | - } |
|
2767 | - |
|
2768 | - /** |
|
2769 | - * Alias of self::set_address(). |
|
2770 | - * |
|
2771 | - * @since 1.0.19 |
|
2772 | - * @param string $value address. |
|
2773 | - */ |
|
2774 | - public function set_user_address( $value ) { |
|
2775 | - $this->set_address( $value ); |
|
2776 | - } |
|
2777 | - |
|
2778 | - /** |
|
2779 | - * Alias of self::set_address(). |
|
2780 | - * |
|
2781 | - * @since 1.0.19 |
|
2782 | - * @param string $value address. |
|
2783 | - */ |
|
2784 | - public function set_customer_address( $value ) { |
|
2785 | - $this->set_address( $value ); |
|
2786 | - } |
|
2787 | - |
|
2788 | - /** |
|
2789 | - * Set whether the customer has viewed the invoice or not. |
|
2790 | - * |
|
2791 | - * @since 1.0.19 |
|
2792 | - * @param int|bool $value confirmed. |
|
2793 | - */ |
|
2794 | - public function set_is_viewed( $value ) { |
|
2795 | - $this->set_prop( 'is_viewed', $value ); |
|
2796 | - } |
|
2797 | - |
|
2798 | - /** |
|
2799 | - * Set extra email recipients. |
|
2800 | - * |
|
2801 | - * @since 1.0.19 |
|
2802 | - * @param string $value email recipients. |
|
2803 | - */ |
|
2804 | - public function set_email_cc( $value ) { |
|
2805 | - $this->set_prop( 'email_cc', $value ); |
|
2806 | - } |
|
2807 | - |
|
2808 | - /** |
|
2809 | - * Set the invoice template. |
|
2810 | - * |
|
2811 | - * @since 1.0.19 |
|
2812 | - * @param string $value template. |
|
2813 | - */ |
|
2814 | - public function set_template( $value ) { |
|
2815 | - if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
2816 | - $this->set_prop( 'template', $value ); |
|
2817 | - } |
|
2818 | - } |
|
2819 | - |
|
2820 | - /** |
|
2821 | - * Set the invoice source. |
|
2822 | - * |
|
2823 | - * @since 1.0.19 |
|
2824 | - * @param string $value source. |
|
2825 | - * @deprecated |
|
2826 | - */ |
|
2827 | - public function created_via( $value ) { |
|
2828 | - $this->set_created_via( sanitize_text_field( $value ) ); |
|
2829 | - } |
|
2830 | - |
|
2831 | - /** |
|
2832 | - * Set the invoice source. |
|
2833 | - * |
|
2834 | - * @since 1.0.19 |
|
2835 | - * @param string $value source. |
|
2836 | - */ |
|
2837 | - public function set_created_via( $value ) { |
|
2838 | - $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
2839 | - } |
|
2840 | - |
|
2841 | - /** |
|
2842 | - * Set the customer's address confirmed status. |
|
2843 | - * |
|
2844 | - * @since 1.0.19 |
|
2845 | - * @param int|bool $value confirmed. |
|
2846 | - */ |
|
2847 | - public function set_address_confirmed( $value ) { |
|
2848 | - $this->set_prop( 'address_confirmed', $value ); |
|
2849 | - } |
|
2850 | - |
|
2851 | - /** |
|
2852 | - * Alias of self::set_address_confirmed(). |
|
2853 | - * |
|
2854 | - * @since 1.0.19 |
|
2855 | - * @param int|bool $value confirmed. |
|
2856 | - */ |
|
2857 | - public function set_user_address_confirmed( $value ) { |
|
2858 | - $this->set_address_confirmed( $value ); |
|
2859 | - } |
|
2860 | - |
|
2861 | - /** |
|
2862 | - * Alias of self::set_address_confirmed(). |
|
2863 | - * |
|
2864 | - * @since 1.0.19 |
|
2865 | - * @param int|bool $value confirmed. |
|
2866 | - */ |
|
2867 | - public function set_customer_address_confirmed( $value ) { |
|
2868 | - $this->set_address_confirmed( $value ); |
|
2869 | - } |
|
2870 | - |
|
2871 | - /** |
|
2872 | - * Set the shipping fee |
|
2873 | - * |
|
2874 | - * @since 1.0.19 |
|
2875 | - * @param float $value shipping amount. |
|
2876 | - */ |
|
2877 | - public function set_shipping( $value ) { |
|
2878 | - |
|
2879 | - if ( ! is_numeric( $value ) ) { |
|
2880 | - return $this->set_prop( 'shipping', null ); |
|
2881 | - } |
|
2882 | - |
|
2883 | - $this->set_prop( 'shipping', max( 0, floatval( $value ) ) ); |
|
2884 | - } |
|
2885 | - |
|
2886 | - /** |
|
2887 | - * Set the invoice sub total. |
|
2888 | - * |
|
2889 | - * @since 1.0.19 |
|
2890 | - * @param float $value sub total. |
|
2891 | - */ |
|
2892 | - public function set_subtotal( $value ) { |
|
2893 | - $this->set_prop( 'subtotal', max( 0, $value ) ); |
|
2894 | - } |
|
2895 | - |
|
2896 | - /** |
|
2897 | - * Set the invoice total. |
|
2898 | - * |
|
2899 | - * @since 1.0.19 |
|
2900 | - * @param float $value sub total. |
|
2901 | - */ |
|
2902 | - public function set_total( $value ) { |
|
2903 | - $this->set_prop( 'total', max( 0, $value ) ); |
|
2904 | - } |
|
2905 | - |
|
2906 | - /** |
|
2907 | - * Set the invoice discount amount. |
|
2908 | - * |
|
2909 | - * @since 1.0.19 |
|
2910 | - * @param float $value discount total. |
|
2911 | - */ |
|
2912 | - public function set_total_discount( $value ) { |
|
2913 | - $this->set_prop( 'total_discount', max( 0, $value ) ); |
|
2907 | + * Set the invoice discount amount. |
|
2908 | + * |
|
2909 | + * @since 1.0.19 |
|
2910 | + * @param float $value discount total. |
|
2911 | + */ |
|
2912 | + public function set_total_discount( $value ) { |
|
2913 | + $this->set_prop( 'total_discount', max( 0, $value ) ); |
|
2914 | 2914 | } |
2915 | 2915 | |
2916 | 2916 | /** |
2917 | - * Alias of self::set_total_discount(). |
|
2918 | - * |
|
2919 | - * @since 1.0.19 |
|
2920 | - * @param float $value discount total. |
|
2921 | - */ |
|
2922 | - public function set_discount( $value ) { |
|
2923 | - $this->set_total_discount( $value ); |
|
2917 | + * Alias of self::set_total_discount(). |
|
2918 | + * |
|
2919 | + * @since 1.0.19 |
|
2920 | + * @param float $value discount total. |
|
2921 | + */ |
|
2922 | + public function set_discount( $value ) { |
|
2923 | + $this->set_total_discount( $value ); |
|
2924 | 2924 | } |
2925 | 2925 | |
2926 | 2926 | /** |
2927 | - * Set the invoice tax amount. |
|
2928 | - * |
|
2929 | - * @since 1.0.19 |
|
2930 | - * @param float $value tax total. |
|
2931 | - */ |
|
2932 | - public function set_total_tax( $value ) { |
|
2933 | - $this->set_prop( 'total_tax', max( 0, $value ) ); |
|
2927 | + * Set the invoice tax amount. |
|
2928 | + * |
|
2929 | + * @since 1.0.19 |
|
2930 | + * @param float $value tax total. |
|
2931 | + */ |
|
2932 | + public function set_total_tax( $value ) { |
|
2933 | + $this->set_prop( 'total_tax', max( 0, $value ) ); |
|
2934 | 2934 | } |
2935 | 2935 | |
2936 | 2936 | /** |
2937 | - * Alias of self::set_total_tax(). |
|
2938 | - * |
|
2939 | - * @since 1.0.19 |
|
2940 | - * @param float $value tax total. |
|
2941 | - */ |
|
2942 | - public function set_tax_total( $value ) { |
|
2943 | - $this->set_total_tax( $value ); |
|
2937 | + * Alias of self::set_total_tax(). |
|
2938 | + * |
|
2939 | + * @since 1.0.19 |
|
2940 | + * @param float $value tax total. |
|
2941 | + */ |
|
2942 | + public function set_tax_total( $value ) { |
|
2943 | + $this->set_total_tax( $value ); |
|
2944 | 2944 | } |
2945 | 2945 | |
2946 | 2946 | /** |
2947 | - * Set the invoice fees amount. |
|
2948 | - * |
|
2949 | - * @since 1.0.19 |
|
2950 | - * @param float $value fees total. |
|
2951 | - */ |
|
2952 | - public function set_total_fees( $value ) { |
|
2953 | - $this->set_prop( 'total_fees', max( 0, $value ) ); |
|
2947 | + * Set the invoice fees amount. |
|
2948 | + * |
|
2949 | + * @since 1.0.19 |
|
2950 | + * @param float $value fees total. |
|
2951 | + */ |
|
2952 | + public function set_total_fees( $value ) { |
|
2953 | + $this->set_prop( 'total_fees', max( 0, $value ) ); |
|
2954 | 2954 | } |
2955 | 2955 | |
2956 | 2956 | /** |
2957 | - * Alias of self::set_total_fees(). |
|
2958 | - * |
|
2959 | - * @since 1.0.19 |
|
2960 | - * @param float $value fees total. |
|
2961 | - */ |
|
2962 | - public function set_fees_total( $value ) { |
|
2963 | - $this->set_total_fees( $value ); |
|
2957 | + * Alias of self::set_total_fees(). |
|
2958 | + * |
|
2959 | + * @since 1.0.19 |
|
2960 | + * @param float $value fees total. |
|
2961 | + */ |
|
2962 | + public function set_fees_total( $value ) { |
|
2963 | + $this->set_total_fees( $value ); |
|
2964 | 2964 | } |
2965 | 2965 | |
2966 | 2966 | /** |
2967 | - * Set the invoice fees. |
|
2968 | - * |
|
2969 | - * @since 1.0.19 |
|
2970 | - * @param array $value fees. |
|
2971 | - */ |
|
2972 | - public function set_fees( $value ) { |
|
2967 | + * Set the invoice fees. |
|
2968 | + * |
|
2969 | + * @since 1.0.19 |
|
2970 | + * @param array $value fees. |
|
2971 | + */ |
|
2972 | + public function set_fees( $value ) { |
|
2973 | 2973 | |
2974 | - if ( ! is_array( $value ) ) { |
|
2975 | - $value = array(); |
|
2976 | - } |
|
2974 | + if ( ! is_array( $value ) ) { |
|
2975 | + $value = array(); |
|
2976 | + } |
|
2977 | 2977 | |
2978 | - $this->set_prop( 'fees', $value ); |
|
2978 | + $this->set_prop( 'fees', $value ); |
|
2979 | 2979 | } |
2980 | 2980 | |
2981 | 2981 | /** |
2982 | - * Set the invoice taxes. |
|
2983 | - * |
|
2984 | - * @since 1.0.19 |
|
2985 | - * @param array $value taxes. |
|
2986 | - */ |
|
2987 | - public function set_taxes( $value ) { |
|
2982 | + * Set the invoice taxes. |
|
2983 | + * |
|
2984 | + * @since 1.0.19 |
|
2985 | + * @param array $value taxes. |
|
2986 | + */ |
|
2987 | + public function set_taxes( $value ) { |
|
2988 | 2988 | |
2989 | - if ( ! is_array( $value ) ) { |
|
2990 | - $value = array(); |
|
2991 | - } |
|
2989 | + if ( ! is_array( $value ) ) { |
|
2990 | + $value = array(); |
|
2991 | + } |
|
2992 | 2992 | |
2993 | - $this->set_prop( 'taxes', $value ); |
|
2993 | + $this->set_prop( 'taxes', $value ); |
|
2994 | 2994 | } |
2995 | 2995 | |
2996 | 2996 | /** |
2997 | - * Set the invoice discounts. |
|
2998 | - * |
|
2999 | - * @since 1.0.19 |
|
3000 | - * @param array $value discounts. |
|
3001 | - */ |
|
3002 | - public function set_discounts( $value ) { |
|
2997 | + * Set the invoice discounts. |
|
2998 | + * |
|
2999 | + * @since 1.0.19 |
|
3000 | + * @param array $value discounts. |
|
3001 | + */ |
|
3002 | + public function set_discounts( $value ) { |
|
3003 | 3003 | |
3004 | - if ( ! is_array( $value ) ) { |
|
3005 | - $value = array(); |
|
3006 | - } |
|
3004 | + if ( ! is_array( $value ) ) { |
|
3005 | + $value = array(); |
|
3006 | + } |
|
3007 | 3007 | |
3008 | - $this->set_prop( 'discounts', $value ); |
|
3008 | + $this->set_prop( 'discounts', $value ); |
|
3009 | 3009 | } |
3010 | 3010 | |
3011 | 3011 | /** |
3012 | - * Set the invoice items. |
|
3013 | - * |
|
3014 | - * @since 1.0.19 |
|
3015 | - * @param GetPaid_Form_Item[] $value items. |
|
3016 | - */ |
|
3017 | - public function set_items( $value ) { |
|
3012 | + * Set the invoice items. |
|
3013 | + * |
|
3014 | + * @since 1.0.19 |
|
3015 | + * @param GetPaid_Form_Item[] $value items. |
|
3016 | + */ |
|
3017 | + public function set_items( $value ) { |
|
3018 | 3018 | |
3019 | 3019 | // Remove existing items. |
3020 | 3020 | $this->set_prop( 'items', array() ); |
3021 | - $this->recurring_item = null; |
|
3021 | + $this->recurring_item = null; |
|
3022 | 3022 | |
3023 | 3023 | // Ensure that we have an array. |
3024 | 3024 | if ( ! is_array( $value ) ) { |
@@ -3031,105 +3031,105 @@ discard block |
||
3031 | 3031 | } |
3032 | 3032 | |
3033 | 3033 | /** |
3034 | - * Set the payment form. |
|
3035 | - * |
|
3036 | - * @since 1.0.19 |
|
3037 | - * @param int $value payment form. |
|
3038 | - */ |
|
3039 | - public function set_payment_form( $value ) { |
|
3040 | - $this->set_prop( 'payment_form', $value ); |
|
3034 | + * Set the payment form. |
|
3035 | + * |
|
3036 | + * @since 1.0.19 |
|
3037 | + * @param int $value payment form. |
|
3038 | + */ |
|
3039 | + public function set_payment_form( $value ) { |
|
3040 | + $this->set_prop( 'payment_form', $value ); |
|
3041 | 3041 | } |
3042 | 3042 | |
3043 | 3043 | /** |
3044 | - * Set the submission id. |
|
3045 | - * |
|
3046 | - * @since 1.0.19 |
|
3047 | - * @param string $value submission id. |
|
3048 | - */ |
|
3049 | - public function set_submission_id( $value ) { |
|
3050 | - $this->set_prop( 'submission_id', $value ); |
|
3044 | + * Set the submission id. |
|
3045 | + * |
|
3046 | + * @since 1.0.19 |
|
3047 | + * @param string $value submission id. |
|
3048 | + */ |
|
3049 | + public function set_submission_id( $value ) { |
|
3050 | + $this->set_prop( 'submission_id', $value ); |
|
3051 | 3051 | } |
3052 | 3052 | |
3053 | 3053 | /** |
3054 | - * Set the discount code. |
|
3055 | - * |
|
3056 | - * @since 1.0.19 |
|
3057 | - * @param string $value discount code. |
|
3058 | - */ |
|
3059 | - public function set_discount_code( $value ) { |
|
3060 | - $this->set_prop( 'discount_code', sanitize_text_field( $value ) ); |
|
3054 | + * Set the discount code. |
|
3055 | + * |
|
3056 | + * @since 1.0.19 |
|
3057 | + * @param string $value discount code. |
|
3058 | + */ |
|
3059 | + public function set_discount_code( $value ) { |
|
3060 | + $this->set_prop( 'discount_code', sanitize_text_field( $value ) ); |
|
3061 | 3061 | } |
3062 | 3062 | |
3063 | 3063 | /** |
3064 | - * Set the gateway. |
|
3065 | - * |
|
3066 | - * @since 1.0.19 |
|
3067 | - * @param string $value gateway. |
|
3068 | - */ |
|
3069 | - public function set_gateway( $value ) { |
|
3070 | - $this->set_prop( 'gateway', $value ); |
|
3064 | + * Set the gateway. |
|
3065 | + * |
|
3066 | + * @since 1.0.19 |
|
3067 | + * @param string $value gateway. |
|
3068 | + */ |
|
3069 | + public function set_gateway( $value ) { |
|
3070 | + $this->set_prop( 'gateway', $value ); |
|
3071 | 3071 | } |
3072 | 3072 | |
3073 | 3073 | /** |
3074 | - * Set the transaction id. |
|
3075 | - * |
|
3076 | - * @since 1.0.19 |
|
3077 | - * @param string $value transaction id. |
|
3078 | - */ |
|
3079 | - public function set_transaction_id( $value ) { |
|
3080 | - if ( ! empty( $value ) ) { |
|
3081 | - $this->set_prop( 'transaction_id', $value ); |
|
3082 | - } |
|
3074 | + * Set the transaction id. |
|
3075 | + * |
|
3076 | + * @since 1.0.19 |
|
3077 | + * @param string $value transaction id. |
|
3078 | + */ |
|
3079 | + public function set_transaction_id( $value ) { |
|
3080 | + if ( ! empty( $value ) ) { |
|
3081 | + $this->set_prop( 'transaction_id', $value ); |
|
3082 | + } |
|
3083 | 3083 | } |
3084 | 3084 | |
3085 | 3085 | /** |
3086 | - * Set the currency id. |
|
3087 | - * |
|
3088 | - * @since 1.0.19 |
|
3089 | - * @param string $value currency id. |
|
3090 | - */ |
|
3091 | - public function set_currency( $value ) { |
|
3092 | - $this->set_prop( 'currency', $value ); |
|
3086 | + * Set the currency id. |
|
3087 | + * |
|
3088 | + * @since 1.0.19 |
|
3089 | + * @param string $value currency id. |
|
3090 | + */ |
|
3091 | + public function set_currency( $value ) { |
|
3092 | + $this->set_prop( 'currency', $value ); |
|
3093 | 3093 | } |
3094 | 3094 | |
3095 | - /** |
|
3096 | - * Set whether to disable taxes. |
|
3097 | - * |
|
3098 | - * @since 1.0.19 |
|
3099 | - * @param bool $value value. |
|
3100 | - */ |
|
3101 | - public function set_disable_taxes( $value ) { |
|
3102 | - $this->set_prop( 'disable_taxes', (bool) $value ); |
|
3103 | - } |
|
3095 | + /** |
|
3096 | + * Set whether to disable taxes. |
|
3097 | + * |
|
3098 | + * @since 1.0.19 |
|
3099 | + * @param bool $value value. |
|
3100 | + */ |
|
3101 | + public function set_disable_taxes( $value ) { |
|
3102 | + $this->set_prop( 'disable_taxes', (bool) $value ); |
|
3103 | + } |
|
3104 | 3104 | |
3105 | 3105 | /** |
3106 | - * Set the subscription id. |
|
3107 | - * |
|
3108 | - * @since 1.0.19 |
|
3109 | - * @param string $value subscription id. |
|
3110 | - */ |
|
3111 | - public function set_subscription_id( $value ) { |
|
3112 | - $this->set_prop( 'subscription_id', $value ); |
|
3113 | - } |
|
3106 | + * Set the subscription id. |
|
3107 | + * |
|
3108 | + * @since 1.0.19 |
|
3109 | + * @param string $value subscription id. |
|
3110 | + */ |
|
3111 | + public function set_subscription_id( $value ) { |
|
3112 | + $this->set_prop( 'subscription_id', $value ); |
|
3113 | + } |
|
3114 | 3114 | |
3115 | - /** |
|
3116 | - * Set the remote subscription id. |
|
3117 | - * |
|
3118 | - * @since 1.0.19 |
|
3119 | - * @param string $value subscription id. |
|
3120 | - */ |
|
3121 | - public function set_remote_subscription_id( $value ) { |
|
3122 | - $this->set_prop( 'remote_subscription_id', $value ); |
|
3115 | + /** |
|
3116 | + * Set the remote subscription id. |
|
3117 | + * |
|
3118 | + * @since 1.0.19 |
|
3119 | + * @param string $value subscription id. |
|
3120 | + */ |
|
3121 | + public function set_remote_subscription_id( $value ) { |
|
3122 | + $this->set_prop( 'remote_subscription_id', $value ); |
|
3123 | 3123 | } |
3124 | 3124 | |
3125 | 3125 | /** |
3126 | - * Set the invoice anonymize status. |
|
3127 | - * |
|
3128 | - * @since 2.8.22 |
|
3129 | - * @param bool $is_anonymized is anonymized. |
|
3130 | - */ |
|
3131 | - public function set_is_anonymized( $is_anonymized ) { |
|
3132 | - $this->set_prop( 'is_anonymized', (bool) $is_anonymized ); |
|
3126 | + * Set the invoice anonymize status. |
|
3127 | + * |
|
3128 | + * @since 2.8.22 |
|
3129 | + * @param bool $is_anonymized is anonymized. |
|
3130 | + */ |
|
3131 | + public function set_is_anonymized( $is_anonymized ) { |
|
3132 | + $this->set_prop( 'is_anonymized', (bool) $is_anonymized ); |
|
3133 | 3133 | } |
3134 | 3134 | |
3135 | 3135 | /* |
@@ -3168,24 +3168,24 @@ discard block |
||
3168 | 3168 | */ |
3169 | 3169 | public function is_taxable() { |
3170 | 3170 | return ! $this->get_disable_taxes(); |
3171 | - } |
|
3171 | + } |
|
3172 | 3172 | |
3173 | - /** |
|
3174 | - * @deprecated |
|
3175 | - */ |
|
3176 | - public function has_vat() { |
|
3173 | + /** |
|
3174 | + * @deprecated |
|
3175 | + */ |
|
3176 | + public function has_vat() { |
|
3177 | 3177 | return $this->is_taxable(); |
3178 | - } |
|
3178 | + } |
|
3179 | 3179 | |
3180 | - /** |
|
3181 | - * Checks to see if the invoice requires payment. |
|
3182 | - */ |
|
3183 | - public function is_free() { |
|
3180 | + /** |
|
3181 | + * Checks to see if the invoice requires payment. |
|
3182 | + */ |
|
3183 | + public function is_free() { |
|
3184 | 3184 | $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 ); |
3185 | 3185 | |
3186 | - if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
3187 | - $is_free = false; |
|
3188 | - } |
|
3186 | + if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
3187 | + $is_free = false; |
|
3188 | + } |
|
3189 | 3189 | |
3190 | 3190 | return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
3191 | 3191 | } |
@@ -3196,46 +3196,46 @@ discard block |
||
3196 | 3196 | public function is_paid() { |
3197 | 3197 | $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
3198 | 3198 | return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
3199 | - } |
|
3199 | + } |
|
3200 | 3200 | |
3201 | - /** |
|
3201 | + /** |
|
3202 | 3202 | * Checks if the invoice needs payment. |
3203 | 3203 | */ |
3204 | - public function needs_payment() { |
|
3205 | - $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
3204 | + public function needs_payment() { |
|
3205 | + $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
3206 | 3206 | return apply_filters( 'wpinv_needs_payment', $needs_payment, $this ); |
3207 | 3207 | } |
3208 | 3208 | |
3209 | - /** |
|
3209 | + /** |
|
3210 | 3210 | * Checks if the invoice is refunded. |
3211 | 3211 | */ |
3212 | - public function is_refunded() { |
|
3212 | + public function is_refunded() { |
|
3213 | 3213 | $is_refunded = $this->has_status( 'wpi-refunded' ); |
3214 | 3214 | return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
3215 | - } |
|
3215 | + } |
|
3216 | 3216 | |
3217 | - /** |
|
3217 | + /** |
|
3218 | 3218 | * Checks if the invoice is held. |
3219 | 3219 | */ |
3220 | - public function is_held() { |
|
3220 | + public function is_held() { |
|
3221 | 3221 | $is_held = $this->has_status( 'wpi-onhold' ); |
3222 | 3222 | return apply_filters( 'wpinv_invoice_is_held', $is_held, $this ); |
3223 | - } |
|
3223 | + } |
|
3224 | 3224 | |
3225 | - /** |
|
3225 | + /** |
|
3226 | 3226 | * Checks if the invoice is due. |
3227 | 3227 | */ |
3228 | - public function is_due() { |
|
3229 | - $due_date = $this->get_due_date(); |
|
3230 | - return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
3231 | - } |
|
3228 | + public function is_due() { |
|
3229 | + $due_date = $this->get_due_date(); |
|
3230 | + return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
3231 | + } |
|
3232 | 3232 | |
3233 | - /** |
|
3233 | + /** |
|
3234 | 3234 | * Checks if the invoice is draft. |
3235 | 3235 | */ |
3236 | - public function is_draft() { |
|
3236 | + public function is_draft() { |
|
3237 | 3237 | return $this->has_status( 'draft, auto-draft' ); |
3238 | - } |
|
3238 | + } |
|
3239 | 3239 | |
3240 | 3240 | /** |
3241 | 3241 | * Checks if the invoice has a given status. |
@@ -3243,9 +3243,9 @@ discard block |
||
3243 | 3243 | public function has_status( $status ) { |
3244 | 3244 | $status = wpinv_parse_list( $status ); |
3245 | 3245 | return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status ); |
3246 | - } |
|
3246 | + } |
|
3247 | 3247 | |
3248 | - /** |
|
3248 | + /** |
|
3249 | 3249 | * Checks if the invoice is of a given type. |
3250 | 3250 | */ |
3251 | 3251 | public function is_type( $type ) { |
@@ -3268,25 +3268,25 @@ discard block |
||
3268 | 3268 | */ |
3269 | 3269 | public function has_free_trial() { |
3270 | 3270 | return $this->is_recurring() && 0 == $this->get_initial_total(); |
3271 | - } |
|
3271 | + } |
|
3272 | 3272 | |
3273 | - /** |
|
3273 | + /** |
|
3274 | 3274 | * @deprecated |
3275 | 3275 | */ |
3276 | 3276 | public function is_free_trial() { |
3277 | 3277 | return $this->has_free_trial(); |
3278 | 3278 | } |
3279 | 3279 | |
3280 | - /** |
|
3280 | + /** |
|
3281 | 3281 | * Check if the initial payment if 0. |
3282 | 3282 | * |
3283 | 3283 | */ |
3284 | - public function is_initial_free() { |
|
3284 | + public function is_initial_free() { |
|
3285 | 3285 | $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 ); |
3286 | 3286 | return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this ); |
3287 | 3287 | } |
3288 | 3288 | |
3289 | - /** |
|
3289 | + /** |
|
3290 | 3290 | * Check if the recurring item has a free trial. |
3291 | 3291 | * |
3292 | 3292 | */ |
@@ -3299,14 +3299,14 @@ discard block |
||
3299 | 3299 | |
3300 | 3300 | $item = $this->get_recurring( true ); |
3301 | 3301 | return $item->has_free_trial(); |
3302 | - } |
|
3302 | + } |
|
3303 | 3303 | |
3304 | - /** |
|
3304 | + /** |
|
3305 | 3305 | * Check if the free trial is a result of a discount. |
3306 | 3306 | */ |
3307 | 3307 | public function is_free_trial_from_discount() { |
3308 | - return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
3309 | - } |
|
3308 | + return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
3309 | + } |
|
3310 | 3310 | |
3311 | 3311 | /** |
3312 | 3312 | * Checks if this is an anonymized invoice. |
@@ -3317,12 +3317,12 @@ discard block |
||
3317 | 3317 | return true === (bool) $this->get_is_anonymized(); |
3318 | 3318 | } |
3319 | 3319 | |
3320 | - /** |
|
3320 | + /** |
|
3321 | 3321 | * @deprecated |
3322 | 3322 | */ |
3323 | 3323 | public function discount_first_payment_only() { |
3324 | 3324 | |
3325 | - $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
3325 | + $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
3326 | 3326 | if ( ! $discount->exists() || ! $this->is_recurring() ) { |
3327 | 3327 | return true; |
3328 | 3328 | } |
@@ -3347,143 +3347,143 @@ discard block |
||
3347 | 3347 | */ |
3348 | 3348 | public function add_item( $item ) { |
3349 | 3349 | |
3350 | - if ( is_array( $item ) ) { |
|
3351 | - $item = $this->process_array_item( $item ); |
|
3352 | - } |
|
3350 | + if ( is_array( $item ) ) { |
|
3351 | + $item = $this->process_array_item( $item ); |
|
3352 | + } |
|
3353 | 3353 | |
3354 | - if ( is_numeric( $item ) ) { |
|
3355 | - $item = new GetPaid_Form_Item( $item ); |
|
3356 | - } |
|
3354 | + if ( is_numeric( $item ) ) { |
|
3355 | + $item = new GetPaid_Form_Item( $item ); |
|
3356 | + } |
|
3357 | 3357 | |
3358 | 3358 | // Make sure that it is available for purchase. |
3359 | - if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
3360 | - return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
3359 | + if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
3360 | + return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
3361 | 3361 | } |
3362 | 3362 | |
3363 | 3363 | // Do we have a recurring item? |
3364 | - if ( $item->is_recurring() ) { |
|
3365 | - $this->recurring_item = $item->get_id(); |
|
3364 | + if ( $item->is_recurring() ) { |
|
3365 | + $this->recurring_item = $item->get_id(); |
|
3366 | 3366 | } |
3367 | 3367 | |
3368 | 3368 | // Invoice id. |
3369 | 3369 | $item->invoice_id = (int) $this->get_id(); |
3370 | 3370 | |
3371 | - // Remove duplicates. |
|
3372 | - $this->remove_item( $item->get_id() ); |
|
3371 | + // Remove duplicates. |
|
3372 | + $this->remove_item( $item->get_id() ); |
|
3373 | 3373 | |
3374 | - if ( 0 == $item->get_quantity() ) { |
|
3375 | - return; |
|
3376 | - } |
|
3374 | + if ( 0 == $item->get_quantity() ) { |
|
3375 | + return; |
|
3376 | + } |
|
3377 | 3377 | |
3378 | - // Retrieve all items. |
|
3378 | + // Retrieve all items. |
|
3379 | 3379 | $items = $this->get_items(); |
3380 | 3380 | |
3381 | - // Add new item. |
|
3381 | + // Add new item. |
|
3382 | 3382 | $items[] = $item; |
3383 | 3383 | |
3384 | 3384 | $this->set_prop( 'items', $items ); |
3385 | 3385 | |
3386 | - return true; |
|
3387 | - } |
|
3388 | - |
|
3389 | - /** |
|
3390 | - * Converts an array to an item. |
|
3391 | - * |
|
3392 | - * @since 1.0.19 |
|
3393 | - * @return GetPaid_Form_Item |
|
3394 | - */ |
|
3395 | - protected function process_array_item( $array ) { |
|
3396 | - |
|
3397 | - $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
3398 | - $item = new GetPaid_Form_Item( $item_id ); |
|
3399 | - |
|
3400 | - // Set item data. |
|
3401 | - foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
3402 | - if ( isset( $array[ "item_$key" ] ) ) { |
|
3403 | - $method = "set_$key"; |
|
3404 | - $item->$method( $array[ "item_$key" ] ); |
|
3405 | - } |
|
3406 | - } |
|
3407 | - |
|
3408 | - if ( isset( $array['quantity'] ) ) { |
|
3409 | - $item->set_quantity( $array['quantity'] ); |
|
3410 | - } |
|
3411 | - |
|
3412 | - // Set item meta. |
|
3413 | - if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
3414 | - $item->set_item_meta( $array['meta'] ); |
|
3415 | - } |
|
3416 | - |
|
3417 | - return $item; |
|
3418 | - } |
|
3419 | - |
|
3420 | - /** |
|
3421 | - * Retrieves a specific item. |
|
3422 | - * |
|
3423 | - * @since 1.0.19 |
|
3424 | - * @return GetPaid_Form_Item|null |
|
3425 | - */ |
|
3426 | - public function get_item( $item_id ) { |
|
3427 | - |
|
3428 | - foreach ( $this->get_items() as $item ) { |
|
3429 | - if ( (int) $item_id == $item->get_id() ) { |
|
3430 | - return $item; |
|
3431 | - } |
|
3432 | - } |
|
3433 | - |
|
3434 | - return null; |
|
3435 | - } |
|
3436 | - |
|
3437 | - /** |
|
3438 | - * Removes a specific item. |
|
3439 | - * |
|
3440 | - * @since 1.0.19 |
|
3441 | - */ |
|
3442 | - public function remove_item( $item_id ) { |
|
3443 | - $items = $this->get_items(); |
|
3444 | - $item_id = (int) $item_id; |
|
3445 | - |
|
3446 | - foreach ( $items as $index => $item ) { |
|
3447 | - if ( (int) $item_id == $item->get_id() ) { |
|
3448 | - unset( $items[ $index ] ); |
|
3449 | - $this->set_prop( 'items', $items ); |
|
3450 | - |
|
3451 | - if ( $item_id == $this->recurring_item ) { |
|
3452 | - $this->recurring_item = null; |
|
3453 | - } |
|
3386 | + return true; |
|
3387 | + } |
|
3388 | + |
|
3389 | + /** |
|
3390 | + * Converts an array to an item. |
|
3391 | + * |
|
3392 | + * @since 1.0.19 |
|
3393 | + * @return GetPaid_Form_Item |
|
3394 | + */ |
|
3395 | + protected function process_array_item( $array ) { |
|
3396 | + |
|
3397 | + $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
3398 | + $item = new GetPaid_Form_Item( $item_id ); |
|
3399 | + |
|
3400 | + // Set item data. |
|
3401 | + foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
3402 | + if ( isset( $array[ "item_$key" ] ) ) { |
|
3403 | + $method = "set_$key"; |
|
3404 | + $item->$method( $array[ "item_$key" ] ); |
|
3405 | + } |
|
3406 | + } |
|
3407 | + |
|
3408 | + if ( isset( $array['quantity'] ) ) { |
|
3409 | + $item->set_quantity( $array['quantity'] ); |
|
3410 | + } |
|
3411 | + |
|
3412 | + // Set item meta. |
|
3413 | + if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
3414 | + $item->set_item_meta( $array['meta'] ); |
|
3415 | + } |
|
3416 | + |
|
3417 | + return $item; |
|
3418 | + } |
|
3419 | + |
|
3420 | + /** |
|
3421 | + * Retrieves a specific item. |
|
3422 | + * |
|
3423 | + * @since 1.0.19 |
|
3424 | + * @return GetPaid_Form_Item|null |
|
3425 | + */ |
|
3426 | + public function get_item( $item_id ) { |
|
3427 | + |
|
3428 | + foreach ( $this->get_items() as $item ) { |
|
3429 | + if ( (int) $item_id == $item->get_id() ) { |
|
3430 | + return $item; |
|
3431 | + } |
|
3432 | + } |
|
3433 | + |
|
3434 | + return null; |
|
3435 | + } |
|
3436 | + |
|
3437 | + /** |
|
3438 | + * Removes a specific item. |
|
3439 | + * |
|
3440 | + * @since 1.0.19 |
|
3441 | + */ |
|
3442 | + public function remove_item( $item_id ) { |
|
3443 | + $items = $this->get_items(); |
|
3444 | + $item_id = (int) $item_id; |
|
3445 | + |
|
3446 | + foreach ( $items as $index => $item ) { |
|
3447 | + if ( (int) $item_id == $item->get_id() ) { |
|
3448 | + unset( $items[ $index ] ); |
|
3449 | + $this->set_prop( 'items', $items ); |
|
3450 | + |
|
3451 | + if ( $item_id == $this->recurring_item ) { |
|
3452 | + $this->recurring_item = null; |
|
3453 | + } |
|
3454 | 3454 | } |
3455 | - } |
|
3455 | + } |
|
3456 | 3456 | } |
3457 | 3457 | |
3458 | 3458 | /** |
3459 | - * Adds a fee to the invoice. |
|
3460 | - * |
|
3461 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
3462 | - * @since 1.0.19 |
|
3463 | - */ |
|
3459 | + * Adds a fee to the invoice. |
|
3460 | + * |
|
3461 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
3462 | + * @since 1.0.19 |
|
3463 | + */ |
|
3464 | 3464 | public function add_fee( $fee ) { |
3465 | 3465 | |
3466 | - $fees = $this->get_fees(); |
|
3467 | - $fees[ $fee['name'] ] = $fee; |
|
3468 | - $this->set_prop( 'fees', $fees ); |
|
3466 | + $fees = $this->get_fees(); |
|
3467 | + $fees[ $fee['name'] ] = $fee; |
|
3468 | + $this->set_prop( 'fees', $fees ); |
|
3469 | 3469 | } |
3470 | 3470 | |
3471 | 3471 | /** |
3472 | - * Retrieves a specific fee. |
|
3473 | - * |
|
3474 | - * @since 1.0.19 |
|
3475 | - */ |
|
3476 | - public function get_fee( $fee ) { |
|
3472 | + * Retrieves a specific fee. |
|
3473 | + * |
|
3474 | + * @since 1.0.19 |
|
3475 | + */ |
|
3476 | + public function get_fee( $fee ) { |
|
3477 | 3477 | $fees = $this->get_fees(); |
3478 | - return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
3478 | + return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
3479 | 3479 | } |
3480 | 3480 | |
3481 | 3481 | /** |
3482 | - * Removes a specific fee. |
|
3483 | - * |
|
3484 | - * @since 1.0.19 |
|
3485 | - */ |
|
3486 | - public function remove_fee( $fee ) { |
|
3482 | + * Removes a specific fee. |
|
3483 | + * |
|
3484 | + * @since 1.0.19 |
|
3485 | + */ |
|
3486 | + public function remove_fee( $fee ) { |
|
3487 | 3487 | $fees = $this->get_fees(); |
3488 | 3488 | if ( isset( $fees[ $fee ] ) ) { |
3489 | 3489 | unset( $fees[ $fee ] ); |
@@ -3491,54 +3491,54 @@ discard block |
||
3491 | 3491 | } |
3492 | 3492 | } |
3493 | 3493 | |
3494 | - /** |
|
3495 | - * Adds a discount to the invoice. |
|
3496 | - * |
|
3497 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
3498 | - * @since 1.0.19 |
|
3499 | - */ |
|
3500 | - public function add_discount( $discount ) { |
|
3494 | + /** |
|
3495 | + * Adds a discount to the invoice. |
|
3496 | + * |
|
3497 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
3498 | + * @since 1.0.19 |
|
3499 | + */ |
|
3500 | + public function add_discount( $discount ) { |
|
3501 | 3501 | |
3502 | - $discounts = $this->get_discounts(); |
|
3503 | - $discounts[ $discount['name'] ] = $discount; |
|
3504 | - $this->set_prop( 'discounts', $discounts ); |
|
3505 | - } |
|
3502 | + $discounts = $this->get_discounts(); |
|
3503 | + $discounts[ $discount['name'] ] = $discount; |
|
3504 | + $this->set_prop( 'discounts', $discounts ); |
|
3505 | + } |
|
3506 | 3506 | |
3507 | 3507 | /** |
3508 | - * Retrieves a specific discount. |
|
3509 | - * |
|
3510 | - * @since 1.0.19 |
|
3511 | - * @return float |
|
3512 | - */ |
|
3513 | - public function get_discount( $discount = false ) { |
|
3508 | + * Retrieves a specific discount. |
|
3509 | + * |
|
3510 | + * @since 1.0.19 |
|
3511 | + * @return float |
|
3512 | + */ |
|
3513 | + public function get_discount( $discount = false ) { |
|
3514 | 3514 | |
3515 | - // Backwards compatibility. |
|
3516 | - if ( empty( $discount ) ) { |
|
3517 | - return $this->get_total_discount(); |
|
3518 | - } |
|
3515 | + // Backwards compatibility. |
|
3516 | + if ( empty( $discount ) ) { |
|
3517 | + return $this->get_total_discount(); |
|
3518 | + } |
|
3519 | 3519 | |
3520 | 3520 | $discounts = $this->get_discounts(); |
3521 | - return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
3521 | + return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
3522 | 3522 | } |
3523 | 3523 | |
3524 | 3524 | /** |
3525 | - * Removes a specific discount. |
|
3526 | - * |
|
3527 | - * @since 1.0.19 |
|
3528 | - */ |
|
3529 | - public function remove_discount( $discount ) { |
|
3525 | + * Removes a specific discount. |
|
3526 | + * |
|
3527 | + * @since 1.0.19 |
|
3528 | + */ |
|
3529 | + public function remove_discount( $discount ) { |
|
3530 | 3530 | $discounts = $this->get_discounts(); |
3531 | 3531 | if ( isset( $discounts[ $discount ] ) ) { |
3532 | 3532 | unset( $discounts[ $discount ] ); |
3533 | 3533 | $this->set_prop( 'discounts', $discounts ); |
3534 | 3534 | } |
3535 | 3535 | |
3536 | - if ( 'discount_code' == $discount ) { |
|
3537 | - foreach ( $this->get_items() as $item ) { |
|
3538 | - $item->item_discount = 0; |
|
3539 | - $item->recurring_item_discount = 0; |
|
3540 | - } |
|
3541 | - } |
|
3536 | + if ( 'discount_code' == $discount ) { |
|
3537 | + foreach ( $this->get_items() as $item ) { |
|
3538 | + $item->item_discount = 0; |
|
3539 | + $item->recurring_item_discount = 0; |
|
3540 | + } |
|
3541 | + } |
|
3542 | 3542 | } |
3543 | 3543 | |
3544 | 3544 | /** |
@@ -3550,116 +3550,116 @@ discard block |
||
3550 | 3550 | if ( $this->is_taxable() ) { |
3551 | 3551 | |
3552 | 3552 | $taxes = $this->get_taxes(); |
3553 | - $taxes[ $tax['name'] ] = $tax; |
|
3554 | - $this->set_prop( 'taxes', $tax ); |
|
3553 | + $taxes[ $tax['name'] ] = $tax; |
|
3554 | + $this->set_prop( 'taxes', $tax ); |
|
3555 | 3555 | |
3556 | 3556 | } |
3557 | 3557 | } |
3558 | 3558 | |
3559 | 3559 | /** |
3560 | - * Retrieves a specific tax. |
|
3561 | - * |
|
3562 | - * @since 1.0.19 |
|
3563 | - */ |
|
3564 | - public function get_tax( $tax = null ) { |
|
3560 | + * Retrieves a specific tax. |
|
3561 | + * |
|
3562 | + * @since 1.0.19 |
|
3563 | + */ |
|
3564 | + public function get_tax( $tax = null ) { |
|
3565 | 3565 | |
3566 | - // Backwards compatibility. |
|
3567 | - if ( empty( $tax ) ) { |
|
3568 | - return $this->get_total_tax(); |
|
3569 | - } |
|
3566 | + // Backwards compatibility. |
|
3567 | + if ( empty( $tax ) ) { |
|
3568 | + return $this->get_total_tax(); |
|
3569 | + } |
|
3570 | 3570 | |
3571 | 3571 | $taxes = $this->get_taxes(); |
3572 | - return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
3572 | + return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
3573 | 3573 | } |
3574 | 3574 | |
3575 | - public function get_tax_total_by_name( $name ) { |
|
3576 | - if ( $name && 0 === strpos( $name, 'tax__' ) ) { |
|
3577 | - $name = str_replace( 'tax__', '', $name ); |
|
3578 | - } |
|
3575 | + public function get_tax_total_by_name( $name ) { |
|
3576 | + if ( $name && 0 === strpos( $name, 'tax__' ) ) { |
|
3577 | + $name = str_replace( 'tax__', '', $name ); |
|
3578 | + } |
|
3579 | 3579 | |
3580 | - if ( empty( $name ) ) { |
|
3581 | - return 0; |
|
3582 | - } |
|
3580 | + if ( empty( $name ) ) { |
|
3581 | + return 0; |
|
3582 | + } |
|
3583 | 3583 | |
3584 | - $tax = $this->get_tax( $name ); |
|
3584 | + $tax = $this->get_tax( $name ); |
|
3585 | 3585 | |
3586 | - if ( empty( $tax ) ) { |
|
3587 | - return 0; |
|
3588 | - } |
|
3586 | + if ( empty( $tax ) ) { |
|
3587 | + return 0; |
|
3588 | + } |
|
3589 | 3589 | |
3590 | 3590 | return $this->is_renewal() ? $tax['recurring_tax'] : $tax['initial_tax']; |
3591 | 3591 | } |
3592 | 3592 | |
3593 | - /** |
|
3594 | - * Get tax item name. |
|
3595 | - * |
|
3596 | - * @since 2.8.8 |
|
3597 | - */ |
|
3598 | - public function get_tax_item_name( $tax_key, $tax_item, $suffix = '' ) { |
|
3599 | - $tax_name = _x( 'Tax', 'Tax name', 'invoicing' ); |
|
3593 | + /** |
|
3594 | + * Get tax item name. |
|
3595 | + * |
|
3596 | + * @since 2.8.8 |
|
3597 | + */ |
|
3598 | + public function get_tax_item_name( $tax_key, $tax_item, $suffix = '' ) { |
|
3599 | + $tax_name = _x( 'Tax', 'Tax name', 'invoicing' ); |
|
3600 | 3600 | |
3601 | - if ( ! empty( $tax_item ) && is_array( $tax_item ) && ! empty( $tax_item['name'] ) ) { |
|
3602 | - $tax_name = __( $tax_item['name'], 'invoicing' ); |
|
3603 | - } |
|
3601 | + if ( ! empty( $tax_item ) && is_array( $tax_item ) && ! empty( $tax_item['name'] ) ) { |
|
3602 | + $tax_name = __( $tax_item['name'], 'invoicing' ); |
|
3603 | + } |
|
3604 | 3604 | |
3605 | - if ( $suffix ) { |
|
3606 | - $tax_name .= $suffix; |
|
3607 | - } |
|
3605 | + if ( $suffix ) { |
|
3606 | + $tax_name .= $suffix; |
|
3607 | + } |
|
3608 | 3608 | |
3609 | - return apply_filters( 'wpinv_invoice_get_tax_name', $tax_name, $this, $tax_key, $tax_item, $suffix ); |
|
3610 | - } |
|
3609 | + return apply_filters( 'wpinv_invoice_get_tax_name', $tax_name, $this, $tax_key, $tax_item, $suffix ); |
|
3610 | + } |
|
3611 | 3611 | |
3612 | - /** |
|
3613 | - * Get tax item amount. |
|
3614 | - * |
|
3615 | - * @since 2.8.8 |
|
3616 | - */ |
|
3617 | - public function get_tax_item_amount( $tax_key, $tax_item, $with_currency = false ) { |
|
3618 | - $tax_amount = $this->get_tax_total_by_name( $tax_key ); |
|
3612 | + /** |
|
3613 | + * Get tax item amount. |
|
3614 | + * |
|
3615 | + * @since 2.8.8 |
|
3616 | + */ |
|
3617 | + public function get_tax_item_amount( $tax_key, $tax_item, $with_currency = false ) { |
|
3618 | + $tax_amount = $this->get_tax_total_by_name( $tax_key ); |
|
3619 | 3619 | |
3620 | - if ( $with_currency ) { |
|
3621 | - $tax_amount = wpinv_price( $tax_amount, $this->get_currency() ); |
|
3622 | - } |
|
3620 | + if ( $with_currency ) { |
|
3621 | + $tax_amount = wpinv_price( $tax_amount, $this->get_currency() ); |
|
3622 | + } |
|
3623 | 3623 | |
3624 | - return apply_filters( 'wpinv_invoice_get_tax_amount', $tax_amount, $this, $tax_item, $with_currency ); |
|
3625 | - } |
|
3624 | + return apply_filters( 'wpinv_invoice_get_tax_amount', $tax_amount, $this, $tax_item, $with_currency ); |
|
3625 | + } |
|
3626 | 3626 | |
3627 | - public function get_item_tax_name( $percentage = true, $sep = ' + ' ) { |
|
3628 | - $taxes = $this->get_taxes(); |
|
3627 | + public function get_item_tax_name( $percentage = true, $sep = ' + ' ) { |
|
3628 | + $taxes = $this->get_taxes(); |
|
3629 | 3629 | |
3630 | - if ( ! empty( $taxes ) && is_array( $taxes ) && count( $taxes ) == 1 && wpinv_display_individual_tax_rates() ) { |
|
3631 | - $names = array(); |
|
3630 | + if ( ! empty( $taxes ) && is_array( $taxes ) && count( $taxes ) == 1 && wpinv_display_individual_tax_rates() ) { |
|
3631 | + $names = array(); |
|
3632 | 3632 | |
3633 | - foreach ( $taxes as $key => $tax ) { |
|
3634 | - if ( ! empty( $tax ) && ! empty( $tax['name'] ) ) { |
|
3635 | - $name = __( $tax['name'], 'invoicing' ); |
|
3633 | + foreach ( $taxes as $key => $tax ) { |
|
3634 | + if ( ! empty( $tax ) && ! empty( $tax['name'] ) ) { |
|
3635 | + $name = __( $tax['name'], 'invoicing' ); |
|
3636 | 3636 | |
3637 | - $names[] = $name; |
|
3638 | - } |
|
3639 | - } |
|
3637 | + $names[] = $name; |
|
3638 | + } |
|
3639 | + } |
|
3640 | 3640 | |
3641 | - if ( ! empty( $names ) ) { |
|
3642 | - $names = array_unique( $names ); |
|
3641 | + if ( ! empty( $names ) ) { |
|
3642 | + $names = array_unique( $names ); |
|
3643 | 3643 | |
3644 | - $tax_name = implode( $sep, $names ); |
|
3645 | - } |
|
3644 | + $tax_name = implode( $sep, $names ); |
|
3645 | + } |
|
3646 | 3646 | |
3647 | - if ( $percentage ) { |
|
3648 | - $tax_name = wp_sprintf( _x( '%s (%%)', 'Tax name with %. Ex: Tax (%)', 'invoicing' ), $tax_name ); |
|
3649 | - } |
|
3650 | - } else { |
|
3651 | - $tax_name = $percentage ? __( 'Tax (%)', 'invoicing' ) : _x( 'Tax', 'Tax name', 'invoicing' ); |
|
3652 | - } |
|
3647 | + if ( $percentage ) { |
|
3648 | + $tax_name = wp_sprintf( _x( '%s (%%)', 'Tax name with %. Ex: Tax (%)', 'invoicing' ), $tax_name ); |
|
3649 | + } |
|
3650 | + } else { |
|
3651 | + $tax_name = $percentage ? __( 'Tax (%)', 'invoicing' ) : _x( 'Tax', 'Tax name', 'invoicing' ); |
|
3652 | + } |
|
3653 | 3653 | |
3654 | - return apply_filters( 'wpinv_invoice_get_item_tax_name', $tax_name, $this, $percentage, $sep ); |
|
3655 | - } |
|
3654 | + return apply_filters( 'wpinv_invoice_get_item_tax_name', $tax_name, $this, $percentage, $sep ); |
|
3655 | + } |
|
3656 | 3656 | |
3657 | 3657 | /** |
3658 | - * Removes a specific tax. |
|
3659 | - * |
|
3660 | - * @since 1.0.19 |
|
3661 | - */ |
|
3662 | - public function remove_tax( $tax ) { |
|
3658 | + * Removes a specific tax. |
|
3659 | + * |
|
3660 | + * @since 1.0.19 |
|
3661 | + */ |
|
3662 | + public function remove_tax( $tax ) { |
|
3663 | 3663 | $taxes = $this->get_taxes(); |
3664 | 3664 | if ( isset( $taxes[ $tax ] ) ) { |
3665 | 3665 | unset( $taxes[ $tax ] ); |
@@ -3668,191 +3668,191 @@ discard block |
||
3668 | 3668 | } |
3669 | 3669 | |
3670 | 3670 | /** |
3671 | - * Recalculates the invoice subtotal. |
|
3672 | - * |
|
3673 | - * @since 1.0.19 |
|
3674 | - * @return float The recalculated subtotal |
|
3675 | - */ |
|
3676 | - public function recalculate_subtotal() { |
|
3671 | + * Recalculates the invoice subtotal. |
|
3672 | + * |
|
3673 | + * @since 1.0.19 |
|
3674 | + * @return float The recalculated subtotal |
|
3675 | + */ |
|
3676 | + public function recalculate_subtotal() { |
|
3677 | 3677 | $items = $this->get_items(); |
3678 | - $subtotal = 0; |
|
3679 | - $recurring = 0; |
|
3678 | + $subtotal = 0; |
|
3679 | + $recurring = 0; |
|
3680 | 3680 | |
3681 | 3681 | foreach ( $items as $item ) { |
3682 | - $subtotal += $item->get_sub_total( 'edit' ); |
|
3683 | - $recurring += $item->get_recurring_sub_total( 'edit' ); |
|
3682 | + $subtotal += $item->get_sub_total( 'edit' ); |
|
3683 | + $recurring += $item->get_recurring_sub_total( 'edit' ); |
|
3684 | 3684 | } |
3685 | 3685 | |
3686 | - if ( wpinv_prices_include_tax() ) { |
|
3687 | - $subtotal = max( 0, $subtotal - $this->totals['tax']['initial'] ); |
|
3688 | - $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] ); |
|
3689 | - } |
|
3686 | + if ( wpinv_prices_include_tax() ) { |
|
3687 | + $subtotal = max( 0, $subtotal - $this->totals['tax']['initial'] ); |
|
3688 | + $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] ); |
|
3689 | + } |
|
3690 | 3690 | |
3691 | - $current = $this->is_renewal() ? $recurring : $subtotal; |
|
3692 | - $this->set_subtotal( $current ); |
|
3691 | + $current = $this->is_renewal() ? $recurring : $subtotal; |
|
3692 | + $this->set_subtotal( $current ); |
|
3693 | 3693 | |
3694 | - $this->totals['subtotal'] = array( |
|
3695 | - 'initial' => $subtotal, |
|
3696 | - 'recurring' => $recurring, |
|
3697 | - ); |
|
3694 | + $this->totals['subtotal'] = array( |
|
3695 | + 'initial' => $subtotal, |
|
3696 | + 'recurring' => $recurring, |
|
3697 | + ); |
|
3698 | 3698 | |
3699 | 3699 | return $current; |
3700 | 3700 | } |
3701 | 3701 | |
3702 | 3702 | /** |
3703 | - * Recalculates the invoice discount total. |
|
3704 | - * |
|
3705 | - * @since 1.0.19 |
|
3706 | - * @return float The recalculated discount |
|
3707 | - */ |
|
3708 | - public function recalculate_total_discount() { |
|
3709 | - // Fix renewal invoice amount when tax + recurring discount applied. |
|
3710 | - if ( $this->is_renewal() && $this->get_discount_code() ) { |
|
3711 | - // Maybe recalculate discount (Pre-GetPaid Fix). |
|
3712 | - $discount = new WPInv_Discount( $this->get_discount_code() ); |
|
3713 | - |
|
3714 | - if ( $discount->exists() && $discount->is_recurring() ) { |
|
3715 | - getpaid_calculate_invoice_discount( $this, $discount ); |
|
3716 | - } |
|
3717 | - } |
|
3703 | + * Recalculates the invoice discount total. |
|
3704 | + * |
|
3705 | + * @since 1.0.19 |
|
3706 | + * @return float The recalculated discount |
|
3707 | + */ |
|
3708 | + public function recalculate_total_discount() { |
|
3709 | + // Fix renewal invoice amount when tax + recurring discount applied. |
|
3710 | + if ( $this->is_renewal() && $this->get_discount_code() ) { |
|
3711 | + // Maybe recalculate discount (Pre-GetPaid Fix). |
|
3712 | + $discount = new WPInv_Discount( $this->get_discount_code() ); |
|
3713 | + |
|
3714 | + if ( $discount->exists() && $discount->is_recurring() ) { |
|
3715 | + getpaid_calculate_invoice_discount( $this, $discount ); |
|
3716 | + } |
|
3717 | + } |
|
3718 | 3718 | |
3719 | - $discounts = $this->get_discounts(); |
|
3720 | - $discount = 0; |
|
3721 | - $recurring = 0; |
|
3719 | + $discounts = $this->get_discounts(); |
|
3720 | + $discount = 0; |
|
3721 | + $recurring = 0; |
|
3722 | 3722 | |
3723 | 3723 | foreach ( $discounts as $data ) { |
3724 | - $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
3725 | - $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
3726 | - } |
|
3724 | + $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
3725 | + $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
3726 | + } |
|
3727 | 3727 | |
3728 | - $current = $this->is_renewal() ? $recurring : $discount; |
|
3728 | + $current = $this->is_renewal() ? $recurring : $discount; |
|
3729 | 3729 | |
3730 | - $this->set_total_discount( $current ); |
|
3730 | + $this->set_total_discount( $current ); |
|
3731 | 3731 | |
3732 | - $this->totals['discount'] = array( |
|
3733 | - 'initial' => $discount, |
|
3734 | - 'recurring' => $recurring, |
|
3735 | - ); |
|
3732 | + $this->totals['discount'] = array( |
|
3733 | + 'initial' => $discount, |
|
3734 | + 'recurring' => $recurring, |
|
3735 | + ); |
|
3736 | 3736 | |
3737 | - return $current; |
|
3737 | + return $current; |
|
3738 | 3738 | } |
3739 | 3739 | |
3740 | 3740 | /** |
3741 | - * Recalculates the invoice tax total. |
|
3742 | - * |
|
3743 | - * @since 1.0.19 |
|
3744 | - * @return float The recalculated tax |
|
3745 | - */ |
|
3746 | - public function recalculate_total_tax() { |
|
3741 | + * Recalculates the invoice tax total. |
|
3742 | + * |
|
3743 | + * @since 1.0.19 |
|
3744 | + * @return float The recalculated tax |
|
3745 | + */ |
|
3746 | + public function recalculate_total_tax() { |
|
3747 | 3747 | |
3748 | - // Maybe disable taxes. |
|
3749 | - $vat_number = $this->get_vat_number(); |
|
3750 | - $skip_tax = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number ); |
|
3748 | + // Maybe disable taxes. |
|
3749 | + $vat_number = $this->get_vat_number(); |
|
3750 | + $skip_tax = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number ); |
|
3751 | 3751 | |
3752 | - if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' === wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
3753 | - $skip_tax = false; |
|
3754 | - } |
|
3752 | + if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' === wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
3753 | + $skip_tax = false; |
|
3754 | + } |
|
3755 | 3755 | |
3756 | - if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax ) { |
|
3756 | + if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax ) { |
|
3757 | 3757 | |
3758 | - $this->totals['tax'] = array( |
|
3759 | - 'initial' => 0, |
|
3760 | - 'recurring' => 0, |
|
3761 | - ); |
|
3758 | + $this->totals['tax'] = array( |
|
3759 | + 'initial' => 0, |
|
3760 | + 'recurring' => 0, |
|
3761 | + ); |
|
3762 | 3762 | |
3763 | - $this->tax_rate = 0; |
|
3763 | + $this->tax_rate = 0; |
|
3764 | 3764 | |
3765 | - $this->set_taxes( array() ); |
|
3766 | - $current = 0; |
|
3767 | - } else { |
|
3765 | + $this->set_taxes( array() ); |
|
3766 | + $current = 0; |
|
3767 | + } else { |
|
3768 | 3768 | |
3769 | - $item_taxes = array(); |
|
3769 | + $item_taxes = array(); |
|
3770 | 3770 | |
3771 | - foreach ( $this->get_items() as $item ) { |
|
3772 | - $rates = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() ); |
|
3773 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
3774 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
3775 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
3776 | - foreach ( $taxes as $name => $amount ) { |
|
3777 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
3778 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
3771 | + foreach ( $this->get_items() as $item ) { |
|
3772 | + $rates = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() ); |
|
3773 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
3774 | + $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
3775 | + $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
3776 | + foreach ( $taxes as $name => $amount ) { |
|
3777 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
3778 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
3779 | 3779 | |
3780 | - if ( ! isset( $item_taxes[ $name ] ) ) { |
|
3781 | - $item_taxes[ $name ] = $tax; |
|
3782 | - continue; |
|
3783 | - } |
|
3780 | + if ( ! isset( $item_taxes[ $name ] ) ) { |
|
3781 | + $item_taxes[ $name ] = $tax; |
|
3782 | + continue; |
|
3783 | + } |
|
3784 | 3784 | |
3785 | - $item_taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
3786 | - $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
3785 | + $item_taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
3786 | + $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
3787 | 3787 | |
3788 | - } |
|
3789 | - } |
|
3788 | + } |
|
3789 | + } |
|
3790 | 3790 | |
3791 | - $this->set_taxes( $item_taxes ); |
|
3791 | + $this->set_taxes( $item_taxes ); |
|
3792 | 3792 | |
3793 | - $initial_tax = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) ); |
|
3794 | - $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) ); |
|
3793 | + $initial_tax = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) ); |
|
3794 | + $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) ); |
|
3795 | 3795 | |
3796 | - $current = $this->is_renewal() ? $recurring_tax : $initial_tax; |
|
3796 | + $current = $this->is_renewal() ? $recurring_tax : $initial_tax; |
|
3797 | 3797 | |
3798 | - $this->totals['tax'] = array( |
|
3799 | - 'initial' => $initial_tax, |
|
3800 | - 'recurring' => $recurring_tax, |
|
3801 | - ); |
|
3798 | + $this->totals['tax'] = array( |
|
3799 | + 'initial' => $initial_tax, |
|
3800 | + 'recurring' => $recurring_tax, |
|
3801 | + ); |
|
3802 | 3802 | |
3803 | - } |
|
3803 | + } |
|
3804 | 3804 | |
3805 | - $this->set_total_tax( $current ); |
|
3805 | + $this->set_total_tax( $current ); |
|
3806 | 3806 | |
3807 | - return $current; |
|
3807 | + return $current; |
|
3808 | 3808 | } |
3809 | 3809 | |
3810 | 3810 | /** |
3811 | - * Recalculates the invoice fees total. |
|
3812 | - * |
|
3813 | - * @since 1.0.19 |
|
3814 | - * @return float The recalculated fee |
|
3815 | - */ |
|
3816 | - public function recalculate_total_fees() { |
|
3817 | - $fees = $this->get_fees(); |
|
3818 | - $fee = 0; |
|
3819 | - $recurring = 0; |
|
3811 | + * Recalculates the invoice fees total. |
|
3812 | + * |
|
3813 | + * @since 1.0.19 |
|
3814 | + * @return float The recalculated fee |
|
3815 | + */ |
|
3816 | + public function recalculate_total_fees() { |
|
3817 | + $fees = $this->get_fees(); |
|
3818 | + $fee = 0; |
|
3819 | + $recurring = 0; |
|
3820 | 3820 | |
3821 | 3821 | foreach ( $fees as $data ) { |
3822 | - $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
3823 | - $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
3824 | - } |
|
3822 | + $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
3823 | + $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
3824 | + } |
|
3825 | 3825 | |
3826 | - $current = $this->is_renewal() ? $recurring : $fee; |
|
3827 | - $this->set_total_fees( $current ); |
|
3826 | + $current = $this->is_renewal() ? $recurring : $fee; |
|
3827 | + $this->set_total_fees( $current ); |
|
3828 | 3828 | |
3829 | - $this->totals['fee'] = array( |
|
3830 | - 'initial' => $fee, |
|
3831 | - 'recurring' => $recurring, |
|
3832 | - ); |
|
3829 | + $this->totals['fee'] = array( |
|
3830 | + 'initial' => $fee, |
|
3831 | + 'recurring' => $recurring, |
|
3832 | + ); |
|
3833 | 3833 | |
3834 | 3834 | $this->set_total_fees( $fee ); |
3835 | 3835 | return $current; |
3836 | 3836 | } |
3837 | 3837 | |
3838 | 3838 | /** |
3839 | - * Recalculates the invoice total. |
|
3840 | - * |
|
3841 | - * @since 1.0.19 |
|
3839 | + * Recalculates the invoice total. |
|
3840 | + * |
|
3841 | + * @since 1.0.19 |
|
3842 | 3842 | * @return float The invoice total |
3843 | - */ |
|
3844 | - public function recalculate_total() { |
|
3843 | + */ |
|
3844 | + public function recalculate_total() { |
|
3845 | 3845 | $this->recalculate_total_fees(); |
3846 | 3846 | $this->recalculate_total_discount(); |
3847 | - $this->recalculate_total_tax(); |
|
3848 | - $this->recalculate_subtotal(); |
|
3849 | - $this->set_total( $this->get_total_tax( 'edit' ) + $this->get_total_fees( 'edit' ) + $this->get_subtotal( 'edit' ) - $this->get_total_discount( 'edit' ) ); |
|
3850 | - return $this->get_total(); |
|
3851 | - } |
|
3852 | - |
|
3853 | - /** |
|
3854 | - * @deprecated |
|
3855 | - */ |
|
3847 | + $this->recalculate_total_tax(); |
|
3848 | + $this->recalculate_subtotal(); |
|
3849 | + $this->set_total( $this->get_total_tax( 'edit' ) + $this->get_total_fees( 'edit' ) + $this->get_subtotal( 'edit' ) - $this->get_total_discount( 'edit' ) ); |
|
3850 | + return $this->get_total(); |
|
3851 | + } |
|
3852 | + |
|
3853 | + /** |
|
3854 | + * @deprecated |
|
3855 | + */ |
|
3856 | 3856 | public function recalculate_totals() { |
3857 | 3857 | $this->recalculate_total(); |
3858 | 3858 | $this->save( true ); |
@@ -3866,22 +3866,22 @@ discard block |
||
3866 | 3866 | return $this->get_data(); |
3867 | 3867 | } |
3868 | 3868 | |
3869 | - /** |
|
3869 | + /** |
|
3870 | 3870 | * Adds a system note to an invoice. |
3871 | 3871 | * |
3872 | 3872 | * @param string $note The note being added. |
3873 | - * @return int|false The new note's ID on success, false on failure. |
|
3873 | + * @return int|false The new note's ID on success, false on failure. |
|
3874 | 3874 | * |
3875 | 3875 | */ |
3876 | 3876 | public function add_system_note( $note ) { |
3877 | - return $this->add_note( $note, false, false, true ); |
|
3878 | - } |
|
3877 | + return $this->add_note( $note, false, false, true ); |
|
3878 | + } |
|
3879 | 3879 | |
3880 | 3880 | /** |
3881 | 3881 | * Adds a note to an invoice. |
3882 | 3882 | * |
3883 | 3883 | * @param string $note The note being added. |
3884 | - * @return int|false The new note's ID on success, false on failure. |
|
3884 | + * @return int|false The new note's ID on success, false on failure. |
|
3885 | 3885 | * |
3886 | 3886 | */ |
3887 | 3887 | public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
@@ -3891,20 +3891,20 @@ discard block |
||
3891 | 3891 | return false; |
3892 | 3892 | } |
3893 | 3893 | |
3894 | - $author = 'System'; |
|
3895 | - $author_email = '[email protected]'; |
|
3894 | + $author = 'System'; |
|
3895 | + $author_email = '[email protected]'; |
|
3896 | 3896 | |
3897 | - // If this is an admin comment or it has been added by the user. |
|
3898 | - if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
3899 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
3897 | + // If this is an admin comment or it has been added by the user. |
|
3898 | + if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
3899 | + $user = get_user_by( 'id', get_current_user_id() ); |
|
3900 | 3900 | $author = $user->display_name; |
3901 | 3901 | $author_email = $user->user_email; |
3902 | - } |
|
3902 | + } |
|
3903 | 3903 | |
3904 | - return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
3905 | - } |
|
3904 | + return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
3905 | + } |
|
3906 | 3906 | |
3907 | - /** |
|
3907 | + /** |
|
3908 | 3908 | * Generates a unique key for the invoice. |
3909 | 3909 | */ |
3910 | 3910 | public function generate_key( $string = '' ) { |
@@ -3924,111 +3924,111 @@ discard block |
||
3924 | 3924 | $number = wpinv_get_next_invoice_number( $this->get_post_type() ); |
3925 | 3925 | } |
3926 | 3926 | |
3927 | - return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
3928 | - } |
|
3929 | - |
|
3930 | - /** |
|
3931 | - * Handle the status transition. |
|
3932 | - */ |
|
3933 | - protected function status_transition() { |
|
3934 | - $status_transition = $this->status_transition; |
|
3935 | - |
|
3936 | - // Reset status transition variable. |
|
3937 | - $this->status_transition = false; |
|
3938 | - |
|
3939 | - if ( $status_transition ) { |
|
3940 | - try { |
|
3941 | - |
|
3942 | - // Fire a hook for the status change. |
|
3943 | - do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
3944 | - |
|
3945 | - // @deprecated this is deprecated and will be removed in the future. |
|
3946 | - do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3947 | - |
|
3948 | - if ( ! empty( $status_transition['from'] ) ) { |
|
3949 | - |
|
3950 | - /* translators: 1: old invoice status 2: new invoice status */ |
|
3951 | - $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
3952 | - |
|
3953 | - // Fire another hook. |
|
3954 | - do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
3955 | - do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
3956 | - |
|
3957 | - // @deprecated this is deprecated and will be removed in the future. |
|
3958 | - do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3959 | - |
|
3960 | - // Note the transition occurred. |
|
3961 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
3962 | - |
|
3963 | - // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
3964 | - if ( |
|
3965 | - in_array( $status_transition['from'], array( 'wpi-cancelled', 'pending', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3966 | - && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3967 | - ) { |
|
3968 | - do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
3969 | - } |
|
3970 | - |
|
3971 | - // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
3972 | - if ( |
|
3973 | - in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3974 | - && in_array( $status_transition['to'], array( 'wpi-cancelled', 'pending', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3975 | - ) { |
|
3976 | - do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
3977 | - } |
|
3978 | - } else { |
|
3979 | - /* translators: %s: new invoice status */ |
|
3980 | - $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
3981 | - |
|
3982 | - // Note the transition occurred. |
|
3983 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3984 | - |
|
3985 | - } |
|
3986 | - } catch ( Exception $e ) { |
|
3987 | - $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
3988 | - } |
|
3989 | - } |
|
3990 | - } |
|
3991 | - |
|
3992 | - /** |
|
3993 | - * Updates an invoice status. |
|
3994 | - */ |
|
3995 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
3996 | - |
|
3997 | - // Fires before updating a status. |
|
3998 | - do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
3999 | - |
|
4000 | - // Update the status. |
|
4001 | - $this->set_status( $new_status, $note, $manual ); |
|
4002 | - |
|
4003 | - // Save the order. |
|
4004 | - return $this->save(); |
|
4005 | - } |
|
4006 | - |
|
4007 | - /** |
|
4008 | - * @deprecated |
|
4009 | - */ |
|
4010 | - public function refresh_item_ids() { |
|
3927 | + return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
3928 | + } |
|
3929 | + |
|
3930 | + /** |
|
3931 | + * Handle the status transition. |
|
3932 | + */ |
|
3933 | + protected function status_transition() { |
|
3934 | + $status_transition = $this->status_transition; |
|
3935 | + |
|
3936 | + // Reset status transition variable. |
|
3937 | + $this->status_transition = false; |
|
3938 | + |
|
3939 | + if ( $status_transition ) { |
|
3940 | + try { |
|
3941 | + |
|
3942 | + // Fire a hook for the status change. |
|
3943 | + do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
3944 | + |
|
3945 | + // @deprecated this is deprecated and will be removed in the future. |
|
3946 | + do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3947 | + |
|
3948 | + if ( ! empty( $status_transition['from'] ) ) { |
|
3949 | + |
|
3950 | + /* translators: 1: old invoice status 2: new invoice status */ |
|
3951 | + $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
3952 | + |
|
3953 | + // Fire another hook. |
|
3954 | + do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
3955 | + do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
3956 | + |
|
3957 | + // @deprecated this is deprecated and will be removed in the future. |
|
3958 | + do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3959 | + |
|
3960 | + // Note the transition occurred. |
|
3961 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
3962 | + |
|
3963 | + // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
3964 | + if ( |
|
3965 | + in_array( $status_transition['from'], array( 'wpi-cancelled', 'pending', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3966 | + && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3967 | + ) { |
|
3968 | + do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
3969 | + } |
|
3970 | + |
|
3971 | + // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
3972 | + if ( |
|
3973 | + in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3974 | + && in_array( $status_transition['to'], array( 'wpi-cancelled', 'pending', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3975 | + ) { |
|
3976 | + do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
3977 | + } |
|
3978 | + } else { |
|
3979 | + /* translators: %s: new invoice status */ |
|
3980 | + $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
3981 | + |
|
3982 | + // Note the transition occurred. |
|
3983 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3984 | + |
|
3985 | + } |
|
3986 | + } catch ( Exception $e ) { |
|
3987 | + $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
3988 | + } |
|
3989 | + } |
|
3990 | + } |
|
3991 | + |
|
3992 | + /** |
|
3993 | + * Updates an invoice status. |
|
3994 | + */ |
|
3995 | + public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
3996 | + |
|
3997 | + // Fires before updating a status. |
|
3998 | + do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
3999 | + |
|
4000 | + // Update the status. |
|
4001 | + $this->set_status( $new_status, $note, $manual ); |
|
4002 | + |
|
4003 | + // Save the order. |
|
4004 | + return $this->save(); |
|
4005 | + } |
|
4006 | + |
|
4007 | + /** |
|
4008 | + * @deprecated |
|
4009 | + */ |
|
4010 | + public function refresh_item_ids() { |
|
4011 | 4011 | $item_ids = implode( ',', array_unique( wp_list_pluck( $this->get_cart_details(), 'item_id' ) ) ); |
4012 | 4012 | update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids ); |
4013 | - } |
|
4013 | + } |
|
4014 | 4014 | |
4015 | - /** |
|
4016 | - * @deprecated |
|
4017 | - */ |
|
4018 | - public function update_items( $temp = false ) { |
|
4015 | + /** |
|
4016 | + * @deprecated |
|
4017 | + */ |
|
4018 | + public function update_items( $temp = false ) { |
|
4019 | 4019 | |
4020 | - $this->set_items( $this->get_items() ); |
|
4020 | + $this->set_items( $this->get_items() ); |
|
4021 | 4021 | |
4022 | - if ( ! $temp ) { |
|
4023 | - $this->save(); |
|
4024 | - } |
|
4022 | + if ( ! $temp ) { |
|
4023 | + $this->save(); |
|
4024 | + } |
|
4025 | 4025 | |
4026 | 4026 | return $this; |
4027 | - } |
|
4027 | + } |
|
4028 | 4028 | |
4029 | - /** |
|
4030 | - * @deprecated |
|
4031 | - */ |
|
4029 | + /** |
|
4030 | + * @deprecated |
|
4031 | + */ |
|
4032 | 4032 | public function validate_discount() { |
4033 | 4033 | |
4034 | 4034 | $discount_code = $this->get_discount_code(); |
@@ -4043,100 +4043,100 @@ discard block |
||
4043 | 4043 | return $discount->exists(); |
4044 | 4044 | } |
4045 | 4045 | |
4046 | - /** |
|
4047 | - * Refunds an invoice. |
|
4048 | - */ |
|
4046 | + /** |
|
4047 | + * Refunds an invoice. |
|
4048 | + */ |
|
4049 | 4049 | public function refund() { |
4050 | - $this->set_status( 'wpi-refunded' ); |
|
4050 | + $this->set_status( 'wpi-refunded' ); |
|
4051 | 4051 | $this->save(); |
4052 | - } |
|
4052 | + } |
|
4053 | 4053 | |
4054 | - /** |
|
4055 | - * Marks an invoice as paid. |
|
4056 | - * |
|
4057 | - * @param string $transaction_id |
|
4058 | - */ |
|
4054 | + /** |
|
4055 | + * Marks an invoice as paid. |
|
4056 | + * |
|
4057 | + * @param string $transaction_id |
|
4058 | + */ |
|
4059 | 4059 | public function mark_paid( $transaction_id = null, $note = '' ) { |
4060 | 4060 | |
4061 | - // Set the transaction id. |
|
4062 | - if ( empty( $transaction_id ) ) { |
|
4063 | - $transaction_id = $this->generate_key( 'trans_' ); |
|
4064 | - } |
|
4061 | + // Set the transaction id. |
|
4062 | + if ( empty( $transaction_id ) ) { |
|
4063 | + $transaction_id = $this->generate_key( 'trans_' ); |
|
4064 | + } |
|
4065 | 4065 | |
4066 | - if ( ! $this->get_transaction_id() ) { |
|
4067 | - $this->set_transaction_id( $transaction_id ); |
|
4068 | - } |
|
4066 | + if ( ! $this->get_transaction_id() ) { |
|
4067 | + $this->set_transaction_id( $transaction_id ); |
|
4068 | + } |
|
4069 | 4069 | |
4070 | - if ( $this->is_paid() && 'wpi-processing' !== $this->get_status() ) { |
|
4071 | - return $this->save(); |
|
4072 | - } |
|
4070 | + if ( $this->is_paid() && 'wpi-processing' !== $this->get_status() ) { |
|
4071 | + return $this->save(); |
|
4072 | + } |
|
4073 | 4073 | |
4074 | - // Set the completed date. |
|
4075 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
4074 | + // Set the completed date. |
|
4075 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
4076 | 4076 | |
4077 | - // Set the new status. |
|
4078 | - $gateway = sanitize_text_field( $this->get_gateway_title() ); |
|
4079 | - if ( $this->is_renewal() || ! $this->is_parent() ) { |
|
4077 | + // Set the new status. |
|
4078 | + $gateway = sanitize_text_field( $this->get_gateway_title() ); |
|
4079 | + if ( $this->is_renewal() || ! $this->is_parent() ) { |
|
4080 | 4080 | |
4081 | - $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway ); |
|
4082 | - $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
4081 | + $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway ); |
|
4082 | + $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
4083 | 4083 | |
4084 | - if ( 'none' == $this->get_gateway() ) { |
|
4085 | - $_note = $note; |
|
4086 | - } |
|
4084 | + if ( 'none' == $this->get_gateway() ) { |
|
4085 | + $_note = $note; |
|
4086 | + } |
|
4087 | 4087 | |
4088 | - $this->set_status( 'wpi-renewal', $_note ); |
|
4088 | + $this->set_status( 'wpi-renewal', $_note ); |
|
4089 | 4089 | |
4090 | - } else { |
|
4090 | + } else { |
|
4091 | 4091 | |
4092 | - $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway ); |
|
4093 | - $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
4092 | + $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway ); |
|
4093 | + $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
4094 | 4094 | |
4095 | - if ( 'none' == $this->get_gateway() ) { |
|
4096 | - $_note = $note; |
|
4097 | - } |
|
4095 | + if ( 'none' == $this->get_gateway() ) { |
|
4096 | + $_note = $note; |
|
4097 | + } |
|
4098 | 4098 | |
4099 | - $this->set_status( 'publish', $_note ); |
|
4099 | + $this->set_status( 'publish', $_note ); |
|
4100 | 4100 | |
4101 | - } |
|
4101 | + } |
|
4102 | 4102 | |
4103 | - // Set checkout mode. |
|
4104 | - $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
4105 | - $this->set_mode( $mode ); |
|
4103 | + // Set checkout mode. |
|
4104 | + $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
4105 | + $this->set_mode( $mode ); |
|
4106 | 4106 | |
4107 | - // Save the invoice. |
|
4107 | + // Save the invoice. |
|
4108 | 4108 | $this->save(); |
4109 | - } |
|
4110 | - |
|
4111 | - /** |
|
4112 | - * Save data to the database. |
|
4113 | - * |
|
4114 | - * @since 1.0.19 |
|
4115 | - * @return int invoice ID |
|
4116 | - */ |
|
4117 | - public function save() { |
|
4118 | - $this->maybe_set_date_paid(); |
|
4119 | - $this->maybe_set_key(); |
|
4120 | - parent::save(); |
|
4121 | - $this->clear_cache(); |
|
4122 | - $this->status_transition(); |
|
4123 | - return $this->get_id(); |
|
4124 | - } |
|
4125 | - |
|
4126 | - /** |
|
4109 | + } |
|
4110 | + |
|
4111 | + /** |
|
4112 | + * Save data to the database. |
|
4113 | + * |
|
4114 | + * @since 1.0.19 |
|
4115 | + * @return int invoice ID |
|
4116 | + */ |
|
4117 | + public function save() { |
|
4118 | + $this->maybe_set_date_paid(); |
|
4119 | + $this->maybe_set_key(); |
|
4120 | + parent::save(); |
|
4121 | + $this->clear_cache(); |
|
4122 | + $this->status_transition(); |
|
4123 | + return $this->get_id(); |
|
4124 | + } |
|
4125 | + |
|
4126 | + /** |
|
4127 | 4127 | * Clears the subscription's cache. |
4128 | 4128 | */ |
4129 | 4129 | public function clear_cache() { |
4130 | - if ( $this->get_key() ) { |
|
4131 | - wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
4132 | - } |
|
4133 | - |
|
4134 | - if ( $this->get_number() ) { |
|
4135 | - wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
4136 | - } |
|
4137 | - |
|
4138 | - if ( $this->get_transaction_id() ) { |
|
4139 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
4140 | - } |
|
4141 | - } |
|
4130 | + if ( $this->get_key() ) { |
|
4131 | + wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
4132 | + } |
|
4133 | + |
|
4134 | + if ( $this->get_number() ) { |
|
4135 | + wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
4136 | + } |
|
4137 | + |
|
4138 | + if ( $this->get_transaction_id() ) { |
|
4139 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
4140 | + } |
|
4141 | + } |
|
4142 | 4142 | } |
@@ -14,620 +14,620 @@ |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var array An array of payment gateways. |
|
40 | - */ |
|
41 | - public $gateways; |
|
42 | - |
|
43 | - /** |
|
44 | - * Class constructor. |
|
45 | - */ |
|
46 | - public function __construct() { |
|
47 | - $this->define_constants(); |
|
48 | - $this->includes(); |
|
49 | - $this->init_hooks(); |
|
50 | - $this->set_properties(); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Sets a custom data property. |
|
55 | - * |
|
56 | - * @param string $prop The prop to set. |
|
57 | - * @param mixed $value The value to retrieve. |
|
58 | - */ |
|
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Gets a custom data property. |
|
65 | - * |
|
66 | - * @param string $prop The prop to set. |
|
67 | - * @return mixed The value. |
|
68 | - */ |
|
69 | - public function get( $prop ) { |
|
70 | - if ( isset( $this->data[ $prop ] ) ) { |
|
71 | - return $this->data[ $prop ]; |
|
72 | - } |
|
73 | - |
|
74 | - return null; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Define class properties. |
|
79 | - */ |
|
80 | - public function set_properties() { |
|
81 | - // Sessions. |
|
82 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
83 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
84 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
85 | - |
|
86 | - // Init other objects. |
|
87 | - $this->set( 'notes', new WPInv_Notes() ); |
|
88 | - $this->set( 'api', new WPInv_API() ); |
|
89 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
90 | - $this->set( 'template', new GetPaid_Template() ); |
|
91 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
92 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
93 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
94 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
95 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
96 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
97 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
98 | - $this->set( 'data_retention', new WPInv_Data_Retention() ); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Define plugin constants. |
|
103 | - */ |
|
104 | - public function define_constants() { |
|
105 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
106 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
107 | - $this->version = WPINV_VERSION; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Hook into actions and filters. |
|
112 | - * |
|
113 | - * @since 1.0.19 |
|
114 | - */ |
|
115 | - protected function init_hooks() { |
|
116 | - /* Internationalize the text strings used. */ |
|
117 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
118 | - |
|
119 | - // Init the plugin after WordPress inits. |
|
120 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
121 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
122 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
123 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
124 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
125 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
126 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
127 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
128 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
129 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
130 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
131 | - |
|
132 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
133 | - add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
134 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
135 | - |
|
136 | - // Fires after registering actions. |
|
137 | - do_action( 'wpinv_actions', $this ); |
|
138 | - do_action( 'getpaid_actions', $this ); |
|
139 | - } |
|
140 | - |
|
141 | - public function plugins_loaded() { |
|
142 | - /* Internationalize the text strings used. */ |
|
143 | - $this->load_textdomain(); |
|
144 | - |
|
145 | - do_action( 'wpinv_loaded' ); |
|
146 | - |
|
147 | - // Fix oxygen page builder conflict |
|
148 | - if ( function_exists( 'ct_css_output' ) ) { |
|
149 | - wpinv_oxygen_fix_conflict(); |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Load Localisation files. |
|
155 | - * |
|
156 | - * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
157 | - * |
|
158 | - * Locales found in: |
|
159 | - * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
160 | - * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
161 | - * |
|
162 | - * @since 1.0.0 |
|
163 | - */ |
|
164 | - public function load_textdomain() { |
|
165 | - // Determines the current locale. |
|
166 | - if ( function_exists( 'determine_locale' ) ) { |
|
167 | - $locale = determine_locale(); |
|
168 | - } elseif ( function_exists( 'get_user_locale' ) ) { |
|
169 | - $locale = get_user_locale(); |
|
170 | - } else { |
|
171 | - $locale = get_locale(); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Filter the locale to use for translations. |
|
176 | - */ |
|
177 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
178 | - |
|
179 | - unload_textdomain( 'invoicing', true ); |
|
180 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
181 | - load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Include required core files used in admin and on the frontend. |
|
186 | - */ |
|
187 | - public function includes() { |
|
188 | - // Start with the settings. |
|
189 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
190 | - |
|
191 | - // Packages/libraries. |
|
192 | - require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
193 | - require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
194 | - |
|
195 | - // Load functions. |
|
196 | - require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
197 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
198 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
199 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
200 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
201 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
202 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
203 | - require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
204 | - require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
205 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
206 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
207 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
208 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
209 | - require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
210 | - require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
211 | - |
|
212 | - // Register autoloader. |
|
213 | - try { |
|
214 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
215 | - } catch ( Exception $e ) { |
|
216 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
217 | - } |
|
218 | - |
|
219 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
220 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
221 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
222 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
223 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
224 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
225 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
226 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
227 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
228 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
229 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
230 | - require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
231 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
232 | - require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
233 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
234 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
235 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
236 | - require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
237 | - require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
238 | - require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
239 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
240 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
241 | - |
|
242 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
243 | - GetPaid_Post_Types_Admin::init(); |
|
244 | - |
|
245 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
246 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
247 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
248 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
249 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
250 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
251 | - // load the user class only on the users.php page |
|
252 | - global $pagenow; |
|
253 | - if ( $pagenow == 'users.php' ) { |
|
254 | - new WPInv_Admin_Users(); |
|
255 | - } |
|
256 | - } |
|
257 | - |
|
258 | - // Register cli commands |
|
259 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
260 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
261 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
262 | - } |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Class autoloader |
|
267 | - * |
|
268 | - * @param string $class_name The name of the class to load. |
|
269 | - * @access public |
|
270 | - * @since 1.0.19 |
|
271 | - * @return void |
|
272 | - */ |
|
273 | - public function autoload( $class_name ) { |
|
274 | - // Normalize the class name... |
|
275 | - $class_name = strtolower( $class_name ); |
|
276 | - |
|
277 | - // ... and make sure it is our class. |
|
278 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
279 | - return; |
|
280 | - } |
|
281 | - |
|
282 | - // Next, prepare the file name from the class. |
|
283 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
284 | - |
|
285 | - // Base path of the classes. |
|
286 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
287 | - |
|
288 | - // And an array of possible locations in order of importance. |
|
289 | - $locations = array( |
|
290 | - "$plugin_path/includes", |
|
291 | - "$plugin_path/includes/data-stores", |
|
292 | - "$plugin_path/includes/gateways", |
|
293 | - "$plugin_path/includes/payments", |
|
294 | - "$plugin_path/includes/geolocation", |
|
295 | - "$plugin_path/includes/reports", |
|
296 | - "$plugin_path/includes/api", |
|
297 | - "$plugin_path/includes/admin", |
|
298 | - "$plugin_path/includes/admin/meta-boxes", |
|
299 | - ); |
|
300 | - |
|
301 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
302 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
303 | - include trailingslashit( $location ) . $file_name; |
|
304 | - break; |
|
305 | - } |
|
306 | - } |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * Inits hooks etc. |
|
311 | - */ |
|
312 | - public function init() { |
|
313 | - // Fires before getpaid inits. |
|
314 | - do_action( 'before_getpaid_init', $this ); |
|
315 | - |
|
316 | - // Maybe upgrade. |
|
317 | - $this->maybe_upgrade_database(); |
|
318 | - |
|
319 | - // Load default gateways. |
|
320 | - $gateways = apply_filters( |
|
321 | - 'getpaid_default_gateways', |
|
322 | - array( |
|
323 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
324 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
325 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
326 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
327 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
328 | - ) |
|
329 | - ); |
|
330 | - |
|
331 | - foreach ( $gateways as $id => $class ) { |
|
332 | - $this->gateways[ $id ] = new $class(); |
|
333 | - } |
|
334 | - |
|
335 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
336 | - GetPaid_Installer::rename_gateways_label(); |
|
337 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
338 | - } |
|
339 | - |
|
340 | - // Fires after getpaid inits. |
|
341 | - do_action( 'getpaid_init', $this ); |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Checks if this is an IPN request and processes it. |
|
346 | - */ |
|
347 | - public function maybe_process_ipn() { |
|
348 | - // Ensure that this is an IPN request. |
|
349 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
350 | - return; |
|
351 | - } |
|
352 | - |
|
353 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
354 | - |
|
355 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
356 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
357 | - exit; |
|
358 | - } |
|
359 | - |
|
360 | - public function enqueue_scripts() { |
|
361 | - // Fires before adding scripts. |
|
362 | - do_action( 'getpaid_enqueue_scripts' ); |
|
363 | - |
|
364 | - $localize = array(); |
|
365 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
366 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
367 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
368 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
369 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
370 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
371 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
372 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
373 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
374 | - $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
375 | - |
|
376 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
377 | - |
|
378 | - // reCaptcha. |
|
379 | - if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
380 | - wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
381 | - } |
|
382 | - |
|
383 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array( 'jquery' ), WPINV_VERSION, true ); |
|
384 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
385 | - } |
|
386 | - |
|
387 | - public function wpinv_actions() { |
|
388 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
389 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
390 | - } |
|
391 | - |
|
392 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
393 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
394 | - } |
|
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * Fires an action after verifying that a user can fire them. |
|
399 | - * |
|
400 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
401 | - * current user owns the invoice/subscription. |
|
402 | - */ |
|
403 | - public function maybe_do_authenticated_action() { |
|
404 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
405 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
406 | - $data = wp_unslash( $_REQUEST ); |
|
407 | - |
|
408 | - if ( is_user_logged_in() ) { |
|
409 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
410 | - } |
|
411 | - |
|
412 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
413 | - } |
|
414 | - } |
|
415 | - |
|
416 | - public function pre_get_posts( $wp_query ) { |
|
417 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
418 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
419 | - } |
|
420 | - |
|
421 | - return $wp_query; |
|
422 | - } |
|
423 | - |
|
424 | - /** |
|
425 | - * Register widgets |
|
426 | - * |
|
427 | - */ |
|
428 | - public function register_widgets() { |
|
429 | - global $pagenow; |
|
430 | - |
|
431 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
432 | - // So we disable our widgets when editing a page with UX Builder. |
|
433 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
434 | - return; |
|
435 | - } |
|
436 | - |
|
437 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
438 | - |
|
439 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
440 | - // don't initiate in these conditions. |
|
441 | - } else { |
|
442 | - // Only load allowed widgets. |
|
443 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
444 | - $widgets = apply_filters( |
|
445 | - 'getpaid_widget_classes', |
|
446 | - array( |
|
447 | - 'WPInv_Checkout_Widget', |
|
448 | - 'WPInv_History_Widget', |
|
449 | - 'WPInv_Receipt_Widget', |
|
450 | - 'WPInv_Subscriptions_Widget', |
|
451 | - 'WPInv_Buy_Item_Widget', |
|
452 | - 'WPInv_Messages_Widget', |
|
453 | - 'WPInv_GetPaid_Widget', |
|
454 | - 'WPInv_Invoice_Widget', |
|
455 | - ) |
|
456 | - ); |
|
457 | - |
|
458 | - // For each widget... |
|
459 | - foreach ( $widgets as $widget ) { |
|
460 | - // Abort early if it is excluded for this page. |
|
461 | - if ( in_array( $widget, $exclude ) ) { |
|
462 | - continue; |
|
463 | - } |
|
464 | - |
|
465 | - // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
466 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
467 | - register_widget( $widget ); |
|
468 | - } else { |
|
469 | - new $widget(); |
|
470 | - } |
|
471 | - } |
|
472 | - } |
|
473 | - } |
|
474 | - |
|
475 | - /** |
|
476 | - * Upgrades the database. |
|
477 | - * |
|
478 | - * @since 2.0.2 |
|
479 | - */ |
|
480 | - public function maybe_upgrade_database() { |
|
481 | - // Ensure the database tables are up to date. |
|
482 | - GetPaid_Installer::maybe_create_db_tables(); |
|
483 | - |
|
484 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
485 | - |
|
486 | - if ( $wpi_version == WPINV_VERSION ) { |
|
487 | - return; |
|
488 | - } |
|
489 | - |
|
490 | - $installer = new GetPaid_Installer(); |
|
491 | - |
|
492 | - if ( empty( $wpi_version ) ) { |
|
493 | - return $installer->upgrade_db( 0 ); |
|
494 | - } |
|
495 | - |
|
496 | - $upgrades = array( |
|
497 | - '0.0.5' => '004', |
|
498 | - '1.0.3' => '102', |
|
499 | - '2.0.0' => '118', |
|
500 | - '2.8.0' => '279', |
|
501 | - ); |
|
502 | - |
|
503 | - foreach ( $upgrades as $key => $method ) { |
|
504 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
505 | - return $installer->upgrade_db( $method ); |
|
506 | - } |
|
507 | - } |
|
508 | - } |
|
509 | - |
|
510 | - /** |
|
511 | - * Flushes the permalinks if needed. |
|
512 | - * |
|
513 | - * @since 2.0.8 |
|
514 | - */ |
|
515 | - public function maybe_flush_permalinks() { |
|
516 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
517 | - |
|
518 | - if ( ! empty( $flush ) ) { |
|
519 | - flush_rewrite_rules(); |
|
520 | - delete_option( 'wpinv_flush_permalinks' ); |
|
521 | - } |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * Remove our pages from yoast sitemaps. |
|
526 | - * |
|
527 | - * @since 1.0.19 |
|
528 | - * @param int[] $excluded_posts_ids |
|
529 | - */ |
|
530 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
531 | - // Ensure that we have an array. |
|
532 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
533 | - $excluded_posts_ids = array(); |
|
534 | - } |
|
535 | - |
|
536 | - // Prepare our pages. |
|
537 | - $our_pages = array(); |
|
538 | - |
|
539 | - // Checkout page. |
|
540 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
541 | - |
|
542 | - // Success page. |
|
543 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
544 | - |
|
545 | - // Failure page. |
|
546 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
547 | - |
|
548 | - // History page. |
|
549 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
550 | - |
|
551 | - // Subscriptions page. |
|
552 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
553 | - |
|
554 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
555 | - |
|
556 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
557 | - |
|
558 | - return array_unique( $excluded_posts_ids ); |
|
559 | - } |
|
560 | - |
|
561 | - /** |
|
562 | - * Remove our pages from yoast sitemaps. |
|
563 | - * |
|
564 | - * @since 1.0.19 |
|
565 | - * @param string[] $post_types |
|
566 | - */ |
|
567 | - public function exclude_invoicing_post_types( $post_types ) { |
|
568 | - // Ensure that we have an array. |
|
569 | - if ( ! is_array( $post_types ) ) { |
|
570 | - $post_types = array(); |
|
571 | - } |
|
572 | - |
|
573 | - // Remove our post types. |
|
574 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * Displays additional footer code. |
|
579 | - * |
|
580 | - * @since 2.0.0 |
|
581 | - */ |
|
582 | - public function wp_footer() { |
|
583 | - wpinv_get_template( 'frontend-footer.php' ); |
|
584 | - } |
|
585 | - |
|
586 | - /** |
|
587 | - * Displays additional header code. |
|
588 | - * |
|
589 | - * @since 2.0.0 |
|
590 | - */ |
|
591 | - public function wp_head() { |
|
592 | - wpinv_get_template( 'frontend-head.php' ); |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * Custom query vars. |
|
597 | - * |
|
598 | - */ |
|
599 | - public function custom_query_vars( $vars ) { |
|
600 | - $vars[] = 'getpaid-ipn'; |
|
601 | - return $vars; |
|
602 | - } |
|
603 | - |
|
604 | - /** |
|
605 | - * Add rewrite tags and rules. |
|
606 | - * |
|
607 | - */ |
|
608 | - public function add_rewrite_rule() { |
|
609 | - $tag = 'getpaid-ipn'; |
|
610 | - add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
611 | - add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * Processes non-query string ipns. |
|
616 | - * |
|
617 | - */ |
|
618 | - public function maybe_process_new_ipn( $query ) { |
|
619 | - if ( is_admin() || ! $query->is_main_query() ) { |
|
620 | - return; |
|
621 | - } |
|
622 | - |
|
623 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
624 | - |
|
625 | - if ( ! empty( $gateway ) ) { |
|
626 | - $gateway = sanitize_text_field( $gateway ); |
|
627 | - nocache_headers(); |
|
628 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
629 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
630 | - exit; |
|
631 | - } |
|
632 | - } |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var array An array of payment gateways. |
|
40 | + */ |
|
41 | + public $gateways; |
|
42 | + |
|
43 | + /** |
|
44 | + * Class constructor. |
|
45 | + */ |
|
46 | + public function __construct() { |
|
47 | + $this->define_constants(); |
|
48 | + $this->includes(); |
|
49 | + $this->init_hooks(); |
|
50 | + $this->set_properties(); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Sets a custom data property. |
|
55 | + * |
|
56 | + * @param string $prop The prop to set. |
|
57 | + * @param mixed $value The value to retrieve. |
|
58 | + */ |
|
59 | + public function set( $prop, $value ) { |
|
60 | + $this->data[ $prop ] = $value; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Gets a custom data property. |
|
65 | + * |
|
66 | + * @param string $prop The prop to set. |
|
67 | + * @return mixed The value. |
|
68 | + */ |
|
69 | + public function get( $prop ) { |
|
70 | + if ( isset( $this->data[ $prop ] ) ) { |
|
71 | + return $this->data[ $prop ]; |
|
72 | + } |
|
73 | + |
|
74 | + return null; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Define class properties. |
|
79 | + */ |
|
80 | + public function set_properties() { |
|
81 | + // Sessions. |
|
82 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
83 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
84 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
85 | + |
|
86 | + // Init other objects. |
|
87 | + $this->set( 'notes', new WPInv_Notes() ); |
|
88 | + $this->set( 'api', new WPInv_API() ); |
|
89 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
90 | + $this->set( 'template', new GetPaid_Template() ); |
|
91 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
92 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
93 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
94 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
95 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
96 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
97 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
98 | + $this->set( 'data_retention', new WPInv_Data_Retention() ); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Define plugin constants. |
|
103 | + */ |
|
104 | + public function define_constants() { |
|
105 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
106 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
107 | + $this->version = WPINV_VERSION; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Hook into actions and filters. |
|
112 | + * |
|
113 | + * @since 1.0.19 |
|
114 | + */ |
|
115 | + protected function init_hooks() { |
|
116 | + /* Internationalize the text strings used. */ |
|
117 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
118 | + |
|
119 | + // Init the plugin after WordPress inits. |
|
120 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
121 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
122 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
123 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
124 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
125 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
126 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
127 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
128 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
129 | + add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
130 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
131 | + |
|
132 | + add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
133 | + add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
134 | + add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
135 | + |
|
136 | + // Fires after registering actions. |
|
137 | + do_action( 'wpinv_actions', $this ); |
|
138 | + do_action( 'getpaid_actions', $this ); |
|
139 | + } |
|
140 | + |
|
141 | + public function plugins_loaded() { |
|
142 | + /* Internationalize the text strings used. */ |
|
143 | + $this->load_textdomain(); |
|
144 | + |
|
145 | + do_action( 'wpinv_loaded' ); |
|
146 | + |
|
147 | + // Fix oxygen page builder conflict |
|
148 | + if ( function_exists( 'ct_css_output' ) ) { |
|
149 | + wpinv_oxygen_fix_conflict(); |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Load Localisation files. |
|
155 | + * |
|
156 | + * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
157 | + * |
|
158 | + * Locales found in: |
|
159 | + * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
160 | + * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
161 | + * |
|
162 | + * @since 1.0.0 |
|
163 | + */ |
|
164 | + public function load_textdomain() { |
|
165 | + // Determines the current locale. |
|
166 | + if ( function_exists( 'determine_locale' ) ) { |
|
167 | + $locale = determine_locale(); |
|
168 | + } elseif ( function_exists( 'get_user_locale' ) ) { |
|
169 | + $locale = get_user_locale(); |
|
170 | + } else { |
|
171 | + $locale = get_locale(); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Filter the locale to use for translations. |
|
176 | + */ |
|
177 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
178 | + |
|
179 | + unload_textdomain( 'invoicing', true ); |
|
180 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
181 | + load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Include required core files used in admin and on the frontend. |
|
186 | + */ |
|
187 | + public function includes() { |
|
188 | + // Start with the settings. |
|
189 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
190 | + |
|
191 | + // Packages/libraries. |
|
192 | + require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
193 | + require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
194 | + |
|
195 | + // Load functions. |
|
196 | + require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
197 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
198 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
199 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
200 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
201 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
202 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
203 | + require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
204 | + require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
205 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
206 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
207 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
208 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
209 | + require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
210 | + require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
211 | + |
|
212 | + // Register autoloader. |
|
213 | + try { |
|
214 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
215 | + } catch ( Exception $e ) { |
|
216 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
217 | + } |
|
218 | + |
|
219 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
220 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
221 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
222 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
223 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
224 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
225 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
226 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
227 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
228 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
229 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
230 | + require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
231 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
232 | + require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
233 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
234 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
235 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
236 | + require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
237 | + require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
238 | + require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
239 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
240 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
241 | + |
|
242 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
243 | + GetPaid_Post_Types_Admin::init(); |
|
244 | + |
|
245 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
246 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
247 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
248 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
249 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
250 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
251 | + // load the user class only on the users.php page |
|
252 | + global $pagenow; |
|
253 | + if ( $pagenow == 'users.php' ) { |
|
254 | + new WPInv_Admin_Users(); |
|
255 | + } |
|
256 | + } |
|
257 | + |
|
258 | + // Register cli commands |
|
259 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
260 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
261 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
262 | + } |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Class autoloader |
|
267 | + * |
|
268 | + * @param string $class_name The name of the class to load. |
|
269 | + * @access public |
|
270 | + * @since 1.0.19 |
|
271 | + * @return void |
|
272 | + */ |
|
273 | + public function autoload( $class_name ) { |
|
274 | + // Normalize the class name... |
|
275 | + $class_name = strtolower( $class_name ); |
|
276 | + |
|
277 | + // ... and make sure it is our class. |
|
278 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
279 | + return; |
|
280 | + } |
|
281 | + |
|
282 | + // Next, prepare the file name from the class. |
|
283 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
284 | + |
|
285 | + // Base path of the classes. |
|
286 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
287 | + |
|
288 | + // And an array of possible locations in order of importance. |
|
289 | + $locations = array( |
|
290 | + "$plugin_path/includes", |
|
291 | + "$plugin_path/includes/data-stores", |
|
292 | + "$plugin_path/includes/gateways", |
|
293 | + "$plugin_path/includes/payments", |
|
294 | + "$plugin_path/includes/geolocation", |
|
295 | + "$plugin_path/includes/reports", |
|
296 | + "$plugin_path/includes/api", |
|
297 | + "$plugin_path/includes/admin", |
|
298 | + "$plugin_path/includes/admin/meta-boxes", |
|
299 | + ); |
|
300 | + |
|
301 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
302 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
303 | + include trailingslashit( $location ) . $file_name; |
|
304 | + break; |
|
305 | + } |
|
306 | + } |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * Inits hooks etc. |
|
311 | + */ |
|
312 | + public function init() { |
|
313 | + // Fires before getpaid inits. |
|
314 | + do_action( 'before_getpaid_init', $this ); |
|
315 | + |
|
316 | + // Maybe upgrade. |
|
317 | + $this->maybe_upgrade_database(); |
|
318 | + |
|
319 | + // Load default gateways. |
|
320 | + $gateways = apply_filters( |
|
321 | + 'getpaid_default_gateways', |
|
322 | + array( |
|
323 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
324 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
325 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
326 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
327 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
328 | + ) |
|
329 | + ); |
|
330 | + |
|
331 | + foreach ( $gateways as $id => $class ) { |
|
332 | + $this->gateways[ $id ] = new $class(); |
|
333 | + } |
|
334 | + |
|
335 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
336 | + GetPaid_Installer::rename_gateways_label(); |
|
337 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
338 | + } |
|
339 | + |
|
340 | + // Fires after getpaid inits. |
|
341 | + do_action( 'getpaid_init', $this ); |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Checks if this is an IPN request and processes it. |
|
346 | + */ |
|
347 | + public function maybe_process_ipn() { |
|
348 | + // Ensure that this is an IPN request. |
|
349 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
350 | + return; |
|
351 | + } |
|
352 | + |
|
353 | + $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
354 | + |
|
355 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
356 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
357 | + exit; |
|
358 | + } |
|
359 | + |
|
360 | + public function enqueue_scripts() { |
|
361 | + // Fires before adding scripts. |
|
362 | + do_action( 'getpaid_enqueue_scripts' ); |
|
363 | + |
|
364 | + $localize = array(); |
|
365 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
366 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
367 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
368 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
369 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
370 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
371 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
372 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
373 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
374 | + $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
375 | + |
|
376 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
377 | + |
|
378 | + // reCaptcha. |
|
379 | + if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
380 | + wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
381 | + } |
|
382 | + |
|
383 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array( 'jquery' ), WPINV_VERSION, true ); |
|
384 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
385 | + } |
|
386 | + |
|
387 | + public function wpinv_actions() { |
|
388 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
389 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
390 | + } |
|
391 | + |
|
392 | + if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
393 | + include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
394 | + } |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | + * Fires an action after verifying that a user can fire them. |
|
399 | + * |
|
400 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
401 | + * current user owns the invoice/subscription. |
|
402 | + */ |
|
403 | + public function maybe_do_authenticated_action() { |
|
404 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
405 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
406 | + $data = wp_unslash( $_REQUEST ); |
|
407 | + |
|
408 | + if ( is_user_logged_in() ) { |
|
409 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
410 | + } |
|
411 | + |
|
412 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
413 | + } |
|
414 | + } |
|
415 | + |
|
416 | + public function pre_get_posts( $wp_query ) { |
|
417 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
418 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
419 | + } |
|
420 | + |
|
421 | + return $wp_query; |
|
422 | + } |
|
423 | + |
|
424 | + /** |
|
425 | + * Register widgets |
|
426 | + * |
|
427 | + */ |
|
428 | + public function register_widgets() { |
|
429 | + global $pagenow; |
|
430 | + |
|
431 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
432 | + // So we disable our widgets when editing a page with UX Builder. |
|
433 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
434 | + return; |
|
435 | + } |
|
436 | + |
|
437 | + $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
438 | + |
|
439 | + if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
440 | + // don't initiate in these conditions. |
|
441 | + } else { |
|
442 | + // Only load allowed widgets. |
|
443 | + $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
444 | + $widgets = apply_filters( |
|
445 | + 'getpaid_widget_classes', |
|
446 | + array( |
|
447 | + 'WPInv_Checkout_Widget', |
|
448 | + 'WPInv_History_Widget', |
|
449 | + 'WPInv_Receipt_Widget', |
|
450 | + 'WPInv_Subscriptions_Widget', |
|
451 | + 'WPInv_Buy_Item_Widget', |
|
452 | + 'WPInv_Messages_Widget', |
|
453 | + 'WPInv_GetPaid_Widget', |
|
454 | + 'WPInv_Invoice_Widget', |
|
455 | + ) |
|
456 | + ); |
|
457 | + |
|
458 | + // For each widget... |
|
459 | + foreach ( $widgets as $widget ) { |
|
460 | + // Abort early if it is excluded for this page. |
|
461 | + if ( in_array( $widget, $exclude ) ) { |
|
462 | + continue; |
|
463 | + } |
|
464 | + |
|
465 | + // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
466 | + if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
467 | + register_widget( $widget ); |
|
468 | + } else { |
|
469 | + new $widget(); |
|
470 | + } |
|
471 | + } |
|
472 | + } |
|
473 | + } |
|
474 | + |
|
475 | + /** |
|
476 | + * Upgrades the database. |
|
477 | + * |
|
478 | + * @since 2.0.2 |
|
479 | + */ |
|
480 | + public function maybe_upgrade_database() { |
|
481 | + // Ensure the database tables are up to date. |
|
482 | + GetPaid_Installer::maybe_create_db_tables(); |
|
483 | + |
|
484 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
485 | + |
|
486 | + if ( $wpi_version == WPINV_VERSION ) { |
|
487 | + return; |
|
488 | + } |
|
489 | + |
|
490 | + $installer = new GetPaid_Installer(); |
|
491 | + |
|
492 | + if ( empty( $wpi_version ) ) { |
|
493 | + return $installer->upgrade_db( 0 ); |
|
494 | + } |
|
495 | + |
|
496 | + $upgrades = array( |
|
497 | + '0.0.5' => '004', |
|
498 | + '1.0.3' => '102', |
|
499 | + '2.0.0' => '118', |
|
500 | + '2.8.0' => '279', |
|
501 | + ); |
|
502 | + |
|
503 | + foreach ( $upgrades as $key => $method ) { |
|
504 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
505 | + return $installer->upgrade_db( $method ); |
|
506 | + } |
|
507 | + } |
|
508 | + } |
|
509 | + |
|
510 | + /** |
|
511 | + * Flushes the permalinks if needed. |
|
512 | + * |
|
513 | + * @since 2.0.8 |
|
514 | + */ |
|
515 | + public function maybe_flush_permalinks() { |
|
516 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
517 | + |
|
518 | + if ( ! empty( $flush ) ) { |
|
519 | + flush_rewrite_rules(); |
|
520 | + delete_option( 'wpinv_flush_permalinks' ); |
|
521 | + } |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * Remove our pages from yoast sitemaps. |
|
526 | + * |
|
527 | + * @since 1.0.19 |
|
528 | + * @param int[] $excluded_posts_ids |
|
529 | + */ |
|
530 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
531 | + // Ensure that we have an array. |
|
532 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
533 | + $excluded_posts_ids = array(); |
|
534 | + } |
|
535 | + |
|
536 | + // Prepare our pages. |
|
537 | + $our_pages = array(); |
|
538 | + |
|
539 | + // Checkout page. |
|
540 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
541 | + |
|
542 | + // Success page. |
|
543 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
544 | + |
|
545 | + // Failure page. |
|
546 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
547 | + |
|
548 | + // History page. |
|
549 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
550 | + |
|
551 | + // Subscriptions page. |
|
552 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
553 | + |
|
554 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
555 | + |
|
556 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
557 | + |
|
558 | + return array_unique( $excluded_posts_ids ); |
|
559 | + } |
|
560 | + |
|
561 | + /** |
|
562 | + * Remove our pages from yoast sitemaps. |
|
563 | + * |
|
564 | + * @since 1.0.19 |
|
565 | + * @param string[] $post_types |
|
566 | + */ |
|
567 | + public function exclude_invoicing_post_types( $post_types ) { |
|
568 | + // Ensure that we have an array. |
|
569 | + if ( ! is_array( $post_types ) ) { |
|
570 | + $post_types = array(); |
|
571 | + } |
|
572 | + |
|
573 | + // Remove our post types. |
|
574 | + return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * Displays additional footer code. |
|
579 | + * |
|
580 | + * @since 2.0.0 |
|
581 | + */ |
|
582 | + public function wp_footer() { |
|
583 | + wpinv_get_template( 'frontend-footer.php' ); |
|
584 | + } |
|
585 | + |
|
586 | + /** |
|
587 | + * Displays additional header code. |
|
588 | + * |
|
589 | + * @since 2.0.0 |
|
590 | + */ |
|
591 | + public function wp_head() { |
|
592 | + wpinv_get_template( 'frontend-head.php' ); |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * Custom query vars. |
|
597 | + * |
|
598 | + */ |
|
599 | + public function custom_query_vars( $vars ) { |
|
600 | + $vars[] = 'getpaid-ipn'; |
|
601 | + return $vars; |
|
602 | + } |
|
603 | + |
|
604 | + /** |
|
605 | + * Add rewrite tags and rules. |
|
606 | + * |
|
607 | + */ |
|
608 | + public function add_rewrite_rule() { |
|
609 | + $tag = 'getpaid-ipn'; |
|
610 | + add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
611 | + add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * Processes non-query string ipns. |
|
616 | + * |
|
617 | + */ |
|
618 | + public function maybe_process_new_ipn( $query ) { |
|
619 | + if ( is_admin() || ! $query->is_main_query() ) { |
|
620 | + return; |
|
621 | + } |
|
622 | + |
|
623 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
624 | + |
|
625 | + if ( ! empty( $gateway ) ) { |
|
626 | + $gateway = sanitize_text_field( $gateway ); |
|
627 | + nocache_headers(); |
|
628 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
629 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
630 | + exit; |
|
631 | + } |
|
632 | + } |
|
633 | 633 | } |