@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if (!defined('ABSPATH')) { |
|
10 | 10 | exit; // Exit if accessed directly |
11 | 11 | } |
12 | 12 | |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @param WP_Post $post |
22 | 22 | */ |
23 | - public static function output( $post ) { |
|
23 | + public static function output($post) { |
|
24 | 24 | ?> |
25 | 25 | <style> |
26 | 26 | .wpinv-form-builder-edit-field-wrapper label.d-block > span:first-child{ |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | <div class="col-sm-4"> |
34 | 34 | |
35 | 35 | <!-- Builder tabs --> |
36 | - <button class="button button-primary" v-if="active_tab!='new_item'" @click.prevent="active_tab='new_item'"><?php _e( 'Go Back', 'invoicing' ); ?></button> |
|
36 | + <button class="button button-primary" v-if="active_tab!='new_item'" @click.prevent="active_tab='new_item'"><?php _e('Go Back', 'invoicing'); ?></button> |
|
37 | 37 | |
38 | 38 | <!-- Builder tab content --> |
39 | 39 | <div class="mt-4"> |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | <!-- Available builder elements --> |
42 | 42 | <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='new_item'"> |
43 | 43 | <div class="wpinv-form-builder-add-field-types"> |
44 | - <small class='form-text text-muted'><?php _e( 'Add an element by dragging it to the payment form.', 'invoicing' ); ?></small> |
|
44 | + <small class='form-text text-muted'><?php _e('Add an element by dragging it to the payment form.', 'invoicing'); ?></small> |
|
45 | 45 | <draggable class="section mt-2" style="display: flex; flex-flow: wrap; justify-content: space-between;" v-model="elements" :group="{ name: 'fields', pull: 'clone', put: false }" :sort="false" :clone="addDraggedField" tag="ul" filter=".wpinv-undraggable"> |
46 | 46 | <li v-for="element in elements" class= "wpinv-payment-form-left-fields-field" @click.prevent="addField(element)" :class="{ 'd-none': element.defaults.premade }"> |
47 | 47 | <button class="button btn text-dark"> |
@@ -56,18 +56,18 @@ discard block |
||
56 | 56 | <!-- Edit an element --> |
57 | 57 | <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='edit_item'" style="font-size: 14px;"> |
58 | 58 | <div class="wpinv-form-builder-edit-field-wrapper"> |
59 | - <?php do_action( 'wpinv_payment_form_edit_element_template', 'active_form_element', $post ); ?> |
|
60 | - <?php do_action( 'getpaid_payment_form_edit_element_template', $post ); ?> |
|
59 | + <?php do_action('wpinv_payment_form_edit_element_template', 'active_form_element', $post); ?> |
|
60 | + <?php do_action('getpaid_payment_form_edit_element_template', $post); ?> |
|
61 | 61 | <div class='form-group'> |
62 | - <label :for="active_form_element.id + '_grid_width'"><?php esc_html_e( 'Width', 'invoicing' ) ?></label> |
|
62 | + <label :for="active_form_element.id + '_grid_width'"><?php esc_html_e('Width', 'invoicing') ?></label> |
|
63 | 63 | <select class='form-control custom-select' :id="active_form_element.id + '_grid_width'" v-model='gridWidth'> |
64 | - <option value='full'><?php esc_html_e( 'Full Width', 'invoicing' ); ?></option> |
|
65 | - <option value='half'><?php esc_html_e( 'Half Width', 'invoicing' ); ?></option> |
|
66 | - <option value='third'><?php esc_html_e( '1/3 Width', 'invoicing' ); ?></option> |
|
64 | + <option value='full'><?php esc_html_e('Full Width', 'invoicing'); ?></option> |
|
65 | + <option value='half'><?php esc_html_e('Half Width', 'invoicing'); ?></option> |
|
66 | + <option value='third'><?php esc_html_e('1/3 Width', 'invoicing'); ?></option> |
|
67 | 67 | </select> |
68 | 68 | </div> |
69 | 69 | <div> |
70 | - <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e( 'Delete Element', 'invoicing' ); ?></button> |
|
70 | + <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e('Delete Element', 'invoicing'); ?></button> |
|
71 | 71 | </div> |
72 | 72 | </div> |
73 | 73 | </div> |
@@ -76,15 +76,15 @@ discard block |
||
76 | 76 | |
77 | 77 | </div> |
78 | 78 | <div class="col-sm-8 border-left"> |
79 | - <small class='form-text text-muted' v-if='form_elements.length'><?php _e( 'Click on any element to edit or delete it.', 'invoicing' ); ?></small> |
|
80 | - <p class='form-text text-muted' v-if='! form_elements.length'><?php _e( 'This form is empty. Add new elements by dragging them from the right.', 'invoicing' ); ?></p> |
|
79 | + <small class='form-text text-muted' v-if='form_elements.length'><?php _e('Click on any element to edit or delete it.', 'invoicing'); ?></small> |
|
80 | + <p class='form-text text-muted' v-if='! form_elements.length'><?php _e('This form is empty. Add new elements by dragging them from the right.', 'invoicing'); ?></p> |
|
81 | 81 | |
82 | 82 | <div class="container-fluid"> |
83 | 83 | <draggable class="section row" v-model="form_elements" @add="highlightLastDroppedField" group="fields" tag="div" style="min-height: 100%; font-size: 14px;"> |
84 | 84 | <div v-for="form_element in form_elements" class="wpinv-form-builder-element-preview" :class="[{ active: active_form_element==form_element && active_tab=='edit_item' }, form_element.type, grid_class( form_element ) ]" @click="active_tab = 'edit_item'; active_form_element = form_element"> |
85 | 85 | <div class="wpinv-form-builder-element-preview-inner"> |
86 | 86 | <div class="wpinv-payment-form-field-preview-overlay"></div> |
87 | - <?php do_action( 'wpinv_payment_form_render_element_template', 'form_element', $post ); ?> |
|
87 | + <?php do_action('wpinv_payment_form_render_element_template', 'form_element', $post); ?> |
|
88 | 88 | </div> |
89 | 89 | </div> |
90 | 90 | </draggable> |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | </div> |
99 | 99 | <?php |
100 | 100 | |
101 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
101 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -106,33 +106,33 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @param int $post_id |
108 | 108 | */ |
109 | - public static function save( $post_id ) { |
|
109 | + public static function save($post_id) { |
|
110 | 110 | |
111 | 111 | // Prepare the form. |
112 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
112 | + $form = new GetPaid_Payment_Form($post_id); |
|
113 | 113 | |
114 | 114 | // Fetch form items. |
115 | - $form_items = json_decode( wp_unslash( $_POST['wpinv_form_items'] ), true ); |
|
115 | + $form_items = json_decode(wp_unslash($_POST['wpinv_form_items']), true); |
|
116 | 116 | |
117 | 117 | // Ensure that we have an array... |
118 | - if ( empty( $form_items ) ) { |
|
118 | + if (empty($form_items)) { |
|
119 | 119 | $form_items = array(); |
120 | 120 | } |
121 | 121 | |
122 | 122 | // Add it to the form. |
123 | - $form->set_items( self::item_to_objects( wp_kses_post_deep( $form_items ) ) ); |
|
123 | + $form->set_items(self::item_to_objects(wp_kses_post_deep($form_items))); |
|
124 | 124 | |
125 | 125 | // Save form elements. |
126 | - $form_elements = json_decode( wp_unslash( $_POST['wpinv_form_elements'] ), true ); |
|
127 | - if ( empty( $form_elements ) ) { |
|
126 | + $form_elements = json_decode(wp_unslash($_POST['wpinv_form_elements']), true); |
|
127 | + if (empty($form_elements)) { |
|
128 | 128 | $form_elements = array(); |
129 | 129 | } |
130 | 130 | |
131 | - $form->set_elements( wp_kses_post_deep( $form_elements ) ); |
|
131 | + $form->set_elements(wp_kses_post_deep($form_elements)); |
|
132 | 132 | |
133 | 133 | // Persist data to the datastore. |
134 | 134 | $form->save(); |
135 | - do_action( 'getpaid_payment_form_metabox_save', $post_id, $form ); |
|
135 | + do_action('getpaid_payment_form_metabox_save', $post_id, $form); |
|
136 | 136 | |
137 | 137 | } |
138 | 138 | |
@@ -141,14 +141,14 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @param array $items |
143 | 143 | */ |
144 | - public static function item_to_objects( $items ) { |
|
144 | + public static function item_to_objects($items) { |
|
145 | 145 | |
146 | 146 | $objects = array(); |
147 | 147 | |
148 | - foreach ( $items as $item ) { |
|
149 | - $_item = new GetPaid_Form_Item( $item['id'] ); |
|
150 | - $_item->set_allow_quantities( (bool) $item['allow_quantities'] ); |
|
151 | - $_item->set_is_required( (bool) $item['required'] ); |
|
148 | + foreach ($items as $item) { |
|
149 | + $_item = new GetPaid_Form_Item($item['id']); |
|
150 | + $_item->set_allow_quantities((bool) $item['allow_quantities']); |
|
151 | + $_item->set_is_required((bool) $item['required']); |
|
152 | 152 | $objects[] = $_item; |
153 | 153 | } |
154 | 154 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Discount_Details { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the discount. |
@@ -368,34 +368,34 @@ discard block |
||
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
371 | - * Save meta box data. |
|
372 | - * |
|
373 | - * @param int $post_id |
|
374 | - */ |
|
375 | - public static function save( $post_id ) { |
|
371 | + * Save meta box data. |
|
372 | + * |
|
373 | + * @param int $post_id |
|
374 | + */ |
|
375 | + public static function save( $post_id ) { |
|
376 | 376 | |
377 | 377 | // Prepare the discount. |
378 | 378 | $discount = new WPInv_Discount( $post_id ); |
379 | 379 | |
380 | 380 | // Load new data. |
381 | 381 | $discount->set_props( |
382 | - array( |
|
383 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
384 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
385 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
382 | + array( |
|
383 | + 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
384 | + 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
385 | + 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | + 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | + 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
388 | 388 | 'type' => isset( $_POST['wpinv_discount_type'] ) ? wpinv_clean( $_POST['wpinv_discount_type'] ) : null, |
389 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
391 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
392 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
393 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
394 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
395 | - ) |
|
389 | + 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | + 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
391 | + 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
392 | + 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
393 | + 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
394 | + 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
395 | + ) |
|
396 | 396 | ); |
397 | 397 | |
398 | - $discount->save(); |
|
399 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
400 | - } |
|
398 | + $discount->save(); |
|
399 | + do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
400 | + } |
|
401 | 401 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,24 +21,24 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | |
26 | 26 | // Prepare the discount. |
27 | - $discount = new WPInv_Discount( $post ); |
|
27 | + $discount = new WPInv_Discount($post); |
|
28 | 28 | |
29 | 29 | // Nonce field. |
30 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
30 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
31 | 31 | |
32 | - do_action( 'wpinv_discount_form_top', $discount ); |
|
32 | + do_action('wpinv_discount_form_top', $discount); |
|
33 | 33 | |
34 | 34 | // Set the currency position. |
35 | 35 | $position = wpinv_currency_position(); |
36 | 36 | |
37 | - if ( $position == 'left_space' ) { |
|
37 | + if ($position == 'left_space') { |
|
38 | 38 | $position = 'left'; |
39 | 39 | } |
40 | 40 | |
41 | - if ( $position == 'right_space' ) { |
|
41 | + if ($position == 'right_space') { |
|
42 | 42 | $position = 'right'; |
43 | 43 | } |
44 | 44 | |
@@ -52,66 +52,66 @@ discard block |
||
52 | 52 | </style> |
53 | 53 | <div class='bsui' style='max-width: 600px;padding-top: 10px;'> |
54 | 54 | |
55 | - <?php do_action( 'wpinv_discount_form_first', $discount ); ?> |
|
55 | + <?php do_action('wpinv_discount_form_first', $discount); ?> |
|
56 | 56 | |
57 | - <?php do_action( 'wpinv_discount_form_before_code', $discount ); ?> |
|
57 | + <?php do_action('wpinv_discount_form_before_code', $discount); ?> |
|
58 | 58 | <div class="form-group row"> |
59 | 59 | <label for="wpinv_discount_code" class="col-sm-3 col-form-label"> |
60 | - <?php _e( 'Discount Code', 'invoicing' );?> |
|
60 | + <?php _e('Discount Code', 'invoicing'); ?> |
|
61 | 61 | </label> |
62 | 62 | <div class="col-sm-8"> |
63 | 63 | <div class="row"> |
64 | 64 | <div class="col-sm-12 form-group"> |
65 | - <input type="text" value="<?php echo esc_attr( $discount->get_code( 'edit' ) ); ?>" placeholder="SUMMER_SALE" name="wpinv_discount_code" id="wpinv_discount_code" style="width: 100%;" /> |
|
65 | + <input type="text" value="<?php echo esc_attr($discount->get_code('edit')); ?>" placeholder="SUMMER_SALE" name="wpinv_discount_code" id="wpinv_discount_code" style="width: 100%;" /> |
|
66 | 66 | </div> |
67 | 67 | <div class="col-sm-12"> |
68 | 68 | <?php |
69 | - do_action( 'wpinv_discount_form_before_single_use', $discount ); |
|
69 | + do_action('wpinv_discount_form_before_single_use', $discount); |
|
70 | 70 | |
71 | 71 | echo aui()->input( |
72 | 72 | array( |
73 | 73 | 'id' => 'wpinv_discount_single_use', |
74 | 74 | 'name' => 'wpinv_discount_single_use', |
75 | 75 | 'type' => 'checkbox', |
76 | - 'label' => __( 'Each customer can only use this discount once', 'invoicing' ), |
|
76 | + 'label' => __('Each customer can only use this discount once', 'invoicing'), |
|
77 | 77 | 'value' => '1', |
78 | 78 | 'checked' => $discount->is_single_use(), |
79 | 79 | ) |
80 | 80 | ); |
81 | 81 | |
82 | - do_action( 'wpinv_discount_form_single_use', $discount ); |
|
82 | + do_action('wpinv_discount_form_single_use', $discount); |
|
83 | 83 | ?> |
84 | 84 | </div> |
85 | 85 | <div class="col-sm-12"> |
86 | 86 | <?php |
87 | - do_action( 'wpinv_discount_form_before_recurring', $discount ); |
|
87 | + do_action('wpinv_discount_form_before_recurring', $discount); |
|
88 | 88 | |
89 | 89 | echo aui()->input( |
90 | 90 | array( |
91 | 91 | 'id' => 'wpinv_discount_recurring', |
92 | 92 | 'name' => 'wpinv_discount_recurring', |
93 | 93 | 'type' => 'checkbox', |
94 | - 'label' => __( 'Apply this discount to all recurring payments for subscriptions', 'invoicing' ), |
|
94 | + 'label' => __('Apply this discount to all recurring payments for subscriptions', 'invoicing'), |
|
95 | 95 | 'value' => '1', |
96 | 96 | 'checked' => $discount->is_recurring(), |
97 | 97 | ) |
98 | 98 | ); |
99 | 99 | |
100 | - do_action( 'wpinv_discount_form_recurring', $discount ); |
|
100 | + do_action('wpinv_discount_form_recurring', $discount); |
|
101 | 101 | ?> |
102 | 102 | </div> |
103 | 103 | </div> |
104 | 104 | </div> |
105 | 105 | <div class="col-sm-1 pt-2 pl-0"> |
106 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter a discount code such as 10OFF.', 'invoicing' ); ?>"></span> |
|
106 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter a discount code such as 10OFF.', 'invoicing'); ?>"></span> |
|
107 | 107 | </div> |
108 | 108 | </div> |
109 | - <?php do_action( 'wpinv_discount_form_code', $discount ); ?> |
|
109 | + <?php do_action('wpinv_discount_form_code', $discount); ?> |
|
110 | 110 | |
111 | - <?php do_action( 'wpinv_discount_form_before_type', $discount ); ?> |
|
111 | + <?php do_action('wpinv_discount_form_before_type', $discount); ?> |
|
112 | 112 | <div class="form-group row"> |
113 | 113 | <label for="wpinv_discount_type" class="col-sm-3 col-form-label"> |
114 | - <?php _e( 'Discount Type', 'invoicing' );?> |
|
114 | + <?php _e('Discount Type', 'invoicing'); ?> |
|
115 | 115 | </label> |
116 | 116 | <div class="col-sm-8"> |
117 | 117 | <?php |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | array( |
120 | 120 | 'id' => 'wpinv_discount_type', |
121 | 121 | 'name' => 'wpinv_discount_type', |
122 | - 'label' => __( 'Discount Type', 'invoicing' ), |
|
123 | - 'placeholder' => __( 'Select Discount Type', 'invoicing' ), |
|
124 | - 'value' => $discount->get_type( 'edit' ), |
|
122 | + 'label' => __('Discount Type', 'invoicing'), |
|
123 | + 'placeholder' => __('Select Discount Type', 'invoicing'), |
|
124 | + 'value' => $discount->get_type('edit'), |
|
125 | 125 | 'select2' => true, |
126 | 126 | 'data-allow-clear' => 'false', |
127 | 127 | 'options' => wpinv_get_discount_types() |
@@ -130,19 +130,19 @@ discard block |
||
130 | 130 | ?> |
131 | 131 | </div> |
132 | 132 | <div class="col-sm-1 pt-2 pl-0"> |
133 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Discount type.', 'invoicing' ); ?>"></span> |
|
133 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Discount type.', 'invoicing'); ?>"></span> |
|
134 | 134 | </div> |
135 | 135 | </div> |
136 | - <?php do_action( 'wpinv_discount_form_type', $discount ); ?> |
|
136 | + <?php do_action('wpinv_discount_form_type', $discount); ?> |
|
137 | 137 | |
138 | - <?php do_action( 'wpinv_discount_form_before_amount', $discount ); ?> |
|
139 | - <div class="form-group row <?php echo esc_attr( $discount->get_type( 'edit' ) ); ?>" id="wpinv_discount_amount_wrap"> |
|
138 | + <?php do_action('wpinv_discount_form_before_amount', $discount); ?> |
|
139 | + <div class="form-group row <?php echo esc_attr($discount->get_type('edit')); ?>" id="wpinv_discount_amount_wrap"> |
|
140 | 140 | <label for="wpinv_discount_amount" class="col-sm-3 col-form-label"> |
141 | - <?php _e( 'Discount Amount', 'invoicing' );?> |
|
141 | + <?php _e('Discount Amount', 'invoicing'); ?> |
|
142 | 142 | </label> |
143 | 143 | <div class="col-sm-8"> |
144 | 144 | <div class="input-group input-group-sm"> |
145 | - <?php if( 'left' == $position ) : ?> |
|
145 | + <?php if ('left' == $position) : ?> |
|
146 | 146 | <div class="input-group-prepend left wpinv-if-flat"> |
147 | 147 | <span class="input-group-text"> |
148 | 148 | <?php echo wpinv_currency_symbol(); ?> |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | </div> |
151 | 151 | <?php endif; ?> |
152 | 152 | |
153 | - <input type="text" name="wpinv_discount_amount" id="wpinv_discount_amount" value="<?php echo esc_attr( $discount->get_amount( 'edit' ) ); ?>" placeholder="0" class="form-control"> |
|
153 | + <input type="text" name="wpinv_discount_amount" id="wpinv_discount_amount" value="<?php echo esc_attr($discount->get_amount('edit')); ?>" placeholder="0" class="form-control"> |
|
154 | 154 | |
155 | - <?php if( 'right' == $position ) : ?> |
|
155 | + <?php if ('right' == $position) : ?> |
|
156 | 156 | <div class="input-group-prepend left wpinv-if-flat"> |
157 | 157 | <span class="input-group-text"> |
158 | 158 | <?php echo wpinv_currency_symbol(); ?> |
@@ -165,15 +165,15 @@ discard block |
||
165 | 165 | </div> |
166 | 166 | </div> |
167 | 167 | <div class="col-sm-1 pt-2 pl-0"> |
168 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?>"></span> |
|
168 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter the discount value. Ex: 10', 'invoicing'); ?>"></span> |
|
169 | 169 | </div> |
170 | 170 | </div> |
171 | - <?php do_action( 'wpinv_discount_form_amount', $discount ); ?> |
|
171 | + <?php do_action('wpinv_discount_form_amount', $discount); ?> |
|
172 | 172 | |
173 | - <?php do_action( 'wpinv_discount_form_before_items', $discount ); ?> |
|
173 | + <?php do_action('wpinv_discount_form_before_items', $discount); ?> |
|
174 | 174 | <div class="form-group row"> |
175 | 175 | <label for="wpinv_discount_items" class="col-sm-3 col-form-label"> |
176 | - <?php _e( 'Items', 'invoicing' );?> |
|
176 | + <?php _e('Items', 'invoicing'); ?> |
|
177 | 177 | </label> |
178 | 178 | <div class="col-sm-8"> |
179 | 179 | <?php |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | array( |
182 | 182 | 'id' => 'wpinv_discount_items', |
183 | 183 | 'name' => 'wpinv_discount_items[]', |
184 | - 'label' => __( 'Items', 'invoicing' ), |
|
185 | - 'placeholder' => __( 'Select Items', 'invoicing' ), |
|
186 | - 'value' => $discount->get_items( 'edit' ), |
|
184 | + 'label' => __('Items', 'invoicing'), |
|
185 | + 'placeholder' => __('Select Items', 'invoicing'), |
|
186 | + 'value' => $discount->get_items('edit'), |
|
187 | 187 | 'select2' => true, |
188 | 188 | 'multiple' => true, |
189 | 189 | 'data-allow-clear' => 'false', |
@@ -193,15 +193,15 @@ discard block |
||
193 | 193 | ?> |
194 | 194 | </div> |
195 | 195 | <div class="col-sm-1 pt-2 pl-0"> |
196 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select the items that are allowed to use this discount or leave blank to use this discount all items.', 'invoicing' ); ?>"></span> |
|
196 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select the items that are allowed to use this discount or leave blank to use this discount all items.', 'invoicing'); ?>"></span> |
|
197 | 197 | </div> |
198 | 198 | </div> |
199 | - <?php do_action( 'wpinv_discount_form_items', $discount ); ?> |
|
199 | + <?php do_action('wpinv_discount_form_items', $discount); ?> |
|
200 | 200 | |
201 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $discount ); ?> |
|
201 | + <?php do_action('wpinv_discount_form_before_excluded_items', $discount); ?> |
|
202 | 202 | <div class="form-group row"> |
203 | 203 | <label for="wpinv_discount_excluded_items" class="col-sm-3 col-form-label"> |
204 | - <?php _e( 'Excluded Items', 'invoicing' );?> |
|
204 | + <?php _e('Excluded Items', 'invoicing'); ?> |
|
205 | 205 | </label> |
206 | 206 | <div class="col-sm-8"> |
207 | 207 | <?php |
@@ -209,9 +209,9 @@ discard block |
||
209 | 209 | array( |
210 | 210 | 'id' => 'wpinv_discount_excluded_items', |
211 | 211 | 'name' => 'wpinv_discount_excluded_items[]', |
212 | - 'label' => __( 'Excluded Items', 'invoicing' ), |
|
213 | - 'placeholder' => __( 'Select Items', 'invoicing' ), |
|
214 | - 'value' => $discount->get_excluded_items( 'edit' ), |
|
212 | + 'label' => __('Excluded Items', 'invoicing'), |
|
213 | + 'placeholder' => __('Select Items', 'invoicing'), |
|
214 | + 'value' => $discount->get_excluded_items('edit'), |
|
215 | 215 | 'select2' => true, |
216 | 216 | 'multiple' => true, |
217 | 217 | 'data-allow-clear' => 'false', |
@@ -221,15 +221,15 @@ discard block |
||
221 | 221 | ?> |
222 | 222 | </div> |
223 | 223 | <div class="col-sm-1 pt-2 pl-0"> |
224 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select all the items that are not allowed to use this discount.', 'invoicing' ); ?>"></span> |
|
224 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select all the items that are not allowed to use this discount.', 'invoicing'); ?>"></span> |
|
225 | 225 | </div> |
226 | 226 | </div> |
227 | - <?php do_action( 'wpinv_discount_form_excluded_items', $discount ); ?> |
|
227 | + <?php do_action('wpinv_discount_form_excluded_items', $discount); ?> |
|
228 | 228 | |
229 | - <?php do_action( 'wpinv_discount_form_before_start', $discount ); ?> |
|
229 | + <?php do_action('wpinv_discount_form_before_start', $discount); ?> |
|
230 | 230 | <div class="form-group row"> |
231 | 231 | <label for="wpinv_discount_start" class="col-sm-3 col-form-label"> |
232 | - <?php _e( 'Start Date', 'invoicing' );?> |
|
232 | + <?php _e('Start Date', 'invoicing'); ?> |
|
233 | 233 | </label> |
234 | 234 | <div class="col-sm-8"> |
235 | 235 | <?php |
@@ -238,10 +238,10 @@ discard block |
||
238 | 238 | 'type' => 'datepicker', |
239 | 239 | 'id' => 'wpinv_discount_start', |
240 | 240 | 'name' => 'wpinv_discount_start', |
241 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
241 | + 'label' => __('Start Date', 'invoicing'), |
|
242 | 242 | 'placeholder' => 'YYYY-MM-DD 00:00', |
243 | 243 | 'class' => 'form-control-sm', |
244 | - 'value' => $discount->get_start_date( 'edit' ), |
|
244 | + 'value' => $discount->get_start_date('edit'), |
|
245 | 245 | 'extra_attributes' => array( |
246 | 246 | 'data-enable-time' => 'true', |
247 | 247 | 'data-time_24hr' => 'true', |
@@ -252,15 +252,15 @@ discard block |
||
252 | 252 | ?> |
253 | 253 | </div> |
254 | 254 | <div class="col-sm-1 pt-2 pl-0"> |
255 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?>"></span> |
|
255 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?>"></span> |
|
256 | 256 | </div> |
257 | 257 | </div> |
258 | - <?php do_action( 'wpinv_discount_form_start', $discount ); ?> |
|
258 | + <?php do_action('wpinv_discount_form_start', $discount); ?> |
|
259 | 259 | |
260 | - <?php do_action( 'wpinv_discount_form_before_expiration', $discount ); ?> |
|
260 | + <?php do_action('wpinv_discount_form_before_expiration', $discount); ?> |
|
261 | 261 | <div class="form-group row"> |
262 | 262 | <label for="wpinv_discount_expiration" class="col-sm-3 col-form-label"> |
263 | - <?php _e( 'Expiration Date', 'invoicing' );?> |
|
263 | + <?php _e('Expiration Date', 'invoicing'); ?> |
|
264 | 264 | </label> |
265 | 265 | <div class="col-sm-8"> |
266 | 266 | <?php |
@@ -269,10 +269,10 @@ discard block |
||
269 | 269 | 'type' => 'datepicker', |
270 | 270 | 'id' => 'wpinv_discount_expiration', |
271 | 271 | 'name' => 'wpinv_discount_expiration', |
272 | - 'label' => __( 'Expiration Date', 'invoicing' ), |
|
272 | + 'label' => __('Expiration Date', 'invoicing'), |
|
273 | 273 | 'placeholder' => 'YYYY-MM-DD 00:00', |
274 | 274 | 'class' => 'form-control-sm', |
275 | - 'value' => $discount->get_end_date( 'edit' ), |
|
275 | + 'value' => $discount->get_end_date('edit'), |
|
276 | 276 | 'extra_attributes' => array( |
277 | 277 | 'data-enable-time' => 'true', |
278 | 278 | 'data-time_24hr' => 'true', |
@@ -285,27 +285,27 @@ discard block |
||
285 | 285 | ?> |
286 | 286 | </div> |
287 | 287 | <div class="col-sm-1 pt-2 pl-0"> |
288 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the date after which the discount will expire.', 'invoicing' ); ?>"></span> |
|
288 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the date after which the discount will expire.', 'invoicing'); ?>"></span> |
|
289 | 289 | </div> |
290 | 290 | </div> |
291 | - <?php do_action( 'wpinv_discount_form_expiration', $discount ); ?> |
|
291 | + <?php do_action('wpinv_discount_form_expiration', $discount); ?> |
|
292 | 292 | |
293 | - <?php do_action( 'wpinv_discount_form_before_min_total', $discount ); ?> |
|
293 | + <?php do_action('wpinv_discount_form_before_min_total', $discount); ?> |
|
294 | 294 | <div class="form-group row"> |
295 | 295 | <label for="wpinv_discount_min_total" class="col-sm-3 col-form-label"> |
296 | - <?php _e( 'Minimum Amount', 'invoicing' );?> |
|
296 | + <?php _e('Minimum Amount', 'invoicing'); ?> |
|
297 | 297 | </label> |
298 | 298 | <div class="col-sm-8"> |
299 | 299 | <div class="input-group input-group-sm"> |
300 | - <?php if( 'left' == $position ) : ?> |
|
300 | + <?php if ('left' == $position) : ?> |
|
301 | 301 | <div class="input-group-prepend"> |
302 | 302 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
303 | 303 | </div> |
304 | 304 | <?php endif; ?> |
305 | 305 | |
306 | - <input type="text" name="wpinv_discount_min_total" id="wpinv_discount_min_total" value="<?php echo esc_attr( $discount->get_minimum_total( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'No minimum', 'invoicing' ); ?>" class="form-control"> |
|
306 | + <input type="text" name="wpinv_discount_min_total" id="wpinv_discount_min_total" value="<?php echo esc_attr($discount->get_minimum_total('edit')); ?>" placeholder="<?php esc_attr_e('No minimum', 'invoicing'); ?>" class="form-control"> |
|
307 | 307 | |
308 | - <?php if( 'left' != $position ) : ?> |
|
308 | + <?php if ('left' != $position) : ?> |
|
309 | 309 | <div class="input-group-append"> |
310 | 310 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
311 | 311 | </div> |
@@ -313,27 +313,27 @@ discard block |
||
313 | 313 | </div> |
314 | 314 | </div> |
315 | 315 | <div class="col-sm-1 pt-2 pl-0"> |
316 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the minimum amount (including taxes) required to use this discount.', 'invoicing' ); ?>"></span> |
|
316 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the minimum amount (including taxes) required to use this discount.', 'invoicing'); ?>"></span> |
|
317 | 317 | </div> |
318 | 318 | </div> |
319 | - <?php do_action( 'wpinv_discount_form_min_total', $discount ); ?> |
|
319 | + <?php do_action('wpinv_discount_form_min_total', $discount); ?> |
|
320 | 320 | |
321 | - <?php do_action( 'wpinv_discount_form_before_max_total', $discount ); ?> |
|
321 | + <?php do_action('wpinv_discount_form_before_max_total', $discount); ?> |
|
322 | 322 | <div class="form-group row"> |
323 | 323 | <label for="wpinv_discount_max_total" class="col-sm-3 col-form-label"> |
324 | - <?php _e( 'Maximum Amount', 'invoicing' );?> |
|
324 | + <?php _e('Maximum Amount', 'invoicing'); ?> |
|
325 | 325 | </label> |
326 | 326 | <div class="col-sm-8"> |
327 | 327 | <div class="input-group input-group-sm"> |
328 | - <?php if( 'left' == $position ) : ?> |
|
328 | + <?php if ('left' == $position) : ?> |
|
329 | 329 | <div class="input-group-prepend"> |
330 | 330 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
331 | 331 | </div> |
332 | 332 | <?php endif; ?> |
333 | 333 | |
334 | - <input type="text" name="wpinv_discount_max_total" id="wpinv_discount_max_total" value="<?php echo esc_attr( $discount->get_maximum_total( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'No maximum', 'invoicing' ); ?>" class="form-control"> |
|
334 | + <input type="text" name="wpinv_discount_max_total" id="wpinv_discount_max_total" value="<?php echo esc_attr($discount->get_maximum_total('edit')); ?>" placeholder="<?php esc_attr_e('No maximum', 'invoicing'); ?>" class="form-control"> |
|
335 | 335 | |
336 | - <?php if( 'left' != $position ) : ?> |
|
336 | + <?php if ('left' != $position) : ?> |
|
337 | 337 | <div class="input-group-append"> |
338 | 338 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
339 | 339 | </div> |
@@ -341,30 +341,30 @@ discard block |
||
341 | 341 | </div> |
342 | 342 | </div> |
343 | 343 | <div class="col-sm-1 pt-2 pl-0"> |
344 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the maximum amount (including taxes) allowed when using this discount.', 'invoicing' ); ?>"></span> |
|
344 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the maximum amount (including taxes) allowed when using this discount.', 'invoicing'); ?>"></span> |
|
345 | 345 | </div> |
346 | 346 | </div> |
347 | - <?php do_action( 'wpinv_discount_form_before_max_total', $discount ); ?> |
|
347 | + <?php do_action('wpinv_discount_form_before_max_total', $discount); ?> |
|
348 | 348 | |
349 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $discount ); ?> |
|
349 | + <?php do_action('wpinv_discount_form_before_max_uses', $discount); ?> |
|
350 | 350 | <div class="form-group row"> |
351 | 351 | <label for="wpinv_discount_max_uses" class="col-sm-3 col-form-label"> |
352 | - <?php _e( 'Maximum Uses', 'invoicing' );?> |
|
352 | + <?php _e('Maximum Uses', 'invoicing'); ?> |
|
353 | 353 | </label> |
354 | 354 | <div class="col-sm-8"> |
355 | - <input type="text" value="<?php echo esc_attr( $discount->get_max_uses( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'Unlimited', 'invoicing' ); ?>" name="wpinv_discount_max_uses" id="wpinv_discount_max_uses" style="width: 100%;" /> |
|
355 | + <input type="text" value="<?php echo esc_attr($discount->get_max_uses('edit')); ?>" placeholder="<?php esc_attr_e('Unlimited', 'invoicing'); ?>" name="wpinv_discount_max_uses" id="wpinv_discount_max_uses" style="width: 100%;" /> |
|
356 | 356 | </div> |
357 | 357 | <div class="col-sm-1 pt-2 pl-0"> |
358 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the maximum number of times that this discount code can be used.', 'invoicing' ); ?>"></span> |
|
358 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the maximum number of times that this discount code can be used.', 'invoicing'); ?>"></span> |
|
359 | 359 | </div> |
360 | 360 | </div> |
361 | - <?php do_action( 'wpinv_discount_form_max_uses', $discount ); ?> |
|
361 | + <?php do_action('wpinv_discount_form_max_uses', $discount); ?> |
|
362 | 362 | |
363 | - <?php do_action( 'wpinv_discount_form_last', $discount ); ?> |
|
363 | + <?php do_action('wpinv_discount_form_last', $discount); ?> |
|
364 | 364 | |
365 | 365 | </div> |
366 | 366 | <?php |
367 | - do_action( 'wpinv_discount_form_bottom', $post ); |
|
367 | + do_action('wpinv_discount_form_bottom', $post); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -372,30 +372,30 @@ discard block |
||
372 | 372 | * |
373 | 373 | * @param int $post_id |
374 | 374 | */ |
375 | - public static function save( $post_id ) { |
|
375 | + public static function save($post_id) { |
|
376 | 376 | |
377 | 377 | // Prepare the discount. |
378 | - $discount = new WPInv_Discount( $post_id ); |
|
378 | + $discount = new WPInv_Discount($post_id); |
|
379 | 379 | |
380 | 380 | // Load new data. |
381 | 381 | $discount->set_props( |
382 | 382 | array( |
383 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
384 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
385 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
388 | - 'type' => isset( $_POST['wpinv_discount_type'] ) ? wpinv_clean( $_POST['wpinv_discount_type'] ) : null, |
|
389 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
391 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
392 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
393 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
394 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
383 | + 'code' => isset($_POST['wpinv_discount_code']) ? wpinv_clean($_POST['wpinv_discount_code']) : null, |
|
384 | + 'amount' => isset($_POST['wpinv_discount_amount']) ? floatval($_POST['wpinv_discount_amount']) : null, |
|
385 | + 'start' => isset($_POST['wpinv_discount_start']) ? wpinv_clean($_POST['wpinv_discount_start']) : null, |
|
386 | + 'expiration' => isset($_POST['wpinv_discount_expiration']) ? wpinv_clean($_POST['wpinv_discount_expiration']) : null, |
|
387 | + 'is_single_use' => isset($_POST['wpinv_discount_single_use']), |
|
388 | + 'type' => isset($_POST['wpinv_discount_type']) ? wpinv_clean($_POST['wpinv_discount_type']) : null, |
|
389 | + 'is_recurring' => isset($_POST['wpinv_discount_recurring']), |
|
390 | + 'items' => isset($_POST['wpinv_discount_items']) ? wpinv_clean($_POST['wpinv_discount_items']) : array(), |
|
391 | + 'excluded_items' => isset($_POST['wpinv_discount_excluded_items']) ? wpinv_clean($_POST['wpinv_discount_excluded_items']) : array(), |
|
392 | + 'max_uses' => isset($_POST['wpinv_discount_max_uses']) ? intval($_POST['wpinv_discount_max_uses']) : null, |
|
393 | + 'min_total' => isset($_POST['wpinv_discount_min_total']) ? floatval($_POST['wpinv_discount_min_total']) : null, |
|
394 | + 'max_total' => isset($_POST['wpinv_discount_max_total']) ? floatval($_POST['wpinv_discount_max_total']) : null, |
|
395 | 395 | ) |
396 | 396 | ); |
397 | 397 | |
398 | 398 | $discount->save(); |
399 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
399 | + do_action('getpaid_discount_metabox_save', $post_id, $discount); |
|
400 | 400 | } |
401 | 401 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 1.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Retrieves all default settings. |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | function wpinv_get_settings() { |
17 | 17 | $defaults = array(); |
18 | 18 | |
19 | - foreach ( array_values( wpinv_get_registered_settings() ) as $tab_settings ) { |
|
19 | + foreach (array_values(wpinv_get_registered_settings()) as $tab_settings) { |
|
20 | 20 | |
21 | - foreach ( array_values( $tab_settings ) as $section_settings ) { |
|
21 | + foreach (array_values($tab_settings) as $section_settings) { |
|
22 | 22 | |
23 | - foreach ( $section_settings as $key => $setting ) { |
|
24 | - if ( isset( $setting['std'] ) ) { |
|
25 | - $defaults[ $key ] = $setting['std']; |
|
23 | + foreach ($section_settings as $key => $setting) { |
|
24 | + if (isset($setting['std'])) { |
|
25 | + $defaults[$key] = $setting['std']; |
|
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
@@ -43,12 +43,12 @@ discard block |
||
43 | 43 | global $wpinv_options; |
44 | 44 | |
45 | 45 | // Try fetching the saved options. |
46 | - if ( empty( $wpinv_options ) ) { |
|
47 | - $wpinv_options = get_option( 'wpinv_settings' ); |
|
46 | + if (empty($wpinv_options)) { |
|
47 | + $wpinv_options = get_option('wpinv_settings'); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | // If that fails, don't fetch the default settings to prevent a loop. |
51 | - if ( ! is_array( $wpinv_options ) ) { |
|
51 | + if (!is_array($wpinv_options)) { |
|
52 | 52 | $wpinv_options = array(); |
53 | 53 | } |
54 | 54 | |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | * @param mixed $default The default value to use if the setting has not been set. |
63 | 63 | * @return mixed |
64 | 64 | */ |
65 | -function wpinv_get_option( $key = '', $default = false ) { |
|
65 | +function wpinv_get_option($key = '', $default = false) { |
|
66 | 66 | |
67 | 67 | $options = wpinv_get_options(); |
68 | - $value = isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
69 | - $value = apply_filters( 'wpinv_get_option', $value, $key, $default ); |
|
68 | + $value = isset($options[$key]) ? $options[$key] : $default; |
|
69 | + $value = apply_filters('wpinv_get_option', $value, $key, $default); |
|
70 | 70 | |
71 | - return apply_filters( 'wpinv_get_option_' . $key, $value, $key, $default ); |
|
71 | + return apply_filters('wpinv_get_option_' . $key, $value, $key, $default); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,11 +77,11 @@ discard block |
||
77 | 77 | * @param array $options the new options. |
78 | 78 | * @return bool |
79 | 79 | */ |
80 | -function wpinv_update_options( $options ) { |
|
80 | +function wpinv_update_options($options) { |
|
81 | 81 | global $wpinv_options; |
82 | 82 | |
83 | 83 | // update the option. |
84 | - if ( is_array( $options ) && update_option( 'wpinv_settings', $options ) ) { |
|
84 | + if (is_array($options) && update_option('wpinv_settings', $options)) { |
|
85 | 85 | $wpinv_options = $options; |
86 | 86 | return true; |
87 | 87 | } |
@@ -96,24 +96,24 @@ discard block |
||
96 | 96 | * @param mixed $value The setting value. |
97 | 97 | * @return bool |
98 | 98 | */ |
99 | -function wpinv_update_option( $key = '', $value = false ) { |
|
99 | +function wpinv_update_option($key = '', $value = false) { |
|
100 | 100 | |
101 | 101 | // If no key, exit. |
102 | - if ( empty( $key ) ) { |
|
102 | + if (empty($key)) { |
|
103 | 103 | return false; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Maybe delete the option instead. |
107 | - if ( is_null( $value ) ) { |
|
108 | - return wpinv_delete_option( $key ); |
|
107 | + if (is_null($value)) { |
|
108 | + return wpinv_delete_option($key); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | // Prepare the new options. |
112 | 112 | $options = wpinv_get_options(); |
113 | - $options[ $key ] = apply_filters( 'wpinv_update_option', $value, $key ); |
|
113 | + $options[$key] = apply_filters('wpinv_update_option', $value, $key); |
|
114 | 114 | |
115 | 115 | // Save the new options. |
116 | - return wpinv_update_options( $options ); |
|
116 | + return wpinv_update_options($options); |
|
117 | 117 | |
118 | 118 | } |
119 | 119 | |
@@ -123,18 +123,18 @@ discard block |
||
123 | 123 | * @param string $key the setting key. |
124 | 124 | * @return bool |
125 | 125 | */ |
126 | -function wpinv_delete_option( $key = '' ) { |
|
126 | +function wpinv_delete_option($key = '') { |
|
127 | 127 | |
128 | 128 | // If no key, exit |
129 | - if ( empty( $key ) ) { |
|
129 | + if (empty($key)) { |
|
130 | 130 | return false; |
131 | 131 | } |
132 | 132 | |
133 | 133 | $options = wpinv_get_options(); |
134 | 134 | |
135 | - if ( isset( $options[ $key ] ) ) { |
|
136 | - unset( $options[ $key ] ); |
|
137 | - return wpinv_update_options( $options ); |
|
135 | + if (isset($options[$key])) { |
|
136 | + unset($options[$key]); |
|
137 | + return wpinv_update_options($options); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | return true; |
@@ -148,14 +148,14 @@ discard block |
||
148 | 148 | function wpinv_register_settings() { |
149 | 149 | |
150 | 150 | // Loop through all tabs. |
151 | - foreach ( wpinv_get_registered_settings() as $tab => $sections ) { |
|
151 | + foreach (wpinv_get_registered_settings() as $tab => $sections) { |
|
152 | 152 | |
153 | 153 | // In each tab, loop through sections. |
154 | - foreach ( $sections as $section => $settings ) { |
|
154 | + foreach ($sections as $section => $settings) { |
|
155 | 155 | |
156 | 156 | // Check for backwards compatibility |
157 | - $section_tabs = wpinv_get_settings_tab_sections( $tab ); |
|
158 | - if ( ! is_array( $section_tabs ) || ! array_key_exists( $section, $section_tabs ) ) { |
|
157 | + $section_tabs = wpinv_get_settings_tab_sections($tab); |
|
158 | + if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) { |
|
159 | 159 | $section = 'main'; |
160 | 160 | $settings = $sections; |
161 | 161 | } |
@@ -168,9 +168,9 @@ discard block |
||
168 | 168 | 'wpinv_settings_' . $tab . '_' . $section |
169 | 169 | ); |
170 | 170 | |
171 | - foreach ( $settings as $option ) { |
|
172 | - if ( ! empty( $option['id'] ) ) { |
|
173 | - wpinv_register_settings_option( $tab, $section, $option ); |
|
171 | + foreach ($settings as $option) { |
|
172 | + if (!empty($option['id'])) { |
|
173 | + wpinv_register_settings_option($tab, $section, $option); |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | |
@@ -178,9 +178,9 @@ discard block |
||
178 | 178 | } |
179 | 179 | |
180 | 180 | // Creates our settings in the options table. |
181 | - register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' ); |
|
181 | + register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize'); |
|
182 | 182 | } |
183 | -add_action( 'admin_init', 'wpinv_register_settings' ); |
|
183 | +add_action('admin_init', 'wpinv_register_settings'); |
|
184 | 184 | |
185 | 185 | /** |
186 | 186 | * Register a single settings option. |
@@ -190,49 +190,49 @@ discard block |
||
190 | 190 | * @param string $option |
191 | 191 | * |
192 | 192 | */ |
193 | -function wpinv_register_settings_option( $tab, $section, $option ) { |
|
193 | +function wpinv_register_settings_option($tab, $section, $option) { |
|
194 | 194 | |
195 | - $name = isset( $option['name'] ) ? $option['name'] : ''; |
|
195 | + $name = isset($option['name']) ? $option['name'] : ''; |
|
196 | 196 | $cb = "wpinv_{$option['type']}_callback"; |
197 | 197 | $section = "wpinv_settings_{$tab}_$section"; |
198 | - $is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page']; |
|
198 | + $is_wizzard = is_admin() && isset($_GET['page']) && 'gp-setup' == $_GET['page']; |
|
199 | 199 | |
200 | - if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) { |
|
201 | - $tip = wpinv_clean( $option['desc'] ); |
|
200 | + if (isset($option['desc']) && (!$is_wizzard && !empty($option['help-tip']))) { |
|
201 | + $tip = wpinv_clean($option['desc']); |
|
202 | 202 | $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
203 | - unset( $option['desc'] ); |
|
203 | + unset($option['desc']); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | // Loop through all tabs. |
207 | 207 | add_settings_field( |
208 | 208 | 'wpinv_settings[' . $option['id'] . ']', |
209 | 209 | $name, |
210 | - function_exists( $cb ) ? $cb : 'wpinv_missing_callback', |
|
210 | + function_exists($cb) ? $cb : 'wpinv_missing_callback', |
|
211 | 211 | $section, |
212 | 212 | $section, |
213 | 213 | array( |
214 | 214 | 'section' => $section, |
215 | - 'id' => isset( $option['id'] ) ? $option['id'] : uniqid( 'wpinv-' ), |
|
216 | - 'desc' => isset( $option['desc'] ) ? $option['desc'] : '', |
|
215 | + 'id' => isset($option['id']) ? $option['id'] : uniqid('wpinv-'), |
|
216 | + 'desc' => isset($option['desc']) ? $option['desc'] : '', |
|
217 | 217 | 'name' => $name, |
218 | - 'size' => isset( $option['size'] ) ? $option['size'] : null, |
|
219 | - 'options' => isset( $option['options'] ) ? $option['options'] : '', |
|
220 | - 'selected' => isset( $option['selected'] ) ? $option['selected'] : null, |
|
221 | - 'std' => isset( $option['std'] ) ? $option['std'] : '', |
|
222 | - 'min' => isset( $option['min'] ) ? $option['min'] : 0, |
|
223 | - 'max' => isset( $option['max'] ) ? $option['max'] : 999999, |
|
224 | - 'step' => isset( $option['step'] ) ? $option['step'] : 1, |
|
225 | - 'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null, |
|
226 | - 'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true, |
|
227 | - 'readonly' => isset( $option['readonly'] ) ? $option['readonly'] : false, |
|
228 | - 'faux' => isset( $option['faux'] ) ? $option['faux'] : false, |
|
229 | - 'onchange' => isset( $option['onchange'] ) ? $option['onchange'] : '', |
|
230 | - 'custom' => isset( $option['custom'] ) ? $option['custom'] : '', |
|
231 | - 'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '', |
|
232 | - 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
233 | - 'style' => isset( $option['style'] ) ? $option['style'] : '', |
|
234 | - 'cols' => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
|
235 | - 'rows' => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
|
218 | + 'size' => isset($option['size']) ? $option['size'] : null, |
|
219 | + 'options' => isset($option['options']) ? $option['options'] : '', |
|
220 | + 'selected' => isset($option['selected']) ? $option['selected'] : null, |
|
221 | + 'std' => isset($option['std']) ? $option['std'] : '', |
|
222 | + 'min' => isset($option['min']) ? $option['min'] : 0, |
|
223 | + 'max' => isset($option['max']) ? $option['max'] : 999999, |
|
224 | + 'step' => isset($option['step']) ? $option['step'] : 1, |
|
225 | + 'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : null, |
|
226 | + 'allow_blank' => isset($option['allow_blank']) ? $option['allow_blank'] : true, |
|
227 | + 'readonly' => isset($option['readonly']) ? $option['readonly'] : false, |
|
228 | + 'faux' => isset($option['faux']) ? $option['faux'] : false, |
|
229 | + 'onchange' => isset($option['onchange']) ? $option['onchange'] : '', |
|
230 | + 'custom' => isset($option['custom']) ? $option['custom'] : '', |
|
231 | + 'default_content' => isset($option['default_content']) ? $option['default_content'] : '', |
|
232 | + 'class' => isset($option['class']) ? $option['class'] : '', |
|
233 | + 'style' => isset($option['style']) ? $option['style'] : '', |
|
234 | + 'cols' => isset($option['cols']) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
|
235 | + 'rows' => isset($option['rows']) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
|
236 | 236 | ) |
237 | 237 | ); |
238 | 238 | |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | * @return array |
245 | 245 | */ |
246 | 246 | function wpinv_get_registered_settings() { |
247 | - return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) ); |
|
247 | + return array_filter(apply_filters('wpinv_registered_settings', wpinv_get_data('admin-settings'))); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @return array |
254 | 254 | */ |
255 | 255 | function getpaid_get_integration_settings() { |
256 | - return apply_filters( 'getpaid_integration_settings', array() ); |
|
256 | + return apply_filters('getpaid_integration_settings', array()); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -261,126 +261,126 @@ discard block |
||
261 | 261 | * |
262 | 262 | * @return array |
263 | 263 | */ |
264 | -function wpinv_settings_sanitize( $input = array() ) { |
|
264 | +function wpinv_settings_sanitize($input = array()) { |
|
265 | 265 | |
266 | 266 | $wpinv_options = wpinv_get_options(); |
267 | 267 | $raw_referrer = wp_get_raw_referer(); |
268 | 268 | |
269 | - if ( empty( $raw_referrer ) ) { |
|
270 | - return array_merge( $wpinv_options, $input ); |
|
269 | + if (empty($raw_referrer)) { |
|
270 | + return array_merge($wpinv_options, $input); |
|
271 | 271 | } |
272 | 272 | |
273 | - wp_parse_str( $raw_referrer, $referrer ); |
|
273 | + wp_parse_str($raw_referrer, $referrer); |
|
274 | 274 | |
275 | - if ( in_array( 'gp-setup', $referrer ) ) { |
|
276 | - return array_merge( $wpinv_options, $input ); |
|
275 | + if (in_array('gp-setup', $referrer)) { |
|
276 | + return array_merge($wpinv_options, $input); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | $settings = wpinv_get_registered_settings(); |
280 | - $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general'; |
|
281 | - $section = isset( $referrer['section'] ) ? $referrer['section'] : 'main'; |
|
280 | + $tab = isset($referrer['tab']) ? $referrer['tab'] : 'general'; |
|
281 | + $section = isset($referrer['section']) ? $referrer['section'] : 'main'; |
|
282 | 282 | |
283 | 283 | $input = $input ? $input : array(); |
284 | - $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input ); |
|
285 | - $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input ); |
|
284 | + $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input); |
|
285 | + $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input); |
|
286 | 286 | |
287 | 287 | // Loop through each setting being saved and pass it through a sanitization filter |
288 | - foreach ( $input as $key => $value ) { |
|
288 | + foreach ($input as $key => $value) { |
|
289 | 289 | |
290 | 290 | // Get the setting type (checkbox, select, etc) |
291 | - $type = isset( $settings[ $tab ][$section][ $key ]['type'] ) ? $settings[ $tab ][$section][ $key ]['type'] : false; |
|
291 | + $type = isset($settings[$tab][$section][$key]['type']) ? $settings[$tab][$section][$key]['type'] : false; |
|
292 | 292 | |
293 | - if ( $type ) { |
|
293 | + if ($type) { |
|
294 | 294 | // Field type specific filter |
295 | - $input[$key] = apply_filters( "wpinv_settings_sanitize_$type", $value, $key ); |
|
295 | + $input[$key] = apply_filters("wpinv_settings_sanitize_$type", $value, $key); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | // General filter |
299 | - $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
299 | + $input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key); |
|
300 | 300 | |
301 | 301 | // Key specific filter. |
302 | - $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
302 | + $input[$key] = apply_filters("wpinv_settings_sanitize_$key", $input[$key]); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | // Loop through the whitelist and unset any that are empty for the tab being saved |
306 | - $main_settings = isset( $settings[ $tab ] ) ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections |
|
307 | - $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array(); |
|
306 | + $main_settings = isset($settings[$tab]) ? $settings[$tab] : array(); // Check for extensions that aren't using new sections |
|
307 | + $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array(); |
|
308 | 308 | |
309 | - $found_settings = array_merge( $main_settings, $section_settings ); |
|
309 | + $found_settings = array_merge($main_settings, $section_settings); |
|
310 | 310 | |
311 | - if ( ! empty( $found_settings ) ) { |
|
312 | - foreach ( $found_settings as $key => $value ) { |
|
311 | + if (!empty($found_settings)) { |
|
312 | + foreach ($found_settings as $key => $value) { |
|
313 | 313 | |
314 | 314 | // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work |
315 | - if ( is_numeric( $key ) ) { |
|
315 | + if (is_numeric($key)) { |
|
316 | 316 | $key = $value['id']; |
317 | 317 | } |
318 | 318 | |
319 | - if ( ! isset( $input[ $key ] ) && isset( $wpinv_options[ $key ] ) ) { |
|
320 | - unset( $wpinv_options[ $key ] ); |
|
319 | + if (!isset($input[$key]) && isset($wpinv_options[$key])) { |
|
320 | + unset($wpinv_options[$key]); |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | } |
324 | 324 | |
325 | 325 | // Merge our new settings with the existing |
326 | - $output = array_merge( $wpinv_options, $input ); |
|
326 | + $output = array_merge($wpinv_options, $input); |
|
327 | 327 | |
328 | - add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' ); |
|
328 | + add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated'); |
|
329 | 329 | |
330 | 330 | return $output; |
331 | 331 | } |
332 | -add_filter( 'wpinv_settings_sanitize_text', 'trim', 10, 1 ); |
|
333 | -add_filter( 'wpinv_settings_sanitize_tax_rate', 'wpinv_sanitize_amount' ); |
|
332 | +add_filter('wpinv_settings_sanitize_text', 'trim', 10, 1); |
|
333 | +add_filter('wpinv_settings_sanitize_tax_rate', 'wpinv_sanitize_amount'); |
|
334 | 334 | |
335 | -function wpinv_settings_sanitize_tax_rates( $input ) { |
|
336 | - if( ! wpinv_current_user_can_manage_invoicing() ) { |
|
335 | +function wpinv_settings_sanitize_tax_rates($input) { |
|
336 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
337 | 337 | return $input; |
338 | 338 | } |
339 | 339 | |
340 | - $new_rates = ! empty( $_POST['tax_rates'] ) ? wp_kses_post_deep( array_values( $_POST['tax_rates'] ) ) : array(); |
|
340 | + $new_rates = !empty($_POST['tax_rates']) ? wp_kses_post_deep(array_values($_POST['tax_rates'])) : array(); |
|
341 | 341 | $tax_rates = array(); |
342 | 342 | |
343 | - foreach ( $new_rates as $rate ) { |
|
343 | + foreach ($new_rates as $rate) { |
|
344 | 344 | |
345 | - $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
346 | - $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
347 | - $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
348 | - $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
349 | - $rate['global'] = empty( $rate['state'] ); |
|
345 | + $rate['rate'] = wpinv_sanitize_amount($rate['rate']); |
|
346 | + $rate['name'] = sanitize_text_field($rate['name']); |
|
347 | + $rate['state'] = sanitize_text_field($rate['state']); |
|
348 | + $rate['country'] = sanitize_text_field($rate['country']); |
|
349 | + $rate['global'] = empty($rate['state']); |
|
350 | 350 | $tax_rates[] = $rate; |
351 | 351 | |
352 | 352 | } |
353 | 353 | |
354 | - update_option( 'wpinv_tax_rates', $tax_rates ); |
|
354 | + update_option('wpinv_tax_rates', $tax_rates); |
|
355 | 355 | |
356 | 356 | return $input; |
357 | 357 | } |
358 | -add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' ); |
|
358 | +add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates'); |
|
359 | 359 | |
360 | 360 | function wpinv_get_settings_tabs() { |
361 | 361 | $tabs = array(); |
362 | - $tabs['general'] = __( 'General', 'invoicing' ); |
|
363 | - $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' ); |
|
364 | - $tabs['taxes'] = __( 'Taxes', 'invoicing' ); |
|
365 | - $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
362 | + $tabs['general'] = __('General', 'invoicing'); |
|
363 | + $tabs['gateways'] = __('Payment Gateways', 'invoicing'); |
|
364 | + $tabs['taxes'] = __('Taxes', 'invoicing'); |
|
365 | + $tabs['emails'] = __('Emails', 'invoicing'); |
|
366 | 366 | |
367 | - if ( count( getpaid_get_integration_settings() ) > 0 ) { |
|
368 | - $tabs['integrations'] = __( 'Integrations', 'invoicing' ); |
|
367 | + if (count(getpaid_get_integration_settings()) > 0) { |
|
368 | + $tabs['integrations'] = __('Integrations', 'invoicing'); |
|
369 | 369 | } |
370 | 370 | |
371 | - $tabs['privacy'] = __( 'Privacy', 'invoicing' ); |
|
372 | - $tabs['misc'] = __( 'Misc', 'invoicing' ); |
|
373 | - $tabs['tools'] = __( 'Tools', 'invoicing' ); |
|
371 | + $tabs['privacy'] = __('Privacy', 'invoicing'); |
|
372 | + $tabs['misc'] = __('Misc', 'invoicing'); |
|
373 | + $tabs['tools'] = __('Tools', 'invoicing'); |
|
374 | 374 | |
375 | - return apply_filters( 'wpinv_settings_tabs', $tabs ); |
|
375 | + return apply_filters('wpinv_settings_tabs', $tabs); |
|
376 | 376 | } |
377 | 377 | |
378 | -function wpinv_get_settings_tab_sections( $tab = false ) { |
|
378 | +function wpinv_get_settings_tab_sections($tab = false) { |
|
379 | 379 | $tabs = false; |
380 | 380 | $sections = wpinv_get_registered_settings_sections(); |
381 | 381 | |
382 | - if( $tab && ! empty( $sections[ $tab ] ) ) { |
|
383 | - $tabs = $sections[ $tab ]; |
|
382 | + if ($tab && !empty($sections[$tab])) { |
|
383 | + $tabs = $sections[$tab]; |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | return $tabs; |
@@ -389,89 +389,89 @@ discard block |
||
389 | 389 | function wpinv_get_registered_settings_sections() { |
390 | 390 | static $sections = false; |
391 | 391 | |
392 | - if ( false !== $sections ) { |
|
392 | + if (false !== $sections) { |
|
393 | 393 | return $sections; |
394 | 394 | } |
395 | 395 | |
396 | 396 | $sections = array( |
397 | - 'general' => apply_filters( 'wpinv_settings_sections_general', array( |
|
398 | - 'main' => __( 'General Settings', 'invoicing' ), |
|
399 | - 'page_section' => __( 'Page Settings', 'invoicing' ), |
|
400 | - 'currency_section' => __( 'Currency Settings', 'invoicing' ), |
|
401 | - 'labels' => __( 'Label Texts', 'invoicing' ), |
|
402 | - ) ), |
|
403 | - 'gateways' => apply_filters( 'wpinv_settings_sections_gateways', array( |
|
404 | - 'main' => __( 'Gateway Settings', 'invoicing' ), |
|
405 | - ) ), |
|
406 | - 'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array( |
|
407 | - 'main' => __( 'Tax Settings', 'invoicing' ), |
|
408 | - 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
409 | - 'vat' => __( 'EU VAT Settings', 'invoicing' ) |
|
410 | - ) ), |
|
411 | - 'emails' => apply_filters( 'wpinv_settings_sections_emails', array( |
|
412 | - 'main' => __( 'Email Settings', 'invoicing' ), |
|
413 | - ) ), |
|
414 | - |
|
415 | - 'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ), |
|
416 | - |
|
417 | - 'privacy' => apply_filters( 'wpinv_settings_sections_privacy', array( |
|
418 | - 'main' => __( 'Privacy policy', 'invoicing' ), |
|
419 | - ) ), |
|
420 | - 'misc' => apply_filters( 'wpinv_settings_sections_misc', array( |
|
421 | - 'main' => __( 'Miscellaneous', 'invoicing' ), |
|
422 | - 'custom-css' => __( 'Custom CSS', 'invoicing' ), |
|
423 | - ) ), |
|
424 | - 'tools' => apply_filters( 'wpinv_settings_sections_tools', array( |
|
425 | - 'main' => __( 'Diagnostic Tools', 'invoicing' ), |
|
426 | - ) ), |
|
397 | + 'general' => apply_filters('wpinv_settings_sections_general', array( |
|
398 | + 'main' => __('General Settings', 'invoicing'), |
|
399 | + 'page_section' => __('Page Settings', 'invoicing'), |
|
400 | + 'currency_section' => __('Currency Settings', 'invoicing'), |
|
401 | + 'labels' => __('Label Texts', 'invoicing'), |
|
402 | + )), |
|
403 | + 'gateways' => apply_filters('wpinv_settings_sections_gateways', array( |
|
404 | + 'main' => __('Gateway Settings', 'invoicing'), |
|
405 | + )), |
|
406 | + 'taxes' => apply_filters('wpinv_settings_sections_taxes', array( |
|
407 | + 'main' => __('Tax Settings', 'invoicing'), |
|
408 | + 'rates' => __('Tax Rates', 'invoicing'), |
|
409 | + 'vat' => __('EU VAT Settings', 'invoicing') |
|
410 | + )), |
|
411 | + 'emails' => apply_filters('wpinv_settings_sections_emails', array( |
|
412 | + 'main' => __('Email Settings', 'invoicing'), |
|
413 | + )), |
|
414 | + |
|
415 | + 'integrations' => wp_list_pluck(getpaid_get_integration_settings(), 'label', 'id'), |
|
416 | + |
|
417 | + 'privacy' => apply_filters('wpinv_settings_sections_privacy', array( |
|
418 | + 'main' => __('Privacy policy', 'invoicing'), |
|
419 | + )), |
|
420 | + 'misc' => apply_filters('wpinv_settings_sections_misc', array( |
|
421 | + 'main' => __('Miscellaneous', 'invoicing'), |
|
422 | + 'custom-css' => __('Custom CSS', 'invoicing'), |
|
423 | + )), |
|
424 | + 'tools' => apply_filters('wpinv_settings_sections_tools', array( |
|
425 | + 'main' => __('Diagnostic Tools', 'invoicing'), |
|
426 | + )), |
|
427 | 427 | ); |
428 | 428 | |
429 | - $sections = apply_filters( 'wpinv_settings_sections', $sections ); |
|
429 | + $sections = apply_filters('wpinv_settings_sections', $sections); |
|
430 | 430 | |
431 | 431 | return $sections; |
432 | 432 | } |
433 | 433 | |
434 | -function wpinv_get_pages( $with_slug = false, $default_label = NULL ) { |
|
434 | +function wpinv_get_pages($with_slug = false, $default_label = NULL) { |
|
435 | 435 | $pages_options = array(); |
436 | 436 | |
437 | - if( $default_label !== NULL && $default_label !== false ) { |
|
438 | - $pages_options = array( '' => $default_label ); // Blank option |
|
437 | + if ($default_label !== NULL && $default_label !== false) { |
|
438 | + $pages_options = array('' => $default_label); // Blank option |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | $pages = get_pages(); |
442 | - if ( $pages ) { |
|
443 | - foreach ( $pages as $page ) { |
|
442 | + if ($pages) { |
|
443 | + foreach ($pages as $page) { |
|
444 | 444 | $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
445 | - $pages_options[ $page->ID ] = $title; |
|
445 | + $pages_options[$page->ID] = $title; |
|
446 | 446 | } |
447 | 447 | } |
448 | 448 | |
449 | 449 | return $pages_options; |
450 | 450 | } |
451 | 451 | |
452 | -function wpinv_header_callback( $args ) { |
|
453 | - if ( !empty( $args['desc'] ) ) { |
|
452 | +function wpinv_header_callback($args) { |
|
453 | + if (!empty($args['desc'])) { |
|
454 | 454 | echo $args['desc']; |
455 | 455 | } |
456 | 456 | } |
457 | 457 | |
458 | -function wpinv_hidden_callback( $args ) { |
|
458 | +function wpinv_hidden_callback($args) { |
|
459 | 459 | |
460 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
461 | - $value = wpinv_get_option( $args['id'], $std ); |
|
460 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
461 | + $value = wpinv_get_option($args['id'], $std); |
|
462 | 462 | |
463 | - if ( isset( $args['set_value'] ) ) { |
|
463 | + if (isset($args['set_value'])) { |
|
464 | 464 | $value = $args['set_value']; |
465 | 465 | } |
466 | 466 | |
467 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
467 | + if (isset($args['faux']) && true === $args['faux']) { |
|
468 | 468 | $args['readonly'] = true; |
469 | - $name = ''; |
|
469 | + $name = ''; |
|
470 | 470 | } else { |
471 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
471 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
472 | 472 | } |
473 | 473 | |
474 | - $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
474 | + $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key($args['id']) . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '" />'; |
|
475 | 475 | |
476 | 476 | echo $html; |
477 | 477 | } |
@@ -479,59 +479,59 @@ discard block |
||
479 | 479 | /** |
480 | 480 | * Displays a checkbox settings callback. |
481 | 481 | */ |
482 | -function wpinv_checkbox_callback( $args ) { |
|
482 | +function wpinv_checkbox_callback($args) { |
|
483 | 483 | |
484 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
485 | - $std = wpinv_get_option( $args['id'], $std ); |
|
486 | - $id = esc_attr( $args['id'] ); |
|
484 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
485 | + $std = wpinv_get_option($args['id'], $std); |
|
486 | + $id = esc_attr($args['id']); |
|
487 | 487 | |
488 | - getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
488 | + getpaid_hidden_field("wpinv_settings[$id]", '0'); |
|
489 | 489 | ?> |
490 | 490 | <fieldset> |
491 | 491 | <label> |
492 | - <input id="wpinv-settings-<?php echo $id; ?>" name="wpinv_settings[<?php echo $id; ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox"> |
|
493 | - <?php echo wp_kses_post( $args['desc'] ); ?> |
|
492 | + <input id="wpinv-settings-<?php echo $id; ?>" name="wpinv_settings[<?php echo $id; ?>]" <?php checked(empty($std), false); ?> value="1" type="checkbox"> |
|
493 | + <?php echo wp_kses_post($args['desc']); ?> |
|
494 | 494 | </label> |
495 | 495 | </fieldset> |
496 | 496 | <?php |
497 | 497 | } |
498 | 498 | |
499 | -function wpinv_multicheck_callback( $args ) { |
|
499 | +function wpinv_multicheck_callback($args) { |
|
500 | 500 | |
501 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
502 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
501 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
502 | + $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : ''; |
|
503 | 503 | |
504 | - if ( ! empty( $args['options'] ) ) { |
|
504 | + if (!empty($args['options'])) { |
|
505 | 505 | |
506 | - $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
507 | - $value = wpinv_get_option( $args['id'], $std ); |
|
506 | + $std = isset($args['std']) ? $args['std'] : array(); |
|
507 | + $value = wpinv_get_option($args['id'], $std); |
|
508 | 508 | |
509 | 509 | echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
510 | - foreach( $args['options'] as $key => $option ): |
|
511 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
512 | - if ( in_array( $sanitize_key, $value ) ) { |
|
510 | + foreach ($args['options'] as $key => $option): |
|
511 | + $sanitize_key = wpinv_sanitize_key($key); |
|
512 | + if (in_array($sanitize_key, $value)) { |
|
513 | 513 | $enabled = $sanitize_key; |
514 | 514 | } else { |
515 | 515 | $enabled = NULL; |
516 | 516 | } |
517 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
518 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
517 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($sanitize_key) . '" ' . checked($sanitize_key, $enabled, false) . '/> '; |
|
518 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post($option) . '</label></div>'; |
|
519 | 519 | endforeach; |
520 | 520 | echo '</div>'; |
521 | 521 | echo '<p class="description">' . $args['desc'] . '</p>'; |
522 | 522 | } |
523 | 523 | } |
524 | 524 | |
525 | -function wpinv_payment_icons_callback( $args ) { |
|
525 | +function wpinv_payment_icons_callback($args) { |
|
526 | 526 | |
527 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
528 | - $value = wpinv_get_option( $args['id'], false); |
|
527 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
528 | + $value = wpinv_get_option($args['id'], false); |
|
529 | 529 | |
530 | - if ( ! empty( $args['options'] ) ) { |
|
531 | - foreach( $args['options'] as $key => $option ) { |
|
532 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
530 | + if (!empty($args['options'])) { |
|
531 | + foreach ($args['options'] as $key => $option) { |
|
532 | + $sanitize_key = wpinv_sanitize_key($key); |
|
533 | 533 | |
534 | - if( empty( $value ) ) { |
|
534 | + if (empty($value)) { |
|
535 | 535 | $enabled = $option; |
536 | 536 | } else { |
537 | 537 | $enabled = NULL; |
@@ -539,67 +539,67 @@ discard block |
||
539 | 539 | |
540 | 540 | echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
541 | 541 | |
542 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
542 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($option) . '" ' . checked($option, $enabled, false) . '/> '; |
|
543 | 543 | |
544 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
545 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
544 | + if (wpinv_string_is_image_url($key)) { |
|
545 | + echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
546 | 546 | } else { |
547 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
547 | + $card = strtolower(str_replace(' ', '', $option)); |
|
548 | 548 | |
549 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
550 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
549 | + if (has_filter('wpinv_accepted_payment_' . $card . '_image')) { |
|
550 | + $image = apply_filters('wpinv_accepted_payment_' . $card . '_image', ''); |
|
551 | 551 | } else { |
552 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
552 | + $image = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false); |
|
553 | 553 | $content_dir = WP_CONTENT_DIR; |
554 | 554 | |
555 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
555 | + if (function_exists('wp_normalize_path')) { |
|
556 | 556 | // Replaces backslashes with forward slashes for Windows systems |
557 | - $image = wp_normalize_path( $image ); |
|
558 | - $content_dir = wp_normalize_path( $content_dir ); |
|
557 | + $image = wp_normalize_path($image); |
|
558 | + $content_dir = wp_normalize_path($content_dir); |
|
559 | 559 | } |
560 | 560 | |
561 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
561 | + $image = str_replace($content_dir, content_url(), $image); |
|
562 | 562 | } |
563 | 563 | |
564 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
564 | + echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
565 | 565 | } |
566 | 566 | echo $option . '</label>'; |
567 | 567 | } |
568 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
568 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>'; |
|
569 | 569 | } |
570 | 570 | } |
571 | 571 | |
572 | 572 | /** |
573 | 573 | * Displays a radio settings field. |
574 | 574 | */ |
575 | -function wpinv_radio_callback( $args ) { |
|
575 | +function wpinv_radio_callback($args) { |
|
576 | 576 | |
577 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
578 | - $std = wpinv_get_option( $args['id'], $std ); |
|
577 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
578 | + $std = wpinv_get_option($args['id'], $std); |
|
579 | 579 | ?> |
580 | 580 | <fieldset> |
581 | - <ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;"> |
|
582 | - <?php foreach( $args['options'] as $key => $option ) : ?> |
|
581 | + <ul id="wpinv-settings-<?php echo esc_attr($args['id']); ?>" style="margin-top: 0;"> |
|
582 | + <?php foreach ($args['options'] as $key => $option) : ?> |
|
583 | 583 | <li> |
584 | 584 | <label> |
585 | - <input name="wpinv_settings[<?php echo esc_attr( $args['id'] ); ?>]" <?php checked( $std, $key ); ?> value="<?php echo esc_attr( $key ); ?>" type="radio"> |
|
586 | - <?php echo wp_kses_post( $option ); ?> |
|
585 | + <input name="wpinv_settings[<?php echo esc_attr($args['id']); ?>]" <?php checked($std, $key); ?> value="<?php echo esc_attr($key); ?>" type="radio"> |
|
586 | + <?php echo wp_kses_post($option); ?> |
|
587 | 587 | </label> |
588 | 588 | </li> |
589 | 589 | <?php endforeach; ?> |
590 | 590 | </ul> |
591 | 591 | </fieldset> |
592 | 592 | <?php |
593 | - getpaid_settings_description_callback( $args ); |
|
593 | + getpaid_settings_description_callback($args); |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | /** |
597 | 597 | * Displays a description if available. |
598 | 598 | */ |
599 | -function getpaid_settings_description_callback( $args ) { |
|
599 | +function getpaid_settings_description_callback($args) { |
|
600 | 600 | |
601 | - if ( ! empty( $args['desc'] ) ) { |
|
602 | - $description = wp_kses_post( $args['desc'] ); |
|
601 | + if (!empty($args['desc'])) { |
|
602 | + $description = wp_kses_post($args['desc']); |
|
603 | 603 | echo "<p class='description'>$description</p>"; |
604 | 604 | } |
605 | 605 | |
@@ -615,31 +615,31 @@ discard block |
||
615 | 615 | </tr> |
616 | 616 | <tr class="bsui"> |
617 | 617 | <td colspan="2" class="p-0"> |
618 | - <?php include plugin_dir_path( __FILE__ ) . 'views/html-gateways-edit.php'; ?> |
|
618 | + <?php include plugin_dir_path(__FILE__) . 'views/html-gateways-edit.php'; ?> |
|
619 | 619 | |
620 | 620 | <?php |
621 | 621 | } |
622 | 622 | |
623 | 623 | function wpinv_gateway_select_callback($args) { |
624 | 624 | |
625 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
626 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
627 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
628 | - $value = wpinv_get_option( $args['id'], $std ); |
|
625 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
626 | + $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : ''; |
|
627 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
628 | + $value = wpinv_get_option($args['id'], $std); |
|
629 | 629 | |
630 | - echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
630 | + echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '" >'; |
|
631 | 631 | |
632 | - foreach ( $args['options'] as $key => $option ) : |
|
633 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
634 | - $selected = selected( $key, $args['selected'], false ); |
|
632 | + foreach ($args['options'] as $key => $option) : |
|
633 | + if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) { |
|
634 | + $selected = selected($key, $args['selected'], false); |
|
635 | 635 | } else { |
636 | - $selected = selected( $key, $value, false ); |
|
636 | + $selected = selected($key, $value, false); |
|
637 | 637 | } |
638 | - echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
638 | + echo '<option value="' . wpinv_sanitize_key($key) . '"' . $selected . '>' . esc_html($option['admin_label']) . '</option>'; |
|
639 | 639 | endforeach; |
640 | 640 | |
641 | 641 | echo '</select>'; |
642 | - echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
642 | + echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | /** |
@@ -648,28 +648,28 @@ discard block |
||
648 | 648 | * @param array $args |
649 | 649 | * @return string |
650 | 650 | */ |
651 | -function wpinv_settings_attrs_helper( $args ) { |
|
651 | +function wpinv_settings_attrs_helper($args) { |
|
652 | 652 | |
653 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
654 | - $id = esc_attr( $args['id'] ); |
|
655 | - $placeholder = esc_attr( $args['placeholder'] ); |
|
653 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
654 | + $id = esc_attr($args['id']); |
|
655 | + $placeholder = esc_attr($args['placeholder']); |
|
656 | 656 | |
657 | - if ( ! empty( $args['faux'] ) ) { |
|
657 | + if (!empty($args['faux'])) { |
|
658 | 658 | $args['readonly'] = true; |
659 | 659 | $name = ''; |
660 | 660 | } else { |
661 | - $value = wpinv_get_option( $args['id'], $value ); |
|
661 | + $value = wpinv_get_option($args['id'], $value); |
|
662 | 662 | $name = "wpinv_settings[$id]"; |
663 | 663 | } |
664 | 664 | |
665 | - $value = is_scalar( $value ) ? esc_attr( $value ) : ''; |
|
666 | - $class = esc_attr( $args['class'] ); |
|
667 | - $style = esc_attr( $args['style'] ); |
|
668 | - $readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"'; |
|
665 | + $value = is_scalar($value) ? esc_attr($value) : ''; |
|
666 | + $class = esc_attr($args['class']); |
|
667 | + $style = esc_attr($args['style']); |
|
668 | + $readonly = empty($args['readonly']) ? '' : 'readonly onclick="this.select()"'; |
|
669 | 669 | |
670 | 670 | $onchange = ''; |
671 | - if ( ! empty( $args['onchange'] ) ) { |
|
672 | - $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
671 | + if (!empty($args['onchange'])) { |
|
672 | + $onchange = ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly"; |
@@ -678,11 +678,11 @@ discard block |
||
678 | 678 | /** |
679 | 679 | * Displays a text input settings callback. |
680 | 680 | */ |
681 | -function wpinv_text_callback( $args ) { |
|
681 | +function wpinv_text_callback($args) { |
|
682 | 682 | |
683 | - $desc = wp_kses_post( $args['desc'] ); |
|
684 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
685 | - $attr = wpinv_settings_attrs_helper( $args ); |
|
683 | + $desc = wp_kses_post($args['desc']); |
|
684 | + $desc = empty($desc) ? '' : "<p class='description'>$desc</p>"; |
|
685 | + $attr = wpinv_settings_attrs_helper($args); |
|
686 | 686 | |
687 | 687 | ?> |
688 | 688 | <label style="width: 100%;"> |
@@ -696,14 +696,14 @@ discard block |
||
696 | 696 | /** |
697 | 697 | * Displays a number input settings callback. |
698 | 698 | */ |
699 | -function wpinv_number_callback( $args ) { |
|
699 | +function wpinv_number_callback($args) { |
|
700 | 700 | |
701 | - $desc = wp_kses_post( $args['desc'] ); |
|
702 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
703 | - $attr = wpinv_settings_attrs_helper( $args ); |
|
704 | - $max = intval( $args['max'] ); |
|
705 | - $min = intval( $args['min'] ); |
|
706 | - $step = floatval( $args['step'] ); |
|
701 | + $desc = wp_kses_post($args['desc']); |
|
702 | + $desc = empty($desc) ? '' : "<p class='description'>$desc</p>"; |
|
703 | + $attr = wpinv_settings_attrs_helper($args); |
|
704 | + $max = intval($args['max']); |
|
705 | + $min = intval($args['min']); |
|
706 | + $step = floatval($args['step']); |
|
707 | 707 | |
708 | 708 | ?> |
709 | 709 | <label style="width: 100%;"> |
@@ -714,37 +714,37 @@ discard block |
||
714 | 714 | |
715 | 715 | } |
716 | 716 | |
717 | -function wpinv_textarea_callback( $args ) { |
|
717 | +function wpinv_textarea_callback($args) { |
|
718 | 718 | |
719 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
720 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
721 | - $value = wpinv_get_option( $args['id'], $std ); |
|
719 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
720 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
721 | + $value = wpinv_get_option($args['id'], $std); |
|
722 | 722 | |
723 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
724 | - $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
|
723 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
724 | + $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text'; |
|
725 | 725 | |
726 | - $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
727 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
726 | + $html = '<textarea class="' . sanitize_html_class($class) . ' txtarea-' . sanitize_html_class($size) . ' wpi-' . esc_attr(sanitize_html_class($sanitize_id)) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']">' . esc_textarea(stripslashes($value)) . '</textarea>'; |
|
727 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
728 | 728 | |
729 | 729 | echo $html; |
730 | 730 | } |
731 | 731 | |
732 | -function wpinv_password_callback( $args ) { |
|
732 | +function wpinv_password_callback($args) { |
|
733 | 733 | |
734 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
735 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
736 | - $value = wpinv_get_option( $args['id'], $std ); |
|
734 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
735 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
736 | + $value = wpinv_get_option($args['id'], $std); |
|
737 | 737 | |
738 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
739 | - $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
740 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
738 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
739 | + $html = '<input type="password" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '"/>'; |
|
740 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
741 | 741 | |
742 | 742 | echo $html; |
743 | 743 | } |
744 | 744 | |
745 | 745 | function wpinv_missing_callback($args) { |
746 | 746 | printf( |
747 | - __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
747 | + __('The callback function used for the %s setting is missing.', 'invoicing'), |
|
748 | 748 | '<strong>' . $args['id'] . '</strong>' |
749 | 749 | ); |
750 | 750 | } |
@@ -752,35 +752,35 @@ discard block |
||
752 | 752 | /** |
753 | 753 | * Displays a number input settings callback. |
754 | 754 | */ |
755 | -function wpinv_select_callback( $args ) { |
|
755 | +function wpinv_select_callback($args) { |
|
756 | 756 | |
757 | - $desc = wp_kses_post( $args['desc'] ); |
|
758 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
759 | - $attr = wpinv_settings_attrs_helper( $args ); |
|
760 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
761 | - $value = wpinv_get_option( $args['id'], $value ); |
|
762 | - $rand = uniqid( 'random_id' ); |
|
757 | + $desc = wp_kses_post($args['desc']); |
|
758 | + $desc = empty($desc) ? '' : "<p class='description'>$desc</p>"; |
|
759 | + $attr = wpinv_settings_attrs_helper($args); |
|
760 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
761 | + $value = wpinv_get_option($args['id'], $value); |
|
762 | + $rand = uniqid('random_id'); |
|
763 | 763 | |
764 | 764 | ?> |
765 | 765 | <label style="width: 100%;"> |
766 | 766 | <select <?php echo $attr; ?>> |
767 | - <?php foreach ( $args['options'] as $option => $name ) : ?> |
|
768 | - <option value="<?php echo esc_attr( $option ); ?>" <?php echo selected( $option, $value ); ?>><?php echo wpinv_clean( $name ); ?></option> |
|
769 | - <?php endforeach;?> |
|
767 | + <?php foreach ($args['options'] as $option => $name) : ?> |
|
768 | + <option value="<?php echo esc_attr($option); ?>" <?php echo selected($option, $value); ?>><?php echo wpinv_clean($name); ?></option> |
|
769 | + <?php endforeach; ?> |
|
770 | 770 | </select> |
771 | 771 | |
772 | - <?php if ( substr( $args['id'], -5 ) === '_page' && is_numeric( $value ) ) : ?> |
|
773 | - <a href="<?php echo get_edit_post_link( $value ); ?>" target="_blank" class="button getpaid-page-setting-edit"><?php _e( 'Edit Page', 'invoicing' ) ?></a> |
|
772 | + <?php if (substr($args['id'], -5) === '_page' && is_numeric($value)) : ?> |
|
773 | + <a href="<?php echo get_edit_post_link($value); ?>" target="_blank" class="button getpaid-page-setting-edit"><?php _e('Edit Page', 'invoicing') ?></a> |
|
774 | 774 | <?php endif; ?> |
775 | 775 | |
776 | - <?php if ( substr( $args['id'], -5 ) === '_page' && ! empty( $args['default_content'] ) ) : ?> |
|
777 | - <a href="#TB_inline?&width=400&height=550&inlineId=<?php echo $rand; ?>" class="button thickbox getpaid-page-setting-view-default"><?php _e( 'View Default Content', 'invoicing' ) ?></a> |
|
776 | + <?php if (substr($args['id'], -5) === '_page' && !empty($args['default_content'])) : ?> |
|
777 | + <a href="#TB_inline?&width=400&height=550&inlineId=<?php echo $rand; ?>" class="button thickbox getpaid-page-setting-view-default"><?php _e('View Default Content', 'invoicing') ?></a> |
|
778 | 778 | <div id='<?php echo $rand; ?>' style='display:none;'> |
779 | 779 | <div> |
780 | - <h3><?php _e( 'Original Content', 'invoicing' ) ?></h3> |
|
781 | - <textarea readonly onclick="this.select()" rows="8" style="width: 100%;"><?php echo gepaid_trim_lines( wp_kses_post( $args['default_content'] ) ); ?></textarea> |
|
782 | - <h3><?php _e( 'Current Content', 'invoicing' ) ?></h3> |
|
783 | - <textarea readonly onclick="this.select()" rows="8" style="width: 100%;"><?php $_post = get_post( $value ); echo empty( $_post ) ? '' : gepaid_trim_lines( wp_kses_post( $_post->post_content ) ); ?></textarea> |
|
780 | + <h3><?php _e('Original Content', 'invoicing') ?></h3> |
|
781 | + <textarea readonly onclick="this.select()" rows="8" style="width: 100%;"><?php echo gepaid_trim_lines(wp_kses_post($args['default_content'])); ?></textarea> |
|
782 | + <h3><?php _e('Current Content', 'invoicing') ?></h3> |
|
783 | + <textarea readonly onclick="this.select()" rows="8" style="width: 100%;"><?php $_post = get_post($value); echo empty($_post) ? '' : gepaid_trim_lines(wp_kses_post($_post->post_content)); ?></textarea> |
|
784 | 784 | </div> |
785 | 785 | </div> |
786 | 786 | <?php endif; ?> |
@@ -791,88 +791,88 @@ discard block |
||
791 | 791 | |
792 | 792 | } |
793 | 793 | |
794 | -function wpinv_color_select_callback( $args ) { |
|
794 | +function wpinv_color_select_callback($args) { |
|
795 | 795 | |
796 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
797 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
798 | - $value = wpinv_get_option( $args['id'], $std ); |
|
796 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
797 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
798 | + $value = wpinv_get_option($args['id'], $std); |
|
799 | 799 | |
800 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
800 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>'; |
|
801 | 801 | |
802 | - foreach ( $args['options'] as $option => $color ) { |
|
803 | - $selected = selected( $option, $value, false ); |
|
804 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
802 | + foreach ($args['options'] as $option => $color) { |
|
803 | + $selected = selected($option, $value, false); |
|
804 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($color['label']) . '</option>'; |
|
805 | 805 | } |
806 | 806 | |
807 | 807 | $html .= '</select>'; |
808 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
808 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
809 | 809 | |
810 | 810 | echo $html; |
811 | 811 | } |
812 | 812 | |
813 | -function wpinv_rich_editor_callback( $args ) { |
|
813 | +function wpinv_rich_editor_callback($args) { |
|
814 | 814 | global $wp_version; |
815 | 815 | |
816 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
816 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
817 | 817 | |
818 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
819 | - $value = wpinv_get_option( $args['id'], $std ); |
|
818 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
819 | + $value = wpinv_get_option($args['id'], $std); |
|
820 | 820 | |
821 | - if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
821 | + if (!empty($args['allow_blank']) && empty($value)) { |
|
822 | 822 | $value = $std; |
823 | 823 | } |
824 | 824 | |
825 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
825 | + $rows = isset($args['size']) ? $args['size'] : 20; |
|
826 | 826 | |
827 | 827 | $html = '<div class="getpaid-settings-editor-input">'; |
828 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
828 | + if ($wp_version >= 3.3 && function_exists('wp_editor')) { |
|
829 | 829 | ob_start(); |
830 | - wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
830 | + wp_editor(stripslashes($value), 'wpinv_settings_' . esc_attr($args['id']), array('textarea_name' => 'wpinv_settings[' . esc_attr($args['id']) . ']', 'textarea_rows' => absint($rows), 'media_buttons' => false)); |
|
831 | 831 | $html .= ob_get_clean(); |
832 | 832 | } else { |
833 | - $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
833 | + $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" class="wpi-' . esc_attr(sanitize_html_class($args['id'])) . '">' . esc_textarea(stripslashes($value)) . '</textarea>'; |
|
834 | 834 | } |
835 | 835 | |
836 | - $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
836 | + $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
837 | 837 | |
838 | 838 | echo $html; |
839 | 839 | } |
840 | 840 | |
841 | -function wpinv_upload_callback( $args ) { |
|
841 | +function wpinv_upload_callback($args) { |
|
842 | 842 | |
843 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
843 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
844 | 844 | |
845 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
846 | - $value = wpinv_get_option( $args['id'], $std ); |
|
845 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
846 | + $value = wpinv_get_option($args['id'], $std); |
|
847 | 847 | |
848 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
849 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
850 | - $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
851 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
848 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
849 | + $html = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr(stripslashes($value)) . '"/>'; |
|
850 | + $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __('Upload File', 'invoicing') . '"/></span>'; |
|
851 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
852 | 852 | |
853 | 853 | echo $html; |
854 | 854 | } |
855 | 855 | |
856 | -function wpinv_color_callback( $args ) { |
|
856 | +function wpinv_color_callback($args) { |
|
857 | 857 | |
858 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
859 | - $value = wpinv_get_option( $args['id'], $std ); |
|
860 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
858 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
859 | + $value = wpinv_get_option($args['id'], $std); |
|
860 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
861 | 861 | |
862 | - $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />'; |
|
863 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
862 | + $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '" data-default-color="' . esc_attr($std) . '" />'; |
|
863 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
864 | 864 | |
865 | 865 | echo $html; |
866 | 866 | } |
867 | 867 | |
868 | 868 | function wpinv_country_states_callback($args) { |
869 | 869 | |
870 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
871 | - $value = wpinv_get_option( $args['id'], $std ); |
|
870 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
871 | + $value = wpinv_get_option($args['id'], $std); |
|
872 | 872 | |
873 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
873 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
874 | 874 | |
875 | - if ( isset( $args['placeholder'] ) ) { |
|
875 | + if (isset($args['placeholder'])) { |
|
876 | 876 | $placeholder = $args['placeholder']; |
877 | 877 | } else { |
878 | 878 | $placeholder = ''; |
@@ -880,16 +880,16 @@ discard block |
||
880 | 880 | |
881 | 881 | $states = wpinv_get_country_states(); |
882 | 882 | |
883 | - $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
884 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
883 | + $class = empty($states) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
884 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"' . $class . 'data-placeholder="' . esc_html($placeholder) . '"/>'; |
|
885 | 885 | |
886 | - foreach ( $states as $option => $name ) { |
|
887 | - $selected = selected( $option, $value, false ); |
|
888 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
886 | + foreach ($states as $option => $name) { |
|
887 | + $selected = selected($option, $value, false); |
|
888 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>'; |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | $html .= '</select>'; |
892 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
892 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
893 | 893 | |
894 | 894 | echo $html; |
895 | 895 | } |
@@ -904,7 +904,7 @@ discard block |
||
904 | 904 | </tr> |
905 | 905 | <tr class="bsui"> |
906 | 906 | <td colspan="2" class="p-0"> |
907 | - <?php include plugin_dir_path( __FILE__ ) . 'views/html-tax-rates-edit.php'; ?> |
|
907 | + <?php include plugin_dir_path(__FILE__) . 'views/html-tax-rates-edit.php'; ?> |
|
908 | 908 | |
909 | 909 | <?php |
910 | 910 | |
@@ -913,14 +913,14 @@ discard block |
||
913 | 913 | /** |
914 | 914 | * Displays a tax rate' edit row. |
915 | 915 | */ |
916 | -function wpinv_tax_rate_callback( $tax_rate, $key, $echo = true ) { |
|
916 | +function wpinv_tax_rate_callback($tax_rate, $key, $echo = true) { |
|
917 | 917 | ob_start(); |
918 | 918 | |
919 | - $key = sanitize_key( $key ); |
|
920 | - $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
921 | - include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
919 | + $key = sanitize_key($key); |
|
920 | + $tax_rate['reduced_rate'] = empty($tax_rate['reduced_rate']) ? 0 : $tax_rate['reduced_rate']; |
|
921 | + include plugin_dir_path(__FILE__) . 'views/html-tax-rate-edit.php'; |
|
922 | 922 | |
923 | - if ( $echo ) { |
|
923 | + if ($echo) { |
|
924 | 924 | echo ob_get_clean(); |
925 | 925 | } else { |
926 | 926 | return ob_get_clean(); |
@@ -933,136 +933,136 @@ discard block |
||
933 | 933 | ob_start(); ?> |
934 | 934 | </td><tr> |
935 | 935 | <td colspan="2" class="wpinv_tools_tdbox"> |
936 | - <?php if ( $args['desc'] ) { ?><p><?php echo $args['desc']; ?></p><?php } ?> |
|
937 | - <?php do_action( 'wpinv_tools_before' ); ?> |
|
936 | + <?php if ($args['desc']) { ?><p><?php echo $args['desc']; ?></p><?php } ?> |
|
937 | + <?php do_action('wpinv_tools_before'); ?> |
|
938 | 938 | <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts"> |
939 | 939 | <thead> |
940 | 940 | <tr> |
941 | - <th scope="col" class="wpinv-th-tool"><?php _e( 'Tool', 'invoicing' ); ?></th> |
|
942 | - <th scope="col" class="wpinv-th-desc"><?php _e( 'Description', 'invoicing' ); ?></th> |
|
943 | - <th scope="col" class="wpinv-th-action"><?php _e( 'Action', 'invoicing' ); ?></th> |
|
941 | + <th scope="col" class="wpinv-th-tool"><?php _e('Tool', 'invoicing'); ?></th> |
|
942 | + <th scope="col" class="wpinv-th-desc"><?php _e('Description', 'invoicing'); ?></th> |
|
943 | + <th scope="col" class="wpinv-th-action"><?php _e('Action', 'invoicing'); ?></th> |
|
944 | 944 | </tr> |
945 | 945 | </thead> |
946 | 946 | |
947 | 947 | <tbody> |
948 | 948 | <tr> |
949 | - <td><?php _e( 'Check Pages', 'invoicing' );?></td> |
|
949 | + <td><?php _e('Check Pages', 'invoicing'); ?></td> |
|
950 | 950 | <td> |
951 | - <small><?php _e( 'Creates any missing GetPaid pages.', 'invoicing' ); ?></small> |
|
951 | + <small><?php _e('Creates any missing GetPaid pages.', 'invoicing'); ?></small> |
|
952 | 952 | </td> |
953 | 953 | <td> |
954 | 954 | <a href="<?php |
955 | 955 | echo esc_url( |
956 | 956 | wp_nonce_url( |
957 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
957 | + add_query_arg('getpaid-admin-action', 'create_missing_pages'), |
|
958 | 958 | 'getpaid-nonce', |
959 | 959 | 'getpaid-nonce' |
960 | 960 | ) |
961 | 961 | ); |
962 | - ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
962 | + ?>" class="button button-primary"><?php _e('Run', 'invoicing'); ?></a> |
|
963 | 963 | </td> |
964 | 964 | </tr> |
965 | 965 | <tr> |
966 | - <td><?php _e( 'Create Database Tables', 'invoicing' );?></td> |
|
966 | + <td><?php _e('Create Database Tables', 'invoicing'); ?></td> |
|
967 | 967 | <td> |
968 | - <small><?php _e( 'Run this tool to create any missing database tables.', 'invoicing' ); ?></small> |
|
968 | + <small><?php _e('Run this tool to create any missing database tables.', 'invoicing'); ?></small> |
|
969 | 969 | </td> |
970 | 970 | <td> |
971 | 971 | <a href="<?php |
972 | 972 | echo esc_url( |
973 | 973 | wp_nonce_url( |
974 | - add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
974 | + add_query_arg('getpaid-admin-action', 'create_missing_tables'), |
|
975 | 975 | 'getpaid-nonce', |
976 | 976 | 'getpaid-nonce' |
977 | 977 | ) |
978 | 978 | ); |
979 | - ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
979 | + ?>" class="button button-primary"><?php _e('Run', 'invoicing'); ?></a> |
|
980 | 980 | </td> |
981 | 981 | </tr> |
982 | 982 | <tr> |
983 | - <td><?php _e( 'Migrate old invoices', 'invoicing' );?></td> |
|
983 | + <td><?php _e('Migrate old invoices', 'invoicing'); ?></td> |
|
984 | 984 | <td> |
985 | - <small><?php _e( 'If your old invoices were not migrated after updating from Invoicing to GetPaid, you can use this tool to migrate them.', 'invoicing' ); ?></small> |
|
985 | + <small><?php _e('If your old invoices were not migrated after updating from Invoicing to GetPaid, you can use this tool to migrate them.', 'invoicing'); ?></small> |
|
986 | 986 | </td> |
987 | 987 | <td> |
988 | 988 | <a href="<?php |
989 | 989 | echo esc_url( |
990 | 990 | wp_nonce_url( |
991 | - add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ), |
|
991 | + add_query_arg('getpaid-admin-action', 'migrate_old_invoices'), |
|
992 | 992 | 'getpaid-nonce', |
993 | 993 | 'getpaid-nonce' |
994 | 994 | ) |
995 | 995 | ); |
996 | - ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
996 | + ?>" class="button button-primary"><?php _e('Run', 'invoicing'); ?></a> |
|
997 | 997 | </td> |
998 | 998 | </tr> |
999 | 999 | |
1000 | 1000 | <tr> |
1001 | - <td><?php _e( 'Recalculate Discounts', 'invoicing' );?></td> |
|
1001 | + <td><?php _e('Recalculate Discounts', 'invoicing'); ?></td> |
|
1002 | 1002 | <td> |
1003 | - <small><?php _e( 'Recalculate discounts for existing invoices that have discount codes but are not discounted.', 'invoicing' ); ?></small> |
|
1003 | + <small><?php _e('Recalculate discounts for existing invoices that have discount codes but are not discounted.', 'invoicing'); ?></small> |
|
1004 | 1004 | </td> |
1005 | 1005 | <td> |
1006 | 1006 | <a href="<?php |
1007 | 1007 | echo esc_url( |
1008 | 1008 | wp_nonce_url( |
1009 | - add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ), |
|
1009 | + add_query_arg('getpaid-admin-action', 'recalculate_discounts'), |
|
1010 | 1010 | 'getpaid-nonce', |
1011 | 1011 | 'getpaid-nonce' |
1012 | 1012 | ) |
1013 | 1013 | ); |
1014 | - ?>" class="button button-primary"><?php _e( 'Run', 'invoicing' );?></a> |
|
1014 | + ?>" class="button button-primary"><?php _e('Run', 'invoicing'); ?></a> |
|
1015 | 1015 | </td> |
1016 | 1016 | </tr> |
1017 | 1017 | |
1018 | 1018 | <tr> |
1019 | - <td><?php _e( 'Set-up Wizard', 'invoicing' );?></td> |
|
1019 | + <td><?php _e('Set-up Wizard', 'invoicing'); ?></td> |
|
1020 | 1020 | <td> |
1021 | - <small><?php _e( 'Launch the quick set-up wizard.', 'invoicing' ); ?></small> |
|
1021 | + <small><?php _e('Launch the quick set-up wizard.', 'invoicing'); ?></small> |
|
1022 | 1022 | </td> |
1023 | 1023 | <td> |
1024 | 1024 | <a href="<?php |
1025 | - echo esc_url( admin_url( 'index.php?page=gp-setup' ) ); |
|
1026 | - ?>" class="button button-primary"><?php _e( 'Launch', 'invoicing' );?></a> |
|
1025 | + echo esc_url(admin_url('index.php?page=gp-setup')); |
|
1026 | + ?>" class="button button-primary"><?php _e('Launch', 'invoicing'); ?></a> |
|
1027 | 1027 | </td> |
1028 | 1028 | </tr> |
1029 | 1029 | |
1030 | - <?php do_action( 'wpinv_tools_row' ); ?> |
|
1030 | + <?php do_action('wpinv_tools_row'); ?> |
|
1031 | 1031 | </tbody> |
1032 | 1032 | </table> |
1033 | - <?php do_action( 'wpinv_tools_after' ); ?> |
|
1033 | + <?php do_action('wpinv_tools_after'); ?> |
|
1034 | 1034 | <?php |
1035 | 1035 | echo ob_get_clean(); |
1036 | 1036 | } |
1037 | 1037 | |
1038 | 1038 | |
1039 | -function wpinv_descriptive_text_callback( $args ) { |
|
1040 | - echo wp_kses_post( $args['desc'] ); |
|
1039 | +function wpinv_descriptive_text_callback($args) { |
|
1040 | + echo wp_kses_post($args['desc']); |
|
1041 | 1041 | } |
1042 | 1042 | |
1043 | -function wpinv_raw_html_callback( $args ) { |
|
1043 | +function wpinv_raw_html_callback($args) { |
|
1044 | 1044 | echo $args['desc']; |
1045 | 1045 | } |
1046 | 1046 | |
1047 | -function wpinv_hook_callback( $args ) { |
|
1048 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
1047 | +function wpinv_hook_callback($args) { |
|
1048 | + do_action('wpinv_' . $args['id'], $args); |
|
1049 | 1049 | } |
1050 | 1050 | |
1051 | 1051 | function wpinv_set_settings_cap() { |
1052 | 1052 | return wpinv_get_capability(); |
1053 | 1053 | } |
1054 | -add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
|
1054 | +add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap'); |
|
1055 | 1055 | |
1056 | 1056 | |
1057 | -function wpinv_on_update_settings( $old_value, $value, $option ) { |
|
1058 | - $old = !empty( $old_value['remove_data_on_unistall'] ) ? 1 : ''; |
|
1059 | - $new = !empty( $value['remove_data_on_unistall'] ) ? 1 : ''; |
|
1057 | +function wpinv_on_update_settings($old_value, $value, $option) { |
|
1058 | + $old = !empty($old_value['remove_data_on_unistall']) ? 1 : ''; |
|
1059 | + $new = !empty($value['remove_data_on_unistall']) ? 1 : ''; |
|
1060 | 1060 | |
1061 | - if ( $old != $new ) { |
|
1062 | - update_option( 'wpinv_remove_data_on_invoice_unistall', $new ); |
|
1061 | + if ($old != $new) { |
|
1062 | + update_option('wpinv_remove_data_on_invoice_unistall', $new); |
|
1063 | 1063 | } |
1064 | 1064 | } |
1065 | -add_action( 'update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3 ); |
|
1065 | +add_action('update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3); |
|
1066 | 1066 | |
1067 | 1067 | /** |
1068 | 1068 | * Returns the merge tags help text. |
@@ -1071,16 +1071,16 @@ discard block |
||
1071 | 1071 | * |
1072 | 1072 | * @return string |
1073 | 1073 | */ |
1074 | -function wpinv_get_merge_tags_help_text( $subscription = false ) { |
|
1074 | +function wpinv_get_merge_tags_help_text($subscription = false) { |
|
1075 | 1075 | |
1076 | 1076 | $url = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f'; |
1077 | 1077 | $link = sprintf( |
1078 | 1078 | '<strong><a href="%s" target="_blank">%s</a></strong>', |
1079 | 1079 | $url, |
1080 | - esc_html__( 'View available merge tags.', 'wpinv-quotes' ) |
|
1080 | + esc_html__('View available merge tags.', 'wpinv-quotes') |
|
1081 | 1081 | ); |
1082 | 1082 | |
1083 | - $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' ); |
|
1083 | + $description = esc_html__('The content of the email (Merge Tags and HTML are allowed).', 'invoicing'); |
|
1084 | 1084 | |
1085 | 1085 | return "$description $link"; |
1086 | 1086 |
@@ -12,276 +12,276 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Metaboxes { |
14 | 14 | |
15 | - /** |
|
16 | - * Only save metaboxes once. |
|
17 | - * |
|
18 | - * @var boolean |
|
19 | - */ |
|
20 | - private static $saved_meta_boxes = false; |
|
21 | - |
|
22 | 15 | /** |
23 | - * Hook in methods. |
|
24 | - */ |
|
25 | - public static function init() { |
|
26 | - |
|
27 | - // Register metaboxes. |
|
28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
29 | - |
|
30 | - // Remove metaboxes. |
|
31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
32 | - |
|
33 | - // Rename metaboxes. |
|
34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
35 | - |
|
36 | - // Save metaboxes. |
|
37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Register core metaboxes. |
|
42 | - */ |
|
43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
16 | + * Only save metaboxes once. |
|
17 | + * |
|
18 | + * @var boolean |
|
19 | + */ |
|
20 | + private static $saved_meta_boxes = false; |
|
44 | 21 | |
45 | - // For invoices... |
|
46 | - self::add_invoice_meta_boxes( $post_type, $post ); |
|
47 | - |
|
48 | - // For payment forms. |
|
49 | - self::add_payment_form_meta_boxes( $post_type ); |
|
50 | - |
|
51 | - // For invoice items. |
|
52 | - self::add_item_meta_boxes( $post_type ); |
|
53 | - |
|
54 | - // For invoice discounts. |
|
55 | - if ( $post_type == 'wpi_discount' ) { |
|
56 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
57 | - } |
|
58 | - |
|
59 | - } |
|
22 | + /** |
|
23 | + * Hook in methods. |
|
24 | + */ |
|
25 | + public static function init() { |
|
60 | 26 | |
61 | - /** |
|
62 | - * Register core metaboxes. |
|
63 | - */ |
|
64 | - protected static function add_payment_form_meta_boxes( $post_type ) { |
|
27 | + // Register metaboxes. |
|
28 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
65 | 29 | |
66 | - // For payment forms. |
|
67 | - if ( $post_type == 'wpi_payment_form' ) { |
|
30 | + // Remove metaboxes. |
|
31 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
68 | 32 | |
69 | - // Design payment form. |
|
70 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
33 | + // Rename metaboxes. |
|
34 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
71 | 35 | |
72 | - // Payment form information. |
|
73 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
36 | + // Save metaboxes. |
|
37 | + add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | + } |
|
74 | 39 | |
75 | - } |
|
40 | + /** |
|
41 | + * Register core metaboxes. |
|
42 | + */ |
|
43 | + public static function add_meta_boxes( $post_type, $post ) { |
|
76 | 44 | |
77 | - } |
|
45 | + // For invoices... |
|
46 | + self::add_invoice_meta_boxes( $post_type, $post ); |
|
78 | 47 | |
79 | - /** |
|
80 | - * Register core metaboxes. |
|
81 | - */ |
|
82 | - protected static function add_item_meta_boxes( $post_type ) { |
|
48 | + // For payment forms. |
|
49 | + self::add_payment_form_meta_boxes( $post_type ); |
|
83 | 50 | |
84 | - if ( $post_type == 'wpi_item' ) { |
|
51 | + // For invoice items. |
|
52 | + self::add_item_meta_boxes( $post_type ); |
|
85 | 53 | |
86 | - // Item details. |
|
87 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
54 | + // For invoice discounts. |
|
55 | + if ( $post_type == 'wpi_discount' ) { |
|
56 | + add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
57 | + } |
|
88 | 58 | |
89 | - // If taxes are enabled, register the tax metabox. |
|
90 | - if ( wpinv_use_taxes() ) { |
|
91 | - add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
92 | - } |
|
59 | + } |
|
93 | 60 | |
94 | - // Item info. |
|
95 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
61 | + /** |
|
62 | + * Register core metaboxes. |
|
63 | + */ |
|
64 | + protected static function add_payment_form_meta_boxes( $post_type ) { |
|
96 | 65 | |
97 | - } |
|
66 | + // For payment forms. |
|
67 | + if ( $post_type == 'wpi_payment_form' ) { |
|
98 | 68 | |
99 | - } |
|
69 | + // Design payment form. |
|
70 | + add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
100 | 71 | |
101 | - /** |
|
102 | - * Register invoice metaboxes. |
|
103 | - */ |
|
104 | - protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
72 | + // Payment form information. |
|
73 | + add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
105 | 74 | |
106 | - // For invoices... |
|
107 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
108 | - $invoice = new WPInv_Invoice( $post ); |
|
75 | + } |
|
109 | 76 | |
110 | - // Resend invoice. |
|
111 | - if ( ! $invoice->is_draft() ) { |
|
77 | + } |
|
112 | 78 | |
113 | - add_meta_box( |
|
114 | - 'wpinv-mb-resend-invoice', |
|
115 | - sprintf( |
|
116 | - __( 'Resend %s', 'invoicing' ), |
|
117 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
118 | - ), |
|
119 | - 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
120 | - $post_type, |
|
121 | - 'side', |
|
122 | - 'low' |
|
123 | - ); |
|
79 | + /** |
|
80 | + * Register core metaboxes. |
|
81 | + */ |
|
82 | + protected static function add_item_meta_boxes( $post_type ) { |
|
124 | 83 | |
125 | - } |
|
84 | + if ( $post_type == 'wpi_item' ) { |
|
126 | 85 | |
127 | - // Subscriptions. |
|
128 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
129 | - if ( ! empty( $subscriptions ) ) { |
|
86 | + // Item details. |
|
87 | + add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
130 | 88 | |
131 | - if ( is_array( $subscriptions ) ) { |
|
132 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
133 | - } else { |
|
134 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
135 | - } |
|
89 | + // If taxes are enabled, register the tax metabox. |
|
90 | + if ( wpinv_use_taxes() ) { |
|
91 | + add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
92 | + } |
|
136 | 93 | |
137 | - if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
138 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
139 | - } |
|
94 | + // Item info. |
|
95 | + add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
140 | 96 | |
141 | - } |
|
97 | + } |
|
142 | 98 | |
143 | - // Invoice details. |
|
144 | - add_meta_box( |
|
145 | - 'wpinv-details', |
|
146 | - sprintf( |
|
147 | - __( '%s Details', 'invoicing' ), |
|
148 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
149 | - ), |
|
150 | - 'GetPaid_Meta_Box_Invoice_Details::output', |
|
151 | - $post_type, |
|
152 | - 'side' |
|
153 | - ); |
|
154 | - |
|
155 | - // Payment details. |
|
156 | - if ( ! $invoice->is_draft() ) { |
|
157 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
158 | - } |
|
99 | + } |
|
159 | 100 | |
160 | - // Billing details. |
|
161 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
101 | + /** |
|
102 | + * Register invoice metaboxes. |
|
103 | + */ |
|
104 | + protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
105 | + |
|
106 | + // For invoices... |
|
107 | + if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
108 | + $invoice = new WPInv_Invoice( $post ); |
|
109 | + |
|
110 | + // Resend invoice. |
|
111 | + if ( ! $invoice->is_draft() ) { |
|
112 | + |
|
113 | + add_meta_box( |
|
114 | + 'wpinv-mb-resend-invoice', |
|
115 | + sprintf( |
|
116 | + __( 'Resend %s', 'invoicing' ), |
|
117 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
118 | + ), |
|
119 | + 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
120 | + $post_type, |
|
121 | + 'side', |
|
122 | + 'low' |
|
123 | + ); |
|
124 | + |
|
125 | + } |
|
126 | + |
|
127 | + // Subscriptions. |
|
128 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
129 | + if ( ! empty( $subscriptions ) ) { |
|
130 | + |
|
131 | + if ( is_array( $subscriptions ) ) { |
|
132 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
133 | + } else { |
|
134 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
135 | + } |
|
136 | + |
|
137 | + if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
138 | + add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
139 | + } |
|
140 | + |
|
141 | + } |
|
142 | + |
|
143 | + // Invoice details. |
|
144 | + add_meta_box( |
|
145 | + 'wpinv-details', |
|
146 | + sprintf( |
|
147 | + __( '%s Details', 'invoicing' ), |
|
148 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
149 | + ), |
|
150 | + 'GetPaid_Meta_Box_Invoice_Details::output', |
|
151 | + $post_type, |
|
152 | + 'side' |
|
153 | + ); |
|
154 | + |
|
155 | + // Payment details. |
|
156 | + if ( ! $invoice->is_draft() ) { |
|
157 | + add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
158 | + } |
|
159 | + |
|
160 | + // Billing details. |
|
161 | + add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
162 | 162 | |
163 | - // Invoice items. |
|
164 | - add_meta_box( |
|
165 | - 'wpinv-items', |
|
166 | - sprintf( |
|
167 | - __( '%s Items', 'invoicing' ), |
|
168 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
169 | - ), |
|
170 | - 'GetPaid_Meta_Box_Invoice_Items::output', |
|
171 | - $post_type, |
|
172 | - 'normal', |
|
173 | - 'high' |
|
174 | - ); |
|
163 | + // Invoice items. |
|
164 | + add_meta_box( |
|
165 | + 'wpinv-items', |
|
166 | + sprintf( |
|
167 | + __( '%s Items', 'invoicing' ), |
|
168 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
169 | + ), |
|
170 | + 'GetPaid_Meta_Box_Invoice_Items::output', |
|
171 | + $post_type, |
|
172 | + 'normal', |
|
173 | + 'high' |
|
174 | + ); |
|
175 | 175 | |
176 | - // Invoice notes. |
|
177 | - add_meta_box( |
|
178 | - 'wpinv-notes', |
|
179 | - sprintf( |
|
180 | - __( '%s Notes', 'invoicing' ), |
|
181 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
182 | - ), |
|
183 | - 'WPInv_Meta_Box_Notes::output', |
|
184 | - $post_type, |
|
185 | - 'side', |
|
186 | - 'low' |
|
187 | - ); |
|
188 | - |
|
189 | - // Shipping Address. |
|
190 | - if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
191 | - add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
192 | - } |
|
193 | - |
|
194 | - // Payment form information. |
|
195 | - if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
196 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
197 | - } |
|
198 | - |
|
199 | - } |
|
200 | - |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Remove some metaboxes. |
|
205 | - */ |
|
206 | - public static function remove_meta_boxes() { |
|
207 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Rename other metaboxes. |
|
212 | - */ |
|
213 | - public static function rename_meta_boxes() { |
|
176 | + // Invoice notes. |
|
177 | + add_meta_box( |
|
178 | + 'wpinv-notes', |
|
179 | + sprintf( |
|
180 | + __( '%s Notes', 'invoicing' ), |
|
181 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
182 | + ), |
|
183 | + 'WPInv_Meta_Box_Notes::output', |
|
184 | + $post_type, |
|
185 | + 'side', |
|
186 | + 'low' |
|
187 | + ); |
|
188 | + |
|
189 | + // Shipping Address. |
|
190 | + if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
191 | + add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
192 | + } |
|
193 | + |
|
194 | + // Payment form information. |
|
195 | + if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
196 | + add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
197 | + } |
|
198 | + |
|
199 | + } |
|
200 | + |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Remove some metaboxes. |
|
205 | + */ |
|
206 | + public static function remove_meta_boxes() { |
|
207 | + remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Rename other metaboxes. |
|
212 | + */ |
|
213 | + public static function rename_meta_boxes() { |
|
214 | 214 | |
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Check if we're saving, then trigger an action based on the post type. |
|
219 | - * |
|
220 | - * @param int $post_id Post ID. |
|
221 | - * @param object $post Post object. |
|
222 | - */ |
|
223 | - public static function save_meta_boxes( $post_id, $post ) { |
|
224 | - $post_id = absint( $post_id ); |
|
225 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
226 | - |
|
227 | - // Do not save for ajax requests. |
|
228 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
229 | - return; |
|
230 | - } |
|
231 | - |
|
232 | - // $post_id and $post are required |
|
233 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
234 | - return; |
|
235 | - } |
|
236 | - |
|
237 | - // Dont' save meta boxes for revisions or autosaves. |
|
238 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
239 | - return; |
|
240 | - } |
|
241 | - |
|
242 | - // Check the nonce. |
|
243 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
244 | - return; |
|
245 | - } |
|
246 | - |
|
247 | - // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
248 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
249 | - return; |
|
250 | - } |
|
251 | - |
|
252 | - // Check user has permission to edit. |
|
253 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
254 | - return; |
|
255 | - } |
|
256 | - |
|
257 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
258 | - |
|
259 | - // We need this save event to run once to avoid potential endless loops. |
|
260 | - self::$saved_meta_boxes = true; |
|
261 | - |
|
262 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
263 | - |
|
264 | - } |
|
265 | - |
|
266 | - // Ensure this is our post type. |
|
267 | - $post_types_map = array( |
|
268 | - 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
269 | - 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
270 | - 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
271 | - ); |
|
272 | - |
|
273 | - // Is this our post type? |
|
274 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
275 | - return; |
|
276 | - } |
|
277 | - |
|
278 | - // We need this save event to run once to avoid potential endless loops. |
|
279 | - self::$saved_meta_boxes = true; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Check if we're saving, then trigger an action based on the post type. |
|
219 | + * |
|
220 | + * @param int $post_id Post ID. |
|
221 | + * @param object $post Post object. |
|
222 | + */ |
|
223 | + public static function save_meta_boxes( $post_id, $post ) { |
|
224 | + $post_id = absint( $post_id ); |
|
225 | + $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
226 | + |
|
227 | + // Do not save for ajax requests. |
|
228 | + if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
229 | + return; |
|
230 | + } |
|
231 | + |
|
232 | + // $post_id and $post are required |
|
233 | + if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
234 | + return; |
|
235 | + } |
|
236 | + |
|
237 | + // Dont' save meta boxes for revisions or autosaves. |
|
238 | + if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
239 | + return; |
|
240 | + } |
|
241 | + |
|
242 | + // Check the nonce. |
|
243 | + if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
244 | + return; |
|
245 | + } |
|
246 | + |
|
247 | + // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
248 | + if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
249 | + return; |
|
250 | + } |
|
251 | + |
|
252 | + // Check user has permission to edit. |
|
253 | + if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
254 | + return; |
|
255 | + } |
|
256 | + |
|
257 | + if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
258 | + |
|
259 | + // We need this save event to run once to avoid potential endless loops. |
|
260 | + self::$saved_meta_boxes = true; |
|
261 | + |
|
262 | + return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
263 | + |
|
264 | + } |
|
265 | + |
|
266 | + // Ensure this is our post type. |
|
267 | + $post_types_map = array( |
|
268 | + 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
269 | + 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
270 | + 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
271 | + ); |
|
272 | + |
|
273 | + // Is this our post type? |
|
274 | + if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
275 | + return; |
|
276 | + } |
|
277 | + |
|
278 | + // We need this save event to run once to avoid potential endless loops. |
|
279 | + self::$saved_meta_boxes = true; |
|
280 | 280 | |
281 | - // Save the post. |
|
282 | - $class = $post_types_map[ $post->post_type ]; |
|
283 | - $class::save( $post_id, $_POST, $post ); |
|
281 | + // Save the post. |
|
282 | + $class = $post_types_map[ $post->post_type ]; |
|
283 | + $class::save( $post_id, $_POST, $post ); |
|
284 | 284 | |
285 | - } |
|
285 | + } |
|
286 | 286 | |
287 | 287 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Metaboxes Admin Class |
@@ -25,35 +25,35 @@ discard block |
||
25 | 25 | public static function init() { |
26 | 26 | |
27 | 27 | // Register metaboxes. |
28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
28 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2); |
|
29 | 29 | |
30 | 30 | // Remove metaboxes. |
31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
31 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30); |
|
32 | 32 | |
33 | 33 | // Rename metaboxes. |
34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
34 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45); |
|
35 | 35 | |
36 | 36 | // Save metaboxes. |
37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
37 | + add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | 41 | * Register core metaboxes. |
42 | 42 | */ |
43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
43 | + public static function add_meta_boxes($post_type, $post) { |
|
44 | 44 | |
45 | 45 | // For invoices... |
46 | - self::add_invoice_meta_boxes( $post_type, $post ); |
|
46 | + self::add_invoice_meta_boxes($post_type, $post); |
|
47 | 47 | |
48 | 48 | // For payment forms. |
49 | - self::add_payment_form_meta_boxes( $post_type ); |
|
49 | + self::add_payment_form_meta_boxes($post_type); |
|
50 | 50 | |
51 | 51 | // For invoice items. |
52 | - self::add_item_meta_boxes( $post_type ); |
|
52 | + self::add_item_meta_boxes($post_type); |
|
53 | 53 | |
54 | 54 | // For invoice discounts. |
55 | - if ( $post_type == 'wpi_discount' ) { |
|
56 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
55 | + if ($post_type == 'wpi_discount') { |
|
56 | + add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | } |
@@ -61,16 +61,16 @@ discard block |
||
61 | 61 | /** |
62 | 62 | * Register core metaboxes. |
63 | 63 | */ |
64 | - protected static function add_payment_form_meta_boxes( $post_type ) { |
|
64 | + protected static function add_payment_form_meta_boxes($post_type) { |
|
65 | 65 | |
66 | 66 | // For payment forms. |
67 | - if ( $post_type == 'wpi_payment_form' ) { |
|
67 | + if ($post_type == 'wpi_payment_form') { |
|
68 | 68 | |
69 | 69 | // Design payment form. |
70 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
70 | + add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal'); |
|
71 | 71 | |
72 | 72 | // Payment form information. |
73 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
73 | + add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side'); |
|
74 | 74 | |
75 | 75 | } |
76 | 76 | |
@@ -79,20 +79,20 @@ discard block |
||
79 | 79 | /** |
80 | 80 | * Register core metaboxes. |
81 | 81 | */ |
82 | - protected static function add_item_meta_boxes( $post_type ) { |
|
82 | + protected static function add_item_meta_boxes($post_type) { |
|
83 | 83 | |
84 | - if ( $post_type == 'wpi_item' ) { |
|
84 | + if ($post_type == 'wpi_item') { |
|
85 | 85 | |
86 | 86 | // Item details. |
87 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
87 | + add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high'); |
|
88 | 88 | |
89 | 89 | // If taxes are enabled, register the tax metabox. |
90 | - if ( wpinv_use_taxes() ) { |
|
91 | - add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
90 | + if (wpinv_use_taxes()) { |
|
91 | + add_meta_box('wpinv_item_vat', __('Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high'); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | // Item info. |
95 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
95 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core'); |
|
96 | 96 | |
97 | 97 | } |
98 | 98 | |
@@ -101,20 +101,20 @@ discard block |
||
101 | 101 | /** |
102 | 102 | * Register invoice metaboxes. |
103 | 103 | */ |
104 | - protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
104 | + protected static function add_invoice_meta_boxes($post_type, $post) { |
|
105 | 105 | |
106 | 106 | // For invoices... |
107 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
108 | - $invoice = new WPInv_Invoice( $post ); |
|
107 | + if (getpaid_is_invoice_post_type($post_type)) { |
|
108 | + $invoice = new WPInv_Invoice($post); |
|
109 | 109 | |
110 | 110 | // Resend invoice. |
111 | - if ( ! $invoice->is_draft() ) { |
|
111 | + if (!$invoice->is_draft()) { |
|
112 | 112 | |
113 | 113 | add_meta_box( |
114 | 114 | 'wpinv-mb-resend-invoice', |
115 | 115 | sprintf( |
116 | - __( 'Resend %s', 'invoicing' ), |
|
117 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
116 | + __('Resend %s', 'invoicing'), |
|
117 | + ucfirst($invoice->get_invoice_quote_type()) |
|
118 | 118 | ), |
119 | 119 | 'GetPaid_Meta_Box_Resend_Invoice::output', |
120 | 120 | $post_type, |
@@ -125,17 +125,17 @@ discard block |
||
125 | 125 | } |
126 | 126 | |
127 | 127 | // Subscriptions. |
128 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
129 | - if ( ! empty( $subscriptions ) ) { |
|
128 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
129 | + if (!empty($subscriptions)) { |
|
130 | 130 | |
131 | - if ( is_array( $subscriptions ) ) { |
|
132 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
131 | + if (is_array($subscriptions)) { |
|
132 | + add_meta_box('wpinv-mb-subscriptions', __('Related Subscriptions', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced'); |
|
133 | 133 | } else { |
134 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
134 | + add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced'); |
|
135 | 135 | } |
136 | 136 | |
137 | - if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
138 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
137 | + if (getpaid_count_subscription_invoices($invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id()) > 1) { |
|
138 | + add_meta_box('wpinv-mb-subscription-invoices', __('Related Payments', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced'); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | } |
@@ -144,8 +144,8 @@ discard block |
||
144 | 144 | add_meta_box( |
145 | 145 | 'wpinv-details', |
146 | 146 | sprintf( |
147 | - __( '%s Details', 'invoicing' ), |
|
148 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
147 | + __('%s Details', 'invoicing'), |
|
148 | + ucfirst($invoice->get_invoice_quote_type()) |
|
149 | 149 | ), |
150 | 150 | 'GetPaid_Meta_Box_Invoice_Details::output', |
151 | 151 | $post_type, |
@@ -153,19 +153,19 @@ discard block |
||
153 | 153 | ); |
154 | 154 | |
155 | 155 | // Payment details. |
156 | - if ( ! $invoice->is_draft() ) { |
|
157 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
156 | + if (!$invoice->is_draft()) { |
|
157 | + add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default'); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | // Billing details. |
161 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
161 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high'); |
|
162 | 162 | |
163 | 163 | // Invoice items. |
164 | 164 | add_meta_box( |
165 | 165 | 'wpinv-items', |
166 | 166 | sprintf( |
167 | - __( '%s Items', 'invoicing' ), |
|
168 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
167 | + __('%s Items', 'invoicing'), |
|
168 | + ucfirst($invoice->get_invoice_quote_type()) |
|
169 | 169 | ), |
170 | 170 | 'GetPaid_Meta_Box_Invoice_Items::output', |
171 | 171 | $post_type, |
@@ -177,8 +177,8 @@ discard block |
||
177 | 177 | add_meta_box( |
178 | 178 | 'wpinv-notes', |
179 | 179 | sprintf( |
180 | - __( '%s Notes', 'invoicing' ), |
|
181 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
180 | + __('%s Notes', 'invoicing'), |
|
181 | + ucfirst($invoice->get_invoice_quote_type()) |
|
182 | 182 | ), |
183 | 183 | 'WPInv_Meta_Box_Notes::output', |
184 | 184 | $post_type, |
@@ -187,13 +187,13 @@ discard block |
||
187 | 187 | ); |
188 | 188 | |
189 | 189 | // Shipping Address. |
190 | - if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
191 | - add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
190 | + if (get_post_meta($invoice->get_id(), 'shipping_address', true)) { |
|
191 | + add_meta_box('wpinv-invoice-shipping-details', __('Shipping Address', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high'); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | // Payment form information. |
195 | - if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
196 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
195 | + if (get_post_meta($invoice->get_id(), 'payment_form_data', true)) { |
|
196 | + add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high'); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * Remove some metaboxes. |
205 | 205 | */ |
206 | 206 | public static function remove_meta_boxes() { |
207 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
207 | + remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -220,46 +220,46 @@ discard block |
||
220 | 220 | * @param int $post_id Post ID. |
221 | 221 | * @param object $post Post object. |
222 | 222 | */ |
223 | - public static function save_meta_boxes( $post_id, $post ) { |
|
224 | - $post_id = absint( $post_id ); |
|
225 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
223 | + public static function save_meta_boxes($post_id, $post) { |
|
224 | + $post_id = absint($post_id); |
|
225 | + $data = wp_kses_post_deep(wp_unslash($_POST)); |
|
226 | 226 | |
227 | 227 | // Do not save for ajax requests. |
228 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
228 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
229 | 229 | return; |
230 | 230 | } |
231 | 231 | |
232 | 232 | // $post_id and $post are required |
233 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
233 | + if (empty($post_id) || empty($post) || self::$saved_meta_boxes) { |
|
234 | 234 | return; |
235 | 235 | } |
236 | 236 | |
237 | 237 | // Dont' save meta boxes for revisions or autosaves. |
238 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
238 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
239 | 239 | return; |
240 | 240 | } |
241 | 241 | |
242 | 242 | // Check the nonce. |
243 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
243 | + if (empty($data['getpaid_meta_nonce']) || !wp_verify_nonce($data['getpaid_meta_nonce'], 'getpaid_meta_nonce')) { |
|
244 | 244 | return; |
245 | 245 | } |
246 | 246 | |
247 | 247 | // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
248 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
248 | + if (empty($data['post_ID']) || absint($data['post_ID']) !== $post_id) { |
|
249 | 249 | return; |
250 | 250 | } |
251 | 251 | |
252 | 252 | // Check user has permission to edit. |
253 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
253 | + if (!current_user_can('edit_post', $post_id)) { |
|
254 | 254 | return; |
255 | 255 | } |
256 | 256 | |
257 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
257 | + if (getpaid_is_invoice_post_type($post->post_type)) { |
|
258 | 258 | |
259 | 259 | // We need this save event to run once to avoid potential endless loops. |
260 | 260 | self::$saved_meta_boxes = true; |
261 | 261 | |
262 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
262 | + return GetPaid_Meta_Box_Invoice_Address::save($post_id); |
|
263 | 263 | |
264 | 264 | } |
265 | 265 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | ); |
272 | 272 | |
273 | 273 | // Is this our post type? |
274 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
274 | + if (!isset($post_types_map[$post->post_type])) { |
|
275 | 275 | return; |
276 | 276 | } |
277 | 277 | |
@@ -279,8 +279,8 @@ discard block |
||
279 | 279 | self::$saved_meta_boxes = true; |
280 | 280 | |
281 | 281 | // Save the post. |
282 | - $class = $post_types_map[ $post->post_type ]; |
|
283 | - $class::save( $post_id, $_POST, $post ); |
|
282 | + $class = $post_types_map[$post->post_type]; |
|
283 | + $class::save($post_id, $_POST, $post); |
|
284 | 284 | |
285 | 285 | } |
286 | 286 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * WPInv_Ajax class. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | * Hook in ajax handlers. |
18 | 18 | */ |
19 | 19 | public static function init() { |
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
20 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
21 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
22 | 22 | self::add_ajax_events(); |
23 | 23 | } |
24 | 24 | |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public static function define_ajax() { |
29 | 29 | |
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
30 | + if (!empty($_GET['wpinv-ajax'])) { |
|
31 | + getpaid_maybe_define_constant('DOING_AJAX', true); |
|
32 | + getpaid_maybe_define_constant('WPInv_DOING_AJAX', true); |
|
33 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
35 | 35 | } |
36 | 36 | $GLOBALS['wpdb']->hide_errors(); |
37 | 37 | } |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | * @since 1.0.18 |
45 | 45 | */ |
46 | 46 | private static function wpinv_ajax_headers() { |
47 | - if ( ! headers_sent() ) { |
|
47 | + if (!headers_sent()) { |
|
48 | 48 | send_origin_headers(); |
49 | 49 | send_nosniff_header(); |
50 | 50 | nocache_headers(); |
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
51 | + header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
52 | + header('X-Robots-Tag: noindex'); |
|
53 | + status_header(200); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | public static function do_wpinv_ajax() { |
61 | 61 | global $wp_query; |
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
63 | + if (!empty($_GET['wpinv-ajax'])) { |
|
64 | + $wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax']))); |
|
65 | 65 | } |
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get('wpinv-ajax'); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
69 | + if ($action) { |
|
70 | 70 | self::wpinv_ajax_headers(); |
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
71 | + $action = sanitize_text_field($action); |
|
72 | + do_action('wpinv_ajax_' . $action); |
|
73 | 73 | wp_die(); |
74 | 74 | } |
75 | 75 | |
@@ -105,36 +105,36 @@ discard block |
||
105 | 105 | 'payment_form_refresh_prices' => true, |
106 | 106 | ); |
107 | 107 | |
108 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
109 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
110 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
108 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
109 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
110 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
111 | 111 | |
112 | - if ( $nopriv ) { |
|
113 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
114 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
115 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
112 | + if ($nopriv) { |
|
113 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
114 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
115 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | 120 | public static function add_note() { |
121 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
121 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
122 | 122 | |
123 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
123 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
124 | 124 | die(-1); |
125 | 125 | } |
126 | 126 | |
127 | - $post_id = absint( $_POST['post_id'] ); |
|
128 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
129 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
127 | + $post_id = absint($_POST['post_id']); |
|
128 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
129 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
130 | 130 | |
131 | 131 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
132 | 132 | |
133 | - if ( $post_id > 0 ) { |
|
134 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
133 | + if ($post_id > 0) { |
|
134 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
135 | 135 | |
136 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
137 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
136 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
137 | + wpinv_get_invoice_note_line_item($note_id); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -142,16 +142,16 @@ discard block |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | public static function delete_note() { |
145 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
145 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
146 | 146 | |
147 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
147 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
148 | 148 | die(-1); |
149 | 149 | } |
150 | 150 | |
151 | - $note_id = (int)$_POST['note_id']; |
|
151 | + $note_id = (int) $_POST['note_id']; |
|
152 | 152 | |
153 | - if ( $note_id > 0 ) { |
|
154 | - wp_delete_comment( $note_id, true ); |
|
153 | + if ($note_id > 0) { |
|
154 | + wp_delete_comment($note_id, true); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | die(); |
@@ -169,34 +169,34 @@ discard block |
||
169 | 169 | public static function get_billing_details() { |
170 | 170 | |
171 | 171 | // Verify nonce. |
172 | - check_ajax_referer( 'wpinv-nonce' ); |
|
172 | + check_ajax_referer('wpinv-nonce'); |
|
173 | 173 | |
174 | 174 | // Can the user manage the plugin? |
175 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
175 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
176 | 176 | die(-1); |
177 | 177 | } |
178 | 178 | |
179 | 179 | // Do we have a user id? |
180 | 180 | $user_id = $_GET['user_id']; |
181 | 181 | |
182 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
182 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
183 | 183 | die(-1); |
184 | 184 | } |
185 | 185 | |
186 | 186 | // Fetch the billing details. |
187 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
188 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
187 | + $billing_details = wpinv_get_user_address($user_id); |
|
188 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
189 | 189 | |
190 | 190 | // unset the user id and email. |
191 | - $to_ignore = array( 'user_id', 'email' ); |
|
191 | + $to_ignore = array('user_id', 'email'); |
|
192 | 192 | |
193 | - foreach ( $to_ignore as $key ) { |
|
194 | - if ( isset( $billing_details[ $key ] ) ) { |
|
195 | - unset( $billing_details[ $key ] ); |
|
193 | + foreach ($to_ignore as $key) { |
|
194 | + if (isset($billing_details[$key])) { |
|
195 | + unset($billing_details[$key]); |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | |
199 | - wp_send_json_success( $billing_details ); |
|
199 | + wp_send_json_success($billing_details); |
|
200 | 200 | |
201 | 201 | } |
202 | 202 | |
@@ -206,47 +206,47 @@ discard block |
||
206 | 206 | public static function check_new_user_email() { |
207 | 207 | |
208 | 208 | // Verify nonce. |
209 | - check_ajax_referer( 'wpinv-nonce' ); |
|
209 | + check_ajax_referer('wpinv-nonce'); |
|
210 | 210 | |
211 | 211 | // Can the user manage the plugin? |
212 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
212 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
213 | 213 | die(-1); |
214 | 214 | } |
215 | 215 | |
216 | 216 | // We need an email address. |
217 | - if ( empty( $_GET['email'] ) ) { |
|
218 | - _e( "Provide the new user's email address", 'invoicing' ); |
|
217 | + if (empty($_GET['email'])) { |
|
218 | + _e("Provide the new user's email address", 'invoicing'); |
|
219 | 219 | exit; |
220 | 220 | } |
221 | 221 | |
222 | 222 | // Ensure the email is valid. |
223 | - $email = sanitize_text_field( $_GET['email'] ); |
|
224 | - if ( ! is_email( $email ) ) { |
|
225 | - _e( 'Invalid email address', 'invoicing' ); |
|
223 | + $email = sanitize_text_field($_GET['email']); |
|
224 | + if (!is_email($email)) { |
|
225 | + _e('Invalid email address', 'invoicing'); |
|
226 | 226 | exit; |
227 | 227 | } |
228 | 228 | |
229 | 229 | // And it does not exist. |
230 | - $id = email_exists( $email ); |
|
231 | - if ( $id ) { |
|
232 | - wp_send_json_success( compact( 'id' ) ); |
|
230 | + $id = email_exists($email); |
|
231 | + if ($id) { |
|
232 | + wp_send_json_success(compact('id')); |
|
233 | 233 | } |
234 | 234 | |
235 | - wp_send_json_success( true ); |
|
235 | + wp_send_json_success(true); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | public static function run_tool() { |
239 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
240 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
239 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
240 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
241 | 241 | die(-1); |
242 | 242 | } |
243 | 243 | |
244 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
244 | + $tool = sanitize_text_field($_POST['tool']); |
|
245 | 245 | |
246 | - do_action( 'wpinv_run_tool' ); |
|
246 | + do_action('wpinv_run_tool'); |
|
247 | 247 | |
248 | - if ( !empty( $tool ) ) { |
|
249 | - do_action( 'wpinv_tool_' . $tool ); |
|
248 | + if (!empty($tool)) { |
|
249 | + do_action('wpinv_tool_' . $tool); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 | |
@@ -256,43 +256,43 @@ discard block |
||
256 | 256 | public static function get_payment_form() { |
257 | 257 | |
258 | 258 | // Check nonce. |
259 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
259 | + check_ajax_referer('getpaid_form_nonce'); |
|
260 | 260 | |
261 | 261 | // Is the request set up correctly? |
262 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
262 | + if (empty($_GET['form']) && empty($_GET['item'])) { |
|
263 | 263 | echo aui()->alert( |
264 | 264 | array( |
265 | 265 | 'type' => 'warning', |
266 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
266 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
267 | 267 | ) |
268 | 268 | ); |
269 | 269 | exit; |
270 | 270 | } |
271 | 271 | |
272 | 272 | // Payment form or button? |
273 | - if ( ! empty( $_GET['form'] ) ) { |
|
274 | - $form = urldecode( $_GET['form'] ); |
|
273 | + if (!empty($_GET['form'])) { |
|
274 | + $form = urldecode($_GET['form']); |
|
275 | 275 | |
276 | - if ( false !== strpos( $form, '|' ) ) { |
|
277 | - $form_pos = strpos( $form, '|' ); |
|
278 | - $_items = getpaid_convert_items_to_array( substr( $form, $form_pos + 1 ) ); |
|
279 | - $form = substr( $form, 0, $form_pos ); |
|
276 | + if (false !== strpos($form, '|')) { |
|
277 | + $form_pos = strpos($form, '|'); |
|
278 | + $_items = getpaid_convert_items_to_array(substr($form, $form_pos + 1)); |
|
279 | + $form = substr($form, 0, $form_pos); |
|
280 | 280 | |
281 | 281 | // Retrieve appropriate payment form. |
282 | - $payment_form = new GetPaid_Payment_Form( $form ); |
|
283 | - $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
282 | + $payment_form = new GetPaid_Payment_Form($form); |
|
283 | + $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
284 | 284 | |
285 | 285 | $items = array(); |
286 | 286 | $item_ids = array(); |
287 | 287 | |
288 | - foreach ( $_items as $item_id => $qty ) { |
|
289 | - if ( ! in_array( $item_id, $item_ids ) ) { |
|
290 | - $item = new GetPaid_Form_Item( $item_id ); |
|
291 | - $item->set_quantity( $qty ); |
|
288 | + foreach ($_items as $item_id => $qty) { |
|
289 | + if (!in_array($item_id, $item_ids)) { |
|
290 | + $item = new GetPaid_Form_Item($item_id); |
|
291 | + $item->set_quantity($qty); |
|
292 | 292 | |
293 | - if ( 0 == $qty ) { |
|
294 | - $item->set_allow_quantities( true ); |
|
295 | - $item->set_is_required( false ); |
|
293 | + if (0 == $qty) { |
|
294 | + $item->set_allow_quantities(true); |
|
295 | + $item->set_is_required(false); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | $item_ids[] = $item->get_id(); |
@@ -300,10 +300,10 @@ discard block |
||
300 | 300 | } |
301 | 301 | } |
302 | 302 | |
303 | - if ( ! $payment_form->is_default() ) { |
|
303 | + if (!$payment_form->is_default()) { |
|
304 | 304 | |
305 | - foreach ( $payment_form->get_items() as $item ) { |
|
306 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
305 | + foreach ($payment_form->get_items() as $item) { |
|
306 | + if (!in_array($item->get_id(), $item_ids)) { |
|
307 | 307 | $item_ids[] = $item->get_id(); |
308 | 308 | $items[] = $item; |
309 | 309 | } |
@@ -311,23 +311,23 @@ discard block |
||
311 | 311 | |
312 | 312 | } |
313 | 313 | |
314 | - $payment_form->set_items( $items ); |
|
315 | - $extra_items = esc_attr( getpaid_convert_items_to_string( $_items ) ); |
|
316 | - $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items ); |
|
314 | + $payment_form->set_items($items); |
|
315 | + $extra_items = esc_attr(getpaid_convert_items_to_string($_items)); |
|
316 | + $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items); |
|
317 | 317 | $extra_items = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />"; |
318 | 318 | $extra_items .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />"; |
319 | - $payment_form->display( $extra_items ); |
|
320 | - remove_filter( 'wpinv_force_default_payment_form', '__return_true' ); |
|
319 | + $payment_form->display($extra_items); |
|
320 | + remove_filter('wpinv_force_default_payment_form', '__return_true'); |
|
321 | 321 | |
322 | 322 | } else { |
323 | - getpaid_display_payment_form( $form ); |
|
323 | + getpaid_display_payment_form($form); |
|
324 | 324 | } |
325 | 325 | |
326 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
327 | - getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) ); |
|
326 | + } else if (!empty($_GET['invoice'])) { |
|
327 | + getpaid_display_invoice_payment_form(urldecode($_GET['invoice'])); |
|
328 | 328 | } else { |
329 | - $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) ); |
|
330 | - getpaid_display_item_payment_form( $items ); |
|
329 | + $items = getpaid_convert_items_to_array(urldecode($_GET['item'])); |
|
330 | + getpaid_display_item_payment_form($items); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | exit; |
@@ -342,17 +342,17 @@ discard block |
||
342 | 342 | public static function payment_form() { |
343 | 343 | |
344 | 344 | // Check nonce. |
345 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
345 | + check_ajax_referer('getpaid_form_nonce'); |
|
346 | 346 | |
347 | 347 | // ... form fields... |
348 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
349 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
348 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
349 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
350 | 350 | exit; |
351 | 351 | } |
352 | 352 | |
353 | 353 | // Process the payment form. |
354 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
355 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
354 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
355 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
356 | 356 | $checkout->process_checkout(); |
357 | 357 | |
358 | 358 | exit; |
@@ -365,55 +365,55 @@ discard block |
||
365 | 365 | */ |
366 | 366 | public static function get_payment_form_states_field() { |
367 | 367 | |
368 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
368 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
369 | 369 | exit; |
370 | 370 | } |
371 | 371 | |
372 | - $elements = getpaid_get_payment_form_elements( $_GET['form'] ); |
|
372 | + $elements = getpaid_get_payment_form_elements($_GET['form']); |
|
373 | 373 | |
374 | - if ( empty( $elements ) ) { |
|
374 | + if (empty($elements)) { |
|
375 | 375 | exit; |
376 | 376 | } |
377 | 377 | |
378 | 378 | $address_fields = array(); |
379 | - foreach ( $elements as $element ) { |
|
380 | - if ( 'address' === $element['type'] ) { |
|
379 | + foreach ($elements as $element) { |
|
380 | + if ('address' === $element['type']) { |
|
381 | 381 | $address_fields = $element; |
382 | 382 | break; |
383 | 383 | } |
384 | 384 | } |
385 | 385 | |
386 | - if ( empty( $address_fields ) ) { |
|
386 | + if (empty($address_fields)) { |
|
387 | 387 | exit; |
388 | 388 | } |
389 | 389 | |
390 | - foreach ( $address_fields['fields'] as $address_field ) { |
|
390 | + foreach ($address_fields['fields'] as $address_field) { |
|
391 | 391 | |
392 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
392 | + if ('wpinv_state' == $address_field['name']) { |
|
393 | 393 | |
394 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
395 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
396 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
397 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
398 | - $value = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : ''; |
|
399 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
394 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
395 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
396 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
397 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
398 | + $value = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : ''; |
|
399 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
400 | 400 | |
401 | - if ( ! empty( $address_field['required'] ) ) { |
|
401 | + if (!empty($address_field['required'])) { |
|
402 | 402 | $label .= "<span class='text-danger'> *</span>"; |
403 | 403 | } |
404 | 404 | |
405 | - $html = getpaid_get_states_select_markup ( |
|
406 | - sanitize_text_field( $_GET['country'] ), |
|
405 | + $html = getpaid_get_states_select_markup( |
|
406 | + sanitize_text_field($_GET['country']), |
|
407 | 407 | $value, |
408 | 408 | $placeholder, |
409 | 409 | $label, |
410 | 410 | $description, |
411 | - ! empty( $address_field['required'] ), |
|
411 | + !empty($address_field['required']), |
|
412 | 412 | $wrap_class, |
413 | - wpinv_clean( $_GET['name'] ) |
|
413 | + wpinv_clean($_GET['name']) |
|
414 | 414 | ); |
415 | 415 | |
416 | - wp_send_json_success( $html ); |
|
416 | + wp_send_json_success($html); |
|
417 | 417 | exit; |
418 | 418 | |
419 | 419 | } |
@@ -429,66 +429,66 @@ discard block |
||
429 | 429 | public static function recalculate_invoice_totals() { |
430 | 430 | |
431 | 431 | // Verify nonce. |
432 | - check_ajax_referer( 'wpinv-nonce' ); |
|
432 | + check_ajax_referer('wpinv-nonce'); |
|
433 | 433 | |
434 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
434 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
435 | 435 | exit; |
436 | 436 | } |
437 | 437 | |
438 | 438 | // We need an invoice. |
439 | - if ( empty( $_POST['post_id'] ) ) { |
|
439 | + if (empty($_POST['post_id'])) { |
|
440 | 440 | exit; |
441 | 441 | } |
442 | 442 | |
443 | 443 | // Fetch the invoice. |
444 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
444 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
445 | 445 | |
446 | 446 | // Ensure it exists. |
447 | - if ( ! $invoice->get_id() ) { |
|
447 | + if (!$invoice->get_id()) { |
|
448 | 448 | exit; |
449 | 449 | } |
450 | 450 | |
451 | 451 | // Maybe set the country, state, currency. |
452 | - foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) { |
|
453 | - if ( isset( $_POST[ $key ] ) ) { |
|
452 | + foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) { |
|
453 | + if (isset($_POST[$key])) { |
|
454 | 454 | $method = "set_$key"; |
455 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
455 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 | |
459 | 459 | // Maybe disable taxes. |
460 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
460 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
461 | 461 | |
462 | 462 | // Discount code. |
463 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
464 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
465 | - if ( $discount->exists() ) { |
|
466 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
463 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
464 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
465 | + if ($discount->exists()) { |
|
466 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
467 | 467 | } else { |
468 | - $invoice->remove_discount( 'discount_code' ); |
|
468 | + $invoice->remove_discount('discount_code'); |
|
469 | 469 | } |
470 | 470 | } |
471 | 471 | |
472 | 472 | // Recalculate totals. |
473 | 473 | $invoice->recalculate_total(); |
474 | 474 | |
475 | - $total = wpinv_price( $invoice->get_total(), $invoice->get_currency() ); |
|
476 | - $suscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
477 | - if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
478 | - $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() ); |
|
479 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
475 | + $total = wpinv_price($invoice->get_total(), $invoice->get_currency()); |
|
476 | + $suscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
477 | + if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
478 | + $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency()); |
|
479 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | $totals = array( |
483 | - 'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
|
484 | - 'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
485 | - 'tax' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
|
483 | + 'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()), |
|
484 | + 'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
485 | + 'tax' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()), |
|
486 | 486 | 'total' => $total, |
487 | 487 | ); |
488 | 488 | |
489 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
489 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
490 | 490 | |
491 | - wp_send_json_success( compact( 'totals' ) ); |
|
491 | + wp_send_json_success(compact('totals')); |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | /** |
@@ -497,33 +497,33 @@ discard block |
||
497 | 497 | public static function get_invoice_items() { |
498 | 498 | |
499 | 499 | // Verify nonce. |
500 | - check_ajax_referer( 'wpinv-nonce' ); |
|
500 | + check_ajax_referer('wpinv-nonce'); |
|
501 | 501 | |
502 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
502 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
503 | 503 | exit; |
504 | 504 | } |
505 | 505 | |
506 | 506 | // We need an invoice and items. |
507 | - if ( empty( $_POST['post_id'] ) ) { |
|
507 | + if (empty($_POST['post_id'])) { |
|
508 | 508 | exit; |
509 | 509 | } |
510 | 510 | |
511 | 511 | // Fetch the invoice. |
512 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
512 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
513 | 513 | |
514 | 514 | // Ensure it exists. |
515 | - if ( ! $invoice->get_id() ) { |
|
515 | + if (!$invoice->get_id()) { |
|
516 | 516 | exit; |
517 | 517 | } |
518 | 518 | |
519 | 519 | // Return an array of invoice items. |
520 | 520 | $items = array(); |
521 | 521 | |
522 | - foreach ( $invoice->get_items() as $item ) { |
|
523 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() ); |
|
522 | + foreach ($invoice->get_items() as $item) { |
|
523 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal()); |
|
524 | 524 | } |
525 | 525 | |
526 | - wp_send_json_success( compact( 'items' ) ); |
|
526 | + wp_send_json_success(compact('items')); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -532,50 +532,50 @@ discard block |
||
532 | 532 | public static function edit_invoice_item() { |
533 | 533 | |
534 | 534 | // Verify nonce. |
535 | - check_ajax_referer( 'wpinv-nonce' ); |
|
535 | + check_ajax_referer('wpinv-nonce'); |
|
536 | 536 | |
537 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
537 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
538 | 538 | exit; |
539 | 539 | } |
540 | 540 | |
541 | 541 | // We need an invoice and item details. |
542 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
542 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
543 | 543 | exit; |
544 | 544 | } |
545 | 545 | |
546 | 546 | // Fetch the invoice. |
547 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
547 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
548 | 548 | |
549 | 549 | // Ensure it exists and its not been paid for. |
550 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
550 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
551 | 551 | exit; |
552 | 552 | } |
553 | 553 | |
554 | 554 | // Format the data. |
555 | - $data = wp_kses_post_deep( wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ) ); |
|
555 | + $data = wp_kses_post_deep(wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field'))); |
|
556 | 556 | |
557 | 557 | // Ensure that we have an item id. |
558 | - if ( empty( $data['id'] ) ) { |
|
558 | + if (empty($data['id'])) { |
|
559 | 559 | exit; |
560 | 560 | } |
561 | 561 | |
562 | 562 | // Abort if the invoice does not have the specified item. |
563 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
563 | + $item = $invoice->get_item((int) $data['id']); |
|
564 | 564 | |
565 | - if ( empty( $item ) ) { |
|
565 | + if (empty($item)) { |
|
566 | 566 | exit; |
567 | 567 | } |
568 | 568 | |
569 | 569 | // Update the item. |
570 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
571 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
572 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
573 | - $item->set_quantity( floatval( $data['quantity'] ) ); |
|
570 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
571 | + $item->set_name(sanitize_text_field($data['name'])); |
|
572 | + $item->set_description(wp_kses_post($data['description'])); |
|
573 | + $item->set_quantity(floatval($data['quantity'])); |
|
574 | 574 | |
575 | 575 | // Add it to the invoice. |
576 | - $error = $invoice->add_item( $item ); |
|
576 | + $error = $invoice->add_item($item); |
|
577 | 577 | $alert = false; |
578 | - if ( is_wp_error( $error ) ) { |
|
578 | + if (is_wp_error($error)) { |
|
579 | 579 | $alert = $error->get_error_message(); |
580 | 580 | } |
581 | 581 | |
@@ -588,11 +588,11 @@ discard block |
||
588 | 588 | // Return an array of invoice items. |
589 | 589 | $items = array(); |
590 | 590 | |
591 | - foreach ( $invoice->get_items() as $item ) { |
|
592 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
591 | + foreach ($invoice->get_items() as $item) { |
|
592 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
593 | 593 | } |
594 | 594 | |
595 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
595 | + wp_send_json_success(compact('items', 'alert')); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | /** |
@@ -601,53 +601,53 @@ discard block |
||
601 | 601 | public static function create_invoice_item() { |
602 | 602 | |
603 | 603 | // Verify nonce. |
604 | - check_ajax_referer( 'wpinv-nonce' ); |
|
604 | + check_ajax_referer('wpinv-nonce'); |
|
605 | 605 | |
606 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
606 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
607 | 607 | exit; |
608 | 608 | } |
609 | 609 | |
610 | 610 | // We need an invoice and item details. |
611 | - if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) { |
|
611 | + if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) { |
|
612 | 612 | exit; |
613 | 613 | } |
614 | 614 | |
615 | 615 | // Fetch the invoice. |
616 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['invoice_id'] ) ); |
|
616 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['invoice_id'])); |
|
617 | 617 | |
618 | 618 | // Ensure it exists and its not been paid for. |
619 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
619 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
620 | 620 | exit; |
621 | 621 | } |
622 | 622 | |
623 | 623 | // Format the data. |
624 | - $data = wp_unslash( $_POST['_wpinv_quick'] ); |
|
624 | + $data = wp_unslash($_POST['_wpinv_quick']); |
|
625 | 625 | |
626 | 626 | $item = new WPInv_Item(); |
627 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
628 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
629 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
630 | - $item->set_type( sanitize_text_field( $data['type'] ) ); |
|
631 | - $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) ); |
|
632 | - $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) ); |
|
633 | - $item->set_status( 'publish' ); |
|
627 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
628 | + $item->set_name(sanitize_text_field($data['name'])); |
|
629 | + $item->set_description(wp_kses_post($data['description'])); |
|
630 | + $item->set_type(sanitize_text_field($data['type'])); |
|
631 | + $item->set_vat_rule(sanitize_text_field($data['vat_rule'])); |
|
632 | + $item->set_vat_class(sanitize_text_field($data['vat_class'])); |
|
633 | + $item->set_status('publish'); |
|
634 | 634 | $item->save(); |
635 | 635 | |
636 | - if ( ! $item->exists() ) { |
|
637 | - $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' ); |
|
638 | - wp_send_json_success( compact( 'alert' ) ); |
|
636 | + if (!$item->exists()) { |
|
637 | + $alert = __('Could not create invoice item. Please try again.', 'invoicing'); |
|
638 | + wp_send_json_success(compact('alert')); |
|
639 | 639 | } |
640 | 640 | |
641 | - $item = new GetPaid_Form_Item( $item->get_id() ); |
|
642 | - $item->set_quantity( floatval( $data['qty'] ) ); |
|
641 | + $item = new GetPaid_Form_Item($item->get_id()); |
|
642 | + $item->set_quantity(floatval($data['qty'])); |
|
643 | 643 | |
644 | 644 | // Add it to the invoice. |
645 | - $error = $invoice->add_item( $item ); |
|
645 | + $error = $invoice->add_item($item); |
|
646 | 646 | $alert = false; |
647 | 647 | |
648 | - if ( is_wp_error( $error ) ) { |
|
648 | + if (is_wp_error($error)) { |
|
649 | 649 | $alert = $error->get_error_message(); |
650 | - wp_send_json_success( compact( 'alert' ) ); |
|
650 | + wp_send_json_success(compact('alert')); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | // Update totals. |
@@ -660,9 +660,9 @@ discard block |
||
660 | 660 | $invoice->recalculate_total(); |
661 | 661 | $invoice->save(); |
662 | 662 | ob_start(); |
663 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
663 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
664 | 664 | $row = ob_get_clean(); |
665 | - wp_send_json_success( compact( 'row' ) ); |
|
665 | + wp_send_json_success(compact('row')); |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | /** |
@@ -671,33 +671,33 @@ discard block |
||
671 | 671 | public static function remove_invoice_item() { |
672 | 672 | |
673 | 673 | // Verify nonce. |
674 | - check_ajax_referer( 'wpinv-nonce' ); |
|
674 | + check_ajax_referer('wpinv-nonce'); |
|
675 | 675 | |
676 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
676 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
677 | 677 | exit; |
678 | 678 | } |
679 | 679 | |
680 | 680 | // We need an invoice and an item. |
681 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
681 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
682 | 682 | exit; |
683 | 683 | } |
684 | 684 | |
685 | 685 | // Fetch the invoice. |
686 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
686 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
687 | 687 | |
688 | 688 | // Ensure it exists and its not been paid for. |
689 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
689 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
690 | 690 | exit; |
691 | 691 | } |
692 | 692 | |
693 | 693 | // Abort if the invoice does not have the specified item. |
694 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
694 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
695 | 695 | |
696 | - if ( empty( $item ) ) { |
|
696 | + if (empty($item)) { |
|
697 | 697 | exit; |
698 | 698 | } |
699 | 699 | |
700 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
700 | + $invoice->remove_item((int) $_POST['item_id']); |
|
701 | 701 | |
702 | 702 | // Update totals. |
703 | 703 | $invoice->recalculate_total(); |
@@ -708,11 +708,11 @@ discard block |
||
708 | 708 | // Return an array of invoice items. |
709 | 709 | $items = array(); |
710 | 710 | |
711 | - foreach ( $invoice->get_items() as $item ) { |
|
712 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
711 | + foreach ($invoice->get_items() as $item) { |
|
712 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
713 | 713 | } |
714 | 714 | |
715 | - wp_send_json_success( compact( 'items' ) ); |
|
715 | + wp_send_json_success(compact('items')); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | /** |
@@ -721,69 +721,69 @@ discard block |
||
721 | 721 | public static function recalculate_full_prices() { |
722 | 722 | |
723 | 723 | // Verify nonce. |
724 | - check_ajax_referer( 'wpinv-nonce' ); |
|
724 | + check_ajax_referer('wpinv-nonce'); |
|
725 | 725 | |
726 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
726 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
727 | 727 | exit; |
728 | 728 | } |
729 | 729 | |
730 | 730 | // We need an invoice and item. |
731 | - if ( empty( $_POST['post_id'] ) ) { |
|
731 | + if (empty($_POST['post_id'])) { |
|
732 | 732 | exit; |
733 | 733 | } |
734 | 734 | |
735 | 735 | // Fetch the invoice. |
736 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
736 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
737 | 737 | $alert = false; |
738 | 738 | |
739 | 739 | // Ensure it exists and its not been paid for. |
740 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
740 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
741 | 741 | exit; |
742 | 742 | } |
743 | 743 | |
744 | - $invoice->set_items( array() ); |
|
744 | + $invoice->set_items(array()); |
|
745 | 745 | |
746 | - if ( ! empty( $_POST['getpaid_items'] ) ) { |
|
746 | + if (!empty($_POST['getpaid_items'])) { |
|
747 | 747 | |
748 | - foreach ( $_POST['getpaid_items'] as $item_id => $args ) { |
|
749 | - $item = new GetPaid_Form_Item( $item_id ); |
|
748 | + foreach ($_POST['getpaid_items'] as $item_id => $args) { |
|
749 | + $item = new GetPaid_Form_Item($item_id); |
|
750 | 750 | |
751 | - if ( $item->exists() ) { |
|
752 | - $item->set_price( getpaid_standardize_amount( $args['price'] ) ); |
|
753 | - $item->set_quantity( floatval( $args['quantity'] ) ); |
|
754 | - $item->set_name( sanitize_text_field( $args['name'] ) ); |
|
755 | - $item->set_description( wp_kses_post( $args['description'] ) ); |
|
756 | - $invoice->add_item( $item ); |
|
751 | + if ($item->exists()) { |
|
752 | + $item->set_price(getpaid_standardize_amount($args['price'])); |
|
753 | + $item->set_quantity(floatval($args['quantity'])); |
|
754 | + $item->set_name(sanitize_text_field($args['name'])); |
|
755 | + $item->set_description(wp_kses_post($args['description'])); |
|
756 | + $invoice->add_item($item); |
|
757 | 757 | } |
758 | 758 | } |
759 | 759 | |
760 | 760 | } |
761 | 761 | |
762 | - $invoice->set_disable_taxes( ! empty( $_POST['disable_taxes'] ) ); |
|
762 | + $invoice->set_disable_taxes(!empty($_POST['disable_taxes'])); |
|
763 | 763 | |
764 | 764 | // Maybe set the country, state, currency. |
765 | - foreach ( array( 'wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code' ) as $key ) { |
|
766 | - if ( isset( $_POST[ $key ] ) ) { |
|
767 | - $_key = str_replace( 'wpinv_', '', $key ); |
|
765 | + foreach (array('wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code') as $key) { |
|
766 | + if (isset($_POST[$key])) { |
|
767 | + $_key = str_replace('wpinv_', '', $key); |
|
768 | 768 | $method = "set_$_key"; |
769 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
769 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
770 | 770 | } |
771 | 771 | } |
772 | 772 | |
773 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
774 | - if ( $discount->exists() ) { |
|
775 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
773 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
774 | + if ($discount->exists()) { |
|
775 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
776 | 776 | } else { |
777 | - $invoice->remove_discount( 'discount_code' ); |
|
777 | + $invoice->remove_discount('discount_code'); |
|
778 | 778 | } |
779 | 779 | |
780 | 780 | // Save the invoice. |
781 | 781 | $invoice->recalculate_total(); |
782 | 782 | $invoice->save(); |
783 | 783 | ob_start(); |
784 | - GetPaid_Meta_Box_Invoice_Items::output( get_post( $invoice->get_id() ), $invoice ); |
|
784 | + GetPaid_Meta_Box_Invoice_Items::output(get_post($invoice->get_id()), $invoice); |
|
785 | 785 | $table = ob_get_clean(); |
786 | - wp_send_json_success( compact( 'table' ) ); |
|
786 | + wp_send_json_success(compact('table')); |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | /** |
@@ -792,42 +792,42 @@ discard block |
||
792 | 792 | public static function admin_add_invoice_item() { |
793 | 793 | |
794 | 794 | // Verify nonce. |
795 | - check_ajax_referer( 'wpinv-nonce' ); |
|
795 | + check_ajax_referer('wpinv-nonce'); |
|
796 | 796 | |
797 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
797 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
798 | 798 | exit; |
799 | 799 | } |
800 | 800 | |
801 | 801 | // We need an invoice and item. |
802 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
802 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
803 | 803 | exit; |
804 | 804 | } |
805 | 805 | |
806 | 806 | // Fetch the invoice. |
807 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
807 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
808 | 808 | $alert = false; |
809 | 809 | |
810 | 810 | // Ensure it exists and its not been paid for. |
811 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
811 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
812 | 812 | exit; |
813 | 813 | } |
814 | 814 | |
815 | 815 | // Add the item. |
816 | - $item = new GetPaid_Form_Item( (int) $_POST['item_id'] ); |
|
817 | - $error = $invoice->add_item( $item ); |
|
816 | + $item = new GetPaid_Form_Item((int) $_POST['item_id']); |
|
817 | + $error = $invoice->add_item($item); |
|
818 | 818 | |
819 | - if ( is_wp_error( $error ) ) { |
|
819 | + if (is_wp_error($error)) { |
|
820 | 820 | $alert = $error->get_error_message(); |
821 | - wp_send_json_success( compact( 'alert' ) ); |
|
821 | + wp_send_json_success(compact('alert')); |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | // Save the invoice. |
825 | 825 | $invoice->recalculate_total(); |
826 | 826 | $invoice->save(); |
827 | 827 | ob_start(); |
828 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
828 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
829 | 829 | $row = ob_get_clean(); |
830 | - wp_send_json_success( compact( 'row' ) ); |
|
830 | + wp_send_json_success(compact('row')); |
|
831 | 831 | } |
832 | 832 | |
833 | 833 | /** |
@@ -836,39 +836,39 @@ discard block |
||
836 | 836 | public static function add_invoice_items() { |
837 | 837 | |
838 | 838 | // Verify nonce. |
839 | - check_ajax_referer( 'wpinv-nonce' ); |
|
839 | + check_ajax_referer('wpinv-nonce'); |
|
840 | 840 | |
841 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
841 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
842 | 842 | exit; |
843 | 843 | } |
844 | 844 | |
845 | 845 | // We need an invoice and items. |
846 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
846 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
847 | 847 | exit; |
848 | 848 | } |
849 | 849 | |
850 | 850 | // Fetch the invoice. |
851 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
851 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
852 | 852 | $alert = false; |
853 | 853 | |
854 | 854 | // Ensure it exists and its not been paid for. |
855 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
855 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
856 | 856 | exit; |
857 | 857 | } |
858 | 858 | |
859 | 859 | // Add the items. |
860 | - foreach ( $_POST['items'] as $data ) { |
|
860 | + foreach ($_POST['items'] as $data) { |
|
861 | 861 | |
862 | - $item = new GetPaid_Form_Item( (int) $data[ 'id' ] ); |
|
862 | + $item = new GetPaid_Form_Item((int) $data['id']); |
|
863 | 863 | |
864 | - if ( is_numeric( $data[ 'qty' ] ) && (float) $data[ 'qty' ] > 0 ) { |
|
865 | - $item->set_quantity( floatval( $data[ 'qty' ] ) ); |
|
864 | + if (is_numeric($data['qty']) && (float) $data['qty'] > 0) { |
|
865 | + $item->set_quantity(floatval($data['qty'])); |
|
866 | 866 | } |
867 | 867 | |
868 | - if ( $item->get_id() > 0 ) { |
|
869 | - $error = $invoice->add_item( $item ); |
|
868 | + if ($item->get_id() > 0) { |
|
869 | + $error = $invoice->add_item($item); |
|
870 | 870 | |
871 | - if ( is_wp_error( $error ) ) { |
|
871 | + if (is_wp_error($error)) { |
|
872 | 872 | $alert = $error->get_error_message(); |
873 | 873 | } |
874 | 874 | |
@@ -883,11 +883,11 @@ discard block |
||
883 | 883 | // Return an array of invoice items. |
884 | 884 | $items = array(); |
885 | 885 | |
886 | - foreach ( $invoice->get_items() as $item ) { |
|
887 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
886 | + foreach ($invoice->get_items() as $item) { |
|
887 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
888 | 888 | } |
889 | 889 | |
890 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
890 | + wp_send_json_success(compact('items', 'alert')); |
|
891 | 891 | } |
892 | 892 | |
893 | 893 | /** |
@@ -896,15 +896,15 @@ discard block |
||
896 | 896 | public static function get_invoicing_items() { |
897 | 897 | |
898 | 898 | // Verify nonce. |
899 | - check_ajax_referer( 'wpinv-nonce' ); |
|
899 | + check_ajax_referer('wpinv-nonce'); |
|
900 | 900 | |
901 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
901 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
902 | 902 | exit; |
903 | 903 | } |
904 | 904 | |
905 | 905 | // We need a search term. |
906 | - if ( empty( $_GET['search'] ) ) { |
|
907 | - wp_send_json_success( array() ); |
|
906 | + if (empty($_GET['search'])) { |
|
907 | + wp_send_json_success(array()); |
|
908 | 908 | } |
909 | 909 | |
910 | 910 | // Retrieve items. |
@@ -913,8 +913,8 @@ discard block |
||
913 | 913 | 'orderby' => 'title', |
914 | 914 | 'order' => 'ASC', |
915 | 915 | 'posts_per_page' => -1, |
916 | - 'post_status' => array( 'publish' ), |
|
917 | - 's' => trim( $_GET['search'] ), |
|
916 | + 'post_status' => array('publish'), |
|
917 | + 's' => trim($_GET['search']), |
|
918 | 918 | 'meta_query' => array( |
919 | 919 | array( |
920 | 920 | 'key' => '_wpinv_type', |
@@ -924,21 +924,21 @@ discard block |
||
924 | 924 | ) |
925 | 925 | ); |
926 | 926 | |
927 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
927 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
928 | 928 | $data = array(); |
929 | 929 | |
930 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) ); |
|
930 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id'])); |
|
931 | 931 | |
932 | - foreach ( $items as $item ) { |
|
933 | - $item = new GetPaid_Form_Item( $item ); |
|
932 | + foreach ($items as $item) { |
|
933 | + $item = new GetPaid_Form_Item($item); |
|
934 | 934 | $data[] = array( |
935 | 935 | 'id' => (int) $item->get_id(), |
936 | - 'text' => strip_tags( $item->get_name() ), |
|
937 | - 'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '', |
|
936 | + 'text' => strip_tags($item->get_name()), |
|
937 | + 'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '', |
|
938 | 938 | ); |
939 | 939 | } |
940 | 940 | |
941 | - wp_send_json_success( $data ); |
|
941 | + wp_send_json_success($data); |
|
942 | 942 | |
943 | 943 | } |
944 | 944 | |
@@ -948,37 +948,37 @@ discard block |
||
948 | 948 | public static function get_customers() { |
949 | 949 | |
950 | 950 | // Verify nonce. |
951 | - check_ajax_referer( 'wpinv-nonce' ); |
|
951 | + check_ajax_referer('wpinv-nonce'); |
|
952 | 952 | |
953 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
953 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
954 | 954 | exit; |
955 | 955 | } |
956 | 956 | |
957 | 957 | // We need a search term. |
958 | - if ( empty( $_GET['search'] ) ) { |
|
959 | - wp_send_json_success( array() ); |
|
958 | + if (empty($_GET['search'])) { |
|
959 | + wp_send_json_success(array()); |
|
960 | 960 | } |
961 | 961 | |
962 | 962 | // Retrieve customers. |
963 | 963 | |
964 | 964 | $customer_args = array( |
965 | - 'fields' => array( 'ID', 'user_email', 'display_name' ), |
|
965 | + 'fields' => array('ID', 'user_email', 'display_name'), |
|
966 | 966 | 'orderby' => 'display_name', |
967 | - 'search' => '*' . sanitize_text_field( $_GET['search'] ) . '*', |
|
968 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
967 | + 'search' => '*' . sanitize_text_field($_GET['search']) . '*', |
|
968 | + 'search_columns' => array('user_login', 'user_email', 'display_name'), |
|
969 | 969 | ); |
970 | 970 | |
971 | - $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) ); |
|
971 | + $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args)); |
|
972 | 972 | $data = array(); |
973 | 973 | |
974 | - foreach ( $customers as $customer ) { |
|
974 | + foreach ($customers as $customer) { |
|
975 | 975 | $data[] = array( |
976 | 976 | 'id' => (int) $customer->ID, |
977 | - 'text' => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ), |
|
977 | + 'text' => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)), |
|
978 | 978 | ); |
979 | 979 | } |
980 | 980 | |
981 | - wp_send_json_success( $data ); |
|
981 | + wp_send_json_success($data); |
|
982 | 982 | |
983 | 983 | } |
984 | 984 | |
@@ -988,28 +988,28 @@ discard block |
||
988 | 988 | public static function get_aui_states_field() { |
989 | 989 | |
990 | 990 | // Verify nonce. |
991 | - check_ajax_referer( 'wpinv-nonce' ); |
|
991 | + check_ajax_referer('wpinv-nonce'); |
|
992 | 992 | |
993 | 993 | // We need a country. |
994 | - if ( empty( $_GET['country'] ) ) { |
|
994 | + if (empty($_GET['country'])) { |
|
995 | 995 | exit; |
996 | 996 | } |
997 | 997 | |
998 | - $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) ); |
|
999 | - $state = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state(); |
|
1000 | - $name = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state'; |
|
1001 | - $class = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm'; |
|
998 | + $states = wpinv_get_country_states(sanitize_text_field($_GET['country'])); |
|
999 | + $state = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state(); |
|
1000 | + $name = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state'; |
|
1001 | + $class = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm'; |
|
1002 | 1002 | |
1003 | - if ( empty( $states ) ) { |
|
1003 | + if (empty($states)) { |
|
1004 | 1004 | |
1005 | 1005 | $html = aui()->input( |
1006 | 1006 | array( |
1007 | 1007 | 'type' => 'text', |
1008 | 1008 | 'id' => 'wpinv_state', |
1009 | 1009 | 'name' => $name, |
1010 | - 'label' => __( 'State', 'invoicing' ), |
|
1010 | + 'label' => __('State', 'invoicing'), |
|
1011 | 1011 | 'label_type' => 'vertical', |
1012 | - 'placeholder' => __( 'State', 'invoicing' ), |
|
1012 | + 'placeholder' => __('State', 'invoicing'), |
|
1013 | 1013 | 'class' => $class, |
1014 | 1014 | 'value' => $state, |
1015 | 1015 | ) |
@@ -1021,9 +1021,9 @@ discard block |
||
1021 | 1021 | array( |
1022 | 1022 | 'id' => 'wpinv_state', |
1023 | 1023 | 'name' => $name, |
1024 | - 'label' => __( 'State', 'invoicing' ), |
|
1024 | + 'label' => __('State', 'invoicing'), |
|
1025 | 1025 | 'label_type' => 'vertical', |
1026 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
1026 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
1027 | 1027 | 'class' => $class, |
1028 | 1028 | 'value' => $state, |
1029 | 1029 | 'options' => $states, |
@@ -1037,7 +1037,7 @@ discard block |
||
1037 | 1037 | wp_send_json_success( |
1038 | 1038 | array( |
1039 | 1039 | 'html' => $html, |
1040 | - 'select' => ! empty ( $states ) |
|
1040 | + 'select' => !empty ($states) |
|
1041 | 1041 | ) |
1042 | 1042 | ); |
1043 | 1043 | |
@@ -1051,11 +1051,11 @@ discard block |
||
1051 | 1051 | public static function payment_form_refresh_prices() { |
1052 | 1052 | |
1053 | 1053 | // Check nonce. |
1054 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
1054 | + check_ajax_referer('getpaid_form_nonce'); |
|
1055 | 1055 | |
1056 | 1056 | // ... form fields... |
1057 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
1058 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
1057 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
1058 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
1059 | 1059 | exit; |
1060 | 1060 | } |
1061 | 1061 | |
@@ -1063,7 +1063,7 @@ discard block |
||
1063 | 1063 | $submission = new GetPaid_Payment_Form_Submission(); |
1064 | 1064 | |
1065 | 1065 | // Do we have an error? |
1066 | - if ( ! empty( $submission->last_error ) ) { |
|
1066 | + if (!empty($submission->last_error)) { |
|
1067 | 1067 | wp_send_json_error( |
1068 | 1068 | array( |
1069 | 1069 | 'code' => $submission->last_error_code, |
@@ -1073,12 +1073,12 @@ discard block |
||
1073 | 1073 | } |
1074 | 1074 | |
1075 | 1075 | // Prepare the response. |
1076 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
1076 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
1077 | 1077 | |
1078 | 1078 | // Filter the response. |
1079 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
1079 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
1080 | 1080 | |
1081 | - wp_send_json_success( $response ); |
|
1081 | + wp_send_json_success($response); |
|
1082 | 1082 | } |
1083 | 1083 | |
1084 | 1084 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,198 +10,198 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form_Submission { |
11 | 11 | |
12 | 12 | /** |
13 | - * Submission ID |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - public $id = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * The raw submission data. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $data = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * Submission totals |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $totals = array( |
|
32 | - |
|
33 | - 'subtotal' => array( |
|
34 | - 'initial' => 0, |
|
35 | - 'recurring' => 0, |
|
36 | - ), |
|
37 | - |
|
38 | - 'discount' => array( |
|
39 | - 'initial' => 0, |
|
40 | - 'recurring' => 0, |
|
41 | - ), |
|
42 | - |
|
43 | - 'fees' => array( |
|
44 | - 'initial' => 0, |
|
45 | - 'recurring' => 0, |
|
46 | - ), |
|
47 | - |
|
48 | - 'taxes' => array( |
|
49 | - 'initial' => 0, |
|
50 | - 'recurring' => 0, |
|
51 | - ), |
|
52 | - |
|
53 | - ); |
|
54 | - |
|
55 | - /** |
|
56 | - * Sets the associated payment form. |
|
57 | - * |
|
58 | - * @var GetPaid_Payment_Form |
|
59 | - */ |
|
13 | + * Submission ID |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + public $id = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * The raw submission data. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $data = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * Submission totals |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $totals = array( |
|
32 | + |
|
33 | + 'subtotal' => array( |
|
34 | + 'initial' => 0, |
|
35 | + 'recurring' => 0, |
|
36 | + ), |
|
37 | + |
|
38 | + 'discount' => array( |
|
39 | + 'initial' => 0, |
|
40 | + 'recurring' => 0, |
|
41 | + ), |
|
42 | + |
|
43 | + 'fees' => array( |
|
44 | + 'initial' => 0, |
|
45 | + 'recurring' => 0, |
|
46 | + ), |
|
47 | + |
|
48 | + 'taxes' => array( |
|
49 | + 'initial' => 0, |
|
50 | + 'recurring' => 0, |
|
51 | + ), |
|
52 | + |
|
53 | + ); |
|
54 | + |
|
55 | + /** |
|
56 | + * Sets the associated payment form. |
|
57 | + * |
|
58 | + * @var GetPaid_Payment_Form |
|
59 | + */ |
|
60 | 60 | protected $payment_form = null; |
61 | 61 | |
62 | 62 | /** |
63 | - * The country for the submission. |
|
64 | - * |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - public $country = null; |
|
68 | - |
|
69 | - /** |
|
70 | - * The state for the submission. |
|
71 | - * |
|
72 | - * @since 1.0.19 |
|
73 | - * @var string |
|
74 | - */ |
|
75 | - public $state = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * The invoice associated with the submission. |
|
79 | - * |
|
80 | - * @var WPInv_Invoice |
|
81 | - */ |
|
82 | - protected $invoice = null; |
|
83 | - |
|
84 | - /** |
|
85 | - * The recurring item for the submission. |
|
86 | - * |
|
87 | - * @var int |
|
88 | - */ |
|
89 | - public $has_recurring = 0; |
|
90 | - |
|
91 | - /** |
|
92 | - * An array of fees for the submission. |
|
93 | - * |
|
94 | - * @var array |
|
95 | - */ |
|
96 | - protected $fees = array(); |
|
97 | - |
|
98 | - /** |
|
99 | - * An array of discounts for the submission. |
|
100 | - * |
|
101 | - * @var array |
|
102 | - */ |
|
103 | - protected $discounts = array(); |
|
104 | - |
|
105 | - /** |
|
106 | - * An array of taxes for the submission. |
|
107 | - * |
|
108 | - * @var array |
|
109 | - */ |
|
110 | - protected $taxes = array(); |
|
111 | - |
|
112 | - /** |
|
113 | - * An array of items for the submission. |
|
114 | - * |
|
115 | - * @var GetPaid_Form_Item[] |
|
116 | - */ |
|
117 | - protected $items = array(); |
|
118 | - |
|
119 | - /** |
|
120 | - * The last error. |
|
121 | - * |
|
122 | - * @var string |
|
123 | - */ |
|
124 | - public $last_error = null; |
|
125 | - |
|
126 | - /** |
|
127 | - * The last error code. |
|
128 | - * |
|
129 | - * @var string |
|
130 | - */ |
|
131 | - public $last_error_code = null; |
|
132 | - |
|
133 | - /** |
|
134 | - * Class constructor. |
|
135 | - * |
|
136 | - */ |
|
137 | - public function __construct() { |
|
138 | - |
|
139 | - // Set the state and country to the default state and country. |
|
140 | - $this->country = wpinv_default_billing_country(); |
|
141 | - $this->state = wpinv_get_default_state(); |
|
142 | - |
|
143 | - // Do we have an actual submission? |
|
144 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
145 | - $this->load_data( $_POST ); |
|
146 | - } |
|
147 | - |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Loads submission data. |
|
152 | - * |
|
153 | - * @param array $data |
|
154 | - */ |
|
155 | - public function load_data( $data ) { |
|
156 | - |
|
157 | - // Remove slashes from the submitted data... |
|
158 | - $data = wp_kses_post_deep( wp_unslash( $data ) ); |
|
159 | - |
|
160 | - // Allow plugins to filter the data. |
|
161 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
162 | - |
|
163 | - // Cache it... |
|
164 | - $this->data = $data; |
|
165 | - |
|
166 | - // Then generate a unique id from the data. |
|
167 | - $this->id = md5( wp_json_encode( $data ) ); |
|
168 | - |
|
169 | - // Finally, process the submission. |
|
170 | - try { |
|
171 | - |
|
172 | - // Each process is passed an instance of the class (with reference) |
|
173 | - // and should throw an Exception whenever it encounters one. |
|
174 | - $processors = apply_filters( |
|
175 | - 'getpaid_payment_form_submission_processors', |
|
176 | - array( |
|
177 | - array( $this, 'process_payment_form' ), |
|
178 | - array( $this, 'process_invoice' ), |
|
179 | - array( $this, 'process_fees' ), |
|
180 | - array( $this, 'process_items' ), |
|
181 | - array( $this, 'process_discount' ), |
|
182 | - array( $this, 'process_taxes' ), |
|
183 | - ), |
|
184 | - $this |
|
185 | - ); |
|
186 | - |
|
187 | - foreach ( $processors as $processor ) { |
|
188 | - call_user_func_array( $processor, array( &$this ) ); |
|
189 | - } |
|
190 | - |
|
191 | - } catch( GetPaid_Payment_Exception $e ) { |
|
192 | - $this->last_error = $e->getMessage(); |
|
193 | - $this->last_error_code = $e->getErrorCode(); |
|
194 | - } catch ( Exception $e ) { |
|
195 | - $this->last_error = $e->getMessage(); |
|
196 | - $this->last_error_code = $e->getCode(); |
|
197 | - } |
|
198 | - |
|
199 | - // Fired when we are done processing a submission. |
|
200 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
201 | - |
|
202 | - } |
|
203 | - |
|
204 | - /* |
|
63 | + * The country for the submission. |
|
64 | + * |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + public $country = null; |
|
68 | + |
|
69 | + /** |
|
70 | + * The state for the submission. |
|
71 | + * |
|
72 | + * @since 1.0.19 |
|
73 | + * @var string |
|
74 | + */ |
|
75 | + public $state = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * The invoice associated with the submission. |
|
79 | + * |
|
80 | + * @var WPInv_Invoice |
|
81 | + */ |
|
82 | + protected $invoice = null; |
|
83 | + |
|
84 | + /** |
|
85 | + * The recurring item for the submission. |
|
86 | + * |
|
87 | + * @var int |
|
88 | + */ |
|
89 | + public $has_recurring = 0; |
|
90 | + |
|
91 | + /** |
|
92 | + * An array of fees for the submission. |
|
93 | + * |
|
94 | + * @var array |
|
95 | + */ |
|
96 | + protected $fees = array(); |
|
97 | + |
|
98 | + /** |
|
99 | + * An array of discounts for the submission. |
|
100 | + * |
|
101 | + * @var array |
|
102 | + */ |
|
103 | + protected $discounts = array(); |
|
104 | + |
|
105 | + /** |
|
106 | + * An array of taxes for the submission. |
|
107 | + * |
|
108 | + * @var array |
|
109 | + */ |
|
110 | + protected $taxes = array(); |
|
111 | + |
|
112 | + /** |
|
113 | + * An array of items for the submission. |
|
114 | + * |
|
115 | + * @var GetPaid_Form_Item[] |
|
116 | + */ |
|
117 | + protected $items = array(); |
|
118 | + |
|
119 | + /** |
|
120 | + * The last error. |
|
121 | + * |
|
122 | + * @var string |
|
123 | + */ |
|
124 | + public $last_error = null; |
|
125 | + |
|
126 | + /** |
|
127 | + * The last error code. |
|
128 | + * |
|
129 | + * @var string |
|
130 | + */ |
|
131 | + public $last_error_code = null; |
|
132 | + |
|
133 | + /** |
|
134 | + * Class constructor. |
|
135 | + * |
|
136 | + */ |
|
137 | + public function __construct() { |
|
138 | + |
|
139 | + // Set the state and country to the default state and country. |
|
140 | + $this->country = wpinv_default_billing_country(); |
|
141 | + $this->state = wpinv_get_default_state(); |
|
142 | + |
|
143 | + // Do we have an actual submission? |
|
144 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
145 | + $this->load_data( $_POST ); |
|
146 | + } |
|
147 | + |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Loads submission data. |
|
152 | + * |
|
153 | + * @param array $data |
|
154 | + */ |
|
155 | + public function load_data( $data ) { |
|
156 | + |
|
157 | + // Remove slashes from the submitted data... |
|
158 | + $data = wp_kses_post_deep( wp_unslash( $data ) ); |
|
159 | + |
|
160 | + // Allow plugins to filter the data. |
|
161 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
162 | + |
|
163 | + // Cache it... |
|
164 | + $this->data = $data; |
|
165 | + |
|
166 | + // Then generate a unique id from the data. |
|
167 | + $this->id = md5( wp_json_encode( $data ) ); |
|
168 | + |
|
169 | + // Finally, process the submission. |
|
170 | + try { |
|
171 | + |
|
172 | + // Each process is passed an instance of the class (with reference) |
|
173 | + // and should throw an Exception whenever it encounters one. |
|
174 | + $processors = apply_filters( |
|
175 | + 'getpaid_payment_form_submission_processors', |
|
176 | + array( |
|
177 | + array( $this, 'process_payment_form' ), |
|
178 | + array( $this, 'process_invoice' ), |
|
179 | + array( $this, 'process_fees' ), |
|
180 | + array( $this, 'process_items' ), |
|
181 | + array( $this, 'process_discount' ), |
|
182 | + array( $this, 'process_taxes' ), |
|
183 | + ), |
|
184 | + $this |
|
185 | + ); |
|
186 | + |
|
187 | + foreach ( $processors as $processor ) { |
|
188 | + call_user_func_array( $processor, array( &$this ) ); |
|
189 | + } |
|
190 | + |
|
191 | + } catch( GetPaid_Payment_Exception $e ) { |
|
192 | + $this->last_error = $e->getMessage(); |
|
193 | + $this->last_error_code = $e->getErrorCode(); |
|
194 | + } catch ( Exception $e ) { |
|
195 | + $this->last_error = $e->getMessage(); |
|
196 | + $this->last_error_code = $e->getCode(); |
|
197 | + } |
|
198 | + |
|
199 | + // Fired when we are done processing a submission. |
|
200 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
201 | + |
|
202 | + } |
|
203 | + |
|
204 | + /* |
|
205 | 205 | |-------------------------------------------------------------------------- |
206 | 206 | | Payment Forms. |
207 | 207 | |-------------------------------------------------------------------------- |
@@ -210,39 +210,39 @@ discard block |
||
210 | 210 | | submission has an active payment form etc. |
211 | 211 | */ |
212 | 212 | |
213 | - /** |
|
214 | - * Prepares the submission's payment form. |
|
215 | - * |
|
216 | - * @since 1.0.19 |
|
217 | - */ |
|
218 | - public function process_payment_form() { |
|
213 | + /** |
|
214 | + * Prepares the submission's payment form. |
|
215 | + * |
|
216 | + * @since 1.0.19 |
|
217 | + */ |
|
218 | + public function process_payment_form() { |
|
219 | 219 | |
220 | - // Every submission needs an active payment form. |
|
221 | - if ( empty( $this->data['form_id'] ) ) { |
|
222 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
223 | - } |
|
220 | + // Every submission needs an active payment form. |
|
221 | + if ( empty( $this->data['form_id'] ) ) { |
|
222 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
223 | + } |
|
224 | 224 | |
225 | - // Fetch the payment form. |
|
226 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
225 | + // Fetch the payment form. |
|
226 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
227 | 227 | |
228 | - if ( ! $this->payment_form->is_active() ) { |
|
229 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
230 | - } |
|
228 | + if ( ! $this->payment_form->is_active() ) { |
|
229 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
230 | + } |
|
231 | 231 | |
232 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
233 | - } |
|
232 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
233 | + } |
|
234 | 234 | |
235 | 235 | /** |
236 | - * Returns the payment form. |
|
237 | - * |
|
238 | - * @since 1.0.19 |
|
239 | - * @return GetPaid_Payment_Form |
|
240 | - */ |
|
241 | - public function get_payment_form() { |
|
242 | - return $this->payment_form; |
|
243 | - } |
|
236 | + * Returns the payment form. |
|
237 | + * |
|
238 | + * @since 1.0.19 |
|
239 | + * @return GetPaid_Payment_Form |
|
240 | + */ |
|
241 | + public function get_payment_form() { |
|
242 | + return $this->payment_form; |
|
243 | + } |
|
244 | 244 | |
245 | - /* |
|
245 | + /* |
|
246 | 246 | |-------------------------------------------------------------------------- |
247 | 247 | | Invoices. |
248 | 248 | |-------------------------------------------------------------------------- |
@@ -251,84 +251,84 @@ discard block |
||
251 | 251 | | might be for an existing invoice. |
252 | 252 | */ |
253 | 253 | |
254 | - /** |
|
255 | - * Prepares the submission's invoice. |
|
256 | - * |
|
257 | - * @since 1.0.19 |
|
258 | - */ |
|
259 | - public function process_invoice() { |
|
254 | + /** |
|
255 | + * Prepares the submission's invoice. |
|
256 | + * |
|
257 | + * @since 1.0.19 |
|
258 | + */ |
|
259 | + public function process_invoice() { |
|
260 | 260 | |
261 | - // Abort if there is no invoice. |
|
262 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
263 | - return; |
|
264 | - } |
|
261 | + // Abort if there is no invoice. |
|
262 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
263 | + return; |
|
264 | + } |
|
265 | 265 | |
266 | - // If the submission is for an existing invoice, ensure that it exists |
|
267 | - // and that it is not paid for. |
|
268 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
266 | + // If the submission is for an existing invoice, ensure that it exists |
|
267 | + // and that it is not paid for. |
|
268 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
269 | 269 | |
270 | 270 | if ( empty( $invoice ) ) { |
271 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
272 | - } |
|
271 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
272 | + } |
|
273 | 273 | |
274 | - if ( $invoice->is_paid() ) { |
|
275 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
276 | - } |
|
274 | + if ( $invoice->is_paid() ) { |
|
275 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
276 | + } |
|
277 | 277 | |
278 | - $this->payment_form->invoice = $invoice; |
|
279 | - if ( ! $this->payment_form->is_default() ) { |
|
278 | + $this->payment_form->invoice = $invoice; |
|
279 | + if ( ! $this->payment_form->is_default() ) { |
|
280 | 280 | |
281 | - $items = array(); |
|
282 | - $item_ids = array(); |
|
281 | + $items = array(); |
|
282 | + $item_ids = array(); |
|
283 | 283 | |
284 | - foreach ( $invoice->get_items() as $item ) { |
|
285 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
286 | - $item_ids[] = $item->get_id(); |
|
287 | - $items[] = $item; |
|
288 | - } |
|
289 | - } |
|
284 | + foreach ( $invoice->get_items() as $item ) { |
|
285 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
286 | + $item_ids[] = $item->get_id(); |
|
287 | + $items[] = $item; |
|
288 | + } |
|
289 | + } |
|
290 | 290 | |
291 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
292 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
293 | - $item_ids[] = $item->get_id(); |
|
294 | - $items[] = $item; |
|
295 | - } |
|
296 | - } |
|
291 | + foreach ( $this->payment_form->get_items() as $item ) { |
|
292 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
293 | + $item_ids[] = $item->get_id(); |
|
294 | + $items[] = $item; |
|
295 | + } |
|
296 | + } |
|
297 | 297 | |
298 | - $this->payment_form->set_items( $items ); |
|
298 | + $this->payment_form->set_items( $items ); |
|
299 | 299 | |
300 | - } else { |
|
301 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
302 | - } |
|
303 | - |
|
304 | - $this->country = $invoice->get_country(); |
|
305 | - $this->state = $invoice->get_state(); |
|
306 | - $this->invoice = $invoice; |
|
307 | - |
|
308 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * Returns the associated invoice. |
|
313 | - * |
|
314 | - * @since 1.0.19 |
|
315 | - * @return WPInv_Invoice |
|
316 | - */ |
|
317 | - public function get_invoice() { |
|
318 | - return $this->invoice; |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * Checks whether there is an invoice associated with this submission. |
|
323 | - * |
|
324 | - * @since 1.0.19 |
|
325 | - * @return bool |
|
326 | - */ |
|
327 | - public function has_invoice() { |
|
328 | - return ! empty( $this->invoice ); |
|
329 | - } |
|
330 | - |
|
331 | - /* |
|
300 | + } else { |
|
301 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
302 | + } |
|
303 | + |
|
304 | + $this->country = $invoice->get_country(); |
|
305 | + $this->state = $invoice->get_state(); |
|
306 | + $this->invoice = $invoice; |
|
307 | + |
|
308 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * Returns the associated invoice. |
|
313 | + * |
|
314 | + * @since 1.0.19 |
|
315 | + * @return WPInv_Invoice |
|
316 | + */ |
|
317 | + public function get_invoice() { |
|
318 | + return $this->invoice; |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * Checks whether there is an invoice associated with this submission. |
|
323 | + * |
|
324 | + * @since 1.0.19 |
|
325 | + * @return bool |
|
326 | + */ |
|
327 | + public function has_invoice() { |
|
328 | + return ! empty( $this->invoice ); |
|
329 | + } |
|
330 | + |
|
331 | + /* |
|
332 | 332 | |-------------------------------------------------------------------------- |
333 | 333 | | Items. |
334 | 334 | |-------------------------------------------------------------------------- |
@@ -337,129 +337,129 @@ discard block |
||
337 | 337 | | recurring item. But can have an unlimited number of non-recurring items. |
338 | 338 | */ |
339 | 339 | |
340 | - /** |
|
341 | - * Prepares the submission's items. |
|
342 | - * |
|
343 | - * @since 1.0.19 |
|
344 | - */ |
|
345 | - public function process_items() { |
|
346 | - |
|
347 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
348 | - |
|
349 | - foreach ( $processor->items as $item ) { |
|
350 | - $this->add_item( $item ); |
|
351 | - } |
|
352 | - |
|
353 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * Adds an item to the submission. |
|
358 | - * |
|
359 | - * @since 1.0.19 |
|
360 | - * @param GetPaid_Form_Item $item |
|
361 | - */ |
|
362 | - public function add_item( $item ) { |
|
363 | - |
|
364 | - // Make sure that it is available for purchase. |
|
365 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
366 | - return; |
|
367 | - } |
|
368 | - |
|
369 | - // Each submission can only contain one recurring item. |
|
370 | - if ( $item->is_recurring() ) { |
|
371 | - $this->has_recurring = $item->get_id(); |
|
372 | - } |
|
373 | - |
|
374 | - // Update the items and totals. |
|
375 | - $this->items[ $item->get_id() ] = $item; |
|
376 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
377 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
378 | - |
|
379 | - } |
|
380 | - |
|
381 | - /** |
|
382 | - * Removes a specific item. |
|
383 | - * |
|
384 | - * You should not call this method after the discounts and taxes |
|
385 | - * have been calculated. |
|
386 | - * |
|
387 | - * @since 1.0.19 |
|
388 | - */ |
|
389 | - public function remove_item( $item_id ) { |
|
390 | - |
|
391 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
392 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
393 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
394 | - |
|
395 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
396 | - $this->has_recurring = 0; |
|
397 | - } |
|
398 | - |
|
399 | - unset( $this->items[ $item_id ] ); |
|
400 | - } |
|
401 | - |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Returns the subtotal. |
|
406 | - * |
|
407 | - * @since 1.0.19 |
|
408 | - */ |
|
409 | - public function get_subtotal() { |
|
410 | - |
|
411 | - if ( wpinv_prices_include_tax() ) { |
|
412 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
413 | - } |
|
414 | - |
|
415 | - return $this->totals['subtotal']['initial']; |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * Returns the recurring subtotal. |
|
420 | - * |
|
421 | - * @since 1.0.19 |
|
422 | - */ |
|
423 | - public function get_recurring_subtotal() { |
|
424 | - |
|
425 | - if ( wpinv_prices_include_tax() ) { |
|
426 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
427 | - } |
|
428 | - |
|
429 | - return $this->totals['subtotal']['recurring']; |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Returns all items. |
|
434 | - * |
|
435 | - * @since 1.0.19 |
|
436 | - * @return GetPaid_Form_Item[] |
|
437 | - */ |
|
438 | - public function get_items() { |
|
439 | - return $this->items; |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * Checks if there's a single subscription group in the submission. |
|
444 | - * |
|
445 | - * @since 2.3.0 |
|
446 | - * @return bool |
|
447 | - */ |
|
448 | - public function has_subscription_group() { |
|
449 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
450 | - } |
|
451 | - |
|
452 | - /** |
|
453 | - * Checks if there are multipe subscription groups in the submission. |
|
454 | - * |
|
455 | - * @since 2.3.0 |
|
456 | - * @return bool |
|
457 | - */ |
|
458 | - public function has_multiple_subscription_groups() { |
|
459 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
460 | - } |
|
461 | - |
|
462 | - /* |
|
340 | + /** |
|
341 | + * Prepares the submission's items. |
|
342 | + * |
|
343 | + * @since 1.0.19 |
|
344 | + */ |
|
345 | + public function process_items() { |
|
346 | + |
|
347 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
348 | + |
|
349 | + foreach ( $processor->items as $item ) { |
|
350 | + $this->add_item( $item ); |
|
351 | + } |
|
352 | + |
|
353 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * Adds an item to the submission. |
|
358 | + * |
|
359 | + * @since 1.0.19 |
|
360 | + * @param GetPaid_Form_Item $item |
|
361 | + */ |
|
362 | + public function add_item( $item ) { |
|
363 | + |
|
364 | + // Make sure that it is available for purchase. |
|
365 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
366 | + return; |
|
367 | + } |
|
368 | + |
|
369 | + // Each submission can only contain one recurring item. |
|
370 | + if ( $item->is_recurring() ) { |
|
371 | + $this->has_recurring = $item->get_id(); |
|
372 | + } |
|
373 | + |
|
374 | + // Update the items and totals. |
|
375 | + $this->items[ $item->get_id() ] = $item; |
|
376 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
377 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
378 | + |
|
379 | + } |
|
380 | + |
|
381 | + /** |
|
382 | + * Removes a specific item. |
|
383 | + * |
|
384 | + * You should not call this method after the discounts and taxes |
|
385 | + * have been calculated. |
|
386 | + * |
|
387 | + * @since 1.0.19 |
|
388 | + */ |
|
389 | + public function remove_item( $item_id ) { |
|
390 | + |
|
391 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
392 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
393 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
394 | + |
|
395 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
396 | + $this->has_recurring = 0; |
|
397 | + } |
|
398 | + |
|
399 | + unset( $this->items[ $item_id ] ); |
|
400 | + } |
|
401 | + |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Returns the subtotal. |
|
406 | + * |
|
407 | + * @since 1.0.19 |
|
408 | + */ |
|
409 | + public function get_subtotal() { |
|
410 | + |
|
411 | + if ( wpinv_prices_include_tax() ) { |
|
412 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
413 | + } |
|
414 | + |
|
415 | + return $this->totals['subtotal']['initial']; |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * Returns the recurring subtotal. |
|
420 | + * |
|
421 | + * @since 1.0.19 |
|
422 | + */ |
|
423 | + public function get_recurring_subtotal() { |
|
424 | + |
|
425 | + if ( wpinv_prices_include_tax() ) { |
|
426 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
427 | + } |
|
428 | + |
|
429 | + return $this->totals['subtotal']['recurring']; |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Returns all items. |
|
434 | + * |
|
435 | + * @since 1.0.19 |
|
436 | + * @return GetPaid_Form_Item[] |
|
437 | + */ |
|
438 | + public function get_items() { |
|
439 | + return $this->items; |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * Checks if there's a single subscription group in the submission. |
|
444 | + * |
|
445 | + * @since 2.3.0 |
|
446 | + * @return bool |
|
447 | + */ |
|
448 | + public function has_subscription_group() { |
|
449 | + return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
450 | + } |
|
451 | + |
|
452 | + /** |
|
453 | + * Checks if there are multipe subscription groups in the submission. |
|
454 | + * |
|
455 | + * @since 2.3.0 |
|
456 | + * @return bool |
|
457 | + */ |
|
458 | + public function has_multiple_subscription_groups() { |
|
459 | + return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
460 | + } |
|
461 | + |
|
462 | + /* |
|
463 | 463 | |-------------------------------------------------------------------------- |
464 | 464 | | Taxes |
465 | 465 | |-------------------------------------------------------------------------- |
@@ -468,128 +468,128 @@ discard block |
||
468 | 468 | | or only one-time. |
469 | 469 | */ |
470 | 470 | |
471 | - /** |
|
472 | - * Prepares the submission's taxes. |
|
473 | - * |
|
474 | - * @since 1.0.19 |
|
475 | - */ |
|
476 | - public function process_taxes() { |
|
477 | - |
|
478 | - // Abort if we're not using taxes. |
|
479 | - if ( ! $this->use_taxes() ) { |
|
480 | - return; |
|
481 | - } |
|
482 | - |
|
483 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
484 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
485 | - if ( ! empty( $country ) ) { |
|
486 | - $this->country = $country; |
|
487 | - } |
|
488 | - |
|
489 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
490 | - if ( ! empty( $state ) ) { |
|
491 | - $this->state = $state; |
|
492 | - } |
|
493 | - |
|
494 | - // Confirm if the provided country and the ip country are similar. |
|
495 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
496 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
497 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
498 | - } |
|
499 | - |
|
500 | - // Abort if the country is not taxable. |
|
501 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
502 | - return; |
|
503 | - } |
|
504 | - |
|
505 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
506 | - |
|
507 | - foreach ( $processor->taxes as $tax ) { |
|
508 | - $this->add_tax( $tax ); |
|
509 | - } |
|
510 | - |
|
511 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
512 | - } |
|
513 | - |
|
514 | - /** |
|
515 | - * Adds a tax to the submission. |
|
516 | - * |
|
517 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
518 | - * @since 1.0.19 |
|
519 | - */ |
|
520 | - public function add_tax( $tax ) { |
|
521 | - |
|
522 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
523 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
524 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
525 | - } |
|
526 | - |
|
527 | - $this->taxes[ $tax['name'] ] = $tax; |
|
528 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
529 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
530 | - |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * Removes a specific tax. |
|
535 | - * |
|
536 | - * @since 1.0.19 |
|
537 | - */ |
|
538 | - public function remove_tax( $tax_name ) { |
|
539 | - |
|
540 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
541 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
542 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
543 | - unset( $this->taxes[ $tax_name ] ); |
|
544 | - } |
|
545 | - |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * Whether or not we'll use taxes for the submission. |
|
550 | - * |
|
551 | - * @since 1.0.19 |
|
552 | - */ |
|
553 | - public function use_taxes() { |
|
554 | - |
|
555 | - $use_taxes = wpinv_use_taxes(); |
|
556 | - |
|
557 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
558 | - $use_taxes = false; |
|
559 | - } |
|
560 | - |
|
561 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
562 | - |
|
563 | - } |
|
564 | - |
|
565 | - /** |
|
566 | - * Returns the tax. |
|
567 | - * |
|
568 | - * @since 1.0.19 |
|
569 | - */ |
|
570 | - public function get_tax() { |
|
571 | - return $this->totals['taxes']['initial']; |
|
572 | - } |
|
573 | - |
|
574 | - /** |
|
575 | - * Returns the recurring tax. |
|
576 | - * |
|
577 | - * @since 1.0.19 |
|
578 | - */ |
|
579 | - public function get_recurring_tax() { |
|
580 | - return $this->totals['taxes']['recurring']; |
|
581 | - } |
|
582 | - |
|
583 | - /** |
|
584 | - * Returns all taxes. |
|
585 | - * |
|
586 | - * @since 1.0.19 |
|
587 | - */ |
|
588 | - public function get_taxes() { |
|
589 | - return $this->taxes; |
|
590 | - } |
|
591 | - |
|
592 | - /* |
|
471 | + /** |
|
472 | + * Prepares the submission's taxes. |
|
473 | + * |
|
474 | + * @since 1.0.19 |
|
475 | + */ |
|
476 | + public function process_taxes() { |
|
477 | + |
|
478 | + // Abort if we're not using taxes. |
|
479 | + if ( ! $this->use_taxes() ) { |
|
480 | + return; |
|
481 | + } |
|
482 | + |
|
483 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
484 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
485 | + if ( ! empty( $country ) ) { |
|
486 | + $this->country = $country; |
|
487 | + } |
|
488 | + |
|
489 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
490 | + if ( ! empty( $state ) ) { |
|
491 | + $this->state = $state; |
|
492 | + } |
|
493 | + |
|
494 | + // Confirm if the provided country and the ip country are similar. |
|
495 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
496 | + if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
497 | + throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
498 | + } |
|
499 | + |
|
500 | + // Abort if the country is not taxable. |
|
501 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
502 | + return; |
|
503 | + } |
|
504 | + |
|
505 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
506 | + |
|
507 | + foreach ( $processor->taxes as $tax ) { |
|
508 | + $this->add_tax( $tax ); |
|
509 | + } |
|
510 | + |
|
511 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
512 | + } |
|
513 | + |
|
514 | + /** |
|
515 | + * Adds a tax to the submission. |
|
516 | + * |
|
517 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
518 | + * @since 1.0.19 |
|
519 | + */ |
|
520 | + public function add_tax( $tax ) { |
|
521 | + |
|
522 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
523 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
524 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
525 | + } |
|
526 | + |
|
527 | + $this->taxes[ $tax['name'] ] = $tax; |
|
528 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
529 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
530 | + |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * Removes a specific tax. |
|
535 | + * |
|
536 | + * @since 1.0.19 |
|
537 | + */ |
|
538 | + public function remove_tax( $tax_name ) { |
|
539 | + |
|
540 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
541 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
542 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
543 | + unset( $this->taxes[ $tax_name ] ); |
|
544 | + } |
|
545 | + |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * Whether or not we'll use taxes for the submission. |
|
550 | + * |
|
551 | + * @since 1.0.19 |
|
552 | + */ |
|
553 | + public function use_taxes() { |
|
554 | + |
|
555 | + $use_taxes = wpinv_use_taxes(); |
|
556 | + |
|
557 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
558 | + $use_taxes = false; |
|
559 | + } |
|
560 | + |
|
561 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
562 | + |
|
563 | + } |
|
564 | + |
|
565 | + /** |
|
566 | + * Returns the tax. |
|
567 | + * |
|
568 | + * @since 1.0.19 |
|
569 | + */ |
|
570 | + public function get_tax() { |
|
571 | + return $this->totals['taxes']['initial']; |
|
572 | + } |
|
573 | + |
|
574 | + /** |
|
575 | + * Returns the recurring tax. |
|
576 | + * |
|
577 | + * @since 1.0.19 |
|
578 | + */ |
|
579 | + public function get_recurring_tax() { |
|
580 | + return $this->totals['taxes']['recurring']; |
|
581 | + } |
|
582 | + |
|
583 | + /** |
|
584 | + * Returns all taxes. |
|
585 | + * |
|
586 | + * @since 1.0.19 |
|
587 | + */ |
|
588 | + public function get_taxes() { |
|
589 | + return $this->taxes; |
|
590 | + } |
|
591 | + |
|
592 | + /* |
|
593 | 593 | |-------------------------------------------------------------------------- |
594 | 594 | | Discounts |
595 | 595 | |-------------------------------------------------------------------------- |
@@ -598,99 +598,99 @@ discard block |
||
598 | 598 | | or only one-time. They also do not have to come from a discount code. |
599 | 599 | */ |
600 | 600 | |
601 | - /** |
|
602 | - * Prepares the submission's discount. |
|
603 | - * |
|
604 | - * @since 1.0.19 |
|
605 | - */ |
|
606 | - public function process_discount() { |
|
607 | - |
|
608 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
609 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
610 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
611 | - |
|
612 | - foreach ( $processor->discounts as $discount ) { |
|
613 | - $this->add_discount( $discount ); |
|
614 | - } |
|
615 | - |
|
616 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
617 | - } |
|
618 | - |
|
619 | - /** |
|
620 | - * Adds a discount to the submission. |
|
621 | - * |
|
622 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
623 | - * @since 1.0.19 |
|
624 | - */ |
|
625 | - public function add_discount( $discount ) { |
|
626 | - $this->discounts[ $discount['name'] ] = $discount; |
|
627 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
628 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
629 | - } |
|
630 | - |
|
631 | - /** |
|
632 | - * Removes a discount from the submission. |
|
633 | - * |
|
634 | - * @since 1.0.19 |
|
635 | - */ |
|
636 | - public function remove_discount( $name ) { |
|
637 | - |
|
638 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
639 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
640 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
641 | - unset( $this->discounts[ $name ] ); |
|
642 | - } |
|
643 | - |
|
644 | - } |
|
645 | - |
|
646 | - /** |
|
647 | - * Checks whether there is a discount code associated with this submission. |
|
648 | - * |
|
649 | - * @since 1.0.19 |
|
650 | - * @return bool |
|
651 | - */ |
|
652 | - public function has_discount_code() { |
|
653 | - return ! empty( $this->discounts['discount_code'] ); |
|
654 | - } |
|
655 | - |
|
656 | - /** |
|
657 | - * Returns the discount code. |
|
658 | - * |
|
659 | - * @since 1.0.19 |
|
660 | - * @return string |
|
661 | - */ |
|
662 | - public function get_discount_code() { |
|
663 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
664 | - } |
|
665 | - |
|
666 | - /** |
|
667 | - * Returns the discount. |
|
668 | - * |
|
669 | - * @since 1.0.19 |
|
670 | - */ |
|
671 | - public function get_discount() { |
|
672 | - return $this->totals['discount']['initial']; |
|
673 | - } |
|
674 | - |
|
675 | - /** |
|
676 | - * Returns the recurring discount. |
|
677 | - * |
|
678 | - * @since 1.0.19 |
|
679 | - */ |
|
680 | - public function get_recurring_discount() { |
|
681 | - return $this->totals['discount']['recurring']; |
|
682 | - } |
|
683 | - |
|
684 | - /** |
|
685 | - * Returns all discounts. |
|
686 | - * |
|
687 | - * @since 1.0.19 |
|
688 | - */ |
|
689 | - public function get_discounts() { |
|
690 | - return $this->discounts; |
|
691 | - } |
|
692 | - |
|
693 | - /* |
|
601 | + /** |
|
602 | + * Prepares the submission's discount. |
|
603 | + * |
|
604 | + * @since 1.0.19 |
|
605 | + */ |
|
606 | + public function process_discount() { |
|
607 | + |
|
608 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
609 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
610 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
611 | + |
|
612 | + foreach ( $processor->discounts as $discount ) { |
|
613 | + $this->add_discount( $discount ); |
|
614 | + } |
|
615 | + |
|
616 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
617 | + } |
|
618 | + |
|
619 | + /** |
|
620 | + * Adds a discount to the submission. |
|
621 | + * |
|
622 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
623 | + * @since 1.0.19 |
|
624 | + */ |
|
625 | + public function add_discount( $discount ) { |
|
626 | + $this->discounts[ $discount['name'] ] = $discount; |
|
627 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
628 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
629 | + } |
|
630 | + |
|
631 | + /** |
|
632 | + * Removes a discount from the submission. |
|
633 | + * |
|
634 | + * @since 1.0.19 |
|
635 | + */ |
|
636 | + public function remove_discount( $name ) { |
|
637 | + |
|
638 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
639 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
640 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
641 | + unset( $this->discounts[ $name ] ); |
|
642 | + } |
|
643 | + |
|
644 | + } |
|
645 | + |
|
646 | + /** |
|
647 | + * Checks whether there is a discount code associated with this submission. |
|
648 | + * |
|
649 | + * @since 1.0.19 |
|
650 | + * @return bool |
|
651 | + */ |
|
652 | + public function has_discount_code() { |
|
653 | + return ! empty( $this->discounts['discount_code'] ); |
|
654 | + } |
|
655 | + |
|
656 | + /** |
|
657 | + * Returns the discount code. |
|
658 | + * |
|
659 | + * @since 1.0.19 |
|
660 | + * @return string |
|
661 | + */ |
|
662 | + public function get_discount_code() { |
|
663 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
664 | + } |
|
665 | + |
|
666 | + /** |
|
667 | + * Returns the discount. |
|
668 | + * |
|
669 | + * @since 1.0.19 |
|
670 | + */ |
|
671 | + public function get_discount() { |
|
672 | + return $this->totals['discount']['initial']; |
|
673 | + } |
|
674 | + |
|
675 | + /** |
|
676 | + * Returns the recurring discount. |
|
677 | + * |
|
678 | + * @since 1.0.19 |
|
679 | + */ |
|
680 | + public function get_recurring_discount() { |
|
681 | + return $this->totals['discount']['recurring']; |
|
682 | + } |
|
683 | + |
|
684 | + /** |
|
685 | + * Returns all discounts. |
|
686 | + * |
|
687 | + * @since 1.0.19 |
|
688 | + */ |
|
689 | + public function get_discounts() { |
|
690 | + return $this->discounts; |
|
691 | + } |
|
692 | + |
|
693 | + /* |
|
694 | 694 | |-------------------------------------------------------------------------- |
695 | 695 | | Fees |
696 | 696 | |-------------------------------------------------------------------------- |
@@ -700,89 +700,89 @@ discard block |
||
700 | 700 | | fees. |
701 | 701 | */ |
702 | 702 | |
703 | - /** |
|
704 | - * Prepares the submission's fees. |
|
705 | - * |
|
706 | - * @since 1.0.19 |
|
707 | - */ |
|
708 | - public function process_fees() { |
|
709 | - |
|
710 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
711 | - |
|
712 | - foreach ( $fees_processor->fees as $fee ) { |
|
713 | - $this->add_fee( $fee ); |
|
714 | - } |
|
715 | - |
|
716 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
717 | - } |
|
718 | - |
|
719 | - /** |
|
720 | - * Adds a fee to the submission. |
|
721 | - * |
|
722 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
723 | - * @since 1.0.19 |
|
724 | - */ |
|
725 | - public function add_fee( $fee ) { |
|
726 | - |
|
727 | - $this->fees[ $fee['name'] ] = $fee; |
|
728 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
729 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
730 | - |
|
731 | - } |
|
732 | - |
|
733 | - /** |
|
734 | - * Removes a fee from the submission. |
|
735 | - * |
|
736 | - * @since 1.0.19 |
|
737 | - */ |
|
738 | - public function remove_fee( $name ) { |
|
739 | - |
|
740 | - if ( isset( $this->fees[ $name ] ) ) { |
|
741 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
742 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
743 | - unset( $this->fees[ $name ] ); |
|
744 | - } |
|
745 | - |
|
746 | - } |
|
747 | - |
|
748 | - /** |
|
749 | - * Returns the fees. |
|
750 | - * |
|
751 | - * @since 1.0.19 |
|
752 | - */ |
|
753 | - public function get_fee() { |
|
754 | - return $this->totals['fees']['initial']; |
|
755 | - } |
|
756 | - |
|
757 | - /** |
|
758 | - * Returns the recurring fees. |
|
759 | - * |
|
760 | - * @since 1.0.19 |
|
761 | - */ |
|
762 | - public function get_recurring_fee() { |
|
763 | - return $this->totals['fees']['recurring']; |
|
764 | - } |
|
765 | - |
|
766 | - /** |
|
767 | - * Returns all fees. |
|
768 | - * |
|
769 | - * @since 1.0.19 |
|
770 | - */ |
|
771 | - public function get_fees() { |
|
772 | - return $this->fees; |
|
773 | - } |
|
774 | - |
|
775 | - /** |
|
776 | - * Checks if there are any fees for the form. |
|
777 | - * |
|
778 | - * @return bool |
|
779 | - * @since 1.0.19 |
|
780 | - */ |
|
781 | - public function has_fees() { |
|
782 | - return count( $this->fees ) !== 0; |
|
783 | - } |
|
784 | - |
|
785 | - /* |
|
703 | + /** |
|
704 | + * Prepares the submission's fees. |
|
705 | + * |
|
706 | + * @since 1.0.19 |
|
707 | + */ |
|
708 | + public function process_fees() { |
|
709 | + |
|
710 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
711 | + |
|
712 | + foreach ( $fees_processor->fees as $fee ) { |
|
713 | + $this->add_fee( $fee ); |
|
714 | + } |
|
715 | + |
|
716 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
717 | + } |
|
718 | + |
|
719 | + /** |
|
720 | + * Adds a fee to the submission. |
|
721 | + * |
|
722 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
723 | + * @since 1.0.19 |
|
724 | + */ |
|
725 | + public function add_fee( $fee ) { |
|
726 | + |
|
727 | + $this->fees[ $fee['name'] ] = $fee; |
|
728 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
729 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
730 | + |
|
731 | + } |
|
732 | + |
|
733 | + /** |
|
734 | + * Removes a fee from the submission. |
|
735 | + * |
|
736 | + * @since 1.0.19 |
|
737 | + */ |
|
738 | + public function remove_fee( $name ) { |
|
739 | + |
|
740 | + if ( isset( $this->fees[ $name ] ) ) { |
|
741 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
742 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
743 | + unset( $this->fees[ $name ] ); |
|
744 | + } |
|
745 | + |
|
746 | + } |
|
747 | + |
|
748 | + /** |
|
749 | + * Returns the fees. |
|
750 | + * |
|
751 | + * @since 1.0.19 |
|
752 | + */ |
|
753 | + public function get_fee() { |
|
754 | + return $this->totals['fees']['initial']; |
|
755 | + } |
|
756 | + |
|
757 | + /** |
|
758 | + * Returns the recurring fees. |
|
759 | + * |
|
760 | + * @since 1.0.19 |
|
761 | + */ |
|
762 | + public function get_recurring_fee() { |
|
763 | + return $this->totals['fees']['recurring']; |
|
764 | + } |
|
765 | + |
|
766 | + /** |
|
767 | + * Returns all fees. |
|
768 | + * |
|
769 | + * @since 1.0.19 |
|
770 | + */ |
|
771 | + public function get_fees() { |
|
772 | + return $this->fees; |
|
773 | + } |
|
774 | + |
|
775 | + /** |
|
776 | + * Checks if there are any fees for the form. |
|
777 | + * |
|
778 | + * @return bool |
|
779 | + * @since 1.0.19 |
|
780 | + */ |
|
781 | + public function has_fees() { |
|
782 | + return count( $this->fees ) !== 0; |
|
783 | + } |
|
784 | + |
|
785 | + /* |
|
786 | 786 | |-------------------------------------------------------------------------- |
787 | 787 | | MISC |
788 | 788 | |-------------------------------------------------------------------------- |
@@ -790,119 +790,119 @@ discard block |
||
790 | 790 | | Extra submission functions. |
791 | 791 | */ |
792 | 792 | |
793 | - /** |
|
794 | - * Checks if this is the initial fetch. |
|
795 | - * |
|
796 | - * @return bool |
|
797 | - * @since 1.0.19 |
|
798 | - */ |
|
799 | - public function is_initial_fetch() { |
|
800 | - return empty( $this->data['initial_state'] ); |
|
801 | - } |
|
802 | - |
|
803 | - /** |
|
804 | - * Returns the total amount to collect for this submission. |
|
805 | - * |
|
806 | - * @since 1.0.19 |
|
807 | - */ |
|
808 | - public function get_total() { |
|
809 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
810 | - return max( $total, 0 ); |
|
811 | - } |
|
812 | - |
|
813 | - /** |
|
814 | - * Returns the recurring total amount to collect for this submission. |
|
815 | - * |
|
816 | - * @since 1.0.19 |
|
817 | - */ |
|
818 | - public function get_recurring_total() { |
|
819 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
820 | - return max( $total, 0 ); |
|
821 | - } |
|
822 | - |
|
823 | - /** |
|
824 | - * Whether payment details should be collected for this submission. |
|
825 | - * |
|
826 | - * @since 1.0.19 |
|
827 | - */ |
|
828 | - public function should_collect_payment_details() { |
|
829 | - $initial = $this->get_total(); |
|
830 | - $recurring = $this->get_recurring_total(); |
|
831 | - |
|
832 | - if ( $this->has_recurring == 0 ) { |
|
833 | - $recurring = 0; |
|
834 | - } |
|
835 | - |
|
836 | - $collect = $initial > 0 || $recurring > 0; |
|
837 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
838 | - } |
|
839 | - |
|
840 | - /** |
|
841 | - * Returns the billing email of the user. |
|
842 | - * |
|
843 | - * @since 1.0.19 |
|
844 | - */ |
|
845 | - public function get_billing_email() { |
|
846 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
847 | - } |
|
848 | - |
|
849 | - /** |
|
850 | - * Checks if the submitter has a billing email. |
|
851 | - * |
|
852 | - * @since 1.0.19 |
|
853 | - */ |
|
854 | - public function has_billing_email() { |
|
855 | - $billing_email = $this->get_billing_email(); |
|
856 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
857 | - } |
|
858 | - |
|
859 | - /** |
|
860 | - * Returns the appropriate currency for the submission. |
|
861 | - * |
|
862 | - * @since 1.0.19 |
|
863 | - * @return string |
|
864 | - */ |
|
865 | - public function get_currency() { |
|
866 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
867 | - } |
|
868 | - |
|
869 | - /** |
|
870 | - * Returns the raw submission data. |
|
871 | - * |
|
872 | - * @since 1.0.19 |
|
873 | - * @return array |
|
874 | - */ |
|
875 | - public function get_data() { |
|
876 | - return $this->data; |
|
877 | - } |
|
878 | - |
|
879 | - /** |
|
880 | - * Returns a field from the submission data |
|
881 | - * |
|
882 | - * @param string $field |
|
883 | - * @since 1.0.19 |
|
884 | - * @return mixed|null |
|
885 | - */ |
|
886 | - public function get_field( $field, $sub_array_key = null ) { |
|
887 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
888 | - } |
|
889 | - |
|
890 | - /** |
|
891 | - * Checks if a required field is set. |
|
892 | - * |
|
893 | - * @since 1.0.19 |
|
894 | - */ |
|
895 | - public function is_required_field_set( $field ) { |
|
896 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
897 | - } |
|
898 | - |
|
899 | - /** |
|
900 | - * Formats an amount |
|
901 | - * |
|
902 | - * @since 1.0.19 |
|
903 | - */ |
|
904 | - public function format_amount( $amount ) { |
|
905 | - return wpinv_price( $amount, $this->get_currency() ); |
|
906 | - } |
|
793 | + /** |
|
794 | + * Checks if this is the initial fetch. |
|
795 | + * |
|
796 | + * @return bool |
|
797 | + * @since 1.0.19 |
|
798 | + */ |
|
799 | + public function is_initial_fetch() { |
|
800 | + return empty( $this->data['initial_state'] ); |
|
801 | + } |
|
802 | + |
|
803 | + /** |
|
804 | + * Returns the total amount to collect for this submission. |
|
805 | + * |
|
806 | + * @since 1.0.19 |
|
807 | + */ |
|
808 | + public function get_total() { |
|
809 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
810 | + return max( $total, 0 ); |
|
811 | + } |
|
812 | + |
|
813 | + /** |
|
814 | + * Returns the recurring total amount to collect for this submission. |
|
815 | + * |
|
816 | + * @since 1.0.19 |
|
817 | + */ |
|
818 | + public function get_recurring_total() { |
|
819 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
820 | + return max( $total, 0 ); |
|
821 | + } |
|
822 | + |
|
823 | + /** |
|
824 | + * Whether payment details should be collected for this submission. |
|
825 | + * |
|
826 | + * @since 1.0.19 |
|
827 | + */ |
|
828 | + public function should_collect_payment_details() { |
|
829 | + $initial = $this->get_total(); |
|
830 | + $recurring = $this->get_recurring_total(); |
|
831 | + |
|
832 | + if ( $this->has_recurring == 0 ) { |
|
833 | + $recurring = 0; |
|
834 | + } |
|
835 | + |
|
836 | + $collect = $initial > 0 || $recurring > 0; |
|
837 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
838 | + } |
|
839 | + |
|
840 | + /** |
|
841 | + * Returns the billing email of the user. |
|
842 | + * |
|
843 | + * @since 1.0.19 |
|
844 | + */ |
|
845 | + public function get_billing_email() { |
|
846 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
847 | + } |
|
848 | + |
|
849 | + /** |
|
850 | + * Checks if the submitter has a billing email. |
|
851 | + * |
|
852 | + * @since 1.0.19 |
|
853 | + */ |
|
854 | + public function has_billing_email() { |
|
855 | + $billing_email = $this->get_billing_email(); |
|
856 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
857 | + } |
|
858 | + |
|
859 | + /** |
|
860 | + * Returns the appropriate currency for the submission. |
|
861 | + * |
|
862 | + * @since 1.0.19 |
|
863 | + * @return string |
|
864 | + */ |
|
865 | + public function get_currency() { |
|
866 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
867 | + } |
|
868 | + |
|
869 | + /** |
|
870 | + * Returns the raw submission data. |
|
871 | + * |
|
872 | + * @since 1.0.19 |
|
873 | + * @return array |
|
874 | + */ |
|
875 | + public function get_data() { |
|
876 | + return $this->data; |
|
877 | + } |
|
878 | + |
|
879 | + /** |
|
880 | + * Returns a field from the submission data |
|
881 | + * |
|
882 | + * @param string $field |
|
883 | + * @since 1.0.19 |
|
884 | + * @return mixed|null |
|
885 | + */ |
|
886 | + public function get_field( $field, $sub_array_key = null ) { |
|
887 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
888 | + } |
|
889 | + |
|
890 | + /** |
|
891 | + * Checks if a required field is set. |
|
892 | + * |
|
893 | + * @since 1.0.19 |
|
894 | + */ |
|
895 | + public function is_required_field_set( $field ) { |
|
896 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
897 | + } |
|
898 | + |
|
899 | + /** |
|
900 | + * Formats an amount |
|
901 | + * |
|
902 | + * @since 1.0.19 |
|
903 | + */ |
|
904 | + public function format_amount( $amount ) { |
|
905 | + return wpinv_price( $amount, $this->get_currency() ); |
|
906 | + } |
|
907 | 907 | |
908 | 908 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -141,8 +141,8 @@ discard block |
||
141 | 141 | $this->state = wpinv_get_default_state(); |
142 | 142 | |
143 | 143 | // Do we have an actual submission? |
144 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
145 | - $this->load_data( $_POST ); |
|
144 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
145 | + $this->load_data($_POST); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | } |
@@ -152,19 +152,19 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @param array $data |
154 | 154 | */ |
155 | - public function load_data( $data ) { |
|
155 | + public function load_data($data) { |
|
156 | 156 | |
157 | 157 | // Remove slashes from the submitted data... |
158 | - $data = wp_kses_post_deep( wp_unslash( $data ) ); |
|
158 | + $data = wp_kses_post_deep(wp_unslash($data)); |
|
159 | 159 | |
160 | 160 | // Allow plugins to filter the data. |
161 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
161 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
162 | 162 | |
163 | 163 | // Cache it... |
164 | 164 | $this->data = $data; |
165 | 165 | |
166 | 166 | // Then generate a unique id from the data. |
167 | - $this->id = md5( wp_json_encode( $data ) ); |
|
167 | + $this->id = md5(wp_json_encode($data)); |
|
168 | 168 | |
169 | 169 | // Finally, process the submission. |
170 | 170 | try { |
@@ -174,30 +174,30 @@ discard block |
||
174 | 174 | $processors = apply_filters( |
175 | 175 | 'getpaid_payment_form_submission_processors', |
176 | 176 | array( |
177 | - array( $this, 'process_payment_form' ), |
|
178 | - array( $this, 'process_invoice' ), |
|
179 | - array( $this, 'process_fees' ), |
|
180 | - array( $this, 'process_items' ), |
|
181 | - array( $this, 'process_discount' ), |
|
182 | - array( $this, 'process_taxes' ), |
|
177 | + array($this, 'process_payment_form'), |
|
178 | + array($this, 'process_invoice'), |
|
179 | + array($this, 'process_fees'), |
|
180 | + array($this, 'process_items'), |
|
181 | + array($this, 'process_discount'), |
|
182 | + array($this, 'process_taxes'), |
|
183 | 183 | ), |
184 | 184 | $this |
185 | 185 | ); |
186 | 186 | |
187 | - foreach ( $processors as $processor ) { |
|
188 | - call_user_func_array( $processor, array( &$this ) ); |
|
187 | + foreach ($processors as $processor) { |
|
188 | + call_user_func_array($processor, array(&$this)); |
|
189 | 189 | } |
190 | 190 | |
191 | - } catch( GetPaid_Payment_Exception $e ) { |
|
191 | + } catch (GetPaid_Payment_Exception $e) { |
|
192 | 192 | $this->last_error = $e->getMessage(); |
193 | 193 | $this->last_error_code = $e->getErrorCode(); |
194 | - } catch ( Exception $e ) { |
|
194 | + } catch (Exception $e) { |
|
195 | 195 | $this->last_error = $e->getMessage(); |
196 | 196 | $this->last_error_code = $e->getCode(); |
197 | 197 | } |
198 | 198 | |
199 | 199 | // Fired when we are done processing a submission. |
200 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
200 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
201 | 201 | |
202 | 202 | } |
203 | 203 | |
@@ -218,18 +218,18 @@ discard block |
||
218 | 218 | public function process_payment_form() { |
219 | 219 | |
220 | 220 | // Every submission needs an active payment form. |
221 | - if ( empty( $this->data['form_id'] ) ) { |
|
222 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
221 | + if (empty($this->data['form_id'])) { |
|
222 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | // Fetch the payment form. |
226 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
226 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
227 | 227 | |
228 | - if ( ! $this->payment_form->is_active() ) { |
|
229 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
228 | + if (!$this->payment_form->is_active()) { |
|
229 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
230 | 230 | } |
231 | 231 | |
232 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
232 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -259,53 +259,53 @@ discard block |
||
259 | 259 | public function process_invoice() { |
260 | 260 | |
261 | 261 | // Abort if there is no invoice. |
262 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
262 | + if (empty($this->data['invoice_id'])) { |
|
263 | 263 | return; |
264 | 264 | } |
265 | 265 | |
266 | 266 | // If the submission is for an existing invoice, ensure that it exists |
267 | 267 | // and that it is not paid for. |
268 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
268 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
269 | 269 | |
270 | - if ( empty( $invoice ) ) { |
|
271 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
270 | + if (empty($invoice)) { |
|
271 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
272 | 272 | } |
273 | 273 | |
274 | - if ( $invoice->is_paid() ) { |
|
275 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
274 | + if ($invoice->is_paid()) { |
|
275 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | $this->payment_form->invoice = $invoice; |
279 | - if ( ! $this->payment_form->is_default() ) { |
|
279 | + if (!$this->payment_form->is_default()) { |
|
280 | 280 | |
281 | 281 | $items = array(); |
282 | 282 | $item_ids = array(); |
283 | 283 | |
284 | - foreach ( $invoice->get_items() as $item ) { |
|
285 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
284 | + foreach ($invoice->get_items() as $item) { |
|
285 | + if (!in_array($item->get_id(), $item_ids)) { |
|
286 | 286 | $item_ids[] = $item->get_id(); |
287 | 287 | $items[] = $item; |
288 | 288 | } |
289 | 289 | } |
290 | 290 | |
291 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
292 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
291 | + foreach ($this->payment_form->get_items() as $item) { |
|
292 | + if (!in_array($item->get_id(), $item_ids)) { |
|
293 | 293 | $item_ids[] = $item->get_id(); |
294 | 294 | $items[] = $item; |
295 | 295 | } |
296 | 296 | } |
297 | 297 | |
298 | - $this->payment_form->set_items( $items ); |
|
298 | + $this->payment_form->set_items($items); |
|
299 | 299 | |
300 | 300 | } else { |
301 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
301 | + $this->payment_form->set_items($invoice->get_items()); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | $this->country = $invoice->get_country(); |
305 | 305 | $this->state = $invoice->get_state(); |
306 | 306 | $this->invoice = $invoice; |
307 | 307 | |
308 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
308 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | /** |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | * @return bool |
326 | 326 | */ |
327 | 327 | public function has_invoice() { |
328 | - return ! empty( $this->invoice ); |
|
328 | + return !empty($this->invoice); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | /* |
@@ -344,13 +344,13 @@ discard block |
||
344 | 344 | */ |
345 | 345 | public function process_items() { |
346 | 346 | |
347 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
347 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
348 | 348 | |
349 | - foreach ( $processor->items as $item ) { |
|
350 | - $this->add_item( $item ); |
|
349 | + foreach ($processor->items as $item) { |
|
350 | + $this->add_item($item); |
|
351 | 351 | } |
352 | 352 | |
353 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
353 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | /** |
@@ -359,20 +359,20 @@ discard block |
||
359 | 359 | * @since 1.0.19 |
360 | 360 | * @param GetPaid_Form_Item $item |
361 | 361 | */ |
362 | - public function add_item( $item ) { |
|
362 | + public function add_item($item) { |
|
363 | 363 | |
364 | 364 | // Make sure that it is available for purchase. |
365 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
365 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
366 | 366 | return; |
367 | 367 | } |
368 | 368 | |
369 | 369 | // Each submission can only contain one recurring item. |
370 | - if ( $item->is_recurring() ) { |
|
370 | + if ($item->is_recurring()) { |
|
371 | 371 | $this->has_recurring = $item->get_id(); |
372 | 372 | } |
373 | 373 | |
374 | 374 | // Update the items and totals. |
375 | - $this->items[ $item->get_id() ] = $item; |
|
375 | + $this->items[$item->get_id()] = $item; |
|
376 | 376 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
377 | 377 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
378 | 378 | |
@@ -386,17 +386,17 @@ discard block |
||
386 | 386 | * |
387 | 387 | * @since 1.0.19 |
388 | 388 | */ |
389 | - public function remove_item( $item_id ) { |
|
389 | + public function remove_item($item_id) { |
|
390 | 390 | |
391 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
392 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
393 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
391 | + if (isset($this->items[$item_id])) { |
|
392 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
393 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
394 | 394 | |
395 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
395 | + if ($this->items[$item_id]->is_recurring()) { |
|
396 | 396 | $this->has_recurring = 0; |
397 | 397 | } |
398 | 398 | |
399 | - unset( $this->items[ $item_id ] ); |
|
399 | + unset($this->items[$item_id]); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | } |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | */ |
409 | 409 | public function get_subtotal() { |
410 | 410 | |
411 | - if ( wpinv_prices_include_tax() ) { |
|
411 | + if (wpinv_prices_include_tax()) { |
|
412 | 412 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
413 | 413 | } |
414 | 414 | |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | */ |
423 | 423 | public function get_recurring_subtotal() { |
424 | 424 | |
425 | - if ( wpinv_prices_include_tax() ) { |
|
425 | + if (wpinv_prices_include_tax()) { |
|
426 | 426 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
427 | 427 | } |
428 | 428 | |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | * @return bool |
447 | 447 | */ |
448 | 448 | public function has_subscription_group() { |
449 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
449 | + return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this)); |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | /** |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | * @return bool |
457 | 457 | */ |
458 | 458 | public function has_multiple_subscription_groups() { |
459 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
459 | + return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this)); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | /* |
@@ -476,39 +476,39 @@ discard block |
||
476 | 476 | public function process_taxes() { |
477 | 477 | |
478 | 478 | // Abort if we're not using taxes. |
479 | - if ( ! $this->use_taxes() ) { |
|
479 | + if (!$this->use_taxes()) { |
|
480 | 480 | return; |
481 | 481 | } |
482 | 482 | |
483 | 483 | // If a custom country && state has been passed in, use it to calculate taxes. |
484 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
485 | - if ( ! empty( $country ) ) { |
|
484 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
485 | + if (!empty($country)) { |
|
486 | 486 | $this->country = $country; |
487 | 487 | } |
488 | 488 | |
489 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
490 | - if ( ! empty( $state ) ) { |
|
489 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
490 | + if (!empty($state)) { |
|
491 | 491 | $this->state = $state; |
492 | 492 | } |
493 | 493 | |
494 | 494 | // Confirm if the provided country and the ip country are similar. |
495 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
496 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
497 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
495 | + $address_confirmed = $this->get_field('confirm-address'); |
|
496 | + if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
497 | + throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing')); |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | // Abort if the country is not taxable. |
501 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
501 | + if (!wpinv_is_country_taxable($this->country)) { |
|
502 | 502 | return; |
503 | 503 | } |
504 | 504 | |
505 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
505 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
506 | 506 | |
507 | - foreach ( $processor->taxes as $tax ) { |
|
508 | - $this->add_tax( $tax ); |
|
507 | + foreach ($processor->taxes as $tax) { |
|
508 | + $this->add_tax($tax); |
|
509 | 509 | } |
510 | 510 | |
511 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
511 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | /** |
@@ -517,16 +517,16 @@ discard block |
||
517 | 517 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
518 | 518 | * @since 1.0.19 |
519 | 519 | */ |
520 | - public function add_tax( $tax ) { |
|
520 | + public function add_tax($tax) { |
|
521 | 521 | |
522 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
523 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
524 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
522 | + if (wpinv_round_tax_per_tax_rate()) { |
|
523 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
524 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
525 | 525 | } |
526 | 526 | |
527 | - $this->taxes[ $tax['name'] ] = $tax; |
|
528 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
529 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
527 | + $this->taxes[$tax['name']] = $tax; |
|
528 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
529 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
530 | 530 | |
531 | 531 | } |
532 | 532 | |
@@ -535,12 +535,12 @@ discard block |
||
535 | 535 | * |
536 | 536 | * @since 1.0.19 |
537 | 537 | */ |
538 | - public function remove_tax( $tax_name ) { |
|
538 | + public function remove_tax($tax_name) { |
|
539 | 539 | |
540 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
541 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
542 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
543 | - unset( $this->taxes[ $tax_name ] ); |
|
540 | + if (isset($this->taxes[$tax_name])) { |
|
541 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
542 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
543 | + unset($this->taxes[$tax_name]); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | } |
@@ -554,11 +554,11 @@ discard block |
||
554 | 554 | |
555 | 555 | $use_taxes = wpinv_use_taxes(); |
556 | 556 | |
557 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
557 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
558 | 558 | $use_taxes = false; |
559 | 559 | } |
560 | 560 | |
561 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
561 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
562 | 562 | |
563 | 563 | } |
564 | 564 | |
@@ -607,13 +607,13 @@ discard block |
||
607 | 607 | |
608 | 608 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
609 | 609 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
610 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
610 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
611 | 611 | |
612 | - foreach ( $processor->discounts as $discount ) { |
|
613 | - $this->add_discount( $discount ); |
|
612 | + foreach ($processor->discounts as $discount) { |
|
613 | + $this->add_discount($discount); |
|
614 | 614 | } |
615 | 615 | |
616 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
616 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | /** |
@@ -622,10 +622,10 @@ discard block |
||
622 | 622 | * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
623 | 623 | * @since 1.0.19 |
624 | 624 | */ |
625 | - public function add_discount( $discount ) { |
|
626 | - $this->discounts[ $discount['name'] ] = $discount; |
|
627 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
628 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
625 | + public function add_discount($discount) { |
|
626 | + $this->discounts[$discount['name']] = $discount; |
|
627 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
628 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | /** |
@@ -633,12 +633,12 @@ discard block |
||
633 | 633 | * |
634 | 634 | * @since 1.0.19 |
635 | 635 | */ |
636 | - public function remove_discount( $name ) { |
|
636 | + public function remove_discount($name) { |
|
637 | 637 | |
638 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
639 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
640 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
641 | - unset( $this->discounts[ $name ] ); |
|
638 | + if (isset($this->discounts[$name])) { |
|
639 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
640 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
641 | + unset($this->discounts[$name]); |
|
642 | 642 | } |
643 | 643 | |
644 | 644 | } |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | * @return bool |
651 | 651 | */ |
652 | 652 | public function has_discount_code() { |
653 | - return ! empty( $this->discounts['discount_code'] ); |
|
653 | + return !empty($this->discounts['discount_code']); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | /** |
@@ -707,13 +707,13 @@ discard block |
||
707 | 707 | */ |
708 | 708 | public function process_fees() { |
709 | 709 | |
710 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
710 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
711 | 711 | |
712 | - foreach ( $fees_processor->fees as $fee ) { |
|
713 | - $this->add_fee( $fee ); |
|
712 | + foreach ($fees_processor->fees as $fee) { |
|
713 | + $this->add_fee($fee); |
|
714 | 714 | } |
715 | 715 | |
716 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
716 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
717 | 717 | } |
718 | 718 | |
719 | 719 | /** |
@@ -722,11 +722,11 @@ discard block |
||
722 | 722 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
723 | 723 | * @since 1.0.19 |
724 | 724 | */ |
725 | - public function add_fee( $fee ) { |
|
725 | + public function add_fee($fee) { |
|
726 | 726 | |
727 | - $this->fees[ $fee['name'] ] = $fee; |
|
728 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
729 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
727 | + $this->fees[$fee['name']] = $fee; |
|
728 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
729 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
730 | 730 | |
731 | 731 | } |
732 | 732 | |
@@ -735,12 +735,12 @@ discard block |
||
735 | 735 | * |
736 | 736 | * @since 1.0.19 |
737 | 737 | */ |
738 | - public function remove_fee( $name ) { |
|
738 | + public function remove_fee($name) { |
|
739 | 739 | |
740 | - if ( isset( $this->fees[ $name ] ) ) { |
|
741 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
742 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
743 | - unset( $this->fees[ $name ] ); |
|
740 | + if (isset($this->fees[$name])) { |
|
741 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
742 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
743 | + unset($this->fees[$name]); |
|
744 | 744 | } |
745 | 745 | |
746 | 746 | } |
@@ -779,7 +779,7 @@ discard block |
||
779 | 779 | * @since 1.0.19 |
780 | 780 | */ |
781 | 781 | public function has_fees() { |
782 | - return count( $this->fees ) !== 0; |
|
782 | + return count($this->fees) !== 0; |
|
783 | 783 | } |
784 | 784 | |
785 | 785 | /* |
@@ -797,7 +797,7 @@ discard block |
||
797 | 797 | * @since 1.0.19 |
798 | 798 | */ |
799 | 799 | public function is_initial_fetch() { |
800 | - return empty( $this->data['initial_state'] ); |
|
800 | + return empty($this->data['initial_state']); |
|
801 | 801 | } |
802 | 802 | |
803 | 803 | /** |
@@ -807,7 +807,7 @@ discard block |
||
807 | 807 | */ |
808 | 808 | public function get_total() { |
809 | 809 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
810 | - return max( $total, 0 ); |
|
810 | + return max($total, 0); |
|
811 | 811 | } |
812 | 812 | |
813 | 813 | /** |
@@ -817,7 +817,7 @@ discard block |
||
817 | 817 | */ |
818 | 818 | public function get_recurring_total() { |
819 | 819 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
820 | - return max( $total, 0 ); |
|
820 | + return max($total, 0); |
|
821 | 821 | } |
822 | 822 | |
823 | 823 | /** |
@@ -829,12 +829,12 @@ discard block |
||
829 | 829 | $initial = $this->get_total(); |
830 | 830 | $recurring = $this->get_recurring_total(); |
831 | 831 | |
832 | - if ( $this->has_recurring == 0 ) { |
|
832 | + if ($this->has_recurring == 0) { |
|
833 | 833 | $recurring = 0; |
834 | 834 | } |
835 | 835 | |
836 | 836 | $collect = $initial > 0 || $recurring > 0; |
837 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
837 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
838 | 838 | } |
839 | 839 | |
840 | 840 | /** |
@@ -843,7 +843,7 @@ discard block |
||
843 | 843 | * @since 1.0.19 |
844 | 844 | */ |
845 | 845 | public function get_billing_email() { |
846 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
846 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
847 | 847 | } |
848 | 848 | |
849 | 849 | /** |
@@ -853,7 +853,7 @@ discard block |
||
853 | 853 | */ |
854 | 854 | public function has_billing_email() { |
855 | 855 | $billing_email = $this->get_billing_email(); |
856 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
856 | + return !empty($billing_email) && is_email($billing_email); |
|
857 | 857 | } |
858 | 858 | |
859 | 859 | /** |
@@ -883,8 +883,8 @@ discard block |
||
883 | 883 | * @since 1.0.19 |
884 | 884 | * @return mixed|null |
885 | 885 | */ |
886 | - public function get_field( $field, $sub_array_key = null ) { |
|
887 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
886 | + public function get_field($field, $sub_array_key = null) { |
|
887 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
888 | 888 | } |
889 | 889 | |
890 | 890 | /** |
@@ -892,8 +892,8 @@ discard block |
||
892 | 892 | * |
893 | 893 | * @since 1.0.19 |
894 | 894 | */ |
895 | - public function is_required_field_set( $field ) { |
|
896 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
895 | + public function is_required_field_set($field) { |
|
896 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
897 | 897 | } |
898 | 898 | |
899 | 899 | /** |
@@ -901,8 +901,8 @@ discard block |
||
901 | 901 | * |
902 | 902 | * @since 1.0.19 |
903 | 903 | */ |
904 | - public function format_amount( $amount ) { |
|
905 | - return wpinv_price( $amount, $this->get_currency() ); |
|
904 | + public function format_amount($amount) { |
|
905 | + return wpinv_price($amount, $this->get_currency()); |
|
906 | 906 | } |
907 | 907 | |
908 | 908 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Contains gateway functions. |
4 | 4 | * |
5 | 5 | */ |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * Returns an array of payment gateways. |
@@ -11,30 +11,30 @@ discard block |
||
11 | 11 | * @return array |
12 | 12 | */ |
13 | 13 | function wpinv_get_payment_gateways() { |
14 | - return apply_filters( 'wpinv_payment_gateways', array() ); |
|
14 | + return apply_filters('wpinv_payment_gateways', array()); |
|
15 | 15 | } |
16 | 16 | |
17 | -function wpinv_payment_gateway_titles( $all_gateways ) { |
|
17 | +function wpinv_payment_gateway_titles($all_gateways) { |
|
18 | 18 | |
19 | 19 | $options = wpinv_get_options(); |
20 | 20 | $gateways = array(); |
21 | - foreach ( $all_gateways as $key => $gateway ) { |
|
22 | - if ( !empty( $options[$key . '_title'] ) ) { |
|
23 | - $all_gateways[$key]['checkout_label'] = __( $options[$key . '_title'], 'invoicing' ); |
|
21 | + foreach ($all_gateways as $key => $gateway) { |
|
22 | + if (!empty($options[$key . '_title'])) { |
|
23 | + $all_gateways[$key]['checkout_label'] = __($options[$key . '_title'], 'invoicing'); |
|
24 | 24 | } |
25 | 25 | |
26 | - $gateways[$key] = isset( $options[$key . '_ordering'] ) ? $options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' ); |
|
26 | + $gateways[$key] = isset($options[$key . '_ordering']) ? $options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : ''); |
|
27 | 27 | } |
28 | 28 | |
29 | - asort( $gateways ); |
|
29 | + asort($gateways); |
|
30 | 30 | |
31 | - foreach ( $gateways as $gateway => $key ) { |
|
31 | + foreach ($gateways as $gateway => $key) { |
|
32 | 32 | $gateways[$gateway] = $all_gateways[$gateway]; |
33 | 33 | } |
34 | 34 | |
35 | 35 | return $gateways; |
36 | 36 | } |
37 | -add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 ); |
|
37 | +add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1); |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Returns an array of enabled gateways. |
@@ -42,38 +42,38 @@ discard block |
||
42 | 42 | * @param bool $sort |
43 | 43 | * @return array |
44 | 44 | */ |
45 | -function wpinv_get_enabled_payment_gateways( $sort = false ) { |
|
45 | +function wpinv_get_enabled_payment_gateways($sort = false) { |
|
46 | 46 | |
47 | 47 | $enabled = array(); |
48 | 48 | |
49 | - foreach ( wpinv_get_payment_gateways() as $gateway => $data ) { |
|
49 | + foreach (wpinv_get_payment_gateways() as $gateway => $data) { |
|
50 | 50 | |
51 | - if ( (int) wpinv_get_option( "{$gateway}_active", $gateway === 'manual' ) === 1 ) { |
|
52 | - $enabled[ $gateway ] = $data; |
|
51 | + if ((int) wpinv_get_option("{$gateway}_active", $gateway === 'manual') === 1) { |
|
52 | + $enabled[$gateway] = $data; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | } |
56 | 56 | |
57 | - if ( true === $sort ) { |
|
58 | - uasort( $enabled, 'wpinv_sort_gateway_order' ); |
|
57 | + if (true === $sort) { |
|
58 | + uasort($enabled, 'wpinv_sort_gateway_order'); |
|
59 | 59 | |
60 | 60 | // Reorder our gateways so the default is first |
61 | 61 | $default_gateway_id = wpinv_get_default_gateway(); |
62 | - if ( isset( $enabled[ $default_gateway_id ] ) ) { |
|
62 | + if (isset($enabled[$default_gateway_id])) { |
|
63 | 63 | $default_gateway = array( |
64 | - $default_gateway_id => $enabled[ $default_gateway_id ] |
|
64 | + $default_gateway_id => $enabled[$default_gateway_id] |
|
65 | 65 | ); |
66 | 66 | |
67 | - unset( $enabled[ $default_gateway_id ] ); |
|
68 | - $enabled = array_merge( $default_gateway, $enabled ); |
|
67 | + unset($enabled[$default_gateway_id]); |
|
68 | + $enabled = array_merge($default_gateway, $enabled); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | } |
72 | 72 | |
73 | - return apply_filters( 'wpinv_enabled_payment_gateways', $enabled ); |
|
73 | + return apply_filters('wpinv_enabled_payment_gateways', $enabled); |
|
74 | 74 | } |
75 | 75 | |
76 | -function wpinv_sort_gateway_order( $a, $b ) { |
|
76 | +function wpinv_sort_gateway_order($a, $b) { |
|
77 | 77 | return $a['ordering'] - $b['ordering']; |
78 | 78 | } |
79 | 79 | |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | * @param string $gateway |
84 | 84 | * @return bool |
85 | 85 | */ |
86 | -function wpinv_is_gateway_active( $gateway ) { |
|
87 | - $is_active = (int) wpinv_get_option( "{$gateway}_active", $gateway === 'manual' ) === 1 ; |
|
88 | - return apply_filters( 'wpinv_is_gateway_active', $is_active, $gateway ); |
|
86 | +function wpinv_is_gateway_active($gateway) { |
|
87 | + $is_active = (int) wpinv_get_option("{$gateway}_active", $gateway === 'manual') === 1; |
|
88 | + return apply_filters('wpinv_is_gateway_active', $is_active, $gateway); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -94,11 +94,11 @@ discard block |
||
94 | 94 | * @return string|false |
95 | 95 | */ |
96 | 96 | function wpinv_get_default_gateway() { |
97 | - $default = wpinv_get_option( 'default_gateway' ); |
|
97 | + $default = wpinv_get_option('default_gateway'); |
|
98 | 98 | $gateways = wpinv_get_enabled_payment_gateways(); |
99 | - $default = ! empty( $default ) && isset( $gateways[ $default ] ) ? $default : false; |
|
99 | + $default = !empty($default) && isset($gateways[$default]) ? $default : false; |
|
100 | 100 | |
101 | - return apply_filters( 'wpinv_default_gateway', $default ); |
|
101 | + return apply_filters('wpinv_default_gateway', $default); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -107,17 +107,17 @@ discard block |
||
107 | 107 | * @param string $gateway The gateway to key. |
108 | 108 | * @return string |
109 | 109 | */ |
110 | -function wpinv_get_gateway_admin_label( $gateway ) { |
|
110 | +function wpinv_get_gateway_admin_label($gateway) { |
|
111 | 111 | |
112 | - if ( empty( $gateway ) || 'none' == $gateway ) { |
|
113 | - return esc_html__( 'No Gateway', 'invoicing' ); |
|
112 | + if (empty($gateway) || 'none' == $gateway) { |
|
113 | + return esc_html__('No Gateway', 'invoicing'); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | $gateways = wpinv_get_payment_gateways(); |
117 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway; |
|
118 | - $gateway = apply_filters( 'wpinv_gateway_admin_label', $label, $gateway ); |
|
117 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway; |
|
118 | + $gateway = apply_filters('wpinv_gateway_admin_label', $label, $gateway); |
|
119 | 119 | |
120 | - return wpinv_clean( $gateway ); |
|
120 | + return wpinv_clean($gateway); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -125,48 +125,48 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @param string $gateway |
127 | 127 | */ |
128 | -function wpinv_get_gateway_description( $gateway ) { |
|
128 | +function wpinv_get_gateway_description($gateway) { |
|
129 | 129 | |
130 | 130 | $options = wpinv_get_options(); |
131 | - $description = ! empty( $options[$gateway . '_desc'] ) ? $options[$gateway . '_desc'] : ''; |
|
131 | + $description = !empty($options[$gateway . '_desc']) ? $options[$gateway . '_desc'] : ''; |
|
132 | 132 | |
133 | - return apply_filters( 'wpinv_gateway_description', $description, $gateway ); |
|
133 | + return apply_filters('wpinv_gateway_description', $description, $gateway); |
|
134 | 134 | } |
135 | 135 | |
136 | -function wpinv_get_gateway_button_label( $gateway ) { |
|
137 | - return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' ); |
|
136 | +function wpinv_get_gateway_button_label($gateway) { |
|
137 | + return apply_filters('wpinv_gateway_' . $gateway . '_button_label', ''); |
|
138 | 138 | } |
139 | 139 | |
140 | -function wpinv_get_gateway_checkout_label( $gateway ) { |
|
140 | +function wpinv_get_gateway_checkout_label($gateway) { |
|
141 | 141 | $gateways = wpinv_get_payment_gateways(); |
142 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway; |
|
142 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway; |
|
143 | 143 | |
144 | - if ( $gateway == 'none' ) { |
|
145 | - $label = __( 'None', 'invoicing' ); |
|
144 | + if ($gateway == 'none') { |
|
145 | + $label = __('None', 'invoicing'); |
|
146 | 146 | } |
147 | 147 | |
148 | - return apply_filters( 'wpinv_gateway_checkout_label', ucfirst( $label ), $gateway ); |
|
148 | + return apply_filters('wpinv_gateway_checkout_label', ucfirst($label), $gateway); |
|
149 | 149 | } |
150 | 150 | |
151 | -function wpinv_settings_sections_gateways( $settings ) { |
|
151 | +function wpinv_settings_sections_gateways($settings) { |
|
152 | 152 | $gateways = wpinv_get_payment_gateways(); |
153 | - ksort( $gateways ); |
|
153 | + ksort($gateways); |
|
154 | 154 | |
155 | - foreach ( $gateways as $key => $gateway ) { |
|
156 | - $settings[ $key ] = $gateway['admin_label']; |
|
155 | + foreach ($gateways as $key => $gateway) { |
|
156 | + $settings[$key] = $gateway['admin_label']; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | return $settings; |
160 | 160 | } |
161 | -add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 ); |
|
161 | +add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1); |
|
162 | 162 | |
163 | 163 | /** |
164 | 164 | * Adds GateWay settings. |
165 | 165 | */ |
166 | -function wpinv_settings_gateways( $settings ) { |
|
166 | +function wpinv_settings_gateways($settings) { |
|
167 | 167 | |
168 | 168 | // Loop through each gateway. |
169 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
169 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
170 | 170 | |
171 | 171 | $gateway_settings = array( |
172 | 172 | |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | "{$key}_header" => array( |
175 | 175 | |
176 | 176 | 'id' => "{$key}_gateway_header", |
177 | - 'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>', |
|
177 | + 'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>', |
|
178 | 178 | 'custom' => $key, |
179 | 179 | 'type' => 'gateway_header', |
180 | 180 | |
@@ -183,8 +183,8 @@ discard block |
||
183 | 183 | // Activate/Deactivate a gateway. |
184 | 184 | "{$key}_active" => array( |
185 | 185 | 'id' => $key . '_active', |
186 | - 'name' => __( 'Activate', 'invoicing' ), |
|
187 | - 'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ), |
|
186 | + 'name' => __('Activate', 'invoicing'), |
|
187 | + 'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']), |
|
188 | 188 | 'type' => 'checkbox', |
189 | 189 | 'std' => $key === 'manual' ? '1' : '0', |
190 | 190 | ), |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | // Activate/Deactivate sandbox. |
193 | 193 | "{$key}_sandbox" => array( |
194 | 194 | 'id' => $key . '_sandbox', |
195 | - 'name' => __( 'Sandbox', 'invoicing' ), |
|
196 | - 'desc' => __( 'Enable sandbox to test payments', 'invoicing' ), |
|
195 | + 'name' => __('Sandbox', 'invoicing'), |
|
196 | + 'desc' => __('Enable sandbox to test payments', 'invoicing'), |
|
197 | 197 | 'type' => 'checkbox', |
198 | 198 | 'std' => '1', |
199 | 199 | ), |
@@ -201,40 +201,40 @@ discard block |
||
201 | 201 | // Checkout title. |
202 | 202 | "{$key}_title" => array( |
203 | 203 | 'id' => $key . '_title', |
204 | - 'name' => __( 'Checkout Title', 'invoicing' ), |
|
205 | - 'std' => isset( $gateway['checkout_label'] ) ? $gateway['checkout_label'] : '', |
|
204 | + 'name' => __('Checkout Title', 'invoicing'), |
|
205 | + 'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : '', |
|
206 | 206 | 'type' => 'text', |
207 | 207 | ), |
208 | 208 | |
209 | 209 | // Checkout description. |
210 | 210 | "{$key}_desc" => array( |
211 | 211 | 'id' => $key . '_desc', |
212 | - 'name' => __( 'Checkout Description', 'invoicing' ), |
|
213 | - 'std' => apply_filters( "getpaid_default_{$key}_checkout_description", '' ), |
|
212 | + 'name' => __('Checkout Description', 'invoicing'), |
|
213 | + 'std' => apply_filters("getpaid_default_{$key}_checkout_description", ''), |
|
214 | 214 | 'type' => 'text', |
215 | 215 | ), |
216 | 216 | |
217 | 217 | // Checkout order. |
218 | 218 | "{$key}_ordering" => array( |
219 | 219 | 'id' => $key . '_ordering', |
220 | - 'name' => __( 'Priority', 'invoicing' ), |
|
221 | - 'std' => apply_filters( "getpaid_default_{$key}_checkout_description", '' ), |
|
220 | + 'name' => __('Priority', 'invoicing'), |
|
221 | + 'std' => apply_filters("getpaid_default_{$key}_checkout_description", ''), |
|
222 | 222 | 'type' => 'number', |
223 | 223 | 'step' => '1', |
224 | 224 | 'min' => '0', |
225 | 225 | 'max' => '100000', |
226 | - 'std' => isset( $gateway['ordering'] ) ? $gateway['ordering'] : '10', |
|
226 | + 'std' => isset($gateway['ordering']) ? $gateway['ordering'] : '10', |
|
227 | 227 | ), |
228 | 228 | |
229 | 229 | ); |
230 | 230 | |
231 | 231 | // Maybe remove the sandbox. |
232 | - if ( ! getpaid_payment_gateway_supports( $key, 'sandbox' ) ) { |
|
233 | - unset( $gateway_settings["{$key}_sandbox"] ); |
|
232 | + if (!getpaid_payment_gateway_supports($key, 'sandbox')) { |
|
233 | + unset($gateway_settings["{$key}_sandbox"]); |
|
234 | 234 | } |
235 | 235 | |
236 | - $gateway_settings = apply_filters( 'wpinv_gateway_settings', $gateway_settings, $key, $gateway ); |
|
237 | - $gateway_settings = apply_filters( 'wpinv_gateway_settings_' . $key, $gateway_settings, $gateway ); |
|
236 | + $gateway_settings = apply_filters('wpinv_gateway_settings', $gateway_settings, $key, $gateway); |
|
237 | + $gateway_settings = apply_filters('wpinv_gateway_settings_' . $key, $gateway_settings, $gateway); |
|
238 | 238 | |
239 | 239 | $settings[$key] = $gateway_settings; |
240 | 240 | } |
@@ -242,10 +242,10 @@ discard block |
||
242 | 242 | return $settings; |
243 | 243 | |
244 | 244 | } |
245 | -add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 ); |
|
245 | +add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1); |
|
246 | 246 | |
247 | -function wpinv_gateway_header_callback( $args ) { |
|
248 | - echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />'; |
|
247 | +function wpinv_gateway_header_callback($args) { |
|
248 | + echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />'; |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -256,61 +256,61 @@ discard block |
||
256 | 256 | * @return bool |
257 | 257 | * @since 2.3.0 |
258 | 258 | */ |
259 | -function getpaid_payment_gateway_supports( $gateway, $feature ) { |
|
259 | +function getpaid_payment_gateway_supports($gateway, $feature) { |
|
260 | 260 | |
261 | 261 | $supports = false; |
262 | 262 | |
263 | - $supports = apply_filters( "getpaid_{$gateway}_supports_{$feature}", false ); |
|
263 | + $supports = apply_filters("getpaid_{$gateway}_supports_{$feature}", false); |
|
264 | 264 | |
265 | 265 | // Backwards compatibility. |
266 | - $supports = apply_filters( "wpinv_{$gateway}_supports_{$feature}", $supports ); |
|
267 | - $supports = apply_filters( "wpinv_{$gateway}_support_{$feature}", $supports ); |
|
266 | + $supports = apply_filters("wpinv_{$gateway}_supports_{$feature}", $supports); |
|
267 | + $supports = apply_filters("wpinv_{$gateway}_support_{$feature}", $supports); |
|
268 | 268 | |
269 | - $supports = apply_filters( "getpaid_gateway_supports_{$feature}", $supports, $gateway ); |
|
270 | - $supports = apply_filters( 'getpaid_payment_gateway_supports', $supports, $feature, $gateway ); |
|
269 | + $supports = apply_filters("getpaid_gateway_supports_{$feature}", $supports, $gateway); |
|
270 | + $supports = apply_filters('getpaid_payment_gateway_supports', $supports, $feature, $gateway); |
|
271 | 271 | |
272 | 272 | return $supports; |
273 | 273 | } |
274 | 274 | |
275 | -function wpinv_get_chosen_gateway( $invoice_id = 0 ) { |
|
276 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
275 | +function wpinv_get_chosen_gateway($invoice_id = 0) { |
|
276 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
277 | 277 | |
278 | 278 | $chosen = false; |
279 | - if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
279 | + if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) { |
|
280 | 280 | $chosen = $invoice->get_gateway(); |
281 | 281 | } |
282 | 282 | |
283 | - $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
283 | + $chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen; |
|
284 | 284 | |
285 | - if ( false !== $chosen ) { |
|
286 | - $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
285 | + if (false !== $chosen) { |
|
286 | + $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen); |
|
287 | 287 | } |
288 | 288 | |
289 | - if ( ! empty ( $chosen ) ) { |
|
290 | - $enabled_gateway = urldecode( $chosen ); |
|
291 | - } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
289 | + if (!empty ($chosen)) { |
|
290 | + $enabled_gateway = urldecode($chosen); |
|
291 | + } else if (!empty($invoice) && (float) $invoice->get_subtotal() <= 0) { |
|
292 | 292 | $enabled_gateway = 'manual'; |
293 | 293 | } else { |
294 | 294 | $enabled_gateway = wpinv_get_default_gateway(); |
295 | 295 | } |
296 | 296 | |
297 | - if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) { |
|
298 | - if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){ |
|
297 | + if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) { |
|
298 | + if (wpinv_is_gateway_active(wpinv_get_default_gateway())) { |
|
299 | 299 | $enabled_gateway = wpinv_get_default_gateway(); |
300 | - }else{ |
|
300 | + } else { |
|
301 | 301 | $enabled_gateway = $gateways[0]; |
302 | 302 | } |
303 | 303 | |
304 | 304 | } |
305 | 305 | |
306 | - return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
306 | + return apply_filters('wpinv_chosen_gateway', $enabled_gateway); |
|
307 | 307 | } |
308 | 308 | |
309 | -function wpinv_record_gateway_error( $title = '', $message = '' ) { |
|
310 | - return wpinv_error_log( $message, $title ); |
|
309 | +function wpinv_record_gateway_error($title = '', $message = '') { |
|
310 | + return wpinv_error_log($message, $title); |
|
311 | 311 | } |
312 | 312 | |
313 | -function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
|
313 | +function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') { |
|
314 | 314 | $ret = 0; |
315 | 315 | $args = array( |
316 | 316 | 'meta_key' => '_wpinv_gateway', |
@@ -321,9 +321,9 @@ discard block |
||
321 | 321 | 'fields' => 'ids' |
322 | 322 | ); |
323 | 323 | |
324 | - $payments = new WP_Query( $args ); |
|
324 | + $payments = new WP_Query($args); |
|
325 | 325 | |
326 | - if( $payments ) |
|
326 | + if ($payments) |
|
327 | 327 | $ret = $payments->post_count; |
328 | 328 | return $ret; |
329 | 329 | } |
@@ -331,13 +331,13 @@ discard block |
||
331 | 331 | /** |
332 | 332 | * Displays the ipn url field. |
333 | 333 | */ |
334 | -function wpinv_ipn_url_callback( $args ) { |
|
335 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
334 | +function wpinv_ipn_url_callback($args) { |
|
335 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
336 | 336 | |
337 | 337 | $attrs = $args['readonly'] ? ' readonly' : ''; |
338 | 338 | |
339 | - $html = '<input class="regular-text" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" onClick="this.select()">'; |
|
340 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
339 | + $html = '<input class="regular-text" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" onClick="this.select()">'; |
|
340 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
341 | 341 | |
342 | 342 | echo $html; |
343 | 343 | } |
@@ -349,10 +349,10 @@ discard block |
||
349 | 349 | * |
350 | 350 | * @return bool |
351 | 351 | */ |
352 | -function wpinv_is_test_mode( $gateway = '' ) { |
|
353 | - $sandbox = empty( $gateway ) ? false : wpinv_get_option( "{$gateway}_sandbox", true ); |
|
354 | - $supports = getpaid_payment_gateway_supports( $gateway, 'sandbox' ); |
|
355 | - return apply_filters( 'wpinv_is_test_mode', $sandbox && $supports, $gateway ); |
|
352 | +function wpinv_is_test_mode($gateway = '') { |
|
353 | + $sandbox = empty($gateway) ? false : wpinv_get_option("{$gateway}_sandbox", true); |
|
354 | + $supports = getpaid_payment_gateway_supports($gateway, 'sandbox'); |
|
355 | + return apply_filters('wpinv_is_test_mode', $sandbox && $supports, $gateway); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | * |
364 | 364 | * @return string |
365 | 365 | */ |
366 | -function wpinv_get_ipn_url( $gateway = false, $args = array() ) { |
|
366 | +function wpinv_get_ipn_url($gateway = false, $args = array()) { |
|
367 | 367 | $args = wp_parse_args( |
368 | 368 | array( |
369 | 369 | 'wpi-listener' => 'IPN', |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | $args |
373 | 373 | ); |
374 | 374 | |
375 | - return apply_filters( 'wpinv_ipn_url', add_query_arg( $args, home_url( 'index.php' ) ), $gateway, $args ); |
|
375 | + return apply_filters('wpinv_ipn_url', add_query_arg($args, home_url('index.php')), $gateway, $args); |
|
376 | 376 | |
377 | 377 | } |
378 | 378 | |
@@ -383,34 +383,34 @@ discard block |
||
383 | 383 | * |
384 | 384 | * @return string |
385 | 385 | */ |
386 | -function getpaid_get_non_query_string_ipn_url( $gateway ) { |
|
387 | - $gateway = wpinv_sanitize_key( $gateway ); |
|
388 | - return home_url( "getpaid-ipn/$gateway" ); |
|
386 | +function getpaid_get_non_query_string_ipn_url($gateway) { |
|
387 | + $gateway = wpinv_sanitize_key($gateway); |
|
388 | + return home_url("getpaid-ipn/$gateway"); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | |
392 | 392 | /** |
393 | 393 | * Retrieves request data with slashes removed slashes. |
394 | 394 | */ |
395 | -function wpinv_get_post_data( $method = 'request' ) { |
|
395 | +function wpinv_get_post_data($method = 'request') { |
|
396 | 396 | |
397 | - if ( $method == 'post' ) { |
|
398 | - return wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
397 | + if ($method == 'post') { |
|
398 | + return wp_kses_post_deep(wp_unslash($_POST)); |
|
399 | 399 | } |
400 | 400 | |
401 | - if ( $method == 'get' ) { |
|
402 | - return wp_kses_post_deep( wp_unslash( $_GET ) ); |
|
401 | + if ($method == 'get') { |
|
402 | + return wp_kses_post_deep(wp_unslash($_GET)); |
|
403 | 403 | } |
404 | 404 | |
405 | - return wp_kses_post_deep( wp_unslash( $_REQUEST ) ); |
|
405 | + return wp_kses_post_deep(wp_unslash($_REQUEST)); |
|
406 | 406 | |
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
410 | 410 | * Checks if a given gateway supports subscription payments. |
411 | 411 | */ |
412 | -function wpinv_gateway_support_subscription( $gateway ) { |
|
413 | - return getpaid_payment_gateway_supports( $gateway, 'subscription' ); |
|
412 | +function wpinv_gateway_support_subscription($gateway) { |
|
413 | + return getpaid_payment_gateway_supports($gateway, 'subscription'); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -419,14 +419,14 @@ discard block |
||
419 | 419 | * @param array $gateways an array of gateways. |
420 | 420 | * @param GetPaid_Payment_Form $form payment form. |
421 | 421 | */ |
422 | -function wpinv_payment_gateways_on_cart( $gateways, $form ) { |
|
422 | +function wpinv_payment_gateways_on_cart($gateways, $form) { |
|
423 | 423 | |
424 | - if ( $form->is_recurring() ) { |
|
424 | + if ($form->is_recurring()) { |
|
425 | 425 | |
426 | - foreach ( array_keys( $gateways ) as $gateway ) { |
|
426 | + foreach (array_keys($gateways) as $gateway) { |
|
427 | 427 | |
428 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
429 | - unset( $gateways[$gateway] ); |
|
428 | + if (!wpinv_gateway_support_subscription($gateway)) { |
|
429 | + unset($gateways[$gateway]); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | } |
@@ -435,4 +435,4 @@ discard block |
||
435 | 435 | |
436 | 436 | return $gateways; |
437 | 437 | } |
438 | -add_filter( 'getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2 ); |
|
438 | +add_filter('getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2); |
@@ -13,65 +13,65 @@ discard block |
||
13 | 13 | class GetPaid_Worldpay_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'worldpay'; |
21 | 21 | |
22 | 22 | /** |
23 | - * Payment method order. |
|
24 | - * |
|
25 | - * @var int |
|
26 | - */ |
|
23 | + * Payment method order. |
|
24 | + * |
|
25 | + * @var int |
|
26 | + */ |
|
27 | 27 | public $order = 5; |
28 | 28 | |
29 | 29 | /** |
30 | - * Endpoint for requests from Worldpay. |
|
31 | - * |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $notify_url; |
|
35 | - |
|
36 | - /** |
|
37 | - * Endpoint for requests to Worldpay. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
30 | + * Endpoint for requests from Worldpay. |
|
31 | + * |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $notify_url; |
|
35 | + |
|
36 | + /** |
|
37 | + * Endpoint for requests to Worldpay. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | 41 | protected $endpoint; |
42 | 42 | |
43 | 43 | /** |
44 | - * An array of features that this gateway supports. |
|
45 | - * |
|
46 | - * @var array |
|
47 | - */ |
|
44 | + * An array of features that this gateway supports. |
|
45 | + * |
|
46 | + * @var array |
|
47 | + */ |
|
48 | 48 | protected $supports = array( 'sandbox' ); |
49 | 49 | |
50 | 50 | /** |
51 | - * Currencies this gateway is allowed for. |
|
52 | - * |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
51 | + * Currencies this gateway is allowed for. |
|
52 | + * |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
56 | 56 | |
57 | 57 | /** |
58 | - * URL to view a transaction. |
|
59 | - * |
|
60 | - * @var string |
|
61 | - */ |
|
58 | + * URL to view a transaction. |
|
59 | + * |
|
60 | + * @var string |
|
61 | + */ |
|
62 | 62 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
63 | 63 | |
64 | 64 | /** |
65 | - * URL to view a subscription. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
69 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
65 | + * URL to view a subscription. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
70 | 70 | |
71 | 71 | /** |
72 | - * Class constructor. |
|
73 | - */ |
|
74 | - public function __construct() { |
|
72 | + * Class constructor. |
|
73 | + */ |
|
74 | + public function __construct() { |
|
75 | 75 | |
76 | 76 | $this->method_title = __( 'Worldpay', 'invoicing' ); |
77 | 77 | $this->title = __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ); |
@@ -85,15 +85,15 @@ discard block |
||
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
88 | - * Process Payment. |
|
89 | - * |
|
90 | - * |
|
91 | - * @param WPInv_Invoice $invoice Invoice. |
|
92 | - * @param array $submission_data Posted checkout fields. |
|
93 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
88 | + * Process Payment. |
|
89 | + * |
|
90 | + * |
|
91 | + * @param WPInv_Invoice $invoice Invoice. |
|
92 | + * @param array $submission_data Posted checkout fields. |
|
93 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
97 | 97 | |
98 | 98 | // Get redirect url. |
99 | 99 | $worldpay_redirect = esc_url( $this->get_request_url( $invoice ) ); |
@@ -128,31 +128,31 @@ discard block |
||
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | - * Get the Worldpay request URL for an invoice. |
|
132 | - * |
|
133 | - * @param WPInv_Invoice $invoice Invoice object. |
|
134 | - * @return string |
|
135 | - */ |
|
136 | - public function get_request_url( $invoice ) { |
|
131 | + * Get the Worldpay request URL for an invoice. |
|
132 | + * |
|
133 | + * @param WPInv_Invoice $invoice Invoice object. |
|
134 | + * @return string |
|
135 | + */ |
|
136 | + public function get_request_url( $invoice ) { |
|
137 | 137 | |
138 | 138 | // Endpoint for this request |
139 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
139 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
140 | 140 | |
141 | 141 | return $this->endpoint; |
142 | 142 | |
143 | - } |
|
143 | + } |
|
144 | 144 | |
145 | 145 | /** |
146 | - * Get Worldpay Args for passing to Worldpay. |
|
147 | - * |
|
148 | - * @param WPInv_Invoice $invoice Invoice object. |
|
149 | - * @return array |
|
150 | - */ |
|
151 | - protected function get_worldpay_args( $invoice ) { |
|
152 | - |
|
153 | - return apply_filters( |
|
154 | - 'getpaid_worldpay_args', |
|
155 | - array( |
|
146 | + * Get Worldpay Args for passing to Worldpay. |
|
147 | + * |
|
148 | + * @param WPInv_Invoice $invoice Invoice object. |
|
149 | + * @return array |
|
150 | + */ |
|
151 | + protected function get_worldpay_args( $invoice ) { |
|
152 | + |
|
153 | + return apply_filters( |
|
154 | + 'getpaid_worldpay_args', |
|
155 | + array( |
|
156 | 156 | 'amount' => wpinv_sanitize_amount( $invoice->get_total() ), // mandatory |
157 | 157 | 'cartId' => wpinv_clean( $invoice->get_number() ), // mandatory reference for the item purchased |
158 | 158 | 'currency' => wpinv_clean( $invoice->get_currency() ), // mandatory |
@@ -177,18 +177,18 @@ discard block |
||
177 | 177 | 'countryString' => wpinv_clean( wpinv_country_name( $invoice->get_country() ) ), |
178 | 178 | 'compName' => wpinv_clean( $invoice->get_company() ), |
179 | 179 | ), |
180 | - $invoice |
|
181 | - ); |
|
180 | + $invoice |
|
181 | + ); |
|
182 | 182 | |
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
186 | - * Secures worldpay args with an md5 hash. |
|
187 | - * |
|
188 | - * @param array $args Gateway args. |
|
189 | - * @return array |
|
190 | - */ |
|
191 | - public function hash_args( $args ) { |
|
186 | + * Secures worldpay args with an md5 hash. |
|
187 | + * |
|
188 | + * @param array $args Gateway args. |
|
189 | + * @return array |
|
190 | + */ |
|
191 | + public function hash_args( $args ) { |
|
192 | 192 | |
193 | 193 | $md5_secret = $this->get_option( 'md5_secret' ); |
194 | 194 | |
@@ -204,16 +204,16 @@ discard block |
||
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
207 | - * Processes ipns and marks payments as complete. |
|
208 | - * |
|
209 | - * @return void |
|
210 | - */ |
|
211 | - public function verify_ipn() { |
|
207 | + * Processes ipns and marks payments as complete. |
|
208 | + * |
|
209 | + * @return void |
|
210 | + */ |
|
211 | + public function verify_ipn() { |
|
212 | 212 | |
213 | 213 | // Validate the IPN. |
214 | 214 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
215 | - wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
216 | - } |
|
215 | + wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
216 | + } |
|
217 | 217 | |
218 | 218 | // Process the IPN. |
219 | 219 | $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
@@ -229,8 +229,8 @@ discard block |
||
229 | 229 | $invoice->set_transaction_id( wpinv_clean( $posted['transId'] ) ); |
230 | 230 | } |
231 | 231 | |
232 | - // Update the ip address. |
|
233 | - if ( ! empty( $posted['ipAddress'] ) ) { |
|
232 | + // Update the ip address. |
|
233 | + if ( ! empty( $posted['ipAddress'] ) ) { |
|
234 | 234 | $invoice->set_ip( wpinv_clean( $posted['ipAddress'] ) ); |
235 | 235 | } |
236 | 236 | |
@@ -257,9 +257,9 @@ discard block |
||
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
260 | - * Check Worldpay IPN validity. |
|
261 | - */ |
|
262 | - public function validate_ipn() { |
|
260 | + * Check Worldpay IPN validity. |
|
261 | + */ |
|
262 | + public function validate_ipn() { |
|
263 | 263 | |
264 | 264 | wpinv_error_log( 'Validating Worldpay IPN response' ); |
265 | 265 | |
@@ -305,11 +305,11 @@ discard block |
||
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
308 | - * Filters the gateway settings. |
|
309 | - * |
|
310 | - * @param array $admin_settings |
|
311 | - */ |
|
312 | - public function admin_settings( $admin_settings ) { |
|
308 | + * Filters the gateway settings. |
|
309 | + * |
|
310 | + * @param array $admin_settings |
|
311 | + */ |
|
312 | + public function admin_settings( $admin_settings ) { |
|
313 | 313 | |
314 | 314 | $currencies = sprintf( |
315 | 315 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | 'readonly' => true |
351 | 351 | ); |
352 | 352 | |
353 | - return $admin_settings; |
|
354 | - } |
|
353 | + return $admin_settings; |
|
354 | + } |
|
355 | 355 | |
356 | 356 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Worldpay Payment Gateway class. |
@@ -45,14 +45,14 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @var array |
47 | 47 | */ |
48 | - protected $supports = array( 'sandbox' ); |
|
48 | + protected $supports = array('sandbox'); |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Currencies this gateway is allowed for. |
52 | 52 | * |
53 | 53 | * @var array |
54 | 54 | */ |
55 | - public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
55 | + public $currencies = array('AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR'); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * URL to view a transaction. |
@@ -73,13 +73,13 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function __construct() { |
75 | 75 | |
76 | - $this->method_title = __( 'Worldpay', 'invoicing' ); |
|
77 | - $this->title = __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ); |
|
78 | - $this->checkout_button_text = __( 'Proceed to Worldpay', 'invoicing' ); |
|
79 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
76 | + $this->method_title = __('Worldpay', 'invoicing'); |
|
77 | + $this->title = __('Worldpay - Credit Card / Debit Card', 'invoicing'); |
|
78 | + $this->checkout_button_text = __('Proceed to Worldpay', 'invoicing'); |
|
79 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
80 | 80 | |
81 | - add_filter( 'wpinv_gateway_description', array( $this, 'sandbox_notice' ), 10, 2 ); |
|
82 | - add_filter( 'getpaid_worldpay_args', array( $this, 'hash_args' ) ); |
|
81 | + add_filter('wpinv_gateway_description', array($this, 'sandbox_notice'), 10, 2); |
|
82 | + add_filter('getpaid_worldpay_args', array($this, 'hash_args')); |
|
83 | 83 | |
84 | 84 | parent::__construct(); |
85 | 85 | } |
@@ -93,24 +93,24 @@ discard block |
||
93 | 93 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
94 | 94 | * @return array |
95 | 95 | */ |
96 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
96 | + public function process_payment($invoice, $submission_data, $submission) { |
|
97 | 97 | |
98 | 98 | // Get redirect url. |
99 | - $worldpay_redirect = esc_url( $this->get_request_url( $invoice ) ); |
|
99 | + $worldpay_redirect = esc_url($this->get_request_url($invoice)); |
|
100 | 100 | |
101 | 101 | // Get submission args. |
102 | - $worldpay_args = $this->get_worldpay_args( $invoice ); |
|
102 | + $worldpay_args = $this->get_worldpay_args($invoice); |
|
103 | 103 | |
104 | 104 | $form = "<form action='$worldpay_redirect' name='wpi_worldpay_form' method='POST'>"; |
105 | 105 | |
106 | - foreach ( $worldpay_args as $key => $value ) { |
|
106 | + foreach ($worldpay_args as $key => $value) { |
|
107 | 107 | |
108 | - if ( false === $value || '' === trim( $value ) ) { |
|
108 | + if (false === $value || '' === trim($value)) { |
|
109 | 109 | continue; |
110 | 110 | } |
111 | 111 | |
112 | - $value = esc_attr( $value ); |
|
113 | - $key = wpinv_clean( $key ); |
|
112 | + $value = esc_attr($value); |
|
113 | + $key = wpinv_clean($key); |
|
114 | 114 | $form .= "<input type='hidden' name='$key' value='$value'>"; |
115 | 115 | } |
116 | 116 | |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | * @param WPInv_Invoice $invoice Invoice object. |
134 | 134 | * @return string |
135 | 135 | */ |
136 | - public function get_request_url( $invoice ) { |
|
136 | + public function get_request_url($invoice) { |
|
137 | 137 | |
138 | 138 | // Endpoint for this request |
139 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
139 | + $this->endpoint = $this->is_sandbox($invoice) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
140 | 140 | |
141 | 141 | return $this->endpoint; |
142 | 142 | |
@@ -148,34 +148,34 @@ discard block |
||
148 | 148 | * @param WPInv_Invoice $invoice Invoice object. |
149 | 149 | * @return array |
150 | 150 | */ |
151 | - protected function get_worldpay_args( $invoice ) { |
|
151 | + protected function get_worldpay_args($invoice) { |
|
152 | 152 | |
153 | 153 | return apply_filters( |
154 | 154 | 'getpaid_worldpay_args', |
155 | 155 | array( |
156 | - 'amount' => wpinv_sanitize_amount( $invoice->get_total() ), // mandatory |
|
157 | - 'cartId' => wpinv_clean( $invoice->get_number() ), // mandatory reference for the item purchased |
|
158 | - 'currency' => wpinv_clean( $invoice->get_currency() ), // mandatory |
|
159 | - 'instId' => wpinv_clean( $this->get_option( 'instId', '' ) ), // mandatory |
|
160 | - 'testMode' => $this->is_sandbox( $invoice ) ? 100 : 0, // mandatory |
|
161 | - 'name' => wpinv_clean( $invoice->get_full_name() ), |
|
162 | - 'address' => wpinv_clean( $invoice->get_address() ), |
|
163 | - 'postcode' => wpinv_clean( $invoice->get_zip() ), |
|
164 | - 'tel' => wpinv_clean( $invoice->get_phone() ), |
|
165 | - 'email' => sanitize_email( $invoice->get_email() ), |
|
166 | - 'country' => wpinv_clean( $invoice->get_country() ), |
|
167 | - 'desc' => sprintf( __( 'Payment for invoice %s.', 'invoicing' ), wpinv_clean( $invoice->get_number() ) ), |
|
168 | - 'MC_description' => sprintf( __( 'Payment for invoice %s.', 'invoicing' ), wpinv_clean( $invoice->get_number() ) ), |
|
169 | - 'MC_callback' => esc_url_raw( $this->notify_url ), |
|
170 | - 'resultfile' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
171 | - 'MC_key' => wpinv_clean( $invoice->get_key() ), |
|
156 | + 'amount' => wpinv_sanitize_amount($invoice->get_total()), // mandatory |
|
157 | + 'cartId' => wpinv_clean($invoice->get_number()), // mandatory reference for the item purchased |
|
158 | + 'currency' => wpinv_clean($invoice->get_currency()), // mandatory |
|
159 | + 'instId' => wpinv_clean($this->get_option('instId', '')), // mandatory |
|
160 | + 'testMode' => $this->is_sandbox($invoice) ? 100 : 0, // mandatory |
|
161 | + 'name' => wpinv_clean($invoice->get_full_name()), |
|
162 | + 'address' => wpinv_clean($invoice->get_address()), |
|
163 | + 'postcode' => wpinv_clean($invoice->get_zip()), |
|
164 | + 'tel' => wpinv_clean($invoice->get_phone()), |
|
165 | + 'email' => sanitize_email($invoice->get_email()), |
|
166 | + 'country' => wpinv_clean($invoice->get_country()), |
|
167 | + 'desc' => sprintf(__('Payment for invoice %s.', 'invoicing'), wpinv_clean($invoice->get_number())), |
|
168 | + 'MC_description' => sprintf(__('Payment for invoice %s.', 'invoicing'), wpinv_clean($invoice->get_number())), |
|
169 | + 'MC_callback' => esc_url_raw($this->notify_url), |
|
170 | + 'resultfile' => esc_url_raw($this->get_return_url($invoice)), |
|
171 | + 'MC_key' => wpinv_clean($invoice->get_key()), |
|
172 | 172 | 'MC_invoice_id' => $invoice->get_id(), |
173 | - 'address1' => wpinv_clean( $invoice->get_address() ), |
|
174 | - 'town' => wpinv_clean( $invoice->get_city() ), |
|
175 | - 'region' => wpinv_clean( $invoice->get_state() ), |
|
176 | - 'amountString' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ), |
|
177 | - 'countryString' => wpinv_clean( wpinv_country_name( $invoice->get_country() ) ), |
|
178 | - 'compName' => wpinv_clean( $invoice->get_company() ), |
|
173 | + 'address1' => wpinv_clean($invoice->get_address()), |
|
174 | + 'town' => wpinv_clean($invoice->get_city()), |
|
175 | + 'region' => wpinv_clean($invoice->get_state()), |
|
176 | + 'amountString' => wpinv_price($invoice->get_total(), $invoice->get_currency()), |
|
177 | + 'countryString' => wpinv_clean(wpinv_country_name($invoice->get_country())), |
|
178 | + 'compName' => wpinv_clean($invoice->get_company()), |
|
179 | 179 | ), |
180 | 180 | $invoice |
181 | 181 | ); |
@@ -188,17 +188,17 @@ discard block |
||
188 | 188 | * @param array $args Gateway args. |
189 | 189 | * @return array |
190 | 190 | */ |
191 | - public function hash_args( $args ) { |
|
191 | + public function hash_args($args) { |
|
192 | 192 | |
193 | - $md5_secret = $this->get_option( 'md5_secret' ); |
|
193 | + $md5_secret = $this->get_option('md5_secret'); |
|
194 | 194 | |
195 | 195 | // Abort if there is no secret. |
196 | - if ( empty( $md5_secret ) ) { |
|
196 | + if (empty($md5_secret)) { |
|
197 | 197 | return $args; |
198 | 198 | } |
199 | 199 | |
200 | 200 | // Hash the args. |
201 | - $args['signature'] = md5( "$md5_secret:{$args['instId']}:{$args['amount']}:{$args['currency']}:{$args['cartId']}" ); |
|
201 | + $args['signature'] = md5("$md5_secret:{$args['instId']}:{$args['amount']}:{$args['currency']}:{$args['cartId']}"); |
|
202 | 202 | |
203 | 203 | return $args; |
204 | 204 | } |
@@ -211,43 +211,43 @@ discard block |
||
211 | 211 | public function verify_ipn() { |
212 | 212 | |
213 | 213 | // Validate the IPN. |
214 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
215 | - wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
214 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
215 | + wp_die('Worldpay IPN Request Failure', 'Worldpay IPN', array('response' => 500)); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | // Process the IPN. |
219 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
220 | - $invoice = wpinv_get_invoice( $posted['MC_invoice_id'] ); |
|
219 | + $posted = wp_kses_post_deep(wp_unslash($_POST)); |
|
220 | + $invoice = wpinv_get_invoice($posted['MC_invoice_id']); |
|
221 | 221 | |
222 | - if ( $invoice && $this->id == $invoice->get_gateway() ) { |
|
222 | + if ($invoice && $this->id == $invoice->get_gateway()) { |
|
223 | 223 | |
224 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
225 | - wpinv_error_log( 'Payment status:' . $posted['transStatus'] ); |
|
224 | + wpinv_error_log('Found invoice #' . $invoice->get_number()); |
|
225 | + wpinv_error_log('Payment status:' . $posted['transStatus']); |
|
226 | 226 | |
227 | 227 | // Update the transaction id. |
228 | - if ( ! empty( $posted['transId'] ) ) { |
|
229 | - $invoice->set_transaction_id( wpinv_clean( $posted['transId'] ) ); |
|
228 | + if (!empty($posted['transId'])) { |
|
229 | + $invoice->set_transaction_id(wpinv_clean($posted['transId'])); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | // Update the ip address. |
233 | - if ( ! empty( $posted['ipAddress'] ) ) { |
|
234 | - $invoice->set_ip( wpinv_clean( $posted['ipAddress'] ) ); |
|
233 | + if (!empty($posted['ipAddress'])) { |
|
234 | + $invoice->set_ip(wpinv_clean($posted['ipAddress'])); |
|
235 | 235 | } |
236 | 236 | |
237 | - if ( $posted['transStatus'] == 'Y' ) { |
|
238 | - $invoice->set_completed_date( date( 'Y-m-d H:i:s', $posted['transTime'] ) ); |
|
237 | + if ($posted['transStatus'] == 'Y') { |
|
238 | + $invoice->set_completed_date(date('Y-m-d H:i:s', $posted['transTime'])); |
|
239 | 239 | $invoice->mark_paid(); |
240 | 240 | return; |
241 | 241 | } |
242 | 242 | |
243 | - if ( $posted['transStatus'] == 'C' ) { |
|
244 | - $invoice->set_status( 'wpi-failed' ); |
|
245 | - $invoice->add_note( __( 'Payment transaction failed while processing Worldpay payment.', 'invoicing' ), false, false, true ); |
|
243 | + if ($posted['transStatus'] == 'C') { |
|
244 | + $invoice->set_status('wpi-failed'); |
|
245 | + $invoice->add_note(__('Payment transaction failed while processing Worldpay payment.', 'invoicing'), false, false, true); |
|
246 | 246 | $invoice->save(); |
247 | 247 | return; |
248 | 248 | } |
249 | 249 | |
250 | - wpinv_error_log( 'Aborting, Invalid transaction status:' . $posted['transStatus'] ); |
|
250 | + wpinv_error_log('Aborting, Invalid transaction status:' . $posted['transStatus']); |
|
251 | 251 | $invoice->save(); |
252 | 252 | |
253 | 253 | } |
@@ -261,27 +261,27 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public function validate_ipn() { |
263 | 263 | |
264 | - wpinv_error_log( 'Validating Worldpay IPN response' ); |
|
264 | + wpinv_error_log('Validating Worldpay IPN response'); |
|
265 | 265 | |
266 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
266 | + $data = wp_kses_post_deep(wp_unslash($_POST)); |
|
267 | 267 | |
268 | 268 | // Verify installation. |
269 | - if ( empty( $data['instId'] ) || $data['instId'] != wpinv_clean( $this->get_option( 'instId', '' ) ) ) { |
|
270 | - wpinv_error_log( 'Received invalid installation ID from Worldpay IPN' ); |
|
269 | + if (empty($data['instId']) || $data['instId'] != wpinv_clean($this->get_option('instId', ''))) { |
|
270 | + wpinv_error_log('Received invalid installation ID from Worldpay IPN'); |
|
271 | 271 | return false; |
272 | 272 | } |
273 | 273 | |
274 | 274 | // Verify invoice. |
275 | - if ( empty( $data['cartId'] ) || ! wpinv_get_id_by_invoice_number( $data['cartId'] ) ) { |
|
276 | - wpinv_error_log( 'Received invalid invoice number from Worldpay IPN' ); |
|
275 | + if (empty($data['cartId']) || !wpinv_get_id_by_invoice_number($data['cartId'])) { |
|
276 | + wpinv_error_log('Received invalid invoice number from Worldpay IPN'); |
|
277 | 277 | return false; |
278 | 278 | } |
279 | 279 | |
280 | 280 | // (maybe) verify password. |
281 | - $password = $this->get_option( 'callback_password' ); |
|
281 | + $password = $this->get_option('callback_password'); |
|
282 | 282 | |
283 | - if ( ! empty( $password ) && ( empty( $data['callbackPW'] ) || $password != $data['callbackPW'] ) ) { |
|
284 | - wpinv_error_log( 'Received invalid invoice number from Worldpay IPN' ); |
|
283 | + if (!empty($password) && (empty($data['callbackPW']) || $password != $data['callbackPW'])) { |
|
284 | + wpinv_error_log('Received invalid invoice number from Worldpay IPN'); |
|
285 | 285 | return false; |
286 | 286 | } |
287 | 287 | |
@@ -292,10 +292,10 @@ discard block |
||
292 | 292 | /** |
293 | 293 | * Displays a notice on the checkout page if sandbox is enabled. |
294 | 294 | */ |
295 | - public function sandbox_notice( $description, $gateway ) { |
|
296 | - if ( 'worldpay' == $gateway && wpinv_is_test_mode( 'worldpay' ) ) { |
|
295 | + public function sandbox_notice($description, $gateway) { |
|
296 | + if ('worldpay' == $gateway && wpinv_is_test_mode('worldpay')) { |
|
297 | 297 | $description .= '<br>' . sprintf( |
298 | - __( 'SANDBOX ENABLED. See the %sWorldpay Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
298 | + __('SANDBOX ENABLED. See the %sWorldpay Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
299 | 299 | '<a href="https://developer.worldpay.com/docs/wpg/directintegration/abouttesting">', |
300 | 300 | '</a>' |
301 | 301 | ); |
@@ -309,43 +309,43 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @param array $admin_settings |
311 | 311 | */ |
312 | - public function admin_settings( $admin_settings ) { |
|
312 | + public function admin_settings($admin_settings) { |
|
313 | 313 | |
314 | 314 | $currencies = sprintf( |
315 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
316 | - implode( ', ', $this->currencies ) |
|
315 | + __('Supported Currencies: %s', 'invoicing'), |
|
316 | + implode(', ', $this->currencies) |
|
317 | 317 | ); |
318 | 318 | |
319 | 319 | $admin_settings['worldpay_active']['desc'] = $admin_settings['worldpay_active']['desc'] . " ($currencies)"; |
320 | - $admin_settings['worldpay_desc']['std'] = __( 'Pay securely via Worldpay using your PayPal account, credit or debit card.', 'invoicing' ); |
|
320 | + $admin_settings['worldpay_desc']['std'] = __('Pay securely via Worldpay using your PayPal account, credit or debit card.', 'invoicing'); |
|
321 | 321 | |
322 | 322 | $admin_settings['worldpay_instId'] = array( |
323 | 323 | 'type' => 'text', |
324 | 324 | 'id' => 'worldpay_instId', |
325 | - 'name' => __( 'Installation Id', 'invoicing' ), |
|
326 | - 'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ), |
|
325 | + 'name' => __('Installation Id', 'invoicing'), |
|
326 | + 'desc' => __('Your installation id. Ex: 211616', 'invoicing'), |
|
327 | 327 | ); |
328 | 328 | |
329 | 329 | $admin_settings['worldpay_md5_secret'] = array( |
330 | 330 | 'type' => 'text', |
331 | 331 | 'id' => 'worldpay_md5_secret', |
332 | - 'name' => __( 'MD5 secret', 'invoicing' ), |
|
333 | - 'desc' => __( 'Optionally enter your MD5 secret here. Next, open your installation settings and ensure that your SignatureFields parameter is set to ', 'invoicing' ) . '<code>instId:amount:currency:cartId</code>', |
|
332 | + 'name' => __('MD5 secret', 'invoicing'), |
|
333 | + 'desc' => __('Optionally enter your MD5 secret here. Next, open your installation settings and ensure that your SignatureFields parameter is set to ', 'invoicing') . '<code>instId:amount:currency:cartId</code>', |
|
334 | 334 | ); |
335 | 335 | |
336 | 336 | $admin_settings['worldpay_callbackPW'] = array( |
337 | 337 | 'type' => 'text', |
338 | 338 | 'id' => 'worldpay_callbackPW', |
339 | - 'name' => __( 'Payment Response password', 'invoicing' ), |
|
340 | - 'desc' => __( 'Recommended. Enter your WorldPay response password to validate payment notifications.', 'invoicing' ), |
|
339 | + 'name' => __('Payment Response password', 'invoicing'), |
|
340 | + 'desc' => __('Recommended. Enter your WorldPay response password to validate payment notifications.', 'invoicing'), |
|
341 | 341 | ); |
342 | 342 | |
343 | 343 | $admin_settings['worldpay_ipn_url'] = array( |
344 | 344 | 'type' => 'ipn_url', |
345 | 345 | 'id' => 'worldpay_ipn_url', |
346 | - 'name' => __( 'Payment Response URL', 'invoicing' ), |
|
346 | + 'name' => __('Payment Response URL', 'invoicing'), |
|
347 | 347 | 'std' => $this->notify_url, |
348 | - 'desc' => __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and enter the above URL.', 'invoicing' ), |
|
348 | + 'desc' => __('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and enter the above URL.', 'invoicing'), |
|
349 | 349 | 'custom' => 'worldpay', |
350 | 350 | 'readonly' => true |
351 | 351 | ); |
@@ -15,31 +15,31 @@ discard block |
||
15 | 15 | abstract class GetPaid_Authorize_Net_Legacy_Gateway extends GetPaid_Payment_Gateway { |
16 | 16 | |
17 | 17 | /** |
18 | - * Class constructor. |
|
19 | - */ |
|
20 | - public function __construct() { |
|
18 | + * Class constructor. |
|
19 | + */ |
|
20 | + public function __construct() { |
|
21 | 21 | parent::__construct(); |
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | - * Returns the API URL. |
|
26 | - * |
|
27 | - * |
|
28 | - * @param WPInv_Invoice $invoice Invoice. |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public function get_api_url( $invoice ) { |
|
25 | + * Returns the API URL. |
|
26 | + * |
|
27 | + * |
|
28 | + * @param WPInv_Invoice $invoice Invoice. |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function get_api_url( $invoice ) { |
|
32 | 32 | return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | - * Communicates with authorize.net |
|
37 | - * |
|
38 | - * |
|
39 | - * @param array $post Data to post. |
|
36 | + * Communicates with authorize.net |
|
37 | + * |
|
38 | + * |
|
39 | + * @param array $post Data to post. |
|
40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
41 | - * @return stdClass|WP_Error |
|
42 | - */ |
|
41 | + * @return stdClass|WP_Error |
|
42 | + */ |
|
43 | 43 | public function post( $post, $invoice ){ |
44 | 44 | |
45 | 45 | $url = $this->get_api_url( $invoice ); |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
92 | - * Returns the API authentication params. |
|
93 | - * |
|
94 | - * |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - public function get_auth_params() { |
|
92 | + * Returns the API authentication params. |
|
93 | + * |
|
94 | + * |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + public function get_auth_params() { |
|
98 | 98 | |
99 | 99 | return array( |
100 | 100 | 'name' => $this->get_option( 'login_id' ), |
@@ -104,13 +104,13 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | - * Cancels a subscription remotely |
|
108 | - * |
|
109 | - * |
|
110 | - * @param WPInv_Subscription $subscription Subscription. |
|
107 | + * Cancels a subscription remotely |
|
108 | + * |
|
109 | + * |
|
110 | + * @param WPInv_Subscription $subscription Subscription. |
|
111 | 111 | * @param WPInv_Invoice $invoice Invoice. |
112 | - */ |
|
113 | - public function cancel_subscription( $subscription, $invoice ) { |
|
112 | + */ |
|
113 | + public function cancel_subscription( $subscription, $invoice ) { |
|
114 | 114 | |
115 | 115 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
116 | 116 | $this->post( |
@@ -126,17 +126,17 @@ discard block |
||
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
129 | - * Processes ipns. |
|
130 | - * |
|
131 | - * @return void |
|
132 | - */ |
|
133 | - public function verify_ipn() { |
|
129 | + * Processes ipns. |
|
130 | + * |
|
131 | + * @return void |
|
132 | + */ |
|
133 | + public function verify_ipn() { |
|
134 | 134 | |
135 | 135 | $this->maybe_process_old_ipn(); |
136 | 136 | |
137 | 137 | // Validate the IPN. |
138 | 138 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
139 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
139 | + wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | // Event type. |
@@ -175,24 +175,24 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
178 | - * Validates IPN invoices. |
|
179 | - * |
|
178 | + * Validates IPN invoices. |
|
179 | + * |
|
180 | 180 | * @param WPInv_Invoice $invoice |
181 | 181 | * @param object $payload |
182 | - * @return void |
|
183 | - */ |
|
184 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
182 | + * @return void |
|
183 | + */ |
|
184 | + public function validate_ipn_invoice( $invoice, $payload ) { |
|
185 | 185 | if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
186 | 186 | exit; |
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | - * Process subscriptio IPNS. |
|
192 | - * |
|
193 | - * @return void |
|
194 | - */ |
|
195 | - public function maybe_process_old_ipn() { |
|
191 | + * Process subscriptio IPNS. |
|
192 | + * |
|
193 | + * @return void |
|
194 | + */ |
|
195 | + public function maybe_process_old_ipn() { |
|
196 | 196 | |
197 | 197 | $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
198 | 198 | |
@@ -234,11 +234,11 @@ discard block |
||
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
237 | - * Validates the old IPN signature. |
|
237 | + * Validates the old IPN signature. |
|
238 | 238 | * |
239 | 239 | * @param array $posted |
240 | - */ |
|
241 | - public function validate_old_ipn_signature( $posted ) { |
|
240 | + */ |
|
241 | + public function validate_old_ipn_signature( $posted ) { |
|
242 | 242 | |
243 | 243 | $signature = $this->get_option( 'signature_key' ); |
244 | 244 | if ( ! empty( $signature ) ) { |
@@ -257,9 +257,9 @@ discard block |
||
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
260 | - * Check Authorize.NET IPN validity. |
|
261 | - */ |
|
262 | - public function validate_ipn() { |
|
260 | + * Check Authorize.NET IPN validity. |
|
261 | + */ |
|
262 | + public function validate_ipn() { |
|
263 | 263 | |
264 | 264 | wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
265 | 265 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Authorize.net Legacy Payment Gateway class. |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | * @param WPInv_Invoice $invoice Invoice. |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - public function get_api_url( $invoice ) { |
|
32 | - return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
31 | + public function get_api_url($invoice) { |
|
32 | + return $this->is_sandbox($invoice) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -40,48 +40,48 @@ discard block |
||
40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
41 | 41 | * @return stdClass|WP_Error |
42 | 42 | */ |
43 | - public function post( $post, $invoice ){ |
|
43 | + public function post($post, $invoice) { |
|
44 | 44 | |
45 | - $url = $this->get_api_url( $invoice ); |
|
45 | + $url = $this->get_api_url($invoice); |
|
46 | 46 | $response = wp_remote_post( |
47 | 47 | $url, |
48 | 48 | array( |
49 | 49 | 'headers' => array( |
50 | 50 | 'Content-Type' => 'application/json; charset=utf-8' |
51 | 51 | ), |
52 | - 'body' => json_encode( $post ), |
|
52 | + 'body' => json_encode($post), |
|
53 | 53 | 'method' => 'POST' |
54 | 54 | ) |
55 | 55 | ); |
56 | 56 | |
57 | - if ( is_wp_error( $response ) ) { |
|
57 | + if (is_wp_error($response)) { |
|
58 | 58 | return $response; |
59 | 59 | } |
60 | 60 | |
61 | - $response = wp_unslash( wp_remote_retrieve_body( $response ) ); |
|
61 | + $response = wp_unslash(wp_remote_retrieve_body($response)); |
|
62 | 62 | $response = preg_replace('/\xEF\xBB\xBF/', '', $response); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851 |
63 | - $response = json_decode( $response ); |
|
63 | + $response = json_decode($response); |
|
64 | 64 | |
65 | - if ( empty( $response ) ) { |
|
66 | - return new WP_Error( 'invalid_reponse', __( 'Invalid gateway response', 'invoicing' ) ); |
|
65 | + if (empty($response)) { |
|
66 | + return new WP_Error('invalid_reponse', __('Invalid gateway response', 'invoicing')); |
|
67 | 67 | } |
68 | 68 | |
69 | - if ( $response->messages->resultCode == 'Error' ) { |
|
69 | + if ($response->messages->resultCode == 'Error') { |
|
70 | 70 | |
71 | - if ( $this->is_sandbox( $invoice ) ) { |
|
72 | - wpinv_error_log( $response ); |
|
71 | + if ($this->is_sandbox($invoice)) { |
|
72 | + wpinv_error_log($response); |
|
73 | 73 | } |
74 | 74 | |
75 | - if ( $response->messages->message[0]->code == 'E00039' && ! empty( $response->customerProfileId ) && ! empty( $response->customerPaymentProfileId ) ) { |
|
76 | - return new WP_Error( 'dup_payment_profile', $response->customerProfileId . '.' . $response->customerPaymentProfileId ); |
|
75 | + if ($response->messages->message[0]->code == 'E00039' && !empty($response->customerProfileId) && !empty($response->customerPaymentProfileId)) { |
|
76 | + return new WP_Error('dup_payment_profile', $response->customerProfileId . '.' . $response->customerPaymentProfileId); |
|
77 | 77 | } |
78 | 78 | |
79 | - if ( ! empty( $response->transactionResponse ) && ! empty( $response->transactionResponse->errors ) ) { |
|
79 | + if (!empty($response->transactionResponse) && !empty($response->transactionResponse->errors)) { |
|
80 | 80 | $error = $response->transactionResponse->errors[0]; |
81 | - return new WP_Error( $error->errorCode, $error->errorText ); |
|
81 | + return new WP_Error($error->errorCode, $error->errorText); |
|
82 | 82 | } |
83 | 83 | |
84 | - return new WP_Error( $response->messages->message[0]->code, $response->messages->message[0]->text ); |
|
84 | + return new WP_Error($response->messages->message[0]->code, $response->messages->message[0]->text); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | return $response; |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | public function get_auth_params() { |
98 | 98 | |
99 | 99 | return array( |
100 | - 'name' => $this->get_option( 'login_id' ), |
|
101 | - 'transactionKey' => $this->get_option( 'transaction_key' ), |
|
100 | + 'name' => $this->get_option('login_id'), |
|
101 | + 'transactionKey' => $this->get_option('transaction_key'), |
|
102 | 102 | ); |
103 | 103 | |
104 | 104 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @param WPInv_Subscription $subscription Subscription. |
111 | 111 | * @param WPInv_Invoice $invoice Invoice. |
112 | 112 | */ |
113 | - public function cancel_subscription( $subscription, $invoice ) { |
|
113 | + public function cancel_subscription($subscription, $invoice) { |
|
114 | 114 | |
115 | 115 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
116 | 116 | $this->post( |
@@ -135,38 +135,38 @@ discard block |
||
135 | 135 | $this->maybe_process_old_ipn(); |
136 | 136 | |
137 | 137 | // Validate the IPN. |
138 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
139 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
138 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
139 | + wp_die('Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array('response' => 500)); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | // Event type. |
143 | - $posted = json_decode( file_get_contents( 'php://input' ) ); |
|
144 | - if ( empty( $posted ) ) { |
|
145 | - wp_die( 'Invalid JSON', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
143 | + $posted = json_decode(file_get_contents('php://input')); |
|
144 | + if (empty($posted)) { |
|
145 | + wp_die('Invalid JSON', 'Authorize.NET IPN', array('response' => 500)); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | // Process the IPN. |
149 | - $posted = (object) wp_unslash( $posted ); |
|
149 | + $posted = (object) wp_unslash($posted); |
|
150 | 150 | |
151 | 151 | // Process refunds. |
152 | - if ( 'net.authorize.payment.refund.created' == $posted->eventType ) { |
|
153 | - $invoice = new WPInv_Invoice( $posted->payload->merchantReferenceId ); |
|
154 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
152 | + if ('net.authorize.payment.refund.created' == $posted->eventType) { |
|
153 | + $invoice = new WPInv_Invoice($posted->payload->merchantReferenceId); |
|
154 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
155 | 155 | $invoice->refund(); |
156 | 156 | } |
157 | 157 | |
158 | 158 | // Held funds approved. |
159 | - if ( 'net.authorize.payment.fraud.approved' == $posted->eventType ) { |
|
160 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
161 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
162 | - $invoice->mark_paid( false, __( 'Payment released', 'invoicing' ) ); |
|
159 | + if ('net.authorize.payment.fraud.approved' == $posted->eventType) { |
|
160 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
161 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
162 | + $invoice->mark_paid(false, __('Payment released', 'invoicing')); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | // Held funds declined. |
166 | - if ( 'net.authorize.payment.fraud.declined' == $posted->eventType ) { |
|
167 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
168 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
169 | - $invoice->set_status( 'wpi-failed', __( 'Payment declined', 'invoicing' ) ); |
|
166 | + if ('net.authorize.payment.fraud.declined' == $posted->eventType) { |
|
167 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
168 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
169 | + $invoice->set_status('wpi-failed', __('Payment declined', 'invoicing')); |
|
170 | 170 | $invoice->save(); |
171 | 171 | } |
172 | 172 | |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | * @param object $payload |
182 | 182 | * @return void |
183 | 183 | */ |
184 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
185 | - if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
|
184 | + public function validate_ipn_invoice($invoice, $payload) { |
|
185 | + if (!$invoice->exists() || $payload->id != $invoice->get_transaction_id()) { |
|
186 | 186 | exit; |
187 | 187 | } |
188 | 188 | } |
@@ -194,32 +194,32 @@ discard block |
||
194 | 194 | */ |
195 | 195 | public function maybe_process_old_ipn() { |
196 | 196 | |
197 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
197 | + $data = wp_kses_post_deep(wp_unslash($_POST)); |
|
198 | 198 | |
199 | 199 | // Only process subscriptions subscriptions. |
200 | - if ( empty( $data['x_subscription_id'] ) ) { |
|
200 | + if (empty($data['x_subscription_id'])) { |
|
201 | 201 | return; |
202 | 202 | } |
203 | 203 | |
204 | 204 | // Check validity. |
205 | - $this->validate_old_ipn_signature( $data ); |
|
205 | + $this->validate_old_ipn_signature($data); |
|
206 | 206 | |
207 | 207 | // Fetch the associated subscription. |
208 | - $subscription_id = WPInv_Subscription::get_subscription_id_by_field( $data['x_subscription_id'] ); |
|
209 | - $subscription = new WPInv_Subscription( $subscription_id ); |
|
208 | + $subscription_id = WPInv_Subscription::get_subscription_id_by_field($data['x_subscription_id']); |
|
209 | + $subscription = new WPInv_Subscription($subscription_id); |
|
210 | 210 | |
211 | 211 | // Abort if it is missing or completed. |
212 | - if ( ! $subscription->get_id() || $subscription->has_status( 'completed' ) ) { |
|
212 | + if (!$subscription->get_id() || $subscription->has_status('completed')) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | 216 | // Payment status. |
217 | - if ( 1 == $data['x_response_code'] ) { |
|
217 | + if (1 == $data['x_response_code']) { |
|
218 | 218 | |
219 | 219 | // Renew the subscription. |
220 | 220 | $subscription->add_payment( |
221 | 221 | array( |
222 | - 'transaction_id' => sanitize_text_field( $data['x_trans_id'] ), |
|
222 | + 'transaction_id' => sanitize_text_field($data['x_trans_id']), |
|
223 | 223 | 'gateway' => $this->id |
224 | 224 | ) |
225 | 225 | ); |
@@ -238,17 +238,17 @@ discard block |
||
238 | 238 | * |
239 | 239 | * @param array $posted |
240 | 240 | */ |
241 | - public function validate_old_ipn_signature( $posted ) { |
|
241 | + public function validate_old_ipn_signature($posted) { |
|
242 | 242 | |
243 | - $signature = $this->get_option( 'signature_key' ); |
|
244 | - if ( ! empty( $signature ) ) { |
|
245 | - $login_id = $this->get_option( 'login_id' ); |
|
246 | - $trans_id = wpinv_clean( $_POST['x_trans_id'] ); |
|
247 | - $amount = wpinv_clean( $_POST['x_amount'] ); |
|
248 | - $hash = hash_hmac ( 'sha512', "^$login_id^$trans_id^$amount^", hex2bin( $signature ) ); |
|
243 | + $signature = $this->get_option('signature_key'); |
|
244 | + if (!empty($signature)) { |
|
245 | + $login_id = $this->get_option('login_id'); |
|
246 | + $trans_id = wpinv_clean($_POST['x_trans_id']); |
|
247 | + $amount = wpinv_clean($_POST['x_amount']); |
|
248 | + $hash = hash_hmac('sha512', "^$login_id^$trans_id^$amount^", hex2bin($signature)); |
|
249 | 249 | |
250 | - if ( ! hash_equals( $hash, $posted['x_SHA2_Hash'] ) ) { |
|
251 | - wpinv_error_log( $posted['x_SHA2_Hash'], "Invalid signature. Expected $hash" ); |
|
250 | + if (!hash_equals($hash, $posted['x_SHA2_Hash'])) { |
|
251 | + wpinv_error_log($posted['x_SHA2_Hash'], "Invalid signature. Expected $hash"); |
|
252 | 252 | exit; |
253 | 253 | } |
254 | 254 | |
@@ -261,28 +261,28 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public function validate_ipn() { |
263 | 263 | |
264 | - wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
|
264 | + wpinv_error_log('Validating Authorize.NET IPN response'); |
|
265 | 265 | |
266 | - if ( empty( $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
266 | + if (empty($_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
267 | 267 | return false; |
268 | 268 | } |
269 | 269 | |
270 | - $signature = $this->get_option( 'signature_key' ); |
|
270 | + $signature = $this->get_option('signature_key'); |
|
271 | 271 | |
272 | - if ( empty( $signature ) ) { |
|
273 | - wpinv_error_log( 'Error: You have not set a signature key' ); |
|
272 | + if (empty($signature)) { |
|
273 | + wpinv_error_log('Error: You have not set a signature key'); |
|
274 | 274 | return false; |
275 | 275 | } |
276 | 276 | |
277 | - $hash = hash_hmac ( 'sha512', file_get_contents( 'php://input' ), hex2bin( $signature ) ); |
|
277 | + $hash = hash_hmac('sha512', file_get_contents('php://input'), hex2bin($signature)); |
|
278 | 278 | |
279 | - if ( hash_equals( $hash, $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
280 | - wpinv_error_log( 'Successfully validated the IPN' ); |
|
279 | + if (hash_equals($hash, $_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
280 | + wpinv_error_log('Successfully validated the IPN'); |
|
281 | 281 | return true; |
282 | 282 | } |
283 | 283 | |
284 | - wpinv_error_log( 'IPN hash is not valid' ); |
|
285 | - wpinv_error_log( $_SERVER['HTTP_X_ANET_SIGNATURE'] ); |
|
284 | + wpinv_error_log('IPN hash is not valid'); |
|
285 | + wpinv_error_log($_SERVER['HTTP_X_ANET_SIGNATURE']); |
|
286 | 286 | return false; |
287 | 287 | |
288 | 288 | } |