@@ -19,28 +19,28 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | function getpaid_get_customers( $args = array(), $return = 'results' ) { |
| 21 | 21 | |
| 22 | - // Do not retrieve all fields if we just want the count. |
|
| 23 | - if ( 'count' === $return ) { |
|
| 24 | - $args['fields'] = 'id'; |
|
| 25 | - $args['number'] = 1; |
|
| 26 | - } |
|
| 22 | + // Do not retrieve all fields if we just want the count. |
|
| 23 | + if ( 'count' === $return ) { |
|
| 24 | + $args['fields'] = 'id'; |
|
| 25 | + $args['number'] = 1; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - // Do not count all matches if we just want the results. |
|
| 29 | - if ( 'results' === $return ) { |
|
| 30 | - $args['count_total'] = false; |
|
| 31 | - } |
|
| 28 | + // Do not count all matches if we just want the results. |
|
| 29 | + if ( 'results' === $return ) { |
|
| 30 | + $args['count_total'] = false; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - $query = new GetPaid_Customers_Query( $args ); |
|
| 33 | + $query = new GetPaid_Customers_Query( $args ); |
|
| 34 | 34 | |
| 35 | - if ( 'results' === $return ) { |
|
| 36 | - return $query->get_results(); |
|
| 37 | - } |
|
| 35 | + if ( 'results' === $return ) { |
|
| 36 | + return $query->get_results(); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - if ( 'count' === $return ) { |
|
| 40 | - return $query->get_total(); |
|
| 41 | - } |
|
| 39 | + if ( 'count' === $return ) { |
|
| 40 | + return $query->get_total(); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - return $query; |
|
| 43 | + return $query; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) { |
| 108 | 108 | |
| 109 | - if ( current_user_can( 'manage_options' ) ) { |
|
| 110 | - return 'manage_options'; |
|
| 111 | - }; |
|
| 109 | + if ( current_user_can( 'manage_options' ) ) { |
|
| 110 | + return 'manage_options'; |
|
| 111 | + }; |
|
| 112 | 112 | |
| 113 | - return $capalibilty; |
|
| 113 | + return $capalibilty; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -133,9 +133,9 @@ discard block |
||
| 133 | 133 | * @return bool Whether the current user has the given capability. |
| 134 | 134 | */ |
| 135 | 135 | function wpinv_current_user_can( $capability, $args = array() ) { |
| 136 | - $can = wpinv_current_user_can_manage_invoicing(); |
|
| 136 | + $can = wpinv_current_user_can_manage_invoicing(); |
|
| 137 | 137 | |
| 138 | - return apply_filters( 'getpaid_current_user_can', $can, $capability, $args ); |
|
| 138 | + return apply_filters( 'getpaid_current_user_can', $can, $capability, $args ); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -149,10 +149,10 @@ discard block |
||
| 149 | 149 | // Prepare user values. |
| 150 | 150 | $prefix = preg_replace( '/\s+/', '', $prefix ); |
| 151 | 151 | $prefix = empty( $prefix ) ? $email : $prefix; |
| 152 | - $args = array( |
|
| 153 | - 'user_login' => wpinv_generate_user_name( $prefix ), |
|
| 154 | - 'user_pass' => wp_generate_password(), |
|
| 155 | - 'user_email' => $email, |
|
| 152 | + $args = array( |
|
| 153 | + 'user_login' => wpinv_generate_user_name( $prefix ), |
|
| 154 | + 'user_pass' => wp_generate_password(), |
|
| 155 | + 'user_email' => $email, |
|
| 156 | 156 | 'role' => 'subscriber', |
| 157 | 157 | ); |
| 158 | 158 | |
@@ -169,16 +169,16 @@ discard block |
||
| 169 | 169 | function wpinv_generate_user_name( $prefix = '' ) { |
| 170 | 170 | |
| 171 | 171 | // If prefix is an email, retrieve the part before the email. |
| 172 | - $prefix = strtok( $prefix, '@' ); |
|
| 172 | + $prefix = strtok( $prefix, '@' ); |
|
| 173 | 173 | $prefix = trim( $prefix, '.' ); |
| 174 | 174 | |
| 175 | - // Sanitize the username. |
|
| 176 | - $prefix = sanitize_user( $prefix, true ); |
|
| 175 | + // Sanitize the username. |
|
| 176 | + $prefix = sanitize_user( $prefix, true ); |
|
| 177 | 177 | |
| 178 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
| 179 | - if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
| 180 | - $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
| 181 | - } |
|
| 178 | + $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
| 179 | + if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
| 180 | + $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | 183 | $username = $prefix; |
| 184 | 184 | $postfix = 2; |
@@ -317,43 +317,43 @@ discard block |
||
| 317 | 317 | |
| 318 | 318 | $value = $customer->get( $key ); |
| 319 | 319 | |
| 320 | - // Display the country. |
|
| 321 | - if ( 'country' == $key ) { |
|
| 322 | - |
|
| 323 | - aui()->select( |
|
| 324 | - array( |
|
| 325 | - 'options' => wpinv_get_country_list(), |
|
| 326 | - 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
| 327 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
| 328 | - 'value' => sanitize_text_field( $value ), |
|
| 329 | - 'placeholder' => $label, |
|
| 330 | - 'label' => wp_kses_post( $label ), |
|
| 331 | - 'label_type' => 'vertical', |
|
| 332 | - 'class' => 'getpaid-address-field', |
|
| 320 | + // Display the country. |
|
| 321 | + if ( 'country' == $key ) { |
|
| 322 | + |
|
| 323 | + aui()->select( |
|
| 324 | + array( |
|
| 325 | + 'options' => wpinv_get_country_list(), |
|
| 326 | + 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
| 327 | + 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
| 328 | + 'value' => sanitize_text_field( $value ), |
|
| 329 | + 'placeholder' => $label, |
|
| 330 | + 'label' => wp_kses_post( $label ), |
|
| 331 | + 'label_type' => 'vertical', |
|
| 332 | + 'class' => 'getpaid-address-field', |
|
| 333 | 333 | ), |
| 334 | 334 | true |
| 335 | - ); |
|
| 335 | + ); |
|
| 336 | 336 | |
| 337 | - } |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - // Display the state. |
|
| 340 | - elseif ( 'state' == $key ) { |
|
| 339 | + // Display the state. |
|
| 340 | + elseif ( 'state' == $key ) { |
|
| 341 | 341 | |
| 342 | - getpaid_get_states_select_markup( |
|
| 342 | + getpaid_get_states_select_markup( |
|
| 343 | 343 | $customer->get( 'country' ), |
| 344 | - $value, |
|
| 345 | - $label, |
|
| 346 | - $label, |
|
| 347 | - '', |
|
| 348 | - false, |
|
| 349 | - '', |
|
| 350 | - 'getpaid_address[' . esc_attr( $key ) . ']', |
|
| 344 | + $value, |
|
| 345 | + $label, |
|
| 346 | + $label, |
|
| 347 | + '', |
|
| 348 | + false, |
|
| 349 | + '', |
|
| 350 | + 'getpaid_address[' . esc_attr( $key ) . ']', |
|
| 351 | 351 | true |
| 352 | - ); |
|
| 352 | + ); |
|
| 353 | 353 | |
| 354 | 354 | } else { |
| 355 | 355 | |
| 356 | - aui()->input( |
|
| 356 | + aui()->input( |
|
| 357 | 357 | array( |
| 358 | 358 | 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
| 359 | 359 | 'id' => 'wpinv-' . sanitize_html_class( $key ), |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | 'class' => 'getpaid-address-field', |
| 366 | 366 | ), |
| 367 | 367 | true |
| 368 | - ); |
|
| 368 | + ); |
|
| 369 | 369 | |
| 370 | 370 | } |
| 371 | 371 | } |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | function getpaid_allowed_html() { |
| 510 | 510 | $allowed_html = wp_kses_allowed_html( 'post' ); |
| 511 | 511 | |
| 512 | - // form fields |
|
| 512 | + // form fields |
|
| 513 | 513 | $allowed_html['form'] = array( |
| 514 | 514 | 'action' => true, |
| 515 | 515 | 'accept' => true, |
@@ -521,12 +521,12 @@ discard block |
||
| 521 | 521 | ); |
| 522 | 522 | |
| 523 | 523 | // - input |
| 524 | - $allowed_html['input'] = array( |
|
| 525 | - 'class' => array(), |
|
| 526 | - 'id' => array(), |
|
| 527 | - 'name' => array(), |
|
| 528 | - 'value' => array(), |
|
| 529 | - 'type' => array(), |
|
| 524 | + $allowed_html['input'] = array( |
|
| 525 | + 'class' => array(), |
|
| 526 | + 'id' => array(), |
|
| 527 | + 'name' => array(), |
|
| 528 | + 'value' => array(), |
|
| 529 | + 'type' => array(), |
|
| 530 | 530 | 'placeholder' => array(), |
| 531 | 531 | 'autocomplete' => array(), |
| 532 | 532 | 'autofocus' => array(), |
@@ -540,33 +540,33 @@ discard block |
||
| 540 | 540 | 'max' => array(), |
| 541 | 541 | 'step' => array(), |
| 542 | 542 | 'size' => array(), |
| 543 | - ); |
|
| 543 | + ); |
|
| 544 | 544 | |
| 545 | 545 | // - input |
| 546 | - $allowed_html['textarea'] = array( |
|
| 547 | - 'class' => array(), |
|
| 548 | - 'id' => array(), |
|
| 549 | - 'name' => array(), |
|
| 550 | - 'value' => array(), |
|
| 551 | - ); |
|
| 552 | - |
|
| 553 | - // select |
|
| 554 | - $allowed_html['select'] = array( |
|
| 555 | - 'class' => array(), |
|
| 556 | - 'id' => array(), |
|
| 557 | - 'name' => array(), |
|
| 546 | + $allowed_html['textarea'] = array( |
|
| 547 | + 'class' => array(), |
|
| 548 | + 'id' => array(), |
|
| 549 | + 'name' => array(), |
|
| 550 | + 'value' => array(), |
|
| 551 | + ); |
|
| 552 | + |
|
| 553 | + // select |
|
| 554 | + $allowed_html['select'] = array( |
|
| 555 | + 'class' => array(), |
|
| 556 | + 'id' => array(), |
|
| 557 | + 'name' => array(), |
|
| 558 | 558 | 'autocomplete' => array(), |
| 559 | 559 | 'multiple' => array(), |
| 560 | - ); |
|
| 560 | + ); |
|
| 561 | 561 | |
| 562 | - // select options |
|
| 563 | - $allowed_html['option'] = array( |
|
| 564 | - 'selected' => array(), |
|
| 562 | + // select options |
|
| 563 | + $allowed_html['option'] = array( |
|
| 564 | + 'selected' => array(), |
|
| 565 | 565 | 'disabled' => array(), |
| 566 | 566 | 'value' => array(), |
| 567 | - ); |
|
| 567 | + ); |
|
| 568 | 568 | |
| 569 | - return $allowed_html; |
|
| 569 | + return $allowed_html; |
|
| 570 | 570 | |
| 571 | 571 | } |
| 572 | 572 | |
@@ -870,14 +870,14 @@ discard block |
||
| 870 | 870 | * @param WP_User $user WP_User object of the user to delete. |
| 871 | 871 | */ |
| 872 | 872 | function getpaid_delete_user_data( $user_id, $reassign, $user ) { |
| 873 | - global $wpdb; |
|
| 874 | - |
|
| 875 | - // Delete customer data. |
|
| 876 | - $wpdb->delete( |
|
| 877 | - $wpdb->prefix . 'getpaid_customers', |
|
| 878 | - array( |
|
| 879 | - 'user_id' => (int) $user_id, |
|
| 880 | - ) |
|
| 881 | - ); |
|
| 873 | + global $wpdb; |
|
| 874 | + |
|
| 875 | + // Delete customer data. |
|
| 876 | + $wpdb->delete( |
|
| 877 | + $wpdb->prefix . 'getpaid_customers', |
|
| 878 | + array( |
|
| 879 | + 'user_id' => (int) $user_id, |
|
| 880 | + ) |
|
| 881 | + ); |
|
| 882 | 882 | } |
| 883 | 883 | add_action( 'delete_user', 'getpaid_delete_user_data', 10, 3 ); |
| 884 | 884 | \ No newline at end of file |
@@ -12,257 +12,257 @@ |
||
| 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 | + // Validate VAT number. |
|
| 34 | + $this->validate_vat( $submission ); |
|
| 35 | + |
|
| 36 | + if ( $this->skip_taxes ) { |
|
| 37 | + return; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + foreach ( $submission->get_items() as $item ) { |
|
| 41 | + $this->process_item_tax( $item, $submission ); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + // Process any existing invoice taxes. |
|
| 45 | + if ( $submission->has_invoice() ) { |
|
| 46 | + $invoice = $submission->get_invoice(); |
|
| 47 | + $invoice = $this->refresh_totals( $invoice, $submission ); |
|
| 48 | + |
|
| 49 | + $this->taxes = array_replace( $invoice->get_taxes(), $this->taxes ); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Maybe process tax. |
|
| 55 | + * |
|
| 56 | + * @since 1.0.19 |
|
| 57 | + * @param GetPaid_Form_Item $item |
|
| 58 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 59 | + */ |
|
| 60 | + public function process_item_tax( $item, $submission ) { |
|
| 61 | + |
|
| 62 | + $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
| 63 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 64 | + $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
| 65 | + $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
| 66 | + |
|
| 67 | + foreach ( $taxes as $name => $amount ) { |
|
| 68 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 69 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 70 | + |
|
| 71 | + $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 72 | + |
|
| 73 | + if ( ! isset( $this->taxes[ $name ] ) ) { |
|
| 74 | + $this->taxes[ $name ] = $tax; |
|
| 75 | + continue; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 79 | + $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 80 | + |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + } |
|
| 26 | 84 | |
| 27 | 85 | /** |
| 28 | - * Class constructor |
|
| 29 | - * |
|
| 30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | - */ |
|
| 32 | - public function __construct( $submission ) { |
|
| 33 | - // Validate VAT number. |
|
| 34 | - $this->validate_vat( $submission ); |
|
| 35 | - |
|
| 36 | - if ( $this->skip_taxes ) { |
|
| 37 | - return; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - foreach ( $submission->get_items() as $item ) { |
|
| 41 | - $this->process_item_tax( $item, $submission ); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - // Process any existing invoice taxes. |
|
| 45 | - if ( $submission->has_invoice() ) { |
|
| 46 | - $invoice = $submission->get_invoice(); |
|
| 47 | - $invoice = $this->refresh_totals( $invoice, $submission ); |
|
| 48 | - |
|
| 49 | - $this->taxes = array_replace( $invoice->get_taxes(), $this->taxes ); |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Maybe process tax. |
|
| 55 | - * |
|
| 56 | - * @since 1.0.19 |
|
| 57 | - * @param GetPaid_Form_Item $item |
|
| 58 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 59 | - */ |
|
| 60 | - public function process_item_tax( $item, $submission ) { |
|
| 61 | - |
|
| 62 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
| 63 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 64 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
| 65 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
| 66 | - |
|
| 67 | - foreach ( $taxes as $name => $amount ) { |
|
| 68 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 69 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 70 | - |
|
| 71 | - $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 72 | - |
|
| 73 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
| 74 | - $this->taxes[ $name ] = $tax; |
|
| 75 | - continue; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 79 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 80 | - |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Checks if the submission has a digital item. |
|
| 87 | - * |
|
| 88 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 89 | - * @since 1.0.19 |
|
| 90 | - * @return bool |
|
| 91 | - */ |
|
| 92 | - public function has_digital_item( $submission ) { |
|
| 93 | - |
|
| 94 | - foreach ( $submission->get_items() as $item ) { |
|
| 95 | - |
|
| 96 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
| 97 | - return true; |
|
| 98 | - } |
|
| 86 | + * Checks if the submission has a digital item. |
|
| 87 | + * |
|
| 88 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 89 | + * @since 1.0.19 |
|
| 90 | + * @return bool |
|
| 91 | + */ |
|
| 92 | + public function has_digital_item( $submission ) { |
|
| 93 | + |
|
| 94 | + foreach ( $submission->get_items() as $item ) { |
|
| 95 | + |
|
| 96 | + if ( 'digital' == $item->get_vat_rule() ) { |
|
| 97 | + return true; |
|
| 98 | + } |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - return false; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Checks if this is an eu store. |
|
| 106 | - * |
|
| 107 | - * @since 1.0.19 |
|
| 108 | - * @return bool |
|
| 109 | - */ |
|
| 110 | - public static function is_eu_store() { |
|
| 111 | - return self::is_eu_country( wpinv_get_default_country() ); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Checks if this is an eu country. |
|
| 116 | - * |
|
| 117 | - * @param string $country |
|
| 118 | - * @since 1.0.19 |
|
| 119 | - * @return bool |
|
| 120 | - */ |
|
| 121 | - public static function is_eu_country( $country ) { |
|
| 122 | - return getpaid_is_eu_state( $country ); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Checks if this is an eu purchase. |
|
| 127 | - * |
|
| 128 | - * @param string $customer_country |
|
| 129 | - * @since 1.0.19 |
|
| 130 | - * @return bool |
|
| 131 | - */ |
|
| 132 | - public static function is_eu_transaction( $customer_country ) { |
|
| 133 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Retrieves the vat number. |
|
| 138 | - * |
|
| 139 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 140 | - * @since 1.0.19 |
|
| 141 | - * @return string |
|
| 142 | - */ |
|
| 143 | - public function get_vat_number( $submission ) { |
|
| 144 | - |
|
| 145 | - // Retrieve from the posted number. |
|
| 146 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
| 147 | - if ( ! is_null( $vat_number ) ) { |
|
| 148 | - return wpinv_clean( $vat_number ); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Retrieves the company. |
|
| 156 | - * |
|
| 157 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 158 | - * @since 1.0.19 |
|
| 159 | - * @return string |
|
| 160 | - */ |
|
| 161 | - public function get_company( $submission ) { |
|
| 162 | - |
|
| 163 | - // Retrieve from the posted data. |
|
| 164 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
| 165 | - if ( ! empty( $company ) ) { |
|
| 166 | - return wpinv_clean( $company ); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - // Retrieve from the invoice. |
|
| 170 | - return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Checks if we require a VAT number. |
|
| 175 | - * |
|
| 176 | - * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
| 177 | - * @param bool $country_in_eu Whether the customer country is from the EU |
|
| 178 | - * @since 1.0.19 |
|
| 179 | - * @return string |
|
| 180 | - */ |
|
| 181 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 182 | - |
|
| 183 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 184 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 185 | - $is_eu = $ip_in_eu || $country_in_eu; |
|
| 186 | - |
|
| 187 | - return $prevent_b2c && $is_eu; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Validate VAT data. |
|
| 192 | - * |
|
| 193 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 194 | - * @since 1.0.19 |
|
| 195 | - */ |
|
| 196 | - public function validate_vat( $submission ) { |
|
| 197 | - |
|
| 198 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 199 | - |
|
| 200 | - // Abort if we are not validating vat numbers. |
|
| 201 | - if ( ! $in_eu ) { |
|
| 101 | + return false; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Checks if this is an eu store. |
|
| 106 | + * |
|
| 107 | + * @since 1.0.19 |
|
| 108 | + * @return bool |
|
| 109 | + */ |
|
| 110 | + public static function is_eu_store() { |
|
| 111 | + return self::is_eu_country( wpinv_get_default_country() ); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Checks if this is an eu country. |
|
| 116 | + * |
|
| 117 | + * @param string $country |
|
| 118 | + * @since 1.0.19 |
|
| 119 | + * @return bool |
|
| 120 | + */ |
|
| 121 | + public static function is_eu_country( $country ) { |
|
| 122 | + return getpaid_is_eu_state( $country ); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Checks if this is an eu purchase. |
|
| 127 | + * |
|
| 128 | + * @param string $customer_country |
|
| 129 | + * @since 1.0.19 |
|
| 130 | + * @return bool |
|
| 131 | + */ |
|
| 132 | + public static function is_eu_transaction( $customer_country ) { |
|
| 133 | + return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Retrieves the vat number. |
|
| 138 | + * |
|
| 139 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 140 | + * @since 1.0.19 |
|
| 141 | + * @return string |
|
| 142 | + */ |
|
| 143 | + public function get_vat_number( $submission ) { |
|
| 144 | + |
|
| 145 | + // Retrieve from the posted number. |
|
| 146 | + $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
| 147 | + if ( ! is_null( $vat_number ) ) { |
|
| 148 | + return wpinv_clean( $vat_number ); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Retrieves the company. |
|
| 156 | + * |
|
| 157 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 158 | + * @since 1.0.19 |
|
| 159 | + * @return string |
|
| 160 | + */ |
|
| 161 | + public function get_company( $submission ) { |
|
| 162 | + |
|
| 163 | + // Retrieve from the posted data. |
|
| 164 | + $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
| 165 | + if ( ! empty( $company ) ) { |
|
| 166 | + return wpinv_clean( $company ); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + // Retrieve from the invoice. |
|
| 170 | + return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Checks if we require a VAT number. |
|
| 175 | + * |
|
| 176 | + * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
| 177 | + * @param bool $country_in_eu Whether the customer country is from the EU |
|
| 178 | + * @since 1.0.19 |
|
| 179 | + * @return string |
|
| 180 | + */ |
|
| 181 | + public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 182 | + |
|
| 183 | + $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 184 | + $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 185 | + $is_eu = $ip_in_eu || $country_in_eu; |
|
| 186 | + |
|
| 187 | + return $prevent_b2c && $is_eu; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Validate VAT data. |
|
| 192 | + * |
|
| 193 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 194 | + * @since 1.0.19 |
|
| 195 | + */ |
|
| 196 | + public function validate_vat( $submission ) { |
|
| 197 | + |
|
| 198 | + $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 199 | + |
|
| 200 | + // Abort if we are not validating vat numbers. |
|
| 201 | + if ( ! $in_eu ) { |
|
| 202 | 202 | return; |
| 203 | - } |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - // Prepare variables. |
|
| 206 | - $vat_number = $this->get_vat_number( $submission ); |
|
| 207 | - $ip_country = getpaid_get_ip_country(); |
|
| 205 | + // Prepare variables. |
|
| 206 | + $vat_number = $this->get_vat_number( $submission ); |
|
| 207 | + $ip_country = getpaid_get_ip_country(); |
|
| 208 | 208 | $is_eu = $this->is_eu_country( $submission->country ); |
| 209 | 209 | $is_ip_eu = $this->is_eu_country( $ip_country ); |
| 210 | 210 | |
| 211 | - // Maybe abort early for initial fetches. |
|
| 212 | - if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
| 213 | - return; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - // If we're preventing business to consumer purchases, |
|
| 217 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 218 | - |
|
| 219 | - // Ensure that a vat number has been specified. |
|
| 220 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) ); |
|
| 221 | - |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - if ( empty( $vat_number ) ) { |
|
| 225 | - return; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
| 229 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 233 | - return; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - $this->skip_taxes = true; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Refresh totals if country or region changed in payment form. |
|
| 241 | - * |
|
| 242 | - * @since 2.8.8 |
|
| 243 | - * |
|
| 244 | - * @param object $invoice Invoice object. |
|
| 245 | - * @param GetPaid_Payment_Form_Submission $submission Payment form submission object. |
|
| 246 | - * @return object Invoice object. |
|
| 247 | - */ |
|
| 248 | - public function refresh_totals( $invoice, $submission ) { |
|
| 249 | - if ( ! ( ! empty( $_POST['action'] ) && ( $_POST['action'] == 'wpinv_payment_form_refresh_prices' || $_POST['action'] == 'wpinv_payment_form' ) && isset( $_POST['billing']['wpinv_country'] ) ) ) { |
|
| 250 | - return $invoice; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - if ( ! ( ! $invoice->is_paid() && ! $invoice->is_refunded() && ! $invoice->is_held() ) ) { |
|
| 254 | - return $invoice; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - // Maybe check the country, state. |
|
| 258 | - if ( $submission->country != $invoice->get_country() || $submission->state != $invoice->get_state() ) { |
|
| 259 | - $invoice->set_country( sanitize_text_field( $submission->country ) ); |
|
| 260 | - $invoice->set_state( sanitize_text_field( $submission->state ) ); |
|
| 261 | - |
|
| 262 | - // Recalculate totals. |
|
| 263 | - $invoice->recalculate_total(); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - return $invoice; |
|
| 267 | - } |
|
| 211 | + // Maybe abort early for initial fetches. |
|
| 212 | + if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
| 213 | + return; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + // If we're preventing business to consumer purchases, |
|
| 217 | + if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 218 | + |
|
| 219 | + // Ensure that a vat number has been specified. |
|
| 220 | + throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) ); |
|
| 221 | + |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + if ( empty( $vat_number ) ) { |
|
| 225 | + return; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
| 229 | + throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 233 | + return; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + $this->skip_taxes = true; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Refresh totals if country or region changed in payment form. |
|
| 241 | + * |
|
| 242 | + * @since 2.8.8 |
|
| 243 | + * |
|
| 244 | + * @param object $invoice Invoice object. |
|
| 245 | + * @param GetPaid_Payment_Form_Submission $submission Payment form submission object. |
|
| 246 | + * @return object Invoice object. |
|
| 247 | + */ |
|
| 248 | + public function refresh_totals( $invoice, $submission ) { |
|
| 249 | + if ( ! ( ! empty( $_POST['action'] ) && ( $_POST['action'] == 'wpinv_payment_form_refresh_prices' || $_POST['action'] == 'wpinv_payment_form' ) && isset( $_POST['billing']['wpinv_country'] ) ) ) { |
|
| 250 | + return $invoice; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + if ( ! ( ! $invoice->is_paid() && ! $invoice->is_refunded() && ! $invoice->is_held() ) ) { |
|
| 254 | + return $invoice; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + // Maybe check the country, state. |
|
| 258 | + if ( $submission->country != $invoice->get_country() || $submission->state != $invoice->get_state() ) { |
|
| 259 | + $invoice->set_country( sanitize_text_field( $submission->country ) ); |
|
| 260 | + $invoice->set_state( sanitize_text_field( $submission->state ) ); |
|
| 261 | + |
|
| 262 | + // Recalculate totals. |
|
| 263 | + $invoice->recalculate_total(); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + return $invoice; |
|
| 267 | + } |
|
| 268 | 268 | } |
@@ -13,738 +13,738 @@ discard block |
||
| 13 | 13 | class GetPaid_Post_Types_Admin { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Hook in methods. |
|
| 17 | - */ |
|
| 18 | - public static function init() { |
|
| 19 | - |
|
| 20 | - // Init metaboxes. |
|
| 21 | - GetPaid_Metaboxes::init(); |
|
| 22 | - |
|
| 23 | - // Filter the post updated messages. |
|
| 24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
| 25 | - |
|
| 26 | - // Filter post actions. |
|
| 27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
| 28 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
| 29 | - |
|
| 30 | - // Invoice table columns. |
|
| 31 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
| 32 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
| 33 | - add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
| 34 | - add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
| 35 | - |
|
| 36 | - // Items table columns. |
|
| 37 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
| 38 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
| 39 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
| 40 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
| 41 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
| 42 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
| 43 | - |
|
| 44 | - // Payment forms columns. |
|
| 45 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
| 46 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
| 47 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
| 48 | - |
|
| 49 | - // Discount table columns. |
|
| 50 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
| 51 | - add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
| 52 | - |
|
| 53 | - // Deleting posts. |
|
| 54 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
| 55 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
| 56 | - |
|
| 57 | - add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Post updated messages. |
|
| 62 | - */ |
|
| 63 | - public static function post_updated_messages( $messages ) { |
|
| 64 | - global $post; |
|
| 65 | - |
|
| 66 | - $messages['wpi_discount'] = array( |
|
| 67 | - 0 => '', |
|
| 68 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
| 69 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 70 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 71 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
| 72 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 73 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
| 74 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
| 75 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
| 76 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 77 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - $messages['wpi_payment_form'] = array( |
|
| 81 | - 0 => '', |
|
| 82 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 83 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 84 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 85 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 86 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 87 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 88 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
| 89 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
| 90 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 91 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
| 92 | - ); |
|
| 93 | - |
|
| 94 | - return $messages; |
|
| 95 | - |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Post row actions. |
|
| 100 | - */ |
|
| 101 | - public static function post_row_actions( $actions, $post ) { |
|
| 102 | - |
|
| 103 | - $post = get_post( $post ); |
|
| 104 | - |
|
| 105 | - // We do not want to edit the default payment form. |
|
| 106 | - if ( 'wpi_payment_form' == $post->post_type ) { |
|
| 107 | - |
|
| 108 | - if ( wpinv_get_default_payment_form() === $post->ID ) { |
|
| 109 | - unset( $actions['trash'] ); |
|
| 110 | - unset( $actions['inline hide-if-no-js'] ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $actions['duplicate'] = sprintf( |
|
| 114 | - '<a href="%1$s">%2$s</a>', |
|
| 115 | - esc_url( |
|
| 116 | - wp_nonce_url( |
|
| 117 | - add_query_arg( |
|
| 118 | - array( |
|
| 119 | - 'getpaid-admin-action' => 'duplicate_form', |
|
| 120 | - 'form_id' => $post->ID, |
|
| 121 | - ) |
|
| 122 | - ), |
|
| 123 | - 'getpaid-nonce', |
|
| 124 | - 'getpaid-nonce' |
|
| 125 | - ) |
|
| 126 | - ), |
|
| 127 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
| 128 | - ); |
|
| 129 | - |
|
| 130 | - $actions['reset'] = sprintf( |
|
| 131 | - '<a href="%1$s" style="color: #800">%2$s</a>', |
|
| 132 | - esc_url( |
|
| 133 | - wp_nonce_url( |
|
| 134 | - add_query_arg( |
|
| 135 | - array( |
|
| 136 | - 'getpaid-admin-action' => 'reset_form_stats', |
|
| 137 | - 'form_id' => $post->ID, |
|
| 138 | - ) |
|
| 139 | - ), |
|
| 140 | - 'getpaid-nonce', |
|
| 141 | - 'getpaid-nonce' |
|
| 142 | - ) |
|
| 143 | - ), |
|
| 144 | - esc_html( __( 'Reset Stats', 'invoicing' ) ) |
|
| 145 | - ); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - // Link to item payment form. |
|
| 149 | - if ( 'wpi_item' == $post->post_type ) { |
|
| 150 | - if ( getpaid_item_type_supports( get_post_meta( $post->ID, '_wpinv_type', true ), 'buy_now' ) ) { |
|
| 151 | - $actions['buy'] = sprintf( |
|
| 152 | - '<a href="%1$s">%2$s</a>', |
|
| 153 | - esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ), |
|
| 154 | - esc_html( __( 'Buy', 'invoicing' ) ) |
|
| 155 | - ); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - return $actions; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 16 | + * Hook in methods. |
|
| 17 | + */ |
|
| 18 | + public static function init() { |
|
| 19 | + |
|
| 20 | + // Init metaboxes. |
|
| 21 | + GetPaid_Metaboxes::init(); |
|
| 22 | + |
|
| 23 | + // Filter the post updated messages. |
|
| 24 | + add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
| 25 | + |
|
| 26 | + // Filter post actions. |
|
| 27 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
| 28 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
| 29 | + |
|
| 30 | + // Invoice table columns. |
|
| 31 | + add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
| 32 | + add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
| 33 | + add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
| 34 | + add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
| 35 | + |
|
| 36 | + // Items table columns. |
|
| 37 | + add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
| 38 | + add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
| 39 | + add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
| 40 | + add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
| 41 | + add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
| 42 | + add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
| 43 | + |
|
| 44 | + // Payment forms columns. |
|
| 45 | + add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
| 46 | + add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
| 47 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
| 48 | + |
|
| 49 | + // Discount table columns. |
|
| 50 | + add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
| 51 | + add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
| 52 | + |
|
| 53 | + // Deleting posts. |
|
| 54 | + add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
| 55 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
| 56 | + |
|
| 57 | + add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Post updated messages. |
|
| 62 | + */ |
|
| 63 | + public static function post_updated_messages( $messages ) { |
|
| 64 | + global $post; |
|
| 65 | + |
|
| 66 | + $messages['wpi_discount'] = array( |
|
| 67 | + 0 => '', |
|
| 68 | + 1 => __( 'Discount updated.', 'invoicing' ), |
|
| 69 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 70 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 71 | + 4 => __( 'Discount updated.', 'invoicing' ), |
|
| 72 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 73 | + 6 => __( 'Discount updated.', 'invoicing' ), |
|
| 74 | + 7 => __( 'Discount saved.', 'invoicing' ), |
|
| 75 | + 8 => __( 'Discount submitted.', 'invoicing' ), |
|
| 76 | + 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 77 | + 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + $messages['wpi_payment_form'] = array( |
|
| 81 | + 0 => '', |
|
| 82 | + 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 83 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 84 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 85 | + 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 86 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 87 | + 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 88 | + 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
| 89 | + 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
| 90 | + 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 91 | + 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
| 92 | + ); |
|
| 93 | + |
|
| 94 | + return $messages; |
|
| 95 | + |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Post row actions. |
|
| 100 | + */ |
|
| 101 | + public static function post_row_actions( $actions, $post ) { |
|
| 102 | + |
|
| 103 | + $post = get_post( $post ); |
|
| 104 | + |
|
| 105 | + // We do not want to edit the default payment form. |
|
| 106 | + if ( 'wpi_payment_form' == $post->post_type ) { |
|
| 107 | + |
|
| 108 | + if ( wpinv_get_default_payment_form() === $post->ID ) { |
|
| 109 | + unset( $actions['trash'] ); |
|
| 110 | + unset( $actions['inline hide-if-no-js'] ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $actions['duplicate'] = sprintf( |
|
| 114 | + '<a href="%1$s">%2$s</a>', |
|
| 115 | + esc_url( |
|
| 116 | + wp_nonce_url( |
|
| 117 | + add_query_arg( |
|
| 118 | + array( |
|
| 119 | + 'getpaid-admin-action' => 'duplicate_form', |
|
| 120 | + 'form_id' => $post->ID, |
|
| 121 | + ) |
|
| 122 | + ), |
|
| 123 | + 'getpaid-nonce', |
|
| 124 | + 'getpaid-nonce' |
|
| 125 | + ) |
|
| 126 | + ), |
|
| 127 | + esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
| 128 | + ); |
|
| 129 | + |
|
| 130 | + $actions['reset'] = sprintf( |
|
| 131 | + '<a href="%1$s" style="color: #800">%2$s</a>', |
|
| 132 | + esc_url( |
|
| 133 | + wp_nonce_url( |
|
| 134 | + add_query_arg( |
|
| 135 | + array( |
|
| 136 | + 'getpaid-admin-action' => 'reset_form_stats', |
|
| 137 | + 'form_id' => $post->ID, |
|
| 138 | + ) |
|
| 139 | + ), |
|
| 140 | + 'getpaid-nonce', |
|
| 141 | + 'getpaid-nonce' |
|
| 142 | + ) |
|
| 143 | + ), |
|
| 144 | + esc_html( __( 'Reset Stats', 'invoicing' ) ) |
|
| 145 | + ); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + // Link to item payment form. |
|
| 149 | + if ( 'wpi_item' == $post->post_type ) { |
|
| 150 | + if ( getpaid_item_type_supports( get_post_meta( $post->ID, '_wpinv_type', true ), 'buy_now' ) ) { |
|
| 151 | + $actions['buy'] = sprintf( |
|
| 152 | + '<a href="%1$s">%2$s</a>', |
|
| 153 | + esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ), |
|
| 154 | + esc_html( __( 'Buy', 'invoicing' ) ) |
|
| 155 | + ); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + return $actions; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | 163 | * Remove bulk edit option from admin side quote listing |
| 164 | 164 | * |
| 165 | 165 | * @since 1.0.0 |
| 166 | 166 | * @param array $actions post actions |
| 167 | - * @param WP_Post $post |
|
| 167 | + * @param WP_Post $post |
|
| 168 | 168 | * @return array $actions actions without edit option |
| 169 | 169 | */ |
| 170 | 170 | public static function filter_invoice_row_actions( $actions, $post ) { |
| 171 | 171 | |
| 172 | 172 | if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
| 173 | 173 | |
| 174 | - $actions = array(); |
|
| 175 | - $invoice = new WPInv_Invoice( $post ); |
|
| 176 | - |
|
| 177 | - $actions['edit'] = sprintf( |
|
| 178 | - '<a href="%1$s">%2$s</a>', |
|
| 179 | - esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
| 180 | - esc_html( __( 'Edit', 'invoicing' ) ) |
|
| 181 | - ); |
|
| 182 | - |
|
| 183 | - if ( ! $invoice->is_draft() ) { |
|
| 184 | - |
|
| 185 | - $actions['view'] = sprintf( |
|
| 186 | - '<a href="%1$s">%2$s</a>', |
|
| 187 | - esc_url( $invoice->get_view_url() ), |
|
| 188 | - sprintf( |
|
| 189 | - // translators: %s is the invoice type |
|
| 190 | - esc_html__( 'View %s', 'invoicing' ), |
|
| 191 | - getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
| 192 | - ) |
|
| 193 | - ); |
|
| 194 | - |
|
| 195 | - $actions['send'] = sprintf( |
|
| 196 | - '<a href="%1$s">%2$s</a>', |
|
| 197 | - esc_url( |
|
| 198 | - wp_nonce_url( |
|
| 199 | - add_query_arg( |
|
| 200 | - array( |
|
| 201 | - 'getpaid-admin-action' => 'send_invoice', |
|
| 202 | - 'invoice_id' => $invoice->get_id(), |
|
| 203 | - ) |
|
| 204 | - ), |
|
| 205 | - 'getpaid-nonce', |
|
| 206 | - 'getpaid-nonce' |
|
| 207 | - ) |
|
| 208 | - ), |
|
| 209 | - esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
| 210 | - ); |
|
| 211 | - |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $actions['duplicate'] = sprintf( |
|
| 215 | - '<a href="%1$s">%2$s</a>', |
|
| 216 | - esc_url( |
|
| 217 | - wp_nonce_url( |
|
| 218 | - add_query_arg( |
|
| 219 | - array( |
|
| 220 | - 'getpaid-admin-action' => 'duplicate_invoice', |
|
| 221 | - 'invoice_id' => $post->ID, |
|
| 222 | - ) |
|
| 223 | - ), |
|
| 224 | - 'getpaid-nonce', |
|
| 225 | - 'getpaid-nonce' |
|
| 226 | - ) |
|
| 227 | - ), |
|
| 228 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
| 229 | - ); |
|
| 174 | + $actions = array(); |
|
| 175 | + $invoice = new WPInv_Invoice( $post ); |
|
| 176 | + |
|
| 177 | + $actions['edit'] = sprintf( |
|
| 178 | + '<a href="%1$s">%2$s</a>', |
|
| 179 | + esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
| 180 | + esc_html( __( 'Edit', 'invoicing' ) ) |
|
| 181 | + ); |
|
| 182 | + |
|
| 183 | + if ( ! $invoice->is_draft() ) { |
|
| 184 | + |
|
| 185 | + $actions['view'] = sprintf( |
|
| 186 | + '<a href="%1$s">%2$s</a>', |
|
| 187 | + esc_url( $invoice->get_view_url() ), |
|
| 188 | + sprintf( |
|
| 189 | + // translators: %s is the invoice type |
|
| 190 | + esc_html__( 'View %s', 'invoicing' ), |
|
| 191 | + getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
| 192 | + ) |
|
| 193 | + ); |
|
| 194 | + |
|
| 195 | + $actions['send'] = sprintf( |
|
| 196 | + '<a href="%1$s">%2$s</a>', |
|
| 197 | + esc_url( |
|
| 198 | + wp_nonce_url( |
|
| 199 | + add_query_arg( |
|
| 200 | + array( |
|
| 201 | + 'getpaid-admin-action' => 'send_invoice', |
|
| 202 | + 'invoice_id' => $invoice->get_id(), |
|
| 203 | + ) |
|
| 204 | + ), |
|
| 205 | + 'getpaid-nonce', |
|
| 206 | + 'getpaid-nonce' |
|
| 207 | + ) |
|
| 208 | + ), |
|
| 209 | + esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
| 210 | + ); |
|
| 211 | + |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $actions['duplicate'] = sprintf( |
|
| 215 | + '<a href="%1$s">%2$s</a>', |
|
| 216 | + esc_url( |
|
| 217 | + wp_nonce_url( |
|
| 218 | + add_query_arg( |
|
| 219 | + array( |
|
| 220 | + 'getpaid-admin-action' => 'duplicate_invoice', |
|
| 221 | + 'invoice_id' => $post->ID, |
|
| 222 | + ) |
|
| 223 | + ), |
|
| 224 | + 'getpaid-nonce', |
|
| 225 | + 'getpaid-nonce' |
|
| 226 | + ) |
|
| 227 | + ), |
|
| 228 | + esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
| 229 | + ); |
|
| 230 | 230 | |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | return $actions; |
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * Returns an array of invoice table columns. |
|
| 238 | - */ |
|
| 239 | - public static function invoice_columns( $columns ) { |
|
| 240 | - |
|
| 241 | - $columns = array( |
|
| 242 | - 'cb' => $columns['cb'], |
|
| 243 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
| 244 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 245 | - 'invoice_date' => __( 'Created', 'invoicing' ), |
|
| 246 | - 'payment_date' => __( 'Completed', 'invoicing' ), |
|
| 247 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 248 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
| 249 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 250 | - ); |
|
| 251 | - |
|
| 252 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Displays invoice table columns. |
|
| 257 | - */ |
|
| 258 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
| 259 | - |
|
| 260 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 261 | - |
|
| 262 | - switch ( $column_name ) { |
|
| 263 | - |
|
| 264 | - case 'invoice_date': |
|
| 265 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
| 266 | - $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
| 267 | - echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
| 268 | - break; |
|
| 269 | - |
|
| 270 | - case 'payment_date': |
|
| 271 | - if ( $invoice->is_paid() ) { |
|
| 272 | - $date_time = esc_attr( $invoice->get_completed_date() ); |
|
| 273 | - $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
| 274 | - echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
| 275 | - } else { |
|
| 276 | - echo '—'; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - break; |
|
| 280 | - |
|
| 281 | - case 'amount': |
|
| 282 | - $amount = $invoice->get_total(); |
|
| 283 | - $formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) ); |
|
| 284 | - |
|
| 285 | - if ( $invoice->is_refunded() ) { |
|
| 286 | - $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
| 287 | - echo wp_kses_post( "<del>$formated_amount</del> <ins>$refunded_amount</ins>" ); |
|
| 288 | - } else { |
|
| 289 | - |
|
| 290 | - $discount = $invoice->get_total_discount(); |
|
| 291 | - |
|
| 292 | - if ( ! empty( $discount ) ) { |
|
| 293 | - $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
| 294 | - echo wp_kses_post( "<del>$new_amount</del> <ins>$formated_amount</ins>" ); |
|
| 295 | - } else { |
|
| 296 | - echo wp_kses_post( $formated_amount ); |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - break; |
|
| 301 | - |
|
| 302 | - case 'status': |
|
| 303 | - $status = esc_html( $invoice->get_status() ); |
|
| 304 | - $status_label = esc_html( $invoice->get_status_nicename() ); |
|
| 305 | - |
|
| 306 | - // If it is paid, show the gateway title. |
|
| 307 | - if ( $invoice->is_paid() ) { |
|
| 308 | - $gateway = esc_html( $invoice->get_gateway_title() ); |
|
| 309 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) ); |
|
| 310 | - |
|
| 311 | - echo wp_kses_post( "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>" ); |
|
| 312 | - } else { |
|
| 313 | - echo wp_kses_post( "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>" ); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - // If it is not paid, display the overdue and view status. |
|
| 317 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 318 | - |
|
| 319 | - // Invoice view status. |
|
| 320 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
| 321 | - echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
| 322 | - } else { |
|
| 323 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - // Display the overview status. |
|
| 327 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
| 328 | - $due_date = $invoice->get_due_date(); |
|
| 329 | - $fomatted = getpaid_format_date( $due_date ); |
|
| 330 | - |
|
| 331 | - if ( ! empty( $fomatted ) ) { |
|
| 332 | - $date = wp_sprintf( |
|
| 333 | - // translators: %s is the due date. |
|
| 334 | - __( 'Due %s', 'invoicing' ), |
|
| 335 | - $fomatted |
|
| 336 | - ); |
|
| 337 | - echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" ); |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - break; |
|
| 343 | - |
|
| 344 | - case 'recurring': |
|
| 345 | - if ( $invoice->is_recurring() ) { |
|
| 346 | - echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
| 347 | - } else { |
|
| 348 | - echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
| 349 | - } |
|
| 350 | - break; |
|
| 351 | - |
|
| 352 | - case 'number': |
|
| 353 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
| 354 | - $invoice_number = esc_html( $invoice->get_number() ); |
|
| 355 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
| 356 | - |
|
| 357 | - echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" ); |
|
| 358 | - |
|
| 359 | - do_action( 'getpaid_admin_table_invoice_number_column', $invoice ); |
|
| 360 | - break; |
|
| 361 | - |
|
| 362 | - case 'customer': |
|
| 363 | - $customer_name = $invoice->get_user_full_name(); |
|
| 364 | - |
|
| 365 | - if ( empty( $customer_name ) ) { |
|
| 366 | - $customer_name = $invoice->get_email(); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - if ( ! empty( $customer_name ) ) { |
|
| 370 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
| 371 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
| 372 | - echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" ); |
|
| 373 | - } else { |
|
| 374 | - echo '<div>—</div>'; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - break; |
|
| 378 | - |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Displays invoice bulk actions. |
|
| 385 | - */ |
|
| 386 | - public static function invoice_bulk_actions( $actions ) { |
|
| 387 | - $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
| 388 | - return $actions; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * Processes invoice bulk actions. |
|
| 393 | - */ |
|
| 394 | - public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
| 395 | - |
|
| 396 | - if ( 'resend-invoice' === $action ) { |
|
| 397 | - foreach ( $post_ids as $post_id ) { |
|
| 398 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
| 399 | - } |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - return $redirect_url; |
|
| 403 | - |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Returns an array of payment forms table columns. |
|
| 408 | - */ |
|
| 409 | - public static function payment_form_columns( $columns ) { |
|
| 410 | - |
|
| 411 | - $columns = array( |
|
| 412 | - 'cb' => $columns['cb'], |
|
| 413 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 414 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 415 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
| 416 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
| 417 | - 'items' => __( 'Items', 'invoicing' ), |
|
| 418 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 419 | - ); |
|
| 420 | - |
|
| 421 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
| 422 | - |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * Displays payment form table columns. |
|
| 427 | - */ |
|
| 428 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
| 429 | - |
|
| 430 | - // Retrieve the payment form. |
|
| 431 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
| 432 | - |
|
| 433 | - switch ( $column_name ) { |
|
| 434 | - |
|
| 435 | - case 'earnings': |
|
| 436 | - echo wp_kses_post( wpinv_price( $form->get_earned() ) ); |
|
| 437 | - break; |
|
| 438 | - |
|
| 439 | - case 'refunds': |
|
| 440 | - echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
| 441 | - break; |
|
| 442 | - |
|
| 443 | - case 'refunds': |
|
| 444 | - echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
| 445 | - break; |
|
| 446 | - |
|
| 447 | - case 'shortcode': |
|
| 448 | - if ( $form->is_default() ) { |
|
| 449 | - echo '—'; |
|
| 450 | - } else { |
|
| 451 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - break; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * Returns an array of invoice table columns. |
|
| 238 | + */ |
|
| 239 | + public static function invoice_columns( $columns ) { |
|
| 240 | + |
|
| 241 | + $columns = array( |
|
| 242 | + 'cb' => $columns['cb'], |
|
| 243 | + 'number' => __( 'Invoice', 'invoicing' ), |
|
| 244 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
| 245 | + 'invoice_date' => __( 'Created', 'invoicing' ), |
|
| 246 | + 'payment_date' => __( 'Completed', 'invoicing' ), |
|
| 247 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 248 | + 'recurring' => __( 'Recurring', 'invoicing' ), |
|
| 249 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 250 | + ); |
|
| 251 | + |
|
| 252 | + return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * Displays invoice table columns. |
|
| 257 | + */ |
|
| 258 | + public static function display_invoice_columns( $column_name, $post_id ) { |
|
| 259 | + |
|
| 260 | + $invoice = new WPInv_Invoice( $post_id ); |
|
| 261 | + |
|
| 262 | + switch ( $column_name ) { |
|
| 263 | + |
|
| 264 | + case 'invoice_date': |
|
| 265 | + $date_time = esc_attr( $invoice->get_created_date() ); |
|
| 266 | + $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
| 267 | + echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
| 268 | + break; |
|
| 269 | + |
|
| 270 | + case 'payment_date': |
|
| 271 | + if ( $invoice->is_paid() ) { |
|
| 272 | + $date_time = esc_attr( $invoice->get_completed_date() ); |
|
| 273 | + $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
| 274 | + echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
| 275 | + } else { |
|
| 276 | + echo '—'; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + break; |
|
| 280 | + |
|
| 281 | + case 'amount': |
|
| 282 | + $amount = $invoice->get_total(); |
|
| 283 | + $formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) ); |
|
| 284 | + |
|
| 285 | + if ( $invoice->is_refunded() ) { |
|
| 286 | + $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
| 287 | + echo wp_kses_post( "<del>$formated_amount</del> <ins>$refunded_amount</ins>" ); |
|
| 288 | + } else { |
|
| 289 | + |
|
| 290 | + $discount = $invoice->get_total_discount(); |
|
| 291 | + |
|
| 292 | + if ( ! empty( $discount ) ) { |
|
| 293 | + $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
| 294 | + echo wp_kses_post( "<del>$new_amount</del> <ins>$formated_amount</ins>" ); |
|
| 295 | + } else { |
|
| 296 | + echo wp_kses_post( $formated_amount ); |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + break; |
|
| 301 | + |
|
| 302 | + case 'status': |
|
| 303 | + $status = esc_html( $invoice->get_status() ); |
|
| 304 | + $status_label = esc_html( $invoice->get_status_nicename() ); |
|
| 305 | + |
|
| 306 | + // If it is paid, show the gateway title. |
|
| 307 | + if ( $invoice->is_paid() ) { |
|
| 308 | + $gateway = esc_html( $invoice->get_gateway_title() ); |
|
| 309 | + $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) ); |
|
| 310 | + |
|
| 311 | + echo wp_kses_post( "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>" ); |
|
| 312 | + } else { |
|
| 313 | + echo wp_kses_post( "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>" ); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + // If it is not paid, display the overdue and view status. |
|
| 317 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 318 | + |
|
| 319 | + // Invoice view status. |
|
| 320 | + if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
| 321 | + echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
| 322 | + } else { |
|
| 323 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + // Display the overview status. |
|
| 327 | + if ( wpinv_get_option( 'overdue_active' ) ) { |
|
| 328 | + $due_date = $invoice->get_due_date(); |
|
| 329 | + $fomatted = getpaid_format_date( $due_date ); |
|
| 330 | + |
|
| 331 | + if ( ! empty( $fomatted ) ) { |
|
| 332 | + $date = wp_sprintf( |
|
| 333 | + // translators: %s is the due date. |
|
| 334 | + __( 'Due %s', 'invoicing' ), |
|
| 335 | + $fomatted |
|
| 336 | + ); |
|
| 337 | + echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" ); |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + break; |
|
| 343 | + |
|
| 344 | + case 'recurring': |
|
| 345 | + if ( $invoice->is_recurring() ) { |
|
| 346 | + echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
| 347 | + } else { |
|
| 348 | + echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
| 349 | + } |
|
| 350 | + break; |
|
| 351 | + |
|
| 352 | + case 'number': |
|
| 353 | + $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
| 354 | + $invoice_number = esc_html( $invoice->get_number() ); |
|
| 355 | + $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
| 356 | + |
|
| 357 | + echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" ); |
|
| 358 | + |
|
| 359 | + do_action( 'getpaid_admin_table_invoice_number_column', $invoice ); |
|
| 360 | + break; |
|
| 361 | + |
|
| 362 | + case 'customer': |
|
| 363 | + $customer_name = $invoice->get_user_full_name(); |
|
| 364 | + |
|
| 365 | + if ( empty( $customer_name ) ) { |
|
| 366 | + $customer_name = $invoice->get_email(); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + if ( ! empty( $customer_name ) ) { |
|
| 370 | + $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
| 371 | + $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
| 372 | + echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" ); |
|
| 373 | + } else { |
|
| 374 | + echo '<div>—</div>'; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + break; |
|
| 455 | 378 | |
| 456 | - case 'items': |
|
| 457 | - $items = $form->get_items(); |
|
| 458 | - |
|
| 459 | - if ( $form->is_default() || empty( $items ) ) { |
|
| 460 | - echo '—'; |
|
| 461 | - return; |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - $_items = array(); |
|
| 465 | - |
|
| 466 | - foreach ( $items as $item ) { |
|
| 467 | - $url = $item->get_edit_url(); |
|
| 468 | - |
|
| 469 | - if ( empty( $url ) ) { |
|
| 470 | - $_items[] = esc_html( $item->get_name() ); |
|
| 471 | - } else { |
|
| 472 | - $_items[] = sprintf( |
|
| 473 | - '<a href="%s">%s</a>', |
|
| 474 | - esc_url( $url ), |
|
| 475 | - esc_html( $item->get_name() ) |
|
| 476 | - ); |
|
| 477 | - } |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Displays invoice bulk actions. |
|
| 385 | + */ |
|
| 386 | + public static function invoice_bulk_actions( $actions ) { |
|
| 387 | + $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
| 388 | + return $actions; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * Processes invoice bulk actions. |
|
| 393 | + */ |
|
| 394 | + public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
| 395 | + |
|
| 396 | + if ( 'resend-invoice' === $action ) { |
|
| 397 | + foreach ( $post_ids as $post_id ) { |
|
| 398 | + getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
| 399 | + } |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + return $redirect_url; |
|
| 403 | + |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * Returns an array of payment forms table columns. |
|
| 408 | + */ |
|
| 409 | + public static function payment_form_columns( $columns ) { |
|
| 410 | + |
|
| 411 | + $columns = array( |
|
| 412 | + 'cb' => $columns['cb'], |
|
| 413 | + 'title' => __( 'Name', 'invoicing' ), |
|
| 414 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 415 | + 'earnings' => __( 'Revenue', 'invoicing' ), |
|
| 416 | + 'refunds' => __( 'Refunded', 'invoicing' ), |
|
| 417 | + 'items' => __( 'Items', 'invoicing' ), |
|
| 418 | + 'date' => __( 'Date', 'invoicing' ), |
|
| 419 | + ); |
|
| 420 | + |
|
| 421 | + return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
| 422 | + |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * Displays payment form table columns. |
|
| 427 | + */ |
|
| 428 | + public static function display_payment_form_columns( $column_name, $post_id ) { |
|
| 429 | + |
|
| 430 | + // Retrieve the payment form. |
|
| 431 | + $form = new GetPaid_Payment_Form( $post_id ); |
|
| 432 | + |
|
| 433 | + switch ( $column_name ) { |
|
| 434 | + |
|
| 435 | + case 'earnings': |
|
| 436 | + echo wp_kses_post( wpinv_price( $form->get_earned() ) ); |
|
| 437 | + break; |
|
| 438 | + |
|
| 439 | + case 'refunds': |
|
| 440 | + echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
| 441 | + break; |
|
| 442 | + |
|
| 443 | + case 'refunds': |
|
| 444 | + echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
| 445 | + break; |
|
| 446 | + |
|
| 447 | + case 'shortcode': |
|
| 448 | + if ( $form->is_default() ) { |
|
| 449 | + echo '—'; |
|
| 450 | + } else { |
|
| 451 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + break; |
|
| 455 | + |
|
| 456 | + case 'items': |
|
| 457 | + $items = $form->get_items(); |
|
| 458 | + |
|
| 459 | + if ( $form->is_default() || empty( $items ) ) { |
|
| 460 | + echo '—'; |
|
| 461 | + return; |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + $_items = array(); |
|
| 465 | + |
|
| 466 | + foreach ( $items as $item ) { |
|
| 467 | + $url = $item->get_edit_url(); |
|
| 468 | + |
|
| 469 | + if ( empty( $url ) ) { |
|
| 470 | + $_items[] = esc_html( $item->get_name() ); |
|
| 471 | + } else { |
|
| 472 | + $_items[] = sprintf( |
|
| 473 | + '<a href="%s">%s</a>', |
|
| 474 | + esc_url( $url ), |
|
| 475 | + esc_html( $item->get_name() ) |
|
| 476 | + ); |
|
| 477 | + } |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | - echo wp_kses_post( implode( '<br>', $_items ) ); |
|
| 480 | + echo wp_kses_post( implode( '<br>', $_items ) ); |
|
| 481 | + |
|
| 482 | + break; |
|
| 483 | + |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + /** |
|
| 489 | + * Filters post states. |
|
| 490 | + */ |
|
| 491 | + public static function filter_payment_form_state( $post_states, $post ) { |
|
| 492 | + |
|
| 493 | + if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) { |
|
| 494 | + $post_states['default_form'] = __( 'Default Payment Form', 'invoicing' ); |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + return $post_states; |
|
| 498 | + |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * Returns an array of coupon table columns. |
|
| 503 | + */ |
|
| 504 | + public static function discount_columns( $columns ) { |
|
| 505 | + |
|
| 506 | + $columns = array( |
|
| 507 | + 'cb' => $columns['cb'], |
|
| 508 | + 'title' => __( 'Name', 'invoicing' ), |
|
| 509 | + 'code' => __( 'Code', 'invoicing' ), |
|
| 510 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 511 | + 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
| 512 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 513 | + 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
| 514 | + ); |
|
| 515 | + |
|
| 516 | + return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
| 517 | + } |
|
| 481 | 518 | |
| 482 | - break; |
|
| 519 | + /** |
|
| 520 | + * Filters post states. |
|
| 521 | + */ |
|
| 522 | + public static function filter_discount_state( $post_states, $post ) { |
|
| 483 | 523 | |
| 484 | - } |
|
| 524 | + if ( 'wpi_discount' === $post->post_type ) { |
|
| 485 | 525 | |
| 486 | - } |
|
| 526 | + $discount = new WPInv_Discount( $post ); |
|
| 487 | 527 | |
| 488 | - /** |
|
| 489 | - * Filters post states. |
|
| 490 | - */ |
|
| 491 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
| 528 | + $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
| 492 | 529 | |
| 493 | - if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) { |
|
| 494 | - $post_states['default_form'] = __( 'Default Payment Form', 'invoicing' ); |
|
| 495 | - } |
|
| 530 | + if ( 'publish' !== $status ) { |
|
| 531 | + return array( |
|
| 532 | + 'discount_status' => wpinv_discount_status( $status ), |
|
| 533 | + ); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + return array(); |
|
| 537 | + |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + return $post_states; |
|
| 496 | 541 | |
| 497 | - return $post_states; |
|
| 542 | + } |
|
| 498 | 543 | |
| 499 | - } |
|
| 544 | + /** |
|
| 545 | + * Returns an array of items table columns. |
|
| 546 | + */ |
|
| 547 | + public static function item_columns( $columns ) { |
|
| 548 | + |
|
| 549 | + $columns = array( |
|
| 550 | + 'cb' => $columns['cb'], |
|
| 551 | + 'title' => __( 'Name', 'invoicing' ), |
|
| 552 | + 'price' => __( 'Price', 'invoicing' ), |
|
| 553 | + 'vat_rule' => __( 'Tax Rule', 'invoicing' ), |
|
| 554 | + 'vat_class' => __( 'Tax Class', 'invoicing' ), |
|
| 555 | + 'type' => __( 'Type', 'invoicing' ), |
|
| 556 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 557 | + ); |
|
| 558 | + |
|
| 559 | + if ( ! wpinv_use_taxes() ) { |
|
| 560 | + unset( $columns['vat_rule'] ); |
|
| 561 | + unset( $columns['vat_class'] ); |
|
| 562 | + } |
|
| 500 | 563 | |
| 501 | - /** |
|
| 502 | - * Returns an array of coupon table columns. |
|
| 503 | - */ |
|
| 504 | - public static function discount_columns( $columns ) { |
|
| 564 | + return apply_filters( 'wpi_item_table_columns', $columns ); |
|
| 565 | + } |
|
| 505 | 566 | |
| 506 | - $columns = array( |
|
| 507 | - 'cb' => $columns['cb'], |
|
| 508 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 509 | - 'code' => __( 'Code', 'invoicing' ), |
|
| 510 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 511 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
| 512 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 513 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
| 514 | - ); |
|
| 567 | + /** |
|
| 568 | + * Returns an array of sortable items table columns. |
|
| 569 | + */ |
|
| 570 | + public static function sortable_item_columns( $columns ) { |
|
| 571 | + |
|
| 572 | + return array_merge( |
|
| 573 | + $columns, |
|
| 574 | + array( |
|
| 575 | + 'price' => 'price', |
|
| 576 | + 'vat_rule' => 'vat_rule', |
|
| 577 | + 'vat_class' => 'vat_class', |
|
| 578 | + 'type' => 'type', |
|
| 579 | + ) |
|
| 580 | + ); |
|
| 515 | 581 | |
| 516 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
| 517 | - } |
|
| 582 | + } |
|
| 518 | 583 | |
| 519 | - /** |
|
| 520 | - * Filters post states. |
|
| 521 | - */ |
|
| 522 | - public static function filter_discount_state( $post_states, $post ) { |
|
| 584 | + /** |
|
| 585 | + * Displays items table columns. |
|
| 586 | + */ |
|
| 587 | + public static function display_item_columns( $column_name, $post_id ) { |
|
| 523 | 588 | |
| 524 | - if ( 'wpi_discount' === $post->post_type ) { |
|
| 589 | + $item = new WPInv_Item( $post_id ); |
|
| 525 | 590 | |
| 526 | - $discount = new WPInv_Discount( $post ); |
|
| 591 | + switch ( $column_name ) { |
|
| 527 | 592 | |
| 528 | - $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
| 593 | + case 'price': |
|
| 594 | + if ( ! $item->is_recurring() ) { |
|
| 595 | + echo wp_kses_post( $item->get_the_price() ); |
|
| 596 | + break; |
|
| 597 | + } |
|
| 529 | 598 | |
| 530 | - if ( 'publish' !== $status ) { |
|
| 531 | - return array( |
|
| 532 | - 'discount_status' => wpinv_discount_status( $status ), |
|
| 533 | - ); |
|
| 534 | - } |
|
| 599 | + $price = wp_sprintf( |
|
| 600 | + __( '%1$s / %2$s', 'invoicing' ), |
|
| 601 | + $item->get_the_price(), |
|
| 602 | + getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
| 603 | + ); |
|
| 535 | 604 | |
| 536 | - return array(); |
|
| 605 | + if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
| 606 | + echo wp_kses_post( $price ); |
|
| 607 | + break; |
|
| 608 | + } |
|
| 537 | 609 | |
| 538 | - } |
|
| 610 | + echo wp_kses_post( $item->get_the_initial_price() ); |
|
| 539 | 611 | |
| 540 | - return $post_states; |
|
| 612 | + echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>'; |
|
| 613 | + break; |
|
| 541 | 614 | |
| 542 | - } |
|
| 615 | + case 'vat_rule': |
|
| 616 | + echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) ); |
|
| 617 | + break; |
|
| 543 | 618 | |
| 544 | - /** |
|
| 545 | - * Returns an array of items table columns. |
|
| 546 | - */ |
|
| 547 | - public static function item_columns( $columns ) { |
|
| 619 | + case 'vat_class': |
|
| 620 | + echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) ); |
|
| 621 | + break; |
|
| 548 | 622 | |
| 549 | - $columns = array( |
|
| 550 | - 'cb' => $columns['cb'], |
|
| 551 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 552 | - 'price' => __( 'Price', 'invoicing' ), |
|
| 553 | - 'vat_rule' => __( 'Tax Rule', 'invoicing' ), |
|
| 554 | - 'vat_class' => __( 'Tax Class', 'invoicing' ), |
|
| 555 | - 'type' => __( 'Type', 'invoicing' ), |
|
| 556 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 557 | - ); |
|
| 623 | + case 'shortcode': |
|
| 624 | + if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) { |
|
| 625 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
| 626 | + } else { |
|
| 627 | + echo '—'; |
|
| 628 | + } |
|
| 558 | 629 | |
| 559 | - if ( ! wpinv_use_taxes() ) { |
|
| 560 | - unset( $columns['vat_rule'] ); |
|
| 561 | - unset( $columns['vat_class'] ); |
|
| 562 | - } |
|
| 630 | + break; |
|
| 563 | 631 | |
| 564 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
| 565 | - } |
|
| 632 | + case 'type': |
|
| 633 | + echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' ); |
|
| 634 | + break; |
|
| 566 | 635 | |
| 567 | - /** |
|
| 568 | - * Returns an array of sortable items table columns. |
|
| 569 | - */ |
|
| 570 | - public static function sortable_item_columns( $columns ) { |
|
| 571 | - |
|
| 572 | - return array_merge( |
|
| 573 | - $columns, |
|
| 574 | - array( |
|
| 575 | - 'price' => 'price', |
|
| 576 | - 'vat_rule' => 'vat_rule', |
|
| 577 | - 'vat_class' => 'vat_class', |
|
| 578 | - 'type' => 'type', |
|
| 579 | - ) |
|
| 580 | - ); |
|
| 581 | - |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * Displays items table columns. |
|
| 586 | - */ |
|
| 587 | - public static function display_item_columns( $column_name, $post_id ) { |
|
| 588 | - |
|
| 589 | - $item = new WPInv_Item( $post_id ); |
|
| 590 | - |
|
| 591 | - switch ( $column_name ) { |
|
| 592 | - |
|
| 593 | - case 'price': |
|
| 594 | - if ( ! $item->is_recurring() ) { |
|
| 595 | - echo wp_kses_post( $item->get_the_price() ); |
|
| 596 | - break; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - $price = wp_sprintf( |
|
| 600 | - __( '%1$s / %2$s', 'invoicing' ), |
|
| 601 | - $item->get_the_price(), |
|
| 602 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
| 603 | - ); |
|
| 604 | - |
|
| 605 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
| 606 | - echo wp_kses_post( $price ); |
|
| 607 | - break; |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - echo wp_kses_post( $item->get_the_initial_price() ); |
|
| 611 | - |
|
| 612 | - echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>'; |
|
| 613 | - break; |
|
| 614 | - |
|
| 615 | - case 'vat_rule': |
|
| 616 | - echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) ); |
|
| 617 | - break; |
|
| 618 | - |
|
| 619 | - case 'vat_class': |
|
| 620 | - echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) ); |
|
| 621 | - break; |
|
| 622 | - |
|
| 623 | - case 'shortcode': |
|
| 624 | - if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) { |
|
| 625 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
| 626 | - } else { |
|
| 627 | - echo '—'; |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - break; |
|
| 631 | - |
|
| 632 | - case 'type': |
|
| 633 | - echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' ); |
|
| 634 | - break; |
|
| 635 | - |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - /** |
|
| 641 | - * Lets users filter items using taxes. |
|
| 642 | - */ |
|
| 643 | - public static function add_item_filters( $post_type ) { |
|
| 644 | - |
|
| 645 | - // Abort if we're not dealing with items. |
|
| 646 | - if ( 'wpi_item' !== $post_type ) { |
|
| 647 | - return; |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - // Filter by vat rules. |
|
| 651 | - if ( wpinv_use_taxes() ) { |
|
| 652 | - |
|
| 653 | - // Sanitize selected vat rule. |
|
| 654 | - $vat_rule = ''; |
|
| 655 | - $vat_rules = getpaid_get_tax_rules(); |
|
| 656 | - if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 657 | - $vat_rule = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - // Filter by VAT rule. |
|
| 661 | - wpinv_html_select( |
|
| 662 | - array( |
|
| 663 | - 'options' => array_merge( |
|
| 664 | - array( |
|
| 665 | - '' => __( 'All Tax Rules', 'invoicing' ), |
|
| 666 | - ), |
|
| 667 | - $vat_rules |
|
| 668 | - ), |
|
| 669 | - 'name' => 'vat_rule', |
|
| 670 | - 'id' => 'vat_rule', |
|
| 671 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '', |
|
| 672 | - 'show_option_all' => false, |
|
| 673 | - 'show_option_none' => false, |
|
| 674 | - ) |
|
| 675 | - ); |
|
| 676 | - |
|
| 677 | - // Filter by VAT class. |
|
| 678 | - |
|
| 679 | - // Sanitize selected vat rule. |
|
| 680 | - $vat_class = ''; |
|
| 681 | - $vat_classes = getpaid_get_tax_classes(); |
|
| 682 | - if ( isset( $_GET['vat_class'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 683 | - $vat_class = sanitize_text_field( $_GET['vat_class'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - wpinv_html_select( |
|
| 687 | - array( |
|
| 688 | - 'options' => array_merge( |
|
| 689 | - array( |
|
| 690 | - '' => __( 'All Tax Classes', 'invoicing' ), |
|
| 691 | - ), |
|
| 692 | - $vat_classes |
|
| 693 | - ), |
|
| 694 | - 'name' => 'vat_class', |
|
| 695 | - 'id' => 'vat_class', |
|
| 696 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '', |
|
| 697 | - 'show_option_all' => false, |
|
| 698 | - 'show_option_none' => false, |
|
| 699 | - ) |
|
| 700 | - ); |
|
| 701 | - |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - // Filter by item type. |
|
| 705 | - $type = ''; |
|
| 706 | - if ( isset( $_GET['type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 707 | - $type = sanitize_text_field( $_GET['type'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - wpinv_html_select( |
|
| 711 | - array( |
|
| 712 | - 'options' => array_merge( |
|
| 713 | - array( |
|
| 714 | - '' => __( 'All item types', 'invoicing' ), |
|
| 715 | - ), |
|
| 716 | - wpinv_get_item_types() |
|
| 717 | - ), |
|
| 718 | - 'name' => 'type', |
|
| 719 | - 'id' => 'type', |
|
| 720 | - 'selected' => in_array( $type, wpinv_item_types(), true ) ? $type : '', |
|
| 721 | - 'show_option_all' => false, |
|
| 722 | - 'show_option_none' => false, |
|
| 723 | - ) |
|
| 724 | - ); |
|
| 725 | - |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - /** |
|
| 729 | - * Filters the item query. |
|
| 730 | - */ |
|
| 731 | - public static function filter_item_query( $query ) { |
|
| 732 | - |
|
| 733 | - // modify the query only if it admin and main query. |
|
| 734 | - if ( ! ( is_admin() && $query->is_main_query() ) ) { |
|
| 735 | - return $query; |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - // we want to modify the query for our items. |
|
| 739 | - if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) { |
|
| 740 | - return $query; |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
| 744 | - $query->query_vars['meta_query'] = array(); |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - // Filter vat rule type |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + /** |
|
| 641 | + * Lets users filter items using taxes. |
|
| 642 | + */ |
|
| 643 | + public static function add_item_filters( $post_type ) { |
|
| 644 | + |
|
| 645 | + // Abort if we're not dealing with items. |
|
| 646 | + if ( 'wpi_item' !== $post_type ) { |
|
| 647 | + return; |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + // Filter by vat rules. |
|
| 651 | + if ( wpinv_use_taxes() ) { |
|
| 652 | + |
|
| 653 | + // Sanitize selected vat rule. |
|
| 654 | + $vat_rule = ''; |
|
| 655 | + $vat_rules = getpaid_get_tax_rules(); |
|
| 656 | + if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 657 | + $vat_rule = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + // Filter by VAT rule. |
|
| 661 | + wpinv_html_select( |
|
| 662 | + array( |
|
| 663 | + 'options' => array_merge( |
|
| 664 | + array( |
|
| 665 | + '' => __( 'All Tax Rules', 'invoicing' ), |
|
| 666 | + ), |
|
| 667 | + $vat_rules |
|
| 668 | + ), |
|
| 669 | + 'name' => 'vat_rule', |
|
| 670 | + 'id' => 'vat_rule', |
|
| 671 | + 'selected' => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '', |
|
| 672 | + 'show_option_all' => false, |
|
| 673 | + 'show_option_none' => false, |
|
| 674 | + ) |
|
| 675 | + ); |
|
| 676 | + |
|
| 677 | + // Filter by VAT class. |
|
| 678 | + |
|
| 679 | + // Sanitize selected vat rule. |
|
| 680 | + $vat_class = ''; |
|
| 681 | + $vat_classes = getpaid_get_tax_classes(); |
|
| 682 | + if ( isset( $_GET['vat_class'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 683 | + $vat_class = sanitize_text_field( $_GET['vat_class'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + wpinv_html_select( |
|
| 687 | + array( |
|
| 688 | + 'options' => array_merge( |
|
| 689 | + array( |
|
| 690 | + '' => __( 'All Tax Classes', 'invoicing' ), |
|
| 691 | + ), |
|
| 692 | + $vat_classes |
|
| 693 | + ), |
|
| 694 | + 'name' => 'vat_class', |
|
| 695 | + 'id' => 'vat_class', |
|
| 696 | + 'selected' => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '', |
|
| 697 | + 'show_option_all' => false, |
|
| 698 | + 'show_option_none' => false, |
|
| 699 | + ) |
|
| 700 | + ); |
|
| 701 | + |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + // Filter by item type. |
|
| 705 | + $type = ''; |
|
| 706 | + if ( isset( $_GET['type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 707 | + $type = sanitize_text_field( $_GET['type'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + wpinv_html_select( |
|
| 711 | + array( |
|
| 712 | + 'options' => array_merge( |
|
| 713 | + array( |
|
| 714 | + '' => __( 'All item types', 'invoicing' ), |
|
| 715 | + ), |
|
| 716 | + wpinv_get_item_types() |
|
| 717 | + ), |
|
| 718 | + 'name' => 'type', |
|
| 719 | + 'id' => 'type', |
|
| 720 | + 'selected' => in_array( $type, wpinv_item_types(), true ) ? $type : '', |
|
| 721 | + 'show_option_all' => false, |
|
| 722 | + 'show_option_none' => false, |
|
| 723 | + ) |
|
| 724 | + ); |
|
| 725 | + |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + /** |
|
| 729 | + * Filters the item query. |
|
| 730 | + */ |
|
| 731 | + public static function filter_item_query( $query ) { |
|
| 732 | + |
|
| 733 | + // modify the query only if it admin and main query. |
|
| 734 | + if ( ! ( is_admin() && $query->is_main_query() ) ) { |
|
| 735 | + return $query; |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + // we want to modify the query for our items. |
|
| 739 | + if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) { |
|
| 740 | + return $query; |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + if ( empty( $query->query_vars['meta_query'] ) ) { |
|
| 744 | + $query->query_vars['meta_query'] = array(); |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + // Filter vat rule type |
|
| 748 | 748 | if ( ! empty( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 749 | 749 | $query->query_vars['meta_query'][] = array( |
| 750 | 750 | 'key' => '_wpinv_vat_rule', |
@@ -769,101 +769,101 @@ discard block |
||
| 769 | 769 | 'value' => sanitize_text_field( $_GET['type'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 770 | 770 | 'compare' => '=', |
| 771 | 771 | ); |
| 772 | - } |
|
| 773 | - |
|
| 774 | - $query->query_vars['meta_query'][] = array( |
|
| 775 | - 'key' => '_wpinv_one_time', |
|
| 776 | - 'compare' => 'NOT EXISTS', |
|
| 777 | - ); |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - /** |
|
| 781 | - * Reorders items. |
|
| 782 | - */ |
|
| 783 | - public static function reorder_items( $vars ) { |
|
| 784 | - global $typenow; |
|
| 785 | - |
|
| 786 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
| 787 | - return $vars; |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - // By item type. |
|
| 791 | - if ( 'type' === $vars['orderby'] ) { |
|
| 792 | - return array_merge( |
|
| 793 | - $vars, |
|
| 794 | - array( |
|
| 795 | - 'meta_key' => '_wpinv_type', |
|
| 796 | - 'orderby' => 'meta_value', |
|
| 797 | - ) |
|
| 798 | - ); |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - // By vat class. |
|
| 802 | - if ( 'vat_class' === $vars['orderby'] ) { |
|
| 803 | - return array_merge( |
|
| 804 | - $vars, |
|
| 805 | - array( |
|
| 806 | - 'meta_key' => '_wpinv_vat_class', |
|
| 807 | - 'orderby' => 'meta_value', |
|
| 808 | - ) |
|
| 809 | - ); |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - // By vat rule. |
|
| 813 | - if ( 'vat_rule' === $vars['orderby'] ) { |
|
| 814 | - return array_merge( |
|
| 815 | - $vars, |
|
| 816 | - array( |
|
| 817 | - 'meta_key' => '_wpinv_vat_rule', |
|
| 818 | - 'orderby' => 'meta_value', |
|
| 819 | - ) |
|
| 820 | - ); |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - // By price. |
|
| 824 | - if ( 'price' === $vars['orderby'] ) { |
|
| 825 | - return array_merge( |
|
| 826 | - $vars, |
|
| 827 | - array( |
|
| 828 | - 'meta_key' => '_wpinv_price', |
|
| 829 | - 'orderby' => 'meta_value_num', |
|
| 830 | - ) |
|
| 831 | - ); |
|
| 832 | - } |
|
| 833 | - |
|
| 834 | - return $vars; |
|
| 835 | - |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - /** |
|
| 839 | - * Fired when deleting a post. |
|
| 840 | - */ |
|
| 841 | - public static function delete_post( $post_id ) { |
|
| 842 | - |
|
| 843 | - switch ( get_post_type( $post_id ) ) { |
|
| 844 | - |
|
| 845 | - case 'wpi_item': |
|
| 846 | - do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) ); |
|
| 847 | - break; |
|
| 848 | - |
|
| 849 | - case 'wpi_payment_form': |
|
| 850 | - do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) ); |
|
| 851 | - break; |
|
| 852 | - |
|
| 853 | - case 'wpi_discount': |
|
| 854 | - do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) ); |
|
| 855 | - break; |
|
| 856 | - |
|
| 857 | - case 'wpi_invoice': |
|
| 858 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 859 | - do_action( 'getpaid_before_delete_invoice', $invoice ); |
|
| 860 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
| 861 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
| 862 | - break; |
|
| 863 | - } |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - /** |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + $query->query_vars['meta_query'][] = array( |
|
| 775 | + 'key' => '_wpinv_one_time', |
|
| 776 | + 'compare' => 'NOT EXISTS', |
|
| 777 | + ); |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + /** |
|
| 781 | + * Reorders items. |
|
| 782 | + */ |
|
| 783 | + public static function reorder_items( $vars ) { |
|
| 784 | + global $typenow; |
|
| 785 | + |
|
| 786 | + if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
| 787 | + return $vars; |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + // By item type. |
|
| 791 | + if ( 'type' === $vars['orderby'] ) { |
|
| 792 | + return array_merge( |
|
| 793 | + $vars, |
|
| 794 | + array( |
|
| 795 | + 'meta_key' => '_wpinv_type', |
|
| 796 | + 'orderby' => 'meta_value', |
|
| 797 | + ) |
|
| 798 | + ); |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + // By vat class. |
|
| 802 | + if ( 'vat_class' === $vars['orderby'] ) { |
|
| 803 | + return array_merge( |
|
| 804 | + $vars, |
|
| 805 | + array( |
|
| 806 | + 'meta_key' => '_wpinv_vat_class', |
|
| 807 | + 'orderby' => 'meta_value', |
|
| 808 | + ) |
|
| 809 | + ); |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + // By vat rule. |
|
| 813 | + if ( 'vat_rule' === $vars['orderby'] ) { |
|
| 814 | + return array_merge( |
|
| 815 | + $vars, |
|
| 816 | + array( |
|
| 817 | + 'meta_key' => '_wpinv_vat_rule', |
|
| 818 | + 'orderby' => 'meta_value', |
|
| 819 | + ) |
|
| 820 | + ); |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + // By price. |
|
| 824 | + if ( 'price' === $vars['orderby'] ) { |
|
| 825 | + return array_merge( |
|
| 826 | + $vars, |
|
| 827 | + array( |
|
| 828 | + 'meta_key' => '_wpinv_price', |
|
| 829 | + 'orderby' => 'meta_value_num', |
|
| 830 | + ) |
|
| 831 | + ); |
|
| 832 | + } |
|
| 833 | + |
|
| 834 | + return $vars; |
|
| 835 | + |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + /** |
|
| 839 | + * Fired when deleting a post. |
|
| 840 | + */ |
|
| 841 | + public static function delete_post( $post_id ) { |
|
| 842 | + |
|
| 843 | + switch ( get_post_type( $post_id ) ) { |
|
| 844 | + |
|
| 845 | + case 'wpi_item': |
|
| 846 | + do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) ); |
|
| 847 | + break; |
|
| 848 | + |
|
| 849 | + case 'wpi_payment_form': |
|
| 850 | + do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) ); |
|
| 851 | + break; |
|
| 852 | + |
|
| 853 | + case 'wpi_discount': |
|
| 854 | + do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) ); |
|
| 855 | + break; |
|
| 856 | + |
|
| 857 | + case 'wpi_invoice': |
|
| 858 | + $invoice = new WPInv_Invoice( $post_id ); |
|
| 859 | + do_action( 'getpaid_before_delete_invoice', $invoice ); |
|
| 860 | + $invoice->get_data_store()->delete_items( $invoice ); |
|
| 861 | + $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
| 862 | + break; |
|
| 863 | + } |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + /** |
|
| 867 | 867 | * Add a post display state for special GetPaid pages in the page list table. |
| 868 | 868 | * |
| 869 | 869 | * @param array $post_states An array of post display states. |
@@ -877,21 +877,21 @@ discard block |
||
| 877 | 877 | $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' ); |
| 878 | 878 | } |
| 879 | 879 | |
| 880 | - foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
| 880 | + foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
| 881 | 881 | |
| 882 | - if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
| 883 | - $post_states[ "getpaid_{$post_type}_history_page" ] = sprintf( |
|
| 884 | - __( 'GetPaid %s History Page', 'invoicing' ), |
|
| 885 | - $label |
|
| 886 | - ); |
|
| 887 | - } |
|
| 882 | + if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
| 883 | + $post_states[ "getpaid_{$post_type}_history_page" ] = sprintf( |
|
| 884 | + __( 'GetPaid %s History Page', 'invoicing' ), |
|
| 885 | + $label |
|
| 886 | + ); |
|
| 887 | + } |
|
| 888 | 888 | } |
| 889 | 889 | |
| 890 | - if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
| 890 | + if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
| 891 | 891 | $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' ); |
| 892 | 892 | } |
| 893 | 893 | |
| 894 | - if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
| 894 | + if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
| 895 | 895 | $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' ); |
| 896 | 896 | } |
| 897 | 897 | |
@@ -57,21 +57,21 @@ discard block |
||
| 57 | 57 | $args = wp_parse_args( |
| 58 | 58 | $args, |
| 59 | 59 | array( |
| 60 | - 'status' => array( 'publish' ), |
|
| 61 | - 'limit' => get_option( 'posts_per_page' ), |
|
| 62 | - 'page' => 1, |
|
| 63 | - 'exclude' => array(), |
|
| 64 | - 'orderby' => 'date', |
|
| 65 | - 'order' => 'DESC', |
|
| 66 | - 'type' => wpinv_item_types(), |
|
| 67 | - 'meta_query' => array( |
|
| 60 | + 'status' => array( 'publish' ), |
|
| 61 | + 'limit' => get_option( 'posts_per_page' ), |
|
| 62 | + 'page' => 1, |
|
| 63 | + 'exclude' => array(), |
|
| 64 | + 'orderby' => 'date', |
|
| 65 | + 'order' => 'DESC', |
|
| 66 | + 'type' => wpinv_item_types(), |
|
| 67 | + 'meta_query' => array( |
|
| 68 | 68 | array( |
| 69 | 69 | 'key' => '_wpinv_one_time', |
| 70 | 70 | 'compare' => 'NOT EXISTS', |
| 71 | 71 | ), |
| 72 | 72 | ), |
| 73 | - 'return' => 'objects', |
|
| 74 | - 'paginate' => false, |
|
| 73 | + 'return' => 'objects', |
|
| 74 | + 'paginate' => false, |
|
| 75 | 75 | ) |
| 76 | 76 | ); |
| 77 | 77 | |
@@ -211,9 +211,9 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | function wpinv_get_item_types() { |
| 213 | 213 | $item_types = array( |
| 214 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
| 215 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
| 216 | - ); |
|
| 214 | + 'custom' => __( 'Standard', 'invoicing' ), |
|
| 215 | + 'fee' => __( 'Fee', 'invoicing' ), |
|
| 216 | + ); |
|
| 217 | 217 | return apply_filters( 'wpinv_get_item_types', $item_types ); |
| 218 | 218 | } |
| 219 | 219 | |
@@ -255,16 +255,16 @@ discard block |
||
| 255 | 255 | $args = array(); |
| 256 | 256 | if ( $post_ids ) { |
| 257 | 257 | $args = array( |
| 258 | - 'fields' => 'ids', |
|
| 259 | - ); |
|
| 258 | + 'fields' => 'ids', |
|
| 259 | + ); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | $args = array_merge( |
| 263 | 263 | $args, |
| 264 | 264 | array( |
| 265 | 265 | 'post_type' => 'wpi_item', |
| 266 | - 'orderby' => 'rand', |
|
| 267 | - 'post_count' => $num, |
|
| 266 | + 'orderby' => 'rand', |
|
| 267 | + 'post_count' => $num, |
|
| 268 | 268 | 'meta_query' => array( |
| 269 | 269 | array( |
| 270 | 270 | 'key' => '_wpinv_one_time', |
@@ -439,10 +439,10 @@ discard block |
||
| 439 | 439 | $bill_times_less = $bill_times - 1; |
| 440 | 440 | |
| 441 | 441 | if ( ! empty( $bill_times ) ) { |
| 442 | - $bill_times = $item->get_recurring_interval() * $bill_times; |
|
| 442 | + $bill_times = $item->get_recurring_interval() * $bill_times; |
|
| 443 | 443 | $bill_times_less = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times - $item->get_recurring_interval() ); |
| 444 | - $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
| 445 | - } |
|
| 444 | + $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
| 445 | + } |
|
| 446 | 446 | |
| 447 | 447 | if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
| 448 | 448 | $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
@@ -587,19 +587,19 @@ discard block |
||
| 587 | 587 | * @return bool Whether the item type supports the given feature. |
| 588 | 588 | */ |
| 589 | 589 | function getpaid_item_type_supports( $item_type, $feature, $item_ID = 0 ) { |
| 590 | - $supports = false; |
|
| 590 | + $supports = false; |
|
| 591 | 591 | |
| 592 | - if ( ! is_scalar( $item_type ) ) { |
|
| 593 | - return $supports; |
|
| 594 | - } |
|
| 592 | + if ( ! is_scalar( $item_type ) ) { |
|
| 593 | + return $supports; |
|
| 594 | + } |
|
| 595 | 595 | |
| 596 | - switch ( $feature ) { |
|
| 597 | - case 'buy_now': |
|
| 598 | - if ( '' === $item_type || 'fee' === $item_type || 'custom' === $item_type ) { |
|
| 599 | - $supports = true; |
|
| 600 | - } |
|
| 601 | - break; |
|
| 602 | - } |
|
| 596 | + switch ( $feature ) { |
|
| 597 | + case 'buy_now': |
|
| 598 | + if ( '' === $item_type || 'fee' === $item_type || 'custom' === $item_type ) { |
|
| 599 | + $supports = true; |
|
| 600 | + } |
|
| 601 | + break; |
|
| 602 | + } |
|
| 603 | 603 | |
| 604 | - return apply_filters( 'getpaid_item_type_supports', $supports, $item_type, $feature, $item_ID ); |
|
| 604 | + return apply_filters( 'getpaid_item_type_supports', $supports, $item_type, $feature, $item_ID ); |
|
| 605 | 605 | } |
| 606 | 606 | \ No newline at end of file |
@@ -5,129 +5,129 @@ discard block |
||
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | - exit; // Exit if accessed directly |
|
| 8 | + exit; // Exit if accessed directly |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | if ( ! class_exists( 'GetPaid_Admin_Profile', false ) ) : |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * GetPaid_Admin_Profile Class. |
|
| 15 | - */ |
|
| 16 | - class GetPaid_Admin_Profile { |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * Hook in tabs. |
|
| 20 | - */ |
|
| 21 | - public function __construct() { |
|
| 22 | - add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
| 23 | - add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
| 24 | - |
|
| 25 | - add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) ); |
|
| 26 | - add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) ); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Get Address Fields for the edit user pages. |
|
| 31 | - * |
|
| 32 | - * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned |
|
| 33 | - */ |
|
| 34 | - public function get_customer_meta_fields() { |
|
| 35 | - |
|
| 36 | - $show_fields = apply_filters( |
|
| 37 | - 'getpaid_customer_meta_fields', |
|
| 38 | - array( |
|
| 39 | - 'billing' => array( |
|
| 40 | - 'title' => __( 'Billing Details (GetPaid)', 'invoicing' ), |
|
| 41 | - 'fields' => array( |
|
| 42 | - '_wpinv_first_name' => array( |
|
| 43 | - 'label' => __( 'First name', 'invoicing' ), |
|
| 44 | - 'description' => '', |
|
| 45 | - ), |
|
| 46 | - '_wpinv_last_name' => array( |
|
| 47 | - 'label' => __( 'Last name', 'invoicing' ), |
|
| 48 | - 'description' => '', |
|
| 49 | - ), |
|
| 50 | - '_wpinv_company' => array( |
|
| 51 | - 'label' => __( 'Company', 'invoicing' ), |
|
| 52 | - 'description' => '', |
|
| 53 | - ), |
|
| 54 | - '_wpinv_company_id' => array( |
|
| 55 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
| 56 | - 'description' => '', |
|
| 57 | - ), |
|
| 58 | - '_wpinv_address' => array( |
|
| 59 | - 'label' => __( 'Address', 'invoicing' ), |
|
| 60 | - 'description' => '', |
|
| 61 | - ), |
|
| 62 | - '_wpinv_city' => array( |
|
| 63 | - 'label' => __( 'City', 'invoicing' ), |
|
| 64 | - 'description' => '', |
|
| 65 | - ), |
|
| 66 | - '_wpinv_zip' => array( |
|
| 67 | - 'label' => __( 'Postcode / ZIP', 'invoicing' ), |
|
| 68 | - 'description' => '', |
|
| 69 | - ), |
|
| 70 | - '_wpinv_country' => array( |
|
| 71 | - 'label' => __( 'Country / Region', 'invoicing' ), |
|
| 72 | - 'description' => '', |
|
| 73 | - 'class' => 'getpaid_js_field-country', |
|
| 74 | - 'type' => 'select', |
|
| 75 | - 'options' => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(), |
|
| 76 | - ), |
|
| 77 | - '_wpinv_state' => array( |
|
| 78 | - 'label' => __( 'State / County', 'invoicing' ), |
|
| 79 | - 'description' => __( 'State / County or state code', 'invoicing' ), |
|
| 80 | - 'class' => 'getpaid_js_field-state regular-text', |
|
| 81 | - ), |
|
| 82 | - '_wpinv_phone' => array( |
|
| 83 | - 'label' => __( 'Phone', 'invoicing' ), |
|
| 84 | - 'description' => '', |
|
| 85 | - ), |
|
| 86 | - '_wpinv_vat_number' => array( |
|
| 87 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
| 88 | - 'description' => '', |
|
| 89 | - ), |
|
| 90 | - ), |
|
| 91 | - ), |
|
| 92 | - ) |
|
| 93 | - ); |
|
| 94 | - return $show_fields; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Show Address Fields on edit user pages. |
|
| 99 | - * |
|
| 100 | - * @param WP_User $user |
|
| 101 | - */ |
|
| 102 | - public function add_customer_meta_fields( $user ) { |
|
| 103 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
| 104 | - return; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $show_fields = $this->get_customer_meta_fields(); |
|
| 108 | - |
|
| 109 | - $customer = getpaid_get_customer_by_user_id( (int) $user->ID ); |
|
| 110 | - |
|
| 111 | - foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
| 112 | - if ( ! wpinv_use_taxes() && isset( $fieldset['fields']['_wpinv_vat_number'] ) ) { |
|
| 113 | - unset( $fieldset['fields']['_wpinv_vat_number'] ); |
|
| 114 | - } |
|
| 115 | - ?> |
|
| 13 | + /** |
|
| 14 | + * GetPaid_Admin_Profile Class. |
|
| 15 | + */ |
|
| 16 | + class GetPaid_Admin_Profile { |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * Hook in tabs. |
|
| 20 | + */ |
|
| 21 | + public function __construct() { |
|
| 22 | + add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
| 23 | + add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
| 24 | + |
|
| 25 | + add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) ); |
|
| 26 | + add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) ); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Get Address Fields for the edit user pages. |
|
| 31 | + * |
|
| 32 | + * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned |
|
| 33 | + */ |
|
| 34 | + public function get_customer_meta_fields() { |
|
| 35 | + |
|
| 36 | + $show_fields = apply_filters( |
|
| 37 | + 'getpaid_customer_meta_fields', |
|
| 38 | + array( |
|
| 39 | + 'billing' => array( |
|
| 40 | + 'title' => __( 'Billing Details (GetPaid)', 'invoicing' ), |
|
| 41 | + 'fields' => array( |
|
| 42 | + '_wpinv_first_name' => array( |
|
| 43 | + 'label' => __( 'First name', 'invoicing' ), |
|
| 44 | + 'description' => '', |
|
| 45 | + ), |
|
| 46 | + '_wpinv_last_name' => array( |
|
| 47 | + 'label' => __( 'Last name', 'invoicing' ), |
|
| 48 | + 'description' => '', |
|
| 49 | + ), |
|
| 50 | + '_wpinv_company' => array( |
|
| 51 | + 'label' => __( 'Company', 'invoicing' ), |
|
| 52 | + 'description' => '', |
|
| 53 | + ), |
|
| 54 | + '_wpinv_company_id' => array( |
|
| 55 | + 'label' => __( 'Company ID', 'invoicing' ), |
|
| 56 | + 'description' => '', |
|
| 57 | + ), |
|
| 58 | + '_wpinv_address' => array( |
|
| 59 | + 'label' => __( 'Address', 'invoicing' ), |
|
| 60 | + 'description' => '', |
|
| 61 | + ), |
|
| 62 | + '_wpinv_city' => array( |
|
| 63 | + 'label' => __( 'City', 'invoicing' ), |
|
| 64 | + 'description' => '', |
|
| 65 | + ), |
|
| 66 | + '_wpinv_zip' => array( |
|
| 67 | + 'label' => __( 'Postcode / ZIP', 'invoicing' ), |
|
| 68 | + 'description' => '', |
|
| 69 | + ), |
|
| 70 | + '_wpinv_country' => array( |
|
| 71 | + 'label' => __( 'Country / Region', 'invoicing' ), |
|
| 72 | + 'description' => '', |
|
| 73 | + 'class' => 'getpaid_js_field-country', |
|
| 74 | + 'type' => 'select', |
|
| 75 | + 'options' => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(), |
|
| 76 | + ), |
|
| 77 | + '_wpinv_state' => array( |
|
| 78 | + 'label' => __( 'State / County', 'invoicing' ), |
|
| 79 | + 'description' => __( 'State / County or state code', 'invoicing' ), |
|
| 80 | + 'class' => 'getpaid_js_field-state regular-text', |
|
| 81 | + ), |
|
| 82 | + '_wpinv_phone' => array( |
|
| 83 | + 'label' => __( 'Phone', 'invoicing' ), |
|
| 84 | + 'description' => '', |
|
| 85 | + ), |
|
| 86 | + '_wpinv_vat_number' => array( |
|
| 87 | + 'label' => __( 'VAT Number', 'invoicing' ), |
|
| 88 | + 'description' => '', |
|
| 89 | + ), |
|
| 90 | + ), |
|
| 91 | + ), |
|
| 92 | + ) |
|
| 93 | + ); |
|
| 94 | + return $show_fields; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Show Address Fields on edit user pages. |
|
| 99 | + * |
|
| 100 | + * @param WP_User $user |
|
| 101 | + */ |
|
| 102 | + public function add_customer_meta_fields( $user ) { |
|
| 103 | + if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
| 104 | + return; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $show_fields = $this->get_customer_meta_fields(); |
|
| 108 | + |
|
| 109 | + $customer = getpaid_get_customer_by_user_id( (int) $user->ID ); |
|
| 110 | + |
|
| 111 | + foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
| 112 | + if ( ! wpinv_use_taxes() && isset( $fieldset['fields']['_wpinv_vat_number'] ) ) { |
|
| 113 | + unset( $fieldset['fields']['_wpinv_vat_number'] ); |
|
| 114 | + } |
|
| 115 | + ?> |
|
| 116 | 116 | <h2><?php echo esc_html( $fieldset['title'] ); ?></h2> |
| 117 | 117 | <table class="form-table" id="<?php echo esc_attr( 'getpaid-fieldset-' . $fieldset_key ); ?>"> |
| 118 | 118 | <?php foreach ( $fieldset['fields'] as $key => $field ) : |
| 119 | - if ( ! empty( $customer ) ) { |
|
| 120 | - if ( strpos( $key, '_wpinv_' ) === 0 ) { |
|
| 121 | - $save_key = substr( $key , 7 ); |
|
| 122 | - } else { |
|
| 123 | - $save_key = $key; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $value = $customer->get( $save_key ); |
|
| 127 | - } else { |
|
| 128 | - $value = $this->get_user_meta( $user->ID, $key ); |
|
| 129 | - } |
|
| 130 | - ?> |
|
| 119 | + if ( ! empty( $customer ) ) { |
|
| 120 | + if ( strpos( $key, '_wpinv_' ) === 0 ) { |
|
| 121 | + $save_key = substr( $key , 7 ); |
|
| 122 | + } else { |
|
| 123 | + $save_key = $key; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $value = $customer->get( $save_key ); |
|
| 127 | + } else { |
|
| 128 | + $value = $this->get_user_meta( $user->ID, $key ); |
|
| 129 | + } |
|
| 130 | + ?> |
|
| 131 | 131 | <tr> |
| 132 | 132 | <th> |
| 133 | 133 | <label for="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $field['label'] ); ?></label> |
@@ -150,75 +150,75 @@ discard block |
||
| 150 | 150 | <?php endforeach; ?> |
| 151 | 151 | </table> |
| 152 | 152 | <?php |
| 153 | - endforeach; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Save Address Fields on edit user pages. |
|
| 158 | - * |
|
| 159 | - * @param int $user_id User ID of the user being saved |
|
| 160 | - */ |
|
| 161 | - public function save_customer_meta_fields( $user_id ) { |
|
| 162 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
| 163 | - return; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $save_fields = $this->get_customer_meta_fields(); |
|
| 167 | - $save_data = array(); |
|
| 168 | - |
|
| 169 | - foreach ( $save_fields as $fieldset ) { |
|
| 170 | - foreach ( $fieldset['fields'] as $key => $field ) { |
|
| 171 | - if ( strpos( $key, '_wpinv_' ) === 0 ) { |
|
| 172 | - $save_key = substr( $key , 7 ); |
|
| 173 | - } else { |
|
| 174 | - $save_key = $key; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - if ( $save_key && isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
| 178 | - $save_data[ $save_key ] = ! empty( $_POST[ $key ] ) ? true : false; |
|
| 179 | - } else if ( $save_key && isset( $_POST[ $key ] ) ) { |
|
| 180 | - $save_data[ $save_key ] = wpinv_clean( $_POST[ $key ] ); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - if ( empty( $save_data ) ) { |
|
| 186 | - return; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - $customer = getpaid_get_customer_by_user_id( (int) $user_id ); |
|
| 190 | - |
|
| 191 | - if ( empty( $customer ) ) { |
|
| 192 | - $customer = new GetPaid_Customer( 0 ); |
|
| 193 | - $customer->clone_user( (int) $user_id ); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - foreach ( $save_data as $key => $value ) { |
|
| 197 | - $customer->set( $key, $value ); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $customer->save(); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. |
|
| 205 | - * |
|
| 206 | - * @since 3.1.0 |
|
| 207 | - * @param int $user_id User ID of the user being edited |
|
| 208 | - * @param string $key Key for user meta field |
|
| 209 | - * @return string |
|
| 210 | - */ |
|
| 211 | - protected function get_user_meta( $user_id, $key ) { |
|
| 212 | - $value = get_user_meta( $user_id, $key, true ); |
|
| 213 | - $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
| 214 | - |
|
| 215 | - if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
| 216 | - $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - return $value; |
|
| 220 | - } |
|
| 221 | - } |
|
| 153 | + endforeach; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Save Address Fields on edit user pages. |
|
| 158 | + * |
|
| 159 | + * @param int $user_id User ID of the user being saved |
|
| 160 | + */ |
|
| 161 | + public function save_customer_meta_fields( $user_id ) { |
|
| 162 | + if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
| 163 | + return; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $save_fields = $this->get_customer_meta_fields(); |
|
| 167 | + $save_data = array(); |
|
| 168 | + |
|
| 169 | + foreach ( $save_fields as $fieldset ) { |
|
| 170 | + foreach ( $fieldset['fields'] as $key => $field ) { |
|
| 171 | + if ( strpos( $key, '_wpinv_' ) === 0 ) { |
|
| 172 | + $save_key = substr( $key , 7 ); |
|
| 173 | + } else { |
|
| 174 | + $save_key = $key; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + if ( $save_key && isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
| 178 | + $save_data[ $save_key ] = ! empty( $_POST[ $key ] ) ? true : false; |
|
| 179 | + } else if ( $save_key && isset( $_POST[ $key ] ) ) { |
|
| 180 | + $save_data[ $save_key ] = wpinv_clean( $_POST[ $key ] ); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + if ( empty( $save_data ) ) { |
|
| 186 | + return; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + $customer = getpaid_get_customer_by_user_id( (int) $user_id ); |
|
| 190 | + |
|
| 191 | + if ( empty( $customer ) ) { |
|
| 192 | + $customer = new GetPaid_Customer( 0 ); |
|
| 193 | + $customer->clone_user( (int) $user_id ); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + foreach ( $save_data as $key => $value ) { |
|
| 197 | + $customer->set( $key, $value ); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $customer->save(); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. |
|
| 205 | + * |
|
| 206 | + * @since 3.1.0 |
|
| 207 | + * @param int $user_id User ID of the user being edited |
|
| 208 | + * @param string $key Key for user meta field |
|
| 209 | + * @return string |
|
| 210 | + */ |
|
| 211 | + protected function get_user_meta( $user_id, $key ) { |
|
| 212 | + $value = get_user_meta( $user_id, $key, true ); |
|
| 213 | + $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
| 214 | + |
|
| 215 | + if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
| 216 | + $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + return $value; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | 223 | endif; |
| 224 | 224 | |
@@ -14,76 +14,76 @@ |
||
| 14 | 14 | * @return array|mixed|string|string[] |
| 15 | 15 | */ |
| 16 | 16 | function aui_bs_convert_sd_output( $output, $instance = '', $args = '', $sd = '' ) { |
| 17 | - global $aui_bs5; |
|
| 17 | + global $aui_bs5; |
|
| 18 | 18 | |
| 19 | - if ( $aui_bs5 ) { |
|
| 20 | - $convert = array( |
|
| 21 | - '"ml-' => '"ms-', |
|
| 22 | - '"mr-' => '"me-', |
|
| 23 | - '"pl-' => '"ps-', |
|
| 24 | - '"pr-' => '"pe-', |
|
| 25 | - "'ml-" => "'ms-", |
|
| 26 | - "'mr-" => "'me-", |
|
| 27 | - "'pl-" => "'ps-", |
|
| 28 | - "'pr-" => "'pe-", |
|
| 29 | - ' ml-' => ' ms-', |
|
| 30 | - ' mr-' => ' me-', |
|
| 31 | - ' pl-' => ' ps-', |
|
| 32 | - ' pr-' => ' pe-', |
|
| 33 | - '.ml-' => '.ms-', |
|
| 34 | - '.mr-' => '.me-', |
|
| 35 | - '.pl-' => '.ps-', |
|
| 36 | - '.pr-' => '.pe-', |
|
| 37 | - ' form-row' => ' row', |
|
| 38 | - ' embed-responsive-item' => '', |
|
| 39 | - ' embed-responsive' => ' ratio', |
|
| 40 | - '-1by1' => '-1x1', |
|
| 41 | - '-4by3' => '-4x3', |
|
| 42 | - '-16by9' => '-16x9', |
|
| 43 | - '-21by9' => '-21x9', |
|
| 44 | - 'geodir-lightbox-image' => 'aui-lightbox-image', |
|
| 45 | - 'geodir-lightbox-iframe' => 'aui-lightbox-iframe', |
|
| 46 | - ' badge-' => ' text-bg-', |
|
| 47 | - 'form-group' => 'mb-3', |
|
| 48 | - 'custom-select' => 'form-select', |
|
| 49 | - 'float-left' => 'float-start', |
|
| 50 | - 'float-right' => 'float-end', |
|
| 51 | - 'text-left' => 'text-start', |
|
| 52 | - 'text-sm-left' => 'text-sm-start', |
|
| 53 | - 'text-md-left' => 'text-md-start', |
|
| 54 | - 'text-lg-left' => 'text-lg-start', |
|
| 55 | - 'text-right' => 'text-end', |
|
| 56 | - 'text-sm-right' => 'text-sm-end', |
|
| 57 | - 'text-md-right' => 'text-md-end', |
|
| 58 | - 'text-lg-right' => 'text-lg-end', |
|
| 59 | - 'border-right' => 'border-end', |
|
| 60 | - 'border-left' => 'border-start', |
|
| 61 | - 'font-weight-' => 'fw-', |
|
| 62 | - 'btn-block' => 'w-100', |
|
| 63 | - 'rounded-left' => 'rounded-start', |
|
| 64 | - 'rounded-right' => 'rounded-end', |
|
| 65 | - 'font-italic' => 'fst-italic', |
|
| 19 | + if ( $aui_bs5 ) { |
|
| 20 | + $convert = array( |
|
| 21 | + '"ml-' => '"ms-', |
|
| 22 | + '"mr-' => '"me-', |
|
| 23 | + '"pl-' => '"ps-', |
|
| 24 | + '"pr-' => '"pe-', |
|
| 25 | + "'ml-" => "'ms-", |
|
| 26 | + "'mr-" => "'me-", |
|
| 27 | + "'pl-" => "'ps-", |
|
| 28 | + "'pr-" => "'pe-", |
|
| 29 | + ' ml-' => ' ms-', |
|
| 30 | + ' mr-' => ' me-', |
|
| 31 | + ' pl-' => ' ps-', |
|
| 32 | + ' pr-' => ' pe-', |
|
| 33 | + '.ml-' => '.ms-', |
|
| 34 | + '.mr-' => '.me-', |
|
| 35 | + '.pl-' => '.ps-', |
|
| 36 | + '.pr-' => '.pe-', |
|
| 37 | + ' form-row' => ' row', |
|
| 38 | + ' embed-responsive-item' => '', |
|
| 39 | + ' embed-responsive' => ' ratio', |
|
| 40 | + '-1by1' => '-1x1', |
|
| 41 | + '-4by3' => '-4x3', |
|
| 42 | + '-16by9' => '-16x9', |
|
| 43 | + '-21by9' => '-21x9', |
|
| 44 | + 'geodir-lightbox-image' => 'aui-lightbox-image', |
|
| 45 | + 'geodir-lightbox-iframe' => 'aui-lightbox-iframe', |
|
| 46 | + ' badge-' => ' text-bg-', |
|
| 47 | + 'form-group' => 'mb-3', |
|
| 48 | + 'custom-select' => 'form-select', |
|
| 49 | + 'float-left' => 'float-start', |
|
| 50 | + 'float-right' => 'float-end', |
|
| 51 | + 'text-left' => 'text-start', |
|
| 52 | + 'text-sm-left' => 'text-sm-start', |
|
| 53 | + 'text-md-left' => 'text-md-start', |
|
| 54 | + 'text-lg-left' => 'text-lg-start', |
|
| 55 | + 'text-right' => 'text-end', |
|
| 56 | + 'text-sm-right' => 'text-sm-end', |
|
| 57 | + 'text-md-right' => 'text-md-end', |
|
| 58 | + 'text-lg-right' => 'text-lg-end', |
|
| 59 | + 'border-right' => 'border-end', |
|
| 60 | + 'border-left' => 'border-start', |
|
| 61 | + 'font-weight-' => 'fw-', |
|
| 62 | + 'btn-block' => 'w-100', |
|
| 63 | + 'rounded-left' => 'rounded-start', |
|
| 64 | + 'rounded-right' => 'rounded-end', |
|
| 65 | + 'font-italic' => 'fst-italic', |
|
| 66 | 66 | |
| 67 | 67 | // 'custom-control custom-checkbox' => 'form-check', |
| 68 | - // data |
|
| 69 | - ' data-toggle=' => ' data-bs-toggle=', |
|
| 70 | - 'data-ride=' => 'data-bs-ride=', |
|
| 71 | - 'data-controlnav=' => 'data-bs-controlnav=', |
|
| 72 | - 'data-slide=' => 'data-bs-slide=', |
|
| 73 | - 'data-slide-to=' => 'data-bs-slide-to=', |
|
| 74 | - 'data-target=' => 'data-bs-target=', |
|
| 75 | - 'data-dismiss="modal"' => 'data-bs-dismiss="modal"', |
|
| 76 | - 'class="close"' => 'class="btn-close"', |
|
| 77 | - '<span aria-hidden="true">×</span>' => '', |
|
| 78 | - ); |
|
| 79 | - $output = str_replace( |
|
| 80 | - array_keys( $convert ), |
|
| 81 | - array_values( $convert ), |
|
| 82 | - $output |
|
| 83 | - ); |
|
| 84 | - } |
|
| 68 | + // data |
|
| 69 | + ' data-toggle=' => ' data-bs-toggle=', |
|
| 70 | + 'data-ride=' => 'data-bs-ride=', |
|
| 71 | + 'data-controlnav=' => 'data-bs-controlnav=', |
|
| 72 | + 'data-slide=' => 'data-bs-slide=', |
|
| 73 | + 'data-slide-to=' => 'data-bs-slide-to=', |
|
| 74 | + 'data-target=' => 'data-bs-target=', |
|
| 75 | + 'data-dismiss="modal"' => 'data-bs-dismiss="modal"', |
|
| 76 | + 'class="close"' => 'class="btn-close"', |
|
| 77 | + '<span aria-hidden="true">×</span>' => '', |
|
| 78 | + ); |
|
| 79 | + $output = str_replace( |
|
| 80 | + array_keys( $convert ), |
|
| 81 | + array_values( $convert ), |
|
| 82 | + $output |
|
| 83 | + ); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - return $output; |
|
| 86 | + return $output; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | add_filter( 'wp_super_duper_widget_output', 'aui_bs_convert_sd_output', 10, 4 ); //$output, $instance, $args, $this |
@@ -15,12 +15,12 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | 17 | if ( ! defined( 'ABSPATH' ) ) { |
| 18 | - exit; |
|
| 18 | + exit; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | if ( ! class_exists( 'WP_Super_Duper' ) ) { |
| 22 | - // include the class if needed |
|
| 23 | - include_once( dirname( __FILE__ ) . "/wp-super-duper.php" ); |
|
| 22 | + // include the class if needed |
|
| 23 | + include_once( dirname( __FILE__ ) . "/wp-super-duper.php" ); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /* |
@@ -35,5 +35,5 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | |
| 37 | 37 | if ( ! function_exists( 'sd_get_class_build_keys' ) ) { |
| 38 | - include_once( dirname( __FILE__ ) . "/sd-functions.php" ); |
|
| 38 | + include_once( dirname( __FILE__ ) . "/sd-functions.php" ); |
|
| 39 | 39 | } |
| 40 | 40 | \ No newline at end of file |
@@ -3,114 +3,114 @@ discard block |
||
| 3 | 3 | class SD_Hello_World extends WP_Super_Duper { |
| 4 | 4 | |
| 5 | 5 | |
| 6 | - public $arguments; |
|
| 7 | - |
|
| 8 | - /** |
|
| 9 | - * Sets up the widgets name etc |
|
| 10 | - */ |
|
| 11 | - public function __construct() { |
|
| 12 | - |
|
| 13 | - $options = array( |
|
| 14 | - 'textdomain' => 'super-duper', |
|
| 15 | - // textdomain of the plugin/theme (used to prefix the Gutenberg block) |
|
| 16 | - 'block-icon' => 'fas fa-globe-americas', |
|
| 17 | - // Dash icon name for the block: https://developer.wordpress.org/resource/dashicons/#arrow-right |
|
| 18 | - // OR font-awesome 5 class name: fas fa-globe-americas |
|
| 19 | - 'block-category' => 'widgets', |
|
| 20 | - // the category for the block, 'common', 'formatting', 'layout', 'widgets', 'embed'. |
|
| 21 | - 'block-keywords' => "['hello','world']", |
|
| 22 | - // used in the block search, MAX 3 |
|
| 23 | - 'block-output' => array( // the block visual output elements as an array |
|
| 6 | + public $arguments; |
|
| 7 | + |
|
| 8 | + /** |
|
| 9 | + * Sets up the widgets name etc |
|
| 10 | + */ |
|
| 11 | + public function __construct() { |
|
| 12 | + |
|
| 13 | + $options = array( |
|
| 14 | + 'textdomain' => 'super-duper', |
|
| 15 | + // textdomain of the plugin/theme (used to prefix the Gutenberg block) |
|
| 16 | + 'block-icon' => 'fas fa-globe-americas', |
|
| 17 | + // Dash icon name for the block: https://developer.wordpress.org/resource/dashicons/#arrow-right |
|
| 18 | + // OR font-awesome 5 class name: fas fa-globe-americas |
|
| 19 | + 'block-category' => 'widgets', |
|
| 20 | + // the category for the block, 'common', 'formatting', 'layout', 'widgets', 'embed'. |
|
| 21 | + 'block-keywords' => "['hello','world']", |
|
| 22 | + // used in the block search, MAX 3 |
|
| 23 | + 'block-output' => array( // the block visual output elements as an array |
|
| 24 | 24 | // array( |
| 25 | 25 | // 'element' => 'p', |
| 26 | 26 | // 'title' => __( 'Placeholder', 'ayecode-connect' ), |
| 27 | 27 | // 'class' => '[%className%]', |
| 28 | 28 | // 'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%] |
| 29 | 29 | // ) |
| 30 | - array( |
|
| 31 | - 'element' => 'BlocksProps', |
|
| 32 | - 'inner_element' => 'p', |
|
| 33 | - 'blockProps' => array( |
|
| 34 | - 'className' => '[%WrapClass%]', |
|
| 30 | + array( |
|
| 31 | + 'element' => 'BlocksProps', |
|
| 32 | + 'inner_element' => 'p', |
|
| 33 | + 'blockProps' => array( |
|
| 34 | + 'className' => '[%WrapClass%]', |
|
| 35 | 35 | // 'content' => 'Hello: [%after_text%]' |
| 36 | 36 | // 'if_dangerouslySetInnerHTML' => '{__html: blockstrap_build_shape(props.attributes) }', |
| 37 | - ), |
|
| 38 | - 'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%] |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - ), |
|
| 42 | - ), |
|
| 43 | - 'block-wrap' => '', // You can specify the type of element to wrap the block `div` or `span` etc.. Or blank for no wrap at all. |
|
| 44 | - 'class_name' => __CLASS__, |
|
| 45 | - // The calling class name |
|
| 46 | - 'base_id' => 'hello_world', |
|
| 47 | - // this is used as the widget id and the shortcode id. |
|
| 48 | - 'name' => __( 'Hello World', 'ayecode-connect' ), |
|
| 49 | - // the name of the widget/block |
|
| 50 | - 'widget_ops' => array( |
|
| 51 | - 'classname' => 'hello-world-class', |
|
| 52 | - // widget class |
|
| 53 | - 'description' => esc_html__( 'This is an example that will take a text parameter and output it after `Hello:`.', 'ayecode-connect' ), |
|
| 54 | - // widget description |
|
| 55 | - ), |
|
| 56 | - 'no_wrap' => true, // This will prevent the widget being wrapped in the containing widget class div. |
|
| 57 | - 'arguments' => array( // these are the arguments that will be used in the widget, shortcode and block settings. |
|
| 58 | - 'after_text' => array( // this is the input name='' |
|
| 59 | - 'title' => __( 'Text after hello:', 'ayecode-connect' ), |
|
| 60 | - // input title |
|
| 61 | - 'desc' => __( 'This is the text that will appear after `Hello:`.', 'ayecode-connect' ), |
|
| 62 | - // input description |
|
| 63 | - 'type' => 'text', |
|
| 64 | - // the type of input, test, select, checkbox etc. |
|
| 65 | - 'placeholder' => 'World', |
|
| 66 | - // the input placeholder text. |
|
| 67 | - 'desc_tip' => true, |
|
| 68 | - // if the input should show the widget description text as a tooltip. |
|
| 69 | - 'default' => 'World', |
|
| 70 | - // the input default value. |
|
| 71 | - 'advanced' => false |
|
| 72 | - // not yet implemented |
|
| 73 | - ), |
|
| 74 | - ) |
|
| 75 | - ); |
|
| 76 | - |
|
| 77 | - parent::__construct( $options ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * This is the output function for the widget, shortcode and block (front end). |
|
| 83 | - * |
|
| 84 | - * @param array $args The arguments values. |
|
| 85 | - * @param array $widget_args The widget arguments when used. |
|
| 86 | - * @param string $content The shortcode content argument |
|
| 87 | - * |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 90 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @var string $after_text |
|
| 94 | - * @var string $another_input This is added by filter below. |
|
| 95 | - */ |
|
| 96 | - extract( $args, EXTR_SKIP ); |
|
| 97 | - |
|
| 98 | - /* |
|
| 37 | + ), |
|
| 38 | + 'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%] |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + ), |
|
| 42 | + ), |
|
| 43 | + 'block-wrap' => '', // You can specify the type of element to wrap the block `div` or `span` etc.. Or blank for no wrap at all. |
|
| 44 | + 'class_name' => __CLASS__, |
|
| 45 | + // The calling class name |
|
| 46 | + 'base_id' => 'hello_world', |
|
| 47 | + // this is used as the widget id and the shortcode id. |
|
| 48 | + 'name' => __( 'Hello World', 'ayecode-connect' ), |
|
| 49 | + // the name of the widget/block |
|
| 50 | + 'widget_ops' => array( |
|
| 51 | + 'classname' => 'hello-world-class', |
|
| 52 | + // widget class |
|
| 53 | + 'description' => esc_html__( 'This is an example that will take a text parameter and output it after `Hello:`.', 'ayecode-connect' ), |
|
| 54 | + // widget description |
|
| 55 | + ), |
|
| 56 | + 'no_wrap' => true, // This will prevent the widget being wrapped in the containing widget class div. |
|
| 57 | + 'arguments' => array( // these are the arguments that will be used in the widget, shortcode and block settings. |
|
| 58 | + 'after_text' => array( // this is the input name='' |
|
| 59 | + 'title' => __( 'Text after hello:', 'ayecode-connect' ), |
|
| 60 | + // input title |
|
| 61 | + 'desc' => __( 'This is the text that will appear after `Hello:`.', 'ayecode-connect' ), |
|
| 62 | + // input description |
|
| 63 | + 'type' => 'text', |
|
| 64 | + // the type of input, test, select, checkbox etc. |
|
| 65 | + 'placeholder' => 'World', |
|
| 66 | + // the input placeholder text. |
|
| 67 | + 'desc_tip' => true, |
|
| 68 | + // if the input should show the widget description text as a tooltip. |
|
| 69 | + 'default' => 'World', |
|
| 70 | + // the input default value. |
|
| 71 | + 'advanced' => false |
|
| 72 | + // not yet implemented |
|
| 73 | + ), |
|
| 74 | + ) |
|
| 75 | + ); |
|
| 76 | + |
|
| 77 | + parent::__construct( $options ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * This is the output function for the widget, shortcode and block (front end). |
|
| 83 | + * |
|
| 84 | + * @param array $args The arguments values. |
|
| 85 | + * @param array $widget_args The widget arguments when used. |
|
| 86 | + * @param string $content The shortcode content argument |
|
| 87 | + * |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @var string $after_text |
|
| 94 | + * @var string $another_input This is added by filter below. |
|
| 95 | + */ |
|
| 96 | + extract( $args, EXTR_SKIP ); |
|
| 97 | + |
|
| 98 | + /* |
|
| 99 | 99 | * This value is added by filter so might not exist if filter is removed so we check. |
| 100 | 100 | */ |
| 101 | - if ( ! isset( $another_input ) ) { |
|
| 102 | - $another_input = ''; |
|
| 103 | - } |
|
| 101 | + if ( ! isset( $another_input ) ) { |
|
| 102 | + $another_input = ''; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - return "Helllo: " . $after_text . "" . $another_input; |
|
| 105 | + return "Helllo: " . $after_text . "" . $another_input; |
|
| 106 | 106 | |
| 107 | - } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | // register it. |
| 112 | 112 | add_action( 'widgets_init', function () { |
| 113 | - register_widget( 'SD_Hello_World' ); |
|
| 113 | + register_widget( 'SD_Hello_World' ); |
|
| 114 | 114 | } ); |
| 115 | 115 | |
| 116 | 116 | |
@@ -123,26 +123,26 @@ discard block |
||
| 123 | 123 | */ |
| 124 | 124 | function _my_extra_arguments( $options ) { |
| 125 | 125 | |
| 126 | - /* |
|
| 126 | + /* |
|
| 127 | 127 | * Add a new input option. |
| 128 | 128 | */ |
| 129 | - $options['arguments']['another_input'] = array( |
|
| 130 | - 'name' => 'another_input', // this is the input name='' |
|
| 131 | - 'title' => __( 'Another input:', 'ayecode-connect' ), // input title |
|
| 132 | - 'desc' => __( 'This is an input added via filter.', 'ayecode-connect' ), // input description |
|
| 133 | - 'type' => 'text', // the type of input, test, select, checkbox etc. |
|
| 134 | - 'placeholder' => 'Placeholder text', // the input placeholder text. |
|
| 135 | - 'desc_tip' => true, // if the input should show the widget description text as a tooltip. |
|
| 136 | - 'default' => '', // the input default value. |
|
| 137 | - 'advanced' => false // not yet implemented |
|
| 138 | - ); |
|
| 139 | - |
|
| 140 | - /* |
|
| 129 | + $options['arguments']['another_input'] = array( |
|
| 130 | + 'name' => 'another_input', // this is the input name='' |
|
| 131 | + 'title' => __( 'Another input:', 'ayecode-connect' ), // input title |
|
| 132 | + 'desc' => __( 'This is an input added via filter.', 'ayecode-connect' ), // input description |
|
| 133 | + 'type' => 'text', // the type of input, test, select, checkbox etc. |
|
| 134 | + 'placeholder' => 'Placeholder text', // the input placeholder text. |
|
| 135 | + 'desc_tip' => true, // if the input should show the widget description text as a tooltip. |
|
| 136 | + 'default' => '', // the input default value. |
|
| 137 | + 'advanced' => false // not yet implemented |
|
| 138 | + ); |
|
| 139 | + |
|
| 140 | + /* |
|
| 141 | 141 | * Output the new option in the block output also. |
| 142 | 142 | */ |
| 143 | - $options['block-output']['element::p']['content'] = $options['block-output']['element::p']['content'] . " [%another_input%]";; |
|
| 143 | + $options['block-output']['element::p']['content'] = $options['block-output']['element::p']['content'] . " [%another_input%]";; |
|
| 144 | 144 | |
| 145 | - return $options; |
|
| 145 | + return $options; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | //add_filter( 'wp_super_duper_options_hello_world', '_my_extra_arguments' ); |
| 149 | 149 | \ No newline at end of file |
@@ -14,143 +14,143 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class WPInv_Subscriptions_Widget extends WP_Super_Duper { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Register the widget with WordPress. |
|
| 19 | - * |
|
| 20 | - */ |
|
| 21 | - public function __construct() { |
|
| 22 | - |
|
| 23 | - $options = array( |
|
| 24 | - 'textdomain' => 'invoicing', |
|
| 25 | - 'block-icon' => 'controls-repeat', |
|
| 26 | - 'block-category' => 'widgets', |
|
| 27 | - 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
|
| 28 | - 'class_name' => __CLASS__, |
|
| 29 | - 'base_id' => 'wpinv_subscriptions', |
|
| 30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
| 31 | - 'widget_ops' => array( |
|
| 32 | - 'classname' => 'getpaid-subscriptions bsui', |
|
| 33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
| 34 | - ), |
|
| 35 | - 'arguments' => array( |
|
| 36 | - 'title' => array( |
|
| 37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
| 38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
| 39 | - 'type' => 'text', |
|
| 40 | - 'desc_tip' => true, |
|
| 41 | - 'default' => '', |
|
| 42 | - 'advanced' => false, |
|
| 43 | - ), |
|
| 44 | - ), |
|
| 45 | - |
|
| 46 | - ); |
|
| 47 | - |
|
| 48 | - parent::__construct( $options ); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Retrieves current user's subscriptions. |
|
| 53 | - * |
|
| 54 | - * @return GetPaid_Subscriptions_Query |
|
| 55 | - */ |
|
| 56 | - public function get_subscriptions() { |
|
| 57 | - |
|
| 58 | - // Prepare license args. |
|
| 59 | - $args = array( |
|
| 60 | - 'customer_in' => get_current_user_id(), |
|
| 61 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
| 62 | - ); |
|
| 63 | - |
|
| 64 | - return new GetPaid_Subscriptions_Query( $args ); |
|
| 65 | - |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * The Super block output function. |
|
| 70 | - * |
|
| 71 | - * @param array $args |
|
| 72 | - * @param array $widget_args |
|
| 73 | - * @param string $content |
|
| 74 | - * |
|
| 75 | - * @return mixed|string|bool |
|
| 76 | - */ |
|
| 77 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 78 | - |
|
| 79 | - // Ensure that the user is logged in. |
|
| 80 | - if ( ! is_user_logged_in() ) { |
|
| 81 | - |
|
| 82 | - return aui()->alert( |
|
| 83 | - array( |
|
| 84 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
| 85 | - 'type' => 'error', |
|
| 86 | - ) |
|
| 87 | - ); |
|
| 88 | - |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Are we displaying a single subscription? |
|
| 92 | - if ( isset( $_GET['subscription'] ) ) { |
|
| 93 | - return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // Retrieve the user's subscriptions. |
|
| 97 | - $subscriptions = $this->get_subscriptions(); |
|
| 98 | - |
|
| 99 | - // Start the output buffer. |
|
| 100 | - ob_start(); |
|
| 101 | - |
|
| 102 | - // Backwards compatibility. |
|
| 103 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
| 104 | - |
|
| 105 | - // Display errors and notices. |
|
| 106 | - wpinv_print_errors(); |
|
| 107 | - |
|
| 108 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
| 109 | - |
|
| 110 | - // Print the table header. |
|
| 111 | - $this->print_table_header(); |
|
| 112 | - |
|
| 113 | - // Print table body. |
|
| 114 | - $this->print_table_body( $subscriptions->get_results() ); |
|
| 115 | - |
|
| 116 | - // Print table footer. |
|
| 117 | - $this->print_table_footer(); |
|
| 118 | - |
|
| 119 | - // Print the navigation. |
|
| 120 | - $this->print_navigation( $subscriptions->get_total() ); |
|
| 121 | - |
|
| 122 | - // Backwards compatibility. |
|
| 123 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
| 124 | - |
|
| 125 | - // Return the output. |
|
| 126 | - return ob_get_clean(); |
|
| 127 | - |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Retrieves the subscription columns. |
|
| 132 | - * |
|
| 133 | - * @return array |
|
| 134 | - */ |
|
| 135 | - public function get_subscriptions_table_columns() { |
|
| 17 | + /** |
|
| 18 | + * Register the widget with WordPress. |
|
| 19 | + * |
|
| 20 | + */ |
|
| 21 | + public function __construct() { |
|
| 22 | + |
|
| 23 | + $options = array( |
|
| 24 | + 'textdomain' => 'invoicing', |
|
| 25 | + 'block-icon' => 'controls-repeat', |
|
| 26 | + 'block-category' => 'widgets', |
|
| 27 | + 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
|
| 28 | + 'class_name' => __CLASS__, |
|
| 29 | + 'base_id' => 'wpinv_subscriptions', |
|
| 30 | + 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
| 31 | + 'widget_ops' => array( |
|
| 32 | + 'classname' => 'getpaid-subscriptions bsui', |
|
| 33 | + 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
| 34 | + ), |
|
| 35 | + 'arguments' => array( |
|
| 36 | + 'title' => array( |
|
| 37 | + 'title' => __( 'Widget title', 'invoicing' ), |
|
| 38 | + 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
| 39 | + 'type' => 'text', |
|
| 40 | + 'desc_tip' => true, |
|
| 41 | + 'default' => '', |
|
| 42 | + 'advanced' => false, |
|
| 43 | + ), |
|
| 44 | + ), |
|
| 45 | + |
|
| 46 | + ); |
|
| 47 | + |
|
| 48 | + parent::__construct( $options ); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Retrieves current user's subscriptions. |
|
| 53 | + * |
|
| 54 | + * @return GetPaid_Subscriptions_Query |
|
| 55 | + */ |
|
| 56 | + public function get_subscriptions() { |
|
| 57 | + |
|
| 58 | + // Prepare license args. |
|
| 59 | + $args = array( |
|
| 60 | + 'customer_in' => get_current_user_id(), |
|
| 61 | + 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
| 62 | + ); |
|
| 63 | + |
|
| 64 | + return new GetPaid_Subscriptions_Query( $args ); |
|
| 65 | + |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * The Super block output function. |
|
| 70 | + * |
|
| 71 | + * @param array $args |
|
| 72 | + * @param array $widget_args |
|
| 73 | + * @param string $content |
|
| 74 | + * |
|
| 75 | + * @return mixed|string|bool |
|
| 76 | + */ |
|
| 77 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 78 | + |
|
| 79 | + // Ensure that the user is logged in. |
|
| 80 | + if ( ! is_user_logged_in() ) { |
|
| 81 | + |
|
| 82 | + return aui()->alert( |
|
| 83 | + array( |
|
| 84 | + 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
| 85 | + 'type' => 'error', |
|
| 86 | + ) |
|
| 87 | + ); |
|
| 88 | + |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Are we displaying a single subscription? |
|
| 92 | + if ( isset( $_GET['subscription'] ) ) { |
|
| 93 | + return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // Retrieve the user's subscriptions. |
|
| 97 | + $subscriptions = $this->get_subscriptions(); |
|
| 98 | + |
|
| 99 | + // Start the output buffer. |
|
| 100 | + ob_start(); |
|
| 101 | + |
|
| 102 | + // Backwards compatibility. |
|
| 103 | + do_action( 'wpinv_before_user_subscriptions' ); |
|
| 104 | + |
|
| 105 | + // Display errors and notices. |
|
| 106 | + wpinv_print_errors(); |
|
| 107 | + |
|
| 108 | + do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
| 109 | + |
|
| 110 | + // Print the table header. |
|
| 111 | + $this->print_table_header(); |
|
| 112 | + |
|
| 113 | + // Print table body. |
|
| 114 | + $this->print_table_body( $subscriptions->get_results() ); |
|
| 115 | + |
|
| 116 | + // Print table footer. |
|
| 117 | + $this->print_table_footer(); |
|
| 118 | + |
|
| 119 | + // Print the navigation. |
|
| 120 | + $this->print_navigation( $subscriptions->get_total() ); |
|
| 121 | + |
|
| 122 | + // Backwards compatibility. |
|
| 123 | + do_action( 'wpinv_after_user_subscriptions' ); |
|
| 124 | + |
|
| 125 | + // Return the output. |
|
| 126 | + return ob_get_clean(); |
|
| 127 | + |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Retrieves the subscription columns. |
|
| 132 | + * |
|
| 133 | + * @return array |
|
| 134 | + */ |
|
| 135 | + public function get_subscriptions_table_columns() { |
|
| 136 | 136 | |
| 137 | - $columns = array( |
|
| 138 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 139 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 140 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
| 141 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 142 | - ); |
|
| 137 | + $columns = array( |
|
| 138 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 139 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 140 | + 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
| 141 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 142 | + ); |
|
| 143 | 143 | |
| 144 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
| 145 | - } |
|
| 144 | + return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Displays the table header. |
|
| 149 | - * |
|
| 150 | - */ |
|
| 151 | - public function print_table_header() { |
|
| 147 | + /** |
|
| 148 | + * Displays the table header. |
|
| 149 | + * |
|
| 150 | + */ |
|
| 151 | + public function print_table_header() { |
|
| 152 | 152 | |
| 153 | - ?> |
|
| 153 | + ?> |
|
| 154 | 154 | |
| 155 | 155 | <table class="table table-bordered table-striped"> |
| 156 | 156 | |
@@ -166,122 +166,122 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | <?php |
| 168 | 168 | |
| 169 | - } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Displays the table body. |
|
| 173 | - * |
|
| 174 | - * @param WPInv_Subscription[] $subscriptions |
|
| 175 | - */ |
|
| 176 | - public function print_table_body( $subscriptions ) { |
|
| 171 | + /** |
|
| 172 | + * Displays the table body. |
|
| 173 | + * |
|
| 174 | + * @param WPInv_Subscription[] $subscriptions |
|
| 175 | + */ |
|
| 176 | + public function print_table_body( $subscriptions ) { |
|
| 177 | 177 | |
| 178 | - if ( empty( $subscriptions ) ) { |
|
| 179 | - $this->print_table_body_no_subscriptions(); |
|
| 180 | - } else { |
|
| 181 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
| 182 | - } |
|
| 178 | + if ( empty( $subscriptions ) ) { |
|
| 179 | + $this->print_table_body_no_subscriptions(); |
|
| 180 | + } else { |
|
| 181 | + $this->print_table_body_subscriptions( $subscriptions ); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - } |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * Displays the table body if no subscriptions were found. |
|
| 188 | - * |
|
| 189 | - */ |
|
| 190 | - public function print_table_body_no_subscriptions() { |
|
| 186 | + /** |
|
| 187 | + * Displays the table body if no subscriptions were found. |
|
| 188 | + * |
|
| 189 | + */ |
|
| 190 | + public function print_table_body_no_subscriptions() { |
|
| 191 | 191 | |
| 192 | - ?> |
|
| 192 | + ?> |
|
| 193 | 193 | <tbody> |
| 194 | 194 | |
| 195 | 195 | <tr> |
| 196 | 196 | <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
| 197 | 197 | |
| 198 | 198 | <?php |
| 199 | - aui()->alert( |
|
| 200 | - array( |
|
| 201 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
| 202 | - 'type' => 'warning', |
|
| 203 | - ), |
|
| 199 | + aui()->alert( |
|
| 200 | + array( |
|
| 201 | + 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
| 202 | + 'type' => 'warning', |
|
| 203 | + ), |
|
| 204 | 204 | true |
| 205 | - ); |
|
| 206 | - ?> |
|
| 205 | + ); |
|
| 206 | + ?> |
|
| 207 | 207 | |
| 208 | 208 | </td> |
| 209 | 209 | </tr> |
| 210 | 210 | |
| 211 | 211 | </tbody> |
| 212 | 212 | <?php |
| 213 | - } |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * Displays the table body if subscriptions were found. |
|
| 217 | - * |
|
| 218 | - * @param WPInv_Subscription[] $subscriptions |
|
| 219 | - */ |
|
| 220 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
| 215 | + /** |
|
| 216 | + * Displays the table body if subscriptions were found. |
|
| 217 | + * |
|
| 218 | + * @param WPInv_Subscription[] $subscriptions |
|
| 219 | + */ |
|
| 220 | + public function print_table_body_subscriptions( $subscriptions ) { |
|
| 221 | 221 | |
| 222 | - ?> |
|
| 222 | + ?> |
|
| 223 | 223 | <tbody> |
| 224 | 224 | |
| 225 | 225 | <?php foreach ( $subscriptions as $subscription ) : ?> |
| 226 | 226 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
| 227 | 227 | <?php |
| 228 | - wpinv_get_template( |
|
| 229 | - 'subscriptions/subscriptions-table-row.php', |
|
| 230 | - array( |
|
| 231 | - 'subscription' => $subscription, |
|
| 232 | - 'widget' => $this, |
|
| 233 | - ) |
|
| 234 | - ); |
|
| 235 | - ?> |
|
| 228 | + wpinv_get_template( |
|
| 229 | + 'subscriptions/subscriptions-table-row.php', |
|
| 230 | + array( |
|
| 231 | + 'subscription' => $subscription, |
|
| 232 | + 'widget' => $this, |
|
| 233 | + ) |
|
| 234 | + ); |
|
| 235 | + ?> |
|
| 236 | 236 | </tr> |
| 237 | 237 | <?php endforeach; ?> |
| 238 | 238 | |
| 239 | 239 | </tbody> |
| 240 | 240 | <?php |
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Adds row actions to a column |
|
| 245 | - * |
|
| 246 | - * @param string $content column content |
|
| 247 | - * @param WPInv_Subscription $subscription |
|
| 248 | - * @since 1.0.0 |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public function add_row_actions( $content, $subscription ) { |
|
| 252 | - |
|
| 253 | - // Prepare row actions. |
|
| 254 | - $actions = array(); |
|
| 255 | - |
|
| 256 | - // View subscription action. |
|
| 257 | - $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 258 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
| 259 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
| 260 | - |
|
| 261 | - // Filter the actions. |
|
| 262 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
| 263 | - |
|
| 264 | - $sanitized = array(); |
|
| 265 | - foreach ( $actions as $key => $action ) { |
|
| 266 | - $key = sanitize_html_class( $key ); |
|
| 267 | - $action = wp_kses_post( $action ); |
|
| 268 | - $sanitized[] = "<span class='$key'>$action</span>"; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
| 272 | - $row_actions .= implode( ' | ', $sanitized ); |
|
| 273 | - $row_actions .= '</small>'; |
|
| 274 | - |
|
| 275 | - return $content . $row_actions; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Displays the table footer. |
|
| 280 | - * |
|
| 281 | - */ |
|
| 282 | - public function print_table_footer() { |
|
| 283 | - |
|
| 284 | - ?> |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Adds row actions to a column |
|
| 245 | + * |
|
| 246 | + * @param string $content column content |
|
| 247 | + * @param WPInv_Subscription $subscription |
|
| 248 | + * @since 1.0.0 |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public function add_row_actions( $content, $subscription ) { |
|
| 252 | + |
|
| 253 | + // Prepare row actions. |
|
| 254 | + $actions = array(); |
|
| 255 | + |
|
| 256 | + // View subscription action. |
|
| 257 | + $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 258 | + $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
| 259 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
| 260 | + |
|
| 261 | + // Filter the actions. |
|
| 262 | + $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
| 263 | + |
|
| 264 | + $sanitized = array(); |
|
| 265 | + foreach ( $actions as $key => $action ) { |
|
| 266 | + $key = sanitize_html_class( $key ); |
|
| 267 | + $action = wp_kses_post( $action ); |
|
| 268 | + $sanitized[] = "<span class='$key'>$action</span>"; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
| 272 | + $row_actions .= implode( ' | ', $sanitized ); |
|
| 273 | + $row_actions .= '</small>'; |
|
| 274 | + |
|
| 275 | + return $content . $row_actions; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Displays the table footer. |
|
| 280 | + * |
|
| 281 | + */ |
|
| 282 | + public function print_table_footer() { |
|
| 283 | + |
|
| 284 | + ?> |
|
| 285 | 285 | |
| 286 | 286 | <tfoot> |
| 287 | 287 | <tr> |
@@ -296,145 +296,145 @@ discard block |
||
| 296 | 296 | </table> |
| 297 | 297 | <?php |
| 298 | 298 | |
| 299 | - } |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | - /** |
|
| 302 | - * Displays the navigation. |
|
| 303 | - * |
|
| 304 | - * @param int $total |
|
| 305 | - */ |
|
| 306 | - public function print_navigation( $total ) { |
|
| 301 | + /** |
|
| 302 | + * Displays the navigation. |
|
| 303 | + * |
|
| 304 | + * @param int $total |
|
| 305 | + */ |
|
| 306 | + public function print_navigation( $total ) { |
|
| 307 | 307 | |
| 308 | - if ( $total < 1 ) { |
|
| 308 | + if ( $total < 1 ) { |
|
| 309 | 309 | |
| 310 | - // Out-of-bounds, run the query again without LIMIT for total count. |
|
| 311 | - $args = array( |
|
| 312 | - 'customer_in' => get_current_user_id(), |
|
| 313 | - 'fields' => 'id', |
|
| 314 | - ); |
|
| 310 | + // Out-of-bounds, run the query again without LIMIT for total count. |
|
| 311 | + $args = array( |
|
| 312 | + 'customer_in' => get_current_user_id(), |
|
| 313 | + 'fields' => 'id', |
|
| 314 | + ); |
|
| 315 | 315 | |
| 316 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
| 317 | - $total = $count_query->get_total(); |
|
| 318 | - } |
|
| 316 | + $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
| 317 | + $total = $count_query->get_total(); |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - // Abort if we do not have pages. |
|
| 321 | - if ( 2 > $total ) { |
|
| 322 | - return; |
|
| 323 | - } |
|
| 320 | + // Abort if we do not have pages. |
|
| 321 | + if ( 2 > $total ) { |
|
| 322 | + return; |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - ?> |
|
| 325 | + ?> |
|
| 326 | 326 | |
| 327 | 327 | <div class="getpaid-subscriptions-pagination"> |
| 328 | 328 | <?php |
| 329 | - $big = 999999; |
|
| 330 | - |
|
| 331 | - echo wp_kses_post( |
|
| 332 | - getpaid_paginate_links( |
|
| 333 | - array( |
|
| 334 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
| 335 | - 'format' => '?paged=%#%', |
|
| 336 | - 'total' => (int) ceil( $total / 10 ), |
|
| 337 | - ) |
|
| 338 | - ) |
|
| 339 | - ); |
|
| 340 | - ?> |
|
| 329 | + $big = 999999; |
|
| 330 | + |
|
| 331 | + echo wp_kses_post( |
|
| 332 | + getpaid_paginate_links( |
|
| 333 | + array( |
|
| 334 | + 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
| 335 | + 'format' => '?paged=%#%', |
|
| 336 | + 'total' => (int) ceil( $total / 10 ), |
|
| 337 | + ) |
|
| 338 | + ) |
|
| 339 | + ); |
|
| 340 | + ?> |
|
| 341 | 341 | </div> |
| 342 | 342 | |
| 343 | 343 | <?php |
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Returns a single subscription's columns. |
|
| 348 | - * |
|
| 349 | - * @param WPInv_Subscription $subscription |
|
| 350 | - * |
|
| 351 | - * @return array |
|
| 352 | - */ |
|
| 353 | - public function get_single_subscription_columns( $subscription ) { |
|
| 354 | - |
|
| 355 | - // Prepare subscription detail columns. |
|
| 356 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
| 357 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
| 358 | - $fields = apply_filters( |
|
| 359 | - 'getpaid_single_subscription_details_fields', |
|
| 360 | - array( |
|
| 361 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 362 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
| 363 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
| 364 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
| 365 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
| 366 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
| 367 | - 'item' => $items_count > 1 ? __( 'Items', $items_count, 'invoicing' ) : __( 'Item', 'invoicing' ) |
|
| 368 | - ), |
|
| 369 | - $subscription, |
|
| 370 | - $items_count |
|
| 371 | - ); |
|
| 372 | - |
|
| 373 | - if ( isset( $fields['expiry_date'] ) ) { |
|
| 374 | - |
|
| 375 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
| 376 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - if ( 'pending' === $subscription->get_status() ) { |
|
| 380 | - unset( $fields['expiry_date'] ); |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) { |
|
| 385 | - unset( $fields['start_date'] ); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) { |
|
| 389 | - unset( $fields['initial_amount'] ); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return $fields; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * Displays a single subscription. |
|
| 397 | - * |
|
| 398 | - * @param string $subscription |
|
| 399 | - * |
|
| 400 | - * @return string |
|
| 401 | - */ |
|
| 402 | - public function display_single_subscription( $subscription ) { |
|
| 403 | - |
|
| 404 | - // Fetch the subscription. |
|
| 405 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
| 406 | - |
|
| 407 | - if ( ! $subscription->exists() ) { |
|
| 408 | - |
|
| 409 | - return aui()->alert( |
|
| 410 | - array( |
|
| 411 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
| 412 | - 'type' => 'error', |
|
| 413 | - ) |
|
| 414 | - ); |
|
| 415 | - |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - // Ensure that the user owns this subscription key. |
|
| 419 | - if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 420 | - |
|
| 421 | - return aui()->alert( |
|
| 422 | - array( |
|
| 423 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
| 424 | - 'type' => 'error', |
|
| 425 | - ) |
|
| 426 | - ); |
|
| 427 | - |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - return wpinv_get_template_html( |
|
| 431 | - 'subscriptions/subscription-details.php', |
|
| 432 | - array( |
|
| 433 | - 'subscription' => $subscription, |
|
| 434 | - 'widget' => $this, |
|
| 435 | - ) |
|
| 436 | - ); |
|
| 437 | - |
|
| 438 | - } |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Returns a single subscription's columns. |
|
| 348 | + * |
|
| 349 | + * @param WPInv_Subscription $subscription |
|
| 350 | + * |
|
| 351 | + * @return array |
|
| 352 | + */ |
|
| 353 | + public function get_single_subscription_columns( $subscription ) { |
|
| 354 | + |
|
| 355 | + // Prepare subscription detail columns. |
|
| 356 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
| 357 | + $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
| 358 | + $fields = apply_filters( |
|
| 359 | + 'getpaid_single_subscription_details_fields', |
|
| 360 | + array( |
|
| 361 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 362 | + 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
| 363 | + 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
| 364 | + 'start_date' => __( 'Start date', 'invoicing' ), |
|
| 365 | + 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
| 366 | + 'payments' => __( 'Payments', 'invoicing' ), |
|
| 367 | + 'item' => $items_count > 1 ? __( 'Items', $items_count, 'invoicing' ) : __( 'Item', 'invoicing' ) |
|
| 368 | + ), |
|
| 369 | + $subscription, |
|
| 370 | + $items_count |
|
| 371 | + ); |
|
| 372 | + |
|
| 373 | + if ( isset( $fields['expiry_date'] ) ) { |
|
| 374 | + |
|
| 375 | + if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
| 376 | + $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + if ( 'pending' === $subscription->get_status() ) { |
|
| 380 | + unset( $fields['expiry_date'] ); |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) { |
|
| 385 | + unset( $fields['start_date'] ); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) { |
|
| 389 | + unset( $fields['initial_amount'] ); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return $fields; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * Displays a single subscription. |
|
| 397 | + * |
|
| 398 | + * @param string $subscription |
|
| 399 | + * |
|
| 400 | + * @return string |
|
| 401 | + */ |
|
| 402 | + public function display_single_subscription( $subscription ) { |
|
| 403 | + |
|
| 404 | + // Fetch the subscription. |
|
| 405 | + $subscription = new WPInv_Subscription( (int) $subscription ); |
|
| 406 | + |
|
| 407 | + if ( ! $subscription->exists() ) { |
|
| 408 | + |
|
| 409 | + return aui()->alert( |
|
| 410 | + array( |
|
| 411 | + 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
| 412 | + 'type' => 'error', |
|
| 413 | + ) |
|
| 414 | + ); |
|
| 415 | + |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + // Ensure that the user owns this subscription key. |
|
| 419 | + if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 420 | + |
|
| 421 | + return aui()->alert( |
|
| 422 | + array( |
|
| 423 | + 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
| 424 | + 'type' => 'error', |
|
| 425 | + ) |
|
| 426 | + ); |
|
| 427 | + |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + return wpinv_get_template_html( |
|
| 431 | + 'subscriptions/subscription-details.php', |
|
| 432 | + array( |
|
| 433 | + 'subscription' => $subscription, |
|
| 434 | + 'widget' => $this, |
|
| 435 | + ) |
|
| 436 | + ); |
|
| 437 | + |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | 440 | } |