@@ -1,16 +1,16 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
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 | 15 | echo $discount->get_code(); |
16 | 16 | break; |
@@ -21,33 +21,33 @@ discard block |
||
21 | 21 | echo $discount->get_usage(); |
22 | 22 | break; |
23 | 23 | case 'start_date' : |
24 | - echo getpaid_format_date_value( $discount->get_start_date() ); |
|
24 | + echo getpaid_format_date_value($discount->get_start_date()); |
|
25 | 25 | break; |
26 | 26 | case 'expiry_date' : |
27 | - echo getpaid_format_date_value( $discount->get_expiration_date(), __( 'Never', 'invoicing' ) ); |
|
27 | + echo 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 | - $url = esc_url( |
|
50 | + $url = esc_url( |
|
51 | 51 | wp_nonce_url( |
52 | 52 | add_query_arg( |
53 | 53 | array( |
@@ -59,13 +59,13 @@ discard block |
||
59 | 59 | 'getpaid-nonce' |
60 | 60 | ) |
61 | 61 | ); |
62 | - $anchor = __( 'Deactivate', 'invoicing' ); |
|
63 | - $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
62 | + $anchor = __('Deactivate', 'invoicing'); |
|
63 | + $title = esc_attr__('Are you sure you want to deactivate this discount?', 'invoicing'); |
|
64 | 64 | $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
65 | 65 | |
66 | - } else if( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
|
66 | + } else if (in_array(strtolower($discount->post_status), array('pending', 'draft'))) { |
|
67 | 67 | |
68 | - $url = esc_url( |
|
68 | + $url = esc_url( |
|
69 | 69 | wp_nonce_url( |
70 | 70 | add_query_arg( |
71 | 71 | array( |
@@ -77,13 +77,13 @@ discard block |
||
77 | 77 | 'getpaid-nonce' |
78 | 78 | ) |
79 | 79 | ); |
80 | - $anchor = __( 'Activate', 'invoicing' ); |
|
81 | - $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
80 | + $anchor = __('Activate', 'invoicing'); |
|
81 | + $title = esc_attr__('Are you sure you want to activate this discount?', 'invoicing'); |
|
82 | 82 | $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
83 | 83 | |
84 | 84 | } |
85 | 85 | |
86 | - $url = esc_url( |
|
86 | + $url = esc_url( |
|
87 | 87 | wp_nonce_url( |
88 | 88 | add_query_arg( |
89 | 89 | array( |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | 'getpaid-nonce' |
96 | 96 | ) |
97 | 97 | ); |
98 | - $anchor = __( 'Delete', 'invoicing' ); |
|
99 | - $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
98 | + $anchor = __('Delete', 'invoicing'); |
|
99 | + $title = esc_attr__('Are you sure you want to delete this discount?', 'invoicing'); |
|
100 | 100 | $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
101 | 101 | |
102 | - $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
|
102 | + $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount); |
|
103 | 103 | |
104 | 104 | return $row_actions; |
105 | 105 | } |
@@ -107,68 +107,68 @@ discard block |
||
107 | 107 | function wpinv_restrict_manage_posts() { |
108 | 108 | global $typenow; |
109 | 109 | |
110 | - if( 'wpi_discount' == $typenow ) { |
|
110 | + if ('wpi_discount' == $typenow) { |
|
111 | 111 | wpinv_discount_filters(); |
112 | 112 | } |
113 | 113 | } |
114 | -add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 ); |
|
114 | +add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10); |
|
115 | 115 | |
116 | 116 | function wpinv_discount_filters() { |
117 | 117 | |
118 | 118 | ?> |
119 | 119 | <select name="discount_type" id="dropdown_wpinv_discount_type"> |
120 | - <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option> |
|
120 | + <option value=""><?php _e('Show all types', 'invoicing'); ?></option> |
|
121 | 121 | <?php |
122 | 122 | $types = wpinv_get_discount_types(); |
123 | 123 | |
124 | - foreach ( $types as $name => $type ) { |
|
125 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
124 | + foreach ($types as $name => $type) { |
|
125 | + echo '<option value="' . esc_attr($name) . '"'; |
|
126 | 126 | |
127 | - if ( isset( $_GET['discount_type'] ) ) |
|
128 | - selected( $name, $_GET['discount_type'] ); |
|
127 | + if (isset($_GET['discount_type'])) |
|
128 | + selected($name, $_GET['discount_type']); |
|
129 | 129 | |
130 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
130 | + echo '>' . esc_html__($type, 'invoicing') . '</option>'; |
|
131 | 131 | } |
132 | 132 | ?> |
133 | 133 | </select> |
134 | 134 | <?php |
135 | 135 | } |
136 | 136 | |
137 | -function wpinv_request( $vars ) { |
|
137 | +function wpinv_request($vars) { |
|
138 | 138 | global $typenow, $wp_post_statuses; |
139 | 139 | |
140 | - if ( getpaid_is_invoice_post_type( $typenow ) ) { |
|
141 | - if ( ! isset( $vars['post_status'] ) ) { |
|
142 | - $post_statuses = wpinv_get_invoice_statuses( false, false, $typenow ); |
|
140 | + if (getpaid_is_invoice_post_type($typenow)) { |
|
141 | + if (!isset($vars['post_status'])) { |
|
142 | + $post_statuses = wpinv_get_invoice_statuses(false, false, $typenow); |
|
143 | 143 | |
144 | - foreach ( $post_statuses as $status => $value ) { |
|
145 | - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { |
|
146 | - unset( $post_statuses[ $status ] ); |
|
144 | + foreach ($post_statuses as $status => $value) { |
|
145 | + if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) { |
|
146 | + unset($post_statuses[$status]); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
150 | - $vars['post_status'] = array_keys( $post_statuses ); |
|
150 | + $vars['post_status'] = array_keys($post_statuses); |
|
151 | 151 | } |
152 | 152 | |
153 | - } else if ( 'wpi_discount' == $typenow ) { |
|
154 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
153 | + } else if ('wpi_discount' == $typenow) { |
|
154 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
155 | 155 | // Filter vat rule type |
156 | - if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
|
156 | + if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') { |
|
157 | 157 | $meta_query[] = array( |
158 | 158 | 'key' => '_wpi_discount_type', |
159 | - 'value' => sanitize_text_field( $_GET['discount_type'] ), |
|
159 | + 'value' => sanitize_text_field($_GET['discount_type']), |
|
160 | 160 | 'compare' => '=' |
161 | 161 | ); |
162 | 162 | } |
163 | 163 | |
164 | - if ( !empty( $meta_query ) ) { |
|
164 | + if (!empty($meta_query)) { |
|
165 | 165 | $vars['meta_query'] = $meta_query; |
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | 169 | return $vars; |
170 | 170 | } |
171 | -add_filter( 'request', 'wpinv_request' ); |
|
171 | +add_filter('request', 'wpinv_request'); |
|
172 | 172 | |
173 | 173 | /** |
174 | 174 | * Create a page and store the ID in an option. |
@@ -180,19 +180,19 @@ discard block |
||
180 | 180 | * @param int $post_parent (default: 0) Parent for the new page |
181 | 181 | * @return int page ID |
182 | 182 | */ |
183 | -function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) { |
|
183 | +function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) { |
|
184 | 184 | global $wpdb; |
185 | 185 | |
186 | - $option_value = wpinv_get_option( $option ); |
|
186 | + $option_value = wpinv_get_option($option); |
|
187 | 187 | |
188 | - if ( ! empty( $option_value ) && ( $page_object = get_post( $option_value ) ) ) { |
|
189 | - if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) { |
|
188 | + if (!empty($option_value) && ($page_object = get_post($option_value))) { |
|
189 | + if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) { |
|
190 | 190 | // Valid page is already in place |
191 | 191 | return $page_object->ID; |
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
195 | - if(!empty($post_parent)){ |
|
195 | + if (!empty($post_parent)) { |
|
196 | 196 | $page = get_page_by_path($post_parent); |
197 | 197 | if ($page) { |
198 | 198 | $post_parent = $page->ID; |
@@ -201,40 +201,40 @@ discard block |
||
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | - if ( strlen( $page_content ) > 0 ) { |
|
204 | + if (strlen($page_content) > 0) { |
|
205 | 205 | // Search for an existing page with the specified page content (typically a shortcode) |
206 | - $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}%" ) ); |
|
206 | + $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}%")); |
|
207 | 207 | } else { |
208 | 208 | // Search for an existing page with the specified page slug |
209 | - $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 ) ); |
|
209 | + $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)); |
|
210 | 210 | } |
211 | 211 | |
212 | - $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content ); |
|
212 | + $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content); |
|
213 | 213 | |
214 | - if ( $valid_page_found ) { |
|
215 | - if ( $option ) { |
|
216 | - wpinv_update_option( $option, $valid_page_found ); |
|
214 | + if ($valid_page_found) { |
|
215 | + if ($option) { |
|
216 | + wpinv_update_option($option, $valid_page_found); |
|
217 | 217 | } |
218 | 218 | return $valid_page_found; |
219 | 219 | } |
220 | 220 | |
221 | 221 | // Search for a matching valid trashed page |
222 | - if ( strlen( $page_content ) > 0 ) { |
|
222 | + if (strlen($page_content) > 0) { |
|
223 | 223 | // Search for an existing page with the specified page content (typically a shortcode) |
224 | - $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}%" ) ); |
|
224 | + $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}%")); |
|
225 | 225 | } else { |
226 | 226 | // Search for an existing page with the specified page slug |
227 | - $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 ) ); |
|
227 | + $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)); |
|
228 | 228 | } |
229 | 229 | |
230 | - if ( $trashed_page_found ) { |
|
230 | + if ($trashed_page_found) { |
|
231 | 231 | $page_id = $trashed_page_found; |
232 | 232 | $page_data = array( |
233 | 233 | 'ID' => $page_id, |
234 | 234 | 'post_status' => 'publish', |
235 | 235 | 'post_parent' => $post_parent, |
236 | 236 | ); |
237 | - wp_update_post( $page_data ); |
|
237 | + wp_update_post($page_data); |
|
238 | 238 | } else { |
239 | 239 | $page_data = array( |
240 | 240 | 'post_status' => 'publish', |
@@ -246,11 +246,11 @@ discard block |
||
246 | 246 | 'post_parent' => $post_parent, |
247 | 247 | 'comment_status' => 'closed', |
248 | 248 | ); |
249 | - $page_id = wp_insert_post( $page_data ); |
|
249 | + $page_id = wp_insert_post($page_data); |
|
250 | 250 | } |
251 | 251 | |
252 | - if ( $option ) { |
|
253 | - wpinv_update_option( $option, (int)$page_id ); |
|
252 | + if ($option) { |
|
253 | + wpinv_update_option($option, (int) $page_id); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | return $page_id; |
@@ -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,20 +21,20 @@ 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 | ?> |
30 | 30 | |
31 | 31 | <div class='bsui' style='padding-top: 10px;'> |
32 | - <?php do_action( 'wpinv_item_before_info_metabox', $item ); ?> |
|
32 | + <?php do_action('wpinv_item_before_info_metabox', $item); ?> |
|
33 | 33 | |
34 | 34 | <div class="wpinv_item_type form-group row"> |
35 | 35 | <label for="wpinv_item_type" class="col-sm-12 col-form-label"> |
36 | - <?php _e( 'Item Type', 'invoicing' );?> |
|
37 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php echo strip_tags( self::get_tooltip( $post ) ); ?>"></span> |
|
36 | + <?php _e('Item Type', 'invoicing'); ?> |
|
37 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php echo strip_tags(self::get_tooltip($post)); ?>"></span> |
|
38 | 38 | </label> |
39 | 39 | |
40 | 40 | <div class="col-sm-12"> |
@@ -44,8 +44,8 @@ discard block |
||
44 | 44 | array( |
45 | 45 | 'id' => 'wpinv_item_type', |
46 | 46 | 'name' => 'wpinv_item_type', |
47 | - 'placeholder' => __( 'Select item type', 'invoicing' ), |
|
48 | - 'value' => $item->get_type( 'edit' ), |
|
47 | + 'placeholder' => __('Select item type', 'invoicing'), |
|
48 | + 'value' => $item->get_type('edit'), |
|
49 | 49 | 'select2' => true, |
50 | 50 | 'data-allow-clear' => 'false', |
51 | 51 | 'no_wrap' => true, |
@@ -59,42 +59,42 @@ discard block |
||
59 | 59 | |
60 | 60 | <div class="wpinv_item_shortcode form-group row"> |
61 | 61 | <label for="wpinv_item_shortcode" class="col-sm-12 col-form-label"> |
62 | - <?php _e( 'Payment Form Shortcode', 'invoicing' );?> |
|
63 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Displays a payment form', 'invoicing' ); ?>"></span> |
|
62 | + <?php _e('Payment Form Shortcode', 'invoicing'); ?> |
|
63 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Displays a payment form', 'invoicing'); ?>"></span> |
|
64 | 64 | </label> |
65 | 65 | |
66 | 66 | <div class="col-sm-12"> |
67 | - <input onClick="this.select()" type="text" id="wpinv_item_shortcode" value="[getpaid item=<?php echo esc_attr( $item->get_id() ); ?>]" style="width: 100%;" readonly/> |
|
67 | + <input onClick="this.select()" type="text" id="wpinv_item_shortcode" value="[getpaid item=<?php echo esc_attr($item->get_id()); ?>]" style="width: 100%;" readonly/> |
|
68 | 68 | </div> |
69 | 69 | </div> |
70 | 70 | |
71 | 71 | <div class="wpinv_item_buy_shortcode form-group row"> |
72 | 72 | <label for="wpinv_item_button_shortcode" class="col-sm-12 col-form-label"> |
73 | - <?php _e( 'Payment Button Shortcode', 'invoicing' );?> |
|
74 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Displays a buy now button', 'invoicing' ); ?>"></span> |
|
73 | + <?php _e('Payment Button Shortcode', 'invoicing'); ?> |
|
74 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Displays a buy now button', 'invoicing'); ?>"></span> |
|
75 | 75 | </label> |
76 | 76 | |
77 | 77 | <div class="col-sm-12"> |
78 | - <input onClick="this.select()" type="text" id="wpinv_item_button_shortcode" value="[getpaid item=<?php echo esc_attr( $item->get_id() ); ?> button='Buy Now']" style="width: 100%;" readonly/> |
|
78 | + <input onClick="this.select()" type="text" id="wpinv_item_button_shortcode" value="[getpaid item=<?php echo esc_attr($item->get_id()); ?> button='Buy Now']" style="width: 100%;" readonly/> |
|
79 | 79 | <small class="form-text text-muted"> |
80 | - <?php _e( 'Or use the following URL in a link:', 'invoicing' );?> |
|
81 | - <code>#getpaid-item-<?php echo intval( $item->get_id() ); ?>|0</code> |
|
80 | + <?php _e('Or use the following URL in a link:', 'invoicing'); ?> |
|
81 | + <code>#getpaid-item-<?php echo intval($item->get_id()); ?>|0</code> |
|
82 | 82 | </small> |
83 | 83 | </div> |
84 | 84 | </div> |
85 | 85 | |
86 | 86 | <div class="wpinv_item_custom_id form-group"> |
87 | - <?php _e( 'Custom ID', 'invoicing' );?> — <?php echo sanitize_text_field( $item->get_custom_id() ) ?> |
|
87 | + <?php _e('Custom ID', 'invoicing'); ?> — <?php echo sanitize_text_field($item->get_custom_id()) ?> |
|
88 | 88 | </div> |
89 | 89 | |
90 | - <?php do_action( 'wpinv_meta_values_metabox_before', $post ); ?> |
|
91 | - <?php foreach ( apply_filters( 'wpinv_show_meta_values_for_keys', array() ) as $meta_key ) : ?> |
|
90 | + <?php do_action('wpinv_meta_values_metabox_before', $post); ?> |
|
91 | + <?php foreach (apply_filters('wpinv_show_meta_values_for_keys', array()) as $meta_key) : ?> |
|
92 | 92 | <div class="wpinv_item_custom_id form-group"> |
93 | - <?php sanitize_text_field( $meta_key );?> — <?php echo sanitize_text_field( get_post_meta( $item->get_id(), '_wpinv_' . $meta_key, true ) ); ?> |
|
93 | + <?php sanitize_text_field($meta_key); ?> — <?php echo sanitize_text_field(get_post_meta($item->get_id(), '_wpinv_' . $meta_key, true)); ?> |
|
94 | 94 | </div> |
95 | 95 | <?php endforeach; ?> |
96 | - <?php do_action( 'wpinv_meta_values_metabox_after', $post ); ?> |
|
97 | - <?php do_action( 'wpinv_item_info_metabox', $item ); ?> |
|
96 | + <?php do_action('wpinv_meta_values_metabox_after', $post); ?> |
|
97 | + <?php do_action('wpinv_item_info_metabox', $item); ?> |
|
98 | 98 | </div> |
99 | 99 | <?php |
100 | 100 | |
@@ -104,16 +104,16 @@ discard block |
||
104 | 104 | * Returns item type tolltip. |
105 | 105 | * |
106 | 106 | */ |
107 | - public static function get_tooltip( $post ) { |
|
107 | + public static function get_tooltip($post) { |
|
108 | 108 | |
109 | 109 | ob_start(); |
110 | 110 | ?> |
111 | 111 | |
112 | - <?php _e( 'Standard: Standard item type', 'invoicing' );?> |
|
113 | - <?php _e( 'Fee: Like Registration Fee, Sign up Fee etc', 'invoicing' );?> |
|
112 | + <?php _e('Standard: Standard item type', 'invoicing'); ?> |
|
113 | + <?php _e('Fee: Like Registration Fee, Sign up Fee etc', 'invoicing'); ?> |
|
114 | 114 | |
115 | 115 | <?php |
116 | - do_action( 'wpinv_item_info_metabox_after', $post ); |
|
116 | + do_action('wpinv_item_info_metabox_after', $post); |
|
117 | 117 | |
118 | 118 | return ob_get_clean(); |
119 | 119 |
@@ -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,43 +21,43 @@ 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 form. |
27 | - $form = new GetPaid_Payment_Form( $post ); |
|
27 | + $form = new GetPaid_Payment_Form($post); |
|
28 | 28 | |
29 | 29 | ?> |
30 | 30 | |
31 | 31 | <div class='bsui' style='padding-top: 10px;'> |
32 | - <?php do_action( 'wpinv_payment_form_before_info_metabox', $form ); ?> |
|
32 | + <?php do_action('wpinv_payment_form_before_info_metabox', $form); ?> |
|
33 | 33 | |
34 | 34 | <div class="wpinv_payment_form_shortcode form-group row"> |
35 | 35 | <label for="wpinv_payment_form_shortcode" class="col-sm-12 col-form-label"> |
36 | - <?php _e( 'Payment Form Shortcode', 'invoicing' );?> |
|
37 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Displays a payment form', 'invoicing' ); ?>"></span> |
|
36 | + <?php _e('Payment Form Shortcode', 'invoicing'); ?> |
|
37 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Displays a payment form', 'invoicing'); ?>"></span> |
|
38 | 38 | </label> |
39 | 39 | |
40 | 40 | <div class="col-sm-12"> |
41 | - <input onClick="this.select()" type="text" id="wpinv_payment_form_shortcode" value="[getpaid form=<?php echo esc_attr( $form->get_id() ); ?>]" style="width: 100%;" /> |
|
41 | + <input onClick="this.select()" type="text" id="wpinv_payment_form_shortcode" value="[getpaid form=<?php echo esc_attr($form->get_id()); ?>]" style="width: 100%;" /> |
|
42 | 42 | </div> |
43 | 43 | </div> |
44 | 44 | |
45 | 45 | <div class="wpinv_payment_form_buy_shortcode form-group row"> |
46 | 46 | <label for="wpinv_payment_form_buy_shortcode" class="col-sm-12 col-form-label"> |
47 | - <?php _e( 'Payment Button Shortcode', 'invoicing' );?> |
|
48 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Displays a buy now button', 'invoicing' ); ?>"></span> |
|
47 | + <?php _e('Payment Button Shortcode', 'invoicing'); ?> |
|
48 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Displays a buy now button', 'invoicing'); ?>"></span> |
|
49 | 49 | </label> |
50 | 50 | |
51 | 51 | <div class="col-sm-12"> |
52 | - <input onClick="this.select()" type="text" id="wpinv_payment_form_buy_shortcode" value="[getpaid form=<?php echo esc_attr( $form->get_id() ); ?> button='Buy Now']" style="width: 100%;" /> |
|
52 | + <input onClick="this.select()" type="text" id="wpinv_payment_form_buy_shortcode" value="[getpaid form=<?php echo esc_attr($form->get_id()); ?> button='Buy Now']" style="width: 100%;" /> |
|
53 | 53 | <small class="form-text text-muted"> |
54 | - <?php _e( 'Or use the following URL in a link:', 'invoicing' );?> |
|
55 | - <code>#getpaid-form-<?php echo intval( $form->get_id() ); ?></code> |
|
54 | + <?php _e('Or use the following URL in a link:', 'invoicing'); ?> |
|
55 | + <code>#getpaid-form-<?php echo intval($form->get_id()); ?></code> |
|
56 | 56 | </small> |
57 | 57 | </div> |
58 | 58 | </div> |
59 | 59 | |
60 | - <?php do_action( 'wpinv_payment_form_info_metabox', $form ); ?> |
|
60 | + <?php do_action('wpinv_payment_form_info_metabox', $form); ?> |
|
61 | 61 | </div> |
62 | 62 | <?php |
63 | 63 |
@@ -13,264 +13,264 @@ |
||
13 | 13 | */ |
14 | 14 | class GetPaid_Geolocation { |
15 | 15 | |
16 | - /** |
|
17 | - * Holds the current user's IP Address. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public static $current_user_ip; |
|
22 | - |
|
23 | - /** |
|
24 | - * API endpoints for looking up a user IP address. |
|
25 | - * |
|
26 | - * For example, in case a user is on localhost. |
|
27 | - * |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected static $ip_lookup_apis = array( |
|
31 | - 'ipify' => 'http://api.ipify.org/', |
|
32 | - 'ipecho' => 'http://ipecho.net/plain', |
|
33 | - 'ident' => 'http://ident.me', |
|
34 | - 'whatismyipaddress' => 'http://bot.whatismyipaddress.com', |
|
35 | - ); |
|
36 | - |
|
37 | - /** |
|
38 | - * API endpoints for geolocating an IP address |
|
39 | - * |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - protected static $geoip_apis = array( |
|
43 | - 'ip-api.com' => 'http://ip-api.com/json/%s', |
|
44 | - 'ipinfo.io' => 'https://ipinfo.io/%s/json', |
|
45 | - ); |
|
46 | - |
|
47 | - /** |
|
48 | - * Get current user IP Address. |
|
49 | - * |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - public static function get_ip_address() { |
|
53 | - return wpinv_get_ip(); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Get user IP Address using an external service. |
|
58 | - * This can be used as a fallback for users on localhost where |
|
59 | - * get_ip_address() will be a local IP and non-geolocatable. |
|
60 | - * |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public static function get_external_ip_address() { |
|
64 | - |
|
65 | - $transient_name = 'external_ip_address_0.0.0.0'; |
|
66 | - |
|
67 | - if ( '' !== self::get_ip_address() ) { |
|
68 | - $transient_name = 'external_ip_address_' . self::get_ip_address(); |
|
69 | - } |
|
70 | - |
|
71 | - // Try retrieving from cache. |
|
72 | - $external_ip_address = get_transient( $transient_name ); |
|
73 | - |
|
74 | - if ( false === $external_ip_address ) { |
|
75 | - $external_ip_address = '0.0.0.0'; |
|
76 | - $ip_lookup_services = apply_filters( 'getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis ); |
|
77 | - $ip_lookup_services_keys = array_keys( $ip_lookup_services ); |
|
78 | - shuffle( $ip_lookup_services_keys ); |
|
79 | - |
|
80 | - foreach ( $ip_lookup_services_keys as $service_name ) { |
|
81 | - $service_endpoint = $ip_lookup_services[ $service_name ]; |
|
82 | - $response = wp_safe_remote_get( $service_endpoint, array( 'timeout' => 2 ) ); |
|
83 | - |
|
84 | - if ( ! is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) { |
|
85 | - $external_ip_address = apply_filters( 'getpaid_geolocation_ip_lookup_api_response', wpinv_clean( $response['body'] ), $service_name ); |
|
86 | - break; |
|
87 | - } |
|
88 | - |
|
89 | - } |
|
90 | - |
|
91 | - set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS ); |
|
92 | - } |
|
93 | - |
|
94 | - return $external_ip_address; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Geolocate an IP address. |
|
99 | - * |
|
100 | - * @param string $ip_address IP Address. |
|
101 | - * @param bool $fallback If true, fallbacks to alternative IP detection (can be slower). |
|
102 | - * @param bool $api_fallback If true, uses geolocation APIs if the database file doesn't exist (can be slower). |
|
103 | - * @return array |
|
104 | - */ |
|
105 | - public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) { |
|
106 | - |
|
107 | - if ( empty( $ip_address ) ) { |
|
108 | - $ip_address = self::get_ip_address(); |
|
109 | - } |
|
110 | - |
|
111 | - // Update the current user's IP Address. |
|
112 | - self::$current_user_ip = $ip_address; |
|
113 | - |
|
114 | - // Filter to allow custom geolocation of the IP address. |
|
115 | - $country_code = apply_filters( 'getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback ); |
|
116 | - |
|
117 | - if ( false !== $country_code ) { |
|
118 | - |
|
119 | - return array( |
|
120 | - 'country' => $country_code, |
|
121 | - 'state' => '', |
|
122 | - 'city' => '', |
|
123 | - 'postcode' => '', |
|
124 | - ); |
|
125 | - |
|
126 | - } |
|
127 | - |
|
128 | - $country_code = self::get_country_code_from_headers(); |
|
129 | - |
|
130 | - /** |
|
131 | - * Get geolocation filter. |
|
132 | - * |
|
133 | - * @since 1.0.19 |
|
134 | - * @param array $geolocation Geolocation data, including country, state, city, and postcode. |
|
135 | - * @param string $ip_address IP Address. |
|
136 | - */ |
|
137 | - $geolocation = apply_filters( |
|
138 | - 'getpaid_get_geolocation', |
|
139 | - array( |
|
140 | - 'country' => $country_code, |
|
141 | - 'state' => '', |
|
142 | - 'city' => '', |
|
143 | - 'postcode' => '', |
|
144 | - ), |
|
145 | - $ip_address |
|
146 | - ); |
|
147 | - |
|
148 | - // If we still haven't found a country code, let's consider doing an API lookup. |
|
149 | - if ( '' === $geolocation['country'] && $api_fallback ) { |
|
150 | - $geolocation['country'] = self::geolocate_via_api( $ip_address ); |
|
151 | - } |
|
152 | - |
|
153 | - // It's possible that we're in a local environment, in which case the geolocation needs to be done from the |
|
154 | - // external address. |
|
155 | - if ( '' === $geolocation['country'] && $fallback ) { |
|
156 | - $external_ip_address = self::get_external_ip_address(); |
|
157 | - |
|
158 | - // Only bother with this if the external IP differs. |
|
159 | - if ( '0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address ) { |
|
160 | - return self::geolocate_ip( $external_ip_address, false, $api_fallback ); |
|
161 | - } |
|
162 | - |
|
163 | - } |
|
164 | - |
|
165 | - return array( |
|
166 | - 'country' => $geolocation['country'], |
|
167 | - 'state' => $geolocation['state'], |
|
168 | - 'city' => $geolocation['city'], |
|
169 | - 'postcode' => $geolocation['postcode'], |
|
170 | - ); |
|
171 | - |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Fetches the country code from the request headers, if one is available. |
|
176 | - * |
|
177 | - * @since 1.0.19 |
|
178 | - * @return string The country code pulled from the headers, or empty string if one was not found. |
|
179 | - */ |
|
180 | - protected static function get_country_code_from_headers() { |
|
181 | - $country_code = ''; |
|
182 | - |
|
183 | - $headers = array( |
|
184 | - 'MM_COUNTRY_CODE', |
|
185 | - 'GEOIP_COUNTRY_CODE', |
|
186 | - 'HTTP_CF_IPCOUNTRY', |
|
187 | - 'HTTP_X_COUNTRY_CODE', |
|
188 | - ); |
|
189 | - |
|
190 | - foreach ( $headers as $header ) { |
|
191 | - if ( empty( $_SERVER[ $header ] ) ) { |
|
192 | - continue; |
|
193 | - } |
|
194 | - |
|
195 | - $country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) ); |
|
196 | - break; |
|
197 | - } |
|
198 | - |
|
199 | - return $country_code; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Use APIs to Geolocate the user. |
|
204 | - * |
|
205 | - * Geolocation APIs can be added through the use of the getpaid_geolocation_geoip_apis filter. |
|
206 | - * Provide a name=>value pair for service-slug=>endpoint. |
|
207 | - * |
|
208 | - * If APIs are defined, one will be chosen at random to fulfil the request. After completing, the result |
|
209 | - * will be cached in a transient. |
|
210 | - * |
|
211 | - * @param string $ip_address IP address. |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - protected static function geolocate_via_api( $ip_address ) { |
|
215 | - |
|
216 | - // Retrieve from cache... |
|
217 | - $country_code = get_transient( 'geoip_' . $ip_address ); |
|
218 | - |
|
219 | - // If missing, retrieve from the API. |
|
220 | - if ( false === $country_code ) { |
|
221 | - $geoip_services = apply_filters( 'getpaid_geolocation_geoip_apis', self::$geoip_apis ); |
|
222 | - |
|
223 | - if ( empty( $geoip_services ) ) { |
|
224 | - return ''; |
|
225 | - } |
|
226 | - |
|
227 | - $geoip_services_keys = array_keys( $geoip_services ); |
|
228 | - |
|
229 | - shuffle( $geoip_services_keys ); |
|
230 | - |
|
231 | - foreach ( $geoip_services_keys as $service_name ) { |
|
232 | - |
|
233 | - $service_endpoint = $geoip_services[ $service_name ]; |
|
234 | - $response = wp_safe_remote_get( sprintf( $service_endpoint, $ip_address ), array( 'timeout' => 2 ) ); |
|
235 | - $country_code = sanitize_text_field( strtoupper( self::handle_geolocation_response( $response, $service_name ) ) ); |
|
236 | - |
|
237 | - if ( ! empty( $country_code ) ) { |
|
238 | - break; |
|
239 | - } |
|
240 | - |
|
241 | - } |
|
242 | - |
|
243 | - set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS ); |
|
244 | - } |
|
245 | - |
|
246 | - return $country_code; |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * Handles geolocation response |
|
251 | - * |
|
252 | - * @param WP_Error|String $geolocation_response |
|
253 | - * @param String $geolocation_service |
|
254 | - * @return string Country code |
|
255 | - */ |
|
256 | - protected static function handle_geolocation_response( $geolocation_response, $geolocation_service ) { |
|
257 | - |
|
258 | - if ( is_wp_error( $geolocation_response ) || empty( $geolocation_response['body'] ) ) { |
|
259 | - return ''; |
|
260 | - } |
|
261 | - |
|
262 | - if ( $geolocation_service === 'ipinfo.io' ) { |
|
263 | - $data = json_decode( $geolocation_response['body'] ); |
|
264 | - return empty( $data ) ? '' : $data->country; |
|
265 | - } |
|
266 | - |
|
267 | - if ( $geolocation_service === 'ip-api.com' ) { |
|
268 | - $data = json_decode( $geolocation_response['body'] ); |
|
269 | - return empty( $data ) ? '' : $data->countryCode; |
|
270 | - } |
|
271 | - |
|
272 | - return apply_filters( 'getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body'] ); |
|
273 | - |
|
274 | - } |
|
16 | + /** |
|
17 | + * Holds the current user's IP Address. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public static $current_user_ip; |
|
22 | + |
|
23 | + /** |
|
24 | + * API endpoints for looking up a user IP address. |
|
25 | + * |
|
26 | + * For example, in case a user is on localhost. |
|
27 | + * |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected static $ip_lookup_apis = array( |
|
31 | + 'ipify' => 'http://api.ipify.org/', |
|
32 | + 'ipecho' => 'http://ipecho.net/plain', |
|
33 | + 'ident' => 'http://ident.me', |
|
34 | + 'whatismyipaddress' => 'http://bot.whatismyipaddress.com', |
|
35 | + ); |
|
36 | + |
|
37 | + /** |
|
38 | + * API endpoints for geolocating an IP address |
|
39 | + * |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + protected static $geoip_apis = array( |
|
43 | + 'ip-api.com' => 'http://ip-api.com/json/%s', |
|
44 | + 'ipinfo.io' => 'https://ipinfo.io/%s/json', |
|
45 | + ); |
|
46 | + |
|
47 | + /** |
|
48 | + * Get current user IP Address. |
|
49 | + * |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + public static function get_ip_address() { |
|
53 | + return wpinv_get_ip(); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Get user IP Address using an external service. |
|
58 | + * This can be used as a fallback for users on localhost where |
|
59 | + * get_ip_address() will be a local IP and non-geolocatable. |
|
60 | + * |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public static function get_external_ip_address() { |
|
64 | + |
|
65 | + $transient_name = 'external_ip_address_0.0.0.0'; |
|
66 | + |
|
67 | + if ( '' !== self::get_ip_address() ) { |
|
68 | + $transient_name = 'external_ip_address_' . self::get_ip_address(); |
|
69 | + } |
|
70 | + |
|
71 | + // Try retrieving from cache. |
|
72 | + $external_ip_address = get_transient( $transient_name ); |
|
73 | + |
|
74 | + if ( false === $external_ip_address ) { |
|
75 | + $external_ip_address = '0.0.0.0'; |
|
76 | + $ip_lookup_services = apply_filters( 'getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis ); |
|
77 | + $ip_lookup_services_keys = array_keys( $ip_lookup_services ); |
|
78 | + shuffle( $ip_lookup_services_keys ); |
|
79 | + |
|
80 | + foreach ( $ip_lookup_services_keys as $service_name ) { |
|
81 | + $service_endpoint = $ip_lookup_services[ $service_name ]; |
|
82 | + $response = wp_safe_remote_get( $service_endpoint, array( 'timeout' => 2 ) ); |
|
83 | + |
|
84 | + if ( ! is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) { |
|
85 | + $external_ip_address = apply_filters( 'getpaid_geolocation_ip_lookup_api_response', wpinv_clean( $response['body'] ), $service_name ); |
|
86 | + break; |
|
87 | + } |
|
88 | + |
|
89 | + } |
|
90 | + |
|
91 | + set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS ); |
|
92 | + } |
|
93 | + |
|
94 | + return $external_ip_address; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Geolocate an IP address. |
|
99 | + * |
|
100 | + * @param string $ip_address IP Address. |
|
101 | + * @param bool $fallback If true, fallbacks to alternative IP detection (can be slower). |
|
102 | + * @param bool $api_fallback If true, uses geolocation APIs if the database file doesn't exist (can be slower). |
|
103 | + * @return array |
|
104 | + */ |
|
105 | + public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) { |
|
106 | + |
|
107 | + if ( empty( $ip_address ) ) { |
|
108 | + $ip_address = self::get_ip_address(); |
|
109 | + } |
|
110 | + |
|
111 | + // Update the current user's IP Address. |
|
112 | + self::$current_user_ip = $ip_address; |
|
113 | + |
|
114 | + // Filter to allow custom geolocation of the IP address. |
|
115 | + $country_code = apply_filters( 'getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback ); |
|
116 | + |
|
117 | + if ( false !== $country_code ) { |
|
118 | + |
|
119 | + return array( |
|
120 | + 'country' => $country_code, |
|
121 | + 'state' => '', |
|
122 | + 'city' => '', |
|
123 | + 'postcode' => '', |
|
124 | + ); |
|
125 | + |
|
126 | + } |
|
127 | + |
|
128 | + $country_code = self::get_country_code_from_headers(); |
|
129 | + |
|
130 | + /** |
|
131 | + * Get geolocation filter. |
|
132 | + * |
|
133 | + * @since 1.0.19 |
|
134 | + * @param array $geolocation Geolocation data, including country, state, city, and postcode. |
|
135 | + * @param string $ip_address IP Address. |
|
136 | + */ |
|
137 | + $geolocation = apply_filters( |
|
138 | + 'getpaid_get_geolocation', |
|
139 | + array( |
|
140 | + 'country' => $country_code, |
|
141 | + 'state' => '', |
|
142 | + 'city' => '', |
|
143 | + 'postcode' => '', |
|
144 | + ), |
|
145 | + $ip_address |
|
146 | + ); |
|
147 | + |
|
148 | + // If we still haven't found a country code, let's consider doing an API lookup. |
|
149 | + if ( '' === $geolocation['country'] && $api_fallback ) { |
|
150 | + $geolocation['country'] = self::geolocate_via_api( $ip_address ); |
|
151 | + } |
|
152 | + |
|
153 | + // It's possible that we're in a local environment, in which case the geolocation needs to be done from the |
|
154 | + // external address. |
|
155 | + if ( '' === $geolocation['country'] && $fallback ) { |
|
156 | + $external_ip_address = self::get_external_ip_address(); |
|
157 | + |
|
158 | + // Only bother with this if the external IP differs. |
|
159 | + if ( '0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address ) { |
|
160 | + return self::geolocate_ip( $external_ip_address, false, $api_fallback ); |
|
161 | + } |
|
162 | + |
|
163 | + } |
|
164 | + |
|
165 | + return array( |
|
166 | + 'country' => $geolocation['country'], |
|
167 | + 'state' => $geolocation['state'], |
|
168 | + 'city' => $geolocation['city'], |
|
169 | + 'postcode' => $geolocation['postcode'], |
|
170 | + ); |
|
171 | + |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Fetches the country code from the request headers, if one is available. |
|
176 | + * |
|
177 | + * @since 1.0.19 |
|
178 | + * @return string The country code pulled from the headers, or empty string if one was not found. |
|
179 | + */ |
|
180 | + protected static function get_country_code_from_headers() { |
|
181 | + $country_code = ''; |
|
182 | + |
|
183 | + $headers = array( |
|
184 | + 'MM_COUNTRY_CODE', |
|
185 | + 'GEOIP_COUNTRY_CODE', |
|
186 | + 'HTTP_CF_IPCOUNTRY', |
|
187 | + 'HTTP_X_COUNTRY_CODE', |
|
188 | + ); |
|
189 | + |
|
190 | + foreach ( $headers as $header ) { |
|
191 | + if ( empty( $_SERVER[ $header ] ) ) { |
|
192 | + continue; |
|
193 | + } |
|
194 | + |
|
195 | + $country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) ); |
|
196 | + break; |
|
197 | + } |
|
198 | + |
|
199 | + return $country_code; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Use APIs to Geolocate the user. |
|
204 | + * |
|
205 | + * Geolocation APIs can be added through the use of the getpaid_geolocation_geoip_apis filter. |
|
206 | + * Provide a name=>value pair for service-slug=>endpoint. |
|
207 | + * |
|
208 | + * If APIs are defined, one will be chosen at random to fulfil the request. After completing, the result |
|
209 | + * will be cached in a transient. |
|
210 | + * |
|
211 | + * @param string $ip_address IP address. |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + protected static function geolocate_via_api( $ip_address ) { |
|
215 | + |
|
216 | + // Retrieve from cache... |
|
217 | + $country_code = get_transient( 'geoip_' . $ip_address ); |
|
218 | + |
|
219 | + // If missing, retrieve from the API. |
|
220 | + if ( false === $country_code ) { |
|
221 | + $geoip_services = apply_filters( 'getpaid_geolocation_geoip_apis', self::$geoip_apis ); |
|
222 | + |
|
223 | + if ( empty( $geoip_services ) ) { |
|
224 | + return ''; |
|
225 | + } |
|
226 | + |
|
227 | + $geoip_services_keys = array_keys( $geoip_services ); |
|
228 | + |
|
229 | + shuffle( $geoip_services_keys ); |
|
230 | + |
|
231 | + foreach ( $geoip_services_keys as $service_name ) { |
|
232 | + |
|
233 | + $service_endpoint = $geoip_services[ $service_name ]; |
|
234 | + $response = wp_safe_remote_get( sprintf( $service_endpoint, $ip_address ), array( 'timeout' => 2 ) ); |
|
235 | + $country_code = sanitize_text_field( strtoupper( self::handle_geolocation_response( $response, $service_name ) ) ); |
|
236 | + |
|
237 | + if ( ! empty( $country_code ) ) { |
|
238 | + break; |
|
239 | + } |
|
240 | + |
|
241 | + } |
|
242 | + |
|
243 | + set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS ); |
|
244 | + } |
|
245 | + |
|
246 | + return $country_code; |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Handles geolocation response |
|
251 | + * |
|
252 | + * @param WP_Error|String $geolocation_response |
|
253 | + * @param String $geolocation_service |
|
254 | + * @return string Country code |
|
255 | + */ |
|
256 | + protected static function handle_geolocation_response( $geolocation_response, $geolocation_service ) { |
|
257 | + |
|
258 | + if ( is_wp_error( $geolocation_response ) || empty( $geolocation_response['body'] ) ) { |
|
259 | + return ''; |
|
260 | + } |
|
261 | + |
|
262 | + if ( $geolocation_service === 'ipinfo.io' ) { |
|
263 | + $data = json_decode( $geolocation_response['body'] ); |
|
264 | + return empty( $data ) ? '' : $data->country; |
|
265 | + } |
|
266 | + |
|
267 | + if ( $geolocation_service === 'ip-api.com' ) { |
|
268 | + $data = json_decode( $geolocation_response['body'] ); |
|
269 | + return empty( $data ) ? '' : $data->countryCode; |
|
270 | + } |
|
271 | + |
|
272 | + return apply_filters( 'getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body'] ); |
|
273 | + |
|
274 | + } |
|
275 | 275 | |
276 | 276 | } |
@@ -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 ) |
@@ -255,24 +255,24 @@ discard block |
||
255 | 255 | check_ajax_referer( 'getpaid_form_nonce' ); |
256 | 256 | |
257 | 257 | // Is the request set up correctly? |
258 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
259 | - echo aui()->alert( |
|
260 | - array( |
|
261 | - 'type' => 'warning', |
|
262 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
263 | - ) |
|
258 | + if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
259 | + echo aui()->alert( |
|
260 | + array( |
|
261 | + 'type' => 'warning', |
|
262 | + 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
263 | + ) |
|
264 | 264 | ); |
265 | 265 | exit; |
266 | 266 | } |
267 | 267 | |
268 | 268 | // Payment form or button? |
269 | - if ( ! empty( $_GET['form'] ) ) { |
|
269 | + if ( ! empty( $_GET['form'] ) ) { |
|
270 | 270 | getpaid_display_payment_form( urldecode( $_GET['form'] ) ); |
271 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
272 | - getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) ); |
|
271 | + } else if( ! empty( $_GET['invoice'] ) ) { |
|
272 | + getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) ); |
|
273 | 273 | } else { |
274 | - $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) ); |
|
275 | - getpaid_display_item_payment_form( $items ); |
|
274 | + $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) ); |
|
275 | + getpaid_display_item_payment_form( $items ); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | exit; |
@@ -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 | |
@@ -101,36 +101,36 @@ discard block |
||
101 | 101 | 'payment_form_refresh_prices' => true, |
102 | 102 | ); |
103 | 103 | |
104 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
105 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
106 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
104 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
105 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
106 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
107 | 107 | |
108 | - if ( $nopriv ) { |
|
109 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
110 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
111 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
108 | + if ($nopriv) { |
|
109 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
110 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
111 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | 116 | public static function add_note() { |
117 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
117 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
118 | 118 | |
119 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
119 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
120 | 120 | die(-1); |
121 | 121 | } |
122 | 122 | |
123 | - $post_id = absint( $_POST['post_id'] ); |
|
124 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
125 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
123 | + $post_id = absint($_POST['post_id']); |
|
124 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
125 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
126 | 126 | |
127 | 127 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
128 | 128 | |
129 | - if ( $post_id > 0 ) { |
|
130 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
129 | + if ($post_id > 0) { |
|
130 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
131 | 131 | |
132 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
133 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
132 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
133 | + wpinv_get_invoice_note_line_item($note_id); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
@@ -138,16 +138,16 @@ discard block |
||
138 | 138 | } |
139 | 139 | |
140 | 140 | public static function delete_note() { |
141 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
141 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
142 | 142 | |
143 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
143 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
144 | 144 | die(-1); |
145 | 145 | } |
146 | 146 | |
147 | - $note_id = (int)$_POST['note_id']; |
|
147 | + $note_id = (int) $_POST['note_id']; |
|
148 | 148 | |
149 | - if ( $note_id > 0 ) { |
|
150 | - wp_delete_comment( $note_id, true ); |
|
149 | + if ($note_id > 0) { |
|
150 | + wp_delete_comment($note_id, true); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | die(); |
@@ -165,34 +165,34 @@ discard block |
||
165 | 165 | public static function get_billing_details() { |
166 | 166 | |
167 | 167 | // Verify nonce. |
168 | - check_ajax_referer( 'wpinv-nonce' ); |
|
168 | + check_ajax_referer('wpinv-nonce'); |
|
169 | 169 | |
170 | 170 | // Can the user manage the plugin? |
171 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
171 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
172 | 172 | die(-1); |
173 | 173 | } |
174 | 174 | |
175 | 175 | // Do we have a user id? |
176 | 176 | $user_id = $_GET['user_id']; |
177 | 177 | |
178 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
178 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
179 | 179 | die(-1); |
180 | 180 | } |
181 | 181 | |
182 | 182 | // Fetch the billing details. |
183 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
184 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
183 | + $billing_details = wpinv_get_user_address($user_id); |
|
184 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
185 | 185 | |
186 | 186 | // unset the user id and email. |
187 | - $to_ignore = array( 'user_id', 'email' ); |
|
187 | + $to_ignore = array('user_id', 'email'); |
|
188 | 188 | |
189 | - foreach ( $to_ignore as $key ) { |
|
190 | - if ( isset( $billing_details[ $key ] ) ) { |
|
191 | - unset( $billing_details[ $key ] ); |
|
189 | + foreach ($to_ignore as $key) { |
|
190 | + if (isset($billing_details[$key])) { |
|
191 | + unset($billing_details[$key]); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
195 | - wp_send_json_success( $billing_details ); |
|
195 | + wp_send_json_success($billing_details); |
|
196 | 196 | |
197 | 197 | } |
198 | 198 | |
@@ -202,47 +202,47 @@ discard block |
||
202 | 202 | public static function check_new_user_email() { |
203 | 203 | |
204 | 204 | // Verify nonce. |
205 | - check_ajax_referer( 'wpinv-nonce' ); |
|
205 | + check_ajax_referer('wpinv-nonce'); |
|
206 | 206 | |
207 | 207 | // Can the user manage the plugin? |
208 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
208 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
209 | 209 | die(-1); |
210 | 210 | } |
211 | 211 | |
212 | 212 | // We need an email address. |
213 | - if ( empty( $_GET['email'] ) ) { |
|
214 | - _e( "Provide the new user's email address", 'invoicing' ); |
|
213 | + if (empty($_GET['email'])) { |
|
214 | + _e("Provide the new user's email address", 'invoicing'); |
|
215 | 215 | exit; |
216 | 216 | } |
217 | 217 | |
218 | 218 | // Ensure the email is valid. |
219 | - $email = sanitize_text_field( $_GET['email'] ); |
|
220 | - if ( ! is_email( $email ) ) { |
|
221 | - _e( 'Invalid email address', 'invoicing' ); |
|
219 | + $email = sanitize_text_field($_GET['email']); |
|
220 | + if (!is_email($email)) { |
|
221 | + _e('Invalid email address', 'invoicing'); |
|
222 | 222 | exit; |
223 | 223 | } |
224 | 224 | |
225 | 225 | // And it does not exist. |
226 | - if ( email_exists( $email ) ) { |
|
227 | - _e( 'A user with this email address already exists', 'invoicing' ); |
|
226 | + if (email_exists($email)) { |
|
227 | + _e('A user with this email address already exists', 'invoicing'); |
|
228 | 228 | exit; |
229 | 229 | } |
230 | 230 | |
231 | - wp_send_json_success( true ); |
|
231 | + wp_send_json_success(true); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | public static function run_tool() { |
235 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
236 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
235 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
236 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
237 | 237 | die(-1); |
238 | 238 | } |
239 | 239 | |
240 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
240 | + $tool = sanitize_text_field($_POST['tool']); |
|
241 | 241 | |
242 | - do_action( 'wpinv_run_tool' ); |
|
242 | + do_action('wpinv_run_tool'); |
|
243 | 243 | |
244 | - if ( !empty( $tool ) ) { |
|
245 | - do_action( 'wpinv_tool_' . $tool ); |
|
244 | + if (!empty($tool)) { |
|
245 | + do_action('wpinv_tool_' . $tool); |
|
246 | 246 | } |
247 | 247 | } |
248 | 248 | |
@@ -252,27 +252,27 @@ discard block |
||
252 | 252 | public static function get_payment_form() { |
253 | 253 | |
254 | 254 | // Check nonce. |
255 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
255 | + check_ajax_referer('getpaid_form_nonce'); |
|
256 | 256 | |
257 | 257 | // Is the request set up correctly? |
258 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
258 | + if (empty($_GET['form']) && empty($_GET['item'])) { |
|
259 | 259 | echo aui()->alert( |
260 | 260 | array( |
261 | 261 | 'type' => 'warning', |
262 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
262 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
263 | 263 | ) |
264 | 264 | ); |
265 | 265 | exit; |
266 | 266 | } |
267 | 267 | |
268 | 268 | // Payment form or button? |
269 | - if ( ! empty( $_GET['form'] ) ) { |
|
270 | - getpaid_display_payment_form( urldecode( $_GET['form'] ) ); |
|
271 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
272 | - getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) ); |
|
269 | + if (!empty($_GET['form'])) { |
|
270 | + getpaid_display_payment_form(urldecode($_GET['form'])); |
|
271 | + } else if (!empty($_GET['invoice'])) { |
|
272 | + getpaid_display_invoice_payment_form(urldecode($_GET['invoice'])); |
|
273 | 273 | } else { |
274 | - $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) ); |
|
275 | - getpaid_display_item_payment_form( $items ); |
|
274 | + $items = getpaid_convert_items_to_array(urldecode($_GET['item'])); |
|
275 | + getpaid_display_item_payment_form($items); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | exit; |
@@ -287,17 +287,17 @@ discard block |
||
287 | 287 | public static function payment_form() { |
288 | 288 | |
289 | 289 | // Check nonce. |
290 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
290 | + check_ajax_referer('getpaid_form_nonce'); |
|
291 | 291 | |
292 | 292 | // ... form fields... |
293 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
294 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
293 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
294 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
295 | 295 | exit; |
296 | 296 | } |
297 | 297 | |
298 | 298 | // Process the payment form. |
299 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
300 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
299 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
300 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
301 | 301 | $checkout->process_checkout(); |
302 | 302 | |
303 | 303 | exit; |
@@ -310,55 +310,55 @@ discard block |
||
310 | 310 | */ |
311 | 311 | public static function get_payment_form_states_field() { |
312 | 312 | |
313 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
313 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
314 | 314 | exit; |
315 | 315 | } |
316 | 316 | |
317 | - $elements = getpaid_get_payment_form_elements( $_GET['form'] ); |
|
317 | + $elements = getpaid_get_payment_form_elements($_GET['form']); |
|
318 | 318 | |
319 | - if ( empty( $elements ) ) { |
|
319 | + if (empty($elements)) { |
|
320 | 320 | exit; |
321 | 321 | } |
322 | 322 | |
323 | 323 | $address_fields = array(); |
324 | - foreach ( $elements as $element ) { |
|
325 | - if ( 'address' === $element['type'] ) { |
|
324 | + foreach ($elements as $element) { |
|
325 | + if ('address' === $element['type']) { |
|
326 | 326 | $address_fields = $element; |
327 | 327 | break; |
328 | 328 | } |
329 | 329 | } |
330 | 330 | |
331 | - if ( empty( $address_fields ) ) { |
|
331 | + if (empty($address_fields)) { |
|
332 | 332 | exit; |
333 | 333 | } |
334 | 334 | |
335 | - foreach ( $address_fields['fields'] as $address_field ) { |
|
335 | + foreach ($address_fields['fields'] as $address_field) { |
|
336 | 336 | |
337 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
337 | + if ('wpinv_state' == $address_field['name']) { |
|
338 | 338 | |
339 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
340 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
341 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
342 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
343 | - $value = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : ''; |
|
344 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
339 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
340 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
341 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
342 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
343 | + $value = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : ''; |
|
344 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
345 | 345 | |
346 | - if ( ! empty( $address_field['required'] ) ) { |
|
346 | + if (!empty($address_field['required'])) { |
|
347 | 347 | $label .= "<span class='text-danger'> *</span>"; |
348 | 348 | } |
349 | 349 | |
350 | - $html = getpaid_get_states_select_markup ( |
|
351 | - sanitize_text_field( $_GET['country'] ), |
|
350 | + $html = getpaid_get_states_select_markup( |
|
351 | + sanitize_text_field($_GET['country']), |
|
352 | 352 | $value, |
353 | 353 | $placeholder, |
354 | 354 | $label, |
355 | 355 | $description, |
356 | - ! empty( $address_field['required'] ), |
|
356 | + !empty($address_field['required']), |
|
357 | 357 | $wrap_class, |
358 | - wpinv_clean( $_GET['name'] ) |
|
358 | + wpinv_clean($_GET['name']) |
|
359 | 359 | ); |
360 | 360 | |
361 | - wp_send_json_success( $html ); |
|
361 | + wp_send_json_success($html); |
|
362 | 362 | exit; |
363 | 363 | |
364 | 364 | } |
@@ -374,56 +374,56 @@ discard block |
||
374 | 374 | public static function recalculate_invoice_totals() { |
375 | 375 | |
376 | 376 | // Verify nonce. |
377 | - check_ajax_referer( 'wpinv-nonce' ); |
|
377 | + check_ajax_referer('wpinv-nonce'); |
|
378 | 378 | |
379 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
379 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
380 | 380 | exit; |
381 | 381 | } |
382 | 382 | |
383 | 383 | // We need an invoice. |
384 | - if ( empty( $_POST['post_id'] ) ) { |
|
384 | + if (empty($_POST['post_id'])) { |
|
385 | 385 | exit; |
386 | 386 | } |
387 | 387 | |
388 | 388 | // Fetch the invoice. |
389 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
389 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
390 | 390 | |
391 | 391 | // Ensure it exists. |
392 | - if ( ! $invoice->get_id() ) { |
|
392 | + if (!$invoice->get_id()) { |
|
393 | 393 | exit; |
394 | 394 | } |
395 | 395 | |
396 | 396 | // Maybe set the country, state, currency. |
397 | - foreach ( array( 'country', 'state', 'currency' ) as $key ) { |
|
398 | - if ( isset( $_POST[ $key ] ) ) { |
|
397 | + foreach (array('country', 'state', 'currency') as $key) { |
|
398 | + if (isset($_POST[$key])) { |
|
399 | 399 | $method = "set_$key"; |
400 | - $invoice->$method( $_POST[ $key ] ); |
|
400 | + $invoice->$method($_POST[$key]); |
|
401 | 401 | } |
402 | 402 | } |
403 | 403 | |
404 | 404 | // Maybe disable taxes. |
405 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
405 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
406 | 406 | |
407 | 407 | // Recalculate totals. |
408 | 408 | $invoice->recalculate_total(); |
409 | 409 | |
410 | - $total = wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ); |
|
410 | + $total = wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()); |
|
411 | 411 | |
412 | - if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
413 | - $recurring_total = wpinv_price( wpinv_format_amount( $invoice->get_recurring_total() ), $invoice->get_currency() ); |
|
414 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
412 | + if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
413 | + $recurring_total = wpinv_price(wpinv_format_amount($invoice->get_recurring_total()), $invoice->get_currency()); |
|
414 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | $totals = array( |
418 | - 'subtotal' => wpinv_price( wpinv_format_amount( $invoice->get_subtotal() ), $invoice->get_currency() ), |
|
419 | - 'discount' => wpinv_price( wpinv_format_amount( $invoice->get_total_discount() ), $invoice->get_currency() ), |
|
420 | - 'tax' => wpinv_price( wpinv_format_amount( $invoice->get_total_tax() ), $invoice->get_currency() ), |
|
418 | + 'subtotal' => wpinv_price(wpinv_format_amount($invoice->get_subtotal()), $invoice->get_currency()), |
|
419 | + 'discount' => wpinv_price(wpinv_format_amount($invoice->get_total_discount()), $invoice->get_currency()), |
|
420 | + 'tax' => wpinv_price(wpinv_format_amount($invoice->get_total_tax()), $invoice->get_currency()), |
|
421 | 421 | 'total' => $total, |
422 | 422 | ); |
423 | 423 | |
424 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
424 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
425 | 425 | |
426 | - wp_send_json_success( compact( 'totals' ) ); |
|
426 | + wp_send_json_success(compact('totals')); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -432,33 +432,33 @@ discard block |
||
432 | 432 | public static function get_invoice_items() { |
433 | 433 | |
434 | 434 | // Verify nonce. |
435 | - check_ajax_referer( 'wpinv-nonce' ); |
|
435 | + check_ajax_referer('wpinv-nonce'); |
|
436 | 436 | |
437 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
437 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
438 | 438 | exit; |
439 | 439 | } |
440 | 440 | |
441 | 441 | // We need an invoice and items. |
442 | - if ( empty( $_POST['post_id'] ) ) { |
|
442 | + if (empty($_POST['post_id'])) { |
|
443 | 443 | exit; |
444 | 444 | } |
445 | 445 | |
446 | 446 | // Fetch the invoice. |
447 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
447 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
448 | 448 | |
449 | 449 | // Ensure it exists. |
450 | - if ( ! $invoice->get_id() ) { |
|
450 | + if (!$invoice->get_id()) { |
|
451 | 451 | exit; |
452 | 452 | } |
453 | 453 | |
454 | 454 | // Return an array of invoice items. |
455 | 455 | $items = array(); |
456 | 456 | |
457 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
458 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
457 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
458 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
459 | 459 | } |
460 | 460 | |
461 | - wp_send_json_success( compact( 'items' ) ); |
|
461 | + wp_send_json_success(compact('items')); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | /** |
@@ -467,50 +467,50 @@ discard block |
||
467 | 467 | public static function edit_invoice_item() { |
468 | 468 | |
469 | 469 | // Verify nonce. |
470 | - check_ajax_referer( 'wpinv-nonce' ); |
|
470 | + check_ajax_referer('wpinv-nonce'); |
|
471 | 471 | |
472 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
472 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
473 | 473 | exit; |
474 | 474 | } |
475 | 475 | |
476 | 476 | // We need an invoice and item details. |
477 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
477 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
478 | 478 | exit; |
479 | 479 | } |
480 | 480 | |
481 | 481 | // Fetch the invoice. |
482 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
482 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
483 | 483 | |
484 | 484 | // Ensure it exists and its not been paid for. |
485 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
485 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
486 | 486 | exit; |
487 | 487 | } |
488 | 488 | |
489 | 489 | // Format the data. |
490 | - $data = wp_list_pluck( $_POST['data'], 'value', 'field' ); |
|
490 | + $data = wp_list_pluck($_POST['data'], 'value', 'field'); |
|
491 | 491 | |
492 | 492 | // Ensure that we have an item id. |
493 | - if ( empty( $data['id'] ) ) { |
|
493 | + if (empty($data['id'])) { |
|
494 | 494 | exit; |
495 | 495 | } |
496 | 496 | |
497 | 497 | // Abort if the invoice does not have the specified item. |
498 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
498 | + $item = $invoice->get_item((int) $data['id']); |
|
499 | 499 | |
500 | - if ( empty( $item ) ) { |
|
500 | + if (empty($item)) { |
|
501 | 501 | exit; |
502 | 502 | } |
503 | 503 | |
504 | 504 | // Update the item. |
505 | - $item->set_price( $data['price'] ); |
|
506 | - $item->set_name( $data['name'] ); |
|
507 | - $item->set_description( $data['description'] ); |
|
508 | - $item->set_quantity( $data['quantity'] ); |
|
505 | + $item->set_price($data['price']); |
|
506 | + $item->set_name($data['name']); |
|
507 | + $item->set_description($data['description']); |
|
508 | + $item->set_quantity($data['quantity']); |
|
509 | 509 | |
510 | 510 | // Add it to the invoice. |
511 | - $error = $invoice->add_item( $item ); |
|
511 | + $error = $invoice->add_item($item); |
|
512 | 512 | $alert = false; |
513 | - if ( is_wp_error( $error ) ) { |
|
513 | + if (is_wp_error($error)) { |
|
514 | 514 | $alert = $error->get_error_message(); |
515 | 515 | } |
516 | 516 | |
@@ -523,11 +523,11 @@ discard block |
||
523 | 523 | // Return an array of invoice items. |
524 | 524 | $items = array(); |
525 | 525 | |
526 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
527 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
526 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
527 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
528 | 528 | } |
529 | 529 | |
530 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
530 | + wp_send_json_success(compact('items', 'alert')); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | /** |
@@ -536,33 +536,33 @@ discard block |
||
536 | 536 | public static function remove_invoice_item() { |
537 | 537 | |
538 | 538 | // Verify nonce. |
539 | - check_ajax_referer( 'wpinv-nonce' ); |
|
539 | + check_ajax_referer('wpinv-nonce'); |
|
540 | 540 | |
541 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
541 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
542 | 542 | exit; |
543 | 543 | } |
544 | 544 | |
545 | 545 | // We need an invoice and an item. |
546 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
546 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
547 | 547 | exit; |
548 | 548 | } |
549 | 549 | |
550 | 550 | // Fetch the invoice. |
551 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
551 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
552 | 552 | |
553 | 553 | // Ensure it exists and its not been paid for. |
554 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
554 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
555 | 555 | exit; |
556 | 556 | } |
557 | 557 | |
558 | 558 | // Abort if the invoice does not have the specified item. |
559 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
559 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
560 | 560 | |
561 | - if ( empty( $item ) ) { |
|
561 | + if (empty($item)) { |
|
562 | 562 | exit; |
563 | 563 | } |
564 | 564 | |
565 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
565 | + $invoice->remove_item((int) $_POST['item_id']); |
|
566 | 566 | |
567 | 567 | // Update totals. |
568 | 568 | $invoice->recalculate_total(); |
@@ -573,11 +573,11 @@ discard block |
||
573 | 573 | // Return an array of invoice items. |
574 | 574 | $items = array(); |
575 | 575 | |
576 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
577 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
576 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
577 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
578 | 578 | } |
579 | 579 | |
580 | - wp_send_json_success( compact( 'items' ) ); |
|
580 | + wp_send_json_success(compact('items')); |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
@@ -586,39 +586,39 @@ discard block |
||
586 | 586 | public static function add_invoice_items() { |
587 | 587 | |
588 | 588 | // Verify nonce. |
589 | - check_ajax_referer( 'wpinv-nonce' ); |
|
589 | + check_ajax_referer('wpinv-nonce'); |
|
590 | 590 | |
591 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
591 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
592 | 592 | exit; |
593 | 593 | } |
594 | 594 | |
595 | 595 | // We need an invoice and items. |
596 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
596 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
597 | 597 | exit; |
598 | 598 | } |
599 | 599 | |
600 | 600 | // Fetch the invoice. |
601 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
601 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
602 | 602 | $alert = false; |
603 | 603 | |
604 | 604 | // Ensure it exists and its not been paid for. |
605 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
605 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
606 | 606 | exit; |
607 | 607 | } |
608 | 608 | |
609 | 609 | // Add the items. |
610 | - foreach ( $_POST['items'] as $data ) { |
|
610 | + foreach ($_POST['items'] as $data) { |
|
611 | 611 | |
612 | - $item = new GetPaid_Form_Item( $data[ 'id' ] ); |
|
612 | + $item = new GetPaid_Form_Item($data['id']); |
|
613 | 613 | |
614 | - if ( is_numeric( $data[ 'qty' ] ) && (int) $data[ 'qty' ] > 0 ) { |
|
615 | - $item->set_quantity( $data[ 'qty' ] ); |
|
614 | + if (is_numeric($data['qty']) && (int) $data['qty'] > 0) { |
|
615 | + $item->set_quantity($data['qty']); |
|
616 | 616 | } |
617 | 617 | |
618 | - if ( $item->get_id() > 0 ) { |
|
619 | - $error = $invoice->add_item( $item ); |
|
618 | + if ($item->get_id() > 0) { |
|
619 | + $error = $invoice->add_item($item); |
|
620 | 620 | |
621 | - if ( is_wp_error( $error ) ) { |
|
621 | + if (is_wp_error($error)) { |
|
622 | 622 | $alert = $error->get_error_message(); |
623 | 623 | } |
624 | 624 | |
@@ -633,11 +633,11 @@ discard block |
||
633 | 633 | // Return an array of invoice items. |
634 | 634 | $items = array(); |
635 | 635 | |
636 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
637 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
636 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
637 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
638 | 638 | } |
639 | 639 | |
640 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
640 | + wp_send_json_success(compact('items', 'alert')); |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | /** |
@@ -646,15 +646,15 @@ discard block |
||
646 | 646 | public static function get_invoicing_items() { |
647 | 647 | |
648 | 648 | // Verify nonce. |
649 | - check_ajax_referer( 'wpinv-nonce' ); |
|
649 | + check_ajax_referer('wpinv-nonce'); |
|
650 | 650 | |
651 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
651 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
652 | 652 | exit; |
653 | 653 | } |
654 | 654 | |
655 | 655 | // We need a search term. |
656 | - if ( empty( $_GET['search'] ) ) { |
|
657 | - wp_send_json_success( array() ); |
|
656 | + if (empty($_GET['search'])) { |
|
657 | + wp_send_json_success(array()); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | // Retrieve items. |
@@ -663,8 +663,8 @@ discard block |
||
663 | 663 | 'orderby' => 'title', |
664 | 664 | 'order' => 'ASC', |
665 | 665 | 'posts_per_page' => -1, |
666 | - 'post_status' => array( 'publish' ), |
|
667 | - 's' => trim( $_GET['search'] ), |
|
666 | + 'post_status' => array('publish'), |
|
667 | + 's' => trim($_GET['search']), |
|
668 | 668 | 'meta_query' => array( |
669 | 669 | array( |
670 | 670 | 'key' => '_wpinv_type', |
@@ -674,22 +674,22 @@ discard block |
||
674 | 674 | ) |
675 | 675 | ); |
676 | 676 | |
677 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
677 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
678 | 678 | $data = array(); |
679 | 679 | |
680 | 680 | |
681 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) ); |
|
681 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id'])); |
|
682 | 682 | |
683 | - foreach ( $items as $item ) { |
|
684 | - $item = new GetPaid_Form_Item( $item ); |
|
683 | + foreach ($items as $item) { |
|
684 | + $item = new GetPaid_Form_Item($item); |
|
685 | 685 | $data[] = array( |
686 | 686 | 'id' => (int) $item->get_id(), |
687 | - 'text' => strip_tags( $item->get_name() ), |
|
688 | - 'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '', |
|
687 | + 'text' => strip_tags($item->get_name()), |
|
688 | + 'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '', |
|
689 | 689 | ); |
690 | 690 | } |
691 | 691 | |
692 | - wp_send_json_success( $data ); |
|
692 | + wp_send_json_success($data); |
|
693 | 693 | |
694 | 694 | } |
695 | 695 | |
@@ -699,24 +699,24 @@ discard block |
||
699 | 699 | public static function get_aui_states_field() { |
700 | 700 | |
701 | 701 | // Verify nonce. |
702 | - check_ajax_referer( 'wpinv-nonce' ); |
|
702 | + check_ajax_referer('wpinv-nonce'); |
|
703 | 703 | |
704 | 704 | // We need a country. |
705 | - if ( empty( $_GET['country'] ) ) { |
|
705 | + if (empty($_GET['country'])) { |
|
706 | 706 | exit; |
707 | 707 | } |
708 | 708 | |
709 | - $states = wpinv_get_country_states( trim( $_GET['country'] ) ); |
|
710 | - $state = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state(); |
|
709 | + $states = wpinv_get_country_states(trim($_GET['country'])); |
|
710 | + $state = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state(); |
|
711 | 711 | |
712 | - if ( empty( $states ) ) { |
|
712 | + if (empty($states)) { |
|
713 | 713 | |
714 | 714 | $html = aui()->input( |
715 | 715 | array( |
716 | 716 | 'type' => 'text', |
717 | 717 | 'id' => 'wpinv_state', |
718 | 718 | 'name' => 'wpinv_state', |
719 | - 'label' => __( 'State', 'invoicing' ), |
|
719 | + 'label' => __('State', 'invoicing'), |
|
720 | 720 | 'label_type' => 'vertical', |
721 | 721 | 'placeholder' => 'Liège', |
722 | 722 | 'class' => 'form-control-sm', |
@@ -730,9 +730,9 @@ discard block |
||
730 | 730 | array( |
731 | 731 | 'id' => 'wpinv_state', |
732 | 732 | 'name' => 'wpinv_state', |
733 | - 'label' => __( 'State', 'invoicing' ), |
|
733 | + 'label' => __('State', 'invoicing'), |
|
734 | 734 | 'label_type' => 'vertical', |
735 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
735 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
736 | 736 | 'class' => 'form-control-sm', |
737 | 737 | 'value' => $state, |
738 | 738 | 'options' => $states, |
@@ -746,7 +746,7 @@ discard block |
||
746 | 746 | wp_send_json_success( |
747 | 747 | array( |
748 | 748 | 'html' => $html, |
749 | - 'select' => ! empty ( $states ) |
|
749 | + 'select' => !empty ($states) |
|
750 | 750 | ) |
751 | 751 | ); |
752 | 752 | |
@@ -760,11 +760,11 @@ discard block |
||
760 | 760 | public static function payment_form_refresh_prices() { |
761 | 761 | |
762 | 762 | // Check nonce. |
763 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
763 | + check_ajax_referer('getpaid_form_nonce'); |
|
764 | 764 | |
765 | 765 | // ... form fields... |
766 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
767 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
766 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
767 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
768 | 768 | exit; |
769 | 769 | } |
770 | 770 | |
@@ -772,18 +772,18 @@ discard block |
||
772 | 772 | $submission = new GetPaid_Payment_Form_Submission(); |
773 | 773 | |
774 | 774 | // Do we have an error? |
775 | - if ( ! empty( $submission->last_error ) ) { |
|
775 | + if (!empty($submission->last_error)) { |
|
776 | 776 | echo $submission->last_error; |
777 | 777 | exit; |
778 | 778 | } |
779 | 779 | |
780 | 780 | // Prepare the response. |
781 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
781 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
782 | 782 | |
783 | 783 | // Filter the response. |
784 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
784 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
785 | 785 | |
786 | - wp_send_json_success( $response ); |
|
786 | + wp_send_json_success($response); |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | } |