@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | defined( 'ABSPATH' ) || exit; |
| 11 | 11 | |
| 12 | 12 | if ( empty( $fields ) ) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | // A prefix for all ids (so that a form can be included in the same page multiple times). |
@@ -18,12 +18,12 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | // Prepare the user's country. |
| 20 | 20 | if ( ! empty( $form->invoice ) ) { |
| 21 | - $country = $form->invoice->get_country(); |
|
| 21 | + $country = $form->invoice->get_country(); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | if ( empty( $country ) ) { |
| 25 | - $country = empty( $country ) ? getpaid_get_ip_country() : $country; |
|
| 26 | - $country = empty( $country ) ? wpinv_get_default_country() : $country; |
|
| 25 | + $country = empty( $country ) ? getpaid_get_ip_country() : $country; |
|
| 26 | + $country = empty( $country ) ? wpinv_get_default_country() : $country; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | // A prefix for all ids (so that a form can be included in the same page multiple times). |
@@ -55,10 +55,10 @@ discard block |
||
| 55 | 55 | <!-- Start Billing Address --> |
| 56 | 56 | <div class="getpaid-billing-address-wrapper"> |
| 57 | 57 | <?php |
| 58 | - $field_type = 'billing'; |
|
| 59 | - include plugin_dir_path( __FILE__ ) . 'address-fields.php'; |
|
| 60 | - do_action( 'getpaid_after_payment_form_billing_fields', $form ); |
|
| 61 | - ?> |
|
| 58 | + $field_type = 'billing'; |
|
| 59 | + include plugin_dir_path( __FILE__ ) . 'address-fields.php'; |
|
| 60 | + do_action( 'getpaid_after_payment_form_billing_fields', $form ); |
|
| 61 | + ?> |
|
| 62 | 62 | </div> |
| 63 | 63 | <!-- End Billing Address --> |
| 64 | 64 | |
@@ -70,19 +70,19 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | <?php |
| 72 | 72 | |
| 73 | - echo aui()->input( |
|
| 74 | - array( |
|
| 75 | - 'type' => 'checkbox', |
|
| 76 | - 'name' => 'same-shipping-address', |
|
| 77 | - 'id' => "shipping-toggle$uniqid", |
|
| 78 | - 'required' => false, |
|
| 79 | - 'label' => wp_kses_post( $shipping_address_toggle ), |
|
| 80 | - 'value' => 1, |
|
| 81 | - 'checked' => true, |
|
| 82 | - ) |
|
| 83 | - ); |
|
| 73 | + echo aui()->input( |
|
| 74 | + array( |
|
| 75 | + 'type' => 'checkbox', |
|
| 76 | + 'name' => 'same-shipping-address', |
|
| 77 | + 'id' => "shipping-toggle$uniqid", |
|
| 78 | + 'required' => false, |
|
| 79 | + 'label' => wp_kses_post( $shipping_address_toggle ), |
|
| 80 | + 'value' => 1, |
|
| 81 | + 'checked' => true, |
|
| 82 | + ) |
|
| 83 | + ); |
|
| 84 | 84 | |
| 85 | - ?> |
|
| 85 | + ?> |
|
| 86 | 86 | |
| 87 | 87 | |
| 88 | 88 | <!-- Start Shipping Address Title --> |
@@ -101,10 +101,10 @@ discard block |
||
| 101 | 101 | <!-- Start Shipping Address --> |
| 102 | 102 | <div class="getpaid-shipping-address-wrapper"> |
| 103 | 103 | <?php |
| 104 | - $field_type = 'shipping'; |
|
| 105 | - include plugin_dir_path( __FILE__ ) . 'address-fields.php'; |
|
| 106 | - do_action( 'getpaid_after_payment_form_shipping_fields', $form ); |
|
| 107 | - ?> |
|
| 104 | + $field_type = 'shipping'; |
|
| 105 | + include plugin_dir_path( __FILE__ ) . 'address-fields.php'; |
|
| 106 | + do_action( 'getpaid_after_payment_form_shipping_fields', $form ); |
|
| 107 | + ?> |
|
| 108 | 108 | </div> |
| 109 | 109 | <!-- End Shipping Address --> |
| 110 | 110 | |
@@ -12,180 +12,180 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Checkout { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var GetPaid_Payment_Form_Submission |
|
| 17 | - */ |
|
| 18 | - protected $payment_form_submission; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Class constructor. |
|
| 22 | - * |
|
| 23 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 24 | - */ |
|
| 25 | - public function __construct( $submission ) { |
|
| 26 | - $this->payment_form_submission = $submission; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Processes the checkout. |
|
| 31 | - * |
|
| 32 | - */ |
|
| 33 | - public function process_checkout() { |
|
| 34 | - |
|
| 35 | - // Validate the submission. |
|
| 36 | - $this->validate_submission(); |
|
| 37 | - |
|
| 38 | - // Prepare the invoice. |
|
| 39 | - $items = $this->get_submission_items(); |
|
| 40 | - $invoice = $this->get_submission_invoice(); |
|
| 41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
| 42 | - $prepared = $this->prepare_submission_data_for_saving(); |
|
| 43 | - |
|
| 44 | - $this->prepare_billing_info( $invoice ); |
|
| 45 | - |
|
| 46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
| 47 | - |
|
| 48 | - // Save the invoice. |
|
| 49 | - $invoice->set_is_viewed( true ); |
|
| 50 | - $invoice->recalculate_total(); |
|
| 15 | + /** |
|
| 16 | + * @var GetPaid_Payment_Form_Submission |
|
| 17 | + */ |
|
| 18 | + protected $payment_form_submission; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Class constructor. |
|
| 22 | + * |
|
| 23 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 24 | + */ |
|
| 25 | + public function __construct( $submission ) { |
|
| 26 | + $this->payment_form_submission = $submission; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Processes the checkout. |
|
| 31 | + * |
|
| 32 | + */ |
|
| 33 | + public function process_checkout() { |
|
| 34 | + |
|
| 35 | + // Validate the submission. |
|
| 36 | + $this->validate_submission(); |
|
| 37 | + |
|
| 38 | + // Prepare the invoice. |
|
| 39 | + $items = $this->get_submission_items(); |
|
| 40 | + $invoice = $this->get_submission_invoice(); |
|
| 41 | + $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
| 42 | + $prepared = $this->prepare_submission_data_for_saving(); |
|
| 43 | + |
|
| 44 | + $this->prepare_billing_info( $invoice ); |
|
| 45 | + |
|
| 46 | + $shipping = $this->prepare_shipping_info( $invoice ); |
|
| 47 | + |
|
| 48 | + // Save the invoice. |
|
| 49 | + $invoice->set_is_viewed( true ); |
|
| 50 | + $invoice->recalculate_total(); |
|
| 51 | 51 | $invoice->save(); |
| 52 | 52 | |
| 53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
| 53 | + do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
| 54 | 54 | |
| 55 | - // Send to the gateway. |
|
| 56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
| 57 | - } |
|
| 55 | + // Send to the gateway. |
|
| 56 | + $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Validates the submission. |
|
| 61 | - * |
|
| 62 | - */ |
|
| 63 | - protected function validate_submission() { |
|
| 59 | + /** |
|
| 60 | + * Validates the submission. |
|
| 61 | + * |
|
| 62 | + */ |
|
| 63 | + protected function validate_submission() { |
|
| 64 | 64 | |
| 65 | - $submission = $this->payment_form_submission; |
|
| 66 | - $data = $submission->get_data(); |
|
| 65 | + $submission = $this->payment_form_submission; |
|
| 66 | + $data = $submission->get_data(); |
|
| 67 | 67 | |
| 68 | - // Do we have an error? |
|
| 68 | + // Do we have an error? |
|
| 69 | 69 | if ( ! empty( $submission->last_error ) ) { |
| 70 | - wp_send_json_error( $submission->last_error ); |
|
| 70 | + wp_send_json_error( $submission->last_error ); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - // We need a billing email. |
|
| 73 | + // We need a billing email. |
|
| 74 | 74 | if ( ! $submission->has_billing_email() ) { |
| 75 | 75 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
| 76 | - } |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
| 79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
| 80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
| 81 | - } |
|
| 78 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
| 79 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
| 80 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - // Ensure the gateway is active. |
|
| 84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
| 85 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
| 86 | - } |
|
| 83 | + // Ensure the gateway is active. |
|
| 84 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
| 85 | + wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - // Clear any existing errors. |
|
| 89 | - wpinv_clear_errors(); |
|
| 88 | + // Clear any existing errors. |
|
| 89 | + wpinv_clear_errors(); |
|
| 90 | 90 | |
| 91 | - // Allow themes and plugins to hook to errors |
|
| 92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
| 91 | + // Allow themes and plugins to hook to errors |
|
| 92 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
| 93 | 93 | |
| 94 | - // Do we have any errors? |
|
| 94 | + // Do we have any errors? |
|
| 95 | 95 | if ( wpinv_get_errors() ) { |
| 96 | 96 | wp_send_json_error( getpaid_get_errors_html() ); |
| 97 | - } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Retrieves submission items. |
|
| 103 | - * |
|
| 104 | - * @return GetPaid_Form_Item[] |
|
| 105 | - */ |
|
| 106 | - protected function get_submission_items() { |
|
| 101 | + /** |
|
| 102 | + * Retrieves submission items. |
|
| 103 | + * |
|
| 104 | + * @return GetPaid_Form_Item[] |
|
| 105 | + */ |
|
| 106 | + protected function get_submission_items() { |
|
| 107 | 107 | |
| 108 | - $items = $this->payment_form_submission->get_items(); |
|
| 108 | + $items = $this->payment_form_submission->get_items(); |
|
| 109 | 109 | |
| 110 | 110 | // Ensure that we have items. |
| 111 | 111 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
| 112 | 112 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
| 113 | - } |
|
| 114 | - |
|
| 115 | - return $items; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Retrieves submission invoice. |
|
| 120 | - * |
|
| 121 | - * @return WPInv_Invoice |
|
| 122 | - */ |
|
| 123 | - protected function get_submission_invoice() { |
|
| 124 | - $submission = $this->payment_form_submission; |
|
| 125 | - |
|
| 126 | - if ( ! $submission->has_invoice() ) { |
|
| 127 | - $invoice = new WPInv_Invoice(); |
|
| 128 | - $invoice->created_via( 'payment_form' ); |
|
| 129 | - return $invoice; |
|
| 130 | 113 | } |
| 131 | 114 | |
| 132 | - $invoice = $submission->get_invoice(); |
|
| 115 | + return $items; |
|
| 116 | + } |
|
| 133 | 117 | |
| 134 | - // Make sure that it is neither paid or refunded. |
|
| 135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
| 137 | - } |
|
| 118 | + /** |
|
| 119 | + * Retrieves submission invoice. |
|
| 120 | + * |
|
| 121 | + * @return WPInv_Invoice |
|
| 122 | + */ |
|
| 123 | + protected function get_submission_invoice() { |
|
| 124 | + $submission = $this->payment_form_submission; |
|
| 138 | 125 | |
| 139 | - return $invoice; |
|
| 140 | - } |
|
| 126 | + if ( ! $submission->has_invoice() ) { |
|
| 127 | + $invoice = new WPInv_Invoice(); |
|
| 128 | + $invoice->created_via( 'payment_form' ); |
|
| 129 | + return $invoice; |
|
| 130 | + } |
|
| 141 | 131 | |
| 142 | - /** |
|
| 143 | - * Processes the submission invoice. |
|
| 144 | - * |
|
| 145 | - * @param WPInv_Invoice $invoice |
|
| 146 | - * @param GetPaid_Form_Item[] $items |
|
| 147 | - * @return WPInv_Invoice |
|
| 148 | - */ |
|
| 149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
| 132 | + $invoice = $submission->get_invoice(); |
|
| 150 | 133 | |
| 151 | - $submission = $this->payment_form_submission; |
|
| 152 | - $data = $submission->get_data(); |
|
| 134 | + // Make sure that it is neither paid or refunded. |
|
| 135 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 136 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
| 137 | + } |
|
| 153 | 138 | |
| 154 | - // Set-up the invoice details. |
|
| 155 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
| 156 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
| 157 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
| 139 | + return $invoice; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Processes the submission invoice. |
|
| 144 | + * |
|
| 145 | + * @param WPInv_Invoice $invoice |
|
| 146 | + * @param GetPaid_Form_Item[] $items |
|
| 147 | + * @return WPInv_Invoice |
|
| 148 | + */ |
|
| 149 | + protected function process_submission_invoice( $invoice, $items ) { |
|
| 150 | + |
|
| 151 | + $submission = $this->payment_form_submission; |
|
| 152 | + $data = $submission->get_data(); |
|
| 153 | + |
|
| 154 | + // Set-up the invoice details. |
|
| 155 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
| 156 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
| 157 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
| 158 | 158 | $invoice->set_items( $items ); |
| 159 | 159 | $invoice->set_fees( $submission->get_fees() ); |
| 160 | 160 | $invoice->set_taxes( $submission->get_taxes() ); |
| 161 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
| 162 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
| 161 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
| 162 | + $invoice->set_gateway( $data['wpi-gateway'] ); |
|
| 163 | 163 | |
| 164 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
| 165 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
| 164 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
| 165 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
| 166 | 166 | |
| 167 | - if ( $submission->has_discount_code() ) { |
|
| 167 | + if ( $submission->has_discount_code() ) { |
|
| 168 | 168 | $invoice->set_discount_code( $submission->get_discount_code() ); |
| 169 | - } |
|
| 170 | - |
|
| 171 | - getpaid_maybe_add_default_address( $invoice ); |
|
| 172 | - return $invoice; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Retrieves the submission's customer. |
|
| 177 | - * |
|
| 178 | - * @return int The customer id. |
|
| 179 | - */ |
|
| 180 | - protected function get_submission_customer() { |
|
| 181 | - $submission = $this->payment_form_submission; |
|
| 182 | - |
|
| 183 | - // If this is an existing invoice... |
|
| 184 | - if ( $submission->has_invoice() ) { |
|
| 185 | - return $submission->get_invoice()->get_user_id(); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // (Maybe) create the user. |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + getpaid_maybe_add_default_address( $invoice ); |
|
| 172 | + return $invoice; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Retrieves the submission's customer. |
|
| 177 | + * |
|
| 178 | + * @return int The customer id. |
|
| 179 | + */ |
|
| 180 | + protected function get_submission_customer() { |
|
| 181 | + $submission = $this->payment_form_submission; |
|
| 182 | + |
|
| 183 | + // If this is an existing invoice... |
|
| 184 | + if ( $submission->has_invoice() ) { |
|
| 185 | + return $submission->get_invoice()->get_user_id(); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // (Maybe) create the user. |
|
| 189 | 189 | $user = get_current_user_id(); |
| 190 | 190 | |
| 191 | 191 | if ( empty( $user ) ) { |
@@ -202,31 +202,31 @@ discard block |
||
| 202 | 202 | |
| 203 | 203 | if ( is_numeric( $user ) ) { |
| 204 | 204 | return $user; |
| 205 | - } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - return $user->ID; |
|
| 207 | + return $user->ID; |
|
| 208 | 208 | |
| 209 | - } |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - /** |
|
| 211 | + /** |
|
| 212 | 212 | * Prepares submission data for saving to the database. |
| 213 | 213 | * |
| 214 | - * @return array |
|
| 214 | + * @return array |
|
| 215 | 215 | */ |
| 216 | 216 | public function prepare_submission_data_for_saving() { |
| 217 | 217 | |
| 218 | - $submission = $this->payment_form_submission; |
|
| 218 | + $submission = $this->payment_form_submission; |
|
| 219 | 219 | |
| 220 | - // Prepared submission details. |
|
| 220 | + // Prepared submission details. |
|
| 221 | 221 | $prepared = array(); |
| 222 | 222 | |
| 223 | 223 | // Raw submission details. |
| 224 | - $data = $submission->get_data(); |
|
| 224 | + $data = $submission->get_data(); |
|
| 225 | 225 | |
| 226 | - // Loop through the submitted details. |
|
| 226 | + // Loop through the submitted details. |
|
| 227 | 227 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
| 228 | 228 | |
| 229 | - // Skip premade fields. |
|
| 229 | + // Skip premade fields. |
|
| 230 | 230 | if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) { |
| 231 | 231 | continue; |
| 232 | 232 | } |
@@ -244,93 +244,93 @@ discard block |
||
| 244 | 244 | $label = $field['label']; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] ); |
|
| 247 | + $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] ); |
|
| 248 | 248 | |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - } |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - return $prepared; |
|
| 253 | + return $prepared; |
|
| 254 | 254 | |
| 255 | - } |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - /** |
|
| 257 | + /** |
|
| 258 | 258 | * Retrieves address details. |
| 259 | 259 | * |
| 260 | - * @return array |
|
| 261 | - * @param WPInv_Invoice $invoice |
|
| 262 | - * @param string $type |
|
| 260 | + * @return array |
|
| 261 | + * @param WPInv_Invoice $invoice |
|
| 262 | + * @param string $type |
|
| 263 | 263 | */ |
| 264 | 264 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
| 265 | 265 | |
| 266 | - $data = $this->payment_form_submission->get_data(); |
|
| 267 | - $type = sanitize_key( $type ); |
|
| 268 | - $address = array(); |
|
| 269 | - $prepared = array(); |
|
| 266 | + $data = $this->payment_form_submission->get_data(); |
|
| 267 | + $type = sanitize_key( $type ); |
|
| 268 | + $address = array(); |
|
| 269 | + $prepared = array(); |
|
| 270 | 270 | |
| 271 | - if ( ! empty( $data[ $type ] ) ) { |
|
| 272 | - $address = $data[ $type ]; |
|
| 273 | - } |
|
| 271 | + if ( ! empty( $data[ $type ] ) ) { |
|
| 272 | + $address = $data[ $type ]; |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - // Clean address details. |
|
| 276 | - foreach ( $address as $key => $value ) { |
|
| 277 | - $key = sanitize_key( $key ); |
|
| 278 | - $key = str_replace( 'wpinv_', '', $key ); |
|
| 279 | - $value = wpinv_clean( $value ); |
|
| 280 | - $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
| 281 | - } |
|
| 275 | + // Clean address details. |
|
| 276 | + foreach ( $address as $key => $value ) { |
|
| 277 | + $key = sanitize_key( $key ); |
|
| 278 | + $key = str_replace( 'wpinv_', '', $key ); |
|
| 279 | + $value = wpinv_clean( $value ); |
|
| 280 | + $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - // Filter address details. |
|
| 284 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
| 283 | + // Filter address details. |
|
| 284 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
| 285 | 285 | |
| 286 | - // Remove non-whitelisted values. |
|
| 287 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
| 286 | + // Remove non-whitelisted values. |
|
| 287 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
| 288 | 288 | |
| 289 | - } |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - /** |
|
| 291 | + /** |
|
| 292 | 292 | * Prepares the billing details. |
| 293 | 293 | * |
| 294 | - * @return array |
|
| 295 | - * @param WPInv_Invoice $invoice |
|
| 294 | + * @return array |
|
| 295 | + * @param WPInv_Invoice $invoice |
|
| 296 | 296 | */ |
| 297 | 297 | protected function prepare_billing_info( &$invoice ) { |
| 298 | 298 | |
| 299 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
| 299 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
| 300 | 300 | |
| 301 | - // Update the invoice with the billing details. |
|
| 302 | - $invoice->set_props( $billing_address ); |
|
| 301 | + // Update the invoice with the billing details. |
|
| 302 | + $invoice->set_props( $billing_address ); |
|
| 303 | 303 | |
| 304 | - } |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - /** |
|
| 306 | + /** |
|
| 307 | 307 | * Prepares the shipping details. |
| 308 | 308 | * |
| 309 | - * @return array |
|
| 310 | - * @param WPInv_Invoice $invoice |
|
| 309 | + * @return array |
|
| 310 | + * @param WPInv_Invoice $invoice |
|
| 311 | 311 | */ |
| 312 | 312 | protected function prepare_shipping_info( $invoice ) { |
| 313 | 313 | |
| 314 | - $data = $this->payment_form_submission->get_data(); |
|
| 314 | + $data = $this->payment_form_submission->get_data(); |
|
| 315 | 315 | |
| 316 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
| 317 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
| 318 | - } |
|
| 316 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
| 317 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
| 320 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
| 321 | 321 | |
| 322 | - } |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - /** |
|
| 325 | - * Confirms the submission is valid and send users to the gateway. |
|
| 326 | - * |
|
| 327 | - * @param WPInv_Invoice $invoice |
|
| 328 | - * @param array $prepared_payment_form_data |
|
| 329 | - * @param array $shipping |
|
| 330 | - */ |
|
| 331 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
| 324 | + /** |
|
| 325 | + * Confirms the submission is valid and send users to the gateway. |
|
| 326 | + * |
|
| 327 | + * @param WPInv_Invoice $invoice |
|
| 328 | + * @param array $prepared_payment_form_data |
|
| 329 | + * @param array $shipping |
|
| 330 | + */ |
|
| 331 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
| 332 | 332 | |
| 333 | - // Ensure the invoice exists. |
|
| 333 | + // Ensure the invoice exists. |
|
| 334 | 334 | if ( ! $invoice->exists() ) { |
| 335 | 335 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
| 336 | 336 | } |
@@ -338,81 +338,81 @@ discard block |
||
| 338 | 338 | // Save payment form data. |
| 339 | 339 | if ( ! empty( $prepared_payment_form_data ) ) { |
| 340 | 340 | update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data ); |
| 341 | - } |
|
| 341 | + } |
|
| 342 | 342 | |
| 343 | - // Save payment form data. |
|
| 343 | + // Save payment form data. |
|
| 344 | 344 | if ( ! empty( $shipping ) ) { |
| 345 | 345 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
| 346 | - } |
|
| 346 | + } |
|
| 347 | 347 | |
| 348 | - // Backwards compatibility. |
|
| 348 | + // Backwards compatibility. |
|
| 349 | 349 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
| 350 | 350 | |
| 351 | - $this->process_payment( $invoice ); |
|
| 351 | + $this->process_payment( $invoice ); |
|
| 352 | 352 | |
| 353 | 353 | // If we are here, there was an error. |
| 354 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 354 | + wpinv_send_back_to_checkout( $invoice ); |
|
| 355 | 355 | |
| 356 | - } |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | - /** |
|
| 359 | - * Processes the actual payment. |
|
| 360 | - * |
|
| 361 | - * @param WPInv_Invoice $invoice |
|
| 362 | - */ |
|
| 363 | - protected function process_payment( $invoice ) { |
|
| 358 | + /** |
|
| 359 | + * Processes the actual payment. |
|
| 360 | + * |
|
| 361 | + * @param WPInv_Invoice $invoice |
|
| 362 | + */ |
|
| 363 | + protected function process_payment( $invoice ) { |
|
| 364 | 364 | |
| 365 | - // Clear any checkout errors. |
|
| 366 | - wpinv_clear_errors(); |
|
| 365 | + // Clear any checkout errors. |
|
| 366 | + wpinv_clear_errors(); |
|
| 367 | 367 | |
| 368 | - // No need to send free invoices to the gateway. |
|
| 369 | - if ( $invoice->is_free() ) { |
|
| 370 | - $this->process_free_payment( $invoice ); |
|
| 371 | - } |
|
| 368 | + // No need to send free invoices to the gateway. |
|
| 369 | + if ( $invoice->is_free() ) { |
|
| 370 | + $this->process_free_payment( $invoice ); |
|
| 371 | + } |
|
| 372 | 372 | |
| 373 | - $submission = $this->payment_form_submission; |
|
| 373 | + $submission = $this->payment_form_submission; |
|
| 374 | 374 | |
| 375 | - // Fires before sending to the gateway. |
|
| 376 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
| 375 | + // Fires before sending to the gateway. |
|
| 376 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
| 377 | 377 | |
| 378 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
| 379 | - $submission_data = $submission->get_data(); |
|
| 380 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
| 381 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
| 378 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
| 379 | + $submission_data = $submission->get_data(); |
|
| 380 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
| 381 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
| 382 | 382 | |
| 383 | - // Validate the currency. |
|
| 384 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
| 385 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
| 386 | - } |
|
| 383 | + // Validate the currency. |
|
| 384 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
| 385 | + wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
| 386 | + } |
|
| 387 | 387 | |
| 388 | - // Check to see if we have any errors. |
|
| 389 | - if ( wpinv_get_errors() ) { |
|
| 390 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 391 | - } |
|
| 388 | + // Check to see if we have any errors. |
|
| 389 | + if ( wpinv_get_errors() ) { |
|
| 390 | + wpinv_send_back_to_checkout( $invoice ); |
|
| 391 | + } |
|
| 392 | 392 | |
| 393 | - // Send info to the gateway for payment processing |
|
| 394 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
| 393 | + // Send info to the gateway for payment processing |
|
| 394 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
| 395 | 395 | |
| 396 | - // Backwards compatibility. |
|
| 397 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
| 396 | + // Backwards compatibility. |
|
| 397 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
| 398 | 398 | |
| 399 | - } |
|
| 399 | + } |
|
| 400 | 400 | |
| 401 | - /** |
|
| 402 | - * Marks the invoice as paid in case the checkout is free. |
|
| 403 | - * |
|
| 404 | - * @param WPInv_Invoice $invoice |
|
| 405 | - */ |
|
| 406 | - protected function process_free_payment( $invoice ) { |
|
| 401 | + /** |
|
| 402 | + * Marks the invoice as paid in case the checkout is free. |
|
| 403 | + * |
|
| 404 | + * @param WPInv_Invoice $invoice |
|
| 405 | + */ |
|
| 406 | + protected function process_free_payment( $invoice ) { |
|
| 407 | 407 | |
| 408 | - $invoice->set_gateway( 'none' ); |
|
| 409 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
| 410 | - $invoice->mark_paid(); |
|
| 411 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 408 | + $invoice->set_gateway( 'none' ); |
|
| 409 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
| 410 | + $invoice->mark_paid(); |
|
| 411 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 412 | 412 | |
| 413 | - } |
|
| 413 | + } |
|
| 414 | 414 | |
| 415 | - /** |
|
| 415 | + /** |
|
| 416 | 416 | * Sends a redrect response to payment details. |
| 417 | 417 | * |
| 418 | 418 | */ |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,187 +10,187 @@ discard block |
||
| 10 | 10 | class GetPaid_Payment_Form_Submission { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Submission ID |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - public $id = null; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * The raw submission data. |
|
| 21 | - * |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $data = null; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Submission totals |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $totals = array( |
|
| 32 | - |
|
| 33 | - 'subtotal' => array( |
|
| 34 | - 'initial' => 0, |
|
| 35 | - 'recurring' => 0, |
|
| 36 | - ), |
|
| 37 | - |
|
| 38 | - 'discount' => array( |
|
| 39 | - 'initial' => 0, |
|
| 40 | - 'recurring' => 0, |
|
| 41 | - ), |
|
| 42 | - |
|
| 43 | - 'fees' => array( |
|
| 44 | - 'initial' => 0, |
|
| 45 | - 'recurring' => 0, |
|
| 46 | - ), |
|
| 47 | - |
|
| 48 | - 'taxes' => array( |
|
| 49 | - 'initial' => 0, |
|
| 50 | - 'recurring' => 0, |
|
| 51 | - ), |
|
| 52 | - |
|
| 53 | - ); |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Sets the associated payment form. |
|
| 57 | - * |
|
| 58 | - * @var GetPaid_Payment_Form |
|
| 59 | - */ |
|
| 13 | + * Submission ID |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + public $id = null; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * The raw submission data. |
|
| 21 | + * |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $data = null; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Submission totals |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $totals = array( |
|
| 32 | + |
|
| 33 | + 'subtotal' => array( |
|
| 34 | + 'initial' => 0, |
|
| 35 | + 'recurring' => 0, |
|
| 36 | + ), |
|
| 37 | + |
|
| 38 | + 'discount' => array( |
|
| 39 | + 'initial' => 0, |
|
| 40 | + 'recurring' => 0, |
|
| 41 | + ), |
|
| 42 | + |
|
| 43 | + 'fees' => array( |
|
| 44 | + 'initial' => 0, |
|
| 45 | + 'recurring' => 0, |
|
| 46 | + ), |
|
| 47 | + |
|
| 48 | + 'taxes' => array( |
|
| 49 | + 'initial' => 0, |
|
| 50 | + 'recurring' => 0, |
|
| 51 | + ), |
|
| 52 | + |
|
| 53 | + ); |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Sets the associated payment form. |
|
| 57 | + * |
|
| 58 | + * @var GetPaid_Payment_Form |
|
| 59 | + */ |
|
| 60 | 60 | protected $payment_form = null; |
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | - * The country for the submission. |
|
| 64 | - * |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 67 | - public $country = null; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * The state for the submission. |
|
| 71 | - * |
|
| 72 | - * @since 1.0.19 |
|
| 73 | - * @var string |
|
| 74 | - */ |
|
| 75 | - public $state = null; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * The invoice associated with the submission. |
|
| 79 | - * |
|
| 80 | - * @var WPInv_Invoice |
|
| 81 | - */ |
|
| 82 | - protected $invoice = null; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * The recurring item for the submission. |
|
| 86 | - * |
|
| 87 | - * @var int |
|
| 88 | - */ |
|
| 89 | - public $has_recurring = 0; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * An array of fees for the submission. |
|
| 93 | - * |
|
| 94 | - * @var array |
|
| 95 | - */ |
|
| 96 | - protected $fees = array(); |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * An array of discounts for the submission. |
|
| 100 | - * |
|
| 101 | - * @var array |
|
| 102 | - */ |
|
| 103 | - protected $discounts = array(); |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * An array of taxes for the submission. |
|
| 107 | - * |
|
| 108 | - * @var array |
|
| 109 | - */ |
|
| 110 | - protected $taxes = array(); |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * An array of items for the submission. |
|
| 114 | - * |
|
| 115 | - * @var GetPaid_Form_Item[] |
|
| 116 | - */ |
|
| 117 | - protected $items = array(); |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * The last error. |
|
| 121 | - * |
|
| 122 | - * @var string |
|
| 123 | - */ |
|
| 124 | - public $last_error = null; |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Class constructor. |
|
| 128 | - * |
|
| 129 | - */ |
|
| 130 | - public function __construct() { |
|
| 131 | - |
|
| 132 | - // Set the state and country to the default state and country. |
|
| 133 | - $this->country = wpinv_default_billing_country(); |
|
| 134 | - $this->state = wpinv_get_default_state(); |
|
| 135 | - |
|
| 136 | - // Do we have an actual submission? |
|
| 137 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 138 | - $this->load_data( $_POST ); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Loads submission data. |
|
| 145 | - * |
|
| 146 | - * @param array $data |
|
| 147 | - */ |
|
| 148 | - public function load_data( $data ) { |
|
| 149 | - |
|
| 150 | - // Remove slashes from the submitted data... |
|
| 151 | - $data = wp_unslash( $data ); |
|
| 152 | - |
|
| 153 | - // Allow plugins to filter the data. |
|
| 154 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 155 | - |
|
| 156 | - // Cache it... |
|
| 157 | - $this->data = $data; |
|
| 158 | - |
|
| 159 | - // Then generate a unique id from the data. |
|
| 160 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 161 | - |
|
| 162 | - // Finally, process the submission. |
|
| 163 | - try { |
|
| 164 | - |
|
| 165 | - // Each process is passed an instance of the class (with reference) |
|
| 166 | - // and should throw an Exception whenever it encounters one. |
|
| 167 | - $processors = apply_filters( |
|
| 168 | - 'getpaid_payment_form_submission_processors', |
|
| 169 | - array( |
|
| 170 | - array( $this, 'process_payment_form' ), |
|
| 171 | - array( $this, 'process_invoice' ), |
|
| 172 | - array( $this, 'process_fees' ), |
|
| 173 | - array( $this, 'process_items' ), |
|
| 174 | - array( $this, 'process_taxes' ), |
|
| 175 | - array( $this, 'process_discount' ), |
|
| 176 | - ), |
|
| 177 | - $this |
|
| 178 | - ); |
|
| 179 | - |
|
| 180 | - foreach ( $processors as $processor ) { |
|
| 181 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - } catch ( Exception $e ) { |
|
| 185 | - $this->last_error = $e->getMessage(); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // Fired when we are done processing a submission. |
|
| 189 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 190 | - |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /* |
|
| 63 | + * The country for the submission. |
|
| 64 | + * |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | + public $country = null; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * The state for the submission. |
|
| 71 | + * |
|
| 72 | + * @since 1.0.19 |
|
| 73 | + * @var string |
|
| 74 | + */ |
|
| 75 | + public $state = null; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * The invoice associated with the submission. |
|
| 79 | + * |
|
| 80 | + * @var WPInv_Invoice |
|
| 81 | + */ |
|
| 82 | + protected $invoice = null; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * The recurring item for the submission. |
|
| 86 | + * |
|
| 87 | + * @var int |
|
| 88 | + */ |
|
| 89 | + public $has_recurring = 0; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * An array of fees for the submission. |
|
| 93 | + * |
|
| 94 | + * @var array |
|
| 95 | + */ |
|
| 96 | + protected $fees = array(); |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * An array of discounts for the submission. |
|
| 100 | + * |
|
| 101 | + * @var array |
|
| 102 | + */ |
|
| 103 | + protected $discounts = array(); |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * An array of taxes for the submission. |
|
| 107 | + * |
|
| 108 | + * @var array |
|
| 109 | + */ |
|
| 110 | + protected $taxes = array(); |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * An array of items for the submission. |
|
| 114 | + * |
|
| 115 | + * @var GetPaid_Form_Item[] |
|
| 116 | + */ |
|
| 117 | + protected $items = array(); |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * The last error. |
|
| 121 | + * |
|
| 122 | + * @var string |
|
| 123 | + */ |
|
| 124 | + public $last_error = null; |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Class constructor. |
|
| 128 | + * |
|
| 129 | + */ |
|
| 130 | + public function __construct() { |
|
| 131 | + |
|
| 132 | + // Set the state and country to the default state and country. |
|
| 133 | + $this->country = wpinv_default_billing_country(); |
|
| 134 | + $this->state = wpinv_get_default_state(); |
|
| 135 | + |
|
| 136 | + // Do we have an actual submission? |
|
| 137 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 138 | + $this->load_data( $_POST ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Loads submission data. |
|
| 145 | + * |
|
| 146 | + * @param array $data |
|
| 147 | + */ |
|
| 148 | + public function load_data( $data ) { |
|
| 149 | + |
|
| 150 | + // Remove slashes from the submitted data... |
|
| 151 | + $data = wp_unslash( $data ); |
|
| 152 | + |
|
| 153 | + // Allow plugins to filter the data. |
|
| 154 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 155 | + |
|
| 156 | + // Cache it... |
|
| 157 | + $this->data = $data; |
|
| 158 | + |
|
| 159 | + // Then generate a unique id from the data. |
|
| 160 | + $this->id = md5( wp_json_encode( $data ) ); |
|
| 161 | + |
|
| 162 | + // Finally, process the submission. |
|
| 163 | + try { |
|
| 164 | + |
|
| 165 | + // Each process is passed an instance of the class (with reference) |
|
| 166 | + // and should throw an Exception whenever it encounters one. |
|
| 167 | + $processors = apply_filters( |
|
| 168 | + 'getpaid_payment_form_submission_processors', |
|
| 169 | + array( |
|
| 170 | + array( $this, 'process_payment_form' ), |
|
| 171 | + array( $this, 'process_invoice' ), |
|
| 172 | + array( $this, 'process_fees' ), |
|
| 173 | + array( $this, 'process_items' ), |
|
| 174 | + array( $this, 'process_taxes' ), |
|
| 175 | + array( $this, 'process_discount' ), |
|
| 176 | + ), |
|
| 177 | + $this |
|
| 178 | + ); |
|
| 179 | + |
|
| 180 | + foreach ( $processors as $processor ) { |
|
| 181 | + call_user_func_array( $processor, array( &$this ) ); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + } catch ( Exception $e ) { |
|
| 185 | + $this->last_error = $e->getMessage(); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // Fired when we are done processing a submission. |
|
| 189 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 190 | + |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /* |
|
| 194 | 194 | |-------------------------------------------------------------------------- |
| 195 | 195 | | Payment Forms. |
| 196 | 196 | |-------------------------------------------------------------------------- |
@@ -199,39 +199,39 @@ discard block |
||
| 199 | 199 | | submission has an active payment form etc. |
| 200 | 200 | */ |
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * Prepares the submission's payment form. |
|
| 204 | - * |
|
| 205 | - * @since 1.0.19 |
|
| 206 | - */ |
|
| 207 | - public function process_payment_form() { |
|
| 202 | + /** |
|
| 203 | + * Prepares the submission's payment form. |
|
| 204 | + * |
|
| 205 | + * @since 1.0.19 |
|
| 206 | + */ |
|
| 207 | + public function process_payment_form() { |
|
| 208 | 208 | |
| 209 | - // Every submission needs an active payment form. |
|
| 210 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 211 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 212 | - } |
|
| 209 | + // Every submission needs an active payment form. |
|
| 210 | + if ( empty( $this->data['form_id'] ) ) { |
|
| 211 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - // Fetch the payment form. |
|
| 215 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 214 | + // Fetch the payment form. |
|
| 215 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 216 | 216 | |
| 217 | - if ( ! $this->payment_form->is_active() ) { |
|
| 218 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 219 | - } |
|
| 217 | + if ( ! $this->payment_form->is_active() ) { |
|
| 218 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 222 | - } |
|
| 221 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | 224 | /** |
| 225 | - * Returns the payment form. |
|
| 226 | - * |
|
| 227 | - * @since 1.0.19 |
|
| 228 | - * @return GetPaid_Payment_Form |
|
| 229 | - */ |
|
| 230 | - public function get_payment_form() { |
|
| 231 | - return $this->payment_form; |
|
| 232 | - } |
|
| 225 | + * Returns the payment form. |
|
| 226 | + * |
|
| 227 | + * @since 1.0.19 |
|
| 228 | + * @return GetPaid_Payment_Form |
|
| 229 | + */ |
|
| 230 | + public function get_payment_form() { |
|
| 231 | + return $this->payment_form; |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - /* |
|
| 234 | + /* |
|
| 235 | 235 | |-------------------------------------------------------------------------- |
| 236 | 236 | | Invoices. |
| 237 | 237 | |-------------------------------------------------------------------------- |
@@ -240,61 +240,61 @@ discard block |
||
| 240 | 240 | | might be for an existing invoice. |
| 241 | 241 | */ |
| 242 | 242 | |
| 243 | - /** |
|
| 244 | - * Prepares the submission's invoice. |
|
| 245 | - * |
|
| 246 | - * @since 1.0.19 |
|
| 247 | - */ |
|
| 248 | - public function process_invoice() { |
|
| 243 | + /** |
|
| 244 | + * Prepares the submission's invoice. |
|
| 245 | + * |
|
| 246 | + * @since 1.0.19 |
|
| 247 | + */ |
|
| 248 | + public function process_invoice() { |
|
| 249 | 249 | |
| 250 | - // Abort if there is no invoice. |
|
| 251 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 252 | - return; |
|
| 253 | - } |
|
| 250 | + // Abort if there is no invoice. |
|
| 251 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
| 252 | + return; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - // If the submission is for an existing invoice, ensure that it exists |
|
| 256 | - // and that it is not paid for. |
|
| 257 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 255 | + // If the submission is for an existing invoice, ensure that it exists |
|
| 256 | + // and that it is not paid for. |
|
| 257 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 258 | 258 | |
| 259 | 259 | if ( empty( $invoice ) ) { |
| 260 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - if ( $invoice->is_paid() ) { |
|
| 264 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 268 | - $this->payment_form->invoice = $invoice; |
|
| 269 | - |
|
| 270 | - $this->country = $invoice->get_country(); |
|
| 271 | - $this->state = $invoice->get_state(); |
|
| 272 | - $this->invoice = $invoice; |
|
| 273 | - |
|
| 274 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Returns the associated invoice. |
|
| 279 | - * |
|
| 280 | - * @since 1.0.19 |
|
| 281 | - * @return WPInv_Invoice |
|
| 282 | - */ |
|
| 283 | - public function get_invoice() { |
|
| 284 | - return $this->invoice; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Checks whether there is an invoice associated with this submission. |
|
| 289 | - * |
|
| 290 | - * @since 1.0.19 |
|
| 291 | - * @return bool |
|
| 292 | - */ |
|
| 293 | - public function has_invoice() { |
|
| 294 | - return ! empty( $this->invoice ); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /* |
|
| 260 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + if ( $invoice->is_paid() ) { |
|
| 264 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
| 268 | + $this->payment_form->invoice = $invoice; |
|
| 269 | + |
|
| 270 | + $this->country = $invoice->get_country(); |
|
| 271 | + $this->state = $invoice->get_state(); |
|
| 272 | + $this->invoice = $invoice; |
|
| 273 | + |
|
| 274 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Returns the associated invoice. |
|
| 279 | + * |
|
| 280 | + * @since 1.0.19 |
|
| 281 | + * @return WPInv_Invoice |
|
| 282 | + */ |
|
| 283 | + public function get_invoice() { |
|
| 284 | + return $this->invoice; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * Checks whether there is an invoice associated with this submission. |
|
| 289 | + * |
|
| 290 | + * @since 1.0.19 |
|
| 291 | + * @return bool |
|
| 292 | + */ |
|
| 293 | + public function has_invoice() { |
|
| 294 | + return ! empty( $this->invoice ); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /* |
|
| 298 | 298 | |-------------------------------------------------------------------------- |
| 299 | 299 | | Items. |
| 300 | 300 | |-------------------------------------------------------------------------- |
@@ -303,115 +303,115 @@ discard block |
||
| 303 | 303 | | recurring item. But can have an unlimited number of non-recurring items. |
| 304 | 304 | */ |
| 305 | 305 | |
| 306 | - /** |
|
| 307 | - * Prepares the submission's items. |
|
| 308 | - * |
|
| 309 | - * @since 1.0.19 |
|
| 310 | - */ |
|
| 311 | - public function process_items() { |
|
| 312 | - |
|
| 313 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 314 | - |
|
| 315 | - foreach ( $processor->items as $item ) { |
|
| 316 | - $this->add_item( $item ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Adds an item to the submission. |
|
| 324 | - * |
|
| 325 | - * @since 1.0.19 |
|
| 326 | - * @param GetPaid_Form_Item $item |
|
| 327 | - */ |
|
| 328 | - public function add_item( $item ) { |
|
| 329 | - |
|
| 330 | - // Make sure that it is available for purchase. |
|
| 331 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 332 | - return; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - // Each submission can only contain one recurring item. |
|
| 336 | - if ( $item->is_recurring() ) { |
|
| 337 | - |
|
| 338 | - if ( $this->has_recurring != 0 ) { |
|
| 339 | - throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - $this->has_recurring = $item->get_id(); |
|
| 343 | - |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - // Update the items and totals. |
|
| 347 | - $this->items[ $item->get_id() ] = $item; |
|
| 348 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 349 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 350 | - |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * Removes a specific item. |
|
| 355 | - * |
|
| 356 | - * You should not call this method after the discounts and taxes |
|
| 357 | - * have been calculated. |
|
| 358 | - * |
|
| 359 | - * @since 1.0.19 |
|
| 360 | - */ |
|
| 361 | - public function remove_item( $item_id ) { |
|
| 362 | - |
|
| 363 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 364 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 365 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 366 | - |
|
| 367 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 368 | - $this->has_recurring = 0; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - unset( $this->items[ $item_id ] ); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Returns the subtotal. |
|
| 378 | - * |
|
| 379 | - * @since 1.0.19 |
|
| 380 | - */ |
|
| 381 | - public function get_subtotal() { |
|
| 382 | - |
|
| 383 | - if ( wpinv_prices_include_tax() ) { |
|
| 384 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - return $this->totals['subtotal']['initial']; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Returns the recurring subtotal. |
|
| 392 | - * |
|
| 393 | - * @since 1.0.19 |
|
| 394 | - */ |
|
| 395 | - public function get_recurring_subtotal() { |
|
| 396 | - |
|
| 397 | - if ( wpinv_prices_include_tax() ) { |
|
| 398 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - return $this->totals['subtotal']['recurring']; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Returns all items. |
|
| 406 | - * |
|
| 407 | - * @since 1.0.19 |
|
| 408 | - * @return GetPaid_Form_Item[] |
|
| 409 | - */ |
|
| 410 | - public function get_items() { |
|
| 411 | - return $this->items; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - /* |
|
| 306 | + /** |
|
| 307 | + * Prepares the submission's items. |
|
| 308 | + * |
|
| 309 | + * @since 1.0.19 |
|
| 310 | + */ |
|
| 311 | + public function process_items() { |
|
| 312 | + |
|
| 313 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 314 | + |
|
| 315 | + foreach ( $processor->items as $item ) { |
|
| 316 | + $this->add_item( $item ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Adds an item to the submission. |
|
| 324 | + * |
|
| 325 | + * @since 1.0.19 |
|
| 326 | + * @param GetPaid_Form_Item $item |
|
| 327 | + */ |
|
| 328 | + public function add_item( $item ) { |
|
| 329 | + |
|
| 330 | + // Make sure that it is available for purchase. |
|
| 331 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 332 | + return; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + // Each submission can only contain one recurring item. |
|
| 336 | + if ( $item->is_recurring() ) { |
|
| 337 | + |
|
| 338 | + if ( $this->has_recurring != 0 ) { |
|
| 339 | + throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + $this->has_recurring = $item->get_id(); |
|
| 343 | + |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + // Update the items and totals. |
|
| 347 | + $this->items[ $item->get_id() ] = $item; |
|
| 348 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 349 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 350 | + |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * Removes a specific item. |
|
| 355 | + * |
|
| 356 | + * You should not call this method after the discounts and taxes |
|
| 357 | + * have been calculated. |
|
| 358 | + * |
|
| 359 | + * @since 1.0.19 |
|
| 360 | + */ |
|
| 361 | + public function remove_item( $item_id ) { |
|
| 362 | + |
|
| 363 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
| 364 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 365 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 366 | + |
|
| 367 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 368 | + $this->has_recurring = 0; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + unset( $this->items[ $item_id ] ); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Returns the subtotal. |
|
| 378 | + * |
|
| 379 | + * @since 1.0.19 |
|
| 380 | + */ |
|
| 381 | + public function get_subtotal() { |
|
| 382 | + |
|
| 383 | + if ( wpinv_prices_include_tax() ) { |
|
| 384 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + return $this->totals['subtotal']['initial']; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Returns the recurring subtotal. |
|
| 392 | + * |
|
| 393 | + * @since 1.0.19 |
|
| 394 | + */ |
|
| 395 | + public function get_recurring_subtotal() { |
|
| 396 | + |
|
| 397 | + if ( wpinv_prices_include_tax() ) { |
|
| 398 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + return $this->totals['subtotal']['recurring']; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Returns all items. |
|
| 406 | + * |
|
| 407 | + * @since 1.0.19 |
|
| 408 | + * @return GetPaid_Form_Item[] |
|
| 409 | + */ |
|
| 410 | + public function get_items() { |
|
| 411 | + return $this->items; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + /* |
|
| 415 | 415 | |-------------------------------------------------------------------------- |
| 416 | 416 | | Taxes |
| 417 | 417 | |-------------------------------------------------------------------------- |
@@ -420,128 +420,128 @@ discard block |
||
| 420 | 420 | | or only one-time. |
| 421 | 421 | */ |
| 422 | 422 | |
| 423 | - /** |
|
| 424 | - * Prepares the submission's taxes. |
|
| 425 | - * |
|
| 426 | - * @since 1.0.19 |
|
| 427 | - */ |
|
| 428 | - public function process_taxes() { |
|
| 429 | - |
|
| 430 | - // Abort if we're not using taxes. |
|
| 431 | - if ( ! $this->use_taxes() ) { |
|
| 432 | - return; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 436 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 437 | - if ( ! empty( $country ) ) { |
|
| 438 | - $this->country = $country; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 442 | - if ( ! empty( $state ) ) { |
|
| 443 | - $this->state = $state; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - // Confirm if the provided country and the ip country are similar. |
|
| 447 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 448 | - if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 449 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - // Abort if the country is not taxable. |
|
| 453 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 454 | - return; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 458 | - |
|
| 459 | - foreach ( $processor->taxes as $tax ) { |
|
| 460 | - $this->add_tax( $tax ); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * Adds a tax to the submission. |
|
| 468 | - * |
|
| 469 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 470 | - * @since 1.0.19 |
|
| 471 | - */ |
|
| 472 | - public function add_tax( $tax ) { |
|
| 473 | - |
|
| 474 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 475 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 476 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 480 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 481 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 482 | - |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * Removes a specific tax. |
|
| 487 | - * |
|
| 488 | - * @since 1.0.19 |
|
| 489 | - */ |
|
| 490 | - public function remove_tax( $tax_name ) { |
|
| 491 | - |
|
| 492 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 493 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 494 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 495 | - unset( $this->taxes[ $tax_name ] ); |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * Whether or not we'll use taxes for the submission. |
|
| 502 | - * |
|
| 503 | - * @since 1.0.19 |
|
| 504 | - */ |
|
| 505 | - public function use_taxes() { |
|
| 506 | - |
|
| 507 | - $use_taxes = wpinv_use_taxes(); |
|
| 508 | - |
|
| 509 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 510 | - $use_taxes = false; |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 514 | - |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * Returns the tax. |
|
| 519 | - * |
|
| 520 | - * @since 1.0.19 |
|
| 521 | - */ |
|
| 522 | - public function get_tax() { |
|
| 523 | - return $this->totals['taxes']['initial']; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * Returns the recurring tax. |
|
| 528 | - * |
|
| 529 | - * @since 1.0.19 |
|
| 530 | - */ |
|
| 531 | - public function get_recurring_tax() { |
|
| 532 | - return $this->totals['taxes']['recurring']; |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * Returns all taxes. |
|
| 537 | - * |
|
| 538 | - * @since 1.0.19 |
|
| 539 | - */ |
|
| 540 | - public function get_taxes() { |
|
| 541 | - return $this->taxes; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - /* |
|
| 423 | + /** |
|
| 424 | + * Prepares the submission's taxes. |
|
| 425 | + * |
|
| 426 | + * @since 1.0.19 |
|
| 427 | + */ |
|
| 428 | + public function process_taxes() { |
|
| 429 | + |
|
| 430 | + // Abort if we're not using taxes. |
|
| 431 | + if ( ! $this->use_taxes() ) { |
|
| 432 | + return; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 436 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 437 | + if ( ! empty( $country ) ) { |
|
| 438 | + $this->country = $country; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 442 | + if ( ! empty( $state ) ) { |
|
| 443 | + $this->state = $state; |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + // Confirm if the provided country and the ip country are similar. |
|
| 447 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 448 | + if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 449 | + throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + // Abort if the country is not taxable. |
|
| 453 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 454 | + return; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 458 | + |
|
| 459 | + foreach ( $processor->taxes as $tax ) { |
|
| 460 | + $this->add_tax( $tax ); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * Adds a tax to the submission. |
|
| 468 | + * |
|
| 469 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 470 | + * @since 1.0.19 |
|
| 471 | + */ |
|
| 472 | + public function add_tax( $tax ) { |
|
| 473 | + |
|
| 474 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 475 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 476 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + $this->taxes[ $tax['name'] ] = $tax; |
|
| 480 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 481 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 482 | + |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * Removes a specific tax. |
|
| 487 | + * |
|
| 488 | + * @since 1.0.19 |
|
| 489 | + */ |
|
| 490 | + public function remove_tax( $tax_name ) { |
|
| 491 | + |
|
| 492 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 493 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 494 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 495 | + unset( $this->taxes[ $tax_name ] ); |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * Whether or not we'll use taxes for the submission. |
|
| 502 | + * |
|
| 503 | + * @since 1.0.19 |
|
| 504 | + */ |
|
| 505 | + public function use_taxes() { |
|
| 506 | + |
|
| 507 | + $use_taxes = wpinv_use_taxes(); |
|
| 508 | + |
|
| 509 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 510 | + $use_taxes = false; |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 514 | + |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * Returns the tax. |
|
| 519 | + * |
|
| 520 | + * @since 1.0.19 |
|
| 521 | + */ |
|
| 522 | + public function get_tax() { |
|
| 523 | + return $this->totals['taxes']['initial']; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * Returns the recurring tax. |
|
| 528 | + * |
|
| 529 | + * @since 1.0.19 |
|
| 530 | + */ |
|
| 531 | + public function get_recurring_tax() { |
|
| 532 | + return $this->totals['taxes']['recurring']; |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * Returns all taxes. |
|
| 537 | + * |
|
| 538 | + * @since 1.0.19 |
|
| 539 | + */ |
|
| 540 | + public function get_taxes() { |
|
| 541 | + return $this->taxes; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + /* |
|
| 545 | 545 | |-------------------------------------------------------------------------- |
| 546 | 546 | | Discounts |
| 547 | 547 | |-------------------------------------------------------------------------- |
@@ -550,99 +550,99 @@ discard block |
||
| 550 | 550 | | or only one-time. They also do not have to come from a discount code. |
| 551 | 551 | */ |
| 552 | 552 | |
| 553 | - /** |
|
| 554 | - * Prepares the submission's discount. |
|
| 555 | - * |
|
| 556 | - * @since 1.0.19 |
|
| 557 | - */ |
|
| 558 | - public function process_discount() { |
|
| 559 | - |
|
| 560 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 561 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 562 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 563 | - |
|
| 564 | - foreach ( $processor->discounts as $discount ) { |
|
| 565 | - $this->add_discount( $discount ); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * Adds a discount to the submission. |
|
| 573 | - * |
|
| 574 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 575 | - * @since 1.0.19 |
|
| 576 | - */ |
|
| 577 | - public function add_discount( $discount ) { |
|
| 578 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 579 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 580 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Removes a discount from the submission. |
|
| 585 | - * |
|
| 586 | - * @since 1.0.19 |
|
| 587 | - */ |
|
| 588 | - public function remove_discount( $name ) { |
|
| 589 | - |
|
| 590 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 591 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 592 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 593 | - unset( $this->discounts[ $name ] ); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - /** |
|
| 599 | - * Checks whether there is a discount code associated with this submission. |
|
| 600 | - * |
|
| 601 | - * @since 1.0.19 |
|
| 602 | - * @return bool |
|
| 603 | - */ |
|
| 604 | - public function has_discount_code() { |
|
| 605 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * Returns the discount code. |
|
| 610 | - * |
|
| 611 | - * @since 1.0.19 |
|
| 612 | - * @return string |
|
| 613 | - */ |
|
| 614 | - public function get_discount_code() { |
|
| 615 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * Returns the discount. |
|
| 620 | - * |
|
| 621 | - * @since 1.0.19 |
|
| 622 | - */ |
|
| 623 | - public function get_discount() { |
|
| 624 | - return $this->totals['discount']['initial']; |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * Returns the recurring discount. |
|
| 629 | - * |
|
| 630 | - * @since 1.0.19 |
|
| 631 | - */ |
|
| 632 | - public function get_recurring_discount() { |
|
| 633 | - return $this->totals['discount']['recurring']; |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * Returns all discounts. |
|
| 638 | - * |
|
| 639 | - * @since 1.0.19 |
|
| 640 | - */ |
|
| 641 | - public function get_discounts() { |
|
| 642 | - return $this->discounts; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - /* |
|
| 553 | + /** |
|
| 554 | + * Prepares the submission's discount. |
|
| 555 | + * |
|
| 556 | + * @since 1.0.19 |
|
| 557 | + */ |
|
| 558 | + public function process_discount() { |
|
| 559 | + |
|
| 560 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 561 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 562 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 563 | + |
|
| 564 | + foreach ( $processor->discounts as $discount ) { |
|
| 565 | + $this->add_discount( $discount ); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * Adds a discount to the submission. |
|
| 573 | + * |
|
| 574 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 575 | + * @since 1.0.19 |
|
| 576 | + */ |
|
| 577 | + public function add_discount( $discount ) { |
|
| 578 | + $this->discounts[ $discount['name'] ] = $discount; |
|
| 579 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 580 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Removes a discount from the submission. |
|
| 585 | + * |
|
| 586 | + * @since 1.0.19 |
|
| 587 | + */ |
|
| 588 | + public function remove_discount( $name ) { |
|
| 589 | + |
|
| 590 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
| 591 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 592 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 593 | + unset( $this->discounts[ $name ] ); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + /** |
|
| 599 | + * Checks whether there is a discount code associated with this submission. |
|
| 600 | + * |
|
| 601 | + * @since 1.0.19 |
|
| 602 | + * @return bool |
|
| 603 | + */ |
|
| 604 | + public function has_discount_code() { |
|
| 605 | + return ! empty( $this->discounts['discount_code'] ); |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * Returns the discount code. |
|
| 610 | + * |
|
| 611 | + * @since 1.0.19 |
|
| 612 | + * @return string |
|
| 613 | + */ |
|
| 614 | + public function get_discount_code() { |
|
| 615 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * Returns the discount. |
|
| 620 | + * |
|
| 621 | + * @since 1.0.19 |
|
| 622 | + */ |
|
| 623 | + public function get_discount() { |
|
| 624 | + return $this->totals['discount']['initial']; |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * Returns the recurring discount. |
|
| 629 | + * |
|
| 630 | + * @since 1.0.19 |
|
| 631 | + */ |
|
| 632 | + public function get_recurring_discount() { |
|
| 633 | + return $this->totals['discount']['recurring']; |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * Returns all discounts. |
|
| 638 | + * |
|
| 639 | + * @since 1.0.19 |
|
| 640 | + */ |
|
| 641 | + public function get_discounts() { |
|
| 642 | + return $this->discounts; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + /* |
|
| 646 | 646 | |-------------------------------------------------------------------------- |
| 647 | 647 | | Fees |
| 648 | 648 | |-------------------------------------------------------------------------- |
@@ -652,89 +652,89 @@ discard block |
||
| 652 | 652 | | fees. |
| 653 | 653 | */ |
| 654 | 654 | |
| 655 | - /** |
|
| 656 | - * Prepares the submission's fees. |
|
| 657 | - * |
|
| 658 | - * @since 1.0.19 |
|
| 659 | - */ |
|
| 660 | - public function process_fees() { |
|
| 661 | - |
|
| 662 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 663 | - |
|
| 664 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 665 | - $this->add_fee( $fee ); |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * Adds a fee to the submission. |
|
| 673 | - * |
|
| 674 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 675 | - * @since 1.0.19 |
|
| 676 | - */ |
|
| 677 | - public function add_fee( $fee ) { |
|
| 678 | - |
|
| 679 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 680 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 681 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 682 | - |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Removes a fee from the submission. |
|
| 687 | - * |
|
| 688 | - * @since 1.0.19 |
|
| 689 | - */ |
|
| 690 | - public function remove_fee( $name ) { |
|
| 691 | - |
|
| 692 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 693 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 694 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 695 | - unset( $this->fees[ $name ] ); |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - /** |
|
| 701 | - * Returns the fees. |
|
| 702 | - * |
|
| 703 | - * @since 1.0.19 |
|
| 704 | - */ |
|
| 705 | - public function get_fee() { |
|
| 706 | - return $this->totals['fees']['initial']; |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * Returns the recurring fees. |
|
| 711 | - * |
|
| 712 | - * @since 1.0.19 |
|
| 713 | - */ |
|
| 714 | - public function get_recurring_fee() { |
|
| 715 | - return $this->totals['fees']['recurring']; |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - /** |
|
| 719 | - * Returns all fees. |
|
| 720 | - * |
|
| 721 | - * @since 1.0.19 |
|
| 722 | - */ |
|
| 723 | - public function get_fees() { |
|
| 724 | - return $this->fees; |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - /** |
|
| 728 | - * Checks if there are any fees for the form. |
|
| 729 | - * |
|
| 730 | - * @return bool |
|
| 731 | - * @since 1.0.19 |
|
| 732 | - */ |
|
| 733 | - public function has_fees() { |
|
| 734 | - return count( $this->fees ) !== 0; |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - /* |
|
| 655 | + /** |
|
| 656 | + * Prepares the submission's fees. |
|
| 657 | + * |
|
| 658 | + * @since 1.0.19 |
|
| 659 | + */ |
|
| 660 | + public function process_fees() { |
|
| 661 | + |
|
| 662 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 663 | + |
|
| 664 | + foreach ( $fees_processor->fees as $fee ) { |
|
| 665 | + $this->add_fee( $fee ); |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * Adds a fee to the submission. |
|
| 673 | + * |
|
| 674 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 675 | + * @since 1.0.19 |
|
| 676 | + */ |
|
| 677 | + public function add_fee( $fee ) { |
|
| 678 | + |
|
| 679 | + $this->fees[ $fee['name'] ] = $fee; |
|
| 680 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 681 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 682 | + |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Removes a fee from the submission. |
|
| 687 | + * |
|
| 688 | + * @since 1.0.19 |
|
| 689 | + */ |
|
| 690 | + public function remove_fee( $name ) { |
|
| 691 | + |
|
| 692 | + if ( isset( $this->fees[ $name ] ) ) { |
|
| 693 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 694 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 695 | + unset( $this->fees[ $name ] ); |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + /** |
|
| 701 | + * Returns the fees. |
|
| 702 | + * |
|
| 703 | + * @since 1.0.19 |
|
| 704 | + */ |
|
| 705 | + public function get_fee() { |
|
| 706 | + return $this->totals['fees']['initial']; |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * Returns the recurring fees. |
|
| 711 | + * |
|
| 712 | + * @since 1.0.19 |
|
| 713 | + */ |
|
| 714 | + public function get_recurring_fee() { |
|
| 715 | + return $this->totals['fees']['recurring']; |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + /** |
|
| 719 | + * Returns all fees. |
|
| 720 | + * |
|
| 721 | + * @since 1.0.19 |
|
| 722 | + */ |
|
| 723 | + public function get_fees() { |
|
| 724 | + return $this->fees; |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + /** |
|
| 728 | + * Checks if there are any fees for the form. |
|
| 729 | + * |
|
| 730 | + * @return bool |
|
| 731 | + * @since 1.0.19 |
|
| 732 | + */ |
|
| 733 | + public function has_fees() { |
|
| 734 | + return count( $this->fees ) !== 0; |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + /* |
|
| 738 | 738 | |-------------------------------------------------------------------------- |
| 739 | 739 | | MISC |
| 740 | 740 | |-------------------------------------------------------------------------- |
@@ -742,109 +742,109 @@ discard block |
||
| 742 | 742 | | Extra submission functions. |
| 743 | 743 | */ |
| 744 | 744 | |
| 745 | - /** |
|
| 746 | - * Returns the total amount to collect for this submission. |
|
| 747 | - * |
|
| 748 | - * @since 1.0.19 |
|
| 749 | - */ |
|
| 750 | - public function get_total() { |
|
| 751 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
| 752 | - return max( $total, 0 ); |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - /** |
|
| 756 | - * Returns the recurring total amount to collect for this submission. |
|
| 757 | - * |
|
| 758 | - * @since 1.0.19 |
|
| 759 | - */ |
|
| 760 | - public function get_recurring_total() { |
|
| 761 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
| 762 | - return max( $total, 0 ); |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * Whether payment details should be collected for this submission. |
|
| 767 | - * |
|
| 768 | - * @since 1.0.19 |
|
| 769 | - */ |
|
| 770 | - public function should_collect_payment_details() { |
|
| 771 | - $initial = $this->get_total(); |
|
| 772 | - $recurring = $this->get_recurring_total(); |
|
| 773 | - |
|
| 774 | - if ( $this->has_recurring == 0 ) { |
|
| 775 | - $recurring = 0; |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - $collect = $initial > 0 || $recurring > 0; |
|
| 779 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - /** |
|
| 783 | - * Returns the billing email of the user. |
|
| 784 | - * |
|
| 785 | - * @since 1.0.19 |
|
| 786 | - */ |
|
| 787 | - public function get_billing_email() { |
|
| 788 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - /** |
|
| 792 | - * Checks if the submitter has a billing email. |
|
| 793 | - * |
|
| 794 | - * @since 1.0.19 |
|
| 795 | - */ |
|
| 796 | - public function has_billing_email() { |
|
| 797 | - $billing_email = $this->get_billing_email(); |
|
| 798 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - /** |
|
| 802 | - * Returns the appropriate currency for the submission. |
|
| 803 | - * |
|
| 804 | - * @since 1.0.19 |
|
| 805 | - * @return string |
|
| 806 | - */ |
|
| 807 | - public function get_currency() { |
|
| 808 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - /** |
|
| 812 | - * Returns the raw submission data. |
|
| 813 | - * |
|
| 814 | - * @since 1.0.19 |
|
| 815 | - * @return array |
|
| 816 | - */ |
|
| 817 | - public function get_data() { |
|
| 818 | - return $this->data; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - /** |
|
| 822 | - * Returns a field from the submission data |
|
| 823 | - * |
|
| 824 | - * @param string $field |
|
| 825 | - * @since 1.0.19 |
|
| 826 | - * @return mixed|null |
|
| 827 | - */ |
|
| 828 | - public function get_field( $field, $sub_array_key = null ) { |
|
| 829 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - /** |
|
| 833 | - * Checks if a required field is set. |
|
| 834 | - * |
|
| 835 | - * @since 1.0.19 |
|
| 836 | - */ |
|
| 837 | - public function is_required_field_set( $field ) { |
|
| 838 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 839 | - } |
|
| 840 | - |
|
| 841 | - /** |
|
| 842 | - * Formats an amount |
|
| 843 | - * |
|
| 844 | - * @since 1.0.19 |
|
| 845 | - */ |
|
| 846 | - public function format_amount( $amount ) { |
|
| 847 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 848 | - } |
|
| 745 | + /** |
|
| 746 | + * Returns the total amount to collect for this submission. |
|
| 747 | + * |
|
| 748 | + * @since 1.0.19 |
|
| 749 | + */ |
|
| 750 | + public function get_total() { |
|
| 751 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
| 752 | + return max( $total, 0 ); |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + /** |
|
| 756 | + * Returns the recurring total amount to collect for this submission. |
|
| 757 | + * |
|
| 758 | + * @since 1.0.19 |
|
| 759 | + */ |
|
| 760 | + public function get_recurring_total() { |
|
| 761 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
| 762 | + return max( $total, 0 ); |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * Whether payment details should be collected for this submission. |
|
| 767 | + * |
|
| 768 | + * @since 1.0.19 |
|
| 769 | + */ |
|
| 770 | + public function should_collect_payment_details() { |
|
| 771 | + $initial = $this->get_total(); |
|
| 772 | + $recurring = $this->get_recurring_total(); |
|
| 773 | + |
|
| 774 | + if ( $this->has_recurring == 0 ) { |
|
| 775 | + $recurring = 0; |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + $collect = $initial > 0 || $recurring > 0; |
|
| 779 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + /** |
|
| 783 | + * Returns the billing email of the user. |
|
| 784 | + * |
|
| 785 | + * @since 1.0.19 |
|
| 786 | + */ |
|
| 787 | + public function get_billing_email() { |
|
| 788 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + /** |
|
| 792 | + * Checks if the submitter has a billing email. |
|
| 793 | + * |
|
| 794 | + * @since 1.0.19 |
|
| 795 | + */ |
|
| 796 | + public function has_billing_email() { |
|
| 797 | + $billing_email = $this->get_billing_email(); |
|
| 798 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + /** |
|
| 802 | + * Returns the appropriate currency for the submission. |
|
| 803 | + * |
|
| 804 | + * @since 1.0.19 |
|
| 805 | + * @return string |
|
| 806 | + */ |
|
| 807 | + public function get_currency() { |
|
| 808 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + /** |
|
| 812 | + * Returns the raw submission data. |
|
| 813 | + * |
|
| 814 | + * @since 1.0.19 |
|
| 815 | + * @return array |
|
| 816 | + */ |
|
| 817 | + public function get_data() { |
|
| 818 | + return $this->data; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + /** |
|
| 822 | + * Returns a field from the submission data |
|
| 823 | + * |
|
| 824 | + * @param string $field |
|
| 825 | + * @since 1.0.19 |
|
| 826 | + * @return mixed|null |
|
| 827 | + */ |
|
| 828 | + public function get_field( $field, $sub_array_key = null ) { |
|
| 829 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + /** |
|
| 833 | + * Checks if a required field is set. |
|
| 834 | + * |
|
| 835 | + * @since 1.0.19 |
|
| 836 | + */ |
|
| 837 | + public function is_required_field_set( $field ) { |
|
| 838 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 839 | + } |
|
| 840 | + |
|
| 841 | + /** |
|
| 842 | + * Formats an amount |
|
| 843 | + * |
|
| 844 | + * @since 1.0.19 |
|
| 845 | + */ |
|
| 846 | + public function format_amount( $amount ) { |
|
| 847 | + return wpinv_price( $amount, $this->get_currency() ); |
|
| 848 | + } |
|
| 849 | 849 | |
| 850 | 850 | } |
@@ -12,223 +12,223 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Taxes { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Submission taxes. |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $taxes = array(); |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Whether or not we should skip the taxes. |
|
| 23 | - * @var bool |
|
| 24 | - */ |
|
| 25 | - protected $skip_taxes = false; |
|
| 15 | + /** |
|
| 16 | + * Submission taxes. |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $taxes = array(); |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Whether or not we should skip the taxes. |
|
| 23 | + * @var bool |
|
| 24 | + */ |
|
| 25 | + protected $skip_taxes = false; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Class constructor |
|
| 29 | + * |
|
| 30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | + */ |
|
| 32 | + public function __construct( $submission ) { |
|
| 33 | + |
|
| 34 | + // Validate VAT number. |
|
| 35 | + $this->validate_vat( $submission ); |
|
| 36 | + |
|
| 37 | + if ( $this->skip_taxes ) { |
|
| 38 | + return; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + foreach ( $submission->get_items() as $item ) { |
|
| 42 | + $this->process_item_tax( $item, $submission ); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + // Process any existing invoice taxes. |
|
| 46 | + if ( $submission->has_invoice() ) { |
|
| 47 | + $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Maybe process tax. |
|
| 54 | + * |
|
| 55 | + * @since 1.0.19 |
|
| 56 | + * @param GetPaid_Form_Item $item |
|
| 57 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 58 | + */ |
|
| 59 | + public function process_item_tax( $item, $submission ) { |
|
| 60 | + |
|
| 61 | + $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
| 62 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 63 | + $taxes = getpaid_calculate_item_taxes( $item->get_sub_total(), $rates ); |
|
| 64 | + $r_taxes = getpaid_calculate_item_taxes( $item->get_recurring_sub_total(), $rates ); |
|
| 65 | + |
|
| 66 | + foreach ( $taxes as $name => $amount ) { |
|
| 67 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 68 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 69 | + |
|
| 70 | + if ( ! isset( $this->taxes[ $name ] ) ) { |
|
| 71 | + $this->taxes[ $name ] = $tax; |
|
| 72 | + continue; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 76 | + $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 77 | + |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Checks if the submission has a digital item. |
|
| 84 | + * |
|
| 85 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 86 | + * @since 1.0.19 |
|
| 87 | + * @return bool |
|
| 88 | + */ |
|
| 89 | + public function has_digital_item( $submission ) { |
|
| 90 | + |
|
| 91 | + foreach ( $submission->get_items() as $item ) { |
|
| 92 | + |
|
| 93 | + if ( 'digital' == $item->get_vat_rule() ) { |
|
| 94 | + return true; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + return false; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Checks if this is an eu store. |
|
| 104 | + * |
|
| 105 | + * @since 1.0.19 |
|
| 106 | + * @return bool |
|
| 107 | + */ |
|
| 108 | + public function is_eu_store() { |
|
| 109 | + return $this->is_eu_country( wpinv_get_default_country() ); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Checks if this is an eu country. |
|
| 114 | + * |
|
| 115 | + * @param string $country |
|
| 116 | + * @since 1.0.19 |
|
| 117 | + * @return bool |
|
| 118 | + */ |
|
| 119 | + public function is_eu_country( $country ) { |
|
| 120 | + return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Checks if this is an eu purchase. |
|
| 125 | + * |
|
| 126 | + * @param string $customer_country |
|
| 127 | + * @since 1.0.19 |
|
| 128 | + * @return bool |
|
| 129 | + */ |
|
| 130 | + public function is_eu_transaction( $customer_country ) { |
|
| 131 | + return $this->is_eu_country( $customer_country ) && $this->is_eu_store(); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Retrieves the vat number. |
|
| 136 | + * |
|
| 137 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 138 | + * @since 1.0.19 |
|
| 139 | + * @return string |
|
| 140 | + */ |
|
| 141 | + public function get_vat_number( $submission ) { |
|
| 142 | + |
|
| 143 | + // Retrieve from the posted number. |
|
| 144 | + $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
| 145 | + if ( ! empty( $vat_number ) ) { |
|
| 146 | + return wpinv_clean( $vat_number ); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + // Retrieve from the invoice. |
|
| 150 | + return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Retrieves the company. |
|
| 155 | + * |
|
| 156 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 157 | + * @since 1.0.19 |
|
| 158 | + * @return string |
|
| 159 | + */ |
|
| 160 | + public function get_company( $submission ) { |
|
| 161 | + |
|
| 162 | + // Retrieve from the posted data. |
|
| 163 | + $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
| 164 | + if ( ! empty( $company ) ) { |
|
| 165 | + return wpinv_clean( $company ); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + // Retrieve from the invoice. |
|
| 169 | + return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
| 170 | + } |
|
| 26 | 171 | |
| 27 | 172 | /** |
| 28 | - * Class constructor |
|
| 29 | - * |
|
| 30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | - */ |
|
| 32 | - public function __construct( $submission ) { |
|
| 33 | - |
|
| 34 | - // Validate VAT number. |
|
| 35 | - $this->validate_vat( $submission ); |
|
| 36 | - |
|
| 37 | - if ( $this->skip_taxes ) { |
|
| 38 | - return; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - foreach ( $submission->get_items() as $item ) { |
|
| 42 | - $this->process_item_tax( $item, $submission ); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - // Process any existing invoice taxes. |
|
| 46 | - if ( $submission->has_invoice() ) { |
|
| 47 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Maybe process tax. |
|
| 54 | - * |
|
| 55 | - * @since 1.0.19 |
|
| 56 | - * @param GetPaid_Form_Item $item |
|
| 57 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 58 | - */ |
|
| 59 | - public function process_item_tax( $item, $submission ) { |
|
| 60 | - |
|
| 61 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
| 62 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 63 | - $taxes = getpaid_calculate_item_taxes( $item->get_sub_total(), $rates ); |
|
| 64 | - $r_taxes = getpaid_calculate_item_taxes( $item->get_recurring_sub_total(), $rates ); |
|
| 65 | - |
|
| 66 | - foreach ( $taxes as $name => $amount ) { |
|
| 67 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 68 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 69 | - |
|
| 70 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
| 71 | - $this->taxes[ $name ] = $tax; |
|
| 72 | - continue; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 76 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 77 | - |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Checks if the submission has a digital item. |
|
| 84 | - * |
|
| 85 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 86 | - * @since 1.0.19 |
|
| 87 | - * @return bool |
|
| 88 | - */ |
|
| 89 | - public function has_digital_item( $submission ) { |
|
| 90 | - |
|
| 91 | - foreach ( $submission->get_items() as $item ) { |
|
| 92 | - |
|
| 93 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
| 94 | - return true; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - return false; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Checks if this is an eu store. |
|
| 104 | - * |
|
| 105 | - * @since 1.0.19 |
|
| 106 | - * @return bool |
|
| 107 | - */ |
|
| 108 | - public function is_eu_store() { |
|
| 109 | - return $this->is_eu_country( wpinv_get_default_country() ); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Checks if this is an eu country. |
|
| 114 | - * |
|
| 115 | - * @param string $country |
|
| 116 | - * @since 1.0.19 |
|
| 117 | - * @return bool |
|
| 118 | - */ |
|
| 119 | - public function is_eu_country( $country ) { |
|
| 120 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Checks if this is an eu purchase. |
|
| 125 | - * |
|
| 126 | - * @param string $customer_country |
|
| 127 | - * @since 1.0.19 |
|
| 128 | - * @return bool |
|
| 129 | - */ |
|
| 130 | - public function is_eu_transaction( $customer_country ) { |
|
| 131 | - return $this->is_eu_country( $customer_country ) && $this->is_eu_store(); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Retrieves the vat number. |
|
| 136 | - * |
|
| 137 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 138 | - * @since 1.0.19 |
|
| 139 | - * @return string |
|
| 140 | - */ |
|
| 141 | - public function get_vat_number( $submission ) { |
|
| 142 | - |
|
| 143 | - // Retrieve from the posted number. |
|
| 144 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
| 145 | - if ( ! empty( $vat_number ) ) { |
|
| 146 | - return wpinv_clean( $vat_number ); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - // Retrieve from the invoice. |
|
| 150 | - return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Retrieves the company. |
|
| 155 | - * |
|
| 156 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 157 | - * @since 1.0.19 |
|
| 158 | - * @return string |
|
| 159 | - */ |
|
| 160 | - public function get_company( $submission ) { |
|
| 161 | - |
|
| 162 | - // Retrieve from the posted data. |
|
| 163 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
| 164 | - if ( ! empty( $company ) ) { |
|
| 165 | - return wpinv_clean( $company ); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - // Retrieve from the invoice. |
|
| 169 | - return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Checks if we require a VAT number. |
|
| 174 | - * |
|
| 175 | - * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
| 176 | - * @param bool $country_in_eu Whether the customer country is from the EU |
|
| 177 | - * @since 1.0.19 |
|
| 178 | - * @return string |
|
| 179 | - */ |
|
| 180 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 181 | - |
|
| 182 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 183 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 184 | - $is_eu = $ip_in_eu || $country_in_eu; |
|
| 185 | - |
|
| 186 | - return $prevent_b2c && $is_eu; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Validate VAT data. |
|
| 191 | - * |
|
| 192 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 193 | - * @since 1.0.19 |
|
| 194 | - */ |
|
| 195 | - public function validate_vat( $submission ) { |
|
| 196 | - |
|
| 197 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 198 | - |
|
| 199 | - // Abort if we are not validating vat numbers. |
|
| 200 | - if ( ! $in_eu || ! wpinv_should_validate_vat_number() ) { |
|
| 173 | + * Checks if we require a VAT number. |
|
| 174 | + * |
|
| 175 | + * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
| 176 | + * @param bool $country_in_eu Whether the customer country is from the EU |
|
| 177 | + * @since 1.0.19 |
|
| 178 | + * @return string |
|
| 179 | + */ |
|
| 180 | + public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 181 | + |
|
| 182 | + $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 183 | + $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 184 | + $is_eu = $ip_in_eu || $country_in_eu; |
|
| 185 | + |
|
| 186 | + return $prevent_b2c && $is_eu; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Validate VAT data. |
|
| 191 | + * |
|
| 192 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 193 | + * @since 1.0.19 |
|
| 194 | + */ |
|
| 195 | + public function validate_vat( $submission ) { |
|
| 196 | + |
|
| 197 | + $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 198 | + |
|
| 199 | + // Abort if we are not validating vat numbers. |
|
| 200 | + if ( ! $in_eu || ! wpinv_should_validate_vat_number() ) { |
|
| 201 | 201 | return; |
| 202 | - } |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - // Prepare variables. |
|
| 205 | - $vat_number = $this->get_vat_number( $submission ); |
|
| 206 | - $ip_country = getpaid_get_ip_country(); |
|
| 204 | + // Prepare variables. |
|
| 205 | + $vat_number = $this->get_vat_number( $submission ); |
|
| 206 | + $ip_country = getpaid_get_ip_country(); |
|
| 207 | 207 | $is_eu = $this->is_eu_country( $submission->country ); |
| 208 | 208 | $is_ip_eu = $this->is_eu_country( $ip_country ); |
| 209 | 209 | |
| 210 | - // If we're preventing business to consumer purchases, |
|
| 211 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 210 | + // If we're preventing business to consumer purchases, |
|
| 211 | + if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 212 | 212 | |
| 213 | - // Ensure that a vat number has been specified. |
|
| 214 | - throw new Exception( |
|
| 215 | - __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
| 216 | - ); |
|
| 213 | + // Ensure that a vat number has been specified. |
|
| 214 | + throw new Exception( |
|
| 215 | + __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
| 216 | + ); |
|
| 217 | 217 | |
| 218 | - } |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - if ( empty( $vat_number ) ) { |
|
| 221 | - return; |
|
| 222 | - } |
|
| 220 | + if ( empty( $vat_number ) ) { |
|
| 221 | + return; |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - if ( ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
| 225 | - throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
| 226 | - } |
|
| 224 | + if ( ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
| 225 | + throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - if ( 'vat_too' != wpinv_get_option( 'vat_same_country_rule' ) ) { |
|
| 229 | - $this->skip_taxes = true; |
|
| 230 | - } |
|
| 228 | + if ( 'vat_too' != wpinv_get_option( 'vat_same_country_rule' ) ) { |
|
| 229 | + $this->skip_taxes = true; |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - } |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | 234 | } |
@@ -13,264 +13,264 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class GetPaid_Geolocation { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Holds the current user's IP Address. |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - public static $current_user_ip; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * API endpoints for looking up a user IP address. |
|
| 25 | - * |
|
| 26 | - * For example, in case a user is on localhost. |
|
| 27 | - * |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - protected static $ip_lookup_apis = array( |
|
| 31 | - 'ipify' => 'http://api.ipify.org/', |
|
| 32 | - 'ipecho' => 'http://ipecho.net/plain', |
|
| 33 | - 'ident' => 'http://ident.me', |
|
| 34 | - 'whatismyipaddress' => 'http://bot.whatismyipaddress.com', |
|
| 35 | - ); |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * API endpoints for geolocating an IP address |
|
| 39 | - * |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - protected static $geoip_apis = array( |
|
| 43 | - 'ip-api.com' => 'http://ip-api.com/json/%s', |
|
| 44 | - 'ipinfo.io' => 'https://ipinfo.io/%s/json', |
|
| 45 | - ); |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Get current user IP Address. |
|
| 49 | - * |
|
| 50 | - * @return string |
|
| 51 | - */ |
|
| 52 | - public static function get_ip_address() { |
|
| 53 | - return wpinv_get_ip(); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Get user IP Address using an external service. |
|
| 58 | - * This can be used as a fallback for users on localhost where |
|
| 59 | - * get_ip_address() will be a local IP and non-geolocatable. |
|
| 60 | - * |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - public static function get_external_ip_address() { |
|
| 64 | - |
|
| 65 | - $transient_name = 'external_ip_address_0.0.0.0'; |
|
| 66 | - |
|
| 67 | - if ( '' !== self::get_ip_address() ) { |
|
| 68 | - $transient_name = 'external_ip_address_' . self::get_ip_address(); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // Try retrieving from cache. |
|
| 72 | - $external_ip_address = get_transient( $transient_name ); |
|
| 73 | - |
|
| 74 | - if ( false === $external_ip_address ) { |
|
| 75 | - $external_ip_address = '0.0.0.0'; |
|
| 76 | - $ip_lookup_services = apply_filters( 'getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis ); |
|
| 77 | - $ip_lookup_services_keys = array_keys( $ip_lookup_services ); |
|
| 78 | - shuffle( $ip_lookup_services_keys ); |
|
| 79 | - |
|
| 80 | - foreach ( $ip_lookup_services_keys as $service_name ) { |
|
| 81 | - $service_endpoint = $ip_lookup_services[ $service_name ]; |
|
| 82 | - $response = wp_safe_remote_get( $service_endpoint, array( 'timeout' => 2 ) ); |
|
| 83 | - |
|
| 84 | - if ( ! is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) { |
|
| 85 | - $external_ip_address = apply_filters( 'getpaid_geolocation_ip_lookup_api_response', wpinv_clean( $response['body'] ), $service_name ); |
|
| 86 | - break; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS ); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return $external_ip_address; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Geolocate an IP address. |
|
| 99 | - * |
|
| 100 | - * @param string $ip_address IP Address. |
|
| 101 | - * @param bool $fallback If true, fallbacks to alternative IP detection (can be slower). |
|
| 102 | - * @param bool $api_fallback If true, uses geolocation APIs if the database file doesn't exist (can be slower). |
|
| 103 | - * @return array |
|
| 104 | - */ |
|
| 105 | - public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) { |
|
| 106 | - |
|
| 107 | - if ( empty( $ip_address ) ) { |
|
| 108 | - $ip_address = self::get_ip_address(); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // Update the current user's IP Address. |
|
| 112 | - self::$current_user_ip = $ip_address; |
|
| 113 | - |
|
| 114 | - // Filter to allow custom geolocation of the IP address. |
|
| 115 | - $country_code = apply_filters( 'getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback ); |
|
| 116 | - |
|
| 117 | - if ( false !== $country_code ) { |
|
| 118 | - |
|
| 119 | - return array( |
|
| 120 | - 'country' => $country_code, |
|
| 121 | - 'state' => '', |
|
| 122 | - 'city' => '', |
|
| 123 | - 'postcode' => '', |
|
| 124 | - ); |
|
| 125 | - |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - $country_code = self::get_country_code_from_headers(); |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Get geolocation filter. |
|
| 132 | - * |
|
| 133 | - * @since 1.0.19 |
|
| 134 | - * @param array $geolocation Geolocation data, including country, state, city, and postcode. |
|
| 135 | - * @param string $ip_address IP Address. |
|
| 136 | - */ |
|
| 137 | - $geolocation = apply_filters( |
|
| 138 | - 'getpaid_get_geolocation', |
|
| 139 | - array( |
|
| 140 | - 'country' => $country_code, |
|
| 141 | - 'state' => '', |
|
| 142 | - 'city' => '', |
|
| 143 | - 'postcode' => '', |
|
| 144 | - ), |
|
| 145 | - $ip_address |
|
| 146 | - ); |
|
| 147 | - |
|
| 148 | - // If we still haven't found a country code, let's consider doing an API lookup. |
|
| 149 | - if ( '' === $geolocation['country'] && $api_fallback ) { |
|
| 150 | - $geolocation['country'] = self::geolocate_via_api( $ip_address ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // It's possible that we're in a local environment, in which case the geolocation needs to be done from the |
|
| 154 | - // external address. |
|
| 155 | - if ( '' === $geolocation['country'] && $fallback ) { |
|
| 156 | - $external_ip_address = self::get_external_ip_address(); |
|
| 157 | - |
|
| 158 | - // Only bother with this if the external IP differs. |
|
| 159 | - if ( '0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address ) { |
|
| 160 | - return self::geolocate_ip( $external_ip_address, false, $api_fallback ); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - return array( |
|
| 166 | - 'country' => $geolocation['country'], |
|
| 167 | - 'state' => $geolocation['state'], |
|
| 168 | - 'city' => $geolocation['city'], |
|
| 169 | - 'postcode' => $geolocation['postcode'], |
|
| 170 | - ); |
|
| 171 | - |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Fetches the country code from the request headers, if one is available. |
|
| 176 | - * |
|
| 177 | - * @since 1.0.19 |
|
| 178 | - * @return string The country code pulled from the headers, or empty string if one was not found. |
|
| 179 | - */ |
|
| 180 | - protected static function get_country_code_from_headers() { |
|
| 181 | - $country_code = ''; |
|
| 182 | - |
|
| 183 | - $headers = array( |
|
| 184 | - 'MM_COUNTRY_CODE', |
|
| 185 | - 'GEOIP_COUNTRY_CODE', |
|
| 186 | - 'HTTP_CF_IPCOUNTRY', |
|
| 187 | - 'HTTP_X_COUNTRY_CODE', |
|
| 188 | - ); |
|
| 189 | - |
|
| 190 | - foreach ( $headers as $header ) { |
|
| 191 | - if ( empty( $_SERVER[ $header ] ) ) { |
|
| 192 | - continue; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - $country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) ); |
|
| 196 | - break; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $country_code; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Use APIs to Geolocate the user. |
|
| 204 | - * |
|
| 205 | - * Geolocation APIs can be added through the use of the getpaid_geolocation_geoip_apis filter. |
|
| 206 | - * Provide a name=>value pair for service-slug=>endpoint. |
|
| 207 | - * |
|
| 208 | - * If APIs are defined, one will be chosen at random to fulfil the request. After completing, the result |
|
| 209 | - * will be cached in a transient. |
|
| 210 | - * |
|
| 211 | - * @param string $ip_address IP address. |
|
| 212 | - * @return string |
|
| 213 | - */ |
|
| 214 | - protected static function geolocate_via_api( $ip_address ) { |
|
| 215 | - |
|
| 216 | - // Retrieve from cache... |
|
| 217 | - $country_code = get_transient( 'geoip_' . $ip_address ); |
|
| 218 | - |
|
| 219 | - // If missing, retrieve from the API. |
|
| 220 | - if ( false === $country_code ) { |
|
| 221 | - $geoip_services = apply_filters( 'getpaid_geolocation_geoip_apis', self::$geoip_apis ); |
|
| 222 | - |
|
| 223 | - if ( empty( $geoip_services ) ) { |
|
| 224 | - return ''; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $geoip_services_keys = array_keys( $geoip_services ); |
|
| 228 | - |
|
| 229 | - shuffle( $geoip_services_keys ); |
|
| 230 | - |
|
| 231 | - foreach ( $geoip_services_keys as $service_name ) { |
|
| 232 | - |
|
| 233 | - $service_endpoint = $geoip_services[ $service_name ]; |
|
| 234 | - $response = wp_safe_remote_get( sprintf( $service_endpoint, $ip_address ), array( 'timeout' => 2 ) ); |
|
| 235 | - $country_code = sanitize_text_field( strtoupper( self::handle_geolocation_response( $response, $service_name ) ) ); |
|
| 236 | - |
|
| 237 | - if ( ! empty( $country_code ) ) { |
|
| 238 | - break; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS ); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - return $country_code; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Handles geolocation response |
|
| 251 | - * |
|
| 252 | - * @param WP_Error|String $geolocation_response |
|
| 253 | - * @param String $geolocation_service |
|
| 254 | - * @return string Country code |
|
| 255 | - */ |
|
| 256 | - protected static function handle_geolocation_response( $geolocation_response, $geolocation_service ) { |
|
| 257 | - |
|
| 258 | - if ( is_wp_error( $geolocation_response ) || empty( $geolocation_response['body'] ) ) { |
|
| 259 | - return ''; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - if ( $geolocation_service === 'ipinfo.io' ) { |
|
| 263 | - $data = json_decode( $geolocation_response['body'] ); |
|
| 264 | - return empty( $data ) || empty( $data->country ) ? '' : $data->country; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - if ( $geolocation_service === 'ip-api.com' ) { |
|
| 268 | - $data = json_decode( $geolocation_response['body'] ); |
|
| 269 | - return empty( $data ) || empty( $data->countryCode ) ? '' : $data->countryCode; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - return apply_filters( 'getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body'] ); |
|
| 273 | - |
|
| 274 | - } |
|
| 16 | + /** |
|
| 17 | + * Holds the current user's IP Address. |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + public static $current_user_ip; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * API endpoints for looking up a user IP address. |
|
| 25 | + * |
|
| 26 | + * For example, in case a user is on localhost. |
|
| 27 | + * |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + protected static $ip_lookup_apis = array( |
|
| 31 | + 'ipify' => 'http://api.ipify.org/', |
|
| 32 | + 'ipecho' => 'http://ipecho.net/plain', |
|
| 33 | + 'ident' => 'http://ident.me', |
|
| 34 | + 'whatismyipaddress' => 'http://bot.whatismyipaddress.com', |
|
| 35 | + ); |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * API endpoints for geolocating an IP address |
|
| 39 | + * |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + protected static $geoip_apis = array( |
|
| 43 | + 'ip-api.com' => 'http://ip-api.com/json/%s', |
|
| 44 | + 'ipinfo.io' => 'https://ipinfo.io/%s/json', |
|
| 45 | + ); |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Get current user IP Address. |
|
| 49 | + * |
|
| 50 | + * @return string |
|
| 51 | + */ |
|
| 52 | + public static function get_ip_address() { |
|
| 53 | + return wpinv_get_ip(); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Get user IP Address using an external service. |
|
| 58 | + * This can be used as a fallback for users on localhost where |
|
| 59 | + * get_ip_address() will be a local IP and non-geolocatable. |
|
| 60 | + * |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + public static function get_external_ip_address() { |
|
| 64 | + |
|
| 65 | + $transient_name = 'external_ip_address_0.0.0.0'; |
|
| 66 | + |
|
| 67 | + if ( '' !== self::get_ip_address() ) { |
|
| 68 | + $transient_name = 'external_ip_address_' . self::get_ip_address(); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // Try retrieving from cache. |
|
| 72 | + $external_ip_address = get_transient( $transient_name ); |
|
| 73 | + |
|
| 74 | + if ( false === $external_ip_address ) { |
|
| 75 | + $external_ip_address = '0.0.0.0'; |
|
| 76 | + $ip_lookup_services = apply_filters( 'getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis ); |
|
| 77 | + $ip_lookup_services_keys = array_keys( $ip_lookup_services ); |
|
| 78 | + shuffle( $ip_lookup_services_keys ); |
|
| 79 | + |
|
| 80 | + foreach ( $ip_lookup_services_keys as $service_name ) { |
|
| 81 | + $service_endpoint = $ip_lookup_services[ $service_name ]; |
|
| 82 | + $response = wp_safe_remote_get( $service_endpoint, array( 'timeout' => 2 ) ); |
|
| 83 | + |
|
| 84 | + if ( ! is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) { |
|
| 85 | + $external_ip_address = apply_filters( 'getpaid_geolocation_ip_lookup_api_response', wpinv_clean( $response['body'] ), $service_name ); |
|
| 86 | + break; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS ); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return $external_ip_address; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Geolocate an IP address. |
|
| 99 | + * |
|
| 100 | + * @param string $ip_address IP Address. |
|
| 101 | + * @param bool $fallback If true, fallbacks to alternative IP detection (can be slower). |
|
| 102 | + * @param bool $api_fallback If true, uses geolocation APIs if the database file doesn't exist (can be slower). |
|
| 103 | + * @return array |
|
| 104 | + */ |
|
| 105 | + public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) { |
|
| 106 | + |
|
| 107 | + if ( empty( $ip_address ) ) { |
|
| 108 | + $ip_address = self::get_ip_address(); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // Update the current user's IP Address. |
|
| 112 | + self::$current_user_ip = $ip_address; |
|
| 113 | + |
|
| 114 | + // Filter to allow custom geolocation of the IP address. |
|
| 115 | + $country_code = apply_filters( 'getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback ); |
|
| 116 | + |
|
| 117 | + if ( false !== $country_code ) { |
|
| 118 | + |
|
| 119 | + return array( |
|
| 120 | + 'country' => $country_code, |
|
| 121 | + 'state' => '', |
|
| 122 | + 'city' => '', |
|
| 123 | + 'postcode' => '', |
|
| 124 | + ); |
|
| 125 | + |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + $country_code = self::get_country_code_from_headers(); |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Get geolocation filter. |
|
| 132 | + * |
|
| 133 | + * @since 1.0.19 |
|
| 134 | + * @param array $geolocation Geolocation data, including country, state, city, and postcode. |
|
| 135 | + * @param string $ip_address IP Address. |
|
| 136 | + */ |
|
| 137 | + $geolocation = apply_filters( |
|
| 138 | + 'getpaid_get_geolocation', |
|
| 139 | + array( |
|
| 140 | + 'country' => $country_code, |
|
| 141 | + 'state' => '', |
|
| 142 | + 'city' => '', |
|
| 143 | + 'postcode' => '', |
|
| 144 | + ), |
|
| 145 | + $ip_address |
|
| 146 | + ); |
|
| 147 | + |
|
| 148 | + // If we still haven't found a country code, let's consider doing an API lookup. |
|
| 149 | + if ( '' === $geolocation['country'] && $api_fallback ) { |
|
| 150 | + $geolocation['country'] = self::geolocate_via_api( $ip_address ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // It's possible that we're in a local environment, in which case the geolocation needs to be done from the |
|
| 154 | + // external address. |
|
| 155 | + if ( '' === $geolocation['country'] && $fallback ) { |
|
| 156 | + $external_ip_address = self::get_external_ip_address(); |
|
| 157 | + |
|
| 158 | + // Only bother with this if the external IP differs. |
|
| 159 | + if ( '0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address ) { |
|
| 160 | + return self::geolocate_ip( $external_ip_address, false, $api_fallback ); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + return array( |
|
| 166 | + 'country' => $geolocation['country'], |
|
| 167 | + 'state' => $geolocation['state'], |
|
| 168 | + 'city' => $geolocation['city'], |
|
| 169 | + 'postcode' => $geolocation['postcode'], |
|
| 170 | + ); |
|
| 171 | + |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Fetches the country code from the request headers, if one is available. |
|
| 176 | + * |
|
| 177 | + * @since 1.0.19 |
|
| 178 | + * @return string The country code pulled from the headers, or empty string if one was not found. |
|
| 179 | + */ |
|
| 180 | + protected static function get_country_code_from_headers() { |
|
| 181 | + $country_code = ''; |
|
| 182 | + |
|
| 183 | + $headers = array( |
|
| 184 | + 'MM_COUNTRY_CODE', |
|
| 185 | + 'GEOIP_COUNTRY_CODE', |
|
| 186 | + 'HTTP_CF_IPCOUNTRY', |
|
| 187 | + 'HTTP_X_COUNTRY_CODE', |
|
| 188 | + ); |
|
| 189 | + |
|
| 190 | + foreach ( $headers as $header ) { |
|
| 191 | + if ( empty( $_SERVER[ $header ] ) ) { |
|
| 192 | + continue; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + $country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) ); |
|
| 196 | + break; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $country_code; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Use APIs to Geolocate the user. |
|
| 204 | + * |
|
| 205 | + * Geolocation APIs can be added through the use of the getpaid_geolocation_geoip_apis filter. |
|
| 206 | + * Provide a name=>value pair for service-slug=>endpoint. |
|
| 207 | + * |
|
| 208 | + * If APIs are defined, one will be chosen at random to fulfil the request. After completing, the result |
|
| 209 | + * will be cached in a transient. |
|
| 210 | + * |
|
| 211 | + * @param string $ip_address IP address. |
|
| 212 | + * @return string |
|
| 213 | + */ |
|
| 214 | + protected static function geolocate_via_api( $ip_address ) { |
|
| 215 | + |
|
| 216 | + // Retrieve from cache... |
|
| 217 | + $country_code = get_transient( 'geoip_' . $ip_address ); |
|
| 218 | + |
|
| 219 | + // If missing, retrieve from the API. |
|
| 220 | + if ( false === $country_code ) { |
|
| 221 | + $geoip_services = apply_filters( 'getpaid_geolocation_geoip_apis', self::$geoip_apis ); |
|
| 222 | + |
|
| 223 | + if ( empty( $geoip_services ) ) { |
|
| 224 | + return ''; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $geoip_services_keys = array_keys( $geoip_services ); |
|
| 228 | + |
|
| 229 | + shuffle( $geoip_services_keys ); |
|
| 230 | + |
|
| 231 | + foreach ( $geoip_services_keys as $service_name ) { |
|
| 232 | + |
|
| 233 | + $service_endpoint = $geoip_services[ $service_name ]; |
|
| 234 | + $response = wp_safe_remote_get( sprintf( $service_endpoint, $ip_address ), array( 'timeout' => 2 ) ); |
|
| 235 | + $country_code = sanitize_text_field( strtoupper( self::handle_geolocation_response( $response, $service_name ) ) ); |
|
| 236 | + |
|
| 237 | + if ( ! empty( $country_code ) ) { |
|
| 238 | + break; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS ); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + return $country_code; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Handles geolocation response |
|
| 251 | + * |
|
| 252 | + * @param WP_Error|String $geolocation_response |
|
| 253 | + * @param String $geolocation_service |
|
| 254 | + * @return string Country code |
|
| 255 | + */ |
|
| 256 | + protected static function handle_geolocation_response( $geolocation_response, $geolocation_service ) { |
|
| 257 | + |
|
| 258 | + if ( is_wp_error( $geolocation_response ) || empty( $geolocation_response['body'] ) ) { |
|
| 259 | + return ''; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + if ( $geolocation_service === 'ipinfo.io' ) { |
|
| 263 | + $data = json_decode( $geolocation_response['body'] ); |
|
| 264 | + return empty( $data ) || empty( $data->country ) ? '' : $data->country; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + if ( $geolocation_service === 'ip-api.com' ) { |
|
| 268 | + $data = json_decode( $geolocation_response['body'] ); |
|
| 269 | + return empty( $data ) || empty( $data->countryCode ) ? '' : $data->countryCode; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + return apply_filters( 'getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body'] ); |
|
| 273 | + |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | 276 | } |
@@ -14,76 +14,76 @@ discard block |
||
| 14 | 14 | class GetPaid_Admin { |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * Local path to this plugins admin directory |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - public $admin_path; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Web path to this plugins admin directory |
|
| 25 | - * |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - public $admin_url; |
|
| 17 | + * Local path to this plugins admin directory |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + public $admin_path; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Web path to this plugins admin directory |
|
| 25 | + * |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + public $admin_url; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Reports components. |
|
| 32 | - * |
|
| 33 | - * @var GetPaid_Reports |
|
| 34 | - */ |
|
| 30 | + /** |
|
| 31 | + * Reports components. |
|
| 32 | + * |
|
| 33 | + * @var GetPaid_Reports |
|
| 34 | + */ |
|
| 35 | 35 | public $reports; |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | - * Class constructor. |
|
| 39 | - */ |
|
| 40 | - public function __construct(){ |
|
| 38 | + * Class constructor. |
|
| 39 | + */ |
|
| 40 | + public function __construct(){ |
|
| 41 | 41 | |
| 42 | 42 | $this->admin_path = plugin_dir_path( __FILE__ ); |
| 43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
| 44 | - $this->reports = new GetPaid_Reports(); |
|
| 43 | + $this->admin_url = plugins_url( '/', __FILE__ ); |
|
| 44 | + $this->reports = new GetPaid_Reports(); |
|
| 45 | 45 | |
| 46 | 46 | if ( is_admin() ) { |
| 47 | - $this->init_admin_hooks(); |
|
| 47 | + $this->init_admin_hooks(); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | - * Init action and filter hooks |
|
| 54 | - * |
|
| 55 | - */ |
|
| 56 | - private function init_admin_hooks() { |
|
| 53 | + * Init action and filter hooks |
|
| 54 | + * |
|
| 55 | + */ |
|
| 56 | + private function init_admin_hooks() { |
|
| 57 | 57 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
| 58 | 58 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
| 59 | 59 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
| 60 | 60 | add_action( 'admin_init', array( $this, 'activation_redirect') ); |
| 61 | 61 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
| 62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
| 63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
| 64 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
| 65 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
| 62 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
| 63 | + add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
| 64 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
| 65 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
| 66 | 66 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
| 67 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
| 68 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
| 69 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
| 70 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
| 71 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
| 67 | + add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
| 68 | + add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
| 69 | + add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
| 70 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
| 71 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
| 72 | 72 | |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | - * Register admin scripts |
|
| 77 | - * |
|
| 78 | - */ |
|
| 79 | - public function enqeue_scripts() { |
|
| 76 | + * Register admin scripts |
|
| 77 | + * |
|
| 78 | + */ |
|
| 79 | + public function enqeue_scripts() { |
|
| 80 | 80 | global $current_screen, $pagenow; |
| 81 | 81 | |
| 82 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 83 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
| 82 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 83 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
| 84 | 84 | |
| 85 | 85 | if ( ! empty( $current_screen->post_type ) ) { |
| 86 | - $page = $current_screen->post_type; |
|
| 86 | + $page = $current_screen->post_type; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // General styles. |
@@ -106,54 +106,54 @@ discard block |
||
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | // Payment form scripts. |
| 109 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
| 109 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
| 110 | 110 | $this->load_payment_form_scripts(); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 114 | - wp_enqueue_script( 'postbox' ); |
|
| 115 | - } |
|
| 113 | + if ( $page == 'wpinv-subscriptions' ) { |
|
| 114 | + wp_enqueue_script( 'postbox' ); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | - * Returns admin js translations. |
|
| 121 | - * |
|
| 122 | - */ |
|
| 123 | - protected function get_admin_i18() { |
|
| 120 | + * Returns admin js translations. |
|
| 121 | + * |
|
| 122 | + */ |
|
| 123 | + protected function get_admin_i18() { |
|
| 124 | 124 | global $post; |
| 125 | 125 | |
| 126 | - $date_range = array( |
|
| 127 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
| 128 | - ); |
|
| 126 | + $date_range = array( |
|
| 127 | + 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
| 128 | + ); |
|
| 129 | 129 | |
| 130 | - if ( $date_range['period'] == 'custom' ) { |
|
| 130 | + if ( $date_range['period'] == 'custom' ) { |
|
| 131 | 131 | |
| 132 | - if ( isset( $_GET['from'] ) ) { |
|
| 133 | - $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
| 134 | - } |
|
| 132 | + if ( isset( $_GET['from'] ) ) { |
|
| 133 | + $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - if ( isset( $_GET['to'] ) ) { |
|
| 137 | - $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
| 138 | - } |
|
| 136 | + if ( isset( $_GET['to'] ) ) { |
|
| 137 | + $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - } |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | 142 | $i18n = array( |
| 143 | 143 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 144 | 144 | 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
| 145 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
| 146 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 147 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
| 148 | - 'date_range' => $date_range, |
|
| 145 | + 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
| 146 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 147 | + 'rest_root' => esc_url_raw( rest_url() ), |
|
| 148 | + 'date_range' => $date_range, |
|
| 149 | 149 | 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
| 150 | 150 | 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
| 151 | 151 | 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
| 152 | 152 | 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
| 153 | 153 | 'tax' => wpinv_tax_amount(), |
| 154 | 154 | 'discount' => 0, |
| 155 | - 'currency_symbol' => wpinv_currency_symbol(), |
|
| 156 | - 'currency' => wpinv_get_currency(), |
|
| 155 | + 'currency_symbol' => wpinv_currency_symbol(), |
|
| 156 | + 'currency' => wpinv_get_currency(), |
|
| 157 | 157 | 'currency_pos' => wpinv_currency_position(), |
| 158 | 158 | 'thousand_sep' => wpinv_thousands_separator(), |
| 159 | 159 | 'decimal_sep' => wpinv_decimal_separator(), |
@@ -176,112 +176,112 @@ discard block |
||
| 176 | 176 | 'searching' => __( 'Searching', 'invoicing' ), |
| 177 | 177 | ); |
| 178 | 178 | |
| 179 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 179 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 180 | 180 | |
| 181 | - $invoice = new WPInv_Invoice( $post ); |
|
| 182 | - $i18n['save_invoice'] = sprintf( |
|
| 183 | - __( 'Save %s', 'invoicing' ), |
|
| 184 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 185 | - ); |
|
| 181 | + $invoice = new WPInv_Invoice( $post ); |
|
| 182 | + $i18n['save_invoice'] = sprintf( |
|
| 183 | + __( 'Save %s', 'invoicing' ), |
|
| 184 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 185 | + ); |
|
| 186 | 186 | |
| 187 | - $i18n['invoice_description'] = sprintf( |
|
| 188 | - __( '%s Description', 'invoicing' ), |
|
| 189 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 190 | - ); |
|
| 187 | + $i18n['invoice_description'] = sprintf( |
|
| 188 | + __( '%s Description', 'invoicing' ), |
|
| 189 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 190 | + ); |
|
| 191 | 191 | |
| 192 | - } |
|
| 193 | - return $i18n; |
|
| 194 | - } |
|
| 192 | + } |
|
| 193 | + return $i18n; |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * Change the admin footer text on GetPaid admin pages. |
|
| 198 | - * |
|
| 199 | - * @since 2.0.0 |
|
| 200 | - * @param string $footer_text |
|
| 201 | - * @return string |
|
| 202 | - */ |
|
| 203 | - public function admin_footer_text( $footer_text ) { |
|
| 204 | - global $current_screen; |
|
| 196 | + /** |
|
| 197 | + * Change the admin footer text on GetPaid admin pages. |
|
| 198 | + * |
|
| 199 | + * @since 2.0.0 |
|
| 200 | + * @param string $footer_text |
|
| 201 | + * @return string |
|
| 202 | + */ |
|
| 203 | + public function admin_footer_text( $footer_text ) { |
|
| 204 | + global $current_screen; |
|
| 205 | 205 | |
| 206 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 206 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 207 | 207 | |
| 208 | 208 | if ( ! empty( $current_screen->post_type ) ) { |
| 209 | - $page = $current_screen->post_type; |
|
| 209 | + $page = $current_screen->post_type; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | // General styles. |
| 213 | 213 | if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
| 214 | 214 | |
| 215 | - // Change the footer text |
|
| 216 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
| 217 | - |
|
| 218 | - $rating_url = esc_url( |
|
| 219 | - wp_nonce_url( |
|
| 220 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
| 221 | - 'getpaid-nonce', |
|
| 222 | - 'getpaid-nonce' |
|
| 223 | - ) |
|
| 224 | - ); |
|
| 225 | - |
|
| 226 | - $footer_text = sprintf( |
|
| 227 | - /* translators: %s: five stars */ |
|
| 228 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
| 229 | - "<a href='$rating_url'>★★★★★</a>" |
|
| 230 | - ); |
|
| 231 | - |
|
| 232 | - } else { |
|
| 233 | - |
|
| 234 | - $footer_text = sprintf( |
|
| 235 | - /* translators: %s: GetPaid */ |
|
| 236 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
| 237 | - "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
| 238 | - ); |
|
| 239 | - |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - return $footer_text; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Redirects to wp.org to rate the plugin. |
|
| 249 | - * |
|
| 250 | - * @since 2.0.0 |
|
| 251 | - */ |
|
| 252 | - public function redirect_to_wordpress_rating_page() { |
|
| 253 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
| 254 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
| 255 | - exit; |
|
| 256 | - } |
|
| 215 | + // Change the footer text |
|
| 216 | + if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
| 217 | + |
|
| 218 | + $rating_url = esc_url( |
|
| 219 | + wp_nonce_url( |
|
| 220 | + admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
| 221 | + 'getpaid-nonce', |
|
| 222 | + 'getpaid-nonce' |
|
| 223 | + ) |
|
| 224 | + ); |
|
| 225 | + |
|
| 226 | + $footer_text = sprintf( |
|
| 227 | + /* translators: %s: five stars */ |
|
| 228 | + __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
| 229 | + "<a href='$rating_url'>★★★★★</a>" |
|
| 230 | + ); |
|
| 231 | + |
|
| 232 | + } else { |
|
| 233 | + |
|
| 234 | + $footer_text = sprintf( |
|
| 235 | + /* translators: %s: GetPaid */ |
|
| 236 | + __( 'Thank you for using %s!', 'invoicing' ), |
|
| 237 | + "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
| 238 | + ); |
|
| 239 | + |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + return $footer_text; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Redirects to wp.org to rate the plugin. |
|
| 249 | + * |
|
| 250 | + * @since 2.0.0 |
|
| 251 | + */ |
|
| 252 | + public function redirect_to_wordpress_rating_page() { |
|
| 253 | + update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
| 254 | + wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
| 255 | + exit; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | 258 | /** |
| 259 | - * Loads payment form js. |
|
| 260 | - * |
|
| 261 | - */ |
|
| 262 | - protected function load_payment_form_scripts() { |
|
| 259 | + * Loads payment form js. |
|
| 260 | + * |
|
| 261 | + */ |
|
| 262 | + protected function load_payment_form_scripts() { |
|
| 263 | 263 | global $post; |
| 264 | 264 | |
| 265 | 265 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
| 266 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 267 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 266 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 267 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 268 | 268 | |
| 269 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 270 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
| 269 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 270 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
| 271 | 271 | |
| 272 | - wp_localize_script( |
|
| 272 | + wp_localize_script( |
|
| 273 | 273 | 'wpinv-admin-payment-form-script', |
| 274 | 274 | 'wpinvPaymentFormAdmin', |
| 275 | 275 | array( |
| 276 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
| 277 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
| 278 | - 'currency' => wpinv_currency_symbol(), |
|
| 279 | - 'position' => wpinv_currency_position(), |
|
| 280 | - 'decimals' => (int) wpinv_decimals(), |
|
| 281 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
| 282 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
| 283 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
| 284 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
| 276 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
| 277 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
| 278 | + 'currency' => wpinv_currency_symbol(), |
|
| 279 | + 'position' => wpinv_currency_position(), |
|
| 280 | + 'decimals' => (int) wpinv_decimals(), |
|
| 281 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
| 282 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
| 283 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
| 284 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
| 285 | 285 | ) |
| 286 | 286 | ); |
| 287 | 287 | |
@@ -290,20 +290,20 @@ discard block |
||
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
| 293 | - * Add our classes to admin pages. |
|
| 293 | + * Add our classes to admin pages. |
|
| 294 | 294 | * |
| 295 | 295 | * @param string $classes |
| 296 | 296 | * @return string |
| 297 | - * |
|
| 298 | - */ |
|
| 297 | + * |
|
| 298 | + */ |
|
| 299 | 299 | public function admin_body_class( $classes ) { |
| 300 | - global $pagenow, $post, $current_screen; |
|
| 300 | + global $pagenow, $post, $current_screen; |
|
| 301 | 301 | |
| 302 | 302 | |
| 303 | 303 | $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
| 304 | 304 | |
| 305 | 305 | if ( ! empty( $current_screen->post_type ) ) { |
| 306 | - $page = $current_screen->post_type; |
|
| 306 | + $page = $current_screen->post_type; |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -312,59 +312,59 @@ discard block |
||
| 312 | 312 | |
| 313 | 313 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
| 314 | 314 | $classes .= ' wpinv-cpt wpinv'; |
| 315 | - } |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
| 317 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
| 318 | 318 | $classes .= ' getpaid-is-invoice-cpt'; |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | - return $classes; |
|
| 321 | + return $classes; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
| 325 | - * Maybe show the AyeCode Connect Notice. |
|
| 326 | - */ |
|
| 327 | - public function init_ayecode_connect_helper(){ |
|
| 325 | + * Maybe show the AyeCode Connect Notice. |
|
| 326 | + */ |
|
| 327 | + public function init_ayecode_connect_helper(){ |
|
| 328 | 328 | |
| 329 | 329 | new AyeCode_Connect_Helper( |
| 330 | 330 | array( |
| 331 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
| 332 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
| 333 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
| 334 | - 'connect_button' => __("Connect Site","invoicing"), |
|
| 335 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
| 336 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
| 337 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
| 331 | + 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
| 332 | + 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
| 333 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
| 334 | + 'connect_button' => __("Connect Site","invoicing"), |
|
| 335 | + 'connecting_button' => __("Connecting...","invoicing"), |
|
| 336 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
| 337 | + 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
| 338 | 338 | ), |
| 339 | 339 | array( 'wpi-addons' ) |
| 340 | 340 | ); |
| 341 | 341 | |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - /** |
|
| 345 | - * Redirect users to settings on activation. |
|
| 346 | - * |
|
| 347 | - * @return void |
|
| 348 | - */ |
|
| 349 | - public function activation_redirect() { |
|
| 344 | + /** |
|
| 345 | + * Redirect users to settings on activation. |
|
| 346 | + * |
|
| 347 | + * @return void |
|
| 348 | + */ |
|
| 349 | + public function activation_redirect() { |
|
| 350 | 350 | |
| 351 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
| 351 | + $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
| 352 | 352 | |
| 353 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
| 354 | - return; |
|
| 355 | - } |
|
| 353 | + if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
| 354 | + return; |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | - // Bail if activating from network, or bulk |
|
| 358 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 359 | - return; |
|
| 360 | - } |
|
| 357 | + // Bail if activating from network, or bulk |
|
| 358 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 359 | + return; |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
| 362 | + update_option( 'wpinv_redirected_to_settings', 1 ); |
|
| 363 | 363 | |
| 364 | 364 | wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
| 365 | 365 | exit; |
| 366 | 366 | |
| 367 | - } |
|
| 367 | + } |
|
| 368 | 368 | |
| 369 | 369 | /** |
| 370 | 370 | * Fires an admin action after verifying that a user can fire them. |
@@ -378,261 +378,261 @@ discard block |
||
| 378 | 378 | |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - /** |
|
| 381 | + /** |
|
| 382 | 382 | * Sends a payment reminder to a customer. |
| 383 | - * |
|
| 384 | - * @param array $args |
|
| 383 | + * |
|
| 384 | + * @param array $args |
|
| 385 | 385 | */ |
| 386 | 386 | public function send_customer_invoice( $args ) { |
| 387 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 387 | + $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 388 | 388 | |
| 389 | - if ( $sent ) { |
|
| 390 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
| 391 | - } else { |
|
| 392 | - $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
| 393 | - } |
|
| 389 | + if ( $sent ) { |
|
| 390 | + $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
| 391 | + } else { |
|
| 392 | + $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 396 | - exit; |
|
| 397 | - } |
|
| 395 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 396 | + exit; |
|
| 397 | + } |
|
| 398 | 398 | |
| 399 | - /** |
|
| 399 | + /** |
|
| 400 | 400 | * Sends a payment reminder to a customer. |
| 401 | - * |
|
| 402 | - * @param array $args |
|
| 401 | + * |
|
| 402 | + * @param array $args |
|
| 403 | 403 | */ |
| 404 | 404 | public function send_customer_payment_reminder( $args ) { |
| 405 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 405 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 406 | 406 | |
| 407 | - if ( $sent ) { |
|
| 408 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
| 409 | - } else { |
|
| 410 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
| 411 | - } |
|
| 407 | + if ( $sent ) { |
|
| 408 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
| 409 | + } else { |
|
| 410 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
| 411 | + } |
|
| 412 | 412 | |
| 413 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 414 | - exit; |
|
| 415 | - } |
|
| 413 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 414 | + exit; |
|
| 415 | + } |
|
| 416 | 416 | |
| 417 | - /** |
|
| 417 | + /** |
|
| 418 | 418 | * Resets tax rates. |
| 419 | - * |
|
| 419 | + * |
|
| 420 | 420 | */ |
| 421 | 421 | public function admin_reset_tax_rates() { |
| 422 | 422 | |
| 423 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 424 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 425 | - exit; |
|
| 423 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 424 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 425 | + exit; |
|
| 426 | 426 | |
| 427 | - } |
|
| 427 | + } |
|
| 428 | 428 | |
| 429 | - /** |
|
| 429 | + /** |
|
| 430 | 430 | * Resets admin pages. |
| 431 | - * |
|
| 431 | + * |
|
| 432 | 432 | */ |
| 433 | 433 | public function admin_create_missing_pages() { |
| 434 | - $installer = new GetPaid_Installer(); |
|
| 435 | - $installer->create_pages(); |
|
| 436 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
| 437 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 438 | - exit; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 434 | + $installer = new GetPaid_Installer(); |
|
| 435 | + $installer->create_pages(); |
|
| 436 | + $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
| 437 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 438 | + exit; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | 442 | * Creates an missing admin tables. |
| 443 | - * |
|
| 443 | + * |
|
| 444 | 444 | */ |
| 445 | 445 | public function admin_create_missing_tables() { |
| 446 | - global $wpdb; |
|
| 447 | - $installer = new GetPaid_Installer(); |
|
| 446 | + global $wpdb; |
|
| 447 | + $installer = new GetPaid_Installer(); |
|
| 448 | 448 | |
| 449 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
| 450 | - $installer->create_subscriptions_table(); |
|
| 449 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
| 450 | + $installer->create_subscriptions_table(); |
|
| 451 | 451 | |
| 452 | - if ( $wpdb->last_error !== '' ) { |
|
| 453 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 454 | - } |
|
| 455 | - } |
|
| 452 | + if ( $wpdb->last_error !== '' ) { |
|
| 453 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 454 | + } |
|
| 455 | + } |
|
| 456 | 456 | |
| 457 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
| 458 | - $installer->create_invoices_table(); |
|
| 457 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
| 458 | + $installer->create_invoices_table(); |
|
| 459 | 459 | |
| 460 | - if ( $wpdb->last_error !== '' ) { |
|
| 461 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 462 | - } |
|
| 463 | - } |
|
| 460 | + if ( $wpdb->last_error !== '' ) { |
|
| 461 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 462 | + } |
|
| 463 | + } |
|
| 464 | 464 | |
| 465 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
| 466 | - $installer->create_invoice_items_table(); |
|
| 465 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
| 466 | + $installer->create_invoice_items_table(); |
|
| 467 | 467 | |
| 468 | - if ( $wpdb->last_error !== '' ) { |
|
| 469 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 470 | - } |
|
| 471 | - } |
|
| 468 | + if ( $wpdb->last_error !== '' ) { |
|
| 469 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 470 | + } |
|
| 471 | + } |
|
| 472 | 472 | |
| 473 | - if ( ! $this->has_notices() ) { |
|
| 474 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
| 475 | - } |
|
| 473 | + if ( ! $this->has_notices() ) { |
|
| 474 | + $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
| 475 | + } |
|
| 476 | 476 | |
| 477 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 478 | - exit; |
|
| 479 | - } |
|
| 477 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 478 | + exit; |
|
| 479 | + } |
|
| 480 | 480 | |
| 481 | - /** |
|
| 481 | + /** |
|
| 482 | 482 | * Migrates old invoices to the new database tables. |
| 483 | - * |
|
| 483 | + * |
|
| 484 | 484 | */ |
| 485 | 485 | public function admin_migrate_old_invoices() { |
| 486 | 486 | |
| 487 | - // Migrate the invoices. |
|
| 488 | - $installer = new GetPaid_Installer(); |
|
| 489 | - $installer->migrate_old_invoices(); |
|
| 487 | + // Migrate the invoices. |
|
| 488 | + $installer = new GetPaid_Installer(); |
|
| 489 | + $installer->migrate_old_invoices(); |
|
| 490 | 490 | |
| 491 | - // Show an admin message. |
|
| 492 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
| 491 | + // Show an admin message. |
|
| 492 | + $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
| 493 | 493 | |
| 494 | - // Redirect the admin. |
|
| 495 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 496 | - exit; |
|
| 494 | + // Redirect the admin. |
|
| 495 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 496 | + exit; |
|
| 497 | 497 | |
| 498 | - } |
|
| 498 | + } |
|
| 499 | 499 | |
| 500 | 500 | /** |
| 501 | - * Returns an array of admin notices. |
|
| 502 | - * |
|
| 503 | - * @since 1.0.19 |
|
| 501 | + * Returns an array of admin notices. |
|
| 502 | + * |
|
| 503 | + * @since 1.0.19 |
|
| 504 | 504 | * @return array |
| 505 | - */ |
|
| 506 | - public function get_notices() { |
|
| 507 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
| 505 | + */ |
|
| 506 | + public function get_notices() { |
|
| 507 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
| 508 | 508 | return is_array( $notices ) ? $notices : array(); |
| 509 | - } |
|
| 509 | + } |
|
| 510 | 510 | |
| 511 | - /** |
|
| 512 | - * Checks if we have any admin notices. |
|
| 513 | - * |
|
| 514 | - * @since 2.0.4 |
|
| 511 | + /** |
|
| 512 | + * Checks if we have any admin notices. |
|
| 513 | + * |
|
| 514 | + * @since 2.0.4 |
|
| 515 | 515 | * @return array |
| 516 | - */ |
|
| 517 | - public function has_notices() { |
|
| 518 | - return count( $this->get_notices() ) > 0; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * Clears all admin notices |
|
| 523 | - * |
|
| 524 | - * @access public |
|
| 525 | - * @since 1.0.19 |
|
| 526 | - */ |
|
| 527 | - public function clear_notices() { |
|
| 528 | - delete_option( 'wpinv_admin_notices' ); |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * Saves a new admin notice |
|
| 533 | - * |
|
| 534 | - * @access public |
|
| 535 | - * @since 1.0.19 |
|
| 536 | - */ |
|
| 537 | - public function save_notice( $type, $message ) { |
|
| 538 | - $notices = $this->get_notices(); |
|
| 539 | - |
|
| 540 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
| 541 | - $notices[ $type ] = array(); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - $notices[ $type ][] = $message; |
|
| 545 | - |
|
| 546 | - update_option( 'wpinv_admin_notices', $notices ); |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Displays a success notice |
|
| 551 | - * |
|
| 552 | - * @param string $msg The message to qeue. |
|
| 553 | - * @access public |
|
| 554 | - * @since 1.0.19 |
|
| 555 | - */ |
|
| 556 | - public function show_success( $msg ) { |
|
| 557 | - $this->save_notice( 'success', $msg ); |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * Displays a error notice |
|
| 562 | - * |
|
| 563 | - * @access public |
|
| 564 | - * @param string $msg The message to qeue. |
|
| 565 | - * @since 1.0.19 |
|
| 566 | - */ |
|
| 567 | - public function show_error( $msg ) { |
|
| 568 | - $this->save_notice( 'error', $msg ); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * Displays a warning notice |
|
| 573 | - * |
|
| 574 | - * @access public |
|
| 575 | - * @param string $msg The message to qeue. |
|
| 576 | - * @since 1.0.19 |
|
| 577 | - */ |
|
| 578 | - public function show_warning( $msg ) { |
|
| 579 | - $this->save_notice( 'warning', $msg ); |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - /** |
|
| 583 | - * Displays a info notice |
|
| 584 | - * |
|
| 585 | - * @access public |
|
| 586 | - * @param string $msg The message to qeue. |
|
| 587 | - * @since 1.0.19 |
|
| 588 | - */ |
|
| 589 | - public function show_info( $msg ) { |
|
| 590 | - $this->save_notice( 'info', $msg ); |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - /** |
|
| 594 | - * Show notices |
|
| 595 | - * |
|
| 596 | - * @access public |
|
| 597 | - * @since 1.0.19 |
|
| 598 | - */ |
|
| 599 | - public function show_notices() { |
|
| 516 | + */ |
|
| 517 | + public function has_notices() { |
|
| 518 | + return count( $this->get_notices() ) > 0; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * Clears all admin notices |
|
| 523 | + * |
|
| 524 | + * @access public |
|
| 525 | + * @since 1.0.19 |
|
| 526 | + */ |
|
| 527 | + public function clear_notices() { |
|
| 528 | + delete_option( 'wpinv_admin_notices' ); |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * Saves a new admin notice |
|
| 533 | + * |
|
| 534 | + * @access public |
|
| 535 | + * @since 1.0.19 |
|
| 536 | + */ |
|
| 537 | + public function save_notice( $type, $message ) { |
|
| 538 | + $notices = $this->get_notices(); |
|
| 539 | + |
|
| 540 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
| 541 | + $notices[ $type ] = array(); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + $notices[ $type ][] = $message; |
|
| 545 | + |
|
| 546 | + update_option( 'wpinv_admin_notices', $notices ); |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Displays a success notice |
|
| 551 | + * |
|
| 552 | + * @param string $msg The message to qeue. |
|
| 553 | + * @access public |
|
| 554 | + * @since 1.0.19 |
|
| 555 | + */ |
|
| 556 | + public function show_success( $msg ) { |
|
| 557 | + $this->save_notice( 'success', $msg ); |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * Displays a error notice |
|
| 562 | + * |
|
| 563 | + * @access public |
|
| 564 | + * @param string $msg The message to qeue. |
|
| 565 | + * @since 1.0.19 |
|
| 566 | + */ |
|
| 567 | + public function show_error( $msg ) { |
|
| 568 | + $this->save_notice( 'error', $msg ); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * Displays a warning notice |
|
| 573 | + * |
|
| 574 | + * @access public |
|
| 575 | + * @param string $msg The message to qeue. |
|
| 576 | + * @since 1.0.19 |
|
| 577 | + */ |
|
| 578 | + public function show_warning( $msg ) { |
|
| 579 | + $this->save_notice( 'warning', $msg ); |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * Displays a info notice |
|
| 584 | + * |
|
| 585 | + * @access public |
|
| 586 | + * @param string $msg The message to qeue. |
|
| 587 | + * @since 1.0.19 |
|
| 588 | + */ |
|
| 589 | + public function show_info( $msg ) { |
|
| 590 | + $this->save_notice( 'info', $msg ); |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * Show notices |
|
| 595 | + * |
|
| 596 | + * @access public |
|
| 597 | + * @since 1.0.19 |
|
| 598 | + */ |
|
| 599 | + public function show_notices() { |
|
| 600 | 600 | |
| 601 | 601 | $notices = $this->get_notices(); |
| 602 | 602 | $this->clear_notices(); |
| 603 | 603 | |
| 604 | - foreach ( $notices as $type => $messages ) { |
|
| 604 | + foreach ( $notices as $type => $messages ) { |
|
| 605 | 605 | |
| 606 | - if ( ! is_array( $messages ) ) { |
|
| 607 | - continue; |
|
| 608 | - } |
|
| 606 | + if ( ! is_array( $messages ) ) { |
|
| 607 | + continue; |
|
| 608 | + } |
|
| 609 | 609 | |
| 610 | 610 | $type = sanitize_key( $type ); |
| 611 | - foreach ( $messages as $message ) { |
|
| 611 | + foreach ( $messages as $message ) { |
|
| 612 | 612 | $message = wp_kses_post( $message ); |
| 613 | - echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
| 613 | + echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
| 619 | + |
|
| 620 | + if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
| 621 | + $url = esc_url( |
|
| 622 | + wp_nonce_url( |
|
| 623 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
| 624 | + 'getpaid-nonce', |
|
| 625 | + 'getpaid-nonce' |
|
| 626 | + ) |
|
| 627 | + ); |
|
| 628 | + $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
| 629 | + $message2 = __( 'Generate Pages', 'invoicing' ); |
|
| 630 | + echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
|
| 631 | + break; |
|
| 614 | 632 | } |
| 615 | 633 | |
| 616 | 634 | } |
| 617 | 635 | |
| 618 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
| 619 | - |
|
| 620 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
| 621 | - $url = esc_url( |
|
| 622 | - wp_nonce_url( |
|
| 623 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
| 624 | - 'getpaid-nonce', |
|
| 625 | - 'getpaid-nonce' |
|
| 626 | - ) |
|
| 627 | - ); |
|
| 628 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
| 629 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
| 630 | - echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
|
| 631 | - break; |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - } |
|
| 636 | + } |
|
| 637 | 637 | |
| 638 | 638 | } |
@@ -196,11 +196,11 @@ discard block |
||
| 196 | 196 | $cb = "wpinv_{$option['type']}_callback"; |
| 197 | 197 | $section = "wpinv_settings_{$tab}_$section"; |
| 198 | 198 | |
| 199 | - if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) { |
|
| 200 | - $tip = wpinv_clean( $option['desc'] ); |
|
| 201 | - $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
| 202 | - unset( $option['desc'] ); |
|
| 203 | - } |
|
| 199 | + if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) { |
|
| 200 | + $tip = wpinv_clean( $option['desc'] ); |
|
| 201 | + $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
| 202 | + unset( $option['desc'] ); |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | 205 | // Loop through all tabs. |
| 206 | 206 | add_settings_field( |
@@ -227,8 +227,8 @@ discard block |
||
| 227 | 227 | 'faux' => isset( $option['faux'] ) ? $option['faux'] : false, |
| 228 | 228 | 'onchange' => isset( $option['onchange'] ) ? $option['onchange'] : '', |
| 229 | 229 | 'custom' => isset( $option['custom'] ) ? $option['custom'] : '', |
| 230 | - 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
| 231 | - 'style' => isset( $option['style'] ) ? $option['style'] : '', |
|
| 230 | + 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
| 231 | + 'style' => isset( $option['style'] ) ? $option['style'] : '', |
|
| 232 | 232 | 'cols' => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
| 233 | 233 | 'rows' => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
| 234 | 234 | ) |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | * @return array |
| 243 | 243 | */ |
| 244 | 244 | function wpinv_get_registered_settings() { |
| 245 | - return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) ); |
|
| 245 | + return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) ); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -289,10 +289,10 @@ discard block |
||
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | // General filter |
| 292 | - $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
| 292 | + $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
| 293 | 293 | |
| 294 | - // Key specific filter. |
|
| 295 | - $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
| 294 | + // Key specific filter. |
|
| 295 | + $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | // Loop through the whitelist and unset any that are empty for the tab being saved |
@@ -348,14 +348,14 @@ discard block |
||
| 348 | 348 | |
| 349 | 349 | foreach ( $new_rates as $rate ) { |
| 350 | 350 | |
| 351 | - $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
| 352 | - $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
| 353 | - $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
| 354 | - $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
| 355 | - $rate['global'] = empty( $rate['state'] ); |
|
| 356 | - $tax_rates[] = $rate; |
|
| 351 | + $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
| 352 | + $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
| 353 | + $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
| 354 | + $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
| 355 | + $rate['global'] = empty( $rate['state'] ); |
|
| 356 | + $tax_rates[] = $rate; |
|
| 357 | 357 | |
| 358 | - } |
|
| 358 | + } |
|
| 359 | 359 | |
| 360 | 360 | update_option( 'wpinv_tax_rates', $tax_rates ); |
| 361 | 361 | |
@@ -373,11 +373,11 @@ discard block |
||
| 373 | 373 | $tabs['general'] = __( 'General', 'invoicing' ); |
| 374 | 374 | $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' ); |
| 375 | 375 | $tabs['taxes'] = __( 'Taxes', 'invoicing' ); |
| 376 | - $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
| 376 | + $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
| 377 | 377 | |
| 378 | - if ( count( getpaid_get_integration_settings() ) > 0 ) { |
|
| 379 | - $tabs['integrations'] = __( 'Integrations', 'invoicing' ); |
|
| 380 | - } |
|
| 378 | + if ( count( getpaid_get_integration_settings() ) > 0 ) { |
|
| 379 | + $tabs['integrations'] = __( 'Integrations', 'invoicing' ); |
|
| 380 | + } |
|
| 381 | 381 | |
| 382 | 382 | $tabs['privacy'] = __( 'Privacy', 'invoicing' ); |
| 383 | 383 | $tabs['misc'] = __( 'Misc', 'invoicing' ); |
@@ -415,14 +415,14 @@ discard block |
||
| 415 | 415 | ) ), |
| 416 | 416 | 'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array( |
| 417 | 417 | 'main' => __( 'Tax Settings', 'invoicing' ), |
| 418 | - 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
| 419 | - 'vat' => __( 'EU VAT Settings', 'invoicing' ) |
|
| 418 | + 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
| 419 | + 'vat' => __( 'EU VAT Settings', 'invoicing' ) |
|
| 420 | 420 | ) ), |
| 421 | 421 | 'emails' => apply_filters( 'wpinv_settings_sections_emails', array( |
| 422 | 422 | 'main' => __( 'Email Settings', 'invoicing' ), |
| 423 | - ) ), |
|
| 423 | + ) ), |
|
| 424 | 424 | |
| 425 | - 'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ), |
|
| 425 | + 'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ), |
|
| 426 | 426 | |
| 427 | 427 | 'privacy' => apply_filters( 'wpinv_settings_sections_privacy', array( |
| 428 | 428 | 'main' => __( 'Privacy policy', 'invoicing' ), |
@@ -442,51 +442,51 @@ discard block |
||
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | function wpinv_get_pages( $with_slug = false, $default_label = NULL ) { |
| 445 | - $pages_options = array(); |
|
| 445 | + $pages_options = array(); |
|
| 446 | 446 | |
| 447 | - if( $default_label !== NULL && $default_label !== false ) { |
|
| 448 | - $pages_options = array( '' => $default_label ); // Blank option |
|
| 449 | - } |
|
| 447 | + if( $default_label !== NULL && $default_label !== false ) { |
|
| 448 | + $pages_options = array( '' => $default_label ); // Blank option |
|
| 449 | + } |
|
| 450 | 450 | |
| 451 | - $pages = get_pages(); |
|
| 452 | - if ( $pages ) { |
|
| 453 | - foreach ( $pages as $page ) { |
|
| 454 | - $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
| 451 | + $pages = get_pages(); |
|
| 452 | + if ( $pages ) { |
|
| 453 | + foreach ( $pages as $page ) { |
|
| 454 | + $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
| 455 | 455 | $pages_options[ $page->ID ] = $title; |
| 456 | - } |
|
| 457 | - } |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | 458 | |
| 459 | - return $pages_options; |
|
| 459 | + return $pages_options; |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | function wpinv_header_callback( $args ) { |
| 463 | - if ( !empty( $args['desc'] ) ) { |
|
| 463 | + if ( !empty( $args['desc'] ) ) { |
|
| 464 | 464 | echo $args['desc']; |
| 465 | 465 | } |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | function wpinv_hidden_callback( $args ) { |
| 469 | - global $wpinv_options; |
|
| 470 | - |
|
| 471 | - if ( isset( $args['set_value'] ) ) { |
|
| 472 | - $value = $args['set_value']; |
|
| 473 | - } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 474 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 475 | - } else { |
|
| 476 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 480 | - $args['readonly'] = true; |
|
| 481 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 482 | - $name = ''; |
|
| 483 | - } else { |
|
| 484 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
| 469 | + global $wpinv_options; |
|
| 470 | + |
|
| 471 | + if ( isset( $args['set_value'] ) ) { |
|
| 472 | + $value = $args['set_value']; |
|
| 473 | + } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 474 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 475 | + } else { |
|
| 476 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 480 | + $args['readonly'] = true; |
|
| 481 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 482 | + $name = ''; |
|
| 483 | + } else { |
|
| 484 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
| 488 | 488 | |
| 489 | - echo $html; |
|
| 489 | + echo $html; |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | /** |
@@ -494,12 +494,12 @@ discard block |
||
| 494 | 494 | */ |
| 495 | 495 | function wpinv_checkbox_callback( $args ) { |
| 496 | 496 | |
| 497 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 498 | - $std = wpinv_get_option( $args['id'], $std ); |
|
| 499 | - $id = esc_attr( $args['id'] ); |
|
| 497 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 498 | + $std = wpinv_get_option( $args['id'], $std ); |
|
| 499 | + $id = esc_attr( $args['id'] ); |
|
| 500 | 500 | |
| 501 | - getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
| 502 | - ?> |
|
| 501 | + getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
| 502 | + ?> |
|
| 503 | 503 | <fieldset> |
| 504 | 504 | <label> |
| 505 | 505 | <input id="wpinv-settings-<?php echo $id; ?>" name="wpinv_settings[<?php echo $id; ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox"> |
@@ -511,77 +511,77 @@ discard block |
||
| 511 | 511 | |
| 512 | 512 | function wpinv_multicheck_callback( $args ) { |
| 513 | 513 | |
| 514 | - global $wpinv_options; |
|
| 514 | + global $wpinv_options; |
|
| 515 | 515 | |
| 516 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 517 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
| 516 | + $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 517 | + $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
| 518 | 518 | |
| 519 | - if ( ! empty( $args['options'] ) ) { |
|
| 519 | + if ( ! empty( $args['options'] ) ) { |
|
| 520 | 520 | |
| 521 | - $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
| 522 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
| 521 | + $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
| 522 | + $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
| 523 | 523 | |
| 524 | - echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
|
| 524 | + echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
|
| 525 | 525 | foreach( $args['options'] as $key => $option ): |
| 526 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 527 | - if ( in_array( $sanitize_key, $value ) ) { |
|
| 528 | - $enabled = $sanitize_key; |
|
| 529 | - } else { |
|
| 530 | - $enabled = NULL; |
|
| 531 | - } |
|
| 532 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
| 533 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
| 534 | - endforeach; |
|
| 535 | - echo '</div>'; |
|
| 536 | - echo '<p class="description">' . $args['desc'] . '</p>'; |
|
| 537 | - } |
|
| 526 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 527 | + if ( in_array( $sanitize_key, $value ) ) { |
|
| 528 | + $enabled = $sanitize_key; |
|
| 529 | + } else { |
|
| 530 | + $enabled = NULL; |
|
| 531 | + } |
|
| 532 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
| 533 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
| 534 | + endforeach; |
|
| 535 | + echo '</div>'; |
|
| 536 | + echo '<p class="description">' . $args['desc'] . '</p>'; |
|
| 537 | + } |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | function wpinv_payment_icons_callback( $args ) { |
| 541 | - global $wpinv_options; |
|
| 541 | + global $wpinv_options; |
|
| 542 | 542 | |
| 543 | 543 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 544 | 544 | |
| 545 | - if ( ! empty( $args['options'] ) ) { |
|
| 546 | - foreach( $args['options'] as $key => $option ) { |
|
| 545 | + if ( ! empty( $args['options'] ) ) { |
|
| 546 | + foreach( $args['options'] as $key => $option ) { |
|
| 547 | 547 | $sanitize_key = wpinv_sanitize_key( $key ); |
| 548 | 548 | |
| 549 | - if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
| 550 | - $enabled = $option; |
|
| 551 | - } else { |
|
| 552 | - $enabled = NULL; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
| 556 | - |
|
| 557 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
| 558 | - |
|
| 559 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
| 560 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 561 | - } else { |
|
| 562 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
| 563 | - |
|
| 564 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
| 565 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
| 566 | - } else { |
|
| 567 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
| 568 | - $content_dir = WP_CONTENT_DIR; |
|
| 569 | - |
|
| 570 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
| 571 | - // Replaces backslashes with forward slashes for Windows systems |
|
| 572 | - $image = wp_normalize_path( $image ); |
|
| 573 | - $content_dir = wp_normalize_path( $content_dir ); |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 580 | - } |
|
| 581 | - echo $option . '</label>'; |
|
| 582 | - } |
|
| 583 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
| 584 | - } |
|
| 549 | + if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
| 550 | + $enabled = $option; |
|
| 551 | + } else { |
|
| 552 | + $enabled = NULL; |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
| 556 | + |
|
| 557 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
| 558 | + |
|
| 559 | + if ( wpinv_string_is_image_url( $key ) ) { |
|
| 560 | + echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 561 | + } else { |
|
| 562 | + $card = strtolower( str_replace( ' ', '', $option ) ); |
|
| 563 | + |
|
| 564 | + if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
| 565 | + $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
| 566 | + } else { |
|
| 567 | + $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
| 568 | + $content_dir = WP_CONTENT_DIR; |
|
| 569 | + |
|
| 570 | + if ( function_exists( 'wp_normalize_path' ) ) { |
|
| 571 | + // Replaces backslashes with forward slashes for Windows systems |
|
| 572 | + $image = wp_normalize_path( $image ); |
|
| 573 | + $content_dir = wp_normalize_path( $content_dir ); |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + $image = str_replace( $content_dir, content_url(), $image ); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 580 | + } |
|
| 581 | + echo $option . '</label>'; |
|
| 582 | + } |
|
| 583 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
| 584 | + } |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | /** |
@@ -589,9 +589,9 @@ discard block |
||
| 589 | 589 | */ |
| 590 | 590 | function wpinv_radio_callback( $args ) { |
| 591 | 591 | |
| 592 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 593 | - $std = wpinv_get_option( $args['id'], $std ); |
|
| 594 | - ?> |
|
| 592 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 593 | + $std = wpinv_get_option( $args['id'], $std ); |
|
| 594 | + ?> |
|
| 595 | 595 | <fieldset> |
| 596 | 596 | <ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;"> |
| 597 | 597 | <?php foreach( $args['options'] as $key => $option ) : ?> |
@@ -605,7 +605,7 @@ discard block |
||
| 605 | 605 | </ul> |
| 606 | 606 | </fieldset> |
| 607 | 607 | <?php |
| 608 | - getpaid_settings_description_callback( $args ); |
|
| 608 | + getpaid_settings_description_callback( $args ); |
|
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | /** |
@@ -613,50 +613,50 @@ discard block |
||
| 613 | 613 | */ |
| 614 | 614 | function getpaid_settings_description_callback( $args ) { |
| 615 | 615 | |
| 616 | - if ( ! empty( $args['desc'] ) ) { |
|
| 617 | - $description = wp_kses_post( $args['desc'] ); |
|
| 618 | - echo "<p class='description'>$description</p>"; |
|
| 619 | - } |
|
| 616 | + if ( ! empty( $args['desc'] ) ) { |
|
| 617 | + $description = wp_kses_post( $args['desc'] ); |
|
| 618 | + echo "<p class='description'>$description</p>"; |
|
| 619 | + } |
|
| 620 | 620 | |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | function wpinv_gateways_callback( $args ) { |
| 624 | 624 | |
| 625 | - $gateways = wpinv_get_option( 'gateways', array( 'manual' => 1 ) ); |
|
| 625 | + $gateways = wpinv_get_option( 'gateways', array( 'manual' => 1 ) ); |
|
| 626 | 626 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 627 | 627 | |
| 628 | - foreach ( $args['options'] as $key => $option ) : |
|
| 629 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 628 | + foreach ( $args['options'] as $key => $option ) : |
|
| 629 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 630 | 630 | |
| 631 | 631 | if ( is_array( $gateways ) && isset( $gateways[ $key ] ) ) |
| 632 | - $enabled = '1'; |
|
| 633 | - else |
|
| 634 | - $enabled = null; |
|
| 632 | + $enabled = '1'; |
|
| 633 | + else |
|
| 634 | + $enabled = null; |
|
| 635 | 635 | |
| 636 | - echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
| 637 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
| 638 | - endforeach; |
|
| 636 | + echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
| 637 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
| 638 | + endforeach; |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | function wpinv_gateway_select_callback($args) { |
| 642 | - global $wpinv_options; |
|
| 642 | + global $wpinv_options; |
|
| 643 | 643 | |
| 644 | 644 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 645 | 645 | $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
| 646 | 646 | |
| 647 | - echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
| 647 | + echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
| 648 | 648 | |
| 649 | - foreach ( $args['options'] as $key => $option ) : |
|
| 650 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
| 649 | + foreach ( $args['options'] as $key => $option ) : |
|
| 650 | + if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
| 651 | 651 | $selected = selected( $key, $args['selected'], false ); |
| 652 | 652 | } else { |
| 653 | 653 | $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : ''; |
| 654 | 654 | } |
| 655 | - echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
| 656 | - endforeach; |
|
| 655 | + echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
| 656 | + endforeach; |
|
| 657 | 657 | |
| 658 | - echo '</select>'; |
|
| 659 | - echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 658 | + echo '</select>'; |
|
| 659 | + echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | /** |
@@ -667,29 +667,29 @@ discard block |
||
| 667 | 667 | */ |
| 668 | 668 | function wpinv_settings_attrs_helper( $args ) { |
| 669 | 669 | |
| 670 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 671 | - $id = esc_attr( $args['id'] ); |
|
| 672 | - $placeholder = esc_attr( $args['placeholder'] ); |
|
| 670 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 671 | + $id = esc_attr( $args['id'] ); |
|
| 672 | + $placeholder = esc_attr( $args['placeholder'] ); |
|
| 673 | 673 | |
| 674 | - if ( ! empty( $args['faux'] ) ) { |
|
| 675 | - $args['readonly'] = true; |
|
| 676 | - $name = ''; |
|
| 677 | - } else { |
|
| 678 | - $value = wpinv_get_option( $args['id'], $value ); |
|
| 679 | - $name = "wpinv_settings[$id]"; |
|
| 680 | - } |
|
| 674 | + if ( ! empty( $args['faux'] ) ) { |
|
| 675 | + $args['readonly'] = true; |
|
| 676 | + $name = ''; |
|
| 677 | + } else { |
|
| 678 | + $value = wpinv_get_option( $args['id'], $value ); |
|
| 679 | + $name = "wpinv_settings[$id]"; |
|
| 680 | + } |
|
| 681 | 681 | |
| 682 | - $value = is_scalar( $value ) ? esc_attr( $value ) : ''; |
|
| 683 | - $class = esc_attr( $args['class'] ); |
|
| 684 | - $style = esc_attr( $args['style'] ); |
|
| 685 | - $readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"'; |
|
| 682 | + $value = is_scalar( $value ) ? esc_attr( $value ) : ''; |
|
| 683 | + $class = esc_attr( $args['class'] ); |
|
| 684 | + $style = esc_attr( $args['style'] ); |
|
| 685 | + $readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"'; |
|
| 686 | 686 | |
| 687 | - $onchange = ''; |
|
| 687 | + $onchange = ''; |
|
| 688 | 688 | if ( ! empty( $args['onchange'] ) ) { |
| 689 | 689 | $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
| 690 | - } |
|
| 690 | + } |
|
| 691 | 691 | |
| 692 | - return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly"; |
|
| 692 | + return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly"; |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | /** |
@@ -697,11 +697,11 @@ discard block |
||
| 697 | 697 | */ |
| 698 | 698 | function wpinv_text_callback( $args ) { |
| 699 | 699 | |
| 700 | - $desc = wp_kses_post( $args['desc'] ); |
|
| 701 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
| 702 | - $attr = wpinv_settings_attrs_helper( $args ); |
|
| 700 | + $desc = wp_kses_post( $args['desc'] ); |
|
| 701 | + $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
| 702 | + $attr = wpinv_settings_attrs_helper( $args ); |
|
| 703 | 703 | |
| 704 | - ?> |
|
| 704 | + ?> |
|
| 705 | 705 | <label style="width: 100%;"> |
| 706 | 706 | <input type="text" <?php echo $attr; ?>> |
| 707 | 707 | <?php echo $desc; ?> |
@@ -715,14 +715,14 @@ discard block |
||
| 715 | 715 | */ |
| 716 | 716 | function wpinv_number_callback( $args ) { |
| 717 | 717 | |
| 718 | - $desc = wp_kses_post( $args['desc'] ); |
|
| 719 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
| 720 | - $attr = wpinv_settings_attrs_helper( $args ); |
|
| 721 | - $max = intval( $args['max'] ); |
|
| 722 | - $min = intval( $args['min'] ); |
|
| 723 | - $step = floatval( $args['step'] ); |
|
| 718 | + $desc = wp_kses_post( $args['desc'] ); |
|
| 719 | + $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
| 720 | + $attr = wpinv_settings_attrs_helper( $args ); |
|
| 721 | + $max = intval( $args['max'] ); |
|
| 722 | + $min = intval( $args['min'] ); |
|
| 723 | + $step = floatval( $args['step'] ); |
|
| 724 | 724 | |
| 725 | - ?> |
|
| 725 | + ?> |
|
| 726 | 726 | <label style="width: 100%;"> |
| 727 | 727 | <input type="number" step="<?php echo $step; ?>" max="<?php echo $max; ?>" min="<?php echo $min; ?>" <?php echo $attr; ?>> |
| 728 | 728 | <?php echo $desc; ?> |
@@ -732,48 +732,48 @@ discard block |
||
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | function wpinv_textarea_callback( $args ) { |
| 735 | - global $wpinv_options; |
|
| 735 | + global $wpinv_options; |
|
| 736 | 736 | |
| 737 | 737 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 738 | 738 | |
| 739 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 740 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 741 | - } else { |
|
| 742 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 743 | - } |
|
| 739 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 740 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 741 | + } else { |
|
| 742 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 743 | + } |
|
| 744 | 744 | |
| 745 | 745 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
| 746 | 746 | $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
| 747 | 747 | |
| 748 | - $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
| 749 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 748 | + $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
| 749 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 750 | 750 | |
| 751 | - echo $html; |
|
| 751 | + echo $html; |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | function wpinv_password_callback( $args ) { |
| 755 | - global $wpinv_options; |
|
| 755 | + global $wpinv_options; |
|
| 756 | 756 | |
| 757 | 757 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 758 | 758 | |
| 759 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 760 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 761 | - } else { |
|
| 762 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 763 | - } |
|
| 759 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 760 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 761 | + } else { |
|
| 762 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 763 | + } |
|
| 764 | 764 | |
| 765 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 766 | - $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
| 767 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 765 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 766 | + $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
| 767 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 768 | 768 | |
| 769 | - echo $html; |
|
| 769 | + echo $html; |
|
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | function wpinv_missing_callback($args) { |
| 773 | - printf( |
|
| 774 | - __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
| 775 | - '<strong>' . $args['id'] . '</strong>' |
|
| 776 | - ); |
|
| 773 | + printf( |
|
| 774 | + __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
| 775 | + '<strong>' . $args['id'] . '</strong>' |
|
| 776 | + ); |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | /** |
@@ -781,13 +781,13 @@ discard block |
||
| 781 | 781 | */ |
| 782 | 782 | function wpinv_select_callback( $args ) { |
| 783 | 783 | |
| 784 | - $desc = wp_kses_post( $args['desc'] ); |
|
| 785 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
| 786 | - $attr = wpinv_settings_attrs_helper( $args ); |
|
| 787 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 788 | - $value = wpinv_get_option( $args['id'], $value ); |
|
| 784 | + $desc = wp_kses_post( $args['desc'] ); |
|
| 785 | + $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
| 786 | + $attr = wpinv_settings_attrs_helper( $args ); |
|
| 787 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 788 | + $value = wpinv_get_option( $args['id'], $value ); |
|
| 789 | 789 | |
| 790 | - ?> |
|
| 790 | + ?> |
|
| 791 | 791 | <label style="width: 100%;"> |
| 792 | 792 | <select <?php echo $attr; ?>> |
| 793 | 793 | <?php foreach ( $args['options'] as $option => $name ) : ?> |
@@ -801,123 +801,123 @@ discard block |
||
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | function wpinv_color_select_callback( $args ) { |
| 804 | - global $wpinv_options; |
|
| 804 | + global $wpinv_options; |
|
| 805 | 805 | |
| 806 | 806 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 807 | 807 | |
| 808 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 809 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 810 | - } else { |
|
| 811 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 812 | - } |
|
| 808 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 809 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 810 | + } else { |
|
| 811 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 812 | + } |
|
| 813 | 813 | |
| 814 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
| 814 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
| 815 | 815 | |
| 816 | - foreach ( $args['options'] as $option => $color ) { |
|
| 817 | - $selected = selected( $option, $value, false ); |
|
| 818 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
| 819 | - } |
|
| 816 | + foreach ( $args['options'] as $option => $color ) { |
|
| 817 | + $selected = selected( $option, $value, false ); |
|
| 818 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
| 819 | + } |
|
| 820 | 820 | |
| 821 | - $html .= '</select>'; |
|
| 822 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 821 | + $html .= '</select>'; |
|
| 822 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 823 | 823 | |
| 824 | - echo $html; |
|
| 824 | + echo $html; |
|
| 825 | 825 | } |
| 826 | 826 | |
| 827 | 827 | function wpinv_rich_editor_callback( $args ) { |
| 828 | - global $wpinv_options, $wp_version; |
|
| 828 | + global $wpinv_options, $wp_version; |
|
| 829 | 829 | |
| 830 | 830 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 831 | 831 | |
| 832 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 833 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 832 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 833 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 834 | 834 | |
| 835 | - if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
| 836 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 837 | - } |
|
| 838 | - } else { |
|
| 839 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 840 | - } |
|
| 835 | + if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
| 836 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 837 | + } |
|
| 838 | + } else { |
|
| 839 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 840 | + } |
|
| 841 | 841 | |
| 842 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
| 842 | + $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
| 843 | 843 | |
| 844 | - $html = '<div class="getpaid-settings-editor-input">'; |
|
| 845 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
| 846 | - ob_start(); |
|
| 847 | - wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
| 848 | - $html .= ob_get_clean(); |
|
| 849 | - } else { |
|
| 850 | - $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
| 851 | - } |
|
| 844 | + $html = '<div class="getpaid-settings-editor-input">'; |
|
| 845 | + if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
| 846 | + ob_start(); |
|
| 847 | + wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
| 848 | + $html .= ob_get_clean(); |
|
| 849 | + } else { |
|
| 850 | + $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
| 851 | + } |
|
| 852 | 852 | |
| 853 | - $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 853 | + $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 854 | 854 | |
| 855 | - echo $html; |
|
| 855 | + echo $html; |
|
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | function wpinv_upload_callback( $args ) { |
| 859 | - global $wpinv_options; |
|
| 859 | + global $wpinv_options; |
|
| 860 | 860 | |
| 861 | 861 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 862 | 862 | |
| 863 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 864 | - $value = $wpinv_options[$args['id']]; |
|
| 865 | - } else { |
|
| 866 | - $value = isset($args['std']) ? $args['std'] : ''; |
|
| 867 | - } |
|
| 863 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 864 | + $value = $wpinv_options[$args['id']]; |
|
| 865 | + } else { |
|
| 866 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
| 867 | + } |
|
| 868 | 868 | |
| 869 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 870 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
| 871 | - $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
| 872 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 869 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 870 | + $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
| 871 | + $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
| 872 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 873 | 873 | |
| 874 | - echo $html; |
|
| 874 | + echo $html; |
|
| 875 | 875 | } |
| 876 | 876 | |
| 877 | 877 | function wpinv_color_callback( $args ) { |
| 878 | - global $wpinv_options; |
|
| 878 | + global $wpinv_options; |
|
| 879 | 879 | |
| 880 | 880 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 881 | 881 | |
| 882 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 883 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 884 | - } else { |
|
| 885 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 886 | - } |
|
| 882 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 883 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 884 | + } else { |
|
| 885 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 886 | + } |
|
| 887 | 887 | |
| 888 | - $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 888 | + $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 889 | 889 | |
| 890 | - $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
| 891 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 890 | + $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
| 891 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 892 | 892 | |
| 893 | - echo $html; |
|
| 893 | + echo $html; |
|
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | function wpinv_country_states_callback($args) { |
| 897 | - global $wpinv_options; |
|
| 897 | + global $wpinv_options; |
|
| 898 | 898 | |
| 899 | 899 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 900 | 900 | |
| 901 | - if ( isset( $args['placeholder'] ) ) { |
|
| 902 | - $placeholder = $args['placeholder']; |
|
| 903 | - } else { |
|
| 904 | - $placeholder = ''; |
|
| 905 | - } |
|
| 901 | + if ( isset( $args['placeholder'] ) ) { |
|
| 902 | + $placeholder = $args['placeholder']; |
|
| 903 | + } else { |
|
| 904 | + $placeholder = ''; |
|
| 905 | + } |
|
| 906 | 906 | |
| 907 | - $states = wpinv_get_country_states(); |
|
| 907 | + $states = wpinv_get_country_states(); |
|
| 908 | 908 | |
| 909 | - $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
| 910 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
| 909 | + $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
| 910 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
| 911 | 911 | |
| 912 | - foreach ( $states as $option => $name ) { |
|
| 913 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
| 914 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
| 915 | - } |
|
| 912 | + foreach ( $states as $option => $name ) { |
|
| 913 | + $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
| 914 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
| 915 | + } |
|
| 916 | 916 | |
| 917 | - $html .= '</select>'; |
|
| 918 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 917 | + $html .= '</select>'; |
|
| 918 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 919 | 919 | |
| 920 | - echo $html; |
|
| 920 | + echo $html; |
|
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | /** |
@@ -925,7 +925,7 @@ discard block |
||
| 925 | 925 | */ |
| 926 | 926 | function wpinv_tax_rates_callback() { |
| 927 | 927 | |
| 928 | - ?> |
|
| 928 | + ?> |
|
| 929 | 929 | </td> |
| 930 | 930 | </tr> |
| 931 | 931 | <tr class="bsui"> |
@@ -940,17 +940,17 @@ discard block |
||
| 940 | 940 | * Displays a tax rate' edit row. |
| 941 | 941 | */ |
| 942 | 942 | function wpinv_tax_rate_callback( $tax_rate, $key, $echo = true ) { |
| 943 | - ob_start(); |
|
| 943 | + ob_start(); |
|
| 944 | 944 | |
| 945 | - $key = sanitize_key( $key ); |
|
| 946 | - $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
| 947 | - include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
| 945 | + $key = sanitize_key( $key ); |
|
| 946 | + $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
| 947 | + include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
| 948 | 948 | |
| 949 | - if ( $echo ) { |
|
| 950 | - echo ob_get_clean(); |
|
| 951 | - } else { |
|
| 952 | - return ob_get_clean(); |
|
| 953 | - } |
|
| 949 | + if ( $echo ) { |
|
| 950 | + echo ob_get_clean(); |
|
| 951 | + } else { |
|
| 952 | + return ob_get_clean(); |
|
| 953 | + } |
|
| 954 | 954 | |
| 955 | 955 | } |
| 956 | 956 | |
@@ -977,14 +977,14 @@ discard block |
||
| 977 | 977 | </td> |
| 978 | 978 | <td> |
| 979 | 979 | <a href="<?php |
| 980 | - echo esc_url( |
|
| 981 | - wp_nonce_url( |
|
| 982 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
| 983 | - 'getpaid-nonce', |
|
| 984 | - 'getpaid-nonce' |
|
| 985 | - ) |
|
| 986 | - ); |
|
| 987 | - ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
| 980 | + echo esc_url( |
|
| 981 | + wp_nonce_url( |
|
| 982 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
| 983 | + 'getpaid-nonce', |
|
| 984 | + 'getpaid-nonce' |
|
| 985 | + ) |
|
| 986 | + ); |
|
| 987 | + ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
| 988 | 988 | </td> |
| 989 | 989 | </tr> |
| 990 | 990 | <tr> |
@@ -994,14 +994,14 @@ discard block |
||
| 994 | 994 | </td> |
| 995 | 995 | <td> |
| 996 | 996 | <a href="<?php |
| 997 | - echo esc_url( |
|
| 998 | - wp_nonce_url( |
|
| 999 | - add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
| 1000 | - 'getpaid-nonce', |
|
| 1001 | - 'getpaid-nonce' |
|
| 1002 | - ) |
|
| 1003 | - ); |
|
| 1004 | - ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
| 997 | + echo esc_url( |
|
| 998 | + wp_nonce_url( |
|
| 999 | + add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
| 1000 | + 'getpaid-nonce', |
|
| 1001 | + 'getpaid-nonce' |
|
| 1002 | + ) |
|
| 1003 | + ); |
|
| 1004 | + ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
| 1005 | 1005 | </td> |
| 1006 | 1006 | </tr> |
| 1007 | 1007 | <tr> |
@@ -1011,14 +1011,14 @@ discard block |
||
| 1011 | 1011 | </td> |
| 1012 | 1012 | <td> |
| 1013 | 1013 | <a href="<?php |
| 1014 | - echo esc_url( |
|
| 1015 | - wp_nonce_url( |
|
| 1016 | - add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ), |
|
| 1017 | - 'getpaid-nonce', |
|
| 1018 | - 'getpaid-nonce' |
|
| 1019 | - ) |
|
| 1020 | - ); |
|
| 1021 | - ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
| 1014 | + echo esc_url( |
|
| 1015 | + wp_nonce_url( |
|
| 1016 | + add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ), |
|
| 1017 | + 'getpaid-nonce', |
|
| 1018 | + 'getpaid-nonce' |
|
| 1019 | + ) |
|
| 1020 | + ); |
|
| 1021 | + ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
| 1022 | 1022 | </td> |
| 1023 | 1023 | </tr> |
| 1024 | 1024 | <?php do_action( 'wpinv_tools_row' ); ?> |
@@ -1030,19 +1030,19 @@ discard block |
||
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | 1032 | function wpinv_descriptive_text_callback( $args ) { |
| 1033 | - echo wp_kses_post( $args['desc'] ); |
|
| 1033 | + echo wp_kses_post( $args['desc'] ); |
|
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | function wpinv_raw_html_callback( $args ) { |
| 1037 | - echo $args['desc']; |
|
| 1037 | + echo $args['desc']; |
|
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | 1040 | function wpinv_hook_callback( $args ) { |
| 1041 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
| 1041 | + do_action( 'wpinv_' . $args['id'], $args ); |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | function wpinv_set_settings_cap() { |
| 1045 | - return wpinv_get_capability(); |
|
| 1045 | + return wpinv_get_capability(); |
|
| 1046 | 1046 | } |
| 1047 | 1047 | add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
| 1048 | 1048 | |
@@ -12,125 +12,125 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class WPInv_Session_Handler extends WPInv_Session { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Cookie name used for the session. |
|
| 17 | - * |
|
| 18 | - * @var string cookie name |
|
| 19 | - */ |
|
| 20 | - protected $_cookie; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Stores session expiry. |
|
| 24 | - * |
|
| 25 | - * @var int session due to expire timestamp |
|
| 26 | - */ |
|
| 27 | - protected $_session_expiring; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Stores session due to expire timestamp. |
|
| 31 | - * |
|
| 32 | - * @var string session expiration timestamp |
|
| 33 | - */ |
|
| 34 | - protected $_session_expiration; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * True when the cookie exists. |
|
| 38 | - * |
|
| 39 | - * @var bool Based on whether a cookie exists. |
|
| 40 | - */ |
|
| 41 | - protected $_has_cookie = false; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Table name for session data. |
|
| 45 | - * |
|
| 46 | - * @var string Custom session table name |
|
| 47 | - */ |
|
| 48 | - protected $_table; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Constructor for the session class. |
|
| 52 | - */ |
|
| 53 | - public function __construct() { |
|
| 54 | - |
|
| 55 | - $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
| 15 | + /** |
|
| 16 | + * Cookie name used for the session. |
|
| 17 | + * |
|
| 18 | + * @var string cookie name |
|
| 19 | + */ |
|
| 20 | + protected $_cookie; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Stores session expiry. |
|
| 24 | + * |
|
| 25 | + * @var int session due to expire timestamp |
|
| 26 | + */ |
|
| 27 | + protected $_session_expiring; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Stores session due to expire timestamp. |
|
| 31 | + * |
|
| 32 | + * @var string session expiration timestamp |
|
| 33 | + */ |
|
| 34 | + protected $_session_expiration; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * True when the cookie exists. |
|
| 38 | + * |
|
| 39 | + * @var bool Based on whether a cookie exists. |
|
| 40 | + */ |
|
| 41 | + protected $_has_cookie = false; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Table name for session data. |
|
| 45 | + * |
|
| 46 | + * @var string Custom session table name |
|
| 47 | + */ |
|
| 48 | + protected $_table; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Constructor for the session class. |
|
| 52 | + */ |
|
| 53 | + public function __construct() { |
|
| 54 | + |
|
| 55 | + $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
| 56 | 56 | add_action( 'init', array( $this, 'init' ), -1 ); |
| 57 | - add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
| 58 | - add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
| 59 | - add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
| 60 | - |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Init hooks and session data. |
|
| 65 | - * |
|
| 66 | - * @since 3.3.0 |
|
| 67 | - */ |
|
| 68 | - public function init() { |
|
| 69 | - $this->init_session_cookie(); |
|
| 70 | - |
|
| 71 | - if ( ! is_user_logged_in() ) { |
|
| 72 | - add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ), 10, 2 ); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Setup cookie and customer ID. |
|
| 78 | - * |
|
| 79 | - * @since 3.6.0 |
|
| 80 | - */ |
|
| 81 | - public function init_session_cookie() { |
|
| 82 | - $cookie = $this->get_session_cookie(); |
|
| 83 | - |
|
| 84 | - if ( $cookie ) { |
|
| 85 | - $this->_customer_id = $cookie[0]; |
|
| 86 | - $this->_session_expiration = $cookie[1]; |
|
| 87 | - $this->_session_expiring = $cookie[2]; |
|
| 88 | - $this->_has_cookie = true; |
|
| 89 | - $this->_data = $this->get_session_data(); |
|
| 90 | - |
|
| 91 | - // If the user logs in, update session. |
|
| 92 | - if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
| 93 | - $this->_customer_id = get_current_user_id(); |
|
| 94 | - $this->_dirty = true; |
|
| 95 | - $this->save_data(); |
|
| 96 | - $this->set_customer_session_cookie( true ); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // Update session if its close to expiring. |
|
| 100 | - if ( time() > $this->_session_expiring ) { |
|
| 101 | - $this->set_session_expiration(); |
|
| 102 | - $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
| 103 | - } |
|
| 104 | - } else { |
|
| 105 | - $this->set_session_expiration(); |
|
| 106 | - $this->_customer_id = $this->generate_customer_id(); |
|
| 107 | - $this->_data = $this->get_session_data(); |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Sets the session cookie on-demand (usually after adding an item to the cart). |
|
| 113 | - * |
|
| 114 | - * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set. |
|
| 115 | - * |
|
| 116 | - * Warning: Cookies will only be set if this is called before the headers are sent. |
|
| 117 | - * |
|
| 118 | - * @param bool $set Should the session cookie be set. |
|
| 119 | - */ |
|
| 120 | - public function set_customer_session_cookie( $set ) { |
|
| 121 | - if ( $set ) { |
|
| 122 | - $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
|
| 123 | - $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 124 | - $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
|
| 125 | - $this->_has_cookie = true; |
|
| 126 | - |
|
| 127 | - if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
| 128 | - $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){ |
|
| 57 | + add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
| 58 | + add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
| 59 | + add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
| 60 | + |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Init hooks and session data. |
|
| 65 | + * |
|
| 66 | + * @since 3.3.0 |
|
| 67 | + */ |
|
| 68 | + public function init() { |
|
| 69 | + $this->init_session_cookie(); |
|
| 70 | + |
|
| 71 | + if ( ! is_user_logged_in() ) { |
|
| 72 | + add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ), 10, 2 ); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Setup cookie and customer ID. |
|
| 78 | + * |
|
| 79 | + * @since 3.6.0 |
|
| 80 | + */ |
|
| 81 | + public function init_session_cookie() { |
|
| 82 | + $cookie = $this->get_session_cookie(); |
|
| 83 | + |
|
| 84 | + if ( $cookie ) { |
|
| 85 | + $this->_customer_id = $cookie[0]; |
|
| 86 | + $this->_session_expiration = $cookie[1]; |
|
| 87 | + $this->_session_expiring = $cookie[2]; |
|
| 88 | + $this->_has_cookie = true; |
|
| 89 | + $this->_data = $this->get_session_data(); |
|
| 90 | + |
|
| 91 | + // If the user logs in, update session. |
|
| 92 | + if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
| 93 | + $this->_customer_id = get_current_user_id(); |
|
| 94 | + $this->_dirty = true; |
|
| 95 | + $this->save_data(); |
|
| 96 | + $this->set_customer_session_cookie( true ); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // Update session if its close to expiring. |
|
| 100 | + if ( time() > $this->_session_expiring ) { |
|
| 101 | + $this->set_session_expiration(); |
|
| 102 | + $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
| 103 | + } |
|
| 104 | + } else { |
|
| 105 | + $this->set_session_expiration(); |
|
| 106 | + $this->_customer_id = $this->generate_customer_id(); |
|
| 107 | + $this->_data = $this->get_session_data(); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Sets the session cookie on-demand (usually after adding an item to the cart). |
|
| 113 | + * |
|
| 114 | + * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set. |
|
| 115 | + * |
|
| 116 | + * Warning: Cookies will only be set if this is called before the headers are sent. |
|
| 117 | + * |
|
| 118 | + * @param bool $set Should the session cookie be set. |
|
| 119 | + */ |
|
| 120 | + public function set_customer_session_cookie( $set ) { |
|
| 121 | + if ( $set ) { |
|
| 122 | + $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
|
| 123 | + $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 124 | + $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
|
| 125 | + $this->_has_cookie = true; |
|
| 126 | + |
|
| 127 | + if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
| 128 | + $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){ |
|
| 134 | 134 | if ( ! headers_sent() ) { |
| 135 | 135 | setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) ); |
| 136 | 136 | } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
@@ -139,86 +139,86 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Should the session cookie be secure? |
|
| 144 | - * |
|
| 145 | - * @since 3.6.0 |
|
| 146 | - * @return bool |
|
| 147 | - */ |
|
| 148 | - protected function use_secure_cookie() { |
|
| 142 | + /** |
|
| 143 | + * Should the session cookie be secure? |
|
| 144 | + * |
|
| 145 | + * @since 3.6.0 |
|
| 146 | + * @return bool |
|
| 147 | + */ |
|
| 148 | + protected function use_secure_cookie() { |
|
| 149 | 149 | $is_https = false !== strstr( get_option( 'home' ), 'https:' ); |
| 150 | - return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Return true if the current user has an active session, i.e. a cookie to retrieve values. |
|
| 155 | - * |
|
| 156 | - * @return bool |
|
| 157 | - */ |
|
| 158 | - public function has_session() { |
|
| 159 | - return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Set session expiration. |
|
| 164 | - */ |
|
| 165 | - public function set_session_expiration() { |
|
| 166 | - $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
| 167 | - $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Generates session ids. |
|
| 172 | - * |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - public function generate_customer_id() { |
|
| 176 | - require_once ABSPATH . 'wp-includes/class-phpass.php'; |
|
| 177 | - $hasher = new PasswordHash( 8, false ); |
|
| 178 | - return md5( $hasher->get_random_bytes( 32 ) ); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Get the session cookie, if set. Otherwise return false. |
|
| 183 | - * |
|
| 184 | - * Session cookies without a customer ID are invalid. |
|
| 185 | - * |
|
| 186 | - * @return bool|array |
|
| 187 | - */ |
|
| 188 | - public function get_session_cookie() { |
|
| 189 | - $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
| 190 | - |
|
| 191 | - if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
| 192 | - return false; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
| 196 | - |
|
| 197 | - if ( empty( $customer_id ) ) { |
|
| 198 | - return false; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // Validate hash. |
|
| 202 | - $to_hash = $customer_id . '|' . $session_expiration; |
|
| 203 | - $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 204 | - |
|
| 205 | - if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
| 206 | - return false; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Get session data. |
|
| 214 | - * |
|
| 215 | - * @return array |
|
| 216 | - */ |
|
| 217 | - public function get_session_data() { |
|
| 218 | - return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - public function generate_key($customer_id){ |
|
| 150 | + return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Return true if the current user has an active session, i.e. a cookie to retrieve values. |
|
| 155 | + * |
|
| 156 | + * @return bool |
|
| 157 | + */ |
|
| 158 | + public function has_session() { |
|
| 159 | + return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Set session expiration. |
|
| 164 | + */ |
|
| 165 | + public function set_session_expiration() { |
|
| 166 | + $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
| 167 | + $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Generates session ids. |
|
| 172 | + * |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + public function generate_customer_id() { |
|
| 176 | + require_once ABSPATH . 'wp-includes/class-phpass.php'; |
|
| 177 | + $hasher = new PasswordHash( 8, false ); |
|
| 178 | + return md5( $hasher->get_random_bytes( 32 ) ); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Get the session cookie, if set. Otherwise return false. |
|
| 183 | + * |
|
| 184 | + * Session cookies without a customer ID are invalid. |
|
| 185 | + * |
|
| 186 | + * @return bool|array |
|
| 187 | + */ |
|
| 188 | + public function get_session_cookie() { |
|
| 189 | + $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
| 190 | + |
|
| 191 | + if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
| 192 | + return false; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
| 196 | + |
|
| 197 | + if ( empty( $customer_id ) ) { |
|
| 198 | + return false; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // Validate hash. |
|
| 202 | + $to_hash = $customer_id . '|' . $session_expiration; |
|
| 203 | + $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 204 | + |
|
| 205 | + if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
| 206 | + return false; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Get session data. |
|
| 214 | + * |
|
| 215 | + * @return array |
|
| 216 | + */ |
|
| 217 | + public function get_session_data() { |
|
| 218 | + return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + public function generate_key($customer_id){ |
|
| 222 | 222 | if(!$customer_id){ |
| 223 | 223 | return; |
| 224 | 224 | } |
@@ -226,68 +226,68 @@ discard block |
||
| 226 | 226 | return 'wpi_trans_'.$customer_id; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * Save data. |
|
| 231 | - */ |
|
| 232 | - public function save_data() { |
|
| 233 | - // Dirty if something changed - prevents saving nothing new. |
|
| 234 | - if ( $this->_dirty && $this->has_session() ) { |
|
| 229 | + /** |
|
| 230 | + * Save data. |
|
| 231 | + */ |
|
| 232 | + public function save_data() { |
|
| 233 | + // Dirty if something changed - prevents saving nothing new. |
|
| 234 | + if ( $this->_dirty && $this->has_session() ) { |
|
| 235 | 235 | |
| 236 | 236 | set_transient( $this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration); |
| 237 | 237 | |
| 238 | - $this->_dirty = false; |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Destroy all session data. |
|
| 244 | - */ |
|
| 245 | - public function destroy_session() { |
|
| 246 | - $this->delete_session( $this->_customer_id ); |
|
| 247 | - $this->forget_session(); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Forget all session data without destroying it. |
|
| 252 | - */ |
|
| 253 | - public function forget_session() { |
|
| 254 | - $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
| 255 | - |
|
| 256 | - wpinv_empty_cart(); |
|
| 257 | - |
|
| 258 | - $this->_data = array(); |
|
| 259 | - $this->_dirty = false; |
|
| 260 | - $this->_customer_id = $this->generate_customer_id(); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. |
|
| 265 | - * |
|
| 266 | - * @param int $uid User ID. |
|
| 267 | - * @return string |
|
| 268 | - */ |
|
| 269 | - public function nonce_user_logged_out( $uid ) { |
|
| 270 | - |
|
| 271 | - // Check if one of our nonces. |
|
| 272 | - if ( substr( $uid, 0, 5 ) === 'wpinv' || substr( $uid, 0, 7 ) === 'getpaid' ) { |
|
| 273 | - return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - return $uid; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Returns the session. |
|
| 281 | - * |
|
| 282 | - * @param string $customer_id Customer ID. |
|
| 283 | - * @param mixed $default Default session value. |
|
| 284 | - * @return string|array |
|
| 285 | - */ |
|
| 286 | - public function get_session( $customer_id, $default = false ) { |
|
| 287 | - |
|
| 288 | - if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
| 289 | - return array(); |
|
| 290 | - } |
|
| 238 | + $this->_dirty = false; |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Destroy all session data. |
|
| 244 | + */ |
|
| 245 | + public function destroy_session() { |
|
| 246 | + $this->delete_session( $this->_customer_id ); |
|
| 247 | + $this->forget_session(); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Forget all session data without destroying it. |
|
| 252 | + */ |
|
| 253 | + public function forget_session() { |
|
| 254 | + $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
| 255 | + |
|
| 256 | + wpinv_empty_cart(); |
|
| 257 | + |
|
| 258 | + $this->_data = array(); |
|
| 259 | + $this->_dirty = false; |
|
| 260 | + $this->_customer_id = $this->generate_customer_id(); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. |
|
| 265 | + * |
|
| 266 | + * @param int $uid User ID. |
|
| 267 | + * @return string |
|
| 268 | + */ |
|
| 269 | + public function nonce_user_logged_out( $uid ) { |
|
| 270 | + |
|
| 271 | + // Check if one of our nonces. |
|
| 272 | + if ( substr( $uid, 0, 5 ) === 'wpinv' || substr( $uid, 0, 7 ) === 'getpaid' ) { |
|
| 273 | + return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + return $uid; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Returns the session. |
|
| 281 | + * |
|
| 282 | + * @param string $customer_id Customer ID. |
|
| 283 | + * @param mixed $default Default session value. |
|
| 284 | + * @return string|array |
|
| 285 | + */ |
|
| 286 | + public function get_session( $customer_id, $default = false ) { |
|
| 287 | + |
|
| 288 | + if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
| 289 | + return array(); |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | 292 | $key = $this->generate_key($customer_id); |
| 293 | 293 | $value = get_transient($key); |
@@ -296,30 +296,30 @@ discard block |
||
| 296 | 296 | $value = $default; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - return maybe_unserialize( $value ); |
|
| 300 | - } |
|
| 299 | + return maybe_unserialize( $value ); |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * Delete the session from the cache and database. |
|
| 304 | - * |
|
| 305 | - * @param int $customer_id Customer ID. |
|
| 306 | - */ |
|
| 307 | - public function delete_session( $customer_id ) { |
|
| 302 | + /** |
|
| 303 | + * Delete the session from the cache and database. |
|
| 304 | + * |
|
| 305 | + * @param int $customer_id Customer ID. |
|
| 306 | + */ |
|
| 307 | + public function delete_session( $customer_id ) { |
|
| 308 | 308 | |
| 309 | 309 | $key = $this->generate_key($customer_id); |
| 310 | 310 | |
| 311 | - delete_transient($key); |
|
| 312 | - } |
|
| 311 | + delete_transient($key); |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - /** |
|
| 315 | - * Update the session expiry timestamp. |
|
| 316 | - * |
|
| 317 | - * @param string $customer_id Customer ID. |
|
| 318 | - * @param int $timestamp Timestamp to expire the cookie. |
|
| 319 | - */ |
|
| 320 | - public function update_session_timestamp( $customer_id, $timestamp ) { |
|
| 314 | + /** |
|
| 315 | + * Update the session expiry timestamp. |
|
| 316 | + * |
|
| 317 | + * @param string $customer_id Customer ID. |
|
| 318 | + * @param int $timestamp Timestamp to expire the cookie. |
|
| 319 | + */ |
|
| 320 | + public function update_session_timestamp( $customer_id, $timestamp ) { |
|
| 321 | 321 | |
| 322 | 322 | set_transient( $this->generate_key($customer_id), maybe_serialize( $this->_data ), $timestamp); |
| 323 | 323 | |
| 324 | - } |
|
| 324 | + } |
|
| 325 | 325 | } |
@@ -20,205 +20,205 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class GetPaid_Installer { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Upgrades the install. |
|
| 25 | - * |
|
| 26 | - * @param string $upgrade_from The current invoicing version. |
|
| 27 | - */ |
|
| 28 | - public function upgrade_db( $upgrade_from ) { |
|
| 29 | - |
|
| 30 | - // Save the current invoicing version. |
|
| 31 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
| 32 | - |
|
| 33 | - // Setup the invoice Custom Post Type. |
|
| 34 | - GetPaid_Post_Types::register_post_types(); |
|
| 35 | - |
|
| 36 | - // Clear the permalinks |
|
| 37 | - flush_rewrite_rules(); |
|
| 38 | - |
|
| 39 | - // Maybe create new/missing pages. |
|
| 40 | - $this->create_pages(); |
|
| 41 | - |
|
| 42 | - // Maybe re(add) admin capabilities. |
|
| 43 | - $this->add_capabilities(); |
|
| 44 | - |
|
| 45 | - // Maybe create the default payment form. |
|
| 46 | - wpinv_get_default_payment_form(); |
|
| 47 | - |
|
| 48 | - // Create any missing database tables. |
|
| 49 | - $method = "upgrade_from_$upgrade_from"; |
|
| 50 | - |
|
| 51 | - if ( method_exists( $this, $method ) ) { |
|
| 52 | - $this->$method(); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Do a fresh install. |
|
| 59 | - * |
|
| 60 | - */ |
|
| 61 | - public function upgrade_from_0() { |
|
| 62 | - $this->create_subscriptions_table(); |
|
| 63 | - $this->create_invoices_table(); |
|
| 64 | - $this->create_invoice_items_table(); |
|
| 65 | - |
|
| 66 | - // Save default tax rates. |
|
| 67 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Upgrade to 0.0.5 |
|
| 72 | - * |
|
| 73 | - */ |
|
| 74 | - public function upgrade_from_004() { |
|
| 75 | - global $wpdb; |
|
| 76 | - |
|
| 77 | - // Invoices. |
|
| 78 | - $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
| 79 | - if ( ! empty( $results ) ) { |
|
| 80 | - $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
| 81 | - |
|
| 82 | - // Clean post cache |
|
| 83 | - foreach ( $results as $row ) { |
|
| 84 | - clean_post_cache( $row->ID ); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - // Item meta key changes |
|
| 90 | - $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
| 91 | - $results = $wpdb->get_results( $query ); |
|
| 92 | - |
|
| 93 | - if ( ! empty( $results ) ) { |
|
| 94 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
| 95 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
| 96 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
| 97 | - |
|
| 98 | - foreach ( $results as $row ) { |
|
| 99 | - clean_post_cache( $row->post_id ); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $this->upgrade_from_102(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Upgrade to 1.0.3 |
|
| 109 | - * |
|
| 110 | - */ |
|
| 111 | - public function upgrade_from_102() { |
|
| 112 | - $this->create_subscriptions_table(); |
|
| 113 | - $this->upgrade_from_118(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Upgrade to version 2.0.0. |
|
| 118 | - * |
|
| 119 | - */ |
|
| 120 | - public function upgrade_from_118() { |
|
| 121 | - $this->create_invoices_table(); |
|
| 122 | - $this->create_invoice_items_table(); |
|
| 123 | - $this->migrate_old_invoices(); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Give administrators the capability to manage GetPaid. |
|
| 128 | - * |
|
| 129 | - */ |
|
| 130 | - public function add_capabilities() { |
|
| 131 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Re-create GetPaid pages. |
|
| 136 | - * |
|
| 137 | - */ |
|
| 138 | - public function create_pages() { |
|
| 139 | - |
|
| 140 | - $pages = apply_filters( |
|
| 141 | - 'wpinv_create_pages', |
|
| 142 | - array( |
|
| 143 | - |
|
| 144 | - // Checkout page. |
|
| 145 | - 'checkout_page' => array( |
|
| 146 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
| 147 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
| 148 | - 'content' => ' |
|
| 23 | + /** |
|
| 24 | + * Upgrades the install. |
|
| 25 | + * |
|
| 26 | + * @param string $upgrade_from The current invoicing version. |
|
| 27 | + */ |
|
| 28 | + public function upgrade_db( $upgrade_from ) { |
|
| 29 | + |
|
| 30 | + // Save the current invoicing version. |
|
| 31 | + update_option( 'wpinv_version', WPINV_VERSION ); |
|
| 32 | + |
|
| 33 | + // Setup the invoice Custom Post Type. |
|
| 34 | + GetPaid_Post_Types::register_post_types(); |
|
| 35 | + |
|
| 36 | + // Clear the permalinks |
|
| 37 | + flush_rewrite_rules(); |
|
| 38 | + |
|
| 39 | + // Maybe create new/missing pages. |
|
| 40 | + $this->create_pages(); |
|
| 41 | + |
|
| 42 | + // Maybe re(add) admin capabilities. |
|
| 43 | + $this->add_capabilities(); |
|
| 44 | + |
|
| 45 | + // Maybe create the default payment form. |
|
| 46 | + wpinv_get_default_payment_form(); |
|
| 47 | + |
|
| 48 | + // Create any missing database tables. |
|
| 49 | + $method = "upgrade_from_$upgrade_from"; |
|
| 50 | + |
|
| 51 | + if ( method_exists( $this, $method ) ) { |
|
| 52 | + $this->$method(); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Do a fresh install. |
|
| 59 | + * |
|
| 60 | + */ |
|
| 61 | + public function upgrade_from_0() { |
|
| 62 | + $this->create_subscriptions_table(); |
|
| 63 | + $this->create_invoices_table(); |
|
| 64 | + $this->create_invoice_items_table(); |
|
| 65 | + |
|
| 66 | + // Save default tax rates. |
|
| 67 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Upgrade to 0.0.5 |
|
| 72 | + * |
|
| 73 | + */ |
|
| 74 | + public function upgrade_from_004() { |
|
| 75 | + global $wpdb; |
|
| 76 | + |
|
| 77 | + // Invoices. |
|
| 78 | + $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
| 79 | + if ( ! empty( $results ) ) { |
|
| 80 | + $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
| 81 | + |
|
| 82 | + // Clean post cache |
|
| 83 | + foreach ( $results as $row ) { |
|
| 84 | + clean_post_cache( $row->ID ); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + // Item meta key changes |
|
| 90 | + $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
| 91 | + $results = $wpdb->get_results( $query ); |
|
| 92 | + |
|
| 93 | + if ( ! empty( $results ) ) { |
|
| 94 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
| 95 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
| 96 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
| 97 | + |
|
| 98 | + foreach ( $results as $row ) { |
|
| 99 | + clean_post_cache( $row->post_id ); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $this->upgrade_from_102(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Upgrade to 1.0.3 |
|
| 109 | + * |
|
| 110 | + */ |
|
| 111 | + public function upgrade_from_102() { |
|
| 112 | + $this->create_subscriptions_table(); |
|
| 113 | + $this->upgrade_from_118(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Upgrade to version 2.0.0. |
|
| 118 | + * |
|
| 119 | + */ |
|
| 120 | + public function upgrade_from_118() { |
|
| 121 | + $this->create_invoices_table(); |
|
| 122 | + $this->create_invoice_items_table(); |
|
| 123 | + $this->migrate_old_invoices(); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Give administrators the capability to manage GetPaid. |
|
| 128 | + * |
|
| 129 | + */ |
|
| 130 | + public function add_capabilities() { |
|
| 131 | + $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Re-create GetPaid pages. |
|
| 136 | + * |
|
| 137 | + */ |
|
| 138 | + public function create_pages() { |
|
| 139 | + |
|
| 140 | + $pages = apply_filters( |
|
| 141 | + 'wpinv_create_pages', |
|
| 142 | + array( |
|
| 143 | + |
|
| 144 | + // Checkout page. |
|
| 145 | + 'checkout_page' => array( |
|
| 146 | + 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
| 147 | + 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
| 148 | + 'content' => ' |
|
| 149 | 149 | <!-- wp:shortcode --> |
| 150 | 150 | [wpinv_checkout] |
| 151 | 151 | <!-- /wp:shortcode --> |
| 152 | 152 | ', |
| 153 | - 'parent' => '', |
|
| 154 | - ), |
|
| 155 | - |
|
| 156 | - // Invoice history page. |
|
| 157 | - 'invoice_history_page' => array( |
|
| 158 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
| 159 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
| 160 | - 'content' => ' |
|
| 153 | + 'parent' => '', |
|
| 154 | + ), |
|
| 155 | + |
|
| 156 | + // Invoice history page. |
|
| 157 | + 'invoice_history_page' => array( |
|
| 158 | + 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
| 159 | + 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
| 160 | + 'content' => ' |
|
| 161 | 161 | <!-- wp:shortcode --> |
| 162 | 162 | [wpinv_history] |
| 163 | 163 | <!-- /wp:shortcode --> |
| 164 | 164 | ', |
| 165 | - 'parent' => '', |
|
| 166 | - ), |
|
| 167 | - |
|
| 168 | - // Success page content. |
|
| 169 | - 'success_page' => array( |
|
| 170 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
| 171 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
| 172 | - 'content' => ' |
|
| 165 | + 'parent' => '', |
|
| 166 | + ), |
|
| 167 | + |
|
| 168 | + // Success page content. |
|
| 169 | + 'success_page' => array( |
|
| 170 | + 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
| 171 | + 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
| 172 | + 'content' => ' |
|
| 173 | 173 | <!-- wp:shortcode --> |
| 174 | 174 | [wpinv_receipt] |
| 175 | 175 | <!-- /wp:shortcode --> |
| 176 | 176 | ', |
| 177 | - 'parent' => 'gp-checkout', |
|
| 178 | - ), |
|
| 179 | - |
|
| 180 | - // Failure page content. |
|
| 181 | - 'failure_page' => array( |
|
| 182 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
| 183 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
| 184 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
| 185 | - 'parent' => 'gp-checkout', |
|
| 186 | - ), |
|
| 187 | - |
|
| 188 | - // Subscriptions history page. |
|
| 189 | - 'invoice_subscription_page' => array( |
|
| 190 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
| 191 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
| 192 | - 'content' => ' |
|
| 177 | + 'parent' => 'gp-checkout', |
|
| 178 | + ), |
|
| 179 | + |
|
| 180 | + // Failure page content. |
|
| 181 | + 'failure_page' => array( |
|
| 182 | + 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
| 183 | + 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
| 184 | + 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
| 185 | + 'parent' => 'gp-checkout', |
|
| 186 | + ), |
|
| 187 | + |
|
| 188 | + // Subscriptions history page. |
|
| 189 | + 'invoice_subscription_page' => array( |
|
| 190 | + 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
| 191 | + 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
| 192 | + 'content' => ' |
|
| 193 | 193 | <!-- wp:shortcode --> |
| 194 | 194 | [wpinv_subscriptions] |
| 195 | 195 | <!-- /wp:shortcode --> |
| 196 | 196 | ', |
| 197 | - 'parent' => '', |
|
| 198 | - ), |
|
| 197 | + 'parent' => '', |
|
| 198 | + ), |
|
| 199 | 199 | |
| 200 | - ) |
|
| 201 | - ); |
|
| 200 | + ) |
|
| 201 | + ); |
|
| 202 | 202 | |
| 203 | - foreach ( $pages as $key => $page ) { |
|
| 204 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
| 205 | - } |
|
| 203 | + foreach ( $pages as $key => $page ) { |
|
| 204 | + wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - } |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Create subscriptions table. |
|
| 211 | - * |
|
| 212 | - */ |
|
| 213 | - public function create_subscriptions_table() { |
|
| 209 | + /** |
|
| 210 | + * Create subscriptions table. |
|
| 211 | + * |
|
| 212 | + */ |
|
| 213 | + public function create_subscriptions_table() { |
|
| 214 | 214 | |
| 215 | - global $wpdb; |
|
| 215 | + global $wpdb; |
|
| 216 | 216 | |
| 217 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 217 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 218 | 218 | |
| 219 | - // Create tables. |
|
| 220 | - $charset_collate = $wpdb->get_charset_collate(); |
|
| 221 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
| 219 | + // Create tables. |
|
| 220 | + $charset_collate = $wpdb->get_charset_collate(); |
|
| 221 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
| 222 | 222 | id bigint(20) unsigned NOT NULL auto_increment, |
| 223 | 223 | customer_id bigint(20) NOT NULL, |
| 224 | 224 | frequency int(11) NOT NULL DEFAULT '1', |
@@ -241,22 +241,22 @@ discard block |
||
| 241 | 241 | KEY customer_and_status (customer_id, status) |
| 242 | 242 | ) $charset_collate;"; |
| 243 | 243 | |
| 244 | - dbDelta( $sql ); |
|
| 244 | + dbDelta( $sql ); |
|
| 245 | 245 | |
| 246 | - } |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * Create invoices table. |
|
| 250 | - * |
|
| 251 | - */ |
|
| 252 | - public function create_invoices_table() { |
|
| 253 | - global $wpdb; |
|
| 248 | + /** |
|
| 249 | + * Create invoices table. |
|
| 250 | + * |
|
| 251 | + */ |
|
| 252 | + public function create_invoices_table() { |
|
| 253 | + global $wpdb; |
|
| 254 | 254 | |
| 255 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 255 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 256 | 256 | |
| 257 | - // Create tables. |
|
| 258 | - $charset_collate = $wpdb->get_charset_collate(); |
|
| 259 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
| 257 | + // Create tables. |
|
| 258 | + $charset_collate = $wpdb->get_charset_collate(); |
|
| 259 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
| 260 | 260 | post_id BIGINT(20) NOT NULL, |
| 261 | 261 | `number` VARCHAR(100), |
| 262 | 262 | `key` VARCHAR(100), |
@@ -292,22 +292,22 @@ discard block |
||
| 292 | 292 | KEY `key` (`key`) |
| 293 | 293 | ) $charset_collate;"; |
| 294 | 294 | |
| 295 | - dbDelta( $sql ); |
|
| 295 | + dbDelta( $sql ); |
|
| 296 | 296 | |
| 297 | - } |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * Create invoice items table. |
|
| 301 | - * |
|
| 302 | - */ |
|
| 303 | - public function create_invoice_items_table() { |
|
| 304 | - global $wpdb; |
|
| 299 | + /** |
|
| 300 | + * Create invoice items table. |
|
| 301 | + * |
|
| 302 | + */ |
|
| 303 | + public function create_invoice_items_table() { |
|
| 304 | + global $wpdb; |
|
| 305 | 305 | |
| 306 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 306 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 307 | 307 | |
| 308 | - // Create tables. |
|
| 309 | - $charset_collate = $wpdb->get_charset_collate(); |
|
| 310 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
| 308 | + // Create tables. |
|
| 309 | + $charset_collate = $wpdb->get_charset_collate(); |
|
| 310 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
| 311 | 311 | ID BIGINT(20) NOT NULL AUTO_INCREMENT, |
| 312 | 312 | post_id BIGINT(20) NOT NULL, |
| 313 | 313 | item_id BIGINT(20) NOT NULL, |
@@ -329,138 +329,138 @@ discard block |
||
| 329 | 329 | KEY post_id (post_id) |
| 330 | 330 | ) $charset_collate;"; |
| 331 | 331 | |
| 332 | - dbDelta( $sql ); |
|
| 333 | - |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * Migrates old invoices to new invoices. |
|
| 338 | - * |
|
| 339 | - */ |
|
| 340 | - public function migrate_old_invoices() { |
|
| 341 | - global $wpdb; |
|
| 342 | - |
|
| 343 | - $invoices = array_unique( |
|
| 344 | - get_posts( |
|
| 345 | - array( |
|
| 346 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
| 347 | - 'posts_per_page' => -1, |
|
| 348 | - 'fields' => 'ids', |
|
| 349 | - 'post_status' => array_keys( get_post_stati() ), |
|
| 350 | - ) |
|
| 351 | - ) |
|
| 352 | - ); |
|
| 353 | - |
|
| 354 | - // Abort if we do not have any invoices. |
|
| 355 | - if ( empty( $invoices ) ) { |
|
| 356 | - return; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 360 | - $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 361 | - |
|
| 362 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
| 363 | - |
|
| 364 | - $invoice_rows = array(); |
|
| 365 | - foreach ( $invoices as $invoice ) { |
|
| 366 | - |
|
| 367 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
| 368 | - |
|
| 369 | - if ( empty( $invoice->ID ) ) { |
|
| 370 | - return; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - $fields = array ( |
|
| 374 | - 'post_id' => $invoice->ID, |
|
| 375 | - 'number' => $invoice->get_number(), |
|
| 376 | - 'key' => $invoice->get_key(), |
|
| 377 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
| 378 | - 'mode' => $invoice->mode, |
|
| 379 | - 'user_ip' => $invoice->get_ip(), |
|
| 380 | - 'first_name' => $invoice->get_first_name(), |
|
| 381 | - 'last_name' => $invoice->get_last_name(), |
|
| 382 | - 'address' => $invoice->get_address(), |
|
| 383 | - 'city' => $invoice->city, |
|
| 384 | - 'state' => $invoice->state, |
|
| 385 | - 'country' => $invoice->country, |
|
| 386 | - 'zip' => $invoice->zip, |
|
| 387 | - 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
| 388 | - 'gateway' => $invoice->get_gateway(), |
|
| 389 | - 'transaction_id' => $invoice->get_transaction_id(), |
|
| 390 | - 'currency' => $invoice->get_currency(), |
|
| 391 | - 'subtotal' => $invoice->get_subtotal(), |
|
| 392 | - 'tax' => $invoice->get_tax(), |
|
| 393 | - 'fees_total' => $invoice->get_fees_total(), |
|
| 394 | - 'total' => $invoice->get_total(), |
|
| 395 | - 'discount' => $invoice->get_discount(), |
|
| 396 | - 'discount_code' => $invoice->get_discount_code(), |
|
| 397 | - 'disable_taxes' => $invoice->disable_taxes, |
|
| 398 | - 'due_date' => $invoice->get_due_date(), |
|
| 399 | - 'completed_date' => $invoice->get_completed_date(), |
|
| 400 | - 'company' => $invoice->company, |
|
| 401 | - 'vat_number' => $invoice->vat_number, |
|
| 402 | - 'vat_rate' => $invoice->vat_rate, |
|
| 403 | - 'custom_meta' => $invoice->payment_meta |
|
| 404 | - ); |
|
| 405 | - |
|
| 406 | - foreach ( $fields as $key => $val ) { |
|
| 407 | - if ( is_null( $val ) ) { |
|
| 408 | - $val = ''; |
|
| 409 | - } |
|
| 410 | - $val = maybe_serialize( $val ); |
|
| 411 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - $fields = implode( ', ', $fields ); |
|
| 415 | - $invoice_rows[] = "($fields)"; |
|
| 416 | - |
|
| 417 | - $item_rows = array(); |
|
| 418 | - $item_columns = array(); |
|
| 419 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
| 420 | - $fields = array( |
|
| 421 | - 'post_id' => $invoice->ID, |
|
| 422 | - 'item_id' => $details['id'], |
|
| 423 | - 'item_name' => $details['name'], |
|
| 424 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
| 425 | - 'vat_rate' => $details['vat_rate'], |
|
| 426 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
| 427 | - 'tax' => $details['tax'], |
|
| 428 | - 'item_price' => $details['item_price'], |
|
| 429 | - 'custom_price' => $details['custom_price'], |
|
| 430 | - 'quantity' => $details['quantity'], |
|
| 431 | - 'discount' => $details['discount'], |
|
| 432 | - 'subtotal' => $details['subtotal'], |
|
| 433 | - 'price' => $details['price'], |
|
| 434 | - 'meta' => $details['meta'], |
|
| 435 | - 'fees' => $details['fees'], |
|
| 436 | - ); |
|
| 437 | - |
|
| 438 | - $item_columns = array_keys ( $fields ); |
|
| 439 | - |
|
| 440 | - foreach ( $fields as $key => $val ) { |
|
| 441 | - if ( is_null( $val ) ) { |
|
| 442 | - $val = ''; |
|
| 443 | - } |
|
| 444 | - $val = maybe_serialize( $val ); |
|
| 445 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - $fields = implode( ', ', $fields ); |
|
| 449 | - $item_rows[] = "($fields)"; |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - $item_rows = implode( ', ', $item_rows ); |
|
| 453 | - $item_columns = implode( ', ', $item_columns ); |
|
| 454 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - if ( empty( $invoice_rows ) ) { |
|
| 458 | - return; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
| 462 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
| 463 | - |
|
| 464 | - } |
|
| 332 | + dbDelta( $sql ); |
|
| 333 | + |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * Migrates old invoices to new invoices. |
|
| 338 | + * |
|
| 339 | + */ |
|
| 340 | + public function migrate_old_invoices() { |
|
| 341 | + global $wpdb; |
|
| 342 | + |
|
| 343 | + $invoices = array_unique( |
|
| 344 | + get_posts( |
|
| 345 | + array( |
|
| 346 | + 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
| 347 | + 'posts_per_page' => -1, |
|
| 348 | + 'fields' => 'ids', |
|
| 349 | + 'post_status' => array_keys( get_post_stati() ), |
|
| 350 | + ) |
|
| 351 | + ) |
|
| 352 | + ); |
|
| 353 | + |
|
| 354 | + // Abort if we do not have any invoices. |
|
| 355 | + if ( empty( $invoices ) ) { |
|
| 356 | + return; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 360 | + $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 361 | + |
|
| 362 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
| 363 | + |
|
| 364 | + $invoice_rows = array(); |
|
| 365 | + foreach ( $invoices as $invoice ) { |
|
| 366 | + |
|
| 367 | + $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
| 368 | + |
|
| 369 | + if ( empty( $invoice->ID ) ) { |
|
| 370 | + return; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + $fields = array ( |
|
| 374 | + 'post_id' => $invoice->ID, |
|
| 375 | + 'number' => $invoice->get_number(), |
|
| 376 | + 'key' => $invoice->get_key(), |
|
| 377 | + 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
| 378 | + 'mode' => $invoice->mode, |
|
| 379 | + 'user_ip' => $invoice->get_ip(), |
|
| 380 | + 'first_name' => $invoice->get_first_name(), |
|
| 381 | + 'last_name' => $invoice->get_last_name(), |
|
| 382 | + 'address' => $invoice->get_address(), |
|
| 383 | + 'city' => $invoice->city, |
|
| 384 | + 'state' => $invoice->state, |
|
| 385 | + 'country' => $invoice->country, |
|
| 386 | + 'zip' => $invoice->zip, |
|
| 387 | + 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
| 388 | + 'gateway' => $invoice->get_gateway(), |
|
| 389 | + 'transaction_id' => $invoice->get_transaction_id(), |
|
| 390 | + 'currency' => $invoice->get_currency(), |
|
| 391 | + 'subtotal' => $invoice->get_subtotal(), |
|
| 392 | + 'tax' => $invoice->get_tax(), |
|
| 393 | + 'fees_total' => $invoice->get_fees_total(), |
|
| 394 | + 'total' => $invoice->get_total(), |
|
| 395 | + 'discount' => $invoice->get_discount(), |
|
| 396 | + 'discount_code' => $invoice->get_discount_code(), |
|
| 397 | + 'disable_taxes' => $invoice->disable_taxes, |
|
| 398 | + 'due_date' => $invoice->get_due_date(), |
|
| 399 | + 'completed_date' => $invoice->get_completed_date(), |
|
| 400 | + 'company' => $invoice->company, |
|
| 401 | + 'vat_number' => $invoice->vat_number, |
|
| 402 | + 'vat_rate' => $invoice->vat_rate, |
|
| 403 | + 'custom_meta' => $invoice->payment_meta |
|
| 404 | + ); |
|
| 405 | + |
|
| 406 | + foreach ( $fields as $key => $val ) { |
|
| 407 | + if ( is_null( $val ) ) { |
|
| 408 | + $val = ''; |
|
| 409 | + } |
|
| 410 | + $val = maybe_serialize( $val ); |
|
| 411 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + $fields = implode( ', ', $fields ); |
|
| 415 | + $invoice_rows[] = "($fields)"; |
|
| 416 | + |
|
| 417 | + $item_rows = array(); |
|
| 418 | + $item_columns = array(); |
|
| 419 | + foreach ( $invoice->get_cart_details() as $details ) { |
|
| 420 | + $fields = array( |
|
| 421 | + 'post_id' => $invoice->ID, |
|
| 422 | + 'item_id' => $details['id'], |
|
| 423 | + 'item_name' => $details['name'], |
|
| 424 | + 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
| 425 | + 'vat_rate' => $details['vat_rate'], |
|
| 426 | + 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
| 427 | + 'tax' => $details['tax'], |
|
| 428 | + 'item_price' => $details['item_price'], |
|
| 429 | + 'custom_price' => $details['custom_price'], |
|
| 430 | + 'quantity' => $details['quantity'], |
|
| 431 | + 'discount' => $details['discount'], |
|
| 432 | + 'subtotal' => $details['subtotal'], |
|
| 433 | + 'price' => $details['price'], |
|
| 434 | + 'meta' => $details['meta'], |
|
| 435 | + 'fees' => $details['fees'], |
|
| 436 | + ); |
|
| 437 | + |
|
| 438 | + $item_columns = array_keys ( $fields ); |
|
| 439 | + |
|
| 440 | + foreach ( $fields as $key => $val ) { |
|
| 441 | + if ( is_null( $val ) ) { |
|
| 442 | + $val = ''; |
|
| 443 | + } |
|
| 444 | + $val = maybe_serialize( $val ); |
|
| 445 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + $fields = implode( ', ', $fields ); |
|
| 449 | + $item_rows[] = "($fields)"; |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + $item_rows = implode( ', ', $item_rows ); |
|
| 453 | + $item_columns = implode( ', ', $item_columns ); |
|
| 454 | + $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + if ( empty( $invoice_rows ) ) { |
|
| 458 | + return; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + $invoice_rows = implode( ', ', $invoice_rows ); |
|
| 462 | + $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
| 463 | + |
|
| 464 | + } |
|
| 465 | 465 | |
| 466 | 466 | } |