@@ -20,214 +20,214 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class GetPaid_Installer { |
22 | 22 | |
23 | - /** |
|
24 | - * Upgrades the install. |
|
25 | - * |
|
26 | - * @param string $upgrade_from The current invoicing version. |
|
27 | - */ |
|
28 | - public function upgrade_db( $upgrade_from ) { |
|
29 | - |
|
30 | - // Save the current invoicing version. |
|
31 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | - |
|
33 | - // Setup the invoice Custom Post Type. |
|
34 | - GetPaid_Post_Types::register_post_types(); |
|
35 | - |
|
36 | - // Clear the permalinks |
|
37 | - flush_rewrite_rules(); |
|
38 | - |
|
39 | - // Maybe create new/missing pages. |
|
40 | - $this->create_pages(); |
|
41 | - |
|
42 | - // Maybe re(add) admin capabilities. |
|
43 | - $this->add_capabilities(); |
|
44 | - |
|
45 | - // Maybe create the default payment form. |
|
46 | - wpinv_get_default_payment_form(); |
|
47 | - |
|
48 | - // Create any missing database tables. |
|
49 | - $method = "upgrade_from_$upgrade_from"; |
|
50 | - |
|
51 | - if ( method_exists( $this, $method ) ) { |
|
52 | - $this->$method(); |
|
53 | - } |
|
54 | - |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Do a fresh install. |
|
59 | - * |
|
60 | - */ |
|
61 | - public function upgrade_from_0() { |
|
62 | - $this->create_subscriptions_table(); |
|
63 | - $this->create_invoices_table(); |
|
64 | - $this->create_invoice_items_table(); |
|
65 | - |
|
66 | - // Save default tax rates. |
|
67 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Upgrade to 0.0.5 |
|
72 | - * |
|
73 | - */ |
|
74 | - public function upgrade_from_004() { |
|
75 | - global $wpdb; |
|
76 | - |
|
77 | - // Invoices. |
|
78 | - $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' )" ); |
|
79 | - if ( ! empty( $results ) ) { |
|
80 | - $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' )" ); |
|
81 | - |
|
82 | - // Clean post cache |
|
83 | - foreach ( $results as $row ) { |
|
84 | - clean_post_cache( $row->ID ); |
|
85 | - } |
|
86 | - |
|
87 | - } |
|
88 | - |
|
89 | - // Item meta key changes |
|
90 | - $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' )"; |
|
91 | - $results = $wpdb->get_results( $query ); |
|
92 | - |
|
93 | - if ( ! empty( $results ) ) { |
|
94 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
95 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
96 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
97 | - |
|
98 | - foreach ( $results as $row ) { |
|
99 | - clean_post_cache( $row->post_id ); |
|
100 | - } |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - $this->upgrade_from_102(); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Upgrade to 1.0.3 |
|
109 | - * |
|
110 | - */ |
|
111 | - public function upgrade_from_102() { |
|
112 | - $this->create_subscriptions_table(); |
|
113 | - $this->upgrade_from_118(); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Upgrade to version 2.0.0. |
|
118 | - * |
|
119 | - */ |
|
120 | - public function upgrade_from_118() { |
|
121 | - $this->create_invoices_table(); |
|
122 | - $this->create_invoice_items_table(); |
|
123 | - $this->migrate_old_invoices(); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Upgrade to version 2.0.8. |
|
128 | - * |
|
129 | - */ |
|
130 | - public function upgrade_from_207() { |
|
131 | - global $wpdb; |
|
132 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" ); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Give administrators the capability to manage GetPaid. |
|
137 | - * |
|
138 | - */ |
|
139 | - public function add_capabilities() { |
|
140 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Re-create GetPaid pages. |
|
145 | - * |
|
146 | - */ |
|
147 | - public function create_pages() { |
|
148 | - |
|
149 | - $pages = apply_filters( |
|
150 | - 'wpinv_create_pages', |
|
151 | - array( |
|
152 | - |
|
153 | - // Checkout page. |
|
154 | - 'checkout_page' => array( |
|
155 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
156 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
157 | - 'content' => ' |
|
23 | + /** |
|
24 | + * Upgrades the install. |
|
25 | + * |
|
26 | + * @param string $upgrade_from The current invoicing version. |
|
27 | + */ |
|
28 | + public function upgrade_db( $upgrade_from ) { |
|
29 | + |
|
30 | + // Save the current invoicing version. |
|
31 | + update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | + |
|
33 | + // Setup the invoice Custom Post Type. |
|
34 | + GetPaid_Post_Types::register_post_types(); |
|
35 | + |
|
36 | + // Clear the permalinks |
|
37 | + flush_rewrite_rules(); |
|
38 | + |
|
39 | + // Maybe create new/missing pages. |
|
40 | + $this->create_pages(); |
|
41 | + |
|
42 | + // Maybe re(add) admin capabilities. |
|
43 | + $this->add_capabilities(); |
|
44 | + |
|
45 | + // Maybe create the default payment form. |
|
46 | + wpinv_get_default_payment_form(); |
|
47 | + |
|
48 | + // Create any missing database tables. |
|
49 | + $method = "upgrade_from_$upgrade_from"; |
|
50 | + |
|
51 | + if ( method_exists( $this, $method ) ) { |
|
52 | + $this->$method(); |
|
53 | + } |
|
54 | + |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Do a fresh install. |
|
59 | + * |
|
60 | + */ |
|
61 | + public function upgrade_from_0() { |
|
62 | + $this->create_subscriptions_table(); |
|
63 | + $this->create_invoices_table(); |
|
64 | + $this->create_invoice_items_table(); |
|
65 | + |
|
66 | + // Save default tax rates. |
|
67 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Upgrade to 0.0.5 |
|
72 | + * |
|
73 | + */ |
|
74 | + public function upgrade_from_004() { |
|
75 | + global $wpdb; |
|
76 | + |
|
77 | + // Invoices. |
|
78 | + $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' )" ); |
|
79 | + if ( ! empty( $results ) ) { |
|
80 | + $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' )" ); |
|
81 | + |
|
82 | + // Clean post cache |
|
83 | + foreach ( $results as $row ) { |
|
84 | + clean_post_cache( $row->ID ); |
|
85 | + } |
|
86 | + |
|
87 | + } |
|
88 | + |
|
89 | + // Item meta key changes |
|
90 | + $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' )"; |
|
91 | + $results = $wpdb->get_results( $query ); |
|
92 | + |
|
93 | + if ( ! empty( $results ) ) { |
|
94 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
95 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
96 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
97 | + |
|
98 | + foreach ( $results as $row ) { |
|
99 | + clean_post_cache( $row->post_id ); |
|
100 | + } |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + $this->upgrade_from_102(); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Upgrade to 1.0.3 |
|
109 | + * |
|
110 | + */ |
|
111 | + public function upgrade_from_102() { |
|
112 | + $this->create_subscriptions_table(); |
|
113 | + $this->upgrade_from_118(); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Upgrade to version 2.0.0. |
|
118 | + * |
|
119 | + */ |
|
120 | + public function upgrade_from_118() { |
|
121 | + $this->create_invoices_table(); |
|
122 | + $this->create_invoice_items_table(); |
|
123 | + $this->migrate_old_invoices(); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Upgrade to version 2.0.8. |
|
128 | + * |
|
129 | + */ |
|
130 | + public function upgrade_from_207() { |
|
131 | + global $wpdb; |
|
132 | + $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" ); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Give administrators the capability to manage GetPaid. |
|
137 | + * |
|
138 | + */ |
|
139 | + public function add_capabilities() { |
|
140 | + $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Re-create GetPaid pages. |
|
145 | + * |
|
146 | + */ |
|
147 | + public function create_pages() { |
|
148 | + |
|
149 | + $pages = apply_filters( |
|
150 | + 'wpinv_create_pages', |
|
151 | + array( |
|
152 | + |
|
153 | + // Checkout page. |
|
154 | + 'checkout_page' => array( |
|
155 | + 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
156 | + 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
157 | + 'content' => ' |
|
158 | 158 | <!-- wp:shortcode --> |
159 | 159 | [wpinv_checkout] |
160 | 160 | <!-- /wp:shortcode --> |
161 | 161 | ', |
162 | - 'parent' => '', |
|
163 | - ), |
|
164 | - |
|
165 | - // Invoice history page. |
|
166 | - 'invoice_history_page' => array( |
|
167 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
168 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
169 | - 'content' => ' |
|
162 | + 'parent' => '', |
|
163 | + ), |
|
164 | + |
|
165 | + // Invoice history page. |
|
166 | + 'invoice_history_page' => array( |
|
167 | + 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
168 | + 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
169 | + 'content' => ' |
|
170 | 170 | <!-- wp:shortcode --> |
171 | 171 | [wpinv_history] |
172 | 172 | <!-- /wp:shortcode --> |
173 | 173 | ', |
174 | - 'parent' => '', |
|
175 | - ), |
|
176 | - |
|
177 | - // Success page content. |
|
178 | - 'success_page' => array( |
|
179 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
180 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
181 | - 'content' => ' |
|
174 | + 'parent' => '', |
|
175 | + ), |
|
176 | + |
|
177 | + // Success page content. |
|
178 | + 'success_page' => array( |
|
179 | + 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
180 | + 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
181 | + 'content' => ' |
|
182 | 182 | <!-- wp:shortcode --> |
183 | 183 | [wpinv_receipt] |
184 | 184 | <!-- /wp:shortcode --> |
185 | 185 | ', |
186 | - 'parent' => 'gp-checkout', |
|
187 | - ), |
|
188 | - |
|
189 | - // Failure page content. |
|
190 | - 'failure_page' => array( |
|
191 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
192 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
193 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
194 | - 'parent' => 'gp-checkout', |
|
195 | - ), |
|
196 | - |
|
197 | - // Subscriptions history page. |
|
198 | - 'invoice_subscription_page' => array( |
|
199 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
200 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
201 | - 'content' => ' |
|
186 | + 'parent' => 'gp-checkout', |
|
187 | + ), |
|
188 | + |
|
189 | + // Failure page content. |
|
190 | + 'failure_page' => array( |
|
191 | + 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
192 | + 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
193 | + 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
194 | + 'parent' => 'gp-checkout', |
|
195 | + ), |
|
196 | + |
|
197 | + // Subscriptions history page. |
|
198 | + 'invoice_subscription_page' => array( |
|
199 | + 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
200 | + 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
201 | + 'content' => ' |
|
202 | 202 | <!-- wp:shortcode --> |
203 | 203 | [wpinv_subscriptions] |
204 | 204 | <!-- /wp:shortcode --> |
205 | 205 | ', |
206 | - 'parent' => '', |
|
207 | - ), |
|
206 | + 'parent' => '', |
|
207 | + ), |
|
208 | 208 | |
209 | - ) |
|
210 | - ); |
|
209 | + ) |
|
210 | + ); |
|
211 | 211 | |
212 | - foreach ( $pages as $key => $page ) { |
|
213 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
214 | - } |
|
212 | + foreach ( $pages as $key => $page ) { |
|
213 | + wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
214 | + } |
|
215 | 215 | |
216 | - } |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
219 | - * Create subscriptions table. |
|
220 | - * |
|
221 | - */ |
|
222 | - public function create_subscriptions_table() { |
|
218 | + /** |
|
219 | + * Create subscriptions table. |
|
220 | + * |
|
221 | + */ |
|
222 | + public function create_subscriptions_table() { |
|
223 | 223 | |
224 | - global $wpdb; |
|
224 | + global $wpdb; |
|
225 | 225 | |
226 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
226 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
227 | 227 | |
228 | - // Create tables. |
|
229 | - $charset_collate = $wpdb->get_charset_collate(); |
|
230 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
228 | + // Create tables. |
|
229 | + $charset_collate = $wpdb->get_charset_collate(); |
|
230 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
231 | 231 | id bigint(20) unsigned NOT NULL auto_increment, |
232 | 232 | customer_id bigint(20) NOT NULL, |
233 | 233 | frequency int(11) NOT NULL DEFAULT '1', |
@@ -250,22 +250,22 @@ discard block |
||
250 | 250 | KEY customer_and_status (customer_id, status) |
251 | 251 | ) $charset_collate;"; |
252 | 252 | |
253 | - dbDelta( $sql ); |
|
253 | + dbDelta( $sql ); |
|
254 | 254 | |
255 | - } |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
258 | - * Create invoices table. |
|
259 | - * |
|
260 | - */ |
|
261 | - public function create_invoices_table() { |
|
262 | - global $wpdb; |
|
257 | + /** |
|
258 | + * Create invoices table. |
|
259 | + * |
|
260 | + */ |
|
261 | + public function create_invoices_table() { |
|
262 | + global $wpdb; |
|
263 | 263 | |
264 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
264 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
265 | 265 | |
266 | - // Create tables. |
|
267 | - $charset_collate = $wpdb->get_charset_collate(); |
|
268 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
266 | + // Create tables. |
|
267 | + $charset_collate = $wpdb->get_charset_collate(); |
|
268 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
269 | 269 | post_id BIGINT(20) NOT NULL, |
270 | 270 | `number` VARCHAR(100), |
271 | 271 | `key` VARCHAR(100), |
@@ -301,22 +301,22 @@ discard block |
||
301 | 301 | KEY `key` (`key`) |
302 | 302 | ) $charset_collate;"; |
303 | 303 | |
304 | - dbDelta( $sql ); |
|
304 | + dbDelta( $sql ); |
|
305 | 305 | |
306 | - } |
|
306 | + } |
|
307 | 307 | |
308 | - /** |
|
309 | - * Create invoice items table. |
|
310 | - * |
|
311 | - */ |
|
312 | - public function create_invoice_items_table() { |
|
313 | - global $wpdb; |
|
308 | + /** |
|
309 | + * Create invoice items table. |
|
310 | + * |
|
311 | + */ |
|
312 | + public function create_invoice_items_table() { |
|
313 | + global $wpdb; |
|
314 | 314 | |
315 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
315 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
316 | 316 | |
317 | - // Create tables. |
|
318 | - $charset_collate = $wpdb->get_charset_collate(); |
|
319 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
317 | + // Create tables. |
|
318 | + $charset_collate = $wpdb->get_charset_collate(); |
|
319 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
320 | 320 | ID BIGINT(20) NOT NULL AUTO_INCREMENT, |
321 | 321 | post_id BIGINT(20) NOT NULL, |
322 | 322 | item_id BIGINT(20) NOT NULL, |
@@ -338,159 +338,159 @@ discard block |
||
338 | 338 | KEY post_id (post_id) |
339 | 339 | ) $charset_collate;"; |
340 | 340 | |
341 | - dbDelta( $sql ); |
|
342 | - |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Migrates old invoices to new invoices. |
|
347 | - * |
|
348 | - */ |
|
349 | - public function migrate_old_invoices() { |
|
350 | - global $wpdb; |
|
351 | - |
|
352 | - $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
353 | - $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
354 | - $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
355 | - $invoices = array_unique( |
|
356 | - get_posts( |
|
357 | - array( |
|
358 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
359 | - 'posts_per_page' => -1, |
|
360 | - 'fields' => 'ids', |
|
361 | - 'post_status' => array_keys( get_post_stati() ), |
|
362 | - 'exclude' => (array) $migrated, |
|
363 | - ) |
|
364 | - ) |
|
365 | - ); |
|
366 | - |
|
367 | - // Abort if we do not have any invoices. |
|
368 | - if ( empty( $invoices ) ) { |
|
369 | - return; |
|
370 | - } |
|
371 | - |
|
372 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
373 | - |
|
374 | - $invoice_rows = array(); |
|
375 | - foreach ( $invoices as $invoice ) { |
|
376 | - |
|
377 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
378 | - |
|
379 | - if ( empty( $invoice->ID ) ) { |
|
380 | - return; |
|
381 | - } |
|
382 | - |
|
383 | - $fields = array ( |
|
384 | - 'post_id' => $invoice->ID, |
|
385 | - 'number' => $invoice->get_number(), |
|
386 | - 'key' => $invoice->get_key(), |
|
387 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
388 | - 'mode' => $invoice->mode, |
|
389 | - 'user_ip' => $invoice->get_ip(), |
|
390 | - 'first_name' => $invoice->get_first_name(), |
|
391 | - 'last_name' => $invoice->get_last_name(), |
|
392 | - 'address' => $invoice->get_address(), |
|
393 | - 'city' => $invoice->city, |
|
394 | - 'state' => $invoice->state, |
|
395 | - 'country' => $invoice->country, |
|
396 | - 'zip' => $invoice->zip, |
|
397 | - 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
398 | - 'gateway' => $invoice->get_gateway(), |
|
399 | - 'transaction_id' => $invoice->get_transaction_id(), |
|
400 | - 'currency' => $invoice->get_currency(), |
|
401 | - 'subtotal' => $invoice->get_subtotal(), |
|
402 | - 'tax' => $invoice->get_tax(), |
|
403 | - 'fees_total' => $invoice->get_fees_total(), |
|
404 | - 'total' => $invoice->get_total(), |
|
405 | - 'discount' => $invoice->get_discount(), |
|
406 | - 'discount_code' => $invoice->get_discount_code(), |
|
407 | - 'disable_taxes' => $invoice->disable_taxes, |
|
408 | - 'due_date' => $invoice->get_due_date(), |
|
409 | - 'completed_date' => $invoice->get_completed_date(), |
|
410 | - 'company' => $invoice->company, |
|
411 | - 'vat_number' => $invoice->vat_number, |
|
412 | - 'vat_rate' => $invoice->vat_rate, |
|
413 | - 'custom_meta' => $invoice->payment_meta |
|
414 | - ); |
|
415 | - |
|
416 | - foreach ( $fields as $key => $val ) { |
|
417 | - if ( is_null( $val ) ) { |
|
418 | - $val = ''; |
|
419 | - } |
|
420 | - $val = maybe_serialize( $val ); |
|
421 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
422 | - } |
|
423 | - |
|
424 | - $fields = implode( ', ', $fields ); |
|
425 | - $invoice_rows[] = "($fields)"; |
|
426 | - |
|
427 | - $item_rows = array(); |
|
428 | - $item_columns = array(); |
|
429 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
430 | - $fields = array( |
|
431 | - 'post_id' => $invoice->ID, |
|
432 | - 'item_id' => $details['id'], |
|
433 | - 'item_name' => $details['name'], |
|
434 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
435 | - 'vat_rate' => $details['vat_rate'], |
|
436 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
437 | - 'tax' => $details['tax'], |
|
438 | - 'item_price' => $details['item_price'], |
|
439 | - 'custom_price' => $details['custom_price'], |
|
440 | - 'quantity' => $details['quantity'], |
|
441 | - 'discount' => $details['discount'], |
|
442 | - 'subtotal' => $details['subtotal'], |
|
443 | - 'price' => $details['price'], |
|
444 | - 'meta' => $details['meta'], |
|
445 | - 'fees' => $details['fees'], |
|
446 | - ); |
|
447 | - |
|
448 | - $item_columns = array_keys ( $fields ); |
|
449 | - |
|
450 | - foreach ( $fields as $key => $val ) { |
|
451 | - if ( is_null( $val ) ) { |
|
452 | - $val = ''; |
|
453 | - } |
|
454 | - $val = maybe_serialize( $val ); |
|
455 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
456 | - } |
|
457 | - |
|
458 | - $fields = implode( ', ', $fields ); |
|
459 | - $item_rows[] = "($fields)"; |
|
460 | - } |
|
461 | - |
|
462 | - $item_rows = implode( ', ', $item_rows ); |
|
463 | - $item_columns = implode( ', ', $item_columns ); |
|
464 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
465 | - } |
|
466 | - |
|
467 | - if ( empty( $invoice_rows ) ) { |
|
468 | - return; |
|
469 | - } |
|
470 | - |
|
471 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
472 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
473 | - |
|
474 | - } |
|
475 | - |
|
476 | - /** |
|
477 | - * Migrates old invoices to new invoices. |
|
478 | - * |
|
479 | - */ |
|
480 | - public static function rename_gateways_label() { |
|
481 | - global $wpdb; |
|
482 | - |
|
483 | - foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
484 | - |
|
485 | - $wpdb->update( |
|
486 | - $wpdb->prefix . 'getpaid_invoices', |
|
487 | - array( 'gateway' => $gateway ), |
|
488 | - array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
489 | - '%s', |
|
490 | - '%s' |
|
491 | - ); |
|
492 | - |
|
493 | - } |
|
494 | - } |
|
341 | + dbDelta( $sql ); |
|
342 | + |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Migrates old invoices to new invoices. |
|
347 | + * |
|
348 | + */ |
|
349 | + public function migrate_old_invoices() { |
|
350 | + global $wpdb; |
|
351 | + |
|
352 | + $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
353 | + $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
354 | + $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
355 | + $invoices = array_unique( |
|
356 | + get_posts( |
|
357 | + array( |
|
358 | + 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
359 | + 'posts_per_page' => -1, |
|
360 | + 'fields' => 'ids', |
|
361 | + 'post_status' => array_keys( get_post_stati() ), |
|
362 | + 'exclude' => (array) $migrated, |
|
363 | + ) |
|
364 | + ) |
|
365 | + ); |
|
366 | + |
|
367 | + // Abort if we do not have any invoices. |
|
368 | + if ( empty( $invoices ) ) { |
|
369 | + return; |
|
370 | + } |
|
371 | + |
|
372 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
373 | + |
|
374 | + $invoice_rows = array(); |
|
375 | + foreach ( $invoices as $invoice ) { |
|
376 | + |
|
377 | + $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
378 | + |
|
379 | + if ( empty( $invoice->ID ) ) { |
|
380 | + return; |
|
381 | + } |
|
382 | + |
|
383 | + $fields = array ( |
|
384 | + 'post_id' => $invoice->ID, |
|
385 | + 'number' => $invoice->get_number(), |
|
386 | + 'key' => $invoice->get_key(), |
|
387 | + 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
388 | + 'mode' => $invoice->mode, |
|
389 | + 'user_ip' => $invoice->get_ip(), |
|
390 | + 'first_name' => $invoice->get_first_name(), |
|
391 | + 'last_name' => $invoice->get_last_name(), |
|
392 | + 'address' => $invoice->get_address(), |
|
393 | + 'city' => $invoice->city, |
|
394 | + 'state' => $invoice->state, |
|
395 | + 'country' => $invoice->country, |
|
396 | + 'zip' => $invoice->zip, |
|
397 | + 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
398 | + 'gateway' => $invoice->get_gateway(), |
|
399 | + 'transaction_id' => $invoice->get_transaction_id(), |
|
400 | + 'currency' => $invoice->get_currency(), |
|
401 | + 'subtotal' => $invoice->get_subtotal(), |
|
402 | + 'tax' => $invoice->get_tax(), |
|
403 | + 'fees_total' => $invoice->get_fees_total(), |
|
404 | + 'total' => $invoice->get_total(), |
|
405 | + 'discount' => $invoice->get_discount(), |
|
406 | + 'discount_code' => $invoice->get_discount_code(), |
|
407 | + 'disable_taxes' => $invoice->disable_taxes, |
|
408 | + 'due_date' => $invoice->get_due_date(), |
|
409 | + 'completed_date' => $invoice->get_completed_date(), |
|
410 | + 'company' => $invoice->company, |
|
411 | + 'vat_number' => $invoice->vat_number, |
|
412 | + 'vat_rate' => $invoice->vat_rate, |
|
413 | + 'custom_meta' => $invoice->payment_meta |
|
414 | + ); |
|
415 | + |
|
416 | + foreach ( $fields as $key => $val ) { |
|
417 | + if ( is_null( $val ) ) { |
|
418 | + $val = ''; |
|
419 | + } |
|
420 | + $val = maybe_serialize( $val ); |
|
421 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
422 | + } |
|
423 | + |
|
424 | + $fields = implode( ', ', $fields ); |
|
425 | + $invoice_rows[] = "($fields)"; |
|
426 | + |
|
427 | + $item_rows = array(); |
|
428 | + $item_columns = array(); |
|
429 | + foreach ( $invoice->get_cart_details() as $details ) { |
|
430 | + $fields = array( |
|
431 | + 'post_id' => $invoice->ID, |
|
432 | + 'item_id' => $details['id'], |
|
433 | + 'item_name' => $details['name'], |
|
434 | + 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
435 | + 'vat_rate' => $details['vat_rate'], |
|
436 | + 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
437 | + 'tax' => $details['tax'], |
|
438 | + 'item_price' => $details['item_price'], |
|
439 | + 'custom_price' => $details['custom_price'], |
|
440 | + 'quantity' => $details['quantity'], |
|
441 | + 'discount' => $details['discount'], |
|
442 | + 'subtotal' => $details['subtotal'], |
|
443 | + 'price' => $details['price'], |
|
444 | + 'meta' => $details['meta'], |
|
445 | + 'fees' => $details['fees'], |
|
446 | + ); |
|
447 | + |
|
448 | + $item_columns = array_keys ( $fields ); |
|
449 | + |
|
450 | + foreach ( $fields as $key => $val ) { |
|
451 | + if ( is_null( $val ) ) { |
|
452 | + $val = ''; |
|
453 | + } |
|
454 | + $val = maybe_serialize( $val ); |
|
455 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
456 | + } |
|
457 | + |
|
458 | + $fields = implode( ', ', $fields ); |
|
459 | + $item_rows[] = "($fields)"; |
|
460 | + } |
|
461 | + |
|
462 | + $item_rows = implode( ', ', $item_rows ); |
|
463 | + $item_columns = implode( ', ', $item_columns ); |
|
464 | + $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
465 | + } |
|
466 | + |
|
467 | + if ( empty( $invoice_rows ) ) { |
|
468 | + return; |
|
469 | + } |
|
470 | + |
|
471 | + $invoice_rows = implode( ', ', $invoice_rows ); |
|
472 | + $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
473 | + |
|
474 | + } |
|
475 | + |
|
476 | + /** |
|
477 | + * Migrates old invoices to new invoices. |
|
478 | + * |
|
479 | + */ |
|
480 | + public static function rename_gateways_label() { |
|
481 | + global $wpdb; |
|
482 | + |
|
483 | + foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
484 | + |
|
485 | + $wpdb->update( |
|
486 | + $wpdb->prefix . 'getpaid_invoices', |
|
487 | + array( 'gateway' => $gateway ), |
|
488 | + array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
489 | + '%s', |
|
490 | + '%s' |
|
491 | + ); |
|
492 | + |
|
493 | + } |
|
494 | + } |
|
495 | 495 | |
496 | 496 | } |
@@ -14,543 +14,543 @@ |
||
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 | - * @param 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 | - |
|
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
73 | - } |
|
74 | - |
|
75 | - return null; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Define class properties. |
|
80 | - */ |
|
81 | - public function set_properties() { |
|
82 | - |
|
83 | - // Sessions. |
|
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | - |
|
88 | - // Init other objects. |
|
89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
91 | - $this->set( 'api', new WPInv_API() ); |
|
92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | - $this->set( 'template', new GetPaid_Template() ); |
|
94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Define plugin constants. |
|
106 | - */ |
|
107 | - public function define_constants() { |
|
108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
110 | - $this->version = WPINV_VERSION; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Hook into actions and filters. |
|
115 | - * |
|
116 | - * @since 1.0.19 |
|
117 | - */ |
|
118 | - protected function init_hooks() { |
|
119 | - /* Internationalize the text strings used. */ |
|
120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
121 | - |
|
122 | - // Init the plugin after WordPress inits. |
|
123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
128 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
129 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
130 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
131 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
132 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
133 | - |
|
134 | - // Fires after registering actions. |
|
135 | - do_action( 'wpinv_actions', $this ); |
|
136 | - do_action( 'getpaid_actions', $this ); |
|
137 | - |
|
138 | - } |
|
139 | - |
|
140 | - public function plugins_loaded() { |
|
141 | - /* Internationalize the text strings used. */ |
|
142 | - $this->load_textdomain(); |
|
143 | - |
|
144 | - do_action( 'wpinv_loaded' ); |
|
145 | - |
|
146 | - // Fix oxygen page builder conflict |
|
147 | - if ( function_exists( 'ct_css_output' ) ) { |
|
148 | - wpinv_oxygen_fix_conflict(); |
|
149 | - } |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Load the translation of the plugin. |
|
154 | - * |
|
155 | - * @since 1.0 |
|
156 | - */ |
|
157 | - public function load_textdomain( $locale = NULL ) { |
|
158 | - if ( empty( $locale ) ) { |
|
159 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
160 | - } |
|
161 | - |
|
162 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
163 | - |
|
164 | - unload_textdomain( 'invoicing' ); |
|
165 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
166 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
167 | - |
|
168 | - /** |
|
169 | - * Define language constants. |
|
170 | - */ |
|
171 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Include required core files used in admin and on the frontend. |
|
176 | - */ |
|
177 | - public function includes() { |
|
178 | - |
|
179 | - // Start with the settings. |
|
180 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
181 | - |
|
182 | - // Packages/libraries. |
|
183 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
184 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
185 | - |
|
186 | - // Load functions. |
|
187 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
188 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
189 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
190 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
191 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
192 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
199 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
202 | - |
|
203 | - // Register autoloader. |
|
204 | - try { |
|
205 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
206 | - } catch ( Exception $e ) { |
|
207 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
208 | - } |
|
209 | - |
|
210 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
211 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
212 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
213 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
215 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
216 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
217 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
218 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
219 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
220 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
221 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
231 | - |
|
232 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
233 | - GetPaid_Post_Types_Admin::init(); |
|
234 | - |
|
235 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
236 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
237 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
238 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
241 | - // load the user class only on the users.php page |
|
242 | - global $pagenow; |
|
243 | - if($pagenow=='users.php'){ |
|
244 | - new WPInv_Admin_Users(); |
|
245 | - } |
|
246 | - } |
|
247 | - |
|
248 | - // Register cli commands |
|
249 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
250 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
251 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
252 | - } |
|
253 | - |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * Class autoloader |
|
258 | - * |
|
259 | - * @param string $class_name The name of the class to load. |
|
260 | - * @access public |
|
261 | - * @since 1.0.19 |
|
262 | - * @return void |
|
263 | - */ |
|
264 | - public function autoload( $class_name ) { |
|
265 | - |
|
266 | - // Normalize the class name... |
|
267 | - $class_name = strtolower( $class_name ); |
|
268 | - |
|
269 | - // ... and make sure it is our class. |
|
270 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
271 | - return; |
|
272 | - } |
|
273 | - |
|
274 | - // Next, prepare the file name from the class. |
|
275 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
276 | - |
|
277 | - // Base path of the classes. |
|
278 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
279 | - |
|
280 | - // And an array of possible locations in order of importance. |
|
281 | - $locations = array( |
|
282 | - "$plugin_path/includes", |
|
283 | - "$plugin_path/includes/data-stores", |
|
284 | - "$plugin_path/includes/gateways", |
|
285 | - "$plugin_path/includes/payments", |
|
286 | - "$plugin_path/includes/geolocation", |
|
287 | - "$plugin_path/includes/reports", |
|
288 | - "$plugin_path/includes/api", |
|
289 | - "$plugin_path/includes/admin", |
|
290 | - "$plugin_path/includes/admin/meta-boxes", |
|
291 | - ); |
|
292 | - |
|
293 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
294 | - |
|
295 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
296 | - include trailingslashit( $location ) . $file_name; |
|
297 | - break; |
|
298 | - } |
|
299 | - |
|
300 | - } |
|
301 | - |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Inits hooks etc. |
|
306 | - */ |
|
307 | - public function init() { |
|
308 | - |
|
309 | - // Fires before getpaid inits. |
|
310 | - do_action( 'before_getpaid_init', $this ); |
|
311 | - |
|
312 | - // Maybe upgrade. |
|
313 | - $this->maybe_upgrade_database(); |
|
314 | - |
|
315 | - // Load default gateways. |
|
316 | - $gateways = apply_filters( |
|
317 | - 'getpaid_default_gateways', |
|
318 | - array( |
|
319 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
320 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
321 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
322 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
323 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
324 | - ) |
|
325 | - ); |
|
326 | - |
|
327 | - foreach ( $gateways as $id => $class ) { |
|
328 | - $this->gateways[ $id ] = new $class(); |
|
329 | - } |
|
330 | - |
|
331 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
332 | - GetPaid_Installer::rename_gateways_label(); |
|
333 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
334 | - } |
|
335 | - |
|
336 | - // Fires after getpaid inits. |
|
337 | - do_action( 'getpaid_init', $this ); |
|
338 | - |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Checks if this is an IPN request and processes it. |
|
343 | - */ |
|
344 | - public function maybe_process_ipn() { |
|
345 | - |
|
346 | - // Ensure that this is an IPN request. |
|
347 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
348 | - return; |
|
349 | - } |
|
350 | - |
|
351 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
352 | - |
|
353 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
354 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
355 | - exit; |
|
356 | - |
|
357 | - } |
|
358 | - |
|
359 | - public function enqueue_scripts() { |
|
360 | - |
|
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['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
367 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
368 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
369 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
370 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
371 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
372 | - |
|
373 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
374 | - |
|
375 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
376 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
377 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
378 | - } |
|
379 | - |
|
380 | - public function wpinv_actions() { |
|
381 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
382 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
383 | - } |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
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 | + * @param 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 | + |
|
71 | + if ( isset( $this->data[ $prop ] ) ) { |
|
72 | + return $this->data[ $prop ]; |
|
73 | + } |
|
74 | + |
|
75 | + return null; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Define class properties. |
|
80 | + */ |
|
81 | + public function set_properties() { |
|
82 | + |
|
83 | + // Sessions. |
|
84 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | + |
|
88 | + // Init other objects. |
|
89 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | + $this->set( 'notes', new WPInv_Notes() ); |
|
91 | + $this->set( 'api', new WPInv_API() ); |
|
92 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | + $this->set( 'template', new GetPaid_Template() ); |
|
94 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Define plugin constants. |
|
106 | + */ |
|
107 | + public function define_constants() { |
|
108 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
110 | + $this->version = WPINV_VERSION; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Hook into actions and filters. |
|
115 | + * |
|
116 | + * @since 1.0.19 |
|
117 | + */ |
|
118 | + protected function init_hooks() { |
|
119 | + /* Internationalize the text strings used. */ |
|
120 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
121 | + |
|
122 | + // Init the plugin after WordPress inits. |
|
123 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
128 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
129 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
130 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
131 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
132 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
133 | + |
|
134 | + // Fires after registering actions. |
|
135 | + do_action( 'wpinv_actions', $this ); |
|
136 | + do_action( 'getpaid_actions', $this ); |
|
137 | + |
|
138 | + } |
|
139 | + |
|
140 | + public function plugins_loaded() { |
|
141 | + /* Internationalize the text strings used. */ |
|
142 | + $this->load_textdomain(); |
|
143 | + |
|
144 | + do_action( 'wpinv_loaded' ); |
|
145 | + |
|
146 | + // Fix oxygen page builder conflict |
|
147 | + if ( function_exists( 'ct_css_output' ) ) { |
|
148 | + wpinv_oxygen_fix_conflict(); |
|
149 | + } |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Load the translation of the plugin. |
|
154 | + * |
|
155 | + * @since 1.0 |
|
156 | + */ |
|
157 | + public function load_textdomain( $locale = NULL ) { |
|
158 | + if ( empty( $locale ) ) { |
|
159 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
160 | + } |
|
161 | + |
|
162 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
163 | + |
|
164 | + unload_textdomain( 'invoicing' ); |
|
165 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
166 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
167 | + |
|
168 | + /** |
|
169 | + * Define language constants. |
|
170 | + */ |
|
171 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Include required core files used in admin and on the frontend. |
|
176 | + */ |
|
177 | + public function includes() { |
|
178 | + |
|
179 | + // Start with the settings. |
|
180 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
181 | + |
|
182 | + // Packages/libraries. |
|
183 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
184 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
185 | + |
|
186 | + // Load functions. |
|
187 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
188 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
189 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
190 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
191 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
192 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
193 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
194 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
195 | + require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
196 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
197 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
198 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
199 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
200 | + require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
201 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
202 | + |
|
203 | + // Register autoloader. |
|
204 | + try { |
|
205 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
206 | + } catch ( Exception $e ) { |
|
207 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
208 | + } |
|
209 | + |
|
210 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
211 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
212 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
213 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
214 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
215 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
216 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
217 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
218 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
219 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
220 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
221 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
222 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
223 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
224 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
225 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
226 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
227 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
228 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
229 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
230 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
231 | + |
|
232 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
233 | + GetPaid_Post_Types_Admin::init(); |
|
234 | + |
|
235 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
236 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
237 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
238 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
239 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
240 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
241 | + // load the user class only on the users.php page |
|
242 | + global $pagenow; |
|
243 | + if($pagenow=='users.php'){ |
|
244 | + new WPInv_Admin_Users(); |
|
245 | + } |
|
246 | + } |
|
247 | + |
|
248 | + // Register cli commands |
|
249 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
250 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
251 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
252 | + } |
|
253 | + |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * Class autoloader |
|
258 | + * |
|
259 | + * @param string $class_name The name of the class to load. |
|
260 | + * @access public |
|
261 | + * @since 1.0.19 |
|
262 | + * @return void |
|
263 | + */ |
|
264 | + public function autoload( $class_name ) { |
|
265 | + |
|
266 | + // Normalize the class name... |
|
267 | + $class_name = strtolower( $class_name ); |
|
268 | + |
|
269 | + // ... and make sure it is our class. |
|
270 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
271 | + return; |
|
272 | + } |
|
273 | + |
|
274 | + // Next, prepare the file name from the class. |
|
275 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
276 | + |
|
277 | + // Base path of the classes. |
|
278 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
279 | + |
|
280 | + // And an array of possible locations in order of importance. |
|
281 | + $locations = array( |
|
282 | + "$plugin_path/includes", |
|
283 | + "$plugin_path/includes/data-stores", |
|
284 | + "$plugin_path/includes/gateways", |
|
285 | + "$plugin_path/includes/payments", |
|
286 | + "$plugin_path/includes/geolocation", |
|
287 | + "$plugin_path/includes/reports", |
|
288 | + "$plugin_path/includes/api", |
|
289 | + "$plugin_path/includes/admin", |
|
290 | + "$plugin_path/includes/admin/meta-boxes", |
|
291 | + ); |
|
292 | + |
|
293 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
294 | + |
|
295 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
296 | + include trailingslashit( $location ) . $file_name; |
|
297 | + break; |
|
298 | + } |
|
299 | + |
|
300 | + } |
|
301 | + |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Inits hooks etc. |
|
306 | + */ |
|
307 | + public function init() { |
|
308 | + |
|
309 | + // Fires before getpaid inits. |
|
310 | + do_action( 'before_getpaid_init', $this ); |
|
311 | + |
|
312 | + // Maybe upgrade. |
|
313 | + $this->maybe_upgrade_database(); |
|
314 | + |
|
315 | + // Load default gateways. |
|
316 | + $gateways = apply_filters( |
|
317 | + 'getpaid_default_gateways', |
|
318 | + array( |
|
319 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
320 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
321 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
322 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
323 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
324 | + ) |
|
325 | + ); |
|
326 | + |
|
327 | + foreach ( $gateways as $id => $class ) { |
|
328 | + $this->gateways[ $id ] = new $class(); |
|
329 | + } |
|
330 | + |
|
331 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
332 | + GetPaid_Installer::rename_gateways_label(); |
|
333 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
334 | + } |
|
335 | + |
|
336 | + // Fires after getpaid inits. |
|
337 | + do_action( 'getpaid_init', $this ); |
|
338 | + |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Checks if this is an IPN request and processes it. |
|
343 | + */ |
|
344 | + public function maybe_process_ipn() { |
|
345 | + |
|
346 | + // Ensure that this is an IPN request. |
|
347 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
348 | + return; |
|
349 | + } |
|
350 | + |
|
351 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
352 | + |
|
353 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
354 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
355 | + exit; |
|
356 | + |
|
357 | + } |
|
358 | + |
|
359 | + public function enqueue_scripts() { |
|
360 | + |
|
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['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
367 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
368 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
369 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
370 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
371 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
372 | + |
|
373 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
374 | + |
|
375 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
376 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
377 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
378 | + } |
|
379 | + |
|
380 | + public function wpinv_actions() { |
|
381 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
382 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
383 | + } |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | 387 | * Fires an action after verifying that a user can fire them. |
388 | - * |
|
389 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
390 | - * current user owns the invoice/subscription. |
|
388 | + * |
|
389 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
390 | + * current user owns the invoice/subscription. |
|
391 | 391 | */ |
392 | 392 | public function maybe_do_authenticated_action() { |
393 | 393 | |
394 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
394 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
395 | 395 | |
396 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
397 | - $data = wp_unslash( $_REQUEST ); |
|
398 | - if ( is_user_logged_in() ) { |
|
399 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
400 | - } |
|
396 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
397 | + $data = wp_unslash( $_REQUEST ); |
|
398 | + if ( is_user_logged_in() ) { |
|
399 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
400 | + } |
|
401 | 401 | |
402 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
402 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
403 | 403 | |
404 | - } |
|
404 | + } |
|
405 | 405 | |
406 | 406 | } |
407 | 407 | |
408 | - public function pre_get_posts( $wp_query ) { |
|
409 | - |
|
410 | - 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() ) { |
|
411 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
412 | - } |
|
413 | - |
|
414 | - return $wp_query; |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * Register widgets |
|
419 | - * |
|
420 | - */ |
|
421 | - public function register_widgets() { |
|
422 | - |
|
423 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
424 | - // So we disable our widgets when editing a page with UX Builder. |
|
425 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
426 | - return; |
|
427 | - } |
|
428 | - |
|
429 | - $widgets = apply_filters( |
|
430 | - 'getpaid_widget_classes', |
|
431 | - array( |
|
432 | - 'WPInv_Checkout_Widget', |
|
433 | - 'WPInv_History_Widget', |
|
434 | - 'WPInv_Receipt_Widget', |
|
435 | - 'WPInv_Subscriptions_Widget', |
|
436 | - 'WPInv_Buy_Item_Widget', |
|
437 | - 'WPInv_Messages_Widget', |
|
438 | - 'WPInv_GetPaid_Widget' |
|
439 | - ) |
|
440 | - ); |
|
441 | - |
|
442 | - foreach ( $widgets as $widget ) { |
|
443 | - register_widget( $widget ); |
|
444 | - } |
|
408 | + public function pre_get_posts( $wp_query ) { |
|
409 | + |
|
410 | + 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() ) { |
|
411 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
412 | + } |
|
413 | + |
|
414 | + return $wp_query; |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * Register widgets |
|
419 | + * |
|
420 | + */ |
|
421 | + public function register_widgets() { |
|
422 | + |
|
423 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
424 | + // So we disable our widgets when editing a page with UX Builder. |
|
425 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
426 | + return; |
|
427 | + } |
|
428 | + |
|
429 | + $widgets = apply_filters( |
|
430 | + 'getpaid_widget_classes', |
|
431 | + array( |
|
432 | + 'WPInv_Checkout_Widget', |
|
433 | + 'WPInv_History_Widget', |
|
434 | + 'WPInv_Receipt_Widget', |
|
435 | + 'WPInv_Subscriptions_Widget', |
|
436 | + 'WPInv_Buy_Item_Widget', |
|
437 | + 'WPInv_Messages_Widget', |
|
438 | + 'WPInv_GetPaid_Widget' |
|
439 | + ) |
|
440 | + ); |
|
441 | + |
|
442 | + foreach ( $widgets as $widget ) { |
|
443 | + register_widget( $widget ); |
|
444 | + } |
|
445 | 445 | |
446 | - } |
|
446 | + } |
|
447 | 447 | |
448 | - /** |
|
449 | - * Upgrades the database. |
|
450 | - * |
|
451 | - * @since 2.0.2 |
|
452 | - */ |
|
453 | - public function maybe_upgrade_database() { |
|
448 | + /** |
|
449 | + * Upgrades the database. |
|
450 | + * |
|
451 | + * @since 2.0.2 |
|
452 | + */ |
|
453 | + public function maybe_upgrade_database() { |
|
454 | 454 | |
455 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
455 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
456 | 456 | |
457 | - if ( $wpi_version == WPINV_VERSION ) { |
|
458 | - return; |
|
459 | - } |
|
457 | + if ( $wpi_version == WPINV_VERSION ) { |
|
458 | + return; |
|
459 | + } |
|
460 | 460 | |
461 | - $installer = new GetPaid_Installer(); |
|
461 | + $installer = new GetPaid_Installer(); |
|
462 | 462 | |
463 | - if ( empty( $wpi_version ) ) { |
|
464 | - return $installer->upgrade_db( 0 ); |
|
465 | - } |
|
463 | + if ( empty( $wpi_version ) ) { |
|
464 | + return $installer->upgrade_db( 0 ); |
|
465 | + } |
|
466 | 466 | |
467 | - $upgrades = array( |
|
468 | - '0.0.5' => '004', |
|
469 | - '1.0.3' => '102', |
|
470 | - '2.0.0' => '118', |
|
471 | - '2.0.8' => '207', |
|
472 | - ); |
|
467 | + $upgrades = array( |
|
468 | + '0.0.5' => '004', |
|
469 | + '1.0.3' => '102', |
|
470 | + '2.0.0' => '118', |
|
471 | + '2.0.8' => '207', |
|
472 | + ); |
|
473 | 473 | |
474 | - foreach ( $upgrades as $key => $method ) { |
|
474 | + foreach ( $upgrades as $key => $method ) { |
|
475 | 475 | |
476 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
477 | - return $installer->upgrade_db( $method ); |
|
478 | - } |
|
476 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
477 | + return $installer->upgrade_db( $method ); |
|
478 | + } |
|
479 | 479 | |
480 | - } |
|
480 | + } |
|
481 | 481 | |
482 | - } |
|
482 | + } |
|
483 | 483 | |
484 | - /** |
|
485 | - * Flushes the permalinks if needed. |
|
486 | - * |
|
487 | - * @since 2.0.8 |
|
488 | - */ |
|
489 | - public function maybe_flush_permalinks() { |
|
484 | + /** |
|
485 | + * Flushes the permalinks if needed. |
|
486 | + * |
|
487 | + * @since 2.0.8 |
|
488 | + */ |
|
489 | + public function maybe_flush_permalinks() { |
|
490 | 490 | |
491 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
491 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
492 | 492 | |
493 | - if ( ! empty( $flush ) ) { |
|
494 | - flush_rewrite_rules(); |
|
495 | - delete_option( 'wpinv_flush_permalinks' ); |
|
496 | - } |
|
493 | + if ( ! empty( $flush ) ) { |
|
494 | + flush_rewrite_rules(); |
|
495 | + delete_option( 'wpinv_flush_permalinks' ); |
|
496 | + } |
|
497 | 497 | |
498 | - } |
|
498 | + } |
|
499 | 499 | |
500 | - /** |
|
501 | - * Remove our pages from yoast sitemaps. |
|
502 | - * |
|
503 | - * @since 1.0.19 |
|
504 | - * @param int[] $excluded_posts_ids |
|
505 | - */ |
|
506 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
500 | + /** |
|
501 | + * Remove our pages from yoast sitemaps. |
|
502 | + * |
|
503 | + * @since 1.0.19 |
|
504 | + * @param int[] $excluded_posts_ids |
|
505 | + */ |
|
506 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
507 | 507 | |
508 | - // Ensure that we have an array. |
|
509 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
510 | - $excluded_posts_ids = array(); |
|
511 | - } |
|
508 | + // Ensure that we have an array. |
|
509 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
510 | + $excluded_posts_ids = array(); |
|
511 | + } |
|
512 | 512 | |
513 | - // Prepare our pages. |
|
514 | - $our_pages = array(); |
|
513 | + // Prepare our pages. |
|
514 | + $our_pages = array(); |
|
515 | 515 | |
516 | - // Checkout page. |
|
517 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
516 | + // Checkout page. |
|
517 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
518 | 518 | |
519 | - // Success page. |
|
520 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
519 | + // Success page. |
|
520 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
521 | 521 | |
522 | - // Failure page. |
|
523 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
522 | + // Failure page. |
|
523 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
524 | 524 | |
525 | - // History page. |
|
526 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
525 | + // History page. |
|
526 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
527 | 527 | |
528 | - // Subscriptions page. |
|
529 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
528 | + // Subscriptions page. |
|
529 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
530 | 530 | |
531 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
531 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
532 | 532 | |
533 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
534 | - return array_unique( $excluded_posts_ids ); |
|
533 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
534 | + return array_unique( $excluded_posts_ids ); |
|
535 | 535 | |
536 | - } |
|
536 | + } |
|
537 | 537 | |
538 | - /** |
|
539 | - * Displays additional footer code. |
|
540 | - * |
|
541 | - * @since 2.0.0 |
|
542 | - */ |
|
543 | - public function wp_footer() { |
|
544 | - wpinv_get_template( 'frontend-footer.php' ); |
|
545 | - } |
|
538 | + /** |
|
539 | + * Displays additional footer code. |
|
540 | + * |
|
541 | + * @since 2.0.0 |
|
542 | + */ |
|
543 | + public function wp_footer() { |
|
544 | + wpinv_get_template( 'frontend-footer.php' ); |
|
545 | + } |
|
546 | 546 | |
547 | - /** |
|
548 | - * Displays additional header code. |
|
549 | - * |
|
550 | - * @since 2.0.0 |
|
551 | - */ |
|
552 | - public function wp_head() { |
|
553 | - wpinv_get_template( 'frontend-head.php' ); |
|
554 | - } |
|
547 | + /** |
|
548 | + * Displays additional header code. |
|
549 | + * |
|
550 | + * @since 2.0.0 |
|
551 | + */ |
|
552 | + public function wp_head() { |
|
553 | + wpinv_get_template( 'frontend-head.php' ); |
|
554 | + } |
|
555 | 555 | |
556 | 556 | } |