@@ -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_Item_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 item. |
@@ -114,23 +114,23 @@ discard block |
||
114 | 114 | // Dynamic pricing. |
115 | 115 | if ( $item->supports_dynamic_pricing() ) { |
116 | 116 | |
117 | - do_action( 'wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item ); |
|
117 | + do_action( 'wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item ); |
|
118 | 118 | |
119 | - // NYP toggle. |
|
120 | - aui()->input( |
|
119 | + // NYP toggle. |
|
120 | + aui()->input( |
|
121 | 121 | array( |
122 | - 'id' => 'wpinv_name_your_price', |
|
123 | - 'name' => 'wpinv_name_your_price', |
|
124 | - 'type' => 'checkbox', |
|
125 | - 'label' => apply_filters( 'wpinv_name_your_price_toggle_text', __( 'Let customers name their price', 'invoicing' ) ), |
|
126 | - 'value' => '1', |
|
127 | - 'checked' => $item->user_can_set_their_price(), |
|
128 | - 'no_wrap' => true, |
|
122 | + 'id' => 'wpinv_name_your_price', |
|
123 | + 'name' => 'wpinv_name_your_price', |
|
124 | + 'type' => 'checkbox', |
|
125 | + 'label' => apply_filters( 'wpinv_name_your_price_toggle_text', __( 'Let customers name their price', 'invoicing' ) ), |
|
126 | + 'value' => '1', |
|
127 | + 'checked' => $item->user_can_set_their_price(), |
|
128 | + 'no_wrap' => true, |
|
129 | 129 | ), |
130 | 130 | true |
131 | 131 | ); |
132 | 132 | |
133 | - do_action( 'wpinv_item_details_metabox_dynamic_pricing_checkbox', $item ); |
|
133 | + do_action( 'wpinv_item_details_metabox_dynamic_pricing_checkbox', $item ); |
|
134 | 134 | |
135 | 135 | } |
136 | 136 | |
@@ -274,35 +274,35 @@ discard block |
||
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
277 | - * Save meta box data. |
|
278 | - * |
|
279 | - * @param int $post_id |
|
280 | - */ |
|
281 | - public static function save( $post_id ) { |
|
277 | + * Save meta box data. |
|
278 | + * |
|
279 | + * @param int $post_id |
|
280 | + */ |
|
281 | + public static function save( $post_id ) { |
|
282 | 282 | |
283 | 283 | // Prepare the item. |
284 | 284 | $item = new WPInv_Item( $post_id ); |
285 | 285 | |
286 | 286 | // Load new data. |
287 | 287 | $item->set_props( |
288 | - array( |
|
289 | - 'price' => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null, |
|
290 | - 'vat_rule' => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null, |
|
291 | - 'vat_class' => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null, |
|
292 | - 'type' => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null, |
|
293 | - 'is_dynamic_pricing' => ! empty( $_POST['wpinv_name_your_price'] ), |
|
288 | + array( |
|
289 | + 'price' => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null, |
|
290 | + 'vat_rule' => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null, |
|
291 | + 'vat_class' => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null, |
|
292 | + 'type' => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null, |
|
293 | + 'is_dynamic_pricing' => ! empty( $_POST['wpinv_name_your_price'] ), |
|
294 | 294 | 'minimum_price' => isset( $_POST['wpinv_minimum_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_minimum_price'] ) : null, |
295 | - 'is_recurring' => ! empty( $_POST['wpinv_is_recurring'] ), |
|
296 | - 'recurring_period' => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null, |
|
297 | - 'recurring_interval' => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1, |
|
298 | - 'recurring_limit' => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null, |
|
299 | - 'is_free_trial' => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null, |
|
300 | - 'trial_period' => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null, |
|
301 | - 'trial_interval' => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null, |
|
302 | - ) |
|
295 | + 'is_recurring' => ! empty( $_POST['wpinv_is_recurring'] ), |
|
296 | + 'recurring_period' => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null, |
|
297 | + 'recurring_interval' => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1, |
|
298 | + 'recurring_limit' => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null, |
|
299 | + 'is_free_trial' => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null, |
|
300 | + 'trial_period' => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null, |
|
301 | + 'trial_interval' => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null, |
|
302 | + ) |
|
303 | 303 | ); |
304 | 304 | |
305 | - $item->save(); |
|
306 | - do_action( 'getpaid_item_metabox_save', $post_id, $item ); |
|
307 | - } |
|
305 | + $item->save(); |
|
306 | + do_action( 'getpaid_item_metabox_save', $post_id, $item ); |
|
307 | + } |
|
308 | 308 | } |
@@ -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,27 +21,27 @@ 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 item. |
27 | - $item = new WPInv_Item( $post ); |
|
27 | + $item = new WPInv_Item($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 | 32 | // Set the currency position. |
33 | 33 | $position = wpinv_currency_position(); |
34 | 34 | |
35 | - if ( $position == 'left_space' ) { |
|
35 | + if ($position == 'left_space') { |
|
36 | 36 | $position = 'left'; |
37 | 37 | } |
38 | 38 | |
39 | - if ( $position == 'right_space' ) { |
|
39 | + if ($position == 'right_space') { |
|
40 | 40 | $position = 'right'; |
41 | 41 | } |
42 | 42 | |
43 | 43 | ?> |
44 | - <input type="hidden" id="_wpi_current_type" value="<?php echo esc_attr( $item->get_type( 'edit' ) ); ?>" /> |
|
44 | + <input type="hidden" id="_wpi_current_type" value="<?php echo esc_attr($item->get_type('edit')); ?>" /> |
|
45 | 45 | <style> |
46 | 46 | #poststuff .input-group-text, |
47 | 47 | #poststuff .form-control { |
@@ -55,21 +55,21 @@ discard block |
||
55 | 55 | </style> |
56 | 56 | <div class='bsui' style='max-width: 600px;padding-top: 10px;'> |
57 | 57 | |
58 | - <?php do_action( 'wpinv_item_details_metabox_before_price', $item ); ?> |
|
58 | + <?php do_action('wpinv_item_details_metabox_before_price', $item); ?> |
|
59 | 59 | <div class="form-group row"> |
60 | - <label class="col-sm-3 col-form-label" for="wpinv_item_price"><span><?php esc_html_e( 'Item Price', 'invoicing' ); ?></span></label> |
|
60 | + <label class="col-sm-3 col-form-label" for="wpinv_item_price"><span><?php esc_html_e('Item Price', 'invoicing'); ?></span></label> |
|
61 | 61 | <div class="col-sm-8"> |
62 | 62 | <div class="row"> |
63 | 63 | <div class="col-sm-4 getpaid-price-input"> |
64 | 64 | <div class="input-group input-group-sm"> |
65 | - <?php if ( 'left' == $position ) : ?> |
|
65 | + <?php if ('left' == $position) : ?> |
|
66 | 66 | <div class="input-group-prepend"> |
67 | 67 | <span class="input-group-text" id="wpinv_item_price_symbol"><?php echo wpinv_currency_symbol(); ?></span> |
68 | 68 | </div> |
69 | 69 | <?php endif; ?> |
70 | - <input type="text" name="wpinv_item_price" id="wpinv_item_price" value="<?php echo esc_attr( getpaid_unstandardize_amount( $item->get_price( 'edit' ) ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control"> |
|
70 | + <input type="text" name="wpinv_item_price" id="wpinv_item_price" value="<?php echo esc_attr(getpaid_unstandardize_amount($item->get_price('edit'))); ?>" placeholder="<?php echo esc_attr(wpinv_sanitize_amount(0)); ?>" class="form-control"> |
|
71 | 71 | |
72 | - <?php if ( 'left' != $position ) : ?> |
|
72 | + <?php if ('left' != $position) : ?> |
|
73 | 73 | <div class="input-group-append"> |
74 | 74 | <span class="input-group-text" id="wpinv_item_price_symbol"><?php echo wpinv_currency_symbol(); ?></span> |
75 | 75 | </div> |
@@ -79,10 +79,10 @@ discard block |
||
79 | 79 | </div> |
80 | 80 | <div class="col-sm-4 wpinv_show_if_recurring"> |
81 | 81 | <?php |
82 | - _e( 'every' ); |
|
82 | + _e('every'); |
|
83 | 83 | echo ' '; |
84 | 84 | ?> |
85 | - <input type="number" style="max-width: 60px;" value="<?php echo esc_attr( $item->get_recurring_interval( 'edit' ) ); ?>" placeholder="1" name="wpinv_recurring_interval" id="wpinv_recurring_interval" /> |
|
85 | + <input type="number" style="max-width: 60px;" value="<?php echo esc_attr($item->get_recurring_interval('edit')); ?>" placeholder="1" name="wpinv_recurring_interval" id="wpinv_recurring_interval" /> |
|
86 | 86 | </div> |
87 | 87 | <div class="col-sm-4 wpinv_show_if_recurring"> |
88 | 88 | <?php |
@@ -90,16 +90,16 @@ discard block |
||
90 | 90 | array( |
91 | 91 | 'id' => 'wpinv_recurring_period', |
92 | 92 | 'name' => 'wpinv_recurring_period', |
93 | - 'label' => __( 'Period', 'invoicing' ), |
|
94 | - 'placeholder' => __( 'Select Period', 'invoicing' ), |
|
95 | - 'value' => $item->get_recurring_period( 'edit' ), |
|
93 | + 'label' => __('Period', 'invoicing'), |
|
94 | + 'placeholder' => __('Select Period', 'invoicing'), |
|
95 | + 'value' => $item->get_recurring_period('edit'), |
|
96 | 96 | 'select2' => true, |
97 | 97 | 'data-allow-clear' => 'false', |
98 | 98 | 'options' => array( |
99 | - 'D' => __( 'day(s)', 'invoicing' ), |
|
100 | - 'W' => __( 'week(s)', 'invoicing' ), |
|
101 | - 'M' => __( 'month(s)', 'invoicing' ), |
|
102 | - 'Y' => __( 'year(s)', 'invoicing' ), |
|
99 | + 'D' => __('day(s)', 'invoicing'), |
|
100 | + 'W' => __('week(s)', 'invoicing'), |
|
101 | + 'M' => __('month(s)', 'invoicing'), |
|
102 | + 'Y' => __('year(s)', 'invoicing'), |
|
103 | 103 | ), |
104 | 104 | ), |
105 | 105 | true |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | <?php |
113 | 113 | |
114 | 114 | // Dynamic pricing. |
115 | - if ( $item->supports_dynamic_pricing() ) { |
|
115 | + if ($item->supports_dynamic_pricing()) { |
|
116 | 116 | |
117 | - do_action( 'wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item ); |
|
117 | + do_action('wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item); |
|
118 | 118 | |
119 | 119 | // NYP toggle. |
120 | 120 | aui()->input( |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | 'id' => 'wpinv_name_your_price', |
123 | 123 | 'name' => 'wpinv_name_your_price', |
124 | 124 | 'type' => 'checkbox', |
125 | - 'label' => apply_filters( 'wpinv_name_your_price_toggle_text', __( 'Let customers name their price', 'invoicing' ) ), |
|
125 | + 'label' => apply_filters('wpinv_name_your_price_toggle_text', __('Let customers name their price', 'invoicing')), |
|
126 | 126 | 'value' => '1', |
127 | 127 | 'checked' => $item->user_can_set_their_price(), |
128 | 128 | 'no_wrap' => true, |
@@ -130,25 +130,25 @@ discard block |
||
130 | 130 | true |
131 | 131 | ); |
132 | 132 | |
133 | - do_action( 'wpinv_item_details_metabox_dynamic_pricing_checkbox', $item ); |
|
133 | + do_action('wpinv_item_details_metabox_dynamic_pricing_checkbox', $item); |
|
134 | 134 | |
135 | 135 | } |
136 | 136 | |
137 | 137 | // Subscriptions. |
138 | - do_action( 'wpinv_item_details_metabox_before_subscription_checkbox', $item ); |
|
138 | + do_action('wpinv_item_details_metabox_before_subscription_checkbox', $item); |
|
139 | 139 | aui()->input( |
140 | 140 | array( |
141 | 141 | 'id' => 'wpinv_is_recurring', |
142 | 142 | 'name' => 'wpinv_is_recurring', |
143 | 143 | 'type' => 'checkbox', |
144 | - 'label' => apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Charge customers a recurring amount for this item', 'invoicing' ) ), |
|
144 | + 'label' => apply_filters('wpinv_is_recurring_toggle_text', __('Charge customers a recurring amount for this item', 'invoicing')), |
|
145 | 145 | 'value' => '1', |
146 | 146 | 'checked' => $item->is_recurring(), |
147 | 147 | 'no_wrap' => true, |
148 | 148 | ), |
149 | 149 | true |
150 | 150 | ); |
151 | - do_action( 'wpinv_item_details_metabox_subscription_checkbox', $item ); |
|
151 | + do_action('wpinv_item_details_metabox_subscription_checkbox', $item); |
|
152 | 152 | |
153 | 153 | ?> |
154 | 154 | <div class="wpinv_show_if_recurring"> |
@@ -158,30 +158,30 @@ discard block |
||
158 | 158 | </div> |
159 | 159 | </div> |
160 | 160 | <div class="col-sm-1 pt-2 pl-0"> |
161 | - <span class="wpi-help-tip dashicons dashicons-editor-help wpinv_show_if_recurring" title="<?php esc_attr_e( 'Set the subscription price, billing interval and period.', 'invoicing' ); ?>"></span> |
|
161 | + <span class="wpi-help-tip dashicons dashicons-editor-help wpinv_show_if_recurring" title="<?php esc_attr_e('Set the subscription price, billing interval and period.', 'invoicing'); ?>"></span> |
|
162 | 162 | </div> |
163 | 163 | </div> |
164 | - <?php do_action( 'wpinv_item_details_metabox_after_price', $item ); ?> |
|
164 | + <?php do_action('wpinv_item_details_metabox_after_price', $item); ?> |
|
165 | 165 | |
166 | - <?php if ( $item->supports_dynamic_pricing() ) : ?> |
|
167 | - <?php do_action( 'wpinv_item_details_metabox_before_minimum_price', $item ); ?> |
|
166 | + <?php if ($item->supports_dynamic_pricing()) : ?> |
|
167 | + <?php do_action('wpinv_item_details_metabox_before_minimum_price', $item); ?> |
|
168 | 168 | <div class="wpinv_show_if_dynamic wpinv_minimum_price"> |
169 | 169 | |
170 | 170 | <div class="form-group row"> |
171 | 171 | <label for="wpinv_minimum_price" class="col-sm-3 col-form-label"> |
172 | - <?php esc_html_e( 'Minimum Price', 'invoicing' ); ?> |
|
172 | + <?php esc_html_e('Minimum Price', 'invoicing'); ?> |
|
173 | 173 | </label> |
174 | 174 | <div class="col-sm-8"> |
175 | 175 | <div class="input-group input-group-sm"> |
176 | - <?php if ( 'left' == $position ) : ?> |
|
176 | + <?php if ('left' == $position) : ?> |
|
177 | 177 | <div class="input-group-prepend"> |
178 | 178 | <span class="input-group-text" id="wpinv_item_minimum_price_symbol"><?php echo wpinv_currency_symbol(); ?></span> |
179 | 179 | </div> |
180 | 180 | <?php endif; ?> |
181 | 181 | |
182 | - <input type="text" name="wpinv_minimum_price" id="wpinv_minimum_price" value="<?php echo esc_attr( getpaid_unstandardize_amount( $item->get_minimum_price( 'edit' ) ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control"> |
|
182 | + <input type="text" name="wpinv_minimum_price" id="wpinv_minimum_price" value="<?php echo esc_attr(getpaid_unstandardize_amount($item->get_minimum_price('edit'))); ?>" placeholder="<?php echo esc_attr(wpinv_sanitize_amount(0)); ?>" class="form-control"> |
|
183 | 183 | |
184 | - <?php if ( 'left' != $position ) : ?> |
|
184 | + <?php if ('left' != $position) : ?> |
|
185 | 185 | <div class="input-group-append"> |
186 | 186 | <span class="input-group-text" id="wpinv_item_minimum_price_symbol"><?php echo wpinv_currency_symbol(); ?></span> |
187 | 187 | </div> |
@@ -190,45 +190,45 @@ discard block |
||
190 | 190 | </div> |
191 | 191 | |
192 | 192 | <div class="col-sm-1 pt-2 pl-0"> |
193 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter the minimum amount that users are allowed to set', 'invoicing' ); ?>"></span> |
|
193 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter the minimum amount that users are allowed to set', 'invoicing'); ?>"></span> |
|
194 | 194 | </div> |
195 | 195 | </div> |
196 | 196 | |
197 | 197 | </div> |
198 | - <?php do_action( 'wpinv_item_details_metabox_minimum_price', $item ); ?> |
|
198 | + <?php do_action('wpinv_item_details_metabox_minimum_price', $item); ?> |
|
199 | 199 | <?php endif; ?> |
200 | 200 | |
201 | - <?php do_action( 'wpinv_item_details_metabox_before_maximum_renewals', $item ); ?> |
|
201 | + <?php do_action('wpinv_item_details_metabox_before_maximum_renewals', $item); ?> |
|
202 | 202 | <div class="wpinv_show_if_recurring wpinv_maximum_renewals"> |
203 | 203 | |
204 | 204 | <div class="form-group row"> |
205 | 205 | <label for="wpinv_recurring_limit" class="col-sm-3 col-form-label"> |
206 | - <?php esc_html_e( 'Maximum Renewals', 'invoicing' ); ?> |
|
206 | + <?php esc_html_e('Maximum Renewals', 'invoicing'); ?> |
|
207 | 207 | </label> |
208 | 208 | <div class="col-sm-8"> |
209 | - <input type="number" value="<?php echo esc_attr( $item->get_recurring_limit( 'edit' ) ); ?>" placeholder="0" name="wpinv_recurring_limit" id="wpinv_recurring_limit" style="width: 100%;" /> |
|
209 | + <input type="number" value="<?php echo esc_attr($item->get_recurring_limit('edit')); ?>" placeholder="0" name="wpinv_recurring_limit" id="wpinv_recurring_limit" style="width: 100%;" /> |
|
210 | 210 | </div> |
211 | 211 | <div class="col-sm-1 pt-2 pl-0"> |
212 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Leave empty if you want the subscription to renew until it is cancelled.', 'invoicing' ); ?>"></span> |
|
212 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Leave empty if you want the subscription to renew until it is cancelled.', 'invoicing'); ?>"></span> |
|
213 | 213 | </div> |
214 | 214 | </div> |
215 | 215 | |
216 | 216 | </div> |
217 | - <?php do_action( 'wpinv_item_details_metabox_maximum_renewals', $item ); ?> |
|
217 | + <?php do_action('wpinv_item_details_metabox_maximum_renewals', $item); ?> |
|
218 | 218 | |
219 | - <?php do_action( 'wpinv_item_details_metabox_before_free_trial', $item ); ?> |
|
219 | + <?php do_action('wpinv_item_details_metabox_before_free_trial', $item); ?> |
|
220 | 220 | <div class="wpinv_show_if_recurring wpinv_free_trial"> |
221 | 221 | |
222 | 222 | <div class="form-group row"> |
223 | - <label class="col-sm-3 col-form-label" for="wpinv_trial_interval"><?php defined( 'GETPAID_PAID_TRIALS_VERSION' ) ? _e( 'Free/Paid Trial', 'invoicing' ) : _e( 'Free Trial', 'invoicing' ); ?></label> |
|
223 | + <label class="col-sm-3 col-form-label" for="wpinv_trial_interval"><?php defined('GETPAID_PAID_TRIALS_VERSION') ? _e('Free/Paid Trial', 'invoicing') : _e('Free Trial', 'invoicing'); ?></label> |
|
224 | 224 | |
225 | 225 | <div class="col-sm-8"> |
226 | 226 | <div class="row"> |
227 | 227 | <div class="col-sm-6"> |
228 | - <?php $value = $item->has_free_trial() ? $item->get_trial_interval( 'edit' ) : 0; ?> |
|
228 | + <?php $value = $item->has_free_trial() ? $item->get_trial_interval('edit') : 0; ?> |
|
229 | 229 | |
230 | 230 | <div> |
231 | - <input type="number" name="wpinv_trial_interval" style="width: 100%;" placeholder="0" id="wpinv_trial_interval" value="<?php echo esc_attr( $value ); ?>" > |
|
231 | + <input type="number" name="wpinv_trial_interval" style="width: 100%;" placeholder="0" id="wpinv_trial_interval" value="<?php echo esc_attr($value); ?>" > |
|
232 | 232 | </div> |
233 | 233 | </div> |
234 | 234 | <div class="col-sm-6"> |
@@ -237,17 +237,17 @@ discard block |
||
237 | 237 | array( |
238 | 238 | 'id' => 'wpinv_trial_period', |
239 | 239 | 'name' => 'wpinv_trial_period', |
240 | - 'label' => __( 'Trial Period', 'invoicing' ), |
|
241 | - 'placeholder' => __( 'Trial Period', 'invoicing' ), |
|
242 | - 'value' => $item->get_trial_period( 'edit' ), |
|
240 | + 'label' => __('Trial Period', 'invoicing'), |
|
241 | + 'placeholder' => __('Trial Period', 'invoicing'), |
|
242 | + 'value' => $item->get_trial_period('edit'), |
|
243 | 243 | 'select2' => true, |
244 | 244 | 'data-allow-clear' => 'false', |
245 | 245 | 'no_wrap' => true, |
246 | 246 | 'options' => array( |
247 | - 'D' => __( 'day(s)', 'invoicing' ), |
|
248 | - 'W' => __( 'week(s)', 'invoicing' ), |
|
249 | - 'M' => __( 'month(s)', 'invoicing' ), |
|
250 | - 'Y' => __( 'year(s)', 'invoicing' ), |
|
247 | + 'D' => __('day(s)', 'invoicing'), |
|
248 | + 'W' => __('week(s)', 'invoicing'), |
|
249 | + 'M' => __('month(s)', 'invoicing'), |
|
250 | + 'Y' => __('year(s)', 'invoicing'), |
|
251 | 251 | ), |
252 | 252 | ), |
253 | 253 | true |
@@ -259,15 +259,15 @@ discard block |
||
259 | 259 | </div> |
260 | 260 | |
261 | 261 | <div class="col-sm-1 pt-2 pl-0"> |
262 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'An optional period of time to wait before charging the first recurring payment.', 'invoicing' ); ?>"></span> |
|
262 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('An optional period of time to wait before charging the first recurring payment.', 'invoicing'); ?>"></span> |
|
263 | 263 | </div> |
264 | 264 | |
265 | 265 | </div> |
266 | 266 | |
267 | 267 | </div> |
268 | - <?php do_action( 'wpinv_item_details_metabox__free_trial', $item ); ?> |
|
268 | + <?php do_action('wpinv_item_details_metabox__free_trial', $item); ?> |
|
269 | 269 | |
270 | - <?php do_action( 'wpinv_item_details_metabox_item_details', $item ); ?> |
|
270 | + <?php do_action('wpinv_item_details_metabox_item_details', $item); ?> |
|
271 | 271 | </div> |
272 | 272 | <?php |
273 | 273 | |
@@ -278,31 +278,31 @@ discard block |
||
278 | 278 | * |
279 | 279 | * @param int $post_id |
280 | 280 | */ |
281 | - public static function save( $post_id ) { |
|
281 | + public static function save($post_id) { |
|
282 | 282 | |
283 | 283 | // Prepare the item. |
284 | - $item = new WPInv_Item( $post_id ); |
|
284 | + $item = new WPInv_Item($post_id); |
|
285 | 285 | |
286 | 286 | // Load new data. |
287 | 287 | $item->set_props( |
288 | 288 | array( |
289 | - 'price' => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null, |
|
290 | - 'vat_rule' => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null, |
|
291 | - 'vat_class' => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null, |
|
292 | - 'type' => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null, |
|
293 | - 'is_dynamic_pricing' => ! empty( $_POST['wpinv_name_your_price'] ), |
|
294 | - 'minimum_price' => isset( $_POST['wpinv_minimum_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_minimum_price'] ) : null, |
|
295 | - 'is_recurring' => ! empty( $_POST['wpinv_is_recurring'] ), |
|
296 | - 'recurring_period' => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null, |
|
297 | - 'recurring_interval' => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1, |
|
298 | - 'recurring_limit' => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null, |
|
299 | - 'is_free_trial' => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null, |
|
300 | - 'trial_period' => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null, |
|
301 | - 'trial_interval' => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null, |
|
289 | + 'price' => isset($_POST['wpinv_item_price']) ? getpaid_standardize_amount($_POST['wpinv_item_price']) : null, |
|
290 | + 'vat_rule' => isset($_POST['wpinv_vat_rules']) ? wpinv_clean($_POST['wpinv_vat_rules']) : null, |
|
291 | + 'vat_class' => isset($_POST['wpinv_vat_class']) ? wpinv_clean($_POST['wpinv_vat_class']) : null, |
|
292 | + 'type' => isset($_POST['wpinv_item_type']) ? wpinv_clean($_POST['wpinv_item_type']) : null, |
|
293 | + 'is_dynamic_pricing' => !empty($_POST['wpinv_name_your_price']), |
|
294 | + 'minimum_price' => isset($_POST['wpinv_minimum_price']) ? getpaid_standardize_amount($_POST['wpinv_minimum_price']) : null, |
|
295 | + 'is_recurring' => !empty($_POST['wpinv_is_recurring']), |
|
296 | + 'recurring_period' => isset($_POST['wpinv_recurring_period']) ? wpinv_clean($_POST['wpinv_recurring_period']) : null, |
|
297 | + 'recurring_interval' => isset($_POST['wpinv_recurring_interval']) ? (int) $_POST['wpinv_recurring_interval'] : 1, |
|
298 | + 'recurring_limit' => isset($_POST['wpinv_recurring_limit']) ? (int) $_POST['wpinv_recurring_limit'] : null, |
|
299 | + 'is_free_trial' => isset($_POST['wpinv_trial_interval']) ? (0 != (int) $_POST['wpinv_trial_interval']) : null, |
|
300 | + 'trial_period' => isset($_POST['wpinv_trial_period']) ? wpinv_clean($_POST['wpinv_trial_period']) : null, |
|
301 | + 'trial_interval' => isset($_POST['wpinv_trial_interval']) ? (int) $_POST['wpinv_trial_interval'] : null, |
|
302 | 302 | ) |
303 | 303 | ); |
304 | 304 | |
305 | 305 | $item->save(); |
306 | - do_action( 'getpaid_item_metabox_save', $post_id, $item ); |
|
306 | + do_action('getpaid_item_metabox_save', $post_id, $item); |
|
307 | 307 | } |
308 | 308 | } |
@@ -1,38 +1,38 @@ |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( ! defined( 'WPINC' ) ) { |
|
3 | +if (!defined('WPINC')) { |
|
4 | 4 | exit; |
5 | 5 | } |
6 | 6 | |
7 | 7 | class WPInv_Meta_Box_Notes { |
8 | - public static function output( $post ) { |
|
8 | + public static function output($post) { |
|
9 | 9 | global $post; |
10 | 10 | |
11 | - $notes = wpinv_get_invoice_notes( $post->ID ); |
|
11 | + $notes = wpinv_get_invoice_notes($post->ID); |
|
12 | 12 | |
13 | 13 | echo '<ul class="invoice_notes">'; |
14 | 14 | |
15 | - if ( $notes ) { |
|
16 | - foreach ( $notes as $note ) { |
|
17 | - wpinv_get_invoice_note_line_item( $note ); |
|
15 | + if ($notes) { |
|
16 | + foreach ($notes as $note) { |
|
17 | + wpinv_get_invoice_note_line_item($note); |
|
18 | 18 | } |
19 | 19 | } else { |
20 | - echo '<li>' . __( 'There are no notes yet.', 'invoicing' ) . '</li>'; |
|
20 | + echo '<li>' . __('There are no notes yet.', 'invoicing') . '</li>'; |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | echo '</ul>'; |
24 | 24 | ?> |
25 | 25 | <div class="add_note"> |
26 | - <h4><?php esc_html_e( 'Add note', 'invoicing' ); ?></h4> |
|
26 | + <h4><?php esc_html_e('Add note', 'invoicing'); ?></h4> |
|
27 | 27 | <p> |
28 | 28 | <textarea type="text" name="invoice_note" id="add_invoice_note" class="input-text" cols="20" rows="5"></textarea> |
29 | 29 | </p> |
30 | 30 | <p> |
31 | 31 | <select name="invoice_note_type" id="invoice_note_type" class="regular-text"> |
32 | - <option value=""><?php esc_html_e( 'Private note', 'invoicing' ); ?></option> |
|
33 | - <option value="customer"><?php esc_html_e( 'Note to customer', 'invoicing' ); ?></option> |
|
32 | + <option value=""><?php esc_html_e('Private note', 'invoicing'); ?></option> |
|
33 | + <option value="customer"><?php esc_html_e('Note to customer', 'invoicing'); ?></option> |
|
34 | 34 | </select> |
35 | - <a href="#" class="add_note button"><?php esc_html_e( 'Add', 'invoicing' ); ?></a> <span class="description"><?php esc_html_e( 'Add a note for your reference, or add a customer note (the user will be notified).', 'invoicing' ); ?></span> |
|
35 | + <a href="#" class="add_note button"><?php esc_html_e('Add', 'invoicing'); ?></a> <span class="description"><?php esc_html_e('Add a note for your reference, or add a customer note (the user will be notified).', 'invoicing'); ?></span> |
|
36 | 36 | </p> |
37 | 37 | </div> |
38 | 38 | <?php |
@@ -1,51 +1,51 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( ! defined( 'WPINC' ) ) { |
|
3 | +if (!defined('WPINC')) { |
|
4 | 4 | exit; |
5 | 5 | } |
6 | 6 | |
7 | -add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' ); |
|
8 | -function wpinv_discount_custom_column( $column ) { |
|
7 | +add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column'); |
|
8 | +function wpinv_discount_custom_column($column) { |
|
9 | 9 | global $post; |
10 | 10 | |
11 | - $discount = new WPInv_Discount( $post ); |
|
11 | + $discount = new WPInv_Discount($post); |
|
12 | 12 | |
13 | - switch ( $column ) { |
|
13 | + switch ($column) { |
|
14 | 14 | case 'code': |
15 | - echo esc_html( $discount->get_code() ); |
|
15 | + echo esc_html($discount->get_code()); |
|
16 | 16 | break; |
17 | 17 | case 'amount': |
18 | - echo wp_kses_post( $discount->get_formatted_amount() ); |
|
18 | + echo wp_kses_post($discount->get_formatted_amount()); |
|
19 | 19 | break; |
20 | 20 | case 'usage': |
21 | - echo wp_kses_post( $discount->get_usage() ); |
|
21 | + echo wp_kses_post($discount->get_usage()); |
|
22 | 22 | break; |
23 | 23 | case 'start_date': |
24 | - echo wp_kses_post( getpaid_format_date_value( $discount->get_start_date() ) ); |
|
24 | + echo wp_kses_post(getpaid_format_date_value($discount->get_start_date())); |
|
25 | 25 | break; |
26 | 26 | case 'expiry_date': |
27 | - echo wp_kses_post( getpaid_format_date_value( $discount->get_expiration_date(), __( 'Never', 'invoicing' ) ) ); |
|
27 | + echo wp_kses_post(getpaid_format_date_value($discount->get_expiration_date(), __('Never', 'invoicing'))); |
|
28 | 28 | break; |
29 | 29 | } |
30 | 30 | } |
31 | 31 | |
32 | -add_filter( 'post_row_actions', 'wpinv_post_row_actions', 90, 2 ); |
|
33 | -function wpinv_post_row_actions( $actions, $post ) { |
|
34 | - $post_type = ! empty( $post->post_type ) ? $post->post_type : ''; |
|
32 | +add_filter('post_row_actions', 'wpinv_post_row_actions', 90, 2); |
|
33 | +function wpinv_post_row_actions($actions, $post) { |
|
34 | + $post_type = !empty($post->post_type) ? $post->post_type : ''; |
|
35 | 35 | |
36 | - if ( $post_type == 'wpi_discount' ) { |
|
37 | - $actions = wpinv_discount_row_actions( $post, $actions ); |
|
36 | + if ($post_type == 'wpi_discount') { |
|
37 | + $actions = wpinv_discount_row_actions($post, $actions); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | return $actions; |
41 | 41 | } |
42 | 42 | |
43 | -function wpinv_discount_row_actions( $discount, $row_actions ) { |
|
44 | - $row_actions = array(); |
|
45 | - $edit_link = get_edit_post_link( $discount->ID ); |
|
46 | - $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>'; |
|
43 | +function wpinv_discount_row_actions($discount, $row_actions) { |
|
44 | + $row_actions = array(); |
|
45 | + $edit_link = get_edit_post_link($discount->ID); |
|
46 | + $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>'; |
|
47 | 47 | |
48 | - if ( in_array( strtolower( $discount->post_status ), array( 'publish' ) ) ) { |
|
48 | + if (in_array(strtolower($discount->post_status), array('publish'))) { |
|
49 | 49 | |
50 | 50 | $url = wp_nonce_url( |
51 | 51 | add_query_arg( |
@@ -57,13 +57,13 @@ discard block |
||
57 | 57 | 'getpaid-nonce', |
58 | 58 | 'getpaid-nonce' |
59 | 59 | ); |
60 | - $anchor = __( 'Deactivate', 'invoicing' ); |
|
61 | - $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
60 | + $anchor = __('Deactivate', 'invoicing'); |
|
61 | + $title = esc_attr__('Are you sure you want to deactivate this discount?', 'invoicing'); |
|
62 | 62 | $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
63 | 63 | |
64 | - } elseif ( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
|
64 | + } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) { |
|
65 | 65 | |
66 | - $url = wp_nonce_url( |
|
66 | + $url = wp_nonce_url( |
|
67 | 67 | add_query_arg( |
68 | 68 | array( |
69 | 69 | 'getpaid-admin-action' => 'activate_discount', |
@@ -73,13 +73,13 @@ discard block |
||
73 | 73 | 'getpaid-nonce', |
74 | 74 | 'getpaid-nonce' |
75 | 75 | ); |
76 | - $anchor = __( 'Activate', 'invoicing' ); |
|
77 | - $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
76 | + $anchor = __('Activate', 'invoicing'); |
|
77 | + $title = esc_attr__('Are you sure you want to activate this discount?', 'invoicing'); |
|
78 | 78 | $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
79 | 79 | |
80 | 80 | } |
81 | 81 | |
82 | - $url = esc_url( |
|
82 | + $url = esc_url( |
|
83 | 83 | wp_nonce_url( |
84 | 84 | add_query_arg( |
85 | 85 | array( |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | 'getpaid-nonce' |
92 | 92 | ) |
93 | 93 | ); |
94 | - $anchor = __( 'Delete', 'invoicing' ); |
|
95 | - $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
94 | + $anchor = __('Delete', 'invoicing'); |
|
95 | + $title = esc_attr__('Are you sure you want to delete this discount?', 'invoicing'); |
|
96 | 96 | $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
97 | 97 | |
98 | - $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
|
98 | + $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount); |
|
99 | 99 | |
100 | 100 | return $row_actions; |
101 | 101 | } |
@@ -103,68 +103,68 @@ discard block |
||
103 | 103 | function wpinv_restrict_manage_posts() { |
104 | 104 | global $typenow; |
105 | 105 | |
106 | - if ( 'wpi_discount' == $typenow ) { |
|
106 | + if ('wpi_discount' == $typenow) { |
|
107 | 107 | wpinv_discount_filters(); |
108 | 108 | } |
109 | 109 | } |
110 | -add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 ); |
|
110 | +add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10); |
|
111 | 111 | |
112 | 112 | function wpinv_discount_filters() { |
113 | 113 | |
114 | 114 | ?> |
115 | 115 | <select name="discount_type" id="dropdown_wpinv_discount_type"> |
116 | - <option value=""><?php esc_html_e( 'Show all types', 'invoicing' ); ?></option> |
|
116 | + <option value=""><?php esc_html_e('Show all types', 'invoicing'); ?></option> |
|
117 | 117 | <?php |
118 | 118 | $types = wpinv_get_discount_types(); |
119 | 119 | |
120 | - foreach ( $types as $name => $type ) { |
|
121 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
120 | + foreach ($types as $name => $type) { |
|
121 | + echo '<option value="' . esc_attr($name) . '"'; |
|
122 | 122 | |
123 | - if ( isset( $_GET['discount_type'] ) ) { |
|
124 | - selected( $name, sanitize_text_field( $_GET['discount_type'] ) ); |
|
123 | + if (isset($_GET['discount_type'])) { |
|
124 | + selected($name, sanitize_text_field($_GET['discount_type'])); |
|
125 | 125 | } |
126 | 126 | |
127 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
127 | + echo '>' . esc_html__($type, 'invoicing') . '</option>'; |
|
128 | 128 | } |
129 | 129 | ?> |
130 | 130 | </select> |
131 | 131 | <?php |
132 | 132 | } |
133 | 133 | |
134 | -function wpinv_request( $vars ) { |
|
134 | +function wpinv_request($vars) { |
|
135 | 135 | global $typenow, $wp_post_statuses; |
136 | 136 | |
137 | - if ( getpaid_is_invoice_post_type( $typenow ) ) { |
|
138 | - if ( ! isset( $vars['post_status'] ) ) { |
|
139 | - $post_statuses = wpinv_get_invoice_statuses( false, false, $typenow ); |
|
137 | + if (getpaid_is_invoice_post_type($typenow)) { |
|
138 | + if (!isset($vars['post_status'])) { |
|
139 | + $post_statuses = wpinv_get_invoice_statuses(false, false, $typenow); |
|
140 | 140 | |
141 | - foreach ( $post_statuses as $status => $value ) { |
|
142 | - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { |
|
143 | - unset( $post_statuses[ $status ] ); |
|
141 | + foreach ($post_statuses as $status => $value) { |
|
142 | + if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) { |
|
143 | + unset($post_statuses[$status]); |
|
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
147 | - $vars['post_status'] = array_keys( $post_statuses ); |
|
147 | + $vars['post_status'] = array_keys($post_statuses); |
|
148 | 148 | } |
149 | -} elseif ( 'wpi_discount' == $typenow ) { |
|
150 | - $meta_query = ! empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
149 | +} elseif ('wpi_discount' == $typenow) { |
|
150 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
151 | 151 | // Filter vat rule type |
152 | - if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
|
152 | + if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') { |
|
153 | 153 | $meta_query[] = array( |
154 | 154 | 'key' => '_wpi_discount_type', |
155 | - 'value' => sanitize_key( urldecode( $_GET['discount_type'] ) ), |
|
155 | + 'value' => sanitize_key(urldecode($_GET['discount_type'])), |
|
156 | 156 | 'compare' => '=', |
157 | 157 | ); |
158 | 158 | } |
159 | 159 | |
160 | - if ( ! empty( $meta_query ) ) { |
|
160 | + if (!empty($meta_query)) { |
|
161 | 161 | $vars['meta_query'] = $meta_query; |
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
165 | 165 | return $vars; |
166 | 166 | } |
167 | -add_filter( 'request', 'wpinv_request' ); |
|
167 | +add_filter('request', 'wpinv_request'); |
|
168 | 168 | |
169 | 169 | /** |
170 | 170 | * Create a page and store the ID in an option. |
@@ -176,61 +176,61 @@ discard block |
||
176 | 176 | * @param int $post_parent (default: 0) Parent for the new page |
177 | 177 | * @return int page ID |
178 | 178 | */ |
179 | -function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) { |
|
179 | +function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) { |
|
180 | 180 | global $wpdb; |
181 | 181 | |
182 | - $option_value = wpinv_get_option( $option ); |
|
182 | + $option_value = wpinv_get_option($option); |
|
183 | 183 | |
184 | - if ( ! empty( $option_value ) && ( $page_object = get_post( $option_value ) ) ) { |
|
185 | - if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) { |
|
184 | + if (!empty($option_value) && ($page_object = get_post($option_value))) { |
|
185 | + if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) { |
|
186 | 186 | // Valid page is already in place |
187 | 187 | return $page_object->ID; |
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
191 | - if ( ! empty( $post_parent ) ) { |
|
192 | - $page = get_page_by_path( $post_parent ); |
|
193 | - if ( $page ) { |
|
191 | + if (!empty($post_parent)) { |
|
192 | + $page = get_page_by_path($post_parent); |
|
193 | + if ($page) { |
|
194 | 194 | $post_parent = $page->ID; |
195 | 195 | } else { |
196 | 196 | $post_parent = ''; |
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
200 | - if ( strlen( $page_content ) > 0 ) { |
|
200 | + if (strlen($page_content) > 0) { |
|
201 | 201 | // Search for an existing page with the specified page content (typically a shortcode) |
202 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
202 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
203 | 203 | } else { |
204 | 204 | // Search for an existing page with the specified page slug |
205 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) ); |
|
205 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug)); |
|
206 | 206 | } |
207 | 207 | |
208 | - $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content ); |
|
208 | + $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content); |
|
209 | 209 | |
210 | - if ( $valid_page_found ) { |
|
211 | - if ( $option ) { |
|
212 | - wpinv_update_option( $option, $valid_page_found ); |
|
210 | + if ($valid_page_found) { |
|
211 | + if ($option) { |
|
212 | + wpinv_update_option($option, $valid_page_found); |
|
213 | 213 | } |
214 | 214 | return $valid_page_found; |
215 | 215 | } |
216 | 216 | |
217 | 217 | // Search for a matching valid trashed page |
218 | - if ( strlen( $page_content ) > 0 ) { |
|
218 | + if (strlen($page_content) > 0) { |
|
219 | 219 | // Search for an existing page with the specified page content (typically a shortcode) |
220 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
220 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
221 | 221 | } else { |
222 | 222 | // Search for an existing page with the specified page slug |
223 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) ); |
|
223 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug)); |
|
224 | 224 | } |
225 | 225 | |
226 | - if ( $trashed_page_found ) { |
|
226 | + if ($trashed_page_found) { |
|
227 | 227 | $page_id = $trashed_page_found; |
228 | 228 | $page_data = array( |
229 | 229 | 'ID' => $page_id, |
230 | 230 | 'post_status' => 'publish', |
231 | 231 | 'post_parent' => $post_parent, |
232 | 232 | ); |
233 | - wp_update_post( $page_data ); |
|
233 | + wp_update_post($page_data); |
|
234 | 234 | } else { |
235 | 235 | $page_data = array( |
236 | 236 | 'post_status' => 'publish', |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | 'post_parent' => $post_parent, |
243 | 243 | 'comment_status' => 'closed', |
244 | 244 | ); |
245 | - $page_id = wp_insert_post( $page_data ); |
|
245 | + $page_id = wp_insert_post($page_data); |
|
246 | 246 | } |
247 | 247 | |
248 | - if ( $option ) { |
|
249 | - wpinv_update_option( $option, (int) $page_id ); |
|
248 | + if ($option) { |
|
249 | + wpinv_update_option($option, (int) $page_id); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | return $page_id; |
@@ -259,11 +259,11 @@ discard block |
||
259 | 259 | * |
260 | 260 | * @return array |
261 | 261 | */ |
262 | -function wpinv_add_aui_screens( $screen_ids ) { |
|
262 | +function wpinv_add_aui_screens($screen_ids) { |
|
263 | 263 | |
264 | 264 | // load on these pages if set |
265 | - $screen_ids = array_merge( $screen_ids, wpinv_get_screen_ids() ); |
|
265 | + $screen_ids = array_merge($screen_ids, wpinv_get_screen_ids()); |
|
266 | 266 | |
267 | 267 | return $screen_ids; |
268 | 268 | } |
269 | -add_filter( 'aui_screen_ids', 'wpinv_add_aui_screens' ); |
|
269 | +add_filter('aui_screen_ids', 'wpinv_add_aui_screens'); |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Setup menus in WP admin. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * WC_Admin_Menus Class. |
@@ -13,14 +13,14 @@ discard block |
||
13 | 13 | * Hook in tabs. |
14 | 14 | */ |
15 | 15 | public function __construct() { |
16 | - add_action( 'admin_head', array( $this, 'set_admin_menu_class' ) ); |
|
17 | - add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 ); |
|
18 | - add_action( 'admin_menu', array( $this, 'add_customers_menu' ), 18 ); |
|
19 | - add_action( 'admin_menu', array( $this, 'add_subscriptions_menu' ), 40 ); |
|
20 | - add_action( 'admin_menu', array( $this, 'add_addons_menu' ), 100 ); |
|
21 | - add_action( 'admin_menu', array( $this, 'add_settings_menu' ), 60 ); |
|
22 | - add_action( 'admin_menu', array( $this, 'remove_admin_submenus' ), 10 ); |
|
23 | - add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) ); |
|
16 | + add_action('admin_head', array($this, 'set_admin_menu_class')); |
|
17 | + add_action('admin_menu', array($this, 'admin_menu'), 10); |
|
18 | + add_action('admin_menu', array($this, 'add_customers_menu'), 18); |
|
19 | + add_action('admin_menu', array($this, 'add_subscriptions_menu'), 40); |
|
20 | + add_action('admin_menu', array($this, 'add_addons_menu'), 100); |
|
21 | + add_action('admin_menu', array($this, 'add_settings_menu'), 60); |
|
22 | + add_action('admin_menu', array($this, 'remove_admin_submenus'), 10); |
|
23 | + add_action('admin_head-nav-menus.php', array($this, 'add_nav_menu_meta_boxes')); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | public function set_admin_menu_class() { |
30 | 30 | global $current_screen, $parent_file, $submenu_file; |
31 | 31 | |
32 | - if ( ! empty( $current_screen->id ) && in_array( $current_screen->id, array( 'wpi_discount', 'wpi_payment_form', 'wpi_invoice' ) ) ) { |
|
32 | + if (!empty($current_screen->id) && in_array($current_screen->id, array('wpi_discount', 'wpi_payment_form', 'wpi_invoice'))) { |
|
33 | 33 | $parent_file = 'wpinv'; |
34 | 34 | $submenu_file = 'edit.php?post_type=' . $current_screen->id; |
35 | 35 | } |
@@ -38,14 +38,14 @@ discard block |
||
38 | 38 | |
39 | 39 | public function admin_menu() { |
40 | 40 | |
41 | - $capability = apply_filters( 'invoicing_capability', wpinv_get_capability() ); |
|
41 | + $capability = apply_filters('invoicing_capability', wpinv_get_capability()); |
|
42 | 42 | add_menu_page( |
43 | - __( 'GetPaid', 'invoicing' ), |
|
44 | - __( 'GetPaid', 'invoicing' ), |
|
43 | + __('GetPaid', 'invoicing'), |
|
44 | + __('GetPaid', 'invoicing'), |
|
45 | 45 | $capability, |
46 | 46 | 'wpinv', |
47 | 47 | null, |
48 | - 'data:image/svg+xml;base64,' . base64_encode( file_get_contents( WPINV_PLUGIN_DIR . 'assets/images/GetPaid.svg' ) ), |
|
48 | + 'data:image/svg+xml;base64,' . base64_encode(file_get_contents(WPINV_PLUGIN_DIR . 'assets/images/GetPaid.svg')), |
|
49 | 49 | '54.123460' |
50 | 50 | ); |
51 | 51 | |
@@ -57,11 +57,11 @@ discard block |
||
57 | 57 | public function add_customers_menu() { |
58 | 58 | add_submenu_page( |
59 | 59 | 'wpinv', |
60 | - __( 'Customers', 'invoicing' ), |
|
61 | - __( 'Customers', 'invoicing' ), |
|
60 | + __('Customers', 'invoicing'), |
|
61 | + __('Customers', 'invoicing'), |
|
62 | 62 | wpinv_get_capability(), |
63 | 63 | 'wpinv-customers', |
64 | - array( $this, 'customers_page' ) |
|
64 | + array($this, 'customers_page') |
|
65 | 65 | ); |
66 | 66 | } |
67 | 67 | |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | public function add_subscriptions_menu() { |
72 | 72 | add_submenu_page( |
73 | 73 | 'wpinv', |
74 | - __( 'Subscriptions', 'invoicing' ), |
|
75 | - __( 'Subscriptions', 'invoicing' ), |
|
74 | + __('Subscriptions', 'invoicing'), |
|
75 | + __('Subscriptions', 'invoicing'), |
|
76 | 76 | wpinv_get_capability(), |
77 | 77 | 'wpinv-subscriptions', |
78 | 78 | 'wpinv_subscriptions_page' |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | width: 30%; |
92 | 92 | } |
93 | 93 | </style> |
94 | - <h1><?php echo esc_html( __( 'Customers', 'invoicing' ) ); ?> <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'download_customers' ), 'getpaid-nonce', 'getpaid-nonce' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Export', 'invoicing' ); ?></a></h1> |
|
94 | + <h1><?php echo esc_html(__('Customers', 'invoicing')); ?> <a href="<?php echo esc_url(wp_nonce_url(add_query_arg('getpaid-admin-action', 'download_customers'), 'getpaid-nonce', 'getpaid-nonce')); ?>" class="page-title-action"><?php esc_html_e('Export', 'invoicing'); ?></a></h1> |
|
95 | 95 | <form method="post"> |
96 | 96 | <?php |
97 | 97 | $table = new WPInv_Customers_Table(); |
98 | 98 | $table->prepare_items(); |
99 | - $table->search_box( __( 'Search Customers', 'invoicing' ), 'search-customers' ); |
|
99 | + $table->search_box(__('Search Customers', 'invoicing'), 'search-customers'); |
|
100 | 100 | $table->display(); |
101 | 101 | ?> |
102 | 102 | </form> |
@@ -110,26 +110,26 @@ discard block |
||
110 | 110 | public function add_settings_menu() { |
111 | 111 | add_submenu_page( |
112 | 112 | 'wpinv', |
113 | - __( 'Invoice Settings', 'invoicing' ), |
|
114 | - __( 'Settings', 'invoicing' ), |
|
115 | - apply_filters( 'invoicing_capability', wpinv_get_capability() ), |
|
113 | + __('Invoice Settings', 'invoicing'), |
|
114 | + __('Settings', 'invoicing'), |
|
115 | + apply_filters('invoicing_capability', wpinv_get_capability()), |
|
116 | 116 | 'wpinv-settings', |
117 | - array( $this, 'options_page' ) |
|
117 | + array($this, 'options_page') |
|
118 | 118 | ); |
119 | 119 | } |
120 | 120 | |
121 | 121 | public function add_addons_menu() { |
122 | - if ( ! apply_filters( 'wpi_show_addons_page', true ) ) { |
|
122 | + if (!apply_filters('wpi_show_addons_page', true)) { |
|
123 | 123 | return; |
124 | 124 | } |
125 | 125 | |
126 | 126 | add_submenu_page( |
127 | 127 | 'wpinv', |
128 | - __( 'Invoicing extensions', 'invoicing' ), |
|
129 | - __( 'Extensions', 'invoicing' ), |
|
128 | + __('Invoicing extensions', 'invoicing'), |
|
129 | + __('Extensions', 'invoicing'), |
|
130 | 130 | 'manage_options', |
131 | 131 | 'wpi-addons', |
132 | - array( $this, 'addons_page' ) |
|
132 | + array($this, 'addons_page') |
|
133 | 133 | ); |
134 | 134 | } |
135 | 135 | |
@@ -140,29 +140,29 @@ discard block |
||
140 | 140 | |
141 | 141 | function options_page() { |
142 | 142 | |
143 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
143 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
144 | 144 | return; |
145 | 145 | } |
146 | 146 | |
147 | 147 | $settings_tabs = wpinv_get_settings_tabs(); |
148 | - $settings_tabs = empty( $settings_tabs ) ? array() : $settings_tabs; |
|
149 | - $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general'; |
|
150 | - $sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
148 | + $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs; |
|
149 | + $active_tab = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general'; |
|
150 | + $sections = wpinv_get_settings_tab_sections($active_tab); |
|
151 | 151 | $key = 'main'; |
152 | 152 | |
153 | - if ( is_array( $sections ) ) { |
|
154 | - $key = key( $sections ); |
|
153 | + if (is_array($sections)) { |
|
154 | + $key = key($sections); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | add_thickbox(); |
158 | 158 | |
159 | - $registered_sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
160 | - $section = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? sanitize_text_field( $_GET['section'] ) : $key; |
|
159 | + $registered_sections = wpinv_get_settings_tab_sections($active_tab); |
|
160 | + $section = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? sanitize_text_field($_GET['section']) : $key; |
|
161 | 161 | ?> |
162 | 162 | <div class="wrap"> |
163 | 163 | <h1 class="nav-tab-wrapper"> |
164 | 164 | <?php |
165 | - foreach ( wpinv_get_settings_tabs() as $tab_id => $tab_name ) { |
|
165 | + foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) { |
|
166 | 166 | $tab_url = add_query_arg( |
167 | 167 | array( |
168 | 168 | 'settings-updated' => false, |
@@ -172,23 +172,23 @@ discard block |
||
172 | 172 | ); |
173 | 173 | |
174 | 174 | // Remove the section from the tabs so we always end up at the main section |
175 | - $tab_url = remove_query_arg( 'section', $tab_url ); |
|
176 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
175 | + $tab_url = remove_query_arg('section', $tab_url); |
|
176 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
177 | 177 | |
178 | 178 | $active = $active_tab == $tab_id ? ' nav-tab-active' : ''; |
179 | 179 | |
180 | - echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . esc_attr( $active ) . '">'; |
|
181 | - echo esc_html( $tab_name ); |
|
180 | + echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . esc_attr($active) . '">'; |
|
181 | + echo esc_html($tab_name); |
|
182 | 182 | echo '</a>'; |
183 | 183 | } |
184 | 184 | ?> |
185 | 185 | </h1> |
186 | 186 | <?php |
187 | - $number_of_sections = count( $sections ); |
|
187 | + $number_of_sections = count($sections); |
|
188 | 188 | $number = 0; |
189 | - if ( $number_of_sections > 1 ) { |
|
189 | + if ($number_of_sections > 1) { |
|
190 | 190 | echo '<div><ul class="subsubsub">'; |
191 | - foreach ( $sections as $section_id => $section_name ) { |
|
191 | + foreach ($sections as $section_id => $section_name) { |
|
192 | 192 | echo '<li>'; |
193 | 193 | $number++; |
194 | 194 | $tab_url = add_query_arg( |
@@ -197,16 +197,16 @@ discard block |
||
197 | 197 | 'tab' => $active_tab, |
198 | 198 | 'section' => $section_id, |
199 | 199 | ), |
200 | - admin_url( 'admin.php?page=wpinv-settings' ) |
|
200 | + admin_url('admin.php?page=wpinv-settings') |
|
201 | 201 | ); |
202 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
202 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
203 | 203 | $class = ''; |
204 | - if ( $section == $section_id ) { |
|
204 | + if ($section == $section_id) { |
|
205 | 205 | $class = 'current'; |
206 | 206 | } |
207 | - echo '<a class="' . esc_attr( $class ) . '" href="' . esc_url( $tab_url ) . '">' . esc_html( $section_name ) . '</a>'; |
|
207 | + echo '<a class="' . esc_attr($class) . '" href="' . esc_url($tab_url) . '">' . esc_html($section_name) . '</a>'; |
|
208 | 208 | |
209 | - if ( $number != $number_of_sections ) { |
|
209 | + if ($number != $number_of_sections) { |
|
210 | 210 | echo ' | '; |
211 | 211 | } |
212 | 212 | echo '</li>'; |
@@ -218,20 +218,20 @@ discard block |
||
218 | 218 | <form method="post" action="options.php"> |
219 | 219 | <table class="form-table"> |
220 | 220 | <?php |
221 | - settings_fields( 'wpinv_settings' ); |
|
221 | + settings_fields('wpinv_settings'); |
|
222 | 222 | |
223 | - if ( 'main' === $section ) { |
|
224 | - do_action( 'wpinv_settings_tab_top', $active_tab ); |
|
223 | + if ('main' === $section) { |
|
224 | + do_action('wpinv_settings_tab_top', $active_tab); |
|
225 | 225 | } |
226 | 226 | |
227 | - do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
228 | - do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
229 | - do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
230 | - do_action( 'getpaid_settings_tab_bottom', $active_tab, $section ); |
|
227 | + do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section); |
|
228 | + do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section); |
|
229 | + do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section); |
|
230 | + do_action('getpaid_settings_tab_bottom', $active_tab, $section); |
|
231 | 231 | |
232 | 232 | // For backwards compatibility |
233 | - if ( 'main' === $section ) { |
|
234 | - do_action( 'wpinv_settings_tab_bottom', $active_tab ); |
|
233 | + if ('main' === $section) { |
|
234 | + do_action('wpinv_settings_tab_bottom', $active_tab); |
|
235 | 235 | } |
236 | 236 | ?> |
237 | 237 | </table> |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | } |
244 | 244 | |
245 | 245 | public function remove_admin_submenus() { |
246 | - remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' ); |
|
246 | + remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice'); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
@@ -253,8 +253,8 @@ discard block |
||
253 | 253 | |
254 | 254 | add_meta_box( |
255 | 255 | 'wpinv_endpoints_nav_link', |
256 | - __( 'GetPaid endpoints', 'invoicing' ), |
|
257 | - array( $this, 'nav_menu_links' ), |
|
256 | + __('GetPaid endpoints', 'invoicing'), |
|
257 | + array($this, 'nav_menu_links'), |
|
258 | 258 | 'nav-menus', |
259 | 259 | 'side', |
260 | 260 | 'low' |
@@ -269,12 +269,12 @@ discard block |
||
269 | 269 | $endpoints = $this->get_menu_items(); |
270 | 270 | ?> |
271 | 271 | <div id="invoicing-endpoints" class="posttypediv"> |
272 | - <?php if ( ! empty( $endpoints['pages'] ) ) : ?> |
|
272 | + <?php if (!empty($endpoints['pages'])) : ?> |
|
273 | 273 | <div id="tabs-panel-invoicing-endpoints" class="tabs-panel tabs-panel-active"> |
274 | 274 | <ul id="invoicing-endpoints-checklist" class="categorychecklist form-no-clear"> |
275 | 275 | <?php |
276 | - $walker = new Walker_Nav_Menu_Checklist( array() ); |
|
277 | - echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $endpoints['pages'] ), 0, (object) array( 'walker' => $walker ) ); |
|
276 | + $walker = new Walker_Nav_Menu_Checklist(array()); |
|
277 | + echo walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $endpoints['pages']), 0, (object) array('walker' => $walker)); |
|
278 | 278 | ?> |
279 | 279 | </ul> |
280 | 280 | </div> |
@@ -283,11 +283,11 @@ discard block |
||
283 | 283 | <p class="button-controls wp-clearfix" data-items-type="invoicing-endpoints"> |
284 | 284 | <span class="list-controls hide-if-no-js"> |
285 | 285 | <input type="checkbox" id="invoicing-endpoints-tab" class="select-all"> |
286 | - <label for="invoicing-endpoints-tab"><?php esc_html_e( 'Select all', 'invoicing' ); ?></label> |
|
286 | + <label for="invoicing-endpoints-tab"><?php esc_html_e('Select all', 'invoicing'); ?></label> |
|
287 | 287 | </span> |
288 | 288 | |
289 | 289 | <span class="add-to-menu"> |
290 | - <input type="submit" class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to menu', 'invoicing' ); ?>" name="add-invoicing-endpoints-item" id="submit-invoicing-endpoints"> |
|
290 | + <input type="submit" class="button submit-add-to-menu right" value="<?php esc_attr_e('Add to menu', 'invoicing'); ?>" name="add-invoicing-endpoints-item" id="submit-invoicing-endpoints"> |
|
291 | 291 | <span class="spinner"></span> |
292 | 292 | </span> |
293 | 293 | </p> |
@@ -305,18 +305,18 @@ discard block |
||
305 | 305 | |
306 | 306 | $pages = array( |
307 | 307 | array( |
308 | - 'id' => wpinv_get_option( 'invoice_history_page' ), |
|
309 | - 'label' => __( 'My Invoices', 'invoicing' ), |
|
308 | + 'id' => wpinv_get_option('invoice_history_page'), |
|
309 | + 'label' => __('My Invoices', 'invoicing'), |
|
310 | 310 | ), |
311 | 311 | array( |
312 | - 'id' => wpinv_get_option( 'invoice_subscription_page' ), |
|
313 | - 'label' => __( 'My Subscriptions', 'invoicing' ), |
|
312 | + 'id' => wpinv_get_option('invoice_subscription_page'), |
|
313 | + 'label' => __('My Subscriptions', 'invoicing'), |
|
314 | 314 | ), |
315 | 315 | ); |
316 | 316 | |
317 | - foreach ( apply_filters( 'getpaid_menu_pages', $pages ) as $page ) { |
|
317 | + foreach (apply_filters('getpaid_menu_pages', $pages) as $page) { |
|
318 | 318 | |
319 | - if ( (int) $page['id'] > 0 ) { |
|
319 | + if ((int) $page['id'] > 0) { |
|
320 | 320 | |
321 | 321 | $item = new stdClass(); |
322 | 322 | $item->object_id = (int) $page['id']; |
@@ -324,11 +324,11 @@ discard block |
||
324 | 324 | $item->object = 'page'; |
325 | 325 | $item->menu_item_parent = 0; |
326 | 326 | $item->type = 'post_type'; |
327 | - $item->title = esc_html( $page['label'] ); |
|
328 | - $item->url = get_permalink( (int) $page['id'] ); |
|
327 | + $item->title = esc_html($page['label']); |
|
328 | + $item->url = get_permalink((int) $page['id']); |
|
329 | 329 | $item->target = ''; |
330 | 330 | $item->attr_title = ''; |
331 | - $item->classes = array( 'wpinv-menu-item' ); |
|
331 | + $item->classes = array('wpinv-menu-item'); |
|
332 | 332 | $item->xfn = ''; |
333 | 333 | |
334 | 334 | $items['pages'][] = $item; |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | } |
337 | 337 | } |
338 | 338 | |
339 | - return apply_filters( 'wpinv_menu_items', $items ); |
|
339 | + return apply_filters('wpinv_menu_items', $items); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | } |
@@ -7,40 +7,40 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( ! defined( 'WPINC' ) ) { |
|
10 | +if (!defined('WPINC')) { |
|
11 | 11 | exit; |
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_is_checkout() { |
15 | 15 | global $wp_query; |
16 | 16 | |
17 | - $is_object_set = isset( $wp_query->queried_object ); |
|
18 | - $is_object_id_set = isset( $wp_query->queried_object_id ); |
|
19 | - $checkout_page = wpinv_get_option( 'checkout_page' ); |
|
20 | - $is_checkout = ! empty( $checkout_page ) && is_page( $checkout_page ); |
|
17 | + $is_object_set = isset($wp_query->queried_object); |
|
18 | + $is_object_id_set = isset($wp_query->queried_object_id); |
|
19 | + $checkout_page = wpinv_get_option('checkout_page'); |
|
20 | + $is_checkout = !empty($checkout_page) && is_page($checkout_page); |
|
21 | 21 | |
22 | - if ( ! $is_object_set ) { |
|
23 | - unset( $wp_query->queried_object ); |
|
22 | + if (!$is_object_set) { |
|
23 | + unset($wp_query->queried_object); |
|
24 | 24 | } |
25 | 25 | |
26 | - if ( ! $is_object_id_set ) { |
|
27 | - unset( $wp_query->queried_object_id ); |
|
26 | + if (!$is_object_id_set) { |
|
27 | + unset($wp_query->queried_object_id); |
|
28 | 28 | } |
29 | 29 | |
30 | - return apply_filters( 'wpinv_is_checkout', $is_checkout ); |
|
30 | + return apply_filters('wpinv_is_checkout', $is_checkout); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | function wpinv_can_checkout() { |
34 | 34 | $can_checkout = true; // Always true for now |
35 | 35 | |
36 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
36 | + return (bool) apply_filters('wpinv_can_checkout', $can_checkout); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | function wpinv_get_success_page_uri() { |
40 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
41 | - $page_id = absint( $page_id ); |
|
40 | + $page_id = wpinv_get_option('success_page', 0); |
|
41 | + $page_id = absint($page_id); |
|
42 | 42 | |
43 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
43 | + return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id)); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -49,143 +49,143 @@ discard block |
||
49 | 49 | * @param string $post_type The post type or invoice type. |
50 | 50 | * @return string The history page URL. |
51 | 51 | */ |
52 | -function wpinv_get_history_page_uri( $post_type = 'wpi_invoice' ) { |
|
53 | - $post_type = sanitize_key( str_replace( 'wpi_', '', $post_type ) ); |
|
54 | - $page_id = wpinv_get_option( "{$post_type}_history_page", 0 ); |
|
55 | - $page_id = absint( $page_id ); |
|
56 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type ); |
|
52 | +function wpinv_get_history_page_uri($post_type = 'wpi_invoice') { |
|
53 | + $post_type = sanitize_key(str_replace('wpi_', '', $post_type)); |
|
54 | + $page_id = wpinv_get_option("{$post_type}_history_page", 0); |
|
55 | + $page_id = absint($page_id); |
|
56 | + return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id), $post_type); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | function wpinv_is_success_page() { |
60 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
61 | - $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
60 | + $is_success_page = wpinv_get_option('success_page', false); |
|
61 | + $is_success_page = !empty($is_success_page) ? is_page($is_success_page) : false; |
|
62 | 62 | |
63 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
63 | + return apply_filters('wpinv_is_success_page', $is_success_page); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | function wpinv_is_invoice_history_page() { |
67 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
68 | - $ret = $ret ? is_page( $ret ) : false; |
|
69 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
67 | + $ret = wpinv_get_option('invoice_history_page', false); |
|
68 | + $ret = $ret ? is_page($ret) : false; |
|
69 | + return apply_filters('wpinv_is_invoice_history_page', $ret); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | function wpinv_is_subscriptions_history_page() { |
73 | - $ret = wpinv_get_option( 'invoice_subscription_page', false ); |
|
74 | - $ret = $ret ? is_page( $ret ) : false; |
|
75 | - return apply_filters( 'wpinv_is_subscriptions_history_page', $ret ); |
|
73 | + $ret = wpinv_get_option('invoice_subscription_page', false); |
|
74 | + $ret = $ret ? is_page($ret) : false; |
|
75 | + return apply_filters('wpinv_is_subscriptions_history_page', $ret); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * Redirects a user the success page. |
80 | 80 | */ |
81 | -function wpinv_send_to_success_page( $args = array() ) { |
|
81 | +function wpinv_send_to_success_page($args = array()) { |
|
82 | 82 | |
83 | 83 | $redirect = add_query_arg( |
84 | - wp_parse_args( $args ), |
|
84 | + wp_parse_args($args), |
|
85 | 85 | wpinv_get_success_page_uri() |
86 | 86 | ); |
87 | 87 | |
88 | - $redirect = apply_filters( 'wpinv_send_to_success_page_url', $redirect, $args ); |
|
88 | + $redirect = apply_filters('wpinv_send_to_success_page_url', $redirect, $args); |
|
89 | 89 | |
90 | - wp_redirect( $redirect ); |
|
90 | + wp_redirect($redirect); |
|
91 | 91 | exit; |
92 | 92 | } |
93 | 93 | |
94 | -function wpinv_send_to_failed_page( $args = null ) { |
|
94 | +function wpinv_send_to_failed_page($args = null) { |
|
95 | 95 | $redirect = wpinv_get_failed_transaction_uri(); |
96 | 96 | |
97 | - if ( ! empty( $args ) ) { |
|
97 | + if (!empty($args)) { |
|
98 | 98 | // Check for backward compatibility |
99 | - if ( is_string( $args ) ) { |
|
100 | - $args = str_replace( '?', '', $args ); |
|
99 | + if (is_string($args)) { |
|
100 | + $args = str_replace('?', '', $args); |
|
101 | 101 | } |
102 | 102 | |
103 | - $args = wp_parse_args( $args ); |
|
103 | + $args = wp_parse_args($args); |
|
104 | 104 | |
105 | - $redirect = add_query_arg( $args, $redirect ); |
|
105 | + $redirect = add_query_arg($args, $redirect); |
|
106 | 106 | } |
107 | 107 | |
108 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : ''; |
|
108 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : ''; |
|
109 | 109 | |
110 | - $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args ); |
|
111 | - wp_redirect( $redirect ); |
|
110 | + $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args); |
|
111 | + wp_redirect($redirect); |
|
112 | 112 | exit; |
113 | 113 | } |
114 | 114 | |
115 | -function wpinv_get_checkout_uri( $args = array() ) { |
|
116 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
117 | - $uri = isset( $uri ) ? get_permalink( $uri ) : null; |
|
115 | +function wpinv_get_checkout_uri($args = array()) { |
|
116 | + $uri = wpinv_get_option('checkout_page', false); |
|
117 | + $uri = isset($uri) ? get_permalink($uri) : null; |
|
118 | 118 | |
119 | - if ( ! empty( $args ) ) { |
|
119 | + if (!empty($args)) { |
|
120 | 120 | // Check for backward compatibility |
121 | - if ( is_string( $args ) ) { |
|
122 | - $args = str_replace( '?', '', $args ); |
|
121 | + if (is_string($args)) { |
|
122 | + $args = str_replace('?', '', $args); |
|
123 | 123 | } |
124 | 124 | |
125 | - $args = wp_parse_args( $args ); |
|
125 | + $args = wp_parse_args($args); |
|
126 | 126 | |
127 | - $uri = add_query_arg( $args, $uri ); |
|
127 | + $uri = add_query_arg($args, $uri); |
|
128 | 128 | } |
129 | 129 | |
130 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
130 | + $scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
131 | 131 | |
132 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
132 | + $ajax_url = admin_url('admin-ajax.php', $scheme); |
|
133 | 133 | |
134 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
135 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
134 | + if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) { |
|
135 | + $uri = preg_replace('/^http:/', 'https:', $uri); |
|
136 | 136 | } |
137 | 137 | |
138 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
138 | + return apply_filters('wpinv_get_checkout_uri', $uri); |
|
139 | 139 | } |
140 | 140 | |
141 | -function wpinv_get_success_page_url( $query_string = null ) { |
|
142 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
143 | - $success_page = get_permalink( $success_page ); |
|
141 | +function wpinv_get_success_page_url($query_string = null) { |
|
142 | + $success_page = wpinv_get_option('success_page', 0); |
|
143 | + $success_page = get_permalink($success_page); |
|
144 | 144 | |
145 | - if ( $query_string ) { |
|
145 | + if ($query_string) { |
|
146 | 146 | $success_page .= $query_string; |
147 | 147 | } |
148 | 148 | |
149 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
149 | + return apply_filters('wpinv_success_page_url', $success_page); |
|
150 | 150 | } |
151 | 151 | |
152 | -function wpinv_get_failed_transaction_uri( $extras = false ) { |
|
153 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
154 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
152 | +function wpinv_get_failed_transaction_uri($extras = false) { |
|
153 | + $uri = wpinv_get_option('failure_page', ''); |
|
154 | + $uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url(); |
|
155 | 155 | |
156 | - if ( $extras ) { |
|
156 | + if ($extras) { |
|
157 | 157 | $uri .= $extras; |
158 | 158 | } |
159 | 159 | |
160 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
160 | + return apply_filters('wpinv_get_failed_transaction_uri', $uri); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | function wpinv_is_failed_transaction_page() { |
164 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
165 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
164 | + $ret = wpinv_get_option('failure_page', false); |
|
165 | + $ret = isset($ret) ? is_page($ret) : false; |
|
166 | 166 | |
167 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
167 | + return apply_filters('wpinv_is_failure_page', $ret); |
|
168 | 168 | } |
169 | 169 | |
170 | -function wpinv_transaction_query( $type = 'start' ) { |
|
170 | +function wpinv_transaction_query($type = 'start') { |
|
171 | 171 | global $wpdb; |
172 | 172 | |
173 | 173 | $wpdb->hide_errors(); |
174 | 174 | |
175 | - if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) { |
|
176 | - define( 'WPINV_USE_TRANSACTIONS', true ); |
|
175 | + if (!defined('WPINV_USE_TRANSACTIONS')) { |
|
176 | + define('WPINV_USE_TRANSACTIONS', true); |
|
177 | 177 | } |
178 | 178 | |
179 | - if ( WPINV_USE_TRANSACTIONS ) { |
|
180 | - switch ( $type ) { |
|
179 | + if (WPINV_USE_TRANSACTIONS) { |
|
180 | + switch ($type) { |
|
181 | 181 | case 'commit': |
182 | - $wpdb->query( 'COMMIT' ); |
|
182 | + $wpdb->query('COMMIT'); |
|
183 | 183 | break; |
184 | 184 | case 'rollback': |
185 | - $wpdb->query( 'ROLLBACK' ); |
|
185 | + $wpdb->query('ROLLBACK'); |
|
186 | 186 | break; |
187 | 187 | default: |
188 | - $wpdb->query( 'START TRANSACTION' ); |
|
188 | + $wpdb->query('START TRANSACTION'); |
|
189 | 189 | break; |
190 | 190 | } |
191 | 191 | } |
@@ -194,146 +194,146 @@ discard block |
||
194 | 194 | function wpinv_get_prefix() { |
195 | 195 | $invoice_prefix = 'INV-'; |
196 | 196 | |
197 | - return apply_filters( 'wpinv_get_prefix', $invoice_prefix ); |
|
197 | + return apply_filters('wpinv_get_prefix', $invoice_prefix); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | function wpinv_get_business_logo() { |
201 | - $business_logo = wpinv_get_option( 'logo' ); |
|
202 | - return apply_filters( 'wpinv_get_business_logo', $business_logo ); |
|
201 | + $business_logo = wpinv_get_option('logo'); |
|
202 | + return apply_filters('wpinv_get_business_logo', $business_logo); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | function wpinv_get_business_name() { |
206 | - $name = wpinv_get_option( 'store_name', wpinv_get_blogname() ); |
|
206 | + $name = wpinv_get_option('store_name', wpinv_get_blogname()); |
|
207 | 207 | |
208 | - if ( empty( $name ) ) { |
|
208 | + if (empty($name)) { |
|
209 | 209 | $name = wpinv_get_blogname(); |
210 | 210 | } |
211 | 211 | |
212 | - return apply_filters( 'wpinv_get_business_name', $name ); |
|
212 | + return apply_filters('wpinv_get_business_name', $name); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | function wpinv_get_blogname() { |
216 | - return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
216 | + return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | function wpinv_get_admin_email() { |
220 | - $admin_email = wpinv_get_option( 'admin_email', get_option( 'admin_email' ) ); |
|
221 | - return apply_filters( 'wpinv_admin_email', $admin_email ); |
|
220 | + $admin_email = wpinv_get_option('admin_email', get_option('admin_email')); |
|
221 | + return apply_filters('wpinv_admin_email', $admin_email); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | function wpinv_get_business_website() { |
225 | - $business_website = home_url( '/' ); |
|
226 | - return apply_filters( 'wpinv_get_business_website', $business_website ); |
|
225 | + $business_website = home_url('/'); |
|
226 | + return apply_filters('wpinv_get_business_website', $business_website); |
|
227 | 227 | } |
228 | 228 | |
229 | -function wpinv_get_terms_text( $invoice_id = 0 ) { |
|
229 | +function wpinv_get_terms_text($invoice_id = 0) { |
|
230 | 230 | $terms_text = ''; |
231 | - return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id ); |
|
231 | + return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | function wpinv_get_business_footer() { |
235 | - $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>'; |
|
236 | - $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link ); |
|
237 | - return apply_filters( 'wpinv_get_business_footer', $business_footer ); |
|
235 | + $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>'; |
|
236 | + $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link); |
|
237 | + return apply_filters('wpinv_get_business_footer', $business_footer); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | function wpinv_checkout_required_fields() { |
241 | 241 | $required_fields = array(); |
242 | 242 | |
243 | 243 | // Let payment gateways and other extensions determine if address fields should be required |
244 | - $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
|
244 | + $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes()); |
|
245 | 245 | |
246 | - if ( $require_billing_details ) { |
|
247 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
246 | + if ($require_billing_details) { |
|
247 | + if ((bool) wpinv_get_option('fname_mandatory')) { |
|
248 | 248 | $required_fields['first_name'] = array( |
249 | 249 | 'error_id' => 'invalid_first_name', |
250 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ), |
|
250 | + 'error_message' => __('Please enter your first name', 'invoicing'), |
|
251 | 251 | ); |
252 | 252 | } |
253 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
253 | + if ((bool) wpinv_get_option('address_mandatory')) { |
|
254 | 254 | $required_fields['address'] = array( |
255 | 255 | 'error_id' => 'invalid_address', |
256 | - 'error_message' => __( 'Please enter your address', 'invoicing' ), |
|
256 | + 'error_message' => __('Please enter your address', 'invoicing'), |
|
257 | 257 | ); |
258 | 258 | } |
259 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
259 | + if ((bool) wpinv_get_option('city_mandatory')) { |
|
260 | 260 | $required_fields['city'] = array( |
261 | 261 | 'error_id' => 'invalid_city', |
262 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ), |
|
262 | + 'error_message' => __('Please enter your billing city', 'invoicing'), |
|
263 | 263 | ); |
264 | 264 | } |
265 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
265 | + if ((bool) wpinv_get_option('state_mandatory')) { |
|
266 | 266 | $required_fields['state'] = array( |
267 | 267 | 'error_id' => 'invalid_state', |
268 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ), |
|
268 | + 'error_message' => __('Please enter billing state / province', 'invoicing'), |
|
269 | 269 | ); |
270 | 270 | } |
271 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
271 | + if ((bool) wpinv_get_option('country_mandatory')) { |
|
272 | 272 | $required_fields['country'] = array( |
273 | 273 | 'error_id' => 'invalid_country', |
274 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ), |
|
274 | + 'error_message' => __('Please select your billing country', 'invoicing'), |
|
275 | 275 | ); |
276 | 276 | } |
277 | 277 | } |
278 | 278 | |
279 | - return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
|
279 | + return apply_filters('wpinv_checkout_required_fields', $required_fields); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | function wpinv_is_ssl_enforced() { |
283 | - $ssl_enforced = wpinv_get_option( 'enforce_ssl', false ); |
|
284 | - return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced ); |
|
283 | + $ssl_enforced = wpinv_get_option('enforce_ssl', false); |
|
284 | + return (bool) apply_filters('wpinv_is_ssl_enforced', $ssl_enforced); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | function wpinv_schedule_event_twicedaily() { |
288 | 288 | wpinv_email_payment_reminders(); |
289 | 289 | } |
290 | -add_action( 'wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily' ); |
|
290 | +add_action('wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily'); |
|
291 | 291 | |
292 | 292 | function wpinv_require_login_to_checkout() { |
293 | - $return = wpinv_get_option( 'login_to_checkout', false ); |
|
294 | - return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return ); |
|
293 | + $return = wpinv_get_option('login_to_checkout', false); |
|
294 | + return (bool) apply_filters('wpinv_require_login_to_checkout', $return); |
|
295 | 295 | } |
296 | 296 | |
297 | -function wpinv_sequential_number_active( $type = '' ) { |
|
298 | - $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type ); |
|
299 | - if ( null !== $check ) { |
|
297 | +function wpinv_sequential_number_active($type = '') { |
|
298 | + $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type); |
|
299 | + if (null !== $check) { |
|
300 | 300 | return $check; |
301 | 301 | } |
302 | 302 | |
303 | - return wpinv_get_option( 'sequential_invoice_number' ); |
|
303 | + return wpinv_get_option('sequential_invoice_number'); |
|
304 | 304 | } |
305 | 305 | |
306 | -function wpinv_switch_to_locale( $locale = null ) { |
|
306 | +function wpinv_switch_to_locale($locale = null) { |
|
307 | 307 | global $invoicing, $wpi_switch_locale; |
308 | 308 | |
309 | - if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) { |
|
310 | - $locale = empty( $locale ) ? get_locale() : $locale; |
|
309 | + if (!empty($invoicing) && function_exists('switch_to_locale')) { |
|
310 | + $locale = empty($locale) ? get_locale() : $locale; |
|
311 | 311 | |
312 | - switch_to_locale( $locale ); |
|
312 | + switch_to_locale($locale); |
|
313 | 313 | |
314 | 314 | $wpi_switch_locale = $locale; |
315 | 315 | |
316 | - add_filter( 'plugin_locale', 'get_locale' ); |
|
316 | + add_filter('plugin_locale', 'get_locale'); |
|
317 | 317 | |
318 | 318 | $invoicing->load_textdomain(); |
319 | 319 | |
320 | - do_action( 'wpinv_switch_to_locale', $locale ); |
|
320 | + do_action('wpinv_switch_to_locale', $locale); |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | |
324 | 324 | function wpinv_restore_locale() { |
325 | 325 | global $invoicing, $wpi_switch_locale; |
326 | 326 | |
327 | - if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) { |
|
327 | + if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) { |
|
328 | 328 | restore_previous_locale(); |
329 | 329 | |
330 | 330 | $wpi_switch_locale = null; |
331 | 331 | |
332 | - remove_filter( 'plugin_locale', 'get_locale' ); |
|
332 | + remove_filter('plugin_locale', 'get_locale'); |
|
333 | 333 | |
334 | 334 | $invoicing->load_textdomain(); |
335 | 335 | |
336 | - do_action( 'wpinv_restore_locale' ); |
|
336 | + do_action('wpinv_restore_locale'); |
|
337 | 337 | } |
338 | 338 | } |
339 | 339 | |
@@ -341,26 +341,26 @@ discard block |
||
341 | 341 | * Returns the default form's id. |
342 | 342 | */ |
343 | 343 | function wpinv_get_default_payment_form() { |
344 | - $form = get_option( 'wpinv_default_payment_form' ); |
|
344 | + $form = get_option('wpinv_default_payment_form'); |
|
345 | 345 | |
346 | - if ( empty( $form ) || 'publish' != get_post_status( $form ) ) { |
|
346 | + if (empty($form) || 'publish' != get_post_status($form)) { |
|
347 | 347 | $form = wp_insert_post( |
348 | 348 | array( |
349 | 349 | 'post_type' => 'wpi_payment_form', |
350 | - 'post_title' => __( 'Checkout (default)', 'invoicing' ), |
|
350 | + 'post_title' => __('Checkout (default)', 'invoicing'), |
|
351 | 351 | 'post_status' => 'publish', |
352 | 352 | 'meta_input' => array( |
353 | - 'wpinv_form_elements' => wpinv_get_data( 'default-payment-form' ), |
|
353 | + 'wpinv_form_elements' => wpinv_get_data('default-payment-form'), |
|
354 | 354 | 'wpinv_form_items' => array(), |
355 | 355 | ), |
356 | 356 | ) |
357 | 357 | ); |
358 | 358 | |
359 | - update_option( 'wpinv_default_payment_form', $form ); |
|
359 | + update_option('wpinv_default_payment_form', $form); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | // WPML support. |
363 | - $form = apply_filters( 'wpml_object_id', $form, 'wpi_payment_form', true ); |
|
363 | + $form = apply_filters('wpml_object_id', $form, 'wpi_payment_form', true); |
|
364 | 364 | return $form; |
365 | 365 | } |
366 | 366 | |
@@ -369,19 +369,19 @@ discard block |
||
369 | 369 | * |
370 | 370 | * @param int $payment_form |
371 | 371 | */ |
372 | -function getpaid_get_payment_form_elements( $payment_form ) { |
|
372 | +function getpaid_get_payment_form_elements($payment_form) { |
|
373 | 373 | |
374 | - if ( empty( $payment_form ) ) { |
|
375 | - return wpinv_get_data( 'sample-payment-form' ); |
|
374 | + if (empty($payment_form)) { |
|
375 | + return wpinv_get_data('sample-payment-form'); |
|
376 | 376 | } |
377 | 377 | |
378 | - $form_elements = get_post_meta( $payment_form, 'wpinv_form_elements', true ); |
|
378 | + $form_elements = get_post_meta($payment_form, 'wpinv_form_elements', true); |
|
379 | 379 | |
380 | - if ( is_array( $form_elements ) ) { |
|
380 | + if (is_array($form_elements)) { |
|
381 | 381 | return $form_elements; |
382 | 382 | } |
383 | 383 | |
384 | - return wpinv_get_data( 'sample-payment-form' ); |
|
384 | + return wpinv_get_data('sample-payment-form'); |
|
385 | 385 | |
386 | 386 | } |
387 | 387 | |
@@ -390,65 +390,65 @@ discard block |
||
390 | 390 | * |
391 | 391 | * @param int $payment_form |
392 | 392 | */ |
393 | -function gepaid_get_form_items( $id ) { |
|
394 | - $form = new GetPaid_Payment_Form( $id ); |
|
393 | +function gepaid_get_form_items($id) { |
|
394 | + $form = new GetPaid_Payment_Form($id); |
|
395 | 395 | |
396 | 396 | // Is this a default form? |
397 | - if ( $form->is_default() ) { |
|
397 | + if ($form->is_default()) { |
|
398 | 398 | return array(); |
399 | 399 | } |
400 | 400 | |
401 | - return $form->get_items( 'view', 'arrays' ); |
|
401 | + return $form->get_items('view', 'arrays'); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | /** |
405 | 405 | * Trims each line in a paragraph. |
406 | 406 | * |
407 | 407 | */ |
408 | -function gepaid_trim_lines( $content ) { |
|
409 | - return implode( "\n", array_map( 'trim', explode( "\n", $content ) ) ); |
|
408 | +function gepaid_trim_lines($content) { |
|
409 | + return implode("\n", array_map('trim', explode("\n", $content))); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | |
413 | -function wpinv_add_elementor_widget_categories( $elements_manager ) { |
|
413 | +function wpinv_add_elementor_widget_categories($elements_manager) { |
|
414 | 414 | $elements_manager->add_category( |
415 | 415 | 'getpaid', |
416 | 416 | array( |
417 | - 'title' => esc_html__( 'GetPaid', 'invoicing' ), |
|
417 | + 'title' => esc_html__('GetPaid', 'invoicing'), |
|
418 | 418 | 'icon' => 'fa fa-plug', |
419 | 419 | ) |
420 | 420 | ); |
421 | 421 | } |
422 | -add_filter( 'elementor/elements/categories_registered', 'wpinv_add_elementor_widget_categories' ); |
|
422 | +add_filter('elementor/elements/categories_registered', 'wpinv_add_elementor_widget_categories'); |
|
423 | 423 | |
424 | -function wpinv_alter_elementor_widget_config( $config ) { |
|
424 | +function wpinv_alter_elementor_widget_config($config) { |
|
425 | 425 | |
426 | - if ( ! empty( $config['initial_document']['widgets'] ) ) { |
|
427 | - foreach ( $config['initial_document']['widgets'] as $key => $widget ) { |
|
428 | - if ( substr( $key, 0, 16 ) === 'wp-widget-wpinv_' || $key === 'wp-widget-getpaid' ) { |
|
429 | - $config['initial_document']['widgets'][ $key ]['categories'][] = 'getpaid'; |
|
430 | - $config['initial_document']['widgets'][ $key ]['hide_on_search'] = false; |
|
431 | - $config['initial_document']['widgets'][ $key ]['icon'] = 'eicon-globe'; //@todo if no icons use on page then font-awesome is not loaded, wif we can fifure out how to force load we can use icons. <i class="fas fa-globe-americas"></i><i class="fa-solid fa-earth-americas"></i> |
|
426 | + if (!empty($config['initial_document']['widgets'])) { |
|
427 | + foreach ($config['initial_document']['widgets'] as $key => $widget) { |
|
428 | + if (substr($key, 0, 16) === 'wp-widget-wpinv_' || $key === 'wp-widget-getpaid') { |
|
429 | + $config['initial_document']['widgets'][$key]['categories'][] = 'getpaid'; |
|
430 | + $config['initial_document']['widgets'][$key]['hide_on_search'] = false; |
|
431 | + $config['initial_document']['widgets'][$key]['icon'] = 'eicon-globe'; //@todo if no icons use on page then font-awesome is not loaded, wif we can fifure out how to force load we can use icons. <i class="fas fa-globe-americas"></i><i class="fa-solid fa-earth-americas"></i> |
|
432 | 432 | } |
433 | 433 | } |
434 | 434 | } |
435 | 435 | |
436 | 436 | return $config; |
437 | 437 | } |
438 | -add_filter( 'elementor/editor/localize_settings', 'wpinv_alter_elementor_widget_config' ); |
|
438 | +add_filter('elementor/editor/localize_settings', 'wpinv_alter_elementor_widget_config'); |
|
439 | 439 | |
440 | 440 | function wpinv_get_report_graphs() { |
441 | 441 | |
442 | 442 | return apply_filters( |
443 | 443 | 'getpaid_report_graphs', |
444 | 444 | array( |
445 | - 'sales' => __( 'Earnings', 'invoicing' ), |
|
446 | - 'refunds' => __( 'Refunds', 'invoicing' ), |
|
447 | - 'tax' => __( 'Taxes', 'invoicing' ), |
|
448 | - 'fees' => __( 'Fees', 'invoicing' ), |
|
449 | - 'discount' => __( 'Discounts', 'invoicing' ), |
|
450 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
451 | - 'items' => __( 'Purchased Items', 'invoicing' ), |
|
445 | + 'sales' => __('Earnings', 'invoicing'), |
|
446 | + 'refunds' => __('Refunds', 'invoicing'), |
|
447 | + 'tax' => __('Taxes', 'invoicing'), |
|
448 | + 'fees' => __('Fees', 'invoicing'), |
|
449 | + 'discount' => __('Discounts', 'invoicing'), |
|
450 | + 'invoices' => __('Invoices', 'invoicing'), |
|
451 | + 'items' => __('Purchased Items', 'invoicing'), |
|
452 | 452 | ) |
453 | 453 | ); |
454 | 454 |
@@ -7,15 +7,15 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( ! defined( 'WPINC' ) ) { |
|
10 | +if (!defined('WPINC')) { |
|
11 | 11 | exit; |
12 | 12 | } |
13 | 13 | |
14 | 14 | |
15 | 15 | function wpinv_get_default_country() { |
16 | - $country = wpinv_get_option( 'default_country', 'UK' ); |
|
16 | + $country = wpinv_get_option('default_country', 'UK'); |
|
17 | 17 | |
18 | - return apply_filters( 'wpinv_default_country', $country ); |
|
18 | + return apply_filters('wpinv_default_country', $country); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @return string |
25 | 25 | */ |
26 | -function getpaid_get_ip_country( $ip_address = '' ) { |
|
27 | - $country = GetPaid_Geolocation::geolocate_ip( $ip_address, true ); |
|
26 | +function getpaid_get_ip_country($ip_address = '') { |
|
27 | + $country = GetPaid_Geolocation::geolocate_ip($ip_address, true); |
|
28 | 28 | return $country['country']; |
29 | 29 | } |
30 | 30 | |
@@ -34,59 +34,59 @@ discard block |
||
34 | 34 | * @param string $country The country code to sanitize |
35 | 35 | * @return array |
36 | 36 | */ |
37 | -function wpinv_sanitize_country( $country ) { |
|
37 | +function wpinv_sanitize_country($country) { |
|
38 | 38 | |
39 | 39 | // Enure the country is specified |
40 | - if ( empty( $country ) ) { |
|
40 | + if (empty($country)) { |
|
41 | 41 | $country = wpinv_get_default_country(); |
42 | 42 | } |
43 | - return trim( wpinv_utf8_strtoupper( $country ) ); |
|
43 | + return trim(wpinv_utf8_strtoupper($country)); |
|
44 | 44 | |
45 | 45 | } |
46 | 46 | |
47 | -function wpinv_is_base_country( $country ) { |
|
47 | +function wpinv_is_base_country($country) { |
|
48 | 48 | $base_country = wpinv_get_default_country(); |
49 | 49 | |
50 | - if ( $base_country === 'UK' ) { |
|
50 | + if ($base_country === 'UK') { |
|
51 | 51 | $base_country = 'GB'; |
52 | 52 | } |
53 | - if ( $country == 'UK' ) { |
|
53 | + if ($country == 'UK') { |
|
54 | 54 | $country = 'GB'; |
55 | 55 | } |
56 | 56 | |
57 | - return ( $country && $country === $base_country ) ? true : false; |
|
57 | + return ($country && $country === $base_country) ? true : false; |
|
58 | 58 | } |
59 | 59 | |
60 | -function wpinv_country_name( $country_code = '' ) { |
|
60 | +function wpinv_country_name($country_code = '') { |
|
61 | 61 | $countries = wpinv_get_country_list(); |
62 | 62 | $country_code = $country_code == 'UK' ? 'GB' : $country_code; |
63 | - $country = isset( $countries[ $country_code ] ) ? $countries[ $country_code ] : $country_code; |
|
63 | + $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code; |
|
64 | 64 | |
65 | - return apply_filters( 'wpinv_country_name', $country, $country_code ); |
|
65 | + return apply_filters('wpinv_country_name', $country, $country_code); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | function wpinv_get_default_state() { |
69 | - $state = wpinv_get_option( 'default_state', '' ); |
|
69 | + $state = wpinv_get_option('default_state', ''); |
|
70 | 70 | |
71 | - return apply_filters( 'wpinv_default_state', $state ); |
|
71 | + return apply_filters('wpinv_default_state', $state); |
|
72 | 72 | } |
73 | 73 | |
74 | -function wpinv_state_name( $state_code = '', $country_code = '' ) { |
|
74 | +function wpinv_state_name($state_code = '', $country_code = '') { |
|
75 | 75 | $state = $state_code; |
76 | 76 | |
77 | - if ( ! empty( $country_code ) ) { |
|
78 | - $states = wpinv_get_country_states( $country_code ); |
|
77 | + if (!empty($country_code)) { |
|
78 | + $states = wpinv_get_country_states($country_code); |
|
79 | 79 | |
80 | - $state = ! empty( $states ) && isset( $states[ $state_code ] ) ? $states[ $state_code ] : $state; |
|
80 | + $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state; |
|
81 | 81 | } |
82 | 82 | |
83 | - return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code ); |
|
83 | + return apply_filters('wpinv_state_name', $state, $state_code, $country_code); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | function wpinv_store_address() { |
87 | - $address = wpinv_get_option( 'store_address', '' ); |
|
87 | + $address = wpinv_get_option('store_address', ''); |
|
88 | 88 | |
89 | - return apply_filters( 'wpinv_store_address', $address ); |
|
89 | + return apply_filters('wpinv_store_address', $address); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,24 +94,24 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @param WPInv_Invoice $invoice |
96 | 96 | */ |
97 | -function getpaid_maybe_add_default_address( &$invoice ) { |
|
97 | +function getpaid_maybe_add_default_address(&$invoice) { |
|
98 | 98 | |
99 | 99 | $user_id = $invoice->get_user_id(); |
100 | 100 | |
101 | 101 | // Abort if the invoice belongs to no one. |
102 | - if ( empty( $user_id ) ) { |
|
102 | + if (empty($user_id)) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Fill in defaults whenever necessary. |
107 | - foreach ( wpinv_get_user_address( $user_id ) as $key => $value ) { |
|
107 | + foreach (wpinv_get_user_address($user_id) as $key => $value) { |
|
108 | 108 | |
109 | - if ( is_callable( $invoice, "get_$key" ) ) { |
|
110 | - $current = call_user_func( array( $invoice, "get_$key" ) ); |
|
109 | + if (is_callable($invoice, "get_$key")) { |
|
110 | + $current = call_user_func(array($invoice, "get_$key")); |
|
111 | 111 | |
112 | - if ( empty( $current ) ) { |
|
112 | + if (empty($current)) { |
|
113 | 113 | $method = "set_$key"; |
114 | - $invoice->$method( $value ); |
|
114 | + $invoice->$method($value); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | } |
@@ -128,22 +128,22 @@ discard block |
||
128 | 128 | $address_fields = apply_filters( |
129 | 129 | 'getpaid_user_address_fields', |
130 | 130 | array( |
131 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
132 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
133 | - 'address' => __( 'Address', 'invoicing' ), |
|
134 | - 'city' => __( 'City', 'invoicing' ), |
|
135 | - 'country' => __( 'Country', 'invoicing' ), |
|
136 | - 'state' => __( 'State', 'invoicing' ), |
|
137 | - 'zip' => __( 'Zip/Postal Code', 'invoicing' ), |
|
138 | - 'phone' => __( 'Phone Number', 'invoicing' ), |
|
139 | - 'company' => __( 'Company', 'invoicing' ), |
|
140 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
141 | - 'vat_number' => __( 'VAT Number', 'invoicing' ), |
|
131 | + 'first_name' => __('First Name', 'invoicing'), |
|
132 | + 'last_name' => __('Last Name', 'invoicing'), |
|
133 | + 'address' => __('Address', 'invoicing'), |
|
134 | + 'city' => __('City', 'invoicing'), |
|
135 | + 'country' => __('Country', 'invoicing'), |
|
136 | + 'state' => __('State', 'invoicing'), |
|
137 | + 'zip' => __('Zip/Postal Code', 'invoicing'), |
|
138 | + 'phone' => __('Phone Number', 'invoicing'), |
|
139 | + 'company' => __('Company', 'invoicing'), |
|
140 | + 'company_id' => __('Company ID', 'invoicing'), |
|
141 | + 'vat_number' => __('VAT Number', 'invoicing'), |
|
142 | 142 | ) |
143 | 143 | ); |
144 | 144 | |
145 | - if ( ! wpinv_use_taxes() && isset( $address_fields['vat_number'] ) ) { |
|
146 | - unset( $address_fields['vat_number'] ); |
|
145 | + if (!wpinv_use_taxes() && isset($address_fields['vat_number'])) { |
|
146 | + unset($address_fields['vat_number']); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return $address_fields; |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @return bool |
156 | 156 | */ |
157 | -function getpaid_is_address_field_whitelisted( $key ) { |
|
158 | - return array_key_exists( $key, getpaid_user_address_fields() ); |
|
157 | +function getpaid_is_address_field_whitelisted($key) { |
|
158 | + return array_key_exists($key, getpaid_user_address_fields()); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -165,30 +165,30 @@ discard block |
||
165 | 165 | * |
166 | 166 | * @param WPInv_Invoice $invoice |
167 | 167 | */ |
168 | -function getpaid_save_invoice_user_address( $invoice ) { |
|
168 | +function getpaid_save_invoice_user_address($invoice) { |
|
169 | 169 | |
170 | 170 | // Retrieve the invoice. |
171 | - $invoice = wpinv_get_invoice( $invoice ); |
|
171 | + $invoice = wpinv_get_invoice($invoice); |
|
172 | 172 | |
173 | 173 | // Abort if it does not exist. |
174 | - if ( empty( $invoice ) || $invoice->is_renewal() ) { |
|
174 | + if (empty($invoice) || $invoice->is_renewal()) { |
|
175 | 175 | return; |
176 | 176 | } |
177 | 177 | |
178 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
178 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
179 | 179 | |
180 | - if ( is_callable( array( $invoice, "get_$field" ) ) ) { |
|
181 | - $value = call_user_func( array( $invoice, "get_$field" ) ); |
|
180 | + if (is_callable(array($invoice, "get_$field"))) { |
|
181 | + $value = call_user_func(array($invoice, "get_$field")); |
|
182 | 182 | |
183 | 183 | // Only save if it is not empty. |
184 | - if ( ! empty( $value ) ) { |
|
185 | - update_user_meta( $invoice->get_user_id(), '_wpinv_' . $field, $value ); |
|
184 | + if (!empty($value)) { |
|
185 | + update_user_meta($invoice->get_user_id(), '_wpinv_' . $field, $value); |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | 190 | } |
191 | -add_action( 'getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address' ); |
|
191 | +add_action('getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address'); |
|
192 | 192 | |
193 | 193 | /** |
194 | 194 | * Retrieves a saved user address. |
@@ -197,14 +197,14 @@ discard block |
||
197 | 197 | * @param bool $with_default Whether or not we should use the default country and state. |
198 | 198 | * @return array |
199 | 199 | */ |
200 | -function wpinv_get_user_address( $user_id = 0, $with_default = true ) { |
|
200 | +function wpinv_get_user_address($user_id = 0, $with_default = true) { |
|
201 | 201 | |
202 | 202 | // Prepare the user id. |
203 | - $user_id = empty( $user_id ) ? get_current_user_id() : $user_id; |
|
204 | - $user_info = get_userdata( $user_id ); |
|
203 | + $user_id = empty($user_id) ? get_current_user_id() : $user_id; |
|
204 | + $user_info = get_userdata($user_id); |
|
205 | 205 | |
206 | 206 | // Abort if non exists. |
207 | - if ( empty( $user_info ) ) { |
|
207 | + if (empty($user_info)) { |
|
208 | 208 | return array(); |
209 | 209 | } |
210 | 210 | |
@@ -214,13 +214,13 @@ discard block |
||
214 | 214 | 'email' => $user_info->user_email, |
215 | 215 | ); |
216 | 216 | |
217 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
218 | - $address[ $field ] = getpaid_get_user_address_field( $user_id, $field ); |
|
217 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
218 | + $address[$field] = getpaid_get_user_address_field($user_id, $field); |
|
219 | 219 | } |
220 | 220 | |
221 | - $address = array_filter( $address ); |
|
221 | + $address = array_filter($address); |
|
222 | 222 | |
223 | - if ( ! $with_default ) { |
|
223 | + if (!$with_default) { |
|
224 | 224 | return $address; |
225 | 225 | } |
226 | 226 | |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | 'country' => wpinv_get_default_country(), |
232 | 232 | ); |
233 | 233 | |
234 | - return getpaid_array_merge_if_empty( $address, $defaults ); |
|
234 | + return getpaid_array_merge_if_empty($address, $defaults); |
|
235 | 235 | |
236 | 236 | } |
237 | 237 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | * @param string $field The field to use. |
243 | 243 | * @return string|null |
244 | 244 | */ |
245 | -function getpaid_get_user_address_field( $user_id, $field ) { |
|
245 | +function getpaid_get_user_address_field($user_id, $field) { |
|
246 | 246 | |
247 | 247 | $prefixes = array( |
248 | 248 | '_wpinv_', |
@@ -250,15 +250,15 @@ discard block |
||
250 | 250 | '', |
251 | 251 | ); |
252 | 252 | |
253 | - foreach ( $prefixes as $prefix ) { |
|
253 | + foreach ($prefixes as $prefix) { |
|
254 | 254 | |
255 | 255 | // Meta table. |
256 | - $value = get_user_meta( $user_id, $prefix . $field, true ); |
|
256 | + $value = get_user_meta($user_id, $prefix . $field, true); |
|
257 | 257 | |
258 | 258 | // UWP table. |
259 | - $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value; |
|
259 | + $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value; |
|
260 | 260 | |
261 | - if ( ! empty( $value ) ) { |
|
261 | + if (!empty($value)) { |
|
262 | 262 | return $value; |
263 | 263 | } |
264 | 264 | } |
@@ -274,16 +274,16 @@ discard block |
||
274 | 274 | * @param string $return What to return. |
275 | 275 | * @return array |
276 | 276 | */ |
277 | -function wpinv_get_continents( $return = 'all' ) { |
|
277 | +function wpinv_get_continents($return = 'all') { |
|
278 | 278 | |
279 | - $continents = wpinv_get_data( 'continents' ); |
|
279 | + $continents = wpinv_get_data('continents'); |
|
280 | 280 | |
281 | - switch ( $return ) { |
|
281 | + switch ($return) { |
|
282 | 282 | case 'name': |
283 | - return wp_list_pluck( $continents, 'name' ); |
|
283 | + return wp_list_pluck($continents, 'name'); |
|
284 | 284 | break; |
285 | 285 | case 'countries': |
286 | - return wp_list_pluck( $continents, 'countries' ); |
|
286 | + return wp_list_pluck($continents, 'countries'); |
|
287 | 287 | break; |
288 | 288 | default: |
289 | 289 | return $continents; |
@@ -299,12 +299,12 @@ discard block |
||
299 | 299 | * @param string $country Country code. If no code is specified, defaults to the default country. |
300 | 300 | * @return string |
301 | 301 | */ |
302 | -function wpinv_get_continent_code_for_country( $country = false ) { |
|
302 | +function wpinv_get_continent_code_for_country($country = false) { |
|
303 | 303 | |
304 | - $country = wpinv_sanitize_country( $country ); |
|
304 | + $country = wpinv_sanitize_country($country); |
|
305 | 305 | |
306 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
307 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
306 | + foreach (wpinv_get_continents('countries') as $continent_code => $countries) { |
|
307 | + if (false !== array_search($country, $countries, true)) { |
|
308 | 308 | return $continent_code; |
309 | 309 | } |
310 | 310 | } |
@@ -320,13 +320,13 @@ discard block |
||
320 | 320 | * @param string $country Country code. If no code is specified, defaults to the default country. |
321 | 321 | * @return array |
322 | 322 | */ |
323 | -function wpinv_get_country_calling_code( $country = null ) { |
|
323 | +function wpinv_get_country_calling_code($country = null) { |
|
324 | 324 | |
325 | - $country = wpinv_sanitize_country( $country ); |
|
326 | - $codes = wpinv_get_data( 'phone-codes' ); |
|
327 | - $code = isset( $codes[ $country ] ) ? $codes[ $country ] : ''; |
|
325 | + $country = wpinv_sanitize_country($country); |
|
326 | + $codes = wpinv_get_data('phone-codes'); |
|
327 | + $code = isset($codes[$country]) ? $codes[$country] : ''; |
|
328 | 328 | |
329 | - if ( is_array( $code ) ) { |
|
329 | + if (is_array($code)) { |
|
330 | 330 | return $code[0]; |
331 | 331 | } |
332 | 332 | return $code; |
@@ -339,8 +339,8 @@ discard block |
||
339 | 339 | * @param bool $first_empty Whether or not the first item in the list should be empty |
340 | 340 | * @return array |
341 | 341 | */ |
342 | -function wpinv_get_country_list( $first_empty = false ) { |
|
343 | - return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty ); |
|
342 | +function wpinv_get_country_list($first_empty = false) { |
|
343 | + return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | /** |
@@ -350,22 +350,22 @@ discard block |
||
350 | 350 | * @param bool $first_empty Whether or not the first item in the list should be empty |
351 | 351 | * @return array |
352 | 352 | */ |
353 | -function wpinv_get_country_states( $country = null, $first_empty = false ) { |
|
353 | +function wpinv_get_country_states($country = null, $first_empty = false) { |
|
354 | 354 | |
355 | 355 | // Prepare the country. |
356 | - $country = wpinv_sanitize_country( $country ); |
|
356 | + $country = wpinv_sanitize_country($country); |
|
357 | 357 | |
358 | 358 | // Fetch all states. |
359 | - $all_states = wpinv_get_data( 'states' ); |
|
359 | + $all_states = wpinv_get_data('states'); |
|
360 | 360 | |
361 | 361 | // Fetch the specified country's states. |
362 | - $states = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array(); |
|
363 | - $states = apply_filters( "wpinv_{$country}_states", $states ); |
|
364 | - $states = apply_filters( 'wpinv_country_states', $states, $country ); |
|
362 | + $states = isset($all_states[$country]) ? $all_states[$country] : array(); |
|
363 | + $states = apply_filters("wpinv_{$country}_states", $states); |
|
364 | + $states = apply_filters('wpinv_country_states', $states, $country); |
|
365 | 365 | |
366 | - asort( $states ); |
|
366 | + asort($states); |
|
367 | 367 | |
368 | - return wpinv_maybe_add_empty_option( $states, $first_empty ); |
|
368 | + return wpinv_maybe_add_empty_option($states, $first_empty); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | /** |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | * @return array |
376 | 376 | */ |
377 | 377 | function wpinv_get_us_states_list() { |
378 | - return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) ); |
|
378 | + return apply_filters('wpinv_usa_states', wpinv_get_country_states('US')); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | /** |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | * @return array |
386 | 386 | */ |
387 | 387 | function wpinv_get_canada_states_list() { |
388 | - return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) ); |
|
388 | + return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA')); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | /** |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | * @return array |
396 | 396 | */ |
397 | 397 | function wpinv_get_australia_states_list() { |
398 | - return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) ); |
|
398 | + return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU')); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | /** |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | * @return array |
406 | 406 | */ |
407 | 407 | function wpinv_get_bangladesh_states_list() { |
408 | - return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) ); |
|
408 | + return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD')); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | * @return array |
416 | 416 | */ |
417 | 417 | function wpinv_get_brazil_states_list() { |
418 | - return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) ); |
|
418 | + return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR')); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | /** |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | * @return array |
426 | 426 | */ |
427 | 427 | function wpinv_get_bulgaria_states_list() { |
428 | - return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) ); |
|
428 | + return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG')); |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | /** |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | * @return array |
436 | 436 | */ |
437 | 437 | function wpinv_get_hong_kong_states_list() { |
438 | - return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) ); |
|
438 | + return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK')); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | /** |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | * @return array |
446 | 446 | */ |
447 | 447 | function wpinv_get_hungary_states_list() { |
448 | - return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) ); |
|
448 | + return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU')); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | /** |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | * @return array |
456 | 456 | */ |
457 | 457 | function wpinv_get_japan_states_list() { |
458 | - return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) ); |
|
458 | + return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP')); |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | /** |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | * @return array |
466 | 466 | */ |
467 | 467 | function wpinv_get_china_states_list() { |
468 | - return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) ); |
|
468 | + return apply_filters('wpinv_china_states', wpinv_get_country_states('CN')); |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | /** |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | * @return array |
476 | 476 | */ |
477 | 477 | function wpinv_get_new_zealand_states_list() { |
478 | - return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) ); |
|
478 | + return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ')); |
|
479 | 479 | } |
480 | 480 | |
481 | 481 | /** |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | * @return array |
486 | 486 | */ |
487 | 487 | function wpinv_get_peru_states_list() { |
488 | - return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) ); |
|
488 | + return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE')); |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | /** |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | * @return array |
496 | 496 | */ |
497 | 497 | function wpinv_get_indonesia_states_list() { |
498 | - return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) ); |
|
498 | + return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID')); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | /** |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | * @return array |
506 | 506 | */ |
507 | 507 | function wpinv_get_india_states_list() { |
508 | - return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) ); |
|
508 | + return apply_filters('wpinv_india_states', wpinv_get_country_states('IN')); |
|
509 | 509 | } |
510 | 510 | |
511 | 511 | /** |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | * @return array |
516 | 516 | */ |
517 | 517 | function wpinv_get_iran_states_list() { |
518 | - return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) ); |
|
518 | + return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR')); |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | /** |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | * @return array |
526 | 526 | */ |
527 | 527 | function wpinv_get_italy_states_list() { |
528 | - return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) ); |
|
528 | + return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT')); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | /** |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | * @return array |
536 | 536 | */ |
537 | 537 | function wpinv_get_malaysia_states_list() { |
538 | - return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) ); |
|
538 | + return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY')); |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | /** |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | * @return array |
546 | 546 | */ |
547 | 547 | function wpinv_get_mexico_states_list() { |
548 | - return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) ); |
|
548 | + return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX')); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | /** |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | * @return array |
556 | 556 | */ |
557 | 557 | function wpinv_get_nepal_states_list() { |
558 | - return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) ); |
|
558 | + return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP')); |
|
559 | 559 | } |
560 | 560 | |
561 | 561 | /** |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | * @return array |
566 | 566 | */ |
567 | 567 | function wpinv_get_south_africa_states_list() { |
568 | - return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) ); |
|
568 | + return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA')); |
|
569 | 569 | } |
570 | 570 | |
571 | 571 | /** |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | * @return array |
576 | 576 | */ |
577 | 577 | function wpinv_get_thailand_states_list() { |
578 | - return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) ); |
|
578 | + return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH')); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | /** |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | * @return array |
586 | 586 | */ |
587 | 587 | function wpinv_get_turkey_states_list() { |
588 | - return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) ); |
|
588 | + return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR')); |
|
589 | 589 | } |
590 | 590 | |
591 | 591 | /** |
@@ -595,31 +595,31 @@ discard block |
||
595 | 595 | * @return array |
596 | 596 | */ |
597 | 597 | function wpinv_get_spain_states_list() { |
598 | - return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) ); |
|
598 | + return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES')); |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | function wpinv_get_states_field() { |
602 | - if ( empty( $_POST['country'] ) ) { |
|
602 | + if (empty($_POST['country'])) { |
|
603 | 603 | $_POST['country'] = wpinv_get_default_country(); |
604 | 604 | } |
605 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
605 | + $states = wpinv_get_country_states(sanitize_text_field($_POST['country'])); |
|
606 | 606 | |
607 | - if ( ! empty( $states ) ) { |
|
608 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
607 | + if (!empty($states)) { |
|
608 | + $sanitized_field_name = sanitize_text_field($_POST['field_name']); |
|
609 | 609 | |
610 | - $class = isset( $_POST['class'] ) ? esc_attr( sanitize_text_field( $_POST['class'] ) ) : ''; |
|
610 | + $class = isset($_POST['class']) ? esc_attr(sanitize_text_field($_POST['class'])) : ''; |
|
611 | 611 | $class .= " $sanitized_field_name getpaid_js_field-state custom-select wpinv-select wpi_select2"; |
612 | 612 | |
613 | - $args = array( |
|
613 | + $args = array( |
|
614 | 614 | 'name' => $sanitized_field_name, |
615 | 615 | 'id' => $sanitized_field_name, |
616 | - 'class' => implode( ' ', array_unique( explode( ' ', $class ) ) ), |
|
617 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
616 | + 'class' => implode(' ', array_unique(explode(' ', $class))), |
|
617 | + 'options' => array_merge(array('' => ''), $states), |
|
618 | 618 | 'show_option_all' => false, |
619 | 619 | 'show_option_none' => false, |
620 | 620 | ); |
621 | 621 | |
622 | - $response = wpinv_html_select( $args ); |
|
622 | + $response = wpinv_html_select($args); |
|
623 | 623 | |
624 | 624 | } else { |
625 | 625 | $response = 'nostates'; |
@@ -628,10 +628,10 @@ discard block |
||
628 | 628 | return $response; |
629 | 629 | } |
630 | 630 | |
631 | -function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
|
632 | - $country = ! empty( $country ) ? $country : wpinv_get_default_country(); |
|
631 | +function wpinv_default_billing_country($country = '', $user_id = 0) { |
|
632 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
633 | 633 | |
634 | - return apply_filters( 'wpinv_default_billing_country', $country, $user_id ); |
|
634 | + return apply_filters('wpinv_default_billing_country', $country, $user_id); |
|
635 | 635 | } |
636 | 636 | |
637 | 637 | /** |
@@ -693,9 +693,9 @@ discard block |
||
693 | 693 | * @see `wpinv_get_invoice_address_replacements` |
694 | 694 | * @return string |
695 | 695 | */ |
696 | -function wpinv_get_full_address_format( $country = false ) { |
|
696 | +function wpinv_get_full_address_format($country = false) { |
|
697 | 697 | |
698 | - if ( empty( $country ) ) { |
|
698 | + if (empty($country)) { |
|
699 | 699 | $country = wpinv_get_default_country(); |
700 | 700 | } |
701 | 701 | |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | $formats = wpinv_get_address_formats(); |
704 | 704 | |
705 | 705 | // Get format for the specified country. |
706 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
706 | + $format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default']; |
|
707 | 707 | |
708 | 708 | /** |
709 | 709 | * Filters the address format to use on Invoices. |
@@ -715,7 +715,7 @@ discard block |
||
715 | 715 | * @param string $format The address format to use. |
716 | 716 | * @param string $country The country who's address format is being retrieved. |
717 | 717 | */ |
718 | - return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
|
718 | + return apply_filters('wpinv_get_full_address_format', $format, $country); |
|
719 | 719 | } |
720 | 720 | |
721 | 721 | /** |
@@ -726,7 +726,7 @@ discard block |
||
726 | 726 | * @param array $billing_details customer's billing details |
727 | 727 | * @return array |
728 | 728 | */ |
729 | -function wpinv_get_invoice_address_replacements( $billing_details ) { |
|
729 | +function wpinv_get_invoice_address_replacements($billing_details) { |
|
730 | 730 | |
731 | 731 | $default_args = array( |
732 | 732 | 'address' => '', |
@@ -739,15 +739,15 @@ discard block |
||
739 | 739 | 'company' => '', |
740 | 740 | ); |
741 | 741 | |
742 | - $args = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' ); |
|
742 | + $args = map_deep(wp_parse_args($billing_details, $default_args), 'trim'); |
|
743 | 743 | $state = $args['state']; |
744 | 744 | $country = $args['country']; |
745 | 745 | |
746 | 746 | // Handle full country name. |
747 | - $full_country = empty( $country ) ? $country : wpinv_country_name( $country ); |
|
747 | + $full_country = empty($country) ? $country : wpinv_country_name($country); |
|
748 | 748 | |
749 | 749 | // Handle full state name. |
750 | - $full_state = ( $country && $state ) ? wpinv_state_name( $state, $country ) : $state; |
|
750 | + $full_state = ($country && $state) ? wpinv_state_name($state, $country) : $state; |
|
751 | 751 | |
752 | 752 | $args['postcode'] = $args['zip']; |
753 | 753 | $args['name'] = $args['first_name'] . ' ' . $args['last_name']; |
@@ -765,14 +765,14 @@ discard block |
||
765 | 765 | * @param array $replacements The address replacements to use. |
766 | 766 | * @param array $billing_details The billing details to use. |
767 | 767 | */ |
768 | - $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
|
768 | + $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details); |
|
769 | 769 | |
770 | 770 | $return = array(); |
771 | 771 | |
772 | - foreach ( $replacements as $key => $value ) { |
|
773 | - $value = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : ''; |
|
774 | - $return[ '{{' . $key . '}}' ] = $value; |
|
775 | - $return[ '{{' . $key . '_upper}}' ] = wpinv_utf8_strtoupper( $value ); |
|
772 | + foreach ($replacements as $key => $value) { |
|
773 | + $value = is_scalar($value) ? trim(sanitize_text_field($value)) : ''; |
|
774 | + $return['{{' . $key . '}}'] = $value; |
|
775 | + $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value); |
|
776 | 776 | } |
777 | 777 | |
778 | 778 | return $return; |
@@ -786,6 +786,6 @@ discard block |
||
786 | 786 | * @since 1.0.14 |
787 | 787 | * @return string |
788 | 788 | */ |
789 | -function wpinv_trim_formatted_address_line( $line ) { |
|
790 | - return trim( $line, ', ' ); |
|
789 | +function wpinv_trim_formatted_address_line($line) { |
|
790 | + return trim($line, ', '); |
|
791 | 791 | } |
@@ -14,70 +14,70 @@ discard block |
||
14 | 14 | class WPInv_Ajax { |
15 | 15 | |
16 | 16 | /** |
17 | - * Hook in ajax handlers. |
|
18 | - */ |
|
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 ); |
|
22 | - self::add_ajax_events(); |
|
17 | + * Hook in ajax handlers. |
|
18 | + */ |
|
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 ); |
|
22 | + self::add_ajax_events(); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | - * Set GetPaid AJAX constant and headers. |
|
27 | - */ |
|
28 | - public static function define_ajax() { |
|
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 ); |
|
35 | - } |
|
36 | - $GLOBALS['wpdb']->hide_errors(); |
|
37 | - } |
|
26 | + * Set GetPaid AJAX constant and headers. |
|
27 | + */ |
|
28 | + public static function define_ajax() { |
|
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 ); |
|
35 | + } |
|
36 | + $GLOBALS['wpdb']->hide_errors(); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | - * Send headers for GetPaid Ajax Requests. |
|
43 | - * |
|
44 | - * @since 1.0.18 |
|
45 | - */ |
|
46 | - private static function wpinv_ajax_headers() { |
|
47 | - if ( ! headers_sent() ) { |
|
48 | - send_origin_headers(); |
|
49 | - send_nosniff_header(); |
|
50 | - nocache_headers(); |
|
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
54 | - } |
|
42 | + * Send headers for GetPaid Ajax Requests. |
|
43 | + * |
|
44 | + * @since 1.0.18 |
|
45 | + */ |
|
46 | + private static function wpinv_ajax_headers() { |
|
47 | + if ( ! headers_sent() ) { |
|
48 | + send_origin_headers(); |
|
49 | + send_nosniff_header(); |
|
50 | + nocache_headers(); |
|
51 | + header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | + header( 'X-Robots-Tag: noindex' ); |
|
53 | + status_header( 200 ); |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | - * Check for GetPaid Ajax request and fire action. |
|
59 | - */ |
|
60 | - public static function do_wpinv_ajax() { |
|
61 | - global $wp_query; |
|
58 | + * Check for GetPaid Ajax request and fire action. |
|
59 | + */ |
|
60 | + public static function do_wpinv_ajax() { |
|
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'] ) ) ); |
|
65 | - } |
|
63 | + if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | + $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
65 | + } |
|
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get( 'wpinv-ajax' ); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
70 | - self::wpinv_ajax_headers(); |
|
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
73 | - wp_die(); |
|
74 | - } |
|
69 | + if ( $action ) { |
|
70 | + self::wpinv_ajax_headers(); |
|
71 | + $action = sanitize_text_field( $action ); |
|
72 | + do_action( 'wpinv_ajax_' . $action ); |
|
73 | + wp_die(); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Hook in ajax methods. |
|
80 | - */ |
|
79 | + * Hook in ajax methods. |
|
80 | + */ |
|
81 | 81 | public static function add_ajax_events() { |
82 | 82 | |
83 | 83 | // array( 'event' => is_frontend ) |
@@ -261,11 +261,11 @@ discard block |
||
261 | 261 | check_ajax_referer( 'getpaid_form_nonce' ); |
262 | 262 | |
263 | 263 | // Is the request set up correctly? |
264 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
265 | - aui()->alert( |
|
266 | - array( |
|
267 | - 'type' => 'warning', |
|
268 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
264 | + if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
265 | + aui()->alert( |
|
266 | + array( |
|
267 | + 'type' => 'warning', |
|
268 | + 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
269 | 269 | ), |
270 | 270 | true |
271 | 271 | ); |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | } |
274 | 274 | |
275 | 275 | // Payment form or button? |
276 | - if ( ! empty( $_GET['form'] ) ) { |
|
276 | + if ( ! empty( $_GET['form'] ) ) { |
|
277 | 277 | $form = sanitize_text_field( urldecode( $_GET['form'] ) ); |
278 | 278 | |
279 | 279 | if ( false !== strpos( $form, '|' ) ) { |
@@ -326,10 +326,10 @@ discard block |
||
326 | 326 | getpaid_display_payment_form( $form ); |
327 | 327 | } |
328 | 328 | } elseif ( ! empty( $_GET['invoice'] ) ) { |
329 | - getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) ); |
|
329 | + getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) ); |
|
330 | 330 | } else { |
331 | - $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) ); |
|
332 | - getpaid_display_item_payment_form( $items ); |
|
331 | + $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) ); |
|
332 | + getpaid_display_item_payment_form( $items ); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | exit; |
@@ -649,7 +649,7 @@ discard block |
||
649 | 649 | if ( is_wp_error( $error ) ) { |
650 | 650 | $alert = $error->get_error_message(); |
651 | 651 | wp_send_json_success( compact( 'alert' ) ); |
652 | - } |
|
652 | + } |
|
653 | 653 | |
654 | 654 | // Update totals. |
655 | 655 | $invoice->recalculate_total(); |
@@ -1084,12 +1084,12 @@ discard block |
||
1084 | 1084 | } |
1085 | 1085 | |
1086 | 1086 | /** |
1087 | - * Handles file uploads. |
|
1088 | - * |
|
1089 | - * @since 1.0.0 |
|
1090 | - * @return void |
|
1091 | - */ |
|
1092 | - public static function file_upload() { |
|
1087 | + * Handles file uploads. |
|
1088 | + * |
|
1089 | + * @since 1.0.0 |
|
1090 | + * @return void |
|
1091 | + */ |
|
1092 | + public static function file_upload() { |
|
1093 | 1093 | |
1094 | 1094 | // Check nonce. |
1095 | 1095 | check_ajax_referer( 'getpaid_form_nonce' ); |
@@ -1150,7 +1150,7 @@ discard block |
||
1150 | 1150 | |
1151 | 1151 | wp_send_json_success( $response ); |
1152 | 1152 | |
1153 | - } |
|
1153 | + } |
|
1154 | 1154 | |
1155 | 1155 | } |
1156 | 1156 |
@@ -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 | |
@@ -106,36 +106,36 @@ discard block |
||
106 | 106 | 'file_upload' => true, |
107 | 107 | ); |
108 | 108 | |
109 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
110 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
111 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
109 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
110 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
111 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
112 | 112 | |
113 | - if ( $nopriv ) { |
|
114 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
115 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
116 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
113 | + if ($nopriv) { |
|
114 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
115 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
116 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
121 | 121 | public static function add_note() { |
122 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
122 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
123 | 123 | |
124 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
124 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
125 | 125 | die( -1 ); |
126 | 126 | } |
127 | 127 | |
128 | - $post_id = absint( $_POST['post_id'] ); |
|
129 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
130 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
128 | + $post_id = absint($_POST['post_id']); |
|
129 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
130 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
131 | 131 | |
132 | 132 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
133 | 133 | |
134 | - if ( $post_id > 0 ) { |
|
135 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
134 | + if ($post_id > 0) { |
|
135 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
136 | 136 | |
137 | - if ( $note_id > 0 && ! is_wp_error( $note_id ) ) { |
|
138 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
137 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
138 | + wpinv_get_invoice_note_line_item($note_id); |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
@@ -143,16 +143,16 @@ discard block |
||
143 | 143 | } |
144 | 144 | |
145 | 145 | public static function delete_note() { |
146 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
146 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
147 | 147 | |
148 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
148 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
149 | 149 | die( -1 ); |
150 | 150 | } |
151 | 151 | |
152 | - $note_id = (int)$_POST['note_id']; |
|
152 | + $note_id = (int) $_POST['note_id']; |
|
153 | 153 | |
154 | - if ( $note_id > 0 ) { |
|
155 | - wp_delete_comment( $note_id, true ); |
|
154 | + if ($note_id > 0) { |
|
155 | + wp_delete_comment($note_id, true); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | die(); |
@@ -170,34 +170,34 @@ discard block |
||
170 | 170 | public static function get_billing_details() { |
171 | 171 | |
172 | 172 | // Verify nonce. |
173 | - check_ajax_referer( 'wpinv-nonce' ); |
|
173 | + check_ajax_referer('wpinv-nonce'); |
|
174 | 174 | |
175 | 175 | // Can the user manage the plugin? |
176 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
176 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
177 | 177 | die( -1 ); |
178 | 178 | } |
179 | 179 | |
180 | 180 | // Do we have a user id? |
181 | 181 | $user_id = (int) $_GET['user_id']; |
182 | 182 | |
183 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
183 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
184 | 184 | die( -1 ); |
185 | 185 | } |
186 | 186 | |
187 | 187 | // Fetch the billing details. |
188 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
189 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
188 | + $billing_details = wpinv_get_user_address($user_id); |
|
189 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
190 | 190 | |
191 | 191 | // unset the user id and email. |
192 | - $to_ignore = array( 'user_id', 'email' ); |
|
192 | + $to_ignore = array('user_id', 'email'); |
|
193 | 193 | |
194 | - foreach ( $to_ignore as $key ) { |
|
195 | - if ( isset( $billing_details[ $key ] ) ) { |
|
196 | - unset( $billing_details[ $key ] ); |
|
194 | + foreach ($to_ignore as $key) { |
|
195 | + if (isset($billing_details[$key])) { |
|
196 | + unset($billing_details[$key]); |
|
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
200 | - wp_send_json_success( $billing_details ); |
|
200 | + wp_send_json_success($billing_details); |
|
201 | 201 | |
202 | 202 | } |
203 | 203 | |
@@ -207,47 +207,47 @@ discard block |
||
207 | 207 | public static function check_new_user_email() { |
208 | 208 | |
209 | 209 | // Verify nonce. |
210 | - check_ajax_referer( 'wpinv-nonce' ); |
|
210 | + check_ajax_referer('wpinv-nonce'); |
|
211 | 211 | |
212 | 212 | // Can the user manage the plugin? |
213 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
213 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
214 | 214 | die( -1 ); |
215 | 215 | } |
216 | 216 | |
217 | 217 | // We need an email address. |
218 | - if ( empty( $_GET['email'] ) ) { |
|
219 | - _e( "Provide the new user's email address", 'invoicing' ); |
|
218 | + if (empty($_GET['email'])) { |
|
219 | + _e("Provide the new user's email address", 'invoicing'); |
|
220 | 220 | exit; |
221 | 221 | } |
222 | 222 | |
223 | 223 | // Ensure the email is valid. |
224 | - $email = sanitize_email( $_GET['email'] ); |
|
225 | - if ( ! is_email( $email ) ) { |
|
226 | - _e( 'Invalid email address', 'invoicing' ); |
|
224 | + $email = sanitize_email($_GET['email']); |
|
225 | + if (!is_email($email)) { |
|
226 | + _e('Invalid email address', 'invoicing'); |
|
227 | 227 | exit; |
228 | 228 | } |
229 | 229 | |
230 | 230 | // And it does not exist. |
231 | - $id = email_exists( $email ); |
|
232 | - if ( $id ) { |
|
233 | - wp_send_json_success( compact( 'id' ) ); |
|
231 | + $id = email_exists($email); |
|
232 | + if ($id) { |
|
233 | + wp_send_json_success(compact('id')); |
|
234 | 234 | } |
235 | 235 | |
236 | - wp_send_json_success( true ); |
|
236 | + wp_send_json_success(true); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | public static function run_tool() { |
240 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
241 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
240 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
241 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
242 | 242 | die( -1 ); |
243 | 243 | } |
244 | 244 | |
245 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
245 | + $tool = sanitize_text_field($_POST['tool']); |
|
246 | 246 | |
247 | - do_action( 'wpinv_run_tool' ); |
|
247 | + do_action('wpinv_run_tool'); |
|
248 | 248 | |
249 | - if ( ! empty( $tool ) ) { |
|
250 | - do_action( 'wpinv_tool_' . $tool ); |
|
249 | + if (!empty($tool)) { |
|
250 | + do_action('wpinv_tool_' . $tool); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | |
@@ -258,14 +258,14 @@ discard block |
||
258 | 258 | global $getpaid_force_checkbox; |
259 | 259 | |
260 | 260 | // Check nonce. |
261 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
261 | + check_ajax_referer('getpaid_form_nonce'); |
|
262 | 262 | |
263 | 263 | // Is the request set up correctly? |
264 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
264 | + if (empty($_GET['form']) && empty($_GET['item']) && empty($_GET['invoice'])) { |
|
265 | 265 | aui()->alert( |
266 | 266 | array( |
267 | 267 | 'type' => 'warning', |
268 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
268 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
269 | 269 | ), |
270 | 270 | true |
271 | 271 | ); |
@@ -273,29 +273,29 @@ discard block |
||
273 | 273 | } |
274 | 274 | |
275 | 275 | // Payment form or button? |
276 | - if ( ! empty( $_GET['form'] ) ) { |
|
277 | - $form = sanitize_text_field( urldecode( $_GET['form'] ) ); |
|
276 | + if (!empty($_GET['form'])) { |
|
277 | + $form = sanitize_text_field(urldecode($_GET['form'])); |
|
278 | 278 | |
279 | - if ( false !== strpos( $form, '|' ) ) { |
|
280 | - $form_pos = strpos( $form, '|' ); |
|
281 | - $_items = getpaid_convert_items_to_array( substr( $form, $form_pos + 1 ) ); |
|
282 | - $form = substr( $form, 0, $form_pos ); |
|
279 | + if (false !== strpos($form, '|')) { |
|
280 | + $form_pos = strpos($form, '|'); |
|
281 | + $_items = getpaid_convert_items_to_array(substr($form, $form_pos + 1)); |
|
282 | + $form = substr($form, 0, $form_pos); |
|
283 | 283 | |
284 | 284 | // Retrieve appropriate payment form. |
285 | - $payment_form = new GetPaid_Payment_Form( $form ); |
|
286 | - $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
285 | + $payment_form = new GetPaid_Payment_Form($form); |
|
286 | + $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
287 | 287 | |
288 | 288 | $items = array(); |
289 | 289 | $item_ids = array(); |
290 | 290 | |
291 | - foreach ( $_items as $item_id => $qty ) { |
|
292 | - if ( ! in_array( $item_id, $item_ids ) ) { |
|
293 | - $item = new GetPaid_Form_Item( $item_id ); |
|
294 | - $item->set_quantity( $qty ); |
|
291 | + foreach ($_items as $item_id => $qty) { |
|
292 | + if (!in_array($item_id, $item_ids)) { |
|
293 | + $item = new GetPaid_Form_Item($item_id); |
|
294 | + $item->set_quantity($qty); |
|
295 | 295 | |
296 | - if ( 0 == $qty ) { |
|
297 | - $item->set_allow_quantities( true ); |
|
298 | - $item->set_is_required( false ); |
|
296 | + if (0 == $qty) { |
|
297 | + $item->set_allow_quantities(true); |
|
298 | + $item->set_is_required(false); |
|
299 | 299 | $getpaid_force_checkbox = true; |
300 | 300 | } |
301 | 301 | |
@@ -304,32 +304,32 @@ discard block |
||
304 | 304 | } |
305 | 305 | } |
306 | 306 | |
307 | - if ( ! $payment_form->is_default() ) { |
|
307 | + if (!$payment_form->is_default()) { |
|
308 | 308 | |
309 | - foreach ( $payment_form->get_items() as $item ) { |
|
310 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
309 | + foreach ($payment_form->get_items() as $item) { |
|
310 | + if (!in_array($item->get_id(), $item_ids)) { |
|
311 | 311 | $item_ids[] = $item->get_id(); |
312 | 312 | $items[] = $item; |
313 | 313 | } |
314 | 314 | } |
315 | 315 | } |
316 | 316 | |
317 | - $payment_form->set_items( $items ); |
|
318 | - $extra_items = esc_attr( getpaid_convert_items_to_string( $_items ) ); |
|
319 | - $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items ); |
|
317 | + $payment_form->set_items($items); |
|
318 | + $extra_items = esc_attr(getpaid_convert_items_to_string($_items)); |
|
319 | + $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items); |
|
320 | 320 | $extra_items = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />"; |
321 | 321 | $extra_items .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />"; |
322 | - $payment_form->display( $extra_items ); |
|
322 | + $payment_form->display($extra_items); |
|
323 | 323 | $getpaid_force_checkbox = false; |
324 | 324 | |
325 | 325 | } else { |
326 | - getpaid_display_payment_form( $form ); |
|
326 | + getpaid_display_payment_form($form); |
|
327 | 327 | } |
328 | -} elseif ( ! empty( $_GET['invoice'] ) ) { |
|
329 | - getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) ); |
|
328 | +} elseif (!empty($_GET['invoice'])) { |
|
329 | + getpaid_display_invoice_payment_form((int) urldecode($_GET['invoice'])); |
|
330 | 330 | } else { |
331 | - $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) ); |
|
332 | - getpaid_display_item_payment_form( $items ); |
|
331 | + $items = getpaid_convert_items_to_array(sanitize_text_field(urldecode($_GET['item']))); |
|
332 | + getpaid_display_item_payment_form($items); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | exit; |
@@ -344,17 +344,17 @@ discard block |
||
344 | 344 | public static function payment_form() { |
345 | 345 | |
346 | 346 | // Check nonce. |
347 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
347 | + check_ajax_referer('getpaid_form_nonce'); |
|
348 | 348 | |
349 | 349 | // ... form fields... |
350 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
351 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
350 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
351 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
352 | 352 | exit; |
353 | 353 | } |
354 | 354 | |
355 | 355 | // Process the payment form. |
356 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
357 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
356 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
357 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
358 | 358 | $checkout->process_checkout(); |
359 | 359 | |
360 | 360 | exit; |
@@ -367,55 +367,55 @@ discard block |
||
367 | 367 | */ |
368 | 368 | public static function get_payment_form_states_field() { |
369 | 369 | |
370 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
370 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
371 | 371 | exit; |
372 | 372 | } |
373 | 373 | |
374 | - $elements = getpaid_get_payment_form_elements( (int) $_GET['form'] ); |
|
374 | + $elements = getpaid_get_payment_form_elements((int) $_GET['form']); |
|
375 | 375 | |
376 | - if ( empty( $elements ) ) { |
|
376 | + if (empty($elements)) { |
|
377 | 377 | exit; |
378 | 378 | } |
379 | 379 | |
380 | 380 | $address_fields = array(); |
381 | - foreach ( $elements as $element ) { |
|
382 | - if ( 'address' === $element['type'] ) { |
|
381 | + foreach ($elements as $element) { |
|
382 | + if ('address' === $element['type']) { |
|
383 | 383 | $address_fields = $element; |
384 | 384 | break; |
385 | 385 | } |
386 | 386 | } |
387 | 387 | |
388 | - if ( empty( $address_fields ) ) { |
|
388 | + if (empty($address_fields)) { |
|
389 | 389 | exit; |
390 | 390 | } |
391 | 391 | |
392 | - foreach ( $address_fields['fields'] as $address_field ) { |
|
392 | + foreach ($address_fields['fields'] as $address_field) { |
|
393 | 393 | |
394 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
394 | + if ('wpinv_state' == $address_field['name']) { |
|
395 | 395 | |
396 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
397 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
398 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
399 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
400 | - $value = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : ''; |
|
401 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
396 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
397 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
398 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
399 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
400 | + $value = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : ''; |
|
401 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
402 | 402 | |
403 | - if ( ! empty( $address_field['required'] ) ) { |
|
403 | + if (!empty($address_field['required'])) { |
|
404 | 404 | $label .= "<span class='text-danger'> *</span>"; |
405 | 405 | } |
406 | 406 | |
407 | 407 | $html = getpaid_get_states_select_markup( |
408 | - sanitize_text_field( $_GET['country'] ), |
|
408 | + sanitize_text_field($_GET['country']), |
|
409 | 409 | $value, |
410 | 410 | $placeholder, |
411 | 411 | $label, |
412 | 412 | $description, |
413 | - ! empty( $address_field['required'] ), |
|
413 | + !empty($address_field['required']), |
|
414 | 414 | $wrap_class, |
415 | - sanitize_text_field( $_GET['name'] ) |
|
415 | + sanitize_text_field($_GET['name']) |
|
416 | 416 | ); |
417 | 417 | |
418 | - wp_send_json_success( $html ); |
|
418 | + wp_send_json_success($html); |
|
419 | 419 | exit; |
420 | 420 | |
421 | 421 | } |
@@ -430,66 +430,66 @@ discard block |
||
430 | 430 | public static function recalculate_invoice_totals() { |
431 | 431 | |
432 | 432 | // Verify nonce. |
433 | - check_ajax_referer( 'wpinv-nonce' ); |
|
433 | + check_ajax_referer('wpinv-nonce'); |
|
434 | 434 | |
435 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
435 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
436 | 436 | exit; |
437 | 437 | } |
438 | 438 | |
439 | 439 | // We need an invoice. |
440 | - if ( empty( $_POST['post_id'] ) ) { |
|
440 | + if (empty($_POST['post_id'])) { |
|
441 | 441 | exit; |
442 | 442 | } |
443 | 443 | |
444 | 444 | // Fetch the invoice. |
445 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
445 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
446 | 446 | |
447 | 447 | // Ensure it exists. |
448 | - if ( ! $invoice->get_id() ) { |
|
448 | + if (!$invoice->get_id()) { |
|
449 | 449 | exit; |
450 | 450 | } |
451 | 451 | |
452 | 452 | // Maybe set the country, state, currency. |
453 | - foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) { |
|
454 | - if ( isset( $_POST[ $key ] ) ) { |
|
453 | + foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) { |
|
454 | + if (isset($_POST[$key])) { |
|
455 | 455 | $method = "set_$key"; |
456 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
456 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
457 | 457 | } |
458 | 458 | } |
459 | 459 | |
460 | 460 | // Maybe disable taxes. |
461 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
461 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
462 | 462 | |
463 | 463 | // Discount code. |
464 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
465 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
466 | - if ( $discount->exists() ) { |
|
467 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
464 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
465 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
466 | + if ($discount->exists()) { |
|
467 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
468 | 468 | } else { |
469 | - $invoice->remove_discount( 'discount_code' ); |
|
469 | + $invoice->remove_discount('discount_code'); |
|
470 | 470 | } |
471 | 471 | } |
472 | 472 | |
473 | 473 | // Recalculate totals. |
474 | 474 | $invoice->recalculate_total(); |
475 | 475 | |
476 | - $total = wpinv_price( $invoice->get_total(), $invoice->get_currency() ); |
|
477 | - $suscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
478 | - if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
479 | - $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() ); |
|
480 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
476 | + $total = wpinv_price($invoice->get_total(), $invoice->get_currency()); |
|
477 | + $suscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
478 | + if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
479 | + $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency()); |
|
480 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | $totals = array( |
484 | - 'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
|
485 | - 'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
486 | - 'tax' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
|
484 | + 'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()), |
|
485 | + 'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
486 | + 'tax' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()), |
|
487 | 487 | 'total' => $total, |
488 | 488 | ); |
489 | 489 | |
490 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
490 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
491 | 491 | |
492 | - wp_send_json_success( compact( 'totals' ) ); |
|
492 | + wp_send_json_success(compact('totals')); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | /** |
@@ -498,33 +498,33 @@ discard block |
||
498 | 498 | public static function get_invoice_items() { |
499 | 499 | |
500 | 500 | // Verify nonce. |
501 | - check_ajax_referer( 'wpinv-nonce' ); |
|
501 | + check_ajax_referer('wpinv-nonce'); |
|
502 | 502 | |
503 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
503 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
504 | 504 | exit; |
505 | 505 | } |
506 | 506 | |
507 | 507 | // We need an invoice and items. |
508 | - if ( empty( $_POST['post_id'] ) ) { |
|
508 | + if (empty($_POST['post_id'])) { |
|
509 | 509 | exit; |
510 | 510 | } |
511 | 511 | |
512 | 512 | // Fetch the invoice. |
513 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
513 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
514 | 514 | |
515 | 515 | // Ensure it exists. |
516 | - if ( ! $invoice->get_id() ) { |
|
516 | + if (!$invoice->get_id()) { |
|
517 | 517 | exit; |
518 | 518 | } |
519 | 519 | |
520 | 520 | // Return an array of invoice items. |
521 | 521 | $items = array(); |
522 | 522 | |
523 | - foreach ( $invoice->get_items() as $item ) { |
|
524 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() ); |
|
523 | + foreach ($invoice->get_items() as $item) { |
|
524 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal()); |
|
525 | 525 | } |
526 | 526 | |
527 | - wp_send_json_success( compact( 'items' ) ); |
|
527 | + wp_send_json_success(compact('items')); |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | /** |
@@ -533,50 +533,50 @@ discard block |
||
533 | 533 | public static function edit_invoice_item() { |
534 | 534 | |
535 | 535 | // Verify nonce. |
536 | - check_ajax_referer( 'wpinv-nonce' ); |
|
536 | + check_ajax_referer('wpinv-nonce'); |
|
537 | 537 | |
538 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
538 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
539 | 539 | exit; |
540 | 540 | } |
541 | 541 | |
542 | 542 | // We need an invoice and item details. |
543 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
543 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
544 | 544 | exit; |
545 | 545 | } |
546 | 546 | |
547 | 547 | // Fetch the invoice. |
548 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
548 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
549 | 549 | |
550 | 550 | // Ensure it exists and its not been paid for. |
551 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
551 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
552 | 552 | exit; |
553 | 553 | } |
554 | 554 | |
555 | 555 | // Format the data. |
556 | - $data = wp_kses_post_deep( wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ) ); |
|
556 | + $data = wp_kses_post_deep(wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field'))); |
|
557 | 557 | |
558 | 558 | // Ensure that we have an item id. |
559 | - if ( empty( $data['id'] ) ) { |
|
559 | + if (empty($data['id'])) { |
|
560 | 560 | exit; |
561 | 561 | } |
562 | 562 | |
563 | 563 | // Abort if the invoice does not have the specified item. |
564 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
564 | + $item = $invoice->get_item((int) $data['id']); |
|
565 | 565 | |
566 | - if ( empty( $item ) ) { |
|
566 | + if (empty($item)) { |
|
567 | 567 | exit; |
568 | 568 | } |
569 | 569 | |
570 | 570 | // Update the item. |
571 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
572 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
573 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
574 | - $item->set_quantity( floatval( $data['quantity'] ) ); |
|
571 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
572 | + $item->set_name(sanitize_text_field($data['name'])); |
|
573 | + $item->set_description(wp_kses_post($data['description'])); |
|
574 | + $item->set_quantity(floatval($data['quantity'])); |
|
575 | 575 | |
576 | 576 | // Add it to the invoice. |
577 | - $error = $invoice->add_item( $item ); |
|
577 | + $error = $invoice->add_item($item); |
|
578 | 578 | $alert = false; |
579 | - if ( is_wp_error( $error ) ) { |
|
579 | + if (is_wp_error($error)) { |
|
580 | 580 | $alert = $error->get_error_message(); |
581 | 581 | } |
582 | 582 | |
@@ -589,11 +589,11 @@ discard block |
||
589 | 589 | // Return an array of invoice items. |
590 | 590 | $items = array(); |
591 | 591 | |
592 | - foreach ( $invoice->get_items() as $item ) { |
|
593 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
592 | + foreach ($invoice->get_items() as $item) { |
|
593 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
594 | 594 | } |
595 | 595 | |
596 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
596 | + wp_send_json_success(compact('items', 'alert')); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | /** |
@@ -602,53 +602,53 @@ discard block |
||
602 | 602 | public static function create_invoice_item() { |
603 | 603 | |
604 | 604 | // Verify nonce. |
605 | - check_ajax_referer( 'wpinv-nonce' ); |
|
605 | + check_ajax_referer('wpinv-nonce'); |
|
606 | 606 | |
607 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
607 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
608 | 608 | exit; |
609 | 609 | } |
610 | 610 | |
611 | 611 | // We need an invoice and item details. |
612 | - if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) { |
|
612 | + if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) { |
|
613 | 613 | exit; |
614 | 614 | } |
615 | 615 | |
616 | 616 | // Fetch the invoice. |
617 | - $invoice = new WPInv_Invoice( intval( $_POST['invoice_id'] ) ); |
|
617 | + $invoice = new WPInv_Invoice(intval($_POST['invoice_id'])); |
|
618 | 618 | |
619 | 619 | // Ensure it exists and its not been paid for. |
620 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
620 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
621 | 621 | exit; |
622 | 622 | } |
623 | 623 | |
624 | 624 | // Format the data. |
625 | - $data = wp_kses_post_deep( wp_unslash( $_POST['_wpinv_quick'] ) ); |
|
625 | + $data = wp_kses_post_deep(wp_unslash($_POST['_wpinv_quick'])); |
|
626 | 626 | |
627 | 627 | $item = new WPInv_Item(); |
628 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
629 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
630 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
631 | - $item->set_type( sanitize_text_field( $data['type'] ) ); |
|
632 | - $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) ); |
|
633 | - $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) ); |
|
634 | - $item->set_status( 'publish' ); |
|
628 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
629 | + $item->set_name(sanitize_text_field($data['name'])); |
|
630 | + $item->set_description(wp_kses_post($data['description'])); |
|
631 | + $item->set_type(sanitize_text_field($data['type'])); |
|
632 | + $item->set_vat_rule(sanitize_text_field($data['vat_rule'])); |
|
633 | + $item->set_vat_class(sanitize_text_field($data['vat_class'])); |
|
634 | + $item->set_status('publish'); |
|
635 | 635 | $item->save(); |
636 | 636 | |
637 | - if ( ! $item->exists() ) { |
|
638 | - $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' ); |
|
639 | - wp_send_json_success( compact( 'alert' ) ); |
|
637 | + if (!$item->exists()) { |
|
638 | + $alert = __('Could not create invoice item. Please try again.', 'invoicing'); |
|
639 | + wp_send_json_success(compact('alert')); |
|
640 | 640 | } |
641 | 641 | |
642 | - $item = new GetPaid_Form_Item( $item->get_id() ); |
|
643 | - $item->set_quantity( floatval( $data['qty'] ) ); |
|
642 | + $item = new GetPaid_Form_Item($item->get_id()); |
|
643 | + $item->set_quantity(floatval($data['qty'])); |
|
644 | 644 | |
645 | 645 | // Add it to the invoice. |
646 | - $error = $invoice->add_item( $item ); |
|
646 | + $error = $invoice->add_item($item); |
|
647 | 647 | $alert = false; |
648 | 648 | |
649 | - if ( is_wp_error( $error ) ) { |
|
649 | + if (is_wp_error($error)) { |
|
650 | 650 | $alert = $error->get_error_message(); |
651 | - wp_send_json_success( compact( 'alert' ) ); |
|
651 | + wp_send_json_success(compact('alert')); |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | // Update totals. |
@@ -661,9 +661,9 @@ discard block |
||
661 | 661 | $invoice->recalculate_total(); |
662 | 662 | $invoice->save(); |
663 | 663 | ob_start(); |
664 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
664 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
665 | 665 | $row = ob_get_clean(); |
666 | - wp_send_json_success( compact( 'row' ) ); |
|
666 | + wp_send_json_success(compact('row')); |
|
667 | 667 | } |
668 | 668 | |
669 | 669 | /** |
@@ -672,33 +672,33 @@ discard block |
||
672 | 672 | public static function remove_invoice_item() { |
673 | 673 | |
674 | 674 | // Verify nonce. |
675 | - check_ajax_referer( 'wpinv-nonce' ); |
|
675 | + check_ajax_referer('wpinv-nonce'); |
|
676 | 676 | |
677 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
677 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
678 | 678 | exit; |
679 | 679 | } |
680 | 680 | |
681 | 681 | // We need an invoice and an item. |
682 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
682 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
683 | 683 | exit; |
684 | 684 | } |
685 | 685 | |
686 | 686 | // Fetch the invoice. |
687 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
687 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
688 | 688 | |
689 | 689 | // Ensure it exists and its not been paid for. |
690 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
690 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
691 | 691 | exit; |
692 | 692 | } |
693 | 693 | |
694 | 694 | // Abort if the invoice does not have the specified item. |
695 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
695 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
696 | 696 | |
697 | - if ( empty( $item ) ) { |
|
697 | + if (empty($item)) { |
|
698 | 698 | exit; |
699 | 699 | } |
700 | 700 | |
701 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
701 | + $invoice->remove_item((int) $_POST['item_id']); |
|
702 | 702 | |
703 | 703 | // Update totals. |
704 | 704 | $invoice->recalculate_total(); |
@@ -709,11 +709,11 @@ discard block |
||
709 | 709 | // Return an array of invoice items. |
710 | 710 | $items = array(); |
711 | 711 | |
712 | - foreach ( $invoice->get_items() as $item ) { |
|
713 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
712 | + foreach ($invoice->get_items() as $item) { |
|
713 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
714 | 714 | } |
715 | 715 | |
716 | - wp_send_json_success( compact( 'items' ) ); |
|
716 | + wp_send_json_success(compact('items')); |
|
717 | 717 | } |
718 | 718 | |
719 | 719 | /** |
@@ -722,68 +722,68 @@ discard block |
||
722 | 722 | public static function recalculate_full_prices() { |
723 | 723 | |
724 | 724 | // Verify nonce. |
725 | - check_ajax_referer( 'wpinv-nonce' ); |
|
725 | + check_ajax_referer('wpinv-nonce'); |
|
726 | 726 | |
727 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
727 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
728 | 728 | exit; |
729 | 729 | } |
730 | 730 | |
731 | 731 | // We need an invoice and item. |
732 | - if ( empty( $_POST['post_id'] ) ) { |
|
732 | + if (empty($_POST['post_id'])) { |
|
733 | 733 | exit; |
734 | 734 | } |
735 | 735 | |
736 | 736 | // Fetch the invoice. |
737 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
737 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
738 | 738 | $alert = false; |
739 | 739 | |
740 | 740 | // Ensure it exists and its not been paid for. |
741 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
741 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
742 | 742 | exit; |
743 | 743 | } |
744 | 744 | |
745 | - $invoice->set_items( array() ); |
|
745 | + $invoice->set_items(array()); |
|
746 | 746 | |
747 | - if ( ! empty( $_POST['getpaid_items'] ) ) { |
|
747 | + if (!empty($_POST['getpaid_items'])) { |
|
748 | 748 | |
749 | - foreach ( wp_kses_post_deep( $_POST['getpaid_items'] ) as $item_id => $args ) { |
|
750 | - $item = new GetPaid_Form_Item( $item_id ); |
|
749 | + foreach (wp_kses_post_deep($_POST['getpaid_items']) as $item_id => $args) { |
|
750 | + $item = new GetPaid_Form_Item($item_id); |
|
751 | 751 | |
752 | - if ( $item->exists() ) { |
|
753 | - $item->set_price( getpaid_standardize_amount( $args['price'] ) ); |
|
754 | - $item->set_quantity( floatval( $args['quantity'] ) ); |
|
755 | - $item->set_name( sanitize_text_field( $args['name'] ) ); |
|
756 | - $item->set_description( wp_kses_post( $args['description'] ) ); |
|
757 | - $invoice->add_item( $item ); |
|
752 | + if ($item->exists()) { |
|
753 | + $item->set_price(getpaid_standardize_amount($args['price'])); |
|
754 | + $item->set_quantity(floatval($args['quantity'])); |
|
755 | + $item->set_name(sanitize_text_field($args['name'])); |
|
756 | + $item->set_description(wp_kses_post($args['description'])); |
|
757 | + $invoice->add_item($item); |
|
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( intval( $_POST['post_id'] ) ); |
|
807 | + $invoice = new WPInv_Invoice(intval($_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( intval( $_POST['post_id'] ) ); |
|
851 | + $invoice = new WPInv_Invoice(intval($_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 ( wp_kses_post_deep( wp_unslash( $_POST['items'] ) ) as $data ) { |
|
860 | + foreach (wp_kses_post_deep(wp_unslash($_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 | } |
@@ -881,11 +881,11 @@ discard block |
||
881 | 881 | // Return an array of invoice items. |
882 | 882 | $items = array(); |
883 | 883 | |
884 | - foreach ( $invoice->get_items() as $item ) { |
|
885 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
884 | + foreach ($invoice->get_items() as $item) { |
|
885 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
886 | 886 | } |
887 | 887 | |
888 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
888 | + wp_send_json_success(compact('items', 'alert')); |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | /** |
@@ -894,15 +894,15 @@ discard block |
||
894 | 894 | public static function get_invoicing_items() { |
895 | 895 | |
896 | 896 | // Verify nonce. |
897 | - check_ajax_referer( 'wpinv-nonce' ); |
|
897 | + check_ajax_referer('wpinv-nonce'); |
|
898 | 898 | |
899 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
899 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
900 | 900 | exit; |
901 | 901 | } |
902 | 902 | |
903 | 903 | // We need a search term. |
904 | - if ( empty( $_GET['search'] ) ) { |
|
905 | - wp_send_json_success( array() ); |
|
904 | + if (empty($_GET['search'])) { |
|
905 | + wp_send_json_success(array()); |
|
906 | 906 | } |
907 | 907 | |
908 | 908 | // Retrieve items. |
@@ -911,8 +911,8 @@ discard block |
||
911 | 911 | 'orderby' => 'title', |
912 | 912 | 'order' => 'ASC', |
913 | 913 | 'posts_per_page' => -1, |
914 | - 'post_status' => array( 'publish' ), |
|
915 | - 's' => sanitize_text_field( urldecode( $_GET['search'] ) ), |
|
914 | + 'post_status' => array('publish'), |
|
915 | + 's' => sanitize_text_field(urldecode($_GET['search'])), |
|
916 | 916 | 'meta_query' => array( |
917 | 917 | array( |
918 | 918 | 'key' => '_wpinv_type', |
@@ -922,25 +922,25 @@ discard block |
||
922 | 922 | ), |
923 | 923 | ); |
924 | 924 | |
925 | - if ( ! empty( $_GET['ignore'] ) ) { |
|
926 | - $item_args['exclude'] = wp_parse_id_list( sanitize_text_field( $_GET['ignore'] ) ); |
|
925 | + if (!empty($_GET['ignore'])) { |
|
926 | + $item_args['exclude'] = wp_parse_id_list(sanitize_text_field($_GET['ignore'])); |
|
927 | 927 | } |
928 | 928 | |
929 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
929 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
930 | 930 | $data = array(); |
931 | 931 | |
932 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( (int) $_GET['post_id'] ) ); |
|
932 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type((int) $_GET['post_id'])); |
|
933 | 933 | |
934 | - foreach ( $items as $item ) { |
|
935 | - $item = new GetPaid_Form_Item( $item ); |
|
934 | + foreach ($items as $item) { |
|
935 | + $item = new GetPaid_Form_Item($item); |
|
936 | 936 | $data[] = array( |
937 | 937 | 'id' => (int) $item->get_id(), |
938 | - 'text' => strip_tags( $item->get_name() ), |
|
939 | - 'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '', |
|
938 | + 'text' => strip_tags($item->get_name()), |
|
939 | + 'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '', |
|
940 | 940 | ); |
941 | 941 | } |
942 | 942 | |
943 | - wp_send_json_success( $data ); |
|
943 | + wp_send_json_success($data); |
|
944 | 944 | |
945 | 945 | } |
946 | 946 | |
@@ -950,37 +950,37 @@ discard block |
||
950 | 950 | public static function get_customers() { |
951 | 951 | |
952 | 952 | // Verify nonce. |
953 | - check_ajax_referer( 'wpinv-nonce' ); |
|
953 | + check_ajax_referer('wpinv-nonce'); |
|
954 | 954 | |
955 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
955 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
956 | 956 | exit; |
957 | 957 | } |
958 | 958 | |
959 | 959 | // We need a search term. |
960 | - if ( empty( $_GET['search'] ) ) { |
|
961 | - wp_send_json_success( array() ); |
|
960 | + if (empty($_GET['search'])) { |
|
961 | + wp_send_json_success(array()); |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | // Retrieve customers. |
965 | 965 | |
966 | 966 | $customer_args = array( |
967 | - 'fields' => array( 'ID', 'user_email', 'display_name' ), |
|
967 | + 'fields' => array('ID', 'user_email', 'display_name'), |
|
968 | 968 | 'orderby' => 'display_name', |
969 | - 'search' => '*' . sanitize_text_field( $_GET['search'] ) . '*', |
|
970 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
969 | + 'search' => '*' . sanitize_text_field($_GET['search']) . '*', |
|
970 | + 'search_columns' => array('user_login', 'user_email', 'display_name'), |
|
971 | 971 | ); |
972 | 972 | |
973 | - $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) ); |
|
973 | + $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args)); |
|
974 | 974 | $data = array(); |
975 | 975 | |
976 | - foreach ( $customers as $customer ) { |
|
976 | + foreach ($customers as $customer) { |
|
977 | 977 | $data[] = array( |
978 | 978 | 'id' => (int) $customer->ID, |
979 | - 'text' => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ), |
|
979 | + 'text' => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)), |
|
980 | 980 | ); |
981 | 981 | } |
982 | 982 | |
983 | - wp_send_json_success( $data ); |
|
983 | + wp_send_json_success($data); |
|
984 | 984 | |
985 | 985 | } |
986 | 986 | |
@@ -990,28 +990,28 @@ discard block |
||
990 | 990 | public static function get_aui_states_field() { |
991 | 991 | |
992 | 992 | // Verify nonce. |
993 | - check_ajax_referer( 'wpinv-nonce' ); |
|
993 | + check_ajax_referer('wpinv-nonce'); |
|
994 | 994 | |
995 | 995 | // We need a country. |
996 | - if ( empty( $_GET['country'] ) ) { |
|
996 | + if (empty($_GET['country'])) { |
|
997 | 997 | exit; |
998 | 998 | } |
999 | 999 | |
1000 | - $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) ); |
|
1001 | - $state = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state(); |
|
1002 | - $name = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state'; |
|
1003 | - $class = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm'; |
|
1000 | + $states = wpinv_get_country_states(sanitize_text_field($_GET['country'])); |
|
1001 | + $state = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state(); |
|
1002 | + $name = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state'; |
|
1003 | + $class = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm'; |
|
1004 | 1004 | |
1005 | - if ( empty( $states ) ) { |
|
1005 | + if (empty($states)) { |
|
1006 | 1006 | |
1007 | 1007 | $html = aui()->input( |
1008 | 1008 | array( |
1009 | 1009 | 'type' => 'text', |
1010 | 1010 | 'id' => 'wpinv_state', |
1011 | 1011 | 'name' => $name, |
1012 | - 'label' => __( 'State', 'invoicing' ), |
|
1012 | + 'label' => __('State', 'invoicing'), |
|
1013 | 1013 | 'label_type' => 'vertical', |
1014 | - 'placeholder' => __( 'State', 'invoicing' ), |
|
1014 | + 'placeholder' => __('State', 'invoicing'), |
|
1015 | 1015 | 'class' => $class, |
1016 | 1016 | 'value' => $state, |
1017 | 1017 | ) |
@@ -1023,9 +1023,9 @@ discard block |
||
1023 | 1023 | array( |
1024 | 1024 | 'id' => 'wpinv_state', |
1025 | 1025 | 'name' => $name, |
1026 | - 'label' => __( 'State', 'invoicing' ), |
|
1026 | + 'label' => __('State', 'invoicing'), |
|
1027 | 1027 | 'label_type' => 'vertical', |
1028 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
1028 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
1029 | 1029 | 'class' => $class, |
1030 | 1030 | 'value' => $state, |
1031 | 1031 | 'options' => $states, |
@@ -1039,7 +1039,7 @@ discard block |
||
1039 | 1039 | wp_send_json_success( |
1040 | 1040 | array( |
1041 | 1041 | 'html' => $html, |
1042 | - 'select' => ! empty( $states ), |
|
1042 | + 'select' => !empty($states), |
|
1043 | 1043 | ) |
1044 | 1044 | ); |
1045 | 1045 | |
@@ -1053,11 +1053,11 @@ discard block |
||
1053 | 1053 | public static function payment_form_refresh_prices() { |
1054 | 1054 | |
1055 | 1055 | // Check nonce. |
1056 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
1056 | + check_ajax_referer('getpaid_form_nonce'); |
|
1057 | 1057 | |
1058 | 1058 | // ... form fields... |
1059 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
1060 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
1059 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
1060 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
1061 | 1061 | exit; |
1062 | 1062 | } |
1063 | 1063 | |
@@ -1065,7 +1065,7 @@ discard block |
||
1065 | 1065 | $submission = new GetPaid_Payment_Form_Submission(); |
1066 | 1066 | |
1067 | 1067 | // Do we have an error? |
1068 | - if ( ! empty( $submission->last_error ) ) { |
|
1068 | + if (!empty($submission->last_error)) { |
|
1069 | 1069 | wp_send_json_error( |
1070 | 1070 | array( |
1071 | 1071 | 'code' => $submission->last_error_code, |
@@ -1075,12 +1075,12 @@ discard block |
||
1075 | 1075 | } |
1076 | 1076 | |
1077 | 1077 | // Prepare the response. |
1078 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
1078 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
1079 | 1079 | |
1080 | 1080 | // Filter the response. |
1081 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
1081 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
1082 | 1082 | |
1083 | - wp_send_json_success( $response ); |
|
1083 | + wp_send_json_success($response); |
|
1084 | 1084 | } |
1085 | 1085 | |
1086 | 1086 | /** |
@@ -1092,63 +1092,63 @@ discard block |
||
1092 | 1092 | public static function file_upload() { |
1093 | 1093 | |
1094 | 1094 | // Check nonce. |
1095 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
1095 | + check_ajax_referer('getpaid_form_nonce'); |
|
1096 | 1096 | |
1097 | - if ( empty( $_POST['form_id'] ) || empty( $_POST['field_name'] ) || empty( $_FILES['file'] ) ) { |
|
1098 | - wp_die( __( 'Bad Request', 'invoicing' ), 400 ); |
|
1097 | + if (empty($_POST['form_id']) || empty($_POST['field_name']) || empty($_FILES['file'])) { |
|
1098 | + wp_die(__('Bad Request', 'invoicing'), 400); |
|
1099 | 1099 | } |
1100 | 1100 | |
1101 | 1101 | // Fetch form. |
1102 | - $form = new GetPaid_Payment_Form( intval( $_POST['form_id'] ) ); |
|
1102 | + $form = new GetPaid_Payment_Form(intval($_POST['form_id'])); |
|
1103 | 1103 | |
1104 | - if ( ! $form->is_active() ) { |
|
1105 | - wp_send_json_error( __( 'Payment form not active', 'invoicing' ) ); |
|
1104 | + if (!$form->is_active()) { |
|
1105 | + wp_send_json_error(__('Payment form not active', 'invoicing')); |
|
1106 | 1106 | } |
1107 | 1107 | |
1108 | 1108 | // Fetch appropriate field. |
1109 | - $upload_field = current( wp_list_filter( $form->get_elements(), array( 'id' => sanitize_text_field( $_POST['field_name'] ) ) ) ); |
|
1110 | - if ( empty( $upload_field ) ) { |
|
1111 | - wp_send_json_error( __( 'Invalid upload field.', 'invoicing' ) ); |
|
1109 | + $upload_field = current(wp_list_filter($form->get_elements(), array('id' => sanitize_text_field($_POST['field_name'])))); |
|
1110 | + if (empty($upload_field)) { |
|
1111 | + wp_send_json_error(__('Invalid upload field.', 'invoicing')); |
|
1112 | 1112 | } |
1113 | 1113 | |
1114 | 1114 | // Prepare allowed file types. |
1115 | - $file_types = isset( $upload_field['file_types'] ) ? $upload_field['file_types'] : array( 'jpg|jpeg|jpe', 'gif', 'png' ); |
|
1115 | + $file_types = isset($upload_field['file_types']) ? $upload_field['file_types'] : array('jpg|jpeg|jpe', 'gif', 'png'); |
|
1116 | 1116 | $all_types = getpaid_get_allowed_mime_types(); |
1117 | 1117 | $mime_types = array(); |
1118 | 1118 | |
1119 | - foreach ( $file_types as $file_type ) { |
|
1120 | - if ( isset( $all_types[ $file_type ] ) ) { |
|
1121 | - $mime_types[] = $all_types[ $file_type ]; |
|
1119 | + foreach ($file_types as $file_type) { |
|
1120 | + if (isset($all_types[$file_type])) { |
|
1121 | + $mime_types[] = $all_types[$file_type]; |
|
1122 | 1122 | } |
1123 | 1123 | } |
1124 | 1124 | |
1125 | - if ( ! in_array( $_FILES['file']['type'], $mime_types ) ) { |
|
1126 | - wp_send_json_error( __( 'Unsupported file type.', 'invoicing' ) ); |
|
1125 | + if (!in_array($_FILES['file']['type'], $mime_types)) { |
|
1126 | + wp_send_json_error(__('Unsupported file type.', 'invoicing')); |
|
1127 | 1127 | } |
1128 | 1128 | |
1129 | 1129 | // Upload file. |
1130 | - $file_name = explode( '.', strtolower( $_FILES['file']['name'] ) ); |
|
1131 | - $file_name = uniqid( 'getpaid-' ) . '.' . array_pop( $file_name ); |
|
1130 | + $file_name = explode('.', strtolower($_FILES['file']['name'])); |
|
1131 | + $file_name = uniqid('getpaid-') . '.' . array_pop($file_name); |
|
1132 | 1132 | |
1133 | 1133 | $uploaded = wp_upload_bits( |
1134 | 1134 | $file_name, |
1135 | 1135 | null, |
1136 | - file_get_contents( $_FILES['file']['tmp_name'] ) |
|
1136 | + file_get_contents($_FILES['file']['tmp_name']) |
|
1137 | 1137 | ); |
1138 | 1138 | |
1139 | - if ( ! empty( $uploaded['error'] ) ) { |
|
1140 | - wp_send_json_error( $uploaded['error'] ); |
|
1139 | + if (!empty($uploaded['error'])) { |
|
1140 | + wp_send_json_error($uploaded['error']); |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | 1143 | // Retrieve response. |
1144 | 1144 | $response = sprintf( |
1145 | 1145 | '<input type="hidden" name="%s[%s]" value="%s" />', |
1146 | - esc_attr( sanitize_text_field( $_POST['field_name'] ) ), |
|
1147 | - esc_url( $uploaded['url'] ), |
|
1148 | - esc_attr( sanitize_text_field( strtolower( $_FILES['file']['name'] ) ) ) |
|
1146 | + esc_attr(sanitize_text_field($_POST['field_name'])), |
|
1147 | + esc_url($uploaded['url']), |
|
1148 | + esc_attr(sanitize_text_field(strtolower($_FILES['file']['name']))) |
|
1149 | 1149 | ); |
1150 | 1150 | |
1151 | - wp_send_json_success( $response ); |
|
1151 | + wp_send_json_success($response); |
|
1152 | 1152 | |
1153 | 1153 | } |
1154 | 1154 |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | 142 | function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
143 | + return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -175,125 +175,125 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
178 | + do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
179 | 179 | |
180 | - // Setup possible parts |
|
181 | - $templates = array(); |
|
182 | - if ( isset( $name ) ) { |
|
183 | - $templates[] = $slug . '-' . $name . '.php'; |
|
180 | + // Setup possible parts |
|
181 | + $templates = array(); |
|
182 | + if ( isset( $name ) ) { |
|
183 | + $templates[] = $slug . '-' . $name . '.php'; |
|
184 | 184 | } |
185 | - $templates[] = $slug . '.php'; |
|
185 | + $templates[] = $slug . '.php'; |
|
186 | 186 | |
187 | - // Allow template parts to be filtered |
|
188 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
187 | + // Allow template parts to be filtered |
|
188 | + $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
189 | 189 | |
190 | - // Return the part that is found |
|
191 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
190 | + // Return the part that is found |
|
191 | + return wpinv_locate_tmpl( $templates, $load, false ); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
195 | - // No file found yet |
|
196 | - $located = false; |
|
195 | + // No file found yet |
|
196 | + $located = false; |
|
197 | 197 | |
198 | - // Try to find a template file |
|
199 | - foreach ( (array)$template_names as $template_name ) { |
|
198 | + // Try to find a template file |
|
199 | + foreach ( (array)$template_names as $template_name ) { |
|
200 | 200 | |
201 | - // Continue if template is empty |
|
202 | - if ( empty( $template_name ) ) { |
|
203 | - continue; |
|
201 | + // Continue if template is empty |
|
202 | + if ( empty( $template_name ) ) { |
|
203 | + continue; |
|
204 | 204 | } |
205 | 205 | |
206 | - // Trim off any slashes from the template name |
|
207 | - $template_name = ltrim( $template_name, '/' ); |
|
206 | + // Trim off any slashes from the template name |
|
207 | + $template_name = ltrim( $template_name, '/' ); |
|
208 | 208 | |
209 | - // try locating this template file by looping through the template paths |
|
210 | - foreach ( wpinv_get_theme_template_paths() as $template_path ) { |
|
209 | + // try locating this template file by looping through the template paths |
|
210 | + foreach ( wpinv_get_theme_template_paths() as $template_path ) { |
|
211 | 211 | |
212 | - if ( file_exists( $template_path . $template_name ) ) { |
|
213 | - $located = $template_path . $template_name; |
|
214 | - break; |
|
215 | - } |
|
216 | - } |
|
212 | + if ( file_exists( $template_path . $template_name ) ) { |
|
213 | + $located = $template_path . $template_name; |
|
214 | + break; |
|
215 | + } |
|
216 | + } |
|
217 | 217 | |
218 | - if ( ! empty( $located ) ) { |
|
219 | - break; |
|
220 | - } |
|
221 | - } |
|
218 | + if ( ! empty( $located ) ) { |
|
219 | + break; |
|
220 | + } |
|
221 | + } |
|
222 | 222 | |
223 | - if ( ( true == $load ) && ! empty( $located ) ) { |
|
224 | - load_template( $located, $require_once ); |
|
223 | + if ( ( true == $load ) && ! empty( $located ) ) { |
|
224 | + load_template( $located, $require_once ); |
|
225 | 225 | } |
226 | 226 | |
227 | - return $located; |
|
227 | + return $located; |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | function wpinv_get_theme_template_paths() { |
231 | - $template_dir = wpinv_get_theme_template_dir_name(); |
|
231 | + $template_dir = wpinv_get_theme_template_dir_name(); |
|
232 | 232 | |
233 | - $file_paths = array( |
|
234 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
235 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
236 | - 100 => wpinv_get_templates_dir(), |
|
237 | - ); |
|
233 | + $file_paths = array( |
|
234 | + 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
235 | + 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
236 | + 100 => wpinv_get_templates_dir(), |
|
237 | + ); |
|
238 | 238 | |
239 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
239 | + $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
240 | 240 | |
241 | - // sort the file paths based on priority |
|
242 | - ksort( $file_paths, SORT_NUMERIC ); |
|
241 | + // sort the file paths based on priority |
|
242 | + ksort( $file_paths, SORT_NUMERIC ); |
|
243 | 243 | |
244 | - return array_map( 'trailingslashit', $file_paths ); |
|
244 | + return array_map( 'trailingslashit', $file_paths ); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | function wpinv_checkout_meta_tags() { |
248 | 248 | |
249 | - $pages = array(); |
|
250 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
251 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
252 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
253 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
249 | + $pages = array(); |
|
250 | + $pages[] = wpinv_get_option( 'success_page' ); |
|
251 | + $pages[] = wpinv_get_option( 'failure_page' ); |
|
252 | + $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
253 | + $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
254 | 254 | |
255 | - if ( ! wpinv_is_checkout() && ! is_page( $pages ) ) { |
|
256 | - return; |
|
257 | - } |
|
255 | + if ( ! wpinv_is_checkout() && ! is_page( $pages ) ) { |
|
256 | + return; |
|
257 | + } |
|
258 | 258 | |
259 | - echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
259 | + echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
260 | 260 | } |
261 | 261 | add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
262 | 262 | |
263 | 263 | function wpinv_add_body_classes( $class ) { |
264 | - $classes = (array)$class; |
|
264 | + $classes = (array)$class; |
|
265 | 265 | |
266 | - if ( wpinv_is_checkout() ) { |
|
267 | - $classes[] = 'wpinv-checkout'; |
|
268 | - $classes[] = 'wpinv-page'; |
|
269 | - } |
|
266 | + if ( wpinv_is_checkout() ) { |
|
267 | + $classes[] = 'wpinv-checkout'; |
|
268 | + $classes[] = 'wpinv-page'; |
|
269 | + } |
|
270 | 270 | |
271 | - if ( wpinv_is_success_page() ) { |
|
272 | - $classes[] = 'wpinv-success'; |
|
273 | - $classes[] = 'wpinv-page'; |
|
274 | - } |
|
271 | + if ( wpinv_is_success_page() ) { |
|
272 | + $classes[] = 'wpinv-success'; |
|
273 | + $classes[] = 'wpinv-page'; |
|
274 | + } |
|
275 | 275 | |
276 | - if ( wpinv_is_failed_transaction_page() ) { |
|
277 | - $classes[] = 'wpinv-failed-transaction'; |
|
278 | - $classes[] = 'wpinv-page'; |
|
279 | - } |
|
276 | + if ( wpinv_is_failed_transaction_page() ) { |
|
277 | + $classes[] = 'wpinv-failed-transaction'; |
|
278 | + $classes[] = 'wpinv-page'; |
|
279 | + } |
|
280 | 280 | |
281 | - if ( wpinv_is_invoice_history_page() ) { |
|
282 | - $classes[] = 'wpinv-history'; |
|
283 | - $classes[] = 'wpinv-page'; |
|
284 | - } |
|
281 | + if ( wpinv_is_invoice_history_page() ) { |
|
282 | + $classes[] = 'wpinv-history'; |
|
283 | + $classes[] = 'wpinv-page'; |
|
284 | + } |
|
285 | 285 | |
286 | - if ( wpinv_is_subscriptions_history_page() ) { |
|
287 | - $classes[] = 'wpinv-subscription'; |
|
288 | - $classes[] = 'wpinv-page'; |
|
289 | - } |
|
286 | + if ( wpinv_is_subscriptions_history_page() ) { |
|
287 | + $classes[] = 'wpinv-subscription'; |
|
288 | + $classes[] = 'wpinv-page'; |
|
289 | + } |
|
290 | 290 | |
291 | - if ( wpinv_is_test_mode() ) { |
|
292 | - $classes[] = 'wpinv-test-mode'; |
|
293 | - $classes[] = 'wpinv-page'; |
|
294 | - } |
|
291 | + if ( wpinv_is_test_mode() ) { |
|
292 | + $classes[] = 'wpinv-test-mode'; |
|
293 | + $classes[] = 'wpinv-page'; |
|
294 | + } |
|
295 | 295 | |
296 | - return array_unique( $classes ); |
|
296 | + return array_unique( $classes ); |
|
297 | 297 | } |
298 | 298 | add_filter( 'body_class', 'wpinv_add_body_classes' ); |
299 | 299 | |
@@ -311,11 +311,11 @@ discard block |
||
311 | 311 | |
312 | 312 | $output = wpinv_html_select( |
313 | 313 | array( |
314 | - 'name' => $name, |
|
315 | - 'selected' => $selected, |
|
316 | - 'options' => $options, |
|
317 | - 'show_option_all' => false, |
|
318 | - 'show_option_none' => false, |
|
314 | + 'name' => $name, |
|
315 | + 'selected' => $selected, |
|
316 | + 'options' => $options, |
|
317 | + 'show_option_all' => false, |
|
318 | + 'show_option_none' => false, |
|
319 | 319 | ) |
320 | 320 | ); |
321 | 321 | |
@@ -344,11 +344,11 @@ discard block |
||
344 | 344 | |
345 | 345 | $output = wpinv_html_select( |
346 | 346 | array( |
347 | - 'name' => $name, |
|
348 | - 'selected' => $selected, |
|
349 | - 'options' => $options, |
|
350 | - 'show_option_all' => false, |
|
351 | - 'show_option_none' => false, |
|
347 | + 'name' => $name, |
|
348 | + 'selected' => $selected, |
|
349 | + 'options' => $options, |
|
350 | + 'show_option_all' => false, |
|
351 | + 'show_option_none' => false, |
|
352 | 352 | ) |
353 | 353 | ); |
354 | 354 | |
@@ -512,16 +512,16 @@ discard block |
||
512 | 512 | |
513 | 513 | $output = wpinv_html_select( |
514 | 514 | array( |
515 | - 'name' => $args['name'], |
|
516 | - 'selected' => $args['selected'], |
|
517 | - 'id' => $args['id'], |
|
518 | - 'class' => $args['class'], |
|
519 | - 'options' => $options, |
|
520 | - 'multiple' => $args['multiple'], |
|
521 | - 'placeholder' => $args['placeholder'], |
|
522 | - 'show_option_all' => $args['show_option_all'], |
|
523 | - 'show_option_none' => $args['show_option_none'], |
|
524 | - 'data' => $args['data'], |
|
515 | + 'name' => $args['name'], |
|
516 | + 'selected' => $args['selected'], |
|
517 | + 'id' => $args['id'], |
|
518 | + 'class' => $args['class'], |
|
519 | + 'options' => $options, |
|
520 | + 'multiple' => $args['multiple'], |
|
521 | + 'placeholder' => $args['placeholder'], |
|
522 | + 'show_option_all' => $args['show_option_all'], |
|
523 | + 'show_option_none' => $args['show_option_none'], |
|
524 | + 'data' => $args['data'], |
|
525 | 525 | ) |
526 | 526 | ); |
527 | 527 | |
@@ -822,21 +822,21 @@ discard block |
||
822 | 822 | |
823 | 823 | $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
824 | 824 | |
825 | - // Remove unavailable tags. |
|
825 | + // Remove unavailable tags. |
|
826 | 826 | $formatted_address = preg_replace( '/\{\{\w+\}\}/', '', $formatted_address ); |
827 | 827 | |
828 | 828 | // Clean up white space. |
829 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
829 | + $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
830 | 830 | $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
831 | 831 | |
832 | 832 | // Break newlines apart and remove empty lines/trim commas and white space. |
833 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
833 | + $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
834 | 834 | |
835 | 835 | // Add html breaks. |
836 | - $formatted_address = implode( $separator, $formatted_address ); |
|
836 | + $formatted_address = implode( $separator, $formatted_address ); |
|
837 | 837 | |
838 | - // We're done! |
|
839 | - return $formatted_address; |
|
838 | + // We're done! |
|
839 | + return $formatted_address; |
|
840 | 840 | |
841 | 841 | } |
842 | 842 | |
@@ -882,7 +882,7 @@ discard block |
||
882 | 882 | function getpaid_display_invoice_subscriptions( $invoice ) { |
883 | 883 | |
884 | 884 | // Subscriptions. |
885 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
885 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
886 | 886 | |
887 | 887 | if ( empty( $subscriptions ) || ! $invoice->is_recurring() ) { |
888 | 888 | return; |
@@ -1094,7 +1094,7 @@ discard block |
||
1094 | 1094 | } |
1095 | 1095 | |
1096 | 1096 | function wpinv_empty_cart_message() { |
1097 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1097 | + return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1098 | 1098 | } |
1099 | 1099 | |
1100 | 1100 | /** |
@@ -1292,9 +1292,9 @@ discard block |
||
1292 | 1292 | |
1293 | 1293 | if ( 0 == count( $form->get_items() ) ) { |
1294 | 1294 | aui()->alert( |
1295 | - array( |
|
1296 | - 'type' => 'warning', |
|
1297 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1295 | + array( |
|
1296 | + 'type' => 'warning', |
|
1297 | + 'content' => __( 'No published items found', 'invoicing' ), |
|
1298 | 1298 | ), |
1299 | 1299 | true |
1300 | 1300 | ); |
@@ -1317,10 +1317,10 @@ discard block |
||
1317 | 1317 | $invoice = wpinv_get_invoice( $invoice_id ); |
1318 | 1318 | |
1319 | 1319 | if ( empty( $invoice ) ) { |
1320 | - aui()->alert( |
|
1321 | - array( |
|
1322 | - 'type' => 'warning', |
|
1323 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1320 | + aui()->alert( |
|
1321 | + array( |
|
1322 | + 'type' => 'warning', |
|
1323 | + 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1324 | 1324 | ), |
1325 | 1325 | true |
1326 | 1326 | ); |
@@ -1328,10 +1328,10 @@ discard block |
||
1328 | 1328 | } |
1329 | 1329 | |
1330 | 1330 | if ( $invoice->is_paid() ) { |
1331 | - aui()->alert( |
|
1332 | - array( |
|
1333 | - 'type' => 'warning', |
|
1334 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1331 | + aui()->alert( |
|
1332 | + array( |
|
1333 | + 'type' => 'warning', |
|
1334 | + 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1335 | 1335 | ), |
1336 | 1336 | true |
1337 | 1337 | ); |
@@ -1395,7 +1395,7 @@ discard block |
||
1395 | 1395 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; |
1396 | 1396 | } |
1397 | 1397 | |
1398 | - if ( ! empty( $items ) ) { |
|
1398 | + if ( ! empty( $items ) ) { |
|
1399 | 1399 | $items = esc_attr( $items ); |
1400 | 1400 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; |
1401 | 1401 | } |
@@ -1581,21 +1581,21 @@ discard block |
||
1581 | 1581 | |
1582 | 1582 | return aui()->select( |
1583 | 1583 | array( |
1584 | - 'options' => $states, |
|
1585 | - 'name' => esc_attr( $field_name ), |
|
1586 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1587 | - 'value' => sanitize_text_field( $state ), |
|
1588 | - 'placeholder' => $placeholder, |
|
1589 | - 'required' => $required, |
|
1590 | - 'label' => wp_kses_post( $label ), |
|
1591 | - 'label_type' => 'vertical', |
|
1592 | - 'help_text' => $help_text, |
|
1593 | - 'class' => 'getpaid-address-field wpinv_state', |
|
1594 | - 'wrap_class' => "$wrapper_class getpaid-address-field-wrapper__state", |
|
1595 | - 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state', |
|
1596 | - 'extra_attributes' => array( |
|
1597 | - 'autocomplete' => 'address-level1', |
|
1598 | - ), |
|
1584 | + 'options' => $states, |
|
1585 | + 'name' => esc_attr( $field_name ), |
|
1586 | + 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1587 | + 'value' => sanitize_text_field( $state ), |
|
1588 | + 'placeholder' => $placeholder, |
|
1589 | + 'required' => $required, |
|
1590 | + 'label' => wp_kses_post( $label ), |
|
1591 | + 'label_type' => 'vertical', |
|
1592 | + 'help_text' => $help_text, |
|
1593 | + 'class' => 'getpaid-address-field wpinv_state', |
|
1594 | + 'wrap_class' => "$wrapper_class getpaid-address-field-wrapper__state", |
|
1595 | + 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state', |
|
1596 | + 'extra_attributes' => array( |
|
1597 | + 'autocomplete' => 'address-level1', |
|
1598 | + ), |
|
1599 | 1599 | ) |
1600 | 1600 | ); |
1601 | 1601 |
@@ -4,99 +4,99 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Displays an invoice. |
11 | 11 | * |
12 | 12 | * @param WPInv_Invoice $invoice. |
13 | 13 | */ |
14 | -function getpaid_invoice( $invoice ) { |
|
15 | - if ( ! empty( $invoice ) ) { |
|
16 | - wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) ); |
|
14 | +function getpaid_invoice($invoice) { |
|
15 | + if (!empty($invoice)) { |
|
16 | + wpinv_get_template('invoice/invoice.php', compact('invoice')); |
|
17 | 17 | } |
18 | 18 | } |
19 | -add_action( 'getpaid_invoice', 'getpaid_invoice', 10 ); |
|
19 | +add_action('getpaid_invoice', 'getpaid_invoice', 10); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Displays the invoice footer. |
23 | 23 | */ |
24 | -function getpaid_invoice_footer( $invoice ) { |
|
25 | - if ( ! empty( $invoice ) ) { |
|
26 | - wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) ); |
|
24 | +function getpaid_invoice_footer($invoice) { |
|
25 | + if (!empty($invoice)) { |
|
26 | + wpinv_get_template('invoice/footer.php', compact('invoice')); |
|
27 | 27 | } |
28 | 28 | } |
29 | -add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 ); |
|
29 | +add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Displays the invoice top bar. |
33 | 33 | */ |
34 | -function getpaid_invoice_header( $invoice ) { |
|
35 | - if ( ! empty( $invoice ) ) { |
|
36 | - wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) ); |
|
34 | +function getpaid_invoice_header($invoice) { |
|
35 | + if (!empty($invoice)) { |
|
36 | + wpinv_get_template('invoice/header.php', compact('invoice')); |
|
37 | 37 | } |
38 | 38 | } |
39 | -add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 ); |
|
39 | +add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10); |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Displays actions on the left side of the header. |
43 | 43 | */ |
44 | -function getpaid_invoice_header_left_actions( $invoice ) { |
|
45 | - if ( ! empty( $invoice ) ) { |
|
46 | - wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) ); |
|
44 | +function getpaid_invoice_header_left_actions($invoice) { |
|
45 | + if (!empty($invoice)) { |
|
46 | + wpinv_get_template('invoice/header-left-actions.php', compact('invoice')); |
|
47 | 47 | } |
48 | 48 | } |
49 | -add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 ); |
|
49 | +add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10); |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Displays actions on the right side of the invoice top bar. |
53 | 53 | */ |
54 | -function getpaid_invoice_header_right_actions( $invoice ) { |
|
55 | - if ( ! empty( $invoice ) ) { |
|
56 | - wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) ); |
|
54 | +function getpaid_invoice_header_right_actions($invoice) { |
|
55 | + if (!empty($invoice)) { |
|
56 | + wpinv_get_template('invoice/header-right-actions.php', compact('invoice')); |
|
57 | 57 | } |
58 | 58 | } |
59 | -add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 ); |
|
59 | +add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10); |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * Displays the invoice title, logo etc. |
63 | 63 | */ |
64 | -function getpaid_invoice_details_top( $invoice ) { |
|
65 | - if ( ! empty( $invoice ) ) { |
|
66 | - wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) ); |
|
64 | +function getpaid_invoice_details_top($invoice) { |
|
65 | + if (!empty($invoice)) { |
|
66 | + wpinv_get_template('invoice/details-top.php', compact('invoice')); |
|
67 | 67 | } |
68 | 68 | } |
69 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 ); |
|
69 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Displays the company logo. |
73 | 73 | */ |
74 | -function getpaid_invoice_logo( $invoice ) { |
|
75 | - if ( ! empty( $invoice ) ) { |
|
76 | - wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) ); |
|
74 | +function getpaid_invoice_logo($invoice) { |
|
75 | + if (!empty($invoice)) { |
|
76 | + wpinv_get_template('invoice/invoice-logo.php', compact('invoice')); |
|
77 | 77 | } |
78 | 78 | } |
79 | -add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' ); |
|
79 | +add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo'); |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Displays the type of invoice. |
83 | 83 | */ |
84 | -function getpaid_invoice_type( $invoice ) { |
|
85 | - if ( ! empty( $invoice ) ) { |
|
86 | - wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) ); |
|
84 | +function getpaid_invoice_type($invoice) { |
|
85 | + if (!empty($invoice)) { |
|
86 | + wpinv_get_template('invoice/invoice-type.php', compact('invoice')); |
|
87 | 87 | } |
88 | 88 | } |
89 | -add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' ); |
|
89 | +add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type'); |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Displays the invoice details. |
93 | 93 | */ |
94 | -function getpaid_invoice_details_main( $invoice ) { |
|
95 | - if ( ! empty( $invoice ) ) { |
|
96 | - wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) ); |
|
94 | +function getpaid_invoice_details_main($invoice) { |
|
95 | + if (!empty($invoice)) { |
|
96 | + wpinv_get_template('invoice/details.php', compact('invoice')); |
|
97 | 97 | } |
98 | 98 | } |
99 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 ); |
|
99 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50); |
|
100 | 100 | |
101 | 101 | /** |
102 | 102 | * Returns a path to the templates directory. |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
126 | 126 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
127 | 127 | */ |
128 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
129 | - getpaid_template()->display_template( $template_name, $args, $template_path, $default_path ); |
|
128 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
129 | + getpaid_template()->display_template($template_name, $args, $template_path, $default_path); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
142 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
143 | + return getpaid_template()->get_template($template_name, $args, $template_path, $default_path); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return string |
150 | 150 | */ |
151 | 151 | function wpinv_template_path() { |
152 | - return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() ); |
|
152 | + return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name()); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing')); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -170,58 +170,58 @@ discard block |
||
170 | 170 | * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'. |
171 | 171 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
172 | 172 | */ |
173 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
174 | - return getpaid_template()->locate_template( $template_name, $template_path, $default_path ); |
|
173 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
174 | + return getpaid_template()->locate_template($template_name, $template_path, $default_path); |
|
175 | 175 | } |
176 | 176 | |
177 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
177 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
178 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
179 | 179 | |
180 | 180 | // Setup possible parts |
181 | 181 | $templates = array(); |
182 | - if ( isset( $name ) ) { |
|
182 | + if (isset($name)) { |
|
183 | 183 | $templates[] = $slug . '-' . $name . '.php'; |
184 | 184 | } |
185 | 185 | $templates[] = $slug . '.php'; |
186 | 186 | |
187 | 187 | // Allow template parts to be filtered |
188 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
188 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
189 | 189 | |
190 | 190 | // Return the part that is found |
191 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
191 | + return wpinv_locate_tmpl($templates, $load, false); |
|
192 | 192 | } |
193 | 193 | |
194 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
194 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
195 | 195 | // No file found yet |
196 | 196 | $located = false; |
197 | 197 | |
198 | 198 | // Try to find a template file |
199 | - foreach ( (array)$template_names as $template_name ) { |
|
199 | + foreach ((array) $template_names as $template_name) { |
|
200 | 200 | |
201 | 201 | // Continue if template is empty |
202 | - if ( empty( $template_name ) ) { |
|
202 | + if (empty($template_name)) { |
|
203 | 203 | continue; |
204 | 204 | } |
205 | 205 | |
206 | 206 | // Trim off any slashes from the template name |
207 | - $template_name = ltrim( $template_name, '/' ); |
|
207 | + $template_name = ltrim($template_name, '/'); |
|
208 | 208 | |
209 | 209 | // try locating this template file by looping through the template paths |
210 | - foreach ( wpinv_get_theme_template_paths() as $template_path ) { |
|
210 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
211 | 211 | |
212 | - if ( file_exists( $template_path . $template_name ) ) { |
|
212 | + if (file_exists($template_path . $template_name)) { |
|
213 | 213 | $located = $template_path . $template_name; |
214 | 214 | break; |
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
218 | - if ( ! empty( $located ) ) { |
|
218 | + if (!empty($located)) { |
|
219 | 219 | break; |
220 | 220 | } |
221 | 221 | } |
222 | 222 | |
223 | - if ( ( true == $load ) && ! empty( $located ) ) { |
|
224 | - load_template( $located, $require_once ); |
|
223 | + if ((true == $load) && !empty($located)) { |
|
224 | + load_template($located, $require_once); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | return $located; |
@@ -231,81 +231,81 @@ discard block |
||
231 | 231 | $template_dir = wpinv_get_theme_template_dir_name(); |
232 | 232 | |
233 | 233 | $file_paths = array( |
234 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
235 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
234 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
235 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
236 | 236 | 100 => wpinv_get_templates_dir(), |
237 | 237 | ); |
238 | 238 | |
239 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
239 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
240 | 240 | |
241 | 241 | // sort the file paths based on priority |
242 | - ksort( $file_paths, SORT_NUMERIC ); |
|
242 | + ksort($file_paths, SORT_NUMERIC); |
|
243 | 243 | |
244 | - return array_map( 'trailingslashit', $file_paths ); |
|
244 | + return array_map('trailingslashit', $file_paths); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | function wpinv_checkout_meta_tags() { |
248 | 248 | |
249 | 249 | $pages = array(); |
250 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
251 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
252 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
253 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
250 | + $pages[] = wpinv_get_option('success_page'); |
|
251 | + $pages[] = wpinv_get_option('failure_page'); |
|
252 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
253 | + $pages[] = wpinv_get_option('invoice_subscription_page'); |
|
254 | 254 | |
255 | - if ( ! wpinv_is_checkout() && ! is_page( $pages ) ) { |
|
255 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
256 | 256 | return; |
257 | 257 | } |
258 | 258 | |
259 | 259 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
260 | 260 | } |
261 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
261 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
262 | 262 | |
263 | -function wpinv_add_body_classes( $class ) { |
|
264 | - $classes = (array)$class; |
|
263 | +function wpinv_add_body_classes($class) { |
|
264 | + $classes = (array) $class; |
|
265 | 265 | |
266 | - if ( wpinv_is_checkout() ) { |
|
266 | + if (wpinv_is_checkout()) { |
|
267 | 267 | $classes[] = 'wpinv-checkout'; |
268 | 268 | $classes[] = 'wpinv-page'; |
269 | 269 | } |
270 | 270 | |
271 | - if ( wpinv_is_success_page() ) { |
|
271 | + if (wpinv_is_success_page()) { |
|
272 | 272 | $classes[] = 'wpinv-success'; |
273 | 273 | $classes[] = 'wpinv-page'; |
274 | 274 | } |
275 | 275 | |
276 | - if ( wpinv_is_failed_transaction_page() ) { |
|
276 | + if (wpinv_is_failed_transaction_page()) { |
|
277 | 277 | $classes[] = 'wpinv-failed-transaction'; |
278 | 278 | $classes[] = 'wpinv-page'; |
279 | 279 | } |
280 | 280 | |
281 | - if ( wpinv_is_invoice_history_page() ) { |
|
281 | + if (wpinv_is_invoice_history_page()) { |
|
282 | 282 | $classes[] = 'wpinv-history'; |
283 | 283 | $classes[] = 'wpinv-page'; |
284 | 284 | } |
285 | 285 | |
286 | - if ( wpinv_is_subscriptions_history_page() ) { |
|
286 | + if (wpinv_is_subscriptions_history_page()) { |
|
287 | 287 | $classes[] = 'wpinv-subscription'; |
288 | 288 | $classes[] = 'wpinv-page'; |
289 | 289 | } |
290 | 290 | |
291 | - if ( wpinv_is_test_mode() ) { |
|
291 | + if (wpinv_is_test_mode()) { |
|
292 | 292 | $classes[] = 'wpinv-test-mode'; |
293 | 293 | $classes[] = 'wpinv-page'; |
294 | 294 | } |
295 | 295 | |
296 | - return array_unique( $classes ); |
|
296 | + return array_unique($classes); |
|
297 | 297 | } |
298 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
298 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
299 | 299 | |
300 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
301 | - $current = date( 'Y' ); |
|
302 | - $start_year = $current - absint( $years_before ); |
|
303 | - $end_year = $current + absint( $years_after ); |
|
304 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
300 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
301 | + $current = date('Y'); |
|
302 | + $start_year = $current - absint($years_before); |
|
303 | + $end_year = $current + absint($years_after); |
|
304 | + $selected = empty($selected) ? date('Y') : $selected; |
|
305 | 305 | $options = array(); |
306 | 306 | |
307 | - while ( $start_year <= $end_year ) { |
|
308 | - $options[ absint( $start_year ) ] = $start_year; |
|
307 | + while ($start_year <= $end_year) { |
|
308 | + $options[absint($start_year)] = $start_year; |
|
309 | 309 | $start_year++; |
310 | 310 | } |
311 | 311 | |
@@ -322,25 +322,25 @@ discard block |
||
322 | 322 | return $output; |
323 | 323 | } |
324 | 324 | |
325 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
325 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
326 | 326 | |
327 | 327 | $options = array( |
328 | - '1' => __( 'January', 'invoicing' ), |
|
329 | - '2' => __( 'February', 'invoicing' ), |
|
330 | - '3' => __( 'March', 'invoicing' ), |
|
331 | - '4' => __( 'April', 'invoicing' ), |
|
332 | - '5' => __( 'May', 'invoicing' ), |
|
333 | - '6' => __( 'June', 'invoicing' ), |
|
334 | - '7' => __( 'July', 'invoicing' ), |
|
335 | - '8' => __( 'August', 'invoicing' ), |
|
336 | - '9' => __( 'September', 'invoicing' ), |
|
337 | - '10' => __( 'October', 'invoicing' ), |
|
338 | - '11' => __( 'November', 'invoicing' ), |
|
339 | - '12' => __( 'December', 'invoicing' ), |
|
328 | + '1' => __('January', 'invoicing'), |
|
329 | + '2' => __('February', 'invoicing'), |
|
330 | + '3' => __('March', 'invoicing'), |
|
331 | + '4' => __('April', 'invoicing'), |
|
332 | + '5' => __('May', 'invoicing'), |
|
333 | + '6' => __('June', 'invoicing'), |
|
334 | + '7' => __('July', 'invoicing'), |
|
335 | + '8' => __('August', 'invoicing'), |
|
336 | + '9' => __('September', 'invoicing'), |
|
337 | + '10' => __('October', 'invoicing'), |
|
338 | + '11' => __('November', 'invoicing'), |
|
339 | + '12' => __('December', 'invoicing'), |
|
340 | 340 | ); |
341 | 341 | |
342 | 342 | // If no month is selected, default to the current month |
343 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
343 | + $selected = empty($selected) ? date('n') : $selected; |
|
344 | 344 | |
345 | 345 | $output = wpinv_html_select( |
346 | 346 | array( |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | return $output; |
356 | 356 | } |
357 | 357 | |
358 | -function wpinv_html_select( $args = array() ) { |
|
358 | +function wpinv_html_select($args = array()) { |
|
359 | 359 | $defaults = array( |
360 | 360 | 'options' => array(), |
361 | 361 | 'name' => null, |
@@ -364,8 +364,8 @@ discard block |
||
364 | 364 | 'selected' => 0, |
365 | 365 | 'placeholder' => null, |
366 | 366 | 'multiple' => false, |
367 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
368 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
367 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
368 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
369 | 369 | 'data' => array(), |
370 | 370 | 'onchange' => null, |
371 | 371 | 'required' => false, |
@@ -373,74 +373,74 @@ discard block |
||
373 | 373 | 'readonly' => false, |
374 | 374 | ); |
375 | 375 | |
376 | - $args = wp_parse_args( $args, $defaults ); |
|
376 | + $args = wp_parse_args($args, $defaults); |
|
377 | 377 | |
378 | 378 | $data_elements = ''; |
379 | - foreach ( $args['data'] as $key => $value ) { |
|
380 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
379 | + foreach ($args['data'] as $key => $value) { |
|
380 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
381 | 381 | } |
382 | 382 | |
383 | - if ( $args['multiple'] ) { |
|
383 | + if ($args['multiple']) { |
|
384 | 384 | $multiple = ' MULTIPLE'; |
385 | 385 | } else { |
386 | 386 | $multiple = ''; |
387 | 387 | } |
388 | 388 | |
389 | - if ( $args['placeholder'] ) { |
|
389 | + if ($args['placeholder']) { |
|
390 | 390 | $placeholder = $args['placeholder']; |
391 | 391 | } else { |
392 | 392 | $placeholder = ''; |
393 | 393 | } |
394 | 394 | |
395 | 395 | $options = ''; |
396 | - if ( ! empty( $args['onchange'] ) ) { |
|
397 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
396 | + if (!empty($args['onchange'])) { |
|
397 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
398 | 398 | } |
399 | 399 | |
400 | - if ( ! empty( $args['required'] ) ) { |
|
400 | + if (!empty($args['required'])) { |
|
401 | 401 | $options .= ' required="required"'; |
402 | 402 | } |
403 | 403 | |
404 | - if ( ! empty( $args['disabled'] ) ) { |
|
404 | + if (!empty($args['disabled'])) { |
|
405 | 405 | $options .= ' disabled'; |
406 | 406 | } |
407 | 407 | |
408 | - if ( ! empty( $args['readonly'] ) ) { |
|
408 | + if (!empty($args['readonly'])) { |
|
409 | 409 | $options .= ' readonly'; |
410 | 410 | } |
411 | 411 | |
412 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
413 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
412 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
413 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
414 | 414 | |
415 | - if ( $args['show_option_all'] ) { |
|
416 | - if ( $args['multiple'] ) { |
|
417 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
415 | + if ($args['show_option_all']) { |
|
416 | + if ($args['multiple']) { |
|
417 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
418 | 418 | } else { |
419 | - $selected = selected( $args['selected'], 0, false ); |
|
419 | + $selected = selected($args['selected'], 0, false); |
|
420 | 420 | } |
421 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
421 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
422 | 422 | } |
423 | 423 | |
424 | - if ( ! empty( $args['options'] ) ) { |
|
424 | + if (!empty($args['options'])) { |
|
425 | 425 | |
426 | - if ( $args['show_option_none'] ) { |
|
427 | - if ( $args['multiple'] ) { |
|
428 | - $selected = selected( true, in_array( '', $args['selected'] ), false ); |
|
426 | + if ($args['show_option_none']) { |
|
427 | + if ($args['multiple']) { |
|
428 | + $selected = selected(true, in_array('', $args['selected']), false); |
|
429 | 429 | } else { |
430 | - $selected = selected( $args['selected'] === '', true, false ); |
|
430 | + $selected = selected($args['selected'] === '', true, false); |
|
431 | 431 | } |
432 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
432 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
433 | 433 | } |
434 | 434 | |
435 | - foreach ( $args['options'] as $key => $option ) { |
|
435 | + foreach ($args['options'] as $key => $option) { |
|
436 | 436 | |
437 | - if ( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
438 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
437 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
438 | + $selected = selected(true, (bool) in_array($key, $args['selected']), false); |
|
439 | 439 | } else { |
440 | - $selected = selected( $args['selected'], $key, false ); |
|
440 | + $selected = selected($args['selected'], $key, false); |
|
441 | 441 | } |
442 | 442 | |
443 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
443 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
444 | 444 | } |
445 | 445 | } |
446 | 446 | |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | return $output; |
450 | 450 | } |
451 | 451 | |
452 | -function wpinv_item_dropdown( $args = array() ) { |
|
452 | +function wpinv_item_dropdown($args = array()) { |
|
453 | 453 | $defaults = array( |
454 | 454 | 'name' => 'wpi_item', |
455 | 455 | 'id' => 'wpi_item', |
@@ -457,14 +457,14 @@ discard block |
||
457 | 457 | 'multiple' => false, |
458 | 458 | 'selected' => 0, |
459 | 459 | 'number' => -1, |
460 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
461 | - 'data' => array( 'search-type' => 'item' ), |
|
460 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
461 | + 'data' => array('search-type' => 'item'), |
|
462 | 462 | 'show_option_all' => false, |
463 | 463 | 'show_option_none' => false, |
464 | 464 | 'show_recurring' => false, |
465 | 465 | ); |
466 | 466 | |
467 | - $args = wp_parse_args( $args, $defaults ); |
|
467 | + $args = wp_parse_args($args, $defaults); |
|
468 | 468 | |
469 | 469 | $item_args = array( |
470 | 470 | 'post_type' => 'wpi_item', |
@@ -473,40 +473,40 @@ discard block |
||
473 | 473 | 'posts_per_page' => $args['number'], |
474 | 474 | ); |
475 | 475 | |
476 | - $item_args = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults ); |
|
476 | + $item_args = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults); |
|
477 | 477 | |
478 | - $items = get_posts( $item_args ); |
|
478 | + $items = get_posts($item_args); |
|
479 | 479 | $options = array(); |
480 | - if ( $items ) { |
|
481 | - foreach ( $items as $item ) { |
|
482 | - $title = esc_html( $item->post_title ); |
|
480 | + if ($items) { |
|
481 | + foreach ($items as $item) { |
|
482 | + $title = esc_html($item->post_title); |
|
483 | 483 | |
484 | - if ( ! empty( $args['show_recurring'] ) ) { |
|
485 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
484 | + if (!empty($args['show_recurring'])) { |
|
485 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
486 | 486 | } |
487 | 487 | |
488 | - $options[ absint( $item->ID ) ] = $title; |
|
488 | + $options[absint($item->ID)] = $title; |
|
489 | 489 | } |
490 | 490 | } |
491 | 491 | |
492 | 492 | // This ensures that any selected items are included in the drop down |
493 | - if ( is_array( $args['selected'] ) ) { |
|
494 | - foreach ( $args['selected'] as $item ) { |
|
495 | - if ( ! in_array( $item, $options ) ) { |
|
496 | - $title = get_the_title( $item ); |
|
497 | - if ( ! empty( $args['show_recurring'] ) ) { |
|
498 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
493 | + if (is_array($args['selected'])) { |
|
494 | + foreach ($args['selected'] as $item) { |
|
495 | + if (!in_array($item, $options)) { |
|
496 | + $title = get_the_title($item); |
|
497 | + if (!empty($args['show_recurring'])) { |
|
498 | + $title .= wpinv_get_item_suffix($item, false); |
|
499 | 499 | } |
500 | - $options[ $item ] = $title; |
|
500 | + $options[$item] = $title; |
|
501 | 501 | } |
502 | 502 | } |
503 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
504 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
505 | - $title = get_the_title( $args['selected'] ); |
|
506 | - if ( ! empty( $args['show_recurring'] ) ) { |
|
507 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
503 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
504 | + if (!in_array($args['selected'], $options)) { |
|
505 | + $title = get_the_title($args['selected']); |
|
506 | + if (!empty($args['show_recurring'])) { |
|
507 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
508 | 508 | } |
509 | - $options[ $args['selected'] ] = get_the_title( $args['selected'] ); |
|
509 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
510 | 510 | } |
511 | 511 | } |
512 | 512 | |
@@ -543,16 +543,16 @@ discard block |
||
543 | 543 | ); |
544 | 544 | |
545 | 545 | $options = array(); |
546 | - if ( $items ) { |
|
547 | - foreach ( $items as $item ) { |
|
548 | - $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false ); |
|
546 | + if ($items) { |
|
547 | + foreach ($items as $item) { |
|
548 | + $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false); |
|
549 | 549 | } |
550 | 550 | } |
551 | 551 | |
552 | 552 | return $options; |
553 | 553 | } |
554 | 554 | |
555 | -function wpinv_html_checkbox( $args = array() ) { |
|
555 | +function wpinv_html_checkbox($args = array()) { |
|
556 | 556 | $defaults = array( |
557 | 557 | 'name' => null, |
558 | 558 | 'current' => null, |
@@ -563,17 +563,17 @@ discard block |
||
563 | 563 | ), |
564 | 564 | ); |
565 | 565 | |
566 | - $args = wp_parse_args( $args, $defaults ); |
|
566 | + $args = wp_parse_args($args, $defaults); |
|
567 | 567 | |
568 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
568 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
569 | 569 | $attr = ''; |
570 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
570 | + if (!empty($args['options']['disabled'])) { |
|
571 | 571 | $attr .= ' disabled="disabled"'; |
572 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
572 | + } elseif (!empty($args['options']['readonly'])) { |
|
573 | 573 | $attr .= ' readonly'; |
574 | 574 | } |
575 | 575 | |
576 | - $output = '<input type="checkbox"' . $attr . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . esc_attr( $class ) . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
576 | + $output = '<input type="checkbox"' . $attr . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . esc_attr($class) . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
577 | 577 | |
578 | 578 | return $output; |
579 | 579 | } |
@@ -581,34 +581,34 @@ discard block |
||
581 | 581 | /** |
582 | 582 | * Displays a hidden field. |
583 | 583 | */ |
584 | -function getpaid_hidden_field( $name, $value ) { |
|
585 | - echo "<input type='hidden' name='" . esc_attr( $name ) . "' value=' " . esc_attr( $value ) . "' />"; |
|
584 | +function getpaid_hidden_field($name, $value) { |
|
585 | + echo "<input type='hidden' name='" . esc_attr($name) . "' value=' " . esc_attr($value) . "' />"; |
|
586 | 586 | } |
587 | 587 | |
588 | 588 | /** |
589 | 589 | * Displays a submit field. |
590 | 590 | */ |
591 | -function getpaid_submit_field( $value, $name = 'submit', $class = 'btn-primary' ) { |
|
592 | - echo "<input type='submit' name='" . esc_attr( $name ) . "' value='" . esc_attr( $value ) . "' class='btn " . esc_attr( $class ) . "' />"; |
|
591 | +function getpaid_submit_field($value, $name = 'submit', $class = 'btn-primary') { |
|
592 | + echo "<input type='submit' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' class='btn " . esc_attr($class) . "' />"; |
|
593 | 593 | } |
594 | 594 | |
595 | -function wpinv_html_text( $args = array() ) { |
|
595 | +function wpinv_html_text($args = array()) { |
|
596 | 596 | // Backwards compatibility |
597 | - if ( func_num_args() > 1 ) { |
|
597 | + if (func_num_args() > 1) { |
|
598 | 598 | $args = func_get_args(); |
599 | 599 | |
600 | 600 | $name = $args[0]; |
601 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
602 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
603 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
601 | + $value = isset($args[1]) ? $args[1] : ''; |
|
602 | + $label = isset($args[2]) ? $args[2] : ''; |
|
603 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | $defaults = array( |
607 | 607 | 'id' => '', |
608 | - 'name' => isset( $name ) ? $name : 'text', |
|
609 | - 'value' => isset( $value ) ? $value : null, |
|
610 | - 'label' => isset( $label ) ? $label : null, |
|
611 | - 'desc' => isset( $desc ) ? $desc : null, |
|
608 | + 'name' => isset($name) ? $name : 'text', |
|
609 | + 'value' => isset($value) ? $value : null, |
|
610 | + 'label' => isset($label) ? $label : null, |
|
611 | + 'desc' => isset($desc) ? $desc : null, |
|
612 | 612 | 'placeholder' => '', |
613 | 613 | 'class' => 'regular-text', |
614 | 614 | 'disabled' => false, |
@@ -618,41 +618,41 @@ discard block |
||
618 | 618 | 'data' => false, |
619 | 619 | ); |
620 | 620 | |
621 | - $args = wp_parse_args( $args, $defaults ); |
|
621 | + $args = wp_parse_args($args, $defaults); |
|
622 | 622 | |
623 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
623 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
624 | 624 | $options = ''; |
625 | - if ( $args['required'] ) { |
|
625 | + if ($args['required']) { |
|
626 | 626 | $options .= ' required="required"'; |
627 | 627 | } |
628 | - if ( $args['readonly'] ) { |
|
628 | + if ($args['readonly']) { |
|
629 | 629 | $options .= ' readonly'; |
630 | 630 | } |
631 | - if ( $args['readonly'] ) { |
|
631 | + if ($args['readonly']) { |
|
632 | 632 | $options .= ' readonly'; |
633 | 633 | } |
634 | 634 | |
635 | 635 | $data = ''; |
636 | - if ( ! empty( $args['data'] ) ) { |
|
637 | - foreach ( $args['data'] as $key => $value ) { |
|
638 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
636 | + if (!empty($args['data'])) { |
|
637 | + foreach ($args['data'] as $key => $value) { |
|
638 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
639 | 639 | } |
640 | 640 | } |
641 | 641 | |
642 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
643 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
644 | - if ( ! empty( $args['desc'] ) ) { |
|
645 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
642 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
643 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
644 | + if (!empty($args['desc'])) { |
|
645 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
646 | 646 | } |
647 | 647 | |
648 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
648 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
649 | 649 | |
650 | 650 | $output .= '</span>'; |
651 | 651 | |
652 | 652 | return $output; |
653 | 653 | } |
654 | 654 | |
655 | -function wpinv_html_textarea( $args = array() ) { |
|
655 | +function wpinv_html_textarea($args = array()) { |
|
656 | 656 | $defaults = array( |
657 | 657 | 'name' => 'textarea', |
658 | 658 | 'value' => null, |
@@ -663,31 +663,31 @@ discard block |
||
663 | 663 | 'placeholder' => '', |
664 | 664 | ); |
665 | 665 | |
666 | - $args = wp_parse_args( $args, $defaults ); |
|
666 | + $args = wp_parse_args($args, $defaults); |
|
667 | 667 | |
668 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
668 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
669 | 669 | $disabled = ''; |
670 | - if ( $args['disabled'] ) { |
|
670 | + if ($args['disabled']) { |
|
671 | 671 | $disabled = ' disabled="disabled"'; |
672 | 672 | } |
673 | 673 | |
674 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
675 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
676 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
674 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
675 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
676 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
677 | 677 | |
678 | - if ( ! empty( $args['desc'] ) ) { |
|
679 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
678 | + if (!empty($args['desc'])) { |
|
679 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
680 | 680 | } |
681 | 681 | $output .= '</span>'; |
682 | 682 | |
683 | 683 | return $output; |
684 | 684 | } |
685 | 685 | |
686 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
686 | +function wpinv_html_ajax_user_search($args = array()) { |
|
687 | 687 | $defaults = array( |
688 | 688 | 'name' => 'user_id', |
689 | 689 | 'value' => null, |
690 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
690 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
691 | 691 | 'label' => null, |
692 | 692 | 'desc' => null, |
693 | 693 | 'class' => '', |
@@ -696,13 +696,13 @@ discard block |
||
696 | 696 | 'data' => false, |
697 | 697 | ); |
698 | 698 | |
699 | - $args = wp_parse_args( $args, $defaults ); |
|
699 | + $args = wp_parse_args($args, $defaults); |
|
700 | 700 | |
701 | 701 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
702 | 702 | |
703 | 703 | $output = '<span class="wpinv_user_search_wrap">'; |
704 | - $output .= wpinv_html_text( $args ); |
|
705 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
704 | + $output .= wpinv_html_text($args); |
|
705 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
706 | 706 | $output .= '</span>'; |
707 | 707 | |
708 | 708 | return $output; |
@@ -713,44 +713,44 @@ discard block |
||
713 | 713 | * |
714 | 714 | * @param string $template the template that is currently being used. |
715 | 715 | */ |
716 | -function wpinv_template( $template ) { |
|
716 | +function wpinv_template($template) { |
|
717 | 717 | global $post; |
718 | 718 | |
719 | - if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) { |
|
719 | + if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) { |
|
720 | 720 | |
721 | 721 | // If the user can view this invoice, display it. |
722 | - if ( wpinv_user_can_view_invoice( $post->ID ) ) { |
|
722 | + if (wpinv_user_can_view_invoice($post->ID)) { |
|
723 | 723 | |
724 | - return wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
724 | + return wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
725 | 725 | |
726 | 726 | // Else display an error message. |
727 | 727 | } else { |
728 | 728 | |
729 | - return wpinv_get_template_part( 'wpinv-invalid-access', false, false ); |
|
729 | + return wpinv_get_template_part('wpinv-invalid-access', false, false); |
|
730 | 730 | |
731 | 731 | } |
732 | 732 | } |
733 | 733 | |
734 | 734 | return $template; |
735 | 735 | } |
736 | -add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
736 | +add_filter('template_include', 'wpinv_template', 10, 1); |
|
737 | 737 | |
738 | 738 | function wpinv_get_business_address() { |
739 | 739 | $business_address = wpinv_store_address(); |
740 | - $business_address = ! empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
740 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
741 | 741 | |
742 | 742 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
743 | 743 | |
744 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
744 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
745 | 745 | } |
746 | 746 | |
747 | 747 | /** |
748 | 748 | * Displays the company address. |
749 | 749 | */ |
750 | 750 | function wpinv_display_from_address() { |
751 | - wpinv_get_template( 'invoice/company-address.php' ); |
|
751 | + wpinv_get_template('invoice/company-address.php'); |
|
752 | 752 | } |
753 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 ); |
|
753 | +add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10); |
|
754 | 754 | |
755 | 755 | /** |
756 | 756 | * Generates a watermark text for an invoice. |
@@ -758,9 +758,9 @@ discard block |
||
758 | 758 | * @param WPInv_Invoice $invoice |
759 | 759 | * @return string |
760 | 760 | */ |
761 | -function wpinv_watermark( $invoice ) { |
|
762 | - $watermark = wpinv_get_watermark( $invoice ); |
|
763 | - return apply_filters( 'wpinv_get_watermark', $watermark, $invoice ); |
|
761 | +function wpinv_watermark($invoice) { |
|
762 | + $watermark = wpinv_get_watermark($invoice); |
|
763 | + return apply_filters('wpinv_get_watermark', $watermark, $invoice); |
|
764 | 764 | } |
765 | 765 | |
766 | 766 | /** |
@@ -769,37 +769,37 @@ discard block |
||
769 | 769 | * @param WPInv_Invoice $invoice |
770 | 770 | * @return string |
771 | 771 | */ |
772 | -function wpinv_get_watermark( $invoice ) { |
|
772 | +function wpinv_get_watermark($invoice) { |
|
773 | 773 | return $invoice->get_status_nicename(); |
774 | 774 | } |
775 | 775 | |
776 | 776 | /** |
777 | 777 | * @deprecated |
778 | 778 | */ |
779 | -function wpinv_display_invoice_details( $invoice ) { |
|
780 | - return getpaid_invoice_meta( $invoice ); |
|
779 | +function wpinv_display_invoice_details($invoice) { |
|
780 | + return getpaid_invoice_meta($invoice); |
|
781 | 781 | } |
782 | 782 | |
783 | 783 | /** |
784 | 784 | * Displays invoice meta. |
785 | 785 | */ |
786 | -function getpaid_invoice_meta( $invoice ) { |
|
786 | +function getpaid_invoice_meta($invoice) { |
|
787 | 787 | |
788 | - $invoice = new WPInv_Invoice( $invoice ); |
|
788 | + $invoice = new WPInv_Invoice($invoice); |
|
789 | 789 | |
790 | 790 | // Ensure that we have an invoice. |
791 | - if ( 0 == $invoice->get_id() ) { |
|
791 | + if (0 == $invoice->get_id()) { |
|
792 | 792 | return; |
793 | 793 | } |
794 | 794 | |
795 | 795 | // Get the invoice meta. |
796 | - $meta = getpaid_get_invoice_meta( $invoice ); |
|
796 | + $meta = getpaid_get_invoice_meta($invoice); |
|
797 | 797 | |
798 | 798 | // Display the meta. |
799 | - wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) ); |
|
799 | + wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta')); |
|
800 | 800 | |
801 | 801 | } |
802 | -add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 ); |
|
802 | +add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10); |
|
803 | 803 | |
804 | 804 | /** |
805 | 805 | * Retrieves the address markup to use on Invoices. |
@@ -811,29 +811,29 @@ discard block |
||
811 | 811 | * @param string $separator How to separate address lines. |
812 | 812 | * @return string |
813 | 813 | */ |
814 | -function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) { |
|
814 | +function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') { |
|
815 | 815 | |
816 | 816 | // Retrieve the address markup... |
817 | - $country = empty( $billing_details['country'] ) ? '' : $billing_details['country']; |
|
818 | - $format = wpinv_get_full_address_format( $country ); |
|
817 | + $country = empty($billing_details['country']) ? '' : $billing_details['country']; |
|
818 | + $format = wpinv_get_full_address_format($country); |
|
819 | 819 | |
820 | 820 | // ... and the replacements. |
821 | - $replacements = wpinv_get_invoice_address_replacements( $billing_details ); |
|
821 | + $replacements = wpinv_get_invoice_address_replacements($billing_details); |
|
822 | 822 | |
823 | - $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
|
823 | + $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format); |
|
824 | 824 | |
825 | 825 | // Remove unavailable tags. |
826 | - $formatted_address = preg_replace( '/\{\{\w+\}\}/', '', $formatted_address ); |
|
826 | + $formatted_address = preg_replace('/\{\{\w+\}\}/', '', $formatted_address); |
|
827 | 827 | |
828 | 828 | // Clean up white space. |
829 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
830 | - $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
|
829 | + $formatted_address = preg_replace('/ +/', ' ', trim($formatted_address)); |
|
830 | + $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address); |
|
831 | 831 | |
832 | 832 | // Break newlines apart and remove empty lines/trim commas and white space. |
833 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
833 | + $formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address))); |
|
834 | 834 | |
835 | 835 | // Add html breaks. |
836 | - $formatted_address = implode( $separator, $formatted_address ); |
|
836 | + $formatted_address = implode($separator, $formatted_address); |
|
837 | 837 | |
838 | 838 | // We're done! |
839 | 839 | return $formatted_address; |
@@ -845,119 +845,119 @@ discard block |
||
845 | 845 | * |
846 | 846 | * @param WPInv_Invoice $invoice |
847 | 847 | */ |
848 | -function wpinv_display_to_address( $invoice = 0 ) { |
|
849 | - if ( ! empty( $invoice ) ) { |
|
850 | - wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) ); |
|
848 | +function wpinv_display_to_address($invoice = 0) { |
|
849 | + if (!empty($invoice)) { |
|
850 | + wpinv_get_template('invoice/billing-address.php', compact('invoice')); |
|
851 | 851 | } |
852 | 852 | } |
853 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 ); |
|
853 | +add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40); |
|
854 | 854 | |
855 | 855 | |
856 | 856 | /** |
857 | 857 | * Displays invoice line items. |
858 | 858 | */ |
859 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
859 | +function wpinv_display_line_items($invoice_id = 0) { |
|
860 | 860 | |
861 | 861 | // Prepare the invoice. |
862 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
862 | + $invoice = new WPInv_Invoice($invoice_id); |
|
863 | 863 | |
864 | 864 | // Abort if there is no invoice. |
865 | - if ( 0 == $invoice->get_id() ) { |
|
865 | + if (0 == $invoice->get_id()) { |
|
866 | 866 | return; |
867 | 867 | } |
868 | 868 | |
869 | 869 | // Line item columns. |
870 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
871 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
870 | + $columns = getpaid_invoice_item_columns($invoice); |
|
871 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
872 | 872 | |
873 | - wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) ); |
|
873 | + wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns')); |
|
874 | 874 | } |
875 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 ); |
|
875 | +add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10); |
|
876 | 876 | |
877 | 877 | /** |
878 | 878 | * Displays invoice subscriptions. |
879 | 879 | * |
880 | 880 | * @param WPInv_Invoice $invoice |
881 | 881 | */ |
882 | -function getpaid_display_invoice_subscriptions( $invoice ) { |
|
882 | +function getpaid_display_invoice_subscriptions($invoice) { |
|
883 | 883 | |
884 | 884 | // Subscriptions. |
885 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
885 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
886 | 886 | |
887 | - if ( empty( $subscriptions ) || ! $invoice->is_recurring() ) { |
|
887 | + if (empty($subscriptions) || !$invoice->is_recurring()) { |
|
888 | 888 | return; |
889 | 889 | } |
890 | 890 | |
891 | - $main_subscription = getpaid_get_invoice_subscription( $invoice ); |
|
891 | + $main_subscription = getpaid_get_invoice_subscription($invoice); |
|
892 | 892 | |
893 | 893 | // Display related subscriptions. |
894 | - if ( is_array( $subscriptions ) ) { |
|
895 | - printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Subscriptions', 'invoicing' ) ); |
|
896 | - getpaid_admin_subscription_related_subscriptions_metabox( $main_subscription, false ); |
|
894 | + if (is_array($subscriptions)) { |
|
895 | + printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Subscriptions', 'invoicing')); |
|
896 | + getpaid_admin_subscription_related_subscriptions_metabox($main_subscription, false); |
|
897 | 897 | } |
898 | 898 | |
899 | - if ( $main_subscription->get_total_payments() > 1 ) { |
|
900 | - printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Invoices', 'invoicing' ) ); |
|
901 | - getpaid_admin_subscription_invoice_details_metabox( $main_subscription, false ); |
|
899 | + if ($main_subscription->get_total_payments() > 1) { |
|
900 | + printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Invoices', 'invoicing')); |
|
901 | + getpaid_admin_subscription_invoice_details_metabox($main_subscription, false); |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | } |
905 | -add_action( 'getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 55 ); |
|
906 | -add_action( 'wpinv_receipt_end', 'getpaid_display_invoice_subscriptions', 11 ); |
|
905 | +add_action('getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 55); |
|
906 | +add_action('wpinv_receipt_end', 'getpaid_display_invoice_subscriptions', 11); |
|
907 | 907 | |
908 | 908 | /** |
909 | 909 | * Displays invoice notices on invoices. |
910 | 910 | */ |
911 | 911 | function wpinv_display_invoice_notice() { |
912 | 912 | |
913 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
914 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
913 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
914 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
915 | 915 | |
916 | - if ( empty( $label ) && empty( $notice ) ) { |
|
916 | + if (empty($label) && empty($notice)) { |
|
917 | 917 | return; |
918 | 918 | } |
919 | 919 | |
920 | 920 | echo '<div class="mt-4 mb-4 wpinv-vat-notice">'; |
921 | 921 | |
922 | - if ( ! empty( $label ) ) { |
|
923 | - $label = esc_html( $label ); |
|
922 | + if (!empty($label)) { |
|
923 | + $label = esc_html($label); |
|
924 | 924 | echo "<h5>$label</h5>"; |
925 | 925 | } |
926 | 926 | |
927 | - if ( ! empty( $notice ) ) { |
|
928 | - echo '<small class="form-text text-muted">' . wp_kses_post( wpautop( wptexturize( $notice ) ) ) . '</small>'; |
|
927 | + if (!empty($notice)) { |
|
928 | + echo '<small class="form-text text-muted">' . wp_kses_post(wpautop(wptexturize($notice))) . '</small>'; |
|
929 | 929 | } |
930 | 930 | |
931 | 931 | echo '</div>'; |
932 | 932 | } |
933 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 ); |
|
933 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100); |
|
934 | 934 | |
935 | 935 | /** |
936 | 936 | * @param WPInv_Invoice $invoice |
937 | 937 | */ |
938 | -function wpinv_display_invoice_notes( $invoice ) { |
|
938 | +function wpinv_display_invoice_notes($invoice) { |
|
939 | 939 | |
940 | 940 | // Retrieve the notes. |
941 | - $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' ); |
|
941 | + $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer'); |
|
942 | 942 | |
943 | 943 | // Abort if we have non. |
944 | - if ( empty( $notes ) ) { |
|
944 | + if (empty($notes)) { |
|
945 | 945 | return; |
946 | 946 | } |
947 | 947 | |
948 | 948 | // Echo the note. |
949 | 949 | echo '<div class="getpaid-invoice-notes-wrapper position-relative my-4">'; |
950 | - echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . __( 'Notes', 'invoicing' ) . '</h2>'; |
|
950 | + echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . __('Notes', 'invoicing') . '</h2>'; |
|
951 | 951 | echo '<ul class="getpaid-invoice-notes text-break overflow-auto list-unstyled p-0 m-0">'; |
952 | 952 | |
953 | - foreach ( $notes as $note ) { |
|
954 | - wpinv_get_invoice_note_line_item( $note ); |
|
953 | + foreach ($notes as $note) { |
|
954 | + wpinv_get_invoice_note_line_item($note); |
|
955 | 955 | } |
956 | 956 | |
957 | 957 | echo '</ul>'; |
958 | 958 | echo '</div>'; |
959 | 959 | } |
960 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 ); |
|
960 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60); |
|
961 | 961 | |
962 | 962 | /** |
963 | 963 | * Loads scripts on our invoice templates. |
@@ -965,32 +965,32 @@ discard block |
||
965 | 965 | function wpinv_display_style() { |
966 | 966 | |
967 | 967 | // Make sure that all scripts have been loaded. |
968 | - if ( ! did_action( 'wp_enqueue_scripts' ) ) { |
|
969 | - do_action( 'wp_enqueue_scripts' ); |
|
968 | + if (!did_action('wp_enqueue_scripts')) { |
|
969 | + do_action('wp_enqueue_scripts'); |
|
970 | 970 | } |
971 | 971 | |
972 | 972 | // Register the invoices style. |
973 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) ); |
|
973 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css')); |
|
974 | 974 | |
975 | 975 | // Load required styles |
976 | - wp_print_styles( 'wpinv-single-style' ); |
|
977 | - wp_print_styles( 'ayecode-ui' ); |
|
976 | + wp_print_styles('wpinv-single-style'); |
|
977 | + wp_print_styles('ayecode-ui'); |
|
978 | 978 | |
979 | 979 | // Maybe load custom css. |
980 | - $custom_css = wpinv_get_option( 'template_custom_css' ); |
|
980 | + $custom_css = wpinv_get_option('template_custom_css'); |
|
981 | 981 | |
982 | - if ( isset( $custom_css ) && ! empty( $custom_css ) ) { |
|
983 | - $custom_css = wp_kses( $custom_css, array( '\'', '\"' ) ); |
|
984 | - $custom_css = str_replace( '>', '>', $custom_css ); |
|
982 | + if (isset($custom_css) && !empty($custom_css)) { |
|
983 | + $custom_css = wp_kses($custom_css, array('\'', '\"')); |
|
984 | + $custom_css = str_replace('>', '>', $custom_css); |
|
985 | 985 | echo '<style type="text/css">'; |
986 | - echo wp_kses_post( $custom_css ); |
|
986 | + echo wp_kses_post($custom_css); |
|
987 | 987 | echo '</style>'; |
988 | 988 | } |
989 | 989 | |
990 | 990 | wp_site_icon(); |
991 | 991 | } |
992 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
993 | -add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' ); |
|
992 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
993 | +add_action('wpinv_invalid_invoice_head', 'wpinv_display_style'); |
|
994 | 994 | |
995 | 995 | |
996 | 996 | /** |
@@ -1002,41 +1002,41 @@ discard block |
||
1002 | 1002 | // Retrieve the current invoice. |
1003 | 1003 | $invoice_id = getpaid_get_current_invoice_id(); |
1004 | 1004 | |
1005 | - if ( empty( $invoice_id ) ) { |
|
1005 | + if (empty($invoice_id)) { |
|
1006 | 1006 | |
1007 | 1007 | return aui()->alert( |
1008 | 1008 | array( |
1009 | 1009 | 'type' => 'warning', |
1010 | - 'content' => __( 'Invalid invoice', 'invoicing' ), |
|
1010 | + 'content' => __('Invalid invoice', 'invoicing'), |
|
1011 | 1011 | ) |
1012 | 1012 | ); |
1013 | 1013 | |
1014 | 1014 | } |
1015 | 1015 | |
1016 | 1016 | // Can the user view this invoice? |
1017 | - if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) { |
|
1017 | + if (!wpinv_user_can_view_invoice($invoice_id)) { |
|
1018 | 1018 | |
1019 | 1019 | return aui()->alert( |
1020 | 1020 | array( |
1021 | 1021 | 'type' => 'warning', |
1022 | - 'content' => __( 'You are not allowed to view this invoice', 'invoicing' ), |
|
1022 | + 'content' => __('You are not allowed to view this invoice', 'invoicing'), |
|
1023 | 1023 | ) |
1024 | 1024 | ); |
1025 | 1025 | |
1026 | 1026 | } |
1027 | 1027 | |
1028 | 1028 | // Ensure that it is not yet paid for. |
1029 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
1029 | + $invoice = new WPInv_Invoice($invoice_id); |
|
1030 | 1030 | |
1031 | 1031 | // Maybe mark it as viewed. |
1032 | - getpaid_maybe_mark_invoice_as_viewed( $invoice ); |
|
1032 | + getpaid_maybe_mark_invoice_as_viewed($invoice); |
|
1033 | 1033 | |
1034 | - if ( $invoice->is_paid() ) { |
|
1034 | + if ($invoice->is_paid()) { |
|
1035 | 1035 | |
1036 | 1036 | return aui()->alert( |
1037 | 1037 | array( |
1038 | 1038 | 'type' => 'success', |
1039 | - 'content' => __( 'This invoice has already been paid.', 'invoicing' ), |
|
1039 | + 'content' => __('This invoice has already been paid.', 'invoicing'), |
|
1040 | 1040 | ) |
1041 | 1041 | ); |
1042 | 1042 | |
@@ -1046,15 +1046,15 @@ discard block |
||
1046 | 1046 | $wpi_checkout_id = $invoice_id; |
1047 | 1047 | |
1048 | 1048 | // Retrieve appropriate payment form. |
1049 | - $payment_form = new GetPaid_Payment_Form( $invoice->get_meta( 'force_payment_form' ) ); |
|
1050 | - $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1049 | + $payment_form = new GetPaid_Payment_Form($invoice->get_meta('force_payment_form')); |
|
1050 | + $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1051 | 1051 | |
1052 | - if ( ! $payment_form->exists() ) { |
|
1052 | + if (!$payment_form->exists()) { |
|
1053 | 1053 | |
1054 | 1054 | return aui()->alert( |
1055 | 1055 | array( |
1056 | 1056 | 'type' => 'warning', |
1057 | - 'content' => __( 'Error loading the payment form', 'invoicing' ), |
|
1057 | + 'content' => __('Error loading the payment form', 'invoicing'), |
|
1058 | 1058 | ) |
1059 | 1059 | ); |
1060 | 1060 | |
@@ -1063,29 +1063,29 @@ discard block |
||
1063 | 1063 | // Set the invoice. |
1064 | 1064 | $payment_form->invoice = $invoice; |
1065 | 1065 | |
1066 | - if ( ! $payment_form->is_default() ) { |
|
1066 | + if (!$payment_form->is_default()) { |
|
1067 | 1067 | |
1068 | 1068 | $items = array(); |
1069 | 1069 | $item_ids = array(); |
1070 | 1070 | |
1071 | - foreach ( $invoice->get_items() as $item ) { |
|
1072 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
1071 | + foreach ($invoice->get_items() as $item) { |
|
1072 | + if (!in_array($item->get_id(), $item_ids)) { |
|
1073 | 1073 | $item_ids[] = $item->get_id(); |
1074 | 1074 | $items[] = $item; |
1075 | 1075 | } |
1076 | 1076 | } |
1077 | 1077 | |
1078 | - foreach ( $payment_form->get_items() as $item ) { |
|
1079 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
1078 | + foreach ($payment_form->get_items() as $item) { |
|
1079 | + if (!in_array($item->get_id(), $item_ids)) { |
|
1080 | 1080 | $item_ids[] = $item->get_id(); |
1081 | 1081 | $items[] = $item; |
1082 | 1082 | } |
1083 | 1083 | } |
1084 | 1084 | |
1085 | - $payment_form->set_items( $items ); |
|
1085 | + $payment_form->set_items($items); |
|
1086 | 1086 | |
1087 | 1087 | } else { |
1088 | - $payment_form->set_items( $invoice->get_items() ); |
|
1088 | + $payment_form->set_items($invoice->get_items()); |
|
1089 | 1089 | } |
1090 | 1090 | |
1091 | 1091 | // Generate the html. |
@@ -1094,7 +1094,7 @@ discard block |
||
1094 | 1094 | } |
1095 | 1095 | |
1096 | 1096 | function wpinv_empty_cart_message() { |
1097 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1097 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1098 | 1098 | } |
1099 | 1099 | |
1100 | 1100 | /** |
@@ -1112,76 +1112,76 @@ discard block |
||
1112 | 1112 | true |
1113 | 1113 | ); |
1114 | 1114 | } |
1115 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1115 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1116 | 1116 | |
1117 | 1117 | /** |
1118 | 1118 | * Filters the receipt page. |
1119 | 1119 | */ |
1120 | -function wpinv_filter_success_page_content( $content ) { |
|
1120 | +function wpinv_filter_success_page_content($content) { |
|
1121 | 1121 | |
1122 | 1122 | // Maybe abort early. |
1123 | - if ( is_admin() || ! is_singular() || ! in_the_loop() || ! is_main_query() || is_preview() ) { |
|
1123 | + if (is_admin() || !is_singular() || !in_the_loop() || !is_main_query() || is_preview()) { |
|
1124 | 1124 | return $content; |
1125 | 1125 | } |
1126 | 1126 | |
1127 | 1127 | // Ensure this is our page. |
1128 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1128 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1129 | 1129 | |
1130 | - $gateway = sanitize_text_field( $_GET['payment-confirm'] ); |
|
1131 | - return apply_filters( "wpinv_payment_confirm_$gateway", $content ); |
|
1130 | + $gateway = sanitize_text_field($_GET['payment-confirm']); |
|
1131 | + return apply_filters("wpinv_payment_confirm_$gateway", $content); |
|
1132 | 1132 | |
1133 | 1133 | } |
1134 | 1134 | |
1135 | 1135 | return $content; |
1136 | 1136 | } |
1137 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1137 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1138 | 1138 | |
1139 | -function wpinv_invoice_link( $invoice_id ) { |
|
1140 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1139 | +function wpinv_invoice_link($invoice_id) { |
|
1140 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1141 | 1141 | |
1142 | - if ( empty( $invoice ) ) { |
|
1142 | + if (empty($invoice)) { |
|
1143 | 1143 | return null; |
1144 | 1144 | } |
1145 | 1145 | |
1146 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1146 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1147 | 1147 | |
1148 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1148 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1149 | 1149 | } |
1150 | 1150 | |
1151 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
1152 | - if ( empty( $note ) ) { |
|
1151 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
1152 | + if (empty($note)) { |
|
1153 | 1153 | return null; |
1154 | 1154 | } |
1155 | 1155 | |
1156 | - if ( is_int( $note ) ) { |
|
1157 | - $note = get_comment( $note ); |
|
1156 | + if (is_int($note)) { |
|
1157 | + $note = get_comment($note); |
|
1158 | 1158 | } |
1159 | 1159 | |
1160 | - if ( ! ( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
1160 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
1161 | 1161 | return null; |
1162 | 1162 | } |
1163 | 1163 | |
1164 | - $note_classes = array( 'note' ); |
|
1165 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
1164 | + $note_classes = array('note'); |
|
1165 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
1166 | 1166 | $note_classes[] = $note->comment_author === 'System' ? 'system-note' : ''; |
1167 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
1168 | - $note_classes = ! empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
1167 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
1168 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
1169 | 1169 | |
1170 | 1170 | ob_start(); |
1171 | 1171 | ?> |
1172 | - <li rel="<?php echo absint( $note->comment_ID ); ?>" class="<?php echo esc_attr( $note_classes ); ?> mb-2"> |
|
1172 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mb-2"> |
|
1173 | 1173 | <div class="note_content"> |
1174 | 1174 | |
1175 | - <?php echo wptexturize( wp_kses_post( $note->comment_content ) ); ?> |
|
1175 | + <?php echo wptexturize(wp_kses_post($note->comment_content)); ?> |
|
1176 | 1176 | |
1177 | - <?php if ( ! is_admin() ) : ?> |
|
1177 | + <?php if (!is_admin()) : ?> |
|
1178 | 1178 | <em class="small form-text text-muted mt-0"> |
1179 | 1179 | <?php |
1180 | 1180 | printf( |
1181 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1181 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
1182 | 1182 | $note->comment_author, |
1183 | - getpaid_format_date_value( $note->comment_date ), |
|
1184 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
1183 | + getpaid_format_date_value($note->comment_date), |
|
1184 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
1185 | 1185 | ); |
1186 | 1186 | ?> |
1187 | 1187 | </em> |
@@ -1189,21 +1189,21 @@ discard block |
||
1189 | 1189 | |
1190 | 1190 | </div> |
1191 | 1191 | |
1192 | - <?php if ( is_admin() ) : ?> |
|
1192 | + <?php if (is_admin()) : ?> |
|
1193 | 1193 | |
1194 | 1194 | <p class="meta px-4 py-2"> |
1195 | - <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>"> |
|
1195 | + <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>"> |
|
1196 | 1196 | <?php |
1197 | 1197 | printf( |
1198 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1198 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
1199 | 1199 | $note->comment_author, |
1200 | - getpaid_format_date_value( $note->comment_date ), |
|
1201 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
1200 | + getpaid_format_date_value($note->comment_date), |
|
1201 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
1202 | 1202 | ); |
1203 | 1203 | ?> |
1204 | 1204 | </abbr> |
1205 | - <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?> |
|
1206 | - <a href="#" class="delete_note"><?php esc_html_e( 'Delete note', 'invoicing' ); ?></a> |
|
1205 | + <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?> |
|
1206 | + <a href="#" class="delete_note"><?php esc_html_e('Delete note', 'invoicing'); ?></a> |
|
1207 | 1207 | <?php } ?> |
1208 | 1208 | </p> |
1209 | 1209 | |
@@ -1212,10 +1212,10 @@ discard block |
||
1212 | 1212 | </li> |
1213 | 1213 | <?php |
1214 | 1214 | $note_content = ob_get_clean(); |
1215 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
1215 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
1216 | 1216 | |
1217 | - if ( $echo ) { |
|
1218 | - echo wp_kses_post( $note_content ); |
|
1217 | + if ($echo) { |
|
1218 | + echo wp_kses_post($note_content); |
|
1219 | 1219 | } else { |
1220 | 1220 | return $note_content; |
1221 | 1221 | } |
@@ -1228,43 +1228,43 @@ discard block |
||
1228 | 1228 | * @return string |
1229 | 1229 | */ |
1230 | 1230 | function wpinv_get_policy_text() { |
1231 | - $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 ); |
|
1231 | + $privacy_page_id = get_option('wp_page_for_privacy_policy', 0); |
|
1232 | 1232 | |
1233 | - $text = wpinv_get_option( 'invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ) ); |
|
1233 | + $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]')); |
|
1234 | 1234 | |
1235 | - if ( ! $privacy_page_id ) { |
|
1236 | - $privacy_page_id = wpinv_get_option( 'privacy_page', 0 ); |
|
1235 | + if (!$privacy_page_id) { |
|
1236 | + $privacy_page_id = wpinv_get_option('privacy_page', 0); |
|
1237 | 1237 | } |
1238 | 1238 | |
1239 | - $privacy_link = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' ); |
|
1239 | + $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing'); |
|
1240 | 1240 | |
1241 | 1241 | $find_replace = array( |
1242 | 1242 | '[wpinv_privacy_policy]' => $privacy_link, |
1243 | 1243 | ); |
1244 | 1244 | |
1245 | - $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text ); |
|
1245 | + $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text); |
|
1246 | 1246 | |
1247 | - return wp_kses_post( wpautop( $privacy_text ) ); |
|
1247 | + return wp_kses_post(wpautop($privacy_text)); |
|
1248 | 1248 | } |
1249 | 1249 | |
1250 | 1250 | function wpinv_oxygen_fix_conflict() { |
1251 | 1251 | global $ct_ignore_post_types; |
1252 | 1252 | |
1253 | - if ( ! is_array( $ct_ignore_post_types ) ) { |
|
1253 | + if (!is_array($ct_ignore_post_types)) { |
|
1254 | 1254 | $ct_ignore_post_types = array(); |
1255 | 1255 | } |
1256 | 1256 | |
1257 | - $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form' ); |
|
1257 | + $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form'); |
|
1258 | 1258 | |
1259 | - foreach ( $post_types as $post_type ) { |
|
1259 | + foreach ($post_types as $post_type) { |
|
1260 | 1260 | $ct_ignore_post_types[] = $post_type; |
1261 | 1261 | |
1262 | 1262 | // Ignore post type |
1263 | - add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 ); |
|
1263 | + add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999); |
|
1264 | 1264 | } |
1265 | 1265 | |
1266 | - remove_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
1267 | - add_filter( 'template_include', 'wpinv_template', 999, 1 ); |
|
1266 | + remove_filter('template_include', 'wpinv_template', 10, 1); |
|
1267 | + add_filter('template_include', 'wpinv_template', 999, 1); |
|
1268 | 1268 | } |
1269 | 1269 | |
1270 | 1270 | /** |
@@ -1272,10 +1272,10 @@ discard block |
||
1272 | 1272 | * |
1273 | 1273 | * @param GetPaid_Payment_Form $form |
1274 | 1274 | */ |
1275 | -function getpaid_display_payment_form( $form ) { |
|
1275 | +function getpaid_display_payment_form($form) { |
|
1276 | 1276 | |
1277 | - if ( is_numeric( $form ) ) { |
|
1278 | - $form = new GetPaid_Payment_Form( $form ); |
|
1277 | + if (is_numeric($form)) { |
|
1278 | + $form = new GetPaid_Payment_Form($form); |
|
1279 | 1279 | } |
1280 | 1280 | |
1281 | 1281 | $form->display(); |
@@ -1285,61 +1285,61 @@ discard block |
||
1285 | 1285 | /** |
1286 | 1286 | * Helper function to display a item payment form on the frontend. |
1287 | 1287 | */ |
1288 | -function getpaid_display_item_payment_form( $items ) { |
|
1288 | +function getpaid_display_item_payment_form($items) { |
|
1289 | 1289 | |
1290 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1291 | - $form->set_items( $items ); |
|
1290 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1291 | + $form->set_items($items); |
|
1292 | 1292 | |
1293 | - if ( 0 == count( $form->get_items() ) ) { |
|
1293 | + if (0 == count($form->get_items())) { |
|
1294 | 1294 | aui()->alert( |
1295 | 1295 | array( |
1296 | 1296 | 'type' => 'warning', |
1297 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1297 | + 'content' => __('No published items found', 'invoicing'), |
|
1298 | 1298 | ), |
1299 | 1299 | true |
1300 | 1300 | ); |
1301 | 1301 | return; |
1302 | 1302 | } |
1303 | 1303 | |
1304 | - $extra_items = esc_attr( getpaid_convert_items_to_string( $items ) ); |
|
1305 | - $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items ); |
|
1304 | + $extra_items = esc_attr(getpaid_convert_items_to_string($items)); |
|
1305 | + $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items); |
|
1306 | 1306 | $extra_items = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />"; |
1307 | 1307 | $extra_items .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />"; |
1308 | 1308 | |
1309 | - $form->display( $extra_items ); |
|
1309 | + $form->display($extra_items); |
|
1310 | 1310 | } |
1311 | 1311 | |
1312 | 1312 | /** |
1313 | 1313 | * Helper function to display an invoice payment form on the frontend. |
1314 | 1314 | */ |
1315 | -function getpaid_display_invoice_payment_form( $invoice_id ) { |
|
1315 | +function getpaid_display_invoice_payment_form($invoice_id) { |
|
1316 | 1316 | |
1317 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1317 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1318 | 1318 | |
1319 | - if ( empty( $invoice ) ) { |
|
1319 | + if (empty($invoice)) { |
|
1320 | 1320 | aui()->alert( |
1321 | 1321 | array( |
1322 | 1322 | 'type' => 'warning', |
1323 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1323 | + 'content' => __('Invoice not found', 'invoicing'), |
|
1324 | 1324 | ), |
1325 | 1325 | true |
1326 | 1326 | ); |
1327 | 1327 | return; |
1328 | 1328 | } |
1329 | 1329 | |
1330 | - if ( $invoice->is_paid() ) { |
|
1330 | + if ($invoice->is_paid()) { |
|
1331 | 1331 | aui()->alert( |
1332 | 1332 | array( |
1333 | 1333 | 'type' => 'warning', |
1334 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1334 | + 'content' => __('Invoice has already been paid', 'invoicing'), |
|
1335 | 1335 | ), |
1336 | 1336 | true |
1337 | 1337 | ); |
1338 | 1338 | return; |
1339 | 1339 | } |
1340 | 1340 | |
1341 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1342 | - $form->set_items( $invoice->get_items() ); |
|
1341 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1342 | + $form->set_items($invoice->get_items()); |
|
1343 | 1343 | |
1344 | 1344 | $form->display(); |
1345 | 1345 | } |
@@ -1347,23 +1347,23 @@ discard block |
||
1347 | 1347 | /** |
1348 | 1348 | * Helper function to convert item string to array. |
1349 | 1349 | */ |
1350 | -function getpaid_convert_items_to_array( $items ) { |
|
1351 | - $items = array_filter( array_map( 'trim', explode( ',', $items ) ) ); |
|
1350 | +function getpaid_convert_items_to_array($items) { |
|
1351 | + $items = array_filter(array_map('trim', explode(',', $items))); |
|
1352 | 1352 | $prepared = array(); |
1353 | 1353 | |
1354 | - foreach ( $items as $item ) { |
|
1355 | - $data = array_map( 'trim', explode( '|', $item ) ); |
|
1354 | + foreach ($items as $item) { |
|
1355 | + $data = array_map('trim', explode('|', $item)); |
|
1356 | 1356 | |
1357 | - if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) { |
|
1357 | + if (empty($data[0]) || !is_numeric($data[0])) { |
|
1358 | 1358 | continue; |
1359 | 1359 | } |
1360 | 1360 | |
1361 | 1361 | $quantity = 1; |
1362 | - if ( isset( $data[1] ) && is_numeric( $data[1] ) ) { |
|
1362 | + if (isset($data[1]) && is_numeric($data[1])) { |
|
1363 | 1363 | $quantity = (float) $data[1]; |
1364 | 1364 | } |
1365 | 1365 | |
1366 | - $prepared[ $data[0] ] = $quantity; |
|
1366 | + $prepared[$data[0]] = $quantity; |
|
1367 | 1367 | |
1368 | 1368 | } |
1369 | 1369 | |
@@ -1373,13 +1373,13 @@ discard block |
||
1373 | 1373 | /** |
1374 | 1374 | * Helper function to convert item array to string. |
1375 | 1375 | */ |
1376 | -function getpaid_convert_items_to_string( $items ) { |
|
1376 | +function getpaid_convert_items_to_string($items) { |
|
1377 | 1377 | $prepared = array(); |
1378 | 1378 | |
1379 | - foreach ( $items as $item => $quantity ) { |
|
1379 | + foreach ($items as $item => $quantity) { |
|
1380 | 1380 | $prepared[] = "$item|$quantity"; |
1381 | 1381 | } |
1382 | - return implode( ',', $prepared ); |
|
1382 | + return implode(',', $prepared); |
|
1383 | 1383 | } |
1384 | 1384 | |
1385 | 1385 | /** |
@@ -1387,21 +1387,21 @@ discard block |
||
1387 | 1387 | * |
1388 | 1388 | * Provide a label and one of $form, $items or $invoice. |
1389 | 1389 | */ |
1390 | -function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) { |
|
1391 | - $label = sanitize_text_field( $label ); |
|
1390 | +function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) { |
|
1391 | + $label = sanitize_text_field($label); |
|
1392 | 1392 | |
1393 | - if ( ! empty( $form ) ) { |
|
1394 | - $form = esc_attr( $form ); |
|
1393 | + if (!empty($form)) { |
|
1394 | + $form = esc_attr($form); |
|
1395 | 1395 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; |
1396 | 1396 | } |
1397 | 1397 | |
1398 | - if ( ! empty( $items ) ) { |
|
1399 | - $items = esc_attr( $items ); |
|
1398 | + if (!empty($items)) { |
|
1399 | + $items = esc_attr($items); |
|
1400 | 1400 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; |
1401 | 1401 | } |
1402 | 1402 | |
1403 | - if ( ! empty( $invoice ) ) { |
|
1404 | - $invoice = esc_attr( $invoice ); |
|
1403 | + if (!empty($invoice)) { |
|
1404 | + $invoice = esc_attr($invoice); |
|
1405 | 1405 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-invoice='$invoice'>$label</button>"; |
1406 | 1406 | } |
1407 | 1407 | |
@@ -1412,18 +1412,18 @@ discard block |
||
1412 | 1412 | * |
1413 | 1413 | * @param WPInv_Invoice $invoice |
1414 | 1414 | */ |
1415 | -function getpaid_the_invoice_description( $invoice ) { |
|
1415 | +function getpaid_the_invoice_description($invoice) { |
|
1416 | 1416 | $description = $invoice->get_description(); |
1417 | 1417 | |
1418 | - if ( empty( $description ) ) { |
|
1418 | + if (empty($description)) { |
|
1419 | 1419 | return; |
1420 | 1420 | } |
1421 | 1421 | |
1422 | - $description = wp_kses_post( wpautop( $description ) ); |
|
1422 | + $description = wp_kses_post(wpautop($description)); |
|
1423 | 1423 | echo "<small class='getpaid-invoice-description text-dark p-2 form-text' style='margin-bottom: 20px; border-left: 2px solid #2196F3;'><em>$description</em></small>"; |
1424 | 1424 | } |
1425 | -add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 ); |
|
1426 | -add_action( 'wpinv_email_billing_details', 'getpaid_the_invoice_description', 100 ); |
|
1425 | +add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100); |
|
1426 | +add_action('wpinv_email_billing_details', 'getpaid_the_invoice_description', 100); |
|
1427 | 1427 | |
1428 | 1428 | /** |
1429 | 1429 | * Render element on a form. |
@@ -1431,60 +1431,60 @@ discard block |
||
1431 | 1431 | * @param array $element |
1432 | 1432 | * @param GetPaid_Payment_Form $form |
1433 | 1433 | */ |
1434 | -function getpaid_payment_form_element( $element, $form ) { |
|
1434 | +function getpaid_payment_form_element($element, $form) { |
|
1435 | 1435 | |
1436 | 1436 | // Set up the args. |
1437 | - $element_type = trim( $element['type'] ); |
|
1437 | + $element_type = trim($element['type']); |
|
1438 | 1438 | $element['form'] = $form; |
1439 | - extract( $element ); |
|
1439 | + extract($element); |
|
1440 | 1440 | |
1441 | 1441 | // Try to locate the appropriate template. |
1442 | - $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" ); |
|
1442 | + $located = wpinv_locate_template("payment-forms/elements/$element_type.php"); |
|
1443 | 1443 | |
1444 | 1444 | // Abort if this is not our element. |
1445 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1445 | + if (empty($located) || !file_exists($located)) { |
|
1446 | 1446 | return; |
1447 | 1447 | } |
1448 | 1448 | |
1449 | 1449 | // Generate the class and id of the element. |
1450 | - $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) ); |
|
1451 | - $id = isset( $id ) ? $id : uniqid( 'gp' ); |
|
1450 | + $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type)); |
|
1451 | + $id = isset($id) ? $id : uniqid('gp'); |
|
1452 | 1452 | |
1453 | 1453 | // Echo the opening wrapper. |
1454 | 1454 | echo "<div class='getpaid-payment-form-element $wrapper_class'>"; |
1455 | 1455 | |
1456 | 1456 | // Fires before displaying a given element type's content. |
1457 | - do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form ); |
|
1457 | + do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form); |
|
1458 | 1458 | |
1459 | 1459 | // Include the template for the element. |
1460 | 1460 | include $located; |
1461 | 1461 | |
1462 | 1462 | // Fires after displaying a given element type's content. |
1463 | - do_action( "getpaid_payment_form_{$element_type}_element", $element, $form ); |
|
1463 | + do_action("getpaid_payment_form_{$element_type}_element", $element, $form); |
|
1464 | 1464 | |
1465 | 1465 | // Echo the closing wrapper. |
1466 | 1466 | echo '</div>'; |
1467 | 1467 | } |
1468 | -add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 ); |
|
1468 | +add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2); |
|
1469 | 1469 | |
1470 | 1470 | /** |
1471 | 1471 | * Render an element's edit page. |
1472 | 1472 | * |
1473 | 1473 | * @param WP_Post $post |
1474 | 1474 | */ |
1475 | -function getpaid_payment_form_edit_element_template( $post ) { |
|
1475 | +function getpaid_payment_form_edit_element_template($post) { |
|
1476 | 1476 | |
1477 | 1477 | // Retrieve all elements. |
1478 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1478 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1479 | 1479 | |
1480 | - foreach ( $all_elements as $element ) { |
|
1480 | + foreach ($all_elements as $element) { |
|
1481 | 1481 | |
1482 | 1482 | // Try to locate the appropriate template. |
1483 | - $element = esc_attr( sanitize_key( $element ) ); |
|
1484 | - $located = wpinv_locate_template( "payment-forms-admin/edit/$element.php" ); |
|
1483 | + $element = esc_attr(sanitize_key($element)); |
|
1484 | + $located = wpinv_locate_template("payment-forms-admin/edit/$element.php"); |
|
1485 | 1485 | |
1486 | 1486 | // Continue if this is not our element. |
1487 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1487 | + if (empty($located) || !file_exists($located)) { |
|
1488 | 1488 | continue; |
1489 | 1489 | } |
1490 | 1490 | |
@@ -1495,7 +1495,7 @@ discard block |
||
1495 | 1495 | } |
1496 | 1496 | |
1497 | 1497 | } |
1498 | -add_action( 'getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template' ); |
|
1498 | +add_action('getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template'); |
|
1499 | 1499 | |
1500 | 1500 | /** |
1501 | 1501 | * Render an element's preview. |
@@ -1504,16 +1504,16 @@ discard block |
||
1504 | 1504 | function getpaid_payment_form_render_element_preview_template() { |
1505 | 1505 | |
1506 | 1506 | // Retrieve all elements. |
1507 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1507 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1508 | 1508 | |
1509 | - foreach ( $all_elements as $element ) { |
|
1509 | + foreach ($all_elements as $element) { |
|
1510 | 1510 | |
1511 | 1511 | // Try to locate the appropriate template. |
1512 | - $element = sanitize_key( $element ); |
|
1513 | - $located = wpinv_locate_template( "payment-forms-admin/previews/$element.php" ); |
|
1512 | + $element = sanitize_key($element); |
|
1513 | + $located = wpinv_locate_template("payment-forms-admin/previews/$element.php"); |
|
1514 | 1514 | |
1515 | 1515 | // Continue if this is not our element. |
1516 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1516 | + if (empty($located) || !file_exists($located)) { |
|
1517 | 1517 | continue; |
1518 | 1518 | } |
1519 | 1519 | |
@@ -1524,7 +1524,7 @@ discard block |
||
1524 | 1524 | } |
1525 | 1525 | |
1526 | 1526 | } |
1527 | -add_action( 'wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template' ); |
|
1527 | +add_action('wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template'); |
|
1528 | 1528 | |
1529 | 1529 | /** |
1530 | 1530 | * Shows a list of gateways that support recurring payments. |
@@ -1532,17 +1532,17 @@ discard block |
||
1532 | 1532 | function wpinv_get_recurring_gateways_text() { |
1533 | 1533 | $gateways = array(); |
1534 | 1534 | |
1535 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
1536 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
1537 | - $gateways[] = sanitize_text_field( $gateway['admin_label'] ); |
|
1535 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
1536 | + if (wpinv_gateway_support_subscription($key)) { |
|
1537 | + $gateways[] = sanitize_text_field($gateway['admin_label']); |
|
1538 | 1538 | } |
1539 | 1539 | } |
1540 | 1540 | |
1541 | - if ( empty( $gateways ) ) { |
|
1542 | - return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) . '</span>'; |
|
1541 | + if (empty($gateways)) { |
|
1542 | + return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . '</span>'; |
|
1543 | 1543 | } |
1544 | 1544 | |
1545 | - return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) . '</span>'; |
|
1545 | + return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . '</span>'; |
|
1546 | 1546 | |
1547 | 1547 | } |
1548 | 1548 | |
@@ -1552,7 +1552,7 @@ discard block |
||
1552 | 1552 | * @return GetPaid_Template |
1553 | 1553 | */ |
1554 | 1554 | function getpaid_template() { |
1555 | - return getpaid()->get( 'template' ); |
|
1555 | + return getpaid()->get('template'); |
|
1556 | 1556 | } |
1557 | 1557 | |
1558 | 1558 | /** |
@@ -1561,8 +1561,8 @@ discard block |
||
1561 | 1561 | * @param array args |
1562 | 1562 | * @return string |
1563 | 1563 | */ |
1564 | -function getpaid_paginate_links( $args ) { |
|
1565 | - return str_replace( 'page-link dots', 'page-link text-dark', aui()->pagination( $args ) ); |
|
1564 | +function getpaid_paginate_links($args) { |
|
1565 | + return str_replace('page-link dots', 'page-link text-dark', aui()->pagination($args)); |
|
1566 | 1566 | } |
1567 | 1567 | |
1568 | 1568 | /** |
@@ -1572,22 +1572,22 @@ discard block |
||
1572 | 1572 | * @param string state |
1573 | 1573 | * @return string |
1574 | 1574 | */ |
1575 | -function getpaid_get_states_select_markup( $country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state' ) { |
|
1575 | +function getpaid_get_states_select_markup($country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state') { |
|
1576 | 1576 | |
1577 | - $states = wpinv_get_country_states( $country ); |
|
1578 | - $uniqid = uniqid( '_' ); |
|
1577 | + $states = wpinv_get_country_states($country); |
|
1578 | + $uniqid = uniqid('_'); |
|
1579 | 1579 | |
1580 | - if ( ! empty( $states ) ) { |
|
1580 | + if (!empty($states)) { |
|
1581 | 1581 | |
1582 | 1582 | return aui()->select( |
1583 | 1583 | array( |
1584 | 1584 | 'options' => $states, |
1585 | - 'name' => esc_attr( $field_name ), |
|
1586 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1587 | - 'value' => sanitize_text_field( $state ), |
|
1585 | + 'name' => esc_attr($field_name), |
|
1586 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
1587 | + 'value' => sanitize_text_field($state), |
|
1588 | 1588 | 'placeholder' => $placeholder, |
1589 | 1589 | 'required' => $required, |
1590 | - 'label' => wp_kses_post( $label ), |
|
1590 | + 'label' => wp_kses_post($label), |
|
1591 | 1591 | 'label_type' => 'vertical', |
1592 | 1592 | 'help_text' => $help_text, |
1593 | 1593 | 'class' => 'getpaid-address-field wpinv_state', |
@@ -1603,14 +1603,14 @@ discard block |
||
1603 | 1603 | |
1604 | 1604 | return aui()->input( |
1605 | 1605 | array( |
1606 | - 'name' => esc_attr( $field_name ), |
|
1607 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1606 | + 'name' => esc_attr($field_name), |
|
1607 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
1608 | 1608 | 'placeholder' => $placeholder, |
1609 | 1609 | 'required' => $required, |
1610 | - 'label' => wp_kses_post( $label ), |
|
1610 | + 'label' => wp_kses_post($label), |
|
1611 | 1611 | 'label_type' => 'vertical', |
1612 | 1612 | 'help_text' => $help_text, |
1613 | - 'value' => sanitize_text_field( $state ), |
|
1613 | + 'value' => sanitize_text_field($state), |
|
1614 | 1614 | 'class' => 'getpaid-address-field wpinv_state', |
1615 | 1615 | 'wrap_class' => "$wrapper_class getpaid-address-field-wrapper__state", |
1616 | 1616 | 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state', |
@@ -1628,16 +1628,16 @@ discard block |
||
1628 | 1628 | * @param array $element |
1629 | 1629 | * @return string |
1630 | 1630 | */ |
1631 | -function getpaid_get_form_element_grid_class( $element ) { |
|
1631 | +function getpaid_get_form_element_grid_class($element) { |
|
1632 | 1632 | |
1633 | 1633 | $class = 'col-12'; |
1634 | - $width = empty( $element['grid_width'] ) ? 'full' : $element['grid_width']; |
|
1634 | + $width = empty($element['grid_width']) ? 'full' : $element['grid_width']; |
|
1635 | 1635 | |
1636 | - if ( $width == 'half' ) { |
|
1636 | + if ($width == 'half') { |
|
1637 | 1637 | $class .= ' col-md-6'; |
1638 | 1638 | } |
1639 | 1639 | |
1640 | - if ( $width == 'third' ) { |
|
1640 | + if ($width == 'third') { |
|
1641 | 1641 | $class .= ' col-md-4'; |
1642 | 1642 | } |
1643 | 1643 | |
@@ -1652,15 +1652,15 @@ discard block |
||
1652 | 1652 | * |
1653 | 1653 | * @return string |
1654 | 1654 | */ |
1655 | -function getpaid_embed_url( $payment_form = false, $items = false ) { |
|
1655 | +function getpaid_embed_url($payment_form = false, $items = false) { |
|
1656 | 1656 | |
1657 | 1657 | return add_query_arg( |
1658 | 1658 | array( |
1659 | 1659 | 'getpaid_embed' => 1, |
1660 | - 'form' => $payment_form ? absint( $payment_form ) : false, |
|
1661 | - 'item' => $items ? urlencode( $items ) : false, |
|
1660 | + 'form' => $payment_form ? absint($payment_form) : false, |
|
1661 | + 'item' => $items ? urlencode($items) : false, |
|
1662 | 1662 | ), |
1663 | - home_url( 'index.php' ) |
|
1663 | + home_url('index.php') |
|
1664 | 1664 | ); |
1665 | 1665 | |
1666 | 1666 | } |
@@ -1670,13 +1670,13 @@ discard block |
||
1670 | 1670 | * |
1671 | 1671 | * @return string |
1672 | 1672 | */ |
1673 | -function getpaid_filter_embed_template( $template ) { |
|
1673 | +function getpaid_filter_embed_template($template) { |
|
1674 | 1674 | |
1675 | - if ( isset( $_GET['getpaid_embed'] ) ) { |
|
1676 | - wpinv_get_template( 'payment-forms/embed.php' ); |
|
1675 | + if (isset($_GET['getpaid_embed'])) { |
|
1676 | + wpinv_get_template('payment-forms/embed.php'); |
|
1677 | 1677 | exit; |
1678 | 1678 | } |
1679 | 1679 | |
1680 | 1680 | return $template; |
1681 | 1681 | } |
1682 | -add_filter( 'template_include', 'getpaid_filter_embed_template' ); |
|
1682 | +add_filter('template_include', 'getpaid_filter_embed_template'); |
@@ -13,462 +13,462 @@ discard block |
||
13 | 13 | */ |
14 | 14 | abstract class GetPaid_Payment_Gateway { |
15 | 15 | |
16 | - /** |
|
17 | - * Set if the place checkout button should be renamed on selection. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $checkout_button_text; |
|
22 | - |
|
23 | - /** |
|
24 | - * Boolean whether the method is enabled. |
|
25 | - * |
|
26 | - * @var bool |
|
27 | - */ |
|
28 | - public $enabled = true; |
|
29 | - |
|
30 | - /** |
|
31 | - * Payment method id. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $id; |
|
36 | - |
|
37 | - /** |
|
38 | - * Payment method order. |
|
39 | - * |
|
40 | - * @var int |
|
41 | - */ |
|
42 | - public $order = 10; |
|
43 | - |
|
44 | - /** |
|
45 | - * Payment method title for the frontend. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $title; |
|
50 | - |
|
51 | - /** |
|
52 | - * Payment method description for the frontend. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - public $description; |
|
57 | - |
|
58 | - /** |
|
59 | - * Gateway title. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $method_title = ''; |
|
64 | - |
|
65 | - /** |
|
66 | - * Gateway description. |
|
67 | - * |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - public $method_description = ''; |
|
71 | - |
|
72 | - /** |
|
73 | - * Countries this gateway is allowed for. |
|
74 | - * |
|
75 | - * @var array |
|
76 | - */ |
|
77 | - public $countries; |
|
78 | - |
|
79 | - /** |
|
80 | - * Currencies this gateway is allowed for. |
|
81 | - * |
|
82 | - * @var array |
|
83 | - */ |
|
84 | - public $currencies; |
|
85 | - |
|
86 | - /** |
|
87 | - * Currencies this gateway is not allowed for. |
|
88 | - * |
|
89 | - * @var array |
|
90 | - */ |
|
91 | - public $exclude_currencies; |
|
92 | - |
|
93 | - /** |
|
94 | - * Maximum transaction amount, zero does not define a maximum. |
|
95 | - * |
|
96 | - * @var int |
|
97 | - */ |
|
98 | - public $max_amount = 0; |
|
99 | - |
|
100 | - /** |
|
101 | - * Optional URL to view a transaction. |
|
102 | - * |
|
103 | - * @var string |
|
104 | - */ |
|
105 | - public $view_transaction_url = ''; |
|
106 | - |
|
107 | - /** |
|
108 | - * Optional URL to view a subscription. |
|
109 | - * |
|
110 | - * @var string |
|
111 | - */ |
|
112 | - public $view_subscription_url = ''; |
|
113 | - |
|
114 | - /** |
|
115 | - * Optional label to show for "new payment method" in the payment |
|
116 | - * method/token selection radio selection. |
|
117 | - * |
|
118 | - * @var string |
|
119 | - */ |
|
120 | - public $new_method_label = ''; |
|
121 | - |
|
122 | - /** |
|
123 | - * Contains a user's saved tokens for this gateway. |
|
124 | - * |
|
125 | - * @var array |
|
126 | - */ |
|
127 | - protected $tokens = array(); |
|
128 | - |
|
129 | - /** |
|
130 | - * An array of features that this gateway supports. |
|
131 | - * |
|
132 | - * @var array |
|
133 | - */ |
|
134 | - protected $supports = array(); |
|
135 | - |
|
136 | - /** |
|
137 | - * Class constructor. |
|
138 | - */ |
|
139 | - public function __construct() { |
|
140 | - |
|
141 | - // Register gateway. |
|
142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
143 | - |
|
144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
145 | - |
|
146 | - // Add support for various features. |
|
147 | - foreach ( $this->supports as $feature ) { |
|
148 | - add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
149 | - add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
150 | - add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
151 | - } |
|
152 | - |
|
153 | - // Invoice addons. |
|
154 | - if ( $this->supports( 'addons' ) ) { |
|
155 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
156 | - } |
|
157 | - |
|
158 | - // Gateway settings. |
|
159 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
160 | - |
|
161 | - // Gateway checkout fiellds. |
|
162 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
163 | - |
|
164 | - // Process payment. |
|
165 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
166 | - |
|
167 | - // Change the checkout button text. |
|
168 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
169 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
170 | - } |
|
171 | - |
|
172 | - // Check if a gateway is valid for a given currency. |
|
173 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
174 | - |
|
175 | - // Generate the transaction url. |
|
176 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
177 | - |
|
178 | - // Generate the subscription url. |
|
179 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
180 | - |
|
181 | - // Confirm payments. |
|
182 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
183 | - |
|
184 | - // Verify IPNs. |
|
185 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
186 | - |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Checks if this gateway is a given gateway. |
|
191 | - * |
|
192 | - * @since 1.0.19 |
|
193 | - * @return bool |
|
194 | - */ |
|
195 | - public function is( $gateway ) { |
|
196 | - return $gateway == $this->id; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Returns a users saved tokens for this gateway. |
|
201 | - * |
|
202 | - * @since 1.0.19 |
|
203 | - * @return array |
|
204 | - */ |
|
205 | - public function get_tokens( $sandbox = null ) { |
|
206 | - |
|
207 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
208 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
209 | - |
|
210 | - if ( is_array( $tokens ) ) { |
|
211 | - $this->tokens = $tokens; |
|
212 | - } |
|
16 | + /** |
|
17 | + * Set if the place checkout button should be renamed on selection. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $checkout_button_text; |
|
22 | + |
|
23 | + /** |
|
24 | + * Boolean whether the method is enabled. |
|
25 | + * |
|
26 | + * @var bool |
|
27 | + */ |
|
28 | + public $enabled = true; |
|
29 | + |
|
30 | + /** |
|
31 | + * Payment method id. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $id; |
|
36 | + |
|
37 | + /** |
|
38 | + * Payment method order. |
|
39 | + * |
|
40 | + * @var int |
|
41 | + */ |
|
42 | + public $order = 10; |
|
43 | + |
|
44 | + /** |
|
45 | + * Payment method title for the frontend. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $title; |
|
50 | + |
|
51 | + /** |
|
52 | + * Payment method description for the frontend. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + public $description; |
|
57 | + |
|
58 | + /** |
|
59 | + * Gateway title. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $method_title = ''; |
|
64 | + |
|
65 | + /** |
|
66 | + * Gateway description. |
|
67 | + * |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + public $method_description = ''; |
|
71 | + |
|
72 | + /** |
|
73 | + * Countries this gateway is allowed for. |
|
74 | + * |
|
75 | + * @var array |
|
76 | + */ |
|
77 | + public $countries; |
|
78 | + |
|
79 | + /** |
|
80 | + * Currencies this gateway is allowed for. |
|
81 | + * |
|
82 | + * @var array |
|
83 | + */ |
|
84 | + public $currencies; |
|
85 | + |
|
86 | + /** |
|
87 | + * Currencies this gateway is not allowed for. |
|
88 | + * |
|
89 | + * @var array |
|
90 | + */ |
|
91 | + public $exclude_currencies; |
|
92 | + |
|
93 | + /** |
|
94 | + * Maximum transaction amount, zero does not define a maximum. |
|
95 | + * |
|
96 | + * @var int |
|
97 | + */ |
|
98 | + public $max_amount = 0; |
|
99 | + |
|
100 | + /** |
|
101 | + * Optional URL to view a transaction. |
|
102 | + * |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + public $view_transaction_url = ''; |
|
106 | + |
|
107 | + /** |
|
108 | + * Optional URL to view a subscription. |
|
109 | + * |
|
110 | + * @var string |
|
111 | + */ |
|
112 | + public $view_subscription_url = ''; |
|
113 | + |
|
114 | + /** |
|
115 | + * Optional label to show for "new payment method" in the payment |
|
116 | + * method/token selection radio selection. |
|
117 | + * |
|
118 | + * @var string |
|
119 | + */ |
|
120 | + public $new_method_label = ''; |
|
121 | + |
|
122 | + /** |
|
123 | + * Contains a user's saved tokens for this gateway. |
|
124 | + * |
|
125 | + * @var array |
|
126 | + */ |
|
127 | + protected $tokens = array(); |
|
128 | + |
|
129 | + /** |
|
130 | + * An array of features that this gateway supports. |
|
131 | + * |
|
132 | + * @var array |
|
133 | + */ |
|
134 | + protected $supports = array(); |
|
135 | + |
|
136 | + /** |
|
137 | + * Class constructor. |
|
138 | + */ |
|
139 | + public function __construct() { |
|
140 | + |
|
141 | + // Register gateway. |
|
142 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
143 | + |
|
144 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
145 | + |
|
146 | + // Add support for various features. |
|
147 | + foreach ( $this->supports as $feature ) { |
|
148 | + add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
149 | + add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
150 | + add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
151 | + } |
|
152 | + |
|
153 | + // Invoice addons. |
|
154 | + if ( $this->supports( 'addons' ) ) { |
|
155 | + add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
156 | + } |
|
157 | + |
|
158 | + // Gateway settings. |
|
159 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
160 | + |
|
161 | + // Gateway checkout fiellds. |
|
162 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
163 | + |
|
164 | + // Process payment. |
|
165 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
166 | + |
|
167 | + // Change the checkout button text. |
|
168 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
169 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
170 | + } |
|
171 | + |
|
172 | + // Check if a gateway is valid for a given currency. |
|
173 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
174 | + |
|
175 | + // Generate the transaction url. |
|
176 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
177 | + |
|
178 | + // Generate the subscription url. |
|
179 | + add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
180 | + |
|
181 | + // Confirm payments. |
|
182 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
183 | + |
|
184 | + // Verify IPNs. |
|
185 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
186 | + |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Checks if this gateway is a given gateway. |
|
191 | + * |
|
192 | + * @since 1.0.19 |
|
193 | + * @return bool |
|
194 | + */ |
|
195 | + public function is( $gateway ) { |
|
196 | + return $gateway == $this->id; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Returns a users saved tokens for this gateway. |
|
201 | + * |
|
202 | + * @since 1.0.19 |
|
203 | + * @return array |
|
204 | + */ |
|
205 | + public function get_tokens( $sandbox = null ) { |
|
206 | + |
|
207 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
208 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
209 | + |
|
210 | + if ( is_array( $tokens ) ) { |
|
211 | + $this->tokens = $tokens; |
|
212 | + } |
|
213 | 213 | } |
214 | 214 | |
215 | - if ( ! is_bool( $sandbox ) ) { |
|
216 | - return $this->tokens; |
|
217 | - } |
|
218 | - |
|
219 | - // Filter tokens. |
|
220 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
221 | - return wp_list_filter( $this->tokens, $args ); |
|
222 | - |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Saves a token for this gateway. |
|
227 | - * |
|
228 | - * @since 1.0.19 |
|
229 | - */ |
|
230 | - public function save_token( $token ) { |
|
231 | - |
|
232 | - $tokens = $this->get_tokens(); |
|
233 | - $tokens[] = $token; |
|
234 | - |
|
235 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
236 | - |
|
237 | - $this->tokens = $tokens; |
|
238 | - |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Return the title for admin screens. |
|
243 | - * |
|
244 | - * @return string |
|
245 | - */ |
|
246 | - public function get_method_title() { |
|
247 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Return the description for admin screens. |
|
252 | - * |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - public function get_method_description() { |
|
256 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Get the success url. |
|
261 | - * |
|
262 | - * @param WPInv_Invoice $invoice Invoice object. |
|
263 | - * @return string |
|
264 | - */ |
|
265 | - public function get_return_url( $invoice ) { |
|
266 | - |
|
267 | - // Payment success url |
|
268 | - $return_url = add_query_arg( |
|
269 | - array( |
|
270 | - 'payment-confirm' => $this->id, |
|
271 | - 'invoice_key' => $invoice->get_key(), |
|
272 | - 'utm_nooverride' => 1, |
|
273 | - ), |
|
274 | - wpinv_get_success_page_uri() |
|
275 | - ); |
|
276 | - |
|
277 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Confirms payments when rendering the success page. |
|
282 | - * |
|
283 | - * @param string $content Success page content. |
|
284 | - * @return string |
|
285 | - */ |
|
286 | - public function confirm_payment( $content ) { |
|
287 | - |
|
288 | - // Retrieve the invoice. |
|
289 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
290 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
291 | - |
|
292 | - // Ensure that it exists and that it is pending payment. |
|
293 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
294 | - return $content; |
|
295 | - } |
|
296 | - |
|
297 | - // Can the user view this invoice?? |
|
298 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
299 | - return $content; |
|
300 | - } |
|
301 | - |
|
302 | - // Show payment processing indicator. |
|
303 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Processes ipns and marks payments as complete. |
|
308 | - * |
|
309 | - * @return void |
|
310 | - */ |
|
311 | - public function verify_ipn() {} |
|
312 | - |
|
313 | - /** |
|
314 | - * Processes invoice addons. |
|
315 | - * |
|
316 | - * @param WPInv_Invoice $invoice |
|
317 | - * @param GetPaid_Form_Item[] $items |
|
318 | - * @return WPInv_Invoice |
|
319 | - */ |
|
320 | - public function process_addons( $invoice, $items ) { |
|
321 | - |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
326 | - * |
|
327 | - * @param string $transaction_url transaction url. |
|
328 | - * @param WPInv_Invoice $invoice Invoice object. |
|
329 | - * @return string transaction URL, or empty string. |
|
330 | - */ |
|
331 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
332 | - |
|
333 | - $transaction_id = $invoice->get_transaction_id(); |
|
334 | - |
|
335 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
336 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
337 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
338 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
339 | - } |
|
340 | - |
|
341 | - return $transaction_url; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
346 | - * |
|
347 | - * @param string $subscription_url transaction url. |
|
348 | - * @param WPInv_Subscription $subscription Subscription objectt. |
|
349 | - * @return string subscription URL, or empty string. |
|
350 | - */ |
|
351 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
352 | - |
|
353 | - $profile_id = $subscription->get_profile_id(); |
|
354 | - |
|
355 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
356 | - |
|
357 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
358 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
359 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
360 | - |
|
361 | - } |
|
362 | - |
|
363 | - return $subscription_url; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Check if the gateway is available for use. |
|
368 | - * |
|
369 | - * @return bool |
|
370 | - */ |
|
371 | - public function is_available() { |
|
372 | - return ! empty( $this->enabled ); |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Return the gateway's title. |
|
377 | - * |
|
378 | - * @return string |
|
379 | - */ |
|
380 | - public function get_title() { |
|
381 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Return the gateway's description. |
|
386 | - * |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - public function get_description() { |
|
390 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Process Payment. |
|
395 | - * |
|
396 | - * |
|
397 | - * @param WPInv_Invoice $invoice Invoice. |
|
398 | - * @param array $submission_data Posted checkout fields. |
|
399 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
400 | - * @return void |
|
401 | - */ |
|
402 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
403 | - // Process the payment then either redirect to the success page or the gateway. |
|
404 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * Process refund. |
|
409 | - * |
|
410 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
411 | - * a passed in amount. |
|
412 | - * |
|
413 | - * @param WPInv_Invoice $invoice Invoice. |
|
414 | - * @param float $amount Refund amount. |
|
415 | - * @param string $reason Refund reason. |
|
416 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
417 | - */ |
|
418 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
419 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Displays the payment fields, credit cards etc. |
|
424 | - * |
|
425 | - * @param int $invoice_id 0 or invoice id. |
|
426 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
427 | - */ |
|
428 | - public function payment_fields( $invoice_id, $form ) { |
|
429 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Filters the gateway settings. |
|
434 | - * |
|
435 | - * @param array $admin_settings |
|
436 | - */ |
|
437 | - public function admin_settings( $admin_settings ) { |
|
438 | - return $admin_settings; |
|
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * Retrieves the value of a gateway setting. |
|
443 | - * |
|
444 | - * @param string $option |
|
445 | - */ |
|
446 | - public function get_option( $option, $default = false ) { |
|
447 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * Check if a gateway supports a given feature. |
|
452 | - * |
|
453 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
454 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
455 | - * |
|
456 | - * @param string $feature string The name of a feature to test support for. |
|
457 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
458 | - * @since 1.0.19 |
|
459 | - */ |
|
460 | - public function supports( $feature ) { |
|
461 | - return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Returns the credit card form html. |
|
466 | - * |
|
467 | - * @param bool $save whether or not to display the save button. |
|
468 | - */ |
|
215 | + if ( ! is_bool( $sandbox ) ) { |
|
216 | + return $this->tokens; |
|
217 | + } |
|
218 | + |
|
219 | + // Filter tokens. |
|
220 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
221 | + return wp_list_filter( $this->tokens, $args ); |
|
222 | + |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Saves a token for this gateway. |
|
227 | + * |
|
228 | + * @since 1.0.19 |
|
229 | + */ |
|
230 | + public function save_token( $token ) { |
|
231 | + |
|
232 | + $tokens = $this->get_tokens(); |
|
233 | + $tokens[] = $token; |
|
234 | + |
|
235 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
236 | + |
|
237 | + $this->tokens = $tokens; |
|
238 | + |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Return the title for admin screens. |
|
243 | + * |
|
244 | + * @return string |
|
245 | + */ |
|
246 | + public function get_method_title() { |
|
247 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Return the description for admin screens. |
|
252 | + * |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + public function get_method_description() { |
|
256 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Get the success url. |
|
261 | + * |
|
262 | + * @param WPInv_Invoice $invoice Invoice object. |
|
263 | + * @return string |
|
264 | + */ |
|
265 | + public function get_return_url( $invoice ) { |
|
266 | + |
|
267 | + // Payment success url |
|
268 | + $return_url = add_query_arg( |
|
269 | + array( |
|
270 | + 'payment-confirm' => $this->id, |
|
271 | + 'invoice_key' => $invoice->get_key(), |
|
272 | + 'utm_nooverride' => 1, |
|
273 | + ), |
|
274 | + wpinv_get_success_page_uri() |
|
275 | + ); |
|
276 | + |
|
277 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Confirms payments when rendering the success page. |
|
282 | + * |
|
283 | + * @param string $content Success page content. |
|
284 | + * @return string |
|
285 | + */ |
|
286 | + public function confirm_payment( $content ) { |
|
287 | + |
|
288 | + // Retrieve the invoice. |
|
289 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
290 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
291 | + |
|
292 | + // Ensure that it exists and that it is pending payment. |
|
293 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
294 | + return $content; |
|
295 | + } |
|
296 | + |
|
297 | + // Can the user view this invoice?? |
|
298 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
299 | + return $content; |
|
300 | + } |
|
301 | + |
|
302 | + // Show payment processing indicator. |
|
303 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Processes ipns and marks payments as complete. |
|
308 | + * |
|
309 | + * @return void |
|
310 | + */ |
|
311 | + public function verify_ipn() {} |
|
312 | + |
|
313 | + /** |
|
314 | + * Processes invoice addons. |
|
315 | + * |
|
316 | + * @param WPInv_Invoice $invoice |
|
317 | + * @param GetPaid_Form_Item[] $items |
|
318 | + * @return WPInv_Invoice |
|
319 | + */ |
|
320 | + public function process_addons( $invoice, $items ) { |
|
321 | + |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
326 | + * |
|
327 | + * @param string $transaction_url transaction url. |
|
328 | + * @param WPInv_Invoice $invoice Invoice object. |
|
329 | + * @return string transaction URL, or empty string. |
|
330 | + */ |
|
331 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
332 | + |
|
333 | + $transaction_id = $invoice->get_transaction_id(); |
|
334 | + |
|
335 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
336 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
337 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
338 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
339 | + } |
|
340 | + |
|
341 | + return $transaction_url; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
346 | + * |
|
347 | + * @param string $subscription_url transaction url. |
|
348 | + * @param WPInv_Subscription $subscription Subscription objectt. |
|
349 | + * @return string subscription URL, or empty string. |
|
350 | + */ |
|
351 | + public function generate_subscription_url( $subscription_url, $subscription ) { |
|
352 | + |
|
353 | + $profile_id = $subscription->get_profile_id(); |
|
354 | + |
|
355 | + if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
356 | + |
|
357 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
358 | + $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
359 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
360 | + |
|
361 | + } |
|
362 | + |
|
363 | + return $subscription_url; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Check if the gateway is available for use. |
|
368 | + * |
|
369 | + * @return bool |
|
370 | + */ |
|
371 | + public function is_available() { |
|
372 | + return ! empty( $this->enabled ); |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Return the gateway's title. |
|
377 | + * |
|
378 | + * @return string |
|
379 | + */ |
|
380 | + public function get_title() { |
|
381 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Return the gateway's description. |
|
386 | + * |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + public function get_description() { |
|
390 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Process Payment. |
|
395 | + * |
|
396 | + * |
|
397 | + * @param WPInv_Invoice $invoice Invoice. |
|
398 | + * @param array $submission_data Posted checkout fields. |
|
399 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
400 | + * @return void |
|
401 | + */ |
|
402 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
403 | + // Process the payment then either redirect to the success page or the gateway. |
|
404 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * Process refund. |
|
409 | + * |
|
410 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
411 | + * a passed in amount. |
|
412 | + * |
|
413 | + * @param WPInv_Invoice $invoice Invoice. |
|
414 | + * @param float $amount Refund amount. |
|
415 | + * @param string $reason Refund reason. |
|
416 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
417 | + */ |
|
418 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
419 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Displays the payment fields, credit cards etc. |
|
424 | + * |
|
425 | + * @param int $invoice_id 0 or invoice id. |
|
426 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
427 | + */ |
|
428 | + public function payment_fields( $invoice_id, $form ) { |
|
429 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Filters the gateway settings. |
|
434 | + * |
|
435 | + * @param array $admin_settings |
|
436 | + */ |
|
437 | + public function admin_settings( $admin_settings ) { |
|
438 | + return $admin_settings; |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * Retrieves the value of a gateway setting. |
|
443 | + * |
|
444 | + * @param string $option |
|
445 | + */ |
|
446 | + public function get_option( $option, $default = false ) { |
|
447 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * Check if a gateway supports a given feature. |
|
452 | + * |
|
453 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
454 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
455 | + * |
|
456 | + * @param string $feature string The name of a feature to test support for. |
|
457 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
458 | + * @since 1.0.19 |
|
459 | + */ |
|
460 | + public function supports( $feature ) { |
|
461 | + return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Returns the credit card form html. |
|
466 | + * |
|
467 | + * @param bool $save whether or not to display the save button. |
|
468 | + */ |
|
469 | 469 | public function get_cc_form( $save = false ) { |
470 | 470 | |
471 | - ob_start(); |
|
471 | + ob_start(); |
|
472 | 472 | |
473 | 473 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
474 | 474 | |
@@ -528,9 +528,9 @@ discard block |
||
528 | 528 | |
529 | 529 | <?php |
530 | 530 | foreach ( $months as $key => $month ) { |
531 | - $key = esc_attr( $key ); |
|
532 | - $month = esc_html( $month ); |
|
533 | - echo "<option value='$key'>$month</option>" . PHP_EOL; |
|
531 | + $key = esc_attr( $key ); |
|
532 | + $month = esc_html( $month ); |
|
533 | + echo "<option value='$key'>$month</option>" . PHP_EOL; |
|
534 | 534 | } |
535 | 535 | ?> |
536 | 536 | |
@@ -543,9 +543,9 @@ discard block |
||
543 | 543 | |
544 | 544 | <?php |
545 | 545 | foreach ( $years as $key => $year ) { |
546 | - $key = esc_attr( $key ); |
|
547 | - $year = esc_html( $year ); |
|
548 | - echo "<option value='$key'>$year</option>" . PHP_EOL; |
|
546 | + $key = esc_attr( $key ); |
|
547 | + $year = esc_html( $year ); |
|
548 | + echo "<option value='$key'>$year</option>" . PHP_EOL; |
|
549 | 549 | } |
550 | 550 | ?> |
551 | 551 | |
@@ -563,13 +563,13 @@ discard block |
||
563 | 563 | 'name' => $this->id . '[cc_cvv2]', |
564 | 564 | 'id' => "$id_prefix-cc-cvv2", |
565 | 565 | 'label' => __( 'CCV', 'invoicing' ), |
566 | - 'label_type' => 'vertical', |
|
567 | - 'class' => 'form-control-sm', |
|
568 | - 'extra_attributes' => array( |
|
569 | - 'autocomplete' => 'cc-csc', |
|
570 | - ), |
|
566 | + 'label_type' => 'vertical', |
|
567 | + 'class' => 'form-control-sm', |
|
568 | + 'extra_attributes' => array( |
|
569 | + 'autocomplete' => 'cc-csc', |
|
570 | + ), |
|
571 | 571 | ), |
572 | - true |
|
572 | + true |
|
573 | 573 | ); |
574 | 574 | ?> |
575 | 575 | </div> |
@@ -578,192 +578,192 @@ discard block |
||
578 | 578 | |
579 | 579 | <?php |
580 | 580 | |
581 | - if ( $save ) { |
|
582 | - echo $this->save_payment_method_checkbox(); |
|
583 | - } |
|
581 | + if ( $save ) { |
|
582 | + echo $this->save_payment_method_checkbox(); |
|
583 | + } |
|
584 | 584 | |
585 | - ?> |
|
585 | + ?> |
|
586 | 586 | </div> |
587 | 587 | |
588 | 588 | </div> |
589 | 589 | <?php |
590 | 590 | |
591 | - return ob_get_clean(); |
|
591 | + return ob_get_clean(); |
|
592 | + |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * Displays a new payment method entry form. |
|
597 | + * |
|
598 | + * @since 1.0.19 |
|
599 | + */ |
|
600 | + public function new_payment_method_entry( $form ) { |
|
601 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
602 | + } |
|
603 | + |
|
604 | + /** |
|
605 | + * Grab and display our saved payment methods. |
|
606 | + * |
|
607 | + * @since 1.0.19 |
|
608 | + */ |
|
609 | + public function saved_payment_methods() { |
|
610 | + $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
611 | + |
|
612 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
613 | + $html .= $this->get_saved_payment_method_option_html( $token ); |
|
614 | + } |
|
615 | + |
|
616 | + $html .= $this->get_new_payment_method_option_html(); |
|
617 | + $html .= '</ul>'; |
|
592 | 618 | |
619 | + echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
593 | 620 | } |
594 | 621 | |
595 | - /** |
|
596 | - * Displays a new payment method entry form. |
|
597 | - * |
|
598 | - * @since 1.0.19 |
|
599 | - */ |
|
600 | - public function new_payment_method_entry( $form ) { |
|
601 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
602 | - } |
|
603 | - |
|
604 | - /** |
|
605 | - * Grab and display our saved payment methods. |
|
606 | - * |
|
607 | - * @since 1.0.19 |
|
608 | - */ |
|
609 | - public function saved_payment_methods() { |
|
610 | - $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
611 | - |
|
612 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
613 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
614 | - } |
|
615 | - |
|
616 | - $html .= $this->get_new_payment_method_option_html(); |
|
617 | - $html .= '</ul>'; |
|
618 | - |
|
619 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
620 | - } |
|
621 | - |
|
622 | - /** |
|
623 | - * Gets saved payment method HTML from a token. |
|
624 | - * |
|
625 | - * @since 1.0.19 |
|
626 | - * @param array $token Payment Token. |
|
627 | - * @return string Generated payment method HTML |
|
628 | - */ |
|
629 | - public function get_saved_payment_method_option_html( $token ) { |
|
630 | - |
|
631 | - return sprintf( |
|
632 | - '<li class="getpaid-payment-method form-group"> |
|
622 | + /** |
|
623 | + * Gets saved payment method HTML from a token. |
|
624 | + * |
|
625 | + * @since 1.0.19 |
|
626 | + * @param array $token Payment Token. |
|
627 | + * @return string Generated payment method HTML |
|
628 | + */ |
|
629 | + public function get_saved_payment_method_option_html( $token ) { |
|
630 | + |
|
631 | + return sprintf( |
|
632 | + '<li class="getpaid-payment-method form-group"> |
|
633 | 633 | <label> |
634 | 634 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" data-currency="%5$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
635 | 635 | <span>%3$s</span> |
636 | 636 | </label> |
637 | 637 | </li>', |
638 | - esc_attr( $this->id ), |
|
639 | - esc_attr( $token['id'] ), |
|
640 | - esc_html( $token['name'] ), |
|
641 | - checked( empty( $token['default'] ), false, false ), |
|
642 | - empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
643 | - ); |
|
644 | - |
|
645 | - } |
|
646 | - |
|
647 | - /** |
|
648 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
649 | - * |
|
650 | - * @since 1.0.19 |
|
651 | - */ |
|
652 | - public function get_new_payment_method_option_html() { |
|
653 | - |
|
654 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
655 | - |
|
656 | - return sprintf( |
|
657 | - '<li class="getpaid-new-payment-method"> |
|
638 | + esc_attr( $this->id ), |
|
639 | + esc_attr( $token['id'] ), |
|
640 | + esc_html( $token['name'] ), |
|
641 | + checked( empty( $token['default'] ), false, false ), |
|
642 | + empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
643 | + ); |
|
644 | + |
|
645 | + } |
|
646 | + |
|
647 | + /** |
|
648 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
649 | + * |
|
650 | + * @since 1.0.19 |
|
651 | + */ |
|
652 | + public function get_new_payment_method_option_html() { |
|
653 | + |
|
654 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
655 | + |
|
656 | + return sprintf( |
|
657 | + '<li class="getpaid-new-payment-method"> |
|
658 | 658 | <label> |
659 | 659 | <input name="getpaid-%1$s-payment-method" type="radio" data-currency="none" value="new" style="width:auto;" /> |
660 | 660 | <span>%2$s</span> |
661 | 661 | </label> |
662 | 662 | </li>', |
663 | - esc_attr( $this->id ), |
|
664 | - esc_html( $label ) |
|
665 | - ); |
|
666 | - |
|
667 | - } |
|
668 | - |
|
669 | - /** |
|
670 | - * Outputs a checkbox for saving a new payment method to the database. |
|
671 | - * |
|
672 | - * @since 1.0.19 |
|
673 | - */ |
|
674 | - public function save_payment_method_checkbox() { |
|
675 | - |
|
676 | - return aui()->input( |
|
677 | - array( |
|
678 | - 'type' => 'checkbox', |
|
679 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
680 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
681 | - 'required' => false, |
|
682 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
683 | - 'value' => 'true', |
|
684 | - 'checked' => true, |
|
685 | - 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
686 | - ) |
|
687 | - ); |
|
688 | - |
|
689 | - } |
|
690 | - |
|
691 | - /** |
|
692 | - * Registers the gateway. |
|
693 | - * |
|
694 | - * @return array |
|
695 | - */ |
|
696 | - public function register_gateway( $gateways ) { |
|
697 | - |
|
698 | - $gateways[ $this->id ] = array( |
|
699 | - |
|
700 | - 'admin_label' => $this->method_title, |
|
663 | + esc_attr( $this->id ), |
|
664 | + esc_html( $label ) |
|
665 | + ); |
|
666 | + |
|
667 | + } |
|
668 | + |
|
669 | + /** |
|
670 | + * Outputs a checkbox for saving a new payment method to the database. |
|
671 | + * |
|
672 | + * @since 1.0.19 |
|
673 | + */ |
|
674 | + public function save_payment_method_checkbox() { |
|
675 | + |
|
676 | + return aui()->input( |
|
677 | + array( |
|
678 | + 'type' => 'checkbox', |
|
679 | + 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
680 | + 'id' => esc_attr( uniqid( $this->id ) ), |
|
681 | + 'required' => false, |
|
682 | + 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
683 | + 'value' => 'true', |
|
684 | + 'checked' => true, |
|
685 | + 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
686 | + ) |
|
687 | + ); |
|
688 | + |
|
689 | + } |
|
690 | + |
|
691 | + /** |
|
692 | + * Registers the gateway. |
|
693 | + * |
|
694 | + * @return array |
|
695 | + */ |
|
696 | + public function register_gateway( $gateways ) { |
|
697 | + |
|
698 | + $gateways[ $this->id ] = array( |
|
699 | + |
|
700 | + 'admin_label' => $this->method_title, |
|
701 | 701 | 'checkout_label' => $this->title, |
702 | - 'ordering' => $this->order, |
|
702 | + 'ordering' => $this->order, |
|
703 | 703 | |
704 | - ); |
|
704 | + ); |
|
705 | 705 | |
706 | - return $gateways; |
|
706 | + return $gateways; |
|
707 | 707 | |
708 | - } |
|
708 | + } |
|
709 | 709 | |
710 | - /** |
|
711 | - * Checks whether or not this is a sandbox request. |
|
712 | - * |
|
713 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
714 | - * @return bool |
|
715 | - */ |
|
716 | - public function is_sandbox( $invoice = null ) { |
|
710 | + /** |
|
711 | + * Checks whether or not this is a sandbox request. |
|
712 | + * |
|
713 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
714 | + * @return bool |
|
715 | + */ |
|
716 | + public function is_sandbox( $invoice = null ) { |
|
717 | 717 | |
718 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
719 | - return $invoice->get_mode() == 'test'; |
|
720 | - } |
|
718 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
719 | + return $invoice->get_mode() == 'test'; |
|
720 | + } |
|
721 | 721 | |
722 | - return wpinv_is_test_mode( $this->id ); |
|
722 | + return wpinv_is_test_mode( $this->id ); |
|
723 | 723 | |
724 | - } |
|
724 | + } |
|
725 | 725 | |
726 | - /** |
|
727 | - * Renames the checkout button |
|
728 | - * |
|
729 | - * @return string |
|
730 | - */ |
|
731 | - public function rename_checkout_button() { |
|
732 | - return $this->checkout_button_text; |
|
733 | - } |
|
726 | + /** |
|
727 | + * Renames the checkout button |
|
728 | + * |
|
729 | + * @return string |
|
730 | + */ |
|
731 | + public function rename_checkout_button() { |
|
732 | + return $this->checkout_button_text; |
|
733 | + } |
|
734 | 734 | |
735 | - /** |
|
736 | - * Validate gateway currency |
|
737 | - * |
|
738 | - * @return bool |
|
739 | - */ |
|
740 | - public function validate_currency( $validation, $currency ) { |
|
735 | + /** |
|
736 | + * Validate gateway currency |
|
737 | + * |
|
738 | + * @return bool |
|
739 | + */ |
|
740 | + public function validate_currency( $validation, $currency ) { |
|
741 | 741 | |
742 | - // Required currencies. |
|
743 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
744 | - return false; |
|
745 | - } |
|
742 | + // Required currencies. |
|
743 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
744 | + return false; |
|
745 | + } |
|
746 | 746 | |
747 | - // Excluded currencies. |
|
748 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
749 | - return false; |
|
750 | - } |
|
747 | + // Excluded currencies. |
|
748 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
749 | + return false; |
|
750 | + } |
|
751 | 751 | |
752 | - return $validation; |
|
753 | - } |
|
752 | + return $validation; |
|
753 | + } |
|
754 | 754 | |
755 | - /** |
|
756 | - * Displays an error |
|
757 | - * |
|
758 | - */ |
|
759 | - public function show_error( $code, $message, $type ) { |
|
755 | + /** |
|
756 | + * Displays an error |
|
757 | + * |
|
758 | + */ |
|
759 | + public function show_error( $code, $message, $type ) { |
|
760 | 760 | |
761 | - if ( is_admin() ) { |
|
762 | - getpaid_admin()->{"show_$type"}( $message ); |
|
763 | - } |
|
761 | + if ( is_admin() ) { |
|
762 | + getpaid_admin()->{"show_$type"}( $message ); |
|
763 | + } |
|
764 | 764 | |
765 | - wpinv_set_error( $code, $message, $type ); |
|
765 | + wpinv_set_error( $code, $message, $type ); |
|
766 | 766 | |
767 | - } |
|
767 | + } |
|
768 | 768 | |
769 | 769 | } |