@@ -7,45 +7,45 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | // The payment methods select title. |
13 | -if ( empty( $text ) ) { |
|
14 | - $text = __( 'Select Payment Method', 'invoicing' ); |
|
13 | +if (empty($text)) { |
|
14 | + $text = __('Select Payment Method', 'invoicing'); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | // An array of active payment methods. |
18 | -$gateways = wpinv_get_enabled_payment_gateways( true ); |
|
18 | +$gateways = wpinv_get_enabled_payment_gateways(true); |
|
19 | 19 | |
20 | 20 | // The current invoice id. |
21 | 21 | $invoice_id = 0; |
22 | 22 | $chosen_gateway = wpinv_get_default_gateway(); |
23 | 23 | |
24 | -if ( ! empty( $form->invoice ) ) { |
|
24 | +if (!empty($form->invoice)) { |
|
25 | 25 | $invoice_id = $form->invoice->get_id(); |
26 | 26 | $chosen_gateway = $form->invoice->get_gateway(); |
27 | 27 | } |
28 | 28 | |
29 | 29 | ?> |
30 | 30 | |
31 | - <?php do_action( 'getpaid_before_payment_form_gateway_select', $form ); ?> |
|
31 | + <?php do_action('getpaid_before_payment_form_gateway_select', $form); ?> |
|
32 | 32 | <div class="mt-4 mb-4 getpaid-gateways"> |
33 | 33 | |
34 | - <?php do_action( 'wpinv_payment_mode_top', $invoice_id, $chosen_gateway, $gateways, $form ); ?> |
|
34 | + <?php do_action('wpinv_payment_mode_top', $invoice_id, $chosen_gateway, $gateways, $form); ?> |
|
35 | 35 | |
36 | 36 | <div class="getpaid-select-gateway-title-div"> |
37 | - <h6><?php echo sanitize_text_field( $text ); ?></h6> |
|
37 | + <h6><?php echo sanitize_text_field($text); ?></h6> |
|
38 | 38 | </div> |
39 | 39 | |
40 | 40 | <div class="getpaid-available-gateways-div"> |
41 | 41 | |
42 | - <?php foreach ( array_keys( $gateways ) as $gateway ) : ?> |
|
42 | + <?php foreach (array_keys($gateways) as $gateway) : ?> |
|
43 | 43 | |
44 | - <div class="pt-1 pb-1 getpaid-gateway getpaid-gateway-<?php echo sanitize_html_class( $gateway ) ;?>" data-checkout-label='<?php echo esc_attr( apply_filters( "getpaid_gateway_{$gateway}_checkout_button_label", '' ) ); ?>'> |
|
44 | + <div class="pt-1 pb-1 getpaid-gateway getpaid-gateway-<?php echo sanitize_html_class($gateway); ?>" data-checkout-label='<?php echo esc_attr(apply_filters("getpaid_gateway_{$gateway}_checkout_button_label", '')); ?>'> |
|
45 | 45 | |
46 | 46 | <label class="d-block w-100 getpaid-gateway-radio"> |
47 | - <input type="radio" value="<?php echo esc_attr( $gateway ) ;?>" <?php checked( $gateway, $chosen_gateway ) ;?> name="wpi-gateway"> |
|
48 | - <span><?php echo sanitize_text_field( wpinv_get_gateway_checkout_label( $gateway ) ); ?></span> |
|
47 | + <input type="radio" value="<?php echo esc_attr($gateway); ?>" <?php checked($gateway, $chosen_gateway); ?> name="wpi-gateway"> |
|
48 | + <span><?php echo sanitize_text_field(wpinv_get_gateway_checkout_label($gateway)); ?></span> |
|
49 | 49 | </label> |
50 | 50 | |
51 | 51 | </div> |
@@ -56,22 +56,22 @@ discard block |
||
56 | 56 | |
57 | 57 | <div class="getpaid-gateway-descriptions-div"> |
58 | 58 | |
59 | - <?php foreach ( array_keys( $gateways ) as $gateway ) : ?> |
|
59 | + <?php foreach (array_keys($gateways) as $gateway) : ?> |
|
60 | 60 | |
61 | - <div class="my-2 p-3 bg-light border getpaid-gateway-description getpaid-description-<?php echo sanitize_html_class( $gateway ) ;?>" style="display: none;"> |
|
61 | + <div class="my-2 p-3 bg-light border getpaid-gateway-description getpaid-description-<?php echo sanitize_html_class($gateway); ?>" style="display: none;"> |
|
62 | 62 | <?php |
63 | 63 | |
64 | - $description = wpinv_get_gateway_description( $gateway ); |
|
64 | + $description = wpinv_get_gateway_description($gateway); |
|
65 | 65 | |
66 | - if ( wpinv_is_test_mode( $gateway ) ) { |
|
67 | - $sandbox_notice = apply_filters( "getpaid_{$gateway}_sandbox_notice", __( 'SANDBOX ENABLED: No real payments will occur.', 'invoicing' ) ); |
|
66 | + if (wpinv_is_test_mode($gateway)) { |
|
67 | + $sandbox_notice = apply_filters("getpaid_{$gateway}_sandbox_notice", __('SANDBOX ENABLED: No real payments will occur.', 'invoicing')); |
|
68 | 68 | $description = "$description $sandbox_notice"; |
69 | 69 | } |
70 | 70 | |
71 | - echo wpautop( wp_kses_post( $description ) ); |
|
71 | + echo wpautop(wp_kses_post($description)); |
|
72 | 72 | |
73 | - do_action( 'wpinv_' . $gateway . '_checkout_fields', $invoice_id ) ; |
|
74 | - do_action( 'wpinv_' . $gateway . '_cc_form', $invoice_id, $form ) ; |
|
73 | + do_action('wpinv_' . $gateway . '_checkout_fields', $invoice_id); |
|
74 | + do_action('wpinv_' . $gateway . '_cc_form', $invoice_id, $form); |
|
75 | 75 | |
76 | 76 | ?> |
77 | 77 | </div> |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | <?php |
85 | 85 | echo aui()->alert( |
86 | 86 | array( |
87 | - 'content' => __( 'None of the available payment gateways support purchasing recurring items.', 'invoicing' ), |
|
87 | + 'content' => __('None of the available payment gateways support purchasing recurring items.', 'invoicing'), |
|
88 | 88 | 'type' => 'danger', |
89 | 89 | ) |
90 | 90 | ); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | <?php |
96 | 96 | echo aui()->alert( |
97 | 97 | array( |
98 | - 'content' => __( 'None of the available payment gateways support purchasing multiple subscriptions in a single order.', 'invoicing' ), |
|
98 | + 'content' => __('None of the available payment gateways support purchasing multiple subscriptions in a single order.', 'invoicing'), |
|
99 | 99 | 'type' => 'danger', |
100 | 100 | ) |
101 | 101 | ); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | <?php |
107 | 107 | echo aui()->alert( |
108 | 108 | array( |
109 | - 'content' => __( 'None of the available payment gateways support purchasing multiple subscriptions with different billing schedules in a single order.', 'invoicing' ), |
|
109 | + 'content' => __('None of the available payment gateways support purchasing multiple subscriptions with different billing schedules in a single order.', 'invoicing'), |
|
110 | 110 | 'type' => 'danger', |
111 | 111 | ) |
112 | 112 | ); |
@@ -117,14 +117,14 @@ discard block |
||
117 | 117 | <?php |
118 | 118 | echo aui()->alert( |
119 | 119 | array( |
120 | - 'content' => __( 'There is no active payment gateway available to process your request.', 'invoicing' ), |
|
120 | + 'content' => __('There is no active payment gateway available to process your request.', 'invoicing'), |
|
121 | 121 | 'type' => 'danger', |
122 | 122 | ) |
123 | 123 | ); |
124 | 124 | ?> |
125 | 125 | </div> |
126 | 126 | |
127 | - <?php do_action( 'wpinv_payment_mode_bottom', $invoice_id, $chosen_gateway, $gateways, $form ); ?> |
|
127 | + <?php do_action('wpinv_payment_mode_bottom', $invoice_id, $chosen_gateway, $gateways, $form); ?> |
|
128 | 128 | |
129 | 129 | </div> |
130 | - <?php do_action( 'getpaid_after_payment_form_gateway_select', $form ); ?> |
|
130 | + <?php do_action('getpaid_after_payment_form_gateway_select', $form); ?> |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Manual Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
27 | + protected $supports = array('subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -39,10 +39,10 @@ discard block |
||
39 | 39 | public function __construct() { |
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | - $this->title = __( 'Test Gateway', 'invoicing' ); |
|
43 | - $this->method_title = __( 'Test Gateway', 'invoicing' ); |
|
42 | + $this->title = __('Test Gateway', 'invoicing'); |
|
43 | + $this->method_title = __('Test Gateway', 'invoicing'); |
|
44 | 44 | |
45 | - add_filter( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 ); |
|
45 | + add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -54,25 +54,25 @@ discard block |
||
54 | 54 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
55 | 55 | * @return array |
56 | 56 | */ |
57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
57 | + public function process_payment($invoice, $submission_data, $submission) { |
|
58 | 58 | |
59 | 59 | // Mark it as paid. |
60 | 60 | $invoice->mark_paid(); |
61 | 61 | |
62 | 62 | // (Maybe) activate subscriptions. |
63 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
63 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
64 | 64 | |
65 | - if ( ! empty( $subscriptions ) ) { |
|
66 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
65 | + if (!empty($subscriptions)) { |
|
66 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
67 | 67 | |
68 | - foreach ( $subscriptions as $subscription ) { |
|
69 | - if ( $subscription->exists() ) { |
|
70 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
71 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
68 | + foreach ($subscriptions as $subscription) { |
|
69 | + if ($subscription->exists()) { |
|
70 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
71 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
72 | 72 | |
73 | - $subscription->set_next_renewal_date( $expiry ); |
|
74 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
75 | - $subscription->set_profile_id( $invoice->generate_key( 'manual_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) ); |
|
73 | + $subscription->set_next_renewal_date($expiry); |
|
74 | + $subscription->set_date_created(current_time('mysql')); |
|
75 | + $subscription->set_profile_id($invoice->generate_key('manual_sub_' . $invoice->get_id() . '_' . $subscription->get_id())); |
|
76 | 76 | $subscription->activate(); |
77 | 77 | } |
78 | 78 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | } |
81 | 81 | |
82 | 82 | // Send to the success page. |
83 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
83 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
84 | 84 | |
85 | 85 | } |
86 | 86 | |
@@ -91,15 +91,15 @@ discard block |
||
91 | 91 | * @param bool $should_expire |
92 | 92 | * @param WPInv_Subscription $subscription |
93 | 93 | */ |
94 | - public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
94 | + public function maybe_renew_subscription($should_expire, $subscription) { |
|
95 | 95 | |
96 | 96 | // Ensure its our subscription && it's active. |
97 | - if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
|
97 | + if ($this->id != $subscription->get_gateway() || !$subscription->has_status('active trialling')) { |
|
98 | 98 | return $should_expire; |
99 | 99 | } |
100 | 100 | |
101 | 101 | // If this is the last renewal, complete the subscription. |
102 | - if ( $subscription->is_last_renewal() ) { |
|
102 | + if ($subscription->is_last_renewal()) { |
|
103 | 103 | $subscription->complete(); |
104 | 104 | return false; |
105 | 105 | } |
@@ -125,10 +125,10 @@ discard block |
||
125 | 125 | * @param GetPaid_Form_Item[] $items |
126 | 126 | * @return WPInv_Invoice |
127 | 127 | */ |
128 | - public function process_addons( $invoice, $items ) { |
|
128 | + public function process_addons($invoice, $items) { |
|
129 | 129 | |
130 | - foreach ( $items as $item ) { |
|
131 | - $invoice->add_item( $item ); |
|
130 | + foreach ($items as $item) { |
|
131 | + $invoice->add_item($item); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | $invoice->recalculate_total(); |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * WPInv_Ajax class. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | * Hook in ajax handlers. |
18 | 18 | */ |
19 | 19 | public static function init() { |
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
20 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
21 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
22 | 22 | self::add_ajax_events(); |
23 | 23 | } |
24 | 24 | |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public static function define_ajax() { |
29 | 29 | |
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
30 | + if (!empty($_GET['wpinv-ajax'])) { |
|
31 | + getpaid_maybe_define_constant('DOING_AJAX', true); |
|
32 | + getpaid_maybe_define_constant('WPInv_DOING_AJAX', true); |
|
33 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
35 | 35 | } |
36 | 36 | $GLOBALS['wpdb']->hide_errors(); |
37 | 37 | } |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | * @since 1.0.18 |
45 | 45 | */ |
46 | 46 | private static function wpinv_ajax_headers() { |
47 | - if ( ! headers_sent() ) { |
|
47 | + if (!headers_sent()) { |
|
48 | 48 | send_origin_headers(); |
49 | 49 | send_nosniff_header(); |
50 | 50 | nocache_headers(); |
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
51 | + header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
52 | + header('X-Robots-Tag: noindex'); |
|
53 | + status_header(200); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | public static function do_wpinv_ajax() { |
61 | 61 | global $wp_query; |
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
63 | + if (!empty($_GET['wpinv-ajax'])) { |
|
64 | + $wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax']))); |
|
65 | 65 | } |
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get('wpinv-ajax'); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
69 | + if ($action) { |
|
70 | 70 | self::wpinv_ajax_headers(); |
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
71 | + $action = sanitize_text_field($action); |
|
72 | + do_action('wpinv_ajax_' . $action); |
|
73 | 73 | wp_die(); |
74 | 74 | } |
75 | 75 | |
@@ -102,36 +102,36 @@ discard block |
||
102 | 102 | 'payment_form_refresh_prices' => true, |
103 | 103 | ); |
104 | 104 | |
105 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
106 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
107 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
105 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
106 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
107 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
108 | 108 | |
109 | - if ( $nopriv ) { |
|
110 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
111 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
112 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
109 | + if ($nopriv) { |
|
110 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
111 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
112 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
117 | 117 | public static function add_note() { |
118 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
118 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
119 | 119 | |
120 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
120 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
121 | 121 | die(-1); |
122 | 122 | } |
123 | 123 | |
124 | - $post_id = absint( $_POST['post_id'] ); |
|
125 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
126 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
124 | + $post_id = absint($_POST['post_id']); |
|
125 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
126 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
127 | 127 | |
128 | 128 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
129 | 129 | |
130 | - if ( $post_id > 0 ) { |
|
131 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
130 | + if ($post_id > 0) { |
|
131 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
132 | 132 | |
133 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
134 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
133 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
134 | + wpinv_get_invoice_note_line_item($note_id); |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
@@ -139,16 +139,16 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | public static function delete_note() { |
142 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
142 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
143 | 143 | |
144 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
144 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
145 | 145 | die(-1); |
146 | 146 | } |
147 | 147 | |
148 | - $note_id = (int)$_POST['note_id']; |
|
148 | + $note_id = (int) $_POST['note_id']; |
|
149 | 149 | |
150 | - if ( $note_id > 0 ) { |
|
151 | - wp_delete_comment( $note_id, true ); |
|
150 | + if ($note_id > 0) { |
|
151 | + wp_delete_comment($note_id, true); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | die(); |
@@ -166,34 +166,34 @@ discard block |
||
166 | 166 | public static function get_billing_details() { |
167 | 167 | |
168 | 168 | // Verify nonce. |
169 | - check_ajax_referer( 'wpinv-nonce' ); |
|
169 | + check_ajax_referer('wpinv-nonce'); |
|
170 | 170 | |
171 | 171 | // Can the user manage the plugin? |
172 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
172 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
173 | 173 | die(-1); |
174 | 174 | } |
175 | 175 | |
176 | 176 | // Do we have a user id? |
177 | 177 | $user_id = $_GET['user_id']; |
178 | 178 | |
179 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
179 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
180 | 180 | die(-1); |
181 | 181 | } |
182 | 182 | |
183 | 183 | // Fetch the billing details. |
184 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
185 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
184 | + $billing_details = wpinv_get_user_address($user_id); |
|
185 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
186 | 186 | |
187 | 187 | // unset the user id and email. |
188 | - $to_ignore = array( 'user_id', 'email' ); |
|
188 | + $to_ignore = array('user_id', 'email'); |
|
189 | 189 | |
190 | - foreach ( $to_ignore as $key ) { |
|
191 | - if ( isset( $billing_details[ $key ] ) ) { |
|
192 | - unset( $billing_details[ $key ] ); |
|
190 | + foreach ($to_ignore as $key) { |
|
191 | + if (isset($billing_details[$key])) { |
|
192 | + unset($billing_details[$key]); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
196 | - wp_send_json_success( $billing_details ); |
|
196 | + wp_send_json_success($billing_details); |
|
197 | 197 | |
198 | 198 | } |
199 | 199 | |
@@ -203,47 +203,47 @@ discard block |
||
203 | 203 | public static function check_new_user_email() { |
204 | 204 | |
205 | 205 | // Verify nonce. |
206 | - check_ajax_referer( 'wpinv-nonce' ); |
|
206 | + check_ajax_referer('wpinv-nonce'); |
|
207 | 207 | |
208 | 208 | // Can the user manage the plugin? |
209 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
209 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
210 | 210 | die(-1); |
211 | 211 | } |
212 | 212 | |
213 | 213 | // We need an email address. |
214 | - if ( empty( $_GET['email'] ) ) { |
|
215 | - _e( "Provide the new user's email address", 'invoicing' ); |
|
214 | + if (empty($_GET['email'])) { |
|
215 | + _e("Provide the new user's email address", 'invoicing'); |
|
216 | 216 | exit; |
217 | 217 | } |
218 | 218 | |
219 | 219 | // Ensure the email is valid. |
220 | - $email = sanitize_text_field( $_GET['email'] ); |
|
221 | - if ( ! is_email( $email ) ) { |
|
222 | - _e( 'Invalid email address', 'invoicing' ); |
|
220 | + $email = sanitize_text_field($_GET['email']); |
|
221 | + if (!is_email($email)) { |
|
222 | + _e('Invalid email address', 'invoicing'); |
|
223 | 223 | exit; |
224 | 224 | } |
225 | 225 | |
226 | 226 | // And it does not exist. |
227 | - if ( email_exists( $email ) ) { |
|
228 | - _e( 'A user with this email address already exists', 'invoicing' ); |
|
227 | + if (email_exists($email)) { |
|
228 | + _e('A user with this email address already exists', 'invoicing'); |
|
229 | 229 | exit; |
230 | 230 | } |
231 | 231 | |
232 | - wp_send_json_success( true ); |
|
232 | + wp_send_json_success(true); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | public static function run_tool() { |
236 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
237 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
236 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
237 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
238 | 238 | die(-1); |
239 | 239 | } |
240 | 240 | |
241 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
241 | + $tool = sanitize_text_field($_POST['tool']); |
|
242 | 242 | |
243 | - do_action( 'wpinv_run_tool' ); |
|
243 | + do_action('wpinv_run_tool'); |
|
244 | 244 | |
245 | - if ( !empty( $tool ) ) { |
|
246 | - do_action( 'wpinv_tool_' . $tool ); |
|
245 | + if (!empty($tool)) { |
|
246 | + do_action('wpinv_tool_' . $tool); |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | |
@@ -253,27 +253,27 @@ discard block |
||
253 | 253 | public static function get_payment_form() { |
254 | 254 | |
255 | 255 | // Check nonce. |
256 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
256 | + check_ajax_referer('getpaid_form_nonce'); |
|
257 | 257 | |
258 | 258 | // Is the request set up correctly? |
259 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
259 | + if (empty($_GET['form']) && empty($_GET['item'])) { |
|
260 | 260 | echo aui()->alert( |
261 | 261 | array( |
262 | 262 | 'type' => 'warning', |
263 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
263 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
264 | 264 | ) |
265 | 265 | ); |
266 | 266 | exit; |
267 | 267 | } |
268 | 268 | |
269 | 269 | // Payment form or button? |
270 | - if ( ! empty( $_GET['form'] ) ) { |
|
271 | - getpaid_display_payment_form( urldecode( $_GET['form'] ) ); |
|
272 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
273 | - getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) ); |
|
270 | + if (!empty($_GET['form'])) { |
|
271 | + getpaid_display_payment_form(urldecode($_GET['form'])); |
|
272 | + } else if (!empty($_GET['invoice'])) { |
|
273 | + getpaid_display_invoice_payment_form(urldecode($_GET['invoice'])); |
|
274 | 274 | } else { |
275 | - $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) ); |
|
276 | - getpaid_display_item_payment_form( $items ); |
|
275 | + $items = getpaid_convert_items_to_array(urldecode($_GET['item'])); |
|
276 | + getpaid_display_item_payment_form($items); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | exit; |
@@ -288,17 +288,17 @@ discard block |
||
288 | 288 | public static function payment_form() { |
289 | 289 | |
290 | 290 | // Check nonce. |
291 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
291 | + check_ajax_referer('getpaid_form_nonce'); |
|
292 | 292 | |
293 | 293 | // ... form fields... |
294 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
295 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
294 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
295 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
296 | 296 | exit; |
297 | 297 | } |
298 | 298 | |
299 | 299 | // Process the payment form. |
300 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
301 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
300 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
301 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
302 | 302 | $checkout->process_checkout(); |
303 | 303 | |
304 | 304 | exit; |
@@ -311,55 +311,55 @@ discard block |
||
311 | 311 | */ |
312 | 312 | public static function get_payment_form_states_field() { |
313 | 313 | |
314 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
314 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
315 | 315 | exit; |
316 | 316 | } |
317 | 317 | |
318 | - $elements = getpaid_get_payment_form_elements( $_GET['form'] ); |
|
318 | + $elements = getpaid_get_payment_form_elements($_GET['form']); |
|
319 | 319 | |
320 | - if ( empty( $elements ) ) { |
|
320 | + if (empty($elements)) { |
|
321 | 321 | exit; |
322 | 322 | } |
323 | 323 | |
324 | 324 | $address_fields = array(); |
325 | - foreach ( $elements as $element ) { |
|
326 | - if ( 'address' === $element['type'] ) { |
|
325 | + foreach ($elements as $element) { |
|
326 | + if ('address' === $element['type']) { |
|
327 | 327 | $address_fields = $element; |
328 | 328 | break; |
329 | 329 | } |
330 | 330 | } |
331 | 331 | |
332 | - if ( empty( $address_fields ) ) { |
|
332 | + if (empty($address_fields)) { |
|
333 | 333 | exit; |
334 | 334 | } |
335 | 335 | |
336 | - foreach ( $address_fields['fields'] as $address_field ) { |
|
336 | + foreach ($address_fields['fields'] as $address_field) { |
|
337 | 337 | |
338 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
338 | + if ('wpinv_state' == $address_field['name']) { |
|
339 | 339 | |
340 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
341 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
342 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
343 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
344 | - $value = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : ''; |
|
345 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
340 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
341 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
342 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
343 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
344 | + $value = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : ''; |
|
345 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
346 | 346 | |
347 | - if ( ! empty( $address_field['required'] ) ) { |
|
347 | + if (!empty($address_field['required'])) { |
|
348 | 348 | $label .= "<span class='text-danger'> *</span>"; |
349 | 349 | } |
350 | 350 | |
351 | - $html = getpaid_get_states_select_markup ( |
|
352 | - sanitize_text_field( $_GET['country'] ), |
|
351 | + $html = getpaid_get_states_select_markup( |
|
352 | + sanitize_text_field($_GET['country']), |
|
353 | 353 | $value, |
354 | 354 | $placeholder, |
355 | 355 | $label, |
356 | 356 | $description, |
357 | - ! empty( $address_field['required'] ), |
|
357 | + !empty($address_field['required']), |
|
358 | 358 | $wrap_class, |
359 | - wpinv_clean( $_GET['name'] ) |
|
359 | + wpinv_clean($_GET['name']) |
|
360 | 360 | ); |
361 | 361 | |
362 | - wp_send_json_success( $html ); |
|
362 | + wp_send_json_success($html); |
|
363 | 363 | exit; |
364 | 364 | |
365 | 365 | } |
@@ -375,66 +375,66 @@ discard block |
||
375 | 375 | public static function recalculate_invoice_totals() { |
376 | 376 | |
377 | 377 | // Verify nonce. |
378 | - check_ajax_referer( 'wpinv-nonce' ); |
|
378 | + check_ajax_referer('wpinv-nonce'); |
|
379 | 379 | |
380 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
380 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
381 | 381 | exit; |
382 | 382 | } |
383 | 383 | |
384 | 384 | // We need an invoice. |
385 | - if ( empty( $_POST['post_id'] ) ) { |
|
385 | + if (empty($_POST['post_id'])) { |
|
386 | 386 | exit; |
387 | 387 | } |
388 | 388 | |
389 | 389 | // Fetch the invoice. |
390 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
390 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
391 | 391 | |
392 | 392 | // Ensure it exists. |
393 | - if ( ! $invoice->get_id() ) { |
|
393 | + if (!$invoice->get_id()) { |
|
394 | 394 | exit; |
395 | 395 | } |
396 | 396 | |
397 | 397 | // Maybe set the country, state, currency. |
398 | - foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) { |
|
399 | - if ( isset( $_POST[ $key ] ) ) { |
|
398 | + foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) { |
|
399 | + if (isset($_POST[$key])) { |
|
400 | 400 | $method = "set_$key"; |
401 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
401 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
402 | 402 | } |
403 | 403 | } |
404 | 404 | |
405 | 405 | // Maybe disable taxes. |
406 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
406 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
407 | 407 | |
408 | 408 | // Discount code. |
409 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
410 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
411 | - if ( $discount->exists() ) { |
|
412 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
409 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
410 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
411 | + if ($discount->exists()) { |
|
412 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
413 | 413 | } else { |
414 | - $invoice->remove_discount( 'discount_code' ); |
|
414 | + $invoice->remove_discount('discount_code'); |
|
415 | 415 | } |
416 | 416 | } |
417 | 417 | |
418 | 418 | // Recalculate totals. |
419 | 419 | $invoice->recalculate_total(); |
420 | 420 | |
421 | - $total = wpinv_price( $invoice->get_total(), $invoice->get_currency() ); |
|
422 | - $suscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
423 | - if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
424 | - $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() ); |
|
425 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
421 | + $total = wpinv_price($invoice->get_total(), $invoice->get_currency()); |
|
422 | + $suscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
423 | + if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
424 | + $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency()); |
|
425 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | $totals = array( |
429 | - 'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
|
430 | - 'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
431 | - 'tax' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
|
429 | + 'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()), |
|
430 | + 'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
431 | + 'tax' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()), |
|
432 | 432 | 'total' => $total, |
433 | 433 | ); |
434 | 434 | |
435 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
435 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
436 | 436 | |
437 | - wp_send_json_success( compact( 'totals' ) ); |
|
437 | + wp_send_json_success(compact('totals')); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | /** |
@@ -443,33 +443,33 @@ discard block |
||
443 | 443 | public static function get_invoice_items() { |
444 | 444 | |
445 | 445 | // Verify nonce. |
446 | - check_ajax_referer( 'wpinv-nonce' ); |
|
446 | + check_ajax_referer('wpinv-nonce'); |
|
447 | 447 | |
448 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
448 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
449 | 449 | exit; |
450 | 450 | } |
451 | 451 | |
452 | 452 | // We need an invoice and items. |
453 | - if ( empty( $_POST['post_id'] ) ) { |
|
453 | + if (empty($_POST['post_id'])) { |
|
454 | 454 | exit; |
455 | 455 | } |
456 | 456 | |
457 | 457 | // Fetch the invoice. |
458 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
458 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
459 | 459 | |
460 | 460 | // Ensure it exists. |
461 | - if ( ! $invoice->get_id() ) { |
|
461 | + if (!$invoice->get_id()) { |
|
462 | 462 | exit; |
463 | 463 | } |
464 | 464 | |
465 | 465 | // Return an array of invoice items. |
466 | 466 | $items = array(); |
467 | 467 | |
468 | - foreach ( $invoice->get_items() as $item ) { |
|
469 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() ); |
|
468 | + foreach ($invoice->get_items() as $item) { |
|
469 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal()); |
|
470 | 470 | } |
471 | 471 | |
472 | - wp_send_json_success( compact( 'items' ) ); |
|
472 | + wp_send_json_success(compact('items')); |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | /** |
@@ -478,50 +478,50 @@ discard block |
||
478 | 478 | public static function edit_invoice_item() { |
479 | 479 | |
480 | 480 | // Verify nonce. |
481 | - check_ajax_referer( 'wpinv-nonce' ); |
|
481 | + check_ajax_referer('wpinv-nonce'); |
|
482 | 482 | |
483 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
483 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
484 | 484 | exit; |
485 | 485 | } |
486 | 486 | |
487 | 487 | // We need an invoice and item details. |
488 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
488 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
489 | 489 | exit; |
490 | 490 | } |
491 | 491 | |
492 | 492 | // Fetch the invoice. |
493 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
493 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
494 | 494 | |
495 | 495 | // Ensure it exists and its not been paid for. |
496 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
496 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
497 | 497 | exit; |
498 | 498 | } |
499 | 499 | |
500 | 500 | // Format the data. |
501 | - $data = wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ); |
|
501 | + $data = wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field')); |
|
502 | 502 | |
503 | 503 | // Ensure that we have an item id. |
504 | - if ( empty( $data['id'] ) ) { |
|
504 | + if (empty($data['id'])) { |
|
505 | 505 | exit; |
506 | 506 | } |
507 | 507 | |
508 | 508 | // Abort if the invoice does not have the specified item. |
509 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
509 | + $item = $invoice->get_item((int) $data['id']); |
|
510 | 510 | |
511 | - if ( empty( $item ) ) { |
|
511 | + if (empty($item)) { |
|
512 | 512 | exit; |
513 | 513 | } |
514 | 514 | |
515 | 515 | // Update the item. |
516 | - $item->set_price( floatval( $data['price'] ) ); |
|
517 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
518 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
519 | - $item->set_quantity( floatval( $data['quantity'] ) ); |
|
516 | + $item->set_price(floatval($data['price'])); |
|
517 | + $item->set_name(sanitize_text_field($data['name'])); |
|
518 | + $item->set_description(wp_kses_post($data['description'])); |
|
519 | + $item->set_quantity(floatval($data['quantity'])); |
|
520 | 520 | |
521 | 521 | // Add it to the invoice. |
522 | - $error = $invoice->add_item( $item ); |
|
522 | + $error = $invoice->add_item($item); |
|
523 | 523 | $alert = false; |
524 | - if ( is_wp_error( $error ) ) { |
|
524 | + if (is_wp_error($error)) { |
|
525 | 525 | $alert = $error->get_error_message(); |
526 | 526 | } |
527 | 527 | |
@@ -534,11 +534,11 @@ discard block |
||
534 | 534 | // Return an array of invoice items. |
535 | 535 | $items = array(); |
536 | 536 | |
537 | - foreach ( $invoice->get_items() as $item ) { |
|
538 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
537 | + foreach ($invoice->get_items() as $item) { |
|
538 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
539 | 539 | } |
540 | 540 | |
541 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
541 | + wp_send_json_success(compact('items', 'alert')); |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | /** |
@@ -547,33 +547,33 @@ discard block |
||
547 | 547 | public static function remove_invoice_item() { |
548 | 548 | |
549 | 549 | // Verify nonce. |
550 | - check_ajax_referer( 'wpinv-nonce' ); |
|
550 | + check_ajax_referer('wpinv-nonce'); |
|
551 | 551 | |
552 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
552 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
553 | 553 | exit; |
554 | 554 | } |
555 | 555 | |
556 | 556 | // We need an invoice and an item. |
557 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
557 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
558 | 558 | exit; |
559 | 559 | } |
560 | 560 | |
561 | 561 | // Fetch the invoice. |
562 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
562 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
563 | 563 | |
564 | 564 | // Ensure it exists and its not been paid for. |
565 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
565 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
566 | 566 | exit; |
567 | 567 | } |
568 | 568 | |
569 | 569 | // Abort if the invoice does not have the specified item. |
570 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
570 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
571 | 571 | |
572 | - if ( empty( $item ) ) { |
|
572 | + if (empty($item)) { |
|
573 | 573 | exit; |
574 | 574 | } |
575 | 575 | |
576 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
576 | + $invoice->remove_item((int) $_POST['item_id']); |
|
577 | 577 | |
578 | 578 | // Update totals. |
579 | 579 | $invoice->recalculate_total(); |
@@ -584,11 +584,11 @@ discard block |
||
584 | 584 | // Return an array of invoice items. |
585 | 585 | $items = array(); |
586 | 586 | |
587 | - foreach ( $invoice->get_items() as $item ) { |
|
588 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
587 | + foreach ($invoice->get_items() as $item) { |
|
588 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
589 | 589 | } |
590 | 590 | |
591 | - wp_send_json_success( compact( 'items' ) ); |
|
591 | + wp_send_json_success(compact('items')); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | /** |
@@ -597,39 +597,39 @@ discard block |
||
597 | 597 | public static function add_invoice_items() { |
598 | 598 | |
599 | 599 | // Verify nonce. |
600 | - check_ajax_referer( 'wpinv-nonce' ); |
|
600 | + check_ajax_referer('wpinv-nonce'); |
|
601 | 601 | |
602 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
602 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
603 | 603 | exit; |
604 | 604 | } |
605 | 605 | |
606 | 606 | // We need an invoice and items. |
607 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
607 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
608 | 608 | exit; |
609 | 609 | } |
610 | 610 | |
611 | 611 | // Fetch the invoice. |
612 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
612 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
613 | 613 | $alert = false; |
614 | 614 | |
615 | 615 | // Ensure it exists and its not been paid for. |
616 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
616 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
617 | 617 | exit; |
618 | 618 | } |
619 | 619 | |
620 | 620 | // Add the items. |
621 | - foreach ( $_POST['items'] as $data ) { |
|
621 | + foreach ($_POST['items'] as $data) { |
|
622 | 622 | |
623 | - $item = new GetPaid_Form_Item( $data[ 'id' ] ); |
|
623 | + $item = new GetPaid_Form_Item($data['id']); |
|
624 | 624 | |
625 | - if ( is_numeric( $data[ 'qty' ] ) && (float) $data[ 'qty' ] > 0 ) { |
|
626 | - $item->set_quantity( $data[ 'qty' ] ); |
|
625 | + if (is_numeric($data['qty']) && (float) $data['qty'] > 0) { |
|
626 | + $item->set_quantity($data['qty']); |
|
627 | 627 | } |
628 | 628 | |
629 | - if ( $item->get_id() > 0 ) { |
|
630 | - $error = $invoice->add_item( $item ); |
|
629 | + if ($item->get_id() > 0) { |
|
630 | + $error = $invoice->add_item($item); |
|
631 | 631 | |
632 | - if ( is_wp_error( $error ) ) { |
|
632 | + if (is_wp_error($error)) { |
|
633 | 633 | $alert = $error->get_error_message(); |
634 | 634 | } |
635 | 635 | |
@@ -644,11 +644,11 @@ discard block |
||
644 | 644 | // Return an array of invoice items. |
645 | 645 | $items = array(); |
646 | 646 | |
647 | - foreach ( $invoice->get_items() as $item ) { |
|
648 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
647 | + foreach ($invoice->get_items() as $item) { |
|
648 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
649 | 649 | } |
650 | 650 | |
651 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
651 | + wp_send_json_success(compact('items', 'alert')); |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | /** |
@@ -657,15 +657,15 @@ discard block |
||
657 | 657 | public static function get_invoicing_items() { |
658 | 658 | |
659 | 659 | // Verify nonce. |
660 | - check_ajax_referer( 'wpinv-nonce' ); |
|
660 | + check_ajax_referer('wpinv-nonce'); |
|
661 | 661 | |
662 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
662 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
663 | 663 | exit; |
664 | 664 | } |
665 | 665 | |
666 | 666 | // We need a search term. |
667 | - if ( empty( $_GET['search'] ) ) { |
|
668 | - wp_send_json_success( array() ); |
|
667 | + if (empty($_GET['search'])) { |
|
668 | + wp_send_json_success(array()); |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | // Retrieve items. |
@@ -674,8 +674,8 @@ discard block |
||
674 | 674 | 'orderby' => 'title', |
675 | 675 | 'order' => 'ASC', |
676 | 676 | 'posts_per_page' => -1, |
677 | - 'post_status' => array( 'publish' ), |
|
678 | - 's' => trim( $_GET['search'] ), |
|
677 | + 'post_status' => array('publish'), |
|
678 | + 's' => trim($_GET['search']), |
|
679 | 679 | 'meta_query' => array( |
680 | 680 | array( |
681 | 681 | 'key' => '_wpinv_type', |
@@ -685,22 +685,22 @@ discard block |
||
685 | 685 | ) |
686 | 686 | ); |
687 | 687 | |
688 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
688 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
689 | 689 | $data = array(); |
690 | 690 | |
691 | 691 | |
692 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) ); |
|
692 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id'])); |
|
693 | 693 | |
694 | - foreach ( $items as $item ) { |
|
695 | - $item = new GetPaid_Form_Item( $item ); |
|
694 | + foreach ($items as $item) { |
|
695 | + $item = new GetPaid_Form_Item($item); |
|
696 | 696 | $data[] = array( |
697 | 697 | 'id' => (int) $item->get_id(), |
698 | - 'text' => strip_tags( $item->get_name() ), |
|
699 | - 'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '', |
|
698 | + 'text' => strip_tags($item->get_name()), |
|
699 | + 'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '', |
|
700 | 700 | ); |
701 | 701 | } |
702 | 702 | |
703 | - wp_send_json_success( $data ); |
|
703 | + wp_send_json_success($data); |
|
704 | 704 | |
705 | 705 | } |
706 | 706 | |
@@ -710,37 +710,37 @@ discard block |
||
710 | 710 | public static function get_customers() { |
711 | 711 | |
712 | 712 | // Verify nonce. |
713 | - check_ajax_referer( 'wpinv-nonce' ); |
|
713 | + check_ajax_referer('wpinv-nonce'); |
|
714 | 714 | |
715 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
715 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
716 | 716 | exit; |
717 | 717 | } |
718 | 718 | |
719 | 719 | // We need a search term. |
720 | - if ( empty( $_GET['search'] ) ) { |
|
721 | - wp_send_json_success( array() ); |
|
720 | + if (empty($_GET['search'])) { |
|
721 | + wp_send_json_success(array()); |
|
722 | 722 | } |
723 | 723 | |
724 | 724 | // Retrieve customers. |
725 | 725 | |
726 | 726 | $customer_args = array( |
727 | - 'fields' => array( 'ID', 'user_email', 'display_name' ), |
|
727 | + 'fields' => array('ID', 'user_email', 'display_name'), |
|
728 | 728 | 'orderby' => 'display_name', |
729 | - 'search' => '*' . sanitize_text_field( $_GET['search'] ) . '*', |
|
730 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
729 | + 'search' => '*' . sanitize_text_field($_GET['search']) . '*', |
|
730 | + 'search_columns' => array('user_login', 'user_email', 'display_name'), |
|
731 | 731 | ); |
732 | 732 | |
733 | - $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) ); |
|
733 | + $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args)); |
|
734 | 734 | $data = array(); |
735 | 735 | |
736 | - foreach ( $customers as $customer ) { |
|
736 | + foreach ($customers as $customer) { |
|
737 | 737 | $data[] = array( |
738 | 738 | 'id' => (int) $customer->ID, |
739 | - 'text' => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ), |
|
739 | + 'text' => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)), |
|
740 | 740 | ); |
741 | 741 | } |
742 | 742 | |
743 | - wp_send_json_success( $data ); |
|
743 | + wp_send_json_success($data); |
|
744 | 744 | |
745 | 745 | } |
746 | 746 | |
@@ -750,28 +750,28 @@ discard block |
||
750 | 750 | public static function get_aui_states_field() { |
751 | 751 | |
752 | 752 | // Verify nonce. |
753 | - check_ajax_referer( 'wpinv-nonce' ); |
|
753 | + check_ajax_referer('wpinv-nonce'); |
|
754 | 754 | |
755 | 755 | // We need a country. |
756 | - if ( empty( $_GET['country'] ) ) { |
|
756 | + if (empty($_GET['country'])) { |
|
757 | 757 | exit; |
758 | 758 | } |
759 | 759 | |
760 | - $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) ); |
|
761 | - $state = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state(); |
|
762 | - $name = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state'; |
|
763 | - $class = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm'; |
|
760 | + $states = wpinv_get_country_states(sanitize_text_field($_GET['country'])); |
|
761 | + $state = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state(); |
|
762 | + $name = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state'; |
|
763 | + $class = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm'; |
|
764 | 764 | |
765 | - if ( empty( $states ) ) { |
|
765 | + if (empty($states)) { |
|
766 | 766 | |
767 | 767 | $html = aui()->input( |
768 | 768 | array( |
769 | 769 | 'type' => 'text', |
770 | 770 | 'id' => 'wpinv_state', |
771 | 771 | 'name' => $name, |
772 | - 'label' => __( 'State', 'invoicing' ), |
|
772 | + 'label' => __('State', 'invoicing'), |
|
773 | 773 | 'label_type' => 'vertical', |
774 | - 'placeholder' => __( 'State', 'invoicing' ), |
|
774 | + 'placeholder' => __('State', 'invoicing'), |
|
775 | 775 | 'class' => $class, |
776 | 776 | 'value' => $state, |
777 | 777 | ) |
@@ -783,9 +783,9 @@ discard block |
||
783 | 783 | array( |
784 | 784 | 'id' => 'wpinv_state', |
785 | 785 | 'name' => $name, |
786 | - 'label' => __( 'State', 'invoicing' ), |
|
786 | + 'label' => __('State', 'invoicing'), |
|
787 | 787 | 'label_type' => 'vertical', |
788 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
788 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
789 | 789 | 'class' => $class, |
790 | 790 | 'value' => $state, |
791 | 791 | 'options' => $states, |
@@ -799,7 +799,7 @@ discard block |
||
799 | 799 | wp_send_json_success( |
800 | 800 | array( |
801 | 801 | 'html' => $html, |
802 | - 'select' => ! empty ( $states ) |
|
802 | + 'select' => !empty ($states) |
|
803 | 803 | ) |
804 | 804 | ); |
805 | 805 | |
@@ -813,11 +813,11 @@ discard block |
||
813 | 813 | public static function payment_form_refresh_prices() { |
814 | 814 | |
815 | 815 | // Check nonce. |
816 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
816 | + check_ajax_referer('getpaid_form_nonce'); |
|
817 | 817 | |
818 | 818 | // ... form fields... |
819 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
820 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
819 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
820 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
821 | 821 | exit; |
822 | 822 | } |
823 | 823 | |
@@ -825,7 +825,7 @@ discard block |
||
825 | 825 | $submission = new GetPaid_Payment_Form_Submission(); |
826 | 826 | |
827 | 827 | // Do we have an error? |
828 | - if ( ! empty( $submission->last_error ) ) { |
|
828 | + if (!empty($submission->last_error)) { |
|
829 | 829 | wp_send_json_error( |
830 | 830 | array( |
831 | 831 | 'code' => $submission->last_error_code, |
@@ -835,12 +835,12 @@ discard block |
||
835 | 835 | } |
836 | 836 | |
837 | 837 | // Prepare the response. |
838 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
838 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
839 | 839 | |
840 | 840 | // Filter the response. |
841 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
841 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
842 | 842 | |
843 | - wp_send_json_success( $response ); |
|
843 | + wp_send_json_success($response); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -78,30 +78,30 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @param int|object|WPInv_Item|WP_Post $item Item to read. |
80 | 80 | */ |
81 | - public function __construct( $item = 0 ) { |
|
82 | - parent::__construct( $item ); |
|
83 | - |
|
84 | - if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
85 | - $this->set_id( $item ); |
|
86 | - } elseif ( $item instanceof self ) { |
|
87 | - $this->set_id( $item->get_id() ); |
|
88 | - } elseif ( ! empty( $item->ID ) ) { |
|
89 | - $this->set_id( $item->ID ); |
|
90 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
91 | - $this->set_id( $item_id ); |
|
92 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
93 | - $this->set_id( $item_id ); |
|
81 | + public function __construct($item = 0) { |
|
82 | + parent::__construct($item); |
|
83 | + |
|
84 | + if (!empty($item) && is_numeric($item) && 'wpi_item' == get_post_type($item)) { |
|
85 | + $this->set_id($item); |
|
86 | + } elseif ($item instanceof self) { |
|
87 | + $this->set_id($item->get_id()); |
|
88 | + } elseif (!empty($item->ID)) { |
|
89 | + $this->set_id($item->ID); |
|
90 | + } elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'custom_id')) { |
|
91 | + $this->set_id($item_id); |
|
92 | + } elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'name')) { |
|
93 | + $this->set_id($item_id); |
|
94 | 94 | } else { |
95 | - $this->set_object_read( true ); |
|
95 | + $this->set_object_read(true); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | // Load the datastore. |
99 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
99 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
100 | 100 | |
101 | - if ( $this->get_id() > 0 ) { |
|
102 | - $this->post = get_post( $this->get_id() ); |
|
101 | + if ($this->get_id() > 0) { |
|
102 | + $this->post = get_post($this->get_id()); |
|
103 | 103 | $this->ID = $this->get_id(); |
104 | - $this->data_store->read( $this ); |
|
104 | + $this->data_store->read($this); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | } |
@@ -128,8 +128,8 @@ discard block |
||
128 | 128 | * @param string $context View or edit context. |
129 | 129 | * @return int |
130 | 130 | */ |
131 | - public function get_parent_id( $context = 'view' ) { |
|
132 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
131 | + public function get_parent_id($context = 'view') { |
|
132 | + return (int) $this->get_prop('parent_id', $context); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @param string $context View or edit context. |
140 | 140 | * @return string |
141 | 141 | */ |
142 | - public function get_status( $context = 'view' ) { |
|
143 | - return $this->get_prop( 'status', $context ); |
|
142 | + public function get_status($context = 'view') { |
|
143 | + return $this->get_prop('status', $context); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -150,8 +150,8 @@ discard block |
||
150 | 150 | * @param string $context View or edit context. |
151 | 151 | * @return string |
152 | 152 | */ |
153 | - public function get_version( $context = 'view' ) { |
|
154 | - return $this->get_prop( 'version', $context ); |
|
153 | + public function get_version($context = 'view') { |
|
154 | + return $this->get_prop('version', $context); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | * @param string $context View or edit context. |
162 | 162 | * @return string |
163 | 163 | */ |
164 | - public function get_date_created( $context = 'view' ) { |
|
165 | - return $this->get_prop( 'date_created', $context ); |
|
164 | + public function get_date_created($context = 'view') { |
|
165 | + return $this->get_prop('date_created', $context); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -172,11 +172,11 @@ discard block |
||
172 | 172 | * @param string $context View or edit context. |
173 | 173 | * @return string |
174 | 174 | */ |
175 | - public function get_date_created_gmt( $context = 'view' ) { |
|
176 | - $date = $this->get_date_created( $context ); |
|
175 | + public function get_date_created_gmt($context = 'view') { |
|
176 | + $date = $this->get_date_created($context); |
|
177 | 177 | |
178 | - if ( $date ) { |
|
179 | - $date = get_gmt_from_date( $date ); |
|
178 | + if ($date) { |
|
179 | + $date = get_gmt_from_date($date); |
|
180 | 180 | } |
181 | 181 | return $date; |
182 | 182 | } |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | * @param string $context View or edit context. |
189 | 189 | * @return string |
190 | 190 | */ |
191 | - public function get_date_modified( $context = 'view' ) { |
|
192 | - return $this->get_prop( 'date_modified', $context ); |
|
191 | + public function get_date_modified($context = 'view') { |
|
192 | + return $this->get_prop('date_modified', $context); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -199,11 +199,11 @@ discard block |
||
199 | 199 | * @param string $context View or edit context. |
200 | 200 | * @return string |
201 | 201 | */ |
202 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
203 | - $date = $this->get_date_modified( $context ); |
|
202 | + public function get_date_modified_gmt($context = 'view') { |
|
203 | + $date = $this->get_date_modified($context); |
|
204 | 204 | |
205 | - if ( $date ) { |
|
206 | - $date = get_gmt_from_date( $date ); |
|
205 | + if ($date) { |
|
206 | + $date = get_gmt_from_date($date); |
|
207 | 207 | } |
208 | 208 | return $date; |
209 | 209 | } |
@@ -215,8 +215,8 @@ discard block |
||
215 | 215 | * @param string $context View or edit context. |
216 | 216 | * @return string |
217 | 217 | */ |
218 | - public function get_name( $context = 'view' ) { |
|
219 | - return $this->get_prop( 'name', $context ); |
|
218 | + public function get_name($context = 'view') { |
|
219 | + return $this->get_prop('name', $context); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -226,8 +226,8 @@ discard block |
||
226 | 226 | * @param string $context View or edit context. |
227 | 227 | * @return string |
228 | 228 | */ |
229 | - public function get_title( $context = 'view' ) { |
|
230 | - return $this->get_name( $context ); |
|
229 | + public function get_title($context = 'view') { |
|
230 | + return $this->get_name($context); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -237,8 +237,8 @@ discard block |
||
237 | 237 | * @param string $context View or edit context. |
238 | 238 | * @return string |
239 | 239 | */ |
240 | - public function get_description( $context = 'view' ) { |
|
241 | - return $this->get_prop( 'description', $context ); |
|
240 | + public function get_description($context = 'view') { |
|
241 | + return $this->get_prop('description', $context); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -248,8 +248,8 @@ discard block |
||
248 | 248 | * @param string $context View or edit context. |
249 | 249 | * @return string |
250 | 250 | */ |
251 | - public function get_excerpt( $context = 'view' ) { |
|
252 | - return $this->get_description( $context ); |
|
251 | + public function get_excerpt($context = 'view') { |
|
252 | + return $this->get_description($context); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -259,8 +259,8 @@ discard block |
||
259 | 259 | * @param string $context View or edit context. |
260 | 260 | * @return string |
261 | 261 | */ |
262 | - public function get_summary( $context = 'view' ) { |
|
263 | - return $this->get_description( $context ); |
|
262 | + public function get_summary($context = 'view') { |
|
263 | + return $this->get_description($context); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -270,8 +270,8 @@ discard block |
||
270 | 270 | * @param string $context View or edit context. |
271 | 271 | * @return int |
272 | 272 | */ |
273 | - public function get_author( $context = 'view' ) { |
|
274 | - return (int) $this->get_prop( 'author', $context ); |
|
273 | + public function get_author($context = 'view') { |
|
274 | + return (int) $this->get_prop('author', $context); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -281,8 +281,8 @@ discard block |
||
281 | 281 | * @param string $context View or edit context. |
282 | 282 | * @return int |
283 | 283 | */ |
284 | - public function get_owner( $context = 'view' ) { |
|
285 | - return $this->get_author( $context ); |
|
284 | + public function get_owner($context = 'view') { |
|
285 | + return $this->get_author($context); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -292,8 +292,8 @@ discard block |
||
292 | 292 | * @param string $context View or edit context. |
293 | 293 | * @return float |
294 | 294 | */ |
295 | - public function get_price( $context = 'view' ) { |
|
296 | - return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
|
295 | + public function get_price($context = 'view') { |
|
296 | + return wpinv_sanitize_amount($this->get_prop('price', $context)); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
@@ -303,15 +303,15 @@ discard block |
||
303 | 303 | * @param string $context View or edit context. |
304 | 304 | * @return float |
305 | 305 | */ |
306 | - public function get_initial_price( $context = 'view' ) { |
|
306 | + public function get_initial_price($context = 'view') { |
|
307 | 307 | |
308 | - $price = (float) $this->get_price( $context ); |
|
308 | + $price = (float) $this->get_price($context); |
|
309 | 309 | |
310 | - if ( $this->has_free_trial() ) { |
|
310 | + if ($this->has_free_trial()) { |
|
311 | 311 | $price = 0; |
312 | 312 | } |
313 | 313 | |
314 | - return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) ); |
|
314 | + return wpinv_sanitize_amount(apply_filters('wpinv_get_initial_item_price', $price, $this)); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | * @return string |
323 | 323 | */ |
324 | 324 | public function get_the_price() { |
325 | - return wpinv_price( $this->get_price() ); |
|
325 | + return wpinv_price($this->get_price()); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | * @return string |
334 | 334 | */ |
335 | 335 | public function get_the_initial_price() { |
336 | - return wpinv_price( $this->get_initial_price() ); |
|
336 | + return wpinv_price($this->get_initial_price()); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
@@ -343,8 +343,8 @@ discard block |
||
343 | 343 | * @param string $context View or edit context. |
344 | 344 | * @return string |
345 | 345 | */ |
346 | - public function get_vat_rule( $context = 'view' ) { |
|
347 | - return $this->get_prop( 'vat_rule', $context ); |
|
346 | + public function get_vat_rule($context = 'view') { |
|
347 | + return $this->get_prop('vat_rule', $context); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
@@ -354,8 +354,8 @@ discard block |
||
354 | 354 | * @param string $context View or edit context. |
355 | 355 | * @return string |
356 | 356 | */ |
357 | - public function get_vat_class( $context = 'view' ) { |
|
358 | - return $this->get_prop( 'vat_class', $context ); |
|
357 | + public function get_vat_class($context = 'view') { |
|
358 | + return $this->get_prop('vat_class', $context); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
@@ -365,8 +365,8 @@ discard block |
||
365 | 365 | * @param string $context View or edit context. |
366 | 366 | * @return string |
367 | 367 | */ |
368 | - public function get_type( $context = 'view' ) { |
|
369 | - return $this->get_prop( 'type', $context ); |
|
368 | + public function get_type($context = 'view') { |
|
369 | + return $this->get_prop('type', $context); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
@@ -376,8 +376,8 @@ discard block |
||
376 | 376 | * @param string $context View or edit context. |
377 | 377 | * @return string |
378 | 378 | */ |
379 | - public function get_custom_id( $context = 'view' ) { |
|
380 | - return $this->get_prop( 'custom_id', $context ); |
|
379 | + public function get_custom_id($context = 'view') { |
|
380 | + return $this->get_prop('custom_id', $context); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
@@ -387,8 +387,8 @@ discard block |
||
387 | 387 | * @param string $context View or edit context. |
388 | 388 | * @return string |
389 | 389 | */ |
390 | - public function get_custom_name( $context = 'view' ) { |
|
391 | - return $this->get_prop( 'custom_name', $context ); |
|
390 | + public function get_custom_name($context = 'view') { |
|
391 | + return $this->get_prop('custom_name', $context); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
@@ -398,8 +398,8 @@ discard block |
||
398 | 398 | * @param string $context View or edit context. |
399 | 399 | * @return string |
400 | 400 | */ |
401 | - public function get_custom_singular_name( $context = 'view' ) { |
|
402 | - return $this->get_prop( 'custom_singular_name', $context ); |
|
401 | + public function get_custom_singular_name($context = 'view') { |
|
402 | + return $this->get_prop('custom_singular_name', $context); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -409,8 +409,8 @@ discard block |
||
409 | 409 | * @param string $context View or edit context. |
410 | 410 | * @return int |
411 | 411 | */ |
412 | - public function get_is_editable( $context = 'view' ) { |
|
413 | - return (int) $this->get_prop( 'is_editable', $context ); |
|
412 | + public function get_is_editable($context = 'view') { |
|
413 | + return (int) $this->get_prop('is_editable', $context); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -420,8 +420,8 @@ discard block |
||
420 | 420 | * @param string $context View or edit context. |
421 | 421 | * @return int |
422 | 422 | */ |
423 | - public function get_editable( $context = 'view' ) { |
|
424 | - return $this->get_is_editable( $context ); |
|
423 | + public function get_editable($context = 'view') { |
|
424 | + return $this->get_is_editable($context); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -431,8 +431,8 @@ discard block |
||
431 | 431 | * @param string $context View or edit context. |
432 | 432 | * @return int |
433 | 433 | */ |
434 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
435 | - return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
|
434 | + public function get_is_dynamic_pricing($context = 'view') { |
|
435 | + return (int) $this->get_prop('is_dynamic_pricing', $context); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
@@ -442,8 +442,8 @@ discard block |
||
442 | 442 | * @param string $context View or edit context. |
443 | 443 | * @return float |
444 | 444 | */ |
445 | - public function get_minimum_price( $context = 'view' ) { |
|
446 | - return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
|
445 | + public function get_minimum_price($context = 'view') { |
|
446 | + return wpinv_sanitize_amount($this->get_prop('minimum_price', $context)); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -453,8 +453,8 @@ discard block |
||
453 | 453 | * @param string $context View or edit context. |
454 | 454 | * @return int |
455 | 455 | */ |
456 | - public function get_is_recurring( $context = 'view' ) { |
|
457 | - return (int) $this->get_prop( 'is_recurring', $context ); |
|
456 | + public function get_is_recurring($context = 'view') { |
|
457 | + return (int) $this->get_prop('is_recurring', $context); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | /** |
@@ -464,9 +464,9 @@ discard block |
||
464 | 464 | * @param string $context View or edit context. |
465 | 465 | * @return float |
466 | 466 | */ |
467 | - public function get_recurring_price( $context = 'view' ) { |
|
468 | - $price = $this->get_price( $context ); |
|
469 | - return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
|
467 | + public function get_recurring_price($context = 'view') { |
|
468 | + $price = $this->get_price($context); |
|
469 | + return wpinv_sanitize_amount(apply_filters('wpinv_get_recurring_item_price', $price, $this->ID)); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | /** |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | * @return string |
478 | 478 | */ |
479 | 479 | public function get_the_recurring_price() { |
480 | - return wpinv_price( $this->get_recurring_price() ); |
|
480 | + return wpinv_price($this->get_recurring_price()); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | /** |
@@ -498,15 +498,15 @@ discard block |
||
498 | 498 | $period = $this->get_recurring_period(); |
499 | 499 | $interval = $this->get_recurring_interval(); |
500 | 500 | |
501 | - if ( $this->has_free_trial() ) { |
|
501 | + if ($this->has_free_trial()) { |
|
502 | 502 | $period = $this->get_trial_period(); |
503 | 503 | $interval = $this->get_trial_interval(); |
504 | 504 | } |
505 | 505 | |
506 | - $period = $periods[ $period ]; |
|
507 | - $interval = empty( $interval ) ? 1 : $interval; |
|
508 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
509 | - return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
|
506 | + $period = $periods[$period]; |
|
507 | + $interval = empty($interval) ? 1 : $interval; |
|
508 | + $next_renewal = strtotime("+$interval $period", current_time('timestamp')); |
|
509 | + return apply_filters('wpinv_get_first_renewal_date', $next_renewal, $this); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
@@ -516,14 +516,14 @@ discard block |
||
516 | 516 | * @param bool $full Return abbreviation or in full. |
517 | 517 | * @return string |
518 | 518 | */ |
519 | - public function get_recurring_period( $full = false ) { |
|
520 | - $period = $this->get_prop( 'recurring_period', 'view' ); |
|
519 | + public function get_recurring_period($full = false) { |
|
520 | + $period = $this->get_prop('recurring_period', 'view'); |
|
521 | 521 | |
522 | - if ( $full && ! is_bool( $full ) ) { |
|
522 | + if ($full && !is_bool($full)) { |
|
523 | 523 | $full = false; |
524 | 524 | } |
525 | 525 | |
526 | - return getpaid_sanitize_recurring_period( $period, $full ); |
|
526 | + return getpaid_sanitize_recurring_period($period, $full); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -533,9 +533,9 @@ discard block |
||
533 | 533 | * @param string $context View or edit context. |
534 | 534 | * @return int |
535 | 535 | */ |
536 | - public function get_recurring_interval( $context = 'view' ) { |
|
537 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
538 | - return max( 1, $interval ); |
|
536 | + public function get_recurring_interval($context = 'view') { |
|
537 | + $interval = absint($this->get_prop('recurring_interval', $context)); |
|
538 | + return max(1, $interval); |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | /** |
@@ -545,8 +545,8 @@ discard block |
||
545 | 545 | * @param string $context View or edit context. |
546 | 546 | * @return int |
547 | 547 | */ |
548 | - public function get_recurring_limit( $context = 'view' ) { |
|
549 | - return (int) $this->get_prop( 'recurring_limit', $context ); |
|
548 | + public function get_recurring_limit($context = 'view') { |
|
549 | + return (int) $this->get_prop('recurring_limit', $context); |
|
550 | 550 | } |
551 | 551 | |
552 | 552 | /** |
@@ -556,8 +556,8 @@ discard block |
||
556 | 556 | * @param string $context View or edit context. |
557 | 557 | * @return int |
558 | 558 | */ |
559 | - public function get_is_free_trial( $context = 'view' ) { |
|
560 | - return (int) $this->get_prop( 'is_free_trial', $context ); |
|
559 | + public function get_is_free_trial($context = 'view') { |
|
560 | + return (int) $this->get_prop('is_free_trial', $context); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | /** |
@@ -567,8 +567,8 @@ discard block |
||
567 | 567 | * @param string $context View or edit context. |
568 | 568 | * @return int |
569 | 569 | */ |
570 | - public function get_free_trial( $context = 'view' ) { |
|
571 | - return $this->get_is_free_trial( $context ); |
|
570 | + public function get_free_trial($context = 'view') { |
|
571 | + return $this->get_is_free_trial($context); |
|
572 | 572 | } |
573 | 573 | |
574 | 574 | /** |
@@ -578,14 +578,14 @@ discard block |
||
578 | 578 | * @param bool $full Return abbreviation or in full. |
579 | 579 | * @return string |
580 | 580 | */ |
581 | - public function get_trial_period( $full = false ) { |
|
582 | - $period = $this->get_prop( 'trial_period', 'view' ); |
|
581 | + public function get_trial_period($full = false) { |
|
582 | + $period = $this->get_prop('trial_period', 'view'); |
|
583 | 583 | |
584 | - if ( $full && ! is_bool( $full ) ) { |
|
584 | + if ($full && !is_bool($full)) { |
|
585 | 585 | $full = false; |
586 | 586 | } |
587 | 587 | |
588 | - return getpaid_sanitize_recurring_period( $period, $full ); |
|
588 | + return getpaid_sanitize_recurring_period($period, $full); |
|
589 | 589 | } |
590 | 590 | |
591 | 591 | /** |
@@ -595,8 +595,8 @@ discard block |
||
595 | 595 | * @param string $context View or edit context. |
596 | 596 | * @return int |
597 | 597 | */ |
598 | - public function get_trial_interval( $context = 'view' ) { |
|
599 | - return (int) $this->get_prop( 'trial_interval', $context ); |
|
598 | + public function get_trial_interval($context = 'view') { |
|
599 | + return (int) $this->get_prop('trial_interval', $context); |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | /** |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | * @return string |
607 | 607 | */ |
608 | 608 | public function get_edit_url() { |
609 | - return get_edit_post_link( $this->get_id(), 'edit' ); |
|
609 | + return get_edit_post_link($this->get_id(), 'edit'); |
|
610 | 610 | } |
611 | 611 | |
612 | 612 | /** |
@@ -620,35 +620,35 @@ discard block |
||
620 | 620 | * @since 1.0.15 |
621 | 621 | * @return int |
622 | 622 | */ |
623 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
623 | + public static function get_item_id_by_field($value, $field = 'custom_id', $type = '') { |
|
624 | 624 | |
625 | 625 | // Trim the value. |
626 | - $value = sanitize_text_field( $value ); |
|
627 | - if ( empty( $value ) ) { |
|
626 | + $value = sanitize_text_field($value); |
|
627 | + if (empty($value)) { |
|
628 | 628 | return 0; |
629 | 629 | } |
630 | 630 | |
631 | 631 | // Valid fields. |
632 | - $fields = array( 'custom_id', 'name', 'slug' ); |
|
632 | + $fields = array('custom_id', 'name', 'slug'); |
|
633 | 633 | |
634 | 634 | // Ensure a field has been passed. |
635 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
635 | + if (empty($field) || !in_array($field, $fields)) { |
|
636 | 636 | return 0; |
637 | 637 | } |
638 | 638 | |
639 | - if ( $field == 'name' ) { |
|
639 | + if ($field == 'name') { |
|
640 | 640 | $field = 'slug'; |
641 | 641 | } |
642 | 642 | |
643 | 643 | // Maybe retrieve from the cache. |
644 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
645 | - if ( ! empty( $item_id ) ) { |
|
644 | + $item_id = wp_cache_get($value, "getpaid_{$type}_item_{$field}s_to_item_ids"); |
|
645 | + if (!empty($item_id)) { |
|
646 | 646 | return $item_id; |
647 | 647 | } |
648 | 648 | |
649 | 649 | // Fetch from the db. |
650 | 650 | $items = array(); |
651 | - if ( $field == 'slug' ) { |
|
651 | + if ($field == 'slug') { |
|
652 | 652 | $items = get_posts( |
653 | 653 | array( |
654 | 654 | 'post_type' => 'wpi_item', |
@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | ); |
660 | 660 | } |
661 | 661 | |
662 | - if ( $field =='custom_id' ) { |
|
662 | + if ($field == 'custom_id') { |
|
663 | 663 | $items = get_posts( |
664 | 664 | array( |
665 | 665 | 'post_type' => 'wpi_item', |
@@ -679,12 +679,12 @@ discard block |
||
679 | 679 | ); |
680 | 680 | } |
681 | 681 | |
682 | - if ( empty( $items ) ) { |
|
682 | + if (empty($items)) { |
|
683 | 683 | return 0; |
684 | 684 | } |
685 | 685 | |
686 | 686 | // Update the cache with our data |
687 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
687 | + wp_cache_set($value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids"); |
|
688 | 688 | |
689 | 689 | return $items[0]->ID; |
690 | 690 | } |
@@ -692,19 +692,19 @@ discard block |
||
692 | 692 | /** |
693 | 693 | * Margic method for retrieving a property. |
694 | 694 | */ |
695 | - public function __get( $key ) { |
|
695 | + public function __get($key) { |
|
696 | 696 | |
697 | 697 | // Check if we have a helper method for that. |
698 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
699 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
698 | + if (method_exists($this, 'get_' . $key)) { |
|
699 | + return call_user_func(array($this, 'get_' . $key)); |
|
700 | 700 | } |
701 | 701 | |
702 | 702 | // Check if the key is in the associated $post object. |
703 | - if ( ! empty( $this->post ) && isset( $this->post->$key ) ) { |
|
703 | + if (!empty($this->post) && isset($this->post->$key)) { |
|
704 | 704 | return $this->post->$key; |
705 | 705 | } |
706 | 706 | |
707 | - return $this->get_prop( $key ); |
|
707 | + return $this->get_prop($key); |
|
708 | 708 | |
709 | 709 | } |
710 | 710 | |
@@ -723,11 +723,11 @@ discard block |
||
723 | 723 | * |
724 | 724 | * @since 1.0.19 |
725 | 725 | */ |
726 | - public function set_parent_id( $value ) { |
|
727 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
726 | + public function set_parent_id($value) { |
|
727 | + if ($value && ($value === $this->get_id() || !get_post($value))) { |
|
728 | 728 | return; |
729 | 729 | } |
730 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
730 | + $this->set_prop('parent_id', absint($value)); |
|
731 | 731 | } |
732 | 732 | |
733 | 733 | /** |
@@ -737,10 +737,10 @@ discard block |
||
737 | 737 | * @param string $status New status. |
738 | 738 | * @return array details of change. |
739 | 739 | */ |
740 | - public function set_status( $status ) { |
|
740 | + public function set_status($status) { |
|
741 | 741 | $old_status = $this->get_status(); |
742 | 742 | |
743 | - $this->set_prop( 'status', $status ); |
|
743 | + $this->set_prop('status', $status); |
|
744 | 744 | |
745 | 745 | return array( |
746 | 746 | 'from' => $old_status, |
@@ -753,8 +753,8 @@ discard block |
||
753 | 753 | * |
754 | 754 | * @since 1.0.19 |
755 | 755 | */ |
756 | - public function set_version( $value ) { |
|
757 | - $this->set_prop( 'version', $value ); |
|
756 | + public function set_version($value) { |
|
757 | + $this->set_prop('version', $value); |
|
758 | 758 | } |
759 | 759 | |
760 | 760 | /** |
@@ -764,11 +764,11 @@ discard block |
||
764 | 764 | * @param string $value Value to set. |
765 | 765 | * @return bool Whether or not the date was set. |
766 | 766 | */ |
767 | - public function set_date_created( $value ) { |
|
768 | - $date = strtotime( $value ); |
|
767 | + public function set_date_created($value) { |
|
768 | + $date = strtotime($value); |
|
769 | 769 | |
770 | - if ( $date ) { |
|
771 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
770 | + if ($date) { |
|
771 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
772 | 772 | return true; |
773 | 773 | } |
774 | 774 | |
@@ -783,11 +783,11 @@ discard block |
||
783 | 783 | * @param string $value Value to set. |
784 | 784 | * @return bool Whether or not the date was set. |
785 | 785 | */ |
786 | - public function set_date_modified( $value ) { |
|
787 | - $date = strtotime( $value ); |
|
786 | + public function set_date_modified($value) { |
|
787 | + $date = strtotime($value); |
|
788 | 788 | |
789 | - if ( $date ) { |
|
790 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
789 | + if ($date) { |
|
790 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
791 | 791 | return true; |
792 | 792 | } |
793 | 793 | |
@@ -801,9 +801,9 @@ discard block |
||
801 | 801 | * @since 1.0.19 |
802 | 802 | * @param string $value New name. |
803 | 803 | */ |
804 | - public function set_name( $value ) { |
|
805 | - $name = sanitize_text_field( $value ); |
|
806 | - $this->set_prop( 'name', $name ); |
|
804 | + public function set_name($value) { |
|
805 | + $name = sanitize_text_field($value); |
|
806 | + $this->set_prop('name', $name); |
|
807 | 807 | } |
808 | 808 | |
809 | 809 | /** |
@@ -812,8 +812,8 @@ discard block |
||
812 | 812 | * @since 1.0.19 |
813 | 813 | * @param string $value New name. |
814 | 814 | */ |
815 | - public function set_title( $value ) { |
|
816 | - $this->set_name( $value ); |
|
815 | + public function set_title($value) { |
|
816 | + $this->set_name($value); |
|
817 | 817 | } |
818 | 818 | |
819 | 819 | /** |
@@ -822,9 +822,9 @@ discard block |
||
822 | 822 | * @since 1.0.19 |
823 | 823 | * @param string $value New description. |
824 | 824 | */ |
825 | - public function set_description( $value ) { |
|
826 | - $description = wp_kses_post( $value ); |
|
827 | - return $this->set_prop( 'description', $description ); |
|
825 | + public function set_description($value) { |
|
826 | + $description = wp_kses_post($value); |
|
827 | + return $this->set_prop('description', $description); |
|
828 | 828 | } |
829 | 829 | |
830 | 830 | /** |
@@ -833,8 +833,8 @@ discard block |
||
833 | 833 | * @since 1.0.19 |
834 | 834 | * @param string $value New description. |
835 | 835 | */ |
836 | - public function set_excerpt( $value ) { |
|
837 | - $this->set_description( $value ); |
|
836 | + public function set_excerpt($value) { |
|
837 | + $this->set_description($value); |
|
838 | 838 | } |
839 | 839 | |
840 | 840 | /** |
@@ -843,8 +843,8 @@ discard block |
||
843 | 843 | * @since 1.0.19 |
844 | 844 | * @param string $value New description. |
845 | 845 | */ |
846 | - public function set_summary( $value ) { |
|
847 | - $this->set_description( $value ); |
|
846 | + public function set_summary($value) { |
|
847 | + $this->set_description($value); |
|
848 | 848 | } |
849 | 849 | |
850 | 850 | /** |
@@ -853,8 +853,8 @@ discard block |
||
853 | 853 | * @since 1.0.19 |
854 | 854 | * @param int $value New author. |
855 | 855 | */ |
856 | - public function set_author( $value ) { |
|
857 | - $this->set_prop( 'author', (int) $value ); |
|
856 | + public function set_author($value) { |
|
857 | + $this->set_prop('author', (int) $value); |
|
858 | 858 | } |
859 | 859 | |
860 | 860 | /** |
@@ -863,8 +863,8 @@ discard block |
||
863 | 863 | * @since 1.0.19 |
864 | 864 | * @param int $value New author. |
865 | 865 | */ |
866 | - public function set_owner( $value ) { |
|
867 | - $this->set_author( $value ); |
|
866 | + public function set_owner($value) { |
|
867 | + $this->set_author($value); |
|
868 | 868 | } |
869 | 869 | |
870 | 870 | /** |
@@ -873,8 +873,8 @@ discard block |
||
873 | 873 | * @since 1.0.19 |
874 | 874 | * @param float $value New price. |
875 | 875 | */ |
876 | - public function set_price( $value ) { |
|
877 | - $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
|
876 | + public function set_price($value) { |
|
877 | + $this->set_prop('price', (float) wpinv_sanitize_amount($value)); |
|
878 | 878 | } |
879 | 879 | |
880 | 880 | /** |
@@ -883,8 +883,8 @@ discard block |
||
883 | 883 | * @since 1.0.19 |
884 | 884 | * @param string $value new rule. |
885 | 885 | */ |
886 | - public function set_vat_rule( $value ) { |
|
887 | - $this->set_prop( 'vat_rule', $value ); |
|
886 | + public function set_vat_rule($value) { |
|
887 | + $this->set_prop('vat_rule', $value); |
|
888 | 888 | } |
889 | 889 | |
890 | 890 | /** |
@@ -893,8 +893,8 @@ discard block |
||
893 | 893 | * @since 1.0.19 |
894 | 894 | * @param string $value new class. |
895 | 895 | */ |
896 | - public function set_vat_class( $value ) { |
|
897 | - $this->set_prop( 'vat_class', $value ); |
|
896 | + public function set_vat_class($value) { |
|
897 | + $this->set_prop('vat_class', $value); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | /** |
@@ -904,13 +904,13 @@ discard block |
||
904 | 904 | * @param string $value new item type. |
905 | 905 | * @return string |
906 | 906 | */ |
907 | - public function set_type( $value ) { |
|
907 | + public function set_type($value) { |
|
908 | 908 | |
909 | - if ( empty( $value ) ) { |
|
909 | + if (empty($value)) { |
|
910 | 910 | $value = 'custom'; |
911 | 911 | } |
912 | 912 | |
913 | - $this->set_prop( 'type', $value ); |
|
913 | + $this->set_prop('type', $value); |
|
914 | 914 | } |
915 | 915 | |
916 | 916 | /** |
@@ -919,8 +919,8 @@ discard block |
||
919 | 919 | * @since 1.0.19 |
920 | 920 | * @param string $value new custom id. |
921 | 921 | */ |
922 | - public function set_custom_id( $value ) { |
|
923 | - $this->set_prop( 'custom_id', $value ); |
|
922 | + public function set_custom_id($value) { |
|
923 | + $this->set_prop('custom_id', $value); |
|
924 | 924 | } |
925 | 925 | |
926 | 926 | /** |
@@ -929,8 +929,8 @@ discard block |
||
929 | 929 | * @since 1.0.19 |
930 | 930 | * @param string $value new custom name. |
931 | 931 | */ |
932 | - public function set_custom_name( $value ) { |
|
933 | - $this->set_prop( 'custom_name', $value ); |
|
932 | + public function set_custom_name($value) { |
|
933 | + $this->set_prop('custom_name', $value); |
|
934 | 934 | } |
935 | 935 | |
936 | 936 | /** |
@@ -939,8 +939,8 @@ discard block |
||
939 | 939 | * @since 1.0.19 |
940 | 940 | * @param string $value new custom singular name. |
941 | 941 | */ |
942 | - public function set_custom_singular_name( $value ) { |
|
943 | - $this->set_prop( 'custom_singular_name', $value ); |
|
942 | + public function set_custom_singular_name($value) { |
|
943 | + $this->set_prop('custom_singular_name', $value); |
|
944 | 944 | } |
945 | 945 | |
946 | 946 | /** |
@@ -949,8 +949,8 @@ discard block |
||
949 | 949 | * @since 1.0.19 |
950 | 950 | * @param int|bool $value whether or not the item is editable. |
951 | 951 | */ |
952 | - public function set_is_editable( $value ) { |
|
953 | - $this->set_prop( 'is_editable', (int) $value ); |
|
952 | + public function set_is_editable($value) { |
|
953 | + $this->set_prop('is_editable', (int) $value); |
|
954 | 954 | } |
955 | 955 | |
956 | 956 | /** |
@@ -959,8 +959,8 @@ discard block |
||
959 | 959 | * @since 1.0.19 |
960 | 960 | * @param int|bool $value whether or not dynamic pricing is allowed. |
961 | 961 | */ |
962 | - public function set_is_dynamic_pricing( $value ) { |
|
963 | - $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
|
962 | + public function set_is_dynamic_pricing($value) { |
|
963 | + $this->set_prop('is_dynamic_pricing', (int) $value); |
|
964 | 964 | } |
965 | 965 | |
966 | 966 | /** |
@@ -969,8 +969,8 @@ discard block |
||
969 | 969 | * @since 1.0.19 |
970 | 970 | * @param float $value minimum price. |
971 | 971 | */ |
972 | - public function set_minimum_price( $value ) { |
|
973 | - $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
|
972 | + public function set_minimum_price($value) { |
|
973 | + $this->set_prop('minimum_price', (float) wpinv_sanitize_amount($value)); |
|
974 | 974 | } |
975 | 975 | |
976 | 976 | /** |
@@ -979,8 +979,8 @@ discard block |
||
979 | 979 | * @since 1.0.19 |
980 | 980 | * @param int|bool $value whether or not dynamic pricing is allowed. |
981 | 981 | */ |
982 | - public function set_is_recurring( $value ) { |
|
983 | - $this->set_prop( 'is_recurring', (int) $value ); |
|
982 | + public function set_is_recurring($value) { |
|
983 | + $this->set_prop('is_recurring', (int) $value); |
|
984 | 984 | } |
985 | 985 | |
986 | 986 | /** |
@@ -989,8 +989,8 @@ discard block |
||
989 | 989 | * @since 1.0.19 |
990 | 990 | * @param string $value new period. |
991 | 991 | */ |
992 | - public function set_recurring_period( $value ) { |
|
993 | - $this->set_prop( 'recurring_period', $value ); |
|
992 | + public function set_recurring_period($value) { |
|
993 | + $this->set_prop('recurring_period', $value); |
|
994 | 994 | } |
995 | 995 | |
996 | 996 | /** |
@@ -999,8 +999,8 @@ discard block |
||
999 | 999 | * @since 1.0.19 |
1000 | 1000 | * @param int $value recurring interval. |
1001 | 1001 | */ |
1002 | - public function set_recurring_interval( $value ) { |
|
1003 | - return $this->set_prop( 'recurring_interval', (int) $value ); |
|
1002 | + public function set_recurring_interval($value) { |
|
1003 | + return $this->set_prop('recurring_interval', (int) $value); |
|
1004 | 1004 | } |
1005 | 1005 | |
1006 | 1006 | /** |
@@ -1009,8 +1009,8 @@ discard block |
||
1009 | 1009 | * @param int $value The recurring limit. |
1010 | 1010 | * @return int |
1011 | 1011 | */ |
1012 | - public function set_recurring_limit( $value ) { |
|
1013 | - $this->set_prop( 'recurring_limit', (int) $value ); |
|
1012 | + public function set_recurring_limit($value) { |
|
1013 | + $this->set_prop('recurring_limit', (int) $value); |
|
1014 | 1014 | } |
1015 | 1015 | |
1016 | 1016 | /** |
@@ -1019,8 +1019,8 @@ discard block |
||
1019 | 1019 | * @since 1.0.19 |
1020 | 1020 | * @param int|bool $value whether or not it has a free trial. |
1021 | 1021 | */ |
1022 | - public function set_is_free_trial( $value ) { |
|
1023 | - $this->set_prop( 'is_free_trial', (int) $value ); |
|
1022 | + public function set_is_free_trial($value) { |
|
1023 | + $this->set_prop('is_free_trial', (int) $value); |
|
1024 | 1024 | } |
1025 | 1025 | |
1026 | 1026 | /** |
@@ -1029,8 +1029,8 @@ discard block |
||
1029 | 1029 | * @since 1.0.19 |
1030 | 1030 | * @param string $value trial period. |
1031 | 1031 | */ |
1032 | - public function set_trial_period( $value ) { |
|
1033 | - $this->set_prop( 'trial_period', $value ); |
|
1032 | + public function set_trial_period($value) { |
|
1033 | + $this->set_prop('trial_period', $value); |
|
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | /** |
@@ -1039,8 +1039,8 @@ discard block |
||
1039 | 1039 | * @since 1.0.19 |
1040 | 1040 | * @param int $value trial interval. |
1041 | 1041 | */ |
1042 | - public function set_trial_interval( $value ) { |
|
1043 | - $this->set_prop( 'trial_interval', $value ); |
|
1042 | + public function set_trial_interval($value) { |
|
1043 | + $this->set_prop('trial_interval', $value); |
|
1044 | 1044 | } |
1045 | 1045 | |
1046 | 1046 | /** |
@@ -1049,11 +1049,11 @@ discard block |
||
1049 | 1049 | * @deprecated |
1050 | 1050 | * @return int item id |
1051 | 1051 | */ |
1052 | - public function create( $data = array() ) { |
|
1052 | + public function create($data = array()) { |
|
1053 | 1053 | |
1054 | 1054 | // Set the properties. |
1055 | - if ( is_array( $data ) ) { |
|
1056 | - $this->set_props( $data ); |
|
1055 | + if (is_array($data)) { |
|
1056 | + $this->set_props($data); |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | // Save the item. |
@@ -1067,8 +1067,8 @@ discard block |
||
1067 | 1067 | * @deprecated |
1068 | 1068 | * @return int item id |
1069 | 1069 | */ |
1070 | - public function update( $data = array() ) { |
|
1071 | - return $this->create( $data ); |
|
1070 | + public function update($data = array()) { |
|
1071 | + return $this->create($data); |
|
1072 | 1072 | } |
1073 | 1073 | |
1074 | 1074 | /* |
@@ -1108,7 +1108,7 @@ discard block |
||
1108 | 1108 | */ |
1109 | 1109 | public function has_free_trial() { |
1110 | 1110 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
1111 | - return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
|
1111 | + return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this); |
|
1112 | 1112 | } |
1113 | 1113 | |
1114 | 1114 | /** |
@@ -1118,8 +1118,8 @@ discard block |
||
1118 | 1118 | * @return bool |
1119 | 1119 | */ |
1120 | 1120 | public function is_free() { |
1121 | - $is_free = $this->get_price() == 0; |
|
1122 | - return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
|
1121 | + $is_free = $this->get_price() == 0; |
|
1122 | + return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID, $this); |
|
1123 | 1123 | } |
1124 | 1124 | |
1125 | 1125 | /** |
@@ -1128,9 +1128,9 @@ discard block |
||
1128 | 1128 | * @param array|string $status Status to check. |
1129 | 1129 | * @return bool |
1130 | 1130 | */ |
1131 | - public function has_status( $status ) { |
|
1132 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1133 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1131 | + public function has_status($status) { |
|
1132 | + $has_status = (is_array($status) && in_array($this->get_status(), $status, true)) || $this->get_status() === $status; |
|
1133 | + return (bool) apply_filters('getpaid_item_has_status', $has_status, $this, $status); |
|
1134 | 1134 | } |
1135 | 1135 | |
1136 | 1136 | /** |
@@ -1139,9 +1139,9 @@ discard block |
||
1139 | 1139 | * @param array|string $type Type to check. |
1140 | 1140 | * @return bool |
1141 | 1141 | */ |
1142 | - public function is_type( $type ) { |
|
1143 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1144 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1142 | + public function is_type($type) { |
|
1143 | + $is_type = (is_array($type) && in_array($this->get_type(), $type, true)) || $this->get_type() === $type; |
|
1144 | + return (bool) apply_filters('getpaid_item_is_type', $is_type, $this, $type); |
|
1145 | 1145 | } |
1146 | 1146 | |
1147 | 1147 | /** |
@@ -1152,7 +1152,7 @@ discard block |
||
1152 | 1152 | */ |
1153 | 1153 | public function is_editable() { |
1154 | 1154 | $is_editable = $this->get_is_editable(); |
1155 | - return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
|
1155 | + return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID, $this); |
|
1156 | 1156 | } |
1157 | 1157 | |
1158 | 1158 | /** |
@@ -1171,11 +1171,11 @@ discard block |
||
1171 | 1171 | public function can_purchase() { |
1172 | 1172 | $can_purchase = $this->exists(); |
1173 | 1173 | |
1174 | - if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) { |
|
1174 | + if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') { |
|
1175 | 1175 | $can_purchase = false; |
1176 | 1176 | } |
1177 | 1177 | |
1178 | - return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this ); |
|
1178 | + return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this); |
|
1179 | 1179 | } |
1180 | 1180 | |
1181 | 1181 | /** |
@@ -1185,6 +1185,6 @@ discard block |
||
1185 | 1185 | * @return bool |
1186 | 1186 | */ |
1187 | 1187 | public function supports_dynamic_pricing() { |
1188 | - return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
|
1188 | + return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this); |
|
1189 | 1189 | } |
1190 | 1190 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Daily maintenance class. |
@@ -15,19 +15,19 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * Class constructor. |
17 | 17 | */ |
18 | - public function __construct(){ |
|
18 | + public function __construct() { |
|
19 | 19 | |
20 | 20 | // Clear deprecated events. |
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
21 | + add_action('wp', array($this, 'maybe_clear_deprecated_events')); |
|
22 | 22 | |
23 | 23 | // (Maybe) schedule a cron that runs daily. |
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
24 | + add_action('wp', array($this, 'maybe_create_scheduled_event')); |
|
25 | 25 | |
26 | 26 | // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
27 | + add_action('getpaid_daily_maintenance', array($this, 'log_cron_run')); |
|
28 | + add_action('getpaid_daily_maintenance', array($this, 'backwards_compat')); |
|
29 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_expire_subscriptions')); |
|
30 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_update_geoip_databases')); |
|
31 | 31 | |
32 | 32 | } |
33 | 33 | |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function maybe_create_scheduled_event() { |
39 | 39 | |
40 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
41 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
42 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
40 | + if (!wp_next_scheduled('getpaid_daily_maintenance')) { |
|
41 | + $timestamp = strtotime('tomorrow 07:00:00', current_time('timestamp')); |
|
42 | + wp_schedule_event($timestamp, 'daily', 'getpaid_daily_maintenance'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | } |
@@ -50,10 +50,10 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function maybe_clear_deprecated_events() { |
52 | 52 | |
53 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
54 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
56 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
53 | + if (!get_option('wpinv_cleared_old_events')) { |
|
54 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily'); |
|
55 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_daily'); |
|
56 | + update_option('wpinv_cleared_old_events', 1); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * |
64 | 64 | */ |
65 | 65 | public function backwards_compat() { |
66 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
66 | + do_action('wpinv_register_schedule_event_daily'); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | public function maybe_expire_subscriptions() { |
74 | 74 | |
75 | 75 | // Fetch expired subscriptions (skips those that expire today). |
76 | - $args = array( |
|
76 | + $args = array( |
|
77 | 77 | 'number' => -1, |
78 | 78 | 'count_total' => false, |
79 | 79 | 'status' => 'trialling active failing cancelled', |
@@ -83,11 +83,11 @@ discard block |
||
83 | 83 | ), |
84 | 84 | ); |
85 | 85 | |
86 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
86 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
87 | 87 | |
88 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
89 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
90 | - $subscription->set_status( 'expired' ); |
|
88 | + foreach ($subscriptions->get_results() as $subscription) { |
|
89 | + if (apply_filters('getpaid_daily_maintenance_should_expire_subscription', true, $subscription)) { |
|
90 | + $subscription->set_status('expired'); |
|
91 | 91 | $subscription->save(); |
92 | 92 | } |
93 | 93 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * |
100 | 100 | */ |
101 | 101 | public function log_cron_run() { |
102 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
102 | + wpinv_error_log('GetPaid Daily Cron', false); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | * |
108 | 108 | */ |
109 | 109 | public function maybe_update_geoip_databases() { |
110 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
110 | + $updated = get_transient('getpaid_updated_geoip_databases'); |
|
111 | 111 | |
112 | - if ( false === $updated ) { |
|
113 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
114 | - do_action( 'getpaid_update_geoip_databases' ); |
|
112 | + if (false === $updated) { |
|
113 | + set_transient('getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS); |
|
114 | + do_action('getpaid_update_geoip_databases'); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | } |
@@ -7,64 +7,64 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | // Fetch the invoice. |
13 | -$invoice = new WPInv_Invoice( $invoice ); |
|
13 | +$invoice = new WPInv_Invoice($invoice); |
|
14 | 14 | |
15 | 15 | // @deprecated |
16 | -do_action( 'wpinv_success_content_before', $invoice ); |
|
17 | -do_action( 'wpinv_before_receipt', $invoice ); |
|
16 | +do_action('wpinv_success_content_before', $invoice); |
|
17 | +do_action('wpinv_before_receipt', $invoice); |
|
18 | 18 | |
19 | 19 | wpinv_print_errors(); |
20 | 20 | |
21 | 21 | // Prepare header text. |
22 | -if ( $invoice->is_paid() ) { |
|
22 | +if ($invoice->is_paid()) { |
|
23 | 23 | |
24 | 24 | $alert = aui()->alert( |
25 | 25 | array( |
26 | 26 | 'type' => 'success', |
27 | - 'content' => __( 'Thank you for your payment!', 'invoicing' ), |
|
27 | + 'content' => __('Thank you for your payment!', 'invoicing'), |
|
28 | 28 | ) |
29 | 29 | ); |
30 | 30 | |
31 | -} else if ( $invoice->is_refunded() ) { |
|
31 | +} else if ($invoice->is_refunded()) { |
|
32 | 32 | |
33 | 33 | $alert = aui()->alert( |
34 | 34 | array( |
35 | 35 | 'type' => 'info', |
36 | - 'content' => __( 'This invoice was refunded.', 'invoicing' ), |
|
36 | + 'content' => __('This invoice was refunded.', 'invoicing'), |
|
37 | 37 | ) |
38 | 38 | ); |
39 | 39 | |
40 | -} else if ( $invoice->is_held() ) { |
|
40 | +} else if ($invoice->is_held()) { |
|
41 | 41 | |
42 | 42 | $alert = aui()->alert( |
43 | 43 | array( |
44 | 44 | 'type' => 'info', |
45 | - 'content' => __( 'This invoice will be processed as soon we verify your payment.', 'invoicing' ), |
|
45 | + 'content' => __('This invoice will be processed as soon we verify your payment.', 'invoicing'), |
|
46 | 46 | ) |
47 | 47 | ); |
48 | 48 | |
49 | -} else if ( $invoice->needs_payment() ) { |
|
49 | +} else if ($invoice->needs_payment()) { |
|
50 | 50 | |
51 | - if ( ! empty( $_GET['token'] ) ) { |
|
51 | + if (!empty($_GET['token'])) { |
|
52 | 52 | |
53 | 53 | $alert = aui()->alert( |
54 | 54 | array( |
55 | 55 | 'type' => 'info', |
56 | - 'content' => __( "Sometimes it takes a few minutes for us to verify your payment. We'll notify you as soon as we've verified the payment.", 'invoicing' ), |
|
56 | + 'content' => __("Sometimes it takes a few minutes for us to verify your payment. We'll notify you as soon as we've verified the payment.", 'invoicing'), |
|
57 | 57 | ) |
58 | 58 | ); |
59 | 59 | |
60 | - } else if ( $invoice->is_due() ) { |
|
60 | + } else if ($invoice->is_due()) { |
|
61 | 61 | |
62 | 62 | $alert = aui()->alert( |
63 | 63 | array( |
64 | 64 | 'type' => 'danger', |
65 | 65 | 'content' => sprintf( |
66 | - __( 'This invoice was due on %.', 'invoicing' ), |
|
67 | - getpaid_format_date_value( $invoice->get_due_date() ) |
|
66 | + __('This invoice was due on %.', 'invoicing'), |
|
67 | + getpaid_format_date_value($invoice->get_due_date()) |
|
68 | 68 | ), |
69 | 69 | ) |
70 | 70 | ); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $alert = aui()->alert( |
75 | 75 | array( |
76 | 76 | 'type' => 'warning', |
77 | - 'content' => __( 'This invoice needs payment.', 'invoicing' ), |
|
77 | + 'content' => __('This invoice needs payment.', 'invoicing'), |
|
78 | 78 | ) |
79 | 79 | ); |
80 | 80 | |
@@ -89,19 +89,19 @@ discard block |
||
89 | 89 | |
90 | 90 | 'pay' => array( |
91 | 91 | 'url' => $invoice->get_checkout_payment_url(), |
92 | - 'name' => __( 'Pay For Invoice', 'invoicing' ), |
|
92 | + 'name' => __('Pay For Invoice', 'invoicing'), |
|
93 | 93 | 'class' => 'btn-success', |
94 | 94 | ), |
95 | 95 | |
96 | 96 | 'view' => array( |
97 | 97 | 'url' => $invoice->get_view_url(), |
98 | - 'name' => __( 'View Invoice', 'invoicing' ), |
|
98 | + 'name' => __('View Invoice', 'invoicing'), |
|
99 | 99 | 'class' => 'btn-primary', |
100 | 100 | ), |
101 | 101 | |
102 | 102 | 'history' => array( |
103 | 103 | 'url' => wpinv_get_history_page_uri(), |
104 | - 'name' => __( 'Invoice History', 'invoicing' ), |
|
104 | + 'name' => __('Invoice History', 'invoicing'), |
|
105 | 105 | 'class' => 'btn-warning', |
106 | 106 | ), |
107 | 107 | |
@@ -110,12 +110,12 @@ discard block |
||
110 | 110 | |
111 | 111 | ); |
112 | 112 | |
113 | -if ( ( ! $invoice->needs_payment() || $invoice->is_held() ) && isset( $actions['pay'] ) ) { |
|
114 | - unset( $actions['pay'] ); |
|
113 | +if ((!$invoice->needs_payment() || $invoice->is_held()) && isset($actions['pay'])) { |
|
114 | + unset($actions['pay']); |
|
115 | 115 | } |
116 | 116 | |
117 | -if ( ! is_user_logged_in() && isset( $actions['history'] ) ) { |
|
118 | - unset( $actions['history'] ); |
|
117 | +if (!is_user_logged_in() && isset($actions['history'])) { |
|
118 | + unset($actions['history']); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | ?> |
@@ -124,19 +124,19 @@ discard block |
||
124 | 124 | |
125 | 125 | <?php |
126 | 126 | |
127 | - do_action( 'wpinv_receipt_start', $invoice ); |
|
127 | + do_action('wpinv_receipt_start', $invoice); |
|
128 | 128 | |
129 | - if ( ! empty( $actions ) ) { |
|
129 | + if (!empty($actions)) { |
|
130 | 130 | |
131 | 131 | echo '<div class="wpinv-receipt-actions text-right mt-1 mb-4">'; |
132 | 132 | |
133 | - foreach ( $actions as $key => $action ) { |
|
133 | + foreach ($actions as $key => $action) { |
|
134 | 134 | |
135 | - $key = sanitize_html_class( $key ); |
|
136 | - $class = empty( $action['class'] ) ? 'btn-dark' : sanitize_html_class( $action['class'] ); |
|
137 | - $url = empty( $action['url'] ) ? '#' : esc_url( $action['url'] ); |
|
138 | - $attrs = empty( $action['attrs'] ) ? '' : $action['attrs']; |
|
139 | - $anchor = sanitize_text_field( $action['name'] ); |
|
135 | + $key = sanitize_html_class($key); |
|
136 | + $class = empty($action['class']) ? 'btn-dark' : sanitize_html_class($action['class']); |
|
137 | + $url = empty($action['url']) ? '#' : esc_url($action['url']); |
|
138 | + $attrs = empty($action['attrs']) ? '' : $action['attrs']; |
|
139 | + $anchor = sanitize_text_field($action['name']); |
|
140 | 140 | |
141 | 141 | echo "<a href='$url' class='btn btn-sm ml-1 $class $key' $attrs>$anchor</a>"; |
142 | 142 | } |
@@ -152,21 +152,21 @@ discard block |
||
152 | 152 | <div class="wpinv-receipt-details"> |
153 | 153 | |
154 | 154 | <h4 class="wpinv-details-t mb-3 mt-3"> |
155 | - <?php echo apply_filters( 'wpinv_receipt_details_title', __( 'Invoice Details', 'invoicing' ), $invoice ); ?> |
|
155 | + <?php echo apply_filters('wpinv_receipt_details_title', __('Invoice Details', 'invoicing'), $invoice); ?> |
|
156 | 156 | </h4> |
157 | 157 | |
158 | - <?php getpaid_invoice_meta( $invoice ); ?> |
|
158 | + <?php getpaid_invoice_meta($invoice); ?> |
|
159 | 159 | |
160 | 160 | </div> |
161 | 161 | |
162 | - <?php echo getpaid_display_invoice_subscriptions( $invoice ); ?> |
|
162 | + <?php echo getpaid_display_invoice_subscriptions($invoice); ?> |
|
163 | 163 | |
164 | - <?php do_action( 'wpinv_receipt_end', $invoice ); ?> |
|
164 | + <?php do_action('wpinv_receipt_end', $invoice); ?> |
|
165 | 165 | |
166 | 166 | </div> |
167 | 167 | |
168 | 168 | <?php |
169 | 169 | |
170 | 170 | // @deprecated |
171 | -do_action( 'wpinv_success_content_after', $invoice ); |
|
172 | -do_action( 'wpinv_after_receipt', $invoice ); |
|
171 | +do_action('wpinv_success_content_after', $invoice); |
|
172 | +do_action('wpinv_after_receipt', $invoice); |
@@ -4,8 +4,8 @@ discard block |
||
4 | 4 | <?php |
5 | 5 | echo |
6 | 6 | wp_sprintf( |
7 | - __( 'Your payment is processing. This page will reload automatically in 10 seconds. If it does not, click <a href="%s">here</a>.', 'invoicing' ), |
|
8 | - esc_url_raw( remove_query_arg( 'payment-confirm' ) ) |
|
7 | + __('Your payment is processing. This page will reload automatically in 10 seconds. If it does not, click <a href="%s">here</a>.', 'invoicing'), |
|
8 | + esc_url_raw(remove_query_arg('payment-confirm')) |
|
9 | 9 | ); |
10 | 10 | ?> |
11 | 11 | <i class="fa fa-spin fa-refresh"></i> |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | <script type="text/javascript"> |
15 | 15 | setTimeout( |
16 | 16 | function(){ |
17 | - window.location.href = '<?php echo esc_url_raw( remove_query_arg( 'payment-confirm' ) ) ;?>'; |
|
17 | + window.location.href = '<?php echo esc_url_raw(remove_query_arg('payment-confirm')); ?>'; |
|
18 | 18 | }, |
19 | 19 | 10000 |
20 | 20 | ); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Metaboxes Admin Class |
@@ -25,35 +25,35 @@ discard block |
||
25 | 25 | public static function init() { |
26 | 26 | |
27 | 27 | // Register metaboxes. |
28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
28 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2); |
|
29 | 29 | |
30 | 30 | // Remove metaboxes. |
31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
31 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30); |
|
32 | 32 | |
33 | 33 | // Rename metaboxes. |
34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
34 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45); |
|
35 | 35 | |
36 | 36 | // Save metaboxes. |
37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
37 | + add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | 41 | * Register core metaboxes. |
42 | 42 | */ |
43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
43 | + public static function add_meta_boxes($post_type, $post) { |
|
44 | 44 | |
45 | 45 | // For invoices... |
46 | - self::add_invoice_meta_boxes( $post_type, $post ); |
|
46 | + self::add_invoice_meta_boxes($post_type, $post); |
|
47 | 47 | |
48 | 48 | // For payment forms. |
49 | - self::add_payment_form_meta_boxes( $post_type ); |
|
49 | + self::add_payment_form_meta_boxes($post_type); |
|
50 | 50 | |
51 | 51 | // For invoice items. |
52 | - self::add_item_meta_boxes( $post_type ); |
|
52 | + self::add_item_meta_boxes($post_type); |
|
53 | 53 | |
54 | 54 | // For invoice discounts. |
55 | - if ( $post_type == 'wpi_discount' ) { |
|
56 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
55 | + if ($post_type == 'wpi_discount') { |
|
56 | + add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | } |
@@ -61,16 +61,16 @@ discard block |
||
61 | 61 | /** |
62 | 62 | * Register core metaboxes. |
63 | 63 | */ |
64 | - protected static function add_payment_form_meta_boxes( $post_type ) { |
|
64 | + protected static function add_payment_form_meta_boxes($post_type) { |
|
65 | 65 | |
66 | 66 | // For payment forms. |
67 | - if ( $post_type == 'wpi_payment_form' ) { |
|
67 | + if ($post_type == 'wpi_payment_form') { |
|
68 | 68 | |
69 | 69 | // Design payment form. |
70 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
70 | + add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal'); |
|
71 | 71 | |
72 | 72 | // Payment form information. |
73 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
73 | + add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side'); |
|
74 | 74 | |
75 | 75 | } |
76 | 76 | |
@@ -79,20 +79,20 @@ discard block |
||
79 | 79 | /** |
80 | 80 | * Register core metaboxes. |
81 | 81 | */ |
82 | - protected static function add_item_meta_boxes( $post_type ) { |
|
82 | + protected static function add_item_meta_boxes($post_type) { |
|
83 | 83 | |
84 | - if ( $post_type == 'wpi_item' ) { |
|
84 | + if ($post_type == 'wpi_item') { |
|
85 | 85 | |
86 | 86 | // Item details. |
87 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
87 | + add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high'); |
|
88 | 88 | |
89 | 89 | // If taxes are enabled, register the tax metabox. |
90 | - if ( wpinv_use_taxes() ) { |
|
91 | - add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
90 | + if (wpinv_use_taxes()) { |
|
91 | + add_meta_box('wpinv_item_vat', __('Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high'); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | // Item info. |
95 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
95 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core'); |
|
96 | 96 | |
97 | 97 | } |
98 | 98 | |
@@ -101,20 +101,20 @@ discard block |
||
101 | 101 | /** |
102 | 102 | * Register invoice metaboxes. |
103 | 103 | */ |
104 | - protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
104 | + protected static function add_invoice_meta_boxes($post_type, $post) { |
|
105 | 105 | |
106 | 106 | // For invoices... |
107 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
108 | - $invoice = new WPInv_Invoice( $post ); |
|
107 | + if (getpaid_is_invoice_post_type($post_type)) { |
|
108 | + $invoice = new WPInv_Invoice($post); |
|
109 | 109 | |
110 | 110 | // Resend invoice. |
111 | - if ( ! $invoice->is_draft() ) { |
|
111 | + if (!$invoice->is_draft()) { |
|
112 | 112 | |
113 | 113 | add_meta_box( |
114 | 114 | 'wpinv-mb-resend-invoice', |
115 | 115 | sprintf( |
116 | - __( 'Resend %s', 'invoicing' ), |
|
117 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
116 | + __('Resend %s', 'invoicing'), |
|
117 | + ucfirst($invoice->get_invoice_quote_type()) |
|
118 | 118 | ), |
119 | 119 | 'GetPaid_Meta_Box_Resend_Invoice::output', |
120 | 120 | $post_type, |
@@ -125,17 +125,17 @@ discard block |
||
125 | 125 | } |
126 | 126 | |
127 | 127 | // Subscriptions. |
128 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
129 | - if ( ! empty( $subscriptions ) ) { |
|
128 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
129 | + if (!empty($subscriptions)) { |
|
130 | 130 | |
131 | - if ( is_array( $subscriptions ) ) { |
|
132 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
131 | + if (is_array($subscriptions)) { |
|
132 | + add_meta_box('wpinv-mb-subscriptions', __('Related Subscriptions', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced'); |
|
133 | 133 | } else { |
134 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
134 | + add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced'); |
|
135 | 135 | } |
136 | 136 | |
137 | - if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
138 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
137 | + if (getpaid_count_subscription_invoices($invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id()) > 1) { |
|
138 | + add_meta_box('wpinv-mb-subscription-invoices', __('Related Payments', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced'); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | } |
@@ -144,8 +144,8 @@ discard block |
||
144 | 144 | add_meta_box( |
145 | 145 | 'wpinv-details', |
146 | 146 | sprintf( |
147 | - __( '%s Details', 'invoicing' ), |
|
148 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
147 | + __('%s Details', 'invoicing'), |
|
148 | + ucfirst($invoice->get_invoice_quote_type()) |
|
149 | 149 | ), |
150 | 150 | 'GetPaid_Meta_Box_Invoice_Details::output', |
151 | 151 | $post_type, |
@@ -153,19 +153,19 @@ discard block |
||
153 | 153 | ); |
154 | 154 | |
155 | 155 | // Payment details. |
156 | - if ( ! $invoice->is_draft() ) { |
|
157 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
156 | + if (!$invoice->is_draft()) { |
|
157 | + add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default'); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | // Billing details. |
161 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
161 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high'); |
|
162 | 162 | |
163 | 163 | // Invoice items. |
164 | 164 | add_meta_box( |
165 | 165 | 'wpinv-items', |
166 | 166 | sprintf( |
167 | - __( '%s Items', 'invoicing' ), |
|
168 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
167 | + __('%s Items', 'invoicing'), |
|
168 | + ucfirst($invoice->get_invoice_quote_type()) |
|
169 | 169 | ), |
170 | 170 | 'GetPaid_Meta_Box_Invoice_Items::output', |
171 | 171 | $post_type, |
@@ -177,8 +177,8 @@ discard block |
||
177 | 177 | add_meta_box( |
178 | 178 | 'wpinv-notes', |
179 | 179 | sprintf( |
180 | - __( '%s Notes', 'invoicing' ), |
|
181 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
180 | + __('%s Notes', 'invoicing'), |
|
181 | + ucfirst($invoice->get_invoice_quote_type()) |
|
182 | 182 | ), |
183 | 183 | 'WPInv_Meta_Box_Notes::output', |
184 | 184 | $post_type, |
@@ -187,13 +187,13 @@ discard block |
||
187 | 187 | ); |
188 | 188 | |
189 | 189 | // Shipping Address. |
190 | - if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
191 | - add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
190 | + if (get_post_meta($invoice->get_id(), 'shipping_address', true)) { |
|
191 | + add_meta_box('wpinv-invoice-shipping-details', __('Shipping Address', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high'); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | // Payment form information. |
195 | - if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
196 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
195 | + if (get_post_meta($invoice->get_id(), 'payment_form_data', true)) { |
|
196 | + add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high'); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * Remove some metaboxes. |
205 | 205 | */ |
206 | 206 | public static function remove_meta_boxes() { |
207 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
207 | + remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -220,46 +220,46 @@ discard block |
||
220 | 220 | * @param int $post_id Post ID. |
221 | 221 | * @param object $post Post object. |
222 | 222 | */ |
223 | - public static function save_meta_boxes( $post_id, $post ) { |
|
224 | - $post_id = absint( $post_id ); |
|
225 | - $data = wp_unslash( $_POST ); |
|
223 | + public static function save_meta_boxes($post_id, $post) { |
|
224 | + $post_id = absint($post_id); |
|
225 | + $data = wp_unslash($_POST); |
|
226 | 226 | |
227 | 227 | // Do not save for ajax requests. |
228 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
228 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
229 | 229 | return; |
230 | 230 | } |
231 | 231 | |
232 | 232 | // $post_id and $post are required |
233 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
233 | + if (empty($post_id) || empty($post) || self::$saved_meta_boxes) { |
|
234 | 234 | return; |
235 | 235 | } |
236 | 236 | |
237 | 237 | // Dont' save meta boxes for revisions or autosaves. |
238 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
238 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
239 | 239 | return; |
240 | 240 | } |
241 | 241 | |
242 | 242 | // Check the nonce. |
243 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
243 | + if (empty($data['getpaid_meta_nonce']) || !wp_verify_nonce($data['getpaid_meta_nonce'], 'getpaid_meta_nonce')) { |
|
244 | 244 | return; |
245 | 245 | } |
246 | 246 | |
247 | 247 | // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
248 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
248 | + if (empty($data['post_ID']) || absint($data['post_ID']) !== $post_id) { |
|
249 | 249 | return; |
250 | 250 | } |
251 | 251 | |
252 | 252 | // Check user has permission to edit. |
253 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
253 | + if (!current_user_can('edit_post', $post_id)) { |
|
254 | 254 | return; |
255 | 255 | } |
256 | 256 | |
257 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
257 | + if (getpaid_is_invoice_post_type($post->post_type)) { |
|
258 | 258 | |
259 | 259 | // We need this save event to run once to avoid potential endless loops. |
260 | 260 | self::$saved_meta_boxes = true; |
261 | 261 | |
262 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
262 | + return GetPaid_Meta_Box_Invoice_Address::save($post_id); |
|
263 | 263 | |
264 | 264 | } |
265 | 265 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | ); |
272 | 272 | |
273 | 273 | // Is this our post type? |
274 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
274 | + if (!isset($post_types_map[$post->post_type])) { |
|
275 | 275 | return; |
276 | 276 | } |
277 | 277 | |
@@ -279,8 +279,8 @@ discard block |
||
279 | 279 | self::$saved_meta_boxes = true; |
280 | 280 | |
281 | 281 | // Save the post. |
282 | - $class = $post_types_map[ $post->post_type ]; |
|
283 | - $class::save( $post_id, $_POST, $post ); |
|
282 | + $class = $post_types_map[$post->post_type]; |
|
283 | + $class::save($post_id, $_POST, $post); |
|
284 | 284 | |
285 | 285 | } |
286 | 286 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Paypal Payment Gateway IPN handler class. |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @param GetPaid_Paypal_Gateway $gateway |
33 | 33 | */ |
34 | - public function __construct( $gateway ) { |
|
34 | + public function __construct($gateway) { |
|
35 | 35 | $this->gateway = $gateway; |
36 | 36 | $this->verify_ipn(); |
37 | 37 | } |
@@ -43,37 +43,37 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function verify_ipn() { |
45 | 45 | |
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
46 | + wpinv_error_log('GetPaid PayPal IPN Handler', false); |
|
47 | 47 | |
48 | 48 | // Validate the IPN. |
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
49 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
50 | + wp_die('PayPal IPN Request Failure', 500); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | // Process the IPN. |
54 | - $posted = wp_unslash( $_POST ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
54 | + $posted = wp_unslash($_POST); |
|
55 | + $invoice = $this->get_ipn_invoice($posted); |
|
56 | 56 | |
57 | 57 | // Abort if it was not paid by our gateway. |
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
58 | + if ($this->id != $invoice->get_gateway()) { |
|
59 | + wpinv_error_log('Aborting, Invoice was not paid via PayPal', false); |
|
60 | + wp_die('Invoice not paid via PayPal', 200); |
|
61 | 61 | } |
62 | 62 | |
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
63 | + $posted['payment_status'] = isset($posted['payment_status']) ? sanitize_key(strtolower($posted['payment_status'])) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key(strtolower($posted['txn_type'])); |
|
65 | 65 | |
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
66 | + wpinv_error_log('Payment status:' . $posted['payment_status'], false); |
|
67 | + wpinv_error_log('IPN Type:' . $posted['txn_type'], false); |
|
68 | 68 | |
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
69 | + if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) { |
|
70 | + call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted); |
|
71 | + wpinv_error_log('Done processing IPN', false); |
|
72 | + wp_die('Processed', 200); |
|
73 | 73 | } |
74 | 74 | |
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
75 | + wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type'], false); |
|
76 | + wp_die('Unsupported IPN type', 200); |
|
77 | 77 | |
78 | 78 | } |
79 | 79 | |
@@ -83,22 +83,22 @@ discard block |
||
83 | 83 | * @param array $posted |
84 | 84 | * @return WPInv_Invoice |
85 | 85 | */ |
86 | - protected function get_ipn_invoice( $posted ) { |
|
86 | + protected function get_ipn_invoice($posted) { |
|
87 | 87 | |
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
88 | + wpinv_error_log('Retrieving PayPal IPN Response Invoice', false); |
|
89 | 89 | |
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
90 | + if (!empty($posted['custom'])) { |
|
91 | + $invoice = new WPInv_Invoice($posted['custom']); |
|
92 | 92 | |
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
93 | + if ($invoice->exists()) { |
|
94 | + wpinv_error_log('Found invoice #' . $invoice->get_number(), false); |
|
95 | 95 | return $invoice; |
96 | 96 | } |
97 | 97 | |
98 | 98 | } |
99 | 99 | |
100 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
101 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
100 | + wpinv_error_log('Could not retrieve the associated invoice.', false); |
|
101 | + wp_die('Could not retrieve the associated invoice.', 200); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -106,14 +106,14 @@ discard block |
||
106 | 106 | */ |
107 | 107 | protected function validate_ipn() { |
108 | 108 | |
109 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
109 | + wpinv_error_log('Validating PayPal IPN response', false); |
|
110 | 110 | |
111 | 111 | // Retrieve the associated invoice. |
112 | - $posted = wp_unslash( $_POST ); |
|
113 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
112 | + $posted = wp_unslash($_POST); |
|
113 | + $invoice = $this->get_ipn_invoice($posted); |
|
114 | 114 | |
115 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
116 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
115 | + if ($this->gateway->is_sandbox($invoice)) { |
|
116 | + wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data', false); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | // Validate the IPN. |
@@ -130,20 +130,20 @@ discard block |
||
130 | 130 | ); |
131 | 131 | |
132 | 132 | // Post back to get a response. |
133 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
133 | + $response = wp_safe_remote_post($this->gateway->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params); |
|
134 | 134 | |
135 | 135 | // Check to see if the request was valid. |
136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
136 | + if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
137 | + wpinv_error_log('Received valid response from PayPal IPN: ' . $response['body'], false); |
|
138 | 138 | return true; |
139 | 139 | } |
140 | 140 | |
141 | - if ( is_wp_error( $response ) ) { |
|
142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
141 | + if (is_wp_error($response)) { |
|
142 | + wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN'); |
|
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | |
146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
146 | + wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN'); |
|
147 | 147 | return false; |
148 | 148 | |
149 | 149 | } |
@@ -154,17 +154,17 @@ discard block |
||
154 | 154 | * @param WPInv_Invoice $invoice Invoice object. |
155 | 155 | * @param string $currency currency to validate. |
156 | 156 | */ |
157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
157 | + protected function validate_ipn_currency($invoice, $currency) { |
|
158 | 158 | |
159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
159 | + if (strtolower($invoice->get_currency()) !== strtolower($currency)) { |
|
160 | 160 | |
161 | 161 | /* translators: %s: currency code. */ |
162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
162 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency)); |
|
163 | 163 | |
164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
164 | + wpinv_error_log("Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true); |
|
165 | 165 | } |
166 | 166 | |
167 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
167 | + wpinv_error_log($currency, 'Validated IPN Currency', false); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -173,16 +173,16 @@ discard block |
||
173 | 173 | * @param WPInv_Invoice $invoice Invoice object. |
174 | 174 | * @param float $amount amount to validate. |
175 | 175 | */ |
176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
176 | + protected function validate_ipn_amount($invoice, $amount) { |
|
177 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) { |
|
178 | 178 | |
179 | 179 | /* translators: %s: Amount. */ |
180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
180 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount)); |
|
181 | 181 | |
182 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
182 | + wpinv_error_log("Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true); |
|
183 | 183 | } |
184 | 184 | |
185 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
185 | + wpinv_error_log($amount, 'Validated IPN Amount', false); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -191,19 +191,19 @@ discard block |
||
191 | 191 | * @param WPInv_Invoice $invoice Invoice object. |
192 | 192 | * @param string $receiver_email Email to validate. |
193 | 193 | */ |
194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
194 | + protected function validate_ipn_receiver_email($invoice, $receiver_email) { |
|
195 | + $paypal_email = wpinv_get_option('paypal_email'); |
|
196 | 196 | |
197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
197 | + if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) { |
|
198 | + wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}"); |
|
199 | 199 | |
200 | 200 | /* translators: %s: email address . */ |
201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
201 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email)); |
|
202 | 202 | |
203 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
203 | + return wpinv_error_log("IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true); |
|
204 | 204 | } |
205 | 205 | |
206 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
206 | + wpinv_error_log('Validated PayPal Email', false); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -212,68 +212,68 @@ discard block |
||
212 | 212 | * @param WPInv_Invoice $invoice Invoice object. |
213 | 213 | * @param array $posted Posted data. |
214 | 214 | */ |
215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
215 | + protected function ipn_txn_web_accept($invoice, $posted) { |
|
216 | 216 | |
217 | 217 | // Collect payment details |
218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
218 | + $payment_status = strtolower($posted['payment_status']); |
|
219 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
220 | 220 | |
221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
221 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
222 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
223 | 223 | |
224 | 224 | // Update the transaction id. |
225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
225 | + if (!empty($posted['txn_id'])) { |
|
226 | + $invoice->set_transaction_id(wpinv_clean($posted['txn_id'])); |
|
227 | 227 | $invoice->save(); |
228 | 228 | } |
229 | 229 | |
230 | 230 | // Process a refund. |
231 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
231 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
232 | 232 | |
233 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
233 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
234 | 234 | |
235 | - if ( ! $invoice->is_refunded() ) { |
|
236 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
235 | + if (!$invoice->is_refunded()) { |
|
236 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
237 | 237 | } |
238 | 238 | |
239 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
239 | + return wpinv_error_log($posted['reason_code'], false); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | // Process payments. |
243 | - if ( $payment_status == 'completed' ) { |
|
243 | + if ($payment_status == 'completed') { |
|
244 | 244 | |
245 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
246 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
245 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
246 | + return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false); |
|
247 | 247 | } |
248 | 248 | |
249 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
249 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
250 | 250 | |
251 | 251 | $note = ''; |
252 | 252 | |
253 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
254 | - $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
253 | + if (!empty($posted['mc_fee'])) { |
|
254 | + $note = sprintf(__('PayPal Transaction Fee %.', 'invoicing'), sanitize_text_field($posted['mc_fee'])); |
|
255 | 255 | } |
256 | 256 | |
257 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
258 | - $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
257 | + if (!empty($posted['payer_status'])) { |
|
258 | + $note = ' ' . sprintf(__('Buyer status %.', 'invoicing'), sanitize_text_field($posted['payer_status'])); |
|
259 | 259 | } |
260 | 260 | |
261 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
262 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
261 | + $invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note)); |
|
262 | + return wpinv_error_log('Invoice marked as paid.', false); |
|
263 | 263 | |
264 | 264 | } |
265 | 265 | |
266 | 266 | // Pending payments. |
267 | - if ( $payment_status == 'pending' ) { |
|
267 | + if ($payment_status == 'pending') { |
|
268 | 268 | |
269 | 269 | /* translators: %s: pending reason. */ |
270 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
270 | + $invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
271 | 271 | |
272 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
272 | + return wpinv_error_log('Invoice marked as "payment held".', false); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /* translators: %s: payment status. */ |
276 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
276 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status']))); |
|
277 | 277 | |
278 | 278 | } |
279 | 279 | |
@@ -283,8 +283,8 @@ discard block |
||
283 | 283 | * @param WPInv_Invoice $invoice Invoice object. |
284 | 284 | * @param array $posted Posted data. |
285 | 285 | */ |
286 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
287 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
286 | + protected function ipn_txn_cart($invoice, $posted) { |
|
287 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -293,43 +293,43 @@ discard block |
||
293 | 293 | * @param WPInv_Invoice $invoice Invoice object. |
294 | 294 | * @param array $posted Posted data. |
295 | 295 | */ |
296 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
296 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
297 | 297 | |
298 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
298 | + wpinv_error_log('Processing subscription signup', false); |
|
299 | 299 | |
300 | 300 | // Make sure the invoice has a subscription. |
301 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
301 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
302 | 302 | |
303 | - if ( empty( $subscription ) ) { |
|
304 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
303 | + if (empty($subscription)) { |
|
304 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
305 | 305 | } |
306 | 306 | |
307 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
307 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
308 | 308 | |
309 | 309 | // Validate the IPN. |
310 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
311 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
312 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
310 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
311 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
312 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
313 | 313 | |
314 | 314 | // Activate the subscription. |
315 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
316 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
317 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
318 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
315 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
316 | + $subscription->set_date_created(current_time('mysql')); |
|
317 | + $subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration))); |
|
318 | + $subscription->set_profile_id(sanitize_text_field($posted['subscr_id'])); |
|
319 | 319 | $subscription->activate(); |
320 | 320 | |
321 | 321 | // Set the transaction id. |
322 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
323 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
324 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
322 | + if (!empty($posted['txn_id'])) { |
|
323 | + $invoice->add_note(sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
324 | + $invoice->set_transaction_id($posted['txn_id']); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | // Update the payment status. |
328 | 328 | $invoice->mark_paid(); |
329 | 329 | |
330 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
330 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
331 | 331 | |
332 | - wpinv_error_log( 'Subscription started.', false ); |
|
332 | + wpinv_error_log('Subscription started.', false); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
@@ -338,45 +338,45 @@ discard block |
||
338 | 338 | * @param WPInv_Invoice $invoice Invoice object. |
339 | 339 | * @param array $posted Posted data. |
340 | 340 | */ |
341 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
341 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
342 | 342 | |
343 | 343 | // Make sure the invoice has a subscription. |
344 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
344 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
345 | 345 | |
346 | - if ( empty( $subscription ) ) { |
|
347 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
346 | + if (empty($subscription)) { |
|
347 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
348 | 348 | } |
349 | 349 | |
350 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
350 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
351 | 351 | |
352 | 352 | // PayPal sends a subscr_payment for the first payment too. |
353 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
354 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
355 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
356 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
357 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
358 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
353 | + $date_completed = getpaid_format_date($invoice->get_date_completed()); |
|
354 | + $date_created = getpaid_format_date($invoice->get_date_created()); |
|
355 | + $today_date = getpaid_format_date(current_time('mysql')); |
|
356 | + $payment_date = getpaid_format_date($posted['payment_date']); |
|
357 | + $subscribe_date = getpaid_format_date($subscription->get_date_created()); |
|
358 | + $dates = array_filter(compact('date_completed', 'date_created', 'subscribe_date')); |
|
359 | 359 | |
360 | - foreach( $dates as $date ) { |
|
360 | + foreach ($dates as $date) { |
|
361 | 361 | |
362 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
362 | + if ($date !== $today_date && $date !== $payment_date) { |
|
363 | 363 | continue; |
364 | 364 | } |
365 | 365 | |
366 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
367 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
368 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
366 | + if (!empty($posted['txn_id'])) { |
|
367 | + $invoice->set_transaction_id(sanitize_text_field($posted['txn_id'])); |
|
368 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), sanitize_text_field($posted['txn_id'])), false, false, true); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | return $invoice->mark_paid(); |
372 | 372 | |
373 | 373 | } |
374 | 374 | |
375 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
375 | + wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false); |
|
376 | 376 | |
377 | 377 | // Abort if the payment is already recorded. |
378 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
379 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
378 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
379 | + return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false); |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | $args = array( |
@@ -384,17 +384,17 @@ discard block |
||
384 | 384 | 'gateway' => $this->id, |
385 | 385 | ); |
386 | 386 | |
387 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
387 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
388 | 388 | |
389 | - if ( empty( $invoice ) ) { |
|
389 | + if (empty($invoice)) { |
|
390 | 390 | return; |
391 | 391 | } |
392 | 392 | |
393 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
394 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
393 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
394 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
395 | 395 | |
396 | 396 | $subscription->renew(); |
397 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
397 | + wpinv_error_log('Subscription renewed.', false); |
|
398 | 398 | |
399 | 399 | } |
400 | 400 | |
@@ -403,18 +403,18 @@ discard block |
||
403 | 403 | * |
404 | 404 | * @param WPInv_Invoice $invoice Invoice object. |
405 | 405 | */ |
406 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
406 | + protected function ipn_txn_subscr_cancel($invoice) { |
|
407 | 407 | |
408 | 408 | // Make sure the invoice has a subscription. |
409 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
409 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
410 | 410 | |
411 | - if ( empty( $subscription ) ) { |
|
412 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
411 | + if (empty($subscription)) { |
|
412 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
413 | 413 | } |
414 | 414 | |
415 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
415 | + wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id(), false); |
|
416 | 416 | $subscription->cancel(); |
417 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
417 | + wpinv_error_log('Subscription cancelled.', false); |
|
418 | 418 | |
419 | 419 | } |
420 | 420 | |
@@ -424,18 +424,18 @@ discard block |
||
424 | 424 | * @param WPInv_Invoice $invoice Invoice object. |
425 | 425 | * @param array $posted Posted data. |
426 | 426 | */ |
427 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
427 | + protected function ipn_txn_subscr_eot($invoice) { |
|
428 | 428 | |
429 | 429 | // Make sure the invoice has a subscription. |
430 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
430 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
431 | 431 | |
432 | - if ( empty( $subscription ) ) { |
|
433 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
432 | + if (empty($subscription)) { |
|
433 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
434 | 434 | } |
435 | 435 | |
436 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
436 | + wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id(), false); |
|
437 | 437 | $subscription->complete(); |
438 | - wpinv_error_log( 'Subscription completed.', false ); |
|
438 | + wpinv_error_log('Subscription completed.', false); |
|
439 | 439 | |
440 | 440 | } |
441 | 441 | |
@@ -445,18 +445,18 @@ discard block |
||
445 | 445 | * @param WPInv_Invoice $invoice Invoice object. |
446 | 446 | * @param array $posted Posted data. |
447 | 447 | */ |
448 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
448 | + protected function ipn_txn_subscr_failed($invoice) { |
|
449 | 449 | |
450 | 450 | // Make sure the invoice has a subscription. |
451 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
451 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
452 | 452 | |
453 | - if ( empty( $subscription ) ) { |
|
454 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
453 | + if (empty($subscription)) { |
|
454 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
455 | 455 | } |
456 | 456 | |
457 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
457 | + wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id(), false); |
|
458 | 458 | $subscription->failing(); |
459 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
459 | + wpinv_error_log('Subscription marked as failing.', false); |
|
460 | 460 | |
461 | 461 | } |
462 | 462 | |
@@ -466,18 +466,18 @@ discard block |
||
466 | 466 | * @param WPInv_Invoice $invoice Invoice object. |
467 | 467 | * @param array $posted Posted data. |
468 | 468 | */ |
469 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
469 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment($invoice) { |
|
470 | 470 | |
471 | 471 | // Make sure the invoice has a subscription. |
472 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
472 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
473 | 473 | |
474 | - if ( empty( $subscription ) ) { |
|
475 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
474 | + if (empty($subscription)) { |
|
475 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
476 | 476 | } |
477 | 477 | |
478 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
478 | + wpinv_error_log('Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false); |
|
479 | 479 | $subscription->cancel(); |
480 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
480 | + wpinv_error_log('Subscription cancelled.', false); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | } |