@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Returns an array of discount type. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | return apply_filters( |
18 | 18 | 'wpinv_discount_types', |
19 | 19 | array( |
20 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
21 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
20 | + 'percent' => __('Percentage', 'invoicing'), |
|
21 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
22 | 22 | ) |
23 | 23 | ); |
24 | 24 | } |
@@ -28,46 +28,46 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return string |
30 | 30 | */ |
31 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
31 | +function wpinv_get_discount_type_name($type = '') { |
|
32 | 32 | $types = wpinv_get_discount_types(); |
33 | - return isset( $types[ $type ] ) ? $types[ $type ] : $type; |
|
33 | + return isset($types[$type]) ? $types[$type] : $type; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Deletes a discount via the admin page. |
38 | 38 | * |
39 | 39 | */ |
40 | -function wpinv_delete_discount( $data ) { |
|
40 | +function wpinv_delete_discount($data) { |
|
41 | 41 | |
42 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
43 | - $discount->delete( true ); |
|
42 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
43 | + $discount->delete(true); |
|
44 | 44 | |
45 | 45 | } |
46 | -add_action( 'getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount' ); |
|
46 | +add_action('getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount'); |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Deactivates a discount via the admin page. |
50 | 50 | */ |
51 | -function wpinv_activate_discount( $data ) { |
|
51 | +function wpinv_activate_discount($data) { |
|
52 | 52 | |
53 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
54 | - $discount->set_status( 'publish' ); |
|
53 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
54 | + $discount->set_status('publish'); |
|
55 | 55 | $discount->save(); |
56 | 56 | |
57 | 57 | } |
58 | -add_action( 'getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount' ); |
|
58 | +add_action('getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount'); |
|
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Activates a discount via the admin page. |
62 | 62 | */ |
63 | -function wpinv_deactivate_discount( $data ) { |
|
63 | +function wpinv_deactivate_discount($data) { |
|
64 | 64 | |
65 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
66 | - $discount->set_status( 'pending' ); |
|
65 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
66 | + $discount->set_status('pending'); |
|
67 | 67 | $discount->save(); |
68 | 68 | |
69 | 69 | } |
70 | -add_action( 'getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
70 | +add_action('getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount'); |
|
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Fetches a discount object. |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * @since 1.0.15 |
77 | 77 | * @return WPInv_Discount |
78 | 78 | */ |
79 | -function wpinv_get_discount( $discount ) { |
|
80 | - return new WPInv_Discount( $discount ); |
|
79 | +function wpinv_get_discount($discount) { |
|
80 | + return new WPInv_Discount($discount); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | * @since 1.0.15 |
88 | 88 | * @return WPInv_Discount |
89 | 89 | */ |
90 | -function wpinv_get_discount_obj( $discount = 0 ) { |
|
91 | - return new WPInv_Discount( $discount ); |
|
90 | +function wpinv_get_discount_obj($discount = 0) { |
|
91 | + return new WPInv_Discount($discount); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -98,10 +98,10 @@ discard block |
||
98 | 98 | * @param string|int $value The field value |
99 | 99 | * @return bool|WPInv_Discount |
100 | 100 | */ |
101 | -function wpinv_get_discount_by( $deprecated = null, $value = '' ) { |
|
102 | - $discount = new WPInv_Discount( $value ); |
|
101 | +function wpinv_get_discount_by($deprecated = null, $value = '') { |
|
102 | + $discount = new WPInv_Discount($value); |
|
103 | 103 | |
104 | - if ( $discount->get_id() != 0 ) { |
|
104 | + if ($discount->get_id() != 0) { |
|
105 | 105 | return $discount; |
106 | 106 | } |
107 | 107 | |
@@ -116,9 +116,9 @@ discard block |
||
116 | 116 | function wpinv_get_discount_statuses() { |
117 | 117 | |
118 | 118 | return array( |
119 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
120 | - 'publish' => __( 'Active', 'invoicing' ), |
|
121 | - 'inactive' => __( 'Inactive', 'invoicing' ), |
|
119 | + 'expired' => __('Expired', 'invoicing'), |
|
120 | + 'publish' => __('Active', 'invoicing'), |
|
121 | + 'inactive' => __('Inactive', 'invoicing'), |
|
122 | 122 | ); |
123 | 123 | |
124 | 124 | } |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | /** |
127 | 127 | * Retrieves an invoice status label. |
128 | 128 | */ |
129 | -function wpinv_discount_status( $status ) { |
|
129 | +function wpinv_discount_status($status) { |
|
130 | 130 | $statuses = wpinv_get_discount_statuses(); |
131 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : __( 'Inactive', 'invoicing' ); |
|
131 | + return isset($statuses[$status]) ? $statuses[$status] : __('Inactive', 'invoicing'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | * @param int|array|string|WPInv_Discount $code discount data, object, ID or code. |
139 | 139 | * @return bool |
140 | 140 | */ |
141 | -function wpinv_discount_is_recurring( $discount = 0, $code = 0 ) { |
|
141 | +function wpinv_discount_is_recurring($discount = 0, $code = 0) { |
|
142 | 142 | |
143 | - if( ! empty( $discount ) ) { |
|
144 | - $discount = wpinv_get_discount_obj( $discount ); |
|
143 | + if (!empty($discount)) { |
|
144 | + $discount = wpinv_get_discount_obj($discount); |
|
145 | 145 | } else { |
146 | - $discount = wpinv_get_discount_obj( $code ); |
|
146 | + $discount = wpinv_get_discount_obj($code); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return $discount->get_is_recurring(); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * The main admin class. |
@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * Class constructor. |
32 | 32 | */ |
33 | - public function __construct(){ |
|
33 | + public function __construct() { |
|
34 | 34 | |
35 | - $this->admin_path = plugin_dir_path( __FILE__ ); |
|
36 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
35 | + $this->admin_path = plugin_dir_path(__FILE__); |
|
36 | + $this->admin_url = plugins_url('/', __FILE__); |
|
37 | 37 | |
38 | - if ( is_admin() ) { |
|
38 | + if (is_admin()) { |
|
39 | 39 | $this->init_admin_hooks(); |
40 | 40 | } |
41 | 41 | |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | * |
47 | 47 | */ |
48 | 48 | private function init_admin_hooks() { |
49 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
|
50 | - add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
|
51 | - add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
|
52 | - add_action( 'admin_init', array( $this, 'activation_redirect') ); |
|
53 | - add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
|
54 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
55 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
56 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
57 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
49 | + add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts')); |
|
50 | + add_filter('admin_body_class', array($this, 'admin_body_class')); |
|
51 | + add_action('admin_init', array($this, 'init_ayecode_connect_helper')); |
|
52 | + add_action('admin_init', array($this, 'activation_redirect')); |
|
53 | + add_action('admin_init', array($this, 'maybe_do_admin_action')); |
|
54 | + add_action('admin_notices', array($this, 'show_notices')); |
|
55 | + add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice')); |
|
56 | + add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder')); |
|
57 | + do_action('getpaid_init_admin_hooks', $this); |
|
58 | 58 | |
59 | 59 | } |
60 | 60 | |
@@ -65,49 +65,49 @@ discard block |
||
65 | 65 | public function enqeue_scripts() { |
66 | 66 | global $current_screen, $pagenow; |
67 | 67 | |
68 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
68 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
69 | 69 | $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
70 | 70 | |
71 | - if ( ! empty( $current_screen->post_type ) ) { |
|
71 | + if (!empty($current_screen->post_type)) { |
|
72 | 72 | $page = $current_screen->post_type; |
73 | 73 | } |
74 | 74 | |
75 | 75 | // General styles. |
76 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
76 | + if (false !== stripos($page, 'wpi')) { |
|
77 | 77 | |
78 | 78 | // Styles. |
79 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
80 | - wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version ); |
|
81 | - wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' ); |
|
82 | - wp_enqueue_style( 'wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
83 | - wp_enqueue_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16' ); |
|
79 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css'); |
|
80 | + wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version); |
|
81 | + wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all'); |
|
82 | + wp_enqueue_style('wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
83 | + wp_enqueue_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16'); |
|
84 | 84 | |
85 | 85 | // Scripts. |
86 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '4.0.13', true ); |
|
87 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION ); |
|
86 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '4.0.13', true); |
|
87 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION); |
|
88 | 88 | |
89 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
90 | - wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker' ), $version ); |
|
91 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) ); |
|
89 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js'); |
|
90 | + wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker'), $version); |
|
91 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18())); |
|
92 | 92 | |
93 | 93 | } |
94 | 94 | |
95 | 95 | // Payment form scripts. |
96 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
96 | + if ('wpi_payment_form' == $page && $editing) { |
|
97 | 97 | $this->load_payment_form_scripts(); |
98 | 98 | } |
99 | 99 | |
100 | - if ( $page == 'wpinv-subscriptions' ) { |
|
101 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
102 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
100 | + if ($page == 'wpinv-subscriptions') { |
|
101 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
102 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
103 | 103 | } |
104 | 104 | |
105 | - if ( $page == 'wpinv-reports' ) { |
|
106 | - wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
105 | + if ($page == 'wpinv-reports') { |
|
106 | + wp_enqueue_script('jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array('jquery'), '0.7'); |
|
107 | 107 | } |
108 | 108 | |
109 | - if ( $page == 'wpinv-subscriptions' ) { |
|
110 | - wp_enqueue_script( 'postbox' ); |
|
109 | + if ($page == 'wpinv-subscriptions') { |
|
110 | + wp_enqueue_script('postbox'); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | } |
@@ -120,13 +120,13 @@ discard block |
||
120 | 120 | global $post; |
121 | 121 | |
122 | 122 | $i18n = array( |
123 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
124 | - 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
|
125 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
126 | - 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
|
127 | - 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
|
128 | - 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
|
129 | - 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
|
123 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
124 | + 'post_ID' => isset($post->ID) ? $post->ID : '', |
|
125 | + 'wpinv_nonce' => wp_create_nonce('wpinv-nonce'), |
|
126 | + 'add_invoice_note_nonce' => wp_create_nonce('add-invoice-note'), |
|
127 | + 'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'), |
|
128 | + 'invoice_item_nonce' => wp_create_nonce('invoice-item'), |
|
129 | + 'billing_details_nonce' => wp_create_nonce('get-billing-details'), |
|
130 | 130 | 'tax' => wpinv_tax_amount(), |
131 | 131 | 'discount' => 0, |
132 | 132 | 'currency_symbol' => wpinv_currency_symbol(), |
@@ -134,35 +134,35 @@ discard block |
||
134 | 134 | 'thousand_sep' => wpinv_thousands_separator(), |
135 | 135 | 'decimal_sep' => wpinv_decimal_separator(), |
136 | 136 | 'decimals' => wpinv_decimals(), |
137 | - 'save_invoice' => __( 'Save Invoice', 'invoicing' ), |
|
138 | - 'status_publish' => wpinv_status_nicename( 'publish' ), |
|
139 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
140 | - 'delete_tax_rate' => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ), |
|
141 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
142 | - 'FillBillingDetails' => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ), |
|
143 | - 'confirmCalcTotals' => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ), |
|
144 | - 'AreYouSure' => __( 'Are you sure?', 'invoicing' ), |
|
145 | - 'errDeleteItem' => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ), |
|
146 | - 'delete_subscription' => __( 'Are you sure you want to delete this subscription?', 'invoicing' ), |
|
147 | - 'action_edit' => __( 'Edit', 'invoicing' ), |
|
148 | - 'action_cancel' => __( 'Cancel', 'invoicing' ), |
|
149 | - 'item_description' => __( 'Item Description', 'invoicing' ), |
|
150 | - 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
|
151 | - 'discount_description' => __( 'Discount Description', 'invoicing' ), |
|
152 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
137 | + 'save_invoice' => __('Save Invoice', 'invoicing'), |
|
138 | + 'status_publish' => wpinv_status_nicename('publish'), |
|
139 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
140 | + 'delete_tax_rate' => __('Are you sure you wish to delete this tax rate?', 'invoicing'), |
|
141 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
142 | + 'FillBillingDetails' => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'), |
|
143 | + 'confirmCalcTotals' => __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'), |
|
144 | + 'AreYouSure' => __('Are you sure?', 'invoicing'), |
|
145 | + 'errDeleteItem' => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'), |
|
146 | + 'delete_subscription' => __('Are you sure you want to delete this subscription?', 'invoicing'), |
|
147 | + 'action_edit' => __('Edit', 'invoicing'), |
|
148 | + 'action_cancel' => __('Cancel', 'invoicing'), |
|
149 | + 'item_description' => __('Item Description', 'invoicing'), |
|
150 | + 'invoice_description' => __('Invoice Description', 'invoicing'), |
|
151 | + 'discount_description' => __('Discount Description', 'invoicing'), |
|
152 | + 'searching' => __('Searching', 'invoicing'), |
|
153 | 153 | ); |
154 | 154 | |
155 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
155 | + if (!empty($post) && getpaid_is_invoice_post_type($post->post_type)) { |
|
156 | 156 | |
157 | - $invoice = new WPInv_Invoice( $post ); |
|
157 | + $invoice = new WPInv_Invoice($post); |
|
158 | 158 | $i18n['save_invoice'] = sprintf( |
159 | - __( 'Save %s', 'invoicing' ), |
|
160 | - ucfirst( $invoice->get_type() ) |
|
159 | + __('Save %s', 'invoicing'), |
|
160 | + ucfirst($invoice->get_type()) |
|
161 | 161 | ); |
162 | 162 | |
163 | 163 | $i18n['invoice_description'] = sprintf( |
164 | - __( '%s Description', 'invoicing' ), |
|
165 | - ucfirst( $invoice->get_type() ) |
|
164 | + __('%s Description', 'invoicing'), |
|
165 | + ucfirst($invoice->get_type()) |
|
166 | 166 | ); |
167 | 167 | |
168 | 168 | } |
@@ -176,30 +176,30 @@ discard block |
||
176 | 176 | protected function load_payment_form_scripts() { |
177 | 177 | global $post; |
178 | 178 | |
179 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
|
180 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
181 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
179 | + wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION); |
|
180 | + wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION); |
|
181 | + wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION); |
|
182 | 182 | |
183 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
184 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
183 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js'); |
|
184 | + wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version); |
|
185 | 185 | |
186 | 186 | wp_localize_script( |
187 | 187 | 'wpinv-admin-payment-form-script', |
188 | 188 | 'wpinvPaymentFormAdmin', |
189 | 189 | array( |
190 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
191 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
190 | + 'elements' => wpinv_get_data('payment-form-elements'), |
|
191 | + 'form_elements' => getpaid_get_payment_form_elements($post->ID), |
|
192 | 192 | 'currency' => wpinv_currency_symbol(), |
193 | 193 | 'position' => wpinv_currency_position(), |
194 | 194 | 'decimals' => (int) wpinv_decimals(), |
195 | 195 | 'thousands_sep' => wpinv_thousands_separator(), |
196 | 196 | 'decimals_sep' => wpinv_decimal_separator(), |
197 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
197 | + 'form_items' => gepaid_get_form_items($post->ID), |
|
198 | 198 | 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
199 | 199 | ) |
200 | 200 | ); |
201 | 201 | |
202 | - wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
202 | + wp_enqueue_script('wpinv-admin-payment-form-script'); |
|
203 | 203 | |
204 | 204 | } |
205 | 205 | |
@@ -210,29 +210,29 @@ discard block |
||
210 | 210 | * @return string |
211 | 211 | * |
212 | 212 | */ |
213 | - public function admin_body_class( $classes ) { |
|
213 | + public function admin_body_class($classes) { |
|
214 | 214 | global $pagenow, $post, $current_screen; |
215 | 215 | |
216 | 216 | |
217 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
217 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
218 | 218 | |
219 | - if ( ! empty( $current_screen->post_type ) ) { |
|
219 | + if (!empty($current_screen->post_type)) { |
|
220 | 220 | $page = $current_screen->post_type; |
221 | 221 | } |
222 | 222 | |
223 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
224 | - $classes .= ' wpi-' . sanitize_key( $page ); |
|
223 | + if (false !== stripos($page, 'wpi')) { |
|
224 | + $classes .= ' wpi-' . sanitize_key($page); |
|
225 | 225 | } |
226 | 226 | |
227 | - if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
|
227 | + if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) { |
|
228 | 228 | $classes .= ' wpinv-cpt wpinv'; |
229 | 229 | } |
230 | 230 | |
231 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
231 | + if (getpaid_is_invoice_post_type($page)) { |
|
232 | 232 | $classes .= ' getpaid-is-invoice-cpt'; |
233 | 233 | } |
234 | 234 | |
235 | - if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) { |
|
235 | + if ($pagenow == 'post.php' && $page == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
236 | 236 | $classes .= ' wpi-editable-n'; |
237 | 237 | } |
238 | 238 | |
@@ -242,19 +242,19 @@ discard block |
||
242 | 242 | /** |
243 | 243 | * Maybe show the AyeCode Connect Notice. |
244 | 244 | */ |
245 | - public function init_ayecode_connect_helper(){ |
|
245 | + public function init_ayecode_connect_helper() { |
|
246 | 246 | |
247 | 247 | new AyeCode_Connect_Helper( |
248 | 248 | array( |
249 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
250 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
251 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
252 | - 'connect_button' => __("Connect Site","invoicing"), |
|
253 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
254 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
255 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
249 | + 'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"), |
|
250 | + 'connect_external' => __("Please confirm you wish to connect your site?", "invoicing"), |
|
251 | + 'connect' => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"), |
|
252 | + 'connect_button' => __("Connect Site", "invoicing"), |
|
253 | + 'connecting_button' => __("Connecting...", "invoicing"), |
|
254 | + 'error_localhost' => __("This service will only work with a live domain, not a localhost.", "invoicing"), |
|
255 | + 'error' => __("Something went wrong, please refresh and try again.", "invoicing"), |
|
256 | 256 | ), |
257 | - array( 'wpi-addons' ) |
|
257 | + array('wpi-addons') |
|
258 | 258 | ); |
259 | 259 | |
260 | 260 | } |
@@ -265,19 +265,19 @@ discard block |
||
265 | 265 | public function activation_redirect() { |
266 | 266 | |
267 | 267 | // Bail if no activation redirect. |
268 | - if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
268 | + if (!get_transient('_wpinv_activation_redirect') || wp_doing_ajax()) { |
|
269 | 269 | return; |
270 | 270 | } |
271 | 271 | |
272 | 272 | // Delete the redirect transient. |
273 | - delete_transient( '_wpinv_activation_redirect' ); |
|
273 | + delete_transient('_wpinv_activation_redirect'); |
|
274 | 274 | |
275 | 275 | // Bail if activating from network, or bulk |
276 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
276 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
277 | 277 | return; |
278 | 278 | } |
279 | 279 | |
280 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
280 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
281 | 281 | exit; |
282 | 282 | } |
283 | 283 | |
@@ -286,9 +286,9 @@ discard block |
||
286 | 286 | */ |
287 | 287 | public function maybe_do_admin_action() { |
288 | 288 | |
289 | - if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
290 | - $key = sanitize_key( $_REQUEST['getpaid-admin-action'] ); |
|
291 | - do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST ); |
|
289 | + if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
290 | + $key = sanitize_key($_REQUEST['getpaid-admin-action']); |
|
291 | + do_action("getpaid_authenticated_admin_action_$key", $_REQUEST); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | } |
@@ -298,16 +298,16 @@ discard block |
||
298 | 298 | * |
299 | 299 | * @param array $args |
300 | 300 | */ |
301 | - public function send_customer_invoice( $args ) { |
|
302 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
301 | + public function send_customer_invoice($args) { |
|
302 | + $sent = getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id'])); |
|
303 | 303 | |
304 | - if ( $sent ) { |
|
305 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
304 | + if ($sent) { |
|
305 | + $this->show_success(__('Invoice was successfully sent to the customer', 'invoicing')); |
|
306 | 306 | } else { |
307 | - $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
307 | + $this->show_error(__('Could not sent the invoice to the customer', 'invoicing')); |
|
308 | 308 | } |
309 | 309 | |
310 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
310 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
311 | 311 | exit; |
312 | 312 | } |
313 | 313 | |
@@ -316,16 +316,16 @@ discard block |
||
316 | 316 | * |
317 | 317 | * @param array $args |
318 | 318 | */ |
319 | - public function send_customer_payment_reminder( $args ) { |
|
320 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
319 | + public function send_customer_payment_reminder($args) { |
|
320 | + $sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id'])); |
|
321 | 321 | |
322 | - if ( $sent ) { |
|
323 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
322 | + if ($sent) { |
|
323 | + $this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing')); |
|
324 | 324 | } else { |
325 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
325 | + $this->show_error(__('Could not sent payment reminder to the customer', 'invoicing')); |
|
326 | 326 | } |
327 | 327 | |
328 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
328 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
329 | 329 | exit; |
330 | 330 | } |
331 | 331 | |
@@ -336,8 +336,8 @@ discard block |
||
336 | 336 | * @return array |
337 | 337 | */ |
338 | 338 | public function get_notices() { |
339 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
340 | - return is_array( $notices ) ? $notices : array(); |
|
339 | + $notices = get_option('wpinv_admin_notices'); |
|
340 | + return is_array($notices) ? $notices : array(); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | * @since 1.0.19 |
348 | 348 | */ |
349 | 349 | public function clear_notices() { |
350 | - delete_option( 'wpinv_admin_notices' ); |
|
350 | + delete_option('wpinv_admin_notices'); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -356,16 +356,16 @@ discard block |
||
356 | 356 | * @access public |
357 | 357 | * @since 1.0.19 |
358 | 358 | */ |
359 | - public function save_notice( $type, $message ) { |
|
359 | + public function save_notice($type, $message) { |
|
360 | 360 | $notices = $this->get_notices(); |
361 | 361 | |
362 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
363 | - $notices[ $type ] = array(); |
|
362 | + if (empty($notices[$type]) || !is_array($notices[$type])) { |
|
363 | + $notices[$type] = array(); |
|
364 | 364 | } |
365 | 365 | |
366 | - $notices[ $type ][] = $message; |
|
366 | + $notices[$type][] = $message; |
|
367 | 367 | |
368 | - update_option( 'wpinv_admin_notices', $notices ); |
|
368 | + update_option('wpinv_admin_notices', $notices); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | /** |
@@ -375,8 +375,8 @@ discard block |
||
375 | 375 | * @access public |
376 | 376 | * @since 1.0.19 |
377 | 377 | */ |
378 | - public function show_success( $msg ) { |
|
379 | - $this->save_notice( 'success', $msg ); |
|
378 | + public function show_success($msg) { |
|
379 | + $this->save_notice('success', $msg); |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | /** |
@@ -386,8 +386,8 @@ discard block |
||
386 | 386 | * @param string $msg The message to qeue. |
387 | 387 | * @since 1.0.19 |
388 | 388 | */ |
389 | - public function show_error( $msg ) { |
|
390 | - $this->save_notice( 'error', $msg ); |
|
389 | + public function show_error($msg) { |
|
390 | + $this->save_notice('error', $msg); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | /** |
@@ -397,8 +397,8 @@ discard block |
||
397 | 397 | * @param string $msg The message to qeue. |
398 | 398 | * @since 1.0.19 |
399 | 399 | */ |
400 | - public function show_warning( $msg ) { |
|
401 | - $this->save_notice( 'warning', $msg ); |
|
400 | + public function show_warning($msg) { |
|
401 | + $this->save_notice('warning', $msg); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | /** |
@@ -408,8 +408,8 @@ discard block |
||
408 | 408 | * @param string $msg The message to qeue. |
409 | 409 | * @since 1.0.19 |
410 | 410 | */ |
411 | - public function show_info( $msg ) { |
|
412 | - $this->save_notice( 'info', $msg ); |
|
411 | + public function show_info($msg) { |
|
412 | + $this->save_notice('info', $msg); |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | /** |
@@ -423,15 +423,15 @@ discard block |
||
423 | 423 | $notices = $this->get_notices(); |
424 | 424 | $this->clear_notices(); |
425 | 425 | |
426 | - foreach ( $notices as $type => $messages ) { |
|
426 | + foreach ($notices as $type => $messages) { |
|
427 | 427 | |
428 | - if ( ! is_array( $messages ) ) { |
|
428 | + if (!is_array($messages)) { |
|
429 | 429 | continue; |
430 | 430 | } |
431 | 431 | |
432 | - $type = sanitize_key( $type ); |
|
433 | - foreach ( $messages as $message ) { |
|
434 | - $message = wp_kses_post( $message ); |
|
432 | + $type = sanitize_key($type); |
|
433 | + foreach ($messages as $message) { |
|
434 | + $message = wp_kses_post($message); |
|
435 | 435 | echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
436 | 436 | } |
437 | 437 |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | 'getpaid-nonce' |
64 | 64 | ) |
65 | 65 | ); |
66 | - $anchor = __( 'Deactivate', 'invoicing' ); |
|
67 | - $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
66 | + $anchor = __( 'Deactivate', 'invoicing' ); |
|
67 | + $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
68 | 68 | $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
69 | 69 | |
70 | 70 | } else if( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | 'getpaid-nonce' |
82 | 82 | ) |
83 | 83 | ); |
84 | - $anchor = __( 'Activate', 'invoicing' ); |
|
85 | - $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
84 | + $anchor = __( 'Activate', 'invoicing' ); |
|
85 | + $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
86 | 86 | $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
87 | 87 | |
88 | 88 | } |
@@ -99,8 +99,8 @@ discard block |
||
99 | 99 | 'getpaid-nonce' |
100 | 100 | ) |
101 | 101 | ); |
102 | - $anchor = __( 'Delete', 'invoicing' ); |
|
103 | - $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
102 | + $anchor = __( 'Delete', 'invoicing' ); |
|
103 | + $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
104 | 104 | $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
105 | 105 | |
106 | 106 | $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
@@ -1,16 +1,16 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | -add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' ); |
|
8 | -function wpinv_discount_custom_column( $column ) { |
|
7 | +add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column'); |
|
8 | +function wpinv_discount_custom_column($column) { |
|
9 | 9 | global $post; |
10 | 10 | |
11 | - $discount = new WPInv_Discount( $post ); |
|
11 | + $discount = new WPInv_Discount($post); |
|
12 | 12 | |
13 | - switch ( $column ) { |
|
13 | + switch ($column) { |
|
14 | 14 | case 'code' : |
15 | 15 | echo $discount->get_code(); |
16 | 16 | break; |
@@ -21,37 +21,37 @@ discard block |
||
21 | 21 | echo $discount->get_usage(); |
22 | 22 | break; |
23 | 23 | case 'start_date' : |
24 | - echo getpaid_format_date_value( $discount->get_start_date() ); |
|
24 | + echo getpaid_format_date_value($discount->get_start_date()); |
|
25 | 25 | break; |
26 | 26 | case 'expiry_date' : |
27 | - echo getpaid_format_date_value( $discount->get_expiration_date(), __( 'Never', 'invoicing' ) ); |
|
27 | + echo getpaid_format_date_value($discount->get_expiration_date(), __('Never', 'invoicing')); |
|
28 | 28 | break; |
29 | 29 | } |
30 | 30 | } |
31 | 31 | |
32 | -add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 ); |
|
33 | -function wpinv_post_row_actions( $actions, $post ) { |
|
34 | - $post_type = !empty( $post->post_type ) ? $post->post_type : ''; |
|
32 | +add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2); |
|
33 | +function wpinv_post_row_actions($actions, $post) { |
|
34 | + $post_type = !empty($post->post_type) ? $post->post_type : ''; |
|
35 | 35 | |
36 | - if ( $post_type == 'wpi_invoice' ) { |
|
36 | + if ($post_type == 'wpi_invoice') { |
|
37 | 37 | $actions = array(); |
38 | 38 | } |
39 | 39 | |
40 | - if ( $post_type == 'wpi_discount' ) { |
|
41 | - $actions = wpinv_discount_row_actions( $post, $actions ); |
|
40 | + if ($post_type == 'wpi_discount') { |
|
41 | + $actions = wpinv_discount_row_actions($post, $actions); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | return $actions; |
45 | 45 | } |
46 | 46 | |
47 | -function wpinv_discount_row_actions( $discount, $row_actions ) { |
|
48 | - $row_actions = array(); |
|
49 | - $edit_link = get_edit_post_link( $discount->ID ); |
|
50 | - $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>'; |
|
47 | +function wpinv_discount_row_actions($discount, $row_actions) { |
|
48 | + $row_actions = array(); |
|
49 | + $edit_link = get_edit_post_link($discount->ID); |
|
50 | + $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>'; |
|
51 | 51 | |
52 | - if ( in_array( strtolower( $discount->post_status ), array( 'publish' ) ) ) { |
|
52 | + if (in_array(strtolower($discount->post_status), array('publish'))) { |
|
53 | 53 | |
54 | - $url = esc_url( |
|
54 | + $url = esc_url( |
|
55 | 55 | wp_nonce_url( |
56 | 56 | add_query_arg( |
57 | 57 | array( |
@@ -63,13 +63,13 @@ discard block |
||
63 | 63 | 'getpaid-nonce' |
64 | 64 | ) |
65 | 65 | ); |
66 | - $anchor = __( 'Deactivate', 'invoicing' ); |
|
67 | - $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
66 | + $anchor = __('Deactivate', 'invoicing'); |
|
67 | + $title = esc_attr__('Are you sure you want to deactivate this discount?', 'invoicing'); |
|
68 | 68 | $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
69 | 69 | |
70 | - } else if( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
|
70 | + } else if (in_array(strtolower($discount->post_status), array('pending', 'draft'))) { |
|
71 | 71 | |
72 | - $url = esc_url( |
|
72 | + $url = esc_url( |
|
73 | 73 | wp_nonce_url( |
74 | 74 | add_query_arg( |
75 | 75 | array( |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | 'getpaid-nonce' |
82 | 82 | ) |
83 | 83 | ); |
84 | - $anchor = __( 'Activate', 'invoicing' ); |
|
85 | - $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
84 | + $anchor = __('Activate', 'invoicing'); |
|
85 | + $title = esc_attr__('Are you sure you want to activate this discount?', 'invoicing'); |
|
86 | 86 | $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
87 | 87 | |
88 | 88 | } |
89 | 89 | |
90 | - $url = esc_url( |
|
90 | + $url = esc_url( |
|
91 | 91 | wp_nonce_url( |
92 | 92 | add_query_arg( |
93 | 93 | array( |
@@ -99,81 +99,81 @@ discard block |
||
99 | 99 | 'getpaid-nonce' |
100 | 100 | ) |
101 | 101 | ); |
102 | - $anchor = __( 'Delete', 'invoicing' ); |
|
103 | - $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
102 | + $anchor = __('Delete', 'invoicing'); |
|
103 | + $title = esc_attr__('Are you sure you want to delete this discount?', 'invoicing'); |
|
104 | 104 | $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
105 | 105 | |
106 | - $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
|
106 | + $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount); |
|
107 | 107 | |
108 | 108 | return $row_actions; |
109 | 109 | } |
110 | 110 | |
111 | -add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 ); |
|
112 | -function wpinv_table_primary_column( $default, $screen_id ) { |
|
113 | - if ( 'edit-wpi_invoice' === $screen_id ) { |
|
111 | +add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2); |
|
112 | +function wpinv_table_primary_column($default, $screen_id) { |
|
113 | + if ('edit-wpi_invoice' === $screen_id) { |
|
114 | 114 | return 'name'; |
115 | 115 | } |
116 | 116 | |
117 | 117 | return $default; |
118 | 118 | } |
119 | 119 | |
120 | -function wpinv_disable_months_dropdown( $disable, $post_type ) { |
|
121 | - if ( $post_type == 'wpi_discount' ) { |
|
120 | +function wpinv_disable_months_dropdown($disable, $post_type) { |
|
121 | + if ($post_type == 'wpi_discount') { |
|
122 | 122 | $disable = true; |
123 | 123 | } |
124 | 124 | |
125 | 125 | return $disable; |
126 | 126 | } |
127 | -add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 ); |
|
127 | +add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2); |
|
128 | 128 | |
129 | 129 | function wpinv_restrict_manage_posts() { |
130 | 130 | global $typenow; |
131 | 131 | |
132 | - if( 'wpi_discount' == $typenow ) { |
|
132 | + if ('wpi_discount' == $typenow) { |
|
133 | 133 | wpinv_discount_filters(); |
134 | 134 | } |
135 | 135 | } |
136 | -add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 ); |
|
136 | +add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10); |
|
137 | 137 | |
138 | 138 | function wpinv_discount_filters() { |
139 | 139 | |
140 | 140 | ?> |
141 | 141 | <select name="discount_type" id="dropdown_wpinv_discount_type"> |
142 | - <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option> |
|
142 | + <option value=""><?php _e('Show all types', 'invoicing'); ?></option> |
|
143 | 143 | <?php |
144 | 144 | $types = wpinv_get_discount_types(); |
145 | 145 | |
146 | - foreach ( $types as $name => $type ) { |
|
147 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
146 | + foreach ($types as $name => $type) { |
|
147 | + echo '<option value="' . esc_attr($name) . '"'; |
|
148 | 148 | |
149 | - if ( isset( $_GET['discount_type'] ) ) |
|
150 | - selected( $name, $_GET['discount_type'] ); |
|
149 | + if (isset($_GET['discount_type'])) |
|
150 | + selected($name, $_GET['discount_type']); |
|
151 | 151 | |
152 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
152 | + echo '>' . esc_html__($type, 'invoicing') . '</option>'; |
|
153 | 153 | } |
154 | 154 | ?> |
155 | 155 | </select> |
156 | 156 | <?php |
157 | 157 | } |
158 | 158 | |
159 | -function wpinv_request( $vars ) { |
|
159 | +function wpinv_request($vars) { |
|
160 | 160 | global $typenow, $wp_query, $wp_post_statuses; |
161 | 161 | |
162 | - if ( getpaid_is_invoice_post_type( $typenow ) ) { |
|
163 | - if ( !isset( $vars['post_status'] ) ) { |
|
164 | - $post_statuses = wpinv_get_invoice_statuses( false, false, $typenow ); |
|
162 | + if (getpaid_is_invoice_post_type($typenow)) { |
|
163 | + if (!isset($vars['post_status'])) { |
|
164 | + $post_statuses = wpinv_get_invoice_statuses(false, false, $typenow); |
|
165 | 165 | |
166 | - foreach ( $post_statuses as $status => $value ) { |
|
167 | - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { |
|
168 | - unset( $post_statuses[ $status ] ); |
|
166 | + foreach ($post_statuses as $status => $value) { |
|
167 | + if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) { |
|
168 | + unset($post_statuses[$status]); |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | - $vars['post_status'] = array_keys( $post_statuses ); |
|
172 | + $vars['post_status'] = array_keys($post_statuses); |
|
173 | 173 | } |
174 | 174 | |
175 | - if ( isset( $vars['orderby'] ) ) { |
|
176 | - if ( 'amount' == $vars['orderby'] ) { |
|
175 | + if (isset($vars['orderby'])) { |
|
176 | + if ('amount' == $vars['orderby']) { |
|
177 | 177 | $vars = array_merge( |
178 | 178 | $vars, |
179 | 179 | array( |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | 'orderby' => 'meta_value_num' |
182 | 182 | ) |
183 | 183 | ); |
184 | - } else if ( 'customer' == $vars['orderby'] ) { |
|
184 | + } else if ('customer' == $vars['orderby']) { |
|
185 | 185 | $vars = array_merge( |
186 | 186 | $vars, |
187 | 187 | array( |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | 'orderby' => 'meta_value' |
190 | 190 | ) |
191 | 191 | ); |
192 | - } else if ( 'number' == $vars['orderby'] ) { |
|
192 | + } else if ('number' == $vars['orderby']) { |
|
193 | 193 | $vars = array_merge( |
194 | 194 | $vars, |
195 | 195 | array( |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | 'orderby' => 'meta_value' |
198 | 198 | ) |
199 | 199 | ); |
200 | - } else if ( 'payment_date' == $vars['orderby'] ) { |
|
200 | + } else if ('payment_date' == $vars['orderby']) { |
|
201 | 201 | $vars = array_merge( |
202 | 202 | $vars, |
203 | 203 | array( |
@@ -207,73 +207,73 @@ discard block |
||
207 | 207 | ); |
208 | 208 | } |
209 | 209 | } |
210 | - } else if ( 'wpi_discount' == $typenow ) { |
|
211 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
210 | + } else if ('wpi_discount' == $typenow) { |
|
211 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
212 | 212 | // Filter vat rule type |
213 | - if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
|
213 | + if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') { |
|
214 | 214 | $meta_query[] = array( |
215 | 215 | 'key' => '_wpi_discount_type', |
216 | - 'value' => sanitize_text_field( $_GET['discount_type'] ), |
|
216 | + 'value' => sanitize_text_field($_GET['discount_type']), |
|
217 | 217 | 'compare' => '=' |
218 | 218 | ); |
219 | 219 | } |
220 | 220 | |
221 | - if ( !empty( $meta_query ) ) { |
|
221 | + if (!empty($meta_query)) { |
|
222 | 222 | $vars['meta_query'] = $meta_query; |
223 | 223 | } |
224 | 224 | } |
225 | 225 | |
226 | 226 | return $vars; |
227 | 227 | } |
228 | -add_filter( 'request', 'wpinv_request' ); |
|
228 | +add_filter('request', 'wpinv_request'); |
|
229 | 229 | |
230 | -function wpinv_item_type_class( $classes, $class, $post_id ) { |
|
230 | +function wpinv_item_type_class($classes, $class, $post_id) { |
|
231 | 231 | global $pagenow, $typenow; |
232 | 232 | |
233 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) { |
|
234 | - if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) { |
|
235 | - $classes[] = 'wpi-type-' . sanitize_html_class( $type ); |
|
233 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) { |
|
234 | + if ($type = get_post_meta($post_id, '_wpinv_type', true)) { |
|
235 | + $classes[] = 'wpi-type-' . sanitize_html_class($type); |
|
236 | 236 | } |
237 | 237 | |
238 | - if ( !wpinv_item_is_editable( $post_id ) ) { |
|
238 | + if (!wpinv_item_is_editable($post_id)) { |
|
239 | 239 | $classes[] = 'wpi-editable-n'; |
240 | 240 | } |
241 | 241 | } |
242 | 242 | return $classes; |
243 | 243 | } |
244 | -add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 ); |
|
244 | +add_filter('post_class', 'wpinv_item_type_class', 10, 3); |
|
245 | 245 | |
246 | 246 | function wpinv_check_quick_edit() { |
247 | 247 | global $pagenow, $current_screen, $wpinv_item_screen; |
248 | 248 | |
249 | - if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) { |
|
250 | - if ( empty( $wpinv_item_screen ) ) { |
|
251 | - if ( $current_screen->post_type == 'wpi_item' ) { |
|
249 | + if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) { |
|
250 | + if (empty($wpinv_item_screen)) { |
|
251 | + if ($current_screen->post_type == 'wpi_item') { |
|
252 | 252 | $wpinv_item_screen = 'y'; |
253 | 253 | } else { |
254 | 254 | $wpinv_item_screen = 'n'; |
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
258 | - if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) { |
|
259 | - add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
260 | - add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
258 | + if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') { |
|
259 | + add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
260 | + add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
261 | 261 | } |
262 | 262 | } |
263 | 263 | } |
264 | -add_action( 'admin_head', 'wpinv_check_quick_edit', 10 ); |
|
264 | +add_action('admin_head', 'wpinv_check_quick_edit', 10); |
|
265 | 265 | |
266 | -function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) { |
|
267 | - if ( isset( $actions['inline hide-if-no-js'] ) ) { |
|
268 | - unset( $actions['inline hide-if-no-js'] ); |
|
266 | +function wpinv_item_disable_quick_edit($actions = array(), $row = null) { |
|
267 | + if (isset($actions['inline hide-if-no-js'])) { |
|
268 | + unset($actions['inline hide-if-no-js']); |
|
269 | 269 | } |
270 | 270 | |
271 | - if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) { |
|
272 | - if ( isset( $actions['trash'] ) ) { |
|
273 | - unset( $actions['trash'] ); |
|
271 | + if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) { |
|
272 | + if (isset($actions['trash'])) { |
|
273 | + unset($actions['trash']); |
|
274 | 274 | } |
275 | - if ( isset( $actions['delete'] ) ) { |
|
276 | - unset( $actions['delete'] ); |
|
275 | + if (isset($actions['delete'])) { |
|
276 | + unset($actions['delete']); |
|
277 | 277 | } |
278 | 278 | } |
279 | 279 | |
@@ -290,19 +290,19 @@ discard block |
||
290 | 290 | * @param int $post_parent (default: 0) Parent for the new page |
291 | 291 | * @return int page ID |
292 | 292 | */ |
293 | -function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) { |
|
293 | +function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) { |
|
294 | 294 | global $wpdb; |
295 | 295 | |
296 | - $option_value = wpinv_get_option( $option ); |
|
296 | + $option_value = wpinv_get_option($option); |
|
297 | 297 | |
298 | - if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) { |
|
299 | - if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) { |
|
298 | + if ($option_value > 0 && ($page_object = get_post($option_value))) { |
|
299 | + if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) { |
|
300 | 300 | // Valid page is already in place |
301 | 301 | return $page_object->ID; |
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
305 | - if(!empty($post_parent)){ |
|
305 | + if (!empty($post_parent)) { |
|
306 | 306 | $page = get_page_by_path($post_parent); |
307 | 307 | if ($page) { |
308 | 308 | $post_parent = $page->ID; |
@@ -311,40 +311,40 @@ discard block |
||
311 | 311 | } |
312 | 312 | } |
313 | 313 | |
314 | - if ( strlen( $page_content ) > 0 ) { |
|
314 | + if (strlen($page_content) > 0) { |
|
315 | 315 | // Search for an existing page with the specified page content (typically a shortcode) |
316 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
316 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
317 | 317 | } else { |
318 | 318 | // Search for an existing page with the specified page slug |
319 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) ); |
|
319 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug)); |
|
320 | 320 | } |
321 | 321 | |
322 | - $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content ); |
|
322 | + $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content); |
|
323 | 323 | |
324 | - if ( $valid_page_found ) { |
|
325 | - if ( $option ) { |
|
326 | - wpinv_update_option( $option, $valid_page_found ); |
|
324 | + if ($valid_page_found) { |
|
325 | + if ($option) { |
|
326 | + wpinv_update_option($option, $valid_page_found); |
|
327 | 327 | } |
328 | 328 | return $valid_page_found; |
329 | 329 | } |
330 | 330 | |
331 | 331 | // Search for a matching valid trashed page |
332 | - if ( strlen( $page_content ) > 0 ) { |
|
332 | + if (strlen($page_content) > 0) { |
|
333 | 333 | // Search for an existing page with the specified page content (typically a shortcode) |
334 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
334 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
335 | 335 | } else { |
336 | 336 | // Search for an existing page with the specified page slug |
337 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) ); |
|
337 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug)); |
|
338 | 338 | } |
339 | 339 | |
340 | - if ( $trashed_page_found ) { |
|
340 | + if ($trashed_page_found) { |
|
341 | 341 | $page_id = $trashed_page_found; |
342 | 342 | $page_data = array( |
343 | 343 | 'ID' => $page_id, |
344 | 344 | 'post_status' => 'publish', |
345 | 345 | 'post_parent' => $post_parent, |
346 | 346 | ); |
347 | - wp_update_post( $page_data ); |
|
347 | + wp_update_post($page_data); |
|
348 | 348 | } else { |
349 | 349 | $page_data = array( |
350 | 350 | 'post_status' => 'publish', |
@@ -356,11 +356,11 @@ discard block |
||
356 | 356 | 'post_parent' => $post_parent, |
357 | 357 | 'comment_status' => 'closed', |
358 | 358 | ); |
359 | - $page_id = wp_insert_post( $page_data ); |
|
359 | + $page_id = wp_insert_post($page_data); |
|
360 | 360 | } |
361 | 361 | |
362 | - if ( $option ) { |
|
363 | - wpinv_update_option( $option, (int)$page_id ); |
|
362 | + if ($option) { |
|
363 | + wpinv_update_option($option, (int) $page_id); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | return $page_id; |
@@ -13,617 +13,617 @@ discard block |
||
13 | 13 | class GetPaid_Post_Types_Admin { |
14 | 14 | |
15 | 15 | /** |
16 | - * Hook in methods. |
|
17 | - */ |
|
18 | - public static function init() { |
|
19 | - |
|
20 | - // Init metaboxes. |
|
21 | - GetPaid_Metaboxes::init(); |
|
22 | - |
|
23 | - // Filter the post updated messages. |
|
24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
25 | - |
|
26 | - // Filter post actions. |
|
27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
28 | - |
|
29 | - // Invoice table columns. |
|
30 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
31 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
32 | - |
|
33 | - // Items table columns. |
|
34 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
35 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
36 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
37 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
38 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
39 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
40 | - |
|
41 | - // Payment forms columns. |
|
42 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
43 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
44 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
45 | - |
|
46 | - // Discount table columns. |
|
47 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
48 | - add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
49 | - |
|
50 | - // Deleting posts. |
|
51 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
52 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Post updated messages. |
|
57 | - */ |
|
58 | - public static function post_updated_messages( $messages ) { |
|
59 | - global $post; |
|
60 | - |
|
61 | - $messages['wpi_discount'] = array( |
|
62 | - 0 => '', |
|
63 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
64 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
65 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
66 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
67 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
68 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
69 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
70 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
71 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
72 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
73 | - ); |
|
74 | - |
|
75 | - $messages['wpi_payment_form'] = array( |
|
76 | - 0 => '', |
|
77 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
78 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
79 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
80 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
81 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
82 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
83 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
84 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
85 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
86 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
87 | - ); |
|
88 | - |
|
89 | - return $messages; |
|
90 | - |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Post row actions. |
|
95 | - */ |
|
96 | - public static function post_row_actions( $actions, $post ) { |
|
97 | - |
|
98 | - $post = get_post( $post ); |
|
99 | - |
|
100 | - // We do not want to edit the default payment form. |
|
101 | - if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
102 | - unset( $actions['trash'] ); |
|
103 | - unset( $actions['inline hide-if-no-js'] ); |
|
104 | - } |
|
105 | - |
|
106 | - return $actions; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Returns an array of invoice table columns. |
|
111 | - */ |
|
112 | - public static function invoice_columns( $columns ) { |
|
113 | - |
|
114 | - $columns = array( |
|
115 | - 'cb' => $columns['cb'], |
|
116 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
117 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
118 | - 'invoice_date' => __( 'Date', 'invoicing' ), |
|
119 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
120 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
121 | - 'status' => __( 'Status', 'invoicing' ), |
|
122 | - 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
123 | - ); |
|
124 | - |
|
125 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Displays invoice table columns. |
|
130 | - */ |
|
131 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
132 | - |
|
133 | - $invoice = new WPInv_Invoice( $post_id ); |
|
134 | - |
|
135 | - switch ( $column_name ) { |
|
136 | - |
|
137 | - case 'invoice_date' : |
|
138 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
139 | - $date = getpaid_format_date_value( $date_time ); |
|
140 | - echo "<span title='$date_time'>$date</span>"; |
|
141 | - break; |
|
142 | - |
|
143 | - case 'amount' : |
|
144 | - |
|
145 | - $amount = $invoice->get_total(); |
|
146 | - $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() ); |
|
147 | - |
|
148 | - if ( $invoice->is_refunded() ) { |
|
149 | - $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() ); |
|
150 | - echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
|
151 | - } else { |
|
152 | - |
|
153 | - $discount = $invoice->get_total_discount(); |
|
154 | - |
|
155 | - if ( ! empty( $discount ) ) { |
|
156 | - $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() ); |
|
157 | - echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
|
158 | - } else { |
|
159 | - echo $formated_amount; |
|
160 | - } |
|
161 | - |
|
162 | - } |
|
163 | - |
|
164 | - break; |
|
165 | - |
|
166 | - case 'status' : |
|
167 | - $status = sanitize_text_field( $invoice->get_status() ); |
|
168 | - $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
169 | - |
|
170 | - // If it is paid, show the gateway title. |
|
171 | - if ( $invoice->is_paid() ) { |
|
172 | - $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
173 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
16 | + * Hook in methods. |
|
17 | + */ |
|
18 | + public static function init() { |
|
174 | 19 | |
175 | - echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
176 | - } else { |
|
177 | - echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
178 | - } |
|
20 | + // Init metaboxes. |
|
21 | + GetPaid_Metaboxes::init(); |
|
179 | 22 | |
180 | - // If it is not paid, display the overdue and view status. |
|
181 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
23 | + // Filter the post updated messages. |
|
24 | + add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
182 | 25 | |
183 | - // Invoice view status. |
|
184 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
185 | - echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
186 | - } else { |
|
187 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
188 | - } |
|
26 | + // Filter post actions. |
|
27 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
189 | 28 | |
190 | - // Display the overview status. |
|
191 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
192 | - $due_date = $invoice->get_due_date(); |
|
193 | - $fomatted = getpaid_format_date( $due_date ); |
|
29 | + // Invoice table columns. |
|
30 | + add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
31 | + add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
194 | 32 | |
195 | - if ( ! empty( $fomatted ) ) { |
|
196 | - $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
197 | - echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
198 | - } |
|
199 | - } |
|
33 | + // Items table columns. |
|
34 | + add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
35 | + add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
36 | + add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
37 | + add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
38 | + add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
39 | + add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
200 | 40 | |
201 | - } |
|
41 | + // Payment forms columns. |
|
42 | + add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
43 | + add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
44 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
202 | 45 | |
203 | - break; |
|
46 | + // Discount table columns. |
|
47 | + add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
48 | + add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
204 | 49 | |
205 | - case 'recurring': |
|
50 | + // Deleting posts. |
|
51 | + add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
52 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
53 | + } |
|
206 | 54 | |
207 | - if ( $invoice->is_recurring() ) { |
|
208 | - echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
209 | - } else { |
|
210 | - echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
211 | - } |
|
212 | - break; |
|
55 | + /** |
|
56 | + * Post updated messages. |
|
57 | + */ |
|
58 | + public static function post_updated_messages( $messages ) { |
|
59 | + global $post; |
|
60 | + |
|
61 | + $messages['wpi_discount'] = array( |
|
62 | + 0 => '', |
|
63 | + 1 => __( 'Discount updated.', 'invoicing' ), |
|
64 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
65 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
66 | + 4 => __( 'Discount updated.', 'invoicing' ), |
|
67 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
68 | + 6 => __( 'Discount updated.', 'invoicing' ), |
|
69 | + 7 => __( 'Discount saved.', 'invoicing' ), |
|
70 | + 8 => __( 'Discount submitted.', 'invoicing' ), |
|
71 | + 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
72 | + 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
73 | + ); |
|
74 | + |
|
75 | + $messages['wpi_payment_form'] = array( |
|
76 | + 0 => '', |
|
77 | + 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
78 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
79 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
80 | + 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
81 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
82 | + 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
83 | + 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
84 | + 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
85 | + 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
86 | + 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
87 | + ); |
|
88 | + |
|
89 | + return $messages; |
|
90 | + |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Post row actions. |
|
95 | + */ |
|
96 | + public static function post_row_actions( $actions, $post ) { |
|
97 | + |
|
98 | + $post = get_post( $post ); |
|
99 | + |
|
100 | + // We do not want to edit the default payment form. |
|
101 | + if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
102 | + unset( $actions['trash'] ); |
|
103 | + unset( $actions['inline hide-if-no-js'] ); |
|
104 | + } |
|
105 | + |
|
106 | + return $actions; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Returns an array of invoice table columns. |
|
111 | + */ |
|
112 | + public static function invoice_columns( $columns ) { |
|
113 | + |
|
114 | + $columns = array( |
|
115 | + 'cb' => $columns['cb'], |
|
116 | + 'number' => __( 'Invoice', 'invoicing' ), |
|
117 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
118 | + 'invoice_date' => __( 'Date', 'invoicing' ), |
|
119 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
120 | + 'recurring' => __( 'Recurring', 'invoicing' ), |
|
121 | + 'status' => __( 'Status', 'invoicing' ), |
|
122 | + 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
123 | + ); |
|
124 | + |
|
125 | + return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Displays invoice table columns. |
|
130 | + */ |
|
131 | + public static function display_invoice_columns( $column_name, $post_id ) { |
|
132 | + |
|
133 | + $invoice = new WPInv_Invoice( $post_id ); |
|
134 | + |
|
135 | + switch ( $column_name ) { |
|
136 | + |
|
137 | + case 'invoice_date' : |
|
138 | + $date_time = esc_attr( $invoice->get_created_date() ); |
|
139 | + $date = getpaid_format_date_value( $date_time ); |
|
140 | + echo "<span title='$date_time'>$date</span>"; |
|
141 | + break; |
|
142 | + |
|
143 | + case 'amount' : |
|
144 | + |
|
145 | + $amount = $invoice->get_total(); |
|
146 | + $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() ); |
|
147 | + |
|
148 | + if ( $invoice->is_refunded() ) { |
|
149 | + $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() ); |
|
150 | + echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
|
151 | + } else { |
|
152 | + |
|
153 | + $discount = $invoice->get_total_discount(); |
|
154 | + |
|
155 | + if ( ! empty( $discount ) ) { |
|
156 | + $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() ); |
|
157 | + echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
|
158 | + } else { |
|
159 | + echo $formated_amount; |
|
160 | + } |
|
161 | + |
|
162 | + } |
|
163 | + |
|
164 | + break; |
|
165 | + |
|
166 | + case 'status' : |
|
167 | + $status = sanitize_text_field( $invoice->get_status() ); |
|
168 | + $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
169 | + |
|
170 | + // If it is paid, show the gateway title. |
|
171 | + if ( $invoice->is_paid() ) { |
|
172 | + $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
173 | + $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
213 | 174 | |
214 | - case 'number' : |
|
175 | + echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
176 | + } else { |
|
177 | + echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
178 | + } |
|
215 | 179 | |
216 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
217 | - $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
218 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
180 | + // If it is not paid, display the overdue and view status. |
|
181 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
219 | 182 | |
220 | - echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
183 | + // Invoice view status. |
|
184 | + if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
185 | + echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
186 | + } else { |
|
187 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
188 | + } |
|
221 | 189 | |
222 | - break; |
|
190 | + // Display the overview status. |
|
191 | + if ( wpinv_get_option( 'overdue_active' ) ) { |
|
192 | + $due_date = $invoice->get_due_date(); |
|
193 | + $fomatted = getpaid_format_date( $due_date ); |
|
223 | 194 | |
224 | - case 'customer' : |
|
195 | + if ( ! empty( $fomatted ) ) { |
|
196 | + $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
197 | + echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + } |
|
202 | + |
|
203 | + break; |
|
204 | + |
|
205 | + case 'recurring': |
|
206 | + |
|
207 | + if ( $invoice->is_recurring() ) { |
|
208 | + echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
209 | + } else { |
|
210 | + echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
211 | + } |
|
212 | + break; |
|
213 | + |
|
214 | + case 'number' : |
|
215 | + |
|
216 | + $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
217 | + $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
218 | + $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
219 | + |
|
220 | + echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
221 | + |
|
222 | + break; |
|
223 | + |
|
224 | + case 'customer' : |
|
225 | 225 | |
226 | - $customer_name = $invoice->get_user_full_name(); |
|
226 | + $customer_name = $invoice->get_user_full_name(); |
|
227 | 227 | |
228 | - if ( empty( $customer_name ) ) { |
|
229 | - $customer_name = $invoice->get_email(); |
|
230 | - } |
|
228 | + if ( empty( $customer_name ) ) { |
|
229 | + $customer_name = $invoice->get_email(); |
|
230 | + } |
|
231 | 231 | |
232 | - if ( ! empty( $customer_name ) ) { |
|
233 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
234 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
235 | - echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
236 | - } else { |
|
237 | - echo '<div>—</div>'; |
|
238 | - } |
|
232 | + if ( ! empty( $customer_name ) ) { |
|
233 | + $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
234 | + $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
235 | + echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
236 | + } else { |
|
237 | + echo '<div>—</div>'; |
|
238 | + } |
|
239 | + |
|
240 | + break; |
|
241 | + |
|
242 | + case 'wpi_actions' : |
|
243 | + |
|
244 | + if ( $invoice->is_draft() ) { |
|
245 | + return; |
|
246 | + } |
|
247 | + |
|
248 | + $url = esc_url( $invoice->get_view_url() ); |
|
249 | + $print = esc_attr__( 'Print invoice', 'invoicing' ); |
|
250 | + echo " <a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>"; |
|
251 | + |
|
252 | + $url = esc_url( |
|
253 | + wp_nonce_url( |
|
254 | + add_query_arg( |
|
255 | + array( |
|
256 | + 'getpaid-admin-action' => 'send_invoice', |
|
257 | + 'invoice_id' => $invoice->get_id() |
|
258 | + ) |
|
259 | + ), |
|
260 | + 'getpaid-nonce', |
|
261 | + 'getpaid-nonce' |
|
262 | + ) |
|
263 | + ); |
|
264 | + |
|
265 | + $send = esc_attr__( 'Send invoice to customer', 'invoicing' ); |
|
266 | + echo " <a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>"; |
|
267 | + |
|
268 | + break; |
|
269 | + } |
|
239 | 270 | |
240 | - break; |
|
271 | + } |
|
241 | 272 | |
242 | - case 'wpi_actions' : |
|
243 | - |
|
244 | - if ( $invoice->is_draft() ) { |
|
245 | - return; |
|
246 | - } |
|
247 | - |
|
248 | - $url = esc_url( $invoice->get_view_url() ); |
|
249 | - $print = esc_attr__( 'Print invoice', 'invoicing' ); |
|
250 | - echo " <a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>"; |
|
273 | + /** |
|
274 | + * Returns an array of payment forms table columns. |
|
275 | + */ |
|
276 | + public static function payment_form_columns( $columns ) { |
|
251 | 277 | |
252 | - $url = esc_url( |
|
253 | - wp_nonce_url( |
|
254 | - add_query_arg( |
|
255 | - array( |
|
256 | - 'getpaid-admin-action' => 'send_invoice', |
|
257 | - 'invoice_id' => $invoice->get_id() |
|
258 | - ) |
|
259 | - ), |
|
260 | - 'getpaid-nonce', |
|
261 | - 'getpaid-nonce' |
|
262 | - ) |
|
263 | - ); |
|
278 | + $columns = array( |
|
279 | + 'cb' => $columns['cb'], |
|
280 | + 'title' => __( 'Name', 'invoicing' ), |
|
281 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
282 | + 'earnings' => __( 'Revenue', 'invoicing' ), |
|
283 | + 'refunds' => __( 'Refunded', 'invoicing' ), |
|
284 | + 'items' => __( 'Items', 'invoicing' ), |
|
285 | + 'date' => __( 'Date', 'invoicing' ), |
|
286 | + ); |
|
264 | 287 | |
265 | - $send = esc_attr__( 'Send invoice to customer', 'invoicing' ); |
|
266 | - echo " <a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>"; |
|
288 | + return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
267 | 289 | |
268 | - break; |
|
269 | - } |
|
290 | + } |
|
270 | 291 | |
271 | - } |
|
292 | + /** |
|
293 | + * Displays payment form table columns. |
|
294 | + */ |
|
295 | + public static function display_payment_form_columns( $column_name, $post_id ) { |
|
272 | 296 | |
273 | - /** |
|
274 | - * Returns an array of payment forms table columns. |
|
275 | - */ |
|
276 | - public static function payment_form_columns( $columns ) { |
|
297 | + // Retrieve the payment form. |
|
298 | + $form = new GetPaid_Payment_Form( $post_id ); |
|
277 | 299 | |
278 | - $columns = array( |
|
279 | - 'cb' => $columns['cb'], |
|
280 | - 'title' => __( 'Name', 'invoicing' ), |
|
281 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
282 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
283 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
284 | - 'items' => __( 'Items', 'invoicing' ), |
|
285 | - 'date' => __( 'Date', 'invoicing' ), |
|
286 | - ); |
|
300 | + switch ( $column_name ) { |
|
287 | 301 | |
288 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
302 | + case 'earnings' : |
|
303 | + echo wpinv_price( wpinv_format_amount( $form->get_earned() ) ); |
|
304 | + break; |
|
289 | 305 | |
290 | - } |
|
306 | + case 'refunds' : |
|
307 | + echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
308 | + break; |
|
291 | 309 | |
292 | - /** |
|
293 | - * Displays payment form table columns. |
|
294 | - */ |
|
295 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
310 | + case 'refunds' : |
|
311 | + echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
312 | + break; |
|
296 | 313 | |
297 | - // Retrieve the payment form. |
|
298 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
314 | + case 'shortcode' : |
|
299 | 315 | |
300 | - switch ( $column_name ) { |
|
316 | + if ( $form->is_default() ) { |
|
317 | + echo '—'; |
|
318 | + } else { |
|
319 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
320 | + } |
|
301 | 321 | |
302 | - case 'earnings' : |
|
303 | - echo wpinv_price( wpinv_format_amount( $form->get_earned() ) ); |
|
304 | - break; |
|
322 | + break; |
|
305 | 323 | |
306 | - case 'refunds' : |
|
307 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
308 | - break; |
|
324 | + case 'items' : |
|
309 | 325 | |
310 | - case 'refunds' : |
|
311 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
312 | - break; |
|
326 | + $items = $form->get_items(); |
|
313 | 327 | |
314 | - case 'shortcode' : |
|
328 | + if ( $form->is_default() || empty( $items ) ) { |
|
329 | + echo '—'; |
|
330 | + return; |
|
331 | + } |
|
315 | 332 | |
316 | - if ( $form->is_default() ) { |
|
317 | - echo '—'; |
|
318 | - } else { |
|
319 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
320 | - } |
|
333 | + $_items = array(); |
|
321 | 334 | |
322 | - break; |
|
335 | + foreach ( $items as $item ) { |
|
336 | + $url = $item->get_edit_url(); |
|
323 | 337 | |
324 | - case 'items' : |
|
338 | + if ( empty( $url ) ) { |
|
339 | + $_items[] = sanitize_text_field( $item->get_name() ); |
|
340 | + } else { |
|
341 | + $_items[] = sprintf( |
|
342 | + '<a href="%s">%s</a>', |
|
343 | + esc_url( $url ), |
|
344 | + sanitize_text_field( $item->get_name() ) |
|
345 | + ); |
|
346 | + } |
|
325 | 347 | |
326 | - $items = $form->get_items(); |
|
348 | + } |
|
327 | 349 | |
328 | - if ( $form->is_default() || empty( $items ) ) { |
|
329 | - echo '—'; |
|
330 | - return; |
|
331 | - } |
|
350 | + echo implode( '<br>', $_items ); |
|
332 | 351 | |
333 | - $_items = array(); |
|
352 | + break; |
|
334 | 353 | |
335 | - foreach ( $items as $item ) { |
|
336 | - $url = $item->get_edit_url(); |
|
354 | + } |
|
337 | 355 | |
338 | - if ( empty( $url ) ) { |
|
339 | - $_items[] = sanitize_text_field( $item->get_name() ); |
|
340 | - } else { |
|
341 | - $_items[] = sprintf( |
|
342 | - '<a href="%s">%s</a>', |
|
343 | - esc_url( $url ), |
|
344 | - sanitize_text_field( $item->get_name() ) |
|
345 | - ); |
|
346 | - } |
|
356 | + } |
|
347 | 357 | |
348 | - } |
|
358 | + /** |
|
359 | + * Filters post states. |
|
360 | + */ |
|
361 | + public static function filter_payment_form_state( $post_states, $post ) { |
|
349 | 362 | |
350 | - echo implode( '<br>', $_items ); |
|
363 | + if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
364 | + $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
365 | + } |
|
366 | + |
|
367 | + return $post_states; |
|
351 | 368 | |
352 | - break; |
|
369 | + } |
|
353 | 370 | |
354 | - } |
|
371 | + /** |
|
372 | + * Returns an array of coupon table columns. |
|
373 | + */ |
|
374 | + public static function discount_columns( $columns ) { |
|
375 | + |
|
376 | + $columns = array( |
|
377 | + 'cb' => $columns['cb'], |
|
378 | + 'title' => __( 'Name', 'invoicing' ), |
|
379 | + 'code' => __( 'Code', 'invoicing' ), |
|
380 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
381 | + 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
382 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
383 | + 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
384 | + ); |
|
385 | + |
|
386 | + return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
387 | + } |
|
355 | 388 | |
356 | - } |
|
389 | + /** |
|
390 | + * Filters post states. |
|
391 | + */ |
|
392 | + public static function filter_discount_state( $post_states, $post ) { |
|
357 | 393 | |
358 | - /** |
|
359 | - * Filters post states. |
|
360 | - */ |
|
361 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
394 | + if ( 'wpi_discount' == $post->post_type ) { |
|
362 | 395 | |
363 | - if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
364 | - $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
365 | - } |
|
366 | - |
|
367 | - return $post_states; |
|
396 | + $discount = new WPInv_Discount( $post ); |
|
368 | 397 | |
369 | - } |
|
398 | + $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
370 | 399 | |
371 | - /** |
|
372 | - * Returns an array of coupon table columns. |
|
373 | - */ |
|
374 | - public static function discount_columns( $columns ) { |
|
400 | + if ( $status != 'publish' ) { |
|
401 | + return array( |
|
402 | + 'discount_status' => wpinv_discount_status( $status ), |
|
403 | + ); |
|
404 | + } |
|
375 | 405 | |
376 | - $columns = array( |
|
377 | - 'cb' => $columns['cb'], |
|
378 | - 'title' => __( 'Name', 'invoicing' ), |
|
379 | - 'code' => __( 'Code', 'invoicing' ), |
|
380 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
381 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
382 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
383 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
384 | - ); |
|
406 | + return array(); |
|
385 | 407 | |
386 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
387 | - } |
|
408 | + } |
|
388 | 409 | |
389 | - /** |
|
390 | - * Filters post states. |
|
391 | - */ |
|
392 | - public static function filter_discount_state( $post_states, $post ) { |
|
410 | + return $post_states; |
|
393 | 411 | |
394 | - if ( 'wpi_discount' == $post->post_type ) { |
|
412 | + } |
|
395 | 413 | |
396 | - $discount = new WPInv_Discount( $post ); |
|
414 | + /** |
|
415 | + * Returns an array of items table columns. |
|
416 | + */ |
|
417 | + public static function item_columns( $columns ) { |
|
418 | + global $wpinv_euvat; |
|
419 | + |
|
420 | + $columns = array( |
|
421 | + 'cb' => $columns['cb'], |
|
422 | + 'title' => __( 'Name', 'invoicing' ), |
|
423 | + 'price' => __( 'Price', 'invoicing' ), |
|
424 | + 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
425 | + 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
426 | + 'type' => __( 'Type', 'invoicing' ), |
|
427 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
428 | + ); |
|
429 | + |
|
430 | + if ( ! $wpinv_euvat->allow_vat_rules() ) { |
|
431 | + unset( $columns['vat_rule'] ); |
|
432 | + } |
|
397 | 433 | |
398 | - $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
434 | + if ( ! $wpinv_euvat->allow_vat_classes() ) { |
|
435 | + unset( $columns['vat_class'] ); |
|
436 | + } |
|
399 | 437 | |
400 | - if ( $status != 'publish' ) { |
|
401 | - return array( |
|
402 | - 'discount_status' => wpinv_discount_status( $status ), |
|
403 | - ); |
|
404 | - } |
|
438 | + return apply_filters( 'wpi_item_table_columns', $columns ); |
|
439 | + } |
|
405 | 440 | |
406 | - return array(); |
|
441 | + /** |
|
442 | + * Returns an array of sortable items table columns. |
|
443 | + */ |
|
444 | + public static function sortable_item_columns( $columns ) { |
|
445 | + |
|
446 | + return array_merge( |
|
447 | + $columns, |
|
448 | + array( |
|
449 | + 'price' => 'price', |
|
450 | + 'vat_rule' => 'vat_rule', |
|
451 | + 'vat_class' => 'vat_class', |
|
452 | + 'type' => 'type', |
|
453 | + ) |
|
454 | + ); |
|
455 | + |
|
456 | + } |
|
407 | 457 | |
408 | - } |
|
458 | + /** |
|
459 | + * Displays items table columns. |
|
460 | + */ |
|
461 | + public static function display_item_columns( $column_name, $post_id ) { |
|
462 | + global $wpinv_euvat; |
|
409 | 463 | |
410 | - return $post_states; |
|
464 | + $item = new WPInv_Item( $post_id ); |
|
411 | 465 | |
412 | - } |
|
466 | + switch ( $column_name ) { |
|
413 | 467 | |
414 | - /** |
|
415 | - * Returns an array of items table columns. |
|
416 | - */ |
|
417 | - public static function item_columns( $columns ) { |
|
418 | - global $wpinv_euvat; |
|
468 | + case 'price' : |
|
419 | 469 | |
420 | - $columns = array( |
|
421 | - 'cb' => $columns['cb'], |
|
422 | - 'title' => __( 'Name', 'invoicing' ), |
|
423 | - 'price' => __( 'Price', 'invoicing' ), |
|
424 | - 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
425 | - 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
426 | - 'type' => __( 'Type', 'invoicing' ), |
|
427 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
428 | - ); |
|
470 | + if ( ! $item->is_recurring() ) { |
|
471 | + echo $item->get_the_price(); |
|
472 | + break; |
|
473 | + } |
|
429 | 474 | |
430 | - if ( ! $wpinv_euvat->allow_vat_rules() ) { |
|
431 | - unset( $columns['vat_rule'] ); |
|
432 | - } |
|
475 | + $price = wp_sprintf( |
|
476 | + __( '%s / %s', 'invoicing' ), |
|
477 | + $item->get_the_price(), |
|
478 | + getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
479 | + ); |
|
433 | 480 | |
434 | - if ( ! $wpinv_euvat->allow_vat_classes() ) { |
|
435 | - unset( $columns['vat_class'] ); |
|
436 | - } |
|
481 | + if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
482 | + echo $price; |
|
483 | + break; |
|
484 | + } |
|
437 | 485 | |
438 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
439 | - } |
|
486 | + echo $item->get_the_initial_price(); |
|
440 | 487 | |
441 | - /** |
|
442 | - * Returns an array of sortable items table columns. |
|
443 | - */ |
|
444 | - public static function sortable_item_columns( $columns ) { |
|
488 | + echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
489 | + break; |
|
445 | 490 | |
446 | - return array_merge( |
|
447 | - $columns, |
|
448 | - array( |
|
449 | - 'price' => 'price', |
|
450 | - 'vat_rule' => 'vat_rule', |
|
451 | - 'vat_class' => 'vat_class', |
|
452 | - 'type' => 'type', |
|
453 | - ) |
|
454 | - ); |
|
491 | + case 'vat_rule' : |
|
492 | + echo $wpinv_euvat->item_rule_label( $item->get_id() ); |
|
493 | + break; |
|
455 | 494 | |
456 | - } |
|
495 | + case 'vat_class' : |
|
496 | + echo $wpinv_euvat->item_class_label( $item->get_id() ); |
|
497 | + break; |
|
457 | 498 | |
458 | - /** |
|
459 | - * Displays items table columns. |
|
460 | - */ |
|
461 | - public static function display_item_columns( $column_name, $post_id ) { |
|
462 | - global $wpinv_euvat; |
|
499 | + case 'shortcode' : |
|
500 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
501 | + break; |
|
463 | 502 | |
464 | - $item = new WPInv_Item( $post_id ); |
|
503 | + case 'type' : |
|
504 | + echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
505 | + break; |
|
465 | 506 | |
466 | - switch ( $column_name ) { |
|
507 | + } |
|
467 | 508 | |
468 | - case 'price' : |
|
509 | + } |
|
469 | 510 | |
470 | - if ( ! $item->is_recurring() ) { |
|
471 | - echo $item->get_the_price(); |
|
472 | - break; |
|
473 | - } |
|
511 | + /** |
|
512 | + * Lets users filter items using taxes. |
|
513 | + */ |
|
514 | + public static function add_item_filters( $post_type ) { |
|
515 | + $wpinv_euvat = getpaid_tax(); |
|
516 | + |
|
517 | + // Abort if we're not dealing with items. |
|
518 | + if ( $post_type != 'wpi_item' ) { |
|
519 | + return; |
|
520 | + } |
|
521 | + |
|
522 | + // Filter by vat rules. |
|
523 | + if ( $wpinv_euvat->allow_vat_rules() ) { |
|
524 | + |
|
525 | + // Sanitize selected vat rule. |
|
526 | + $vat_rule = ''; |
|
527 | + $vat_rules = $wpinv_euvat->get_rules(); |
|
528 | + if ( isset( $_GET['vat_rule'] ) ) { |
|
529 | + $vat_rule = $_GET['vat_rule']; |
|
530 | + } |
|
531 | + |
|
532 | + // Filter by VAT rule. |
|
533 | + echo wpinv_html_select( |
|
534 | + array( |
|
535 | + 'options' => array_merge( |
|
536 | + array( |
|
537 | + '' => __( 'All VAT rules', 'invoicing' ) |
|
538 | + ), |
|
539 | + $vat_rules |
|
540 | + ), |
|
541 | + 'name' => 'vat_rule', |
|
542 | + 'id' => 'vat_rule', |
|
543 | + 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
544 | + 'show_option_all' => false, |
|
545 | + 'show_option_none' => false, |
|
546 | + 'class' => 'gdmbx2-text-medium', |
|
547 | + ) |
|
548 | + ); |
|
549 | + |
|
550 | + // Filter by VAT class. |
|
551 | + } |
|
474 | 552 | |
475 | - $price = wp_sprintf( |
|
476 | - __( '%s / %s', 'invoicing' ), |
|
477 | - $item->get_the_price(), |
|
478 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
479 | - ); |
|
553 | + // Filter by vat class. |
|
554 | + if ( $wpinv_euvat->allow_vat_classes() ) { |
|
555 | + |
|
556 | + // Sanitize selected vat rule. |
|
557 | + $vat_class = ''; |
|
558 | + $vat_classes = $wpinv_euvat->get_all_classes(); |
|
559 | + if ( isset( $_GET['vat_class'] ) ) { |
|
560 | + $vat_class = $_GET['vat_class']; |
|
561 | + } |
|
562 | + |
|
563 | + echo wpinv_html_select( |
|
564 | + array( |
|
565 | + 'options' => array_merge( |
|
566 | + array( |
|
567 | + '' => __( 'All VAT classes', 'invoicing' ) |
|
568 | + ), |
|
569 | + $vat_classes |
|
570 | + ), |
|
571 | + 'name' => 'vat_class', |
|
572 | + 'id' => 'vat_class', |
|
573 | + 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
574 | + 'show_option_all' => false, |
|
575 | + 'show_option_none' => false, |
|
576 | + 'class' => 'gdmbx2-text-medium', |
|
577 | + ) |
|
578 | + ); |
|
480 | 579 | |
481 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
482 | - echo $price; |
|
483 | - break; |
|
484 | - } |
|
580 | + } |
|
485 | 581 | |
486 | - echo $item->get_the_initial_price(); |
|
582 | + // Filter by item type. |
|
583 | + $type = ''; |
|
584 | + if ( isset( $_GET['type'] ) ) { |
|
585 | + $type = $_GET['type']; |
|
586 | + } |
|
487 | 587 | |
488 | - echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
489 | - break; |
|
588 | + echo wpinv_html_select( |
|
589 | + array( |
|
590 | + 'options' => array_merge( |
|
591 | + array( |
|
592 | + '' => __( 'All item types', 'invoicing' ) |
|
593 | + ), |
|
594 | + wpinv_get_item_types() |
|
595 | + ), |
|
596 | + 'name' => 'type', |
|
597 | + 'id' => 'type', |
|
598 | + 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
599 | + 'show_option_all' => false, |
|
600 | + 'show_option_none' => false, |
|
601 | + 'class' => 'gdmbx2-text-medium', |
|
602 | + ) |
|
603 | + ); |
|
604 | + |
|
605 | + } |
|
490 | 606 | |
491 | - case 'vat_rule' : |
|
492 | - echo $wpinv_euvat->item_rule_label( $item->get_id() ); |
|
493 | - break; |
|
607 | + /** |
|
608 | + * Filters the item query. |
|
609 | + */ |
|
610 | + public static function filter_item_query( $query ) { |
|
494 | 611 | |
495 | - case 'vat_class' : |
|
496 | - echo $wpinv_euvat->item_class_label( $item->get_id() ); |
|
497 | - break; |
|
612 | + // modify the query only if it admin and main query. |
|
613 | + if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
614 | + return $query; |
|
615 | + } |
|
498 | 616 | |
499 | - case 'shortcode' : |
|
500 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
501 | - break; |
|
617 | + // we want to modify the query for our items. |
|
618 | + if ( 'wpi_item' != $query->query['post_type'] ){ |
|
619 | + return $query; |
|
620 | + } |
|
502 | 621 | |
503 | - case 'type' : |
|
504 | - echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
505 | - break; |
|
622 | + if ( empty( $query->query_vars['meta_query'] ) ) { |
|
623 | + $query->query_vars['meta_query'] = array(); |
|
624 | + } |
|
506 | 625 | |
507 | - } |
|
508 | - |
|
509 | - } |
|
510 | - |
|
511 | - /** |
|
512 | - * Lets users filter items using taxes. |
|
513 | - */ |
|
514 | - public static function add_item_filters( $post_type ) { |
|
515 | - $wpinv_euvat = getpaid_tax(); |
|
516 | - |
|
517 | - // Abort if we're not dealing with items. |
|
518 | - if ( $post_type != 'wpi_item' ) { |
|
519 | - return; |
|
520 | - } |
|
521 | - |
|
522 | - // Filter by vat rules. |
|
523 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
524 | - |
|
525 | - // Sanitize selected vat rule. |
|
526 | - $vat_rule = ''; |
|
527 | - $vat_rules = $wpinv_euvat->get_rules(); |
|
528 | - if ( isset( $_GET['vat_rule'] ) ) { |
|
529 | - $vat_rule = $_GET['vat_rule']; |
|
530 | - } |
|
531 | - |
|
532 | - // Filter by VAT rule. |
|
533 | - echo wpinv_html_select( |
|
534 | - array( |
|
535 | - 'options' => array_merge( |
|
536 | - array( |
|
537 | - '' => __( 'All VAT rules', 'invoicing' ) |
|
538 | - ), |
|
539 | - $vat_rules |
|
540 | - ), |
|
541 | - 'name' => 'vat_rule', |
|
542 | - 'id' => 'vat_rule', |
|
543 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
544 | - 'show_option_all' => false, |
|
545 | - 'show_option_none' => false, |
|
546 | - 'class' => 'gdmbx2-text-medium', |
|
547 | - ) |
|
548 | - ); |
|
549 | - |
|
550 | - // Filter by VAT class. |
|
551 | - } |
|
552 | - |
|
553 | - // Filter by vat class. |
|
554 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
555 | - |
|
556 | - // Sanitize selected vat rule. |
|
557 | - $vat_class = ''; |
|
558 | - $vat_classes = $wpinv_euvat->get_all_classes(); |
|
559 | - if ( isset( $_GET['vat_class'] ) ) { |
|
560 | - $vat_class = $_GET['vat_class']; |
|
561 | - } |
|
562 | - |
|
563 | - echo wpinv_html_select( |
|
564 | - array( |
|
565 | - 'options' => array_merge( |
|
566 | - array( |
|
567 | - '' => __( 'All VAT classes', 'invoicing' ) |
|
568 | - ), |
|
569 | - $vat_classes |
|
570 | - ), |
|
571 | - 'name' => 'vat_class', |
|
572 | - 'id' => 'vat_class', |
|
573 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
574 | - 'show_option_all' => false, |
|
575 | - 'show_option_none' => false, |
|
576 | - 'class' => 'gdmbx2-text-medium', |
|
577 | - ) |
|
578 | - ); |
|
579 | - |
|
580 | - } |
|
581 | - |
|
582 | - // Filter by item type. |
|
583 | - $type = ''; |
|
584 | - if ( isset( $_GET['type'] ) ) { |
|
585 | - $type = $_GET['type']; |
|
586 | - } |
|
587 | - |
|
588 | - echo wpinv_html_select( |
|
589 | - array( |
|
590 | - 'options' => array_merge( |
|
591 | - array( |
|
592 | - '' => __( 'All item types', 'invoicing' ) |
|
593 | - ), |
|
594 | - wpinv_get_item_types() |
|
595 | - ), |
|
596 | - 'name' => 'type', |
|
597 | - 'id' => 'type', |
|
598 | - 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
599 | - 'show_option_all' => false, |
|
600 | - 'show_option_none' => false, |
|
601 | - 'class' => 'gdmbx2-text-medium', |
|
602 | - ) |
|
603 | - ); |
|
604 | - |
|
605 | - } |
|
606 | - |
|
607 | - /** |
|
608 | - * Filters the item query. |
|
609 | - */ |
|
610 | - public static function filter_item_query( $query ) { |
|
611 | - |
|
612 | - // modify the query only if it admin and main query. |
|
613 | - if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
614 | - return $query; |
|
615 | - } |
|
616 | - |
|
617 | - // we want to modify the query for our items. |
|
618 | - if ( 'wpi_item' != $query->query['post_type'] ){ |
|
619 | - return $query; |
|
620 | - } |
|
621 | - |
|
622 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
623 | - $query->query_vars['meta_query'] = array(); |
|
624 | - } |
|
625 | - |
|
626 | - // Filter vat rule type |
|
626 | + // Filter vat rule type |
|
627 | 627 | if ( ! empty( $_GET['vat_rule'] ) ) { |
628 | 628 | $query->query_vars['meta_query'][] = array( |
629 | 629 | 'key' => '_wpinv_vat_rule', |
@@ -648,94 +648,94 @@ discard block |
||
648 | 648 | 'value' => sanitize_text_field( $_GET['type'] ), |
649 | 649 | 'compare' => '=' |
650 | 650 | ); |
651 | - } |
|
652 | - |
|
653 | - } |
|
654 | - |
|
655 | - /** |
|
656 | - * Reorders items. |
|
657 | - */ |
|
658 | - public static function reorder_items( $vars ) { |
|
659 | - global $typenow; |
|
660 | - |
|
661 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
662 | - return $vars; |
|
663 | - } |
|
664 | - |
|
665 | - // By item type. |
|
666 | - if ( 'type' == $vars['orderby'] ) { |
|
667 | - return array_merge( |
|
668 | - $vars, |
|
669 | - array( |
|
670 | - 'meta_key' => '_wpinv_type', |
|
671 | - 'orderby' => 'meta_value' |
|
672 | - ) |
|
673 | - ); |
|
674 | - } |
|
675 | - |
|
676 | - // By vat class. |
|
677 | - if ( 'vat_class' == $vars['orderby'] ) { |
|
678 | - return array_merge( |
|
679 | - $vars, |
|
680 | - array( |
|
681 | - 'meta_key' => '_wpinv_vat_class', |
|
682 | - 'orderby' => 'meta_value' |
|
683 | - ) |
|
684 | - ); |
|
685 | - } |
|
686 | - |
|
687 | - // By vat rule. |
|
688 | - if ( 'vat_rule' == $vars['orderby'] ) { |
|
689 | - return array_merge( |
|
690 | - $vars, |
|
691 | - array( |
|
692 | - 'meta_key' => '_wpinv_vat_rule', |
|
693 | - 'orderby' => 'meta_value' |
|
694 | - ) |
|
695 | - ); |
|
696 | - } |
|
697 | - |
|
698 | - // By price. |
|
699 | - if ( 'price' == $vars['orderby'] ) { |
|
700 | - return array_merge( |
|
701 | - $vars, |
|
702 | - array( |
|
703 | - 'meta_key' => '_wpinv_price', |
|
704 | - 'orderby' => 'meta_value_num' |
|
705 | - ) |
|
706 | - ); |
|
707 | - } |
|
708 | - |
|
709 | - return $vars; |
|
710 | - |
|
711 | - } |
|
712 | - |
|
713 | - /** |
|
714 | - * Fired when deleting a post. |
|
715 | - */ |
|
716 | - public static function delete_post( $post_id ) { |
|
717 | - |
|
718 | - switch ( get_post_type( $post_id ) ) { |
|
719 | - |
|
720 | - case 'wpi_item' : |
|
721 | - do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
722 | - break; |
|
723 | - |
|
724 | - case 'wpi_payment_form' : |
|
725 | - do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
726 | - break; |
|
727 | - |
|
728 | - case 'wpi_discount' : |
|
729 | - do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
730 | - break; |
|
731 | - |
|
732 | - case 'wpi_invoice' : |
|
733 | - $invoice = new WPInv_Invoice( $post_id ); |
|
734 | - do_action( "getpaid_before_delete_invoice", $invoice ); |
|
735 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
736 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
737 | - break; |
|
738 | - } |
|
739 | - } |
|
651 | + } |
|
652 | + |
|
653 | + } |
|
654 | + |
|
655 | + /** |
|
656 | + * Reorders items. |
|
657 | + */ |
|
658 | + public static function reorder_items( $vars ) { |
|
659 | + global $typenow; |
|
660 | + |
|
661 | + if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
662 | + return $vars; |
|
663 | + } |
|
664 | + |
|
665 | + // By item type. |
|
666 | + if ( 'type' == $vars['orderby'] ) { |
|
667 | + return array_merge( |
|
668 | + $vars, |
|
669 | + array( |
|
670 | + 'meta_key' => '_wpinv_type', |
|
671 | + 'orderby' => 'meta_value' |
|
672 | + ) |
|
673 | + ); |
|
674 | + } |
|
675 | + |
|
676 | + // By vat class. |
|
677 | + if ( 'vat_class' == $vars['orderby'] ) { |
|
678 | + return array_merge( |
|
679 | + $vars, |
|
680 | + array( |
|
681 | + 'meta_key' => '_wpinv_vat_class', |
|
682 | + 'orderby' => 'meta_value' |
|
683 | + ) |
|
684 | + ); |
|
685 | + } |
|
686 | + |
|
687 | + // By vat rule. |
|
688 | + if ( 'vat_rule' == $vars['orderby'] ) { |
|
689 | + return array_merge( |
|
690 | + $vars, |
|
691 | + array( |
|
692 | + 'meta_key' => '_wpinv_vat_rule', |
|
693 | + 'orderby' => 'meta_value' |
|
694 | + ) |
|
695 | + ); |
|
696 | + } |
|
697 | + |
|
698 | + // By price. |
|
699 | + if ( 'price' == $vars['orderby'] ) { |
|
700 | + return array_merge( |
|
701 | + $vars, |
|
702 | + array( |
|
703 | + 'meta_key' => '_wpinv_price', |
|
704 | + 'orderby' => 'meta_value_num' |
|
705 | + ) |
|
706 | + ); |
|
707 | + } |
|
708 | + |
|
709 | + return $vars; |
|
710 | + |
|
711 | + } |
|
712 | + |
|
713 | + /** |
|
714 | + * Fired when deleting a post. |
|
715 | + */ |
|
716 | + public static function delete_post( $post_id ) { |
|
717 | + |
|
718 | + switch ( get_post_type( $post_id ) ) { |
|
719 | + |
|
720 | + case 'wpi_item' : |
|
721 | + do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
722 | + break; |
|
723 | + |
|
724 | + case 'wpi_payment_form' : |
|
725 | + do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
726 | + break; |
|
727 | + |
|
728 | + case 'wpi_discount' : |
|
729 | + do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
730 | + break; |
|
731 | + |
|
732 | + case 'wpi_invoice' : |
|
733 | + $invoice = new WPInv_Invoice( $post_id ); |
|
734 | + do_action( "getpaid_before_delete_invoice", $invoice ); |
|
735 | + $invoice->get_data_store()->delete_items( $invoice ); |
|
736 | + $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
737 | + break; |
|
738 | + } |
|
739 | + } |
|
740 | 740 | |
741 | 741 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Post types Admin Class |
@@ -21,69 +21,69 @@ discard block |
||
21 | 21 | GetPaid_Metaboxes::init(); |
22 | 22 | |
23 | 23 | // Filter the post updated messages. |
24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
24 | + add_filter('post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages'); |
|
25 | 25 | |
26 | 26 | // Filter post actions. |
27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
27 | + add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2); |
|
28 | 28 | |
29 | 29 | // Invoice table columns. |
30 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
31 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
30 | + add_filter('manage_wpi_invoice_posts_columns', array(__CLASS__, 'invoice_columns'), 100); |
|
31 | + add_action('manage_wpi_invoice_posts_custom_column', array(__CLASS__, 'display_invoice_columns'), 10, 2); |
|
32 | 32 | |
33 | 33 | // Items table columns. |
34 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
35 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
36 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
37 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
38 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
39 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
34 | + add_filter('manage_wpi_item_posts_columns', array(__CLASS__, 'item_columns'), 100); |
|
35 | + add_filter('manage_edit-wpi_item_sortable_columns', array(__CLASS__, 'sortable_item_columns'), 20); |
|
36 | + add_action('manage_wpi_item_posts_custom_column', array(__CLASS__, 'display_item_columns'), 10, 2); |
|
37 | + add_action('restrict_manage_posts', array(__CLASS__, 'add_item_filters'), 100); |
|
38 | + add_action('parse_query', array(__CLASS__, 'filter_item_query'), 100); |
|
39 | + add_action('request', array(__CLASS__, 'reorder_items'), 100); |
|
40 | 40 | |
41 | 41 | // Payment forms columns. |
42 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
43 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
44 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
42 | + add_filter('manage_wpi_payment_form_posts_columns', array(__CLASS__, 'payment_form_columns'), 100); |
|
43 | + add_action('manage_wpi_payment_form_posts_custom_column', array(__CLASS__, 'display_payment_form_columns'), 10, 2); |
|
44 | + add_filter('display_post_states', array(__CLASS__, 'filter_payment_form_state'), 10, 2); |
|
45 | 45 | |
46 | 46 | // Discount table columns. |
47 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
48 | - add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
47 | + add_filter('manage_wpi_discount_posts_columns', array(__CLASS__, 'discount_columns'), 100); |
|
48 | + add_filter('bulk_actions-edit-wpi_discount', '__return_empty_array', 100); |
|
49 | 49 | |
50 | 50 | // Deleting posts. |
51 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
52 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
51 | + add_action('delete_post', array(__CLASS__, 'delete_post')); |
|
52 | + add_filter('display_post_states', array(__CLASS__, 'filter_discount_state'), 10, 2); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Post updated messages. |
57 | 57 | */ |
58 | - public static function post_updated_messages( $messages ) { |
|
58 | + public static function post_updated_messages($messages) { |
|
59 | 59 | global $post; |
60 | 60 | |
61 | 61 | $messages['wpi_discount'] = array( |
62 | 62 | 0 => '', |
63 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
64 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
65 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
66 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
67 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
68 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
69 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
70 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
71 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
72 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
63 | + 1 => __('Discount updated.', 'invoicing'), |
|
64 | + 2 => __('Custom field updated.', 'invoicing'), |
|
65 | + 3 => __('Custom field deleted.', 'invoicing'), |
|
66 | + 4 => __('Discount updated.', 'invoicing'), |
|
67 | + 5 => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
68 | + 6 => __('Discount updated.', 'invoicing'), |
|
69 | + 7 => __('Discount saved.', 'invoicing'), |
|
70 | + 8 => __('Discount submitted.', 'invoicing'), |
|
71 | + 9 => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))), |
|
72 | + 10 => __('Discount draft updated.', 'invoicing'), |
|
73 | 73 | ); |
74 | 74 | |
75 | 75 | $messages['wpi_payment_form'] = array( |
76 | 76 | 0 => '', |
77 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
78 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
79 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
80 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
81 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
82 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
83 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
84 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
85 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
86 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
77 | + 1 => __('Payment Form updated.', 'invoicing'), |
|
78 | + 2 => __('Custom field updated.', 'invoicing'), |
|
79 | + 3 => __('Custom field deleted.', 'invoicing'), |
|
80 | + 4 => __('Payment Form updated.', 'invoicing'), |
|
81 | + 5 => isset($_GET['revision']) ? wp_sprintf(__('Payment Form restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
82 | + 6 => __('Payment Form updated.', 'invoicing'), |
|
83 | + 7 => __('Payment Form saved.', 'invoicing'), |
|
84 | + 8 => __('Payment Form submitted.', 'invoicing'), |
|
85 | + 9 => wp_sprintf(__('Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))), |
|
86 | + 10 => __('Payment Form draft updated.', 'invoicing'), |
|
87 | 87 | ); |
88 | 88 | |
89 | 89 | return $messages; |
@@ -93,14 +93,14 @@ discard block |
||
93 | 93 | /** |
94 | 94 | * Post row actions. |
95 | 95 | */ |
96 | - public static function post_row_actions( $actions, $post ) { |
|
96 | + public static function post_row_actions($actions, $post) { |
|
97 | 97 | |
98 | - $post = get_post( $post ); |
|
98 | + $post = get_post($post); |
|
99 | 99 | |
100 | 100 | // We do not want to edit the default payment form. |
101 | - if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
102 | - unset( $actions['trash'] ); |
|
103 | - unset( $actions['inline hide-if-no-js'] ); |
|
101 | + if ('wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form()) { |
|
102 | + unset($actions['trash']); |
|
103 | + unset($actions['inline hide-if-no-js']); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | return $actions; |
@@ -109,51 +109,51 @@ discard block |
||
109 | 109 | /** |
110 | 110 | * Returns an array of invoice table columns. |
111 | 111 | */ |
112 | - public static function invoice_columns( $columns ) { |
|
112 | + public static function invoice_columns($columns) { |
|
113 | 113 | |
114 | 114 | $columns = array( |
115 | 115 | 'cb' => $columns['cb'], |
116 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
117 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
118 | - 'invoice_date' => __( 'Date', 'invoicing' ), |
|
119 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
120 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
121 | - 'status' => __( 'Status', 'invoicing' ), |
|
122 | - 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
116 | + 'number' => __('Invoice', 'invoicing'), |
|
117 | + 'customer' => __('Customer', 'invoicing'), |
|
118 | + 'invoice_date' => __('Date', 'invoicing'), |
|
119 | + 'amount' => __('Amount', 'invoicing'), |
|
120 | + 'recurring' => __('Recurring', 'invoicing'), |
|
121 | + 'status' => __('Status', 'invoicing'), |
|
122 | + 'wpi_actions' => __('Actions', 'invoicing'), |
|
123 | 123 | ); |
124 | 124 | |
125 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
125 | + return apply_filters('wpi_invoice_table_columns', $columns); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
129 | 129 | * Displays invoice table columns. |
130 | 130 | */ |
131 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
131 | + public static function display_invoice_columns($column_name, $post_id) { |
|
132 | 132 | |
133 | - $invoice = new WPInv_Invoice( $post_id ); |
|
133 | + $invoice = new WPInv_Invoice($post_id); |
|
134 | 134 | |
135 | - switch ( $column_name ) { |
|
135 | + switch ($column_name) { |
|
136 | 136 | |
137 | 137 | case 'invoice_date' : |
138 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
139 | - $date = getpaid_format_date_value( $date_time ); |
|
138 | + $date_time = esc_attr($invoice->get_created_date()); |
|
139 | + $date = getpaid_format_date_value($date_time); |
|
140 | 140 | echo "<span title='$date_time'>$date</span>"; |
141 | 141 | break; |
142 | 142 | |
143 | 143 | case 'amount' : |
144 | 144 | |
145 | 145 | $amount = $invoice->get_total(); |
146 | - $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() ); |
|
146 | + $formated_amount = wpinv_price(wpinv_format_amount($amount), $invoice->get_currency()); |
|
147 | 147 | |
148 | - if ( $invoice->is_refunded() ) { |
|
149 | - $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() ); |
|
148 | + if ($invoice->is_refunded()) { |
|
149 | + $refunded_amount = wpinv_price(wpinv_format_amount(0), $invoice->get_currency()); |
|
150 | 150 | echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
151 | 151 | } else { |
152 | 152 | |
153 | 153 | $discount = $invoice->get_total_discount(); |
154 | 154 | |
155 | - if ( ! empty( $discount ) ) { |
|
156 | - $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() ); |
|
155 | + if (!empty($discount)) { |
|
156 | + $new_amount = wpinv_price(wpinv_format_amount($amount + $discount), $invoice->get_currency()); |
|
157 | 157 | echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
158 | 158 | } else { |
159 | 159 | echo $formated_amount; |
@@ -164,13 +164,13 @@ discard block |
||
164 | 164 | break; |
165 | 165 | |
166 | 166 | case 'status' : |
167 | - $status = sanitize_text_field( $invoice->get_status() ); |
|
168 | - $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
167 | + $status = sanitize_text_field($invoice->get_status()); |
|
168 | + $status_label = sanitize_text_field($invoice->get_status_nicename()); |
|
169 | 169 | |
170 | 170 | // If it is paid, show the gateway title. |
171 | - if ( $invoice->is_paid() ) { |
|
172 | - $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
173 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
171 | + if ($invoice->is_paid()) { |
|
172 | + $gateway = sanitize_text_field($invoice->get_gateway_title()); |
|
173 | + $gateway = wp_sprintf(esc_attr__('Paid via %s', 'invoicing'), $gateway); |
|
174 | 174 | |
175 | 175 | echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
176 | 176 | } else { |
@@ -178,22 +178,22 @@ discard block |
||
178 | 178 | } |
179 | 179 | |
180 | 180 | // If it is not paid, display the overdue and view status. |
181 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
181 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
182 | 182 | |
183 | 183 | // Invoice view status. |
184 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
185 | - echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
184 | + if (wpinv_is_invoice_viewed($invoice->get_id())) { |
|
185 | + echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__('Viewed by Customer', 'invoicing') . '"></i>'; |
|
186 | 186 | } else { |
187 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
187 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__('Not Viewed by Customer', 'invoicing') . '"></i>'; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | // Display the overview status. |
191 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
191 | + if (wpinv_get_option('overdue_active')) { |
|
192 | 192 | $due_date = $invoice->get_due_date(); |
193 | - $fomatted = getpaid_format_date( $due_date ); |
|
193 | + $fomatted = getpaid_format_date($due_date); |
|
194 | 194 | |
195 | - if ( ! empty( $fomatted ) ) { |
|
196 | - $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
195 | + if (!empty($fomatted)) { |
|
196 | + $date = wp_sprintf(__('Due %s', 'invoicing'), $fomatted); |
|
197 | 197 | echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
198 | 198 | } |
199 | 199 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | |
205 | 205 | case 'recurring': |
206 | 206 | |
207 | - if ( $invoice->is_recurring() ) { |
|
207 | + if ($invoice->is_recurring()) { |
|
208 | 208 | echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
209 | 209 | } else { |
210 | 210 | echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
@@ -213,9 +213,9 @@ discard block |
||
213 | 213 | |
214 | 214 | case 'number' : |
215 | 215 | |
216 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
217 | - $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
218 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
216 | + $edit_link = esc_url(get_edit_post_link($invoice->get_id())); |
|
217 | + $invoice_number = sanitize_text_field($invoice->get_number()); |
|
218 | + $invoice_details = esc_attr__('View Invoice Details', 'invoicing'); |
|
219 | 219 | |
220 | 220 | echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
221 | 221 | |
@@ -225,13 +225,13 @@ discard block |
||
225 | 225 | |
226 | 226 | $customer_name = $invoice->get_user_full_name(); |
227 | 227 | |
228 | - if ( empty( $customer_name ) ) { |
|
228 | + if (empty($customer_name)) { |
|
229 | 229 | $customer_name = $invoice->get_email(); |
230 | 230 | } |
231 | 231 | |
232 | - if ( ! empty( $customer_name ) ) { |
|
233 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
234 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
232 | + if (!empty($customer_name)) { |
|
233 | + $customer_details = esc_attr__('View Customer Details', 'invoicing'); |
|
234 | + $view_link = esc_url(add_query_arg('user_id', $invoice->get_user_id(), admin_url('user-edit.php'))); |
|
235 | 235 | echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
236 | 236 | } else { |
237 | 237 | echo '<div>—</div>'; |
@@ -241,12 +241,12 @@ discard block |
||
241 | 241 | |
242 | 242 | case 'wpi_actions' : |
243 | 243 | |
244 | - if ( $invoice->is_draft() ) { |
|
244 | + if ($invoice->is_draft()) { |
|
245 | 245 | return; |
246 | 246 | } |
247 | 247 | |
248 | - $url = esc_url( $invoice->get_view_url() ); |
|
249 | - $print = esc_attr__( 'Print invoice', 'invoicing' ); |
|
248 | + $url = esc_url($invoice->get_view_url()); |
|
249 | + $print = esc_attr__('Print invoice', 'invoicing'); |
|
250 | 250 | echo " <a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>"; |
251 | 251 | |
252 | 252 | $url = esc_url( |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | ) |
263 | 263 | ); |
264 | 264 | |
265 | - $send = esc_attr__( 'Send invoice to customer', 'invoicing' ); |
|
265 | + $send = esc_attr__('Send invoice to customer', 'invoicing'); |
|
266 | 266 | echo " <a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>"; |
267 | 267 | |
268 | 268 | break; |
@@ -273,50 +273,50 @@ discard block |
||
273 | 273 | /** |
274 | 274 | * Returns an array of payment forms table columns. |
275 | 275 | */ |
276 | - public static function payment_form_columns( $columns ) { |
|
276 | + public static function payment_form_columns($columns) { |
|
277 | 277 | |
278 | 278 | $columns = array( |
279 | 279 | 'cb' => $columns['cb'], |
280 | - 'title' => __( 'Name', 'invoicing' ), |
|
281 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
282 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
283 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
284 | - 'items' => __( 'Items', 'invoicing' ), |
|
285 | - 'date' => __( 'Date', 'invoicing' ), |
|
280 | + 'title' => __('Name', 'invoicing'), |
|
281 | + 'shortcode' => __('Shortcode', 'invoicing'), |
|
282 | + 'earnings' => __('Revenue', 'invoicing'), |
|
283 | + 'refunds' => __('Refunded', 'invoicing'), |
|
284 | + 'items' => __('Items', 'invoicing'), |
|
285 | + 'date' => __('Date', 'invoicing'), |
|
286 | 286 | ); |
287 | 287 | |
288 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
288 | + return apply_filters('wpi_payment_form_table_columns', $columns); |
|
289 | 289 | |
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
293 | 293 | * Displays payment form table columns. |
294 | 294 | */ |
295 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
295 | + public static function display_payment_form_columns($column_name, $post_id) { |
|
296 | 296 | |
297 | 297 | // Retrieve the payment form. |
298 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
298 | + $form = new GetPaid_Payment_Form($post_id); |
|
299 | 299 | |
300 | - switch ( $column_name ) { |
|
300 | + switch ($column_name) { |
|
301 | 301 | |
302 | 302 | case 'earnings' : |
303 | - echo wpinv_price( wpinv_format_amount( $form->get_earned() ) ); |
|
303 | + echo wpinv_price(wpinv_format_amount($form->get_earned())); |
|
304 | 304 | break; |
305 | 305 | |
306 | 306 | case 'refunds' : |
307 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
307 | + echo wpinv_price(wpinv_format_amount($form->get_refunded())); |
|
308 | 308 | break; |
309 | 309 | |
310 | 310 | case 'refunds' : |
311 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
311 | + echo wpinv_price(wpinv_format_amount($form->get_refunded())); |
|
312 | 312 | break; |
313 | 313 | |
314 | 314 | case 'shortcode' : |
315 | 315 | |
316 | - if ( $form->is_default() ) { |
|
316 | + if ($form->is_default()) { |
|
317 | 317 | echo '—'; |
318 | 318 | } else { |
319 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
319 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr($form->get_id()) . ']" style="width: 100%;" readonly/>'; |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | break; |
@@ -325,29 +325,29 @@ discard block |
||
325 | 325 | |
326 | 326 | $items = $form->get_items(); |
327 | 327 | |
328 | - if ( $form->is_default() || empty( $items ) ) { |
|
328 | + if ($form->is_default() || empty($items)) { |
|
329 | 329 | echo '—'; |
330 | 330 | return; |
331 | 331 | } |
332 | 332 | |
333 | 333 | $_items = array(); |
334 | 334 | |
335 | - foreach ( $items as $item ) { |
|
335 | + foreach ($items as $item) { |
|
336 | 336 | $url = $item->get_edit_url(); |
337 | 337 | |
338 | - if ( empty( $url ) ) { |
|
339 | - $_items[] = sanitize_text_field( $item->get_name() ); |
|
338 | + if (empty($url)) { |
|
339 | + $_items[] = sanitize_text_field($item->get_name()); |
|
340 | 340 | } else { |
341 | 341 | $_items[] = sprintf( |
342 | 342 | '<a href="%s">%s</a>', |
343 | - esc_url( $url ), |
|
344 | - sanitize_text_field( $item->get_name() ) |
|
343 | + esc_url($url), |
|
344 | + sanitize_text_field($item->get_name()) |
|
345 | 345 | ); |
346 | 346 | } |
347 | 347 | |
348 | 348 | } |
349 | 349 | |
350 | - echo implode( '<br>', $_items ); |
|
350 | + echo implode('<br>', $_items); |
|
351 | 351 | |
352 | 352 | break; |
353 | 353 | |
@@ -358,10 +358,10 @@ discard block |
||
358 | 358 | /** |
359 | 359 | * Filters post states. |
360 | 360 | */ |
361 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
361 | + public static function filter_payment_form_state($post_states, $post) { |
|
362 | 362 | |
363 | - if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
364 | - $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
363 | + if ('wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID) { |
|
364 | + $post_states['default_form'] = __('Default Payment Form', 'invoicing'); |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | return $post_states; |
@@ -371,35 +371,35 @@ discard block |
||
371 | 371 | /** |
372 | 372 | * Returns an array of coupon table columns. |
373 | 373 | */ |
374 | - public static function discount_columns( $columns ) { |
|
374 | + public static function discount_columns($columns) { |
|
375 | 375 | |
376 | 376 | $columns = array( |
377 | 377 | 'cb' => $columns['cb'], |
378 | - 'title' => __( 'Name', 'invoicing' ), |
|
379 | - 'code' => __( 'Code', 'invoicing' ), |
|
380 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
381 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
382 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
383 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
378 | + 'title' => __('Name', 'invoicing'), |
|
379 | + 'code' => __('Code', 'invoicing'), |
|
380 | + 'amount' => __('Amount', 'invoicing'), |
|
381 | + 'usage' => __('Usage / Limit', 'invoicing'), |
|
382 | + 'start_date' => __('Start Date', 'invoicing'), |
|
383 | + 'expiry_date' => __('Expiry Date', 'invoicing'), |
|
384 | 384 | ); |
385 | 385 | |
386 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
386 | + return apply_filters('wpi_discount_table_columns', $columns); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
390 | 390 | * Filters post states. |
391 | 391 | */ |
392 | - public static function filter_discount_state( $post_states, $post ) { |
|
392 | + public static function filter_discount_state($post_states, $post) { |
|
393 | 393 | |
394 | - if ( 'wpi_discount' == $post->post_type ) { |
|
394 | + if ('wpi_discount' == $post->post_type) { |
|
395 | 395 | |
396 | - $discount = new WPInv_Discount( $post ); |
|
396 | + $discount = new WPInv_Discount($post); |
|
397 | 397 | |
398 | 398 | $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
399 | 399 | |
400 | - if ( $status != 'publish' ) { |
|
400 | + if ($status != 'publish') { |
|
401 | 401 | return array( |
402 | - 'discount_status' => wpinv_discount_status( $status ), |
|
402 | + 'discount_status' => wpinv_discount_status($status), |
|
403 | 403 | ); |
404 | 404 | } |
405 | 405 | |
@@ -414,34 +414,34 @@ discard block |
||
414 | 414 | /** |
415 | 415 | * Returns an array of items table columns. |
416 | 416 | */ |
417 | - public static function item_columns( $columns ) { |
|
417 | + public static function item_columns($columns) { |
|
418 | 418 | global $wpinv_euvat; |
419 | 419 | |
420 | 420 | $columns = array( |
421 | 421 | 'cb' => $columns['cb'], |
422 | - 'title' => __( 'Name', 'invoicing' ), |
|
423 | - 'price' => __( 'Price', 'invoicing' ), |
|
424 | - 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
425 | - 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
426 | - 'type' => __( 'Type', 'invoicing' ), |
|
427 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
422 | + 'title' => __('Name', 'invoicing'), |
|
423 | + 'price' => __('Price', 'invoicing'), |
|
424 | + 'vat_rule' => __('VAT rule', 'invoicing'), |
|
425 | + 'vat_class' => __('VAT class', 'invoicing'), |
|
426 | + 'type' => __('Type', 'invoicing'), |
|
427 | + 'shortcode' => __('Shortcode', 'invoicing'), |
|
428 | 428 | ); |
429 | 429 | |
430 | - if ( ! $wpinv_euvat->allow_vat_rules() ) { |
|
431 | - unset( $columns['vat_rule'] ); |
|
430 | + if (!$wpinv_euvat->allow_vat_rules()) { |
|
431 | + unset($columns['vat_rule']); |
|
432 | 432 | } |
433 | 433 | |
434 | - if ( ! $wpinv_euvat->allow_vat_classes() ) { |
|
435 | - unset( $columns['vat_class'] ); |
|
434 | + if (!$wpinv_euvat->allow_vat_classes()) { |
|
435 | + unset($columns['vat_class']); |
|
436 | 436 | } |
437 | 437 | |
438 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
438 | + return apply_filters('wpi_item_table_columns', $columns); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | /** |
442 | 442 | * Returns an array of sortable items table columns. |
443 | 443 | */ |
444 | - public static function sortable_item_columns( $columns ) { |
|
444 | + public static function sortable_item_columns($columns) { |
|
445 | 445 | |
446 | 446 | return array_merge( |
447 | 447 | $columns, |
@@ -458,50 +458,50 @@ discard block |
||
458 | 458 | /** |
459 | 459 | * Displays items table columns. |
460 | 460 | */ |
461 | - public static function display_item_columns( $column_name, $post_id ) { |
|
461 | + public static function display_item_columns($column_name, $post_id) { |
|
462 | 462 | global $wpinv_euvat; |
463 | 463 | |
464 | - $item = new WPInv_Item( $post_id ); |
|
464 | + $item = new WPInv_Item($post_id); |
|
465 | 465 | |
466 | - switch ( $column_name ) { |
|
466 | + switch ($column_name) { |
|
467 | 467 | |
468 | 468 | case 'price' : |
469 | 469 | |
470 | - if ( ! $item->is_recurring() ) { |
|
470 | + if (!$item->is_recurring()) { |
|
471 | 471 | echo $item->get_the_price(); |
472 | 472 | break; |
473 | 473 | } |
474 | 474 | |
475 | 475 | $price = wp_sprintf( |
476 | - __( '%s / %s', 'invoicing' ), |
|
476 | + __('%s / %s', 'invoicing'), |
|
477 | 477 | $item->get_the_price(), |
478 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
478 | + getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '') |
|
479 | 479 | ); |
480 | 480 | |
481 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
481 | + if ($item->get_the_price() == $item->get_the_initial_price()) { |
|
482 | 482 | echo $price; |
483 | 483 | break; |
484 | 484 | } |
485 | 485 | |
486 | 486 | echo $item->get_the_initial_price(); |
487 | 487 | |
488 | - echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
488 | + echo '<span class="meta">' . wp_sprintf(__('then %s', 'invoicing'), $price) . '</span>'; |
|
489 | 489 | break; |
490 | 490 | |
491 | 491 | case 'vat_rule' : |
492 | - echo $wpinv_euvat->item_rule_label( $item->get_id() ); |
|
492 | + echo $wpinv_euvat->item_rule_label($item->get_id()); |
|
493 | 493 | break; |
494 | 494 | |
495 | 495 | case 'vat_class' : |
496 | - echo $wpinv_euvat->item_class_label( $item->get_id() ); |
|
496 | + echo $wpinv_euvat->item_class_label($item->get_id()); |
|
497 | 497 | break; |
498 | 498 | |
499 | 499 | case 'shortcode' : |
500 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
500 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr($item->get_id()) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
501 | 501 | break; |
502 | 502 | |
503 | 503 | case 'type' : |
504 | - echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
504 | + echo wpinv_item_type($item->get_id()) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
505 | 505 | break; |
506 | 506 | |
507 | 507 | } |
@@ -511,22 +511,22 @@ discard block |
||
511 | 511 | /** |
512 | 512 | * Lets users filter items using taxes. |
513 | 513 | */ |
514 | - public static function add_item_filters( $post_type ) { |
|
514 | + public static function add_item_filters($post_type) { |
|
515 | 515 | $wpinv_euvat = getpaid_tax(); |
516 | 516 | |
517 | 517 | // Abort if we're not dealing with items. |
518 | - if ( $post_type != 'wpi_item' ) { |
|
518 | + if ($post_type != 'wpi_item') { |
|
519 | 519 | return; |
520 | 520 | } |
521 | 521 | |
522 | 522 | // Filter by vat rules. |
523 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
523 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
524 | 524 | |
525 | 525 | // Sanitize selected vat rule. |
526 | 526 | $vat_rule = ''; |
527 | 527 | $vat_rules = $wpinv_euvat->get_rules(); |
528 | - if ( isset( $_GET['vat_rule'] ) ) { |
|
529 | - $vat_rule = $_GET['vat_rule']; |
|
528 | + if (isset($_GET['vat_rule'])) { |
|
529 | + $vat_rule = $_GET['vat_rule']; |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | // Filter by VAT rule. |
@@ -534,13 +534,13 @@ discard block |
||
534 | 534 | array( |
535 | 535 | 'options' => array_merge( |
536 | 536 | array( |
537 | - '' => __( 'All VAT rules', 'invoicing' ) |
|
537 | + '' => __('All VAT rules', 'invoicing') |
|
538 | 538 | ), |
539 | 539 | $vat_rules |
540 | 540 | ), |
541 | 541 | 'name' => 'vat_rule', |
542 | 542 | 'id' => 'vat_rule', |
543 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
543 | + 'selected' => in_array($vat_rule, array_keys($vat_rules)) ? $vat_rule : '', |
|
544 | 544 | 'show_option_all' => false, |
545 | 545 | 'show_option_none' => false, |
546 | 546 | 'class' => 'gdmbx2-text-medium', |
@@ -551,26 +551,26 @@ discard block |
||
551 | 551 | } |
552 | 552 | |
553 | 553 | // Filter by vat class. |
554 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
554 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
555 | 555 | |
556 | 556 | // Sanitize selected vat rule. |
557 | 557 | $vat_class = ''; |
558 | 558 | $vat_classes = $wpinv_euvat->get_all_classes(); |
559 | - if ( isset( $_GET['vat_class'] ) ) { |
|
560 | - $vat_class = $_GET['vat_class']; |
|
559 | + if (isset($_GET['vat_class'])) { |
|
560 | + $vat_class = $_GET['vat_class']; |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | echo wpinv_html_select( |
564 | 564 | array( |
565 | 565 | 'options' => array_merge( |
566 | 566 | array( |
567 | - '' => __( 'All VAT classes', 'invoicing' ) |
|
567 | + '' => __('All VAT classes', 'invoicing') |
|
568 | 568 | ), |
569 | 569 | $vat_classes |
570 | 570 | ), |
571 | 571 | 'name' => 'vat_class', |
572 | 572 | 'id' => 'vat_class', |
573 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
573 | + 'selected' => in_array($vat_class, array_keys($vat_classes)) ? $vat_class : '', |
|
574 | 574 | 'show_option_all' => false, |
575 | 575 | 'show_option_none' => false, |
576 | 576 | 'class' => 'gdmbx2-text-medium', |
@@ -580,22 +580,22 @@ discard block |
||
580 | 580 | } |
581 | 581 | |
582 | 582 | // Filter by item type. |
583 | - $type = ''; |
|
584 | - if ( isset( $_GET['type'] ) ) { |
|
585 | - $type = $_GET['type']; |
|
583 | + $type = ''; |
|
584 | + if (isset($_GET['type'])) { |
|
585 | + $type = $_GET['type']; |
|
586 | 586 | } |
587 | 587 | |
588 | 588 | echo wpinv_html_select( |
589 | 589 | array( |
590 | 590 | 'options' => array_merge( |
591 | 591 | array( |
592 | - '' => __( 'All item types', 'invoicing' ) |
|
592 | + '' => __('All item types', 'invoicing') |
|
593 | 593 | ), |
594 | 594 | wpinv_get_item_types() |
595 | 595 | ), |
596 | 596 | 'name' => 'type', |
597 | 597 | 'id' => 'type', |
598 | - 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
598 | + 'selected' => in_array($type, wpinv_item_types()) ? $type : '', |
|
599 | 599 | 'show_option_all' => false, |
600 | 600 | 'show_option_none' => false, |
601 | 601 | 'class' => 'gdmbx2-text-medium', |
@@ -607,45 +607,45 @@ discard block |
||
607 | 607 | /** |
608 | 608 | * Filters the item query. |
609 | 609 | */ |
610 | - public static function filter_item_query( $query ) { |
|
610 | + public static function filter_item_query($query) { |
|
611 | 611 | |
612 | 612 | // modify the query only if it admin and main query. |
613 | - if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
613 | + if (!(is_admin() && $query->is_main_query())) { |
|
614 | 614 | return $query; |
615 | 615 | } |
616 | 616 | |
617 | 617 | // we want to modify the query for our items. |
618 | - if ( 'wpi_item' != $query->query['post_type'] ){ |
|
618 | + if ('wpi_item' != $query->query['post_type']) { |
|
619 | 619 | return $query; |
620 | 620 | } |
621 | 621 | |
622 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
622 | + if (empty($query->query_vars['meta_query'])) { |
|
623 | 623 | $query->query_vars['meta_query'] = array(); |
624 | 624 | } |
625 | 625 | |
626 | 626 | // Filter vat rule type |
627 | - if ( ! empty( $_GET['vat_rule'] ) ) { |
|
627 | + if (!empty($_GET['vat_rule'])) { |
|
628 | 628 | $query->query_vars['meta_query'][] = array( |
629 | 629 | 'key' => '_wpinv_vat_rule', |
630 | - 'value' => sanitize_text_field( $_GET['vat_rule'] ), |
|
630 | + 'value' => sanitize_text_field($_GET['vat_rule']), |
|
631 | 631 | 'compare' => '=' |
632 | 632 | ); |
633 | 633 | } |
634 | 634 | |
635 | 635 | // Filter vat class |
636 | - if ( ! empty( $_GET['vat_class'] ) ) { |
|
636 | + if (!empty($_GET['vat_class'])) { |
|
637 | 637 | $query->query_vars['meta_query'][] = array( |
638 | 638 | 'key' => '_wpinv_vat_class', |
639 | - 'value' => sanitize_text_field( $_GET['vat_class'] ), |
|
639 | + 'value' => sanitize_text_field($_GET['vat_class']), |
|
640 | 640 | 'compare' => '=' |
641 | 641 | ); |
642 | 642 | } |
643 | 643 | |
644 | 644 | // Filter item type |
645 | - if ( ! empty( $_GET['type'] ) ) { |
|
645 | + if (!empty($_GET['type'])) { |
|
646 | 646 | $query->query_vars['meta_query'][] = array( |
647 | 647 | 'key' => '_wpinv_type', |
648 | - 'value' => sanitize_text_field( $_GET['type'] ), |
|
648 | + 'value' => sanitize_text_field($_GET['type']), |
|
649 | 649 | 'compare' => '=' |
650 | 650 | ); |
651 | 651 | } |
@@ -655,15 +655,15 @@ discard block |
||
655 | 655 | /** |
656 | 656 | * Reorders items. |
657 | 657 | */ |
658 | - public static function reorder_items( $vars ) { |
|
658 | + public static function reorder_items($vars) { |
|
659 | 659 | global $typenow; |
660 | 660 | |
661 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
661 | + if ('wpi_item' !== $typenow || empty($vars['orderby'])) { |
|
662 | 662 | return $vars; |
663 | 663 | } |
664 | 664 | |
665 | 665 | // By item type. |
666 | - if ( 'type' == $vars['orderby'] ) { |
|
666 | + if ('type' == $vars['orderby']) { |
|
667 | 667 | return array_merge( |
668 | 668 | $vars, |
669 | 669 | array( |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | } |
675 | 675 | |
676 | 676 | // By vat class. |
677 | - if ( 'vat_class' == $vars['orderby'] ) { |
|
677 | + if ('vat_class' == $vars['orderby']) { |
|
678 | 678 | return array_merge( |
679 | 679 | $vars, |
680 | 680 | array( |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | } |
686 | 686 | |
687 | 687 | // By vat rule. |
688 | - if ( 'vat_rule' == $vars['orderby'] ) { |
|
688 | + if ('vat_rule' == $vars['orderby']) { |
|
689 | 689 | return array_merge( |
690 | 690 | $vars, |
691 | 691 | array( |
@@ -696,7 +696,7 @@ discard block |
||
696 | 696 | } |
697 | 697 | |
698 | 698 | // By price. |
699 | - if ( 'price' == $vars['orderby'] ) { |
|
699 | + if ('price' == $vars['orderby']) { |
|
700 | 700 | return array_merge( |
701 | 701 | $vars, |
702 | 702 | array( |
@@ -713,27 +713,27 @@ discard block |
||
713 | 713 | /** |
714 | 714 | * Fired when deleting a post. |
715 | 715 | */ |
716 | - public static function delete_post( $post_id ) { |
|
716 | + public static function delete_post($post_id) { |
|
717 | 717 | |
718 | - switch ( get_post_type( $post_id ) ) { |
|
718 | + switch (get_post_type($post_id)) { |
|
719 | 719 | |
720 | 720 | case 'wpi_item' : |
721 | - do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
721 | + do_action("getpaid_before_delete_item", new WPInv_Item($post_id)); |
|
722 | 722 | break; |
723 | 723 | |
724 | 724 | case 'wpi_payment_form' : |
725 | - do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
725 | + do_action("getpaid_before_delete_payment_form", new GetPaid_Payment_Form($post_id)); |
|
726 | 726 | break; |
727 | 727 | |
728 | 728 | case 'wpi_discount' : |
729 | - do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
729 | + do_action("getpaid_before_delete_discount", new WPInv_Discount($post_id)); |
|
730 | 730 | break; |
731 | 731 | |
732 | 732 | case 'wpi_invoice' : |
733 | - $invoice = new WPInv_Invoice( $post_id ); |
|
734 | - do_action( "getpaid_before_delete_invoice", $invoice ); |
|
735 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
736 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
733 | + $invoice = new WPInv_Invoice($post_id); |
|
734 | + do_action("getpaid_before_delete_invoice", $invoice); |
|
735 | + $invoice->get_data_store()->delete_items($invoice); |
|
736 | + $invoice->get_data_store()->delete_special_fields($invoice); |
|
737 | 737 | break; |
738 | 738 | } |
739 | 739 | } |
@@ -7,8 +7,8 @@ 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 | final class WPInv_Legacy_Invoice { |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * Invoice id. |
18 | 18 | */ |
19 | - public $ID = 0; |
|
19 | + public $ID = 0; |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * The title of the invoice. Usually the invoice number. |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | /** |
133 | 133 | * The invoice status. |
134 | 134 | */ |
135 | - public $status = 'wpi-pending'; |
|
135 | + public $status = 'wpi-pending'; |
|
136 | 136 | |
137 | 137 | /** |
138 | 138 | * Same as self::$status. |
@@ -259,17 +259,17 @@ discard block |
||
259 | 259 | */ |
260 | 260 | public $parent_invoice = 0; |
261 | 261 | |
262 | - public function __construct( $invoice_id = false ) { |
|
263 | - if( empty( $invoice_id ) ) { |
|
262 | + public function __construct($invoice_id = false) { |
|
263 | + if (empty($invoice_id)) { |
|
264 | 264 | return false; |
265 | 265 | } |
266 | 266 | |
267 | - $this->setup_invoice( $invoice_id ); |
|
267 | + $this->setup_invoice($invoice_id); |
|
268 | 268 | } |
269 | 269 | |
270 | - public function get( $key ) { |
|
271 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
272 | - $value = call_user_func( array( $this, 'get_' . $key ) ); |
|
270 | + public function get($key) { |
|
271 | + if (method_exists($this, 'get_' . $key)) { |
|
272 | + $value = call_user_func(array($this, 'get_' . $key)); |
|
273 | 273 | } else { |
274 | 274 | $value = $this->$key; |
275 | 275 | } |
@@ -277,51 +277,51 @@ discard block |
||
277 | 277 | return $value; |
278 | 278 | } |
279 | 279 | |
280 | - public function set( $key, $value ) { |
|
281 | - $ignore = array( 'items', 'cart_details', 'fees', '_ID' ); |
|
280 | + public function set($key, $value) { |
|
281 | + $ignore = array('items', 'cart_details', 'fees', '_ID'); |
|
282 | 282 | |
283 | - if ( $key === 'status' ) { |
|
283 | + if ($key === 'status') { |
|
284 | 284 | $this->old_status = $this->status; |
285 | 285 | } |
286 | 286 | |
287 | - if ( ! in_array( $key, $ignore ) ) { |
|
288 | - $this->pending[ $key ] = $value; |
|
287 | + if (!in_array($key, $ignore)) { |
|
288 | + $this->pending[$key] = $value; |
|
289 | 289 | } |
290 | 290 | |
291 | - if( '_ID' !== $key ) { |
|
291 | + if ('_ID' !== $key) { |
|
292 | 292 | $this->$key = $value; |
293 | 293 | } |
294 | 294 | } |
295 | 295 | |
296 | - public function _isset( $name ) { |
|
297 | - if ( property_exists( $this, $name) ) { |
|
298 | - return false === empty( $this->$name ); |
|
296 | + public function _isset($name) { |
|
297 | + if (property_exists($this, $name)) { |
|
298 | + return false === empty($this->$name); |
|
299 | 299 | } else { |
300 | 300 | return null; |
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
304 | - private function setup_invoice( $invoice_id ) { |
|
304 | + private function setup_invoice($invoice_id) { |
|
305 | 305 | $this->pending = array(); |
306 | 306 | |
307 | - if ( empty( $invoice_id ) ) { |
|
307 | + if (empty($invoice_id)) { |
|
308 | 308 | return false; |
309 | 309 | } |
310 | 310 | |
311 | - $invoice = get_post( $invoice_id ); |
|
311 | + $invoice = get_post($invoice_id); |
|
312 | 312 | |
313 | - if( !$invoice || is_wp_error( $invoice ) ) { |
|
313 | + if (!$invoice || is_wp_error($invoice)) { |
|
314 | 314 | return false; |
315 | 315 | } |
316 | 316 | |
317 | - if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) { |
|
317 | + if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) { |
|
318 | 318 | return false; |
319 | 319 | } |
320 | 320 | |
321 | - do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id ); |
|
321 | + do_action('wpinv_pre_setup_invoice', $this, $invoice_id); |
|
322 | 322 | |
323 | 323 | // Primary Identifier |
324 | - $this->ID = absint( $invoice_id ); |
|
324 | + $this->ID = absint($invoice_id); |
|
325 | 325 | $this->post_type = $invoice->post_type; |
326 | 326 | |
327 | 327 | // We have a payment, get the generic payment_meta item to reduce calls to it |
@@ -331,14 +331,14 @@ discard block |
||
331 | 331 | $this->completed_date = $this->setup_completed_date(); |
332 | 332 | $this->status = $invoice->post_status; |
333 | 333 | |
334 | - if ( 'future' == $this->status ) { |
|
334 | + if ('future' == $this->status) { |
|
335 | 335 | $this->status = 'publish'; |
336 | 336 | } |
337 | 337 | |
338 | 338 | $this->post_status = $this->status; |
339 | 339 | $this->mode = $this->setup_mode(); |
340 | 340 | $this->parent_invoice = $invoice->post_parent; |
341 | - $this->post_name = $this->setup_post_name( $invoice ); |
|
341 | + $this->post_name = $this->setup_post_name($invoice); |
|
342 | 342 | $this->status_nicename = $this->setup_status_nicename($invoice->post_status); |
343 | 343 | |
344 | 344 | // Items |
@@ -361,8 +361,8 @@ discard block |
||
361 | 361 | |
362 | 362 | // User based |
363 | 363 | $this->ip = $this->setup_ip(); |
364 | - $this->user_id = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id(); |
|
365 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
364 | + $this->user_id = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id(); |
|
365 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
366 | 366 | |
367 | 367 | $this->user_info = $this->setup_user_info(); |
368 | 368 | |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | $this->company = $this->user_info['company']; |
372 | 372 | $this->vat_number = $this->user_info['vat_number']; |
373 | 373 | $this->vat_rate = $this->user_info['vat_rate']; |
374 | - $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
374 | + $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
375 | 375 | $this->address = $this->user_info['address']; |
376 | 376 | $this->city = $this->user_info['city']; |
377 | 377 | $this->country = $this->user_info['country']; |
@@ -386,39 +386,39 @@ discard block |
||
386 | 386 | // Other Identifiers |
387 | 387 | $this->key = $this->setup_invoice_key(); |
388 | 388 | $this->number = $this->setup_invoice_number(); |
389 | - $this->title = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number; |
|
389 | + $this->title = !empty($invoice->post_title) ? $invoice->post_title : $this->number; |
|
390 | 390 | |
391 | - $this->full_name = trim( $this->first_name . ' '. $this->last_name ); |
|
391 | + $this->full_name = trim($this->first_name . ' ' . $this->last_name); |
|
392 | 392 | |
393 | 393 | // Allow extensions to add items to this object via hook |
394 | - do_action( 'wpinv_setup_invoice', $this, $invoice_id ); |
|
394 | + do_action('wpinv_setup_invoice', $this, $invoice_id); |
|
395 | 395 | |
396 | 396 | return true; |
397 | 397 | } |
398 | 398 | |
399 | - private function setup_status_nicename( $status ) { |
|
400 | - $all_invoice_statuses = wpinv_get_invoice_statuses( true, true, $this ); |
|
399 | + private function setup_status_nicename($status) { |
|
400 | + $all_invoice_statuses = wpinv_get_invoice_statuses(true, true, $this); |
|
401 | 401 | |
402 | - if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) { |
|
403 | - $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
|
402 | + if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) { |
|
403 | + $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
|
404 | 404 | } |
405 | - $status = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' ); |
|
405 | + $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing'); |
|
406 | 406 | |
407 | - return apply_filters( 'setup_status_nicename', $status ); |
|
407 | + return apply_filters('setup_status_nicename', $status); |
|
408 | 408 | } |
409 | 409 | |
410 | - private function setup_post_name( $post = NULL ) { |
|
410 | + private function setup_post_name($post = NULL) { |
|
411 | 411 | global $wpdb; |
412 | 412 | |
413 | 413 | $post_name = ''; |
414 | 414 | |
415 | - if ( !empty( $post ) ) { |
|
416 | - if( !empty( $post->post_name ) ) { |
|
415 | + if (!empty($post)) { |
|
416 | + if (!empty($post->post_name)) { |
|
417 | 417 | $post_name = $post->post_name; |
418 | - } else if ( !empty( $post->ID ) ) { |
|
419 | - $post_name = wpinv_generate_post_name( $post->ID ); |
|
418 | + } else if (!empty($post->ID)) { |
|
419 | + $post_name = wpinv_generate_post_name($post->ID); |
|
420 | 420 | |
421 | - $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) ); |
|
421 | + $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID)); |
|
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
@@ -426,12 +426,12 @@ discard block |
||
426 | 426 | } |
427 | 427 | |
428 | 428 | private function setup_due_date() { |
429 | - $due_date = $this->get_meta( '_wpinv_due_date' ); |
|
429 | + $due_date = $this->get_meta('_wpinv_due_date'); |
|
430 | 430 | |
431 | - if ( empty( $due_date ) ) { |
|
432 | - $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) ); |
|
433 | - $due_date = date_i18n( 'Y-m-d', $overdue_time ); |
|
434 | - } else if ( $due_date == 'none' ) { |
|
431 | + if (empty($due_date)) { |
|
432 | + $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days'))); |
|
433 | + $due_date = date_i18n('Y-m-d', $overdue_time); |
|
434 | + } else if ($due_date == 'none') { |
|
435 | 435 | $due_date = ''; |
436 | 436 | } |
437 | 437 | |
@@ -439,67 +439,67 @@ discard block |
||
439 | 439 | } |
440 | 440 | |
441 | 441 | private function setup_completed_date() { |
442 | - $invoice = get_post( $this->ID ); |
|
442 | + $invoice = get_post($this->ID); |
|
443 | 443 | |
444 | - if ( 'wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) { |
|
444 | + if ('wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) { |
|
445 | 445 | return false; // This invoice was never paid |
446 | 446 | } |
447 | 447 | |
448 | - $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date; |
|
448 | + $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date; |
|
449 | 449 | |
450 | 450 | return $date; |
451 | 451 | } |
452 | 452 | |
453 | 453 | private function setup_cart_details() { |
454 | - $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array(); |
|
454 | + $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array(); |
|
455 | 455 | return $cart_details; |
456 | 456 | } |
457 | 457 | |
458 | 458 | public function array_convert() { |
459 | - return get_object_vars( $this ); |
|
459 | + return get_object_vars($this); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | private function setup_items() { |
463 | - $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array(); |
|
463 | + $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array(); |
|
464 | 464 | return $items; |
465 | 465 | } |
466 | 466 | |
467 | 467 | private function setup_fees() { |
468 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
468 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
469 | 469 | return $payment_fees; |
470 | 470 | } |
471 | 471 | |
472 | 472 | private function setup_currency() { |
473 | - $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this ); |
|
473 | + $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this); |
|
474 | 474 | return $currency; |
475 | 475 | } |
476 | 476 | |
477 | 477 | private function setup_discount() { |
478 | 478 | //$discount = $this->get_meta( '_wpinv_discount', true ); |
479 | - $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total ); |
|
480 | - if ( $discount < 0 ) { |
|
479 | + $discount = (float) $this->subtotal - ((float) $this->total - (float) $this->tax - (float) $this->fees_total); |
|
480 | + if ($discount < 0) { |
|
481 | 481 | $discount = 0; |
482 | 482 | } |
483 | - $discount = wpinv_round_amount( $discount ); |
|
483 | + $discount = wpinv_round_amount($discount); |
|
484 | 484 | |
485 | 485 | return $discount; |
486 | 486 | } |
487 | 487 | |
488 | 488 | private function setup_discount_code() { |
489 | - $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true ); |
|
489 | + $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true); |
|
490 | 490 | return $discount_code; |
491 | 491 | } |
492 | 492 | |
493 | 493 | private function setup_tax() { |
494 | 494 | |
495 | - $tax = $this->get_meta( '_wpinv_tax', true ); |
|
495 | + $tax = $this->get_meta('_wpinv_tax', true); |
|
496 | 496 | |
497 | 497 | // We don't have tax as it's own meta and no meta was passed |
498 | - if ( '' === $tax ) { |
|
499 | - $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0; |
|
498 | + if ('' === $tax) { |
|
499 | + $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0; |
|
500 | 500 | } |
501 | 501 | |
502 | - if ( $tax < 0 || ! $this->is_taxable() ) { |
|
502 | + if ($tax < 0 || !$this->is_taxable()) { |
|
503 | 503 | $tax = 0; |
504 | 504 | } |
505 | 505 | |
@@ -510,16 +510,16 @@ discard block |
||
510 | 510 | * If taxes are enabled, allow users to enable/disable taxes per invoice. |
511 | 511 | */ |
512 | 512 | private function setup_is_taxable() { |
513 | - return (int) $this->get_meta( '_wpinv_disable_taxes', true ); |
|
513 | + return (int) $this->get_meta('_wpinv_disable_taxes', true); |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | private function setup_subtotal() { |
517 | 517 | $subtotal = 0; |
518 | 518 | $cart_details = $this->cart_details; |
519 | 519 | |
520 | - if ( is_array( $cart_details ) ) { |
|
521 | - foreach ( $cart_details as $item ) { |
|
522 | - if ( isset( $item['subtotal'] ) ) { |
|
520 | + if (is_array($cart_details)) { |
|
521 | + foreach ($cart_details as $item) { |
|
522 | + if (isset($item['subtotal'])) { |
|
523 | 523 | $subtotal += $item['subtotal']; |
524 | 524 | } |
525 | 525 | } |
@@ -533,23 +533,23 @@ discard block |
||
533 | 533 | } |
534 | 534 | |
535 | 535 | private function setup_discounts() { |
536 | - $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array(); |
|
536 | + $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array(); |
|
537 | 537 | return $discounts; |
538 | 538 | } |
539 | 539 | |
540 | 540 | private function setup_total() { |
541 | - $amount = $this->get_meta( '_wpinv_total', true ); |
|
541 | + $amount = $this->get_meta('_wpinv_total', true); |
|
542 | 542 | |
543 | - if ( empty( $amount ) && '0.00' != $amount ) { |
|
544 | - $meta = $this->get_meta( '_wpinv_payment_meta', true ); |
|
545 | - $meta = maybe_unserialize( $meta ); |
|
543 | + if (empty($amount) && '0.00' != $amount) { |
|
544 | + $meta = $this->get_meta('_wpinv_payment_meta', true); |
|
545 | + $meta = maybe_unserialize($meta); |
|
546 | 546 | |
547 | - if ( isset( $meta['amount'] ) ) { |
|
547 | + if (isset($meta['amount'])) { |
|
548 | 548 | $amount = $meta['amount']; |
549 | 549 | } |
550 | 550 | } |
551 | 551 | |
552 | - if($amount < 0){ |
|
552 | + if ($amount < 0) { |
|
553 | 553 | $amount = 0; |
554 | 554 | } |
555 | 555 | |
@@ -557,13 +557,13 @@ discard block |
||
557 | 557 | } |
558 | 558 | |
559 | 559 | private function setup_mode() { |
560 | - return $this->get_meta( '_wpinv_mode' ); |
|
560 | + return $this->get_meta('_wpinv_mode'); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | private function setup_gateway() { |
564 | - $gateway = $this->get_meta( '_wpinv_gateway' ); |
|
564 | + $gateway = $this->get_meta('_wpinv_gateway'); |
|
565 | 565 | |
566 | - if ( empty( $gateway ) && 'publish' === $this->status ) { |
|
566 | + if (empty($gateway) && 'publish' === $this->status) { |
|
567 | 567 | $gateway = 'manual'; |
568 | 568 | } |
569 | 569 | |
@@ -571,23 +571,23 @@ discard block |
||
571 | 571 | } |
572 | 572 | |
573 | 573 | private function setup_gateway_title() { |
574 | - $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway ); |
|
574 | + $gateway_title = wpinv_get_gateway_checkout_label($this->gateway); |
|
575 | 575 | return $gateway_title; |
576 | 576 | } |
577 | 577 | |
578 | 578 | private function setup_transaction_id() { |
579 | - $transaction_id = $this->get_meta( '_wpinv_transaction_id' ); |
|
579 | + $transaction_id = $this->get_meta('_wpinv_transaction_id'); |
|
580 | 580 | |
581 | - if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) { |
|
581 | + if (empty($transaction_id) || (int) $transaction_id === (int) $this->ID) { |
|
582 | 582 | $gateway = $this->gateway; |
583 | - $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID ); |
|
583 | + $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | return $transaction_id; |
587 | 587 | } |
588 | 588 | |
589 | 589 | private function setup_ip() { |
590 | - $ip = $this->get_meta( '_wpinv_user_ip' ); |
|
590 | + $ip = $this->get_meta('_wpinv_user_ip'); |
|
591 | 591 | return $ip; |
592 | 592 | } |
593 | 593 | |
@@ -597,62 +597,62 @@ discard block |
||
597 | 597 | ///} |
598 | 598 | |
599 | 599 | private function setup_first_name() { |
600 | - $first_name = $this->get_meta( '_wpinv_first_name' ); |
|
600 | + $first_name = $this->get_meta('_wpinv_first_name'); |
|
601 | 601 | return $first_name; |
602 | 602 | } |
603 | 603 | |
604 | 604 | private function setup_last_name() { |
605 | - $last_name = $this->get_meta( '_wpinv_last_name' ); |
|
605 | + $last_name = $this->get_meta('_wpinv_last_name'); |
|
606 | 606 | return $last_name; |
607 | 607 | } |
608 | 608 | |
609 | 609 | private function setup_company() { |
610 | - $company = $this->get_meta( '_wpinv_company' ); |
|
610 | + $company = $this->get_meta('_wpinv_company'); |
|
611 | 611 | return $company; |
612 | 612 | } |
613 | 613 | |
614 | 614 | private function setup_vat_number() { |
615 | - $vat_number = $this->get_meta( '_wpinv_vat_number' ); |
|
615 | + $vat_number = $this->get_meta('_wpinv_vat_number'); |
|
616 | 616 | return $vat_number; |
617 | 617 | } |
618 | 618 | |
619 | 619 | private function setup_vat_rate() { |
620 | - $vat_rate = $this->get_meta( '_wpinv_vat_rate' ); |
|
620 | + $vat_rate = $this->get_meta('_wpinv_vat_rate'); |
|
621 | 621 | return $vat_rate; |
622 | 622 | } |
623 | 623 | |
624 | 624 | private function setup_adddress_confirmed() { |
625 | - $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' ); |
|
625 | + $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed'); |
|
626 | 626 | return $adddress_confirmed; |
627 | 627 | } |
628 | 628 | |
629 | 629 | private function setup_phone() { |
630 | - $phone = $this->get_meta( '_wpinv_phone' ); |
|
630 | + $phone = $this->get_meta('_wpinv_phone'); |
|
631 | 631 | return $phone; |
632 | 632 | } |
633 | 633 | |
634 | 634 | private function setup_address() { |
635 | - $address = $this->get_meta( '_wpinv_address', true ); |
|
635 | + $address = $this->get_meta('_wpinv_address', true); |
|
636 | 636 | return $address; |
637 | 637 | } |
638 | 638 | |
639 | 639 | private function setup_city() { |
640 | - $city = $this->get_meta( '_wpinv_city', true ); |
|
640 | + $city = $this->get_meta('_wpinv_city', true); |
|
641 | 641 | return $city; |
642 | 642 | } |
643 | 643 | |
644 | 644 | private function setup_country() { |
645 | - $country = $this->get_meta( '_wpinv_country', true ); |
|
645 | + $country = $this->get_meta('_wpinv_country', true); |
|
646 | 646 | return $country; |
647 | 647 | } |
648 | 648 | |
649 | 649 | private function setup_state() { |
650 | - $state = $this->get_meta( '_wpinv_state', true ); |
|
650 | + $state = $this->get_meta('_wpinv_state', true); |
|
651 | 651 | return $state; |
652 | 652 | } |
653 | 653 | |
654 | 654 | private function setup_zip() { |
655 | - $zip = $this->get_meta( '_wpinv_zip', true ); |
|
655 | + $zip = $this->get_meta('_wpinv_zip', true); |
|
656 | 656 | return $zip; |
657 | 657 | } |
658 | 658 | |
@@ -661,7 +661,7 @@ discard block |
||
661 | 661 | 'user_id' => $this->user_id, |
662 | 662 | 'first_name' => $this->first_name, |
663 | 663 | 'last_name' => $this->last_name, |
664 | - 'email' => get_the_author_meta( 'email', $this->user_id ), |
|
664 | + 'email' => get_the_author_meta('email', $this->user_id), |
|
665 | 665 | 'phone' => $this->phone, |
666 | 666 | 'address' => $this->address, |
667 | 667 | 'city' => $this->city, |
@@ -676,12 +676,12 @@ discard block |
||
676 | 676 | ); |
677 | 677 | |
678 | 678 | $user_info = array(); |
679 | - if ( isset( $this->payment_meta['user_info'] ) ) { |
|
680 | - $user_info = maybe_unserialize( $this->payment_meta['user_info'] ); |
|
679 | + if (isset($this->payment_meta['user_info'])) { |
|
680 | + $user_info = maybe_unserialize($this->payment_meta['user_info']); |
|
681 | 681 | |
682 | - if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) { |
|
682 | + if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) { |
|
683 | 683 | $this->user_id = $post->post_author; |
684 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
684 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
685 | 685 | |
686 | 686 | $user_info['user_id'] = $this->user_id; |
687 | 687 | $user_info['email'] = $this->email; |
@@ -690,13 +690,13 @@ discard block |
||
690 | 690 | } |
691 | 691 | } |
692 | 692 | |
693 | - $user_info = wp_parse_args( $user_info, $defaults ); |
|
693 | + $user_info = wp_parse_args($user_info, $defaults); |
|
694 | 694 | |
695 | 695 | // Get the user, but only if it's been created |
696 | - $user = get_userdata( $this->user_id ); |
|
696 | + $user = get_userdata($this->user_id); |
|
697 | 697 | |
698 | - if ( !empty( $user ) && $user->ID > 0 ) { |
|
699 | - if ( empty( $user_info ) ) { |
|
698 | + if (!empty($user) && $user->ID > 0) { |
|
699 | + if (empty($user_info)) { |
|
700 | 700 | $user_info = array( |
701 | 701 | 'user_id' => $user->ID, |
702 | 702 | 'first_name' => $user->first_name, |
@@ -705,23 +705,23 @@ discard block |
||
705 | 705 | 'discount' => '', |
706 | 706 | ); |
707 | 707 | } else { |
708 | - foreach ( $user_info as $key => $value ) { |
|
709 | - if ( ! empty( $value ) ) { |
|
708 | + foreach ($user_info as $key => $value) { |
|
709 | + if (!empty($value)) { |
|
710 | 710 | continue; |
711 | 711 | } |
712 | 712 | |
713 | - switch( $key ) { |
|
713 | + switch ($key) { |
|
714 | 714 | case 'user_id': |
715 | - $user_info[ $key ] = $user->ID; |
|
715 | + $user_info[$key] = $user->ID; |
|
716 | 716 | break; |
717 | 717 | case 'first_name': |
718 | - $user_info[ $key ] = $user->first_name; |
|
718 | + $user_info[$key] = $user->first_name; |
|
719 | 719 | break; |
720 | 720 | case 'last_name': |
721 | - $user_info[ $key ] = $user->last_name; |
|
721 | + $user_info[$key] = $user->last_name; |
|
722 | 722 | break; |
723 | 723 | case 'email': |
724 | - $user_info[ $key ] = $user->user_email; |
|
724 | + $user_info[$key] = $user->user_email; |
|
725 | 725 | break; |
726 | 726 | } |
727 | 727 | } |
@@ -732,25 +732,25 @@ discard block |
||
732 | 732 | } |
733 | 733 | |
734 | 734 | private function setup_invoice_key() { |
735 | - $key = $this->get_meta( '_wpinv_key', true ); |
|
735 | + $key = $this->get_meta('_wpinv_key', true); |
|
736 | 736 | |
737 | 737 | return $key; |
738 | 738 | } |
739 | 739 | |
740 | 740 | private function setup_invoice_number() { |
741 | - $number = $this->get_meta( '_wpinv_number', true ); |
|
741 | + $number = $this->get_meta('_wpinv_number', true); |
|
742 | 742 | |
743 | - if ( !$number ) { |
|
743 | + if (!$number) { |
|
744 | 744 | $number = $this->ID; |
745 | 745 | |
746 | - if ( $this->status == 'auto-draft' ) { |
|
747 | - if ( wpinv_sequential_number_active( $this->post_type ) ) { |
|
748 | - $next_number = wpinv_get_next_invoice_number( $this->post_type ); |
|
746 | + if ($this->status == 'auto-draft') { |
|
747 | + if (wpinv_sequential_number_active($this->post_type)) { |
|
748 | + $next_number = wpinv_get_next_invoice_number($this->post_type); |
|
749 | 749 | $number = $next_number; |
750 | 750 | } |
751 | 751 | } |
752 | 752 | |
753 | - $number = wpinv_format_invoice_number( $number, $this->post_type ); |
|
753 | + $number = wpinv_format_invoice_number($number, $this->post_type); |
|
754 | 754 | } |
755 | 755 | |
756 | 756 | return $number; |
@@ -758,7 +758,7 @@ discard block |
||
758 | 758 | |
759 | 759 | public function save() {} |
760 | 760 | |
761 | - public function add_fee( $args ) { |
|
761 | + public function add_fee($args) { |
|
762 | 762 | $default_args = array( |
763 | 763 | 'label' => '', |
764 | 764 | 'amount' => 0, |
@@ -768,75 +768,75 @@ discard block |
||
768 | 768 | 'item_id' => 0, |
769 | 769 | ); |
770 | 770 | |
771 | - $fee = wp_parse_args( $args, $default_args ); |
|
771 | + $fee = wp_parse_args($args, $default_args); |
|
772 | 772 | |
773 | - if ( empty( $fee['label'] ) ) { |
|
773 | + if (empty($fee['label'])) { |
|
774 | 774 | return false; |
775 | 775 | } |
776 | 776 | |
777 | - $fee['id'] = sanitize_title( $fee['label'] ); |
|
777 | + $fee['id'] = sanitize_title($fee['label']); |
|
778 | 778 | |
779 | - $this->fees[] = $fee; |
|
779 | + $this->fees[] = $fee; |
|
780 | 780 | |
781 | 781 | $added_fee = $fee; |
782 | 782 | $added_fee['action'] = 'add'; |
783 | 783 | $this->pending['fees'][] = $added_fee; |
784 | - reset( $this->fees ); |
|
784 | + reset($this->fees); |
|
785 | 785 | |
786 | - $this->increase_fees( $fee['amount'] ); |
|
786 | + $this->increase_fees($fee['amount']); |
|
787 | 787 | return true; |
788 | 788 | } |
789 | 789 | |
790 | - public function remove_fee( $key ) { |
|
790 | + public function remove_fee($key) { |
|
791 | 791 | $removed = false; |
792 | 792 | |
793 | - if ( is_numeric( $key ) ) { |
|
794 | - $removed = $this->remove_fee_by( 'index', $key ); |
|
793 | + if (is_numeric($key)) { |
|
794 | + $removed = $this->remove_fee_by('index', $key); |
|
795 | 795 | } |
796 | 796 | |
797 | 797 | return $removed; |
798 | 798 | } |
799 | 799 | |
800 | - public function remove_fee_by( $key, $value, $global = false ) { |
|
801 | - $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array( |
|
800 | + public function remove_fee_by($key, $value, $global = false) { |
|
801 | + $allowed_fee_keys = apply_filters('wpinv_fee_keys', array( |
|
802 | 802 | 'index', 'label', 'amount', 'type', |
803 | - ) ); |
|
803 | + )); |
|
804 | 804 | |
805 | - if ( ! in_array( $key, $allowed_fee_keys ) ) { |
|
805 | + if (!in_array($key, $allowed_fee_keys)) { |
|
806 | 806 | return false; |
807 | 807 | } |
808 | 808 | |
809 | 809 | $removed = false; |
810 | - if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) { |
|
811 | - $removed_fee = $this->fees[ $value ]; |
|
810 | + if ('index' === $key && array_key_exists($value, $this->fees)) { |
|
811 | + $removed_fee = $this->fees[$value]; |
|
812 | 812 | $removed_fee['action'] = 'remove'; |
813 | 813 | $this->pending['fees'][] = $removed_fee; |
814 | 814 | |
815 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
815 | + $this->decrease_fees($removed_fee['amount']); |
|
816 | 816 | |
817 | - unset( $this->fees[ $value ] ); |
|
817 | + unset($this->fees[$value]); |
|
818 | 818 | $removed = true; |
819 | - } else if ( 'index' !== $key ) { |
|
820 | - foreach ( $this->fees as $index => $fee ) { |
|
821 | - if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) { |
|
819 | + } else if ('index' !== $key) { |
|
820 | + foreach ($this->fees as $index => $fee) { |
|
821 | + if (isset($fee[$key]) && $fee[$key] == $value) { |
|
822 | 822 | $removed_fee = $fee; |
823 | 823 | $removed_fee['action'] = 'remove'; |
824 | 824 | $this->pending['fees'][] = $removed_fee; |
825 | 825 | |
826 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
826 | + $this->decrease_fees($removed_fee['amount']); |
|
827 | 827 | |
828 | - unset( $this->fees[ $index ] ); |
|
828 | + unset($this->fees[$index]); |
|
829 | 829 | $removed = true; |
830 | 830 | |
831 | - if ( false === $global ) { |
|
831 | + if (false === $global) { |
|
832 | 832 | break; |
833 | 833 | } |
834 | 834 | } |
835 | 835 | } |
836 | 836 | } |
837 | 837 | |
838 | - if ( true === $removed ) { |
|
839 | - $this->fees = array_values( $this->fees ); |
|
838 | + if (true === $removed) { |
|
839 | + $this->fees = array_values($this->fees); |
|
840 | 840 | } |
841 | 841 | |
842 | 842 | return $removed; |
@@ -844,35 +844,35 @@ discard block |
||
844 | 844 | |
845 | 845 | |
846 | 846 | |
847 | - public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
|
847 | + public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) { |
|
848 | 848 | // Bail if no note specified |
849 | - if( !$note ) { |
|
849 | + if (!$note) { |
|
850 | 850 | return false; |
851 | 851 | } |
852 | 852 | |
853 | - if ( empty( $this->ID ) ) |
|
853 | + if (empty($this->ID)) |
|
854 | 854 | return false; |
855 | 855 | |
856 | - if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) { |
|
857 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
856 | + if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) { |
|
857 | + $user = get_user_by('id', get_current_user_id()); |
|
858 | 858 | $comment_author = $user->display_name; |
859 | 859 | $comment_author_email = $user->user_email; |
860 | 860 | } else { |
861 | 861 | $comment_author = 'System'; |
862 | 862 | $comment_author_email = 'system@'; |
863 | - $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com'; |
|
864 | - $comment_author_email = sanitize_email( $comment_author_email ); |
|
863 | + $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com'; |
|
864 | + $comment_author_email = sanitize_email($comment_author_email); |
|
865 | 865 | } |
866 | 866 | |
867 | - do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type ); |
|
867 | + do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type); |
|
868 | 868 | |
869 | - $note_id = wp_insert_comment( wp_filter_comment( array( |
|
869 | + $note_id = wp_insert_comment(wp_filter_comment(array( |
|
870 | 870 | 'comment_post_ID' => $this->ID, |
871 | 871 | 'comment_content' => $note, |
872 | 872 | 'comment_agent' => 'WPInvoicing', |
873 | 873 | 'user_id' => is_admin() ? get_current_user_id() : 0, |
874 | - 'comment_date' => current_time( 'mysql' ), |
|
875 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
874 | + 'comment_date' => current_time('mysql'), |
|
875 | + 'comment_date_gmt' => current_time('mysql', 1), |
|
876 | 876 | 'comment_approved' => 1, |
877 | 877 | 'comment_parent' => 0, |
878 | 878 | 'comment_author' => $comment_author, |
@@ -880,53 +880,53 @@ discard block |
||
880 | 880 | 'comment_author_url' => '', |
881 | 881 | 'comment_author_email' => $comment_author_email, |
882 | 882 | 'comment_type' => 'wpinv_note' |
883 | - ) ) ); |
|
883 | + ))); |
|
884 | 884 | |
885 | - do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note ); |
|
885 | + do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note); |
|
886 | 886 | |
887 | - if ( $customer_type ) { |
|
888 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
887 | + if ($customer_type) { |
|
888 | + add_comment_meta($note_id, '_wpi_customer_note', 1); |
|
889 | 889 | |
890 | - do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) ); |
|
890 | + do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note)); |
|
891 | 891 | } |
892 | 892 | |
893 | 893 | return $note_id; |
894 | 894 | } |
895 | 895 | |
896 | - private function increase_subtotal( $amount = 0.00 ) { |
|
896 | + private function increase_subtotal($amount = 0.00) { |
|
897 | 897 | $amount = (float) $amount; |
898 | 898 | $this->subtotal += $amount; |
899 | - $this->subtotal = wpinv_round_amount( $this->subtotal ); |
|
899 | + $this->subtotal = wpinv_round_amount($this->subtotal); |
|
900 | 900 | |
901 | 901 | $this->recalculate_total(); |
902 | 902 | } |
903 | 903 | |
904 | - private function decrease_subtotal( $amount = 0.00 ) { |
|
904 | + private function decrease_subtotal($amount = 0.00) { |
|
905 | 905 | $amount = (float) $amount; |
906 | 906 | $this->subtotal -= $amount; |
907 | - $this->subtotal = wpinv_round_amount( $this->subtotal ); |
|
907 | + $this->subtotal = wpinv_round_amount($this->subtotal); |
|
908 | 908 | |
909 | - if ( $this->subtotal < 0 ) { |
|
909 | + if ($this->subtotal < 0) { |
|
910 | 910 | $this->subtotal = 0; |
911 | 911 | } |
912 | 912 | |
913 | 913 | $this->recalculate_total(); |
914 | 914 | } |
915 | 915 | |
916 | - private function increase_fees( $amount = 0.00 ) { |
|
917 | - $amount = (float)$amount; |
|
916 | + private function increase_fees($amount = 0.00) { |
|
917 | + $amount = (float) $amount; |
|
918 | 918 | $this->fees_total += $amount; |
919 | - $this->fees_total = wpinv_round_amount( $this->fees_total ); |
|
919 | + $this->fees_total = wpinv_round_amount($this->fees_total); |
|
920 | 920 | |
921 | 921 | $this->recalculate_total(); |
922 | 922 | } |
923 | 923 | |
924 | - private function decrease_fees( $amount = 0.00 ) { |
|
924 | + private function decrease_fees($amount = 0.00) { |
|
925 | 925 | $amount = (float) $amount; |
926 | 926 | $this->fees_total -= $amount; |
927 | - $this->fees_total = wpinv_round_amount( $this->fees_total ); |
|
927 | + $this->fees_total = wpinv_round_amount($this->fees_total); |
|
928 | 928 | |
929 | - if ( $this->fees_total < 0 ) { |
|
929 | + if ($this->fees_total < 0) { |
|
930 | 930 | $this->fees_total = 0; |
931 | 931 | } |
932 | 932 | |
@@ -937,56 +937,56 @@ discard block |
||
937 | 937 | global $wpi_nosave; |
938 | 938 | |
939 | 939 | $this->total = $this->subtotal + $this->tax + $this->fees_total; |
940 | - $this->total = wpinv_round_amount( $this->total ); |
|
940 | + $this->total = wpinv_round_amount($this->total); |
|
941 | 941 | |
942 | - do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave ); |
|
942 | + do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave); |
|
943 | 943 | } |
944 | 944 | |
945 | - public function increase_tax( $amount = 0.00 ) { |
|
945 | + public function increase_tax($amount = 0.00) { |
|
946 | 946 | $amount = (float) $amount; |
947 | 947 | $this->tax += $amount; |
948 | 948 | |
949 | 949 | $this->recalculate_total(); |
950 | 950 | } |
951 | 951 | |
952 | - public function decrease_tax( $amount = 0.00 ) { |
|
952 | + public function decrease_tax($amount = 0.00) { |
|
953 | 953 | $amount = (float) $amount; |
954 | 954 | $this->tax -= $amount; |
955 | 955 | |
956 | - if ( $this->tax < 0 ) { |
|
956 | + if ($this->tax < 0) { |
|
957 | 957 | $this->tax = 0; |
958 | 958 | } |
959 | 959 | |
960 | 960 | $this->recalculate_total(); |
961 | 961 | } |
962 | 962 | |
963 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
964 | - $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID ); |
|
963 | + public function update_status($new_status = false, $note = '', $manual = false) { |
|
964 | + $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID); |
|
965 | 965 | |
966 | - if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses( true ) ) ) ) { |
|
966 | + if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses(true)))) { |
|
967 | 967 | return false; // Don't permit status changes that aren't changes |
968 | 968 | } |
969 | 969 | |
970 | - $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status ); |
|
970 | + $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status); |
|
971 | 971 | $updated = false; |
972 | 972 | |
973 | - if ( $do_change ) { |
|
974 | - do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status ); |
|
973 | + if ($do_change) { |
|
974 | + do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status); |
|
975 | 975 | |
976 | 976 | $update_post_data = array(); |
977 | 977 | $update_post_data['ID'] = $this->ID; |
978 | 978 | $update_post_data['post_status'] = $new_status; |
979 | - $update_post_data['edit_date'] = current_time( 'mysql', 0 ); |
|
980 | - $update_post_data['edit_date_gmt'] = current_time( 'mysql', 1 ); |
|
979 | + $update_post_data['edit_date'] = current_time('mysql', 0); |
|
980 | + $update_post_data['edit_date_gmt'] = current_time('mysql', 1); |
|
981 | 981 | |
982 | - $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID ); |
|
982 | + $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID); |
|
983 | 983 | |
984 | - $updated = wp_update_post( $update_post_data ); |
|
984 | + $updated = wp_update_post($update_post_data); |
|
985 | 985 | |
986 | 986 | // Status was changed. |
987 | - do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status ); |
|
988 | - do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status ); |
|
989 | - do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status ); |
|
987 | + do_action('wpinv_status_' . $new_status, $this->ID, $old_status); |
|
988 | + do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status); |
|
989 | + do_action('wpinv_update_status', $this->ID, $new_status, $old_status); |
|
990 | 990 | } |
991 | 991 | |
992 | 992 | return $updated; |
@@ -1000,20 +1000,20 @@ discard block |
||
1000 | 1000 | $this->save(); |
1001 | 1001 | } |
1002 | 1002 | |
1003 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
1004 | - if ( empty( $meta_key ) ) { |
|
1003 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
1004 | + if (empty($meta_key)) { |
|
1005 | 1005 | return false; |
1006 | 1006 | } |
1007 | 1007 | |
1008 | - if ( $meta_key == 'key' || $meta_key == 'date' ) { |
|
1008 | + if ($meta_key == 'key' || $meta_key == 'date') { |
|
1009 | 1009 | $current_meta = $this->get_meta(); |
1010 | - $current_meta[ $meta_key ] = $meta_value; |
|
1010 | + $current_meta[$meta_key] = $meta_value; |
|
1011 | 1011 | |
1012 | 1012 | $meta_key = '_wpinv_payment_meta'; |
1013 | 1013 | $meta_value = $current_meta; |
1014 | 1014 | } |
1015 | 1015 | |
1016 | - $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID ); |
|
1016 | + $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID); |
|
1017 | 1017 | |
1018 | 1018 | // Do not update created date on invoice marked as paid. |
1019 | 1019 | /*if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) { |
@@ -1028,76 +1028,76 @@ discard block |
||
1028 | 1028 | wp_update_post( $args ); |
1029 | 1029 | }*/ |
1030 | 1030 | |
1031 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
1031 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | // get data |
1035 | - public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
1036 | - $meta = get_post_meta( $this->ID, $meta_key, $single ); |
|
1035 | + public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) { |
|
1036 | + $meta = get_post_meta($this->ID, $meta_key, $single); |
|
1037 | 1037 | |
1038 | - if ( $meta_key === '_wpinv_payment_meta' ) { |
|
1038 | + if ($meta_key === '_wpinv_payment_meta') { |
|
1039 | 1039 | |
1040 | - if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is. |
|
1040 | + if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is. |
|
1041 | 1041 | |
1042 | - if ( empty( $meta['key'] ) ) { |
|
1042 | + if (empty($meta['key'])) { |
|
1043 | 1043 | $meta['key'] = $this->setup_invoice_key(); |
1044 | 1044 | } |
1045 | 1045 | |
1046 | - if ( empty( $meta['date'] ) ) { |
|
1047 | - $meta['date'] = get_post_field( 'post_date', $this->ID ); |
|
1046 | + if (empty($meta['date'])) { |
|
1047 | + $meta['date'] = get_post_field('post_date', $this->ID); |
|
1048 | 1048 | } |
1049 | 1049 | } |
1050 | 1050 | |
1051 | - $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID ); |
|
1051 | + $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID); |
|
1052 | 1052 | |
1053 | - return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key ); |
|
1053 | + return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key); |
|
1054 | 1054 | } |
1055 | 1055 | |
1056 | 1056 | public function get_description() { |
1057 | - $post = get_post( $this->ID ); |
|
1057 | + $post = get_post($this->ID); |
|
1058 | 1058 | |
1059 | - $description = !empty( $post ) ? $post->post_content : ''; |
|
1060 | - return apply_filters( 'wpinv_get_description', $description, $this->ID, $this ); |
|
1059 | + $description = !empty($post) ? $post->post_content : ''; |
|
1060 | + return apply_filters('wpinv_get_description', $description, $this->ID, $this); |
|
1061 | 1061 | } |
1062 | 1062 | |
1063 | - public function get_status( $nicename = false ) { |
|
1064 | - if ( !$nicename ) { |
|
1063 | + public function get_status($nicename = false) { |
|
1064 | + if (!$nicename) { |
|
1065 | 1065 | $status = $this->status; |
1066 | 1066 | } else { |
1067 | 1067 | $status = $this->status_nicename; |
1068 | 1068 | } |
1069 | 1069 | |
1070 | - return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this ); |
|
1070 | + return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this); |
|
1071 | 1071 | } |
1072 | 1072 | |
1073 | 1073 | public function get_cart_details() { |
1074 | - return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this ); |
|
1074 | + return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this); |
|
1075 | 1075 | } |
1076 | 1076 | |
1077 | - public function get_subtotal( $currency = false ) { |
|
1078 | - $subtotal = wpinv_round_amount( $this->subtotal ); |
|
1077 | + public function get_subtotal($currency = false) { |
|
1078 | + $subtotal = wpinv_round_amount($this->subtotal); |
|
1079 | 1079 | |
1080 | - if ( $currency ) { |
|
1081 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() ); |
|
1080 | + if ($currency) { |
|
1081 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency()); |
|
1082 | 1082 | } |
1083 | 1083 | |
1084 | - return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency ); |
|
1084 | + return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency); |
|
1085 | 1085 | } |
1086 | 1086 | |
1087 | - public function get_total( $currency = false ) { |
|
1088 | - if ( $this->is_free_trial() ) { |
|
1089 | - $total = wpinv_round_amount( 0 ); |
|
1087 | + public function get_total($currency = false) { |
|
1088 | + if ($this->is_free_trial()) { |
|
1089 | + $total = wpinv_round_amount(0); |
|
1090 | 1090 | } else { |
1091 | - $total = wpinv_round_amount( $this->total ); |
|
1091 | + $total = wpinv_round_amount($this->total); |
|
1092 | 1092 | } |
1093 | - if ( $currency ) { |
|
1094 | - $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() ); |
|
1093 | + if ($currency) { |
|
1094 | + $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency()); |
|
1095 | 1095 | } |
1096 | 1096 | |
1097 | - return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency ); |
|
1097 | + return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency); |
|
1098 | 1098 | } |
1099 | 1099 | |
1100 | - public function get_recurring_details( $field = '', $currency = false ) { |
|
1100 | + public function get_recurring_details($field = '', $currency = false) { |
|
1101 | 1101 | $data = array(); |
1102 | 1102 | $data['cart_details'] = $this->cart_details; |
1103 | 1103 | $data['subtotal'] = $this->get_subtotal(); |
@@ -1105,119 +1105,119 @@ discard block |
||
1105 | 1105 | $data['tax'] = $this->get_tax(); |
1106 | 1106 | $data['total'] = $this->get_total(); |
1107 | 1107 | |
1108 | - if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) { |
|
1108 | + if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) { |
|
1109 | 1109 | $is_free_trial = $this->is_free_trial(); |
1110 | - $discounts = $this->get_discounts( true ); |
|
1110 | + $discounts = $this->get_discounts(true); |
|
1111 | 1111 | |
1112 | - if ( $is_free_trial || !empty( $discounts ) ) { |
|
1112 | + if ($is_free_trial || !empty($discounts)) { |
|
1113 | 1113 | $first_use_only = false; |
1114 | 1114 | |
1115 | - if ( !empty( $discounts ) ) { |
|
1116 | - foreach ( $discounts as $key => $code ) { |
|
1117 | - if ( wpinv_discount_is_recurring( $code, true ) && !$this->is_renewal() ) { |
|
1115 | + if (!empty($discounts)) { |
|
1116 | + foreach ($discounts as $key => $code) { |
|
1117 | + if (wpinv_discount_is_recurring($code, true) && !$this->is_renewal()) { |
|
1118 | 1118 | $first_use_only = true; |
1119 | 1119 | break; |
1120 | 1120 | } |
1121 | 1121 | } |
1122 | 1122 | } |
1123 | 1123 | |
1124 | - if ( !$first_use_only ) { |
|
1125 | - $data['subtotal'] = wpinv_round_amount( $this->subtotal ); |
|
1126 | - $data['discount'] = wpinv_round_amount( $this->discount ); |
|
1127 | - $data['tax'] = wpinv_round_amount( $this->tax ); |
|
1128 | - $data['total'] = wpinv_round_amount( $this->total ); |
|
1124 | + if (!$first_use_only) { |
|
1125 | + $data['subtotal'] = wpinv_round_amount($this->subtotal); |
|
1126 | + $data['discount'] = wpinv_round_amount($this->discount); |
|
1127 | + $data['tax'] = wpinv_round_amount($this->tax); |
|
1128 | + $data['total'] = wpinv_round_amount($this->total); |
|
1129 | 1129 | } else { |
1130 | 1130 | $cart_subtotal = 0; |
1131 | 1131 | $cart_discount = $this->discount; |
1132 | 1132 | $cart_tax = 0; |
1133 | 1133 | |
1134 | - foreach ( $this->cart_details as $key => $item ) { |
|
1135 | - $item_quantity = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
1136 | - $item_subtotal = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity; |
|
1134 | + foreach ($this->cart_details as $key => $item) { |
|
1135 | + $item_quantity = $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
1136 | + $item_subtotal = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity; |
|
1137 | 1137 | $item_discount = 0; |
1138 | - $item_tax = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0; |
|
1138 | + $item_tax = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float) $item['vat_rate']) : 0; |
|
1139 | 1139 | |
1140 | - if ( wpinv_prices_include_tax() ) { |
|
1141 | - $item_subtotal -= wpinv_round_amount( $item_tax ); |
|
1140 | + if (wpinv_prices_include_tax()) { |
|
1141 | + $item_subtotal -= wpinv_round_amount($item_tax); |
|
1142 | 1142 | } |
1143 | 1143 | |
1144 | 1144 | $item_total = $item_subtotal - $item_discount + $item_tax; |
1145 | 1145 | // Do not allow totals to go negative |
1146 | - if ( $item_total < 0 ) { |
|
1146 | + if ($item_total < 0) { |
|
1147 | 1147 | $item_total = 0; |
1148 | 1148 | } |
1149 | 1149 | |
1150 | - $cart_subtotal += (float)($item_subtotal); |
|
1151 | - $cart_discount += (float)($item_discount); |
|
1152 | - $cart_tax += (float)($item_tax); |
|
1150 | + $cart_subtotal += (float) ($item_subtotal); |
|
1151 | + $cart_discount += (float) ($item_discount); |
|
1152 | + $cart_tax += (float) ($item_tax); |
|
1153 | 1153 | |
1154 | - $data['cart_details'][$key]['discount'] = wpinv_round_amount( $item_discount ); |
|
1155 | - $data['cart_details'][$key]['tax'] = wpinv_round_amount( $item_tax ); |
|
1156 | - $data['cart_details'][$key]['price'] = wpinv_round_amount( $item_total ); |
|
1154 | + $data['cart_details'][$key]['discount'] = wpinv_round_amount($item_discount); |
|
1155 | + $data['cart_details'][$key]['tax'] = wpinv_round_amount($item_tax); |
|
1156 | + $data['cart_details'][$key]['price'] = wpinv_round_amount($item_total); |
|
1157 | 1157 | } |
1158 | 1158 | |
1159 | 1159 | $total = $data['subtotal'] - $data['discount'] + $data['tax']; |
1160 | - if ( $total < 0 ) { |
|
1160 | + if ($total < 0) { |
|
1161 | 1161 | $total = 0; |
1162 | 1162 | } |
1163 | 1163 | |
1164 | - $data['subtotal'] = wpinv_round_amount( $cart_subtotal ); |
|
1165 | - $data['discount'] = wpinv_round_amount( $cart_discount ); |
|
1166 | - $data['tax'] = wpinv_round_amount( $cart_tax ); |
|
1167 | - $data['total'] = wpinv_round_amount( $total ); |
|
1164 | + $data['subtotal'] = wpinv_round_amount($cart_subtotal); |
|
1165 | + $data['discount'] = wpinv_round_amount($cart_discount); |
|
1166 | + $data['tax'] = wpinv_round_amount($cart_tax); |
|
1167 | + $data['total'] = wpinv_round_amount($total); |
|
1168 | 1168 | } |
1169 | 1169 | } |
1170 | 1170 | } |
1171 | 1171 | |
1172 | - $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency ); |
|
1172 | + $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency); |
|
1173 | 1173 | |
1174 | - if ( isset( $data[$field] ) ) { |
|
1175 | - return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
|
1174 | + if (isset($data[$field])) { |
|
1175 | + return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]); |
|
1176 | 1176 | } |
1177 | 1177 | |
1178 | 1178 | return $data; |
1179 | 1179 | } |
1180 | 1180 | |
1181 | - public function get_final_tax( $currency = false ) { |
|
1182 | - $final_total = wpinv_round_amount( $this->tax ); |
|
1183 | - if ( $currency ) { |
|
1184 | - $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() ); |
|
1181 | + public function get_final_tax($currency = false) { |
|
1182 | + $final_total = wpinv_round_amount($this->tax); |
|
1183 | + if ($currency) { |
|
1184 | + $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency()); |
|
1185 | 1185 | } |
1186 | 1186 | |
1187 | - return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency ); |
|
1187 | + return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency); |
|
1188 | 1188 | } |
1189 | 1189 | |
1190 | - public function get_discounts( $array = false ) { |
|
1190 | + public function get_discounts($array = false) { |
|
1191 | 1191 | $discounts = $this->discounts; |
1192 | - if ( $array && $discounts ) { |
|
1193 | - $discounts = explode( ',', $discounts ); |
|
1192 | + if ($array && $discounts) { |
|
1193 | + $discounts = explode(',', $discounts); |
|
1194 | 1194 | } |
1195 | - return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array ); |
|
1195 | + return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array); |
|
1196 | 1196 | } |
1197 | 1197 | |
1198 | - public function get_discount( $currency = false, $dash = false ) { |
|
1199 | - if ( !empty( $this->discounts ) ) { |
|
1198 | + public function get_discount($currency = false, $dash = false) { |
|
1199 | + if (!empty($this->discounts)) { |
|
1200 | 1200 | global $ajax_cart_details; |
1201 | 1201 | $ajax_cart_details = $this->get_cart_details(); |
1202 | 1202 | |
1203 | - if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) { |
|
1203 | + if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) { |
|
1204 | 1204 | $cart_items = $ajax_cart_details; |
1205 | 1205 | } else { |
1206 | 1206 | $cart_items = $this->items; |
1207 | 1207 | } |
1208 | 1208 | |
1209 | - $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts ); |
|
1209 | + $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts); |
|
1210 | 1210 | } |
1211 | - $discount = wpinv_round_amount( $this->discount ); |
|
1211 | + $discount = wpinv_round_amount($this->discount); |
|
1212 | 1212 | $dash = $dash && $discount > 0 ? '–' : ''; |
1213 | 1213 | |
1214 | - if ( $currency ) { |
|
1215 | - $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() ); |
|
1214 | + if ($currency) { |
|
1215 | + $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency()); |
|
1216 | 1216 | } |
1217 | 1217 | |
1218 | - $discount = $dash . $discount; |
|
1218 | + $discount = $dash . $discount; |
|
1219 | 1219 | |
1220 | - return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash ); |
|
1220 | + return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash); |
|
1221 | 1221 | } |
1222 | 1222 | |
1223 | 1223 | public function get_discount_code() { |
@@ -1229,49 +1229,49 @@ discard block |
||
1229 | 1229 | return (int) $this->disable_taxes === 0; |
1230 | 1230 | } |
1231 | 1231 | |
1232 | - public function get_tax( $currency = false ) { |
|
1233 | - $tax = wpinv_round_amount( $this->tax ); |
|
1232 | + public function get_tax($currency = false) { |
|
1233 | + $tax = wpinv_round_amount($this->tax); |
|
1234 | 1234 | |
1235 | - if ( $currency ) { |
|
1236 | - $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() ); |
|
1235 | + if ($currency) { |
|
1236 | + $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency()); |
|
1237 | 1237 | } |
1238 | 1238 | |
1239 | - if ( ! $this->is_taxable() ) { |
|
1240 | - $tax = wpinv_round_amount( 0.00 ); |
|
1239 | + if (!$this->is_taxable()) { |
|
1240 | + $tax = wpinv_round_amount(0.00); |
|
1241 | 1241 | } |
1242 | 1242 | |
1243 | - return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency ); |
|
1243 | + return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency); |
|
1244 | 1244 | } |
1245 | 1245 | |
1246 | - public function get_fees( $type = 'all' ) { |
|
1247 | - $fees = array(); |
|
1246 | + public function get_fees($type = 'all') { |
|
1247 | + $fees = array(); |
|
1248 | 1248 | |
1249 | - if ( ! empty( $this->fees ) && is_array( $this->fees ) ) { |
|
1250 | - foreach ( $this->fees as $fee ) { |
|
1251 | - if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
1249 | + if (!empty($this->fees) && is_array($this->fees)) { |
|
1250 | + foreach ($this->fees as $fee) { |
|
1251 | + if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) { |
|
1252 | 1252 | continue; |
1253 | 1253 | } |
1254 | 1254 | |
1255 | - $fee['label'] = stripslashes( $fee['label'] ); |
|
1256 | - $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() ); |
|
1257 | - $fees[] = $fee; |
|
1255 | + $fee['label'] = stripslashes($fee['label']); |
|
1256 | + $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency()); |
|
1257 | + $fees[] = $fee; |
|
1258 | 1258 | } |
1259 | 1259 | } |
1260 | 1260 | |
1261 | - return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this ); |
|
1261 | + return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this); |
|
1262 | 1262 | } |
1263 | 1263 | |
1264 | - public function get_fees_total( $type = 'all' ) { |
|
1264 | + public function get_fees_total($type = 'all') { |
|
1265 | 1265 | $fees_total = (float) 0.00; |
1266 | 1266 | |
1267 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
1268 | - if ( ! empty( $payment_fees ) ) { |
|
1269 | - foreach ( $payment_fees as $fee ) { |
|
1267 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
1268 | + if (!empty($payment_fees)) { |
|
1269 | + foreach ($payment_fees as $fee) { |
|
1270 | 1270 | $fees_total += (float) $fee['amount']; |
1271 | 1271 | } |
1272 | 1272 | } |
1273 | 1273 | |
1274 | - return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this ); |
|
1274 | + return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this); |
|
1275 | 1275 | /* |
1276 | 1276 | $fees = $this->get_fees( $type ); |
1277 | 1277 | |
@@ -1291,116 +1291,116 @@ discard block |
||
1291 | 1291 | } |
1292 | 1292 | |
1293 | 1293 | public function get_user_id() { |
1294 | - return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this ); |
|
1294 | + return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this); |
|
1295 | 1295 | } |
1296 | 1296 | |
1297 | 1297 | public function get_first_name() { |
1298 | - return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this ); |
|
1298 | + return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this); |
|
1299 | 1299 | } |
1300 | 1300 | |
1301 | 1301 | public function get_last_name() { |
1302 | - return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this ); |
|
1302 | + return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this); |
|
1303 | 1303 | } |
1304 | 1304 | |
1305 | 1305 | public function get_user_full_name() { |
1306 | - return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this ); |
|
1306 | + return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this); |
|
1307 | 1307 | } |
1308 | 1308 | |
1309 | 1309 | public function get_user_info() { |
1310 | - return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this ); |
|
1310 | + return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this); |
|
1311 | 1311 | } |
1312 | 1312 | |
1313 | 1313 | public function get_email() { |
1314 | - return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this ); |
|
1314 | + return apply_filters('wpinv_user_email', $this->email, $this->ID, $this); |
|
1315 | 1315 | } |
1316 | 1316 | |
1317 | 1317 | public function get_address() { |
1318 | - return apply_filters( 'wpinv_address', $this->address, $this->ID, $this ); |
|
1318 | + return apply_filters('wpinv_address', $this->address, $this->ID, $this); |
|
1319 | 1319 | } |
1320 | 1320 | |
1321 | 1321 | public function get_phone() { |
1322 | - return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this ); |
|
1322 | + return apply_filters('wpinv_phone', $this->phone, $this->ID, $this); |
|
1323 | 1323 | } |
1324 | 1324 | |
1325 | 1325 | public function get_number() { |
1326 | - return apply_filters( 'wpinv_number', $this->number, $this->ID, $this ); |
|
1326 | + return apply_filters('wpinv_number', $this->number, $this->ID, $this); |
|
1327 | 1327 | } |
1328 | 1328 | |
1329 | 1329 | public function get_items() { |
1330 | - return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this ); |
|
1330 | + return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this); |
|
1331 | 1331 | } |
1332 | 1332 | |
1333 | 1333 | public function get_key() { |
1334 | - return apply_filters( 'wpinv_key', $this->key, $this->ID, $this ); |
|
1334 | + return apply_filters('wpinv_key', $this->key, $this->ID, $this); |
|
1335 | 1335 | } |
1336 | 1336 | |
1337 | 1337 | public function get_transaction_id() { |
1338 | - return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this ); |
|
1338 | + return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this); |
|
1339 | 1339 | } |
1340 | 1340 | |
1341 | 1341 | public function get_gateway() { |
1342 | - return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this ); |
|
1342 | + return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this); |
|
1343 | 1343 | } |
1344 | 1344 | |
1345 | 1345 | public function get_gateway_title() { |
1346 | - $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway ); |
|
1346 | + $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway); |
|
1347 | 1347 | |
1348 | - return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this ); |
|
1348 | + return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this); |
|
1349 | 1349 | } |
1350 | 1350 | |
1351 | 1351 | public function get_currency() { |
1352 | - return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this ); |
|
1352 | + return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this); |
|
1353 | 1353 | } |
1354 | 1354 | |
1355 | 1355 | public function get_created_date() { |
1356 | - return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this ); |
|
1356 | + return apply_filters('wpinv_created_date', $this->date, $this->ID, $this); |
|
1357 | 1357 | } |
1358 | 1358 | |
1359 | - public function get_due_date( $display = false ) { |
|
1360 | - $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this ); |
|
1359 | + public function get_due_date($display = false) { |
|
1360 | + $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this); |
|
1361 | 1361 | |
1362 | - if ( ! $display ) { |
|
1362 | + if (!$display) { |
|
1363 | 1363 | return $due_date; |
1364 | 1364 | } |
1365 | 1365 | |
1366 | - return getpaid_format_date( $this->due_date ); |
|
1366 | + return getpaid_format_date($this->due_date); |
|
1367 | 1367 | } |
1368 | 1368 | |
1369 | 1369 | public function get_completed_date() { |
1370 | - return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this ); |
|
1370 | + return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this); |
|
1371 | 1371 | } |
1372 | 1372 | |
1373 | - public function get_invoice_date( $formatted = true ) { |
|
1373 | + public function get_invoice_date($formatted = true) { |
|
1374 | 1374 | $date_completed = $this->completed_date; |
1375 | 1375 | $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
1376 | 1376 | |
1377 | - if ( $invoice_date == '' ) { |
|
1377 | + if ($invoice_date == '') { |
|
1378 | 1378 | $date_created = $this->date; |
1379 | 1379 | $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : ''; |
1380 | 1380 | } |
1381 | 1381 | |
1382 | - if ( $formatted && $invoice_date ) { |
|
1383 | - $invoice_date = getpaid_format_date( $invoice_date ); |
|
1382 | + if ($formatted && $invoice_date) { |
|
1383 | + $invoice_date = getpaid_format_date($invoice_date); |
|
1384 | 1384 | } |
1385 | 1385 | |
1386 | - return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this ); |
|
1386 | + return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this); |
|
1387 | 1387 | } |
1388 | 1388 | |
1389 | 1389 | public function get_ip() { |
1390 | - return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this ); |
|
1390 | + return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this); |
|
1391 | 1391 | } |
1392 | 1392 | |
1393 | - public function has_status( $status ) { |
|
1394 | - return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status ); |
|
1393 | + public function has_status($status) { |
|
1394 | + return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status); |
|
1395 | 1395 | } |
1396 | 1396 | |
1397 | - public function add_item( $item_id = 0, $args = array() ) { |
|
1397 | + public function add_item($item_id = 0, $args = array()) { |
|
1398 | 1398 | global $wpi_current_id, $wpi_item_id; |
1399 | 1399 | |
1400 | - $item = new WPInv_Item( $item_id ); |
|
1400 | + $item = new WPInv_Item($item_id); |
|
1401 | 1401 | |
1402 | 1402 | // Bail if this post isn't a item |
1403 | - if( !$item || $item->post_type !== 'wpi_item' ) { |
|
1403 | + if (!$item || $item->post_type !== 'wpi_item') { |
|
1404 | 1404 | return false; |
1405 | 1405 | } |
1406 | 1406 | |
@@ -1419,8 +1419,8 @@ discard block |
||
1419 | 1419 | 'fees' => array() |
1420 | 1420 | ); |
1421 | 1421 | |
1422 | - $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults ); |
|
1423 | - $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1; |
|
1422 | + $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults); |
|
1423 | + $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1; |
|
1424 | 1424 | |
1425 | 1425 | $wpi_current_id = $this->ID; |
1426 | 1426 | $wpi_item_id = $item->ID; |
@@ -1432,19 +1432,19 @@ discard block |
||
1432 | 1432 | $found_cart_key = false; |
1433 | 1433 | |
1434 | 1434 | if ($has_quantities) { |
1435 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
1435 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
1436 | 1436 | |
1437 | - foreach ( $this->items as $key => $cart_item ) { |
|
1438 | - if ( (int)$item_id !== (int)$cart_item['id'] ) { |
|
1437 | + foreach ($this->items as $key => $cart_item) { |
|
1438 | + if ((int) $item_id !== (int) $cart_item['id']) { |
|
1439 | 1439 | continue; |
1440 | 1440 | } |
1441 | 1441 | |
1442 | - $this->items[ $key ]['quantity'] += $args['quantity']; |
|
1442 | + $this->items[$key]['quantity'] += $args['quantity']; |
|
1443 | 1443 | break; |
1444 | 1444 | } |
1445 | 1445 | |
1446 | - foreach ( $this->cart_details as $cart_key => $cart_item ) { |
|
1447 | - if ( $item_id != $cart_item['id'] ) { |
|
1446 | + foreach ($this->cart_details as $cart_key => $cart_item) { |
|
1447 | + if ($item_id != $cart_item['id']) { |
|
1448 | 1448 | continue; |
1449 | 1449 | } |
1450 | 1450 | |
@@ -1456,29 +1456,29 @@ discard block |
||
1456 | 1456 | if ($has_quantities && $found_cart_key !== false) { |
1457 | 1457 | $cart_item = $this->cart_details[$found_cart_key]; |
1458 | 1458 | $item_price = $cart_item['item_price']; |
1459 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
1460 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
1459 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
1460 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
1461 | 1461 | |
1462 | 1462 | $new_quantity = $quantity + $args['quantity']; |
1463 | 1463 | $subtotal = $item_price * $new_quantity; |
1464 | 1464 | |
1465 | 1465 | $args['quantity'] = $new_quantity; |
1466 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
1467 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1466 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
1467 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
1468 | 1468 | |
1469 | - $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0; |
|
1470 | - $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0; |
|
1469 | + $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float) $cart_item['discount'] ? $discount - (float) $cart_item['discount'] : 0; |
|
1470 | + $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float) $cart_item['tax'] ? $tax - (float) $cart_item['tax'] : 0; |
|
1471 | 1471 | // The total increase equals the number removed * the item_price |
1472 | - $total_increased = wpinv_round_amount( $item_price ); |
|
1472 | + $total_increased = wpinv_round_amount($item_price); |
|
1473 | 1473 | |
1474 | - if ( wpinv_prices_include_tax() ) { |
|
1475 | - $subtotal -= wpinv_round_amount( $tax ); |
|
1474 | + if (wpinv_prices_include_tax()) { |
|
1475 | + $subtotal -= wpinv_round_amount($tax); |
|
1476 | 1476 | } |
1477 | 1477 | |
1478 | - $total = $subtotal - $discount + $tax; |
|
1478 | + $total = $subtotal - $discount + $tax; |
|
1479 | 1479 | |
1480 | 1480 | // Do not allow totals to go negative |
1481 | - if( $total < 0 ) { |
|
1481 | + if ($total < 0) { |
|
1482 | 1482 | $total = 0; |
1483 | 1483 | } |
1484 | 1484 | |
@@ -1494,25 +1494,25 @@ discard block |
||
1494 | 1494 | $this->cart_details[$found_cart_key] = $cart_item; |
1495 | 1495 | } else { |
1496 | 1496 | // Set custom price. |
1497 | - if ( $args['custom_price'] !== '' ) { |
|
1497 | + if ($args['custom_price'] !== '') { |
|
1498 | 1498 | $item_price = $args['custom_price']; |
1499 | 1499 | } else { |
1500 | 1500 | // Allow overriding the price |
1501 | - if ( false !== $args['item_price'] ) { |
|
1501 | + if (false !== $args['item_price']) { |
|
1502 | 1502 | $item_price = $args['item_price']; |
1503 | 1503 | } else { |
1504 | - $item_price = wpinv_get_item_price( $item->ID ); |
|
1504 | + $item_price = wpinv_get_item_price($item->ID); |
|
1505 | 1505 | } |
1506 | 1506 | } |
1507 | 1507 | |
1508 | 1508 | // Sanitizing the price here so we don't have a dozen calls later |
1509 | - $item_price = wpinv_sanitize_amount( $item_price ); |
|
1510 | - $subtotal = wpinv_round_amount( $item_price * $args['quantity'] ); |
|
1509 | + $item_price = wpinv_sanitize_amount($item_price); |
|
1510 | + $subtotal = wpinv_round_amount($item_price * $args['quantity']); |
|
1511 | 1511 | |
1512 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
1513 | - $tax_class = !empty( $args['vat_class'] ) ? $args['vat_class'] : ''; |
|
1514 | - $tax_rate = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0; |
|
1515 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1512 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
1513 | + $tax_class = !empty($args['vat_class']) ? $args['vat_class'] : ''; |
|
1514 | + $tax_rate = !empty($args['vat_rate']) ? $args['vat_rate'] : 0; |
|
1515 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
1516 | 1516 | |
1517 | 1517 | // Setup the items meta item |
1518 | 1518 | $new_item = array( |
@@ -1520,29 +1520,29 @@ discard block |
||
1520 | 1520 | 'quantity' => $args['quantity'], |
1521 | 1521 | ); |
1522 | 1522 | |
1523 | - $this->items[] = $new_item; |
|
1523 | + $this->items[] = $new_item; |
|
1524 | 1524 | |
1525 | - if ( wpinv_prices_include_tax() ) { |
|
1526 | - $subtotal -= wpinv_round_amount( $tax ); |
|
1525 | + if (wpinv_prices_include_tax()) { |
|
1526 | + $subtotal -= wpinv_round_amount($tax); |
|
1527 | 1527 | } |
1528 | 1528 | |
1529 | - $total = $subtotal - $discount + $tax; |
|
1529 | + $total = $subtotal - $discount + $tax; |
|
1530 | 1530 | |
1531 | 1531 | // Do not allow totals to go negative |
1532 | - if( $total < 0 ) { |
|
1532 | + if ($total < 0) { |
|
1533 | 1533 | $total = 0; |
1534 | 1534 | } |
1535 | 1535 | |
1536 | 1536 | $this->cart_details[] = array( |
1537 | 1537 | 'name' => !empty($args['name']) ? $args['name'] : $item->get_name(), |
1538 | 1538 | 'id' => $item->ID, |
1539 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
1540 | - 'custom_price' => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ), |
|
1539 | + 'item_price' => wpinv_round_amount($item_price), |
|
1540 | + 'custom_price' => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''), |
|
1541 | 1541 | 'quantity' => $args['quantity'], |
1542 | 1542 | 'discount' => $discount, |
1543 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
1544 | - 'tax' => wpinv_round_amount( $tax ), |
|
1545 | - 'price' => wpinv_round_amount( $total ), |
|
1543 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
1544 | + 'tax' => wpinv_round_amount($tax), |
|
1545 | + 'price' => wpinv_round_amount($total), |
|
1546 | 1546 | 'vat_rate' => $tax_rate, |
1547 | 1547 | 'vat_class' => $tax_class, |
1548 | 1548 | 'meta' => $args['meta'], |
@@ -1552,18 +1552,18 @@ discard block |
||
1552 | 1552 | $subtotal = $subtotal - $discount; |
1553 | 1553 | } |
1554 | 1554 | |
1555 | - $added_item = end( $this->cart_details ); |
|
1556 | - $added_item['action'] = 'add'; |
|
1555 | + $added_item = end($this->cart_details); |
|
1556 | + $added_item['action'] = 'add'; |
|
1557 | 1557 | |
1558 | 1558 | $this->pending['items'][] = $added_item; |
1559 | 1559 | |
1560 | - $this->increase_subtotal( $subtotal ); |
|
1561 | - $this->increase_tax( $tax ); |
|
1560 | + $this->increase_subtotal($subtotal); |
|
1561 | + $this->increase_tax($tax); |
|
1562 | 1562 | |
1563 | 1563 | return true; |
1564 | 1564 | } |
1565 | 1565 | |
1566 | - public function remove_item( $item_id, $args = array() ) { |
|
1566 | + public function remove_item($item_id, $args = array()) { |
|
1567 | 1567 | // Set some defaults |
1568 | 1568 | $defaults = array( |
1569 | 1569 | 'quantity' => 1, |
@@ -1571,51 +1571,51 @@ discard block |
||
1571 | 1571 | 'custom_price' => '', |
1572 | 1572 | 'cart_index' => false, |
1573 | 1573 | ); |
1574 | - $args = wp_parse_args( $args, $defaults ); |
|
1574 | + $args = wp_parse_args($args, $defaults); |
|
1575 | 1575 | |
1576 | 1576 | // Bail if this post isn't a item |
1577 | - if ( get_post_type( $item_id ) !== 'wpi_item' ) { |
|
1577 | + if (get_post_type($item_id) !== 'wpi_item') { |
|
1578 | 1578 | return false; |
1579 | 1579 | } |
1580 | 1580 | |
1581 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
1581 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
1582 | 1582 | |
1583 | - foreach ( $this->items as $key => $item ) { |
|
1584 | - if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) { |
|
1583 | + foreach ($this->items as $key => $item) { |
|
1584 | + if (!empty($item['id']) && (int) $item_id !== (int) $item['id']) { |
|
1585 | 1585 | continue; |
1586 | 1586 | } |
1587 | 1587 | |
1588 | - if ( false !== $args['cart_index'] ) { |
|
1589 | - $cart_index = absint( $args['cart_index'] ); |
|
1590 | - $cart_item = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false; |
|
1588 | + if (false !== $args['cart_index']) { |
|
1589 | + $cart_index = absint($args['cart_index']); |
|
1590 | + $cart_item = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false; |
|
1591 | 1591 | |
1592 | - if ( ! empty( $cart_item ) ) { |
|
1592 | + if (!empty($cart_item)) { |
|
1593 | 1593 | // If the cart index item isn't the same item ID, don't remove it |
1594 | - if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) { |
|
1594 | + if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) { |
|
1595 | 1595 | continue; |
1596 | 1596 | } |
1597 | 1597 | } |
1598 | 1598 | } |
1599 | 1599 | |
1600 | - $item_quantity = $this->items[ $key ]['quantity']; |
|
1601 | - if ( $item_quantity > $args['quantity'] ) { |
|
1602 | - $this->items[ $key ]['quantity'] -= $args['quantity']; |
|
1600 | + $item_quantity = $this->items[$key]['quantity']; |
|
1601 | + if ($item_quantity > $args['quantity']) { |
|
1602 | + $this->items[$key]['quantity'] -= $args['quantity']; |
|
1603 | 1603 | break; |
1604 | 1604 | } else { |
1605 | - unset( $this->items[ $key ] ); |
|
1605 | + unset($this->items[$key]); |
|
1606 | 1606 | break; |
1607 | 1607 | } |
1608 | 1608 | } |
1609 | 1609 | |
1610 | 1610 | $found_cart_key = false; |
1611 | - if ( false === $args['cart_index'] ) { |
|
1612 | - foreach ( $this->cart_details as $cart_key => $item ) { |
|
1613 | - if ( $item_id != $item['id'] ) { |
|
1611 | + if (false === $args['cart_index']) { |
|
1612 | + foreach ($this->cart_details as $cart_key => $item) { |
|
1613 | + if ($item_id != $item['id']) { |
|
1614 | 1614 | continue; |
1615 | 1615 | } |
1616 | 1616 | |
1617 | - if ( false !== $args['item_price'] ) { |
|
1618 | - if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) { |
|
1617 | + if (false !== $args['item_price']) { |
|
1618 | + if (isset($item['item_price']) && (float) $args['item_price'] != (float) $item['item_price']) { |
|
1619 | 1619 | continue; |
1620 | 1620 | } |
1621 | 1621 | } |
@@ -1624,13 +1624,13 @@ discard block |
||
1624 | 1624 | break; |
1625 | 1625 | } |
1626 | 1626 | } else { |
1627 | - $cart_index = absint( $args['cart_index'] ); |
|
1627 | + $cart_index = absint($args['cart_index']); |
|
1628 | 1628 | |
1629 | - if ( ! array_key_exists( $cart_index, $this->cart_details ) ) { |
|
1629 | + if (!array_key_exists($cart_index, $this->cart_details)) { |
|
1630 | 1630 | return false; // Invalid cart index passed. |
1631 | 1631 | } |
1632 | 1632 | |
1633 | - if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) { |
|
1633 | + if ((int) $this->cart_details[$cart_index]['id'] > 0 && (int) $this->cart_details[$cart_index]['id'] !== (int) $item_id) { |
|
1634 | 1634 | return false; // We still need the proper Item ID to be sure. |
1635 | 1635 | } |
1636 | 1636 | |
@@ -1638,41 +1638,41 @@ discard block |
||
1638 | 1638 | } |
1639 | 1639 | |
1640 | 1640 | $cart_item = $this->cart_details[$found_cart_key]; |
1641 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
1641 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
1642 | 1642 | |
1643 | - if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) { |
|
1643 | + if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) { |
|
1644 | 1644 | //return false; // Invoice must contain at least one item. |
1645 | 1645 | } |
1646 | 1646 | |
1647 | - $discounts = $this->get_discounts(); |
|
1647 | + $discounts = $this->get_discounts(); |
|
1648 | 1648 | |
1649 | - if ( $quantity > $args['quantity'] ) { |
|
1649 | + if ($quantity > $args['quantity']) { |
|
1650 | 1650 | $item_price = $cart_item['item_price']; |
1651 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
1651 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
1652 | 1652 | |
1653 | - $new_quantity = max( $quantity - $args['quantity'], 1); |
|
1653 | + $new_quantity = max($quantity - $args['quantity'], 1); |
|
1654 | 1654 | $subtotal = $item_price * $new_quantity; |
1655 | 1655 | |
1656 | 1656 | $args['quantity'] = $new_quantity; |
1657 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
1658 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1657 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
1658 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
1659 | 1659 | |
1660 | - $discount_decrease = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0; |
|
1661 | - $discount_decrease = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; |
|
1662 | - $tax_decrease = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0; |
|
1663 | - $tax_decrease = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease; |
|
1660 | + $discount_decrease = (float) $cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['discount'] / $quantity)) : 0; |
|
1661 | + $discount_decrease = $discount > 0 && $subtotal > 0 && (float) $cart_item['discount'] > $discount ? (float) $cart_item['discount'] - $discount : $discount_decrease; |
|
1662 | + $tax_decrease = (float) $cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['tax'] / $quantity)) : 0; |
|
1663 | + $tax_decrease = $tax > 0 && $subtotal > 0 && (float) $cart_item['tax'] > $tax ? (float) $cart_item['tax'] - $tax : $tax_decrease; |
|
1664 | 1664 | |
1665 | 1665 | // The total increase equals the number removed * the item_price |
1666 | - $total_decrease = wpinv_round_amount( $item_price ); |
|
1666 | + $total_decrease = wpinv_round_amount($item_price); |
|
1667 | 1667 | |
1668 | - if ( wpinv_prices_include_tax() ) { |
|
1669 | - $subtotal -= wpinv_round_amount( $tax ); |
|
1668 | + if (wpinv_prices_include_tax()) { |
|
1669 | + $subtotal -= wpinv_round_amount($tax); |
|
1670 | 1670 | } |
1671 | 1671 | |
1672 | - $total = $subtotal - $discount + $tax; |
|
1672 | + $total = $subtotal - $discount + $tax; |
|
1673 | 1673 | |
1674 | 1674 | // Do not allow totals to go negative |
1675 | - if( $total < 0 ) { |
|
1675 | + if ($total < 0) { |
|
1676 | 1676 | $total = 0; |
1677 | 1677 | } |
1678 | 1678 | |
@@ -1691,16 +1691,16 @@ discard block |
||
1691 | 1691 | |
1692 | 1692 | $this->cart_details[$found_cart_key] = $cart_item; |
1693 | 1693 | |
1694 | - $remove_item = end( $this->cart_details ); |
|
1694 | + $remove_item = end($this->cart_details); |
|
1695 | 1695 | } else { |
1696 | 1696 | $item_price = $cart_item['item_price']; |
1697 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
1698 | - $tax = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0; |
|
1697 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
1698 | + $tax = !empty($cart_item['tax']) ? $cart_item['tax'] : 0; |
|
1699 | 1699 | |
1700 | - $subtotal_decrease = ( $item_price * $quantity ) - $discount; |
|
1700 | + $subtotal_decrease = ($item_price * $quantity) - $discount; |
|
1701 | 1701 | $tax_decrease = $tax; |
1702 | 1702 | |
1703 | - unset( $this->cart_details[$found_cart_key] ); |
|
1703 | + unset($this->cart_details[$found_cart_key]); |
|
1704 | 1704 | |
1705 | 1705 | $remove_item = $args; |
1706 | 1706 | $remove_item['id'] = $item_id; |
@@ -1711,8 +1711,8 @@ discard block |
||
1711 | 1711 | $remove_item['action'] = 'remove'; |
1712 | 1712 | $this->pending['items'][] = $remove_item; |
1713 | 1713 | |
1714 | - $this->decrease_subtotal( $subtotal_decrease ); |
|
1715 | - $this->decrease_tax( $tax_decrease ); |
|
1714 | + $this->decrease_subtotal($subtotal_decrease); |
|
1715 | + $this->decrease_tax($tax_decrease); |
|
1716 | 1716 | |
1717 | 1717 | return true; |
1718 | 1718 | } |
@@ -1720,7 +1720,7 @@ discard block |
||
1720 | 1720 | public function update_items($temp = false) { |
1721 | 1721 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave; |
1722 | 1722 | |
1723 | - if ( !empty( $this->cart_details ) ) { |
|
1723 | + if (!empty($this->cart_details)) { |
|
1724 | 1724 | $wpi_nosave = $temp; |
1725 | 1725 | $cart_subtotal = 0; |
1726 | 1726 | $cart_discount = 0; |
@@ -1730,65 +1730,65 @@ discard block |
||
1730 | 1730 | $_POST['wpinv_country'] = $this->country; |
1731 | 1731 | $_POST['wpinv_state'] = $this->state; |
1732 | 1732 | |
1733 | - foreach ( $this->cart_details as $key => $item ) { |
|
1733 | + foreach ($this->cart_details as $key => $item) { |
|
1734 | 1734 | $item_price = $item['item_price']; |
1735 | - $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
1736 | - $amount = wpinv_round_amount( $item_price * $quantity ); |
|
1735 | + $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
1736 | + $amount = wpinv_round_amount($item_price * $quantity); |
|
1737 | 1737 | $subtotal = $item_price * $quantity; |
1738 | 1738 | |
1739 | 1739 | $wpi_current_id = $this->ID; |
1740 | 1740 | $wpi_item_id = $item['id']; |
1741 | 1741 | |
1742 | - $discount = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() ); |
|
1742 | + $discount = wpinv_get_cart_item_discount_amount($item, $this->get_discounts()); |
|
1743 | 1743 | |
1744 | - $tax_rate = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id ); |
|
1745 | - $tax_class = $wpinv_euvat->get_item_class( $wpi_item_id ); |
|
1746 | - $tax = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1744 | + $tax_rate = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id); |
|
1745 | + $tax_class = $wpinv_euvat->get_item_class($wpi_item_id); |
|
1746 | + $tax = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
1747 | 1747 | |
1748 | - if ( ! $this->is_taxable() ) { |
|
1748 | + if (!$this->is_taxable()) { |
|
1749 | 1749 | $tax = 0; |
1750 | 1750 | } |
1751 | 1751 | |
1752 | - if ( wpinv_prices_include_tax() ) { |
|
1753 | - $subtotal -= wpinv_round_amount( $tax ); |
|
1752 | + if (wpinv_prices_include_tax()) { |
|
1753 | + $subtotal -= wpinv_round_amount($tax); |
|
1754 | 1754 | } |
1755 | 1755 | |
1756 | - $total = $subtotal - $discount + $tax; |
|
1756 | + $total = $subtotal - $discount + $tax; |
|
1757 | 1757 | |
1758 | 1758 | // Do not allow totals to go negative |
1759 | - if( $total < 0 ) { |
|
1759 | + if ($total < 0) { |
|
1760 | 1760 | $total = 0; |
1761 | 1761 | } |
1762 | 1762 | |
1763 | 1763 | $cart_details[] = array( |
1764 | 1764 | 'id' => $item['id'], |
1765 | 1765 | 'name' => $item['name'], |
1766 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
1767 | - 'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ), |
|
1766 | + 'item_price' => wpinv_round_amount($item_price), |
|
1767 | + 'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''), |
|
1768 | 1768 | 'quantity' => $quantity, |
1769 | 1769 | 'discount' => $discount, |
1770 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
1771 | - 'tax' => wpinv_round_amount( $tax ), |
|
1772 | - 'price' => wpinv_round_amount( $total ), |
|
1770 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
1771 | + 'tax' => wpinv_round_amount($tax), |
|
1772 | + 'price' => wpinv_round_amount($total), |
|
1773 | 1773 | 'vat_rate' => $tax_rate, |
1774 | 1774 | 'vat_class' => $tax_class, |
1775 | 1775 | 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
1776 | 1776 | 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
1777 | 1777 | ); |
1778 | 1778 | |
1779 | - $cart_subtotal += (float)($subtotal - $discount); // TODO |
|
1780 | - $cart_discount += (float)($discount); |
|
1781 | - $cart_tax += (float)($tax); |
|
1779 | + $cart_subtotal += (float) ($subtotal - $discount); // TODO |
|
1780 | + $cart_discount += (float) ($discount); |
|
1781 | + $cart_tax += (float) ($tax); |
|
1782 | 1782 | } |
1783 | - if ( $cart_subtotal < 0 ) { |
|
1783 | + if ($cart_subtotal < 0) { |
|
1784 | 1784 | $cart_subtotal = 0; |
1785 | 1785 | } |
1786 | - if ( $cart_tax < 0 ) { |
|
1786 | + if ($cart_tax < 0) { |
|
1787 | 1787 | $cart_tax = 0; |
1788 | 1788 | } |
1789 | - $this->subtotal = wpinv_round_amount( $cart_subtotal ); |
|
1790 | - $this->tax = wpinv_round_amount( $cart_tax ); |
|
1791 | - $this->discount = wpinv_round_amount( $cart_discount ); |
|
1789 | + $this->subtotal = wpinv_round_amount($cart_subtotal); |
|
1790 | + $this->tax = wpinv_round_amount($cart_tax); |
|
1791 | + $this->discount = wpinv_round_amount($cart_discount); |
|
1792 | 1792 | |
1793 | 1793 | $this->recalculate_total(); |
1794 | 1794 | |
@@ -1800,177 +1800,177 @@ discard block |
||
1800 | 1800 | |
1801 | 1801 | public function recalculate_totals($temp = false) { |
1802 | 1802 | $this->update_items($temp); |
1803 | - $this->save( true ); |
|
1803 | + $this->save(true); |
|
1804 | 1804 | |
1805 | 1805 | return $this; |
1806 | 1806 | } |
1807 | 1807 | |
1808 | 1808 | public function needs_payment() { |
1809 | - $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'wpi-pending' ), $this ); |
|
1809 | + $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('wpi-pending'), $this); |
|
1810 | 1810 | |
1811 | - if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free() ) ) { |
|
1811 | + if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free())) { |
|
1812 | 1812 | $needs_payment = true; |
1813 | 1813 | } else { |
1814 | 1814 | $needs_payment = false; |
1815 | 1815 | } |
1816 | 1816 | |
1817 | - return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses ); |
|
1817 | + return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses); |
|
1818 | 1818 | } |
1819 | 1819 | |
1820 | - public function get_checkout_payment_url( $with_key = false, $secret = false ) { |
|
1820 | + public function get_checkout_payment_url($with_key = false, $secret = false) { |
|
1821 | 1821 | $pay_url = wpinv_get_checkout_uri(); |
1822 | 1822 | |
1823 | - if ( is_ssl() ) { |
|
1824 | - $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
|
1823 | + if (is_ssl()) { |
|
1824 | + $pay_url = str_replace('http:', 'https:', $pay_url); |
|
1825 | 1825 | } |
1826 | 1826 | |
1827 | 1827 | $key = $this->get_key(); |
1828 | 1828 | |
1829 | - if ( $with_key ) { |
|
1830 | - $pay_url = add_query_arg( 'invoice_key', $key, $pay_url ); |
|
1829 | + if ($with_key) { |
|
1830 | + $pay_url = add_query_arg('invoice_key', $key, $pay_url); |
|
1831 | 1831 | } else { |
1832 | - $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url ); |
|
1832 | + $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url); |
|
1833 | 1833 | } |
1834 | 1834 | |
1835 | - if ( $secret ) { |
|
1836 | - $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url ); |
|
1835 | + if ($secret) { |
|
1836 | + $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url); |
|
1837 | 1837 | } |
1838 | 1838 | |
1839 | - return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret ); |
|
1839 | + return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret); |
|
1840 | 1840 | } |
1841 | 1841 | |
1842 | - public function get_view_url( $with_key = false ) { |
|
1843 | - $invoice_url = get_permalink( $this->ID ); |
|
1842 | + public function get_view_url($with_key = false) { |
|
1843 | + $invoice_url = get_permalink($this->ID); |
|
1844 | 1844 | |
1845 | - if ( $with_key ) { |
|
1846 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
1845 | + if ($with_key) { |
|
1846 | + $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url); |
|
1847 | 1847 | } |
1848 | 1848 | |
1849 | - return apply_filters( 'wpinv_get_view_url', $invoice_url, $this, $with_key ); |
|
1849 | + return apply_filters('wpinv_get_view_url', $invoice_url, $this, $with_key); |
|
1850 | 1850 | } |
1851 | 1851 | |
1852 | - public function generate_key( $string = '' ) { |
|
1853 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1854 | - return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) ); // Unique key |
|
1852 | + public function generate_key($string = '') { |
|
1853 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1854 | + return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key |
|
1855 | 1855 | } |
1856 | 1856 | |
1857 | 1857 | public function is_recurring() { |
1858 | - if ( empty( $this->cart_details ) ) { |
|
1858 | + if (empty($this->cart_details)) { |
|
1859 | 1859 | return false; |
1860 | 1860 | } |
1861 | 1861 | |
1862 | 1862 | $has_subscription = false; |
1863 | - foreach( $this->cart_details as $cart_item ) { |
|
1864 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
1863 | + foreach ($this->cart_details as $cart_item) { |
|
1864 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
1865 | 1865 | $has_subscription = true; |
1866 | 1866 | break; |
1867 | 1867 | } |
1868 | 1868 | } |
1869 | 1869 | |
1870 | - if ( count( $this->cart_details ) > 1 ) { |
|
1870 | + if (count($this->cart_details) > 1) { |
|
1871 | 1871 | $has_subscription = false; |
1872 | 1872 | } |
1873 | 1873 | |
1874 | - return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details ); |
|
1874 | + return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details); |
|
1875 | 1875 | } |
1876 | 1876 | |
1877 | 1877 | public function is_free_trial() { |
1878 | 1878 | $is_free_trial = false; |
1879 | 1879 | |
1880 | - if ( $this->is_parent() && $item = $this->get_recurring( true ) ) { |
|
1881 | - if ( !empty( $item ) && $item->has_free_trial() ) { |
|
1880 | + if ($this->is_parent() && $item = $this->get_recurring(true)) { |
|
1881 | + if (!empty($item) && $item->has_free_trial()) { |
|
1882 | 1882 | $is_free_trial = true; |
1883 | 1883 | } |
1884 | 1884 | } |
1885 | 1885 | |
1886 | - return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this ); |
|
1886 | + return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this); |
|
1887 | 1887 | } |
1888 | 1888 | |
1889 | 1889 | public function is_initial_free() { |
1890 | 1890 | $is_initial_free = false; |
1891 | 1891 | |
1892 | - if ( ! ( (float)wpinv_round_amount( $this->get_total() ) > 0 ) && $this->is_parent() && $this->is_recurring() && ! $this->is_free_trial() && ! $this->is_free() ) { |
|
1892 | + if (!((float) wpinv_round_amount($this->get_total()) > 0) && $this->is_parent() && $this->is_recurring() && !$this->is_free_trial() && !$this->is_free()) { |
|
1893 | 1893 | $is_initial_free = true; |
1894 | 1894 | } |
1895 | 1895 | |
1896 | - return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details ); |
|
1896 | + return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details); |
|
1897 | 1897 | } |
1898 | 1898 | |
1899 | - public function get_recurring( $object = false ) { |
|
1899 | + public function get_recurring($object = false) { |
|
1900 | 1900 | $item = NULL; |
1901 | 1901 | |
1902 | - if ( empty( $this->cart_details ) ) { |
|
1902 | + if (empty($this->cart_details)) { |
|
1903 | 1903 | return $item; |
1904 | 1904 | } |
1905 | 1905 | |
1906 | - foreach( $this->cart_details as $cart_item ) { |
|
1907 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
1906 | + foreach ($this->cart_details as $cart_item) { |
|
1907 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
1908 | 1908 | $item = $cart_item['id']; |
1909 | 1909 | break; |
1910 | 1910 | } |
1911 | 1911 | } |
1912 | 1912 | |
1913 | - if ( $object ) { |
|
1914 | - $item = $item ? new WPInv_Item( $item ) : NULL; |
|
1913 | + if ($object) { |
|
1914 | + $item = $item ? new WPInv_Item($item) : NULL; |
|
1915 | 1915 | |
1916 | - apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this ); |
|
1916 | + apply_filters('wpinv_invoice_get_recurring_item', $item, $this); |
|
1917 | 1917 | } |
1918 | 1918 | |
1919 | - return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this ); |
|
1919 | + return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this); |
|
1920 | 1920 | } |
1921 | 1921 | |
1922 | 1922 | public function get_subscription_name() { |
1923 | - $item = $this->get_recurring( true ); |
|
1923 | + $item = $this->get_recurring(true); |
|
1924 | 1924 | |
1925 | - if ( empty( $item ) ) { |
|
1925 | + if (empty($item)) { |
|
1926 | 1926 | return NULL; |
1927 | 1927 | } |
1928 | 1928 | |
1929 | - if ( !($name = $item->get_name()) ) { |
|
1929 | + if (!($name = $item->get_name())) { |
|
1930 | 1930 | $name = $item->post_name; |
1931 | 1931 | } |
1932 | 1932 | |
1933 | - return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this ); |
|
1933 | + return apply_filters('wpinv_invoice_get_subscription_name', $name, $this); |
|
1934 | 1934 | } |
1935 | 1935 | |
1936 | 1936 | public function get_subscription_id() { |
1937 | - $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true ); |
|
1937 | + $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true); |
|
1938 | 1938 | |
1939 | - if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) { |
|
1940 | - $parent_invoice = wpinv_get_invoice( $this->parent_invoice ); |
|
1939 | + if (empty($subscription_id) && !empty($this->parent_invoice)) { |
|
1940 | + $parent_invoice = wpinv_get_invoice($this->parent_invoice); |
|
1941 | 1941 | |
1942 | - $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true ); |
|
1942 | + $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true); |
|
1943 | 1943 | } |
1944 | 1944 | |
1945 | 1945 | return $subscription_id; |
1946 | 1946 | } |
1947 | 1947 | |
1948 | 1948 | public function is_parent() { |
1949 | - $is_parent = empty( $this->parent_invoice ) ? true : false; |
|
1949 | + $is_parent = empty($this->parent_invoice) ? true : false; |
|
1950 | 1950 | |
1951 | - return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this ); |
|
1951 | + return apply_filters('wpinv_invoice_is_parent', $is_parent, $this); |
|
1952 | 1952 | } |
1953 | 1953 | |
1954 | 1954 | public function is_renewal() { |
1955 | 1955 | $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false; |
1956 | 1956 | |
1957 | - return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this ); |
|
1957 | + return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this); |
|
1958 | 1958 | } |
1959 | 1959 | |
1960 | 1960 | public function get_parent_payment() { |
1961 | 1961 | $parent_payment = NULL; |
1962 | 1962 | |
1963 | - if ( $this->is_renewal() ) { |
|
1964 | - $parent_payment = wpinv_get_invoice( $this->parent_invoice ); |
|
1963 | + if ($this->is_renewal()) { |
|
1964 | + $parent_payment = wpinv_get_invoice($this->parent_invoice); |
|
1965 | 1965 | } |
1966 | 1966 | |
1967 | 1967 | return $parent_payment; |
1968 | 1968 | } |
1969 | 1969 | |
1970 | 1970 | public function is_paid() { |
1971 | - $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
|
1971 | + $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal')); |
|
1972 | 1972 | |
1973 | - return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
|
1973 | + return apply_filters('wpinv_invoice_is_paid', $is_paid, $this); |
|
1974 | 1974 | } |
1975 | 1975 | |
1976 | 1976 | /** |
@@ -1983,23 +1983,23 @@ discard block |
||
1983 | 1983 | } |
1984 | 1984 | |
1985 | 1985 | public function is_refunded() { |
1986 | - $is_refunded = $this->has_status( array( 'wpi-refunded' ) ); |
|
1986 | + $is_refunded = $this->has_status(array('wpi-refunded')); |
|
1987 | 1987 | |
1988 | - return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
|
1988 | + return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this); |
|
1989 | 1989 | } |
1990 | 1990 | |
1991 | 1991 | public function is_free() { |
1992 | 1992 | $is_free = false; |
1993 | 1993 | |
1994 | - if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) { |
|
1995 | - if ( $this->is_parent() && $this->is_recurring() ) { |
|
1996 | - $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true; |
|
1994 | + if (!((float) wpinv_round_amount($this->get_total()) > 0)) { |
|
1995 | + if ($this->is_parent() && $this->is_recurring()) { |
|
1996 | + $is_free = (float) wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true; |
|
1997 | 1997 | } else { |
1998 | 1998 | $is_free = true; |
1999 | 1999 | } |
2000 | 2000 | } |
2001 | 2001 | |
2002 | - return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
|
2002 | + return apply_filters('wpinv_invoice_is_free', $is_free, $this); |
|
2003 | 2003 | } |
2004 | 2004 | |
2005 | 2005 | public function has_vat() { |
@@ -2007,41 +2007,41 @@ discard block |
||
2007 | 2007 | |
2008 | 2008 | $requires_vat = false; |
2009 | 2009 | |
2010 | - if ( $this->country ) { |
|
2010 | + if ($this->country) { |
|
2011 | 2011 | $wpi_country = $this->country; |
2012 | 2012 | |
2013 | - $requires_vat = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) ); |
|
2013 | + $requires_vat = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this)); |
|
2014 | 2014 | } |
2015 | 2015 | |
2016 | - return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this ); |
|
2016 | + return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this); |
|
2017 | 2017 | } |
2018 | 2018 | |
2019 | 2019 | public function refresh_item_ids() { |
2020 | 2020 | $item_ids = array(); |
2021 | 2021 | |
2022 | - if ( !empty( $this->cart_details ) ) { |
|
2023 | - foreach ( $this->cart_details as $key => $item ) { |
|
2024 | - if ( !empty( $item['id'] ) ) { |
|
2022 | + if (!empty($this->cart_details)) { |
|
2023 | + foreach ($this->cart_details as $key => $item) { |
|
2024 | + if (!empty($item['id'])) { |
|
2025 | 2025 | $item_ids[] = $item['id']; |
2026 | 2026 | } |
2027 | 2027 | } |
2028 | 2028 | } |
2029 | 2029 | |
2030 | - $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : ''; |
|
2030 | + $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : ''; |
|
2031 | 2031 | |
2032 | - update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids ); |
|
2032 | + update_post_meta($this->ID, '_wpinv_item_ids', $item_ids); |
|
2033 | 2033 | } |
2034 | 2034 | |
2035 | - public function get_invoice_quote_type( $post_id ) { |
|
2036 | - if ( empty( $post_id ) ) { |
|
2035 | + public function get_invoice_quote_type($post_id) { |
|
2036 | + if (empty($post_id)) { |
|
2037 | 2037 | return ''; |
2038 | 2038 | } |
2039 | 2039 | |
2040 | - $type = get_post_type( $post_id ); |
|
2040 | + $type = get_post_type($post_id); |
|
2041 | 2041 | |
2042 | - if ( 'wpi_invoice' === $type ) { |
|
2042 | + if ('wpi_invoice' === $type) { |
|
2043 | 2043 | $post_type = __('Invoice', 'invoicing'); |
2044 | - } else{ |
|
2044 | + } else { |
|
2045 | 2045 | $post_type = __('Quote', 'invoicing'); |
2046 | 2046 | } |
2047 | 2047 |
@@ -4,99 +4,99 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Displays an invoice. |
11 | 11 | * |
12 | 12 | * @param WPInv_Invoice $invoice. |
13 | 13 | */ |
14 | -function getpaid_invoice( $invoice ) { |
|
15 | - if ( ! empty( $invoice ) ) { |
|
16 | - wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) ); |
|
14 | +function getpaid_invoice($invoice) { |
|
15 | + if (!empty($invoice)) { |
|
16 | + wpinv_get_template('invoice/invoice.php', compact('invoice')); |
|
17 | 17 | } |
18 | 18 | } |
19 | -add_action( 'getpaid_invoice', 'getpaid_invoice', 10 ); |
|
19 | +add_action('getpaid_invoice', 'getpaid_invoice', 10); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Displays the invoice footer. |
23 | 23 | */ |
24 | -function getpaid_invoice_footer( $invoice ) { |
|
25 | - if ( ! empty( $invoice ) ) { |
|
26 | - wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) ); |
|
24 | +function getpaid_invoice_footer($invoice) { |
|
25 | + if (!empty($invoice)) { |
|
26 | + wpinv_get_template('invoice/footer.php', compact('invoice')); |
|
27 | 27 | } |
28 | 28 | } |
29 | -add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 ); |
|
29 | +add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Displays the invoice top bar. |
33 | 33 | */ |
34 | -function getpaid_invoice_header( $invoice ) { |
|
35 | - if ( ! empty( $invoice ) ) { |
|
36 | - wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) ); |
|
34 | +function getpaid_invoice_header($invoice) { |
|
35 | + if (!empty($invoice)) { |
|
36 | + wpinv_get_template('invoice/header.php', compact('invoice')); |
|
37 | 37 | } |
38 | 38 | } |
39 | -add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 ); |
|
39 | +add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10); |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Displays actions on the left side of the header. |
43 | 43 | */ |
44 | -function getpaid_invoice_header_left_actions( $invoice ) { |
|
45 | - if ( ! empty( $invoice ) ) { |
|
46 | - wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) ); |
|
44 | +function getpaid_invoice_header_left_actions($invoice) { |
|
45 | + if (!empty($invoice)) { |
|
46 | + wpinv_get_template('invoice/header-left-actions.php', compact('invoice')); |
|
47 | 47 | } |
48 | 48 | } |
49 | -add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 ); |
|
49 | +add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10); |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Displays actions on the right side of the invoice top bar. |
53 | 53 | */ |
54 | -function getpaid_invoice_header_right_actions( $invoice ) { |
|
55 | - if ( ! empty( $invoice ) ) { |
|
56 | - wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) ); |
|
54 | +function getpaid_invoice_header_right_actions($invoice) { |
|
55 | + if (!empty($invoice)) { |
|
56 | + wpinv_get_template('invoice/header-right-actions.php', compact('invoice')); |
|
57 | 57 | } |
58 | 58 | } |
59 | -add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 ); |
|
59 | +add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10); |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * Displays the invoice title, watermark, logo etc. |
63 | 63 | */ |
64 | -function getpaid_invoice_details_top( $invoice ) { |
|
65 | - if ( ! empty( $invoice ) ) { |
|
66 | - wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) ); |
|
64 | +function getpaid_invoice_details_top($invoice) { |
|
65 | + if (!empty($invoice)) { |
|
66 | + wpinv_get_template('invoice/details-top.php', compact('invoice')); |
|
67 | 67 | } |
68 | 68 | } |
69 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 ); |
|
69 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Displays the company logo. |
73 | 73 | */ |
74 | -function getpaid_invoice_logo( $invoice ) { |
|
75 | - if ( ! empty( $invoice ) ) { |
|
76 | - wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) ); |
|
74 | +function getpaid_invoice_logo($invoice) { |
|
75 | + if (!empty($invoice)) { |
|
76 | + wpinv_get_template('invoice/invoice-logo.php', compact('invoice')); |
|
77 | 77 | } |
78 | 78 | } |
79 | -add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' ); |
|
79 | +add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo'); |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Displays the type of invoice. |
83 | 83 | */ |
84 | -function getpaid_invoice_type( $invoice ) { |
|
85 | - if ( ! empty( $invoice ) ) { |
|
86 | - wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) ); |
|
84 | +function getpaid_invoice_type($invoice) { |
|
85 | + if (!empty($invoice)) { |
|
86 | + wpinv_get_template('invoice/invoice-type.php', compact('invoice')); |
|
87 | 87 | } |
88 | 88 | } |
89 | -add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' ); |
|
89 | +add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type'); |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Displays the invoice details. |
93 | 93 | */ |
94 | -function getpaid_invoice_details_main( $invoice ) { |
|
95 | - if ( ! empty( $invoice ) ) { |
|
96 | - wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) ); |
|
94 | +function getpaid_invoice_details_main($invoice) { |
|
95 | + if (!empty($invoice)) { |
|
96 | + wpinv_get_template('invoice/details.php', compact('invoice')); |
|
97 | 97 | } |
98 | 98 | } |
99 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 ); |
|
99 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50); |
|
100 | 100 | |
101 | 101 | /** |
102 | 102 | * Returns a path to the templates directory. |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
126 | 126 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
127 | 127 | */ |
128 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
129 | - return getpaid_template()->display_template( $template_name, $args, $template_path, $default_path ); |
|
128 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
129 | + return getpaid_template()->display_template($template_name, $args, $template_path, $default_path); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
142 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
143 | + return getpaid_template()->get_template($template_name, $args, $template_path, $default_path); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return string |
150 | 150 | */ |
151 | 151 | function wpinv_template_path() { |
152 | - return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() ); |
|
152 | + return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name()); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing')); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -170,56 +170,56 @@ discard block |
||
170 | 170 | * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'. |
171 | 171 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
172 | 172 | */ |
173 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
174 | - return getpaid_template()->locate_template( $template_name, $template_path, $default_path ); |
|
173 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
174 | + return getpaid_template()->locate_template($template_name, $template_path, $default_path); |
|
175 | 175 | } |
176 | 176 | |
177 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
177 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
178 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
179 | 179 | |
180 | 180 | // Setup possible parts |
181 | 181 | $templates = array(); |
182 | - if ( isset( $name ) ) |
|
182 | + if (isset($name)) |
|
183 | 183 | $templates[] = $slug . '-' . $name . '.php'; |
184 | 184 | $templates[] = $slug . '.php'; |
185 | 185 | |
186 | 186 | // Allow template parts to be filtered |
187 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
187 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
188 | 188 | |
189 | 189 | // Return the part that is found |
190 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
190 | + return wpinv_locate_tmpl($templates, $load, false); |
|
191 | 191 | } |
192 | 192 | |
193 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
193 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
194 | 194 | // No file found yet |
195 | 195 | $located = false; |
196 | 196 | |
197 | 197 | // Try to find a template file |
198 | - foreach ( (array)$template_names as $template_name ) { |
|
198 | + foreach ((array) $template_names as $template_name) { |
|
199 | 199 | |
200 | 200 | // Continue if template is empty |
201 | - if ( empty( $template_name ) ) |
|
201 | + if (empty($template_name)) |
|
202 | 202 | continue; |
203 | 203 | |
204 | 204 | // Trim off any slashes from the template name |
205 | - $template_name = ltrim( $template_name, '/' ); |
|
205 | + $template_name = ltrim($template_name, '/'); |
|
206 | 206 | |
207 | 207 | // try locating this template file by looping through the template paths |
208 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
208 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
209 | 209 | |
210 | - if( file_exists( $template_path . $template_name ) ) { |
|
210 | + if (file_exists($template_path . $template_name)) { |
|
211 | 211 | $located = $template_path . $template_name; |
212 | 212 | break; |
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
216 | - if( !empty( $located ) ) { |
|
216 | + if (!empty($located)) { |
|
217 | 217 | break; |
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
221 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
222 | - load_template( $located, $require_once ); |
|
221 | + if ((true == $load) && !empty($located)) |
|
222 | + load_template($located, $require_once); |
|
223 | 223 | |
224 | 224 | return $located; |
225 | 225 | } |
@@ -228,127 +228,127 @@ discard block |
||
228 | 228 | $template_dir = wpinv_get_theme_template_dir_name(); |
229 | 229 | |
230 | 230 | $file_paths = array( |
231 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
232 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
231 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
232 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
233 | 233 | 100 => wpinv_get_templates_dir() |
234 | 234 | ); |
235 | 235 | |
236 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
236 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
237 | 237 | |
238 | 238 | // sort the file paths based on priority |
239 | - ksort( $file_paths, SORT_NUMERIC ); |
|
239 | + ksort($file_paths, SORT_NUMERIC); |
|
240 | 240 | |
241 | - return array_map( 'trailingslashit', $file_paths ); |
|
241 | + return array_map('trailingslashit', $file_paths); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | function wpinv_checkout_meta_tags() { |
245 | 245 | |
246 | 246 | $pages = array(); |
247 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
248 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
249 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
250 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
247 | + $pages[] = wpinv_get_option('success_page'); |
|
248 | + $pages[] = wpinv_get_option('failure_page'); |
|
249 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
250 | + $pages[] = wpinv_get_option('invoice_subscription_page'); |
|
251 | 251 | |
252 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
252 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
253 | 253 | return; |
254 | 254 | } |
255 | 255 | |
256 | 256 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
257 | 257 | } |
258 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
258 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
259 | 259 | |
260 | -function wpinv_add_body_classes( $class ) { |
|
261 | - $classes = (array)$class; |
|
260 | +function wpinv_add_body_classes($class) { |
|
261 | + $classes = (array) $class; |
|
262 | 262 | |
263 | - if( wpinv_is_checkout() ) { |
|
263 | + if (wpinv_is_checkout()) { |
|
264 | 264 | $classes[] = 'wpinv-checkout'; |
265 | 265 | $classes[] = 'wpinv-page'; |
266 | 266 | } |
267 | 267 | |
268 | - if( wpinv_is_success_page() ) { |
|
268 | + if (wpinv_is_success_page()) { |
|
269 | 269 | $classes[] = 'wpinv-success'; |
270 | 270 | $classes[] = 'wpinv-page'; |
271 | 271 | } |
272 | 272 | |
273 | - if( wpinv_is_failed_transaction_page() ) { |
|
273 | + if (wpinv_is_failed_transaction_page()) { |
|
274 | 274 | $classes[] = 'wpinv-failed-transaction'; |
275 | 275 | $classes[] = 'wpinv-page'; |
276 | 276 | } |
277 | 277 | |
278 | - if( wpinv_is_invoice_history_page() ) { |
|
278 | + if (wpinv_is_invoice_history_page()) { |
|
279 | 279 | $classes[] = 'wpinv-history'; |
280 | 280 | $classes[] = 'wpinv-page'; |
281 | 281 | } |
282 | 282 | |
283 | - if( wpinv_is_subscriptions_history_page() ) { |
|
283 | + if (wpinv_is_subscriptions_history_page()) { |
|
284 | 284 | $classes[] = 'wpinv-subscription'; |
285 | 285 | $classes[] = 'wpinv-page'; |
286 | 286 | } |
287 | 287 | |
288 | - if( wpinv_is_test_mode() ) { |
|
288 | + if (wpinv_is_test_mode()) { |
|
289 | 289 | $classes[] = 'wpinv-test-mode'; |
290 | 290 | $classes[] = 'wpinv-page'; |
291 | 291 | } |
292 | 292 | |
293 | - return array_unique( $classes ); |
|
293 | + return array_unique($classes); |
|
294 | 294 | } |
295 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
295 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
296 | 296 | |
297 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
298 | - $current = date( 'Y' ); |
|
299 | - $start_year = $current - absint( $years_before ); |
|
300 | - $end_year = $current + absint( $years_after ); |
|
301 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
297 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
298 | + $current = date('Y'); |
|
299 | + $start_year = $current - absint($years_before); |
|
300 | + $end_year = $current + absint($years_after); |
|
301 | + $selected = empty($selected) ? date('Y') : $selected; |
|
302 | 302 | $options = array(); |
303 | 303 | |
304 | - while ( $start_year <= $end_year ) { |
|
305 | - $options[ absint( $start_year ) ] = $start_year; |
|
304 | + while ($start_year <= $end_year) { |
|
305 | + $options[absint($start_year)] = $start_year; |
|
306 | 306 | $start_year++; |
307 | 307 | } |
308 | 308 | |
309 | - $output = wpinv_html_select( array( |
|
309 | + $output = wpinv_html_select(array( |
|
310 | 310 | 'name' => $name, |
311 | 311 | 'selected' => $selected, |
312 | 312 | 'options' => $options, |
313 | 313 | 'show_option_all' => false, |
314 | 314 | 'show_option_none' => false |
315 | - ) ); |
|
315 | + )); |
|
316 | 316 | |
317 | 317 | return $output; |
318 | 318 | } |
319 | 319 | |
320 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
320 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
321 | 321 | |
322 | 322 | $options = array( |
323 | - '1' => __( 'January', 'invoicing' ), |
|
324 | - '2' => __( 'February', 'invoicing' ), |
|
325 | - '3' => __( 'March', 'invoicing' ), |
|
326 | - '4' => __( 'April', 'invoicing' ), |
|
327 | - '5' => __( 'May', 'invoicing' ), |
|
328 | - '6' => __( 'June', 'invoicing' ), |
|
329 | - '7' => __( 'July', 'invoicing' ), |
|
330 | - '8' => __( 'August', 'invoicing' ), |
|
331 | - '9' => __( 'September', 'invoicing' ), |
|
332 | - '10' => __( 'October', 'invoicing' ), |
|
333 | - '11' => __( 'November', 'invoicing' ), |
|
334 | - '12' => __( 'December', 'invoicing' ), |
|
323 | + '1' => __('January', 'invoicing'), |
|
324 | + '2' => __('February', 'invoicing'), |
|
325 | + '3' => __('March', 'invoicing'), |
|
326 | + '4' => __('April', 'invoicing'), |
|
327 | + '5' => __('May', 'invoicing'), |
|
328 | + '6' => __('June', 'invoicing'), |
|
329 | + '7' => __('July', 'invoicing'), |
|
330 | + '8' => __('August', 'invoicing'), |
|
331 | + '9' => __('September', 'invoicing'), |
|
332 | + '10' => __('October', 'invoicing'), |
|
333 | + '11' => __('November', 'invoicing'), |
|
334 | + '12' => __('December', 'invoicing'), |
|
335 | 335 | ); |
336 | 336 | |
337 | 337 | // If no month is selected, default to the current month |
338 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
338 | + $selected = empty($selected) ? date('n') : $selected; |
|
339 | 339 | |
340 | - $output = wpinv_html_select( array( |
|
340 | + $output = wpinv_html_select(array( |
|
341 | 341 | 'name' => $name, |
342 | 342 | 'selected' => $selected, |
343 | 343 | 'options' => $options, |
344 | 344 | 'show_option_all' => false, |
345 | 345 | 'show_option_none' => false |
346 | - ) ); |
|
346 | + )); |
|
347 | 347 | |
348 | 348 | return $output; |
349 | 349 | } |
350 | 350 | |
351 | -function wpinv_html_select( $args = array() ) { |
|
351 | +function wpinv_html_select($args = array()) { |
|
352 | 352 | $defaults = array( |
353 | 353 | 'options' => array(), |
354 | 354 | 'name' => null, |
@@ -357,8 +357,8 @@ discard block |
||
357 | 357 | 'selected' => 0, |
358 | 358 | 'placeholder' => null, |
359 | 359 | 'multiple' => false, |
360 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
361 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
360 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
361 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
362 | 362 | 'data' => array(), |
363 | 363 | 'onchange' => null, |
364 | 364 | 'required' => false, |
@@ -366,74 +366,74 @@ discard block |
||
366 | 366 | 'readonly' => false, |
367 | 367 | ); |
368 | 368 | |
369 | - $args = wp_parse_args( $args, $defaults ); |
|
369 | + $args = wp_parse_args($args, $defaults); |
|
370 | 370 | |
371 | 371 | $data_elements = ''; |
372 | - foreach ( $args['data'] as $key => $value ) { |
|
373 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
372 | + foreach ($args['data'] as $key => $value) { |
|
373 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
374 | 374 | } |
375 | 375 | |
376 | - if( $args['multiple'] ) { |
|
376 | + if ($args['multiple']) { |
|
377 | 377 | $multiple = ' MULTIPLE'; |
378 | 378 | } else { |
379 | 379 | $multiple = ''; |
380 | 380 | } |
381 | 381 | |
382 | - if( $args['placeholder'] ) { |
|
382 | + if ($args['placeholder']) { |
|
383 | 383 | $placeholder = $args['placeholder']; |
384 | 384 | } else { |
385 | 385 | $placeholder = ''; |
386 | 386 | } |
387 | 387 | |
388 | 388 | $options = ''; |
389 | - if( !empty( $args['onchange'] ) ) { |
|
390 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
389 | + if (!empty($args['onchange'])) { |
|
390 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
391 | 391 | } |
392 | 392 | |
393 | - if( !empty( $args['required'] ) ) { |
|
393 | + if (!empty($args['required'])) { |
|
394 | 394 | $options .= ' required="required"'; |
395 | 395 | } |
396 | 396 | |
397 | - if( !empty( $args['disabled'] ) ) { |
|
397 | + if (!empty($args['disabled'])) { |
|
398 | 398 | $options .= ' disabled'; |
399 | 399 | } |
400 | 400 | |
401 | - if( !empty( $args['readonly'] ) ) { |
|
401 | + if (!empty($args['readonly'])) { |
|
402 | 402 | $options .= ' readonly'; |
403 | 403 | } |
404 | 404 | |
405 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
406 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
405 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
406 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
407 | 407 | |
408 | - if ( $args['show_option_all'] ) { |
|
409 | - if( $args['multiple'] ) { |
|
410 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
408 | + if ($args['show_option_all']) { |
|
409 | + if ($args['multiple']) { |
|
410 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
411 | 411 | } else { |
412 | - $selected = selected( $args['selected'], 0, false ); |
|
412 | + $selected = selected($args['selected'], 0, false); |
|
413 | 413 | } |
414 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
414 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
415 | 415 | } |
416 | 416 | |
417 | - if ( !empty( $args['options'] ) ) { |
|
417 | + if (!empty($args['options'])) { |
|
418 | 418 | |
419 | - if ( $args['show_option_none'] ) { |
|
420 | - if( $args['multiple'] ) { |
|
421 | - $selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
419 | + if ($args['show_option_none']) { |
|
420 | + if ($args['multiple']) { |
|
421 | + $selected = selected(true, in_array("", $args['selected']), false); |
|
422 | 422 | } else { |
423 | - $selected = selected( $args['selected'] === "", true, false ); |
|
423 | + $selected = selected($args['selected'] === "", true, false); |
|
424 | 424 | } |
425 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
425 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
426 | 426 | } |
427 | 427 | |
428 | - foreach( $args['options'] as $key => $option ) { |
|
428 | + foreach ($args['options'] as $key => $option) { |
|
429 | 429 | |
430 | - if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
431 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
430 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
431 | + $selected = selected(true, (bool) in_array($key, $args['selected']), false); |
|
432 | 432 | } else { |
433 | - $selected = selected( $args['selected'], $key, false ); |
|
433 | + $selected = selected($args['selected'], $key, false); |
|
434 | 434 | } |
435 | 435 | |
436 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
436 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
437 | 437 | } |
438 | 438 | } |
439 | 439 | |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | return $output; |
443 | 443 | } |
444 | 444 | |
445 | -function wpinv_item_dropdown( $args = array() ) { |
|
445 | +function wpinv_item_dropdown($args = array()) { |
|
446 | 446 | $defaults = array( |
447 | 447 | 'name' => 'wpi_item', |
448 | 448 | 'id' => 'wpi_item', |
@@ -450,14 +450,14 @@ discard block |
||
450 | 450 | 'multiple' => false, |
451 | 451 | 'selected' => 0, |
452 | 452 | 'number' => 100, |
453 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
454 | - 'data' => array( 'search-type' => 'item' ), |
|
453 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
454 | + 'data' => array('search-type' => 'item'), |
|
455 | 455 | 'show_option_all' => false, |
456 | 456 | 'show_option_none' => false, |
457 | 457 | 'show_recurring' => false, |
458 | 458 | ); |
459 | 459 | |
460 | - $args = wp_parse_args( $args, $defaults ); |
|
460 | + $args = wp_parse_args($args, $defaults); |
|
461 | 461 | |
462 | 462 | $item_args = array( |
463 | 463 | 'post_type' => 'wpi_item', |
@@ -466,44 +466,44 @@ discard block |
||
466 | 466 | 'posts_per_page' => $args['number'] |
467 | 467 | ); |
468 | 468 | |
469 | - $item_args = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults ); |
|
469 | + $item_args = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults); |
|
470 | 470 | |
471 | - $items = get_posts( $item_args ); |
|
471 | + $items = get_posts($item_args); |
|
472 | 472 | $options = array(); |
473 | - if ( $items ) { |
|
474 | - foreach ( $items as $item ) { |
|
475 | - $title = esc_html( $item->post_title ); |
|
473 | + if ($items) { |
|
474 | + foreach ($items as $item) { |
|
475 | + $title = esc_html($item->post_title); |
|
476 | 476 | |
477 | - if ( !empty( $args['show_recurring'] ) ) { |
|
478 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
477 | + if (!empty($args['show_recurring'])) { |
|
478 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
479 | 479 | } |
480 | 480 | |
481 | - $options[ absint( $item->ID ) ] = $title; |
|
481 | + $options[absint($item->ID)] = $title; |
|
482 | 482 | } |
483 | 483 | } |
484 | 484 | |
485 | 485 | // This ensures that any selected items are included in the drop down |
486 | - if( is_array( $args['selected'] ) ) { |
|
487 | - foreach( $args['selected'] as $item ) { |
|
488 | - if( ! in_array( $item, $options ) ) { |
|
489 | - $title = get_the_title( $item ); |
|
490 | - if ( !empty( $args['show_recurring'] ) ) { |
|
491 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
486 | + if (is_array($args['selected'])) { |
|
487 | + foreach ($args['selected'] as $item) { |
|
488 | + if (!in_array($item, $options)) { |
|
489 | + $title = get_the_title($item); |
|
490 | + if (!empty($args['show_recurring'])) { |
|
491 | + $title .= wpinv_get_item_suffix($item, false); |
|
492 | 492 | } |
493 | 493 | $options[$item] = $title; |
494 | 494 | } |
495 | 495 | } |
496 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
497 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
498 | - $title = get_the_title( $args['selected'] ); |
|
499 | - if ( !empty( $args['show_recurring'] ) ) { |
|
500 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
496 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
497 | + if (!in_array($args['selected'], $options)) { |
|
498 | + $title = get_the_title($args['selected']); |
|
499 | + if (!empty($args['show_recurring'])) { |
|
500 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
501 | 501 | } |
502 | - $options[$args['selected']] = get_the_title( $args['selected'] ); |
|
502 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
503 | 503 | } |
504 | 504 | } |
505 | 505 | |
506 | - $output = wpinv_html_select( array( |
|
506 | + $output = wpinv_html_select(array( |
|
507 | 507 | 'name' => $args['name'], |
508 | 508 | 'selected' => $args['selected'], |
509 | 509 | 'id' => $args['id'], |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | 'show_option_all' => $args['show_option_all'], |
515 | 515 | 'show_option_none' => $args['show_option_none'], |
516 | 516 | 'data' => $args['data'], |
517 | - ) ); |
|
517 | + )); |
|
518 | 518 | |
519 | 519 | return $output; |
520 | 520 | } |
@@ -534,16 +534,16 @@ discard block |
||
534 | 534 | ); |
535 | 535 | |
536 | 536 | $options = array(); |
537 | - if ( $items ) { |
|
538 | - foreach ( $items as $item ) { |
|
539 | - $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false ); |
|
537 | + if ($items) { |
|
538 | + foreach ($items as $item) { |
|
539 | + $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false); |
|
540 | 540 | } |
541 | 541 | } |
542 | 542 | |
543 | 543 | return $options; |
544 | 544 | } |
545 | 545 | |
546 | -function wpinv_html_checkbox( $args = array() ) { |
|
546 | +function wpinv_html_checkbox($args = array()) { |
|
547 | 547 | $defaults = array( |
548 | 548 | 'name' => null, |
549 | 549 | 'current' => null, |
@@ -554,17 +554,17 @@ discard block |
||
554 | 554 | ) |
555 | 555 | ); |
556 | 556 | |
557 | - $args = wp_parse_args( $args, $defaults ); |
|
557 | + $args = wp_parse_args($args, $defaults); |
|
558 | 558 | |
559 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
559 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
560 | 560 | $options = ''; |
561 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
561 | + if (!empty($args['options']['disabled'])) { |
|
562 | 562 | $options .= ' disabled="disabled"'; |
563 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
563 | + } elseif (!empty($args['options']['readonly'])) { |
|
564 | 564 | $options .= ' readonly'; |
565 | 565 | } |
566 | 566 | |
567 | - $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
567 | + $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
568 | 568 | |
569 | 569 | return $output; |
570 | 570 | } |
@@ -572,30 +572,30 @@ discard block |
||
572 | 572 | /** |
573 | 573 | * Displays a hidden field. |
574 | 574 | */ |
575 | -function getpaid_hidden_field( $name, $value ) { |
|
576 | - $name = sanitize_text_field( $name ); |
|
577 | - $value = esc_attr( $value ); |
|
575 | +function getpaid_hidden_field($name, $value) { |
|
576 | + $name = sanitize_text_field($name); |
|
577 | + $value = esc_attr($value); |
|
578 | 578 | |
579 | 579 | echo "<input type='hidden' name='$name' value='$value' />"; |
580 | 580 | } |
581 | 581 | |
582 | -function wpinv_html_text( $args = array() ) { |
|
582 | +function wpinv_html_text($args = array()) { |
|
583 | 583 | // Backwards compatibility |
584 | - if ( func_num_args() > 1 ) { |
|
584 | + if (func_num_args() > 1) { |
|
585 | 585 | $args = func_get_args(); |
586 | 586 | |
587 | 587 | $name = $args[0]; |
588 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
589 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
590 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
588 | + $value = isset($args[1]) ? $args[1] : ''; |
|
589 | + $label = isset($args[2]) ? $args[2] : ''; |
|
590 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
591 | 591 | } |
592 | 592 | |
593 | 593 | $defaults = array( |
594 | 594 | 'id' => '', |
595 | - 'name' => isset( $name ) ? $name : 'text', |
|
596 | - 'value' => isset( $value ) ? $value : null, |
|
597 | - 'label' => isset( $label ) ? $label : null, |
|
598 | - 'desc' => isset( $desc ) ? $desc : null, |
|
595 | + 'name' => isset($name) ? $name : 'text', |
|
596 | + 'value' => isset($value) ? $value : null, |
|
597 | + 'label' => isset($label) ? $label : null, |
|
598 | + 'desc' => isset($desc) ? $desc : null, |
|
599 | 599 | 'placeholder' => '', |
600 | 600 | 'class' => 'regular-text', |
601 | 601 | 'disabled' => false, |
@@ -605,51 +605,51 @@ discard block |
||
605 | 605 | 'data' => false |
606 | 606 | ); |
607 | 607 | |
608 | - $args = wp_parse_args( $args, $defaults ); |
|
608 | + $args = wp_parse_args($args, $defaults); |
|
609 | 609 | |
610 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
610 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
611 | 611 | $options = ''; |
612 | - if( $args['required'] ) { |
|
612 | + if ($args['required']) { |
|
613 | 613 | $options .= ' required="required"'; |
614 | 614 | } |
615 | - if( $args['readonly'] ) { |
|
615 | + if ($args['readonly']) { |
|
616 | 616 | $options .= ' readonly'; |
617 | 617 | } |
618 | - if( $args['readonly'] ) { |
|
618 | + if ($args['readonly']) { |
|
619 | 619 | $options .= ' readonly'; |
620 | 620 | } |
621 | 621 | |
622 | 622 | $data = ''; |
623 | - if ( !empty( $args['data'] ) ) { |
|
624 | - foreach ( $args['data'] as $key => $value ) { |
|
625 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
623 | + if (!empty($args['data'])) { |
|
624 | + foreach ($args['data'] as $key => $value) { |
|
625 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
626 | 626 | } |
627 | 627 | } |
628 | 628 | |
629 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
630 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
631 | - if ( ! empty( $args['desc'] ) ) { |
|
632 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
629 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
630 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
631 | + if (!empty($args['desc'])) { |
|
632 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
633 | 633 | } |
634 | 634 | |
635 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
635 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
636 | 636 | |
637 | 637 | $output .= '</span>'; |
638 | 638 | |
639 | 639 | return $output; |
640 | 640 | } |
641 | 641 | |
642 | -function wpinv_html_date_field( $args = array() ) { |
|
643 | - if( empty( $args['class'] ) ) { |
|
642 | +function wpinv_html_date_field($args = array()) { |
|
643 | + if (empty($args['class'])) { |
|
644 | 644 | $args['class'] = 'wpiDatepicker'; |
645 | - } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) { |
|
645 | + } elseif (!strpos($args['class'], 'wpiDatepicker')) { |
|
646 | 646 | $args['class'] .= ' wpiDatepicker'; |
647 | 647 | } |
648 | 648 | |
649 | - return wpinv_html_text( $args ); |
|
649 | + return wpinv_html_text($args); |
|
650 | 650 | } |
651 | 651 | |
652 | -function wpinv_html_textarea( $args = array() ) { |
|
652 | +function wpinv_html_textarea($args = array()) { |
|
653 | 653 | $defaults = array( |
654 | 654 | 'name' => 'textarea', |
655 | 655 | 'value' => null, |
@@ -660,31 +660,31 @@ discard block |
||
660 | 660 | 'placeholder' => '', |
661 | 661 | ); |
662 | 662 | |
663 | - $args = wp_parse_args( $args, $defaults ); |
|
663 | + $args = wp_parse_args($args, $defaults); |
|
664 | 664 | |
665 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
665 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
666 | 666 | $disabled = ''; |
667 | - if( $args['disabled'] ) { |
|
667 | + if ($args['disabled']) { |
|
668 | 668 | $disabled = ' disabled="disabled"'; |
669 | 669 | } |
670 | 670 | |
671 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
672 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
673 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
671 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
672 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
673 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
674 | 674 | |
675 | - if ( ! empty( $args['desc'] ) ) { |
|
676 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
675 | + if (!empty($args['desc'])) { |
|
676 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
677 | 677 | } |
678 | 678 | $output .= '</span>'; |
679 | 679 | |
680 | 680 | return $output; |
681 | 681 | } |
682 | 682 | |
683 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
683 | +function wpinv_html_ajax_user_search($args = array()) { |
|
684 | 684 | $defaults = array( |
685 | 685 | 'name' => 'user_id', |
686 | 686 | 'value' => null, |
687 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
687 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
688 | 688 | 'label' => null, |
689 | 689 | 'desc' => null, |
690 | 690 | 'class' => '', |
@@ -693,13 +693,13 @@ discard block |
||
693 | 693 | 'data' => false |
694 | 694 | ); |
695 | 695 | |
696 | - $args = wp_parse_args( $args, $defaults ); |
|
696 | + $args = wp_parse_args($args, $defaults); |
|
697 | 697 | |
698 | 698 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
699 | 699 | |
700 | 700 | $output = '<span class="wpinv_user_search_wrap">'; |
701 | - $output .= wpinv_html_text( $args ); |
|
702 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
701 | + $output .= wpinv_html_text($args); |
|
702 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
703 | 703 | $output .= '</span>'; |
704 | 704 | |
705 | 705 | return $output; |
@@ -715,20 +715,20 @@ discard block |
||
715 | 715 | * |
716 | 716 | * @param string $template the template that is currently being used. |
717 | 717 | */ |
718 | -function wpinv_template( $template ) { |
|
718 | +function wpinv_template($template) { |
|
719 | 719 | global $post; |
720 | 720 | |
721 | - if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) { |
|
721 | + if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) { |
|
722 | 722 | |
723 | 723 | // If the user can view this invoice, display it. |
724 | - if ( wpinv_user_can_view_invoice( $post->ID ) ) { |
|
724 | + if (wpinv_user_can_view_invoice($post->ID)) { |
|
725 | 725 | |
726 | - return wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
726 | + return wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
727 | 727 | |
728 | 728 | // Else display an error message. |
729 | 729 | } else { |
730 | 730 | |
731 | - return wpinv_get_template_part( 'wpinv-invalid-access', false, false ); |
|
731 | + return wpinv_get_template_part('wpinv-invalid-access', false, false); |
|
732 | 732 | |
733 | 733 | } |
734 | 734 | |
@@ -736,46 +736,46 @@ discard block |
||
736 | 736 | |
737 | 737 | return $template; |
738 | 738 | } |
739 | -add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
739 | +add_filter('template_include', 'wpinv_template', 10, 1); |
|
740 | 740 | |
741 | 741 | function wpinv_get_business_address() { |
742 | 742 | $business_address = wpinv_store_address(); |
743 | - $business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
743 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
744 | 744 | |
745 | 745 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
746 | 746 | |
747 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
747 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
748 | 748 | } |
749 | 749 | |
750 | 750 | /** |
751 | 751 | * Displays the company address. |
752 | 752 | */ |
753 | 753 | function wpinv_display_from_address() { |
754 | - wpinv_get_template( 'invoice/company-address.php' ); |
|
754 | + wpinv_get_template('invoice/company-address.php'); |
|
755 | 755 | } |
756 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 ); |
|
756 | +add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10); |
|
757 | 757 | |
758 | -function wpinv_watermark( $id = 0 ) { |
|
759 | - $output = wpinv_get_watermark( $id ); |
|
760 | - return apply_filters( 'wpinv_get_watermark', $output, $id ); |
|
758 | +function wpinv_watermark($id = 0) { |
|
759 | + $output = wpinv_get_watermark($id); |
|
760 | + return apply_filters('wpinv_get_watermark', $output, $id); |
|
761 | 761 | } |
762 | 762 | |
763 | -function wpinv_get_watermark( $id ) { |
|
764 | - if ( !$id > 0 ) { |
|
763 | +function wpinv_get_watermark($id) { |
|
764 | + if (!$id > 0) { |
|
765 | 765 | return NULL; |
766 | 766 | } |
767 | 767 | |
768 | - $invoice = wpinv_get_invoice( $id ); |
|
768 | + $invoice = wpinv_get_invoice($id); |
|
769 | 769 | |
770 | - if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) { |
|
771 | - if ( $invoice->is_paid() ) { |
|
772 | - return __( 'Paid', 'invoicing' ); |
|
770 | + if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) { |
|
771 | + if ($invoice->is_paid()) { |
|
772 | + return __('Paid', 'invoicing'); |
|
773 | 773 | } |
774 | - if ( $invoice->is_refunded() ) { |
|
775 | - return __( 'Refunded', 'invoicing' ); |
|
774 | + if ($invoice->is_refunded()) { |
|
775 | + return __('Refunded', 'invoicing'); |
|
776 | 776 | } |
777 | - if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) { |
|
778 | - return __( 'Cancelled', 'invoicing' ); |
|
777 | + if ($invoice->has_status(array('wpi-cancelled'))) { |
|
778 | + return __('Cancelled', 'invoicing'); |
|
779 | 779 | } |
780 | 780 | } |
781 | 781 | |
@@ -785,30 +785,30 @@ discard block |
||
785 | 785 | /** |
786 | 786 | * @deprecated |
787 | 787 | */ |
788 | -function wpinv_display_invoice_details( $invoice ) { |
|
789 | - return getpaid_invoice_meta( $invoice ); |
|
788 | +function wpinv_display_invoice_details($invoice) { |
|
789 | + return getpaid_invoice_meta($invoice); |
|
790 | 790 | } |
791 | 791 | |
792 | 792 | /** |
793 | 793 | * Displays invoice meta. |
794 | 794 | */ |
795 | -function getpaid_invoice_meta( $invoice ) { |
|
795 | +function getpaid_invoice_meta($invoice) { |
|
796 | 796 | |
797 | - $invoice = new WPInv_Invoice( $invoice ); |
|
797 | + $invoice = new WPInv_Invoice($invoice); |
|
798 | 798 | |
799 | 799 | // Ensure that we have an invoice. |
800 | - if ( 0 == $invoice->get_id() ) { |
|
800 | + if (0 == $invoice->get_id()) { |
|
801 | 801 | return; |
802 | 802 | } |
803 | 803 | |
804 | 804 | // Get the invoice meta. |
805 | - $meta = getpaid_get_invoice_meta( $invoice ); |
|
805 | + $meta = getpaid_get_invoice_meta($invoice); |
|
806 | 806 | |
807 | 807 | // Display the meta. |
808 | - wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) ); |
|
808 | + wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta')); |
|
809 | 809 | |
810 | 810 | } |
811 | -add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 ); |
|
811 | +add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10); |
|
812 | 812 | |
813 | 813 | /** |
814 | 814 | * Retrieves the address markup to use on Invoices. |
@@ -820,29 +820,29 @@ discard block |
||
820 | 820 | * @param string $separator How to separate address lines. |
821 | 821 | * @return string |
822 | 822 | */ |
823 | -function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) { |
|
823 | +function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') { |
|
824 | 824 | |
825 | 825 | // Retrieve the address markup... |
826 | - $country= empty( $billing_details['country'] ) ? '' : $billing_details['country']; |
|
827 | - $format = wpinv_get_full_address_format( $country ); |
|
826 | + $country = empty($billing_details['country']) ? '' : $billing_details['country']; |
|
827 | + $format = wpinv_get_full_address_format($country); |
|
828 | 828 | |
829 | 829 | // ... and the replacements. |
830 | - $replacements = wpinv_get_invoice_address_replacements( $billing_details ); |
|
830 | + $replacements = wpinv_get_invoice_address_replacements($billing_details); |
|
831 | 831 | |
832 | - $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
|
832 | + $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format); |
|
833 | 833 | |
834 | 834 | // Remove unavailable tags. |
835 | - $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address ); |
|
835 | + $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address); |
|
836 | 836 | |
837 | 837 | // Clean up white space. |
838 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
839 | - $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
|
838 | + $formatted_address = preg_replace('/ +/', ' ', trim($formatted_address)); |
|
839 | + $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address); |
|
840 | 840 | |
841 | 841 | // Break newlines apart and remove empty lines/trim commas and white space. |
842 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
842 | + $formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address))); |
|
843 | 843 | |
844 | 844 | // Add html breaks. |
845 | - $formatted_address = implode( $separator, $formatted_address ); |
|
845 | + $formatted_address = implode($separator, $formatted_address); |
|
846 | 846 | |
847 | 847 | // We're done! |
848 | 848 | return $formatted_address; |
@@ -854,88 +854,88 @@ discard block |
||
854 | 854 | * |
855 | 855 | * @param WPInv_Invoice $invoice |
856 | 856 | */ |
857 | -function wpinv_display_to_address( $invoice = 0 ) { |
|
858 | - if ( ! empty( $invoice ) ) { |
|
859 | - wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) ); |
|
857 | +function wpinv_display_to_address($invoice = 0) { |
|
858 | + if (!empty($invoice)) { |
|
859 | + wpinv_get_template('invoice/billing-address.php', compact('invoice')); |
|
860 | 860 | } |
861 | 861 | } |
862 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 ); |
|
862 | +add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40); |
|
863 | 863 | |
864 | 864 | |
865 | 865 | /** |
866 | 866 | * Displays invoice line items. |
867 | 867 | */ |
868 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
868 | +function wpinv_display_line_items($invoice_id = 0) { |
|
869 | 869 | |
870 | 870 | // Prepare the invoice. |
871 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
871 | + $invoice = new WPInv_Invoice($invoice_id); |
|
872 | 872 | |
873 | 873 | // Abort if there is no invoice. |
874 | - if ( 0 == $invoice->get_id() ) { |
|
874 | + if (0 == $invoice->get_id()) { |
|
875 | 875 | return; |
876 | 876 | } |
877 | 877 | |
878 | 878 | // Line item columns. |
879 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
880 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
879 | + $columns = getpaid_invoice_item_columns($invoice); |
|
880 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
881 | 881 | |
882 | - wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) ); |
|
882 | + wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns')); |
|
883 | 883 | } |
884 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 ); |
|
884 | +add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10); |
|
885 | 885 | |
886 | 886 | /** |
887 | 887 | * Displays invoice notices on invoices. |
888 | 888 | */ |
889 | 889 | function wpinv_display_invoice_notice() { |
890 | 890 | |
891 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
892 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
891 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
892 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
893 | 893 | |
894 | - if ( empty( $label ) && empty( $notice ) ) { |
|
894 | + if (empty($label) && empty($notice)) { |
|
895 | 895 | return; |
896 | 896 | } |
897 | 897 | |
898 | 898 | echo '<div class="mt-4 mb-4 wpinv-vat-notice">'; |
899 | 899 | |
900 | - if ( ! empty( $label ) ) { |
|
901 | - $label = sanitize_text_field( $label ); |
|
900 | + if (!empty($label)) { |
|
901 | + $label = sanitize_text_field($label); |
|
902 | 902 | echo "<h5>$label</h5>"; |
903 | 903 | } |
904 | 904 | |
905 | - if ( ! empty( $notice ) ) { |
|
906 | - echo '<small class="form-text text-muted">' . wpautop( wptexturize( $notice ) ) . '</small>'; |
|
905 | + if (!empty($notice)) { |
|
906 | + echo '<small class="form-text text-muted">' . wpautop(wptexturize($notice)) . '</small>'; |
|
907 | 907 | } |
908 | 908 | |
909 | 909 | echo '</div>'; |
910 | 910 | } |
911 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 ); |
|
911 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100); |
|
912 | 912 | |
913 | 913 | /** |
914 | 914 | * @param WPInv_Invoice $invoice |
915 | 915 | */ |
916 | -function wpinv_display_invoice_notes( $invoice ) { |
|
916 | +function wpinv_display_invoice_notes($invoice) { |
|
917 | 917 | |
918 | 918 | // Retrieve the notes. |
919 | - $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' ); |
|
919 | + $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer'); |
|
920 | 920 | |
921 | 921 | // Abort if we have non. |
922 | - if ( empty( $notes ) ) { |
|
922 | + if (empty($notes)) { |
|
923 | 923 | return; |
924 | 924 | } |
925 | 925 | |
926 | 926 | // Echo the note. |
927 | 927 | echo '<div class="getpaid-invoice-notes-wrapper border position-relative w-100 mb-4 p-0">'; |
928 | - echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __( 'Notes', 'invoicing' ) .'</h3>'; |
|
928 | + echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __('Notes', 'invoicing') . '</h3>'; |
|
929 | 929 | echo '<ul class="getpaid-invoice-notes mt-4 p-0">'; |
930 | 930 | |
931 | - foreach( $notes as $note ) { |
|
932 | - wpinv_get_invoice_note_line_item( $note ); |
|
931 | + foreach ($notes as $note) { |
|
932 | + wpinv_get_invoice_note_line_item($note); |
|
933 | 933 | } |
934 | 934 | |
935 | 935 | echo '</ul>'; |
936 | 936 | echo '</div>'; |
937 | 937 | } |
938 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 ); |
|
938 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60); |
|
939 | 939 | |
940 | 940 | /** |
941 | 941 | * Loads scripts on our invoice templates. |
@@ -943,32 +943,32 @@ discard block |
||
943 | 943 | function wpinv_display_style() { |
944 | 944 | |
945 | 945 | // Make sure that all scripts have been loaded. |
946 | - if ( ! did_action( 'wp_enqueue_scripts' ) ) { |
|
947 | - do_action( 'wp_enqueue_scripts' ); |
|
946 | + if (!did_action('wp_enqueue_scripts')) { |
|
947 | + do_action('wp_enqueue_scripts'); |
|
948 | 948 | } |
949 | 949 | |
950 | 950 | // Register the invoices style. |
951 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) ); |
|
951 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css')); |
|
952 | 952 | |
953 | 953 | // Load required styles |
954 | - wp_print_styles( 'open-sans' ); |
|
955 | - wp_print_styles( 'wpinv-single-style' ); |
|
956 | - wp_print_styles( 'ayecode-ui' ); |
|
954 | + wp_print_styles('open-sans'); |
|
955 | + wp_print_styles('wpinv-single-style'); |
|
956 | + wp_print_styles('ayecode-ui'); |
|
957 | 957 | |
958 | 958 | // Maybe load custom css. |
959 | - $custom_css = wpinv_get_option( 'template_custom_css' ); |
|
959 | + $custom_css = wpinv_get_option('template_custom_css'); |
|
960 | 960 | |
961 | - if ( isset( $custom_css ) && ! empty( $custom_css ) ) { |
|
962 | - $custom_css = wp_kses( $custom_css, array( '\'', '\"' ) ); |
|
963 | - $custom_css = str_replace( '>', '>', $custom_css ); |
|
961 | + if (isset($custom_css) && !empty($custom_css)) { |
|
962 | + $custom_css = wp_kses($custom_css, array('\'', '\"')); |
|
963 | + $custom_css = str_replace('>', '>', $custom_css); |
|
964 | 964 | echo '<style type="text/css">'; |
965 | 965 | echo $custom_css; |
966 | 966 | echo '</style>'; |
967 | 967 | } |
968 | 968 | |
969 | 969 | } |
970 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
971 | -add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' ); |
|
970 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
971 | +add_action('wpinv_invalid_invoice_head', 'wpinv_display_style'); |
|
972 | 972 | |
973 | 973 | |
974 | 974 | /** |
@@ -980,41 +980,41 @@ discard block |
||
980 | 980 | // Retrieve the current invoice. |
981 | 981 | $invoice_id = getpaid_get_current_invoice_id(); |
982 | 982 | |
983 | - if ( empty( $invoice_id ) ) { |
|
983 | + if (empty($invoice_id)) { |
|
984 | 984 | |
985 | 985 | return aui()->alert( |
986 | 986 | array( |
987 | 987 | 'type' => 'warning', |
988 | - 'content' => __( 'Invalid invoice', 'invoicing' ), |
|
988 | + 'content' => __('Invalid invoice', 'invoicing'), |
|
989 | 989 | ) |
990 | 990 | ); |
991 | 991 | |
992 | 992 | } |
993 | 993 | |
994 | 994 | // Can the user view this invoice? |
995 | - if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) { |
|
995 | + if (!wpinv_user_can_view_invoice($invoice_id)) { |
|
996 | 996 | |
997 | 997 | return aui()->alert( |
998 | 998 | array( |
999 | 999 | 'type' => 'warning', |
1000 | - 'content' => __( 'You are not allowed to view this invoice', 'invoicing' ), |
|
1000 | + 'content' => __('You are not allowed to view this invoice', 'invoicing'), |
|
1001 | 1001 | ) |
1002 | 1002 | ); |
1003 | 1003 | |
1004 | 1004 | } |
1005 | 1005 | |
1006 | 1006 | // Ensure that it is not yet paid for. |
1007 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
1007 | + $invoice = new WPInv_Invoice($invoice_id); |
|
1008 | 1008 | |
1009 | 1009 | // Maybe mark it as viewed. |
1010 | - getpaid_maybe_mark_invoice_as_viewed( $invoice ); |
|
1010 | + getpaid_maybe_mark_invoice_as_viewed($invoice); |
|
1011 | 1011 | |
1012 | - if ( $invoice->is_paid() ) { |
|
1012 | + if ($invoice->is_paid()) { |
|
1013 | 1013 | |
1014 | 1014 | return aui()->alert( |
1015 | 1015 | array( |
1016 | 1016 | 'type' => 'success', |
1017 | - 'content' => __( 'This invoice has already been paid.', 'invoicing' ), |
|
1017 | + 'content' => __('This invoice has already been paid.', 'invoicing'), |
|
1018 | 1018 | ) |
1019 | 1019 | ); |
1020 | 1020 | |
@@ -1024,14 +1024,14 @@ discard block |
||
1024 | 1024 | $wpi_checkout_id = $invoice_id; |
1025 | 1025 | |
1026 | 1026 | // We'll display this invoice via the default form. |
1027 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1027 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1028 | 1028 | |
1029 | - if ( 0 == $form->get_id() ) { |
|
1029 | + if (0 == $form->get_id()) { |
|
1030 | 1030 | |
1031 | 1031 | return aui()->alert( |
1032 | 1032 | array( |
1033 | 1033 | 'type' => 'warning', |
1034 | - 'content' => __( 'Error loading the payment form', 'invoicing' ), |
|
1034 | + 'content' => __('Error loading the payment form', 'invoicing'), |
|
1035 | 1035 | ) |
1036 | 1036 | ); |
1037 | 1037 | |
@@ -1039,7 +1039,7 @@ discard block |
||
1039 | 1039 | |
1040 | 1040 | // Set the invoice. |
1041 | 1041 | $form->invoice = $invoice; |
1042 | - $form->set_items( $invoice->get_items() ); |
|
1042 | + $form->set_items($invoice->get_items()); |
|
1043 | 1043 | |
1044 | 1044 | // Generate the html. |
1045 | 1045 | return $form->get_html(); |
@@ -1047,7 +1047,7 @@ discard block |
||
1047 | 1047 | } |
1048 | 1048 | |
1049 | 1049 | function wpinv_empty_cart_message() { |
1050 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1050 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1051 | 1051 | } |
1052 | 1052 | |
1053 | 1053 | /** |
@@ -1064,38 +1064,38 @@ discard block |
||
1064 | 1064 | ) |
1065 | 1065 | ); |
1066 | 1066 | } |
1067 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1067 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1068 | 1068 | |
1069 | -function wpinv_receipt_billing_address( $invoice_id = 0 ) { |
|
1070 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1069 | +function wpinv_receipt_billing_address($invoice_id = 0) { |
|
1070 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1071 | 1071 | |
1072 | - if ( empty( $invoice ) ) { |
|
1072 | + if (empty($invoice)) { |
|
1073 | 1073 | return NULL; |
1074 | 1074 | } |
1075 | 1075 | |
1076 | 1076 | $billing_details = $invoice->get_user_info(); |
1077 | - $address_row = wpinv_get_invoice_address_markup( $billing_details ); |
|
1077 | + $address_row = wpinv_get_invoice_address_markup($billing_details); |
|
1078 | 1078 | |
1079 | 1079 | ob_start(); |
1080 | 1080 | ?> |
1081 | 1081 | <table class="table table-bordered table-sm wpi-billing-details"> |
1082 | 1082 | <tbody> |
1083 | 1083 | <tr class="wpi-receipt-name"> |
1084 | - <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
1085 | - <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td> |
|
1084 | + <th class="text-left"><?php _e('Name', 'invoicing'); ?></th> |
|
1085 | + <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td> |
|
1086 | 1086 | </tr> |
1087 | 1087 | <tr class="wpi-receipt-email"> |
1088 | - <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
1089 | - <td><?php echo $billing_details['email'] ;?></td> |
|
1088 | + <th class="text-left"><?php _e('Email', 'invoicing'); ?></th> |
|
1089 | + <td><?php echo $billing_details['email']; ?></td> |
|
1090 | 1090 | </tr> |
1091 | 1091 | <tr class="wpi-receipt-address"> |
1092 | - <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
1093 | - <td><?php echo $address_row ;?></td> |
|
1092 | + <th class="text-left"><?php _e('Address', 'invoicing'); ?></th> |
|
1093 | + <td><?php echo $address_row; ?></td> |
|
1094 | 1094 | </tr> |
1095 | - <?php if ( $billing_details['phone'] ) { ?> |
|
1095 | + <?php if ($billing_details['phone']) { ?> |
|
1096 | 1096 | <tr class="wpi-receipt-phone"> |
1097 | - <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
1098 | - <td><?php echo esc_html( $billing_details['phone'] ) ;?></td> |
|
1097 | + <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th> |
|
1098 | + <td><?php echo esc_html($billing_details['phone']); ?></td> |
|
1099 | 1099 | </tr> |
1100 | 1100 | <?php } ?> |
1101 | 1101 | </tbody> |
@@ -1103,7 +1103,7 @@ discard block |
||
1103 | 1103 | <?php |
1104 | 1104 | $output = ob_get_clean(); |
1105 | 1105 | |
1106 | - $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id ); |
|
1106 | + $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id); |
|
1107 | 1107 | |
1108 | 1108 | echo $output; |
1109 | 1109 | } |
@@ -1111,66 +1111,66 @@ discard block |
||
1111 | 1111 | /** |
1112 | 1112 | * Filters the receipt page. |
1113 | 1113 | */ |
1114 | -function wpinv_filter_success_page_content( $content ) { |
|
1114 | +function wpinv_filter_success_page_content($content) { |
|
1115 | 1115 | |
1116 | 1116 | // Ensure this is our page. |
1117 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1117 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1118 | 1118 | |
1119 | - $gateway = sanitize_text_field( $_GET['payment-confirm'] ); |
|
1120 | - return apply_filters( "wpinv_payment_confirm_$gateway", $content ); |
|
1119 | + $gateway = sanitize_text_field($_GET['payment-confirm']); |
|
1120 | + return apply_filters("wpinv_payment_confirm_$gateway", $content); |
|
1121 | 1121 | |
1122 | 1122 | } |
1123 | 1123 | |
1124 | 1124 | return $content; |
1125 | 1125 | } |
1126 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1126 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1127 | 1127 | |
1128 | -function wpinv_invoice_link( $invoice_id ) { |
|
1129 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1128 | +function wpinv_invoice_link($invoice_id) { |
|
1129 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1130 | 1130 | |
1131 | - if ( empty( $invoice ) ) { |
|
1131 | + if (empty($invoice)) { |
|
1132 | 1132 | return NULL; |
1133 | 1133 | } |
1134 | 1134 | |
1135 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1135 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1136 | 1136 | |
1137 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1137 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1138 | 1138 | } |
1139 | 1139 | |
1140 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
1141 | - if ( empty( $note ) ) { |
|
1140 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
1141 | + if (empty($note)) { |
|
1142 | 1142 | return NULL; |
1143 | 1143 | } |
1144 | 1144 | |
1145 | - if ( is_int( $note ) ) { |
|
1146 | - $note = get_comment( $note ); |
|
1145 | + if (is_int($note)) { |
|
1146 | + $note = get_comment($note); |
|
1147 | 1147 | } |
1148 | 1148 | |
1149 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
1149 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
1150 | 1150 | return NULL; |
1151 | 1151 | } |
1152 | 1152 | |
1153 | - $note_classes = array( 'note' ); |
|
1154 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
1153 | + $note_classes = array('note'); |
|
1154 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
1155 | 1155 | $note_classes[] = $note->comment_author === 'System' ? 'system-note' : ''; |
1156 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
1157 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
1156 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
1157 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
1158 | 1158 | |
1159 | 1159 | ob_start(); |
1160 | 1160 | ?> |
1161 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?> mt-4 pl-3 pr-3"> |
|
1161 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mt-4 pl-3 pr-3"> |
|
1162 | 1162 | <div class="note_content bg-light border position-relative p-4"> |
1163 | 1163 | |
1164 | - <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?> |
|
1164 | + <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?> |
|
1165 | 1165 | |
1166 | - <?php if ( ! is_admin() ) : ?> |
|
1166 | + <?php if (!is_admin()) : ?> |
|
1167 | 1167 | <em class="meta position-absolute form-text"> |
1168 | 1168 | <?php |
1169 | 1169 | printf( |
1170 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1170 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
1171 | 1171 | $note->comment_author, |
1172 | - getpaid_format_date_value( $note->comment_date ), |
|
1173 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
1172 | + getpaid_format_date_value($note->comment_date), |
|
1173 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
1174 | 1174 | ); |
1175 | 1175 | ?> |
1176 | 1176 | </em> |
@@ -1178,21 +1178,21 @@ discard block |
||
1178 | 1178 | |
1179 | 1179 | </div> |
1180 | 1180 | |
1181 | - <?php if ( is_admin() ) : ?> |
|
1181 | + <?php if (is_admin()) : ?> |
|
1182 | 1182 | |
1183 | 1183 | <p class="meta px-4 py-2"> |
1184 | - <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>"> |
|
1184 | + <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>"> |
|
1185 | 1185 | <?php |
1186 | 1186 | printf( |
1187 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1187 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
1188 | 1188 | $note->comment_author, |
1189 | - getpaid_format_date_value( $note->comment_date ), |
|
1190 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
1189 | + getpaid_format_date_value($note->comment_date), |
|
1190 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
1191 | 1191 | ); |
1192 | 1192 | ?> |
1193 | 1193 | </abbr> |
1194 | - <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?> |
|
1195 | - <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
1194 | + <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?> |
|
1195 | + <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
1196 | 1196 | <?php } ?> |
1197 | 1197 | </p> |
1198 | 1198 | |
@@ -1201,9 +1201,9 @@ discard block |
||
1201 | 1201 | </li> |
1202 | 1202 | <?php |
1203 | 1203 | $note_content = ob_get_clean(); |
1204 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
1204 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
1205 | 1205 | |
1206 | - if ( $echo ) { |
|
1206 | + if ($echo) { |
|
1207 | 1207 | echo $note_content; |
1208 | 1208 | } else { |
1209 | 1209 | return $note_content; |
@@ -1213,36 +1213,36 @@ discard block |
||
1213 | 1213 | function wpinv_invalid_invoice_content() { |
1214 | 1214 | global $post; |
1215 | 1215 | |
1216 | - $invoice = wpinv_get_invoice( $post->ID ); |
|
1216 | + $invoice = wpinv_get_invoice($post->ID); |
|
1217 | 1217 | |
1218 | - $error = __( 'This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing' ); |
|
1219 | - if ( !empty( $invoice->get_id() ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
1220 | - if ( is_user_logged_in() ) { |
|
1221 | - if ( wpinv_require_login_to_checkout() ) { |
|
1222 | - if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
1223 | - $error = __( 'You are not allowed to view this invoice.', 'invoicing' ); |
|
1218 | + $error = __('This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing'); |
|
1219 | + if (!empty($invoice->get_id()) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) { |
|
1220 | + if (is_user_logged_in()) { |
|
1221 | + if (wpinv_require_login_to_checkout()) { |
|
1222 | + if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
1223 | + $error = __('You are not allowed to view this invoice.', 'invoicing'); |
|
1224 | 1224 | } |
1225 | 1225 | } |
1226 | 1226 | } else { |
1227 | - if ( wpinv_require_login_to_checkout() ) { |
|
1228 | - if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
1229 | - $error = __( 'You must be logged in to view this invoice.', 'invoicing' ); |
|
1227 | + if (wpinv_require_login_to_checkout()) { |
|
1228 | + if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
1229 | + $error = __('You must be logged in to view this invoice.', 'invoicing'); |
|
1230 | 1230 | } |
1231 | 1231 | } |
1232 | 1232 | } |
1233 | 1233 | } else { |
1234 | - $error = __( 'This invoice is deleted or does not exist.', 'invoicing' ); |
|
1234 | + $error = __('This invoice is deleted or does not exist.', 'invoicing'); |
|
1235 | 1235 | } |
1236 | 1236 | ?> |
1237 | 1237 | <div class="row wpinv-row-invalid"> |
1238 | 1238 | <div class="col-md-6 col-md-offset-3 wpinv-message error"> |
1239 | - <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3> |
|
1239 | + <h3><?php _e('Access Denied', 'invoicing'); ?></h3> |
|
1240 | 1240 | <p class="wpinv-msg-text"><?php echo $error; ?></p> |
1241 | 1241 | </div> |
1242 | 1242 | </div> |
1243 | 1243 | <?php |
1244 | 1244 | } |
1245 | -add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' ); |
|
1245 | +add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content'); |
|
1246 | 1246 | |
1247 | 1247 | /** |
1248 | 1248 | * Function to get privacy policy text. |
@@ -1251,21 +1251,21 @@ discard block |
||
1251 | 1251 | * @return string |
1252 | 1252 | */ |
1253 | 1253 | function wpinv_get_policy_text() { |
1254 | - $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 ); |
|
1254 | + $privacy_page_id = get_option('wp_page_for_privacy_policy', 0); |
|
1255 | 1255 | |
1256 | - $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' )); |
|
1256 | + $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]')); |
|
1257 | 1257 | |
1258 | - if(!$privacy_page_id){ |
|
1259 | - $privacy_page_id = wpinv_get_option( 'privacy_page', 0 ); |
|
1258 | + if (!$privacy_page_id) { |
|
1259 | + $privacy_page_id = wpinv_get_option('privacy_page', 0); |
|
1260 | 1260 | } |
1261 | 1261 | |
1262 | - $privacy_link = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' ); |
|
1262 | + $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing'); |
|
1263 | 1263 | |
1264 | 1264 | $find_replace = array( |
1265 | 1265 | '[wpinv_privacy_policy]' => $privacy_link, |
1266 | 1266 | ); |
1267 | 1267 | |
1268 | - $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text ); |
|
1268 | + $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text); |
|
1269 | 1269 | |
1270 | 1270 | return wp_kses_post(wpautop($privacy_text)); |
1271 | 1271 | } |
@@ -1273,21 +1273,21 @@ discard block |
||
1273 | 1273 | function wpinv_oxygen_fix_conflict() { |
1274 | 1274 | global $ct_ignore_post_types; |
1275 | 1275 | |
1276 | - if ( ! is_array( $ct_ignore_post_types ) ) { |
|
1276 | + if (!is_array($ct_ignore_post_types)) { |
|
1277 | 1277 | $ct_ignore_post_types = array(); |
1278 | 1278 | } |
1279 | 1279 | |
1280 | - $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item' ); |
|
1280 | + $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item'); |
|
1281 | 1281 | |
1282 | - foreach ( $post_types as $post_type ) { |
|
1282 | + foreach ($post_types as $post_type) { |
|
1283 | 1283 | $ct_ignore_post_types[] = $post_type; |
1284 | 1284 | |
1285 | 1285 | // Ignore post type |
1286 | - add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 ); |
|
1286 | + add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999); |
|
1287 | 1287 | } |
1288 | 1288 | |
1289 | - remove_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
1290 | - add_filter( 'template_include', 'wpinv_template', 999, 1 ); |
|
1289 | + remove_filter('template_include', 'wpinv_template', 10, 1); |
|
1290 | + add_filter('template_include', 'wpinv_template', 999, 1); |
|
1291 | 1291 | } |
1292 | 1292 | |
1293 | 1293 | /** |
@@ -1295,10 +1295,10 @@ discard block |
||
1295 | 1295 | * |
1296 | 1296 | * @param GetPaid_Payment_Form $form |
1297 | 1297 | */ |
1298 | -function getpaid_display_payment_form( $form ) { |
|
1298 | +function getpaid_display_payment_form($form) { |
|
1299 | 1299 | |
1300 | - if ( is_numeric( $form ) ) { |
|
1301 | - $form = new GetPaid_Payment_Form( $form ); |
|
1300 | + if (is_numeric($form)) { |
|
1301 | + $form = new GetPaid_Payment_Form($form); |
|
1302 | 1302 | } |
1303 | 1303 | |
1304 | 1304 | $form->display(); |
@@ -1308,55 +1308,55 @@ discard block |
||
1308 | 1308 | /** |
1309 | 1309 | * Helper function to display a item payment form on the frontend. |
1310 | 1310 | */ |
1311 | -function getpaid_display_item_payment_form( $items ) { |
|
1311 | +function getpaid_display_item_payment_form($items) { |
|
1312 | 1312 | |
1313 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1314 | - $form->set_items( $items ); |
|
1313 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1314 | + $form->set_items($items); |
|
1315 | 1315 | |
1316 | - if ( 0 == count( $form->get_items() ) ) { |
|
1316 | + if (0 == count($form->get_items())) { |
|
1317 | 1317 | echo aui()->alert( |
1318 | 1318 | array( |
1319 | 1319 | 'type' => 'warning', |
1320 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1320 | + 'content' => __('No published items found', 'invoicing'), |
|
1321 | 1321 | ) |
1322 | 1322 | ); |
1323 | 1323 | return; |
1324 | 1324 | } |
1325 | 1325 | |
1326 | - $form_items = esc_attr( getpaid_convert_items_to_string( $items ) ); |
|
1326 | + $form_items = esc_attr(getpaid_convert_items_to_string($items)); |
|
1327 | 1327 | $form_items = "<input type='hidden' name='getpaid-form-items' value='$form_items' />"; |
1328 | - $form->display( $form_items ); |
|
1328 | + $form->display($form_items); |
|
1329 | 1329 | } |
1330 | 1330 | |
1331 | 1331 | /** |
1332 | 1332 | * Helper function to display an invoice payment form on the frontend. |
1333 | 1333 | */ |
1334 | -function getpaid_display_invoice_payment_form( $invoice_id ) { |
|
1334 | +function getpaid_display_invoice_payment_form($invoice_id) { |
|
1335 | 1335 | |
1336 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1336 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1337 | 1337 | |
1338 | - if ( empty( $invoice ) ) { |
|
1338 | + if (empty($invoice)) { |
|
1339 | 1339 | echo aui()->alert( |
1340 | 1340 | array( |
1341 | 1341 | 'type' => 'warning', |
1342 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1342 | + 'content' => __('Invoice not found', 'invoicing'), |
|
1343 | 1343 | ) |
1344 | 1344 | ); |
1345 | 1345 | return; |
1346 | 1346 | } |
1347 | 1347 | |
1348 | - if ( $invoice->is_paid() ) { |
|
1348 | + if ($invoice->is_paid()) { |
|
1349 | 1349 | echo aui()->alert( |
1350 | 1350 | array( |
1351 | 1351 | 'type' => 'warning', |
1352 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1352 | + 'content' => __('Invoice has already been paid', 'invoicing'), |
|
1353 | 1353 | ) |
1354 | 1354 | ); |
1355 | 1355 | return; |
1356 | 1356 | } |
1357 | 1357 | |
1358 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1359 | - $form->set_items( $invoice->get_items() ); |
|
1358 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1359 | + $form->set_items($invoice->get_items()); |
|
1360 | 1360 | |
1361 | 1361 | $form->display(); |
1362 | 1362 | } |
@@ -1364,23 +1364,23 @@ discard block |
||
1364 | 1364 | /** |
1365 | 1365 | * Helper function to convert item string to array. |
1366 | 1366 | */ |
1367 | -function getpaid_convert_items_to_array( $items ) { |
|
1368 | - $items = array_filter( array_map( 'trim', explode( ',', $items ) ) ); |
|
1367 | +function getpaid_convert_items_to_array($items) { |
|
1368 | + $items = array_filter(array_map('trim', explode(',', $items))); |
|
1369 | 1369 | $prepared = array(); |
1370 | 1370 | |
1371 | - foreach ( $items as $item ) { |
|
1372 | - $data = array_map( 'trim', explode( '|', $item ) ); |
|
1371 | + foreach ($items as $item) { |
|
1372 | + $data = array_map('trim', explode('|', $item)); |
|
1373 | 1373 | |
1374 | - if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) { |
|
1374 | + if (empty($data[0]) || !is_numeric($data[0])) { |
|
1375 | 1375 | continue; |
1376 | 1376 | } |
1377 | 1377 | |
1378 | 1378 | $quantity = 1; |
1379 | - if ( isset( $data[1] ) && is_numeric( $data[1] ) ) { |
|
1379 | + if (isset($data[1]) && is_numeric($data[1])) { |
|
1380 | 1380 | $quantity = (int) $data[1]; |
1381 | 1381 | } |
1382 | 1382 | |
1383 | - $prepared[ $data[0] ] = $quantity; |
|
1383 | + $prepared[$data[0]] = $quantity; |
|
1384 | 1384 | |
1385 | 1385 | } |
1386 | 1386 | |
@@ -1390,13 +1390,13 @@ discard block |
||
1390 | 1390 | /** |
1391 | 1391 | * Helper function to convert item array to string. |
1392 | 1392 | */ |
1393 | -function getpaid_convert_items_to_string( $items ) { |
|
1393 | +function getpaid_convert_items_to_string($items) { |
|
1394 | 1394 | $prepared = array(); |
1395 | 1395 | |
1396 | - foreach ( $items as $item => $quantity ) { |
|
1396 | + foreach ($items as $item => $quantity) { |
|
1397 | 1397 | $prepared[] = "$item|$quantity"; |
1398 | 1398 | } |
1399 | - return implode( ',', $prepared ); |
|
1399 | + return implode(',', $prepared); |
|
1400 | 1400 | } |
1401 | 1401 | |
1402 | 1402 | /** |
@@ -1404,21 +1404,21 @@ discard block |
||
1404 | 1404 | * |
1405 | 1405 | * Provide a label and one of $form, $items or $invoice. |
1406 | 1406 | */ |
1407 | -function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) { |
|
1408 | - $label = sanitize_text_field( $label ); |
|
1407 | +function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) { |
|
1408 | + $label = sanitize_text_field($label); |
|
1409 | 1409 | |
1410 | - if ( ! empty( $form ) ) { |
|
1411 | - $form = esc_attr( $form ); |
|
1410 | + if (!empty($form)) { |
|
1411 | + $form = esc_attr($form); |
|
1412 | 1412 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; |
1413 | 1413 | } |
1414 | 1414 | |
1415 | - if ( ! empty( $items ) ) { |
|
1416 | - $items = esc_attr( $items ); |
|
1415 | + if (!empty($items)) { |
|
1416 | + $items = esc_attr($items); |
|
1417 | 1417 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; |
1418 | 1418 | } |
1419 | 1419 | |
1420 | - if ( ! empty( $invoice ) ) { |
|
1421 | - $invoice = esc_attr( $invoice ); |
|
1420 | + if (!empty($invoice)) { |
|
1421 | + $invoice = esc_attr($invoice); |
|
1422 | 1422 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-invoice='$invoice'>$label</button>"; |
1423 | 1423 | } |
1424 | 1424 | |
@@ -1429,17 +1429,17 @@ discard block |
||
1429 | 1429 | * |
1430 | 1430 | * @param WPInv_Invoice $invoice |
1431 | 1431 | */ |
1432 | -function getpaid_the_invoice_description( $invoice ) { |
|
1432 | +function getpaid_the_invoice_description($invoice) { |
|
1433 | 1433 | $description = $invoice->get_description(); |
1434 | 1434 | |
1435 | - if ( empty( $description ) ) { |
|
1435 | + if (empty($description)) { |
|
1436 | 1436 | return; |
1437 | 1437 | } |
1438 | 1438 | |
1439 | - $description = wp_kses_post( $description ); |
|
1439 | + $description = wp_kses_post($description); |
|
1440 | 1440 | echo "<small class='getpaid-invoice-description text-dark p-2 form-text'><em>$description</em></small>"; |
1441 | 1441 | } |
1442 | -add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 ); |
|
1442 | +add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100); |
|
1443 | 1443 | |
1444 | 1444 | /** |
1445 | 1445 | * Render element on a form. |
@@ -1447,60 +1447,60 @@ discard block |
||
1447 | 1447 | * @param array $element |
1448 | 1448 | * @param GetPaid_Payment_Form $form |
1449 | 1449 | */ |
1450 | -function getpaid_payment_form_element( $element, $form ) { |
|
1450 | +function getpaid_payment_form_element($element, $form) { |
|
1451 | 1451 | |
1452 | 1452 | // Set up the args. |
1453 | - $element_type = trim( $element['type'] ); |
|
1453 | + $element_type = trim($element['type']); |
|
1454 | 1454 | $element['form'] = $form; |
1455 | - extract( $element ); |
|
1455 | + extract($element); |
|
1456 | 1456 | |
1457 | 1457 | // Try to locate the appropriate template. |
1458 | - $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" ); |
|
1458 | + $located = wpinv_locate_template("payment-forms/elements/$element_type.php"); |
|
1459 | 1459 | |
1460 | 1460 | // Abort if this is not our element. |
1461 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1461 | + if (empty($located) || !file_exists($located)) { |
|
1462 | 1462 | return; |
1463 | 1463 | } |
1464 | 1464 | |
1465 | 1465 | // Generate the class and id of the element. |
1466 | - $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) ); |
|
1467 | - $id = isset( $id ) ? $id : uniqid( 'gp' ); |
|
1466 | + $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type)); |
|
1467 | + $id = isset($id) ? $id : uniqid('gp'); |
|
1468 | 1468 | |
1469 | 1469 | // Echo the opening wrapper. |
1470 | 1470 | echo "<div class='getpaid-payment-form-element $wrapper_class'>"; |
1471 | 1471 | |
1472 | 1472 | // Fires before displaying a given element type's content. |
1473 | - do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form ); |
|
1473 | + do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form); |
|
1474 | 1474 | |
1475 | 1475 | // Include the template for the element. |
1476 | 1476 | include $located; |
1477 | 1477 | |
1478 | 1478 | // Fires after displaying a given element type's content. |
1479 | - do_action( "getpaid_payment_form_{$element_type}_element", $element, $form ); |
|
1479 | + do_action("getpaid_payment_form_{$element_type}_element", $element, $form); |
|
1480 | 1480 | |
1481 | 1481 | // Echo the closing wrapper. |
1482 | 1482 | echo '</div>'; |
1483 | 1483 | } |
1484 | -add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 ); |
|
1484 | +add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2); |
|
1485 | 1485 | |
1486 | 1486 | /** |
1487 | 1487 | * Render an element's edit page. |
1488 | 1488 | * |
1489 | 1489 | * @param WP_Post $post |
1490 | 1490 | */ |
1491 | -function getpaid_payment_form_edit_element_template( $post ) { |
|
1491 | +function getpaid_payment_form_edit_element_template($post) { |
|
1492 | 1492 | |
1493 | 1493 | // Retrieve all elements. |
1494 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1494 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1495 | 1495 | |
1496 | - foreach ( $all_elements as $element ) { |
|
1496 | + foreach ($all_elements as $element) { |
|
1497 | 1497 | |
1498 | 1498 | // Try to locate the appropriate template. |
1499 | - $element = sanitize_key( $element ); |
|
1500 | - $located = wpinv_locate_template( "payment-forms-admin/edit/$element.php" ); |
|
1499 | + $element = sanitize_key($element); |
|
1500 | + $located = wpinv_locate_template("payment-forms-admin/edit/$element.php"); |
|
1501 | 1501 | |
1502 | 1502 | // Continue if this is not our element. |
1503 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1503 | + if (empty($located) || !file_exists($located)) { |
|
1504 | 1504 | continue; |
1505 | 1505 | } |
1506 | 1506 | |
@@ -1511,7 +1511,7 @@ discard block |
||
1511 | 1511 | } |
1512 | 1512 | |
1513 | 1513 | } |
1514 | -add_action( 'getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template' ); |
|
1514 | +add_action('getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template'); |
|
1515 | 1515 | |
1516 | 1516 | /** |
1517 | 1517 | * Render an element's preview. |
@@ -1520,16 +1520,16 @@ discard block |
||
1520 | 1520 | function getpaid_payment_form_render_element_preview_template() { |
1521 | 1521 | |
1522 | 1522 | // Retrieve all elements. |
1523 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1523 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1524 | 1524 | |
1525 | - foreach ( $all_elements as $element ) { |
|
1525 | + foreach ($all_elements as $element) { |
|
1526 | 1526 | |
1527 | 1527 | // Try to locate the appropriate template. |
1528 | - $element = sanitize_key( $element ); |
|
1529 | - $located = wpinv_locate_template( "payment-forms-admin/previews/$element.php" ); |
|
1528 | + $element = sanitize_key($element); |
|
1529 | + $located = wpinv_locate_template("payment-forms-admin/previews/$element.php"); |
|
1530 | 1530 | |
1531 | 1531 | // Continue if this is not our element. |
1532 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1532 | + if (empty($located) || !file_exists($located)) { |
|
1533 | 1533 | continue; |
1534 | 1534 | } |
1535 | 1535 | |
@@ -1540,7 +1540,7 @@ discard block |
||
1540 | 1540 | } |
1541 | 1541 | |
1542 | 1542 | } |
1543 | -add_action( 'wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template' ); |
|
1543 | +add_action('wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template'); |
|
1544 | 1544 | |
1545 | 1545 | /** |
1546 | 1546 | * Shows a list of gateways that support recurring payments. |
@@ -1548,17 +1548,17 @@ discard block |
||
1548 | 1548 | function wpinv_get_recurring_gateways_text() { |
1549 | 1549 | $gateways = array(); |
1550 | 1550 | |
1551 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
1552 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
1553 | - $gateways[] = sanitize_text_field( $gateway['admin_label'] ); |
|
1551 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
1552 | + if (wpinv_gateway_support_subscription($key)) { |
|
1553 | + $gateways[] = sanitize_text_field($gateway['admin_label']); |
|
1554 | 1554 | } |
1555 | 1555 | } |
1556 | 1556 | |
1557 | - if ( empty( $gateways ) ) { |
|
1558 | - return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) ."</span>"; |
|
1557 | + if (empty($gateways)) { |
|
1558 | + return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . "</span>"; |
|
1559 | 1559 | } |
1560 | 1560 | |
1561 | - return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) ."</span>"; |
|
1561 | + return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . "</span>"; |
|
1562 | 1562 | |
1563 | 1563 | } |
1564 | 1564 | |
@@ -1568,7 +1568,7 @@ discard block |
||
1568 | 1568 | * @return GetPaid_Template |
1569 | 1569 | */ |
1570 | 1570 | function getpaid_template() { |
1571 | - return getpaid()->get( 'template' ); |
|
1571 | + return getpaid()->get('template'); |
|
1572 | 1572 | } |
1573 | 1573 | |
1574 | 1574 | /** |
@@ -1577,23 +1577,23 @@ discard block |
||
1577 | 1577 | * @param array args |
1578 | 1578 | * @return string |
1579 | 1579 | */ |
1580 | -function getpaid_paginate_links( $args ) { |
|
1580 | +function getpaid_paginate_links($args) { |
|
1581 | 1581 | |
1582 | 1582 | $args['type'] = 'array'; |
1583 | 1583 | $args['mid_size'] = 1; |
1584 | - $pages = paginate_links( $args ); |
|
1584 | + $pages = paginate_links($args); |
|
1585 | 1585 | |
1586 | - if ( ! is_array( $pages ) ) { |
|
1586 | + if (!is_array($pages)) { |
|
1587 | 1587 | return ''; |
1588 | 1588 | } |
1589 | 1589 | |
1590 | 1590 | $_pages = array(); |
1591 | - foreach ( $pages as $page ) { |
|
1592 | - $_pages[] = str_replace( 'page-numbers', 'page-link text-decoration-none', $page ); |
|
1591 | + foreach ($pages as $page) { |
|
1592 | + $_pages[] = str_replace('page-numbers', 'page-link text-decoration-none', $page); |
|
1593 | 1593 | } |
1594 | 1594 | |
1595 | 1595 | $links = "<nav>\n\t<ul class='pagination justify-content-end m-0'>\n\t\t<li class='page-item'>"; |
1596 | - $links .= join( "</li>\n\t\t<li class='page-item'>", $_pages ); |
|
1596 | + $links .= join("</li>\n\t\t<li class='page-item'>", $_pages); |
|
1597 | 1597 | $links .= "</li>\n\t</ul>\n</nav>\n"; |
1598 | 1598 | |
1599 | 1599 | return $links; |
@@ -1606,21 +1606,21 @@ discard block |
||
1606 | 1606 | * @param string state |
1607 | 1607 | * @return string |
1608 | 1608 | */ |
1609 | -function getpaid_get_states_select_markup( $country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12' ) { |
|
1609 | +function getpaid_get_states_select_markup($country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12') { |
|
1610 | 1610 | |
1611 | - $states = wpinv_get_country_states( $country ); |
|
1612 | - $uniqid = uniqid( '_' ); |
|
1611 | + $states = wpinv_get_country_states($country); |
|
1612 | + $uniqid = uniqid('_'); |
|
1613 | 1613 | |
1614 | - if ( ! empty( $states ) ) { |
|
1614 | + if (!empty($states)) { |
|
1615 | 1615 | |
1616 | - return aui()->select( array( |
|
1616 | + return aui()->select(array( |
|
1617 | 1617 | 'options' => $states, |
1618 | 1618 | 'name' => 'wpinv_state', |
1619 | 1619 | 'id' => 'wpinv_state' . $uniqid, |
1620 | - 'value' => sanitize_text_field( $state ), |
|
1620 | + 'value' => sanitize_text_field($state), |
|
1621 | 1621 | 'placeholder' => $placeholder, |
1622 | 1622 | 'required' => $required, |
1623 | - 'label' => wp_kses_post( $label ), |
|
1623 | + 'label' => wp_kses_post($label), |
|
1624 | 1624 | 'label_type' => 'vertical', |
1625 | 1625 | 'help_text' => $help_text, |
1626 | 1626 | 'class' => 'getpaid-address-field wpinv_state', |
@@ -1636,10 +1636,10 @@ discard block |
||
1636 | 1636 | 'id' => 'wpinv_state' . $uniqid, |
1637 | 1637 | 'placeholder' => $placeholder, |
1638 | 1638 | 'required' => $required, |
1639 | - 'label' => wp_kses_post( $label ), |
|
1639 | + 'label' => wp_kses_post($label), |
|
1640 | 1640 | 'label_type' => 'vertical', |
1641 | 1641 | 'help_text' => $help_text, |
1642 | - 'value' => sanitize_text_field( $state ), |
|
1642 | + 'value' => sanitize_text_field($state), |
|
1643 | 1643 | 'class' => 'getpaid-address-field wpinv_state', |
1644 | 1644 | 'wrap_class' => "$wrapper_class getpaid-address-field-wrapper__state", |
1645 | 1645 | 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state', |
@@ -1654,16 +1654,16 @@ discard block |
||
1654 | 1654 | * @param array $element |
1655 | 1655 | * @return string |
1656 | 1656 | */ |
1657 | -function getpaid_get_form_element_grid_class( $element ) { |
|
1657 | +function getpaid_get_form_element_grid_class($element) { |
|
1658 | 1658 | |
1659 | 1659 | $class = "col-12"; |
1660 | - $width = empty( $element['grid_width'] ) ? 'full' : $element['grid_width']; |
|
1660 | + $width = empty($element['grid_width']) ? 'full' : $element['grid_width']; |
|
1661 | 1661 | |
1662 | - if ( $width == 'half' ) { |
|
1662 | + if ($width == 'half') { |
|
1663 | 1663 | $class = "col-12 col-md-6"; |
1664 | 1664 | } |
1665 | 1665 | |
1666 | - if ( $width == 'third' ) { |
|
1666 | + if ($width == 'third') { |
|
1667 | 1667 | $class = "col-12 col-md-4"; |
1668 | 1668 | } |
1669 | 1669 |
@@ -179,8 +179,9 @@ discard block |
||
179 | 179 | |
180 | 180 | // Setup possible parts |
181 | 181 | $templates = array(); |
182 | - if ( isset( $name ) ) |
|
183 | - $templates[] = $slug . '-' . $name . '.php'; |
|
182 | + if ( isset( $name ) ) { |
|
183 | + $templates[] = $slug . '-' . $name . '.php'; |
|
184 | + } |
|
184 | 185 | $templates[] = $slug . '.php'; |
185 | 186 | |
186 | 187 | // Allow template parts to be filtered |
@@ -198,8 +199,9 @@ discard block |
||
198 | 199 | foreach ( (array)$template_names as $template_name ) { |
199 | 200 | |
200 | 201 | // Continue if template is empty |
201 | - if ( empty( $template_name ) ) |
|
202 | - continue; |
|
202 | + if ( empty( $template_name ) ) { |
|
203 | + continue; |
|
204 | + } |
|
203 | 205 | |
204 | 206 | // Trim off any slashes from the template name |
205 | 207 | $template_name = ltrim( $template_name, '/' ); |
@@ -218,8 +220,9 @@ discard block |
||
218 | 220 | } |
219 | 221 | } |
220 | 222 | |
221 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
222 | - load_template( $located, $require_once ); |
|
223 | + if ( ( true == $load ) && ! empty( $located ) ) { |
|
224 | + load_template( $located, $require_once ); |
|
225 | + } |
|
223 | 226 | |
224 | 227 | return $located; |
225 | 228 | } |
@@ -15,30 +15,30 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class WPInv_Discount extends GetPaid_Data { |
17 | 17 | |
18 | - /** |
|
19 | - * Which data store to load. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
18 | + /** |
|
19 | + * Which data store to load. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | 23 | protected $data_store_name = 'discount'; |
24 | 24 | |
25 | 25 | /** |
26 | - * This is the name of this object type. |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $object_type = 'discount'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Discount Data array. This is the core item data exposed in APIs. |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $data = array( |
|
39 | - 'status' => 'draft', |
|
40 | - 'version' => '', |
|
41 | - 'date_created' => null, |
|
26 | + * This is the name of this object type. |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $object_type = 'discount'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Discount Data array. This is the core item data exposed in APIs. |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $data = array( |
|
39 | + 'status' => 'draft', |
|
40 | + 'version' => '', |
|
41 | + 'date_created' => null, |
|
42 | 42 | 'date_modified' => null, |
43 | 43 | 'name' => 'no-name', |
44 | 44 | 'description' => '', |
@@ -58,144 +58,144 @@ discard block |
||
58 | 58 | 'amount' => null, |
59 | 59 | ); |
60 | 60 | |
61 | - /** |
|
62 | - * Stores meta in cache for future reads. |
|
63 | - * |
|
64 | - * A group must be set to to enable caching. |
|
65 | - * |
|
66 | - * @var string |
|
67 | - */ |
|
68 | - protected $cache_group = 'getpaid_discounts'; |
|
61 | + /** |
|
62 | + * Stores meta in cache for future reads. |
|
63 | + * |
|
64 | + * A group must be set to to enable caching. |
|
65 | + * |
|
66 | + * @var string |
|
67 | + */ |
|
68 | + protected $cache_group = 'getpaid_discounts'; |
|
69 | 69 | |
70 | 70 | /** |
71 | 71 | * Stores a reference to the original WP_Post object |
72 | 72 | * |
73 | 73 | * @var WP_Post |
74 | 74 | */ |
75 | - protected $post = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * Get the discount if ID is passed, otherwise the discount is new and empty. |
|
79 | - * |
|
80 | - * @param int|array|string|WPInv_Discount|WP_Post $discount discount data, object, ID or code. |
|
81 | - */ |
|
82 | - public function __construct( $discount = 0 ) { |
|
83 | - parent::__construct( $discount ); |
|
84 | - |
|
85 | - if ( is_numeric( $discount ) && 'wpi_discount' === get_post_type( $discount ) ) { |
|
86 | - $this->set_id( $discount ); |
|
87 | - } elseif ( $discount instanceof self ) { |
|
88 | - $this->set_id( $discount->get_id() ); |
|
89 | - } elseif ( ! empty( $discount->ID ) ) { |
|
90 | - $this->set_id( $discount->ID ); |
|
91 | - } elseif ( is_array( $discount ) ) { |
|
92 | - $this->set_props( $discount ); |
|
93 | - |
|
94 | - if ( isset( $discount['ID'] ) ) { |
|
95 | - $this->set_id( $discount['ID'] ); |
|
96 | - } |
|
97 | - |
|
98 | - } elseif ( is_scalar( $discount ) && $discount = self::get_discount_id_by_code( $discount ) ) { |
|
99 | - $this->set_id( $discount ); |
|
100 | - } else { |
|
101 | - $this->set_object_read( true ); |
|
102 | - } |
|
75 | + protected $post = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * Get the discount if ID is passed, otherwise the discount is new and empty. |
|
79 | + * |
|
80 | + * @param int|array|string|WPInv_Discount|WP_Post $discount discount data, object, ID or code. |
|
81 | + */ |
|
82 | + public function __construct( $discount = 0 ) { |
|
83 | + parent::__construct( $discount ); |
|
84 | + |
|
85 | + if ( is_numeric( $discount ) && 'wpi_discount' === get_post_type( $discount ) ) { |
|
86 | + $this->set_id( $discount ); |
|
87 | + } elseif ( $discount instanceof self ) { |
|
88 | + $this->set_id( $discount->get_id() ); |
|
89 | + } elseif ( ! empty( $discount->ID ) ) { |
|
90 | + $this->set_id( $discount->ID ); |
|
91 | + } elseif ( is_array( $discount ) ) { |
|
92 | + $this->set_props( $discount ); |
|
93 | + |
|
94 | + if ( isset( $discount['ID'] ) ) { |
|
95 | + $this->set_id( $discount['ID'] ); |
|
96 | + } |
|
97 | + |
|
98 | + } elseif ( is_scalar( $discount ) && $discount = self::get_discount_id_by_code( $discount ) ) { |
|
99 | + $this->set_id( $discount ); |
|
100 | + } else { |
|
101 | + $this->set_object_read( true ); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | // Load the datastore. |
105 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
105 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
106 | 106 | |
107 | - if ( $this->get_id() > 0 ) { |
|
107 | + if ( $this->get_id() > 0 ) { |
|
108 | 108 | $this->post = get_post( $this->get_id() ); |
109 | 109 | $this->ID = $this->get_id(); |
110 | - $this->data_store->read( $this ); |
|
110 | + $this->data_store->read( $this ); |
|
111 | + } |
|
112 | + |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Fetch a discount from the db/cache |
|
117 | + * |
|
118 | + * |
|
119 | + * @static |
|
120 | + * @param string $field The field to query against: 'ID', 'discount_code' |
|
121 | + * @param string|int $value The field value |
|
122 | + * @deprecated |
|
123 | + * @since 1.0.15 |
|
124 | + * @return array|bool array of discount details on success. False otherwise. |
|
125 | + */ |
|
126 | + public static function get_data_by( $field, $value ) { |
|
127 | + |
|
128 | + if ( 'id' == strtolower( $field ) ) { |
|
129 | + // Make sure the value is numeric to avoid casting objects, for example, |
|
130 | + // to int 1. |
|
131 | + if ( ! is_numeric( $value ) ) |
|
132 | + return false; |
|
133 | + $value = intval( $value ); |
|
134 | + if ( $value < 1 ) |
|
135 | + return false; |
|
136 | + } |
|
137 | + |
|
138 | + if ( ! $value || ! is_string( $field ) ) { |
|
139 | + return false; |
|
140 | + } |
|
141 | + |
|
142 | + $field = trim( $field ); |
|
143 | + |
|
144 | + // prepare query args |
|
145 | + switch ( strtolower( $field ) ) { |
|
146 | + case 'id': |
|
147 | + $discount_id = $value; |
|
148 | + $args = array( 'include' => array( $value ) ); |
|
149 | + break; |
|
150 | + case 'discount_code': |
|
151 | + case 'code': |
|
152 | + $value = trim( $value ); |
|
153 | + $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' ); |
|
154 | + $args = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value ); |
|
155 | + break; |
|
156 | + case 'name': |
|
157 | + $discount_id = 0; |
|
158 | + $args = array( 'name' => trim( $value ) ); |
|
159 | + break; |
|
160 | + default: |
|
161 | + $args = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value ); |
|
162 | + if ( ! is_array( $args ) ) { |
|
163 | + return apply_filters( "wpinv_discount_get_data_by_$field", false, $value ); |
|
164 | + } |
|
165 | + |
|
166 | + } |
|
167 | + |
|
168 | + // Check if there is a cached value. |
|
169 | + if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) { |
|
170 | + return $discount; |
|
171 | + } |
|
172 | + |
|
173 | + $args = array_merge( |
|
174 | + $args, |
|
175 | + array( |
|
176 | + 'post_type' => 'wpi_discount', |
|
177 | + 'posts_per_page' => 1, |
|
178 | + 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
179 | + ) |
|
180 | + ); |
|
181 | + |
|
182 | + $discount = get_posts( $args ); |
|
183 | + |
|
184 | + if( empty( $discount ) ) { |
|
185 | + return false; |
|
111 | 186 | } |
112 | 187 | |
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Fetch a discount from the db/cache |
|
117 | - * |
|
118 | - * |
|
119 | - * @static |
|
120 | - * @param string $field The field to query against: 'ID', 'discount_code' |
|
121 | - * @param string|int $value The field value |
|
122 | - * @deprecated |
|
123 | - * @since 1.0.15 |
|
124 | - * @return array|bool array of discount details on success. False otherwise. |
|
125 | - */ |
|
126 | - public static function get_data_by( $field, $value ) { |
|
127 | - |
|
128 | - if ( 'id' == strtolower( $field ) ) { |
|
129 | - // Make sure the value is numeric to avoid casting objects, for example, |
|
130 | - // to int 1. |
|
131 | - if ( ! is_numeric( $value ) ) |
|
132 | - return false; |
|
133 | - $value = intval( $value ); |
|
134 | - if ( $value < 1 ) |
|
135 | - return false; |
|
136 | - } |
|
137 | - |
|
138 | - if ( ! $value || ! is_string( $field ) ) { |
|
139 | - return false; |
|
140 | - } |
|
141 | - |
|
142 | - $field = trim( $field ); |
|
143 | - |
|
144 | - // prepare query args |
|
145 | - switch ( strtolower( $field ) ) { |
|
146 | - case 'id': |
|
147 | - $discount_id = $value; |
|
148 | - $args = array( 'include' => array( $value ) ); |
|
149 | - break; |
|
150 | - case 'discount_code': |
|
151 | - case 'code': |
|
152 | - $value = trim( $value ); |
|
153 | - $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' ); |
|
154 | - $args = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value ); |
|
155 | - break; |
|
156 | - case 'name': |
|
157 | - $discount_id = 0; |
|
158 | - $args = array( 'name' => trim( $value ) ); |
|
159 | - break; |
|
160 | - default: |
|
161 | - $args = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value ); |
|
162 | - if ( ! is_array( $args ) ) { |
|
163 | - return apply_filters( "wpinv_discount_get_data_by_$field", false, $value ); |
|
164 | - } |
|
165 | - |
|
166 | - } |
|
167 | - |
|
168 | - // Check if there is a cached value. |
|
169 | - if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) { |
|
170 | - return $discount; |
|
171 | - } |
|
172 | - |
|
173 | - $args = array_merge( |
|
174 | - $args, |
|
175 | - array( |
|
176 | - 'post_type' => 'wpi_discount', |
|
177 | - 'posts_per_page' => 1, |
|
178 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
179 | - ) |
|
180 | - ); |
|
181 | - |
|
182 | - $discount = get_posts( $args ); |
|
183 | - |
|
184 | - if( empty( $discount ) ) { |
|
185 | - return false; |
|
186 | - } |
|
187 | - |
|
188 | - $discount = $discount[0]; |
|
189 | - |
|
190 | - // Prepare the return data. |
|
191 | - $return = array( |
|
188 | + $discount = $discount[0]; |
|
189 | + |
|
190 | + // Prepare the return data. |
|
191 | + $return = array( |
|
192 | 192 | 'ID' => $discount->ID, |
193 | 193 | 'code' => get_post_meta( $discount->ID, '_wpi_discount_code', true ), |
194 | 194 | 'amount' => get_post_meta( $discount->ID, '_wpi_discount_amount', true ), |
195 | 195 | 'date_created' => $discount->post_date, |
196 | - 'date_modified' => $discount->post_modified, |
|
197 | - 'status' => $discount->post_status, |
|
198 | - 'start' => get_post_meta( $discount->ID, '_wpi_discount_start', true ), |
|
196 | + 'date_modified' => $discount->post_modified, |
|
197 | + 'status' => $discount->post_status, |
|
198 | + 'start' => get_post_meta( $discount->ID, '_wpi_discount_start', true ), |
|
199 | 199 | 'expiration' => get_post_meta( $discount->ID, '_wpi_discount_expiration', true ), |
200 | 200 | 'type' => get_post_meta( $discount->ID, '_wpi_discount_type', true ), |
201 | 201 | 'description' => $discount->post_excerpt, |
@@ -209,77 +209,77 @@ discard block |
||
209 | 209 | 'max_total' => get_post_meta( $discount->ID, '_wpi_discount_max_total', true ), |
210 | 210 | ); |
211 | 211 | |
212 | - $return = apply_filters( 'wpinv_discount_properties', $return ); |
|
213 | - |
|
214 | - // Update the cache with our data |
|
215 | - wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' ); |
|
216 | - wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' ); |
|
217 | - |
|
218 | - return $return; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Given a discount code, it returns a discount id. |
|
223 | - * |
|
224 | - * |
|
225 | - * @static |
|
226 | - * @param string $discount_code |
|
227 | - * @since 1.0.15 |
|
228 | - * @return int |
|
229 | - */ |
|
230 | - public static function get_discount_id_by_code( $discount_code ) { |
|
231 | - |
|
232 | - // Trim the code. |
|
233 | - $discount_code = trim( $discount_code ); |
|
234 | - |
|
235 | - // Ensure a value has been passed. |
|
236 | - if ( empty( $discount_code ) ) { |
|
237 | - return 0; |
|
238 | - } |
|
239 | - |
|
240 | - // Maybe retrieve from the cache. |
|
241 | - $discount_id = wp_cache_get( $discount_code, 'getpaid_discount_codes' ); |
|
242 | - if ( ! empty( $discount_id ) ) { |
|
243 | - return $discount_id; |
|
244 | - } |
|
245 | - |
|
246 | - // Fetch the first discount codes. |
|
247 | - $discounts = get_posts( |
|
248 | - array( |
|
249 | - 'meta_key' => '_wpi_discount_code', |
|
250 | - 'meta_value' => $discount_code, |
|
251 | - 'post_type' => 'wpi_discount', |
|
252 | - 'posts_per_page' => 1, |
|
253 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
254 | - 'fields' => 'ids', |
|
255 | - ) |
|
256 | - ); |
|
257 | - |
|
258 | - if ( empty( $discounts ) ) { |
|
259 | - return 0; |
|
260 | - } |
|
261 | - |
|
262 | - $discount_id = $discounts[0]; |
|
263 | - |
|
264 | - // Update the cache with our data |
|
265 | - wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' ); |
|
266 | - |
|
267 | - return $discount_id; |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * Magic method for checking the existence of a certain custom field. |
|
272 | - * |
|
273 | - * @since 1.0.15 |
|
274 | - * @access public |
|
275 | - * |
|
276 | - * @return bool Whether the given discount field is set. |
|
277 | - */ |
|
278 | - public function __isset( $key ){ |
|
279 | - return isset( $this->data[$key] ) || method_exists( $this, "get_$key"); |
|
280 | - } |
|
281 | - |
|
282 | - /* |
|
212 | + $return = apply_filters( 'wpinv_discount_properties', $return ); |
|
213 | + |
|
214 | + // Update the cache with our data |
|
215 | + wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' ); |
|
216 | + wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' ); |
|
217 | + |
|
218 | + return $return; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Given a discount code, it returns a discount id. |
|
223 | + * |
|
224 | + * |
|
225 | + * @static |
|
226 | + * @param string $discount_code |
|
227 | + * @since 1.0.15 |
|
228 | + * @return int |
|
229 | + */ |
|
230 | + public static function get_discount_id_by_code( $discount_code ) { |
|
231 | + |
|
232 | + // Trim the code. |
|
233 | + $discount_code = trim( $discount_code ); |
|
234 | + |
|
235 | + // Ensure a value has been passed. |
|
236 | + if ( empty( $discount_code ) ) { |
|
237 | + return 0; |
|
238 | + } |
|
239 | + |
|
240 | + // Maybe retrieve from the cache. |
|
241 | + $discount_id = wp_cache_get( $discount_code, 'getpaid_discount_codes' ); |
|
242 | + if ( ! empty( $discount_id ) ) { |
|
243 | + return $discount_id; |
|
244 | + } |
|
245 | + |
|
246 | + // Fetch the first discount codes. |
|
247 | + $discounts = get_posts( |
|
248 | + array( |
|
249 | + 'meta_key' => '_wpi_discount_code', |
|
250 | + 'meta_value' => $discount_code, |
|
251 | + 'post_type' => 'wpi_discount', |
|
252 | + 'posts_per_page' => 1, |
|
253 | + 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
254 | + 'fields' => 'ids', |
|
255 | + ) |
|
256 | + ); |
|
257 | + |
|
258 | + if ( empty( $discounts ) ) { |
|
259 | + return 0; |
|
260 | + } |
|
261 | + |
|
262 | + $discount_id = $discounts[0]; |
|
263 | + |
|
264 | + // Update the cache with our data |
|
265 | + wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' ); |
|
266 | + |
|
267 | + return $discount_id; |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * Magic method for checking the existence of a certain custom field. |
|
272 | + * |
|
273 | + * @since 1.0.15 |
|
274 | + * @access public |
|
275 | + * |
|
276 | + * @return bool Whether the given discount field is set. |
|
277 | + */ |
|
278 | + public function __isset( $key ){ |
|
279 | + return isset( $this->data[$key] ) || method_exists( $this, "get_$key"); |
|
280 | + } |
|
281 | + |
|
282 | + /* |
|
283 | 283 | |-------------------------------------------------------------------------- |
284 | 284 | | CRUD methods |
285 | 285 | |-------------------------------------------------------------------------- |
@@ -294,430 +294,430 @@ discard block |
||
294 | 294 | |-------------------------------------------------------------------------- |
295 | 295 | */ |
296 | 296 | |
297 | - /** |
|
298 | - * Get discount status. |
|
299 | - * |
|
300 | - * @since 1.0.19 |
|
301 | - * @param string $context View or edit context. |
|
302 | - * @return string |
|
303 | - */ |
|
304 | - public function get_status( $context = 'view' ) { |
|
305 | - return $this->get_prop( 'status', $context ); |
|
297 | + /** |
|
298 | + * Get discount status. |
|
299 | + * |
|
300 | + * @since 1.0.19 |
|
301 | + * @param string $context View or edit context. |
|
302 | + * @return string |
|
303 | + */ |
|
304 | + public function get_status( $context = 'view' ) { |
|
305 | + return $this->get_prop( 'status', $context ); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
309 | - * Get plugin version when the discount was created. |
|
310 | - * |
|
311 | - * @since 1.0.19 |
|
312 | - * @param string $context View or edit context. |
|
313 | - * @return string |
|
314 | - */ |
|
315 | - public function get_version( $context = 'view' ) { |
|
316 | - return $this->get_prop( 'version', $context ); |
|
309 | + * Get plugin version when the discount was created. |
|
310 | + * |
|
311 | + * @since 1.0.19 |
|
312 | + * @param string $context View or edit context. |
|
313 | + * @return string |
|
314 | + */ |
|
315 | + public function get_version( $context = 'view' ) { |
|
316 | + return $this->get_prop( 'version', $context ); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
320 | - * Get date when the discount was created. |
|
321 | - * |
|
322 | - * @since 1.0.19 |
|
323 | - * @param string $context View or edit context. |
|
324 | - * @return string |
|
325 | - */ |
|
326 | - public function get_date_created( $context = 'view' ) { |
|
327 | - return $this->get_prop( 'date_created', $context ); |
|
320 | + * Get date when the discount was created. |
|
321 | + * |
|
322 | + * @since 1.0.19 |
|
323 | + * @param string $context View or edit context. |
|
324 | + * @return string |
|
325 | + */ |
|
326 | + public function get_date_created( $context = 'view' ) { |
|
327 | + return $this->get_prop( 'date_created', $context ); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
331 | - * Get GMT date when the discount was created. |
|
332 | - * |
|
333 | - * @since 1.0.19 |
|
334 | - * @param string $context View or edit context. |
|
335 | - * @return string |
|
336 | - */ |
|
337 | - public function get_date_created_gmt( $context = 'view' ) { |
|
331 | + * Get GMT date when the discount was created. |
|
332 | + * |
|
333 | + * @since 1.0.19 |
|
334 | + * @param string $context View or edit context. |
|
335 | + * @return string |
|
336 | + */ |
|
337 | + public function get_date_created_gmt( $context = 'view' ) { |
|
338 | 338 | $date = $this->get_date_created( $context ); |
339 | 339 | |
340 | 340 | if ( $date ) { |
341 | 341 | $date = get_gmt_from_date( $date ); |
342 | 342 | } |
343 | - return $date; |
|
343 | + return $date; |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | /** |
347 | - * Get date when the discount was last modified. |
|
348 | - * |
|
349 | - * @since 1.0.19 |
|
350 | - * @param string $context View or edit context. |
|
351 | - * @return string |
|
352 | - */ |
|
353 | - public function get_date_modified( $context = 'view' ) { |
|
354 | - return $this->get_prop( 'date_modified', $context ); |
|
347 | + * Get date when the discount was last modified. |
|
348 | + * |
|
349 | + * @since 1.0.19 |
|
350 | + * @param string $context View or edit context. |
|
351 | + * @return string |
|
352 | + */ |
|
353 | + public function get_date_modified( $context = 'view' ) { |
|
354 | + return $this->get_prop( 'date_modified', $context ); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
358 | - * Get GMT date when the discount was last modified. |
|
359 | - * |
|
360 | - * @since 1.0.19 |
|
361 | - * @param string $context View or edit context. |
|
362 | - * @return string |
|
363 | - */ |
|
364 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
358 | + * Get GMT date when the discount was last modified. |
|
359 | + * |
|
360 | + * @since 1.0.19 |
|
361 | + * @param string $context View or edit context. |
|
362 | + * @return string |
|
363 | + */ |
|
364 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
365 | 365 | $date = $this->get_date_modified( $context ); |
366 | 366 | |
367 | 367 | if ( $date ) { |
368 | 368 | $date = get_gmt_from_date( $date ); |
369 | 369 | } |
370 | - return $date; |
|
370 | + return $date; |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
374 | - * Get the discount name. |
|
375 | - * |
|
376 | - * @since 1.0.19 |
|
377 | - * @param string $context View or edit context. |
|
378 | - * @return string |
|
379 | - */ |
|
380 | - public function get_name( $context = 'view' ) { |
|
381 | - return $this->get_prop( 'name', $context ); |
|
374 | + * Get the discount name. |
|
375 | + * |
|
376 | + * @since 1.0.19 |
|
377 | + * @param string $context View or edit context. |
|
378 | + * @return string |
|
379 | + */ |
|
380 | + public function get_name( $context = 'view' ) { |
|
381 | + return $this->get_prop( 'name', $context ); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | /** |
385 | - * Alias of self::get_name(). |
|
386 | - * |
|
387 | - * @since 1.0.19 |
|
388 | - * @param string $context View or edit context. |
|
389 | - * @return string |
|
390 | - */ |
|
391 | - public function get_title( $context = 'view' ) { |
|
392 | - return $this->get_name( $context ); |
|
385 | + * Alias of self::get_name(). |
|
386 | + * |
|
387 | + * @since 1.0.19 |
|
388 | + * @param string $context View or edit context. |
|
389 | + * @return string |
|
390 | + */ |
|
391 | + public function get_title( $context = 'view' ) { |
|
392 | + return $this->get_name( $context ); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | /** |
396 | - * Get the discount description. |
|
397 | - * |
|
398 | - * @since 1.0.19 |
|
399 | - * @param string $context View or edit context. |
|
400 | - * @return string |
|
401 | - */ |
|
402 | - public function get_description( $context = 'view' ) { |
|
403 | - return $this->get_prop( 'description', $context ); |
|
396 | + * Get the discount description. |
|
397 | + * |
|
398 | + * @since 1.0.19 |
|
399 | + * @param string $context View or edit context. |
|
400 | + * @return string |
|
401 | + */ |
|
402 | + public function get_description( $context = 'view' ) { |
|
403 | + return $this->get_prop( 'description', $context ); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | /** |
407 | - * Alias of self::get_description(). |
|
408 | - * |
|
409 | - * @since 1.0.19 |
|
410 | - * @param string $context View or edit context. |
|
411 | - * @return string |
|
412 | - */ |
|
413 | - public function get_excerpt( $context = 'view' ) { |
|
414 | - return $this->get_description( $context ); |
|
407 | + * Alias of self::get_description(). |
|
408 | + * |
|
409 | + * @since 1.0.19 |
|
410 | + * @param string $context View or edit context. |
|
411 | + * @return string |
|
412 | + */ |
|
413 | + public function get_excerpt( $context = 'view' ) { |
|
414 | + return $this->get_description( $context ); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | /** |
418 | - * Alias of self::get_description(). |
|
419 | - * |
|
420 | - * @since 1.0.19 |
|
421 | - * @param string $context View or edit context. |
|
422 | - * @return string |
|
423 | - */ |
|
424 | - public function get_summary( $context = 'view' ) { |
|
425 | - return $this->get_description( $context ); |
|
418 | + * Alias of self::get_description(). |
|
419 | + * |
|
420 | + * @since 1.0.19 |
|
421 | + * @param string $context View or edit context. |
|
422 | + * @return string |
|
423 | + */ |
|
424 | + public function get_summary( $context = 'view' ) { |
|
425 | + return $this->get_description( $context ); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | /** |
429 | - * Get the owner of the discount. |
|
430 | - * |
|
431 | - * @since 1.0.19 |
|
432 | - * @param string $context View or edit context. |
|
433 | - * @return string |
|
434 | - */ |
|
435 | - public function get_author( $context = 'view' ) { |
|
436 | - return (int) $this->get_prop( 'author', $context ); |
|
437 | - } |
|
429 | + * Get the owner of the discount. |
|
430 | + * |
|
431 | + * @since 1.0.19 |
|
432 | + * @param string $context View or edit context. |
|
433 | + * @return string |
|
434 | + */ |
|
435 | + public function get_author( $context = 'view' ) { |
|
436 | + return (int) $this->get_prop( 'author', $context ); |
|
437 | + } |
|
438 | 438 | |
439 | - /** |
|
440 | - * Get the discount code. |
|
441 | - * |
|
442 | - * @since 1.0.19 |
|
443 | - * @param string $context View or edit context. |
|
444 | - * @return string |
|
445 | - */ |
|
446 | - public function get_code( $context = 'view' ) { |
|
447 | - return $this->get_prop( 'code', $context ); |
|
448 | - } |
|
439 | + /** |
|
440 | + * Get the discount code. |
|
441 | + * |
|
442 | + * @since 1.0.19 |
|
443 | + * @param string $context View or edit context. |
|
444 | + * @return string |
|
445 | + */ |
|
446 | + public function get_code( $context = 'view' ) { |
|
447 | + return $this->get_prop( 'code', $context ); |
|
448 | + } |
|
449 | 449 | |
450 | - /** |
|
451 | - * Alias for self::get_code(). |
|
452 | - * |
|
453 | - * @since 1.0.19 |
|
454 | - * @param string $context View or edit context. |
|
455 | - * @return string |
|
456 | - */ |
|
457 | - public function get_coupon_code( $context = 'view' ) { |
|
458 | - return $this->get_code( $context ); |
|
459 | - } |
|
450 | + /** |
|
451 | + * Alias for self::get_code(). |
|
452 | + * |
|
453 | + * @since 1.0.19 |
|
454 | + * @param string $context View or edit context. |
|
455 | + * @return string |
|
456 | + */ |
|
457 | + public function get_coupon_code( $context = 'view' ) { |
|
458 | + return $this->get_code( $context ); |
|
459 | + } |
|
460 | 460 | |
461 | - /** |
|
462 | - * Alias for self::get_code(). |
|
463 | - * |
|
464 | - * @since 1.0.19 |
|
465 | - * @param string $context View or edit context. |
|
466 | - * @return string |
|
467 | - */ |
|
468 | - public function get_discount_code( $context = 'view' ) { |
|
469 | - return $this->get_code( $context ); |
|
470 | - } |
|
461 | + /** |
|
462 | + * Alias for self::get_code(). |
|
463 | + * |
|
464 | + * @since 1.0.19 |
|
465 | + * @param string $context View or edit context. |
|
466 | + * @return string |
|
467 | + */ |
|
468 | + public function get_discount_code( $context = 'view' ) { |
|
469 | + return $this->get_code( $context ); |
|
470 | + } |
|
471 | 471 | |
472 | - /** |
|
473 | - * Get the discount's amount. |
|
474 | - * |
|
475 | - * @since 1.0.19 |
|
476 | - * @param string $context View or edit context. |
|
477 | - * @return float |
|
478 | - */ |
|
479 | - public function get_amount( $context = 'view' ) { |
|
480 | - return $this->get_prop( 'amount', $context ); |
|
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * Get the discount's formated amount/rate. |
|
485 | - * |
|
486 | - * @since 1.0.19 |
|
487 | - * @return string |
|
488 | - */ |
|
489 | - public function get_formatted_amount() { |
|
490 | - |
|
491 | - if ( $this->is_type( 'flat' ) ) { |
|
492 | - $rate = wpinv_price( wpinv_format_amount( $this->get_amount() ) ); |
|
493 | - } else { |
|
494 | - $rate = $this->get_amount() . '%'; |
|
495 | - } |
|
496 | - |
|
497 | - return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() ); |
|
498 | - } |
|
472 | + /** |
|
473 | + * Get the discount's amount. |
|
474 | + * |
|
475 | + * @since 1.0.19 |
|
476 | + * @param string $context View or edit context. |
|
477 | + * @return float |
|
478 | + */ |
|
479 | + public function get_amount( $context = 'view' ) { |
|
480 | + return $this->get_prop( 'amount', $context ); |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * Get the discount's formated amount/rate. |
|
485 | + * |
|
486 | + * @since 1.0.19 |
|
487 | + * @return string |
|
488 | + */ |
|
489 | + public function get_formatted_amount() { |
|
490 | + |
|
491 | + if ( $this->is_type( 'flat' ) ) { |
|
492 | + $rate = wpinv_price( wpinv_format_amount( $this->get_amount() ) ); |
|
493 | + } else { |
|
494 | + $rate = $this->get_amount() . '%'; |
|
495 | + } |
|
496 | + |
|
497 | + return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() ); |
|
498 | + } |
|
499 | 499 | |
500 | - /** |
|
501 | - * Get the discount's start date. |
|
502 | - * |
|
503 | - * @since 1.0.19 |
|
504 | - * @param string $context View or edit context. |
|
505 | - * @return string |
|
506 | - */ |
|
507 | - public function get_start( $context = 'view' ) { |
|
508 | - return $this->get_prop( 'start', $context ); |
|
509 | - } |
|
500 | + /** |
|
501 | + * Get the discount's start date. |
|
502 | + * |
|
503 | + * @since 1.0.19 |
|
504 | + * @param string $context View or edit context. |
|
505 | + * @return string |
|
506 | + */ |
|
507 | + public function get_start( $context = 'view' ) { |
|
508 | + return $this->get_prop( 'start', $context ); |
|
509 | + } |
|
510 | 510 | |
511 | - /** |
|
512 | - * Alias for self::get_start(). |
|
513 | - * |
|
514 | - * @since 1.0.19 |
|
515 | - * @param string $context View or edit context. |
|
516 | - * @return string |
|
517 | - */ |
|
518 | - public function get_start_date( $context = 'view' ) { |
|
519 | - return $this->get_start( $context ); |
|
520 | - } |
|
511 | + /** |
|
512 | + * Alias for self::get_start(). |
|
513 | + * |
|
514 | + * @since 1.0.19 |
|
515 | + * @param string $context View or edit context. |
|
516 | + * @return string |
|
517 | + */ |
|
518 | + public function get_start_date( $context = 'view' ) { |
|
519 | + return $this->get_start( $context ); |
|
520 | + } |
|
521 | 521 | |
522 | - /** |
|
523 | - * Get the discount's expiration date. |
|
524 | - * |
|
525 | - * @since 1.0.19 |
|
526 | - * @param string $context View or edit context. |
|
527 | - * @return string |
|
528 | - */ |
|
529 | - public function get_expiration( $context = 'view' ) { |
|
530 | - return $this->get_prop( 'expiration', $context ); |
|
531 | - } |
|
522 | + /** |
|
523 | + * Get the discount's expiration date. |
|
524 | + * |
|
525 | + * @since 1.0.19 |
|
526 | + * @param string $context View or edit context. |
|
527 | + * @return string |
|
528 | + */ |
|
529 | + public function get_expiration( $context = 'view' ) { |
|
530 | + return $this->get_prop( 'expiration', $context ); |
|
531 | + } |
|
532 | 532 | |
533 | - /** |
|
534 | - * Alias for self::get_expiration(). |
|
535 | - * |
|
536 | - * @since 1.0.19 |
|
537 | - * @param string $context View or edit context. |
|
538 | - * @return string |
|
539 | - */ |
|
540 | - public function get_expiration_date( $context = 'view' ) { |
|
541 | - return $this->get_expiration( $context ); |
|
542 | - } |
|
543 | - |
|
544 | - /** |
|
545 | - * Alias for self::get_expiration(). |
|
546 | - * |
|
547 | - * @since 1.0.19 |
|
548 | - * @param string $context View or edit context. |
|
549 | - * @return string |
|
550 | - */ |
|
551 | - public function get_end_date( $context = 'view' ) { |
|
552 | - return $this->get_expiration( $context ); |
|
553 | - } |
|
533 | + /** |
|
534 | + * Alias for self::get_expiration(). |
|
535 | + * |
|
536 | + * @since 1.0.19 |
|
537 | + * @param string $context View or edit context. |
|
538 | + * @return string |
|
539 | + */ |
|
540 | + public function get_expiration_date( $context = 'view' ) { |
|
541 | + return $this->get_expiration( $context ); |
|
542 | + } |
|
543 | + |
|
544 | + /** |
|
545 | + * Alias for self::get_expiration(). |
|
546 | + * |
|
547 | + * @since 1.0.19 |
|
548 | + * @param string $context View or edit context. |
|
549 | + * @return string |
|
550 | + */ |
|
551 | + public function get_end_date( $context = 'view' ) { |
|
552 | + return $this->get_expiration( $context ); |
|
553 | + } |
|
554 | 554 | |
555 | - /** |
|
556 | - * Get the discount's type. |
|
557 | - * |
|
558 | - * @since 1.0.19 |
|
559 | - * @param string $context View or edit context. |
|
560 | - * @return string |
|
561 | - */ |
|
562 | - public function get_type( $context = 'view' ) { |
|
563 | - return $this->get_prop( 'type', $context ); |
|
564 | - } |
|
565 | - |
|
566 | - /** |
|
567 | - * Get the number of times a discount has been used. |
|
568 | - * |
|
569 | - * @since 1.0.19 |
|
570 | - * @param string $context View or edit context. |
|
571 | - * @return int |
|
572 | - */ |
|
573 | - public function get_uses( $context = 'view' ) { |
|
574 | - return (int) $this->get_prop( 'uses', $context ); |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * Get the discount's usage, i.e uses / max uses. |
|
579 | - * |
|
580 | - * @since 1.0.19 |
|
581 | - * @return string |
|
582 | - */ |
|
583 | - public function get_usage() { |
|
584 | - |
|
585 | - if ( ! $this->has_limit() ) { |
|
586 | - return $this->get_uses() . ' / ' . ' ∞'; |
|
587 | - } |
|
588 | - |
|
589 | - return $this->get_uses() . ' / ' . (int) $this->get_max_uses(); |
|
590 | - |
|
591 | - } |
|
592 | - |
|
593 | - /** |
|
594 | - * Get the maximum number of time a discount can be used. |
|
595 | - * |
|
596 | - * @since 1.0.19 |
|
597 | - * @param string $context View or edit context. |
|
598 | - * @return int |
|
599 | - */ |
|
600 | - public function get_max_uses( $context = 'view' ) { |
|
601 | - $max_uses = $this->get_prop( 'max_uses', $context ); |
|
602 | - return empty( $max_uses ) ? null : $max_uses; |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Checks if this is a single use discount or not. |
|
607 | - * |
|
608 | - * @since 1.0.19 |
|
609 | - * @param string $context View or edit context. |
|
610 | - * @return bool |
|
611 | - */ |
|
612 | - public function get_is_single_use( $context = 'view' ) { |
|
613 | - return $this->get_prop( 'is_single_use', $context ); |
|
614 | - } |
|
615 | - |
|
616 | - /** |
|
617 | - * Get the items that can be used with this discount. |
|
618 | - * |
|
619 | - * @since 1.0.19 |
|
620 | - * @param string $context View or edit context. |
|
621 | - * @return array |
|
622 | - */ |
|
623 | - public function get_items( $context = 'view' ) { |
|
624 | - return wpinv_parse_list( $this->get_prop( 'items', $context ) ); |
|
625 | - } |
|
626 | - |
|
627 | - /** |
|
628 | - * Alias for self::get_items(). |
|
629 | - * |
|
630 | - * @since 1.0.19 |
|
631 | - * @param string $context View or edit context. |
|
632 | - * @return array |
|
633 | - */ |
|
634 | - public function get_allowed_items( $context = 'view' ) { |
|
635 | - return $this->get_items( $context ); |
|
636 | - } |
|
637 | - |
|
638 | - /** |
|
639 | - * Get the items that are not allowed to use this discount. |
|
640 | - * |
|
641 | - * @since 1.0.19 |
|
642 | - * @param string $context View or edit context. |
|
643 | - * @return array |
|
644 | - */ |
|
645 | - public function get_excluded_items( $context = 'view' ) { |
|
646 | - return wpinv_parse_list( $this->get_prop( 'excluded_items', $context ) ); |
|
647 | - } |
|
648 | - |
|
649 | - /** |
|
650 | - * Checks if this is a recurring discount or not. |
|
651 | - * |
|
652 | - * @since 1.0.19 |
|
653 | - * @param string $context View or edit context. |
|
654 | - * @return int|string|bool |
|
655 | - */ |
|
656 | - public function get_is_recurring( $context = 'view' ) { |
|
657 | - return $this->get_prop( 'is_recurring', $context ); |
|
658 | - } |
|
659 | - |
|
660 | - /** |
|
661 | - * Get's the minimum total amount allowed for this discount. |
|
662 | - * |
|
663 | - * @since 1.0.19 |
|
664 | - * @param string $context View or edit context. |
|
665 | - * @return float |
|
666 | - */ |
|
667 | - public function get_min_total( $context = 'view' ) { |
|
668 | - $minimum = $this->get_prop( 'min_total', $context ); |
|
669 | - return empty( $minimum ) ? null : $minimum; |
|
670 | - } |
|
671 | - |
|
672 | - /** |
|
673 | - * Alias for self::get_min_total(). |
|
674 | - * |
|
675 | - * @since 1.0.19 |
|
676 | - * @param string $context View or edit context. |
|
677 | - * @return float |
|
678 | - */ |
|
679 | - public function get_minimum_total( $context = 'view' ) { |
|
680 | - return $this->get_min_total( $context ); |
|
681 | - } |
|
682 | - |
|
683 | - /** |
|
684 | - * Get's the maximum total amount allowed for this discount. |
|
685 | - * |
|
686 | - * @since 1.0.19 |
|
687 | - * @param string $context View or edit context. |
|
688 | - * @return float |
|
689 | - */ |
|
690 | - public function get_max_total( $context = 'view' ) { |
|
691 | - $maximum = $this->get_prop( 'max_total', $context ); |
|
692 | - return empty( $maximum ) ? null : $maximum; |
|
693 | - } |
|
694 | - |
|
695 | - /** |
|
696 | - * Alias for self::get_max_total(). |
|
697 | - * |
|
698 | - * @since 1.0.19 |
|
699 | - * @param string $context View or edit context. |
|
700 | - * @return float |
|
701 | - */ |
|
702 | - public function get_maximum_total( $context = 'view' ) { |
|
703 | - return $this->get_max_total( $context ); |
|
704 | - } |
|
705 | - |
|
706 | - /** |
|
707 | - * Magic method for accessing discount properties. |
|
708 | - * |
|
709 | - * @since 1.0.15 |
|
710 | - * @access public |
|
711 | - * |
|
712 | - * @param string $key Discount data to retrieve |
|
713 | - * @param string $context View or edit context. |
|
714 | - * @return mixed Value of the given discount property (if set). |
|
715 | - */ |
|
716 | - public function get( $key, $context = 'view' ) { |
|
555 | + /** |
|
556 | + * Get the discount's type. |
|
557 | + * |
|
558 | + * @since 1.0.19 |
|
559 | + * @param string $context View or edit context. |
|
560 | + * @return string |
|
561 | + */ |
|
562 | + public function get_type( $context = 'view' ) { |
|
563 | + return $this->get_prop( 'type', $context ); |
|
564 | + } |
|
565 | + |
|
566 | + /** |
|
567 | + * Get the number of times a discount has been used. |
|
568 | + * |
|
569 | + * @since 1.0.19 |
|
570 | + * @param string $context View or edit context. |
|
571 | + * @return int |
|
572 | + */ |
|
573 | + public function get_uses( $context = 'view' ) { |
|
574 | + return (int) $this->get_prop( 'uses', $context ); |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * Get the discount's usage, i.e uses / max uses. |
|
579 | + * |
|
580 | + * @since 1.0.19 |
|
581 | + * @return string |
|
582 | + */ |
|
583 | + public function get_usage() { |
|
584 | + |
|
585 | + if ( ! $this->has_limit() ) { |
|
586 | + return $this->get_uses() . ' / ' . ' ∞'; |
|
587 | + } |
|
588 | + |
|
589 | + return $this->get_uses() . ' / ' . (int) $this->get_max_uses(); |
|
590 | + |
|
591 | + } |
|
592 | + |
|
593 | + /** |
|
594 | + * Get the maximum number of time a discount can be used. |
|
595 | + * |
|
596 | + * @since 1.0.19 |
|
597 | + * @param string $context View or edit context. |
|
598 | + * @return int |
|
599 | + */ |
|
600 | + public function get_max_uses( $context = 'view' ) { |
|
601 | + $max_uses = $this->get_prop( 'max_uses', $context ); |
|
602 | + return empty( $max_uses ) ? null : $max_uses; |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * Checks if this is a single use discount or not. |
|
607 | + * |
|
608 | + * @since 1.0.19 |
|
609 | + * @param string $context View or edit context. |
|
610 | + * @return bool |
|
611 | + */ |
|
612 | + public function get_is_single_use( $context = 'view' ) { |
|
613 | + return $this->get_prop( 'is_single_use', $context ); |
|
614 | + } |
|
615 | + |
|
616 | + /** |
|
617 | + * Get the items that can be used with this discount. |
|
618 | + * |
|
619 | + * @since 1.0.19 |
|
620 | + * @param string $context View or edit context. |
|
621 | + * @return array |
|
622 | + */ |
|
623 | + public function get_items( $context = 'view' ) { |
|
624 | + return wpinv_parse_list( $this->get_prop( 'items', $context ) ); |
|
625 | + } |
|
626 | + |
|
627 | + /** |
|
628 | + * Alias for self::get_items(). |
|
629 | + * |
|
630 | + * @since 1.0.19 |
|
631 | + * @param string $context View or edit context. |
|
632 | + * @return array |
|
633 | + */ |
|
634 | + public function get_allowed_items( $context = 'view' ) { |
|
635 | + return $this->get_items( $context ); |
|
636 | + } |
|
637 | + |
|
638 | + /** |
|
639 | + * Get the items that are not allowed to use this discount. |
|
640 | + * |
|
641 | + * @since 1.0.19 |
|
642 | + * @param string $context View or edit context. |
|
643 | + * @return array |
|
644 | + */ |
|
645 | + public function get_excluded_items( $context = 'view' ) { |
|
646 | + return wpinv_parse_list( $this->get_prop( 'excluded_items', $context ) ); |
|
647 | + } |
|
648 | + |
|
649 | + /** |
|
650 | + * Checks if this is a recurring discount or not. |
|
651 | + * |
|
652 | + * @since 1.0.19 |
|
653 | + * @param string $context View or edit context. |
|
654 | + * @return int|string|bool |
|
655 | + */ |
|
656 | + public function get_is_recurring( $context = 'view' ) { |
|
657 | + return $this->get_prop( 'is_recurring', $context ); |
|
658 | + } |
|
659 | + |
|
660 | + /** |
|
661 | + * Get's the minimum total amount allowed for this discount. |
|
662 | + * |
|
663 | + * @since 1.0.19 |
|
664 | + * @param string $context View or edit context. |
|
665 | + * @return float |
|
666 | + */ |
|
667 | + public function get_min_total( $context = 'view' ) { |
|
668 | + $minimum = $this->get_prop( 'min_total', $context ); |
|
669 | + return empty( $minimum ) ? null : $minimum; |
|
670 | + } |
|
671 | + |
|
672 | + /** |
|
673 | + * Alias for self::get_min_total(). |
|
674 | + * |
|
675 | + * @since 1.0.19 |
|
676 | + * @param string $context View or edit context. |
|
677 | + * @return float |
|
678 | + */ |
|
679 | + public function get_minimum_total( $context = 'view' ) { |
|
680 | + return $this->get_min_total( $context ); |
|
681 | + } |
|
682 | + |
|
683 | + /** |
|
684 | + * Get's the maximum total amount allowed for this discount. |
|
685 | + * |
|
686 | + * @since 1.0.19 |
|
687 | + * @param string $context View or edit context. |
|
688 | + * @return float |
|
689 | + */ |
|
690 | + public function get_max_total( $context = 'view' ) { |
|
691 | + $maximum = $this->get_prop( 'max_total', $context ); |
|
692 | + return empty( $maximum ) ? null : $maximum; |
|
693 | + } |
|
694 | + |
|
695 | + /** |
|
696 | + * Alias for self::get_max_total(). |
|
697 | + * |
|
698 | + * @since 1.0.19 |
|
699 | + * @param string $context View or edit context. |
|
700 | + * @return float |
|
701 | + */ |
|
702 | + public function get_maximum_total( $context = 'view' ) { |
|
703 | + return $this->get_max_total( $context ); |
|
704 | + } |
|
705 | + |
|
706 | + /** |
|
707 | + * Magic method for accessing discount properties. |
|
708 | + * |
|
709 | + * @since 1.0.15 |
|
710 | + * @access public |
|
711 | + * |
|
712 | + * @param string $key Discount data to retrieve |
|
713 | + * @param string $context View or edit context. |
|
714 | + * @return mixed Value of the given discount property (if set). |
|
715 | + */ |
|
716 | + public function get( $key, $context = 'view' ) { |
|
717 | 717 | return $this->get_prop( $key, $context ); |
718 | - } |
|
718 | + } |
|
719 | 719 | |
720 | - /* |
|
720 | + /* |
|
721 | 721 | |-------------------------------------------------------------------------- |
722 | 722 | | Setters |
723 | 723 | |-------------------------------------------------------------------------- |
@@ -727,41 +727,41 @@ discard block |
||
727 | 727 | | object. |
728 | 728 | */ |
729 | 729 | |
730 | - /** |
|
731 | - * Sets discount status. |
|
732 | - * |
|
733 | - * @since 1.0.19 |
|
734 | - * @param string $status New status. |
|
735 | - * @return array details of change. |
|
736 | - */ |
|
737 | - public function set_status( $status ) { |
|
730 | + /** |
|
731 | + * Sets discount status. |
|
732 | + * |
|
733 | + * @since 1.0.19 |
|
734 | + * @param string $status New status. |
|
735 | + * @return array details of change. |
|
736 | + */ |
|
737 | + public function set_status( $status ) { |
|
738 | 738 | $old_status = $this->get_status(); |
739 | 739 | |
740 | 740 | $this->set_prop( 'status', $status ); |
741 | 741 | |
742 | - return array( |
|
743 | - 'from' => $old_status, |
|
744 | - 'to' => $status, |
|
745 | - ); |
|
742 | + return array( |
|
743 | + 'from' => $old_status, |
|
744 | + 'to' => $status, |
|
745 | + ); |
|
746 | 746 | } |
747 | 747 | |
748 | 748 | /** |
749 | - * Set plugin version when the discount was created. |
|
750 | - * |
|
751 | - * @since 1.0.19 |
|
752 | - */ |
|
753 | - public function set_version( $value ) { |
|
754 | - $this->set_prop( 'version', $value ); |
|
749 | + * Set plugin version when the discount was created. |
|
750 | + * |
|
751 | + * @since 1.0.19 |
|
752 | + */ |
|
753 | + public function set_version( $value ) { |
|
754 | + $this->set_prop( 'version', $value ); |
|
755 | 755 | } |
756 | 756 | |
757 | 757 | /** |
758 | - * Set date when the discount was created. |
|
759 | - * |
|
760 | - * @since 1.0.19 |
|
761 | - * @param string $value Value to set. |
|
758 | + * Set date when the discount was created. |
|
759 | + * |
|
760 | + * @since 1.0.19 |
|
761 | + * @param string $value Value to set. |
|
762 | 762 | * @return bool Whether or not the date was set. |
763 | - */ |
|
764 | - public function set_date_created( $value ) { |
|
763 | + */ |
|
764 | + public function set_date_created( $value ) { |
|
765 | 765 | $date = strtotime( $value ); |
766 | 766 | |
767 | 767 | if ( $date ) { |
@@ -774,13 +774,13 @@ discard block |
||
774 | 774 | } |
775 | 775 | |
776 | 776 | /** |
777 | - * Set date when the discount was last modified. |
|
778 | - * |
|
779 | - * @since 1.0.19 |
|
780 | - * @param string $value Value to set. |
|
777 | + * Set date when the discount was last modified. |
|
778 | + * |
|
779 | + * @since 1.0.19 |
|
780 | + * @param string $value Value to set. |
|
781 | 781 | * @return bool Whether or not the date was set. |
782 | - */ |
|
783 | - public function set_date_modified( $value ) { |
|
782 | + */ |
|
783 | + public function set_date_modified( $value ) { |
|
784 | 784 | $date = strtotime( $value ); |
785 | 785 | |
786 | 786 | if ( $date ) { |
@@ -793,324 +793,324 @@ discard block |
||
793 | 793 | } |
794 | 794 | |
795 | 795 | /** |
796 | - * Set the discount name. |
|
797 | - * |
|
798 | - * @since 1.0.19 |
|
799 | - * @param string $value New name. |
|
800 | - */ |
|
801 | - public function set_name( $value ) { |
|
796 | + * Set the discount name. |
|
797 | + * |
|
798 | + * @since 1.0.19 |
|
799 | + * @param string $value New name. |
|
800 | + */ |
|
801 | + public function set_name( $value ) { |
|
802 | 802 | $name = sanitize_text_field( $value ); |
803 | - $this->set_prop( 'name', $name ); |
|
803 | + $this->set_prop( 'name', $name ); |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | /** |
807 | - * Alias of self::set_name(). |
|
808 | - * |
|
809 | - * @since 1.0.19 |
|
810 | - * @param string $value New name. |
|
811 | - */ |
|
812 | - public function set_title( $value ) { |
|
813 | - $this->set_name( $value ); |
|
807 | + * Alias of self::set_name(). |
|
808 | + * |
|
809 | + * @since 1.0.19 |
|
810 | + * @param string $value New name. |
|
811 | + */ |
|
812 | + public function set_title( $value ) { |
|
813 | + $this->set_name( $value ); |
|
814 | 814 | } |
815 | 815 | |
816 | 816 | /** |
817 | - * Set the discount description. |
|
818 | - * |
|
819 | - * @since 1.0.19 |
|
820 | - * @param string $value New description. |
|
821 | - */ |
|
822 | - public function set_description( $value ) { |
|
817 | + * Set the discount description. |
|
818 | + * |
|
819 | + * @since 1.0.19 |
|
820 | + * @param string $value New description. |
|
821 | + */ |
|
822 | + public function set_description( $value ) { |
|
823 | 823 | $description = wp_kses_post( $value ); |
824 | - return $this->set_prop( 'description', $description ); |
|
824 | + return $this->set_prop( 'description', $description ); |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | /** |
828 | - * Alias of self::set_description(). |
|
829 | - * |
|
830 | - * @since 1.0.19 |
|
831 | - * @param string $value New description. |
|
832 | - */ |
|
833 | - public function set_excerpt( $value ) { |
|
834 | - $this->set_description( $value ); |
|
828 | + * Alias of self::set_description(). |
|
829 | + * |
|
830 | + * @since 1.0.19 |
|
831 | + * @param string $value New description. |
|
832 | + */ |
|
833 | + public function set_excerpt( $value ) { |
|
834 | + $this->set_description( $value ); |
|
835 | 835 | } |
836 | 836 | |
837 | 837 | /** |
838 | - * Alias of self::set_description(). |
|
839 | - * |
|
840 | - * @since 1.0.19 |
|
841 | - * @param string $value New description. |
|
842 | - */ |
|
843 | - public function set_summary( $value ) { |
|
844 | - $this->set_description( $value ); |
|
838 | + * Alias of self::set_description(). |
|
839 | + * |
|
840 | + * @since 1.0.19 |
|
841 | + * @param string $value New description. |
|
842 | + */ |
|
843 | + public function set_summary( $value ) { |
|
844 | + $this->set_description( $value ); |
|
845 | 845 | } |
846 | 846 | |
847 | 847 | /** |
848 | - * Set the owner of the discount. |
|
849 | - * |
|
850 | - * @since 1.0.19 |
|
851 | - * @param int $value New author. |
|
852 | - */ |
|
853 | - public function set_author( $value ) { |
|
854 | - $this->set_prop( 'author', (int) $value ); |
|
855 | - } |
|
848 | + * Set the owner of the discount. |
|
849 | + * |
|
850 | + * @since 1.0.19 |
|
851 | + * @param int $value New author. |
|
852 | + */ |
|
853 | + public function set_author( $value ) { |
|
854 | + $this->set_prop( 'author', (int) $value ); |
|
855 | + } |
|
856 | 856 | |
857 | - /** |
|
858 | - * Sets the discount code. |
|
859 | - * |
|
860 | - * @since 1.0.19 |
|
861 | - * @param string $value New discount code. |
|
862 | - */ |
|
863 | - public function set_code( $value ) { |
|
864 | - $code = sanitize_text_field( $value ); |
|
865 | - $this->set_prop( 'code', $code ); |
|
866 | - } |
|
857 | + /** |
|
858 | + * Sets the discount code. |
|
859 | + * |
|
860 | + * @since 1.0.19 |
|
861 | + * @param string $value New discount code. |
|
862 | + */ |
|
863 | + public function set_code( $value ) { |
|
864 | + $code = sanitize_text_field( $value ); |
|
865 | + $this->set_prop( 'code', $code ); |
|
866 | + } |
|
867 | 867 | |
868 | - /** |
|
869 | - * Alias of self::set_code(). |
|
870 | - * |
|
871 | - * @since 1.0.19 |
|
872 | - * @param string $value New discount code. |
|
873 | - */ |
|
874 | - public function set_coupon_code( $value ) { |
|
875 | - $this->set_code( $value ); |
|
876 | - } |
|
868 | + /** |
|
869 | + * Alias of self::set_code(). |
|
870 | + * |
|
871 | + * @since 1.0.19 |
|
872 | + * @param string $value New discount code. |
|
873 | + */ |
|
874 | + public function set_coupon_code( $value ) { |
|
875 | + $this->set_code( $value ); |
|
876 | + } |
|
877 | 877 | |
878 | - /** |
|
879 | - * Alias of self::set_code(). |
|
880 | - * |
|
881 | - * @since 1.0.19 |
|
882 | - * @param string $value New discount code. |
|
883 | - */ |
|
884 | - public function set_discount_code( $value ) { |
|
885 | - $this->set_code( $value ); |
|
886 | - } |
|
878 | + /** |
|
879 | + * Alias of self::set_code(). |
|
880 | + * |
|
881 | + * @since 1.0.19 |
|
882 | + * @param string $value New discount code. |
|
883 | + */ |
|
884 | + public function set_discount_code( $value ) { |
|
885 | + $this->set_code( $value ); |
|
886 | + } |
|
887 | 887 | |
888 | - /** |
|
889 | - * Sets the discount amount. |
|
890 | - * |
|
891 | - * @since 1.0.19 |
|
892 | - * @param float $value New discount code. |
|
893 | - */ |
|
894 | - public function set_amount( $value ) { |
|
895 | - $amount = floatval( wpinv_sanitize_amount( $value ) ); |
|
896 | - $this->set_prop( 'amount', $amount ); |
|
897 | - } |
|
898 | - |
|
899 | - /** |
|
900 | - * Sets the discount's start date. |
|
901 | - * |
|
902 | - * @since 1.0.19 |
|
903 | - * @param float $value New start date. |
|
904 | - */ |
|
905 | - public function set_start( $value ) { |
|
906 | - $date = strtotime( $value ); |
|
888 | + /** |
|
889 | + * Sets the discount amount. |
|
890 | + * |
|
891 | + * @since 1.0.19 |
|
892 | + * @param float $value New discount code. |
|
893 | + */ |
|
894 | + public function set_amount( $value ) { |
|
895 | + $amount = floatval( wpinv_sanitize_amount( $value ) ); |
|
896 | + $this->set_prop( 'amount', $amount ); |
|
897 | + } |
|
907 | 898 | |
908 | - if ( $date ) { |
|
909 | - $this->set_prop( 'start', date( 'Y-m-d H:i', $date ) ); |
|
910 | - return true; |
|
911 | - } |
|
899 | + /** |
|
900 | + * Sets the discount's start date. |
|
901 | + * |
|
902 | + * @since 1.0.19 |
|
903 | + * @param float $value New start date. |
|
904 | + */ |
|
905 | + public function set_start( $value ) { |
|
906 | + $date = strtotime( $value ); |
|
907 | + |
|
908 | + if ( $date ) { |
|
909 | + $this->set_prop( 'start', date( 'Y-m-d H:i', $date ) ); |
|
910 | + return true; |
|
911 | + } |
|
912 | 912 | |
913 | - $this->set_prop( 'start', '' ); |
|
913 | + $this->set_prop( 'start', '' ); |
|
914 | 914 | |
915 | 915 | return false; |
916 | - } |
|
917 | - |
|
918 | - /** |
|
919 | - * Alias of self::set_start(). |
|
920 | - * |
|
921 | - * @since 1.0.19 |
|
922 | - * @param string $value New start date. |
|
923 | - */ |
|
924 | - public function set_start_date( $value ) { |
|
925 | - $this->set_start( $value ); |
|
926 | - } |
|
927 | - |
|
928 | - /** |
|
929 | - * Sets the discount's expiration date. |
|
930 | - * |
|
931 | - * @since 1.0.19 |
|
932 | - * @param float $value New expiration date. |
|
933 | - */ |
|
934 | - public function set_expiration( $value ) { |
|
935 | - $date = strtotime( $value ); |
|
916 | + } |
|
917 | + |
|
918 | + /** |
|
919 | + * Alias of self::set_start(). |
|
920 | + * |
|
921 | + * @since 1.0.19 |
|
922 | + * @param string $value New start date. |
|
923 | + */ |
|
924 | + public function set_start_date( $value ) { |
|
925 | + $this->set_start( $value ); |
|
926 | + } |
|
927 | + |
|
928 | + /** |
|
929 | + * Sets the discount's expiration date. |
|
930 | + * |
|
931 | + * @since 1.0.19 |
|
932 | + * @param float $value New expiration date. |
|
933 | + */ |
|
934 | + public function set_expiration( $value ) { |
|
935 | + $date = strtotime( $value ); |
|
936 | 936 | |
937 | 937 | if ( $date ) { |
938 | 938 | $this->set_prop( 'expiration', date( 'Y-m-d H:i', $date ) ); |
939 | 939 | return true; |
940 | 940 | } |
941 | 941 | |
942 | - $this->set_prop( 'expiration', '' ); |
|
942 | + $this->set_prop( 'expiration', '' ); |
|
943 | 943 | return false; |
944 | - } |
|
945 | - |
|
946 | - /** |
|
947 | - * Alias of self::set_expiration(). |
|
948 | - * |
|
949 | - * @since 1.0.19 |
|
950 | - * @param string $value New expiration date. |
|
951 | - */ |
|
952 | - public function set_expiration_date( $value ) { |
|
953 | - $this->set_expiration( $value ); |
|
954 | - } |
|
955 | - |
|
956 | - /** |
|
957 | - * Alias of self::set_expiration(). |
|
958 | - * |
|
959 | - * @since 1.0.19 |
|
960 | - * @param string $value New expiration date. |
|
961 | - */ |
|
962 | - public function set_end_date( $value ) { |
|
963 | - $this->set_expiration( $value ); |
|
964 | - } |
|
965 | - |
|
966 | - /** |
|
967 | - * Sets the discount type. |
|
968 | - * |
|
969 | - * @since 1.0.19 |
|
970 | - * @param string $value New discount type. |
|
971 | - */ |
|
972 | - public function set_type( $value ) { |
|
973 | - if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) { |
|
974 | - $this->set_prop( 'type', sanitize_text_field( $value ) ); |
|
975 | - } |
|
976 | - } |
|
977 | - |
|
978 | - /** |
|
979 | - * Sets the number of times a discount has been used. |
|
980 | - * |
|
981 | - * @since 1.0.19 |
|
982 | - * @param int $value usage count. |
|
983 | - */ |
|
984 | - public function set_uses( $value ) { |
|
985 | - |
|
986 | - $value = (int) $value; |
|
987 | - |
|
988 | - if ( $value < 0 ) { |
|
989 | - $value = 0; |
|
990 | - } |
|
991 | - |
|
992 | - $this->set_prop( 'uses', (int) $value ); |
|
993 | - } |
|
994 | - |
|
995 | - /** |
|
996 | - * Sets the maximum number of times a discount can be used. |
|
997 | - * |
|
998 | - * @since 1.0.19 |
|
999 | - * @param int $value maximum usage count. |
|
1000 | - */ |
|
1001 | - public function set_max_uses( $value ) { |
|
1002 | - $this->set_prop( 'max_uses', absint( $value ) ); |
|
1003 | - } |
|
1004 | - |
|
1005 | - /** |
|
1006 | - * Sets if this is a single use discount or not. |
|
1007 | - * |
|
1008 | - * @since 1.0.19 |
|
1009 | - * @param int|bool $value is single use. |
|
1010 | - */ |
|
1011 | - public function set_is_single_use( $value ) { |
|
1012 | - $this->set_prop( 'is_single_use', (bool) $value ); |
|
1013 | - } |
|
1014 | - |
|
1015 | - /** |
|
1016 | - * Sets the items that can be used with this discount. |
|
1017 | - * |
|
1018 | - * @since 1.0.19 |
|
1019 | - * @param array $value items. |
|
1020 | - */ |
|
1021 | - public function set_items( $value ) { |
|
1022 | - $this->set_prop( 'items', wpinv_parse_list( $value ) ); |
|
1023 | - } |
|
1024 | - |
|
1025 | - /** |
|
1026 | - * Alias for self::set_items(). |
|
1027 | - * |
|
1028 | - * @since 1.0.19 |
|
1029 | - * @param array $value items. |
|
1030 | - */ |
|
1031 | - public function set_allowed_items( $value ) { |
|
1032 | - $this->set_items( $value ); |
|
1033 | - } |
|
1034 | - |
|
1035 | - /** |
|
1036 | - * Sets the items that can not be used with this discount. |
|
1037 | - * |
|
1038 | - * @since 1.0.19 |
|
1039 | - * @param array $value items. |
|
1040 | - */ |
|
1041 | - public function set_excluded_items( $value ) { |
|
1042 | - $this->set_prop( 'excluded_items', wpinv_parse_list( $value ) ); |
|
1043 | - } |
|
1044 | - |
|
1045 | - /** |
|
1046 | - * Sets if this is a recurring discounts or not. |
|
1047 | - * |
|
1048 | - * @since 1.0.19 |
|
1049 | - * @param int|bool $value is recurring. |
|
1050 | - */ |
|
1051 | - public function set_is_recurring( $value ) { |
|
1052 | - $this->set_prop( 'is_recurring', (bool) $value ); |
|
1053 | - } |
|
1054 | - |
|
1055 | - /** |
|
1056 | - * Sets the minimum total that can not be used with this discount. |
|
1057 | - * |
|
1058 | - * @since 1.0.19 |
|
1059 | - * @param float $value minimum total. |
|
1060 | - */ |
|
1061 | - public function set_min_total( $value ) { |
|
1062 | - $this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1063 | - } |
|
1064 | - |
|
1065 | - /** |
|
1066 | - * Alias for self::set_min_total(). |
|
1067 | - * |
|
1068 | - * @since 1.0.19 |
|
1069 | - * @param float $value minimum total. |
|
1070 | - */ |
|
1071 | - public function set_minimum_total( $value ) { |
|
1072 | - $this->set_min_total( $value ); |
|
1073 | - } |
|
1074 | - |
|
1075 | - /** |
|
1076 | - * Sets the maximum total that can not be used with this discount. |
|
1077 | - * |
|
1078 | - * @since 1.0.19 |
|
1079 | - * @param float $value maximum total. |
|
1080 | - */ |
|
1081 | - public function set_max_total( $value ) { |
|
1082 | - $this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1083 | - } |
|
1084 | - |
|
1085 | - /** |
|
1086 | - * Alias for self::set_max_total(). |
|
1087 | - * |
|
1088 | - * @since 1.0.19 |
|
1089 | - * @param float $value maximum total. |
|
1090 | - */ |
|
1091 | - public function set_maximum_total( $value ) { |
|
1092 | - $this->set_max_total( $value ); |
|
1093 | - } |
|
1094 | - |
|
1095 | - /** |
|
1096 | - * @deprecated |
|
1097 | - */ |
|
1098 | - public function refresh(){} |
|
1099 | - |
|
1100 | - /** |
|
1101 | - * @deprecated |
|
1102 | - * |
|
1103 | - */ |
|
1104 | - public function update_status( $status = 'publish' ){ |
|
1105 | - |
|
1106 | - if ( $this->exists() && $this->get_status() != $status ) { |
|
1107 | - $this->set_status( $status ); |
|
1108 | - $this->save(); |
|
1109 | - } |
|
1110 | - |
|
1111 | - } |
|
1112 | - |
|
1113 | - /* |
|
944 | + } |
|
945 | + |
|
946 | + /** |
|
947 | + * Alias of self::set_expiration(). |
|
948 | + * |
|
949 | + * @since 1.0.19 |
|
950 | + * @param string $value New expiration date. |
|
951 | + */ |
|
952 | + public function set_expiration_date( $value ) { |
|
953 | + $this->set_expiration( $value ); |
|
954 | + } |
|
955 | + |
|
956 | + /** |
|
957 | + * Alias of self::set_expiration(). |
|
958 | + * |
|
959 | + * @since 1.0.19 |
|
960 | + * @param string $value New expiration date. |
|
961 | + */ |
|
962 | + public function set_end_date( $value ) { |
|
963 | + $this->set_expiration( $value ); |
|
964 | + } |
|
965 | + |
|
966 | + /** |
|
967 | + * Sets the discount type. |
|
968 | + * |
|
969 | + * @since 1.0.19 |
|
970 | + * @param string $value New discount type. |
|
971 | + */ |
|
972 | + public function set_type( $value ) { |
|
973 | + if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) { |
|
974 | + $this->set_prop( 'type', sanitize_text_field( $value ) ); |
|
975 | + } |
|
976 | + } |
|
977 | + |
|
978 | + /** |
|
979 | + * Sets the number of times a discount has been used. |
|
980 | + * |
|
981 | + * @since 1.0.19 |
|
982 | + * @param int $value usage count. |
|
983 | + */ |
|
984 | + public function set_uses( $value ) { |
|
985 | + |
|
986 | + $value = (int) $value; |
|
987 | + |
|
988 | + if ( $value < 0 ) { |
|
989 | + $value = 0; |
|
990 | + } |
|
991 | + |
|
992 | + $this->set_prop( 'uses', (int) $value ); |
|
993 | + } |
|
994 | + |
|
995 | + /** |
|
996 | + * Sets the maximum number of times a discount can be used. |
|
997 | + * |
|
998 | + * @since 1.0.19 |
|
999 | + * @param int $value maximum usage count. |
|
1000 | + */ |
|
1001 | + public function set_max_uses( $value ) { |
|
1002 | + $this->set_prop( 'max_uses', absint( $value ) ); |
|
1003 | + } |
|
1004 | + |
|
1005 | + /** |
|
1006 | + * Sets if this is a single use discount or not. |
|
1007 | + * |
|
1008 | + * @since 1.0.19 |
|
1009 | + * @param int|bool $value is single use. |
|
1010 | + */ |
|
1011 | + public function set_is_single_use( $value ) { |
|
1012 | + $this->set_prop( 'is_single_use', (bool) $value ); |
|
1013 | + } |
|
1014 | + |
|
1015 | + /** |
|
1016 | + * Sets the items that can be used with this discount. |
|
1017 | + * |
|
1018 | + * @since 1.0.19 |
|
1019 | + * @param array $value items. |
|
1020 | + */ |
|
1021 | + public function set_items( $value ) { |
|
1022 | + $this->set_prop( 'items', wpinv_parse_list( $value ) ); |
|
1023 | + } |
|
1024 | + |
|
1025 | + /** |
|
1026 | + * Alias for self::set_items(). |
|
1027 | + * |
|
1028 | + * @since 1.0.19 |
|
1029 | + * @param array $value items. |
|
1030 | + */ |
|
1031 | + public function set_allowed_items( $value ) { |
|
1032 | + $this->set_items( $value ); |
|
1033 | + } |
|
1034 | + |
|
1035 | + /** |
|
1036 | + * Sets the items that can not be used with this discount. |
|
1037 | + * |
|
1038 | + * @since 1.0.19 |
|
1039 | + * @param array $value items. |
|
1040 | + */ |
|
1041 | + public function set_excluded_items( $value ) { |
|
1042 | + $this->set_prop( 'excluded_items', wpinv_parse_list( $value ) ); |
|
1043 | + } |
|
1044 | + |
|
1045 | + /** |
|
1046 | + * Sets if this is a recurring discounts or not. |
|
1047 | + * |
|
1048 | + * @since 1.0.19 |
|
1049 | + * @param int|bool $value is recurring. |
|
1050 | + */ |
|
1051 | + public function set_is_recurring( $value ) { |
|
1052 | + $this->set_prop( 'is_recurring', (bool) $value ); |
|
1053 | + } |
|
1054 | + |
|
1055 | + /** |
|
1056 | + * Sets the minimum total that can not be used with this discount. |
|
1057 | + * |
|
1058 | + * @since 1.0.19 |
|
1059 | + * @param float $value minimum total. |
|
1060 | + */ |
|
1061 | + public function set_min_total( $value ) { |
|
1062 | + $this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1063 | + } |
|
1064 | + |
|
1065 | + /** |
|
1066 | + * Alias for self::set_min_total(). |
|
1067 | + * |
|
1068 | + * @since 1.0.19 |
|
1069 | + * @param float $value minimum total. |
|
1070 | + */ |
|
1071 | + public function set_minimum_total( $value ) { |
|
1072 | + $this->set_min_total( $value ); |
|
1073 | + } |
|
1074 | + |
|
1075 | + /** |
|
1076 | + * Sets the maximum total that can not be used with this discount. |
|
1077 | + * |
|
1078 | + * @since 1.0.19 |
|
1079 | + * @param float $value maximum total. |
|
1080 | + */ |
|
1081 | + public function set_max_total( $value ) { |
|
1082 | + $this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1083 | + } |
|
1084 | + |
|
1085 | + /** |
|
1086 | + * Alias for self::set_max_total(). |
|
1087 | + * |
|
1088 | + * @since 1.0.19 |
|
1089 | + * @param float $value maximum total. |
|
1090 | + */ |
|
1091 | + public function set_maximum_total( $value ) { |
|
1092 | + $this->set_max_total( $value ); |
|
1093 | + } |
|
1094 | + |
|
1095 | + /** |
|
1096 | + * @deprecated |
|
1097 | + */ |
|
1098 | + public function refresh(){} |
|
1099 | + |
|
1100 | + /** |
|
1101 | + * @deprecated |
|
1102 | + * |
|
1103 | + */ |
|
1104 | + public function update_status( $status = 'publish' ){ |
|
1105 | + |
|
1106 | + if ( $this->exists() && $this->get_status() != $status ) { |
|
1107 | + $this->set_status( $status ); |
|
1108 | + $this->save(); |
|
1109 | + } |
|
1110 | + |
|
1111 | + } |
|
1112 | + |
|
1113 | + /* |
|
1114 | 1114 | |-------------------------------------------------------------------------- |
1115 | 1115 | | Conditionals |
1116 | 1116 | |-------------------------------------------------------------------------- |
@@ -1119,263 +1119,263 @@ discard block |
||
1119 | 1119 | | |
1120 | 1120 | */ |
1121 | 1121 | |
1122 | - /** |
|
1123 | - * Checks whether a discount exists in the database or not |
|
1124 | - * |
|
1125 | - * @since 1.0.15 |
|
1126 | - */ |
|
1127 | - public function exists(){ |
|
1128 | - $id = $this->get_id(); |
|
1129 | - return ! empty( $id ); |
|
1130 | - } |
|
1131 | - |
|
1132 | - /** |
|
1133 | - * Checks the discount type. |
|
1134 | - * |
|
1135 | - * |
|
1136 | - * @param string $type the discount type to check against |
|
1137 | - * @since 1.0.15 |
|
1138 | - * @return bool |
|
1139 | - */ |
|
1140 | - public function is_type( $type ) { |
|
1141 | - return $this->get_type() == $type; |
|
1142 | - } |
|
1143 | - |
|
1144 | - /** |
|
1145 | - * Checks whether the discount is published or not |
|
1146 | - * |
|
1147 | - * @since 1.0.15 |
|
1148 | - * @return bool |
|
1149 | - */ |
|
1150 | - public function is_active() { |
|
1151 | - return $this->get_status() == 'publish'; |
|
1152 | - } |
|
1153 | - |
|
1154 | - /** |
|
1155 | - * Checks whether the discount has max uses |
|
1156 | - * |
|
1157 | - * @since 1.0.15 |
|
1158 | - * @return bool |
|
1159 | - */ |
|
1160 | - public function has_limit() { |
|
1161 | - $limit = $this->get_max_uses(); |
|
1162 | - return ! empty( $limit ); |
|
1163 | - } |
|
1164 | - |
|
1165 | - /** |
|
1166 | - * Checks whether the discount has ever been used. |
|
1167 | - * |
|
1168 | - * @since 1.0.15 |
|
1169 | - * @return bool |
|
1170 | - */ |
|
1171 | - public function has_uses() { |
|
1172 | - return $this->get_uses() > 0; |
|
1173 | - } |
|
1174 | - |
|
1175 | - /** |
|
1176 | - * Checks whether the discount is has exided the usage limit or not |
|
1177 | - * |
|
1178 | - * @since 1.0.15 |
|
1179 | - * @return bool |
|
1180 | - */ |
|
1181 | - public function has_exceeded_limit() { |
|
1182 | - |
|
1183 | - if ( ! $this->has_limit() || ! $this->has_uses() ) { |
|
1184 | - $exceeded = false ; |
|
1185 | - } else { |
|
1186 | - $exceeded = ! ( (int) $this->get_max_uses() < $this->get_uses() ); |
|
1187 | - } |
|
1188 | - |
|
1189 | - return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->get_id(), $this, $this->get_code() ); |
|
1190 | - } |
|
1191 | - |
|
1192 | - /** |
|
1193 | - * Checks whether the discount has an expiration date. |
|
1194 | - * |
|
1195 | - * @since 1.0.15 |
|
1196 | - * @return bool |
|
1197 | - */ |
|
1198 | - public function has_expiration_date() { |
|
1199 | - $date = $this->get_expiration_date(); |
|
1200 | - return ! empty( $date ); |
|
1201 | - } |
|
1202 | - |
|
1203 | - /** |
|
1204 | - * Checks if the discount is expired |
|
1205 | - * |
|
1206 | - * @since 1.0.15 |
|
1207 | - * @return bool |
|
1208 | - */ |
|
1209 | - public function is_expired() { |
|
1210 | - $expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false; |
|
1211 | - return apply_filters( 'wpinv_is_discount_expired', $expired, $this->get_id(), $this, $this->get_code() ); |
|
1212 | - } |
|
1213 | - |
|
1214 | - /** |
|
1215 | - * Checks whether the discount has a start date. |
|
1216 | - * |
|
1217 | - * @since 1.0.15 |
|
1218 | - * @return bool |
|
1219 | - */ |
|
1220 | - public function has_start_date() { |
|
1221 | - $date = $this->get_start_date(); |
|
1222 | - return ! empty( $date ); |
|
1223 | - } |
|
1224 | - |
|
1225 | - /** |
|
1226 | - * Checks the discount start date. |
|
1227 | - * |
|
1228 | - * @since 1.0.15 |
|
1229 | - * @return bool |
|
1230 | - */ |
|
1231 | - public function has_started() { |
|
1232 | - $started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() ); |
|
1233 | - return apply_filters( 'wpinv_is_discount_started', $started, $this->get_id(), $this, $this->get_code() ); |
|
1234 | - } |
|
1235 | - |
|
1236 | - /** |
|
1237 | - * Checks the discount has allowed items or not. |
|
1238 | - * |
|
1239 | - * @since 1.0.15 |
|
1240 | - * @return bool |
|
1241 | - */ |
|
1242 | - public function has_allowed_items() { |
|
1243 | - $allowed_items = $this->get_allowed_items(); |
|
1244 | - return ! empty( $allowed_items ); |
|
1245 | - } |
|
1246 | - |
|
1247 | - /** |
|
1248 | - * Checks the discount has excluded items or not. |
|
1249 | - * |
|
1250 | - * @since 1.0.15 |
|
1251 | - * @return bool |
|
1252 | - */ |
|
1253 | - public function has_excluded_items() { |
|
1254 | - $excluded_items = $this->get_excluded_items(); |
|
1255 | - return ! empty( $excluded_items ); |
|
1256 | - } |
|
1257 | - |
|
1258 | - /** |
|
1259 | - * Check if a discount is valid for a given item id. |
|
1260 | - * |
|
1261 | - * @param int|int[] $item_ids |
|
1262 | - * @since 1.0.15 |
|
1263 | - * @return boolean |
|
1264 | - */ |
|
1265 | - public function is_valid_for_items( $item_ids ) { |
|
1266 | - |
|
1267 | - $item_ids = wp_parse_id_list( $item_ids ); |
|
1268 | - $included = array_intersect( $item_ids, $this->get_allowed_items() ); |
|
1269 | - $excluded = array_intersect( $item_ids, $this->get_excluded_items() ); |
|
1270 | - |
|
1271 | - if ( $this->has_excluded_items() && ! empty( $excluded ) ) { |
|
1272 | - return false; |
|
1273 | - } |
|
1274 | - |
|
1275 | - if ( $this->has_allowed_items() && empty( $included ) ) { |
|
1276 | - return false; |
|
1277 | - } |
|
1278 | - |
|
1279 | - return true; |
|
1280 | - } |
|
1281 | - |
|
1282 | - /** |
|
1283 | - * Check if a discount is valid for the given amount |
|
1284 | - * |
|
1285 | - * @param float $amount The amount to check against |
|
1286 | - * @since 1.0.15 |
|
1287 | - * @return boolean |
|
1288 | - */ |
|
1289 | - public function is_valid_for_amount( $amount ) { |
|
1290 | - return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount ); |
|
1291 | - } |
|
1292 | - |
|
1293 | - /** |
|
1294 | - * Checks if the minimum amount is set |
|
1295 | - * |
|
1296 | - * @since 1.0.15 |
|
1297 | - * @return boolean |
|
1298 | - */ |
|
1299 | - public function has_minimum_amount() { |
|
1300 | - $minimum = $this->get_minimum_total(); |
|
1301 | - return ! empty( $minimum ); |
|
1302 | - } |
|
1303 | - |
|
1304 | - /** |
|
1305 | - * Checks if the minimum amount is met |
|
1306 | - * |
|
1307 | - * @param float $amount The amount to check against |
|
1308 | - * @since 1.0.15 |
|
1309 | - * @return boolean |
|
1310 | - */ |
|
1311 | - public function is_minimum_amount_met( $amount ) { |
|
1312 | - $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1313 | - $min_met= ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) ); |
|
1314 | - return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
1315 | - } |
|
1316 | - |
|
1317 | - /** |
|
1318 | - * Checks if the maximum amount is set |
|
1319 | - * |
|
1320 | - * @since 1.0.15 |
|
1321 | - * @return boolean |
|
1322 | - */ |
|
1323 | - public function has_maximum_amount() { |
|
1324 | - $maximum = $this->get_maximum_total(); |
|
1325 | - return ! empty( $maximum ); |
|
1326 | - } |
|
1327 | - |
|
1328 | - /** |
|
1329 | - * Checks if the maximum amount is met |
|
1330 | - * |
|
1331 | - * @param float $amount The amount to check against |
|
1332 | - * @since 1.0.15 |
|
1333 | - * @return boolean |
|
1334 | - */ |
|
1335 | - public function is_maximum_amount_met( $amount ) { |
|
1336 | - $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1337 | - $max_met= ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) ); |
|
1338 | - return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
1339 | - } |
|
1340 | - |
|
1341 | - /** |
|
1342 | - * Checks if the discount is recurring. |
|
1343 | - * |
|
1344 | - * @since 1.0.15 |
|
1345 | - * @return boolean |
|
1346 | - */ |
|
1347 | - public function is_recurring() { |
|
1348 | - $recurring = $this->get_is_recurring(); |
|
1349 | - return ! empty( $recurring ); |
|
1350 | - } |
|
1351 | - |
|
1352 | - /** |
|
1353 | - * Checks if the discount is single use. |
|
1354 | - * |
|
1355 | - * @since 1.0.15 |
|
1356 | - * @return boolean |
|
1357 | - */ |
|
1358 | - public function is_single_use() { |
|
1359 | - $usage = $this->get_is_single_use(); |
|
1360 | - return ! empty( $usage ); |
|
1361 | - } |
|
1362 | - |
|
1363 | - /** |
|
1364 | - * Check if a discount is valid for the given user |
|
1365 | - * |
|
1366 | - * @param int|string $user |
|
1367 | - * @since 1.0.15 |
|
1368 | - * @return boolean |
|
1369 | - */ |
|
1370 | - public function is_valid_for_user( $user ) { |
|
1371 | - |
|
1372 | - // Ensure that the discount is single use. |
|
1373 | - if ( empty( $user ) || ! $this->is_single_use() ) { |
|
1374 | - return true; |
|
1375 | - } |
|
1376 | - |
|
1377 | - // Prepare the user id. |
|
1378 | - $user_id = 0; |
|
1122 | + /** |
|
1123 | + * Checks whether a discount exists in the database or not |
|
1124 | + * |
|
1125 | + * @since 1.0.15 |
|
1126 | + */ |
|
1127 | + public function exists(){ |
|
1128 | + $id = $this->get_id(); |
|
1129 | + return ! empty( $id ); |
|
1130 | + } |
|
1131 | + |
|
1132 | + /** |
|
1133 | + * Checks the discount type. |
|
1134 | + * |
|
1135 | + * |
|
1136 | + * @param string $type the discount type to check against |
|
1137 | + * @since 1.0.15 |
|
1138 | + * @return bool |
|
1139 | + */ |
|
1140 | + public function is_type( $type ) { |
|
1141 | + return $this->get_type() == $type; |
|
1142 | + } |
|
1143 | + |
|
1144 | + /** |
|
1145 | + * Checks whether the discount is published or not |
|
1146 | + * |
|
1147 | + * @since 1.0.15 |
|
1148 | + * @return bool |
|
1149 | + */ |
|
1150 | + public function is_active() { |
|
1151 | + return $this->get_status() == 'publish'; |
|
1152 | + } |
|
1153 | + |
|
1154 | + /** |
|
1155 | + * Checks whether the discount has max uses |
|
1156 | + * |
|
1157 | + * @since 1.0.15 |
|
1158 | + * @return bool |
|
1159 | + */ |
|
1160 | + public function has_limit() { |
|
1161 | + $limit = $this->get_max_uses(); |
|
1162 | + return ! empty( $limit ); |
|
1163 | + } |
|
1164 | + |
|
1165 | + /** |
|
1166 | + * Checks whether the discount has ever been used. |
|
1167 | + * |
|
1168 | + * @since 1.0.15 |
|
1169 | + * @return bool |
|
1170 | + */ |
|
1171 | + public function has_uses() { |
|
1172 | + return $this->get_uses() > 0; |
|
1173 | + } |
|
1174 | + |
|
1175 | + /** |
|
1176 | + * Checks whether the discount is has exided the usage limit or not |
|
1177 | + * |
|
1178 | + * @since 1.0.15 |
|
1179 | + * @return bool |
|
1180 | + */ |
|
1181 | + public function has_exceeded_limit() { |
|
1182 | + |
|
1183 | + if ( ! $this->has_limit() || ! $this->has_uses() ) { |
|
1184 | + $exceeded = false ; |
|
1185 | + } else { |
|
1186 | + $exceeded = ! ( (int) $this->get_max_uses() < $this->get_uses() ); |
|
1187 | + } |
|
1188 | + |
|
1189 | + return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->get_id(), $this, $this->get_code() ); |
|
1190 | + } |
|
1191 | + |
|
1192 | + /** |
|
1193 | + * Checks whether the discount has an expiration date. |
|
1194 | + * |
|
1195 | + * @since 1.0.15 |
|
1196 | + * @return bool |
|
1197 | + */ |
|
1198 | + public function has_expiration_date() { |
|
1199 | + $date = $this->get_expiration_date(); |
|
1200 | + return ! empty( $date ); |
|
1201 | + } |
|
1202 | + |
|
1203 | + /** |
|
1204 | + * Checks if the discount is expired |
|
1205 | + * |
|
1206 | + * @since 1.0.15 |
|
1207 | + * @return bool |
|
1208 | + */ |
|
1209 | + public function is_expired() { |
|
1210 | + $expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false; |
|
1211 | + return apply_filters( 'wpinv_is_discount_expired', $expired, $this->get_id(), $this, $this->get_code() ); |
|
1212 | + } |
|
1213 | + |
|
1214 | + /** |
|
1215 | + * Checks whether the discount has a start date. |
|
1216 | + * |
|
1217 | + * @since 1.0.15 |
|
1218 | + * @return bool |
|
1219 | + */ |
|
1220 | + public function has_start_date() { |
|
1221 | + $date = $this->get_start_date(); |
|
1222 | + return ! empty( $date ); |
|
1223 | + } |
|
1224 | + |
|
1225 | + /** |
|
1226 | + * Checks the discount start date. |
|
1227 | + * |
|
1228 | + * @since 1.0.15 |
|
1229 | + * @return bool |
|
1230 | + */ |
|
1231 | + public function has_started() { |
|
1232 | + $started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() ); |
|
1233 | + return apply_filters( 'wpinv_is_discount_started', $started, $this->get_id(), $this, $this->get_code() ); |
|
1234 | + } |
|
1235 | + |
|
1236 | + /** |
|
1237 | + * Checks the discount has allowed items or not. |
|
1238 | + * |
|
1239 | + * @since 1.0.15 |
|
1240 | + * @return bool |
|
1241 | + */ |
|
1242 | + public function has_allowed_items() { |
|
1243 | + $allowed_items = $this->get_allowed_items(); |
|
1244 | + return ! empty( $allowed_items ); |
|
1245 | + } |
|
1246 | + |
|
1247 | + /** |
|
1248 | + * Checks the discount has excluded items or not. |
|
1249 | + * |
|
1250 | + * @since 1.0.15 |
|
1251 | + * @return bool |
|
1252 | + */ |
|
1253 | + public function has_excluded_items() { |
|
1254 | + $excluded_items = $this->get_excluded_items(); |
|
1255 | + return ! empty( $excluded_items ); |
|
1256 | + } |
|
1257 | + |
|
1258 | + /** |
|
1259 | + * Check if a discount is valid for a given item id. |
|
1260 | + * |
|
1261 | + * @param int|int[] $item_ids |
|
1262 | + * @since 1.0.15 |
|
1263 | + * @return boolean |
|
1264 | + */ |
|
1265 | + public function is_valid_for_items( $item_ids ) { |
|
1266 | + |
|
1267 | + $item_ids = wp_parse_id_list( $item_ids ); |
|
1268 | + $included = array_intersect( $item_ids, $this->get_allowed_items() ); |
|
1269 | + $excluded = array_intersect( $item_ids, $this->get_excluded_items() ); |
|
1270 | + |
|
1271 | + if ( $this->has_excluded_items() && ! empty( $excluded ) ) { |
|
1272 | + return false; |
|
1273 | + } |
|
1274 | + |
|
1275 | + if ( $this->has_allowed_items() && empty( $included ) ) { |
|
1276 | + return false; |
|
1277 | + } |
|
1278 | + |
|
1279 | + return true; |
|
1280 | + } |
|
1281 | + |
|
1282 | + /** |
|
1283 | + * Check if a discount is valid for the given amount |
|
1284 | + * |
|
1285 | + * @param float $amount The amount to check against |
|
1286 | + * @since 1.0.15 |
|
1287 | + * @return boolean |
|
1288 | + */ |
|
1289 | + public function is_valid_for_amount( $amount ) { |
|
1290 | + return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount ); |
|
1291 | + } |
|
1292 | + |
|
1293 | + /** |
|
1294 | + * Checks if the minimum amount is set |
|
1295 | + * |
|
1296 | + * @since 1.0.15 |
|
1297 | + * @return boolean |
|
1298 | + */ |
|
1299 | + public function has_minimum_amount() { |
|
1300 | + $minimum = $this->get_minimum_total(); |
|
1301 | + return ! empty( $minimum ); |
|
1302 | + } |
|
1303 | + |
|
1304 | + /** |
|
1305 | + * Checks if the minimum amount is met |
|
1306 | + * |
|
1307 | + * @param float $amount The amount to check against |
|
1308 | + * @since 1.0.15 |
|
1309 | + * @return boolean |
|
1310 | + */ |
|
1311 | + public function is_minimum_amount_met( $amount ) { |
|
1312 | + $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1313 | + $min_met= ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) ); |
|
1314 | + return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
1315 | + } |
|
1316 | + |
|
1317 | + /** |
|
1318 | + * Checks if the maximum amount is set |
|
1319 | + * |
|
1320 | + * @since 1.0.15 |
|
1321 | + * @return boolean |
|
1322 | + */ |
|
1323 | + public function has_maximum_amount() { |
|
1324 | + $maximum = $this->get_maximum_total(); |
|
1325 | + return ! empty( $maximum ); |
|
1326 | + } |
|
1327 | + |
|
1328 | + /** |
|
1329 | + * Checks if the maximum amount is met |
|
1330 | + * |
|
1331 | + * @param float $amount The amount to check against |
|
1332 | + * @since 1.0.15 |
|
1333 | + * @return boolean |
|
1334 | + */ |
|
1335 | + public function is_maximum_amount_met( $amount ) { |
|
1336 | + $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1337 | + $max_met= ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) ); |
|
1338 | + return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
1339 | + } |
|
1340 | + |
|
1341 | + /** |
|
1342 | + * Checks if the discount is recurring. |
|
1343 | + * |
|
1344 | + * @since 1.0.15 |
|
1345 | + * @return boolean |
|
1346 | + */ |
|
1347 | + public function is_recurring() { |
|
1348 | + $recurring = $this->get_is_recurring(); |
|
1349 | + return ! empty( $recurring ); |
|
1350 | + } |
|
1351 | + |
|
1352 | + /** |
|
1353 | + * Checks if the discount is single use. |
|
1354 | + * |
|
1355 | + * @since 1.0.15 |
|
1356 | + * @return boolean |
|
1357 | + */ |
|
1358 | + public function is_single_use() { |
|
1359 | + $usage = $this->get_is_single_use(); |
|
1360 | + return ! empty( $usage ); |
|
1361 | + } |
|
1362 | + |
|
1363 | + /** |
|
1364 | + * Check if a discount is valid for the given user |
|
1365 | + * |
|
1366 | + * @param int|string $user |
|
1367 | + * @since 1.0.15 |
|
1368 | + * @return boolean |
|
1369 | + */ |
|
1370 | + public function is_valid_for_user( $user ) { |
|
1371 | + |
|
1372 | + // Ensure that the discount is single use. |
|
1373 | + if ( empty( $user ) || ! $this->is_single_use() ) { |
|
1374 | + return true; |
|
1375 | + } |
|
1376 | + |
|
1377 | + // Prepare the user id. |
|
1378 | + $user_id = 0; |
|
1379 | 1379 | if ( is_numeric( $user ) ) { |
1380 | 1380 | $user_id = absint( $user ); |
1381 | 1381 | } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
@@ -1384,117 +1384,117 @@ discard block |
||
1384 | 1384 | $user_id = $user_data->ID; |
1385 | 1385 | } |
1386 | 1386 | |
1387 | - // Ensure that we have a user. |
|
1388 | - if ( empty( $user_id ) ) { |
|
1389 | - return true; |
|
1390 | - } |
|
1387 | + // Ensure that we have a user. |
|
1388 | + if ( empty( $user_id ) ) { |
|
1389 | + return true; |
|
1390 | + } |
|
1391 | 1391 | |
1392 | - // Get all payments with matching user id. |
|
1392 | + // Get all payments with matching user id. |
|
1393 | 1393 | $payments = wpinv_get_invoices( array( 'user' => $user_id, 'limit' => false, 'paginate' => false ) ); |
1394 | - $code = strtolower( $this->get_code() ); |
|
1395 | - |
|
1396 | - // For each payment... |
|
1397 | - foreach ( $payments as $payment ) { |
|
1398 | - |
|
1399 | - // Only check for paid invoices. |
|
1400 | - if ( $payment->is_paid() && strtolower( $payment->get_discount_code() ) == $code ) { |
|
1401 | - return false; |
|
1402 | - } |
|
1403 | - |
|
1404 | - } |
|
1405 | - |
|
1406 | - return true; |
|
1407 | - } |
|
1408 | - |
|
1409 | - /** |
|
1410 | - * Deletes the discount from the database |
|
1411 | - * |
|
1412 | - * @since 1.0.15 |
|
1413 | - * @return boolean |
|
1414 | - */ |
|
1415 | - public function remove() { |
|
1416 | - return $this->delete(); |
|
1417 | - } |
|
1418 | - |
|
1419 | - /** |
|
1420 | - * Increases a discount's usage. |
|
1421 | - * |
|
1422 | - * @since 1.0.15 |
|
1423 | - * @param int $by The number of usages to increas by. |
|
1424 | - * @return int |
|
1425 | - */ |
|
1426 | - public function increase_usage( $by = 1 ) { |
|
1427 | - |
|
1428 | - // Abort if zero. |
|
1429 | - if ( empty( $by ) ) { |
|
1430 | - return; |
|
1431 | - } |
|
1432 | - |
|
1433 | - // Increase the usage. |
|
1434 | - $this->set_uses( $this->get_uses() + (int) $by ); |
|
1435 | - |
|
1436 | - // Save the discount. |
|
1437 | - $this->save(); |
|
1438 | - |
|
1439 | - // Fire relevant hooks. |
|
1440 | - if( (int) $by > 0 ) { |
|
1441 | - do_action( 'wpinv_discount_increase_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
1442 | - } else { |
|
1443 | - do_action( 'wpinv_discount_decrease_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
1444 | - } |
|
1445 | - |
|
1446 | - // Return the number of times the discount has been used. |
|
1447 | - return $this->get_uses(); |
|
1448 | - } |
|
1449 | - |
|
1450 | - /** |
|
1451 | - * Alias of self::__toString() |
|
1452 | - * |
|
1453 | - * @since 1.0.15 |
|
1454 | - * @return string|false |
|
1455 | - */ |
|
1456 | - public function get_data_as_json() { |
|
1457 | - return $this->__toString(); |
|
1458 | - } |
|
1459 | - |
|
1460 | - /** |
|
1461 | - * Returns a discount's discounted amount. |
|
1462 | - * |
|
1463 | - * @since 1.0.15 |
|
1464 | - * @param float $amount |
|
1465 | - * @return float |
|
1466 | - */ |
|
1467 | - public function get_discounted_amount( $amount ) { |
|
1468 | - |
|
1469 | - // Convert amount to float. |
|
1470 | - $amount = (float) $amount; |
|
1471 | - |
|
1472 | - // Get discount amount. |
|
1473 | - $discount_amount = $this->get_amount(); |
|
1474 | - |
|
1475 | - if ( empty( $discount_amount ) ) { |
|
1476 | - return 0; |
|
1477 | - } |
|
1478 | - |
|
1479 | - // Format the amount. |
|
1480 | - $discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) ); |
|
1394 | + $code = strtolower( $this->get_code() ); |
|
1395 | + |
|
1396 | + // For each payment... |
|
1397 | + foreach ( $payments as $payment ) { |
|
1398 | + |
|
1399 | + // Only check for paid invoices. |
|
1400 | + if ( $payment->is_paid() && strtolower( $payment->get_discount_code() ) == $code ) { |
|
1401 | + return false; |
|
1402 | + } |
|
1403 | + |
|
1404 | + } |
|
1405 | + |
|
1406 | + return true; |
|
1407 | + } |
|
1408 | + |
|
1409 | + /** |
|
1410 | + * Deletes the discount from the database |
|
1411 | + * |
|
1412 | + * @since 1.0.15 |
|
1413 | + * @return boolean |
|
1414 | + */ |
|
1415 | + public function remove() { |
|
1416 | + return $this->delete(); |
|
1417 | + } |
|
1418 | + |
|
1419 | + /** |
|
1420 | + * Increases a discount's usage. |
|
1421 | + * |
|
1422 | + * @since 1.0.15 |
|
1423 | + * @param int $by The number of usages to increas by. |
|
1424 | + * @return int |
|
1425 | + */ |
|
1426 | + public function increase_usage( $by = 1 ) { |
|
1427 | + |
|
1428 | + // Abort if zero. |
|
1429 | + if ( empty( $by ) ) { |
|
1430 | + return; |
|
1431 | + } |
|
1432 | + |
|
1433 | + // Increase the usage. |
|
1434 | + $this->set_uses( $this->get_uses() + (int) $by ); |
|
1435 | + |
|
1436 | + // Save the discount. |
|
1437 | + $this->save(); |
|
1438 | + |
|
1439 | + // Fire relevant hooks. |
|
1440 | + if( (int) $by > 0 ) { |
|
1441 | + do_action( 'wpinv_discount_increase_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
1442 | + } else { |
|
1443 | + do_action( 'wpinv_discount_decrease_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
1444 | + } |
|
1445 | + |
|
1446 | + // Return the number of times the discount has been used. |
|
1447 | + return $this->get_uses(); |
|
1448 | + } |
|
1449 | + |
|
1450 | + /** |
|
1451 | + * Alias of self::__toString() |
|
1452 | + * |
|
1453 | + * @since 1.0.15 |
|
1454 | + * @return string|false |
|
1455 | + */ |
|
1456 | + public function get_data_as_json() { |
|
1457 | + return $this->__toString(); |
|
1458 | + } |
|
1459 | + |
|
1460 | + /** |
|
1461 | + * Returns a discount's discounted amount. |
|
1462 | + * |
|
1463 | + * @since 1.0.15 |
|
1464 | + * @param float $amount |
|
1465 | + * @return float |
|
1466 | + */ |
|
1467 | + public function get_discounted_amount( $amount ) { |
|
1468 | + |
|
1469 | + // Convert amount to float. |
|
1470 | + $amount = (float) $amount; |
|
1471 | + |
|
1472 | + // Get discount amount. |
|
1473 | + $discount_amount = $this->get_amount(); |
|
1474 | + |
|
1475 | + if ( empty( $discount_amount ) ) { |
|
1476 | + return 0; |
|
1477 | + } |
|
1478 | + |
|
1479 | + // Format the amount. |
|
1480 | + $discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) ); |
|
1481 | 1481 | |
1482 | - // If this is a percentage discount. |
|
1483 | - if ( $this->is_type( 'percent' ) ) { |
|
1482 | + // If this is a percentage discount. |
|
1483 | + if ( $this->is_type( 'percent' ) ) { |
|
1484 | 1484 | $discount_amount = $amount * ( $discount_amount / 100 ); |
1485 | - } |
|
1485 | + } |
|
1486 | 1486 | |
1487 | - // Discount can not be less than zero... |
|
1488 | - if ( $discount_amount < 0 ) { |
|
1489 | - $discount_amount = 0; |
|
1490 | - } |
|
1487 | + // Discount can not be less than zero... |
|
1488 | + if ( $discount_amount < 0 ) { |
|
1489 | + $discount_amount = 0; |
|
1490 | + } |
|
1491 | 1491 | |
1492 | - // ... or more than the amount. |
|
1493 | - if ( $discount_amount > $amount ) { |
|
1494 | - $discount_amount = $amount; |
|
1495 | - } |
|
1492 | + // ... or more than the amount. |
|
1493 | + if ( $discount_amount > $amount ) { |
|
1494 | + $discount_amount = $amount; |
|
1495 | + } |
|
1496 | 1496 | |
1497 | - return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this ); |
|
1498 | - } |
|
1497 | + return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this ); |
|
1498 | + } |
|
1499 | 1499 | |
1500 | 1500 | } |