@@ -13,741 +13,741 @@ 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 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
29 | - |
|
30 | - // Invoice table columns. |
|
31 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
32 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
33 | - add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
34 | - add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
35 | - |
|
36 | - // Items table columns. |
|
37 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
38 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
39 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
40 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
41 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
42 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
43 | - |
|
44 | - // Payment forms columns. |
|
45 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
46 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
47 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
48 | - |
|
49 | - // Discount table columns. |
|
50 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
51 | - add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
52 | - |
|
53 | - // Deleting posts. |
|
54 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
55 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
56 | - |
|
57 | - add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Post updated messages. |
|
62 | - */ |
|
63 | - public static function post_updated_messages( $messages ) { |
|
64 | - global $post; |
|
65 | - |
|
66 | - $messages['wpi_discount'] = array( |
|
67 | - 0 => '', |
|
68 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
69 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
70 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
71 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
72 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
73 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
74 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
75 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
76 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
77 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
78 | - ); |
|
79 | - |
|
80 | - $messages['wpi_payment_form'] = array( |
|
81 | - 0 => '', |
|
82 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
83 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
84 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
85 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
86 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
87 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
88 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
89 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
90 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
91 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
92 | - ); |
|
93 | - |
|
94 | - return $messages; |
|
95 | - |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Post row actions. |
|
100 | - */ |
|
101 | - public static function post_row_actions( $actions, $post ) { |
|
102 | - |
|
103 | - $post = get_post( $post ); |
|
104 | - |
|
105 | - // We do not want to edit the default payment form. |
|
106 | - if ( 'wpi_payment_form' == $post->post_type ) { |
|
107 | - |
|
108 | - if ( wpinv_get_default_payment_form() === $post->ID ) { |
|
109 | - unset( $actions['trash'] ); |
|
110 | - unset( $actions['inline hide-if-no-js'] ); |
|
111 | - } |
|
112 | - |
|
113 | - $actions['duplicate'] = sprintf( |
|
114 | - '<a href="%1$s">%2$s</a>', |
|
115 | - esc_url( |
|
116 | - wp_nonce_url( |
|
117 | - add_query_arg( |
|
118 | - array( |
|
119 | - 'getpaid-admin-action' => 'duplicate_form', |
|
120 | - 'form_id' => $post->ID, |
|
121 | - ) |
|
122 | - ), |
|
123 | - 'getpaid-nonce', |
|
124 | - 'getpaid-nonce' |
|
125 | - ) |
|
126 | - ), |
|
127 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
128 | - ); |
|
129 | - |
|
130 | - $actions['reset'] = sprintf( |
|
131 | - '<a href="%1$s" style="color: #800">%2$s</a>', |
|
132 | - esc_url( |
|
133 | - wp_nonce_url( |
|
134 | - add_query_arg( |
|
135 | - array( |
|
136 | - 'getpaid-admin-action' => 'reset_form_stats', |
|
137 | - 'form_id' => $post->ID, |
|
138 | - ) |
|
139 | - ), |
|
140 | - 'getpaid-nonce', |
|
141 | - 'getpaid-nonce' |
|
142 | - ) |
|
143 | - ), |
|
144 | - esc_html( __( 'Reset Stats', 'invoicing' ) ) |
|
145 | - ); |
|
146 | - } |
|
147 | - |
|
148 | - // Link to item payment form. |
|
149 | - if ( 'wpi_item' == $post->post_type ) { |
|
150 | - |
|
151 | - if ( in_array( get_post_meta( $post->ID, '_wpinv_type', true ), array( '', 'fee', 'custom' ), true ) ) { |
|
152 | - |
|
153 | - $actions['buy'] = sprintf( |
|
154 | - '<a href="%1$s">%2$s</a>', |
|
155 | - esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ), |
|
156 | - esc_html( __( 'Buy', 'invoicing' ) ) |
|
157 | - ); |
|
158 | - |
|
159 | - } |
|
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 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
29 | + |
|
30 | + // Invoice table columns. |
|
31 | + add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
32 | + add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
33 | + add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
34 | + add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
35 | + |
|
36 | + // Items table columns. |
|
37 | + add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
38 | + add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
39 | + add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
40 | + add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
41 | + add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
42 | + add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
43 | + |
|
44 | + // Payment forms columns. |
|
45 | + add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
46 | + add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
47 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
48 | + |
|
49 | + // Discount table columns. |
|
50 | + add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
51 | + add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
52 | + |
|
53 | + // Deleting posts. |
|
54 | + add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
55 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
56 | + |
|
57 | + add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Post updated messages. |
|
62 | + */ |
|
63 | + public static function post_updated_messages( $messages ) { |
|
64 | + global $post; |
|
65 | + |
|
66 | + $messages['wpi_discount'] = array( |
|
67 | + 0 => '', |
|
68 | + 1 => __( 'Discount updated.', 'invoicing' ), |
|
69 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
70 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
71 | + 4 => __( 'Discount updated.', 'invoicing' ), |
|
72 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
73 | + 6 => __( 'Discount updated.', 'invoicing' ), |
|
74 | + 7 => __( 'Discount saved.', 'invoicing' ), |
|
75 | + 8 => __( 'Discount submitted.', 'invoicing' ), |
|
76 | + 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
77 | + 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
78 | + ); |
|
79 | + |
|
80 | + $messages['wpi_payment_form'] = array( |
|
81 | + 0 => '', |
|
82 | + 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
83 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
84 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
85 | + 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
86 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
87 | + 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
88 | + 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
89 | + 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
90 | + 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
91 | + 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
92 | + ); |
|
93 | + |
|
94 | + return $messages; |
|
95 | + |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Post row actions. |
|
100 | + */ |
|
101 | + public static function post_row_actions( $actions, $post ) { |
|
102 | + |
|
103 | + $post = get_post( $post ); |
|
104 | + |
|
105 | + // We do not want to edit the default payment form. |
|
106 | + if ( 'wpi_payment_form' == $post->post_type ) { |
|
107 | + |
|
108 | + if ( wpinv_get_default_payment_form() === $post->ID ) { |
|
109 | + unset( $actions['trash'] ); |
|
110 | + unset( $actions['inline hide-if-no-js'] ); |
|
111 | + } |
|
112 | + |
|
113 | + $actions['duplicate'] = sprintf( |
|
114 | + '<a href="%1$s">%2$s</a>', |
|
115 | + esc_url( |
|
116 | + wp_nonce_url( |
|
117 | + add_query_arg( |
|
118 | + array( |
|
119 | + 'getpaid-admin-action' => 'duplicate_form', |
|
120 | + 'form_id' => $post->ID, |
|
121 | + ) |
|
122 | + ), |
|
123 | + 'getpaid-nonce', |
|
124 | + 'getpaid-nonce' |
|
125 | + ) |
|
126 | + ), |
|
127 | + esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
128 | + ); |
|
129 | + |
|
130 | + $actions['reset'] = sprintf( |
|
131 | + '<a href="%1$s" style="color: #800">%2$s</a>', |
|
132 | + esc_url( |
|
133 | + wp_nonce_url( |
|
134 | + add_query_arg( |
|
135 | + array( |
|
136 | + 'getpaid-admin-action' => 'reset_form_stats', |
|
137 | + 'form_id' => $post->ID, |
|
138 | + ) |
|
139 | + ), |
|
140 | + 'getpaid-nonce', |
|
141 | + 'getpaid-nonce' |
|
142 | + ) |
|
143 | + ), |
|
144 | + esc_html( __( 'Reset Stats', 'invoicing' ) ) |
|
145 | + ); |
|
146 | + } |
|
147 | + |
|
148 | + // Link to item payment form. |
|
149 | + if ( 'wpi_item' == $post->post_type ) { |
|
150 | + |
|
151 | + if ( in_array( get_post_meta( $post->ID, '_wpinv_type', true ), array( '', 'fee', 'custom' ), true ) ) { |
|
152 | + |
|
153 | + $actions['buy'] = sprintf( |
|
154 | + '<a href="%1$s">%2$s</a>', |
|
155 | + esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ), |
|
156 | + esc_html( __( 'Buy', 'invoicing' ) ) |
|
157 | + ); |
|
158 | + |
|
159 | + } |
|
160 | 160 | } |
161 | 161 | |
162 | - return $actions; |
|
163 | - } |
|
162 | + return $actions; |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
165 | + /** |
|
166 | 166 | * Remove bulk edit option from admin side quote listing |
167 | 167 | * |
168 | 168 | * @since 1.0.0 |
169 | 169 | * @param array $actions post actions |
170 | - * @param WP_Post $post |
|
170 | + * @param WP_Post $post |
|
171 | 171 | * @return array $actions actions without edit option |
172 | 172 | */ |
173 | 173 | public static function filter_invoice_row_actions( $actions, $post ) { |
174 | 174 | |
175 | 175 | if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
176 | 176 | |
177 | - $actions = array(); |
|
178 | - $invoice = new WPInv_Invoice( $post ); |
|
179 | - |
|
180 | - $actions['edit'] = sprintf( |
|
181 | - '<a href="%1$s">%2$s</a>', |
|
182 | - esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
183 | - esc_html( __( 'Edit', 'invoicing' ) ) |
|
184 | - ); |
|
185 | - |
|
186 | - if ( ! $invoice->is_draft() ) { |
|
187 | - |
|
188 | - $actions['view'] = sprintf( |
|
189 | - '<a href="%1$s">%2$s</a>', |
|
190 | - esc_url( $invoice->get_view_url() ), |
|
191 | - sprintf( |
|
192 | - // translators: %s is the invoice type |
|
193 | - esc_html__( 'View %s', 'invoicing' ), |
|
194 | - getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
195 | - ) |
|
196 | - ); |
|
197 | - |
|
198 | - $actions['send'] = sprintf( |
|
199 | - '<a href="%1$s">%2$s</a>', |
|
200 | - esc_url( |
|
201 | - wp_nonce_url( |
|
202 | - add_query_arg( |
|
203 | - array( |
|
204 | - 'getpaid-admin-action' => 'send_invoice', |
|
205 | - 'invoice_id' => $invoice->get_id(), |
|
206 | - ) |
|
207 | - ), |
|
208 | - 'getpaid-nonce', |
|
209 | - 'getpaid-nonce' |
|
210 | - ) |
|
211 | - ), |
|
212 | - esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
213 | - ); |
|
214 | - |
|
215 | - } |
|
216 | - |
|
217 | - $actions['duplicate'] = sprintf( |
|
218 | - '<a href="%1$s">%2$s</a>', |
|
219 | - esc_url( |
|
220 | - wp_nonce_url( |
|
221 | - add_query_arg( |
|
222 | - array( |
|
223 | - 'getpaid-admin-action' => 'duplicate_invoice', |
|
224 | - 'invoice_id' => $post->ID, |
|
225 | - ) |
|
226 | - ), |
|
227 | - 'getpaid-nonce', |
|
228 | - 'getpaid-nonce' |
|
229 | - ) |
|
230 | - ), |
|
231 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
232 | - ); |
|
177 | + $actions = array(); |
|
178 | + $invoice = new WPInv_Invoice( $post ); |
|
179 | + |
|
180 | + $actions['edit'] = sprintf( |
|
181 | + '<a href="%1$s">%2$s</a>', |
|
182 | + esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
183 | + esc_html( __( 'Edit', 'invoicing' ) ) |
|
184 | + ); |
|
185 | + |
|
186 | + if ( ! $invoice->is_draft() ) { |
|
187 | + |
|
188 | + $actions['view'] = sprintf( |
|
189 | + '<a href="%1$s">%2$s</a>', |
|
190 | + esc_url( $invoice->get_view_url() ), |
|
191 | + sprintf( |
|
192 | + // translators: %s is the invoice type |
|
193 | + esc_html__( 'View %s', 'invoicing' ), |
|
194 | + getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
195 | + ) |
|
196 | + ); |
|
197 | + |
|
198 | + $actions['send'] = sprintf( |
|
199 | + '<a href="%1$s">%2$s</a>', |
|
200 | + esc_url( |
|
201 | + wp_nonce_url( |
|
202 | + add_query_arg( |
|
203 | + array( |
|
204 | + 'getpaid-admin-action' => 'send_invoice', |
|
205 | + 'invoice_id' => $invoice->get_id(), |
|
206 | + ) |
|
207 | + ), |
|
208 | + 'getpaid-nonce', |
|
209 | + 'getpaid-nonce' |
|
210 | + ) |
|
211 | + ), |
|
212 | + esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
213 | + ); |
|
214 | + |
|
215 | + } |
|
216 | + |
|
217 | + $actions['duplicate'] = sprintf( |
|
218 | + '<a href="%1$s">%2$s</a>', |
|
219 | + esc_url( |
|
220 | + wp_nonce_url( |
|
221 | + add_query_arg( |
|
222 | + array( |
|
223 | + 'getpaid-admin-action' => 'duplicate_invoice', |
|
224 | + 'invoice_id' => $post->ID, |
|
225 | + ) |
|
226 | + ), |
|
227 | + 'getpaid-nonce', |
|
228 | + 'getpaid-nonce' |
|
229 | + ) |
|
230 | + ), |
|
231 | + esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
232 | + ); |
|
233 | 233 | |
234 | 234 | } |
235 | 235 | |
236 | 236 | return $actions; |
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Returns an array of invoice table columns. |
|
241 | - */ |
|
242 | - public static function invoice_columns( $columns ) { |
|
243 | - |
|
244 | - $columns = array( |
|
245 | - 'cb' => $columns['cb'], |
|
246 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
247 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
248 | - 'invoice_date' => __( 'Created', 'invoicing' ), |
|
249 | - 'payment_date' => __( 'Completed', 'invoicing' ), |
|
250 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
251 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
252 | - 'status' => __( 'Status', 'invoicing' ), |
|
253 | - ); |
|
254 | - |
|
255 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Displays invoice table columns. |
|
260 | - */ |
|
261 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
262 | - |
|
263 | - $invoice = new WPInv_Invoice( $post_id ); |
|
264 | - |
|
265 | - switch ( $column_name ) { |
|
266 | - |
|
267 | - case 'invoice_date': |
|
268 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
269 | - $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
270 | - echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
271 | - break; |
|
272 | - |
|
273 | - case 'payment_date': |
|
274 | - if ( $invoice->is_paid() ) { |
|
275 | - $date_time = esc_attr( $invoice->get_completed_date() ); |
|
276 | - $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
277 | - echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
278 | - } else { |
|
279 | - echo '—'; |
|
280 | - } |
|
281 | - |
|
282 | - break; |
|
283 | - |
|
284 | - case 'amount': |
|
285 | - $amount = $invoice->get_total(); |
|
286 | - $formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) ); |
|
287 | - |
|
288 | - if ( $invoice->is_refunded() ) { |
|
289 | - $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
290 | - echo wp_kses_post( "<del>$formated_amount</del> <ins>$refunded_amount</ins>" ); |
|
291 | - } else { |
|
292 | - |
|
293 | - $discount = $invoice->get_total_discount(); |
|
294 | - |
|
295 | - if ( ! empty( $discount ) ) { |
|
296 | - $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
297 | - echo wp_kses_post( "<del>$new_amount</del> <ins>$formated_amount</ins>" ); |
|
298 | - } else { |
|
299 | - echo wp_kses_post( $formated_amount ); |
|
300 | - } |
|
301 | - } |
|
302 | - |
|
303 | - break; |
|
304 | - |
|
305 | - case 'status': |
|
306 | - $status = esc_html( $invoice->get_status() ); |
|
307 | - $status_label = esc_html( $invoice->get_status_nicename() ); |
|
308 | - |
|
309 | - // If it is paid, show the gateway title. |
|
310 | - if ( $invoice->is_paid() ) { |
|
311 | - $gateway = esc_html( $invoice->get_gateway_title() ); |
|
312 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) ); |
|
313 | - |
|
314 | - echo wp_kses_post( "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>" ); |
|
315 | - } else { |
|
316 | - echo wp_kses_post( "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>" ); |
|
317 | - } |
|
318 | - |
|
319 | - // If it is not paid, display the overdue and view status. |
|
320 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
321 | - |
|
322 | - // Invoice view status. |
|
323 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
324 | - echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
325 | - } else { |
|
326 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
327 | - } |
|
328 | - |
|
329 | - // Display the overview status. |
|
330 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
331 | - $due_date = $invoice->get_due_date(); |
|
332 | - $fomatted = getpaid_format_date( $due_date ); |
|
333 | - |
|
334 | - if ( ! empty( $fomatted ) ) { |
|
335 | - $date = wp_sprintf( |
|
336 | - // translators: %s is the due date. |
|
337 | - __( 'Due %s', 'invoicing' ), |
|
338 | - $fomatted |
|
339 | - ); |
|
340 | - echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" ); |
|
341 | - } |
|
342 | - } |
|
343 | - } |
|
344 | - |
|
345 | - break; |
|
346 | - |
|
347 | - case 'recurring': |
|
348 | - if ( $invoice->is_recurring() ) { |
|
349 | - echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
350 | - } else { |
|
351 | - echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
352 | - } |
|
353 | - break; |
|
354 | - |
|
355 | - case 'number': |
|
356 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
357 | - $invoice_number = esc_html( $invoice->get_number() ); |
|
358 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
359 | - |
|
360 | - echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" ); |
|
361 | - |
|
362 | - do_action( 'getpaid_admin_table_invoice_number_column', $invoice ); |
|
363 | - break; |
|
364 | - |
|
365 | - case 'customer': |
|
366 | - $customer_name = $invoice->get_user_full_name(); |
|
367 | - |
|
368 | - if ( empty( $customer_name ) ) { |
|
369 | - $customer_name = $invoice->get_email(); |
|
370 | - } |
|
371 | - |
|
372 | - if ( ! empty( $customer_name ) ) { |
|
373 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
374 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
375 | - echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" ); |
|
376 | - } else { |
|
377 | - echo '<div>—</div>'; |
|
378 | - } |
|
379 | - |
|
380 | - break; |
|
381 | - |
|
382 | - } |
|
383 | - |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Displays invoice bulk actions. |
|
388 | - */ |
|
389 | - public static function invoice_bulk_actions( $actions ) { |
|
390 | - $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
391 | - return $actions; |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * Processes invoice bulk actions. |
|
396 | - */ |
|
397 | - public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
398 | - |
|
399 | - if ( 'resend-invoice' === $action ) { |
|
400 | - foreach ( $post_ids as $post_id ) { |
|
401 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
402 | - } |
|
403 | - } |
|
404 | - |
|
405 | - return $redirect_url; |
|
406 | - |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Returns an array of payment forms table columns. |
|
411 | - */ |
|
412 | - public static function payment_form_columns( $columns ) { |
|
413 | - |
|
414 | - $columns = array( |
|
415 | - 'cb' => $columns['cb'], |
|
416 | - 'title' => __( 'Name', 'invoicing' ), |
|
417 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
418 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
419 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
420 | - 'items' => __( 'Items', 'invoicing' ), |
|
421 | - 'date' => __( 'Date', 'invoicing' ), |
|
422 | - ); |
|
423 | - |
|
424 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
425 | - |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * Displays payment form table columns. |
|
430 | - */ |
|
431 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
432 | - |
|
433 | - // Retrieve the payment form. |
|
434 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
435 | - |
|
436 | - switch ( $column_name ) { |
|
437 | - |
|
438 | - case 'earnings': |
|
439 | - echo wp_kses_post( wpinv_price( $form->get_earned() ) ); |
|
440 | - break; |
|
441 | - |
|
442 | - case 'refunds': |
|
443 | - echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
444 | - break; |
|
445 | - |
|
446 | - case 'refunds': |
|
447 | - echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
448 | - break; |
|
449 | - |
|
450 | - case 'shortcode': |
|
451 | - if ( $form->is_default() ) { |
|
452 | - echo '—'; |
|
453 | - } else { |
|
454 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
455 | - } |
|
456 | - |
|
457 | - break; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Returns an array of invoice table columns. |
|
241 | + */ |
|
242 | + public static function invoice_columns( $columns ) { |
|
243 | + |
|
244 | + $columns = array( |
|
245 | + 'cb' => $columns['cb'], |
|
246 | + 'number' => __( 'Invoice', 'invoicing' ), |
|
247 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
248 | + 'invoice_date' => __( 'Created', 'invoicing' ), |
|
249 | + 'payment_date' => __( 'Completed', 'invoicing' ), |
|
250 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
251 | + 'recurring' => __( 'Recurring', 'invoicing' ), |
|
252 | + 'status' => __( 'Status', 'invoicing' ), |
|
253 | + ); |
|
254 | + |
|
255 | + return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Displays invoice table columns. |
|
260 | + */ |
|
261 | + public static function display_invoice_columns( $column_name, $post_id ) { |
|
262 | + |
|
263 | + $invoice = new WPInv_Invoice( $post_id ); |
|
264 | + |
|
265 | + switch ( $column_name ) { |
|
266 | + |
|
267 | + case 'invoice_date': |
|
268 | + $date_time = esc_attr( $invoice->get_created_date() ); |
|
269 | + $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
270 | + echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
271 | + break; |
|
272 | + |
|
273 | + case 'payment_date': |
|
274 | + if ( $invoice->is_paid() ) { |
|
275 | + $date_time = esc_attr( $invoice->get_completed_date() ); |
|
276 | + $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
277 | + echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
278 | + } else { |
|
279 | + echo '—'; |
|
280 | + } |
|
281 | + |
|
282 | + break; |
|
283 | + |
|
284 | + case 'amount': |
|
285 | + $amount = $invoice->get_total(); |
|
286 | + $formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) ); |
|
287 | + |
|
288 | + if ( $invoice->is_refunded() ) { |
|
289 | + $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
290 | + echo wp_kses_post( "<del>$formated_amount</del> <ins>$refunded_amount</ins>" ); |
|
291 | + } else { |
|
292 | + |
|
293 | + $discount = $invoice->get_total_discount(); |
|
294 | + |
|
295 | + if ( ! empty( $discount ) ) { |
|
296 | + $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
297 | + echo wp_kses_post( "<del>$new_amount</del> <ins>$formated_amount</ins>" ); |
|
298 | + } else { |
|
299 | + echo wp_kses_post( $formated_amount ); |
|
300 | + } |
|
301 | + } |
|
302 | + |
|
303 | + break; |
|
304 | + |
|
305 | + case 'status': |
|
306 | + $status = esc_html( $invoice->get_status() ); |
|
307 | + $status_label = esc_html( $invoice->get_status_nicename() ); |
|
308 | + |
|
309 | + // If it is paid, show the gateway title. |
|
310 | + if ( $invoice->is_paid() ) { |
|
311 | + $gateway = esc_html( $invoice->get_gateway_title() ); |
|
312 | + $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) ); |
|
313 | + |
|
314 | + echo wp_kses_post( "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>" ); |
|
315 | + } else { |
|
316 | + echo wp_kses_post( "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>" ); |
|
317 | + } |
|
318 | + |
|
319 | + // If it is not paid, display the overdue and view status. |
|
320 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
321 | + |
|
322 | + // Invoice view status. |
|
323 | + if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
324 | + echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
325 | + } else { |
|
326 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
327 | + } |
|
328 | + |
|
329 | + // Display the overview status. |
|
330 | + if ( wpinv_get_option( 'overdue_active' ) ) { |
|
331 | + $due_date = $invoice->get_due_date(); |
|
332 | + $fomatted = getpaid_format_date( $due_date ); |
|
333 | + |
|
334 | + if ( ! empty( $fomatted ) ) { |
|
335 | + $date = wp_sprintf( |
|
336 | + // translators: %s is the due date. |
|
337 | + __( 'Due %s', 'invoicing' ), |
|
338 | + $fomatted |
|
339 | + ); |
|
340 | + echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" ); |
|
341 | + } |
|
342 | + } |
|
343 | + } |
|
344 | + |
|
345 | + break; |
|
346 | + |
|
347 | + case 'recurring': |
|
348 | + if ( $invoice->is_recurring() ) { |
|
349 | + echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
350 | + } else { |
|
351 | + echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
352 | + } |
|
353 | + break; |
|
354 | + |
|
355 | + case 'number': |
|
356 | + $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
357 | + $invoice_number = esc_html( $invoice->get_number() ); |
|
358 | + $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
359 | + |
|
360 | + echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" ); |
|
361 | + |
|
362 | + do_action( 'getpaid_admin_table_invoice_number_column', $invoice ); |
|
363 | + break; |
|
364 | + |
|
365 | + case 'customer': |
|
366 | + $customer_name = $invoice->get_user_full_name(); |
|
367 | + |
|
368 | + if ( empty( $customer_name ) ) { |
|
369 | + $customer_name = $invoice->get_email(); |
|
370 | + } |
|
371 | + |
|
372 | + if ( ! empty( $customer_name ) ) { |
|
373 | + $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
374 | + $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
375 | + echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" ); |
|
376 | + } else { |
|
377 | + echo '<div>—</div>'; |
|
378 | + } |
|
379 | + |
|
380 | + break; |
|
458 | 381 | |
459 | - case 'items': |
|
460 | - $items = $form->get_items(); |
|
461 | - |
|
462 | - if ( $form->is_default() || empty( $items ) ) { |
|
463 | - echo '—'; |
|
464 | - return; |
|
465 | - } |
|
466 | - |
|
467 | - $_items = array(); |
|
468 | - |
|
469 | - foreach ( $items as $item ) { |
|
470 | - $url = $item->get_edit_url(); |
|
471 | - |
|
472 | - if ( empty( $url ) ) { |
|
473 | - $_items[] = esc_html( $item->get_name() ); |
|
474 | - } else { |
|
475 | - $_items[] = sprintf( |
|
476 | - '<a href="%s">%s</a>', |
|
477 | - esc_url( $url ), |
|
478 | - esc_html( $item->get_name() ) |
|
479 | - ); |
|
480 | - } |
|
382 | + } |
|
383 | + |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Displays invoice bulk actions. |
|
388 | + */ |
|
389 | + public static function invoice_bulk_actions( $actions ) { |
|
390 | + $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
391 | + return $actions; |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * Processes invoice bulk actions. |
|
396 | + */ |
|
397 | + public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
398 | + |
|
399 | + if ( 'resend-invoice' === $action ) { |
|
400 | + foreach ( $post_ids as $post_id ) { |
|
401 | + getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
402 | + } |
|
403 | + } |
|
404 | + |
|
405 | + return $redirect_url; |
|
406 | + |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Returns an array of payment forms table columns. |
|
411 | + */ |
|
412 | + public static function payment_form_columns( $columns ) { |
|
413 | + |
|
414 | + $columns = array( |
|
415 | + 'cb' => $columns['cb'], |
|
416 | + 'title' => __( 'Name', 'invoicing' ), |
|
417 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
418 | + 'earnings' => __( 'Revenue', 'invoicing' ), |
|
419 | + 'refunds' => __( 'Refunded', 'invoicing' ), |
|
420 | + 'items' => __( 'Items', 'invoicing' ), |
|
421 | + 'date' => __( 'Date', 'invoicing' ), |
|
422 | + ); |
|
423 | + |
|
424 | + return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
425 | + |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * Displays payment form table columns. |
|
430 | + */ |
|
431 | + public static function display_payment_form_columns( $column_name, $post_id ) { |
|
432 | + |
|
433 | + // Retrieve the payment form. |
|
434 | + $form = new GetPaid_Payment_Form( $post_id ); |
|
435 | + |
|
436 | + switch ( $column_name ) { |
|
437 | + |
|
438 | + case 'earnings': |
|
439 | + echo wp_kses_post( wpinv_price( $form->get_earned() ) ); |
|
440 | + break; |
|
441 | + |
|
442 | + case 'refunds': |
|
443 | + echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
444 | + break; |
|
445 | + |
|
446 | + case 'refunds': |
|
447 | + echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
448 | + break; |
|
449 | + |
|
450 | + case 'shortcode': |
|
451 | + if ( $form->is_default() ) { |
|
452 | + echo '—'; |
|
453 | + } else { |
|
454 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
455 | + } |
|
456 | + |
|
457 | + break; |
|
458 | + |
|
459 | + case 'items': |
|
460 | + $items = $form->get_items(); |
|
461 | + |
|
462 | + if ( $form->is_default() || empty( $items ) ) { |
|
463 | + echo '—'; |
|
464 | + return; |
|
465 | + } |
|
466 | + |
|
467 | + $_items = array(); |
|
468 | + |
|
469 | + foreach ( $items as $item ) { |
|
470 | + $url = $item->get_edit_url(); |
|
471 | + |
|
472 | + if ( empty( $url ) ) { |
|
473 | + $_items[] = esc_html( $item->get_name() ); |
|
474 | + } else { |
|
475 | + $_items[] = sprintf( |
|
476 | + '<a href="%s">%s</a>', |
|
477 | + esc_url( $url ), |
|
478 | + esc_html( $item->get_name() ) |
|
479 | + ); |
|
480 | + } |
|
481 | 481 | } |
482 | 482 | |
483 | - echo wp_kses_post( implode( '<br>', $_items ) ); |
|
483 | + echo wp_kses_post( implode( '<br>', $_items ) ); |
|
484 | + |
|
485 | + break; |
|
486 | + |
|
487 | + } |
|
488 | + |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * Filters post states. |
|
493 | + */ |
|
494 | + public static function filter_payment_form_state( $post_states, $post ) { |
|
495 | + |
|
496 | + if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) { |
|
497 | + $post_states['default_form'] = __( 'Default Payment Form', 'invoicing' ); |
|
498 | + } |
|
499 | + |
|
500 | + return $post_states; |
|
501 | + |
|
502 | + } |
|
503 | + |
|
504 | + /** |
|
505 | + * Returns an array of coupon table columns. |
|
506 | + */ |
|
507 | + public static function discount_columns( $columns ) { |
|
508 | + |
|
509 | + $columns = array( |
|
510 | + 'cb' => $columns['cb'], |
|
511 | + 'title' => __( 'Name', 'invoicing' ), |
|
512 | + 'code' => __( 'Code', 'invoicing' ), |
|
513 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
514 | + 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
515 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
516 | + 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
517 | + ); |
|
518 | + |
|
519 | + return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
520 | + } |
|
484 | 521 | |
485 | - break; |
|
522 | + /** |
|
523 | + * Filters post states. |
|
524 | + */ |
|
525 | + public static function filter_discount_state( $post_states, $post ) { |
|
486 | 526 | |
487 | - } |
|
527 | + if ( 'wpi_discount' === $post->post_type ) { |
|
488 | 528 | |
489 | - } |
|
529 | + $discount = new WPInv_Discount( $post ); |
|
490 | 530 | |
491 | - /** |
|
492 | - * Filters post states. |
|
493 | - */ |
|
494 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
531 | + $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
495 | 532 | |
496 | - if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) { |
|
497 | - $post_states['default_form'] = __( 'Default Payment Form', 'invoicing' ); |
|
498 | - } |
|
533 | + if ( 'publish' !== $status ) { |
|
534 | + return array( |
|
535 | + 'discount_status' => wpinv_discount_status( $status ), |
|
536 | + ); |
|
537 | + } |
|
538 | + |
|
539 | + return array(); |
|
540 | + |
|
541 | + } |
|
542 | + |
|
543 | + return $post_states; |
|
499 | 544 | |
500 | - return $post_states; |
|
545 | + } |
|
501 | 546 | |
502 | - } |
|
547 | + /** |
|
548 | + * Returns an array of items table columns. |
|
549 | + */ |
|
550 | + public static function item_columns( $columns ) { |
|
551 | + |
|
552 | + $columns = array( |
|
553 | + 'cb' => $columns['cb'], |
|
554 | + 'title' => __( 'Name', 'invoicing' ), |
|
555 | + 'price' => __( 'Price', 'invoicing' ), |
|
556 | + 'vat_rule' => __( 'Tax Rule', 'invoicing' ), |
|
557 | + 'vat_class' => __( 'Tax Class', 'invoicing' ), |
|
558 | + 'type' => __( 'Type', 'invoicing' ), |
|
559 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
560 | + ); |
|
561 | + |
|
562 | + if ( ! wpinv_use_taxes() ) { |
|
563 | + unset( $columns['vat_rule'] ); |
|
564 | + unset( $columns['vat_class'] ); |
|
565 | + } |
|
503 | 566 | |
504 | - /** |
|
505 | - * Returns an array of coupon table columns. |
|
506 | - */ |
|
507 | - public static function discount_columns( $columns ) { |
|
567 | + return apply_filters( 'wpi_item_table_columns', $columns ); |
|
568 | + } |
|
508 | 569 | |
509 | - $columns = array( |
|
510 | - 'cb' => $columns['cb'], |
|
511 | - 'title' => __( 'Name', 'invoicing' ), |
|
512 | - 'code' => __( 'Code', 'invoicing' ), |
|
513 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
514 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
515 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
516 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
517 | - ); |
|
570 | + /** |
|
571 | + * Returns an array of sortable items table columns. |
|
572 | + */ |
|
573 | + public static function sortable_item_columns( $columns ) { |
|
574 | + |
|
575 | + return array_merge( |
|
576 | + $columns, |
|
577 | + array( |
|
578 | + 'price' => 'price', |
|
579 | + 'vat_rule' => 'vat_rule', |
|
580 | + 'vat_class' => 'vat_class', |
|
581 | + 'type' => 'type', |
|
582 | + ) |
|
583 | + ); |
|
518 | 584 | |
519 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
520 | - } |
|
585 | + } |
|
521 | 586 | |
522 | - /** |
|
523 | - * Filters post states. |
|
524 | - */ |
|
525 | - public static function filter_discount_state( $post_states, $post ) { |
|
587 | + /** |
|
588 | + * Displays items table columns. |
|
589 | + */ |
|
590 | + public static function display_item_columns( $column_name, $post_id ) { |
|
526 | 591 | |
527 | - if ( 'wpi_discount' === $post->post_type ) { |
|
592 | + $item = new WPInv_Item( $post_id ); |
|
528 | 593 | |
529 | - $discount = new WPInv_Discount( $post ); |
|
594 | + switch ( $column_name ) { |
|
530 | 595 | |
531 | - $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
596 | + case 'price': |
|
597 | + if ( ! $item->is_recurring() ) { |
|
598 | + echo wp_kses_post( $item->get_the_price() ); |
|
599 | + break; |
|
600 | + } |
|
532 | 601 | |
533 | - if ( 'publish' !== $status ) { |
|
534 | - return array( |
|
535 | - 'discount_status' => wpinv_discount_status( $status ), |
|
536 | - ); |
|
537 | - } |
|
602 | + $price = wp_sprintf( |
|
603 | + __( '%1$s / %2$s', 'invoicing' ), |
|
604 | + $item->get_the_price(), |
|
605 | + getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
606 | + ); |
|
538 | 607 | |
539 | - return array(); |
|
608 | + if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
609 | + echo wp_kses_post( $price ); |
|
610 | + break; |
|
611 | + } |
|
540 | 612 | |
541 | - } |
|
613 | + echo wp_kses_post( $item->get_the_initial_price() ); |
|
542 | 614 | |
543 | - return $post_states; |
|
615 | + echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>'; |
|
616 | + break; |
|
544 | 617 | |
545 | - } |
|
618 | + case 'vat_rule': |
|
619 | + echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) ); |
|
620 | + break; |
|
546 | 621 | |
547 | - /** |
|
548 | - * Returns an array of items table columns. |
|
549 | - */ |
|
550 | - public static function item_columns( $columns ) { |
|
622 | + case 'vat_class': |
|
623 | + echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) ); |
|
624 | + break; |
|
551 | 625 | |
552 | - $columns = array( |
|
553 | - 'cb' => $columns['cb'], |
|
554 | - 'title' => __( 'Name', 'invoicing' ), |
|
555 | - 'price' => __( 'Price', 'invoicing' ), |
|
556 | - 'vat_rule' => __( 'Tax Rule', 'invoicing' ), |
|
557 | - 'vat_class' => __( 'Tax Class', 'invoicing' ), |
|
558 | - 'type' => __( 'Type', 'invoicing' ), |
|
559 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
560 | - ); |
|
626 | + case 'shortcode': |
|
627 | + if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) { |
|
628 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
629 | + } else { |
|
630 | + echo '—'; |
|
631 | + } |
|
561 | 632 | |
562 | - if ( ! wpinv_use_taxes() ) { |
|
563 | - unset( $columns['vat_rule'] ); |
|
564 | - unset( $columns['vat_class'] ); |
|
565 | - } |
|
633 | + break; |
|
566 | 634 | |
567 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
568 | - } |
|
635 | + case 'type': |
|
636 | + echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' ); |
|
637 | + break; |
|
569 | 638 | |
570 | - /** |
|
571 | - * Returns an array of sortable items table columns. |
|
572 | - */ |
|
573 | - public static function sortable_item_columns( $columns ) { |
|
574 | - |
|
575 | - return array_merge( |
|
576 | - $columns, |
|
577 | - array( |
|
578 | - 'price' => 'price', |
|
579 | - 'vat_rule' => 'vat_rule', |
|
580 | - 'vat_class' => 'vat_class', |
|
581 | - 'type' => 'type', |
|
582 | - ) |
|
583 | - ); |
|
584 | - |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Displays items table columns. |
|
589 | - */ |
|
590 | - public static function display_item_columns( $column_name, $post_id ) { |
|
591 | - |
|
592 | - $item = new WPInv_Item( $post_id ); |
|
593 | - |
|
594 | - switch ( $column_name ) { |
|
595 | - |
|
596 | - case 'price': |
|
597 | - if ( ! $item->is_recurring() ) { |
|
598 | - echo wp_kses_post( $item->get_the_price() ); |
|
599 | - break; |
|
600 | - } |
|
601 | - |
|
602 | - $price = wp_sprintf( |
|
603 | - __( '%1$s / %2$s', 'invoicing' ), |
|
604 | - $item->get_the_price(), |
|
605 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
606 | - ); |
|
607 | - |
|
608 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
609 | - echo wp_kses_post( $price ); |
|
610 | - break; |
|
611 | - } |
|
612 | - |
|
613 | - echo wp_kses_post( $item->get_the_initial_price() ); |
|
614 | - |
|
615 | - echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>'; |
|
616 | - break; |
|
617 | - |
|
618 | - case 'vat_rule': |
|
619 | - echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) ); |
|
620 | - break; |
|
621 | - |
|
622 | - case 'vat_class': |
|
623 | - echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) ); |
|
624 | - break; |
|
625 | - |
|
626 | - case 'shortcode': |
|
627 | - if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) { |
|
628 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
629 | - } else { |
|
630 | - echo '—'; |
|
631 | - } |
|
632 | - |
|
633 | - break; |
|
634 | - |
|
635 | - case 'type': |
|
636 | - echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' ); |
|
637 | - break; |
|
638 | - |
|
639 | - } |
|
640 | - |
|
641 | - } |
|
642 | - |
|
643 | - /** |
|
644 | - * Lets users filter items using taxes. |
|
645 | - */ |
|
646 | - public static function add_item_filters( $post_type ) { |
|
647 | - |
|
648 | - // Abort if we're not dealing with items. |
|
649 | - if ( 'wpi_item' !== $post_type ) { |
|
650 | - return; |
|
651 | - } |
|
652 | - |
|
653 | - // Filter by vat rules. |
|
654 | - if ( wpinv_use_taxes() ) { |
|
655 | - |
|
656 | - // Sanitize selected vat rule. |
|
657 | - $vat_rule = ''; |
|
658 | - $vat_rules = getpaid_get_tax_rules(); |
|
659 | - if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
660 | - $vat_rule = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
661 | - } |
|
662 | - |
|
663 | - // Filter by VAT rule. |
|
664 | - wpinv_html_select( |
|
665 | - array( |
|
666 | - 'options' => array_merge( |
|
667 | - array( |
|
668 | - '' => __( 'All Tax Rules', 'invoicing' ), |
|
669 | - ), |
|
670 | - $vat_rules |
|
671 | - ), |
|
672 | - 'name' => 'vat_rule', |
|
673 | - 'id' => 'vat_rule', |
|
674 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '', |
|
675 | - 'show_option_all' => false, |
|
676 | - 'show_option_none' => false, |
|
677 | - ) |
|
678 | - ); |
|
679 | - |
|
680 | - // Filter by VAT class. |
|
681 | - |
|
682 | - // Sanitize selected vat rule. |
|
683 | - $vat_class = ''; |
|
684 | - $vat_classes = getpaid_get_tax_classes(); |
|
685 | - if ( isset( $_GET['vat_class'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
686 | - $vat_class = sanitize_text_field( $_GET['vat_class'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
687 | - } |
|
688 | - |
|
689 | - wpinv_html_select( |
|
690 | - array( |
|
691 | - 'options' => array_merge( |
|
692 | - array( |
|
693 | - '' => __( 'All Tax Classes', 'invoicing' ), |
|
694 | - ), |
|
695 | - $vat_classes |
|
696 | - ), |
|
697 | - 'name' => 'vat_class', |
|
698 | - 'id' => 'vat_class', |
|
699 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '', |
|
700 | - 'show_option_all' => false, |
|
701 | - 'show_option_none' => false, |
|
702 | - ) |
|
703 | - ); |
|
704 | - |
|
705 | - } |
|
706 | - |
|
707 | - // Filter by item type. |
|
708 | - $type = ''; |
|
709 | - if ( isset( $_GET['type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
710 | - $type = sanitize_text_field( $_GET['type'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
711 | - } |
|
712 | - |
|
713 | - wpinv_html_select( |
|
714 | - array( |
|
715 | - 'options' => array_merge( |
|
716 | - array( |
|
717 | - '' => __( 'All item types', 'invoicing' ), |
|
718 | - ), |
|
719 | - wpinv_get_item_types() |
|
720 | - ), |
|
721 | - 'name' => 'type', |
|
722 | - 'id' => 'type', |
|
723 | - 'selected' => in_array( $type, wpinv_item_types(), true ) ? $type : '', |
|
724 | - 'show_option_all' => false, |
|
725 | - 'show_option_none' => false, |
|
726 | - ) |
|
727 | - ); |
|
728 | - |
|
729 | - } |
|
730 | - |
|
731 | - /** |
|
732 | - * Filters the item query. |
|
733 | - */ |
|
734 | - public static function filter_item_query( $query ) { |
|
735 | - |
|
736 | - // modify the query only if it admin and main query. |
|
737 | - if ( ! ( is_admin() && $query->is_main_query() ) ) { |
|
738 | - return $query; |
|
739 | - } |
|
740 | - |
|
741 | - // we want to modify the query for our items. |
|
742 | - if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) { |
|
743 | - return $query; |
|
744 | - } |
|
745 | - |
|
746 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
747 | - $query->query_vars['meta_query'] = array(); |
|
748 | - } |
|
749 | - |
|
750 | - // Filter vat rule type |
|
639 | + } |
|
640 | + |
|
641 | + } |
|
642 | + |
|
643 | + /** |
|
644 | + * Lets users filter items using taxes. |
|
645 | + */ |
|
646 | + public static function add_item_filters( $post_type ) { |
|
647 | + |
|
648 | + // Abort if we're not dealing with items. |
|
649 | + if ( 'wpi_item' !== $post_type ) { |
|
650 | + return; |
|
651 | + } |
|
652 | + |
|
653 | + // Filter by vat rules. |
|
654 | + if ( wpinv_use_taxes() ) { |
|
655 | + |
|
656 | + // Sanitize selected vat rule. |
|
657 | + $vat_rule = ''; |
|
658 | + $vat_rules = getpaid_get_tax_rules(); |
|
659 | + if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
660 | + $vat_rule = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
661 | + } |
|
662 | + |
|
663 | + // Filter by VAT rule. |
|
664 | + wpinv_html_select( |
|
665 | + array( |
|
666 | + 'options' => array_merge( |
|
667 | + array( |
|
668 | + '' => __( 'All Tax Rules', 'invoicing' ), |
|
669 | + ), |
|
670 | + $vat_rules |
|
671 | + ), |
|
672 | + 'name' => 'vat_rule', |
|
673 | + 'id' => 'vat_rule', |
|
674 | + 'selected' => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '', |
|
675 | + 'show_option_all' => false, |
|
676 | + 'show_option_none' => false, |
|
677 | + ) |
|
678 | + ); |
|
679 | + |
|
680 | + // Filter by VAT class. |
|
681 | + |
|
682 | + // Sanitize selected vat rule. |
|
683 | + $vat_class = ''; |
|
684 | + $vat_classes = getpaid_get_tax_classes(); |
|
685 | + if ( isset( $_GET['vat_class'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
686 | + $vat_class = sanitize_text_field( $_GET['vat_class'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
687 | + } |
|
688 | + |
|
689 | + wpinv_html_select( |
|
690 | + array( |
|
691 | + 'options' => array_merge( |
|
692 | + array( |
|
693 | + '' => __( 'All Tax Classes', 'invoicing' ), |
|
694 | + ), |
|
695 | + $vat_classes |
|
696 | + ), |
|
697 | + 'name' => 'vat_class', |
|
698 | + 'id' => 'vat_class', |
|
699 | + 'selected' => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '', |
|
700 | + 'show_option_all' => false, |
|
701 | + 'show_option_none' => false, |
|
702 | + ) |
|
703 | + ); |
|
704 | + |
|
705 | + } |
|
706 | + |
|
707 | + // Filter by item type. |
|
708 | + $type = ''; |
|
709 | + if ( isset( $_GET['type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
710 | + $type = sanitize_text_field( $_GET['type'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
711 | + } |
|
712 | + |
|
713 | + wpinv_html_select( |
|
714 | + array( |
|
715 | + 'options' => array_merge( |
|
716 | + array( |
|
717 | + '' => __( 'All item types', 'invoicing' ), |
|
718 | + ), |
|
719 | + wpinv_get_item_types() |
|
720 | + ), |
|
721 | + 'name' => 'type', |
|
722 | + 'id' => 'type', |
|
723 | + 'selected' => in_array( $type, wpinv_item_types(), true ) ? $type : '', |
|
724 | + 'show_option_all' => false, |
|
725 | + 'show_option_none' => false, |
|
726 | + ) |
|
727 | + ); |
|
728 | + |
|
729 | + } |
|
730 | + |
|
731 | + /** |
|
732 | + * Filters the item query. |
|
733 | + */ |
|
734 | + public static function filter_item_query( $query ) { |
|
735 | + |
|
736 | + // modify the query only if it admin and main query. |
|
737 | + if ( ! ( is_admin() && $query->is_main_query() ) ) { |
|
738 | + return $query; |
|
739 | + } |
|
740 | + |
|
741 | + // we want to modify the query for our items. |
|
742 | + if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) { |
|
743 | + return $query; |
|
744 | + } |
|
745 | + |
|
746 | + if ( empty( $query->query_vars['meta_query'] ) ) { |
|
747 | + $query->query_vars['meta_query'] = array(); |
|
748 | + } |
|
749 | + |
|
750 | + // Filter vat rule type |
|
751 | 751 | if ( ! empty( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
752 | 752 | $query->query_vars['meta_query'][] = array( |
753 | 753 | 'key' => '_wpinv_vat_rule', |
@@ -772,97 +772,97 @@ discard block |
||
772 | 772 | 'value' => sanitize_text_field( $_GET['type'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
773 | 773 | 'compare' => '=', |
774 | 774 | ); |
775 | - } |
|
776 | - |
|
777 | - } |
|
778 | - |
|
779 | - /** |
|
780 | - * Reorders items. |
|
781 | - */ |
|
782 | - public static function reorder_items( $vars ) { |
|
783 | - global $typenow; |
|
784 | - |
|
785 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
786 | - return $vars; |
|
787 | - } |
|
788 | - |
|
789 | - // By item type. |
|
790 | - if ( 'type' === $vars['orderby'] ) { |
|
791 | - return array_merge( |
|
792 | - $vars, |
|
793 | - array( |
|
794 | - 'meta_key' => '_wpinv_type', |
|
795 | - 'orderby' => 'meta_value', |
|
796 | - ) |
|
797 | - ); |
|
798 | - } |
|
799 | - |
|
800 | - // By vat class. |
|
801 | - if ( 'vat_class' === $vars['orderby'] ) { |
|
802 | - return array_merge( |
|
803 | - $vars, |
|
804 | - array( |
|
805 | - 'meta_key' => '_wpinv_vat_class', |
|
806 | - 'orderby' => 'meta_value', |
|
807 | - ) |
|
808 | - ); |
|
809 | - } |
|
810 | - |
|
811 | - // By vat rule. |
|
812 | - if ( 'vat_rule' === $vars['orderby'] ) { |
|
813 | - return array_merge( |
|
814 | - $vars, |
|
815 | - array( |
|
816 | - 'meta_key' => '_wpinv_vat_rule', |
|
817 | - 'orderby' => 'meta_value', |
|
818 | - ) |
|
819 | - ); |
|
820 | - } |
|
821 | - |
|
822 | - // By price. |
|
823 | - if ( 'price' === $vars['orderby'] ) { |
|
824 | - return array_merge( |
|
825 | - $vars, |
|
826 | - array( |
|
827 | - 'meta_key' => '_wpinv_price', |
|
828 | - 'orderby' => 'meta_value_num', |
|
829 | - ) |
|
830 | - ); |
|
831 | - } |
|
832 | - |
|
833 | - return $vars; |
|
834 | - |
|
835 | - } |
|
836 | - |
|
837 | - /** |
|
838 | - * Fired when deleting a post. |
|
839 | - */ |
|
840 | - public static function delete_post( $post_id ) { |
|
841 | - |
|
842 | - switch ( get_post_type( $post_id ) ) { |
|
843 | - |
|
844 | - case 'wpi_item': |
|
845 | - do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) ); |
|
846 | - break; |
|
847 | - |
|
848 | - case 'wpi_payment_form': |
|
849 | - do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) ); |
|
850 | - break; |
|
851 | - |
|
852 | - case 'wpi_discount': |
|
853 | - do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) ); |
|
854 | - break; |
|
855 | - |
|
856 | - case 'wpi_invoice': |
|
857 | - $invoice = new WPInv_Invoice( $post_id ); |
|
858 | - do_action( 'getpaid_before_delete_invoice', $invoice ); |
|
859 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
860 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
861 | - break; |
|
862 | - } |
|
863 | - } |
|
864 | - |
|
865 | - /** |
|
775 | + } |
|
776 | + |
|
777 | + } |
|
778 | + |
|
779 | + /** |
|
780 | + * Reorders items. |
|
781 | + */ |
|
782 | + public static function reorder_items( $vars ) { |
|
783 | + global $typenow; |
|
784 | + |
|
785 | + if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
786 | + return $vars; |
|
787 | + } |
|
788 | + |
|
789 | + // By item type. |
|
790 | + if ( 'type' === $vars['orderby'] ) { |
|
791 | + return array_merge( |
|
792 | + $vars, |
|
793 | + array( |
|
794 | + 'meta_key' => '_wpinv_type', |
|
795 | + 'orderby' => 'meta_value', |
|
796 | + ) |
|
797 | + ); |
|
798 | + } |
|
799 | + |
|
800 | + // By vat class. |
|
801 | + if ( 'vat_class' === $vars['orderby'] ) { |
|
802 | + return array_merge( |
|
803 | + $vars, |
|
804 | + array( |
|
805 | + 'meta_key' => '_wpinv_vat_class', |
|
806 | + 'orderby' => 'meta_value', |
|
807 | + ) |
|
808 | + ); |
|
809 | + } |
|
810 | + |
|
811 | + // By vat rule. |
|
812 | + if ( 'vat_rule' === $vars['orderby'] ) { |
|
813 | + return array_merge( |
|
814 | + $vars, |
|
815 | + array( |
|
816 | + 'meta_key' => '_wpinv_vat_rule', |
|
817 | + 'orderby' => 'meta_value', |
|
818 | + ) |
|
819 | + ); |
|
820 | + } |
|
821 | + |
|
822 | + // By price. |
|
823 | + if ( 'price' === $vars['orderby'] ) { |
|
824 | + return array_merge( |
|
825 | + $vars, |
|
826 | + array( |
|
827 | + 'meta_key' => '_wpinv_price', |
|
828 | + 'orderby' => 'meta_value_num', |
|
829 | + ) |
|
830 | + ); |
|
831 | + } |
|
832 | + |
|
833 | + return $vars; |
|
834 | + |
|
835 | + } |
|
836 | + |
|
837 | + /** |
|
838 | + * Fired when deleting a post. |
|
839 | + */ |
|
840 | + public static function delete_post( $post_id ) { |
|
841 | + |
|
842 | + switch ( get_post_type( $post_id ) ) { |
|
843 | + |
|
844 | + case 'wpi_item': |
|
845 | + do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) ); |
|
846 | + break; |
|
847 | + |
|
848 | + case 'wpi_payment_form': |
|
849 | + do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) ); |
|
850 | + break; |
|
851 | + |
|
852 | + case 'wpi_discount': |
|
853 | + do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) ); |
|
854 | + break; |
|
855 | + |
|
856 | + case 'wpi_invoice': |
|
857 | + $invoice = new WPInv_Invoice( $post_id ); |
|
858 | + do_action( 'getpaid_before_delete_invoice', $invoice ); |
|
859 | + $invoice->get_data_store()->delete_items( $invoice ); |
|
860 | + $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
861 | + break; |
|
862 | + } |
|
863 | + } |
|
864 | + |
|
865 | + /** |
|
866 | 866 | * Add a post display state for special GetPaid pages in the page list table. |
867 | 867 | * |
868 | 868 | * @param array $post_states An array of post display states. |
@@ -876,21 +876,21 @@ discard block |
||
876 | 876 | $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' ); |
877 | 877 | } |
878 | 878 | |
879 | - foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
879 | + foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
880 | 880 | |
881 | - if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
882 | - $post_states[ "getpaid_{$post_type}_history_page" ] = sprintf( |
|
883 | - __( 'GetPaid %s History Page', 'invoicing' ), |
|
884 | - $label |
|
885 | - ); |
|
886 | - } |
|
881 | + if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
882 | + $post_states[ "getpaid_{$post_type}_history_page" ] = sprintf( |
|
883 | + __( 'GetPaid %s History Page', 'invoicing' ), |
|
884 | + $label |
|
885 | + ); |
|
886 | + } |
|
887 | 887 | } |
888 | 888 | |
889 | - if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
889 | + if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
890 | 890 | $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' ); |
891 | 891 | } |
892 | 892 | |
893 | - if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
893 | + if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
894 | 894 | $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' ); |
895 | 895 | } |
896 | 896 |
@@ -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,74 +21,74 @@ 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 ); |
|
28 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
27 | + add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2); |
|
28 | + add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2); |
|
29 | 29 | |
30 | 30 | // Invoice table columns. |
31 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
32 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
33 | - add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
34 | - add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
31 | + add_filter('manage_wpi_invoice_posts_columns', array(__CLASS__, 'invoice_columns'), 100); |
|
32 | + add_action('manage_wpi_invoice_posts_custom_column', array(__CLASS__, 'display_invoice_columns'), 10, 2); |
|
33 | + add_filter('bulk_actions-edit-wpi_invoice', array(__CLASS__, 'invoice_bulk_actions')); |
|
34 | + add_filter('handle_bulk_actions-edit-wpi_invoice', array(__CLASS__, 'handle_invoice_bulk_actions'), 10, 3); |
|
35 | 35 | |
36 | 36 | // Items table columns. |
37 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
38 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
39 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
40 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
41 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
42 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
37 | + add_filter('manage_wpi_item_posts_columns', array(__CLASS__, 'item_columns'), 100); |
|
38 | + add_filter('manage_edit-wpi_item_sortable_columns', array(__CLASS__, 'sortable_item_columns'), 20); |
|
39 | + add_action('manage_wpi_item_posts_custom_column', array(__CLASS__, 'display_item_columns'), 10, 2); |
|
40 | + add_action('restrict_manage_posts', array(__CLASS__, 'add_item_filters'), 100); |
|
41 | + add_action('parse_query', array(__CLASS__, 'filter_item_query'), 100); |
|
42 | + add_action('request', array(__CLASS__, 'reorder_items'), 100); |
|
43 | 43 | |
44 | 44 | // Payment forms columns. |
45 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
46 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
47 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
45 | + add_filter('manage_wpi_payment_form_posts_columns', array(__CLASS__, 'payment_form_columns'), 100); |
|
46 | + add_action('manage_wpi_payment_form_posts_custom_column', array(__CLASS__, 'display_payment_form_columns'), 10, 2); |
|
47 | + add_filter('display_post_states', array(__CLASS__, 'filter_payment_form_state'), 10, 2); |
|
48 | 48 | |
49 | 49 | // Discount table columns. |
50 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
51 | - add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
50 | + add_filter('manage_wpi_discount_posts_columns', array(__CLASS__, 'discount_columns'), 100); |
|
51 | + add_filter('bulk_actions-edit-wpi_discount', '__return_empty_array', 100); |
|
52 | 52 | |
53 | 53 | // Deleting posts. |
54 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
55 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
54 | + add_action('delete_post', array(__CLASS__, 'delete_post')); |
|
55 | + add_filter('display_post_states', array(__CLASS__, 'filter_discount_state'), 10, 2); |
|
56 | 56 | |
57 | - add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
57 | + add_filter('display_post_states', array(__CLASS__, 'add_display_post_states'), 10, 2); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Post updated messages. |
62 | 62 | */ |
63 | - public static function post_updated_messages( $messages ) { |
|
63 | + public static function post_updated_messages($messages) { |
|
64 | 64 | global $post; |
65 | 65 | |
66 | 66 | $messages['wpi_discount'] = array( |
67 | 67 | 0 => '', |
68 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
69 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
70 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
71 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
72 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
73 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
74 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
75 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
76 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
77 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
68 | + 1 => __('Discount updated.', 'invoicing'), |
|
69 | + 2 => __('Custom field updated.', 'invoicing'), |
|
70 | + 3 => __('Custom field deleted.', 'invoicing'), |
|
71 | + 4 => __('Discount updated.', 'invoicing'), |
|
72 | + 5 => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
73 | + 6 => __('Discount updated.', 'invoicing'), |
|
74 | + 7 => __('Discount saved.', 'invoicing'), |
|
75 | + 8 => __('Discount submitted.', 'invoicing'), |
|
76 | + 9 => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))), |
|
77 | + 10 => __('Discount draft updated.', 'invoicing'), |
|
78 | 78 | ); |
79 | 79 | |
80 | 80 | $messages['wpi_payment_form'] = array( |
81 | 81 | 0 => '', |
82 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
83 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
84 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
85 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
86 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
87 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
88 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
89 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
90 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
91 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
82 | + 1 => __('Payment Form updated.', 'invoicing'), |
|
83 | + 2 => __('Custom field updated.', 'invoicing'), |
|
84 | + 3 => __('Custom field deleted.', 'invoicing'), |
|
85 | + 4 => __('Payment Form updated.', 'invoicing'), |
|
86 | + 5 => isset($_GET['revision']) ? wp_sprintf(__('Payment Form restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
87 | + 6 => __('Payment Form updated.', 'invoicing'), |
|
88 | + 7 => __('Payment Form saved.', 'invoicing'), |
|
89 | + 8 => __('Payment Form submitted.', 'invoicing'), |
|
90 | + 9 => wp_sprintf(__('Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))), |
|
91 | + 10 => __('Payment Form draft updated.', 'invoicing'), |
|
92 | 92 | ); |
93 | 93 | |
94 | 94 | return $messages; |
@@ -98,16 +98,16 @@ discard block |
||
98 | 98 | /** |
99 | 99 | * Post row actions. |
100 | 100 | */ |
101 | - public static function post_row_actions( $actions, $post ) { |
|
101 | + public static function post_row_actions($actions, $post) { |
|
102 | 102 | |
103 | - $post = get_post( $post ); |
|
103 | + $post = get_post($post); |
|
104 | 104 | |
105 | 105 | // We do not want to edit the default payment form. |
106 | - if ( 'wpi_payment_form' == $post->post_type ) { |
|
106 | + if ('wpi_payment_form' == $post->post_type) { |
|
107 | 107 | |
108 | - if ( wpinv_get_default_payment_form() === $post->ID ) { |
|
109 | - unset( $actions['trash'] ); |
|
110 | - unset( $actions['inline hide-if-no-js'] ); |
|
108 | + if (wpinv_get_default_payment_form() === $post->ID) { |
|
109 | + unset($actions['trash']); |
|
110 | + unset($actions['inline hide-if-no-js']); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | $actions['duplicate'] = sprintf( |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | 'getpaid-nonce' |
125 | 125 | ) |
126 | 126 | ), |
127 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
127 | + esc_html(__('Duplicate', 'invoicing')) |
|
128 | 128 | ); |
129 | 129 | |
130 | 130 | $actions['reset'] = sprintf( |
@@ -141,19 +141,19 @@ discard block |
||
141 | 141 | 'getpaid-nonce' |
142 | 142 | ) |
143 | 143 | ), |
144 | - esc_html( __( 'Reset Stats', 'invoicing' ) ) |
|
144 | + esc_html(__('Reset Stats', 'invoicing')) |
|
145 | 145 | ); |
146 | 146 | } |
147 | 147 | |
148 | 148 | // Link to item payment form. |
149 | - if ( 'wpi_item' == $post->post_type ) { |
|
149 | + if ('wpi_item' == $post->post_type) { |
|
150 | 150 | |
151 | - if ( in_array( get_post_meta( $post->ID, '_wpinv_type', true ), array( '', 'fee', 'custom' ), true ) ) { |
|
151 | + if (in_array(get_post_meta($post->ID, '_wpinv_type', true), array('', 'fee', 'custom'), true)) { |
|
152 | 152 | |
153 | 153 | $actions['buy'] = sprintf( |
154 | 154 | '<a href="%1$s">%2$s</a>', |
155 | - esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ), |
|
156 | - esc_html( __( 'Buy', 'invoicing' ) ) |
|
155 | + esc_url(getpaid_embed_url(false, $post->ID . '|0')), |
|
156 | + esc_html(__('Buy', 'invoicing')) |
|
157 | 157 | ); |
158 | 158 | |
159 | 159 | } |
@@ -170,28 +170,28 @@ discard block |
||
170 | 170 | * @param WP_Post $post |
171 | 171 | * @return array $actions actions without edit option |
172 | 172 | */ |
173 | - public static function filter_invoice_row_actions( $actions, $post ) { |
|
173 | + public static function filter_invoice_row_actions($actions, $post) { |
|
174 | 174 | |
175 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
175 | + if (getpaid_is_invoice_post_type($post->post_type)) { |
|
176 | 176 | |
177 | 177 | $actions = array(); |
178 | - $invoice = new WPInv_Invoice( $post ); |
|
178 | + $invoice = new WPInv_Invoice($post); |
|
179 | 179 | |
180 | 180 | $actions['edit'] = sprintf( |
181 | 181 | '<a href="%1$s">%2$s</a>', |
182 | - esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
183 | - esc_html( __( 'Edit', 'invoicing' ) ) |
|
182 | + esc_url(get_edit_post_link($invoice->get_id())), |
|
183 | + esc_html(__('Edit', 'invoicing')) |
|
184 | 184 | ); |
185 | 185 | |
186 | - if ( ! $invoice->is_draft() ) { |
|
186 | + if (!$invoice->is_draft()) { |
|
187 | 187 | |
188 | 188 | $actions['view'] = sprintf( |
189 | 189 | '<a href="%1$s">%2$s</a>', |
190 | - esc_url( $invoice->get_view_url() ), |
|
190 | + esc_url($invoice->get_view_url()), |
|
191 | 191 | sprintf( |
192 | 192 | // translators: %s is the invoice type |
193 | - esc_html__( 'View %s', 'invoicing' ), |
|
194 | - getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
193 | + esc_html__('View %s', 'invoicing'), |
|
194 | + getpaid_get_post_type_label($invoice->get_post_type(), false) |
|
195 | 195 | ) |
196 | 196 | ); |
197 | 197 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | 'getpaid-nonce' |
210 | 210 | ) |
211 | 211 | ), |
212 | - esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
212 | + esc_html(__('Send to Customer', 'invoicing')) |
|
213 | 213 | ); |
214 | 214 | |
215 | 215 | } |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | 'getpaid-nonce' |
229 | 229 | ) |
230 | 230 | ), |
231 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
231 | + esc_html(__('Duplicate', 'invoicing')) |
|
232 | 232 | ); |
233 | 233 | |
234 | 234 | } |
@@ -239,42 +239,42 @@ discard block |
||
239 | 239 | /** |
240 | 240 | * Returns an array of invoice table columns. |
241 | 241 | */ |
242 | - public static function invoice_columns( $columns ) { |
|
242 | + public static function invoice_columns($columns) { |
|
243 | 243 | |
244 | 244 | $columns = array( |
245 | 245 | 'cb' => $columns['cb'], |
246 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
247 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
248 | - 'invoice_date' => __( 'Created', 'invoicing' ), |
|
249 | - 'payment_date' => __( 'Completed', 'invoicing' ), |
|
250 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
251 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
252 | - 'status' => __( 'Status', 'invoicing' ), |
|
246 | + 'number' => __('Invoice', 'invoicing'), |
|
247 | + 'customer' => __('Customer', 'invoicing'), |
|
248 | + 'invoice_date' => __('Created', 'invoicing'), |
|
249 | + 'payment_date' => __('Completed', 'invoicing'), |
|
250 | + 'amount' => __('Amount', 'invoicing'), |
|
251 | + 'recurring' => __('Recurring', 'invoicing'), |
|
252 | + 'status' => __('Status', 'invoicing'), |
|
253 | 253 | ); |
254 | 254 | |
255 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
255 | + return apply_filters('wpi_invoice_table_columns', $columns); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
259 | 259 | * Displays invoice table columns. |
260 | 260 | */ |
261 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
261 | + public static function display_invoice_columns($column_name, $post_id) { |
|
262 | 262 | |
263 | - $invoice = new WPInv_Invoice( $post_id ); |
|
263 | + $invoice = new WPInv_Invoice($post_id); |
|
264 | 264 | |
265 | - switch ( $column_name ) { |
|
265 | + switch ($column_name) { |
|
266 | 266 | |
267 | 267 | case 'invoice_date': |
268 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
269 | - $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
270 | - echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
268 | + $date_time = esc_attr($invoice->get_created_date()); |
|
269 | + $date = esc_html(getpaid_format_date_value($date_time, '—', true)); |
|
270 | + echo wp_kses_post("<span title='$date_time'>$date</span>"); |
|
271 | 271 | break; |
272 | 272 | |
273 | 273 | case 'payment_date': |
274 | - if ( $invoice->is_paid() ) { |
|
275 | - $date_time = esc_attr( $invoice->get_completed_date() ); |
|
276 | - $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
277 | - echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
274 | + if ($invoice->is_paid()) { |
|
275 | + $date_time = esc_attr($invoice->get_completed_date()); |
|
276 | + $date = esc_html(getpaid_format_date_value($date_time, '—', true)); |
|
277 | + echo wp_kses_post("<span title='$date_time'>$date</span>"); |
|
278 | 278 | } else { |
279 | 279 | echo '—'; |
280 | 280 | } |
@@ -283,61 +283,61 @@ discard block |
||
283 | 283 | |
284 | 284 | case 'amount': |
285 | 285 | $amount = $invoice->get_total(); |
286 | - $formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) ); |
|
286 | + $formated_amount = wp_kses_post(wpinv_price($amount, $invoice->get_currency())); |
|
287 | 287 | |
288 | - if ( $invoice->is_refunded() ) { |
|
289 | - $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
290 | - echo wp_kses_post( "<del>$formated_amount</del> <ins>$refunded_amount</ins>" ); |
|
288 | + if ($invoice->is_refunded()) { |
|
289 | + $refunded_amount = wpinv_price(0, $invoice->get_currency()); |
|
290 | + echo wp_kses_post("<del>$formated_amount</del> <ins>$refunded_amount</ins>"); |
|
291 | 291 | } else { |
292 | 292 | |
293 | 293 | $discount = $invoice->get_total_discount(); |
294 | 294 | |
295 | - if ( ! empty( $discount ) ) { |
|
296 | - $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
297 | - echo wp_kses_post( "<del>$new_amount</del> <ins>$formated_amount</ins>" ); |
|
295 | + if (!empty($discount)) { |
|
296 | + $new_amount = wpinv_price($amount + $discount, $invoice->get_currency()); |
|
297 | + echo wp_kses_post("<del>$new_amount</del> <ins>$formated_amount</ins>"); |
|
298 | 298 | } else { |
299 | - echo wp_kses_post( $formated_amount ); |
|
299 | + echo wp_kses_post($formated_amount); |
|
300 | 300 | } |
301 | 301 | } |
302 | 302 | |
303 | 303 | break; |
304 | 304 | |
305 | 305 | case 'status': |
306 | - $status = esc_html( $invoice->get_status() ); |
|
307 | - $status_label = esc_html( $invoice->get_status_nicename() ); |
|
306 | + $status = esc_html($invoice->get_status()); |
|
307 | + $status_label = esc_html($invoice->get_status_nicename()); |
|
308 | 308 | |
309 | 309 | // If it is paid, show the gateway title. |
310 | - if ( $invoice->is_paid() ) { |
|
311 | - $gateway = esc_html( $invoice->get_gateway_title() ); |
|
312 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) ); |
|
310 | + if ($invoice->is_paid()) { |
|
311 | + $gateway = esc_html($invoice->get_gateway_title()); |
|
312 | + $gateway = wp_sprintf(esc_attr__('Paid via %s', 'invoicing'), esc_html($gateway)); |
|
313 | 313 | |
314 | - echo wp_kses_post( "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>" ); |
|
314 | + echo wp_kses_post("<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"); |
|
315 | 315 | } else { |
316 | - echo wp_kses_post( "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>" ); |
|
316 | + echo wp_kses_post("<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | // If it is not paid, display the overdue and view status. |
320 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
320 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
321 | 321 | |
322 | 322 | // Invoice view status. |
323 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
324 | - echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
323 | + if (wpinv_is_invoice_viewed($invoice->get_id())) { |
|
324 | + echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__('Viewed by Customer', 'invoicing') . '"></i>'; |
|
325 | 325 | } else { |
326 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
326 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__('Not Viewed by Customer', 'invoicing') . '"></i>'; |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | // Display the overview status. |
330 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
330 | + if (wpinv_get_option('overdue_active')) { |
|
331 | 331 | $due_date = $invoice->get_due_date(); |
332 | - $fomatted = getpaid_format_date( $due_date ); |
|
332 | + $fomatted = getpaid_format_date($due_date); |
|
333 | 333 | |
334 | - if ( ! empty( $fomatted ) ) { |
|
334 | + if (!empty($fomatted)) { |
|
335 | 335 | $date = wp_sprintf( |
336 | 336 | // translators: %s is the due date. |
337 | - __( 'Due %s', 'invoicing' ), |
|
337 | + __('Due %s', 'invoicing'), |
|
338 | 338 | $fomatted |
339 | 339 | ); |
340 | - echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" ); |
|
340 | + echo wp_kses_post("<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"); |
|
341 | 341 | } |
342 | 342 | } |
343 | 343 | } |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | break; |
346 | 346 | |
347 | 347 | case 'recurring': |
348 | - if ( $invoice->is_recurring() ) { |
|
348 | + if ($invoice->is_recurring()) { |
|
349 | 349 | echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
350 | 350 | } else { |
351 | 351 | echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
@@ -353,26 +353,26 @@ discard block |
||
353 | 353 | break; |
354 | 354 | |
355 | 355 | case 'number': |
356 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
357 | - $invoice_number = esc_html( $invoice->get_number() ); |
|
358 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
356 | + $edit_link = esc_url(get_edit_post_link($invoice->get_id())); |
|
357 | + $invoice_number = esc_html($invoice->get_number()); |
|
358 | + $invoice_details = esc_attr__('View Invoice Details', 'invoicing'); |
|
359 | 359 | |
360 | - echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" ); |
|
360 | + echo wp_kses_post("<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"); |
|
361 | 361 | |
362 | - do_action( 'getpaid_admin_table_invoice_number_column', $invoice ); |
|
362 | + do_action('getpaid_admin_table_invoice_number_column', $invoice); |
|
363 | 363 | break; |
364 | 364 | |
365 | 365 | case 'customer': |
366 | 366 | $customer_name = $invoice->get_user_full_name(); |
367 | 367 | |
368 | - if ( empty( $customer_name ) ) { |
|
368 | + if (empty($customer_name)) { |
|
369 | 369 | $customer_name = $invoice->get_email(); |
370 | 370 | } |
371 | 371 | |
372 | - if ( ! empty( $customer_name ) ) { |
|
373 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
374 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
375 | - echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" ); |
|
372 | + if (!empty($customer_name)) { |
|
373 | + $customer_details = esc_attr__('View Customer Details', 'invoicing'); |
|
374 | + $view_link = esc_url(add_query_arg('user_id', $invoice->get_user_id(), admin_url('user-edit.php'))); |
|
375 | + echo wp_kses_post("<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"); |
|
376 | 376 | } else { |
377 | 377 | echo '<div>—</div>'; |
378 | 378 | } |
@@ -386,19 +386,19 @@ discard block |
||
386 | 386 | /** |
387 | 387 | * Displays invoice bulk actions. |
388 | 388 | */ |
389 | - public static function invoice_bulk_actions( $actions ) { |
|
390 | - $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
389 | + public static function invoice_bulk_actions($actions) { |
|
390 | + $actions['resend-invoice'] = __('Send to Customer', 'invoicing'); |
|
391 | 391 | return $actions; |
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
395 | 395 | * Processes invoice bulk actions. |
396 | 396 | */ |
397 | - public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
397 | + public static function handle_invoice_bulk_actions($redirect_url, $action, $post_ids) { |
|
398 | 398 | |
399 | - if ( 'resend-invoice' === $action ) { |
|
400 | - foreach ( $post_ids as $post_id ) { |
|
401 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
399 | + if ('resend-invoice' === $action) { |
|
400 | + foreach ($post_ids as $post_id) { |
|
401 | + getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($post_id), true); |
|
402 | 402 | } |
403 | 403 | } |
404 | 404 | |
@@ -409,49 +409,49 @@ discard block |
||
409 | 409 | /** |
410 | 410 | * Returns an array of payment forms table columns. |
411 | 411 | */ |
412 | - public static function payment_form_columns( $columns ) { |
|
412 | + public static function payment_form_columns($columns) { |
|
413 | 413 | |
414 | 414 | $columns = array( |
415 | 415 | 'cb' => $columns['cb'], |
416 | - 'title' => __( 'Name', 'invoicing' ), |
|
417 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
418 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
419 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
420 | - 'items' => __( 'Items', 'invoicing' ), |
|
421 | - 'date' => __( 'Date', 'invoicing' ), |
|
416 | + 'title' => __('Name', 'invoicing'), |
|
417 | + 'shortcode' => __('Shortcode', 'invoicing'), |
|
418 | + 'earnings' => __('Revenue', 'invoicing'), |
|
419 | + 'refunds' => __('Refunded', 'invoicing'), |
|
420 | + 'items' => __('Items', 'invoicing'), |
|
421 | + 'date' => __('Date', 'invoicing'), |
|
422 | 422 | ); |
423 | 423 | |
424 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
424 | + return apply_filters('wpi_payment_form_table_columns', $columns); |
|
425 | 425 | |
426 | 426 | } |
427 | 427 | |
428 | 428 | /** |
429 | 429 | * Displays payment form table columns. |
430 | 430 | */ |
431 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
431 | + public static function display_payment_form_columns($column_name, $post_id) { |
|
432 | 432 | |
433 | 433 | // Retrieve the payment form. |
434 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
434 | + $form = new GetPaid_Payment_Form($post_id); |
|
435 | 435 | |
436 | - switch ( $column_name ) { |
|
436 | + switch ($column_name) { |
|
437 | 437 | |
438 | 438 | case 'earnings': |
439 | - echo wp_kses_post( wpinv_price( $form->get_earned() ) ); |
|
439 | + echo wp_kses_post(wpinv_price($form->get_earned())); |
|
440 | 440 | break; |
441 | 441 | |
442 | 442 | case 'refunds': |
443 | - echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
443 | + echo wp_kses_post(wpinv_price($form->get_refunded())); |
|
444 | 444 | break; |
445 | 445 | |
446 | 446 | case 'refunds': |
447 | - echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
447 | + echo wp_kses_post(wpinv_price($form->get_refunded())); |
|
448 | 448 | break; |
449 | 449 | |
450 | 450 | case 'shortcode': |
451 | - if ( $form->is_default() ) { |
|
451 | + if ($form->is_default()) { |
|
452 | 452 | echo '—'; |
453 | 453 | } else { |
454 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
454 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr($form->get_id()) . ']" style="width: 100%;" readonly/>'; |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | break; |
@@ -459,28 +459,28 @@ discard block |
||
459 | 459 | case 'items': |
460 | 460 | $items = $form->get_items(); |
461 | 461 | |
462 | - if ( $form->is_default() || empty( $items ) ) { |
|
462 | + if ($form->is_default() || empty($items)) { |
|
463 | 463 | echo '—'; |
464 | 464 | return; |
465 | 465 | } |
466 | 466 | |
467 | 467 | $_items = array(); |
468 | 468 | |
469 | - foreach ( $items as $item ) { |
|
469 | + foreach ($items as $item) { |
|
470 | 470 | $url = $item->get_edit_url(); |
471 | 471 | |
472 | - if ( empty( $url ) ) { |
|
473 | - $_items[] = esc_html( $item->get_name() ); |
|
472 | + if (empty($url)) { |
|
473 | + $_items[] = esc_html($item->get_name()); |
|
474 | 474 | } else { |
475 | 475 | $_items[] = sprintf( |
476 | 476 | '<a href="%s">%s</a>', |
477 | - esc_url( $url ), |
|
478 | - esc_html( $item->get_name() ) |
|
477 | + esc_url($url), |
|
478 | + esc_html($item->get_name()) |
|
479 | 479 | ); |
480 | 480 | } |
481 | 481 | } |
482 | 482 | |
483 | - echo wp_kses_post( implode( '<br>', $_items ) ); |
|
483 | + echo wp_kses_post(implode('<br>', $_items)); |
|
484 | 484 | |
485 | 485 | break; |
486 | 486 | |
@@ -491,10 +491,10 @@ discard block |
||
491 | 491 | /** |
492 | 492 | * Filters post states. |
493 | 493 | */ |
494 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
494 | + public static function filter_payment_form_state($post_states, $post) { |
|
495 | 495 | |
496 | - if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) { |
|
497 | - $post_states['default_form'] = __( 'Default Payment Form', 'invoicing' ); |
|
496 | + if ('wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID) { |
|
497 | + $post_states['default_form'] = __('Default Payment Form', 'invoicing'); |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | return $post_states; |
@@ -504,35 +504,35 @@ discard block |
||
504 | 504 | /** |
505 | 505 | * Returns an array of coupon table columns. |
506 | 506 | */ |
507 | - public static function discount_columns( $columns ) { |
|
507 | + public static function discount_columns($columns) { |
|
508 | 508 | |
509 | 509 | $columns = array( |
510 | 510 | 'cb' => $columns['cb'], |
511 | - 'title' => __( 'Name', 'invoicing' ), |
|
512 | - 'code' => __( 'Code', 'invoicing' ), |
|
513 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
514 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
515 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
516 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
511 | + 'title' => __('Name', 'invoicing'), |
|
512 | + 'code' => __('Code', 'invoicing'), |
|
513 | + 'amount' => __('Amount', 'invoicing'), |
|
514 | + 'usage' => __('Usage / Limit', 'invoicing'), |
|
515 | + 'start_date' => __('Start Date', 'invoicing'), |
|
516 | + 'expiry_date' => __('Expiry Date', 'invoicing'), |
|
517 | 517 | ); |
518 | 518 | |
519 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
519 | + return apply_filters('wpi_discount_table_columns', $columns); |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | /** |
523 | 523 | * Filters post states. |
524 | 524 | */ |
525 | - public static function filter_discount_state( $post_states, $post ) { |
|
525 | + public static function filter_discount_state($post_states, $post) { |
|
526 | 526 | |
527 | - if ( 'wpi_discount' === $post->post_type ) { |
|
527 | + if ('wpi_discount' === $post->post_type) { |
|
528 | 528 | |
529 | - $discount = new WPInv_Discount( $post ); |
|
529 | + $discount = new WPInv_Discount($post); |
|
530 | 530 | |
531 | 531 | $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
532 | 532 | |
533 | - if ( 'publish' !== $status ) { |
|
533 | + if ('publish' !== $status) { |
|
534 | 534 | return array( |
535 | - 'discount_status' => wpinv_discount_status( $status ), |
|
535 | + 'discount_status' => wpinv_discount_status($status), |
|
536 | 536 | ); |
537 | 537 | } |
538 | 538 | |
@@ -547,30 +547,30 @@ discard block |
||
547 | 547 | /** |
548 | 548 | * Returns an array of items table columns. |
549 | 549 | */ |
550 | - public static function item_columns( $columns ) { |
|
550 | + public static function item_columns($columns) { |
|
551 | 551 | |
552 | 552 | $columns = array( |
553 | 553 | 'cb' => $columns['cb'], |
554 | - 'title' => __( 'Name', 'invoicing' ), |
|
555 | - 'price' => __( 'Price', 'invoicing' ), |
|
556 | - 'vat_rule' => __( 'Tax Rule', 'invoicing' ), |
|
557 | - 'vat_class' => __( 'Tax Class', 'invoicing' ), |
|
558 | - 'type' => __( 'Type', 'invoicing' ), |
|
559 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
554 | + 'title' => __('Name', 'invoicing'), |
|
555 | + 'price' => __('Price', 'invoicing'), |
|
556 | + 'vat_rule' => __('Tax Rule', 'invoicing'), |
|
557 | + 'vat_class' => __('Tax Class', 'invoicing'), |
|
558 | + 'type' => __('Type', 'invoicing'), |
|
559 | + 'shortcode' => __('Shortcode', 'invoicing'), |
|
560 | 560 | ); |
561 | 561 | |
562 | - if ( ! wpinv_use_taxes() ) { |
|
563 | - unset( $columns['vat_rule'] ); |
|
564 | - unset( $columns['vat_class'] ); |
|
562 | + if (!wpinv_use_taxes()) { |
|
563 | + unset($columns['vat_rule']); |
|
564 | + unset($columns['vat_class']); |
|
565 | 565 | } |
566 | 566 | |
567 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
567 | + return apply_filters('wpi_item_table_columns', $columns); |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | /** |
571 | 571 | * Returns an array of sortable items table columns. |
572 | 572 | */ |
573 | - public static function sortable_item_columns( $columns ) { |
|
573 | + public static function sortable_item_columns($columns) { |
|
574 | 574 | |
575 | 575 | return array_merge( |
576 | 576 | $columns, |
@@ -587,45 +587,45 @@ discard block |
||
587 | 587 | /** |
588 | 588 | * Displays items table columns. |
589 | 589 | */ |
590 | - public static function display_item_columns( $column_name, $post_id ) { |
|
590 | + public static function display_item_columns($column_name, $post_id) { |
|
591 | 591 | |
592 | - $item = new WPInv_Item( $post_id ); |
|
592 | + $item = new WPInv_Item($post_id); |
|
593 | 593 | |
594 | - switch ( $column_name ) { |
|
594 | + switch ($column_name) { |
|
595 | 595 | |
596 | 596 | case 'price': |
597 | - if ( ! $item->is_recurring() ) { |
|
598 | - echo wp_kses_post( $item->get_the_price() ); |
|
597 | + if (!$item->is_recurring()) { |
|
598 | + echo wp_kses_post($item->get_the_price()); |
|
599 | 599 | break; |
600 | 600 | } |
601 | 601 | |
602 | 602 | $price = wp_sprintf( |
603 | - __( '%1$s / %2$s', 'invoicing' ), |
|
603 | + __('%1$s / %2$s', 'invoicing'), |
|
604 | 604 | $item->get_the_price(), |
605 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
605 | + getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '') |
|
606 | 606 | ); |
607 | 607 | |
608 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
609 | - echo wp_kses_post( $price ); |
|
608 | + if ($item->get_the_price() == $item->get_the_initial_price()) { |
|
609 | + echo wp_kses_post($price); |
|
610 | 610 | break; |
611 | 611 | } |
612 | 612 | |
613 | - echo wp_kses_post( $item->get_the_initial_price() ); |
|
613 | + echo wp_kses_post($item->get_the_initial_price()); |
|
614 | 614 | |
615 | - echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>'; |
|
615 | + echo '<span class="meta">' . wp_sprintf(esc_html__('then %s', 'invoicing'), wp_kses_post($price)) . '</span>'; |
|
616 | 616 | break; |
617 | 617 | |
618 | 618 | case 'vat_rule': |
619 | - echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) ); |
|
619 | + echo wp_kses_post(getpaid_get_tax_rule_label($item->get_vat_rule())); |
|
620 | 620 | break; |
621 | 621 | |
622 | 622 | case 'vat_class': |
623 | - echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) ); |
|
623 | + echo wp_kses_post(getpaid_get_tax_class_label($item->get_vat_class())); |
|
624 | 624 | break; |
625 | 625 | |
626 | 626 | case 'shortcode': |
627 | - if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) { |
|
628 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
627 | + if ($item->is_type(array('', 'fee', 'custom'))) { |
|
628 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr($item->get_id()) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
629 | 629 | } else { |
630 | 630 | echo '—'; |
631 | 631 | } |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | break; |
634 | 634 | |
635 | 635 | case 'type': |
636 | - echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' ); |
|
636 | + echo wp_kses_post(wpinv_item_type($item->get_id()) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'); |
|
637 | 637 | break; |
638 | 638 | |
639 | 639 | } |
@@ -643,21 +643,21 @@ discard block |
||
643 | 643 | /** |
644 | 644 | * Lets users filter items using taxes. |
645 | 645 | */ |
646 | - public static function add_item_filters( $post_type ) { |
|
646 | + public static function add_item_filters($post_type) { |
|
647 | 647 | |
648 | 648 | // Abort if we're not dealing with items. |
649 | - if ( 'wpi_item' !== $post_type ) { |
|
649 | + if ('wpi_item' !== $post_type) { |
|
650 | 650 | return; |
651 | 651 | } |
652 | 652 | |
653 | 653 | // Filter by vat rules. |
654 | - if ( wpinv_use_taxes() ) { |
|
654 | + if (wpinv_use_taxes()) { |
|
655 | 655 | |
656 | 656 | // Sanitize selected vat rule. |
657 | 657 | $vat_rule = ''; |
658 | 658 | $vat_rules = getpaid_get_tax_rules(); |
659 | - if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
660 | - $vat_rule = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
659 | + if (isset($_GET['vat_rule'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
660 | + $vat_rule = sanitize_text_field($_GET['vat_rule']); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | // Filter by VAT rule. |
@@ -665,13 +665,13 @@ discard block |
||
665 | 665 | array( |
666 | 666 | 'options' => array_merge( |
667 | 667 | array( |
668 | - '' => __( 'All Tax Rules', 'invoicing' ), |
|
668 | + '' => __('All Tax Rules', 'invoicing'), |
|
669 | 669 | ), |
670 | 670 | $vat_rules |
671 | 671 | ), |
672 | 672 | 'name' => 'vat_rule', |
673 | 673 | 'id' => 'vat_rule', |
674 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '', |
|
674 | + 'selected' => in_array($vat_rule, array_keys($vat_rules), true) ? $vat_rule : '', |
|
675 | 675 | 'show_option_all' => false, |
676 | 676 | 'show_option_none' => false, |
677 | 677 | ) |
@@ -682,21 +682,21 @@ discard block |
||
682 | 682 | // Sanitize selected vat rule. |
683 | 683 | $vat_class = ''; |
684 | 684 | $vat_classes = getpaid_get_tax_classes(); |
685 | - if ( isset( $_GET['vat_class'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
686 | - $vat_class = sanitize_text_field( $_GET['vat_class'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
685 | + if (isset($_GET['vat_class'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
686 | + $vat_class = sanitize_text_field($_GET['vat_class']); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
687 | 687 | } |
688 | 688 | |
689 | 689 | wpinv_html_select( |
690 | 690 | array( |
691 | 691 | 'options' => array_merge( |
692 | 692 | array( |
693 | - '' => __( 'All Tax Classes', 'invoicing' ), |
|
693 | + '' => __('All Tax Classes', 'invoicing'), |
|
694 | 694 | ), |
695 | 695 | $vat_classes |
696 | 696 | ), |
697 | 697 | 'name' => 'vat_class', |
698 | 698 | 'id' => 'vat_class', |
699 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '', |
|
699 | + 'selected' => in_array($vat_class, array_keys($vat_classes), true) ? $vat_class : '', |
|
700 | 700 | 'show_option_all' => false, |
701 | 701 | 'show_option_none' => false, |
702 | 702 | ) |
@@ -705,22 +705,22 @@ discard block |
||
705 | 705 | } |
706 | 706 | |
707 | 707 | // Filter by item type. |
708 | - $type = ''; |
|
709 | - if ( isset( $_GET['type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
710 | - $type = sanitize_text_field( $_GET['type'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
708 | + $type = ''; |
|
709 | + if (isset($_GET['type'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
710 | + $type = sanitize_text_field($_GET['type']); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
711 | 711 | } |
712 | 712 | |
713 | 713 | wpinv_html_select( |
714 | 714 | array( |
715 | 715 | 'options' => array_merge( |
716 | 716 | array( |
717 | - '' => __( 'All item types', 'invoicing' ), |
|
717 | + '' => __('All item types', 'invoicing'), |
|
718 | 718 | ), |
719 | 719 | wpinv_get_item_types() |
720 | 720 | ), |
721 | 721 | 'name' => 'type', |
722 | 722 | 'id' => 'type', |
723 | - 'selected' => in_array( $type, wpinv_item_types(), true ) ? $type : '', |
|
723 | + 'selected' => in_array($type, wpinv_item_types(), true) ? $type : '', |
|
724 | 724 | 'show_option_all' => false, |
725 | 725 | 'show_option_none' => false, |
726 | 726 | ) |
@@ -731,45 +731,45 @@ discard block |
||
731 | 731 | /** |
732 | 732 | * Filters the item query. |
733 | 733 | */ |
734 | - public static function filter_item_query( $query ) { |
|
734 | + public static function filter_item_query($query) { |
|
735 | 735 | |
736 | 736 | // modify the query only if it admin and main query. |
737 | - if ( ! ( is_admin() && $query->is_main_query() ) ) { |
|
737 | + if (!(is_admin() && $query->is_main_query())) { |
|
738 | 738 | return $query; |
739 | 739 | } |
740 | 740 | |
741 | 741 | // we want to modify the query for our items. |
742 | - if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) { |
|
742 | + if (empty($query->query['post_type']) || 'wpi_item' !== $query->query['post_type']) { |
|
743 | 743 | return $query; |
744 | 744 | } |
745 | 745 | |
746 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
746 | + if (empty($query->query_vars['meta_query'])) { |
|
747 | 747 | $query->query_vars['meta_query'] = array(); |
748 | 748 | } |
749 | 749 | |
750 | 750 | // Filter vat rule type |
751 | - if ( ! empty( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
751 | + if (!empty($_GET['vat_rule'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
752 | 752 | $query->query_vars['meta_query'][] = array( |
753 | 753 | 'key' => '_wpinv_vat_rule', |
754 | - 'value' => sanitize_text_field( $_GET['vat_rule'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
754 | + 'value' => sanitize_text_field($_GET['vat_rule']), // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
755 | 755 | 'compare' => '=', |
756 | 756 | ); |
757 | 757 | } |
758 | 758 | |
759 | 759 | // Filter vat class |
760 | - if ( ! empty( $_GET['vat_class'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
760 | + if (!empty($_GET['vat_class'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
761 | 761 | $query->query_vars['meta_query'][] = array( |
762 | 762 | 'key' => '_wpinv_vat_class', |
763 | - 'value' => sanitize_text_field( $_GET['vat_class'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
763 | + 'value' => sanitize_text_field($_GET['vat_class']), // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
764 | 764 | 'compare' => '=', |
765 | 765 | ); |
766 | 766 | } |
767 | 767 | |
768 | 768 | // Filter item type |
769 | - if ( ! empty( $_GET['type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
769 | + if (!empty($_GET['type'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
770 | 770 | $query->query_vars['meta_query'][] = array( |
771 | 771 | 'key' => '_wpinv_type', |
772 | - 'value' => sanitize_text_field( $_GET['type'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
772 | + 'value' => sanitize_text_field($_GET['type']), // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
773 | 773 | 'compare' => '=', |
774 | 774 | ); |
775 | 775 | } |
@@ -779,15 +779,15 @@ discard block |
||
779 | 779 | /** |
780 | 780 | * Reorders items. |
781 | 781 | */ |
782 | - public static function reorder_items( $vars ) { |
|
782 | + public static function reorder_items($vars) { |
|
783 | 783 | global $typenow; |
784 | 784 | |
785 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
785 | + if ('wpi_item' !== $typenow || empty($vars['orderby'])) { |
|
786 | 786 | return $vars; |
787 | 787 | } |
788 | 788 | |
789 | 789 | // By item type. |
790 | - if ( 'type' === $vars['orderby'] ) { |
|
790 | + if ('type' === $vars['orderby']) { |
|
791 | 791 | return array_merge( |
792 | 792 | $vars, |
793 | 793 | array( |
@@ -798,7 +798,7 @@ discard block |
||
798 | 798 | } |
799 | 799 | |
800 | 800 | // By vat class. |
801 | - if ( 'vat_class' === $vars['orderby'] ) { |
|
801 | + if ('vat_class' === $vars['orderby']) { |
|
802 | 802 | return array_merge( |
803 | 803 | $vars, |
804 | 804 | array( |
@@ -809,7 +809,7 @@ discard block |
||
809 | 809 | } |
810 | 810 | |
811 | 811 | // By vat rule. |
812 | - if ( 'vat_rule' === $vars['orderby'] ) { |
|
812 | + if ('vat_rule' === $vars['orderby']) { |
|
813 | 813 | return array_merge( |
814 | 814 | $vars, |
815 | 815 | array( |
@@ -820,7 +820,7 @@ discard block |
||
820 | 820 | } |
821 | 821 | |
822 | 822 | // By price. |
823 | - if ( 'price' === $vars['orderby'] ) { |
|
823 | + if ('price' === $vars['orderby']) { |
|
824 | 824 | return array_merge( |
825 | 825 | $vars, |
826 | 826 | array( |
@@ -837,27 +837,27 @@ discard block |
||
837 | 837 | /** |
838 | 838 | * Fired when deleting a post. |
839 | 839 | */ |
840 | - public static function delete_post( $post_id ) { |
|
840 | + public static function delete_post($post_id) { |
|
841 | 841 | |
842 | - switch ( get_post_type( $post_id ) ) { |
|
842 | + switch (get_post_type($post_id)) { |
|
843 | 843 | |
844 | 844 | case 'wpi_item': |
845 | - do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) ); |
|
845 | + do_action('getpaid_before_delete_item', new WPInv_Item($post_id)); |
|
846 | 846 | break; |
847 | 847 | |
848 | 848 | case 'wpi_payment_form': |
849 | - do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) ); |
|
849 | + do_action('getpaid_before_delete_payment_form', new GetPaid_Payment_Form($post_id)); |
|
850 | 850 | break; |
851 | 851 | |
852 | 852 | case 'wpi_discount': |
853 | - do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) ); |
|
853 | + do_action('getpaid_before_delete_discount', new WPInv_Discount($post_id)); |
|
854 | 854 | break; |
855 | 855 | |
856 | 856 | case 'wpi_invoice': |
857 | - $invoice = new WPInv_Invoice( $post_id ); |
|
858 | - do_action( 'getpaid_before_delete_invoice', $invoice ); |
|
859 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
860 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
857 | + $invoice = new WPInv_Invoice($post_id); |
|
858 | + do_action('getpaid_before_delete_invoice', $invoice); |
|
859 | + $invoice->get_data_store()->delete_items($invoice); |
|
860 | + $invoice->get_data_store()->delete_special_fields($invoice); |
|
861 | 861 | break; |
862 | 862 | } |
863 | 863 | } |
@@ -870,28 +870,28 @@ discard block |
||
870 | 870 | * |
871 | 871 | * @return mixed |
872 | 872 | */ |
873 | - public static function add_display_post_states( $post_states, $post ) { |
|
873 | + public static function add_display_post_states($post_states, $post) { |
|
874 | 874 | |
875 | - if ( wpinv_get_option( 'success_page', 0 ) == $post->ID ) { |
|
876 | - $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' ); |
|
875 | + if (wpinv_get_option('success_page', 0) == $post->ID) { |
|
876 | + $post_states['getpaid_success_page'] = __('GetPaid Receipt Page', 'invoicing'); |
|
877 | 877 | } |
878 | 878 | |
879 | - foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
879 | + foreach (getpaid_get_invoice_post_types() as $post_type => $label) { |
|
880 | 880 | |
881 | - if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
882 | - $post_states[ "getpaid_{$post_type}_history_page" ] = sprintf( |
|
883 | - __( 'GetPaid %s History Page', 'invoicing' ), |
|
881 | + if (wpinv_get_option("{$post_type}_history_page", 0) == $post->ID) { |
|
882 | + $post_states["getpaid_{$post_type}_history_page"] = sprintf( |
|
883 | + __('GetPaid %s History Page', 'invoicing'), |
|
884 | 884 | $label |
885 | 885 | ); |
886 | 886 | } |
887 | 887 | } |
888 | 888 | |
889 | - if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
890 | - $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' ); |
|
889 | + if (wpinv_get_option('invoice_subscription_page', 0) == $post->ID) { |
|
890 | + $post_states['getpaid_invoice_subscription_page'] = __('GetPaid Subscription Page', 'invoicing'); |
|
891 | 891 | } |
892 | 892 | |
893 | - if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
894 | - $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' ); |
|
893 | + if (wpinv_get_option('checkout_page', 0) == $post->ID) { |
|
894 | + $post_states['getpaid_checkout_page'] = __('GetPaid Checkout Page', 'invoicing'); |
|
895 | 895 | } |
896 | 896 | |
897 | 897 | return $post_states; |
@@ -14,93 +14,93 @@ discard block |
||
14 | 14 | class GetPaid_Admin { |
15 | 15 | |
16 | 16 | /** |
17 | - * Local path to this plugins admin directory |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $admin_path; |
|
22 | - |
|
23 | - /** |
|
24 | - * Web path to this plugins admin directory |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $admin_url; |
|
29 | - |
|
30 | - /** |
|
31 | - * Reports components. |
|
32 | - * |
|
33 | - * @var GetPaid_Reports |
|
34 | - */ |
|
17 | + * Local path to this plugins admin directory |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $admin_path; |
|
22 | + |
|
23 | + /** |
|
24 | + * Web path to this plugins admin directory |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + public $admin_url; |
|
29 | + |
|
30 | + /** |
|
31 | + * Reports components. |
|
32 | + * |
|
33 | + * @var GetPaid_Reports |
|
34 | + */ |
|
35 | 35 | public $reports; |
36 | 36 | |
37 | 37 | /** |
38 | - * Class constructor. |
|
39 | - */ |
|
40 | - public function __construct() { |
|
38 | + * Class constructor. |
|
39 | + */ |
|
40 | + public function __construct() { |
|
41 | 41 | |
42 | 42 | $this->admin_path = plugin_dir_path( __FILE__ ); |
43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | - $this->reports = new GetPaid_Reports(); |
|
43 | + $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | + $this->reports = new GetPaid_Reports(); |
|
45 | 45 | |
46 | 46 | if ( is_admin() ) { |
47 | - $this->init_admin_hooks(); |
|
47 | + $this->init_admin_hooks(); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | - * Init action and filter hooks |
|
54 | - * |
|
55 | - */ |
|
56 | - private function init_admin_hooks() { |
|
53 | + * Init action and filter hooks |
|
54 | + * |
|
55 | + */ |
|
56 | + private function init_admin_hooks() { |
|
57 | 57 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 ); |
58 | 58 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
59 | 59 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
60 | 60 | add_action( 'admin_init', array( $this, 'activation_redirect' ) ); |
61 | 61 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action' ) ); |
62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | - add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | - add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) ); |
|
66 | - add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
67 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
68 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
62 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | + add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | + add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | + add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) ); |
|
66 | + add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
67 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
68 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
69 | 69 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
70 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
71 | - add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
72 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
73 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
74 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
75 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
76 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
77 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
78 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
79 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
80 | - |
|
81 | - // Setup/welcome |
|
82 | - if ( ! empty( $_GET['page'] ) ) { |
|
83 | - switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
84 | - case 'gp-setup': |
|
85 | - include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
86 | - break; |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Register admin scripts |
|
94 | - * |
|
95 | - */ |
|
96 | - public function enqeue_scripts() { |
|
70 | + add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
71 | + add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
72 | + add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
73 | + add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
74 | + add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
75 | + add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
76 | + add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
77 | + add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
78 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
79 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
80 | + |
|
81 | + // Setup/welcome |
|
82 | + if ( ! empty( $_GET['page'] ) ) { |
|
83 | + switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
84 | + case 'gp-setup': |
|
85 | + include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
86 | + break; |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Register admin scripts |
|
94 | + * |
|
95 | + */ |
|
96 | + public function enqeue_scripts() { |
|
97 | 97 | global $current_screen, $pagenow; |
98 | 98 | |
99 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
100 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
99 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
100 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
101 | 101 | |
102 | 102 | if ( ! empty( $current_screen->post_type ) ) { |
103 | - $page = $current_screen->post_type; |
|
103 | + $page = $current_screen->post_type; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | // General styles. |
@@ -121,53 +121,53 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | // Payment form scripts. |
124 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
124 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
125 | 125 | $this->load_payment_form_scripts(); |
126 | 126 | } |
127 | 127 | |
128 | - if ( $page == 'wpinv-subscriptions' ) { |
|
129 | - wp_enqueue_script( 'postbox' ); |
|
130 | - } |
|
128 | + if ( $page == 'wpinv-subscriptions' ) { |
|
129 | + wp_enqueue_script( 'postbox' ); |
|
130 | + } |
|
131 | 131 | |
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | - * Returns admin js translations. |
|
136 | - * |
|
137 | - */ |
|
138 | - protected function get_admin_i18() { |
|
135 | + * Returns admin js translations. |
|
136 | + * |
|
137 | + */ |
|
138 | + protected function get_admin_i18() { |
|
139 | 139 | global $post; |
140 | 140 | |
141 | - $date_range = array( |
|
142 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
143 | - ); |
|
141 | + $date_range = array( |
|
142 | + 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
143 | + ); |
|
144 | 144 | |
145 | - if ( $date_range['period'] == 'custom' ) { |
|
145 | + if ( $date_range['period'] == 'custom' ) { |
|
146 | 146 | |
147 | - if ( isset( $_GET['from'] ) ) { |
|
148 | - $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
149 | - } |
|
147 | + if ( isset( $_GET['from'] ) ) { |
|
148 | + $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
149 | + } |
|
150 | 150 | |
151 | - if ( isset( $_GET['to'] ) ) { |
|
152 | - $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
153 | - } |
|
151 | + if ( isset( $_GET['to'] ) ) { |
|
152 | + $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
153 | + } |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | $i18n = array( |
157 | 157 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
158 | 158 | 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
159 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
160 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
161 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
162 | - 'date_range' => $date_range, |
|
159 | + 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
160 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
161 | + 'rest_root' => esc_url_raw( rest_url() ), |
|
162 | + 'date_range' => $date_range, |
|
163 | 163 | 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
164 | 164 | 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
165 | 165 | 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
166 | 166 | 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
167 | 167 | 'tax' => wpinv_tax_amount(), |
168 | 168 | 'discount' => 0, |
169 | - 'currency_symbol' => wpinv_currency_symbol(), |
|
170 | - 'currency' => wpinv_get_currency(), |
|
169 | + 'currency_symbol' => wpinv_currency_symbol(), |
|
170 | + 'currency' => wpinv_get_currency(), |
|
171 | 171 | 'currency_pos' => wpinv_currency_position(), |
172 | 172 | 'thousand_sep' => wpinv_thousands_separator(), |
173 | 173 | 'decimal_sep' => wpinv_decimal_separator(), |
@@ -187,118 +187,118 @@ discard block |
||
187 | 187 | 'item_description' => __( 'Item Description', 'invoicing' ), |
188 | 188 | 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
189 | 189 | 'discount_description' => __( 'Discount Description', 'invoicing' ), |
190 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
191 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
192 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
193 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
194 | - 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
190 | + 'searching' => __( 'Searching', 'invoicing' ), |
|
191 | + 'loading' => __( 'Loading...', 'invoicing' ), |
|
192 | + 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
193 | + 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
194 | + 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
195 | 195 | ); |
196 | 196 | |
197 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
197 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
198 | 198 | |
199 | - $invoice = new WPInv_Invoice( $post ); |
|
200 | - $i18n['save_invoice'] = sprintf( |
|
201 | - __( 'Save %s', 'invoicing' ), |
|
202 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
203 | - ); |
|
199 | + $invoice = new WPInv_Invoice( $post ); |
|
200 | + $i18n['save_invoice'] = sprintf( |
|
201 | + __( 'Save %s', 'invoicing' ), |
|
202 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
203 | + ); |
|
204 | 204 | |
205 | - $i18n['invoice_description'] = sprintf( |
|
206 | - __( '%s Description', 'invoicing' ), |
|
207 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
208 | - ); |
|
205 | + $i18n['invoice_description'] = sprintf( |
|
206 | + __( '%s Description', 'invoicing' ), |
|
207 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
208 | + ); |
|
209 | 209 | |
210 | - } |
|
211 | - return $i18n; |
|
212 | - } |
|
210 | + } |
|
211 | + return $i18n; |
|
212 | + } |
|
213 | 213 | |
214 | - /** |
|
215 | - * Change the admin footer text on GetPaid admin pages. |
|
216 | - * |
|
217 | - * @since 2.0.0 |
|
218 | - * @param string $footer_text |
|
219 | - * @return string |
|
220 | - */ |
|
221 | - public function admin_footer_text( $footer_text ) { |
|
222 | - global $current_screen; |
|
214 | + /** |
|
215 | + * Change the admin footer text on GetPaid admin pages. |
|
216 | + * |
|
217 | + * @since 2.0.0 |
|
218 | + * @param string $footer_text |
|
219 | + * @return string |
|
220 | + */ |
|
221 | + public function admin_footer_text( $footer_text ) { |
|
222 | + global $current_screen; |
|
223 | 223 | |
224 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
224 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
225 | 225 | |
226 | 226 | if ( ! empty( $current_screen->post_type ) ) { |
227 | - $page = $current_screen->post_type; |
|
227 | + $page = $current_screen->post_type; |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | // General styles. |
231 | 231 | if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
232 | 232 | |
233 | - // Change the footer text |
|
234 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
233 | + // Change the footer text |
|
234 | + if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
235 | 235 | |
236 | - $rating_url = esc_url( |
|
237 | - wp_nonce_url( |
|
238 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
239 | - 'getpaid-nonce', |
|
240 | - 'getpaid-nonce' |
|
236 | + $rating_url = esc_url( |
|
237 | + wp_nonce_url( |
|
238 | + admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
239 | + 'getpaid-nonce', |
|
240 | + 'getpaid-nonce' |
|
241 | 241 | ) |
242 | - ); |
|
242 | + ); |
|
243 | 243 | |
244 | - $footer_text = sprintf( |
|
245 | - /* translators: %s: five stars */ |
|
246 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
247 | - "<a href='$rating_url'>★★★★★</a>" |
|
248 | - ); |
|
244 | + $footer_text = sprintf( |
|
245 | + /* translators: %s: five stars */ |
|
246 | + __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
247 | + "<a href='$rating_url'>★★★★★</a>" |
|
248 | + ); |
|
249 | 249 | |
250 | - } else { |
|
250 | + } else { |
|
251 | 251 | |
252 | - $footer_text = sprintf( |
|
253 | - /* translators: %s: GetPaid */ |
|
254 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
255 | - "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
256 | - ); |
|
252 | + $footer_text = sprintf( |
|
253 | + /* translators: %s: GetPaid */ |
|
254 | + __( 'Thank you for using %s!', 'invoicing' ), |
|
255 | + "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
256 | + ); |
|
257 | 257 | |
258 | - } |
|
258 | + } |
|
259 | 259 | } |
260 | 260 | |
261 | - return $footer_text; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Redirects to wp.org to rate the plugin. |
|
266 | - * |
|
267 | - * @since 2.0.0 |
|
268 | - */ |
|
269 | - public function redirect_to_wordpress_rating_page() { |
|
270 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
271 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
272 | - exit; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Loads payment form js. |
|
277 | - * |
|
278 | - */ |
|
279 | - protected function load_payment_form_scripts() { |
|
261 | + return $footer_text; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Redirects to wp.org to rate the plugin. |
|
266 | + * |
|
267 | + * @since 2.0.0 |
|
268 | + */ |
|
269 | + public function redirect_to_wordpress_rating_page() { |
|
270 | + update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
271 | + wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
272 | + exit; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Loads payment form js. |
|
277 | + * |
|
278 | + */ |
|
279 | + protected function load_payment_form_scripts() { |
|
280 | 280 | global $post; |
281 | 281 | |
282 | 282 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
283 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
284 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
283 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
284 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
285 | 285 | |
286 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
287 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
286 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
287 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
288 | 288 | |
289 | - wp_localize_script( |
|
289 | + wp_localize_script( |
|
290 | 290 | 'wpinv-admin-payment-form-script', |
291 | 291 | 'wpinvPaymentFormAdmin', |
292 | 292 | array( |
293 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
294 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
295 | - 'currency' => wpinv_currency_symbol(), |
|
296 | - 'position' => wpinv_currency_position(), |
|
297 | - 'decimals' => (int) wpinv_decimals(), |
|
298 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
299 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
300 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
301 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
293 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
294 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
295 | + 'currency' => wpinv_currency_symbol(), |
|
296 | + 'position' => wpinv_currency_position(), |
|
297 | + 'decimals' => (int) wpinv_decimals(), |
|
298 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
299 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
300 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
301 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
302 | 302 | ) |
303 | 303 | ); |
304 | 304 | |
@@ -307,19 +307,19 @@ discard block |
||
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
310 | - * Add our classes to admin pages. |
|
310 | + * Add our classes to admin pages. |
|
311 | 311 | * |
312 | 312 | * @param string $classes |
313 | 313 | * @return string |
314 | - * |
|
315 | - */ |
|
314 | + * |
|
315 | + */ |
|
316 | 316 | public function admin_body_class( $classes ) { |
317 | - global $pagenow, $post, $current_screen; |
|
317 | + global $pagenow, $post, $current_screen; |
|
318 | 318 | |
319 | 319 | $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
320 | 320 | |
321 | 321 | if ( ! empty( $current_screen->post_type ) ) { |
322 | - $page = $current_screen->post_type; |
|
322 | + $page = $current_screen->post_type; |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -328,70 +328,70 @@ discard block |
||
328 | 328 | |
329 | 329 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
330 | 330 | $classes .= ' wpinv-cpt wpinv'; |
331 | - } |
|
331 | + } |
|
332 | 332 | |
333 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
333 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
334 | 334 | $classes .= ' getpaid-is-invoice-cpt'; |
335 | 335 | } |
336 | 336 | |
337 | - return $classes; |
|
337 | + return $classes; |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
341 | - * Maybe show the AyeCode Connect Notice. |
|
342 | - */ |
|
343 | - public function init_ayecode_connect_helper() { |
|
341 | + * Maybe show the AyeCode Connect Notice. |
|
342 | + */ |
|
343 | + public function init_ayecode_connect_helper() { |
|
344 | 344 | |
345 | - // Register with the deactivation survey class. |
|
346 | - AyeCode_Deactivation_Survey::instance( |
|
345 | + // Register with the deactivation survey class. |
|
346 | + AyeCode_Deactivation_Survey::instance( |
|
347 | 347 | array( |
348 | - 'slug' => 'invoicing', |
|
349 | - 'version' => WPINV_VERSION, |
|
350 | - 'support_url' => 'https://wpgetpaid.com/support/', |
|
351 | - 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
352 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
348 | + 'slug' => 'invoicing', |
|
349 | + 'version' => WPINV_VERSION, |
|
350 | + 'support_url' => 'https://wpgetpaid.com/support/', |
|
351 | + 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
352 | + 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
353 | 353 | ) |
354 | 354 | ); |
355 | 355 | |
356 | 356 | new AyeCode_Connect_Helper( |
357 | 357 | array( |
358 | - 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
359 | - 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
360 | - 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
361 | - 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
362 | - 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
363 | - 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
364 | - 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
358 | + 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
359 | + 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
360 | + 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
361 | + 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
362 | + 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
363 | + 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
364 | + 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
365 | 365 | ), |
366 | 366 | array( 'wpi-addons' ) |
367 | 367 | ); |
368 | 368 | |
369 | 369 | } |
370 | 370 | |
371 | - /** |
|
372 | - * Redirect users to settings on activation. |
|
373 | - * |
|
374 | - * @return void |
|
375 | - */ |
|
376 | - public function activation_redirect() { |
|
371 | + /** |
|
372 | + * Redirect users to settings on activation. |
|
373 | + * |
|
374 | + * @return void |
|
375 | + */ |
|
376 | + public function activation_redirect() { |
|
377 | 377 | |
378 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
378 | + $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
379 | 379 | |
380 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
381 | - return; |
|
382 | - } |
|
380 | + if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
381 | + return; |
|
382 | + } |
|
383 | 383 | |
384 | - // Bail if activating from network, or bulk |
|
385 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
386 | - return; |
|
387 | - } |
|
384 | + // Bail if activating from network, or bulk |
|
385 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
386 | + return; |
|
387 | + } |
|
388 | 388 | |
389 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
389 | + update_option( 'wpinv_redirected_to_settings', 1 ); |
|
390 | 390 | |
391 | 391 | wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
392 | 392 | exit; |
393 | 393 | |
394 | - } |
|
394 | + } |
|
395 | 395 | |
396 | 396 | /** |
397 | 397 | * Fires an admin action after verifying that a user can fire them. |
@@ -405,564 +405,564 @@ discard block |
||
405 | 405 | |
406 | 406 | } |
407 | 407 | |
408 | - /** |
|
408 | + /** |
|
409 | 409 | * Duplicate invoice. |
410 | - * |
|
411 | - * @param array $args |
|
410 | + * |
|
411 | + * @param array $args |
|
412 | 412 | */ |
413 | 413 | public function duplicate_invoice( $args ) { |
414 | 414 | |
415 | - if ( empty( $args['invoice_id'] ) ) { |
|
416 | - return; |
|
417 | - } |
|
415 | + if ( empty( $args['invoice_id'] ) ) { |
|
416 | + return; |
|
417 | + } |
|
418 | 418 | |
419 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
419 | + $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
420 | 420 | |
421 | - if ( ! $invoice->exists() ) { |
|
422 | - return; |
|
423 | - } |
|
421 | + if ( ! $invoice->exists() ) { |
|
422 | + return; |
|
423 | + } |
|
424 | 424 | |
425 | - $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
426 | - $new_invoice->save(); |
|
425 | + $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
426 | + $new_invoice->save(); |
|
427 | 427 | |
428 | - if ( $new_invoice->exists() ) { |
|
428 | + if ( $new_invoice->exists() ) { |
|
429 | 429 | |
430 | - getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) ); |
|
430 | + getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) ); |
|
431 | 431 | |
432 | - wp_safe_redirect( |
|
433 | - add_query_arg( |
|
434 | - array( |
|
435 | - 'action' => 'edit', |
|
436 | - 'post' => $new_invoice->get_id(), |
|
437 | - ), |
|
438 | - admin_url( 'post.php' ) |
|
439 | - ) |
|
440 | - ); |
|
441 | - exit; |
|
432 | + wp_safe_redirect( |
|
433 | + add_query_arg( |
|
434 | + array( |
|
435 | + 'action' => 'edit', |
|
436 | + 'post' => $new_invoice->get_id(), |
|
437 | + ), |
|
438 | + admin_url( 'post.php' ) |
|
439 | + ) |
|
440 | + ); |
|
441 | + exit; |
|
442 | 442 | |
443 | - } |
|
443 | + } |
|
444 | 444 | |
445 | - getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) ); |
|
445 | + getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) ); |
|
446 | 446 | |
447 | - } |
|
447 | + } |
|
448 | 448 | |
449 | - /** |
|
449 | + /** |
|
450 | 450 | * Sends a payment reminder to a customer. |
451 | - * |
|
452 | - * @param array $args |
|
451 | + * |
|
452 | + * @param array $args |
|
453 | 453 | */ |
454 | 454 | public function duplicate_payment_form( $args ) { |
455 | 455 | |
456 | - if ( empty( $args['form_id'] ) ) { |
|
457 | - return; |
|
458 | - } |
|
459 | - |
|
460 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
456 | + if ( empty( $args['form_id'] ) ) { |
|
457 | + return; |
|
458 | + } |
|
461 | 459 | |
462 | - if ( ! $form->exists() ) { |
|
463 | - return; |
|
464 | - } |
|
460 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
465 | 461 | |
466 | - $new_form = new GetPaid_Payment_Form(); |
|
467 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
468 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
469 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
470 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
471 | - $new_form->save(); |
|
462 | + if ( ! $form->exists() ) { |
|
463 | + return; |
|
464 | + } |
|
472 | 465 | |
473 | - if ( $new_form->exists() ) { |
|
474 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
475 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
476 | - } else { |
|
477 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
478 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
479 | - } |
|
466 | + $new_form = new GetPaid_Payment_Form(); |
|
467 | + $new_form->set_author( $form->get_author( 'edit' ) ); |
|
468 | + $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
469 | + $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
470 | + $new_form->set_items( $form->get_items( 'edit' ) ); |
|
471 | + $new_form->save(); |
|
472 | + |
|
473 | + if ( $new_form->exists() ) { |
|
474 | + $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
475 | + $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
476 | + } else { |
|
477 | + $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
478 | + $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
479 | + } |
|
480 | 480 | |
481 | - wp_redirect( $url ); |
|
482 | - exit; |
|
483 | - } |
|
481 | + wp_redirect( $url ); |
|
482 | + exit; |
|
483 | + } |
|
484 | 484 | |
485 | - /** |
|
485 | + /** |
|
486 | 486 | * Resets form stats. |
487 | - * |
|
488 | - * @param array $args |
|
487 | + * |
|
488 | + * @param array $args |
|
489 | 489 | */ |
490 | 490 | public function reset_form_stats( $args ) { |
491 | 491 | |
492 | - if ( empty( $args['form_id'] ) ) { |
|
493 | - return; |
|
494 | - } |
|
492 | + if ( empty( $args['form_id'] ) ) { |
|
493 | + return; |
|
494 | + } |
|
495 | 495 | |
496 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
496 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
497 | 497 | |
498 | - if ( ! $form->exists() ) { |
|
499 | - return; |
|
500 | - } |
|
498 | + if ( ! $form->exists() ) { |
|
499 | + return; |
|
500 | + } |
|
501 | 501 | |
502 | - $form->set_earned( 0 ); |
|
503 | - $form->set_refunded( 0 ); |
|
504 | - $form->set_cancelled( 0 ); |
|
505 | - $form->set_failed( 0 ); |
|
506 | - $form->save(); |
|
502 | + $form->set_earned( 0 ); |
|
503 | + $form->set_refunded( 0 ); |
|
504 | + $form->set_cancelled( 0 ); |
|
505 | + $form->set_failed( 0 ); |
|
506 | + $form->save(); |
|
507 | 507 | |
508 | - $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) ); |
|
508 | + $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) ); |
|
509 | 509 | |
510 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) ); |
|
511 | - exit; |
|
512 | - } |
|
510 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) ); |
|
511 | + exit; |
|
512 | + } |
|
513 | 513 | |
514 | - /** |
|
514 | + /** |
|
515 | 515 | * Sends a payment reminder to a customer. |
516 | - * |
|
517 | - * @param array $args |
|
516 | + * |
|
517 | + * @param array $args |
|
518 | 518 | */ |
519 | 519 | public function send_customer_invoice( $args ) { |
520 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
521 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
522 | - exit; |
|
523 | - } |
|
520 | + getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
521 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
522 | + exit; |
|
523 | + } |
|
524 | 524 | |
525 | - /** |
|
525 | + /** |
|
526 | 526 | * Sends a payment reminder to a customer. |
527 | - * |
|
528 | - * @param array $args |
|
527 | + * |
|
528 | + * @param array $args |
|
529 | 529 | */ |
530 | 530 | public function send_customer_payment_reminder( $args ) { |
531 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
531 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
532 | 532 | |
533 | - if ( $sent ) { |
|
534 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
535 | - } else { |
|
536 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
537 | - } |
|
533 | + if ( $sent ) { |
|
534 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
535 | + } else { |
|
536 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
537 | + } |
|
538 | 538 | |
539 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
540 | - exit; |
|
541 | - } |
|
539 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
540 | + exit; |
|
541 | + } |
|
542 | 542 | |
543 | - /** |
|
543 | + /** |
|
544 | 544 | * Resets tax rates. |
545 | - * |
|
545 | + * |
|
546 | 546 | */ |
547 | 547 | public function admin_reset_tax_rates() { |
548 | 548 | |
549 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
550 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
551 | - exit; |
|
549 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
550 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
551 | + exit; |
|
552 | 552 | |
553 | - } |
|
553 | + } |
|
554 | 554 | |
555 | - /** |
|
555 | + /** |
|
556 | 556 | * Resets admin pages. |
557 | - * |
|
557 | + * |
|
558 | 558 | */ |
559 | 559 | public function admin_create_missing_pages() { |
560 | - $installer = new GetPaid_Installer(); |
|
561 | - $installer->create_pages(); |
|
562 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
563 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
564 | - exit; |
|
565 | - } |
|
566 | - |
|
567 | - /** |
|
568 | - * Refreshes the permalinks. |
|
569 | - */ |
|
570 | - public function admin_refresh_permalinks() { |
|
571 | - flush_rewrite_rules(); |
|
572 | - $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
573 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
574 | - exit; |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
560 | + $installer = new GetPaid_Installer(); |
|
561 | + $installer->create_pages(); |
|
562 | + $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
563 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
564 | + exit; |
|
565 | + } |
|
566 | + |
|
567 | + /** |
|
568 | + * Refreshes the permalinks. |
|
569 | + */ |
|
570 | + public function admin_refresh_permalinks() { |
|
571 | + flush_rewrite_rules(); |
|
572 | + $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
573 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
574 | + exit; |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | 578 | * Creates an missing admin tables. |
579 | - * |
|
579 | + * |
|
580 | 580 | */ |
581 | 581 | public function admin_create_missing_tables() { |
582 | - global $wpdb; |
|
583 | - $installer = new GetPaid_Installer(); |
|
582 | + global $wpdb; |
|
583 | + $installer = new GetPaid_Installer(); |
|
584 | 584 | |
585 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
586 | - $installer->create_subscriptions_table(); |
|
585 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
586 | + $installer->create_subscriptions_table(); |
|
587 | 587 | |
588 | - if ( $wpdb->last_error !== '' ) { |
|
589 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
590 | - } |
|
591 | - } |
|
588 | + if ( $wpdb->last_error !== '' ) { |
|
589 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
590 | + } |
|
591 | + } |
|
592 | 592 | |
593 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
594 | - $installer->create_invoices_table(); |
|
593 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
594 | + $installer->create_invoices_table(); |
|
595 | 595 | |
596 | - if ( '' !== $wpdb->last_error ) { |
|
597 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
598 | - } |
|
599 | - } |
|
596 | + if ( '' !== $wpdb->last_error ) { |
|
597 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
598 | + } |
|
599 | + } |
|
600 | 600 | |
601 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
602 | - $installer->create_invoice_items_table(); |
|
601 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
602 | + $installer->create_invoice_items_table(); |
|
603 | 603 | |
604 | - if ( '' !== $wpdb->last_error ) { |
|
605 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
606 | - } |
|
607 | - } |
|
604 | + if ( '' !== $wpdb->last_error ) { |
|
605 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
606 | + } |
|
607 | + } |
|
608 | 608 | |
609 | - if ( ! $this->has_notices() ) { |
|
610 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
611 | - } |
|
609 | + if ( ! $this->has_notices() ) { |
|
610 | + $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
611 | + } |
|
612 | 612 | |
613 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
614 | - exit; |
|
615 | - } |
|
613 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
614 | + exit; |
|
615 | + } |
|
616 | 616 | |
617 | - /** |
|
617 | + /** |
|
618 | 618 | * Migrates old invoices to the new database tables. |
619 | - * |
|
619 | + * |
|
620 | 620 | */ |
621 | 621 | public function admin_migrate_old_invoices() { |
622 | 622 | |
623 | - // Migrate the invoices. |
|
624 | - $installer = new GetPaid_Installer(); |
|
625 | - $installer->migrate_old_invoices(); |
|
623 | + // Migrate the invoices. |
|
624 | + $installer = new GetPaid_Installer(); |
|
625 | + $installer->migrate_old_invoices(); |
|
626 | 626 | |
627 | - // Show an admin message. |
|
628 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
627 | + // Show an admin message. |
|
628 | + $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
629 | 629 | |
630 | - // Redirect the admin. |
|
631 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
632 | - exit; |
|
630 | + // Redirect the admin. |
|
631 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
632 | + exit; |
|
633 | 633 | |
634 | - } |
|
634 | + } |
|
635 | 635 | |
636 | - /** |
|
636 | + /** |
|
637 | 637 | * Download customers. |
638 | - * |
|
638 | + * |
|
639 | 639 | */ |
640 | 640 | public function admin_download_customers() { |
641 | - global $wpdb; |
|
642 | - |
|
643 | - $output = fopen( 'php://output', 'w' ); |
|
644 | - |
|
645 | - if ( false === $output ) { |
|
646 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
647 | - } |
|
641 | + global $wpdb; |
|
648 | 642 | |
649 | - header( 'Content-Type:text/csv' ); |
|
650 | - header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
643 | + $output = fopen( 'php://output', 'w' ); |
|
651 | 644 | |
652 | - $post_types = ''; |
|
645 | + if ( false === $output ) { |
|
646 | + wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
647 | + } |
|
653 | 648 | |
654 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
655 | - $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
656 | - } |
|
649 | + header( 'Content-Type:text/csv' ); |
|
650 | + header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
657 | 651 | |
658 | - $post_types = rtrim( $post_types, ' OR' ); |
|
652 | + $post_types = ''; |
|
659 | 653 | |
660 | - $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" ); |
|
654 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
655 | + $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
656 | + } |
|
661 | 657 | |
662 | - $columns = array( |
|
663 | - 'name' => __( 'Name', 'invoicing' ), |
|
664 | - 'email' => __( 'Email', 'invoicing' ), |
|
665 | - 'country' => __( 'Country', 'invoicing' ), |
|
666 | - 'state' => __( 'State', 'invoicing' ), |
|
667 | - 'city' => __( 'City', 'invoicing' ), |
|
668 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
669 | - 'address' => __( 'Address', 'invoicing' ), |
|
670 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
671 | - 'company' => __( 'Company', 'invoicing' ), |
|
672 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
673 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
674 | - 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
675 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
676 | - ); |
|
658 | + $post_types = rtrim( $post_types, ' OR' ); |
|
659 | + |
|
660 | + $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" ); |
|
661 | + |
|
662 | + $columns = array( |
|
663 | + 'name' => __( 'Name', 'invoicing' ), |
|
664 | + 'email' => __( 'Email', 'invoicing' ), |
|
665 | + 'country' => __( 'Country', 'invoicing' ), |
|
666 | + 'state' => __( 'State', 'invoicing' ), |
|
667 | + 'city' => __( 'City', 'invoicing' ), |
|
668 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
669 | + 'address' => __( 'Address', 'invoicing' ), |
|
670 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
671 | + 'company' => __( 'Company', 'invoicing' ), |
|
672 | + 'company_id' => __( 'Company ID', 'invoicing' ), |
|
673 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
674 | + 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
675 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
676 | + ); |
|
677 | 677 | |
678 | - // Output the csv column headers. |
|
679 | - fputcsv( $output, array_values( $columns ) ); |
|
678 | + // Output the csv column headers. |
|
679 | + fputcsv( $output, array_values( $columns ) ); |
|
680 | 680 | |
681 | - // Loop through |
|
682 | - $table = new WPInv_Customers_Table(); |
|
683 | - foreach ( $customers as $customer_id ) { |
|
681 | + // Loop through |
|
682 | + $table = new WPInv_Customers_Table(); |
|
683 | + foreach ( $customers as $customer_id ) { |
|
684 | 684 | |
685 | - $user = get_user_by( 'id', $customer_id ); |
|
686 | - $row = array(); |
|
687 | - if ( empty( $user ) ) { |
|
688 | - continue; |
|
689 | - } |
|
685 | + $user = get_user_by( 'id', $customer_id ); |
|
686 | + $row = array(); |
|
687 | + if ( empty( $user ) ) { |
|
688 | + continue; |
|
689 | + } |
|
690 | 690 | |
691 | - foreach ( array_keys( $columns ) as $column ) { |
|
691 | + foreach ( array_keys( $columns ) as $column ) { |
|
692 | 692 | |
693 | - $method = 'column_' . $column; |
|
693 | + $method = 'column_' . $column; |
|
694 | 694 | |
695 | - if ( 'name' == $column ) { |
|
696 | - $value = esc_html( $user->display_name ); |
|
697 | - } elseif ( 'email' == $column ) { |
|
698 | - $value = sanitize_email( $user->user_email ); |
|
699 | - } elseif ( is_callable( array( $table, $method ) ) ) { |
|
700 | - $value = wp_strip_all_tags( $table->$method( $user ) ); |
|
701 | - } |
|
695 | + if ( 'name' == $column ) { |
|
696 | + $value = esc_html( $user->display_name ); |
|
697 | + } elseif ( 'email' == $column ) { |
|
698 | + $value = sanitize_email( $user->user_email ); |
|
699 | + } elseif ( is_callable( array( $table, $method ) ) ) { |
|
700 | + $value = wp_strip_all_tags( $table->$method( $user ) ); |
|
701 | + } |
|
702 | 702 | |
703 | - if ( empty( $value ) ) { |
|
704 | - $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
705 | - } |
|
703 | + if ( empty( $value ) ) { |
|
704 | + $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
705 | + } |
|
706 | 706 | |
707 | - $row[] = $value; |
|
707 | + $row[] = $value; |
|
708 | 708 | |
709 | - } |
|
709 | + } |
|
710 | 710 | |
711 | - fputcsv( $output, $row ); |
|
712 | - } |
|
711 | + fputcsv( $output, $row ); |
|
712 | + } |
|
713 | 713 | |
714 | - fclose( $output ); |
|
715 | - exit; |
|
714 | + fclose( $output ); |
|
715 | + exit; |
|
716 | 716 | |
717 | - } |
|
717 | + } |
|
718 | 718 | |
719 | - /** |
|
719 | + /** |
|
720 | 720 | * Installs a plugin. |
721 | - * |
|
722 | - * @param array $data |
|
721 | + * |
|
722 | + * @param array $data |
|
723 | 723 | */ |
724 | 724 | public function admin_install_plugin( $data ) { |
725 | 725 | |
726 | - if ( ! empty( $data['plugins'] ) ) { |
|
727 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
728 | - wp_cache_flush(); |
|
726 | + if ( ! empty( $data['plugins'] ) ) { |
|
727 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
728 | + wp_cache_flush(); |
|
729 | 729 | |
730 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
731 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
732 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
733 | - $installed = $upgrader->install( $plugin_zip ); |
|
730 | + foreach ( $data['plugins'] as $slug => $file ) { |
|
731 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
732 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
733 | + $installed = $upgrader->install( $plugin_zip ); |
|
734 | 734 | |
735 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
736 | - activate_plugin( $file, '', false, true ); |
|
737 | - } else { |
|
738 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
739 | - } |
|
735 | + if ( ! is_wp_error( $installed ) && $installed ) { |
|
736 | + activate_plugin( $file, '', false, true ); |
|
737 | + } else { |
|
738 | + wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
739 | + } |
|
740 | 740 | } |
741 | 741 | } |
742 | 742 | |
743 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
744 | - wp_safe_redirect( $redirect ); |
|
745 | - exit; |
|
743 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
744 | + wp_safe_redirect( $redirect ); |
|
745 | + exit; |
|
746 | 746 | |
747 | - } |
|
747 | + } |
|
748 | 748 | |
749 | - /** |
|
749 | + /** |
|
750 | 750 | * Connects a gateway. |
751 | - * |
|
752 | - * @param array $data |
|
751 | + * |
|
752 | + * @param array $data |
|
753 | 753 | */ |
754 | 754 | public function admin_connect_gateway( $data ) { |
755 | 755 | |
756 | - if ( ! empty( $data['plugin'] ) ) { |
|
756 | + if ( ! empty( $data['plugin'] ) ) { |
|
757 | 757 | |
758 | - $gateway = sanitize_key( $data['plugin'] ); |
|
759 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
758 | + $gateway = sanitize_key( $data['plugin'] ); |
|
759 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
760 | 760 | |
761 | - if ( ! empty( $connect_url ) ) { |
|
762 | - wp_redirect( $connect_url ); |
|
763 | - exit; |
|
764 | - } |
|
761 | + if ( ! empty( $connect_url ) ) { |
|
762 | + wp_redirect( $connect_url ); |
|
763 | + exit; |
|
764 | + } |
|
765 | 765 | |
766 | - if ( 'stripe' == $data['plugin'] ) { |
|
767 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
768 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
769 | - wp_cache_flush(); |
|
766 | + if ( 'stripe' == $data['plugin'] ) { |
|
767 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
768 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
769 | + wp_cache_flush(); |
|
770 | 770 | |
771 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
772 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
773 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
774 | - $upgrader->install( $plugin_zip ); |
|
775 | - } |
|
771 | + if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
772 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
773 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
774 | + $upgrader->install( $plugin_zip ); |
|
775 | + } |
|
776 | 776 | |
777 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
778 | - } |
|
777 | + activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
778 | + } |
|
779 | 779 | |
780 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
781 | - if ( ! empty( $connect_url ) ) { |
|
782 | - wp_redirect( $connect_url ); |
|
783 | - exit; |
|
784 | - } |
|
780 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
781 | + if ( ! empty( $connect_url ) ) { |
|
782 | + wp_redirect( $connect_url ); |
|
783 | + exit; |
|
784 | + } |
|
785 | 785 | } |
786 | 786 | |
787 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
788 | - wp_safe_redirect( $redirect ); |
|
789 | - exit; |
|
787 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
788 | + wp_safe_redirect( $redirect ); |
|
789 | + exit; |
|
790 | 790 | |
791 | - } |
|
791 | + } |
|
792 | 792 | |
793 | - /** |
|
793 | + /** |
|
794 | 794 | * Recalculates discounts. |
795 | - * |
|
795 | + * |
|
796 | 796 | */ |
797 | 797 | public function admin_recalculate_discounts() { |
798 | - global $wpdb; |
|
798 | + global $wpdb; |
|
799 | 799 | |
800 | - // Fetch all invoices that have discount codes. |
|
801 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
802 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
800 | + // Fetch all invoices that have discount codes. |
|
801 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
802 | + $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
803 | 803 | |
804 | - foreach ( $invoices as $invoice ) { |
|
804 | + foreach ( $invoices as $invoice ) { |
|
805 | 805 | |
806 | - $invoice = new WPInv_Invoice( $invoice ); |
|
806 | + $invoice = new WPInv_Invoice( $invoice ); |
|
807 | 807 | |
808 | - if ( ! $invoice->exists() ) { |
|
809 | - continue; |
|
810 | - } |
|
808 | + if ( ! $invoice->exists() ) { |
|
809 | + continue; |
|
810 | + } |
|
811 | 811 | |
812 | - // Abort if the discount does not exist or does not apply here. |
|
813 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
814 | - if ( ! $discount->exists() ) { |
|
815 | - continue; |
|
816 | - } |
|
812 | + // Abort if the discount does not exist or does not apply here. |
|
813 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
814 | + if ( ! $discount->exists() ) { |
|
815 | + continue; |
|
816 | + } |
|
817 | 817 | |
818 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
819 | - $invoice->recalculate_total(); |
|
818 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
819 | + $invoice->recalculate_total(); |
|
820 | 820 | |
821 | - if ( $invoice->get_total_discount() > 0 ) { |
|
822 | - $invoice->save(); |
|
823 | - } |
|
821 | + if ( $invoice->get_total_discount() > 0 ) { |
|
822 | + $invoice->save(); |
|
823 | + } |
|
824 | 824 | } |
825 | 825 | |
826 | - // Show an admin message. |
|
827 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
826 | + // Show an admin message. |
|
827 | + $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
828 | 828 | |
829 | - // Redirect the admin. |
|
830 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
831 | - exit; |
|
829 | + // Redirect the admin. |
|
830 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
831 | + exit; |
|
832 | 832 | |
833 | - } |
|
833 | + } |
|
834 | 834 | |
835 | 835 | /** |
836 | - * Returns an array of admin notices. |
|
837 | - * |
|
838 | - * @since 1.0.19 |
|
836 | + * Returns an array of admin notices. |
|
837 | + * |
|
838 | + * @since 1.0.19 |
|
839 | 839 | * @return array |
840 | - */ |
|
841 | - public function get_notices() { |
|
842 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
840 | + */ |
|
841 | + public function get_notices() { |
|
842 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
843 | 843 | return is_array( $notices ) ? $notices : array(); |
844 | - } |
|
844 | + } |
|
845 | 845 | |
846 | - /** |
|
847 | - * Checks if we have any admin notices. |
|
848 | - * |
|
849 | - * @since 2.0.4 |
|
846 | + /** |
|
847 | + * Checks if we have any admin notices. |
|
848 | + * |
|
849 | + * @since 2.0.4 |
|
850 | 850 | * @return array |
851 | - */ |
|
852 | - public function has_notices() { |
|
853 | - return count( $this->get_notices() ) > 0; |
|
854 | - } |
|
855 | - |
|
856 | - /** |
|
857 | - * Clears all admin notices |
|
858 | - * |
|
859 | - * @access public |
|
860 | - * @since 1.0.19 |
|
861 | - */ |
|
862 | - public function clear_notices() { |
|
863 | - delete_option( 'wpinv_admin_notices' ); |
|
864 | - } |
|
865 | - |
|
866 | - /** |
|
867 | - * Saves a new admin notice |
|
868 | - * |
|
869 | - * @access public |
|
870 | - * @since 1.0.19 |
|
871 | - */ |
|
872 | - public function save_notice( $type, $message ) { |
|
873 | - $notices = $this->get_notices(); |
|
874 | - |
|
875 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
876 | - $notices[ $type ] = array(); |
|
877 | - } |
|
878 | - |
|
879 | - $notices[ $type ][] = $message; |
|
880 | - |
|
881 | - update_option( 'wpinv_admin_notices', $notices ); |
|
882 | - } |
|
883 | - |
|
884 | - /** |
|
885 | - * Displays a success notice |
|
886 | - * |
|
887 | - * @param string $msg The message to qeue. |
|
888 | - * @access public |
|
889 | - * @since 1.0.19 |
|
890 | - */ |
|
891 | - public function show_success( $msg ) { |
|
892 | - $this->save_notice( 'success', $msg ); |
|
893 | - } |
|
894 | - |
|
895 | - /** |
|
896 | - * Displays a error notice |
|
897 | - * |
|
898 | - * @access public |
|
899 | - * @param string $msg The message to qeue. |
|
900 | - * @since 1.0.19 |
|
901 | - */ |
|
902 | - public function show_error( $msg ) { |
|
903 | - $this->save_notice( 'error', $msg ); |
|
904 | - } |
|
905 | - |
|
906 | - /** |
|
907 | - * Displays a warning notice |
|
908 | - * |
|
909 | - * @access public |
|
910 | - * @param string $msg The message to qeue. |
|
911 | - * @since 1.0.19 |
|
912 | - */ |
|
913 | - public function show_warning( $msg ) { |
|
914 | - $this->save_notice( 'warning', $msg ); |
|
915 | - } |
|
916 | - |
|
917 | - /** |
|
918 | - * Displays a info notice |
|
919 | - * |
|
920 | - * @access public |
|
921 | - * @param string $msg The message to qeue. |
|
922 | - * @since 1.0.19 |
|
923 | - */ |
|
924 | - public function show_info( $msg ) { |
|
925 | - $this->save_notice( 'info', $msg ); |
|
926 | - } |
|
927 | - |
|
928 | - /** |
|
929 | - * Show notices |
|
930 | - * |
|
931 | - * @access public |
|
932 | - * @since 1.0.19 |
|
933 | - */ |
|
934 | - public function show_notices() { |
|
851 | + */ |
|
852 | + public function has_notices() { |
|
853 | + return count( $this->get_notices() ) > 0; |
|
854 | + } |
|
855 | + |
|
856 | + /** |
|
857 | + * Clears all admin notices |
|
858 | + * |
|
859 | + * @access public |
|
860 | + * @since 1.0.19 |
|
861 | + */ |
|
862 | + public function clear_notices() { |
|
863 | + delete_option( 'wpinv_admin_notices' ); |
|
864 | + } |
|
865 | + |
|
866 | + /** |
|
867 | + * Saves a new admin notice |
|
868 | + * |
|
869 | + * @access public |
|
870 | + * @since 1.0.19 |
|
871 | + */ |
|
872 | + public function save_notice( $type, $message ) { |
|
873 | + $notices = $this->get_notices(); |
|
874 | + |
|
875 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
876 | + $notices[ $type ] = array(); |
|
877 | + } |
|
878 | + |
|
879 | + $notices[ $type ][] = $message; |
|
880 | + |
|
881 | + update_option( 'wpinv_admin_notices', $notices ); |
|
882 | + } |
|
883 | + |
|
884 | + /** |
|
885 | + * Displays a success notice |
|
886 | + * |
|
887 | + * @param string $msg The message to qeue. |
|
888 | + * @access public |
|
889 | + * @since 1.0.19 |
|
890 | + */ |
|
891 | + public function show_success( $msg ) { |
|
892 | + $this->save_notice( 'success', $msg ); |
|
893 | + } |
|
894 | + |
|
895 | + /** |
|
896 | + * Displays a error notice |
|
897 | + * |
|
898 | + * @access public |
|
899 | + * @param string $msg The message to qeue. |
|
900 | + * @since 1.0.19 |
|
901 | + */ |
|
902 | + public function show_error( $msg ) { |
|
903 | + $this->save_notice( 'error', $msg ); |
|
904 | + } |
|
905 | + |
|
906 | + /** |
|
907 | + * Displays a warning notice |
|
908 | + * |
|
909 | + * @access public |
|
910 | + * @param string $msg The message to qeue. |
|
911 | + * @since 1.0.19 |
|
912 | + */ |
|
913 | + public function show_warning( $msg ) { |
|
914 | + $this->save_notice( 'warning', $msg ); |
|
915 | + } |
|
916 | + |
|
917 | + /** |
|
918 | + * Displays a info notice |
|
919 | + * |
|
920 | + * @access public |
|
921 | + * @param string $msg The message to qeue. |
|
922 | + * @since 1.0.19 |
|
923 | + */ |
|
924 | + public function show_info( $msg ) { |
|
925 | + $this->save_notice( 'info', $msg ); |
|
926 | + } |
|
927 | + |
|
928 | + /** |
|
929 | + * Show notices |
|
930 | + * |
|
931 | + * @access public |
|
932 | + * @since 1.0.19 |
|
933 | + */ |
|
934 | + public function show_notices() { |
|
935 | 935 | |
936 | 936 | $notices = $this->get_notices(); |
937 | 937 | $this->clear_notices(); |
938 | 938 | |
939 | - foreach ( $notices as $type => $messages ) { |
|
939 | + foreach ( $notices as $type => $messages ) { |
|
940 | 940 | |
941 | - if ( ! is_array( $messages ) ) { |
|
942 | - continue; |
|
943 | - } |
|
941 | + if ( ! is_array( $messages ) ) { |
|
942 | + continue; |
|
943 | + } |
|
944 | 944 | |
945 | 945 | $type = esc_attr( $type ); |
946 | - foreach ( $messages as $message ) { |
|
947 | - echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
946 | + foreach ( $messages as $message ) { |
|
947 | + echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
948 | 948 | } |
949 | 949 | } |
950 | 950 | |
951 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
952 | - |
|
953 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
954 | - $url = wp_nonce_url( |
|
955 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
956 | - 'getpaid-nonce', |
|
957 | - 'getpaid-nonce' |
|
958 | - ); |
|
959 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
960 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
961 | - echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
962 | - break; |
|
963 | - } |
|
951 | + foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
952 | + |
|
953 | + if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
954 | + $url = wp_nonce_url( |
|
955 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
956 | + 'getpaid-nonce', |
|
957 | + 'getpaid-nonce' |
|
958 | + ); |
|
959 | + $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
960 | + $message2 = __( 'Generate Pages', 'invoicing' ); |
|
961 | + echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
962 | + break; |
|
963 | + } |
|
964 | 964 | } |
965 | 965 | |
966 | - } |
|
966 | + } |
|
967 | 967 | |
968 | 968 | } |
@@ -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. |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function __construct() { |
41 | 41 | |
42 | - $this->admin_path = plugin_dir_path( __FILE__ ); |
|
43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
42 | + $this->admin_path = plugin_dir_path(__FILE__); |
|
43 | + $this->admin_url = plugins_url('/', __FILE__); |
|
44 | 44 | $this->reports = new GetPaid_Reports(); |
45 | 45 | |
46 | - if ( is_admin() ) { |
|
46 | + if (is_admin()) { |
|
47 | 47 | $this->init_admin_hooks(); |
48 | 48 | } |
49 | 49 | |
@@ -54,35 +54,35 @@ discard block |
||
54 | 54 | * |
55 | 55 | */ |
56 | 56 | private function init_admin_hooks() { |
57 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 ); |
|
58 | - add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
|
59 | - add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
|
60 | - add_action( 'admin_init', array( $this, 'activation_redirect' ) ); |
|
61 | - add_action( 'admin_init', array( $this, 'maybe_do_admin_action' ) ); |
|
62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | - add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | - add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) ); |
|
66 | - add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
67 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
68 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
69 | - add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
|
70 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
71 | - add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
72 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
73 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
74 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
75 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
76 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
77 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
78 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
79 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
57 | + add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts'), 9); |
|
58 | + add_filter('admin_body_class', array($this, 'admin_body_class')); |
|
59 | + add_action('admin_init', array($this, 'init_ayecode_connect_helper')); |
|
60 | + add_action('admin_init', array($this, 'activation_redirect')); |
|
61 | + add_action('admin_init', array($this, 'maybe_do_admin_action')); |
|
62 | + add_action('admin_notices', array($this, 'show_notices')); |
|
63 | + add_action('getpaid_authenticated_admin_action_rate_plugin', array($this, 'redirect_to_wordpress_rating_page')); |
|
64 | + add_action('getpaid_authenticated_admin_action_duplicate_form', array($this, 'duplicate_payment_form')); |
|
65 | + add_action('getpaid_authenticated_admin_action_reset_form_stats', array($this, 'reset_form_stats')); |
|
66 | + add_action('getpaid_authenticated_admin_action_duplicate_invoice', array($this, 'duplicate_invoice')); |
|
67 | + add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice')); |
|
68 | + add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder')); |
|
69 | + add_action('getpaid_authenticated_admin_action_reset_tax_rates', array($this, 'admin_reset_tax_rates')); |
|
70 | + add_action('getpaid_authenticated_admin_action_create_missing_pages', array($this, 'admin_create_missing_pages')); |
|
71 | + add_action('getpaid_authenticated_admin_action_refresh_permalinks', array($this, 'admin_refresh_permalinks')); |
|
72 | + add_action('getpaid_authenticated_admin_action_create_missing_tables', array($this, 'admin_create_missing_tables')); |
|
73 | + add_action('getpaid_authenticated_admin_action_migrate_old_invoices', array($this, 'admin_migrate_old_invoices')); |
|
74 | + add_action('getpaid_authenticated_admin_action_download_customers', array($this, 'admin_download_customers')); |
|
75 | + add_action('getpaid_authenticated_admin_action_recalculate_discounts', array($this, 'admin_recalculate_discounts')); |
|
76 | + add_action('getpaid_authenticated_admin_action_install_plugin', array($this, 'admin_install_plugin')); |
|
77 | + add_action('getpaid_authenticated_admin_action_connect_gateway', array($this, 'admin_connect_gateway')); |
|
78 | + add_filter('admin_footer_text', array($this, 'admin_footer_text')); |
|
79 | + do_action('getpaid_init_admin_hooks', $this); |
|
80 | 80 | |
81 | 81 | // Setup/welcome |
82 | - if ( ! empty( $_GET['page'] ) ) { |
|
83 | - switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
82 | + if (!empty($_GET['page'])) { |
|
83 | + switch (sanitize_text_field($_GET['page'])) { |
|
84 | 84 | case 'gp-setup': |
85 | - include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
85 | + include_once dirname(__FILE__) . '/class-getpaid-admin-setup-wizard.php'; |
|
86 | 86 | break; |
87 | 87 | } |
88 | 88 | } |
@@ -96,37 +96,37 @@ discard block |
||
96 | 96 | public function enqeue_scripts() { |
97 | 97 | global $current_screen, $pagenow; |
98 | 98 | |
99 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
99 | + $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
|
100 | 100 | $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
101 | 101 | |
102 | - if ( ! empty( $current_screen->post_type ) ) { |
|
102 | + if (!empty($current_screen->post_type)) { |
|
103 | 103 | $page = $current_screen->post_type; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // General styles. |
107 | - if ( false !== stripos( $page, 'wpi' ) || false !== stripos( $page, 'getpaid' ) || 'gp-setup' == $page || false !== stripos( $page, 'geodir-tickets' ) ) { |
|
107 | + if (false !== stripos($page, 'wpi') || false !== stripos($page, 'getpaid') || 'gp-setup' == $page || false !== stripos($page, 'geodir-tickets')) { |
|
108 | 108 | |
109 | 109 | // Styles. |
110 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
111 | - wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version ); |
|
112 | - wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' ); |
|
110 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css'); |
|
111 | + wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version); |
|
112 | + wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all'); |
|
113 | 113 | |
114 | 114 | // Scripts. |
115 | - wp_enqueue_script( 'select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION ); |
|
115 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION); |
|
116 | 116 | |
117 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
118 | - wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'wp-color-picker', 'jquery-ui-tooltip' ), $version ); |
|
119 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) ); |
|
117 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js'); |
|
118 | + wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'wp-color-picker', 'jquery-ui-tooltip'), $version); |
|
119 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18())); |
|
120 | 120 | |
121 | 121 | } |
122 | 122 | |
123 | 123 | // Payment form scripts. |
124 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
124 | + if ('wpi_payment_form' == $page && $editing) { |
|
125 | 125 | $this->load_payment_form_scripts(); |
126 | 126 | } |
127 | 127 | |
128 | - if ( $page == 'wpinv-subscriptions' ) { |
|
129 | - wp_enqueue_script( 'postbox' ); |
|
128 | + if ($page == 'wpinv-subscriptions') { |
|
129 | + wp_enqueue_script('postbox'); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | } |
@@ -139,31 +139,31 @@ discard block |
||
139 | 139 | global $post; |
140 | 140 | |
141 | 141 | $date_range = array( |
142 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
142 | + 'period' => isset($_GET['date_range']) ? sanitize_text_field($_GET['date_range']) : '7_days', |
|
143 | 143 | ); |
144 | 144 | |
145 | - if ( $date_range['period'] == 'custom' ) { |
|
145 | + if ($date_range['period'] == 'custom') { |
|
146 | 146 | |
147 | - if ( isset( $_GET['from'] ) ) { |
|
148 | - $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
147 | + if (isset($_GET['from'])) { |
|
148 | + $date_range['after'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['from']), current_time('timestamp')) - DAY_IN_SECONDS); |
|
149 | 149 | } |
150 | 150 | |
151 | - if ( isset( $_GET['to'] ) ) { |
|
152 | - $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
151 | + if (isset($_GET['to'])) { |
|
152 | + $date_range['before'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['to']), current_time('timestamp')) + DAY_IN_SECONDS); |
|
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
156 | 156 | $i18n = array( |
157 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
158 | - 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
|
159 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
160 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
161 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
157 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
158 | + 'post_ID' => isset($post->ID) ? $post->ID : '', |
|
159 | + 'wpinv_nonce' => wp_create_nonce('wpinv-nonce'), |
|
160 | + 'rest_nonce' => wp_create_nonce('wp_rest'), |
|
161 | + 'rest_root' => esc_url_raw(rest_url()), |
|
162 | 162 | 'date_range' => $date_range, |
163 | - 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
|
164 | - 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
|
165 | - 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
|
166 | - 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
|
163 | + 'add_invoice_note_nonce' => wp_create_nonce('add-invoice-note'), |
|
164 | + 'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'), |
|
165 | + 'invoice_item_nonce' => wp_create_nonce('invoice-item'), |
|
166 | + 'billing_details_nonce' => wp_create_nonce('get-billing-details'), |
|
167 | 167 | 'tax' => wpinv_tax_amount(), |
168 | 168 | 'discount' => 0, |
169 | 169 | 'currency_symbol' => wpinv_currency_symbol(), |
@@ -172,39 +172,39 @@ discard block |
||
172 | 172 | 'thousand_sep' => wpinv_thousands_separator(), |
173 | 173 | 'decimal_sep' => wpinv_decimal_separator(), |
174 | 174 | 'decimals' => wpinv_decimals(), |
175 | - 'save_invoice' => __( 'Save Invoice', 'invoicing' ), |
|
176 | - 'status_publish' => wpinv_status_nicename( 'publish' ), |
|
177 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
178 | - 'delete_tax_rate' => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ), |
|
179 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
180 | - 'FillBillingDetails' => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ), |
|
181 | - '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' ), |
|
182 | - 'AreYouSure' => __( 'Are you sure?', 'invoicing' ), |
|
183 | - 'errDeleteItem' => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ), |
|
184 | - 'delete_subscription' => __( 'Are you sure you want to delete this subscription?', 'invoicing' ), |
|
185 | - 'action_edit' => __( 'Edit', 'invoicing' ), |
|
186 | - 'action_cancel' => __( 'Cancel', 'invoicing' ), |
|
187 | - 'item_description' => __( 'Item Description', 'invoicing' ), |
|
188 | - 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
|
189 | - 'discount_description' => __( 'Discount Description', 'invoicing' ), |
|
190 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
191 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
192 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
193 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
194 | - 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
175 | + 'save_invoice' => __('Save Invoice', 'invoicing'), |
|
176 | + 'status_publish' => wpinv_status_nicename('publish'), |
|
177 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
178 | + 'delete_tax_rate' => __('Are you sure you wish to delete this tax rate?', 'invoicing'), |
|
179 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
180 | + 'FillBillingDetails' => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'), |
|
181 | + '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'), |
|
182 | + 'AreYouSure' => __('Are you sure?', 'invoicing'), |
|
183 | + 'errDeleteItem' => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'), |
|
184 | + 'delete_subscription' => __('Are you sure you want to delete this subscription?', 'invoicing'), |
|
185 | + 'action_edit' => __('Edit', 'invoicing'), |
|
186 | + 'action_cancel' => __('Cancel', 'invoicing'), |
|
187 | + 'item_description' => __('Item Description', 'invoicing'), |
|
188 | + 'invoice_description' => __('Invoice Description', 'invoicing'), |
|
189 | + 'discount_description' => __('Discount Description', 'invoicing'), |
|
190 | + 'searching' => __('Searching', 'invoicing'), |
|
191 | + 'loading' => __('Loading...', 'invoicing'), |
|
192 | + 'search_customers' => __('Enter customer name or email', 'invoicing'), |
|
193 | + 'search_items' => __('Enter item name', 'invoicing'), |
|
194 | + 'graphs' => array_merge(array('refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax'), array_keys(wpinv_get_report_graphs())), |
|
195 | 195 | ); |
196 | 196 | |
197 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
197 | + if (!empty($post) && getpaid_is_invoice_post_type($post->post_type)) { |
|
198 | 198 | |
199 | - $invoice = new WPInv_Invoice( $post ); |
|
199 | + $invoice = new WPInv_Invoice($post); |
|
200 | 200 | $i18n['save_invoice'] = sprintf( |
201 | - __( 'Save %s', 'invoicing' ), |
|
202 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
201 | + __('Save %s', 'invoicing'), |
|
202 | + ucfirst($invoice->get_invoice_quote_type()) |
|
203 | 203 | ); |
204 | 204 | |
205 | 205 | $i18n['invoice_description'] = sprintf( |
206 | - __( '%s Description', 'invoicing' ), |
|
207 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
206 | + __('%s Description', 'invoicing'), |
|
207 | + ucfirst($invoice->get_invoice_quote_type()) |
|
208 | 208 | ); |
209 | 209 | |
210 | 210 | } |
@@ -218,24 +218,24 @@ discard block |
||
218 | 218 | * @param string $footer_text |
219 | 219 | * @return string |
220 | 220 | */ |
221 | - public function admin_footer_text( $footer_text ) { |
|
221 | + public function admin_footer_text($footer_text) { |
|
222 | 222 | global $current_screen; |
223 | 223 | |
224 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
224 | + $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
|
225 | 225 | |
226 | - if ( ! empty( $current_screen->post_type ) ) { |
|
226 | + if (!empty($current_screen->post_type)) { |
|
227 | 227 | $page = $current_screen->post_type; |
228 | 228 | } |
229 | 229 | |
230 | 230 | // General styles. |
231 | - if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
|
231 | + if (apply_filters('getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing()) && false !== stripos($page, 'wpi')) { |
|
232 | 232 | |
233 | 233 | // Change the footer text |
234 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
234 | + if (!get_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', true)) { |
|
235 | 235 | |
236 | - $rating_url = esc_url( |
|
236 | + $rating_url = esc_url( |
|
237 | 237 | wp_nonce_url( |
238 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
238 | + admin_url('admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin'), |
|
239 | 239 | 'getpaid-nonce', |
240 | 240 | 'getpaid-nonce' |
241 | 241 | ) |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | |
244 | 244 | $footer_text = sprintf( |
245 | 245 | /* translators: %s: five stars */ |
246 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
246 | + __('If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing'), |
|
247 | 247 | "<a href='$rating_url'>★★★★★</a>" |
248 | 248 | ); |
249 | 249 | |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | |
252 | 252 | $footer_text = sprintf( |
253 | 253 | /* translators: %s: GetPaid */ |
254 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
254 | + __('Thank you for using %s!', 'invoicing'), |
|
255 | 255 | "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
256 | 256 | ); |
257 | 257 | |
@@ -267,8 +267,8 @@ discard block |
||
267 | 267 | * @since 2.0.0 |
268 | 268 | */ |
269 | 269 | public function redirect_to_wordpress_rating_page() { |
270 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
271 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
270 | + update_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', 1); |
|
271 | + wp_redirect('https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post'); |
|
272 | 272 | exit; |
273 | 273 | } |
274 | 274 | |
@@ -279,30 +279,30 @@ discard block |
||
279 | 279 | protected function load_payment_form_scripts() { |
280 | 280 | global $post; |
281 | 281 | |
282 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
|
283 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
284 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
282 | + wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION); |
|
283 | + wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION); |
|
284 | + wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION); |
|
285 | 285 | |
286 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
287 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
286 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js'); |
|
287 | + wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable', 'wp-hooks'), $version); |
|
288 | 288 | |
289 | 289 | wp_localize_script( |
290 | 290 | 'wpinv-admin-payment-form-script', |
291 | 291 | 'wpinvPaymentFormAdmin', |
292 | 292 | array( |
293 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
294 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
293 | + 'elements' => wpinv_get_data('payment-form-elements'), |
|
294 | + 'form_elements' => getpaid_get_payment_form_elements($post->ID), |
|
295 | 295 | 'currency' => wpinv_currency_symbol(), |
296 | 296 | 'position' => wpinv_currency_position(), |
297 | 297 | 'decimals' => (int) wpinv_decimals(), |
298 | 298 | 'thousands_sep' => wpinv_thousands_separator(), |
299 | 299 | 'decimals_sep' => wpinv_decimal_separator(), |
300 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
300 | + 'form_items' => gepaid_get_form_items($post->ID), |
|
301 | 301 | 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
302 | 302 | ) |
303 | 303 | ); |
304 | 304 | |
305 | - wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
305 | + wp_enqueue_script('wpinv-admin-payment-form-script'); |
|
306 | 306 | |
307 | 307 | } |
308 | 308 | |
@@ -313,24 +313,24 @@ discard block |
||
313 | 313 | * @return string |
314 | 314 | * |
315 | 315 | */ |
316 | - public function admin_body_class( $classes ) { |
|
316 | + public function admin_body_class($classes) { |
|
317 | 317 | global $pagenow, $post, $current_screen; |
318 | 318 | |
319 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
319 | + $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
|
320 | 320 | |
321 | - if ( ! empty( $current_screen->post_type ) ) { |
|
321 | + if (!empty($current_screen->post_type)) { |
|
322 | 322 | $page = $current_screen->post_type; |
323 | 323 | } |
324 | 324 | |
325 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
326 | - $classes .= ' wpi-' . sanitize_key( $page ); |
|
325 | + if (false !== stripos($page, 'wpi')) { |
|
326 | + $classes .= ' wpi-' . sanitize_key($page); |
|
327 | 327 | } |
328 | 328 | |
329 | - if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
|
329 | + if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) { |
|
330 | 330 | $classes .= ' wpinv-cpt wpinv'; |
331 | 331 | } |
332 | 332 | |
333 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
333 | + if (getpaid_is_invoice_post_type($page)) { |
|
334 | 334 | $classes .= ' getpaid-is-invoice-cpt'; |
335 | 335 | } |
336 | 336 | |
@@ -349,21 +349,21 @@ discard block |
||
349 | 349 | 'version' => WPINV_VERSION, |
350 | 350 | 'support_url' => 'https://wpgetpaid.com/support/', |
351 | 351 | 'documentation_url' => 'https://docs.wpgetpaid.com/', |
352 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
352 | + 'activated' => (int) get_option('gepaid_installed_on'), |
|
353 | 353 | ) |
354 | 354 | ); |
355 | 355 | |
356 | 356 | new AyeCode_Connect_Helper( |
357 | 357 | array( |
358 | - 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
359 | - 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
360 | - 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
361 | - 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
362 | - 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
363 | - 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
364 | - 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
358 | + 'connect_title' => __('WP Invoicing - an AyeCode product!', 'invoicing'), |
|
359 | + 'connect_external' => __('Please confirm you wish to connect your site?', 'invoicing'), |
|
360 | + 'connect' => sprintf(__('<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing'), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>'), |
|
361 | + 'connect_button' => __('Connect Site', 'invoicing'), |
|
362 | + 'connecting_button' => __('Connecting...', 'invoicing'), |
|
363 | + 'error_localhost' => __('This service will only work with a live domain, not a localhost.', 'invoicing'), |
|
364 | + 'error' => __('Something went wrong, please refresh and try again.', 'invoicing'), |
|
365 | 365 | ), |
366 | - array( 'wpi-addons' ) |
|
366 | + array('wpi-addons') |
|
367 | 367 | ); |
368 | 368 | |
369 | 369 | } |
@@ -375,20 +375,20 @@ discard block |
||
375 | 375 | */ |
376 | 376 | public function activation_redirect() { |
377 | 377 | |
378 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
378 | + $redirected = get_option('wpinv_redirected_to_settings'); |
|
379 | 379 | |
380 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
380 | + if (!empty($redirected) || wp_doing_ajax() || !current_user_can('manage_options')) { |
|
381 | 381 | return; |
382 | 382 | } |
383 | 383 | |
384 | 384 | // Bail if activating from network, or bulk |
385 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
385 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
386 | 386 | return; |
387 | 387 | } |
388 | 388 | |
389 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
389 | + update_option('wpinv_redirected_to_settings', 1); |
|
390 | 390 | |
391 | - wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
|
391 | + wp_safe_redirect(admin_url('index.php?page=gp-setup')); |
|
392 | 392 | exit; |
393 | 393 | |
394 | 394 | } |
@@ -398,9 +398,9 @@ discard block |
||
398 | 398 | */ |
399 | 399 | public function maybe_do_admin_action() { |
400 | 400 | |
401 | - if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
402 | - $key = sanitize_key( $_REQUEST['getpaid-admin-action'] ); |
|
403 | - do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST ); |
|
401 | + if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
402 | + $key = sanitize_key($_REQUEST['getpaid-admin-action']); |
|
403 | + do_action("getpaid_authenticated_admin_action_$key", $_REQUEST); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | } |
@@ -410,24 +410,24 @@ discard block |
||
410 | 410 | * |
411 | 411 | * @param array $args |
412 | 412 | */ |
413 | - public function duplicate_invoice( $args ) { |
|
413 | + public function duplicate_invoice($args) { |
|
414 | 414 | |
415 | - if ( empty( $args['invoice_id'] ) ) { |
|
415 | + if (empty($args['invoice_id'])) { |
|
416 | 416 | return; |
417 | 417 | } |
418 | 418 | |
419 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
419 | + $invoice = new WPInv_Invoice((int) $args['invoice_id']); |
|
420 | 420 | |
421 | - if ( ! $invoice->exists() ) { |
|
421 | + if (!$invoice->exists()) { |
|
422 | 422 | return; |
423 | 423 | } |
424 | 424 | |
425 | - $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
425 | + $new_invoice = getpaid_duplicate_invoice($invoice); |
|
426 | 426 | $new_invoice->save(); |
427 | 427 | |
428 | - if ( $new_invoice->exists() ) { |
|
428 | + if ($new_invoice->exists()) { |
|
429 | 429 | |
430 | - getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) ); |
|
430 | + getpaid_admin()->show_success(__('Invoice duplicated successfully.', 'invoicing')); |
|
431 | 431 | |
432 | 432 | wp_safe_redirect( |
433 | 433 | add_query_arg( |
@@ -435,14 +435,14 @@ discard block |
||
435 | 435 | 'action' => 'edit', |
436 | 436 | 'post' => $new_invoice->get_id(), |
437 | 437 | ), |
438 | - admin_url( 'post.php' ) |
|
438 | + admin_url('post.php') |
|
439 | 439 | ) |
440 | 440 | ); |
441 | 441 | exit; |
442 | 442 | |
443 | 443 | } |
444 | 444 | |
445 | - getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) ); |
|
445 | + getpaid_admin()->show_error(__('There was an error duplicating this invoice. Please try again.', 'invoicing')); |
|
446 | 446 | |
447 | 447 | } |
448 | 448 | |
@@ -451,34 +451,34 @@ discard block |
||
451 | 451 | * |
452 | 452 | * @param array $args |
453 | 453 | */ |
454 | - public function duplicate_payment_form( $args ) { |
|
454 | + public function duplicate_payment_form($args) { |
|
455 | 455 | |
456 | - if ( empty( $args['form_id'] ) ) { |
|
456 | + if (empty($args['form_id'])) { |
|
457 | 457 | return; |
458 | 458 | } |
459 | 459 | |
460 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
460 | + $form = new GetPaid_Payment_Form((int) $args['form_id']); |
|
461 | 461 | |
462 | - if ( ! $form->exists() ) { |
|
462 | + if (!$form->exists()) { |
|
463 | 463 | return; |
464 | 464 | } |
465 | 465 | |
466 | 466 | $new_form = new GetPaid_Payment_Form(); |
467 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
468 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
469 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
470 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
467 | + $new_form->set_author($form->get_author('edit')); |
|
468 | + $new_form->set_name($form->get_name('edit') . __('(copy)', 'invoicing')); |
|
469 | + $new_form->set_elements($form->get_elements('edit')); |
|
470 | + $new_form->set_items($form->get_items('edit')); |
|
471 | 471 | $new_form->save(); |
472 | 472 | |
473 | - if ( $new_form->exists() ) { |
|
474 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
475 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
473 | + if ($new_form->exists()) { |
|
474 | + $this->show_success(__('Form duplicated successfully', 'invoicing')); |
|
475 | + $url = get_edit_post_link($new_form->get_id(), 'edit'); |
|
476 | 476 | } else { |
477 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
478 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
477 | + $this->show_error(__('Unable to duplicate form', 'invoicing')); |
|
478 | + $url = remove_query_arg(array('getpaid-admin-action', 'form_id', 'getpaid-nonce')); |
|
479 | 479 | } |
480 | 480 | |
481 | - wp_redirect( $url ); |
|
481 | + wp_redirect($url); |
|
482 | 482 | exit; |
483 | 483 | } |
484 | 484 | |
@@ -487,27 +487,27 @@ discard block |
||
487 | 487 | * |
488 | 488 | * @param array $args |
489 | 489 | */ |
490 | - public function reset_form_stats( $args ) { |
|
490 | + public function reset_form_stats($args) { |
|
491 | 491 | |
492 | - if ( empty( $args['form_id'] ) ) { |
|
492 | + if (empty($args['form_id'])) { |
|
493 | 493 | return; |
494 | 494 | } |
495 | 495 | |
496 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
496 | + $form = new GetPaid_Payment_Form((int) $args['form_id']); |
|
497 | 497 | |
498 | - if ( ! $form->exists() ) { |
|
498 | + if (!$form->exists()) { |
|
499 | 499 | return; |
500 | 500 | } |
501 | 501 | |
502 | - $form->set_earned( 0 ); |
|
503 | - $form->set_refunded( 0 ); |
|
504 | - $form->set_cancelled( 0 ); |
|
505 | - $form->set_failed( 0 ); |
|
502 | + $form->set_earned(0); |
|
503 | + $form->set_refunded(0); |
|
504 | + $form->set_cancelled(0); |
|
505 | + $form->set_failed(0); |
|
506 | 506 | $form->save(); |
507 | 507 | |
508 | - $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) ); |
|
508 | + $this->show_success(__('Form stats reset successfully', 'invoicing')); |
|
509 | 509 | |
510 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) ); |
|
510 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'form_id', 'getpaid-nonce'))); |
|
511 | 511 | exit; |
512 | 512 | } |
513 | 513 | |
@@ -516,9 +516,9 @@ discard block |
||
516 | 516 | * |
517 | 517 | * @param array $args |
518 | 518 | */ |
519 | - public function send_customer_invoice( $args ) { |
|
520 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
521 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
519 | + public function send_customer_invoice($args) { |
|
520 | + getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id']), true); |
|
521 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
522 | 522 | exit; |
523 | 523 | } |
524 | 524 | |
@@ -527,16 +527,16 @@ discard block |
||
527 | 527 | * |
528 | 528 | * @param array $args |
529 | 529 | */ |
530 | - public function send_customer_payment_reminder( $args ) { |
|
531 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
530 | + public function send_customer_payment_reminder($args) { |
|
531 | + $sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id'])); |
|
532 | 532 | |
533 | - if ( $sent ) { |
|
534 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
533 | + if ($sent) { |
|
534 | + $this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing')); |
|
535 | 535 | } else { |
536 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
536 | + $this->show_error(__('Could not sent payment reminder to the customer', 'invoicing')); |
|
537 | 537 | } |
538 | 538 | |
539 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
539 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
540 | 540 | exit; |
541 | 541 | } |
542 | 542 | |
@@ -546,8 +546,8 @@ discard block |
||
546 | 546 | */ |
547 | 547 | public function admin_reset_tax_rates() { |
548 | 548 | |
549 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
550 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
549 | + update_option('wpinv_tax_rates', wpinv_get_data('tax-rates')); |
|
550 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
551 | 551 | exit; |
552 | 552 | |
553 | 553 | } |
@@ -559,8 +559,8 @@ discard block |
||
559 | 559 | public function admin_create_missing_pages() { |
560 | 560 | $installer = new GetPaid_Installer(); |
561 | 561 | $installer->create_pages(); |
562 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
563 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
562 | + $this->show_success(__('GetPaid pages updated.', 'invoicing')); |
|
563 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
564 | 564 | exit; |
565 | 565 | } |
566 | 566 | |
@@ -569,8 +569,8 @@ discard block |
||
569 | 569 | */ |
570 | 570 | public function admin_refresh_permalinks() { |
571 | 571 | flush_rewrite_rules(); |
572 | - $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
573 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
572 | + $this->show_success(__('Permalinks refreshed.', 'invoicing')); |
|
573 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
574 | 574 | exit; |
575 | 575 | } |
576 | 576 | |
@@ -582,35 +582,35 @@ discard block |
||
582 | 582 | global $wpdb; |
583 | 583 | $installer = new GetPaid_Installer(); |
584 | 584 | |
585 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
585 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'") != $wpdb->prefix . 'wpinv_subscriptions') { |
|
586 | 586 | $installer->create_subscriptions_table(); |
587 | 587 | |
588 | - if ( $wpdb->last_error !== '' ) { |
|
589 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
588 | + if ($wpdb->last_error !== '') { |
|
589 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
590 | 590 | } |
591 | 591 | } |
592 | 592 | |
593 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
593 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'") != $wpdb->prefix . 'getpaid_invoices') { |
|
594 | 594 | $installer->create_invoices_table(); |
595 | 595 | |
596 | - if ( '' !== $wpdb->last_error ) { |
|
597 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
596 | + if ('' !== $wpdb->last_error) { |
|
597 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
598 | 598 | } |
599 | 599 | } |
600 | 600 | |
601 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
601 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'") != $wpdb->prefix . 'getpaid_invoice_items') { |
|
602 | 602 | $installer->create_invoice_items_table(); |
603 | 603 | |
604 | - if ( '' !== $wpdb->last_error ) { |
|
605 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
604 | + if ('' !== $wpdb->last_error) { |
|
605 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
606 | 606 | } |
607 | 607 | } |
608 | 608 | |
609 | - if ( ! $this->has_notices() ) { |
|
610 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
609 | + if (!$this->has_notices()) { |
|
610 | + $this->show_success(__('Your GetPaid tables have been updated.', 'invoicing')); |
|
611 | 611 | } |
612 | 612 | |
613 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
613 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
614 | 614 | exit; |
615 | 615 | } |
616 | 616 | |
@@ -625,10 +625,10 @@ discard block |
||
625 | 625 | $installer->migrate_old_invoices(); |
626 | 626 | |
627 | 627 | // Show an admin message. |
628 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
628 | + $this->show_success(__('Your invoices have been migrated.', 'invoicing')); |
|
629 | 629 | |
630 | 630 | // Redirect the admin. |
631 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
631 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
632 | 632 | exit; |
633 | 633 | |
634 | 634 | } |
@@ -640,78 +640,78 @@ discard block |
||
640 | 640 | public function admin_download_customers() { |
641 | 641 | global $wpdb; |
642 | 642 | |
643 | - $output = fopen( 'php://output', 'w' ); |
|
643 | + $output = fopen('php://output', 'w'); |
|
644 | 644 | |
645 | - if ( false === $output ) { |
|
646 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
645 | + if (false === $output) { |
|
646 | + wp_die(esc_html__('Unsupported server', 'invoicing'), 500); |
|
647 | 647 | } |
648 | 648 | |
649 | - header( 'Content-Type:text/csv' ); |
|
650 | - header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
649 | + header('Content-Type:text/csv'); |
|
650 | + header('Content-Disposition:attachment;filename=customers.csv'); |
|
651 | 651 | |
652 | 652 | $post_types = ''; |
653 | 653 | |
654 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
655 | - $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
654 | + foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) { |
|
655 | + $post_types .= $wpdb->prepare('post_type=%s OR ', $post_type); |
|
656 | 656 | } |
657 | 657 | |
658 | - $post_types = rtrim( $post_types, ' OR' ); |
|
658 | + $post_types = rtrim($post_types, ' OR'); |
|
659 | 659 | |
660 | - $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" ); |
|
660 | + $customers = $wpdb->get_col("SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types"); |
|
661 | 661 | |
662 | 662 | $columns = array( |
663 | - 'name' => __( 'Name', 'invoicing' ), |
|
664 | - 'email' => __( 'Email', 'invoicing' ), |
|
665 | - 'country' => __( 'Country', 'invoicing' ), |
|
666 | - 'state' => __( 'State', 'invoicing' ), |
|
667 | - 'city' => __( 'City', 'invoicing' ), |
|
668 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
669 | - 'address' => __( 'Address', 'invoicing' ), |
|
670 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
671 | - 'company' => __( 'Company', 'invoicing' ), |
|
672 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
673 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
674 | - 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
675 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
663 | + 'name' => __('Name', 'invoicing'), |
|
664 | + 'email' => __('Email', 'invoicing'), |
|
665 | + 'country' => __('Country', 'invoicing'), |
|
666 | + 'state' => __('State', 'invoicing'), |
|
667 | + 'city' => __('City', 'invoicing'), |
|
668 | + 'zip' => __('ZIP', 'invoicing'), |
|
669 | + 'address' => __('Address', 'invoicing'), |
|
670 | + 'phone' => __('Phone', 'invoicing'), |
|
671 | + 'company' => __('Company', 'invoicing'), |
|
672 | + 'company_id' => __('Company ID', 'invoicing'), |
|
673 | + 'invoices' => __('Invoices', 'invoicing'), |
|
674 | + 'total_raw' => __('Total Spend', 'invoicing'), |
|
675 | + 'signup' => __('Date created', 'invoicing'), |
|
676 | 676 | ); |
677 | 677 | |
678 | 678 | // Output the csv column headers. |
679 | - fputcsv( $output, array_values( $columns ) ); |
|
679 | + fputcsv($output, array_values($columns)); |
|
680 | 680 | |
681 | 681 | // Loop through |
682 | 682 | $table = new WPInv_Customers_Table(); |
683 | - foreach ( $customers as $customer_id ) { |
|
683 | + foreach ($customers as $customer_id) { |
|
684 | 684 | |
685 | - $user = get_user_by( 'id', $customer_id ); |
|
685 | + $user = get_user_by('id', $customer_id); |
|
686 | 686 | $row = array(); |
687 | - if ( empty( $user ) ) { |
|
687 | + if (empty($user)) { |
|
688 | 688 | continue; |
689 | 689 | } |
690 | 690 | |
691 | - foreach ( array_keys( $columns ) as $column ) { |
|
691 | + foreach (array_keys($columns) as $column) { |
|
692 | 692 | |
693 | 693 | $method = 'column_' . $column; |
694 | 694 | |
695 | - if ( 'name' == $column ) { |
|
696 | - $value = esc_html( $user->display_name ); |
|
697 | - } elseif ( 'email' == $column ) { |
|
698 | - $value = sanitize_email( $user->user_email ); |
|
699 | - } elseif ( is_callable( array( $table, $method ) ) ) { |
|
700 | - $value = wp_strip_all_tags( $table->$method( $user ) ); |
|
695 | + if ('name' == $column) { |
|
696 | + $value = esc_html($user->display_name); |
|
697 | + } elseif ('email' == $column) { |
|
698 | + $value = sanitize_email($user->user_email); |
|
699 | + } elseif (is_callable(array($table, $method))) { |
|
700 | + $value = wp_strip_all_tags($table->$method($user)); |
|
701 | 701 | } |
702 | 702 | |
703 | - if ( empty( $value ) ) { |
|
704 | - $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
703 | + if (empty($value)) { |
|
704 | + $value = esc_html(get_user_meta($user->ID, '_wpinv_' . $column, true)); |
|
705 | 705 | } |
706 | 706 | |
707 | 707 | $row[] = $value; |
708 | 708 | |
709 | 709 | } |
710 | 710 | |
711 | - fputcsv( $output, $row ); |
|
711 | + fputcsv($output, $row); |
|
712 | 712 | } |
713 | 713 | |
714 | - fclose( $output ); |
|
714 | + fclose($output); |
|
715 | 715 | exit; |
716 | 716 | |
717 | 717 | } |
@@ -721,27 +721,27 @@ discard block |
||
721 | 721 | * |
722 | 722 | * @param array $data |
723 | 723 | */ |
724 | - public function admin_install_plugin( $data ) { |
|
724 | + public function admin_install_plugin($data) { |
|
725 | 725 | |
726 | - if ( ! empty( $data['plugins'] ) ) { |
|
726 | + if (!empty($data['plugins'])) { |
|
727 | 727 | include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
728 | 728 | wp_cache_flush(); |
729 | 729 | |
730 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
731 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
732 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
733 | - $installed = $upgrader->install( $plugin_zip ); |
|
730 | + foreach ($data['plugins'] as $slug => $file) { |
|
731 | + $plugin_zip = esc_url('https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip'); |
|
732 | + $upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin()); |
|
733 | + $installed = $upgrader->install($plugin_zip); |
|
734 | 734 | |
735 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
736 | - activate_plugin( $file, '', false, true ); |
|
735 | + if (!is_wp_error($installed) && $installed) { |
|
736 | + activate_plugin($file, '', false, true); |
|
737 | 737 | } else { |
738 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
738 | + wpinv_error_log($upgrader->skin->get_upgrade_messages(), false); |
|
739 | 739 | } |
740 | 740 | } |
741 | 741 | } |
742 | 742 | |
743 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
744 | - wp_safe_redirect( $redirect ); |
|
743 | + $redirect = isset($data['redirect']) ? esc_url_raw($data['redirect']) : admin_url('plugins.php'); |
|
744 | + wp_safe_redirect($redirect); |
|
745 | 745 | exit; |
746 | 746 | |
747 | 747 | } |
@@ -751,41 +751,41 @@ discard block |
||
751 | 751 | * |
752 | 752 | * @param array $data |
753 | 753 | */ |
754 | - public function admin_connect_gateway( $data ) { |
|
754 | + public function admin_connect_gateway($data) { |
|
755 | 755 | |
756 | - if ( ! empty( $data['plugin'] ) ) { |
|
756 | + if (!empty($data['plugin'])) { |
|
757 | 757 | |
758 | - $gateway = sanitize_key( $data['plugin'] ); |
|
759 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
758 | + $gateway = sanitize_key($data['plugin']); |
|
759 | + $connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data); |
|
760 | 760 | |
761 | - if ( ! empty( $connect_url ) ) { |
|
762 | - wp_redirect( $connect_url ); |
|
761 | + if (!empty($connect_url)) { |
|
762 | + wp_redirect($connect_url); |
|
763 | 763 | exit; |
764 | 764 | } |
765 | 765 | |
766 | - if ( 'stripe' == $data['plugin'] ) { |
|
766 | + if ('stripe' == $data['plugin']) { |
|
767 | 767 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
768 | 768 | include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
769 | 769 | wp_cache_flush(); |
770 | 770 | |
771 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
772 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
773 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
774 | - $upgrader->install( $plugin_zip ); |
|
771 | + if (!array_key_exists('getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins())) { |
|
772 | + $plugin_zip = esc_url('https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip'); |
|
773 | + $upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin()); |
|
774 | + $upgrader->install($plugin_zip); |
|
775 | 775 | } |
776 | 776 | |
777 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
777 | + activate_plugin('getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true); |
|
778 | 778 | } |
779 | 779 | |
780 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
781 | - if ( ! empty( $connect_url ) ) { |
|
782 | - wp_redirect( $connect_url ); |
|
780 | + $connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data); |
|
781 | + if (!empty($connect_url)) { |
|
782 | + wp_redirect($connect_url); |
|
783 | 783 | exit; |
784 | 784 | } |
785 | 785 | } |
786 | 786 | |
787 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
788 | - wp_safe_redirect( $redirect ); |
|
787 | + $redirect = isset($data['redirect']) ? esc_url_raw(urldecode($data['redirect'])) : admin_url('admin.php?page=wpinv-settings&tab=gateways'); |
|
788 | + wp_safe_redirect($redirect); |
|
789 | 789 | exit; |
790 | 790 | |
791 | 791 | } |
@@ -799,35 +799,35 @@ discard block |
||
799 | 799 | |
800 | 800 | // Fetch all invoices that have discount codes. |
801 | 801 | $table = $wpdb->prefix . 'getpaid_invoices'; |
802 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
802 | + $invoices = $wpdb->get_col("SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''"); |
|
803 | 803 | |
804 | - foreach ( $invoices as $invoice ) { |
|
804 | + foreach ($invoices as $invoice) { |
|
805 | 805 | |
806 | - $invoice = new WPInv_Invoice( $invoice ); |
|
806 | + $invoice = new WPInv_Invoice($invoice); |
|
807 | 807 | |
808 | - if ( ! $invoice->exists() ) { |
|
808 | + if (!$invoice->exists()) { |
|
809 | 809 | continue; |
810 | 810 | } |
811 | 811 | |
812 | 812 | // Abort if the discount does not exist or does not apply here. |
813 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
814 | - if ( ! $discount->exists() ) { |
|
813 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
814 | + if (!$discount->exists()) { |
|
815 | 815 | continue; |
816 | 816 | } |
817 | 817 | |
818 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
818 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
819 | 819 | $invoice->recalculate_total(); |
820 | 820 | |
821 | - if ( $invoice->get_total_discount() > 0 ) { |
|
821 | + if ($invoice->get_total_discount() > 0) { |
|
822 | 822 | $invoice->save(); |
823 | 823 | } |
824 | 824 | } |
825 | 825 | |
826 | 826 | // Show an admin message. |
827 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
827 | + $this->show_success(__('Discounts have been recalculated.', 'invoicing')); |
|
828 | 828 | |
829 | 829 | // Redirect the admin. |
830 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
830 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
831 | 831 | exit; |
832 | 832 | |
833 | 833 | } |
@@ -839,8 +839,8 @@ discard block |
||
839 | 839 | * @return array |
840 | 840 | */ |
841 | 841 | public function get_notices() { |
842 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
843 | - return is_array( $notices ) ? $notices : array(); |
|
842 | + $notices = get_option('wpinv_admin_notices'); |
|
843 | + return is_array($notices) ? $notices : array(); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | /** |
@@ -850,7 +850,7 @@ discard block |
||
850 | 850 | * @return array |
851 | 851 | */ |
852 | 852 | public function has_notices() { |
853 | - return count( $this->get_notices() ) > 0; |
|
853 | + return count($this->get_notices()) > 0; |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | /** |
@@ -860,7 +860,7 @@ discard block |
||
860 | 860 | * @since 1.0.19 |
861 | 861 | */ |
862 | 862 | public function clear_notices() { |
863 | - delete_option( 'wpinv_admin_notices' ); |
|
863 | + delete_option('wpinv_admin_notices'); |
|
864 | 864 | } |
865 | 865 | |
866 | 866 | /** |
@@ -869,16 +869,16 @@ discard block |
||
869 | 869 | * @access public |
870 | 870 | * @since 1.0.19 |
871 | 871 | */ |
872 | - public function save_notice( $type, $message ) { |
|
872 | + public function save_notice($type, $message) { |
|
873 | 873 | $notices = $this->get_notices(); |
874 | 874 | |
875 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
876 | - $notices[ $type ] = array(); |
|
875 | + if (empty($notices[$type]) || !is_array($notices[$type])) { |
|
876 | + $notices[$type] = array(); |
|
877 | 877 | } |
878 | 878 | |
879 | - $notices[ $type ][] = $message; |
|
879 | + $notices[$type][] = $message; |
|
880 | 880 | |
881 | - update_option( 'wpinv_admin_notices', $notices ); |
|
881 | + update_option('wpinv_admin_notices', $notices); |
|
882 | 882 | } |
883 | 883 | |
884 | 884 | /** |
@@ -888,8 +888,8 @@ discard block |
||
888 | 888 | * @access public |
889 | 889 | * @since 1.0.19 |
890 | 890 | */ |
891 | - public function show_success( $msg ) { |
|
892 | - $this->save_notice( 'success', $msg ); |
|
891 | + public function show_success($msg) { |
|
892 | + $this->save_notice('success', $msg); |
|
893 | 893 | } |
894 | 894 | |
895 | 895 | /** |
@@ -899,8 +899,8 @@ discard block |
||
899 | 899 | * @param string $msg The message to qeue. |
900 | 900 | * @since 1.0.19 |
901 | 901 | */ |
902 | - public function show_error( $msg ) { |
|
903 | - $this->save_notice( 'error', $msg ); |
|
902 | + public function show_error($msg) { |
|
903 | + $this->save_notice('error', $msg); |
|
904 | 904 | } |
905 | 905 | |
906 | 906 | /** |
@@ -910,8 +910,8 @@ discard block |
||
910 | 910 | * @param string $msg The message to qeue. |
911 | 911 | * @since 1.0.19 |
912 | 912 | */ |
913 | - public function show_warning( $msg ) { |
|
914 | - $this->save_notice( 'warning', $msg ); |
|
913 | + public function show_warning($msg) { |
|
914 | + $this->save_notice('warning', $msg); |
|
915 | 915 | } |
916 | 916 | |
917 | 917 | /** |
@@ -921,8 +921,8 @@ discard block |
||
921 | 921 | * @param string $msg The message to qeue. |
922 | 922 | * @since 1.0.19 |
923 | 923 | */ |
924 | - public function show_info( $msg ) { |
|
925 | - $this->save_notice( 'info', $msg ); |
|
924 | + public function show_info($msg) { |
|
925 | + $this->save_notice('info', $msg); |
|
926 | 926 | } |
927 | 927 | |
928 | 928 | /** |
@@ -936,29 +936,29 @@ discard block |
||
936 | 936 | $notices = $this->get_notices(); |
937 | 937 | $this->clear_notices(); |
938 | 938 | |
939 | - foreach ( $notices as $type => $messages ) { |
|
939 | + foreach ($notices as $type => $messages) { |
|
940 | 940 | |
941 | - if ( ! is_array( $messages ) ) { |
|
941 | + if (!is_array($messages)) { |
|
942 | 942 | continue; |
943 | 943 | } |
944 | 944 | |
945 | - $type = esc_attr( $type ); |
|
946 | - foreach ( $messages as $message ) { |
|
947 | - echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
945 | + $type = esc_attr($type); |
|
946 | + foreach ($messages as $message) { |
|
947 | + echo wp_kses_post("<div class='notice notice-$type is-dismissible'><p>$message</p></div>"); |
|
948 | 948 | } |
949 | 949 | } |
950 | 950 | |
951 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
951 | + foreach (array('checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page') as $page) { |
|
952 | 952 | |
953 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
954 | - $url = wp_nonce_url( |
|
955 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
953 | + if (!is_numeric(wpinv_get_option($page, false))) { |
|
954 | + $url = wp_nonce_url( |
|
955 | + add_query_arg('getpaid-admin-action', 'create_missing_pages'), |
|
956 | 956 | 'getpaid-nonce', |
957 | 957 | 'getpaid-nonce' |
958 | 958 | ); |
959 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
960 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
961 | - echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
959 | + $message = __('Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing'); |
|
960 | + $message2 = __('Generate Pages', 'invoicing'); |
|
961 | + echo wp_kses_post("<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"); |
|
962 | 962 | break; |
963 | 963 | } |
964 | 964 | } |