@@ -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,514 +391,514 @@ 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 | - $this->save(); |
|
509 | - } |
|
510 | - |
|
511 | - /** |
|
512 | - * Update meta data by key or ID, if provided. |
|
513 | - * |
|
514 | - * @since 1.0.19 |
|
515 | - * |
|
516 | - * @param string $key Meta key. |
|
517 | - * @param string|array $value Meta value. |
|
518 | - * @param int $meta_id Meta ID. |
|
519 | - */ |
|
520 | - public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
521 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
522 | - $function = 'set_' . $key; |
|
523 | - |
|
524 | - if ( is_callable( array( $this, $function ) ) ) { |
|
525 | - return $this->{$function}( $value ); |
|
526 | - } |
|
527 | - } |
|
528 | - |
|
529 | - $this->maybe_read_meta_data(); |
|
530 | - |
|
531 | - $array_key = false; |
|
532 | - |
|
533 | - if ( $meta_id ) { |
|
534 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
535 | - $array_key = $array_keys ? current( $array_keys ) : false; |
|
536 | - } else { |
|
537 | - // Find matches by key. |
|
538 | - $matches = array(); |
|
539 | - foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
540 | - if ( $meta->key === $key ) { |
|
541 | - $matches[] = $meta_data_array_key; |
|
542 | - } |
|
543 | - } |
|
544 | - |
|
545 | - if ( ! empty( $matches ) ) { |
|
546 | - // Set matches to null so only one key gets the new value. |
|
547 | - foreach ( $matches as $meta_data_array_key ) { |
|
548 | - $this->meta_data[ $meta_data_array_key ]->value = null; |
|
549 | - } |
|
550 | - $array_key = current( $matches ); |
|
551 | - } |
|
552 | - } |
|
553 | - |
|
554 | - if ( false !== $array_key ) { |
|
555 | - $meta = $this->meta_data[ $array_key ]; |
|
556 | - $meta->key = $key; |
|
557 | - $meta->value = $value; |
|
558 | - } else { |
|
559 | - $this->add_meta_data( $key, $value, true ); |
|
560 | - } |
|
561 | - } |
|
562 | - |
|
563 | - /** |
|
564 | - * Delete meta data. |
|
565 | - * |
|
566 | - * @since 1.0.19 |
|
567 | - * @param string $key Meta key. |
|
568 | - */ |
|
569 | - public function delete_meta_data( $key ) { |
|
570 | - $this->maybe_read_meta_data(); |
|
571 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
572 | - |
|
573 | - if ( $array_keys ) { |
|
574 | - foreach ( $array_keys as $array_key ) { |
|
575 | - $this->meta_data[ $array_key ]->value = null; |
|
576 | - } |
|
577 | - } |
|
578 | - } |
|
579 | - |
|
580 | - /** |
|
581 | - * Delete meta data. |
|
582 | - * |
|
583 | - * @since 1.0.19 |
|
584 | - * @param int $mid Meta ID. |
|
585 | - */ |
|
586 | - public function delete_meta_data_by_mid( $mid ) { |
|
587 | - $this->maybe_read_meta_data(); |
|
588 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
589 | - |
|
590 | - if ( $array_keys ) { |
|
591 | - foreach ( $array_keys as $array_key ) { |
|
592 | - $this->meta_data[ $array_key ]->value = null; |
|
593 | - } |
|
594 | - } |
|
595 | - } |
|
596 | - |
|
597 | - /** |
|
598 | - * Read meta data if null. |
|
599 | - * |
|
600 | - * @since 1.0.19 |
|
601 | - */ |
|
602 | - protected function maybe_read_meta_data() { |
|
603 | - if ( is_null( $this->meta_data ) ) { |
|
604 | - $this->read_meta_data(); |
|
605 | - } |
|
606 | - } |
|
607 | - |
|
608 | - /** |
|
609 | - * Read Meta Data from the database. Ignore any internal properties. |
|
610 | - * Uses it's own caches because get_metadata does not provide meta_ids. |
|
611 | - * |
|
612 | - * @since 1.0.19 |
|
613 | - * @param bool $force_read True to force a new DB read (and update cache). |
|
614 | - */ |
|
615 | - public function read_meta_data( $force_read = false ) { |
|
616 | - |
|
617 | - // Reset meta data. |
|
618 | - $this->meta_data = array(); |
|
619 | - |
|
620 | - // Maybe abort early. |
|
621 | - if ( ! $this->get_id() || ! $this->data_store ) { |
|
622 | - return; |
|
623 | - } |
|
624 | - |
|
625 | - // Only read from cache if the cache key is set. |
|
626 | - $cache_key = null; |
|
627 | - if ( ! $force_read && ! empty( $this->cache_group ) ) { |
|
628 | - $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(); |
|
629 | - $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group ); |
|
630 | - } |
|
631 | - |
|
632 | - // Should we force read? |
|
633 | - if ( empty( $raw_meta_data ) ) { |
|
634 | - $raw_meta_data = $this->data_store->read_meta( $this ); |
|
635 | - |
|
636 | - if ( ! empty( $cache_key ) ) { |
|
637 | - wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
638 | - } |
|
639 | - |
|
640 | - } |
|
641 | - |
|
642 | - // Set meta data. |
|
643 | - if ( is_array( $raw_meta_data ) ) { |
|
644 | - |
|
645 | - foreach ( $raw_meta_data as $meta ) { |
|
646 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
647 | - array( |
|
648 | - 'id' => (int) $meta->meta_id, |
|
649 | - 'key' => $meta->meta_key, |
|
650 | - 'value' => maybe_unserialize( $meta->meta_value ), |
|
651 | - ) |
|
652 | - ); |
|
653 | - } |
|
654 | - |
|
655 | - } |
|
656 | - |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * Update Meta Data in the database. |
|
661 | - * |
|
662 | - * @since 1.0.19 |
|
663 | - */ |
|
664 | - public function save_meta_data() { |
|
665 | - if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
666 | - return; |
|
667 | - } |
|
668 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
669 | - if ( is_null( $meta->value ) ) { |
|
670 | - if ( ! empty( $meta->id ) ) { |
|
671 | - $this->data_store->delete_meta( $this, $meta ); |
|
672 | - unset( $this->meta_data[ $array_key ] ); |
|
673 | - } |
|
674 | - } elseif ( empty( $meta->id ) ) { |
|
675 | - $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
676 | - $meta->apply_changes(); |
|
677 | - } else { |
|
678 | - if ( $meta->get_changes() ) { |
|
679 | - $this->data_store->update_meta( $this, $meta ); |
|
680 | - $meta->apply_changes(); |
|
681 | - } |
|
682 | - } |
|
683 | - } |
|
684 | - if ( ! empty( $this->cache_group ) ) { |
|
685 | - $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(); |
|
686 | - wp_cache_delete( $cache_key, $this->cache_group ); |
|
687 | - } |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Set ID. |
|
692 | - * |
|
693 | - * @since 1.0.19 |
|
694 | - * @param int $id ID. |
|
695 | - */ |
|
696 | - public function set_id( $id ) { |
|
697 | - $this->id = absint( $id ); |
|
698 | - } |
|
699 | - |
|
700 | - /** |
|
701 | - * Sets item status. |
|
702 | - * |
|
703 | - * @since 1.0.19 |
|
704 | - * @param string $status New status. |
|
705 | - * @return array details of change. |
|
706 | - */ |
|
707 | - 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 | + $this->save(); |
|
509 | + } |
|
510 | + |
|
511 | + /** |
|
512 | + * Update meta data by key or ID, if provided. |
|
513 | + * |
|
514 | + * @since 1.0.19 |
|
515 | + * |
|
516 | + * @param string $key Meta key. |
|
517 | + * @param string|array $value Meta value. |
|
518 | + * @param int $meta_id Meta ID. |
|
519 | + */ |
|
520 | + public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
521 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
522 | + $function = 'set_' . $key; |
|
523 | + |
|
524 | + if ( is_callable( array( $this, $function ) ) ) { |
|
525 | + return $this->{$function}( $value ); |
|
526 | + } |
|
527 | + } |
|
528 | + |
|
529 | + $this->maybe_read_meta_data(); |
|
530 | + |
|
531 | + $array_key = false; |
|
532 | + |
|
533 | + if ( $meta_id ) { |
|
534 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
535 | + $array_key = $array_keys ? current( $array_keys ) : false; |
|
536 | + } else { |
|
537 | + // Find matches by key. |
|
538 | + $matches = array(); |
|
539 | + foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
540 | + if ( $meta->key === $key ) { |
|
541 | + $matches[] = $meta_data_array_key; |
|
542 | + } |
|
543 | + } |
|
544 | + |
|
545 | + if ( ! empty( $matches ) ) { |
|
546 | + // Set matches to null so only one key gets the new value. |
|
547 | + foreach ( $matches as $meta_data_array_key ) { |
|
548 | + $this->meta_data[ $meta_data_array_key ]->value = null; |
|
549 | + } |
|
550 | + $array_key = current( $matches ); |
|
551 | + } |
|
552 | + } |
|
553 | + |
|
554 | + if ( false !== $array_key ) { |
|
555 | + $meta = $this->meta_data[ $array_key ]; |
|
556 | + $meta->key = $key; |
|
557 | + $meta->value = $value; |
|
558 | + } else { |
|
559 | + $this->add_meta_data( $key, $value, true ); |
|
560 | + } |
|
561 | + } |
|
562 | + |
|
563 | + /** |
|
564 | + * Delete meta data. |
|
565 | + * |
|
566 | + * @since 1.0.19 |
|
567 | + * @param string $key Meta key. |
|
568 | + */ |
|
569 | + public function delete_meta_data( $key ) { |
|
570 | + $this->maybe_read_meta_data(); |
|
571 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
572 | + |
|
573 | + if ( $array_keys ) { |
|
574 | + foreach ( $array_keys as $array_key ) { |
|
575 | + $this->meta_data[ $array_key ]->value = null; |
|
576 | + } |
|
577 | + } |
|
578 | + } |
|
579 | + |
|
580 | + /** |
|
581 | + * Delete meta data. |
|
582 | + * |
|
583 | + * @since 1.0.19 |
|
584 | + * @param int $mid Meta ID. |
|
585 | + */ |
|
586 | + public function delete_meta_data_by_mid( $mid ) { |
|
587 | + $this->maybe_read_meta_data(); |
|
588 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
589 | + |
|
590 | + if ( $array_keys ) { |
|
591 | + foreach ( $array_keys as $array_key ) { |
|
592 | + $this->meta_data[ $array_key ]->value = null; |
|
593 | + } |
|
594 | + } |
|
595 | + } |
|
596 | + |
|
597 | + /** |
|
598 | + * Read meta data if null. |
|
599 | + * |
|
600 | + * @since 1.0.19 |
|
601 | + */ |
|
602 | + protected function maybe_read_meta_data() { |
|
603 | + if ( is_null( $this->meta_data ) ) { |
|
604 | + $this->read_meta_data(); |
|
605 | + } |
|
606 | + } |
|
607 | + |
|
608 | + /** |
|
609 | + * Read Meta Data from the database. Ignore any internal properties. |
|
610 | + * Uses it's own caches because get_metadata does not provide meta_ids. |
|
611 | + * |
|
612 | + * @since 1.0.19 |
|
613 | + * @param bool $force_read True to force a new DB read (and update cache). |
|
614 | + */ |
|
615 | + public function read_meta_data( $force_read = false ) { |
|
616 | + |
|
617 | + // Reset meta data. |
|
618 | + $this->meta_data = array(); |
|
619 | + |
|
620 | + // Maybe abort early. |
|
621 | + if ( ! $this->get_id() || ! $this->data_store ) { |
|
622 | + return; |
|
623 | + } |
|
624 | + |
|
625 | + // Only read from cache if the cache key is set. |
|
626 | + $cache_key = null; |
|
627 | + if ( ! $force_read && ! empty( $this->cache_group ) ) { |
|
628 | + $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(); |
|
629 | + $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group ); |
|
630 | + } |
|
631 | + |
|
632 | + // Should we force read? |
|
633 | + if ( empty( $raw_meta_data ) ) { |
|
634 | + $raw_meta_data = $this->data_store->read_meta( $this ); |
|
635 | + |
|
636 | + if ( ! empty( $cache_key ) ) { |
|
637 | + wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
638 | + } |
|
639 | + |
|
640 | + } |
|
641 | + |
|
642 | + // Set meta data. |
|
643 | + if ( is_array( $raw_meta_data ) ) { |
|
644 | + |
|
645 | + foreach ( $raw_meta_data as $meta ) { |
|
646 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
647 | + array( |
|
648 | + 'id' => (int) $meta->meta_id, |
|
649 | + 'key' => $meta->meta_key, |
|
650 | + 'value' => maybe_unserialize( $meta->meta_value ), |
|
651 | + ) |
|
652 | + ); |
|
653 | + } |
|
654 | + |
|
655 | + } |
|
656 | + |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * Update Meta Data in the database. |
|
661 | + * |
|
662 | + * @since 1.0.19 |
|
663 | + */ |
|
664 | + public function save_meta_data() { |
|
665 | + if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
666 | + return; |
|
667 | + } |
|
668 | + foreach ( $this->meta_data as $array_key => $meta ) { |
|
669 | + if ( is_null( $meta->value ) ) { |
|
670 | + if ( ! empty( $meta->id ) ) { |
|
671 | + $this->data_store->delete_meta( $this, $meta ); |
|
672 | + unset( $this->meta_data[ $array_key ] ); |
|
673 | + } |
|
674 | + } elseif ( empty( $meta->id ) ) { |
|
675 | + $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
676 | + $meta->apply_changes(); |
|
677 | + } else { |
|
678 | + if ( $meta->get_changes() ) { |
|
679 | + $this->data_store->update_meta( $this, $meta ); |
|
680 | + $meta->apply_changes(); |
|
681 | + } |
|
682 | + } |
|
683 | + } |
|
684 | + if ( ! empty( $this->cache_group ) ) { |
|
685 | + $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(); |
|
686 | + wp_cache_delete( $cache_key, $this->cache_group ); |
|
687 | + } |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Set ID. |
|
692 | + * |
|
693 | + * @since 1.0.19 |
|
694 | + * @param int $id ID. |
|
695 | + */ |
|
696 | + public function set_id( $id ) { |
|
697 | + $this->id = absint( $id ); |
|
698 | + } |
|
699 | + |
|
700 | + /** |
|
701 | + * Sets item status. |
|
702 | + * |
|
703 | + * @since 1.0.19 |
|
704 | + * @param string $status New status. |
|
705 | + * @return array details of change. |
|
706 | + */ |
|
707 | + public function set_status( $status ) { |
|
708 | 708 | $old_status = $this->get_status(); |
709 | 709 | |
710 | - $this->set_prop( 'status', $status ); |
|
711 | - |
|
712 | - return array( |
|
713 | - 'from' => $old_status, |
|
714 | - 'to' => $status, |
|
715 | - ); |
|
716 | - } |
|
717 | - |
|
718 | - /** |
|
719 | - * Set all props to default values. |
|
720 | - * |
|
721 | - * @since 1.0.19 |
|
722 | - */ |
|
723 | - public function set_defaults() { |
|
724 | - $this->data = $this->default_data; |
|
725 | - $this->changes = array(); |
|
726 | - $this->set_object_read( false ); |
|
727 | - } |
|
728 | - |
|
729 | - /** |
|
730 | - * Set object read property. |
|
731 | - * |
|
732 | - * @since 1.0.19 |
|
733 | - * @param boolean $read Should read?. |
|
734 | - */ |
|
735 | - public function set_object_read( $read = true ) { |
|
736 | - $this->object_read = (bool) $read; |
|
737 | - } |
|
738 | - |
|
739 | - /** |
|
740 | - * Get object read property. |
|
741 | - * |
|
742 | - * @since 1.0.19 |
|
743 | - * @return boolean |
|
744 | - */ |
|
745 | - public function get_object_read() { |
|
746 | - return (bool) $this->object_read; |
|
747 | - } |
|
748 | - |
|
749 | - /** |
|
750 | - * Set a collection of props in one go, collect any errors, and return the result. |
|
751 | - * Only sets using public methods. |
|
752 | - * |
|
753 | - * @since 1.0.19 |
|
754 | - * |
|
755 | - * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
756 | - * @param string $context In what context to run this. |
|
757 | - * |
|
758 | - * @return bool|WP_Error |
|
759 | - */ |
|
760 | - public function set_props( $props, $context = 'set' ) { |
|
761 | - $errors = false; |
|
762 | - |
|
763 | - foreach ( $props as $prop => $value ) { |
|
764 | - try { |
|
765 | - /** |
|
766 | - * Checks if the prop being set is allowed, and the value is not null. |
|
767 | - */ |
|
768 | - if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
769 | - continue; |
|
770 | - } |
|
771 | - $setter = "set_$prop"; |
|
772 | - |
|
773 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
774 | - $this->{$setter}( $value ); |
|
775 | - } |
|
776 | - } catch ( Exception $e ) { |
|
777 | - if ( ! $errors ) { |
|
778 | - $errors = new WP_Error(); |
|
779 | - } |
|
780 | - $errors->add( $e->getCode(), $e->getMessage() ); |
|
781 | - $this->last_error = $e->getMessage(); |
|
782 | - } |
|
783 | - } |
|
784 | - |
|
785 | - return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
786 | - } |
|
787 | - |
|
788 | - /** |
|
789 | - * Sets a prop for a setter method. |
|
790 | - * |
|
791 | - * This stores changes in a special array so we can track what needs saving |
|
792 | - * the the DB later. |
|
793 | - * |
|
794 | - * @since 1.0.19 |
|
795 | - * @param string $prop Name of prop to set. |
|
796 | - * @param mixed $value Value of the prop. |
|
797 | - */ |
|
798 | - protected function set_prop( $prop, $value ) { |
|
799 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
800 | - if ( true === $this->object_read ) { |
|
801 | - if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
802 | - $this->changes[ $prop ] = $value; |
|
803 | - } |
|
804 | - } else { |
|
805 | - $this->data[ $prop ] = $value; |
|
806 | - } |
|
807 | - } |
|
808 | - } |
|
809 | - |
|
810 | - /** |
|
811 | - * Return data changes only. |
|
812 | - * |
|
813 | - * @since 1.0.19 |
|
814 | - * @return array |
|
815 | - */ |
|
816 | - public function get_changes() { |
|
817 | - return $this->changes; |
|
818 | - } |
|
819 | - |
|
820 | - /** |
|
821 | - * Merge changes with data and clear. |
|
822 | - * |
|
823 | - * @since 1.0.19 |
|
824 | - */ |
|
825 | - public function apply_changes() { |
|
826 | - $this->data = array_replace( $this->data, $this->changes ); |
|
827 | - $this->changes = array(); |
|
828 | - } |
|
829 | - |
|
830 | - /** |
|
831 | - * Prefix for action and filter hooks on data. |
|
832 | - * |
|
833 | - * @since 1.0.19 |
|
834 | - * @return string |
|
835 | - */ |
|
836 | - protected function get_hook_prefix() { |
|
837 | - return 'wpinv_get_' . $this->object_type . '_'; |
|
838 | - } |
|
839 | - |
|
840 | - /** |
|
841 | - * Gets a prop for a getter method. |
|
842 | - * |
|
843 | - * Gets the value from either current pending changes, or the data itself. |
|
844 | - * Context controls what happens to the value before it's returned. |
|
845 | - * |
|
846 | - * @since 1.0.19 |
|
847 | - * @param string $prop Name of prop to get. |
|
848 | - * @param string $context What the value is for. Valid values are view and edit. |
|
849 | - * @return mixed |
|
850 | - */ |
|
851 | - protected function get_prop( $prop, $context = 'view' ) { |
|
852 | - $value = null; |
|
853 | - |
|
854 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
855 | - $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
856 | - |
|
857 | - if ( 'view' === $context ) { |
|
858 | - $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
859 | - } |
|
860 | - } |
|
861 | - |
|
862 | - return $value; |
|
863 | - } |
|
864 | - |
|
865 | - /** |
|
866 | - * Sets a date prop whilst handling formatting and datetime objects. |
|
867 | - * |
|
868 | - * @since 1.0.19 |
|
869 | - * @param string $prop Name of prop to set. |
|
870 | - * @param string|integer $value Value of the prop. |
|
871 | - */ |
|
872 | - protected function set_date_prop( $prop, $value ) { |
|
873 | - |
|
874 | - if ( empty( $value ) ) { |
|
875 | - $this->set_prop( $prop, null ); |
|
876 | - return; |
|
877 | - } |
|
878 | - $this->set_prop( $prop, $value ); |
|
879 | - |
|
880 | - } |
|
881 | - |
|
882 | - /** |
|
883 | - * When invalid data is found, throw an exception unless reading from the DB. |
|
884 | - * |
|
885 | - * @since 1.0.19 |
|
886 | - * @param string $code Error code. |
|
887 | - * @param string $message Error message. |
|
888 | - */ |
|
889 | - protected function error( $code, $message ) { |
|
890 | - $this->last_error = $message; |
|
891 | - } |
|
892 | - |
|
893 | - /** |
|
894 | - * Checks if the object is saved in the database |
|
895 | - * |
|
896 | - * @since 1.0.19 |
|
897 | - * @return bool |
|
898 | - */ |
|
899 | - public function exists() { |
|
900 | - $id = $this->get_id(); |
|
901 | - return ! empty( $id ); |
|
902 | - } |
|
710 | + $this->set_prop( 'status', $status ); |
|
711 | + |
|
712 | + return array( |
|
713 | + 'from' => $old_status, |
|
714 | + 'to' => $status, |
|
715 | + ); |
|
716 | + } |
|
717 | + |
|
718 | + /** |
|
719 | + * Set all props to default values. |
|
720 | + * |
|
721 | + * @since 1.0.19 |
|
722 | + */ |
|
723 | + public function set_defaults() { |
|
724 | + $this->data = $this->default_data; |
|
725 | + $this->changes = array(); |
|
726 | + $this->set_object_read( false ); |
|
727 | + } |
|
728 | + |
|
729 | + /** |
|
730 | + * Set object read property. |
|
731 | + * |
|
732 | + * @since 1.0.19 |
|
733 | + * @param boolean $read Should read?. |
|
734 | + */ |
|
735 | + public function set_object_read( $read = true ) { |
|
736 | + $this->object_read = (bool) $read; |
|
737 | + } |
|
738 | + |
|
739 | + /** |
|
740 | + * Get object read property. |
|
741 | + * |
|
742 | + * @since 1.0.19 |
|
743 | + * @return boolean |
|
744 | + */ |
|
745 | + public function get_object_read() { |
|
746 | + return (bool) $this->object_read; |
|
747 | + } |
|
748 | + |
|
749 | + /** |
|
750 | + * Set a collection of props in one go, collect any errors, and return the result. |
|
751 | + * Only sets using public methods. |
|
752 | + * |
|
753 | + * @since 1.0.19 |
|
754 | + * |
|
755 | + * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
756 | + * @param string $context In what context to run this. |
|
757 | + * |
|
758 | + * @return bool|WP_Error |
|
759 | + */ |
|
760 | + public function set_props( $props, $context = 'set' ) { |
|
761 | + $errors = false; |
|
762 | + |
|
763 | + foreach ( $props as $prop => $value ) { |
|
764 | + try { |
|
765 | + /** |
|
766 | + * Checks if the prop being set is allowed, and the value is not null. |
|
767 | + */ |
|
768 | + if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
769 | + continue; |
|
770 | + } |
|
771 | + $setter = "set_$prop"; |
|
772 | + |
|
773 | + if ( is_callable( array( $this, $setter ) ) ) { |
|
774 | + $this->{$setter}( $value ); |
|
775 | + } |
|
776 | + } catch ( Exception $e ) { |
|
777 | + if ( ! $errors ) { |
|
778 | + $errors = new WP_Error(); |
|
779 | + } |
|
780 | + $errors->add( $e->getCode(), $e->getMessage() ); |
|
781 | + $this->last_error = $e->getMessage(); |
|
782 | + } |
|
783 | + } |
|
784 | + |
|
785 | + return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
786 | + } |
|
787 | + |
|
788 | + /** |
|
789 | + * Sets a prop for a setter method. |
|
790 | + * |
|
791 | + * This stores changes in a special array so we can track what needs saving |
|
792 | + * the the DB later. |
|
793 | + * |
|
794 | + * @since 1.0.19 |
|
795 | + * @param string $prop Name of prop to set. |
|
796 | + * @param mixed $value Value of the prop. |
|
797 | + */ |
|
798 | + protected function set_prop( $prop, $value ) { |
|
799 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
800 | + if ( true === $this->object_read ) { |
|
801 | + if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
802 | + $this->changes[ $prop ] = $value; |
|
803 | + } |
|
804 | + } else { |
|
805 | + $this->data[ $prop ] = $value; |
|
806 | + } |
|
807 | + } |
|
808 | + } |
|
809 | + |
|
810 | + /** |
|
811 | + * Return data changes only. |
|
812 | + * |
|
813 | + * @since 1.0.19 |
|
814 | + * @return array |
|
815 | + */ |
|
816 | + public function get_changes() { |
|
817 | + return $this->changes; |
|
818 | + } |
|
819 | + |
|
820 | + /** |
|
821 | + * Merge changes with data and clear. |
|
822 | + * |
|
823 | + * @since 1.0.19 |
|
824 | + */ |
|
825 | + public function apply_changes() { |
|
826 | + $this->data = array_replace( $this->data, $this->changes ); |
|
827 | + $this->changes = array(); |
|
828 | + } |
|
829 | + |
|
830 | + /** |
|
831 | + * Prefix for action and filter hooks on data. |
|
832 | + * |
|
833 | + * @since 1.0.19 |
|
834 | + * @return string |
|
835 | + */ |
|
836 | + protected function get_hook_prefix() { |
|
837 | + return 'wpinv_get_' . $this->object_type . '_'; |
|
838 | + } |
|
839 | + |
|
840 | + /** |
|
841 | + * Gets a prop for a getter method. |
|
842 | + * |
|
843 | + * Gets the value from either current pending changes, or the data itself. |
|
844 | + * Context controls what happens to the value before it's returned. |
|
845 | + * |
|
846 | + * @since 1.0.19 |
|
847 | + * @param string $prop Name of prop to get. |
|
848 | + * @param string $context What the value is for. Valid values are view and edit. |
|
849 | + * @return mixed |
|
850 | + */ |
|
851 | + protected function get_prop( $prop, $context = 'view' ) { |
|
852 | + $value = null; |
|
853 | + |
|
854 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
855 | + $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
856 | + |
|
857 | + if ( 'view' === $context ) { |
|
858 | + $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
859 | + } |
|
860 | + } |
|
861 | + |
|
862 | + return $value; |
|
863 | + } |
|
864 | + |
|
865 | + /** |
|
866 | + * Sets a date prop whilst handling formatting and datetime objects. |
|
867 | + * |
|
868 | + * @since 1.0.19 |
|
869 | + * @param string $prop Name of prop to set. |
|
870 | + * @param string|integer $value Value of the prop. |
|
871 | + */ |
|
872 | + protected function set_date_prop( $prop, $value ) { |
|
873 | + |
|
874 | + if ( empty( $value ) ) { |
|
875 | + $this->set_prop( $prop, null ); |
|
876 | + return; |
|
877 | + } |
|
878 | + $this->set_prop( $prop, $value ); |
|
879 | + |
|
880 | + } |
|
881 | + |
|
882 | + /** |
|
883 | + * When invalid data is found, throw an exception unless reading from the DB. |
|
884 | + * |
|
885 | + * @since 1.0.19 |
|
886 | + * @param string $code Error code. |
|
887 | + * @param string $message Error message. |
|
888 | + */ |
|
889 | + protected function error( $code, $message ) { |
|
890 | + $this->last_error = $message; |
|
891 | + } |
|
892 | + |
|
893 | + /** |
|
894 | + * Checks if the object is saved in the database |
|
895 | + * |
|
896 | + * @since 1.0.19 |
|
897 | + * @return bool |
|
898 | + */ |
|
899 | + public function exists() { |
|
900 | + $id = $this->get_id(); |
|
901 | + return ! empty( $id ); |
|
902 | + } |
|
903 | 903 | |
904 | 904 | } |
@@ -13,288 +13,288 @@ |
||
13 | 13 | class GetPaid_Subscription_Notification_Emails { |
14 | 14 | |
15 | 15 | /** |
16 | - * The array of subscription email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $subscription_actions; |
|
16 | + * The array of subscription email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $subscription_actions; |
|
21 | 21 | |
22 | 22 | /** |
23 | - * Class constructor |
|
23 | + * Class constructor |
|
24 | 24 | * |
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->subscription_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_subscription_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_subscription_trialling' => 'subscription_trial', |
|
32 | - 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
33 | - 'getpaid_subscription_expired' => 'subscription_expired', |
|
34 | - 'getpaid_subscription_completed' => 'subscription_complete', |
|
35 | - 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
36 | - ) |
|
37 | - ); |
|
38 | - |
|
39 | - $this->init_hooks(); |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->subscription_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_subscription_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_subscription_trialling' => 'subscription_trial', |
|
32 | + 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
33 | + 'getpaid_subscription_expired' => 'subscription_expired', |
|
34 | + 'getpaid_subscription_completed' => 'subscription_complete', |
|
35 | + 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
36 | + ) |
|
37 | + ); |
|
38 | + |
|
39 | + $this->init_hooks(); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | - * Registers email hooks. |
|
45 | - */ |
|
46 | - public function init_hooks() { |
|
47 | - |
|
48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
50 | - |
|
51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
52 | - |
|
53 | - if ( ! $email->is_active() ) { |
|
54 | - continue; |
|
55 | - } |
|
56 | - |
|
57 | - if ( method_exists( $this, $email_type ) ) { |
|
58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
59 | - continue; |
|
60 | - } |
|
61 | - |
|
62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
63 | - |
|
64 | - } |
|
65 | - |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Filters subscription merge tags. |
|
70 | - * |
|
71 | - * @param array $merge_tags |
|
72 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
73 | - */ |
|
74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
75 | - |
|
76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
77 | - $merge_tags = array_merge( |
|
78 | - $merge_tags, |
|
79 | - $this->get_subscription_merge_tags( $object ) |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - return $merge_tags; |
|
84 | - |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Generates subscription merge tags. |
|
89 | - * |
|
90 | - * @param WPInv_Subscription $subscription |
|
91 | - * @return array |
|
92 | - */ |
|
93 | - public function get_subscription_merge_tags( $subscription ) { |
|
94 | - |
|
95 | - // Abort if it does not exist. |
|
96 | - if ( ! $subscription->get_id() ) { |
|
97 | - return array(); |
|
98 | - } |
|
99 | - |
|
100 | - $invoice = $subscription->get_parent_invoice(); |
|
101 | - return array( |
|
102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | - '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
108 | - '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
110 | - '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
112 | - ); |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Checks if we should send a notification for a subscription. |
|
118 | - * |
|
119 | - * @param WPInv_Invoice $invoice |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - public function should_send_notification( $invoice ) { |
|
123 | - return 0 != $invoice->get_id(); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Returns notification recipients. |
|
128 | - * |
|
129 | - * @param WPInv_Invoice $invoice |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - public function get_recipients( $invoice ) { |
|
133 | - $recipients = array( $invoice->get_email() ); |
|
134 | - |
|
135 | - $cc = $invoice->get_email_cc(); |
|
136 | - |
|
137 | - if ( ! empty( $cc ) ) { |
|
138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
140 | - } |
|
141 | - |
|
142 | - return $recipients; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Helper function to send an email. |
|
147 | - * |
|
148 | - * @param WPInv_Subscription $subscription |
|
149 | - * @param GetPaid_Notification_Email $email |
|
150 | - * @param string $type |
|
151 | - * @param array $extra_args Extra template args. |
|
152 | - */ |
|
153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
154 | - |
|
155 | - // Abort in case the parent invoice does not exist. |
|
156 | - $invoice = $subscription->get_parent_invoice(); |
|
157 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
158 | - return; |
|
159 | - } |
|
160 | - |
|
161 | - if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
162 | - return; |
|
163 | - } |
|
164 | - |
|
165 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
166 | - |
|
167 | - $recipients = $this->get_recipients( $invoice ); |
|
168 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
169 | - $merge_tags = $email->get_merge_tags(); |
|
170 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
171 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
172 | - $attachments = $email->get_attachments(); |
|
173 | - |
|
174 | - $result = $mailer->send( |
|
175 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
176 | - $subject, |
|
177 | - $content, |
|
178 | - $attachments |
|
179 | - ); |
|
180 | - |
|
181 | - // Maybe send a copy to the admin. |
|
182 | - if ( $email->include_admin_bcc() ) { |
|
183 | - $mailer->send( |
|
184 | - wpinv_get_admin_email(), |
|
185 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
186 | - $content, |
|
187 | - $attachments |
|
188 | - ); |
|
189 | - } |
|
190 | - |
|
191 | - if ( $result ) { |
|
192 | - $subscription->get_parent_invoice()->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
193 | - } else { |
|
194 | - $subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
195 | - } |
|
196 | - |
|
197 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
198 | - |
|
199 | - } |
|
44 | + * Registers email hooks. |
|
45 | + */ |
|
46 | + public function init_hooks() { |
|
47 | + |
|
48 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | + foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
50 | + |
|
51 | + $email = new GetPaid_Notification_Email( $email_type ); |
|
52 | + |
|
53 | + if ( ! $email->is_active() ) { |
|
54 | + continue; |
|
55 | + } |
|
56 | + |
|
57 | + if ( method_exists( $this, $email_type ) ) { |
|
58 | + add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
59 | + continue; |
|
60 | + } |
|
61 | + |
|
62 | + do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
63 | + |
|
64 | + } |
|
65 | + |
|
66 | + } |
|
200 | 67 | |
201 | 68 | /** |
202 | - * Sends a new trial notification. |
|
203 | - * |
|
204 | - * @param WPInv_Subscription $subscription |
|
205 | - */ |
|
206 | - public function subscription_trial( $subscription ) { |
|
69 | + * Filters subscription merge tags. |
|
70 | + * |
|
71 | + * @param array $merge_tags |
|
72 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
73 | + */ |
|
74 | + public function subscription_merge_tags( $merge_tags, $object ) { |
|
207 | 75 | |
208 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
209 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
76 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
77 | + $merge_tags = array_merge( |
|
78 | + $merge_tags, |
|
79 | + $this->get_subscription_merge_tags( $object ) |
|
80 | + ); |
|
81 | + } |
|
210 | 82 | |
211 | - } |
|
83 | + return $merge_tags; |
|
212 | 84 | |
213 | - /** |
|
214 | - * Sends a cancelled subscription notification. |
|
215 | - * |
|
216 | - * @param WPInv_Subscription $subscription |
|
217 | - */ |
|
218 | - public function subscription_cancelled( $subscription ) { |
|
85 | + } |
|
219 | 86 | |
220 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
221 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
87 | + /** |
|
88 | + * Generates subscription merge tags. |
|
89 | + * |
|
90 | + * @param WPInv_Subscription $subscription |
|
91 | + * @return array |
|
92 | + */ |
|
93 | + public function get_subscription_merge_tags( $subscription ) { |
|
94 | + |
|
95 | + // Abort if it does not exist. |
|
96 | + if ( ! $subscription->get_id() ) { |
|
97 | + return array(); |
|
98 | + } |
|
99 | + |
|
100 | + $invoice = $subscription->get_parent_invoice(); |
|
101 | + return array( |
|
102 | + '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | + '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | + '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | + '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | + '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | + '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
108 | + '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
110 | + '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
111 | + '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
112 | + ); |
|
222 | 113 | |
223 | - } |
|
114 | + } |
|
224 | 115 | |
225 | - /** |
|
226 | - * Sends a subscription expired notification. |
|
227 | - * |
|
228 | - * @param WPInv_Subscription $subscription |
|
229 | - */ |
|
230 | - public function subscription_expired( $subscription ) { |
|
116 | + /** |
|
117 | + * Checks if we should send a notification for a subscription. |
|
118 | + * |
|
119 | + * @param WPInv_Invoice $invoice |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + public function should_send_notification( $invoice ) { |
|
123 | + return 0 != $invoice->get_id(); |
|
124 | + } |
|
231 | 125 | |
232 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
233 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
126 | + /** |
|
127 | + * Returns notification recipients. |
|
128 | + * |
|
129 | + * @param WPInv_Invoice $invoice |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + public function get_recipients( $invoice ) { |
|
133 | + $recipients = array( $invoice->get_email() ); |
|
234 | 134 | |
235 | - } |
|
135 | + $cc = $invoice->get_email_cc(); |
|
236 | 136 | |
237 | - /** |
|
238 | - * Sends a completed subscription notification. |
|
239 | - * |
|
240 | - * @param WPInv_Subscription $subscription |
|
241 | - */ |
|
242 | - public function subscription_complete( $subscription ) { |
|
137 | + if ( ! empty( $cc ) ) { |
|
138 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
140 | + } |
|
243 | 141 | |
244 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
245 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
142 | + return $recipients; |
|
143 | + } |
|
246 | 144 | |
247 | - } |
|
145 | + /** |
|
146 | + * Helper function to send an email. |
|
147 | + * |
|
148 | + * @param WPInv_Subscription $subscription |
|
149 | + * @param GetPaid_Notification_Email $email |
|
150 | + * @param string $type |
|
151 | + * @param array $extra_args Extra template args. |
|
152 | + */ |
|
153 | + public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
154 | + |
|
155 | + // Abort in case the parent invoice does not exist. |
|
156 | + $invoice = $subscription->get_parent_invoice(); |
|
157 | + if ( ! $this->should_send_notification( $invoice ) ) { |
|
158 | + return; |
|
159 | + } |
|
160 | + |
|
161 | + if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
162 | + return; |
|
163 | + } |
|
164 | + |
|
165 | + do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
166 | + |
|
167 | + $recipients = $this->get_recipients( $invoice ); |
|
168 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
169 | + $merge_tags = $email->get_merge_tags(); |
|
170 | + $content = $email->get_content( $merge_tags, $extra_args ); |
|
171 | + $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
172 | + $attachments = $email->get_attachments(); |
|
173 | + |
|
174 | + $result = $mailer->send( |
|
175 | + apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
176 | + $subject, |
|
177 | + $content, |
|
178 | + $attachments |
|
179 | + ); |
|
180 | + |
|
181 | + // Maybe send a copy to the admin. |
|
182 | + if ( $email->include_admin_bcc() ) { |
|
183 | + $mailer->send( |
|
184 | + wpinv_get_admin_email(), |
|
185 | + $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
186 | + $content, |
|
187 | + $attachments |
|
188 | + ); |
|
189 | + } |
|
190 | + |
|
191 | + if ( $result ) { |
|
192 | + $subscription->get_parent_invoice()->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
193 | + } else { |
|
194 | + $subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
195 | + } |
|
196 | + |
|
197 | + do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
248 | 198 | |
249 | - /** |
|
250 | - * Sends a subscription renewal reminder notification. |
|
251 | - * |
|
252 | - */ |
|
253 | - public function renewal_reminder() { |
|
199 | + } |
|
254 | 200 | |
255 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
201 | + /** |
|
202 | + * Sends a new trial notification. |
|
203 | + * |
|
204 | + * @param WPInv_Subscription $subscription |
|
205 | + */ |
|
206 | + public function subscription_trial( $subscription ) { |
|
256 | 207 | |
257 | - // Fetch reminder days. |
|
258 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
208 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
209 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
259 | 210 | |
260 | - // Abort if non is set. |
|
261 | - if ( empty( $reminder_days ) ) { |
|
262 | - return; |
|
263 | - } |
|
211 | + } |
|
264 | 212 | |
265 | - // Fetch matching subscriptions. |
|
213 | + /** |
|
214 | + * Sends a cancelled subscription notification. |
|
215 | + * |
|
216 | + * @param WPInv_Subscription $subscription |
|
217 | + */ |
|
218 | + public function subscription_cancelled( $subscription ) { |
|
219 | + |
|
220 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
221 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
222 | + |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Sends a subscription expired notification. |
|
227 | + * |
|
228 | + * @param WPInv_Subscription $subscription |
|
229 | + */ |
|
230 | + public function subscription_expired( $subscription ) { |
|
231 | + |
|
232 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
233 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
234 | + |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Sends a completed subscription notification. |
|
239 | + * |
|
240 | + * @param WPInv_Subscription $subscription |
|
241 | + */ |
|
242 | + public function subscription_complete( $subscription ) { |
|
243 | + |
|
244 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
245 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
246 | + |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Sends a subscription renewal reminder notification. |
|
251 | + * |
|
252 | + */ |
|
253 | + public function renewal_reminder() { |
|
254 | + |
|
255 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
256 | + |
|
257 | + // Fetch reminder days. |
|
258 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
259 | + |
|
260 | + // Abort if non is set. |
|
261 | + if ( empty( $reminder_days ) ) { |
|
262 | + return; |
|
263 | + } |
|
264 | + |
|
265 | + // Fetch matching subscriptions. |
|
266 | 266 | $args = array( |
267 | 267 | 'number' => -1, |
268 | - 'count_total' => false, |
|
269 | - 'status' => 'trialling active', |
|
268 | + 'count_total' => false, |
|
269 | + 'status' => 'trialling active', |
|
270 | 270 | 'date_expires_query' => array( |
271 | - 'relation' => 'OR' |
|
271 | + 'relation' => 'OR' |
|
272 | 272 | ), |
273 | - ); |
|
273 | + ); |
|
274 | 274 | |
275 | - foreach ( $reminder_days as $days ) { |
|
276 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
275 | + foreach ( $reminder_days as $days ) { |
|
276 | + $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
277 | 277 | |
278 | - $args['date_expires_query'][] = array( |
|
279 | - 'year' => $date['year'], |
|
280 | - 'month' => $date['month'], |
|
281 | - 'day' => $date['day'], |
|
282 | - ); |
|
278 | + $args['date_expires_query'][] = array( |
|
279 | + 'year' => $date['year'], |
|
280 | + 'month' => $date['month'], |
|
281 | + 'day' => $date['day'], |
|
282 | + ); |
|
283 | 283 | |
284 | - } |
|
284 | + } |
|
285 | 285 | |
286 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
286 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
287 | 287 | |
288 | 288 | foreach ( $subscriptions as $subscription ) { |
289 | 289 | |
290 | - // Skip packages. |
|
291 | - if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) { |
|
292 | - $email->object = $subscription; |
|
293 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
294 | - } |
|
290 | + // Skip packages. |
|
291 | + if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) { |
|
292 | + $email->object = $subscription; |
|
293 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
294 | + } |
|
295 | 295 | |
296 | - } |
|
296 | + } |
|
297 | 297 | |
298 | - } |
|
298 | + } |
|
299 | 299 | |
300 | 300 | } |
@@ -13,467 +13,467 @@ discard block |
||
13 | 13 | */ |
14 | 14 | abstract class GetPaid_Payment_Gateway { |
15 | 15 | |
16 | - /** |
|
17 | - * Set if the place checkout button should be renamed on selection. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $checkout_button_text; |
|
22 | - |
|
23 | - /** |
|
24 | - * Boolean whether the method is enabled. |
|
25 | - * |
|
26 | - * @var bool |
|
27 | - */ |
|
28 | - public $enabled = true; |
|
29 | - |
|
30 | - /** |
|
31 | - * Payment method id. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $id; |
|
36 | - |
|
37 | - /** |
|
38 | - * Payment method order. |
|
39 | - * |
|
40 | - * @var int |
|
41 | - */ |
|
42 | - public $order = 10; |
|
43 | - |
|
44 | - /** |
|
45 | - * Payment method title for the frontend. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $title; |
|
50 | - |
|
51 | - /** |
|
52 | - * Payment method description for the frontend. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - public $description; |
|
57 | - |
|
58 | - /** |
|
59 | - * Gateway title. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $method_title = ''; |
|
64 | - |
|
65 | - /** |
|
66 | - * Gateway description. |
|
67 | - * |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - public $method_description = ''; |
|
71 | - |
|
72 | - /** |
|
73 | - * Countries this gateway is allowed for. |
|
74 | - * |
|
75 | - * @var array |
|
76 | - */ |
|
77 | - public $countries; |
|
78 | - |
|
79 | - /** |
|
80 | - * Currencies this gateway is allowed for. |
|
81 | - * |
|
82 | - * @var array |
|
83 | - */ |
|
84 | - public $currencies; |
|
85 | - |
|
86 | - /** |
|
87 | - * Currencies this gateway is not allowed for. |
|
88 | - * |
|
89 | - * @var array |
|
90 | - */ |
|
91 | - public $exclude_currencies; |
|
92 | - |
|
93 | - /** |
|
94 | - * Maximum transaction amount, zero does not define a maximum. |
|
95 | - * |
|
96 | - * @var int |
|
97 | - */ |
|
98 | - public $max_amount = 0; |
|
99 | - |
|
100 | - /** |
|
101 | - * Optional URL to view a transaction. |
|
102 | - * |
|
103 | - * @var string |
|
104 | - */ |
|
105 | - public $view_transaction_url = ''; |
|
106 | - |
|
107 | - /** |
|
108 | - * Optional URL to view a subscription. |
|
109 | - * |
|
110 | - * @var string |
|
111 | - */ |
|
112 | - public $view_subscription_url = ''; |
|
113 | - |
|
114 | - /** |
|
115 | - * Optional label to show for "new payment method" in the payment |
|
116 | - * method/token selection radio selection. |
|
117 | - * |
|
118 | - * @var string |
|
119 | - */ |
|
120 | - public $new_method_label = ''; |
|
121 | - |
|
122 | - /** |
|
123 | - * Contains a user's saved tokens for this gateway. |
|
124 | - * |
|
125 | - * @var array |
|
126 | - */ |
|
127 | - protected $tokens = array(); |
|
128 | - |
|
129 | - /** |
|
130 | - * An array of features that this gateway supports. |
|
131 | - * |
|
132 | - * @var array |
|
133 | - */ |
|
134 | - protected $supports = array(); |
|
135 | - |
|
136 | - /** |
|
137 | - * Class constructor. |
|
138 | - */ |
|
139 | - public function __construct() { |
|
140 | - |
|
141 | - // Register gateway. |
|
142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
143 | - |
|
144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
145 | - |
|
146 | - // Enable Subscriptions. |
|
147 | - if ( $this->supports( 'subscription' ) ) { |
|
148 | - add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
149 | - } |
|
150 | - |
|
151 | - // Enable sandbox. |
|
152 | - if ( $this->supports( 'sandbox' ) ) { |
|
153 | - add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
154 | - } |
|
155 | - |
|
156 | - // Invoice addons. |
|
157 | - if ( $this->supports( 'addons' ) ) { |
|
158 | - add_filter( "getpaid_{$this->id}_supports_addons", '__return_true' ); |
|
159 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
160 | - } |
|
161 | - |
|
162 | - // Gateway settings. |
|
163 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
16 | + /** |
|
17 | + * Set if the place checkout button should be renamed on selection. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $checkout_button_text; |
|
22 | + |
|
23 | + /** |
|
24 | + * Boolean whether the method is enabled. |
|
25 | + * |
|
26 | + * @var bool |
|
27 | + */ |
|
28 | + public $enabled = true; |
|
29 | + |
|
30 | + /** |
|
31 | + * Payment method id. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $id; |
|
36 | + |
|
37 | + /** |
|
38 | + * Payment method order. |
|
39 | + * |
|
40 | + * @var int |
|
41 | + */ |
|
42 | + public $order = 10; |
|
43 | + |
|
44 | + /** |
|
45 | + * Payment method title for the frontend. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $title; |
|
50 | + |
|
51 | + /** |
|
52 | + * Payment method description for the frontend. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + public $description; |
|
57 | + |
|
58 | + /** |
|
59 | + * Gateway title. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $method_title = ''; |
|
64 | + |
|
65 | + /** |
|
66 | + * Gateway description. |
|
67 | + * |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + public $method_description = ''; |
|
71 | + |
|
72 | + /** |
|
73 | + * Countries this gateway is allowed for. |
|
74 | + * |
|
75 | + * @var array |
|
76 | + */ |
|
77 | + public $countries; |
|
78 | + |
|
79 | + /** |
|
80 | + * Currencies this gateway is allowed for. |
|
81 | + * |
|
82 | + * @var array |
|
83 | + */ |
|
84 | + public $currencies; |
|
85 | + |
|
86 | + /** |
|
87 | + * Currencies this gateway is not allowed for. |
|
88 | + * |
|
89 | + * @var array |
|
90 | + */ |
|
91 | + public $exclude_currencies; |
|
92 | + |
|
93 | + /** |
|
94 | + * Maximum transaction amount, zero does not define a maximum. |
|
95 | + * |
|
96 | + * @var int |
|
97 | + */ |
|
98 | + public $max_amount = 0; |
|
99 | + |
|
100 | + /** |
|
101 | + * Optional URL to view a transaction. |
|
102 | + * |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + public $view_transaction_url = ''; |
|
106 | + |
|
107 | + /** |
|
108 | + * Optional URL to view a subscription. |
|
109 | + * |
|
110 | + * @var string |
|
111 | + */ |
|
112 | + public $view_subscription_url = ''; |
|
113 | + |
|
114 | + /** |
|
115 | + * Optional label to show for "new payment method" in the payment |
|
116 | + * method/token selection radio selection. |
|
117 | + * |
|
118 | + * @var string |
|
119 | + */ |
|
120 | + public $new_method_label = ''; |
|
121 | + |
|
122 | + /** |
|
123 | + * Contains a user's saved tokens for this gateway. |
|
124 | + * |
|
125 | + * @var array |
|
126 | + */ |
|
127 | + protected $tokens = array(); |
|
128 | + |
|
129 | + /** |
|
130 | + * An array of features that this gateway supports. |
|
131 | + * |
|
132 | + * @var array |
|
133 | + */ |
|
134 | + protected $supports = array(); |
|
135 | + |
|
136 | + /** |
|
137 | + * Class constructor. |
|
138 | + */ |
|
139 | + public function __construct() { |
|
140 | + |
|
141 | + // Register gateway. |
|
142 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
143 | + |
|
144 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
145 | + |
|
146 | + // Enable Subscriptions. |
|
147 | + if ( $this->supports( 'subscription' ) ) { |
|
148 | + add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
149 | + } |
|
150 | + |
|
151 | + // Enable sandbox. |
|
152 | + if ( $this->supports( 'sandbox' ) ) { |
|
153 | + add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
154 | + } |
|
155 | + |
|
156 | + // Invoice addons. |
|
157 | + if ( $this->supports( 'addons' ) ) { |
|
158 | + add_filter( "getpaid_{$this->id}_supports_addons", '__return_true' ); |
|
159 | + add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
160 | + } |
|
161 | + |
|
162 | + // Gateway settings. |
|
163 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
164 | 164 | |
165 | 165 | |
166 | - // Gateway checkout fiellds. |
|
167 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
168 | - |
|
169 | - // Process payment. |
|
170 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
166 | + // Gateway checkout fiellds. |
|
167 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
168 | + |
|
169 | + // Process payment. |
|
170 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
171 | + |
|
172 | + // Change the checkout button text. |
|
173 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
174 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
175 | + } |
|
176 | + |
|
177 | + // Check if a gateway is valid for a given currency. |
|
178 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
179 | + |
|
180 | + // Generate the transaction url. |
|
181 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
182 | + |
|
183 | + // Generate the subscription url. |
|
184 | + add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
185 | + |
|
186 | + // Confirm payments. |
|
187 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
188 | + |
|
189 | + // Verify IPNs. |
|
190 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
191 | + |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Checks if this gateway is a given gateway. |
|
196 | + * |
|
197 | + * @since 1.0.19 |
|
198 | + * @return bool |
|
199 | + */ |
|
200 | + public function is( $gateway ) { |
|
201 | + return $gateway == $this->id; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Returns a users saved tokens for this gateway. |
|
206 | + * |
|
207 | + * @since 1.0.19 |
|
208 | + * @return array |
|
209 | + */ |
|
210 | + public function get_tokens( $sandbox = null ) { |
|
211 | + |
|
212 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
213 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
214 | + |
|
215 | + if ( is_array( $tokens ) ) { |
|
216 | + $this->tokens = $tokens; |
|
217 | + } |
|
218 | + |
|
219 | + } |
|
220 | + |
|
221 | + if ( ! is_bool( $sandbox ) ) { |
|
222 | + return $this->tokens; |
|
223 | + } |
|
224 | + |
|
225 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
226 | + return wp_list_filter( $this->tokens, $args ); |
|
227 | + |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Saves a token for this gateway. |
|
232 | + * |
|
233 | + * @since 1.0.19 |
|
234 | + */ |
|
235 | + public function save_token( $token ) { |
|
236 | + |
|
237 | + $tokens = $this->get_tokens(); |
|
238 | + $tokens[] = $token; |
|
239 | + |
|
240 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
241 | + |
|
242 | + $this->tokens = $tokens; |
|
243 | + |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * Return the title for admin screens. |
|
248 | + * |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function get_method_title() { |
|
252 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Return the description for admin screens. |
|
257 | + * |
|
258 | + * @return string |
|
259 | + */ |
|
260 | + public function get_method_description() { |
|
261 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Get the success url. |
|
266 | + * |
|
267 | + * @param WPInv_Invoice $invoice Invoice object. |
|
268 | + * @return string |
|
269 | + */ |
|
270 | + public function get_return_url( $invoice ) { |
|
271 | + |
|
272 | + // Payment success url |
|
273 | + $return_url = add_query_arg( |
|
274 | + array( |
|
275 | + 'payment-confirm' => $this->id, |
|
276 | + 'invoice_key' => $invoice->get_key(), |
|
277 | + 'utm_nooverride' => 1 |
|
278 | + ), |
|
279 | + wpinv_get_success_page_uri() |
|
280 | + ); |
|
281 | + |
|
282 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Confirms payments when rendering the success page. |
|
287 | + * |
|
288 | + * @param string $content Success page content. |
|
289 | + * @return string |
|
290 | + */ |
|
291 | + public function confirm_payment( $content ) { |
|
292 | + |
|
293 | + // Retrieve the invoice. |
|
294 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
295 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
296 | + |
|
297 | + // Ensure that it exists and that it is pending payment. |
|
298 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
299 | + return $content; |
|
300 | + } |
|
301 | + |
|
302 | + // Can the user view this invoice?? |
|
303 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
304 | + return $content; |
|
305 | + } |
|
306 | + |
|
307 | + // Show payment processing indicator. |
|
308 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * Processes ipns and marks payments as complete. |
|
313 | + * |
|
314 | + * @return void |
|
315 | + */ |
|
316 | + public function verify_ipn() {} |
|
317 | + |
|
318 | + /** |
|
319 | + * Processes invoice addons. |
|
320 | + * |
|
321 | + * @param WPInv_Invoice $invoice |
|
322 | + * @param GetPaid_Form_Item[] $items |
|
323 | + * @return WPInv_Invoice |
|
324 | + */ |
|
325 | + public function process_addons( $invoice, $items ) { |
|
326 | + |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
331 | + * |
|
332 | + * @param string $transaction_url transaction url. |
|
333 | + * @param WPInv_Invoice $invoice Invoice object. |
|
334 | + * @return string transaction URL, or empty string. |
|
335 | + */ |
|
336 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
337 | + |
|
338 | + $transaction_id = $invoice->get_transaction_id(); |
|
339 | + |
|
340 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
341 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
342 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
343 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
344 | + } |
|
345 | + |
|
346 | + return $transaction_url; |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
351 | + * |
|
352 | + * @param string $subscription_url transaction url. |
|
353 | + * @param WPInv_Subscription $subscription Subscription objectt. |
|
354 | + * @return string subscription URL, or empty string. |
|
355 | + */ |
|
356 | + public function generate_subscription_url( $subscription_url, $subscription ) { |
|
171 | 357 | |
172 | - // Change the checkout button text. |
|
173 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
174 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
175 | - } |
|
176 | - |
|
177 | - // Check if a gateway is valid for a given currency. |
|
178 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
179 | - |
|
180 | - // Generate the transaction url. |
|
181 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
182 | - |
|
183 | - // Generate the subscription url. |
|
184 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
185 | - |
|
186 | - // Confirm payments. |
|
187 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
188 | - |
|
189 | - // Verify IPNs. |
|
190 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
191 | - |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Checks if this gateway is a given gateway. |
|
196 | - * |
|
197 | - * @since 1.0.19 |
|
198 | - * @return bool |
|
199 | - */ |
|
200 | - public function is( $gateway ) { |
|
201 | - return $gateway == $this->id; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Returns a users saved tokens for this gateway. |
|
206 | - * |
|
207 | - * @since 1.0.19 |
|
208 | - * @return array |
|
209 | - */ |
|
210 | - public function get_tokens( $sandbox = null ) { |
|
211 | - |
|
212 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
213 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
214 | - |
|
215 | - if ( is_array( $tokens ) ) { |
|
216 | - $this->tokens = $tokens; |
|
217 | - } |
|
218 | - |
|
219 | - } |
|
220 | - |
|
221 | - if ( ! is_bool( $sandbox ) ) { |
|
222 | - return $this->tokens; |
|
223 | - } |
|
224 | - |
|
225 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
226 | - return wp_list_filter( $this->tokens, $args ); |
|
227 | - |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Saves a token for this gateway. |
|
232 | - * |
|
233 | - * @since 1.0.19 |
|
234 | - */ |
|
235 | - public function save_token( $token ) { |
|
236 | - |
|
237 | - $tokens = $this->get_tokens(); |
|
238 | - $tokens[] = $token; |
|
239 | - |
|
240 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
241 | - |
|
242 | - $this->tokens = $tokens; |
|
243 | - |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * Return the title for admin screens. |
|
248 | - * |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function get_method_title() { |
|
252 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Return the description for admin screens. |
|
257 | - * |
|
258 | - * @return string |
|
259 | - */ |
|
260 | - public function get_method_description() { |
|
261 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Get the success url. |
|
266 | - * |
|
267 | - * @param WPInv_Invoice $invoice Invoice object. |
|
268 | - * @return string |
|
269 | - */ |
|
270 | - public function get_return_url( $invoice ) { |
|
271 | - |
|
272 | - // Payment success url |
|
273 | - $return_url = add_query_arg( |
|
274 | - array( |
|
275 | - 'payment-confirm' => $this->id, |
|
276 | - 'invoice_key' => $invoice->get_key(), |
|
277 | - 'utm_nooverride' => 1 |
|
278 | - ), |
|
279 | - wpinv_get_success_page_uri() |
|
280 | - ); |
|
281 | - |
|
282 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * Confirms payments when rendering the success page. |
|
287 | - * |
|
288 | - * @param string $content Success page content. |
|
289 | - * @return string |
|
290 | - */ |
|
291 | - public function confirm_payment( $content ) { |
|
292 | - |
|
293 | - // Retrieve the invoice. |
|
294 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
295 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
296 | - |
|
297 | - // Ensure that it exists and that it is pending payment. |
|
298 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
299 | - return $content; |
|
300 | - } |
|
301 | - |
|
302 | - // Can the user view this invoice?? |
|
303 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
304 | - return $content; |
|
305 | - } |
|
306 | - |
|
307 | - // Show payment processing indicator. |
|
308 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * Processes ipns and marks payments as complete. |
|
313 | - * |
|
314 | - * @return void |
|
315 | - */ |
|
316 | - public function verify_ipn() {} |
|
317 | - |
|
318 | - /** |
|
319 | - * Processes invoice addons. |
|
320 | - * |
|
321 | - * @param WPInv_Invoice $invoice |
|
322 | - * @param GetPaid_Form_Item[] $items |
|
323 | - * @return WPInv_Invoice |
|
324 | - */ |
|
325 | - public function process_addons( $invoice, $items ) { |
|
326 | - |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
331 | - * |
|
332 | - * @param string $transaction_url transaction url. |
|
333 | - * @param WPInv_Invoice $invoice Invoice object. |
|
334 | - * @return string transaction URL, or empty string. |
|
335 | - */ |
|
336 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
337 | - |
|
338 | - $transaction_id = $invoice->get_transaction_id(); |
|
339 | - |
|
340 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
341 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
342 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
343 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
344 | - } |
|
345 | - |
|
346 | - return $transaction_url; |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
351 | - * |
|
352 | - * @param string $subscription_url transaction url. |
|
353 | - * @param WPInv_Subscription $subscription Subscription objectt. |
|
354 | - * @return string subscription URL, or empty string. |
|
355 | - */ |
|
356 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
357 | - |
|
358 | - $profile_id = $subscription->get_profile_id(); |
|
359 | - |
|
360 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
361 | - |
|
362 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
363 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
364 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
365 | - |
|
366 | - } |
|
367 | - |
|
368 | - return $subscription_url; |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Check if the gateway is available for use. |
|
373 | - * |
|
374 | - * @return bool |
|
375 | - */ |
|
376 | - public function is_available() { |
|
377 | - return ! empty( $this->enabled ); |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Return the gateway's title. |
|
382 | - * |
|
383 | - * @return string |
|
384 | - */ |
|
385 | - public function get_title() { |
|
386 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Return the gateway's description. |
|
391 | - * |
|
392 | - * @return string |
|
393 | - */ |
|
394 | - public function get_description() { |
|
395 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * Process Payment. |
|
400 | - * |
|
401 | - * |
|
402 | - * @param WPInv_Invoice $invoice Invoice. |
|
403 | - * @param array $submission_data Posted checkout fields. |
|
404 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
405 | - * @return void |
|
406 | - */ |
|
407 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
408 | - // Process the payment then either redirect to the success page or the gateway. |
|
409 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Process refund. |
|
414 | - * |
|
415 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
416 | - * a passed in amount. |
|
417 | - * |
|
418 | - * @param WPInv_Invoice $invoice Invoice. |
|
419 | - * @param float $amount Refund amount. |
|
420 | - * @param string $reason Refund reason. |
|
421 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
422 | - */ |
|
423 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
424 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Displays the payment fields, credit cards etc. |
|
429 | - * |
|
430 | - * @param int $invoice_id 0 or invoice id. |
|
431 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
432 | - */ |
|
433 | - public function payment_fields( $invoice_id, $form ) { |
|
434 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * Filters the gateway settings. |
|
439 | - * |
|
440 | - * @param array $admin_settings |
|
441 | - */ |
|
442 | - public function admin_settings( $admin_settings ) { |
|
443 | - return $admin_settings; |
|
444 | - } |
|
445 | - |
|
446 | - /** |
|
447 | - * Retrieves the value of a gateway setting. |
|
448 | - * |
|
449 | - * @param string $option |
|
450 | - */ |
|
451 | - public function get_option( $option, $default = false ) { |
|
452 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Check if a gateway supports a given feature. |
|
457 | - * |
|
458 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
459 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
460 | - * |
|
461 | - * @param string $feature string The name of a feature to test support for. |
|
462 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
463 | - * @since 1.0.19 |
|
464 | - */ |
|
465 | - public function supports( $feature ) { |
|
466 | - return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
467 | - } |
|
468 | - |
|
469 | - /** |
|
470 | - * Returns the credit card form html. |
|
471 | - * |
|
472 | - * @param bool $save whether or not to display the save button. |
|
473 | - */ |
|
358 | + $profile_id = $subscription->get_profile_id(); |
|
359 | + |
|
360 | + if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
361 | + |
|
362 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
363 | + $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
364 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
365 | + |
|
366 | + } |
|
367 | + |
|
368 | + return $subscription_url; |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Check if the gateway is available for use. |
|
373 | + * |
|
374 | + * @return bool |
|
375 | + */ |
|
376 | + public function is_available() { |
|
377 | + return ! empty( $this->enabled ); |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * Return the gateway's title. |
|
382 | + * |
|
383 | + * @return string |
|
384 | + */ |
|
385 | + public function get_title() { |
|
386 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Return the gateway's description. |
|
391 | + * |
|
392 | + * @return string |
|
393 | + */ |
|
394 | + public function get_description() { |
|
395 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Process Payment. |
|
400 | + * |
|
401 | + * |
|
402 | + * @param WPInv_Invoice $invoice Invoice. |
|
403 | + * @param array $submission_data Posted checkout fields. |
|
404 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
405 | + * @return void |
|
406 | + */ |
|
407 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
408 | + // Process the payment then either redirect to the success page or the gateway. |
|
409 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Process refund. |
|
414 | + * |
|
415 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
416 | + * a passed in amount. |
|
417 | + * |
|
418 | + * @param WPInv_Invoice $invoice Invoice. |
|
419 | + * @param float $amount Refund amount. |
|
420 | + * @param string $reason Refund reason. |
|
421 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
422 | + */ |
|
423 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
424 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Displays the payment fields, credit cards etc. |
|
429 | + * |
|
430 | + * @param int $invoice_id 0 or invoice id. |
|
431 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
432 | + */ |
|
433 | + public function payment_fields( $invoice_id, $form ) { |
|
434 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Filters the gateway settings. |
|
439 | + * |
|
440 | + * @param array $admin_settings |
|
441 | + */ |
|
442 | + public function admin_settings( $admin_settings ) { |
|
443 | + return $admin_settings; |
|
444 | + } |
|
445 | + |
|
446 | + /** |
|
447 | + * Retrieves the value of a gateway setting. |
|
448 | + * |
|
449 | + * @param string $option |
|
450 | + */ |
|
451 | + public function get_option( $option, $default = false ) { |
|
452 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Check if a gateway supports a given feature. |
|
457 | + * |
|
458 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
459 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
460 | + * |
|
461 | + * @param string $feature string The name of a feature to test support for. |
|
462 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
463 | + * @since 1.0.19 |
|
464 | + */ |
|
465 | + public function supports( $feature ) { |
|
466 | + return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
467 | + } |
|
468 | + |
|
469 | + /** |
|
470 | + * Returns the credit card form html. |
|
471 | + * |
|
472 | + * @param bool $save whether or not to display the save button. |
|
473 | + */ |
|
474 | 474 | public function get_cc_form( $save = false ) { |
475 | 475 | |
476 | - ob_start(); |
|
476 | + ob_start(); |
|
477 | 477 | |
478 | 478 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
479 | 479 | |
@@ -568,11 +568,11 @@ discard block |
||
568 | 568 | 'name' => $this->id . '[cc_cvv2]', |
569 | 569 | 'id' => "$id_prefix-cc-cvv2", |
570 | 570 | 'label' => __( 'CCV', 'invoicing' ), |
571 | - 'label_type' => 'vertical', |
|
572 | - 'class' => 'form-control-sm', |
|
573 | - 'extra_attributes' => array( |
|
574 | - 'autocomplete' => "cc-csc", |
|
575 | - ), |
|
571 | + 'label_type' => 'vertical', |
|
572 | + 'class' => 'form-control-sm', |
|
573 | + 'extra_attributes' => array( |
|
574 | + 'autocomplete' => "cc-csc", |
|
575 | + ), |
|
576 | 576 | ) |
577 | 577 | ); |
578 | 578 | ?> |
@@ -582,191 +582,191 @@ discard block |
||
582 | 582 | |
583 | 583 | <?php |
584 | 584 | |
585 | - if ( $save ) { |
|
586 | - echo $this->save_payment_method_checkbox(); |
|
587 | - } |
|
585 | + if ( $save ) { |
|
586 | + echo $this->save_payment_method_checkbox(); |
|
587 | + } |
|
588 | 588 | |
589 | - ?> |
|
589 | + ?> |
|
590 | 590 | </div> |
591 | 591 | |
592 | 592 | </div> |
593 | 593 | <?php |
594 | 594 | |
595 | - return ob_get_clean(); |
|
595 | + return ob_get_clean(); |
|
596 | 596 | |
597 | 597 | } |
598 | 598 | |
599 | - /** |
|
600 | - * Displays a new payment method entry form. |
|
601 | - * |
|
602 | - * @since 1.0.19 |
|
603 | - */ |
|
604 | - public function new_payment_method_entry( $form ) { |
|
605 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
606 | - } |
|
607 | - |
|
608 | - /** |
|
609 | - * Grab and display our saved payment methods. |
|
610 | - * |
|
611 | - * @since 1.0.19 |
|
612 | - */ |
|
613 | - public function saved_payment_methods() { |
|
614 | - $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
615 | - |
|
616 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
617 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
618 | - } |
|
619 | - |
|
620 | - $html .= $this->get_new_payment_method_option_html(); |
|
621 | - $html .= '</ul>'; |
|
622 | - |
|
623 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
624 | - } |
|
625 | - |
|
626 | - /** |
|
627 | - * Gets saved payment method HTML from a token. |
|
628 | - * |
|
629 | - * @since 1.0.19 |
|
630 | - * @param array $token Payment Token. |
|
631 | - * @return string Generated payment method HTML |
|
632 | - */ |
|
633 | - public function get_saved_payment_method_option_html( $token ) { |
|
634 | - |
|
635 | - return sprintf( |
|
636 | - '<li class="getpaid-payment-method form-group"> |
|
599 | + /** |
|
600 | + * Displays a new payment method entry form. |
|
601 | + * |
|
602 | + * @since 1.0.19 |
|
603 | + */ |
|
604 | + public function new_payment_method_entry( $form ) { |
|
605 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
606 | + } |
|
607 | + |
|
608 | + /** |
|
609 | + * Grab and display our saved payment methods. |
|
610 | + * |
|
611 | + * @since 1.0.19 |
|
612 | + */ |
|
613 | + public function saved_payment_methods() { |
|
614 | + $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
615 | + |
|
616 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
617 | + $html .= $this->get_saved_payment_method_option_html( $token ); |
|
618 | + } |
|
619 | + |
|
620 | + $html .= $this->get_new_payment_method_option_html(); |
|
621 | + $html .= '</ul>'; |
|
622 | + |
|
623 | + echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
624 | + } |
|
625 | + |
|
626 | + /** |
|
627 | + * Gets saved payment method HTML from a token. |
|
628 | + * |
|
629 | + * @since 1.0.19 |
|
630 | + * @param array $token Payment Token. |
|
631 | + * @return string Generated payment method HTML |
|
632 | + */ |
|
633 | + public function get_saved_payment_method_option_html( $token ) { |
|
634 | + |
|
635 | + return sprintf( |
|
636 | + '<li class="getpaid-payment-method form-group"> |
|
637 | 637 | <label> |
638 | 638 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
639 | 639 | <span>%3$s</span> |
640 | 640 | </label> |
641 | 641 | </li>', |
642 | - esc_attr( $this->id ), |
|
643 | - esc_attr( $token['id'] ), |
|
644 | - esc_html( $token['name'] ), |
|
645 | - checked( empty( $token['default'] ), false, false ) |
|
646 | - ); |
|
642 | + esc_attr( $this->id ), |
|
643 | + esc_attr( $token['id'] ), |
|
644 | + esc_html( $token['name'] ), |
|
645 | + checked( empty( $token['default'] ), false, false ) |
|
646 | + ); |
|
647 | 647 | |
648 | - } |
|
648 | + } |
|
649 | 649 | |
650 | - /** |
|
651 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
652 | - * |
|
653 | - * @since 1.0.19 |
|
654 | - */ |
|
655 | - public function get_new_payment_method_option_html() { |
|
650 | + /** |
|
651 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
652 | + * |
|
653 | + * @since 1.0.19 |
|
654 | + */ |
|
655 | + public function get_new_payment_method_option_html() { |
|
656 | 656 | |
657 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
657 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
658 | 658 | |
659 | - return sprintf( |
|
660 | - '<li class="getpaid-new-payment-method"> |
|
659 | + return sprintf( |
|
660 | + '<li class="getpaid-new-payment-method"> |
|
661 | 661 | <label> |
662 | 662 | <input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" /> |
663 | 663 | <span>%2$s</span> |
664 | 664 | </label> |
665 | 665 | </li>', |
666 | - esc_attr( $this->id ), |
|
667 | - esc_html( $label ) |
|
668 | - ); |
|
669 | - |
|
670 | - } |
|
671 | - |
|
672 | - /** |
|
673 | - * Outputs a checkbox for saving a new payment method to the database. |
|
674 | - * |
|
675 | - * @since 1.0.19 |
|
676 | - */ |
|
677 | - public function save_payment_method_checkbox() { |
|
678 | - |
|
679 | - return aui()->input( |
|
680 | - array( |
|
681 | - 'type' => 'checkbox', |
|
682 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
683 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
684 | - 'required' => false, |
|
685 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
686 | - 'value' => 'true', |
|
687 | - 'checked' => true, |
|
688 | - 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
689 | - ) |
|
690 | - ); |
|
691 | - |
|
692 | - } |
|
693 | - |
|
694 | - /** |
|
695 | - * Registers the gateway. |
|
696 | - * |
|
697 | - * @return array |
|
698 | - */ |
|
699 | - public function register_gateway( $gateways ) { |
|
700 | - |
|
701 | - $gateways[ $this->id ] = array( |
|
702 | - |
|
703 | - 'admin_label' => $this->method_title, |
|
666 | + esc_attr( $this->id ), |
|
667 | + esc_html( $label ) |
|
668 | + ); |
|
669 | + |
|
670 | + } |
|
671 | + |
|
672 | + /** |
|
673 | + * Outputs a checkbox for saving a new payment method to the database. |
|
674 | + * |
|
675 | + * @since 1.0.19 |
|
676 | + */ |
|
677 | + public function save_payment_method_checkbox() { |
|
678 | + |
|
679 | + return aui()->input( |
|
680 | + array( |
|
681 | + 'type' => 'checkbox', |
|
682 | + 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
683 | + 'id' => esc_attr( uniqid( $this->id ) ), |
|
684 | + 'required' => false, |
|
685 | + 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
686 | + 'value' => 'true', |
|
687 | + 'checked' => true, |
|
688 | + 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
689 | + ) |
|
690 | + ); |
|
691 | + |
|
692 | + } |
|
693 | + |
|
694 | + /** |
|
695 | + * Registers the gateway. |
|
696 | + * |
|
697 | + * @return array |
|
698 | + */ |
|
699 | + public function register_gateway( $gateways ) { |
|
700 | + |
|
701 | + $gateways[ $this->id ] = array( |
|
702 | + |
|
703 | + 'admin_label' => $this->method_title, |
|
704 | 704 | 'checkout_label' => $this->title, |
705 | - 'ordering' => $this->order, |
|
705 | + 'ordering' => $this->order, |
|
706 | 706 | |
707 | - ); |
|
707 | + ); |
|
708 | 708 | |
709 | - return $gateways; |
|
709 | + return $gateways; |
|
710 | 710 | |
711 | - } |
|
711 | + } |
|
712 | 712 | |
713 | - /** |
|
714 | - * Checks whether or not this is a sandbox request. |
|
715 | - * |
|
716 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
717 | - * @return bool |
|
718 | - */ |
|
719 | - public function is_sandbox( $invoice = null ) { |
|
713 | + /** |
|
714 | + * Checks whether or not this is a sandbox request. |
|
715 | + * |
|
716 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
717 | + * @return bool |
|
718 | + */ |
|
719 | + public function is_sandbox( $invoice = null ) { |
|
720 | 720 | |
721 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
722 | - return $invoice->get_mode() == 'test'; |
|
723 | - } |
|
721 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
722 | + return $invoice->get_mode() == 'test'; |
|
723 | + } |
|
724 | 724 | |
725 | - return wpinv_is_test_mode( $this->id ); |
|
725 | + return wpinv_is_test_mode( $this->id ); |
|
726 | 726 | |
727 | - } |
|
727 | + } |
|
728 | 728 | |
729 | - /** |
|
730 | - * Renames the checkout button |
|
731 | - * |
|
732 | - * @return string |
|
733 | - */ |
|
734 | - public function rename_checkout_button() { |
|
735 | - return $this->checkout_button_text; |
|
736 | - } |
|
729 | + /** |
|
730 | + * Renames the checkout button |
|
731 | + * |
|
732 | + * @return string |
|
733 | + */ |
|
734 | + public function rename_checkout_button() { |
|
735 | + return $this->checkout_button_text; |
|
736 | + } |
|
737 | 737 | |
738 | - /** |
|
739 | - * Validate gateway currency |
|
740 | - * |
|
741 | - * @return bool |
|
742 | - */ |
|
743 | - public function validate_currency( $validation, $currency ) { |
|
738 | + /** |
|
739 | + * Validate gateway currency |
|
740 | + * |
|
741 | + * @return bool |
|
742 | + */ |
|
743 | + public function validate_currency( $validation, $currency ) { |
|
744 | 744 | |
745 | - // Required currencies. |
|
746 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
747 | - return false; |
|
748 | - } |
|
745 | + // Required currencies. |
|
746 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
747 | + return false; |
|
748 | + } |
|
749 | 749 | |
750 | - // Excluded currencies. |
|
751 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
752 | - return false; |
|
753 | - } |
|
750 | + // Excluded currencies. |
|
751 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
752 | + return false; |
|
753 | + } |
|
754 | 754 | |
755 | - return $validation; |
|
756 | - } |
|
755 | + return $validation; |
|
756 | + } |
|
757 | 757 | |
758 | - /** |
|
759 | - * Displays an error |
|
760 | - * |
|
761 | - */ |
|
762 | - public function show_error( $code, $message, $type ) { |
|
758 | + /** |
|
759 | + * Displays an error |
|
760 | + * |
|
761 | + */ |
|
762 | + public function show_error( $code, $message, $type ) { |
|
763 | 763 | |
764 | - if ( is_admin() ) { |
|
765 | - getpaid_admin()->{"show_$type"}( $message ); |
|
766 | - } |
|
764 | + if ( is_admin() ) { |
|
765 | + getpaid_admin()->{"show_$type"}( $message ); |
|
766 | + } |
|
767 | 767 | |
768 | - wpinv_set_error( $code, $message, $type ); |
|
768 | + wpinv_set_error( $code, $message, $type ); |
|
769 | 769 | |
770 | - } |
|
770 | + } |
|
771 | 771 | |
772 | 772 | } |
@@ -14,144 +14,144 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Subscriptions_Widget extends WP_Super_Duper { |
16 | 16 | |
17 | - /** |
|
18 | - * Register the widget with WordPress. |
|
19 | - * |
|
20 | - */ |
|
21 | - public function __construct() { |
|
22 | - |
|
23 | - $options = array( |
|
24 | - 'textdomain' => 'invoicing', |
|
25 | - 'block-icon' => 'controls-repeat', |
|
26 | - 'block-category'=> 'widgets', |
|
27 | - 'block-keywords'=> "['invoicing','subscriptions', 'getpaid']", |
|
28 | - 'class_name' => __CLASS__, |
|
29 | - 'base_id' => 'wpinv_subscriptions', |
|
30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
31 | - 'widget_ops' => array( |
|
32 | - 'classname' => 'getpaid-subscriptions bsui', |
|
33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
34 | - ), |
|
35 | - 'arguments' => array( |
|
36 | - 'title' => array( |
|
37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
39 | - 'type' => 'text', |
|
40 | - 'desc_tip' => true, |
|
41 | - 'default' => '', |
|
42 | - 'advanced' => false |
|
43 | - ), |
|
44 | - ) |
|
45 | - |
|
46 | - ); |
|
47 | - |
|
48 | - |
|
49 | - parent::__construct( $options ); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Retrieves current user's subscriptions. |
|
54 | - * |
|
55 | - * @return GetPaid_Subscriptions_Query |
|
56 | - */ |
|
57 | - public function get_subscriptions() { |
|
58 | - |
|
59 | - // Prepare license args. |
|
60 | - $args = array( |
|
61 | - 'customer_in' => get_current_user_id(), |
|
62 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
63 | - ); |
|
64 | - |
|
65 | - return new GetPaid_Subscriptions_Query( $args ); |
|
66 | - |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * The Super block output function. |
|
71 | - * |
|
72 | - * @param array $args |
|
73 | - * @param array $widget_args |
|
74 | - * @param string $content |
|
75 | - * |
|
76 | - * @return mixed|string|bool |
|
77 | - */ |
|
78 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
79 | - |
|
80 | - // Ensure that the user is logged in. |
|
81 | - if ( ! is_user_logged_in() ) { |
|
82 | - |
|
83 | - return aui()->alert( |
|
84 | - array( |
|
85 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
86 | - 'type' => 'error', |
|
87 | - ) |
|
88 | - ); |
|
89 | - |
|
90 | - } |
|
91 | - |
|
92 | - // Are we displaying a single subscription? |
|
93 | - if ( isset( $_GET['subscription'] ) ) { |
|
94 | - return $this->display_single_subscription( trim( $_GET['subscription'] ) ); |
|
95 | - } |
|
96 | - |
|
97 | - // Retrieve the user's subscriptions. |
|
98 | - $subscriptions = $this->get_subscriptions(); |
|
99 | - |
|
100 | - // Start the output buffer. |
|
101 | - ob_start(); |
|
102 | - |
|
103 | - // Backwards compatibility. |
|
104 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
105 | - |
|
106 | - // Display errors and notices. |
|
107 | - wpinv_print_errors(); |
|
108 | - |
|
109 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
110 | - |
|
111 | - // Print the table header. |
|
112 | - $this->print_table_header(); |
|
113 | - |
|
114 | - // Print table body. |
|
115 | - $this->print_table_body( $subscriptions->get_results() ); |
|
116 | - |
|
117 | - // Print table footer. |
|
118 | - $this->print_table_footer(); |
|
119 | - |
|
120 | - // Print the navigation. |
|
121 | - $this->print_navigation( $subscriptions->get_total() ); |
|
122 | - |
|
123 | - // Backwards compatibility. |
|
124 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
125 | - |
|
126 | - // Return the output. |
|
127 | - return ob_get_clean(); |
|
128 | - |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Retrieves the subscription columns. |
|
133 | - * |
|
134 | - * @return array |
|
135 | - */ |
|
136 | - public function get_subscriptions_table_columns() { |
|
17 | + /** |
|
18 | + * Register the widget with WordPress. |
|
19 | + * |
|
20 | + */ |
|
21 | + public function __construct() { |
|
22 | + |
|
23 | + $options = array( |
|
24 | + 'textdomain' => 'invoicing', |
|
25 | + 'block-icon' => 'controls-repeat', |
|
26 | + 'block-category'=> 'widgets', |
|
27 | + 'block-keywords'=> "['invoicing','subscriptions', 'getpaid']", |
|
28 | + 'class_name' => __CLASS__, |
|
29 | + 'base_id' => 'wpinv_subscriptions', |
|
30 | + 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
31 | + 'widget_ops' => array( |
|
32 | + 'classname' => 'getpaid-subscriptions bsui', |
|
33 | + 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
34 | + ), |
|
35 | + 'arguments' => array( |
|
36 | + 'title' => array( |
|
37 | + 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | + 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
39 | + 'type' => 'text', |
|
40 | + 'desc_tip' => true, |
|
41 | + 'default' => '', |
|
42 | + 'advanced' => false |
|
43 | + ), |
|
44 | + ) |
|
45 | + |
|
46 | + ); |
|
47 | + |
|
48 | + |
|
49 | + parent::__construct( $options ); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Retrieves current user's subscriptions. |
|
54 | + * |
|
55 | + * @return GetPaid_Subscriptions_Query |
|
56 | + */ |
|
57 | + public function get_subscriptions() { |
|
58 | + |
|
59 | + // Prepare license args. |
|
60 | + $args = array( |
|
61 | + 'customer_in' => get_current_user_id(), |
|
62 | + 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
63 | + ); |
|
64 | + |
|
65 | + return new GetPaid_Subscriptions_Query( $args ); |
|
66 | + |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * The Super block output function. |
|
71 | + * |
|
72 | + * @param array $args |
|
73 | + * @param array $widget_args |
|
74 | + * @param string $content |
|
75 | + * |
|
76 | + * @return mixed|string|bool |
|
77 | + */ |
|
78 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
79 | + |
|
80 | + // Ensure that the user is logged in. |
|
81 | + if ( ! is_user_logged_in() ) { |
|
82 | + |
|
83 | + return aui()->alert( |
|
84 | + array( |
|
85 | + 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
86 | + 'type' => 'error', |
|
87 | + ) |
|
88 | + ); |
|
89 | + |
|
90 | + } |
|
91 | + |
|
92 | + // Are we displaying a single subscription? |
|
93 | + if ( isset( $_GET['subscription'] ) ) { |
|
94 | + return $this->display_single_subscription( trim( $_GET['subscription'] ) ); |
|
95 | + } |
|
96 | + |
|
97 | + // Retrieve the user's subscriptions. |
|
98 | + $subscriptions = $this->get_subscriptions(); |
|
99 | + |
|
100 | + // Start the output buffer. |
|
101 | + ob_start(); |
|
102 | + |
|
103 | + // Backwards compatibility. |
|
104 | + do_action( 'wpinv_before_user_subscriptions' ); |
|
105 | + |
|
106 | + // Display errors and notices. |
|
107 | + wpinv_print_errors(); |
|
108 | + |
|
109 | + do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
110 | + |
|
111 | + // Print the table header. |
|
112 | + $this->print_table_header(); |
|
113 | + |
|
114 | + // Print table body. |
|
115 | + $this->print_table_body( $subscriptions->get_results() ); |
|
116 | + |
|
117 | + // Print table footer. |
|
118 | + $this->print_table_footer(); |
|
119 | + |
|
120 | + // Print the navigation. |
|
121 | + $this->print_navigation( $subscriptions->get_total() ); |
|
122 | + |
|
123 | + // Backwards compatibility. |
|
124 | + do_action( 'wpinv_after_user_subscriptions' ); |
|
125 | + |
|
126 | + // Return the output. |
|
127 | + return ob_get_clean(); |
|
128 | + |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Retrieves the subscription columns. |
|
133 | + * |
|
134 | + * @return array |
|
135 | + */ |
|
136 | + public function get_subscriptions_table_columns() { |
|
137 | 137 | |
138 | - $columns = array( |
|
139 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
140 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
141 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
142 | - 'status' => __( 'Status', 'invoicing' ), |
|
143 | - ); |
|
138 | + $columns = array( |
|
139 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
140 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
141 | + 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
142 | + 'status' => __( 'Status', 'invoicing' ), |
|
143 | + ); |
|
144 | 144 | |
145 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
146 | - } |
|
145 | + return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * Displays the table header. |
|
150 | - * |
|
151 | - */ |
|
152 | - public function print_table_header() { |
|
148 | + /** |
|
149 | + * Displays the table header. |
|
150 | + * |
|
151 | + */ |
|
152 | + public function print_table_header() { |
|
153 | 153 | |
154 | - ?> |
|
154 | + ?> |
|
155 | 155 | |
156 | 156 | <table class="table table-bordered table-striped"> |
157 | 157 | |
@@ -167,121 +167,121 @@ discard block |
||
167 | 167 | |
168 | 168 | <?php |
169 | 169 | |
170 | - } |
|
170 | + } |
|
171 | 171 | |
172 | - /** |
|
173 | - * Displays the table body. |
|
174 | - * |
|
175 | - * @param WPInv_Subscription[] $subscriptions |
|
176 | - */ |
|
177 | - public function print_table_body( $subscriptions ) { |
|
172 | + /** |
|
173 | + * Displays the table body. |
|
174 | + * |
|
175 | + * @param WPInv_Subscription[] $subscriptions |
|
176 | + */ |
|
177 | + public function print_table_body( $subscriptions ) { |
|
178 | 178 | |
179 | - if ( empty( $subscriptions ) ) { |
|
180 | - $this->print_table_body_no_subscriptions(); |
|
181 | - } else { |
|
182 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
183 | - } |
|
179 | + if ( empty( $subscriptions ) ) { |
|
180 | + $this->print_table_body_no_subscriptions(); |
|
181 | + } else { |
|
182 | + $this->print_table_body_subscriptions( $subscriptions ); |
|
183 | + } |
|
184 | 184 | |
185 | - } |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * Displays the table body if no subscriptions were found. |
|
189 | - * |
|
190 | - */ |
|
191 | - public function print_table_body_no_subscriptions() { |
|
187 | + /** |
|
188 | + * Displays the table body if no subscriptions were found. |
|
189 | + * |
|
190 | + */ |
|
191 | + public function print_table_body_no_subscriptions() { |
|
192 | 192 | |
193 | - ?> |
|
193 | + ?> |
|
194 | 194 | <tbody> |
195 | 195 | |
196 | 196 | <tr> |
197 | 197 | <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
198 | 198 | |
199 | 199 | <?php |
200 | - echo aui()->alert( |
|
201 | - array( |
|
202 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
203 | - 'type' => 'warning', |
|
204 | - ) |
|
205 | - ); |
|
206 | - ?> |
|
200 | + echo aui()->alert( |
|
201 | + array( |
|
202 | + 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
203 | + 'type' => 'warning', |
|
204 | + ) |
|
205 | + ); |
|
206 | + ?> |
|
207 | 207 | |
208 | 208 | </td> |
209 | 209 | </tr> |
210 | 210 | |
211 | 211 | </tbody> |
212 | 212 | <?php |
213 | - } |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * Displays the table body if subscriptions were found. |
|
217 | - * |
|
218 | - * @param WPInv_Subscription[] $subscriptions |
|
219 | - */ |
|
220 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
215 | + /** |
|
216 | + * Displays the table body if subscriptions were found. |
|
217 | + * |
|
218 | + * @param WPInv_Subscription[] $subscriptions |
|
219 | + */ |
|
220 | + public function print_table_body_subscriptions( $subscriptions ) { |
|
221 | 221 | |
222 | - ?> |
|
222 | + ?> |
|
223 | 223 | <tbody> |
224 | 224 | |
225 | 225 | <?php foreach ( $subscriptions as $subscription ) : ?> |
226 | 226 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
227 | 227 | <?php |
228 | - wpinv_get_template( |
|
229 | - 'subscriptions/subscriptions-table-row.php', |
|
230 | - array( |
|
231 | - 'subscription' => $subscription, |
|
232 | - 'widget' => $this |
|
233 | - ) |
|
234 | - ); |
|
235 | - ?> |
|
228 | + wpinv_get_template( |
|
229 | + 'subscriptions/subscriptions-table-row.php', |
|
230 | + array( |
|
231 | + 'subscription' => $subscription, |
|
232 | + 'widget' => $this |
|
233 | + ) |
|
234 | + ); |
|
235 | + ?> |
|
236 | 236 | </tr> |
237 | 237 | <?php endforeach; ?> |
238 | 238 | |
239 | 239 | </tbody> |
240 | 240 | <?php |
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Adds row actions to a column |
|
245 | - * |
|
246 | - * @param string $content column content |
|
247 | - * @param WPInv_Subscription $subscription |
|
248 | - * @since 1.0.0 |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function add_row_actions( $content, $subscription ) { |
|
252 | - |
|
253 | - // Prepare row actions. |
|
254 | - $actions = array(); |
|
255 | - |
|
256 | - // View subscription action. |
|
257 | - $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
258 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
259 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
260 | - |
|
261 | - // Filter the actions. |
|
262 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
263 | - |
|
264 | - $sanitized = array(); |
|
265 | - foreach ( $actions as $key => $action ) { |
|
266 | - $key = sanitize_html_class( $key ); |
|
267 | - $action = wp_kses_post( $action ); |
|
268 | - $sanitized[] = "<span class='$key'>$action</span>"; |
|
269 | - } |
|
270 | - |
|
271 | - $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
272 | - $row_actions .= implode( ' | ', $sanitized ); |
|
273 | - $row_actions .= '</small>'; |
|
274 | - |
|
275 | - return $content . $row_actions; |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Displays the table footer. |
|
280 | - * |
|
281 | - */ |
|
282 | - public function print_table_footer() { |
|
283 | - |
|
284 | - ?> |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Adds row actions to a column |
|
245 | + * |
|
246 | + * @param string $content column content |
|
247 | + * @param WPInv_Subscription $subscription |
|
248 | + * @since 1.0.0 |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function add_row_actions( $content, $subscription ) { |
|
252 | + |
|
253 | + // Prepare row actions. |
|
254 | + $actions = array(); |
|
255 | + |
|
256 | + // View subscription action. |
|
257 | + $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
258 | + $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
259 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
260 | + |
|
261 | + // Filter the actions. |
|
262 | + $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
263 | + |
|
264 | + $sanitized = array(); |
|
265 | + foreach ( $actions as $key => $action ) { |
|
266 | + $key = sanitize_html_class( $key ); |
|
267 | + $action = wp_kses_post( $action ); |
|
268 | + $sanitized[] = "<span class='$key'>$action</span>"; |
|
269 | + } |
|
270 | + |
|
271 | + $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
272 | + $row_actions .= implode( ' | ', $sanitized ); |
|
273 | + $row_actions .= '</small>'; |
|
274 | + |
|
275 | + return $content . $row_actions; |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Displays the table footer. |
|
280 | + * |
|
281 | + */ |
|
282 | + public function print_table_footer() { |
|
283 | + |
|
284 | + ?> |
|
285 | 285 | |
286 | 286 | <tfoot> |
287 | 287 | <tr> |
@@ -296,129 +296,129 @@ discard block |
||
296 | 296 | </table> |
297 | 297 | <?php |
298 | 298 | |
299 | - } |
|
299 | + } |
|
300 | 300 | |
301 | - /** |
|
302 | - * Displays the navigation. |
|
303 | - * |
|
304 | - * @param int $total |
|
305 | - */ |
|
306 | - public function print_navigation( $total ) { |
|
301 | + /** |
|
302 | + * Displays the navigation. |
|
303 | + * |
|
304 | + * @param int $total |
|
305 | + */ |
|
306 | + public function print_navigation( $total ) { |
|
307 | 307 | |
308 | - if ( $total < 1 ) { |
|
308 | + if ( $total < 1 ) { |
|
309 | 309 | |
310 | - // Out-of-bounds, run the query again without LIMIT for total count. |
|
311 | - $args = array( |
|
312 | - 'customer_in' => get_current_user_id(), |
|
313 | - 'fields' => 'id', |
|
314 | - ); |
|
310 | + // Out-of-bounds, run the query again without LIMIT for total count. |
|
311 | + $args = array( |
|
312 | + 'customer_in' => get_current_user_id(), |
|
313 | + 'fields' => 'id', |
|
314 | + ); |
|
315 | 315 | |
316 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
317 | - $total = $count_query->get_total(); |
|
318 | - } |
|
316 | + $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
317 | + $total = $count_query->get_total(); |
|
318 | + } |
|
319 | 319 | |
320 | - // Abort if we do not have pages. |
|
321 | - if ( 2 > $total ) { |
|
322 | - return; |
|
323 | - } |
|
320 | + // Abort if we do not have pages. |
|
321 | + if ( 2 > $total ) { |
|
322 | + return; |
|
323 | + } |
|
324 | 324 | |
325 | - ?> |
|
325 | + ?> |
|
326 | 326 | |
327 | 327 | <div class="getpaid-subscriptions-pagination"> |
328 | 328 | <?php |
329 | - $big = 999999; |
|
330 | - |
|
331 | - echo getpaid_paginate_links( |
|
332 | - array( |
|
333 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
334 | - 'format' => '?paged=%#%', |
|
335 | - 'total' => (int) ceil( $total / 10 ), |
|
336 | - ) |
|
337 | - ); |
|
338 | - ?> |
|
329 | + $big = 999999; |
|
330 | + |
|
331 | + echo getpaid_paginate_links( |
|
332 | + array( |
|
333 | + 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
334 | + 'format' => '?paged=%#%', |
|
335 | + 'total' => (int) ceil( $total / 10 ), |
|
336 | + ) |
|
337 | + ); |
|
338 | + ?> |
|
339 | 339 | </div> |
340 | 340 | |
341 | 341 | <?php |
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Returns a single subscription's columns. |
|
346 | - * |
|
347 | - * @param WPInv_Subscription $subscription |
|
348 | - * |
|
349 | - * @return array |
|
350 | - */ |
|
351 | - public function get_single_subscription_columns( $subscription ) { |
|
352 | - |
|
353 | - // Prepare subscription detail columns. |
|
354 | - $fields = apply_filters( |
|
355 | - 'getpaid_single_subscription_details_fields', |
|
356 | - array( |
|
357 | - 'status' => __( 'Status', 'invoicing' ), |
|
358 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
359 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
360 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
361 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
362 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
363 | - 'item' => __( 'Item', 'invoicing' ), |
|
364 | - ), |
|
365 | - $subscription |
|
366 | - ); |
|
367 | - |
|
368 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
369 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
370 | - } |
|
371 | - |
|
372 | - if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) { |
|
373 | - unset( $fields['initial_amount'] ); |
|
374 | - } |
|
375 | - |
|
376 | - return $fields; |
|
377 | - } |
|
378 | - |
|
379 | - /** |
|
380 | - * Displays a single subscription. |
|
381 | - * |
|
382 | - * @param string $subscription |
|
383 | - * |
|
384 | - * @return string |
|
385 | - */ |
|
386 | - public function display_single_subscription( $subscription ) { |
|
387 | - |
|
388 | - // Fetch the subscription. |
|
389 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
390 | - |
|
391 | - if ( ! $subscription->get_id() ) { |
|
392 | - |
|
393 | - return aui()->alert( |
|
394 | - array( |
|
395 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
396 | - 'type' => 'error', |
|
397 | - ) |
|
398 | - ); |
|
399 | - |
|
400 | - } |
|
401 | - |
|
402 | - // Ensure that the user owns this subscription key. |
|
403 | - if ( get_current_user_id() != $subscription->get_customer_id() && current_user_can( 'edit_options' ) ) { |
|
404 | - |
|
405 | - return aui()->alert( |
|
406 | - array( |
|
407 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
408 | - 'type' => 'error', |
|
409 | - ) |
|
410 | - ); |
|
411 | - |
|
412 | - } |
|
413 | - |
|
414 | - return wpinv_get_template_html( |
|
415 | - 'subscriptions/subscription-details.php', |
|
416 | - array( |
|
417 | - 'subscription' => $subscription, |
|
418 | - 'widget' => $this |
|
419 | - ) |
|
420 | - ); |
|
421 | - |
|
422 | - } |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Returns a single subscription's columns. |
|
346 | + * |
|
347 | + * @param WPInv_Subscription $subscription |
|
348 | + * |
|
349 | + * @return array |
|
350 | + */ |
|
351 | + public function get_single_subscription_columns( $subscription ) { |
|
352 | + |
|
353 | + // Prepare subscription detail columns. |
|
354 | + $fields = apply_filters( |
|
355 | + 'getpaid_single_subscription_details_fields', |
|
356 | + array( |
|
357 | + 'status' => __( 'Status', 'invoicing' ), |
|
358 | + 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
359 | + 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
360 | + 'start_date' => __( 'Start date', 'invoicing' ), |
|
361 | + 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
362 | + 'payments' => __( 'Payments', 'invoicing' ), |
|
363 | + 'item' => __( 'Item', 'invoicing' ), |
|
364 | + ), |
|
365 | + $subscription |
|
366 | + ); |
|
367 | + |
|
368 | + if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
369 | + $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
370 | + } |
|
371 | + |
|
372 | + if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) { |
|
373 | + unset( $fields['initial_amount'] ); |
|
374 | + } |
|
375 | + |
|
376 | + return $fields; |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * Displays a single subscription. |
|
381 | + * |
|
382 | + * @param string $subscription |
|
383 | + * |
|
384 | + * @return string |
|
385 | + */ |
|
386 | + public function display_single_subscription( $subscription ) { |
|
387 | + |
|
388 | + // Fetch the subscription. |
|
389 | + $subscription = new WPInv_Subscription( (int) $subscription ); |
|
390 | + |
|
391 | + if ( ! $subscription->get_id() ) { |
|
392 | + |
|
393 | + return aui()->alert( |
|
394 | + array( |
|
395 | + 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
396 | + 'type' => 'error', |
|
397 | + ) |
|
398 | + ); |
|
399 | + |
|
400 | + } |
|
401 | + |
|
402 | + // Ensure that the user owns this subscription key. |
|
403 | + if ( get_current_user_id() != $subscription->get_customer_id() && current_user_can( 'edit_options' ) ) { |
|
404 | + |
|
405 | + return aui()->alert( |
|
406 | + array( |
|
407 | + 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
408 | + 'type' => 'error', |
|
409 | + ) |
|
410 | + ); |
|
411 | + |
|
412 | + } |
|
413 | + |
|
414 | + return wpinv_get_template_html( |
|
415 | + 'subscriptions/subscription-details.php', |
|
416 | + array( |
|
417 | + 'subscription' => $subscription, |
|
418 | + 'widget' => $this |
|
419 | + ) |
|
420 | + ); |
|
421 | + |
|
422 | + } |
|
423 | 423 | |
424 | 424 | } |
@@ -411,9 +411,9 @@ |
||
411 | 411 | $bill_times = $item->get_recurring_limit(); |
412 | 412 | |
413 | 413 | if ( ! empty( $bill_times ) ) { |
414 | - $bill_times = $item->get_recurring_interval() * $bill_times; |
|
415 | - $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
416 | - } |
|
414 | + $bill_times = $item->get_recurring_interval() * $bill_times; |
|
415 | + $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
416 | + } |
|
417 | 417 | |
418 | 418 | if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
419 | 419 | $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
@@ -12,280 +12,280 @@ |
||
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 | - $this->add_data( $submission ); |
|
42 | - |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Adds totals to a response for submission refresh prices. |
|
47 | - * |
|
48 | - * @param GetPaid_Payment_Form_Submission $submission |
|
49 | - */ |
|
50 | - public function add_totals( $submission ) { |
|
51 | - |
|
52 | - $this->response = array_merge( |
|
53 | - $this->response, |
|
54 | - array( |
|
55 | - |
|
56 | - 'totals' => array( |
|
57 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
58 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
59 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
60 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
61 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
62 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
63 | - ), |
|
64 | - |
|
65 | - 'recurring' => array( |
|
66 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
67 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
68 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
69 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
70 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
71 | - ), |
|
72 | - |
|
73 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
74 | - 'currency' => $submission->get_currency(), |
|
75 | - |
|
76 | - ) |
|
77 | - ); |
|
78 | - |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Adds texts to a response for submission refresh prices. |
|
83 | - * |
|
84 | - * @param GetPaid_Payment_Form_Submission $submission |
|
85 | - */ |
|
86 | - public function add_texts( $submission ) { |
|
87 | - |
|
88 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
89 | - |
|
90 | - if ( $submission->has_recurring != 0 ) { |
|
91 | - |
|
92 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
93 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
94 | - |
|
95 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
96 | - $payable = "$payable / $period"; |
|
97 | - } else { |
|
98 | - $payable = sprintf( |
|
99 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
100 | - $submission->format_amount( $submission->get_total() ), |
|
101 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
102 | - $period |
|
103 | - ); |
|
104 | - } |
|
105 | - |
|
106 | - } |
|
107 | - |
|
108 | - $texts = array( |
|
109 | - '.getpaid-checkout-total-payable' => $payable, |
|
110 | - ); |
|
111 | - |
|
112 | - foreach ( $submission->get_items() as $item ) { |
|
113 | - $item_id = $item->get_id(); |
|
114 | - $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
115 | - $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
116 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
117 | - } |
|
118 | - |
|
119 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
120 | - |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Adds items to a response for submission refresh prices. |
|
125 | - * |
|
126 | - * @param GetPaid_Payment_Form_Submission $submission |
|
127 | - */ |
|
128 | - public function add_items( $submission ) { |
|
129 | - |
|
130 | - // Add items. |
|
131 | - $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 | + $this->add_data( $submission ); |
|
42 | + |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Adds totals to a response for submission refresh prices. |
|
47 | + * |
|
48 | + * @param GetPaid_Payment_Form_Submission $submission |
|
49 | + */ |
|
50 | + public function add_totals( $submission ) { |
|
51 | + |
|
52 | + $this->response = array_merge( |
|
53 | + $this->response, |
|
54 | + array( |
|
55 | + |
|
56 | + 'totals' => array( |
|
57 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
58 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
59 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
60 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
61 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
62 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
63 | + ), |
|
64 | + |
|
65 | + 'recurring' => array( |
|
66 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
67 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
68 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
69 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
70 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
71 | + ), |
|
72 | + |
|
73 | + 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
74 | + 'currency' => $submission->get_currency(), |
|
75 | + |
|
76 | + ) |
|
77 | + ); |
|
78 | + |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Adds texts to a response for submission refresh prices. |
|
83 | + * |
|
84 | + * @param GetPaid_Payment_Form_Submission $submission |
|
85 | + */ |
|
86 | + public function add_texts( $submission ) { |
|
87 | + |
|
88 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
89 | + |
|
90 | + if ( $submission->has_recurring != 0 ) { |
|
91 | + |
|
92 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
93 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
94 | + |
|
95 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
96 | + $payable = "$payable / $period"; |
|
97 | + } else { |
|
98 | + $payable = sprintf( |
|
99 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
100 | + $submission->format_amount( $submission->get_total() ), |
|
101 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
102 | + $period |
|
103 | + ); |
|
104 | + } |
|
105 | + |
|
106 | + } |
|
107 | + |
|
108 | + $texts = array( |
|
109 | + '.getpaid-checkout-total-payable' => $payable, |
|
110 | + ); |
|
132 | 111 | |
133 | 112 | foreach ( $submission->get_items() as $item ) { |
134 | - $item_id = $item->get_id(); |
|
135 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
136 | - } |
|
113 | + $item_id = $item->get_id(); |
|
114 | + $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
115 | + $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
116 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
117 | + } |
|
137 | 118 | |
138 | - $this->response = array_merge( |
|
139 | - $this->response, |
|
140 | - array( 'items' => $items ) |
|
141 | - ); |
|
119 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
142 | 120 | |
143 | - } |
|
121 | + } |
|
144 | 122 | |
145 | - /** |
|
146 | - * Adds fees to a response for submission refresh prices. |
|
147 | - * |
|
148 | - * @param GetPaid_Payment_Form_Submission $submission |
|
149 | - */ |
|
150 | - public function add_fees( $submission ) { |
|
123 | + /** |
|
124 | + * Adds items to a response for submission refresh prices. |
|
125 | + * |
|
126 | + * @param GetPaid_Payment_Form_Submission $submission |
|
127 | + */ |
|
128 | + public function add_items( $submission ) { |
|
151 | 129 | |
152 | - $fees = array(); |
|
130 | + // Add items. |
|
131 | + $items = array(); |
|
153 | 132 | |
154 | - foreach ( $submission->get_fees() as $name => $data ) { |
|
155 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
156 | - } |
|
133 | + foreach ( $submission->get_items() as $item ) { |
|
134 | + $item_id = $item->get_id(); |
|
135 | + $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
136 | + } |
|
157 | 137 | |
158 | - $this->response = array_merge( |
|
159 | - $this->response, |
|
160 | - array( 'fees' => $fees ) |
|
161 | - ); |
|
138 | + $this->response = array_merge( |
|
139 | + $this->response, |
|
140 | + array( 'items' => $items ) |
|
141 | + ); |
|
162 | 142 | |
163 | - } |
|
143 | + } |
|
164 | 144 | |
165 | - /** |
|
166 | - * Adds discounts to a response for submission refresh prices. |
|
167 | - * |
|
168 | - * @param GetPaid_Payment_Form_Submission $submission |
|
169 | - */ |
|
170 | - public function add_discounts( $submission ) { |
|
145 | + /** |
|
146 | + * Adds fees to a response for submission refresh prices. |
|
147 | + * |
|
148 | + * @param GetPaid_Payment_Form_Submission $submission |
|
149 | + */ |
|
150 | + public function add_fees( $submission ) { |
|
171 | 151 | |
172 | - $discounts = array(); |
|
152 | + $fees = array(); |
|
173 | 153 | |
174 | - foreach ( $submission->get_discounts() as $name => $data ) { |
|
175 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
176 | - } |
|
154 | + foreach ( $submission->get_fees() as $name => $data ) { |
|
155 | + $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
156 | + } |
|
177 | 157 | |
178 | - $this->response = array_merge( |
|
179 | - $this->response, |
|
180 | - array( 'discounts' => $discounts ) |
|
181 | - ); |
|
158 | + $this->response = array_merge( |
|
159 | + $this->response, |
|
160 | + array( 'fees' => $fees ) |
|
161 | + ); |
|
182 | 162 | |
183 | - } |
|
163 | + } |
|
184 | 164 | |
185 | - /** |
|
186 | - * Adds taxes to a response for submission refresh prices. |
|
187 | - * |
|
188 | - * @param GetPaid_Payment_Form_Submission $submission |
|
189 | - */ |
|
190 | - public function add_taxes( $submission ) { |
|
165 | + /** |
|
166 | + * Adds discounts to a response for submission refresh prices. |
|
167 | + * |
|
168 | + * @param GetPaid_Payment_Form_Submission $submission |
|
169 | + */ |
|
170 | + public function add_discounts( $submission ) { |
|
191 | 171 | |
192 | - $taxes = array(); |
|
193 | - $markup = ''; |
|
194 | - foreach ( $submission->get_taxes() as $name => $data ) { |
|
195 | - $name = sanitize_text_field( $name ); |
|
196 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
197 | - $taxes[$name] = $amount; |
|
198 | - $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
199 | - } |
|
172 | + $discounts = array(); |
|
173 | + |
|
174 | + foreach ( $submission->get_discounts() as $name => $data ) { |
|
175 | + $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
176 | + } |
|
200 | 177 | |
201 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
202 | - $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
203 | - } |
|
178 | + $this->response = array_merge( |
|
179 | + $this->response, |
|
180 | + array( 'discounts' => $discounts ) |
|
181 | + ); |
|
204 | 182 | |
205 | - $this->response = array_merge( |
|
206 | - $this->response, |
|
207 | - array( 'taxes' => $taxes ) |
|
208 | - ); |
|
183 | + } |
|
209 | 184 | |
210 | - } |
|
185 | + /** |
|
186 | + * Adds taxes to a response for submission refresh prices. |
|
187 | + * |
|
188 | + * @param GetPaid_Payment_Form_Submission $submission |
|
189 | + */ |
|
190 | + public function add_taxes( $submission ) { |
|
191 | + |
|
192 | + $taxes = array(); |
|
193 | + $markup = ''; |
|
194 | + foreach ( $submission->get_taxes() as $name => $data ) { |
|
195 | + $name = sanitize_text_field( $name ); |
|
196 | + $amount = $submission->format_amount( $data['initial_tax'] ); |
|
197 | + $taxes[$name] = $amount; |
|
198 | + $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
199 | + } |
|
211 | 200 | |
212 | - /** |
|
213 | - * Adds gateways to a response for submission refresh prices. |
|
214 | - * |
|
215 | - * @param GetPaid_Payment_Form_Submission $submission |
|
216 | - */ |
|
217 | - public function add_gateways( $submission ) { |
|
201 | + if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
202 | + $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
203 | + } |
|
218 | 204 | |
219 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
205 | + $this->response = array_merge( |
|
206 | + $this->response, |
|
207 | + array( 'taxes' => $taxes ) |
|
208 | + ); |
|
220 | 209 | |
221 | - if ( $this->response['has_recurring'] ) { |
|
210 | + } |
|
222 | 211 | |
223 | - foreach ( $gateways as $i => $gateway ) { |
|
212 | + /** |
|
213 | + * Adds gateways to a response for submission refresh prices. |
|
214 | + * |
|
215 | + * @param GetPaid_Payment_Form_Submission $submission |
|
216 | + */ |
|
217 | + public function add_gateways( $submission ) { |
|
224 | 218 | |
225 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
226 | - unset( $gateways[ $i ] ); |
|
227 | - } |
|
219 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
228 | 220 | |
229 | - } |
|
221 | + if ( $this->response['has_recurring'] ) { |
|
230 | 222 | |
231 | - } |
|
223 | + foreach ( $gateways as $i => $gateway ) { |
|
232 | 224 | |
225 | + if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
226 | + unset( $gateways[ $i ] ); |
|
227 | + } |
|
233 | 228 | |
234 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
235 | - $this->response = array_merge( |
|
236 | - $this->response, |
|
237 | - array( 'gateways' => $gateways ) |
|
238 | - ); |
|
229 | + } |
|
239 | 230 | |
240 | - } |
|
231 | + } |
|
241 | 232 | |
242 | - /** |
|
243 | - * Standardizes prices. |
|
244 | - * |
|
245 | - * @param int $item_id |
|
246 | - * @param float $item_total |
|
247 | - * @param string $discount_code |
|
248 | - * @param bool $recurring |
|
249 | - */ |
|
250 | - public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
251 | 233 | |
252 | - $standardadized_price = $item_total; |
|
234 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
235 | + $this->response = array_merge( |
|
236 | + $this->response, |
|
237 | + array( 'gateways' => $gateways ) |
|
238 | + ); |
|
253 | 239 | |
254 | - // Do we have a $discount_code? |
|
255 | - if ( ! empty( $discount_code ) ) { |
|
240 | + } |
|
256 | 241 | |
257 | - $discount = new WPInv_Discount( $discount_code ); |
|
242 | + /** |
|
243 | + * Standardizes prices. |
|
244 | + * |
|
245 | + * @param int $item_id |
|
246 | + * @param float $item_total |
|
247 | + * @param string $discount_code |
|
248 | + * @param bool $recurring |
|
249 | + */ |
|
250 | + public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
251 | + |
|
252 | + $standardadized_price = $item_total; |
|
258 | 253 | |
259 | - if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
260 | - $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
261 | - } |
|
254 | + // Do we have a $discount_code? |
|
255 | + if ( ! empty( $discount_code ) ) { |
|
262 | 256 | |
263 | - } |
|
257 | + $discount = new WPInv_Discount( $discount_code ); |
|
264 | 258 | |
265 | - return max( 0, $standardadized_price ); |
|
259 | + if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
260 | + $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
261 | + } |
|
266 | 262 | |
267 | - } |
|
263 | + } |
|
268 | 264 | |
269 | - /** |
|
270 | - * Adds data to a response for submission refresh prices. |
|
271 | - * |
|
272 | - * @param GetPaid_Payment_Form_Submission $submission |
|
273 | - */ |
|
274 | - public function add_data( $submission ) { |
|
265 | + return max( 0, $standardadized_price ); |
|
275 | 266 | |
276 | - $this->response = array_merge( |
|
277 | - $this->response, |
|
278 | - array( |
|
279 | - 'js_data' => apply_filters( |
|
280 | - 'getpaid_submission_js_data', |
|
281 | - array( |
|
282 | - 'is_recurring' => $this->response['has_recurring'], |
|
283 | - ), |
|
284 | - $submission |
|
285 | - ) |
|
286 | - ) |
|
287 | - ); |
|
267 | + } |
|
288 | 268 | |
289 | - } |
|
269 | + /** |
|
270 | + * Adds data to a response for submission refresh prices. |
|
271 | + * |
|
272 | + * @param GetPaid_Payment_Form_Submission $submission |
|
273 | + */ |
|
274 | + public function add_data( $submission ) { |
|
275 | + |
|
276 | + $this->response = array_merge( |
|
277 | + $this->response, |
|
278 | + array( |
|
279 | + 'js_data' => apply_filters( |
|
280 | + 'getpaid_submission_js_data', |
|
281 | + array( |
|
282 | + 'is_recurring' => $this->response['has_recurring'], |
|
283 | + ), |
|
284 | + $submission |
|
285 | + ) |
|
286 | + ) |
|
287 | + ); |
|
288 | + |
|
289 | + } |
|
290 | 290 | |
291 | 291 | } |
@@ -7,40 +7,40 @@ |
||
7 | 7 | * Bail if we are not in WP. |
8 | 8 | */ |
9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
10 | - exit; |
|
10 | + exit; |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Set the version only if its the current newest while loading. |
15 | 15 | */ |
16 | 16 | add_action('after_setup_theme', function () { |
17 | - global $ayecode_ui_version,$ayecode_ui_file_key; |
|
18 | - $this_version = "0.1.46"; |
|
19 | - if(version_compare($this_version , $ayecode_ui_version, '>')){ |
|
20 | - $ayecode_ui_version = $this_version ; |
|
21 | - $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
22 | - } |
|
17 | + global $ayecode_ui_version,$ayecode_ui_file_key; |
|
18 | + $this_version = "0.1.46"; |
|
19 | + if(version_compare($this_version , $ayecode_ui_version, '>')){ |
|
20 | + $ayecode_ui_version = $this_version ; |
|
21 | + $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
22 | + } |
|
23 | 23 | },0); |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Load this version of WP Bootstrap Settings only if the file hash is the current one. |
27 | 27 | */ |
28 | 28 | add_action('after_setup_theme', function () { |
29 | - global $ayecode_ui_file_key; |
|
30 | - if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
31 | - include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
32 | - include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
33 | - } |
|
29 | + global $ayecode_ui_file_key; |
|
30 | + if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
31 | + include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
32 | + include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
33 | + } |
|
34 | 34 | },1); |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Add the function that calls the class. |
38 | 38 | */ |
39 | 39 | if(!function_exists('aui')){ |
40 | - function aui(){ |
|
41 | - if(!class_exists("AUI",false)){ |
|
42 | - return false; |
|
43 | - } |
|
44 | - return AUI::instance(); |
|
45 | - } |
|
40 | + function aui(){ |
|
41 | + if(!class_exists("AUI",false)){ |
|
42 | + return false; |
|
43 | + } |
|
44 | + return AUI::instance(); |
|
45 | + } |
|
46 | 46 | } |
47 | 47 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; // Exit if accessed directly |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -11,231 +11,231 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI { |
13 | 13 | |
14 | - /** |
|
15 | - * Holds the class instance. |
|
16 | - * |
|
17 | - * @since 1.0.0 |
|
18 | - * @var null |
|
19 | - */ |
|
20 | - private static $instance = null; |
|
21 | - |
|
22 | - /** |
|
23 | - * Holds the current AUI version number. |
|
24 | - * |
|
25 | - * @var string $ver The current version number. |
|
26 | - */ |
|
27 | - public static $ver = '0.1.46'; |
|
28 | - |
|
29 | - public static $options = null; |
|
30 | - |
|
31 | - /** |
|
32 | - * There can be only one. |
|
33 | - * |
|
34 | - * @since 1.0.0 |
|
35 | - * @return AUI|null |
|
36 | - */ |
|
37 | - public static function instance() { |
|
38 | - if ( self::$instance == null ) { |
|
39 | - self::$instance = new AUI(); |
|
40 | - } |
|
41 | - |
|
42 | - return self::$instance; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * AUI constructor. |
|
47 | - * |
|
48 | - * @since 1.0.0 |
|
49 | - */ |
|
50 | - private function __construct() { |
|
51 | - if ( function_exists( "__autoload" ) ) { |
|
52 | - spl_autoload_register( "__autoload" ); |
|
53 | - } |
|
54 | - spl_autoload_register( array( $this, 'autoload' ) ); |
|
55 | - |
|
56 | - // load options |
|
57 | - self::$options = get_option('aui_options'); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Autoload any components on the fly. |
|
62 | - * |
|
63 | - * @since 1.0.0 |
|
64 | - * |
|
65 | - * @param $classname |
|
66 | - */ |
|
67 | - private function autoload( $classname ) { |
|
68 | - $class = str_replace( '_', '-', strtolower( $classname ) ); |
|
69 | - $file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php'; |
|
70 | - if ( $file_path && is_readable( $file_path ) ) { |
|
71 | - include_once( $file_path ); |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Get the AUI options. |
|
77 | - * |
|
78 | - * @param $option |
|
79 | - * |
|
80 | - * @return string|void |
|
81 | - */ |
|
82 | - public function get_option( $option ){ |
|
83 | - $result = isset(self::$options[$option]) ? esc_attr(self::$options[$option]) : ''; |
|
84 | - |
|
85 | - if ( ! $result && $option) { |
|
86 | - if( $option == 'color_primary' ){ |
|
87 | - $result = AUI_PRIMARY_COLOR; |
|
88 | - }elseif( $option == 'color_secondary' ){ |
|
89 | - $result = AUI_SECONDARY_COLOR; |
|
90 | - } |
|
91 | - } |
|
92 | - return $result; |
|
93 | - } |
|
94 | - |
|
95 | - public function render( $items = array() ) { |
|
96 | - $output = ''; |
|
97 | - |
|
98 | - if ( ! empty( $items ) ) { |
|
99 | - foreach ( $items as $args ) { |
|
100 | - $render = isset( $args['render'] ) ? $args['render'] : ''; |
|
101 | - if ( $render && method_exists( __CLASS__, $render ) ) { |
|
102 | - $output .= $this->$render( $args ); |
|
103 | - } |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - return $output; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Render and return a bootstrap alert component. |
|
112 | - * |
|
113 | - * @since 1.0.0 |
|
114 | - * |
|
115 | - * @param array $args |
|
116 | - * |
|
117 | - * @return string The rendered component. |
|
118 | - */ |
|
119 | - public function alert( $args = array() ) { |
|
120 | - return AUI_Component_Alert::get( $args ); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Render and return a bootstrap input component. |
|
125 | - * |
|
126 | - * @since 1.0.0 |
|
127 | - * |
|
128 | - * @param array $args |
|
129 | - * |
|
130 | - * @return string The rendered component. |
|
131 | - */ |
|
132 | - public function input( $args = array() ) { |
|
133 | - return AUI_Component_Input::input( $args ); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Render and return a bootstrap textarea component. |
|
138 | - * |
|
139 | - * @since 1.0.0 |
|
140 | - * |
|
141 | - * @param array $args |
|
142 | - * |
|
143 | - * @return string The rendered component. |
|
144 | - */ |
|
145 | - public function textarea( $args = array() ) { |
|
146 | - return AUI_Component_Input::textarea( $args ); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Render and return a bootstrap button component. |
|
151 | - * |
|
152 | - * @since 1.0.0 |
|
153 | - * |
|
154 | - * @param array $args |
|
155 | - * |
|
156 | - * @return string The rendered component. |
|
157 | - */ |
|
158 | - public function button( $args = array() ) { |
|
159 | - return AUI_Component_Button::get( $args ); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Render and return a bootstrap button component. |
|
164 | - * |
|
165 | - * @since 1.0.0 |
|
166 | - * |
|
167 | - * @param array $args |
|
168 | - * |
|
169 | - * @return string The rendered component. |
|
170 | - */ |
|
171 | - public function badge( $args = array() ) { |
|
172 | - $defaults = array( |
|
173 | - 'class' => 'badge badge-primary align-middle', |
|
174 | - ); |
|
175 | - |
|
176 | - // maybe set type |
|
177 | - if ( empty( $args['href'] ) ) { |
|
178 | - $defaults['type'] = 'badge'; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Parse incoming $args into an array and merge it with $defaults |
|
183 | - */ |
|
184 | - $args = wp_parse_args( $args, $defaults ); |
|
185 | - |
|
186 | - return AUI_Component_Button::get( $args ); |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Render and return a bootstrap dropdown component. |
|
191 | - * |
|
192 | - * @since 1.0.0 |
|
193 | - * |
|
194 | - * @param array $args |
|
195 | - * |
|
196 | - * @return string The rendered component. |
|
197 | - */ |
|
198 | - public function dropdown( $args = array() ) { |
|
199 | - return AUI_Component_Dropdown::get( $args ); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Render and return a bootstrap select component. |
|
204 | - * |
|
205 | - * @since 1.0.0 |
|
206 | - * |
|
207 | - * @param array $args |
|
208 | - * |
|
209 | - * @return string The rendered component. |
|
210 | - */ |
|
211 | - public function select( $args = array() ) { |
|
212 | - return AUI_Component_Input::select( $args ); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Render and return a bootstrap radio component. |
|
217 | - * |
|
218 | - * @since 1.0.0 |
|
219 | - * |
|
220 | - * @param array $args |
|
221 | - * |
|
222 | - * @return string The rendered component. |
|
223 | - */ |
|
224 | - public function radio( $args = array() ) { |
|
225 | - return AUI_Component_Input::radio( $args ); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Render and return a bootstrap pagination component. |
|
230 | - * |
|
231 | - * @since 1.0.0 |
|
232 | - * |
|
233 | - * @param array $args |
|
234 | - * |
|
235 | - * @return string The rendered component. |
|
236 | - */ |
|
237 | - public function pagination( $args = array() ) { |
|
238 | - return AUI_Component_Pagination::get( $args ); |
|
239 | - } |
|
14 | + /** |
|
15 | + * Holds the class instance. |
|
16 | + * |
|
17 | + * @since 1.0.0 |
|
18 | + * @var null |
|
19 | + */ |
|
20 | + private static $instance = null; |
|
21 | + |
|
22 | + /** |
|
23 | + * Holds the current AUI version number. |
|
24 | + * |
|
25 | + * @var string $ver The current version number. |
|
26 | + */ |
|
27 | + public static $ver = '0.1.46'; |
|
28 | + |
|
29 | + public static $options = null; |
|
30 | + |
|
31 | + /** |
|
32 | + * There can be only one. |
|
33 | + * |
|
34 | + * @since 1.0.0 |
|
35 | + * @return AUI|null |
|
36 | + */ |
|
37 | + public static function instance() { |
|
38 | + if ( self::$instance == null ) { |
|
39 | + self::$instance = new AUI(); |
|
40 | + } |
|
41 | + |
|
42 | + return self::$instance; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * AUI constructor. |
|
47 | + * |
|
48 | + * @since 1.0.0 |
|
49 | + */ |
|
50 | + private function __construct() { |
|
51 | + if ( function_exists( "__autoload" ) ) { |
|
52 | + spl_autoload_register( "__autoload" ); |
|
53 | + } |
|
54 | + spl_autoload_register( array( $this, 'autoload' ) ); |
|
55 | + |
|
56 | + // load options |
|
57 | + self::$options = get_option('aui_options'); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Autoload any components on the fly. |
|
62 | + * |
|
63 | + * @since 1.0.0 |
|
64 | + * |
|
65 | + * @param $classname |
|
66 | + */ |
|
67 | + private function autoload( $classname ) { |
|
68 | + $class = str_replace( '_', '-', strtolower( $classname ) ); |
|
69 | + $file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php'; |
|
70 | + if ( $file_path && is_readable( $file_path ) ) { |
|
71 | + include_once( $file_path ); |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Get the AUI options. |
|
77 | + * |
|
78 | + * @param $option |
|
79 | + * |
|
80 | + * @return string|void |
|
81 | + */ |
|
82 | + public function get_option( $option ){ |
|
83 | + $result = isset(self::$options[$option]) ? esc_attr(self::$options[$option]) : ''; |
|
84 | + |
|
85 | + if ( ! $result && $option) { |
|
86 | + if( $option == 'color_primary' ){ |
|
87 | + $result = AUI_PRIMARY_COLOR; |
|
88 | + }elseif( $option == 'color_secondary' ){ |
|
89 | + $result = AUI_SECONDARY_COLOR; |
|
90 | + } |
|
91 | + } |
|
92 | + return $result; |
|
93 | + } |
|
94 | + |
|
95 | + public function render( $items = array() ) { |
|
96 | + $output = ''; |
|
97 | + |
|
98 | + if ( ! empty( $items ) ) { |
|
99 | + foreach ( $items as $args ) { |
|
100 | + $render = isset( $args['render'] ) ? $args['render'] : ''; |
|
101 | + if ( $render && method_exists( __CLASS__, $render ) ) { |
|
102 | + $output .= $this->$render( $args ); |
|
103 | + } |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + return $output; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Render and return a bootstrap alert component. |
|
112 | + * |
|
113 | + * @since 1.0.0 |
|
114 | + * |
|
115 | + * @param array $args |
|
116 | + * |
|
117 | + * @return string The rendered component. |
|
118 | + */ |
|
119 | + public function alert( $args = array() ) { |
|
120 | + return AUI_Component_Alert::get( $args ); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Render and return a bootstrap input component. |
|
125 | + * |
|
126 | + * @since 1.0.0 |
|
127 | + * |
|
128 | + * @param array $args |
|
129 | + * |
|
130 | + * @return string The rendered component. |
|
131 | + */ |
|
132 | + public function input( $args = array() ) { |
|
133 | + return AUI_Component_Input::input( $args ); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Render and return a bootstrap textarea component. |
|
138 | + * |
|
139 | + * @since 1.0.0 |
|
140 | + * |
|
141 | + * @param array $args |
|
142 | + * |
|
143 | + * @return string The rendered component. |
|
144 | + */ |
|
145 | + public function textarea( $args = array() ) { |
|
146 | + return AUI_Component_Input::textarea( $args ); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Render and return a bootstrap button component. |
|
151 | + * |
|
152 | + * @since 1.0.0 |
|
153 | + * |
|
154 | + * @param array $args |
|
155 | + * |
|
156 | + * @return string The rendered component. |
|
157 | + */ |
|
158 | + public function button( $args = array() ) { |
|
159 | + return AUI_Component_Button::get( $args ); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Render and return a bootstrap button component. |
|
164 | + * |
|
165 | + * @since 1.0.0 |
|
166 | + * |
|
167 | + * @param array $args |
|
168 | + * |
|
169 | + * @return string The rendered component. |
|
170 | + */ |
|
171 | + public function badge( $args = array() ) { |
|
172 | + $defaults = array( |
|
173 | + 'class' => 'badge badge-primary align-middle', |
|
174 | + ); |
|
175 | + |
|
176 | + // maybe set type |
|
177 | + if ( empty( $args['href'] ) ) { |
|
178 | + $defaults['type'] = 'badge'; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Parse incoming $args into an array and merge it with $defaults |
|
183 | + */ |
|
184 | + $args = wp_parse_args( $args, $defaults ); |
|
185 | + |
|
186 | + return AUI_Component_Button::get( $args ); |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Render and return a bootstrap dropdown component. |
|
191 | + * |
|
192 | + * @since 1.0.0 |
|
193 | + * |
|
194 | + * @param array $args |
|
195 | + * |
|
196 | + * @return string The rendered component. |
|
197 | + */ |
|
198 | + public function dropdown( $args = array() ) { |
|
199 | + return AUI_Component_Dropdown::get( $args ); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Render and return a bootstrap select component. |
|
204 | + * |
|
205 | + * @since 1.0.0 |
|
206 | + * |
|
207 | + * @param array $args |
|
208 | + * |
|
209 | + * @return string The rendered component. |
|
210 | + */ |
|
211 | + public function select( $args = array() ) { |
|
212 | + return AUI_Component_Input::select( $args ); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Render and return a bootstrap radio component. |
|
217 | + * |
|
218 | + * @since 1.0.0 |
|
219 | + * |
|
220 | + * @param array $args |
|
221 | + * |
|
222 | + * @return string The rendered component. |
|
223 | + */ |
|
224 | + public function radio( $args = array() ) { |
|
225 | + return AUI_Component_Input::radio( $args ); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Render and return a bootstrap pagination component. |
|
230 | + * |
|
231 | + * @since 1.0.0 |
|
232 | + * |
|
233 | + * @param array $args |
|
234 | + * |
|
235 | + * @return string The rendered component. |
|
236 | + */ |
|
237 | + public function pagination( $args = array() ) { |
|
238 | + return AUI_Component_Pagination::get( $args ); |
|
239 | + } |
|
240 | 240 | |
241 | 241 | } |
242 | 242 | \ No newline at end of file |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -21,236 +21,236 @@ discard block |
||
21 | 21 | */ |
22 | 22 | if ( ! class_exists( 'AyeCode_UI_Settings' ) ) { |
23 | 23 | |
24 | - /** |
|
25 | - * A Class to be able to change settings for Font Awesome. |
|
26 | - * |
|
27 | - * Class AyeCode_UI_Settings |
|
28 | - * @ver 1.0.0 |
|
29 | - * @todo decide how to implement textdomain |
|
30 | - */ |
|
31 | - class AyeCode_UI_Settings { |
|
32 | - |
|
33 | - /** |
|
34 | - * Class version version. |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - public $version = '0.1.46'; |
|
39 | - |
|
40 | - /** |
|
41 | - * Class textdomain. |
|
42 | - * |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - public $textdomain = 'aui'; |
|
46 | - |
|
47 | - /** |
|
48 | - * Latest version of Bootstrap at time of publish published. |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - public $latest = "4.5.3"; |
|
53 | - |
|
54 | - /** |
|
55 | - * Current version of select2 being used. |
|
56 | - * |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - public $select2_version = "4.0.11"; |
|
60 | - |
|
61 | - /** |
|
62 | - * The title. |
|
63 | - * |
|
64 | - * @var string |
|
65 | - */ |
|
66 | - public $name = 'AyeCode UI'; |
|
67 | - |
|
68 | - /** |
|
69 | - * The relative url to the assets. |
|
70 | - * |
|
71 | - * @var string |
|
72 | - */ |
|
73 | - public $url = ''; |
|
74 | - |
|
75 | - /** |
|
76 | - * Holds the settings values. |
|
77 | - * |
|
78 | - * @var array |
|
79 | - */ |
|
80 | - private $settings; |
|
81 | - |
|
82 | - /** |
|
83 | - * AyeCode_UI_Settings instance. |
|
84 | - * |
|
85 | - * @access private |
|
86 | - * @since 1.0.0 |
|
87 | - * @var AyeCode_UI_Settings There can be only one! |
|
88 | - */ |
|
89 | - private static $instance = null; |
|
90 | - |
|
91 | - /** |
|
92 | - * Main AyeCode_UI_Settings Instance. |
|
93 | - * |
|
94 | - * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded. |
|
95 | - * |
|
96 | - * @since 1.0.0 |
|
97 | - * @static |
|
98 | - * @return AyeCode_UI_Settings - Main instance. |
|
99 | - */ |
|
100 | - public static function instance() { |
|
101 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) { |
|
102 | - |
|
103 | - self::$instance = new AyeCode_UI_Settings; |
|
104 | - |
|
105 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
106 | - |
|
107 | - if ( is_admin() ) { |
|
108 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
109 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
110 | - |
|
111 | - // Maybe show example page |
|
112 | - add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) ); |
|
113 | - } |
|
114 | - |
|
115 | - add_action( 'customize_register', array( self::$instance, 'customizer_settings' )); |
|
116 | - |
|
117 | - do_action( 'ayecode_ui_settings_loaded' ); |
|
118 | - } |
|
119 | - |
|
120 | - return self::$instance; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Setup some constants. |
|
125 | - */ |
|
126 | - public function constants(){ |
|
127 | - define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be"); |
|
128 | - define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d'); |
|
129 | - if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL); |
|
130 | - if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Initiate the settings and add the required action hooks. |
|
135 | - */ |
|
136 | - public function init() { |
|
137 | - $this->constants(); |
|
138 | - $this->settings = $this->get_settings(); |
|
139 | - $this->url = $this->get_url(); |
|
140 | - |
|
141 | - /** |
|
142 | - * Maybe load CSS |
|
143 | - * |
|
144 | - * We load super early in case there is a theme version that might change the colors |
|
145 | - */ |
|
146 | - if ( $this->settings['css'] ) { |
|
147 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
148 | - } |
|
149 | - if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) { |
|
150 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
151 | - } |
|
152 | - |
|
153 | - // maybe load JS |
|
154 | - if ( $this->settings['js'] ) { |
|
155 | - $priority = $this->is_bs3_compat() ? 100 : 1; |
|
156 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority ); |
|
157 | - } |
|
158 | - if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
|
159 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
160 | - } |
|
161 | - |
|
162 | - // Maybe set the HTML font size |
|
163 | - if ( $this->settings['html_font_size'] ) { |
|
164 | - add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Check if we should load the admin scripts or not. |
|
172 | - * |
|
173 | - * @return bool |
|
174 | - */ |
|
175 | - public function load_admin_scripts(){ |
|
176 | - $result = true; |
|
177 | - |
|
178 | - // check if specifically disabled |
|
179 | - if(!empty($this->settings['disable_admin'])){ |
|
180 | - $url_parts = explode("\n",$this->settings['disable_admin']); |
|
181 | - foreach($url_parts as $part){ |
|
182 | - if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){ |
|
183 | - return false; // return early, no point checking further |
|
184 | - } |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - return $result; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Add a html font size to the footer. |
|
193 | - */ |
|
194 | - public function html_font_size(){ |
|
195 | - $this->settings = $this->get_settings(); |
|
196 | - echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>"; |
|
197 | - } |
|
24 | + /** |
|
25 | + * A Class to be able to change settings for Font Awesome. |
|
26 | + * |
|
27 | + * Class AyeCode_UI_Settings |
|
28 | + * @ver 1.0.0 |
|
29 | + * @todo decide how to implement textdomain |
|
30 | + */ |
|
31 | + class AyeCode_UI_Settings { |
|
32 | + |
|
33 | + /** |
|
34 | + * Class version version. |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + public $version = '0.1.46'; |
|
39 | + |
|
40 | + /** |
|
41 | + * Class textdomain. |
|
42 | + * |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + public $textdomain = 'aui'; |
|
46 | + |
|
47 | + /** |
|
48 | + * Latest version of Bootstrap at time of publish published. |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + public $latest = "4.5.3"; |
|
53 | + |
|
54 | + /** |
|
55 | + * Current version of select2 being used. |
|
56 | + * |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + public $select2_version = "4.0.11"; |
|
60 | + |
|
61 | + /** |
|
62 | + * The title. |
|
63 | + * |
|
64 | + * @var string |
|
65 | + */ |
|
66 | + public $name = 'AyeCode UI'; |
|
67 | + |
|
68 | + /** |
|
69 | + * The relative url to the assets. |
|
70 | + * |
|
71 | + * @var string |
|
72 | + */ |
|
73 | + public $url = ''; |
|
74 | + |
|
75 | + /** |
|
76 | + * Holds the settings values. |
|
77 | + * |
|
78 | + * @var array |
|
79 | + */ |
|
80 | + private $settings; |
|
81 | + |
|
82 | + /** |
|
83 | + * AyeCode_UI_Settings instance. |
|
84 | + * |
|
85 | + * @access private |
|
86 | + * @since 1.0.0 |
|
87 | + * @var AyeCode_UI_Settings There can be only one! |
|
88 | + */ |
|
89 | + private static $instance = null; |
|
90 | + |
|
91 | + /** |
|
92 | + * Main AyeCode_UI_Settings Instance. |
|
93 | + * |
|
94 | + * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded. |
|
95 | + * |
|
96 | + * @since 1.0.0 |
|
97 | + * @static |
|
98 | + * @return AyeCode_UI_Settings - Main instance. |
|
99 | + */ |
|
100 | + public static function instance() { |
|
101 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) { |
|
102 | + |
|
103 | + self::$instance = new AyeCode_UI_Settings; |
|
104 | + |
|
105 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
106 | + |
|
107 | + if ( is_admin() ) { |
|
108 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
109 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
110 | + |
|
111 | + // Maybe show example page |
|
112 | + add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) ); |
|
113 | + } |
|
198 | 114 | |
199 | - /** |
|
200 | - * Check if the current admin screen should load scripts. |
|
201 | - * |
|
202 | - * @return bool |
|
203 | - */ |
|
204 | - public function is_aui_screen(){ |
|
205 | - $load = false; |
|
206 | - // check if we should load or not |
|
207 | - if ( is_admin() ) { |
|
208 | - // Only enable on set pages |
|
209 | - $aui_screens = array( |
|
210 | - 'page', |
|
211 | - 'post', |
|
212 | - 'settings_page_ayecode-ui-settings', |
|
213 | - 'appearance_page_gutenberg-widgets' |
|
214 | - ); |
|
215 | - $screen_ids = apply_filters( 'aui_screen_ids', $aui_screens ); |
|
216 | - |
|
217 | - $screen = get_current_screen(); |
|
115 | + add_action( 'customize_register', array( self::$instance, 'customizer_settings' )); |
|
116 | + |
|
117 | + do_action( 'ayecode_ui_settings_loaded' ); |
|
118 | + } |
|
119 | + |
|
120 | + return self::$instance; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Setup some constants. |
|
125 | + */ |
|
126 | + public function constants(){ |
|
127 | + define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be"); |
|
128 | + define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d'); |
|
129 | + if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL); |
|
130 | + if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Initiate the settings and add the required action hooks. |
|
135 | + */ |
|
136 | + public function init() { |
|
137 | + $this->constants(); |
|
138 | + $this->settings = $this->get_settings(); |
|
139 | + $this->url = $this->get_url(); |
|
140 | + |
|
141 | + /** |
|
142 | + * Maybe load CSS |
|
143 | + * |
|
144 | + * We load super early in case there is a theme version that might change the colors |
|
145 | + */ |
|
146 | + if ( $this->settings['css'] ) { |
|
147 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
148 | + } |
|
149 | + if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) { |
|
150 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
151 | + } |
|
152 | + |
|
153 | + // maybe load JS |
|
154 | + if ( $this->settings['js'] ) { |
|
155 | + $priority = $this->is_bs3_compat() ? 100 : 1; |
|
156 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority ); |
|
157 | + } |
|
158 | + if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
|
159 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
160 | + } |
|
161 | + |
|
162 | + // Maybe set the HTML font size |
|
163 | + if ( $this->settings['html_font_size'] ) { |
|
164 | + add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Check if we should load the admin scripts or not. |
|
172 | + * |
|
173 | + * @return bool |
|
174 | + */ |
|
175 | + public function load_admin_scripts(){ |
|
176 | + $result = true; |
|
177 | + |
|
178 | + // check if specifically disabled |
|
179 | + if(!empty($this->settings['disable_admin'])){ |
|
180 | + $url_parts = explode("\n",$this->settings['disable_admin']); |
|
181 | + foreach($url_parts as $part){ |
|
182 | + if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){ |
|
183 | + return false; // return early, no point checking further |
|
184 | + } |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + return $result; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Add a html font size to the footer. |
|
193 | + */ |
|
194 | + public function html_font_size(){ |
|
195 | + $this->settings = $this->get_settings(); |
|
196 | + echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>"; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Check if the current admin screen should load scripts. |
|
201 | + * |
|
202 | + * @return bool |
|
203 | + */ |
|
204 | + public function is_aui_screen(){ |
|
205 | + $load = false; |
|
206 | + // check if we should load or not |
|
207 | + if ( is_admin() ) { |
|
208 | + // Only enable on set pages |
|
209 | + $aui_screens = array( |
|
210 | + 'page', |
|
211 | + 'post', |
|
212 | + 'settings_page_ayecode-ui-settings', |
|
213 | + 'appearance_page_gutenberg-widgets' |
|
214 | + ); |
|
215 | + $screen_ids = apply_filters( 'aui_screen_ids', $aui_screens ); |
|
216 | + |
|
217 | + $screen = get_current_screen(); |
|
218 | 218 | |
219 | 219 | // echo '###'.$screen->id; |
220 | 220 | |
221 | - if ( $screen && in_array( $screen->id, $screen_ids ) ) { |
|
222 | - $load = true; |
|
223 | - } |
|
224 | - } |
|
221 | + if ( $screen && in_array( $screen->id, $screen_ids ) ) { |
|
222 | + $load = true; |
|
223 | + } |
|
224 | + } |
|
225 | 225 | |
226 | - return $load; |
|
227 | - } |
|
226 | + return $load; |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * Adds the styles. |
|
231 | - */ |
|
232 | - public function enqueue_style() { |
|
229 | + /** |
|
230 | + * Adds the styles. |
|
231 | + */ |
|
232 | + public function enqueue_style() { |
|
233 | 233 | |
234 | - if( is_admin() && !$this->is_aui_screen()){ |
|
235 | - // don't add wp-admin scripts if not requested to |
|
236 | - }else{ |
|
237 | - $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
|
234 | + if( is_admin() && !$this->is_aui_screen()){ |
|
235 | + // don't add wp-admin scripts if not requested to |
|
236 | + }else{ |
|
237 | + $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
|
238 | 238 | |
239 | - $rtl = is_rtl() ? '-rtl' : ''; |
|
239 | + $rtl = is_rtl() ? '-rtl' : ''; |
|
240 | 240 | |
241 | - if($this->settings[$css_setting]){ |
|
242 | - $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
|
243 | - $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css'; |
|
244 | - wp_register_style( 'ayecode-ui', $url, array(), $this->latest ); |
|
245 | - wp_enqueue_style( 'ayecode-ui' ); |
|
241 | + if($this->settings[$css_setting]){ |
|
242 | + $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
|
243 | + $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css'; |
|
244 | + wp_register_style( 'ayecode-ui', $url, array(), $this->latest ); |
|
245 | + wp_enqueue_style( 'ayecode-ui' ); |
|
246 | 246 | |
247 | - // flatpickr |
|
248 | - wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest ); |
|
247 | + // flatpickr |
|
248 | + wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest ); |
|
249 | 249 | |
250 | 250 | |
251 | - // fix some wp-admin issues |
|
252 | - if(is_admin()){ |
|
253 | - $custom_css = " |
|
251 | + // fix some wp-admin issues |
|
252 | + if(is_admin()){ |
|
253 | + $custom_css = " |
|
254 | 254 | body{ |
255 | 255 | background-color: #f1f1f1; |
256 | 256 | font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif; |
@@ -289,35 +289,35 @@ discard block |
||
289 | 289 | } |
290 | 290 | "; |
291 | 291 | |
292 | - // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
|
293 | - $custom_css .= " |
|
292 | + // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
|
293 | + $custom_css .= " |
|
294 | 294 | .edit-post-sidebar input[type=color].components-text-control__input{ |
295 | 295 | padding: 0; |
296 | 296 | } |
297 | 297 | "; |
298 | - wp_add_inline_style( 'ayecode-ui', $custom_css ); |
|
299 | - } |
|
298 | + wp_add_inline_style( 'ayecode-ui', $custom_css ); |
|
299 | + } |
|
300 | 300 | |
301 | - // custom changes |
|
302 | - wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
|
301 | + // custom changes |
|
302 | + wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
|
303 | 303 | |
304 | - } |
|
305 | - } |
|
304 | + } |
|
305 | + } |
|
306 | 306 | |
307 | 307 | |
308 | - } |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Get inline script used if bootstrap enqueued |
|
312 | + * |
|
313 | + * If this remains small then its best to use this than to add another JS file. |
|
314 | + */ |
|
315 | + public function inline_script() { |
|
316 | + // Flatpickr calendar locale |
|
317 | + $flatpickr_locale = self::flatpickr_locale(); |
|
309 | 318 | |
310 | - /** |
|
311 | - * Get inline script used if bootstrap enqueued |
|
312 | - * |
|
313 | - * If this remains small then its best to use this than to add another JS file. |
|
314 | - */ |
|
315 | - public function inline_script() { |
|
316 | - // Flatpickr calendar locale |
|
317 | - $flatpickr_locale = self::flatpickr_locale(); |
|
318 | - |
|
319 | - ob_start(); |
|
320 | - ?> |
|
319 | + ob_start(); |
|
320 | + ?> |
|
321 | 321 | <script> |
322 | 322 | /** |
323 | 323 | * An AUI bootstrap adaptation of GreedyNav.js ( by Luke Jackson ). |
@@ -981,27 +981,27 @@ discard block |
||
981 | 981 | |
982 | 982 | </script> |
983 | 983 | <?php |
984 | - $output = ob_get_clean(); |
|
984 | + $output = ob_get_clean(); |
|
985 | 985 | |
986 | - /* |
|
986 | + /* |
|
987 | 987 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
988 | 988 | */ |
989 | - return str_replace( array( |
|
990 | - '<script>', |
|
991 | - '</script>' |
|
992 | - ), '', $output ); |
|
993 | - } |
|
994 | - |
|
995 | - |
|
996 | - /** |
|
997 | - * JS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
998 | - * |
|
999 | - * @TODO we may need this when other conflicts arrise. |
|
1000 | - * @return mixed |
|
1001 | - */ |
|
1002 | - public static function bs3_compat_js() { |
|
1003 | - ob_start(); |
|
1004 | - ?> |
|
989 | + return str_replace( array( |
|
990 | + '<script>', |
|
991 | + '</script>' |
|
992 | + ), '', $output ); |
|
993 | + } |
|
994 | + |
|
995 | + |
|
996 | + /** |
|
997 | + * JS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
998 | + * |
|
999 | + * @TODO we may need this when other conflicts arrise. |
|
1000 | + * @return mixed |
|
1001 | + */ |
|
1002 | + public static function bs3_compat_js() { |
|
1003 | + ob_start(); |
|
1004 | + ?> |
|
1005 | 1005 | <script> |
1006 | 1006 | <?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?> |
1007 | 1007 | /* With Avada builder */ |
@@ -1009,20 +1009,20 @@ discard block |
||
1009 | 1009 | <?php } ?> |
1010 | 1010 | </script> |
1011 | 1011 | <?php |
1012 | - return str_replace( array( |
|
1013 | - '<script>', |
|
1014 | - '</script>' |
|
1015 | - ), '', ob_get_clean()); |
|
1016 | - } |
|
1017 | - |
|
1018 | - /** |
|
1019 | - * Get inline script used if bootstrap file browser enqueued. |
|
1020 | - * |
|
1021 | - * If this remains small then its best to use this than to add another JS file. |
|
1022 | - */ |
|
1023 | - public function inline_script_file_browser(){ |
|
1024 | - ob_start(); |
|
1025 | - ?> |
|
1012 | + return str_replace( array( |
|
1013 | + '<script>', |
|
1014 | + '</script>' |
|
1015 | + ), '', ob_get_clean()); |
|
1016 | + } |
|
1017 | + |
|
1018 | + /** |
|
1019 | + * Get inline script used if bootstrap file browser enqueued. |
|
1020 | + * |
|
1021 | + * If this remains small then its best to use this than to add another JS file. |
|
1022 | + */ |
|
1023 | + public function inline_script_file_browser(){ |
|
1024 | + ob_start(); |
|
1025 | + ?> |
|
1026 | 1026 | <script> |
1027 | 1027 | // run on doc ready |
1028 | 1028 | jQuery(document).ready(function () { |
@@ -1030,192 +1030,192 @@ discard block |
||
1030 | 1030 | }); |
1031 | 1031 | </script> |
1032 | 1032 | <?php |
1033 | - $output = ob_get_clean(); |
|
1033 | + $output = ob_get_clean(); |
|
1034 | 1034 | |
1035 | - /* |
|
1035 | + /* |
|
1036 | 1036 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1037 | 1037 | */ |
1038 | - return str_replace( array( |
|
1039 | - '<script>', |
|
1040 | - '</script>' |
|
1041 | - ), '', $output ); |
|
1042 | - } |
|
1043 | - |
|
1044 | - /** |
|
1045 | - * Adds the Font Awesome JS. |
|
1046 | - */ |
|
1047 | - public function enqueue_scripts() { |
|
1048 | - |
|
1049 | - if( is_admin() && !$this->is_aui_screen()){ |
|
1050 | - // don't add wp-admin scripts if not requested to |
|
1051 | - }else { |
|
1052 | - |
|
1053 | - $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
|
1054 | - |
|
1055 | - // select2 |
|
1056 | - wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version ); |
|
1057 | - |
|
1058 | - // flatpickr |
|
1059 | - wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest ); |
|
1060 | - |
|
1061 | - // Bootstrap file browser |
|
1062 | - wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version ); |
|
1063 | - wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
|
1064 | - |
|
1065 | - $load_inline = false; |
|
1066 | - |
|
1067 | - if ( $this->settings[ $js_setting ] == 'core-popper' ) { |
|
1068 | - // Bootstrap bundle |
|
1069 | - $url = $this->url . 'assets/js/bootstrap.bundle.min.js'; |
|
1070 | - wp_register_script( 'bootstrap-js-bundle', $url, array( |
|
1071 | - 'select2', |
|
1072 | - 'jquery' |
|
1073 | - ), $this->latest, $this->is_bs3_compat() ); |
|
1074 | - // if in admin then add to footer for compatibility. |
|
1075 | - is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' ); |
|
1076 | - $script = $this->inline_script(); |
|
1077 | - wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
|
1078 | - } elseif ( $this->settings[ $js_setting ] == 'popper' ) { |
|
1079 | - $url = $this->url . 'assets/js/popper.min.js'; |
|
1080 | - wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->latest ); |
|
1081 | - wp_enqueue_script( 'bootstrap-js-popper' ); |
|
1082 | - $load_inline = true; |
|
1083 | - } else { |
|
1084 | - $load_inline = true; |
|
1085 | - } |
|
1086 | - |
|
1087 | - // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
|
1088 | - if ( $load_inline ) { |
|
1089 | - wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) ); |
|
1090 | - wp_enqueue_script( 'bootstrap-dummy' ); |
|
1091 | - $script = $this->inline_script(); |
|
1092 | - wp_add_inline_script( 'bootstrap-dummy', $script ); |
|
1093 | - } |
|
1094 | - } |
|
1095 | - |
|
1096 | - } |
|
1097 | - |
|
1098 | - /** |
|
1099 | - * Enqueue flatpickr if called. |
|
1100 | - */ |
|
1101 | - public function enqueue_flatpickr(){ |
|
1102 | - wp_enqueue_style( 'flatpickr' ); |
|
1103 | - wp_enqueue_script( 'flatpickr' ); |
|
1104 | - } |
|
1105 | - |
|
1106 | - /** |
|
1107 | - * Get the url path to the current folder. |
|
1108 | - * |
|
1109 | - * @return string |
|
1110 | - */ |
|
1111 | - public function get_url() { |
|
1112 | - |
|
1113 | - $url = ''; |
|
1114 | - // check if we are inside a plugin |
|
1115 | - $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
1116 | - |
|
1117 | - // add check in-case user has changed wp-content dir name. |
|
1118 | - $wp_content_folder_name = basename(WP_CONTENT_DIR); |
|
1119 | - $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
|
1120 | - $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
|
1121 | - |
|
1122 | - if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
1123 | - $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
|
1124 | - } |
|
1125 | - |
|
1126 | - return $url; |
|
1127 | - } |
|
1128 | - |
|
1129 | - /** |
|
1130 | - * Register the database settings with WordPress. |
|
1131 | - */ |
|
1132 | - public function register_settings() { |
|
1133 | - register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
|
1134 | - } |
|
1135 | - |
|
1136 | - /** |
|
1137 | - * Add the WordPress settings menu item. |
|
1138 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
1139 | - */ |
|
1140 | - public function menu_item() { |
|
1141 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
1142 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
|
1143 | - $this, |
|
1144 | - 'settings_page' |
|
1145 | - ) ); |
|
1146 | - } |
|
1147 | - |
|
1148 | - /** |
|
1149 | - * Get a list of themes and their default JS settings. |
|
1150 | - * |
|
1151 | - * @return array |
|
1152 | - */ |
|
1153 | - public function theme_js_settings(){ |
|
1154 | - return array( |
|
1155 | - 'ayetheme' => 'popper', |
|
1156 | - 'listimia' => 'required', |
|
1157 | - 'listimia_backend' => 'core-popper', |
|
1158 | - //'avada' => 'required', // removed as we now add compatibility |
|
1159 | - ); |
|
1160 | - } |
|
1161 | - |
|
1162 | - /** |
|
1163 | - * Get the current Font Awesome output settings. |
|
1164 | - * |
|
1165 | - * @return array The array of settings. |
|
1166 | - */ |
|
1167 | - public function get_settings() { |
|
1168 | - |
|
1169 | - $db_settings = get_option( 'ayecode-ui-settings' ); |
|
1170 | - $js_default = 'core-popper'; |
|
1171 | - $js_default_backend = $js_default; |
|
1172 | - |
|
1173 | - // maybe set defaults (if no settings set) |
|
1174 | - if(empty($db_settings)){ |
|
1175 | - $active_theme = strtolower( get_template() ); // active parent theme. |
|
1176 | - $theme_js_settings = self::theme_js_settings(); |
|
1177 | - if(isset($theme_js_settings[$active_theme])){ |
|
1178 | - $js_default = $theme_js_settings[$active_theme]; |
|
1179 | - $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
|
1180 | - } |
|
1181 | - } |
|
1182 | - |
|
1183 | - $defaults = array( |
|
1184 | - 'css' => 'compatibility', // core, compatibility |
|
1185 | - 'js' => $js_default, // js to load, core-popper, popper |
|
1186 | - 'html_font_size' => '16', // js to load, core-popper, popper |
|
1187 | - 'css_backend' => 'compatibility', // core, compatibility |
|
1188 | - 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
|
1189 | - 'disable_admin' => '', // URL snippets to disable loading on admin |
|
1190 | - ); |
|
1191 | - |
|
1192 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
1193 | - |
|
1194 | - /** |
|
1195 | - * Filter the Bootstrap settings. |
|
1196 | - * |
|
1197 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
1198 | - */ |
|
1199 | - return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
|
1200 | - } |
|
1201 | - |
|
1038 | + return str_replace( array( |
|
1039 | + '<script>', |
|
1040 | + '</script>' |
|
1041 | + ), '', $output ); |
|
1042 | + } |
|
1043 | + |
|
1044 | + /** |
|
1045 | + * Adds the Font Awesome JS. |
|
1046 | + */ |
|
1047 | + public function enqueue_scripts() { |
|
1048 | + |
|
1049 | + if( is_admin() && !$this->is_aui_screen()){ |
|
1050 | + // don't add wp-admin scripts if not requested to |
|
1051 | + }else { |
|
1052 | + |
|
1053 | + $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
|
1054 | + |
|
1055 | + // select2 |
|
1056 | + wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version ); |
|
1057 | + |
|
1058 | + // flatpickr |
|
1059 | + wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest ); |
|
1060 | + |
|
1061 | + // Bootstrap file browser |
|
1062 | + wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version ); |
|
1063 | + wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
|
1064 | + |
|
1065 | + $load_inline = false; |
|
1066 | + |
|
1067 | + if ( $this->settings[ $js_setting ] == 'core-popper' ) { |
|
1068 | + // Bootstrap bundle |
|
1069 | + $url = $this->url . 'assets/js/bootstrap.bundle.min.js'; |
|
1070 | + wp_register_script( 'bootstrap-js-bundle', $url, array( |
|
1071 | + 'select2', |
|
1072 | + 'jquery' |
|
1073 | + ), $this->latest, $this->is_bs3_compat() ); |
|
1074 | + // if in admin then add to footer for compatibility. |
|
1075 | + is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' ); |
|
1076 | + $script = $this->inline_script(); |
|
1077 | + wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
|
1078 | + } elseif ( $this->settings[ $js_setting ] == 'popper' ) { |
|
1079 | + $url = $this->url . 'assets/js/popper.min.js'; |
|
1080 | + wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->latest ); |
|
1081 | + wp_enqueue_script( 'bootstrap-js-popper' ); |
|
1082 | + $load_inline = true; |
|
1083 | + } else { |
|
1084 | + $load_inline = true; |
|
1085 | + } |
|
1202 | 1086 | |
1203 | - /** |
|
1204 | - * The settings page html output. |
|
1205 | - */ |
|
1206 | - public function settings_page() { |
|
1207 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
1208 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
|
1209 | - } |
|
1210 | - ?> |
|
1087 | + // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
|
1088 | + if ( $load_inline ) { |
|
1089 | + wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) ); |
|
1090 | + wp_enqueue_script( 'bootstrap-dummy' ); |
|
1091 | + $script = $this->inline_script(); |
|
1092 | + wp_add_inline_script( 'bootstrap-dummy', $script ); |
|
1093 | + } |
|
1094 | + } |
|
1095 | + |
|
1096 | + } |
|
1097 | + |
|
1098 | + /** |
|
1099 | + * Enqueue flatpickr if called. |
|
1100 | + */ |
|
1101 | + public function enqueue_flatpickr(){ |
|
1102 | + wp_enqueue_style( 'flatpickr' ); |
|
1103 | + wp_enqueue_script( 'flatpickr' ); |
|
1104 | + } |
|
1105 | + |
|
1106 | + /** |
|
1107 | + * Get the url path to the current folder. |
|
1108 | + * |
|
1109 | + * @return string |
|
1110 | + */ |
|
1111 | + public function get_url() { |
|
1112 | + |
|
1113 | + $url = ''; |
|
1114 | + // check if we are inside a plugin |
|
1115 | + $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
1116 | + |
|
1117 | + // add check in-case user has changed wp-content dir name. |
|
1118 | + $wp_content_folder_name = basename(WP_CONTENT_DIR); |
|
1119 | + $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
|
1120 | + $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
|
1121 | + |
|
1122 | + if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
1123 | + $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
|
1124 | + } |
|
1125 | + |
|
1126 | + return $url; |
|
1127 | + } |
|
1128 | + |
|
1129 | + /** |
|
1130 | + * Register the database settings with WordPress. |
|
1131 | + */ |
|
1132 | + public function register_settings() { |
|
1133 | + register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
|
1134 | + } |
|
1135 | + |
|
1136 | + /** |
|
1137 | + * Add the WordPress settings menu item. |
|
1138 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
1139 | + */ |
|
1140 | + public function menu_item() { |
|
1141 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
1142 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
|
1143 | + $this, |
|
1144 | + 'settings_page' |
|
1145 | + ) ); |
|
1146 | + } |
|
1147 | + |
|
1148 | + /** |
|
1149 | + * Get a list of themes and their default JS settings. |
|
1150 | + * |
|
1151 | + * @return array |
|
1152 | + */ |
|
1153 | + public function theme_js_settings(){ |
|
1154 | + return array( |
|
1155 | + 'ayetheme' => 'popper', |
|
1156 | + 'listimia' => 'required', |
|
1157 | + 'listimia_backend' => 'core-popper', |
|
1158 | + //'avada' => 'required', // removed as we now add compatibility |
|
1159 | + ); |
|
1160 | + } |
|
1161 | + |
|
1162 | + /** |
|
1163 | + * Get the current Font Awesome output settings. |
|
1164 | + * |
|
1165 | + * @return array The array of settings. |
|
1166 | + */ |
|
1167 | + public function get_settings() { |
|
1168 | + |
|
1169 | + $db_settings = get_option( 'ayecode-ui-settings' ); |
|
1170 | + $js_default = 'core-popper'; |
|
1171 | + $js_default_backend = $js_default; |
|
1172 | + |
|
1173 | + // maybe set defaults (if no settings set) |
|
1174 | + if(empty($db_settings)){ |
|
1175 | + $active_theme = strtolower( get_template() ); // active parent theme. |
|
1176 | + $theme_js_settings = self::theme_js_settings(); |
|
1177 | + if(isset($theme_js_settings[$active_theme])){ |
|
1178 | + $js_default = $theme_js_settings[$active_theme]; |
|
1179 | + $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
|
1180 | + } |
|
1181 | + } |
|
1182 | + |
|
1183 | + $defaults = array( |
|
1184 | + 'css' => 'compatibility', // core, compatibility |
|
1185 | + 'js' => $js_default, // js to load, core-popper, popper |
|
1186 | + 'html_font_size' => '16', // js to load, core-popper, popper |
|
1187 | + 'css_backend' => 'compatibility', // core, compatibility |
|
1188 | + 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
|
1189 | + 'disable_admin' => '', // URL snippets to disable loading on admin |
|
1190 | + ); |
|
1191 | + |
|
1192 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
1193 | + |
|
1194 | + /** |
|
1195 | + * Filter the Bootstrap settings. |
|
1196 | + * |
|
1197 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
1198 | + */ |
|
1199 | + return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
|
1200 | + } |
|
1201 | + |
|
1202 | + |
|
1203 | + /** |
|
1204 | + * The settings page html output. |
|
1205 | + */ |
|
1206 | + public function settings_page() { |
|
1207 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
1208 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
|
1209 | + } |
|
1210 | + ?> |
|
1211 | 1211 | <div class="wrap"> |
1212 | 1212 | <h1><?php echo $this->name; ?></h1> |
1213 | 1213 | <p><?php _e("Here you can adjust settings if you are having compatibility issues.",'aui');?></p> |
1214 | 1214 | <form method="post" action="options.php"> |
1215 | 1215 | <?php |
1216 | - settings_fields( 'ayecode-ui-settings' ); |
|
1217 | - do_settings_sections( 'ayecode-ui-settings' ); |
|
1218 | - ?> |
|
1216 | + settings_fields( 'ayecode-ui-settings' ); |
|
1217 | + do_settings_sections( 'ayecode-ui-settings' ); |
|
1218 | + ?> |
|
1219 | 1219 | |
1220 | 1220 | <h2><?php _e( 'Frontend', 'aui' ); ?></h2> |
1221 | 1221 | <table class="form-table wpbs-table-settings"> |
@@ -1295,60 +1295,60 @@ discard block |
||
1295 | 1295 | </table> |
1296 | 1296 | |
1297 | 1297 | <?php |
1298 | - submit_button(); |
|
1299 | - ?> |
|
1298 | + submit_button(); |
|
1299 | + ?> |
|
1300 | 1300 | </form> |
1301 | 1301 | |
1302 | 1302 | <div id="wpbs-version"><?php echo $this->version; ?></div> |
1303 | 1303 | </div> |
1304 | 1304 | |
1305 | 1305 | <?php |
1306 | - } |
|
1307 | - |
|
1308 | - public function customizer_settings($wp_customize){ |
|
1309 | - $wp_customize->add_section('aui_settings', array( |
|
1310 | - 'title' => __('AyeCode UI','aui'), |
|
1311 | - 'priority' => 120, |
|
1312 | - )); |
|
1313 | - |
|
1314 | - // ============================= |
|
1315 | - // = Color Picker = |
|
1316 | - // ============================= |
|
1317 | - $wp_customize->add_setting('aui_options[color_primary]', array( |
|
1318 | - 'default' => AUI_PRIMARY_COLOR, |
|
1319 | - 'sanitize_callback' => 'sanitize_hex_color', |
|
1320 | - 'capability' => 'edit_theme_options', |
|
1321 | - 'type' => 'option', |
|
1322 | - 'transport' => 'refresh', |
|
1323 | - )); |
|
1324 | - $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
|
1325 | - 'label' => __('Primary Color','aui'), |
|
1326 | - 'section' => 'aui_settings', |
|
1327 | - 'settings' => 'aui_options[color_primary]', |
|
1328 | - ))); |
|
1329 | - |
|
1330 | - $wp_customize->add_setting('aui_options[color_secondary]', array( |
|
1331 | - 'default' => '#6c757d', |
|
1332 | - 'sanitize_callback' => 'sanitize_hex_color', |
|
1333 | - 'capability' => 'edit_theme_options', |
|
1334 | - 'type' => 'option', |
|
1335 | - 'transport' => 'refresh', |
|
1336 | - )); |
|
1337 | - $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
|
1338 | - 'label' => __('Secondary Color','aui'), |
|
1339 | - 'section' => 'aui_settings', |
|
1340 | - 'settings' => 'aui_options[color_secondary]', |
|
1341 | - ))); |
|
1342 | - } |
|
1343 | - |
|
1344 | - /** |
|
1345 | - * CSS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
1346 | - * |
|
1347 | - * @return mixed |
|
1348 | - */ |
|
1349 | - public static function bs3_compat_css() { |
|
1350 | - ob_start(); |
|
1351 | - ?> |
|
1306 | + } |
|
1307 | + |
|
1308 | + public function customizer_settings($wp_customize){ |
|
1309 | + $wp_customize->add_section('aui_settings', array( |
|
1310 | + 'title' => __('AyeCode UI','aui'), |
|
1311 | + 'priority' => 120, |
|
1312 | + )); |
|
1313 | + |
|
1314 | + // ============================= |
|
1315 | + // = Color Picker = |
|
1316 | + // ============================= |
|
1317 | + $wp_customize->add_setting('aui_options[color_primary]', array( |
|
1318 | + 'default' => AUI_PRIMARY_COLOR, |
|
1319 | + 'sanitize_callback' => 'sanitize_hex_color', |
|
1320 | + 'capability' => 'edit_theme_options', |
|
1321 | + 'type' => 'option', |
|
1322 | + 'transport' => 'refresh', |
|
1323 | + )); |
|
1324 | + $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
|
1325 | + 'label' => __('Primary Color','aui'), |
|
1326 | + 'section' => 'aui_settings', |
|
1327 | + 'settings' => 'aui_options[color_primary]', |
|
1328 | + ))); |
|
1329 | + |
|
1330 | + $wp_customize->add_setting('aui_options[color_secondary]', array( |
|
1331 | + 'default' => '#6c757d', |
|
1332 | + 'sanitize_callback' => 'sanitize_hex_color', |
|
1333 | + 'capability' => 'edit_theme_options', |
|
1334 | + 'type' => 'option', |
|
1335 | + 'transport' => 'refresh', |
|
1336 | + )); |
|
1337 | + $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
|
1338 | + 'label' => __('Secondary Color','aui'), |
|
1339 | + 'section' => 'aui_settings', |
|
1340 | + 'settings' => 'aui_options[color_secondary]', |
|
1341 | + ))); |
|
1342 | + } |
|
1343 | + |
|
1344 | + /** |
|
1345 | + * CSS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
1346 | + * |
|
1347 | + * @return mixed |
|
1348 | + */ |
|
1349 | + public static function bs3_compat_css() { |
|
1350 | + ob_start(); |
|
1351 | + ?> |
|
1352 | 1352 | <style> |
1353 | 1353 | /* Bootstrap 3 compatibility */ |
1354 | 1354 | body.modal-open .modal-backdrop.show:not(.in) {opacity:0.5;} |
@@ -1374,579 +1374,579 @@ discard block |
||
1374 | 1374 | <?php } ?> |
1375 | 1375 | </style> |
1376 | 1376 | <?php |
1377 | - return str_replace( array( |
|
1378 | - '<style>', |
|
1379 | - '</style>' |
|
1380 | - ), '', ob_get_clean()); |
|
1381 | - } |
|
1377 | + return str_replace( array( |
|
1378 | + '<style>', |
|
1379 | + '</style>' |
|
1380 | + ), '', ob_get_clean()); |
|
1381 | + } |
|
1382 | 1382 | |
1383 | 1383 | |
1384 | - public static function custom_css($compatibility = true) { |
|
1385 | - $settings = get_option('aui_options'); |
|
1384 | + public static function custom_css($compatibility = true) { |
|
1385 | + $settings = get_option('aui_options'); |
|
1386 | 1386 | |
1387 | - ob_start(); |
|
1387 | + ob_start(); |
|
1388 | 1388 | |
1389 | - $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR; |
|
1390 | - $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR; |
|
1391 | - //AUI_PRIMARY_COLOR_ORIGINAL |
|
1392 | - ?> |
|
1389 | + $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR; |
|
1390 | + $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR; |
|
1391 | + //AUI_PRIMARY_COLOR_ORIGINAL |
|
1392 | + ?> |
|
1393 | 1393 | <style> |
1394 | 1394 | <?php |
1395 | 1395 | |
1396 | - // BS v3 compat |
|
1397 | - if( self::is_bs3_compat() ){ |
|
1398 | - echo self::bs3_compat_css(); |
|
1399 | - } |
|
1396 | + // BS v3 compat |
|
1397 | + if( self::is_bs3_compat() ){ |
|
1398 | + echo self::bs3_compat_css(); |
|
1399 | + } |
|
1400 | 1400 | |
1401 | - if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){ |
|
1402 | - echo self::css_primary($primary_color,$compatibility); |
|
1403 | - } |
|
1401 | + if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){ |
|
1402 | + echo self::css_primary($primary_color,$compatibility); |
|
1403 | + } |
|
1404 | 1404 | |
1405 | - if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){ |
|
1406 | - echo self::css_secondary($settings['color_secondary'],$compatibility); |
|
1407 | - } |
|
1405 | + if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){ |
|
1406 | + echo self::css_secondary($settings['color_secondary'],$compatibility); |
|
1407 | + } |
|
1408 | 1408 | |
1409 | - // Set admin bar z-index lower when modal is open. |
|
1410 | - echo ' body.modal-open #wpadminbar{z-index:999}'; |
|
1409 | + // Set admin bar z-index lower when modal is open. |
|
1410 | + echo ' body.modal-open #wpadminbar{z-index:999}'; |
|
1411 | 1411 | ?> |
1412 | 1412 | </style> |
1413 | 1413 | <?php |
1414 | 1414 | |
1415 | 1415 | |
1416 | - /* |
|
1416 | + /* |
|
1417 | 1417 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1418 | 1418 | */ |
1419 | - return str_replace( array( |
|
1420 | - '<style>', |
|
1421 | - '</style>' |
|
1422 | - ), '', ob_get_clean()); |
|
1423 | - } |
|
1424 | - |
|
1425 | - /** |
|
1426 | - * Check if we should add booststrap 3 compatibility changes. |
|
1427 | - * |
|
1428 | - * @return bool |
|
1429 | - */ |
|
1430 | - public static function is_bs3_compat(){ |
|
1431 | - return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION'); |
|
1432 | - } |
|
1433 | - |
|
1434 | - public static function css_primary($color_code,$compatibility){; |
|
1435 | - $color_code = sanitize_hex_color($color_code); |
|
1436 | - if(!$color_code){return '';} |
|
1437 | - /** |
|
1438 | - * c = color, b = background color, o = border-color, f = fill |
|
1439 | - */ |
|
1440 | - $selectors = array( |
|
1441 | - 'a' => array('c'), |
|
1442 | - '.btn-primary' => array('b','o'), |
|
1443 | - '.btn-primary.disabled' => array('b','o'), |
|
1444 | - '.btn-primary:disabled' => array('b','o'), |
|
1445 | - '.btn-outline-primary' => array('c','o'), |
|
1446 | - '.btn-outline-primary:hover' => array('b','o'), |
|
1447 | - '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1448 | - '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1449 | - '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
|
1450 | - '.btn-link' => array('c'), |
|
1451 | - '.dropdown-item.active' => array('b'), |
|
1452 | - '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
|
1453 | - '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
|
1419 | + return str_replace( array( |
|
1420 | + '<style>', |
|
1421 | + '</style>' |
|
1422 | + ), '', ob_get_clean()); |
|
1423 | + } |
|
1424 | + |
|
1425 | + /** |
|
1426 | + * Check if we should add booststrap 3 compatibility changes. |
|
1427 | + * |
|
1428 | + * @return bool |
|
1429 | + */ |
|
1430 | + public static function is_bs3_compat(){ |
|
1431 | + return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION'); |
|
1432 | + } |
|
1433 | + |
|
1434 | + public static function css_primary($color_code,$compatibility){; |
|
1435 | + $color_code = sanitize_hex_color($color_code); |
|
1436 | + if(!$color_code){return '';} |
|
1437 | + /** |
|
1438 | + * c = color, b = background color, o = border-color, f = fill |
|
1439 | + */ |
|
1440 | + $selectors = array( |
|
1441 | + 'a' => array('c'), |
|
1442 | + '.btn-primary' => array('b','o'), |
|
1443 | + '.btn-primary.disabled' => array('b','o'), |
|
1444 | + '.btn-primary:disabled' => array('b','o'), |
|
1445 | + '.btn-outline-primary' => array('c','o'), |
|
1446 | + '.btn-outline-primary:hover' => array('b','o'), |
|
1447 | + '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1448 | + '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1449 | + '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
|
1450 | + '.btn-link' => array('c'), |
|
1451 | + '.dropdown-item.active' => array('b'), |
|
1452 | + '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
|
1453 | + '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
|
1454 | 1454 | // '.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules... |
1455 | 1455 | // '.custom-range::-moz-range-thumb' => array('b'), |
1456 | 1456 | // '.custom-range::-ms-thumb' => array('b'), |
1457 | - '.nav-pills .nav-link.active' => array('b'), |
|
1458 | - '.nav-pills .show>.nav-link' => array('b'), |
|
1459 | - '.page-link' => array('c'), |
|
1460 | - '.page-item.active .page-link' => array('b','o'), |
|
1461 | - '.badge-primary' => array('b'), |
|
1462 | - '.alert-primary' => array('b','o'), |
|
1463 | - '.progress-bar' => array('b'), |
|
1464 | - '.list-group-item.active' => array('b','o'), |
|
1465 | - '.bg-primary' => array('b','f'), |
|
1466 | - '.btn-link.btn-primary' => array('c'), |
|
1467 | - '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
|
1468 | - ); |
|
1469 | - |
|
1470 | - $important_selectors = array( |
|
1471 | - '.bg-primary' => array('b','f'), |
|
1472 | - '.border-primary' => array('o'), |
|
1473 | - '.text-primary' => array('c'), |
|
1474 | - ); |
|
1475 | - |
|
1476 | - $color = array(); |
|
1477 | - $color_i = array(); |
|
1478 | - $background = array(); |
|
1479 | - $background_i = array(); |
|
1480 | - $border = array(); |
|
1481 | - $border_i = array(); |
|
1482 | - $fill = array(); |
|
1483 | - $fill_i = array(); |
|
1484 | - |
|
1485 | - $output = ''; |
|
1486 | - |
|
1487 | - // build rules into each type |
|
1488 | - foreach($selectors as $selector => $types){ |
|
1489 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1490 | - $types = array_combine($types,$types); |
|
1491 | - if(isset($types['c'])){$color[] = $selector;} |
|
1492 | - if(isset($types['b'])){$background[] = $selector;} |
|
1493 | - if(isset($types['o'])){$border[] = $selector;} |
|
1494 | - if(isset($types['f'])){$fill[] = $selector;} |
|
1495 | - } |
|
1496 | - |
|
1497 | - // build rules into each type |
|
1498 | - foreach($important_selectors as $selector => $types){ |
|
1499 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1500 | - $types = array_combine($types,$types); |
|
1501 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
1502 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
1503 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
1504 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
1505 | - } |
|
1506 | - |
|
1507 | - // add any color rules |
|
1508 | - if(!empty($color)){ |
|
1509 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1510 | - } |
|
1511 | - if(!empty($color_i)){ |
|
1512 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1513 | - } |
|
1514 | - |
|
1515 | - // add any background color rules |
|
1516 | - if(!empty($background)){ |
|
1517 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1518 | - } |
|
1519 | - if(!empty($background_i)){ |
|
1520 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1521 | - } |
|
1522 | - |
|
1523 | - // add any border color rules |
|
1524 | - if(!empty($border)){ |
|
1525 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1526 | - } |
|
1527 | - if(!empty($border_i)){ |
|
1528 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1529 | - } |
|
1530 | - |
|
1531 | - // add any fill color rules |
|
1532 | - if(!empty($fill)){ |
|
1533 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1534 | - } |
|
1535 | - if(!empty($fill_i)){ |
|
1536 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1537 | - } |
|
1538 | - |
|
1539 | - |
|
1540 | - $prefix = $compatibility ? ".bsui " : ""; |
|
1541 | - |
|
1542 | - // darken |
|
1543 | - $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1544 | - $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1545 | - $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1546 | - |
|
1547 | - // lighten |
|
1548 | - $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1549 | - |
|
1550 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1551 | - $op_25 = $color_code."40"; // 25% opacity |
|
1552 | - |
|
1553 | - |
|
1554 | - // button states |
|
1555 | - $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1556 | - $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1557 | - $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1558 | - $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1559 | - |
|
1560 | - |
|
1561 | - // dropdown's |
|
1562 | - $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
1563 | - |
|
1564 | - |
|
1565 | - // input states |
|
1566 | - $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1567 | - |
|
1568 | - // page link |
|
1569 | - $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1570 | - |
|
1571 | - return $output; |
|
1572 | - } |
|
1573 | - |
|
1574 | - public static function css_secondary($color_code,$compatibility){; |
|
1575 | - $color_code = sanitize_hex_color($color_code); |
|
1576 | - if(!$color_code){return '';} |
|
1577 | - /** |
|
1578 | - * c = color, b = background color, o = border-color, f = fill |
|
1579 | - */ |
|
1580 | - $selectors = array( |
|
1581 | - '.btn-secondary' => array('b','o'), |
|
1582 | - '.btn-secondary.disabled' => array('b','o'), |
|
1583 | - '.btn-secondary:disabled' => array('b','o'), |
|
1584 | - '.btn-outline-secondary' => array('c','o'), |
|
1585 | - '.btn-outline-secondary:hover' => array('b','o'), |
|
1586 | - '.btn-outline-secondary.disabled' => array('c'), |
|
1587 | - '.btn-outline-secondary:disabled' => array('c'), |
|
1588 | - '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1589 | - '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1590 | - '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
|
1591 | - '.badge-secondary' => array('b'), |
|
1592 | - '.alert-secondary' => array('b','o'), |
|
1593 | - '.btn-link.btn-secondary' => array('c'), |
|
1594 | - ); |
|
1595 | - |
|
1596 | - $important_selectors = array( |
|
1597 | - '.bg-secondary' => array('b','f'), |
|
1598 | - '.border-secondary' => array('o'), |
|
1599 | - '.text-secondary' => array('c'), |
|
1600 | - ); |
|
1601 | - |
|
1602 | - $color = array(); |
|
1603 | - $color_i = array(); |
|
1604 | - $background = array(); |
|
1605 | - $background_i = array(); |
|
1606 | - $border = array(); |
|
1607 | - $border_i = array(); |
|
1608 | - $fill = array(); |
|
1609 | - $fill_i = array(); |
|
1610 | - |
|
1611 | - $output = ''; |
|
1612 | - |
|
1613 | - // build rules into each type |
|
1614 | - foreach($selectors as $selector => $types){ |
|
1615 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1616 | - $types = array_combine($types,$types); |
|
1617 | - if(isset($types['c'])){$color[] = $selector;} |
|
1618 | - if(isset($types['b'])){$background[] = $selector;} |
|
1619 | - if(isset($types['o'])){$border[] = $selector;} |
|
1620 | - if(isset($types['f'])){$fill[] = $selector;} |
|
1621 | - } |
|
1622 | - |
|
1623 | - // build rules into each type |
|
1624 | - foreach($important_selectors as $selector => $types){ |
|
1625 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1626 | - $types = array_combine($types,$types); |
|
1627 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
1628 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
1629 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
1630 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
1631 | - } |
|
1632 | - |
|
1633 | - // add any color rules |
|
1634 | - if(!empty($color)){ |
|
1635 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1636 | - } |
|
1637 | - if(!empty($color_i)){ |
|
1638 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1639 | - } |
|
1640 | - |
|
1641 | - // add any background color rules |
|
1642 | - if(!empty($background)){ |
|
1643 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1644 | - } |
|
1645 | - if(!empty($background_i)){ |
|
1646 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1647 | - } |
|
1648 | - |
|
1649 | - // add any border color rules |
|
1650 | - if(!empty($border)){ |
|
1651 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1652 | - } |
|
1653 | - if(!empty($border_i)){ |
|
1654 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1655 | - } |
|
1656 | - |
|
1657 | - // add any fill color rules |
|
1658 | - if(!empty($fill)){ |
|
1659 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1660 | - } |
|
1661 | - if(!empty($fill_i)){ |
|
1662 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1663 | - } |
|
1664 | - |
|
1665 | - |
|
1666 | - $prefix = $compatibility ? ".bsui " : ""; |
|
1667 | - |
|
1668 | - // darken |
|
1669 | - $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1670 | - $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1671 | - $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1672 | - |
|
1673 | - // lighten |
|
1674 | - $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1675 | - |
|
1676 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1677 | - $op_25 = $color_code."40"; // 25% opacity |
|
1678 | - |
|
1679 | - |
|
1680 | - // button states |
|
1681 | - $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1682 | - $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1683 | - $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1684 | - $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1685 | - |
|
1686 | - |
|
1687 | - return $output; |
|
1688 | - } |
|
1689 | - |
|
1690 | - /** |
|
1691 | - * Increases or decreases the brightness of a color by a percentage of the current brightness. |
|
1692 | - * |
|
1693 | - * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
|
1694 | - * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
|
1695 | - * |
|
1696 | - * @return string |
|
1697 | - */ |
|
1698 | - public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
|
1699 | - $hexCode = ltrim($hexCode, '#'); |
|
1700 | - |
|
1701 | - if (strlen($hexCode) == 3) { |
|
1702 | - $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
|
1703 | - } |
|
1704 | - |
|
1705 | - $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
|
1706 | - |
|
1707 | - foreach ($hexCode as & $color) { |
|
1708 | - $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
|
1709 | - $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
|
1710 | - |
|
1711 | - $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
|
1712 | - } |
|
1713 | - |
|
1714 | - return '#' . implode($hexCode); |
|
1715 | - } |
|
1716 | - |
|
1717 | - /** |
|
1718 | - * Check if we should display examples. |
|
1719 | - */ |
|
1720 | - public function maybe_show_examples(){ |
|
1721 | - if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
1722 | - echo "<head>"; |
|
1723 | - wp_head(); |
|
1724 | - echo "</head>"; |
|
1725 | - echo "<body>"; |
|
1726 | - echo $this->get_examples(); |
|
1727 | - echo "</body>"; |
|
1728 | - exit; |
|
1729 | - } |
|
1730 | - } |
|
1731 | - |
|
1732 | - /** |
|
1733 | - * Get developer examples. |
|
1734 | - * |
|
1735 | - * @return string |
|
1736 | - */ |
|
1737 | - public function get_examples(){ |
|
1738 | - $output = ''; |
|
1739 | - |
|
1740 | - |
|
1741 | - // open form |
|
1742 | - $output .= "<form class='p-5 m-5 border rounded'>"; |
|
1743 | - |
|
1744 | - // input example |
|
1745 | - $output .= aui()->input(array( |
|
1746 | - 'type' => 'text', |
|
1747 | - 'id' => 'text-example', |
|
1748 | - 'name' => 'text-example', |
|
1749 | - 'placeholder' => 'text placeholder', |
|
1750 | - 'title' => 'Text input example', |
|
1751 | - 'value' => '', |
|
1752 | - 'required' => false, |
|
1753 | - 'help_text' => 'help text', |
|
1754 | - 'label' => 'Text input example label' |
|
1755 | - )); |
|
1756 | - |
|
1757 | - // input example |
|
1758 | - $output .= aui()->input(array( |
|
1759 | - 'type' => 'url', |
|
1760 | - 'id' => 'text-example2', |
|
1761 | - 'name' => 'text-example', |
|
1762 | - 'placeholder' => 'url placeholder', |
|
1763 | - 'title' => 'Text input example', |
|
1764 | - 'value' => '', |
|
1765 | - 'required' => false, |
|
1766 | - 'help_text' => 'help text', |
|
1767 | - 'label' => 'Text input example label' |
|
1768 | - )); |
|
1769 | - |
|
1770 | - // checkbox example |
|
1771 | - $output .= aui()->input(array( |
|
1772 | - 'type' => 'checkbox', |
|
1773 | - 'id' => 'checkbox-example', |
|
1774 | - 'name' => 'checkbox-example', |
|
1775 | - 'placeholder' => 'checkbox-example', |
|
1776 | - 'title' => 'Checkbox example', |
|
1777 | - 'value' => '1', |
|
1778 | - 'checked' => true, |
|
1779 | - 'required' => false, |
|
1780 | - 'help_text' => 'help text', |
|
1781 | - 'label' => 'Checkbox checked' |
|
1782 | - )); |
|
1783 | - |
|
1784 | - // checkbox example |
|
1785 | - $output .= aui()->input(array( |
|
1786 | - 'type' => 'checkbox', |
|
1787 | - 'id' => 'checkbox-example2', |
|
1788 | - 'name' => 'checkbox-example2', |
|
1789 | - 'placeholder' => 'checkbox-example', |
|
1790 | - 'title' => 'Checkbox example', |
|
1791 | - 'value' => '1', |
|
1792 | - 'checked' => false, |
|
1793 | - 'required' => false, |
|
1794 | - 'help_text' => 'help text', |
|
1795 | - 'label' => 'Checkbox un-checked' |
|
1796 | - )); |
|
1797 | - |
|
1798 | - // switch example |
|
1799 | - $output .= aui()->input(array( |
|
1800 | - 'type' => 'checkbox', |
|
1801 | - 'id' => 'switch-example', |
|
1802 | - 'name' => 'switch-example', |
|
1803 | - 'placeholder' => 'checkbox-example', |
|
1804 | - 'title' => 'Switch example', |
|
1805 | - 'value' => '1', |
|
1806 | - 'checked' => true, |
|
1807 | - 'switch' => true, |
|
1808 | - 'required' => false, |
|
1809 | - 'help_text' => 'help text', |
|
1810 | - 'label' => 'Switch on' |
|
1811 | - )); |
|
1812 | - |
|
1813 | - // switch example |
|
1814 | - $output .= aui()->input(array( |
|
1815 | - 'type' => 'checkbox', |
|
1816 | - 'id' => 'switch-example2', |
|
1817 | - 'name' => 'switch-example2', |
|
1818 | - 'placeholder' => 'checkbox-example', |
|
1819 | - 'title' => 'Switch example', |
|
1820 | - 'value' => '1', |
|
1821 | - 'checked' => false, |
|
1822 | - 'switch' => true, |
|
1823 | - 'required' => false, |
|
1824 | - 'help_text' => 'help text', |
|
1825 | - 'label' => 'Switch off' |
|
1826 | - )); |
|
1827 | - |
|
1828 | - // close form |
|
1829 | - $output .= "</form>"; |
|
1830 | - |
|
1831 | - return $output; |
|
1832 | - } |
|
1833 | - |
|
1834 | - /** |
|
1835 | - * Calendar params. |
|
1836 | - * |
|
1837 | - * @since 0.1.44 |
|
1838 | - * |
|
1839 | - * @return array Calendar params. |
|
1840 | - */ |
|
1841 | - public static function calendar_params() { |
|
1842 | - $params = array( |
|
1843 | - 'month_long_1' => __( 'January', 'aui' ), |
|
1844 | - 'month_long_2' => __( 'February', 'aui' ), |
|
1845 | - 'month_long_3' => __( 'March', 'aui' ), |
|
1846 | - 'month_long_4' => __( 'April', 'aui' ), |
|
1847 | - 'month_long_5' => __( 'May', 'aui' ), |
|
1848 | - 'month_long_6' => __( 'June', 'aui' ), |
|
1849 | - 'month_long_7' => __( 'July', 'aui' ), |
|
1850 | - 'month_long_8' => __( 'August', 'aui' ), |
|
1851 | - 'month_long_9' => __( 'September', 'aui' ), |
|
1852 | - 'month_long_10' => __( 'October', 'aui' ), |
|
1853 | - 'month_long_11' => __( 'November', 'aui' ), |
|
1854 | - 'month_long_12' => __( 'December', 'aui' ), |
|
1855 | - 'month_s_1' => _x( 'Jan', 'January abbreviation', 'aui' ), |
|
1856 | - 'month_s_2' => _x( 'Feb', 'February abbreviation', 'aui' ), |
|
1857 | - 'month_s_3' => _x( 'Mar', 'March abbreviation', 'aui' ), |
|
1858 | - 'month_s_4' => _x( 'Apr', 'April abbreviation', 'aui' ), |
|
1859 | - 'month_s_5' => _x( 'May', 'May abbreviation', 'aui' ), |
|
1860 | - 'month_s_6' => _x( 'Jun', 'June abbreviation', 'aui' ), |
|
1861 | - 'month_s_7' => _x( 'Jul', 'July abbreviation', 'aui' ), |
|
1862 | - 'month_s_8' => _x( 'Aug', 'August abbreviation', 'aui' ), |
|
1863 | - 'month_s_9' => _x( 'Sep', 'September abbreviation', 'aui' ), |
|
1864 | - 'month_s_10' => _x( 'Oct', 'October abbreviation', 'aui' ), |
|
1865 | - 'month_s_11' => _x( 'Nov', 'November abbreviation', 'aui' ), |
|
1866 | - 'month_s_12' => _x( 'Dec', 'December abbreviation', 'aui' ), |
|
1867 | - 'day_s1_1' => _x( 'S', 'Sunday initial', 'aui' ), |
|
1868 | - 'day_s1_2' => _x( 'M', 'Monday initial', 'aui' ), |
|
1869 | - 'day_s1_3' => _x( 'T', 'Tuesday initial', 'aui' ), |
|
1870 | - 'day_s1_4' => _x( 'W', 'Wednesday initial', 'aui' ), |
|
1871 | - 'day_s1_5' => _x( 'T', 'Friday initial', 'aui' ), |
|
1872 | - 'day_s1_6' => _x( 'F', 'Thursday initial', 'aui' ), |
|
1873 | - 'day_s1_7' => _x( 'S', 'Saturday initial', 'aui' ), |
|
1874 | - 'day_s2_1' => __( 'Su', 'aui' ), |
|
1875 | - 'day_s2_2' => __( 'Mo', 'aui' ), |
|
1876 | - 'day_s2_3' => __( 'Tu', 'aui' ), |
|
1877 | - 'day_s2_4' => __( 'We', 'aui' ), |
|
1878 | - 'day_s2_5' => __( 'Th', 'aui' ), |
|
1879 | - 'day_s2_6' => __( 'Fr', 'aui' ), |
|
1880 | - 'day_s2_7' => __( 'Sa', 'aui' ), |
|
1881 | - 'day_s3_1' => __( 'Sun', 'aui' ), |
|
1882 | - 'day_s3_2' => __( 'Mon', 'aui' ), |
|
1883 | - 'day_s3_3' => __( 'Tue', 'aui' ), |
|
1884 | - 'day_s3_4' => __( 'Wed', 'aui' ), |
|
1885 | - 'day_s3_5' => __( 'Thu', 'aui' ), |
|
1886 | - 'day_s3_6' => __( 'Fri', 'aui' ), |
|
1887 | - 'day_s3_7' => __( 'Sat', 'aui' ), |
|
1888 | - 'day_s5_1' => __( 'Sunday', 'aui' ), |
|
1889 | - 'day_s5_2' => __( 'Monday', 'aui' ), |
|
1890 | - 'day_s5_3' => __( 'Tuesday', 'aui' ), |
|
1891 | - 'day_s5_4' => __( 'Wednesday', 'aui' ), |
|
1892 | - 'day_s5_5' => __( 'Thursday', 'aui' ), |
|
1893 | - 'day_s5_6' => __( 'Friday', 'aui' ), |
|
1894 | - 'day_s5_7' => __( 'Saturday', 'aui' ), |
|
1895 | - 'am_lower' => __( 'am', 'aui' ), |
|
1896 | - 'pm_lower' => __( 'pm', 'aui' ), |
|
1897 | - 'am_upper' => __( 'AM', 'aui' ), |
|
1898 | - 'pm_upper' => __( 'PM', 'aui' ), |
|
1899 | - 'firstDayOfWeek' => (int) get_option( 'start_of_week' ), |
|
1900 | - 'time_24hr' => false, |
|
1901 | - 'year' => __( 'Year', 'aui' ), |
|
1902 | - 'hour' => __( 'Hour', 'aui' ), |
|
1903 | - 'minute' => __( 'Minute', 'aui' ), |
|
1904 | - 'weekAbbreviation' => __( 'Wk', 'aui' ), |
|
1905 | - 'rangeSeparator' => __( ' to ', 'aui' ), |
|
1906 | - 'scrollTitle' => __( 'Scroll to increment', 'aui' ), |
|
1907 | - 'toggleTitle' => __( 'Click to toggle', 'aui' ) |
|
1908 | - ); |
|
1909 | - |
|
1910 | - return apply_filters( 'ayecode_ui_calendar_params', $params ); |
|
1911 | - } |
|
1912 | - |
|
1913 | - /** |
|
1914 | - * Flatpickr calendar localize. |
|
1915 | - * |
|
1916 | - * @since 0.1.44 |
|
1917 | - * |
|
1918 | - * @return string Calendar locale. |
|
1919 | - */ |
|
1920 | - public static function flatpickr_locale() { |
|
1921 | - $params = self::calendar_params(); |
|
1922 | - |
|
1923 | - if ( is_string( $params ) ) { |
|
1924 | - $params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' ); |
|
1925 | - } else { |
|
1926 | - foreach ( (array) $params as $key => $value ) { |
|
1927 | - if ( ! is_scalar( $value ) ) { |
|
1928 | - continue; |
|
1929 | - } |
|
1930 | - |
|
1931 | - $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
1932 | - } |
|
1933 | - } |
|
1457 | + '.nav-pills .nav-link.active' => array('b'), |
|
1458 | + '.nav-pills .show>.nav-link' => array('b'), |
|
1459 | + '.page-link' => array('c'), |
|
1460 | + '.page-item.active .page-link' => array('b','o'), |
|
1461 | + '.badge-primary' => array('b'), |
|
1462 | + '.alert-primary' => array('b','o'), |
|
1463 | + '.progress-bar' => array('b'), |
|
1464 | + '.list-group-item.active' => array('b','o'), |
|
1465 | + '.bg-primary' => array('b','f'), |
|
1466 | + '.btn-link.btn-primary' => array('c'), |
|
1467 | + '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
|
1468 | + ); |
|
1469 | + |
|
1470 | + $important_selectors = array( |
|
1471 | + '.bg-primary' => array('b','f'), |
|
1472 | + '.border-primary' => array('o'), |
|
1473 | + '.text-primary' => array('c'), |
|
1474 | + ); |
|
1475 | + |
|
1476 | + $color = array(); |
|
1477 | + $color_i = array(); |
|
1478 | + $background = array(); |
|
1479 | + $background_i = array(); |
|
1480 | + $border = array(); |
|
1481 | + $border_i = array(); |
|
1482 | + $fill = array(); |
|
1483 | + $fill_i = array(); |
|
1484 | + |
|
1485 | + $output = ''; |
|
1486 | + |
|
1487 | + // build rules into each type |
|
1488 | + foreach($selectors as $selector => $types){ |
|
1489 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1490 | + $types = array_combine($types,$types); |
|
1491 | + if(isset($types['c'])){$color[] = $selector;} |
|
1492 | + if(isset($types['b'])){$background[] = $selector;} |
|
1493 | + if(isset($types['o'])){$border[] = $selector;} |
|
1494 | + if(isset($types['f'])){$fill[] = $selector;} |
|
1495 | + } |
|
1496 | + |
|
1497 | + // build rules into each type |
|
1498 | + foreach($important_selectors as $selector => $types){ |
|
1499 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1500 | + $types = array_combine($types,$types); |
|
1501 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
1502 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
1503 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
1504 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
1505 | + } |
|
1506 | + |
|
1507 | + // add any color rules |
|
1508 | + if(!empty($color)){ |
|
1509 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1510 | + } |
|
1511 | + if(!empty($color_i)){ |
|
1512 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1513 | + } |
|
1514 | + |
|
1515 | + // add any background color rules |
|
1516 | + if(!empty($background)){ |
|
1517 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1518 | + } |
|
1519 | + if(!empty($background_i)){ |
|
1520 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1521 | + } |
|
1522 | + |
|
1523 | + // add any border color rules |
|
1524 | + if(!empty($border)){ |
|
1525 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1526 | + } |
|
1527 | + if(!empty($border_i)){ |
|
1528 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1529 | + } |
|
1530 | + |
|
1531 | + // add any fill color rules |
|
1532 | + if(!empty($fill)){ |
|
1533 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1534 | + } |
|
1535 | + if(!empty($fill_i)){ |
|
1536 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1537 | + } |
|
1538 | + |
|
1539 | + |
|
1540 | + $prefix = $compatibility ? ".bsui " : ""; |
|
1541 | + |
|
1542 | + // darken |
|
1543 | + $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1544 | + $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1545 | + $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1546 | + |
|
1547 | + // lighten |
|
1548 | + $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1549 | + |
|
1550 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1551 | + $op_25 = $color_code."40"; // 25% opacity |
|
1552 | + |
|
1553 | + |
|
1554 | + // button states |
|
1555 | + $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1556 | + $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1557 | + $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1558 | + $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1559 | + |
|
1560 | + |
|
1561 | + // dropdown's |
|
1562 | + $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
1563 | + |
|
1564 | + |
|
1565 | + // input states |
|
1566 | + $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1567 | + |
|
1568 | + // page link |
|
1569 | + $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1570 | + |
|
1571 | + return $output; |
|
1572 | + } |
|
1573 | + |
|
1574 | + public static function css_secondary($color_code,$compatibility){; |
|
1575 | + $color_code = sanitize_hex_color($color_code); |
|
1576 | + if(!$color_code){return '';} |
|
1577 | + /** |
|
1578 | + * c = color, b = background color, o = border-color, f = fill |
|
1579 | + */ |
|
1580 | + $selectors = array( |
|
1581 | + '.btn-secondary' => array('b','o'), |
|
1582 | + '.btn-secondary.disabled' => array('b','o'), |
|
1583 | + '.btn-secondary:disabled' => array('b','o'), |
|
1584 | + '.btn-outline-secondary' => array('c','o'), |
|
1585 | + '.btn-outline-secondary:hover' => array('b','o'), |
|
1586 | + '.btn-outline-secondary.disabled' => array('c'), |
|
1587 | + '.btn-outline-secondary:disabled' => array('c'), |
|
1588 | + '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1589 | + '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1590 | + '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
|
1591 | + '.badge-secondary' => array('b'), |
|
1592 | + '.alert-secondary' => array('b','o'), |
|
1593 | + '.btn-link.btn-secondary' => array('c'), |
|
1594 | + ); |
|
1595 | + |
|
1596 | + $important_selectors = array( |
|
1597 | + '.bg-secondary' => array('b','f'), |
|
1598 | + '.border-secondary' => array('o'), |
|
1599 | + '.text-secondary' => array('c'), |
|
1600 | + ); |
|
1601 | + |
|
1602 | + $color = array(); |
|
1603 | + $color_i = array(); |
|
1604 | + $background = array(); |
|
1605 | + $background_i = array(); |
|
1606 | + $border = array(); |
|
1607 | + $border_i = array(); |
|
1608 | + $fill = array(); |
|
1609 | + $fill_i = array(); |
|
1610 | + |
|
1611 | + $output = ''; |
|
1612 | + |
|
1613 | + // build rules into each type |
|
1614 | + foreach($selectors as $selector => $types){ |
|
1615 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1616 | + $types = array_combine($types,$types); |
|
1617 | + if(isset($types['c'])){$color[] = $selector;} |
|
1618 | + if(isset($types['b'])){$background[] = $selector;} |
|
1619 | + if(isset($types['o'])){$border[] = $selector;} |
|
1620 | + if(isset($types['f'])){$fill[] = $selector;} |
|
1621 | + } |
|
1622 | + |
|
1623 | + // build rules into each type |
|
1624 | + foreach($important_selectors as $selector => $types){ |
|
1625 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1626 | + $types = array_combine($types,$types); |
|
1627 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
1628 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
1629 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
1630 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
1631 | + } |
|
1632 | + |
|
1633 | + // add any color rules |
|
1634 | + if(!empty($color)){ |
|
1635 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1636 | + } |
|
1637 | + if(!empty($color_i)){ |
|
1638 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1639 | + } |
|
1640 | + |
|
1641 | + // add any background color rules |
|
1642 | + if(!empty($background)){ |
|
1643 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1644 | + } |
|
1645 | + if(!empty($background_i)){ |
|
1646 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1647 | + } |
|
1648 | + |
|
1649 | + // add any border color rules |
|
1650 | + if(!empty($border)){ |
|
1651 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1652 | + } |
|
1653 | + if(!empty($border_i)){ |
|
1654 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1655 | + } |
|
1656 | + |
|
1657 | + // add any fill color rules |
|
1658 | + if(!empty($fill)){ |
|
1659 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1660 | + } |
|
1661 | + if(!empty($fill_i)){ |
|
1662 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1663 | + } |
|
1664 | + |
|
1665 | + |
|
1666 | + $prefix = $compatibility ? ".bsui " : ""; |
|
1667 | + |
|
1668 | + // darken |
|
1669 | + $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1670 | + $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1671 | + $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1672 | + |
|
1673 | + // lighten |
|
1674 | + $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1675 | + |
|
1676 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1677 | + $op_25 = $color_code."40"; // 25% opacity |
|
1678 | + |
|
1679 | + |
|
1680 | + // button states |
|
1681 | + $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1682 | + $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1683 | + $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1684 | + $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1685 | + |
|
1686 | + |
|
1687 | + return $output; |
|
1688 | + } |
|
1689 | + |
|
1690 | + /** |
|
1691 | + * Increases or decreases the brightness of a color by a percentage of the current brightness. |
|
1692 | + * |
|
1693 | + * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
|
1694 | + * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
|
1695 | + * |
|
1696 | + * @return string |
|
1697 | + */ |
|
1698 | + public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
|
1699 | + $hexCode = ltrim($hexCode, '#'); |
|
1700 | + |
|
1701 | + if (strlen($hexCode) == 3) { |
|
1702 | + $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
|
1703 | + } |
|
1704 | + |
|
1705 | + $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
|
1706 | + |
|
1707 | + foreach ($hexCode as & $color) { |
|
1708 | + $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
|
1709 | + $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
|
1710 | + |
|
1711 | + $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
|
1712 | + } |
|
1713 | + |
|
1714 | + return '#' . implode($hexCode); |
|
1715 | + } |
|
1716 | + |
|
1717 | + /** |
|
1718 | + * Check if we should display examples. |
|
1719 | + */ |
|
1720 | + public function maybe_show_examples(){ |
|
1721 | + if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
1722 | + echo "<head>"; |
|
1723 | + wp_head(); |
|
1724 | + echo "</head>"; |
|
1725 | + echo "<body>"; |
|
1726 | + echo $this->get_examples(); |
|
1727 | + echo "</body>"; |
|
1728 | + exit; |
|
1729 | + } |
|
1730 | + } |
|
1731 | + |
|
1732 | + /** |
|
1733 | + * Get developer examples. |
|
1734 | + * |
|
1735 | + * @return string |
|
1736 | + */ |
|
1737 | + public function get_examples(){ |
|
1738 | + $output = ''; |
|
1739 | + |
|
1740 | + |
|
1741 | + // open form |
|
1742 | + $output .= "<form class='p-5 m-5 border rounded'>"; |
|
1743 | + |
|
1744 | + // input example |
|
1745 | + $output .= aui()->input(array( |
|
1746 | + 'type' => 'text', |
|
1747 | + 'id' => 'text-example', |
|
1748 | + 'name' => 'text-example', |
|
1749 | + 'placeholder' => 'text placeholder', |
|
1750 | + 'title' => 'Text input example', |
|
1751 | + 'value' => '', |
|
1752 | + 'required' => false, |
|
1753 | + 'help_text' => 'help text', |
|
1754 | + 'label' => 'Text input example label' |
|
1755 | + )); |
|
1756 | + |
|
1757 | + // input example |
|
1758 | + $output .= aui()->input(array( |
|
1759 | + 'type' => 'url', |
|
1760 | + 'id' => 'text-example2', |
|
1761 | + 'name' => 'text-example', |
|
1762 | + 'placeholder' => 'url placeholder', |
|
1763 | + 'title' => 'Text input example', |
|
1764 | + 'value' => '', |
|
1765 | + 'required' => false, |
|
1766 | + 'help_text' => 'help text', |
|
1767 | + 'label' => 'Text input example label' |
|
1768 | + )); |
|
1769 | + |
|
1770 | + // checkbox example |
|
1771 | + $output .= aui()->input(array( |
|
1772 | + 'type' => 'checkbox', |
|
1773 | + 'id' => 'checkbox-example', |
|
1774 | + 'name' => 'checkbox-example', |
|
1775 | + 'placeholder' => 'checkbox-example', |
|
1776 | + 'title' => 'Checkbox example', |
|
1777 | + 'value' => '1', |
|
1778 | + 'checked' => true, |
|
1779 | + 'required' => false, |
|
1780 | + 'help_text' => 'help text', |
|
1781 | + 'label' => 'Checkbox checked' |
|
1782 | + )); |
|
1783 | + |
|
1784 | + // checkbox example |
|
1785 | + $output .= aui()->input(array( |
|
1786 | + 'type' => 'checkbox', |
|
1787 | + 'id' => 'checkbox-example2', |
|
1788 | + 'name' => 'checkbox-example2', |
|
1789 | + 'placeholder' => 'checkbox-example', |
|
1790 | + 'title' => 'Checkbox example', |
|
1791 | + 'value' => '1', |
|
1792 | + 'checked' => false, |
|
1793 | + 'required' => false, |
|
1794 | + 'help_text' => 'help text', |
|
1795 | + 'label' => 'Checkbox un-checked' |
|
1796 | + )); |
|
1797 | + |
|
1798 | + // switch example |
|
1799 | + $output .= aui()->input(array( |
|
1800 | + 'type' => 'checkbox', |
|
1801 | + 'id' => 'switch-example', |
|
1802 | + 'name' => 'switch-example', |
|
1803 | + 'placeholder' => 'checkbox-example', |
|
1804 | + 'title' => 'Switch example', |
|
1805 | + 'value' => '1', |
|
1806 | + 'checked' => true, |
|
1807 | + 'switch' => true, |
|
1808 | + 'required' => false, |
|
1809 | + 'help_text' => 'help text', |
|
1810 | + 'label' => 'Switch on' |
|
1811 | + )); |
|
1812 | + |
|
1813 | + // switch example |
|
1814 | + $output .= aui()->input(array( |
|
1815 | + 'type' => 'checkbox', |
|
1816 | + 'id' => 'switch-example2', |
|
1817 | + 'name' => 'switch-example2', |
|
1818 | + 'placeholder' => 'checkbox-example', |
|
1819 | + 'title' => 'Switch example', |
|
1820 | + 'value' => '1', |
|
1821 | + 'checked' => false, |
|
1822 | + 'switch' => true, |
|
1823 | + 'required' => false, |
|
1824 | + 'help_text' => 'help text', |
|
1825 | + 'label' => 'Switch off' |
|
1826 | + )); |
|
1827 | + |
|
1828 | + // close form |
|
1829 | + $output .= "</form>"; |
|
1830 | + |
|
1831 | + return $output; |
|
1832 | + } |
|
1833 | + |
|
1834 | + /** |
|
1835 | + * Calendar params. |
|
1836 | + * |
|
1837 | + * @since 0.1.44 |
|
1838 | + * |
|
1839 | + * @return array Calendar params. |
|
1840 | + */ |
|
1841 | + public static function calendar_params() { |
|
1842 | + $params = array( |
|
1843 | + 'month_long_1' => __( 'January', 'aui' ), |
|
1844 | + 'month_long_2' => __( 'February', 'aui' ), |
|
1845 | + 'month_long_3' => __( 'March', 'aui' ), |
|
1846 | + 'month_long_4' => __( 'April', 'aui' ), |
|
1847 | + 'month_long_5' => __( 'May', 'aui' ), |
|
1848 | + 'month_long_6' => __( 'June', 'aui' ), |
|
1849 | + 'month_long_7' => __( 'July', 'aui' ), |
|
1850 | + 'month_long_8' => __( 'August', 'aui' ), |
|
1851 | + 'month_long_9' => __( 'September', 'aui' ), |
|
1852 | + 'month_long_10' => __( 'October', 'aui' ), |
|
1853 | + 'month_long_11' => __( 'November', 'aui' ), |
|
1854 | + 'month_long_12' => __( 'December', 'aui' ), |
|
1855 | + 'month_s_1' => _x( 'Jan', 'January abbreviation', 'aui' ), |
|
1856 | + 'month_s_2' => _x( 'Feb', 'February abbreviation', 'aui' ), |
|
1857 | + 'month_s_3' => _x( 'Mar', 'March abbreviation', 'aui' ), |
|
1858 | + 'month_s_4' => _x( 'Apr', 'April abbreviation', 'aui' ), |
|
1859 | + 'month_s_5' => _x( 'May', 'May abbreviation', 'aui' ), |
|
1860 | + 'month_s_6' => _x( 'Jun', 'June abbreviation', 'aui' ), |
|
1861 | + 'month_s_7' => _x( 'Jul', 'July abbreviation', 'aui' ), |
|
1862 | + 'month_s_8' => _x( 'Aug', 'August abbreviation', 'aui' ), |
|
1863 | + 'month_s_9' => _x( 'Sep', 'September abbreviation', 'aui' ), |
|
1864 | + 'month_s_10' => _x( 'Oct', 'October abbreviation', 'aui' ), |
|
1865 | + 'month_s_11' => _x( 'Nov', 'November abbreviation', 'aui' ), |
|
1866 | + 'month_s_12' => _x( 'Dec', 'December abbreviation', 'aui' ), |
|
1867 | + 'day_s1_1' => _x( 'S', 'Sunday initial', 'aui' ), |
|
1868 | + 'day_s1_2' => _x( 'M', 'Monday initial', 'aui' ), |
|
1869 | + 'day_s1_3' => _x( 'T', 'Tuesday initial', 'aui' ), |
|
1870 | + 'day_s1_4' => _x( 'W', 'Wednesday initial', 'aui' ), |
|
1871 | + 'day_s1_5' => _x( 'T', 'Friday initial', 'aui' ), |
|
1872 | + 'day_s1_6' => _x( 'F', 'Thursday initial', 'aui' ), |
|
1873 | + 'day_s1_7' => _x( 'S', 'Saturday initial', 'aui' ), |
|
1874 | + 'day_s2_1' => __( 'Su', 'aui' ), |
|
1875 | + 'day_s2_2' => __( 'Mo', 'aui' ), |
|
1876 | + 'day_s2_3' => __( 'Tu', 'aui' ), |
|
1877 | + 'day_s2_4' => __( 'We', 'aui' ), |
|
1878 | + 'day_s2_5' => __( 'Th', 'aui' ), |
|
1879 | + 'day_s2_6' => __( 'Fr', 'aui' ), |
|
1880 | + 'day_s2_7' => __( 'Sa', 'aui' ), |
|
1881 | + 'day_s3_1' => __( 'Sun', 'aui' ), |
|
1882 | + 'day_s3_2' => __( 'Mon', 'aui' ), |
|
1883 | + 'day_s3_3' => __( 'Tue', 'aui' ), |
|
1884 | + 'day_s3_4' => __( 'Wed', 'aui' ), |
|
1885 | + 'day_s3_5' => __( 'Thu', 'aui' ), |
|
1886 | + 'day_s3_6' => __( 'Fri', 'aui' ), |
|
1887 | + 'day_s3_7' => __( 'Sat', 'aui' ), |
|
1888 | + 'day_s5_1' => __( 'Sunday', 'aui' ), |
|
1889 | + 'day_s5_2' => __( 'Monday', 'aui' ), |
|
1890 | + 'day_s5_3' => __( 'Tuesday', 'aui' ), |
|
1891 | + 'day_s5_4' => __( 'Wednesday', 'aui' ), |
|
1892 | + 'day_s5_5' => __( 'Thursday', 'aui' ), |
|
1893 | + 'day_s5_6' => __( 'Friday', 'aui' ), |
|
1894 | + 'day_s5_7' => __( 'Saturday', 'aui' ), |
|
1895 | + 'am_lower' => __( 'am', 'aui' ), |
|
1896 | + 'pm_lower' => __( 'pm', 'aui' ), |
|
1897 | + 'am_upper' => __( 'AM', 'aui' ), |
|
1898 | + 'pm_upper' => __( 'PM', 'aui' ), |
|
1899 | + 'firstDayOfWeek' => (int) get_option( 'start_of_week' ), |
|
1900 | + 'time_24hr' => false, |
|
1901 | + 'year' => __( 'Year', 'aui' ), |
|
1902 | + 'hour' => __( 'Hour', 'aui' ), |
|
1903 | + 'minute' => __( 'Minute', 'aui' ), |
|
1904 | + 'weekAbbreviation' => __( 'Wk', 'aui' ), |
|
1905 | + 'rangeSeparator' => __( ' to ', 'aui' ), |
|
1906 | + 'scrollTitle' => __( 'Scroll to increment', 'aui' ), |
|
1907 | + 'toggleTitle' => __( 'Click to toggle', 'aui' ) |
|
1908 | + ); |
|
1909 | + |
|
1910 | + return apply_filters( 'ayecode_ui_calendar_params', $params ); |
|
1911 | + } |
|
1912 | + |
|
1913 | + /** |
|
1914 | + * Flatpickr calendar localize. |
|
1915 | + * |
|
1916 | + * @since 0.1.44 |
|
1917 | + * |
|
1918 | + * @return string Calendar locale. |
|
1919 | + */ |
|
1920 | + public static function flatpickr_locale() { |
|
1921 | + $params = self::calendar_params(); |
|
1922 | + |
|
1923 | + if ( is_string( $params ) ) { |
|
1924 | + $params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' ); |
|
1925 | + } else { |
|
1926 | + foreach ( (array) $params as $key => $value ) { |
|
1927 | + if ( ! is_scalar( $value ) ) { |
|
1928 | + continue; |
|
1929 | + } |
|
1930 | + |
|
1931 | + $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
1932 | + } |
|
1933 | + } |
|
1934 | 1934 | |
1935 | - $day_s3 = array(); |
|
1936 | - $day_s5 = array(); |
|
1935 | + $day_s3 = array(); |
|
1936 | + $day_s5 = array(); |
|
1937 | 1937 | |
1938 | - for ( $i = 1; $i <= 7; $i ++ ) { |
|
1939 | - $day_s3[] = addslashes( $params[ 'day_s3_' . $i ] ); |
|
1940 | - $day_s5[] = addslashes( $params[ 'day_s3_' . $i ] ); |
|
1941 | - } |
|
1938 | + for ( $i = 1; $i <= 7; $i ++ ) { |
|
1939 | + $day_s3[] = addslashes( $params[ 'day_s3_' . $i ] ); |
|
1940 | + $day_s5[] = addslashes( $params[ 'day_s3_' . $i ] ); |
|
1941 | + } |
|
1942 | 1942 | |
1943 | - $month_s = array(); |
|
1944 | - $month_long = array(); |
|
1943 | + $month_s = array(); |
|
1944 | + $month_long = array(); |
|
1945 | 1945 | |
1946 | - for ( $i = 1; $i <= 12; $i ++ ) { |
|
1947 | - $month_s[] = addslashes( $params[ 'month_s_' . $i ] ); |
|
1948 | - $month_long[] = addslashes( $params[ 'month_long_' . $i ] ); |
|
1949 | - } |
|
1946 | + for ( $i = 1; $i <= 12; $i ++ ) { |
|
1947 | + $month_s[] = addslashes( $params[ 'month_s_' . $i ] ); |
|
1948 | + $month_long[] = addslashes( $params[ 'month_long_' . $i ] ); |
|
1949 | + } |
|
1950 | 1950 | |
1951 | 1951 | ob_start(); |
1952 | 1952 | if ( 0 ) { ?><script><?php } ?> |
@@ -1988,62 +1988,62 @@ discard block |
||
1988 | 1988 | } |
1989 | 1989 | <?php if ( 0 ) { ?></script><?php } ?> |
1990 | 1990 | <?php |
1991 | - $locale = ob_get_clean(); |
|
1992 | - |
|
1993 | - return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) ); |
|
1994 | - } |
|
1995 | - |
|
1996 | - /** |
|
1997 | - * Select2 JS params. |
|
1998 | - * |
|
1999 | - * @since 0.1.44 |
|
2000 | - * |
|
2001 | - * @return array Select2 JS params. |
|
2002 | - */ |
|
2003 | - public static function select2_params() { |
|
2004 | - $params = array( |
|
2005 | - 'i18n_select_state_text' => esc_attr__( 'Select an option…', 'aui' ), |
|
2006 | - 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'aui' ), |
|
2007 | - 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'aui' ), |
|
2008 | - 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'aui' ), |
|
2009 | - 'i18n_input_too_short_n' => _x( 'Please enter %item% or more characters', 'enhanced select', 'aui' ), |
|
2010 | - 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'aui' ), |
|
2011 | - 'i18n_input_too_long_n' => _x( 'Please delete %item% characters', 'enhanced select', 'aui' ), |
|
2012 | - 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'aui' ), |
|
2013 | - 'i18n_selection_too_long_n' => _x( 'You can only select %item% items', 'enhanced select', 'aui' ), |
|
2014 | - 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'aui' ), |
|
2015 | - 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'aui' ) |
|
2016 | - ); |
|
2017 | - |
|
2018 | - return apply_filters( 'ayecode_ui_select2_params', $params ); |
|
2019 | - } |
|
2020 | - |
|
2021 | - /** |
|
2022 | - * Select2 JS localize. |
|
2023 | - * |
|
2024 | - * @since 0.1.44 |
|
2025 | - * |
|
2026 | - * @return string Select2 JS locale. |
|
2027 | - */ |
|
2028 | - public static function select2_locale() { |
|
2029 | - $params = self::select2_params(); |
|
2030 | - |
|
2031 | - foreach ( (array) $params as $key => $value ) { |
|
2032 | - if ( ! is_scalar( $value ) ) { |
|
2033 | - continue; |
|
2034 | - } |
|
1991 | + $locale = ob_get_clean(); |
|
1992 | + |
|
1993 | + return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) ); |
|
1994 | + } |
|
1995 | + |
|
1996 | + /** |
|
1997 | + * Select2 JS params. |
|
1998 | + * |
|
1999 | + * @since 0.1.44 |
|
2000 | + * |
|
2001 | + * @return array Select2 JS params. |
|
2002 | + */ |
|
2003 | + public static function select2_params() { |
|
2004 | + $params = array( |
|
2005 | + 'i18n_select_state_text' => esc_attr__( 'Select an option…', 'aui' ), |
|
2006 | + 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'aui' ), |
|
2007 | + 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'aui' ), |
|
2008 | + 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'aui' ), |
|
2009 | + 'i18n_input_too_short_n' => _x( 'Please enter %item% or more characters', 'enhanced select', 'aui' ), |
|
2010 | + 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'aui' ), |
|
2011 | + 'i18n_input_too_long_n' => _x( 'Please delete %item% characters', 'enhanced select', 'aui' ), |
|
2012 | + 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'aui' ), |
|
2013 | + 'i18n_selection_too_long_n' => _x( 'You can only select %item% items', 'enhanced select', 'aui' ), |
|
2014 | + 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'aui' ), |
|
2015 | + 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'aui' ) |
|
2016 | + ); |
|
2017 | + |
|
2018 | + return apply_filters( 'ayecode_ui_select2_params', $params ); |
|
2019 | + } |
|
2020 | + |
|
2021 | + /** |
|
2022 | + * Select2 JS localize. |
|
2023 | + * |
|
2024 | + * @since 0.1.44 |
|
2025 | + * |
|
2026 | + * @return string Select2 JS locale. |
|
2027 | + */ |
|
2028 | + public static function select2_locale() { |
|
2029 | + $params = self::select2_params(); |
|
2030 | + |
|
2031 | + foreach ( (array) $params as $key => $value ) { |
|
2032 | + if ( ! is_scalar( $value ) ) { |
|
2033 | + continue; |
|
2034 | + } |
|
2035 | 2035 | |
2036 | - $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
2037 | - } |
|
2036 | + $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
2037 | + } |
|
2038 | 2038 | |
2039 | - $locale = json_encode( $params ); |
|
2039 | + $locale = json_encode( $params ); |
|
2040 | 2040 | |
2041 | - return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) ); |
|
2042 | - } |
|
2043 | - } |
|
2041 | + return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) ); |
|
2042 | + } |
|
2043 | + } |
|
2044 | 2044 | |
2045 | - /** |
|
2046 | - * Run the class if found. |
|
2047 | - */ |
|
2048 | - AyeCode_UI_Settings::instance(); |
|
2045 | + /** |
|
2046 | + * Run the class if found. |
|
2047 | + */ |
|
2048 | + AyeCode_UI_Settings::instance(); |
|
2049 | 2049 | } |
2050 | 2050 | \ No newline at end of file |