@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; // Exit if accessed directly |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -11,77 +11,77 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Pagination { |
13 | 13 | |
14 | - /** |
|
15 | - * Build the component. |
|
16 | - * |
|
17 | - * @param array $args |
|
18 | - * |
|
19 | - * @return string The rendered component. |
|
20 | - */ |
|
21 | - public static function get( $args = array() ) { |
|
22 | - global $wp_query; |
|
23 | - |
|
24 | - $defaults = array( |
|
25 | - 'class' => '', |
|
26 | - 'mid_size' => 2, |
|
27 | - 'prev_text' => '<i class="fas fa-chevron-left"></i>', |
|
28 | - 'next_text' => '<i class="fas fa-chevron-right"></i>', |
|
29 | - 'screen_reader_text' => __( 'Posts navigation','aui' ), |
|
30 | - 'before_paging' => '', |
|
31 | - 'after_paging' => '', |
|
32 | - 'type' => 'array', |
|
33 | - 'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1, |
|
34 | - 'links' => array() // an array of links if using custom links, this includes the a tag. |
|
35 | - ); |
|
36 | - |
|
37 | - /** |
|
38 | - * Parse incoming $args into an array and merge it with $defaults |
|
39 | - */ |
|
40 | - $args = wp_parse_args( $args, $defaults ); |
|
41 | - |
|
42 | - $output = ''; |
|
43 | - |
|
44 | - // Don't print empty markup if there's only one page. |
|
45 | - if ( $args['total'] > 1 ) { |
|
46 | - |
|
47 | - // Set up paginated links. |
|
48 | - $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
49 | - |
|
50 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
51 | - |
|
52 | - // make the output bootstrap ready |
|
53 | - $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
|
54 | - if ( ! empty( $links ) ) { |
|
55 | - foreach ( $links as $link ) { |
|
56 | - $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
57 | - $links_html .= "<li class='page-item $active'>"; |
|
58 | - $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
59 | - $links_html .= "</li>"; |
|
60 | - } |
|
61 | - } |
|
62 | - $links_html .= "</ul>"; |
|
63 | - |
|
64 | - if ( $links ) { |
|
65 | - $output .= '<section class="px-0 py-2 w-100">'; |
|
66 | - $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
67 | - $output .= '</section>'; |
|
68 | - } |
|
69 | - |
|
70 | - $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
71 | - $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
72 | - } |
|
73 | - |
|
74 | - if ( $output ) { |
|
75 | - if ( ! empty( $args['before_paging'] ) ) { |
|
76 | - $output = $args['before_paging'] . $output; |
|
77 | - } |
|
78 | - |
|
79 | - if ( ! empty( $args['after_paging'] ) ) { |
|
80 | - $output = $output . $args['after_paging']; |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - return $output; |
|
85 | - } |
|
14 | + /** |
|
15 | + * Build the component. |
|
16 | + * |
|
17 | + * @param array $args |
|
18 | + * |
|
19 | + * @return string The rendered component. |
|
20 | + */ |
|
21 | + public static function get( $args = array() ) { |
|
22 | + global $wp_query; |
|
23 | + |
|
24 | + $defaults = array( |
|
25 | + 'class' => '', |
|
26 | + 'mid_size' => 2, |
|
27 | + 'prev_text' => '<i class="fas fa-chevron-left"></i>', |
|
28 | + 'next_text' => '<i class="fas fa-chevron-right"></i>', |
|
29 | + 'screen_reader_text' => __( 'Posts navigation','aui' ), |
|
30 | + 'before_paging' => '', |
|
31 | + 'after_paging' => '', |
|
32 | + 'type' => 'array', |
|
33 | + 'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1, |
|
34 | + 'links' => array() // an array of links if using custom links, this includes the a tag. |
|
35 | + ); |
|
36 | + |
|
37 | + /** |
|
38 | + * Parse incoming $args into an array and merge it with $defaults |
|
39 | + */ |
|
40 | + $args = wp_parse_args( $args, $defaults ); |
|
41 | + |
|
42 | + $output = ''; |
|
43 | + |
|
44 | + // Don't print empty markup if there's only one page. |
|
45 | + if ( $args['total'] > 1 ) { |
|
46 | + |
|
47 | + // Set up paginated links. |
|
48 | + $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
49 | + |
|
50 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
51 | + |
|
52 | + // make the output bootstrap ready |
|
53 | + $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
|
54 | + if ( ! empty( $links ) ) { |
|
55 | + foreach ( $links as $link ) { |
|
56 | + $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
57 | + $links_html .= "<li class='page-item $active'>"; |
|
58 | + $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
59 | + $links_html .= "</li>"; |
|
60 | + } |
|
61 | + } |
|
62 | + $links_html .= "</ul>"; |
|
63 | + |
|
64 | + if ( $links ) { |
|
65 | + $output .= '<section class="px-0 py-2 w-100">'; |
|
66 | + $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
67 | + $output .= '</section>'; |
|
68 | + } |
|
69 | + |
|
70 | + $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
71 | + $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
72 | + } |
|
73 | + |
|
74 | + if ( $output ) { |
|
75 | + if ( ! empty( $args['before_paging'] ) ) { |
|
76 | + $output = $args['before_paging'] . $output; |
|
77 | + } |
|
78 | + |
|
79 | + if ( ! empty( $args['after_paging'] ) ) { |
|
80 | + $output = $output . $args['after_paging']; |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + return $output; |
|
85 | + } |
|
86 | 86 | |
87 | 87 | } |
88 | 88 | \ No newline at end of file |
@@ -232,26 +232,26 @@ discard block |
||
232 | 232 | } |
233 | 233 | |
234 | 234 | function wpinv_get_chosen_gateway( $invoice_id = 0 ) { |
235 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
235 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
236 | 236 | |
237 | 237 | $chosen = false; |
238 | 238 | if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
239 | 239 | $chosen = $invoice->get_gateway(); |
240 | 240 | } |
241 | 241 | |
242 | - $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
242 | + $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
243 | 243 | |
244 | - if ( false !== $chosen ) { |
|
245 | - $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
246 | - } |
|
244 | + if ( false !== $chosen ) { |
|
245 | + $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
246 | + } |
|
247 | 247 | |
248 | - if ( ! empty ( $chosen ) ) { |
|
249 | - $enabled_gateway = urldecode( $chosen ); |
|
250 | - } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
251 | - $enabled_gateway = 'manual'; |
|
252 | - } else { |
|
253 | - $enabled_gateway = wpinv_get_default_gateway(); |
|
254 | - } |
|
248 | + if ( ! empty ( $chosen ) ) { |
|
249 | + $enabled_gateway = urldecode( $chosen ); |
|
250 | + } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
251 | + $enabled_gateway = 'manual'; |
|
252 | + } else { |
|
253 | + $enabled_gateway = wpinv_get_default_gateway(); |
|
254 | + } |
|
255 | 255 | |
256 | 256 | if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) { |
257 | 257 | if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){ |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | |
263 | 263 | } |
264 | 264 | |
265 | - return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
265 | + return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | function wpinv_record_gateway_error( $title = '', $message = '' ) { |
@@ -270,21 +270,21 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
273 | - $ret = 0; |
|
274 | - $args = array( |
|
275 | - 'meta_key' => '_wpinv_gateway', |
|
276 | - 'meta_value' => $gateway_id, |
|
277 | - 'nopaging' => true, |
|
278 | - 'post_type' => 'wpi_invoice', |
|
279 | - 'post_status' => $status, |
|
280 | - 'fields' => 'ids' |
|
281 | - ); |
|
282 | - |
|
283 | - $payments = new WP_Query( $args ); |
|
284 | - |
|
285 | - if( $payments ) |
|
286 | - $ret = $payments->post_count; |
|
287 | - return $ret; |
|
273 | + $ret = 0; |
|
274 | + $args = array( |
|
275 | + 'meta_key' => '_wpinv_gateway', |
|
276 | + 'meta_value' => $gateway_id, |
|
277 | + 'nopaging' => true, |
|
278 | + 'post_type' => 'wpi_invoice', |
|
279 | + 'post_status' => $status, |
|
280 | + 'fields' => 'ids' |
|
281 | + ); |
|
282 | + |
|
283 | + $payments = new WP_Query( $args ); |
|
284 | + |
|
285 | + if( $payments ) |
|
286 | + $ret = $payments->post_count; |
|
287 | + return $ret; |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | function wpinv_settings_update_gateways( $input ) { |
@@ -31,16 +31,16 @@ discard block |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | function wpinv_can_checkout() { |
34 | - $can_checkout = true; // Always true for now |
|
34 | + $can_checkout = true; // Always true for now |
|
35 | 35 | |
36 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
36 | + return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | function wpinv_get_success_page_uri() { |
40 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
41 | - $page_id = absint( $page_id ); |
|
40 | + $page_id = wpinv_get_option( 'success_page', 0 ); |
|
41 | + $page_id = absint( $page_id ); |
|
42 | 42 | |
43 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
43 | + return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -51,22 +51,22 @@ discard block |
||
51 | 51 | */ |
52 | 52 | function wpinv_get_history_page_uri( $post_type = 'wpi_invoice' ) { |
53 | 53 | $post_type = sanitize_key( str_replace( 'wpi_', '', $post_type ) ); |
54 | - $page_id = wpinv_get_option( "{$post_type}_history_page", 0 ); |
|
55 | - $page_id = absint( $page_id ); |
|
56 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type ); |
|
54 | + $page_id = wpinv_get_option( "{$post_type}_history_page", 0 ); |
|
55 | + $page_id = absint( $page_id ); |
|
56 | + return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | function wpinv_is_success_page() { |
60 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
61 | - $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
60 | + $is_success_page = wpinv_get_option( 'success_page', false ); |
|
61 | + $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
62 | 62 | |
63 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
63 | + return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | function wpinv_is_invoice_history_page() { |
67 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
68 | - $ret = $ret ? is_page( $ret ) : false; |
|
69 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
67 | + $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
68 | + $ret = $ret ? is_page( $ret ) : false; |
|
69 | + return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | function wpinv_is_subscriptions_history_page() { |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | function wpinv_send_to_failed_page( $args = null ) { |
92 | - $redirect = wpinv_get_failed_transaction_uri(); |
|
92 | + $redirect = wpinv_get_failed_transaction_uri(); |
|
93 | 93 | |
94 | 94 | if ( !empty( $args ) ) { |
95 | 95 | // Check for backward compatibility |
@@ -109,55 +109,55 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | function wpinv_get_checkout_uri( $args = array() ) { |
112 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
113 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
112 | + $uri = wpinv_get_option( 'checkout_page', false ); |
|
113 | + $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
114 | 114 | |
115 | - if ( !empty( $args ) ) { |
|
116 | - // Check for backward compatibility |
|
117 | - if ( is_string( $args ) ) |
|
118 | - $args = str_replace( '?', '', $args ); |
|
115 | + if ( !empty( $args ) ) { |
|
116 | + // Check for backward compatibility |
|
117 | + if ( is_string( $args ) ) |
|
118 | + $args = str_replace( '?', '', $args ); |
|
119 | 119 | |
120 | - $args = wp_parse_args( $args ); |
|
120 | + $args = wp_parse_args( $args ); |
|
121 | 121 | |
122 | - $uri = add_query_arg( $args, $uri ); |
|
123 | - } |
|
122 | + $uri = add_query_arg( $args, $uri ); |
|
123 | + } |
|
124 | 124 | |
125 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
125 | + $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
126 | 126 | |
127 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
127 | + $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
128 | 128 | |
129 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
130 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
131 | - } |
|
129 | + if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
130 | + $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
131 | + } |
|
132 | 132 | |
133 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
133 | + return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | function wpinv_get_success_page_url( $query_string = null ) { |
137 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
138 | - $success_page = get_permalink( $success_page ); |
|
137 | + $success_page = wpinv_get_option( 'success_page', 0 ); |
|
138 | + $success_page = get_permalink( $success_page ); |
|
139 | 139 | |
140 | - if ( $query_string ) |
|
141 | - $success_page .= $query_string; |
|
140 | + if ( $query_string ) |
|
141 | + $success_page .= $query_string; |
|
142 | 142 | |
143 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
143 | + return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | function wpinv_get_failed_transaction_uri( $extras = false ) { |
147 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
148 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
147 | + $uri = wpinv_get_option( 'failure_page', '' ); |
|
148 | + $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
149 | 149 | |
150 | - if ( $extras ) |
|
151 | - $uri .= $extras; |
|
150 | + if ( $extras ) |
|
151 | + $uri .= $extras; |
|
152 | 152 | |
153 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
153 | + return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | function wpinv_is_failed_transaction_page() { |
157 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
158 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
157 | + $ret = wpinv_get_option( 'failure_page', false ); |
|
158 | + $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
159 | 159 | |
160 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
160 | + return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | function wpinv_transaction_query( $type = 'start' ) { |
@@ -232,36 +232,36 @@ discard block |
||
232 | 232 | $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
233 | 233 | |
234 | 234 | if ( $require_billing_details ) { |
235 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
236 | - $required_fields['first_name'] = array( |
|
237 | - 'error_id' => 'invalid_first_name', |
|
238 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
239 | - ); |
|
240 | - } |
|
241 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
242 | - $required_fields['address'] = array( |
|
243 | - 'error_id' => 'invalid_address', |
|
244 | - 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
245 | - ); |
|
246 | - } |
|
247 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
248 | - $required_fields['city'] = array( |
|
249 | - 'error_id' => 'invalid_city', |
|
250 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
251 | - ); |
|
252 | - } |
|
253 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
254 | - $required_fields['state'] = array( |
|
255 | - 'error_id' => 'invalid_state', |
|
256 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
257 | - ); |
|
258 | - } |
|
259 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
260 | - $required_fields['country'] = array( |
|
261 | - 'error_id' => 'invalid_country', |
|
262 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
263 | - ); |
|
264 | - } |
|
235 | + if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
236 | + $required_fields['first_name'] = array( |
|
237 | + 'error_id' => 'invalid_first_name', |
|
238 | + 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
239 | + ); |
|
240 | + } |
|
241 | + if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
242 | + $required_fields['address'] = array( |
|
243 | + 'error_id' => 'invalid_address', |
|
244 | + 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
245 | + ); |
|
246 | + } |
|
247 | + if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
248 | + $required_fields['city'] = array( |
|
249 | + 'error_id' => 'invalid_city', |
|
250 | + 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
251 | + ); |
|
252 | + } |
|
253 | + if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
254 | + $required_fields['state'] = array( |
|
255 | + 'error_id' => 'invalid_state', |
|
256 | + 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
257 | + ); |
|
258 | + } |
|
259 | + if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
260 | + $required_fields['country'] = array( |
|
261 | + 'error_id' => 'invalid_country', |
|
262 | + 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
263 | + ); |
|
264 | + } |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
@@ -15,136 +15,136 @@ |
||
15 | 15 | class WPInv_REST_Invoice_Controller extends GetPaid_REST_Posts_Controller { |
16 | 16 | |
17 | 17 | /** |
18 | - * Post type. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $post_type = 'wpi_invoice'; |
|
23 | - |
|
24 | - /** |
|
25 | - * The base of this controller's route. |
|
26 | - * |
|
27 | - * @since 1.0.13 |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $rest_base = 'invoices'; |
|
31 | - |
|
32 | - /** Contains this controller's class name. |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $crud_class = 'WPInv_Invoice'; |
|
18 | + * Post type. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $post_type = 'wpi_invoice'; |
|
37 | 23 | |
38 | 24 | /** |
39 | - * Retrieves the query params for the invoices collection. |
|
40 | - * |
|
41 | - * @since 1.0.13 |
|
42 | - * |
|
43 | - * @return array Collection parameters. |
|
44 | - */ |
|
45 | - public function get_collection_params() { |
|
46 | - |
|
47 | - $params = array_merge( |
|
48 | - |
|
49 | - parent::get_collection_params(), |
|
50 | - |
|
51 | - array( |
|
52 | - |
|
53 | - |
|
54 | - 'customers' => array( |
|
55 | - 'description' => __( 'Limit result set to invoices for specific user ids.', 'invoicing' ), |
|
56 | - 'type' => 'array', |
|
57 | - 'items' => array( |
|
58 | - 'type' => 'integer', |
|
59 | - ), |
|
60 | - 'default' => array(), |
|
61 | - 'sanitize_callback' => 'wp_parse_id_list', |
|
62 | - ), |
|
63 | - |
|
64 | - 'exclude_customers' => array( |
|
65 | - 'description' => __( 'Exclude invoices to specific users.', 'invoicing' ), |
|
66 | - 'type' => 'array', |
|
67 | - 'items' => array( |
|
68 | - 'type' => 'integer', |
|
69 | - ), |
|
70 | - 'default' => array(), |
|
71 | - 'sanitize_callback' => 'wp_parse_id_list', |
|
72 | - ), |
|
73 | - |
|
74 | - 'parent' => array( |
|
75 | - 'description' => __( 'Limit result set to those of particular parent IDs.', 'invoicing' ), |
|
76 | - 'type' => 'array', |
|
77 | - 'items' => array( |
|
78 | - 'type' => 'integer', |
|
79 | - ), |
|
80 | - 'sanitize_callback' => 'wp_parse_id_list', |
|
81 | - 'default' => array(), |
|
82 | - ), |
|
83 | - |
|
84 | - 'parent_exclude' => array( |
|
85 | - 'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'invoicing' ), |
|
86 | - 'type' => 'array', |
|
87 | - 'items' => array( |
|
88 | - 'type' => 'integer', |
|
89 | - ), |
|
90 | - 'sanitize_callback' => 'wp_parse_id_list', |
|
91 | - 'default' => array(), |
|
92 | - ), |
|
93 | - |
|
94 | - ) |
|
95 | - |
|
96 | - ); |
|
97 | - |
|
98 | - // Filter collection parameters for the invoices controller. |
|
99 | - return apply_filters( 'getpaid_rest_invoices_collection_params', $params, $this ); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Determine the allowed query_vars for a get_items() response and |
|
104 | - * prepare for WP_Query. |
|
105 | - * |
|
106 | - * @param array $prepared_args Prepared arguments. |
|
107 | - * @param WP_REST_Request $request Request object. |
|
108 | - * @return array $query_args |
|
109 | - */ |
|
110 | - protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
111 | - |
|
112 | - $query_args = parent::prepare_items_query( $prepared_args ); |
|
113 | - |
|
114 | - // Retrieve invoices for specific customers. |
|
115 | - if ( ! empty( $request['customers'] ) ) { |
|
116 | - $query_args['author__in'] = $request['customers']; |
|
117 | - } |
|
118 | - |
|
119 | - // Skip invoices for specific customers. |
|
120 | - if ( ! empty( $request['exclude_customers'] ) ) { |
|
121 | - $query_args['author__not_in'] = $request['exclude_customers']; |
|
122 | - } |
|
123 | - |
|
124 | - return apply_filters( 'getpaid_rest_invoices_prepare_items_query', $query_args, $request, $this ); |
|
125 | - |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Retrieves a valid list of post statuses. |
|
130 | - * |
|
131 | - * @since 1.0.15 |
|
132 | - * |
|
133 | - * @return array A list of registered item statuses. |
|
134 | - */ |
|
135 | - public function get_post_statuses() { |
|
136 | - return array_keys( wpinv_get_invoice_statuses( true, false, $this->post_type ) ); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Saves a single invoice. |
|
141 | - * |
|
142 | - * @param WPInv_Invoice $invoice Invoice to save. |
|
143 | - * @return WP_Error|WPInv_Invoice |
|
144 | - */ |
|
145 | - protected function save_object( $invoice ) { |
|
146 | - $invoice->recalculate_total(); |
|
147 | - return parent::save_object( $invoice ); |
|
148 | - } |
|
25 | + * The base of this controller's route. |
|
26 | + * |
|
27 | + * @since 1.0.13 |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $rest_base = 'invoices'; |
|
31 | + |
|
32 | + /** Contains this controller's class name. |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $crud_class = 'WPInv_Invoice'; |
|
37 | + |
|
38 | + /** |
|
39 | + * Retrieves the query params for the invoices collection. |
|
40 | + * |
|
41 | + * @since 1.0.13 |
|
42 | + * |
|
43 | + * @return array Collection parameters. |
|
44 | + */ |
|
45 | + public function get_collection_params() { |
|
46 | + |
|
47 | + $params = array_merge( |
|
48 | + |
|
49 | + parent::get_collection_params(), |
|
50 | + |
|
51 | + array( |
|
52 | + |
|
53 | + |
|
54 | + 'customers' => array( |
|
55 | + 'description' => __( 'Limit result set to invoices for specific user ids.', 'invoicing' ), |
|
56 | + 'type' => 'array', |
|
57 | + 'items' => array( |
|
58 | + 'type' => 'integer', |
|
59 | + ), |
|
60 | + 'default' => array(), |
|
61 | + 'sanitize_callback' => 'wp_parse_id_list', |
|
62 | + ), |
|
63 | + |
|
64 | + 'exclude_customers' => array( |
|
65 | + 'description' => __( 'Exclude invoices to specific users.', 'invoicing' ), |
|
66 | + 'type' => 'array', |
|
67 | + 'items' => array( |
|
68 | + 'type' => 'integer', |
|
69 | + ), |
|
70 | + 'default' => array(), |
|
71 | + 'sanitize_callback' => 'wp_parse_id_list', |
|
72 | + ), |
|
73 | + |
|
74 | + 'parent' => array( |
|
75 | + 'description' => __( 'Limit result set to those of particular parent IDs.', 'invoicing' ), |
|
76 | + 'type' => 'array', |
|
77 | + 'items' => array( |
|
78 | + 'type' => 'integer', |
|
79 | + ), |
|
80 | + 'sanitize_callback' => 'wp_parse_id_list', |
|
81 | + 'default' => array(), |
|
82 | + ), |
|
83 | + |
|
84 | + 'parent_exclude' => array( |
|
85 | + 'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'invoicing' ), |
|
86 | + 'type' => 'array', |
|
87 | + 'items' => array( |
|
88 | + 'type' => 'integer', |
|
89 | + ), |
|
90 | + 'sanitize_callback' => 'wp_parse_id_list', |
|
91 | + 'default' => array(), |
|
92 | + ), |
|
93 | + |
|
94 | + ) |
|
95 | + |
|
96 | + ); |
|
97 | + |
|
98 | + // Filter collection parameters for the invoices controller. |
|
99 | + return apply_filters( 'getpaid_rest_invoices_collection_params', $params, $this ); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Determine the allowed query_vars for a get_items() response and |
|
104 | + * prepare for WP_Query. |
|
105 | + * |
|
106 | + * @param array $prepared_args Prepared arguments. |
|
107 | + * @param WP_REST_Request $request Request object. |
|
108 | + * @return array $query_args |
|
109 | + */ |
|
110 | + protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
111 | + |
|
112 | + $query_args = parent::prepare_items_query( $prepared_args ); |
|
113 | + |
|
114 | + // Retrieve invoices for specific customers. |
|
115 | + if ( ! empty( $request['customers'] ) ) { |
|
116 | + $query_args['author__in'] = $request['customers']; |
|
117 | + } |
|
118 | + |
|
119 | + // Skip invoices for specific customers. |
|
120 | + if ( ! empty( $request['exclude_customers'] ) ) { |
|
121 | + $query_args['author__not_in'] = $request['exclude_customers']; |
|
122 | + } |
|
123 | + |
|
124 | + return apply_filters( 'getpaid_rest_invoices_prepare_items_query', $query_args, $request, $this ); |
|
125 | + |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Retrieves a valid list of post statuses. |
|
130 | + * |
|
131 | + * @since 1.0.15 |
|
132 | + * |
|
133 | + * @return array A list of registered item statuses. |
|
134 | + */ |
|
135 | + public function get_post_statuses() { |
|
136 | + return array_keys( wpinv_get_invoice_statuses( true, false, $this->post_type ) ); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Saves a single invoice. |
|
141 | + * |
|
142 | + * @param WPInv_Invoice $invoice Invoice to save. |
|
143 | + * @return WP_Error|WPInv_Invoice |
|
144 | + */ |
|
145 | + protected function save_object( $invoice ) { |
|
146 | + $invoice->recalculate_total(); |
|
147 | + return parent::save_object( $invoice ); |
|
148 | + } |
|
149 | 149 | |
150 | 150 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | 142 | function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
143 | + return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -175,122 +175,122 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
178 | + do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
179 | 179 | |
180 | - // Setup possible parts |
|
181 | - $templates = array(); |
|
182 | - if ( isset( $name ) ) |
|
183 | - $templates[] = $slug . '-' . $name . '.php'; |
|
184 | - $templates[] = $slug . '.php'; |
|
180 | + // Setup possible parts |
|
181 | + $templates = array(); |
|
182 | + if ( isset( $name ) ) |
|
183 | + $templates[] = $slug . '-' . $name . '.php'; |
|
184 | + $templates[] = $slug . '.php'; |
|
185 | 185 | |
186 | - // Allow template parts to be filtered |
|
187 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
186 | + // Allow template parts to be filtered |
|
187 | + $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
188 | 188 | |
189 | - // Return the part that is found |
|
190 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
189 | + // Return the part that is found |
|
190 | + return wpinv_locate_tmpl( $templates, $load, false ); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
194 | - // No file found yet |
|
195 | - $located = false; |
|
194 | + // No file found yet |
|
195 | + $located = false; |
|
196 | 196 | |
197 | - // Try to find a template file |
|
198 | - foreach ( (array)$template_names as $template_name ) { |
|
197 | + // Try to find a template file |
|
198 | + foreach ( (array)$template_names as $template_name ) { |
|
199 | 199 | |
200 | - // Continue if template is empty |
|
201 | - if ( empty( $template_name ) ) |
|
202 | - continue; |
|
200 | + // Continue if template is empty |
|
201 | + if ( empty( $template_name ) ) |
|
202 | + continue; |
|
203 | 203 | |
204 | - // Trim off any slashes from the template name |
|
205 | - $template_name = ltrim( $template_name, '/' ); |
|
204 | + // Trim off any slashes from the template name |
|
205 | + $template_name = ltrim( $template_name, '/' ); |
|
206 | 206 | |
207 | - // try locating this template file by looping through the template paths |
|
208 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
207 | + // try locating this template file by looping through the template paths |
|
208 | + foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
209 | 209 | |
210 | - if( file_exists( $template_path . $template_name ) ) { |
|
211 | - $located = $template_path . $template_name; |
|
212 | - break; |
|
213 | - } |
|
214 | - } |
|
210 | + if( file_exists( $template_path . $template_name ) ) { |
|
211 | + $located = $template_path . $template_name; |
|
212 | + break; |
|
213 | + } |
|
214 | + } |
|
215 | 215 | |
216 | - if( !empty( $located ) ) { |
|
217 | - break; |
|
218 | - } |
|
219 | - } |
|
216 | + if( !empty( $located ) ) { |
|
217 | + break; |
|
218 | + } |
|
219 | + } |
|
220 | 220 | |
221 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
222 | - load_template( $located, $require_once ); |
|
221 | + if ( ( true == $load ) && ! empty( $located ) ) |
|
222 | + load_template( $located, $require_once ); |
|
223 | 223 | |
224 | - return $located; |
|
224 | + return $located; |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | function wpinv_get_theme_template_paths() { |
228 | - $template_dir = wpinv_get_theme_template_dir_name(); |
|
228 | + $template_dir = wpinv_get_theme_template_dir_name(); |
|
229 | 229 | |
230 | - $file_paths = array( |
|
231 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
232 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
233 | - 100 => wpinv_get_templates_dir() |
|
234 | - ); |
|
230 | + $file_paths = array( |
|
231 | + 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
232 | + 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
233 | + 100 => wpinv_get_templates_dir() |
|
234 | + ); |
|
235 | 235 | |
236 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
236 | + $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
237 | 237 | |
238 | - // sort the file paths based on priority |
|
239 | - ksort( $file_paths, SORT_NUMERIC ); |
|
238 | + // sort the file paths based on priority |
|
239 | + ksort( $file_paths, SORT_NUMERIC ); |
|
240 | 240 | |
241 | - return array_map( 'trailingslashit', $file_paths ); |
|
241 | + return array_map( 'trailingslashit', $file_paths ); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | function wpinv_checkout_meta_tags() { |
245 | 245 | |
246 | - $pages = array(); |
|
247 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
248 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
249 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
250 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
246 | + $pages = array(); |
|
247 | + $pages[] = wpinv_get_option( 'success_page' ); |
|
248 | + $pages[] = wpinv_get_option( 'failure_page' ); |
|
249 | + $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
250 | + $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
251 | 251 | |
252 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
253 | - return; |
|
254 | - } |
|
252 | + if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
253 | + return; |
|
254 | + } |
|
255 | 255 | |
256 | - echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
256 | + echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
257 | 257 | } |
258 | 258 | add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
259 | 259 | |
260 | 260 | function wpinv_add_body_classes( $class ) { |
261 | - $classes = (array)$class; |
|
261 | + $classes = (array)$class; |
|
262 | 262 | |
263 | - if( wpinv_is_checkout() ) { |
|
264 | - $classes[] = 'wpinv-checkout'; |
|
265 | - $classes[] = 'wpinv-page'; |
|
266 | - } |
|
263 | + if( wpinv_is_checkout() ) { |
|
264 | + $classes[] = 'wpinv-checkout'; |
|
265 | + $classes[] = 'wpinv-page'; |
|
266 | + } |
|
267 | 267 | |
268 | - if( wpinv_is_success_page() ) { |
|
269 | - $classes[] = 'wpinv-success'; |
|
270 | - $classes[] = 'wpinv-page'; |
|
271 | - } |
|
268 | + if( wpinv_is_success_page() ) { |
|
269 | + $classes[] = 'wpinv-success'; |
|
270 | + $classes[] = 'wpinv-page'; |
|
271 | + } |
|
272 | 272 | |
273 | - if( wpinv_is_failed_transaction_page() ) { |
|
274 | - $classes[] = 'wpinv-failed-transaction'; |
|
275 | - $classes[] = 'wpinv-page'; |
|
276 | - } |
|
273 | + if( wpinv_is_failed_transaction_page() ) { |
|
274 | + $classes[] = 'wpinv-failed-transaction'; |
|
275 | + $classes[] = 'wpinv-page'; |
|
276 | + } |
|
277 | 277 | |
278 | - if( wpinv_is_invoice_history_page() ) { |
|
279 | - $classes[] = 'wpinv-history'; |
|
280 | - $classes[] = 'wpinv-page'; |
|
281 | - } |
|
278 | + if( wpinv_is_invoice_history_page() ) { |
|
279 | + $classes[] = 'wpinv-history'; |
|
280 | + $classes[] = 'wpinv-page'; |
|
281 | + } |
|
282 | 282 | |
283 | - if( wpinv_is_subscriptions_history_page() ) { |
|
284 | - $classes[] = 'wpinv-subscription'; |
|
285 | - $classes[] = 'wpinv-page'; |
|
286 | - } |
|
283 | + if( wpinv_is_subscriptions_history_page() ) { |
|
284 | + $classes[] = 'wpinv-subscription'; |
|
285 | + $classes[] = 'wpinv-page'; |
|
286 | + } |
|
287 | 287 | |
288 | - if( wpinv_is_test_mode() ) { |
|
289 | - $classes[] = 'wpinv-test-mode'; |
|
290 | - $classes[] = 'wpinv-page'; |
|
291 | - } |
|
288 | + if( wpinv_is_test_mode() ) { |
|
289 | + $classes[] = 'wpinv-test-mode'; |
|
290 | + $classes[] = 'wpinv-page'; |
|
291 | + } |
|
292 | 292 | |
293 | - return array_unique( $classes ); |
|
293 | + return array_unique( $classes ); |
|
294 | 294 | } |
295 | 295 | add_filter( 'body_class', 'wpinv_add_body_classes' ); |
296 | 296 | |
@@ -859,21 +859,21 @@ discard block |
||
859 | 859 | |
860 | 860 | $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
861 | 861 | |
862 | - // Remove unavailable tags. |
|
862 | + // Remove unavailable tags. |
|
863 | 863 | $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address ); |
864 | 864 | |
865 | 865 | // Clean up white space. |
866 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
866 | + $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
867 | 867 | $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
868 | 868 | |
869 | 869 | // Break newlines apart and remove empty lines/trim commas and white space. |
870 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
870 | + $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
871 | 871 | |
872 | 872 | // Add html breaks. |
873 | - $formatted_address = implode( $separator, $formatted_address ); |
|
873 | + $formatted_address = implode( $separator, $formatted_address ); |
|
874 | 874 | |
875 | - // We're done! |
|
876 | - return $formatted_address; |
|
875 | + // We're done! |
|
876 | + return $formatted_address; |
|
877 | 877 | |
878 | 878 | } |
879 | 879 | |
@@ -1075,7 +1075,7 @@ discard block |
||
1075 | 1075 | } |
1076 | 1076 | |
1077 | 1077 | function wpinv_empty_cart_message() { |
1078 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1078 | + return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | /** |
@@ -1343,10 +1343,10 @@ discard block |
||
1343 | 1343 | |
1344 | 1344 | if ( 0 == count( $form->get_items() ) ) { |
1345 | 1345 | echo aui()->alert( |
1346 | - array( |
|
1347 | - 'type' => 'warning', |
|
1348 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1349 | - ) |
|
1346 | + array( |
|
1347 | + 'type' => 'warning', |
|
1348 | + 'content' => __( 'No published items found', 'invoicing' ), |
|
1349 | + ) |
|
1350 | 1350 | ); |
1351 | 1351 | return; |
1352 | 1352 | } |
@@ -1364,21 +1364,21 @@ discard block |
||
1364 | 1364 | $invoice = wpinv_get_invoice( $invoice_id ); |
1365 | 1365 | |
1366 | 1366 | if ( empty( $invoice ) ) { |
1367 | - echo aui()->alert( |
|
1368 | - array( |
|
1369 | - 'type' => 'warning', |
|
1370 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1371 | - ) |
|
1367 | + echo aui()->alert( |
|
1368 | + array( |
|
1369 | + 'type' => 'warning', |
|
1370 | + 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1371 | + ) |
|
1372 | 1372 | ); |
1373 | 1373 | return; |
1374 | 1374 | } |
1375 | 1375 | |
1376 | 1376 | if ( $invoice->is_paid() ) { |
1377 | - echo aui()->alert( |
|
1378 | - array( |
|
1379 | - 'type' => 'warning', |
|
1380 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1381 | - ) |
|
1377 | + echo aui()->alert( |
|
1378 | + array( |
|
1379 | + 'type' => 'warning', |
|
1380 | + 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1381 | + ) |
|
1382 | 1382 | ); |
1383 | 1383 | return; |
1384 | 1384 | } |
@@ -1440,7 +1440,7 @@ discard block |
||
1440 | 1440 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; |
1441 | 1441 | } |
1442 | 1442 | |
1443 | - if ( ! empty( $items ) ) { |
|
1443 | + if ( ! empty( $items ) ) { |
|
1444 | 1444 | $items = esc_attr( $items ); |
1445 | 1445 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; |
1446 | 1446 | } |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | |
14 | 14 | |
15 | 15 | function wpinv_get_default_country() { |
16 | - $country = wpinv_get_option( 'default_country', 'UK' ); |
|
16 | + $country = wpinv_get_option( 'default_country', 'UK' ); |
|
17 | 17 | |
18 | - return apply_filters( 'wpinv_default_country', $country ); |
|
18 | + return apply_filters( 'wpinv_default_country', $country ); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | function wpinv_sanitize_country( $country ) { |
28 | 28 | |
29 | - // Enure the country is specified |
|
29 | + // Enure the country is specified |
|
30 | 30 | if ( empty( $country ) ) { |
31 | 31 | $country = wpinv_get_default_country(); |
32 | 32 | } |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | function wpinv_get_default_state() { |
59 | - $state = wpinv_get_option( 'default_state', '' ); |
|
59 | + $state = wpinv_get_option( 'default_state', '' ); |
|
60 | 60 | |
61 | - return apply_filters( 'wpinv_default_state', $state ); |
|
61 | + return apply_filters( 'wpinv_default_state', $state ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | function wpinv_state_name( $state_code = '', $country_code = '' ) { |
@@ -288,11 +288,11 @@ discard block |
||
288 | 288 | |
289 | 289 | $country = wpinv_sanitize_country( $country ); |
290 | 290 | |
291 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
292 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
293 | - return $continent_code; |
|
294 | - } |
|
295 | - } |
|
291 | + foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
292 | + if ( false !== array_search( $country, $countries, true ) ) { |
|
293 | + return $continent_code; |
|
294 | + } |
|
295 | + } |
|
296 | 296 | |
297 | 297 | return ''; |
298 | 298 | |
@@ -584,30 +584,30 @@ discard block |
||
584 | 584 | } |
585 | 585 | |
586 | 586 | function wpinv_get_states_field() { |
587 | - if( empty( $_POST['country'] ) ) { |
|
588 | - $_POST['country'] = wpinv_get_default_country(); |
|
589 | - } |
|
590 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
587 | + if( empty( $_POST['country'] ) ) { |
|
588 | + $_POST['country'] = wpinv_get_default_country(); |
|
589 | + } |
|
590 | + $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
591 | 591 | |
592 | - if( !empty( $states ) ) { |
|
593 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
592 | + if( !empty( $states ) ) { |
|
593 | + $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
594 | 594 | |
595 | 595 | $args = array( |
596 | - 'name' => $sanitized_field_name, |
|
597 | - 'id' => $sanitized_field_name, |
|
598 | - 'class' => $sanitized_field_name . 'custom-select wpinv-select wpi_select2', |
|
599 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
600 | - 'show_option_all' => false, |
|
601 | - 'show_option_none' => false |
|
602 | - ); |
|
603 | - |
|
604 | - $response = wpinv_html_select( $args ); |
|
605 | - |
|
606 | - } else { |
|
607 | - $response = 'nostates'; |
|
608 | - } |
|
596 | + 'name' => $sanitized_field_name, |
|
597 | + 'id' => $sanitized_field_name, |
|
598 | + 'class' => $sanitized_field_name . 'custom-select wpinv-select wpi_select2', |
|
599 | + 'options' => array_merge( array( '' => '' ), $states ), |
|
600 | + 'show_option_all' => false, |
|
601 | + 'show_option_none' => false |
|
602 | + ); |
|
603 | + |
|
604 | + $response = wpinv_html_select( $args ); |
|
605 | + |
|
606 | + } else { |
|
607 | + $response = 'nostates'; |
|
608 | + } |
|
609 | 609 | |
610 | - return $response; |
|
610 | + return $response; |
|
611 | 611 | } |
612 | 612 | |
613 | 613 | function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
@@ -625,46 +625,46 @@ discard block |
||
625 | 625 | */ |
626 | 626 | function wpinv_get_address_formats() { |
627 | 627 | |
628 | - return apply_filters( 'wpinv_localisation_address_formats', |
|
629 | - array( |
|
630 | - 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
|
631 | - 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
|
632 | - 'AT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
633 | - 'BE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
634 | - 'CA' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}} {{zip}}\n{{country}}", |
|
635 | - 'CH' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
636 | - 'CL' => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}", |
|
637 | - 'CN' => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}", |
|
638 | - 'CZ' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
639 | - 'DE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
640 | - 'EE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
641 | - 'FI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
642 | - 'DK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
643 | - 'FR' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}", |
|
644 | - 'HK' => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}", |
|
645 | - 'HU' => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}", |
|
646 | - 'IN' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}", |
|
647 | - 'IS' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
648 | - 'IT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}", |
|
649 | - 'JP' => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}", |
|
650 | - 'TW' => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}", |
|
651 | - 'LI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
652 | - 'NL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
653 | - 'NZ' => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}", |
|
654 | - 'NO' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
655 | - 'PL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
656 | - 'PT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
657 | - 'SK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
658 | - 'RS' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
659 | - 'SI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
660 | - 'ES' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}", |
|
661 | - 'SE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
662 | - 'TR' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}", |
|
663 | - 'UG' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}", |
|
664 | - 'US' => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}", |
|
665 | - 'VN' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}", |
|
666 | - ) |
|
667 | - ); |
|
628 | + return apply_filters( 'wpinv_localisation_address_formats', |
|
629 | + array( |
|
630 | + 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
|
631 | + 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
|
632 | + 'AT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
633 | + 'BE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
634 | + 'CA' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}} {{zip}}\n{{country}}", |
|
635 | + 'CH' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
636 | + 'CL' => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}", |
|
637 | + 'CN' => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}", |
|
638 | + 'CZ' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
639 | + 'DE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
640 | + 'EE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
641 | + 'FI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
642 | + 'DK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
643 | + 'FR' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}", |
|
644 | + 'HK' => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}", |
|
645 | + 'HU' => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}", |
|
646 | + 'IN' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}", |
|
647 | + 'IS' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
648 | + 'IT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}", |
|
649 | + 'JP' => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}", |
|
650 | + 'TW' => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}", |
|
651 | + 'LI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
652 | + 'NL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
653 | + 'NZ' => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}", |
|
654 | + 'NO' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
655 | + 'PL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
656 | + 'PT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
657 | + 'SK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
658 | + 'RS' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
659 | + 'SI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
660 | + 'ES' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}", |
|
661 | + 'SE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
662 | + 'TR' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}", |
|
663 | + 'UG' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}", |
|
664 | + 'US' => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}", |
|
665 | + 'VN' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}", |
|
666 | + ) |
|
667 | + ); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | /** |
@@ -681,21 +681,21 @@ discard block |
||
681 | 681 | } |
682 | 682 | |
683 | 683 | // Get all formats. |
684 | - $formats = wpinv_get_address_formats(); |
|
684 | + $formats = wpinv_get_address_formats(); |
|
685 | 685 | |
686 | - // Get format for the specified country. |
|
687 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
686 | + // Get format for the specified country. |
|
687 | + $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
688 | 688 | |
689 | 689 | /** |
690 | - * Filters the address format to use on Invoices. |
|
690 | + * Filters the address format to use on Invoices. |
|
691 | 691 | * |
692 | 692 | * New lines will be replaced by a `br` element. Double new lines will be replaced by a paragraph. HTML tags are allowed. |
693 | - * |
|
694 | - * @since 1.0.13 |
|
695 | - * |
|
696 | - * @param string $format The address format to use. |
|
693 | + * |
|
694 | + * @since 1.0.13 |
|
695 | + * |
|
696 | + * @param string $format The address format to use. |
|
697 | 697 | * @param string $country The country who's address format is being retrieved. |
698 | - */ |
|
698 | + */ |
|
699 | 699 | return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
700 | 700 | } |
701 | 701 | |
@@ -716,8 +716,8 @@ discard block |
||
716 | 716 | 'country' => '', |
717 | 717 | 'zip' => '', |
718 | 718 | 'first_name' => '', |
719 | - 'last_name' => '', |
|
720 | - 'company' => '', |
|
719 | + 'last_name' => '', |
|
720 | + 'company' => '', |
|
721 | 721 | ); |
722 | 722 | |
723 | 723 | $args = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' ); |
@@ -738,14 +738,14 @@ discard block |
||
738 | 738 | $args['country_code']= $country; |
739 | 739 | |
740 | 740 | /** |
741 | - * Filters the address format replacements to use on Invoices. |
|
741 | + * Filters the address format replacements to use on Invoices. |
|
742 | 742 | * |
743 | - * |
|
744 | - * @since 1.0.13 |
|
745 | - * |
|
746 | - * @param array $replacements The address replacements to use. |
|
743 | + * |
|
744 | + * @since 1.0.13 |
|
745 | + * |
|
746 | + * @param array $replacements The address replacements to use. |
|
747 | 747 | * @param array $billing_details The billing details to use. |
748 | - */ |
|
748 | + */ |
|
749 | 749 | $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
750 | 750 | |
751 | 751 | $return = array(); |
@@ -768,5 +768,5 @@ discard block |
||
768 | 768 | * @return string |
769 | 769 | */ |
770 | 770 | function wpinv_trim_formatted_address_line( $line ) { |
771 | - return trim( $line, ', ' ); |
|
771 | + return trim( $line, ', ' ); |
|
772 | 772 | } |
773 | 773 | \ No newline at end of file |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | 'getpaid-nonce' |
64 | 64 | ) |
65 | 65 | ); |
66 | - $anchor = __( 'Deactivate', 'invoicing' ); |
|
67 | - $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
66 | + $anchor = __( 'Deactivate', 'invoicing' ); |
|
67 | + $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
68 | 68 | $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
69 | 69 | |
70 | 70 | } else if( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | 'getpaid-nonce' |
82 | 82 | ) |
83 | 83 | ); |
84 | - $anchor = __( 'Activate', 'invoicing' ); |
|
85 | - $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
84 | + $anchor = __( 'Activate', 'invoicing' ); |
|
85 | + $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
86 | 86 | $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
87 | 87 | |
88 | 88 | } |
@@ -99,8 +99,8 @@ discard block |
||
99 | 99 | 'getpaid-nonce' |
100 | 100 | ) |
101 | 101 | ); |
102 | - $anchor = __( 'Delete', 'invoicing' ); |
|
103 | - $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
102 | + $anchor = __( 'Delete', 'invoicing' ); |
|
103 | + $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
104 | 104 | $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
105 | 105 | |
106 | 106 | $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
@@ -56,7 +56,7 @@ |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | function wpinv_admin_messages() { |
59 | - settings_errors( 'wpinv-notices' ); |
|
59 | + settings_errors( 'wpinv-notices' ); |
|
60 | 60 | } |
61 | 61 | add_action( 'admin_notices', 'wpinv_admin_messages' ); |
62 | 62 |
@@ -12,108 +12,108 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Daily_Maintenance { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - */ |
|
18 | - public function __construct(){ |
|
19 | - |
|
20 | - // Clear deprecated events. |
|
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | - |
|
23 | - // (Maybe) schedule a cron that runs daily. |
|
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | - |
|
26 | - // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
31 | - |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * Schedules a cron to run every day at 7 a.m |
|
36 | - * |
|
37 | - */ |
|
38 | - public function maybe_create_scheduled_event() { |
|
39 | - |
|
40 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
41 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
42 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
43 | - } |
|
44 | - |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Clears deprecated events. |
|
49 | - * |
|
50 | - */ |
|
51 | - public function maybe_clear_deprecated_events() { |
|
52 | - |
|
53 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
54 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
56 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
57 | - } |
|
58 | - |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Fires the old hook for backwards compatibility. |
|
63 | - * |
|
64 | - */ |
|
65 | - public function backwards_compat() { |
|
66 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Expires expired subscriptions. |
|
71 | - * |
|
72 | - */ |
|
73 | - public function maybe_expire_subscriptions() { |
|
74 | - |
|
75 | - // Fetch expired subscriptions (skips those that expire today). |
|
76 | - $args = array( |
|
77 | - 'number' => -1, |
|
78 | - 'count_total' => false, |
|
79 | - 'status' => 'trialling active failing cancelled', |
|
80 | - 'date_expires_query' => array( |
|
81 | - 'before' => 'today', |
|
82 | - 'inclusive' => false, |
|
83 | - ), |
|
84 | - ); |
|
85 | - |
|
86 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
87 | - |
|
88 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
89 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
90 | - $subscription->set_status( 'expired' ); |
|
91 | - $subscription->save(); |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Logs cron runs. |
|
99 | - * |
|
100 | - */ |
|
101 | - public function log_cron_run() { |
|
102 | - wpinv_error_log( 'GetPaid Daily Cron' ); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Updates GeoIP databases. |
|
107 | - * |
|
108 | - */ |
|
109 | - public function maybe_update_geoip_databases() { |
|
110 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
111 | - |
|
112 | - if ( false === $updated ) { |
|
113 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
114 | - do_action( 'getpaid_update_geoip_databases' ); |
|
115 | - } |
|
116 | - |
|
117 | - } |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + */ |
|
18 | + public function __construct(){ |
|
19 | + |
|
20 | + // Clear deprecated events. |
|
21 | + add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | + |
|
23 | + // (Maybe) schedule a cron that runs daily. |
|
24 | + add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | + |
|
26 | + // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | + add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | + add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
31 | + |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * Schedules a cron to run every day at 7 a.m |
|
36 | + * |
|
37 | + */ |
|
38 | + public function maybe_create_scheduled_event() { |
|
39 | + |
|
40 | + if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
41 | + $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
42 | + wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
43 | + } |
|
44 | + |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Clears deprecated events. |
|
49 | + * |
|
50 | + */ |
|
51 | + public function maybe_clear_deprecated_events() { |
|
52 | + |
|
53 | + if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
54 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
55 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
56 | + update_option( 'wpinv_cleared_old_events', 1 ); |
|
57 | + } |
|
58 | + |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Fires the old hook for backwards compatibility. |
|
63 | + * |
|
64 | + */ |
|
65 | + public function backwards_compat() { |
|
66 | + do_action( 'wpinv_register_schedule_event_daily' ); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Expires expired subscriptions. |
|
71 | + * |
|
72 | + */ |
|
73 | + public function maybe_expire_subscriptions() { |
|
74 | + |
|
75 | + // Fetch expired subscriptions (skips those that expire today). |
|
76 | + $args = array( |
|
77 | + 'number' => -1, |
|
78 | + 'count_total' => false, |
|
79 | + 'status' => 'trialling active failing cancelled', |
|
80 | + 'date_expires_query' => array( |
|
81 | + 'before' => 'today', |
|
82 | + 'inclusive' => false, |
|
83 | + ), |
|
84 | + ); |
|
85 | + |
|
86 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
87 | + |
|
88 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
89 | + if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
90 | + $subscription->set_status( 'expired' ); |
|
91 | + $subscription->save(); |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Logs cron runs. |
|
99 | + * |
|
100 | + */ |
|
101 | + public function log_cron_run() { |
|
102 | + wpinv_error_log( 'GetPaid Daily Cron' ); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Updates GeoIP databases. |
|
107 | + * |
|
108 | + */ |
|
109 | + public function maybe_update_geoip_databases() { |
|
110 | + $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
111 | + |
|
112 | + if ( false === $updated ) { |
|
113 | + set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
114 | + do_action( 'getpaid_update_geoip_databases' ); |
|
115 | + } |
|
116 | + |
|
117 | + } |
|
118 | 118 | |
119 | 119 | } |