@@ -7,7 +7,7 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 |
@@ -7,7 +7,7 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 |
@@ -7,7 +7,7 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 |
@@ -7,7 +7,7 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 |
@@ -14,62 +14,62 @@ discard block |
||
14 | 14 | class GetPaid_Admin { |
15 | 15 | |
16 | 16 | /** |
17 | - * Local path to this plugins admin directory |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $admin_path; |
|
22 | - |
|
23 | - /** |
|
24 | - * Web path to this plugins admin directory |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
17 | + * Local path to this plugins admin directory |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $admin_path; |
|
22 | + |
|
23 | + /** |
|
24 | + * Web path to this plugins admin directory |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | 28 | public $admin_url; |
29 | 29 | |
30 | 30 | /** |
31 | - * Class constructor. |
|
32 | - */ |
|
33 | - public function __construct(){ |
|
31 | + * Class constructor. |
|
32 | + */ |
|
33 | + public function __construct(){ |
|
34 | 34 | |
35 | 35 | $this->admin_path = plugin_dir_path( __FILE__ ); |
36 | 36 | $this->admin_url = plugins_url( '/', __FILE__ ); |
37 | 37 | |
38 | 38 | if ( is_admin() ) { |
39 | - $this->init_admin_hooks(); |
|
39 | + $this->init_admin_hooks(); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | - * Init action and filter hooks |
|
46 | - * |
|
47 | - */ |
|
48 | - private function init_admin_hooks() { |
|
45 | + * Init action and filter hooks |
|
46 | + * |
|
47 | + */ |
|
48 | + private function init_admin_hooks() { |
|
49 | 49 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
50 | 50 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
51 | 51 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
52 | 52 | add_action( 'admin_init', array( $this, 'activation_redirect') ); |
53 | 53 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
54 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
55 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
56 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
57 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
54 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
55 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
56 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
57 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
58 | 58 | |
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
62 | - * Register admin scripts |
|
63 | - * |
|
64 | - */ |
|
65 | - public function enqeue_scripts() { |
|
62 | + * Register admin scripts |
|
63 | + * |
|
64 | + */ |
|
65 | + public function enqeue_scripts() { |
|
66 | 66 | global $current_screen, $pagenow; |
67 | 67 | |
68 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
69 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
68 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
69 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
70 | 70 | |
71 | 71 | if ( ! empty( $current_screen->post_type ) ) { |
72 | - $page = $current_screen->post_type; |
|
72 | + $page = $current_screen->post_type; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | // General styles. |
@@ -93,30 +93,30 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | // Payment form scripts. |
96 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
96 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
97 | 97 | $this->load_payment_form_scripts(); |
98 | 98 | } |
99 | 99 | |
100 | 100 | if ( $page == 'wpinv-subscriptions' ) { |
101 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
102 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
103 | - } |
|
101 | + wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
102 | + wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
103 | + } |
|
104 | 104 | |
105 | - if ( $page == 'wpinv-reports' ) { |
|
106 | - wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
107 | - } |
|
105 | + if ( $page == 'wpinv-reports' ) { |
|
106 | + wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
107 | + } |
|
108 | 108 | |
109 | - if ( $page == 'wpinv-subscriptions' ) { |
|
110 | - wp_enqueue_script( 'postbox' ); |
|
111 | - } |
|
109 | + if ( $page == 'wpinv-subscriptions' ) { |
|
110 | + wp_enqueue_script( 'postbox' ); |
|
111 | + } |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
116 | - * Returns admin js translations. |
|
117 | - * |
|
118 | - */ |
|
119 | - protected function get_admin_i18() { |
|
116 | + * Returns admin js translations. |
|
117 | + * |
|
118 | + */ |
|
119 | + protected function get_admin_i18() { |
|
120 | 120 | global $post; |
121 | 121 | |
122 | 122 | return array( |
@@ -157,32 +157,32 @@ discard block |
||
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
160 | - * Loads payment form js. |
|
161 | - * |
|
162 | - */ |
|
163 | - protected function load_payment_form_scripts() { |
|
160 | + * Loads payment form js. |
|
161 | + * |
|
162 | + */ |
|
163 | + protected function load_payment_form_scripts() { |
|
164 | 164 | global $post; |
165 | 165 | |
166 | 166 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
167 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
168 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
167 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
168 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
169 | 169 | |
170 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
171 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
170 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
171 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
172 | 172 | |
173 | - wp_localize_script( |
|
173 | + wp_localize_script( |
|
174 | 174 | 'wpinv-admin-payment-form-script', |
175 | 175 | 'wpinvPaymentFormAdmin', |
176 | 176 | array( |
177 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
178 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
179 | - 'currency' => wpinv_currency_symbol(), |
|
180 | - 'position' => wpinv_currency_position(), |
|
181 | - 'decimals' => (int) wpinv_decimals(), |
|
182 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
183 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
184 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
185 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
177 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
178 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
179 | + 'currency' => wpinv_currency_symbol(), |
|
180 | + 'position' => wpinv_currency_position(), |
|
181 | + 'decimals' => (int) wpinv_decimals(), |
|
182 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
183 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
184 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
185 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
186 | 186 | ) |
187 | 187 | ); |
188 | 188 | |
@@ -191,20 +191,20 @@ discard block |
||
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
194 | - * Add our classes to admin pages. |
|
194 | + * Add our classes to admin pages. |
|
195 | 195 | * |
196 | 196 | * @param string $classes |
197 | 197 | * @return string |
198 | - * |
|
199 | - */ |
|
198 | + * |
|
199 | + */ |
|
200 | 200 | public function admin_body_class( $classes ) { |
201 | - global $pagenow, $post, $current_screen; |
|
201 | + global $pagenow, $post, $current_screen; |
|
202 | 202 | |
203 | 203 | |
204 | 204 | $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
205 | 205 | |
206 | 206 | if ( ! empty( $current_screen->post_type ) ) { |
207 | - $page = $current_screen->post_type; |
|
207 | + $page = $current_screen->post_type; |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -215,27 +215,27 @@ discard block |
||
215 | 215 | $classes .= ' wpinv-cpt wpinv'; |
216 | 216 | } |
217 | 217 | |
218 | - if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) { |
|
219 | - $classes .= ' wpi-editable-n'; |
|
220 | - } |
|
218 | + if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) { |
|
219 | + $classes .= ' wpi-editable-n'; |
|
220 | + } |
|
221 | 221 | |
222 | - return $classes; |
|
222 | + return $classes; |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
226 | - * Maybe show the AyeCode Connect Notice. |
|
227 | - */ |
|
228 | - public function init_ayecode_connect_helper(){ |
|
226 | + * Maybe show the AyeCode Connect Notice. |
|
227 | + */ |
|
228 | + public function init_ayecode_connect_helper(){ |
|
229 | 229 | |
230 | 230 | new AyeCode_Connect_Helper( |
231 | 231 | array( |
232 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
233 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
234 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
235 | - 'connect_button' => __("Connect Site","invoicing"), |
|
236 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
237 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
238 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
232 | + 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
233 | + 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
234 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
235 | + 'connect_button' => __("Connect Site","invoicing"), |
|
236 | + 'connecting_button' => __("Connecting...","invoicing"), |
|
237 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
238 | + 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
239 | 239 | ), |
240 | 240 | array( 'wpi-addons' ) |
241 | 241 | ); |
@@ -247,21 +247,21 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public function activation_redirect() { |
249 | 249 | |
250 | - // Bail if no activation redirect. |
|
251 | - if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
252 | - return; |
|
253 | - } |
|
250 | + // Bail if no activation redirect. |
|
251 | + if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
252 | + return; |
|
253 | + } |
|
254 | 254 | |
255 | - // Delete the redirect transient. |
|
256 | - delete_transient( '_wpinv_activation_redirect' ); |
|
255 | + // Delete the redirect transient. |
|
256 | + delete_transient( '_wpinv_activation_redirect' ); |
|
257 | 257 | |
258 | - // Bail if activating from network, or bulk |
|
259 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
260 | - return; |
|
261 | - } |
|
258 | + // Bail if activating from network, or bulk |
|
259 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
260 | + return; |
|
261 | + } |
|
262 | 262 | |
263 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
264 | - exit; |
|
263 | + wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
264 | + exit; |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
@@ -276,150 +276,150 @@ discard block |
||
276 | 276 | |
277 | 277 | } |
278 | 278 | |
279 | - /** |
|
279 | + /** |
|
280 | 280 | * Sends a payment reminder to a customer. |
281 | - * |
|
282 | - * @param array $args |
|
281 | + * |
|
282 | + * @param array $args |
|
283 | 283 | */ |
284 | 284 | public function send_customer_invoice( $args ) { |
285 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
285 | + $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
286 | 286 | |
287 | - if ( $sent ) { |
|
288 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
289 | - } else { |
|
290 | - $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
291 | - } |
|
287 | + if ( $sent ) { |
|
288 | + $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
289 | + } else { |
|
290 | + $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
291 | + } |
|
292 | 292 | |
293 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
294 | - exit; |
|
295 | - } |
|
293 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
294 | + exit; |
|
295 | + } |
|
296 | 296 | |
297 | - /** |
|
297 | + /** |
|
298 | 298 | * Sends a payment reminder to a customer. |
299 | - * |
|
300 | - * @param array $args |
|
299 | + * |
|
300 | + * @param array $args |
|
301 | 301 | */ |
302 | 302 | public function send_customer_payment_reminder( $args ) { |
303 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
303 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
304 | 304 | |
305 | - if ( $sent ) { |
|
306 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
307 | - } else { |
|
308 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
309 | - } |
|
305 | + if ( $sent ) { |
|
306 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
307 | + } else { |
|
308 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
309 | + } |
|
310 | 310 | |
311 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
312 | - exit; |
|
313 | - } |
|
311 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
312 | + exit; |
|
313 | + } |
|
314 | 314 | |
315 | 315 | /** |
316 | - * Returns an array of admin notices. |
|
317 | - * |
|
318 | - * @since 1.0.19 |
|
316 | + * Returns an array of admin notices. |
|
317 | + * |
|
318 | + * @since 1.0.19 |
|
319 | 319 | * @return array |
320 | - */ |
|
321 | - public function get_notices() { |
|
322 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
320 | + */ |
|
321 | + public function get_notices() { |
|
322 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
323 | 323 | return is_array( $notices ) ? $notices : array(); |
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Clears all admin notices |
|
328 | - * |
|
329 | - * @access public |
|
330 | - * @since 1.0.19 |
|
331 | - */ |
|
332 | - public function clear_notices() { |
|
333 | - delete_option( 'wpinv_admin_notices' ); |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * Saves a new admin notice |
|
338 | - * |
|
339 | - * @access public |
|
340 | - * @since 1.0.19 |
|
341 | - */ |
|
342 | - public function save_notice( $type, $message ) { |
|
343 | - $notices = $this->get_notices(); |
|
344 | - |
|
345 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
346 | - $notices[ $type ] = array(); |
|
347 | - } |
|
348 | - |
|
349 | - $notices[ $type ][] = $message; |
|
350 | - |
|
351 | - update_option( 'wpinv_admin_notices', $notices ); |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Displays a success notice |
|
356 | - * |
|
357 | - * @param string $msg The message to qeue. |
|
358 | - * @access public |
|
359 | - * @since 1.0.19 |
|
360 | - */ |
|
361 | - public function show_success( $msg ) { |
|
362 | - $this->save_notice( 'success', $msg ); |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Displays a error notice |
|
367 | - * |
|
368 | - * @access public |
|
369 | - * @param string $msg The message to qeue. |
|
370 | - * @since 1.0.19 |
|
371 | - */ |
|
372 | - public function show_error( $msg ) { |
|
373 | - $this->save_notice( 'error', $msg ); |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * Displays a warning notice |
|
378 | - * |
|
379 | - * @access public |
|
380 | - * @param string $msg The message to qeue. |
|
381 | - * @since 1.0.19 |
|
382 | - */ |
|
383 | - public function show_warning( $msg ) { |
|
384 | - $this->save_notice( 'warning', $msg ); |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * Displays a info notice |
|
389 | - * |
|
390 | - * @access public |
|
391 | - * @param string $msg The message to qeue. |
|
392 | - * @since 1.0.19 |
|
393 | - */ |
|
394 | - public function show_info( $msg ) { |
|
395 | - $this->save_notice( 'info', $msg ); |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * Show notices |
|
400 | - * |
|
401 | - * @access public |
|
402 | - * @since 1.0.19 |
|
403 | - */ |
|
404 | - public function show_notices() { |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Clears all admin notices |
|
328 | + * |
|
329 | + * @access public |
|
330 | + * @since 1.0.19 |
|
331 | + */ |
|
332 | + public function clear_notices() { |
|
333 | + delete_option( 'wpinv_admin_notices' ); |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * Saves a new admin notice |
|
338 | + * |
|
339 | + * @access public |
|
340 | + * @since 1.0.19 |
|
341 | + */ |
|
342 | + public function save_notice( $type, $message ) { |
|
343 | + $notices = $this->get_notices(); |
|
344 | + |
|
345 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
346 | + $notices[ $type ] = array(); |
|
347 | + } |
|
348 | + |
|
349 | + $notices[ $type ][] = $message; |
|
350 | + |
|
351 | + update_option( 'wpinv_admin_notices', $notices ); |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Displays a success notice |
|
356 | + * |
|
357 | + * @param string $msg The message to qeue. |
|
358 | + * @access public |
|
359 | + * @since 1.0.19 |
|
360 | + */ |
|
361 | + public function show_success( $msg ) { |
|
362 | + $this->save_notice( 'success', $msg ); |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Displays a error notice |
|
367 | + * |
|
368 | + * @access public |
|
369 | + * @param string $msg The message to qeue. |
|
370 | + * @since 1.0.19 |
|
371 | + */ |
|
372 | + public function show_error( $msg ) { |
|
373 | + $this->save_notice( 'error', $msg ); |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * Displays a warning notice |
|
378 | + * |
|
379 | + * @access public |
|
380 | + * @param string $msg The message to qeue. |
|
381 | + * @since 1.0.19 |
|
382 | + */ |
|
383 | + public function show_warning( $msg ) { |
|
384 | + $this->save_notice( 'warning', $msg ); |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * Displays a info notice |
|
389 | + * |
|
390 | + * @access public |
|
391 | + * @param string $msg The message to qeue. |
|
392 | + * @since 1.0.19 |
|
393 | + */ |
|
394 | + public function show_info( $msg ) { |
|
395 | + $this->save_notice( 'info', $msg ); |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Show notices |
|
400 | + * |
|
401 | + * @access public |
|
402 | + * @since 1.0.19 |
|
403 | + */ |
|
404 | + public function show_notices() { |
|
405 | 405 | |
406 | 406 | $notices = $this->get_notices(); |
407 | 407 | $this->clear_notices(); |
408 | 408 | |
409 | - foreach ( $notices as $type => $messages ) { |
|
409 | + foreach ( $notices as $type => $messages ) { |
|
410 | 410 | |
411 | - if ( ! is_array( $messages ) ) { |
|
412 | - continue; |
|
413 | - } |
|
411 | + if ( ! is_array( $messages ) ) { |
|
412 | + continue; |
|
413 | + } |
|
414 | 414 | |
415 | 415 | $type = sanitize_key( $type ); |
416 | - foreach ( $messages as $message ) { |
|
416 | + foreach ( $messages as $message ) { |
|
417 | 417 | $message = wp_kses_post( $message ); |
418 | - echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
418 | + echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | } |
422 | 422 | |
423 | - } |
|
423 | + } |
|
424 | 424 | |
425 | 425 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * The main admin class. |
@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * Class constructor. |
32 | 32 | */ |
33 | - public function __construct(){ |
|
33 | + public function __construct() { |
|
34 | 34 | |
35 | - $this->admin_path = plugin_dir_path( __FILE__ ); |
|
36 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
35 | + $this->admin_path = plugin_dir_path(__FILE__); |
|
36 | + $this->admin_url = plugins_url('/', __FILE__); |
|
37 | 37 | |
38 | - if ( is_admin() ) { |
|
38 | + if (is_admin()) { |
|
39 | 39 | $this->init_admin_hooks(); |
40 | 40 | } |
41 | 41 | |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | * |
47 | 47 | */ |
48 | 48 | private function init_admin_hooks() { |
49 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
|
50 | - add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
|
51 | - add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
|
52 | - add_action( 'admin_init', array( $this, 'activation_redirect') ); |
|
53 | - add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
|
54 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
55 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
56 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
57 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
49 | + add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts')); |
|
50 | + add_filter('admin_body_class', array($this, 'admin_body_class')); |
|
51 | + add_action('admin_init', array($this, 'init_ayecode_connect_helper')); |
|
52 | + add_action('admin_init', array($this, 'activation_redirect')); |
|
53 | + add_action('admin_init', array($this, 'maybe_do_admin_action')); |
|
54 | + add_action('admin_notices', array($this, 'show_notices')); |
|
55 | + add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice')); |
|
56 | + add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder')); |
|
57 | + do_action('getpaid_init_admin_hooks', $this); |
|
58 | 58 | |
59 | 59 | } |
60 | 60 | |
@@ -65,49 +65,49 @@ discard block |
||
65 | 65 | public function enqeue_scripts() { |
66 | 66 | global $current_screen, $pagenow; |
67 | 67 | |
68 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
68 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
69 | 69 | $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
70 | 70 | |
71 | - if ( ! empty( $current_screen->post_type ) ) { |
|
71 | + if (!empty($current_screen->post_type)) { |
|
72 | 72 | $page = $current_screen->post_type; |
73 | 73 | } |
74 | 74 | |
75 | 75 | // General styles. |
76 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
76 | + if (false !== stripos($page, 'wpi')) { |
|
77 | 77 | |
78 | 78 | // Styles. |
79 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
80 | - wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version ); |
|
81 | - wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' ); |
|
82 | - wp_enqueue_style( 'wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
83 | - wp_enqueue_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16' ); |
|
79 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css'); |
|
80 | + wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version); |
|
81 | + wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all'); |
|
82 | + wp_enqueue_style('wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
83 | + wp_enqueue_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16'); |
|
84 | 84 | |
85 | 85 | // Scripts. |
86 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '4.0.13', true ); |
|
87 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION ); |
|
86 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '4.0.13', true); |
|
87 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION); |
|
88 | 88 | |
89 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
90 | - wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker' ), $version ); |
|
91 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) ); |
|
89 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js'); |
|
90 | + wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker'), $version); |
|
91 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18())); |
|
92 | 92 | |
93 | 93 | } |
94 | 94 | |
95 | 95 | // Payment form scripts. |
96 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
96 | + if ('wpi_payment_form' == $page && $editing) { |
|
97 | 97 | $this->load_payment_form_scripts(); |
98 | 98 | } |
99 | 99 | |
100 | - if ( $page == 'wpinv-subscriptions' ) { |
|
101 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
102 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
100 | + if ($page == 'wpinv-subscriptions') { |
|
101 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
102 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
103 | 103 | } |
104 | 104 | |
105 | - if ( $page == 'wpinv-reports' ) { |
|
106 | - wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
105 | + if ($page == 'wpinv-reports') { |
|
106 | + wp_enqueue_script('jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array('jquery'), '0.7'); |
|
107 | 107 | } |
108 | 108 | |
109 | - if ( $page == 'wpinv-subscriptions' ) { |
|
110 | - wp_enqueue_script( 'postbox' ); |
|
109 | + if ($page == 'wpinv-subscriptions') { |
|
110 | + wp_enqueue_script('postbox'); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | } |
@@ -120,13 +120,13 @@ discard block |
||
120 | 120 | global $post; |
121 | 121 | |
122 | 122 | return array( |
123 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
124 | - 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
|
125 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
126 | - 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
|
127 | - 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
|
128 | - 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
|
129 | - 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
|
123 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
124 | + 'post_ID' => isset($post->ID) ? $post->ID : '', |
|
125 | + 'wpinv_nonce' => wp_create_nonce('wpinv-nonce'), |
|
126 | + 'add_invoice_note_nonce' => wp_create_nonce('add-invoice-note'), |
|
127 | + 'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'), |
|
128 | + 'invoice_item_nonce' => wp_create_nonce('invoice-item'), |
|
129 | + 'billing_details_nonce' => wp_create_nonce('get-billing-details'), |
|
130 | 130 | 'tax' => wpinv_tax_amount(), |
131 | 131 | 'discount' => wpinv_discount_amount(), |
132 | 132 | 'currency_symbol' => wpinv_currency_symbol(), |
@@ -134,24 +134,24 @@ discard block |
||
134 | 134 | 'thousand_sep' => wpinv_thousands_separator(), |
135 | 135 | 'decimal_sep' => wpinv_decimal_separator(), |
136 | 136 | 'decimals' => wpinv_decimals(), |
137 | - 'save_invoice' => __( 'Save Invoice', 'invoicing' ), |
|
138 | - 'status_publish' => wpinv_status_nicename( 'publish' ), |
|
139 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
140 | - 'delete_tax_rate' => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ), |
|
141 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
142 | - 'OneItemMin' => __( 'Invoice must contain at least one item', 'invoicing' ), |
|
143 | - 'FillBillingDetails' => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ), |
|
144 | - 'confirmCalcTotals' => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ), |
|
145 | - 'AreYouSure' => __( 'Are you sure?', 'invoicing' ), |
|
146 | - 'emptyInvoice' => __( 'Add at least one item to save invoice!', 'invoicing' ), |
|
147 | - 'errDeleteItem' => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ), |
|
148 | - 'delete_subscription' => __( 'Are you sure you want to delete this subscription?', 'invoicing' ), |
|
149 | - 'action_edit' => __( 'Edit', 'invoicing' ), |
|
150 | - 'action_cancel' => __( 'Cancel', 'invoicing' ), |
|
151 | - 'item_description' => __( 'Item Description', 'invoicing' ), |
|
152 | - 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
|
153 | - 'discount_description' => __( 'Discount Description', 'invoicing' ), |
|
154 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
137 | + 'save_invoice' => __('Save Invoice', 'invoicing'), |
|
138 | + 'status_publish' => wpinv_status_nicename('publish'), |
|
139 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
140 | + 'delete_tax_rate' => __('Are you sure you wish to delete this tax rate?', 'invoicing'), |
|
141 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
142 | + 'OneItemMin' => __('Invoice must contain at least one item', 'invoicing'), |
|
143 | + 'FillBillingDetails' => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'), |
|
144 | + 'confirmCalcTotals' => __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'), |
|
145 | + 'AreYouSure' => __('Are you sure?', 'invoicing'), |
|
146 | + 'emptyInvoice' => __('Add at least one item to save invoice!', 'invoicing'), |
|
147 | + 'errDeleteItem' => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'), |
|
148 | + 'delete_subscription' => __('Are you sure you want to delete this subscription?', 'invoicing'), |
|
149 | + 'action_edit' => __('Edit', 'invoicing'), |
|
150 | + 'action_cancel' => __('Cancel', 'invoicing'), |
|
151 | + 'item_description' => __('Item Description', 'invoicing'), |
|
152 | + 'invoice_description' => __('Invoice Description', 'invoicing'), |
|
153 | + 'discount_description' => __('Discount Description', 'invoicing'), |
|
154 | + 'searching' => __('Searching', 'invoicing'), |
|
155 | 155 | ); |
156 | 156 | |
157 | 157 | } |
@@ -163,30 +163,30 @@ discard block |
||
163 | 163 | protected function load_payment_form_scripts() { |
164 | 164 | global $post; |
165 | 165 | |
166 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
|
167 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
168 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
166 | + wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION); |
|
167 | + wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION); |
|
168 | + wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION); |
|
169 | 169 | |
170 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
171 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
170 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js'); |
|
171 | + wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version); |
|
172 | 172 | |
173 | 173 | wp_localize_script( |
174 | 174 | 'wpinv-admin-payment-form-script', |
175 | 175 | 'wpinvPaymentFormAdmin', |
176 | 176 | array( |
177 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
178 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
177 | + 'elements' => wpinv_get_data('payment-form-elements'), |
|
178 | + 'form_elements' => getpaid_get_payment_form_elements($post->ID), |
|
179 | 179 | 'currency' => wpinv_currency_symbol(), |
180 | 180 | 'position' => wpinv_currency_position(), |
181 | 181 | 'decimals' => (int) wpinv_decimals(), |
182 | 182 | 'thousands_sep' => wpinv_thousands_separator(), |
183 | 183 | 'decimals_sep' => wpinv_decimal_separator(), |
184 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
184 | + 'form_items' => gepaid_get_form_items($post->ID), |
|
185 | 185 | 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
186 | 186 | ) |
187 | 187 | ); |
188 | 188 | |
189 | - wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
189 | + wp_enqueue_script('wpinv-admin-payment-form-script'); |
|
190 | 190 | |
191 | 191 | } |
192 | 192 | |
@@ -197,25 +197,25 @@ discard block |
||
197 | 197 | * @return string |
198 | 198 | * |
199 | 199 | */ |
200 | - public function admin_body_class( $classes ) { |
|
200 | + public function admin_body_class($classes) { |
|
201 | 201 | global $pagenow, $post, $current_screen; |
202 | 202 | |
203 | 203 | |
204 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
204 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
205 | 205 | |
206 | - if ( ! empty( $current_screen->post_type ) ) { |
|
206 | + if (!empty($current_screen->post_type)) { |
|
207 | 207 | $page = $current_screen->post_type; |
208 | 208 | } |
209 | 209 | |
210 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
211 | - $classes .= ' wpi-' . sanitize_key( $page ); |
|
210 | + if (false !== stripos($page, 'wpi')) { |
|
211 | + $classes .= ' wpi-' . sanitize_key($page); |
|
212 | 212 | } |
213 | 213 | |
214 | - if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
|
214 | + if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) { |
|
215 | 215 | $classes .= ' wpinv-cpt wpinv'; |
216 | 216 | } |
217 | 217 | |
218 | - if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) { |
|
218 | + if ($pagenow == 'post.php' && $page == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
219 | 219 | $classes .= ' wpi-editable-n'; |
220 | 220 | } |
221 | 221 | |
@@ -225,19 +225,19 @@ discard block |
||
225 | 225 | /** |
226 | 226 | * Maybe show the AyeCode Connect Notice. |
227 | 227 | */ |
228 | - public function init_ayecode_connect_helper(){ |
|
228 | + public function init_ayecode_connect_helper() { |
|
229 | 229 | |
230 | 230 | new AyeCode_Connect_Helper( |
231 | 231 | array( |
232 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
233 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
234 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
235 | - 'connect_button' => __("Connect Site","invoicing"), |
|
236 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
237 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
238 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
232 | + 'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"), |
|
233 | + 'connect_external' => __("Please confirm you wish to connect your site?", "invoicing"), |
|
234 | + 'connect' => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"), |
|
235 | + 'connect_button' => __("Connect Site", "invoicing"), |
|
236 | + 'connecting_button' => __("Connecting...", "invoicing"), |
|
237 | + 'error_localhost' => __("This service will only work with a live domain, not a localhost.", "invoicing"), |
|
238 | + 'error' => __("Something went wrong, please refresh and try again.", "invoicing"), |
|
239 | 239 | ), |
240 | - array( 'wpi-addons' ) |
|
240 | + array('wpi-addons') |
|
241 | 241 | ); |
242 | 242 | |
243 | 243 | } |
@@ -248,19 +248,19 @@ discard block |
||
248 | 248 | public function activation_redirect() { |
249 | 249 | |
250 | 250 | // Bail if no activation redirect. |
251 | - if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
251 | + if (!get_transient('_wpinv_activation_redirect') || wp_doing_ajax()) { |
|
252 | 252 | return; |
253 | 253 | } |
254 | 254 | |
255 | 255 | // Delete the redirect transient. |
256 | - delete_transient( '_wpinv_activation_redirect' ); |
|
256 | + delete_transient('_wpinv_activation_redirect'); |
|
257 | 257 | |
258 | 258 | // Bail if activating from network, or bulk |
259 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
259 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
260 | 260 | return; |
261 | 261 | } |
262 | 262 | |
263 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
263 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
264 | 264 | exit; |
265 | 265 | } |
266 | 266 | |
@@ -269,9 +269,9 @@ discard block |
||
269 | 269 | */ |
270 | 270 | public function maybe_do_admin_action() { |
271 | 271 | |
272 | - if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
273 | - $key = sanitize_key( $_REQUEST['getpaid-admin-action'] ); |
|
274 | - do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST ); |
|
272 | + if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
273 | + $key = sanitize_key($_REQUEST['getpaid-admin-action']); |
|
274 | + do_action("getpaid_authenticated_admin_action_$key", $_REQUEST); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | } |
@@ -281,16 +281,16 @@ discard block |
||
281 | 281 | * |
282 | 282 | * @param array $args |
283 | 283 | */ |
284 | - public function send_customer_invoice( $args ) { |
|
285 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
284 | + public function send_customer_invoice($args) { |
|
285 | + $sent = getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id'])); |
|
286 | 286 | |
287 | - if ( $sent ) { |
|
288 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
287 | + if ($sent) { |
|
288 | + $this->show_success(__('Invoice was successfully sent to the customer', 'invoicing')); |
|
289 | 289 | } else { |
290 | - $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
290 | + $this->show_error(__('Could not sent the invoice to the customer', 'invoicing')); |
|
291 | 291 | } |
292 | 292 | |
293 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
293 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
294 | 294 | exit; |
295 | 295 | } |
296 | 296 | |
@@ -299,16 +299,16 @@ discard block |
||
299 | 299 | * |
300 | 300 | * @param array $args |
301 | 301 | */ |
302 | - public function send_customer_payment_reminder( $args ) { |
|
303 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
302 | + public function send_customer_payment_reminder($args) { |
|
303 | + $sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id'])); |
|
304 | 304 | |
305 | - if ( $sent ) { |
|
306 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
305 | + if ($sent) { |
|
306 | + $this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing')); |
|
307 | 307 | } else { |
308 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
308 | + $this->show_error(__('Could not sent payment reminder to the customer', 'invoicing')); |
|
309 | 309 | } |
310 | 310 | |
311 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
311 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
312 | 312 | exit; |
313 | 313 | } |
314 | 314 | |
@@ -319,8 +319,8 @@ discard block |
||
319 | 319 | * @return array |
320 | 320 | */ |
321 | 321 | public function get_notices() { |
322 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
323 | - return is_array( $notices ) ? $notices : array(); |
|
322 | + $notices = get_option('wpinv_admin_notices'); |
|
323 | + return is_array($notices) ? $notices : array(); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | * @since 1.0.19 |
331 | 331 | */ |
332 | 332 | public function clear_notices() { |
333 | - delete_option( 'wpinv_admin_notices' ); |
|
333 | + delete_option('wpinv_admin_notices'); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -339,16 +339,16 @@ discard block |
||
339 | 339 | * @access public |
340 | 340 | * @since 1.0.19 |
341 | 341 | */ |
342 | - public function save_notice( $type, $message ) { |
|
342 | + public function save_notice($type, $message) { |
|
343 | 343 | $notices = $this->get_notices(); |
344 | 344 | |
345 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
346 | - $notices[ $type ] = array(); |
|
345 | + if (empty($notices[$type]) || !is_array($notices[$type])) { |
|
346 | + $notices[$type] = array(); |
|
347 | 347 | } |
348 | 348 | |
349 | - $notices[ $type ][] = $message; |
|
349 | + $notices[$type][] = $message; |
|
350 | 350 | |
351 | - update_option( 'wpinv_admin_notices', $notices ); |
|
351 | + update_option('wpinv_admin_notices', $notices); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
@@ -358,8 +358,8 @@ discard block |
||
358 | 358 | * @access public |
359 | 359 | * @since 1.0.19 |
360 | 360 | */ |
361 | - public function show_success( $msg ) { |
|
362 | - $this->save_notice( 'success', $msg ); |
|
361 | + public function show_success($msg) { |
|
362 | + $this->save_notice('success', $msg); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -369,8 +369,8 @@ discard block |
||
369 | 369 | * @param string $msg The message to qeue. |
370 | 370 | * @since 1.0.19 |
371 | 371 | */ |
372 | - public function show_error( $msg ) { |
|
373 | - $this->save_notice( 'error', $msg ); |
|
372 | + public function show_error($msg) { |
|
373 | + $this->save_notice('error', $msg); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | /** |
@@ -380,8 +380,8 @@ discard block |
||
380 | 380 | * @param string $msg The message to qeue. |
381 | 381 | * @since 1.0.19 |
382 | 382 | */ |
383 | - public function show_warning( $msg ) { |
|
384 | - $this->save_notice( 'warning', $msg ); |
|
383 | + public function show_warning($msg) { |
|
384 | + $this->save_notice('warning', $msg); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
@@ -391,8 +391,8 @@ discard block |
||
391 | 391 | * @param string $msg The message to qeue. |
392 | 392 | * @since 1.0.19 |
393 | 393 | */ |
394 | - public function show_info( $msg ) { |
|
395 | - $this->save_notice( 'info', $msg ); |
|
394 | + public function show_info($msg) { |
|
395 | + $this->save_notice('info', $msg); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
@@ -406,15 +406,15 @@ discard block |
||
406 | 406 | $notices = $this->get_notices(); |
407 | 407 | $this->clear_notices(); |
408 | 408 | |
409 | - foreach ( $notices as $type => $messages ) { |
|
409 | + foreach ($notices as $type => $messages) { |
|
410 | 410 | |
411 | - if ( ! is_array( $messages ) ) { |
|
411 | + if (!is_array($messages)) { |
|
412 | 412 | continue; |
413 | 413 | } |
414 | 414 | |
415 | - $type = sanitize_key( $type ); |
|
416 | - foreach ( $messages as $message ) { |
|
417 | - $message = wp_kses_post( $message ); |
|
415 | + $type = sanitize_key($type); |
|
416 | + foreach ($messages as $message) { |
|
417 | + $message = wp_kses_post($message); |
|
418 | 418 | echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
419 | 419 | } |
420 | 420 |
@@ -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 ) |
@@ -260,24 +260,24 @@ discard block |
||
260 | 260 | } |
261 | 261 | |
262 | 262 | // Is the request set up correctly? |
263 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
264 | - echo aui()->alert( |
|
265 | - array( |
|
266 | - 'type' => 'warning', |
|
267 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
268 | - ) |
|
263 | + if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
264 | + echo aui()->alert( |
|
265 | + array( |
|
266 | + 'type' => 'warning', |
|
267 | + 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
268 | + ) |
|
269 | 269 | ); |
270 | 270 | exit; |
271 | 271 | } |
272 | 272 | |
273 | 273 | // Payment form or button? |
274 | - if ( ! empty( $_GET['form'] ) ) { |
|
274 | + if ( ! empty( $_GET['form'] ) ) { |
|
275 | 275 | getpaid_display_payment_form( $_GET['form'] ); |
276 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
277 | - getpaid_display_invoice_payment_form( $_GET['invoice'] ); |
|
276 | + } else if( ! empty( $_GET['invoice'] ) ) { |
|
277 | + getpaid_display_invoice_payment_form( $_GET['invoice'] ); |
|
278 | 278 | } else { |
279 | - $items = getpaid_convert_items_to_array( $_GET['item'] ); |
|
280 | - getpaid_display_item_payment_form( $items ); |
|
279 | + $items = getpaid_convert_items_to_array( $_GET['item'] ); |
|
280 | + getpaid_display_item_payment_form( $items ); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | 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 | |
@@ -102,36 +102,36 @@ discard block |
||
102 | 102 | 'ip_geolocation' => true, |
103 | 103 | ); |
104 | 104 | |
105 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
106 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
107 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
105 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
106 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
107 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
108 | 108 | |
109 | - if ( $nopriv ) { |
|
110 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
111 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
112 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
109 | + if ($nopriv) { |
|
110 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
111 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
112 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
117 | 117 | public static function add_note() { |
118 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
118 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
119 | 119 | |
120 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
120 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
121 | 121 | die(-1); |
122 | 122 | } |
123 | 123 | |
124 | - $post_id = absint( $_POST['post_id'] ); |
|
125 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
126 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
124 | + $post_id = absint($_POST['post_id']); |
|
125 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
126 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
127 | 127 | |
128 | 128 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
129 | 129 | |
130 | - if ( $post_id > 0 ) { |
|
131 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
130 | + if ($post_id > 0) { |
|
131 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
132 | 132 | |
133 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
134 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
133 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
134 | + wpinv_get_invoice_note_line_item($note_id); |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
@@ -139,16 +139,16 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | public static function delete_note() { |
142 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
142 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
143 | 143 | |
144 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
144 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
145 | 145 | die(-1); |
146 | 146 | } |
147 | 147 | |
148 | - $note_id = (int)$_POST['note_id']; |
|
148 | + $note_id = (int) $_POST['note_id']; |
|
149 | 149 | |
150 | - if ( $note_id > 0 ) { |
|
151 | - wp_delete_comment( $note_id, true ); |
|
150 | + if ($note_id > 0) { |
|
151 | + wp_delete_comment($note_id, true); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | die(); |
@@ -166,34 +166,34 @@ discard block |
||
166 | 166 | public static function get_billing_details() { |
167 | 167 | |
168 | 168 | // Verify nonce. |
169 | - check_ajax_referer( 'wpinv-nonce' ); |
|
169 | + check_ajax_referer('wpinv-nonce'); |
|
170 | 170 | |
171 | 171 | // Can the user manage the plugin? |
172 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
172 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
173 | 173 | die(-1); |
174 | 174 | } |
175 | 175 | |
176 | 176 | // Do we have a user id? |
177 | 177 | $user_id = $_GET['user_id']; |
178 | 178 | |
179 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
179 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
180 | 180 | die(-1); |
181 | 181 | } |
182 | 182 | |
183 | 183 | // Fetch the billing details. |
184 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
185 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
184 | + $billing_details = wpinv_get_user_address($user_id); |
|
185 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
186 | 186 | |
187 | 187 | // unset the user id and email. |
188 | - $to_ignore = array( 'user_id', 'email' ); |
|
188 | + $to_ignore = array('user_id', 'email'); |
|
189 | 189 | |
190 | - foreach ( $to_ignore as $key ) { |
|
191 | - if ( isset( $billing_details[ $key ] ) ) { |
|
192 | - unset( $billing_details[ $key ] ); |
|
190 | + foreach ($to_ignore as $key) { |
|
191 | + if (isset($billing_details[$key])) { |
|
192 | + unset($billing_details[$key]); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
196 | - wp_send_json_success( $billing_details ); |
|
196 | + wp_send_json_success($billing_details); |
|
197 | 197 | |
198 | 198 | } |
199 | 199 | |
@@ -203,47 +203,47 @@ discard block |
||
203 | 203 | public static function check_new_user_email() { |
204 | 204 | |
205 | 205 | // Verify nonce. |
206 | - check_ajax_referer( 'wpinv-nonce' ); |
|
206 | + check_ajax_referer('wpinv-nonce'); |
|
207 | 207 | |
208 | 208 | // Can the user manage the plugin? |
209 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
209 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
210 | 210 | die(-1); |
211 | 211 | } |
212 | 212 | |
213 | 213 | // We need an email address. |
214 | - if ( empty( $_GET['email'] ) ) { |
|
215 | - _e( "Provide the new user's email address", 'invoicing' ); |
|
214 | + if (empty($_GET['email'])) { |
|
215 | + _e("Provide the new user's email address", 'invoicing'); |
|
216 | 216 | exit; |
217 | 217 | } |
218 | 218 | |
219 | 219 | // Ensure the email is valid. |
220 | - $email = sanitize_text_field( $_GET['email'] ); |
|
221 | - if ( ! is_email( $email ) ) { |
|
222 | - _e( 'Invalid email address', 'invoicing' ); |
|
220 | + $email = sanitize_text_field($_GET['email']); |
|
221 | + if (!is_email($email)) { |
|
222 | + _e('Invalid email address', 'invoicing'); |
|
223 | 223 | exit; |
224 | 224 | } |
225 | 225 | |
226 | 226 | // And it does not exist. |
227 | - if ( email_exists( $email ) ) { |
|
228 | - _e( 'A user with this email address already exists', 'invoicing' ); |
|
227 | + if (email_exists($email)) { |
|
228 | + _e('A user with this email address already exists', 'invoicing'); |
|
229 | 229 | exit; |
230 | 230 | } |
231 | 231 | |
232 | - wp_send_json_success( true ); |
|
232 | + wp_send_json_success(true); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | public static function run_tool() { |
236 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
237 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
236 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
237 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
238 | 238 | die(-1); |
239 | 239 | } |
240 | 240 | |
241 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
241 | + $tool = sanitize_text_field($_POST['tool']); |
|
242 | 242 | |
243 | - do_action( 'wpinv_run_tool' ); |
|
243 | + do_action('wpinv_run_tool'); |
|
244 | 244 | |
245 | - if ( !empty( $tool ) ) { |
|
246 | - do_action( 'wpinv_tool_' . $tool ); |
|
245 | + if (!empty($tool)) { |
|
246 | + do_action('wpinv_tool_' . $tool); |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | |
@@ -253,30 +253,30 @@ discard block |
||
253 | 253 | public static function get_payment_form() { |
254 | 254 | |
255 | 255 | // Check nonce. |
256 | - if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'getpaid_ajax_form' ) ) { |
|
257 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
256 | + if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], 'getpaid_ajax_form')) { |
|
257 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
258 | 258 | exit; |
259 | 259 | } |
260 | 260 | |
261 | 261 | // Is the request set up correctly? |
262 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
262 | + if (empty($_GET['form']) && empty($_GET['item'])) { |
|
263 | 263 | echo aui()->alert( |
264 | 264 | array( |
265 | 265 | 'type' => 'warning', |
266 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
266 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
267 | 267 | ) |
268 | 268 | ); |
269 | 269 | exit; |
270 | 270 | } |
271 | 271 | |
272 | 272 | // Payment form or button? |
273 | - if ( ! empty( $_GET['form'] ) ) { |
|
274 | - getpaid_display_payment_form( $_GET['form'] ); |
|
275 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
276 | - getpaid_display_invoice_payment_form( $_GET['invoice'] ); |
|
273 | + if (!empty($_GET['form'])) { |
|
274 | + getpaid_display_payment_form($_GET['form']); |
|
275 | + } else if (!empty($_GET['invoice'])) { |
|
276 | + getpaid_display_invoice_payment_form($_GET['invoice']); |
|
277 | 277 | } else { |
278 | - $items = getpaid_convert_items_to_array( $_GET['item'] ); |
|
279 | - getpaid_display_item_payment_form( $items ); |
|
278 | + $items = getpaid_convert_items_to_array($_GET['item']); |
|
279 | + getpaid_display_item_payment_form($items); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | exit; |
@@ -291,17 +291,17 @@ discard block |
||
291 | 291 | public static function payment_form() { |
292 | 292 | |
293 | 293 | // Check nonce. |
294 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
294 | + check_ajax_referer('getpaid_form_nonce'); |
|
295 | 295 | |
296 | 296 | // ... form fields... |
297 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
298 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
297 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
298 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
299 | 299 | exit; |
300 | 300 | } |
301 | 301 | |
302 | 302 | // Process the payment form. |
303 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
304 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
303 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
304 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
305 | 305 | $checkout->process_checkout(); |
306 | 306 | |
307 | 307 | exit; |
@@ -314,51 +314,51 @@ discard block |
||
314 | 314 | */ |
315 | 315 | public static function get_payment_form_states_field() { |
316 | 316 | |
317 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
317 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
318 | 318 | exit; |
319 | 319 | } |
320 | 320 | |
321 | - $elements = getpaid_get_payment_form_elements( $_GET['form'] ); |
|
321 | + $elements = getpaid_get_payment_form_elements($_GET['form']); |
|
322 | 322 | |
323 | - if ( empty( $elements ) ) { |
|
323 | + if (empty($elements)) { |
|
324 | 324 | exit; |
325 | 325 | } |
326 | 326 | |
327 | 327 | $address_fields = array(); |
328 | - foreach ( $elements as $element ) { |
|
329 | - if ( 'address' === $element['type'] ) { |
|
328 | + foreach ($elements as $element) { |
|
329 | + if ('address' === $element['type']) { |
|
330 | 330 | $address_fields = $element; |
331 | 331 | break; |
332 | 332 | } |
333 | 333 | } |
334 | 334 | |
335 | - if ( empty( $address_fields ) ) { |
|
335 | + if (empty($address_fields)) { |
|
336 | 336 | exit; |
337 | 337 | } |
338 | 338 | |
339 | - foreach( $address_fields['fields'] as $address_field ) { |
|
339 | + foreach ($address_fields['fields'] as $address_field) { |
|
340 | 340 | |
341 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
341 | + if ('wpinv_state' == $address_field['name']) { |
|
342 | 342 | |
343 | 343 | $label = $address_field['label']; |
344 | 344 | |
345 | - if ( ! empty( $address_field['required'] ) ) { |
|
345 | + if (!empty($address_field['required'])) { |
|
346 | 346 | $label .= "<span class='text-danger'> *</span>"; |
347 | 347 | } |
348 | 348 | |
349 | - $states = wpinv_get_country_states( $_GET['country'] ); |
|
349 | + $states = wpinv_get_country_states($_GET['country']); |
|
350 | 350 | |
351 | - if ( ! empty( $states ) ) { |
|
351 | + if (!empty($states)) { |
|
352 | 352 | |
353 | 353 | $html = aui()->select( |
354 | 354 | array( |
355 | 355 | 'options' => $states, |
356 | - 'name' => esc_attr( $address_field['name'] ), |
|
357 | - 'id' => esc_attr( $address_field['name'] ), |
|
358 | - 'placeholder' => esc_attr( $address_field['placeholder'] ), |
|
356 | + 'name' => esc_attr($address_field['name']), |
|
357 | + 'id' => esc_attr($address_field['name']), |
|
358 | + 'placeholder' => esc_attr($address_field['placeholder']), |
|
359 | 359 | 'required' => (bool) $address_field['required'], |
360 | 360 | 'no_wrap' => true, |
361 | - 'label' => wp_kses_post( $label ), |
|
361 | + 'label' => wp_kses_post($label), |
|
362 | 362 | 'select2' => false, |
363 | 363 | ) |
364 | 364 | ); |
@@ -367,10 +367,10 @@ discard block |
||
367 | 367 | |
368 | 368 | $html = aui()->input( |
369 | 369 | array( |
370 | - 'name' => esc_attr( $address_field['name'] ), |
|
371 | - 'id' => esc_attr( $address_field['name'] ), |
|
370 | + 'name' => esc_attr($address_field['name']), |
|
371 | + 'id' => esc_attr($address_field['name']), |
|
372 | 372 | 'required' => (bool) $address_field['required'], |
373 | - 'label' => wp_kses_post( $label ), |
|
373 | + 'label' => wp_kses_post($label), |
|
374 | 374 | 'no_wrap' => true, |
375 | 375 | 'type' => 'text', |
376 | 376 | ) |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | |
379 | 379 | } |
380 | 380 | |
381 | - wp_send_json_success( str_replace( 'sr-only', '', $html ) ); |
|
381 | + wp_send_json_success(str_replace('sr-only', '', $html)); |
|
382 | 382 | exit; |
383 | 383 | |
384 | 384 | } |
@@ -394,56 +394,56 @@ discard block |
||
394 | 394 | public static function recalculate_invoice_totals() { |
395 | 395 | |
396 | 396 | // Verify nonce. |
397 | - check_ajax_referer( 'wpinv-nonce' ); |
|
397 | + check_ajax_referer('wpinv-nonce'); |
|
398 | 398 | |
399 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
399 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
400 | 400 | exit; |
401 | 401 | } |
402 | 402 | |
403 | 403 | // We need an invoice. |
404 | - if ( empty( $_POST['post_id'] ) ) { |
|
404 | + if (empty($_POST['post_id'])) { |
|
405 | 405 | exit; |
406 | 406 | } |
407 | 407 | |
408 | 408 | // Fetch the invoice. |
409 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
409 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
410 | 410 | |
411 | 411 | // Ensure it exists. |
412 | - if ( ! $invoice->get_id() ) { |
|
412 | + if (!$invoice->get_id()) { |
|
413 | 413 | exit; |
414 | 414 | } |
415 | 415 | |
416 | 416 | // Maybe set the country, state, currency. |
417 | - foreach ( array( 'country', 'state', 'currency' ) as $key ) { |
|
418 | - if ( isset( $_POST[ $key ] ) ) { |
|
417 | + foreach (array('country', 'state', 'currency') as $key) { |
|
418 | + if (isset($_POST[$key])) { |
|
419 | 419 | $method = "set_$key"; |
420 | - $invoice->$method( $_POST[ $key ] ); |
|
420 | + $invoice->$method($_POST[$key]); |
|
421 | 421 | } |
422 | 422 | } |
423 | 423 | |
424 | 424 | // Maybe disable taxes. |
425 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
425 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
426 | 426 | |
427 | 427 | // Recalculate totals. |
428 | 428 | $invoice->recalculate_total(); |
429 | 429 | |
430 | - $total = wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ); |
|
430 | + $total = wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()); |
|
431 | 431 | |
432 | - if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
433 | - $recurring_total = wpinv_price( wpinv_format_amount( $invoice->get_recurring_total() ), $invoice->get_currency() ); |
|
434 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
432 | + if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
433 | + $recurring_total = wpinv_price(wpinv_format_amount($invoice->get_recurring_total()), $invoice->get_currency()); |
|
434 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | $totals = array( |
438 | - 'subtotal' => wpinv_price( wpinv_format_amount( $invoice->get_subtotal() ), $invoice->get_currency() ), |
|
439 | - 'discount' => wpinv_price( wpinv_format_amount( $invoice->get_total_discount() ), $invoice->get_currency() ), |
|
440 | - 'tax' => wpinv_price( wpinv_format_amount( $invoice->get_total_tax() ), $invoice->get_currency() ), |
|
438 | + 'subtotal' => wpinv_price(wpinv_format_amount($invoice->get_subtotal()), $invoice->get_currency()), |
|
439 | + 'discount' => wpinv_price(wpinv_format_amount($invoice->get_total_discount()), $invoice->get_currency()), |
|
440 | + 'tax' => wpinv_price(wpinv_format_amount($invoice->get_total_tax()), $invoice->get_currency()), |
|
441 | 441 | 'total' => $total, |
442 | 442 | ); |
443 | 443 | |
444 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
444 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
445 | 445 | |
446 | - wp_send_json_success( compact( 'totals' ) ); |
|
446 | + wp_send_json_success(compact('totals')); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -452,33 +452,33 @@ discard block |
||
452 | 452 | public static function get_invoice_items() { |
453 | 453 | |
454 | 454 | // Verify nonce. |
455 | - check_ajax_referer( 'wpinv-nonce' ); |
|
455 | + check_ajax_referer('wpinv-nonce'); |
|
456 | 456 | |
457 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
457 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
458 | 458 | exit; |
459 | 459 | } |
460 | 460 | |
461 | 461 | // We need an invoice and items. |
462 | - if ( empty( $_POST['post_id'] ) ) { |
|
462 | + if (empty($_POST['post_id'])) { |
|
463 | 463 | exit; |
464 | 464 | } |
465 | 465 | |
466 | 466 | // Fetch the invoice. |
467 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
467 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
468 | 468 | |
469 | 469 | // Ensure it exists. |
470 | - if ( ! $invoice->get_id() ) { |
|
470 | + if (!$invoice->get_id()) { |
|
471 | 471 | exit; |
472 | 472 | } |
473 | 473 | |
474 | 474 | // Return an array of invoice items. |
475 | 475 | $items = array(); |
476 | 476 | |
477 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
478 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
477 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
478 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
479 | 479 | } |
480 | 480 | |
481 | - wp_send_json_success( compact( 'items' ) ); |
|
481 | + wp_send_json_success(compact('items')); |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | /** |
@@ -487,50 +487,50 @@ discard block |
||
487 | 487 | public static function edit_invoice_item() { |
488 | 488 | |
489 | 489 | // Verify nonce. |
490 | - check_ajax_referer( 'wpinv-nonce' ); |
|
490 | + check_ajax_referer('wpinv-nonce'); |
|
491 | 491 | |
492 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
492 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
493 | 493 | exit; |
494 | 494 | } |
495 | 495 | |
496 | 496 | // We need an invoice and item details. |
497 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
497 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
498 | 498 | exit; |
499 | 499 | } |
500 | 500 | |
501 | 501 | // Fetch the invoice. |
502 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
502 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
503 | 503 | |
504 | 504 | // Ensure it exists and its not been paid for. |
505 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
505 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
506 | 506 | exit; |
507 | 507 | } |
508 | 508 | |
509 | 509 | // Format the data. |
510 | - $data = wp_list_pluck( $_POST['data'], 'value', 'field' ); |
|
510 | + $data = wp_list_pluck($_POST['data'], 'value', 'field'); |
|
511 | 511 | |
512 | 512 | // Ensure that we have an item id. |
513 | - if ( empty( $data['id'] ) ) { |
|
513 | + if (empty($data['id'])) { |
|
514 | 514 | exit; |
515 | 515 | } |
516 | 516 | |
517 | 517 | // Abort if the invoice does not have the specified item. |
518 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
518 | + $item = $invoice->get_item((int) $data['id']); |
|
519 | 519 | |
520 | - if ( empty( $item ) ) { |
|
520 | + if (empty($item)) { |
|
521 | 521 | exit; |
522 | 522 | } |
523 | 523 | |
524 | 524 | // Update the item. |
525 | - $item->set_price( $data['price'] ); |
|
526 | - $item->set_name( $data['name'] ); |
|
527 | - $item->set_description( $data['description'] ); |
|
528 | - $item->set_quantity( $data['quantity'] ); |
|
525 | + $item->set_price($data['price']); |
|
526 | + $item->set_name($data['name']); |
|
527 | + $item->set_description($data['description']); |
|
528 | + $item->set_quantity($data['quantity']); |
|
529 | 529 | |
530 | 530 | // Add it to the invoice. |
531 | - $error = $invoice->add_item( $item ); |
|
531 | + $error = $invoice->add_item($item); |
|
532 | 532 | $alert = false; |
533 | - if ( is_wp_error( $error ) ) { |
|
533 | + if (is_wp_error($error)) { |
|
534 | 534 | $alert = $error->get_error_message(); |
535 | 535 | } |
536 | 536 | |
@@ -543,11 +543,11 @@ discard block |
||
543 | 543 | // Return an array of invoice items. |
544 | 544 | $items = array(); |
545 | 545 | |
546 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
547 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
546 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
547 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
548 | 548 | } |
549 | 549 | |
550 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
550 | + wp_send_json_success(compact('items', 'alert')); |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | /** |
@@ -556,33 +556,33 @@ discard block |
||
556 | 556 | public static function remove_invoice_item() { |
557 | 557 | |
558 | 558 | // Verify nonce. |
559 | - check_ajax_referer( 'wpinv-nonce' ); |
|
559 | + check_ajax_referer('wpinv-nonce'); |
|
560 | 560 | |
561 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
561 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
562 | 562 | exit; |
563 | 563 | } |
564 | 564 | |
565 | 565 | // We need an invoice and an item. |
566 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
566 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
567 | 567 | exit; |
568 | 568 | } |
569 | 569 | |
570 | 570 | // Fetch the invoice. |
571 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
571 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
572 | 572 | |
573 | 573 | // Ensure it exists and its not been paid for. |
574 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
574 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
575 | 575 | exit; |
576 | 576 | } |
577 | 577 | |
578 | 578 | // Abort if the invoice does not have the specified item. |
579 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
579 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
580 | 580 | |
581 | - if ( empty( $item ) ) { |
|
581 | + if (empty($item)) { |
|
582 | 582 | exit; |
583 | 583 | } |
584 | 584 | |
585 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
585 | + $invoice->remove_item((int) $_POST['item_id']); |
|
586 | 586 | |
587 | 587 | // Update totals. |
588 | 588 | $invoice->recalculate_total(); |
@@ -593,11 +593,11 @@ discard block |
||
593 | 593 | // Return an array of invoice items. |
594 | 594 | $items = array(); |
595 | 595 | |
596 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
597 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
596 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
597 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
598 | 598 | } |
599 | 599 | |
600 | - wp_send_json_success( compact( 'items' ) ); |
|
600 | + wp_send_json_success(compact('items')); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | /** |
@@ -606,39 +606,39 @@ discard block |
||
606 | 606 | public static function add_invoice_items() { |
607 | 607 | |
608 | 608 | // Verify nonce. |
609 | - check_ajax_referer( 'wpinv-nonce' ); |
|
609 | + check_ajax_referer('wpinv-nonce'); |
|
610 | 610 | |
611 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
611 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
612 | 612 | exit; |
613 | 613 | } |
614 | 614 | |
615 | 615 | // We need an invoice and items. |
616 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
616 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
617 | 617 | exit; |
618 | 618 | } |
619 | 619 | |
620 | 620 | // Fetch the invoice. |
621 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
621 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
622 | 622 | $alert = false; |
623 | 623 | |
624 | 624 | // Ensure it exists and its not been paid for. |
625 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
625 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
626 | 626 | exit; |
627 | 627 | } |
628 | 628 | |
629 | 629 | // Add the items. |
630 | - foreach ( $_POST['items'] as $data ) { |
|
630 | + foreach ($_POST['items'] as $data) { |
|
631 | 631 | |
632 | - $item = new GetPaid_Form_Item( $data[ 'id' ] ); |
|
632 | + $item = new GetPaid_Form_Item($data['id']); |
|
633 | 633 | |
634 | - if ( is_numeric( $data[ 'qty' ] ) && (int) $data[ 'qty' ] > 0 ) { |
|
635 | - $item->set_quantity( $data[ 'qty' ] ); |
|
634 | + if (is_numeric($data['qty']) && (int) $data['qty'] > 0) { |
|
635 | + $item->set_quantity($data['qty']); |
|
636 | 636 | } |
637 | 637 | |
638 | - if ( $item->get_id() > 0 ) { |
|
639 | - $error = $invoice->add_item( $item ); |
|
638 | + if ($item->get_id() > 0) { |
|
639 | + $error = $invoice->add_item($item); |
|
640 | 640 | |
641 | - if ( is_wp_error( $error ) ) { |
|
641 | + if (is_wp_error($error)) { |
|
642 | 642 | $alert = $error->get_error_message(); |
643 | 643 | } |
644 | 644 | |
@@ -653,11 +653,11 @@ discard block |
||
653 | 653 | // Return an array of invoice items. |
654 | 654 | $items = array(); |
655 | 655 | |
656 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
657 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
656 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
657 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
658 | 658 | } |
659 | 659 | |
660 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
660 | + wp_send_json_success(compact('items', 'alert')); |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | /** |
@@ -666,15 +666,15 @@ discard block |
||
666 | 666 | public static function get_invoicing_items() { |
667 | 667 | |
668 | 668 | // Verify nonce. |
669 | - check_ajax_referer( 'wpinv-nonce' ); |
|
669 | + check_ajax_referer('wpinv-nonce'); |
|
670 | 670 | |
671 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
671 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
672 | 672 | exit; |
673 | 673 | } |
674 | 674 | |
675 | 675 | // We need a search term. |
676 | - if ( empty( $_GET['search'] ) ) { |
|
677 | - wp_send_json_success( array() ); |
|
676 | + if (empty($_GET['search'])) { |
|
677 | + wp_send_json_success(array()); |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | // Retrieve items. |
@@ -683,8 +683,8 @@ discard block |
||
683 | 683 | 'orderby' => 'title', |
684 | 684 | 'order' => 'ASC', |
685 | 685 | 'posts_per_page' => -1, |
686 | - 'post_status' => array( 'publish' ), |
|
687 | - 's' => trim( $_GET['search'] ), |
|
686 | + 'post_status' => array('publish'), |
|
687 | + 's' => trim($_GET['search']), |
|
688 | 688 | 'meta_query' => array( |
689 | 689 | array( |
690 | 690 | 'key' => '_wpinv_type', |
@@ -694,22 +694,22 @@ discard block |
||
694 | 694 | ) |
695 | 695 | ); |
696 | 696 | |
697 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
697 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
698 | 698 | $data = array(); |
699 | 699 | |
700 | 700 | |
701 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) ); |
|
701 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id'])); |
|
702 | 702 | |
703 | - foreach ( $items as $item ) { |
|
704 | - $item = new GetPaid_Form_Item( $item ); |
|
703 | + foreach ($items as $item) { |
|
704 | + $item = new GetPaid_Form_Item($item); |
|
705 | 705 | $data[] = array( |
706 | 706 | 'id' => (int) $item->get_id(), |
707 | - 'text' => strip_tags( $item->get_name() ), |
|
708 | - 'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '', |
|
707 | + 'text' => strip_tags($item->get_name()), |
|
708 | + 'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '', |
|
709 | 709 | ); |
710 | 710 | } |
711 | 711 | |
712 | - wp_send_json_success( $data ); |
|
712 | + wp_send_json_success($data); |
|
713 | 713 | |
714 | 714 | } |
715 | 715 | |
@@ -719,24 +719,24 @@ discard block |
||
719 | 719 | public static function get_aui_states_field() { |
720 | 720 | |
721 | 721 | // Verify nonce. |
722 | - check_ajax_referer( 'wpinv-nonce' ); |
|
722 | + check_ajax_referer('wpinv-nonce'); |
|
723 | 723 | |
724 | 724 | // We need a country. |
725 | - if ( empty( $_GET['country'] ) ) { |
|
725 | + if (empty($_GET['country'])) { |
|
726 | 726 | exit; |
727 | 727 | } |
728 | 728 | |
729 | - $states = wpinv_get_country_states( trim( $_GET['country'] ) ); |
|
730 | - $state = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state(); |
|
729 | + $states = wpinv_get_country_states(trim($_GET['country'])); |
|
730 | + $state = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state(); |
|
731 | 731 | |
732 | - if ( empty( $states ) ) { |
|
732 | + if (empty($states)) { |
|
733 | 733 | |
734 | 734 | $html = aui()->input( |
735 | 735 | array( |
736 | 736 | 'type' => 'text', |
737 | 737 | 'id' => 'wpinv_state', |
738 | 738 | 'name' => 'wpinv_state', |
739 | - 'label' => __( 'State', 'invoicing' ), |
|
739 | + 'label' => __('State', 'invoicing'), |
|
740 | 740 | 'label_type' => 'vertical', |
741 | 741 | 'placeholder' => 'Liège', |
742 | 742 | 'class' => 'form-control-sm', |
@@ -750,9 +750,9 @@ discard block |
||
750 | 750 | array( |
751 | 751 | 'id' => 'wpinv_state', |
752 | 752 | 'name' => 'wpinv_state', |
753 | - 'label' => __( 'State', 'invoicing' ), |
|
753 | + 'label' => __('State', 'invoicing'), |
|
754 | 754 | 'label_type' => 'vertical', |
755 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
755 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
756 | 756 | 'class' => 'form-control-sm', |
757 | 757 | 'value' => $state, |
758 | 758 | 'options' => $states, |
@@ -766,7 +766,7 @@ discard block |
||
766 | 766 | wp_send_json_success( |
767 | 767 | array( |
768 | 768 | 'html' => $html, |
769 | - 'select' => ! empty ( $states ) |
|
769 | + 'select' => !empty ($states) |
|
770 | 770 | ) |
771 | 771 | ); |
772 | 772 | |
@@ -780,46 +780,46 @@ discard block |
||
780 | 780 | public static function ip_geolocation() { |
781 | 781 | |
782 | 782 | // Check nonce. |
783 | - check_ajax_referer( 'getpaid-ip-location' ); |
|
783 | + check_ajax_referer('getpaid-ip-location'); |
|
784 | 784 | |
785 | 785 | // IP address. |
786 | - if ( empty( $_GET['ip'] ) || ! rest_is_ip_address( $_GET['ip'] ) ) { |
|
787 | - _e( 'Invalid IP Address.', 'invoicing' ); |
|
786 | + if (empty($_GET['ip']) || !rest_is_ip_address($_GET['ip'])) { |
|
787 | + _e('Invalid IP Address.', 'invoicing'); |
|
788 | 788 | exit; |
789 | 789 | } |
790 | 790 | |
791 | 791 | // Retrieve location info. |
792 | - $location = getpaid_geolocate_ip_address( $_GET['ip'] ); |
|
792 | + $location = getpaid_geolocate_ip_address($_GET['ip']); |
|
793 | 793 | |
794 | - if ( empty( $location ) ) { |
|
795 | - _e( 'Unable to find geolocation for the IP Address.', 'invoicing' ); |
|
794 | + if (empty($location)) { |
|
795 | + _e('Unable to find geolocation for the IP Address.', 'invoicing'); |
|
796 | 796 | exit; |
797 | 797 | } |
798 | 798 | |
799 | 799 | // Sorry. |
800 | - extract( $location ); |
|
800 | + extract($location); |
|
801 | 801 | |
802 | 802 | // Prepare the address. |
803 | 803 | $content = ''; |
804 | 804 | |
805 | - if ( ! empty( $location['city'] ) ) { |
|
806 | - $content .= $location['city'] . ', '; |
|
805 | + if (!empty($location['city'])) { |
|
806 | + $content .= $location['city'] . ', '; |
|
807 | 807 | } |
808 | 808 | |
809 | - if ( ! empty( $location['region'] ) ) { |
|
810 | - $content .= $location['region'] . ', '; |
|
809 | + if (!empty($location['region'])) { |
|
810 | + $content .= $location['region'] . ', '; |
|
811 | 811 | } |
812 | 812 | |
813 | - $content .= $location['country'] . ' (' . $location['iso'] . ')'; |
|
813 | + $content .= $location['country'] . ' (' . $location['iso'] . ')'; |
|
814 | 814 | |
815 | 815 | $location['address'] = $content; |
816 | 816 | |
817 | - $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $content ) . '</p>'; |
|
818 | - $content .= '<p>'. $location['credit'] . '</p>'; |
|
817 | + $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $content) . '</p>'; |
|
818 | + $content .= '<p>' . $location['credit'] . '</p>'; |
|
819 | 819 | |
820 | 820 | $location['content'] = $content; |
821 | 821 | |
822 | - wpinv_get_template( 'geolocation.php', $location ); |
|
822 | + wpinv_get_template('geolocation.php', $location); |
|
823 | 823 | |
824 | 824 | exit; |
825 | 825 | } |
@@ -832,11 +832,11 @@ discard block |
||
832 | 832 | public static function payment_form_refresh_prices() { |
833 | 833 | |
834 | 834 | // Check nonce. |
835 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
835 | + check_ajax_referer('getpaid_form_nonce'); |
|
836 | 836 | |
837 | 837 | // ... form fields... |
838 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
839 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
838 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
839 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
840 | 840 | exit; |
841 | 841 | } |
842 | 842 | |
@@ -844,18 +844,18 @@ discard block |
||
844 | 844 | $submission = new GetPaid_Payment_Form_Submission(); |
845 | 845 | |
846 | 846 | // Do we have an error? |
847 | - if ( ! empty( $submission->last_error ) ) { |
|
847 | + if (!empty($submission->last_error)) { |
|
848 | 848 | echo $submission->last_error; |
849 | 849 | exit; |
850 | 850 | } |
851 | 851 | |
852 | 852 | // Prepare the response. |
853 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
853 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
854 | 854 | |
855 | 855 | // Filter the response. |
856 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
856 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
857 | 857 | |
858 | - wp_send_json_success( $response ); |
|
858 | + wp_send_json_success($response); |
|
859 | 859 | } |
860 | 860 | |
861 | 861 | } |
@@ -13,128 +13,128 @@ |
||
13 | 13 | class GetPaid_Payment_Forms { |
14 | 14 | |
15 | 15 | /** |
16 | - * Class constructor |
|
17 | - * |
|
18 | - */ |
|
19 | - public function __construct() { |
|
20 | - |
|
21 | - // Update a payment form's revenue whenever an invoice is paid for or refunded. |
|
22 | - add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
23 | - add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
24 | - |
|
25 | - // Sync form amount whenever invoice statuses change. |
|
26 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
27 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
28 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
29 | - |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * Increments a form's revenue whenever there is a payment. |
|
34 | - * |
|
35 | - * @param WPInv_Invoice $invoice |
|
36 | - */ |
|
37 | - public function increment_form_revenue( $invoice ) { |
|
38 | - |
|
39 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
40 | - if ( $form->get_id() ) { |
|
41 | - $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
42 | - $form->save(); |
|
43 | - } |
|
44 | - |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Decreases form revenue whenever invoice payment changes. |
|
49 | - * |
|
50 | - * @param WPInv_Invoice $invoice |
|
51 | - */ |
|
52 | - public function decrease_form_revenue( $invoice ) { |
|
53 | - |
|
54 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
55 | - if ( $form->get_id() ) { |
|
56 | - $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
57 | - $form->save(); |
|
58 | - } |
|
59 | - |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Updates a form's failed amount. |
|
64 | - * |
|
65 | - * @param WPInv_Invoice $invoice |
|
66 | - * @param string $from |
|
67 | - * @param string $to |
|
68 | - */ |
|
69 | - public function update_form_failed_amount( $invoice, $from, $to ) { |
|
70 | - |
|
71 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
72 | - if ( $form->get_id() ) { |
|
73 | - return; |
|
74 | - } |
|
75 | - |
|
76 | - if ( 'wpi-failed' == $from ) { |
|
77 | - $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
78 | - $form->save(); |
|
79 | - } |
|
80 | - |
|
81 | - if ( 'wpi-failed' == $to ) { |
|
82 | - $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
83 | - $form->save(); |
|
84 | - } |
|
85 | - |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Updates a form's refunded amount. |
|
90 | - * |
|
91 | - * @param WPInv_Invoice $invoice |
|
92 | - * @param string $from |
|
93 | - * @param string $to |
|
94 | - */ |
|
95 | - public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
96 | - |
|
97 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
98 | - if ( $form->get_id() ) { |
|
99 | - return; |
|
100 | - } |
|
101 | - |
|
102 | - if ( 'wpi-refunded' == $from ) { |
|
103 | - $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
104 | - $form->save(); |
|
105 | - } |
|
106 | - |
|
107 | - if ( 'wpi-refunded' == $to ) { |
|
108 | - $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
109 | - $form->save(); |
|
110 | - } |
|
111 | - |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Updates a form's cancelled amount. |
|
116 | - * |
|
117 | - * @param WPInv_Invoice $invoice |
|
118 | - * @param string $from |
|
119 | - * @param string $to |
|
120 | - */ |
|
121 | - public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
122 | - |
|
123 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
124 | - if ( $form->get_id() ) { |
|
125 | - return; |
|
126 | - } |
|
127 | - |
|
128 | - if ( 'wpi-cancelled' == $from ) { |
|
129 | - $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
130 | - $form->save(); |
|
131 | - } |
|
132 | - |
|
133 | - if ( 'wpi-cancelled' == $to ) { |
|
134 | - $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
135 | - $form->save(); |
|
136 | - } |
|
137 | - |
|
138 | - } |
|
16 | + * Class constructor |
|
17 | + * |
|
18 | + */ |
|
19 | + public function __construct() { |
|
20 | + |
|
21 | + // Update a payment form's revenue whenever an invoice is paid for or refunded. |
|
22 | + add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
23 | + add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
24 | + |
|
25 | + // Sync form amount whenever invoice statuses change. |
|
26 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
27 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
28 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
29 | + |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * Increments a form's revenue whenever there is a payment. |
|
34 | + * |
|
35 | + * @param WPInv_Invoice $invoice |
|
36 | + */ |
|
37 | + public function increment_form_revenue( $invoice ) { |
|
38 | + |
|
39 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
40 | + if ( $form->get_id() ) { |
|
41 | + $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
42 | + $form->save(); |
|
43 | + } |
|
44 | + |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Decreases form revenue whenever invoice payment changes. |
|
49 | + * |
|
50 | + * @param WPInv_Invoice $invoice |
|
51 | + */ |
|
52 | + public function decrease_form_revenue( $invoice ) { |
|
53 | + |
|
54 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
55 | + if ( $form->get_id() ) { |
|
56 | + $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
57 | + $form->save(); |
|
58 | + } |
|
59 | + |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Updates a form's failed amount. |
|
64 | + * |
|
65 | + * @param WPInv_Invoice $invoice |
|
66 | + * @param string $from |
|
67 | + * @param string $to |
|
68 | + */ |
|
69 | + public function update_form_failed_amount( $invoice, $from, $to ) { |
|
70 | + |
|
71 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
72 | + if ( $form->get_id() ) { |
|
73 | + return; |
|
74 | + } |
|
75 | + |
|
76 | + if ( 'wpi-failed' == $from ) { |
|
77 | + $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
78 | + $form->save(); |
|
79 | + } |
|
80 | + |
|
81 | + if ( 'wpi-failed' == $to ) { |
|
82 | + $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
83 | + $form->save(); |
|
84 | + } |
|
85 | + |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Updates a form's refunded amount. |
|
90 | + * |
|
91 | + * @param WPInv_Invoice $invoice |
|
92 | + * @param string $from |
|
93 | + * @param string $to |
|
94 | + */ |
|
95 | + public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
96 | + |
|
97 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
98 | + if ( $form->get_id() ) { |
|
99 | + return; |
|
100 | + } |
|
101 | + |
|
102 | + if ( 'wpi-refunded' == $from ) { |
|
103 | + $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
104 | + $form->save(); |
|
105 | + } |
|
106 | + |
|
107 | + if ( 'wpi-refunded' == $to ) { |
|
108 | + $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
109 | + $form->save(); |
|
110 | + } |
|
111 | + |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Updates a form's cancelled amount. |
|
116 | + * |
|
117 | + * @param WPInv_Invoice $invoice |
|
118 | + * @param string $from |
|
119 | + * @param string $to |
|
120 | + */ |
|
121 | + public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
122 | + |
|
123 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
124 | + if ( $form->get_id() ) { |
|
125 | + return; |
|
126 | + } |
|
127 | + |
|
128 | + if ( 'wpi-cancelled' == $from ) { |
|
129 | + $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
130 | + $form->save(); |
|
131 | + } |
|
132 | + |
|
133 | + if ( 'wpi-cancelled' == $to ) { |
|
134 | + $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
135 | + $form->save(); |
|
136 | + } |
|
137 | + |
|
138 | + } |
|
139 | 139 | |
140 | 140 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment forms controller class |
@@ -19,13 +19,13 @@ discard block |
||
19 | 19 | public function __construct() { |
20 | 20 | |
21 | 21 | // Update a payment form's revenue whenever an invoice is paid for or refunded. |
22 | - add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
23 | - add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
22 | + add_action('getpaid_invoice_payment_status_changed', array($this, 'increment_form_revenue')); |
|
23 | + add_action('getpaid_invoice_payment_status_reversed', array($this, 'decrease_form_revenue')); |
|
24 | 24 | |
25 | 25 | // Sync form amount whenever invoice statuses change. |
26 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
27 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
28 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
26 | + add_action('getpaid_invoice_status_changed', array($this, 'update_form_failed_amount'), 10, 3); |
|
27 | + add_action('getpaid_invoice_status_changed', array($this, 'update_form_refunded_amount'), 10, 3); |
|
28 | + add_action('getpaid_invoice_status_changed', array($this, 'update_form_cancelled_amount'), 10, 3); |
|
29 | 29 | |
30 | 30 | } |
31 | 31 | |
@@ -34,11 +34,11 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @param WPInv_Invoice $invoice |
36 | 36 | */ |
37 | - public function increment_form_revenue( $invoice ) { |
|
37 | + public function increment_form_revenue($invoice) { |
|
38 | 38 | |
39 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
40 | - if ( $form->get_id() ) { |
|
41 | - $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
39 | + $form = new GetPaid_Payment_Form($invoice->get_payment_form()); |
|
40 | + if ($form->get_id()) { |
|
41 | + $form->set_earned($form->get_earned() + $invoice->get_total()); |
|
42 | 42 | $form->save(); |
43 | 43 | } |
44 | 44 | |
@@ -49,11 +49,11 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @param WPInv_Invoice $invoice |
51 | 51 | */ |
52 | - public function decrease_form_revenue( $invoice ) { |
|
52 | + public function decrease_form_revenue($invoice) { |
|
53 | 53 | |
54 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
55 | - if ( $form->get_id() ) { |
|
56 | - $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
54 | + $form = new GetPaid_Payment_Form($invoice->get_payment_form()); |
|
55 | + if ($form->get_id()) { |
|
56 | + $form->set_earned($form->get_earned() - $invoice->get_total()); |
|
57 | 57 | $form->save(); |
58 | 58 | } |
59 | 59 | |
@@ -66,20 +66,20 @@ discard block |
||
66 | 66 | * @param string $from |
67 | 67 | * @param string $to |
68 | 68 | */ |
69 | - public function update_form_failed_amount( $invoice, $from, $to ) { |
|
69 | + public function update_form_failed_amount($invoice, $from, $to) { |
|
70 | 70 | |
71 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
72 | - if ( $form->get_id() ) { |
|
71 | + $form = new GetPaid_Payment_Form($invoice->get_payment_form()); |
|
72 | + if ($form->get_id()) { |
|
73 | 73 | return; |
74 | 74 | } |
75 | 75 | |
76 | - if ( 'wpi-failed' == $from ) { |
|
77 | - $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
76 | + if ('wpi-failed' == $from) { |
|
77 | + $form->set_failed($form->get_failed() - $invoice->get_total()); |
|
78 | 78 | $form->save(); |
79 | 79 | } |
80 | 80 | |
81 | - if ( 'wpi-failed' == $to ) { |
|
82 | - $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
81 | + if ('wpi-failed' == $to) { |
|
82 | + $form->set_failed($form->get_failed() + $invoice->get_total()); |
|
83 | 83 | $form->save(); |
84 | 84 | } |
85 | 85 | |
@@ -92,20 +92,20 @@ discard block |
||
92 | 92 | * @param string $from |
93 | 93 | * @param string $to |
94 | 94 | */ |
95 | - public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
95 | + public function update_form_refunded_amount($invoice, $from, $to) { |
|
96 | 96 | |
97 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
98 | - if ( $form->get_id() ) { |
|
97 | + $form = new GetPaid_Payment_Form($invoice->get_payment_form()); |
|
98 | + if ($form->get_id()) { |
|
99 | 99 | return; |
100 | 100 | } |
101 | 101 | |
102 | - if ( 'wpi-refunded' == $from ) { |
|
103 | - $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
102 | + if ('wpi-refunded' == $from) { |
|
103 | + $form->set_refunded($form->get_refunded() - $invoice->get_total()); |
|
104 | 104 | $form->save(); |
105 | 105 | } |
106 | 106 | |
107 | - if ( 'wpi-refunded' == $to ) { |
|
108 | - $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
107 | + if ('wpi-refunded' == $to) { |
|
108 | + $form->set_refunded($form->get_refunded() + $invoice->get_total()); |
|
109 | 109 | $form->save(); |
110 | 110 | } |
111 | 111 | |
@@ -118,20 +118,20 @@ discard block |
||
118 | 118 | * @param string $from |
119 | 119 | * @param string $to |
120 | 120 | */ |
121 | - public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
121 | + public function update_form_cancelled_amount($invoice, $from, $to) { |
|
122 | 122 | |
123 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
124 | - if ( $form->get_id() ) { |
|
123 | + $form = new GetPaid_Payment_Form($invoice->get_payment_form()); |
|
124 | + if ($form->get_id()) { |
|
125 | 125 | return; |
126 | 126 | } |
127 | 127 | |
128 | - if ( 'wpi-cancelled' == $from ) { |
|
129 | - $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
128 | + if ('wpi-cancelled' == $from) { |
|
129 | + $form->set_cancelled($form->get_cancelled() - $invoice->get_total()); |
|
130 | 130 | $form->save(); |
131 | 131 | } |
132 | 132 | |
133 | - if ( 'wpi-cancelled' == $to ) { |
|
134 | - $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
133 | + if ('wpi-cancelled' == $to) { |
|
134 | + $form->set_cancelled($form->get_cancelled() + $invoice->get_total()); |
|
135 | 135 | $form->save(); |
136 | 136 | } |
137 | 137 |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
10 | - exit; // Exit if accessed directly |
|
10 | + exit; // Exit if accessed directly |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | class GetPaid_Meta_Box_Payment_Form { |
17 | 17 | |
18 | 18 | /** |
19 | - * Output the metabox. |
|
20 | - * |
|
21 | - * @param WP_Post $post |
|
22 | - */ |
|
19 | + * Output the metabox. |
|
20 | + * |
|
21 | + * @param WP_Post $post |
|
22 | + */ |
|
23 | 23 | public static function output( $post ) { |
24 | 24 | ?> |
25 | 25 | <div id="wpinv-form-builder" class="bsui"> |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | - * Save meta box data. |
|
90 | - * |
|
91 | - * @param int $post_id |
|
92 | - */ |
|
93 | - public static function save( $post_id ) { |
|
89 | + * Save meta box data. |
|
90 | + * |
|
91 | + * @param int $post_id |
|
92 | + */ |
|
93 | + public static function save( $post_id ) { |
|
94 | 94 | |
95 | 95 | // Prepare the form. |
96 | 96 | $form = new GetPaid_Payment_Form( $post_id ); |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | - * Converts an array fo form items to objects. |
|
125 | - * |
|
126 | - * @param array $items |
|
127 | - */ |
|
128 | - public static function item_to_objects( $items ) { |
|
124 | + * Converts an array fo form items to objects. |
|
125 | + * |
|
126 | + * @param array $items |
|
127 | + */ |
|
128 | + public static function item_to_objects( $items ) { |
|
129 | 129 | |
130 | 130 | $objects = array(); |
131 | 131 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if (!defined('ABSPATH')) { |
|
10 | 10 | exit; // Exit if accessed directly |
11 | 11 | } |
12 | 12 | |
@@ -20,14 +20,14 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @param WP_Post $post |
22 | 22 | */ |
23 | - public static function output( $post ) { |
|
23 | + public static function output($post) { |
|
24 | 24 | ?> |
25 | 25 | <div id="wpinv-form-builder" class="bsui"> |
26 | 26 | <div class="row"> |
27 | 27 | <div class="col-sm-4"> |
28 | 28 | |
29 | 29 | <!-- Builder tabs --> |
30 | - <button class="button button-primary" v-if="active_tab!='new_item'" @click.prevent="active_tab='new_item'"><?php _e( 'Go Back', 'invoicing' ); ?></button> |
|
30 | + <button class="button button-primary" v-if="active_tab!='new_item'" @click.prevent="active_tab='new_item'"><?php _e('Go Back', 'invoicing'); ?></button> |
|
31 | 31 | |
32 | 32 | <!-- Builder tab content --> |
33 | 33 | <div class="mt-4"> |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | <!-- Available builder elements --> |
36 | 36 | <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='new_item'"> |
37 | 37 | <div class="wpinv-form-builder-add-field-types"> |
38 | - <small class='form-text text-muted'><?php _e( 'Add an element by dragging it to the payment form.', 'invoicing' ); ?></small> |
|
38 | + <small class='form-text text-muted'><?php _e('Add an element by dragging it to the payment form.', 'invoicing'); ?></small> |
|
39 | 39 | <draggable class="section mt-2" style="display: flex; flex-flow: wrap; justify-content: space-between;" v-model="elements" :group="{ name: 'fields', pull: 'clone', put: false }" :sort="false" :clone="addDraggedField" tag="ul" filter=".wpinv-undraggable"> |
40 | 40 | <li v-for="element in elements" class= "wpinv-payment-form-left-fields-field" @click.prevent="addField(element)" :class="{ 'd-none': element.defaults.premade }"> |
41 | 41 | <button class="button btn"> |
@@ -50,10 +50,10 @@ discard block |
||
50 | 50 | <!-- Edit an element --> |
51 | 51 | <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='edit_item'" style="font-size: 14px;"> |
52 | 52 | <div class="wpinv-form-builder-edit-field-wrapper"> |
53 | - <?php do_action( 'wpinv_payment_form_edit_element_template', 'active_form_element', $post ); ?> |
|
54 | - <?php do_action( 'getpaid_payment_form_edit_element_template', $post ); ?> |
|
53 | + <?php do_action('wpinv_payment_form_edit_element_template', 'active_form_element', $post); ?> |
|
54 | + <?php do_action('getpaid_payment_form_edit_element_template', $post); ?> |
|
55 | 55 | <div> |
56 | - <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e( 'Delete Element', 'invoicing' ); ?></button> |
|
56 | + <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e('Delete Element', 'invoicing'); ?></button> |
|
57 | 57 | </div> |
58 | 58 | </div> |
59 | 59 | </div> |
@@ -62,14 +62,14 @@ discard block |
||
62 | 62 | |
63 | 63 | </div> |
64 | 64 | <div class="col-sm-8 border-left"> |
65 | - <small class='form-text text-muted' v-if='form_elements.length'><?php _e( 'Click on any element to edit or delete it.', 'invoicing' ); ?></small> |
|
66 | - <p class='form-text text-muted' v-if='! form_elements.length'><?php _e( 'This form is empty. Add new elements by dragging them from the right.', 'invoicing' ); ?></p> |
|
65 | + <small class='form-text text-muted' v-if='form_elements.length'><?php _e('Click on any element to edit or delete it.', 'invoicing'); ?></small> |
|
66 | + <p class='form-text text-muted' v-if='! form_elements.length'><?php _e('This form is empty. Add new elements by dragging them from the right.', 'invoicing'); ?></p> |
|
67 | 67 | |
68 | 68 | <draggable class="section bsui" v-model="form_elements" @add="highlightLastDroppedField" group="fields" tag="div" style="min-height: 100%; font-size: 14px;"> |
69 | 69 | <div v-for="form_element in form_elements" class="wpinv-form-builder-element-preview" :class="[{ active: active_form_element==form_element && active_tab=='edit_item' }, form_element.type]" @click="active_tab = 'edit_item'; active_form_element = form_element"> |
70 | 70 | <div class="wpinv-form-builder-element-preview-inner"> |
71 | 71 | <div class="wpinv-payment-form-field-preview-overlay"></div> |
72 | - <?php do_action( 'wpinv_payment_form_render_element_template', 'form_element', $post ); ?> |
|
72 | + <?php do_action('wpinv_payment_form_render_element_template', 'form_element', $post); ?> |
|
73 | 73 | </div> |
74 | 74 | </div> |
75 | 75 | </draggable> |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | </div> |
83 | 83 | <?php |
84 | 84 | |
85 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
85 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -90,33 +90,33 @@ discard block |
||
90 | 90 | * |
91 | 91 | * @param int $post_id |
92 | 92 | */ |
93 | - public static function save( $post_id ) { |
|
93 | + public static function save($post_id) { |
|
94 | 94 | |
95 | 95 | // Prepare the form. |
96 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
96 | + $form = new GetPaid_Payment_Form($post_id); |
|
97 | 97 | |
98 | 98 | // Fetch form items. |
99 | - $form_items = json_decode( wp_unslash( $_POST['wpinv_form_items'] ), true ); |
|
99 | + $form_items = json_decode(wp_unslash($_POST['wpinv_form_items']), true); |
|
100 | 100 | |
101 | 101 | // Ensure that we have an array... |
102 | - if ( empty( $form_items ) ) { |
|
102 | + if (empty($form_items)) { |
|
103 | 103 | $form_items = array(); |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Add it to the form. |
107 | - $form->set_items( self::item_to_objects( $form_items ) ); |
|
107 | + $form->set_items(self::item_to_objects($form_items)); |
|
108 | 108 | |
109 | 109 | // Save form elements. |
110 | - $form_elements = json_decode( wp_unslash( $_POST['wpinv_form_elements'] ), true ); |
|
111 | - if ( empty( $form_elements ) ) { |
|
110 | + $form_elements = json_decode(wp_unslash($_POST['wpinv_form_elements']), true); |
|
111 | + if (empty($form_elements)) { |
|
112 | 112 | $form_elements = array(); |
113 | 113 | } |
114 | 114 | |
115 | - $form->set_elements( $form_elements ); |
|
115 | + $form->set_elements($form_elements); |
|
116 | 116 | |
117 | 117 | // Persist data to the datastore. |
118 | 118 | $form->save(); |
119 | - do_action( 'getpaid_payment_form_metabox_save', $post_id, $form ); |
|
119 | + do_action('getpaid_payment_form_metabox_save', $post_id, $form); |
|
120 | 120 | |
121 | 121 | } |
122 | 122 | |
@@ -125,14 +125,14 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @param array $items |
127 | 127 | */ |
128 | - public static function item_to_objects( $items ) { |
|
128 | + public static function item_to_objects($items) { |
|
129 | 129 | |
130 | 130 | $objects = array(); |
131 | 131 | |
132 | - foreach ( $items as $item ) { |
|
133 | - $_item = new GetPaid_Form_Item( $item['id'] ); |
|
134 | - $_item->set_allow_quantities( (bool) $item['allow_quantities'] ); |
|
135 | - $_item->set_is_required( (bool) $item['required'] ); |
|
132 | + foreach ($items as $item) { |
|
133 | + $_item = new GetPaid_Form_Item($item['id']); |
|
134 | + $_item->set_allow_quantities((bool) $item['allow_quantities']); |
|
135 | + $_item->set_is_required((bool) $item['required']); |
|
136 | 136 | $objects[] = $_item; |
137 | 137 | } |
138 | 138 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Discount_Details { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the discount. |
@@ -368,34 +368,34 @@ discard block |
||
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
371 | - * Save meta box data. |
|
372 | - * |
|
373 | - * @param int $post_id |
|
374 | - */ |
|
375 | - public static function save( $post_id ) { |
|
371 | + * Save meta box data. |
|
372 | + * |
|
373 | + * @param int $post_id |
|
374 | + */ |
|
375 | + public static function save( $post_id ) { |
|
376 | 376 | |
377 | 377 | // Prepare the discount. |
378 | 378 | $discount = new WPInv_Discount( $post_id ); |
379 | 379 | |
380 | 380 | // Load new data. |
381 | 381 | $discount->set_props( |
382 | - array( |
|
383 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
384 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
385 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
382 | + array( |
|
383 | + 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
384 | + 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
385 | + 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | + 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | + 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
388 | 388 | 'type' => isset( $_POST['wpinv_discount_type'] ) ? $_POST['wpinv_discount_type'] : null, |
389 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(), |
|
391 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
392 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
393 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
394 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
395 | - ) |
|
389 | + 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | + 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(), |
|
391 | + 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
392 | + 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
393 | + 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
394 | + 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
395 | + ) |
|
396 | 396 | ); |
397 | 397 | |
398 | - $discount->save(); |
|
399 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
400 | - } |
|
398 | + $discount->save(); |
|
399 | + do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
400 | + } |
|
401 | 401 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,24 +21,24 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | |
26 | 26 | // Prepare the discount. |
27 | - $discount = new WPInv_Discount( $post ); |
|
27 | + $discount = new WPInv_Discount($post); |
|
28 | 28 | |
29 | 29 | // Nonce field. |
30 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
30 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
31 | 31 | |
32 | - do_action( 'wpinv_discount_form_top', $discount ); |
|
32 | + do_action('wpinv_discount_form_top', $discount); |
|
33 | 33 | |
34 | 34 | // Set the currency position. |
35 | 35 | $position = wpinv_currency_position(); |
36 | 36 | |
37 | - if ( $position == 'left_space' ) { |
|
37 | + if ($position == 'left_space') { |
|
38 | 38 | $position = 'left'; |
39 | 39 | } |
40 | 40 | |
41 | - if ( $position == 'right_space' ) { |
|
41 | + if ($position == 'right_space') { |
|
42 | 42 | $position = 'right'; |
43 | 43 | } |
44 | 44 | |
@@ -52,66 +52,66 @@ discard block |
||
52 | 52 | </style> |
53 | 53 | <div class='bsui' style='max-width: 600px;padding-top: 10px;'> |
54 | 54 | |
55 | - <?php do_action( 'wpinv_discount_form_first', $discount ); ?> |
|
55 | + <?php do_action('wpinv_discount_form_first', $discount); ?> |
|
56 | 56 | |
57 | - <?php do_action( 'wpinv_discount_form_before_code', $discount ); ?> |
|
57 | + <?php do_action('wpinv_discount_form_before_code', $discount); ?> |
|
58 | 58 | <div class="form-group row"> |
59 | 59 | <label for="wpinv_discount_code" class="col-sm-3 col-form-label"> |
60 | - <?php _e( 'Discount Code', 'invoicing' );?> |
|
60 | + <?php _e('Discount Code', 'invoicing'); ?> |
|
61 | 61 | </label> |
62 | 62 | <div class="col-sm-8"> |
63 | 63 | <div class="row"> |
64 | 64 | <div class="col-sm-12 form-group"> |
65 | - <input type="text" value="<?php echo esc_attr( $discount->get_code( 'edit' ) ); ?>" placeholder="SUMMER_SALE" name="wpinv_discount_code" id="wpinv_discount_code" style="width: 100%;" /> |
|
65 | + <input type="text" value="<?php echo esc_attr($discount->get_code('edit')); ?>" placeholder="SUMMER_SALE" name="wpinv_discount_code" id="wpinv_discount_code" style="width: 100%;" /> |
|
66 | 66 | </div> |
67 | 67 | <div class="col-sm-12"> |
68 | 68 | <?php |
69 | - do_action( 'wpinv_discount_form_before_single_use', $discount ); |
|
69 | + do_action('wpinv_discount_form_before_single_use', $discount); |
|
70 | 70 | |
71 | 71 | echo aui()->input( |
72 | 72 | array( |
73 | 73 | 'id' => 'wpinv_discount_single_use', |
74 | 74 | 'name' => 'wpinv_discount_single_use', |
75 | 75 | 'type' => 'checkbox', |
76 | - 'label' => __( 'Each customer can only use this discount once', 'invoicing' ), |
|
76 | + 'label' => __('Each customer can only use this discount once', 'invoicing'), |
|
77 | 77 | 'value' => '1', |
78 | 78 | 'checked' => $discount->is_single_use(), |
79 | 79 | ) |
80 | 80 | ); |
81 | 81 | |
82 | - do_action( 'wpinv_discount_form_single_use', $discount ); |
|
82 | + do_action('wpinv_discount_form_single_use', $discount); |
|
83 | 83 | ?> |
84 | 84 | </div> |
85 | 85 | <div class="col-sm-12"> |
86 | 86 | <?php |
87 | - do_action( 'wpinv_discount_form_before_recurring', $discount ); |
|
87 | + do_action('wpinv_discount_form_before_recurring', $discount); |
|
88 | 88 | |
89 | 89 | echo aui()->input( |
90 | 90 | array( |
91 | 91 | 'id' => 'wpinv_discount_recurring', |
92 | 92 | 'name' => 'wpinv_discount_recurring', |
93 | 93 | 'type' => 'checkbox', |
94 | - 'label' => __( 'Apply this discount to all recurring payments for subscriptions', 'invoicing' ), |
|
94 | + 'label' => __('Apply this discount to all recurring payments for subscriptions', 'invoicing'), |
|
95 | 95 | 'value' => '1', |
96 | 96 | 'checked' => $discount->is_recurring(), |
97 | 97 | ) |
98 | 98 | ); |
99 | 99 | |
100 | - do_action( 'wpinv_discount_form_recurring', $discount ); |
|
100 | + do_action('wpinv_discount_form_recurring', $discount); |
|
101 | 101 | ?> |
102 | 102 | </div> |
103 | 103 | </div> |
104 | 104 | </div> |
105 | 105 | <div class="col-sm-1 pt-2 pl-0"> |
106 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter a discount code such as 10OFF.', 'invoicing' ); ?>"></span> |
|
106 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter a discount code such as 10OFF.', 'invoicing'); ?>"></span> |
|
107 | 107 | </div> |
108 | 108 | </div> |
109 | - <?php do_action( 'wpinv_discount_form_code', $discount ); ?> |
|
109 | + <?php do_action('wpinv_discount_form_code', $discount); ?> |
|
110 | 110 | |
111 | - <?php do_action( 'wpinv_discount_form_before_type', $discount ); ?> |
|
111 | + <?php do_action('wpinv_discount_form_before_type', $discount); ?> |
|
112 | 112 | <div class="form-group row"> |
113 | 113 | <label for="wpinv_discount_type" class="col-sm-3 col-form-label"> |
114 | - <?php _e( 'Discount Type', 'invoicing' );?> |
|
114 | + <?php _e('Discount Type', 'invoicing'); ?> |
|
115 | 115 | </label> |
116 | 116 | <div class="col-sm-8"> |
117 | 117 | <?php |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | array( |
120 | 120 | 'id' => 'wpinv_discount_type', |
121 | 121 | 'name' => 'wpinv_discount_type', |
122 | - 'label' => __( 'Discount Type', 'invoicing' ), |
|
123 | - 'placeholder' => __( 'Select Discount Type', 'invoicing' ), |
|
124 | - 'value' => $discount->get_type( 'edit' ), |
|
122 | + 'label' => __('Discount Type', 'invoicing'), |
|
123 | + 'placeholder' => __('Select Discount Type', 'invoicing'), |
|
124 | + 'value' => $discount->get_type('edit'), |
|
125 | 125 | 'select2' => true, |
126 | 126 | 'data-allow-clear' => 'false', |
127 | 127 | 'options' => wpinv_get_discount_types() |
@@ -130,19 +130,19 @@ discard block |
||
130 | 130 | ?> |
131 | 131 | </div> |
132 | 132 | <div class="col-sm-1 pt-2 pl-0"> |
133 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Discount type.', 'invoicing' ); ?>"></span> |
|
133 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Discount type.', 'invoicing'); ?>"></span> |
|
134 | 134 | </div> |
135 | 135 | </div> |
136 | - <?php do_action( 'wpinv_discount_form_type', $discount ); ?> |
|
136 | + <?php do_action('wpinv_discount_form_type', $discount); ?> |
|
137 | 137 | |
138 | - <?php do_action( 'wpinv_discount_form_before_amount', $discount ); ?> |
|
139 | - <div class="form-group row <?php echo esc_attr( $discount->get_type( 'edit' ) ); ?>" id="wpinv_discount_amount_wrap"> |
|
138 | + <?php do_action('wpinv_discount_form_before_amount', $discount); ?> |
|
139 | + <div class="form-group row <?php echo esc_attr($discount->get_type('edit')); ?>" id="wpinv_discount_amount_wrap"> |
|
140 | 140 | <label for="wpinv_discount_amount" class="col-sm-3 col-form-label"> |
141 | - <?php _e( 'Discount Amount', 'invoicing' );?> |
|
141 | + <?php _e('Discount Amount', 'invoicing'); ?> |
|
142 | 142 | </label> |
143 | 143 | <div class="col-sm-8"> |
144 | 144 | <div class="input-group input-group-sm"> |
145 | - <?php if( 'left' == $position ) : ?> |
|
145 | + <?php if ('left' == $position) : ?> |
|
146 | 146 | <div class="input-group-prepend left wpinv-if-flat"> |
147 | 147 | <span class="input-group-text"> |
148 | 148 | <?php echo wpinv_currency_symbol(); ?> |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | </div> |
151 | 151 | <?php endif; ?> |
152 | 152 | |
153 | - <input type="text" name="wpinv_discount_amount" id="wpinv_discount_amount" value="<?php echo esc_attr( $discount->get_amount( 'edit' ) ); ?>" placeholder="0" class="form-control"> |
|
153 | + <input type="text" name="wpinv_discount_amount" id="wpinv_discount_amount" value="<?php echo esc_attr($discount->get_amount('edit')); ?>" placeholder="0" class="form-control"> |
|
154 | 154 | |
155 | - <?php if( 'right' == $position ) : ?> |
|
155 | + <?php if ('right' == $position) : ?> |
|
156 | 156 | <div class="input-group-prepend left wpinv-if-flat"> |
157 | 157 | <span class="input-group-text"> |
158 | 158 | <?php echo wpinv_currency_symbol(); ?> |
@@ -165,15 +165,15 @@ discard block |
||
165 | 165 | </div> |
166 | 166 | </div> |
167 | 167 | <div class="col-sm-1 pt-2 pl-0"> |
168 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?>"></span> |
|
168 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter the discount value. Ex: 10', 'invoicing'); ?>"></span> |
|
169 | 169 | </div> |
170 | 170 | </div> |
171 | - <?php do_action( 'wpinv_discount_form_amount', $discount ); ?> |
|
171 | + <?php do_action('wpinv_discount_form_amount', $discount); ?> |
|
172 | 172 | |
173 | - <?php do_action( 'wpinv_discount_form_before_items', $discount ); ?> |
|
173 | + <?php do_action('wpinv_discount_form_before_items', $discount); ?> |
|
174 | 174 | <div class="form-group row"> |
175 | 175 | <label for="wpinv_discount_items" class="col-sm-3 col-form-label"> |
176 | - <?php _e( 'Items', 'invoicing' );?> |
|
176 | + <?php _e('Items', 'invoicing'); ?> |
|
177 | 177 | </label> |
178 | 178 | <div class="col-sm-8"> |
179 | 179 | <?php |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | array( |
182 | 182 | 'id' => 'wpinv_discount_items', |
183 | 183 | 'name' => 'wpinv_discount_items[]', |
184 | - 'label' => __( 'Items', 'invoicing' ), |
|
185 | - 'placeholder' => __( 'Select Items', 'invoicing' ), |
|
186 | - 'value' => $discount->get_items( 'edit' ), |
|
184 | + 'label' => __('Items', 'invoicing'), |
|
185 | + 'placeholder' => __('Select Items', 'invoicing'), |
|
186 | + 'value' => $discount->get_items('edit'), |
|
187 | 187 | 'select2' => true, |
188 | 188 | 'multiple' => true, |
189 | 189 | 'data-allow-clear' => 'false', |
@@ -193,15 +193,15 @@ discard block |
||
193 | 193 | ?> |
194 | 194 | </div> |
195 | 195 | <div class="col-sm-1 pt-2 pl-0"> |
196 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select the items that are allowed to use this discount or leave blank to use this discount all items.', 'invoicing' ); ?>"></span> |
|
196 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select the items that are allowed to use this discount or leave blank to use this discount all items.', 'invoicing'); ?>"></span> |
|
197 | 197 | </div> |
198 | 198 | </div> |
199 | - <?php do_action( 'wpinv_discount_form_items', $discount ); ?> |
|
199 | + <?php do_action('wpinv_discount_form_items', $discount); ?> |
|
200 | 200 | |
201 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $discount ); ?> |
|
201 | + <?php do_action('wpinv_discount_form_before_excluded_items', $discount); ?> |
|
202 | 202 | <div class="form-group row"> |
203 | 203 | <label for="wpinv_discount_excluded_items" class="col-sm-3 col-form-label"> |
204 | - <?php _e( 'Excluded Items', 'invoicing' );?> |
|
204 | + <?php _e('Excluded Items', 'invoicing'); ?> |
|
205 | 205 | </label> |
206 | 206 | <div class="col-sm-8"> |
207 | 207 | <?php |
@@ -209,9 +209,9 @@ discard block |
||
209 | 209 | array( |
210 | 210 | 'id' => 'wpinv_discount_excluded_items', |
211 | 211 | 'name' => 'wpinv_discount_excluded_items[]', |
212 | - 'label' => __( 'Excluded Items', 'invoicing' ), |
|
213 | - 'placeholder' => __( 'Select Items', 'invoicing' ), |
|
214 | - 'value' => $discount->get_excluded_items( 'edit' ), |
|
212 | + 'label' => __('Excluded Items', 'invoicing'), |
|
213 | + 'placeholder' => __('Select Items', 'invoicing'), |
|
214 | + 'value' => $discount->get_excluded_items('edit'), |
|
215 | 215 | 'select2' => true, |
216 | 216 | 'multiple' => true, |
217 | 217 | 'data-allow-clear' => 'false', |
@@ -221,15 +221,15 @@ discard block |
||
221 | 221 | ?> |
222 | 222 | </div> |
223 | 223 | <div class="col-sm-1 pt-2 pl-0"> |
224 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select all the items that are not allowed to use this discount.', 'invoicing' ); ?>"></span> |
|
224 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select all the items that are not allowed to use this discount.', 'invoicing'); ?>"></span> |
|
225 | 225 | </div> |
226 | 226 | </div> |
227 | - <?php do_action( 'wpinv_discount_form_excluded_items', $discount ); ?> |
|
227 | + <?php do_action('wpinv_discount_form_excluded_items', $discount); ?> |
|
228 | 228 | |
229 | - <?php do_action( 'wpinv_discount_form_before_start', $discount ); ?> |
|
229 | + <?php do_action('wpinv_discount_form_before_start', $discount); ?> |
|
230 | 230 | <div class="form-group row"> |
231 | 231 | <label for="wpinv_discount_start" class="col-sm-3 col-form-label"> |
232 | - <?php _e( 'Start Date', 'invoicing' );?> |
|
232 | + <?php _e('Start Date', 'invoicing'); ?> |
|
233 | 233 | </label> |
234 | 234 | <div class="col-sm-8"> |
235 | 235 | <?php |
@@ -238,10 +238,10 @@ discard block |
||
238 | 238 | 'type' => 'datepicker', |
239 | 239 | 'id' => 'wpinv_discount_start', |
240 | 240 | 'name' => 'wpinv_discount_start', |
241 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
241 | + 'label' => __('Start Date', 'invoicing'), |
|
242 | 242 | 'placeholder' => 'YYYY-MM-DD 00:00', |
243 | 243 | 'class' => 'form-control-sm', |
244 | - 'value' => $discount->get_start_date( 'edit' ), |
|
244 | + 'value' => $discount->get_start_date('edit'), |
|
245 | 245 | 'extra_attributes' => array( |
246 | 246 | 'data-enable-time' => 'true', |
247 | 247 | 'data-time_24hr' => 'true', |
@@ -252,15 +252,15 @@ discard block |
||
252 | 252 | ?> |
253 | 253 | </div> |
254 | 254 | <div class="col-sm-1 pt-2 pl-0"> |
255 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?>"></span> |
|
255 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?>"></span> |
|
256 | 256 | </div> |
257 | 257 | </div> |
258 | - <?php do_action( 'wpinv_discount_form_start', $discount ); ?> |
|
258 | + <?php do_action('wpinv_discount_form_start', $discount); ?> |
|
259 | 259 | |
260 | - <?php do_action( 'wpinv_discount_form_before_expiration', $discount ); ?> |
|
260 | + <?php do_action('wpinv_discount_form_before_expiration', $discount); ?> |
|
261 | 261 | <div class="form-group row"> |
262 | 262 | <label for="wpinv_discount_expiration" class="col-sm-3 col-form-label"> |
263 | - <?php _e( 'Expiration Date', 'invoicing' );?> |
|
263 | + <?php _e('Expiration Date', 'invoicing'); ?> |
|
264 | 264 | </label> |
265 | 265 | <div class="col-sm-8"> |
266 | 266 | <?php |
@@ -269,10 +269,10 @@ discard block |
||
269 | 269 | 'type' => 'datepicker', |
270 | 270 | 'id' => 'wpinv_discount_expiration', |
271 | 271 | 'name' => 'wpinv_discount_expiration', |
272 | - 'label' => __( 'Expiration Date', 'invoicing' ), |
|
272 | + 'label' => __('Expiration Date', 'invoicing'), |
|
273 | 273 | 'placeholder' => 'YYYY-MM-DD 00:00', |
274 | 274 | 'class' => 'form-control-sm', |
275 | - 'value' => $discount->get_end_date( 'edit' ), |
|
275 | + 'value' => $discount->get_end_date('edit'), |
|
276 | 276 | 'extra_attributes' => array( |
277 | 277 | 'data-enable-time' => 'true', |
278 | 278 | 'data-time_24hr' => 'true', |
@@ -285,27 +285,27 @@ discard block |
||
285 | 285 | ?> |
286 | 286 | </div> |
287 | 287 | <div class="col-sm-1 pt-2 pl-0"> |
288 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the date after which the discount will expire.', 'invoicing' ); ?>"></span> |
|
288 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the date after which the discount will expire.', 'invoicing'); ?>"></span> |
|
289 | 289 | </div> |
290 | 290 | </div> |
291 | - <?php do_action( 'wpinv_discount_form_expiration', $discount ); ?> |
|
291 | + <?php do_action('wpinv_discount_form_expiration', $discount); ?> |
|
292 | 292 | |
293 | - <?php do_action( 'wpinv_discount_form_before_min_total', $discount ); ?> |
|
293 | + <?php do_action('wpinv_discount_form_before_min_total', $discount); ?> |
|
294 | 294 | <div class="form-group row"> |
295 | 295 | <label for="wpinv_discount_min_total" class="col-sm-3 col-form-label"> |
296 | - <?php _e( 'Minimum Amount', 'invoicing' );?> |
|
296 | + <?php _e('Minimum Amount', 'invoicing'); ?> |
|
297 | 297 | </label> |
298 | 298 | <div class="col-sm-8"> |
299 | 299 | <div class="input-group input-group-sm"> |
300 | - <?php if( 'left' == $position ) : ?> |
|
300 | + <?php if ('left' == $position) : ?> |
|
301 | 301 | <div class="input-group-prepend"> |
302 | 302 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
303 | 303 | </div> |
304 | 304 | <?php endif; ?> |
305 | 305 | |
306 | - <input type="text" name="wpinv_discount_min_total" id="wpinv_discount_min_total" value="<?php echo esc_attr( $discount->get_minimum_total( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'No minimum', 'invoicing' ); ?>" class="form-control"> |
|
306 | + <input type="text" name="wpinv_discount_min_total" id="wpinv_discount_min_total" value="<?php echo esc_attr($discount->get_minimum_total('edit')); ?>" placeholder="<?php esc_attr_e('No minimum', 'invoicing'); ?>" class="form-control"> |
|
307 | 307 | |
308 | - <?php if( 'left' != $position ) : ?> |
|
308 | + <?php if ('left' != $position) : ?> |
|
309 | 309 | <div class="input-group-append"> |
310 | 310 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
311 | 311 | </div> |
@@ -313,27 +313,27 @@ discard block |
||
313 | 313 | </div> |
314 | 314 | </div> |
315 | 315 | <div class="col-sm-1 pt-2 pl-0"> |
316 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the minimum amount (including taxes) required to use this discount.', 'invoicing' ); ?>"></span> |
|
316 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the minimum amount (including taxes) required to use this discount.', 'invoicing'); ?>"></span> |
|
317 | 317 | </div> |
318 | 318 | </div> |
319 | - <?php do_action( 'wpinv_discount_form_min_total', $discount ); ?> |
|
319 | + <?php do_action('wpinv_discount_form_min_total', $discount); ?> |
|
320 | 320 | |
321 | - <?php do_action( 'wpinv_discount_form_before_max_total', $discount ); ?> |
|
321 | + <?php do_action('wpinv_discount_form_before_max_total', $discount); ?> |
|
322 | 322 | <div class="form-group row"> |
323 | 323 | <label for="wpinv_discount_max_total" class="col-sm-3 col-form-label"> |
324 | - <?php _e( 'Maximum Amount', 'invoicing' );?> |
|
324 | + <?php _e('Maximum Amount', 'invoicing'); ?> |
|
325 | 325 | </label> |
326 | 326 | <div class="col-sm-8"> |
327 | 327 | <div class="input-group input-group-sm"> |
328 | - <?php if( 'left' == $position ) : ?> |
|
328 | + <?php if ('left' == $position) : ?> |
|
329 | 329 | <div class="input-group-prepend"> |
330 | 330 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
331 | 331 | </div> |
332 | 332 | <?php endif; ?> |
333 | 333 | |
334 | - <input type="text" name="wpinv_discount_max_total" id="wpinv_discount_max_total" value="<?php echo esc_attr( $discount->get_maximum_total( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'No maximum', 'invoicing' ); ?>" class="form-control"> |
|
334 | + <input type="text" name="wpinv_discount_max_total" id="wpinv_discount_max_total" value="<?php echo esc_attr($discount->get_maximum_total('edit')); ?>" placeholder="<?php esc_attr_e('No maximum', 'invoicing'); ?>" class="form-control"> |
|
335 | 335 | |
336 | - <?php if( 'left' != $position ) : ?> |
|
336 | + <?php if ('left' != $position) : ?> |
|
337 | 337 | <div class="input-group-append"> |
338 | 338 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
339 | 339 | </div> |
@@ -341,30 +341,30 @@ discard block |
||
341 | 341 | </div> |
342 | 342 | </div> |
343 | 343 | <div class="col-sm-1 pt-2 pl-0"> |
344 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the maximum amount (including taxes) allowed when using this discount.', 'invoicing' ); ?>"></span> |
|
344 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the maximum amount (including taxes) allowed when using this discount.', 'invoicing'); ?>"></span> |
|
345 | 345 | </div> |
346 | 346 | </div> |
347 | - <?php do_action( 'wpinv_discount_form_before_max_total', $discount ); ?> |
|
347 | + <?php do_action('wpinv_discount_form_before_max_total', $discount); ?> |
|
348 | 348 | |
349 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $discount ); ?> |
|
349 | + <?php do_action('wpinv_discount_form_before_max_uses', $discount); ?> |
|
350 | 350 | <div class="form-group row"> |
351 | 351 | <label for="wpinv_discount_max_uses" class="col-sm-3 col-form-label"> |
352 | - <?php _e( 'Maximum Uses', 'invoicing' );?> |
|
352 | + <?php _e('Maximum Uses', 'invoicing'); ?> |
|
353 | 353 | </label> |
354 | 354 | <div class="col-sm-8"> |
355 | - <input type="text" value="<?php echo esc_attr( $discount->get_max_uses( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'Unlimited', 'invoicing' ); ?>" name="wpinv_discount_max_uses" id="wpinv_discount_max_uses" style="width: 100%;" /> |
|
355 | + <input type="text" value="<?php echo esc_attr($discount->get_max_uses('edit')); ?>" placeholder="<?php esc_attr_e('Unlimited', 'invoicing'); ?>" name="wpinv_discount_max_uses" id="wpinv_discount_max_uses" style="width: 100%;" /> |
|
356 | 356 | </div> |
357 | 357 | <div class="col-sm-1 pt-2 pl-0"> |
358 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the maximum number of times that this discount code can be used.', 'invoicing' ); ?>"></span> |
|
358 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the maximum number of times that this discount code can be used.', 'invoicing'); ?>"></span> |
|
359 | 359 | </div> |
360 | 360 | </div> |
361 | - <?php do_action( 'wpinv_discount_form_max_uses', $discount ); ?> |
|
361 | + <?php do_action('wpinv_discount_form_max_uses', $discount); ?> |
|
362 | 362 | |
363 | - <?php do_action( 'wpinv_discount_form_last', $discount ); ?> |
|
363 | + <?php do_action('wpinv_discount_form_last', $discount); ?> |
|
364 | 364 | |
365 | 365 | </div> |
366 | 366 | <?php |
367 | - do_action( 'wpinv_discount_form_bottom', $post ); |
|
367 | + do_action('wpinv_discount_form_bottom', $post); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -372,30 +372,30 @@ discard block |
||
372 | 372 | * |
373 | 373 | * @param int $post_id |
374 | 374 | */ |
375 | - public static function save( $post_id ) { |
|
375 | + public static function save($post_id) { |
|
376 | 376 | |
377 | 377 | // Prepare the discount. |
378 | - $discount = new WPInv_Discount( $post_id ); |
|
378 | + $discount = new WPInv_Discount($post_id); |
|
379 | 379 | |
380 | 380 | // Load new data. |
381 | 381 | $discount->set_props( |
382 | 382 | array( |
383 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
384 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
385 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
388 | - 'type' => isset( $_POST['wpinv_discount_type'] ) ? $_POST['wpinv_discount_type'] : null, |
|
389 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(), |
|
391 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
392 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
393 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
394 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
383 | + 'code' => isset($_POST['wpinv_discount_code']) ? $_POST['wpinv_discount_code'] : null, |
|
384 | + 'amount' => isset($_POST['wpinv_discount_amount']) ? $_POST['wpinv_discount_amount'] : null, |
|
385 | + 'start' => isset($_POST['wpinv_discount_start']) ? wpinv_clean($_POST['wpinv_discount_start']) : null, |
|
386 | + 'expiration' => isset($_POST['wpinv_discount_expiration']) ? wpinv_clean($_POST['wpinv_discount_expiration']) : null, |
|
387 | + 'is_single_use' => isset($_POST['wpinv_discount_single_use']), |
|
388 | + 'type' => isset($_POST['wpinv_discount_type']) ? $_POST['wpinv_discount_type'] : null, |
|
389 | + 'is_recurring' => isset($_POST['wpinv_discount_recurring']), |
|
390 | + 'items' => isset($_POST['wpinv_discount_items']) ? $_POST['wpinv_discount_items'] : array(), |
|
391 | + 'excluded_items' => isset($_POST['wpinv_discount_excluded_items']) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
392 | + 'max_uses' => isset($_POST['wpinv_discount_max_uses']) ? $_POST['wpinv_discount_max_uses'] : null, |
|
393 | + 'min_total' => isset($_POST['wpinv_discount_min_total']) ? $_POST['wpinv_discount_min_total'] : null, |
|
394 | + 'max_total' => isset($_POST['wpinv_discount_max_total']) ? $_POST['wpinv_discount_max_total'] : null, |
|
395 | 395 | ) |
396 | 396 | ); |
397 | 397 | |
398 | 398 | $discount->save(); |
399 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
399 | + do_action('getpaid_discount_metabox_save', $post_id, $discount); |
|
400 | 400 | } |
401 | 401 | } |