@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | */ |
10 | 10 | |
11 | 11 | if ( ! defined( 'ABSPATH' ) ) { |
12 | - exit; |
|
12 | + exit; |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | /** |
@@ -21,356 +21,356 @@ discard block |
||
21 | 21 | */ |
22 | 22 | abstract class GetPaid_Data { |
23 | 23 | |
24 | - /** |
|
25 | - * ID for this object. |
|
26 | - * |
|
27 | - * @since 1.0.19 |
|
28 | - * @var int |
|
29 | - */ |
|
30 | - protected $id = 0; |
|
31 | - |
|
32 | - /** |
|
33 | - * Core data for this object. Name value pairs (name + default value). |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $data = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * Core data changes for this object. |
|
42 | - * |
|
43 | - * @since 1.0.19 |
|
44 | - * @var array |
|
45 | - */ |
|
46 | - protected $changes = array(); |
|
47 | - |
|
48 | - /** |
|
49 | - * This is false until the object is read from the DB. |
|
50 | - * |
|
51 | - * @since 1.0.19 |
|
52 | - * @var bool |
|
53 | - */ |
|
54 | - protected $object_read = false; |
|
55 | - |
|
56 | - /** |
|
57 | - * This is the name of this object type. |
|
58 | - * |
|
59 | - * @since 1.0.19 |
|
60 | - * @var string |
|
61 | - */ |
|
62 | - protected $object_type = 'data'; |
|
63 | - |
|
64 | - /** |
|
65 | - * Extra data for this object. Name value pairs (name + default value). |
|
66 | - * Used as a standard way for sub classes (like item types) to add |
|
67 | - * additional information to an inherited class. |
|
68 | - * |
|
69 | - * @since 1.0.19 |
|
70 | - * @var array |
|
71 | - */ |
|
72 | - protected $extra_data = array(); |
|
73 | - |
|
74 | - /** |
|
75 | - * Set to _data on construct so we can track and reset data if needed. |
|
76 | - * |
|
77 | - * @since 1.0.19 |
|
78 | - * @var array |
|
79 | - */ |
|
80 | - protected $default_data = array(); |
|
81 | - |
|
82 | - /** |
|
83 | - * Contains a reference to the data store for this class. |
|
84 | - * |
|
85 | - * @since 1.0.19 |
|
86 | - * @var GetPaid_Data_Store |
|
87 | - */ |
|
88 | - protected $data_store; |
|
89 | - |
|
90 | - /** |
|
91 | - * Stores meta in cache for future reads. |
|
92 | - * A group must be set to to enable caching. |
|
93 | - * |
|
94 | - * @since 1.0.19 |
|
95 | - * @var string |
|
96 | - */ |
|
97 | - protected $cache_group = ''; |
|
98 | - |
|
99 | - /** |
|
100 | - * Stores the last error. |
|
101 | - * |
|
102 | - * @since 1.0.19 |
|
103 | - * @var string |
|
104 | - */ |
|
105 | - public $last_error = ''; |
|
106 | - |
|
107 | - /** |
|
108 | - * Stores additional meta data. |
|
109 | - * |
|
110 | - * @since 1.0.19 |
|
111 | - * @var array |
|
112 | - */ |
|
113 | - protected $meta_data = null; |
|
114 | - |
|
115 | - /** |
|
116 | - * Default constructor. |
|
117 | - * |
|
118 | - * @param int|object|array|string $read ID to load from the DB (optional) or already queried data. |
|
119 | - */ |
|
120 | - public function __construct( $read = 0 ) { |
|
121 | - $this->data = array_merge( $this->data, $this->extra_data ); |
|
122 | - $this->default_data = $this->data; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Only store the object ID to avoid serializing the data object instance. |
|
127 | - * |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - public function __sleep() { |
|
131 | - return array( 'id' ); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Re-run the constructor with the object ID. |
|
136 | - * |
|
137 | - * If the object no longer exists, remove the ID. |
|
138 | - */ |
|
139 | - public function __wakeup() { |
|
140 | - $this->__construct( absint( $this->id ) ); |
|
141 | - |
|
142 | - if ( ! empty( $this->last_error ) ) { |
|
143 | - $this->set_id( 0 ); |
|
144 | - } |
|
145 | - |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * When the object is cloned, make sure meta is duplicated correctly. |
|
150 | - * |
|
151 | - * @since 1.0.19 |
|
152 | - */ |
|
153 | - public function __clone() { |
|
154 | - $this->maybe_read_meta_data(); |
|
155 | - if ( ! empty( $this->meta_data ) ) { |
|
156 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
157 | - $this->meta_data[ $array_key ] = clone $meta; |
|
158 | - if ( ! empty( $meta->id ) ) { |
|
159 | - $this->meta_data[ $array_key ]->id = null; |
|
160 | - } |
|
161 | - } |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Get the data store. |
|
167 | - * |
|
168 | - * @since 1.0.19 |
|
169 | - * @return object |
|
170 | - */ |
|
171 | - public function get_data_store() { |
|
172 | - return $this->data_store; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Get the object type. |
|
177 | - * |
|
178 | - * @since 1.0.19 |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - public function get_object_type() { |
|
182 | - return $this->object_type; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Returns the unique ID for this object. |
|
187 | - * |
|
188 | - * @since 1.0.19 |
|
189 | - * @return int |
|
190 | - */ |
|
191 | - public function get_id() { |
|
192 | - return $this->id; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Get form status. |
|
197 | - * |
|
198 | - * @since 1.0.19 |
|
199 | - * @param string $context View or edit context. |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public function get_status( $context = 'view' ) { |
|
203 | - return $this->get_prop( 'status', $context ); |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Delete an object, set the ID to 0, and return result. |
|
208 | - * |
|
209 | - * @since 1.0.19 |
|
210 | - * @param bool $force_delete Should the data be deleted permanently. |
|
211 | - * @return bool result |
|
212 | - */ |
|
213 | - public function delete( $force_delete = false ) { |
|
214 | - if ( $this->data_store && $this->exists() ) { |
|
215 | - $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
216 | - $this->set_id( 0 ); |
|
217 | - return true; |
|
218 | - } |
|
219 | - return false; |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Save should create or update based on object existence. |
|
224 | - * |
|
225 | - * @since 1.0.19 |
|
226 | - * @return int |
|
227 | - */ |
|
228 | - public function save() { |
|
229 | - if ( ! $this->data_store ) { |
|
230 | - return $this->get_id(); |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Trigger action before saving to the DB. Allows you to adjust object props before save. |
|
235 | - * |
|
236 | - * @param GetPaid_Data $this The object being saved. |
|
237 | - * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
238 | - */ |
|
239 | - do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
240 | - |
|
241 | - if ( $this->get_id() ) { |
|
242 | - $this->data_store->update( $this ); |
|
243 | - } else { |
|
244 | - $this->data_store->create( $this ); |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Trigger action after saving to the DB. |
|
249 | - * |
|
250 | - * @param GetPaid_Data $this The object being saved. |
|
251 | - * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
252 | - */ |
|
253 | - do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
254 | - |
|
255 | - return $this->get_id(); |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Change data to JSON format. |
|
260 | - * |
|
261 | - * @since 1.0.19 |
|
262 | - * @return string Data in JSON format. |
|
263 | - */ |
|
264 | - public function __toString() { |
|
265 | - return wp_json_encode( $this->get_data() ); |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * Returns all data for this object. |
|
270 | - * |
|
271 | - * @since 1.0.19 |
|
272 | - * @return array |
|
273 | - */ |
|
274 | - public function get_data() { |
|
275 | - return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Returns array of expected data keys for this object. |
|
280 | - * |
|
281 | - * @since 1.0.19 |
|
282 | - * @return array |
|
283 | - */ |
|
284 | - public function get_data_keys() { |
|
285 | - return array_keys( $this->data ); |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Returns all "extra" data keys for an object (for sub objects like item types). |
|
290 | - * |
|
291 | - * @since 1.0.19 |
|
292 | - * @return array |
|
293 | - */ |
|
294 | - public function get_extra_data_keys() { |
|
295 | - return array_keys( $this->extra_data ); |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Filter null meta values from array. |
|
300 | - * |
|
301 | - * @since 1.0.19 |
|
302 | - * @param mixed $meta Meta value to check. |
|
303 | - * @return bool |
|
304 | - */ |
|
305 | - protected function filter_null_meta( $meta ) { |
|
306 | - return ! is_null( $meta->value ); |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * Get All Meta Data. |
|
311 | - * |
|
312 | - * @since 1.0.19 |
|
313 | - * @return array of objects. |
|
314 | - */ |
|
315 | - public function get_meta_data() { |
|
316 | - $this->maybe_read_meta_data(); |
|
317 | - return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * Check if the key is an internal one. |
|
322 | - * |
|
323 | - * @since 1.0.19 |
|
324 | - * @param string $key Key to check. |
|
325 | - * @return bool true if it's an internal key, false otherwise |
|
326 | - */ |
|
327 | - protected function is_internal_meta_key( $key ) { |
|
328 | - $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
329 | - |
|
330 | - if ( ! $internal_meta_key ) { |
|
331 | - return false; |
|
332 | - } |
|
333 | - |
|
334 | - $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
335 | - |
|
336 | - if ( ! $has_setter_or_getter ) { |
|
337 | - return false; |
|
338 | - } |
|
339 | - |
|
340 | - /* translators: %s: $key Key to check */ |
|
341 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
342 | - |
|
343 | - return true; |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Magic method for setting data fields. |
|
348 | - * |
|
349 | - * This method does not update custom fields in the database. |
|
350 | - * |
|
351 | - * @since 1.0.19 |
|
352 | - * @access public |
|
353 | - * |
|
354 | - */ |
|
355 | - public function __set( $key, $value ) { |
|
356 | - |
|
357 | - if ( 'id' == strtolower( $key ) ) { |
|
358 | - return $this->set_id( $value ); |
|
359 | - } |
|
360 | - |
|
361 | - if ( method_exists( $this, "set_$key") ) { |
|
362 | - |
|
363 | - /* translators: %s: $key Key to set */ |
|
364 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
365 | - |
|
366 | - call_user_func( array( $this, "set_$key" ), $value ); |
|
367 | - } else { |
|
368 | - $this->set_prop( $key, $value ); |
|
369 | - } |
|
370 | - |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
24 | + /** |
|
25 | + * ID for this object. |
|
26 | + * |
|
27 | + * @since 1.0.19 |
|
28 | + * @var int |
|
29 | + */ |
|
30 | + protected $id = 0; |
|
31 | + |
|
32 | + /** |
|
33 | + * Core data for this object. Name value pairs (name + default value). |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $data = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * Core data changes for this object. |
|
42 | + * |
|
43 | + * @since 1.0.19 |
|
44 | + * @var array |
|
45 | + */ |
|
46 | + protected $changes = array(); |
|
47 | + |
|
48 | + /** |
|
49 | + * This is false until the object is read from the DB. |
|
50 | + * |
|
51 | + * @since 1.0.19 |
|
52 | + * @var bool |
|
53 | + */ |
|
54 | + protected $object_read = false; |
|
55 | + |
|
56 | + /** |
|
57 | + * This is the name of this object type. |
|
58 | + * |
|
59 | + * @since 1.0.19 |
|
60 | + * @var string |
|
61 | + */ |
|
62 | + protected $object_type = 'data'; |
|
63 | + |
|
64 | + /** |
|
65 | + * Extra data for this object. Name value pairs (name + default value). |
|
66 | + * Used as a standard way for sub classes (like item types) to add |
|
67 | + * additional information to an inherited class. |
|
68 | + * |
|
69 | + * @since 1.0.19 |
|
70 | + * @var array |
|
71 | + */ |
|
72 | + protected $extra_data = array(); |
|
73 | + |
|
74 | + /** |
|
75 | + * Set to _data on construct so we can track and reset data if needed. |
|
76 | + * |
|
77 | + * @since 1.0.19 |
|
78 | + * @var array |
|
79 | + */ |
|
80 | + protected $default_data = array(); |
|
81 | + |
|
82 | + /** |
|
83 | + * Contains a reference to the data store for this class. |
|
84 | + * |
|
85 | + * @since 1.0.19 |
|
86 | + * @var GetPaid_Data_Store |
|
87 | + */ |
|
88 | + protected $data_store; |
|
89 | + |
|
90 | + /** |
|
91 | + * Stores meta in cache for future reads. |
|
92 | + * A group must be set to to enable caching. |
|
93 | + * |
|
94 | + * @since 1.0.19 |
|
95 | + * @var string |
|
96 | + */ |
|
97 | + protected $cache_group = ''; |
|
98 | + |
|
99 | + /** |
|
100 | + * Stores the last error. |
|
101 | + * |
|
102 | + * @since 1.0.19 |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + public $last_error = ''; |
|
106 | + |
|
107 | + /** |
|
108 | + * Stores additional meta data. |
|
109 | + * |
|
110 | + * @since 1.0.19 |
|
111 | + * @var array |
|
112 | + */ |
|
113 | + protected $meta_data = null; |
|
114 | + |
|
115 | + /** |
|
116 | + * Default constructor. |
|
117 | + * |
|
118 | + * @param int|object|array|string $read ID to load from the DB (optional) or already queried data. |
|
119 | + */ |
|
120 | + public function __construct( $read = 0 ) { |
|
121 | + $this->data = array_merge( $this->data, $this->extra_data ); |
|
122 | + $this->default_data = $this->data; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Only store the object ID to avoid serializing the data object instance. |
|
127 | + * |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + public function __sleep() { |
|
131 | + return array( 'id' ); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Re-run the constructor with the object ID. |
|
136 | + * |
|
137 | + * If the object no longer exists, remove the ID. |
|
138 | + */ |
|
139 | + public function __wakeup() { |
|
140 | + $this->__construct( absint( $this->id ) ); |
|
141 | + |
|
142 | + if ( ! empty( $this->last_error ) ) { |
|
143 | + $this->set_id( 0 ); |
|
144 | + } |
|
145 | + |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * When the object is cloned, make sure meta is duplicated correctly. |
|
150 | + * |
|
151 | + * @since 1.0.19 |
|
152 | + */ |
|
153 | + public function __clone() { |
|
154 | + $this->maybe_read_meta_data(); |
|
155 | + if ( ! empty( $this->meta_data ) ) { |
|
156 | + foreach ( $this->meta_data as $array_key => $meta ) { |
|
157 | + $this->meta_data[ $array_key ] = clone $meta; |
|
158 | + if ( ! empty( $meta->id ) ) { |
|
159 | + $this->meta_data[ $array_key ]->id = null; |
|
160 | + } |
|
161 | + } |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Get the data store. |
|
167 | + * |
|
168 | + * @since 1.0.19 |
|
169 | + * @return object |
|
170 | + */ |
|
171 | + public function get_data_store() { |
|
172 | + return $this->data_store; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Get the object type. |
|
177 | + * |
|
178 | + * @since 1.0.19 |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + public function get_object_type() { |
|
182 | + return $this->object_type; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Returns the unique ID for this object. |
|
187 | + * |
|
188 | + * @since 1.0.19 |
|
189 | + * @return int |
|
190 | + */ |
|
191 | + public function get_id() { |
|
192 | + return $this->id; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Get form status. |
|
197 | + * |
|
198 | + * @since 1.0.19 |
|
199 | + * @param string $context View or edit context. |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public function get_status( $context = 'view' ) { |
|
203 | + return $this->get_prop( 'status', $context ); |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Delete an object, set the ID to 0, and return result. |
|
208 | + * |
|
209 | + * @since 1.0.19 |
|
210 | + * @param bool $force_delete Should the data be deleted permanently. |
|
211 | + * @return bool result |
|
212 | + */ |
|
213 | + public function delete( $force_delete = false ) { |
|
214 | + if ( $this->data_store && $this->exists() ) { |
|
215 | + $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
216 | + $this->set_id( 0 ); |
|
217 | + return true; |
|
218 | + } |
|
219 | + return false; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Save should create or update based on object existence. |
|
224 | + * |
|
225 | + * @since 1.0.19 |
|
226 | + * @return int |
|
227 | + */ |
|
228 | + public function save() { |
|
229 | + if ( ! $this->data_store ) { |
|
230 | + return $this->get_id(); |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Trigger action before saving to the DB. Allows you to adjust object props before save. |
|
235 | + * |
|
236 | + * @param GetPaid_Data $this The object being saved. |
|
237 | + * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
238 | + */ |
|
239 | + do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
240 | + |
|
241 | + if ( $this->get_id() ) { |
|
242 | + $this->data_store->update( $this ); |
|
243 | + } else { |
|
244 | + $this->data_store->create( $this ); |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Trigger action after saving to the DB. |
|
249 | + * |
|
250 | + * @param GetPaid_Data $this The object being saved. |
|
251 | + * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
252 | + */ |
|
253 | + do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
254 | + |
|
255 | + return $this->get_id(); |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Change data to JSON format. |
|
260 | + * |
|
261 | + * @since 1.0.19 |
|
262 | + * @return string Data in JSON format. |
|
263 | + */ |
|
264 | + public function __toString() { |
|
265 | + return wp_json_encode( $this->get_data() ); |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * Returns all data for this object. |
|
270 | + * |
|
271 | + * @since 1.0.19 |
|
272 | + * @return array |
|
273 | + */ |
|
274 | + public function get_data() { |
|
275 | + return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Returns array of expected data keys for this object. |
|
280 | + * |
|
281 | + * @since 1.0.19 |
|
282 | + * @return array |
|
283 | + */ |
|
284 | + public function get_data_keys() { |
|
285 | + return array_keys( $this->data ); |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Returns all "extra" data keys for an object (for sub objects like item types). |
|
290 | + * |
|
291 | + * @since 1.0.19 |
|
292 | + * @return array |
|
293 | + */ |
|
294 | + public function get_extra_data_keys() { |
|
295 | + return array_keys( $this->extra_data ); |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Filter null meta values from array. |
|
300 | + * |
|
301 | + * @since 1.0.19 |
|
302 | + * @param mixed $meta Meta value to check. |
|
303 | + * @return bool |
|
304 | + */ |
|
305 | + protected function filter_null_meta( $meta ) { |
|
306 | + return ! is_null( $meta->value ); |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * Get All Meta Data. |
|
311 | + * |
|
312 | + * @since 1.0.19 |
|
313 | + * @return array of objects. |
|
314 | + */ |
|
315 | + public function get_meta_data() { |
|
316 | + $this->maybe_read_meta_data(); |
|
317 | + return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * Check if the key is an internal one. |
|
322 | + * |
|
323 | + * @since 1.0.19 |
|
324 | + * @param string $key Key to check. |
|
325 | + * @return bool true if it's an internal key, false otherwise |
|
326 | + */ |
|
327 | + protected function is_internal_meta_key( $key ) { |
|
328 | + $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
329 | + |
|
330 | + if ( ! $internal_meta_key ) { |
|
331 | + return false; |
|
332 | + } |
|
333 | + |
|
334 | + $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
335 | + |
|
336 | + if ( ! $has_setter_or_getter ) { |
|
337 | + return false; |
|
338 | + } |
|
339 | + |
|
340 | + /* translators: %s: $key Key to check */ |
|
341 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
342 | + |
|
343 | + return true; |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Magic method for setting data fields. |
|
348 | + * |
|
349 | + * This method does not update custom fields in the database. |
|
350 | + * |
|
351 | + * @since 1.0.19 |
|
352 | + * @access public |
|
353 | + * |
|
354 | + */ |
|
355 | + public function __set( $key, $value ) { |
|
356 | + |
|
357 | + if ( 'id' == strtolower( $key ) ) { |
|
358 | + return $this->set_id( $value ); |
|
359 | + } |
|
360 | + |
|
361 | + if ( method_exists( $this, "set_$key") ) { |
|
362 | + |
|
363 | + /* translators: %s: $key Key to set */ |
|
364 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
365 | + |
|
366 | + call_user_func( array( $this, "set_$key" ), $value ); |
|
367 | + } else { |
|
368 | + $this->set_prop( $key, $value ); |
|
369 | + } |
|
370 | + |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | 374 | * Margic method for retrieving a property. |
375 | 375 | */ |
376 | 376 | public function __get( $key ) { |
@@ -378,10 +378,10 @@ discard block |
||
378 | 378 | // Check if we have a helper method for that. |
379 | 379 | if ( method_exists( $this, 'get_' . $key ) ) { |
380 | 380 | |
381 | - if ( 'post_type' != $key ) { |
|
382 | - /* translators: %s: $key Key to set */ |
|
383 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
384 | - } |
|
381 | + if ( 'post_type' != $key ) { |
|
382 | + /* translators: %s: $key Key to set */ |
|
383 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
384 | + } |
|
385 | 385 | |
386 | 386 | return call_user_func( array( $this, 'get_' . $key ) ); |
387 | 387 | } |
@@ -391,512 +391,512 @@ discard block |
||
391 | 391 | return $this->post->$key; |
392 | 392 | } |
393 | 393 | |
394 | - return $this->get_prop( $key ); |
|
395 | - |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * Get Meta Data by Key. |
|
400 | - * |
|
401 | - * @since 1.0.19 |
|
402 | - * @param string $key Meta Key. |
|
403 | - * @param bool $single return first found meta with key, or all with $key. |
|
404 | - * @param string $context What the value is for. Valid values are view and edit. |
|
405 | - * @return mixed |
|
406 | - */ |
|
407 | - public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
408 | - |
|
409 | - // Check if this is an internal meta key. |
|
410 | - $_key = str_replace( '_wpinv', '', $key ); |
|
411 | - $_key = str_replace( 'wpinv', '', $_key ); |
|
412 | - if ( $this->is_internal_meta_key( $_key ) ) { |
|
413 | - $function = 'get_' . $_key; |
|
414 | - |
|
415 | - if ( is_callable( array( $this, $function ) ) ) { |
|
416 | - return $this->{$function}(); |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - // Read the meta data if not yet read. |
|
421 | - $this->maybe_read_meta_data(); |
|
422 | - $meta_data = $this->get_meta_data(); |
|
423 | - $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
424 | - $value = $single ? '' : array(); |
|
425 | - |
|
426 | - if ( ! empty( $array_keys ) ) { |
|
427 | - // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
|
428 | - if ( $single ) { |
|
429 | - $value = $meta_data[ current( $array_keys ) ]->value; |
|
430 | - } else { |
|
431 | - $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
432 | - } |
|
433 | - } |
|
434 | - |
|
435 | - if ( 'view' === $context ) { |
|
436 | - $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
437 | - } |
|
438 | - |
|
439 | - return $value; |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * See if meta data exists, since get_meta always returns a '' or array(). |
|
444 | - * |
|
445 | - * @since 1.0.19 |
|
446 | - * @param string $key Meta Key. |
|
447 | - * @return boolean |
|
448 | - */ |
|
449 | - public function meta_exists( $key = '' ) { |
|
450 | - $this->maybe_read_meta_data(); |
|
451 | - $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
452 | - return in_array( $key, $array_keys, true ); |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Set all meta data from array. |
|
457 | - * |
|
458 | - * @since 1.0.19 |
|
459 | - * @param array $data Key/Value pairs. |
|
460 | - */ |
|
461 | - public function set_meta_data( $data ) { |
|
462 | - if ( ! empty( $data ) && is_array( $data ) ) { |
|
463 | - $this->maybe_read_meta_data(); |
|
464 | - foreach ( $data as $meta ) { |
|
465 | - $meta = (array) $meta; |
|
466 | - if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
467 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
468 | - array( |
|
469 | - 'id' => $meta['id'], |
|
470 | - 'key' => $meta['key'], |
|
471 | - 'value' => $meta['value'], |
|
472 | - ) |
|
473 | - ); |
|
474 | - } |
|
475 | - } |
|
476 | - } |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * Add meta data. |
|
481 | - * |
|
482 | - * @since 1.0.19 |
|
483 | - * |
|
484 | - * @param string $key Meta key. |
|
485 | - * @param string|array $value Meta value. |
|
486 | - * @param bool $unique Should this be a unique key?. |
|
487 | - */ |
|
488 | - public function add_meta_data( $key, $value, $unique = false ) { |
|
489 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
490 | - $function = 'set_' . $key; |
|
491 | - |
|
492 | - if ( is_callable( array( $this, $function ) ) ) { |
|
493 | - return $this->{$function}( $value ); |
|
494 | - } |
|
495 | - } |
|
496 | - |
|
497 | - $this->maybe_read_meta_data(); |
|
498 | - if ( $unique ) { |
|
499 | - $this->delete_meta_data( $key ); |
|
500 | - } |
|
501 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
502 | - array( |
|
503 | - 'key' => $key, |
|
504 | - 'value' => $value, |
|
505 | - ) |
|
506 | - ); |
|
507 | - } |
|
508 | - |
|
509 | - /** |
|
510 | - * Update meta data by key or ID, if provided. |
|
511 | - * |
|
512 | - * @since 1.0.19 |
|
513 | - * |
|
514 | - * @param string $key Meta key. |
|
515 | - * @param string|array $value Meta value. |
|
516 | - * @param int $meta_id Meta ID. |
|
517 | - */ |
|
518 | - public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
519 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
520 | - $function = 'set_' . $key; |
|
521 | - |
|
522 | - if ( is_callable( array( $this, $function ) ) ) { |
|
523 | - return $this->{$function}( $value ); |
|
524 | - } |
|
525 | - } |
|
526 | - |
|
527 | - $this->maybe_read_meta_data(); |
|
528 | - |
|
529 | - $array_key = false; |
|
530 | - |
|
531 | - if ( $meta_id ) { |
|
532 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
533 | - $array_key = $array_keys ? current( $array_keys ) : false; |
|
534 | - } else { |
|
535 | - // Find matches by key. |
|
536 | - $matches = array(); |
|
537 | - foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
538 | - if ( $meta->key === $key ) { |
|
539 | - $matches[] = $meta_data_array_key; |
|
540 | - } |
|
541 | - } |
|
542 | - |
|
543 | - if ( ! empty( $matches ) ) { |
|
544 | - // Set matches to null so only one key gets the new value. |
|
545 | - foreach ( $matches as $meta_data_array_key ) { |
|
546 | - $this->meta_data[ $meta_data_array_key ]->value = null; |
|
547 | - } |
|
548 | - $array_key = current( $matches ); |
|
549 | - } |
|
550 | - } |
|
551 | - |
|
552 | - if ( false !== $array_key ) { |
|
553 | - $meta = $this->meta_data[ $array_key ]; |
|
554 | - $meta->key = $key; |
|
555 | - $meta->value = $value; |
|
556 | - } else { |
|
557 | - $this->add_meta_data( $key, $value, true ); |
|
558 | - } |
|
559 | - } |
|
560 | - |
|
561 | - /** |
|
562 | - * Delete meta data. |
|
563 | - * |
|
564 | - * @since 1.0.19 |
|
565 | - * @param string $key Meta key. |
|
566 | - */ |
|
567 | - public function delete_meta_data( $key ) { |
|
568 | - $this->maybe_read_meta_data(); |
|
569 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
570 | - |
|
571 | - if ( $array_keys ) { |
|
572 | - foreach ( $array_keys as $array_key ) { |
|
573 | - $this->meta_data[ $array_key ]->value = null; |
|
574 | - } |
|
575 | - } |
|
576 | - } |
|
577 | - |
|
578 | - /** |
|
579 | - * Delete meta data. |
|
580 | - * |
|
581 | - * @since 1.0.19 |
|
582 | - * @param int $mid Meta ID. |
|
583 | - */ |
|
584 | - public function delete_meta_data_by_mid( $mid ) { |
|
585 | - $this->maybe_read_meta_data(); |
|
586 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
587 | - |
|
588 | - if ( $array_keys ) { |
|
589 | - foreach ( $array_keys as $array_key ) { |
|
590 | - $this->meta_data[ $array_key ]->value = null; |
|
591 | - } |
|
592 | - } |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * Read meta data if null. |
|
597 | - * |
|
598 | - * @since 1.0.19 |
|
599 | - */ |
|
600 | - protected function maybe_read_meta_data() { |
|
601 | - if ( is_null( $this->meta_data ) ) { |
|
602 | - $this->read_meta_data(); |
|
603 | - } |
|
604 | - } |
|
605 | - |
|
606 | - /** |
|
607 | - * Read Meta Data from the database. Ignore any internal properties. |
|
608 | - * Uses it's own caches because get_metadata does not provide meta_ids. |
|
609 | - * |
|
610 | - * @since 1.0.19 |
|
611 | - * @param bool $force_read True to force a new DB read (and update cache). |
|
612 | - */ |
|
613 | - public function read_meta_data( $force_read = false ) { |
|
614 | - |
|
615 | - // Reset meta data. |
|
616 | - $this->meta_data = array(); |
|
617 | - |
|
618 | - // Maybe abort early. |
|
619 | - if ( ! $this->get_id() || ! $this->data_store ) { |
|
620 | - return; |
|
621 | - } |
|
622 | - |
|
623 | - // Only read from cache if the cache key is set. |
|
624 | - $cache_key = null; |
|
625 | - if ( ! $force_read && ! empty( $this->cache_group ) ) { |
|
626 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
627 | - $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group ); |
|
628 | - } |
|
629 | - |
|
630 | - // Should we force read? |
|
631 | - if ( empty( $raw_meta_data ) ) { |
|
632 | - $raw_meta_data = $this->data_store->read_meta( $this ); |
|
633 | - |
|
634 | - if ( ! empty( $cache_key ) ) { |
|
635 | - wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
636 | - } |
|
637 | - |
|
638 | - } |
|
639 | - |
|
640 | - // Set meta data. |
|
641 | - if ( is_array( $raw_meta_data ) ) { |
|
642 | - |
|
643 | - foreach ( $raw_meta_data as $meta ) { |
|
644 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
645 | - array( |
|
646 | - 'id' => (int) $meta->meta_id, |
|
647 | - 'key' => $meta->meta_key, |
|
648 | - 'value' => maybe_unserialize( $meta->meta_value ), |
|
649 | - ) |
|
650 | - ); |
|
651 | - } |
|
652 | - |
|
653 | - } |
|
654 | - |
|
655 | - } |
|
656 | - |
|
657 | - /** |
|
658 | - * Update Meta Data in the database. |
|
659 | - * |
|
660 | - * @since 1.0.19 |
|
661 | - */ |
|
662 | - public function save_meta_data() { |
|
663 | - if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
664 | - return; |
|
665 | - } |
|
666 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
667 | - if ( is_null( $meta->value ) ) { |
|
668 | - if ( ! empty( $meta->id ) ) { |
|
669 | - $this->data_store->delete_meta( $this, $meta ); |
|
670 | - unset( $this->meta_data[ $array_key ] ); |
|
671 | - } |
|
672 | - } elseif ( empty( $meta->id ) ) { |
|
673 | - $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
674 | - $meta->apply_changes(); |
|
675 | - } else { |
|
676 | - if ( $meta->get_changes() ) { |
|
677 | - $this->data_store->update_meta( $this, $meta ); |
|
678 | - $meta->apply_changes(); |
|
679 | - } |
|
680 | - } |
|
681 | - } |
|
682 | - if ( ! empty( $this->cache_group ) ) { |
|
683 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
684 | - wp_cache_delete( $cache_key, $this->cache_group ); |
|
685 | - } |
|
686 | - } |
|
687 | - |
|
688 | - /** |
|
689 | - * Set ID. |
|
690 | - * |
|
691 | - * @since 1.0.19 |
|
692 | - * @param int $id ID. |
|
693 | - */ |
|
694 | - public function set_id( $id ) { |
|
695 | - $this->id = absint( $id ); |
|
696 | - } |
|
697 | - |
|
698 | - /** |
|
699 | - * Sets item status. |
|
700 | - * |
|
701 | - * @since 1.0.19 |
|
702 | - * @param string $status New status. |
|
703 | - * @return array details of change. |
|
704 | - */ |
|
705 | - public function set_status( $status ) { |
|
394 | + return $this->get_prop( $key ); |
|
395 | + |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Get Meta Data by Key. |
|
400 | + * |
|
401 | + * @since 1.0.19 |
|
402 | + * @param string $key Meta Key. |
|
403 | + * @param bool $single return first found meta with key, or all with $key. |
|
404 | + * @param string $context What the value is for. Valid values are view and edit. |
|
405 | + * @return mixed |
|
406 | + */ |
|
407 | + public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
408 | + |
|
409 | + // Check if this is an internal meta key. |
|
410 | + $_key = str_replace( '_wpinv', '', $key ); |
|
411 | + $_key = str_replace( 'wpinv', '', $_key ); |
|
412 | + if ( $this->is_internal_meta_key( $_key ) ) { |
|
413 | + $function = 'get_' . $_key; |
|
414 | + |
|
415 | + if ( is_callable( array( $this, $function ) ) ) { |
|
416 | + return $this->{$function}(); |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + // Read the meta data if not yet read. |
|
421 | + $this->maybe_read_meta_data(); |
|
422 | + $meta_data = $this->get_meta_data(); |
|
423 | + $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
424 | + $value = $single ? '' : array(); |
|
425 | + |
|
426 | + if ( ! empty( $array_keys ) ) { |
|
427 | + // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
|
428 | + if ( $single ) { |
|
429 | + $value = $meta_data[ current( $array_keys ) ]->value; |
|
430 | + } else { |
|
431 | + $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
432 | + } |
|
433 | + } |
|
434 | + |
|
435 | + if ( 'view' === $context ) { |
|
436 | + $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
437 | + } |
|
438 | + |
|
439 | + return $value; |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * See if meta data exists, since get_meta always returns a '' or array(). |
|
444 | + * |
|
445 | + * @since 1.0.19 |
|
446 | + * @param string $key Meta Key. |
|
447 | + * @return boolean |
|
448 | + */ |
|
449 | + public function meta_exists( $key = '' ) { |
|
450 | + $this->maybe_read_meta_data(); |
|
451 | + $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
452 | + return in_array( $key, $array_keys, true ); |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Set all meta data from array. |
|
457 | + * |
|
458 | + * @since 1.0.19 |
|
459 | + * @param array $data Key/Value pairs. |
|
460 | + */ |
|
461 | + public function set_meta_data( $data ) { |
|
462 | + if ( ! empty( $data ) && is_array( $data ) ) { |
|
463 | + $this->maybe_read_meta_data(); |
|
464 | + foreach ( $data as $meta ) { |
|
465 | + $meta = (array) $meta; |
|
466 | + if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
467 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
468 | + array( |
|
469 | + 'id' => $meta['id'], |
|
470 | + 'key' => $meta['key'], |
|
471 | + 'value' => $meta['value'], |
|
472 | + ) |
|
473 | + ); |
|
474 | + } |
|
475 | + } |
|
476 | + } |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * Add meta data. |
|
481 | + * |
|
482 | + * @since 1.0.19 |
|
483 | + * |
|
484 | + * @param string $key Meta key. |
|
485 | + * @param string|array $value Meta value. |
|
486 | + * @param bool $unique Should this be a unique key?. |
|
487 | + */ |
|
488 | + public function add_meta_data( $key, $value, $unique = false ) { |
|
489 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
490 | + $function = 'set_' . $key; |
|
491 | + |
|
492 | + if ( is_callable( array( $this, $function ) ) ) { |
|
493 | + return $this->{$function}( $value ); |
|
494 | + } |
|
495 | + } |
|
496 | + |
|
497 | + $this->maybe_read_meta_data(); |
|
498 | + if ( $unique ) { |
|
499 | + $this->delete_meta_data( $key ); |
|
500 | + } |
|
501 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
502 | + array( |
|
503 | + 'key' => $key, |
|
504 | + 'value' => $value, |
|
505 | + ) |
|
506 | + ); |
|
507 | + } |
|
508 | + |
|
509 | + /** |
|
510 | + * Update meta data by key or ID, if provided. |
|
511 | + * |
|
512 | + * @since 1.0.19 |
|
513 | + * |
|
514 | + * @param string $key Meta key. |
|
515 | + * @param string|array $value Meta value. |
|
516 | + * @param int $meta_id Meta ID. |
|
517 | + */ |
|
518 | + public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
519 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
520 | + $function = 'set_' . $key; |
|
521 | + |
|
522 | + if ( is_callable( array( $this, $function ) ) ) { |
|
523 | + return $this->{$function}( $value ); |
|
524 | + } |
|
525 | + } |
|
526 | + |
|
527 | + $this->maybe_read_meta_data(); |
|
528 | + |
|
529 | + $array_key = false; |
|
530 | + |
|
531 | + if ( $meta_id ) { |
|
532 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
533 | + $array_key = $array_keys ? current( $array_keys ) : false; |
|
534 | + } else { |
|
535 | + // Find matches by key. |
|
536 | + $matches = array(); |
|
537 | + foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
538 | + if ( $meta->key === $key ) { |
|
539 | + $matches[] = $meta_data_array_key; |
|
540 | + } |
|
541 | + } |
|
542 | + |
|
543 | + if ( ! empty( $matches ) ) { |
|
544 | + // Set matches to null so only one key gets the new value. |
|
545 | + foreach ( $matches as $meta_data_array_key ) { |
|
546 | + $this->meta_data[ $meta_data_array_key ]->value = null; |
|
547 | + } |
|
548 | + $array_key = current( $matches ); |
|
549 | + } |
|
550 | + } |
|
551 | + |
|
552 | + if ( false !== $array_key ) { |
|
553 | + $meta = $this->meta_data[ $array_key ]; |
|
554 | + $meta->key = $key; |
|
555 | + $meta->value = $value; |
|
556 | + } else { |
|
557 | + $this->add_meta_data( $key, $value, true ); |
|
558 | + } |
|
559 | + } |
|
560 | + |
|
561 | + /** |
|
562 | + * Delete meta data. |
|
563 | + * |
|
564 | + * @since 1.0.19 |
|
565 | + * @param string $key Meta key. |
|
566 | + */ |
|
567 | + public function delete_meta_data( $key ) { |
|
568 | + $this->maybe_read_meta_data(); |
|
569 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
570 | + |
|
571 | + if ( $array_keys ) { |
|
572 | + foreach ( $array_keys as $array_key ) { |
|
573 | + $this->meta_data[ $array_key ]->value = null; |
|
574 | + } |
|
575 | + } |
|
576 | + } |
|
577 | + |
|
578 | + /** |
|
579 | + * Delete meta data. |
|
580 | + * |
|
581 | + * @since 1.0.19 |
|
582 | + * @param int $mid Meta ID. |
|
583 | + */ |
|
584 | + public function delete_meta_data_by_mid( $mid ) { |
|
585 | + $this->maybe_read_meta_data(); |
|
586 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
587 | + |
|
588 | + if ( $array_keys ) { |
|
589 | + foreach ( $array_keys as $array_key ) { |
|
590 | + $this->meta_data[ $array_key ]->value = null; |
|
591 | + } |
|
592 | + } |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * Read meta data if null. |
|
597 | + * |
|
598 | + * @since 1.0.19 |
|
599 | + */ |
|
600 | + protected function maybe_read_meta_data() { |
|
601 | + if ( is_null( $this->meta_data ) ) { |
|
602 | + $this->read_meta_data(); |
|
603 | + } |
|
604 | + } |
|
605 | + |
|
606 | + /** |
|
607 | + * Read Meta Data from the database. Ignore any internal properties. |
|
608 | + * Uses it's own caches because get_metadata does not provide meta_ids. |
|
609 | + * |
|
610 | + * @since 1.0.19 |
|
611 | + * @param bool $force_read True to force a new DB read (and update cache). |
|
612 | + */ |
|
613 | + public function read_meta_data( $force_read = false ) { |
|
614 | + |
|
615 | + // Reset meta data. |
|
616 | + $this->meta_data = array(); |
|
617 | + |
|
618 | + // Maybe abort early. |
|
619 | + if ( ! $this->get_id() || ! $this->data_store ) { |
|
620 | + return; |
|
621 | + } |
|
622 | + |
|
623 | + // Only read from cache if the cache key is set. |
|
624 | + $cache_key = null; |
|
625 | + if ( ! $force_read && ! empty( $this->cache_group ) ) { |
|
626 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
627 | + $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group ); |
|
628 | + } |
|
629 | + |
|
630 | + // Should we force read? |
|
631 | + if ( empty( $raw_meta_data ) ) { |
|
632 | + $raw_meta_data = $this->data_store->read_meta( $this ); |
|
633 | + |
|
634 | + if ( ! empty( $cache_key ) ) { |
|
635 | + wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
636 | + } |
|
637 | + |
|
638 | + } |
|
639 | + |
|
640 | + // Set meta data. |
|
641 | + if ( is_array( $raw_meta_data ) ) { |
|
642 | + |
|
643 | + foreach ( $raw_meta_data as $meta ) { |
|
644 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
645 | + array( |
|
646 | + 'id' => (int) $meta->meta_id, |
|
647 | + 'key' => $meta->meta_key, |
|
648 | + 'value' => maybe_unserialize( $meta->meta_value ), |
|
649 | + ) |
|
650 | + ); |
|
651 | + } |
|
652 | + |
|
653 | + } |
|
654 | + |
|
655 | + } |
|
656 | + |
|
657 | + /** |
|
658 | + * Update Meta Data in the database. |
|
659 | + * |
|
660 | + * @since 1.0.19 |
|
661 | + */ |
|
662 | + public function save_meta_data() { |
|
663 | + if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
664 | + return; |
|
665 | + } |
|
666 | + foreach ( $this->meta_data as $array_key => $meta ) { |
|
667 | + if ( is_null( $meta->value ) ) { |
|
668 | + if ( ! empty( $meta->id ) ) { |
|
669 | + $this->data_store->delete_meta( $this, $meta ); |
|
670 | + unset( $this->meta_data[ $array_key ] ); |
|
671 | + } |
|
672 | + } elseif ( empty( $meta->id ) ) { |
|
673 | + $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
674 | + $meta->apply_changes(); |
|
675 | + } else { |
|
676 | + if ( $meta->get_changes() ) { |
|
677 | + $this->data_store->update_meta( $this, $meta ); |
|
678 | + $meta->apply_changes(); |
|
679 | + } |
|
680 | + } |
|
681 | + } |
|
682 | + if ( ! empty( $this->cache_group ) ) { |
|
683 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
684 | + wp_cache_delete( $cache_key, $this->cache_group ); |
|
685 | + } |
|
686 | + } |
|
687 | + |
|
688 | + /** |
|
689 | + * Set ID. |
|
690 | + * |
|
691 | + * @since 1.0.19 |
|
692 | + * @param int $id ID. |
|
693 | + */ |
|
694 | + public function set_id( $id ) { |
|
695 | + $this->id = absint( $id ); |
|
696 | + } |
|
697 | + |
|
698 | + /** |
|
699 | + * Sets item status. |
|
700 | + * |
|
701 | + * @since 1.0.19 |
|
702 | + * @param string $status New status. |
|
703 | + * @return array details of change. |
|
704 | + */ |
|
705 | + public function set_status( $status ) { |
|
706 | 706 | $old_status = $this->get_status(); |
707 | 707 | |
708 | - $this->set_prop( 'status', $status ); |
|
709 | - |
|
710 | - return array( |
|
711 | - 'from' => $old_status, |
|
712 | - 'to' => $status, |
|
713 | - ); |
|
714 | - } |
|
715 | - |
|
716 | - /** |
|
717 | - * Set all props to default values. |
|
718 | - * |
|
719 | - * @since 1.0.19 |
|
720 | - */ |
|
721 | - public function set_defaults() { |
|
722 | - $this->data = $this->default_data; |
|
723 | - $this->changes = array(); |
|
724 | - $this->set_object_read( false ); |
|
725 | - } |
|
726 | - |
|
727 | - /** |
|
728 | - * Set object read property. |
|
729 | - * |
|
730 | - * @since 1.0.19 |
|
731 | - * @param boolean $read Should read?. |
|
732 | - */ |
|
733 | - public function set_object_read( $read = true ) { |
|
734 | - $this->object_read = (bool) $read; |
|
735 | - } |
|
736 | - |
|
737 | - /** |
|
738 | - * Get object read property. |
|
739 | - * |
|
740 | - * @since 1.0.19 |
|
741 | - * @return boolean |
|
742 | - */ |
|
743 | - public function get_object_read() { |
|
744 | - return (bool) $this->object_read; |
|
745 | - } |
|
746 | - |
|
747 | - /** |
|
748 | - * Set a collection of props in one go, collect any errors, and return the result. |
|
749 | - * Only sets using public methods. |
|
750 | - * |
|
751 | - * @since 1.0.19 |
|
752 | - * |
|
753 | - * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
754 | - * @param string $context In what context to run this. |
|
755 | - * |
|
756 | - * @return bool|WP_Error |
|
757 | - */ |
|
758 | - public function set_props( $props, $context = 'set' ) { |
|
759 | - $errors = false; |
|
760 | - |
|
761 | - foreach ( $props as $prop => $value ) { |
|
762 | - try { |
|
763 | - /** |
|
764 | - * Checks if the prop being set is allowed, and the value is not null. |
|
765 | - */ |
|
766 | - if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
767 | - continue; |
|
768 | - } |
|
769 | - $setter = "set_$prop"; |
|
770 | - |
|
771 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
772 | - $this->{$setter}( $value ); |
|
773 | - } |
|
774 | - } catch ( Exception $e ) { |
|
775 | - if ( ! $errors ) { |
|
776 | - $errors = new WP_Error(); |
|
777 | - } |
|
778 | - $errors->add( $e->getCode(), $e->getMessage() ); |
|
779 | - $this->last_error = $e->getMessage(); |
|
780 | - } |
|
781 | - } |
|
782 | - |
|
783 | - return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
784 | - } |
|
785 | - |
|
786 | - /** |
|
787 | - * Sets a prop for a setter method. |
|
788 | - * |
|
789 | - * This stores changes in a special array so we can track what needs saving |
|
790 | - * the the DB later. |
|
791 | - * |
|
792 | - * @since 1.0.19 |
|
793 | - * @param string $prop Name of prop to set. |
|
794 | - * @param mixed $value Value of the prop. |
|
795 | - */ |
|
796 | - protected function set_prop( $prop, $value ) { |
|
797 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
798 | - if ( true === $this->object_read ) { |
|
799 | - if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
800 | - $this->changes[ $prop ] = $value; |
|
801 | - } |
|
802 | - } else { |
|
803 | - $this->data[ $prop ] = $value; |
|
804 | - } |
|
805 | - } |
|
806 | - } |
|
807 | - |
|
808 | - /** |
|
809 | - * Return data changes only. |
|
810 | - * |
|
811 | - * @since 1.0.19 |
|
812 | - * @return array |
|
813 | - */ |
|
814 | - public function get_changes() { |
|
815 | - return $this->changes; |
|
816 | - } |
|
817 | - |
|
818 | - /** |
|
819 | - * Merge changes with data and clear. |
|
820 | - * |
|
821 | - * @since 1.0.19 |
|
822 | - */ |
|
823 | - public function apply_changes() { |
|
824 | - $this->data = array_replace_recursive( $this->data, $this->changes ); |
|
825 | - $this->changes = array(); |
|
826 | - } |
|
827 | - |
|
828 | - /** |
|
829 | - * Prefix for action and filter hooks on data. |
|
830 | - * |
|
831 | - * @since 1.0.19 |
|
832 | - * @return string |
|
833 | - */ |
|
834 | - protected function get_hook_prefix() { |
|
835 | - return 'wpinv_get_' . $this->object_type . '_'; |
|
836 | - } |
|
837 | - |
|
838 | - /** |
|
839 | - * Gets a prop for a getter method. |
|
840 | - * |
|
841 | - * Gets the value from either current pending changes, or the data itself. |
|
842 | - * Context controls what happens to the value before it's returned. |
|
843 | - * |
|
844 | - * @since 1.0.19 |
|
845 | - * @param string $prop Name of prop to get. |
|
846 | - * @param string $context What the value is for. Valid values are view and edit. |
|
847 | - * @return mixed |
|
848 | - */ |
|
849 | - protected function get_prop( $prop, $context = 'view' ) { |
|
850 | - $value = null; |
|
851 | - |
|
852 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
853 | - $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
854 | - |
|
855 | - if ( 'view' === $context ) { |
|
856 | - $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
857 | - } |
|
858 | - } |
|
859 | - |
|
860 | - return $value; |
|
861 | - } |
|
862 | - |
|
863 | - /** |
|
864 | - * Sets a date prop whilst handling formatting and datetime objects. |
|
865 | - * |
|
866 | - * @since 1.0.19 |
|
867 | - * @param string $prop Name of prop to set. |
|
868 | - * @param string|integer $value Value of the prop. |
|
869 | - */ |
|
870 | - protected function set_date_prop( $prop, $value ) { |
|
871 | - |
|
872 | - if ( empty( $value ) ) { |
|
873 | - $this->set_prop( $prop, null ); |
|
874 | - return; |
|
875 | - } |
|
876 | - $this->set_prop( $prop, $value ); |
|
877 | - |
|
878 | - } |
|
879 | - |
|
880 | - /** |
|
881 | - * When invalid data is found, throw an exception unless reading from the DB. |
|
882 | - * |
|
883 | - * @since 1.0.19 |
|
884 | - * @param string $code Error code. |
|
885 | - * @param string $message Error message. |
|
886 | - */ |
|
887 | - protected function error( $code, $message ) { |
|
888 | - $this->last_error = $message; |
|
889 | - } |
|
890 | - |
|
891 | - /** |
|
892 | - * Checks if the object is saved in the database |
|
893 | - * |
|
894 | - * @since 1.0.19 |
|
895 | - * @return bool |
|
896 | - */ |
|
897 | - public function exists() { |
|
898 | - $id = $this->get_id(); |
|
899 | - return ! empty( $id ); |
|
900 | - } |
|
708 | + $this->set_prop( 'status', $status ); |
|
709 | + |
|
710 | + return array( |
|
711 | + 'from' => $old_status, |
|
712 | + 'to' => $status, |
|
713 | + ); |
|
714 | + } |
|
715 | + |
|
716 | + /** |
|
717 | + * Set all props to default values. |
|
718 | + * |
|
719 | + * @since 1.0.19 |
|
720 | + */ |
|
721 | + public function set_defaults() { |
|
722 | + $this->data = $this->default_data; |
|
723 | + $this->changes = array(); |
|
724 | + $this->set_object_read( false ); |
|
725 | + } |
|
726 | + |
|
727 | + /** |
|
728 | + * Set object read property. |
|
729 | + * |
|
730 | + * @since 1.0.19 |
|
731 | + * @param boolean $read Should read?. |
|
732 | + */ |
|
733 | + public function set_object_read( $read = true ) { |
|
734 | + $this->object_read = (bool) $read; |
|
735 | + } |
|
736 | + |
|
737 | + /** |
|
738 | + * Get object read property. |
|
739 | + * |
|
740 | + * @since 1.0.19 |
|
741 | + * @return boolean |
|
742 | + */ |
|
743 | + public function get_object_read() { |
|
744 | + return (bool) $this->object_read; |
|
745 | + } |
|
746 | + |
|
747 | + /** |
|
748 | + * Set a collection of props in one go, collect any errors, and return the result. |
|
749 | + * Only sets using public methods. |
|
750 | + * |
|
751 | + * @since 1.0.19 |
|
752 | + * |
|
753 | + * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
754 | + * @param string $context In what context to run this. |
|
755 | + * |
|
756 | + * @return bool|WP_Error |
|
757 | + */ |
|
758 | + public function set_props( $props, $context = 'set' ) { |
|
759 | + $errors = false; |
|
760 | + |
|
761 | + foreach ( $props as $prop => $value ) { |
|
762 | + try { |
|
763 | + /** |
|
764 | + * Checks if the prop being set is allowed, and the value is not null. |
|
765 | + */ |
|
766 | + if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
767 | + continue; |
|
768 | + } |
|
769 | + $setter = "set_$prop"; |
|
770 | + |
|
771 | + if ( is_callable( array( $this, $setter ) ) ) { |
|
772 | + $this->{$setter}( $value ); |
|
773 | + } |
|
774 | + } catch ( Exception $e ) { |
|
775 | + if ( ! $errors ) { |
|
776 | + $errors = new WP_Error(); |
|
777 | + } |
|
778 | + $errors->add( $e->getCode(), $e->getMessage() ); |
|
779 | + $this->last_error = $e->getMessage(); |
|
780 | + } |
|
781 | + } |
|
782 | + |
|
783 | + return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
784 | + } |
|
785 | + |
|
786 | + /** |
|
787 | + * Sets a prop for a setter method. |
|
788 | + * |
|
789 | + * This stores changes in a special array so we can track what needs saving |
|
790 | + * the the DB later. |
|
791 | + * |
|
792 | + * @since 1.0.19 |
|
793 | + * @param string $prop Name of prop to set. |
|
794 | + * @param mixed $value Value of the prop. |
|
795 | + */ |
|
796 | + protected function set_prop( $prop, $value ) { |
|
797 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
798 | + if ( true === $this->object_read ) { |
|
799 | + if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
800 | + $this->changes[ $prop ] = $value; |
|
801 | + } |
|
802 | + } else { |
|
803 | + $this->data[ $prop ] = $value; |
|
804 | + } |
|
805 | + } |
|
806 | + } |
|
807 | + |
|
808 | + /** |
|
809 | + * Return data changes only. |
|
810 | + * |
|
811 | + * @since 1.0.19 |
|
812 | + * @return array |
|
813 | + */ |
|
814 | + public function get_changes() { |
|
815 | + return $this->changes; |
|
816 | + } |
|
817 | + |
|
818 | + /** |
|
819 | + * Merge changes with data and clear. |
|
820 | + * |
|
821 | + * @since 1.0.19 |
|
822 | + */ |
|
823 | + public function apply_changes() { |
|
824 | + $this->data = array_replace_recursive( $this->data, $this->changes ); |
|
825 | + $this->changes = array(); |
|
826 | + } |
|
827 | + |
|
828 | + /** |
|
829 | + * Prefix for action and filter hooks on data. |
|
830 | + * |
|
831 | + * @since 1.0.19 |
|
832 | + * @return string |
|
833 | + */ |
|
834 | + protected function get_hook_prefix() { |
|
835 | + return 'wpinv_get_' . $this->object_type . '_'; |
|
836 | + } |
|
837 | + |
|
838 | + /** |
|
839 | + * Gets a prop for a getter method. |
|
840 | + * |
|
841 | + * Gets the value from either current pending changes, or the data itself. |
|
842 | + * Context controls what happens to the value before it's returned. |
|
843 | + * |
|
844 | + * @since 1.0.19 |
|
845 | + * @param string $prop Name of prop to get. |
|
846 | + * @param string $context What the value is for. Valid values are view and edit. |
|
847 | + * @return mixed |
|
848 | + */ |
|
849 | + protected function get_prop( $prop, $context = 'view' ) { |
|
850 | + $value = null; |
|
851 | + |
|
852 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
853 | + $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
854 | + |
|
855 | + if ( 'view' === $context ) { |
|
856 | + $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
857 | + } |
|
858 | + } |
|
859 | + |
|
860 | + return $value; |
|
861 | + } |
|
862 | + |
|
863 | + /** |
|
864 | + * Sets a date prop whilst handling formatting and datetime objects. |
|
865 | + * |
|
866 | + * @since 1.0.19 |
|
867 | + * @param string $prop Name of prop to set. |
|
868 | + * @param string|integer $value Value of the prop. |
|
869 | + */ |
|
870 | + protected function set_date_prop( $prop, $value ) { |
|
871 | + |
|
872 | + if ( empty( $value ) ) { |
|
873 | + $this->set_prop( $prop, null ); |
|
874 | + return; |
|
875 | + } |
|
876 | + $this->set_prop( $prop, $value ); |
|
877 | + |
|
878 | + } |
|
879 | + |
|
880 | + /** |
|
881 | + * When invalid data is found, throw an exception unless reading from the DB. |
|
882 | + * |
|
883 | + * @since 1.0.19 |
|
884 | + * @param string $code Error code. |
|
885 | + * @param string $message Error message. |
|
886 | + */ |
|
887 | + protected function error( $code, $message ) { |
|
888 | + $this->last_error = $message; |
|
889 | + } |
|
890 | + |
|
891 | + /** |
|
892 | + * Checks if the object is saved in the database |
|
893 | + * |
|
894 | + * @since 1.0.19 |
|
895 | + * @return bool |
|
896 | + */ |
|
897 | + public function exists() { |
|
898 | + $id = $this->get_id(); |
|
899 | + return ! empty( $id ); |
|
900 | + } |
|
901 | 901 | |
902 | 902 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * |
9 | 9 | */ |
10 | 10 | |
11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
11 | +if (!defined('ABSPATH')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @param int|object|array|string $read ID to load from the DB (optional) or already queried data. |
119 | 119 | */ |
120 | - public function __construct( $read = 0 ) { |
|
121 | - $this->data = array_merge( $this->data, $this->extra_data ); |
|
120 | + public function __construct($read = 0) { |
|
121 | + $this->data = array_merge($this->data, $this->extra_data); |
|
122 | 122 | $this->default_data = $this->data; |
123 | 123 | } |
124 | 124 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @return array |
129 | 129 | */ |
130 | 130 | public function __sleep() { |
131 | - return array( 'id' ); |
|
131 | + return array('id'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | * If the object no longer exists, remove the ID. |
138 | 138 | */ |
139 | 139 | public function __wakeup() { |
140 | - $this->__construct( absint( $this->id ) ); |
|
140 | + $this->__construct(absint($this->id)); |
|
141 | 141 | |
142 | - if ( ! empty( $this->last_error ) ) { |
|
143 | - $this->set_id( 0 ); |
|
142 | + if (!empty($this->last_error)) { |
|
143 | + $this->set_id(0); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | } |
@@ -152,11 +152,11 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function __clone() { |
154 | 154 | $this->maybe_read_meta_data(); |
155 | - if ( ! empty( $this->meta_data ) ) { |
|
156 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
157 | - $this->meta_data[ $array_key ] = clone $meta; |
|
158 | - if ( ! empty( $meta->id ) ) { |
|
159 | - $this->meta_data[ $array_key ]->id = null; |
|
155 | + if (!empty($this->meta_data)) { |
|
156 | + foreach ($this->meta_data as $array_key => $meta) { |
|
157 | + $this->meta_data[$array_key] = clone $meta; |
|
158 | + if (!empty($meta->id)) { |
|
159 | + $this->meta_data[$array_key]->id = null; |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | } |
@@ -199,8 +199,8 @@ discard block |
||
199 | 199 | * @param string $context View or edit context. |
200 | 200 | * @return string |
201 | 201 | */ |
202 | - public function get_status( $context = 'view' ) { |
|
203 | - return $this->get_prop( 'status', $context ); |
|
202 | + public function get_status($context = 'view') { |
|
203 | + return $this->get_prop('status', $context); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -210,10 +210,10 @@ discard block |
||
210 | 210 | * @param bool $force_delete Should the data be deleted permanently. |
211 | 211 | * @return bool result |
212 | 212 | */ |
213 | - public function delete( $force_delete = false ) { |
|
214 | - if ( $this->data_store && $this->exists() ) { |
|
215 | - $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
216 | - $this->set_id( 0 ); |
|
213 | + public function delete($force_delete = false) { |
|
214 | + if ($this->data_store && $this->exists()) { |
|
215 | + $this->data_store->delete($this, array('force_delete' => $force_delete)); |
|
216 | + $this->set_id(0); |
|
217 | 217 | return true; |
218 | 218 | } |
219 | 219 | return false; |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @return int |
227 | 227 | */ |
228 | 228 | public function save() { |
229 | - if ( ! $this->data_store ) { |
|
229 | + if (!$this->data_store) { |
|
230 | 230 | return $this->get_id(); |
231 | 231 | } |
232 | 232 | |
@@ -236,12 +236,12 @@ discard block |
||
236 | 236 | * @param GetPaid_Data $this The object being saved. |
237 | 237 | * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
238 | 238 | */ |
239 | - do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
239 | + do_action('getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store); |
|
240 | 240 | |
241 | - if ( $this->get_id() ) { |
|
242 | - $this->data_store->update( $this ); |
|
241 | + if ($this->get_id()) { |
|
242 | + $this->data_store->update($this); |
|
243 | 243 | } else { |
244 | - $this->data_store->create( $this ); |
|
244 | + $this->data_store->create($this); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * @param GetPaid_Data $this The object being saved. |
251 | 251 | * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
252 | 252 | */ |
253 | - do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
253 | + do_action('getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store); |
|
254 | 254 | |
255 | 255 | return $this->get_id(); |
256 | 256 | } |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @return string Data in JSON format. |
263 | 263 | */ |
264 | 264 | public function __toString() { |
265 | - return wp_json_encode( $this->get_data() ); |
|
265 | + return wp_json_encode($this->get_data()); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | * @return array |
273 | 273 | */ |
274 | 274 | public function get_data() { |
275 | - return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
275 | + return array_merge(array('id' => $this->get_id()), $this->data, array('meta_data' => $this->get_meta_data())); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @return array |
283 | 283 | */ |
284 | 284 | public function get_data_keys() { |
285 | - return array_keys( $this->data ); |
|
285 | + return array_keys($this->data); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | * @return array |
293 | 293 | */ |
294 | 294 | public function get_extra_data_keys() { |
295 | - return array_keys( $this->extra_data ); |
|
295 | + return array_keys($this->extra_data); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
@@ -302,8 +302,8 @@ discard block |
||
302 | 302 | * @param mixed $meta Meta value to check. |
303 | 303 | * @return bool |
304 | 304 | */ |
305 | - protected function filter_null_meta( $meta ) { |
|
306 | - return ! is_null( $meta->value ); |
|
305 | + protected function filter_null_meta($meta) { |
|
306 | + return !is_null($meta->value); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | */ |
315 | 315 | public function get_meta_data() { |
316 | 316 | $this->maybe_read_meta_data(); |
317 | - return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
317 | + return array_values(array_filter($this->meta_data, array($this, 'filter_null_meta'))); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | /** |
@@ -324,21 +324,21 @@ discard block |
||
324 | 324 | * @param string $key Key to check. |
325 | 325 | * @return bool true if it's an internal key, false otherwise |
326 | 326 | */ |
327 | - protected function is_internal_meta_key( $key ) { |
|
328 | - $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
327 | + protected function is_internal_meta_key($key) { |
|
328 | + $internal_meta_key = !empty($key) && $this->data_store && in_array($key, $this->data_store->get_internal_meta_keys(), true); |
|
329 | 329 | |
330 | - if ( ! $internal_meta_key ) { |
|
330 | + if (!$internal_meta_key) { |
|
331 | 331 | return false; |
332 | 332 | } |
333 | 333 | |
334 | - $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
334 | + $has_setter_or_getter = is_callable(array($this, 'set_' . $key)) || is_callable(array($this, 'get_' . $key)); |
|
335 | 335 | |
336 | - if ( ! $has_setter_or_getter ) { |
|
336 | + if (!$has_setter_or_getter) { |
|
337 | 337 | return false; |
338 | 338 | } |
339 | 339 | |
340 | 340 | /* translators: %s: $key Key to check */ |
341 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
341 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'invoicing'), $key), '1.0.19'); |
|
342 | 342 | |
343 | 343 | return true; |
344 | 344 | } |
@@ -352,20 +352,20 @@ discard block |
||
352 | 352 | * @access public |
353 | 353 | * |
354 | 354 | */ |
355 | - public function __set( $key, $value ) { |
|
355 | + public function __set($key, $value) { |
|
356 | 356 | |
357 | - if ( 'id' == strtolower( $key ) ) { |
|
358 | - return $this->set_id( $value ); |
|
357 | + if ('id' == strtolower($key)) { |
|
358 | + return $this->set_id($value); |
|
359 | 359 | } |
360 | 360 | |
361 | - if ( method_exists( $this, "set_$key") ) { |
|
361 | + if (method_exists($this, "set_$key")) { |
|
362 | 362 | |
363 | 363 | /* translators: %s: $key Key to set */ |
364 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
364 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing'), $key), '1.0.19'); |
|
365 | 365 | |
366 | - call_user_func( array( $this, "set_$key" ), $value ); |
|
366 | + call_user_func(array($this, "set_$key"), $value); |
|
367 | 367 | } else { |
368 | - $this->set_prop( $key, $value ); |
|
368 | + $this->set_prop($key, $value); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | } |
@@ -373,25 +373,25 @@ discard block |
||
373 | 373 | /** |
374 | 374 | * Margic method for retrieving a property. |
375 | 375 | */ |
376 | - public function __get( $key ) { |
|
376 | + public function __get($key) { |
|
377 | 377 | |
378 | 378 | // Check if we have a helper method for that. |
379 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
379 | + if (method_exists($this, 'get_' . $key)) { |
|
380 | 380 | |
381 | - if ( 'post_type' != $key ) { |
|
381 | + if ('post_type' != $key) { |
|
382 | 382 | /* translators: %s: $key Key to set */ |
383 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
383 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing'), $key), '1.0.19'); |
|
384 | 384 | } |
385 | 385 | |
386 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
386 | + return call_user_func(array($this, 'get_' . $key)); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | // Check if the key is in the associated $post object. |
390 | - if ( ! empty( $this->post ) && isset( $this->post->$key ) ) { |
|
390 | + if (!empty($this->post) && isset($this->post->$key)) { |
|
391 | 391 | return $this->post->$key; |
392 | 392 | } |
393 | 393 | |
394 | - return $this->get_prop( $key ); |
|
394 | + return $this->get_prop($key); |
|
395 | 395 | |
396 | 396 | } |
397 | 397 | |
@@ -404,15 +404,15 @@ discard block |
||
404 | 404 | * @param string $context What the value is for. Valid values are view and edit. |
405 | 405 | * @return mixed |
406 | 406 | */ |
407 | - public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
407 | + public function get_meta($key = '', $single = true, $context = 'view') { |
|
408 | 408 | |
409 | 409 | // Check if this is an internal meta key. |
410 | - $_key = str_replace( '_wpinv', '', $key ); |
|
411 | - $_key = str_replace( 'wpinv', '', $_key ); |
|
412 | - if ( $this->is_internal_meta_key( $_key ) ) { |
|
410 | + $_key = str_replace('_wpinv', '', $key); |
|
411 | + $_key = str_replace('wpinv', '', $_key); |
|
412 | + if ($this->is_internal_meta_key($_key)) { |
|
413 | 413 | $function = 'get_' . $_key; |
414 | 414 | |
415 | - if ( is_callable( array( $this, $function ) ) ) { |
|
415 | + if (is_callable(array($this, $function))) { |
|
416 | 416 | return $this->{$function}(); |
417 | 417 | } |
418 | 418 | } |
@@ -420,20 +420,20 @@ discard block |
||
420 | 420 | // Read the meta data if not yet read. |
421 | 421 | $this->maybe_read_meta_data(); |
422 | 422 | $meta_data = $this->get_meta_data(); |
423 | - $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
423 | + $array_keys = array_keys(wp_list_pluck($meta_data, 'key'), $key, true); |
|
424 | 424 | $value = $single ? '' : array(); |
425 | 425 | |
426 | - if ( ! empty( $array_keys ) ) { |
|
426 | + if (!empty($array_keys)) { |
|
427 | 427 | // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
428 | - if ( $single ) { |
|
429 | - $value = $meta_data[ current( $array_keys ) ]->value; |
|
428 | + if ($single) { |
|
429 | + $value = $meta_data[current($array_keys)]->value; |
|
430 | 430 | } else { |
431 | - $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
431 | + $value = array_intersect_key($meta_data, array_flip($array_keys)); |
|
432 | 432 | } |
433 | 433 | } |
434 | 434 | |
435 | - if ( 'view' === $context ) { |
|
436 | - $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
435 | + if ('view' === $context) { |
|
436 | + $value = apply_filters($this->get_hook_prefix() . $key, $value, $this); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | return $value; |
@@ -446,10 +446,10 @@ discard block |
||
446 | 446 | * @param string $key Meta Key. |
447 | 447 | * @return boolean |
448 | 448 | */ |
449 | - public function meta_exists( $key = '' ) { |
|
449 | + public function meta_exists($key = '') { |
|
450 | 450 | $this->maybe_read_meta_data(); |
451 | - $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
452 | - return in_array( $key, $array_keys, true ); |
|
451 | + $array_keys = wp_list_pluck($this->get_meta_data(), 'key'); |
|
452 | + return in_array($key, $array_keys, true); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | /** |
@@ -458,12 +458,12 @@ discard block |
||
458 | 458 | * @since 1.0.19 |
459 | 459 | * @param array $data Key/Value pairs. |
460 | 460 | */ |
461 | - public function set_meta_data( $data ) { |
|
462 | - if ( ! empty( $data ) && is_array( $data ) ) { |
|
461 | + public function set_meta_data($data) { |
|
462 | + if (!empty($data) && is_array($data)) { |
|
463 | 463 | $this->maybe_read_meta_data(); |
464 | - foreach ( $data as $meta ) { |
|
464 | + foreach ($data as $meta) { |
|
465 | 465 | $meta = (array) $meta; |
466 | - if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
466 | + if (isset($meta['key'], $meta['value'], $meta['id'])) { |
|
467 | 467 | $this->meta_data[] = new GetPaid_Meta_Data( |
468 | 468 | array( |
469 | 469 | 'id' => $meta['id'], |
@@ -485,18 +485,18 @@ discard block |
||
485 | 485 | * @param string|array $value Meta value. |
486 | 486 | * @param bool $unique Should this be a unique key?. |
487 | 487 | */ |
488 | - public function add_meta_data( $key, $value, $unique = false ) { |
|
489 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
488 | + public function add_meta_data($key, $value, $unique = false) { |
|
489 | + if ($this->is_internal_meta_key($key)) { |
|
490 | 490 | $function = 'set_' . $key; |
491 | 491 | |
492 | - if ( is_callable( array( $this, $function ) ) ) { |
|
493 | - return $this->{$function}( $value ); |
|
492 | + if (is_callable(array($this, $function))) { |
|
493 | + return $this->{$function}($value); |
|
494 | 494 | } |
495 | 495 | } |
496 | 496 | |
497 | 497 | $this->maybe_read_meta_data(); |
498 | - if ( $unique ) { |
|
499 | - $this->delete_meta_data( $key ); |
|
498 | + if ($unique) { |
|
499 | + $this->delete_meta_data($key); |
|
500 | 500 | } |
501 | 501 | $this->meta_data[] = new GetPaid_Meta_Data( |
502 | 502 | array( |
@@ -515,12 +515,12 @@ discard block |
||
515 | 515 | * @param string|array $value Meta value. |
516 | 516 | * @param int $meta_id Meta ID. |
517 | 517 | */ |
518 | - public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
519 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
518 | + public function update_meta_data($key, $value, $meta_id = 0) { |
|
519 | + if ($this->is_internal_meta_key($key)) { |
|
520 | 520 | $function = 'set_' . $key; |
521 | 521 | |
522 | - if ( is_callable( array( $this, $function ) ) ) { |
|
523 | - return $this->{$function}( $value ); |
|
522 | + if (is_callable(array($this, $function))) { |
|
523 | + return $this->{$function}($value); |
|
524 | 524 | } |
525 | 525 | } |
526 | 526 | |
@@ -528,33 +528,33 @@ discard block |
||
528 | 528 | |
529 | 529 | $array_key = false; |
530 | 530 | |
531 | - if ( $meta_id ) { |
|
532 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
533 | - $array_key = $array_keys ? current( $array_keys ) : false; |
|
531 | + if ($meta_id) { |
|
532 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), $meta_id, true); |
|
533 | + $array_key = $array_keys ? current($array_keys) : false; |
|
534 | 534 | } else { |
535 | 535 | // Find matches by key. |
536 | 536 | $matches = array(); |
537 | - foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
538 | - if ( $meta->key === $key ) { |
|
537 | + foreach ($this->meta_data as $meta_data_array_key => $meta) { |
|
538 | + if ($meta->key === $key) { |
|
539 | 539 | $matches[] = $meta_data_array_key; |
540 | 540 | } |
541 | 541 | } |
542 | 542 | |
543 | - if ( ! empty( $matches ) ) { |
|
543 | + if (!empty($matches)) { |
|
544 | 544 | // Set matches to null so only one key gets the new value. |
545 | - foreach ( $matches as $meta_data_array_key ) { |
|
546 | - $this->meta_data[ $meta_data_array_key ]->value = null; |
|
545 | + foreach ($matches as $meta_data_array_key) { |
|
546 | + $this->meta_data[$meta_data_array_key]->value = null; |
|
547 | 547 | } |
548 | - $array_key = current( $matches ); |
|
548 | + $array_key = current($matches); |
|
549 | 549 | } |
550 | 550 | } |
551 | 551 | |
552 | - if ( false !== $array_key ) { |
|
553 | - $meta = $this->meta_data[ $array_key ]; |
|
552 | + if (false !== $array_key) { |
|
553 | + $meta = $this->meta_data[$array_key]; |
|
554 | 554 | $meta->key = $key; |
555 | 555 | $meta->value = $value; |
556 | 556 | } else { |
557 | - $this->add_meta_data( $key, $value, true ); |
|
557 | + $this->add_meta_data($key, $value, true); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | |
@@ -564,13 +564,13 @@ discard block |
||
564 | 564 | * @since 1.0.19 |
565 | 565 | * @param string $key Meta key. |
566 | 566 | */ |
567 | - public function delete_meta_data( $key ) { |
|
567 | + public function delete_meta_data($key) { |
|
568 | 568 | $this->maybe_read_meta_data(); |
569 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
569 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'key'), $key, true); |
|
570 | 570 | |
571 | - if ( $array_keys ) { |
|
572 | - foreach ( $array_keys as $array_key ) { |
|
573 | - $this->meta_data[ $array_key ]->value = null; |
|
571 | + if ($array_keys) { |
|
572 | + foreach ($array_keys as $array_key) { |
|
573 | + $this->meta_data[$array_key]->value = null; |
|
574 | 574 | } |
575 | 575 | } |
576 | 576 | } |
@@ -581,13 +581,13 @@ discard block |
||
581 | 581 | * @since 1.0.19 |
582 | 582 | * @param int $mid Meta ID. |
583 | 583 | */ |
584 | - public function delete_meta_data_by_mid( $mid ) { |
|
584 | + public function delete_meta_data_by_mid($mid) { |
|
585 | 585 | $this->maybe_read_meta_data(); |
586 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
586 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), (int) $mid, true); |
|
587 | 587 | |
588 | - if ( $array_keys ) { |
|
589 | - foreach ( $array_keys as $array_key ) { |
|
590 | - $this->meta_data[ $array_key ]->value = null; |
|
588 | + if ($array_keys) { |
|
589 | + foreach ($array_keys as $array_key) { |
|
590 | + $this->meta_data[$array_key]->value = null; |
|
591 | 591 | } |
592 | 592 | } |
593 | 593 | } |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | * @since 1.0.19 |
599 | 599 | */ |
600 | 600 | protected function maybe_read_meta_data() { |
601 | - if ( is_null( $this->meta_data ) ) { |
|
601 | + if (is_null($this->meta_data)) { |
|
602 | 602 | $this->read_meta_data(); |
603 | 603 | } |
604 | 604 | } |
@@ -610,42 +610,42 @@ discard block |
||
610 | 610 | * @since 1.0.19 |
611 | 611 | * @param bool $force_read True to force a new DB read (and update cache). |
612 | 612 | */ |
613 | - public function read_meta_data( $force_read = false ) { |
|
613 | + public function read_meta_data($force_read = false) { |
|
614 | 614 | |
615 | 615 | // Reset meta data. |
616 | 616 | $this->meta_data = array(); |
617 | 617 | |
618 | 618 | // Maybe abort early. |
619 | - if ( ! $this->get_id() || ! $this->data_store ) { |
|
619 | + if (!$this->get_id() || !$this->data_store) { |
|
620 | 620 | return; |
621 | 621 | } |
622 | 622 | |
623 | 623 | // Only read from cache if the cache key is set. |
624 | 624 | $cache_key = null; |
625 | - if ( ! $force_read && ! empty( $this->cache_group ) ) { |
|
626 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
627 | - $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group ); |
|
625 | + if (!$force_read && !empty($this->cache_group)) { |
|
626 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id(); |
|
627 | + $raw_meta_data = wp_cache_get($cache_key, $this->cache_group); |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | // Should we force read? |
631 | - if ( empty( $raw_meta_data ) ) { |
|
632 | - $raw_meta_data = $this->data_store->read_meta( $this ); |
|
631 | + if (empty($raw_meta_data)) { |
|
632 | + $raw_meta_data = $this->data_store->read_meta($this); |
|
633 | 633 | |
634 | - if ( ! empty( $cache_key ) ) { |
|
635 | - wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
634 | + if (!empty($cache_key)) { |
|
635 | + wp_cache_set($cache_key, $raw_meta_data, $this->cache_group); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | } |
639 | 639 | |
640 | 640 | // Set meta data. |
641 | - if ( is_array( $raw_meta_data ) ) { |
|
641 | + if (is_array($raw_meta_data)) { |
|
642 | 642 | |
643 | - foreach ( $raw_meta_data as $meta ) { |
|
643 | + foreach ($raw_meta_data as $meta) { |
|
644 | 644 | $this->meta_data[] = new GetPaid_Meta_Data( |
645 | 645 | array( |
646 | 646 | 'id' => (int) $meta->meta_id, |
647 | 647 | 'key' => $meta->meta_key, |
648 | - 'value' => maybe_unserialize( $meta->meta_value ), |
|
648 | + 'value' => maybe_unserialize($meta->meta_value), |
|
649 | 649 | ) |
650 | 650 | ); |
651 | 651 | } |
@@ -660,28 +660,28 @@ discard block |
||
660 | 660 | * @since 1.0.19 |
661 | 661 | */ |
662 | 662 | public function save_meta_data() { |
663 | - if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
663 | + if (!$this->data_store || is_null($this->meta_data)) { |
|
664 | 664 | return; |
665 | 665 | } |
666 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
667 | - if ( is_null( $meta->value ) ) { |
|
668 | - if ( ! empty( $meta->id ) ) { |
|
669 | - $this->data_store->delete_meta( $this, $meta ); |
|
670 | - unset( $this->meta_data[ $array_key ] ); |
|
666 | + foreach ($this->meta_data as $array_key => $meta) { |
|
667 | + if (is_null($meta->value)) { |
|
668 | + if (!empty($meta->id)) { |
|
669 | + $this->data_store->delete_meta($this, $meta); |
|
670 | + unset($this->meta_data[$array_key]); |
|
671 | 671 | } |
672 | - } elseif ( empty( $meta->id ) ) { |
|
673 | - $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
672 | + } elseif (empty($meta->id)) { |
|
673 | + $meta->id = $this->data_store->add_meta($this, $meta); |
|
674 | 674 | $meta->apply_changes(); |
675 | 675 | } else { |
676 | - if ( $meta->get_changes() ) { |
|
677 | - $this->data_store->update_meta( $this, $meta ); |
|
676 | + if ($meta->get_changes()) { |
|
677 | + $this->data_store->update_meta($this, $meta); |
|
678 | 678 | $meta->apply_changes(); |
679 | 679 | } |
680 | 680 | } |
681 | 681 | } |
682 | - if ( ! empty( $this->cache_group ) ) { |
|
683 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
684 | - wp_cache_delete( $cache_key, $this->cache_group ); |
|
682 | + if (!empty($this->cache_group)) { |
|
683 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id(); |
|
684 | + wp_cache_delete($cache_key, $this->cache_group); |
|
685 | 685 | } |
686 | 686 | } |
687 | 687 | |
@@ -691,8 +691,8 @@ discard block |
||
691 | 691 | * @since 1.0.19 |
692 | 692 | * @param int $id ID. |
693 | 693 | */ |
694 | - public function set_id( $id ) { |
|
695 | - $this->id = absint( $id ); |
|
694 | + public function set_id($id) { |
|
695 | + $this->id = absint($id); |
|
696 | 696 | } |
697 | 697 | |
698 | 698 | /** |
@@ -702,10 +702,10 @@ discard block |
||
702 | 702 | * @param string $status New status. |
703 | 703 | * @return array details of change. |
704 | 704 | */ |
705 | - public function set_status( $status ) { |
|
705 | + public function set_status($status) { |
|
706 | 706 | $old_status = $this->get_status(); |
707 | 707 | |
708 | - $this->set_prop( 'status', $status ); |
|
708 | + $this->set_prop('status', $status); |
|
709 | 709 | |
710 | 710 | return array( |
711 | 711 | 'from' => $old_status, |
@@ -721,7 +721,7 @@ discard block |
||
721 | 721 | public function set_defaults() { |
722 | 722 | $this->data = $this->default_data; |
723 | 723 | $this->changes = array(); |
724 | - $this->set_object_read( false ); |
|
724 | + $this->set_object_read(false); |
|
725 | 725 | } |
726 | 726 | |
727 | 727 | /** |
@@ -730,7 +730,7 @@ discard block |
||
730 | 730 | * @since 1.0.19 |
731 | 731 | * @param boolean $read Should read?. |
732 | 732 | */ |
733 | - public function set_object_read( $read = true ) { |
|
733 | + public function set_object_read($read = true) { |
|
734 | 734 | $this->object_read = (bool) $read; |
735 | 735 | } |
736 | 736 | |
@@ -755,32 +755,32 @@ discard block |
||
755 | 755 | * |
756 | 756 | * @return bool|WP_Error |
757 | 757 | */ |
758 | - public function set_props( $props, $context = 'set' ) { |
|
758 | + public function set_props($props, $context = 'set') { |
|
759 | 759 | $errors = false; |
760 | 760 | |
761 | - foreach ( $props as $prop => $value ) { |
|
761 | + foreach ($props as $prop => $value) { |
|
762 | 762 | try { |
763 | 763 | /** |
764 | 764 | * Checks if the prop being set is allowed, and the value is not null. |
765 | 765 | */ |
766 | - if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
766 | + if (is_null($value) || in_array($prop, array('prop', 'date_prop', 'meta_data'), true)) { |
|
767 | 767 | continue; |
768 | 768 | } |
769 | 769 | $setter = "set_$prop"; |
770 | 770 | |
771 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
772 | - $this->{$setter}( $value ); |
|
771 | + if (is_callable(array($this, $setter))) { |
|
772 | + $this->{$setter}($value); |
|
773 | 773 | } |
774 | - } catch ( Exception $e ) { |
|
775 | - if ( ! $errors ) { |
|
774 | + } catch (Exception $e) { |
|
775 | + if (!$errors) { |
|
776 | 776 | $errors = new WP_Error(); |
777 | 777 | } |
778 | - $errors->add( $e->getCode(), $e->getMessage() ); |
|
778 | + $errors->add($e->getCode(), $e->getMessage()); |
|
779 | 779 | $this->last_error = $e->getMessage(); |
780 | 780 | } |
781 | 781 | } |
782 | 782 | |
783 | - return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
783 | + return $errors && count($errors->get_error_codes()) ? $errors : true; |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | /** |
@@ -793,14 +793,14 @@ discard block |
||
793 | 793 | * @param string $prop Name of prop to set. |
794 | 794 | * @param mixed $value Value of the prop. |
795 | 795 | */ |
796 | - protected function set_prop( $prop, $value ) { |
|
797 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
798 | - if ( true === $this->object_read ) { |
|
799 | - if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
800 | - $this->changes[ $prop ] = $value; |
|
796 | + protected function set_prop($prop, $value) { |
|
797 | + if (array_key_exists($prop, $this->data)) { |
|
798 | + if (true === $this->object_read) { |
|
799 | + if ($value !== $this->data[$prop] || array_key_exists($prop, $this->changes)) { |
|
800 | + $this->changes[$prop] = $value; |
|
801 | 801 | } |
802 | 802 | } else { |
803 | - $this->data[ $prop ] = $value; |
|
803 | + $this->data[$prop] = $value; |
|
804 | 804 | } |
805 | 805 | } |
806 | 806 | } |
@@ -821,7 +821,7 @@ discard block |
||
821 | 821 | * @since 1.0.19 |
822 | 822 | */ |
823 | 823 | public function apply_changes() { |
824 | - $this->data = array_replace_recursive( $this->data, $this->changes ); |
|
824 | + $this->data = array_replace_recursive($this->data, $this->changes); |
|
825 | 825 | $this->changes = array(); |
826 | 826 | } |
827 | 827 | |
@@ -846,14 +846,14 @@ discard block |
||
846 | 846 | * @param string $context What the value is for. Valid values are view and edit. |
847 | 847 | * @return mixed |
848 | 848 | */ |
849 | - protected function get_prop( $prop, $context = 'view' ) { |
|
849 | + protected function get_prop($prop, $context = 'view') { |
|
850 | 850 | $value = null; |
851 | 851 | |
852 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
853 | - $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
852 | + if (array_key_exists($prop, $this->data)) { |
|
853 | + $value = array_key_exists($prop, $this->changes) ? $this->changes[$prop] : $this->data[$prop]; |
|
854 | 854 | |
855 | - if ( 'view' === $context ) { |
|
856 | - $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
855 | + if ('view' === $context) { |
|
856 | + $value = apply_filters($this->get_hook_prefix() . $prop, $value, $this); |
|
857 | 857 | } |
858 | 858 | } |
859 | 859 | |
@@ -867,13 +867,13 @@ discard block |
||
867 | 867 | * @param string $prop Name of prop to set. |
868 | 868 | * @param string|integer $value Value of the prop. |
869 | 869 | */ |
870 | - protected function set_date_prop( $prop, $value ) { |
|
870 | + protected function set_date_prop($prop, $value) { |
|
871 | 871 | |
872 | - if ( empty( $value ) ) { |
|
873 | - $this->set_prop( $prop, null ); |
|
872 | + if (empty($value)) { |
|
873 | + $this->set_prop($prop, null); |
|
874 | 874 | return; |
875 | 875 | } |
876 | - $this->set_prop( $prop, $value ); |
|
876 | + $this->set_prop($prop, $value); |
|
877 | 877 | |
878 | 878 | } |
879 | 879 | |
@@ -884,7 +884,7 @@ discard block |
||
884 | 884 | * @param string $code Error code. |
885 | 885 | * @param string $message Error message. |
886 | 886 | */ |
887 | - protected function error( $code, $message ) { |
|
887 | + protected function error($code, $message) { |
|
888 | 888 | $this->last_error = $message; |
889 | 889 | } |
890 | 890 | |
@@ -896,7 +896,7 @@ discard block |
||
896 | 896 | */ |
897 | 897 | public function exists() { |
898 | 898 | $id = $this->get_id(); |
899 | - return ! empty( $id ); |
|
899 | + return !empty($id); |
|
900 | 900 | } |
901 | 901 | |
902 | 902 | } |
@@ -12,49 +12,49 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - * |
|
18 | - */ |
|
19 | - public function __construct() { |
|
20 | - add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
21 | - add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
22 | - add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
23 | - add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
24 | - add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) ); |
|
25 | - |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Registers the reports page. |
|
30 | - * |
|
31 | - */ |
|
32 | - public function register_reports_page() { |
|
33 | - |
|
34 | - add_submenu_page( |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + * |
|
18 | + */ |
|
19 | + public function __construct() { |
|
20 | + add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
21 | + add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
22 | + add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
23 | + add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
24 | + add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) ); |
|
25 | + |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Registers the reports page. |
|
30 | + * |
|
31 | + */ |
|
32 | + public function register_reports_page() { |
|
33 | + |
|
34 | + add_submenu_page( |
|
35 | 35 | 'wpinv', |
36 | 36 | __( 'Reports', 'invoicing' ), |
37 | 37 | __( 'Reports', 'invoicing' ), |
38 | 38 | wpinv_get_capability(), |
39 | 39 | 'wpinv-reports', |
40 | 40 | array( $this, 'display_reports_page' ) |
41 | - ); |
|
41 | + ); |
|
42 | 42 | |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Displays the reports page. |
|
47 | - * |
|
48 | - */ |
|
49 | - public function display_reports_page() { |
|
45 | + /** |
|
46 | + * Displays the reports page. |
|
47 | + * |
|
48 | + */ |
|
49 | + public function display_reports_page() { |
|
50 | 50 | |
51 | - // Prepare variables. |
|
52 | - $tabs = $this->get_tabs(); |
|
53 | - $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
54 | - $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
51 | + // Prepare variables. |
|
52 | + $tabs = $this->get_tabs(); |
|
53 | + $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
54 | + $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
55 | 55 | |
56 | - // Display the current tab. |
|
57 | - ?> |
|
56 | + // Display the current tab. |
|
57 | + ?> |
|
58 | 58 | |
59 | 59 | <div class="wrap"> |
60 | 60 | |
@@ -63,19 +63,19 @@ discard block |
||
63 | 63 | <nav class="nav-tab-wrapper"> |
64 | 64 | |
65 | 65 | <?php |
66 | - foreach( $tabs as $key => $label ) { |
|
66 | + foreach( $tabs as $key => $label ) { |
|
67 | 67 | |
68 | - $key = sanitize_text_field( $key ); |
|
69 | - $label = sanitize_text_field( $label ); |
|
70 | - $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
|
71 | - $url = esc_url( |
|
72 | - add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
|
73 | - ); |
|
68 | + $key = sanitize_text_field( $key ); |
|
69 | + $label = sanitize_text_field( $label ); |
|
70 | + $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
|
71 | + $url = esc_url( |
|
72 | + add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
|
73 | + ); |
|
74 | 74 | |
75 | - echo "\n\t\t\t<a href='$url' class='$class'>$label</a>"; |
|
75 | + echo "\n\t\t\t<a href='$url' class='$class'>$label</a>"; |
|
76 | 76 | |
77 | - } |
|
78 | - ?> |
|
77 | + } |
|
78 | + ?> |
|
79 | 79 | |
80 | 80 | </nav> |
81 | 81 | |
@@ -86,77 +86,77 @@ discard block |
||
86 | 86 | </div> |
87 | 87 | <?php |
88 | 88 | |
89 | - // Wordfence loads an unsupported version of chart js on our page. |
|
90 | - wp_deregister_style( 'chart-js' ); |
|
91 | - wp_deregister_script( 'chart-js' ); |
|
92 | - wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true ); |
|
93 | - wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' ); |
|
94 | - |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Retrieves reports page tabs. |
|
99 | - * |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - public function get_tabs() { |
|
103 | - |
|
104 | - $tabs = array( |
|
105 | - 'reports' => __( 'Reports', 'invoicing' ), |
|
106 | - 'export' => __( 'Export', 'invoicing' ), |
|
107 | - ); |
|
108 | - |
|
109 | - return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Displays the reports tab. |
|
114 | - * |
|
115 | - */ |
|
116 | - public function display_reports_tab() { |
|
117 | - |
|
118 | - $reports = new GetPaid_Reports_Report(); |
|
119 | - $reports->display(); |
|
120 | - |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Displays the exports tab. |
|
125 | - * |
|
126 | - */ |
|
127 | - public function display_exports_tab() { |
|
128 | - |
|
129 | - $exports = new GetPaid_Reports_Export(); |
|
130 | - $exports->display(); |
|
131 | - |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Donwnloads a graph. |
|
136 | - * |
|
137 | - * @param array $args |
|
138 | - */ |
|
139 | - public function download_graph( $args ) { |
|
140 | - |
|
141 | - if ( ! empty( $args['graph'] ) ) { |
|
142 | - $downloader = new GetPaid_Graph_Downloader(); |
|
143 | - $downloader->download( $args['graph'] ); |
|
144 | - } |
|
145 | - |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Exports invoices. |
|
150 | - * |
|
151 | - * @param array $args |
|
152 | - */ |
|
153 | - public function export_invoices( $args ) { |
|
154 | - |
|
155 | - if ( ! empty( $args['post_type'] ) ) { |
|
156 | - $downloader = new GetPaid_Invoice_Exporter(); |
|
157 | - $downloader->export( $args['post_type'], $args ); |
|
158 | - } |
|
159 | - |
|
160 | - } |
|
89 | + // Wordfence loads an unsupported version of chart js on our page. |
|
90 | + wp_deregister_style( 'chart-js' ); |
|
91 | + wp_deregister_script( 'chart-js' ); |
|
92 | + wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true ); |
|
93 | + wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' ); |
|
94 | + |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Retrieves reports page tabs. |
|
99 | + * |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + public function get_tabs() { |
|
103 | + |
|
104 | + $tabs = array( |
|
105 | + 'reports' => __( 'Reports', 'invoicing' ), |
|
106 | + 'export' => __( 'Export', 'invoicing' ), |
|
107 | + ); |
|
108 | + |
|
109 | + return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Displays the reports tab. |
|
114 | + * |
|
115 | + */ |
|
116 | + public function display_reports_tab() { |
|
117 | + |
|
118 | + $reports = new GetPaid_Reports_Report(); |
|
119 | + $reports->display(); |
|
120 | + |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Displays the exports tab. |
|
125 | + * |
|
126 | + */ |
|
127 | + public function display_exports_tab() { |
|
128 | + |
|
129 | + $exports = new GetPaid_Reports_Export(); |
|
130 | + $exports->display(); |
|
131 | + |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Donwnloads a graph. |
|
136 | + * |
|
137 | + * @param array $args |
|
138 | + */ |
|
139 | + public function download_graph( $args ) { |
|
140 | + |
|
141 | + if ( ! empty( $args['graph'] ) ) { |
|
142 | + $downloader = new GetPaid_Graph_Downloader(); |
|
143 | + $downloader->download( $args['graph'] ); |
|
144 | + } |
|
145 | + |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Exports invoices. |
|
150 | + * |
|
151 | + * @param array $args |
|
152 | + */ |
|
153 | + public function export_invoices( $args ) { |
|
154 | + |
|
155 | + if ( ! empty( $args['post_type'] ) ) { |
|
156 | + $downloader = new GetPaid_Invoice_Exporter(); |
|
157 | + $downloader->export( $args['post_type'], $args ); |
|
158 | + } |
|
159 | + |
|
160 | + } |
|
161 | 161 | |
162 | 162 | } |
@@ -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 Class. |
@@ -17,11 +17,11 @@ discard block |
||
17 | 17 | * |
18 | 18 | */ |
19 | 19 | public function __construct() { |
20 | - add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
21 | - add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
22 | - add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
23 | - add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
24 | - add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) ); |
|
20 | + add_action('admin_menu', array($this, 'register_reports_page'), 20); |
|
21 | + add_action('wpinv_reports_tab_reports', array($this, 'display_reports_tab')); |
|
22 | + add_action('wpinv_reports_tab_export', array($this, 'display_exports_tab')); |
|
23 | + add_action('getpaid_authenticated_admin_action_download_graph', array($this, 'download_graph')); |
|
24 | + add_action('getpaid_authenticated_admin_action_export_invoices', array($this, 'export_invoices')); |
|
25 | 25 | |
26 | 26 | } |
27 | 27 | |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | |
34 | 34 | add_submenu_page( |
35 | 35 | 'wpinv', |
36 | - __( 'Reports', 'invoicing' ), |
|
37 | - __( 'Reports', 'invoicing' ), |
|
36 | + __('Reports', 'invoicing'), |
|
37 | + __('Reports', 'invoicing'), |
|
38 | 38 | wpinv_get_capability(), |
39 | 39 | 'wpinv-reports', |
40 | - array( $this, 'display_reports_page' ) |
|
40 | + array($this, 'display_reports_page') |
|
41 | 41 | ); |
42 | 42 | |
43 | 43 | } |
@@ -50,26 +50,26 @@ discard block |
||
50 | 50 | |
51 | 51 | // Prepare variables. |
52 | 52 | $tabs = $this->get_tabs(); |
53 | - $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
54 | - $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
53 | + $current_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'reports'; |
|
54 | + $current_tab = array_key_exists($current_tab, $tabs) ? $current_tab : 'reports'; |
|
55 | 55 | |
56 | 56 | // Display the current tab. |
57 | 57 | ?> |
58 | 58 | |
59 | 59 | <div class="wrap"> |
60 | 60 | |
61 | - <h1><?php echo sanitize_text_field( $tabs[ $current_tab ] ); ?></h1> |
|
61 | + <h1><?php echo sanitize_text_field($tabs[$current_tab]); ?></h1> |
|
62 | 62 | |
63 | 63 | <nav class="nav-tab-wrapper"> |
64 | 64 | |
65 | 65 | <?php |
66 | - foreach( $tabs as $key => $label ) { |
|
66 | + foreach ($tabs as $key => $label) { |
|
67 | 67 | |
68 | - $key = sanitize_text_field( $key ); |
|
69 | - $label = sanitize_text_field( $label ); |
|
68 | + $key = sanitize_text_field($key); |
|
69 | + $label = sanitize_text_field($label); |
|
70 | 70 | $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
71 | 71 | $url = esc_url( |
72 | - add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
|
72 | + add_query_arg('tab', $key, admin_url('admin.php?page=wpinv-reports')) |
|
73 | 73 | ); |
74 | 74 | |
75 | 75 | echo "\n\t\t\t<a href='$url' class='$class'>$label</a>"; |
@@ -79,18 +79,18 @@ discard block |
||
79 | 79 | |
80 | 80 | </nav> |
81 | 81 | |
82 | - <div class="bsui <?php echo esc_attr( $current_tab ); ?>"> |
|
83 | - <?php do_action( "wpinv_reports_tab_{$current_tab}" ); ?> |
|
82 | + <div class="bsui <?php echo esc_attr($current_tab); ?>"> |
|
83 | + <?php do_action("wpinv_reports_tab_{$current_tab}"); ?> |
|
84 | 84 | </div> |
85 | 85 | |
86 | 86 | </div> |
87 | 87 | <?php |
88 | 88 | |
89 | 89 | // Wordfence loads an unsupported version of chart js on our page. |
90 | - wp_deregister_style( 'chart-js' ); |
|
91 | - wp_deregister_script( 'chart-js' ); |
|
92 | - wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true ); |
|
93 | - wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' ); |
|
90 | + wp_deregister_style('chart-js'); |
|
91 | + wp_deregister_script('chart-js'); |
|
92 | + wp_enqueue_script('chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array('jquery'), '2.9.4', true); |
|
93 | + wp_enqueue_style('chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4'); |
|
94 | 94 | |
95 | 95 | } |
96 | 96 | |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | public function get_tabs() { |
103 | 103 | |
104 | 104 | $tabs = array( |
105 | - 'reports' => __( 'Reports', 'invoicing' ), |
|
106 | - 'export' => __( 'Export', 'invoicing' ), |
|
105 | + 'reports' => __('Reports', 'invoicing'), |
|
106 | + 'export' => __('Export', 'invoicing'), |
|
107 | 107 | ); |
108 | 108 | |
109 | - return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
109 | + return apply_filters('getpaid_report_tabs', $tabs); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -136,11 +136,11 @@ discard block |
||
136 | 136 | * |
137 | 137 | * @param array $args |
138 | 138 | */ |
139 | - public function download_graph( $args ) { |
|
139 | + public function download_graph($args) { |
|
140 | 140 | |
141 | - if ( ! empty( $args['graph'] ) ) { |
|
141 | + if (!empty($args['graph'])) { |
|
142 | 142 | $downloader = new GetPaid_Graph_Downloader(); |
143 | - $downloader->download( $args['graph'] ); |
|
143 | + $downloader->download($args['graph']); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | } |
@@ -150,11 +150,11 @@ discard block |
||
150 | 150 | * |
151 | 151 | * @param array $args |
152 | 152 | */ |
153 | - public function export_invoices( $args ) { |
|
153 | + public function export_invoices($args) { |
|
154 | 154 | |
155 | - if ( ! empty( $args['post_type'] ) ) { |
|
155 | + if (!empty($args['post_type'])) { |
|
156 | 156 | $downloader = new GetPaid_Invoice_Exporter(); |
157 | - $downloader->export( $args['post_type'], $args ); |
|
157 | + $downloader->export($args['post_type'], $args); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 2.0.2 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * The main installer/updater class. |
@@ -25,10 +25,10 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @param string $upgrade_from The current invoicing version. |
27 | 27 | */ |
28 | - public function upgrade_db( $upgrade_from ) { |
|
28 | + public function upgrade_db($upgrade_from) { |
|
29 | 29 | |
30 | 30 | // Save the current invoicing version. |
31 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
31 | + update_option('wpinv_version', WPINV_VERSION); |
|
32 | 32 | |
33 | 33 | // Setup the invoice Custom Post Type. |
34 | 34 | GetPaid_Post_Types::register_post_types(); |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | // Create any missing database tables. |
46 | 46 | $method = "upgrade_from_$upgrade_from"; |
47 | 47 | |
48 | - if ( method_exists( $this, $method ) ) { |
|
48 | + if (method_exists($this, $method)) { |
|
49 | 49 | $this->$method(); |
50 | 50 | } |
51 | 51 | |
@@ -69,28 +69,28 @@ discard block |
||
69 | 69 | global $wpdb; |
70 | 70 | |
71 | 71 | // Invoices. |
72 | - $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
73 | - if ( ! empty( $results ) ) { |
|
74 | - $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
72 | + $results = $wpdb->get_results("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
73 | + if (!empty($results)) { |
|
74 | + $wpdb->query("UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
75 | 75 | |
76 | 76 | // Clean post cache |
77 | - foreach ( $results as $row ) { |
|
78 | - clean_post_cache( $row->ID ); |
|
77 | + foreach ($results as $row) { |
|
78 | + clean_post_cache($row->ID); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | } |
82 | 82 | |
83 | 83 | // Item meta key changes |
84 | 84 | $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
85 | - $results = $wpdb->get_results( $query ); |
|
85 | + $results = $wpdb->get_results($query); |
|
86 | 86 | |
87 | - if ( ! empty( $results ) ) { |
|
88 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
89 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
90 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
87 | + if (!empty($results)) { |
|
88 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )"); |
|
89 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'"); |
|
90 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'"); |
|
91 | 91 | |
92 | - foreach ( $results as $row ) { |
|
93 | - clean_post_cache( $row->post_id ); |
|
92 | + foreach ($results as $row) { |
|
93 | + clean_post_cache($row->post_id); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * |
123 | 123 | */ |
124 | 124 | public function add_capabilities() { |
125 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
125 | + $GLOBALS['wp_roles']->add_cap('administrator', 'manage_invoicing'); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | |
138 | 138 | // Checkout page. |
139 | 139 | 'checkout_page' => array( |
140 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
141 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
140 | + 'name' => _x('gp-checkout', 'Page slug', 'invoicing'), |
|
141 | + 'title' => _x('Checkout', 'Page title', 'invoicing'), |
|
142 | 142 | 'content' => ' |
143 | 143 | <!-- wp:shortcode --> |
144 | 144 | [wpinv_checkout] |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | |
150 | 150 | // Invoice history page. |
151 | 151 | 'invoice_history_page' => array( |
152 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
153 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
152 | + 'name' => _x('gp-invoices', 'Page slug', 'invoicing'), |
|
153 | + 'title' => _x('My Invoices', 'Page title', 'invoicing'), |
|
154 | 154 | 'content' => ' |
155 | 155 | <!-- wp:shortcode --> |
156 | 156 | [wpinv_history] |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | |
162 | 162 | // Success page content. |
163 | 163 | 'success_page' => array( |
164 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
165 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
164 | + 'name' => _x('gp-receipt', 'Page slug', 'invoicing'), |
|
165 | + 'title' => _x('Payment Confirmation', 'Page title', 'invoicing'), |
|
166 | 166 | 'content' => ' |
167 | 167 | <!-- wp:shortcode --> |
168 | 168 | [wpinv_receipt] |
@@ -173,16 +173,16 @@ discard block |
||
173 | 173 | |
174 | 174 | // Failure page content. |
175 | 175 | 'failure_page' => array( |
176 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
177 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
178 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
176 | + 'name' => _x('gp-transaction-failed', 'Page slug', 'invoicing'), |
|
177 | + 'title' => _x('Transaction Failed', 'Page title', 'invoicing'), |
|
178 | + 'content' => __('Your transaction failed, please try again or contact site support.', 'invoicing'), |
|
179 | 179 | 'parent' => 'gp-checkout', |
180 | 180 | ), |
181 | 181 | |
182 | 182 | // Subscriptions history page. |
183 | 183 | 'invoice_subscription_page' => array( |
184 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
185 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
184 | + 'name' => _x('gp-subscriptions', 'Page slug', 'invoicing'), |
|
185 | + 'title' => _x('My Subscriptions', 'Page title', 'invoicing'), |
|
186 | 186 | 'content' => ' |
187 | 187 | <!-- wp:shortcode --> |
188 | 188 | [wpinv_subscriptions] |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | ) |
195 | 195 | ); |
196 | 196 | |
197 | - foreach ( $pages as $key => $page ) { |
|
198 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
197 | + foreach ($pages as $key => $page) { |
|
198 | + wpinv_create_page(esc_sql($page['name']), $key, $page['title'], $page['content'], $page['parent']); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | } |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | |
209 | 209 | global $wpdb; |
210 | 210 | |
211 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
211 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
212 | 212 | |
213 | 213 | // Create tables. |
214 | 214 | $charset_collate = $wpdb->get_charset_collate(); |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | KEY customer_and_status (customer_id, status) |
236 | 236 | ) $charset_collate;"; |
237 | 237 | |
238 | - dbDelta( $sql ); |
|
238 | + dbDelta($sql); |
|
239 | 239 | |
240 | 240 | } |
241 | 241 | |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | public function create_invoices_table() { |
247 | 247 | global $wpdb; |
248 | 248 | |
249 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
249 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
250 | 250 | |
251 | 251 | // Create tables. |
252 | 252 | $charset_collate = $wpdb->get_charset_collate(); |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | KEY `key` (`key`) |
287 | 287 | ) $charset_collate;"; |
288 | 288 | |
289 | - dbDelta( $sql ); |
|
289 | + dbDelta($sql); |
|
290 | 290 | |
291 | 291 | } |
292 | 292 | |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | public function create_invoice_items_table() { |
298 | 298 | global $wpdb; |
299 | 299 | |
300 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
300 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
301 | 301 | |
302 | 302 | // Create tables. |
303 | 303 | $charset_collate = $wpdb->get_charset_collate(); |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | KEY post_id (post_id) |
324 | 324 | ) $charset_collate;"; |
325 | 325 | |
326 | - dbDelta( $sql ); |
|
326 | + dbDelta($sql); |
|
327 | 327 | |
328 | 328 | } |
329 | 329 | |
@@ -337,38 +337,38 @@ discard block |
||
337 | 337 | $invoices = array_unique( |
338 | 338 | get_posts( |
339 | 339 | array( |
340 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
340 | + 'post_type' => array('wpi_invoice', 'wpi_quote'), |
|
341 | 341 | 'posts_per_page' => -1, |
342 | 342 | 'fields' => 'ids', |
343 | - 'post_status' => array_keys( get_post_stati() ), |
|
343 | + 'post_status' => array_keys(get_post_stati()), |
|
344 | 344 | ) |
345 | 345 | ) |
346 | 346 | ); |
347 | 347 | |
348 | 348 | // Abort if we do not have any invoices. |
349 | - if ( empty( $invoices ) ) { |
|
349 | + if (empty($invoices)) { |
|
350 | 350 | return; |
351 | 351 | } |
352 | 352 | |
353 | 353 | $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
354 | 354 | $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
355 | 355 | |
356 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
356 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'); |
|
357 | 357 | |
358 | 358 | $invoice_rows = array(); |
359 | - foreach ( $invoices as $invoice ) { |
|
359 | + foreach ($invoices as $invoice) { |
|
360 | 360 | |
361 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
361 | + $invoice = new WPInv_Legacy_Invoice($invoice); |
|
362 | 362 | |
363 | - if ( empty( $invoice->ID ) ) { |
|
363 | + if (empty($invoice->ID)) { |
|
364 | 364 | return; |
365 | 365 | } |
366 | 366 | |
367 | - $fields = array ( |
|
367 | + $fields = array( |
|
368 | 368 | 'post_id' => $invoice->ID, |
369 | 369 | 'number' => $invoice->get_number(), |
370 | 370 | 'key' => $invoice->get_key(), |
371 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
371 | + 'type' => str_replace('wpi_', '', $invoice->post_type), |
|
372 | 372 | 'mode' => $invoice->mode, |
373 | 373 | 'user_ip' => $invoice->get_ip(), |
374 | 374 | 'first_name' => $invoice->get_first_name(), |
@@ -397,27 +397,27 @@ discard block |
||
397 | 397 | 'custom_meta' => $invoice->payment_meta |
398 | 398 | ); |
399 | 399 | |
400 | - foreach ( $fields as $key => $val ) { |
|
401 | - if ( is_null( $val ) ) { |
|
400 | + foreach ($fields as $key => $val) { |
|
401 | + if (is_null($val)) { |
|
402 | 402 | $val = ''; |
403 | 403 | } |
404 | - $val = maybe_serialize( $val ); |
|
405 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
404 | + $val = maybe_serialize($val); |
|
405 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
406 | 406 | } |
407 | 407 | |
408 | - $fields = implode( ', ', $fields ); |
|
408 | + $fields = implode(', ', $fields); |
|
409 | 409 | $invoice_rows[] = "($fields)"; |
410 | 410 | |
411 | 411 | $item_rows = array(); |
412 | 412 | $item_columns = array(); |
413 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
413 | + foreach ($invoice->get_cart_details() as $details) { |
|
414 | 414 | $fields = array( |
415 | 415 | 'post_id' => $invoice->ID, |
416 | 416 | 'item_id' => $details['id'], |
417 | 417 | 'item_name' => $details['name'], |
418 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
418 | + 'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'], |
|
419 | 419 | 'vat_rate' => $details['vat_rate'], |
420 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
420 | + 'vat_class' => empty($details['vat_class']) ? '_standard' : $details['vat_class'], |
|
421 | 421 | 'tax' => $details['tax'], |
422 | 422 | 'item_price' => $details['item_price'], |
423 | 423 | 'custom_price' => $details['custom_price'], |
@@ -429,31 +429,31 @@ discard block |
||
429 | 429 | 'fees' => $details['fees'], |
430 | 430 | ); |
431 | 431 | |
432 | - $item_columns = array_keys ( $fields ); |
|
432 | + $item_columns = array_keys($fields); |
|
433 | 433 | |
434 | - foreach ( $fields as $key => $val ) { |
|
435 | - if ( is_null( $val ) ) { |
|
434 | + foreach ($fields as $key => $val) { |
|
435 | + if (is_null($val)) { |
|
436 | 436 | $val = ''; |
437 | 437 | } |
438 | - $val = maybe_serialize( $val ); |
|
439 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
438 | + $val = maybe_serialize($val); |
|
439 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
440 | 440 | } |
441 | 441 | |
442 | - $fields = implode( ', ', $fields ); |
|
442 | + $fields = implode(', ', $fields); |
|
443 | 443 | $item_rows[] = "($fields)"; |
444 | 444 | } |
445 | 445 | |
446 | - $item_rows = implode( ', ', $item_rows ); |
|
447 | - $item_columns = implode( ', ', $item_columns ); |
|
448 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
446 | + $item_rows = implode(', ', $item_rows); |
|
447 | + $item_columns = implode(', ', $item_columns); |
|
448 | + $wpdb->query("INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows"); |
|
449 | 449 | } |
450 | 450 | |
451 | - if ( empty( $invoice_rows ) ) { |
|
451 | + if (empty($invoice_rows)) { |
|
452 | 452 | return; |
453 | 453 | } |
454 | 454 | |
455 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
456 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
455 | + $invoice_rows = implode(', ', $invoice_rows); |
|
456 | + $wpdb->query("INSERT INTO $invoices_table VALUES $invoice_rows"); |
|
457 | 457 | |
458 | 458 | } |
459 | 459 |
@@ -20,202 +20,202 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class GetPaid_Installer { |
22 | 22 | |
23 | - /** |
|
24 | - * Upgrades the install. |
|
25 | - * |
|
26 | - * @param string $upgrade_from The current invoicing version. |
|
27 | - */ |
|
28 | - public function upgrade_db( $upgrade_from ) { |
|
29 | - |
|
30 | - // Save the current invoicing version. |
|
31 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | - |
|
33 | - // Setup the invoice Custom Post Type. |
|
34 | - GetPaid_Post_Types::register_post_types(); |
|
35 | - |
|
36 | - // Clear the permalinks |
|
37 | - flush_rewrite_rules(); |
|
38 | - |
|
39 | - // Maybe create new/missing pages. |
|
40 | - $this->create_pages(); |
|
41 | - |
|
42 | - // Maybe re(add) admin capabilities. |
|
43 | - $this->add_capabilities(); |
|
44 | - |
|
45 | - // Maybe create the default payment form. |
|
46 | - wpinv_get_default_payment_form(); |
|
47 | - |
|
48 | - // Create any missing database tables. |
|
49 | - $method = "upgrade_from_$upgrade_from"; |
|
50 | - |
|
51 | - if ( method_exists( $this, $method ) ) { |
|
52 | - $this->$method(); |
|
53 | - } |
|
54 | - |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Do a fresh install. |
|
59 | - * |
|
60 | - */ |
|
61 | - public function upgrade_from_0() { |
|
62 | - $this->create_subscriptions_table(); |
|
63 | - $this->create_invoices_table(); |
|
64 | - $this->create_invoice_items_table(); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Upgrade to 0.0.5 |
|
69 | - * |
|
70 | - */ |
|
71 | - public function upgrade_from_004() { |
|
72 | - global $wpdb; |
|
73 | - |
|
74 | - // Invoices. |
|
75 | - $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
76 | - if ( ! empty( $results ) ) { |
|
77 | - $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
78 | - |
|
79 | - // Clean post cache |
|
80 | - foreach ( $results as $row ) { |
|
81 | - clean_post_cache( $row->ID ); |
|
82 | - } |
|
83 | - |
|
84 | - } |
|
85 | - |
|
86 | - // Item meta key changes |
|
87 | - $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
88 | - $results = $wpdb->get_results( $query ); |
|
89 | - |
|
90 | - if ( ! empty( $results ) ) { |
|
91 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
92 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
93 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
94 | - |
|
95 | - foreach ( $results as $row ) { |
|
96 | - clean_post_cache( $row->post_id ); |
|
97 | - } |
|
98 | - |
|
99 | - } |
|
100 | - |
|
101 | - $this->upgrade_from_102(); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Upgrade to 1.0.3 |
|
106 | - * |
|
107 | - */ |
|
108 | - public function upgrade_from_102() { |
|
109 | - $this->create_subscriptions_table(); |
|
110 | - $this->upgrade_from_118(); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Upgrade to version 2.0.0. |
|
115 | - * |
|
116 | - */ |
|
117 | - public function upgrade_from_118() { |
|
118 | - $this->create_invoices_table(); |
|
119 | - $this->create_invoice_items_table(); |
|
120 | - $this->migrate_old_invoices(); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Give administrators the capability to manage GetPaid. |
|
125 | - * |
|
126 | - */ |
|
127 | - public function add_capabilities() { |
|
128 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Re-create GetPaid pages. |
|
133 | - * |
|
134 | - */ |
|
135 | - public function create_pages() { |
|
136 | - |
|
137 | - $pages = apply_filters( |
|
138 | - 'wpinv_create_pages', |
|
139 | - array( |
|
140 | - |
|
141 | - // Checkout page. |
|
142 | - 'checkout_page' => array( |
|
143 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
144 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
145 | - 'content' => ' |
|
23 | + /** |
|
24 | + * Upgrades the install. |
|
25 | + * |
|
26 | + * @param string $upgrade_from The current invoicing version. |
|
27 | + */ |
|
28 | + public function upgrade_db( $upgrade_from ) { |
|
29 | + |
|
30 | + // Save the current invoicing version. |
|
31 | + update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | + |
|
33 | + // Setup the invoice Custom Post Type. |
|
34 | + GetPaid_Post_Types::register_post_types(); |
|
35 | + |
|
36 | + // Clear the permalinks |
|
37 | + flush_rewrite_rules(); |
|
38 | + |
|
39 | + // Maybe create new/missing pages. |
|
40 | + $this->create_pages(); |
|
41 | + |
|
42 | + // Maybe re(add) admin capabilities. |
|
43 | + $this->add_capabilities(); |
|
44 | + |
|
45 | + // Maybe create the default payment form. |
|
46 | + wpinv_get_default_payment_form(); |
|
47 | + |
|
48 | + // Create any missing database tables. |
|
49 | + $method = "upgrade_from_$upgrade_from"; |
|
50 | + |
|
51 | + if ( method_exists( $this, $method ) ) { |
|
52 | + $this->$method(); |
|
53 | + } |
|
54 | + |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Do a fresh install. |
|
59 | + * |
|
60 | + */ |
|
61 | + public function upgrade_from_0() { |
|
62 | + $this->create_subscriptions_table(); |
|
63 | + $this->create_invoices_table(); |
|
64 | + $this->create_invoice_items_table(); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Upgrade to 0.0.5 |
|
69 | + * |
|
70 | + */ |
|
71 | + public function upgrade_from_004() { |
|
72 | + global $wpdb; |
|
73 | + |
|
74 | + // Invoices. |
|
75 | + $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
76 | + if ( ! empty( $results ) ) { |
|
77 | + $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
78 | + |
|
79 | + // Clean post cache |
|
80 | + foreach ( $results as $row ) { |
|
81 | + clean_post_cache( $row->ID ); |
|
82 | + } |
|
83 | + |
|
84 | + } |
|
85 | + |
|
86 | + // Item meta key changes |
|
87 | + $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
88 | + $results = $wpdb->get_results( $query ); |
|
89 | + |
|
90 | + if ( ! empty( $results ) ) { |
|
91 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
92 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
93 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
94 | + |
|
95 | + foreach ( $results as $row ) { |
|
96 | + clean_post_cache( $row->post_id ); |
|
97 | + } |
|
98 | + |
|
99 | + } |
|
100 | + |
|
101 | + $this->upgrade_from_102(); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Upgrade to 1.0.3 |
|
106 | + * |
|
107 | + */ |
|
108 | + public function upgrade_from_102() { |
|
109 | + $this->create_subscriptions_table(); |
|
110 | + $this->upgrade_from_118(); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Upgrade to version 2.0.0. |
|
115 | + * |
|
116 | + */ |
|
117 | + public function upgrade_from_118() { |
|
118 | + $this->create_invoices_table(); |
|
119 | + $this->create_invoice_items_table(); |
|
120 | + $this->migrate_old_invoices(); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Give administrators the capability to manage GetPaid. |
|
125 | + * |
|
126 | + */ |
|
127 | + public function add_capabilities() { |
|
128 | + $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Re-create GetPaid pages. |
|
133 | + * |
|
134 | + */ |
|
135 | + public function create_pages() { |
|
136 | + |
|
137 | + $pages = apply_filters( |
|
138 | + 'wpinv_create_pages', |
|
139 | + array( |
|
140 | + |
|
141 | + // Checkout page. |
|
142 | + 'checkout_page' => array( |
|
143 | + 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
144 | + 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
145 | + 'content' => ' |
|
146 | 146 | <!-- wp:shortcode --> |
147 | 147 | [wpinv_checkout] |
148 | 148 | <!-- /wp:shortcode --> |
149 | 149 | ', |
150 | - 'parent' => '', |
|
151 | - ), |
|
152 | - |
|
153 | - // Invoice history page. |
|
154 | - 'invoice_history_page' => array( |
|
155 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
156 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
157 | - 'content' => ' |
|
150 | + 'parent' => '', |
|
151 | + ), |
|
152 | + |
|
153 | + // Invoice history page. |
|
154 | + 'invoice_history_page' => array( |
|
155 | + 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
156 | + 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
157 | + 'content' => ' |
|
158 | 158 | <!-- wp:shortcode --> |
159 | 159 | [wpinv_history] |
160 | 160 | <!-- /wp:shortcode --> |
161 | 161 | ', |
162 | - 'parent' => '', |
|
163 | - ), |
|
164 | - |
|
165 | - // Success page content. |
|
166 | - 'success_page' => array( |
|
167 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
168 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
169 | - 'content' => ' |
|
162 | + 'parent' => '', |
|
163 | + ), |
|
164 | + |
|
165 | + // Success page content. |
|
166 | + 'success_page' => array( |
|
167 | + 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
168 | + 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
169 | + 'content' => ' |
|
170 | 170 | <!-- wp:shortcode --> |
171 | 171 | [wpinv_receipt] |
172 | 172 | <!-- /wp:shortcode --> |
173 | 173 | ', |
174 | - 'parent' => 'gp-checkout', |
|
175 | - ), |
|
176 | - |
|
177 | - // Failure page content. |
|
178 | - 'failure_page' => array( |
|
179 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
180 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
181 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
182 | - 'parent' => 'gp-checkout', |
|
183 | - ), |
|
184 | - |
|
185 | - // Subscriptions history page. |
|
186 | - 'invoice_subscription_page' => array( |
|
187 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
188 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
189 | - 'content' => ' |
|
174 | + 'parent' => 'gp-checkout', |
|
175 | + ), |
|
176 | + |
|
177 | + // Failure page content. |
|
178 | + 'failure_page' => array( |
|
179 | + 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
180 | + 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
181 | + 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
182 | + 'parent' => 'gp-checkout', |
|
183 | + ), |
|
184 | + |
|
185 | + // Subscriptions history page. |
|
186 | + 'invoice_subscription_page' => array( |
|
187 | + 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
188 | + 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
189 | + 'content' => ' |
|
190 | 190 | <!-- wp:shortcode --> |
191 | 191 | [wpinv_subscriptions] |
192 | 192 | <!-- /wp:shortcode --> |
193 | 193 | ', |
194 | - 'parent' => '', |
|
195 | - ), |
|
194 | + 'parent' => '', |
|
195 | + ), |
|
196 | 196 | |
197 | - ) |
|
198 | - ); |
|
197 | + ) |
|
198 | + ); |
|
199 | 199 | |
200 | - foreach ( $pages as $key => $page ) { |
|
201 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
202 | - } |
|
200 | + foreach ( $pages as $key => $page ) { |
|
201 | + wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
202 | + } |
|
203 | 203 | |
204 | - } |
|
204 | + } |
|
205 | 205 | |
206 | - /** |
|
207 | - * Create subscriptions table. |
|
208 | - * |
|
209 | - */ |
|
210 | - public function create_subscriptions_table() { |
|
206 | + /** |
|
207 | + * Create subscriptions table. |
|
208 | + * |
|
209 | + */ |
|
210 | + public function create_subscriptions_table() { |
|
211 | 211 | |
212 | - global $wpdb; |
|
212 | + global $wpdb; |
|
213 | 213 | |
214 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
214 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
215 | 215 | |
216 | - // Create tables. |
|
217 | - $charset_collate = $wpdb->get_charset_collate(); |
|
218 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
216 | + // Create tables. |
|
217 | + $charset_collate = $wpdb->get_charset_collate(); |
|
218 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
219 | 219 | id bigint(20) unsigned NOT NULL auto_increment, |
220 | 220 | customer_id bigint(20) NOT NULL, |
221 | 221 | frequency int(11) NOT NULL DEFAULT '1', |
@@ -238,22 +238,22 @@ discard block |
||
238 | 238 | KEY customer_and_status (customer_id, status) |
239 | 239 | ) $charset_collate;"; |
240 | 240 | |
241 | - dbDelta( $sql ); |
|
241 | + dbDelta( $sql ); |
|
242 | 242 | |
243 | - } |
|
243 | + } |
|
244 | 244 | |
245 | - /** |
|
246 | - * Create invoices table. |
|
247 | - * |
|
248 | - */ |
|
249 | - public function create_invoices_table() { |
|
250 | - global $wpdb; |
|
245 | + /** |
|
246 | + * Create invoices table. |
|
247 | + * |
|
248 | + */ |
|
249 | + public function create_invoices_table() { |
|
250 | + global $wpdb; |
|
251 | 251 | |
252 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
252 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
253 | 253 | |
254 | - // Create tables. |
|
255 | - $charset_collate = $wpdb->get_charset_collate(); |
|
256 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
254 | + // Create tables. |
|
255 | + $charset_collate = $wpdb->get_charset_collate(); |
|
256 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
257 | 257 | post_id BIGINT(20) NOT NULL, |
258 | 258 | `number` VARCHAR(100), |
259 | 259 | `key` VARCHAR(100), |
@@ -289,22 +289,22 @@ discard block |
||
289 | 289 | KEY `key` (`key`) |
290 | 290 | ) $charset_collate;"; |
291 | 291 | |
292 | - dbDelta( $sql ); |
|
292 | + dbDelta( $sql ); |
|
293 | 293 | |
294 | - } |
|
294 | + } |
|
295 | 295 | |
296 | - /** |
|
297 | - * Create invoice items table. |
|
298 | - * |
|
299 | - */ |
|
300 | - public function create_invoice_items_table() { |
|
301 | - global $wpdb; |
|
296 | + /** |
|
297 | + * Create invoice items table. |
|
298 | + * |
|
299 | + */ |
|
300 | + public function create_invoice_items_table() { |
|
301 | + global $wpdb; |
|
302 | 302 | |
303 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
303 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
304 | 304 | |
305 | - // Create tables. |
|
306 | - $charset_collate = $wpdb->get_charset_collate(); |
|
307 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
305 | + // Create tables. |
|
306 | + $charset_collate = $wpdb->get_charset_collate(); |
|
307 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
308 | 308 | ID BIGINT(20) NOT NULL AUTO_INCREMENT, |
309 | 309 | post_id BIGINT(20) NOT NULL, |
310 | 310 | item_id BIGINT(20) NOT NULL, |
@@ -326,138 +326,138 @@ discard block |
||
326 | 326 | KEY post_id (post_id) |
327 | 327 | ) $charset_collate;"; |
328 | 328 | |
329 | - dbDelta( $sql ); |
|
330 | - |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Migrates old invoices to new invoices. |
|
335 | - * |
|
336 | - */ |
|
337 | - public function migrate_old_invoices() { |
|
338 | - global $wpdb; |
|
339 | - |
|
340 | - $invoices = array_unique( |
|
341 | - get_posts( |
|
342 | - array( |
|
343 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
344 | - 'posts_per_page' => -1, |
|
345 | - 'fields' => 'ids', |
|
346 | - 'post_status' => array_keys( get_post_stati() ), |
|
347 | - ) |
|
348 | - ) |
|
349 | - ); |
|
350 | - |
|
351 | - // Abort if we do not have any invoices. |
|
352 | - if ( empty( $invoices ) ) { |
|
353 | - return; |
|
354 | - } |
|
355 | - |
|
356 | - $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
357 | - $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
358 | - |
|
359 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
360 | - |
|
361 | - $invoice_rows = array(); |
|
362 | - foreach ( $invoices as $invoice ) { |
|
363 | - |
|
364 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
365 | - |
|
366 | - if ( empty( $invoice->ID ) ) { |
|
367 | - return; |
|
368 | - } |
|
369 | - |
|
370 | - $fields = array ( |
|
371 | - 'post_id' => $invoice->ID, |
|
372 | - 'number' => $invoice->get_number(), |
|
373 | - 'key' => $invoice->get_key(), |
|
374 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
375 | - 'mode' => $invoice->mode, |
|
376 | - 'user_ip' => $invoice->get_ip(), |
|
377 | - 'first_name' => $invoice->get_first_name(), |
|
378 | - 'last_name' => $invoice->get_last_name(), |
|
379 | - 'address' => $invoice->get_address(), |
|
380 | - 'city' => $invoice->city, |
|
381 | - 'state' => $invoice->state, |
|
382 | - 'country' => $invoice->country, |
|
383 | - 'zip' => $invoice->zip, |
|
384 | - 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
385 | - 'gateway' => $invoice->get_gateway(), |
|
386 | - 'transaction_id' => $invoice->get_transaction_id(), |
|
387 | - 'currency' => $invoice->get_currency(), |
|
388 | - 'subtotal' => $invoice->get_subtotal(), |
|
389 | - 'tax' => $invoice->get_tax(), |
|
390 | - 'fees_total' => $invoice->get_fees_total(), |
|
391 | - 'total' => $invoice->get_total(), |
|
392 | - 'discount' => $invoice->get_discount(), |
|
393 | - 'discount_code' => $invoice->get_discount_code(), |
|
394 | - 'disable_taxes' => $invoice->disable_taxes, |
|
395 | - 'due_date' => $invoice->get_due_date(), |
|
396 | - 'completed_date' => $invoice->get_completed_date(), |
|
397 | - 'company' => $invoice->company, |
|
398 | - 'vat_number' => $invoice->vat_number, |
|
399 | - 'vat_rate' => $invoice->vat_rate, |
|
400 | - 'custom_meta' => $invoice->payment_meta |
|
401 | - ); |
|
402 | - |
|
403 | - foreach ( $fields as $key => $val ) { |
|
404 | - if ( is_null( $val ) ) { |
|
405 | - $val = ''; |
|
406 | - } |
|
407 | - $val = maybe_serialize( $val ); |
|
408 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
409 | - } |
|
410 | - |
|
411 | - $fields = implode( ', ', $fields ); |
|
412 | - $invoice_rows[] = "($fields)"; |
|
413 | - |
|
414 | - $item_rows = array(); |
|
415 | - $item_columns = array(); |
|
416 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
417 | - $fields = array( |
|
418 | - 'post_id' => $invoice->ID, |
|
419 | - 'item_id' => $details['id'], |
|
420 | - 'item_name' => $details['name'], |
|
421 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
422 | - 'vat_rate' => $details['vat_rate'], |
|
423 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
424 | - 'tax' => $details['tax'], |
|
425 | - 'item_price' => $details['item_price'], |
|
426 | - 'custom_price' => $details['custom_price'], |
|
427 | - 'quantity' => $details['quantity'], |
|
428 | - 'discount' => $details['discount'], |
|
429 | - 'subtotal' => $details['subtotal'], |
|
430 | - 'price' => $details['price'], |
|
431 | - 'meta' => $details['meta'], |
|
432 | - 'fees' => $details['fees'], |
|
433 | - ); |
|
434 | - |
|
435 | - $item_columns = array_keys ( $fields ); |
|
436 | - |
|
437 | - foreach ( $fields as $key => $val ) { |
|
438 | - if ( is_null( $val ) ) { |
|
439 | - $val = ''; |
|
440 | - } |
|
441 | - $val = maybe_serialize( $val ); |
|
442 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
443 | - } |
|
444 | - |
|
445 | - $fields = implode( ', ', $fields ); |
|
446 | - $item_rows[] = "($fields)"; |
|
447 | - } |
|
448 | - |
|
449 | - $item_rows = implode( ', ', $item_rows ); |
|
450 | - $item_columns = implode( ', ', $item_columns ); |
|
451 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
452 | - } |
|
453 | - |
|
454 | - if ( empty( $invoice_rows ) ) { |
|
455 | - return; |
|
456 | - } |
|
457 | - |
|
458 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
459 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
460 | - |
|
461 | - } |
|
329 | + dbDelta( $sql ); |
|
330 | + |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Migrates old invoices to new invoices. |
|
335 | + * |
|
336 | + */ |
|
337 | + public function migrate_old_invoices() { |
|
338 | + global $wpdb; |
|
339 | + |
|
340 | + $invoices = array_unique( |
|
341 | + get_posts( |
|
342 | + array( |
|
343 | + 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
344 | + 'posts_per_page' => -1, |
|
345 | + 'fields' => 'ids', |
|
346 | + 'post_status' => array_keys( get_post_stati() ), |
|
347 | + ) |
|
348 | + ) |
|
349 | + ); |
|
350 | + |
|
351 | + // Abort if we do not have any invoices. |
|
352 | + if ( empty( $invoices ) ) { |
|
353 | + return; |
|
354 | + } |
|
355 | + |
|
356 | + $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
357 | + $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
358 | + |
|
359 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
360 | + |
|
361 | + $invoice_rows = array(); |
|
362 | + foreach ( $invoices as $invoice ) { |
|
363 | + |
|
364 | + $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
365 | + |
|
366 | + if ( empty( $invoice->ID ) ) { |
|
367 | + return; |
|
368 | + } |
|
369 | + |
|
370 | + $fields = array ( |
|
371 | + 'post_id' => $invoice->ID, |
|
372 | + 'number' => $invoice->get_number(), |
|
373 | + 'key' => $invoice->get_key(), |
|
374 | + 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
375 | + 'mode' => $invoice->mode, |
|
376 | + 'user_ip' => $invoice->get_ip(), |
|
377 | + 'first_name' => $invoice->get_first_name(), |
|
378 | + 'last_name' => $invoice->get_last_name(), |
|
379 | + 'address' => $invoice->get_address(), |
|
380 | + 'city' => $invoice->city, |
|
381 | + 'state' => $invoice->state, |
|
382 | + 'country' => $invoice->country, |
|
383 | + 'zip' => $invoice->zip, |
|
384 | + 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
385 | + 'gateway' => $invoice->get_gateway(), |
|
386 | + 'transaction_id' => $invoice->get_transaction_id(), |
|
387 | + 'currency' => $invoice->get_currency(), |
|
388 | + 'subtotal' => $invoice->get_subtotal(), |
|
389 | + 'tax' => $invoice->get_tax(), |
|
390 | + 'fees_total' => $invoice->get_fees_total(), |
|
391 | + 'total' => $invoice->get_total(), |
|
392 | + 'discount' => $invoice->get_discount(), |
|
393 | + 'discount_code' => $invoice->get_discount_code(), |
|
394 | + 'disable_taxes' => $invoice->disable_taxes, |
|
395 | + 'due_date' => $invoice->get_due_date(), |
|
396 | + 'completed_date' => $invoice->get_completed_date(), |
|
397 | + 'company' => $invoice->company, |
|
398 | + 'vat_number' => $invoice->vat_number, |
|
399 | + 'vat_rate' => $invoice->vat_rate, |
|
400 | + 'custom_meta' => $invoice->payment_meta |
|
401 | + ); |
|
402 | + |
|
403 | + foreach ( $fields as $key => $val ) { |
|
404 | + if ( is_null( $val ) ) { |
|
405 | + $val = ''; |
|
406 | + } |
|
407 | + $val = maybe_serialize( $val ); |
|
408 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
409 | + } |
|
410 | + |
|
411 | + $fields = implode( ', ', $fields ); |
|
412 | + $invoice_rows[] = "($fields)"; |
|
413 | + |
|
414 | + $item_rows = array(); |
|
415 | + $item_columns = array(); |
|
416 | + foreach ( $invoice->get_cart_details() as $details ) { |
|
417 | + $fields = array( |
|
418 | + 'post_id' => $invoice->ID, |
|
419 | + 'item_id' => $details['id'], |
|
420 | + 'item_name' => $details['name'], |
|
421 | + 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
422 | + 'vat_rate' => $details['vat_rate'], |
|
423 | + 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
424 | + 'tax' => $details['tax'], |
|
425 | + 'item_price' => $details['item_price'], |
|
426 | + 'custom_price' => $details['custom_price'], |
|
427 | + 'quantity' => $details['quantity'], |
|
428 | + 'discount' => $details['discount'], |
|
429 | + 'subtotal' => $details['subtotal'], |
|
430 | + 'price' => $details['price'], |
|
431 | + 'meta' => $details['meta'], |
|
432 | + 'fees' => $details['fees'], |
|
433 | + ); |
|
434 | + |
|
435 | + $item_columns = array_keys ( $fields ); |
|
436 | + |
|
437 | + foreach ( $fields as $key => $val ) { |
|
438 | + if ( is_null( $val ) ) { |
|
439 | + $val = ''; |
|
440 | + } |
|
441 | + $val = maybe_serialize( $val ); |
|
442 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
443 | + } |
|
444 | + |
|
445 | + $fields = implode( ', ', $fields ); |
|
446 | + $item_rows[] = "($fields)"; |
|
447 | + } |
|
448 | + |
|
449 | + $item_rows = implode( ', ', $item_rows ); |
|
450 | + $item_columns = implode( ', ', $item_columns ); |
|
451 | + $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
452 | + } |
|
453 | + |
|
454 | + if ( empty( $invoice_rows ) ) { |
|
455 | + return; |
|
456 | + } |
|
457 | + |
|
458 | + $invoice_rows = implode( ', ', $invoice_rows ); |
|
459 | + $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
460 | + |
|
461 | + } |
|
462 | 462 | |
463 | 463 | } |
@@ -628,10 +628,11 @@ |
||
628 | 628 | foreach ( $args['options'] as $key => $option ) : |
629 | 629 | $sanitize_key = wpinv_sanitize_key( $key ); |
630 | 630 | |
631 | - if ( is_array( $gateways ) && isset( $gateways[ $key ] ) ) |
|
632 | - $enabled = '1'; |
|
633 | - else |
|
634 | - $enabled = null; |
|
631 | + if ( is_array( $gateways ) && isset( $gateways[ $key ] ) ) { |
|
632 | + $enabled = '1'; |
|
633 | + } else { |
|
634 | + $enabled = null; |
|
635 | + } |
|
635 | 636 | |
636 | 637 | echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
637 | 638 | echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | $cb = "wpinv_{$option['type']}_callback"; |
197 | 197 | $section = "wpinv_settings_{$tab}_$section"; |
198 | 198 | |
199 | - if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) { |
|
200 | - $tip = wpinv_clean( $option['desc'] ); |
|
201 | - $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
202 | - unset( $option['desc'] ); |
|
203 | - } |
|
199 | + if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) { |
|
200 | + $tip = wpinv_clean( $option['desc'] ); |
|
201 | + $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
202 | + unset( $option['desc'] ); |
|
203 | + } |
|
204 | 204 | |
205 | 205 | // Loop through all tabs. |
206 | 206 | add_settings_field( |
@@ -227,8 +227,8 @@ discard block |
||
227 | 227 | 'faux' => isset( $option['faux'] ) ? $option['faux'] : false, |
228 | 228 | 'onchange' => isset( $option['onchange'] ) ? $option['onchange'] : '', |
229 | 229 | 'custom' => isset( $option['custom'] ) ? $option['custom'] : '', |
230 | - 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
231 | - 'style' => isset( $option['style'] ) ? $option['style'] : '', |
|
230 | + 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
231 | + 'style' => isset( $option['style'] ) ? $option['style'] : '', |
|
232 | 232 | 'cols' => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
233 | 233 | 'rows' => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
234 | 234 | ) |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | * @return array |
243 | 243 | */ |
244 | 244 | function wpinv_get_registered_settings() { |
245 | - return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) ); |
|
245 | + return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) ); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -289,10 +289,10 @@ discard block |
||
289 | 289 | } |
290 | 290 | |
291 | 291 | // General filter |
292 | - $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
292 | + $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
293 | 293 | |
294 | - // Key specific filter. |
|
295 | - $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
294 | + // Key specific filter. |
|
295 | + $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | // Loop through the whitelist and unset any that are empty for the tab being saved |
@@ -348,14 +348,14 @@ discard block |
||
348 | 348 | |
349 | 349 | foreach ( $new_rates as $rate ) { |
350 | 350 | |
351 | - $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
352 | - $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
353 | - $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
354 | - $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
355 | - $rate['global'] = empty( $rate['state'] ); |
|
356 | - $tax_rates[] = $rate; |
|
351 | + $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
352 | + $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
353 | + $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
354 | + $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
355 | + $rate['global'] = empty( $rate['state'] ); |
|
356 | + $tax_rates[] = $rate; |
|
357 | 357 | |
358 | - } |
|
358 | + } |
|
359 | 359 | |
360 | 360 | update_option( 'wpinv_tax_rates', $tax_rates ); |
361 | 361 | |
@@ -373,11 +373,11 @@ discard block |
||
373 | 373 | $tabs['general'] = __( 'General', 'invoicing' ); |
374 | 374 | $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' ); |
375 | 375 | $tabs['taxes'] = __( 'Taxes', 'invoicing' ); |
376 | - $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
376 | + $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
377 | 377 | |
378 | - if ( count( getpaid_get_integration_settings() ) > 0 ) { |
|
379 | - $tabs['integrations'] = __( 'Integrations', 'invoicing' ); |
|
380 | - } |
|
378 | + if ( count( getpaid_get_integration_settings() ) > 0 ) { |
|
379 | + $tabs['integrations'] = __( 'Integrations', 'invoicing' ); |
|
380 | + } |
|
381 | 381 | |
382 | 382 | $tabs['privacy'] = __( 'Privacy', 'invoicing' ); |
383 | 383 | $tabs['misc'] = __( 'Misc', 'invoicing' ); |
@@ -415,14 +415,14 @@ discard block |
||
415 | 415 | ) ), |
416 | 416 | 'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array( |
417 | 417 | 'main' => __( 'Tax Settings', 'invoicing' ), |
418 | - 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
419 | - 'vat' => __( 'EU VAT Settings', 'invoicing' ) |
|
418 | + 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
419 | + 'vat' => __( 'EU VAT Settings', 'invoicing' ) |
|
420 | 420 | ) ), |
421 | 421 | 'emails' => apply_filters( 'wpinv_settings_sections_emails', array( |
422 | 422 | 'main' => __( 'Email Settings', 'invoicing' ), |
423 | - ) ), |
|
423 | + ) ), |
|
424 | 424 | |
425 | - 'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ), |
|
425 | + 'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ), |
|
426 | 426 | |
427 | 427 | 'privacy' => apply_filters( 'wpinv_settings_sections_privacy', array( |
428 | 428 | 'main' => __( 'Privacy policy', 'invoicing' ), |
@@ -442,51 +442,51 @@ discard block |
||
442 | 442 | } |
443 | 443 | |
444 | 444 | function wpinv_get_pages( $with_slug = false, $default_label = NULL ) { |
445 | - $pages_options = array(); |
|
445 | + $pages_options = array(); |
|
446 | 446 | |
447 | - if( $default_label !== NULL && $default_label !== false ) { |
|
448 | - $pages_options = array( '' => $default_label ); // Blank option |
|
449 | - } |
|
447 | + if( $default_label !== NULL && $default_label !== false ) { |
|
448 | + $pages_options = array( '' => $default_label ); // Blank option |
|
449 | + } |
|
450 | 450 | |
451 | - $pages = get_pages(); |
|
452 | - if ( $pages ) { |
|
453 | - foreach ( $pages as $page ) { |
|
454 | - $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
451 | + $pages = get_pages(); |
|
452 | + if ( $pages ) { |
|
453 | + foreach ( $pages as $page ) { |
|
454 | + $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
455 | 455 | $pages_options[ $page->ID ] = $title; |
456 | - } |
|
457 | - } |
|
456 | + } |
|
457 | + } |
|
458 | 458 | |
459 | - return $pages_options; |
|
459 | + return $pages_options; |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | function wpinv_header_callback( $args ) { |
463 | - if ( !empty( $args['desc'] ) ) { |
|
463 | + if ( !empty( $args['desc'] ) ) { |
|
464 | 464 | echo $args['desc']; |
465 | 465 | } |
466 | 466 | } |
467 | 467 | |
468 | 468 | function wpinv_hidden_callback( $args ) { |
469 | - global $wpinv_options; |
|
470 | - |
|
471 | - if ( isset( $args['set_value'] ) ) { |
|
472 | - $value = $args['set_value']; |
|
473 | - } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
474 | - $value = $wpinv_options[ $args['id'] ]; |
|
475 | - } else { |
|
476 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
477 | - } |
|
478 | - |
|
479 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
480 | - $args['readonly'] = true; |
|
481 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
482 | - $name = ''; |
|
483 | - } else { |
|
484 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
485 | - } |
|
486 | - |
|
487 | - $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
469 | + global $wpinv_options; |
|
470 | + |
|
471 | + if ( isset( $args['set_value'] ) ) { |
|
472 | + $value = $args['set_value']; |
|
473 | + } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
474 | + $value = $wpinv_options[ $args['id'] ]; |
|
475 | + } else { |
|
476 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
477 | + } |
|
478 | + |
|
479 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
480 | + $args['readonly'] = true; |
|
481 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
482 | + $name = ''; |
|
483 | + } else { |
|
484 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
485 | + } |
|
486 | + |
|
487 | + $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
488 | 488 | |
489 | - echo $html; |
|
489 | + echo $html; |
|
490 | 490 | } |
491 | 491 | |
492 | 492 | /** |
@@ -494,12 +494,12 @@ discard block |
||
494 | 494 | */ |
495 | 495 | function wpinv_checkbox_callback( $args ) { |
496 | 496 | |
497 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
498 | - $std = wpinv_get_option( $args['id'], $std ); |
|
499 | - $id = esc_attr( $args['id'] ); |
|
497 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
498 | + $std = wpinv_get_option( $args['id'], $std ); |
|
499 | + $id = esc_attr( $args['id'] ); |
|
500 | 500 | |
501 | - getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
502 | - ?> |
|
501 | + getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
502 | + ?> |
|
503 | 503 | <fieldset> |
504 | 504 | <label> |
505 | 505 | <input id="wpinv-settings-<?php echo $id; ?>" name="wpinv_settings[<?php echo $id; ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox"> |
@@ -511,77 +511,77 @@ discard block |
||
511 | 511 | |
512 | 512 | function wpinv_multicheck_callback( $args ) { |
513 | 513 | |
514 | - global $wpinv_options; |
|
514 | + global $wpinv_options; |
|
515 | 515 | |
516 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
517 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
516 | + $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
517 | + $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
518 | 518 | |
519 | - if ( ! empty( $args['options'] ) ) { |
|
519 | + if ( ! empty( $args['options'] ) ) { |
|
520 | 520 | |
521 | - $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
522 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
521 | + $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
522 | + $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
523 | 523 | |
524 | - echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
|
524 | + echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
|
525 | 525 | foreach( $args['options'] as $key => $option ): |
526 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
527 | - if ( in_array( $sanitize_key, $value ) ) { |
|
528 | - $enabled = $sanitize_key; |
|
529 | - } else { |
|
530 | - $enabled = NULL; |
|
531 | - } |
|
532 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
533 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
534 | - endforeach; |
|
535 | - echo '</div>'; |
|
536 | - echo '<p class="description">' . $args['desc'] . '</p>'; |
|
537 | - } |
|
526 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
527 | + if ( in_array( $sanitize_key, $value ) ) { |
|
528 | + $enabled = $sanitize_key; |
|
529 | + } else { |
|
530 | + $enabled = NULL; |
|
531 | + } |
|
532 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
533 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
534 | + endforeach; |
|
535 | + echo '</div>'; |
|
536 | + echo '<p class="description">' . $args['desc'] . '</p>'; |
|
537 | + } |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | function wpinv_payment_icons_callback( $args ) { |
541 | - global $wpinv_options; |
|
541 | + global $wpinv_options; |
|
542 | 542 | |
543 | 543 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
544 | 544 | |
545 | - if ( ! empty( $args['options'] ) ) { |
|
546 | - foreach( $args['options'] as $key => $option ) { |
|
545 | + if ( ! empty( $args['options'] ) ) { |
|
546 | + foreach( $args['options'] as $key => $option ) { |
|
547 | 547 | $sanitize_key = wpinv_sanitize_key( $key ); |
548 | 548 | |
549 | - if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
550 | - $enabled = $option; |
|
551 | - } else { |
|
552 | - $enabled = NULL; |
|
553 | - } |
|
554 | - |
|
555 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
556 | - |
|
557 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
558 | - |
|
559 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
560 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
561 | - } else { |
|
562 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
563 | - |
|
564 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
565 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
566 | - } else { |
|
567 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
568 | - $content_dir = WP_CONTENT_DIR; |
|
569 | - |
|
570 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
571 | - // Replaces backslashes with forward slashes for Windows systems |
|
572 | - $image = wp_normalize_path( $image ); |
|
573 | - $content_dir = wp_normalize_path( $content_dir ); |
|
574 | - } |
|
575 | - |
|
576 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
577 | - } |
|
578 | - |
|
579 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
580 | - } |
|
581 | - echo $option . '</label>'; |
|
582 | - } |
|
583 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
584 | - } |
|
549 | + if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
550 | + $enabled = $option; |
|
551 | + } else { |
|
552 | + $enabled = NULL; |
|
553 | + } |
|
554 | + |
|
555 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
556 | + |
|
557 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
558 | + |
|
559 | + if ( wpinv_string_is_image_url( $key ) ) { |
|
560 | + echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
561 | + } else { |
|
562 | + $card = strtolower( str_replace( ' ', '', $option ) ); |
|
563 | + |
|
564 | + if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
565 | + $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
566 | + } else { |
|
567 | + $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
568 | + $content_dir = WP_CONTENT_DIR; |
|
569 | + |
|
570 | + if ( function_exists( 'wp_normalize_path' ) ) { |
|
571 | + // Replaces backslashes with forward slashes for Windows systems |
|
572 | + $image = wp_normalize_path( $image ); |
|
573 | + $content_dir = wp_normalize_path( $content_dir ); |
|
574 | + } |
|
575 | + |
|
576 | + $image = str_replace( $content_dir, content_url(), $image ); |
|
577 | + } |
|
578 | + |
|
579 | + echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
580 | + } |
|
581 | + echo $option . '</label>'; |
|
582 | + } |
|
583 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
584 | + } |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | /** |
@@ -589,9 +589,9 @@ discard block |
||
589 | 589 | */ |
590 | 590 | function wpinv_radio_callback( $args ) { |
591 | 591 | |
592 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
593 | - $std = wpinv_get_option( $args['id'], $std ); |
|
594 | - ?> |
|
592 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
593 | + $std = wpinv_get_option( $args['id'], $std ); |
|
594 | + ?> |
|
595 | 595 | <fieldset> |
596 | 596 | <ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;"> |
597 | 597 | <?php foreach( $args['options'] as $key => $option ) : ?> |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | </ul> |
606 | 606 | </fieldset> |
607 | 607 | <?php |
608 | - getpaid_settings_description_callback( $args ); |
|
608 | + getpaid_settings_description_callback( $args ); |
|
609 | 609 | } |
610 | 610 | |
611 | 611 | /** |
@@ -613,50 +613,50 @@ discard block |
||
613 | 613 | */ |
614 | 614 | function getpaid_settings_description_callback( $args ) { |
615 | 615 | |
616 | - if ( ! empty( $args['desc'] ) ) { |
|
617 | - $description = wp_kses_post( $args['desc'] ); |
|
618 | - echo "<p class='description'>$description</p>"; |
|
619 | - } |
|
616 | + if ( ! empty( $args['desc'] ) ) { |
|
617 | + $description = wp_kses_post( $args['desc'] ); |
|
618 | + echo "<p class='description'>$description</p>"; |
|
619 | + } |
|
620 | 620 | |
621 | 621 | } |
622 | 622 | |
623 | 623 | function wpinv_gateways_callback( $args ) { |
624 | 624 | |
625 | - $gateways = wpinv_get_option( 'gateways', array( 'manual' => 1 ) ); |
|
625 | + $gateways = wpinv_get_option( 'gateways', array( 'manual' => 1 ) ); |
|
626 | 626 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
627 | 627 | |
628 | - foreach ( $args['options'] as $key => $option ) : |
|
629 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
628 | + foreach ( $args['options'] as $key => $option ) : |
|
629 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
630 | 630 | |
631 | 631 | if ( is_array( $gateways ) && isset( $gateways[ $key ] ) ) |
632 | - $enabled = '1'; |
|
633 | - else |
|
634 | - $enabled = null; |
|
632 | + $enabled = '1'; |
|
633 | + else |
|
634 | + $enabled = null; |
|
635 | 635 | |
636 | - echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
637 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
638 | - endforeach; |
|
636 | + echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
637 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
638 | + endforeach; |
|
639 | 639 | } |
640 | 640 | |
641 | 641 | function wpinv_gateway_select_callback($args) { |
642 | - global $wpinv_options; |
|
642 | + global $wpinv_options; |
|
643 | 643 | |
644 | 644 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
645 | 645 | $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
646 | 646 | |
647 | - echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
647 | + echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
648 | 648 | |
649 | - foreach ( $args['options'] as $key => $option ) : |
|
650 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
649 | + foreach ( $args['options'] as $key => $option ) : |
|
650 | + if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
651 | 651 | $selected = selected( $key, $args['selected'], false ); |
652 | 652 | } else { |
653 | 653 | $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : ''; |
654 | 654 | } |
655 | - echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
656 | - endforeach; |
|
655 | + echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
656 | + endforeach; |
|
657 | 657 | |
658 | - echo '</select>'; |
|
659 | - echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
658 | + echo '</select>'; |
|
659 | + echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
660 | 660 | } |
661 | 661 | |
662 | 662 | /** |
@@ -667,29 +667,29 @@ discard block |
||
667 | 667 | */ |
668 | 668 | function wpinv_settings_attrs_helper( $args ) { |
669 | 669 | |
670 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
671 | - $id = esc_attr( $args['id'] ); |
|
672 | - $placeholder = esc_attr( $args['placeholder'] ); |
|
670 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
671 | + $id = esc_attr( $args['id'] ); |
|
672 | + $placeholder = esc_attr( $args['placeholder'] ); |
|
673 | 673 | |
674 | - if ( ! empty( $args['faux'] ) ) { |
|
675 | - $args['readonly'] = true; |
|
676 | - $name = ''; |
|
677 | - } else { |
|
678 | - $value = wpinv_get_option( $args['id'], $value ); |
|
679 | - $name = "wpinv_settings[$id]"; |
|
680 | - } |
|
674 | + if ( ! empty( $args['faux'] ) ) { |
|
675 | + $args['readonly'] = true; |
|
676 | + $name = ''; |
|
677 | + } else { |
|
678 | + $value = wpinv_get_option( $args['id'], $value ); |
|
679 | + $name = "wpinv_settings[$id]"; |
|
680 | + } |
|
681 | 681 | |
682 | - $value = is_scalar( $value ) ? esc_attr( $value ) : ''; |
|
683 | - $class = esc_attr( $args['class'] ); |
|
684 | - $style = esc_attr( $args['style'] ); |
|
685 | - $readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"'; |
|
682 | + $value = is_scalar( $value ) ? esc_attr( $value ) : ''; |
|
683 | + $class = esc_attr( $args['class'] ); |
|
684 | + $style = esc_attr( $args['style'] ); |
|
685 | + $readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"'; |
|
686 | 686 | |
687 | - $onchange = ''; |
|
687 | + $onchange = ''; |
|
688 | 688 | if ( ! empty( $args['onchange'] ) ) { |
689 | 689 | $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
690 | - } |
|
690 | + } |
|
691 | 691 | |
692 | - return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly"; |
|
692 | + return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly"; |
|
693 | 693 | } |
694 | 694 | |
695 | 695 | /** |
@@ -697,11 +697,11 @@ discard block |
||
697 | 697 | */ |
698 | 698 | function wpinv_text_callback( $args ) { |
699 | 699 | |
700 | - $desc = wp_kses_post( $args['desc'] ); |
|
701 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
702 | - $attr = wpinv_settings_attrs_helper( $args ); |
|
700 | + $desc = wp_kses_post( $args['desc'] ); |
|
701 | + $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
702 | + $attr = wpinv_settings_attrs_helper( $args ); |
|
703 | 703 | |
704 | - ?> |
|
704 | + ?> |
|
705 | 705 | <label style="width: 100%;"> |
706 | 706 | <input type="text" <?php echo $attr; ?>> |
707 | 707 | <?php echo $desc; ?> |
@@ -715,14 +715,14 @@ discard block |
||
715 | 715 | */ |
716 | 716 | function wpinv_number_callback( $args ) { |
717 | 717 | |
718 | - $desc = wp_kses_post( $args['desc'] ); |
|
719 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
720 | - $attr = wpinv_settings_attrs_helper( $args ); |
|
721 | - $max = intval( $args['max'] ); |
|
722 | - $min = intval( $args['min'] ); |
|
723 | - $step = floatval( $args['step'] ); |
|
718 | + $desc = wp_kses_post( $args['desc'] ); |
|
719 | + $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
720 | + $attr = wpinv_settings_attrs_helper( $args ); |
|
721 | + $max = intval( $args['max'] ); |
|
722 | + $min = intval( $args['min'] ); |
|
723 | + $step = floatval( $args['step'] ); |
|
724 | 724 | |
725 | - ?> |
|
725 | + ?> |
|
726 | 726 | <label style="width: 100%;"> |
727 | 727 | <input type="number" step="<?php echo $step; ?>" max="<?php echo $max; ?>" min="<?php echo $min; ?>" <?php echo $attr; ?>> |
728 | 728 | <?php echo $desc; ?> |
@@ -732,48 +732,48 @@ discard block |
||
732 | 732 | } |
733 | 733 | |
734 | 734 | function wpinv_textarea_callback( $args ) { |
735 | - global $wpinv_options; |
|
735 | + global $wpinv_options; |
|
736 | 736 | |
737 | 737 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
738 | 738 | |
739 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
740 | - $value = $wpinv_options[ $args['id'] ]; |
|
741 | - } else { |
|
742 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
743 | - } |
|
739 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
740 | + $value = $wpinv_options[ $args['id'] ]; |
|
741 | + } else { |
|
742 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
743 | + } |
|
744 | 744 | |
745 | 745 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
746 | 746 | $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
747 | 747 | |
748 | - $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
749 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
748 | + $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
749 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
750 | 750 | |
751 | - echo $html; |
|
751 | + echo $html; |
|
752 | 752 | } |
753 | 753 | |
754 | 754 | function wpinv_password_callback( $args ) { |
755 | - global $wpinv_options; |
|
755 | + global $wpinv_options; |
|
756 | 756 | |
757 | 757 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
758 | 758 | |
759 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
760 | - $value = $wpinv_options[ $args['id'] ]; |
|
761 | - } else { |
|
762 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
763 | - } |
|
759 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
760 | + $value = $wpinv_options[ $args['id'] ]; |
|
761 | + } else { |
|
762 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
763 | + } |
|
764 | 764 | |
765 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
766 | - $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
767 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
765 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
766 | + $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
767 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
768 | 768 | |
769 | - echo $html; |
|
769 | + echo $html; |
|
770 | 770 | } |
771 | 771 | |
772 | 772 | function wpinv_missing_callback($args) { |
773 | - printf( |
|
774 | - __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
775 | - '<strong>' . $args['id'] . '</strong>' |
|
776 | - ); |
|
773 | + printf( |
|
774 | + __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
775 | + '<strong>' . $args['id'] . '</strong>' |
|
776 | + ); |
|
777 | 777 | } |
778 | 778 | |
779 | 779 | /** |
@@ -781,13 +781,13 @@ discard block |
||
781 | 781 | */ |
782 | 782 | function wpinv_select_callback( $args ) { |
783 | 783 | |
784 | - $desc = wp_kses_post( $args['desc'] ); |
|
785 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
786 | - $attr = wpinv_settings_attrs_helper( $args ); |
|
787 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
788 | - $value = wpinv_get_option( $args['id'], $value ); |
|
784 | + $desc = wp_kses_post( $args['desc'] ); |
|
785 | + $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
786 | + $attr = wpinv_settings_attrs_helper( $args ); |
|
787 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
788 | + $value = wpinv_get_option( $args['id'], $value ); |
|
789 | 789 | |
790 | - ?> |
|
790 | + ?> |
|
791 | 791 | <label style="width: 100%;"> |
792 | 792 | <select <?php echo $attr; ?>> |
793 | 793 | <?php foreach ( $args['options'] as $option => $name ) : ?> |
@@ -801,123 +801,123 @@ discard block |
||
801 | 801 | } |
802 | 802 | |
803 | 803 | function wpinv_color_select_callback( $args ) { |
804 | - global $wpinv_options; |
|
804 | + global $wpinv_options; |
|
805 | 805 | |
806 | 806 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
807 | 807 | |
808 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
809 | - $value = $wpinv_options[ $args['id'] ]; |
|
810 | - } else { |
|
811 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
812 | - } |
|
808 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
809 | + $value = $wpinv_options[ $args['id'] ]; |
|
810 | + } else { |
|
811 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
812 | + } |
|
813 | 813 | |
814 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
814 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
815 | 815 | |
816 | - foreach ( $args['options'] as $option => $color ) { |
|
817 | - $selected = selected( $option, $value, false ); |
|
818 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
819 | - } |
|
816 | + foreach ( $args['options'] as $option => $color ) { |
|
817 | + $selected = selected( $option, $value, false ); |
|
818 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
819 | + } |
|
820 | 820 | |
821 | - $html .= '</select>'; |
|
822 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
821 | + $html .= '</select>'; |
|
822 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
823 | 823 | |
824 | - echo $html; |
|
824 | + echo $html; |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | function wpinv_rich_editor_callback( $args ) { |
828 | - global $wpinv_options, $wp_version; |
|
828 | + global $wpinv_options, $wp_version; |
|
829 | 829 | |
830 | 830 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
831 | 831 | |
832 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
833 | - $value = $wpinv_options[ $args['id'] ]; |
|
832 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
833 | + $value = $wpinv_options[ $args['id'] ]; |
|
834 | 834 | |
835 | - if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
836 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
837 | - } |
|
838 | - } else { |
|
839 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
840 | - } |
|
835 | + if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
836 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
837 | + } |
|
838 | + } else { |
|
839 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
840 | + } |
|
841 | 841 | |
842 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
842 | + $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
843 | 843 | |
844 | - $html = '<div class="getpaid-settings-editor-input">'; |
|
845 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
846 | - ob_start(); |
|
847 | - wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
848 | - $html .= ob_get_clean(); |
|
849 | - } else { |
|
850 | - $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
851 | - } |
|
844 | + $html = '<div class="getpaid-settings-editor-input">'; |
|
845 | + if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
846 | + ob_start(); |
|
847 | + wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
848 | + $html .= ob_get_clean(); |
|
849 | + } else { |
|
850 | + $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
851 | + } |
|
852 | 852 | |
853 | - $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
853 | + $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
854 | 854 | |
855 | - echo $html; |
|
855 | + echo $html; |
|
856 | 856 | } |
857 | 857 | |
858 | 858 | function wpinv_upload_callback( $args ) { |
859 | - global $wpinv_options; |
|
859 | + global $wpinv_options; |
|
860 | 860 | |
861 | 861 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
862 | 862 | |
863 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
864 | - $value = $wpinv_options[$args['id']]; |
|
865 | - } else { |
|
866 | - $value = isset($args['std']) ? $args['std'] : ''; |
|
867 | - } |
|
863 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
864 | + $value = $wpinv_options[$args['id']]; |
|
865 | + } else { |
|
866 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
867 | + } |
|
868 | 868 | |
869 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
870 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
871 | - $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
872 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
869 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
870 | + $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
871 | + $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
872 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
873 | 873 | |
874 | - echo $html; |
|
874 | + echo $html; |
|
875 | 875 | } |
876 | 876 | |
877 | 877 | function wpinv_color_callback( $args ) { |
878 | - global $wpinv_options; |
|
878 | + global $wpinv_options; |
|
879 | 879 | |
880 | 880 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
881 | 881 | |
882 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
883 | - $value = $wpinv_options[ $args['id'] ]; |
|
884 | - } else { |
|
885 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
886 | - } |
|
882 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
883 | + $value = $wpinv_options[ $args['id'] ]; |
|
884 | + } else { |
|
885 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
886 | + } |
|
887 | 887 | |
888 | - $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
888 | + $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
889 | 889 | |
890 | - $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
891 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
890 | + $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
891 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
892 | 892 | |
893 | - echo $html; |
|
893 | + echo $html; |
|
894 | 894 | } |
895 | 895 | |
896 | 896 | function wpinv_country_states_callback($args) { |
897 | - global $wpinv_options; |
|
897 | + global $wpinv_options; |
|
898 | 898 | |
899 | 899 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
900 | 900 | |
901 | - if ( isset( $args['placeholder'] ) ) { |
|
902 | - $placeholder = $args['placeholder']; |
|
903 | - } else { |
|
904 | - $placeholder = ''; |
|
905 | - } |
|
901 | + if ( isset( $args['placeholder'] ) ) { |
|
902 | + $placeholder = $args['placeholder']; |
|
903 | + } else { |
|
904 | + $placeholder = ''; |
|
905 | + } |
|
906 | 906 | |
907 | - $states = wpinv_get_country_states(); |
|
907 | + $states = wpinv_get_country_states(); |
|
908 | 908 | |
909 | - $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
910 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
909 | + $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
910 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
911 | 911 | |
912 | - foreach ( $states as $option => $name ) { |
|
913 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
914 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
915 | - } |
|
912 | + foreach ( $states as $option => $name ) { |
|
913 | + $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
914 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
915 | + } |
|
916 | 916 | |
917 | - $html .= '</select>'; |
|
918 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
917 | + $html .= '</select>'; |
|
918 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
919 | 919 | |
920 | - echo $html; |
|
920 | + echo $html; |
|
921 | 921 | } |
922 | 922 | |
923 | 923 | /** |
@@ -925,7 +925,7 @@ discard block |
||
925 | 925 | */ |
926 | 926 | function wpinv_tax_rates_callback() { |
927 | 927 | |
928 | - ?> |
|
928 | + ?> |
|
929 | 929 | </td> |
930 | 930 | </tr> |
931 | 931 | <tr class="bsui"> |
@@ -940,17 +940,17 @@ discard block |
||
940 | 940 | * Displays a tax rate' edit row. |
941 | 941 | */ |
942 | 942 | function wpinv_tax_rate_callback( $tax_rate, $key, $echo = true ) { |
943 | - ob_start(); |
|
943 | + ob_start(); |
|
944 | 944 | |
945 | - $key = sanitize_key( $key ); |
|
946 | - $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
947 | - include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
945 | + $key = sanitize_key( $key ); |
|
946 | + $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
947 | + include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
948 | 948 | |
949 | - if ( $echo ) { |
|
950 | - echo ob_get_clean(); |
|
951 | - } else { |
|
952 | - return ob_get_clean(); |
|
953 | - } |
|
949 | + if ( $echo ) { |
|
950 | + echo ob_get_clean(); |
|
951 | + } else { |
|
952 | + return ob_get_clean(); |
|
953 | + } |
|
954 | 954 | |
955 | 955 | } |
956 | 956 | |
@@ -977,14 +977,14 @@ discard block |
||
977 | 977 | </td> |
978 | 978 | <td> |
979 | 979 | <a href="<?php |
980 | - echo esc_url( |
|
981 | - wp_nonce_url( |
|
982 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
983 | - 'getpaid-nonce', |
|
984 | - 'getpaid-nonce' |
|
985 | - ) |
|
986 | - ); |
|
987 | - ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
980 | + echo esc_url( |
|
981 | + wp_nonce_url( |
|
982 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
983 | + 'getpaid-nonce', |
|
984 | + 'getpaid-nonce' |
|
985 | + ) |
|
986 | + ); |
|
987 | + ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
988 | 988 | </td> |
989 | 989 | </tr> |
990 | 990 | <tr> |
@@ -994,14 +994,14 @@ discard block |
||
994 | 994 | </td> |
995 | 995 | <td> |
996 | 996 | <a href="<?php |
997 | - echo esc_url( |
|
998 | - wp_nonce_url( |
|
999 | - add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
1000 | - 'getpaid-nonce', |
|
1001 | - 'getpaid-nonce' |
|
1002 | - ) |
|
1003 | - ); |
|
1004 | - ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
997 | + echo esc_url( |
|
998 | + wp_nonce_url( |
|
999 | + add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
1000 | + 'getpaid-nonce', |
|
1001 | + 'getpaid-nonce' |
|
1002 | + ) |
|
1003 | + ); |
|
1004 | + ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
1005 | 1005 | </td> |
1006 | 1006 | </tr> |
1007 | 1007 | <tr> |
@@ -1011,14 +1011,14 @@ discard block |
||
1011 | 1011 | </td> |
1012 | 1012 | <td> |
1013 | 1013 | <a href="<?php |
1014 | - echo esc_url( |
|
1015 | - wp_nonce_url( |
|
1016 | - add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ), |
|
1017 | - 'getpaid-nonce', |
|
1018 | - 'getpaid-nonce' |
|
1019 | - ) |
|
1020 | - ); |
|
1021 | - ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
1014 | + echo esc_url( |
|
1015 | + wp_nonce_url( |
|
1016 | + add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ), |
|
1017 | + 'getpaid-nonce', |
|
1018 | + 'getpaid-nonce' |
|
1019 | + ) |
|
1020 | + ); |
|
1021 | + ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
1022 | 1022 | </td> |
1023 | 1023 | </tr> |
1024 | 1024 | <?php do_action( 'wpinv_tools_row' ); ?> |
@@ -1030,19 +1030,19 @@ discard block |
||
1030 | 1030 | } |
1031 | 1031 | |
1032 | 1032 | function wpinv_descriptive_text_callback( $args ) { |
1033 | - echo wp_kses_post( $args['desc'] ); |
|
1033 | + echo wp_kses_post( $args['desc'] ); |
|
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | function wpinv_raw_html_callback( $args ) { |
1037 | - echo $args['desc']; |
|
1037 | + echo $args['desc']; |
|
1038 | 1038 | } |
1039 | 1039 | |
1040 | 1040 | function wpinv_hook_callback( $args ) { |
1041 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
1041 | + do_action( 'wpinv_' . $args['id'], $args ); |
|
1042 | 1042 | } |
1043 | 1043 | |
1044 | 1044 | function wpinv_set_settings_cap() { |
1045 | - return wpinv_get_capability(); |
|
1045 | + return wpinv_get_capability(); |
|
1046 | 1046 | } |
1047 | 1047 | add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
1048 | 1048 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 1.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Retrieves all default settings. |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | function wpinv_get_settings() { |
17 | 17 | $defaults = array(); |
18 | 18 | |
19 | - foreach ( array_values( wpinv_get_registered_settings() ) as $tab_settings ) { |
|
19 | + foreach (array_values(wpinv_get_registered_settings()) as $tab_settings) { |
|
20 | 20 | |
21 | - foreach ( array_values( $tab_settings ) as $section_settings ) { |
|
21 | + foreach (array_values($tab_settings) as $section_settings) { |
|
22 | 22 | |
23 | - foreach ( $section_settings as $key => $setting ) { |
|
24 | - if ( isset( $setting['std'] ) ) { |
|
25 | - $defaults[ $key ] = $setting['std']; |
|
23 | + foreach ($section_settings as $key => $setting) { |
|
24 | + if (isset($setting['std'])) { |
|
25 | + $defaults[$key] = $setting['std']; |
|
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
@@ -43,12 +43,12 @@ discard block |
||
43 | 43 | global $wpinv_options; |
44 | 44 | |
45 | 45 | // Try fetching the saved options. |
46 | - if ( ! is_array( $wpinv_options ) ) { |
|
47 | - $wpinv_options = get_option( 'wpinv_settings' ); |
|
46 | + if (!is_array($wpinv_options)) { |
|
47 | + $wpinv_options = get_option('wpinv_settings'); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | // If that fails, don't fetch the default settings to prevent a loop. |
51 | - if ( ! is_array( $wpinv_options ) ) { |
|
51 | + if (!is_array($wpinv_options)) { |
|
52 | 52 | $wpinv_options = array(); |
53 | 53 | } |
54 | 54 | |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | * @param mixed $default The default value to use if the setting has not been set. |
63 | 63 | * @return mixed |
64 | 64 | */ |
65 | -function wpinv_get_option( $key = '', $default = false ) { |
|
65 | +function wpinv_get_option($key = '', $default = false) { |
|
66 | 66 | |
67 | 67 | $options = wpinv_get_options(); |
68 | - $value = isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
69 | - $value = apply_filters( 'wpinv_get_option', $value, $key, $default ); |
|
68 | + $value = isset($options[$key]) ? $options[$key] : $default; |
|
69 | + $value = apply_filters('wpinv_get_option', $value, $key, $default); |
|
70 | 70 | |
71 | - return apply_filters( 'wpinv_get_option_' . $key, $value, $key, $default ); |
|
71 | + return apply_filters('wpinv_get_option_' . $key, $value, $key, $default); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,11 +77,11 @@ discard block |
||
77 | 77 | * @param array $options the new options. |
78 | 78 | * @return bool |
79 | 79 | */ |
80 | -function wpinv_update_options( $options ) { |
|
80 | +function wpinv_update_options($options) { |
|
81 | 81 | global $wpinv_options; |
82 | 82 | |
83 | 83 | // update the option. |
84 | - if ( is_array( $options ) && update_option( 'wpinv_settings', $options ) ) { |
|
84 | + if (is_array($options) && update_option('wpinv_settings', $options)) { |
|
85 | 85 | $wpinv_options = $options; |
86 | 86 | return true; |
87 | 87 | } |
@@ -96,24 +96,24 @@ discard block |
||
96 | 96 | * @param mixed $value The setting value. |
97 | 97 | * @return bool |
98 | 98 | */ |
99 | -function wpinv_update_option( $key = '', $value = false ) { |
|
99 | +function wpinv_update_option($key = '', $value = false) { |
|
100 | 100 | |
101 | 101 | // If no key, exit. |
102 | - if ( empty( $key ) ) { |
|
102 | + if (empty($key)) { |
|
103 | 103 | return false; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Maybe delete the option instead. |
107 | - if ( is_null( $value ) ) { |
|
108 | - return wpinv_delete_option( $key ); |
|
107 | + if (is_null($value)) { |
|
108 | + return wpinv_delete_option($key); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | // Prepare the new options. |
112 | 112 | $options = wpinv_get_options(); |
113 | - $options[ $key ] = apply_filters( 'wpinv_update_option', $value, $key ); |
|
113 | + $options[$key] = apply_filters('wpinv_update_option', $value, $key); |
|
114 | 114 | |
115 | 115 | // Save the new options. |
116 | - return wpinv_update_options( $options ); |
|
116 | + return wpinv_update_options($options); |
|
117 | 117 | |
118 | 118 | } |
119 | 119 | |
@@ -123,18 +123,18 @@ discard block |
||
123 | 123 | * @param string $key the setting key. |
124 | 124 | * @return bool |
125 | 125 | */ |
126 | -function wpinv_delete_option( $key = '' ) { |
|
126 | +function wpinv_delete_option($key = '') { |
|
127 | 127 | |
128 | 128 | // If no key, exit |
129 | - if ( empty( $key ) ) { |
|
129 | + if (empty($key)) { |
|
130 | 130 | return false; |
131 | 131 | } |
132 | 132 | |
133 | 133 | $options = wpinv_get_options(); |
134 | 134 | |
135 | - if ( isset( $options[ $key ] ) ) { |
|
136 | - unset( $options[ $key ] ); |
|
137 | - return wpinv_update_options( $options ); |
|
135 | + if (isset($options[$key])) { |
|
136 | + unset($options[$key]); |
|
137 | + return wpinv_update_options($options); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | return true; |
@@ -148,14 +148,14 @@ discard block |
||
148 | 148 | function wpinv_register_settings() { |
149 | 149 | |
150 | 150 | // Loop through all tabs. |
151 | - foreach ( wpinv_get_registered_settings() as $tab => $sections ) { |
|
151 | + foreach (wpinv_get_registered_settings() as $tab => $sections) { |
|
152 | 152 | |
153 | 153 | // In each tab, loop through sections. |
154 | - foreach ( $sections as $section => $settings ) { |
|
154 | + foreach ($sections as $section => $settings) { |
|
155 | 155 | |
156 | 156 | // Check for backwards compatibility |
157 | - $section_tabs = wpinv_get_settings_tab_sections( $tab ); |
|
158 | - if ( ! is_array( $section_tabs ) || ! array_key_exists( $section, $section_tabs ) ) { |
|
157 | + $section_tabs = wpinv_get_settings_tab_sections($tab); |
|
158 | + if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) { |
|
159 | 159 | $section = 'main'; |
160 | 160 | $settings = $sections; |
161 | 161 | } |
@@ -168,9 +168,9 @@ discard block |
||
168 | 168 | 'wpinv_settings_' . $tab . '_' . $section |
169 | 169 | ); |
170 | 170 | |
171 | - foreach ( $settings as $option ) { |
|
172 | - if ( ! empty( $option['id'] ) ) { |
|
173 | - wpinv_register_settings_option( $tab, $section, $option ); |
|
171 | + foreach ($settings as $option) { |
|
172 | + if (!empty($option['id'])) { |
|
173 | + wpinv_register_settings_option($tab, $section, $option); |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | |
@@ -178,9 +178,9 @@ discard block |
||
178 | 178 | } |
179 | 179 | |
180 | 180 | // Creates our settings in the options table. |
181 | - register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' ); |
|
181 | + register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize'); |
|
182 | 182 | } |
183 | -add_action( 'admin_init', 'wpinv_register_settings' ); |
|
183 | +add_action('admin_init', 'wpinv_register_settings'); |
|
184 | 184 | |
185 | 185 | /** |
186 | 186 | * Register a single settings option. |
@@ -190,47 +190,47 @@ discard block |
||
190 | 190 | * @param string $option |
191 | 191 | * |
192 | 192 | */ |
193 | -function wpinv_register_settings_option( $tab, $section, $option ) { |
|
193 | +function wpinv_register_settings_option($tab, $section, $option) { |
|
194 | 194 | |
195 | - $name = isset( $option['name'] ) ? $option['name'] : ''; |
|
195 | + $name = isset($option['name']) ? $option['name'] : ''; |
|
196 | 196 | $cb = "wpinv_{$option['type']}_callback"; |
197 | 197 | $section = "wpinv_settings_{$tab}_$section"; |
198 | 198 | |
199 | - if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) { |
|
200 | - $tip = wpinv_clean( $option['desc'] ); |
|
199 | + if (isset($option['desc']) && !empty($option['help-tip'])) { |
|
200 | + $tip = wpinv_clean($option['desc']); |
|
201 | 201 | $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
202 | - unset( $option['desc'] ); |
|
202 | + unset($option['desc']); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | // Loop through all tabs. |
206 | 206 | add_settings_field( |
207 | 207 | 'wpinv_settings[' . $option['id'] . ']', |
208 | 208 | $name, |
209 | - function_exists( $cb ) ? $cb : 'wpinv_missing_callback', |
|
209 | + function_exists($cb) ? $cb : 'wpinv_missing_callback', |
|
210 | 210 | $section, |
211 | 211 | $section, |
212 | 212 | array( |
213 | 213 | 'section' => $section, |
214 | - 'id' => isset( $option['id'] ) ? $option['id'] : uniqid( 'wpinv-' ), |
|
215 | - 'desc' => isset( $option['desc'] ) ? $option['desc'] : '', |
|
214 | + 'id' => isset($option['id']) ? $option['id'] : uniqid('wpinv-'), |
|
215 | + 'desc' => isset($option['desc']) ? $option['desc'] : '', |
|
216 | 216 | 'name' => $name, |
217 | - 'size' => isset( $option['size'] ) ? $option['size'] : null, |
|
218 | - 'options' => isset( $option['options'] ) ? $option['options'] : '', |
|
219 | - 'selected' => isset( $option['selected'] ) ? $option['selected'] : null, |
|
220 | - 'std' => isset( $option['std'] ) ? $option['std'] : '', |
|
221 | - 'min' => isset( $option['min'] ) ? $option['min'] : 0, |
|
222 | - 'max' => isset( $option['max'] ) ? $option['max'] : 999999, |
|
223 | - 'step' => isset( $option['step'] ) ? $option['step'] : 1, |
|
224 | - 'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null, |
|
225 | - 'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true, |
|
226 | - 'readonly' => isset( $option['readonly'] ) ? $option['readonly'] : false, |
|
227 | - 'faux' => isset( $option['faux'] ) ? $option['faux'] : false, |
|
228 | - 'onchange' => isset( $option['onchange'] ) ? $option['onchange'] : '', |
|
229 | - 'custom' => isset( $option['custom'] ) ? $option['custom'] : '', |
|
230 | - 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
231 | - 'style' => isset( $option['style'] ) ? $option['style'] : '', |
|
232 | - 'cols' => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
|
233 | - 'rows' => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
|
217 | + 'size' => isset($option['size']) ? $option['size'] : null, |
|
218 | + 'options' => isset($option['options']) ? $option['options'] : '', |
|
219 | + 'selected' => isset($option['selected']) ? $option['selected'] : null, |
|
220 | + 'std' => isset($option['std']) ? $option['std'] : '', |
|
221 | + 'min' => isset($option['min']) ? $option['min'] : 0, |
|
222 | + 'max' => isset($option['max']) ? $option['max'] : 999999, |
|
223 | + 'step' => isset($option['step']) ? $option['step'] : 1, |
|
224 | + 'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : null, |
|
225 | + 'allow_blank' => isset($option['allow_blank']) ? $option['allow_blank'] : true, |
|
226 | + 'readonly' => isset($option['readonly']) ? $option['readonly'] : false, |
|
227 | + 'faux' => isset($option['faux']) ? $option['faux'] : false, |
|
228 | + 'onchange' => isset($option['onchange']) ? $option['onchange'] : '', |
|
229 | + 'custom' => isset($option['custom']) ? $option['custom'] : '', |
|
230 | + 'class' => isset($option['class']) ? $option['class'] : '', |
|
231 | + 'style' => isset($option['style']) ? $option['style'] : '', |
|
232 | + 'cols' => isset($option['cols']) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
|
233 | + 'rows' => isset($option['rows']) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
|
234 | 234 | ) |
235 | 235 | ); |
236 | 236 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | * @return array |
243 | 243 | */ |
244 | 244 | function wpinv_get_registered_settings() { |
245 | - return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) ); |
|
245 | + return array_filter(apply_filters('wpinv_registered_settings', wpinv_get_data('admin-settings'))); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * @return array |
252 | 252 | */ |
253 | 253 | function getpaid_get_integration_settings() { |
254 | - return apply_filters( 'getpaid_integration_settings', array() ); |
|
254 | + return apply_filters('getpaid_integration_settings', array()); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
@@ -259,139 +259,139 @@ discard block |
||
259 | 259 | * |
260 | 260 | * @return array |
261 | 261 | */ |
262 | -function wpinv_settings_sanitize( $input = array() ) { |
|
262 | +function wpinv_settings_sanitize($input = array()) { |
|
263 | 263 | |
264 | 264 | $wpinv_options = wpinv_get_options(); |
265 | 265 | |
266 | - if ( empty( wp_get_raw_referer() ) ) { |
|
266 | + if (empty(wp_get_raw_referer())) { |
|
267 | 267 | return $input; |
268 | 268 | } |
269 | 269 | |
270 | - wp_parse_str( wp_get_raw_referer(), $referrer ); |
|
270 | + wp_parse_str(wp_get_raw_referer(), $referrer); |
|
271 | 271 | |
272 | 272 | $settings = wpinv_get_registered_settings(); |
273 | - $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general'; |
|
274 | - $section = isset( $referrer['section'] ) ? $referrer['section'] : 'main'; |
|
273 | + $tab = isset($referrer['tab']) ? $referrer['tab'] : 'general'; |
|
274 | + $section = isset($referrer['section']) ? $referrer['section'] : 'main'; |
|
275 | 275 | |
276 | 276 | $input = $input ? $input : array(); |
277 | - $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input ); |
|
278 | - $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input ); |
|
277 | + $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input); |
|
278 | + $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input); |
|
279 | 279 | |
280 | 280 | // Loop through each setting being saved and pass it through a sanitization filter |
281 | - foreach ( $input as $key => $value ) { |
|
281 | + foreach ($input as $key => $value) { |
|
282 | 282 | |
283 | 283 | // Get the setting type (checkbox, select, etc) |
284 | - $type = isset( $settings[ $tab ][$section][ $key ]['type'] ) ? $settings[ $tab ][$section][ $key ]['type'] : false; |
|
284 | + $type = isset($settings[$tab][$section][$key]['type']) ? $settings[$tab][$section][$key]['type'] : false; |
|
285 | 285 | |
286 | - if ( $type ) { |
|
286 | + if ($type) { |
|
287 | 287 | // Field type specific filter |
288 | - $input[$key] = apply_filters( 'wpinv_settings_sanitize_' . $type, $value, $key ); |
|
288 | + $input[$key] = apply_filters('wpinv_settings_sanitize_' . $type, $value, $key); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | // General filter |
292 | - $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
292 | + $input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key); |
|
293 | 293 | |
294 | 294 | // Key specific filter. |
295 | - $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
295 | + $input[$key] = apply_filters("wpinv_settings_sanitize_$key", $input[$key]); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | // Loop through the whitelist and unset any that are empty for the tab being saved |
299 | - $main_settings = $section == 'main' ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections |
|
300 | - $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array(); |
|
299 | + $main_settings = $section == 'main' ? $settings[$tab] : array(); // Check for extensions that aren't using new sections |
|
300 | + $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array(); |
|
301 | 301 | |
302 | - $found_settings = array_merge( $main_settings, $section_settings ); |
|
302 | + $found_settings = array_merge($main_settings, $section_settings); |
|
303 | 303 | |
304 | - if ( ! empty( $found_settings ) ) { |
|
305 | - foreach ( $found_settings as $key => $value ) { |
|
304 | + if (!empty($found_settings)) { |
|
305 | + foreach ($found_settings as $key => $value) { |
|
306 | 306 | |
307 | 307 | // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work |
308 | - if ( is_numeric( $key ) ) { |
|
308 | + if (is_numeric($key)) { |
|
309 | 309 | $key = $value['id']; |
310 | 310 | } |
311 | 311 | |
312 | - if ( ! isset( $input[ $key ] ) && isset( $wpinv_options[ $key ] ) ) { |
|
313 | - unset( $wpinv_options[ $key ] ); |
|
312 | + if (!isset($input[$key]) && isset($wpinv_options[$key])) { |
|
313 | + unset($wpinv_options[$key]); |
|
314 | 314 | } |
315 | 315 | } |
316 | 316 | } |
317 | 317 | |
318 | 318 | // Merge our new settings with the existing |
319 | - $output = array_merge( $wpinv_options, $input ); |
|
319 | + $output = array_merge($wpinv_options, $input); |
|
320 | 320 | |
321 | - add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' ); |
|
321 | + add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated'); |
|
322 | 322 | |
323 | 323 | return $output; |
324 | 324 | } |
325 | 325 | |
326 | -function wpinv_settings_sanitize_misc_accounting( $input ) { |
|
326 | +function wpinv_settings_sanitize_misc_accounting($input) { |
|
327 | 327 | |
328 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
328 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
329 | 329 | return $input; |
330 | 330 | } |
331 | 331 | |
332 | - if( ! empty( $input['enable_sequential'] ) && !wpinv_get_option( 'enable_sequential' ) ) { |
|
332 | + if (!empty($input['enable_sequential']) && !wpinv_get_option('enable_sequential')) { |
|
333 | 333 | // Shows an admin notice about upgrading previous order numbers |
334 | - getpaid_session()->set( 'upgrade_sequential', '1' ); |
|
334 | + getpaid_session()->set('upgrade_sequential', '1'); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | return $input; |
338 | 338 | } |
339 | -add_filter( 'wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting' ); |
|
339 | +add_filter('wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting'); |
|
340 | 340 | |
341 | -function wpinv_settings_sanitize_tax_rates( $input ) { |
|
342 | - if( ! wpinv_current_user_can_manage_invoicing() ) { |
|
341 | +function wpinv_settings_sanitize_tax_rates($input) { |
|
342 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
343 | 343 | return $input; |
344 | 344 | } |
345 | 345 | |
346 | - $new_rates = ! empty( $_POST['tax_rates'] ) ? array_values( $_POST['tax_rates'] ) : array(); |
|
346 | + $new_rates = !empty($_POST['tax_rates']) ? array_values($_POST['tax_rates']) : array(); |
|
347 | 347 | $tax_rates = array(); |
348 | 348 | |
349 | - foreach ( $new_rates as $rate ) { |
|
349 | + foreach ($new_rates as $rate) { |
|
350 | 350 | |
351 | - $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
352 | - $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
353 | - $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
354 | - $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
355 | - $rate['global'] = empty( $rate['state'] ); |
|
351 | + $rate['rate'] = wpinv_sanitize_amount($rate['rate']); |
|
352 | + $rate['name'] = sanitize_text_field($rate['name']); |
|
353 | + $rate['state'] = sanitize_text_field($rate['state']); |
|
354 | + $rate['country'] = sanitize_text_field($rate['country']); |
|
355 | + $rate['global'] = empty($rate['state']); |
|
356 | 356 | $tax_rates[] = $rate; |
357 | 357 | |
358 | 358 | } |
359 | 359 | |
360 | - update_option( 'wpinv_tax_rates', $tax_rates ); |
|
360 | + update_option('wpinv_tax_rates', $tax_rates); |
|
361 | 361 | |
362 | 362 | return $input; |
363 | 363 | } |
364 | -add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' ); |
|
364 | +add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates'); |
|
365 | 365 | |
366 | -function wpinv_sanitize_text_field( $input ) { |
|
367 | - return trim( $input ); |
|
366 | +function wpinv_sanitize_text_field($input) { |
|
367 | + return trim($input); |
|
368 | 368 | } |
369 | -add_filter( 'wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field' ); |
|
369 | +add_filter('wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field'); |
|
370 | 370 | |
371 | 371 | function wpinv_get_settings_tabs() { |
372 | 372 | $tabs = array(); |
373 | - $tabs['general'] = __( 'General', 'invoicing' ); |
|
374 | - $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' ); |
|
375 | - $tabs['taxes'] = __( 'Taxes', 'invoicing' ); |
|
376 | - $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
373 | + $tabs['general'] = __('General', 'invoicing'); |
|
374 | + $tabs['gateways'] = __('Payment Gateways', 'invoicing'); |
|
375 | + $tabs['taxes'] = __('Taxes', 'invoicing'); |
|
376 | + $tabs['emails'] = __('Emails', 'invoicing'); |
|
377 | 377 | |
378 | - if ( count( getpaid_get_integration_settings() ) > 0 ) { |
|
379 | - $tabs['integrations'] = __( 'Integrations', 'invoicing' ); |
|
378 | + if (count(getpaid_get_integration_settings()) > 0) { |
|
379 | + $tabs['integrations'] = __('Integrations', 'invoicing'); |
|
380 | 380 | } |
381 | 381 | |
382 | - $tabs['privacy'] = __( 'Privacy', 'invoicing' ); |
|
383 | - $tabs['misc'] = __( 'Misc', 'invoicing' ); |
|
384 | - $tabs['tools'] = __( 'Tools', 'invoicing' ); |
|
382 | + $tabs['privacy'] = __('Privacy', 'invoicing'); |
|
383 | + $tabs['misc'] = __('Misc', 'invoicing'); |
|
384 | + $tabs['tools'] = __('Tools', 'invoicing'); |
|
385 | 385 | |
386 | - return apply_filters( 'wpinv_settings_tabs', $tabs ); |
|
386 | + return apply_filters('wpinv_settings_tabs', $tabs); |
|
387 | 387 | } |
388 | 388 | |
389 | -function wpinv_get_settings_tab_sections( $tab = false ) { |
|
389 | +function wpinv_get_settings_tab_sections($tab = false) { |
|
390 | 390 | $tabs = false; |
391 | 391 | $sections = wpinv_get_registered_settings_sections(); |
392 | 392 | |
393 | - if( $tab && ! empty( $sections[ $tab ] ) ) { |
|
394 | - $tabs = $sections[ $tab ]; |
|
393 | + if ($tab && !empty($sections[$tab])) { |
|
394 | + $tabs = $sections[$tab]; |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | return $tabs; |
@@ -400,91 +400,91 @@ discard block |
||
400 | 400 | function wpinv_get_registered_settings_sections() { |
401 | 401 | static $sections = false; |
402 | 402 | |
403 | - if ( false !== $sections ) { |
|
403 | + if (false !== $sections) { |
|
404 | 404 | return $sections; |
405 | 405 | } |
406 | 406 | |
407 | 407 | $sections = array( |
408 | - 'general' => apply_filters( 'wpinv_settings_sections_general', array( |
|
409 | - 'main' => __( 'General Settings', 'invoicing' ), |
|
410 | - 'currency_section' => __( 'Currency Settings', 'invoicing' ), |
|
411 | - 'labels' => __( 'Label Texts', 'invoicing' ), |
|
412 | - ) ), |
|
413 | - 'gateways' => apply_filters( 'wpinv_settings_sections_gateways', array( |
|
414 | - 'main' => __( 'Gateway Settings', 'invoicing' ), |
|
415 | - ) ), |
|
416 | - 'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array( |
|
417 | - 'main' => __( 'Tax Settings', 'invoicing' ), |
|
418 | - 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
419 | - 'vat' => __( 'EU VAT Settings', 'invoicing' ) |
|
420 | - ) ), |
|
421 | - 'emails' => apply_filters( 'wpinv_settings_sections_emails', array( |
|
422 | - 'main' => __( 'Email Settings', 'invoicing' ), |
|
423 | - ) ), |
|
424 | - |
|
425 | - 'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ), |
|
426 | - |
|
427 | - 'privacy' => apply_filters( 'wpinv_settings_sections_privacy', array( |
|
428 | - 'main' => __( 'Privacy policy', 'invoicing' ), |
|
429 | - ) ), |
|
430 | - 'misc' => apply_filters( 'wpinv_settings_sections_misc', array( |
|
431 | - 'main' => __( 'Miscellaneous', 'invoicing' ), |
|
432 | - 'custom-css' => __( 'Custom CSS', 'invoicing' ), |
|
433 | - ) ), |
|
434 | - 'tools' => apply_filters( 'wpinv_settings_sections_tools', array( |
|
435 | - 'main' => __( 'Diagnostic Tools', 'invoicing' ), |
|
436 | - ) ), |
|
408 | + 'general' => apply_filters('wpinv_settings_sections_general', array( |
|
409 | + 'main' => __('General Settings', 'invoicing'), |
|
410 | + 'currency_section' => __('Currency Settings', 'invoicing'), |
|
411 | + 'labels' => __('Label Texts', 'invoicing'), |
|
412 | + )), |
|
413 | + 'gateways' => apply_filters('wpinv_settings_sections_gateways', array( |
|
414 | + 'main' => __('Gateway Settings', 'invoicing'), |
|
415 | + )), |
|
416 | + 'taxes' => apply_filters('wpinv_settings_sections_taxes', array( |
|
417 | + 'main' => __('Tax Settings', 'invoicing'), |
|
418 | + 'rates' => __('Tax Rates', 'invoicing'), |
|
419 | + 'vat' => __('EU VAT Settings', 'invoicing') |
|
420 | + )), |
|
421 | + 'emails' => apply_filters('wpinv_settings_sections_emails', array( |
|
422 | + 'main' => __('Email Settings', 'invoicing'), |
|
423 | + )), |
|
424 | + |
|
425 | + 'integrations' => wp_list_pluck(getpaid_get_integration_settings(), 'label', 'id'), |
|
426 | + |
|
427 | + 'privacy' => apply_filters('wpinv_settings_sections_privacy', array( |
|
428 | + 'main' => __('Privacy policy', 'invoicing'), |
|
429 | + )), |
|
430 | + 'misc' => apply_filters('wpinv_settings_sections_misc', array( |
|
431 | + 'main' => __('Miscellaneous', 'invoicing'), |
|
432 | + 'custom-css' => __('Custom CSS', 'invoicing'), |
|
433 | + )), |
|
434 | + 'tools' => apply_filters('wpinv_settings_sections_tools', array( |
|
435 | + 'main' => __('Diagnostic Tools', 'invoicing'), |
|
436 | + )), |
|
437 | 437 | ); |
438 | 438 | |
439 | - $sections = apply_filters( 'wpinv_settings_sections', $sections ); |
|
439 | + $sections = apply_filters('wpinv_settings_sections', $sections); |
|
440 | 440 | |
441 | 441 | return $sections; |
442 | 442 | } |
443 | 443 | |
444 | -function wpinv_get_pages( $with_slug = false, $default_label = NULL ) { |
|
444 | +function wpinv_get_pages($with_slug = false, $default_label = NULL) { |
|
445 | 445 | $pages_options = array(); |
446 | 446 | |
447 | - if( $default_label !== NULL && $default_label !== false ) { |
|
448 | - $pages_options = array( '' => $default_label ); // Blank option |
|
447 | + if ($default_label !== NULL && $default_label !== false) { |
|
448 | + $pages_options = array('' => $default_label); // Blank option |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | $pages = get_pages(); |
452 | - if ( $pages ) { |
|
453 | - foreach ( $pages as $page ) { |
|
452 | + if ($pages) { |
|
453 | + foreach ($pages as $page) { |
|
454 | 454 | $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
455 | - $pages_options[ $page->ID ] = $title; |
|
455 | + $pages_options[$page->ID] = $title; |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 | |
459 | 459 | return $pages_options; |
460 | 460 | } |
461 | 461 | |
462 | -function wpinv_header_callback( $args ) { |
|
463 | - if ( !empty( $args['desc'] ) ) { |
|
462 | +function wpinv_header_callback($args) { |
|
463 | + if (!empty($args['desc'])) { |
|
464 | 464 | echo $args['desc']; |
465 | 465 | } |
466 | 466 | } |
467 | 467 | |
468 | -function wpinv_hidden_callback( $args ) { |
|
468 | +function wpinv_hidden_callback($args) { |
|
469 | 469 | global $wpinv_options; |
470 | 470 | |
471 | - if ( isset( $args['set_value'] ) ) { |
|
471 | + if (isset($args['set_value'])) { |
|
472 | 472 | $value = $args['set_value']; |
473 | - } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
474 | - $value = $wpinv_options[ $args['id'] ]; |
|
473 | + } elseif (isset($wpinv_options[$args['id']])) { |
|
474 | + $value = $wpinv_options[$args['id']]; |
|
475 | 475 | } else { |
476 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
476 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
477 | 477 | } |
478 | 478 | |
479 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
479 | + if (isset($args['faux']) && true === $args['faux']) { |
|
480 | 480 | $args['readonly'] = true; |
481 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
481 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
482 | 482 | $name = ''; |
483 | 483 | } else { |
484 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
484 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
485 | 485 | } |
486 | 486 | |
487 | - $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
487 | + $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key($args['id']) . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '" />'; |
|
488 | 488 | |
489 | 489 | echo $html; |
490 | 490 | } |
@@ -492,61 +492,61 @@ discard block |
||
492 | 492 | /** |
493 | 493 | * Displays a checkbox settings callback. |
494 | 494 | */ |
495 | -function wpinv_checkbox_callback( $args ) { |
|
495 | +function wpinv_checkbox_callback($args) { |
|
496 | 496 | |
497 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
498 | - $std = wpinv_get_option( $args['id'], $std ); |
|
499 | - $id = esc_attr( $args['id'] ); |
|
497 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
498 | + $std = wpinv_get_option($args['id'], $std); |
|
499 | + $id = esc_attr($args['id']); |
|
500 | 500 | |
501 | - getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
501 | + getpaid_hidden_field("wpinv_settings[$id]", '0'); |
|
502 | 502 | ?> |
503 | 503 | <fieldset> |
504 | 504 | <label> |
505 | - <input id="wpinv-settings-<?php echo $id; ?>" name="wpinv_settings[<?php echo $id; ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox"> |
|
506 | - <?php echo wp_kses_post( $args['desc'] ); ?> |
|
505 | + <input id="wpinv-settings-<?php echo $id; ?>" name="wpinv_settings[<?php echo $id; ?>]" <?php checked(empty($std), false); ?> value="1" type="checkbox"> |
|
506 | + <?php echo wp_kses_post($args['desc']); ?> |
|
507 | 507 | </label> |
508 | 508 | </fieldset> |
509 | 509 | <?php |
510 | 510 | } |
511 | 511 | |
512 | -function wpinv_multicheck_callback( $args ) { |
|
512 | +function wpinv_multicheck_callback($args) { |
|
513 | 513 | |
514 | 514 | global $wpinv_options; |
515 | 515 | |
516 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
517 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
516 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
517 | + $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : ''; |
|
518 | 518 | |
519 | - if ( ! empty( $args['options'] ) ) { |
|
519 | + if (!empty($args['options'])) { |
|
520 | 520 | |
521 | - $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
522 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
521 | + $std = isset($args['std']) ? $args['std'] : array(); |
|
522 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : $std; |
|
523 | 523 | |
524 | 524 | echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
525 | - foreach( $args['options'] as $key => $option ): |
|
526 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
527 | - if ( in_array( $sanitize_key, $value ) ) { |
|
525 | + foreach ($args['options'] as $key => $option): |
|
526 | + $sanitize_key = wpinv_sanitize_key($key); |
|
527 | + if (in_array($sanitize_key, $value)) { |
|
528 | 528 | $enabled = $sanitize_key; |
529 | 529 | } else { |
530 | 530 | $enabled = NULL; |
531 | 531 | } |
532 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
533 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
532 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($sanitize_key) . '" ' . checked($sanitize_key, $enabled, false) . '/> '; |
|
533 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post($option) . '</label></div>'; |
|
534 | 534 | endforeach; |
535 | 535 | echo '</div>'; |
536 | 536 | echo '<p class="description">' . $args['desc'] . '</p>'; |
537 | 537 | } |
538 | 538 | } |
539 | 539 | |
540 | -function wpinv_payment_icons_callback( $args ) { |
|
540 | +function wpinv_payment_icons_callback($args) { |
|
541 | 541 | global $wpinv_options; |
542 | 542 | |
543 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
543 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
544 | 544 | |
545 | - if ( ! empty( $args['options'] ) ) { |
|
546 | - foreach( $args['options'] as $key => $option ) { |
|
547 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
545 | + if (!empty($args['options'])) { |
|
546 | + foreach ($args['options'] as $key => $option) { |
|
547 | + $sanitize_key = wpinv_sanitize_key($key); |
|
548 | 548 | |
549 | - if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
549 | + if (isset($wpinv_options[$args['id']][$key])) { |
|
550 | 550 | $enabled = $option; |
551 | 551 | } else { |
552 | 552 | $enabled = NULL; |
@@ -554,109 +554,109 @@ discard block |
||
554 | 554 | |
555 | 555 | echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
556 | 556 | |
557 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
557 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($option) . '" ' . checked($option, $enabled, false) . '/> '; |
|
558 | 558 | |
559 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
560 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
559 | + if (wpinv_string_is_image_url($key)) { |
|
560 | + echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
561 | 561 | } else { |
562 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
562 | + $card = strtolower(str_replace(' ', '', $option)); |
|
563 | 563 | |
564 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
565 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
564 | + if (has_filter('wpinv_accepted_payment_' . $card . '_image')) { |
|
565 | + $image = apply_filters('wpinv_accepted_payment_' . $card . '_image', ''); |
|
566 | 566 | } else { |
567 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
567 | + $image = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false); |
|
568 | 568 | $content_dir = WP_CONTENT_DIR; |
569 | 569 | |
570 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
570 | + if (function_exists('wp_normalize_path')) { |
|
571 | 571 | // Replaces backslashes with forward slashes for Windows systems |
572 | - $image = wp_normalize_path( $image ); |
|
573 | - $content_dir = wp_normalize_path( $content_dir ); |
|
572 | + $image = wp_normalize_path($image); |
|
573 | + $content_dir = wp_normalize_path($content_dir); |
|
574 | 574 | } |
575 | 575 | |
576 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
576 | + $image = str_replace($content_dir, content_url(), $image); |
|
577 | 577 | } |
578 | 578 | |
579 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
579 | + echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
580 | 580 | } |
581 | 581 | echo $option . '</label>'; |
582 | 582 | } |
583 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
583 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>'; |
|
584 | 584 | } |
585 | 585 | } |
586 | 586 | |
587 | 587 | /** |
588 | 588 | * Displays a radio settings field. |
589 | 589 | */ |
590 | -function wpinv_radio_callback( $args ) { |
|
590 | +function wpinv_radio_callback($args) { |
|
591 | 591 | |
592 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
593 | - $std = wpinv_get_option( $args['id'], $std ); |
|
592 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
593 | + $std = wpinv_get_option($args['id'], $std); |
|
594 | 594 | ?> |
595 | 595 | <fieldset> |
596 | - <ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;"> |
|
597 | - <?php foreach( $args['options'] as $key => $option ) : ?> |
|
596 | + <ul id="wpinv-settings-<?php echo esc_attr($args['id']); ?>" style="margin-top: 0;"> |
|
597 | + <?php foreach ($args['options'] as $key => $option) : ?> |
|
598 | 598 | <li> |
599 | 599 | <label> |
600 | - <input name="wpinv_settings[<?php echo esc_attr( $args['id'] ); ?>]" <?php checked( $std, $key ); ?> value="<?php echo esc_attr( $key ); ?>" type="radio"> |
|
601 | - <?php echo wp_kses_post( $option ); ?> |
|
600 | + <input name="wpinv_settings[<?php echo esc_attr($args['id']); ?>]" <?php checked($std, $key); ?> value="<?php echo esc_attr($key); ?>" type="radio"> |
|
601 | + <?php echo wp_kses_post($option); ?> |
|
602 | 602 | </label> |
603 | 603 | </li> |
604 | 604 | <?php endforeach; ?> |
605 | 605 | </ul> |
606 | 606 | </fieldset> |
607 | 607 | <?php |
608 | - getpaid_settings_description_callback( $args ); |
|
608 | + getpaid_settings_description_callback($args); |
|
609 | 609 | } |
610 | 610 | |
611 | 611 | /** |
612 | 612 | * Displays a description if available. |
613 | 613 | */ |
614 | -function getpaid_settings_description_callback( $args ) { |
|
614 | +function getpaid_settings_description_callback($args) { |
|
615 | 615 | |
616 | - if ( ! empty( $args['desc'] ) ) { |
|
617 | - $description = wp_kses_post( $args['desc'] ); |
|
616 | + if (!empty($args['desc'])) { |
|
617 | + $description = wp_kses_post($args['desc']); |
|
618 | 618 | echo "<p class='description'>$description</p>"; |
619 | 619 | } |
620 | 620 | |
621 | 621 | } |
622 | 622 | |
623 | -function wpinv_gateways_callback( $args ) { |
|
623 | +function wpinv_gateways_callback($args) { |
|
624 | 624 | |
625 | - $gateways = wpinv_get_option( 'gateways', array( 'manual' => 1 ) ); |
|
626 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
625 | + $gateways = wpinv_get_option('gateways', array('manual' => 1)); |
|
626 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
627 | 627 | |
628 | - foreach ( $args['options'] as $key => $option ) : |
|
629 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
628 | + foreach ($args['options'] as $key => $option) : |
|
629 | + $sanitize_key = wpinv_sanitize_key($key); |
|
630 | 630 | |
631 | - if ( is_array( $gateways ) && isset( $gateways[ $key ] ) ) |
|
631 | + if (is_array($gateways) && isset($gateways[$key])) |
|
632 | 632 | $enabled = '1'; |
633 | 633 | else |
634 | 634 | $enabled = null; |
635 | 635 | |
636 | - echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
637 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
636 | + echo '<input name="wpinv_settings[' . esc_attr($args['id']) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
637 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option['admin_label']) . '</label><br/>'; |
|
638 | 638 | endforeach; |
639 | 639 | } |
640 | 640 | |
641 | 641 | function wpinv_gateway_select_callback($args) { |
642 | 642 | global $wpinv_options; |
643 | 643 | |
644 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
645 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
644 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
645 | + $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : ''; |
|
646 | 646 | |
647 | - echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
647 | + echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '" >'; |
|
648 | 648 | |
649 | - foreach ( $args['options'] as $key => $option ) : |
|
650 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
651 | - $selected = selected( $key, $args['selected'], false ); |
|
649 | + foreach ($args['options'] as $key => $option) : |
|
650 | + if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) { |
|
651 | + $selected = selected($key, $args['selected'], false); |
|
652 | 652 | } else { |
653 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : ''; |
|
653 | + $selected = isset($wpinv_options[$args['id']]) ? selected($key, $wpinv_options[$args['id']], false) : ''; |
|
654 | 654 | } |
655 | - echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
655 | + echo '<option value="' . wpinv_sanitize_key($key) . '"' . $selected . '>' . esc_html($option['admin_label']) . '</option>'; |
|
656 | 656 | endforeach; |
657 | 657 | |
658 | 658 | echo '</select>'; |
659 | - echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
659 | + echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
660 | 660 | } |
661 | 661 | |
662 | 662 | /** |
@@ -665,28 +665,28 @@ discard block |
||
665 | 665 | * @param array $args |
666 | 666 | * @return string |
667 | 667 | */ |
668 | -function wpinv_settings_attrs_helper( $args ) { |
|
668 | +function wpinv_settings_attrs_helper($args) { |
|
669 | 669 | |
670 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
671 | - $id = esc_attr( $args['id'] ); |
|
672 | - $placeholder = esc_attr( $args['placeholder'] ); |
|
670 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
671 | + $id = esc_attr($args['id']); |
|
672 | + $placeholder = esc_attr($args['placeholder']); |
|
673 | 673 | |
674 | - if ( ! empty( $args['faux'] ) ) { |
|
674 | + if (!empty($args['faux'])) { |
|
675 | 675 | $args['readonly'] = true; |
676 | 676 | $name = ''; |
677 | 677 | } else { |
678 | - $value = wpinv_get_option( $args['id'], $value ); |
|
678 | + $value = wpinv_get_option($args['id'], $value); |
|
679 | 679 | $name = "wpinv_settings[$id]"; |
680 | 680 | } |
681 | 681 | |
682 | - $value = is_scalar( $value ) ? esc_attr( $value ) : ''; |
|
683 | - $class = esc_attr( $args['class'] ); |
|
684 | - $style = esc_attr( $args['style'] ); |
|
685 | - $readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"'; |
|
682 | + $value = is_scalar($value) ? esc_attr($value) : ''; |
|
683 | + $class = esc_attr($args['class']); |
|
684 | + $style = esc_attr($args['style']); |
|
685 | + $readonly = empty($args['readonly']) ? '' : 'readonly onclick="this.select()"'; |
|
686 | 686 | |
687 | 687 | $onchange = ''; |
688 | - if ( ! empty( $args['onchange'] ) ) { |
|
689 | - $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
688 | + if (!empty($args['onchange'])) { |
|
689 | + $onchange = ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly"; |
@@ -695,11 +695,11 @@ discard block |
||
695 | 695 | /** |
696 | 696 | * Displays a text input settings callback. |
697 | 697 | */ |
698 | -function wpinv_text_callback( $args ) { |
|
698 | +function wpinv_text_callback($args) { |
|
699 | 699 | |
700 | - $desc = wp_kses_post( $args['desc'] ); |
|
701 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
702 | - $attr = wpinv_settings_attrs_helper( $args ); |
|
700 | + $desc = wp_kses_post($args['desc']); |
|
701 | + $desc = empty($desc) ? '' : "<p class='description'>$desc</p>"; |
|
702 | + $attr = wpinv_settings_attrs_helper($args); |
|
703 | 703 | |
704 | 704 | ?> |
705 | 705 | <label style="width: 100%;"> |
@@ -713,14 +713,14 @@ discard block |
||
713 | 713 | /** |
714 | 714 | * Displays a number input settings callback. |
715 | 715 | */ |
716 | -function wpinv_number_callback( $args ) { |
|
716 | +function wpinv_number_callback($args) { |
|
717 | 717 | |
718 | - $desc = wp_kses_post( $args['desc'] ); |
|
719 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
720 | - $attr = wpinv_settings_attrs_helper( $args ); |
|
721 | - $max = intval( $args['max'] ); |
|
722 | - $min = intval( $args['min'] ); |
|
723 | - $step = floatval( $args['step'] ); |
|
718 | + $desc = wp_kses_post($args['desc']); |
|
719 | + $desc = empty($desc) ? '' : "<p class='description'>$desc</p>"; |
|
720 | + $attr = wpinv_settings_attrs_helper($args); |
|
721 | + $max = intval($args['max']); |
|
722 | + $min = intval($args['min']); |
|
723 | + $step = floatval($args['step']); |
|
724 | 724 | |
725 | 725 | ?> |
726 | 726 | <label style="width: 100%;"> |
@@ -731,47 +731,47 @@ discard block |
||
731 | 731 | |
732 | 732 | } |
733 | 733 | |
734 | -function wpinv_textarea_callback( $args ) { |
|
734 | +function wpinv_textarea_callback($args) { |
|
735 | 735 | global $wpinv_options; |
736 | 736 | |
737 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
737 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
738 | 738 | |
739 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
740 | - $value = $wpinv_options[ $args['id'] ]; |
|
739 | + if (isset($wpinv_options[$args['id']])) { |
|
740 | + $value = $wpinv_options[$args['id']]; |
|
741 | 741 | } else { |
742 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
742 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
743 | 743 | } |
744 | 744 | |
745 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
746 | - $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
|
745 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
746 | + $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text'; |
|
747 | 747 | |
748 | - $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
749 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
748 | + $html = '<textarea class="' . sanitize_html_class($class) . ' txtarea-' . sanitize_html_class($size) . ' wpi-' . esc_attr(sanitize_html_class($sanitize_id)) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']">' . esc_textarea(stripslashes($value)) . '</textarea>'; |
|
749 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
750 | 750 | |
751 | 751 | echo $html; |
752 | 752 | } |
753 | 753 | |
754 | -function wpinv_password_callback( $args ) { |
|
754 | +function wpinv_password_callback($args) { |
|
755 | 755 | global $wpinv_options; |
756 | 756 | |
757 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
757 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
758 | 758 | |
759 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
760 | - $value = $wpinv_options[ $args['id'] ]; |
|
759 | + if (isset($wpinv_options[$args['id']])) { |
|
760 | + $value = $wpinv_options[$args['id']]; |
|
761 | 761 | } else { |
762 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
762 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
763 | 763 | } |
764 | 764 | |
765 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
766 | - $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
767 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
765 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
766 | + $html = '<input type="password" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '"/>'; |
|
767 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
768 | 768 | |
769 | 769 | echo $html; |
770 | 770 | } |
771 | 771 | |
772 | 772 | function wpinv_missing_callback($args) { |
773 | 773 | printf( |
774 | - __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
774 | + __('The callback function used for the %s setting is missing.', 'invoicing'), |
|
775 | 775 | '<strong>' . $args['id'] . '</strong>' |
776 | 776 | ); |
777 | 777 | } |
@@ -779,20 +779,20 @@ discard block |
||
779 | 779 | /** |
780 | 780 | * Displays a number input settings callback. |
781 | 781 | */ |
782 | -function wpinv_select_callback( $args ) { |
|
782 | +function wpinv_select_callback($args) { |
|
783 | 783 | |
784 | - $desc = wp_kses_post( $args['desc'] ); |
|
785 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
786 | - $attr = wpinv_settings_attrs_helper( $args ); |
|
787 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
788 | - $value = wpinv_get_option( $args['id'], $value ); |
|
784 | + $desc = wp_kses_post($args['desc']); |
|
785 | + $desc = empty($desc) ? '' : "<p class='description'>$desc</p>"; |
|
786 | + $attr = wpinv_settings_attrs_helper($args); |
|
787 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
788 | + $value = wpinv_get_option($args['id'], $value); |
|
789 | 789 | |
790 | 790 | ?> |
791 | 791 | <label style="width: 100%;"> |
792 | 792 | <select <?php echo $attr; ?>> |
793 | - <?php foreach ( $args['options'] as $option => $name ) : ?> |
|
794 | - <option value="<?php echo esc_attr( $option ); ?>" <?php echo selected( is_array( $value ) ? in_array( "$option", $value, true ) : "$option" === $value ); ?>><?php echo wpinv_clean( $name ); ?></option> |
|
795 | - <?php endforeach;?> |
|
793 | + <?php foreach ($args['options'] as $option => $name) : ?> |
|
794 | + <option value="<?php echo esc_attr($option); ?>" <?php echo selected(is_array($value) ? in_array("$option", $value, true) : "$option" === $value); ?>><?php echo wpinv_clean($name); ?></option> |
|
795 | + <?php endforeach; ?> |
|
796 | 796 | </select> |
797 | 797 | <?php echo $desc; ?> |
798 | 798 | </label> |
@@ -800,95 +800,95 @@ discard block |
||
800 | 800 | |
801 | 801 | } |
802 | 802 | |
803 | -function wpinv_color_select_callback( $args ) { |
|
803 | +function wpinv_color_select_callback($args) { |
|
804 | 804 | global $wpinv_options; |
805 | 805 | |
806 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
806 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
807 | 807 | |
808 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
809 | - $value = $wpinv_options[ $args['id'] ]; |
|
808 | + if (isset($wpinv_options[$args['id']])) { |
|
809 | + $value = $wpinv_options[$args['id']]; |
|
810 | 810 | } else { |
811 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
811 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
812 | 812 | } |
813 | 813 | |
814 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
814 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>'; |
|
815 | 815 | |
816 | - foreach ( $args['options'] as $option => $color ) { |
|
817 | - $selected = selected( $option, $value, false ); |
|
818 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
816 | + foreach ($args['options'] as $option => $color) { |
|
817 | + $selected = selected($option, $value, false); |
|
818 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($color['label']) . '</option>'; |
|
819 | 819 | } |
820 | 820 | |
821 | 821 | $html .= '</select>'; |
822 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
822 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
823 | 823 | |
824 | 824 | echo $html; |
825 | 825 | } |
826 | 826 | |
827 | -function wpinv_rich_editor_callback( $args ) { |
|
827 | +function wpinv_rich_editor_callback($args) { |
|
828 | 828 | global $wpinv_options, $wp_version; |
829 | 829 | |
830 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
830 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
831 | 831 | |
832 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
833 | - $value = $wpinv_options[ $args['id'] ]; |
|
832 | + if (isset($wpinv_options[$args['id']])) { |
|
833 | + $value = $wpinv_options[$args['id']]; |
|
834 | 834 | |
835 | - if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
836 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
835 | + if (empty($args['allow_blank']) && empty($value)) { |
|
836 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
837 | 837 | } |
838 | 838 | } else { |
839 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
839 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
840 | 840 | } |
841 | 841 | |
842 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
842 | + $rows = isset($args['size']) ? $args['size'] : 20; |
|
843 | 843 | |
844 | 844 | $html = '<div class="getpaid-settings-editor-input">'; |
845 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
845 | + if ($wp_version >= 3.3 && function_exists('wp_editor')) { |
|
846 | 846 | ob_start(); |
847 | - wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
847 | + wp_editor(stripslashes($value), 'wpinv_settings_' . esc_attr($args['id']), array('textarea_name' => 'wpinv_settings[' . esc_attr($args['id']) . ']', 'textarea_rows' => absint($rows), 'media_buttons' => false)); |
|
848 | 848 | $html .= ob_get_clean(); |
849 | 849 | } else { |
850 | - $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
850 | + $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" class="wpi-' . esc_attr(sanitize_html_class($args['id'])) . '">' . esc_textarea(stripslashes($value)) . '</textarea>'; |
|
851 | 851 | } |
852 | 852 | |
853 | - $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
853 | + $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
854 | 854 | |
855 | 855 | echo $html; |
856 | 856 | } |
857 | 857 | |
858 | -function wpinv_upload_callback( $args ) { |
|
858 | +function wpinv_upload_callback($args) { |
|
859 | 859 | global $wpinv_options; |
860 | 860 | |
861 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
861 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
862 | 862 | |
863 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
863 | + if (isset($wpinv_options[$args['id']])) { |
|
864 | 864 | $value = $wpinv_options[$args['id']]; |
865 | 865 | } else { |
866 | 866 | $value = isset($args['std']) ? $args['std'] : ''; |
867 | 867 | } |
868 | 868 | |
869 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
870 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
871 | - $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
872 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
869 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
870 | + $html = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr(stripslashes($value)) . '"/>'; |
|
871 | + $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __('Upload File', 'invoicing') . '"/></span>'; |
|
872 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
873 | 873 | |
874 | 874 | echo $html; |
875 | 875 | } |
876 | 876 | |
877 | -function wpinv_color_callback( $args ) { |
|
877 | +function wpinv_color_callback($args) { |
|
878 | 878 | global $wpinv_options; |
879 | 879 | |
880 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
880 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
881 | 881 | |
882 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
883 | - $value = $wpinv_options[ $args['id'] ]; |
|
882 | + if (isset($wpinv_options[$args['id']])) { |
|
883 | + $value = $wpinv_options[$args['id']]; |
|
884 | 884 | } else { |
885 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
885 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
886 | 886 | } |
887 | 887 | |
888 | - $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
888 | + $default = isset($args['std']) ? $args['std'] : ''; |
|
889 | 889 | |
890 | - $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
891 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
890 | + $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '" data-default-color="' . esc_attr($default) . '" />'; |
|
891 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
892 | 892 | |
893 | 893 | echo $html; |
894 | 894 | } |
@@ -896,9 +896,9 @@ discard block |
||
896 | 896 | function wpinv_country_states_callback($args) { |
897 | 897 | global $wpinv_options; |
898 | 898 | |
899 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
899 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
900 | 900 | |
901 | - if ( isset( $args['placeholder'] ) ) { |
|
901 | + if (isset($args['placeholder'])) { |
|
902 | 902 | $placeholder = $args['placeholder']; |
903 | 903 | } else { |
904 | 904 | $placeholder = ''; |
@@ -906,16 +906,16 @@ discard block |
||
906 | 906 | |
907 | 907 | $states = wpinv_get_country_states(); |
908 | 908 | |
909 | - $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
910 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
909 | + $class = empty($states) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
910 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"' . $class . 'data-placeholder="' . esc_html($placeholder) . '"/>'; |
|
911 | 911 | |
912 | - foreach ( $states as $option => $name ) { |
|
913 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
914 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
912 | + foreach ($states as $option => $name) { |
|
913 | + $selected = isset($wpinv_options[$args['id']]) ? selected($option, $wpinv_options[$args['id']], false) : ''; |
|
914 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>'; |
|
915 | 915 | } |
916 | 916 | |
917 | 917 | $html .= '</select>'; |
918 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
918 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
919 | 919 | |
920 | 920 | echo $html; |
921 | 921 | } |
@@ -930,7 +930,7 @@ discard block |
||
930 | 930 | </tr> |
931 | 931 | <tr class="bsui"> |
932 | 932 | <td colspan="2" class="p-0"> |
933 | - <?php include plugin_dir_path( __FILE__ ) . 'views/html-tax-rates-edit.php'; ?> |
|
933 | + <?php include plugin_dir_path(__FILE__) . 'views/html-tax-rates-edit.php'; ?> |
|
934 | 934 | |
935 | 935 | <?php |
936 | 936 | |
@@ -939,14 +939,14 @@ discard block |
||
939 | 939 | /** |
940 | 940 | * Displays a tax rate' edit row. |
941 | 941 | */ |
942 | -function wpinv_tax_rate_callback( $tax_rate, $key, $echo = true ) { |
|
942 | +function wpinv_tax_rate_callback($tax_rate, $key, $echo = true) { |
|
943 | 943 | ob_start(); |
944 | 944 | |
945 | - $key = sanitize_key( $key ); |
|
946 | - $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
947 | - include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
945 | + $key = sanitize_key($key); |
|
946 | + $tax_rate['reduced_rate'] = empty($tax_rate['reduced_rate']) ? 0 : $tax_rate['reduced_rate']; |
|
947 | + include plugin_dir_path(__FILE__) . 'views/html-tax-rate-edit.php'; |
|
948 | 948 | |
949 | - if ( $echo ) { |
|
949 | + if ($echo) { |
|
950 | 950 | echo ob_get_clean(); |
951 | 951 | } else { |
952 | 952 | return ob_get_clean(); |
@@ -958,133 +958,133 @@ discard block |
||
958 | 958 | ob_start(); ?> |
959 | 959 | </td><tr> |
960 | 960 | <td colspan="2" class="wpinv_tools_tdbox"> |
961 | - <?php if ( $args['desc'] ) { ?><p><?php echo $args['desc']; ?></p><?php } ?> |
|
962 | - <?php do_action( 'wpinv_tools_before' ); ?> |
|
961 | + <?php if ($args['desc']) { ?><p><?php echo $args['desc']; ?></p><?php } ?> |
|
962 | + <?php do_action('wpinv_tools_before'); ?> |
|
963 | 963 | <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts"> |
964 | 964 | <thead> |
965 | 965 | <tr> |
966 | - <th scope="col" class="wpinv-th-tool"><?php _e( 'Tool', 'invoicing' ); ?></th> |
|
967 | - <th scope="col" class="wpinv-th-desc"><?php _e( 'Description', 'invoicing' ); ?></th> |
|
968 | - <th scope="col" class="wpinv-th-action"><?php _e( 'Action', 'invoicing' ); ?></th> |
|
966 | + <th scope="col" class="wpinv-th-tool"><?php _e('Tool', 'invoicing'); ?></th> |
|
967 | + <th scope="col" class="wpinv-th-desc"><?php _e('Description', 'invoicing'); ?></th> |
|
968 | + <th scope="col" class="wpinv-th-action"><?php _e('Action', 'invoicing'); ?></th> |
|
969 | 969 | </tr> |
970 | 970 | </thead> |
971 | 971 | |
972 | 972 | <tbody> |
973 | 973 | <tr> |
974 | - <td><?php _e( 'Check Pages', 'invoicing' );?></td> |
|
974 | + <td><?php _e('Check Pages', 'invoicing'); ?></td> |
|
975 | 975 | <td> |
976 | - <small><?php _e( 'Creates any missing GetPaid pages.', 'invoicing' ); ?></small> |
|
976 | + <small><?php _e('Creates any missing GetPaid pages.', 'invoicing'); ?></small> |
|
977 | 977 | </td> |
978 | 978 | <td> |
979 | 979 | <a href="<?php |
980 | 980 | echo esc_url( |
981 | 981 | wp_nonce_url( |
982 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
982 | + add_query_arg('getpaid-admin-action', 'create_missing_pages'), |
|
983 | 983 | 'getpaid-nonce', |
984 | 984 | 'getpaid-nonce' |
985 | 985 | ) |
986 | 986 | ); |
987 | - ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
987 | + ?>" class="button button-primary"><?php _e('Run', 'invoicing'); ?></a> |
|
988 | 988 | </td> |
989 | 989 | </tr> |
990 | 990 | <tr> |
991 | - <td><?php _e( 'Create Database Tables', 'invoicing' );?></td> |
|
991 | + <td><?php _e('Create Database Tables', 'invoicing'); ?></td> |
|
992 | 992 | <td> |
993 | - <small><?php _e( 'Run this tool to create any missing database tables.', 'invoicing' ); ?></small> |
|
993 | + <small><?php _e('Run this tool to create any missing database tables.', 'invoicing'); ?></small> |
|
994 | 994 | </td> |
995 | 995 | <td> |
996 | 996 | <a href="<?php |
997 | 997 | echo esc_url( |
998 | 998 | wp_nonce_url( |
999 | - add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
999 | + add_query_arg('getpaid-admin-action', 'create_missing_tables'), |
|
1000 | 1000 | 'getpaid-nonce', |
1001 | 1001 | 'getpaid-nonce' |
1002 | 1002 | ) |
1003 | 1003 | ); |
1004 | - ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
1004 | + ?>" class="button button-primary"><?php _e('Run', 'invoicing'); ?></a> |
|
1005 | 1005 | </td> |
1006 | 1006 | </tr> |
1007 | 1007 | <tr> |
1008 | - <td><?php _e( 'Migrate old invoices', 'invoicing' );?></td> |
|
1008 | + <td><?php _e('Migrate old invoices', 'invoicing'); ?></td> |
|
1009 | 1009 | <td> |
1010 | - <small><?php _e( 'If your old invoices were not migrated after updating from Invoicing to GetPaid, you can use this tool to migrate them.', 'invoicing' ); ?></small> |
|
1010 | + <small><?php _e('If your old invoices were not migrated after updating from Invoicing to GetPaid, you can use this tool to migrate them.', 'invoicing'); ?></small> |
|
1011 | 1011 | </td> |
1012 | 1012 | <td> |
1013 | 1013 | <a href="<?php |
1014 | 1014 | echo esc_url( |
1015 | 1015 | wp_nonce_url( |
1016 | - add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ), |
|
1016 | + add_query_arg('getpaid-admin-action', 'migrate_old_invoices'), |
|
1017 | 1017 | 'getpaid-nonce', |
1018 | 1018 | 'getpaid-nonce' |
1019 | 1019 | ) |
1020 | 1020 | ); |
1021 | - ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
1021 | + ?>" class="button button-primary"><?php _e('Run', 'invoicing'); ?></a> |
|
1022 | 1022 | </td> |
1023 | 1023 | </tr> |
1024 | - <?php do_action( 'wpinv_tools_row' ); ?> |
|
1024 | + <?php do_action('wpinv_tools_row'); ?> |
|
1025 | 1025 | </tbody> |
1026 | 1026 | </table> |
1027 | - <?php do_action( 'wpinv_tools_after' ); ?> |
|
1027 | + <?php do_action('wpinv_tools_after'); ?> |
|
1028 | 1028 | <?php |
1029 | 1029 | echo ob_get_clean(); |
1030 | 1030 | } |
1031 | 1031 | |
1032 | -function wpinv_descriptive_text_callback( $args ) { |
|
1033 | - echo wp_kses_post( $args['desc'] ); |
|
1032 | +function wpinv_descriptive_text_callback($args) { |
|
1033 | + echo wp_kses_post($args['desc']); |
|
1034 | 1034 | } |
1035 | 1035 | |
1036 | -function wpinv_raw_html_callback( $args ) { |
|
1036 | +function wpinv_raw_html_callback($args) { |
|
1037 | 1037 | echo $args['desc']; |
1038 | 1038 | } |
1039 | 1039 | |
1040 | -function wpinv_hook_callback( $args ) { |
|
1041 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
1040 | +function wpinv_hook_callback($args) { |
|
1041 | + do_action('wpinv_' . $args['id'], $args); |
|
1042 | 1042 | } |
1043 | 1043 | |
1044 | 1044 | function wpinv_set_settings_cap() { |
1045 | 1045 | return wpinv_get_capability(); |
1046 | 1046 | } |
1047 | -add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
|
1047 | +add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap'); |
|
1048 | 1048 | |
1049 | -function wpinv_settings_sanitize_input( $value, $key ) { |
|
1049 | +function wpinv_settings_sanitize_input($value, $key) { |
|
1050 | 1050 | |
1051 | - if ( $key == 'tax_rate' ) { |
|
1052 | - $value = wpinv_sanitize_amount( $value ); |
|
1051 | + if ($key == 'tax_rate') { |
|
1052 | + $value = wpinv_sanitize_amount($value); |
|
1053 | 1053 | $value = $value >= 100 ? 99 : $value; |
1054 | 1054 | } |
1055 | 1055 | |
1056 | 1056 | return $value; |
1057 | 1057 | } |
1058 | -add_filter( 'wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2 ); |
|
1058 | +add_filter('wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2); |
|
1059 | 1059 | |
1060 | -function wpinv_on_update_settings( $old_value, $value, $option ) { |
|
1061 | - $old = !empty( $old_value['remove_data_on_unistall'] ) ? 1 : ''; |
|
1062 | - $new = !empty( $value['remove_data_on_unistall'] ) ? 1 : ''; |
|
1060 | +function wpinv_on_update_settings($old_value, $value, $option) { |
|
1061 | + $old = !empty($old_value['remove_data_on_unistall']) ? 1 : ''; |
|
1062 | + $new = !empty($value['remove_data_on_unistall']) ? 1 : ''; |
|
1063 | 1063 | |
1064 | - if ( $old != $new ) { |
|
1065 | - update_option( 'wpinv_remove_data_on_invoice_unistall', $new ); |
|
1064 | + if ($old != $new) { |
|
1065 | + update_option('wpinv_remove_data_on_invoice_unistall', $new); |
|
1066 | 1066 | } |
1067 | 1067 | } |
1068 | -add_action( 'update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3 ); |
|
1069 | -add_action( 'wpinv_settings_tab_bottom_emails_new_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1070 | -add_action( 'wpinv_settings_tab_bottom_emails_cancelled_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1071 | -add_action( 'wpinv_settings_tab_bottom_emails_failed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1072 | -add_action( 'wpinv_settings_tab_bottom_emails_onhold_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1073 | -add_action( 'wpinv_settings_tab_bottom_emails_processing_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1074 | -add_action( 'wpinv_settings_tab_bottom_emails_completed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1075 | -add_action( 'wpinv_settings_tab_bottom_emails_refunded_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1076 | -add_action( 'wpinv_settings_tab_bottom_emails_user_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1077 | -add_action( 'wpinv_settings_tab_bottom_emails_user_note', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1078 | -add_action( 'wpinv_settings_tab_bottom_emails_overdue', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1079 | - |
|
1080 | -function wpinv_settings_tab_bottom_emails( $active_tab, $section ) { |
|
1068 | +add_action('update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3); |
|
1069 | +add_action('wpinv_settings_tab_bottom_emails_new_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1070 | +add_action('wpinv_settings_tab_bottom_emails_cancelled_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1071 | +add_action('wpinv_settings_tab_bottom_emails_failed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1072 | +add_action('wpinv_settings_tab_bottom_emails_onhold_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1073 | +add_action('wpinv_settings_tab_bottom_emails_processing_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1074 | +add_action('wpinv_settings_tab_bottom_emails_completed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1075 | +add_action('wpinv_settings_tab_bottom_emails_refunded_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1076 | +add_action('wpinv_settings_tab_bottom_emails_user_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1077 | +add_action('wpinv_settings_tab_bottom_emails_user_note', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1078 | +add_action('wpinv_settings_tab_bottom_emails_overdue', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1079 | + |
|
1080 | +function wpinv_settings_tab_bottom_emails($active_tab, $section) { |
|
1081 | 1081 | ?> |
1082 | 1082 | <div class="wpinv-email-wc-row "> |
1083 | 1083 | <div class="wpinv-email-wc-td"> |
1084 | - <h3 class="wpinv-email-wc-title"><?php echo apply_filters( 'wpinv_settings_email_wildcards_title', __( 'Wildcards For Emails', 'invoicing' ) ); ?></h3> |
|
1084 | + <h3 class="wpinv-email-wc-title"><?php echo apply_filters('wpinv_settings_email_wildcards_title', __('Wildcards For Emails', 'invoicing')); ?></h3> |
|
1085 | 1085 | <p class="wpinv-email-wc-description"> |
1086 | 1086 | <?php |
1087 | - $description = __( 'The following wildcards can be used in email subjects, heading and content:<br> |
|
1087 | + $description = __('The following wildcards can be used in email subjects, heading and content:<br> |
|
1088 | 1088 | <strong>{site_title} :</strong> Site Title<br> |
1089 | 1089 | <strong>{name} :</strong> Customer\'s full name<br> |
1090 | 1090 | <strong>{first_name} :</strong> Customer\'s first name<br> |
@@ -1098,7 +1098,7 @@ discard block |
||
1098 | 1098 | <strong>{invoice_due_date} :</strong> The date the invoice is due<br> |
1099 | 1099 | <strong>{date} :</strong> Today\'s date.<br> |
1100 | 1100 | <strong>{is_was} :</strong> If due date of invoice is past, displays "was" otherwise displays "is"<br> |
1101 | - <strong>{invoice_label} :</strong> Invoices/quotes singular name. Ex: Invoice/Quote<br>', 'invoicing' ); |
|
1101 | + <strong>{invoice_label} :</strong> Invoices/quotes singular name. Ex: Invoice/Quote<br>', 'invoicing'); |
|
1102 | 1102 | echo apply_filters('wpinv_settings_email_wildcards_description', $description, $active_tab, $section); |
1103 | 1103 | ?> |
1104 | 1104 | </p> |
@@ -15,319 +15,319 @@ |
||
15 | 15 | class GetPaid_Post_Types { |
16 | 16 | |
17 | 17 | /** |
18 | - * Hook in methods. |
|
19 | - */ |
|
20 | - public function __construct() { |
|
21 | - add_action( 'init', array( __CLASS__, 'register_post_types' ), 1 ); |
|
22 | - add_action( 'init', array( __CLASS__, 'register_post_status' ), 4 ); |
|
23 | - add_action( 'getpaid_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) ); |
|
24 | - add_action( 'getpaid_after_register_post_types', array( __CLASS__, 'maybe_flush_rewrite_rules' ) ); |
|
25 | - } |
|
18 | + * Hook in methods. |
|
19 | + */ |
|
20 | + public function __construct() { |
|
21 | + add_action( 'init', array( __CLASS__, 'register_post_types' ), 1 ); |
|
22 | + add_action( 'init', array( __CLASS__, 'register_post_status' ), 4 ); |
|
23 | + add_action( 'getpaid_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) ); |
|
24 | + add_action( 'getpaid_after_register_post_types', array( __CLASS__, 'maybe_flush_rewrite_rules' ) ); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * Register core post types. |
|
29 | - */ |
|
30 | - public static function register_post_types() { |
|
27 | + /** |
|
28 | + * Register core post types. |
|
29 | + */ |
|
30 | + public static function register_post_types() { |
|
31 | 31 | |
32 | - if ( ! is_blog_installed() || post_type_exists( 'wpi_item' ) ) { |
|
33 | - return; |
|
34 | - } |
|
32 | + if ( ! is_blog_installed() || post_type_exists( 'wpi_item' ) ) { |
|
33 | + return; |
|
34 | + } |
|
35 | 35 | |
36 | - // Fires before registering post types. |
|
37 | - do_action( 'getpaid_register_post_types' ); |
|
36 | + // Fires before registering post types. |
|
37 | + do_action( 'getpaid_register_post_types' ); |
|
38 | 38 | |
39 | - // Register item post type. |
|
40 | - register_post_type( |
|
41 | - 'wpi_item', |
|
42 | - apply_filters( |
|
43 | - 'wpinv_register_post_type_invoice_item', |
|
44 | - array( |
|
45 | - 'labels' => array( |
|
46 | - 'name' => _x( 'Items', 'post type general name', 'invoicing' ), |
|
47 | - 'singular_name' => _x( 'Item', 'post type singular name', 'invoicing' ), |
|
48 | - 'menu_name' => _x( 'Items', 'admin menu', 'invoicing' ), |
|
49 | - 'name_admin_bar' => _x( 'Item', 'add new on admin bar', 'invoicing' ), |
|
50 | - 'add_new' => _x( 'Add New', 'Item', 'invoicing' ), |
|
51 | - 'add_new_item' => __( 'Add New Item', 'invoicing' ), |
|
52 | - 'new_item' => __( 'New Item', 'invoicing' ), |
|
53 | - 'edit_item' => __( 'Edit Item', 'invoicing' ), |
|
54 | - 'view_item' => __( 'View Item', 'invoicing' ), |
|
55 | - 'all_items' => __( 'Items', 'invoicing' ), |
|
56 | - 'search_items' => __( 'Search items', 'invoicing' ), |
|
57 | - 'parent_item_colon' => __( 'Parent item:', 'invoicing' ), |
|
58 | - 'not_found' => __( 'No items found.', 'invoicing' ), |
|
59 | - 'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' ) |
|
60 | - ), |
|
61 | - 'description' => __( 'This is where you can add new invoice items.', 'invoicing' ), |
|
62 | - 'public' => false, |
|
63 | - 'has_archive' => false, |
|
64 | - '_builtin' => false, |
|
65 | - 'show_ui' => true, |
|
66 | - 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
67 | - 'show_in_nav_menus' => false, |
|
68 | - 'supports' => array( 'title', 'excerpt', 'thumbnail' ), |
|
69 | - 'rewrite' => false, |
|
70 | - 'query_var' => false, |
|
71 | - 'map_meta_cap' => true, |
|
72 | - 'show_in_admin_bar' => true, |
|
73 | - 'can_export' => true, |
|
74 | - ) |
|
75 | - ) |
|
76 | - ); |
|
39 | + // Register item post type. |
|
40 | + register_post_type( |
|
41 | + 'wpi_item', |
|
42 | + apply_filters( |
|
43 | + 'wpinv_register_post_type_invoice_item', |
|
44 | + array( |
|
45 | + 'labels' => array( |
|
46 | + 'name' => _x( 'Items', 'post type general name', 'invoicing' ), |
|
47 | + 'singular_name' => _x( 'Item', 'post type singular name', 'invoicing' ), |
|
48 | + 'menu_name' => _x( 'Items', 'admin menu', 'invoicing' ), |
|
49 | + 'name_admin_bar' => _x( 'Item', 'add new on admin bar', 'invoicing' ), |
|
50 | + 'add_new' => _x( 'Add New', 'Item', 'invoicing' ), |
|
51 | + 'add_new_item' => __( 'Add New Item', 'invoicing' ), |
|
52 | + 'new_item' => __( 'New Item', 'invoicing' ), |
|
53 | + 'edit_item' => __( 'Edit Item', 'invoicing' ), |
|
54 | + 'view_item' => __( 'View Item', 'invoicing' ), |
|
55 | + 'all_items' => __( 'Items', 'invoicing' ), |
|
56 | + 'search_items' => __( 'Search items', 'invoicing' ), |
|
57 | + 'parent_item_colon' => __( 'Parent item:', 'invoicing' ), |
|
58 | + 'not_found' => __( 'No items found.', 'invoicing' ), |
|
59 | + 'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' ) |
|
60 | + ), |
|
61 | + 'description' => __( 'This is where you can add new invoice items.', 'invoicing' ), |
|
62 | + 'public' => false, |
|
63 | + 'has_archive' => false, |
|
64 | + '_builtin' => false, |
|
65 | + 'show_ui' => true, |
|
66 | + 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
67 | + 'show_in_nav_menus' => false, |
|
68 | + 'supports' => array( 'title', 'excerpt', 'thumbnail' ), |
|
69 | + 'rewrite' => false, |
|
70 | + 'query_var' => false, |
|
71 | + 'map_meta_cap' => true, |
|
72 | + 'show_in_admin_bar' => true, |
|
73 | + 'can_export' => true, |
|
74 | + ) |
|
75 | + ) |
|
76 | + ); |
|
77 | 77 | |
78 | - // Register payment form post type. |
|
79 | - register_post_type( |
|
80 | - 'wpi_payment_form', |
|
81 | - apply_filters( |
|
82 | - 'wpinv_register_post_type_payment_form', |
|
83 | - array( |
|
84 | - 'labels' => array( |
|
85 | - 'name' => _x( 'Payment Forms', 'post type general name', 'invoicing' ), |
|
86 | - 'singular_name' => _x( 'Payment Form', 'post type singular name', 'invoicing' ), |
|
87 | - 'menu_name' => _x( 'Payment Forms', 'admin menu', 'invoicing' ), |
|
88 | - 'name_admin_bar' => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ), |
|
89 | - 'add_new' => _x( 'Add New', 'Payment Form', 'invoicing' ), |
|
90 | - 'add_new_item' => __( 'Add New Payment Form', 'invoicing' ), |
|
91 | - 'new_item' => __( 'New Payment Form', 'invoicing' ), |
|
92 | - 'edit_item' => __( 'Edit Payment Form', 'invoicing' ), |
|
93 | - 'view_item' => __( 'View Payment Form', 'invoicing' ), |
|
94 | - 'all_items' => __( 'Payment Forms', 'invoicing' ), |
|
95 | - 'search_items' => __( 'Search Payment Forms', 'invoicing' ), |
|
96 | - 'parent_item_colon' => __( 'Parent Payment Forms:', 'invoicing' ), |
|
97 | - 'not_found' => __( 'No payment forms found.', 'invoicing' ), |
|
98 | - 'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' ) |
|
99 | - ), |
|
100 | - 'description' => __( 'Add new payment forms.', 'invoicing' ), |
|
101 | - 'public' => false, |
|
102 | - 'show_ui' => true, |
|
103 | - 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : true, |
|
104 | - 'show_in_nav_menus' => false, |
|
105 | - 'query_var' => false, |
|
106 | - 'rewrite' => true, |
|
107 | - 'map_meta_cap' => true, |
|
108 | - 'has_archive' => false, |
|
109 | - 'hierarchical' => false, |
|
110 | - 'menu_position' => null, |
|
111 | - 'supports' => array( 'title' ), |
|
112 | - 'menu_icon' => 'dashicons-media-form', |
|
113 | - ) |
|
114 | - ) |
|
115 | - ); |
|
78 | + // Register payment form post type. |
|
79 | + register_post_type( |
|
80 | + 'wpi_payment_form', |
|
81 | + apply_filters( |
|
82 | + 'wpinv_register_post_type_payment_form', |
|
83 | + array( |
|
84 | + 'labels' => array( |
|
85 | + 'name' => _x( 'Payment Forms', 'post type general name', 'invoicing' ), |
|
86 | + 'singular_name' => _x( 'Payment Form', 'post type singular name', 'invoicing' ), |
|
87 | + 'menu_name' => _x( 'Payment Forms', 'admin menu', 'invoicing' ), |
|
88 | + 'name_admin_bar' => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ), |
|
89 | + 'add_new' => _x( 'Add New', 'Payment Form', 'invoicing' ), |
|
90 | + 'add_new_item' => __( 'Add New Payment Form', 'invoicing' ), |
|
91 | + 'new_item' => __( 'New Payment Form', 'invoicing' ), |
|
92 | + 'edit_item' => __( 'Edit Payment Form', 'invoicing' ), |
|
93 | + 'view_item' => __( 'View Payment Form', 'invoicing' ), |
|
94 | + 'all_items' => __( 'Payment Forms', 'invoicing' ), |
|
95 | + 'search_items' => __( 'Search Payment Forms', 'invoicing' ), |
|
96 | + 'parent_item_colon' => __( 'Parent Payment Forms:', 'invoicing' ), |
|
97 | + 'not_found' => __( 'No payment forms found.', 'invoicing' ), |
|
98 | + 'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' ) |
|
99 | + ), |
|
100 | + 'description' => __( 'Add new payment forms.', 'invoicing' ), |
|
101 | + 'public' => false, |
|
102 | + 'show_ui' => true, |
|
103 | + 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : true, |
|
104 | + 'show_in_nav_menus' => false, |
|
105 | + 'query_var' => false, |
|
106 | + 'rewrite' => true, |
|
107 | + 'map_meta_cap' => true, |
|
108 | + 'has_archive' => false, |
|
109 | + 'hierarchical' => false, |
|
110 | + 'menu_position' => null, |
|
111 | + 'supports' => array( 'title' ), |
|
112 | + 'menu_icon' => 'dashicons-media-form', |
|
113 | + ) |
|
114 | + ) |
|
115 | + ); |
|
116 | 116 | |
117 | - // Register invoice post type. |
|
118 | - register_post_type( |
|
119 | - 'wpi_invoice', |
|
120 | - apply_filters( |
|
121 | - 'wpinv_register_post_type_invoice', |
|
122 | - array( |
|
123 | - 'labels' => array( |
|
124 | - 'name' => __( 'Invoices', 'invoicing' ), |
|
125 | - 'singular_name' => __( 'Invoice', 'invoicing' ), |
|
126 | - 'all_items' => __( 'Invoices', 'invoicing' ), |
|
127 | - 'menu_name' => _x( 'Invoices', 'Admin menu name', 'invoicing' ), |
|
128 | - 'add_new' => __( 'Add New', 'invoicing' ), |
|
129 | - 'add_new_item' => __( 'Add new invoice', 'invoicing' ), |
|
130 | - 'edit' => __( 'Edit', 'invoicing' ), |
|
131 | - 'edit_item' => __( 'Edit invoice', 'invoicing' ), |
|
132 | - 'new_item' => __( 'New invoice', 'invoicing' ), |
|
133 | - 'view_item' => __( 'View invoice', 'invoicing' ), |
|
134 | - 'view_items' => __( 'View Invoices', 'invoicing' ), |
|
135 | - 'search_items' => __( 'Search invoices', 'invoicing' ), |
|
136 | - 'not_found' => __( 'No invoices found', 'invoicing' ), |
|
137 | - 'not_found_in_trash' => __( 'No invoices found in trash', 'invoicing' ), |
|
138 | - 'parent' => __( 'Parent invoice', 'invoicing' ), |
|
139 | - 'featured_image' => __( 'Invoice image', 'invoicing' ), |
|
140 | - 'set_featured_image' => __( 'Set invoice image', 'invoicing' ), |
|
141 | - 'remove_featured_image' => __( 'Remove invoice image', 'invoicing' ), |
|
142 | - 'use_featured_image' => __( 'Use as invoice image', 'invoicing' ), |
|
143 | - 'insert_into_item' => __( 'Insert into invoice', 'invoicing' ), |
|
144 | - 'uploaded_to_this_item' => __( 'Uploaded to this invoice', 'invoicing' ), |
|
145 | - 'filter_items_list' => __( 'Filter invoices', 'invoicing' ), |
|
146 | - 'items_list_navigation' => __( 'Invoices navigation', 'invoicing' ), |
|
147 | - 'items_list' => __( 'Invoices list', 'invoicing' ), |
|
148 | - ), |
|
149 | - 'description' => __( 'This is where invoices are stored.', 'invoicing' ), |
|
150 | - 'public' => true, |
|
151 | - 'has_archive' => false, |
|
152 | - 'publicly_queryable' => true, |
|
153 | - 'exclude_from_search' => true, |
|
154 | - 'show_ui' => true, |
|
155 | - 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
156 | - 'show_in_nav_menus' => false, |
|
157 | - 'supports' => array( 'title', 'author', 'excerpt' ), |
|
158 | - 'rewrite' => array( |
|
159 | - 'slug' => 'invoice', |
|
160 | - 'with_front' => false, |
|
161 | - ), |
|
162 | - 'query_var' => false, |
|
163 | - 'map_meta_cap' => true, |
|
164 | - 'show_in_admin_bar' => true, |
|
165 | - 'can_export' => true, |
|
166 | - 'hierarchical' => false, |
|
167 | - 'menu_position' => null, |
|
168 | - 'menu_icon' => 'dashicons-media-spreadsheet', |
|
169 | - ) |
|
170 | - ) |
|
171 | - ); |
|
117 | + // Register invoice post type. |
|
118 | + register_post_type( |
|
119 | + 'wpi_invoice', |
|
120 | + apply_filters( |
|
121 | + 'wpinv_register_post_type_invoice', |
|
122 | + array( |
|
123 | + 'labels' => array( |
|
124 | + 'name' => __( 'Invoices', 'invoicing' ), |
|
125 | + 'singular_name' => __( 'Invoice', 'invoicing' ), |
|
126 | + 'all_items' => __( 'Invoices', 'invoicing' ), |
|
127 | + 'menu_name' => _x( 'Invoices', 'Admin menu name', 'invoicing' ), |
|
128 | + 'add_new' => __( 'Add New', 'invoicing' ), |
|
129 | + 'add_new_item' => __( 'Add new invoice', 'invoicing' ), |
|
130 | + 'edit' => __( 'Edit', 'invoicing' ), |
|
131 | + 'edit_item' => __( 'Edit invoice', 'invoicing' ), |
|
132 | + 'new_item' => __( 'New invoice', 'invoicing' ), |
|
133 | + 'view_item' => __( 'View invoice', 'invoicing' ), |
|
134 | + 'view_items' => __( 'View Invoices', 'invoicing' ), |
|
135 | + 'search_items' => __( 'Search invoices', 'invoicing' ), |
|
136 | + 'not_found' => __( 'No invoices found', 'invoicing' ), |
|
137 | + 'not_found_in_trash' => __( 'No invoices found in trash', 'invoicing' ), |
|
138 | + 'parent' => __( 'Parent invoice', 'invoicing' ), |
|
139 | + 'featured_image' => __( 'Invoice image', 'invoicing' ), |
|
140 | + 'set_featured_image' => __( 'Set invoice image', 'invoicing' ), |
|
141 | + 'remove_featured_image' => __( 'Remove invoice image', 'invoicing' ), |
|
142 | + 'use_featured_image' => __( 'Use as invoice image', 'invoicing' ), |
|
143 | + 'insert_into_item' => __( 'Insert into invoice', 'invoicing' ), |
|
144 | + 'uploaded_to_this_item' => __( 'Uploaded to this invoice', 'invoicing' ), |
|
145 | + 'filter_items_list' => __( 'Filter invoices', 'invoicing' ), |
|
146 | + 'items_list_navigation' => __( 'Invoices navigation', 'invoicing' ), |
|
147 | + 'items_list' => __( 'Invoices list', 'invoicing' ), |
|
148 | + ), |
|
149 | + 'description' => __( 'This is where invoices are stored.', 'invoicing' ), |
|
150 | + 'public' => true, |
|
151 | + 'has_archive' => false, |
|
152 | + 'publicly_queryable' => true, |
|
153 | + 'exclude_from_search' => true, |
|
154 | + 'show_ui' => true, |
|
155 | + 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
156 | + 'show_in_nav_menus' => false, |
|
157 | + 'supports' => array( 'title', 'author', 'excerpt' ), |
|
158 | + 'rewrite' => array( |
|
159 | + 'slug' => 'invoice', |
|
160 | + 'with_front' => false, |
|
161 | + ), |
|
162 | + 'query_var' => false, |
|
163 | + 'map_meta_cap' => true, |
|
164 | + 'show_in_admin_bar' => true, |
|
165 | + 'can_export' => true, |
|
166 | + 'hierarchical' => false, |
|
167 | + 'menu_position' => null, |
|
168 | + 'menu_icon' => 'dashicons-media-spreadsheet', |
|
169 | + ) |
|
170 | + ) |
|
171 | + ); |
|
172 | 172 | |
173 | - // Register discount post type. |
|
174 | - register_post_type( |
|
175 | - 'wpi_discount', |
|
176 | - apply_filters( |
|
177 | - 'wpinv_register_post_type_discount', |
|
178 | - array( |
|
179 | - 'labels' => array( |
|
180 | - 'name' => __( 'Discounts', 'invoicing' ), |
|
181 | - 'singular_name' => __( 'Discount', 'invoicing' ), |
|
182 | - 'all_items' => __( 'Discounts', 'invoicing' ), |
|
183 | - 'menu_name' => _x( 'Discounts', 'Admin menu name', 'invoicing' ), |
|
184 | - 'add_new' => __( 'Add New', 'invoicing' ), |
|
185 | - 'add_new_item' => __( 'Add new discount', 'invoicing' ), |
|
186 | - 'edit' => __( 'Edit', 'invoicing' ), |
|
187 | - 'edit_item' => __( 'Edit discount', 'invoicing' ), |
|
188 | - 'new_item' => __( 'New discount', 'invoicing' ), |
|
189 | - 'view_item' => __( 'View discount', 'invoicing' ), |
|
190 | - 'view_items' => __( 'View Discounts', 'invoicing' ), |
|
191 | - 'search_items' => __( 'Search discounts', 'invoicing' ), |
|
192 | - 'not_found' => __( 'No discounts found', 'invoicing' ), |
|
193 | - 'not_found_in_trash' => __( 'No discounts found in trash', 'invoicing' ), |
|
194 | - 'parent' => __( 'Parent discount', 'invoicing' ), |
|
195 | - 'featured_image' => __( 'Discount image', 'invoicing' ), |
|
196 | - 'set_featured_image' => __( 'Set discount image', 'invoicing' ), |
|
197 | - 'remove_featured_image' => __( 'Remove discount image', 'invoicing' ), |
|
198 | - 'use_featured_image' => __( 'Use as discount image', 'invoicing' ), |
|
199 | - 'insert_into_item' => __( 'Insert into discount', 'invoicing' ), |
|
200 | - 'uploaded_to_this_item' => __( 'Uploaded to this discount', 'invoicing' ), |
|
201 | - 'filter_items_list' => __( 'Filter discounts', 'invoicing' ), |
|
202 | - 'items_list_navigation' => __( 'Discount navigation', 'invoicing' ), |
|
203 | - 'items_list' => __( 'Discounts list', 'invoicing' ), |
|
204 | - ), |
|
205 | - 'description' => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ), |
|
206 | - 'public' => false, |
|
207 | - 'can_export' => true, |
|
208 | - '_builtin' => false, |
|
209 | - 'publicly_queryable' => false, |
|
210 | - 'exclude_from_search'=> true, |
|
211 | - 'show_ui' => true, |
|
212 | - 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
213 | - 'query_var' => false, |
|
214 | - 'rewrite' => false, |
|
215 | - 'map_meta_cap' => true, |
|
216 | - 'has_archive' => false, |
|
217 | - 'hierarchical' => false, |
|
218 | - 'supports' => array( 'title', 'excerpt' ), |
|
219 | - 'show_in_nav_menus' => false, |
|
220 | - 'show_in_admin_bar' => true, |
|
221 | - 'menu_position' => null, |
|
222 | - ) |
|
223 | - ) |
|
224 | - ); |
|
173 | + // Register discount post type. |
|
174 | + register_post_type( |
|
175 | + 'wpi_discount', |
|
176 | + apply_filters( |
|
177 | + 'wpinv_register_post_type_discount', |
|
178 | + array( |
|
179 | + 'labels' => array( |
|
180 | + 'name' => __( 'Discounts', 'invoicing' ), |
|
181 | + 'singular_name' => __( 'Discount', 'invoicing' ), |
|
182 | + 'all_items' => __( 'Discounts', 'invoicing' ), |
|
183 | + 'menu_name' => _x( 'Discounts', 'Admin menu name', 'invoicing' ), |
|
184 | + 'add_new' => __( 'Add New', 'invoicing' ), |
|
185 | + 'add_new_item' => __( 'Add new discount', 'invoicing' ), |
|
186 | + 'edit' => __( 'Edit', 'invoicing' ), |
|
187 | + 'edit_item' => __( 'Edit discount', 'invoicing' ), |
|
188 | + 'new_item' => __( 'New discount', 'invoicing' ), |
|
189 | + 'view_item' => __( 'View discount', 'invoicing' ), |
|
190 | + 'view_items' => __( 'View Discounts', 'invoicing' ), |
|
191 | + 'search_items' => __( 'Search discounts', 'invoicing' ), |
|
192 | + 'not_found' => __( 'No discounts found', 'invoicing' ), |
|
193 | + 'not_found_in_trash' => __( 'No discounts found in trash', 'invoicing' ), |
|
194 | + 'parent' => __( 'Parent discount', 'invoicing' ), |
|
195 | + 'featured_image' => __( 'Discount image', 'invoicing' ), |
|
196 | + 'set_featured_image' => __( 'Set discount image', 'invoicing' ), |
|
197 | + 'remove_featured_image' => __( 'Remove discount image', 'invoicing' ), |
|
198 | + 'use_featured_image' => __( 'Use as discount image', 'invoicing' ), |
|
199 | + 'insert_into_item' => __( 'Insert into discount', 'invoicing' ), |
|
200 | + 'uploaded_to_this_item' => __( 'Uploaded to this discount', 'invoicing' ), |
|
201 | + 'filter_items_list' => __( 'Filter discounts', 'invoicing' ), |
|
202 | + 'items_list_navigation' => __( 'Discount navigation', 'invoicing' ), |
|
203 | + 'items_list' => __( 'Discounts list', 'invoicing' ), |
|
204 | + ), |
|
205 | + 'description' => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ), |
|
206 | + 'public' => false, |
|
207 | + 'can_export' => true, |
|
208 | + '_builtin' => false, |
|
209 | + 'publicly_queryable' => false, |
|
210 | + 'exclude_from_search'=> true, |
|
211 | + 'show_ui' => true, |
|
212 | + 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
213 | + 'query_var' => false, |
|
214 | + 'rewrite' => false, |
|
215 | + 'map_meta_cap' => true, |
|
216 | + 'has_archive' => false, |
|
217 | + 'hierarchical' => false, |
|
218 | + 'supports' => array( 'title', 'excerpt' ), |
|
219 | + 'show_in_nav_menus' => false, |
|
220 | + 'show_in_admin_bar' => true, |
|
221 | + 'menu_position' => null, |
|
222 | + ) |
|
223 | + ) |
|
224 | + ); |
|
225 | 225 | |
226 | - do_action( 'getpaid_after_register_post_types' ); |
|
227 | - } |
|
226 | + do_action( 'getpaid_after_register_post_types' ); |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * Register our custom post statuses. |
|
231 | - */ |
|
232 | - public static function register_post_status() { |
|
229 | + /** |
|
230 | + * Register our custom post statuses. |
|
231 | + */ |
|
232 | + public static function register_post_status() { |
|
233 | 233 | |
234 | - $invoice_statuses = apply_filters( |
|
235 | - 'getpaid_register_invoice_post_statuses', |
|
236 | - array( |
|
234 | + $invoice_statuses = apply_filters( |
|
235 | + 'getpaid_register_invoice_post_statuses', |
|
236 | + array( |
|
237 | 237 | |
238 | - 'wpi-pending' => array( |
|
239 | - 'label' => _x( 'Pending Payment', 'Invoice status', 'invoicing' ), |
|
240 | - 'public' => true, |
|
241 | - 'exclude_from_search' => true, |
|
242 | - 'show_in_admin_all_list' => true, |
|
243 | - 'show_in_admin_status_list' => true, |
|
244 | - /* translators: %s: number of invoices */ |
|
245 | - 'label_count' => _n_noop( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing' ) |
|
246 | - ), |
|
238 | + 'wpi-pending' => array( |
|
239 | + 'label' => _x( 'Pending Payment', 'Invoice status', 'invoicing' ), |
|
240 | + 'public' => true, |
|
241 | + 'exclude_from_search' => true, |
|
242 | + 'show_in_admin_all_list' => true, |
|
243 | + 'show_in_admin_status_list' => true, |
|
244 | + /* translators: %s: number of invoices */ |
|
245 | + 'label_count' => _n_noop( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing' ) |
|
246 | + ), |
|
247 | 247 | |
248 | - 'wpi-processing' => array( |
|
249 | - 'label' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
250 | - 'public' => true, |
|
251 | - 'exclude_from_search' => true, |
|
252 | - 'show_in_admin_all_list' => true, |
|
253 | - 'show_in_admin_status_list' => true, |
|
254 | - /* translators: %s: number of invoices */ |
|
255 | - 'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' ) |
|
256 | - ), |
|
248 | + 'wpi-processing' => array( |
|
249 | + 'label' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
250 | + 'public' => true, |
|
251 | + 'exclude_from_search' => true, |
|
252 | + 'show_in_admin_all_list' => true, |
|
253 | + 'show_in_admin_status_list' => true, |
|
254 | + /* translators: %s: number of invoices */ |
|
255 | + 'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' ) |
|
256 | + ), |
|
257 | 257 | |
258 | - 'wpi-onhold' => array( |
|
259 | - 'label' => _x( 'On Hold', 'Invoice status', 'invoicing' ), |
|
260 | - 'public' => true, |
|
261 | - 'exclude_from_search' => true, |
|
262 | - 'show_in_admin_all_list' => true, |
|
263 | - 'show_in_admin_status_list' => true, |
|
264 | - /* translators: %s: number of invoices */ |
|
265 | - 'label_count' => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' ) |
|
266 | - ), |
|
258 | + 'wpi-onhold' => array( |
|
259 | + 'label' => _x( 'On Hold', 'Invoice status', 'invoicing' ), |
|
260 | + 'public' => true, |
|
261 | + 'exclude_from_search' => true, |
|
262 | + 'show_in_admin_all_list' => true, |
|
263 | + 'show_in_admin_status_list' => true, |
|
264 | + /* translators: %s: number of invoices */ |
|
265 | + 'label_count' => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' ) |
|
266 | + ), |
|
267 | 267 | |
268 | - 'wpi-cancelled' => array( |
|
269 | - 'label' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
270 | - 'public' => true, |
|
271 | - 'exclude_from_search' => true, |
|
272 | - 'show_in_admin_all_list' => true, |
|
273 | - 'show_in_admin_status_list' => true, |
|
274 | - /* translators: %s: number of invoices */ |
|
275 | - 'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' ) |
|
276 | - ), |
|
268 | + 'wpi-cancelled' => array( |
|
269 | + 'label' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
270 | + 'public' => true, |
|
271 | + 'exclude_from_search' => true, |
|
272 | + 'show_in_admin_all_list' => true, |
|
273 | + 'show_in_admin_status_list' => true, |
|
274 | + /* translators: %s: number of invoices */ |
|
275 | + 'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' ) |
|
276 | + ), |
|
277 | 277 | |
278 | - 'wpi-refunded' => array( |
|
279 | - 'label' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
280 | - 'public' => true, |
|
281 | - 'exclude_from_search' => true, |
|
282 | - 'show_in_admin_all_list' => true, |
|
283 | - 'show_in_admin_status_list' => true, |
|
284 | - /* translators: %s: number of invoices */ |
|
285 | - 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' ) |
|
286 | - ), |
|
278 | + 'wpi-refunded' => array( |
|
279 | + 'label' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
280 | + 'public' => true, |
|
281 | + 'exclude_from_search' => true, |
|
282 | + 'show_in_admin_all_list' => true, |
|
283 | + 'show_in_admin_status_list' => true, |
|
284 | + /* translators: %s: number of invoices */ |
|
285 | + 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' ) |
|
286 | + ), |
|
287 | 287 | |
288 | - 'wpi-failed' => array( |
|
289 | - 'label' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
290 | - 'public' => true, |
|
291 | - 'exclude_from_search' => true, |
|
292 | - 'show_in_admin_all_list' => true, |
|
293 | - 'show_in_admin_status_list' => true, |
|
294 | - /* translators: %s: number of invoices */ |
|
295 | - 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' ) |
|
296 | - ), |
|
288 | + 'wpi-failed' => array( |
|
289 | + 'label' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
290 | + 'public' => true, |
|
291 | + 'exclude_from_search' => true, |
|
292 | + 'show_in_admin_all_list' => true, |
|
293 | + 'show_in_admin_status_list' => true, |
|
294 | + /* translators: %s: number of invoices */ |
|
295 | + 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' ) |
|
296 | + ), |
|
297 | 297 | |
298 | - 'wpi-renewal' => array( |
|
299 | - 'label' => _x( 'Renewal', 'Invoice status', 'invoicing' ), |
|
300 | - 'public' => true, |
|
301 | - 'exclude_from_search' => true, |
|
302 | - 'show_in_admin_all_list' => true, |
|
303 | - 'show_in_admin_status_list' => true, |
|
304 | - /* translators: %s: number of invoices */ |
|
305 | - 'label_count' => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' ) |
|
306 | - ) |
|
307 | - ) |
|
308 | - ); |
|
298 | + 'wpi-renewal' => array( |
|
299 | + 'label' => _x( 'Renewal', 'Invoice status', 'invoicing' ), |
|
300 | + 'public' => true, |
|
301 | + 'exclude_from_search' => true, |
|
302 | + 'show_in_admin_all_list' => true, |
|
303 | + 'show_in_admin_status_list' => true, |
|
304 | + /* translators: %s: number of invoices */ |
|
305 | + 'label_count' => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' ) |
|
306 | + ) |
|
307 | + ) |
|
308 | + ); |
|
309 | 309 | |
310 | - foreach ( $invoice_statuses as $invoice_statuse => $args ) { |
|
311 | - register_post_status( $invoice_statuse, $args ); |
|
312 | - } |
|
313 | - } |
|
310 | + foreach ( $invoice_statuses as $invoice_statuse => $args ) { |
|
311 | + register_post_status( $invoice_statuse, $args ); |
|
312 | + } |
|
313 | + } |
|
314 | 314 | |
315 | - /** |
|
316 | - * Flush rewrite rules. |
|
317 | - */ |
|
318 | - public static function flush_rewrite_rules() { |
|
319 | - flush_rewrite_rules(); |
|
320 | - } |
|
315 | + /** |
|
316 | + * Flush rewrite rules. |
|
317 | + */ |
|
318 | + public static function flush_rewrite_rules() { |
|
319 | + flush_rewrite_rules(); |
|
320 | + } |
|
321 | 321 | |
322 | - /** |
|
323 | - * Flush rules to prevent 404. |
|
324 | - * |
|
325 | - */ |
|
326 | - public static function maybe_flush_rewrite_rules() { |
|
327 | - if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) { |
|
328 | - update_option( 'getpaid_flushed_rewrite_rules', '1' ); |
|
329 | - self::flush_rewrite_rules(); |
|
330 | - } |
|
331 | - } |
|
322 | + /** |
|
323 | + * Flush rules to prevent 404. |
|
324 | + * |
|
325 | + */ |
|
326 | + public static function maybe_flush_rewrite_rules() { |
|
327 | + if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) { |
|
328 | + update_option( 'getpaid_flushed_rewrite_rules', '1' ); |
|
329 | + self::flush_rewrite_rules(); |
|
330 | + } |
|
331 | + } |
|
332 | 332 | |
333 | 333 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Post types Class |
@@ -18,10 +18,10 @@ discard block |
||
18 | 18 | * Hook in methods. |
19 | 19 | */ |
20 | 20 | public function __construct() { |
21 | - add_action( 'init', array( __CLASS__, 'register_post_types' ), 1 ); |
|
22 | - add_action( 'init', array( __CLASS__, 'register_post_status' ), 4 ); |
|
23 | - add_action( 'getpaid_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) ); |
|
24 | - add_action( 'getpaid_after_register_post_types', array( __CLASS__, 'maybe_flush_rewrite_rules' ) ); |
|
21 | + add_action('init', array(__CLASS__, 'register_post_types'), 1); |
|
22 | + add_action('init', array(__CLASS__, 'register_post_status'), 4); |
|
23 | + add_action('getpaid_flush_rewrite_rules', array(__CLASS__, 'flush_rewrite_rules')); |
|
24 | + add_action('getpaid_after_register_post_types', array(__CLASS__, 'maybe_flush_rewrite_rules')); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -29,12 +29,12 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public static function register_post_types() { |
31 | 31 | |
32 | - if ( ! is_blog_installed() || post_type_exists( 'wpi_item' ) ) { |
|
32 | + if (!is_blog_installed() || post_type_exists('wpi_item')) { |
|
33 | 33 | return; |
34 | 34 | } |
35 | 35 | |
36 | 36 | // Fires before registering post types. |
37 | - do_action( 'getpaid_register_post_types' ); |
|
37 | + do_action('getpaid_register_post_types'); |
|
38 | 38 | |
39 | 39 | // Register item post type. |
40 | 40 | register_post_type( |
@@ -43,29 +43,29 @@ discard block |
||
43 | 43 | 'wpinv_register_post_type_invoice_item', |
44 | 44 | array( |
45 | 45 | 'labels' => array( |
46 | - 'name' => _x( 'Items', 'post type general name', 'invoicing' ), |
|
47 | - 'singular_name' => _x( 'Item', 'post type singular name', 'invoicing' ), |
|
48 | - 'menu_name' => _x( 'Items', 'admin menu', 'invoicing' ), |
|
49 | - 'name_admin_bar' => _x( 'Item', 'add new on admin bar', 'invoicing' ), |
|
50 | - 'add_new' => _x( 'Add New', 'Item', 'invoicing' ), |
|
51 | - 'add_new_item' => __( 'Add New Item', 'invoicing' ), |
|
52 | - 'new_item' => __( 'New Item', 'invoicing' ), |
|
53 | - 'edit_item' => __( 'Edit Item', 'invoicing' ), |
|
54 | - 'view_item' => __( 'View Item', 'invoicing' ), |
|
55 | - 'all_items' => __( 'Items', 'invoicing' ), |
|
56 | - 'search_items' => __( 'Search items', 'invoicing' ), |
|
57 | - 'parent_item_colon' => __( 'Parent item:', 'invoicing' ), |
|
58 | - 'not_found' => __( 'No items found.', 'invoicing' ), |
|
59 | - 'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' ) |
|
46 | + 'name' => _x('Items', 'post type general name', 'invoicing'), |
|
47 | + 'singular_name' => _x('Item', 'post type singular name', 'invoicing'), |
|
48 | + 'menu_name' => _x('Items', 'admin menu', 'invoicing'), |
|
49 | + 'name_admin_bar' => _x('Item', 'add new on admin bar', 'invoicing'), |
|
50 | + 'add_new' => _x('Add New', 'Item', 'invoicing'), |
|
51 | + 'add_new_item' => __('Add New Item', 'invoicing'), |
|
52 | + 'new_item' => __('New Item', 'invoicing'), |
|
53 | + 'edit_item' => __('Edit Item', 'invoicing'), |
|
54 | + 'view_item' => __('View Item', 'invoicing'), |
|
55 | + 'all_items' => __('Items', 'invoicing'), |
|
56 | + 'search_items' => __('Search items', 'invoicing'), |
|
57 | + 'parent_item_colon' => __('Parent item:', 'invoicing'), |
|
58 | + 'not_found' => __('No items found.', 'invoicing'), |
|
59 | + 'not_found_in_trash' => __('No items found in trash.', 'invoicing') |
|
60 | 60 | ), |
61 | - 'description' => __( 'This is where you can add new invoice items.', 'invoicing' ), |
|
61 | + 'description' => __('This is where you can add new invoice items.', 'invoicing'), |
|
62 | 62 | 'public' => false, |
63 | 63 | 'has_archive' => false, |
64 | 64 | '_builtin' => false, |
65 | 65 | 'show_ui' => true, |
66 | 66 | 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
67 | 67 | 'show_in_nav_menus' => false, |
68 | - 'supports' => array( 'title', 'excerpt', 'thumbnail' ), |
|
68 | + 'supports' => array('title', 'excerpt', 'thumbnail'), |
|
69 | 69 | 'rewrite' => false, |
70 | 70 | 'query_var' => false, |
71 | 71 | 'map_meta_cap' => true, |
@@ -82,22 +82,22 @@ discard block |
||
82 | 82 | 'wpinv_register_post_type_payment_form', |
83 | 83 | array( |
84 | 84 | 'labels' => array( |
85 | - 'name' => _x( 'Payment Forms', 'post type general name', 'invoicing' ), |
|
86 | - 'singular_name' => _x( 'Payment Form', 'post type singular name', 'invoicing' ), |
|
87 | - 'menu_name' => _x( 'Payment Forms', 'admin menu', 'invoicing' ), |
|
88 | - 'name_admin_bar' => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ), |
|
89 | - 'add_new' => _x( 'Add New', 'Payment Form', 'invoicing' ), |
|
90 | - 'add_new_item' => __( 'Add New Payment Form', 'invoicing' ), |
|
91 | - 'new_item' => __( 'New Payment Form', 'invoicing' ), |
|
92 | - 'edit_item' => __( 'Edit Payment Form', 'invoicing' ), |
|
93 | - 'view_item' => __( 'View Payment Form', 'invoicing' ), |
|
94 | - 'all_items' => __( 'Payment Forms', 'invoicing' ), |
|
95 | - 'search_items' => __( 'Search Payment Forms', 'invoicing' ), |
|
96 | - 'parent_item_colon' => __( 'Parent Payment Forms:', 'invoicing' ), |
|
97 | - 'not_found' => __( 'No payment forms found.', 'invoicing' ), |
|
98 | - 'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' ) |
|
85 | + 'name' => _x('Payment Forms', 'post type general name', 'invoicing'), |
|
86 | + 'singular_name' => _x('Payment Form', 'post type singular name', 'invoicing'), |
|
87 | + 'menu_name' => _x('Payment Forms', 'admin menu', 'invoicing'), |
|
88 | + 'name_admin_bar' => _x('Payment Form', 'add new on admin bar', 'invoicing'), |
|
89 | + 'add_new' => _x('Add New', 'Payment Form', 'invoicing'), |
|
90 | + 'add_new_item' => __('Add New Payment Form', 'invoicing'), |
|
91 | + 'new_item' => __('New Payment Form', 'invoicing'), |
|
92 | + 'edit_item' => __('Edit Payment Form', 'invoicing'), |
|
93 | + 'view_item' => __('View Payment Form', 'invoicing'), |
|
94 | + 'all_items' => __('Payment Forms', 'invoicing'), |
|
95 | + 'search_items' => __('Search Payment Forms', 'invoicing'), |
|
96 | + 'parent_item_colon' => __('Parent Payment Forms:', 'invoicing'), |
|
97 | + 'not_found' => __('No payment forms found.', 'invoicing'), |
|
98 | + 'not_found_in_trash' => __('No payment forms found in trash.', 'invoicing') |
|
99 | 99 | ), |
100 | - 'description' => __( 'Add new payment forms.', 'invoicing' ), |
|
100 | + 'description' => __('Add new payment forms.', 'invoicing'), |
|
101 | 101 | 'public' => false, |
102 | 102 | 'show_ui' => true, |
103 | 103 | 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : true, |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | 'has_archive' => false, |
109 | 109 | 'hierarchical' => false, |
110 | 110 | 'menu_position' => null, |
111 | - 'supports' => array( 'title' ), |
|
111 | + 'supports' => array('title'), |
|
112 | 112 | 'menu_icon' => 'dashicons-media-form', |
113 | 113 | ) |
114 | 114 | ) |
@@ -121,32 +121,32 @@ discard block |
||
121 | 121 | 'wpinv_register_post_type_invoice', |
122 | 122 | array( |
123 | 123 | 'labels' => array( |
124 | - 'name' => __( 'Invoices', 'invoicing' ), |
|
125 | - 'singular_name' => __( 'Invoice', 'invoicing' ), |
|
126 | - 'all_items' => __( 'Invoices', 'invoicing' ), |
|
127 | - 'menu_name' => _x( 'Invoices', 'Admin menu name', 'invoicing' ), |
|
128 | - 'add_new' => __( 'Add New', 'invoicing' ), |
|
129 | - 'add_new_item' => __( 'Add new invoice', 'invoicing' ), |
|
130 | - 'edit' => __( 'Edit', 'invoicing' ), |
|
131 | - 'edit_item' => __( 'Edit invoice', 'invoicing' ), |
|
132 | - 'new_item' => __( 'New invoice', 'invoicing' ), |
|
133 | - 'view_item' => __( 'View invoice', 'invoicing' ), |
|
134 | - 'view_items' => __( 'View Invoices', 'invoicing' ), |
|
135 | - 'search_items' => __( 'Search invoices', 'invoicing' ), |
|
136 | - 'not_found' => __( 'No invoices found', 'invoicing' ), |
|
137 | - 'not_found_in_trash' => __( 'No invoices found in trash', 'invoicing' ), |
|
138 | - 'parent' => __( 'Parent invoice', 'invoicing' ), |
|
139 | - 'featured_image' => __( 'Invoice image', 'invoicing' ), |
|
140 | - 'set_featured_image' => __( 'Set invoice image', 'invoicing' ), |
|
141 | - 'remove_featured_image' => __( 'Remove invoice image', 'invoicing' ), |
|
142 | - 'use_featured_image' => __( 'Use as invoice image', 'invoicing' ), |
|
143 | - 'insert_into_item' => __( 'Insert into invoice', 'invoicing' ), |
|
144 | - 'uploaded_to_this_item' => __( 'Uploaded to this invoice', 'invoicing' ), |
|
145 | - 'filter_items_list' => __( 'Filter invoices', 'invoicing' ), |
|
146 | - 'items_list_navigation' => __( 'Invoices navigation', 'invoicing' ), |
|
147 | - 'items_list' => __( 'Invoices list', 'invoicing' ), |
|
124 | + 'name' => __('Invoices', 'invoicing'), |
|
125 | + 'singular_name' => __('Invoice', 'invoicing'), |
|
126 | + 'all_items' => __('Invoices', 'invoicing'), |
|
127 | + 'menu_name' => _x('Invoices', 'Admin menu name', 'invoicing'), |
|
128 | + 'add_new' => __('Add New', 'invoicing'), |
|
129 | + 'add_new_item' => __('Add new invoice', 'invoicing'), |
|
130 | + 'edit' => __('Edit', 'invoicing'), |
|
131 | + 'edit_item' => __('Edit invoice', 'invoicing'), |
|
132 | + 'new_item' => __('New invoice', 'invoicing'), |
|
133 | + 'view_item' => __('View invoice', 'invoicing'), |
|
134 | + 'view_items' => __('View Invoices', 'invoicing'), |
|
135 | + 'search_items' => __('Search invoices', 'invoicing'), |
|
136 | + 'not_found' => __('No invoices found', 'invoicing'), |
|
137 | + 'not_found_in_trash' => __('No invoices found in trash', 'invoicing'), |
|
138 | + 'parent' => __('Parent invoice', 'invoicing'), |
|
139 | + 'featured_image' => __('Invoice image', 'invoicing'), |
|
140 | + 'set_featured_image' => __('Set invoice image', 'invoicing'), |
|
141 | + 'remove_featured_image' => __('Remove invoice image', 'invoicing'), |
|
142 | + 'use_featured_image' => __('Use as invoice image', 'invoicing'), |
|
143 | + 'insert_into_item' => __('Insert into invoice', 'invoicing'), |
|
144 | + 'uploaded_to_this_item' => __('Uploaded to this invoice', 'invoicing'), |
|
145 | + 'filter_items_list' => __('Filter invoices', 'invoicing'), |
|
146 | + 'items_list_navigation' => __('Invoices navigation', 'invoicing'), |
|
147 | + 'items_list' => __('Invoices list', 'invoicing'), |
|
148 | 148 | ), |
149 | - 'description' => __( 'This is where invoices are stored.', 'invoicing' ), |
|
149 | + 'description' => __('This is where invoices are stored.', 'invoicing'), |
|
150 | 150 | 'public' => true, |
151 | 151 | 'has_archive' => false, |
152 | 152 | 'publicly_queryable' => true, |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | 'show_ui' => true, |
155 | 155 | 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
156 | 156 | 'show_in_nav_menus' => false, |
157 | - 'supports' => array( 'title', 'author', 'excerpt' ), |
|
157 | + 'supports' => array('title', 'author', 'excerpt'), |
|
158 | 158 | 'rewrite' => array( |
159 | 159 | 'slug' => 'invoice', |
160 | 160 | 'with_front' => false, |
@@ -177,32 +177,32 @@ discard block |
||
177 | 177 | 'wpinv_register_post_type_discount', |
178 | 178 | array( |
179 | 179 | 'labels' => array( |
180 | - 'name' => __( 'Discounts', 'invoicing' ), |
|
181 | - 'singular_name' => __( 'Discount', 'invoicing' ), |
|
182 | - 'all_items' => __( 'Discounts', 'invoicing' ), |
|
183 | - 'menu_name' => _x( 'Discounts', 'Admin menu name', 'invoicing' ), |
|
184 | - 'add_new' => __( 'Add New', 'invoicing' ), |
|
185 | - 'add_new_item' => __( 'Add new discount', 'invoicing' ), |
|
186 | - 'edit' => __( 'Edit', 'invoicing' ), |
|
187 | - 'edit_item' => __( 'Edit discount', 'invoicing' ), |
|
188 | - 'new_item' => __( 'New discount', 'invoicing' ), |
|
189 | - 'view_item' => __( 'View discount', 'invoicing' ), |
|
190 | - 'view_items' => __( 'View Discounts', 'invoicing' ), |
|
191 | - 'search_items' => __( 'Search discounts', 'invoicing' ), |
|
192 | - 'not_found' => __( 'No discounts found', 'invoicing' ), |
|
193 | - 'not_found_in_trash' => __( 'No discounts found in trash', 'invoicing' ), |
|
194 | - 'parent' => __( 'Parent discount', 'invoicing' ), |
|
195 | - 'featured_image' => __( 'Discount image', 'invoicing' ), |
|
196 | - 'set_featured_image' => __( 'Set discount image', 'invoicing' ), |
|
197 | - 'remove_featured_image' => __( 'Remove discount image', 'invoicing' ), |
|
198 | - 'use_featured_image' => __( 'Use as discount image', 'invoicing' ), |
|
199 | - 'insert_into_item' => __( 'Insert into discount', 'invoicing' ), |
|
200 | - 'uploaded_to_this_item' => __( 'Uploaded to this discount', 'invoicing' ), |
|
201 | - 'filter_items_list' => __( 'Filter discounts', 'invoicing' ), |
|
202 | - 'items_list_navigation' => __( 'Discount navigation', 'invoicing' ), |
|
203 | - 'items_list' => __( 'Discounts list', 'invoicing' ), |
|
180 | + 'name' => __('Discounts', 'invoicing'), |
|
181 | + 'singular_name' => __('Discount', 'invoicing'), |
|
182 | + 'all_items' => __('Discounts', 'invoicing'), |
|
183 | + 'menu_name' => _x('Discounts', 'Admin menu name', 'invoicing'), |
|
184 | + 'add_new' => __('Add New', 'invoicing'), |
|
185 | + 'add_new_item' => __('Add new discount', 'invoicing'), |
|
186 | + 'edit' => __('Edit', 'invoicing'), |
|
187 | + 'edit_item' => __('Edit discount', 'invoicing'), |
|
188 | + 'new_item' => __('New discount', 'invoicing'), |
|
189 | + 'view_item' => __('View discount', 'invoicing'), |
|
190 | + 'view_items' => __('View Discounts', 'invoicing'), |
|
191 | + 'search_items' => __('Search discounts', 'invoicing'), |
|
192 | + 'not_found' => __('No discounts found', 'invoicing'), |
|
193 | + 'not_found_in_trash' => __('No discounts found in trash', 'invoicing'), |
|
194 | + 'parent' => __('Parent discount', 'invoicing'), |
|
195 | + 'featured_image' => __('Discount image', 'invoicing'), |
|
196 | + 'set_featured_image' => __('Set discount image', 'invoicing'), |
|
197 | + 'remove_featured_image' => __('Remove discount image', 'invoicing'), |
|
198 | + 'use_featured_image' => __('Use as discount image', 'invoicing'), |
|
199 | + 'insert_into_item' => __('Insert into discount', 'invoicing'), |
|
200 | + 'uploaded_to_this_item' => __('Uploaded to this discount', 'invoicing'), |
|
201 | + 'filter_items_list' => __('Filter discounts', 'invoicing'), |
|
202 | + 'items_list_navigation' => __('Discount navigation', 'invoicing'), |
|
203 | + 'items_list' => __('Discounts list', 'invoicing'), |
|
204 | 204 | ), |
205 | - 'description' => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ), |
|
205 | + 'description' => __('This is where you can add new discounts that users can use in invoices.', 'invoicing'), |
|
206 | 206 | 'public' => false, |
207 | 207 | 'can_export' => true, |
208 | 208 | '_builtin' => false, |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | 'map_meta_cap' => true, |
216 | 216 | 'has_archive' => false, |
217 | 217 | 'hierarchical' => false, |
218 | - 'supports' => array( 'title', 'excerpt' ), |
|
218 | + 'supports' => array('title', 'excerpt'), |
|
219 | 219 | 'show_in_nav_menus' => false, |
220 | 220 | 'show_in_admin_bar' => true, |
221 | 221 | 'menu_position' => null, |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | ) |
224 | 224 | ); |
225 | 225 | |
226 | - do_action( 'getpaid_after_register_post_types' ); |
|
226 | + do_action('getpaid_after_register_post_types'); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -236,79 +236,79 @@ discard block |
||
236 | 236 | array( |
237 | 237 | |
238 | 238 | 'wpi-pending' => array( |
239 | - 'label' => _x( 'Pending Payment', 'Invoice status', 'invoicing' ), |
|
239 | + 'label' => _x('Pending Payment', 'Invoice status', 'invoicing'), |
|
240 | 240 | 'public' => true, |
241 | 241 | 'exclude_from_search' => true, |
242 | 242 | 'show_in_admin_all_list' => true, |
243 | 243 | 'show_in_admin_status_list' => true, |
244 | 244 | /* translators: %s: number of invoices */ |
245 | - 'label_count' => _n_noop( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing' ) |
|
245 | + 'label_count' => _n_noop('Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing') |
|
246 | 246 | ), |
247 | 247 | |
248 | 248 | 'wpi-processing' => array( |
249 | - 'label' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
249 | + 'label' => _x('Processing', 'Invoice status', 'invoicing'), |
|
250 | 250 | 'public' => true, |
251 | 251 | 'exclude_from_search' => true, |
252 | 252 | 'show_in_admin_all_list' => true, |
253 | 253 | 'show_in_admin_status_list' => true, |
254 | 254 | /* translators: %s: number of invoices */ |
255 | - 'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' ) |
|
255 | + 'label_count' => _n_noop('Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing') |
|
256 | 256 | ), |
257 | 257 | |
258 | 258 | 'wpi-onhold' => array( |
259 | - 'label' => _x( 'On Hold', 'Invoice status', 'invoicing' ), |
|
259 | + 'label' => _x('On Hold', 'Invoice status', 'invoicing'), |
|
260 | 260 | 'public' => true, |
261 | 261 | 'exclude_from_search' => true, |
262 | 262 | 'show_in_admin_all_list' => true, |
263 | 263 | 'show_in_admin_status_list' => true, |
264 | 264 | /* translators: %s: number of invoices */ |
265 | - 'label_count' => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' ) |
|
265 | + 'label_count' => _n_noop('On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing') |
|
266 | 266 | ), |
267 | 267 | |
268 | 268 | 'wpi-cancelled' => array( |
269 | - 'label' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
269 | + 'label' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
270 | 270 | 'public' => true, |
271 | 271 | 'exclude_from_search' => true, |
272 | 272 | 'show_in_admin_all_list' => true, |
273 | 273 | 'show_in_admin_status_list' => true, |
274 | 274 | /* translators: %s: number of invoices */ |
275 | - 'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' ) |
|
275 | + 'label_count' => _n_noop('Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing') |
|
276 | 276 | ), |
277 | 277 | |
278 | 278 | 'wpi-refunded' => array( |
279 | - 'label' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
279 | + 'label' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
280 | 280 | 'public' => true, |
281 | 281 | 'exclude_from_search' => true, |
282 | 282 | 'show_in_admin_all_list' => true, |
283 | 283 | 'show_in_admin_status_list' => true, |
284 | 284 | /* translators: %s: number of invoices */ |
285 | - 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' ) |
|
285 | + 'label_count' => _n_noop('Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing') |
|
286 | 286 | ), |
287 | 287 | |
288 | 288 | 'wpi-failed' => array( |
289 | - 'label' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
289 | + 'label' => _x('Failed', 'Invoice status', 'invoicing'), |
|
290 | 290 | 'public' => true, |
291 | 291 | 'exclude_from_search' => true, |
292 | 292 | 'show_in_admin_all_list' => true, |
293 | 293 | 'show_in_admin_status_list' => true, |
294 | 294 | /* translators: %s: number of invoices */ |
295 | - 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' ) |
|
295 | + 'label_count' => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing') |
|
296 | 296 | ), |
297 | 297 | |
298 | 298 | 'wpi-renewal' => array( |
299 | - 'label' => _x( 'Renewal', 'Invoice status', 'invoicing' ), |
|
299 | + 'label' => _x('Renewal', 'Invoice status', 'invoicing'), |
|
300 | 300 | 'public' => true, |
301 | 301 | 'exclude_from_search' => true, |
302 | 302 | 'show_in_admin_all_list' => true, |
303 | 303 | 'show_in_admin_status_list' => true, |
304 | 304 | /* translators: %s: number of invoices */ |
305 | - 'label_count' => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' ) |
|
305 | + 'label_count' => _n_noop('Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing') |
|
306 | 306 | ) |
307 | 307 | ) |
308 | 308 | ); |
309 | 309 | |
310 | - foreach ( $invoice_statuses as $invoice_statuse => $args ) { |
|
311 | - register_post_status( $invoice_statuse, $args ); |
|
310 | + foreach ($invoice_statuses as $invoice_statuse => $args) { |
|
311 | + register_post_status($invoice_statuse, $args); |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | |
@@ -324,8 +324,8 @@ discard block |
||
324 | 324 | * |
325 | 325 | */ |
326 | 326 | public static function maybe_flush_rewrite_rules() { |
327 | - if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) { |
|
328 | - update_option( 'getpaid_flushed_rewrite_rules', '1' ); |
|
327 | + if (!get_option('getpaid_flushed_rewrite_rules')) { |
|
328 | + update_option('getpaid_flushed_rewrite_rules', '1'); |
|
329 | 329 | self::flush_rewrite_rules(); |
330 | 330 | } |
331 | 331 | } |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if (!defined('ABSPATH')) |
|
4 | 4 | die('-1'); |
5 | 5 | |
6 | -$email_footer = apply_filters( 'wpinv_email_footer_text', wpinv_get_option( 'email_footer_text', get_bloginfo( 'name', 'display' ) . ' - ' . __( 'Powered by GetPaid', 'invoicing' ) ) ); |
|
7 | -$email_footer = $email_footer ? wpautop( wp_kses_post( wptexturize( $email_footer ) ) ) : ''; |
|
6 | +$email_footer = apply_filters('wpinv_email_footer_text', wpinv_get_option('email_footer_text', get_bloginfo('name', 'display') . ' - ' . __('Powered by GetPaid', 'invoicing'))); |
|
7 | +$email_footer = $email_footer ? wpautop(wp_kses_post(wptexturize($email_footer))) : ''; |
|
8 | 8 | ?> |
9 | 9 | </div> |
10 | 10 | </td> |
@@ -1,7 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if ( !defined('ABSPATH') ) { |
|
4 | 4 | die('-1'); |
5 | +} |
|
5 | 6 | |
6 | 7 | $email_footer = apply_filters( 'wpinv_email_footer_text', wpinv_get_option( 'email_footer_text', get_bloginfo( 'name', 'display' ) . ' - ' . __( 'Powered by GetPaid', 'invoicing' ) ) ); |
7 | 8 | $email_footer = $email_footer ? wpautop( wp_kses_post( wptexturize( $email_footer ) ) ) : ''; |
@@ -14,521 +14,521 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * @param array An array of payment gateways. |
|
40 | - */ |
|
41 | - public $gateways; |
|
42 | - |
|
43 | - /** |
|
44 | - * Class constructor. |
|
45 | - */ |
|
46 | - public function __construct() { |
|
47 | - $this->define_constants(); |
|
48 | - $this->includes(); |
|
49 | - $this->init_hooks(); |
|
50 | - $this->set_properties(); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Sets a custom data property. |
|
55 | - * |
|
56 | - * @param string $prop The prop to set. |
|
57 | - * @param mixed $value The value to retrieve. |
|
58 | - */ |
|
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Gets a custom data property. |
|
65 | - * |
|
66 | - * @param string $prop The prop to set. |
|
67 | - * @return mixed The value. |
|
68 | - */ |
|
69 | - public function get( $prop ) { |
|
70 | - |
|
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
73 | - } |
|
74 | - |
|
75 | - return null; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Define class properties. |
|
80 | - */ |
|
81 | - public function set_properties() { |
|
82 | - |
|
83 | - // Sessions. |
|
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | - |
|
88 | - // Init other objects. |
|
89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
91 | - $this->set( 'api', new WPInv_API() ); |
|
92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | - $this->set( 'template', new GetPaid_Template() ); |
|
94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Define plugin constants. |
|
106 | - */ |
|
107 | - public function define_constants() { |
|
108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
110 | - $this->version = WPINV_VERSION; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Hook into actions and filters. |
|
115 | - * |
|
116 | - * @since 1.0.19 |
|
117 | - */ |
|
118 | - protected function init_hooks() { |
|
119 | - /* Internationalize the text strings used. */ |
|
120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
121 | - |
|
122 | - // Init the plugin after WordPress inits. |
|
123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | - |
|
128 | - if ( class_exists( 'BuddyPress' ) ) { |
|
129 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
130 | - } |
|
131 | - |
|
132 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
133 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
134 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
135 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
136 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
137 | - |
|
138 | - // Fires after registering actions. |
|
139 | - do_action( 'wpinv_actions', $this ); |
|
140 | - do_action( 'getpaid_actions', $this ); |
|
141 | - |
|
142 | - } |
|
143 | - |
|
144 | - public function plugins_loaded() { |
|
145 | - /* Internationalize the text strings used. */ |
|
146 | - $this->load_textdomain(); |
|
147 | - |
|
148 | - do_action( 'wpinv_loaded' ); |
|
149 | - |
|
150 | - // Fix oxygen page builder conflict |
|
151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
152 | - wpinv_oxygen_fix_conflict(); |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Load the translation of the plugin. |
|
158 | - * |
|
159 | - * @since 1.0 |
|
160 | - */ |
|
161 | - public function load_textdomain( $locale = NULL ) { |
|
162 | - if ( empty( $locale ) ) { |
|
163 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
164 | - } |
|
165 | - |
|
166 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
167 | - |
|
168 | - unload_textdomain( 'invoicing' ); |
|
169 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
170 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
171 | - |
|
172 | - /** |
|
173 | - * Define language constants. |
|
174 | - */ |
|
175 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Include required core files used in admin and on the frontend. |
|
180 | - */ |
|
181 | - public function includes() { |
|
182 | - |
|
183 | - // Start with the settings. |
|
184 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
185 | - |
|
186 | - // Packages/libraries. |
|
187 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
188 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
189 | - |
|
190 | - // Load functions. |
|
191 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
192 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
199 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
206 | - |
|
207 | - // Register autoloader. |
|
208 | - try { |
|
209 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
210 | - } catch ( Exception $e ) { |
|
211 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
212 | - } |
|
213 | - |
|
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
215 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
216 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
217 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
218 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
219 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
220 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
221 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
234 | - |
|
235 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
236 | - GetPaid_Post_Types_Admin::init(); |
|
237 | - |
|
238 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
244 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
245 | - // load the user class only on the users.php page |
|
246 | - global $pagenow; |
|
247 | - if($pagenow=='users.php'){ |
|
248 | - new WPInv_Admin_Users(); |
|
249 | - } |
|
250 | - } |
|
251 | - |
|
252 | - // Register cli commands |
|
253 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
255 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
256 | - } |
|
257 | - |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Class autoloader |
|
262 | - * |
|
263 | - * @param string $class_name The name of the class to load. |
|
264 | - * @access public |
|
265 | - * @since 1.0.19 |
|
266 | - * @return void |
|
267 | - */ |
|
268 | - public function autoload( $class_name ) { |
|
269 | - |
|
270 | - // Normalize the class name... |
|
271 | - $class_name = strtolower( $class_name ); |
|
272 | - |
|
273 | - // ... and make sure it is our class. |
|
274 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
275 | - return; |
|
276 | - } |
|
277 | - |
|
278 | - // Next, prepare the file name from the class. |
|
279 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
280 | - |
|
281 | - // Base path of the classes. |
|
282 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
283 | - |
|
284 | - // And an array of possible locations in order of importance. |
|
285 | - $locations = array( |
|
286 | - "$plugin_path/includes", |
|
287 | - "$plugin_path/includes/data-stores", |
|
288 | - "$plugin_path/includes/gateways", |
|
289 | - "$plugin_path/includes/payments", |
|
290 | - "$plugin_path/includes/geolocation", |
|
291 | - "$plugin_path/includes/reports", |
|
292 | - "$plugin_path/includes/api", |
|
293 | - "$plugin_path/includes/admin", |
|
294 | - "$plugin_path/includes/admin/meta-boxes", |
|
295 | - ); |
|
296 | - |
|
297 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
298 | - |
|
299 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | - include trailingslashit( $location ) . $file_name; |
|
301 | - break; |
|
302 | - } |
|
303 | - |
|
304 | - } |
|
305 | - |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Inits hooks etc. |
|
310 | - */ |
|
311 | - public function init() { |
|
312 | - |
|
313 | - // Fires before getpaid inits. |
|
314 | - do_action( 'before_getpaid_init', $this ); |
|
315 | - |
|
316 | - // Maybe upgrade. |
|
317 | - $this->maybe_upgrade_database(); |
|
318 | - |
|
319 | - // Load default gateways. |
|
320 | - $gateways = apply_filters( |
|
321 | - 'getpaid_default_gateways', |
|
322 | - array( |
|
323 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
324 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
325 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
326 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
327 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
328 | - ) |
|
329 | - ); |
|
330 | - |
|
331 | - foreach ( $gateways as $id => $class ) { |
|
332 | - $this->gateways[ $id ] = new $class(); |
|
333 | - } |
|
334 | - |
|
335 | - // Fires after getpaid inits. |
|
336 | - do_action( 'getpaid_init', $this ); |
|
337 | - |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * Checks if this is an IPN request and processes it. |
|
342 | - */ |
|
343 | - public function maybe_process_ipn() { |
|
344 | - |
|
345 | - // Ensure that this is an IPN request. |
|
346 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
347 | - return; |
|
348 | - } |
|
349 | - |
|
350 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
351 | - |
|
352 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
353 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
354 | - exit; |
|
355 | - |
|
356 | - } |
|
357 | - |
|
358 | - public function enqueue_scripts() { |
|
359 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
360 | - |
|
361 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
362 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
363 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
364 | - |
|
365 | - // Register scripts |
|
366 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
367 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ), true ); |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * @param array An array of payment gateways. |
|
40 | + */ |
|
41 | + public $gateways; |
|
42 | + |
|
43 | + /** |
|
44 | + * Class constructor. |
|
45 | + */ |
|
46 | + public function __construct() { |
|
47 | + $this->define_constants(); |
|
48 | + $this->includes(); |
|
49 | + $this->init_hooks(); |
|
50 | + $this->set_properties(); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Sets a custom data property. |
|
55 | + * |
|
56 | + * @param string $prop The prop to set. |
|
57 | + * @param mixed $value The value to retrieve. |
|
58 | + */ |
|
59 | + public function set( $prop, $value ) { |
|
60 | + $this->data[ $prop ] = $value; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Gets a custom data property. |
|
65 | + * |
|
66 | + * @param string $prop The prop to set. |
|
67 | + * @return mixed The value. |
|
68 | + */ |
|
69 | + public function get( $prop ) { |
|
70 | + |
|
71 | + if ( isset( $this->data[ $prop ] ) ) { |
|
72 | + return $this->data[ $prop ]; |
|
73 | + } |
|
74 | + |
|
75 | + return null; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Define class properties. |
|
80 | + */ |
|
81 | + public function set_properties() { |
|
82 | + |
|
83 | + // Sessions. |
|
84 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | + |
|
88 | + // Init other objects. |
|
89 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | + $this->set( 'notes', new WPInv_Notes() ); |
|
91 | + $this->set( 'api', new WPInv_API() ); |
|
92 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | + $this->set( 'template', new GetPaid_Template() ); |
|
94 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Define plugin constants. |
|
106 | + */ |
|
107 | + public function define_constants() { |
|
108 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
110 | + $this->version = WPINV_VERSION; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Hook into actions and filters. |
|
115 | + * |
|
116 | + * @since 1.0.19 |
|
117 | + */ |
|
118 | + protected function init_hooks() { |
|
119 | + /* Internationalize the text strings used. */ |
|
120 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
121 | + |
|
122 | + // Init the plugin after WordPress inits. |
|
123 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | + |
|
128 | + if ( class_exists( 'BuddyPress' ) ) { |
|
129 | + add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
130 | + } |
|
131 | + |
|
132 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
133 | + add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
134 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
135 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
136 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
137 | + |
|
138 | + // Fires after registering actions. |
|
139 | + do_action( 'wpinv_actions', $this ); |
|
140 | + do_action( 'getpaid_actions', $this ); |
|
141 | + |
|
142 | + } |
|
143 | + |
|
144 | + public function plugins_loaded() { |
|
145 | + /* Internationalize the text strings used. */ |
|
146 | + $this->load_textdomain(); |
|
147 | + |
|
148 | + do_action( 'wpinv_loaded' ); |
|
149 | + |
|
150 | + // Fix oxygen page builder conflict |
|
151 | + if ( function_exists( 'ct_css_output' ) ) { |
|
152 | + wpinv_oxygen_fix_conflict(); |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Load the translation of the plugin. |
|
158 | + * |
|
159 | + * @since 1.0 |
|
160 | + */ |
|
161 | + public function load_textdomain( $locale = NULL ) { |
|
162 | + if ( empty( $locale ) ) { |
|
163 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
164 | + } |
|
165 | + |
|
166 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
167 | + |
|
168 | + unload_textdomain( 'invoicing' ); |
|
169 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
170 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
171 | + |
|
172 | + /** |
|
173 | + * Define language constants. |
|
174 | + */ |
|
175 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Include required core files used in admin and on the frontend. |
|
180 | + */ |
|
181 | + public function includes() { |
|
182 | + |
|
183 | + // Start with the settings. |
|
184 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
185 | + |
|
186 | + // Packages/libraries. |
|
187 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
188 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
189 | + |
|
190 | + // Load functions. |
|
191 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
192 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
193 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
194 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
195 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
196 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
197 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
198 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
199 | + require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
200 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
202 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
203 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
204 | + require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
205 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
206 | + |
|
207 | + // Register autoloader. |
|
208 | + try { |
|
209 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
210 | + } catch ( Exception $e ) { |
|
211 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
212 | + } |
|
213 | + |
|
214 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
215 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
216 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
217 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
218 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
219 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
220 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
221 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
222 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
223 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
224 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
225 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
226 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
227 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
228 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
229 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
230 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
231 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
232 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
233 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
234 | + |
|
235 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
236 | + GetPaid_Post_Types_Admin::init(); |
|
237 | + |
|
238 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
239 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
240 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
241 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
242 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
243 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
244 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
245 | + // load the user class only on the users.php page |
|
246 | + global $pagenow; |
|
247 | + if($pagenow=='users.php'){ |
|
248 | + new WPInv_Admin_Users(); |
|
249 | + } |
|
250 | + } |
|
251 | + |
|
252 | + // Register cli commands |
|
253 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
255 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
256 | + } |
|
257 | + |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Class autoloader |
|
262 | + * |
|
263 | + * @param string $class_name The name of the class to load. |
|
264 | + * @access public |
|
265 | + * @since 1.0.19 |
|
266 | + * @return void |
|
267 | + */ |
|
268 | + public function autoload( $class_name ) { |
|
269 | + |
|
270 | + // Normalize the class name... |
|
271 | + $class_name = strtolower( $class_name ); |
|
272 | + |
|
273 | + // ... and make sure it is our class. |
|
274 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
275 | + return; |
|
276 | + } |
|
368 | 277 | |
369 | - $localize = array(); |
|
370 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
371 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
372 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
373 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
374 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
375 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
376 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
278 | + // Next, prepare the file name from the class. |
|
279 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
377 | 280 | |
378 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
379 | - |
|
380 | - wp_enqueue_script( 'jquery-blockui' ); |
|
381 | - |
|
382 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
383 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
384 | - |
|
385 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
386 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
387 | - |
|
388 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
389 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script' ), $version, true ); |
|
390 | - } |
|
281 | + // Base path of the classes. |
|
282 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
391 | 283 | |
392 | - public function wpinv_actions() { |
|
393 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
394 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
395 | - } |
|
396 | - } |
|
284 | + // And an array of possible locations in order of importance. |
|
285 | + $locations = array( |
|
286 | + "$plugin_path/includes", |
|
287 | + "$plugin_path/includes/data-stores", |
|
288 | + "$plugin_path/includes/gateways", |
|
289 | + "$plugin_path/includes/payments", |
|
290 | + "$plugin_path/includes/geolocation", |
|
291 | + "$plugin_path/includes/reports", |
|
292 | + "$plugin_path/includes/api", |
|
293 | + "$plugin_path/includes/admin", |
|
294 | + "$plugin_path/includes/admin/meta-boxes", |
|
295 | + ); |
|
397 | 296 | |
398 | - /** |
|
297 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
298 | + |
|
299 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | + include trailingslashit( $location ) . $file_name; |
|
301 | + break; |
|
302 | + } |
|
303 | + |
|
304 | + } |
|
305 | + |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Inits hooks etc. |
|
310 | + */ |
|
311 | + public function init() { |
|
312 | + |
|
313 | + // Fires before getpaid inits. |
|
314 | + do_action( 'before_getpaid_init', $this ); |
|
315 | + |
|
316 | + // Maybe upgrade. |
|
317 | + $this->maybe_upgrade_database(); |
|
318 | + |
|
319 | + // Load default gateways. |
|
320 | + $gateways = apply_filters( |
|
321 | + 'getpaid_default_gateways', |
|
322 | + array( |
|
323 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
324 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
325 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
326 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
327 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
328 | + ) |
|
329 | + ); |
|
330 | + |
|
331 | + foreach ( $gateways as $id => $class ) { |
|
332 | + $this->gateways[ $id ] = new $class(); |
|
333 | + } |
|
334 | + |
|
335 | + // Fires after getpaid inits. |
|
336 | + do_action( 'getpaid_init', $this ); |
|
337 | + |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * Checks if this is an IPN request and processes it. |
|
342 | + */ |
|
343 | + public function maybe_process_ipn() { |
|
344 | + |
|
345 | + // Ensure that this is an IPN request. |
|
346 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
347 | + return; |
|
348 | + } |
|
349 | + |
|
350 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
351 | + |
|
352 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
353 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
354 | + exit; |
|
355 | + |
|
356 | + } |
|
357 | + |
|
358 | + public function enqueue_scripts() { |
|
359 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
360 | + |
|
361 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
362 | + wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
363 | + wp_enqueue_style( 'wpinv_front_style' ); |
|
364 | + |
|
365 | + // Register scripts |
|
366 | + wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
367 | + wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ), true ); |
|
368 | + |
|
369 | + $localize = array(); |
|
370 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
371 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
372 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
373 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
374 | + $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
375 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
376 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
377 | + |
|
378 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
379 | + |
|
380 | + wp_enqueue_script( 'jquery-blockui' ); |
|
381 | + |
|
382 | + wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
383 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
384 | + |
|
385 | + wp_enqueue_script( 'wpinv-front-script' ); |
|
386 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
387 | + |
|
388 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
389 | + wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script' ), $version, true ); |
|
390 | + } |
|
391 | + |
|
392 | + public function wpinv_actions() { |
|
393 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
394 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
395 | + } |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | 399 | * Fires an action after verifying that a user can fire them. |
400 | - * |
|
401 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
402 | - * current user owns the invoice/subscription. |
|
400 | + * |
|
401 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
402 | + * current user owns the invoice/subscription. |
|
403 | 403 | */ |
404 | 404 | public function maybe_do_authenticated_action() { |
405 | 405 | |
406 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
406 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
407 | 407 | |
408 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
409 | - $data = wp_unslash( $_REQUEST ); |
|
410 | - if ( is_user_logged_in() ) { |
|
411 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
412 | - } |
|
408 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
409 | + $data = wp_unslash( $_REQUEST ); |
|
410 | + if ( is_user_logged_in() ) { |
|
411 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
412 | + } |
|
413 | 413 | |
414 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
414 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
415 | 415 | |
416 | - } |
|
416 | + } |
|
417 | 417 | |
418 | 418 | } |
419 | 419 | |
420 | - public function pre_get_posts( $wp_query ) { |
|
421 | - |
|
422 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
423 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
424 | - } |
|
425 | - |
|
426 | - return $wp_query; |
|
427 | - } |
|
428 | - |
|
429 | - public function bp_invoicing_init() { |
|
430 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * Register widgets |
|
435 | - * |
|
436 | - */ |
|
437 | - public function register_widgets() { |
|
438 | - $widgets = apply_filters( |
|
439 | - 'getpaid_widget_classes', |
|
440 | - array( |
|
441 | - 'WPInv_Checkout_Widget', |
|
442 | - 'WPInv_History_Widget', |
|
443 | - 'WPInv_Receipt_Widget', |
|
444 | - 'WPInv_Subscriptions_Widget', |
|
445 | - 'WPInv_Buy_Item_Widget', |
|
446 | - 'WPInv_Messages_Widget', |
|
447 | - 'WPInv_GetPaid_Widget' |
|
448 | - ) |
|
449 | - ); |
|
450 | - |
|
451 | - foreach ( $widgets as $widget ) { |
|
452 | - register_widget( $widget ); |
|
453 | - } |
|
420 | + public function pre_get_posts( $wp_query ) { |
|
421 | + |
|
422 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
423 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
424 | + } |
|
425 | + |
|
426 | + return $wp_query; |
|
427 | + } |
|
428 | + |
|
429 | + public function bp_invoicing_init() { |
|
430 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * Register widgets |
|
435 | + * |
|
436 | + */ |
|
437 | + public function register_widgets() { |
|
438 | + $widgets = apply_filters( |
|
439 | + 'getpaid_widget_classes', |
|
440 | + array( |
|
441 | + 'WPInv_Checkout_Widget', |
|
442 | + 'WPInv_History_Widget', |
|
443 | + 'WPInv_Receipt_Widget', |
|
444 | + 'WPInv_Subscriptions_Widget', |
|
445 | + 'WPInv_Buy_Item_Widget', |
|
446 | + 'WPInv_Messages_Widget', |
|
447 | + 'WPInv_GetPaid_Widget' |
|
448 | + ) |
|
449 | + ); |
|
450 | + |
|
451 | + foreach ( $widgets as $widget ) { |
|
452 | + register_widget( $widget ); |
|
453 | + } |
|
454 | 454 | |
455 | - } |
|
455 | + } |
|
456 | 456 | |
457 | - /** |
|
458 | - * Upgrades the database. |
|
459 | - * |
|
460 | - * @since 2.0.2 |
|
461 | - */ |
|
462 | - public function maybe_upgrade_database() { |
|
457 | + /** |
|
458 | + * Upgrades the database. |
|
459 | + * |
|
460 | + * @since 2.0.2 |
|
461 | + */ |
|
462 | + public function maybe_upgrade_database() { |
|
463 | 463 | |
464 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
464 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
465 | 465 | |
466 | - if ( $wpi_version == WPINV_VERSION ) { |
|
467 | - return; |
|
468 | - } |
|
466 | + if ( $wpi_version == WPINV_VERSION ) { |
|
467 | + return; |
|
468 | + } |
|
469 | 469 | |
470 | - $installer = new GetPaid_Installer(); |
|
470 | + $installer = new GetPaid_Installer(); |
|
471 | 471 | |
472 | - if ( empty( $wpi_version ) ) { |
|
473 | - return $installer->upgrade_db( 0 ); |
|
474 | - } |
|
472 | + if ( empty( $wpi_version ) ) { |
|
473 | + return $installer->upgrade_db( 0 ); |
|
474 | + } |
|
475 | 475 | |
476 | - $upgrades = array( |
|
477 | - '0.0.5' => '004', |
|
478 | - '1.0.3' => '102', |
|
479 | - '2.0.0' => '118', |
|
480 | - ); |
|
476 | + $upgrades = array( |
|
477 | + '0.0.5' => '004', |
|
478 | + '1.0.3' => '102', |
|
479 | + '2.0.0' => '118', |
|
480 | + ); |
|
481 | 481 | |
482 | - foreach ( $upgrades as $key => $method ) { |
|
482 | + foreach ( $upgrades as $key => $method ) { |
|
483 | 483 | |
484 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
485 | - return $installer->upgrade_db( $method ); |
|
486 | - } |
|
484 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
485 | + return $installer->upgrade_db( $method ); |
|
486 | + } |
|
487 | 487 | |
488 | - } |
|
488 | + } |
|
489 | 489 | |
490 | - } |
|
490 | + } |
|
491 | 491 | |
492 | - /** |
|
493 | - * Remove our pages from yoast sitemaps. |
|
494 | - * |
|
495 | - * @since 1.0.19 |
|
496 | - * @param int[] $excluded_posts_ids |
|
497 | - */ |
|
498 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
492 | + /** |
|
493 | + * Remove our pages from yoast sitemaps. |
|
494 | + * |
|
495 | + * @since 1.0.19 |
|
496 | + * @param int[] $excluded_posts_ids |
|
497 | + */ |
|
498 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
499 | 499 | |
500 | - // Ensure that we have an array. |
|
501 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
502 | - $excluded_posts_ids = array(); |
|
503 | - } |
|
500 | + // Ensure that we have an array. |
|
501 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
502 | + $excluded_posts_ids = array(); |
|
503 | + } |
|
504 | 504 | |
505 | - // Prepare our pages. |
|
506 | - $our_pages = array(); |
|
505 | + // Prepare our pages. |
|
506 | + $our_pages = array(); |
|
507 | 507 | |
508 | - // Checkout page. |
|
509 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
508 | + // Checkout page. |
|
509 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
510 | 510 | |
511 | - // Success page. |
|
512 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
511 | + // Success page. |
|
512 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
513 | 513 | |
514 | - // Failure page. |
|
515 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
514 | + // Failure page. |
|
515 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
516 | 516 | |
517 | - // History page. |
|
518 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
517 | + // History page. |
|
518 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
519 | 519 | |
520 | - // Subscriptions page. |
|
521 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
520 | + // Subscriptions page. |
|
521 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
522 | 522 | |
523 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
523 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
524 | 524 | |
525 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
526 | - return array_unique( $excluded_posts_ids ); |
|
525 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
526 | + return array_unique( $excluded_posts_ids ); |
|
527 | 527 | |
528 | - } |
|
528 | + } |
|
529 | 529 | |
530 | - public function wp_footer() { |
|
531 | - echo ' |
|
530 | + public function wp_footer() { |
|
531 | + echo ' |
|
532 | 532 | <div class="bsui"> |
533 | 533 | <div id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog"> |
534 | 534 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
@@ -544,6 +544,6 @@ discard block |
||
544 | 544 | </div> |
545 | 545 | </div> |
546 | 546 | '; |
547 | - } |
|
547 | + } |
|
548 | 548 | |
549 | 549 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 1.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Main Invoicing class. |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * @param string $prop The prop to set. |
57 | 57 | * @param mixed $value The value to retrieve. |
58 | 58 | */ |
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
59 | + public function set($prop, $value) { |
|
60 | + $this->data[$prop] = $value; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | * @param string $prop The prop to set. |
67 | 67 | * @return mixed The value. |
68 | 68 | */ |
69 | - public function get( $prop ) { |
|
69 | + public function get($prop) { |
|
70 | 70 | |
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
71 | + if (isset($this->data[$prop])) { |
|
72 | + return $this->data[$prop]; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | return null; |
@@ -81,23 +81,23 @@ discard block |
||
81 | 81 | public function set_properties() { |
82 | 82 | |
83 | 83 | // Sessions. |
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
84 | + $this->set('session', new WPInv_Session_Handler()); |
|
85 | + $GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility. |
|
86 | 86 | $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
87 | 87 | |
88 | 88 | // Init other objects. |
89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
91 | - $this->set( 'api', new WPInv_API() ); |
|
92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | - $this->set( 'template', new GetPaid_Template() ); |
|
94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
89 | + $this->set('session', new WPInv_Session_Handler()); |
|
90 | + $this->set('notes', new WPInv_Notes()); |
|
91 | + $this->set('api', new WPInv_API()); |
|
92 | + $this->set('post_types', new GetPaid_Post_Types()); |
|
93 | + $this->set('template', new GetPaid_Template()); |
|
94 | + $this->set('admin', new GetPaid_Admin()); |
|
95 | + $this->set('subscriptions', new WPInv_Subscriptions()); |
|
96 | + $this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails()); |
|
97 | + $this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails()); |
|
98 | + $this->set('daily_maintenace', new GetPaid_Daily_Maintenance()); |
|
99 | + $this->set('payment_forms', new GetPaid_Payment_Forms()); |
|
100 | + $this->set('maxmind', new GetPaid_MaxMind_Geolocation()); |
|
101 | 101 | |
102 | 102 | } |
103 | 103 | |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | * Define plugin constants. |
106 | 106 | */ |
107 | 107 | public function define_constants() { |
108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
108 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
109 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
110 | 110 | $this->version = WPINV_VERSION; |
111 | 111 | } |
112 | 112 | |
@@ -117,27 +117,27 @@ discard block |
||
117 | 117 | */ |
118 | 118 | protected function init_hooks() { |
119 | 119 | /* Internationalize the text strings used. */ |
120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
120 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
121 | 121 | |
122 | 122 | // Init the plugin after WordPress inits. |
123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
123 | + add_action('init', array($this, 'init'), 1); |
|
124 | + add_action('init', array($this, 'maybe_process_ipn'), 10); |
|
125 | + add_action('init', array($this, 'wpinv_actions')); |
|
126 | + add_action('init', array($this, 'maybe_do_authenticated_action'), 100); |
|
127 | 127 | |
128 | - if ( class_exists( 'BuddyPress' ) ) { |
|
129 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
128 | + if (class_exists('BuddyPress')) { |
|
129 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
130 | 130 | } |
131 | 131 | |
132 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
133 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
134 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
135 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
136 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
132 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 11); |
|
133 | + add_action('wp_footer', array(&$this, 'wp_footer')); |
|
134 | + add_action('widgets_init', array(&$this, 'register_widgets')); |
|
135 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
136 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
137 | 137 | |
138 | 138 | // Fires after registering actions. |
139 | - do_action( 'wpinv_actions', $this ); |
|
140 | - do_action( 'getpaid_actions', $this ); |
|
139 | + do_action('wpinv_actions', $this); |
|
140 | + do_action('getpaid_actions', $this); |
|
141 | 141 | |
142 | 142 | } |
143 | 143 | |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | /* Internationalize the text strings used. */ |
146 | 146 | $this->load_textdomain(); |
147 | 147 | |
148 | - do_action( 'wpinv_loaded' ); |
|
148 | + do_action('wpinv_loaded'); |
|
149 | 149 | |
150 | 150 | // Fix oxygen page builder conflict |
151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
151 | + if (function_exists('ct_css_output')) { |
|
152 | 152 | wpinv_oxygen_fix_conflict(); |
153 | 153 | } |
154 | 154 | } |
@@ -158,21 +158,21 @@ discard block |
||
158 | 158 | * |
159 | 159 | * @since 1.0 |
160 | 160 | */ |
161 | - public function load_textdomain( $locale = NULL ) { |
|
162 | - if ( empty( $locale ) ) { |
|
163 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
161 | + public function load_textdomain($locale = NULL) { |
|
162 | + if (empty($locale)) { |
|
163 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
164 | 164 | } |
165 | 165 | |
166 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
166 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
167 | 167 | |
168 | - unload_textdomain( 'invoicing' ); |
|
169 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
170 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
168 | + unload_textdomain('invoicing'); |
|
169 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
170 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Define language constants. |
174 | 174 | */ |
175 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
175 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -181,78 +181,78 @@ discard block |
||
181 | 181 | public function includes() { |
182 | 182 | |
183 | 183 | // Start with the settings. |
184 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
184 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
185 | 185 | |
186 | 186 | // Packages/libraries. |
187 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
188 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
187 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
188 | + require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'); |
|
189 | 189 | |
190 | 190 | // Load functions. |
191 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
192 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
199 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
191 | + require_once(WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'); |
|
192 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
193 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
194 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
195 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
196 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
197 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
198 | + require_once(WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'); |
|
199 | + require_once(WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'); |
|
200 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
201 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
202 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
203 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
204 | + require_once(WPINV_PLUGIN_DIR . 'includes/user-functions.php'); |
|
205 | + require_once(WPINV_PLUGIN_DIR . 'includes/error-functions.php'); |
|
206 | 206 | |
207 | 207 | // Register autoloader. |
208 | 208 | try { |
209 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
210 | - } catch ( Exception $e ) { |
|
211 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
209 | + spl_autoload_register(array($this, 'autoload'), true); |
|
210 | + } catch (Exception $e) { |
|
211 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
212 | 212 | } |
213 | 213 | |
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
215 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
216 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
217 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
218 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
219 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
220 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
221 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
234 | - |
|
235 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
214 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
215 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
216 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
217 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
218 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
219 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
220 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
221 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
222 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
223 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
224 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
225 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
226 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
227 | + require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php'); |
|
228 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'); |
|
229 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'); |
|
230 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'); |
|
231 | + require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'); |
|
232 | + require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php'); |
|
233 | + require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php'); |
|
234 | + |
|
235 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
236 | 236 | GetPaid_Post_Types_Admin::init(); |
237 | 237 | |
238 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
244 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
238 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
239 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'); |
|
240 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
241 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
242 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
243 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
244 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'); |
|
245 | 245 | // load the user class only on the users.php page |
246 | 246 | global $pagenow; |
247 | - if($pagenow=='users.php'){ |
|
247 | + if ($pagenow == 'users.php') { |
|
248 | 248 | new WPInv_Admin_Users(); |
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
252 | 252 | // Register cli commands |
253 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
255 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
253 | + if (defined('WP_CLI') && WP_CLI) { |
|
254 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'); |
|
255 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | } |
@@ -265,21 +265,21 @@ discard block |
||
265 | 265 | * @since 1.0.19 |
266 | 266 | * @return void |
267 | 267 | */ |
268 | - public function autoload( $class_name ) { |
|
268 | + public function autoload($class_name) { |
|
269 | 269 | |
270 | 270 | // Normalize the class name... |
271 | - $class_name = strtolower( $class_name ); |
|
271 | + $class_name = strtolower($class_name); |
|
272 | 272 | |
273 | 273 | // ... and make sure it is our class. |
274 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
274 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
275 | 275 | return; |
276 | 276 | } |
277 | 277 | |
278 | 278 | // Next, prepare the file name from the class. |
279 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
279 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
280 | 280 | |
281 | 281 | // Base path of the classes. |
282 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
282 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
283 | 283 | |
284 | 284 | // And an array of possible locations in order of importance. |
285 | 285 | $locations = array( |
@@ -294,10 +294,10 @@ discard block |
||
294 | 294 | "$plugin_path/includes/admin/meta-boxes", |
295 | 295 | ); |
296 | 296 | |
297 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
297 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
298 | 298 | |
299 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | - include trailingslashit( $location ) . $file_name; |
|
299 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
300 | + include trailingslashit($location) . $file_name; |
|
301 | 301 | break; |
302 | 302 | } |
303 | 303 | |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | public function init() { |
312 | 312 | |
313 | 313 | // Fires before getpaid inits. |
314 | - do_action( 'before_getpaid_init', $this ); |
|
314 | + do_action('before_getpaid_init', $this); |
|
315 | 315 | |
316 | 316 | // Maybe upgrade. |
317 | 317 | $this->maybe_upgrade_database(); |
@@ -328,12 +328,12 @@ discard block |
||
328 | 328 | ) |
329 | 329 | ); |
330 | 330 | |
331 | - foreach ( $gateways as $id => $class ) { |
|
332 | - $this->gateways[ $id ] = new $class(); |
|
331 | + foreach ($gateways as $id => $class) { |
|
332 | + $this->gateways[$id] = new $class(); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | // Fires after getpaid inits. |
336 | - do_action( 'getpaid_init', $this ); |
|
336 | + do_action('getpaid_init', $this); |
|
337 | 337 | |
338 | 338 | } |
339 | 339 | |
@@ -343,55 +343,55 @@ discard block |
||
343 | 343 | public function maybe_process_ipn() { |
344 | 344 | |
345 | 345 | // Ensure that this is an IPN request. |
346 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
346 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
347 | 347 | return; |
348 | 348 | } |
349 | 349 | |
350 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
350 | + $gateway = wpinv_clean($_GET['wpi-gateway']); |
|
351 | 351 | |
352 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
353 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
352 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
353 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
354 | 354 | exit; |
355 | 355 | |
356 | 356 | } |
357 | 357 | |
358 | 358 | public function enqueue_scripts() { |
359 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
359 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
360 | 360 | |
361 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
362 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
363 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
361 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css'); |
|
362 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version); |
|
363 | + wp_enqueue_style('wpinv_front_style'); |
|
364 | 364 | |
365 | 365 | // Register scripts |
366 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
367 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ), true ); |
|
366 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
367 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js'), true); |
|
368 | 368 | |
369 | 369 | $localize = array(); |
370 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
371 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
372 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
370 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
371 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
372 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
373 | 373 | $localize['UseTaxes'] = wpinv_use_taxes(); |
374 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
375 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
376 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
374 | + $localize['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
375 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
376 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
377 | 377 | |
378 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
378 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
379 | 379 | |
380 | - wp_enqueue_script( 'jquery-blockui' ); |
|
380 | + wp_enqueue_script('jquery-blockui'); |
|
381 | 381 | |
382 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
383 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
382 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all'); |
|
383 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
384 | 384 | |
385 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
386 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
385 | + wp_enqueue_script('wpinv-front-script'); |
|
386 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
387 | 387 | |
388 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
389 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script' ), $version, true ); |
|
388 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
389 | + wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script'), $version, true); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | public function wpinv_actions() { |
393 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
394 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
393 | + if (isset($_REQUEST['wpi_action'])) { |
|
394 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
395 | 395 | } |
396 | 396 | } |
397 | 397 | |
@@ -403,31 +403,31 @@ discard block |
||
403 | 403 | */ |
404 | 404 | public function maybe_do_authenticated_action() { |
405 | 405 | |
406 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
406 | + if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
407 | 407 | |
408 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
409 | - $data = wp_unslash( $_REQUEST ); |
|
410 | - if ( is_user_logged_in() ) { |
|
411 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
408 | + $key = sanitize_key($_REQUEST['getpaid-action']); |
|
409 | + $data = wp_unslash($_REQUEST); |
|
410 | + if (is_user_logged_in()) { |
|
411 | + do_action("getpaid_authenticated_action_$key", $data); |
|
412 | 412 | } |
413 | 413 | |
414 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
414 | + do_action("getpaid_unauthenticated_action_$key", $data); |
|
415 | 415 | |
416 | 416 | } |
417 | 417 | |
418 | 418 | } |
419 | 419 | |
420 | - public function pre_get_posts( $wp_query ) { |
|
420 | + public function pre_get_posts($wp_query) { |
|
421 | 421 | |
422 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
423 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
422 | + if (!is_admin() && !empty($wp_query->query_vars['post_type']) && getpaid_is_invoice_post_type($wp_query->query_vars['post_type']) && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
423 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type'])); |
|
424 | 424 | } |
425 | 425 | |
426 | 426 | return $wp_query; |
427 | 427 | } |
428 | 428 | |
429 | 429 | public function bp_invoicing_init() { |
430 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
430 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
@@ -448,8 +448,8 @@ discard block |
||
448 | 448 | ) |
449 | 449 | ); |
450 | 450 | |
451 | - foreach ( $widgets as $widget ) { |
|
452 | - register_widget( $widget ); |
|
451 | + foreach ($widgets as $widget) { |
|
452 | + register_widget($widget); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | } |
@@ -461,28 +461,28 @@ discard block |
||
461 | 461 | */ |
462 | 462 | public function maybe_upgrade_database() { |
463 | 463 | |
464 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
464 | + $wpi_version = get_option('wpinv_version', 0); |
|
465 | 465 | |
466 | - if ( $wpi_version == WPINV_VERSION ) { |
|
466 | + if ($wpi_version == WPINV_VERSION) { |
|
467 | 467 | return; |
468 | 468 | } |
469 | 469 | |
470 | 470 | $installer = new GetPaid_Installer(); |
471 | 471 | |
472 | - if ( empty( $wpi_version ) ) { |
|
473 | - return $installer->upgrade_db( 0 ); |
|
472 | + if (empty($wpi_version)) { |
|
473 | + return $installer->upgrade_db(0); |
|
474 | 474 | } |
475 | 475 | |
476 | - $upgrades = array( |
|
476 | + $upgrades = array( |
|
477 | 477 | '0.0.5' => '004', |
478 | 478 | '1.0.3' => '102', |
479 | 479 | '2.0.0' => '118', |
480 | 480 | ); |
481 | 481 | |
482 | - foreach ( $upgrades as $key => $method ) { |
|
482 | + foreach ($upgrades as $key => $method) { |
|
483 | 483 | |
484 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
485 | - return $installer->upgrade_db( $method ); |
|
484 | + if (version_compare($wpi_version, $key, '<')) { |
|
485 | + return $installer->upgrade_db($method); |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | } |
@@ -495,10 +495,10 @@ discard block |
||
495 | 495 | * @since 1.0.19 |
496 | 496 | * @param int[] $excluded_posts_ids |
497 | 497 | */ |
498 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
498 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
499 | 499 | |
500 | 500 | // Ensure that we have an array. |
501 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
501 | + if (!is_array($excluded_posts_ids)) { |
|
502 | 502 | $excluded_posts_ids = array(); |
503 | 503 | } |
504 | 504 | |
@@ -506,24 +506,24 @@ discard block |
||
506 | 506 | $our_pages = array(); |
507 | 507 | |
508 | 508 | // Checkout page. |
509 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
509 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
510 | 510 | |
511 | 511 | // Success page. |
512 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
512 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
513 | 513 | |
514 | 514 | // Failure page. |
515 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
515 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
516 | 516 | |
517 | 517 | // History page. |
518 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
518 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
519 | 519 | |
520 | 520 | // Subscriptions page. |
521 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
521 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
522 | 522 | |
523 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
523 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
524 | 524 | |
525 | 525 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
526 | - return array_unique( $excluded_posts_ids ); |
|
526 | + return array_unique($excluded_posts_ids); |
|
527 | 527 | |
528 | 528 | } |
529 | 529 | |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
535 | 535 | <div class="modal-content"> |
536 | 536 | <div class="modal-body"> |
537 | - <button type="button" class="close p-2 getpaid-payment-modal-close d-sm-none" data-dismiss="modal" aria-label="' . esc_attr__( 'Close', 'invoicing' ) . '"> |
|
537 | + <button type="button" class="close p-2 getpaid-payment-modal-close d-sm-none" data-dismiss="modal" aria-label="' . esc_attr__('Close', 'invoicing') . '"> |
|
538 | 538 | <i class="fa fa-times" aria-hidden="true"></i> |
539 | 539 | </button> |
540 | 540 | <div class="modal-body-wrapper"></div> |
@@ -12,227 +12,227 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Refresh_Prices { |
14 | 14 | |
15 | - /** |
|
16 | - * Contains the response for refreshing prices. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $response = array(); |
|
15 | + /** |
|
16 | + * Contains the response for refreshing prices. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $response = array(); |
|
20 | 20 | |
21 | 21 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - */ |
|
26 | - public function __construct( $submission ) { |
|
27 | - |
|
28 | - $this->response = array( |
|
29 | - 'submission_id' => $submission->id, |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + */ |
|
26 | + public function __construct( $submission ) { |
|
27 | + |
|
28 | + $this->response = array( |
|
29 | + 'submission_id' => $submission->id, |
|
30 | 30 | 'has_recurring' => $submission->has_recurring, |
31 | 31 | 'is_free' => ! $submission->should_collect_payment_details(), |
32 | - ); |
|
33 | - |
|
34 | - $this->add_totals( $submission ); |
|
35 | - $this->add_texts( $submission ); |
|
36 | - $this->add_items( $submission ); |
|
37 | - $this->add_fees( $submission ); |
|
38 | - $this->add_discounts( $submission ); |
|
39 | - $this->add_taxes( $submission ); |
|
40 | - $this->add_gateways( $submission ); |
|
41 | - |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Adds totals to a response for submission refresh prices. |
|
46 | - * |
|
47 | - * @param GetPaid_Payment_Form_Submission $submission |
|
48 | - */ |
|
49 | - public function add_totals( $submission ) { |
|
50 | - |
|
51 | - $this->response = array_merge( |
|
52 | - $this->response, |
|
53 | - array( |
|
54 | - |
|
55 | - 'totals' => array( |
|
56 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
57 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
58 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
59 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
60 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
61 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
62 | - ), |
|
63 | - |
|
64 | - 'recurring' => array( |
|
65 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
66 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
67 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
68 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
69 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
70 | - ), |
|
71 | - |
|
72 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
73 | - 'currency' => $submission->get_currency(), |
|
74 | - |
|
75 | - ) |
|
76 | - ); |
|
77 | - |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Adds texts to a response for submission refresh prices. |
|
82 | - * |
|
83 | - * @param GetPaid_Payment_Form_Submission $submission |
|
84 | - */ |
|
85 | - public function add_texts( $submission ) { |
|
86 | - |
|
87 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
88 | - |
|
89 | - if ( $submission->has_recurring != 0 ) { |
|
90 | - |
|
91 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
92 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
93 | - |
|
94 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
95 | - $payable = "$payable / $period"; |
|
96 | - } else { |
|
97 | - $payable = sprintf( |
|
98 | - __( '%1$s (renews at %2$s / %3$s)'), |
|
99 | - $submission->format_amount( $submission->get_total() ), |
|
100 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
101 | - $period |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - } |
|
106 | - |
|
107 | - $texts = array( |
|
108 | - '.getpaid-checkout-total-payable' => $payable, |
|
109 | - ); |
|
110 | - |
|
111 | - foreach ( $submission->get_items() as $item_id => $item ) { |
|
112 | - $texts[".item-$item_id .getpaid-item-initial-price"] = $submission->format_amount( $item->get_sub_total() ); |
|
113 | - $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() ); |
|
114 | - } |
|
115 | - |
|
116 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
117 | - |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Adds items to a response for submission refresh prices. |
|
122 | - * |
|
123 | - * @param GetPaid_Payment_Form_Submission $submission |
|
124 | - */ |
|
125 | - public function add_items( $submission ) { |
|
126 | - |
|
127 | - // Add items. |
|
128 | - $items = array(); |
|
32 | + ); |
|
33 | + |
|
34 | + $this->add_totals( $submission ); |
|
35 | + $this->add_texts( $submission ); |
|
36 | + $this->add_items( $submission ); |
|
37 | + $this->add_fees( $submission ); |
|
38 | + $this->add_discounts( $submission ); |
|
39 | + $this->add_taxes( $submission ); |
|
40 | + $this->add_gateways( $submission ); |
|
41 | + |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Adds totals to a response for submission refresh prices. |
|
46 | + * |
|
47 | + * @param GetPaid_Payment_Form_Submission $submission |
|
48 | + */ |
|
49 | + public function add_totals( $submission ) { |
|
50 | + |
|
51 | + $this->response = array_merge( |
|
52 | + $this->response, |
|
53 | + array( |
|
54 | + |
|
55 | + 'totals' => array( |
|
56 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
57 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
58 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
59 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
60 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
61 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
62 | + ), |
|
63 | + |
|
64 | + 'recurring' => array( |
|
65 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
66 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
67 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
68 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
69 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
70 | + ), |
|
71 | + |
|
72 | + 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
73 | + 'currency' => $submission->get_currency(), |
|
74 | + |
|
75 | + ) |
|
76 | + ); |
|
77 | + |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Adds texts to a response for submission refresh prices. |
|
82 | + * |
|
83 | + * @param GetPaid_Payment_Form_Submission $submission |
|
84 | + */ |
|
85 | + public function add_texts( $submission ) { |
|
86 | + |
|
87 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
88 | + |
|
89 | + if ( $submission->has_recurring != 0 ) { |
|
90 | + |
|
91 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
92 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
93 | + |
|
94 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
95 | + $payable = "$payable / $period"; |
|
96 | + } else { |
|
97 | + $payable = sprintf( |
|
98 | + __( '%1$s (renews at %2$s / %3$s)'), |
|
99 | + $submission->format_amount( $submission->get_total() ), |
|
100 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
101 | + $period |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + } |
|
106 | + |
|
107 | + $texts = array( |
|
108 | + '.getpaid-checkout-total-payable' => $payable, |
|
109 | + ); |
|
129 | 110 | |
130 | 111 | foreach ( $submission->get_items() as $item_id => $item ) { |
131 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
132 | - } |
|
112 | + $texts[".item-$item_id .getpaid-item-initial-price"] = $submission->format_amount( $item->get_sub_total() ); |
|
113 | + $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() ); |
|
114 | + } |
|
133 | 115 | |
134 | - $this->response = array_merge( |
|
135 | - $this->response, |
|
136 | - array( 'items' => $items ) |
|
137 | - ); |
|
116 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
138 | 117 | |
139 | - } |
|
118 | + } |
|
140 | 119 | |
141 | - /** |
|
142 | - * Adds fees to a response for submission refresh prices. |
|
143 | - * |
|
144 | - * @param GetPaid_Payment_Form_Submission $submission |
|
145 | - */ |
|
146 | - public function add_fees( $submission ) { |
|
120 | + /** |
|
121 | + * Adds items to a response for submission refresh prices. |
|
122 | + * |
|
123 | + * @param GetPaid_Payment_Form_Submission $submission |
|
124 | + */ |
|
125 | + public function add_items( $submission ) { |
|
126 | + |
|
127 | + // Add items. |
|
128 | + $items = array(); |
|
129 | + |
|
130 | + foreach ( $submission->get_items() as $item_id => $item ) { |
|
131 | + $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
132 | + } |
|
133 | + |
|
134 | + $this->response = array_merge( |
|
135 | + $this->response, |
|
136 | + array( 'items' => $items ) |
|
137 | + ); |
|
138 | + |
|
139 | + } |
|
147 | 140 | |
148 | - $fees = array(); |
|
141 | + /** |
|
142 | + * Adds fees to a response for submission refresh prices. |
|
143 | + * |
|
144 | + * @param GetPaid_Payment_Form_Submission $submission |
|
145 | + */ |
|
146 | + public function add_fees( $submission ) { |
|
147 | + |
|
148 | + $fees = array(); |
|
149 | 149 | |
150 | 150 | foreach ( $submission->get_fees() as $name => $data ) { |
151 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
152 | - } |
|
151 | + $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
152 | + } |
|
153 | 153 | |
154 | - $this->response = array_merge( |
|
155 | - $this->response, |
|
156 | - array( 'fees' => $fees ) |
|
157 | - ); |
|
154 | + $this->response = array_merge( |
|
155 | + $this->response, |
|
156 | + array( 'fees' => $fees ) |
|
157 | + ); |
|
158 | 158 | |
159 | - } |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * Adds discounts to a response for submission refresh prices. |
|
163 | - * |
|
164 | - * @param GetPaid_Payment_Form_Submission $submission |
|
165 | - */ |
|
166 | - public function add_discounts( $submission ) { |
|
161 | + /** |
|
162 | + * Adds discounts to a response for submission refresh prices. |
|
163 | + * |
|
164 | + * @param GetPaid_Payment_Form_Submission $submission |
|
165 | + */ |
|
166 | + public function add_discounts( $submission ) { |
|
167 | 167 | |
168 | - $discounts = array(); |
|
168 | + $discounts = array(); |
|
169 | 169 | |
170 | 170 | foreach ( $submission->get_discounts() as $name => $data ) { |
171 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
172 | - } |
|
171 | + $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
172 | + } |
|
173 | 173 | |
174 | - $this->response = array_merge( |
|
175 | - $this->response, |
|
176 | - array( 'discounts' => $discounts ) |
|
177 | - ); |
|
174 | + $this->response = array_merge( |
|
175 | + $this->response, |
|
176 | + array( 'discounts' => $discounts ) |
|
177 | + ); |
|
178 | 178 | |
179 | - } |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * Adds taxes to a response for submission refresh prices. |
|
183 | - * |
|
184 | - * @param GetPaid_Payment_Form_Submission $submission |
|
185 | - */ |
|
186 | - public function add_taxes( $submission ) { |
|
187 | - |
|
188 | - $taxes = array(); |
|
189 | - $markup = ''; |
|
181 | + /** |
|
182 | + * Adds taxes to a response for submission refresh prices. |
|
183 | + * |
|
184 | + * @param GetPaid_Payment_Form_Submission $submission |
|
185 | + */ |
|
186 | + public function add_taxes( $submission ) { |
|
187 | + |
|
188 | + $taxes = array(); |
|
189 | + $markup = ''; |
|
190 | 190 | foreach ( $submission->get_taxes() as $name => $data ) { |
191 | - $name = sanitize_text_field( $name ); |
|
192 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
193 | - $taxes[$name] = $amount; |
|
194 | - $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
195 | - } |
|
191 | + $name = sanitize_text_field( $name ); |
|
192 | + $amount = $submission->format_amount( $data['initial_tax'] ); |
|
193 | + $taxes[$name] = $amount; |
|
194 | + $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
195 | + } |
|
196 | 196 | |
197 | - if ( wpinv_display_individual_tax_rates() ) { |
|
198 | - $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
199 | - } |
|
197 | + if ( wpinv_display_individual_tax_rates() ) { |
|
198 | + $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
199 | + } |
|
200 | 200 | |
201 | - $this->response = array_merge( |
|
202 | - $this->response, |
|
203 | - array( 'taxes' => $taxes ) |
|
204 | - ); |
|
201 | + $this->response = array_merge( |
|
202 | + $this->response, |
|
203 | + array( 'taxes' => $taxes ) |
|
204 | + ); |
|
205 | 205 | |
206 | - } |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * Adds gateways to a response for submission refresh prices. |
|
210 | - * |
|
211 | - * @param GetPaid_Payment_Form_Submission $submission |
|
212 | - */ |
|
213 | - public function add_gateways( $submission ) { |
|
208 | + /** |
|
209 | + * Adds gateways to a response for submission refresh prices. |
|
210 | + * |
|
211 | + * @param GetPaid_Payment_Form_Submission $submission |
|
212 | + */ |
|
213 | + public function add_gateways( $submission ) { |
|
214 | 214 | |
215 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
215 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
216 | 216 | |
217 | - if ( $this->response['has_recurring'] ) { |
|
217 | + if ( $this->response['has_recurring'] ) { |
|
218 | 218 | |
219 | - foreach ( $gateways as $i => $gateway ) { |
|
219 | + foreach ( $gateways as $i => $gateway ) { |
|
220 | 220 | |
221 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
222 | - unset( $gateways[ $i ] ); |
|
223 | - } |
|
221 | + if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
222 | + unset( $gateways[ $i ] ); |
|
223 | + } |
|
224 | 224 | |
225 | - } |
|
225 | + } |
|
226 | 226 | |
227 | - } |
|
227 | + } |
|
228 | 228 | |
229 | 229 | |
230 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
231 | - $this->response = array_merge( |
|
232 | - $this->response, |
|
233 | - array( 'gateways' => $gateways ) |
|
234 | - ); |
|
230 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
231 | + $this->response = array_merge( |
|
232 | + $this->response, |
|
233 | + array( 'gateways' => $gateways ) |
|
234 | + ); |
|
235 | 235 | |
236 | - } |
|
236 | + } |
|
237 | 237 | |
238 | 238 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment form submission refresh prices class |
@@ -23,21 +23,21 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param GetPaid_Payment_Form_Submission $submission |
25 | 25 | */ |
26 | - public function __construct( $submission ) { |
|
26 | + public function __construct($submission) { |
|
27 | 27 | |
28 | 28 | $this->response = array( |
29 | 29 | 'submission_id' => $submission->id, |
30 | 30 | 'has_recurring' => $submission->has_recurring, |
31 | - 'is_free' => ! $submission->should_collect_payment_details(), |
|
31 | + 'is_free' => !$submission->should_collect_payment_details(), |
|
32 | 32 | ); |
33 | 33 | |
34 | - $this->add_totals( $submission ); |
|
35 | - $this->add_texts( $submission ); |
|
36 | - $this->add_items( $submission ); |
|
37 | - $this->add_fees( $submission ); |
|
38 | - $this->add_discounts( $submission ); |
|
39 | - $this->add_taxes( $submission ); |
|
40 | - $this->add_gateways( $submission ); |
|
34 | + $this->add_totals($submission); |
|
35 | + $this->add_texts($submission); |
|
36 | + $this->add_items($submission); |
|
37 | + $this->add_fees($submission); |
|
38 | + $this->add_discounts($submission); |
|
39 | + $this->add_taxes($submission); |
|
40 | + $this->add_gateways($submission); |
|
41 | 41 | |
42 | 42 | } |
43 | 43 | |
@@ -46,30 +46,30 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @param GetPaid_Payment_Form_Submission $submission |
48 | 48 | */ |
49 | - public function add_totals( $submission ) { |
|
49 | + public function add_totals($submission) { |
|
50 | 50 | |
51 | 51 | $this->response = array_merge( |
52 | 52 | $this->response, |
53 | 53 | array( |
54 | 54 | |
55 | 55 | 'totals' => array( |
56 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
57 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
58 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
59 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
60 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
61 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
56 | + 'subtotal' => $submission->format_amount($submission->get_subtotal()), |
|
57 | + 'discount' => $submission->format_amount($submission->get_discount()), |
|
58 | + 'fees' => $submission->format_amount($submission->get_fee()), |
|
59 | + 'tax' => $submission->format_amount($submission->get_tax()), |
|
60 | + 'total' => $submission->format_amount($submission->get_total()), |
|
61 | + 'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES), |
|
62 | 62 | ), |
63 | 63 | |
64 | 64 | 'recurring' => array( |
65 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
66 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
67 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
68 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
69 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
65 | + 'subtotal' => $submission->format_amount($submission->get_recurring_subtotal()), |
|
66 | + 'discount' => $submission->format_amount($submission->get_recurring_discount()), |
|
67 | + 'fees' => $submission->format_amount($submission->get_recurring_fee()), |
|
68 | + 'tax' => $submission->format_amount($submission->get_recurring_tax()), |
|
69 | + 'total' => $submission->format_amount($submission->get_recurring_total()), |
|
70 | 70 | ), |
71 | 71 | |
72 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
72 | + 'initial_amt' => wpinv_round_amount($submission->get_total(), null, true), |
|
73 | 73 | 'currency' => $submission->get_currency(), |
74 | 74 | |
75 | 75 | ) |
@@ -82,22 +82,22 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @param GetPaid_Payment_Form_Submission $submission |
84 | 84 | */ |
85 | - public function add_texts( $submission ) { |
|
85 | + public function add_texts($submission) { |
|
86 | 86 | |
87 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
87 | + $payable = $submission->format_amount($submission->get_total()); |
|
88 | 88 | |
89 | - if ( $submission->has_recurring != 0 ) { |
|
89 | + if ($submission->has_recurring != 0) { |
|
90 | 90 | |
91 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
92 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
91 | + $recurring = new WPInv_Item($submission->has_recurring); |
|
92 | + $period = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), ''); |
|
93 | 93 | |
94 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
94 | + if ($submission->get_total() == $submission->get_recurring_total()) { |
|
95 | 95 | $payable = "$payable / $period"; |
96 | 96 | } else { |
97 | 97 | $payable = sprintf( |
98 | - __( '%1$s (renews at %2$s / %3$s)'), |
|
99 | - $submission->format_amount( $submission->get_total() ), |
|
100 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
98 | + __('%1$s (renews at %2$s / %3$s)'), |
|
99 | + $submission->format_amount($submission->get_total()), |
|
100 | + $submission->format_amount($submission->get_recurring_total()), |
|
101 | 101 | $period |
102 | 102 | ); |
103 | 103 | } |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | '.getpaid-checkout-total-payable' => $payable, |
109 | 109 | ); |
110 | 110 | |
111 | - foreach ( $submission->get_items() as $item_id => $item ) { |
|
112 | - $texts[".item-$item_id .getpaid-item-initial-price"] = $submission->format_amount( $item->get_sub_total() ); |
|
113 | - $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() ); |
|
111 | + foreach ($submission->get_items() as $item_id => $item) { |
|
112 | + $texts[".item-$item_id .getpaid-item-initial-price"] = $submission->format_amount($item->get_sub_total()); |
|
113 | + $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount($item->get_recurring_sub_total()); |
|
114 | 114 | } |
115 | 115 | |
116 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
116 | + $this->response = array_merge($this->response, array('texts' => $texts)); |
|
117 | 117 | |
118 | 118 | } |
119 | 119 | |
@@ -122,18 +122,18 @@ discard block |
||
122 | 122 | * |
123 | 123 | * @param GetPaid_Payment_Form_Submission $submission |
124 | 124 | */ |
125 | - public function add_items( $submission ) { |
|
125 | + public function add_items($submission) { |
|
126 | 126 | |
127 | 127 | // Add items. |
128 | 128 | $items = array(); |
129 | 129 | |
130 | - foreach ( $submission->get_items() as $item_id => $item ) { |
|
131 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
130 | + foreach ($submission->get_items() as $item_id => $item) { |
|
131 | + $items["$item_id"] = $submission->format_amount($item->get_sub_total()); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | $this->response = array_merge( |
135 | 135 | $this->response, |
136 | - array( 'items' => $items ) |
|
136 | + array('items' => $items) |
|
137 | 137 | ); |
138 | 138 | |
139 | 139 | } |
@@ -143,17 +143,17 @@ discard block |
||
143 | 143 | * |
144 | 144 | * @param GetPaid_Payment_Form_Submission $submission |
145 | 145 | */ |
146 | - public function add_fees( $submission ) { |
|
146 | + public function add_fees($submission) { |
|
147 | 147 | |
148 | 148 | $fees = array(); |
149 | 149 | |
150 | - foreach ( $submission->get_fees() as $name => $data ) { |
|
151 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
150 | + foreach ($submission->get_fees() as $name => $data) { |
|
151 | + $fees[$name] = $submission->format_amount($data['initial_fee']); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | $this->response = array_merge( |
155 | 155 | $this->response, |
156 | - array( 'fees' => $fees ) |
|
156 | + array('fees' => $fees) |
|
157 | 157 | ); |
158 | 158 | |
159 | 159 | } |
@@ -163,17 +163,17 @@ discard block |
||
163 | 163 | * |
164 | 164 | * @param GetPaid_Payment_Form_Submission $submission |
165 | 165 | */ |
166 | - public function add_discounts( $submission ) { |
|
166 | + public function add_discounts($submission) { |
|
167 | 167 | |
168 | 168 | $discounts = array(); |
169 | 169 | |
170 | - foreach ( $submission->get_discounts() as $name => $data ) { |
|
171 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
170 | + foreach ($submission->get_discounts() as $name => $data) { |
|
171 | + $discounts[$name] = $submission->format_amount($data['initial_discount']); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | $this->response = array_merge( |
175 | 175 | $this->response, |
176 | - array( 'discounts' => $discounts ) |
|
176 | + array('discounts' => $discounts) |
|
177 | 177 | ); |
178 | 178 | |
179 | 179 | } |
@@ -183,24 +183,24 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @param GetPaid_Payment_Form_Submission $submission |
185 | 185 | */ |
186 | - public function add_taxes( $submission ) { |
|
186 | + public function add_taxes($submission) { |
|
187 | 187 | |
188 | 188 | $taxes = array(); |
189 | 189 | $markup = ''; |
190 | - foreach ( $submission->get_taxes() as $name => $data ) { |
|
191 | - $name = sanitize_text_field( $name ); |
|
192 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
190 | + foreach ($submission->get_taxes() as $name => $data) { |
|
191 | + $name = sanitize_text_field($name); |
|
192 | + $amount = $submission->format_amount($data['initial_tax']); |
|
193 | 193 | $taxes[$name] = $amount; |
194 | 194 | $markup .= "<small class='form-text'>$name : $amount</small>"; |
195 | 195 | } |
196 | 196 | |
197 | - if ( wpinv_display_individual_tax_rates() ) { |
|
197 | + if (wpinv_display_individual_tax_rates()) { |
|
198 | 198 | $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
199 | 199 | } |
200 | 200 | |
201 | 201 | $this->response = array_merge( |
202 | 202 | $this->response, |
203 | - array( 'taxes' => $taxes ) |
|
203 | + array('taxes' => $taxes) |
|
204 | 204 | ); |
205 | 205 | |
206 | 206 | } |
@@ -210,16 +210,16 @@ discard block |
||
210 | 210 | * |
211 | 211 | * @param GetPaid_Payment_Form_Submission $submission |
212 | 212 | */ |
213 | - public function add_gateways( $submission ) { |
|
213 | + public function add_gateways($submission) { |
|
214 | 214 | |
215 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
215 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
216 | 216 | |
217 | - if ( $this->response['has_recurring'] ) { |
|
217 | + if ($this->response['has_recurring']) { |
|
218 | 218 | |
219 | - foreach ( $gateways as $i => $gateway ) { |
|
219 | + foreach ($gateways as $i => $gateway) { |
|
220 | 220 | |
221 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
222 | - unset( $gateways[ $i ] ); |
|
221 | + if (!wpinv_gateway_support_subscription($gateway)) { |
|
222 | + unset($gateways[$i]); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | } |
@@ -227,10 +227,10 @@ discard block |
||
227 | 227 | } |
228 | 228 | |
229 | 229 | |
230 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
230 | + $gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission); |
|
231 | 231 | $this->response = array_merge( |
232 | 232 | $this->response, |
233 | - array( 'gateways' => $gateways ) |
|
233 | + array('gateways' => $gateways) |
|
234 | 234 | ); |
235 | 235 | |
236 | 236 | } |
@@ -7,35 +7,35 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | $value = ''; |
13 | 13 | $class = ''; |
14 | 14 | |
15 | -if ( ! empty( $form->invoice ) ) { |
|
16 | - $value = sanitize_email( $form->invoice->get_email() ); |
|
17 | -} else if ( is_user_logged_in() ) { |
|
15 | +if (!empty($form->invoice)) { |
|
16 | + $value = sanitize_email($form->invoice->get_email()); |
|
17 | +} else if (is_user_logged_in()) { |
|
18 | 18 | $user = wp_get_current_user(); |
19 | - $value = sanitize_email( $user->user_email ); |
|
19 | + $value = sanitize_email($user->user_email); |
|
20 | 20 | } |
21 | 21 | |
22 | -if ( ! empty( $value ) && ! empty( $hide_billing_email ) ) { |
|
22 | +if (!empty($value) && !empty($hide_billing_email)) { |
|
23 | 23 | $class = 'd-none'; |
24 | 24 | } |
25 | 25 | |
26 | -do_action( 'getpaid_before_payment_form_billing_email', $form ); |
|
26 | +do_action('getpaid_before_payment_form_billing_email', $form); |
|
27 | 27 | |
28 | 28 | echo "<span class='$class'>"; |
29 | 29 | |
30 | 30 | echo aui()->input( |
31 | 31 | array( |
32 | 32 | 'name' => 'billing_email', |
33 | - 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
34 | - 'placeholder'=> empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
35 | - 'required' => ! empty( $required ), |
|
36 | - 'label' => empty( $label ) ? '' : wp_kses_post( $label ) . '<span class="text-danger"> *</span>', |
|
33 | + 'id' => esc_attr($id) . uniqid('_'), |
|
34 | + 'placeholder'=> empty($placeholder) ? '' : esc_attr($placeholder), |
|
35 | + 'required' => !empty($required), |
|
36 | + 'label' => empty($label) ? '' : wp_kses_post($label) . '<span class="text-danger"> *</span>', |
|
37 | 37 | 'label_type' => 'vertical', |
38 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
38 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
39 | 39 | 'type' => 'email', |
40 | 40 | 'value' => $value, |
41 | 41 | 'class' => 'wpinv_billing_email', |
@@ -47,4 +47,4 @@ discard block |
||
47 | 47 | |
48 | 48 | echo '</span>'; |
49 | 49 | |
50 | -do_action( 'getpaid_after_payment_form_billing_email', $form ); |
|
50 | +do_action('getpaid_after_payment_form_billing_email', $form); |