@@ -12,294 +12,294 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Helper { |
14 | 14 | |
15 | - /** |
|
16 | - * Get report totals such as invoice totals and discount amounts. |
|
17 | - * |
|
18 | - * Data example: |
|
19 | - * |
|
20 | - * 'subtotal' => array( |
|
21 | - * 'type' => 'invoice_data', |
|
22 | - * 'function' => 'SUM', |
|
23 | - * 'name' => 'subtotal' |
|
24 | - * ) |
|
25 | - * |
|
26 | - * @param array $args |
|
27 | - * @return mixed depending on query_type |
|
28 | - */ |
|
29 | - public static function get_invoice_report_data( $args = array() ) { |
|
30 | - global $wpdb; |
|
31 | - |
|
32 | - $default_args = array( |
|
33 | - 'data' => array(), // The data to retrieve. |
|
34 | - 'where' => array(), // An array of where queries. |
|
35 | - 'query_type' => 'get_row', // wpdb query to run. |
|
36 | - 'group_by' => '', // What to group results by. |
|
37 | - 'order_by' => '', // What to order by. |
|
38 | - 'limit' => '', // Results limit. |
|
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' ), |
|
42 | - 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
|
43 | - ); |
|
44 | - |
|
45 | - $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
46 | - $args = wp_parse_args( $args, $default_args ); |
|
47 | - |
|
48 | - extract( $args ); |
|
49 | - |
|
50 | - if ( empty( $data ) ) { |
|
51 | - return ''; |
|
52 | - } |
|
53 | - |
|
54 | - $query = array(); |
|
55 | - $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
56 | - $query['from'] = "FROM {$wpdb->posts} AS posts"; |
|
57 | - $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
58 | - |
|
59 | - $query['where'] = " |
|
15 | + /** |
|
16 | + * Get report totals such as invoice totals and discount amounts. |
|
17 | + * |
|
18 | + * Data example: |
|
19 | + * |
|
20 | + * 'subtotal' => array( |
|
21 | + * 'type' => 'invoice_data', |
|
22 | + * 'function' => 'SUM', |
|
23 | + * 'name' => 'subtotal' |
|
24 | + * ) |
|
25 | + * |
|
26 | + * @param array $args |
|
27 | + * @return mixed depending on query_type |
|
28 | + */ |
|
29 | + public static function get_invoice_report_data( $args = array() ) { |
|
30 | + global $wpdb; |
|
31 | + |
|
32 | + $default_args = array( |
|
33 | + 'data' => array(), // The data to retrieve. |
|
34 | + 'where' => array(), // An array of where queries. |
|
35 | + 'query_type' => 'get_row', // wpdb query to run. |
|
36 | + 'group_by' => '', // What to group results by. |
|
37 | + 'order_by' => '', // What to order by. |
|
38 | + 'limit' => '', // Results limit. |
|
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' ), |
|
42 | + 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
|
43 | + ); |
|
44 | + |
|
45 | + $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
46 | + $args = wp_parse_args( $args, $default_args ); |
|
47 | + |
|
48 | + extract( $args ); |
|
49 | + |
|
50 | + if ( empty( $data ) ) { |
|
51 | + return ''; |
|
52 | + } |
|
53 | + |
|
54 | + $query = array(); |
|
55 | + $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
56 | + $query['from'] = "FROM {$wpdb->posts} AS posts"; |
|
57 | + $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
58 | + |
|
59 | + $query['where'] = " |
|
60 | 60 | WHERE posts.post_type IN ( '" . implode( "','", $invoice_types ) . "' ) |
61 | 61 | "; |
62 | 62 | |
63 | - if ( ! empty( $invoice_status ) ) { |
|
64 | - $query['where'] .= " |
|
63 | + if ( ! empty( $invoice_status ) ) { |
|
64 | + $query['where'] .= " |
|
65 | 65 | AND posts.post_status IN ( '" . implode( "','", $invoice_status ) . "' ) |
66 | 66 | "; |
67 | - } |
|
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 ) "; |
|
72 | - } else { |
|
73 | - $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - if ( ! empty( $filter_range['before'] ) ) { |
|
78 | - $query['where'] .= " |
|
67 | + } |
|
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 ) "; |
|
72 | + } else { |
|
73 | + $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + if ( ! empty( $filter_range['before'] ) ) { |
|
78 | + $query['where'] .= " |
|
79 | 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'] ) ) { |
|
84 | - $query['where'] .= " |
|
83 | + if ( ! empty( $filter_range['after'] ) ) { |
|
84 | + $query['where'] .= " |
|
85 | 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' ) { |
|
94 | - |
|
95 | - if ( is_array( $value['value'] ) ) { |
|
96 | - $value['value'] = implode( "','", $value['value'] ); |
|
97 | - } |
|
98 | - |
|
99 | - if ( ! empty( $value['value'] ) ) { |
|
100 | - $where_value = "{$value['operator']} ('{$value['value']}')"; |
|
101 | - } |
|
102 | - } else { |
|
103 | - $where_value = "{$value['operator']} '{$value['value']}'"; |
|
104 | - } |
|
105 | - |
|
106 | - if ( ! empty( $where_value ) ) { |
|
107 | - $query['where'] .= " AND {$value['key']} {$where_value}"; |
|
108 | - } |
|
109 | - } |
|
110 | - } |
|
111 | - |
|
112 | - if ( $group_by ) { |
|
113 | - $query['group_by'] = "GROUP BY {$group_by}"; |
|
114 | - } |
|
115 | - |
|
116 | - if ( $order_by ) { |
|
117 | - $query['order_by'] = "ORDER BY {$order_by}"; |
|
118 | - } |
|
119 | - |
|
120 | - if ( $limit ) { |
|
121 | - $query['limit'] = "LIMIT {$limit}"; |
|
122 | - } |
|
123 | - |
|
124 | - $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
125 | - $query = implode( ' ', $query ); |
|
126 | - |
|
127 | - return self::execute( $query_type, $query ); |
|
128 | - |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Prepares the data to select. |
|
133 | - * |
|
134 | - * |
|
135 | - * @param array $data |
|
136 | - * @return array |
|
137 | - */ |
|
138 | - public static function prepare_invoice_data( $data ) { |
|
139 | - |
|
140 | - $prepared = array(); |
|
141 | - |
|
142 | - foreach ( $data as $raw_key => $value ) { |
|
143 | - $key = sanitize_key( $raw_key ); |
|
144 | - $distinct = ''; |
|
145 | - |
|
146 | - if ( isset( $value['distinct'] ) ) { |
|
147 | - $distinct = 'DISTINCT'; |
|
148 | - } |
|
149 | - |
|
150 | - $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
151 | - |
|
152 | - if ( false === $get_key ) { |
|
153 | - // Skip to the next foreach iteration else the query will be invalid. |
|
154 | - continue; |
|
155 | - } |
|
156 | - |
|
157 | - if ( ! empty( $value['function'] ) ) { |
|
158 | - $get = "{$value['function']}({$distinct} {$get_key})"; |
|
159 | - } else { |
|
160 | - $get = "{$distinct} {$get_key}"; |
|
161 | - } |
|
162 | - |
|
163 | - $prepared[] = "{$get} as {$value['name']}"; |
|
164 | - } |
|
165 | - |
|
166 | - return $prepared; |
|
167 | - |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Prepares the joins to use. |
|
172 | - * |
|
173 | - * |
|
174 | - * @param array $data |
|
175 | - * @param bool $with_parent |
|
176 | - * @return array |
|
177 | - */ |
|
178 | - public static function prepare_invoice_joins( $data, $with_parent ) { |
|
179 | - global $wpdb; |
|
180 | - |
|
181 | - $prepared = array(); |
|
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 ); |
|
187 | - |
|
188 | - switch ( $type ) { |
|
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}' )"; |
|
191 | - break; |
|
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}')"; |
|
194 | - break; |
|
195 | - case 'invoice_data': |
|
196 | - $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
|
197 | - break; |
|
198 | - case 'invoice_item': |
|
199 | - $prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id"; |
|
200 | - break; |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - if ( $with_parent ) { |
|
205 | - $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
|
206 | - } |
|
207 | - |
|
208 | - return $prepared; |
|
209 | - |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Retrieves the appropriate table key to use. |
|
214 | - * |
|
215 | - * |
|
216 | - * @param string $key |
|
217 | - * @param string $table |
|
218 | - * @return string|false |
|
219 | - */ |
|
220 | - public static function get_invoice_table_key( $key, $table ) { |
|
221 | - |
|
222 | - $keys = array( |
|
223 | - 'meta' => "meta_{$key}.meta_value", |
|
224 | - 'parent_meta' => "parent_meta_{$key}.meta_value", |
|
225 | - 'post_data' => "posts.{$key}", |
|
226 | - 'invoice_data' => "invoices.{$key}", |
|
227 | - 'invoice_item' => "invoice_items.{$key}", |
|
228 | - ); |
|
229 | - |
|
230 | - return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
231 | - |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Executes a query and caches the result for a minute. |
|
236 | - * |
|
237 | - * |
|
238 | - * @param string $query_type |
|
239 | - * @param string $query |
|
240 | - * @return mixed depending on query_type |
|
241 | - */ |
|
242 | - public static function execute( $query_type, $query ) { |
|
243 | - global $wpdb; |
|
244 | - |
|
245 | - $query_hash = md5( $query_type . $query ); |
|
246 | - $result = self::get_cached_query( $query_hash ); |
|
247 | - if ( $result === false ) { |
|
248 | - self::enable_big_selects(); |
|
249 | - |
|
250 | - $result = $wpdb->$query_type( $query ); |
|
251 | - self::set_cached_query( $query_hash, $result ); |
|
252 | - } |
|
253 | - |
|
254 | - return $result; |
|
255 | - |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Enables big mysql selects for reports, just once for this session. |
|
260 | - */ |
|
261 | - protected static function enable_big_selects() { |
|
262 | - static $big_selects = false; |
|
263 | - |
|
264 | - global $wpdb; |
|
265 | - |
|
266 | - if ( ! $big_selects ) { |
|
267 | - $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
268 | - $big_selects = true; |
|
269 | - } |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Get the cached query result or null if it's not in the cache. |
|
274 | - * |
|
275 | - * @param string $query_hash The query hash. |
|
276 | - * |
|
277 | - * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
|
278 | - */ |
|
279 | - protected static function get_cached_query( $query_hash ) { |
|
280 | - |
|
281 | - return wp_cache_get( |
|
282 | - $query_hash, |
|
283 | - strtolower( __CLASS__ ) |
|
284 | - ); |
|
285 | - |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Set the cached query result. |
|
290 | - * |
|
291 | - * @param string $query_hash The query hash. |
|
292 | - * @param mixed $data The data to cache. |
|
293 | - */ |
|
294 | - protected static function set_cached_query( $query_hash, $data ) { |
|
295 | - |
|
296 | - wp_cache_set( |
|
297 | - $query_hash, |
|
298 | - $data, |
|
299 | - strtolower( __CLASS__ ), |
|
300 | - MINUTE_IN_SECONDS |
|
301 | - ); |
|
302 | - |
|
303 | - } |
|
93 | + if ( strtolower( $value['operator'] ) === 'in' || strtolower( $value['operator'] ) === 'not in' ) { |
|
94 | + |
|
95 | + if ( is_array( $value['value'] ) ) { |
|
96 | + $value['value'] = implode( "','", $value['value'] ); |
|
97 | + } |
|
98 | + |
|
99 | + if ( ! empty( $value['value'] ) ) { |
|
100 | + $where_value = "{$value['operator']} ('{$value['value']}')"; |
|
101 | + } |
|
102 | + } else { |
|
103 | + $where_value = "{$value['operator']} '{$value['value']}'"; |
|
104 | + } |
|
105 | + |
|
106 | + if ( ! empty( $where_value ) ) { |
|
107 | + $query['where'] .= " AND {$value['key']} {$where_value}"; |
|
108 | + } |
|
109 | + } |
|
110 | + } |
|
111 | + |
|
112 | + if ( $group_by ) { |
|
113 | + $query['group_by'] = "GROUP BY {$group_by}"; |
|
114 | + } |
|
115 | + |
|
116 | + if ( $order_by ) { |
|
117 | + $query['order_by'] = "ORDER BY {$order_by}"; |
|
118 | + } |
|
119 | + |
|
120 | + if ( $limit ) { |
|
121 | + $query['limit'] = "LIMIT {$limit}"; |
|
122 | + } |
|
123 | + |
|
124 | + $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
125 | + $query = implode( ' ', $query ); |
|
126 | + |
|
127 | + return self::execute( $query_type, $query ); |
|
128 | + |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Prepares the data to select. |
|
133 | + * |
|
134 | + * |
|
135 | + * @param array $data |
|
136 | + * @return array |
|
137 | + */ |
|
138 | + public static function prepare_invoice_data( $data ) { |
|
139 | + |
|
140 | + $prepared = array(); |
|
141 | + |
|
142 | + foreach ( $data as $raw_key => $value ) { |
|
143 | + $key = sanitize_key( $raw_key ); |
|
144 | + $distinct = ''; |
|
145 | + |
|
146 | + if ( isset( $value['distinct'] ) ) { |
|
147 | + $distinct = 'DISTINCT'; |
|
148 | + } |
|
149 | + |
|
150 | + $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
151 | + |
|
152 | + if ( false === $get_key ) { |
|
153 | + // Skip to the next foreach iteration else the query will be invalid. |
|
154 | + continue; |
|
155 | + } |
|
156 | + |
|
157 | + if ( ! empty( $value['function'] ) ) { |
|
158 | + $get = "{$value['function']}({$distinct} {$get_key})"; |
|
159 | + } else { |
|
160 | + $get = "{$distinct} {$get_key}"; |
|
161 | + } |
|
162 | + |
|
163 | + $prepared[] = "{$get} as {$value['name']}"; |
|
164 | + } |
|
165 | + |
|
166 | + return $prepared; |
|
167 | + |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Prepares the joins to use. |
|
172 | + * |
|
173 | + * |
|
174 | + * @param array $data |
|
175 | + * @param bool $with_parent |
|
176 | + * @return array |
|
177 | + */ |
|
178 | + public static function prepare_invoice_joins( $data, $with_parent ) { |
|
179 | + global $wpdb; |
|
180 | + |
|
181 | + $prepared = array(); |
|
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 ); |
|
187 | + |
|
188 | + switch ( $type ) { |
|
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}' )"; |
|
191 | + break; |
|
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}')"; |
|
194 | + break; |
|
195 | + case 'invoice_data': |
|
196 | + $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
|
197 | + break; |
|
198 | + case 'invoice_item': |
|
199 | + $prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id"; |
|
200 | + break; |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + if ( $with_parent ) { |
|
205 | + $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
|
206 | + } |
|
207 | + |
|
208 | + return $prepared; |
|
209 | + |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Retrieves the appropriate table key to use. |
|
214 | + * |
|
215 | + * |
|
216 | + * @param string $key |
|
217 | + * @param string $table |
|
218 | + * @return string|false |
|
219 | + */ |
|
220 | + public static function get_invoice_table_key( $key, $table ) { |
|
221 | + |
|
222 | + $keys = array( |
|
223 | + 'meta' => "meta_{$key}.meta_value", |
|
224 | + 'parent_meta' => "parent_meta_{$key}.meta_value", |
|
225 | + 'post_data' => "posts.{$key}", |
|
226 | + 'invoice_data' => "invoices.{$key}", |
|
227 | + 'invoice_item' => "invoice_items.{$key}", |
|
228 | + ); |
|
229 | + |
|
230 | + return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
231 | + |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Executes a query and caches the result for a minute. |
|
236 | + * |
|
237 | + * |
|
238 | + * @param string $query_type |
|
239 | + * @param string $query |
|
240 | + * @return mixed depending on query_type |
|
241 | + */ |
|
242 | + public static function execute( $query_type, $query ) { |
|
243 | + global $wpdb; |
|
244 | + |
|
245 | + $query_hash = md5( $query_type . $query ); |
|
246 | + $result = self::get_cached_query( $query_hash ); |
|
247 | + if ( $result === false ) { |
|
248 | + self::enable_big_selects(); |
|
249 | + |
|
250 | + $result = $wpdb->$query_type( $query ); |
|
251 | + self::set_cached_query( $query_hash, $result ); |
|
252 | + } |
|
253 | + |
|
254 | + return $result; |
|
255 | + |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Enables big mysql selects for reports, just once for this session. |
|
260 | + */ |
|
261 | + protected static function enable_big_selects() { |
|
262 | + static $big_selects = false; |
|
263 | + |
|
264 | + global $wpdb; |
|
265 | + |
|
266 | + if ( ! $big_selects ) { |
|
267 | + $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
268 | + $big_selects = true; |
|
269 | + } |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Get the cached query result or null if it's not in the cache. |
|
274 | + * |
|
275 | + * @param string $query_hash The query hash. |
|
276 | + * |
|
277 | + * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
|
278 | + */ |
|
279 | + protected static function get_cached_query( $query_hash ) { |
|
280 | + |
|
281 | + return wp_cache_get( |
|
282 | + $query_hash, |
|
283 | + strtolower( __CLASS__ ) |
|
284 | + ); |
|
285 | + |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Set the cached query result. |
|
290 | + * |
|
291 | + * @param string $query_hash The query hash. |
|
292 | + * @param mixed $data The data to cache. |
|
293 | + */ |
|
294 | + protected static function set_cached_query( $query_hash, $data ) { |
|
295 | + |
|
296 | + wp_cache_set( |
|
297 | + $query_hash, |
|
298 | + $data, |
|
299 | + strtolower( __CLASS__ ), |
|
300 | + MINUTE_IN_SECONDS |
|
301 | + ); |
|
302 | + |
|
303 | + } |
|
304 | 304 | |
305 | 305 | } |
@@ -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 |
@@ -39,62 +39,62 @@ discard block |
||
39 | 39 | <td style="width: 65%"> |
40 | 40 | <?php |
41 | 41 | |
42 | - switch ( $key ) { |
|
42 | + switch ( $key ) { |
|
43 | 43 | |
44 | - case 'status': |
|
45 | - echo esc_html( $subscription->get_status_label() ); |
|
46 | - break; |
|
44 | + case 'status': |
|
45 | + echo esc_html( $subscription->get_status_label() ); |
|
46 | + break; |
|
47 | 47 | |
48 | - case 'start_date': |
|
49 | - echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
50 | - break; |
|
48 | + case 'start_date': |
|
49 | + echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
50 | + break; |
|
51 | 51 | |
52 | - case 'expiry_date': |
|
53 | - echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
54 | - break; |
|
52 | + case 'expiry_date': |
|
53 | + echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
54 | + break; |
|
55 | 55 | |
56 | - case 'initial_amount': |
|
57 | - echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) ); |
|
56 | + case 'initial_amount': |
|
57 | + echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) ); |
|
58 | 58 | |
59 | - if ( $subscription->has_trial_period() ) { |
|
59 | + if ( $subscription->has_trial_period() ) { |
|
60 | 60 | |
61 | - echo "<small class='text-muted'> "; |
|
62 | - printf( |
|
63 | - esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
64 | - esc_html( $subscription->get_trial_period() ) |
|
65 | - ); |
|
66 | - echo '</small>'; |
|
61 | + echo "<small class='text-muted'> "; |
|
62 | + printf( |
|
63 | + esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
64 | + esc_html( $subscription->get_trial_period() ) |
|
65 | + ); |
|
66 | + echo '</small>'; |
|
67 | 67 | |
68 | - } |
|
68 | + } |
|
69 | 69 | |
70 | - break; |
|
70 | + break; |
|
71 | 71 | |
72 | - case 'recurring_amount': |
|
73 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
74 | - $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
75 | - echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) ); |
|
76 | - break; |
|
72 | + case 'recurring_amount': |
|
73 | + $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
74 | + $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
75 | + echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) ); |
|
76 | + break; |
|
77 | 77 | |
78 | - case 'item': |
|
79 | - if ( empty( $subscription_group ) ) { |
|
80 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
81 | - } else { |
|
82 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
83 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
84 | - } |
|
78 | + case 'item': |
|
79 | + if ( empty( $subscription_group ) ) { |
|
80 | + echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
81 | + } else { |
|
82 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
83 | + echo wp_kses_post( implode( ' | ', $markup ) ); |
|
84 | + } |
|
85 | 85 | |
86 | - break; |
|
86 | + break; |
|
87 | 87 | |
88 | - case 'payments': |
|
89 | - $max_activations = (int) $subscription->get_bill_times(); |
|
90 | - echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '∞' : (int) $max_activations ); |
|
88 | + case 'payments': |
|
89 | + $max_activations = (int) $subscription->get_bill_times(); |
|
90 | + echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '∞' : (int) $max_activations ); |
|
91 | 91 | |
92 | - break; |
|
92 | + break; |
|
93 | 93 | |
94 | - } |
|
95 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
94 | + } |
|
95 | + do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
96 | 96 | |
97 | - ?> |
|
97 | + ?> |
|
98 | 98 | </td> |
99 | 99 | |
100 | 100 | </tr> |
@@ -121,17 +121,17 @@ discard block |
||
121 | 121 | <span class="form-text"> |
122 | 122 | |
123 | 123 | <?php |
124 | - if ( $subscription->can_cancel() ) { |
|
125 | - printf( |
|
124 | + if ( $subscription->can_cancel() ) { |
|
125 | + printf( |
|
126 | 126 | '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
127 | 127 | esc_url( $subscription->get_cancel_url() ), |
128 | 128 | esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
129 | 129 | esc_html__( 'Cancel Subscription', 'invoicing' ) |
130 | 130 | ); |
131 | - } |
|
131 | + } |
|
132 | 132 | |
133 | - do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
134 | - ?> |
|
133 | + do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
134 | + ?> |
|
135 | 135 | |
136 | 136 | <a href="<?php echo esc_url( getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); ?>" class="btn btn-secondary btn-sm"><?php esc_html_e( 'Go Back', 'invoicing' ); ?></a> |
137 | 137 | </span> |
@@ -41,55 +41,55 @@ |
||
41 | 41 | |
42 | 42 | switch ( $key ) { |
43 | 43 | |
44 | - case 'status': |
|
45 | - echo esc_html( $subscription->get_status_label() ); |
|
46 | - break; |
|
44 | + case 'status': |
|
45 | + echo esc_html( $subscription->get_status_label() ); |
|
46 | + break; |
|
47 | 47 | |
48 | - case 'start_date': |
|
49 | - echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
50 | - break; |
|
48 | + case 'start_date': |
|
49 | + echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
50 | + break; |
|
51 | 51 | |
52 | - case 'expiry_date': |
|
53 | - echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
54 | - break; |
|
52 | + case 'expiry_date': |
|
53 | + echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
54 | + break; |
|
55 | 55 | |
56 | - case 'initial_amount': |
|
57 | - echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) ); |
|
56 | + case 'initial_amount': |
|
57 | + echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) ); |
|
58 | 58 | |
59 | - if ( $subscription->has_trial_period() ) { |
|
59 | + if ( $subscription->has_trial_period() ) { |
|
60 | 60 | |
61 | - echo "<small class='text-muted'> "; |
|
62 | - printf( |
|
63 | - esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
64 | - esc_html( $subscription->get_trial_period() ) |
|
65 | - ); |
|
66 | - echo '</small>'; |
|
61 | + echo "<small class='text-muted'> "; |
|
62 | + printf( |
|
63 | + esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
64 | + esc_html( $subscription->get_trial_period() ) |
|
65 | + ); |
|
66 | + echo '</small>'; |
|
67 | 67 | |
68 | - } |
|
68 | + } |
|
69 | 69 | |
70 | - break; |
|
70 | + break; |
|
71 | 71 | |
72 | - case 'recurring_amount': |
|
73 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
74 | - $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
75 | - echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) ); |
|
76 | - break; |
|
72 | + case 'recurring_amount': |
|
73 | + $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
74 | + $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
75 | + echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) ); |
|
76 | + break; |
|
77 | 77 | |
78 | - case 'item': |
|
79 | - if ( empty( $subscription_group ) ) { |
|
80 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
81 | - } else { |
|
82 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
83 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
84 | - } |
|
78 | + case 'item': |
|
79 | + if ( empty( $subscription_group ) ) { |
|
80 | + echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
81 | + } else { |
|
82 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
83 | + echo wp_kses_post( implode( ' | ', $markup ) ); |
|
84 | + } |
|
85 | 85 | |
86 | - break; |
|
86 | + break; |
|
87 | 87 | |
88 | - case 'payments': |
|
89 | - $max_activations = (int) $subscription->get_bill_times(); |
|
90 | - echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '∞' : (int) $max_activations ); |
|
88 | + case 'payments': |
|
89 | + $max_activations = (int) $subscription->get_bill_times(); |
|
90 | + echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '∞' : (int) $max_activations ); |
|
91 | 91 | |
92 | - break; |
|
92 | + break; |
|
93 | 93 | |
94 | 94 | } |
95 | 95 | do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
@@ -10,58 +10,58 @@ discard block |
||
10 | 10 | * @var WPInv_Subscriptions_Widget $widget |
11 | 11 | */ |
12 | 12 | |
13 | -defined( 'ABSPATH' ) || exit; |
|
13 | +defined('ABSPATH') || exit; |
|
14 | 14 | |
15 | -do_action( 'getpaid_single_subscription_before_notices', $subscription ); |
|
15 | +do_action('getpaid_single_subscription_before_notices', $subscription); |
|
16 | 16 | |
17 | 17 | // Display errors and notices. |
18 | 18 | wpinv_print_errors(); |
19 | 19 | |
20 | -$subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_invoice_id() ); |
|
21 | -$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
20 | +$subscription_groups = getpaid_get_invoice_subscription_groups($subscription->get_parent_invoice_id()); |
|
21 | +$subscription_group = getpaid_get_invoice_subscription_group($subscription->get_parent_invoice_id(), $subscription->get_id()); |
|
22 | 22 | |
23 | -do_action( 'getpaid_before_single_subscription', $subscription, $subscription_groups ); |
|
23 | +do_action('getpaid_before_single_subscription', $subscription, $subscription_groups); |
|
24 | 24 | |
25 | 25 | ?> |
26 | 26 | |
27 | -<h2 class="mb-1 h4"><?php esc_html_e( 'Subscription Details', 'invoicing' ); ?></h2> |
|
27 | +<h2 class="mb-1 h4"><?php esc_html_e('Subscription Details', 'invoicing'); ?></h2> |
|
28 | 28 | <table class="table table-bordered"> |
29 | 29 | <tbody> |
30 | 30 | |
31 | - <?php foreach ( $widget->get_single_subscription_columns( $subscription ) as $key => $label ) : ?> |
|
31 | + <?php foreach ($widget->get_single_subscription_columns($subscription) as $key => $label) : ?> |
|
32 | 32 | |
33 | - <tr class="getpaid-subscription-meta-<?php echo esc_attr( $key ); ?>"> |
|
33 | + <tr class="getpaid-subscription-meta-<?php echo esc_attr($key); ?>"> |
|
34 | 34 | |
35 | 35 | <th class="font-weight-bold" style="width: 35%"> |
36 | - <?php echo esc_html( $label ); ?> |
|
36 | + <?php echo esc_html($label); ?> |
|
37 | 37 | </th> |
38 | 38 | |
39 | 39 | <td style="width: 65%"> |
40 | 40 | <?php |
41 | 41 | |
42 | - switch ( $key ) { |
|
42 | + switch ($key) { |
|
43 | 43 | |
44 | 44 | case 'status': |
45 | - echo esc_html( $subscription->get_status_label() ); |
|
45 | + echo esc_html($subscription->get_status_label()); |
|
46 | 46 | break; |
47 | 47 | |
48 | 48 | case 'start_date': |
49 | - echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
49 | + echo esc_html(getpaid_format_date_value($subscription->get_date_created())); |
|
50 | 50 | break; |
51 | 51 | |
52 | 52 | case 'expiry_date': |
53 | - echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
53 | + echo esc_html(getpaid_format_date_value($subscription->get_next_renewal_date())); |
|
54 | 54 | break; |
55 | 55 | |
56 | 56 | case 'initial_amount': |
57 | - echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) ); |
|
57 | + echo wp_kses_post(wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency())); |
|
58 | 58 | |
59 | - if ( $subscription->has_trial_period() ) { |
|
59 | + if ($subscription->has_trial_period()) { |
|
60 | 60 | |
61 | 61 | echo "<small class='text-muted'> "; |
62 | 62 | printf( |
63 | - esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
64 | - esc_html( $subscription->get_trial_period() ) |
|
63 | + esc_html_x('( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing'), |
|
64 | + esc_html($subscription->get_trial_period()) |
|
65 | 65 | ); |
66 | 66 | echo '</small>'; |
67 | 67 | |
@@ -70,29 +70,29 @@ discard block |
||
70 | 70 | break; |
71 | 71 | |
72 | 72 | case 'recurring_amount': |
73 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
74 | - $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
75 | - echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) ); |
|
73 | + $frequency = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''); |
|
74 | + $amount = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency()); |
|
75 | + echo wp_kses_post(strtolower("<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>")); |
|
76 | 76 | break; |
77 | 77 | |
78 | 78 | case 'item': |
79 | - if ( empty( $subscription_group ) ) { |
|
80 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
79 | + if (empty($subscription_group)) { |
|
80 | + echo wp_kses_post(WPInv_Subscriptions_List_Table::generate_item_markup($subscription->get_product_id())); |
|
81 | 81 | } else { |
82 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
83 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
82 | + $markup = array_map(array('WPInv_Subscriptions_List_Table', 'generate_item_markup'), array_keys($subscription_group['items'])); |
|
83 | + echo wp_kses_post(implode(' | ', $markup)); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | break; |
87 | 87 | |
88 | 88 | case 'payments': |
89 | 89 | $max_activations = (int) $subscription->get_bill_times(); |
90 | - echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '∞' : (int) $max_activations ); |
|
90 | + echo ((int) $subscription->get_times_billed()) . ' / ' . (empty($max_activations) ? '∞' : (int) $max_activations); |
|
91 | 91 | |
92 | 92 | break; |
93 | 93 | |
94 | 94 | } |
95 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
95 | + do_action("getpaid_render_single_subscription_column_$key", $subscription); |
|
96 | 96 | |
97 | 97 | ?> |
98 | 98 | </td> |
@@ -104,34 +104,34 @@ discard block |
||
104 | 104 | </tbody> |
105 | 105 | </table> |
106 | 106 | |
107 | -<?php if ( ! empty( $subscription_group ) ) : ?> |
|
108 | - <h2 class='mt-5 mb-1 h4'><?php esc_html_e( 'Subscription Items', 'invoicing' ); ?></h2> |
|
109 | - <?php getpaid_admin_subscription_item_details_metabox( $subscription ); ?> |
|
107 | +<?php if (!empty($subscription_group)) : ?> |
|
108 | + <h2 class='mt-5 mb-1 h4'><?php esc_html_e('Subscription Items', 'invoicing'); ?></h2> |
|
109 | + <?php getpaid_admin_subscription_item_details_metabox($subscription); ?> |
|
110 | 110 | <?php endif; ?> |
111 | 111 | |
112 | -<h2 class='mt-5 mb-1 h4'><?php esc_html_e( 'Related Invoices', 'invoicing' ); ?></h2> |
|
112 | +<h2 class='mt-5 mb-1 h4'><?php esc_html_e('Related Invoices', 'invoicing'); ?></h2> |
|
113 | 113 | |
114 | -<?php ob_start();getpaid_admin_subscription_invoice_details_metabox( $subscription ); $invoice_details = ob_get_clean(); echo wp_kses_post( $invoice_details ); ?> |
|
114 | +<?php ob_start(); getpaid_admin_subscription_invoice_details_metabox($subscription); $invoice_details = ob_get_clean(); echo wp_kses_post($invoice_details); ?> |
|
115 | 115 | |
116 | -<?php if ( 1 < count( $subscription_groups ) ) : ?> |
|
117 | - <h2 class='mt-5 mb-1 h4'><?php esc_html_e( 'Related Subscriptions', 'invoicing' ); ?></h2> |
|
118 | - <?php getpaid_admin_subscription_related_subscriptions_metabox( $subscription ); ?> |
|
116 | +<?php if (1 < count($subscription_groups)) : ?> |
|
117 | + <h2 class='mt-5 mb-1 h4'><?php esc_html_e('Related Subscriptions', 'invoicing'); ?></h2> |
|
118 | + <?php getpaid_admin_subscription_related_subscriptions_metabox($subscription); ?> |
|
119 | 119 | <?php endif; ?> |
120 | 120 | |
121 | 121 | <span class="form-text"> |
122 | 122 | |
123 | 123 | <?php |
124 | - if ( $subscription->can_cancel() ) { |
|
124 | + if ($subscription->can_cancel()) { |
|
125 | 125 | printf( |
126 | 126 | '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
127 | - esc_url( $subscription->get_cancel_url() ), |
|
128 | - esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
129 | - esc_html__( 'Cancel Subscription', 'invoicing' ) |
|
127 | + esc_url($subscription->get_cancel_url()), |
|
128 | + esc_attr__('Are you sure you want to cancel this subscription?', 'invoicing'), |
|
129 | + esc_html__('Cancel Subscription', 'invoicing') |
|
130 | 130 | ); |
131 | 131 | } |
132 | 132 | |
133 | - do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
133 | + do_action('getpaid-single-subscription-page-actions', $subscription); |
|
134 | 134 | ?> |
135 | 135 | |
136 | - <a href="<?php echo esc_url( getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); ?>" class="btn btn-secondary btn-sm"><?php esc_html_e( 'Go Back', 'invoicing' ); ?></a> |
|
136 | + <a href="<?php echo esc_url(getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page')))); ?>" class="btn btn-secondary btn-sm"><?php esc_html_e('Go Back', 'invoicing'); ?></a> |
|
137 | 137 | </span> |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -16,85 +16,85 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class GetPaid_Meta_Box_Invoice_Address { |
18 | 18 | |
19 | - /** |
|
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
24 | - public static function output( $post ) { |
|
25 | - |
|
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' ); |
|
32 | - |
|
33 | - // Address fields. |
|
34 | - $address_fields = array( |
|
35 | - 'first_name' => array( |
|
36 | - 'label' => __( 'First Name', 'invoicing' ), |
|
37 | - 'type' => 'text', |
|
38 | - ), |
|
39 | - 'last_name' => array( |
|
40 | - 'label' => __( 'Last Name', 'invoicing' ), |
|
41 | - 'type' => 'text', |
|
42 | - ), |
|
43 | - 'company' => array( |
|
44 | - 'label' => __( 'Company', 'invoicing' ), |
|
45 | - 'type' => 'text', |
|
46 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
47 | - ), |
|
48 | - 'vat_number' => array( |
|
49 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
50 | - 'type' => 'text', |
|
51 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
52 | - ), |
|
53 | - 'address' => array( |
|
54 | - 'label' => __( 'Address', 'invoicing' ), |
|
55 | - 'type' => 'text', |
|
56 | - ), |
|
57 | - 'city' => array( |
|
58 | - 'label' => __( 'City', 'invoicing' ), |
|
59 | - 'type' => 'text', |
|
60 | - ), |
|
61 | - 'country' => array( |
|
62 | - 'label' => __( 'Country', 'invoicing' ), |
|
63 | - 'type' => 'select', |
|
64 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
65 | - 'options' => wpinv_get_country_list(), |
|
66 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
67 | - ), |
|
68 | - 'state' => array( |
|
69 | - 'label' => __( 'State', 'invoicing' ), |
|
70 | - 'type' => 'text', |
|
71 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
72 | - ), |
|
73 | - 'zip' => array( |
|
74 | - 'label' => __( 'Zip', 'invoicing' ), |
|
75 | - 'type' => 'text', |
|
76 | - ), |
|
77 | - 'phone' => array( |
|
78 | - 'label' => __( 'Phone', 'invoicing' ), |
|
79 | - 'type' => 'text', |
|
80 | - ), |
|
81 | - ); |
|
82 | - |
|
83 | - $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) ); |
|
84 | - |
|
85 | - if ( ! empty( $states ) ) { |
|
86 | - $address_fields['state']['type'] = 'select'; |
|
87 | - $address_fields['state']['options'] = $states; |
|
88 | - $address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' ); |
|
89 | - } |
|
90 | - |
|
91 | - // Maybe remove the VAT field. |
|
92 | - if ( ! wpinv_use_taxes() ) { |
|
93 | - unset( $address_fields['vat_number'] ); |
|
94 | - } |
|
95 | - |
|
96 | - $address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice ); |
|
97 | - ?> |
|
19 | + /** |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | + public static function output( $post ) { |
|
25 | + |
|
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' ); |
|
32 | + |
|
33 | + // Address fields. |
|
34 | + $address_fields = array( |
|
35 | + 'first_name' => array( |
|
36 | + 'label' => __( 'First Name', 'invoicing' ), |
|
37 | + 'type' => 'text', |
|
38 | + ), |
|
39 | + 'last_name' => array( |
|
40 | + 'label' => __( 'Last Name', 'invoicing' ), |
|
41 | + 'type' => 'text', |
|
42 | + ), |
|
43 | + 'company' => array( |
|
44 | + 'label' => __( 'Company', 'invoicing' ), |
|
45 | + 'type' => 'text', |
|
46 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
47 | + ), |
|
48 | + 'vat_number' => array( |
|
49 | + 'label' => __( 'VAT Number', 'invoicing' ), |
|
50 | + 'type' => 'text', |
|
51 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
52 | + ), |
|
53 | + 'address' => array( |
|
54 | + 'label' => __( 'Address', 'invoicing' ), |
|
55 | + 'type' => 'text', |
|
56 | + ), |
|
57 | + 'city' => array( |
|
58 | + 'label' => __( 'City', 'invoicing' ), |
|
59 | + 'type' => 'text', |
|
60 | + ), |
|
61 | + 'country' => array( |
|
62 | + 'label' => __( 'Country', 'invoicing' ), |
|
63 | + 'type' => 'select', |
|
64 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
65 | + 'options' => wpinv_get_country_list(), |
|
66 | + 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
67 | + ), |
|
68 | + 'state' => array( |
|
69 | + 'label' => __( 'State', 'invoicing' ), |
|
70 | + 'type' => 'text', |
|
71 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
72 | + ), |
|
73 | + 'zip' => array( |
|
74 | + 'label' => __( 'Zip', 'invoicing' ), |
|
75 | + 'type' => 'text', |
|
76 | + ), |
|
77 | + 'phone' => array( |
|
78 | + 'label' => __( 'Phone', 'invoicing' ), |
|
79 | + 'type' => 'text', |
|
80 | + ), |
|
81 | + ); |
|
82 | + |
|
83 | + $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) ); |
|
84 | + |
|
85 | + if ( ! empty( $states ) ) { |
|
86 | + $address_fields['state']['type'] = 'select'; |
|
87 | + $address_fields['state']['options'] = $states; |
|
88 | + $address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' ); |
|
89 | + } |
|
90 | + |
|
91 | + // Maybe remove the VAT field. |
|
92 | + if ( ! wpinv_use_taxes() ) { |
|
93 | + unset( $address_fields['vat_number'] ); |
|
94 | + } |
|
95 | + |
|
96 | + $address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice ); |
|
97 | + ?> |
|
98 | 98 | |
99 | 99 | <style> |
100 | 100 | #wpinv-address label { |
@@ -119,19 +119,19 @@ discard block |
||
119 | 119 | <div id="getpaid-invoice-email-wrapper" class="d-none"> |
120 | 120 | <input type="hidden" id="getpaid-invoice-create-new-user" name="wpinv_new_user" value="" /> |
121 | 121 | <?php |
122 | - aui()->input( |
|
123 | - array( |
|
124 | - 'type' => 'text', |
|
125 | - 'id' => 'getpaid-invoice-new-user-email', |
|
126 | - 'name' => 'wpinv_email', |
|
127 | - 'label' => __( 'Email', 'invoicing' ) . '<span class="required">*</span>', |
|
128 | - 'label_type' => 'vertical', |
|
129 | - 'placeholder' => '[email protected]', |
|
130 | - 'class' => 'form-control-sm', |
|
131 | - ), |
|
132 | - true |
|
133 | - ); |
|
134 | - ?> |
|
122 | + aui()->input( |
|
123 | + array( |
|
124 | + 'type' => 'text', |
|
125 | + 'id' => 'getpaid-invoice-new-user-email', |
|
126 | + 'name' => 'wpinv_email', |
|
127 | + 'label' => __( 'Email', 'invoicing' ) . '<span class="required">*</span>', |
|
128 | + 'label_type' => 'vertical', |
|
129 | + 'placeholder' => '[email protected]', |
|
130 | + 'class' => 'form-control-sm', |
|
131 | + ), |
|
132 | + true |
|
133 | + ); |
|
134 | + ?> |
|
135 | 135 | </div> |
136 | 136 | </div> |
137 | 137 | <div class="col-12 col-sm-6 form-group mb-3 mt-sm-4"> |
@@ -155,39 +155,39 @@ discard block |
||
155 | 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'] ) { |
|
159 | - aui()->select( |
|
160 | - array( |
|
161 | - 'id' => 'wpinv_' . $key, |
|
162 | - 'name' => 'wpinv_' . $key, |
|
163 | - 'label' => $field['label'], |
|
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' ), |
|
168 | - 'options' => $field['options'], |
|
169 | - 'data-allow-clear' => 'false', |
|
170 | - 'select2' => true, |
|
171 | - ), |
|
172 | - true |
|
173 | - ); |
|
174 | - } else { |
|
175 | - aui()->input( |
|
176 | - array( |
|
177 | - 'type' => $field['type'], |
|
178 | - 'id' => 'wpinv_' . $key, |
|
179 | - 'name' => 'wpinv_' . $key, |
|
180 | - 'label' => $field['label'], |
|
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' ), |
|
185 | - ), |
|
186 | - true |
|
187 | - ); |
|
188 | - } |
|
189 | - |
|
190 | - ?> |
|
158 | + if ( 'select' === $field['type'] ) { |
|
159 | + aui()->select( |
|
160 | + array( |
|
161 | + 'id' => 'wpinv_' . $key, |
|
162 | + 'name' => 'wpinv_' . $key, |
|
163 | + 'label' => $field['label'], |
|
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' ), |
|
168 | + 'options' => $field['options'], |
|
169 | + 'data-allow-clear' => 'false', |
|
170 | + 'select2' => true, |
|
171 | + ), |
|
172 | + true |
|
173 | + ); |
|
174 | + } else { |
|
175 | + aui()->input( |
|
176 | + array( |
|
177 | + 'type' => $field['type'], |
|
178 | + 'id' => 'wpinv_' . $key, |
|
179 | + 'name' => 'wpinv_' . $key, |
|
180 | + 'label' => $field['label'], |
|
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' ), |
|
185 | + ), |
|
186 | + true |
|
187 | + ); |
|
188 | + } |
|
189 | + |
|
190 | + ?> |
|
191 | 191 | </div> |
192 | 192 | <?php endforeach; ?> |
193 | 193 | </div> |
@@ -198,48 +198,48 @@ discard block |
||
198 | 198 | <div class="row"> |
199 | 199 | <div class="col-12 col-sm-6"> |
200 | 200 | <?php |
201 | - aui()->select( |
|
202 | - array( |
|
203 | - 'id' => 'wpinv_template', |
|
204 | - 'name' => 'wpinv_template', |
|
205 | - 'label' => __( 'Template', 'invoicing' ), |
|
206 | - 'label_type' => 'vertical', |
|
207 | - 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
208 | - 'class' => 'form-control-sm', |
|
209 | - 'value' => $invoice->get_template( 'edit' ), |
|
210 | - 'options' => array( |
|
211 | - 'quantity' => __( 'Quantity', 'invoicing' ), |
|
212 | - 'hours' => __( 'Hours', 'invoicing' ), |
|
213 | - ), |
|
214 | - 'data-allow-clear' => 'false', |
|
215 | - 'select2' => true, |
|
216 | - ), |
|
217 | - true |
|
218 | - ); |
|
219 | - ?> |
|
201 | + aui()->select( |
|
202 | + array( |
|
203 | + 'id' => 'wpinv_template', |
|
204 | + 'name' => 'wpinv_template', |
|
205 | + 'label' => __( 'Template', 'invoicing' ), |
|
206 | + 'label_type' => 'vertical', |
|
207 | + 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
208 | + 'class' => 'form-control-sm', |
|
209 | + 'value' => $invoice->get_template( 'edit' ), |
|
210 | + 'options' => array( |
|
211 | + 'quantity' => __( 'Quantity', 'invoicing' ), |
|
212 | + 'hours' => __( 'Hours', 'invoicing' ), |
|
213 | + ), |
|
214 | + 'data-allow-clear' => 'false', |
|
215 | + 'select2' => true, |
|
216 | + ), |
|
217 | + true |
|
218 | + ); |
|
219 | + ?> |
|
220 | 220 | </div> |
221 | 221 | <div class="col-12 col-sm-6"> |
222 | 222 | <?php |
223 | 223 | |
224 | - // Set currency. |
|
225 | - aui()->select( |
|
226 | - array( |
|
227 | - 'id' => 'wpinv_currency', |
|
228 | - 'name' => 'wpinv_currency', |
|
229 | - 'label' => __( 'Currency', 'invoicing' ), |
|
230 | - 'label_type' => 'vertical', |
|
231 | - 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
232 | - 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
|
233 | - 'value' => $invoice->get_currency( 'edit' ), |
|
234 | - 'required' => false, |
|
235 | - 'data-allow-clear' => 'false', |
|
236 | - 'select2' => true, |
|
237 | - 'options' => wpinv_get_currencies(), |
|
238 | - ), |
|
239 | - true |
|
240 | - ); |
|
241 | - |
|
242 | - ?> |
|
224 | + // Set currency. |
|
225 | + aui()->select( |
|
226 | + array( |
|
227 | + 'id' => 'wpinv_currency', |
|
228 | + 'name' => 'wpinv_currency', |
|
229 | + 'label' => __( 'Currency', 'invoicing' ), |
|
230 | + 'label_type' => 'vertical', |
|
231 | + 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
232 | + 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
|
233 | + 'value' => $invoice->get_currency( 'edit' ), |
|
234 | + 'required' => false, |
|
235 | + 'data-allow-clear' => 'false', |
|
236 | + 'select2' => true, |
|
237 | + 'options' => wpinv_get_currencies(), |
|
238 | + ), |
|
239 | + true |
|
240 | + ); |
|
241 | + |
|
242 | + ?> |
|
243 | 243 | </div> |
244 | 244 | </div> |
245 | 245 | |
@@ -249,123 +249,123 @@ discard block |
||
249 | 249 | <div class="row"> |
250 | 250 | <div class="col-12 col-sm-6"> |
251 | 251 | <?php |
252 | - aui()->input( |
|
253 | - array( |
|
254 | - 'type' => 'text', |
|
255 | - 'id' => 'wpinv_company_id', |
|
256 | - 'name' => 'wpinv_company_id', |
|
257 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
258 | - 'label_type' => 'vertical', |
|
259 | - 'placeholder' => '', |
|
260 | - 'class' => 'form-control-sm', |
|
261 | - 'value' => $invoice->get_company_id( 'edit' ), |
|
262 | - ), |
|
263 | - true |
|
264 | - ); |
|
265 | - ?> |
|
252 | + aui()->input( |
|
253 | + array( |
|
254 | + 'type' => 'text', |
|
255 | + 'id' => 'wpinv_company_id', |
|
256 | + 'name' => 'wpinv_company_id', |
|
257 | + 'label' => __( 'Company ID', 'invoicing' ), |
|
258 | + 'label_type' => 'vertical', |
|
259 | + 'placeholder' => '', |
|
260 | + 'class' => 'form-control-sm', |
|
261 | + 'value' => $invoice->get_company_id( 'edit' ), |
|
262 | + ), |
|
263 | + true |
|
264 | + ); |
|
265 | + ?> |
|
266 | 266 | </div> |
267 | 267 | </div> |
268 | 268 | |
269 | 269 | <?php do_action( 'getpaid_after_metabox_invoice_address', $invoice ); ?> |
270 | 270 | </div> |
271 | 271 | <?php |
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Save meta box data. |
|
276 | - * |
|
277 | - * @param int $post_id |
|
278 | - * @param array $posted the posted data. |
|
279 | - */ |
|
280 | - public static function save( $post_id, $posted ) { |
|
281 | - |
|
282 | - // Prepare the invoice. |
|
283 | - $invoice = new WPInv_Invoice( $post_id ); |
|
284 | - |
|
285 | - // Load new data. |
|
286 | - $invoice->set_props( |
|
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, |
|
310 | - ) |
|
311 | - ); |
|
312 | - |
|
313 | - // Discount code. |
|
314 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
315 | - |
|
316 | - if ( isset( $posted['wpinv_discount_code'] ) ) { |
|
317 | - $invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) ); |
|
318 | - } |
|
319 | - |
|
320 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
321 | - if ( $discount->exists() ) { |
|
322 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
323 | - } else { |
|
324 | - $invoice->remove_discount( 'discount_code' ); |
|
325 | - } |
|
326 | - |
|
327 | - // Recalculate totals. |
|
328 | - $invoice->recalculate_total(); |
|
329 | - |
|
330 | - } |
|
331 | - |
|
332 | - // If we're creating a new user... |
|
333 | - if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) { |
|
334 | - |
|
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() ); |
|
337 | - |
|
338 | - // If successful, update the invoice author. |
|
339 | - if ( is_numeric( $user ) ) { |
|
340 | - $invoice->set_author( $user ); |
|
341 | - } else { |
|
342 | - wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ ); |
|
343 | - } |
|
344 | - } |
|
345 | - |
|
346 | - // Do not send new invoice notifications. |
|
347 | - $GLOBALS['wpinv_skip_invoice_notification'] = true; |
|
348 | - |
|
349 | - // Save the invoice. |
|
350 | - $invoice->save(); |
|
351 | - |
|
352 | - // Save the user address. |
|
353 | - getpaid_save_invoice_user_address( $invoice ); |
|
354 | - |
|
355 | - // Undo do not send new invoice notifications. |
|
356 | - $GLOBALS['wpinv_skip_invoice_notification'] = false; |
|
357 | - |
|
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' ); |
|
362 | - } |
|
363 | - |
|
364 | - if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) { |
|
365 | - getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true ); |
|
366 | - } |
|
367 | - |
|
368 | - // Fires after an invoice is saved. |
|
369 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
370 | - } |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Save meta box data. |
|
276 | + * |
|
277 | + * @param int $post_id |
|
278 | + * @param array $posted the posted data. |
|
279 | + */ |
|
280 | + public static function save( $post_id, $posted ) { |
|
281 | + |
|
282 | + // Prepare the invoice. |
|
283 | + $invoice = new WPInv_Invoice( $post_id ); |
|
284 | + |
|
285 | + // Load new data. |
|
286 | + $invoice->set_props( |
|
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, |
|
310 | + ) |
|
311 | + ); |
|
312 | + |
|
313 | + // Discount code. |
|
314 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
315 | + |
|
316 | + if ( isset( $posted['wpinv_discount_code'] ) ) { |
|
317 | + $invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) ); |
|
318 | + } |
|
319 | + |
|
320 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
321 | + if ( $discount->exists() ) { |
|
322 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
323 | + } else { |
|
324 | + $invoice->remove_discount( 'discount_code' ); |
|
325 | + } |
|
326 | + |
|
327 | + // Recalculate totals. |
|
328 | + $invoice->recalculate_total(); |
|
329 | + |
|
330 | + } |
|
331 | + |
|
332 | + // If we're creating a new user... |
|
333 | + if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) { |
|
334 | + |
|
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() ); |
|
337 | + |
|
338 | + // If successful, update the invoice author. |
|
339 | + if ( is_numeric( $user ) ) { |
|
340 | + $invoice->set_author( $user ); |
|
341 | + } else { |
|
342 | + wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ ); |
|
343 | + } |
|
344 | + } |
|
345 | + |
|
346 | + // Do not send new invoice notifications. |
|
347 | + $GLOBALS['wpinv_skip_invoice_notification'] = true; |
|
348 | + |
|
349 | + // Save the invoice. |
|
350 | + $invoice->save(); |
|
351 | + |
|
352 | + // Save the user address. |
|
353 | + getpaid_save_invoice_user_address( $invoice ); |
|
354 | + |
|
355 | + // Undo do not send new invoice notifications. |
|
356 | + $GLOBALS['wpinv_skip_invoice_notification'] = false; |
|
357 | + |
|
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' ); |
|
362 | + } |
|
363 | + |
|
364 | + if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) { |
|
365 | + getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true ); |
|
366 | + } |
|
367 | + |
|
368 | + // Fires after an invoice is saved. |
|
369 | + do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
370 | + } |
|
371 | 371 | } |
@@ -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 | } |
@@ -128,7 +128,7 @@ |
||
128 | 128 | |
129 | 129 | if( !$version || version_compare($version,'5.999','>')){ |
130 | 130 | $url .= 'assets/js/fa-iconpicker-v6.min.js'; |
131 | - }else{ |
|
131 | + } else{ |
|
132 | 132 | $url .= 'assets/js/fa-iconpicker-v5.min.js'; |
133 | 133 | } |
134 | 134 |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -21,414 +21,414 @@ discard block |
||
21 | 21 | */ |
22 | 22 | if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
23 | 23 | |
24 | - /** |
|
25 | - * A Class to be able to change settings for Font Awesome. |
|
26 | - * |
|
27 | - * Class WP_Font_Awesome_Settings |
|
28 | - */ |
|
29 | - class WP_Font_Awesome_Settings { |
|
30 | - |
|
31 | - /** |
|
32 | - * Class version version. |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $version = '1.1.10'; |
|
37 | - |
|
38 | - /** |
|
39 | - * Class textdomain. |
|
40 | - * |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - public $textdomain = 'font-awesome-settings'; |
|
44 | - |
|
45 | - /** |
|
46 | - * Latest version of Font Awesome at time of publish published. |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - public $latest = "6.4.2"; |
|
51 | - |
|
52 | - /** |
|
53 | - * The title. |
|
54 | - * |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - public $name = 'Font Awesome'; |
|
58 | - |
|
59 | - /** |
|
60 | - * Holds the settings values. |
|
61 | - * |
|
62 | - * @var array |
|
63 | - */ |
|
64 | - private $settings; |
|
65 | - |
|
66 | - /** |
|
67 | - * WP_Font_Awesome_Settings instance. |
|
68 | - * |
|
69 | - * @access private |
|
70 | - * @since 1.0.0 |
|
71 | - * @var WP_Font_Awesome_Settings There can be only one! |
|
72 | - */ |
|
73 | - private static $instance = null; |
|
74 | - |
|
75 | - /** |
|
76 | - * Main WP_Font_Awesome_Settings Instance. |
|
77 | - * |
|
78 | - * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
79 | - * |
|
80 | - * @since 1.0.0 |
|
81 | - * @static |
|
82 | - * @return WP_Font_Awesome_Settings - Main instance. |
|
83 | - */ |
|
84 | - public static function instance() { |
|
85 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
86 | - self::$instance = new WP_Font_Awesome_Settings; |
|
87 | - |
|
88 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
89 | - |
|
90 | - if ( is_admin() ) { |
|
91 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
92 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
93 | - add_action( 'admin_init', array( self::$instance, 'constants' ) ); |
|
94 | - add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
95 | - } |
|
96 | - |
|
97 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
98 | - } |
|
99 | - |
|
100 | - return self::$instance; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
24 | + /** |
|
25 | + * A Class to be able to change settings for Font Awesome. |
|
26 | + * |
|
27 | + * Class WP_Font_Awesome_Settings |
|
28 | + */ |
|
29 | + class WP_Font_Awesome_Settings { |
|
30 | + |
|
31 | + /** |
|
32 | + * Class version version. |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $version = '1.1.10'; |
|
37 | + |
|
38 | + /** |
|
39 | + * Class textdomain. |
|
40 | + * |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + public $textdomain = 'font-awesome-settings'; |
|
44 | + |
|
45 | + /** |
|
46 | + * Latest version of Font Awesome at time of publish published. |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + public $latest = "6.4.2"; |
|
51 | + |
|
52 | + /** |
|
53 | + * The title. |
|
54 | + * |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + public $name = 'Font Awesome'; |
|
58 | + |
|
59 | + /** |
|
60 | + * Holds the settings values. |
|
61 | + * |
|
62 | + * @var array |
|
63 | + */ |
|
64 | + private $settings; |
|
65 | + |
|
66 | + /** |
|
67 | + * WP_Font_Awesome_Settings instance. |
|
68 | + * |
|
69 | + * @access private |
|
70 | + * @since 1.0.0 |
|
71 | + * @var WP_Font_Awesome_Settings There can be only one! |
|
72 | + */ |
|
73 | + private static $instance = null; |
|
74 | + |
|
75 | + /** |
|
76 | + * Main WP_Font_Awesome_Settings Instance. |
|
77 | + * |
|
78 | + * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
79 | + * |
|
80 | + * @since 1.0.0 |
|
81 | + * @static |
|
82 | + * @return WP_Font_Awesome_Settings - Main instance. |
|
83 | + */ |
|
84 | + public static function instance() { |
|
85 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
86 | + self::$instance = new WP_Font_Awesome_Settings; |
|
87 | + |
|
88 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
89 | + |
|
90 | + if ( is_admin() ) { |
|
91 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
92 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
93 | + add_action( 'admin_init', array( self::$instance, 'constants' ) ); |
|
94 | + add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
95 | + } |
|
96 | + |
|
97 | + do_action( 'wp_font_awesome_settings_loaded' ); |
|
98 | + } |
|
99 | + |
|
100 | + return self::$instance; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | 104 | * Define any constants that may be needed by other packages. |
105 | 105 | * |
106 | - * @return void |
|
107 | - */ |
|
108 | - public function constants(){ |
|
106 | + * @return void |
|
107 | + */ |
|
108 | + public function constants(){ |
|
109 | 109 | |
110 | - // register iconpicker constant |
|
111 | - if ( ! defined( 'FAS_ICONPICKER_JS_URL' ) ) { |
|
112 | - $url = $this->get_path_url(); |
|
113 | - $version = $this->settings['version']; |
|
110 | + // register iconpicker constant |
|
111 | + if ( ! defined( 'FAS_ICONPICKER_JS_URL' ) ) { |
|
112 | + $url = $this->get_path_url(); |
|
113 | + $version = $this->settings['version']; |
|
114 | 114 | |
115 | - if( !$version || version_compare($version,'5.999','>')){ |
|
116 | - $url .= 'assets/js/fa-iconpicker-v6.min.js'; |
|
117 | - }else{ |
|
118 | - $url .= 'assets/js/fa-iconpicker-v5.min.js'; |
|
119 | - } |
|
115 | + if( !$version || version_compare($version,'5.999','>')){ |
|
116 | + $url .= 'assets/js/fa-iconpicker-v6.min.js'; |
|
117 | + }else{ |
|
118 | + $url .= 'assets/js/fa-iconpicker-v5.min.js'; |
|
119 | + } |
|
120 | 120 | |
121 | - define( 'FAS_ICONPICKER_JS_URL', $url ); |
|
121 | + define( 'FAS_ICONPICKER_JS_URL', $url ); |
|
122 | 122 | |
123 | - } |
|
123 | + } |
|
124 | 124 | |
125 | 125 | // Set a constant if pro enabled |
126 | - if ( ! defined( 'FAS_PRO' ) && $this->settings['pro'] ) { |
|
127 | - define( 'FAS_PRO', true ); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Get the url path to the current folder. |
|
133 | - * |
|
134 | - * @return string |
|
135 | - */ |
|
136 | - public function get_path_url() { |
|
137 | - $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) ); |
|
138 | - $content_url = untrailingslashit( WP_CONTENT_URL ); |
|
139 | - |
|
140 | - // Replace http:// to https://. |
|
141 | - if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) { |
|
142 | - $content_url = str_replace( 'http://', 'https://', $content_url ); |
|
143 | - } |
|
144 | - |
|
145 | - // Check if we are inside a plugin |
|
146 | - $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
147 | - $url = str_replace( $content_dir, $content_url, $file_dir ); |
|
148 | - |
|
149 | - return trailingslashit( $url ); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Initiate the settings and add the required action hooks. |
|
154 | - * |
|
155 | - * @since 1.0.8 Settings name wrong - FIXED |
|
156 | - */ |
|
157 | - public function init() { |
|
158 | - // Download fontawesome locally. |
|
159 | - add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 ); |
|
160 | - add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
161 | - |
|
162 | - $this->settings = $this->get_settings(); |
|
163 | - |
|
164 | - // Check if the official plugin is active and use that instead if so. |
|
165 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
166 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
167 | - add_action( 'admin_head', array( $this, 'add_generator' ), 99 ); |
|
168 | - } |
|
169 | - |
|
170 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
171 | - add_action( 'wp_head', array( $this, 'add_generator' ), 99 ); |
|
172 | - } |
|
173 | - |
|
174 | - if ( $this->settings['type'] == 'CSS' ) { |
|
175 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
176 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
177 | - //add_action( 'wp_footer', array( $this, 'enqueue_style' ), 5000 ); // not sure why this was added, seems to break frontend |
|
178 | - } |
|
179 | - |
|
180 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
181 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
182 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 ); |
|
183 | - } |
|
184 | - } else { |
|
185 | - $enqueue = false; |
|
186 | - |
|
187 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
188 | - $enqueue = true; |
|
189 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
190 | - } |
|
191 | - |
|
192 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
193 | - $enqueue = true; |
|
194 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
195 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 ); |
|
196 | - } |
|
197 | - |
|
198 | - if ( $enqueue ) { |
|
199 | - add_filter( 'script_loader_tag', array( $this, 'script_loader_tag' ), 20, 3 ); |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - // remove font awesome if set to do so |
|
204 | - if ( $this->settings['dequeue'] == '1' ) { |
|
205 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
206 | - } |
|
207 | - } |
|
208 | - |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Add FA to the FSE. |
|
213 | - * |
|
214 | - * @param $editor_settings |
|
215 | - * @param $block_editor_context |
|
216 | - * |
|
217 | - * @return array |
|
218 | - */ |
|
219 | - public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
|
220 | - |
|
221 | - if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
|
222 | - $url = $this->get_url(); |
|
223 | - $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
|
224 | - } |
|
225 | - |
|
226 | - return $editor_settings; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Add FA to the FSE. |
|
231 | - * |
|
232 | - * @param $editor_settings |
|
233 | - * @param $block_editor_context |
|
234 | - * |
|
235 | - * @return array |
|
236 | - */ |
|
237 | - public function enqueue_editor_scripts( $editor_settings, $block_editor_context ) { |
|
238 | - $url = $this->get_url(); |
|
239 | - |
|
240 | - $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js' defer crossorigin='anonymous'></script>"; |
|
241 | - |
|
242 | - return $editor_settings; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * Adds the Font Awesome styles. |
|
247 | - */ |
|
248 | - public function enqueue_style() { |
|
249 | - // build url |
|
250 | - $url = $this->get_url(); |
|
251 | - $version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null; |
|
252 | - |
|
253 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
254 | - wp_register_style( 'font-awesome', $url, array(), $version ); |
|
255 | - wp_enqueue_style( 'font-awesome' ); |
|
256 | - |
|
257 | - // RTL language support CSS. |
|
258 | - if ( is_rtl() ) { |
|
259 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
260 | - } |
|
261 | - |
|
262 | - if ( $this->settings['shims'] ) { |
|
263 | - $url = $this->get_url( true ); |
|
264 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
265 | - wp_register_style( 'font-awesome-shims', $url, array(), $version ); |
|
266 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
267 | - } |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * Adds the Font Awesome JS. |
|
272 | - */ |
|
273 | - public function enqueue_scripts() { |
|
274 | - // build url |
|
275 | - $url = $this->get_url(); |
|
276 | - |
|
277 | - $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
278 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
279 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
280 | - wp_enqueue_script( 'font-awesome' ); |
|
281 | - |
|
282 | - if ( $this->settings['shims'] ) { |
|
283 | - $url = $this->get_url( true ); |
|
284 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
285 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
286 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
287 | - } |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Get the url of the Font Awesome files. |
|
292 | - * |
|
293 | - * @param bool $shims If this is a shim file or not. |
|
294 | - * @param bool $local Load locally if allowed. |
|
295 | - * |
|
296 | - * @return string The url to the file. |
|
297 | - */ |
|
298 | - public function get_url( $shims = false, $local = true ) { |
|
299 | - $script = $shims ? 'v4-shims' : 'all'; |
|
300 | - $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
301 | - $type = $this->settings['type']; |
|
302 | - $version = $this->settings['version']; |
|
303 | - $kit_url = $this->settings['kit-url'] ? sanitize_text_field( $this->settings['kit-url'] ) : ''; |
|
304 | - $url = ''; |
|
305 | - |
|
306 | - if ( $type == 'KIT' && $kit_url ) { |
|
307 | - if ( $shims ) { |
|
308 | - // if its a kit then we don't add shims here |
|
309 | - return ''; |
|
310 | - } |
|
311 | - $url .= $kit_url; // CDN |
|
312 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
313 | - } else { |
|
314 | - $v = ''; |
|
315 | - // Check and load locally. |
|
316 | - if ( $local && $this->has_local() ) { |
|
317 | - $script .= ".min"; |
|
318 | - $v .= '&ver=' . strip_tags( $this->settings['local_version'] ); |
|
319 | - $url .= $this->get_fonts_url(); // Local fonts url. |
|
320 | - } else { |
|
321 | - $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
322 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
323 | - } |
|
324 | - $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
325 | - $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
326 | - $url .= "?wpfas=true" . $v; // set our var so our version is not removed |
|
327 | - } |
|
328 | - |
|
329 | - return $url; |
|
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
334 | - * |
|
335 | - * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
336 | - * |
|
337 | - * @param $url |
|
338 | - * @param $original_url |
|
339 | - * @param $_context |
|
340 | - * |
|
341 | - * @return string The filtered url. |
|
342 | - */ |
|
343 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
344 | - |
|
345 | - if ( $_context == 'display' |
|
346 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
347 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
348 | - ) {// it's a font-awesome-url (probably) |
|
349 | - |
|
350 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
351 | - if ( $this->settings['type'] == 'JS' ) { |
|
352 | - if ( $this->settings['js-pseudo'] ) { |
|
353 | - $url .= "' data-search-pseudo-elements defer='defer"; |
|
354 | - } else { |
|
355 | - $url .= "' defer='defer"; |
|
356 | - } |
|
357 | - } |
|
358 | - } else { |
|
359 | - $url = ''; // removing the url removes the file |
|
360 | - } |
|
361 | - |
|
362 | - } |
|
363 | - |
|
364 | - return $url; |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Register the database settings with WordPress. |
|
369 | - */ |
|
370 | - public function register_settings() { |
|
371 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * Add the WordPress settings menu item. |
|
376 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
377 | - */ |
|
378 | - public function menu_item() { |
|
379 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
380 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
381 | - $this, |
|
382 | - 'settings_page' |
|
383 | - ) ); |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Get the current Font Awesome output settings. |
|
388 | - * |
|
389 | - * @return array The array of settings. |
|
390 | - */ |
|
391 | - public function get_settings() { |
|
392 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
393 | - |
|
394 | - $defaults = array( |
|
395 | - 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
396 | - 'version' => '', // latest |
|
397 | - 'enqueue' => '', // front and backend |
|
398 | - 'shims' => '0', // default OFF now in 2020 |
|
399 | - 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
400 | - 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
401 | - 'pro' => '0', // if pro CDN url should be used |
|
402 | - 'local' => '0', // Store fonts locally. |
|
403 | - 'local_version' => '', // Local fonts version. |
|
404 | - 'kit-url' => '', // the kit url |
|
405 | - ); |
|
406 | - |
|
407 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
408 | - |
|
409 | - /** |
|
410 | - * Filter the Font Awesome settings. |
|
411 | - * |
|
412 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
413 | - */ |
|
414 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * The settings page html output. |
|
419 | - */ |
|
420 | - public function settings_page() { |
|
421 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
422 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'ayecode-connect' ) ); |
|
423 | - } |
|
424 | - |
|
425 | - // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
426 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
427 | - $this->get_latest_version( $force_api = true ); |
|
428 | - } |
|
429 | - |
|
430 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
431 | - ?> |
|
126 | + if ( ! defined( 'FAS_PRO' ) && $this->settings['pro'] ) { |
|
127 | + define( 'FAS_PRO', true ); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Get the url path to the current folder. |
|
133 | + * |
|
134 | + * @return string |
|
135 | + */ |
|
136 | + public function get_path_url() { |
|
137 | + $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) ); |
|
138 | + $content_url = untrailingslashit( WP_CONTENT_URL ); |
|
139 | + |
|
140 | + // Replace http:// to https://. |
|
141 | + if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) { |
|
142 | + $content_url = str_replace( 'http://', 'https://', $content_url ); |
|
143 | + } |
|
144 | + |
|
145 | + // Check if we are inside a plugin |
|
146 | + $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
147 | + $url = str_replace( $content_dir, $content_url, $file_dir ); |
|
148 | + |
|
149 | + return trailingslashit( $url ); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Initiate the settings and add the required action hooks. |
|
154 | + * |
|
155 | + * @since 1.0.8 Settings name wrong - FIXED |
|
156 | + */ |
|
157 | + public function init() { |
|
158 | + // Download fontawesome locally. |
|
159 | + add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 ); |
|
160 | + add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
161 | + |
|
162 | + $this->settings = $this->get_settings(); |
|
163 | + |
|
164 | + // Check if the official plugin is active and use that instead if so. |
|
165 | + if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
166 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
167 | + add_action( 'admin_head', array( $this, 'add_generator' ), 99 ); |
|
168 | + } |
|
169 | + |
|
170 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
171 | + add_action( 'wp_head', array( $this, 'add_generator' ), 99 ); |
|
172 | + } |
|
173 | + |
|
174 | + if ( $this->settings['type'] == 'CSS' ) { |
|
175 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
176 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
177 | + //add_action( 'wp_footer', array( $this, 'enqueue_style' ), 5000 ); // not sure why this was added, seems to break frontend |
|
178 | + } |
|
179 | + |
|
180 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
181 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
182 | + add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 ); |
|
183 | + } |
|
184 | + } else { |
|
185 | + $enqueue = false; |
|
186 | + |
|
187 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
188 | + $enqueue = true; |
|
189 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
190 | + } |
|
191 | + |
|
192 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
193 | + $enqueue = true; |
|
194 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
195 | + add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 ); |
|
196 | + } |
|
197 | + |
|
198 | + if ( $enqueue ) { |
|
199 | + add_filter( 'script_loader_tag', array( $this, 'script_loader_tag' ), 20, 3 ); |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + // remove font awesome if set to do so |
|
204 | + if ( $this->settings['dequeue'] == '1' ) { |
|
205 | + add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
206 | + } |
|
207 | + } |
|
208 | + |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Add FA to the FSE. |
|
213 | + * |
|
214 | + * @param $editor_settings |
|
215 | + * @param $block_editor_context |
|
216 | + * |
|
217 | + * @return array |
|
218 | + */ |
|
219 | + public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
|
220 | + |
|
221 | + if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
|
222 | + $url = $this->get_url(); |
|
223 | + $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
|
224 | + } |
|
225 | + |
|
226 | + return $editor_settings; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Add FA to the FSE. |
|
231 | + * |
|
232 | + * @param $editor_settings |
|
233 | + * @param $block_editor_context |
|
234 | + * |
|
235 | + * @return array |
|
236 | + */ |
|
237 | + public function enqueue_editor_scripts( $editor_settings, $block_editor_context ) { |
|
238 | + $url = $this->get_url(); |
|
239 | + |
|
240 | + $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js' defer crossorigin='anonymous'></script>"; |
|
241 | + |
|
242 | + return $editor_settings; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * Adds the Font Awesome styles. |
|
247 | + */ |
|
248 | + public function enqueue_style() { |
|
249 | + // build url |
|
250 | + $url = $this->get_url(); |
|
251 | + $version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null; |
|
252 | + |
|
253 | + wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
254 | + wp_register_style( 'font-awesome', $url, array(), $version ); |
|
255 | + wp_enqueue_style( 'font-awesome' ); |
|
256 | + |
|
257 | + // RTL language support CSS. |
|
258 | + if ( is_rtl() ) { |
|
259 | + wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
260 | + } |
|
261 | + |
|
262 | + if ( $this->settings['shims'] ) { |
|
263 | + $url = $this->get_url( true ); |
|
264 | + wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
265 | + wp_register_style( 'font-awesome-shims', $url, array(), $version ); |
|
266 | + wp_enqueue_style( 'font-awesome-shims' ); |
|
267 | + } |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * Adds the Font Awesome JS. |
|
272 | + */ |
|
273 | + public function enqueue_scripts() { |
|
274 | + // build url |
|
275 | + $url = $this->get_url(); |
|
276 | + |
|
277 | + $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
278 | + call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
279 | + wp_register_script( 'font-awesome', $url, array(), null ); |
|
280 | + wp_enqueue_script( 'font-awesome' ); |
|
281 | + |
|
282 | + if ( $this->settings['shims'] ) { |
|
283 | + $url = $this->get_url( true ); |
|
284 | + call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
285 | + wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
286 | + wp_enqueue_script( 'font-awesome-shims' ); |
|
287 | + } |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Get the url of the Font Awesome files. |
|
292 | + * |
|
293 | + * @param bool $shims If this is a shim file or not. |
|
294 | + * @param bool $local Load locally if allowed. |
|
295 | + * |
|
296 | + * @return string The url to the file. |
|
297 | + */ |
|
298 | + public function get_url( $shims = false, $local = true ) { |
|
299 | + $script = $shims ? 'v4-shims' : 'all'; |
|
300 | + $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
301 | + $type = $this->settings['type']; |
|
302 | + $version = $this->settings['version']; |
|
303 | + $kit_url = $this->settings['kit-url'] ? sanitize_text_field( $this->settings['kit-url'] ) : ''; |
|
304 | + $url = ''; |
|
305 | + |
|
306 | + if ( $type == 'KIT' && $kit_url ) { |
|
307 | + if ( $shims ) { |
|
308 | + // if its a kit then we don't add shims here |
|
309 | + return ''; |
|
310 | + } |
|
311 | + $url .= $kit_url; // CDN |
|
312 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
313 | + } else { |
|
314 | + $v = ''; |
|
315 | + // Check and load locally. |
|
316 | + if ( $local && $this->has_local() ) { |
|
317 | + $script .= ".min"; |
|
318 | + $v .= '&ver=' . strip_tags( $this->settings['local_version'] ); |
|
319 | + $url .= $this->get_fonts_url(); // Local fonts url. |
|
320 | + } else { |
|
321 | + $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
322 | + $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
323 | + } |
|
324 | + $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
325 | + $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
326 | + $url .= "?wpfas=true" . $v; // set our var so our version is not removed |
|
327 | + } |
|
328 | + |
|
329 | + return $url; |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
334 | + * |
|
335 | + * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
336 | + * |
|
337 | + * @param $url |
|
338 | + * @param $original_url |
|
339 | + * @param $_context |
|
340 | + * |
|
341 | + * @return string The filtered url. |
|
342 | + */ |
|
343 | + public function remove_font_awesome( $url, $original_url, $_context ) { |
|
344 | + |
|
345 | + if ( $_context == 'display' |
|
346 | + && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
347 | + && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
348 | + ) {// it's a font-awesome-url (probably) |
|
349 | + |
|
350 | + if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
351 | + if ( $this->settings['type'] == 'JS' ) { |
|
352 | + if ( $this->settings['js-pseudo'] ) { |
|
353 | + $url .= "' data-search-pseudo-elements defer='defer"; |
|
354 | + } else { |
|
355 | + $url .= "' defer='defer"; |
|
356 | + } |
|
357 | + } |
|
358 | + } else { |
|
359 | + $url = ''; // removing the url removes the file |
|
360 | + } |
|
361 | + |
|
362 | + } |
|
363 | + |
|
364 | + return $url; |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Register the database settings with WordPress. |
|
369 | + */ |
|
370 | + public function register_settings() { |
|
371 | + register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * Add the WordPress settings menu item. |
|
376 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
377 | + */ |
|
378 | + public function menu_item() { |
|
379 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
380 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
381 | + $this, |
|
382 | + 'settings_page' |
|
383 | + ) ); |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Get the current Font Awesome output settings. |
|
388 | + * |
|
389 | + * @return array The array of settings. |
|
390 | + */ |
|
391 | + public function get_settings() { |
|
392 | + $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
393 | + |
|
394 | + $defaults = array( |
|
395 | + 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
396 | + 'version' => '', // latest |
|
397 | + 'enqueue' => '', // front and backend |
|
398 | + 'shims' => '0', // default OFF now in 2020 |
|
399 | + 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
400 | + 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
401 | + 'pro' => '0', // if pro CDN url should be used |
|
402 | + 'local' => '0', // Store fonts locally. |
|
403 | + 'local_version' => '', // Local fonts version. |
|
404 | + 'kit-url' => '', // the kit url |
|
405 | + ); |
|
406 | + |
|
407 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
408 | + |
|
409 | + /** |
|
410 | + * Filter the Font Awesome settings. |
|
411 | + * |
|
412 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
413 | + */ |
|
414 | + return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * The settings page html output. |
|
419 | + */ |
|
420 | + public function settings_page() { |
|
421 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
422 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'ayecode-connect' ) ); |
|
423 | + } |
|
424 | + |
|
425 | + // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
426 | + if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
427 | + $this->get_latest_version( $force_api = true ); |
|
428 | + } |
|
429 | + |
|
430 | + if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
431 | + ?> |
|
432 | 432 | <style> |
433 | 433 | .wpfas-kit-show { |
434 | 434 | display: none; |
@@ -454,16 +454,16 @@ discard block |
||
454 | 454 | <h1><?php echo $this->name; ?></h1> |
455 | 455 | <form method="post" action="options.php" class="fas-settings-form"> |
456 | 456 | <?php |
457 | - settings_fields( 'wp-font-awesome-settings' ); |
|
458 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
459 | - $table_class = ''; |
|
460 | - if ( $this->settings['type'] ) { |
|
461 | - $table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set'; |
|
462 | - } |
|
463 | - if ( ! empty( $this->settings['pro'] ) ) { |
|
464 | - $table_class .= ' wpfas-has-pro'; |
|
465 | - } |
|
466 | - ?> |
|
457 | + settings_fields( 'wp-font-awesome-settings' ); |
|
458 | + do_settings_sections( 'wp-font-awesome-settings' ); |
|
459 | + $table_class = ''; |
|
460 | + if ( $this->settings['type'] ) { |
|
461 | + $table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set'; |
|
462 | + } |
|
463 | + if ( ! empty( $this->settings['pro'] ) ) { |
|
464 | + $table_class .= ' wpfas-has-pro'; |
|
465 | + } |
|
466 | + ?> |
|
467 | 467 | <?php if ( $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ) { ?> |
468 | 468 | <?php if ( $this->has_local() ) { ?> |
469 | 469 | <div class="notice notice-info"><p><strong><?php _e( 'Font Awesome fonts are loading locally.', 'ayecode-connect' ); ?></strong></p></div> |
@@ -488,12 +488,12 @@ discard block |
||
488 | 488 | <td> |
489 | 489 | <input class="regular-text" id="wpfas-kit-url" type="url" name="wp-font-awesome-settings[kit-url]" value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
490 | 490 | <span><?php |
491 | - echo wp_sprintf( |
|
492 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'ayecode-connect' ), |
|
493 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i> ', |
|
494 | - '</a>' |
|
495 | - ); |
|
496 | - ?></span> |
|
491 | + echo wp_sprintf( |
|
492 | + __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'ayecode-connect' ), |
|
493 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i> ', |
|
494 | + '</a>' |
|
495 | + ); |
|
496 | + ?></span> |
|
497 | 497 | </td> |
498 | 498 | </tr> |
499 | 499 | <tr valign="top" class="wpfas-kit-hide"> |
@@ -543,14 +543,14 @@ discard block |
||
543 | 543 | <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/> |
544 | 544 | <input type="checkbox" name="wp-font-awesome-settings[pro]" value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro" onchange="if(jQuery(this).is(':checked')){jQuery('.wpfas-table-settings').addClass('wpfas-has-pro')}else{jQuery('.wpfas-table-settings').removeClass('wpfas-has-pro')}"/> |
545 | 545 | <span><?php |
546 | - echo wp_sprintf( |
|
547 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'ayecode-connect' ), |
|
548 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
|
549 | - ' <i class="fas fa-external-link-alt"></i></a>', |
|
550 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
|
551 | - ' <i class="fas fa-external-link-alt"></i></a>' |
|
552 | - ); |
|
553 | - ?></span> |
|
546 | + echo wp_sprintf( |
|
547 | + __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'ayecode-connect' ), |
|
548 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
|
549 | + ' <i class="fas fa-external-link-alt"></i></a>', |
|
550 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
|
551 | + ' <i class="fas fa-external-link-alt"></i></a>' |
|
552 | + ); |
|
553 | + ?></span> |
|
554 | 554 | </td> |
555 | 555 | </tr> |
556 | 556 | |
@@ -604,8 +604,8 @@ discard block |
||
604 | 604 | </table> |
605 | 605 | <div class="fas-buttons"> |
606 | 606 | <?php |
607 | - submit_button(); |
|
608 | - ?> |
|
607 | + submit_button(); |
|
608 | + ?> |
|
609 | 609 | <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 24,000+ more icons with Font Awesome Pro','ayecode-connect'); ?> <i class="fas fa-external-link-alt"></i></a></p> |
610 | 610 | |
611 | 611 | </div> |
@@ -614,444 +614,444 @@ discard block |
||
614 | 614 | <div id="wpfas-version"><?php echo wp_sprintf(__( 'Version: %s (affiliate links provided)', 'ayecode-connect' ), $this->version ); ?></div> |
615 | 615 | </div> |
616 | 616 | <?php |
617 | - } |
|
618 | - } |
|
619 | - |
|
620 | - /** |
|
621 | - * Check a version number is valid and if so return it or else return an empty string. |
|
622 | - * |
|
623 | - * @param $version string The version number to check. |
|
624 | - * |
|
625 | - * @since 1.0.6 |
|
626 | - * |
|
627 | - * @return string Either a valid version number or an empty string. |
|
628 | - */ |
|
629 | - public function validate_version_number( $version ) { |
|
630 | - |
|
631 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
632 | - // valid |
|
633 | - } else { |
|
634 | - $version = '';// not validated |
|
635 | - } |
|
636 | - |
|
637 | - return $version; |
|
638 | - } |
|
639 | - |
|
640 | - |
|
641 | - /** |
|
642 | - * Get the latest version of Font Awesome. |
|
643 | - * |
|
644 | - * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
645 | - * |
|
646 | - * @since 1.0.7 |
|
647 | - * @return mixed|string The latest version number found. |
|
648 | - */ |
|
649 | - public function get_latest_version( $force_api = false, $force_latest = false ) { |
|
650 | - $latest_version = $this->latest; |
|
651 | - |
|
652 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
653 | - |
|
654 | - if ( $cache === false || $force_api ) { // its not set |
|
655 | - $api_ver = $this->get_latest_version_from_api(); |
|
656 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
657 | - $latest_version = $api_ver; |
|
658 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
659 | - } |
|
660 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
661 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
662 | - $latest_version = $cache; |
|
663 | - } |
|
664 | - } |
|
665 | - |
|
666 | - // @todo remove after FA7 compatibility |
|
667 | - if ( ! $force_latest && version_compare( $cache, '7.0.0', '>=' ) >= 0 ) { |
|
668 | - $latest_version = '6.7.2'; |
|
669 | - } |
|
670 | - |
|
671 | - // Check and auto download fonts locally. |
|
672 | - if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) { |
|
673 | - if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) { |
|
674 | - $this->download_package( $latest_version ); |
|
675 | - } |
|
676 | - } |
|
677 | - |
|
678 | - return $latest_version; |
|
679 | - } |
|
680 | - |
|
681 | - /** |
|
682 | - * Get the latest Font Awesome version from the github API. |
|
683 | - * |
|
684 | - * @since 1.0.7 |
|
685 | - * @return string The latest version number or `0` on API fail. |
|
686 | - */ |
|
687 | - public function get_latest_version_from_api() { |
|
688 | - $version = "0"; |
|
689 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
690 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
691 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
692 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
693 | - $version = $api_response['tag_name']; |
|
694 | - } |
|
695 | - } |
|
696 | - |
|
697 | - return $version; |
|
698 | - } |
|
699 | - |
|
700 | - /** |
|
701 | - * Inline CSS for RTL language support. |
|
702 | - * |
|
703 | - * @since 1.0.13 |
|
704 | - * @return string Inline CSS. |
|
705 | - */ |
|
706 | - public function rtl_inline_css() { |
|
707 | - $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
708 | - |
|
709 | - return $inline_css; |
|
710 | - } |
|
711 | - |
|
712 | - /** |
|
713 | - * Show any warnings as an admin notice. |
|
714 | - * |
|
715 | - * @return void |
|
716 | - */ |
|
717 | - public function admin_notices() { |
|
718 | - $settings = $this->settings; |
|
719 | - |
|
720 | - if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
721 | - if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
722 | - ?> |
|
617 | + } |
|
618 | + } |
|
619 | + |
|
620 | + /** |
|
621 | + * Check a version number is valid and if so return it or else return an empty string. |
|
622 | + * |
|
623 | + * @param $version string The version number to check. |
|
624 | + * |
|
625 | + * @since 1.0.6 |
|
626 | + * |
|
627 | + * @return string Either a valid version number or an empty string. |
|
628 | + */ |
|
629 | + public function validate_version_number( $version ) { |
|
630 | + |
|
631 | + if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
632 | + // valid |
|
633 | + } else { |
|
634 | + $version = '';// not validated |
|
635 | + } |
|
636 | + |
|
637 | + return $version; |
|
638 | + } |
|
639 | + |
|
640 | + |
|
641 | + /** |
|
642 | + * Get the latest version of Font Awesome. |
|
643 | + * |
|
644 | + * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
645 | + * |
|
646 | + * @since 1.0.7 |
|
647 | + * @return mixed|string The latest version number found. |
|
648 | + */ |
|
649 | + public function get_latest_version( $force_api = false, $force_latest = false ) { |
|
650 | + $latest_version = $this->latest; |
|
651 | + |
|
652 | + $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
653 | + |
|
654 | + if ( $cache === false || $force_api ) { // its not set |
|
655 | + $api_ver = $this->get_latest_version_from_api(); |
|
656 | + if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
657 | + $latest_version = $api_ver; |
|
658 | + set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
659 | + } |
|
660 | + } elseif ( $this->validate_version_number( $cache ) ) { |
|
661 | + if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
662 | + $latest_version = $cache; |
|
663 | + } |
|
664 | + } |
|
665 | + |
|
666 | + // @todo remove after FA7 compatibility |
|
667 | + if ( ! $force_latest && version_compare( $cache, '7.0.0', '>=' ) >= 0 ) { |
|
668 | + $latest_version = '6.7.2'; |
|
669 | + } |
|
670 | + |
|
671 | + // Check and auto download fonts locally. |
|
672 | + if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) { |
|
673 | + if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) { |
|
674 | + $this->download_package( $latest_version ); |
|
675 | + } |
|
676 | + } |
|
677 | + |
|
678 | + return $latest_version; |
|
679 | + } |
|
680 | + |
|
681 | + /** |
|
682 | + * Get the latest Font Awesome version from the github API. |
|
683 | + * |
|
684 | + * @since 1.0.7 |
|
685 | + * @return string The latest version number or `0` on API fail. |
|
686 | + */ |
|
687 | + public function get_latest_version_from_api() { |
|
688 | + $version = "0"; |
|
689 | + $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
690 | + if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
691 | + $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
692 | + if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
693 | + $version = $api_response['tag_name']; |
|
694 | + } |
|
695 | + } |
|
696 | + |
|
697 | + return $version; |
|
698 | + } |
|
699 | + |
|
700 | + /** |
|
701 | + * Inline CSS for RTL language support. |
|
702 | + * |
|
703 | + * @since 1.0.13 |
|
704 | + * @return string Inline CSS. |
|
705 | + */ |
|
706 | + public function rtl_inline_css() { |
|
707 | + $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
708 | + |
|
709 | + return $inline_css; |
|
710 | + } |
|
711 | + |
|
712 | + /** |
|
713 | + * Show any warnings as an admin notice. |
|
714 | + * |
|
715 | + * @return void |
|
716 | + */ |
|
717 | + public function admin_notices() { |
|
718 | + $settings = $this->settings; |
|
719 | + |
|
720 | + if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
721 | + if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
722 | + ?> |
|
723 | 723 | <div class="notice notice-error is-dismissible"> |
724 | 724 | <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'ayecode-connect' ); ?></p> |
725 | 725 | </div> |
726 | 726 | <?php |
727 | - } |
|
728 | - } else { |
|
729 | - if ( ! empty( $settings ) ) { |
|
730 | - if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
731 | - $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
|
732 | - ?> |
|
727 | + } |
|
728 | + } else { |
|
729 | + if ( ! empty( $settings ) ) { |
|
730 | + if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
731 | + $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
|
732 | + ?> |
|
733 | 733 | <div class="notice notice-error is-dismissible"> |
734 | 734 | <p><?php echo wp_sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'ayecode-connect' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p> |
735 | 735 | </div> |
736 | 736 | <?php |
737 | - } |
|
738 | - } |
|
739 | - } |
|
740 | - } |
|
741 | - |
|
742 | - /** |
|
743 | - * Handle fontawesome add settings to download fontawesome to store locally. |
|
744 | - * |
|
745 | - * @since 1.1.1 |
|
746 | - * |
|
747 | - * @param string $option The option name. |
|
748 | - * @param mixed $value The option value. |
|
749 | - */ |
|
750 | - public function add_option_wp_font_awesome_settings( $option, $value ) { |
|
751 | - // Do nothing if WordPress is being installed. |
|
752 | - if ( wp_installing() ) { |
|
753 | - return; |
|
754 | - } |
|
755 | - |
|
756 | - if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) { |
|
757 | - $version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version(); |
|
758 | - |
|
759 | - if ( ! empty( $version ) ) { |
|
760 | - $response = $this->download_package( $version, $value ); |
|
761 | - |
|
762 | - if ( is_wp_error( $response ) ) { |
|
763 | - add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' ); |
|
764 | - } |
|
765 | - } |
|
766 | - } |
|
767 | - } |
|
768 | - |
|
769 | - /** |
|
770 | - * Handle fontawesome update settings to download fontawesome to store locally. |
|
771 | - * |
|
772 | - * @since 1.1.0 |
|
773 | - * |
|
774 | - * @param mixed $old_value The old option value. |
|
775 | - * @param mixed $value The new option value. |
|
776 | - */ |
|
777 | - public function update_option_wp_font_awesome_settings( $old_value, $new_value ) { |
|
778 | - // Do nothing if WordPress is being installed. |
|
779 | - if ( wp_installing() ) { |
|
780 | - return; |
|
781 | - } |
|
782 | - |
|
783 | - if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) { |
|
784 | - // Old values |
|
785 | - $old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' ); |
|
786 | - $old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0; |
|
787 | - |
|
788 | - // New values |
|
789 | - $new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version(); |
|
790 | - |
|
791 | - if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
792 | - $response = $this->download_package( $new_version, $new_value ); |
|
793 | - |
|
794 | - if ( is_wp_error( $response ) ) { |
|
795 | - add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' ); |
|
796 | - } |
|
797 | - } |
|
798 | - } |
|
799 | - } |
|
800 | - |
|
801 | - /** |
|
802 | - * Get the fonts directory local path. |
|
803 | - * |
|
804 | - * @since 1.1.0 |
|
805 | - * |
|
806 | - * @param string Fonts directory local path. |
|
807 | - */ |
|
808 | - public function get_fonts_dir() { |
|
809 | - $upload_dir = wp_upload_dir( null, false ); |
|
810 | - |
|
811 | - return $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR; |
|
812 | - } |
|
813 | - |
|
814 | - /** |
|
815 | - * Get the fonts directory local url. |
|
816 | - * |
|
817 | - * @since 1.1.0 |
|
818 | - * |
|
819 | - * @param string Fonts directory local url. |
|
820 | - */ |
|
821 | - public function get_fonts_url() { |
|
822 | - $upload_dir = wp_upload_dir( null, false ); |
|
823 | - |
|
824 | - return $upload_dir['baseurl'] . '/ayefonts/fa/'; |
|
825 | - } |
|
826 | - |
|
827 | - /** |
|
828 | - * Check whether load locally active. |
|
829 | - * |
|
830 | - * @since 1.1.0 |
|
831 | - * |
|
832 | - * @return bool True if active else false. |
|
833 | - */ |
|
834 | - public function has_local() { |
|
835 | - if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
836 | - return true; |
|
837 | - } |
|
838 | - |
|
839 | - return false; |
|
840 | - } |
|
841 | - |
|
842 | - /** |
|
843 | - * Get the WP Filesystem access. |
|
844 | - * |
|
845 | - * @since 1.1.0 |
|
846 | - * |
|
847 | - * @return object The WP Filesystem. |
|
848 | - */ |
|
849 | - public function get_wp_filesystem() { |
|
850 | - if ( ! function_exists( 'get_filesystem_method' ) ) { |
|
851 | - require_once( ABSPATH . "/wp-admin/includes/file.php" ); |
|
852 | - } |
|
853 | - |
|
854 | - $access_type = get_filesystem_method(); |
|
855 | - |
|
856 | - if ( $access_type === 'direct' ) { |
|
857 | - /* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */ |
|
858 | - $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
859 | - |
|
860 | - /* Initialize the API */ |
|
861 | - if ( ! WP_Filesystem( $creds ) ) { |
|
862 | - /* Any problems and we exit */ |
|
863 | - return false; |
|
864 | - } |
|
865 | - |
|
866 | - global $wp_filesystem; |
|
867 | - |
|
868 | - return $wp_filesystem; |
|
869 | - /* Do our file manipulations below */ |
|
870 | - } else if ( defined( 'FTP_USER' ) ) { |
|
871 | - $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
872 | - |
|
873 | - /* Initialize the API */ |
|
874 | - if ( ! WP_Filesystem( $creds ) ) { |
|
875 | - /* Any problems and we exit */ |
|
876 | - return false; |
|
877 | - } |
|
878 | - |
|
879 | - global $wp_filesystem; |
|
880 | - |
|
881 | - return $wp_filesystem; |
|
882 | - } else { |
|
883 | - /* Don't have direct write access. Prompt user with our notice */ |
|
884 | - return false; |
|
885 | - } |
|
886 | - } |
|
887 | - |
|
888 | - /** |
|
889 | - * Download the fontawesome package file. |
|
890 | - * |
|
891 | - * @since 1.1.0 |
|
892 | - * |
|
893 | - * @param mixed $version The font awesome. |
|
894 | - * @param array $option Fontawesome settings. |
|
895 | - * @return WP_ERROR|bool Error on fail and true on success. |
|
896 | - */ |
|
897 | - public function download_package( $version, $option = array() ) { |
|
898 | - $filename = 'fontawesome-free-' . $version . '-web'; |
|
899 | - $url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip'; |
|
900 | - |
|
901 | - if ( ! function_exists( 'wp_handle_upload' ) ) { |
|
902 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
903 | - } |
|
904 | - |
|
905 | - $download_file = download_url( esc_url_raw( $url ) ); |
|
906 | - |
|
907 | - if ( is_wp_error( $download_file ) ) { |
|
908 | - return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'ayecode-connect' ) ); |
|
909 | - } else if ( empty( $download_file ) ) { |
|
910 | - return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'ayecode-connect' ) ); |
|
911 | - } |
|
912 | - |
|
913 | - $response = $this->extract_package( $download_file, $filename, true ); |
|
914 | - |
|
915 | - // Update local version. |
|
916 | - if ( is_wp_error( $response ) ) { |
|
917 | - return $response; |
|
918 | - } else if ( $response ) { |
|
919 | - if ( empty( $option ) ) { |
|
920 | - $option = get_option( 'wp-font-awesome-settings' ); |
|
921 | - } |
|
922 | - |
|
923 | - $option['local_version'] = $version; |
|
924 | - |
|
925 | - // Remove action to prevent looping. |
|
926 | - remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
927 | - |
|
928 | - update_option( 'wp-font-awesome-settings', $option ); |
|
929 | - |
|
930 | - return true; |
|
931 | - } |
|
932 | - |
|
933 | - return false; |
|
934 | - } |
|
935 | - |
|
936 | - /** |
|
937 | - * Extract the fontawesome package file. |
|
938 | - * |
|
939 | - * @since 1.1.0 |
|
940 | - * |
|
941 | - * @param string $package The package file path. |
|
942 | - * @param string $dirname Package file name. |
|
943 | - * @param bool $delete_package Delete temp file or not. |
|
944 | - * @return WP_Error|bool True on success WP_Error on fail. |
|
945 | - */ |
|
946 | - public function extract_package( $package, $dirname = '', $delete_package = false ) { |
|
947 | - global $wp_filesystem; |
|
948 | - |
|
949 | - $wp_filesystem = $this->get_wp_filesystem(); |
|
950 | - |
|
951 | - if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { |
|
952 | - return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'ayecode-connect' ) ); |
|
953 | - } else if ( empty( $wp_filesystem ) ) { |
|
954 | - return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'ayecode-connect' ) ); |
|
955 | - } |
|
956 | - |
|
957 | - $fonts_dir = $this->get_fonts_dir(); |
|
958 | - $fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR; |
|
959 | - |
|
960 | - if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
961 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
962 | - } |
|
963 | - |
|
964 | - // Unzip package to working directory. |
|
965 | - $result = unzip_file( $package, $fonts_tmp_dir ); |
|
966 | - |
|
967 | - if ( is_wp_error( $result ) ) { |
|
968 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
969 | - |
|
970 | - if ( 'incompatible_archive' === $result->get_error_code() ) { |
|
971 | - return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'ayecode-connect' ) ); |
|
972 | - } |
|
973 | - |
|
974 | - return $result; |
|
975 | - } |
|
976 | - |
|
977 | - if ( $wp_filesystem->is_dir( $fonts_dir ) ) { |
|
978 | - $wp_filesystem->delete( $fonts_dir, true ); |
|
979 | - } |
|
980 | - |
|
981 | - $extract_dir = $fonts_tmp_dir; |
|
982 | - |
|
983 | - if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) { |
|
984 | - $extract_dir .= $dirname . DIRECTORY_SEPARATOR; |
|
985 | - } |
|
986 | - |
|
987 | - try { |
|
988 | - $return = $wp_filesystem->move( $extract_dir, $fonts_dir, true ); |
|
989 | - } catch ( Exception $e ) { |
|
990 | - $return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'ayecode-connect' ) ); |
|
991 | - } |
|
992 | - |
|
993 | - if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
994 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
995 | - } |
|
996 | - |
|
997 | - // Once extracted, delete the package if required. |
|
998 | - if ( $delete_package ) { |
|
999 | - unlink( $package ); |
|
1000 | - } |
|
1001 | - |
|
1002 | - return $return; |
|
1003 | - } |
|
1004 | - |
|
1005 | - /** |
|
1006 | - * Output the version in the header. |
|
1007 | - */ |
|
1008 | - public function add_generator() { |
|
1009 | - $file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) ); |
|
1010 | - $plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) ); |
|
1011 | - |
|
1012 | - // Find source plugin/theme. |
|
1013 | - $source = array(); |
|
1014 | - if ( strpos( $file, $plugins_dir ) !== false ) { |
|
1015 | - $source = explode( "/", plugin_basename( $file ) ); |
|
1016 | - } else if ( function_exists( 'get_theme_root' ) ) { |
|
1017 | - $themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) ); |
|
1018 | - |
|
1019 | - if ( strpos( $file, $themes_dir ) !== false ) { |
|
1020 | - $source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) ); |
|
1021 | - } |
|
1022 | - } |
|
1023 | - |
|
1024 | - echo '<meta name="generator" content="WP Font Awesome Settings v' . esc_attr( $this->version ) . '"' . ( ! empty( $source[0] ) ? ' data-ac-source="' . esc_attr( $source[0] ) . '"' : '' ) . ' />'; |
|
1025 | - } |
|
1026 | - |
|
1027 | - /** |
|
1028 | - * Add extra parameters to the script tag. |
|
1029 | - * |
|
1030 | - * Add crossorigin="anonymous" to prevent OpaqueResponseBlocking |
|
1031 | - * (NS_BINDING_ABORTED) http error. |
|
1032 | - * |
|
1033 | - * @since 1.1.8 |
|
1034 | - * |
|
1035 | - * @param string $tag The script tag. |
|
1036 | - * @param string $handle The script handle. |
|
1037 | - * @param string $src The script url. |
|
1038 | - * @return string The script tag. |
|
1039 | - */ |
|
1040 | - public function script_loader_tag( $tag, $handle, $src ) { |
|
1041 | - if ( ( $handle == 'font-awesome' || $handle == 'font-awesome-shims' ) && ( strpos( $src, "kit.fontawesome.com" ) !== false || strpos( $src, ".fontawesome.com/releases/" ) !== false ) ) { |
|
1042 | - $tag = preg_replace( |
|
1043 | - '/<script[\s]+(.*?)>/', |
|
1044 | - '<script defer crossorigin="anonymous" \1>', |
|
1045 | - $tag |
|
1046 | - ); |
|
1047 | - } |
|
1048 | - |
|
1049 | - return $tag; |
|
1050 | - } |
|
1051 | - } |
|
1052 | - |
|
1053 | - /** |
|
1054 | - * Run the class if found. |
|
1055 | - */ |
|
1056 | - WP_Font_Awesome_Settings::instance(); |
|
737 | + } |
|
738 | + } |
|
739 | + } |
|
740 | + } |
|
741 | + |
|
742 | + /** |
|
743 | + * Handle fontawesome add settings to download fontawesome to store locally. |
|
744 | + * |
|
745 | + * @since 1.1.1 |
|
746 | + * |
|
747 | + * @param string $option The option name. |
|
748 | + * @param mixed $value The option value. |
|
749 | + */ |
|
750 | + public function add_option_wp_font_awesome_settings( $option, $value ) { |
|
751 | + // Do nothing if WordPress is being installed. |
|
752 | + if ( wp_installing() ) { |
|
753 | + return; |
|
754 | + } |
|
755 | + |
|
756 | + if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) { |
|
757 | + $version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version(); |
|
758 | + |
|
759 | + if ( ! empty( $version ) ) { |
|
760 | + $response = $this->download_package( $version, $value ); |
|
761 | + |
|
762 | + if ( is_wp_error( $response ) ) { |
|
763 | + add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' ); |
|
764 | + } |
|
765 | + } |
|
766 | + } |
|
767 | + } |
|
768 | + |
|
769 | + /** |
|
770 | + * Handle fontawesome update settings to download fontawesome to store locally. |
|
771 | + * |
|
772 | + * @since 1.1.0 |
|
773 | + * |
|
774 | + * @param mixed $old_value The old option value. |
|
775 | + * @param mixed $value The new option value. |
|
776 | + */ |
|
777 | + public function update_option_wp_font_awesome_settings( $old_value, $new_value ) { |
|
778 | + // Do nothing if WordPress is being installed. |
|
779 | + if ( wp_installing() ) { |
|
780 | + return; |
|
781 | + } |
|
782 | + |
|
783 | + if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) { |
|
784 | + // Old values |
|
785 | + $old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' ); |
|
786 | + $old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0; |
|
787 | + |
|
788 | + // New values |
|
789 | + $new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version(); |
|
790 | + |
|
791 | + if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
792 | + $response = $this->download_package( $new_version, $new_value ); |
|
793 | + |
|
794 | + if ( is_wp_error( $response ) ) { |
|
795 | + add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' ); |
|
796 | + } |
|
797 | + } |
|
798 | + } |
|
799 | + } |
|
800 | + |
|
801 | + /** |
|
802 | + * Get the fonts directory local path. |
|
803 | + * |
|
804 | + * @since 1.1.0 |
|
805 | + * |
|
806 | + * @param string Fonts directory local path. |
|
807 | + */ |
|
808 | + public function get_fonts_dir() { |
|
809 | + $upload_dir = wp_upload_dir( null, false ); |
|
810 | + |
|
811 | + return $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR; |
|
812 | + } |
|
813 | + |
|
814 | + /** |
|
815 | + * Get the fonts directory local url. |
|
816 | + * |
|
817 | + * @since 1.1.0 |
|
818 | + * |
|
819 | + * @param string Fonts directory local url. |
|
820 | + */ |
|
821 | + public function get_fonts_url() { |
|
822 | + $upload_dir = wp_upload_dir( null, false ); |
|
823 | + |
|
824 | + return $upload_dir['baseurl'] . '/ayefonts/fa/'; |
|
825 | + } |
|
826 | + |
|
827 | + /** |
|
828 | + * Check whether load locally active. |
|
829 | + * |
|
830 | + * @since 1.1.0 |
|
831 | + * |
|
832 | + * @return bool True if active else false. |
|
833 | + */ |
|
834 | + public function has_local() { |
|
835 | + if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
836 | + return true; |
|
837 | + } |
|
838 | + |
|
839 | + return false; |
|
840 | + } |
|
841 | + |
|
842 | + /** |
|
843 | + * Get the WP Filesystem access. |
|
844 | + * |
|
845 | + * @since 1.1.0 |
|
846 | + * |
|
847 | + * @return object The WP Filesystem. |
|
848 | + */ |
|
849 | + public function get_wp_filesystem() { |
|
850 | + if ( ! function_exists( 'get_filesystem_method' ) ) { |
|
851 | + require_once( ABSPATH . "/wp-admin/includes/file.php" ); |
|
852 | + } |
|
853 | + |
|
854 | + $access_type = get_filesystem_method(); |
|
855 | + |
|
856 | + if ( $access_type === 'direct' ) { |
|
857 | + /* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */ |
|
858 | + $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
859 | + |
|
860 | + /* Initialize the API */ |
|
861 | + if ( ! WP_Filesystem( $creds ) ) { |
|
862 | + /* Any problems and we exit */ |
|
863 | + return false; |
|
864 | + } |
|
865 | + |
|
866 | + global $wp_filesystem; |
|
867 | + |
|
868 | + return $wp_filesystem; |
|
869 | + /* Do our file manipulations below */ |
|
870 | + } else if ( defined( 'FTP_USER' ) ) { |
|
871 | + $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
872 | + |
|
873 | + /* Initialize the API */ |
|
874 | + if ( ! WP_Filesystem( $creds ) ) { |
|
875 | + /* Any problems and we exit */ |
|
876 | + return false; |
|
877 | + } |
|
878 | + |
|
879 | + global $wp_filesystem; |
|
880 | + |
|
881 | + return $wp_filesystem; |
|
882 | + } else { |
|
883 | + /* Don't have direct write access. Prompt user with our notice */ |
|
884 | + return false; |
|
885 | + } |
|
886 | + } |
|
887 | + |
|
888 | + /** |
|
889 | + * Download the fontawesome package file. |
|
890 | + * |
|
891 | + * @since 1.1.0 |
|
892 | + * |
|
893 | + * @param mixed $version The font awesome. |
|
894 | + * @param array $option Fontawesome settings. |
|
895 | + * @return WP_ERROR|bool Error on fail and true on success. |
|
896 | + */ |
|
897 | + public function download_package( $version, $option = array() ) { |
|
898 | + $filename = 'fontawesome-free-' . $version . '-web'; |
|
899 | + $url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip'; |
|
900 | + |
|
901 | + if ( ! function_exists( 'wp_handle_upload' ) ) { |
|
902 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
903 | + } |
|
904 | + |
|
905 | + $download_file = download_url( esc_url_raw( $url ) ); |
|
906 | + |
|
907 | + if ( is_wp_error( $download_file ) ) { |
|
908 | + return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'ayecode-connect' ) ); |
|
909 | + } else if ( empty( $download_file ) ) { |
|
910 | + return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'ayecode-connect' ) ); |
|
911 | + } |
|
912 | + |
|
913 | + $response = $this->extract_package( $download_file, $filename, true ); |
|
914 | + |
|
915 | + // Update local version. |
|
916 | + if ( is_wp_error( $response ) ) { |
|
917 | + return $response; |
|
918 | + } else if ( $response ) { |
|
919 | + if ( empty( $option ) ) { |
|
920 | + $option = get_option( 'wp-font-awesome-settings' ); |
|
921 | + } |
|
922 | + |
|
923 | + $option['local_version'] = $version; |
|
924 | + |
|
925 | + // Remove action to prevent looping. |
|
926 | + remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
927 | + |
|
928 | + update_option( 'wp-font-awesome-settings', $option ); |
|
929 | + |
|
930 | + return true; |
|
931 | + } |
|
932 | + |
|
933 | + return false; |
|
934 | + } |
|
935 | + |
|
936 | + /** |
|
937 | + * Extract the fontawesome package file. |
|
938 | + * |
|
939 | + * @since 1.1.0 |
|
940 | + * |
|
941 | + * @param string $package The package file path. |
|
942 | + * @param string $dirname Package file name. |
|
943 | + * @param bool $delete_package Delete temp file or not. |
|
944 | + * @return WP_Error|bool True on success WP_Error on fail. |
|
945 | + */ |
|
946 | + public function extract_package( $package, $dirname = '', $delete_package = false ) { |
|
947 | + global $wp_filesystem; |
|
948 | + |
|
949 | + $wp_filesystem = $this->get_wp_filesystem(); |
|
950 | + |
|
951 | + if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { |
|
952 | + return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'ayecode-connect' ) ); |
|
953 | + } else if ( empty( $wp_filesystem ) ) { |
|
954 | + return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'ayecode-connect' ) ); |
|
955 | + } |
|
956 | + |
|
957 | + $fonts_dir = $this->get_fonts_dir(); |
|
958 | + $fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR; |
|
959 | + |
|
960 | + if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
961 | + $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
962 | + } |
|
963 | + |
|
964 | + // Unzip package to working directory. |
|
965 | + $result = unzip_file( $package, $fonts_tmp_dir ); |
|
966 | + |
|
967 | + if ( is_wp_error( $result ) ) { |
|
968 | + $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
969 | + |
|
970 | + if ( 'incompatible_archive' === $result->get_error_code() ) { |
|
971 | + return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'ayecode-connect' ) ); |
|
972 | + } |
|
973 | + |
|
974 | + return $result; |
|
975 | + } |
|
976 | + |
|
977 | + if ( $wp_filesystem->is_dir( $fonts_dir ) ) { |
|
978 | + $wp_filesystem->delete( $fonts_dir, true ); |
|
979 | + } |
|
980 | + |
|
981 | + $extract_dir = $fonts_tmp_dir; |
|
982 | + |
|
983 | + if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) { |
|
984 | + $extract_dir .= $dirname . DIRECTORY_SEPARATOR; |
|
985 | + } |
|
986 | + |
|
987 | + try { |
|
988 | + $return = $wp_filesystem->move( $extract_dir, $fonts_dir, true ); |
|
989 | + } catch ( Exception $e ) { |
|
990 | + $return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'ayecode-connect' ) ); |
|
991 | + } |
|
992 | + |
|
993 | + if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
994 | + $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
995 | + } |
|
996 | + |
|
997 | + // Once extracted, delete the package if required. |
|
998 | + if ( $delete_package ) { |
|
999 | + unlink( $package ); |
|
1000 | + } |
|
1001 | + |
|
1002 | + return $return; |
|
1003 | + } |
|
1004 | + |
|
1005 | + /** |
|
1006 | + * Output the version in the header. |
|
1007 | + */ |
|
1008 | + public function add_generator() { |
|
1009 | + $file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) ); |
|
1010 | + $plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) ); |
|
1011 | + |
|
1012 | + // Find source plugin/theme. |
|
1013 | + $source = array(); |
|
1014 | + if ( strpos( $file, $plugins_dir ) !== false ) { |
|
1015 | + $source = explode( "/", plugin_basename( $file ) ); |
|
1016 | + } else if ( function_exists( 'get_theme_root' ) ) { |
|
1017 | + $themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) ); |
|
1018 | + |
|
1019 | + if ( strpos( $file, $themes_dir ) !== false ) { |
|
1020 | + $source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) ); |
|
1021 | + } |
|
1022 | + } |
|
1023 | + |
|
1024 | + echo '<meta name="generator" content="WP Font Awesome Settings v' . esc_attr( $this->version ) . '"' . ( ! empty( $source[0] ) ? ' data-ac-source="' . esc_attr( $source[0] ) . '"' : '' ) . ' />'; |
|
1025 | + } |
|
1026 | + |
|
1027 | + /** |
|
1028 | + * Add extra parameters to the script tag. |
|
1029 | + * |
|
1030 | + * Add crossorigin="anonymous" to prevent OpaqueResponseBlocking |
|
1031 | + * (NS_BINDING_ABORTED) http error. |
|
1032 | + * |
|
1033 | + * @since 1.1.8 |
|
1034 | + * |
|
1035 | + * @param string $tag The script tag. |
|
1036 | + * @param string $handle The script handle. |
|
1037 | + * @param string $src The script url. |
|
1038 | + * @return string The script tag. |
|
1039 | + */ |
|
1040 | + public function script_loader_tag( $tag, $handle, $src ) { |
|
1041 | + if ( ( $handle == 'font-awesome' || $handle == 'font-awesome-shims' ) && ( strpos( $src, "kit.fontawesome.com" ) !== false || strpos( $src, ".fontawesome.com/releases/" ) !== false ) ) { |
|
1042 | + $tag = preg_replace( |
|
1043 | + '/<script[\s]+(.*?)>/', |
|
1044 | + '<script defer crossorigin="anonymous" \1>', |
|
1045 | + $tag |
|
1046 | + ); |
|
1047 | + } |
|
1048 | + |
|
1049 | + return $tag; |
|
1050 | + } |
|
1051 | + } |
|
1052 | + |
|
1053 | + /** |
|
1054 | + * Run the class if found. |
|
1055 | + */ |
|
1056 | + WP_Font_Awesome_Settings::instance(); |
|
1057 | 1057 | } |
@@ -12,14 +12,14 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if (!defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Only add if the class does not already exist. |
21 | 21 | */ |
22 | -if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
|
22 | +if (!class_exists('WP_Font_Awesome_Settings')) { |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * A Class to be able to change settings for Font Awesome. |
@@ -82,19 +82,19 @@ discard block |
||
82 | 82 | * @return WP_Font_Awesome_Settings - Main instance. |
83 | 83 | */ |
84 | 84 | public static function instance() { |
85 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
85 | + if (!isset(self::$instance) && !(self::$instance instanceof WP_Font_Awesome_Settings)) { |
|
86 | 86 | self::$instance = new WP_Font_Awesome_Settings; |
87 | 87 | |
88 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
88 | + add_action('init', array(self::$instance, 'init')); // set settings |
|
89 | 89 | |
90 | - if ( is_admin() ) { |
|
91 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
92 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
93 | - add_action( 'admin_init', array( self::$instance, 'constants' ) ); |
|
94 | - add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
90 | + if (is_admin()) { |
|
91 | + add_action('admin_menu', array(self::$instance, 'menu_item')); |
|
92 | + add_action('admin_init', array(self::$instance, 'register_settings')); |
|
93 | + add_action('admin_init', array(self::$instance, 'constants')); |
|
94 | + add_action('admin_notices', array(self::$instance, 'admin_notices')); |
|
95 | 95 | } |
96 | 96 | |
97 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
97 | + do_action('wp_font_awesome_settings_loaded'); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | return self::$instance; |
@@ -105,26 +105,26 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @return void |
107 | 107 | */ |
108 | - public function constants(){ |
|
108 | + public function constants() { |
|
109 | 109 | |
110 | 110 | // register iconpicker constant |
111 | - if ( ! defined( 'FAS_ICONPICKER_JS_URL' ) ) { |
|
111 | + if (!defined('FAS_ICONPICKER_JS_URL')) { |
|
112 | 112 | $url = $this->get_path_url(); |
113 | 113 | $version = $this->settings['version']; |
114 | 114 | |
115 | - if( !$version || version_compare($version,'5.999','>')){ |
|
115 | + if (!$version || version_compare($version, '5.999', '>')) { |
|
116 | 116 | $url .= 'assets/js/fa-iconpicker-v6.min.js'; |
117 | - }else{ |
|
117 | + } else { |
|
118 | 118 | $url .= 'assets/js/fa-iconpicker-v5.min.js'; |
119 | 119 | } |
120 | 120 | |
121 | - define( 'FAS_ICONPICKER_JS_URL', $url ); |
|
121 | + define('FAS_ICONPICKER_JS_URL', $url); |
|
122 | 122 | |
123 | 123 | } |
124 | 124 | |
125 | 125 | // Set a constant if pro enabled |
126 | - if ( ! defined( 'FAS_PRO' ) && $this->settings['pro'] ) { |
|
127 | - define( 'FAS_PRO', true ); |
|
126 | + if (!defined('FAS_PRO') && $this->settings['pro']) { |
|
127 | + define('FAS_PRO', true); |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | |
@@ -134,19 +134,19 @@ discard block |
||
134 | 134 | * @return string |
135 | 135 | */ |
136 | 136 | public function get_path_url() { |
137 | - $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) ); |
|
138 | - $content_url = untrailingslashit( WP_CONTENT_URL ); |
|
137 | + $content_dir = wp_normalize_path(untrailingslashit(WP_CONTENT_DIR)); |
|
138 | + $content_url = untrailingslashit(WP_CONTENT_URL); |
|
139 | 139 | |
140 | 140 | // Replace http:// to https://. |
141 | - if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) { |
|
142 | - $content_url = str_replace( 'http://', 'https://', $content_url ); |
|
141 | + if (strpos($content_url, 'http://') === 0 && strpos(plugins_url(), 'https://') === 0) { |
|
142 | + $content_url = str_replace('http://', 'https://', $content_url); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | // Check if we are inside a plugin |
146 | - $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
147 | - $url = str_replace( $content_dir, $content_url, $file_dir ); |
|
146 | + $file_dir = str_replace("/includes", "", wp_normalize_path(dirname(__FILE__))); |
|
147 | + $url = str_replace($content_dir, $content_url, $file_dir); |
|
148 | 148 | |
149 | - return trailingslashit( $url ); |
|
149 | + return trailingslashit($url); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -156,53 +156,53 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public function init() { |
158 | 158 | // Download fontawesome locally. |
159 | - add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 ); |
|
160 | - add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
159 | + add_action('add_option_wp-font-awesome-settings', array($this, 'add_option_wp_font_awesome_settings'), 10, 2); |
|
160 | + add_action('update_option_wp-font-awesome-settings', array($this, 'update_option_wp_font_awesome_settings'), 10, 2); |
|
161 | 161 | |
162 | 162 | $this->settings = $this->get_settings(); |
163 | 163 | |
164 | 164 | // Check if the official plugin is active and use that instead if so. |
165 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
166 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
167 | - add_action( 'admin_head', array( $this, 'add_generator' ), 99 ); |
|
165 | + if (!defined('FONTAWESOME_PLUGIN_FILE')) { |
|
166 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
167 | + add_action('admin_head', array($this, 'add_generator'), 99); |
|
168 | 168 | } |
169 | 169 | |
170 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
171 | - add_action( 'wp_head', array( $this, 'add_generator' ), 99 ); |
|
170 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
171 | + add_action('wp_head', array($this, 'add_generator'), 99); |
|
172 | 172 | } |
173 | 173 | |
174 | - if ( $this->settings['type'] == 'CSS' ) { |
|
175 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
176 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
174 | + if ($this->settings['type'] == 'CSS') { |
|
175 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
176 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
177 | 177 | //add_action( 'wp_footer', array( $this, 'enqueue_style' ), 5000 ); // not sure why this was added, seems to break frontend |
178 | 178 | } |
179 | 179 | |
180 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
181 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
182 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 ); |
|
180 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
181 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
182 | + add_filter('block_editor_settings_all', array($this, 'enqueue_editor_styles'), 10, 2); |
|
183 | 183 | } |
184 | 184 | } else { |
185 | 185 | $enqueue = false; |
186 | 186 | |
187 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
187 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
188 | 188 | $enqueue = true; |
189 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
189 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
190 | 190 | } |
191 | 191 | |
192 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
192 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
193 | 193 | $enqueue = true; |
194 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
195 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 ); |
|
194 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
195 | + add_filter('block_editor_settings_all', array($this, 'enqueue_editor_scripts'), 10, 2); |
|
196 | 196 | } |
197 | 197 | |
198 | - if ( $enqueue ) { |
|
199 | - add_filter( 'script_loader_tag', array( $this, 'script_loader_tag' ), 20, 3 ); |
|
198 | + if ($enqueue) { |
|
199 | + add_filter('script_loader_tag', array($this, 'script_loader_tag'), 20, 3); |
|
200 | 200 | } |
201 | 201 | } |
202 | 202 | |
203 | 203 | // remove font awesome if set to do so |
204 | - if ( $this->settings['dequeue'] == '1' ) { |
|
205 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
204 | + if ($this->settings['dequeue'] == '1') { |
|
205 | + add_action('clean_url', array($this, 'remove_font_awesome'), 5000, 3); |
|
206 | 206 | } |
207 | 207 | } |
208 | 208 | |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | * |
217 | 217 | * @return array |
218 | 218 | */ |
219 | - public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
|
219 | + public function enqueue_editor_styles($editor_settings, $block_editor_context) { |
|
220 | 220 | |
221 | - if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
|
221 | + if (!empty($editor_settings['__unstableResolvedAssets']['styles'])) { |
|
222 | 222 | $url = $this->get_url(); |
223 | 223 | $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
224 | 224 | } |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | * |
235 | 235 | * @return array |
236 | 236 | */ |
237 | - public function enqueue_editor_scripts( $editor_settings, $block_editor_context ) { |
|
237 | + public function enqueue_editor_scripts($editor_settings, $block_editor_context) { |
|
238 | 238 | $url = $this->get_url(); |
239 | 239 | |
240 | 240 | $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js' defer crossorigin='anonymous'></script>"; |
@@ -248,22 +248,22 @@ discard block |
||
248 | 248 | public function enqueue_style() { |
249 | 249 | // build url |
250 | 250 | $url = $this->get_url(); |
251 | - $version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null; |
|
251 | + $version = !empty($this->settings['local']) && empty($this->settings['pro']) ? strip_tags($this->settings['local_version']) : null; |
|
252 | 252 | |
253 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
254 | - wp_register_style( 'font-awesome', $url, array(), $version ); |
|
255 | - wp_enqueue_style( 'font-awesome' ); |
|
253 | + wp_deregister_style('font-awesome'); // deregister in case its already there |
|
254 | + wp_register_style('font-awesome', $url, array(), $version); |
|
255 | + wp_enqueue_style('font-awesome'); |
|
256 | 256 | |
257 | 257 | // RTL language support CSS. |
258 | - if ( is_rtl() ) { |
|
259 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
258 | + if (is_rtl()) { |
|
259 | + wp_add_inline_style('font-awesome', $this->rtl_inline_css()); |
|
260 | 260 | } |
261 | 261 | |
262 | - if ( $this->settings['shims'] ) { |
|
263 | - $url = $this->get_url( true ); |
|
264 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
265 | - wp_register_style( 'font-awesome-shims', $url, array(), $version ); |
|
266 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
262 | + if ($this->settings['shims']) { |
|
263 | + $url = $this->get_url(true); |
|
264 | + wp_deregister_style('font-awesome-shims'); // deregister in case its already there |
|
265 | + wp_register_style('font-awesome-shims', $url, array(), $version); |
|
266 | + wp_enqueue_style('font-awesome-shims'); |
|
267 | 267 | } |
268 | 268 | } |
269 | 269 | |
@@ -275,15 +275,15 @@ discard block |
||
275 | 275 | $url = $this->get_url(); |
276 | 276 | |
277 | 277 | $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
278 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
279 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
280 | - wp_enqueue_script( 'font-awesome' ); |
|
281 | - |
|
282 | - if ( $this->settings['shims'] ) { |
|
283 | - $url = $this->get_url( true ); |
|
284 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
285 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
286 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
278 | + call_user_func($deregister_function, 'font-awesome'); // deregister in case its already there |
|
279 | + wp_register_script('font-awesome', $url, array(), null); |
|
280 | + wp_enqueue_script('font-awesome'); |
|
281 | + |
|
282 | + if ($this->settings['shims']) { |
|
283 | + $url = $this->get_url(true); |
|
284 | + call_user_func($deregister_function, 'font-awesome-shims'); // deregister in case its already there |
|
285 | + wp_register_script('font-awesome-shims', $url, array(), null); |
|
286 | + wp_enqueue_script('font-awesome-shims'); |
|
287 | 287 | } |
288 | 288 | } |
289 | 289 | |
@@ -295,16 +295,16 @@ discard block |
||
295 | 295 | * |
296 | 296 | * @return string The url to the file. |
297 | 297 | */ |
298 | - public function get_url( $shims = false, $local = true ) { |
|
298 | + public function get_url($shims = false, $local = true) { |
|
299 | 299 | $script = $shims ? 'v4-shims' : 'all'; |
300 | 300 | $sub = $this->settings['pro'] ? 'pro' : 'use'; |
301 | 301 | $type = $this->settings['type']; |
302 | 302 | $version = $this->settings['version']; |
303 | - $kit_url = $this->settings['kit-url'] ? sanitize_text_field( $this->settings['kit-url'] ) : ''; |
|
303 | + $kit_url = $this->settings['kit-url'] ? sanitize_text_field($this->settings['kit-url']) : ''; |
|
304 | 304 | $url = ''; |
305 | 305 | |
306 | - if ( $type == 'KIT' && $kit_url ) { |
|
307 | - if ( $shims ) { |
|
306 | + if ($type == 'KIT' && $kit_url) { |
|
307 | + if ($shims) { |
|
308 | 308 | // if its a kit then we don't add shims here |
309 | 309 | return ''; |
310 | 310 | } |
@@ -313,13 +313,13 @@ discard block |
||
313 | 313 | } else { |
314 | 314 | $v = ''; |
315 | 315 | // Check and load locally. |
316 | - if ( $local && $this->has_local() ) { |
|
316 | + if ($local && $this->has_local()) { |
|
317 | 317 | $script .= ".min"; |
318 | - $v .= '&ver=' . strip_tags( $this->settings['local_version'] ); |
|
318 | + $v .= '&ver=' . strip_tags($this->settings['local_version']); |
|
319 | 319 | $url .= $this->get_fonts_url(); // Local fonts url. |
320 | 320 | } else { |
321 | 321 | $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
322 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
322 | + $url .= !empty($version) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
323 | 323 | } |
324 | 324 | $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
325 | 325 | $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
@@ -340,16 +340,16 @@ discard block |
||
340 | 340 | * |
341 | 341 | * @return string The filtered url. |
342 | 342 | */ |
343 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
343 | + public function remove_font_awesome($url, $original_url, $_context) { |
|
344 | 344 | |
345 | - if ( $_context == 'display' |
|
346 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
347 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
345 | + if ($_context == 'display' |
|
346 | + && (strstr($url, "fontawesome") !== false || strstr($url, "font-awesome") !== false) |
|
347 | + && (strstr($url, ".js") !== false || strstr($url, ".css") !== false) |
|
348 | 348 | ) {// it's a font-awesome-url (probably) |
349 | 349 | |
350 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
351 | - if ( $this->settings['type'] == 'JS' ) { |
|
352 | - if ( $this->settings['js-pseudo'] ) { |
|
350 | + if (strstr($url, "wpfas=true") !== false) { |
|
351 | + if ($this->settings['type'] == 'JS') { |
|
352 | + if ($this->settings['js-pseudo']) { |
|
353 | 353 | $url .= "' data-search-pseudo-elements defer='defer"; |
354 | 354 | } else { |
355 | 355 | $url .= "' defer='defer"; |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | * Register the database settings with WordPress. |
369 | 369 | */ |
370 | 370 | public function register_settings() { |
371 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
371 | + register_setting('wp-font-awesome-settings', 'wp-font-awesome-settings'); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
@@ -377,10 +377,10 @@ discard block |
||
377 | 377 | */ |
378 | 378 | public function menu_item() { |
379 | 379 | $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
380 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
380 | + call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
381 | 381 | $this, |
382 | 382 | 'settings_page' |
383 | - ) ); |
|
383 | + )); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | /** |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | * @return array The array of settings. |
390 | 390 | */ |
391 | 391 | public function get_settings() { |
392 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
392 | + $db_settings = get_option('wp-font-awesome-settings'); |
|
393 | 393 | |
394 | 394 | $defaults = array( |
395 | 395 | 'type' => 'CSS', // type to use, CSS or JS or KIT |
@@ -404,30 +404,30 @@ discard block |
||
404 | 404 | 'kit-url' => '', // the kit url |
405 | 405 | ); |
406 | 406 | |
407 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
407 | + $settings = wp_parse_args($db_settings, $defaults); |
|
408 | 408 | |
409 | 409 | /** |
410 | 410 | * Filter the Font Awesome settings. |
411 | 411 | * |
412 | 412 | * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
413 | 413 | */ |
414 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
414 | + return $this->settings = apply_filters('wp-font-awesome-settings', $settings, $db_settings, $defaults); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | /** |
418 | 418 | * The settings page html output. |
419 | 419 | */ |
420 | 420 | public function settings_page() { |
421 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
422 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'ayecode-connect' ) ); |
|
421 | + if (!current_user_can('manage_options')) { |
|
422 | + wp_die(__('You do not have sufficient permissions to access this page.', 'ayecode-connect')); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
426 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
427 | - $this->get_latest_version( $force_api = true ); |
|
426 | + if (isset($_REQUEST['force-version-check'])) { |
|
427 | + $this->get_latest_version($force_api = true); |
|
428 | 428 | } |
429 | 429 | |
430 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
430 | + if (!defined('FONTAWESOME_PLUGIN_FILE')) { |
|
431 | 431 | ?> |
432 | 432 | <style> |
433 | 433 | .wpfas-kit-show { |
@@ -454,42 +454,42 @@ discard block |
||
454 | 454 | <h1><?php echo $this->name; ?></h1> |
455 | 455 | <form method="post" action="options.php" class="fas-settings-form"> |
456 | 456 | <?php |
457 | - settings_fields( 'wp-font-awesome-settings' ); |
|
458 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
457 | + settings_fields('wp-font-awesome-settings'); |
|
458 | + do_settings_sections('wp-font-awesome-settings'); |
|
459 | 459 | $table_class = ''; |
460 | - if ( $this->settings['type'] ) { |
|
461 | - $table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set'; |
|
460 | + if ($this->settings['type']) { |
|
461 | + $table_class .= 'wpfas-' . sanitize_html_class(strtolower($this->settings['type'])) . '-set'; |
|
462 | 462 | } |
463 | - if ( ! empty( $this->settings['pro'] ) ) { |
|
463 | + if (!empty($this->settings['pro'])) { |
|
464 | 464 | $table_class .= ' wpfas-has-pro'; |
465 | 465 | } |
466 | 466 | ?> |
467 | - <?php if ( $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ) { ?> |
|
468 | - <?php if ( $this->has_local() ) { ?> |
|
469 | - <div class="notice notice-info"><p><strong><?php _e( 'Font Awesome fonts are loading locally.', 'ayecode-connect' ); ?></strong></p></div> |
|
467 | + <?php if ($this->settings['type'] != 'KIT' && !empty($this->settings['local']) && empty($this->settings['pro'])) { ?> |
|
468 | + <?php if ($this->has_local()) { ?> |
|
469 | + <div class="notice notice-info"><p><strong><?php _e('Font Awesome fonts are loading locally.', 'ayecode-connect'); ?></strong></p></div> |
|
470 | 470 | <?php } else { ?> |
471 | - <div class="notice notice-error"><p><strong><?php _e( 'Font Awesome fonts are not loading locally!', 'ayecode-connect' ); ?></strong></p></div> |
|
471 | + <div class="notice notice-error"><p><strong><?php _e('Font Awesome fonts are not loading locally!', 'ayecode-connect'); ?></strong></p></div> |
|
472 | 472 | <?php } ?> |
473 | 473 | <?php } ?> |
474 | - <table class="form-table wpfas-table-settings <?php echo esc_attr( $table_class ); ?>"> |
|
474 | + <table class="form-table wpfas-table-settings <?php echo esc_attr($table_class); ?>"> |
|
475 | 475 | <tr valign="top"> |
476 | - <th scope="row"><label for="wpfas-type"><?php _e( 'Type', 'ayecode-connect' ); ?></label></th> |
|
476 | + <th scope="row"><label for="wpfas-type"><?php _e('Type', 'ayecode-connect'); ?></label></th> |
|
477 | 477 | <td> |
478 | 478 | <select name="wp-font-awesome-settings[type]" id="wpfas-type" onchange="if(this.value=='KIT'){jQuery('.wpfas-table-settings').addClass('wpfas-kit-set');}else{jQuery('.wpfas-table-settings').removeClass('wpfas-kit-set');}"> |
479 | - <option value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e( 'CSS (default)', 'ayecode-connect' ); ?></option> |
|
480 | - <option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option> |
|
481 | - <option value="KIT" <?php selected( $this->settings['type'], 'KIT' ); ?>><?php _e( 'Kits (settings managed on fontawesome.com)', 'ayecode-connect' ); ?></option> |
|
479 | + <option value="CSS" <?php selected($this->settings['type'], 'CSS'); ?>><?php _e('CSS (default)', 'ayecode-connect'); ?></option> |
|
480 | + <option value="JS" <?php selected($this->settings['type'], 'JS'); ?>>JS</option> |
|
481 | + <option value="KIT" <?php selected($this->settings['type'], 'KIT'); ?>><?php _e('Kits (settings managed on fontawesome.com)', 'ayecode-connect'); ?></option> |
|
482 | 482 | </select> |
483 | 483 | </td> |
484 | 484 | </tr> |
485 | 485 | |
486 | 486 | <tr valign="top" class="wpfas-kit-show"> |
487 | - <th scope="row"><label for="wpfas-kit-url"><?php _e( 'Kit URL', 'ayecode-connect' ); ?></label></th> |
|
487 | + <th scope="row"><label for="wpfas-kit-url"><?php _e('Kit URL', 'ayecode-connect'); ?></label></th> |
|
488 | 488 | <td> |
489 | - <input class="regular-text" id="wpfas-kit-url" type="url" name="wp-font-awesome-settings[kit-url]" value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
|
489 | + <input class="regular-text" id="wpfas-kit-url" type="url" name="wp-font-awesome-settings[kit-url]" value="<?php echo esc_attr($this->settings['kit-url']); ?>" placeholder="<?php echo 'https://kit.font'; echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
|
490 | 490 | <span><?php |
491 | 491 | echo wp_sprintf( |
492 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'ayecode-connect' ), |
|
492 | + __('Requires a free account with Font Awesome. %sGet kit url%s', 'ayecode-connect'), |
|
493 | 493 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i> ', |
494 | 494 | '</a>' |
495 | 495 | ); |
@@ -497,54 +497,54 @@ discard block |
||
497 | 497 | </td> |
498 | 498 | </tr> |
499 | 499 | <tr valign="top" class="wpfas-kit-hide"> |
500 | - <th scope="row"><label for="wpfas-version"><?php _e( 'Version', 'ayecode-connect' ); ?></label></th> |
|
500 | + <th scope="row"><label for="wpfas-version"><?php _e('Version', 'ayecode-connect'); ?></label></th> |
|
501 | 501 | <td> |
502 | 502 | <select name="wp-font-awesome-settings[version]" id="wpfas-version"> |
503 | 503 | <?php /* @todo Remove after FA7 compatibility */ ?> |
504 | - <option value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo wp_sprintf( __( '%s (default)', 'ayecode-connect' ), '6.7.2' ); ?></option> |
|
505 | - <?php $latest_version = $this->get_latest_version( false, true ); if ( $latest_version && version_compare( $latest_version, '7.0.0', '>' ) ) { ?> |
|
506 | - <option value="<?php echo esc_attr( $latest_version ); ?>" <?php selected( $this->settings['version'], $latest_version ); ?>><?php echo esc_html( $latest_version ); ?></option> |
|
504 | + <option value="" <?php selected($this->settings['version'], ''); ?>><?php echo wp_sprintf(__('%s (default)', 'ayecode-connect'), '6.7.2'); ?></option> |
|
505 | + <?php $latest_version = $this->get_latest_version(false, true); if ($latest_version && version_compare($latest_version, '7.0.0', '>')) { ?> |
|
506 | + <option value="<?php echo esc_attr($latest_version); ?>" <?php selected($this->settings['version'], $latest_version); ?>><?php echo esc_html($latest_version); ?></option> |
|
507 | 507 | <?php } ?> |
508 | 508 | <?php /* @todo Remove after after FA7 compatibility */ ?> |
509 | 509 | |
510 | 510 | <?php /* @todo Un-comment after FA7 compatibility */ ?> |
511 | 511 | <?php /* ?><option value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo wp_sprintf( __( 'Latest - %s (default)', 'ayecode-connect' ), $this->get_latest_version() ); ?></option><?php */ ?> |
512 | - <option value="7.0.0" <?php selected( $this->settings['version'], '7.0.0' ); ?>>7.0.0</option> |
|
513 | - <option value="6.4.2" <?php selected( $this->settings['version'], '6.4.2' ); ?>>6.4.2</option> |
|
514 | - <option value="6.1.0" <?php selected( $this->settings['version'], '6.1.0' ); ?>>6.1.0</option> |
|
515 | - <option value="6.0.0" <?php selected( $this->settings['version'], '6.0.0' ); ?>>6.0.0</option> |
|
516 | - <option value="5.15.4" <?php selected( $this->settings['version'], '5.15.4' ); ?>>5.15.4</option> |
|
517 | - <option value="5.6.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>>5.6.0</option> |
|
518 | - <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>>5.5.0</option> |
|
519 | - <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>>5.4.0</option> |
|
520 | - <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>>5.3.0</option> |
|
521 | - <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>>5.2.0</option> |
|
522 | - <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>>5.1.0</option> |
|
523 | - <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>>4.7.1 (CSS only)</option> |
|
512 | + <option value="7.0.0" <?php selected($this->settings['version'], '7.0.0'); ?>>7.0.0</option> |
|
513 | + <option value="6.4.2" <?php selected($this->settings['version'], '6.4.2'); ?>>6.4.2</option> |
|
514 | + <option value="6.1.0" <?php selected($this->settings['version'], '6.1.0'); ?>>6.1.0</option> |
|
515 | + <option value="6.0.0" <?php selected($this->settings['version'], '6.0.0'); ?>>6.0.0</option> |
|
516 | + <option value="5.15.4" <?php selected($this->settings['version'], '5.15.4'); ?>>5.15.4</option> |
|
517 | + <option value="5.6.0" <?php selected($this->settings['version'], '5.6.0'); ?>>5.6.0</option> |
|
518 | + <option value="5.5.0" <?php selected($this->settings['version'], '5.5.0'); ?>>5.5.0</option> |
|
519 | + <option value="5.4.0" <?php selected($this->settings['version'], '5.4.0'); ?>>5.4.0</option> |
|
520 | + <option value="5.3.0" <?php selected($this->settings['version'], '5.3.0'); ?>>5.3.0</option> |
|
521 | + <option value="5.2.0" <?php selected($this->settings['version'], '5.2.0'); ?>>5.2.0</option> |
|
522 | + <option value="5.1.0" <?php selected($this->settings['version'], '5.1.0'); ?>>5.1.0</option> |
|
523 | + <option value="4.7.0" <?php selected($this->settings['version'], '4.7.0'); ?>>4.7.1 (CSS only)</option> |
|
524 | 524 | </select> |
525 | 525 | </td> |
526 | 526 | </tr> |
527 | 527 | |
528 | 528 | <tr valign="top"> |
529 | - <th scope="row"><label for="wpfas-enqueue"><?php _e( 'Enqueue', 'ayecode-connect' ); ?></label></th> |
|
529 | + <th scope="row"><label for="wpfas-enqueue"><?php _e('Enqueue', 'ayecode-connect'); ?></label></th> |
|
530 | 530 | <td> |
531 | 531 | <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue"> |
532 | - <option value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)', 'ayecode-connect' ); ?></option> |
|
533 | - <option value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend', 'ayecode-connect' ); ?></option> |
|
534 | - <option value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend', 'ayecode-connect' ); ?></option> |
|
532 | + <option value="" <?php selected($this->settings['enqueue'], ''); ?>><?php _e('Frontend + Backend (default)', 'ayecode-connect'); ?></option> |
|
533 | + <option value="frontend" <?php selected($this->settings['enqueue'], 'frontend'); ?>><?php _e('Frontend', 'ayecode-connect'); ?></option> |
|
534 | + <option value="backend" <?php selected($this->settings['enqueue'], 'backend'); ?>><?php _e('Backend', 'ayecode-connect'); ?></option> |
|
535 | 535 | </select> |
536 | 536 | </td> |
537 | 537 | </tr> |
538 | 538 | |
539 | 539 | <tr valign="top" class="wpfas-kit-hide"> |
540 | 540 | <th scope="row"><label |
541 | - for="wpfas-pro"><?php _e( 'Enable pro', 'ayecode-connect' ); ?></label></th> |
|
541 | + for="wpfas-pro"><?php _e('Enable pro', 'ayecode-connect'); ?></label></th> |
|
542 | 542 | <td> |
543 | 543 | <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/> |
544 | - <input type="checkbox" name="wp-font-awesome-settings[pro]" value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro" onchange="if(jQuery(this).is(':checked')){jQuery('.wpfas-table-settings').addClass('wpfas-has-pro')}else{jQuery('.wpfas-table-settings').removeClass('wpfas-has-pro')}"/> |
|
544 | + <input type="checkbox" name="wp-font-awesome-settings[pro]" value="1" <?php checked($this->settings['pro'], '1'); ?> id="wpfas-pro" onchange="if(jQuery(this).is(':checked')){jQuery('.wpfas-table-settings').addClass('wpfas-has-pro')}else{jQuery('.wpfas-table-settings').removeClass('wpfas-has-pro')}"/> |
|
545 | 545 | <span><?php |
546 | 546 | echo wp_sprintf( |
547 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'ayecode-connect' ), |
|
547 | + __('Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'ayecode-connect'), |
|
548 | 548 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
549 | 549 | ' <i class="fas fa-external-link-alt"></i></a>', |
550 | 550 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
@@ -555,49 +555,49 @@ discard block |
||
555 | 555 | </tr> |
556 | 556 | |
557 | 557 | <tr valign="top" class="wpfas-kit-hide wpfas-hide-pro"> |
558 | - <th scope="row"><label for="wpfas-local"><?php _e( 'Load Fonts Locally', 'ayecode-connect' ); ?></label></th> |
|
558 | + <th scope="row"><label for="wpfas-local"><?php _e('Load Fonts Locally', 'ayecode-connect'); ?></label></th> |
|
559 | 559 | <td> |
560 | 560 | <input type="hidden" name="wp-font-awesome-settings[local]" value="0"/> |
561 | - <input type="hidden" name="wp-font-awesome-settings[local_version]" value="<?php echo esc_attr( $this->settings['local_version'] ); ?>"/> |
|
562 | - <input type="checkbox" name="wp-font-awesome-settings[local]" value="1" <?php checked( $this->settings['local'], '1' ); ?> id="wpfas-local"/> |
|
563 | - <span><?php _e( '(For free version only) Load FontAwesome fonts from locally. This downloads FontAwesome fonts from fontawesome.com & stores at the local site.', 'ayecode-connect' ); ?></span> |
|
561 | + <input type="hidden" name="wp-font-awesome-settings[local_version]" value="<?php echo esc_attr($this->settings['local_version']); ?>"/> |
|
562 | + <input type="checkbox" name="wp-font-awesome-settings[local]" value="1" <?php checked($this->settings['local'], '1'); ?> id="wpfas-local"/> |
|
563 | + <span><?php _e('(For free version only) Load FontAwesome fonts from locally. This downloads FontAwesome fonts from fontawesome.com & stores at the local site.', 'ayecode-connect'); ?></span> |
|
564 | 564 | </td> |
565 | 565 | </tr> |
566 | 566 | |
567 | 567 | <tr valign="top" class="wpfas-kit-hide"> |
568 | 568 | <th scope="row"><label |
569 | - for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility', 'ayecode-connect' ); ?></label> |
|
569 | + for="wpfas-shims"><?php _e('Enable v4 shims compatibility', 'ayecode-connect'); ?></label> |
|
570 | 570 | </th> |
571 | 571 | <td> |
572 | 572 | <input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/> |
573 | 573 | <input type="checkbox" name="wp-font-awesome-settings[shims]" |
574 | - value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims"/> |
|
575 | - <span><?php _e( 'This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'ayecode-connect' ); ?></span> |
|
574 | + value="1" <?php checked($this->settings['shims'], '1'); ?> id="wpfas-shims"/> |
|
575 | + <span><?php _e('This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'ayecode-connect'); ?></span> |
|
576 | 576 | </td> |
577 | 577 | </tr> |
578 | 578 | |
579 | 579 | <tr valign="top" class="wpfas-kit-hide"> |
580 | 580 | <th scope="row"><label |
581 | - for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)', 'ayecode-connect' ); ?></label> |
|
581 | + for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)', 'ayecode-connect'); ?></label> |
|
582 | 582 | </th> |
583 | 583 | <td> |
584 | 584 | <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/> |
585 | 585 | <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]" |
586 | - value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?> |
|
586 | + value="1" <?php checked($this->settings['js-pseudo'], '1'); ?> |
|
587 | 587 | id="wpfas-js-pseudo"/> |
588 | - <span><?php _e( 'Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'ayecode-connect' ); ?></span> |
|
588 | + <span><?php _e('Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'ayecode-connect'); ?></span> |
|
589 | 589 | </td> |
590 | 590 | </tr> |
591 | 591 | |
592 | 592 | <tr valign="top"> |
593 | 593 | <th scope="row"><label |
594 | - for="wpfas-dequeue"><?php _e( 'Dequeue', 'ayecode-connect' ); ?></label></th> |
|
594 | + for="wpfas-dequeue"><?php _e('Dequeue', 'ayecode-connect'); ?></label></th> |
|
595 | 595 | <td> |
596 | 596 | <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/> |
597 | 597 | <input type="checkbox" name="wp-font-awesome-settings[dequeue]" |
598 | - value="1" <?php checked( $this->settings['dequeue'], '1' ); ?> |
|
598 | + value="1" <?php checked($this->settings['dequeue'], '1'); ?> |
|
599 | 599 | id="wpfas-dequeue"/> |
600 | - <span><?php _e( 'This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'ayecode-connect' ); ?></span> |
|
600 | + <span><?php _e('This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'ayecode-connect'); ?></span> |
|
601 | 601 | </td> |
602 | 602 | </tr> |
603 | 603 | |
@@ -606,12 +606,12 @@ discard block |
||
606 | 606 | <?php |
607 | 607 | submit_button(); |
608 | 608 | ?> |
609 | - <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 24,000+ more icons with Font Awesome Pro','ayecode-connect'); ?> <i class="fas fa-external-link-alt"></i></a></p> |
|
609 | + <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 24,000+ more icons with Font Awesome Pro', 'ayecode-connect'); ?> <i class="fas fa-external-link-alt"></i></a></p> |
|
610 | 610 | |
611 | 611 | </div> |
612 | 612 | </form> |
613 | 613 | |
614 | - <div id="wpfas-version"><?php echo wp_sprintf(__( 'Version: %s (affiliate links provided)', 'ayecode-connect' ), $this->version ); ?></div> |
|
614 | + <div id="wpfas-version"><?php echo wp_sprintf(__('Version: %s (affiliate links provided)', 'ayecode-connect'), $this->version); ?></div> |
|
615 | 615 | </div> |
616 | 616 | <?php |
617 | 617 | } |
@@ -626,12 +626,12 @@ discard block |
||
626 | 626 | * |
627 | 627 | * @return string Either a valid version number or an empty string. |
628 | 628 | */ |
629 | - public function validate_version_number( $version ) { |
|
629 | + public function validate_version_number($version) { |
|
630 | 630 | |
631 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
631 | + if (version_compare($version, '0.0.1', '>=') >= 0) { |
|
632 | 632 | // valid |
633 | 633 | } else { |
634 | - $version = '';// not validated |
|
634 | + $version = ''; // not validated |
|
635 | 635 | } |
636 | 636 | |
637 | 637 | return $version; |
@@ -646,32 +646,32 @@ discard block |
||
646 | 646 | * @since 1.0.7 |
647 | 647 | * @return mixed|string The latest version number found. |
648 | 648 | */ |
649 | - public function get_latest_version( $force_api = false, $force_latest = false ) { |
|
649 | + public function get_latest_version($force_api = false, $force_latest = false) { |
|
650 | 650 | $latest_version = $this->latest; |
651 | 651 | |
652 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
652 | + $cache = get_transient('wp-font-awesome-settings-version'); |
|
653 | 653 | |
654 | - if ( $cache === false || $force_api ) { // its not set |
|
654 | + if ($cache === false || $force_api) { // its not set |
|
655 | 655 | $api_ver = $this->get_latest_version_from_api(); |
656 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
656 | + if (version_compare($api_ver, $this->latest, '>=') >= 0) { |
|
657 | 657 | $latest_version = $api_ver; |
658 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
658 | + set_transient('wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS); |
|
659 | 659 | } |
660 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
661 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
660 | + } elseif ($this->validate_version_number($cache)) { |
|
661 | + if (version_compare($cache, $this->latest, '>=') >= 0) { |
|
662 | 662 | $latest_version = $cache; |
663 | 663 | } |
664 | 664 | } |
665 | 665 | |
666 | 666 | // @todo remove after FA7 compatibility |
667 | - if ( ! $force_latest && version_compare( $cache, '7.0.0', '>=' ) >= 0 ) { |
|
667 | + if (!$force_latest && version_compare($cache, '7.0.0', '>=') >= 0) { |
|
668 | 668 | $latest_version = '6.7.2'; |
669 | 669 | } |
670 | 670 | |
671 | 671 | // Check and auto download fonts locally. |
672 | - if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) { |
|
673 | - if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) { |
|
674 | - $this->download_package( $latest_version ); |
|
672 | + if (empty($this->settings['pro']) && empty($this->settings['version']) && $this->settings['type'] != 'KIT' && !empty($this->settings['local']) && !empty($this->settings['local_version']) && !empty($latest_version)) { |
|
673 | + if (version_compare($latest_version, $this->settings['local_version'], '>') && is_admin() && !wp_doing_ajax()) { |
|
674 | + $this->download_package($latest_version); |
|
675 | 675 | } |
676 | 676 | } |
677 | 677 | |
@@ -686,10 +686,10 @@ discard block |
||
686 | 686 | */ |
687 | 687 | public function get_latest_version_from_api() { |
688 | 688 | $version = "0"; |
689 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
690 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
691 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
692 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
689 | + $response = wp_remote_get("https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest"); |
|
690 | + if (!is_wp_error($response) && is_array($response)) { |
|
691 | + $api_response = json_decode(wp_remote_retrieve_body($response), true); |
|
692 | + if (isset($api_response['tag_name']) && version_compare($api_response['tag_name'], $this->latest, '>=') >= 0 && empty($api_response['prerelease'])) { |
|
693 | 693 | $version = $api_response['tag_name']; |
694 | 694 | } |
695 | 695 | } |
@@ -717,21 +717,21 @@ discard block |
||
717 | 717 | public function admin_notices() { |
718 | 718 | $settings = $this->settings; |
719 | 719 | |
720 | - if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
721 | - if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
720 | + if (defined('FONTAWESOME_PLUGIN_FILE')) { |
|
721 | + if (!empty($_REQUEST['page']) && $_REQUEST['page'] == 'wp-font-awesome-settings') { |
|
722 | 722 | ?> |
723 | 723 | <div class="notice notice-error is-dismissible"> |
724 | - <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'ayecode-connect' ); ?></p> |
|
724 | + <p><?php _e('The Official Font Awesome Plugin is active, please adjust your settings there.', 'ayecode-connect'); ?></p> |
|
725 | 725 | </div> |
726 | 726 | <?php |
727 | 727 | } |
728 | 728 | } else { |
729 | - if ( ! empty( $settings ) ) { |
|
730 | - if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
729 | + if (!empty($settings)) { |
|
730 | + if ($settings['type'] != 'KIT' && $settings['pro'] && ($settings['version'] == '' || version_compare($settings['version'], '6', '>='))) { |
|
731 | 731 | $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
732 | 732 | ?> |
733 | 733 | <div class="notice notice-error is-dismissible"> |
734 | - <p><?php echo wp_sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'ayecode-connect' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p> |
|
734 | + <p><?php echo wp_sprintf(__('Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'ayecode-connect'), "<a href='" . esc_url_raw($link) . "'>", "</a>"); ?></p> |
|
735 | 735 | </div> |
736 | 736 | <?php |
737 | 737 | } |
@@ -747,20 +747,20 @@ discard block |
||
747 | 747 | * @param string $option The option name. |
748 | 748 | * @param mixed $value The option value. |
749 | 749 | */ |
750 | - public function add_option_wp_font_awesome_settings( $option, $value ) { |
|
750 | + public function add_option_wp_font_awesome_settings($option, $value) { |
|
751 | 751 | // Do nothing if WordPress is being installed. |
752 | - if ( wp_installing() ) { |
|
752 | + if (wp_installing()) { |
|
753 | 753 | return; |
754 | 754 | } |
755 | 755 | |
756 | - if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) { |
|
757 | - $version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version(); |
|
756 | + if (!empty($value['local']) && empty($value['pro']) && !(!empty($value['type']) && $value['type'] == 'KIT')) { |
|
757 | + $version = isset($value['version']) && $value['version'] ? $value['version'] : $this->get_latest_version(); |
|
758 | 758 | |
759 | - if ( ! empty( $version ) ) { |
|
760 | - $response = $this->download_package( $version, $value ); |
|
759 | + if (!empty($version)) { |
|
760 | + $response = $this->download_package($version, $value); |
|
761 | 761 | |
762 | - if ( is_wp_error( $response ) ) { |
|
763 | - add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' ); |
|
762 | + if (is_wp_error($response)) { |
|
763 | + add_settings_error('general', 'fontawesome_download', __('ERROR:', 'ayecode-connect') . ' ' . $response->get_error_message(), 'error'); |
|
764 | 764 | } |
765 | 765 | } |
766 | 766 | } |
@@ -774,25 +774,25 @@ discard block |
||
774 | 774 | * @param mixed $old_value The old option value. |
775 | 775 | * @param mixed $value The new option value. |
776 | 776 | */ |
777 | - public function update_option_wp_font_awesome_settings( $old_value, $new_value ) { |
|
777 | + public function update_option_wp_font_awesome_settings($old_value, $new_value) { |
|
778 | 778 | // Do nothing if WordPress is being installed. |
779 | - if ( wp_installing() ) { |
|
779 | + if (wp_installing()) { |
|
780 | 780 | return; |
781 | 781 | } |
782 | 782 | |
783 | - if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) { |
|
783 | + if (!empty($new_value['local']) && empty($new_value['pro']) && !(!empty($new_value['type']) && $new_value['type'] == 'KIT')) { |
|
784 | 784 | // Old values |
785 | - $old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' ); |
|
786 | - $old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0; |
|
785 | + $old_version = isset($old_value['version']) && $old_value['version'] ? $old_value['version'] : (isset($old_value['local_version']) ? $old_value['local_version'] : ''); |
|
786 | + $old_local = isset($old_value['local']) ? (int) $old_value['local'] : 0; |
|
787 | 787 | |
788 | 788 | // New values |
789 | - $new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version(); |
|
789 | + $new_version = isset($new_value['version']) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version(); |
|
790 | 790 | |
791 | - if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
792 | - $response = $this->download_package( $new_version, $new_value ); |
|
791 | + if (empty($old_local) || $old_version !== $new_version || !file_exists($this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css')) { |
|
792 | + $response = $this->download_package($new_version, $new_value); |
|
793 | 793 | |
794 | - if ( is_wp_error( $response ) ) { |
|
795 | - add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' ); |
|
794 | + if (is_wp_error($response)) { |
|
795 | + add_settings_error('general', 'fontawesome_download', __('ERROR:', 'ayecode-connect') . ' ' . $response->get_error_message(), 'error'); |
|
796 | 796 | } |
797 | 797 | } |
798 | 798 | } |
@@ -806,9 +806,9 @@ discard block |
||
806 | 806 | * @param string Fonts directory local path. |
807 | 807 | */ |
808 | 808 | public function get_fonts_dir() { |
809 | - $upload_dir = wp_upload_dir( null, false ); |
|
809 | + $upload_dir = wp_upload_dir(null, false); |
|
810 | 810 | |
811 | - return $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR; |
|
811 | + return $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR; |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | /** |
@@ -819,9 +819,9 @@ discard block |
||
819 | 819 | * @param string Fonts directory local url. |
820 | 820 | */ |
821 | 821 | public function get_fonts_url() { |
822 | - $upload_dir = wp_upload_dir( null, false ); |
|
822 | + $upload_dir = wp_upload_dir(null, false); |
|
823 | 823 | |
824 | - return $upload_dir['baseurl'] . '/ayefonts/fa/'; |
|
824 | + return $upload_dir['baseurl'] . '/ayefonts/fa/'; |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | /** |
@@ -832,7 +832,7 @@ discard block |
||
832 | 832 | * @return bool True if active else false. |
833 | 833 | */ |
834 | 834 | public function has_local() { |
835 | - if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
835 | + if (!empty($this->settings['local']) && empty($this->settings['pro']) && file_exists($this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css')) { |
|
836 | 836 | return true; |
837 | 837 | } |
838 | 838 | |
@@ -847,18 +847,18 @@ discard block |
||
847 | 847 | * @return object The WP Filesystem. |
848 | 848 | */ |
849 | 849 | public function get_wp_filesystem() { |
850 | - if ( ! function_exists( 'get_filesystem_method' ) ) { |
|
851 | - require_once( ABSPATH . "/wp-admin/includes/file.php" ); |
|
850 | + if (!function_exists('get_filesystem_method')) { |
|
851 | + require_once(ABSPATH . "/wp-admin/includes/file.php"); |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | $access_type = get_filesystem_method(); |
855 | 855 | |
856 | - if ( $access_type === 'direct' ) { |
|
856 | + if ($access_type === 'direct') { |
|
857 | 857 | /* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */ |
858 | - $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
858 | + $creds = request_filesystem_credentials(trailingslashit(site_url()) . 'wp-admin/', '', false, false, array()); |
|
859 | 859 | |
860 | 860 | /* Initialize the API */ |
861 | - if ( ! WP_Filesystem( $creds ) ) { |
|
861 | + if (!WP_Filesystem($creds)) { |
|
862 | 862 | /* Any problems and we exit */ |
863 | 863 | return false; |
864 | 864 | } |
@@ -867,11 +867,11 @@ discard block |
||
867 | 867 | |
868 | 868 | return $wp_filesystem; |
869 | 869 | /* Do our file manipulations below */ |
870 | - } else if ( defined( 'FTP_USER' ) ) { |
|
871 | - $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
870 | + } else if (defined('FTP_USER')) { |
|
871 | + $creds = request_filesystem_credentials(trailingslashit(site_url()) . 'wp-admin/', '', false, false, array()); |
|
872 | 872 | |
873 | 873 | /* Initialize the API */ |
874 | - if ( ! WP_Filesystem( $creds ) ) { |
|
874 | + if (!WP_Filesystem($creds)) { |
|
875 | 875 | /* Any problems and we exit */ |
876 | 876 | return false; |
877 | 877 | } |
@@ -894,38 +894,38 @@ discard block |
||
894 | 894 | * @param array $option Fontawesome settings. |
895 | 895 | * @return WP_ERROR|bool Error on fail and true on success. |
896 | 896 | */ |
897 | - public function download_package( $version, $option = array() ) { |
|
897 | + public function download_package($version, $option = array()) { |
|
898 | 898 | $filename = 'fontawesome-free-' . $version . '-web'; |
899 | 899 | $url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip'; |
900 | 900 | |
901 | - if ( ! function_exists( 'wp_handle_upload' ) ) { |
|
901 | + if (!function_exists('wp_handle_upload')) { |
|
902 | 902 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
903 | 903 | } |
904 | 904 | |
905 | - $download_file = download_url( esc_url_raw( $url ) ); |
|
905 | + $download_file = download_url(esc_url_raw($url)); |
|
906 | 906 | |
907 | - if ( is_wp_error( $download_file ) ) { |
|
908 | - return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'ayecode-connect' ) ); |
|
909 | - } else if ( empty( $download_file ) ) { |
|
910 | - return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'ayecode-connect' ) ); |
|
907 | + if (is_wp_error($download_file)) { |
|
908 | + return new WP_Error('fontawesome_download_failed', __($download_file->get_error_message(), 'ayecode-connect')); |
|
909 | + } else if (empty($download_file)) { |
|
910 | + return new WP_Error('fontawesome_download_failed', __('Something went wrong in downloading the font awesome to store locally.', 'ayecode-connect')); |
|
911 | 911 | } |
912 | 912 | |
913 | - $response = $this->extract_package( $download_file, $filename, true ); |
|
913 | + $response = $this->extract_package($download_file, $filename, true); |
|
914 | 914 | |
915 | 915 | // Update local version. |
916 | - if ( is_wp_error( $response ) ) { |
|
916 | + if (is_wp_error($response)) { |
|
917 | 917 | return $response; |
918 | - } else if ( $response ) { |
|
919 | - if ( empty( $option ) ) { |
|
920 | - $option = get_option( 'wp-font-awesome-settings' ); |
|
918 | + } else if ($response) { |
|
919 | + if (empty($option)) { |
|
920 | + $option = get_option('wp-font-awesome-settings'); |
|
921 | 921 | } |
922 | 922 | |
923 | 923 | $option['local_version'] = $version; |
924 | 924 | |
925 | 925 | // Remove action to prevent looping. |
926 | - remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
926 | + remove_action('update_option_wp-font-awesome-settings', array($this, 'update_option_wp_font_awesome_settings'), 10, 2); |
|
927 | 927 | |
928 | - update_option( 'wp-font-awesome-settings', $option ); |
|
928 | + update_option('wp-font-awesome-settings', $option); |
|
929 | 929 | |
930 | 930 | return true; |
931 | 931 | } |
@@ -943,60 +943,60 @@ discard block |
||
943 | 943 | * @param bool $delete_package Delete temp file or not. |
944 | 944 | * @return WP_Error|bool True on success WP_Error on fail. |
945 | 945 | */ |
946 | - public function extract_package( $package, $dirname = '', $delete_package = false ) { |
|
946 | + public function extract_package($package, $dirname = '', $delete_package = false) { |
|
947 | 947 | global $wp_filesystem; |
948 | 948 | |
949 | 949 | $wp_filesystem = $this->get_wp_filesystem(); |
950 | 950 | |
951 | - if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { |
|
952 | - return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'ayecode-connect' ) ); |
|
953 | - } else if ( empty( $wp_filesystem ) ) { |
|
954 | - return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'ayecode-connect' ) ); |
|
951 | + if (empty($wp_filesystem) && isset($wp_filesystem->errors) && is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { |
|
952 | + return new WP_Error('fontawesome_filesystem_error', __($wp_filesystem->errors->get_error_message(), 'ayecode-connect')); |
|
953 | + } else if (empty($wp_filesystem)) { |
|
954 | + return new WP_Error('fontawesome_filesystem_error', __('Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'ayecode-connect')); |
|
955 | 955 | } |
956 | 956 | |
957 | 957 | $fonts_dir = $this->get_fonts_dir(); |
958 | - $fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR; |
|
958 | + $fonts_tmp_dir = dirname($fonts_dir) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR; |
|
959 | 959 | |
960 | - if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
961 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
960 | + if ($wp_filesystem->is_dir($fonts_tmp_dir)) { |
|
961 | + $wp_filesystem->delete($fonts_tmp_dir, true); |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | // Unzip package to working directory. |
965 | - $result = unzip_file( $package, $fonts_tmp_dir ); |
|
965 | + $result = unzip_file($package, $fonts_tmp_dir); |
|
966 | 966 | |
967 | - if ( is_wp_error( $result ) ) { |
|
968 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
967 | + if (is_wp_error($result)) { |
|
968 | + $wp_filesystem->delete($fonts_tmp_dir, true); |
|
969 | 969 | |
970 | - if ( 'incompatible_archive' === $result->get_error_code() ) { |
|
971 | - return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'ayecode-connect' ) ); |
|
970 | + if ('incompatible_archive' === $result->get_error_code()) { |
|
971 | + return new WP_Error('fontawesome_incompatible_archive', __($result->get_error_message(), 'ayecode-connect')); |
|
972 | 972 | } |
973 | 973 | |
974 | 974 | return $result; |
975 | 975 | } |
976 | 976 | |
977 | - if ( $wp_filesystem->is_dir( $fonts_dir ) ) { |
|
978 | - $wp_filesystem->delete( $fonts_dir, true ); |
|
977 | + if ($wp_filesystem->is_dir($fonts_dir)) { |
|
978 | + $wp_filesystem->delete($fonts_dir, true); |
|
979 | 979 | } |
980 | 980 | |
981 | 981 | $extract_dir = $fonts_tmp_dir; |
982 | 982 | |
983 | - if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) { |
|
983 | + if ($dirname && $wp_filesystem->is_dir($extract_dir . $dirname . DIRECTORY_SEPARATOR)) { |
|
984 | 984 | $extract_dir .= $dirname . DIRECTORY_SEPARATOR; |
985 | 985 | } |
986 | 986 | |
987 | 987 | try { |
988 | - $return = $wp_filesystem->move( $extract_dir, $fonts_dir, true ); |
|
989 | - } catch ( Exception $e ) { |
|
990 | - $return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'ayecode-connect' ) ); |
|
988 | + $return = $wp_filesystem->move($extract_dir, $fonts_dir, true); |
|
989 | + } catch (Exception $e) { |
|
990 | + $return = new WP_Error('fontawesome_move_package', __('Fail to move font awesome package!', 'ayecode-connect')); |
|
991 | 991 | } |
992 | 992 | |
993 | - if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
994 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
993 | + if ($wp_filesystem->is_dir($fonts_tmp_dir)) { |
|
994 | + $wp_filesystem->delete($fonts_tmp_dir, true); |
|
995 | 995 | } |
996 | 996 | |
997 | 997 | // Once extracted, delete the package if required. |
998 | - if ( $delete_package ) { |
|
999 | - unlink( $package ); |
|
998 | + if ($delete_package) { |
|
999 | + unlink($package); |
|
1000 | 1000 | } |
1001 | 1001 | |
1002 | 1002 | return $return; |
@@ -1006,22 +1006,22 @@ discard block |
||
1006 | 1006 | * Output the version in the header. |
1007 | 1007 | */ |
1008 | 1008 | public function add_generator() { |
1009 | - $file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) ); |
|
1010 | - $plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) ); |
|
1009 | + $file = str_replace(array("/", "\\"), "/", realpath(__FILE__)); |
|
1010 | + $plugins_dir = str_replace(array("/", "\\"), "/", realpath(WP_PLUGIN_DIR)); |
|
1011 | 1011 | |
1012 | 1012 | // Find source plugin/theme. |
1013 | 1013 | $source = array(); |
1014 | - if ( strpos( $file, $plugins_dir ) !== false ) { |
|
1015 | - $source = explode( "/", plugin_basename( $file ) ); |
|
1016 | - } else if ( function_exists( 'get_theme_root' ) ) { |
|
1017 | - $themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) ); |
|
1014 | + if (strpos($file, $plugins_dir) !== false) { |
|
1015 | + $source = explode("/", plugin_basename($file)); |
|
1016 | + } else if (function_exists('get_theme_root')) { |
|
1017 | + $themes_dir = str_replace(array("/", "\\"), "/", realpath(get_theme_root())); |
|
1018 | 1018 | |
1019 | - if ( strpos( $file, $themes_dir ) !== false ) { |
|
1020 | - $source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) ); |
|
1019 | + if (strpos($file, $themes_dir) !== false) { |
|
1020 | + $source = explode("/", ltrim(str_replace($themes_dir, "", $file), "/")); |
|
1021 | 1021 | } |
1022 | 1022 | } |
1023 | 1023 | |
1024 | - echo '<meta name="generator" content="WP Font Awesome Settings v' . esc_attr( $this->version ) . '"' . ( ! empty( $source[0] ) ? ' data-ac-source="' . esc_attr( $source[0] ) . '"' : '' ) . ' />'; |
|
1024 | + echo '<meta name="generator" content="WP Font Awesome Settings v' . esc_attr($this->version) . '"' . (!empty($source[0]) ? ' data-ac-source="' . esc_attr($source[0]) . '"' : '') . ' />'; |
|
1025 | 1025 | } |
1026 | 1026 | |
1027 | 1027 | /** |
@@ -1037,8 +1037,8 @@ discard block |
||
1037 | 1037 | * @param string $src The script url. |
1038 | 1038 | * @return string The script tag. |
1039 | 1039 | */ |
1040 | - public function script_loader_tag( $tag, $handle, $src ) { |
|
1041 | - if ( ( $handle == 'font-awesome' || $handle == 'font-awesome-shims' ) && ( strpos( $src, "kit.fontawesome.com" ) !== false || strpos( $src, ".fontawesome.com/releases/" ) !== false ) ) { |
|
1040 | + public function script_loader_tag($tag, $handle, $src) { |
|
1041 | + if (($handle == 'font-awesome' || $handle == 'font-awesome-shims') && (strpos($src, "kit.fontawesome.com") !== false || strpos($src, ".fontawesome.com/releases/") !== false)) { |
|
1042 | 1042 | $tag = preg_replace( |
1043 | 1043 | '/<script[\s]+(.*?)>/', |
1044 | 1044 | '<script defer crossorigin="anonymous" \1>', |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -15,196 +15,196 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Customer_Data_Store { |
17 | 17 | |
18 | - /* |
|
18 | + /* |
|
19 | 19 | |-------------------------------------------------------------------------- |
20 | 20 | | CRUD Methods |
21 | 21 | |-------------------------------------------------------------------------- |
22 | 22 | */ |
23 | 23 | |
24 | - /** |
|
25 | - * Method to create a new customer in the database. |
|
26 | - * |
|
27 | - * @param GetPaid_Customer $customer customer object. |
|
28 | - */ |
|
29 | - public function create( &$customer ) { |
|
30 | - global $wpdb; |
|
31 | - |
|
32 | - $values = array(); |
|
33 | - $formats = array(); |
|
34 | - |
|
35 | - $fields = self::get_database_fields(); |
|
36 | - unset( $fields['id'] ); |
|
37 | - |
|
38 | - foreach ( $fields as $key => $format ) { |
|
39 | - $values[ $key ] = $customer->get( $key, 'edit' ); |
|
40 | - $formats[] = $format; |
|
41 | - } |
|
42 | - |
|
43 | - $result = $wpdb->insert( $wpdb->prefix . 'getpaid_customers', $values, $formats ); |
|
44 | - |
|
45 | - if ( $result ) { |
|
46 | - $customer->set_id( $wpdb->insert_id ); |
|
47 | - $customer->apply_changes(); |
|
48 | - $customer->clear_cache(); |
|
49 | - do_action( 'getpaid_new_customer', $customer ); |
|
50 | - return true; |
|
51 | - } |
|
52 | - |
|
53 | - return false; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Method to read a customer from the database. |
|
58 | - * |
|
59 | - * @param GetPaid_Customer $customer customer object. |
|
60 | - * |
|
61 | - */ |
|
62 | - public function read( &$customer ) { |
|
63 | - global $wpdb; |
|
64 | - |
|
65 | - $customer->set_defaults(); |
|
66 | - |
|
67 | - if ( ! $customer->get_id() ) { |
|
68 | - $customer->last_error = 'Invalid customer.'; |
|
69 | - $customer->set_id( 0 ); |
|
70 | - return false; |
|
71 | - } |
|
72 | - |
|
73 | - // Maybe retrieve from the cache. |
|
74 | - $raw_customer = wp_cache_get( $customer->get_id(), 'getpaid_customers' ); |
|
75 | - |
|
76 | - // If not found, retrieve from the db. |
|
77 | - if ( false === $raw_customer ) { |
|
78 | - |
|
79 | - $raw_customer = $wpdb->get_row( |
|
80 | - $wpdb->prepare( |
|
81 | - "SELECT * FROM {$wpdb->prefix}getpaid_customers WHERE id = %d", |
|
82 | - $customer->get_id() |
|
83 | - ) |
|
84 | - ); |
|
85 | - |
|
86 | - // Update the cache with our data |
|
87 | - wp_cache_set( $customer->get_id(), $raw_customer, 'getpaid_customers' ); |
|
88 | - |
|
89 | - } |
|
90 | - |
|
91 | - if ( ! $raw_customer ) { |
|
92 | - $raw_customer->last_error = 'Invalid customer.'; |
|
93 | - return false; |
|
94 | - } |
|
95 | - |
|
96 | - // Loop through raw customer fields. |
|
97 | - foreach ( (array) $raw_customer as $key => $value ) { |
|
98 | - $customer->set( $key, $value ); |
|
99 | - } |
|
100 | - |
|
101 | - $customer->set_object_read( true ); |
|
102 | - do_action( 'getpaid_read_customer', $customer ); |
|
103 | - |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Method to update a customer in the database. |
|
108 | - * |
|
109 | - * @param GetPaid_Customer $customer Customer object. |
|
110 | - */ |
|
111 | - public function update( &$customer ) { |
|
112 | - global $wpdb; |
|
113 | - |
|
114 | - do_action( 'getpaid_before_update_customer', $customer, $customer->get_changes() ); |
|
115 | - |
|
116 | - $changes = $customer->get_changes(); |
|
117 | - $values = array(); |
|
118 | - $format = array(); |
|
119 | - |
|
120 | - foreach ( self::get_database_fields() as $key => $format ) { |
|
121 | - if ( array_key_exists( $key, $changes ) ) { |
|
122 | - $values[ $key ] = $customer->get( $key, 'edit' ); |
|
123 | - $formats[] = $format; |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - if ( empty( $values ) ) { |
|
128 | - return; |
|
129 | - } |
|
130 | - |
|
131 | - $wpdb->update( |
|
132 | - $wpdb->prefix . 'getpaid_customers', |
|
133 | - $values, |
|
134 | - array( |
|
135 | - 'id' => $customer->get_id(), |
|
136 | - ), |
|
137 | - $formats, |
|
138 | - '%d' |
|
139 | - ); |
|
140 | - |
|
141 | - // Apply the changes. |
|
142 | - $customer->apply_changes(); |
|
143 | - |
|
144 | - // Delete cache. |
|
145 | - $customer->clear_cache(); |
|
146 | - |
|
147 | - // Fire a hook. |
|
148 | - do_action( 'getpaid_update_customer', $customer ); |
|
149 | - |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Method to delete a customer from the database. |
|
154 | - * |
|
155 | - * @param GetPaid_Customer $customer |
|
156 | - */ |
|
157 | - public function delete( &$customer ) { |
|
158 | - global $wpdb; |
|
159 | - |
|
160 | - do_action( 'getpaid_before_delete_customer', $customer ); |
|
161 | - |
|
162 | - $wpdb->delete( |
|
163 | - $wpdb->prefix . 'getpaid_customers', |
|
164 | - array( |
|
165 | - 'id' => $customer->get_id(), |
|
166 | - ), |
|
167 | - '%d' |
|
168 | - ); |
|
169 | - |
|
170 | - // Delete cache. |
|
171 | - $customer->clear_cache(); |
|
172 | - |
|
173 | - // Fire a hook. |
|
174 | - do_action( 'getpaid_delete_customer', $customer ); |
|
175 | - |
|
176 | - $customer->set_id( 0 ); |
|
177 | - } |
|
178 | - |
|
179 | - /* |
|
24 | + /** |
|
25 | + * Method to create a new customer in the database. |
|
26 | + * |
|
27 | + * @param GetPaid_Customer $customer customer object. |
|
28 | + */ |
|
29 | + public function create( &$customer ) { |
|
30 | + global $wpdb; |
|
31 | + |
|
32 | + $values = array(); |
|
33 | + $formats = array(); |
|
34 | + |
|
35 | + $fields = self::get_database_fields(); |
|
36 | + unset( $fields['id'] ); |
|
37 | + |
|
38 | + foreach ( $fields as $key => $format ) { |
|
39 | + $values[ $key ] = $customer->get( $key, 'edit' ); |
|
40 | + $formats[] = $format; |
|
41 | + } |
|
42 | + |
|
43 | + $result = $wpdb->insert( $wpdb->prefix . 'getpaid_customers', $values, $formats ); |
|
44 | + |
|
45 | + if ( $result ) { |
|
46 | + $customer->set_id( $wpdb->insert_id ); |
|
47 | + $customer->apply_changes(); |
|
48 | + $customer->clear_cache(); |
|
49 | + do_action( 'getpaid_new_customer', $customer ); |
|
50 | + return true; |
|
51 | + } |
|
52 | + |
|
53 | + return false; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Method to read a customer from the database. |
|
58 | + * |
|
59 | + * @param GetPaid_Customer $customer customer object. |
|
60 | + * |
|
61 | + */ |
|
62 | + public function read( &$customer ) { |
|
63 | + global $wpdb; |
|
64 | + |
|
65 | + $customer->set_defaults(); |
|
66 | + |
|
67 | + if ( ! $customer->get_id() ) { |
|
68 | + $customer->last_error = 'Invalid customer.'; |
|
69 | + $customer->set_id( 0 ); |
|
70 | + return false; |
|
71 | + } |
|
72 | + |
|
73 | + // Maybe retrieve from the cache. |
|
74 | + $raw_customer = wp_cache_get( $customer->get_id(), 'getpaid_customers' ); |
|
75 | + |
|
76 | + // If not found, retrieve from the db. |
|
77 | + if ( false === $raw_customer ) { |
|
78 | + |
|
79 | + $raw_customer = $wpdb->get_row( |
|
80 | + $wpdb->prepare( |
|
81 | + "SELECT * FROM {$wpdb->prefix}getpaid_customers WHERE id = %d", |
|
82 | + $customer->get_id() |
|
83 | + ) |
|
84 | + ); |
|
85 | + |
|
86 | + // Update the cache with our data |
|
87 | + wp_cache_set( $customer->get_id(), $raw_customer, 'getpaid_customers' ); |
|
88 | + |
|
89 | + } |
|
90 | + |
|
91 | + if ( ! $raw_customer ) { |
|
92 | + $raw_customer->last_error = 'Invalid customer.'; |
|
93 | + return false; |
|
94 | + } |
|
95 | + |
|
96 | + // Loop through raw customer fields. |
|
97 | + foreach ( (array) $raw_customer as $key => $value ) { |
|
98 | + $customer->set( $key, $value ); |
|
99 | + } |
|
100 | + |
|
101 | + $customer->set_object_read( true ); |
|
102 | + do_action( 'getpaid_read_customer', $customer ); |
|
103 | + |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Method to update a customer in the database. |
|
108 | + * |
|
109 | + * @param GetPaid_Customer $customer Customer object. |
|
110 | + */ |
|
111 | + public function update( &$customer ) { |
|
112 | + global $wpdb; |
|
113 | + |
|
114 | + do_action( 'getpaid_before_update_customer', $customer, $customer->get_changes() ); |
|
115 | + |
|
116 | + $changes = $customer->get_changes(); |
|
117 | + $values = array(); |
|
118 | + $format = array(); |
|
119 | + |
|
120 | + foreach ( self::get_database_fields() as $key => $format ) { |
|
121 | + if ( array_key_exists( $key, $changes ) ) { |
|
122 | + $values[ $key ] = $customer->get( $key, 'edit' ); |
|
123 | + $formats[] = $format; |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + if ( empty( $values ) ) { |
|
128 | + return; |
|
129 | + } |
|
130 | + |
|
131 | + $wpdb->update( |
|
132 | + $wpdb->prefix . 'getpaid_customers', |
|
133 | + $values, |
|
134 | + array( |
|
135 | + 'id' => $customer->get_id(), |
|
136 | + ), |
|
137 | + $formats, |
|
138 | + '%d' |
|
139 | + ); |
|
140 | + |
|
141 | + // Apply the changes. |
|
142 | + $customer->apply_changes(); |
|
143 | + |
|
144 | + // Delete cache. |
|
145 | + $customer->clear_cache(); |
|
146 | + |
|
147 | + // Fire a hook. |
|
148 | + do_action( 'getpaid_update_customer', $customer ); |
|
149 | + |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Method to delete a customer from the database. |
|
154 | + * |
|
155 | + * @param GetPaid_Customer $customer |
|
156 | + */ |
|
157 | + public function delete( &$customer ) { |
|
158 | + global $wpdb; |
|
159 | + |
|
160 | + do_action( 'getpaid_before_delete_customer', $customer ); |
|
161 | + |
|
162 | + $wpdb->delete( |
|
163 | + $wpdb->prefix . 'getpaid_customers', |
|
164 | + array( |
|
165 | + 'id' => $customer->get_id(), |
|
166 | + ), |
|
167 | + '%d' |
|
168 | + ); |
|
169 | + |
|
170 | + // Delete cache. |
|
171 | + $customer->clear_cache(); |
|
172 | + |
|
173 | + // Fire a hook. |
|
174 | + do_action( 'getpaid_delete_customer', $customer ); |
|
175 | + |
|
176 | + $customer->set_id( 0 ); |
|
177 | + } |
|
178 | + |
|
179 | + /* |
|
180 | 180 | |-------------------------------------------------------------------------- |
181 | 181 | | Additional Methods |
182 | 182 | |-------------------------------------------------------------------------- |
183 | 183 | */ |
184 | - public static function get_database_fields() { |
|
185 | - |
|
186 | - $fields = array( |
|
187 | - 'id' => '%d', |
|
188 | - 'user_id' => '%d', |
|
189 | - 'email' => '%s', |
|
190 | - 'email_cc' => '%s', |
|
191 | - 'status' => '%s', |
|
192 | - 'purchase_value' => '%f', |
|
193 | - 'purchase_count' => '%d', |
|
194 | - 'date_created' => '%s', |
|
195 | - 'date_modified' => '%s', |
|
196 | - 'uuid' => '%s', |
|
197 | - ); |
|
198 | - |
|
199 | - // Add address fields. |
|
200 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
201 | - |
|
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'; |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - return $fields; |
|
209 | - } |
|
184 | + public static function get_database_fields() { |
|
185 | + |
|
186 | + $fields = array( |
|
187 | + 'id' => '%d', |
|
188 | + 'user_id' => '%d', |
|
189 | + 'email' => '%s', |
|
190 | + 'email_cc' => '%s', |
|
191 | + 'status' => '%s', |
|
192 | + 'purchase_value' => '%f', |
|
193 | + 'purchase_count' => '%d', |
|
194 | + 'date_created' => '%s', |
|
195 | + 'date_modified' => '%s', |
|
196 | + 'uuid' => '%s', |
|
197 | + ); |
|
198 | + |
|
199 | + // Add address fields. |
|
200 | + foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
201 | + |
|
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'; |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + return $fields; |
|
209 | + } |
|
210 | 210 | } |
@@ -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 |
@@ -15,69 +15,69 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Customer extends GetPaid_Data { |
17 | 17 | |
18 | - /** |
|
19 | - * Which data store to load. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
18 | + /** |
|
19 | + * Which data store to load. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | 23 | protected $data_store_name = 'customer'; |
24 | 24 | |
25 | 25 | /** |
26 | - * This is the name of this object type. |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $object_type = 'customer'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Get the customer if ID is passed, otherwise the customer is new and empty. |
|
34 | - * |
|
35 | - * @param int|string|GetPaid_Customer|object $customer customer id, object, or email. |
|
36 | - */ |
|
37 | - public function __construct( $customer = 0 ) { |
|
26 | + * This is the name of this object type. |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $object_type = 'customer'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Get the customer if ID is passed, otherwise the customer is new and empty. |
|
34 | + * |
|
35 | + * @param int|string|GetPaid_Customer|object $customer customer id, object, or email. |
|
36 | + */ |
|
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 ); |
|
50 | - } |
|
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 | + } |
|
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 | 59 | $this->set_object_read( true ); |
60 | - } |
|
60 | + } |
|
61 | 61 | |
62 | 62 | /** |
63 | - * Sets up default customer data. |
|
64 | - */ |
|
65 | - private function setup_default_data() { |
|
63 | + * Sets up default customer data. |
|
64 | + */ |
|
65 | + private function setup_default_data() { |
|
66 | 66 | |
67 | 67 | $this->data = array( |
68 | - 'user_id' => 0, |
|
69 | - 'email' => '', |
|
70 | - 'email_cc' => '', |
|
71 | - 'status' => 'active', |
|
72 | - 'purchase_value' => 0, |
|
73 | - 'purchase_count' => 0, |
|
74 | - 'date_created' => current_time( 'mysql' ), |
|
75 | - 'date_modified' => current_time( 'mysql' ), |
|
76 | - 'uuid' => wp_generate_uuid4(), |
|
77 | - ); |
|
68 | + 'user_id' => 0, |
|
69 | + 'email' => '', |
|
70 | + 'email_cc' => '', |
|
71 | + 'status' => 'active', |
|
72 | + 'purchase_value' => 0, |
|
73 | + 'purchase_count' => 0, |
|
74 | + 'date_created' => current_time( 'mysql' ), |
|
75 | + 'date_modified' => current_time( 'mysql' ), |
|
76 | + 'uuid' => wp_generate_uuid4(), |
|
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 | 82 | if ( isset( $this->data[ $field ] ) ) { |
83 | 83 | continue; |
@@ -95,22 +95,22 @@ discard block |
||
95 | 95 | continue; |
96 | 96 | } |
97 | 97 | |
98 | - $this->data[ $field ] = ''; |
|
99 | - } |
|
98 | + $this->data[ $field ] = ''; |
|
99 | + } |
|
100 | 100 | |
101 | 101 | $this->default_data = $this->data; |
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Given a customer email or user id, it returns a customer id. |
|
106 | - * |
|
107 | - * @static |
|
108 | - * @param string $value |
|
109 | - * @since 1.0.15 |
|
110 | - * @return int |
|
111 | - */ |
|
112 | - public static function get_customer_id_by( $value, $by = 'email' ) { |
|
113 | - global $wpdb; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Given a customer email or user id, it returns a customer id. |
|
106 | + * |
|
107 | + * @static |
|
108 | + * @param string $value |
|
109 | + * @since 1.0.15 |
|
110 | + * @return int |
|
111 | + */ |
|
112 | + public static function get_customer_id_by( $value, $by = 'email' ) { |
|
113 | + global $wpdb; |
|
114 | 114 | |
115 | 115 | // Prepare value. |
116 | 116 | if ( 'email' === $by ) { |
@@ -125,12 +125,12 @@ discard block |
||
125 | 125 | return 0; |
126 | 126 | } |
127 | 127 | |
128 | - // Maybe retrieve from the cache. |
|
128 | + // Maybe retrieve from the cache. |
|
129 | 129 | $cache_key = 'getpaid_customer_ids_by_' . $by; |
130 | - $customer_id = wp_cache_get( $value, $cache_key ); |
|
131 | - if ( false !== $customer_id ) { |
|
132 | - return $customer_id; |
|
133 | - } |
|
130 | + $customer_id = wp_cache_get( $value, $cache_key ); |
|
131 | + if ( false !== $customer_id ) { |
|
132 | + return $customer_id; |
|
133 | + } |
|
134 | 134 | |
135 | 135 | if ( 'email' === $by ) { |
136 | 136 | $customer_id = (int) $wpdb->get_var( |
@@ -142,23 +142,23 @@ discard block |
||
142 | 142 | ); |
143 | 143 | } |
144 | 144 | |
145 | - // Update the cache with our data |
|
146 | - wp_cache_set( $value, $customer_id, $cache_key ); |
|
145 | + // Update the cache with our data |
|
146 | + wp_cache_set( $value, $customer_id, $cache_key ); |
|
147 | 147 | |
148 | - return $customer_id; |
|
148 | + return $customer_id; |
|
149 | 149 | |
150 | - } |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
152 | + /** |
|
153 | 153 | * Clears the customer's cache. |
154 | 154 | */ |
155 | 155 | public function clear_cache() { |
156 | 156 | wp_cache_delete( $this->get( 'email' ), 'getpaid_customer_ids_by_email' ); |
157 | 157 | wp_cache_delete( $this->get( 'user_id' ), 'getpaid_customer_ids_by_user_id' ); |
158 | - wp_cache_delete( $this->get_id(), 'getpaid_customers' ); |
|
159 | - } |
|
158 | + wp_cache_delete( $this->get_id(), 'getpaid_customers' ); |
|
159 | + } |
|
160 | 160 | |
161 | - /* |
|
161 | + /* |
|
162 | 162 | |-------------------------------------------------------------------------- |
163 | 163 | | CRUD methods |
164 | 164 | |-------------------------------------------------------------------------- |
@@ -189,11 +189,11 @@ discard block |
||
189 | 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 | |
196 | - /* |
|
196 | + /* |
|
197 | 197 | |-------------------------------------------------------------------------- |
198 | 198 | | Setters |
199 | 199 | |-------------------------------------------------------------------------- |
@@ -216,114 +216,114 @@ discard block |
||
216 | 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 | |
223 | - /** |
|
224 | - * Sets customer status. |
|
225 | - * |
|
226 | - * @since 1.0.0 |
|
227 | - * @param string $status New status. |
|
228 | - */ |
|
229 | - public function set_status( $status ) { |
|
230 | - |
|
231 | - if ( in_array( $status, array( 'active', 'inactive', 'blocked' ), true ) ) { |
|
232 | - return $this->set_prop( 'status', $status ); |
|
233 | - } |
|
234 | - |
|
235 | - $this->set_prop( 'status', 'inactive' ); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Sets the purchase value. |
|
240 | - * |
|
241 | - * @since 1.0.0 |
|
242 | - * @param float $purchase_value. |
|
243 | - */ |
|
244 | - public function set_purchase_value( $purchase_value ) { |
|
245 | - $this->set_prop( 'purchase_value', (float) $purchase_value ); |
|
246 | - } |
|
223 | + /** |
|
224 | + * Sets customer status. |
|
225 | + * |
|
226 | + * @since 1.0.0 |
|
227 | + * @param string $status New status. |
|
228 | + */ |
|
229 | + public function set_status( $status ) { |
|
230 | + |
|
231 | + if ( in_array( $status, array( 'active', 'inactive', 'blocked' ), true ) ) { |
|
232 | + return $this->set_prop( 'status', $status ); |
|
233 | + } |
|
234 | + |
|
235 | + $this->set_prop( 'status', 'inactive' ); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Sets the purchase value. |
|
240 | + * |
|
241 | + * @since 1.0.0 |
|
242 | + * @param float $purchase_value. |
|
243 | + */ |
|
244 | + public function set_purchase_value( $purchase_value ) { |
|
245 | + $this->set_prop( 'purchase_value', (float) $purchase_value ); |
|
246 | + } |
|
247 | 247 | |
248 | 248 | /** |
249 | - * Sets the purchase count. |
|
250 | - * |
|
251 | - * @since 1.0.0 |
|
252 | - * @param int $purchase_count. |
|
253 | - */ |
|
254 | - public function set_purchase_count( $purchase_count ) { |
|
255 | - $this->set_prop( 'purchase_count', absint( $purchase_count ) ); |
|
256 | - } |
|
249 | + * Sets the purchase count. |
|
250 | + * |
|
251 | + * @since 1.0.0 |
|
252 | + * @param int $purchase_count. |
|
253 | + */ |
|
254 | + public function set_purchase_count( $purchase_count ) { |
|
255 | + $this->set_prop( 'purchase_count', absint( $purchase_count ) ); |
|
256 | + } |
|
257 | 257 | |
258 | 258 | /** |
259 | - * Sets the user id. |
|
260 | - * |
|
261 | - * @since 1.0.0 |
|
262 | - * @param int $user_id. |
|
263 | - */ |
|
264 | - public function set_user_id( $user_id ) { |
|
265 | - $this->set_prop( 'user_id', absint( $user_id ) ); |
|
266 | - } |
|
259 | + * Sets the user id. |
|
260 | + * |
|
261 | + * @since 1.0.0 |
|
262 | + * @param int $user_id. |
|
263 | + */ |
|
264 | + public function set_user_id( $user_id ) { |
|
265 | + $this->set_prop( 'user_id', absint( $user_id ) ); |
|
266 | + } |
|
267 | 267 | |
268 | 268 | /** |
269 | - * Sets the email. |
|
270 | - * |
|
271 | - * @since 1.0.0 |
|
272 | - * @param string $email. |
|
273 | - */ |
|
274 | - public function set_email( $email ) { |
|
269 | + * Sets the email. |
|
270 | + * |
|
271 | + * @since 1.0.0 |
|
272 | + * @param string $email. |
|
273 | + */ |
|
274 | + public function set_email( $email ) { |
|
275 | 275 | $email = is_string( $email ) ? sanitize_email( $email ) : ''; |
276 | - $this->set_prop( 'email', $email ); |
|
277 | - } |
|
276 | + $this->set_prop( 'email', $email ); |
|
277 | + } |
|
278 | 278 | |
279 | 279 | /** |
280 | - * Sets the email cc. |
|
281 | - * |
|
282 | - * @since 1.0.0 |
|
283 | - * @param string $email_cc. |
|
284 | - */ |
|
285 | - public function set_email_cc( $email_cc ) { |
|
280 | + * Sets the email cc. |
|
281 | + * |
|
282 | + * @since 1.0.0 |
|
283 | + * @param string $email_cc. |
|
284 | + */ |
|
285 | + public function set_email_cc( $email_cc ) { |
|
286 | 286 | $email_cc = implode( ', ', wp_parse_list( $email_cc ) ); |
287 | - $this->set_prop( 'email_cc', $email_cc ); |
|
288 | - } |
|
287 | + $this->set_prop( 'email_cc', $email_cc ); |
|
288 | + } |
|
289 | 289 | |
290 | 290 | /** |
291 | - * Sets the created date. |
|
292 | - * |
|
293 | - * @since 1.0.0 |
|
294 | - * @param string $date_created date created. |
|
295 | - */ |
|
296 | - public function set_date_created( $date_created ) { |
|
291 | + * Sets the created date. |
|
292 | + * |
|
293 | + * @since 1.0.0 |
|
294 | + * @param string $date_created date created. |
|
295 | + */ |
|
296 | + public function set_date_created( $date_created ) { |
|
297 | 297 | |
298 | - $date = strtotime( $date_created ); |
|
298 | + $date = strtotime( $date_created ); |
|
299 | 299 | |
300 | 300 | if ( $date && $date_created !== '0000-00-00 00:00:00' && $date_created !== '0000-00-00 00:00' ) { |
301 | 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 ); |
|
306 | - } |
|
305 | + $this->set_prop( 'date_created', null ); |
|
306 | + } |
|
307 | 307 | |
308 | 308 | /** |
309 | - * Sets the created date. |
|
310 | - * |
|
311 | - * @since 1.0.0 |
|
312 | - * @param string $date_modified date created. |
|
313 | - */ |
|
314 | - public function set_date_modified( $date_modified ) { |
|
309 | + * Sets the created date. |
|
310 | + * |
|
311 | + * @since 1.0.0 |
|
312 | + * @param string $date_modified date created. |
|
313 | + */ |
|
314 | + public function set_date_modified( $date_modified ) { |
|
315 | 315 | |
316 | - $date = strtotime( $date_modified ); |
|
316 | + $date = strtotime( $date_modified ); |
|
317 | 317 | |
318 | 318 | if ( $date && $date_modified !== '0000-00-00 00:00:00' && $date_modified !== '0000-00-00 00:00' ) { |
319 | 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 ); |
|
324 | - } |
|
323 | + $this->set_prop( 'date_modified', null ); |
|
324 | + } |
|
325 | 325 | |
326 | - /* |
|
326 | + /* |
|
327 | 327 | |-------------------------------------------------------------------------- |
328 | 328 | | Additional methods |
329 | 329 | |-------------------------------------------------------------------------- |
@@ -332,12 +332,12 @@ discard block |
||
332 | 332 | | |
333 | 333 | */ |
334 | 334 | |
335 | - /** |
|
336 | - * Saves the customer. |
|
337 | - * |
|
338 | - * @since 1.0.0 |
|
339 | - */ |
|
340 | - public function save() { |
|
335 | + /** |
|
336 | + * Saves the customer. |
|
337 | + * |
|
338 | + * @since 1.0.0 |
|
339 | + */ |
|
340 | + public function save() { |
|
341 | 341 | |
342 | 342 | $maybe_set = array( |
343 | 343 | 'uuid' => wp_generate_uuid4(), |
@@ -354,29 +354,29 @@ discard block |
||
354 | 354 | |
355 | 355 | $this->set( 'date_modified', current_time( 'mysql' ) ); |
356 | 356 | |
357 | - return parent::save(); |
|
358 | - } |
|
357 | + return parent::save(); |
|
358 | + } |
|
359 | 359 | |
360 | 360 | /** |
361 | - * Helper method to clone a customer from a user ID. |
|
362 | - * |
|
363 | - * @since 1.0.0 |
|
364 | - * @param int $user_id. |
|
365 | - */ |
|
366 | - public function clone_user( $user_id ) { |
|
361 | + * Helper method to clone a customer from a user ID. |
|
362 | + * |
|
363 | + * @since 1.0.0 |
|
364 | + * @param int $user_id. |
|
365 | + */ |
|
366 | + public function clone_user( $user_id ) { |
|
367 | 367 | $user = get_userdata( $user_id ); |
368 | 368 | |
369 | 369 | if ( empty( $user ) ) { |
370 | 370 | return; |
371 | 371 | } |
372 | 372 | |
373 | - $this->set_user_id( $user->ID ); |
|
373 | + $this->set_user_id( $user->ID ); |
|
374 | 374 | $this->set_email( $user->user_email ); |
375 | 375 | $this->set_purchase_value( getpaid_get_user_total_spend( $user->ID ) ); |
376 | 376 | $this->set_purchase_count( getpaid_count_user_invoices( $user->ID ) ); |
377 | 377 | $this->set( 'first_name', $user->first_name ); |
378 | 378 | $this->set( 'last_name', $user->last_name ); |
379 | - $this->set_date_created( $user->user_registered ); |
|
379 | + $this->set_date_created( $user->user_registered ); |
|
380 | 380 | |
381 | 381 | // Fetch extra data from WC or old GetPaid. |
382 | 382 | $prefixes = array( |
@@ -400,18 +400,18 @@ discard block |
||
400 | 400 | continue; |
401 | 401 | } |
402 | 402 | } |
403 | - } |
|
404 | - } |
|
403 | + } |
|
404 | + } |
|
405 | 405 | |
406 | 406 | /** |
407 | - * Helper method to migrate an existing user ID to the new customers table. |
|
408 | - * |
|
409 | - * @since 1.0.0 |
|
410 | - * @param int $user_id. |
|
411 | - */ |
|
412 | - public function migrate_from_user( $user_id ) { |
|
407 | + * Helper method to migrate an existing user ID to the new customers table. |
|
408 | + * |
|
409 | + * @since 1.0.0 |
|
410 | + * @param int $user_id. |
|
411 | + */ |
|
412 | + public function migrate_from_user( $user_id ) { |
|
413 | 413 | $this->clone_user( $user_id ); |
414 | 414 | do_action( 'getpaid_customer_migrated_from_user', $this, $user_id ); |
415 | 415 | $this->save(); |
416 | - } |
|
416 | + } |
|
417 | 417 | } |
@@ -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 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -75,16 +75,16 @@ discard block |
||
75 | 75 | $class .= ' wpi-recurring'; |
76 | 76 | } |
77 | 77 | |
78 | - $refund_url = wp_nonce_url( |
|
79 | - add_query_arg( |
|
80 | - array( |
|
81 | - 'getpaid-admin-action' => 'refund_invoice', |
|
82 | - 'invoice_id' => $invoice->get_id(), |
|
83 | - ) |
|
84 | - ), |
|
85 | - 'getpaid-nonce', |
|
86 | - 'getpaid-nonce' |
|
87 | - ); |
|
78 | + $refund_url = wp_nonce_url( |
|
79 | + add_query_arg( |
|
80 | + array( |
|
81 | + 'getpaid-admin-action' => 'refund_invoice', |
|
82 | + 'invoice_id' => $invoice->get_id(), |
|
83 | + ) |
|
84 | + ), |
|
85 | + 'getpaid-nonce', |
|
86 | + 'getpaid-nonce' |
|
87 | + ); |
|
88 | 88 | ?> |
89 | 89 | |
90 | 90 | <div class="wpinv-items-wrap<?php echo esc_attr( $class ); ?>" id="wpinv_items_wrap" data-status="<?php echo esc_attr( $invoice->get_status() ); ?>"> |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | <th class=" |
97 | 97 | <?php |
98 | 98 | echo esc_attr( $key ); |
99 | - echo 'total' == $key || 'qty' == $key ? ' hide-if-amount' : ''; |
|
100 | - ?> |
|
99 | + echo 'total' == $key || 'qty' == $key ? ' hide-if-amount' : ''; |
|
100 | + ?> |
|
101 | 101 | "><?php echo wp_kses_post( $label ); ?></th> |
102 | 102 | <?php endforeach; ?> |
103 | 103 | </tr> |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | <tbody class="wpinv-line-items"> |
107 | 107 | <?php |
108 | 108 | foreach ( $invoice->get_items() as $int => $item ) { |
109 | - self::output_row( $columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd' ); |
|
109 | + self::output_row( $columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd' ); |
|
110 | 110 | } |
111 | 111 | ?> |
112 | 112 | </tbody> |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | <?php |
152 | 152 | wpinv_html_select( |
153 | 153 | array( |
154 | - 'options' => $item_types, |
|
155 | - 'name' => '_wpinv_quick[type]', |
|
156 | - 'id' => '_wpinv_quick_type', |
|
157 | - 'selected' => 'custom', |
|
158 | - 'show_option_all' => false, |
|
159 | - 'show_option_none' => false, |
|
160 | - 'class' => 'gdmbx2-text-medium wpinv-quick-type', |
|
154 | + 'options' => $item_types, |
|
155 | + 'name' => '_wpinv_quick[type]', |
|
156 | + 'id' => '_wpinv_quick_type', |
|
157 | + 'selected' => 'custom', |
|
158 | + 'show_option_all' => false, |
|
159 | + 'show_option_none' => false, |
|
160 | + 'class' => 'gdmbx2-text-medium wpinv-quick-type', |
|
161 | 161 | ) |
162 | 162 | ); |
163 | 163 | ?> |
@@ -172,16 +172,16 @@ discard block |
||
172 | 172 | <?php |
173 | 173 | wpinv_html_select( |
174 | 174 | array( |
175 | - 'options' => array_merge( |
|
176 | - array( '' => __( 'Select VAT Rule', 'invoicing' ) ), |
|
177 | - getpaid_get_tax_rules() |
|
178 | - ), |
|
179 | - 'name' => '_wpinv_quick[vat_rule]', |
|
180 | - 'id' => '_wpinv_quick_vat_rule', |
|
181 | - 'show_option_all' => false, |
|
182 | - 'show_option_none' => false, |
|
183 | - 'class' => 'gdmbx2-text-medium wpinv-quick-vat-rule', |
|
184 | - 'selected' => 'digital', |
|
175 | + 'options' => array_merge( |
|
176 | + array( '' => __( 'Select VAT Rule', 'invoicing' ) ), |
|
177 | + getpaid_get_tax_rules() |
|
178 | + ), |
|
179 | + 'name' => '_wpinv_quick[vat_rule]', |
|
180 | + 'id' => '_wpinv_quick_vat_rule', |
|
181 | + 'show_option_all' => false, |
|
182 | + 'show_option_none' => false, |
|
183 | + 'class' => 'gdmbx2-text-medium wpinv-quick-vat-rule', |
|
184 | + 'selected' => 'digital', |
|
185 | 185 | ) |
186 | 186 | ); |
187 | 187 | ?> |
@@ -194,16 +194,16 @@ discard block |
||
194 | 194 | <?php |
195 | 195 | wpinv_html_select( |
196 | 196 | array( |
197 | - 'options' => array_merge( |
|
198 | - array( '' => __( 'Select VAT Class', 'invoicing' ) ), |
|
199 | - getpaid_get_tax_classes() |
|
200 | - ), |
|
201 | - 'name' => '_wpinv_quick[vat_class]', |
|
202 | - 'id' => '_wpinv_quick_vat_class', |
|
203 | - 'show_option_all' => false, |
|
204 | - 'show_option_none' => false, |
|
205 | - 'class' => 'gdmbx2-text-medium wpinv-quick-vat-class', |
|
206 | - 'selected' => '_standard', |
|
197 | + 'options' => array_merge( |
|
198 | + array( '' => __( 'Select VAT Class', 'invoicing' ) ), |
|
199 | + getpaid_get_tax_classes() |
|
200 | + ), |
|
201 | + 'name' => '_wpinv_quick[vat_class]', |
|
202 | + 'id' => '_wpinv_quick_vat_class', |
|
203 | + 'show_option_all' => false, |
|
204 | + 'show_option_none' => false, |
|
205 | + 'class' => 'gdmbx2-text-medium wpinv-quick-vat-class', |
|
206 | + 'selected' => '_standard', |
|
207 | 207 | ) |
208 | 208 | ); |
209 | 209 | ?> |
@@ -294,37 +294,37 @@ discard block |
||
294 | 294 | </p> |
295 | 295 | <?php if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) ) : ?> |
296 | 296 | <?php |
297 | - aui()->input( |
|
298 | - array( |
|
299 | - 'type' => 'checkbox', |
|
300 | - 'name' => 'getpaid_refund_remote', |
|
301 | - 'id' => 'getpaid_refund_remote', |
|
302 | - 'label' => sprintf( |
|
303 | - 'Refund payment in %s', |
|
304 | - wpinv_get_gateway_admin_label( $invoice->get_gateway() ) |
|
305 | - ), |
|
306 | - 'value' => 1, |
|
307 | - 'class' => 'getpaid-refund-field', |
|
308 | - ), |
|
309 | - true |
|
310 | - ); |
|
311 | - ?> |
|
297 | + aui()->input( |
|
298 | + array( |
|
299 | + 'type' => 'checkbox', |
|
300 | + 'name' => 'getpaid_refund_remote', |
|
301 | + 'id' => 'getpaid_refund_remote', |
|
302 | + 'label' => sprintf( |
|
303 | + 'Refund payment in %s', |
|
304 | + wpinv_get_gateway_admin_label( $invoice->get_gateway() ) |
|
305 | + ), |
|
306 | + 'value' => 1, |
|
307 | + 'class' => 'getpaid-refund-field', |
|
308 | + ), |
|
309 | + true |
|
310 | + ); |
|
311 | + ?> |
|
312 | 312 | <?php endif; ?> |
313 | 313 | |
314 | 314 | <?php if ( getpaid_get_invoice_subscriptions( $invoice ) ) : ?> |
315 | 315 | <?php |
316 | - aui()->input( |
|
317 | - array( |
|
318 | - 'type' => 'checkbox', |
|
319 | - 'name' => 'getpaid_cancel_subscription', |
|
320 | - 'id' => 'getpaid_cancel_subscription', |
|
321 | - 'label' => __( 'Cancel subscription', 'invoicing' ), |
|
322 | - 'value' => 1, |
|
323 | - 'class' => 'getpaid-refund-field', |
|
324 | - ), |
|
325 | - true |
|
326 | - ); |
|
327 | - ?> |
|
316 | + aui()->input( |
|
317 | + array( |
|
318 | + 'type' => 'checkbox', |
|
319 | + 'name' => 'getpaid_cancel_subscription', |
|
320 | + 'id' => 'getpaid_cancel_subscription', |
|
321 | + 'label' => __( 'Cancel subscription', 'invoicing' ), |
|
322 | + 'value' => 1, |
|
323 | + 'class' => 'getpaid-refund-field', |
|
324 | + ), |
|
325 | + true |
|
326 | + ); |
|
327 | + ?> |
|
328 | 328 | <?php endif; ?> |
329 | 329 | </div> |
330 | 330 | <div class="modal-footer"> |
@@ -364,23 +364,23 @@ discard block |
||
364 | 364 | <?php |
365 | 365 | if ( $invoice->is_paid() ) { |
366 | 366 | |
367 | - printf( |
|
368 | - '<span class="bsui"><button type="button" class="button button-primary" data-toggle="modal" data-bs-toggle="modal" data-bs-target="#getpaid-refund-invoice-modal" data-target="#getpaid-refund-invoice-modal">%s</button></span>', |
|
369 | - esc_html__( 'Refund', 'invoicing' ) |
|
370 | - ); |
|
367 | + printf( |
|
368 | + '<span class="bsui"><button type="button" class="button button-primary" data-toggle="modal" data-bs-toggle="modal" data-bs-target="#getpaid-refund-invoice-modal" data-target="#getpaid-refund-invoice-modal">%s</button></span>', |
|
369 | + esc_html__( 'Refund', 'invoicing' ) |
|
370 | + ); |
|
371 | 371 | } elseif ( ! $invoice->is_refunded() ) { |
372 | - wpinv_item_dropdown( |
|
373 | - array( |
|
374 | - 'name' => 'wpinv_invoice_item', |
|
375 | - 'id' => 'wpinv_invoice_item', |
|
376 | - 'show_recurring' => true, |
|
377 | - 'class' => 'wpi_select2', |
|
378 | - ) |
|
379 | - ); |
|
380 | - |
|
381 | - echo ' ' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf( esc_html__( 'Add item to %s', 'invoicing' ), esc_html( $invoice->get_label() ) ) . '</button>'; |
|
382 | - echo ' ' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__( 'Create new item', 'invoicing' ) . '</button>'; |
|
383 | - echo ' ' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__( 'Recalculate Totals', 'invoicing' ) . '</button>'; |
|
372 | + wpinv_item_dropdown( |
|
373 | + array( |
|
374 | + 'name' => 'wpinv_invoice_item', |
|
375 | + 'id' => 'wpinv_invoice_item', |
|
376 | + 'show_recurring' => true, |
|
377 | + 'class' => 'wpi_select2', |
|
378 | + ) |
|
379 | + ); |
|
380 | + |
|
381 | + echo ' ' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf( esc_html__( 'Add item to %s', 'invoicing' ), esc_html( $invoice->get_label() ) ) . '</button>'; |
|
382 | + echo ' ' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__( 'Create new item', 'invoicing' ) . '</button>'; |
|
383 | + echo ' ' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__( 'Recalculate Totals', 'invoicing' ) . '</button>'; |
|
384 | 384 | |
385 | 385 | } |
386 | 386 | ?> |
@@ -397,72 +397,72 @@ discard block |
||
397 | 397 | <?php foreach ( array_keys( $columns ) as $column ) : ?> |
398 | 398 | <td class=" |
399 | 399 | <?php |
400 | - echo esc_attr( $column ); |
|
401 | - echo 'total' == $column || 'qty' == $column ? ' hide-if-amount' : ''; |
|
402 | - ?> |
|
400 | + echo esc_attr( $column ); |
|
401 | + echo 'total' == $column || 'qty' == $column ? ' hide-if-amount' : ''; |
|
402 | + ?> |
|
403 | 403 | "> |
404 | 404 | <?php |
405 | 405 | switch ( $column ) { |
406 | - case 'id': |
|
407 | - echo (int) $item->get_id(); |
|
408 | - break; |
|
409 | - case 'title': |
|
410 | - printf( |
|
411 | - '<a href="%s" target="_blank">%s</a>', |
|
412 | - esc_url( get_edit_post_link( $item->get_id() ) ), |
|
413 | - esc_html( $item->get_raw_name() ) |
|
414 | - ); |
|
415 | - |
|
416 | - $summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice ); |
|
417 | - if ( $summary !== '' ) { |
|
418 | - printf( |
|
419 | - '<span class="meta">%s</span>', |
|
420 | - wp_kses_post( wpautop( $summary ) ) |
|
421 | - ); |
|
422 | - } |
|
423 | - |
|
424 | - printf( |
|
425 | - '<input type="hidden" value="%s" name="getpaid_items[%s][name]" class="getpaid-recalculate-prices-on-change" />', |
|
426 | - esc_attr( $item->get_raw_name() ), |
|
427 | - (int) $item->get_id() |
|
428 | - ); |
|
429 | - |
|
430 | - printf( |
|
431 | - '<textarea style="display: none;" name="getpaid_items[%s][description]" class="getpaid-recalculate-prices-on-change">%s</textarea>', |
|
432 | - (int) $item->get_id(), |
|
433 | - esc_attr( $item->get_description() ) |
|
434 | - ); |
|
435 | - |
|
436 | - break; |
|
437 | - case 'price': |
|
438 | - printf( |
|
439 | - '<input type="text" value="%s" name="getpaid_items[%s][price]" style="width: 100px;" class="getpaid-admin-invoice-item-price getpaid-recalculate-prices-on-change" />', |
|
440 | - esc_attr( getpaid_unstandardize_amount( $item->get_price() ) ), |
|
441 | - (int) $item->get_id() |
|
442 | - ); |
|
443 | - |
|
444 | - break; |
|
445 | - case 'qty': |
|
446 | - printf( |
|
447 | - '<input type="text" style="width: 100px;" value="%s" name="getpaid_items[%s][quantity]" class="getpaid-admin-invoice-item-quantity getpaid-recalculate-prices-on-change" />', |
|
448 | - floatval( $item->get_quantity() ), |
|
449 | - (int) $item->get_id() |
|
450 | - ); |
|
451 | - |
|
452 | - break; |
|
453 | - case 'total': |
|
454 | - wpinv_the_price( $item->get_sub_total(), $invoice->get_currency() ); |
|
455 | - |
|
456 | - break; |
|
457 | - case 'tax': |
|
458 | - echo floatval( wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%'; |
|
459 | - |
|
460 | - break; |
|
461 | - case 'action': |
|
462 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
463 | - echo '<i class="fa fa-trash wpinv-item-remove"></i>'; |
|
406 | + case 'id': |
|
407 | + echo (int) $item->get_id(); |
|
408 | + break; |
|
409 | + case 'title': |
|
410 | + printf( |
|
411 | + '<a href="%s" target="_blank">%s</a>', |
|
412 | + esc_url( get_edit_post_link( $item->get_id() ) ), |
|
413 | + esc_html( $item->get_raw_name() ) |
|
414 | + ); |
|
415 | + |
|
416 | + $summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice ); |
|
417 | + if ( $summary !== '' ) { |
|
418 | + printf( |
|
419 | + '<span class="meta">%s</span>', |
|
420 | + wp_kses_post( wpautop( $summary ) ) |
|
421 | + ); |
|
422 | + } |
|
423 | + |
|
424 | + printf( |
|
425 | + '<input type="hidden" value="%s" name="getpaid_items[%s][name]" class="getpaid-recalculate-prices-on-change" />', |
|
426 | + esc_attr( $item->get_raw_name() ), |
|
427 | + (int) $item->get_id() |
|
428 | + ); |
|
429 | + |
|
430 | + printf( |
|
431 | + '<textarea style="display: none;" name="getpaid_items[%s][description]" class="getpaid-recalculate-prices-on-change">%s</textarea>', |
|
432 | + (int) $item->get_id(), |
|
433 | + esc_attr( $item->get_description() ) |
|
434 | + ); |
|
435 | + |
|
436 | + break; |
|
437 | + case 'price': |
|
438 | + printf( |
|
439 | + '<input type="text" value="%s" name="getpaid_items[%s][price]" style="width: 100px;" class="getpaid-admin-invoice-item-price getpaid-recalculate-prices-on-change" />', |
|
440 | + esc_attr( getpaid_unstandardize_amount( $item->get_price() ) ), |
|
441 | + (int) $item->get_id() |
|
442 | + ); |
|
443 | + |
|
444 | + break; |
|
445 | + case 'qty': |
|
446 | + printf( |
|
447 | + '<input type="text" style="width: 100px;" value="%s" name="getpaid_items[%s][quantity]" class="getpaid-admin-invoice-item-quantity getpaid-recalculate-prices-on-change" />', |
|
448 | + floatval( $item->get_quantity() ), |
|
449 | + (int) $item->get_id() |
|
450 | + ); |
|
451 | + |
|
452 | + break; |
|
453 | + case 'total': |
|
454 | + wpinv_the_price( $item->get_sub_total(), $invoice->get_currency() ); |
|
455 | + |
|
456 | + break; |
|
457 | + case 'tax': |
|
458 | + echo floatval( wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%'; |
|
459 | + |
|
460 | + break; |
|
461 | + case 'action': |
|
462 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
463 | + echo '<i class="fa fa-trash wpinv-item-remove"></i>'; |
|
464 | 464 | } |
465 | - break; |
|
465 | + break; |
|
466 | 466 | } |
467 | 467 | do_action( 'getpaid_admin_edit_invoice_item_' . $column, $item, $invoice ); |
468 | 468 | ?> |
@@ -473,10 +473,10 @@ discard block |
||
473 | 473 | } |
474 | 474 | |
475 | 475 | /** |
476 | - * Output the metabox. |
|
477 | - * |
|
478 | - * @param WP_Post $post |
|
479 | - */ |
|
476 | + * Output the metabox. |
|
477 | + * |
|
478 | + * @param WP_Post $post |
|
479 | + */ |
|
480 | 480 | public static function output2( $post ) { |
481 | 481 | |
482 | 482 | // Prepare the invoice. |
@@ -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 | |
@@ -16,62 +16,62 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class GetPaid_Meta_Box_Invoice_Items { |
18 | 18 | |
19 | - public static function get_columns( $invoice ) { |
|
19 | + public static function get_columns($invoice) { |
|
20 | 20 | $use_taxes = $invoice->is_taxable() && wpinv_use_taxes(); |
21 | 21 | $columns = array( |
22 | - 'id' => __( 'ID', 'invoicing' ), |
|
23 | - 'title' => __( 'Item', 'invoicing' ), |
|
22 | + 'id' => __('ID', 'invoicing'), |
|
23 | + 'title' => __('Item', 'invoicing'), |
|
24 | 24 | 'price' => sprintf( |
25 | 25 | '<span class="getpaid-hide-if-hours getpaid-hide-if-quantity">%s</span> |
26 | 26 | <span class="getpaid-hide-if-hours hide-if-amount">%s</span> |
27 | 27 | <span class="getpaid-hide-if-quantity hide-if-amount">%s</span>', |
28 | - __( 'Amount', 'invoicing' ), |
|
29 | - __( 'Price', 'invoicing' ), |
|
30 | - __( 'Rate', 'invoicing' ) |
|
28 | + __('Amount', 'invoicing'), |
|
29 | + __('Price', 'invoicing'), |
|
30 | + __('Rate', 'invoicing') |
|
31 | 31 | ), |
32 | 32 | 'qty' => sprintf( |
33 | 33 | '<span class="getpaid-hide-if-hours">%s</span><span class="getpaid-hide-if-quantity">%s</span>', |
34 | - __( 'Quantity', 'invoicing' ), |
|
35 | - __( 'Hours', 'invoicing' ) |
|
34 | + __('Quantity', 'invoicing'), |
|
35 | + __('Hours', 'invoicing') |
|
36 | 36 | ), |
37 | - 'total' => __( 'Total', 'invoicing' ), |
|
37 | + 'total' => __('Total', 'invoicing'), |
|
38 | 38 | 'tax' => $invoice->get_item_tax_name(), |
39 | 39 | 'action' => '', |
40 | 40 | ); |
41 | 41 | |
42 | - if ( ! $use_taxes ) { |
|
43 | - unset( $columns['tax'] ); |
|
42 | + if (!$use_taxes) { |
|
43 | + unset($columns['tax']); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | return $columns; |
47 | 47 | } |
48 | 48 | |
49 | - public static function output( $post, $invoice = false ) { |
|
49 | + public static function output($post, $invoice = false) { |
|
50 | 50 | |
51 | - if ( apply_filters( 'getpaid_use_new_invoice_items_metabox', false ) ) { |
|
52 | - return self::output2( $post ); |
|
51 | + if (apply_filters('getpaid_use_new_invoice_items_metabox', false)) { |
|
52 | + return self::output2($post); |
|
53 | 53 | } |
54 | 54 | |
55 | - $post_id = ! empty( $post->ID ) ? $post->ID : 0; |
|
56 | - $invoice = $invoice instanceof WPInv_Invoice ? $invoice : new WPInv_Invoice( $post_id ); |
|
55 | + $post_id = !empty($post->ID) ? $post->ID : 0; |
|
56 | + $invoice = $invoice instanceof WPInv_Invoice ? $invoice : new WPInv_Invoice($post_id); |
|
57 | 57 | $use_taxes = $invoice->is_taxable() && wpinv_use_taxes(); |
58 | - $item_types = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post ); |
|
59 | - $columns = self::get_columns( $invoice ); |
|
60 | - $cols = count( $columns ); |
|
58 | + $item_types = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post); |
|
59 | + $columns = self::get_columns($invoice); |
|
60 | + $cols = count($columns); |
|
61 | 61 | $class = ''; |
62 | 62 | |
63 | - unset( $item_types['adv'] ); |
|
64 | - unset( $item_types['package'] ); |
|
63 | + unset($item_types['adv']); |
|
64 | + unset($item_types['package']); |
|
65 | 65 | |
66 | - if ( $invoice->is_paid() ) { |
|
66 | + if ($invoice->is_paid()) { |
|
67 | 67 | $class .= ' wpinv-paid'; |
68 | 68 | } |
69 | 69 | |
70 | - if ( $invoice->is_refunded() ) { |
|
70 | + if ($invoice->is_refunded()) { |
|
71 | 71 | $class .= ' wpinv-refunded'; |
72 | 72 | } |
73 | 73 | |
74 | - if ( $invoice->is_recurring() ) { |
|
74 | + if ($invoice->is_recurring()) { |
|
75 | 75 | $class .= ' wpi-recurring'; |
76 | 76 | } |
77 | 77 | |
@@ -87,26 +87,26 @@ discard block |
||
87 | 87 | ); |
88 | 88 | ?> |
89 | 89 | |
90 | - <div class="wpinv-items-wrap<?php echo esc_attr( $class ); ?>" id="wpinv_items_wrap" data-status="<?php echo esc_attr( $invoice->get_status() ); ?>"> |
|
90 | + <div class="wpinv-items-wrap<?php echo esc_attr($class); ?>" id="wpinv_items_wrap" data-status="<?php echo esc_attr($invoice->get_status()); ?>"> |
|
91 | 91 | <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0"> |
92 | 92 | |
93 | 93 | <thead> |
94 | 94 | <tr> |
95 | - <?php foreach ( $columns as $key => $label ) : ?> |
|
95 | + <?php foreach ($columns as $key => $label) : ?> |
|
96 | 96 | <th class=" |
97 | 97 | <?php |
98 | - echo esc_attr( $key ); |
|
98 | + echo esc_attr($key); |
|
99 | 99 | echo 'total' == $key || 'qty' == $key ? ' hide-if-amount' : ''; |
100 | 100 | ?> |
101 | - "><?php echo wp_kses_post( $label ); ?></th> |
|
101 | + "><?php echo wp_kses_post($label); ?></th> |
|
102 | 102 | <?php endforeach; ?> |
103 | 103 | </tr> |
104 | 104 | </thead> |
105 | 105 | |
106 | 106 | <tbody class="wpinv-line-items"> |
107 | 107 | <?php |
108 | - foreach ( $invoice->get_items() as $int => $item ) { |
|
109 | - self::output_row( $columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd' ); |
|
108 | + foreach ($invoice->get_items() as $int => $item) { |
|
109 | + self::output_row($columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd'); |
|
110 | 110 | } |
111 | 111 | ?> |
112 | 112 | </tbody> |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | <div class="wp-clearfix"> |
124 | 124 | <label class="wpi-item-name"> |
125 | 125 | <span class="input-text-wrap"> |
126 | - <input type="text" style="width: 100%" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="wpinv-quick-item-name" name="_wpinv_quick[name]"> |
|
126 | + <input type="text" style="width: 100%" placeholder="<?php esc_attr_e('Item Name', 'invoicing'); ?>" class="wpinv-quick-item-name" name="_wpinv_quick[name]"> |
|
127 | 127 | </span> |
128 | 128 | </label> |
129 | 129 | </div> |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | <div class="wp-clearfix"> |
132 | 132 | <label class="wpi-item-price"> |
133 | 133 | <span class="input-text-wrap"> |
134 | - <input type="text" style="width: 200px" placeholder="<?php esc_attr_e( 'Item Price', 'invoicing' ); ?>" class="wpinv-quick-item-price" name="_wpinv_quick[price]"> |
|
135 | - × <input type="text" style="width: 140px" placeholder="<?php esc_attr_e( 'Item Quantity', 'invoicing' ); ?>" class="wpinv-quick-item-qty" name="_wpinv_quick[qty]"> |
|
134 | + <input type="text" style="width: 200px" placeholder="<?php esc_attr_e('Item Price', 'invoicing'); ?>" class="wpinv-quick-item-price" name="_wpinv_quick[price]"> |
|
135 | + × <input type="text" style="width: 140px" placeholder="<?php esc_attr_e('Item Quantity', 'invoicing'); ?>" class="wpinv-quick-item-qty" name="_wpinv_quick[qty]"> |
|
136 | 136 | </span> |
137 | 137 | </label> |
138 | 138 | </div> |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | <div class="wp-clearfix"> |
141 | 141 | <label class="wpi-item-name"> |
142 | 142 | <span class="input-text-wrap"> |
143 | - <textarea rows="4" style="width: 100%" placeholder="<?php esc_attr_e( 'Item Description', 'invoicing' ); ?>" class="wpinv-quick-item-description" name="_wpinv_quick[description]"></textarea> |
|
143 | + <textarea rows="4" style="width: 100%" placeholder="<?php esc_attr_e('Item Description', 'invoicing'); ?>" class="wpinv-quick-item-description" name="_wpinv_quick[description]"></textarea> |
|
144 | 144 | </span> |
145 | 145 | </label> |
146 | 146 | </div> |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | </label> |
166 | 166 | </div> |
167 | 167 | |
168 | - <?php if ( $use_taxes ) : ?> |
|
168 | + <?php if ($use_taxes) : ?> |
|
169 | 169 | <div class="wp-clearfix"> |
170 | 170 | <label class="wpi-vat-rule"> |
171 | 171 | <span class="input-text-wrap"> |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | wpinv_html_select( |
174 | 174 | array( |
175 | 175 | 'options' => array_merge( |
176 | - array( '' => __( 'Select VAT Rule', 'invoicing' ) ), |
|
176 | + array('' => __('Select VAT Rule', 'invoicing')), |
|
177 | 177 | getpaid_get_tax_rules() |
178 | 178 | ), |
179 | 179 | 'name' => '_wpinv_quick[vat_rule]', |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | wpinv_html_select( |
196 | 196 | array( |
197 | 197 | 'options' => array_merge( |
198 | - array( '' => __( 'Select VAT Class', 'invoicing' ) ), |
|
198 | + array('' => __('Select VAT Class', 'invoicing')), |
|
199 | 199 | getpaid_get_tax_classes() |
200 | 200 | ), |
201 | 201 | 'name' => '_wpinv_quick[vat_class]', |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | 'type' => 'checkbox', |
220 | 220 | 'name' => '_wpinv_quick[one-time]', |
221 | 221 | 'id' => '_wpinv_quick-one-time', |
222 | - 'label' => __( "One time item (won't be saved to regular items list)", 'invoicing' ), |
|
222 | + 'label' => __("One time item (won't be saved to regular items list)", 'invoicing'), |
|
223 | 223 | 'value' => 1, |
224 | 224 | 'no_wrap' => true, |
225 | 225 | 'checked' => false, |
@@ -243,39 +243,39 @@ discard block |
||
243 | 243 | </td> |
244 | 244 | </tr> |
245 | 245 | <tr class="totals"> |
246 | - <td colspan="<?php echo ( (int) $cols - 4 ); ?>"></td> |
|
246 | + <td colspan="<?php echo ((int) $cols - 4); ?>"></td> |
|
247 | 247 | <td colspan="4"> |
248 | 248 | <table cellspacing="0" cellpadding="0"> |
249 | 249 | <tr class="subtotal"> |
250 | - <td class="name"><?php esc_html_e( 'Sub Total:', 'invoicing' ); ?></td> |
|
251 | - <td class="total"><?php wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); ?></td> |
|
250 | + <td class="name"><?php esc_html_e('Sub Total:', 'invoicing'); ?></td> |
|
251 | + <td class="total"><?php wpinv_the_price($invoice->get_subtotal(), $invoice->get_currency()); ?></td> |
|
252 | 252 | <td class="action"></td> |
253 | 253 | </tr> |
254 | 254 | <tr class="discount"> |
255 | - <td class="name"><?php esc_html_e( 'Discount:', 'invoicing' ); ?></td> |
|
256 | - <td class="total"><?php wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); ?></td> |
|
255 | + <td class="name"><?php esc_html_e('Discount:', 'invoicing'); ?></td> |
|
256 | + <td class="total"><?php wpinv_the_price($invoice->get_total_discount(), $invoice->get_currency()); ?></td> |
|
257 | 257 | <td class="action"></td> |
258 | 258 | </tr> |
259 | - <?php if ( $use_taxes ) : ?> |
|
260 | - <?php if ( is_array( $taxes = $invoice->get_taxes() ) && wpinv_display_individual_tax_rates() ) { ?> |
|
261 | - <?php foreach ( $taxes as $tax_key => $tax_item ) { ?> |
|
259 | + <?php if ($use_taxes) : ?> |
|
260 | + <?php if (is_array($taxes = $invoice->get_taxes()) && wpinv_display_individual_tax_rates()) { ?> |
|
261 | + <?php foreach ($taxes as $tax_key => $tax_item) { ?> |
|
262 | 262 | <tr class="tax"> |
263 | - <td class="name"><?php echo esc_html( $invoice->get_tax_item_name( $tax_key, $tax_item, ':' ) ); ?></td> |
|
264 | - <td class="total"><?php wpinv_the_price( $invoice->get_tax_item_amount( $tax_key, $tax_item ), $invoice->get_currency() ); ?></td> |
|
263 | + <td class="name"><?php echo esc_html($invoice->get_tax_item_name($tax_key, $tax_item, ':')); ?></td> |
|
264 | + <td class="total"><?php wpinv_the_price($invoice->get_tax_item_amount($tax_key, $tax_item), $invoice->get_currency()); ?></td> |
|
265 | 265 | <td class="action"></td> |
266 | 266 | </tr> |
267 | 267 | <?php } ?> |
268 | 268 | <?php } else { ?> |
269 | 269 | <tr class="tax"> |
270 | - <td class="name"><?php esc_html_e( 'Tax:', 'invoicing' ); ?></td> |
|
271 | - <td class="total"><?php wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() ); ?></td> |
|
270 | + <td class="name"><?php esc_html_e('Tax:', 'invoicing'); ?></td> |
|
271 | + <td class="total"><?php wpinv_the_price($invoice->get_total_tax(), $invoice->get_currency()); ?></td> |
|
272 | 272 | <td class="action"></td> |
273 | 273 | </tr> |
274 | 274 | <?php } ?> |
275 | 275 | <?php endif; ?> |
276 | 276 | <tr class="total"> |
277 | - <td class="name"><?php esc_html_e( 'Total:', 'invoicing' ); ?></td> |
|
278 | - <td class="total"><?php wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); ?></td> |
|
277 | + <td class="name"><?php esc_html_e('Total:', 'invoicing'); ?></td> |
|
278 | + <td class="total"><?php wpinv_the_price($invoice->get_total(), $invoice->get_currency()); ?></td> |
|
279 | 279 | <td class="action"></td> |
280 | 280 | </tr> |
281 | 281 | </table> |
@@ -291,18 +291,18 @@ discard block |
||
291 | 291 | <div class="modal-dialog modal-dialog-centered" role="document"> |
292 | 292 | <div class="modal-content"> |
293 | 293 | <div class="modal-header"> |
294 | - <h5 class="modal-title" id="getpaid-refund-invoice-modal-label"><?php esc_html_e( 'Refund Payment', 'invoicing' ); ?></h5> |
|
295 | - <button type="button" class="close btn-close" data-bs-dismiss="modal" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>"> |
|
296 | - <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
|
294 | + <h5 class="modal-title" id="getpaid-refund-invoice-modal-label"><?php esc_html_e('Refund Payment', 'invoicing'); ?></h5> |
|
295 | + <button type="button" class="close btn-close" data-bs-dismiss="modal" data-dismiss="modal" aria-label="<?php esc_html_e('Close', 'invoicing'); ?>"> |
|
296 | + <?php if (empty($GLOBALS['aui_bs5'])) : ?> |
|
297 | 297 | <span aria-hidden="true">×</span> |
298 | 298 | <?php endif; ?> |
299 | 299 | </button> |
300 | 300 | </div> |
301 | 301 | <div class="modal-body"> |
302 | 302 | <p> |
303 | - <?php esc_html_e( 'Are you sure you want to refund this payment?', 'invoicing' ); ?> |
|
303 | + <?php esc_html_e('Are you sure you want to refund this payment?', 'invoicing'); ?> |
|
304 | 304 | </p> |
305 | - <?php if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) ) : ?> |
|
305 | + <?php if (getpaid_payment_gateway_supports($invoice->get_gateway(), 'refunds')) : ?> |
|
306 | 306 | <?php |
307 | 307 | aui()->input( |
308 | 308 | array( |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | 'id' => 'getpaid_refund_remote', |
312 | 312 | 'label' => sprintf( |
313 | 313 | 'Refund payment in %s', |
314 | - wpinv_get_gateway_admin_label( $invoice->get_gateway() ) |
|
314 | + wpinv_get_gateway_admin_label($invoice->get_gateway()) |
|
315 | 315 | ), |
316 | 316 | 'value' => 1, |
317 | 317 | 'class' => 'getpaid-refund-field', |
@@ -321,14 +321,14 @@ discard block |
||
321 | 321 | ?> |
322 | 322 | <?php endif; ?> |
323 | 323 | |
324 | - <?php if ( getpaid_get_invoice_subscriptions( $invoice ) ) : ?> |
|
324 | + <?php if (getpaid_get_invoice_subscriptions($invoice)) : ?> |
|
325 | 325 | <?php |
326 | 326 | aui()->input( |
327 | 327 | array( |
328 | 328 | 'type' => 'checkbox', |
329 | 329 | 'name' => 'getpaid_cancel_subscription', |
330 | 330 | 'id' => 'getpaid_cancel_subscription', |
331 | - 'label' => __( 'Cancel subscription', 'invoicing' ), |
|
331 | + 'label' => __('Cancel subscription', 'invoicing'), |
|
332 | 332 | 'value' => 1, |
333 | 333 | 'class' => 'getpaid-refund-field', |
334 | 334 | ), |
@@ -338,12 +338,12 @@ discard block |
||
338 | 338 | <?php endif; ?> |
339 | 339 | </div> |
340 | 340 | <div class="modal-footer"> |
341 | - <button type="button" class="btn btn-secondary getpaid-cancel" data-bs-dismiss="modal" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button> |
|
341 | + <button type="button" class="btn btn-secondary getpaid-cancel" data-bs-dismiss="modal" data-dismiss="modal"><?php esc_html_e('Cancel', 'invoicing'); ?></button> |
|
342 | 342 | <a |
343 | - href="<?php echo esc_url_raw( $refund_url ); ?>" |
|
344 | - data-href="<?php echo esc_url_raw( $refund_url ); ?>" |
|
343 | + href="<?php echo esc_url_raw($refund_url); ?>" |
|
344 | + data-href="<?php echo esc_url_raw($refund_url); ?>" |
|
345 | 345 | class="btn btn-primary getpaid-refund-payment-button" |
346 | - ><?php esc_html_e( 'Refund', 'invoicing' ); ?></a> |
|
346 | + ><?php esc_html_e('Refund', 'invoicing'); ?></a> |
|
347 | 347 | <script> |
348 | 348 | // Update the refund URL when the user changes the refund options. |
349 | 349 | jQuery( function( $ ) { |
@@ -369,13 +369,13 @@ discard block |
||
369 | 369 | |
370 | 370 | <div class="wpinv-actions"> |
371 | 371 | <?php |
372 | - if ( $invoice->is_paid() ) { |
|
372 | + if ($invoice->is_paid()) { |
|
373 | 373 | |
374 | 374 | printf( |
375 | 375 | '<span class="bsui"><button type="button" class="button button-primary" data-toggle="modal" data-bs-toggle="modal" data-bs-target="#getpaid-refund-invoice-modal" data-target="#getpaid-refund-invoice-modal">%s</button></span>', |
376 | - esc_html__( 'Refund', 'invoicing' ) |
|
376 | + esc_html__('Refund', 'invoicing') |
|
377 | 377 | ); |
378 | - } elseif ( ! $invoice->is_refunded() ) { |
|
378 | + } elseif (!$invoice->is_refunded()) { |
|
379 | 379 | wpinv_item_dropdown( |
380 | 380 | array( |
381 | 381 | 'name' => 'wpinv_invoice_item', |
@@ -385,66 +385,66 @@ discard block |
||
385 | 385 | ) |
386 | 386 | ); |
387 | 387 | |
388 | - echo ' ' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf( esc_html__( 'Add item to %s', 'invoicing' ), esc_html( $invoice->get_label() ) ) . '</button>'; |
|
389 | - echo ' ' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__( 'Create new item', 'invoicing' ) . '</button>'; |
|
390 | - echo ' ' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__( 'Recalculate Totals', 'invoicing' ) . '</button>'; |
|
388 | + echo ' ' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf(esc_html__('Add item to %s', 'invoicing'), esc_html($invoice->get_label())) . '</button>'; |
|
389 | + echo ' ' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__('Create new item', 'invoicing') . '</button>'; |
|
390 | + echo ' ' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__('Recalculate Totals', 'invoicing') . '</button>'; |
|
391 | 391 | |
392 | 392 | } |
393 | 393 | ?> |
394 | - <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?> |
|
394 | + <?php do_action('wpinv_invoice_items_actions', $invoice); ?> |
|
395 | 395 | </div> |
396 | 396 | </div> |
397 | 397 | <?php |
398 | 398 | } |
399 | 399 | |
400 | - public static function output_row( $columns, $item, $invoice, $class = 'even' ) { |
|
400 | + public static function output_row($columns, $item, $invoice, $class = 'even') { |
|
401 | 401 | |
402 | 402 | ?> |
403 | - <tr class="item item-<?php echo esc_attr( $class ); ?>" data-item-id="<?php echo esc_attr( $item->get_id() ); ?>"> |
|
404 | - <?php foreach ( array_keys( $columns ) as $column ) : ?> |
|
403 | + <tr class="item item-<?php echo esc_attr($class); ?>" data-item-id="<?php echo esc_attr($item->get_id()); ?>"> |
|
404 | + <?php foreach (array_keys($columns) as $column) : ?> |
|
405 | 405 | <td class=" |
406 | 406 | <?php |
407 | - echo esc_attr( $column ); |
|
407 | + echo esc_attr($column); |
|
408 | 408 | echo 'total' == $column || 'qty' == $column ? ' hide-if-amount' : ''; |
409 | 409 | ?> |
410 | 410 | "> |
411 | 411 | <?php |
412 | - switch ( $column ) { |
|
412 | + switch ($column) { |
|
413 | 413 | case 'id': |
414 | 414 | echo (int) $item->get_id(); |
415 | 415 | break; |
416 | 416 | case 'title': |
417 | 417 | printf( |
418 | 418 | '<a href="%s" target="_blank">%s</a>', |
419 | - esc_url( get_edit_post_link( $item->get_id() ) ), |
|
420 | - esc_html( $item->get_raw_name() ) |
|
419 | + esc_url(get_edit_post_link($item->get_id())), |
|
420 | + esc_html($item->get_raw_name()) |
|
421 | 421 | ); |
422 | 422 | |
423 | - $summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice ); |
|
424 | - if ( $summary !== '' ) { |
|
423 | + $summary = apply_filters('getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice); |
|
424 | + if ($summary !== '') { |
|
425 | 425 | printf( |
426 | 426 | '<span class="meta">%s</span>', |
427 | - wp_kses_post( wpautop( $summary ) ) |
|
427 | + wp_kses_post(wpautop($summary)) |
|
428 | 428 | ); |
429 | 429 | } |
430 | 430 | |
431 | 431 | printf( |
432 | 432 | '<input type="hidden" value="%s" name="getpaid_items[%s][name]" class="getpaid-recalculate-prices-on-change" />', |
433 | - esc_attr( $item->get_raw_name() ), |
|
433 | + esc_attr($item->get_raw_name()), |
|
434 | 434 | (int) $item->get_id() |
435 | 435 | ); |
436 | 436 | |
437 | 437 | printf( |
438 | 438 | '<textarea style="display: none;" name="getpaid_items[%s][description]" class="getpaid-recalculate-prices-on-change">%s</textarea>', |
439 | 439 | (int) $item->get_id(), |
440 | - esc_attr( $item->get_description() ) |
|
440 | + esc_attr($item->get_description()) |
|
441 | 441 | ); |
442 | 442 | |
443 | 443 | break; |
444 | 444 | case 'price': |
445 | 445 | printf( |
446 | 446 | '<input type="text" value="%s" name="getpaid_items[%s][price]" style="width: 100px;" class="getpaid-admin-invoice-item-price getpaid-recalculate-prices-on-change" />', |
447 | - esc_attr( getpaid_unstandardize_amount( $item->get_price() ) ), |
|
447 | + esc_attr(getpaid_unstandardize_amount($item->get_price())), |
|
448 | 448 | (int) $item->get_id() |
449 | 449 | ); |
450 | 450 | |
@@ -452,26 +452,26 @@ discard block |
||
452 | 452 | case 'qty': |
453 | 453 | printf( |
454 | 454 | '<input type="text" style="width: 100px;" value="%s" name="getpaid_items[%s][quantity]" class="getpaid-admin-invoice-item-quantity getpaid-recalculate-prices-on-change" />', |
455 | - floatval( $item->get_quantity() ), |
|
455 | + floatval($item->get_quantity()), |
|
456 | 456 | (int) $item->get_id() |
457 | 457 | ); |
458 | 458 | |
459 | 459 | break; |
460 | 460 | case 'total': |
461 | - wpinv_the_price( $item->get_sub_total(), $invoice->get_currency() ); |
|
461 | + wpinv_the_price($item->get_sub_total(), $invoice->get_currency()); |
|
462 | 462 | |
463 | 463 | break; |
464 | 464 | case 'tax': |
465 | - echo floatval( wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%'; |
|
465 | + echo floatval(wpinv_round_amount(getpaid_get_invoice_tax_rate($invoice, $item), 2)) . '%'; |
|
466 | 466 | |
467 | 467 | break; |
468 | 468 | case 'action': |
469 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
469 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
470 | 470 | echo '<i class="fa fa-trash wpinv-item-remove"></i>'; |
471 | 471 | } |
472 | 472 | break; |
473 | 473 | } |
474 | - do_action( 'getpaid_admin_edit_invoice_item_' . $column, $item, $invoice ); |
|
474 | + do_action('getpaid_admin_edit_invoice_item_' . $column, $item, $invoice); |
|
475 | 475 | ?> |
476 | 476 | </td> |
477 | 477 | <?php endforeach; ?> |
@@ -484,10 +484,10 @@ discard block |
||
484 | 484 | * |
485 | 485 | * @param WP_Post $post |
486 | 486 | */ |
487 | - public static function output2( $post ) { |
|
487 | + public static function output2($post) { |
|
488 | 488 | |
489 | 489 | // Prepare the invoice. |
490 | - $invoice = new WPInv_Invoice( $post ); |
|
490 | + $invoice = new WPInv_Invoice($post); |
|
491 | 491 | |
492 | 492 | // Invoice items. |
493 | 493 | $items = $invoice->get_items(); |
@@ -495,28 +495,28 @@ discard block |
||
495 | 495 | $totals = array( |
496 | 496 | |
497 | 497 | 'subtotal' => array( |
498 | - 'label' => __( 'Items Subtotal', 'invoicing' ), |
|
499 | - 'value' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
|
498 | + 'label' => __('Items Subtotal', 'invoicing'), |
|
499 | + 'value' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()), |
|
500 | 500 | ), |
501 | 501 | |
502 | 502 | 'discount' => array( |
503 | - 'label' => __( 'Total Discount', 'invoicing' ), |
|
504 | - 'value' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
503 | + 'label' => __('Total Discount', 'invoicing'), |
|
504 | + 'value' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
505 | 505 | ), |
506 | 506 | |
507 | 507 | 'tax' => array( |
508 | - 'label' => __( 'Total Tax', 'invoicing' ), |
|
509 | - 'value' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
|
508 | + 'label' => __('Total Tax', 'invoicing'), |
|
509 | + 'value' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()), |
|
510 | 510 | ), |
511 | 511 | |
512 | 512 | 'total' => array( |
513 | - 'label' => __( 'Invoice Total', 'invoicing' ), |
|
514 | - 'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ), |
|
513 | + 'label' => __('Invoice Total', 'invoicing'), |
|
514 | + 'value' => wpinv_price($invoice->get_total(), $invoice->get_currency()), |
|
515 | 515 | ), |
516 | 516 | ); |
517 | 517 | |
518 | - if ( ! wpinv_use_taxes() ) { |
|
519 | - unset( $totals['tax'] ); |
|
518 | + if (!wpinv_use_taxes()) { |
|
519 | + unset($totals['tax']); |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | $item_args = array( |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | 'orderby' => 'title', |
525 | 525 | 'order' => 'ASC', |
526 | 526 | 'posts_per_page' => -1, |
527 | - 'post_status' => array( 'publish' ), |
|
527 | + 'post_status' => array('publish'), |
|
528 | 528 | 'meta_query' => array( |
529 | 529 | array( |
530 | 530 | 'key' => '_wpinv_type', |
@@ -552,10 +552,10 @@ discard block |
||
552 | 552 | } |
553 | 553 | </style> |
554 | 554 | |
555 | - <div class="bsui getpaid-invoice-items-inner <?php echo empty( $items ) ? 'no-items' : 'has-items'; ?> <?php echo $invoice->is_paid() || $invoice->is_refunded() ? 'not-editable' : 'editable'; ?>" style="margin-top: 1.5rem; padding: 0 12px 12px;"> |
|
555 | + <div class="bsui getpaid-invoice-items-inner <?php echo empty($items) ? 'no-items' : 'has-items'; ?> <?php echo $invoice->is_paid() || $invoice->is_refunded() ? 'not-editable' : 'editable'; ?>" style="margin-top: 1.5rem; padding: 0 12px 12px;"> |
|
556 | 556 | |
557 | - <?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?> |
|
558 | - <?php do_action( 'wpinv_meta_box_before_invoice_template_row', $invoice->get_id() ); ?> |
|
557 | + <?php if (!$invoice->is_paid() && !$invoice->is_refunded()) : ?> |
|
558 | + <?php do_action('wpinv_meta_box_before_invoice_template_row', $invoice->get_id()); ?> |
|
559 | 559 | |
560 | 560 | <div class="row"> |
561 | 561 | <div class="col-12 col-sm-6"> |
@@ -564,15 +564,15 @@ discard block |
||
564 | 564 | array( |
565 | 565 | 'id' => 'wpinv_template', |
566 | 566 | 'name' => 'wpinv_template', |
567 | - 'label' => __( 'Template', 'invoicing' ), |
|
567 | + 'label' => __('Template', 'invoicing'), |
|
568 | 568 | 'label_type' => 'vertical', |
569 | - 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
569 | + 'placeholder' => __('Choose a template', 'invoicing'), |
|
570 | 570 | 'class' => 'form-control-sm', |
571 | - 'value' => $invoice->get_template( 'edit' ), |
|
571 | + 'value' => $invoice->get_template('edit'), |
|
572 | 572 | 'options' => array( |
573 | - 'quantity' => __( 'Quantity', 'invoicing' ), |
|
574 | - 'hours' => __( 'Hours', 'invoicing' ), |
|
575 | - 'amount' => __( 'Amount Only', 'invoicing' ), |
|
573 | + 'quantity' => __('Quantity', 'invoicing'), |
|
574 | + 'hours' => __('Hours', 'invoicing'), |
|
575 | + 'amount' => __('Amount Only', 'invoicing'), |
|
576 | 576 | ), |
577 | 577 | 'data-allow-clear' => 'false', |
578 | 578 | 'select2' => true, |
@@ -589,11 +589,11 @@ discard block |
||
589 | 589 | array( |
590 | 590 | 'id' => 'wpinv_currency', |
591 | 591 | 'name' => 'wpinv_currency', |
592 | - 'label' => __( 'Currency', 'invoicing' ), |
|
592 | + 'label' => __('Currency', 'invoicing'), |
|
593 | 593 | 'label_type' => 'vertical', |
594 | - 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
594 | + 'placeholder' => __('Select Invoice Currency', 'invoicing'), |
|
595 | 595 | 'class' => 'form-control-sm', |
596 | - 'value' => $invoice->get_currency( 'edit' ), |
|
596 | + 'value' => $invoice->get_currency('edit'), |
|
597 | 597 | 'required' => false, |
598 | 598 | 'data-allow-clear' => 'false', |
599 | 599 | 'select2' => true, |
@@ -606,24 +606,24 @@ discard block |
||
606 | 606 | </div> |
607 | 607 | </div> |
608 | 608 | |
609 | - <?php do_action( 'wpinv_meta_box_invoice_template_row', $invoice->get_id() ); ?> |
|
609 | + <?php do_action('wpinv_meta_box_invoice_template_row', $invoice->get_id()); ?> |
|
610 | 610 | <?php endif; ?> |
611 | 611 | |
612 | 612 | <table cellpadding="0" cellspacing="0" class="getpaid_invoice_items"> |
613 | 613 | <thead> |
614 | 614 | <tr> |
615 | - <th class="getpaid-item" colspan="2"><?php esc_html_e( 'Item', 'invoicing' ); ?></th> |
|
615 | + <th class="getpaid-item" colspan="2"><?php esc_html_e('Item', 'invoicing'); ?></th> |
|
616 | 616 | <th class="getpaid-quantity hide-if-amount text-right"> |
617 | - <span class="getpaid-hide-if-hours"><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span> |
|
618 | - <span class="getpaid-hide-if-quantity"><?php esc_html_e( 'Hours', 'invoicing' ); ?></span> |
|
617 | + <span class="getpaid-hide-if-hours"><?php esc_html_e('Quantity', 'invoicing'); ?></span> |
|
618 | + <span class="getpaid-hide-if-quantity"><?php esc_html_e('Hours', 'invoicing'); ?></span> |
|
619 | 619 | </th> |
620 | 620 | <th class="getpaid-price hide-if-amount text-right"> |
621 | - <span class="getpaid-hide-if-hours"><?php esc_html_e( 'Price', 'invoicing' ); ?></span> |
|
622 | - <span class="getpaid-hide-if-quantity"><?php esc_html_e( 'Rate', 'invoicing' ); ?></span> |
|
621 | + <span class="getpaid-hide-if-hours"><?php esc_html_e('Price', 'invoicing'); ?></span> |
|
622 | + <span class="getpaid-hide-if-quantity"><?php esc_html_e('Rate', 'invoicing'); ?></span> |
|
623 | 623 | </th> |
624 | 624 | <th class="getpaid-item-subtotal text-right"> |
625 | - <span class="getpaid-hide-if-hours getpaid-hide-if-quantity"><?php esc_html_e( 'Amount', 'invoicing' ); ?></span> |
|
626 | - <span class="hide-if-amount"><?php esc_html_e( 'Total', 'invoicing' ); ?></span> |
|
625 | + <span class="getpaid-hide-if-hours getpaid-hide-if-quantity"><?php esc_html_e('Amount', 'invoicing'); ?></span> |
|
626 | + <span class="hide-if-amount"><?php esc_html_e('Total', 'invoicing'); ?></span> |
|
627 | 627 | </th> |
628 | 628 | <th class="getpaid-item-actions hide-if-not-editable" width="70px"> </th> |
629 | 629 | </tr> |
@@ -631,8 +631,8 @@ discard block |
||
631 | 631 | <tbody class="getpaid_invoice_line_items"> |
632 | 632 | <tr class="hide-if-has-items hide-if-not-editable"> |
633 | 633 | <td colspan="2" class="pt-4 pb-4"> |
634 | - <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php esc_html_e( 'Add Existing Items', 'invoicing' ); ?></button> |
|
635 | - <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php esc_html_e( 'Create New Item', 'invoicing' ); ?></button> |
|
634 | + <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php esc_html_e('Add Existing Items', 'invoicing'); ?></button> |
|
635 | + <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php esc_html_e('Create New Item', 'invoicing'); ?></button> |
|
636 | 636 | </td> |
637 | 637 | <td class="hide-if-amount"> </th> |
638 | 638 | <td class="hide-if-amount"> </th> |
@@ -664,11 +664,11 @@ discard block |
||
664 | 664 | <div class="col-12 col-sm-6 offset-sm-6"> |
665 | 665 | <table class="getpaid-invoice-totals text-right w-100"> |
666 | 666 | <tbody> |
667 | - <?php foreach ( apply_filters( 'getpaid_invoice_subtotal_rows', $totals, $invoice ) as $key => $data ) : ?> |
|
668 | - <tr class="getpaid-totals-<?php echo esc_attr( $key ); ?>"> |
|
669 | - <td class="label"><?php echo esc_html( $data['label'] ); ?>:</td> |
|
667 | + <?php foreach (apply_filters('getpaid_invoice_subtotal_rows', $totals, $invoice) as $key => $data) : ?> |
|
668 | + <tr class="getpaid-totals-<?php echo esc_attr($key); ?>"> |
|
669 | + <td class="label"><?php echo esc_html($data['label']); ?>:</td> |
|
670 | 670 | <td width="1%"></td> |
671 | - <td class="value"><?php echo wp_kses_post( $data['value'] ); ?></td> |
|
671 | + <td class="value"><?php echo wp_kses_post($data['value']); ?></td> |
|
672 | 672 | </tr> |
673 | 673 | <?php endforeach; ?> |
674 | 674 | </tbody> |
@@ -681,18 +681,18 @@ discard block |
||
681 | 681 | <div class="getpaid-invoice-item-actions hide-if-no-items hide-if-not-editable"> |
682 | 682 | <div class="row"> |
683 | 683 | <div class="text-left col-12 col-sm-8"> |
684 | - <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php esc_html_e( 'Add Existing Item', 'invoicing' ); ?></button> |
|
685 | - <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php esc_html_e( 'Create New Item', 'invoicing' ); ?></button> |
|
686 | - <?php do_action( 'getpaid-invoice-items-actions', $invoice ); ?> |
|
684 | + <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php esc_html_e('Add Existing Item', 'invoicing'); ?></button> |
|
685 | + <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php esc_html_e('Create New Item', 'invoicing'); ?></button> |
|
686 | + <?php do_action('getpaid-invoice-items-actions', $invoice); ?> |
|
687 | 687 | </div> |
688 | 688 | <div class="text-right col-12 col-sm-4"> |
689 | - <button type="button" class="button button-primary recalculate-totals-button"><?php esc_html_e( 'Recalculate Totals', 'invoicing' ); ?></button> |
|
689 | + <button type="button" class="button button-primary recalculate-totals-button"><?php esc_html_e('Recalculate Totals', 'invoicing'); ?></button> |
|
690 | 690 | </div> |
691 | 691 | </div> |
692 | 692 | </div> |
693 | 693 | |
694 | 694 | <div class="getpaid-invoice-item-actions hide-if-editable"> |
695 | - <p class="description m-2 text-right text-muted"><?php esc_html_e( 'This invoice is no longer editable', 'invoicing' ); ?></p> |
|
695 | + <p class="description m-2 text-right text-muted"><?php esc_html_e('This invoice is no longer editable', 'invoicing'); ?></p> |
|
696 | 696 | </div> |
697 | 697 | |
698 | 698 | <!-- Add items to an invoice --> |
@@ -700,9 +700,9 @@ discard block |
||
700 | 700 | <div class="modal-dialog modal-dialog-centered" role="document"> |
701 | 701 | <div class="modal-content"> |
702 | 702 | <div class="modal-header"> |
703 | - <h5 class="modal-title" id="getpaid-add-item-to-invoice-label"><?php esc_html_e( 'Add Item(s)', 'invoicing' ); ?></h5> |
|
704 | - <button type="button" class="close btn-close" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>"> |
|
705 | - <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
|
703 | + <h5 class="modal-title" id="getpaid-add-item-to-invoice-label"><?php esc_html_e('Add Item(s)', 'invoicing'); ?></h5> |
|
704 | + <button type="button" class="close btn-close" data-dismiss="modal" aria-label="<?php esc_html_e('Close', 'invoicing'); ?>"> |
|
705 | + <?php if (empty($GLOBALS['aui_bs5'])) : ?> |
|
706 | 706 | <span aria-hidden="true">×</span> |
707 | 707 | <?php endif; ?> |
708 | 708 | </button> |
@@ -711,10 +711,10 @@ discard block |
||
711 | 711 | <table class="widefat"> |
712 | 712 | <thead> |
713 | 713 | <tr> |
714 | - <th class="pl-0 text-left"><?php esc_html_e( 'Item', 'invoicing' ); ?></th> |
|
714 | + <th class="pl-0 text-left"><?php esc_html_e('Item', 'invoicing'); ?></th> |
|
715 | 715 | <th class="pr-0 text-right hide-if-amount"> |
716 | - <span class="getpaid-hide-if-hours"><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span> |
|
717 | - <span class="getpaid-hide-if-quantity"><?php esc_html_e( 'Hours', 'invoicing' ); ?></span> |
|
716 | + <span class="getpaid-hide-if-hours"><?php esc_html_e('Quantity', 'invoicing'); ?></span> |
|
717 | + <span class="getpaid-hide-if-quantity"><?php esc_html_e('Hours', 'invoicing'); ?></span> |
|
718 | 718 | </th> |
719 | 719 | </tr> |
720 | 720 | </thead> |
@@ -722,9 +722,9 @@ discard block |
||
722 | 722 | <tr> |
723 | 723 | <td class="pl-0 text-left"> |
724 | 724 | <select class="regular-text getpaid-add-invoice-item-select"> |
725 | - <option value="" selected="selected" disabled><?php esc_html_e( 'Select an item…', 'invoicing' ); ?></option> |
|
726 | - <?php foreach ( get_posts( $item_args ) as $item ) : ?> |
|
727 | - <option value="<?php echo (int) $item->ID; ?>"><?php echo esc_html( $item->post_title ); ?></option> |
|
725 | + <option value="" selected="selected" disabled><?php esc_html_e('Select an item…', 'invoicing'); ?></option> |
|
726 | + <?php foreach (get_posts($item_args) as $item) : ?> |
|
727 | + <option value="<?php echo (int) $item->ID; ?>"><?php echo esc_html($item->post_title); ?></option> |
|
728 | 728 | <?php endforeach; ?> |
729 | 729 | </select> |
730 | 730 | </td> |
@@ -736,8 +736,8 @@ discard block |
||
736 | 736 | </table> |
737 | 737 | </div> |
738 | 738 | <div class="modal-footer"> |
739 | - <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button> |
|
740 | - <button type="button" class="btn btn-primary getpaid-add" data-dismiss="modal"><?php esc_html_e( 'Add', 'invoicing' ); ?></button> |
|
739 | + <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e('Cancel', 'invoicing'); ?></button> |
|
740 | + <button type="button" class="btn btn-primary getpaid-add" data-dismiss="modal"><?php esc_html_e('Add', 'invoicing'); ?></button> |
|
741 | 741 | </div> |
742 | 742 | </div> |
743 | 743 | </div> |
@@ -748,9 +748,9 @@ discard block |
||
748 | 748 | <div class="modal-dialog modal-dialog-centered" role="document"> |
749 | 749 | <div class="modal-content"> |
750 | 750 | <div class="modal-header"> |
751 | - <h5 class="modal-title" id="getpaid-create-invoice-item-label"><?php esc_html_e( 'Create Item', 'invoicing' ); ?></h5> |
|
752 | - <button type="button" class="close btn-close" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>"> |
|
753 | - <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
|
751 | + <h5 class="modal-title" id="getpaid-create-invoice-item-label"><?php esc_html_e('Create Item', 'invoicing'); ?></h5> |
|
752 | + <button type="button" class="close btn-close" data-dismiss="modal" aria-label="<?php esc_html_e('Close', 'invoicing'); ?>"> |
|
753 | + <?php if (empty($GLOBALS['aui_bs5'])) : ?> |
|
754 | 754 | <span aria-hidden="true">×</span> |
755 | 755 | <?php endif; ?> |
756 | 756 | </button> |
@@ -759,27 +759,27 @@ discard block |
||
759 | 759 | <div class="getpaid-create-item-div"> |
760 | 760 | <input type="hidden" name="id" value="new" class="form-control form-control-sm item-id"> |
761 | 761 | <label class="form-group mb-3 w-100"> |
762 | - <span><?php esc_html_e( 'Name', 'invoicing' ); ?></span> |
|
763 | - <input type="text" name="name" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="form-control form-control-sm item-name"> |
|
762 | + <span><?php esc_html_e('Name', 'invoicing'); ?></span> |
|
763 | + <input type="text" name="name" placeholder="<?php esc_attr_e('Item Name', 'invoicing'); ?>" class="form-control form-control-sm item-name"> |
|
764 | 764 | </label> |
765 | 765 | <label class="form-group mb-3 w-100"> |
766 | - <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php esc_html_e( 'Amount', 'invoicing' ); ?></span> |
|
767 | - <span class="hide-if-amount"><?php esc_html_e( 'Price', 'invoicing' ); ?></span> |
|
768 | - <input type="text" name="price" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control form-control-sm item-price"> |
|
766 | + <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php esc_html_e('Amount', 'invoicing'); ?></span> |
|
767 | + <span class="hide-if-amount"><?php esc_html_e('Price', 'invoicing'); ?></span> |
|
768 | + <input type="text" name="price" placeholder="<?php echo esc_attr(wpinv_sanitize_amount(0)); ?>" class="form-control form-control-sm item-price"> |
|
769 | 769 | </label> |
770 | 770 | <label class="form-group mb-3 w-100 hide-if-amount"> |
771 | - <span><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span> |
|
771 | + <span><?php esc_html_e('Quantity', 'invoicing'); ?></span> |
|
772 | 772 | <input type="text" name="quantity" placeholder="1" class="form-control form-control-sm item-quantity"> |
773 | 773 | </label> |
774 | 774 | <label class="form-group mb-3 w-100"> |
775 | - <span><?php esc_html_e( 'Item Description', 'invoicing' ); ?></span> |
|
776 | - <textarea name="description" placeholder="<?php esc_attr_e( 'Enter a description for this item', 'invoicing' ); ?>" class="form-control item-description"></textarea> |
|
775 | + <span><?php esc_html_e('Item Description', 'invoicing'); ?></span> |
|
776 | + <textarea name="description" placeholder="<?php esc_attr_e('Enter a description for this item', 'invoicing'); ?>" class="form-control item-description"></textarea> |
|
777 | 777 | </label> |
778 | 778 | </div> |
779 | 779 | </div> |
780 | 780 | <div class="modal-footer"> |
781 | - <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button> |
|
782 | - <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php esc_html_e( 'Create', 'invoicing' ); ?></button> |
|
781 | + <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e('Cancel', 'invoicing'); ?></button> |
|
782 | + <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php esc_html_e('Create', 'invoicing'); ?></button> |
|
783 | 783 | </div> |
784 | 784 | </div> |
785 | 785 | </div> |
@@ -790,9 +790,9 @@ discard block |
||
790 | 790 | <div class="modal-dialog modal-dialog-centered" role="document"> |
791 | 791 | <div class="modal-content"> |
792 | 792 | <div class="modal-header"> |
793 | - <h5 class="modal-title" id="getpaid-edit-invoice-item-label"><?php esc_html_e( 'Edit Item', 'invoicing' ); ?></h5> |
|
794 | - <button type="button" class="close close" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>"> |
|
795 | - <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
|
793 | + <h5 class="modal-title" id="getpaid-edit-invoice-item-label"><?php esc_html_e('Edit Item', 'invoicing'); ?></h5> |
|
794 | + <button type="button" class="close close" data-dismiss="modal" aria-label="<?php esc_html_e('Close', 'invoicing'); ?>"> |
|
795 | + <?php if (empty($GLOBALS['aui_bs5'])) : ?> |
|
796 | 796 | <span aria-hidden="true">×</span> |
797 | 797 | <?php endif; ?> |
798 | 798 | </button> |
@@ -801,27 +801,27 @@ discard block |
||
801 | 801 | <div class="getpaid-edit-item-div"> |
802 | 802 | <input type="hidden" name="id" class="form-control form-control-sm item-id"> |
803 | 803 | <label class="form-group mb-3 w-100"> |
804 | - <span><?php esc_html_e( 'Name', 'invoicing' ); ?></span> |
|
805 | - <input type="text" name="name" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="form-control form-control-sm item-name"> |
|
804 | + <span><?php esc_html_e('Name', 'invoicing'); ?></span> |
|
805 | + <input type="text" name="name" placeholder="<?php esc_attr_e('Item Name', 'invoicing'); ?>" class="form-control form-control-sm item-name"> |
|
806 | 806 | </label> |
807 | 807 | <label class="form-group mb-3 w-100"> |
808 | - <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php esc_html_e( 'Amount', 'invoicing' ); ?></span> |
|
809 | - <span class="hide-if-amount"><?php esc_html_e( 'Price', 'invoicing' ); ?></span> |
|
810 | - <input type="text" name="price" placeholder="<?php wpinv_sanitize_amount( 0 ); ?>" class="form-control form-control-sm item-price"> |
|
808 | + <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php esc_html_e('Amount', 'invoicing'); ?></span> |
|
809 | + <span class="hide-if-amount"><?php esc_html_e('Price', 'invoicing'); ?></span> |
|
810 | + <input type="text" name="price" placeholder="<?php wpinv_sanitize_amount(0); ?>" class="form-control form-control-sm item-price"> |
|
811 | 811 | </label> |
812 | 812 | <label class="form-group mb-3 w-100 hide-if-amount"> |
813 | - <span><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span> |
|
813 | + <span><?php esc_html_e('Quantity', 'invoicing'); ?></span> |
|
814 | 814 | <input type="text" name="quantity" placeholder="1" class="form-control form-control-sm item-quantity"> |
815 | 815 | </label> |
816 | 816 | <label class="form-group mb-3 w-100"> |
817 | - <span><?php esc_html_e( 'Item Description', 'invoicing' ); ?></span> |
|
818 | - <textarea name="description" placeholder="<?php esc_attr_e( 'Enter a description for this item', 'invoicing' ); ?>" class="form-control item-description"></textarea> |
|
817 | + <span><?php esc_html_e('Item Description', 'invoicing'); ?></span> |
|
818 | + <textarea name="description" placeholder="<?php esc_attr_e('Enter a description for this item', 'invoicing'); ?>" class="form-control item-description"></textarea> |
|
819 | 819 | </label> |
820 | 820 | </div> |
821 | 821 | </div> |
822 | 822 | <div class="modal-footer"> |
823 | - <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button> |
|
824 | - <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php esc_html_e( 'Save', 'invoicing' ); ?></button> |
|
823 | + <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e('Cancel', 'invoicing'); ?></button> |
|
824 | + <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php esc_html_e('Save', 'invoicing'); ?></button> |
|
825 | 825 | </div> |
826 | 826 | </div> |
827 | 827 | </div> |
@@ -0,0 +1,1 @@ |
||
1 | + |
|
0 | 2 | \ No newline at end of file |
@@ -1,2 +1,2 @@ |
||
1 | -<?php |
|
1 | + <?php |
|
2 | 2 | # Silence is golden. |
3 | 3 | \ No newline at end of file |