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