@@ -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 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
10 | - exit; // Exit if accessed directly |
|
10 | + exit; // Exit if accessed directly |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -15,22 +15,22 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Meta_Box_Invoice_Shipping_Address { |
17 | 17 | |
18 | - /** |
|
19 | - * Output the metabox. |
|
20 | - * |
|
21 | - * @param WP_Post $post |
|
22 | - */ |
|
23 | - public static function output( $post ) { |
|
18 | + /** |
|
19 | + * Output the metabox. |
|
20 | + * |
|
21 | + * @param WP_Post $post |
|
22 | + */ |
|
23 | + public static function output( $post ) { |
|
24 | 24 | |
25 | - // Retrieve shipping address. |
|
26 | - $shipping_address = get_post_meta( $post->ID, 'shipping_address', true ); |
|
25 | + // Retrieve shipping address. |
|
26 | + $shipping_address = get_post_meta( $post->ID, 'shipping_address', true ); |
|
27 | 27 | |
28 | - // Abort if it is invalid. |
|
29 | - if ( ! is_array( $shipping_address ) ) { |
|
30 | - return; |
|
31 | - } |
|
28 | + // Abort if it is invalid. |
|
29 | + if ( ! is_array( $shipping_address ) ) { |
|
30 | + return; |
|
31 | + } |
|
32 | 32 | |
33 | - ?> |
|
33 | + ?> |
|
34 | 34 | |
35 | 35 | <div class="bsui"> |
36 | 36 | |
@@ -55,31 +55,31 @@ discard block |
||
55 | 55 | |
56 | 56 | <?php |
57 | 57 | |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Prepares a value. |
|
62 | - * |
|
63 | - * @param array $address |
|
64 | - * @param string $key |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public static function prepare_for_display( $address, $key ) { |
|
60 | + /** |
|
61 | + * Prepares a value. |
|
62 | + * |
|
63 | + * @param array $address |
|
64 | + * @param string $key |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public static function prepare_for_display( $address, $key ) { |
|
68 | 68 | |
69 | - // Prepare the value. |
|
70 | - $value = $address[ $key ]; |
|
69 | + // Prepare the value. |
|
70 | + $value = $address[ $key ]; |
|
71 | 71 | |
72 | - if ( $key == 'country' ) { |
|
73 | - $value = wpinv_country_name( $value ); |
|
74 | - } |
|
72 | + if ( $key == 'country' ) { |
|
73 | + $value = wpinv_country_name( $value ); |
|
74 | + } |
|
75 | 75 | |
76 | - if ( $key == 'state' ) { |
|
77 | - $country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country(); |
|
78 | - $value = wpinv_state_name( $value, $country ); |
|
79 | - } |
|
76 | + if ( $key == 'state' ) { |
|
77 | + $country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country(); |
|
78 | + $value = wpinv_state_name( $value, $country ); |
|
79 | + } |
|
80 | 80 | |
81 | - return sanitize_text_field( $value ); |
|
81 | + return sanitize_text_field( $value ); |
|
82 | 82 | |
83 | - } |
|
83 | + } |
|
84 | 84 | |
85 | 85 | } |
@@ -13,17 +13,17 @@ discard block |
||
13 | 13 | class GetPaid_Notification_Email_Sender { |
14 | 14 | |
15 | 15 | /** |
16 | - * Whether or not we should inline CSS into the email. |
|
17 | - */ |
|
18 | - public $inline_css = true; |
|
16 | + * Whether or not we should inline CSS into the email. |
|
17 | + */ |
|
18 | + public $inline_css = true; |
|
19 | 19 | |
20 | 20 | /** |
21 | - * The wp_mail() data. |
|
22 | - */ |
|
21 | + * The wp_mail() data. |
|
22 | + */ |
|
23 | 23 | public $wp_mail_data = null; |
24 | 24 | |
25 | 25 | /** |
26 | - * Sends a new email. |
|
26 | + * Sends a new email. |
|
27 | 27 | * |
28 | 28 | * @param string|array $to The recipients email or an array of recipient emails. |
29 | 29 | * @param string $subject The email's subject. |
@@ -31,49 +31,49 @@ discard block |
||
31 | 31 | * @param array $attachments The email attachments. |
32 | 32 | * |
33 | 33 | * @return bool |
34 | - */ |
|
35 | - public function send( $to, $subject, $email, $attachments = array() ) { |
|
34 | + */ |
|
35 | + public function send( $to, $subject, $email, $attachments = array() ) { |
|
36 | 36 | |
37 | - /* |
|
37 | + /* |
|
38 | 38 | * Allow to filter data on per-email basis. |
39 | 39 | */ |
40 | - $data = apply_filters( |
|
41 | - 'getpaid_email_data', |
|
42 | - array( |
|
43 | - 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
44 | - 'subject' => htmlspecialchars_decode( strip_tags( $subject ), ENT_QUOTES ), |
|
45 | - 'email' => apply_filters( 'wpinv_mail_content', $email ), |
|
46 | - 'headers' => $this->get_headers(), |
|
47 | - 'attachments' => $attachments, |
|
48 | - ), |
|
49 | - $this |
|
50 | - ); |
|
40 | + $data = apply_filters( |
|
41 | + 'getpaid_email_data', |
|
42 | + array( |
|
43 | + 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
44 | + 'subject' => htmlspecialchars_decode( strip_tags( $subject ), ENT_QUOTES ), |
|
45 | + 'email' => apply_filters( 'wpinv_mail_content', $email ), |
|
46 | + 'headers' => $this->get_headers(), |
|
47 | + 'attachments' => $attachments, |
|
48 | + ), |
|
49 | + $this |
|
50 | + ); |
|
51 | 51 | |
52 | 52 | // Remove slashes. |
53 | 53 | $data = (array) wp_unslash( $data ); |
54 | 54 | |
55 | 55 | // Cache it. |
56 | - $this->wp_mail_data = $data; |
|
56 | + $this->wp_mail_data = $data; |
|
57 | 57 | |
58 | - // Attach our own hooks. |
|
59 | - $this->before_sending(); |
|
58 | + // Attach our own hooks. |
|
59 | + $this->before_sending(); |
|
60 | 60 | |
61 | 61 | $result = false; |
62 | 62 | |
63 | 63 | foreach ( $this->wp_mail_data['to'] as $to ) { |
64 | - $result = $this->_send( $to, $data ); |
|
64 | + $result = $this->_send( $to, $data ); |
|
65 | 65 | } |
66 | 66 | |
67 | - // Remove our hooks. |
|
68 | - $this->after_sending(); |
|
67 | + // Remove our hooks. |
|
68 | + $this->after_sending(); |
|
69 | 69 | |
70 | - $this->wp_mail_data = null; |
|
70 | + $this->wp_mail_data = null; |
|
71 | 71 | |
72 | - return $result; |
|
73 | - } |
|
72 | + return $result; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Does the actual sending. |
|
75 | + /** |
|
76 | + * Does the actual sending. |
|
77 | 77 | * |
78 | 78 | * @param string $to The recipient's email. |
79 | 79 | * @param array $data The email's data. |
@@ -81,81 +81,81 @@ discard block |
||
81 | 81 | * @param array $attachments The email attachments. |
82 | 82 | * |
83 | 83 | * @return bool |
84 | - */ |
|
85 | - protected function _send( $to, $data ) { |
|
86 | - |
|
87 | - // Prepare the sending function. |
|
88 | - $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
89 | - |
|
90 | - // Send the actual email. |
|
91 | - $result = call_user_func( |
|
92 | - $sending_function, |
|
93 | - $to, |
|
94 | - html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
95 | - $data['email'], |
|
96 | - $data['headers'], |
|
97 | - $data['attachments'] |
|
98 | - ); |
|
99 | - |
|
100 | - if ( ! $result ) { |
|
101 | - $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
102 | - wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
103 | - } |
|
104 | - |
|
105 | - return $result; |
|
106 | - } |
|
84 | + */ |
|
85 | + protected function _send( $to, $data ) { |
|
86 | + |
|
87 | + // Prepare the sending function. |
|
88 | + $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
89 | + |
|
90 | + // Send the actual email. |
|
91 | + $result = call_user_func( |
|
92 | + $sending_function, |
|
93 | + $to, |
|
94 | + html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
95 | + $data['email'], |
|
96 | + $data['headers'], |
|
97 | + $data['attachments'] |
|
98 | + ); |
|
99 | + |
|
100 | + if ( ! $result ) { |
|
101 | + $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
102 | + wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
103 | + } |
|
104 | + |
|
105 | + return $result; |
|
106 | + } |
|
107 | 107 | |
108 | 108 | /** |
109 | - * Retrieves email headers. |
|
110 | - */ |
|
111 | - public function get_headers() { |
|
109 | + * Retrieves email headers. |
|
110 | + */ |
|
111 | + public function get_headers() { |
|
112 | 112 | |
113 | - $name = $this->get_from_name(); |
|
114 | - $reply_to = $this->get_reply_to(); |
|
115 | - $headers = array( "Reply-To:$name <$reply_to>" ); |
|
113 | + $name = $this->get_from_name(); |
|
114 | + $reply_to = $this->get_reply_to(); |
|
115 | + $headers = array( "Reply-To:$name <$reply_to>" ); |
|
116 | 116 | |
117 | - return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
117 | + return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
118 | 118 | |
119 | - } |
|
119 | + } |
|
120 | 120 | |
121 | 121 | /** |
122 | - * Fires before an email is sent |
|
123 | - * |
|
124 | - * @since 1.0.0 |
|
125 | - */ |
|
126 | - public function before_sending() { |
|
122 | + * Fires before an email is sent |
|
123 | + * |
|
124 | + * @since 1.0.0 |
|
125 | + */ |
|
126 | + public function before_sending() { |
|
127 | 127 | |
128 | 128 | do_action( 'getpaid_before_send_email', $this ); |
129 | - add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
130 | - add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
131 | - add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
132 | - add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
129 | + add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
130 | + add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
131 | + add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
132 | + add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
133 | 133 | |
134 | - } |
|
134 | + } |
|
135 | 135 | |
136 | 136 | /** |
137 | - * Returns the from name. |
|
138 | - */ |
|
139 | - public function get_from_name() { |
|
137 | + * Returns the from name. |
|
138 | + */ |
|
139 | + public function get_from_name() { |
|
140 | 140 | |
141 | 141 | $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) ); |
142 | 142 | |
143 | - if ( empty( $from_name ) ) { |
|
144 | - $from_name = get_bloginfo( 'name' ); |
|
143 | + if ( empty( $from_name ) ) { |
|
144 | + $from_name = get_bloginfo( 'name' ); |
|
145 | 145 | } |
146 | 146 | |
147 | - return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
147 | + return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
151 | - * Returns the from email. |
|
152 | - */ |
|
153 | - public function get_from_address() { |
|
151 | + * Returns the from email. |
|
152 | + */ |
|
153 | + public function get_from_address() { |
|
154 | 154 | |
155 | 155 | $from_address = wpinv_get_option( 'email_from', $this->default_from_address() ); |
156 | 156 | |
157 | - if ( ! is_email( $from_address ) ) { |
|
158 | - $from_address = $this->default_from_address(); |
|
157 | + if ( ! is_email( $from_address ) ) { |
|
158 | + $from_address = $this->default_from_address(); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | return $from_address; |
@@ -163,75 +163,75 @@ discard block |
||
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | - * The default emails from address. |
|
167 | - * |
|
168 | - * Defaults to wordpress@$sitename |
|
169 | - * Some hosts will block outgoing mail from this address if it doesn't exist, |
|
170 | - * but there's no easy alternative. Defaulting to admin_email might appear to be |
|
171 | - * another option, but some hosts may refuse to relay mail from an unknown domain. |
|
172 | - * |
|
173 | - */ |
|
174 | - public function default_from_address() { |
|
175 | - |
|
176 | - // Get the site domain and get rid of www. |
|
177 | - $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
178 | - if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
179 | - $sitename = substr( $sitename, 4 ); |
|
180 | - } |
|
181 | - |
|
182 | - $from_email = 'wordpress@' . $sitename; |
|
183 | - |
|
184 | - return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
166 | + * The default emails from address. |
|
167 | + * |
|
168 | + * Defaults to wordpress@$sitename |
|
169 | + * Some hosts will block outgoing mail from this address if it doesn't exist, |
|
170 | + * but there's no easy alternative. Defaulting to admin_email might appear to be |
|
171 | + * another option, but some hosts may refuse to relay mail from an unknown domain. |
|
172 | + * |
|
173 | + */ |
|
174 | + public function default_from_address() { |
|
175 | + |
|
176 | + // Get the site domain and get rid of www. |
|
177 | + $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
178 | + if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
179 | + $sitename = substr( $sitename, 4 ); |
|
180 | + } |
|
181 | + |
|
182 | + $from_email = 'wordpress@' . $sitename; |
|
183 | + |
|
184 | + return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
185 | 185 | |
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
189 | - * Get the email reply-to. |
|
190 | - * |
|
191 | - * |
|
192 | - * @return string The email reply-to address. |
|
193 | - */ |
|
194 | - public function get_reply_to() { |
|
189 | + * Get the email reply-to. |
|
190 | + * |
|
191 | + * |
|
192 | + * @return string The email reply-to address. |
|
193 | + */ |
|
194 | + public function get_reply_to() { |
|
195 | 195 | |
196 | - $reply_to = wpinv_get_admin_email(); |
|
196 | + $reply_to = wpinv_get_admin_email(); |
|
197 | 197 | |
198 | - if ( ! is_email( $reply_to ) ) { |
|
199 | - $reply_to = get_option( 'admin_email' ); |
|
200 | - } |
|
198 | + if ( ! is_email( $reply_to ) ) { |
|
199 | + $reply_to = get_option( 'admin_email' ); |
|
200 | + } |
|
201 | 201 | |
202 | - return $reply_to; |
|
202 | + return $reply_to; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
206 | - * Get the email content type. |
|
207 | - * |
|
208 | - */ |
|
209 | - public function get_content_type() { |
|
210 | - return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
206 | + * Get the email content type. |
|
207 | + * |
|
208 | + */ |
|
209 | + public function get_content_type() { |
|
210 | + return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
214 | - * Ensures that our email messages are not messed up by template plugins. |
|
215 | - * |
|
216 | - * @return array wp_mail_data. |
|
217 | - */ |
|
218 | - public function ensure_email_content( $args ) { |
|
219 | - $args['message'] = $this->wp_mail_data['email']; |
|
220 | - return $args; |
|
214 | + * Ensures that our email messages are not messed up by template plugins. |
|
215 | + * |
|
216 | + * @return array wp_mail_data. |
|
217 | + */ |
|
218 | + public function ensure_email_content( $args ) { |
|
219 | + $args['message'] = $this->wp_mail_data['email']; |
|
220 | + return $args; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
224 | - * A little house keeping after an email is sent. |
|
225 | - * |
|
226 | - */ |
|
227 | - public function after_sending() { |
|
224 | + * A little house keeping after an email is sent. |
|
225 | + * |
|
226 | + */ |
|
227 | + public function after_sending() { |
|
228 | 228 | |
229 | 229 | do_action( 'getpaid_after_send_email', $this->wp_mail_data ); |
230 | - remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
231 | - remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
232 | - remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
233 | - remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000000 ); |
|
230 | + remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
231 | + remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
232 | + remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
233 | + remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000000 ); |
|
234 | 234 | |
235 | - } |
|
235 | + } |
|
236 | 236 | |
237 | 237 | } |
@@ -12,72 +12,72 @@ discard block |
||
12 | 12 | */ |
13 | 13 | abstract class GetPaid_Reports_Abstract_Report { |
14 | 14 | |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - public $stats; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - */ |
|
24 | - public function __construct() { |
|
25 | - $this->prepare_stats(); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Retrieves the current range. |
|
30 | - * |
|
31 | - */ |
|
32 | - public function get_range() { |
|
33 | - $valid_ranges = $this->get_periods(); |
|
34 | - |
|
35 | - if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
36 | - return sanitize_key( $_GET['date_range'] ); |
|
37 | - } |
|
38 | - |
|
39 | - return '7_days'; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Returns an array of date ranges. |
|
44 | - * |
|
45 | - * @return array |
|
46 | - */ |
|
47 | - public function get_periods() { |
|
48 | - |
|
49 | - $periods = array( |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + public $stats; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + */ |
|
24 | + public function __construct() { |
|
25 | + $this->prepare_stats(); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Retrieves the current range. |
|
30 | + * |
|
31 | + */ |
|
32 | + public function get_range() { |
|
33 | + $valid_ranges = $this->get_periods(); |
|
34 | + |
|
35 | + if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
36 | + return sanitize_key( $_GET['date_range'] ); |
|
37 | + } |
|
38 | + |
|
39 | + return '7_days'; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Returns an array of date ranges. |
|
44 | + * |
|
45 | + * @return array |
|
46 | + */ |
|
47 | + public function get_periods() { |
|
48 | + |
|
49 | + $periods = array( |
|
50 | 50 | 'today' => __( 'Today', 'invoicing' ), |
51 | 51 | 'yesterday' => __( 'Yesterday', 'invoicing' ), |
52 | 52 | '7_days' => __( 'Last 7 days', 'invoicing' ), |
53 | - '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
54 | - '60_days' => __( 'Last 60 days', 'invoicing' ), |
|
55 | - '90_days' => __( 'Last 90 days', 'invoicing' ), |
|
56 | - '180_days' => __( 'Last 180 days', 'invoicing' ), |
|
57 | - '360_days' => __( 'Last 360 days', 'invoicing' ), |
|
58 | - ); |
|
59 | - |
|
60 | - return apply_filters( 'getpaid_earning_periods', $periods ); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Retrieves the current range's sql. |
|
65 | - * |
|
66 | - */ |
|
67 | - public function get_range_sql( $range ) { |
|
68 | - |
|
69 | - $date = 'CAST(meta.completed_date AS DATE)'; |
|
53 | + '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
54 | + '60_days' => __( 'Last 60 days', 'invoicing' ), |
|
55 | + '90_days' => __( 'Last 90 days', 'invoicing' ), |
|
56 | + '180_days' => __( 'Last 180 days', 'invoicing' ), |
|
57 | + '360_days' => __( 'Last 360 days', 'invoicing' ), |
|
58 | + ); |
|
59 | + |
|
60 | + return apply_filters( 'getpaid_earning_periods', $periods ); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Retrieves the current range's sql. |
|
65 | + * |
|
66 | + */ |
|
67 | + public function get_range_sql( $range ) { |
|
68 | + |
|
69 | + $date = 'CAST(meta.completed_date AS DATE)'; |
|
70 | 70 | $datetime = 'meta.completed_date'; |
71 | 71 | |
72 | 72 | // Prepare durations. |
73 | 73 | $today = current_time( 'Y-m-d' ); |
74 | - $yesterday = date( 'Y-m-d', strtotime( '-1 day', current_time( 'timestamp' ) ) ); |
|
75 | - $seven_days_ago = date( 'Y-m-d', strtotime( '-7 days', current_time( 'timestamp' ) ) ); |
|
76 | - $thirty_days_ago = date( 'Y-m-d', strtotime( '-30 days', current_time( 'timestamp' ) ) ); |
|
77 | - $ninety_days_ago = date( 'Y-m-d', strtotime( '-90 days', current_time( 'timestamp' ) ) ); |
|
78 | - $sixty_days_ago = date( 'Y-m-d', strtotime( '-60 days', current_time( 'timestamp' ) ) ); |
|
79 | - $one_eighty_days_ago = date( 'Y-m-d', strtotime( '-180 days', current_time( 'timestamp' ) ) ); |
|
80 | - $three_sixty_days_ago = date( 'Y-m-d', strtotime( '-360 days', current_time( 'timestamp' ) ) ); |
|
74 | + $yesterday = date( 'Y-m-d', strtotime( '-1 day', current_time( 'timestamp' ) ) ); |
|
75 | + $seven_days_ago = date( 'Y-m-d', strtotime( '-7 days', current_time( 'timestamp' ) ) ); |
|
76 | + $thirty_days_ago = date( 'Y-m-d', strtotime( '-30 days', current_time( 'timestamp' ) ) ); |
|
77 | + $ninety_days_ago = date( 'Y-m-d', strtotime( '-90 days', current_time( 'timestamp' ) ) ); |
|
78 | + $sixty_days_ago = date( 'Y-m-d', strtotime( '-60 days', current_time( 'timestamp' ) ) ); |
|
79 | + $one_eighty_days_ago = date( 'Y-m-d', strtotime( '-180 days', current_time( 'timestamp' ) ) ); |
|
80 | + $three_sixty_days_ago = date( 'Y-m-d', strtotime( '-360 days', current_time( 'timestamp' ) ) ); |
|
81 | 81 | |
82 | 82 | $ranges = array( |
83 | 83 | |
@@ -94,130 +94,130 @@ discard block |
||
94 | 94 | '7_days' => array( |
95 | 95 | "DATE($datetime)", |
96 | 96 | "$date BETWEEN '$seven_days_ago' AND '$today'" |
97 | - ), |
|
97 | + ), |
|
98 | 98 | |
99 | - '30_days' => array( |
|
99 | + '30_days' => array( |
|
100 | 100 | "DATE($datetime)", |
101 | 101 | "$date BETWEEN '$thirty_days_ago' AND '$today'" |
102 | - ), |
|
102 | + ), |
|
103 | 103 | |
104 | - '60_days' => array( |
|
104 | + '60_days' => array( |
|
105 | 105 | "DATE($datetime)", |
106 | 106 | "$date BETWEEN '$sixty_days_ago' AND '$today'" |
107 | - ), |
|
107 | + ), |
|
108 | 108 | |
109 | - '90_days' => array( |
|
109 | + '90_days' => array( |
|
110 | 110 | "WEEK($datetime)", |
111 | 111 | "$date BETWEEN '$ninety_days_ago' AND '$today'" |
112 | - ), |
|
112 | + ), |
|
113 | 113 | |
114 | - '180_days' => array( |
|
114 | + '180_days' => array( |
|
115 | 115 | "WEEK($datetime)", |
116 | 116 | "$date BETWEEN '$one_eighty_days_ago' AND '$today'" |
117 | - ), |
|
117 | + ), |
|
118 | 118 | |
119 | - '360_days' => array( |
|
119 | + '360_days' => array( |
|
120 | 120 | "WEEK($datetime)", |
121 | 121 | "$date BETWEEN '$three_sixty_days_ago' AND '$today'" |
122 | 122 | ), |
123 | 123 | |
124 | 124 | ); |
125 | 125 | |
126 | - $sql = isset( $ranges[ $range ] ) ? $ranges[ $range ] : $ranges[ '7_days' ]; |
|
127 | - return apply_filters( 'getpaid_earning_graphs_get_range_sql', $sql, $range ); |
|
128 | - |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Retrieves the hours in a day |
|
133 | - * |
|
134 | - */ |
|
135 | - public function get_hours_in_a_day() { |
|
136 | - |
|
137 | - return array( |
|
138 | - '12AM' => __( '12 AM', 'invoicing'), |
|
139 | - '1AM' => __( '1 AM', 'invoicing'), |
|
140 | - '2AM' => __( '2 AM', 'invoicing'), |
|
141 | - '3AM' => __( '3 AM', 'invoicing'), |
|
142 | - '4AM' => __( '4 AM', 'invoicing'), |
|
143 | - '5AM' => __( '5 AM', 'invoicing'), |
|
144 | - '6AM' => __( '6 AM', 'invoicing'), |
|
145 | - '7AM' => __( '7 AM', 'invoicing'), |
|
146 | - '8AM' => __( '8 AM', 'invoicing'), |
|
147 | - '9AM' => __( '9 AM', 'invoicing'), |
|
148 | - '10AM' => __( '10 AM', 'invoicing'), |
|
149 | - '11AM' => __( '11 AM', 'invoicing'), |
|
150 | - '12pm' => __( '12 PM', 'invoicing'), |
|
151 | - '1PM' => __( '1 PM', 'invoicing'), |
|
152 | - '2PM' => __( '2 PM', 'invoicing'), |
|
153 | - '3PM' => __( '3 PM', 'invoicing'), |
|
154 | - '4PM' => __( '4 PM', 'invoicing'), |
|
155 | - '5PM' => __( '5 PM', 'invoicing'), |
|
156 | - '6PM' => __( '6 PM', 'invoicing'), |
|
157 | - '7PM' => __( '7 PM', 'invoicing'), |
|
158 | - '8PM' => __( '8 PM', 'invoicing'), |
|
159 | - '9PM' => __( '9 PM', 'invoicing'), |
|
160 | - '10PM' => __( '10 PM', 'invoicing'), |
|
161 | - '11PM' => __( '11 PM', 'invoicing'), |
|
162 | - ); |
|
163 | - |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Retrieves the days in a period |
|
168 | - * |
|
169 | - */ |
|
170 | - public function get_days_in_period( $days ) { |
|
171 | - |
|
172 | - $return = array(); |
|
173 | - $format = 'Y-m-d'; |
|
174 | - |
|
175 | - if ( $days < 8 ) { |
|
176 | - $format = 'D'; |
|
177 | - } |
|
178 | - |
|
179 | - if ( $days < 32 ) { |
|
180 | - $format = 'M j'; |
|
181 | - } |
|
182 | - |
|
183 | - while ( $days > 0 ) { |
|
184 | - |
|
185 | - $key = date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
186 | - $label = date_i18n( $format, strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
187 | - $return[ $key ] = $label; |
|
188 | - $days--; |
|
189 | - |
|
190 | - } |
|
191 | - |
|
192 | - return $return; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Retrieves the weeks in a period |
|
197 | - * |
|
198 | - */ |
|
199 | - public function get_weeks_in_period( $days ) { |
|
200 | - |
|
201 | - $return = array(); |
|
202 | - |
|
203 | - while ( $days > 0 ) { |
|
204 | - |
|
205 | - $key = date( 'W', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
206 | - $label = date_i18n( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
207 | - $return[ $key ] = $label; |
|
208 | - $days--; |
|
209 | - |
|
210 | - } |
|
211 | - |
|
212 | - return $return; |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Displays the report card. |
|
217 | - * |
|
218 | - */ |
|
219 | - public function display() { |
|
220 | - ?> |
|
126 | + $sql = isset( $ranges[ $range ] ) ? $ranges[ $range ] : $ranges[ '7_days' ]; |
|
127 | + return apply_filters( 'getpaid_earning_graphs_get_range_sql', $sql, $range ); |
|
128 | + |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Retrieves the hours in a day |
|
133 | + * |
|
134 | + */ |
|
135 | + public function get_hours_in_a_day() { |
|
136 | + |
|
137 | + return array( |
|
138 | + '12AM' => __( '12 AM', 'invoicing'), |
|
139 | + '1AM' => __( '1 AM', 'invoicing'), |
|
140 | + '2AM' => __( '2 AM', 'invoicing'), |
|
141 | + '3AM' => __( '3 AM', 'invoicing'), |
|
142 | + '4AM' => __( '4 AM', 'invoicing'), |
|
143 | + '5AM' => __( '5 AM', 'invoicing'), |
|
144 | + '6AM' => __( '6 AM', 'invoicing'), |
|
145 | + '7AM' => __( '7 AM', 'invoicing'), |
|
146 | + '8AM' => __( '8 AM', 'invoicing'), |
|
147 | + '9AM' => __( '9 AM', 'invoicing'), |
|
148 | + '10AM' => __( '10 AM', 'invoicing'), |
|
149 | + '11AM' => __( '11 AM', 'invoicing'), |
|
150 | + '12pm' => __( '12 PM', 'invoicing'), |
|
151 | + '1PM' => __( '1 PM', 'invoicing'), |
|
152 | + '2PM' => __( '2 PM', 'invoicing'), |
|
153 | + '3PM' => __( '3 PM', 'invoicing'), |
|
154 | + '4PM' => __( '4 PM', 'invoicing'), |
|
155 | + '5PM' => __( '5 PM', 'invoicing'), |
|
156 | + '6PM' => __( '6 PM', 'invoicing'), |
|
157 | + '7PM' => __( '7 PM', 'invoicing'), |
|
158 | + '8PM' => __( '8 PM', 'invoicing'), |
|
159 | + '9PM' => __( '9 PM', 'invoicing'), |
|
160 | + '10PM' => __( '10 PM', 'invoicing'), |
|
161 | + '11PM' => __( '11 PM', 'invoicing'), |
|
162 | + ); |
|
163 | + |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Retrieves the days in a period |
|
168 | + * |
|
169 | + */ |
|
170 | + public function get_days_in_period( $days ) { |
|
171 | + |
|
172 | + $return = array(); |
|
173 | + $format = 'Y-m-d'; |
|
174 | + |
|
175 | + if ( $days < 8 ) { |
|
176 | + $format = 'D'; |
|
177 | + } |
|
178 | + |
|
179 | + if ( $days < 32 ) { |
|
180 | + $format = 'M j'; |
|
181 | + } |
|
182 | + |
|
183 | + while ( $days > 0 ) { |
|
184 | + |
|
185 | + $key = date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
186 | + $label = date_i18n( $format, strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
187 | + $return[ $key ] = $label; |
|
188 | + $days--; |
|
189 | + |
|
190 | + } |
|
191 | + |
|
192 | + return $return; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Retrieves the weeks in a period |
|
197 | + * |
|
198 | + */ |
|
199 | + public function get_weeks_in_period( $days ) { |
|
200 | + |
|
201 | + $return = array(); |
|
202 | + |
|
203 | + while ( $days > 0 ) { |
|
204 | + |
|
205 | + $key = date( 'W', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
206 | + $label = date_i18n( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
207 | + $return[ $key ] = $label; |
|
208 | + $days--; |
|
209 | + |
|
210 | + } |
|
211 | + |
|
212 | + return $return; |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Displays the report card. |
|
217 | + * |
|
218 | + */ |
|
219 | + public function display() { |
|
220 | + ?> |
|
221 | 221 | |
222 | 222 | <div class="row"> |
223 | 223 | <div class="col-12"> |
@@ -231,20 +231,20 @@ discard block |
||
231 | 231 | |
232 | 232 | <?php |
233 | 233 | |
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Prepares the report stats. |
|
238 | - * |
|
239 | - * Extend this in child classes. |
|
240 | - */ |
|
241 | - abstract public function prepare_stats(); |
|
242 | - |
|
243 | - /** |
|
244 | - * Displays the actual report. |
|
245 | - * |
|
246 | - * Extend this in child classes. |
|
247 | - */ |
|
248 | - abstract public function display_stats(); |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Prepares the report stats. |
|
238 | + * |
|
239 | + * Extend this in child classes. |
|
240 | + */ |
|
241 | + abstract public function prepare_stats(); |
|
242 | + |
|
243 | + /** |
|
244 | + * Displays the actual report. |
|
245 | + * |
|
246 | + * Extend this in child classes. |
|
247 | + */ |
|
248 | + abstract public function display_stats(); |
|
249 | 249 | |
250 | 250 | } |