@@ -1,18 +1,18 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if (!defined('ABSPATH')) |
|
4 | 4 | die('-1'); |
5 | 5 | |
6 | -do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
|
6 | +do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin); |
|
7 | 7 | |
8 | -if ( ! empty( $message_body ) ) { |
|
9 | - echo wpautop( wptexturize( $message_body ) ); |
|
8 | +if (!empty($message_body)) { |
|
9 | + echo wpautop(wptexturize($message_body)); |
|
10 | 10 | } |
11 | 11 | |
12 | -do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin ); |
|
12 | +do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin); |
|
13 | 13 | |
14 | -do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin ); |
|
14 | +do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin); |
|
15 | 15 | |
16 | -do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin ); |
|
16 | +do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin); |
|
17 | 17 | |
18 | -do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin ); |
|
19 | 18 | \ No newline at end of file |
19 | +do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin); |
|
20 | 20 | \ No newline at end of file |
@@ -1,22 +1,22 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if (!defined('ABSPATH')) |
|
4 | 4 | die('-1'); |
5 | 5 | |
6 | -do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
|
6 | +do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin); |
|
7 | 7 | |
8 | -do_action( 'wpinv_email_before_note_details', $invoice, $email_type, $sent_to_admin, $customer_note ); |
|
8 | +do_action('wpinv_email_before_note_details', $invoice, $email_type, $sent_to_admin, $customer_note); |
|
9 | 9 | |
10 | -if ( ! empty( $message_body ) ) { |
|
11 | - echo wpautop( wptexturize( $message_body ) ); |
|
10 | +if (!empty($message_body)) { |
|
11 | + echo wpautop(wptexturize($message_body)); |
|
12 | 12 | } |
13 | 13 | |
14 | -do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin ); |
|
14 | +do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin); |
|
15 | 15 | |
16 | -do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin ); |
|
16 | +do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin); |
|
17 | 17 | |
18 | -do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin ); |
|
18 | +do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin); |
|
19 | 19 | |
20 | -do_action( 'wpinv_email_after_note_details', $invoice, $email_type, $sent_to_admin, $customer_note ); |
|
20 | +do_action('wpinv_email_after_note_details', $invoice, $email_type, $sent_to_admin, $customer_note); |
|
21 | 21 | |
22 | -do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin ); |
|
23 | 22 | \ No newline at end of file |
23 | +do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin); |
|
24 | 24 | \ No newline at end of file |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if (!defined('ABSPATH')) |
|
4 | 4 | die('-1'); |
5 | 5 | |
6 | -do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
|
6 | +do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin); |
|
7 | 7 | |
8 | -if ( ! empty( $message_body ) ) { |
|
9 | - echo wpautop( wptexturize( $message_body ) ); |
|
8 | +if (!empty($message_body)) { |
|
9 | + echo wpautop(wptexturize($message_body)); |
|
10 | 10 | } |
11 | 11 | |
12 | -do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin ); |
|
13 | 12 | \ No newline at end of file |
13 | +do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin); |
|
14 | 14 | \ No newline at end of file |
@@ -29,16 +29,16 @@ |
||
29 | 29 | <table class="table table-bordered table-hover table-responsive wpi-user-subscriptions"> |
30 | 30 | <thead> |
31 | 31 | <tr> |
32 | - <th class="sub-no"><span class="nobr"><?php _e( 'No.', 'invoicing' ); ?></span></th> |
|
33 | - <th class="sub-amount"><span class="nobr"><?php _e( 'Initial Amount', 'invoicing' ); ?></span></th> |
|
34 | - <th class="sub-cycle"><span class="nobr"><?php _e( 'Billing Cycle', 'invoicing' ); ?></span></th> |
|
35 | - <th class="sub-billed"><span class="nobr"><?php _e( 'Times Billed', 'invoicing' ); ?></span></th> |
|
36 | - <th class="sub-status"><span class="nobr"><?php _e( 'Status', 'invoicing' ); ?></span></th> |
|
37 | - <th class="sub-invoice"><span class="nobr"><?php _e( 'Invoice', 'invoicing' ); ?></span></th> |
|
38 | - <th class="sub-item"><span class="nobr"><?php _e( 'Item', 'invoicing' ); ?></span></th> |
|
39 | - <th class="sub-gateway"><span class="nobr"><?php _e( 'Gateway', 'invoicing' ); ?></span></th> |
|
40 | - <th class="sub-expiry"><span class="nobr"><?php _e( 'Expires On', 'invoicing' ); ?></span></th> |
|
41 | - <th class="sub-actions"><span class="nobr"><?php _e( 'Actions', 'invoicing' ); ?></span></th> |
|
32 | + <th class="sub-no"><span class="nobr"><?php _e('No.', 'invoicing'); ?></span></th> |
|
33 | + <th class="sub-amount"><span class="nobr"><?php _e('Initial Amount', 'invoicing'); ?></span></th> |
|
34 | + <th class="sub-cycle"><span class="nobr"><?php _e('Billing Cycle', 'invoicing'); ?></span></th> |
|
35 | + <th class="sub-billed"><span class="nobr"><?php _e('Times Billed', 'invoicing'); ?></span></th> |
|
36 | + <th class="sub-status"><span class="nobr"><?php _e('Status', 'invoicing'); ?></span></th> |
|
37 | + <th class="sub-invoice"><span class="nobr"><?php _e('Invoice', 'invoicing'); ?></span></th> |
|
38 | + <th class="sub-item"><span class="nobr"><?php _e('Item', 'invoicing'); ?></span></th> |
|
39 | + <th class="sub-gateway"><span class="nobr"><?php _e('Gateway', 'invoicing'); ?></span></th> |
|
40 | + <th class="sub-expiry"><span class="nobr"><?php _e('Expires On', 'invoicing'); ?></span></th> |
|
41 | + <th class="sub-actions"><span class="nobr"><?php _e('Actions', 'invoicing'); ?></span></th> |
|
42 | 42 | </tr> |
43 | 43 | </thead> |
44 | 44 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | * Hook in methods. |
15 | 15 | */ |
16 | 16 | public static function init() { |
17 | - add_action( 'init', array( __CLASS__, 'init_hooks' ), 0 ); |
|
18 | - add_action( 'admin_notices', array( __CLASS__, 'notices' ) ); |
|
17 | + add_action('init', array(__CLASS__, 'init_hooks'), 0); |
|
18 | + add_action('admin_notices', array(__CLASS__, 'notices')); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function init_hooks() { |
22 | - if ( false === ( $page_uris = get_transient( 'wpinv_cache_excluded_uris' ) ) ) { |
|
23 | - $checkout_page = wpinv_get_option( 'checkout_page', '' ); |
|
24 | - $success_page = wpinv_get_option( 'success_page', '' ); |
|
25 | - $failure_page = wpinv_get_option( 'failure_page', '' ); |
|
26 | - $history_page = wpinv_get_option( 'invoice_history_page', '' ); |
|
27 | - $subscr_page = wpinv_get_option( 'invoice_subscription_page', '' ); |
|
28 | - if ( empty( $checkout_page ) || empty( $success_page ) || empty( $failure_page ) || empty( $history_page ) || empty( $subscr_page ) ) { |
|
22 | + if (false === ($page_uris = get_transient('wpinv_cache_excluded_uris'))) { |
|
23 | + $checkout_page = wpinv_get_option('checkout_page', ''); |
|
24 | + $success_page = wpinv_get_option('success_page', ''); |
|
25 | + $failure_page = wpinv_get_option('failure_page', ''); |
|
26 | + $history_page = wpinv_get_option('invoice_history_page', ''); |
|
27 | + $subscr_page = wpinv_get_option('invoice_subscription_page', ''); |
|
28 | + if (empty($checkout_page) || empty($success_page) || empty($failure_page) || empty($history_page) || empty($subscr_page)) { |
|
29 | 29 | return; |
30 | 30 | } |
31 | 31 | |
@@ -39,34 +39,34 @@ discard block |
||
39 | 39 | $page_uris[] = 'p=' . $subscr_page; |
40 | 40 | |
41 | 41 | // Exclude permalinks |
42 | - $checkout_page = get_post( $checkout_page ); |
|
43 | - $success_page = get_post( $success_page ); |
|
44 | - $failure_page = get_post( $failure_page ); |
|
45 | - $history_page = get_post( $history_page ); |
|
46 | - $subscr_page = get_post( $subscr_page ); |
|
42 | + $checkout_page = get_post($checkout_page); |
|
43 | + $success_page = get_post($success_page); |
|
44 | + $failure_page = get_post($failure_page); |
|
45 | + $history_page = get_post($history_page); |
|
46 | + $subscr_page = get_post($subscr_page); |
|
47 | 47 | |
48 | - if ( ! is_null( $checkout_page ) ) { |
|
48 | + if (!is_null($checkout_page)) { |
|
49 | 49 | $page_uris[] = '/' . $checkout_page->post_name; |
50 | 50 | } |
51 | - if ( ! is_null( $success_page ) ) { |
|
51 | + if (!is_null($success_page)) { |
|
52 | 52 | $page_uris[] = '/' . $success_page->post_name; |
53 | 53 | } |
54 | - if ( ! is_null( $failure_page ) ) { |
|
54 | + if (!is_null($failure_page)) { |
|
55 | 55 | $page_uris[] = '/' . $failure_page->post_name; |
56 | 56 | } |
57 | - if ( ! is_null( $history_page ) ) { |
|
57 | + if (!is_null($history_page)) { |
|
58 | 58 | $page_uris[] = '/' . $history_page->post_name; |
59 | 59 | } |
60 | - if ( ! is_null( $subscr_page ) ) { |
|
60 | + if (!is_null($subscr_page)) { |
|
61 | 61 | $page_uris[] = '/' . $subscr_page->post_name; |
62 | 62 | } |
63 | 63 | |
64 | - set_transient( 'wpinv_cache_excluded_uris', $page_uris ); |
|
64 | + set_transient('wpinv_cache_excluded_uris', $page_uris); |
|
65 | 65 | } |
66 | 66 | |
67 | - if ( is_array( $page_uris ) ) { |
|
68 | - foreach( $page_uris as $uri ) { |
|
69 | - if ( strstr( $_SERVER['REQUEST_URI'], $uri ) ) { |
|
67 | + if (is_array($page_uris)) { |
|
68 | + foreach ($page_uris as $uri) { |
|
69 | + if (strstr($_SERVER['REQUEST_URI'], $uri)) { |
|
70 | 70 | self::nocache(); |
71 | 71 | break; |
72 | 72 | } |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | * @access private |
80 | 80 | */ |
81 | 81 | private static function nocache() { |
82 | - if ( ! defined( 'DONOTCACHEPAGE' ) ) { |
|
83 | - define( "DONOTCACHEPAGE", true ); |
|
82 | + if (!defined('DONOTCACHEPAGE')) { |
|
83 | + define("DONOTCACHEPAGE", true); |
|
84 | 84 | } |
85 | - if ( ! defined( 'DONOTCACHEOBJECT' ) ) { |
|
86 | - define( "DONOTCACHEOBJECT", true ); |
|
85 | + if (!defined('DONOTCACHEOBJECT')) { |
|
86 | + define("DONOTCACHEOBJECT", true); |
|
87 | 87 | } |
88 | - if ( ! defined( 'DONOTCACHEDB' ) ) { |
|
89 | - define( "DONOTCACHEDB", true ); |
|
88 | + if (!defined('DONOTCACHEDB')) { |
|
89 | + define("DONOTCACHEDB", true); |
|
90 | 90 | } |
91 | 91 | nocache_headers(); |
92 | 92 | } |
@@ -95,18 +95,18 @@ discard block |
||
95 | 95 | * notices function. |
96 | 96 | */ |
97 | 97 | public static function notices() { |
98 | - if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) ) { |
|
98 | + if (!function_exists('w3tc_pgcache_flush') || !function_exists('w3_instance')) { |
|
99 | 99 | return; |
100 | 100 | } |
101 | 101 | |
102 | - $config = w3_instance( 'W3_Config' ); |
|
103 | - $enabled = $config->get_integer( 'dbcache.enabled' ); |
|
104 | - $settings = array_map( 'trim', $config->get_array( 'dbcache.reject.sql' ) ); |
|
102 | + $config = w3_instance('W3_Config'); |
|
103 | + $enabled = $config->get_integer('dbcache.enabled'); |
|
104 | + $settings = array_map('trim', $config->get_array('dbcache.reject.sql')); |
|
105 | 105 | |
106 | - if ( $enabled && ! in_array( '_wp_session_', $settings ) ) { |
|
106 | + if ($enabled && !in_array('_wp_session_', $settings)) { |
|
107 | 107 | ?> |
108 | 108 | <div class="error"> |
109 | - <p><?php printf( __( 'In order for <strong>database caching</strong> to work with Invoicing you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'invoicing' ), '<code>_wp_session_</code>', admin_url( 'admin.php?page=w3tc_dbcache' ) ); ?></p> |
|
109 | + <p><?php printf(__('In order for <strong>database caching</strong> to work with Invoicing you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'invoicing'), '<code>_wp_session_</code>', admin_url('admin.php?page=w3tc_dbcache')); ?></p> |
|
110 | 110 | </div> |
111 | 111 | <?php |
112 | 112 | } |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_action( 'wpinv_manual_cc_form', '__return_false' ); |
|
5 | +add_action('wpinv_manual_cc_form', '__return_false'); |
|
6 | 6 | |
7 | -function wpinv_process_manual_payment( $purchase_data ) { |
|
8 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
9 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
7 | +function wpinv_process_manual_payment($purchase_data) { |
|
8 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
9 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | /* |
@@ -41,22 +41,22 @@ discard block |
||
41 | 41 | ); |
42 | 42 | |
43 | 43 | // Record the pending payment |
44 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
44 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
45 | 45 | |
46 | - if ( !empty( $invoice ) ) { |
|
47 | - wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() ); |
|
48 | - wpinv_update_payment_status( $invoice, 'publish' ); |
|
46 | + if (!empty($invoice)) { |
|
47 | + wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key()); |
|
48 | + wpinv_update_payment_status($invoice, 'publish'); |
|
49 | 49 | |
50 | 50 | // Empty the shopping cart |
51 | 51 | wpinv_empty_cart(); |
52 | 52 | |
53 | - do_action( 'wpinv_send_to_success_page', $invoice->ID, $payment_data ); |
|
53 | + do_action('wpinv_send_to_success_page', $invoice->ID, $payment_data); |
|
54 | 54 | |
55 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
55 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
56 | 56 | } else { |
57 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
57 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice); |
|
58 | 58 | // If errors are present, send the user back to the purchase page so they can be corrected |
59 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
59 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
60 | 60 | } |
61 | 61 | } |
62 | -add_action( 'wpinv_gateway_manual', 'wpinv_process_manual_payment' ); |
|
63 | 62 | \ No newline at end of file |
63 | +add_action('wpinv_gateway_manual', 'wpinv_process_manual_payment'); |
|
64 | 64 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly. |
3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * The Subscriptions DB Class |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | 'transaction_id' => '', |
69 | 69 | 'parent_payment_id' => 0, |
70 | 70 | 'product_id' => 0, |
71 | - 'created' => date( 'Y-m-d H:i:s' ), |
|
72 | - 'expiration' => date( 'Y-m-d H:i:s' ), |
|
71 | + 'created' => date('Y-m-d H:i:s'), |
|
72 | + 'expiration' => date('Y-m-d H:i:s'), |
|
73 | 73 | 'trial_period' => '', |
74 | 74 | 'status' => '', |
75 | 75 | 'profile_id' => '', |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | * @access public |
83 | 83 | * @since 1.0.0 |
84 | 84 | */ |
85 | - public function get_subscriptions( $args = array() ) { |
|
85 | + public function get_subscriptions($args = array()) { |
|
86 | 86 | global $wpdb; |
87 | 87 | |
88 | 88 | $defaults = array( |
89 | - 'number' => get_option( 'posts_per_page' ), |
|
89 | + 'number' => get_option('posts_per_page'), |
|
90 | 90 | 'offset' => 0, |
91 | 91 | 'search' => '', |
92 | 92 | 'customer_id' => 0, |
@@ -94,21 +94,21 @@ discard block |
||
94 | 94 | 'order' => 'DESC' |
95 | 95 | ); |
96 | 96 | |
97 | - $args = wp_parse_args( $args, $defaults ); |
|
97 | + $args = wp_parse_args($args, $defaults); |
|
98 | 98 | |
99 | - if( $args['number'] < 1 ) { |
|
99 | + if ($args['number'] < 1) { |
|
100 | 100 | $args['number'] = 999999999999; |
101 | 101 | } |
102 | 102 | |
103 | 103 | $where = ' WHERE 1=1 '; |
104 | 104 | |
105 | 105 | // specific customers |
106 | - if( ! empty( $args['id'] ) ) { |
|
106 | + if (!empty($args['id'])) { |
|
107 | 107 | |
108 | - if( is_array( $args['id'] ) ) { |
|
109 | - $ids = implode( ',', array_map('intval', $args['id'] ) ); |
|
108 | + if (is_array($args['id'])) { |
|
109 | + $ids = implode(',', array_map('intval', $args['id'])); |
|
110 | 110 | } else { |
111 | - $ids = intval( $args['id'] ); |
|
111 | + $ids = intval($args['id']); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | $where .= " AND `id` IN( {$ids} ) "; |
@@ -116,12 +116,12 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | // Specific products |
119 | - if( ! empty( $args['product_id'] ) ) { |
|
119 | + if (!empty($args['product_id'])) { |
|
120 | 120 | |
121 | - if( is_array( $args['product_id'] ) ) { |
|
122 | - $product_ids = implode( ',', array_map('intval', $args['product_id'] ) ); |
|
121 | + if (is_array($args['product_id'])) { |
|
122 | + $product_ids = implode(',', array_map('intval', $args['product_id'])); |
|
123 | 123 | } else { |
124 | - $product_ids = intval( $args['product_id'] ); |
|
124 | + $product_ids = intval($args['product_id']); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | $where .= " AND `product_id` IN( {$product_ids} ) "; |
@@ -129,12 +129,12 @@ discard block |
||
129 | 129 | } |
130 | 130 | |
131 | 131 | // Specific parent payments |
132 | - if( ! empty( $args['parent_payment_id'] ) ) { |
|
132 | + if (!empty($args['parent_payment_id'])) { |
|
133 | 133 | |
134 | - if( is_array( $args['parent_payment_id'] ) ) { |
|
135 | - $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) ); |
|
134 | + if (is_array($args['parent_payment_id'])) { |
|
135 | + $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id'])); |
|
136 | 136 | } else { |
137 | - $parent_payment_ids = intval( $args['parent_payment_id'] ); |
|
137 | + $parent_payment_ids = intval($args['parent_payment_id']); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) "; |
@@ -142,12 +142,12 @@ discard block |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | // Specific transaction IDs |
145 | - if( ! empty( $args['transaction_id'] ) ) { |
|
145 | + if (!empty($args['transaction_id'])) { |
|
146 | 146 | |
147 | - if( is_array( $args['transaction_id'] ) ) { |
|
148 | - $transaction_ids = implode( "','", array_map('sanitize_text_field', $args['transaction_id'] ) ); |
|
147 | + if (is_array($args['transaction_id'])) { |
|
148 | + $transaction_ids = implode("','", array_map('sanitize_text_field', $args['transaction_id'])); |
|
149 | 149 | } else { |
150 | - $transaction_ids = sanitize_text_field( $args['transaction_id'] ); |
|
150 | + $transaction_ids = sanitize_text_field($args['transaction_id']); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | $where .= " AND `transaction_id` IN ( '{$transaction_ids}' ) "; |
@@ -155,12 +155,12 @@ discard block |
||
155 | 155 | } |
156 | 156 | |
157 | 157 | // Subscriptoins for specific customers |
158 | - if( ! empty( $args['customer_id'] ) ) { |
|
158 | + if (!empty($args['customer_id'])) { |
|
159 | 159 | |
160 | - if( is_array( $args['customer_id'] ) ) { |
|
161 | - $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) ); |
|
160 | + if (is_array($args['customer_id'])) { |
|
161 | + $customer_ids = implode(',', array_map('intval', $args['customer_id'])); |
|
162 | 162 | } else { |
163 | - $customer_ids = intval( $args['customer_id'] ); |
|
163 | + $customer_ids = intval($args['customer_id']); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | $where .= " AND `customer_id` IN( {$customer_ids} ) "; |
@@ -168,12 +168,12 @@ discard block |
||
168 | 168 | } |
169 | 169 | |
170 | 170 | // Subscriptions for specific profile IDs |
171 | - if( ! empty( $args['profile_id'] ) ) { |
|
171 | + if (!empty($args['profile_id'])) { |
|
172 | 172 | |
173 | - if( is_array( $args['profile_id'] ) ) { |
|
174 | - $profile_ids = implode( "','", array_map('sanitize_text_field', $args['profile_id'] ) ); |
|
173 | + if (is_array($args['profile_id'])) { |
|
174 | + $profile_ids = implode("','", array_map('sanitize_text_field', $args['profile_id'])); |
|
175 | 175 | } else { |
176 | - $profile_ids = sanitize_text_field( $args['profile_id'] ); |
|
176 | + $profile_ids = sanitize_text_field($args['profile_id']); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | $where .= " AND `profile_id` IN( '{$profile_ids}' ) "; |
@@ -181,12 +181,12 @@ discard block |
||
181 | 181 | } |
182 | 182 | |
183 | 183 | // Subscriptions for specific statuses |
184 | - if( ! empty( $args['status'] ) ) { |
|
184 | + if (!empty($args['status'])) { |
|
185 | 185 | |
186 | - if( is_array( $args['status'] ) ) { |
|
187 | - $statuses = implode( "','", array_map( 'sanitize_text_field', $args['status'] ) ); |
|
186 | + if (is_array($args['status'])) { |
|
187 | + $statuses = implode("','", array_map('sanitize_text_field', $args['status'])); |
|
188 | 188 | } else { |
189 | - $statuses = sanitize_text_field( $args['status'] ); |
|
189 | + $statuses = sanitize_text_field($args['status']); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | $where .= " AND `status` IN( '{$statuses}' ) "; |
@@ -194,21 +194,21 @@ discard block |
||
194 | 194 | } |
195 | 195 | |
196 | 196 | // Subscriptions created for a specific date or in a date range |
197 | - if( ! empty( $args['date'] ) ) { |
|
197 | + if (!empty($args['date'])) { |
|
198 | 198 | |
199 | - if( is_array( $args['date'] ) ) { |
|
199 | + if (is_array($args['date'])) { |
|
200 | 200 | |
201 | - if( ! empty( $args['date']['start'] ) ) { |
|
201 | + if (!empty($args['date']['start'])) { |
|
202 | 202 | |
203 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) ); |
|
203 | + $start = date('Y-m-d H:i:s', strtotime($args['date']['start'])); |
|
204 | 204 | |
205 | 205 | $where .= " AND `created` >= '{$start}'"; |
206 | 206 | |
207 | 207 | } |
208 | 208 | |
209 | - if( ! empty( $args['date']['end'] ) ) { |
|
209 | + if (!empty($args['date']['end'])) { |
|
210 | 210 | |
211 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) ); |
|
211 | + $end = date('Y-m-d H:i:s', strtotime($args['date']['end'])); |
|
212 | 212 | |
213 | 213 | $where .= " AND `created` <= '{$end}'"; |
214 | 214 | |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | |
217 | 217 | } else { |
218 | 218 | |
219 | - $year = date( 'Y', strtotime( $args['date'] ) ); |
|
220 | - $month = date( 'm', strtotime( $args['date'] ) ); |
|
221 | - $day = date( 'd', strtotime( $args['date'] ) ); |
|
219 | + $year = date('Y', strtotime($args['date'])); |
|
220 | + $month = date('m', strtotime($args['date'])); |
|
221 | + $day = date('d', strtotime($args['date'])); |
|
222 | 222 | |
223 | 223 | $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )"; |
224 | 224 | } |
@@ -226,21 +226,21 @@ discard block |
||
226 | 226 | } |
227 | 227 | |
228 | 228 | // Subscriptions with a specific expiration date or in an expiration date range |
229 | - if( ! empty( $args['expiration'] ) ) { |
|
229 | + if (!empty($args['expiration'])) { |
|
230 | 230 | |
231 | - if( is_array( $args['expiration'] ) ) { |
|
231 | + if (is_array($args['expiration'])) { |
|
232 | 232 | |
233 | - if( ! empty( $args['expiration']['start'] ) ) { |
|
233 | + if (!empty($args['expiration']['start'])) { |
|
234 | 234 | |
235 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) ); |
|
235 | + $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start'])); |
|
236 | 236 | |
237 | 237 | $where .= " AND `expiration` >= '{$start}'"; |
238 | 238 | |
239 | 239 | } |
240 | 240 | |
241 | - if( ! empty( $args['expiration']['end'] ) ) { |
|
241 | + if (!empty($args['expiration']['end'])) { |
|
242 | 242 | |
243 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) ); |
|
243 | + $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end'])); |
|
244 | 244 | |
245 | 245 | $where .= " AND `expiration` <= '{$end}'"; |
246 | 246 | |
@@ -248,73 +248,73 @@ discard block |
||
248 | 248 | |
249 | 249 | } else { |
250 | 250 | |
251 | - $year = date( 'Y', strtotime( $args['expiration'] ) ); |
|
252 | - $month = date( 'm', strtotime( $args['expiration'] ) ); |
|
253 | - $day = date( 'd', strtotime( $args['expiration'] ) ); |
|
251 | + $year = date('Y', strtotime($args['expiration'])); |
|
252 | + $month = date('m', strtotime($args['expiration'])); |
|
253 | + $day = date('d', strtotime($args['expiration'])); |
|
254 | 254 | |
255 | 255 | $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )"; |
256 | 256 | } |
257 | 257 | |
258 | 258 | } |
259 | 259 | |
260 | - if ( ! empty( $args['search'] ) ) { |
|
260 | + if (!empty($args['search'])) { |
|
261 | 261 | |
262 | - if( false !== strpos( 'id:', $args['search'] ) ) { |
|
262 | + if (false !== strpos('id:', $args['search'])) { |
|
263 | 263 | |
264 | - $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) ); |
|
265 | - $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'"; |
|
264 | + $args['search'] = trim(str_replace('id:', '', $args['search'])); |
|
265 | + $where .= " AND `id` = '" . esc_sql($args['search']) . "'"; |
|
266 | 266 | |
267 | - } else if( false !== strpos( $args['search'], 'txn:' ) ) { |
|
267 | + } else if (false !== strpos($args['search'], 'txn:')) { |
|
268 | 268 | |
269 | - $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) ); |
|
270 | - $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
269 | + $args['search'] = trim(str_replace('txn:', '', $args['search'])); |
|
270 | + $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'"; |
|
271 | 271 | |
272 | - } else if( false !== strpos( $args['search'], 'profile_id:' ) ) { |
|
272 | + } else if (false !== strpos($args['search'], 'profile_id:')) { |
|
273 | 273 | |
274 | - $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) ); |
|
275 | - $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
274 | + $args['search'] = trim(str_replace('profile_id:', '', $args['search'])); |
|
275 | + $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'"; |
|
276 | 276 | |
277 | - } else if( false !== strpos( $args['search'], 'product_id:' ) ) { |
|
277 | + } else if (false !== strpos($args['search'], 'product_id:')) { |
|
278 | 278 | |
279 | - $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) ); |
|
280 | - $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
279 | + $args['search'] = trim(str_replace('product_id:', '', $args['search'])); |
|
280 | + $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'"; |
|
281 | 281 | |
282 | - } else if( false !== strpos( $args['search'], 'customer_id:' ) ) { |
|
282 | + } else if (false !== strpos($args['search'], 'customer_id:')) { |
|
283 | 283 | |
284 | - $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) ); |
|
285 | - $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
284 | + $args['search'] = trim(str_replace('customer_id:', '', $args['search'])); |
|
285 | + $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'"; |
|
286 | 286 | |
287 | 287 | } else { |
288 | 288 | |
289 | - $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )"; |
|
289 | + $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )"; |
|
290 | 290 | |
291 | 291 | } |
292 | 292 | |
293 | 293 | } |
294 | 294 | |
295 | - $args['orderby'] = ! array_key_exists( $args['orderby'], $this->get_columns() ) ? 'id' : $args['orderby']; |
|
295 | + $args['orderby'] = !array_key_exists($args['orderby'], $this->get_columns()) ? 'id' : $args['orderby']; |
|
296 | 296 | |
297 | - if( 'amount' == $args['orderby'] ) { |
|
297 | + if ('amount' == $args['orderby']) { |
|
298 | 298 | $args['orderby'] = 'amount+0'; |
299 | 299 | } |
300 | 300 | |
301 | - $cache_key = md5( 'wpinv_subscriptions_' . serialize( $args ) ); |
|
301 | + $cache_key = md5('wpinv_subscriptions_' . serialize($args)); |
|
302 | 302 | |
303 | - $subscriptions = wp_cache_get( $cache_key, 'subscriptions' ); |
|
303 | + $subscriptions = wp_cache_get($cache_key, 'subscriptions'); |
|
304 | 304 | |
305 | - $args['orderby'] = esc_sql( $args['orderby'] ); |
|
306 | - $args['order'] = esc_sql( $args['order'] ); |
|
305 | + $args['orderby'] = esc_sql($args['orderby']); |
|
306 | + $args['order'] = esc_sql($args['order']); |
|
307 | 307 | |
308 | - if( $subscriptions === false ) { |
|
309 | - $subscriptions = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint( $args['offset'] ), absint( $args['number'] ) ), OBJECT ); |
|
308 | + if ($subscriptions === false) { |
|
309 | + $subscriptions = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint($args['offset']), absint($args['number'])), OBJECT); |
|
310 | 310 | |
311 | - if( ! empty( $subscriptions ) ) { |
|
311 | + if (!empty($subscriptions)) { |
|
312 | 312 | |
313 | - foreach( $subscriptions as $key => $subscription ) { |
|
314 | - $subscriptions[ $key ] = new WPInv_Subscription( $subscription ); |
|
313 | + foreach ($subscriptions as $key => $subscription) { |
|
314 | + $subscriptions[$key] = new WPInv_Subscription($subscription); |
|
315 | 315 | } |
316 | 316 | |
317 | - wp_cache_set( $cache_key, $subscriptions, 'subscriptions', 3600 ); |
|
317 | + wp_cache_set($cache_key, $subscriptions, 'subscriptions', 3600); |
|
318 | 318 | |
319 | 319 | } |
320 | 320 | |
@@ -329,19 +329,19 @@ discard block |
||
329 | 329 | * @access public |
330 | 330 | * @since 1.0.0 |
331 | 331 | */ |
332 | - public function count( $args = array() ) { |
|
332 | + public function count($args = array()) { |
|
333 | 333 | |
334 | 334 | global $wpdb; |
335 | 335 | |
336 | 336 | $where = ' WHERE 1=1 '; |
337 | 337 | |
338 | 338 | // specific customers |
339 | - if( ! empty( $args['id'] ) ) { |
|
339 | + if (!empty($args['id'])) { |
|
340 | 340 | |
341 | - if( is_array( $args['id'] ) ) { |
|
342 | - $ids = implode( ',', array_map('intval', $args['id'] ) ); |
|
341 | + if (is_array($args['id'])) { |
|
342 | + $ids = implode(',', array_map('intval', $args['id'])); |
|
343 | 343 | } else { |
344 | - $ids = intval( $args['id'] ); |
|
344 | + $ids = intval($args['id']); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | $where .= " AND `id` IN( {$ids} ) "; |
@@ -349,12 +349,12 @@ discard block |
||
349 | 349 | } |
350 | 350 | |
351 | 351 | // Specific products |
352 | - if( ! empty( $args['product_id'] ) ) { |
|
352 | + if (!empty($args['product_id'])) { |
|
353 | 353 | |
354 | - if( is_array( $args['product_id'] ) ) { |
|
355 | - $product_ids = implode( ',', array_map('intval', $args['product_id'] ) ); |
|
354 | + if (is_array($args['product_id'])) { |
|
355 | + $product_ids = implode(',', array_map('intval', $args['product_id'])); |
|
356 | 356 | } else { |
357 | - $product_ids = intval( $args['product_id'] ); |
|
357 | + $product_ids = intval($args['product_id']); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | $where .= " AND `product_id` IN( {$product_ids} ) "; |
@@ -362,12 +362,12 @@ discard block |
||
362 | 362 | } |
363 | 363 | |
364 | 364 | // Specific parent payments |
365 | - if( ! empty( $args['parent_payment_id'] ) ) { |
|
365 | + if (!empty($args['parent_payment_id'])) { |
|
366 | 366 | |
367 | - if( is_array( $args['parent_payment_id'] ) ) { |
|
368 | - $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) ); |
|
367 | + if (is_array($args['parent_payment_id'])) { |
|
368 | + $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id'])); |
|
369 | 369 | } else { |
370 | - $parent_payment_ids = intval( $args['parent_payment_id'] ); |
|
370 | + $parent_payment_ids = intval($args['parent_payment_id']); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) "; |
@@ -375,12 +375,12 @@ discard block |
||
375 | 375 | } |
376 | 376 | |
377 | 377 | // Subscriptoins for specific customers |
378 | - if( ! empty( $args['customer_id'] ) ) { |
|
378 | + if (!empty($args['customer_id'])) { |
|
379 | 379 | |
380 | - if( is_array( $args['customer_id'] ) ) { |
|
381 | - $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) ); |
|
380 | + if (is_array($args['customer_id'])) { |
|
381 | + $customer_ids = implode(',', array_map('intval', $args['customer_id'])); |
|
382 | 382 | } else { |
383 | - $customer_ids = intval( $args['customer_id'] ); |
|
383 | + $customer_ids = intval($args['customer_id']); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | $where .= " AND `customer_id` IN( {$customer_ids} ) "; |
@@ -388,12 +388,12 @@ discard block |
||
388 | 388 | } |
389 | 389 | |
390 | 390 | // Subscriptions for specific profile IDs |
391 | - if( ! empty( $args['profile_id'] ) ) { |
|
391 | + if (!empty($args['profile_id'])) { |
|
392 | 392 | |
393 | - if( is_array( $args['profile_id'] ) ) { |
|
394 | - $profile_ids = implode( ',', array_map('intval', $args['profile_id'] ) ); |
|
393 | + if (is_array($args['profile_id'])) { |
|
394 | + $profile_ids = implode(',', array_map('intval', $args['profile_id'])); |
|
395 | 395 | } else { |
396 | - $profile_ids = intval( $args['profile_id'] ); |
|
396 | + $profile_ids = intval($args['profile_id']); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | $where .= " AND `profile_id` IN( {$profile_ids} ) "; |
@@ -401,12 +401,12 @@ discard block |
||
401 | 401 | } |
402 | 402 | |
403 | 403 | // Specific transaction IDs |
404 | - if( ! empty( $args['transaction_id'] ) ) { |
|
404 | + if (!empty($args['transaction_id'])) { |
|
405 | 405 | |
406 | - if( is_array( $args['transaction_id'] ) ) { |
|
407 | - $transaction_ids = implode( ',', array_map('sanitize_text_field', $args['transaction_id'] ) ); |
|
406 | + if (is_array($args['transaction_id'])) { |
|
407 | + $transaction_ids = implode(',', array_map('sanitize_text_field', $args['transaction_id'])); |
|
408 | 408 | } else { |
409 | - $transaction_ids = sanitize_text_field( $args['transaction_id'] ); |
|
409 | + $transaction_ids = sanitize_text_field($args['transaction_id']); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | $where .= " AND `transaction_id` IN( {$transaction_ids} ) "; |
@@ -414,10 +414,10 @@ discard block |
||
414 | 414 | } |
415 | 415 | |
416 | 416 | // Subscriptions for specific statuses |
417 | - if( ! empty( $args['status'] ) ) { |
|
417 | + if (!empty($args['status'])) { |
|
418 | 418 | |
419 | - if( is_array( $args['status'] ) ) { |
|
420 | - $statuses = implode( ',', $args['status'] ); |
|
419 | + if (is_array($args['status'])) { |
|
420 | + $statuses = implode(',', $args['status']); |
|
421 | 421 | $where .= " AND `status` IN( {$statuses} ) "; |
422 | 422 | } else { |
423 | 423 | $statuses = $args['status']; |
@@ -429,21 +429,21 @@ discard block |
||
429 | 429 | } |
430 | 430 | |
431 | 431 | // Subscriptions created for a specific date or in a date range |
432 | - if( ! empty( $args['date'] ) ) { |
|
432 | + if (!empty($args['date'])) { |
|
433 | 433 | |
434 | - if( is_array( $args['date'] ) ) { |
|
434 | + if (is_array($args['date'])) { |
|
435 | 435 | |
436 | - if( ! empty( $args['date']['start'] ) ) { |
|
436 | + if (!empty($args['date']['start'])) { |
|
437 | 437 | |
438 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) ); |
|
438 | + $start = date('Y-m-d H:i:s', strtotime($args['date']['start'])); |
|
439 | 439 | |
440 | 440 | $where .= " AND `created` >= '{$start}'"; |
441 | 441 | |
442 | 442 | } |
443 | 443 | |
444 | - if( ! empty( $args['date']['end'] ) ) { |
|
444 | + if (!empty($args['date']['end'])) { |
|
445 | 445 | |
446 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) ); |
|
446 | + $end = date('Y-m-d H:i:s', strtotime($args['date']['end'])); |
|
447 | 447 | |
448 | 448 | $where .= " AND `created` <= '{$end}'"; |
449 | 449 | |
@@ -451,9 +451,9 @@ discard block |
||
451 | 451 | |
452 | 452 | } else { |
453 | 453 | |
454 | - $year = date( 'Y', strtotime( $args['date'] ) ); |
|
455 | - $month = date( 'm', strtotime( $args['date'] ) ); |
|
456 | - $day = date( 'd', strtotime( $args['date'] ) ); |
|
454 | + $year = date('Y', strtotime($args['date'])); |
|
455 | + $month = date('m', strtotime($args['date'])); |
|
456 | + $day = date('d', strtotime($args['date'])); |
|
457 | 457 | |
458 | 458 | $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )"; |
459 | 459 | } |
@@ -461,21 +461,21 @@ discard block |
||
461 | 461 | } |
462 | 462 | |
463 | 463 | // Subscriptions with a specific expiration date or in an expiration date range |
464 | - if( ! empty( $args['expiration'] ) ) { |
|
464 | + if (!empty($args['expiration'])) { |
|
465 | 465 | |
466 | - if( is_array( $args['expiration'] ) ) { |
|
466 | + if (is_array($args['expiration'])) { |
|
467 | 467 | |
468 | - if( ! empty( $args['expiration']['start'] ) ) { |
|
468 | + if (!empty($args['expiration']['start'])) { |
|
469 | 469 | |
470 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) ); |
|
470 | + $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start'])); |
|
471 | 471 | |
472 | 472 | $where .= " AND `expiration` >= '{$start}'"; |
473 | 473 | |
474 | 474 | } |
475 | 475 | |
476 | - if( ! empty( $args['expiration']['end'] ) ) { |
|
476 | + if (!empty($args['expiration']['end'])) { |
|
477 | 477 | |
478 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) ); |
|
478 | + $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end'])); |
|
479 | 479 | |
480 | 480 | $where .= " AND `expiration` <= '{$end}'"; |
481 | 481 | |
@@ -483,64 +483,64 @@ discard block |
||
483 | 483 | |
484 | 484 | } else { |
485 | 485 | |
486 | - $year = date( 'Y', strtotime( $args['expiration'] ) ); |
|
487 | - $month = date( 'm', strtotime( $args['expiration'] ) ); |
|
488 | - $day = date( 'd', strtotime( $args['expiration'] ) ); |
|
486 | + $year = date('Y', strtotime($args['expiration'])); |
|
487 | + $month = date('m', strtotime($args['expiration'])); |
|
488 | + $day = date('d', strtotime($args['expiration'])); |
|
489 | 489 | |
490 | 490 | $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )"; |
491 | 491 | } |
492 | 492 | |
493 | 493 | } |
494 | 494 | |
495 | - if ( ! empty( $args['search'] ) ) { |
|
495 | + if (!empty($args['search'])) { |
|
496 | 496 | |
497 | - if( false !== strpos( 'id:', $args['search'] ) ) { |
|
497 | + if (false !== strpos('id:', $args['search'])) { |
|
498 | 498 | |
499 | - $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) ); |
|
500 | - $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'"; |
|
499 | + $args['search'] = trim(str_replace('id:', '', $args['search'])); |
|
500 | + $where .= " AND `id` = '" . esc_sql($args['search']) . "'"; |
|
501 | 501 | |
502 | - } else if( false !== strpos( $args['search'], 'txn:' ) ) { |
|
502 | + } else if (false !== strpos($args['search'], 'txn:')) { |
|
503 | 503 | |
504 | - $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) ); |
|
505 | - $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
504 | + $args['search'] = trim(str_replace('txn:', '', $args['search'])); |
|
505 | + $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'"; |
|
506 | 506 | |
507 | - } else if( false !== strpos( $args['search'], 'profile_id:' ) ) { |
|
507 | + } else if (false !== strpos($args['search'], 'profile_id:')) { |
|
508 | 508 | |
509 | - $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) ); |
|
510 | - $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
509 | + $args['search'] = trim(str_replace('profile_id:', '', $args['search'])); |
|
510 | + $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'"; |
|
511 | 511 | |
512 | - } else if( false !== strpos( $args['search'], 'product_id:' ) ) { |
|
512 | + } else if (false !== strpos($args['search'], 'product_id:')) { |
|
513 | 513 | |
514 | - $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) ); |
|
515 | - $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
514 | + $args['search'] = trim(str_replace('product_id:', '', $args['search'])); |
|
515 | + $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'"; |
|
516 | 516 | |
517 | - } else if( false !== strpos( $args['search'], 'customer_id:' ) ) { |
|
517 | + } else if (false !== strpos($args['search'], 'customer_id:')) { |
|
518 | 518 | |
519 | - $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) ); |
|
520 | - $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
519 | + $args['search'] = trim(str_replace('customer_id:', '', $args['search'])); |
|
520 | + $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'"; |
|
521 | 521 | |
522 | 522 | } else { |
523 | 523 | |
524 | - $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )"; |
|
524 | + $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )"; |
|
525 | 525 | |
526 | 526 | } |
527 | 527 | |
528 | 528 | } |
529 | 529 | |
530 | - $cache_key = md5( 'wpinv_subscriptions_count' . serialize( $args ) ); |
|
530 | + $cache_key = md5('wpinv_subscriptions_count' . serialize($args)); |
|
531 | 531 | |
532 | - $count = wp_cache_get( $cache_key, 'subscriptions' ); |
|
532 | + $count = wp_cache_get($cache_key, 'subscriptions'); |
|
533 | 533 | |
534 | - if( $count === false ) { |
|
534 | + if ($count === false) { |
|
535 | 535 | |
536 | 536 | $sql = "SELECT COUNT($this->primary_key) FROM " . $this->table_name . "{$where};"; |
537 | - $count = $wpdb->get_var( $sql ); |
|
537 | + $count = $wpdb->get_var($sql); |
|
538 | 538 | |
539 | - wp_cache_set( $cache_key, $count, 'subscriptions', 3600 ); |
|
539 | + wp_cache_set($cache_key, $count, 'subscriptions', 3600); |
|
540 | 540 | |
541 | 541 | } |
542 | 542 | |
543 | - return absint( $count ); |
|
543 | + return absint($count); |
|
544 | 544 | |
545 | 545 | } |
546 | 546 | |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | public function create_table() { |
554 | 554 | global $wpdb; |
555 | 555 | |
556 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
556 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
557 | 557 | |
558 | 558 | $sql = "CREATE TABLE " . $this->table_name . " ( |
559 | 559 | id bigint(20) NOT NULL AUTO_INCREMENT, |
@@ -578,9 +578,9 @@ discard block |
||
578 | 578 | KEY customer_and_status ( customer_id, status) |
579 | 579 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
580 | 580 | |
581 | - dbDelta( $sql ); |
|
581 | + dbDelta($sql); |
|
582 | 582 | |
583 | - update_option( $this->table_name . '_db_version', $this->version ); |
|
583 | + update_option($this->table_name . '_db_version', $this->version); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | } |
587 | 587 | \ No newline at end of file |
@@ -8,11 +8,11 @@ discard block |
||
8 | 8 | |
9 | 9 | |
10 | 10 | // Exit if accessed directly |
11 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
11 | +if (!defined('ABSPATH')) exit; |
|
12 | 12 | |
13 | 13 | |
14 | 14 | // Load WP_List_Table if not loaded |
15 | -if( ! class_exists( 'WP_List_Table' ) ) { |
|
15 | +if (!class_exists('WP_List_Table')) { |
|
16 | 16 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
17 | 17 | } |
18 | 18 | |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | public $pending_count = 0; |
36 | 36 | public $expired_count = 0; |
37 | 37 | public $completed_count = 0; |
38 | - public $trialling_count = 0; |
|
38 | + public $trialling_count = 0; |
|
39 | 39 | public $cancelled_count = 0; |
40 | 40 | public $failing_count = 0; |
41 | 41 | |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | * @since 1.0.0 |
47 | 47 | * @return void |
48 | 48 | */ |
49 | - function __construct(){ |
|
49 | + function __construct() { |
|
50 | 50 | global $status, $page; |
51 | 51 | |
52 | 52 | // Set parent defaults |
53 | - parent::__construct( array( |
|
53 | + parent::__construct(array( |
|
54 | 54 | 'singular' => 'subscription', |
55 | 55 | 'plural' => 'subscriptions', |
56 | 56 | 'ajax' => false |
57 | - ) ); |
|
57 | + )); |
|
58 | 58 | |
59 | 59 | $this->get_subscription_counts(); |
60 | 60 | |
@@ -69,28 +69,28 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function get_views() { |
71 | 71 | |
72 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
|
73 | - $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
72 | + $current = isset($_GET['status']) ? $_GET['status'] : ''; |
|
73 | + $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
74 | 74 | $active_count = ' <span class="count">(' . $this->active_count . ')</span>'; |
75 | 75 | $pending_count = ' <span class="count">(' . $this->pending_count . ')</span>'; |
76 | - $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
76 | + $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
77 | 77 | $completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; |
78 | - $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
79 | - $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
80 | - $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
78 | + $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
79 | + $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
80 | + $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
81 | 81 | |
82 | 82 | $views = array( |
83 | - 'all' => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), |
|
84 | - 'active' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), |
|
85 | - 'pending' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), |
|
86 | - 'expired' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), |
|
87 | - 'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), |
|
88 | - 'trialling' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), |
|
89 | - 'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), |
|
90 | - 'failing' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), |
|
83 | + 'all' => sprintf('<a href="%s"%s>%s</a>', remove_query_arg(array('status', 'paged')), $current === 'all' || $current == '' ? ' class="current"' : '', __('All', 'invoicing') . $total_count), |
|
84 | + 'active' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'active', 'paged' => FALSE)), $current === 'active' ? ' class="current"' : '', __('Active', 'invoicing') . $active_count), |
|
85 | + 'pending' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'pending', 'paged' => FALSE)), $current === 'pending' ? ' class="current"' : '', __('Pending', 'invoicing') . $pending_count), |
|
86 | + 'expired' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'expired', 'paged' => FALSE)), $current === 'expired' ? ' class="current"' : '', __('Expired', 'invoicing') . $expired_count), |
|
87 | + 'completed' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'completed', 'paged' => FALSE)), $current === 'completed' ? ' class="current"' : '', __('Completed', 'invoicing') . $completed_count), |
|
88 | + 'trialling' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'trialling', 'paged' => FALSE)), $current === 'trialling' ? ' class="current"' : '', __('Trialling', 'invoicing') . $trialling_count), |
|
89 | + 'cancelled' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'cancelled', 'paged' => FALSE)), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled', 'invoicing') . $cancelled_count), |
|
90 | + 'failing' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'failing', 'paged' => FALSE)), $current === 'failing' ? ' class="current"' : '', __('Failing', 'invoicing') . $failing_count), |
|
91 | 91 | ); |
92 | 92 | |
93 | - return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views ); |
|
93 | + return apply_filters('wpinv_recurring_subscriptions_table_views', $views); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -104,27 +104,27 @@ discard block |
||
104 | 104 | * |
105 | 105 | * @return void |
106 | 106 | */ |
107 | - public function search_box( $text, $input_id ) { |
|
107 | + public function search_box($text, $input_id) { |
|
108 | 108 | |
109 | - if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
|
109 | + if (empty($_REQUEST['s']) && !$this->has_items()) { |
|
110 | 110 | return; |
111 | 111 | } |
112 | 112 | |
113 | 113 | $input_id = $input_id . '-search-input'; |
114 | 114 | |
115 | - if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
116 | - echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
115 | + if (!empty($_REQUEST['orderby'])) { |
|
116 | + echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />'; |
|
117 | 117 | } |
118 | 118 | |
119 | - if ( ! empty( $_REQUEST['order'] ) ) { |
|
120 | - echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
119 | + if (!empty($_REQUEST['order'])) { |
|
120 | + echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />'; |
|
121 | 121 | } |
122 | 122 | ?> |
123 | 123 | <p class="search-box"> |
124 | - <?php do_action( 'wpinv_recurring_subscription_search_box' ); ?> |
|
124 | + <?php do_action('wpinv_recurring_subscription_search_box'); ?> |
|
125 | 125 | <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> |
126 | 126 | <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" /> |
127 | - <?php submit_button( $text, 'button', false, false, array('ID' => 'search-submit') ); ?><br/> |
|
127 | + <?php submit_button($text, 'button', false, false, array('ID' => 'search-submit')); ?><br/> |
|
128 | 128 | </p> |
129 | 129 | <?php |
130 | 130 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @since 1.0.0 |
137 | 137 | * @return string |
138 | 138 | */ |
139 | - function column_default( $item, $column_name ) { |
|
139 | + function column_default($item, $column_name) { |
|
140 | 140 | return $item->$column_name; |
141 | 141 | } |
142 | 142 | |
@@ -147,8 +147,8 @@ discard block |
||
147 | 147 | * @since 1.0.0 |
148 | 148 | * @return string |
149 | 149 | */ |
150 | - function column_sub_id( $item ) { |
|
151 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" target="_blank">' . $item->id . '</a>'; |
|
150 | + function column_sub_id($item) { |
|
151 | + return '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $item->id)) . '" target="_blank">' . $item->id . '</a>'; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -158,11 +158,11 @@ discard block |
||
158 | 158 | * @since 1.0.0 |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - function column_customer_id( $item ) { |
|
162 | - $subscriber = get_userdata( $item->customer_id ); |
|
163 | - $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; |
|
161 | + function column_customer_id($item) { |
|
162 | + $subscriber = get_userdata($item->customer_id); |
|
163 | + $customer = !empty($subscriber->display_name) ? $subscriber->display_name : $subscriber->user_email; |
|
164 | 164 | |
165 | - return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>'; |
|
165 | + return '<a href="' . esc_url(get_edit_user_link($item->customer_id)) . '" target="_blank">' . $customer . '</a>'; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @since 1.0.0 |
173 | 173 | * @return string |
174 | 174 | */ |
175 | - function column_status( $item ) { |
|
175 | + function column_status($item) { |
|
176 | 176 | return $item->get_status_label(); |
177 | 177 | } |
178 | 178 | |
@@ -183,11 +183,11 @@ discard block |
||
183 | 183 | * @since 1.0.0 |
184 | 184 | * @return string |
185 | 185 | */ |
186 | - function column_period( $item ) { |
|
186 | + function column_period($item) { |
|
187 | 187 | |
188 | - $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency ); |
|
188 | + $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($item->period, $item->frequency); |
|
189 | 189 | |
190 | - return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period; |
|
190 | + return wpinv_price(wpinv_format_amount($item->recurring_amount), wpinv_get_invoice_currency_code($item->parent_payment_id)) . ' / ' . $period; |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | * @since 1.0.0 |
198 | 198 | * @return string |
199 | 199 | */ |
200 | - function column_bill_times( $item ) { |
|
201 | - return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? 'Until Cancelled' : $item->bill_times ); |
|
200 | + function column_bill_times($item) { |
|
201 | + return $item->get_times_billed() . ' / ' . (($item->bill_times == 0) ? 'Until Cancelled' : $item->bill_times); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | * @since 1.0.0 |
209 | 209 | * @return string |
210 | 210 | */ |
211 | - function column_initial_amount( $item ) { |
|
212 | - return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ); |
|
211 | + function column_initial_amount($item) { |
|
212 | + return wpinv_price(wpinv_format_amount($item->initial_amount), wpinv_get_invoice_currency_code($item->parent_payment_id)); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -219,8 +219,8 @@ discard block |
||
219 | 219 | * @since 1.0.0 |
220 | 220 | * @return string |
221 | 221 | */ |
222 | - function column_renewal_date( $item ) { |
|
223 | - return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' ); |
|
222 | + function column_renewal_date($item) { |
|
223 | + return $renewal_date = !empty($item->expiration) ? date_i18n(get_option('date_format'), strtotime($item->expiration)) : __('N/A', 'invoicing'); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -230,8 +230,8 @@ discard block |
||
230 | 230 | * @since 1.0.0 |
231 | 231 | * @return string |
232 | 232 | */ |
233 | - function column_parent_payment_id( $item ) { |
|
234 | - return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . wpinv_get_invoice_number( $item->parent_payment_id ) . '</a>'; |
|
233 | + function column_parent_payment_id($item) { |
|
234 | + return '<a href="' . get_edit_post_link($item->parent_payment_id) . '" target="_blank">' . wpinv_get_invoice_number($item->parent_payment_id) . '</a>'; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -241,8 +241,8 @@ discard block |
||
241 | 241 | * @since 1.0.0 |
242 | 242 | * @return string |
243 | 243 | */ |
244 | - function column_product_id( $item ) { |
|
245 | - return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>'; |
|
244 | + function column_product_id($item) { |
|
245 | + return '<a href="' . esc_url(admin_url('post.php?action=edit&post=' . $item->product_id)) . '" target="_blank">' . get_the_title($item->product_id) . '</a>'; |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -252,8 +252,8 @@ discard block |
||
252 | 252 | * @since 2.0 |
253 | 253 | * @return string |
254 | 254 | */ |
255 | - function column_actions( $item ) { |
|
256 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>'; |
|
255 | + function column_actions($item) { |
|
256 | + return '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $item->id)) . '" title="' . esc_attr(__('View or edit subscription', 'invoicing')) . '" target="_blank">' . __('View', 'invoicing') . '</a>'; |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | |
@@ -265,21 +265,21 @@ discard block |
||
265 | 265 | * @return array |
266 | 266 | */ |
267 | 267 | |
268 | - function get_columns(){ |
|
268 | + function get_columns() { |
|
269 | 269 | $columns = array( |
270 | - 'sub_id' => __( 'ID', 'invoicing' ), |
|
271 | - 'customer_id' => __( 'Customer', 'invoicing' ), |
|
272 | - 'status' => __( 'Status', 'invoicing' ), |
|
273 | - 'period' => __( 'Billing Cycle', 'invoicing' ), |
|
274 | - 'initial_amount' => __( 'Initial Amount', 'invoicing' ), |
|
275 | - 'bill_times' => __( 'Times Billed', 'invoicing' ), |
|
276 | - 'renewal_date' => __( 'Renewal Date', 'invoicing' ), |
|
277 | - 'parent_payment_id' => __( 'Invoice', 'invoicing' ), |
|
278 | - 'product_id' => __( 'Item', 'invoicing' ), |
|
279 | - 'actions' => __( 'Actions', 'invoicing' ), |
|
270 | + 'sub_id' => __('ID', 'invoicing'), |
|
271 | + 'customer_id' => __('Customer', 'invoicing'), |
|
272 | + 'status' => __('Status', 'invoicing'), |
|
273 | + 'period' => __('Billing Cycle', 'invoicing'), |
|
274 | + 'initial_amount' => __('Initial Amount', 'invoicing'), |
|
275 | + 'bill_times' => __('Times Billed', 'invoicing'), |
|
276 | + 'renewal_date' => __('Renewal Date', 'invoicing'), |
|
277 | + 'parent_payment_id' => __('Invoice', 'invoicing'), |
|
278 | + 'product_id' => __('Item', 'invoicing'), |
|
279 | + 'actions' => __('Actions', 'invoicing'), |
|
280 | 280 | ); |
281 | 281 | |
282 | - return apply_filters( 'wpinv_report_subscription_columns', $columns ); |
|
282 | + return apply_filters('wpinv_report_subscription_columns', $columns); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * @return int |
291 | 291 | */ |
292 | 292 | function get_paged() { |
293 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
293 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
@@ -306,16 +306,16 @@ discard block |
||
306 | 306 | |
307 | 307 | $db = new WPInv_Subscriptions_DB; |
308 | 308 | |
309 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
309 | + $search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : ''; |
|
310 | 310 | |
311 | 311 | $this->total_count = $db->count(); |
312 | - $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) ); |
|
313 | - $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) ); |
|
314 | - $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) ); |
|
315 | - $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) ); |
|
316 | - $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) ); |
|
317 | - $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) ); |
|
318 | - $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) ); |
|
312 | + $this->active_count = $db->count(array('status' => 'active', 'search' => $search)); |
|
313 | + $this->pending_count = $db->count(array('status' => 'pending', 'search' => $search)); |
|
314 | + $this->expired_count = $db->count(array('status' => 'expired', 'search' => $search)); |
|
315 | + $this->trialling_count = $db->count(array('status' => 'trialling', 'search' => $search)); |
|
316 | + $this->cancelled_count = $db->count(array('status' => 'cancelled', 'search' => $search)); |
|
317 | + $this->completed_count = $db->count(array('status' => 'completed', 'search' => $search)); |
|
318 | + $this->failing_count = $db->count(array('status' => 'failing', 'search' => $search)); |
|
319 | 319 | |
320 | 320 | } |
321 | 321 | |
@@ -336,28 +336,28 @@ discard block |
||
336 | 336 | |
337 | 337 | $columns = $this->get_columns(); |
338 | 338 | $hidden = array(); // No hidden columns |
339 | - $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
|
339 | + $status = isset($_GET['status']) ? $_GET['status'] : 'any'; |
|
340 | 340 | $sortable = $this->get_sortable_columns(); |
341 | 341 | |
342 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
342 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
343 | 343 | |
344 | 344 | $current_page = $this->get_pagenum(); |
345 | 345 | |
346 | 346 | $db = new WPInv_Subscriptions_DB; |
347 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
347 | + $search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : ''; |
|
348 | 348 | $args = array( |
349 | 349 | 'number' => $this->per_page, |
350 | - 'offset' => $this->per_page * ( $this->get_paged() - 1 ), |
|
350 | + 'offset' => $this->per_page * ($this->get_paged() - 1), |
|
351 | 351 | 'search' => $search |
352 | 352 | ); |
353 | 353 | |
354 | - if ( 'any' !== $status ) { |
|
354 | + if ('any' !== $status) { |
|
355 | 355 | $args['status'] = $status; |
356 | 356 | } |
357 | 357 | |
358 | - $this->items = $db->get_subscriptions( $args ); |
|
358 | + $this->items = $db->get_subscriptions($args); |
|
359 | 359 | |
360 | - switch ( $status ) { |
|
360 | + switch ($status) { |
|
361 | 361 | case 'active': |
362 | 362 | $total_items = $this->active_count; |
363 | 363 | break; |
@@ -385,10 +385,10 @@ discard block |
||
385 | 385 | break; |
386 | 386 | } |
387 | 387 | |
388 | - $this->set_pagination_args( array( |
|
388 | + $this->set_pagination_args(array( |
|
389 | 389 | 'total_items' => $total_items, |
390 | 390 | 'per_page' => $this->per_page, |
391 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
392 | - ) ); |
|
391 | + 'total_pages' => ceil($total_items / $this->per_page) |
|
392 | + )); |
|
393 | 393 | } |
394 | 394 | } |
@@ -7,28 +7,28 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | class WPInv_Ajax { |
15 | 15 | public static function init() { |
16 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
17 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
16 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
17 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
18 | 18 | self::add_ajax_events(); |
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function define_ajax() { |
22 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
23 | - if ( ! defined( 'DOING_AJAX' ) ) { |
|
24 | - define( 'DOING_AJAX', true ); |
|
22 | + if (!empty($_GET['wpinv-ajax'])) { |
|
23 | + if (!defined('DOING_AJAX')) { |
|
24 | + define('DOING_AJAX', true); |
|
25 | 25 | } |
26 | - if ( ! defined( 'WC_DOING_AJAX' ) ) { |
|
27 | - define( 'WC_DOING_AJAX', true ); |
|
26 | + if (!defined('WC_DOING_AJAX')) { |
|
27 | + define('WC_DOING_AJAX', true); |
|
28 | 28 | } |
29 | 29 | // Turn off display_errors during AJAX events to prevent malformed JSON |
30 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
31 | - @ini_set( 'display_errors', 0 ); |
|
30 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
31 | + @ini_set('display_errors', 0); |
|
32 | 32 | } |
33 | 33 | $GLOBALS['wpdb']->hide_errors(); |
34 | 34 | } |
@@ -37,24 +37,24 @@ discard block |
||
37 | 37 | public static function do_wpinv_ajax() { |
38 | 38 | global $wp_query; |
39 | 39 | |
40 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
41 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) ); |
|
40 | + if (!empty($_GET['wpinv-ajax'])) { |
|
41 | + $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax'])); |
|
42 | 42 | } |
43 | 43 | |
44 | - if ( $action = $wp_query->get( 'wpinv-ajax' ) ) { |
|
44 | + if ($action = $wp_query->get('wpinv-ajax')) { |
|
45 | 45 | self::wpinv_ajax_headers(); |
46 | - do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) ); |
|
46 | + do_action('wpinv_ajax_' . sanitize_text_field($action)); |
|
47 | 47 | die(); |
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | 51 | private static function wpinv_ajax_headers() { |
52 | 52 | send_origin_headers(); |
53 | - @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
54 | - @header( 'X-Robots-Tag: noindex' ); |
|
53 | + @header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
54 | + @header('X-Robots-Tag: noindex'); |
|
55 | 55 | send_nosniff_header(); |
56 | 56 | nocache_headers(); |
57 | - status_header( 200 ); |
|
57 | + status_header(200); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public static function add_ajax_events() { |
@@ -77,39 +77,39 @@ discard block |
||
77 | 77 | 'buy_items' => true, |
78 | 78 | ); |
79 | 79 | |
80 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
81 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
80 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
81 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
82 | 82 | |
83 | - if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) { |
|
84 | - define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 ); |
|
83 | + if (!defined('WPI_AJAX_' . strtoupper($nopriv))) { |
|
84 | + define('WPI_AJAX_' . strtoupper($nopriv), 1); |
|
85 | 85 | } |
86 | 86 | |
87 | - if ( $nopriv ) { |
|
88 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
87 | + if ($nopriv) { |
|
88 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
89 | 89 | |
90 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
90 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | 95 | public static function add_note() { |
96 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
96 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
97 | 97 | |
98 | - if ( !current_user_can( 'manage_options' ) ) { |
|
98 | + if (!current_user_can('manage_options')) { |
|
99 | 99 | die(-1); |
100 | 100 | } |
101 | 101 | |
102 | - $post_id = absint( $_POST['post_id'] ); |
|
103 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
104 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
102 | + $post_id = absint($_POST['post_id']); |
|
103 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
104 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
105 | 105 | |
106 | 106 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
107 | 107 | |
108 | - if ( $post_id > 0 ) { |
|
109 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
108 | + if ($post_id > 0) { |
|
109 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
110 | 110 | |
111 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
112 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
111 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
112 | + wpinv_get_invoice_note_line_item($note_id); |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
@@ -117,16 +117,16 @@ discard block |
||
117 | 117 | } |
118 | 118 | |
119 | 119 | public static function delete_note() { |
120 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
120 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
121 | 121 | |
122 | - if ( !current_user_can( 'manage_options' ) ) { |
|
122 | + if (!current_user_can('manage_options')) { |
|
123 | 123 | die(-1); |
124 | 124 | } |
125 | 125 | |
126 | 126 | $note_id = (int)$_POST['note_id']; |
127 | 127 | |
128 | - if ( $note_id > 0 ) { |
|
129 | - wp_delete_comment( $note_id, true ); |
|
128 | + if ($note_id > 0) { |
|
129 | + wp_delete_comment($note_id, true); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | die(); |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | public static function checkout() { |
142 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
143 | - define( 'WPINV_CHECKOUT', true ); |
|
142 | + if (!defined('WPINV_CHECKOUT')) { |
|
143 | + define('WPINV_CHECKOUT', true); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | wpinv_process_checkout(); |
@@ -149,53 +149,53 @@ discard block |
||
149 | 149 | |
150 | 150 | public static function add_invoice_item() { |
151 | 151 | global $wpi_userID, $wpinv_ip_address_country; |
152 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
153 | - if ( !current_user_can( 'manage_options' ) ) { |
|
152 | + check_ajax_referer('invoice-item', '_nonce'); |
|
153 | + if (!current_user_can('manage_options')) { |
|
154 | 154 | die(-1); |
155 | 155 | } |
156 | 156 | |
157 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
158 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
157 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
158 | + $invoice_id = absint($_POST['invoice_id']); |
|
159 | 159 | |
160 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
160 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
161 | 161 | die(); |
162 | 162 | } |
163 | 163 | |
164 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
165 | - if ( empty( $invoice ) ) { |
|
164 | + $invoice = wpinv_get_invoice($invoice_id); |
|
165 | + if (empty($invoice)) { |
|
166 | 166 | die(); |
167 | 167 | } |
168 | 168 | |
169 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
169 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
170 | 170 | die(); // Don't allow modify items for paid invoice. |
171 | 171 | } |
172 | 172 | |
173 | - if ( !empty( $_POST['user_id'] ) ) { |
|
174 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
173 | + if (!empty($_POST['user_id'])) { |
|
174 | + $wpi_userID = absint($_POST['user_id']); |
|
175 | 175 | } |
176 | 176 | |
177 | - $item = new WPInv_Item( $item_id ); |
|
178 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
177 | + $item = new WPInv_Item($item_id); |
|
178 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
179 | 179 | die(); |
180 | 180 | } |
181 | 181 | |
182 | 182 | // Validate item before adding to invoice because recurring item must be paid individually. |
183 | - if ( !empty( $invoice->cart_details ) ) { |
|
183 | + if (!empty($invoice->cart_details)) { |
|
184 | 184 | $valid = true; |
185 | 185 | |
186 | - if ( $recurring_item = $invoice->get_recurring() ) { |
|
187 | - if ( $recurring_item != $item_id ) { |
|
186 | + if ($recurring_item = $invoice->get_recurring()) { |
|
187 | + if ($recurring_item != $item_id) { |
|
188 | 188 | $valid = false; |
189 | 189 | } |
190 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
190 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
191 | 191 | $valid = false; |
192 | 192 | } |
193 | 193 | |
194 | - if ( !$valid ) { |
|
194 | + if (!$valid) { |
|
195 | 195 | $response = array(); |
196 | 196 | $response['success'] = false; |
197 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
198 | - wp_send_json( $response ); |
|
197 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
198 | + wp_send_json($response); |
|
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | |
204 | 204 | $data = array(); |
205 | 205 | $data['invoice_id'] = $invoice_id; |
206 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
206 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
207 | 207 | |
208 | - wpinv_set_checkout_session( $data ); |
|
208 | + wpinv_set_checkout_session($data); |
|
209 | 209 | |
210 | 210 | $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1; |
211 | 211 | |
@@ -220,21 +220,21 @@ discard block |
||
220 | 220 | 'fees' => array() |
221 | 221 | ); |
222 | 222 | |
223 | - $invoice->add_item( $item_id, $args ); |
|
223 | + $invoice->add_item($item_id, $args); |
|
224 | 224 | $invoice->save(); |
225 | 225 | |
226 | - if ( empty( $_POST['country'] ) ) { |
|
226 | + if (empty($_POST['country'])) { |
|
227 | 227 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
228 | 228 | } |
229 | - if ( empty( $_POST['state'] ) ) { |
|
229 | + if (empty($_POST['state'])) { |
|
230 | 230 | $_POST['state'] = $invoice->state; |
231 | 231 | } |
232 | 232 | |
233 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
234 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
233 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
234 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
235 | 235 | |
236 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
237 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
236 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
237 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
238 | 238 | |
239 | 239 | $wpinv_ip_address_country = $invoice->country; |
240 | 240 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | |
243 | 243 | $response = array(); |
244 | 244 | $response['success'] = true; |
245 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
245 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
246 | 246 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
247 | 247 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
248 | 248 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -254,40 +254,40 @@ discard block |
||
254 | 254 | |
255 | 255 | wpinv_set_checkout_session($checkout_session); |
256 | 256 | |
257 | - wp_send_json( $response ); |
|
257 | + wp_send_json($response); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | public static function remove_invoice_item() { |
261 | 261 | global $wpi_userID, $wpinv_ip_address_country; |
262 | 262 | |
263 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
264 | - if ( !current_user_can( 'manage_options' ) ) { |
|
263 | + check_ajax_referer('invoice-item', '_nonce'); |
|
264 | + if (!current_user_can('manage_options')) { |
|
265 | 265 | die(-1); |
266 | 266 | } |
267 | 267 | |
268 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
269 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
270 | - $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
268 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
269 | + $invoice_id = absint($_POST['invoice_id']); |
|
270 | + $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
271 | 271 | |
272 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
272 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
273 | 273 | die(); |
274 | 274 | } |
275 | 275 | |
276 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
277 | - if ( empty( $invoice ) ) { |
|
276 | + $invoice = wpinv_get_invoice($invoice_id); |
|
277 | + if (empty($invoice)) { |
|
278 | 278 | die(); |
279 | 279 | } |
280 | 280 | |
281 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
281 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
282 | 282 | die(); // Don't allow modify items for paid invoice. |
283 | 283 | } |
284 | 284 | |
285 | - if ( !empty( $_POST['user_id'] ) ) { |
|
286 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
285 | + if (!empty($_POST['user_id'])) { |
|
286 | + $wpi_userID = absint($_POST['user_id']); |
|
287 | 287 | } |
288 | 288 | |
289 | - $item = new WPInv_Item( $item_id ); |
|
290 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
289 | + $item = new WPInv_Item($item_id); |
|
290 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
291 | 291 | die(); |
292 | 292 | } |
293 | 293 | |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | |
296 | 296 | $data = array(); |
297 | 297 | $data['invoice_id'] = $invoice_id; |
298 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
298 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
299 | 299 | |
300 | - wpinv_set_checkout_session( $data ); |
|
300 | + wpinv_set_checkout_session($data); |
|
301 | 301 | |
302 | 302 | $args = array( |
303 | 303 | 'id' => $item_id, |
@@ -305,21 +305,21 @@ discard block |
||
305 | 305 | 'cart_index' => $cart_index |
306 | 306 | ); |
307 | 307 | |
308 | - $invoice->remove_item( $item_id, $args ); |
|
308 | + $invoice->remove_item($item_id, $args); |
|
309 | 309 | $invoice->save(); |
310 | 310 | |
311 | - if ( empty( $_POST['country'] ) ) { |
|
311 | + if (empty($_POST['country'])) { |
|
312 | 312 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
313 | 313 | } |
314 | - if ( empty( $_POST['state'] ) ) { |
|
314 | + if (empty($_POST['state'])) { |
|
315 | 315 | $_POST['state'] = $invoice->state; |
316 | 316 | } |
317 | 317 | |
318 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
319 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
318 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
319 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
320 | 320 | |
321 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
322 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
321 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
322 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
323 | 323 | |
324 | 324 | $wpinv_ip_address_country = $invoice->country; |
325 | 325 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | |
328 | 328 | $response = array(); |
329 | 329 | $response['success'] = true; |
330 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
330 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
331 | 331 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
332 | 332 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
333 | 333 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -339,40 +339,40 @@ discard block |
||
339 | 339 | |
340 | 340 | wpinv_set_checkout_session($checkout_session); |
341 | 341 | |
342 | - wp_send_json( $response ); |
|
342 | + wp_send_json($response); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | public static function create_invoice_item() { |
346 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
347 | - if ( !current_user_can( 'manage_options' ) ) { |
|
346 | + check_ajax_referer('invoice-item', '_nonce'); |
|
347 | + if (!current_user_can('manage_options')) { |
|
348 | 348 | die(-1); |
349 | 349 | } |
350 | 350 | |
351 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
351 | + $invoice_id = absint($_POST['invoice_id']); |
|
352 | 352 | |
353 | 353 | // Find the item |
354 | - if ( !is_numeric( $invoice_id ) ) { |
|
354 | + if (!is_numeric($invoice_id)) { |
|
355 | 355 | die(); |
356 | 356 | } |
357 | 357 | |
358 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
359 | - if ( empty( $invoice ) ) { |
|
358 | + $invoice = wpinv_get_invoice($invoice_id); |
|
359 | + if (empty($invoice)) { |
|
360 | 360 | die(); |
361 | 361 | } |
362 | 362 | |
363 | 363 | // Validate item before adding to invoice because recurring item must be paid individually. |
364 | - if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) { |
|
364 | + if (!empty($invoice->cart_details) && $invoice->get_recurring()) { |
|
365 | 365 | $response = array(); |
366 | 366 | $response['success'] = false; |
367 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
368 | - wp_send_json( $response ); |
|
367 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
368 | + wp_send_json($response); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | $save_item = $_POST['_wpinv_quick']; |
372 | 372 | |
373 | 373 | $meta = array(); |
374 | 374 | $meta['type'] = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom'; |
375 | - $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0; |
|
375 | + $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0; |
|
376 | 376 | $meta['vat_rule'] = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital'; |
377 | 377 | $meta['vat_class'] = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard'; |
378 | 378 | |
@@ -382,9 +382,9 @@ discard block |
||
382 | 382 | $data['meta'] = $meta; |
383 | 383 | |
384 | 384 | $item = new WPInv_Item(); |
385 | - $item->create( $data ); |
|
385 | + $item->create($data); |
|
386 | 386 | |
387 | - if ( !empty( $item ) ) { |
|
387 | + if (!empty($item)) { |
|
388 | 388 | $_POST['item_id'] = $item->ID; |
389 | 389 | $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1; |
390 | 390 | |
@@ -394,15 +394,15 @@ discard block |
||
394 | 394 | } |
395 | 395 | |
396 | 396 | public static function get_billing_details() { |
397 | - check_ajax_referer( 'get-billing-details', '_nonce' ); |
|
397 | + check_ajax_referer('get-billing-details', '_nonce'); |
|
398 | 398 | |
399 | - if ( !current_user_can( 'manage_options' ) ) { |
|
399 | + if (!current_user_can('manage_options')) { |
|
400 | 400 | die(-1); |
401 | 401 | } |
402 | 402 | |
403 | 403 | $user_id = (int)$_POST['user_id']; |
404 | 404 | $billing_details = wpinv_get_user_address($user_id); |
405 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
405 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
406 | 406 | |
407 | 407 | if (isset($billing_details['user_id'])) { |
408 | 408 | unset($billing_details['user_id']); |
@@ -416,20 +416,20 @@ discard block |
||
416 | 416 | $response['success'] = true; |
417 | 417 | $response['data']['billing_details'] = $billing_details; |
418 | 418 | |
419 | - wp_send_json( $response ); |
|
419 | + wp_send_json($response); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | public static function admin_recalculate_totals() { |
423 | 423 | global $wpi_userID, $wpinv_ip_address_country; |
424 | 424 | |
425 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
426 | - if ( !current_user_can( 'manage_options' ) ) { |
|
425 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
426 | + if (!current_user_can('manage_options')) { |
|
427 | 427 | die(-1); |
428 | 428 | } |
429 | 429 | |
430 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
431 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
432 | - if ( empty( $invoice ) ) { |
|
430 | + $invoice_id = absint($_POST['invoice_id']); |
|
431 | + $invoice = wpinv_get_invoice($invoice_id); |
|
432 | + if (empty($invoice)) { |
|
433 | 433 | die(); |
434 | 434 | } |
435 | 435 | |
@@ -437,23 +437,23 @@ discard block |
||
437 | 437 | |
438 | 438 | $data = array(); |
439 | 439 | $data['invoice_id'] = $invoice_id; |
440 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
440 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
441 | 441 | |
442 | - wpinv_set_checkout_session( $data ); |
|
442 | + wpinv_set_checkout_session($data); |
|
443 | 443 | |
444 | - if ( !empty( $_POST['user_id'] ) ) { |
|
445 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
444 | + if (!empty($_POST['user_id'])) { |
|
445 | + $wpi_userID = absint($_POST['user_id']); |
|
446 | 446 | } |
447 | 447 | |
448 | - if ( empty( $_POST['country'] ) ) { |
|
448 | + if (empty($_POST['country'])) { |
|
449 | 449 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
450 | 450 | } |
451 | 451 | |
452 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
453 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
454 | - if ( isset( $_POST['state'] ) ) { |
|
455 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
456 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
452 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
453 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
454 | + if (isset($_POST['state'])) { |
|
455 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
456 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | $wpinv_ip_address_country = $invoice->country; |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | |
463 | 463 | $response = array(); |
464 | 464 | $response['success'] = true; |
465 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
465 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
466 | 466 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
467 | 467 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
468 | 468 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -474,25 +474,25 @@ discard block |
||
474 | 474 | |
475 | 475 | wpinv_set_checkout_session($checkout_session); |
476 | 476 | |
477 | - wp_send_json( $response ); |
|
477 | + wp_send_json($response); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | public static function admin_apply_discount() { |
481 | 481 | global $wpi_userID; |
482 | 482 | |
483 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
484 | - if ( !current_user_can( 'manage_options' ) ) { |
|
483 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
484 | + if (!current_user_can('manage_options')) { |
|
485 | 485 | die(-1); |
486 | 486 | } |
487 | 487 | |
488 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
489 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
490 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
488 | + $invoice_id = absint($_POST['invoice_id']); |
|
489 | + $discount_code = sanitize_text_field($_POST['code']); |
|
490 | + if (empty($invoice_id) || empty($discount_code)) { |
|
491 | 491 | die(); |
492 | 492 | } |
493 | 493 | |
494 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
495 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
494 | + $invoice = wpinv_get_invoice($invoice_id); |
|
495 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
496 | 496 | die(); |
497 | 497 | } |
498 | 498 | |
@@ -500,49 +500,49 @@ discard block |
||
500 | 500 | |
501 | 501 | $data = array(); |
502 | 502 | $data['invoice_id'] = $invoice_id; |
503 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
503 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
504 | 504 | |
505 | - wpinv_set_checkout_session( $data ); |
|
505 | + wpinv_set_checkout_session($data); |
|
506 | 506 | |
507 | 507 | $response = array(); |
508 | 508 | $response['success'] = false; |
509 | - $response['msg'] = __( 'This discount is invalid.', 'invoicing' ); |
|
509 | + $response['msg'] = __('This discount is invalid.', 'invoicing'); |
|
510 | 510 | $response['data']['code'] = $discount_code; |
511 | 511 | |
512 | - if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) { |
|
513 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
512 | + if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) { |
|
513 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
514 | 514 | |
515 | 515 | $response['success'] = true; |
516 | - $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' ); |
|
517 | - } else { |
|
516 | + $response['msg'] = __('Discount has been applied successfully.', 'invoicing'); |
|
517 | + } else { |
|
518 | 518 | $errors = wpinv_get_errors(); |
519 | - if ( !empty( $errors['wpinv-discount-error'] ) ) { |
|
519 | + if (!empty($errors['wpinv-discount-error'])) { |
|
520 | 520 | $response['msg'] = $errors['wpinv-discount-error']; |
521 | 521 | } |
522 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
522 | + wpinv_unset_error('wpinv-discount-error'); |
|
523 | 523 | } |
524 | 524 | |
525 | 525 | wpinv_set_checkout_session($checkout_session); |
526 | 526 | |
527 | - wp_send_json( $response ); |
|
527 | + wp_send_json($response); |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | public static function admin_remove_discount() { |
531 | 531 | global $wpi_userID; |
532 | 532 | |
533 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
534 | - if ( !current_user_can( 'manage_options' ) ) { |
|
533 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
534 | + if (!current_user_can('manage_options')) { |
|
535 | 535 | die(-1); |
536 | 536 | } |
537 | 537 | |
538 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
539 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
540 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
538 | + $invoice_id = absint($_POST['invoice_id']); |
|
539 | + $discount_code = sanitize_text_field($_POST['code']); |
|
540 | + if (empty($invoice_id) || empty($discount_code)) { |
|
541 | 541 | die(); |
542 | 542 | } |
543 | 543 | |
544 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
545 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
544 | + $invoice = wpinv_get_invoice($invoice_id); |
|
545 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
546 | 546 | die(); |
547 | 547 | } |
548 | 548 | |
@@ -550,38 +550,38 @@ discard block |
||
550 | 550 | |
551 | 551 | $data = array(); |
552 | 552 | $data['invoice_id'] = $invoice_id; |
553 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
553 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
554 | 554 | |
555 | - wpinv_set_checkout_session( $data ); |
|
555 | + wpinv_set_checkout_session($data); |
|
556 | 556 | |
557 | 557 | $response = array(); |
558 | 558 | $response['success'] = false; |
559 | 559 | $response['msg'] = NULL; |
560 | 560 | |
561 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
561 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
562 | 562 | $response['success'] = true; |
563 | - $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' ); |
|
563 | + $response['msg'] = __('Discount has been removed successfully.', 'invoicing'); |
|
564 | 564 | |
565 | 565 | wpinv_set_checkout_session($checkout_session); |
566 | 566 | |
567 | - wp_send_json( $response ); |
|
567 | + wp_send_json($response); |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | public static function check_email() { |
571 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
572 | - if ( !current_user_can( 'manage_options' ) ) { |
|
571 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
572 | + if (!current_user_can('manage_options')) { |
|
573 | 573 | die(-1); |
574 | 574 | } |
575 | 575 | |
576 | - $email = sanitize_text_field( $_POST['email'] ); |
|
576 | + $email = sanitize_text_field($_POST['email']); |
|
577 | 577 | |
578 | 578 | $response = array(); |
579 | - if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) { |
|
579 | + if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) { |
|
580 | 580 | $user_id = $user_data->ID; |
581 | 581 | $user_login = $user_data->user_login; |
582 | 582 | $display_name = $user_data->display_name ? $user_data->display_name : $user_login; |
583 | 583 | $billing_details = wpinv_get_user_address($user_id); |
584 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
584 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
585 | 585 | |
586 | 586 | if (isset($billing_details['user_id'])) { |
587 | 587 | unset($billing_details['user_id']); |
@@ -597,54 +597,54 @@ discard block |
||
597 | 597 | $response['data']['billing_details'] = $billing_details; |
598 | 598 | } |
599 | 599 | |
600 | - wp_send_json( $response ); |
|
600 | + wp_send_json($response); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | public static function run_tool() { |
604 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
605 | - if ( !current_user_can( 'manage_options' ) ) { |
|
604 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
605 | + if (!current_user_can('manage_options')) { |
|
606 | 606 | die(-1); |
607 | 607 | } |
608 | 608 | |
609 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
609 | + $tool = sanitize_text_field($_POST['tool']); |
|
610 | 610 | |
611 | - do_action( 'wpinv_run_tool' ); |
|
611 | + do_action('wpinv_run_tool'); |
|
612 | 612 | |
613 | - if ( !empty( $tool ) ) { |
|
614 | - do_action( 'wpinv_tool_' . $tool ); |
|
613 | + if (!empty($tool)) { |
|
614 | + do_action('wpinv_tool_' . $tool); |
|
615 | 615 | } |
616 | 616 | } |
617 | 617 | |
618 | 618 | public static function apply_discount() { |
619 | 619 | global $wpi_userID; |
620 | 620 | |
621 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
621 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
622 | 622 | |
623 | 623 | $response = array(); |
624 | 624 | |
625 | - if ( isset( $_POST['code'] ) ) { |
|
626 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
625 | + if (isset($_POST['code'])) { |
|
626 | + $discount_code = sanitize_text_field($_POST['code']); |
|
627 | 627 | |
628 | 628 | $response['success'] = false; |
629 | 629 | $response['msg'] = ''; |
630 | 630 | $response['data']['code'] = $discount_code; |
631 | 631 | |
632 | 632 | $invoice = wpinv_get_invoice_cart(); |
633 | - if ( empty( $invoice->ID ) ) { |
|
634 | - $response['msg'] = __( 'Invalid checkout request.', 'invoicing' ); |
|
635 | - wp_send_json( $response ); |
|
633 | + if (empty($invoice->ID)) { |
|
634 | + $response['msg'] = __('Invalid checkout request.', 'invoicing'); |
|
635 | + wp_send_json($response); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | $wpi_userID = $invoice->get_user_id(); |
639 | 639 | |
640 | - if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) { |
|
641 | - $discount = wpinv_get_discount_by_code( $discount_code ); |
|
642 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
643 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
644 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
645 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
640 | + if (wpinv_is_discount_valid($discount_code, $wpi_userID)) { |
|
641 | + $discount = wpinv_get_discount_by_code($discount_code); |
|
642 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
643 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
644 | + $total = wpinv_get_cart_total(null, $discounts); |
|
645 | + $cart_totals = wpinv_recalculate_tax(true); |
|
646 | 646 | |
647 | - if ( !empty( $cart_totals ) ) { |
|
647 | + if (!empty($cart_totals)) { |
|
648 | 648 | $response['success'] = true; |
649 | 649 | $response['data'] = $cart_totals; |
650 | 650 | $response['data']['code'] = $discount_code; |
@@ -653,29 +653,29 @@ discard block |
||
653 | 653 | } |
654 | 654 | } else { |
655 | 655 | $errors = wpinv_get_errors(); |
656 | - $response['msg'] = $errors['wpinv-discount-error']; |
|
657 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
656 | + $response['msg'] = $errors['wpinv-discount-error']; |
|
657 | + wpinv_unset_error('wpinv-discount-error'); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | // Allow for custom discount code handling |
661 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
661 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
662 | 662 | } |
663 | 663 | |
664 | - wp_send_json( $response ); |
|
664 | + wp_send_json($response); |
|
665 | 665 | } |
666 | 666 | |
667 | 667 | public static function remove_discount() { |
668 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
668 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
669 | 669 | |
670 | 670 | $response = array(); |
671 | 671 | |
672 | - if ( isset( $_POST['code'] ) ) { |
|
673 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
674 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
675 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
676 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
672 | + if (isset($_POST['code'])) { |
|
673 | + $discount_code = sanitize_text_field($_POST['code']); |
|
674 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
675 | + $total = wpinv_get_cart_total(null, $discounts); |
|
676 | + $cart_totals = wpinv_recalculate_tax(true); |
|
677 | 677 | |
678 | - if ( !empty( $cart_totals ) ) { |
|
678 | + if (!empty($cart_totals)) { |
|
679 | 679 | $response['success'] = true; |
680 | 680 | $response['data'] = $cart_totals; |
681 | 681 | $response['data']['code'] = $discount_code; |
@@ -684,10 +684,10 @@ discard block |
||
684 | 684 | } |
685 | 685 | |
686 | 686 | // Allow for custom discount code handling |
687 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
687 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
688 | 688 | } |
689 | 689 | |
690 | - wp_send_json( $response ); |
|
690 | + wp_send_json($response); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | |
@@ -699,53 +699,53 @@ discard block |
||
699 | 699 | public static function buy_items() { |
700 | 700 | $user_id = get_current_user_id(); |
701 | 701 | |
702 | - if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page |
|
703 | - wp_send_json( array( |
|
704 | - 'success' => wp_login_url( wp_get_referer() ) |
|
705 | - ) ); |
|
702 | + if (empty($user_id)) { // If not logged in then lets redirect to the login page |
|
703 | + wp_send_json(array( |
|
704 | + 'success' => wp_login_url(wp_get_referer()) |
|
705 | + )); |
|
706 | 706 | } else { |
707 | 707 | // Only check nonce if logged in as it could be cached when logged out. |
708 | - if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) { |
|
709 | - wp_send_json( array( |
|
710 | - 'error' => __( 'Security checks failed.', 'invoicing' ) |
|
711 | - ) ); |
|
708 | + if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) { |
|
709 | + wp_send_json(array( |
|
710 | + 'error' => __('Security checks failed.', 'invoicing') |
|
711 | + )); |
|
712 | 712 | wp_die(); |
713 | 713 | } |
714 | 714 | |
715 | 715 | // allow to set a custom price through post_id |
716 | 716 | $items = $_POST['items']; |
717 | - $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0; |
|
718 | - $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0; |
|
717 | + $related_post_id = isset($_POST['post_id']) ? (int)$_POST['post_id'] : 0; |
|
718 | + $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0; |
|
719 | 719 | |
720 | 720 | $cart_items = array(); |
721 | - if ( $items ) { |
|
722 | - $items = explode( ',', $items ); |
|
721 | + if ($items) { |
|
722 | + $items = explode(',', $items); |
|
723 | 723 | |
724 | - foreach( $items as $item ) { |
|
724 | + foreach ($items as $item) { |
|
725 | 725 | $item_id = $item; |
726 | 726 | $quantity = 1; |
727 | 727 | |
728 | - if ( strpos( $item, '|' ) !== false ) { |
|
729 | - $item_parts = explode( '|', $item ); |
|
728 | + if (strpos($item, '|') !== false) { |
|
729 | + $item_parts = explode('|', $item); |
|
730 | 730 | $item_id = $item_parts[0]; |
731 | 731 | $quantity = $item_parts[1]; |
732 | 732 | } |
733 | 733 | |
734 | - if ( $item_id && $quantity ) { |
|
734 | + if ($item_id && $quantity) { |
|
735 | 735 | $cart_items_arr = array( |
736 | 736 | 'id' => (int)$item_id, |
737 | 737 | 'quantity' => (int)$quantity |
738 | 738 | ); |
739 | 739 | |
740 | 740 | // If there is a related post id then add it to meta |
741 | - if ( $related_post_id ) { |
|
741 | + if ($related_post_id) { |
|
742 | 742 | $cart_items_arr['meta'] = array( |
743 | 743 | 'post_id' => $related_post_id |
744 | 744 | ); |
745 | 745 | } |
746 | 746 | |
747 | 747 | // If there is a custom price then set it. |
748 | - if ( $custom_item_price ) { |
|
748 | + if ($custom_item_price) { |
|
749 | 749 | $cart_items_arr['custom_price'] = $custom_item_price; |
750 | 750 | } |
751 | 751 | |
@@ -761,37 +761,37 @@ discard block |
||
761 | 761 | * @param int $related_post_id The related post id if any. |
762 | 762 | * @since 1.0.0 |
763 | 763 | */ |
764 | - $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id ); |
|
764 | + $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id); |
|
765 | 765 | |
766 | 766 | // Make sure its not in the cart already, if it is then redirect to checkout. |
767 | 767 | $cart_invoice = wpinv_get_invoice_cart(); |
768 | 768 | |
769 | - if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) { |
|
770 | - wp_send_json( array( |
|
769 | + if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) { |
|
770 | + wp_send_json(array( |
|
771 | 771 | 'success' => $cart_invoice->get_checkout_payment_url() |
772 | - ) ); |
|
772 | + )); |
|
773 | 773 | wp_die(); |
774 | 774 | } |
775 | 775 | |
776 | 776 | // Check if user has invoice with same items waiting to be paid. |
777 | - $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' ); |
|
778 | - if ( !empty( $user_invoices ) ) { |
|
779 | - foreach( $user_invoices as $user_invoice ) { |
|
777 | + $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending'); |
|
778 | + if (!empty($user_invoices)) { |
|
779 | + foreach ($user_invoices as $user_invoice) { |
|
780 | 780 | $user_cart_details = array(); |
781 | - $invoice = wpinv_get_invoice( $user_invoice->ID ); |
|
781 | + $invoice = wpinv_get_invoice($user_invoice->ID); |
|
782 | 782 | $cart_details = $invoice->get_cart_details(); |
783 | 783 | |
784 | - if ( !empty( $cart_details ) ) { |
|
785 | - foreach ( $cart_details as $invoice_item ) { |
|
784 | + if (!empty($cart_details)) { |
|
785 | + foreach ($cart_details as $invoice_item) { |
|
786 | 786 | $ii_arr = array(); |
787 | 787 | $ii_arr['id'] = (int)$invoice_item['id']; |
788 | 788 | $ii_arr['quantity'] = (int)$invoice_item['quantity']; |
789 | 789 | |
790 | - if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) { |
|
790 | + if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) { |
|
791 | 791 | $ii_arr['meta'] = $invoice_item['meta']; |
792 | 792 | } |
793 | 793 | |
794 | - if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) { |
|
794 | + if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) { |
|
795 | 795 | $ii_arr['custom_price'] = $invoice_item['custom_price']; |
796 | 796 | } |
797 | 797 | |
@@ -799,17 +799,17 @@ discard block |
||
799 | 799 | } |
800 | 800 | } |
801 | 801 | |
802 | - if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) { |
|
803 | - wp_send_json( array( |
|
802 | + if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) { |
|
803 | + wp_send_json(array( |
|
804 | 804 | 'success' => $invoice->get_checkout_payment_url() |
805 | - ) ); |
|
805 | + )); |
|
806 | 806 | wp_die(); |
807 | 807 | } |
808 | 808 | } |
809 | 809 | } |
810 | 810 | |
811 | 811 | // Create invoice and send user to checkout |
812 | - if ( !empty( $cart_items ) ) { |
|
812 | + if (!empty($cart_items)) { |
|
813 | 813 | $invoice_data = array( |
814 | 814 | 'status' => 'wpi-pending', |
815 | 815 | 'created_via' => 'wpi', |
@@ -817,21 +817,21 @@ discard block |
||
817 | 817 | 'cart_details' => $cart_items, |
818 | 818 | ); |
819 | 819 | |
820 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
820 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
821 | 821 | |
822 | - if ( !empty( $invoice ) && isset( $invoice->ID ) ) { |
|
823 | - wp_send_json( array( |
|
822 | + if (!empty($invoice) && isset($invoice->ID)) { |
|
823 | + wp_send_json(array( |
|
824 | 824 | 'success' => $invoice->get_checkout_payment_url() |
825 | - ) ); |
|
825 | + )); |
|
826 | 826 | } else { |
827 | - wp_send_json( array( |
|
828 | - 'error' => __( 'Invoice failed to create', 'invoicing' ) |
|
829 | - ) ); |
|
827 | + wp_send_json(array( |
|
828 | + 'error' => __('Invoice failed to create', 'invoicing') |
|
829 | + )); |
|
830 | 830 | } |
831 | 831 | } else { |
832 | - wp_send_json( array( |
|
833 | - 'error' => __( 'Items not valid.', 'invoicing' ) |
|
834 | - ) ); |
|
832 | + wp_send_json(array( |
|
833 | + 'error' => __('Items not valid.', 'invoicing') |
|
834 | + )); |
|
835 | 835 | } |
836 | 836 | } |
837 | 837 |