@@ -14,619 +14,619 @@ |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var array An array of payment gateways. |
|
40 | - */ |
|
41 | - public $gateways; |
|
42 | - |
|
43 | - /** |
|
44 | - * Class constructor. |
|
45 | - */ |
|
46 | - public function __construct() { |
|
47 | - $this->define_constants(); |
|
48 | - $this->includes(); |
|
49 | - $this->init_hooks(); |
|
50 | - $this->set_properties(); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Sets a custom data property. |
|
55 | - * |
|
56 | - * @param string $prop The prop to set. |
|
57 | - * @param mixed $value The value to retrieve. |
|
58 | - */ |
|
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Gets a custom data property. |
|
65 | - * |
|
66 | - * @param string $prop The prop to set. |
|
67 | - * @return mixed The value. |
|
68 | - */ |
|
69 | - public function get( $prop ) { |
|
70 | - if ( isset( $this->data[ $prop ] ) ) { |
|
71 | - return $this->data[ $prop ]; |
|
72 | - } |
|
73 | - |
|
74 | - return null; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Define class properties. |
|
79 | - */ |
|
80 | - public function set_properties() { |
|
81 | - // Sessions. |
|
82 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
83 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
84 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
85 | - |
|
86 | - // Init other objects. |
|
87 | - $this->set( 'notes', new WPInv_Notes() ); |
|
88 | - $this->set( 'api', new WPInv_API() ); |
|
89 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
90 | - $this->set( 'template', new GetPaid_Template() ); |
|
91 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
92 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
93 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
94 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
95 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
96 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
97 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Define plugin constants. |
|
102 | - */ |
|
103 | - public function define_constants() { |
|
104 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
105 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
106 | - $this->version = WPINV_VERSION; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Hook into actions and filters. |
|
111 | - * |
|
112 | - * @since 1.0.19 |
|
113 | - */ |
|
114 | - protected function init_hooks() { |
|
115 | - /* Internationalize the text strings used. */ |
|
116 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
117 | - |
|
118 | - // Init the plugin after WordPress inits. |
|
119 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
120 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 100 ); |
|
121 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
122 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
123 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
124 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
125 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
126 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
127 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
128 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
129 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
130 | - |
|
131 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
132 | - add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
133 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
134 | - |
|
135 | - // Fires after registering actions. |
|
136 | - do_action( 'wpinv_actions', $this ); |
|
137 | - do_action( 'getpaid_actions', $this ); |
|
138 | - } |
|
139 | - |
|
140 | - public function plugins_loaded() { |
|
141 | - /* Internationalize the text strings used. */ |
|
142 | - $this->load_textdomain(); |
|
143 | - |
|
144 | - do_action( 'wpinv_loaded' ); |
|
145 | - |
|
146 | - // Fix oxygen page builder conflict |
|
147 | - if ( function_exists( 'ct_css_output' ) ) { |
|
148 | - wpinv_oxygen_fix_conflict(); |
|
149 | - } |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Load Localisation files. |
|
154 | - * |
|
155 | - * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
156 | - * |
|
157 | - * Locales found in: |
|
158 | - * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
159 | - * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
160 | - * |
|
161 | - * @since 1.0.0 |
|
162 | - */ |
|
163 | - public function load_textdomain() { |
|
164 | - // Determines the current locale. |
|
165 | - if ( function_exists( 'determine_locale' ) ) { |
|
166 | - $locale = determine_locale(); |
|
167 | - } else if ( function_exists( 'get_user_locale' ) ) { |
|
168 | - $locale = get_user_locale(); |
|
169 | - } else { |
|
170 | - $locale = get_locale(); |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Filter the locale to use for translations. |
|
175 | - */ |
|
176 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
177 | - |
|
178 | - unload_textdomain( 'invoicing', true ); |
|
179 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
180 | - load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Include required core files used in admin and on the frontend. |
|
185 | - */ |
|
186 | - public function includes() { |
|
187 | - // Start with the settings. |
|
188 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
189 | - |
|
190 | - // Packages/libraries. |
|
191 | - require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
192 | - require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
193 | - |
|
194 | - // Load functions. |
|
195 | - require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
196 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
197 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
198 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
199 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
200 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
201 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
202 | - require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
203 | - require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
204 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
205 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
206 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
207 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
208 | - require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
209 | - require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
210 | - |
|
211 | - // Register autoloader. |
|
212 | - try { |
|
213 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
214 | - } catch ( Exception $e ) { |
|
215 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
216 | - } |
|
217 | - |
|
218 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
219 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
220 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
221 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
222 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
223 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
224 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
225 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
226 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
227 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
228 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
229 | - require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
230 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
231 | - require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
232 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
233 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
234 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
235 | - require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
236 | - require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
237 | - require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
238 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
239 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
240 | - |
|
241 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
242 | - GetPaid_Post_Types_Admin::init(); |
|
243 | - |
|
244 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
245 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
246 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
247 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
248 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
249 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
250 | - // load the user class only on the users.php page |
|
251 | - global $pagenow; |
|
252 | - if ( $pagenow == 'users.php' ) { |
|
253 | - new WPInv_Admin_Users(); |
|
254 | - } |
|
255 | - } |
|
256 | - |
|
257 | - // Register cli commands |
|
258 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
259 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
260 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
261 | - } |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Class autoloader |
|
266 | - * |
|
267 | - * @param string $class_name The name of the class to load. |
|
268 | - * @access public |
|
269 | - * @since 1.0.19 |
|
270 | - * @return void |
|
271 | - */ |
|
272 | - public function autoload( $class_name ) { |
|
273 | - // Normalize the class name... |
|
274 | - $class_name = strtolower( $class_name ); |
|
275 | - |
|
276 | - // ... and make sure it is our class. |
|
277 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
278 | - return; |
|
279 | - } |
|
280 | - |
|
281 | - // Next, prepare the file name from the class. |
|
282 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
283 | - |
|
284 | - // Base path of the classes. |
|
285 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
286 | - |
|
287 | - // And an array of possible locations in order of importance. |
|
288 | - $locations = array( |
|
289 | - "$plugin_path/includes", |
|
290 | - "$plugin_path/includes/data-stores", |
|
291 | - "$plugin_path/includes/gateways", |
|
292 | - "$plugin_path/includes/payments", |
|
293 | - "$plugin_path/includes/geolocation", |
|
294 | - "$plugin_path/includes/reports", |
|
295 | - "$plugin_path/includes/api", |
|
296 | - "$plugin_path/includes/admin", |
|
297 | - "$plugin_path/includes/admin/meta-boxes", |
|
298 | - ); |
|
299 | - |
|
300 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
301 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
302 | - include trailingslashit( $location ) . $file_name; |
|
303 | - break; |
|
304 | - } |
|
305 | - } |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Inits hooks etc. |
|
310 | - */ |
|
311 | - public function init() { |
|
312 | - // Fires before getpaid inits. |
|
313 | - do_action( 'before_getpaid_init', $this ); |
|
314 | - |
|
315 | - // Maybe upgrade. |
|
316 | - $this->maybe_upgrade_database(); |
|
317 | - |
|
318 | - // Load default gateways. |
|
319 | - $gateways = apply_filters( |
|
320 | - 'getpaid_default_gateways', |
|
321 | - array( |
|
322 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
323 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
324 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
325 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
326 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
327 | - ) |
|
328 | - ); |
|
329 | - |
|
330 | - foreach ( $gateways as $id => $class ) { |
|
331 | - $this->gateways[ $id ] = new $class(); |
|
332 | - } |
|
333 | - |
|
334 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
335 | - GetPaid_Installer::rename_gateways_label(); |
|
336 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
337 | - } |
|
338 | - |
|
339 | - // Fires after getpaid inits. |
|
340 | - do_action( 'getpaid_init', $this ); |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Checks if this is an IPN request and processes it. |
|
345 | - */ |
|
346 | - public function maybe_process_ipn() { |
|
347 | - // Ensure that this is an IPN request. |
|
348 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
349 | - return; |
|
350 | - } |
|
351 | - |
|
352 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
353 | - |
|
354 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
355 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
356 | - exit; |
|
357 | - } |
|
358 | - |
|
359 | - public function enqueue_scripts() { |
|
360 | - // Fires before adding scripts. |
|
361 | - do_action( 'getpaid_enqueue_scripts' ); |
|
362 | - |
|
363 | - $localize = array(); |
|
364 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
365 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
366 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
367 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
368 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
369 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
370 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
371 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
372 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
373 | - $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
374 | - |
|
375 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
376 | - |
|
377 | - // reCaptcha. |
|
378 | - if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
379 | - wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
380 | - } |
|
381 | - |
|
382 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array( 'jquery' ), WPINV_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 | - * 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. |
|
401 | - */ |
|
402 | - public function maybe_do_authenticated_action() { |
|
403 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
404 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
405 | - $data = wp_unslash( $_REQUEST ); |
|
406 | - |
|
407 | - if ( is_user_logged_in() ) { |
|
408 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
409 | - } |
|
410 | - |
|
411 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
412 | - } |
|
413 | - } |
|
414 | - |
|
415 | - public function pre_get_posts( $wp_query ) { |
|
416 | - 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() ) { |
|
417 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
418 | - } |
|
419 | - |
|
420 | - return $wp_query; |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Register widgets |
|
425 | - * |
|
426 | - */ |
|
427 | - public function register_widgets() { |
|
428 | - global $pagenow; |
|
429 | - |
|
430 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
431 | - // So we disable our widgets when editing a page with UX Builder. |
|
432 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
433 | - return; |
|
434 | - } |
|
435 | - |
|
436 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
437 | - |
|
438 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
439 | - // don't initiate in these conditions. |
|
440 | - } else { |
|
441 | - // Only load allowed widgets. |
|
442 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
443 | - $widgets = apply_filters( |
|
444 | - 'getpaid_widget_classes', |
|
445 | - array( |
|
446 | - 'WPInv_Checkout_Widget', |
|
447 | - 'WPInv_History_Widget', |
|
448 | - 'WPInv_Receipt_Widget', |
|
449 | - 'WPInv_Subscriptions_Widget', |
|
450 | - 'WPInv_Buy_Item_Widget', |
|
451 | - 'WPInv_Messages_Widget', |
|
452 | - 'WPInv_GetPaid_Widget', |
|
453 | - 'WPInv_Invoice_Widget', |
|
454 | - ) |
|
455 | - ); |
|
456 | - |
|
457 | - // For each widget... |
|
458 | - foreach ( $widgets as $widget ) { |
|
459 | - // Abort early if it is excluded for this page. |
|
460 | - if ( in_array( $widget, $exclude ) ) { |
|
461 | - continue; |
|
462 | - } |
|
463 | - |
|
464 | - // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
465 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
466 | - register_widget( $widget ); |
|
467 | - } else { |
|
468 | - new $widget(); |
|
469 | - } |
|
470 | - } |
|
471 | - } |
|
472 | - } |
|
473 | - |
|
474 | - /** |
|
475 | - * Upgrades the database. |
|
476 | - * |
|
477 | - * @since 2.0.2 |
|
478 | - */ |
|
479 | - public function maybe_upgrade_database() { |
|
480 | - // Ensure the database tables are up to date. |
|
481 | - GetPaid_Installer::maybe_create_db_tables(); |
|
482 | - |
|
483 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
484 | - |
|
485 | - if ( $wpi_version == WPINV_VERSION ) { |
|
486 | - return; |
|
487 | - } |
|
488 | - |
|
489 | - $installer = new GetPaid_Installer(); |
|
490 | - |
|
491 | - if ( empty( $wpi_version ) ) { |
|
492 | - return $installer->upgrade_db( 0 ); |
|
493 | - } |
|
494 | - |
|
495 | - $upgrades = array( |
|
496 | - '0.0.5' => '004', |
|
497 | - '1.0.3' => '102', |
|
498 | - '2.0.0' => '118', |
|
499 | - '2.8.0' => '279', |
|
500 | - ); |
|
501 | - |
|
502 | - foreach ( $upgrades as $key => $method ) { |
|
503 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
504 | - return $installer->upgrade_db( $method ); |
|
505 | - } |
|
506 | - } |
|
507 | - } |
|
508 | - |
|
509 | - /** |
|
510 | - * Flushes the permalinks if needed. |
|
511 | - * |
|
512 | - * @since 2.0.8 |
|
513 | - */ |
|
514 | - public function maybe_flush_permalinks() { |
|
515 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
516 | - |
|
517 | - if ( ! empty( $flush ) ) { |
|
518 | - flush_rewrite_rules(); |
|
519 | - delete_option( 'wpinv_flush_permalinks' ); |
|
520 | - } |
|
521 | - } |
|
522 | - |
|
523 | - /** |
|
524 | - * Remove our pages from yoast sitemaps. |
|
525 | - * |
|
526 | - * @since 1.0.19 |
|
527 | - * @param int[] $excluded_posts_ids |
|
528 | - */ |
|
529 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
530 | - // Ensure that we have an array. |
|
531 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
532 | - $excluded_posts_ids = array(); |
|
533 | - } |
|
534 | - |
|
535 | - // Prepare our pages. |
|
536 | - $our_pages = array(); |
|
537 | - |
|
538 | - // Checkout page. |
|
539 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
540 | - |
|
541 | - // Success page. |
|
542 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
543 | - |
|
544 | - // Failure page. |
|
545 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
546 | - |
|
547 | - // History page. |
|
548 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
549 | - |
|
550 | - // Subscriptions page. |
|
551 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
552 | - |
|
553 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
554 | - |
|
555 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
556 | - |
|
557 | - return array_unique( $excluded_posts_ids ); |
|
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * Remove our pages from yoast sitemaps. |
|
562 | - * |
|
563 | - * @since 1.0.19 |
|
564 | - * @param string[] $post_types |
|
565 | - */ |
|
566 | - public function exclude_invoicing_post_types( $post_types ) { |
|
567 | - // Ensure that we have an array. |
|
568 | - if ( ! is_array( $post_types ) ) { |
|
569 | - $post_types = array(); |
|
570 | - } |
|
571 | - |
|
572 | - // Remove our post types. |
|
573 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
574 | - } |
|
575 | - |
|
576 | - /** |
|
577 | - * Displays additional footer code. |
|
578 | - * |
|
579 | - * @since 2.0.0 |
|
580 | - */ |
|
581 | - public function wp_footer() { |
|
582 | - wpinv_get_template( 'frontend-footer.php' ); |
|
583 | - } |
|
584 | - |
|
585 | - /** |
|
586 | - * Displays additional header code. |
|
587 | - * |
|
588 | - * @since 2.0.0 |
|
589 | - */ |
|
590 | - public function wp_head() { |
|
591 | - wpinv_get_template( 'frontend-head.php' ); |
|
592 | - } |
|
593 | - |
|
594 | - /** |
|
595 | - * Custom query vars. |
|
596 | - * |
|
597 | - */ |
|
598 | - public function custom_query_vars( $vars ) { |
|
599 | - $vars[] = 'getpaid-ipn'; |
|
600 | - return $vars; |
|
601 | - } |
|
602 | - |
|
603 | - /** |
|
604 | - * Add rewrite tags and rules. |
|
605 | - * |
|
606 | - */ |
|
607 | - public function add_rewrite_rule() { |
|
608 | - $tag = 'getpaid-ipn'; |
|
609 | - add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
610 | - add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
611 | - } |
|
612 | - |
|
613 | - /** |
|
614 | - * Processes non-query string ipns. |
|
615 | - * |
|
616 | - */ |
|
617 | - public function maybe_process_new_ipn( $query ) { |
|
618 | - if ( is_admin() || ! $query->is_main_query() ) { |
|
619 | - return; |
|
620 | - } |
|
621 | - |
|
622 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
623 | - |
|
624 | - if ( ! empty( $gateway ) ) { |
|
625 | - $gateway = sanitize_text_field( $gateway ); |
|
626 | - nocache_headers(); |
|
627 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
628 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
629 | - exit; |
|
630 | - } |
|
631 | - } |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var array An array of payment gateways. |
|
40 | + */ |
|
41 | + public $gateways; |
|
42 | + |
|
43 | + /** |
|
44 | + * Class constructor. |
|
45 | + */ |
|
46 | + public function __construct() { |
|
47 | + $this->define_constants(); |
|
48 | + $this->includes(); |
|
49 | + $this->init_hooks(); |
|
50 | + $this->set_properties(); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Sets a custom data property. |
|
55 | + * |
|
56 | + * @param string $prop The prop to set. |
|
57 | + * @param mixed $value The value to retrieve. |
|
58 | + */ |
|
59 | + public function set( $prop, $value ) { |
|
60 | + $this->data[ $prop ] = $value; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Gets a custom data property. |
|
65 | + * |
|
66 | + * @param string $prop The prop to set. |
|
67 | + * @return mixed The value. |
|
68 | + */ |
|
69 | + public function get( $prop ) { |
|
70 | + if ( isset( $this->data[ $prop ] ) ) { |
|
71 | + return $this->data[ $prop ]; |
|
72 | + } |
|
73 | + |
|
74 | + return null; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Define class properties. |
|
79 | + */ |
|
80 | + public function set_properties() { |
|
81 | + // Sessions. |
|
82 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
83 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
84 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
85 | + |
|
86 | + // Init other objects. |
|
87 | + $this->set( 'notes', new WPInv_Notes() ); |
|
88 | + $this->set( 'api', new WPInv_API() ); |
|
89 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
90 | + $this->set( 'template', new GetPaid_Template() ); |
|
91 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
92 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
93 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
94 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
95 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
96 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
97 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Define plugin constants. |
|
102 | + */ |
|
103 | + public function define_constants() { |
|
104 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
105 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
106 | + $this->version = WPINV_VERSION; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Hook into actions and filters. |
|
111 | + * |
|
112 | + * @since 1.0.19 |
|
113 | + */ |
|
114 | + protected function init_hooks() { |
|
115 | + /* Internationalize the text strings used. */ |
|
116 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
117 | + |
|
118 | + // Init the plugin after WordPress inits. |
|
119 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
120 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 100 ); |
|
121 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
122 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
123 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
124 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
125 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
126 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
127 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
128 | + add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
129 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
130 | + |
|
131 | + add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
132 | + add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
133 | + add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
134 | + |
|
135 | + // Fires after registering actions. |
|
136 | + do_action( 'wpinv_actions', $this ); |
|
137 | + do_action( 'getpaid_actions', $this ); |
|
138 | + } |
|
139 | + |
|
140 | + public function plugins_loaded() { |
|
141 | + /* Internationalize the text strings used. */ |
|
142 | + $this->load_textdomain(); |
|
143 | + |
|
144 | + do_action( 'wpinv_loaded' ); |
|
145 | + |
|
146 | + // Fix oxygen page builder conflict |
|
147 | + if ( function_exists( 'ct_css_output' ) ) { |
|
148 | + wpinv_oxygen_fix_conflict(); |
|
149 | + } |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Load Localisation files. |
|
154 | + * |
|
155 | + * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
156 | + * |
|
157 | + * Locales found in: |
|
158 | + * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
159 | + * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
160 | + * |
|
161 | + * @since 1.0.0 |
|
162 | + */ |
|
163 | + public function load_textdomain() { |
|
164 | + // Determines the current locale. |
|
165 | + if ( function_exists( 'determine_locale' ) ) { |
|
166 | + $locale = determine_locale(); |
|
167 | + } else if ( function_exists( 'get_user_locale' ) ) { |
|
168 | + $locale = get_user_locale(); |
|
169 | + } else { |
|
170 | + $locale = get_locale(); |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Filter the locale to use for translations. |
|
175 | + */ |
|
176 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
177 | + |
|
178 | + unload_textdomain( 'invoicing', true ); |
|
179 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
180 | + load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Include required core files used in admin and on the frontend. |
|
185 | + */ |
|
186 | + public function includes() { |
|
187 | + // Start with the settings. |
|
188 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
189 | + |
|
190 | + // Packages/libraries. |
|
191 | + require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
192 | + require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
193 | + |
|
194 | + // Load functions. |
|
195 | + require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
196 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
197 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
198 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
199 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
200 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
201 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
202 | + require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
203 | + require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
204 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
205 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
206 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
207 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
208 | + require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
209 | + require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
210 | + |
|
211 | + // Register autoloader. |
|
212 | + try { |
|
213 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
214 | + } catch ( Exception $e ) { |
|
215 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
216 | + } |
|
217 | + |
|
218 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
219 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
220 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
221 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
222 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
223 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
224 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
225 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
226 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
227 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
228 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
229 | + require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
230 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
231 | + require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
232 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
233 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
234 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
235 | + require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
236 | + require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
237 | + require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
238 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
239 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
240 | + |
|
241 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
242 | + GetPaid_Post_Types_Admin::init(); |
|
243 | + |
|
244 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
245 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
246 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
247 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
248 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
249 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
250 | + // load the user class only on the users.php page |
|
251 | + global $pagenow; |
|
252 | + if ( $pagenow == 'users.php' ) { |
|
253 | + new WPInv_Admin_Users(); |
|
254 | + } |
|
255 | + } |
|
256 | + |
|
257 | + // Register cli commands |
|
258 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
259 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
260 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
261 | + } |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Class autoloader |
|
266 | + * |
|
267 | + * @param string $class_name The name of the class to load. |
|
268 | + * @access public |
|
269 | + * @since 1.0.19 |
|
270 | + * @return void |
|
271 | + */ |
|
272 | + public function autoload( $class_name ) { |
|
273 | + // Normalize the class name... |
|
274 | + $class_name = strtolower( $class_name ); |
|
275 | + |
|
276 | + // ... and make sure it is our class. |
|
277 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
278 | + return; |
|
279 | + } |
|
280 | + |
|
281 | + // Next, prepare the file name from the class. |
|
282 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
283 | + |
|
284 | + // Base path of the classes. |
|
285 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
286 | + |
|
287 | + // And an array of possible locations in order of importance. |
|
288 | + $locations = array( |
|
289 | + "$plugin_path/includes", |
|
290 | + "$plugin_path/includes/data-stores", |
|
291 | + "$plugin_path/includes/gateways", |
|
292 | + "$plugin_path/includes/payments", |
|
293 | + "$plugin_path/includes/geolocation", |
|
294 | + "$plugin_path/includes/reports", |
|
295 | + "$plugin_path/includes/api", |
|
296 | + "$plugin_path/includes/admin", |
|
297 | + "$plugin_path/includes/admin/meta-boxes", |
|
298 | + ); |
|
299 | + |
|
300 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
301 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
302 | + include trailingslashit( $location ) . $file_name; |
|
303 | + break; |
|
304 | + } |
|
305 | + } |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Inits hooks etc. |
|
310 | + */ |
|
311 | + public function init() { |
|
312 | + // Fires before getpaid inits. |
|
313 | + do_action( 'before_getpaid_init', $this ); |
|
314 | + |
|
315 | + // Maybe upgrade. |
|
316 | + $this->maybe_upgrade_database(); |
|
317 | + |
|
318 | + // Load default gateways. |
|
319 | + $gateways = apply_filters( |
|
320 | + 'getpaid_default_gateways', |
|
321 | + array( |
|
322 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
323 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
324 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
325 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
326 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
327 | + ) |
|
328 | + ); |
|
329 | + |
|
330 | + foreach ( $gateways as $id => $class ) { |
|
331 | + $this->gateways[ $id ] = new $class(); |
|
332 | + } |
|
333 | + |
|
334 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
335 | + GetPaid_Installer::rename_gateways_label(); |
|
336 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
337 | + } |
|
338 | + |
|
339 | + // Fires after getpaid inits. |
|
340 | + do_action( 'getpaid_init', $this ); |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * Checks if this is an IPN request and processes it. |
|
345 | + */ |
|
346 | + public function maybe_process_ipn() { |
|
347 | + // Ensure that this is an IPN request. |
|
348 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
349 | + return; |
|
350 | + } |
|
351 | + |
|
352 | + $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
353 | + |
|
354 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
355 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
356 | + exit; |
|
357 | + } |
|
358 | + |
|
359 | + public function enqueue_scripts() { |
|
360 | + // Fires before adding scripts. |
|
361 | + do_action( 'getpaid_enqueue_scripts' ); |
|
362 | + |
|
363 | + $localize = array(); |
|
364 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
365 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
366 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
367 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
368 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
369 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
370 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
371 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
372 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
373 | + $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
374 | + |
|
375 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
376 | + |
|
377 | + // reCaptcha. |
|
378 | + if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
379 | + wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
380 | + } |
|
381 | + |
|
382 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array( 'jquery' ), WPINV_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 | + * 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. |
|
401 | + */ |
|
402 | + public function maybe_do_authenticated_action() { |
|
403 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
404 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
405 | + $data = wp_unslash( $_REQUEST ); |
|
406 | + |
|
407 | + if ( is_user_logged_in() ) { |
|
408 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
409 | + } |
|
410 | + |
|
411 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
412 | + } |
|
413 | + } |
|
414 | + |
|
415 | + public function pre_get_posts( $wp_query ) { |
|
416 | + 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() ) { |
|
417 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
418 | + } |
|
419 | + |
|
420 | + return $wp_query; |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Register widgets |
|
425 | + * |
|
426 | + */ |
|
427 | + public function register_widgets() { |
|
428 | + global $pagenow; |
|
429 | + |
|
430 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
431 | + // So we disable our widgets when editing a page with UX Builder. |
|
432 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
433 | + return; |
|
434 | + } |
|
435 | + |
|
436 | + $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
437 | + |
|
438 | + if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
439 | + // don't initiate in these conditions. |
|
440 | + } else { |
|
441 | + // Only load allowed widgets. |
|
442 | + $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
443 | + $widgets = apply_filters( |
|
444 | + 'getpaid_widget_classes', |
|
445 | + array( |
|
446 | + 'WPInv_Checkout_Widget', |
|
447 | + 'WPInv_History_Widget', |
|
448 | + 'WPInv_Receipt_Widget', |
|
449 | + 'WPInv_Subscriptions_Widget', |
|
450 | + 'WPInv_Buy_Item_Widget', |
|
451 | + 'WPInv_Messages_Widget', |
|
452 | + 'WPInv_GetPaid_Widget', |
|
453 | + 'WPInv_Invoice_Widget', |
|
454 | + ) |
|
455 | + ); |
|
456 | + |
|
457 | + // For each widget... |
|
458 | + foreach ( $widgets as $widget ) { |
|
459 | + // Abort early if it is excluded for this page. |
|
460 | + if ( in_array( $widget, $exclude ) ) { |
|
461 | + continue; |
|
462 | + } |
|
463 | + |
|
464 | + // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
465 | + if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
466 | + register_widget( $widget ); |
|
467 | + } else { |
|
468 | + new $widget(); |
|
469 | + } |
|
470 | + } |
|
471 | + } |
|
472 | + } |
|
473 | + |
|
474 | + /** |
|
475 | + * Upgrades the database. |
|
476 | + * |
|
477 | + * @since 2.0.2 |
|
478 | + */ |
|
479 | + public function maybe_upgrade_database() { |
|
480 | + // Ensure the database tables are up to date. |
|
481 | + GetPaid_Installer::maybe_create_db_tables(); |
|
482 | + |
|
483 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
484 | + |
|
485 | + if ( $wpi_version == WPINV_VERSION ) { |
|
486 | + return; |
|
487 | + } |
|
488 | + |
|
489 | + $installer = new GetPaid_Installer(); |
|
490 | + |
|
491 | + if ( empty( $wpi_version ) ) { |
|
492 | + return $installer->upgrade_db( 0 ); |
|
493 | + } |
|
494 | + |
|
495 | + $upgrades = array( |
|
496 | + '0.0.5' => '004', |
|
497 | + '1.0.3' => '102', |
|
498 | + '2.0.0' => '118', |
|
499 | + '2.8.0' => '279', |
|
500 | + ); |
|
501 | + |
|
502 | + foreach ( $upgrades as $key => $method ) { |
|
503 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
504 | + return $installer->upgrade_db( $method ); |
|
505 | + } |
|
506 | + } |
|
507 | + } |
|
508 | + |
|
509 | + /** |
|
510 | + * Flushes the permalinks if needed. |
|
511 | + * |
|
512 | + * @since 2.0.8 |
|
513 | + */ |
|
514 | + public function maybe_flush_permalinks() { |
|
515 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
516 | + |
|
517 | + if ( ! empty( $flush ) ) { |
|
518 | + flush_rewrite_rules(); |
|
519 | + delete_option( 'wpinv_flush_permalinks' ); |
|
520 | + } |
|
521 | + } |
|
522 | + |
|
523 | + /** |
|
524 | + * Remove our pages from yoast sitemaps. |
|
525 | + * |
|
526 | + * @since 1.0.19 |
|
527 | + * @param int[] $excluded_posts_ids |
|
528 | + */ |
|
529 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
530 | + // Ensure that we have an array. |
|
531 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
532 | + $excluded_posts_ids = array(); |
|
533 | + } |
|
534 | + |
|
535 | + // Prepare our pages. |
|
536 | + $our_pages = array(); |
|
537 | + |
|
538 | + // Checkout page. |
|
539 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
540 | + |
|
541 | + // Success page. |
|
542 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
543 | + |
|
544 | + // Failure page. |
|
545 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
546 | + |
|
547 | + // History page. |
|
548 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
549 | + |
|
550 | + // Subscriptions page. |
|
551 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
552 | + |
|
553 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
554 | + |
|
555 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
556 | + |
|
557 | + return array_unique( $excluded_posts_ids ); |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * Remove our pages from yoast sitemaps. |
|
562 | + * |
|
563 | + * @since 1.0.19 |
|
564 | + * @param string[] $post_types |
|
565 | + */ |
|
566 | + public function exclude_invoicing_post_types( $post_types ) { |
|
567 | + // Ensure that we have an array. |
|
568 | + if ( ! is_array( $post_types ) ) { |
|
569 | + $post_types = array(); |
|
570 | + } |
|
571 | + |
|
572 | + // Remove our post types. |
|
573 | + return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
574 | + } |
|
575 | + |
|
576 | + /** |
|
577 | + * Displays additional footer code. |
|
578 | + * |
|
579 | + * @since 2.0.0 |
|
580 | + */ |
|
581 | + public function wp_footer() { |
|
582 | + wpinv_get_template( 'frontend-footer.php' ); |
|
583 | + } |
|
584 | + |
|
585 | + /** |
|
586 | + * Displays additional header code. |
|
587 | + * |
|
588 | + * @since 2.0.0 |
|
589 | + */ |
|
590 | + public function wp_head() { |
|
591 | + wpinv_get_template( 'frontend-head.php' ); |
|
592 | + } |
|
593 | + |
|
594 | + /** |
|
595 | + * Custom query vars. |
|
596 | + * |
|
597 | + */ |
|
598 | + public function custom_query_vars( $vars ) { |
|
599 | + $vars[] = 'getpaid-ipn'; |
|
600 | + return $vars; |
|
601 | + } |
|
602 | + |
|
603 | + /** |
|
604 | + * Add rewrite tags and rules. |
|
605 | + * |
|
606 | + */ |
|
607 | + public function add_rewrite_rule() { |
|
608 | + $tag = 'getpaid-ipn'; |
|
609 | + add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
610 | + add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
611 | + } |
|
612 | + |
|
613 | + /** |
|
614 | + * Processes non-query string ipns. |
|
615 | + * |
|
616 | + */ |
|
617 | + public function maybe_process_new_ipn( $query ) { |
|
618 | + if ( is_admin() || ! $query->is_main_query() ) { |
|
619 | + return; |
|
620 | + } |
|
621 | + |
|
622 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
623 | + |
|
624 | + if ( ! empty( $gateway ) ) { |
|
625 | + $gateway = sanitize_text_field( $gateway ); |
|
626 | + nocache_headers(); |
|
627 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
628 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
629 | + exit; |
|
630 | + } |
|
631 | + } |
|
632 | 632 | } |
@@ -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,9 +66,9 @@ discard block |
||
66 | 66 | * @param string $prop The prop to set. |
67 | 67 | * @return mixed The value. |
68 | 68 | */ |
69 | - public function get( $prop ) { |
|
70 | - if ( isset( $this->data[ $prop ] ) ) { |
|
71 | - return $this->data[ $prop ]; |
|
69 | + public function get($prop) { |
|
70 | + if (isset($this->data[$prop])) { |
|
71 | + return $this->data[$prop]; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | return null; |
@@ -79,30 +79,30 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function set_properties() { |
81 | 81 | // Sessions. |
82 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
83 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
82 | + $this->set('session', new WPInv_Session_Handler()); |
|
83 | + $GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility. |
|
84 | 84 | $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
85 | 85 | |
86 | 86 | // Init other objects. |
87 | - $this->set( 'notes', new WPInv_Notes() ); |
|
88 | - $this->set( 'api', new WPInv_API() ); |
|
89 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
90 | - $this->set( 'template', new GetPaid_Template() ); |
|
91 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
92 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
93 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
94 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
95 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
96 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
97 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
87 | + $this->set('notes', new WPInv_Notes()); |
|
88 | + $this->set('api', new WPInv_API()); |
|
89 | + $this->set('post_types', new GetPaid_Post_Types()); |
|
90 | + $this->set('template', new GetPaid_Template()); |
|
91 | + $this->set('admin', new GetPaid_Admin()); |
|
92 | + $this->set('subscriptions', new WPInv_Subscriptions()); |
|
93 | + $this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails()); |
|
94 | + $this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails()); |
|
95 | + $this->set('daily_maintenace', new GetPaid_Daily_Maintenance()); |
|
96 | + $this->set('payment_forms', new GetPaid_Payment_Forms()); |
|
97 | + $this->set('maxmind', new GetPaid_MaxMind_Geolocation()); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * Define plugin constants. |
102 | 102 | */ |
103 | 103 | public function define_constants() { |
104 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
105 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
104 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
105 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
106 | 106 | $this->version = WPINV_VERSION; |
107 | 107 | } |
108 | 108 | |
@@ -113,38 +113,38 @@ discard block |
||
113 | 113 | */ |
114 | 114 | protected function init_hooks() { |
115 | 115 | /* Internationalize the text strings used. */ |
116 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
116 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
117 | 117 | |
118 | 118 | // Init the plugin after WordPress inits. |
119 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
120 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 100 ); |
|
121 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
122 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
123 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
124 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
125 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
126 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
127 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
128 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
129 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
130 | - |
|
131 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
132 | - add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
133 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
119 | + add_action('init', array($this, 'init'), 1); |
|
120 | + add_action('init', array($this, 'maybe_process_ipn'), 100); |
|
121 | + add_action('init', array($this, 'wpinv_actions')); |
|
122 | + add_action('init', array($this, 'maybe_do_authenticated_action'), 100); |
|
123 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 11); |
|
124 | + add_action('wp_footer', array($this, 'wp_footer')); |
|
125 | + add_action('wp_head', array($this, 'wp_head')); |
|
126 | + add_action('widgets_init', array($this, 'register_widgets')); |
|
127 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
128 | + add_filter('the_seo_framework_sitemap_supported_post_types', array($this, 'exclude_invoicing_post_types')); |
|
129 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
130 | + |
|
131 | + add_filter('query_vars', array($this, 'custom_query_vars')); |
|
132 | + add_action('init', array($this, 'add_rewrite_rule'), 10, 0); |
|
133 | + add_action('pre_get_posts', array($this, 'maybe_process_new_ipn'), 1); |
|
134 | 134 | |
135 | 135 | // Fires after registering actions. |
136 | - do_action( 'wpinv_actions', $this ); |
|
137 | - do_action( 'getpaid_actions', $this ); |
|
136 | + do_action('wpinv_actions', $this); |
|
137 | + do_action('getpaid_actions', $this); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | public function plugins_loaded() { |
141 | 141 | /* Internationalize the text strings used. */ |
142 | 142 | $this->load_textdomain(); |
143 | 143 | |
144 | - do_action( 'wpinv_loaded' ); |
|
144 | + do_action('wpinv_loaded'); |
|
145 | 145 | |
146 | 146 | // Fix oxygen page builder conflict |
147 | - if ( function_exists( 'ct_css_output' ) ) { |
|
147 | + if (function_exists('ct_css_output')) { |
|
148 | 148 | wpinv_oxygen_fix_conflict(); |
149 | 149 | } |
150 | 150 | } |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public function load_textdomain() { |
164 | 164 | // Determines the current locale. |
165 | - if ( function_exists( 'determine_locale' ) ) { |
|
165 | + if (function_exists('determine_locale')) { |
|
166 | 166 | $locale = determine_locale(); |
167 | - } else if ( function_exists( 'get_user_locale' ) ) { |
|
167 | + } else if (function_exists('get_user_locale')) { |
|
168 | 168 | $locale = get_user_locale(); |
169 | 169 | } else { |
170 | 170 | $locale = get_locale(); |
@@ -173,11 +173,11 @@ discard block |
||
173 | 173 | /** |
174 | 174 | * Filter the locale to use for translations. |
175 | 175 | */ |
176 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
176 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
177 | 177 | |
178 | - unload_textdomain( 'invoicing', true ); |
|
179 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
180 | - load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
178 | + unload_textdomain('invoicing', true); |
|
179 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
180 | + load_plugin_textdomain('invoicing', false, plugin_basename(dirname(WPINV_PLUGIN_FILE)) . '/languages/'); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | |
211 | 211 | // Register autoloader. |
212 | 212 | try { |
213 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
214 | - } catch ( Exception $e ) { |
|
215 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
213 | + spl_autoload_register(array($this, 'autoload'), true); |
|
214 | + } catch (Exception $e) { |
|
215 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
239 | 239 | require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
240 | 240 | |
241 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
241 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
242 | 242 | GetPaid_Post_Types_Admin::init(); |
243 | 243 | |
244 | 244 | require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
@@ -249,15 +249,15 @@ discard block |
||
249 | 249 | require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
250 | 250 | // load the user class only on the users.php page |
251 | 251 | global $pagenow; |
252 | - if ( $pagenow == 'users.php' ) { |
|
252 | + if ($pagenow == 'users.php') { |
|
253 | 253 | new WPInv_Admin_Users(); |
254 | 254 | } |
255 | 255 | } |
256 | 256 | |
257 | 257 | // Register cli commands |
258 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
258 | + if (defined('WP_CLI') && WP_CLI) { |
|
259 | 259 | require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
260 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
260 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
261 | 261 | } |
262 | 262 | } |
263 | 263 | |
@@ -269,20 +269,20 @@ discard block |
||
269 | 269 | * @since 1.0.19 |
270 | 270 | * @return void |
271 | 271 | */ |
272 | - public function autoload( $class_name ) { |
|
272 | + public function autoload($class_name) { |
|
273 | 273 | // Normalize the class name... |
274 | - $class_name = strtolower( $class_name ); |
|
274 | + $class_name = strtolower($class_name); |
|
275 | 275 | |
276 | 276 | // ... and make sure it is our class. |
277 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
277 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
278 | 278 | return; |
279 | 279 | } |
280 | 280 | |
281 | 281 | // Next, prepare the file name from the class. |
282 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
282 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
283 | 283 | |
284 | 284 | // Base path of the classes. |
285 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
285 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
286 | 286 | |
287 | 287 | // And an array of possible locations in order of importance. |
288 | 288 | $locations = array( |
@@ -297,9 +297,9 @@ discard block |
||
297 | 297 | "$plugin_path/includes/admin/meta-boxes", |
298 | 298 | ); |
299 | 299 | |
300 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
301 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
302 | - include trailingslashit( $location ) . $file_name; |
|
300 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
301 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
302 | + include trailingslashit($location) . $file_name; |
|
303 | 303 | break; |
304 | 304 | } |
305 | 305 | } |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | */ |
311 | 311 | public function init() { |
312 | 312 | // Fires before getpaid inits. |
313 | - do_action( 'before_getpaid_init', $this ); |
|
313 | + do_action('before_getpaid_init', $this); |
|
314 | 314 | |
315 | 315 | // Maybe upgrade. |
316 | 316 | $this->maybe_upgrade_database(); |
@@ -327,17 +327,17 @@ discard block |
||
327 | 327 | ) |
328 | 328 | ); |
329 | 329 | |
330 | - foreach ( $gateways as $id => $class ) { |
|
331 | - $this->gateways[ $id ] = new $class(); |
|
330 | + foreach ($gateways as $id => $class) { |
|
331 | + $this->gateways[$id] = new $class(); |
|
332 | 332 | } |
333 | 333 | |
334 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
334 | + if ('yes' != get_option('wpinv_renamed_gateways')) { |
|
335 | 335 | GetPaid_Installer::rename_gateways_label(); |
336 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
336 | + update_option('wpinv_renamed_gateways', 'yes'); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | // Fires after getpaid inits. |
340 | - do_action( 'getpaid_init', $this ); |
|
340 | + do_action('getpaid_init', $this); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
@@ -345,51 +345,51 @@ discard block |
||
345 | 345 | */ |
346 | 346 | public function maybe_process_ipn() { |
347 | 347 | // Ensure that this is an IPN request. |
348 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
348 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
349 | 349 | return; |
350 | 350 | } |
351 | 351 | |
352 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
352 | + $gateway = sanitize_text_field($_GET['wpi-gateway']); |
|
353 | 353 | |
354 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
355 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
354 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
355 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
356 | 356 | exit; |
357 | 357 | } |
358 | 358 | |
359 | 359 | public function enqueue_scripts() { |
360 | 360 | // Fires before adding scripts. |
361 | - do_action( 'getpaid_enqueue_scripts' ); |
|
361 | + do_action('getpaid_enqueue_scripts'); |
|
362 | 362 | |
363 | 363 | $localize = array(); |
364 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
364 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
365 | 365 | $localize['thousands'] = wpinv_thousands_separator(); |
366 | 366 | $localize['decimals'] = wpinv_decimal_separator(); |
367 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
368 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
367 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
368 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
369 | 369 | $localize['UseTaxes'] = wpinv_use_taxes(); |
370 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
371 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
372 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
370 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
371 | + $localize['loading'] = __('Loading...', 'invoicing'); |
|
372 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
373 | 373 | $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
374 | 374 | |
375 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
375 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
376 | 376 | |
377 | 377 | // reCaptcha. |
378 | - if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
379 | - wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
378 | + if (getpaid_is_recaptcha_enabled() && ($recaptcha_js = getpaid_recaptcha_api_url())) { |
|
379 | + wp_enqueue_script('recaptcha', $recaptcha_js, array(), null, true); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
380 | 380 | } |
381 | 381 | |
382 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array( 'jquery' ), WPINV_VERSION, true ); |
|
383 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
382 | + wp_enqueue_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array('jquery'), WPINV_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 | |
@@ -400,21 +400,21 @@ discard block |
||
400 | 400 | * current user owns the invoice/subscription. |
401 | 401 | */ |
402 | 402 | public function maybe_do_authenticated_action() { |
403 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
404 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
405 | - $data = wp_unslash( $_REQUEST ); |
|
403 | + if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
404 | + $key = sanitize_key($_REQUEST['getpaid-action']); |
|
405 | + $data = wp_unslash($_REQUEST); |
|
406 | 406 | |
407 | - if ( is_user_logged_in() ) { |
|
408 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
407 | + if (is_user_logged_in()) { |
|
408 | + do_action("getpaid_authenticated_action_$key", $data); |
|
409 | 409 | } |
410 | 410 | |
411 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
411 | + do_action("getpaid_unauthenticated_action_$key", $data); |
|
412 | 412 | } |
413 | 413 | } |
414 | 414 | |
415 | - public function pre_get_posts( $wp_query ) { |
|
416 | - 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() ) { |
|
417 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
415 | + public function pre_get_posts($wp_query) { |
|
416 | + 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()) { |
|
417 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type'])); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | return $wp_query; |
@@ -429,17 +429,17 @@ discard block |
||
429 | 429 | |
430 | 430 | // Currently, UX Builder does not work particulaly well with SuperDuper. |
431 | 431 | // So we disable our widgets when editing a page with UX Builder. |
432 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
432 | + if (function_exists('ux_builder_is_active') && ux_builder_is_active()) { |
|
433 | 433 | return; |
434 | 434 | } |
435 | 435 | |
436 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
436 | + $block_widget_init_screens = function_exists('sd_pagenow_exclude') ? sd_pagenow_exclude() : array(); |
|
437 | 437 | |
438 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
438 | + if (is_admin() && $pagenow && in_array($pagenow, $block_widget_init_screens)) { |
|
439 | 439 | // don't initiate in these conditions. |
440 | 440 | } else { |
441 | 441 | // Only load allowed widgets. |
442 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
442 | + $exclude = function_exists('sd_widget_exclude') ? sd_widget_exclude() : array(); |
|
443 | 443 | $widgets = apply_filters( |
444 | 444 | 'getpaid_widget_classes', |
445 | 445 | array( |
@@ -455,15 +455,15 @@ discard block |
||
455 | 455 | ); |
456 | 456 | |
457 | 457 | // For each widget... |
458 | - foreach ( $widgets as $widget ) { |
|
458 | + foreach ($widgets as $widget) { |
|
459 | 459 | // Abort early if it is excluded for this page. |
460 | - if ( in_array( $widget, $exclude ) ) { |
|
460 | + if (in_array($widget, $exclude)) { |
|
461 | 461 | continue; |
462 | 462 | } |
463 | 463 | |
464 | 464 | // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
465 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
466 | - register_widget( $widget ); |
|
465 | + if (is_subclass_of($widget, 'WP_Widget')) { |
|
466 | + register_widget($widget); |
|
467 | 467 | } else { |
468 | 468 | new $widget(); |
469 | 469 | } |
@@ -480,28 +480,28 @@ discard block |
||
480 | 480 | // Ensure the database tables are up to date. |
481 | 481 | GetPaid_Installer::maybe_create_db_tables(); |
482 | 482 | |
483 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
483 | + $wpi_version = get_option('wpinv_version', 0); |
|
484 | 484 | |
485 | - if ( $wpi_version == WPINV_VERSION ) { |
|
485 | + if ($wpi_version == WPINV_VERSION) { |
|
486 | 486 | return; |
487 | 487 | } |
488 | 488 | |
489 | 489 | $installer = new GetPaid_Installer(); |
490 | 490 | |
491 | - if ( empty( $wpi_version ) ) { |
|
492 | - return $installer->upgrade_db( 0 ); |
|
491 | + if (empty($wpi_version)) { |
|
492 | + return $installer->upgrade_db(0); |
|
493 | 493 | } |
494 | 494 | |
495 | - $upgrades = array( |
|
495 | + $upgrades = array( |
|
496 | 496 | '0.0.5' => '004', |
497 | 497 | '1.0.3' => '102', |
498 | 498 | '2.0.0' => '118', |
499 | 499 | '2.8.0' => '279', |
500 | 500 | ); |
501 | 501 | |
502 | - foreach ( $upgrades as $key => $method ) { |
|
503 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
504 | - return $installer->upgrade_db( $method ); |
|
502 | + foreach ($upgrades as $key => $method) { |
|
503 | + if (version_compare($wpi_version, $key, '<')) { |
|
504 | + return $installer->upgrade_db($method); |
|
505 | 505 | } |
506 | 506 | } |
507 | 507 | } |
@@ -512,11 +512,11 @@ discard block |
||
512 | 512 | * @since 2.0.8 |
513 | 513 | */ |
514 | 514 | public function maybe_flush_permalinks() { |
515 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
515 | + $flush = get_option('wpinv_flush_permalinks', 0); |
|
516 | 516 | |
517 | - if ( ! empty( $flush ) ) { |
|
517 | + if (!empty($flush)) { |
|
518 | 518 | flush_rewrite_rules(); |
519 | - delete_option( 'wpinv_flush_permalinks' ); |
|
519 | + delete_option('wpinv_flush_permalinks'); |
|
520 | 520 | } |
521 | 521 | } |
522 | 522 | |
@@ -526,9 +526,9 @@ discard block |
||
526 | 526 | * @since 1.0.19 |
527 | 527 | * @param int[] $excluded_posts_ids |
528 | 528 | */ |
529 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
529 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
530 | 530 | // Ensure that we have an array. |
531 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
531 | + if (!is_array($excluded_posts_ids)) { |
|
532 | 532 | $excluded_posts_ids = array(); |
533 | 533 | } |
534 | 534 | |
@@ -536,25 +536,25 @@ discard block |
||
536 | 536 | $our_pages = array(); |
537 | 537 | |
538 | 538 | // Checkout page. |
539 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
539 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
540 | 540 | |
541 | 541 | // Success page. |
542 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
542 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
543 | 543 | |
544 | 544 | // Failure page. |
545 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
545 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
546 | 546 | |
547 | 547 | // History page. |
548 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
548 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
549 | 549 | |
550 | 550 | // Subscriptions page. |
551 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
551 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
552 | 552 | |
553 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
553 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
554 | 554 | |
555 | 555 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
556 | 556 | |
557 | - return array_unique( $excluded_posts_ids ); |
|
557 | + return array_unique($excluded_posts_ids); |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | /** |
@@ -563,14 +563,14 @@ discard block |
||
563 | 563 | * @since 1.0.19 |
564 | 564 | * @param string[] $post_types |
565 | 565 | */ |
566 | - public function exclude_invoicing_post_types( $post_types ) { |
|
566 | + public function exclude_invoicing_post_types($post_types) { |
|
567 | 567 | // Ensure that we have an array. |
568 | - if ( ! is_array( $post_types ) ) { |
|
568 | + if (!is_array($post_types)) { |
|
569 | 569 | $post_types = array(); |
570 | 570 | } |
571 | 571 | |
572 | 572 | // Remove our post types. |
573 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
573 | + return array_diff($post_types, array_keys(getpaid_get_invoice_post_types())); |
|
574 | 574 | } |
575 | 575 | |
576 | 576 | /** |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | * @since 2.0.0 |
580 | 580 | */ |
581 | 581 | public function wp_footer() { |
582 | - wpinv_get_template( 'frontend-footer.php' ); |
|
582 | + wpinv_get_template('frontend-footer.php'); |
|
583 | 583 | } |
584 | 584 | |
585 | 585 | /** |
@@ -588,14 +588,14 @@ discard block |
||
588 | 588 | * @since 2.0.0 |
589 | 589 | */ |
590 | 590 | public function wp_head() { |
591 | - wpinv_get_template( 'frontend-head.php' ); |
|
591 | + wpinv_get_template('frontend-head.php'); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | /** |
595 | 595 | * Custom query vars. |
596 | 596 | * |
597 | 597 | */ |
598 | - public function custom_query_vars( $vars ) { |
|
598 | + public function custom_query_vars($vars) { |
|
599 | 599 | $vars[] = 'getpaid-ipn'; |
600 | 600 | return $vars; |
601 | 601 | } |
@@ -606,26 +606,26 @@ discard block |
||
606 | 606 | */ |
607 | 607 | public function add_rewrite_rule() { |
608 | 608 | $tag = 'getpaid-ipn'; |
609 | - add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
610 | - add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
609 | + add_rewrite_tag("%$tag%", '([^&]+)'); |
|
610 | + add_rewrite_rule("^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top'); |
|
611 | 611 | } |
612 | 612 | |
613 | 613 | /** |
614 | 614 | * Processes non-query string ipns. |
615 | 615 | * |
616 | 616 | */ |
617 | - public function maybe_process_new_ipn( $query ) { |
|
618 | - if ( is_admin() || ! $query->is_main_query() ) { |
|
617 | + public function maybe_process_new_ipn($query) { |
|
618 | + if (is_admin() || !$query->is_main_query()) { |
|
619 | 619 | return; |
620 | 620 | } |
621 | 621 | |
622 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
622 | + $gateway = get_query_var('getpaid-ipn'); |
|
623 | 623 | |
624 | - if ( ! empty( $gateway ) ) { |
|
625 | - $gateway = sanitize_text_field( $gateway ); |
|
624 | + if (!empty($gateway)) { |
|
625 | + $gateway = sanitize_text_field($gateway); |
|
626 | 626 | nocache_headers(); |
627 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
628 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
627 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
628 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
629 | 629 | exit; |
630 | 630 | } |
631 | 631 | } |