@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports_Helper Class. |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @param array $args |
27 | 27 | * @return mixed depending on query_type |
28 | 28 | */ |
29 | - public static function get_invoice_report_data( $args = array() ) { |
|
29 | + public static function get_invoice_report_data($args = array()) { |
|
30 | 30 | global $wpdb; |
31 | 31 | |
32 | 32 | $default_args = array( |
@@ -37,94 +37,94 @@ discard block |
||
37 | 37 | 'order_by' => '', // What to order by. |
38 | 38 | 'limit' => '', // Results limit. |
39 | 39 | 'filter_range' => array(), // An array of before and after dates to limit results by. |
40 | - 'invoice_types' => array( 'wpi_invoice' ), // An array of post types to retrieve. |
|
41 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold' ), |
|
40 | + 'invoice_types' => array('wpi_invoice'), // An array of post types to retrieve. |
|
41 | + 'invoice_status' => array('publish', 'wpi-processing', 'wpi-onhold'), |
|
42 | 42 | 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
43 | 43 | ); |
44 | 44 | |
45 | - $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
46 | - $args = wp_parse_args( $args, $default_args ); |
|
45 | + $args = apply_filters('getpaid_reports_get_invoice_report_data_args', $args); |
|
46 | + $args = wp_parse_args($args, $default_args); |
|
47 | 47 | |
48 | - extract( $args ); |
|
48 | + extract($args); |
|
49 | 49 | |
50 | - if ( empty( $data ) ) { |
|
50 | + if (empty($data)) { |
|
51 | 51 | return ''; |
52 | 52 | } |
53 | 53 | |
54 | 54 | $query = array(); |
55 | - $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
55 | + $query['select'] = 'SELECT ' . implode(',', self::prepare_invoice_data($data)); |
|
56 | 56 | $query['from'] = "FROM {$wpdb->posts} AS posts"; |
57 | - $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
57 | + $query['join'] = implode(' ', self::prepare_invoice_joins($data + $where, !empty($parent_invoice_status))); |
|
58 | 58 | |
59 | 59 | $query['where'] = " |
60 | - WHERE posts.post_type IN ( '" . implode( "','", $invoice_types ) . "' ) |
|
60 | + WHERE posts.post_type IN ( '" . implode("','", $invoice_types) . "' ) |
|
61 | 61 | "; |
62 | 62 | |
63 | - if ( ! empty( $invoice_status ) ) { |
|
63 | + if (!empty($invoice_status)) { |
|
64 | 64 | $query['where'] .= " |
65 | - AND posts.post_status IN ( '" . implode( "','", $invoice_status ) . "' ) |
|
65 | + AND posts.post_status IN ( '" . implode("','", $invoice_status) . "' ) |
|
66 | 66 | "; |
67 | 67 | } |
68 | 68 | |
69 | - if ( ! empty( $parent_invoice_status ) ) { |
|
70 | - if ( ! empty( $invoice_status ) ) { |
|
71 | - $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) "; |
|
69 | + if (!empty($parent_invoice_status)) { |
|
70 | + if (!empty($invoice_status)) { |
|
71 | + $query['where'] .= " AND ( parent.post_status IN ( '" . implode("','", $parent_invoice_status) . "' ) OR parent.ID IS NULL ) "; |
|
72 | 72 | } else { |
73 | - $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
73 | + $query['where'] .= " AND parent.post_status IN ( '" . implode("','", $parent_invoice_status) . "' ) "; |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
77 | - if ( ! empty( $filter_range['before'] ) ) { |
|
77 | + if (!empty($filter_range['before'])) { |
|
78 | 78 | $query['where'] .= " |
79 | - AND posts.post_date <= '" . gmdate( 'Y-m-d 23:59:59', strtotime( $filter_range['before'] ) ) . "' |
|
79 | + AND posts.post_date <= '" . gmdate('Y-m-d 23:59:59', strtotime($filter_range['before'])) . "' |
|
80 | 80 | "; |
81 | 81 | } |
82 | 82 | |
83 | - if ( ! empty( $filter_range['after'] ) ) { |
|
83 | + if (!empty($filter_range['after'])) { |
|
84 | 84 | $query['where'] .= " |
85 | - AND posts.post_date >= '" . gmdate( 'Y-m-d 00:00:00', strtotime( $filter_range['after'] ) ) . "' |
|
85 | + AND posts.post_date >= '" . gmdate('Y-m-d 00:00:00', strtotime($filter_range['after'])) . "' |
|
86 | 86 | "; |
87 | 87 | } |
88 | 88 | |
89 | - if ( ! empty( $where ) ) { |
|
89 | + if (!empty($where)) { |
|
90 | 90 | |
91 | - foreach ( $where as $value ) { |
|
91 | + foreach ($where as $value) { |
|
92 | 92 | |
93 | - if ( strtolower( $value['operator'] ) === 'in' || strtolower( $value['operator'] ) === 'not in' ) { |
|
93 | + if (strtolower($value['operator']) === 'in' || strtolower($value['operator']) === 'not in') { |
|
94 | 94 | |
95 | - if ( is_array( $value['value'] ) ) { |
|
96 | - $value['value'] = implode( "','", $value['value'] ); |
|
95 | + if (is_array($value['value'])) { |
|
96 | + $value['value'] = implode("','", $value['value']); |
|
97 | 97 | } |
98 | 98 | |
99 | - if ( ! empty( $value['value'] ) ) { |
|
99 | + if (!empty($value['value'])) { |
|
100 | 100 | $where_value = "{$value['operator']} ('{$value['value']}')"; |
101 | 101 | } |
102 | 102 | } else { |
103 | 103 | $where_value = "{$value['operator']} '{$value['value']}'"; |
104 | 104 | } |
105 | 105 | |
106 | - if ( ! empty( $where_value ) ) { |
|
106 | + if (!empty($where_value)) { |
|
107 | 107 | $query['where'] .= " AND {$value['key']} {$where_value}"; |
108 | 108 | } |
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | - if ( $group_by ) { |
|
112 | + if ($group_by) { |
|
113 | 113 | $query['group_by'] = "GROUP BY {$group_by}"; |
114 | 114 | } |
115 | 115 | |
116 | - if ( $order_by ) { |
|
116 | + if ($order_by) { |
|
117 | 117 | $query['order_by'] = "ORDER BY {$order_by}"; |
118 | 118 | } |
119 | 119 | |
120 | - if ( $limit ) { |
|
120 | + if ($limit) { |
|
121 | 121 | $query['limit'] = "LIMIT {$limit}"; |
122 | 122 | } |
123 | 123 | |
124 | - $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
125 | - $query = implode( ' ', $query ); |
|
124 | + $query = apply_filters('getpaid_reports_get_invoice_report_query', $query, $data); |
|
125 | + $query = implode(' ', $query); |
|
126 | 126 | |
127 | - return self::execute( $query_type, $query ); |
|
127 | + return self::execute($query_type, $query); |
|
128 | 128 | |
129 | 129 | } |
130 | 130 | |
@@ -135,26 +135,26 @@ discard block |
||
135 | 135 | * @param array $data |
136 | 136 | * @return array |
137 | 137 | */ |
138 | - public static function prepare_invoice_data( $data ) { |
|
138 | + public static function prepare_invoice_data($data) { |
|
139 | 139 | |
140 | 140 | $prepared = array(); |
141 | 141 | |
142 | - foreach ( $data as $raw_key => $value ) { |
|
143 | - $key = sanitize_key( $raw_key ); |
|
142 | + foreach ($data as $raw_key => $value) { |
|
143 | + $key = sanitize_key($raw_key); |
|
144 | 144 | $distinct = ''; |
145 | 145 | |
146 | - if ( isset( $value['distinct'] ) ) { |
|
146 | + if (isset($value['distinct'])) { |
|
147 | 147 | $distinct = 'DISTINCT'; |
148 | 148 | } |
149 | 149 | |
150 | - $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
150 | + $get_key = self::get_invoice_table_key($key, $value['type']); |
|
151 | 151 | |
152 | - if ( false === $get_key ) { |
|
152 | + if (false === $get_key) { |
|
153 | 153 | // Skip to the next foreach iteration else the query will be invalid. |
154 | 154 | continue; |
155 | 155 | } |
156 | 156 | |
157 | - if ( ! empty( $value['function'] ) ) { |
|
157 | + if (!empty($value['function'])) { |
|
158 | 158 | $get = "{$value['function']}({$distinct} {$get_key})"; |
159 | 159 | } else { |
160 | 160 | $get = "{$distinct} {$get_key}"; |
@@ -175,22 +175,22 @@ discard block |
||
175 | 175 | * @param bool $with_parent |
176 | 176 | * @return array |
177 | 177 | */ |
178 | - public static function prepare_invoice_joins( $data, $with_parent ) { |
|
178 | + public static function prepare_invoice_joins($data, $with_parent) { |
|
179 | 179 | global $wpdb; |
180 | 180 | |
181 | 181 | $prepared = array(); |
182 | 182 | |
183 | - foreach ( $data as $raw_key => $value ) { |
|
184 | - $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER'; |
|
185 | - $type = isset( $value['type'] ) ? $value['type'] : false; |
|
186 | - $key = sanitize_key( $raw_key ); |
|
183 | + foreach ($data as $raw_key => $value) { |
|
184 | + $join_type = isset($value['join_type']) ? $value['join_type'] : 'INNER'; |
|
185 | + $type = isset($value['type']) ? $value['type'] : false; |
|
186 | + $key = sanitize_key($raw_key); |
|
187 | 187 | |
188 | - switch ( $type ) { |
|
188 | + switch ($type) { |
|
189 | 189 | case 'meta': |
190 | - $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
190 | + $prepared["meta_{$key}"] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
191 | 191 | break; |
192 | 192 | case 'parent_meta': |
193 | - $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
193 | + $prepared["parent_meta_{$key}"] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
194 | 194 | break; |
195 | 195 | case 'invoice_data': |
196 | 196 | $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | - if ( $with_parent ) { |
|
204 | + if ($with_parent) { |
|
205 | 205 | $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
206 | 206 | } |
207 | 207 | |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @param string $table |
218 | 218 | * @return string|false |
219 | 219 | */ |
220 | - public static function get_invoice_table_key( $key, $table ) { |
|
220 | + public static function get_invoice_table_key($key, $table) { |
|
221 | 221 | |
222 | 222 | $keys = array( |
223 | 223 | 'meta' => "meta_{$key}.meta_value", |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | 'invoice_item' => "invoice_items.{$key}", |
228 | 228 | ); |
229 | 229 | |
230 | - return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
230 | + return isset($keys[$table]) ? $keys[$table] : false; |
|
231 | 231 | |
232 | 232 | } |
233 | 233 | |
@@ -239,16 +239,16 @@ discard block |
||
239 | 239 | * @param string $query |
240 | 240 | * @return mixed depending on query_type |
241 | 241 | */ |
242 | - public static function execute( $query_type, $query ) { |
|
242 | + public static function execute($query_type, $query) { |
|
243 | 243 | global $wpdb; |
244 | 244 | |
245 | - $query_hash = md5( $query_type . $query ); |
|
246 | - $result = self::get_cached_query( $query_hash ); |
|
247 | - if ( $result === false ) { |
|
245 | + $query_hash = md5($query_type . $query); |
|
246 | + $result = self::get_cached_query($query_hash); |
|
247 | + if ($result === false) { |
|
248 | 248 | self::enable_big_selects(); |
249 | 249 | |
250 | - $result = $wpdb->$query_type( $query ); |
|
251 | - self::set_cached_query( $query_hash, $result ); |
|
250 | + $result = $wpdb->$query_type($query); |
|
251 | + self::set_cached_query($query_hash, $result); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | return $result; |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | |
264 | 264 | global $wpdb; |
265 | 265 | |
266 | - if ( ! $big_selects ) { |
|
267 | - $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
266 | + if (!$big_selects) { |
|
267 | + $wpdb->query('SET SESSION SQL_BIG_SELECTS=1'); |
|
268 | 268 | $big_selects = true; |
269 | 269 | } |
270 | 270 | } |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
278 | 278 | */ |
279 | - protected static function get_cached_query( $query_hash ) { |
|
279 | + protected static function get_cached_query($query_hash) { |
|
280 | 280 | |
281 | 281 | return wp_cache_get( |
282 | 282 | $query_hash, |
283 | - strtolower( __CLASS__ ) |
|
283 | + strtolower(__CLASS__) |
|
284 | 284 | ); |
285 | 285 | |
286 | 286 | } |
@@ -291,12 +291,12 @@ discard block |
||
291 | 291 | * @param string $query_hash The query hash. |
292 | 292 | * @param mixed $data The data to cache. |
293 | 293 | */ |
294 | - protected static function set_cached_query( $query_hash, $data ) { |
|
294 | + protected static function set_cached_query($query_hash, $data) { |
|
295 | 295 | |
296 | 296 | wp_cache_set( |
297 | 297 | $query_hash, |
298 | 298 | $data, |
299 | - strtolower( __CLASS__ ), |
|
299 | + strtolower(__CLASS__), |
|
300 | 300 | MINUTE_IN_SECONDS |
301 | 301 | ); |
302 | 302 |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,79 +21,79 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | |
26 | 26 | // Prepare the invoice. |
27 | - $invoice = new WPInv_Invoice( $post ); |
|
28 | - $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id(); |
|
29 | - $customer = new WP_User( $customer ); |
|
30 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ); |
|
31 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
27 | + $invoice = new WPInv_Invoice($post); |
|
28 | + $customer = $invoice->exists() ? $invoice->get_user_id('edit') : get_current_user_id(); |
|
29 | + $customer = new WP_User($customer); |
|
30 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email); |
|
31 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
32 | 32 | |
33 | 33 | // Address fields. |
34 | 34 | $address_fields = array( |
35 | 35 | 'first_name' => array( |
36 | - 'label' => __( 'First Name', 'invoicing' ), |
|
36 | + 'label' => __('First Name', 'invoicing'), |
|
37 | 37 | 'type' => 'text', |
38 | 38 | ), |
39 | 39 | 'last_name' => array( |
40 | - 'label' => __( 'Last Name', 'invoicing' ), |
|
40 | + 'label' => __('Last Name', 'invoicing'), |
|
41 | 41 | 'type' => 'text', |
42 | 42 | ), |
43 | 43 | 'company' => array( |
44 | - 'label' => __( 'Company', 'invoicing' ), |
|
44 | + 'label' => __('Company', 'invoicing'), |
|
45 | 45 | 'type' => 'text', |
46 | 46 | 'class' => 'getpaid-recalculate-prices-on-change', |
47 | 47 | ), |
48 | 48 | 'vat_number' => array( |
49 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
49 | + 'label' => __('VAT Number', 'invoicing'), |
|
50 | 50 | 'type' => 'text', |
51 | 51 | 'class' => 'getpaid-recalculate-prices-on-change', |
52 | 52 | ), |
53 | 53 | 'address' => array( |
54 | - 'label' => __( 'Address', 'invoicing' ), |
|
54 | + 'label' => __('Address', 'invoicing'), |
|
55 | 55 | 'type' => 'text', |
56 | 56 | ), |
57 | 57 | 'city' => array( |
58 | - 'label' => __( 'City', 'invoicing' ), |
|
58 | + 'label' => __('City', 'invoicing'), |
|
59 | 59 | 'type' => 'text', |
60 | 60 | ), |
61 | 61 | 'country' => array( |
62 | - 'label' => __( 'Country', 'invoicing' ), |
|
62 | + 'label' => __('Country', 'invoicing'), |
|
63 | 63 | 'type' => 'select', |
64 | 64 | 'class' => 'getpaid-recalculate-prices-on-change', |
65 | 65 | 'options' => wpinv_get_country_list(), |
66 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
66 | + 'placeholder' => __('Choose a country', 'invoicing'), |
|
67 | 67 | ), |
68 | 68 | 'state' => array( |
69 | - 'label' => __( 'State', 'invoicing' ), |
|
69 | + 'label' => __('State', 'invoicing'), |
|
70 | 70 | 'type' => 'text', |
71 | 71 | 'class' => 'getpaid-recalculate-prices-on-change', |
72 | 72 | ), |
73 | 73 | 'zip' => array( |
74 | - 'label' => __( 'Zip', 'invoicing' ), |
|
74 | + 'label' => __('Zip', 'invoicing'), |
|
75 | 75 | 'type' => 'text', |
76 | 76 | ), |
77 | 77 | 'phone' => array( |
78 | - 'label' => __( 'Phone', 'invoicing' ), |
|
78 | + 'label' => __('Phone', 'invoicing'), |
|
79 | 79 | 'type' => 'text', |
80 | 80 | ), |
81 | 81 | ); |
82 | 82 | |
83 | - $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) ); |
|
83 | + $states = wpinv_get_country_states($invoice->get_country('edit')); |
|
84 | 84 | |
85 | - if ( ! empty( $states ) ) { |
|
85 | + if (!empty($states)) { |
|
86 | 86 | $address_fields['state']['type'] = 'select'; |
87 | 87 | $address_fields['state']['options'] = $states; |
88 | - $address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' ); |
|
88 | + $address_fields['state']['placeholder'] = __('Choose a state', 'invoicing'); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // Maybe remove the VAT field. |
92 | - if ( ! wpinv_use_taxes() ) { |
|
93 | - unset( $address_fields['vat_number'] ); |
|
92 | + if (!wpinv_use_taxes()) { |
|
93 | + unset($address_fields['vat_number']); |
|
94 | 94 | } |
95 | 95 | |
96 | - $address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice ); |
|
96 | + $address_fields = apply_filters('getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice); |
|
97 | 97 | ?> |
98 | 98 | |
99 | 99 | <style> |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | <div class="col-12 col-sm-6"> |
108 | 108 | <div id="getpaid-invoice-user-id-wrapper" class="form-group mb-3"> |
109 | 109 | <div> |
110 | - <label for="post_author_override"><?php esc_html_e( 'Customer', 'invoicing' ); ?></label> |
|
110 | + <label for="post_author_override"><?php esc_html_e('Customer', 'invoicing'); ?></label> |
|
111 | 111 | </div> |
112 | 112 | <div> |
113 | - <select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e( 'Search for a customer by email or name', 'invoicing' ); ?>"> |
|
114 | - <option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo esc_html( $display ); ?> </option>) |
|
113 | + <select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e('Search for a customer by email or name', 'invoicing'); ?>"> |
|
114 | + <option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo esc_html($display); ?> </option>) |
|
115 | 115 | </select> |
116 | 116 | </div> |
117 | 117 | </div> |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | 'type' => 'text', |
125 | 125 | 'id' => 'getpaid-invoice-new-user-email', |
126 | 126 | 'name' => 'wpinv_email', |
127 | - 'label' => __( 'Email', 'invoicing' ) . '<span class="required">*</span>', |
|
127 | + 'label' => __('Email', 'invoicing') . '<span class="required">*</span>', |
|
128 | 128 | 'label_type' => 'vertical', |
129 | 129 | 'placeholder' => '[email protected]', |
130 | 130 | 'class' => 'form-control-sm', |
@@ -135,36 +135,36 @@ discard block |
||
135 | 135 | </div> |
136 | 136 | </div> |
137 | 137 | <div class="col-12 col-sm-6 form-group mb-3 mt-sm-4"> |
138 | - <?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?> |
|
138 | + <?php if (!$invoice->is_paid() && !$invoice->is_refunded()) : ?> |
|
139 | 139 | <a id="getpaid-invoice-fill-user-details" class="button button-small button-secondary" href="javascript:void(0)"> |
140 | 140 | <i aria-hidden="true" class="fa fa-refresh"></i> |
141 | - <?php esc_html_e( 'Fill User Details', 'invoicing' ); ?> |
|
141 | + <?php esc_html_e('Fill User Details', 'invoicing'); ?> |
|
142 | 142 | </a> |
143 | 143 | <a id="getpaid-invoice-create-new-user-button" class="button button-small button-secondary" href="javascript:void(0)"> |
144 | 144 | <i aria-hidden="true" class="fa fa-plus"></i> |
145 | - <?php esc_html_e( 'Add New User', 'invoicing' ); ?> |
|
145 | + <?php esc_html_e('Add New User', 'invoicing'); ?> |
|
146 | 146 | </a> |
147 | 147 | <a id="getpaid-invoice-cancel-create-new-user" class="button button-small button-secondary d-none" href="javascript:void(0)"> |
148 | 148 | <i aria-hidden="true" class="fa fa-close"></i> |
149 | - <?php esc_html_e( 'Cancel', 'invoicing' ); ?> |
|
149 | + <?php esc_html_e('Cancel', 'invoicing'); ?> |
|
150 | 150 | </a> |
151 | 151 | <?php endif; ?> |
152 | 152 | </div> |
153 | 153 | |
154 | - <?php foreach ( $address_fields as $key => $field ) : ?> |
|
155 | - <div class="col-12 col-sm-6 getpaid-invoice-address-field__<?php echo esc_attr( $key ); ?>--wrapper"> |
|
154 | + <?php foreach ($address_fields as $key => $field) : ?> |
|
155 | + <div class="col-12 col-sm-6 getpaid-invoice-address-field__<?php echo esc_attr($key); ?>--wrapper"> |
|
156 | 156 | <?php |
157 | 157 | |
158 | - if ( 'select' === $field['type'] ) { |
|
158 | + if ('select' === $field['type']) { |
|
159 | 159 | aui()->select( |
160 | 160 | array( |
161 | 161 | 'id' => 'wpinv_' . $key, |
162 | 162 | 'name' => 'wpinv_' . $key, |
163 | 163 | 'label' => $field['label'], |
164 | 164 | 'label_type' => 'vertical', |
165 | - 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
166 | - 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
167 | - 'value' => $invoice->get( $key, 'edit' ), |
|
165 | + 'placeholder' => isset($field['placeholder']) ? $field['placeholder'] : '', |
|
166 | + 'class' => 'form-control-sm ' . (isset($field['class']) ? $field['class'] : ''), |
|
167 | + 'value' => $invoice->get($key, 'edit'), |
|
168 | 168 | 'options' => $field['options'], |
169 | 169 | 'data-allow-clear' => 'false', |
170 | 170 | 'select2' => true, |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | 'name' => 'wpinv_' . $key, |
180 | 180 | 'label' => $field['label'], |
181 | 181 | 'label_type' => 'vertical', |
182 | - 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
183 | - 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
184 | - 'value' => $invoice->get( $key, 'edit' ), |
|
182 | + 'placeholder' => isset($field['placeholder']) ? $field['placeholder'] : '', |
|
183 | + 'class' => 'form-control-sm ' . (isset($field['class']) ? $field['class'] : ''), |
|
184 | + 'value' => $invoice->get($key, 'edit'), |
|
185 | 185 | ), |
186 | 186 | true |
187 | 187 | ); |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | <?php endforeach; ?> |
193 | 193 | </div> |
194 | 194 | |
195 | - <?php if ( ! apply_filters( 'getpaid_use_new_invoice_items_metabox', false ) ) : ?> |
|
196 | - <?php do_action( 'wpinv_meta_box_before_invoice_template_row', $invoice->get_id() ); ?> |
|
195 | + <?php if (!apply_filters('getpaid_use_new_invoice_items_metabox', false)) : ?> |
|
196 | + <?php do_action('wpinv_meta_box_before_invoice_template_row', $invoice->get_id()); ?> |
|
197 | 197 | |
198 | 198 | <div class="row"> |
199 | 199 | <div class="col-12 col-sm-6"> |
@@ -202,14 +202,14 @@ discard block |
||
202 | 202 | array( |
203 | 203 | 'id' => 'wpinv_template', |
204 | 204 | 'name' => 'wpinv_template', |
205 | - 'label' => __( 'Template', 'invoicing' ), |
|
205 | + 'label' => __('Template', 'invoicing'), |
|
206 | 206 | 'label_type' => 'vertical', |
207 | - 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
207 | + 'placeholder' => __('Choose a template', 'invoicing'), |
|
208 | 208 | 'class' => 'form-control-sm', |
209 | - 'value' => $invoice->get_template( 'edit' ), |
|
209 | + 'value' => $invoice->get_template('edit'), |
|
210 | 210 | 'options' => array( |
211 | - 'quantity' => __( 'Quantity', 'invoicing' ), |
|
212 | - 'hours' => __( 'Hours', 'invoicing' ), |
|
211 | + 'quantity' => __('Quantity', 'invoicing'), |
|
212 | + 'hours' => __('Hours', 'invoicing'), |
|
213 | 213 | ), |
214 | 214 | 'data-allow-clear' => 'false', |
215 | 215 | 'select2' => true, |
@@ -226,11 +226,11 @@ discard block |
||
226 | 226 | array( |
227 | 227 | 'id' => 'wpinv_currency', |
228 | 228 | 'name' => 'wpinv_currency', |
229 | - 'label' => __( 'Currency', 'invoicing' ), |
|
229 | + 'label' => __('Currency', 'invoicing'), |
|
230 | 230 | 'label_type' => 'vertical', |
231 | - 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
231 | + 'placeholder' => __('Select Invoice Currency', 'invoicing'), |
|
232 | 232 | 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
233 | - 'value' => $invoice->get_currency( 'edit' ), |
|
233 | + 'value' => $invoice->get_currency('edit'), |
|
234 | 234 | 'required' => false, |
235 | 235 | 'data-allow-clear' => 'false', |
236 | 236 | 'select2' => true, |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | </div> |
244 | 244 | </div> |
245 | 245 | |
246 | - <?php do_action( 'wpinv_meta_box_invoice_template_row', $invoice->get_id() ); ?> |
|
246 | + <?php do_action('wpinv_meta_box_invoice_template_row', $invoice->get_id()); ?> |
|
247 | 247 | <?php endif; ?> |
248 | 248 | |
249 | 249 | <div class="row"> |
@@ -254,11 +254,11 @@ discard block |
||
254 | 254 | 'type' => 'text', |
255 | 255 | 'id' => 'wpinv_company_id', |
256 | 256 | 'name' => 'wpinv_company_id', |
257 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
257 | + 'label' => __('Company ID', 'invoicing'), |
|
258 | 258 | 'label_type' => 'vertical', |
259 | 259 | 'placeholder' => '', |
260 | 260 | 'class' => 'form-control-sm', |
261 | - 'value' => $invoice->get_company_id( 'edit' ), |
|
261 | + 'value' => $invoice->get_company_id('edit'), |
|
262 | 262 | ), |
263 | 263 | true |
264 | 264 | ); |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | </div> |
267 | 267 | </div> |
268 | 268 | |
269 | - <?php do_action( 'getpaid_after_metabox_invoice_address', $invoice ); ?> |
|
269 | + <?php do_action('getpaid_after_metabox_invoice_address', $invoice); ?> |
|
270 | 270 | </div> |
271 | 271 | <?php |
272 | 272 | } |
@@ -277,51 +277,51 @@ discard block |
||
277 | 277 | * @param int $post_id |
278 | 278 | * @param array $posted the posted data. |
279 | 279 | */ |
280 | - public static function save( $post_id, $posted ) { |
|
280 | + public static function save($post_id, $posted) { |
|
281 | 281 | |
282 | 282 | // Prepare the invoice. |
283 | - $invoice = new WPInv_Invoice( $post_id ); |
|
283 | + $invoice = new WPInv_Invoice($post_id); |
|
284 | 284 | |
285 | 285 | // Load new data. |
286 | 286 | $invoice->set_props( |
287 | 287 | array( |
288 | - 'template' => isset( $posted['wpinv_template'] ) ? wpinv_clean( $posted['wpinv_template'] ) : null, |
|
289 | - 'email_cc' => isset( $posted['wpinv_cc'] ) ? wpinv_clean( $posted['wpinv_cc'] ) : null, |
|
290 | - 'disable_taxes' => ! empty( $posted['disable_taxes'] ), |
|
291 | - 'currency' => isset( $posted['wpinv_currency'] ) ? wpinv_clean( $posted['wpinv_currency'] ) : null, |
|
292 | - 'gateway' => ( $invoice->needs_payment() && isset( $posted['wpinv_gateway'] ) ) ? wpinv_clean( $posted['wpinv_gateway'] ) : null, |
|
293 | - 'address' => isset( $posted['wpinv_address'] ) ? wpinv_clean( $posted['wpinv_address'] ) : null, |
|
294 | - 'vat_number' => isset( $posted['wpinv_vat_number'] ) ? wpinv_clean( $posted['wpinv_vat_number'] ) : null, |
|
295 | - 'company' => isset( $posted['wpinv_company'] ) ? wpinv_clean( $posted['wpinv_company'] ) : null, |
|
296 | - 'company_id' => isset( $posted['wpinv_company_id'] ) ? wpinv_clean( $posted['wpinv_company_id'] ) : null, |
|
297 | - 'zip' => isset( $posted['wpinv_zip'] ) ? wpinv_clean( $posted['wpinv_zip'] ) : null, |
|
298 | - 'state' => isset( $posted['wpinv_state'] ) ? wpinv_clean( $posted['wpinv_state'] ) : null, |
|
299 | - 'city' => isset( $posted['wpinv_city'] ) ? wpinv_clean( $posted['wpinv_city'] ) : null, |
|
300 | - 'country' => isset( $posted['wpinv_country'] ) ? wpinv_clean( $posted['wpinv_country'] ) : null, |
|
301 | - 'phone' => isset( $posted['wpinv_phone'] ) ? wpinv_clean( $posted['wpinv_phone'] ) : null, |
|
302 | - 'first_name' => isset( $posted['wpinv_first_name'] ) ? wpinv_clean( $posted['wpinv_first_name'] ) : null, |
|
303 | - 'last_name' => isset( $posted['wpinv_last_name'] ) ? wpinv_clean( $posted['wpinv_last_name'] ) : null, |
|
304 | - 'author' => isset( $posted['post_author_override'] ) ? wpinv_clean( $posted['post_author_override'] ) : null, |
|
305 | - 'date_created' => isset( $posted['date_created'] ) ? wpinv_clean( $posted['date_created'] ) : null, |
|
306 | - 'date_completed' => isset( $posted['wpinv_date_completed'] ) ? wpinv_clean( $posted['wpinv_date_completed'] ) : null, |
|
307 | - 'due_date' => isset( $posted['wpinv_due_date'] ) ? wpinv_clean( $posted['wpinv_due_date'] ) : null, |
|
308 | - 'number' => isset( $posted['wpinv_number'] ) ? wpinv_clean( $posted['wpinv_number'] ) : null, |
|
309 | - 'status' => isset( $posted['wpinv_status'] ) ? wpinv_clean( $posted['wpinv_status'] ) : null, |
|
288 | + 'template' => isset($posted['wpinv_template']) ? wpinv_clean($posted['wpinv_template']) : null, |
|
289 | + 'email_cc' => isset($posted['wpinv_cc']) ? wpinv_clean($posted['wpinv_cc']) : null, |
|
290 | + 'disable_taxes' => !empty($posted['disable_taxes']), |
|
291 | + 'currency' => isset($posted['wpinv_currency']) ? wpinv_clean($posted['wpinv_currency']) : null, |
|
292 | + 'gateway' => ($invoice->needs_payment() && isset($posted['wpinv_gateway'])) ? wpinv_clean($posted['wpinv_gateway']) : null, |
|
293 | + 'address' => isset($posted['wpinv_address']) ? wpinv_clean($posted['wpinv_address']) : null, |
|
294 | + 'vat_number' => isset($posted['wpinv_vat_number']) ? wpinv_clean($posted['wpinv_vat_number']) : null, |
|
295 | + 'company' => isset($posted['wpinv_company']) ? wpinv_clean($posted['wpinv_company']) : null, |
|
296 | + 'company_id' => isset($posted['wpinv_company_id']) ? wpinv_clean($posted['wpinv_company_id']) : null, |
|
297 | + 'zip' => isset($posted['wpinv_zip']) ? wpinv_clean($posted['wpinv_zip']) : null, |
|
298 | + 'state' => isset($posted['wpinv_state']) ? wpinv_clean($posted['wpinv_state']) : null, |
|
299 | + 'city' => isset($posted['wpinv_city']) ? wpinv_clean($posted['wpinv_city']) : null, |
|
300 | + 'country' => isset($posted['wpinv_country']) ? wpinv_clean($posted['wpinv_country']) : null, |
|
301 | + 'phone' => isset($posted['wpinv_phone']) ? wpinv_clean($posted['wpinv_phone']) : null, |
|
302 | + 'first_name' => isset($posted['wpinv_first_name']) ? wpinv_clean($posted['wpinv_first_name']) : null, |
|
303 | + 'last_name' => isset($posted['wpinv_last_name']) ? wpinv_clean($posted['wpinv_last_name']) : null, |
|
304 | + 'author' => isset($posted['post_author_override']) ? wpinv_clean($posted['post_author_override']) : null, |
|
305 | + 'date_created' => isset($posted['date_created']) ? wpinv_clean($posted['date_created']) : null, |
|
306 | + 'date_completed' => isset($posted['wpinv_date_completed']) ? wpinv_clean($posted['wpinv_date_completed']) : null, |
|
307 | + 'due_date' => isset($posted['wpinv_due_date']) ? wpinv_clean($posted['wpinv_due_date']) : null, |
|
308 | + 'number' => isset($posted['wpinv_number']) ? wpinv_clean($posted['wpinv_number']) : null, |
|
309 | + 'status' => isset($posted['wpinv_status']) ? wpinv_clean($posted['wpinv_status']) : null, |
|
310 | 310 | ) |
311 | 311 | ); |
312 | 312 | |
313 | 313 | // Discount code. |
314 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
314 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
315 | 315 | |
316 | - if ( isset( $posted['wpinv_discount_code'] ) ) { |
|
317 | - $invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) ); |
|
316 | + if (isset($posted['wpinv_discount_code'])) { |
|
317 | + $invoice->set_discount_code(wpinv_clean($posted['wpinv_discount_code'])); |
|
318 | 318 | } |
319 | 319 | |
320 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
321 | - if ( $discount->exists() ) { |
|
322 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
320 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
321 | + if ($discount->exists()) { |
|
322 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
323 | 323 | } else { |
324 | - $invoice->remove_discount( 'discount_code' ); |
|
324 | + $invoice->remove_discount('discount_code'); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | // Recalculate totals. |
@@ -330,16 +330,16 @@ discard block |
||
330 | 330 | } |
331 | 331 | |
332 | 332 | // If we're creating a new user... |
333 | - if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) { |
|
333 | + if (!empty($posted['wpinv_new_user']) && is_email(stripslashes($posted['wpinv_email']))) { |
|
334 | 334 | |
335 | 335 | // Attempt to create the user. |
336 | - $user = wpinv_create_user( sanitize_email( stripslashes( $posted['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() ); |
|
336 | + $user = wpinv_create_user(sanitize_email(stripslashes($posted['wpinv_email'])), $invoice->get_first_name() . $invoice->get_last_name()); |
|
337 | 337 | |
338 | 338 | // If successful, update the invoice author. |
339 | - if ( is_numeric( $user ) ) { |
|
340 | - $invoice->set_author( $user ); |
|
339 | + if (is_numeric($user)) { |
|
340 | + $invoice->set_author($user); |
|
341 | 341 | } else { |
342 | - wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ ); |
|
342 | + wpinv_error_log($user->get_error_message(), __('Invoice add new user', 'invoicing'), __FILE__, __LINE__); |
|
343 | 343 | } |
344 | 344 | } |
345 | 345 | |
@@ -350,22 +350,22 @@ discard block |
||
350 | 350 | $invoice->save(); |
351 | 351 | |
352 | 352 | // Save the user address. |
353 | - getpaid_save_invoice_user_address( $invoice ); |
|
353 | + getpaid_save_invoice_user_address($invoice); |
|
354 | 354 | |
355 | 355 | // Undo do not send new invoice notifications. |
356 | 356 | $GLOBALS['wpinv_skip_invoice_notification'] = false; |
357 | 357 | |
358 | 358 | // (Maybe) send new user notification. |
359 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
360 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) { |
|
361 | - wp_send_new_user_notifications( $user, 'user' ); |
|
359 | + $should_send_notification = wpinv_get_option('disable_new_user_emails'); |
|
360 | + if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification))) { |
|
361 | + wp_send_new_user_notifications($user, 'user'); |
|
362 | 362 | } |
363 | 363 | |
364 | - if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) { |
|
365 | - getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true ); |
|
364 | + if (!empty($posted['send_to_customer']) && !$invoice->is_draft()) { |
|
365 | + getpaid()->get('invoice_emails')->user_invoice($invoice, true); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | // Fires after an invoice is saved. |
369 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
369 | + do_action('wpinv_invoice_metabox_saved', $invoice); |
|
370 | 370 | } |
371 | 371 | } |
@@ -1,51 +1,51 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( ! defined( 'WPINC' ) ) { |
|
3 | +if (!defined('WPINC')) { |
|
4 | 4 | exit; |
5 | 5 | } |
6 | 6 | |
7 | -add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' ); |
|
8 | -function wpinv_discount_custom_column( $column ) { |
|
7 | +add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column'); |
|
8 | +function wpinv_discount_custom_column($column) { |
|
9 | 9 | global $post; |
10 | 10 | |
11 | - $discount = new WPInv_Discount( $post ); |
|
11 | + $discount = new WPInv_Discount($post); |
|
12 | 12 | |
13 | - switch ( $column ) { |
|
13 | + switch ($column) { |
|
14 | 14 | case 'code': |
15 | - echo esc_html( $discount->get_code() ); |
|
15 | + echo esc_html($discount->get_code()); |
|
16 | 16 | break; |
17 | 17 | case 'amount': |
18 | - echo wp_kses_post( $discount->get_formatted_amount() ); |
|
18 | + echo wp_kses_post($discount->get_formatted_amount()); |
|
19 | 19 | break; |
20 | 20 | case 'usage': |
21 | - echo wp_kses_post( $discount->get_usage() ); |
|
21 | + echo wp_kses_post($discount->get_usage()); |
|
22 | 22 | break; |
23 | 23 | case 'start_date': |
24 | - echo wp_kses_post( getpaid_format_date_value( $discount->get_start_date() ) ); |
|
24 | + echo wp_kses_post(getpaid_format_date_value($discount->get_start_date())); |
|
25 | 25 | break; |
26 | 26 | case 'expiry_date': |
27 | - echo wp_kses_post( getpaid_format_date_value( $discount->get_expiration_date(), __( 'Never', 'invoicing' ) ) ); |
|
27 | + echo wp_kses_post(getpaid_format_date_value($discount->get_expiration_date(), __('Never', 'invoicing'))); |
|
28 | 28 | break; |
29 | 29 | } |
30 | 30 | } |
31 | 31 | |
32 | -add_filter( 'post_row_actions', 'wpinv_post_row_actions', 90, 2 ); |
|
33 | -function wpinv_post_row_actions( $actions, $post ) { |
|
34 | - $post_type = ! empty( $post->post_type ) ? $post->post_type : ''; |
|
32 | +add_filter('post_row_actions', 'wpinv_post_row_actions', 90, 2); |
|
33 | +function wpinv_post_row_actions($actions, $post) { |
|
34 | + $post_type = !empty($post->post_type) ? $post->post_type : ''; |
|
35 | 35 | |
36 | - if ( $post_type == 'wpi_discount' ) { |
|
37 | - $actions = wpinv_discount_row_actions( $post, $actions ); |
|
36 | + if ($post_type == 'wpi_discount') { |
|
37 | + $actions = wpinv_discount_row_actions($post, $actions); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | return $actions; |
41 | 41 | } |
42 | 42 | |
43 | -function wpinv_discount_row_actions( $discount, $row_actions ) { |
|
44 | - $row_actions = array(); |
|
45 | - $edit_link = get_edit_post_link( $discount->ID ); |
|
46 | - $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>'; |
|
43 | +function wpinv_discount_row_actions($discount, $row_actions) { |
|
44 | + $row_actions = array(); |
|
45 | + $edit_link = get_edit_post_link($discount->ID); |
|
46 | + $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>'; |
|
47 | 47 | |
48 | - if ( in_array( strtolower( $discount->post_status ), array( 'publish' ) ) && wpinv_current_user_can( 'deactivate_discount', array( 'discount' => (int) $discount->ID ) ) ) { |
|
48 | + if (in_array(strtolower($discount->post_status), array('publish')) && wpinv_current_user_can('deactivate_discount', array('discount' => (int) $discount->ID))) { |
|
49 | 49 | |
50 | 50 | $url = wp_nonce_url( |
51 | 51 | add_query_arg( |
@@ -57,13 +57,13 @@ discard block |
||
57 | 57 | 'getpaid-nonce', |
58 | 58 | 'getpaid-nonce' |
59 | 59 | ); |
60 | - $anchor = __( 'Deactivate', 'invoicing' ); |
|
61 | - $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
60 | + $anchor = __('Deactivate', 'invoicing'); |
|
61 | + $title = esc_attr__('Are you sure you want to deactivate this discount?', 'invoicing'); |
|
62 | 62 | $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
63 | 63 | |
64 | - } elseif ( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) && wpinv_current_user_can( 'activate_discount', array( 'discount' => (int) $discount->ID ) ) ) { |
|
64 | + } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft')) && wpinv_current_user_can('activate_discount', array('discount' => (int) $discount->ID))) { |
|
65 | 65 | |
66 | - $url = wp_nonce_url( |
|
66 | + $url = wp_nonce_url( |
|
67 | 67 | add_query_arg( |
68 | 68 | array( |
69 | 69 | 'getpaid-admin-action' => 'activate_discount', |
@@ -73,14 +73,14 @@ discard block |
||
73 | 73 | 'getpaid-nonce', |
74 | 74 | 'getpaid-nonce' |
75 | 75 | ); |
76 | - $anchor = __( 'Activate', 'invoicing' ); |
|
77 | - $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
76 | + $anchor = __('Activate', 'invoicing'); |
|
77 | + $title = esc_attr__('Are you sure you want to activate this discount?', 'invoicing'); |
|
78 | 78 | $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
79 | 79 | |
80 | 80 | } |
81 | 81 | |
82 | - if ( wpinv_current_user_can( 'delete_discount', array( 'discount' => (int) $discount->ID ) ) ) { |
|
83 | - $url = esc_url( |
|
82 | + if (wpinv_current_user_can('delete_discount', array('discount' => (int) $discount->ID))) { |
|
83 | + $url = esc_url( |
|
84 | 84 | wp_nonce_url( |
85 | 85 | add_query_arg( |
86 | 86 | array( |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | ) |
94 | 94 | ); |
95 | 95 | |
96 | - $anchor = __( 'Delete', 'invoicing' ); |
|
97 | - $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
96 | + $anchor = __('Delete', 'invoicing'); |
|
97 | + $title = esc_attr__('Are you sure you want to delete this discount?', 'invoicing'); |
|
98 | 98 | $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
99 | 99 | } |
100 | 100 | |
101 | - $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
|
101 | + $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount); |
|
102 | 102 | |
103 | 103 | return $row_actions; |
104 | 104 | } |
@@ -106,68 +106,68 @@ discard block |
||
106 | 106 | function wpinv_restrict_manage_posts() { |
107 | 107 | global $typenow; |
108 | 108 | |
109 | - if ( 'wpi_discount' == $typenow ) { |
|
109 | + if ('wpi_discount' == $typenow) { |
|
110 | 110 | wpinv_discount_filters(); |
111 | 111 | } |
112 | 112 | } |
113 | -add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 ); |
|
113 | +add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10); |
|
114 | 114 | |
115 | 115 | function wpinv_discount_filters() { |
116 | 116 | |
117 | 117 | ?> |
118 | 118 | <select name="discount_type" id="dropdown_wpinv_discount_type"> |
119 | - <option value=""><?php esc_html_e( 'Show all types', 'invoicing' ); ?></option> |
|
119 | + <option value=""><?php esc_html_e('Show all types', 'invoicing'); ?></option> |
|
120 | 120 | <?php |
121 | 121 | $types = wpinv_get_discount_types(); |
122 | 122 | |
123 | - foreach ( $types as $name => $type ) { |
|
124 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
123 | + foreach ($types as $name => $type) { |
|
124 | + echo '<option value="' . esc_attr($name) . '"'; |
|
125 | 125 | |
126 | - if ( isset( $_GET['discount_type'] ) ) { |
|
127 | - selected( $name, sanitize_text_field( $_GET['discount_type'] ) ); |
|
126 | + if (isset($_GET['discount_type'])) { |
|
127 | + selected($name, sanitize_text_field($_GET['discount_type'])); |
|
128 | 128 | } |
129 | 129 | |
130 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
130 | + echo '>' . esc_html__($type, 'invoicing') . '</option>'; |
|
131 | 131 | } |
132 | 132 | ?> |
133 | 133 | </select> |
134 | 134 | <?php |
135 | 135 | } |
136 | 136 | |
137 | -function wpinv_request( $vars ) { |
|
137 | +function wpinv_request($vars) { |
|
138 | 138 | global $typenow, $wp_post_statuses; |
139 | 139 | |
140 | - if ( getpaid_is_invoice_post_type( $typenow ) ) { |
|
141 | - if ( ! isset( $vars['post_status'] ) ) { |
|
142 | - $post_statuses = wpinv_get_invoice_statuses( false, false, $typenow ); |
|
140 | + if (getpaid_is_invoice_post_type($typenow)) { |
|
141 | + if (!isset($vars['post_status'])) { |
|
142 | + $post_statuses = wpinv_get_invoice_statuses(false, false, $typenow); |
|
143 | 143 | |
144 | - foreach ( $post_statuses as $status => $value ) { |
|
145 | - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { |
|
146 | - unset( $post_statuses[ $status ] ); |
|
144 | + foreach ($post_statuses as $status => $value) { |
|
145 | + if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) { |
|
146 | + unset($post_statuses[$status]); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
150 | - $vars['post_status'] = array_keys( $post_statuses ); |
|
150 | + $vars['post_status'] = array_keys($post_statuses); |
|
151 | 151 | } |
152 | -} elseif ( 'wpi_discount' == $typenow ) { |
|
153 | - $meta_query = ! empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
152 | +} elseif ('wpi_discount' == $typenow) { |
|
153 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
154 | 154 | // Filter vat rule type |
155 | - if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
|
155 | + if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') { |
|
156 | 156 | $meta_query[] = array( |
157 | 157 | 'key' => '_wpi_discount_type', |
158 | - 'value' => sanitize_key( urldecode( $_GET['discount_type'] ) ), |
|
158 | + 'value' => sanitize_key(urldecode($_GET['discount_type'])), |
|
159 | 159 | 'compare' => '=', |
160 | 160 | ); |
161 | 161 | } |
162 | 162 | |
163 | - if ( ! empty( $meta_query ) ) { |
|
163 | + if (!empty($meta_query)) { |
|
164 | 164 | $vars['meta_query'] = $meta_query; |
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | 168 | return $vars; |
169 | 169 | } |
170 | -add_filter( 'request', 'wpinv_request' ); |
|
170 | +add_filter('request', 'wpinv_request'); |
|
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Create a page and store the ID in an option. |
@@ -179,61 +179,61 @@ discard block |
||
179 | 179 | * @param int $post_parent (default: 0) Parent for the new page |
180 | 180 | * @return int page ID |
181 | 181 | */ |
182 | -function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) { |
|
182 | +function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) { |
|
183 | 183 | global $wpdb; |
184 | 184 | |
185 | - $option_value = wpinv_get_option( $option ); |
|
185 | + $option_value = wpinv_get_option($option); |
|
186 | 186 | |
187 | - if ( ! empty( $option_value ) && ( $page_object = get_post( $option_value ) ) ) { |
|
188 | - if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) { |
|
187 | + if (!empty($option_value) && ($page_object = get_post($option_value))) { |
|
188 | + if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) { |
|
189 | 189 | // Valid page is already in place |
190 | 190 | return $page_object->ID; |
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
194 | - if ( ! empty( $post_parent ) ) { |
|
195 | - $page = get_page_by_path( $post_parent ); |
|
196 | - if ( $page ) { |
|
194 | + if (!empty($post_parent)) { |
|
195 | + $page = get_page_by_path($post_parent); |
|
196 | + if ($page) { |
|
197 | 197 | $post_parent = $page->ID; |
198 | 198 | } else { |
199 | 199 | $post_parent = ''; |
200 | 200 | } |
201 | 201 | } |
202 | 202 | |
203 | - if ( strlen( $page_content ) > 0 ) { |
|
203 | + if (strlen($page_content) > 0) { |
|
204 | 204 | // Search for an existing page with the specified page content (typically a shortcode) |
205 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
205 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
206 | 206 | } else { |
207 | 207 | // Search for an existing page with the specified page slug |
208 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) ); |
|
208 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug)); |
|
209 | 209 | } |
210 | 210 | |
211 | - $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content ); |
|
211 | + $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content); |
|
212 | 212 | |
213 | - if ( $valid_page_found ) { |
|
214 | - if ( $option ) { |
|
215 | - wpinv_update_option( $option, $valid_page_found ); |
|
213 | + if ($valid_page_found) { |
|
214 | + if ($option) { |
|
215 | + wpinv_update_option($option, $valid_page_found); |
|
216 | 216 | } |
217 | 217 | return $valid_page_found; |
218 | 218 | } |
219 | 219 | |
220 | 220 | // Search for a matching valid trashed page |
221 | - if ( strlen( $page_content ) > 0 ) { |
|
221 | + if (strlen($page_content) > 0) { |
|
222 | 222 | // Search for an existing page with the specified page content (typically a shortcode) |
223 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
223 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
224 | 224 | } else { |
225 | 225 | // Search for an existing page with the specified page slug |
226 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) ); |
|
226 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug)); |
|
227 | 227 | } |
228 | 228 | |
229 | - if ( $trashed_page_found ) { |
|
229 | + if ($trashed_page_found) { |
|
230 | 230 | $page_id = $trashed_page_found; |
231 | 231 | $page_data = array( |
232 | 232 | 'ID' => $page_id, |
233 | 233 | 'post_status' => 'publish', |
234 | 234 | 'post_parent' => $post_parent, |
235 | 235 | ); |
236 | - wp_update_post( $page_data ); |
|
236 | + wp_update_post($page_data); |
|
237 | 237 | } else { |
238 | 238 | $page_data = array( |
239 | 239 | 'post_status' => 'publish', |
@@ -245,11 +245,11 @@ discard block |
||
245 | 245 | 'post_parent' => $post_parent, |
246 | 246 | 'comment_status' => 'closed', |
247 | 247 | ); |
248 | - $page_id = wp_insert_post( $page_data ); |
|
248 | + $page_id = wp_insert_post($page_data); |
|
249 | 249 | } |
250 | 250 | |
251 | - if ( $option ) { |
|
252 | - wpinv_update_option( $option, (int) $page_id ); |
|
251 | + if ($option) { |
|
252 | + wpinv_update_option($option, (int) $page_id); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | return $page_id; |
@@ -262,11 +262,11 @@ discard block |
||
262 | 262 | * |
263 | 263 | * @return array |
264 | 264 | */ |
265 | -function wpinv_add_aui_screens( $screen_ids ) { |
|
265 | +function wpinv_add_aui_screens($screen_ids) { |
|
266 | 266 | |
267 | 267 | // load on these pages if set |
268 | - $screen_ids = array_merge( $screen_ids, wpinv_get_screen_ids() ); |
|
268 | + $screen_ids = array_merge($screen_ids, wpinv_get_screen_ids()); |
|
269 | 269 | |
270 | 270 | return $screen_ids; |
271 | 271 | } |
272 | -add_filter( 'aui_screen_ids', 'wpinv_add_aui_screens' ); |
|
272 | +add_filter('aui_screen_ids', 'wpinv_add_aui_screens'); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * GetPaid_Customer_Data_Store class file. |
5 | 5 | * |
6 | 6 | */ |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if (!defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -26,27 +26,27 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @param GetPaid_Customer $customer customer object. |
28 | 28 | */ |
29 | - public function create( &$customer ) { |
|
29 | + public function create(&$customer) { |
|
30 | 30 | global $wpdb; |
31 | 31 | |
32 | 32 | $values = array(); |
33 | 33 | $formats = array(); |
34 | 34 | |
35 | 35 | $fields = self::get_database_fields(); |
36 | - unset( $fields['id'] ); |
|
36 | + unset($fields['id']); |
|
37 | 37 | |
38 | - foreach ( $fields as $key => $format ) { |
|
39 | - $values[ $key ] = $customer->get( $key, 'edit' ); |
|
38 | + foreach ($fields as $key => $format) { |
|
39 | + $values[$key] = $customer->get($key, 'edit'); |
|
40 | 40 | $formats[] = $format; |
41 | 41 | } |
42 | 42 | |
43 | - $result = $wpdb->insert( $wpdb->prefix . 'getpaid_customers', $values, $formats ); |
|
43 | + $result = $wpdb->insert($wpdb->prefix . 'getpaid_customers', $values, $formats); |
|
44 | 44 | |
45 | - if ( $result ) { |
|
46 | - $customer->set_id( $wpdb->insert_id ); |
|
45 | + if ($result) { |
|
46 | + $customer->set_id($wpdb->insert_id); |
|
47 | 47 | $customer->apply_changes(); |
48 | 48 | $customer->clear_cache(); |
49 | - do_action( 'getpaid_new_customer', $customer ); |
|
49 | + do_action('getpaid_new_customer', $customer); |
|
50 | 50 | return true; |
51 | 51 | } |
52 | 52 | |
@@ -59,22 +59,22 @@ discard block |
||
59 | 59 | * @param GetPaid_Customer $customer customer object. |
60 | 60 | * |
61 | 61 | */ |
62 | - public function read( &$customer ) { |
|
62 | + public function read(&$customer) { |
|
63 | 63 | global $wpdb; |
64 | 64 | |
65 | 65 | $customer->set_defaults(); |
66 | 66 | |
67 | - if ( ! $customer->get_id() ) { |
|
67 | + if (!$customer->get_id()) { |
|
68 | 68 | $customer->last_error = 'Invalid customer.'; |
69 | - $customer->set_id( 0 ); |
|
69 | + $customer->set_id(0); |
|
70 | 70 | return false; |
71 | 71 | } |
72 | 72 | |
73 | 73 | // Maybe retrieve from the cache. |
74 | - $raw_customer = wp_cache_get( $customer->get_id(), 'getpaid_customers' ); |
|
74 | + $raw_customer = wp_cache_get($customer->get_id(), 'getpaid_customers'); |
|
75 | 75 | |
76 | 76 | // If not found, retrieve from the db. |
77 | - if ( false === $raw_customer ) { |
|
77 | + if (false === $raw_customer) { |
|
78 | 78 | |
79 | 79 | $raw_customer = $wpdb->get_row( |
80 | 80 | $wpdb->prepare( |
@@ -84,22 +84,22 @@ discard block |
||
84 | 84 | ); |
85 | 85 | |
86 | 86 | // Update the cache with our data |
87 | - wp_cache_set( $customer->get_id(), $raw_customer, 'getpaid_customers' ); |
|
87 | + wp_cache_set($customer->get_id(), $raw_customer, 'getpaid_customers'); |
|
88 | 88 | |
89 | 89 | } |
90 | 90 | |
91 | - if ( ! $raw_customer ) { |
|
91 | + if (!$raw_customer) { |
|
92 | 92 | $raw_customer->last_error = 'Invalid customer.'; |
93 | 93 | return false; |
94 | 94 | } |
95 | 95 | |
96 | 96 | // Loop through raw customer fields. |
97 | - foreach ( (array) $raw_customer as $key => $value ) { |
|
98 | - $customer->set( $key, $value ); |
|
97 | + foreach ((array) $raw_customer as $key => $value) { |
|
98 | + $customer->set($key, $value); |
|
99 | 99 | } |
100 | 100 | |
101 | - $customer->set_object_read( true ); |
|
102 | - do_action( 'getpaid_read_customer', $customer ); |
|
101 | + $customer->set_object_read(true); |
|
102 | + do_action('getpaid_read_customer', $customer); |
|
103 | 103 | |
104 | 104 | } |
105 | 105 | |
@@ -108,23 +108,23 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @param GetPaid_Customer $customer Customer object. |
110 | 110 | */ |
111 | - public function update( &$customer ) { |
|
111 | + public function update(&$customer) { |
|
112 | 112 | global $wpdb; |
113 | 113 | |
114 | - do_action( 'getpaid_before_update_customer', $customer, $customer->get_changes() ); |
|
114 | + do_action('getpaid_before_update_customer', $customer, $customer->get_changes()); |
|
115 | 115 | |
116 | 116 | $changes = $customer->get_changes(); |
117 | 117 | $values = array(); |
118 | 118 | $format = array(); |
119 | 119 | |
120 | - foreach ( self::get_database_fields() as $key => $format ) { |
|
121 | - if ( array_key_exists( $key, $changes ) ) { |
|
122 | - $values[ $key ] = $customer->get( $key, 'edit' ); |
|
120 | + foreach (self::get_database_fields() as $key => $format) { |
|
121 | + if (array_key_exists($key, $changes)) { |
|
122 | + $values[$key] = $customer->get($key, 'edit'); |
|
123 | 123 | $formats[] = $format; |
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
127 | - if ( empty( $values ) ) { |
|
127 | + if (empty($values)) { |
|
128 | 128 | return; |
129 | 129 | } |
130 | 130 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $customer->clear_cache(); |
146 | 146 | |
147 | 147 | // Fire a hook. |
148 | - do_action( 'getpaid_update_customer', $customer ); |
|
148 | + do_action('getpaid_update_customer', $customer); |
|
149 | 149 | |
150 | 150 | } |
151 | 151 | |
@@ -154,10 +154,10 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @param GetPaid_Customer $customer |
156 | 156 | */ |
157 | - public function delete( &$customer ) { |
|
157 | + public function delete(&$customer) { |
|
158 | 158 | global $wpdb; |
159 | 159 | |
160 | - do_action( 'getpaid_before_delete_customer', $customer ); |
|
160 | + do_action('getpaid_before_delete_customer', $customer); |
|
161 | 161 | |
162 | 162 | $wpdb->delete( |
163 | 163 | $wpdb->prefix . 'getpaid_customers', |
@@ -171,9 +171,9 @@ discard block |
||
171 | 171 | $customer->clear_cache(); |
172 | 172 | |
173 | 173 | // Fire a hook. |
174 | - do_action( 'getpaid_delete_customer', $customer ); |
|
174 | + do_action('getpaid_delete_customer', $customer); |
|
175 | 175 | |
176 | - $customer->set_id( 0 ); |
|
176 | + $customer->set_id(0); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /* |
@@ -197,11 +197,11 @@ discard block |
||
197 | 197 | ); |
198 | 198 | |
199 | 199 | // Add address fields. |
200 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
200 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
201 | 201 | |
202 | 202 | // Skip id, user_id and email. |
203 | - if ( ! in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
204 | - $fields[ $field ] = '%s'; |
|
203 | + if (!in_array($field, array('id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid'), true)) { |
|
204 | + $fields[$field] = '%s'; |
|
205 | 205 | } |
206 | 206 | } |
207 | 207 |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @since 1.0.15 |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Customer class. |
@@ -34,29 +34,29 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @param int|string|GetPaid_Customer|object $customer customer id, object, or email. |
36 | 36 | */ |
37 | - public function __construct( $customer = 0 ) { |
|
37 | + public function __construct($customer = 0) { |
|
38 | 38 | |
39 | 39 | // Setup default customer data. |
40 | 40 | $this->setup_default_data(); |
41 | 41 | |
42 | - if ( is_numeric( $customer ) ) { |
|
43 | - $this->set_id( $customer ); |
|
44 | - } elseif ( $customer instanceof self ) { |
|
45 | - $this->set_id( $customer->get_id() ); |
|
46 | - } elseif ( is_string( $customer ) && $customer_id = self::get_customer_id_by( $customer, 'email' ) ) { |
|
47 | - $this->set_id( $customer_id ); |
|
48 | - } elseif ( ! empty( $customer->id ) ) { |
|
49 | - $this->set_id( $customer->id ); |
|
42 | + if (is_numeric($customer)) { |
|
43 | + $this->set_id($customer); |
|
44 | + } elseif ($customer instanceof self) { |
|
45 | + $this->set_id($customer->get_id()); |
|
46 | + } elseif (is_string($customer) && $customer_id = self::get_customer_id_by($customer, 'email')) { |
|
47 | + $this->set_id($customer_id); |
|
48 | + } elseif (!empty($customer->id)) { |
|
49 | + $this->set_id($customer->id); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | // Load the datastore. |
53 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
53 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
54 | 54 | |
55 | - if ( $this->get_id() > 0 ) { |
|
56 | - $this->data_store->read( $this ); |
|
55 | + if ($this->get_id() > 0) { |
|
56 | + $this->data_store->read($this); |
|
57 | 57 | } |
58 | 58 | |
59 | - $this->set_object_read( true ); |
|
59 | + $this->set_object_read(true); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -71,31 +71,31 @@ discard block |
||
71 | 71 | 'status' => 'active', |
72 | 72 | 'purchase_value' => 0, |
73 | 73 | 'purchase_count' => 0, |
74 | - 'date_created' => current_time( 'mysql' ), |
|
75 | - 'date_modified' => current_time( 'mysql' ), |
|
74 | + 'date_created' => current_time('mysql'), |
|
75 | + 'date_modified' => current_time('mysql'), |
|
76 | 76 | 'uuid' => wp_generate_uuid4(), |
77 | 77 | ); |
78 | 78 | |
79 | 79 | // Add address fields. |
80 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
80 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
81 | 81 | |
82 | - if ( isset( $this->data[ $field ] ) ) { |
|
82 | + if (isset($this->data[$field])) { |
|
83 | 83 | continue; |
84 | 84 | } |
85 | 85 | |
86 | 86 | // Country. |
87 | - if ( 'country' === $field ) { |
|
88 | - $this->data[ $field ] = wpinv_get_default_country(); |
|
87 | + if ('country' === $field) { |
|
88 | + $this->data[$field] = wpinv_get_default_country(); |
|
89 | 89 | continue; |
90 | 90 | } |
91 | 91 | |
92 | 92 | // State. |
93 | - if ( 'state' === $field ) { |
|
94 | - $this->data[ $field ] = wpinv_get_default_state(); |
|
93 | + if ('state' === $field) { |
|
94 | + $this->data[$field] = wpinv_get_default_state(); |
|
95 | 95 | continue; |
96 | 96 | } |
97 | 97 | |
98 | - $this->data[ $field ] = ''; |
|
98 | + $this->data[$field] = ''; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | $this->default_data = $this->data; |
@@ -109,41 +109,41 @@ discard block |
||
109 | 109 | * @since 1.0.15 |
110 | 110 | * @return int |
111 | 111 | */ |
112 | - public static function get_customer_id_by( $value, $by = 'email' ) { |
|
112 | + public static function get_customer_id_by($value, $by = 'email') { |
|
113 | 113 | global $wpdb; |
114 | 114 | |
115 | 115 | // Prepare value. |
116 | - if ( 'email' === $by ) { |
|
117 | - $value = sanitize_email( $value ); |
|
118 | - } elseif ( 'user_id' === $by ) { |
|
119 | - $value = absint( $value ); |
|
116 | + if ('email' === $by) { |
|
117 | + $value = sanitize_email($value); |
|
118 | + } elseif ('user_id' === $by) { |
|
119 | + $value = absint($value); |
|
120 | 120 | } else { |
121 | 121 | return 0; |
122 | 122 | } |
123 | 123 | |
124 | - if ( empty( $value ) ) { |
|
124 | + if (empty($value)) { |
|
125 | 125 | return 0; |
126 | 126 | } |
127 | 127 | |
128 | 128 | // Maybe retrieve from the cache. |
129 | - $cache_key = 'getpaid_customer_ids_by_' . $by; |
|
130 | - $customer_id = wp_cache_get( $value, $cache_key ); |
|
131 | - if ( false !== $customer_id ) { |
|
129 | + $cache_key = 'getpaid_customer_ids_by_' . $by; |
|
130 | + $customer_id = wp_cache_get($value, $cache_key); |
|
131 | + if (false !== $customer_id) { |
|
132 | 132 | return $customer_id; |
133 | 133 | } |
134 | 134 | |
135 | - if ( 'email' === $by ) { |
|
135 | + if ('email' === $by) { |
|
136 | 136 | $customer_id = (int) $wpdb->get_var( |
137 | - $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}getpaid_customers WHERE email=%s LIMIT 1", $value ) |
|
137 | + $wpdb->prepare("SELECT id FROM {$wpdb->prefix}getpaid_customers WHERE email=%s LIMIT 1", $value) |
|
138 | 138 | ); |
139 | - } elseif ( 'user_id' === $by ) { |
|
139 | + } elseif ('user_id' === $by) { |
|
140 | 140 | $customer_id = (int) $wpdb->get_var( |
141 | - $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}getpaid_customers WHERE user_id=%d LIMIT 1", $value ) |
|
141 | + $wpdb->prepare("SELECT id FROM {$wpdb->prefix}getpaid_customers WHERE user_id=%d LIMIT 1", $value) |
|
142 | 142 | ); |
143 | 143 | } |
144 | 144 | |
145 | 145 | // Update the cache with our data |
146 | - wp_cache_set( $value, $customer_id, $cache_key ); |
|
146 | + wp_cache_set($value, $customer_id, $cache_key); |
|
147 | 147 | |
148 | 148 | return $customer_id; |
149 | 149 | |
@@ -153,9 +153,9 @@ discard block |
||
153 | 153 | * Clears the customer's cache. |
154 | 154 | */ |
155 | 155 | public function clear_cache() { |
156 | - wp_cache_delete( $this->get( 'email' ), 'getpaid_customer_ids_by_email' ); |
|
157 | - wp_cache_delete( $this->get( 'user_id' ), 'getpaid_customer_ids_by_user_id' ); |
|
158 | - wp_cache_delete( $this->get_id(), 'getpaid_customers' ); |
|
156 | + wp_cache_delete($this->get('email'), 'getpaid_customer_ids_by_email'); |
|
157 | + wp_cache_delete($this->get('user_id'), 'getpaid_customer_ids_by_user_id'); |
|
158 | + wp_cache_delete($this->get_id(), 'getpaid_customers'); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /* |
@@ -179,17 +179,17 @@ discard block |
||
179 | 179 | * @param string $key The key to fetch. |
180 | 180 | * @param string $context View or edit context. |
181 | 181 | */ |
182 | - public function get( $key, $context = 'view' ) { |
|
182 | + public function get($key, $context = 'view') { |
|
183 | 183 | |
184 | 184 | // Maybe strip _wpinv_ prefix from key. |
185 | - $key = str_replace( '_wpinv_', '', $key ); |
|
185 | + $key = str_replace('_wpinv_', '', $key); |
|
186 | 186 | |
187 | 187 | // Check if we have a helper method for that. |
188 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
189 | - return call_user_func( array( $this, 'get_' . $key ), $context ); |
|
188 | + if (method_exists($this, 'get_' . $key)) { |
|
189 | + return call_user_func(array($this, 'get_' . $key), $context); |
|
190 | 190 | } |
191 | 191 | |
192 | - return $this->get_prop( $key, $context ); |
|
192 | + return $this->get_prop($key, $context); |
|
193 | 193 | |
194 | 194 | } |
195 | 195 | |
@@ -209,14 +209,14 @@ discard block |
||
209 | 209 | * @param string $key The key to fetch. |
210 | 210 | * @param mixed $value The new value. |
211 | 211 | */ |
212 | - public function set( $key, $value ) { |
|
212 | + public function set($key, $value) { |
|
213 | 213 | |
214 | 214 | // Check if we have a helper method for that. |
215 | - if ( method_exists( $this, 'set_' . $key ) ) { |
|
216 | - return call_user_func( array( $this, 'set_' . $key ), $value ); |
|
215 | + if (method_exists($this, 'set_' . $key)) { |
|
216 | + return call_user_func(array($this, 'set_' . $key), $value); |
|
217 | 217 | } |
218 | 218 | |
219 | - return $this->set_prop( $key, $value ); |
|
219 | + return $this->set_prop($key, $value); |
|
220 | 220 | |
221 | 221 | } |
222 | 222 | |
@@ -226,13 +226,13 @@ discard block |
||
226 | 226 | * @since 1.0.0 |
227 | 227 | * @param string $status New status. |
228 | 228 | */ |
229 | - public function set_status( $status ) { |
|
229 | + public function set_status($status) { |
|
230 | 230 | |
231 | - if ( in_array( $status, array( 'active', 'inactive', 'blocked' ), true ) ) { |
|
232 | - return $this->set_prop( 'status', $status ); |
|
231 | + if (in_array($status, array('active', 'inactive', 'blocked'), true)) { |
|
232 | + return $this->set_prop('status', $status); |
|
233 | 233 | } |
234 | 234 | |
235 | - $this->set_prop( 'status', 'inactive' ); |
|
235 | + $this->set_prop('status', 'inactive'); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -241,8 +241,8 @@ discard block |
||
241 | 241 | * @since 1.0.0 |
242 | 242 | * @param float $purchase_value. |
243 | 243 | */ |
244 | - public function set_purchase_value( $purchase_value ) { |
|
245 | - $this->set_prop( 'purchase_value', (float) $purchase_value ); |
|
244 | + public function set_purchase_value($purchase_value) { |
|
245 | + $this->set_prop('purchase_value', (float) $purchase_value); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | * @since 1.0.0 |
252 | 252 | * @param int $purchase_count. |
253 | 253 | */ |
254 | - public function set_purchase_count( $purchase_count ) { |
|
255 | - $this->set_prop( 'purchase_count', absint( $purchase_count ) ); |
|
254 | + public function set_purchase_count($purchase_count) { |
|
255 | + $this->set_prop('purchase_count', absint($purchase_count)); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -261,8 +261,8 @@ discard block |
||
261 | 261 | * @since 1.0.0 |
262 | 262 | * @param int $user_id. |
263 | 263 | */ |
264 | - public function set_user_id( $user_id ) { |
|
265 | - $this->set_prop( 'user_id', absint( $user_id ) ); |
|
264 | + public function set_user_id($user_id) { |
|
265 | + $this->set_prop('user_id', absint($user_id)); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -271,9 +271,9 @@ discard block |
||
271 | 271 | * @since 1.0.0 |
272 | 272 | * @param string $email. |
273 | 273 | */ |
274 | - public function set_email( $email ) { |
|
275 | - $email = is_string( $email ) ? sanitize_email( $email ) : ''; |
|
276 | - $this->set_prop( 'email', $email ); |
|
274 | + public function set_email($email) { |
|
275 | + $email = is_string($email) ? sanitize_email($email) : ''; |
|
276 | + $this->set_prop('email', $email); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | /** |
@@ -282,9 +282,9 @@ discard block |
||
282 | 282 | * @since 1.0.0 |
283 | 283 | * @param string $email_cc. |
284 | 284 | */ |
285 | - public function set_email_cc( $email_cc ) { |
|
286 | - $email_cc = implode( ', ', wp_parse_list( $email_cc ) ); |
|
287 | - $this->set_prop( 'email_cc', $email_cc ); |
|
285 | + public function set_email_cc($email_cc) { |
|
286 | + $email_cc = implode(', ', wp_parse_list($email_cc)); |
|
287 | + $this->set_prop('email_cc', $email_cc); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -293,16 +293,16 @@ discard block |
||
293 | 293 | * @since 1.0.0 |
294 | 294 | * @param string $date_created date created. |
295 | 295 | */ |
296 | - public function set_date_created( $date_created ) { |
|
296 | + public function set_date_created($date_created) { |
|
297 | 297 | |
298 | - $date = strtotime( $date_created ); |
|
298 | + $date = strtotime($date_created); |
|
299 | 299 | |
300 | - if ( $date && $date_created !== '0000-00-00 00:00:00' && $date_created !== '0000-00-00 00:00' ) { |
|
301 | - $this->set_prop( 'date_created', gmdate( 'Y-m-d H:i:s', $date ) ); |
|
300 | + if ($date && $date_created !== '0000-00-00 00:00:00' && $date_created !== '0000-00-00 00:00') { |
|
301 | + $this->set_prop('date_created', gmdate('Y-m-d H:i:s', $date)); |
|
302 | 302 | return; |
303 | 303 | } |
304 | 304 | |
305 | - $this->set_prop( 'date_created', null ); |
|
305 | + $this->set_prop('date_created', null); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -311,16 +311,16 @@ discard block |
||
311 | 311 | * @since 1.0.0 |
312 | 312 | * @param string $date_modified date created. |
313 | 313 | */ |
314 | - public function set_date_modified( $date_modified ) { |
|
314 | + public function set_date_modified($date_modified) { |
|
315 | 315 | |
316 | - $date = strtotime( $date_modified ); |
|
316 | + $date = strtotime($date_modified); |
|
317 | 317 | |
318 | - if ( $date && $date_modified !== '0000-00-00 00:00:00' && $date_modified !== '0000-00-00 00:00' ) { |
|
319 | - $this->set_prop( 'date_modified', gmdate( 'Y-m-d H:i:s', $date ) ); |
|
318 | + if ($date && $date_modified !== '0000-00-00 00:00:00' && $date_modified !== '0000-00-00 00:00') { |
|
319 | + $this->set_prop('date_modified', gmdate('Y-m-d H:i:s', $date)); |
|
320 | 320 | return; |
321 | 321 | } |
322 | 322 | |
323 | - $this->set_prop( 'date_modified', null ); |
|
323 | + $this->set_prop('date_modified', null); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /* |
@@ -341,18 +341,18 @@ discard block |
||
341 | 341 | |
342 | 342 | $maybe_set = array( |
343 | 343 | 'uuid' => wp_generate_uuid4(), |
344 | - 'date_created' => current_time( 'mysql' ), |
|
344 | + 'date_created' => current_time('mysql'), |
|
345 | 345 | ); |
346 | 346 | |
347 | - foreach ( $maybe_set as $key => $value ) { |
|
348 | - $current_value = $this->get( $key ); |
|
347 | + foreach ($maybe_set as $key => $value) { |
|
348 | + $current_value = $this->get($key); |
|
349 | 349 | |
350 | - if ( empty( $current_value ) ) { |
|
351 | - $this->set( $key, $value ); |
|
350 | + if (empty($current_value)) { |
|
351 | + $this->set($key, $value); |
|
352 | 352 | } |
353 | 353 | } |
354 | 354 | |
355 | - $this->set( 'date_modified', current_time( 'mysql' ) ); |
|
355 | + $this->set('date_modified', current_time('mysql')); |
|
356 | 356 | |
357 | 357 | return parent::save(); |
358 | 358 | } |
@@ -363,20 +363,20 @@ discard block |
||
363 | 363 | * @since 1.0.0 |
364 | 364 | * @param int $user_id. |
365 | 365 | */ |
366 | - public function clone_user( $user_id ) { |
|
367 | - $user = get_userdata( $user_id ); |
|
366 | + public function clone_user($user_id) { |
|
367 | + $user = get_userdata($user_id); |
|
368 | 368 | |
369 | - if ( empty( $user ) ) { |
|
369 | + if (empty($user)) { |
|
370 | 370 | return; |
371 | 371 | } |
372 | 372 | |
373 | - $this->set_user_id( $user->ID ); |
|
374 | - $this->set_email( $user->user_email ); |
|
375 | - $this->set_purchase_value( getpaid_get_user_total_spend( $user->ID ) ); |
|
376 | - $this->set_purchase_count( getpaid_count_user_invoices( $user->ID ) ); |
|
377 | - $this->set( 'first_name', $user->first_name ); |
|
378 | - $this->set( 'last_name', $user->last_name ); |
|
379 | - $this->set_date_created( $user->user_registered ); |
|
373 | + $this->set_user_id($user->ID); |
|
374 | + $this->set_email($user->user_email); |
|
375 | + $this->set_purchase_value(getpaid_get_user_total_spend($user->ID)); |
|
376 | + $this->set_purchase_count(getpaid_count_user_invoices($user->ID)); |
|
377 | + $this->set('first_name', $user->first_name); |
|
378 | + $this->set('last_name', $user->last_name); |
|
379 | + $this->set_date_created($user->user_registered); |
|
380 | 380 | |
381 | 381 | // Fetch extra data from WC or old GetPaid. |
382 | 382 | $prefixes = array( |
@@ -385,18 +385,18 @@ discard block |
||
385 | 385 | '', |
386 | 386 | ); |
387 | 387 | |
388 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
388 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
389 | 389 | |
390 | - foreach ( $prefixes as $prefix ) { |
|
390 | + foreach ($prefixes as $prefix) { |
|
391 | 391 | |
392 | 392 | // Meta table. |
393 | - $value = get_user_meta( $user_id, $prefix . $field, true ); |
|
393 | + $value = get_user_meta($user_id, $prefix . $field, true); |
|
394 | 394 | |
395 | 395 | // UWP table. |
396 | - $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value; |
|
396 | + $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value; |
|
397 | 397 | |
398 | - if ( ! empty( $value ) ) { |
|
399 | - $this->set( $field, $value ); |
|
398 | + if (!empty($value)) { |
|
399 | + $this->set($field, $value); |
|
400 | 400 | continue; |
401 | 401 | } |
402 | 402 | } |
@@ -409,9 +409,9 @@ discard block |
||
409 | 409 | * @since 1.0.0 |
410 | 410 | * @param int $user_id. |
411 | 411 | */ |
412 | - public function migrate_from_user( $user_id ) { |
|
413 | - $this->clone_user( $user_id ); |
|
414 | - do_action( 'getpaid_customer_migrated_from_user', $this, $user_id ); |
|
412 | + public function migrate_from_user($user_id) { |
|
413 | + $this->clone_user($user_id); |
|
414 | + do_action('getpaid_customer_migrated_from_user', $this, $user_id); |
|
415 | 415 | $this->save(); |
416 | 416 | } |
417 | 417 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | /** |
9 | 9 | * Main Subscriptions class. |
10 | 10 | * |
@@ -17,28 +17,28 @@ discard block |
||
17 | 17 | public function __construct() { |
18 | 18 | |
19 | 19 | // Fire gateway specific hooks when a subscription changes. |
20 | - add_action( 'getpaid_subscription_status_changed', array( $this, 'process_subscription_status_change' ), 10, 3 ); |
|
20 | + add_action('getpaid_subscription_status_changed', array($this, 'process_subscription_status_change'), 10, 3); |
|
21 | 21 | |
22 | 22 | // De-activate a subscription whenever the invoice changes payment statuses. |
23 | 23 | // add_action( 'getpaid_invoice_status_wpi-refunded', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
24 | - add_action( 'getpaid_invoice_status_wpi-failed', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
25 | - add_action( 'getpaid_invoice_status_wpi-cancelled', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
26 | - add_action( 'getpaid_invoice_status_wpi-pending', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
24 | + add_action('getpaid_invoice_status_wpi-failed', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
25 | + add_action('getpaid_invoice_status_wpi-cancelled', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
26 | + add_action('getpaid_invoice_status_wpi-pending', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
27 | 27 | |
28 | 28 | // Handles subscription cancelations. |
29 | - add_action( 'getpaid_authenticated_action_subscription_cancel', array( $this, 'user_cancel_single_subscription' ) ); |
|
29 | + add_action('getpaid_authenticated_action_subscription_cancel', array($this, 'user_cancel_single_subscription')); |
|
30 | 30 | |
31 | 31 | // Create a subscription whenever an invoice is created, (and update it when it is updated). |
32 | - add_action( 'wpinv_invoice_metabox_saved', array( $this, 'maybe_update_invoice_subscription' ), 5 ); |
|
33 | - add_action( 'getpaid_checkout_invoice_updated', array( $this, 'maybe_update_invoice_subscription' ), 5 ); |
|
32 | + add_action('wpinv_invoice_metabox_saved', array($this, 'maybe_update_invoice_subscription'), 5); |
|
33 | + add_action('getpaid_checkout_invoice_updated', array($this, 'maybe_update_invoice_subscription'), 5); |
|
34 | 34 | |
35 | 35 | // Handles admin subscription update actions. |
36 | - add_action( 'getpaid_authenticated_admin_action_update_single_subscription', array( $this, 'admin_update_single_subscription' ) ); |
|
37 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_renew', array( $this, 'admin_renew_single_subscription' ) ); |
|
38 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_delete', array( $this, 'admin_delete_single_subscription' ) ); |
|
36 | + add_action('getpaid_authenticated_admin_action_update_single_subscription', array($this, 'admin_update_single_subscription')); |
|
37 | + add_action('getpaid_authenticated_admin_action_subscription_manual_renew', array($this, 'admin_renew_single_subscription')); |
|
38 | + add_action('getpaid_authenticated_admin_action_subscription_manual_delete', array($this, 'admin_delete_single_subscription')); |
|
39 | 39 | |
40 | 40 | // Filter invoice item row actions. |
41 | - add_action( 'getpaid-invoice-page-line-item-actions', array( $this, 'filter_invoice_line_item_actions' ), 10, 3 ); |
|
41 | + add_action('getpaid-invoice-page-line-item-actions', array($this, 'filter_invoice_line_item_actions'), 10, 3); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -47,19 +47,19 @@ discard block |
||
47 | 47 | * @param WPInv_Invoice $invoice |
48 | 48 | * @return WPInv_Subscription|bool |
49 | 49 | */ |
50 | - public function get_invoice_subscription( $invoice ) { |
|
50 | + public function get_invoice_subscription($invoice) { |
|
51 | 51 | $subscription_id = $invoice->get_subscription_id(); |
52 | 52 | |
53 | 53 | // Fallback to the parent invoice if the child invoice has no subscription id. |
54 | - if ( empty( $subscription_id ) && $invoice->is_renewal() ) { |
|
54 | + if (empty($subscription_id) && $invoice->is_renewal()) { |
|
55 | 55 | $subscription_id = $invoice->get_parent_payment()->get_subscription_id(); |
56 | 56 | } |
57 | 57 | |
58 | 58 | // Fetch the subscription. |
59 | - $subscription = new WPInv_Subscription( $subscription_id ); |
|
59 | + $subscription = new WPInv_Subscription($subscription_id); |
|
60 | 60 | |
61 | 61 | // Return subscription or use a fallback for backwards compatibility. |
62 | - return $subscription->exists() ? $subscription : wpinv_get_invoice_subscription( $invoice ); |
|
62 | + return $subscription->exists() ? $subscription : wpinv_get_invoice_subscription($invoice); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -67,21 +67,21 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @param WPInv_Invoice $invoice |
69 | 69 | */ |
70 | - public function maybe_deactivate_invoice_subscription( $invoice ) { |
|
70 | + public function maybe_deactivate_invoice_subscription($invoice) { |
|
71 | 71 | |
72 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
72 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
73 | 73 | |
74 | - if ( empty( $subscriptions ) ) { |
|
74 | + if (empty($subscriptions)) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | 77 | |
78 | - if ( ! is_array( $subscriptions ) ) { |
|
79 | - $subscriptions = array( $subscriptions ); |
|
78 | + if (!is_array($subscriptions)) { |
|
79 | + $subscriptions = array($subscriptions); |
|
80 | 80 | } |
81 | 81 | |
82 | - foreach ( $subscriptions as $subscription ) { |
|
83 | - if ( $subscription->is_active() ) { |
|
84 | - $subscription->set_status( 'pending' ); |
|
82 | + foreach ($subscriptions as $subscription) { |
|
83 | + if ($subscription->is_active()) { |
|
84 | + $subscription->set_status('pending'); |
|
85 | 85 | $subscription->save(); |
86 | 86 | } |
87 | 87 | } |
@@ -95,15 +95,15 @@ discard block |
||
95 | 95 | * @param string $from |
96 | 96 | * @param string $to |
97 | 97 | */ |
98 | - public function process_subscription_status_change( $subscription, $from, $to ) { |
|
98 | + public function process_subscription_status_change($subscription, $from, $to) { |
|
99 | 99 | |
100 | 100 | $gateway = $subscription->get_gateway(); |
101 | 101 | |
102 | - if ( ! empty( $gateway ) ) { |
|
103 | - $gateway = sanitize_key( $gateway ); |
|
104 | - $from = sanitize_key( $from ); |
|
105 | - $to = sanitize_key( $to ); |
|
106 | - do_action( "getpaid_{$gateway}_subscription_$to", $subscription, $from ); |
|
102 | + if (!empty($gateway)) { |
|
103 | + $gateway = sanitize_key($gateway); |
|
104 | + $from = sanitize_key($from); |
|
105 | + $to = sanitize_key($to); |
|
106 | + do_action("getpaid_{$gateway}_subscription_$to", $subscription, $from); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | } |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | * @deprecated |
117 | 117 | * @return mixed|string|void |
118 | 118 | */ |
119 | - public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1 ) { |
|
120 | - return getpaid_get_subscription_period_label( $period, $frequency_count ); |
|
119 | + public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) { |
|
120 | + return getpaid_get_subscription_period_label($period, $frequency_count); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -127,21 +127,21 @@ discard block |
||
127 | 127 | * @since 1.0.0 |
128 | 128 | * @return void |
129 | 129 | */ |
130 | - public function user_cancel_single_subscription( $data ) { |
|
130 | + public function user_cancel_single_subscription($data) { |
|
131 | 131 | |
132 | 132 | // Ensure there is a subscription to cancel. |
133 | - if ( empty( $data['subscription'] ) ) { |
|
133 | + if (empty($data['subscription'])) { |
|
134 | 134 | return; |
135 | 135 | } |
136 | 136 | |
137 | - $subscription = new WPInv_Subscription( (int) $data['subscription'] ); |
|
137 | + $subscription = new WPInv_Subscription((int) $data['subscription']); |
|
138 | 138 | |
139 | 139 | // Ensure that it exists and that it belongs to the current user. |
140 | - if ( ! $subscription->exists() || $subscription->get_customer_id() != get_current_user_id() ) { |
|
140 | + if (!$subscription->exists() || $subscription->get_customer_id() != get_current_user_id()) { |
|
141 | 141 | $notice = 'perm_cancel_subscription'; |
142 | 142 | |
143 | 143 | // Can it be cancelled. |
144 | - } elseif ( ! $subscription->can_cancel() ) { |
|
144 | + } elseif (!$subscription->can_cancel()) { |
|
145 | 145 | $notice = 'cannot_cancel_subscription'; |
146 | 146 | |
147 | 147 | // Cancel it. |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | 'wpinv-notice' => $notice, |
158 | 158 | ); |
159 | 159 | |
160 | - wp_safe_redirect( add_query_arg( $redirect ) ); |
|
160 | + wp_safe_redirect(add_query_arg($redirect)); |
|
161 | 161 | exit; |
162 | 162 | |
163 | 163 | } |
@@ -169,41 +169,41 @@ discard block |
||
169 | 169 | * @param WPInv_Invoice $invoice |
170 | 170 | * @since 1.0.0 |
171 | 171 | */ |
172 | - public function maybe_create_invoice_subscription( $invoice ) { |
|
172 | + public function maybe_create_invoice_subscription($invoice) { |
|
173 | 173 | global $getpaid_subscriptions_skip_invoice_update; |
174 | 174 | |
175 | 175 | // Abort if it is not recurring. |
176 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_free() || ! $invoice->is_recurring() || $invoice->is_renewal() ) { |
|
176 | + if (!$invoice->is_type('invoice') || $invoice->is_free() || !$invoice->is_recurring() || $invoice->is_renewal()) { |
|
177 | 177 | return; |
178 | 178 | } |
179 | 179 | |
180 | 180 | // Either group the subscriptions or only process a single suscription. |
181 | - if ( getpaid_should_group_subscriptions( $invoice ) ) { |
|
181 | + if (getpaid_should_group_subscriptions($invoice)) { |
|
182 | 182 | |
183 | 183 | $subscription_groups = array(); |
184 | 184 | $is_first = true; |
185 | 185 | |
186 | - foreach ( getpaid_calculate_subscription_totals( $invoice ) as $group_key => $totals ) { |
|
187 | - $subscription_groups[ $group_key ] = $this->create_invoice_subscription_group( $totals, $invoice, 0, $is_first ); |
|
186 | + foreach (getpaid_calculate_subscription_totals($invoice) as $group_key => $totals) { |
|
187 | + $subscription_groups[$group_key] = $this->create_invoice_subscription_group($totals, $invoice, 0, $is_first); |
|
188 | 188 | |
189 | - if ( $is_first ) { |
|
189 | + if ($is_first) { |
|
190 | 190 | $getpaid_subscriptions_skip_invoice_update = true; |
191 | - $invoice->set_subscription_id( $subscription_groups[ $group_key ]['subscription_id'] ); |
|
191 | + $invoice->set_subscription_id($subscription_groups[$group_key]['subscription_id']); |
|
192 | 192 | $invoice->save(); |
193 | 193 | $getpaid_subscriptions_skip_invoice_update = false; |
194 | 194 | } |
195 | 195 | |
196 | - $is_first = false; |
|
196 | + $is_first = false; |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | // Cache subscription groups. |
200 | - update_post_meta( $invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups ); |
|
200 | + update_post_meta($invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups); |
|
201 | 201 | return true; |
202 | 202 | |
203 | 203 | } |
204 | 204 | |
205 | 205 | $subscription = new WPInv_Subscription(); |
206 | - return $this->update_invoice_subscription( $subscription, $invoice ); |
|
206 | + return $this->update_invoice_subscription($subscription, $invoice); |
|
207 | 207 | |
208 | 208 | } |
209 | 209 | |
@@ -218,46 +218,46 @@ discard block |
||
218 | 218 | * |
219 | 219 | * @since 2.3.0 |
220 | 220 | */ |
221 | - public function create_invoice_subscription_group( $totals, $invoice, $subscription_id = 0, $is_first = false ) { |
|
221 | + public function create_invoice_subscription_group($totals, $invoice, $subscription_id = 0, $is_first = false) { |
|
222 | 222 | |
223 | - $subscription = new WPInv_Subscription( (int) $subscription_id ); |
|
223 | + $subscription = new WPInv_Subscription((int) $subscription_id); |
|
224 | 224 | $initial_amt = $totals['initial_total']; |
225 | 225 | $recurring_amt = $totals['recurring_total']; |
226 | 226 | $fees = array(); |
227 | 227 | |
228 | 228 | // Maybe add recurring fees. |
229 | - if ( $is_first ) { |
|
229 | + if ($is_first) { |
|
230 | 230 | |
231 | - foreach ( $invoice->get_fees() as $i => $fee ) { |
|
232 | - if ( ! empty( $fee['recurring_fee'] ) ) { |
|
233 | - $initial_amt += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
234 | - $recurring_amt += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
235 | - $fees[ $i ] = $fee; |
|
231 | + foreach ($invoice->get_fees() as $i => $fee) { |
|
232 | + if (!empty($fee['recurring_fee'])) { |
|
233 | + $initial_amt += wpinv_sanitize_amount($fee['initial_fee']); |
|
234 | + $recurring_amt += wpinv_sanitize_amount($fee['recurring_fee']); |
|
235 | + $fees[$i] = $fee; |
|
236 | 236 | } |
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
240 | - $subscription->set_customer_id( $invoice->get_user_id() ); |
|
241 | - $subscription->set_parent_invoice_id( $invoice->get_id() ); |
|
242 | - $subscription->set_initial_amount( $initial_amt ); |
|
243 | - $subscription->set_recurring_amount( $recurring_amt ); |
|
244 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
245 | - $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' ); |
|
246 | - $subscription->set_product_id( $totals['item_id'] ); |
|
247 | - $subscription->set_period( $totals['period'] ); |
|
248 | - $subscription->set_frequency( $totals['interval'] ); |
|
249 | - $subscription->set_bill_times( $totals['recurring_limit'] ); |
|
250 | - $subscription->set_next_renewal_date( $totals['renews_on'] ); |
|
240 | + $subscription->set_customer_id($invoice->get_user_id()); |
|
241 | + $subscription->set_parent_invoice_id($invoice->get_id()); |
|
242 | + $subscription->set_initial_amount($initial_amt); |
|
243 | + $subscription->set_recurring_amount($recurring_amt); |
|
244 | + $subscription->set_date_created(current_time('mysql')); |
|
245 | + $subscription->set_status($invoice->is_paid() ? 'active' : 'pending'); |
|
246 | + $subscription->set_product_id($totals['item_id']); |
|
247 | + $subscription->set_period($totals['period']); |
|
248 | + $subscription->set_frequency($totals['interval']); |
|
249 | + $subscription->set_bill_times($totals['recurring_limit']); |
|
250 | + $subscription->set_next_renewal_date($totals['renews_on']); |
|
251 | 251 | |
252 | 252 | // Trial periods. |
253 | - if ( ! empty( $totals['trialling'] ) ) { |
|
254 | - $subscription->set_trial_period( $totals['trialling'] ); |
|
255 | - $subscription->set_status( 'trialling' ); |
|
253 | + if (!empty($totals['trialling'])) { |
|
254 | + $subscription->set_trial_period($totals['trialling']); |
|
255 | + $subscription->set_status('trialling'); |
|
256 | 256 | |
257 | 257 | // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial. |
258 | - } elseif ( empty( $initial_amt ) ) { |
|
259 | - $subscription->set_trial_period( $totals['interval'] . ' ' . $totals['period'] ); |
|
260 | - $subscription->set_status( 'trialling' ); |
|
258 | + } elseif (empty($initial_amt)) { |
|
259 | + $subscription->set_trial_period($totals['interval'] . ' ' . $totals['period']); |
|
260 | + $subscription->set_status('trialling'); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | $subscription->save(); |
@@ -275,86 +275,86 @@ discard block |
||
275 | 275 | * @param WPInv_Invoice $invoice |
276 | 276 | * @since 1.0.19 |
277 | 277 | */ |
278 | - public function maybe_update_invoice_subscription( $invoice ) { |
|
278 | + public function maybe_update_invoice_subscription($invoice) { |
|
279 | 279 | global $getpaid_subscriptions_skip_invoice_update; |
280 | 280 | |
281 | 281 | // Avoid infinite loops. |
282 | - if ( ! empty( $getpaid_subscriptions_skip_invoice_update ) ) { |
|
282 | + if (!empty($getpaid_subscriptions_skip_invoice_update)) { |
|
283 | 283 | return; |
284 | 284 | } |
285 | 285 | |
286 | 286 | // Do not process renewals. |
287 | - if ( $invoice->is_renewal() ) { |
|
287 | + if ($invoice->is_renewal()) { |
|
288 | 288 | return; |
289 | 289 | } |
290 | 290 | |
291 | 291 | // Delete existing subscriptions if available and the invoice is not recurring. |
292 | - if ( ! $invoice->is_recurring() ) { |
|
293 | - $this->delete_invoice_subscriptions( $invoice ); |
|
292 | + if (!$invoice->is_recurring()) { |
|
293 | + $this->delete_invoice_subscriptions($invoice); |
|
294 | 294 | return; |
295 | 295 | } |
296 | 296 | |
297 | 297 | // Fetch existing subscriptions. |
298 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
298 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
299 | 299 | |
300 | 300 | // Create new ones if no existing subscriptions. |
301 | - if ( empty( $subscriptions ) ) { |
|
302 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
301 | + if (empty($subscriptions)) { |
|
302 | + return $this->maybe_create_invoice_subscription($invoice); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | // Abort if an invoice is paid and already has a subscription. |
306 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
306 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
307 | 307 | return; |
308 | 308 | } |
309 | 309 | |
310 | - $is_grouped = is_array( $subscriptions ); |
|
311 | - $should_group = getpaid_should_group_subscriptions( $invoice ); |
|
310 | + $is_grouped = is_array($subscriptions); |
|
311 | + $should_group = getpaid_should_group_subscriptions($invoice); |
|
312 | 312 | |
313 | 313 | // Ensure that the subscriptions are only grouped if there are more than 1 recurring items. |
314 | - if ( $is_grouped != $should_group ) { |
|
315 | - $this->delete_invoice_subscriptions( $invoice ); |
|
316 | - delete_post_meta( $invoice->get_id(), 'getpaid_subscription_groups' ); |
|
317 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
314 | + if ($is_grouped != $should_group) { |
|
315 | + $this->delete_invoice_subscriptions($invoice); |
|
316 | + delete_post_meta($invoice->get_id(), 'getpaid_subscription_groups'); |
|
317 | + return $this->maybe_create_invoice_subscription($invoice); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | // If there is only one recurring item... |
321 | - if ( ! $is_grouped ) { |
|
322 | - return $this->update_invoice_subscription( $subscriptions, $invoice ); |
|
321 | + if (!$is_grouped) { |
|
322 | + return $this->update_invoice_subscription($subscriptions, $invoice); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | // Process subscription groups. |
326 | - $current_groups = getpaid_get_invoice_subscription_groups( $invoice->get_id() ); |
|
326 | + $current_groups = getpaid_get_invoice_subscription_groups($invoice->get_id()); |
|
327 | 327 | $subscription_groups = array(); |
328 | 328 | $is_first = true; |
329 | 329 | |
330 | 330 | // Create new subscription groups. |
331 | - foreach ( getpaid_calculate_subscription_totals( $invoice ) as $group_key => $totals ) { |
|
332 | - $subscription_id = isset( $current_groups[ $group_key ] ) ? $current_groups[ $group_key ]['subscription_id'] : 0; |
|
333 | - $subscription_groups[ $group_key ] = $this->create_invoice_subscription_group( $totals, $invoice, $subscription_id, $is_first ); |
|
331 | + foreach (getpaid_calculate_subscription_totals($invoice) as $group_key => $totals) { |
|
332 | + $subscription_id = isset($current_groups[$group_key]) ? $current_groups[$group_key]['subscription_id'] : 0; |
|
333 | + $subscription_groups[$group_key] = $this->create_invoice_subscription_group($totals, $invoice, $subscription_id, $is_first); |
|
334 | 334 | |
335 | - if ( $is_first && $invoice->get_subscription_id() !== $subscription_groups[ $group_key ]['subscription_id'] ) { |
|
335 | + if ($is_first && $invoice->get_subscription_id() !== $subscription_groups[$group_key]['subscription_id']) { |
|
336 | 336 | $getpaid_subscriptions_skip_invoice_update = true; |
337 | - $invoice->set_subscription_id( $subscription_groups[ $group_key ]['subscription_id'] ); |
|
337 | + $invoice->set_subscription_id($subscription_groups[$group_key]['subscription_id']); |
|
338 | 338 | $invoice->save(); |
339 | 339 | $getpaid_subscriptions_skip_invoice_update = false; |
340 | 340 | } |
341 | 341 | |
342 | - $is_first = false; |
|
342 | + $is_first = false; |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | // Delete non-existent subscription groups. |
346 | - foreach ( $current_groups as $group_key => $data ) { |
|
347 | - if ( ! isset( $subscription_groups[ $group_key ] ) ) { |
|
348 | - $subscription = new WPInv_Subscription( (int) $data['subscription_id'] ); |
|
346 | + foreach ($current_groups as $group_key => $data) { |
|
347 | + if (!isset($subscription_groups[$group_key])) { |
|
348 | + $subscription = new WPInv_Subscription((int) $data['subscription_id']); |
|
349 | 349 | |
350 | - if ( $subscription->exists() ) { |
|
351 | - $subscription->delete( true ); |
|
350 | + if ($subscription->exists()) { |
|
351 | + $subscription->delete(true); |
|
352 | 352 | } |
353 | 353 | } |
354 | 354 | } |
355 | 355 | |
356 | 356 | // Cache subscription groups. |
357 | - update_post_meta( $invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups ); |
|
357 | + update_post_meta($invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups); |
|
358 | 358 | return true; |
359 | 359 | |
360 | 360 | } |
@@ -364,20 +364,20 @@ discard block |
||
364 | 364 | * |
365 | 365 | * @param WPInv_Invoice $invoice |
366 | 366 | */ |
367 | - public function delete_invoice_subscriptions( $invoice ) { |
|
367 | + public function delete_invoice_subscriptions($invoice) { |
|
368 | 368 | |
369 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
369 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
370 | 370 | |
371 | - if ( empty( $subscriptions ) ) { |
|
371 | + if (empty($subscriptions)) { |
|
372 | 372 | return; |
373 | 373 | } |
374 | 374 | |
375 | - if ( ! is_array( $subscriptions ) ) { |
|
376 | - $subscriptions = array( $subscriptions ); |
|
375 | + if (!is_array($subscriptions)) { |
|
376 | + $subscriptions = array($subscriptions); |
|
377 | 377 | } |
378 | 378 | |
379 | - foreach ( $subscriptions as $subscription ) { |
|
380 | - $subscription->delete( true ); |
|
379 | + foreach ($subscriptions as $subscription) { |
|
380 | + $subscription->delete(true); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | } |
@@ -390,57 +390,57 @@ discard block |
||
390 | 390 | * @param WPInv_Invoice $invoice |
391 | 391 | * @since 1.0.19 |
392 | 392 | */ |
393 | - public function update_invoice_subscription( $subscription, $invoice ) { |
|
393 | + public function update_invoice_subscription($subscription, $invoice) { |
|
394 | 394 | |
395 | 395 | // Delete the subscription if an invoice is free or nolonger recurring. |
396 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_free() || ! $invoice->is_recurring() ) { |
|
396 | + if (!$invoice->is_type('invoice') || $invoice->is_free() || !$invoice->is_recurring()) { |
|
397 | 397 | return $subscription->delete(); |
398 | 398 | } |
399 | 399 | |
400 | - $subscription->set_customer_id( $invoice->get_user_id() ); |
|
401 | - $subscription->set_parent_invoice_id( $invoice->get_id() ); |
|
402 | - $subscription->set_initial_amount( $invoice->get_initial_total() ); |
|
403 | - $subscription->set_recurring_amount( $invoice->get_recurring_total() ); |
|
404 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
405 | - $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' ); |
|
400 | + $subscription->set_customer_id($invoice->get_user_id()); |
|
401 | + $subscription->set_parent_invoice_id($invoice->get_id()); |
|
402 | + $subscription->set_initial_amount($invoice->get_initial_total()); |
|
403 | + $subscription->set_recurring_amount($invoice->get_recurring_total()); |
|
404 | + $subscription->set_date_created(current_time('mysql')); |
|
405 | + $subscription->set_status($invoice->is_paid() ? 'active' : 'pending'); |
|
406 | 406 | |
407 | 407 | // Get the recurring item and abort if it does not exist. |
408 | - $subscription_item = $invoice->get_recurring( true ); |
|
409 | - if ( ! $subscription_item->get_id() ) { |
|
410 | - $invoice->set_subscription_id( 0 ); |
|
408 | + $subscription_item = $invoice->get_recurring(true); |
|
409 | + if (!$subscription_item->get_id()) { |
|
410 | + $invoice->set_subscription_id(0); |
|
411 | 411 | $invoice->save(); |
412 | 412 | return $subscription->delete(); |
413 | 413 | } |
414 | 414 | |
415 | - $subscription->set_product_id( $subscription_item->get_id() ); |
|
416 | - $subscription->set_period( $subscription_item->get_recurring_period( true ) ); |
|
417 | - $subscription->set_frequency( $subscription_item->get_recurring_interval() ); |
|
418 | - $subscription->set_bill_times( $subscription_item->get_recurring_limit() ); |
|
415 | + $subscription->set_product_id($subscription_item->get_id()); |
|
416 | + $subscription->set_period($subscription_item->get_recurring_period(true)); |
|
417 | + $subscription->set_frequency($subscription_item->get_recurring_interval()); |
|
418 | + $subscription->set_bill_times($subscription_item->get_recurring_limit()); |
|
419 | 419 | |
420 | 420 | // Calculate the next renewal date. |
421 | - $period = $subscription_item->get_recurring_period( true ); |
|
421 | + $period = $subscription_item->get_recurring_period(true); |
|
422 | 422 | $interval = $subscription_item->get_recurring_interval(); |
423 | 423 | |
424 | 424 | // If the subscription item has a trial period... |
425 | - if ( $subscription_item->has_free_trial() ) { |
|
426 | - $period = $subscription_item->get_trial_period( true ); |
|
425 | + if ($subscription_item->has_free_trial()) { |
|
426 | + $period = $subscription_item->get_trial_period(true); |
|
427 | 427 | $interval = $subscription_item->get_trial_interval(); |
428 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
429 | - $subscription->set_status( 'trialling' ); |
|
428 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
429 | + $subscription->set_status('trialling'); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial. |
433 | - if ( $invoice->has_free_trial() ) { |
|
434 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
435 | - $subscription->set_status( 'trialling' ); |
|
433 | + if ($invoice->has_free_trial()) { |
|
434 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
435 | + $subscription->set_status('trialling'); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | // Calculate the next renewal date. |
439 | - $expiration = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", strtotime( $subscription->get_date_created() ) ) ); |
|
439 | + $expiration = date('Y-m-d H:i:s', strtotime("+$interval $period", strtotime($subscription->get_date_created()))); |
|
440 | 440 | |
441 | - $subscription->set_next_renewal_date( $expiration ); |
|
441 | + $subscription->set_next_renewal_date($expiration); |
|
442 | 442 | $subscription->save(); |
443 | - $invoice->set_subscription_id( $subscription->get_id() ); |
|
443 | + $invoice->set_subscription_id($subscription->get_id()); |
|
444 | 444 | return $subscription->get_id(); |
445 | 445 | |
446 | 446 | } |
@@ -451,34 +451,34 @@ discard block |
||
451 | 451 | * @param array $data |
452 | 452 | * @since 1.0.19 |
453 | 453 | */ |
454 | - public function admin_update_single_subscription( $args ) { |
|
454 | + public function admin_update_single_subscription($args) { |
|
455 | 455 | |
456 | 456 | // Ensure the subscription exists and that a status has been given. |
457 | - if ( empty( $args['subscription_id'] ) ) { |
|
457 | + if (empty($args['subscription_id'])) { |
|
458 | 458 | return; |
459 | 459 | } |
460 | 460 | |
461 | 461 | // Retrieve the subscriptions. |
462 | - $subscription = new WPInv_Subscription( $args['subscription_id'] ); |
|
462 | + $subscription = new WPInv_Subscription($args['subscription_id']); |
|
463 | 463 | |
464 | - if ( $subscription->get_id() ) { |
|
464 | + if ($subscription->get_id()) { |
|
465 | 465 | |
466 | 466 | $subscription->set_props( |
467 | 467 | array( |
468 | - 'status' => isset( $args['subscription_status'] ) ? $args['subscription_status'] : null, |
|
469 | - 'profile_id' => isset( $args['wpinv_subscription_profile_id'] ) ? $args['wpinv_subscription_profile_id'] : null, |
|
470 | - 'date_created' => ! empty( $args['wpinv_subscription_date_created'] ) ? $args['wpinv_subscription_date_created'] : null, |
|
471 | - 'expiration' => ! empty( $args['wpinv_subscription_expiration'] ) ? $args['wpinv_subscription_expiration'] : null, |
|
472 | - 'bill_times' => ! empty( $args['wpinv_subscription_max_bill_times'] ) ? $args['wpinv_subscription_max_bill_times'] : null, |
|
468 | + 'status' => isset($args['subscription_status']) ? $args['subscription_status'] : null, |
|
469 | + 'profile_id' => isset($args['wpinv_subscription_profile_id']) ? $args['wpinv_subscription_profile_id'] : null, |
|
470 | + 'date_created' => !empty($args['wpinv_subscription_date_created']) ? $args['wpinv_subscription_date_created'] : null, |
|
471 | + 'expiration' => !empty($args['wpinv_subscription_expiration']) ? $args['wpinv_subscription_expiration'] : null, |
|
472 | + 'bill_times' => !empty($args['wpinv_subscription_max_bill_times']) ? $args['wpinv_subscription_max_bill_times'] : null, |
|
473 | 473 | ) |
474 | 474 | ); |
475 | 475 | |
476 | 476 | $changes = $subscription->get_changes(); |
477 | 477 | |
478 | 478 | $subscription->save(); |
479 | - getpaid_admin()->show_info( __( 'Subscription updated', 'invoicing' ) ); |
|
479 | + getpaid_admin()->show_info(__('Subscription updated', 'invoicing')); |
|
480 | 480 | |
481 | - do_action( 'getpaid_admin_updated_subscription', $subscription, $args, $changes ); |
|
481 | + do_action('getpaid_admin_updated_subscription', $subscription, $args, $changes); |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | } |
@@ -489,27 +489,27 @@ discard block |
||
489 | 489 | * @param array $data |
490 | 490 | * @since 1.0.19 |
491 | 491 | */ |
492 | - public function admin_renew_single_subscription( $args ) { |
|
492 | + public function admin_renew_single_subscription($args) { |
|
493 | 493 | |
494 | 494 | // Ensure the subscription exists and that a status has been given. |
495 | - if ( empty( $args['id'] ) ) { |
|
495 | + if (empty($args['id'])) { |
|
496 | 496 | return; |
497 | 497 | } |
498 | 498 | |
499 | 499 | // Retrieve the subscriptions. |
500 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
500 | + $subscription = new WPInv_Subscription($args['id']); |
|
501 | 501 | |
502 | - if ( $subscription->get_id() ) { |
|
502 | + if ($subscription->get_id()) { |
|
503 | 503 | |
504 | - do_action( 'getpaid_admin_renew_subscription', $subscription ); |
|
504 | + do_action('getpaid_admin_renew_subscription', $subscription); |
|
505 | 505 | |
506 | - $args = array( 'transaction_id', $subscription->get_parent_invoice()->generate_key( 'renewal_' ) ); |
|
506 | + $args = array('transaction_id', $subscription->get_parent_invoice()->generate_key('renewal_')); |
|
507 | 507 | |
508 | - if ( ! $subscription->add_payment( $args ) ) { |
|
509 | - getpaid_admin()->show_error( __( 'We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing' ) ); |
|
508 | + if (!$subscription->add_payment($args)) { |
|
509 | + getpaid_admin()->show_error(__('We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing')); |
|
510 | 510 | } else { |
511 | 511 | $subscription->renew(); |
512 | - getpaid_admin()->show_info( __( 'This subscription has been renewed and extended.', 'invoicing' ) ); |
|
512 | + getpaid_admin()->show_info(__('This subscription has been renewed and extended.', 'invoicing')); |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | wp_safe_redirect( |
@@ -532,20 +532,20 @@ discard block |
||
532 | 532 | * @param array $data |
533 | 533 | * @since 1.0.19 |
534 | 534 | */ |
535 | - public function admin_delete_single_subscription( $args ) { |
|
535 | + public function admin_delete_single_subscription($args) { |
|
536 | 536 | |
537 | 537 | // Ensure the subscription exists and that a status has been given. |
538 | - if ( empty( $args['id'] ) ) { |
|
538 | + if (empty($args['id'])) { |
|
539 | 539 | return; |
540 | 540 | } |
541 | 541 | |
542 | 542 | // Retrieve the subscriptions. |
543 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
543 | + $subscription = new WPInv_Subscription($args['id']); |
|
544 | 544 | |
545 | - if ( $subscription->delete() ) { |
|
546 | - getpaid_admin()->show_info( __( 'This subscription has been deleted.', 'invoicing' ) ); |
|
545 | + if ($subscription->delete()) { |
|
546 | + getpaid_admin()->show_info(__('This subscription has been deleted.', 'invoicing')); |
|
547 | 547 | } else { |
548 | - getpaid_admin()->show_error( __( 'We are unable to delete this subscription. Please try again.', 'invoicing' ) ); |
|
548 | + getpaid_admin()->show_error(__('We are unable to delete this subscription. Please try again.', 'invoicing')); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | $redirected = wp_safe_redirect( |
@@ -558,7 +558,7 @@ discard block |
||
558 | 558 | ) |
559 | 559 | ); |
560 | 560 | |
561 | - if ( $redirected ) { |
|
561 | + if ($redirected) { |
|
562 | 562 | exit; |
563 | 563 | } |
564 | 564 | |
@@ -571,16 +571,16 @@ discard block |
||
571 | 571 | * @param WPInv_Item $item |
572 | 572 | * @param WPInv_Invoice $invoice |
573 | 573 | */ |
574 | - public function filter_invoice_line_item_actions( $actions, $item, $invoice ) { |
|
574 | + public function filter_invoice_line_item_actions($actions, $item, $invoice) { |
|
575 | 575 | |
576 | 576 | // Abort if this invoice uses subscription groups. |
577 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
578 | - if ( ! $invoice->is_recurring() || ! is_object( $subscriptions ) ) { |
|
577 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
578 | + if (!$invoice->is_recurring() || !is_object($subscriptions)) { |
|
579 | 579 | return $actions; |
580 | 580 | } |
581 | 581 | |
582 | 582 | // Fetch item subscription. |
583 | - $args = array( |
|
583 | + $args = array( |
|
584 | 584 | 'invoice_in' => $invoice->is_parent() ? $invoice->get_id() : $invoice->get_parent_id(), |
585 | 585 | 'product_in' => $item->get_id(), |
586 | 586 | 'number' => 1, |
@@ -588,13 +588,13 @@ discard block |
||
588 | 588 | 'fields' => 'id', |
589 | 589 | ); |
590 | 590 | |
591 | - $subscription = new GetPaid_Subscriptions_Query( $args ); |
|
591 | + $subscription = new GetPaid_Subscriptions_Query($args); |
|
592 | 592 | $subscription = $subscription->get_results(); |
593 | 593 | |
594 | 594 | // In case we found a match... |
595 | - if ( ! empty( $subscription ) ) { |
|
596 | - $url = esc_url( add_query_arg( 'subscription', (int) $subscription[0], get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
597 | - $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
595 | + if (!empty($subscription)) { |
|
596 | + $url = esc_url(add_query_arg('subscription', (int) $subscription[0], get_permalink((int) wpinv_get_option('invoice_subscription_page')))); |
|
597 | + $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>'; |
|
598 | 598 | } |
599 | 599 | |
600 | 600 | return $actions; |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Class GetPaid_Tax |
@@ -21,15 +21,15 @@ discard block |
||
21 | 21 | * @param boolean $price_includes_tax Whether the passed price has taxes included. |
22 | 22 | * @return array Array of tax name => tax amount. |
23 | 23 | */ |
24 | - public static function calc_tax( $price, $rates, $price_includes_tax = false ) { |
|
24 | + public static function calc_tax($price, $rates, $price_includes_tax = false) { |
|
25 | 25 | |
26 | - if ( $price_includes_tax ) { |
|
27 | - $taxes = self::calc_inclusive_tax( $price, $rates ); |
|
26 | + if ($price_includes_tax) { |
|
27 | + $taxes = self::calc_inclusive_tax($price, $rates); |
|
28 | 28 | } else { |
29 | - $taxes = self::calc_exclusive_tax( $price, $rates ); |
|
29 | + $taxes = self::calc_exclusive_tax($price, $rates); |
|
30 | 30 | } |
31 | 31 | |
32 | - return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax ); |
|
32 | + return apply_filters('getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax); |
|
33 | 33 | |
34 | 34 | } |
35 | 35 | |
@@ -40,22 +40,22 @@ discard block |
||
40 | 40 | * @param array $rates Array of tax rates. |
41 | 41 | * @return array |
42 | 42 | */ |
43 | - public static function calc_inclusive_tax( $price, $rates ) { |
|
43 | + public static function calc_inclusive_tax($price, $rates) { |
|
44 | 44 | $taxes = array(); |
45 | - $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
45 | + $tax_rates = wp_list_pluck($rates, 'rate', 'name'); |
|
46 | 46 | |
47 | 47 | // Add tax rates. |
48 | - $tax_rate = 1 + ( array_sum( $tax_rates ) / 100 ); |
|
48 | + $tax_rate = 1 + (array_sum($tax_rates) / 100); |
|
49 | 49 | |
50 | - foreach ( $tax_rates as $name => $rate ) { |
|
51 | - $the_rate = ( $rate / 100 ) / $tax_rate; |
|
52 | - $net_price = $price - ( $the_rate * $price ); |
|
53 | - $tax_amount = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price ); |
|
54 | - $taxes[ $name ] = $tax_amount; |
|
50 | + foreach ($tax_rates as $name => $rate) { |
|
51 | + $the_rate = ($rate / 100) / $tax_rate; |
|
52 | + $net_price = $price - ($the_rate * $price); |
|
53 | + $tax_amount = apply_filters('getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price); |
|
54 | + $taxes[$name] = $tax_amount; |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | // Round all taxes to precision (4DP) before passing them back. |
58 | - $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
58 | + $taxes = array_map(array(__CLASS__, 'round'), $taxes); |
|
59 | 59 | |
60 | 60 | return $taxes; |
61 | 61 | } |
@@ -67,19 +67,19 @@ discard block |
||
67 | 67 | * @param array $rates Array of tax rates. |
68 | 68 | * @return array |
69 | 69 | */ |
70 | - public static function calc_exclusive_tax( $price, $rates ) { |
|
70 | + public static function calc_exclusive_tax($price, $rates) { |
|
71 | 71 | $taxes = array(); |
72 | - $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
72 | + $tax_rates = wp_list_pluck($rates, 'rate', 'name'); |
|
73 | 73 | |
74 | - foreach ( $tax_rates as $name => $rate ) { |
|
74 | + foreach ($tax_rates as $name => $rate) { |
|
75 | 75 | |
76 | - $tax_amount = $price * ( $rate / 100 ); |
|
77 | - $taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price ); |
|
76 | + $tax_amount = $price * ($rate / 100); |
|
77 | + $taxes[$name] = apply_filters('getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price); |
|
78 | 78 | |
79 | 79 | } |
80 | 80 | |
81 | 81 | // Round all taxes to precision (4DP) before passing them back. |
82 | - $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
82 | + $taxes = array_map(array(__CLASS__, 'round'), $taxes); |
|
83 | 83 | |
84 | 84 | return $taxes; |
85 | 85 | } |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public static function get_all_tax_rates() { |
93 | 93 | |
94 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
94 | + $rates = get_option('wpinv_tax_rates', array()); |
|
95 | 95 | |
96 | 96 | return apply_filters( |
97 | 97 | 'getpaid_get_all_tax_rates', |
98 | - array_filter( wpinv_parse_list( $rates ) ) |
|
98 | + array_filter(wpinv_parse_list($rates)) |
|
99 | 99 | ); |
100 | 100 | |
101 | 101 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | 'state' => wpinv_get_default_state(), |
116 | 116 | 'global' => true, |
117 | 117 | 'rate' => wpinv_get_default_tax_rate(), |
118 | - 'name' => __( 'Tax', 'invoicing' ), |
|
118 | + 'name' => __('Tax', 'invoicing'), |
|
119 | 119 | ), |
120 | 120 | ) |
121 | 121 | ); |
@@ -134,22 +134,22 @@ discard block |
||
134 | 134 | array( |
135 | 135 | array( |
136 | 136 | 'key' => 'physical', |
137 | - 'label' => __( 'Physical Item', 'invoicing' ), |
|
138 | - 'tax_base' => wpinv_get_option( 'tax_base', 'billing' ), |
|
139 | - 'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ), |
|
137 | + 'label' => __('Physical Item', 'invoicing'), |
|
138 | + 'tax_base' => wpinv_get_option('tax_base', 'billing'), |
|
139 | + 'same_country_rule' => wpinv_get_option('vat_same_country_rule', 'vat_too'), |
|
140 | 140 | ), |
141 | 141 | array( |
142 | 142 | 'key' => 'digital', |
143 | - 'label' => __( 'Digital Item', 'invoicing' ), |
|
144 | - 'tax_base' => wpinv_get_option( 'tax_base', 'billing' ), |
|
145 | - 'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ), |
|
143 | + 'label' => __('Digital Item', 'invoicing'), |
|
144 | + 'tax_base' => wpinv_get_option('tax_base', 'billing'), |
|
145 | + 'same_country_rule' => wpinv_get_option('vat_same_country_rule', 'vat_too'), |
|
146 | 146 | ), |
147 | 147 | ) |
148 | 148 | ); |
149 | 149 | |
150 | 150 | return apply_filters( |
151 | 151 | 'getpaid_tax_rules', |
152 | - array_filter( array_values( wpinv_parse_list( $rules ) ) ) |
|
152 | + array_filter(array_values(wpinv_parse_list($rules))) |
|
153 | 153 | ); |
154 | 154 | |
155 | 155 | } |
@@ -161,23 +161,23 @@ discard block |
||
161 | 161 | * @param string $state |
162 | 162 | * @return array |
163 | 163 | */ |
164 | - public static function get_address_tax_rates( $country, $state ) { |
|
164 | + public static function get_address_tax_rates($country, $state) { |
|
165 | 165 | |
166 | 166 | $all_tax_rates = self::get_all_tax_rates(); |
167 | 167 | $matching_rates = array_merge( |
168 | - wp_list_filter( $all_tax_rates, array( 'country' => $country ) ), |
|
169 | - wp_list_filter( $all_tax_rates, array( 'country' => '' ) ) |
|
168 | + wp_list_filter($all_tax_rates, array('country' => $country)), |
|
169 | + wp_list_filter($all_tax_rates, array('country' => '')) |
|
170 | 170 | ); |
171 | 171 | |
172 | - foreach ( $matching_rates as $i => $rate ) { |
|
172 | + foreach ($matching_rates as $i => $rate) { |
|
173 | 173 | |
174 | - $states = array_filter( wpinv_clean( explode( ',', strtolower( $rate['state'] ) ) ) ); |
|
175 | - if ( empty( $rate['global'] ) && ! in_array( strtolower( $state ), $states ) ) { |
|
176 | - unset( $matching_rates[ $i ] ); |
|
174 | + $states = array_filter(wpinv_clean(explode(',', strtolower($rate['state'])))); |
|
175 | + if (empty($rate['global']) && !in_array(strtolower($state), $states)) { |
|
176 | + unset($matching_rates[$i]); |
|
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
180 | - return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state ); |
|
180 | + return apply_filters('getpaid_get_address_tax_rates', $matching_rates, $country, $state); |
|
181 | 181 | |
182 | 182 | } |
183 | 183 | |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | * @param array $taxes Array of taxes. |
188 | 188 | * @return float |
189 | 189 | */ |
190 | - public static function get_tax_total( $taxes ) { |
|
191 | - return self::round( array_sum( $taxes ) ); |
|
190 | + public static function get_tax_total($taxes) { |
|
191 | + return self::round(array_sum($taxes)); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -204,8 +204,8 @@ discard block |
||
204 | 204 | * @param float|int $in Value to round. |
205 | 205 | * @return float |
206 | 206 | */ |
207 | - public static function round( $in ) { |
|
208 | - return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in ); |
|
207 | + public static function round($in) { |
|
208 | + return apply_filters('getpaid_tax_round', round($in, 4), $in); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | } |
@@ -8,22 +8,22 @@ discard block |
||
8 | 8 | * @var WPInv_Invoice $invoice |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | // Totals rows. |
14 | -$totals = getpaid_invoice_totals_rows( $invoice ); |
|
14 | +$totals = getpaid_invoice_totals_rows($invoice); |
|
15 | 15 | |
16 | -do_action( 'getpaid_before_email_line_totals', $invoice, $totals ); |
|
16 | +do_action('getpaid_before_email_line_totals', $invoice, $totals); |
|
17 | 17 | |
18 | 18 | ?> |
19 | 19 | |
20 | 20 | |
21 | -<?php if ( has_action( 'wpinv_email_footer_buttons' ) ) : ?> |
|
21 | +<?php if (has_action('wpinv_email_footer_buttons')) : ?> |
|
22 | 22 | |
23 | 23 | <tr class="wpinv_cart_footer_row"> |
24 | 24 | |
25 | - <td colspan="<?php echo ( (int) $column_count ); ?>"> |
|
26 | - <?php do_action( 'wpinv_email_footer_buttons' ); ?> |
|
25 | + <td colspan="<?php echo ((int) $column_count); ?>"> |
|
26 | + <?php do_action('wpinv_email_footer_buttons'); ?> |
|
27 | 27 | </td> |
28 | 28 | |
29 | 29 | </tr> |
@@ -31,49 +31,49 @@ discard block |
||
31 | 31 | <?php endif; ?> |
32 | 32 | |
33 | 33 | |
34 | -<?php foreach ( $totals as $key => $label ) : ?> |
|
34 | +<?php foreach ($totals as $key => $label) : ?> |
|
35 | 35 | |
36 | - <tr class="wpinv_cart_footer_row wpinv_cart_<?php echo esc_html( $key ); ?>_row"> |
|
36 | + <tr class="wpinv_cart_footer_row wpinv_cart_<?php echo esc_html($key); ?>_row"> |
|
37 | 37 | |
38 | - <td colspan="<?php echo absint( ( $column_count - 1 ) ); ?>" class="wpinv_cart_<?php echo esc_html( $key ); ?>_label text-right"> |
|
39 | - <strong><?php echo esc_html( $label ); ?>:</strong> |
|
38 | + <td colspan="<?php echo absint(($column_count - 1)); ?>" class="wpinv_cart_<?php echo esc_html($key); ?>_label text-right"> |
|
39 | + <strong><?php echo esc_html($label); ?>:</strong> |
|
40 | 40 | </td> |
41 | 41 | |
42 | - <td class="wpinv_cart_<?php echo esc_html( $key ); ?> text-right"> |
|
42 | + <td class="wpinv_cart_<?php echo esc_html($key); ?> text-right"> |
|
43 | 43 | |
44 | 44 | <?php |
45 | 45 | |
46 | 46 | // Total tax. |
47 | - if ( 'tax' == $key ) { |
|
48 | - wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() ); |
|
47 | + if ('tax' == $key) { |
|
48 | + wpinv_the_price($invoice->get_total_tax(), $invoice->get_currency()); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | // Individual taxes. |
52 | - if ( 0 === strpos( $key, 'tax__' ) ) { |
|
53 | - wpinv_the_price( $invoice->get_tax_total_by_name( str_replace( 'tax__', '', $key ) ), $invoice->get_currency() ); |
|
52 | + if (0 === strpos($key, 'tax__')) { |
|
53 | + wpinv_the_price($invoice->get_tax_total_by_name(str_replace('tax__', '', $key)), $invoice->get_currency()); |
|
54 | 54 | } |
55 | 55 | |
56 | - if ( 'fee' == $key ) { |
|
57 | - wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
56 | + if ('fee' == $key) { |
|
57 | + wpinv_the_price($invoice->get_total_fees(), $invoice->get_currency()); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Total discount. |
61 | - if ( 'discount' == $key ) { |
|
62 | - wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
61 | + if ('discount' == $key) { |
|
62 | + wpinv_the_price($invoice->get_total_discount(), $invoice->get_currency()); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | // Sub total. |
66 | - if ( 'subtotal' == $key ) { |
|
67 | - wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
66 | + if ('subtotal' == $key) { |
|
67 | + wpinv_the_price($invoice->get_subtotal(), $invoice->get_currency()); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | // Total. |
71 | - if ( 'total' == $key ) { |
|
72 | - wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
71 | + if ('total' == $key) { |
|
72 | + wpinv_the_price($invoice->get_total(), $invoice->get_currency()); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | // Fires when printing a cart total in an email. |
76 | - do_action( "getpaid_email_cart_totals_$key", $invoice ); |
|
76 | + do_action("getpaid_email_cart_totals_$key", $invoice); |
|
77 | 77 | |
78 | 78 | ?> |
79 | 79 | |
@@ -85,4 +85,4 @@ discard block |
||
85 | 85 | |
86 | 86 | <?php |
87 | 87 | |
88 | - do_action( 'getpaid_after_email_line_totals', $invoice, $totals ); |
|
88 | + do_action('getpaid_after_email_line_totals', $invoice, $totals); |
@@ -9,26 +9,26 @@ discard block |
||
9 | 9 | * @var WPInv_Invoice $invoice |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | // Totals rows. |
15 | -$totals = getpaid_invoice_totals_rows( $invoice ); |
|
15 | +$totals = getpaid_invoice_totals_rows($invoice); |
|
16 | 16 | |
17 | -do_action( 'getpaid_before_invoice_line_totals', $invoice, $totals ); |
|
17 | +do_action('getpaid_before_invoice_line_totals', $invoice, $totals); |
|
18 | 18 | |
19 | 19 | ?> |
20 | 20 | <div class='getpaid-invoice-line-totals'> |
21 | 21 | <div class="row"> |
22 | 22 | <div class="col-12 offset-sm-6 col-sm-6 border-sm-left pl-sm-0"> |
23 | 23 | |
24 | - <?php foreach ( $totals as $key => $label ) : ?> |
|
24 | + <?php foreach ($totals as $key => $label) : ?> |
|
25 | 25 | |
26 | - <div class="getpaid-invoice-line-totals-col <?php echo esc_attr( $key ); ?>"> |
|
26 | + <div class="getpaid-invoice-line-totals-col <?php echo esc_attr($key); ?>"> |
|
27 | 27 | |
28 | 28 | <div class="form-row row"> |
29 | 29 | |
30 | 30 | <div class="col-8 getpaid-invoice-line-totals-label"> |
31 | - <?php echo esc_html( $label ); ?> |
|
31 | + <?php echo esc_html($label); ?> |
|
32 | 32 | </div> |
33 | 33 | |
34 | 34 | <div class="col-4 getpaid-invoice-line-totals-value pl-0"> |
@@ -36,62 +36,62 @@ discard block |
||
36 | 36 | <?php |
37 | 37 | |
38 | 38 | // Total tax. |
39 | - if ( 'tax' === $key ) { |
|
40 | - wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() ); |
|
39 | + if ('tax' === $key) { |
|
40 | + wpinv_the_price($invoice->get_total_tax(), $invoice->get_currency()); |
|
41 | 41 | |
42 | - if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
42 | + if (wpinv_use_taxes() && !$invoice->get_disable_taxes()) { |
|
43 | 43 | |
44 | 44 | $taxes = $invoice->get_total_tax(); |
45 | - if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
45 | + if (empty($taxes) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) { |
|
46 | 46 | echo ' <em class="text-muted small">'; |
47 | - _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
47 | + _x('(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing'); |
|
48 | 48 | echo '</em>'; |
49 | 49 | } |
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
53 | 53 | // Check if field starts with tax__. |
54 | - if ( 0 === strpos( $key, 'tax__' ) ) { |
|
55 | - $tax_amount = $invoice->get_tax_total_by_name( str_replace( 'tax__', '', $key ) ); |
|
56 | - wpinv_the_price( $tax_amount, $invoice->get_currency() ); |
|
54 | + if (0 === strpos($key, 'tax__')) { |
|
55 | + $tax_amount = $invoice->get_tax_total_by_name(str_replace('tax__', '', $key)); |
|
56 | + wpinv_the_price($tax_amount, $invoice->get_currency()); |
|
57 | 57 | |
58 | - if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
58 | + if (wpinv_use_taxes() && !$invoice->get_disable_taxes()) { |
|
59 | 59 | |
60 | - if ( empty( $tax_amount ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
60 | + if (empty($tax_amount) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) { |
|
61 | 61 | echo ' <em class="text-muted small">'; |
62 | - _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
62 | + _x('(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing'); |
|
63 | 63 | echo '</em>'; |
64 | 64 | } |
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | 68 | // Total Fee. |
69 | - if ( 'fee' === $key ) { |
|
70 | - wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
69 | + if ('fee' === $key) { |
|
70 | + wpinv_the_price($invoice->get_total_fees(), $invoice->get_currency()); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // Total discount. |
74 | - if ( 'discount' === $key ) { |
|
75 | - wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
74 | + if ('discount' === $key) { |
|
75 | + wpinv_the_price($invoice->get_total_discount(), $invoice->get_currency()); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Shipping. |
79 | - if ( 'shipping' === $key ) { |
|
80 | - wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
79 | + if ('shipping' === $key) { |
|
80 | + wpinv_the_price($invoice->get_shipping(), $invoice->get_currency()); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | // Sub total. |
84 | - if ( 'subtotal' === $key ) { |
|
85 | - wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
84 | + if ('subtotal' === $key) { |
|
85 | + wpinv_the_price($invoice->get_subtotal(), $invoice->get_currency()); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Total. |
89 | - if ( 'total' === $key ) { |
|
90 | - wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
89 | + if ('total' === $key) { |
|
90 | + wpinv_the_price($invoice->get_total(), $invoice->get_currency()); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | // Fires when printing a cart total. |
94 | - do_action( "getpaid_invoice_cart_totals_$key", $invoice ); |
|
94 | + do_action("getpaid_invoice_cart_totals_$key", $invoice); |
|
95 | 95 | |
96 | 96 | ?> |
97 | 97 | |
@@ -105,4 +105,4 @@ discard block |
||
105 | 105 | </div> |
106 | 106 | </div> <!-- end .getpaid-invoice-line-totals --> |
107 | 107 | |
108 | -<?php do_action( 'getpaid_after_invoice_line_totals', $invoice, $totals ); ?> |
|
108 | +<?php do_action('getpaid_after_invoice_line_totals', $invoice, $totals); ?> |