@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,30 +10,30 @@ discard block |
||
10 | 10 | class WPInv_Item extends GetPaid_Data { |
11 | 11 | |
12 | 12 | /** |
13 | - * Which data store to load. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
13 | + * Which data store to load. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | 17 | protected $data_store_name = 'item'; |
18 | 18 | |
19 | 19 | /** |
20 | - * This is the name of this object type. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $object_type = 'item'; |
|
20 | + * This is the name of this object type. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $object_type = 'item'; |
|
25 | 25 | |
26 | 26 | /** |
27 | - * Item Data array. This is the core item data exposed in APIs. |
|
28 | - * |
|
29 | - * @since 1.0.19 |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $data = array( |
|
33 | - 'parent_id' => 0, |
|
34 | - 'status' => 'draft', |
|
35 | - 'version' => '', |
|
36 | - 'date_created' => null, |
|
27 | + * Item Data array. This is the core item data exposed in APIs. |
|
28 | + * |
|
29 | + * @since 1.0.19 |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $data = array( |
|
33 | + 'parent_id' => 0, |
|
34 | + 'status' => 'draft', |
|
35 | + 'version' => '', |
|
36 | + 'date_created' => null, |
|
37 | 37 | 'date_modified' => null, |
38 | 38 | 'name' => '', |
39 | 39 | 'description' => '', |
@@ -58,13 +58,13 @@ discard block |
||
58 | 58 | ); |
59 | 59 | |
60 | 60 | /** |
61 | - * Stores meta in cache for future reads. |
|
62 | - * |
|
63 | - * A group must be set to to enable caching. |
|
64 | - * |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - protected $cache_group = 'getpaid_items'; |
|
61 | + * Stores meta in cache for future reads. |
|
62 | + * |
|
63 | + * A group must be set to to enable caching. |
|
64 | + * |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + protected $cache_group = 'getpaid_items'; |
|
68 | 68 | |
69 | 69 | /** |
70 | 70 | * Stores a reference to the original WP_Post object |
@@ -74,33 +74,33 @@ discard block |
||
74 | 74 | protected $post = null; |
75 | 75 | |
76 | 76 | /** |
77 | - * Get the item if ID is passed, otherwise the item is new and empty. |
|
78 | - * |
|
79 | - * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
80 | - */ |
|
81 | - public function __construct( $item = 0 ) { |
|
82 | - parent::__construct( $item ); |
|
83 | - |
|
84 | - if ( is_numeric( $item ) && $item > 0 ) { |
|
85 | - $this->set_id( $item ); |
|
86 | - } elseif ( $item instanceof self ) { |
|
87 | - $this->set_id( $item->get_id() ); |
|
88 | - } elseif ( ! empty( $item->ID ) ) { |
|
89 | - $this->set_id( $item->ID ); |
|
90 | - } else { |
|
91 | - $this->set_object_read( true ); |
|
92 | - } |
|
77 | + * Get the item if ID is passed, otherwise the item is new and empty. |
|
78 | + * |
|
79 | + * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
80 | + */ |
|
81 | + public function __construct( $item = 0 ) { |
|
82 | + parent::__construct( $item ); |
|
83 | + |
|
84 | + if ( is_numeric( $item ) && $item > 0 ) { |
|
85 | + $this->set_id( $item ); |
|
86 | + } elseif ( $item instanceof self ) { |
|
87 | + $this->set_id( $item->get_id() ); |
|
88 | + } elseif ( ! empty( $item->ID ) ) { |
|
89 | + $this->set_id( $item->ID ); |
|
90 | + } else { |
|
91 | + $this->set_object_read( true ); |
|
92 | + } |
|
93 | 93 | |
94 | 94 | // Load the datastore. |
95 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
95 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
96 | 96 | |
97 | - if ( $this->get_id() > 0 ) { |
|
97 | + if ( $this->get_id() > 0 ) { |
|
98 | 98 | $this->post = get_post( $this->get_id() ); |
99 | 99 | $this->ID = $this->get_id(); |
100 | - $this->data_store->read( $this ); |
|
100 | + $this->data_store->read( $this ); |
|
101 | 101 | } |
102 | 102 | |
103 | - } |
|
103 | + } |
|
104 | 104 | |
105 | 105 | /* |
106 | 106 | |-------------------------------------------------------------------------- |
@@ -118,176 +118,176 @@ discard block |
||
118 | 118 | */ |
119 | 119 | |
120 | 120 | /** |
121 | - * Get parent item ID. |
|
122 | - * |
|
123 | - * @since 1.0.19 |
|
124 | - * @param string $context View or edit context. |
|
125 | - * @return int |
|
126 | - */ |
|
127 | - public function get_parent_id( $context = 'view' ) { |
|
128 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
121 | + * Get parent item ID. |
|
122 | + * |
|
123 | + * @since 1.0.19 |
|
124 | + * @param string $context View or edit context. |
|
125 | + * @return int |
|
126 | + */ |
|
127 | + public function get_parent_id( $context = 'view' ) { |
|
128 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
132 | - * Get item status. |
|
133 | - * |
|
134 | - * @since 1.0.19 |
|
135 | - * @param string $context View or edit context. |
|
136 | - * @return string |
|
137 | - */ |
|
138 | - public function get_status( $context = 'view' ) { |
|
139 | - return $this->get_prop( 'status', $context ); |
|
132 | + * Get item status. |
|
133 | + * |
|
134 | + * @since 1.0.19 |
|
135 | + * @param string $context View or edit context. |
|
136 | + * @return string |
|
137 | + */ |
|
138 | + public function get_status( $context = 'view' ) { |
|
139 | + return $this->get_prop( 'status', $context ); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
143 | - * Get plugin version when the item was created. |
|
144 | - * |
|
145 | - * @since 1.0.19 |
|
146 | - * @param string $context View or edit context. |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public function get_version( $context = 'view' ) { |
|
150 | - return $this->get_prop( 'version', $context ); |
|
143 | + * Get plugin version when the item was created. |
|
144 | + * |
|
145 | + * @since 1.0.19 |
|
146 | + * @param string $context View or edit context. |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public function get_version( $context = 'view' ) { |
|
150 | + return $this->get_prop( 'version', $context ); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
154 | - * Get date when the item was created. |
|
155 | - * |
|
156 | - * @since 1.0.19 |
|
157 | - * @param string $context View or edit context. |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - public function get_date_created( $context = 'view' ) { |
|
161 | - return $this->get_prop( 'date_created', $context ); |
|
154 | + * Get date when the item was created. |
|
155 | + * |
|
156 | + * @since 1.0.19 |
|
157 | + * @param string $context View or edit context. |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + public function get_date_created( $context = 'view' ) { |
|
161 | + return $this->get_prop( 'date_created', $context ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
165 | - * Get GMT date when the item was created. |
|
166 | - * |
|
167 | - * @since 1.0.19 |
|
168 | - * @param string $context View or edit context. |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function get_date_created_gmt( $context = 'view' ) { |
|
165 | + * Get GMT date when the item was created. |
|
166 | + * |
|
167 | + * @since 1.0.19 |
|
168 | + * @param string $context View or edit context. |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function get_date_created_gmt( $context = 'view' ) { |
|
172 | 172 | $date = $this->get_date_created( $context ); |
173 | 173 | |
174 | 174 | if ( $date ) { |
175 | 175 | $date = get_gmt_from_date( $date ); |
176 | 176 | } |
177 | - return $date; |
|
177 | + return $date; |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
181 | - * Get date when the item was last modified. |
|
182 | - * |
|
183 | - * @since 1.0.19 |
|
184 | - * @param string $context View or edit context. |
|
185 | - * @return string |
|
186 | - */ |
|
187 | - public function get_date_modified( $context = 'view' ) { |
|
188 | - return $this->get_prop( 'date_modified', $context ); |
|
181 | + * Get date when the item was last modified. |
|
182 | + * |
|
183 | + * @since 1.0.19 |
|
184 | + * @param string $context View or edit context. |
|
185 | + * @return string |
|
186 | + */ |
|
187 | + public function get_date_modified( $context = 'view' ) { |
|
188 | + return $this->get_prop( 'date_modified', $context ); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | - * Get GMT date when the item was last modified. |
|
193 | - * |
|
194 | - * @since 1.0.19 |
|
195 | - * @param string $context View or edit context. |
|
196 | - * @return string |
|
197 | - */ |
|
198 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
192 | + * Get GMT date when the item was last modified. |
|
193 | + * |
|
194 | + * @since 1.0.19 |
|
195 | + * @param string $context View or edit context. |
|
196 | + * @return string |
|
197 | + */ |
|
198 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
199 | 199 | $date = $this->get_date_modified( $context ); |
200 | 200 | |
201 | 201 | if ( $date ) { |
202 | 202 | $date = get_gmt_from_date( $date ); |
203 | 203 | } |
204 | - return $date; |
|
204 | + return $date; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
208 | - * Get the item name. |
|
209 | - * |
|
210 | - * @since 1.0.19 |
|
211 | - * @param string $context View or edit context. |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - public function get_name( $context = 'view' ) { |
|
215 | - return $this->get_prop( 'name', $context ); |
|
208 | + * Get the item name. |
|
209 | + * |
|
210 | + * @since 1.0.19 |
|
211 | + * @param string $context View or edit context. |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + public function get_name( $context = 'view' ) { |
|
215 | + return $this->get_prop( 'name', $context ); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
219 | - * Alias of self::get_name(). |
|
220 | - * |
|
221 | - * @since 1.0.19 |
|
222 | - * @param string $context View or edit context. |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - public function get_title( $context = 'view' ) { |
|
226 | - return $this->get_name( $context ); |
|
219 | + * Alias of self::get_name(). |
|
220 | + * |
|
221 | + * @since 1.0.19 |
|
222 | + * @param string $context View or edit context. |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + public function get_title( $context = 'view' ) { |
|
226 | + return $this->get_name( $context ); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
230 | - * Get the item description. |
|
231 | - * |
|
232 | - * @since 1.0.19 |
|
233 | - * @param string $context View or edit context. |
|
234 | - * @return string |
|
235 | - */ |
|
236 | - public function get_description( $context = 'view' ) { |
|
237 | - return $this->get_prop( 'description', $context ); |
|
230 | + * Get the item description. |
|
231 | + * |
|
232 | + * @since 1.0.19 |
|
233 | + * @param string $context View or edit context. |
|
234 | + * @return string |
|
235 | + */ |
|
236 | + public function get_description( $context = 'view' ) { |
|
237 | + return $this->get_prop( 'description', $context ); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
241 | - * Alias of self::get_description(). |
|
242 | - * |
|
243 | - * @since 1.0.19 |
|
244 | - * @param string $context View or edit context. |
|
245 | - * @return string |
|
246 | - */ |
|
247 | - public function get_excerpt( $context = 'view' ) { |
|
248 | - return $this->get_description( $context ); |
|
241 | + * Alias of self::get_description(). |
|
242 | + * |
|
243 | + * @since 1.0.19 |
|
244 | + * @param string $context View or edit context. |
|
245 | + * @return string |
|
246 | + */ |
|
247 | + public function get_excerpt( $context = 'view' ) { |
|
248 | + return $this->get_description( $context ); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
252 | - * Alias of self::get_description(). |
|
253 | - * |
|
254 | - * @since 1.0.19 |
|
255 | - * @param string $context View or edit context. |
|
256 | - * @return string |
|
257 | - */ |
|
258 | - public function get_summary( $context = 'view' ) { |
|
259 | - return $this->get_description( $context ); |
|
252 | + * Alias of self::get_description(). |
|
253 | + * |
|
254 | + * @since 1.0.19 |
|
255 | + * @param string $context View or edit context. |
|
256 | + * @return string |
|
257 | + */ |
|
258 | + public function get_summary( $context = 'view' ) { |
|
259 | + return $this->get_description( $context ); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
263 | - * Get the owner of the item. |
|
264 | - * |
|
265 | - * @since 1.0.19 |
|
266 | - * @param string $context View or edit context. |
|
267 | - * @return string |
|
268 | - */ |
|
269 | - public function get_author( $context = 'view' ) { |
|
270 | - return (int) $this->get_prop( 'author', $context ); |
|
263 | + * Get the owner of the item. |
|
264 | + * |
|
265 | + * @since 1.0.19 |
|
266 | + * @param string $context View or edit context. |
|
267 | + * @return string |
|
268 | + */ |
|
269 | + public function get_author( $context = 'view' ) { |
|
270 | + return (int) $this->get_prop( 'author', $context ); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
274 | - * Get the price of the item. |
|
275 | - * |
|
276 | - * @since 1.0.19 |
|
277 | - * @param string $context View or edit context. |
|
278 | - * @return float |
|
279 | - */ |
|
280 | - public function get_price( $context = 'view' ) { |
|
274 | + * Get the price of the item. |
|
275 | + * |
|
276 | + * @since 1.0.19 |
|
277 | + * @param string $context View or edit context. |
|
278 | + * @return float |
|
279 | + */ |
|
280 | + public function get_price( $context = 'view' ) { |
|
281 | 281 | return (float) wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
285 | - * Returns a formated price. |
|
286 | - * |
|
287 | - * @since 1.0.19 |
|
288 | - * @param string $context View or edit context. |
|
289 | - * @return string |
|
290 | - */ |
|
285 | + * Returns a formated price. |
|
286 | + * |
|
287 | + * @since 1.0.19 |
|
288 | + * @param string $context View or edit context. |
|
289 | + * @return string |
|
290 | + */ |
|
291 | 291 | public function get_the_price() { |
292 | 292 | $item_price = wpinv_price( wpinv_format_amount( $this->get_price() ) ); |
293 | 293 | |
@@ -295,134 +295,134 @@ discard block |
||
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
298 | - * Get the VAT rule of the item. |
|
299 | - * |
|
300 | - * @since 1.0.19 |
|
301 | - * @param string $context View or edit context. |
|
302 | - * @return string |
|
303 | - */ |
|
304 | - public function get_vat_rule( $context = 'view' ) { |
|
298 | + * Get the VAT rule of the item. |
|
299 | + * |
|
300 | + * @since 1.0.19 |
|
301 | + * @param string $context View or edit context. |
|
302 | + * @return string |
|
303 | + */ |
|
304 | + public function get_vat_rule( $context = 'view' ) { |
|
305 | 305 | return $this->get_prop( 'vat_rule', $context ); |
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
309 | - * Get the VAT class of the item. |
|
310 | - * |
|
311 | - * @since 1.0.19 |
|
312 | - * @param string $context View or edit context. |
|
313 | - * @return string |
|
314 | - */ |
|
315 | - public function get_vat_class( $context = 'view' ) { |
|
309 | + * Get the VAT class of the item. |
|
310 | + * |
|
311 | + * @since 1.0.19 |
|
312 | + * @param string $context View or edit context. |
|
313 | + * @return string |
|
314 | + */ |
|
315 | + public function get_vat_class( $context = 'view' ) { |
|
316 | 316 | return $this->get_prop( 'vat_class', $context ); |
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
320 | - * Get the type of the item. |
|
321 | - * |
|
322 | - * @since 1.0.19 |
|
323 | - * @param string $context View or edit context. |
|
324 | - * @return string |
|
325 | - */ |
|
326 | - public function get_type( $context = 'view' ) { |
|
320 | + * Get the type of the item. |
|
321 | + * |
|
322 | + * @since 1.0.19 |
|
323 | + * @param string $context View or edit context. |
|
324 | + * @return string |
|
325 | + */ |
|
326 | + public function get_type( $context = 'view' ) { |
|
327 | 327 | return $this->get_prop( 'type', $context ); |
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
331 | - * Get the custom id of the item. |
|
332 | - * |
|
333 | - * @since 1.0.19 |
|
334 | - * @param string $context View or edit context. |
|
335 | - * @return string |
|
336 | - */ |
|
337 | - public function get_custom_id( $context = 'view' ) { |
|
331 | + * Get the custom id of the item. |
|
332 | + * |
|
333 | + * @since 1.0.19 |
|
334 | + * @param string $context View or edit context. |
|
335 | + * @return string |
|
336 | + */ |
|
337 | + public function get_custom_id( $context = 'view' ) { |
|
338 | 338 | return $this->get_prop( 'custom_id', $context ); |
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
342 | - * Get the custom name of the item. |
|
343 | - * |
|
344 | - * @since 1.0.19 |
|
345 | - * @param string $context View or edit context. |
|
346 | - * @return string |
|
347 | - */ |
|
348 | - public function get_custom_name( $context = 'view' ) { |
|
342 | + * Get the custom name of the item. |
|
343 | + * |
|
344 | + * @since 1.0.19 |
|
345 | + * @param string $context View or edit context. |
|
346 | + * @return string |
|
347 | + */ |
|
348 | + public function get_custom_name( $context = 'view' ) { |
|
349 | 349 | return $this->get_prop( 'custom_name', $context ); |
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
353 | - * Get the custom singular name of the item. |
|
354 | - * |
|
355 | - * @since 1.0.19 |
|
356 | - * @param string $context View or edit context. |
|
357 | - * @return string |
|
358 | - */ |
|
359 | - public function get_custom_singular_name( $context = 'view' ) { |
|
353 | + * Get the custom singular name of the item. |
|
354 | + * |
|
355 | + * @since 1.0.19 |
|
356 | + * @param string $context View or edit context. |
|
357 | + * @return string |
|
358 | + */ |
|
359 | + public function get_custom_singular_name( $context = 'view' ) { |
|
360 | 360 | return $this->get_prop( 'custom_singular_name', $context ); |
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
364 | - * Checks if an item is editable.. |
|
365 | - * |
|
366 | - * @since 1.0.19 |
|
367 | - * @param string $context View or edit context. |
|
368 | - * @return int |
|
369 | - */ |
|
370 | - public function get_is_editable( $context = 'view' ) { |
|
364 | + * Checks if an item is editable.. |
|
365 | + * |
|
366 | + * @since 1.0.19 |
|
367 | + * @param string $context View or edit context. |
|
368 | + * @return int |
|
369 | + */ |
|
370 | + public function get_is_editable( $context = 'view' ) { |
|
371 | 371 | return (int) $this->get_prop( 'is_editable', $context ); |
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
375 | - * Alias of self::get_is_editable(). |
|
376 | - * |
|
377 | - * @since 1.0.19 |
|
378 | - * @param string $context View or edit context. |
|
379 | - * @return int |
|
380 | - */ |
|
381 | - public function get_editable( $context = 'view' ) { |
|
382 | - return $this->get_is_editable( $context ); |
|
375 | + * Alias of self::get_is_editable(). |
|
376 | + * |
|
377 | + * @since 1.0.19 |
|
378 | + * @param string $context View or edit context. |
|
379 | + * @return int |
|
380 | + */ |
|
381 | + public function get_editable( $context = 'view' ) { |
|
382 | + return $this->get_is_editable( $context ); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | /** |
386 | - * Checks if dynamic pricing is enabled. |
|
387 | - * |
|
388 | - * @since 1.0.19 |
|
389 | - * @param string $context View or edit context. |
|
390 | - * @return int |
|
391 | - */ |
|
392 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
386 | + * Checks if dynamic pricing is enabled. |
|
387 | + * |
|
388 | + * @since 1.0.19 |
|
389 | + * @param string $context View or edit context. |
|
390 | + * @return int |
|
391 | + */ |
|
392 | + public function get_is_dynamic_pricing( $context = 'view' ) { |
|
393 | 393 | return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
397 | - * Returns the minimum price if dynamic pricing is enabled. |
|
398 | - * |
|
399 | - * @since 1.0.19 |
|
400 | - * @param string $context View or edit context. |
|
401 | - * @return float |
|
402 | - */ |
|
403 | - public function get_minimum_price( $context = 'view' ) { |
|
397 | + * Returns the minimum price if dynamic pricing is enabled. |
|
398 | + * |
|
399 | + * @since 1.0.19 |
|
400 | + * @param string $context View or edit context. |
|
401 | + * @return float |
|
402 | + */ |
|
403 | + public function get_minimum_price( $context = 'view' ) { |
|
404 | 404 | return (float) wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
405 | 405 | } |
406 | 406 | |
407 | 407 | /** |
408 | - * Checks if this is a recurring item. |
|
409 | - * |
|
410 | - * @since 1.0.19 |
|
411 | - * @param string $context View or edit context. |
|
412 | - * @return int |
|
413 | - */ |
|
414 | - public function get_is_recurring( $context = 'view' ) { |
|
408 | + * Checks if this is a recurring item. |
|
409 | + * |
|
410 | + * @since 1.0.19 |
|
411 | + * @param string $context View or edit context. |
|
412 | + * @return int |
|
413 | + */ |
|
414 | + public function get_is_recurring( $context = 'view' ) { |
|
415 | 415 | return (int) $this->get_prop( 'is_recurring', $context ); |
416 | 416 | } |
417 | 417 | |
418 | 418 | /** |
419 | - * Get the recurring period. |
|
420 | - * |
|
421 | - * @since 1.0.19 |
|
422 | - * @param bool $full Return abbreviation or in full. |
|
423 | - * @return string |
|
424 | - */ |
|
425 | - public function get_recurring_period( $full = false ) { |
|
419 | + * Get the recurring period. |
|
420 | + * |
|
421 | + * @since 1.0.19 |
|
422 | + * @param bool $full Return abbreviation or in full. |
|
423 | + * @return string |
|
424 | + */ |
|
425 | + public function get_recurring_period( $full = false ) { |
|
426 | 426 | $period = $this->get_prop( 'recurring_period', 'view' ); |
427 | 427 | |
428 | 428 | if ( $full && ! is_bool( $full ) ) { |
@@ -433,63 +433,63 @@ discard block |
||
433 | 433 | } |
434 | 434 | |
435 | 435 | /** |
436 | - * Get the recurring interval. |
|
437 | - * |
|
438 | - * @since 1.0.19 |
|
439 | - * @param string $context View or edit context. |
|
440 | - * @return int |
|
441 | - */ |
|
442 | - public function get_recurring_interval( $context = 'view' ) { |
|
443 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
436 | + * Get the recurring interval. |
|
437 | + * |
|
438 | + * @since 1.0.19 |
|
439 | + * @param string $context View or edit context. |
|
440 | + * @return int |
|
441 | + */ |
|
442 | + public function get_recurring_interval( $context = 'view' ) { |
|
443 | + $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
444 | 444 | |
445 | - if ( $interval < 1 ) { |
|
446 | - $interval = 1; |
|
447 | - } |
|
445 | + if ( $interval < 1 ) { |
|
446 | + $interval = 1; |
|
447 | + } |
|
448 | 448 | |
449 | 449 | return $interval; |
450 | 450 | } |
451 | 451 | |
452 | 452 | /** |
453 | - * Get the recurring limit. |
|
454 | - * |
|
455 | - * @since 1.0.19 |
|
456 | - * @param string $context View or edit context. |
|
457 | - * @return int |
|
458 | - */ |
|
459 | - public function get_recurring_limit( $context = 'view' ) { |
|
453 | + * Get the recurring limit. |
|
454 | + * |
|
455 | + * @since 1.0.19 |
|
456 | + * @param string $context View or edit context. |
|
457 | + * @return int |
|
458 | + */ |
|
459 | + public function get_recurring_limit( $context = 'view' ) { |
|
460 | 460 | return (int) $this->get_prop( 'recurring_limit', $context ); |
461 | 461 | } |
462 | 462 | |
463 | 463 | /** |
464 | - * Checks if we have a free trial. |
|
465 | - * |
|
466 | - * @since 1.0.19 |
|
467 | - * @param string $context View or edit context. |
|
468 | - * @return int |
|
469 | - */ |
|
470 | - public function get_is_free_trial( $context = 'view' ) { |
|
464 | + * Checks if we have a free trial. |
|
465 | + * |
|
466 | + * @since 1.0.19 |
|
467 | + * @param string $context View or edit context. |
|
468 | + * @return int |
|
469 | + */ |
|
470 | + public function get_is_free_trial( $context = 'view' ) { |
|
471 | 471 | return (int) $this->get_prop( 'is_free_trial', $context ); |
472 | 472 | } |
473 | 473 | |
474 | 474 | /** |
475 | - * Alias for self::get_is_free_trial(). |
|
476 | - * |
|
477 | - * @since 1.0.19 |
|
478 | - * @param string $context View or edit context. |
|
479 | - * @return int |
|
480 | - */ |
|
481 | - public function get_free_trial( $context = 'view' ) { |
|
475 | + * Alias for self::get_is_free_trial(). |
|
476 | + * |
|
477 | + * @since 1.0.19 |
|
478 | + * @param string $context View or edit context. |
|
479 | + * @return int |
|
480 | + */ |
|
481 | + public function get_free_trial( $context = 'view' ) { |
|
482 | 482 | return $this->get_is_free_trial( $context ); |
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
486 | - * Get the trial period. |
|
487 | - * |
|
488 | - * @since 1.0.19 |
|
489 | - * @param bool $full Return abbreviation or in full. |
|
490 | - * @return string |
|
491 | - */ |
|
492 | - public function get_trial_period( $full = false ) { |
|
486 | + * Get the trial period. |
|
487 | + * |
|
488 | + * @since 1.0.19 |
|
489 | + * @param bool $full Return abbreviation or in full. |
|
490 | + * @return string |
|
491 | + */ |
|
492 | + public function get_trial_period( $full = false ) { |
|
493 | 493 | $period = $this->get_prop( 'trial_period', 'view' ); |
494 | 494 | |
495 | 495 | if ( $full && ! is_bool( $full ) ) { |
@@ -500,13 +500,13 @@ discard block |
||
500 | 500 | } |
501 | 501 | |
502 | 502 | /** |
503 | - * Get the trial interval. |
|
504 | - * |
|
505 | - * @since 1.0.19 |
|
506 | - * @param string $context View or edit context. |
|
507 | - * @return int |
|
508 | - */ |
|
509 | - public function get_trial_interval( $context = 'view' ) { |
|
503 | + * Get the trial interval. |
|
504 | + * |
|
505 | + * @since 1.0.19 |
|
506 | + * @param string $context View or edit context. |
|
507 | + * @return int |
|
508 | + */ |
|
509 | + public function get_trial_interval( $context = 'view' ) { |
|
510 | 510 | return (int) $this->get_prop( 'trial_interval', $context ); |
511 | 511 | } |
512 | 512 | |
@@ -540,52 +540,52 @@ discard block |
||
540 | 540 | */ |
541 | 541 | |
542 | 542 | /** |
543 | - * Set parent order ID. |
|
544 | - * |
|
545 | - * @since 1.0.19 |
|
546 | - */ |
|
547 | - public function set_parent_id( $value ) { |
|
548 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
549 | - return; |
|
550 | - } |
|
551 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
552 | - } |
|
553 | - |
|
554 | - /** |
|
555 | - * Sets item status. |
|
556 | - * |
|
557 | - * @since 1.0.19 |
|
558 | - * @param string $status New status. |
|
559 | - * @return array details of change. |
|
560 | - */ |
|
561 | - public function set_status( $status ) { |
|
543 | + * Set parent order ID. |
|
544 | + * |
|
545 | + * @since 1.0.19 |
|
546 | + */ |
|
547 | + public function set_parent_id( $value ) { |
|
548 | + if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
549 | + return; |
|
550 | + } |
|
551 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
552 | + } |
|
553 | + |
|
554 | + /** |
|
555 | + * Sets item status. |
|
556 | + * |
|
557 | + * @since 1.0.19 |
|
558 | + * @param string $status New status. |
|
559 | + * @return array details of change. |
|
560 | + */ |
|
561 | + public function set_status( $status ) { |
|
562 | 562 | $old_status = $this->get_status(); |
563 | 563 | |
564 | 564 | $this->set_prop( 'status', $status ); |
565 | 565 | |
566 | - return array( |
|
567 | - 'from' => $old_status, |
|
568 | - 'to' => $status, |
|
569 | - ); |
|
566 | + return array( |
|
567 | + 'from' => $old_status, |
|
568 | + 'to' => $status, |
|
569 | + ); |
|
570 | 570 | } |
571 | 571 | |
572 | 572 | /** |
573 | - * Set plugin version when the item was created. |
|
574 | - * |
|
575 | - * @since 1.0.19 |
|
576 | - */ |
|
577 | - public function set_version( $value ) { |
|
578 | - $this->set_prop( 'version', $value ); |
|
573 | + * Set plugin version when the item was created. |
|
574 | + * |
|
575 | + * @since 1.0.19 |
|
576 | + */ |
|
577 | + public function set_version( $value ) { |
|
578 | + $this->set_prop( 'version', $value ); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | /** |
582 | - * Set date when the item was created. |
|
583 | - * |
|
584 | - * @since 1.0.19 |
|
585 | - * @param string $value Value to set. |
|
582 | + * Set date when the item was created. |
|
583 | + * |
|
584 | + * @since 1.0.19 |
|
585 | + * @param string $value Value to set. |
|
586 | 586 | * @return bool Whether or not the date was set. |
587 | - */ |
|
588 | - public function set_date_created( $value ) { |
|
587 | + */ |
|
588 | + public function set_date_created( $value ) { |
|
589 | 589 | $date = strtotime( $value ); |
590 | 590 | |
591 | 591 | if ( $date ) { |
@@ -598,13 +598,13 @@ discard block |
||
598 | 598 | } |
599 | 599 | |
600 | 600 | /** |
601 | - * Set date when the item was last modified. |
|
602 | - * |
|
603 | - * @since 1.0.19 |
|
604 | - * @param string $value Value to set. |
|
601 | + * Set date when the item was last modified. |
|
602 | + * |
|
603 | + * @since 1.0.19 |
|
604 | + * @param string $value Value to set. |
|
605 | 605 | * @return bool Whether or not the date was set. |
606 | - */ |
|
607 | - public function set_date_modified( $value ) { |
|
606 | + */ |
|
607 | + public function set_date_modified( $value ) { |
|
608 | 608 | $date = strtotime( $value ); |
609 | 609 | |
610 | 610 | if ( $date ) { |
@@ -617,105 +617,105 @@ discard block |
||
617 | 617 | } |
618 | 618 | |
619 | 619 | /** |
620 | - * Set the item name. |
|
621 | - * |
|
622 | - * @since 1.0.19 |
|
623 | - * @param string $value New name. |
|
624 | - */ |
|
625 | - public function set_name( $value ) { |
|
620 | + * Set the item name. |
|
621 | + * |
|
622 | + * @since 1.0.19 |
|
623 | + * @param string $value New name. |
|
624 | + */ |
|
625 | + public function set_name( $value ) { |
|
626 | 626 | $name = sanitize_text_field( $value ); |
627 | - $this->set_prop( 'name', $name ); |
|
627 | + $this->set_prop( 'name', $name ); |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | /** |
631 | - * Alias of self::set_name(). |
|
632 | - * |
|
633 | - * @since 1.0.19 |
|
634 | - * @param string $value New name. |
|
635 | - */ |
|
636 | - public function set_title( $value ) { |
|
637 | - $this->set_name( $value ); |
|
631 | + * Alias of self::set_name(). |
|
632 | + * |
|
633 | + * @since 1.0.19 |
|
634 | + * @param string $value New name. |
|
635 | + */ |
|
636 | + public function set_title( $value ) { |
|
637 | + $this->set_name( $value ); |
|
638 | 638 | } |
639 | 639 | |
640 | 640 | /** |
641 | - * Set the item description. |
|
642 | - * |
|
643 | - * @since 1.0.19 |
|
644 | - * @param string $value New description. |
|
645 | - */ |
|
646 | - public function set_description( $value ) { |
|
641 | + * Set the item description. |
|
642 | + * |
|
643 | + * @since 1.0.19 |
|
644 | + * @param string $value New description. |
|
645 | + */ |
|
646 | + public function set_description( $value ) { |
|
647 | 647 | $description = wp_kses_post( $value ); |
648 | - return $this->set_prop( 'description', $description ); |
|
648 | + return $this->set_prop( 'description', $description ); |
|
649 | 649 | } |
650 | 650 | |
651 | 651 | /** |
652 | - * Alias of self::set_description(). |
|
653 | - * |
|
654 | - * @since 1.0.19 |
|
655 | - * @param string $value New description. |
|
656 | - */ |
|
657 | - public function set_excerpt( $value ) { |
|
658 | - $this->set_description( $value ); |
|
652 | + * Alias of self::set_description(). |
|
653 | + * |
|
654 | + * @since 1.0.19 |
|
655 | + * @param string $value New description. |
|
656 | + */ |
|
657 | + public function set_excerpt( $value ) { |
|
658 | + $this->set_description( $value ); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | /** |
662 | - * Alias of self::set_description(). |
|
663 | - * |
|
664 | - * @since 1.0.19 |
|
665 | - * @param string $value New description. |
|
666 | - */ |
|
667 | - public function set_summary( $value ) { |
|
668 | - $this->set_description( $value ); |
|
662 | + * Alias of self::set_description(). |
|
663 | + * |
|
664 | + * @since 1.0.19 |
|
665 | + * @param string $value New description. |
|
666 | + */ |
|
667 | + public function set_summary( $value ) { |
|
668 | + $this->set_description( $value ); |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | /** |
672 | - * Set the owner of the item. |
|
673 | - * |
|
674 | - * @since 1.0.19 |
|
675 | - * @param int $value New author. |
|
676 | - */ |
|
677 | - public function set_author( $value ) { |
|
678 | - $this->set_prop( 'author', (int) $value ); |
|
672 | + * Set the owner of the item. |
|
673 | + * |
|
674 | + * @since 1.0.19 |
|
675 | + * @param int $value New author. |
|
676 | + */ |
|
677 | + public function set_author( $value ) { |
|
678 | + $this->set_prop( 'author', (int) $value ); |
|
679 | 679 | } |
680 | 680 | |
681 | 681 | /** |
682 | - * Set the price of the item. |
|
683 | - * |
|
684 | - * @since 1.0.19 |
|
685 | - * @param float $value New price. |
|
682 | + * Set the price of the item. |
|
683 | + * |
|
684 | + * @since 1.0.19 |
|
685 | + * @param float $value New price. |
|
686 | 686 | ] */ |
687 | - public function set_price( $value ) { |
|
687 | + public function set_price( $value ) { |
|
688 | 688 | $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
689 | 689 | } |
690 | 690 | |
691 | 691 | /** |
692 | - * Set the VAT rule of the item. |
|
693 | - * |
|
694 | - * @since 1.0.19 |
|
695 | - * @param string $value new rule. |
|
696 | - */ |
|
697 | - public function set_vat_rule( $value ) { |
|
692 | + * Set the VAT rule of the item. |
|
693 | + * |
|
694 | + * @since 1.0.19 |
|
695 | + * @param string $value new rule. |
|
696 | + */ |
|
697 | + public function set_vat_rule( $value ) { |
|
698 | 698 | $this->set_prop( 'vat_rule', $value ); |
699 | 699 | } |
700 | 700 | |
701 | 701 | /** |
702 | - * Set the VAT class of the item. |
|
703 | - * |
|
704 | - * @since 1.0.19 |
|
705 | - * @param string $value new class. |
|
706 | - */ |
|
707 | - public function set_vat_class( $value ) { |
|
702 | + * Set the VAT class of the item. |
|
703 | + * |
|
704 | + * @since 1.0.19 |
|
705 | + * @param string $value new class. |
|
706 | + */ |
|
707 | + public function set_vat_class( $value ) { |
|
708 | 708 | $this->set_prop( 'vat_class', $value ); |
709 | 709 | } |
710 | 710 | |
711 | 711 | /** |
712 | - * Set the type of the item. |
|
713 | - * |
|
714 | - * @since 1.0.19 |
|
715 | - * @param string $value new item type. |
|
716 | - * @return string |
|
717 | - */ |
|
718 | - public function set_type( $value ) { |
|
712 | + * Set the type of the item. |
|
713 | + * |
|
714 | + * @since 1.0.19 |
|
715 | + * @param string $value new item type. |
|
716 | + * @return string |
|
717 | + */ |
|
718 | + public function set_type( $value ) { |
|
719 | 719 | |
720 | 720 | if ( empty( $value ) ) { |
721 | 721 | $value = 'custom'; |
@@ -725,134 +725,134 @@ discard block |
||
725 | 725 | } |
726 | 726 | |
727 | 727 | /** |
728 | - * Set the custom id of the item. |
|
729 | - * |
|
730 | - * @since 1.0.19 |
|
731 | - * @param string $value new custom id. |
|
732 | - */ |
|
733 | - public function set_custom_id( $value ) { |
|
728 | + * Set the custom id of the item. |
|
729 | + * |
|
730 | + * @since 1.0.19 |
|
731 | + * @param string $value new custom id. |
|
732 | + */ |
|
733 | + public function set_custom_id( $value ) { |
|
734 | 734 | $this->set_prop( 'custom_id', $value ); |
735 | 735 | } |
736 | 736 | |
737 | 737 | /** |
738 | - * Set the custom name of the item. |
|
739 | - * |
|
740 | - * @since 1.0.19 |
|
741 | - * @param string $value new custom name. |
|
742 | - */ |
|
743 | - public function set_custom_name( $value ) { |
|
738 | + * Set the custom name of the item. |
|
739 | + * |
|
740 | + * @since 1.0.19 |
|
741 | + * @param string $value new custom name. |
|
742 | + */ |
|
743 | + public function set_custom_name( $value ) { |
|
744 | 744 | $this->set_prop( 'custom_name', $value ); |
745 | 745 | } |
746 | 746 | |
747 | 747 | /** |
748 | - * Set the custom singular name of the item. |
|
749 | - * |
|
750 | - * @since 1.0.19 |
|
751 | - * @param string $value new custom singular name. |
|
752 | - */ |
|
753 | - public function set_custom_singular_name( $value ) { |
|
748 | + * Set the custom singular name of the item. |
|
749 | + * |
|
750 | + * @since 1.0.19 |
|
751 | + * @param string $value new custom singular name. |
|
752 | + */ |
|
753 | + public function set_custom_singular_name( $value ) { |
|
754 | 754 | $this->set_prop( 'custom_singular_name', $value ); |
755 | 755 | } |
756 | 756 | |
757 | 757 | /** |
758 | - * Sets if an item is editable.. |
|
759 | - * |
|
760 | - * @since 1.0.19 |
|
761 | - * @param int|bool $value whether or not the item is editable. |
|
762 | - */ |
|
763 | - public function set_is_editable( $value ) { |
|
764 | - if ( is_numeric( $value ) ) { |
|
765 | - $this->set_prop( 'is_editable', (int) $value ); |
|
766 | - } |
|
758 | + * Sets if an item is editable.. |
|
759 | + * |
|
760 | + * @since 1.0.19 |
|
761 | + * @param int|bool $value whether or not the item is editable. |
|
762 | + */ |
|
763 | + public function set_is_editable( $value ) { |
|
764 | + if ( is_numeric( $value ) ) { |
|
765 | + $this->set_prop( 'is_editable', (int) $value ); |
|
766 | + } |
|
767 | 767 | } |
768 | 768 | |
769 | 769 | /** |
770 | - * Sets if dynamic pricing is enabled. |
|
771 | - * |
|
772 | - * @since 1.0.19 |
|
773 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
774 | - */ |
|
775 | - public function set_is_dynamic_pricing( $value ) { |
|
770 | + * Sets if dynamic pricing is enabled. |
|
771 | + * |
|
772 | + * @since 1.0.19 |
|
773 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
774 | + */ |
|
775 | + public function set_is_dynamic_pricing( $value ) { |
|
776 | 776 | $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
777 | 777 | } |
778 | 778 | |
779 | 779 | /** |
780 | - * Sets the minimum price if dynamic pricing is enabled. |
|
781 | - * |
|
782 | - * @since 1.0.19 |
|
783 | - * @param float $value minimum price. |
|
784 | - */ |
|
785 | - public function set_minimum_price( $value ) { |
|
780 | + * Sets the minimum price if dynamic pricing is enabled. |
|
781 | + * |
|
782 | + * @since 1.0.19 |
|
783 | + * @param float $value minimum price. |
|
784 | + */ |
|
785 | + public function set_minimum_price( $value ) { |
|
786 | 786 | $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
787 | 787 | } |
788 | 788 | |
789 | 789 | /** |
790 | - * Sets if this is a recurring item. |
|
791 | - * |
|
792 | - * @since 1.0.19 |
|
793 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
794 | - */ |
|
795 | - public function set_is_recurring( $value ) { |
|
790 | + * Sets if this is a recurring item. |
|
791 | + * |
|
792 | + * @since 1.0.19 |
|
793 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
794 | + */ |
|
795 | + public function set_is_recurring( $value ) { |
|
796 | 796 | $this->set_prop( 'is_recurring', (int) $value ); |
797 | 797 | } |
798 | 798 | |
799 | 799 | /** |
800 | - * Set the recurring period. |
|
801 | - * |
|
802 | - * @since 1.0.19 |
|
803 | - * @param string $value new period. |
|
804 | - */ |
|
805 | - public function set_recurring_period( $value ) { |
|
800 | + * Set the recurring period. |
|
801 | + * |
|
802 | + * @since 1.0.19 |
|
803 | + * @param string $value new period. |
|
804 | + */ |
|
805 | + public function set_recurring_period( $value ) { |
|
806 | 806 | $this->set_prop( 'recurring_period', $value ); |
807 | 807 | } |
808 | 808 | |
809 | 809 | /** |
810 | - * Set the recurring interval. |
|
811 | - * |
|
812 | - * @since 1.0.19 |
|
813 | - * @param int $value recurring interval. |
|
814 | - */ |
|
815 | - public function set_recurring_interval( $value ) { |
|
810 | + * Set the recurring interval. |
|
811 | + * |
|
812 | + * @since 1.0.19 |
|
813 | + * @param int $value recurring interval. |
|
814 | + */ |
|
815 | + public function set_recurring_interval( $value ) { |
|
816 | 816 | return $this->set_prop( 'recurring_interval', (int) $value ); |
817 | 817 | } |
818 | 818 | |
819 | 819 | /** |
820 | - * Get the recurring limit. |
|
821 | - * @since 1.0.19 |
|
822 | - * @param int $value The recurring limit. |
|
823 | - * @return int |
|
824 | - */ |
|
825 | - public function set_recurring_limit( $value ) { |
|
820 | + * Get the recurring limit. |
|
821 | + * @since 1.0.19 |
|
822 | + * @param int $value The recurring limit. |
|
823 | + * @return int |
|
824 | + */ |
|
825 | + public function set_recurring_limit( $value ) { |
|
826 | 826 | $this->set_prop( 'recurring_limit', (int) $value ); |
827 | 827 | } |
828 | 828 | |
829 | 829 | /** |
830 | - * Checks if we have a free trial. |
|
831 | - * |
|
832 | - * @since 1.0.19 |
|
833 | - * @param int|bool $value whether or not it has a free trial. |
|
834 | - */ |
|
835 | - public function set_is_free_trial( $value ) { |
|
830 | + * Checks if we have a free trial. |
|
831 | + * |
|
832 | + * @since 1.0.19 |
|
833 | + * @param int|bool $value whether or not it has a free trial. |
|
834 | + */ |
|
835 | + public function set_is_free_trial( $value ) { |
|
836 | 836 | $this->set_prop( 'is_free_trial', (int) $value ); |
837 | 837 | } |
838 | 838 | |
839 | 839 | /** |
840 | - * Set the trial period. |
|
841 | - * |
|
842 | - * @since 1.0.19 |
|
843 | - * @param string $value trial period. |
|
844 | - */ |
|
845 | - public function set_trial_period( $value ) { |
|
840 | + * Set the trial period. |
|
841 | + * |
|
842 | + * @since 1.0.19 |
|
843 | + * @param string $value trial period. |
|
844 | + */ |
|
845 | + public function set_trial_period( $value ) { |
|
846 | 846 | $this->set_prop( 'trial_period', $value ); |
847 | 847 | } |
848 | 848 | |
849 | 849 | /** |
850 | - * Set the trial interval. |
|
851 | - * |
|
852 | - * @since 1.0.19 |
|
853 | - * @param int $value trial interval. |
|
854 | - */ |
|
855 | - public function set_trial_interval( $value ) { |
|
850 | + * Set the trial interval. |
|
851 | + * |
|
852 | + * @since 1.0.19 |
|
853 | + * @param int $value trial interval. |
|
854 | + */ |
|
855 | + public function set_trial_interval( $value ) { |
|
856 | 856 | $this->set_prop( 'trial_interval', $value ); |
857 | 857 | } |
858 | 858 | |
@@ -860,17 +860,17 @@ discard block |
||
860 | 860 | * Create an item. For backwards compatibilty. |
861 | 861 | * |
862 | 862 | * @deprecated |
863 | - * @return int item id |
|
863 | + * @return int item id |
|
864 | 864 | */ |
865 | 865 | public function create( $data = array() ) { |
866 | 866 | |
867 | - // Set the properties. |
|
868 | - if ( is_array( $data ) ) { |
|
869 | - $this->set_props( $data ); |
|
870 | - } |
|
867 | + // Set the properties. |
|
868 | + if ( is_array( $data ) ) { |
|
869 | + $this->set_props( $data ); |
|
870 | + } |
|
871 | 871 | |
872 | - // Save the item. |
|
873 | - return $this->save(); |
|
872 | + // Save the item. |
|
873 | + return $this->save(); |
|
874 | 874 | |
875 | 875 | } |
876 | 876 | |
@@ -878,7 +878,7 @@ discard block |
||
878 | 878 | * Updates an item. For backwards compatibilty. |
879 | 879 | * |
880 | 880 | * @deprecated |
881 | - * @return int item id |
|
881 | + * @return int item id |
|
882 | 882 | */ |
883 | 883 | public function update( $data = array() ) { |
884 | 884 | return $this->create( $data ); |
@@ -894,84 +894,84 @@ discard block |
||
894 | 894 | */ |
895 | 895 | |
896 | 896 | /** |
897 | - * Checks whether the item has enabled dynamic pricing. |
|
898 | - * |
|
899 | - * @since 1.0.19 |
|
900 | - * @return bool |
|
901 | - */ |
|
902 | - public function user_can_set_their_price() { |
|
897 | + * Checks whether the item has enabled dynamic pricing. |
|
898 | + * |
|
899 | + * @since 1.0.19 |
|
900 | + * @return bool |
|
901 | + */ |
|
902 | + public function user_can_set_their_price() { |
|
903 | 903 | return (bool) $this->get_is_dynamic_pricing(); |
904 | - } |
|
904 | + } |
|
905 | 905 | |
906 | - /** |
|
907 | - * Checks whether the item is recurring. |
|
908 | - * |
|
909 | - * @since 1.0.19 |
|
910 | - * @return bool |
|
911 | - */ |
|
912 | - public function is_recurring() { |
|
906 | + /** |
|
907 | + * Checks whether the item is recurring. |
|
908 | + * |
|
909 | + * @since 1.0.19 |
|
910 | + * @return bool |
|
911 | + */ |
|
912 | + public function is_recurring() { |
|
913 | 913 | return (bool) $this->get_is_recurring(); |
914 | 914 | } |
915 | 915 | |
916 | 916 | /** |
917 | - * Checks whether the item has a free trial. |
|
918 | - * |
|
919 | - * @since 1.0.19 |
|
920 | - * @return bool |
|
921 | - */ |
|
917 | + * Checks whether the item has a free trial. |
|
918 | + * |
|
919 | + * @since 1.0.19 |
|
920 | + * @return bool |
|
921 | + */ |
|
922 | 922 | public function has_free_trial() { |
923 | 923 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
924 | 924 | return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
925 | 925 | } |
926 | 926 | |
927 | 927 | /** |
928 | - * Checks whether the item is free. |
|
929 | - * |
|
930 | - * @since 1.0.19 |
|
931 | - * @return bool |
|
932 | - */ |
|
928 | + * Checks whether the item is free. |
|
929 | + * |
|
930 | + * @since 1.0.19 |
|
931 | + * @return bool |
|
932 | + */ |
|
933 | 933 | public function is_free() { |
934 | 934 | $is_free = $this->get_price() == 0; |
935 | 935 | return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
936 | 936 | } |
937 | 937 | |
938 | 938 | /** |
939 | - * Checks the item status against a passed in status. |
|
940 | - * |
|
941 | - * @param array|string $status Status to check. |
|
942 | - * @return bool |
|
943 | - */ |
|
944 | - public function has_status( $status ) { |
|
945 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
946 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
939 | + * Checks the item status against a passed in status. |
|
940 | + * |
|
941 | + * @param array|string $status Status to check. |
|
942 | + * @return bool |
|
943 | + */ |
|
944 | + public function has_status( $status ) { |
|
945 | + $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
946 | + return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
947 | 947 | } |
948 | 948 | |
949 | 949 | /** |
950 | - * Checks the item type against a passed in types. |
|
951 | - * |
|
952 | - * @param array|string $type Type to check. |
|
953 | - * @return bool |
|
954 | - */ |
|
955 | - public function is_type( $type ) { |
|
956 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
957 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
958 | - } |
|
950 | + * Checks the item type against a passed in types. |
|
951 | + * |
|
952 | + * @param array|string $type Type to check. |
|
953 | + * @return bool |
|
954 | + */ |
|
955 | + public function is_type( $type ) { |
|
956 | + $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
957 | + return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
958 | + } |
|
959 | 959 | |
960 | 960 | /** |
961 | - * Checks whether the item is editable. |
|
962 | - * |
|
963 | - * @since 1.0.19 |
|
964 | - * @return bool |
|
965 | - */ |
|
961 | + * Checks whether the item is editable. |
|
962 | + * |
|
963 | + * @since 1.0.19 |
|
964 | + * @return bool |
|
965 | + */ |
|
966 | 966 | public function is_editable() { |
967 | 967 | $is_editable = $this->get_is_editable(); |
968 | 968 | return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
969 | - } |
|
969 | + } |
|
970 | 970 | |
971 | - /** |
|
972 | - * Returns an array of cart fees. |
|
973 | - */ |
|
974 | - public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
971 | + /** |
|
972 | + * Returns an array of cart fees. |
|
973 | + */ |
|
974 | + public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
975 | 975 | global $wpi_session; |
976 | 976 | |
977 | 977 | $fees = $wpi_session->get( 'wpi_cart_fees' ); |
@@ -1015,11 +1015,11 @@ discard block |
||
1015 | 1015 | } |
1016 | 1016 | |
1017 | 1017 | /** |
1018 | - * Checks whether the item is purchasable. |
|
1019 | - * |
|
1020 | - * @since 1.0.19 |
|
1021 | - * @return bool |
|
1022 | - */ |
|
1018 | + * Checks whether the item is purchasable. |
|
1019 | + * |
|
1020 | + * @since 1.0.19 |
|
1021 | + * @return bool |
|
1022 | + */ |
|
1023 | 1023 | public function can_purchase() { |
1024 | 1024 | $can_purchase = null !== $this->get_id(); |
1025 | 1025 | |
@@ -1031,11 +1031,11 @@ discard block |
||
1031 | 1031 | } |
1032 | 1032 | |
1033 | 1033 | /** |
1034 | - * Checks whether the item supports dynamic pricing. |
|
1035 | - * |
|
1036 | - * @since 1.0.19 |
|
1037 | - * @return bool |
|
1038 | - */ |
|
1034 | + * Checks whether the item supports dynamic pricing. |
|
1035 | + * |
|
1036 | + * @since 1.0.19 |
|
1037 | + * @return bool |
|
1038 | + */ |
|
1039 | 1039 | public function supports_dynamic_pricing() { |
1040 | 1040 | return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
1041 | 1041 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -78,26 +78,26 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @param int|object|WPInv_Item|WP_Post $item Item to read. |
80 | 80 | */ |
81 | - public function __construct( $item = 0 ) { |
|
82 | - parent::__construct( $item ); |
|
81 | + public function __construct($item = 0) { |
|
82 | + parent::__construct($item); |
|
83 | 83 | |
84 | - if ( is_numeric( $item ) && $item > 0 ) { |
|
85 | - $this->set_id( $item ); |
|
86 | - } elseif ( $item instanceof self ) { |
|
87 | - $this->set_id( $item->get_id() ); |
|
88 | - } elseif ( ! empty( $item->ID ) ) { |
|
89 | - $this->set_id( $item->ID ); |
|
84 | + if (is_numeric($item) && $item > 0) { |
|
85 | + $this->set_id($item); |
|
86 | + } elseif ($item instanceof self) { |
|
87 | + $this->set_id($item->get_id()); |
|
88 | + } elseif (!empty($item->ID)) { |
|
89 | + $this->set_id($item->ID); |
|
90 | 90 | } else { |
91 | - $this->set_object_read( true ); |
|
91 | + $this->set_object_read(true); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | // Load the datastore. |
95 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
95 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
96 | 96 | |
97 | - if ( $this->get_id() > 0 ) { |
|
98 | - $this->post = get_post( $this->get_id() ); |
|
97 | + if ($this->get_id() > 0) { |
|
98 | + $this->post = get_post($this->get_id()); |
|
99 | 99 | $this->ID = $this->get_id(); |
100 | - $this->data_store->read( $this ); |
|
100 | + $this->data_store->read($this); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @param string $context View or edit context. |
125 | 125 | * @return int |
126 | 126 | */ |
127 | - public function get_parent_id( $context = 'view' ) { |
|
128 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
127 | + public function get_parent_id($context = 'view') { |
|
128 | + return (int) $this->get_prop('parent_id', $context); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | * @param string $context View or edit context. |
136 | 136 | * @return string |
137 | 137 | */ |
138 | - public function get_status( $context = 'view' ) { |
|
139 | - return $this->get_prop( 'status', $context ); |
|
138 | + public function get_status($context = 'view') { |
|
139 | + return $this->get_prop('status', $context); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | * @param string $context View or edit context. |
147 | 147 | * @return string |
148 | 148 | */ |
149 | - public function get_version( $context = 'view' ) { |
|
150 | - return $this->get_prop( 'version', $context ); |
|
149 | + public function get_version($context = 'view') { |
|
150 | + return $this->get_prop('version', $context); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | * @param string $context View or edit context. |
158 | 158 | * @return string |
159 | 159 | */ |
160 | - public function get_date_created( $context = 'view' ) { |
|
161 | - return $this->get_prop( 'date_created', $context ); |
|
160 | + public function get_date_created($context = 'view') { |
|
161 | + return $this->get_prop('date_created', $context); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -168,11 +168,11 @@ discard block |
||
168 | 168 | * @param string $context View or edit context. |
169 | 169 | * @return string |
170 | 170 | */ |
171 | - public function get_date_created_gmt( $context = 'view' ) { |
|
172 | - $date = $this->get_date_created( $context ); |
|
171 | + public function get_date_created_gmt($context = 'view') { |
|
172 | + $date = $this->get_date_created($context); |
|
173 | 173 | |
174 | - if ( $date ) { |
|
175 | - $date = get_gmt_from_date( $date ); |
|
174 | + if ($date) { |
|
175 | + $date = get_gmt_from_date($date); |
|
176 | 176 | } |
177 | 177 | return $date; |
178 | 178 | } |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | * @param string $context View or edit context. |
185 | 185 | * @return string |
186 | 186 | */ |
187 | - public function get_date_modified( $context = 'view' ) { |
|
188 | - return $this->get_prop( 'date_modified', $context ); |
|
187 | + public function get_date_modified($context = 'view') { |
|
188 | + return $this->get_prop('date_modified', $context); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | * @param string $context View or edit context. |
196 | 196 | * @return string |
197 | 197 | */ |
198 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
199 | - $date = $this->get_date_modified( $context ); |
|
198 | + public function get_date_modified_gmt($context = 'view') { |
|
199 | + $date = $this->get_date_modified($context); |
|
200 | 200 | |
201 | - if ( $date ) { |
|
202 | - $date = get_gmt_from_date( $date ); |
|
201 | + if ($date) { |
|
202 | + $date = get_gmt_from_date($date); |
|
203 | 203 | } |
204 | 204 | return $date; |
205 | 205 | } |
@@ -211,8 +211,8 @@ discard block |
||
211 | 211 | * @param string $context View or edit context. |
212 | 212 | * @return string |
213 | 213 | */ |
214 | - public function get_name( $context = 'view' ) { |
|
215 | - return $this->get_prop( 'name', $context ); |
|
214 | + public function get_name($context = 'view') { |
|
215 | + return $this->get_prop('name', $context); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -222,8 +222,8 @@ discard block |
||
222 | 222 | * @param string $context View or edit context. |
223 | 223 | * @return string |
224 | 224 | */ |
225 | - public function get_title( $context = 'view' ) { |
|
226 | - return $this->get_name( $context ); |
|
225 | + public function get_title($context = 'view') { |
|
226 | + return $this->get_name($context); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -233,8 +233,8 @@ discard block |
||
233 | 233 | * @param string $context View or edit context. |
234 | 234 | * @return string |
235 | 235 | */ |
236 | - public function get_description( $context = 'view' ) { |
|
237 | - return $this->get_prop( 'description', $context ); |
|
236 | + public function get_description($context = 'view') { |
|
237 | + return $this->get_prop('description', $context); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -244,8 +244,8 @@ discard block |
||
244 | 244 | * @param string $context View or edit context. |
245 | 245 | * @return string |
246 | 246 | */ |
247 | - public function get_excerpt( $context = 'view' ) { |
|
248 | - return $this->get_description( $context ); |
|
247 | + public function get_excerpt($context = 'view') { |
|
248 | + return $this->get_description($context); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -255,8 +255,8 @@ discard block |
||
255 | 255 | * @param string $context View or edit context. |
256 | 256 | * @return string |
257 | 257 | */ |
258 | - public function get_summary( $context = 'view' ) { |
|
259 | - return $this->get_description( $context ); |
|
258 | + public function get_summary($context = 'view') { |
|
259 | + return $this->get_description($context); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -266,8 +266,8 @@ discard block |
||
266 | 266 | * @param string $context View or edit context. |
267 | 267 | * @return string |
268 | 268 | */ |
269 | - public function get_author( $context = 'view' ) { |
|
270 | - return (int) $this->get_prop( 'author', $context ); |
|
269 | + public function get_author($context = 'view') { |
|
270 | + return (int) $this->get_prop('author', $context); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | * @param string $context View or edit context. |
278 | 278 | * @return float |
279 | 279 | */ |
280 | - public function get_price( $context = 'view' ) { |
|
281 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
|
280 | + public function get_price($context = 'view') { |
|
281 | + return (float) wpinv_sanitize_amount($this->get_prop('price', $context)); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
@@ -289,9 +289,9 @@ discard block |
||
289 | 289 | * @return string |
290 | 290 | */ |
291 | 291 | public function get_the_price() { |
292 | - $item_price = wpinv_price( wpinv_format_amount( $this->get_price() ) ); |
|
292 | + $item_price = wpinv_price(wpinv_format_amount($this->get_price())); |
|
293 | 293 | |
294 | - return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID ); |
|
294 | + return apply_filters('wpinv_get_the_item_price', $item_price, $this->ID); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -301,8 +301,8 @@ discard block |
||
301 | 301 | * @param string $context View or edit context. |
302 | 302 | * @return string |
303 | 303 | */ |
304 | - public function get_vat_rule( $context = 'view' ) { |
|
305 | - return $this->get_prop( 'vat_rule', $context ); |
|
304 | + public function get_vat_rule($context = 'view') { |
|
305 | + return $this->get_prop('vat_rule', $context); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -312,8 +312,8 @@ discard block |
||
312 | 312 | * @param string $context View or edit context. |
313 | 313 | * @return string |
314 | 314 | */ |
315 | - public function get_vat_class( $context = 'view' ) { |
|
316 | - return $this->get_prop( 'vat_class', $context ); |
|
315 | + public function get_vat_class($context = 'view') { |
|
316 | + return $this->get_prop('vat_class', $context); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | * @param string $context View or edit context. |
324 | 324 | * @return string |
325 | 325 | */ |
326 | - public function get_type( $context = 'view' ) { |
|
327 | - return $this->get_prop( 'type', $context ); |
|
326 | + public function get_type($context = 'view') { |
|
327 | + return $this->get_prop('type', $context); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -334,8 +334,8 @@ discard block |
||
334 | 334 | * @param string $context View or edit context. |
335 | 335 | * @return string |
336 | 336 | */ |
337 | - public function get_custom_id( $context = 'view' ) { |
|
338 | - return $this->get_prop( 'custom_id', $context ); |
|
337 | + public function get_custom_id($context = 'view') { |
|
338 | + return $this->get_prop('custom_id', $context); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -345,8 +345,8 @@ discard block |
||
345 | 345 | * @param string $context View or edit context. |
346 | 346 | * @return string |
347 | 347 | */ |
348 | - public function get_custom_name( $context = 'view' ) { |
|
349 | - return $this->get_prop( 'custom_name', $context ); |
|
348 | + public function get_custom_name($context = 'view') { |
|
349 | + return $this->get_prop('custom_name', $context); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
@@ -356,8 +356,8 @@ discard block |
||
356 | 356 | * @param string $context View or edit context. |
357 | 357 | * @return string |
358 | 358 | */ |
359 | - public function get_custom_singular_name( $context = 'view' ) { |
|
360 | - return $this->get_prop( 'custom_singular_name', $context ); |
|
359 | + public function get_custom_singular_name($context = 'view') { |
|
360 | + return $this->get_prop('custom_singular_name', $context); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
@@ -367,8 +367,8 @@ discard block |
||
367 | 367 | * @param string $context View or edit context. |
368 | 368 | * @return int |
369 | 369 | */ |
370 | - public function get_is_editable( $context = 'view' ) { |
|
371 | - return (int) $this->get_prop( 'is_editable', $context ); |
|
370 | + public function get_is_editable($context = 'view') { |
|
371 | + return (int) $this->get_prop('is_editable', $context); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
@@ -378,8 +378,8 @@ discard block |
||
378 | 378 | * @param string $context View or edit context. |
379 | 379 | * @return int |
380 | 380 | */ |
381 | - public function get_editable( $context = 'view' ) { |
|
382 | - return $this->get_is_editable( $context ); |
|
381 | + public function get_editable($context = 'view') { |
|
382 | + return $this->get_is_editable($context); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | /** |
@@ -389,8 +389,8 @@ discard block |
||
389 | 389 | * @param string $context View or edit context. |
390 | 390 | * @return int |
391 | 391 | */ |
392 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
393 | - return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
|
392 | + public function get_is_dynamic_pricing($context = 'view') { |
|
393 | + return (int) $this->get_prop('is_dynamic_pricing', $context); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
@@ -400,8 +400,8 @@ discard block |
||
400 | 400 | * @param string $context View or edit context. |
401 | 401 | * @return float |
402 | 402 | */ |
403 | - public function get_minimum_price( $context = 'view' ) { |
|
404 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
|
403 | + public function get_minimum_price($context = 'view') { |
|
404 | + return (float) wpinv_sanitize_amount($this->get_prop('minimum_price', $context)); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | /** |
@@ -411,8 +411,8 @@ discard block |
||
411 | 411 | * @param string $context View or edit context. |
412 | 412 | * @return int |
413 | 413 | */ |
414 | - public function get_is_recurring( $context = 'view' ) { |
|
415 | - return (int) $this->get_prop( 'is_recurring', $context ); |
|
414 | + public function get_is_recurring($context = 'view') { |
|
415 | + return (int) $this->get_prop('is_recurring', $context); |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | /** |
@@ -422,14 +422,14 @@ discard block |
||
422 | 422 | * @param bool $full Return abbreviation or in full. |
423 | 423 | * @return string |
424 | 424 | */ |
425 | - public function get_recurring_period( $full = false ) { |
|
426 | - $period = $this->get_prop( 'recurring_period', 'view' ); |
|
425 | + public function get_recurring_period($full = false) { |
|
426 | + $period = $this->get_prop('recurring_period', 'view'); |
|
427 | 427 | |
428 | - if ( $full && ! is_bool( $full ) ) { |
|
428 | + if ($full && !is_bool($full)) { |
|
429 | 429 | $full = false; |
430 | 430 | } |
431 | 431 | |
432 | - return getpaid_sanitize_recurring_period( $period, $full ); |
|
432 | + return getpaid_sanitize_recurring_period($period, $full); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | /** |
@@ -439,10 +439,10 @@ discard block |
||
439 | 439 | * @param string $context View or edit context. |
440 | 440 | * @return int |
441 | 441 | */ |
442 | - public function get_recurring_interval( $context = 'view' ) { |
|
443 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
442 | + public function get_recurring_interval($context = 'view') { |
|
443 | + $interval = absint($this->get_prop('recurring_interval', $context)); |
|
444 | 444 | |
445 | - if ( $interval < 1 ) { |
|
445 | + if ($interval < 1) { |
|
446 | 446 | $interval = 1; |
447 | 447 | } |
448 | 448 | |
@@ -456,8 +456,8 @@ discard block |
||
456 | 456 | * @param string $context View or edit context. |
457 | 457 | * @return int |
458 | 458 | */ |
459 | - public function get_recurring_limit( $context = 'view' ) { |
|
460 | - return (int) $this->get_prop( 'recurring_limit', $context ); |
|
459 | + public function get_recurring_limit($context = 'view') { |
|
460 | + return (int) $this->get_prop('recurring_limit', $context); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | /** |
@@ -467,8 +467,8 @@ discard block |
||
467 | 467 | * @param string $context View or edit context. |
468 | 468 | * @return int |
469 | 469 | */ |
470 | - public function get_is_free_trial( $context = 'view' ) { |
|
471 | - return (int) $this->get_prop( 'is_free_trial', $context ); |
|
470 | + public function get_is_free_trial($context = 'view') { |
|
471 | + return (int) $this->get_prop('is_free_trial', $context); |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | /** |
@@ -478,8 +478,8 @@ discard block |
||
478 | 478 | * @param string $context View or edit context. |
479 | 479 | * @return int |
480 | 480 | */ |
481 | - public function get_free_trial( $context = 'view' ) { |
|
482 | - return $this->get_is_free_trial( $context ); |
|
481 | + public function get_free_trial($context = 'view') { |
|
482 | + return $this->get_is_free_trial($context); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
@@ -489,14 +489,14 @@ discard block |
||
489 | 489 | * @param bool $full Return abbreviation or in full. |
490 | 490 | * @return string |
491 | 491 | */ |
492 | - public function get_trial_period( $full = false ) { |
|
493 | - $period = $this->get_prop( 'trial_period', 'view' ); |
|
492 | + public function get_trial_period($full = false) { |
|
493 | + $period = $this->get_prop('trial_period', 'view'); |
|
494 | 494 | |
495 | - if ( $full && ! is_bool( $full ) ) { |
|
495 | + if ($full && !is_bool($full)) { |
|
496 | 496 | $full = false; |
497 | 497 | } |
498 | 498 | |
499 | - return getpaid_sanitize_recurring_period( $period, $full ); |
|
499 | + return getpaid_sanitize_recurring_period($period, $full); |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | /** |
@@ -506,26 +506,26 @@ discard block |
||
506 | 506 | * @param string $context View or edit context. |
507 | 507 | * @return int |
508 | 508 | */ |
509 | - public function get_trial_interval( $context = 'view' ) { |
|
510 | - return (int) $this->get_prop( 'trial_interval', $context ); |
|
509 | + public function get_trial_interval($context = 'view') { |
|
510 | + return (int) $this->get_prop('trial_interval', $context); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | /** |
514 | 514 | * Margic method for retrieving a property. |
515 | 515 | */ |
516 | - public function __get( $key ) { |
|
516 | + public function __get($key) { |
|
517 | 517 | |
518 | 518 | // Check if we have a helper method for that. |
519 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
520 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
519 | + if (method_exists($this, 'get_' . $key)) { |
|
520 | + return call_user_func(array($this, 'get_' . $key)); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | // Check if the key is in the associated $post object. |
524 | - if ( ! empty( $this->post ) && isset( $this->post->$key ) ) { |
|
524 | + if (!empty($this->post) && isset($this->post->$key)) { |
|
525 | 525 | return $this->post->$key; |
526 | 526 | } |
527 | 527 | |
528 | - return $this->get_prop( $key ); |
|
528 | + return $this->get_prop($key); |
|
529 | 529 | |
530 | 530 | } |
531 | 531 | |
@@ -544,11 +544,11 @@ discard block |
||
544 | 544 | * |
545 | 545 | * @since 1.0.19 |
546 | 546 | */ |
547 | - public function set_parent_id( $value ) { |
|
548 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
547 | + public function set_parent_id($value) { |
|
548 | + if ($value && ($value === $this->get_id() || !get_post($value))) { |
|
549 | 549 | return; |
550 | 550 | } |
551 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
551 | + $this->set_prop('parent_id', absint($value)); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | /** |
@@ -558,10 +558,10 @@ discard block |
||
558 | 558 | * @param string $status New status. |
559 | 559 | * @return array details of change. |
560 | 560 | */ |
561 | - public function set_status( $status ) { |
|
561 | + public function set_status($status) { |
|
562 | 562 | $old_status = $this->get_status(); |
563 | 563 | |
564 | - $this->set_prop( 'status', $status ); |
|
564 | + $this->set_prop('status', $status); |
|
565 | 565 | |
566 | 566 | return array( |
567 | 567 | 'from' => $old_status, |
@@ -574,8 +574,8 @@ discard block |
||
574 | 574 | * |
575 | 575 | * @since 1.0.19 |
576 | 576 | */ |
577 | - public function set_version( $value ) { |
|
578 | - $this->set_prop( 'version', $value ); |
|
577 | + public function set_version($value) { |
|
578 | + $this->set_prop('version', $value); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | /** |
@@ -585,11 +585,11 @@ discard block |
||
585 | 585 | * @param string $value Value to set. |
586 | 586 | * @return bool Whether or not the date was set. |
587 | 587 | */ |
588 | - public function set_date_created( $value ) { |
|
589 | - $date = strtotime( $value ); |
|
588 | + public function set_date_created($value) { |
|
589 | + $date = strtotime($value); |
|
590 | 590 | |
591 | - if ( $date ) { |
|
592 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
591 | + if ($date) { |
|
592 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
593 | 593 | return true; |
594 | 594 | } |
595 | 595 | |
@@ -604,11 +604,11 @@ discard block |
||
604 | 604 | * @param string $value Value to set. |
605 | 605 | * @return bool Whether or not the date was set. |
606 | 606 | */ |
607 | - public function set_date_modified( $value ) { |
|
608 | - $date = strtotime( $value ); |
|
607 | + public function set_date_modified($value) { |
|
608 | + $date = strtotime($value); |
|
609 | 609 | |
610 | - if ( $date ) { |
|
611 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
610 | + if ($date) { |
|
611 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
612 | 612 | return true; |
613 | 613 | } |
614 | 614 | |
@@ -622,9 +622,9 @@ discard block |
||
622 | 622 | * @since 1.0.19 |
623 | 623 | * @param string $value New name. |
624 | 624 | */ |
625 | - public function set_name( $value ) { |
|
626 | - $name = sanitize_text_field( $value ); |
|
627 | - $this->set_prop( 'name', $name ); |
|
625 | + public function set_name($value) { |
|
626 | + $name = sanitize_text_field($value); |
|
627 | + $this->set_prop('name', $name); |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | /** |
@@ -633,8 +633,8 @@ discard block |
||
633 | 633 | * @since 1.0.19 |
634 | 634 | * @param string $value New name. |
635 | 635 | */ |
636 | - public function set_title( $value ) { |
|
637 | - $this->set_name( $value ); |
|
636 | + public function set_title($value) { |
|
637 | + $this->set_name($value); |
|
638 | 638 | } |
639 | 639 | |
640 | 640 | /** |
@@ -643,9 +643,9 @@ discard block |
||
643 | 643 | * @since 1.0.19 |
644 | 644 | * @param string $value New description. |
645 | 645 | */ |
646 | - public function set_description( $value ) { |
|
647 | - $description = wp_kses_post( $value ); |
|
648 | - return $this->set_prop( 'description', $description ); |
|
646 | + public function set_description($value) { |
|
647 | + $description = wp_kses_post($value); |
|
648 | + return $this->set_prop('description', $description); |
|
649 | 649 | } |
650 | 650 | |
651 | 651 | /** |
@@ -654,8 +654,8 @@ discard block |
||
654 | 654 | * @since 1.0.19 |
655 | 655 | * @param string $value New description. |
656 | 656 | */ |
657 | - public function set_excerpt( $value ) { |
|
658 | - $this->set_description( $value ); |
|
657 | + public function set_excerpt($value) { |
|
658 | + $this->set_description($value); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | /** |
@@ -664,8 +664,8 @@ discard block |
||
664 | 664 | * @since 1.0.19 |
665 | 665 | * @param string $value New description. |
666 | 666 | */ |
667 | - public function set_summary( $value ) { |
|
668 | - $this->set_description( $value ); |
|
667 | + public function set_summary($value) { |
|
668 | + $this->set_description($value); |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | /** |
@@ -674,8 +674,8 @@ discard block |
||
674 | 674 | * @since 1.0.19 |
675 | 675 | * @param int $value New author. |
676 | 676 | */ |
677 | - public function set_author( $value ) { |
|
678 | - $this->set_prop( 'author', (int) $value ); |
|
677 | + public function set_author($value) { |
|
678 | + $this->set_prop('author', (int) $value); |
|
679 | 679 | } |
680 | 680 | |
681 | 681 | /** |
@@ -684,8 +684,8 @@ discard block |
||
684 | 684 | * @since 1.0.19 |
685 | 685 | * @param float $value New price. |
686 | 686 | ] */ |
687 | - public function set_price( $value ) { |
|
688 | - $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
|
687 | + public function set_price($value) { |
|
688 | + $this->set_prop('price', (float) wpinv_sanitize_amount($value)); |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | /** |
@@ -694,8 +694,8 @@ discard block |
||
694 | 694 | * @since 1.0.19 |
695 | 695 | * @param string $value new rule. |
696 | 696 | */ |
697 | - public function set_vat_rule( $value ) { |
|
698 | - $this->set_prop( 'vat_rule', $value ); |
|
697 | + public function set_vat_rule($value) { |
|
698 | + $this->set_prop('vat_rule', $value); |
|
699 | 699 | } |
700 | 700 | |
701 | 701 | /** |
@@ -704,8 +704,8 @@ discard block |
||
704 | 704 | * @since 1.0.19 |
705 | 705 | * @param string $value new class. |
706 | 706 | */ |
707 | - public function set_vat_class( $value ) { |
|
708 | - $this->set_prop( 'vat_class', $value ); |
|
707 | + public function set_vat_class($value) { |
|
708 | + $this->set_prop('vat_class', $value); |
|
709 | 709 | } |
710 | 710 | |
711 | 711 | /** |
@@ -715,13 +715,13 @@ discard block |
||
715 | 715 | * @param string $value new item type. |
716 | 716 | * @return string |
717 | 717 | */ |
718 | - public function set_type( $value ) { |
|
718 | + public function set_type($value) { |
|
719 | 719 | |
720 | - if ( empty( $value ) ) { |
|
720 | + if (empty($value)) { |
|
721 | 721 | $value = 'custom'; |
722 | 722 | } |
723 | 723 | |
724 | - $this->set_prop( 'type', $value ); |
|
724 | + $this->set_prop('type', $value); |
|
725 | 725 | } |
726 | 726 | |
727 | 727 | /** |
@@ -730,8 +730,8 @@ discard block |
||
730 | 730 | * @since 1.0.19 |
731 | 731 | * @param string $value new custom id. |
732 | 732 | */ |
733 | - public function set_custom_id( $value ) { |
|
734 | - $this->set_prop( 'custom_id', $value ); |
|
733 | + public function set_custom_id($value) { |
|
734 | + $this->set_prop('custom_id', $value); |
|
735 | 735 | } |
736 | 736 | |
737 | 737 | /** |
@@ -740,8 +740,8 @@ discard block |
||
740 | 740 | * @since 1.0.19 |
741 | 741 | * @param string $value new custom name. |
742 | 742 | */ |
743 | - public function set_custom_name( $value ) { |
|
744 | - $this->set_prop( 'custom_name', $value ); |
|
743 | + public function set_custom_name($value) { |
|
744 | + $this->set_prop('custom_name', $value); |
|
745 | 745 | } |
746 | 746 | |
747 | 747 | /** |
@@ -750,8 +750,8 @@ discard block |
||
750 | 750 | * @since 1.0.19 |
751 | 751 | * @param string $value new custom singular name. |
752 | 752 | */ |
753 | - public function set_custom_singular_name( $value ) { |
|
754 | - $this->set_prop( 'custom_singular_name', $value ); |
|
753 | + public function set_custom_singular_name($value) { |
|
754 | + $this->set_prop('custom_singular_name', $value); |
|
755 | 755 | } |
756 | 756 | |
757 | 757 | /** |
@@ -760,9 +760,9 @@ discard block |
||
760 | 760 | * @since 1.0.19 |
761 | 761 | * @param int|bool $value whether or not the item is editable. |
762 | 762 | */ |
763 | - public function set_is_editable( $value ) { |
|
764 | - if ( is_numeric( $value ) ) { |
|
765 | - $this->set_prop( 'is_editable', (int) $value ); |
|
763 | + public function set_is_editable($value) { |
|
764 | + if (is_numeric($value)) { |
|
765 | + $this->set_prop('is_editable', (int) $value); |
|
766 | 766 | } |
767 | 767 | } |
768 | 768 | |
@@ -772,8 +772,8 @@ discard block |
||
772 | 772 | * @since 1.0.19 |
773 | 773 | * @param int|bool $value whether or not dynamic pricing is allowed. |
774 | 774 | */ |
775 | - public function set_is_dynamic_pricing( $value ) { |
|
776 | - $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
|
775 | + public function set_is_dynamic_pricing($value) { |
|
776 | + $this->set_prop('is_dynamic_pricing', (int) $value); |
|
777 | 777 | } |
778 | 778 | |
779 | 779 | /** |
@@ -782,8 +782,8 @@ discard block |
||
782 | 782 | * @since 1.0.19 |
783 | 783 | * @param float $value minimum price. |
784 | 784 | */ |
785 | - public function set_minimum_price( $value ) { |
|
786 | - $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
|
785 | + public function set_minimum_price($value) { |
|
786 | + $this->set_prop('minimum_price', (float) wpinv_sanitize_amount($value)); |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | /** |
@@ -792,8 +792,8 @@ discard block |
||
792 | 792 | * @since 1.0.19 |
793 | 793 | * @param int|bool $value whether or not dynamic pricing is allowed. |
794 | 794 | */ |
795 | - public function set_is_recurring( $value ) { |
|
796 | - $this->set_prop( 'is_recurring', (int) $value ); |
|
795 | + public function set_is_recurring($value) { |
|
796 | + $this->set_prop('is_recurring', (int) $value); |
|
797 | 797 | } |
798 | 798 | |
799 | 799 | /** |
@@ -802,8 +802,8 @@ discard block |
||
802 | 802 | * @since 1.0.19 |
803 | 803 | * @param string $value new period. |
804 | 804 | */ |
805 | - public function set_recurring_period( $value ) { |
|
806 | - $this->set_prop( 'recurring_period', $value ); |
|
805 | + public function set_recurring_period($value) { |
|
806 | + $this->set_prop('recurring_period', $value); |
|
807 | 807 | } |
808 | 808 | |
809 | 809 | /** |
@@ -812,8 +812,8 @@ discard block |
||
812 | 812 | * @since 1.0.19 |
813 | 813 | * @param int $value recurring interval. |
814 | 814 | */ |
815 | - public function set_recurring_interval( $value ) { |
|
816 | - return $this->set_prop( 'recurring_interval', (int) $value ); |
|
815 | + public function set_recurring_interval($value) { |
|
816 | + return $this->set_prop('recurring_interval', (int) $value); |
|
817 | 817 | } |
818 | 818 | |
819 | 819 | /** |
@@ -822,8 +822,8 @@ discard block |
||
822 | 822 | * @param int $value The recurring limit. |
823 | 823 | * @return int |
824 | 824 | */ |
825 | - public function set_recurring_limit( $value ) { |
|
826 | - $this->set_prop( 'recurring_limit', (int) $value ); |
|
825 | + public function set_recurring_limit($value) { |
|
826 | + $this->set_prop('recurring_limit', (int) $value); |
|
827 | 827 | } |
828 | 828 | |
829 | 829 | /** |
@@ -832,8 +832,8 @@ discard block |
||
832 | 832 | * @since 1.0.19 |
833 | 833 | * @param int|bool $value whether or not it has a free trial. |
834 | 834 | */ |
835 | - public function set_is_free_trial( $value ) { |
|
836 | - $this->set_prop( 'is_free_trial', (int) $value ); |
|
835 | + public function set_is_free_trial($value) { |
|
836 | + $this->set_prop('is_free_trial', (int) $value); |
|
837 | 837 | } |
838 | 838 | |
839 | 839 | /** |
@@ -842,8 +842,8 @@ discard block |
||
842 | 842 | * @since 1.0.19 |
843 | 843 | * @param string $value trial period. |
844 | 844 | */ |
845 | - public function set_trial_period( $value ) { |
|
846 | - $this->set_prop( 'trial_period', $value ); |
|
845 | + public function set_trial_period($value) { |
|
846 | + $this->set_prop('trial_period', $value); |
|
847 | 847 | } |
848 | 848 | |
849 | 849 | /** |
@@ -852,8 +852,8 @@ discard block |
||
852 | 852 | * @since 1.0.19 |
853 | 853 | * @param int $value trial interval. |
854 | 854 | */ |
855 | - public function set_trial_interval( $value ) { |
|
856 | - $this->set_prop( 'trial_interval', $value ); |
|
855 | + public function set_trial_interval($value) { |
|
856 | + $this->set_prop('trial_interval', $value); |
|
857 | 857 | } |
858 | 858 | |
859 | 859 | /** |
@@ -862,11 +862,11 @@ discard block |
||
862 | 862 | * @deprecated |
863 | 863 | * @return int item id |
864 | 864 | */ |
865 | - public function create( $data = array() ) { |
|
865 | + public function create($data = array()) { |
|
866 | 866 | |
867 | 867 | // Set the properties. |
868 | - if ( is_array( $data ) ) { |
|
869 | - $this->set_props( $data ); |
|
868 | + if (is_array($data)) { |
|
869 | + $this->set_props($data); |
|
870 | 870 | } |
871 | 871 | |
872 | 872 | // Save the item. |
@@ -880,8 +880,8 @@ discard block |
||
880 | 880 | * @deprecated |
881 | 881 | * @return int item id |
882 | 882 | */ |
883 | - public function update( $data = array() ) { |
|
884 | - return $this->create( $data ); |
|
883 | + public function update($data = array()) { |
|
884 | + return $this->create($data); |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | /* |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | */ |
922 | 922 | public function has_free_trial() { |
923 | 923 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
924 | - return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
|
924 | + return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this); |
|
925 | 925 | } |
926 | 926 | |
927 | 927 | /** |
@@ -931,8 +931,8 @@ discard block |
||
931 | 931 | * @return bool |
932 | 932 | */ |
933 | 933 | public function is_free() { |
934 | - $is_free = $this->get_price() == 0; |
|
935 | - return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
|
934 | + $is_free = $this->get_price() == 0; |
|
935 | + return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID, $this); |
|
936 | 936 | } |
937 | 937 | |
938 | 938 | /** |
@@ -941,9 +941,9 @@ discard block |
||
941 | 941 | * @param array|string $status Status to check. |
942 | 942 | * @return bool |
943 | 943 | */ |
944 | - public function has_status( $status ) { |
|
945 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
946 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
944 | + public function has_status($status) { |
|
945 | + $has_status = (is_array($status) && in_array($this->get_status(), $status, true)) || $this->get_status() === $status; |
|
946 | + return (bool) apply_filters('getpaid_item_has_status', $has_status, $this, $status); |
|
947 | 947 | } |
948 | 948 | |
949 | 949 | /** |
@@ -952,9 +952,9 @@ discard block |
||
952 | 952 | * @param array|string $type Type to check. |
953 | 953 | * @return bool |
954 | 954 | */ |
955 | - public function is_type( $type ) { |
|
956 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
957 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
955 | + public function is_type($type) { |
|
956 | + $is_type = (is_array($type) && in_array($this->get_type(), $type, true)) || $this->get_type() === $type; |
|
957 | + return (bool) apply_filters('getpaid_item_is_type', $is_type, $this, $type); |
|
958 | 958 | } |
959 | 959 | |
960 | 960 | /** |
@@ -965,53 +965,53 @@ discard block |
||
965 | 965 | */ |
966 | 966 | public function is_editable() { |
967 | 967 | $is_editable = $this->get_is_editable(); |
968 | - return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
|
968 | + return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID, $this); |
|
969 | 969 | } |
970 | 970 | |
971 | 971 | /** |
972 | 972 | * Returns an array of cart fees. |
973 | 973 | */ |
974 | - public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
974 | + public function get_fees($type = 'fee', $item_id = 0) { |
|
975 | 975 | global $wpi_session; |
976 | 976 | |
977 | - $fees = $wpi_session->get( 'wpi_cart_fees' ); |
|
977 | + $fees = $wpi_session->get('wpi_cart_fees'); |
|
978 | 978 | |
979 | - if ( ! wpinv_get_cart_contents() ) { |
|
979 | + if (!wpinv_get_cart_contents()) { |
|
980 | 980 | // We can only get item type fees when the cart is empty |
981 | 981 | $type = 'custom'; |
982 | 982 | } |
983 | 983 | |
984 | - if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) { |
|
985 | - foreach( $fees as $key => $fee ) { |
|
986 | - if( ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
987 | - unset( $fees[ $key ] ); |
|
984 | + if (!empty($fees) && !empty($type) && 'all' !== $type) { |
|
985 | + foreach ($fees as $key => $fee) { |
|
986 | + if (!empty($fee['type']) && $type != $fee['type']) { |
|
987 | + unset($fees[$key]); |
|
988 | 988 | } |
989 | 989 | } |
990 | 990 | } |
991 | 991 | |
992 | - if ( ! empty( $fees ) && ! empty( $item_id ) ) { |
|
992 | + if (!empty($fees) && !empty($item_id)) { |
|
993 | 993 | // Remove fees that don't belong to the specified Item |
994 | - foreach ( $fees as $key => $fee ) { |
|
995 | - if ( (int) $item_id !== (int)$fee['custom_id'] ) { |
|
996 | - unset( $fees[ $key ] ); |
|
994 | + foreach ($fees as $key => $fee) { |
|
995 | + if ((int) $item_id !== (int) $fee['custom_id']) { |
|
996 | + unset($fees[$key]); |
|
997 | 997 | } |
998 | 998 | } |
999 | 999 | } |
1000 | 1000 | |
1001 | - if ( ! empty( $fees ) ) { |
|
1001 | + if (!empty($fees)) { |
|
1002 | 1002 | // Remove fees that belong to a specific item but are not in the cart |
1003 | - foreach( $fees as $key => $fee ) { |
|
1004 | - if( empty( $fee['custom_id'] ) ) { |
|
1003 | + foreach ($fees as $key => $fee) { |
|
1004 | + if (empty($fee['custom_id'])) { |
|
1005 | 1005 | continue; |
1006 | 1006 | } |
1007 | 1007 | |
1008 | - if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) { |
|
1009 | - unset( $fees[ $key ] ); |
|
1008 | + if (!wpinv_item_in_cart($fee['custom_id'])) { |
|
1009 | + unset($fees[$key]); |
|
1010 | 1010 | } |
1011 | 1011 | } |
1012 | 1012 | } |
1013 | 1013 | |
1014 | - return ! empty( $fees ) ? $fees : array(); |
|
1014 | + return !empty($fees) ? $fees : array(); |
|
1015 | 1015 | } |
1016 | 1016 | |
1017 | 1017 | /** |
@@ -1023,11 +1023,11 @@ discard block |
||
1023 | 1023 | public function can_purchase() { |
1024 | 1024 | $can_purchase = null !== $this->get_id(); |
1025 | 1025 | |
1026 | - if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) { |
|
1026 | + if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') { |
|
1027 | 1027 | $can_purchase = false; |
1028 | 1028 | } |
1029 | 1029 | |
1030 | - return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this ); |
|
1030 | + return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this); |
|
1031 | 1031 | } |
1032 | 1032 | |
1033 | 1033 | /** |
@@ -1037,6 +1037,6 @@ discard block |
||
1037 | 1037 | * @return bool |
1038 | 1038 | */ |
1039 | 1039 | public function supports_dynamic_pricing() { |
1040 | - return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
|
1040 | + return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this); |
|
1041 | 1041 | } |
1042 | 1042 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,43 +21,43 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | global $wpinv_euvat, $ajax_cart_details; |
26 | 26 | |
27 | - $post_id = !empty( $post->ID ) ? $post->ID : 0; |
|
28 | - $invoice = new WPInv_Invoice( $post_id ); |
|
27 | + $post_id = !empty($post->ID) ? $post->ID : 0; |
|
28 | + $invoice = new WPInv_Invoice($post_id); |
|
29 | 29 | $ajax_cart_details = $invoice->get_cart_details(); |
30 | - $subtotal = $invoice->get_subtotal( true ); |
|
30 | + $subtotal = $invoice->get_subtotal(true); |
|
31 | 31 | $discount_raw = $invoice->get_discount(); |
32 | - $discount = wpinv_price( $discount_raw, $invoice->get_currency() ); |
|
32 | + $discount = wpinv_price($discount_raw, $invoice->get_currency()); |
|
33 | 33 | $discounts = $discount_raw > 0 ? $invoice->get_discounts() : ''; |
34 | - $tax = $invoice->get_tax( true ); |
|
35 | - $total = $invoice->get_total( true ); |
|
34 | + $tax = $invoice->get_tax(true); |
|
35 | + $total = $invoice->get_total(true); |
|
36 | 36 | $item_quantities = wpinv_item_quantities_enabled(); |
37 | 37 | $use_taxes = wpinv_use_taxes(); |
38 | - if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) { |
|
38 | + if (!$use_taxes && (float) $invoice->get_tax() > 0) { |
|
39 | 39 | $use_taxes = true; |
40 | 40 | } |
41 | - $item_types = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post ); |
|
41 | + $item_types = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post); |
|
42 | 42 | $is_recurring = $invoice->is_recurring(); |
43 | 43 | $post_type_object = get_post_type_object($invoice->post_type); |
44 | 44 | $type_title = $post_type_object->labels->singular_name; |
45 | 45 | |
46 | 46 | $cols = 5; |
47 | - if ( $item_quantities ) { |
|
47 | + if ($item_quantities) { |
|
48 | 48 | $cols++; |
49 | 49 | } |
50 | - if ( $use_taxes ) { |
|
50 | + if ($use_taxes) { |
|
51 | 51 | $cols++; |
52 | 52 | } |
53 | 53 | $class = ''; |
54 | - if ( $invoice->is_paid() ) { |
|
54 | + if ($invoice->is_paid()) { |
|
55 | 55 | $class .= ' wpinv-paid'; |
56 | 56 | } |
57 | - if ( $invoice->is_refunded() ) { |
|
57 | + if ($invoice->is_refunded()) { |
|
58 | 58 | $class .= ' wpinv-refunded'; |
59 | 59 | } |
60 | - if ( $is_recurring ) { |
|
60 | + if ($is_recurring) { |
|
61 | 61 | $class .= ' wpi-recurring'; |
62 | 62 | } |
63 | 63 | ?> |
@@ -65,21 +65,21 @@ discard block |
||
65 | 65 | <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0"> |
66 | 66 | <thead> |
67 | 67 | <tr> |
68 | - <th class="id"><?php _e( 'ID', 'invoicing' );?></th> |
|
69 | - <th class="title"><?php _e( 'Item', 'invoicing' );?></th> |
|
70 | - <th class="price"><?php _e( 'Price', 'invoicing' );?></th> |
|
71 | - <?php if ( $item_quantities ) { ?> |
|
72 | - <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th> |
|
68 | + <th class="id"><?php _e('ID', 'invoicing'); ?></th> |
|
69 | + <th class="title"><?php _e('Item', 'invoicing'); ?></th> |
|
70 | + <th class="price"><?php _e('Price', 'invoicing'); ?></th> |
|
71 | + <?php if ($item_quantities) { ?> |
|
72 | + <th class="qty"><?php _e('Qty', 'invoicing'); ?></th> |
|
73 | 73 | <?php } ?> |
74 | - <th class="total"><?php _e( 'Total', 'invoicing' );?></th> |
|
75 | - <?php if ( $use_taxes ) { ?> |
|
76 | - <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th> |
|
74 | + <th class="total"><?php _e('Total', 'invoicing'); ?></th> |
|
75 | + <?php if ($use_taxes) { ?> |
|
76 | + <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th> |
|
77 | 77 | <?php } ?> |
78 | 78 | <th class="action"></th> |
79 | 79 | </tr> |
80 | 80 | </thead> |
81 | 81 | <tbody class="wpinv-line-items"> |
82 | - <?php echo wpinv_admin_get_line_items( $invoice ); ?> |
|
82 | + <?php echo wpinv_admin_get_line_items($invoice); ?> |
|
83 | 83 | </tbody> |
84 | 84 | <tfoot class="wpinv-totals"> |
85 | 85 | <tr> |
@@ -90,45 +90,45 @@ discard block |
||
90 | 90 | <td class="id"> |
91 | 91 | </td> |
92 | 92 | <td class="title"> |
93 | - <input type="text" class="regular-text" placeholder="<?php _e( 'Item Name', 'invoicing' ); ?>" value="" name="_wpinv_quick[name]"> |
|
94 | - <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?> |
|
93 | + <input type="text" class="regular-text" placeholder="<?php _e('Item Name', 'invoicing'); ?>" value="" name="_wpinv_quick[name]"> |
|
94 | + <?php if ($wpinv_euvat->allow_vat_rules()) { ?> |
|
95 | 95 | <div class="wp-clearfix"> |
96 | 96 | <label class="wpi-vat-rule"> |
97 | - <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span> |
|
97 | + <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span> |
|
98 | 98 | <span class="input-text-wrap"> |
99 | - <?php echo wpinv_html_select( array( |
|
99 | + <?php echo wpinv_html_select(array( |
|
100 | 100 | 'options' => $wpinv_euvat->get_rules(), |
101 | 101 | 'name' => '_wpinv_quick[vat_rule]', |
102 | 102 | 'id' => '_wpinv_quick_vat_rule', |
103 | 103 | 'show_option_all' => false, |
104 | 104 | 'show_option_none' => false, |
105 | 105 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-rule wpi_select2', |
106 | - ) ); ?> |
|
106 | + )); ?> |
|
107 | 107 | </span> |
108 | 108 | </label> |
109 | 109 | </div> |
110 | - <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?> |
|
110 | + <?php } if ($wpinv_euvat->allow_vat_classes()) { ?> |
|
111 | 111 | <div class="wp-clearfix"> |
112 | 112 | <label class="wpi-vat-class"> |
113 | - <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span> |
|
113 | + <span class="title"><?php _e('VAT class', 'invoicing'); ?></span> |
|
114 | 114 | <span class="input-text-wrap"> |
115 | - <?php echo wpinv_html_select( array( |
|
115 | + <?php echo wpinv_html_select(array( |
|
116 | 116 | 'options' => $wpinv_euvat->get_all_classes(), |
117 | 117 | 'name' => '_wpinv_quick[vat_class]', |
118 | 118 | 'id' => '_wpinv_quick_vat_class', |
119 | 119 | 'show_option_all' => false, |
120 | 120 | 'show_option_none' => false, |
121 | 121 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-class wpi_select2', |
122 | - ) ); ?> |
|
122 | + )); ?> |
|
123 | 123 | </span> |
124 | 124 | </label> |
125 | 125 | </div> |
126 | 126 | <?php } ?> |
127 | 127 | <div class="wp-clearfix"> |
128 | 128 | <label class="wpi-item-type"> |
129 | - <span class="title"><?php _e( 'Item type', 'invoicing' );?></span> |
|
129 | + <span class="title"><?php _e('Item type', 'invoicing'); ?></span> |
|
130 | 130 | <span class="input-text-wrap"> |
131 | - <?php echo wpinv_html_select( array( |
|
131 | + <?php echo wpinv_html_select(array( |
|
132 | 132 | 'options' => $item_types, |
133 | 133 | 'name' => '_wpinv_quick[type]', |
134 | 134 | 'id' => '_wpinv_quick_type', |
@@ -136,37 +136,37 @@ discard block |
||
136 | 136 | 'show_option_all' => false, |
137 | 137 | 'show_option_none' => false, |
138 | 138 | 'class' => 'gdmbx2-text-medium wpinv-quick-type wpi_select2', |
139 | - ) ); ?> |
|
139 | + )); ?> |
|
140 | 140 | </span> |
141 | 141 | </label> |
142 | 142 | </div> |
143 | 143 | |
144 | 144 | <div class="wp-clearfix"> |
145 | 145 | <?php |
146 | - echo wpinv_html_textarea( array( |
|
146 | + echo wpinv_html_textarea(array( |
|
147 | 147 | 'name' => '_wpinv_quick[excerpt]', |
148 | 148 | 'id' => '_wpinv_quick_excerpt', |
149 | 149 | 'value' => '', |
150 | 150 | 'class' => 'large-text', |
151 | - 'label' => __( 'Item description', 'invoicing' ), |
|
152 | - ) ); |
|
151 | + 'label' => __('Item description', 'invoicing'), |
|
152 | + )); |
|
153 | 153 | ?> |
154 | 154 | </div> |
155 | 155 | |
156 | 156 | <div class="wp-clearfix"> |
157 | 157 | <label class="wpi-item-actions"> |
158 | 158 | <span class="input-text-wrap"> |
159 | - <input type="button" value="<?php esc_attr_e( 'Add', 'invoicing' ); ?>" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item"> |
|
159 | + <input type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item"> |
|
160 | 160 | </span> |
161 | 161 | </label> |
162 | 162 | </div> |
163 | 163 | </td> |
164 | 164 | <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td> |
165 | - <?php if ( $item_quantities ) { ?> |
|
165 | + <?php if ($item_quantities) { ?> |
|
166 | 166 | <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td> |
167 | 167 | <?php } ?> |
168 | 168 | <td class="total"></td> |
169 | - <?php if ( $use_taxes ) { ?> |
|
169 | + <?php if ($use_taxes) { ?> |
|
170 | 170 | <td class="tax"></td> |
171 | 171 | <?php } ?> |
172 | 172 | <td class="action"></td> |
@@ -179,29 +179,29 @@ discard block |
||
179 | 179 | <td colspan="<?php echo $cols; ?>"></td> |
180 | 180 | </tr> |
181 | 181 | <tr class="totals"> |
182 | - <td colspan="<?php echo ( $cols - 4 ); ?>"></td> |
|
182 | + <td colspan="<?php echo ($cols - 4); ?>"></td> |
|
183 | 183 | <td colspan="4"> |
184 | 184 | <table cellspacing="0" cellpadding="0"> |
185 | 185 | <tr class="subtotal"> |
186 | - <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td> |
|
187 | - <td class="total"><?php echo $subtotal;?></td> |
|
186 | + <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td> |
|
187 | + <td class="total"><?php echo $subtotal; ?></td> |
|
188 | 188 | <td class="action"></td> |
189 | 189 | </tr> |
190 | 190 | <tr class="discount"> |
191 | - <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td> |
|
192 | - <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td> |
|
191 | + <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td> |
|
192 | + <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td> |
|
193 | 193 | <td class="action"></td> |
194 | 194 | </tr> |
195 | - <?php if ( $use_taxes ) { ?> |
|
195 | + <?php if ($use_taxes) { ?> |
|
196 | 196 | <tr class="tax"> |
197 | - <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td> |
|
198 | - <td class="total"><?php echo $tax;?></td> |
|
197 | + <td class="name"><?php _e('Tax:', 'invoicing'); ?></td> |
|
198 | + <td class="total"><?php echo $tax; ?></td> |
|
199 | 199 | <td class="action"></td> |
200 | 200 | </tr> |
201 | 201 | <?php } ?> |
202 | 202 | <tr class="total"> |
203 | - <td class="name"><?php echo apply_filters( 'wpinv_invoice_items_total_label', __( 'Invoice Total:', 'invoicing' ), $invoice );?></td> |
|
204 | - <td class="total"><?php echo $total;?></td> |
|
203 | + <td class="name"><?php echo apply_filters('wpinv_invoice_items_total_label', __('Invoice Total:', 'invoicing'), $invoice); ?></td> |
|
204 | + <td class="total"><?php echo $total; ?></td> |
|
205 | 205 | <td class="action"></td> |
206 | 206 | </tr> |
207 | 207 | </table> |
@@ -212,19 +212,19 @@ discard block |
||
212 | 212 | <div class="wpinv-actions"> |
213 | 213 | <?php ob_start(); ?> |
214 | 214 | <?php |
215 | - if ( !$invoice->is_paid() && !$invoice->is_refunded() ) { |
|
216 | - if ( !$invoice->is_recurring() ) { |
|
217 | - echo wpinv_item_dropdown( array( |
|
215 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
216 | + if (!$invoice->is_recurring()) { |
|
217 | + echo wpinv_item_dropdown(array( |
|
218 | 218 | 'name' => 'wpinv_invoice_item', |
219 | 219 | 'id' => 'wpinv_invoice_item', |
220 | 220 | 'show_recurring' => true, |
221 | 221 | 'class' => 'wpi_select2', |
222 | - ) ); |
|
222 | + )); |
|
223 | 223 | ?> |
224 | - <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals"> |
|
224 | + <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals"> |
|
225 | 225 | <?php } ?> |
226 | - <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?> |
|
227 | - <?php $item_actions = ob_get_clean(); echo apply_filters( 'wpinv_invoice_items_actions_content', $item_actions, $invoice, $post ); ?> |
|
226 | + <?php do_action('wpinv_invoice_items_actions', $invoice); ?> |
|
227 | + <?php $item_actions = ob_get_clean(); echo apply_filters('wpinv_invoice_items_actions_content', $item_actions, $invoice, $post); ?> |
|
228 | 228 | </div> |
229 | 229 | </div> |
230 | 230 | <?php |
@@ -233,101 +233,101 @@ discard block |
||
233 | 233 | /** |
234 | 234 | * Display the items buy now shortcode. |
235 | 235 | */ |
236 | - public static function shortcode( $post ) { |
|
236 | + public static function shortcode($post) { |
|
237 | 237 | |
238 | - if ( ! is_numeric( $post ) ) { |
|
238 | + if (!is_numeric($post)) { |
|
239 | 239 | $post = $post->ID; |
240 | 240 | } |
241 | 241 | |
242 | 242 | echo "<input type='text' style='min-width: 100%; font-size: small;' value='[getpaid item=$post]' disabled>"; |
243 | 243 | } |
244 | 244 | |
245 | - public static function save( $post_id, $data, $post ) { |
|
245 | + public static function save($post_id, $data, $post) { |
|
246 | 246 | |
247 | - if ( empty( $_POST['wpinv_save_invoice'] ) || ! wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) { |
|
247 | + if (empty($_POST['wpinv_save_invoice']) || !wp_verify_nonce($_POST['wpinv_save_invoice'], 'wpinv_save_invoice')) { |
|
248 | 248 | return; |
249 | 249 | } |
250 | 250 | |
251 | - $invoice = new WPInv_Invoice( $post_id ); |
|
251 | + $invoice = new WPInv_Invoice($post_id); |
|
252 | 252 | |
253 | 253 | // Billing |
254 | - $first_name = sanitize_text_field( $data['wpinv_first_name'] ); |
|
255 | - $last_name = sanitize_text_field( $data['wpinv_last_name'] ); |
|
256 | - $company = sanitize_text_field( $data['wpinv_company'] ); |
|
257 | - $vat_number = sanitize_text_field( $data['wpinv_vat_number'] ); |
|
258 | - $phone = sanitize_text_field( $data['wpinv_phone'] ); |
|
259 | - $address = sanitize_text_field( $data['wpinv_address'] ); |
|
260 | - $city = sanitize_text_field( $data['wpinv_city'] ); |
|
261 | - $zip = sanitize_text_field( $data['wpinv_zip'] ); |
|
262 | - $country = sanitize_text_field( $data['wpinv_country'] ); |
|
263 | - $state = sanitize_text_field( $data['wpinv_state'] ); |
|
254 | + $first_name = sanitize_text_field($data['wpinv_first_name']); |
|
255 | + $last_name = sanitize_text_field($data['wpinv_last_name']); |
|
256 | + $company = sanitize_text_field($data['wpinv_company']); |
|
257 | + $vat_number = sanitize_text_field($data['wpinv_vat_number']); |
|
258 | + $phone = sanitize_text_field($data['wpinv_phone']); |
|
259 | + $address = sanitize_text_field($data['wpinv_address']); |
|
260 | + $city = sanitize_text_field($data['wpinv_city']); |
|
261 | + $zip = sanitize_text_field($data['wpinv_zip']); |
|
262 | + $country = sanitize_text_field($data['wpinv_country']); |
|
263 | + $state = sanitize_text_field($data['wpinv_state']); |
|
264 | 264 | |
265 | 265 | // Details |
266 | - $status = sanitize_text_field( $data['wpinv_status'] ); |
|
267 | - $old_status = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status; |
|
268 | - $number = sanitize_text_field( $data['wpinv_number'] ); |
|
269 | - $due_date = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : ''; |
|
270 | - $date_created = isset( $data['date_created'] ) ? sanitize_text_field( $data['date_created'] ) : ''; |
|
266 | + $status = sanitize_text_field($data['wpinv_status']); |
|
267 | + $old_status = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status; |
|
268 | + $number = sanitize_text_field($data['wpinv_number']); |
|
269 | + $due_date = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : ''; |
|
270 | + $date_created = isset($data['date_created']) ? sanitize_text_field($data['date_created']) : ''; |
|
271 | 271 | //$discounts = sanitize_text_field( $data['wpinv_discounts'] ); |
272 | 272 | //$discount = sanitize_text_field( $data['wpinv_discount'] ); |
273 | 273 | |
274 | 274 | $disable_taxes = 0; |
275 | 275 | |
276 | - if ( ! empty( $data['disable_taxes'] ) ) { |
|
276 | + if (!empty($data['disable_taxes'])) { |
|
277 | 277 | $disable_taxes = 1; |
278 | 278 | } |
279 | 279 | |
280 | - $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
281 | - |
|
282 | - $invoice->set( 'due_date', $due_date ); |
|
283 | - $invoice->set( 'first_name', $first_name ); |
|
284 | - $invoice->set( 'last_name', $last_name ); |
|
285 | - $invoice->set( 'company', $company ); |
|
286 | - $invoice->set( 'vat_number', $vat_number ); |
|
287 | - $invoice->set( 'phone', $phone ); |
|
288 | - $invoice->set( 'address', $address ); |
|
289 | - $invoice->set( 'city', $city ); |
|
290 | - $invoice->set( 'zip', $zip ); |
|
291 | - $invoice->set( 'country', $country ); |
|
292 | - $invoice->set( 'state', $state ); |
|
293 | - $invoice->set( 'status', $status ); |
|
294 | - $invoice->set( 'set', $status ); |
|
280 | + $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
281 | + |
|
282 | + $invoice->set('due_date', $due_date); |
|
283 | + $invoice->set('first_name', $first_name); |
|
284 | + $invoice->set('last_name', $last_name); |
|
285 | + $invoice->set('company', $company); |
|
286 | + $invoice->set('vat_number', $vat_number); |
|
287 | + $invoice->set('phone', $phone); |
|
288 | + $invoice->set('address', $address); |
|
289 | + $invoice->set('city', $city); |
|
290 | + $invoice->set('zip', $zip); |
|
291 | + $invoice->set('country', $country); |
|
292 | + $invoice->set('state', $state); |
|
293 | + $invoice->set('status', $status); |
|
294 | + $invoice->set('set', $status); |
|
295 | 295 | //$invoice->set( 'number', $number ); |
296 | 296 | //$invoice->set( 'discounts', $discounts ); |
297 | 297 | //$invoice->set( 'discount', $discount ); |
298 | - $invoice->set( 'disable_taxes', $disable_taxes ); |
|
299 | - $invoice->set( 'ip', $ip ); |
|
298 | + $invoice->set('disable_taxes', $disable_taxes); |
|
299 | + $invoice->set('ip', $ip); |
|
300 | 300 | $invoice->old_status = $_POST['original_post_status']; |
301 | 301 | |
302 | 302 | $currency = $invoice->get_currency(); |
303 | - if ( ! empty( $data['wpinv_currency'] ) ) { |
|
304 | - $currency = sanitize_text_field( $data['wpinv_currency'] ); |
|
303 | + if (!empty($data['wpinv_currency'])) { |
|
304 | + $currency = sanitize_text_field($data['wpinv_currency']); |
|
305 | 305 | } |
306 | 306 | |
307 | - if ( empty( $currency ) ) { |
|
307 | + if (empty($currency)) { |
|
308 | 308 | $currency = wpinv_get_currency(); |
309 | 309 | } |
310 | 310 | |
311 | - if ( ! $invoice->is_paid() ) { |
|
311 | + if (!$invoice->is_paid()) { |
|
312 | 312 | $invoice->currency = $currency; |
313 | 313 | } |
314 | 314 | |
315 | - if ( !empty( $data['wpinv_gateway'] ) ) { |
|
316 | - $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) ); |
|
315 | + if (!empty($data['wpinv_gateway'])) { |
|
316 | + $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway'])); |
|
317 | 317 | } |
318 | 318 | $saved = $invoice->save(); |
319 | 319 | |
320 | 320 | $emails = ''; |
321 | - if ( ! empty( $data['wpinv_cc'] ) ) { |
|
322 | - $emails = wpinv_clean( $data['wpinv_cc'] ); |
|
321 | + if (!empty($data['wpinv_cc'])) { |
|
322 | + $emails = wpinv_clean($data['wpinv_cc']); |
|
323 | 323 | } |
324 | - update_post_meta( $invoice->ID, 'wpinv_email_cc', $emails ); |
|
324 | + update_post_meta($invoice->ID, 'wpinv_email_cc', $emails); |
|
325 | 325 | |
326 | - if ( ! empty( $date_created ) && strtotime( $date_created, current_time( 'timestamp' ) ) ) { |
|
326 | + if (!empty($date_created) && strtotime($date_created, current_time('timestamp'))) { |
|
327 | 327 | |
328 | - $time = strtotime( $date_created, current_time( 'timestamp' ) ); |
|
329 | - $date = date( 'Y-m-d H:i:s', $time ); |
|
330 | - $date_gmt = get_gmt_from_date( $date ); |
|
328 | + $time = strtotime($date_created, current_time('timestamp')); |
|
329 | + $date = date('Y-m-d H:i:s', $time); |
|
330 | + $date_gmt = get_gmt_from_date($date); |
|
331 | 331 | |
332 | 332 | wp_update_post( |
333 | 333 | array( |
@@ -342,37 +342,37 @@ discard block |
||
342 | 342 | } |
343 | 343 | |
344 | 344 | // Check for payment notes |
345 | - if ( !empty( $data['invoice_note'] ) ) { |
|
346 | - $note = wp_kses( $data['invoice_note'], array() ); |
|
347 | - $note_type = sanitize_text_field( $data['invoice_note_type'] ); |
|
345 | + if (!empty($data['invoice_note'])) { |
|
346 | + $note = wp_kses($data['invoice_note'], array()); |
|
347 | + $note_type = sanitize_text_field($data['invoice_note_type']); |
|
348 | 348 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
349 | 349 | |
350 | - wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note ); |
|
350 | + wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | // Update user address if empty. |
354 | - if ( $saved && !empty( $invoice ) ) { |
|
355 | - if ( $user_id = $invoice->get_user_id() ) { |
|
356 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
354 | + if ($saved && !empty($invoice)) { |
|
355 | + if ($user_id = $invoice->get_user_id()) { |
|
356 | + $user_address = wpinv_get_user_address($user_id, false); |
|
357 | 357 | |
358 | 358 | if (empty($user_address['first_name'])) { |
359 | - update_user_meta( $user_id, '_wpinv_first_name', $first_name ); |
|
360 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
359 | + update_user_meta($user_id, '_wpinv_first_name', $first_name); |
|
360 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
361 | 361 | } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) { |
362 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
362 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) { |
366 | - update_user_meta( $user_id, '_wpinv_address', $address ); |
|
367 | - update_user_meta( $user_id, '_wpinv_city', $city ); |
|
368 | - update_user_meta( $user_id, '_wpinv_state', $state ); |
|
369 | - update_user_meta( $user_id, '_wpinv_country', $country ); |
|
370 | - update_user_meta( $user_id, '_wpinv_zip', $zip ); |
|
371 | - update_user_meta( $user_id, '_wpinv_phone', $phone ); |
|
366 | + update_user_meta($user_id, '_wpinv_address', $address); |
|
367 | + update_user_meta($user_id, '_wpinv_city', $city); |
|
368 | + update_user_meta($user_id, '_wpinv_state', $state); |
|
369 | + update_user_meta($user_id, '_wpinv_country', $country); |
|
370 | + update_user_meta($user_id, '_wpinv_zip', $zip); |
|
371 | + update_user_meta($user_id, '_wpinv_phone', $phone); |
|
372 | 372 | } |
373 | 373 | } |
374 | 374 | |
375 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
375 | + do_action('wpinv_invoice_metabox_saved', $invoice); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | return $saved; |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | class WPInv_Meta_Box_Payment_Form { |
@@ -11,23 +11,23 @@ discard block |
||
11 | 11 | * |
12 | 12 | * @param WP_Post $post |
13 | 13 | */ |
14 | - public static function output_details( $post ) { |
|
15 | - $details = get_post_meta( $post->ID, 'payment_form_data', true ); |
|
14 | + public static function output_details($post) { |
|
15 | + $details = get_post_meta($post->ID, 'payment_form_data', true); |
|
16 | 16 | |
17 | - if ( ! is_array( $details ) ) { |
|
17 | + if (!is_array($details)) { |
|
18 | 18 | return; |
19 | 19 | } |
20 | 20 | |
21 | 21 | echo '<div class="gdmbx2-wrap form-table"> <div class="gdmbx2-metabox gdmbx-field-list">'; |
22 | 22 | |
23 | - foreach ( $details as $key => $value ) { |
|
24 | - $key = sanitize_text_field( $key ); |
|
23 | + foreach ($details as $key => $value) { |
|
24 | + $key = sanitize_text_field($key); |
|
25 | 25 | |
26 | - if ( is_array( $value ) ) { |
|
27 | - $value = implode( ',', $value ); |
|
26 | + if (is_array($value)) { |
|
27 | + $value = implode(',', $value); |
|
28 | 28 | } |
29 | 29 | |
30 | - $value = esc_html( $value ); |
|
30 | + $value = esc_html($value); |
|
31 | 31 | |
32 | 32 | echo "<div class='gdmbx-row gdmbx-type-select'>"; |
33 | 33 | echo "<div class='gdmbx-th'><label>$key:</label></div>"; |
@@ -43,13 +43,13 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @param WP_Post $post |
45 | 45 | */ |
46 | - public static function output_shortcode( $post ) { |
|
46 | + public static function output_shortcode($post) { |
|
47 | 47 | |
48 | - if ( ! is_numeric( $post ) ) { |
|
48 | + if (!is_numeric($post)) { |
|
49 | 49 | $post = $post->ID; |
50 | 50 | } |
51 | 51 | |
52 | - if ( $post == wpinv_get_default_payment_form() ) { |
|
52 | + if ($post == wpinv_get_default_payment_form()) { |
|
53 | 53 | echo '—'; |
54 | 54 | return; |
55 | 55 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
10 | - exit; // Exit if accessed directly |
|
10 | + exit; // Exit if accessed directly |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | class GetPaid_Meta_Box_Payment_Form { |
17 | 17 | |
18 | 18 | /** |
19 | - * Output the metabox. |
|
20 | - * |
|
21 | - * @param WP_Post $post |
|
22 | - */ |
|
19 | + * Output the metabox. |
|
20 | + * |
|
21 | + * @param WP_Post $post |
|
22 | + */ |
|
23 | 23 | public static function output( $post ) { |
24 | 24 | ?> |
25 | 25 | <div id="wpinv-form-builder" class="bsui"> |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | - * Save meta box data. |
|
86 | - * |
|
87 | - * @param int $post_id |
|
88 | - */ |
|
89 | - public static function save( $post_id ) { |
|
85 | + * Save meta box data. |
|
86 | + * |
|
87 | + * @param int $post_id |
|
88 | + */ |
|
89 | + public static function save( $post_id ) { |
|
90 | 90 | |
91 | 91 | // verify nonce |
92 | 92 | if ( ! isset( $_POST['wpinv_save_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_save_payment_form'], 'wpinv_save_payment_form' ) ) { |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if (!defined('ABSPATH')) { |
|
10 | 10 | exit; // Exit if accessed directly |
11 | 11 | } |
12 | 12 | |
@@ -20,14 +20,14 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @param WP_Post $post |
22 | 22 | */ |
23 | - public static function output( $post ) { |
|
23 | + public static function output($post) { |
|
24 | 24 | ?> |
25 | 25 | <div id="wpinv-form-builder" class="bsui"> |
26 | 26 | <div class="row"> |
27 | 27 | <div class="col-sm-4"> |
28 | 28 | |
29 | 29 | <!-- Builder tabs --> |
30 | - <button class="button button-primary" v-if="active_tab!='new_item'" @click.prevent="active_tab='new_item'"><?php _e( 'Go Back', 'invoicing' ); ?></button> |
|
30 | + <button class="button button-primary" v-if="active_tab!='new_item'" @click.prevent="active_tab='new_item'"><?php _e('Go Back', 'invoicing'); ?></button> |
|
31 | 31 | |
32 | 32 | <!-- Builder tab content --> |
33 | 33 | <div class="mt-4"> |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | <!-- Available builder elements --> |
36 | 36 | <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='new_item'"> |
37 | 37 | <div class="wpinv-form-builder-add-field-types"> |
38 | - <small class='form-text text-muted'><?php _e( 'Add an element by dragging it to the payment form.', 'invoicing' ); ?></small> |
|
38 | + <small class='form-text text-muted'><?php _e('Add an element by dragging it to the payment form.', 'invoicing'); ?></small> |
|
39 | 39 | <draggable class="section mt-2" style="display: flex; flex-flow: wrap; justify-content: space-between;" v-model="elements" :group="{ name: 'fields', pull: 'clone', put: false }" :sort="false" :clone="addDraggedField" tag="ul" filter=".wpinv-undraggable"> |
40 | 40 | <li v-for="element in elements" class= "wpinv-payment-form-left-fields-field" @click.prevent="addField(element)" :class="{ 'd-none': element.defaults.premade }"> |
41 | 41 | <button class="button btn"> |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | <!-- Edit an element --> |
51 | 51 | <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='edit_item'" style="font-size: 16px;"> |
52 | 52 | <div class="wpinv-form-builder-edit-field-wrapper"> |
53 | - <?php do_action( 'wpinv_payment_form_edit_element_template', 'active_form_element', $post ); ?> |
|
53 | + <?php do_action('wpinv_payment_form_edit_element_template', 'active_form_element', $post); ?> |
|
54 | 54 | <div> |
55 | - <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e( 'Delete Element', 'invoicing' ); ?></button> |
|
55 | + <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e('Delete Element', 'invoicing'); ?></button> |
|
56 | 56 | </div> |
57 | 57 | </div> |
58 | 58 | </div> |
@@ -61,12 +61,12 @@ discard block |
||
61 | 61 | |
62 | 62 | </div> |
63 | 63 | <div class="col-sm-8 border-left"> |
64 | - <small class='form-text text-muted' v-if='form_elements.length'><?php _e( 'Click on any element to edit or delete it.', 'invoicing' ); ?></small> |
|
65 | - <p class='form-text text-muted' v-if='! form_elements.length'><?php _e( 'This form is empty. Add new elements by dragging them from the right.', 'invoicing' ); ?></p> |
|
64 | + <small class='form-text text-muted' v-if='form_elements.length'><?php _e('Click on any element to edit or delete it.', 'invoicing'); ?></small> |
|
65 | + <p class='form-text text-muted' v-if='! form_elements.length'><?php _e('This form is empty. Add new elements by dragging them from the right.', 'invoicing'); ?></p> |
|
66 | 66 | |
67 | 67 | <draggable class="section bsui" v-model="form_elements" @add="highlightLastDroppedField" group="fields" tag="div" style="min-height: 100%; font-size: 16px;"> |
68 | 68 | <div v-for="form_element in form_elements" class="wpinv-form-builder-element-preview" :class="{ active: active_form_element==form_element && active_tab=='edit_item' }" @click="active_tab = 'edit_item'; active_form_element = form_element"> |
69 | - <?php do_action( 'wpinv_payment_form_render_element_template', 'form_element', $post ); ?> |
|
69 | + <?php do_action('wpinv_payment_form_render_element_template', 'form_element', $post); ?> |
|
70 | 70 | </div> |
71 | 71 | </draggable> |
72 | 72 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | </div> |
79 | 79 | <?php |
80 | 80 | |
81 | - wp_nonce_field( 'wpinv_save_payment_form', 'wpinv_save_payment_form' ) ; |
|
81 | + wp_nonce_field('wpinv_save_payment_form', 'wpinv_save_payment_form'); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -86,54 +86,54 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @param int $post_id |
88 | 88 | */ |
89 | - public static function save( $post_id ) { |
|
89 | + public static function save($post_id) { |
|
90 | 90 | |
91 | 91 | // verify nonce |
92 | - if ( ! isset( $_POST['wpinv_save_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_save_payment_form'], 'wpinv_save_payment_form' ) ) { |
|
92 | + if (!isset($_POST['wpinv_save_payment_form']) || !wp_verify_nonce($_POST['wpinv_save_payment_form'], 'wpinv_save_payment_form')) { |
|
93 | 93 | return; |
94 | 94 | } |
95 | 95 | |
96 | 96 | // Prepare the form. |
97 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
97 | + $form = new GetPaid_Payment_Form($post_id); |
|
98 | 98 | |
99 | 99 | // Fetch form items. |
100 | - $form_items = json_decode( wp_unslash( $_POST['wpinv_form_items'] ), true ); |
|
100 | + $form_items = json_decode(wp_unslash($_POST['wpinv_form_items']), true); |
|
101 | 101 | |
102 | 102 | // Ensure that we have an array... |
103 | - if ( empty( $form_items ) ) { |
|
103 | + if (empty($form_items)) { |
|
104 | 104 | $form_items = array(); |
105 | 105 | } |
106 | 106 | |
107 | 107 | // ... and that new items are saved to the db. |
108 | - $form_items = self::maybe_save_items( $form_items ); |
|
108 | + $form_items = self::maybe_save_items($form_items); |
|
109 | 109 | |
110 | 110 | // Add it to the form. |
111 | - $form->set_items( $form_items ); |
|
111 | + $form->set_items($form_items); |
|
112 | 112 | |
113 | 113 | // Save form elements. |
114 | - $form_elements = json_decode( wp_unslash( $_POST['wpinv_form_elements'] ), true ); |
|
115 | - if ( empty( $form_elements ) ) { |
|
114 | + $form_elements = json_decode(wp_unslash($_POST['wpinv_form_elements']), true); |
|
115 | + if (empty($form_elements)) { |
|
116 | 116 | $form_elements = array(); |
117 | 117 | } |
118 | 118 | |
119 | - $form->set_elements( $form_elements ); |
|
119 | + $form->set_elements($form_elements); |
|
120 | 120 | |
121 | 121 | // Persist data to the datastore. |
122 | 122 | $form->save(); |
123 | - do_action( 'getpaid_payment_form_metabox_save', $post_id, $form ); |
|
123 | + do_action('getpaid_payment_form_metabox_save', $post_id, $form); |
|
124 | 124 | |
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | 128 | * Saves unsaved form items. |
129 | 129 | */ |
130 | - public static function maybe_save_items( $items ) { |
|
130 | + public static function maybe_save_items($items) { |
|
131 | 131 | |
132 | 132 | $saved = array(); |
133 | 133 | |
134 | - foreach( $items as $item ) { |
|
134 | + foreach ($items as $item) { |
|
135 | 135 | |
136 | - if ( is_numeric( $item['id'] ) ) { |
|
136 | + if (is_numeric($item['id'])) { |
|
137 | 137 | $saved[] = $item; |
138 | 138 | continue; |
139 | 139 | } |
@@ -143,32 +143,32 @@ discard block |
||
143 | 143 | // Save post data. |
144 | 144 | $new_item->set_props( |
145 | 145 | array( |
146 | - 'name' => sanitize_text_field( $item['title'] ), |
|
147 | - 'description' => wp_kses_post( $item['description'] ), |
|
146 | + 'name' => sanitize_text_field($item['title']), |
|
147 | + 'description' => wp_kses_post($item['description']), |
|
148 | 148 | 'status' => 'publish', |
149 | - 'type' => empty( $item['type'] ) ? 'custom' : $item['type'], |
|
150 | - 'price' => wpinv_sanitize_amount( $item['price'] ), |
|
151 | - 'vat_rule' => empty( $item['rule'] ) ? 'digital' : $item['rule'], |
|
152 | - 'vat_class' => empty( $item['class'] ) ? '_standard' : $item['class'], |
|
153 | - 'is_dynamic_pricing' => empty( $item['custom_price'] ) ? 0 : (int) $item['custom_price'], |
|
154 | - 'minimum_price' => empty( $item['minimum_price'] ) ? 0 : (float) $item['minimum_price'], |
|
149 | + 'type' => empty($item['type']) ? 'custom' : $item['type'], |
|
150 | + 'price' => wpinv_sanitize_amount($item['price']), |
|
151 | + 'vat_rule' => empty($item['rule']) ? 'digital' : $item['rule'], |
|
152 | + 'vat_class' => empty($item['class']) ? '_standard' : $item['class'], |
|
153 | + 'is_dynamic_pricing' => empty($item['custom_price']) ? 0 : (int) $item['custom_price'], |
|
154 | + 'minimum_price' => empty($item['minimum_price']) ? 0 : (float) $item['minimum_price'], |
|
155 | 155 | ) |
156 | 156 | ); |
157 | 157 | |
158 | 158 | // Save the item. |
159 | 159 | $new_item->save(); |
160 | 160 | |
161 | - if ( $new_item->get_id() ) { |
|
161 | + if ($new_item->get_id()) { |
|
162 | 162 | $item['id'] = $new_item->get_id(); |
163 | 163 | $saved[] = $item; |
164 | 164 | } |
165 | 165 | |
166 | 166 | } |
167 | 167 | |
168 | - foreach ( $saved as $i => $item ) { |
|
169 | - foreach ( array( 'new', 'type', 'class', 'rule', 'price', 'title', 'custom_price', 'minimum_price', 'recurring' ) as $key ) { |
|
170 | - if ( isset( $item[ $key ] ) ) { |
|
171 | - unset( $saved[ $i ][ $key ] ); |
|
168 | + foreach ($saved as $i => $item) { |
|
169 | + foreach (array('new', 'type', 'class', 'rule', 'price', 'title', 'custom_price', 'minimum_price', 'recurring') as $key) { |
|
170 | + if (isset($item[$key])) { |
|
171 | + unset($saved[$i][$key]); |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | } |
@@ -1,68 +1,68 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | -function wpinv_add_meta_boxes( $post_type, $post ) { |
|
7 | +function wpinv_add_meta_boxes($post_type, $post) { |
|
8 | 8 | global $wpi_mb_invoice; |
9 | - if ( $post_type == 'wpi_invoice' && !empty( $post->ID ) ) { |
|
10 | - $wpi_mb_invoice = wpinv_get_invoice( $post->ID ); |
|
9 | + if ($post_type == 'wpi_invoice' && !empty($post->ID)) { |
|
10 | + $wpi_mb_invoice = wpinv_get_invoice($post->ID); |
|
11 | 11 | } |
12 | 12 | |
13 | - if ( !empty( $wpi_mb_invoice ) && !$wpi_mb_invoice->has_status( array( 'draft', 'auto-draft' ) ) ) { |
|
14 | - add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high' ); |
|
13 | + if (!empty($wpi_mb_invoice) && !$wpi_mb_invoice->has_status(array('draft', 'auto-draft'))) { |
|
14 | + add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high'); |
|
15 | 15 | } |
16 | 16 | |
17 | - if ( !empty( $wpi_mb_invoice ) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent() ) { |
|
18 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscriptions', 'invoicing' ), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high' ); |
|
17 | + if (!empty($wpi_mb_invoice) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent()) { |
|
18 | + add_meta_box('wpinv-mb-subscriptions', __('Subscriptions', 'invoicing'), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high'); |
|
19 | 19 | } |
20 | 20 | |
21 | - if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) { |
|
22 | - add_meta_box( 'wpinv-mb-renewals', __( 'Renewal Payment', 'invoicing' ), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high' ); |
|
21 | + if (wpinv_is_subscription_payment($wpi_mb_invoice)) { |
|
22 | + add_meta_box('wpinv-mb-renewals', __('Renewal Payment', 'invoicing'), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high'); |
|
23 | 23 | } |
24 | 24 | |
25 | - add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default' ); |
|
26 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default' ); |
|
25 | + add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default'); |
|
26 | + add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default'); |
|
27 | 27 | |
28 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
29 | - add_meta_box( 'wpinv-payment-form-shortcode', __( 'Shortcode', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_shortcode', 'wpi_payment_form', 'side' ); |
|
28 | + add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal'); |
|
29 | + add_meta_box('wpinv-payment-form-shortcode', __('Shortcode', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_shortcode', 'wpi_payment_form', 'side'); |
|
30 | 30 | |
31 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' ); |
|
32 | - add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' ); |
|
33 | - add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' ); |
|
31 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high'); |
|
32 | + add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high'); |
|
33 | + add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high'); |
|
34 | 34 | |
35 | - if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) { |
|
36 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high' ); |
|
35 | + if (!empty($post->ID) && get_post_meta($post->ID, 'payment_form_data', true)) { |
|
36 | + add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
40 | 40 | } |
41 | -add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 ); |
|
41 | +add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2); |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Saves meta boxes. |
45 | 45 | */ |
46 | -function wpinv_save_meta_boxes( $post_id, $post ) { |
|
47 | - remove_action( 'save_post', __FUNCTION__ ); |
|
46 | +function wpinv_save_meta_boxes($post_id, $post) { |
|
47 | + remove_action('save_post', __FUNCTION__); |
|
48 | 48 | |
49 | 49 | // $post_id and $post are required. |
50 | - if ( empty( $post_id ) || empty( $post ) ) { |
|
50 | + if (empty($post_id) || empty($post)) { |
|
51 | 51 | return; |
52 | 52 | } |
53 | 53 | |
54 | 54 | // Ensure that this user can edit the post. |
55 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
55 | + if (!current_user_can('edit_post', $post_id)) { |
|
56 | 56 | return; |
57 | 57 | } |
58 | 58 | |
59 | 59 | // Dont' save meta boxes for revisions or autosaves |
60 | - if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
60 | + if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | 64 | // Do not save for ajax requests. |
65 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
65 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
66 | 66 | return; |
67 | 67 | } |
68 | 68 | |
@@ -74,67 +74,67 @@ discard block |
||
74 | 74 | ); |
75 | 75 | |
76 | 76 | // Is this our post type? |
77 | - if ( empty( $post->post_type ) || ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
77 | + if (empty($post->post_type) || !isset($post_types_map[$post->post_type])) { |
|
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
81 | 81 | // Save the post. |
82 | - $class = $post_types_map[ $post->post_type ]; |
|
83 | - $class::save( $post_id, $_POST, $post ); |
|
82 | + $class = $post_types_map[$post->post_type]; |
|
83 | + $class::save($post_id, $_POST, $post); |
|
84 | 84 | |
85 | 85 | } |
86 | -add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 ); |
|
86 | +add_action('save_post', 'wpinv_save_meta_boxes', 10, 3); |
|
87 | 87 | |
88 | 88 | function wpinv_register_item_meta_boxes() { |
89 | 89 | global $wpinv_euvat; |
90 | 90 | |
91 | 91 | // Item details metabox. |
92 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
92 | + add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high'); |
|
93 | 93 | |
94 | 94 | // If taxes are enabled, register the tax metabox. |
95 | - if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) { |
|
96 | - add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
95 | + if ($wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes()) { |
|
96 | + add_meta_box('wpinv_item_vat', __('VAT / Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high'); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | // Item info. |
100 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
100 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core'); |
|
101 | 101 | |
102 | 102 | } |
103 | 103 | |
104 | 104 | function wpinv_register_discount_meta_boxes() { |
105 | - add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' ); |
|
105 | + add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high'); |
|
106 | 106 | } |
107 | 107 | |
108 | -function wpinv_discount_metabox_details( $post ) { |
|
108 | +function wpinv_discount_metabox_details($post) { |
|
109 | 109 | $discount_id = $post->ID; |
110 | - $discount = wpinv_get_discount( $discount_id ); |
|
110 | + $discount = wpinv_get_discount($discount_id); |
|
111 | 111 | |
112 | - $type = wpinv_get_discount_type( $discount_id ); |
|
113 | - $item_reqs = wpinv_get_discount_item_reqs( $discount_id ); |
|
114 | - $excluded_items = wpinv_get_discount_excluded_items( $discount_id ); |
|
115 | - $min_total = wpinv_get_discount_min_total( $discount_id ); |
|
116 | - $max_total = wpinv_get_discount_max_total( $discount_id ); |
|
117 | - $max_uses = wpinv_get_discount_max_uses( $discount_id ); |
|
118 | - $single_use = wpinv_discount_is_single_use( $discount_id ); |
|
119 | - $recurring = (bool)wpinv_discount_is_recurring( $discount_id ); |
|
120 | - $start_date = wpinv_get_discount_start_date( $discount_id ); |
|
121 | - $expiration_date = wpinv_get_discount_expiration( $discount_id ); |
|
112 | + $type = wpinv_get_discount_type($discount_id); |
|
113 | + $item_reqs = wpinv_get_discount_item_reqs($discount_id); |
|
114 | + $excluded_items = wpinv_get_discount_excluded_items($discount_id); |
|
115 | + $min_total = wpinv_get_discount_min_total($discount_id); |
|
116 | + $max_total = wpinv_get_discount_max_total($discount_id); |
|
117 | + $max_uses = wpinv_get_discount_max_uses($discount_id); |
|
118 | + $single_use = wpinv_discount_is_single_use($discount_id); |
|
119 | + $recurring = (bool) wpinv_discount_is_recurring($discount_id); |
|
120 | + $start_date = wpinv_get_discount_start_date($discount_id); |
|
121 | + $expiration_date = wpinv_get_discount_expiration($discount_id); |
|
122 | 122 | |
123 | - if ( ! empty( $start_date ) && strpos( $start_date, '0000' ) === false ) { |
|
124 | - $start_time = strtotime( $start_date ); |
|
125 | - $start_h = date_i18n( 'H', $start_time ); |
|
126 | - $start_m = date_i18n( 'i', $start_time ); |
|
127 | - $start_date = date_i18n( 'Y-m-d', $start_time ); |
|
123 | + if (!empty($start_date) && strpos($start_date, '0000') === false) { |
|
124 | + $start_time = strtotime($start_date); |
|
125 | + $start_h = date_i18n('H', $start_time); |
|
126 | + $start_m = date_i18n('i', $start_time); |
|
127 | + $start_date = date_i18n('Y-m-d', $start_time); |
|
128 | 128 | } else { |
129 | 129 | $start_h = '00'; |
130 | 130 | $start_m = '00'; |
131 | 131 | } |
132 | 132 | |
133 | - if ( ! empty( $expiration_date ) && strpos( $expiration_date, '0000' ) === false ) { |
|
134 | - $expiration_time = strtotime( $expiration_date ); |
|
135 | - $expiration_h = date_i18n( 'H', $expiration_time ); |
|
136 | - $expiration_m = date_i18n( 'i', $expiration_time ); |
|
137 | - $expiration_date = date_i18n( 'Y-m-d', $expiration_time ); |
|
133 | + if (!empty($expiration_date) && strpos($expiration_date, '0000') === false) { |
|
134 | + $expiration_time = strtotime($expiration_date); |
|
135 | + $expiration_h = date_i18n('H', $expiration_time); |
|
136 | + $expiration_m = date_i18n('i', $expiration_time); |
|
137 | + $expiration_date = date_i18n('Y-m-d', $expiration_time); |
|
138 | 138 | } else { |
139 | 139 | $expiration_h = '23'; |
140 | 140 | $expiration_m = '59'; |
@@ -144,220 +144,220 @@ discard block |
||
144 | 144 | $max_total = $max_total > 0 ? $max_total : ''; |
145 | 145 | $max_uses = $max_uses > 0 ? $max_uses : ''; |
146 | 146 | ?> |
147 | -<?php do_action( 'wpinv_discount_form_top', $post ); ?> |
|
148 | -<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?> |
|
147 | +<?php do_action('wpinv_discount_form_top', $post); ?> |
|
148 | +<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?> |
|
149 | 149 | <table class="form-table wpi-form-table"> |
150 | 150 | <tbody> |
151 | - <?php do_action( 'wpinv_discount_form_first', $post ); ?> |
|
152 | - <?php do_action( 'wpinv_discount_form_before_code', $post ); ?> |
|
151 | + <?php do_action('wpinv_discount_form_first', $post); ?> |
|
152 | + <?php do_action('wpinv_discount_form_before_code', $post); ?> |
|
153 | 153 | <tr> |
154 | 154 | <th valign="top" scope="row"> |
155 | - <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label> |
|
155 | + <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label> |
|
156 | 156 | </th> |
157 | 157 | <td> |
158 | - <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required> |
|
159 | - <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p> |
|
158 | + <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required> |
|
159 | + <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p> |
|
160 | 160 | </td> |
161 | 161 | </tr> |
162 | - <?php do_action( 'wpinv_discount_form_before_type', $post ); ?> |
|
162 | + <?php do_action('wpinv_discount_form_before_type', $post); ?> |
|
163 | 163 | <tr> |
164 | 164 | <th valign="top" scope="row"> |
165 | - <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label> |
|
165 | + <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label> |
|
166 | 166 | </th> |
167 | 167 | <td> |
168 | 168 | <select id="wpinv_discount_type" name="type" class="medium-text wpi_select2"> |
169 | - <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?> |
|
170 | - <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option> |
|
169 | + <?php foreach (wpinv_get_discount_types() as $value => $label) { ?> |
|
170 | + <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option> |
|
171 | 171 | <?php } ?> |
172 | 172 | </select> |
173 | - <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p> |
|
173 | + <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p> |
|
174 | 174 | </td> |
175 | 175 | </tr> |
176 | - <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?> |
|
176 | + <?php do_action('wpinv_discount_form_before_amount', $post); ?> |
|
177 | 177 | <tr> |
178 | 178 | <th valign="top" scope="row"> |
179 | - <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label> |
|
179 | + <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label> |
|
180 | 180 | </th> |
181 | 181 | <td> |
182 | - <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr( wpinv_get_discount_amount( $discount_id ) ); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol() ;?></font> |
|
183 | - <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p> |
|
184 | - <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p> |
|
182 | + <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr(wpinv_get_discount_amount($discount_id)); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol(); ?></font> |
|
183 | + <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p> |
|
184 | + <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p> |
|
185 | 185 | </td> |
186 | 186 | </tr> |
187 | - <?php do_action( 'wpinv_discount_form_before_items', $post ); ?> |
|
187 | + <?php do_action('wpinv_discount_form_before_items', $post); ?> |
|
188 | 188 | <tr> |
189 | 189 | <th valign="top" scope="row"> |
190 | - <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label> |
|
190 | + <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label> |
|
191 | 191 | </th> |
192 | 192 | <td> |
193 | - <p><?php echo wpinv_item_dropdown( array( |
|
193 | + <p><?php echo wpinv_item_dropdown(array( |
|
194 | 194 | 'name' => 'items[]', |
195 | 195 | 'id' => 'items', |
196 | 196 | 'selected' => $item_reqs, |
197 | 197 | 'multiple' => true, |
198 | 198 | 'class' => 'medium-text wpi_select2', |
199 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
199 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
200 | 200 | 'show_recurring' => true, |
201 | - ) ); ?> |
|
201 | + )); ?> |
|
202 | 202 | </p> |
203 | - <p class="description"><?php _e( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing' ); ?></p> |
|
203 | + <p class="description"><?php _e('Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing'); ?></p> |
|
204 | 204 | </td> |
205 | 205 | </tr> |
206 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?> |
|
206 | + <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?> |
|
207 | 207 | <tr> |
208 | 208 | <th valign="top" scope="row"> |
209 | - <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label> |
|
209 | + <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label> |
|
210 | 210 | </th> |
211 | 211 | <td> |
212 | - <p><?php echo wpinv_item_dropdown( array( |
|
212 | + <p><?php echo wpinv_item_dropdown(array( |
|
213 | 213 | 'name' => 'excluded_items[]', |
214 | 214 | 'id' => 'excluded_items', |
215 | 215 | 'selected' => $excluded_items, |
216 | 216 | 'multiple' => true, |
217 | 217 | 'class' => 'medium-text wpi_select2', |
218 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
218 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
219 | 219 | 'show_recurring' => true, |
220 | - ) ); ?> |
|
220 | + )); ?> |
|
221 | 221 | </p> |
222 | - <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p> |
|
222 | + <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p> |
|
223 | 223 | </td> |
224 | 224 | </tr> |
225 | - <?php do_action( 'wpinv_discount_form_before_start', $post ); ?> |
|
225 | + <?php do_action('wpinv_discount_form_before_start', $post); ?> |
|
226 | 226 | <tr> |
227 | 227 | <th valign="top" scope="row"> |
228 | - <label for="wpinv_discount_start"><?php _e( 'Start Date', 'invoicing' ); ?></label> |
|
228 | + <label for="wpinv_discount_start"><?php _e('Start Date', 'invoicing'); ?></label> |
|
229 | 229 | </th> |
230 | 230 | <td> |
231 | - <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr( $start_date ); ?>"> @ <select id="wpinv_discount_start_h" name="start_h"> |
|
232 | - <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
233 | - <option value="<?php echo $value;?>" <?php selected( $value, $start_h ); ?>><?php echo $value;?></option> |
|
231 | + <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr($start_date); ?>"> @ <select id="wpinv_discount_start_h" name="start_h"> |
|
232 | + <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
233 | + <option value="<?php echo $value; ?>" <?php selected($value, $start_h); ?>><?php echo $value; ?></option> |
|
234 | 234 | <?php } ?> |
235 | 235 | </select> : <select id="wpinv_discount_start_m" name="start_m"> |
236 | - <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
237 | - <option value="<?php echo $value;?>" <?php selected( $value, $start_m ); ?>><?php echo $value;?></option> |
|
236 | + <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
237 | + <option value="<?php echo $value; ?>" <?php selected($value, $start_m); ?>><?php echo $value; ?></option> |
|
238 | 238 | <?php } ?> |
239 | 239 | </select> |
240 | - <p class="description"><?php _e( 'Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?></p> |
|
240 | + <p class="description"><?php _e('Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?></p> |
|
241 | 241 | </td> |
242 | 242 | </tr> |
243 | - <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?> |
|
243 | + <?php do_action('wpinv_discount_form_before_expiration', $post); ?> |
|
244 | 244 | <tr> |
245 | 245 | <th valign="top" scope="row"> |
246 | - <label for="wpinv_discount_expiration"><?php _e( 'Expiration Date', 'invoicing' ); ?></label> |
|
246 | + <label for="wpinv_discount_expiration"><?php _e('Expiration Date', 'invoicing'); ?></label> |
|
247 | 247 | </th> |
248 | 248 | <td> |
249 | - <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr( $expiration_date ); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h"> |
|
250 | - <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
251 | - <option value="<?php echo $value;?>" <?php selected( $value, $expiration_h ); ?>><?php echo $value;?></option> |
|
249 | + <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr($expiration_date); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h"> |
|
250 | + <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
251 | + <option value="<?php echo $value; ?>" <?php selected($value, $expiration_h); ?>><?php echo $value; ?></option> |
|
252 | 252 | <?php } ?> |
253 | 253 | </select> : <select id="wpinv_discount_expiration_m" name="expiration_m"> |
254 | - <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
255 | - <option value="<?php echo $value;?>" <?php selected( $value, $expiration_m ); ?>><?php echo $value;?></option> |
|
254 | + <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
255 | + <option value="<?php echo $value; ?>" <?php selected($value, $expiration_m); ?>><?php echo $value; ?></option> |
|
256 | 256 | <?php } ?> |
257 | 257 | </select> |
258 | - <p class="description"><?php _e( 'Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing' ); ?></p> |
|
258 | + <p class="description"><?php _e('Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing'); ?></p> |
|
259 | 259 | </td> |
260 | 260 | </tr> |
261 | - <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?> |
|
261 | + <?php do_action('wpinv_discount_form_before_min_total', $post); ?> |
|
262 | 262 | <tr> |
263 | 263 | <th valign="top" scope="row"> |
264 | - <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label> |
|
264 | + <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label> |
|
265 | 265 | </th> |
266 | 266 | <td> |
267 | 267 | <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>"> |
268 | - <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
268 | + <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
269 | 269 | </td> |
270 | 270 | </tr> |
271 | - <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?> |
|
271 | + <?php do_action('wpinv_discount_form_before_max_total', $post); ?> |
|
272 | 272 | <tr> |
273 | 273 | <th valign="top" scope="row"> |
274 | - <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label> |
|
274 | + <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label> |
|
275 | 275 | </th> |
276 | 276 | <td> |
277 | 277 | <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>"> |
278 | - <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
278 | + <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
279 | 279 | </td> |
280 | 280 | </tr> |
281 | - <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?> |
|
281 | + <?php do_action('wpinv_discount_form_before_recurring', $post); ?> |
|
282 | 282 | <tr> |
283 | 283 | <th valign="top" scope="row"> |
284 | - <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label> |
|
284 | + <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label> |
|
285 | 285 | </th> |
286 | 286 | <td> |
287 | 287 | <select id="wpinv_discount_recurring" name="recurring" class="medium-text wpi_select2"> |
288 | - <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option> |
|
289 | - <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option> |
|
288 | + <option value="0" <?php selected(false, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option> |
|
289 | + <option value="1" <?php selected(true, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option> |
|
290 | 290 | </select> |
291 | - <p class="description"><?php _e( '<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing' ); ?></p> |
|
291 | + <p class="description"><?php _e('<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing'); ?></p> |
|
292 | 292 | </td> |
293 | 293 | </tr> |
294 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?> |
|
294 | + <?php do_action('wpinv_discount_form_before_max_uses', $post); ?> |
|
295 | 295 | <tr> |
296 | 296 | <th valign="top" scope="row"> |
297 | - <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label> |
|
297 | + <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label> |
|
298 | 298 | </th> |
299 | 299 | <td> |
300 | 300 | <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>"> |
301 | - <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p> |
|
301 | + <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p> |
|
302 | 302 | </td> |
303 | 303 | </tr> |
304 | - <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?> |
|
304 | + <?php do_action('wpinv_discount_form_before_single_use', $post); ?> |
|
305 | 305 | <tr> |
306 | 306 | <th valign="top" scope="row"> |
307 | - <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label> |
|
307 | + <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label> |
|
308 | 308 | </th> |
309 | 309 | <td> |
310 | - <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>> |
|
311 | - <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span> |
|
310 | + <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>> |
|
311 | + <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span> |
|
312 | 312 | </td> |
313 | 313 | </tr> |
314 | - <?php do_action( 'wpinv_discount_form_last', $post ); ?> |
|
314 | + <?php do_action('wpinv_discount_form_last', $post); ?> |
|
315 | 315 | </tbody> |
316 | 316 | </table> |
317 | -<?php do_action( 'wpinv_discount_form_bottom', $post ); ?> |
|
317 | +<?php do_action('wpinv_discount_form_bottom', $post); ?> |
|
318 | 318 | <?php |
319 | 319 | } |
320 | 320 | |
321 | -function wpinv_discount_metabox_save( $post_id, $post, $update = false ) { |
|
322 | - $post_type = !empty( $post ) ? $post->post_type : ''; |
|
321 | +function wpinv_discount_metabox_save($post_id, $post, $update = false) { |
|
322 | + $post_type = !empty($post) ? $post->post_type : ''; |
|
323 | 323 | |
324 | - if ( $post_type != 'wpi_discount' ) { |
|
324 | + if ($post_type != 'wpi_discount') { |
|
325 | 325 | return; |
326 | 326 | } |
327 | 327 | |
328 | - if ( !isset( $_POST['wpinv_discount_metabox_nonce'] ) || ( isset( $_POST['wpinv_discount_metabox_nonce'] ) && !wp_verify_nonce( $_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce' ) ) ) { |
|
328 | + if (!isset($_POST['wpinv_discount_metabox_nonce']) || (isset($_POST['wpinv_discount_metabox_nonce']) && !wp_verify_nonce($_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce'))) { |
|
329 | 329 | return; |
330 | 330 | } |
331 | 331 | |
332 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
332 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
333 | 333 | return; |
334 | 334 | } |
335 | 335 | |
336 | - if ( !current_user_can( wpinv_get_capability(), $post_id ) ) { |
|
336 | + if (!current_user_can(wpinv_get_capability(), $post_id)) { |
|
337 | 337 | return; |
338 | 338 | } |
339 | 339 | |
340 | - if ( !empty( $_POST['start'] ) && isset( $_POST['start_h'] ) && isset( $_POST['start_m'] ) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '' ) { |
|
340 | + if (!empty($_POST['start']) && isset($_POST['start_h']) && isset($_POST['start_m']) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '') { |
|
341 | 341 | $_POST['start'] = $_POST['start'] . ' ' . $_POST['start_h'] . ':' . $_POST['start_m']; |
342 | 342 | } |
343 | 343 | |
344 | - if ( !empty( $_POST['expiration'] ) && isset( $_POST['expiration_h'] ) && isset( $_POST['expiration_m'] ) ) { |
|
344 | + if (!empty($_POST['expiration']) && isset($_POST['expiration_h']) && isset($_POST['expiration_m'])) { |
|
345 | 345 | $_POST['expiration'] = $_POST['expiration'] . ' ' . $_POST['expiration_h'] . ':' . $_POST['expiration_m']; |
346 | 346 | } |
347 | 347 | |
348 | - return /** @scrutinizer ignore-call */ wpinv_store_discount( $post_id, $_POST, $post, $update ); |
|
348 | + return /** @scrutinizer ignore-call */ wpinv_store_discount($post_id, $_POST, $post, $update); |
|
349 | 349 | } |
350 | -add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 ); |
|
350 | +add_action('save_post', 'wpinv_discount_metabox_save', 10, 3); |
|
351 | 351 | |
352 | 352 | /** |
353 | 353 | * Remove trash link from the default form. |
354 | 354 | */ |
355 | -function getpaid_remove_action_link( $actions, $post ) { |
|
356 | - $post = get_post( $post ); |
|
357 | - if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
358 | - unset( $actions['trash'] ); |
|
359 | - unset( $actions['inline hide-if-no-js'] ); |
|
355 | +function getpaid_remove_action_link($actions, $post) { |
|
356 | + $post = get_post($post); |
|
357 | + if ('wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form()) { |
|
358 | + unset($actions['trash']); |
|
359 | + unset($actions['inline hide-if-no-js']); |
|
360 | 360 | } |
361 | 361 | return $actions; |
362 | 362 | } |
363 | -add_filter( 'post_row_actions', 'getpaid_remove_action_link', 10, 2 ); |
|
363 | +add_filter('post_row_actions', 'getpaid_remove_action_link', 10, 2); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -14,212 +14,212 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class GetPaid_Item_Data_Store extends GetPaid_Data_Store_WP { |
16 | 16 | |
17 | - /** |
|
18 | - * Data stored in meta keys, but not considered "meta" for an item. |
|
19 | - * |
|
20 | - * @since 1.0.19 |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $internal_meta_keys = array( |
|
24 | - '_wpinv_price', |
|
25 | - '_wpinv_vat_rule', |
|
26 | - '_wpinv_vat_class', |
|
27 | - '_wpinv_type', |
|
28 | - '_wpinv_custom_id', |
|
29 | - '_wpinv_custom_name', |
|
30 | - '_wpinv_custom_singular_name', |
|
31 | - '_wpinv_editable', |
|
32 | - '_wpinv_dynamic_pricing', |
|
33 | - '_minimum_price', |
|
34 | - '_wpinv_is_recurring', |
|
35 | - '_wpinv_recurring_period', |
|
36 | - '_wpinv_recurring_interval', |
|
37 | - '_wpinv_recurring_limit', |
|
38 | - '_wpinv_free_trial', |
|
39 | - '_wpinv_trial_period', |
|
40 | - '_wpinv_trial_interval' |
|
41 | - ); |
|
42 | - |
|
43 | - /** |
|
44 | - * A map of meta keys to data props. |
|
45 | - * |
|
46 | - * @since 1.0.19 |
|
47 | - * |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - protected $meta_key_to_props = array( |
|
51 | - '_wpinv_price' => 'price', |
|
52 | - '_wpinv_vat_rule' => 'vat_rule', |
|
53 | - '_wpinv_vat_class' => 'vat_class', |
|
54 | - '_wpinv_type' => 'type', |
|
55 | - '_wpinv_custom_id' => 'custom_id', |
|
56 | - '_wpinv_custom_name' => 'custom_name', |
|
57 | - '_wpinv_custom_singular_name' => 'custom_singular_name', |
|
58 | - '_wpinv_editable' => 'is_editable', |
|
59 | - '_wpinv_dynamic_pricing' => 'is_dynamic_pricing', |
|
60 | - '_minimum_price' => 'minimum_price', |
|
61 | - '_wpinv_custom_name' => 'custom_name', |
|
62 | - '_wpinv_is_recurring' => 'is_recurring', |
|
63 | - '_wpinv_recurring_period' => 'recurring_period', |
|
64 | - '_wpinv_recurring_interval' => 'recurring_interval', |
|
65 | - '_wpinv_recurring_limit' => 'recurring_limit', |
|
66 | - '_wpinv_free_trial' => 'is_free_trial', |
|
67 | - '_wpinv_trial_period' => 'trial_period', |
|
68 | - '_wpinv_trial_interval' => 'trial_interval', |
|
69 | - '_wpinv_version' => 'version', |
|
70 | - ); |
|
71 | - |
|
72 | - /* |
|
17 | + /** |
|
18 | + * Data stored in meta keys, but not considered "meta" for an item. |
|
19 | + * |
|
20 | + * @since 1.0.19 |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $internal_meta_keys = array( |
|
24 | + '_wpinv_price', |
|
25 | + '_wpinv_vat_rule', |
|
26 | + '_wpinv_vat_class', |
|
27 | + '_wpinv_type', |
|
28 | + '_wpinv_custom_id', |
|
29 | + '_wpinv_custom_name', |
|
30 | + '_wpinv_custom_singular_name', |
|
31 | + '_wpinv_editable', |
|
32 | + '_wpinv_dynamic_pricing', |
|
33 | + '_minimum_price', |
|
34 | + '_wpinv_is_recurring', |
|
35 | + '_wpinv_recurring_period', |
|
36 | + '_wpinv_recurring_interval', |
|
37 | + '_wpinv_recurring_limit', |
|
38 | + '_wpinv_free_trial', |
|
39 | + '_wpinv_trial_period', |
|
40 | + '_wpinv_trial_interval' |
|
41 | + ); |
|
42 | + |
|
43 | + /** |
|
44 | + * A map of meta keys to data props. |
|
45 | + * |
|
46 | + * @since 1.0.19 |
|
47 | + * |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + protected $meta_key_to_props = array( |
|
51 | + '_wpinv_price' => 'price', |
|
52 | + '_wpinv_vat_rule' => 'vat_rule', |
|
53 | + '_wpinv_vat_class' => 'vat_class', |
|
54 | + '_wpinv_type' => 'type', |
|
55 | + '_wpinv_custom_id' => 'custom_id', |
|
56 | + '_wpinv_custom_name' => 'custom_name', |
|
57 | + '_wpinv_custom_singular_name' => 'custom_singular_name', |
|
58 | + '_wpinv_editable' => 'is_editable', |
|
59 | + '_wpinv_dynamic_pricing' => 'is_dynamic_pricing', |
|
60 | + '_minimum_price' => 'minimum_price', |
|
61 | + '_wpinv_custom_name' => 'custom_name', |
|
62 | + '_wpinv_is_recurring' => 'is_recurring', |
|
63 | + '_wpinv_recurring_period' => 'recurring_period', |
|
64 | + '_wpinv_recurring_interval' => 'recurring_interval', |
|
65 | + '_wpinv_recurring_limit' => 'recurring_limit', |
|
66 | + '_wpinv_free_trial' => 'is_free_trial', |
|
67 | + '_wpinv_trial_period' => 'trial_period', |
|
68 | + '_wpinv_trial_interval' => 'trial_interval', |
|
69 | + '_wpinv_version' => 'version', |
|
70 | + ); |
|
71 | + |
|
72 | + /* |
|
73 | 73 | |-------------------------------------------------------------------------- |
74 | 74 | | CRUD Methods |
75 | 75 | |-------------------------------------------------------------------------- |
76 | 76 | */ |
77 | 77 | |
78 | - /** |
|
79 | - * Method to create a new item in the database. |
|
80 | - * |
|
81 | - * @param WPInv_Item $item Item object. |
|
82 | - */ |
|
83 | - public function create( &$item ) { |
|
84 | - $item->set_version( WPINV_VERSION ); |
|
85 | - $item->set_date_created( current_time('mysql') ); |
|
86 | - |
|
87 | - // Create a new post. |
|
88 | - $id = wp_insert_post( |
|
89 | - apply_filters( |
|
90 | - 'getpaid_new_item_data', |
|
91 | - array( |
|
92 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
93 | - 'post_type' => 'wpi_item', |
|
94 | - 'post_status' => $this->get_post_status( $item ), |
|
95 | - 'ping_status' => 'closed', |
|
96 | - 'post_author' => $item->get_author( 'edit' ), |
|
97 | - 'post_title' => $item->get_name( 'edit' ), |
|
98 | - 'post_parent' => 0, |
|
99 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
100 | - ) |
|
101 | - ), |
|
102 | - true |
|
103 | - ); |
|
104 | - |
|
105 | - if ( $id && ! is_wp_error( $id ) ) { |
|
106 | - $item->set_id( $id ); |
|
107 | - $this->update_post_meta( $item ); |
|
108 | - $item->save_meta_data(); |
|
109 | - $item->apply_changes(); |
|
110 | - $this->clear_caches( $item ); |
|
111 | - return true; |
|
112 | - } |
|
113 | - |
|
114 | - if ( is_wp_error( $id ) ) { |
|
115 | - $item->last_error = $id->get_error_message(); |
|
116 | - } |
|
78 | + /** |
|
79 | + * Method to create a new item in the database. |
|
80 | + * |
|
81 | + * @param WPInv_Item $item Item object. |
|
82 | + */ |
|
83 | + public function create( &$item ) { |
|
84 | + $item->set_version( WPINV_VERSION ); |
|
85 | + $item->set_date_created( current_time('mysql') ); |
|
86 | + |
|
87 | + // Create a new post. |
|
88 | + $id = wp_insert_post( |
|
89 | + apply_filters( |
|
90 | + 'getpaid_new_item_data', |
|
91 | + array( |
|
92 | + 'post_date' => $item->get_date_created( 'edit' ), |
|
93 | + 'post_type' => 'wpi_item', |
|
94 | + 'post_status' => $this->get_post_status( $item ), |
|
95 | + 'ping_status' => 'closed', |
|
96 | + 'post_author' => $item->get_author( 'edit' ), |
|
97 | + 'post_title' => $item->get_name( 'edit' ), |
|
98 | + 'post_parent' => 0, |
|
99 | + 'post_excerpt' => $item->get_description( 'edit' ), |
|
100 | + ) |
|
101 | + ), |
|
102 | + true |
|
103 | + ); |
|
104 | + |
|
105 | + if ( $id && ! is_wp_error( $id ) ) { |
|
106 | + $item->set_id( $id ); |
|
107 | + $this->update_post_meta( $item ); |
|
108 | + $item->save_meta_data(); |
|
109 | + $item->apply_changes(); |
|
110 | + $this->clear_caches( $item ); |
|
111 | + return true; |
|
112 | + } |
|
113 | + |
|
114 | + if ( is_wp_error( $id ) ) { |
|
115 | + $item->last_error = $id->get_error_message(); |
|
116 | + } |
|
117 | 117 | |
118 | - return false; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Method to read an item from the database. |
|
123 | - * |
|
124 | - * @param WPInv_Item $item Item object. |
|
125 | - * |
|
126 | - */ |
|
127 | - public function read( &$item ) { |
|
128 | - |
|
129 | - $item->set_defaults(); |
|
130 | - $item_object = get_post( $item->get_id() ); |
|
131 | - |
|
132 | - if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
133 | - $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
134 | - return false; |
|
135 | - } |
|
136 | - |
|
137 | - $item->set_props( |
|
138 | - array( |
|
139 | - 'parent_id' => $item_object->post_parent, |
|
140 | - 'date_created' => 0 < $item_object->post_date_gmt ? $item_object->post_date_gmt : null, |
|
141 | - 'date_modified' => 0 < $item_object->post_modified_gmt ? $item_object->post_modified_gmt : null, |
|
142 | - 'status' => $item_object->post_status, |
|
143 | - 'name' => $item_object->post_title, |
|
144 | - 'description' => $item_object->post_excerpt, |
|
145 | - 'author' => $item_object->post_author, |
|
146 | - ) |
|
147 | - ); |
|
148 | - |
|
149 | - $this->read_object_data( $item, $item_object ); |
|
150 | - $item->read_meta_data(); |
|
151 | - $item->set_object_read( true ); |
|
152 | - |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Method to update an item in the database. |
|
157 | - * |
|
158 | - * @param WPInv_Item $item Item object. |
|
159 | - */ |
|
160 | - public function update( &$item ) { |
|
161 | - $item->save_meta_data(); |
|
162 | - $item->set_version( WPINV_VERSION ); |
|
163 | - |
|
164 | - if ( null === $item->get_date_created( 'edit' ) ) { |
|
165 | - $item->set_date_created( current_time('mysql') ); |
|
166 | - } |
|
167 | - |
|
168 | - $changes = $item->get_changes(); |
|
169 | - |
|
170 | - // Only update the post when the post data changes. |
|
171 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
172 | - $post_data = array( |
|
173 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
174 | - 'post_status' => $item->get_status( 'edit' ), |
|
175 | - 'post_parent' => $item->get_parent_id( 'edit' ), |
|
176 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
177 | - 'post_modified' => $item->get_date_modified( 'edit' ), |
|
178 | - 'post_title' => $item->get_name( 'edit' ), |
|
179 | - 'post_author' => $item->get_author( 'edit' ), |
|
180 | - ); |
|
181 | - |
|
182 | - /** |
|
183 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
184 | - * to update data, since wp_update_post spawns more calls to the |
|
185 | - * save_post action. |
|
186 | - * |
|
187 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
188 | - * or an update purely from CRUD. |
|
189 | - */ |
|
190 | - if ( doing_action( 'save_post' ) ) { |
|
191 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
192 | - clean_post_cache( $item->get_id() ); |
|
193 | - } else { |
|
194 | - wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
195 | - } |
|
196 | - $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
197 | - } |
|
198 | - $this->update_post_meta( $item ); |
|
199 | - $item->apply_changes(); |
|
200 | - $this->clear_caches( $item ); |
|
201 | - } |
|
202 | - |
|
203 | - /* |
|
118 | + return false; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Method to read an item from the database. |
|
123 | + * |
|
124 | + * @param WPInv_Item $item Item object. |
|
125 | + * |
|
126 | + */ |
|
127 | + public function read( &$item ) { |
|
128 | + |
|
129 | + $item->set_defaults(); |
|
130 | + $item_object = get_post( $item->get_id() ); |
|
131 | + |
|
132 | + if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
133 | + $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
134 | + return false; |
|
135 | + } |
|
136 | + |
|
137 | + $item->set_props( |
|
138 | + array( |
|
139 | + 'parent_id' => $item_object->post_parent, |
|
140 | + 'date_created' => 0 < $item_object->post_date_gmt ? $item_object->post_date_gmt : null, |
|
141 | + 'date_modified' => 0 < $item_object->post_modified_gmt ? $item_object->post_modified_gmt : null, |
|
142 | + 'status' => $item_object->post_status, |
|
143 | + 'name' => $item_object->post_title, |
|
144 | + 'description' => $item_object->post_excerpt, |
|
145 | + 'author' => $item_object->post_author, |
|
146 | + ) |
|
147 | + ); |
|
148 | + |
|
149 | + $this->read_object_data( $item, $item_object ); |
|
150 | + $item->read_meta_data(); |
|
151 | + $item->set_object_read( true ); |
|
152 | + |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Method to update an item in the database. |
|
157 | + * |
|
158 | + * @param WPInv_Item $item Item object. |
|
159 | + */ |
|
160 | + public function update( &$item ) { |
|
161 | + $item->save_meta_data(); |
|
162 | + $item->set_version( WPINV_VERSION ); |
|
163 | + |
|
164 | + if ( null === $item->get_date_created( 'edit' ) ) { |
|
165 | + $item->set_date_created( current_time('mysql') ); |
|
166 | + } |
|
167 | + |
|
168 | + $changes = $item->get_changes(); |
|
169 | + |
|
170 | + // Only update the post when the post data changes. |
|
171 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
172 | + $post_data = array( |
|
173 | + 'post_date' => $item->get_date_created( 'edit' ), |
|
174 | + 'post_status' => $item->get_status( 'edit' ), |
|
175 | + 'post_parent' => $item->get_parent_id( 'edit' ), |
|
176 | + 'post_excerpt' => $item->get_description( 'edit' ), |
|
177 | + 'post_modified' => $item->get_date_modified( 'edit' ), |
|
178 | + 'post_title' => $item->get_name( 'edit' ), |
|
179 | + 'post_author' => $item->get_author( 'edit' ), |
|
180 | + ); |
|
181 | + |
|
182 | + /** |
|
183 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
184 | + * to update data, since wp_update_post spawns more calls to the |
|
185 | + * save_post action. |
|
186 | + * |
|
187 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
188 | + * or an update purely from CRUD. |
|
189 | + */ |
|
190 | + if ( doing_action( 'save_post' ) ) { |
|
191 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
192 | + clean_post_cache( $item->get_id() ); |
|
193 | + } else { |
|
194 | + wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
195 | + } |
|
196 | + $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
197 | + } |
|
198 | + $this->update_post_meta( $item ); |
|
199 | + $item->apply_changes(); |
|
200 | + $this->clear_caches( $item ); |
|
201 | + } |
|
202 | + |
|
203 | + /* |
|
204 | 204 | |-------------------------------------------------------------------------- |
205 | 205 | | Additional Methods |
206 | 206 | |-------------------------------------------------------------------------- |
207 | 207 | */ |
208 | 208 | |
209 | - /** |
|
210 | - * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class. |
|
211 | - * |
|
212 | - * @param WPInv_Item $item WPInv_Item object. |
|
213 | - * @since 1.0.19 |
|
214 | - */ |
|
215 | - protected function update_post_meta( &$item ) { |
|
209 | + /** |
|
210 | + * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class. |
|
211 | + * |
|
212 | + * @param WPInv_Item $item WPInv_Item object. |
|
213 | + * @since 1.0.19 |
|
214 | + */ |
|
215 | + protected function update_post_meta( &$item ) { |
|
216 | 216 | |
217 | - // Ensure that we have a custom id. |
|
217 | + // Ensure that we have a custom id. |
|
218 | 218 | if ( ! $item->get_custom_id() ) { |
219 | 219 | $item->set_custom_id( $item->get_id() ); |
220 | - } |
|
220 | + } |
|
221 | 221 | |
222 | - parent::update_post_meta( $item ); |
|
223 | - } |
|
222 | + parent::update_post_meta( $item ); |
|
223 | + } |
|
224 | 224 | |
225 | 225 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * GetPaid_Item_Data_Store class file. |
4 | 4 | * |
5 | 5 | */ |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -80,38 +80,38 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @param WPInv_Item $item Item object. |
82 | 82 | */ |
83 | - public function create( &$item ) { |
|
84 | - $item->set_version( WPINV_VERSION ); |
|
85 | - $item->set_date_created( current_time('mysql') ); |
|
83 | + public function create(&$item) { |
|
84 | + $item->set_version(WPINV_VERSION); |
|
85 | + $item->set_date_created(current_time('mysql')); |
|
86 | 86 | |
87 | 87 | // Create a new post. |
88 | 88 | $id = wp_insert_post( |
89 | 89 | apply_filters( |
90 | 90 | 'getpaid_new_item_data', |
91 | 91 | array( |
92 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
92 | + 'post_date' => $item->get_date_created('edit'), |
|
93 | 93 | 'post_type' => 'wpi_item', |
94 | - 'post_status' => $this->get_post_status( $item ), |
|
94 | + 'post_status' => $this->get_post_status($item), |
|
95 | 95 | 'ping_status' => 'closed', |
96 | - 'post_author' => $item->get_author( 'edit' ), |
|
97 | - 'post_title' => $item->get_name( 'edit' ), |
|
96 | + 'post_author' => $item->get_author('edit'), |
|
97 | + 'post_title' => $item->get_name('edit'), |
|
98 | 98 | 'post_parent' => 0, |
99 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
99 | + 'post_excerpt' => $item->get_description('edit'), |
|
100 | 100 | ) |
101 | 101 | ), |
102 | 102 | true |
103 | 103 | ); |
104 | 104 | |
105 | - if ( $id && ! is_wp_error( $id ) ) { |
|
106 | - $item->set_id( $id ); |
|
107 | - $this->update_post_meta( $item ); |
|
105 | + if ($id && !is_wp_error($id)) { |
|
106 | + $item->set_id($id); |
|
107 | + $this->update_post_meta($item); |
|
108 | 108 | $item->save_meta_data(); |
109 | 109 | $item->apply_changes(); |
110 | - $this->clear_caches( $item ); |
|
110 | + $this->clear_caches($item); |
|
111 | 111 | return true; |
112 | 112 | } |
113 | 113 | |
114 | - if ( is_wp_error( $id ) ) { |
|
114 | + if (is_wp_error($id)) { |
|
115 | 115 | $item->last_error = $id->get_error_message(); |
116 | 116 | } |
117 | 117 | |
@@ -124,13 +124,13 @@ discard block |
||
124 | 124 | * @param WPInv_Item $item Item object. |
125 | 125 | * |
126 | 126 | */ |
127 | - public function read( &$item ) { |
|
127 | + public function read(&$item) { |
|
128 | 128 | |
129 | 129 | $item->set_defaults(); |
130 | - $item_object = get_post( $item->get_id() ); |
|
130 | + $item_object = get_post($item->get_id()); |
|
131 | 131 | |
132 | - if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
133 | - $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
132 | + if (!$item->get_id() || !$item_object || $item_object->post_type != 'wpi_item') { |
|
133 | + $item->last_error = __('Invalid item.', 'invoicing'); |
|
134 | 134 | return false; |
135 | 135 | } |
136 | 136 | |
@@ -146,9 +146,9 @@ discard block |
||
146 | 146 | ) |
147 | 147 | ); |
148 | 148 | |
149 | - $this->read_object_data( $item, $item_object ); |
|
149 | + $this->read_object_data($item, $item_object); |
|
150 | 150 | $item->read_meta_data(); |
151 | - $item->set_object_read( true ); |
|
151 | + $item->set_object_read(true); |
|
152 | 152 | |
153 | 153 | } |
154 | 154 | |
@@ -157,26 +157,26 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @param WPInv_Item $item Item object. |
159 | 159 | */ |
160 | - public function update( &$item ) { |
|
160 | + public function update(&$item) { |
|
161 | 161 | $item->save_meta_data(); |
162 | - $item->set_version( WPINV_VERSION ); |
|
162 | + $item->set_version(WPINV_VERSION); |
|
163 | 163 | |
164 | - if ( null === $item->get_date_created( 'edit' ) ) { |
|
165 | - $item->set_date_created( current_time('mysql') ); |
|
164 | + if (null === $item->get_date_created('edit')) { |
|
165 | + $item->set_date_created(current_time('mysql')); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | $changes = $item->get_changes(); |
169 | 169 | |
170 | 170 | // Only update the post when the post data changes. |
171 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
171 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author'), array_keys($changes))) { |
|
172 | 172 | $post_data = array( |
173 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
174 | - 'post_status' => $item->get_status( 'edit' ), |
|
175 | - 'post_parent' => $item->get_parent_id( 'edit' ), |
|
176 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
177 | - 'post_modified' => $item->get_date_modified( 'edit' ), |
|
178 | - 'post_title' => $item->get_name( 'edit' ), |
|
179 | - 'post_author' => $item->get_author( 'edit' ), |
|
173 | + 'post_date' => $item->get_date_created('edit'), |
|
174 | + 'post_status' => $item->get_status('edit'), |
|
175 | + 'post_parent' => $item->get_parent_id('edit'), |
|
176 | + 'post_excerpt' => $item->get_description('edit'), |
|
177 | + 'post_modified' => $item->get_date_modified('edit'), |
|
178 | + 'post_title' => $item->get_name('edit'), |
|
179 | + 'post_author' => $item->get_author('edit'), |
|
180 | 180 | ); |
181 | 181 | |
182 | 182 | /** |
@@ -187,17 +187,17 @@ discard block |
||
187 | 187 | * This ensures hooks are fired by either WP itself (admin screen save), |
188 | 188 | * or an update purely from CRUD. |
189 | 189 | */ |
190 | - if ( doing_action( 'save_post' ) ) { |
|
191 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
192 | - clean_post_cache( $item->get_id() ); |
|
190 | + if (doing_action('save_post')) { |
|
191 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $item->get_id())); |
|
192 | + clean_post_cache($item->get_id()); |
|
193 | 193 | } else { |
194 | - wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
194 | + wp_update_post(array_merge(array('ID' => $item->get_id()), $post_data)); |
|
195 | 195 | } |
196 | - $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
196 | + $item->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
197 | 197 | } |
198 | - $this->update_post_meta( $item ); |
|
198 | + $this->update_post_meta($item); |
|
199 | 199 | $item->apply_changes(); |
200 | - $this->clear_caches( $item ); |
|
200 | + $this->clear_caches($item); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /* |
@@ -212,14 +212,14 @@ discard block |
||
212 | 212 | * @param WPInv_Item $item WPInv_Item object. |
213 | 213 | * @since 1.0.19 |
214 | 214 | */ |
215 | - protected function update_post_meta( &$item ) { |
|
215 | + protected function update_post_meta(&$item) { |
|
216 | 216 | |
217 | 217 | // Ensure that we have a custom id. |
218 | - if ( ! $item->get_custom_id() ) { |
|
219 | - $item->set_custom_id( $item->get_id() ); |
|
218 | + if (!$item->get_custom_id()) { |
|
219 | + $item->set_custom_id($item->get_id()); |
|
220 | 220 | } |
221 | 221 | |
222 | - parent::update_post_meta( $item ); |
|
222 | + parent::update_post_meta($item); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -14,163 +14,163 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class GetPaid_Payment_Form_Data_Store extends GetPaid_Data_Store_WP { |
16 | 16 | |
17 | - /** |
|
18 | - * Data stored in meta keys, but not considered "meta" for a form. |
|
19 | - * |
|
20 | - * @since 1.0.19 |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $internal_meta_keys = array( |
|
24 | - 'wpinv_form_elements', |
|
25 | - 'wpinv_form_items', |
|
26 | - 'wpinv_form_earned', |
|
27 | - 'wpinv_form_refunded', |
|
28 | - 'wpinv_form_cancelled', |
|
29 | - 'wpinv_form_failed' |
|
30 | - ); |
|
31 | - |
|
32 | - /** |
|
33 | - * A map of meta keys to data props. |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $meta_key_to_props = array( |
|
40 | - 'wpinv_form_elements' => 'elements', |
|
41 | - 'wpinv_form_items' => 'items', |
|
42 | - 'wpinv_form_earned' => 'earned', |
|
43 | - 'wpinv_form_refunded' => 'refunded', |
|
44 | - 'wpinv_form_cancelled' => 'cancelled', |
|
45 | - 'wpinv_form_failed' => 'failed', |
|
46 | - ); |
|
47 | - |
|
48 | - /* |
|
17 | + /** |
|
18 | + * Data stored in meta keys, but not considered "meta" for a form. |
|
19 | + * |
|
20 | + * @since 1.0.19 |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $internal_meta_keys = array( |
|
24 | + 'wpinv_form_elements', |
|
25 | + 'wpinv_form_items', |
|
26 | + 'wpinv_form_earned', |
|
27 | + 'wpinv_form_refunded', |
|
28 | + 'wpinv_form_cancelled', |
|
29 | + 'wpinv_form_failed' |
|
30 | + ); |
|
31 | + |
|
32 | + /** |
|
33 | + * A map of meta keys to data props. |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $meta_key_to_props = array( |
|
40 | + 'wpinv_form_elements' => 'elements', |
|
41 | + 'wpinv_form_items' => 'items', |
|
42 | + 'wpinv_form_earned' => 'earned', |
|
43 | + 'wpinv_form_refunded' => 'refunded', |
|
44 | + 'wpinv_form_cancelled' => 'cancelled', |
|
45 | + 'wpinv_form_failed' => 'failed', |
|
46 | + ); |
|
47 | + |
|
48 | + /* |
|
49 | 49 | |-------------------------------------------------------------------------- |
50 | 50 | | CRUD Methods |
51 | 51 | |-------------------------------------------------------------------------- |
52 | 52 | */ |
53 | 53 | |
54 | - /** |
|
55 | - * Method to create a new form in the database. |
|
56 | - * |
|
57 | - * @param GetPaid_Payment_Form $form Form object. |
|
58 | - */ |
|
59 | - public function create( &$form ) { |
|
60 | - $form->set_version( WPINV_VERSION ); |
|
61 | - $form->set_date_created( current_time('mysql') ); |
|
62 | - |
|
63 | - // Create a new post. |
|
64 | - $id = wp_insert_post( |
|
65 | - apply_filters( |
|
66 | - 'getpaid_new_payment_form_data', |
|
67 | - array( |
|
68 | - 'post_date' => $form->get_date_created( 'edit' ), |
|
69 | - 'post_type' => 'wpi_payment_form', |
|
70 | - 'post_status' => $this->get_post_status( $form ), |
|
71 | - 'ping_status' => 'closed', |
|
72 | - 'post_author' => $form->get_author( 'edit' ), |
|
73 | - 'post_title' => $form->get_name( 'edit' ), |
|
74 | - ) |
|
75 | - ), |
|
76 | - true |
|
77 | - ); |
|
78 | - |
|
79 | - if ( $id && ! is_wp_error( $id ) ) { |
|
80 | - $form->set_id( $id ); |
|
81 | - $this->update_post_meta( $form ); |
|
82 | - $form->save_meta_data(); |
|
83 | - $form->apply_changes(); |
|
84 | - $this->clear_caches( $form ); |
|
85 | - return true; |
|
86 | - } |
|
87 | - |
|
88 | - if ( is_wp_error( $id ) ) { |
|
89 | - $form->last_error = $id->get_error_message(); |
|
90 | - } |
|
91 | - |
|
92 | - return false; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Method to read a form from the database. |
|
97 | - * |
|
98 | - * @param GetPaid_Payment_Form $form Form object. |
|
99 | - * |
|
100 | - */ |
|
101 | - public function read( &$form ) { |
|
102 | - |
|
103 | - $form->set_defaults(); |
|
104 | - $form_object = get_post( $form->get_id() ); |
|
105 | - |
|
106 | - if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) { |
|
107 | - $form->last_error = __( 'Invalid form.', 'invoicing' ); |
|
108 | - return false; |
|
109 | - } |
|
110 | - |
|
111 | - $form->set_props( |
|
112 | - array( |
|
113 | - 'date_created' => 0 < $form_object->post_date_gmt ? $form_object->post_date_gmt : null, |
|
114 | - 'date_modified' => 0 < $form_object->post_modified_gmt ? $form_object->post_modified_gmt : null, |
|
115 | - 'status' => $form_object->post_status, |
|
116 | - 'name' => $form_object->post_title, |
|
117 | - 'author' => $form_object->post_author, |
|
118 | - ) |
|
119 | - ); |
|
120 | - |
|
121 | - $this->read_object_data( $form, $form_object ); |
|
122 | - $form->read_meta_data(); |
|
123 | - $form->set_object_read( true ); |
|
124 | - |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Method to update a form in the database. |
|
129 | - * |
|
130 | - * @param GetPaid_Payment_Form $form Form object. |
|
131 | - */ |
|
132 | - public function update( &$form ) { |
|
133 | - $form->save_meta_data(); |
|
134 | - $form->set_version( WPINV_VERSION ); |
|
135 | - |
|
136 | - if ( null === $form->get_date_created( 'edit' ) ) { |
|
137 | - $form->set_date_created( current_time('mysql') ); |
|
138 | - } |
|
139 | - |
|
140 | - $changes = $form->get_changes(); |
|
141 | - |
|
142 | - // Only update the post when the post data changes. |
|
143 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
144 | - $post_data = array( |
|
145 | - 'post_date' => $form->get_date_created( 'edit' ), |
|
146 | - 'post_status' => $form->get_status( 'edit' ), |
|
147 | - 'post_title' => $form->get_name( 'edit' ), |
|
148 | - 'post_author' => $form->get_author( 'edit' ), |
|
149 | - 'post_modified' => $form->get_date_modified( 'edit' ), |
|
150 | - ); |
|
151 | - |
|
152 | - /** |
|
153 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
154 | - * to update data, since wp_update_post spawns more calls to the |
|
155 | - * save_post action. |
|
156 | - * |
|
157 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
158 | - * or an update purely from CRUD. |
|
159 | - */ |
|
160 | - if ( doing_action( 'save_post' ) ) { |
|
161 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) ); |
|
162 | - clean_post_cache( $form->get_id() ); |
|
163 | - } else { |
|
164 | - wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) ); |
|
165 | - } |
|
166 | - $form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
167 | - } |
|
168 | - $this->update_post_meta( $form ); |
|
169 | - $form->apply_changes(); |
|
170 | - $this->clear_caches( $form ); |
|
171 | - } |
|
172 | - |
|
173 | - /* |
|
54 | + /** |
|
55 | + * Method to create a new form in the database. |
|
56 | + * |
|
57 | + * @param GetPaid_Payment_Form $form Form object. |
|
58 | + */ |
|
59 | + public function create( &$form ) { |
|
60 | + $form->set_version( WPINV_VERSION ); |
|
61 | + $form->set_date_created( current_time('mysql') ); |
|
62 | + |
|
63 | + // Create a new post. |
|
64 | + $id = wp_insert_post( |
|
65 | + apply_filters( |
|
66 | + 'getpaid_new_payment_form_data', |
|
67 | + array( |
|
68 | + 'post_date' => $form->get_date_created( 'edit' ), |
|
69 | + 'post_type' => 'wpi_payment_form', |
|
70 | + 'post_status' => $this->get_post_status( $form ), |
|
71 | + 'ping_status' => 'closed', |
|
72 | + 'post_author' => $form->get_author( 'edit' ), |
|
73 | + 'post_title' => $form->get_name( 'edit' ), |
|
74 | + ) |
|
75 | + ), |
|
76 | + true |
|
77 | + ); |
|
78 | + |
|
79 | + if ( $id && ! is_wp_error( $id ) ) { |
|
80 | + $form->set_id( $id ); |
|
81 | + $this->update_post_meta( $form ); |
|
82 | + $form->save_meta_data(); |
|
83 | + $form->apply_changes(); |
|
84 | + $this->clear_caches( $form ); |
|
85 | + return true; |
|
86 | + } |
|
87 | + |
|
88 | + if ( is_wp_error( $id ) ) { |
|
89 | + $form->last_error = $id->get_error_message(); |
|
90 | + } |
|
91 | + |
|
92 | + return false; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Method to read a form from the database. |
|
97 | + * |
|
98 | + * @param GetPaid_Payment_Form $form Form object. |
|
99 | + * |
|
100 | + */ |
|
101 | + public function read( &$form ) { |
|
102 | + |
|
103 | + $form->set_defaults(); |
|
104 | + $form_object = get_post( $form->get_id() ); |
|
105 | + |
|
106 | + if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) { |
|
107 | + $form->last_error = __( 'Invalid form.', 'invoicing' ); |
|
108 | + return false; |
|
109 | + } |
|
110 | + |
|
111 | + $form->set_props( |
|
112 | + array( |
|
113 | + 'date_created' => 0 < $form_object->post_date_gmt ? $form_object->post_date_gmt : null, |
|
114 | + 'date_modified' => 0 < $form_object->post_modified_gmt ? $form_object->post_modified_gmt : null, |
|
115 | + 'status' => $form_object->post_status, |
|
116 | + 'name' => $form_object->post_title, |
|
117 | + 'author' => $form_object->post_author, |
|
118 | + ) |
|
119 | + ); |
|
120 | + |
|
121 | + $this->read_object_data( $form, $form_object ); |
|
122 | + $form->read_meta_data(); |
|
123 | + $form->set_object_read( true ); |
|
124 | + |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Method to update a form in the database. |
|
129 | + * |
|
130 | + * @param GetPaid_Payment_Form $form Form object. |
|
131 | + */ |
|
132 | + public function update( &$form ) { |
|
133 | + $form->save_meta_data(); |
|
134 | + $form->set_version( WPINV_VERSION ); |
|
135 | + |
|
136 | + if ( null === $form->get_date_created( 'edit' ) ) { |
|
137 | + $form->set_date_created( current_time('mysql') ); |
|
138 | + } |
|
139 | + |
|
140 | + $changes = $form->get_changes(); |
|
141 | + |
|
142 | + // Only update the post when the post data changes. |
|
143 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
144 | + $post_data = array( |
|
145 | + 'post_date' => $form->get_date_created( 'edit' ), |
|
146 | + 'post_status' => $form->get_status( 'edit' ), |
|
147 | + 'post_title' => $form->get_name( 'edit' ), |
|
148 | + 'post_author' => $form->get_author( 'edit' ), |
|
149 | + 'post_modified' => $form->get_date_modified( 'edit' ), |
|
150 | + ); |
|
151 | + |
|
152 | + /** |
|
153 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
154 | + * to update data, since wp_update_post spawns more calls to the |
|
155 | + * save_post action. |
|
156 | + * |
|
157 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
158 | + * or an update purely from CRUD. |
|
159 | + */ |
|
160 | + if ( doing_action( 'save_post' ) ) { |
|
161 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) ); |
|
162 | + clean_post_cache( $form->get_id() ); |
|
163 | + } else { |
|
164 | + wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) ); |
|
165 | + } |
|
166 | + $form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
167 | + } |
|
168 | + $this->update_post_meta( $form ); |
|
169 | + $form->apply_changes(); |
|
170 | + $this->clear_caches( $form ); |
|
171 | + } |
|
172 | + |
|
173 | + /* |
|
174 | 174 | |-------------------------------------------------------------------------- |
175 | 175 | | Additional Methods |
176 | 176 | |-------------------------------------------------------------------------- |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * GetPaid_Payment_Form_Data_Store class file. |
4 | 4 | * |
5 | 5 | */ |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -56,36 +56,36 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @param GetPaid_Payment_Form $form Form object. |
58 | 58 | */ |
59 | - public function create( &$form ) { |
|
60 | - $form->set_version( WPINV_VERSION ); |
|
61 | - $form->set_date_created( current_time('mysql') ); |
|
59 | + public function create(&$form) { |
|
60 | + $form->set_version(WPINV_VERSION); |
|
61 | + $form->set_date_created(current_time('mysql')); |
|
62 | 62 | |
63 | 63 | // Create a new post. |
64 | 64 | $id = wp_insert_post( |
65 | 65 | apply_filters( |
66 | 66 | 'getpaid_new_payment_form_data', |
67 | 67 | array( |
68 | - 'post_date' => $form->get_date_created( 'edit' ), |
|
68 | + 'post_date' => $form->get_date_created('edit'), |
|
69 | 69 | 'post_type' => 'wpi_payment_form', |
70 | - 'post_status' => $this->get_post_status( $form ), |
|
70 | + 'post_status' => $this->get_post_status($form), |
|
71 | 71 | 'ping_status' => 'closed', |
72 | - 'post_author' => $form->get_author( 'edit' ), |
|
73 | - 'post_title' => $form->get_name( 'edit' ), |
|
72 | + 'post_author' => $form->get_author('edit'), |
|
73 | + 'post_title' => $form->get_name('edit'), |
|
74 | 74 | ) |
75 | 75 | ), |
76 | 76 | true |
77 | 77 | ); |
78 | 78 | |
79 | - if ( $id && ! is_wp_error( $id ) ) { |
|
80 | - $form->set_id( $id ); |
|
81 | - $this->update_post_meta( $form ); |
|
79 | + if ($id && !is_wp_error($id)) { |
|
80 | + $form->set_id($id); |
|
81 | + $this->update_post_meta($form); |
|
82 | 82 | $form->save_meta_data(); |
83 | 83 | $form->apply_changes(); |
84 | - $this->clear_caches( $form ); |
|
84 | + $this->clear_caches($form); |
|
85 | 85 | return true; |
86 | 86 | } |
87 | 87 | |
88 | - if ( is_wp_error( $id ) ) { |
|
88 | + if (is_wp_error($id)) { |
|
89 | 89 | $form->last_error = $id->get_error_message(); |
90 | 90 | } |
91 | 91 | |
@@ -98,13 +98,13 @@ discard block |
||
98 | 98 | * @param GetPaid_Payment_Form $form Form object. |
99 | 99 | * |
100 | 100 | */ |
101 | - public function read( &$form ) { |
|
101 | + public function read(&$form) { |
|
102 | 102 | |
103 | 103 | $form->set_defaults(); |
104 | - $form_object = get_post( $form->get_id() ); |
|
104 | + $form_object = get_post($form->get_id()); |
|
105 | 105 | |
106 | - if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) { |
|
107 | - $form->last_error = __( 'Invalid form.', 'invoicing' ); |
|
106 | + if (!$form->get_id() || !$form_object || $form_object->post_type != 'wpi_payment_form') { |
|
107 | + $form->last_error = __('Invalid form.', 'invoicing'); |
|
108 | 108 | return false; |
109 | 109 | } |
110 | 110 | |
@@ -118,9 +118,9 @@ discard block |
||
118 | 118 | ) |
119 | 119 | ); |
120 | 120 | |
121 | - $this->read_object_data( $form, $form_object ); |
|
121 | + $this->read_object_data($form, $form_object); |
|
122 | 122 | $form->read_meta_data(); |
123 | - $form->set_object_read( true ); |
|
123 | + $form->set_object_read(true); |
|
124 | 124 | |
125 | 125 | } |
126 | 126 | |
@@ -129,24 +129,24 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @param GetPaid_Payment_Form $form Form object. |
131 | 131 | */ |
132 | - public function update( &$form ) { |
|
132 | + public function update(&$form) { |
|
133 | 133 | $form->save_meta_data(); |
134 | - $form->set_version( WPINV_VERSION ); |
|
134 | + $form->set_version(WPINV_VERSION); |
|
135 | 135 | |
136 | - if ( null === $form->get_date_created( 'edit' ) ) { |
|
137 | - $form->set_date_created( current_time('mysql') ); |
|
136 | + if (null === $form->get_date_created('edit')) { |
|
137 | + $form->set_date_created(current_time('mysql')); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $changes = $form->get_changes(); |
141 | 141 | |
142 | 142 | // Only update the post when the post data changes. |
143 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
143 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author'), array_keys($changes))) { |
|
144 | 144 | $post_data = array( |
145 | - 'post_date' => $form->get_date_created( 'edit' ), |
|
146 | - 'post_status' => $form->get_status( 'edit' ), |
|
147 | - 'post_title' => $form->get_name( 'edit' ), |
|
148 | - 'post_author' => $form->get_author( 'edit' ), |
|
149 | - 'post_modified' => $form->get_date_modified( 'edit' ), |
|
145 | + 'post_date' => $form->get_date_created('edit'), |
|
146 | + 'post_status' => $form->get_status('edit'), |
|
147 | + 'post_title' => $form->get_name('edit'), |
|
148 | + 'post_author' => $form->get_author('edit'), |
|
149 | + 'post_modified' => $form->get_date_modified('edit'), |
|
150 | 150 | ); |
151 | 151 | |
152 | 152 | /** |
@@ -157,17 +157,17 @@ discard block |
||
157 | 157 | * This ensures hooks are fired by either WP itself (admin screen save), |
158 | 158 | * or an update purely from CRUD. |
159 | 159 | */ |
160 | - if ( doing_action( 'save_post' ) ) { |
|
161 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) ); |
|
162 | - clean_post_cache( $form->get_id() ); |
|
160 | + if (doing_action('save_post')) { |
|
161 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $form->get_id())); |
|
162 | + clean_post_cache($form->get_id()); |
|
163 | 163 | } else { |
164 | - wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) ); |
|
164 | + wp_update_post(array_merge(array('ID' => $form->get_id()), $post_data)); |
|
165 | 165 | } |
166 | - $form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
166 | + $form->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
167 | 167 | } |
168 | - $this->update_post_meta( $form ); |
|
168 | + $this->update_post_meta($form); |
|
169 | 169 | $form->apply_changes(); |
170 | - $this->clear_caches( $form ); |
|
170 | + $this->clear_caches($form); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /* |
@@ -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,814 +21,814 @@ 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 $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 | - try { |
|
141 | - $this->__construct( absint( $this->id ) ); |
|
142 | - } catch ( Exception $e ) { |
|
143 | - $this->set_id( 0 ); |
|
144 | - $this->set_object_read( true ); |
|
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 ) { |
|
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.', 'getpaid' ), $key ), '1.0.19' ); |
|
342 | - |
|
343 | - return true; |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Get Meta Data by Key. |
|
348 | - * |
|
349 | - * @since 1.0.19 |
|
350 | - * @param string $key Meta Key. |
|
351 | - * @param bool $single return first found meta with key, or all with $key. |
|
352 | - * @param string $context What the value is for. Valid values are view and edit. |
|
353 | - * @return mixed |
|
354 | - */ |
|
355 | - public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
356 | - |
|
357 | - // Check if this is an internal meta key. |
|
358 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
359 | - $function = 'get_' . $key; |
|
360 | - |
|
361 | - if ( is_callable( array( $this, $function ) ) ) { |
|
362 | - return $this->{$function}(); |
|
363 | - } |
|
364 | - } |
|
365 | - |
|
366 | - // Read the meta data if not yet read. |
|
367 | - $this->maybe_read_meta_data(); |
|
368 | - $meta_data = $this->get_meta_data(); |
|
369 | - $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
370 | - $value = $single ? '' : array(); |
|
371 | - |
|
372 | - if ( ! empty( $array_keys ) ) { |
|
373 | - // 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()). |
|
374 | - if ( $single ) { |
|
375 | - $value = $meta_data[ current( $array_keys ) ]->value; |
|
376 | - } else { |
|
377 | - $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
378 | - } |
|
379 | - } |
|
380 | - |
|
381 | - if ( 'view' === $context ) { |
|
382 | - $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
383 | - } |
|
384 | - |
|
385 | - return $value; |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * See if meta data exists, since get_meta always returns a '' or array(). |
|
390 | - * |
|
391 | - * @since 1.0.19 |
|
392 | - * @param string $key Meta Key. |
|
393 | - * @return boolean |
|
394 | - */ |
|
395 | - public function meta_exists( $key = '' ) { |
|
396 | - $this->maybe_read_meta_data(); |
|
397 | - $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
398 | - return in_array( $key, $array_keys, true ); |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * Set all meta data from array. |
|
403 | - * |
|
404 | - * @since 1.0.19 |
|
405 | - * @param array $data Key/Value pairs. |
|
406 | - */ |
|
407 | - public function set_meta_data( $data ) { |
|
408 | - if ( ! empty( $data ) && is_array( $data ) ) { |
|
409 | - $this->maybe_read_meta_data(); |
|
410 | - foreach ( $data as $meta ) { |
|
411 | - $meta = (array) $meta; |
|
412 | - if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
413 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
414 | - array( |
|
415 | - 'id' => $meta['id'], |
|
416 | - 'key' => $meta['key'], |
|
417 | - 'value' => $meta['value'], |
|
418 | - ) |
|
419 | - ); |
|
420 | - } |
|
421 | - } |
|
422 | - } |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
426 | - * Add meta data. |
|
427 | - * |
|
428 | - * @since 1.0.19 |
|
429 | - * |
|
430 | - * @param string $key Meta key. |
|
431 | - * @param string|array $value Meta value. |
|
432 | - * @param bool $unique Should this be a unique key?. |
|
433 | - */ |
|
434 | - public function add_meta_data( $key, $value, $unique = false ) { |
|
435 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
436 | - $function = 'set_' . $key; |
|
437 | - |
|
438 | - if ( is_callable( array( $this, $function ) ) ) { |
|
439 | - return $this->{$function}( $value ); |
|
440 | - } |
|
441 | - } |
|
442 | - |
|
443 | - $this->maybe_read_meta_data(); |
|
444 | - if ( $unique ) { |
|
445 | - $this->delete_meta_data( $key ); |
|
446 | - } |
|
447 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
448 | - array( |
|
449 | - 'key' => $key, |
|
450 | - 'value' => $value, |
|
451 | - ) |
|
452 | - ); |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Update meta data by key or ID, if provided. |
|
457 | - * |
|
458 | - * @since 1.0.19 |
|
459 | - * |
|
460 | - * @param string $key Meta key. |
|
461 | - * @param string|array $value Meta value. |
|
462 | - * @param int $meta_id Meta ID. |
|
463 | - */ |
|
464 | - public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
465 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
466 | - $function = 'set_' . $key; |
|
467 | - |
|
468 | - if ( is_callable( array( $this, $function ) ) ) { |
|
469 | - return $this->{$function}( $value ); |
|
470 | - } |
|
471 | - } |
|
472 | - |
|
473 | - $this->maybe_read_meta_data(); |
|
474 | - |
|
475 | - $array_key = false; |
|
476 | - |
|
477 | - if ( $meta_id ) { |
|
478 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
479 | - $array_key = $array_keys ? current( $array_keys ) : false; |
|
480 | - } else { |
|
481 | - // Find matches by key. |
|
482 | - $matches = array(); |
|
483 | - foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
484 | - if ( $meta->key === $key ) { |
|
485 | - $matches[] = $meta_data_array_key; |
|
486 | - } |
|
487 | - } |
|
488 | - |
|
489 | - if ( ! empty( $matches ) ) { |
|
490 | - // Set matches to null so only one key gets the new value. |
|
491 | - foreach ( $matches as $meta_data_array_key ) { |
|
492 | - $this->meta_data[ $meta_data_array_key ]->value = null; |
|
493 | - } |
|
494 | - $array_key = current( $matches ); |
|
495 | - } |
|
496 | - } |
|
497 | - |
|
498 | - if ( false !== $array_key ) { |
|
499 | - $meta = $this->meta_data[ $array_key ]; |
|
500 | - $meta->key = $key; |
|
501 | - $meta->value = $value; |
|
502 | - } else { |
|
503 | - $this->add_meta_data( $key, $value, true ); |
|
504 | - } |
|
505 | - } |
|
506 | - |
|
507 | - /** |
|
508 | - * Delete meta data. |
|
509 | - * |
|
510 | - * @since 1.0.19 |
|
511 | - * @param string $key Meta key. |
|
512 | - */ |
|
513 | - public function delete_meta_data( $key ) { |
|
514 | - $this->maybe_read_meta_data(); |
|
515 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
516 | - |
|
517 | - if ( $array_keys ) { |
|
518 | - foreach ( $array_keys as $array_key ) { |
|
519 | - $this->meta_data[ $array_key ]->value = null; |
|
520 | - } |
|
521 | - } |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * Delete meta data. |
|
526 | - * |
|
527 | - * @since 1.0.19 |
|
528 | - * @param int $mid Meta ID. |
|
529 | - */ |
|
530 | - public function delete_meta_data_by_mid( $mid ) { |
|
531 | - $this->maybe_read_meta_data(); |
|
532 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
533 | - |
|
534 | - if ( $array_keys ) { |
|
535 | - foreach ( $array_keys as $array_key ) { |
|
536 | - $this->meta_data[ $array_key ]->value = null; |
|
537 | - } |
|
538 | - } |
|
539 | - } |
|
540 | - |
|
541 | - /** |
|
542 | - * Read meta data if null. |
|
543 | - * |
|
544 | - * @since 1.0.19 |
|
545 | - */ |
|
546 | - protected function maybe_read_meta_data() { |
|
547 | - if ( is_null( $this->meta_data ) ) { |
|
548 | - $this->read_meta_data(); |
|
549 | - } |
|
550 | - } |
|
551 | - |
|
552 | - /** |
|
553 | - * Read Meta Data from the database. Ignore any internal properties. |
|
554 | - * Uses it's own caches because get_metadata does not provide meta_ids. |
|
555 | - * |
|
556 | - * @since 1.0.19 |
|
557 | - * @param bool $force_read True to force a new DB read (and update cache). |
|
558 | - */ |
|
559 | - public function read_meta_data( $force_read = false ) { |
|
560 | - $this->meta_data = array(); |
|
561 | - $cache_loaded = false; |
|
562 | - |
|
563 | - if ( ! $this->get_id() ) { |
|
564 | - return; |
|
565 | - } |
|
566 | - |
|
567 | - if ( ! $this->data_store ) { |
|
568 | - return; |
|
569 | - } |
|
570 | - |
|
571 | - if ( ! empty( $this->cache_group ) ) { |
|
572 | - $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(); |
|
573 | - } |
|
574 | - |
|
575 | - if ( ! $force_read ) { |
|
576 | - if ( ! empty( $this->cache_group ) ) { |
|
577 | - $cached_meta = wp_cache_get( $cache_key, $this->cache_group ); |
|
578 | - $cache_loaded = ! empty( $cached_meta ); |
|
579 | - } |
|
580 | - } |
|
581 | - |
|
582 | - $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this ); |
|
583 | - if ( $raw_meta_data ) { |
|
584 | - foreach ( $raw_meta_data as $meta ) { |
|
585 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
586 | - array( |
|
587 | - 'id' => (int) $meta->meta_id, |
|
588 | - 'key' => $meta->meta_key, |
|
589 | - 'value' => maybe_unserialize( $meta->meta_value ), |
|
590 | - ) |
|
591 | - ); |
|
592 | - } |
|
593 | - |
|
594 | - if ( ! $cache_loaded && ! empty( $this->cache_group ) ) { |
|
595 | - wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
596 | - } |
|
597 | - } |
|
598 | - } |
|
599 | - |
|
600 | - /** |
|
601 | - * Update Meta Data in the database. |
|
602 | - * |
|
603 | - * @since 1.0.19 |
|
604 | - */ |
|
605 | - public function save_meta_data() { |
|
606 | - if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
607 | - return; |
|
608 | - } |
|
609 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
610 | - if ( is_null( $meta->value ) ) { |
|
611 | - if ( ! empty( $meta->id ) ) { |
|
612 | - $this->data_store->delete_meta( $this, $meta ); |
|
613 | - unset( $this->meta_data[ $array_key ] ); |
|
614 | - } |
|
615 | - } elseif ( empty( $meta->id ) ) { |
|
616 | - $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
617 | - $meta->apply_changes(); |
|
618 | - } else { |
|
619 | - if ( $meta->get_changes() ) { |
|
620 | - $this->data_store->update_meta( $this, $meta ); |
|
621 | - $meta->apply_changes(); |
|
622 | - } |
|
623 | - } |
|
624 | - } |
|
625 | - if ( ! empty( $this->cache_group ) ) { |
|
626 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
627 | - wp_cache_delete( $cache_key, $this->cache_group ); |
|
628 | - } |
|
629 | - } |
|
630 | - |
|
631 | - /** |
|
632 | - * Set ID. |
|
633 | - * |
|
634 | - * @since 1.0.19 |
|
635 | - * @param int $id ID. |
|
636 | - */ |
|
637 | - public function set_id( $id ) { |
|
638 | - $this->id = absint( $id ); |
|
639 | - } |
|
640 | - |
|
641 | - /** |
|
642 | - * Sets item status. |
|
643 | - * |
|
644 | - * @since 1.0.19 |
|
645 | - * @param string $status New status. |
|
646 | - * @return array details of change. |
|
647 | - */ |
|
648 | - public function set_status( $status ) { |
|
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 $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 | + try { |
|
141 | + $this->__construct( absint( $this->id ) ); |
|
142 | + } catch ( Exception $e ) { |
|
143 | + $this->set_id( 0 ); |
|
144 | + $this->set_object_read( true ); |
|
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 ) { |
|
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.', 'getpaid' ), $key ), '1.0.19' ); |
|
342 | + |
|
343 | + return true; |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Get Meta Data by Key. |
|
348 | + * |
|
349 | + * @since 1.0.19 |
|
350 | + * @param string $key Meta Key. |
|
351 | + * @param bool $single return first found meta with key, or all with $key. |
|
352 | + * @param string $context What the value is for. Valid values are view and edit. |
|
353 | + * @return mixed |
|
354 | + */ |
|
355 | + public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
356 | + |
|
357 | + // Check if this is an internal meta key. |
|
358 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
359 | + $function = 'get_' . $key; |
|
360 | + |
|
361 | + if ( is_callable( array( $this, $function ) ) ) { |
|
362 | + return $this->{$function}(); |
|
363 | + } |
|
364 | + } |
|
365 | + |
|
366 | + // Read the meta data if not yet read. |
|
367 | + $this->maybe_read_meta_data(); |
|
368 | + $meta_data = $this->get_meta_data(); |
|
369 | + $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
370 | + $value = $single ? '' : array(); |
|
371 | + |
|
372 | + if ( ! empty( $array_keys ) ) { |
|
373 | + // 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()). |
|
374 | + if ( $single ) { |
|
375 | + $value = $meta_data[ current( $array_keys ) ]->value; |
|
376 | + } else { |
|
377 | + $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
378 | + } |
|
379 | + } |
|
380 | + |
|
381 | + if ( 'view' === $context ) { |
|
382 | + $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
383 | + } |
|
384 | + |
|
385 | + return $value; |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * See if meta data exists, since get_meta always returns a '' or array(). |
|
390 | + * |
|
391 | + * @since 1.0.19 |
|
392 | + * @param string $key Meta Key. |
|
393 | + * @return boolean |
|
394 | + */ |
|
395 | + public function meta_exists( $key = '' ) { |
|
396 | + $this->maybe_read_meta_data(); |
|
397 | + $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
398 | + return in_array( $key, $array_keys, true ); |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * Set all meta data from array. |
|
403 | + * |
|
404 | + * @since 1.0.19 |
|
405 | + * @param array $data Key/Value pairs. |
|
406 | + */ |
|
407 | + public function set_meta_data( $data ) { |
|
408 | + if ( ! empty( $data ) && is_array( $data ) ) { |
|
409 | + $this->maybe_read_meta_data(); |
|
410 | + foreach ( $data as $meta ) { |
|
411 | + $meta = (array) $meta; |
|
412 | + if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
413 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
414 | + array( |
|
415 | + 'id' => $meta['id'], |
|
416 | + 'key' => $meta['key'], |
|
417 | + 'value' => $meta['value'], |
|
418 | + ) |
|
419 | + ); |
|
420 | + } |
|
421 | + } |
|
422 | + } |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | + * Add meta data. |
|
427 | + * |
|
428 | + * @since 1.0.19 |
|
429 | + * |
|
430 | + * @param string $key Meta key. |
|
431 | + * @param string|array $value Meta value. |
|
432 | + * @param bool $unique Should this be a unique key?. |
|
433 | + */ |
|
434 | + public function add_meta_data( $key, $value, $unique = false ) { |
|
435 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
436 | + $function = 'set_' . $key; |
|
437 | + |
|
438 | + if ( is_callable( array( $this, $function ) ) ) { |
|
439 | + return $this->{$function}( $value ); |
|
440 | + } |
|
441 | + } |
|
442 | + |
|
443 | + $this->maybe_read_meta_data(); |
|
444 | + if ( $unique ) { |
|
445 | + $this->delete_meta_data( $key ); |
|
446 | + } |
|
447 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
448 | + array( |
|
449 | + 'key' => $key, |
|
450 | + 'value' => $value, |
|
451 | + ) |
|
452 | + ); |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Update meta data by key or ID, if provided. |
|
457 | + * |
|
458 | + * @since 1.0.19 |
|
459 | + * |
|
460 | + * @param string $key Meta key. |
|
461 | + * @param string|array $value Meta value. |
|
462 | + * @param int $meta_id Meta ID. |
|
463 | + */ |
|
464 | + public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
465 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
466 | + $function = 'set_' . $key; |
|
467 | + |
|
468 | + if ( is_callable( array( $this, $function ) ) ) { |
|
469 | + return $this->{$function}( $value ); |
|
470 | + } |
|
471 | + } |
|
472 | + |
|
473 | + $this->maybe_read_meta_data(); |
|
474 | + |
|
475 | + $array_key = false; |
|
476 | + |
|
477 | + if ( $meta_id ) { |
|
478 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
479 | + $array_key = $array_keys ? current( $array_keys ) : false; |
|
480 | + } else { |
|
481 | + // Find matches by key. |
|
482 | + $matches = array(); |
|
483 | + foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
484 | + if ( $meta->key === $key ) { |
|
485 | + $matches[] = $meta_data_array_key; |
|
486 | + } |
|
487 | + } |
|
488 | + |
|
489 | + if ( ! empty( $matches ) ) { |
|
490 | + // Set matches to null so only one key gets the new value. |
|
491 | + foreach ( $matches as $meta_data_array_key ) { |
|
492 | + $this->meta_data[ $meta_data_array_key ]->value = null; |
|
493 | + } |
|
494 | + $array_key = current( $matches ); |
|
495 | + } |
|
496 | + } |
|
497 | + |
|
498 | + if ( false !== $array_key ) { |
|
499 | + $meta = $this->meta_data[ $array_key ]; |
|
500 | + $meta->key = $key; |
|
501 | + $meta->value = $value; |
|
502 | + } else { |
|
503 | + $this->add_meta_data( $key, $value, true ); |
|
504 | + } |
|
505 | + } |
|
506 | + |
|
507 | + /** |
|
508 | + * Delete meta data. |
|
509 | + * |
|
510 | + * @since 1.0.19 |
|
511 | + * @param string $key Meta key. |
|
512 | + */ |
|
513 | + public function delete_meta_data( $key ) { |
|
514 | + $this->maybe_read_meta_data(); |
|
515 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
516 | + |
|
517 | + if ( $array_keys ) { |
|
518 | + foreach ( $array_keys as $array_key ) { |
|
519 | + $this->meta_data[ $array_key ]->value = null; |
|
520 | + } |
|
521 | + } |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * Delete meta data. |
|
526 | + * |
|
527 | + * @since 1.0.19 |
|
528 | + * @param int $mid Meta ID. |
|
529 | + */ |
|
530 | + public function delete_meta_data_by_mid( $mid ) { |
|
531 | + $this->maybe_read_meta_data(); |
|
532 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
533 | + |
|
534 | + if ( $array_keys ) { |
|
535 | + foreach ( $array_keys as $array_key ) { |
|
536 | + $this->meta_data[ $array_key ]->value = null; |
|
537 | + } |
|
538 | + } |
|
539 | + } |
|
540 | + |
|
541 | + /** |
|
542 | + * Read meta data if null. |
|
543 | + * |
|
544 | + * @since 1.0.19 |
|
545 | + */ |
|
546 | + protected function maybe_read_meta_data() { |
|
547 | + if ( is_null( $this->meta_data ) ) { |
|
548 | + $this->read_meta_data(); |
|
549 | + } |
|
550 | + } |
|
551 | + |
|
552 | + /** |
|
553 | + * Read Meta Data from the database. Ignore any internal properties. |
|
554 | + * Uses it's own caches because get_metadata does not provide meta_ids. |
|
555 | + * |
|
556 | + * @since 1.0.19 |
|
557 | + * @param bool $force_read True to force a new DB read (and update cache). |
|
558 | + */ |
|
559 | + public function read_meta_data( $force_read = false ) { |
|
560 | + $this->meta_data = array(); |
|
561 | + $cache_loaded = false; |
|
562 | + |
|
563 | + if ( ! $this->get_id() ) { |
|
564 | + return; |
|
565 | + } |
|
566 | + |
|
567 | + if ( ! $this->data_store ) { |
|
568 | + return; |
|
569 | + } |
|
570 | + |
|
571 | + if ( ! empty( $this->cache_group ) ) { |
|
572 | + $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(); |
|
573 | + } |
|
574 | + |
|
575 | + if ( ! $force_read ) { |
|
576 | + if ( ! empty( $this->cache_group ) ) { |
|
577 | + $cached_meta = wp_cache_get( $cache_key, $this->cache_group ); |
|
578 | + $cache_loaded = ! empty( $cached_meta ); |
|
579 | + } |
|
580 | + } |
|
581 | + |
|
582 | + $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this ); |
|
583 | + if ( $raw_meta_data ) { |
|
584 | + foreach ( $raw_meta_data as $meta ) { |
|
585 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
586 | + array( |
|
587 | + 'id' => (int) $meta->meta_id, |
|
588 | + 'key' => $meta->meta_key, |
|
589 | + 'value' => maybe_unserialize( $meta->meta_value ), |
|
590 | + ) |
|
591 | + ); |
|
592 | + } |
|
593 | + |
|
594 | + if ( ! $cache_loaded && ! empty( $this->cache_group ) ) { |
|
595 | + wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
596 | + } |
|
597 | + } |
|
598 | + } |
|
599 | + |
|
600 | + /** |
|
601 | + * Update Meta Data in the database. |
|
602 | + * |
|
603 | + * @since 1.0.19 |
|
604 | + */ |
|
605 | + public function save_meta_data() { |
|
606 | + if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
607 | + return; |
|
608 | + } |
|
609 | + foreach ( $this->meta_data as $array_key => $meta ) { |
|
610 | + if ( is_null( $meta->value ) ) { |
|
611 | + if ( ! empty( $meta->id ) ) { |
|
612 | + $this->data_store->delete_meta( $this, $meta ); |
|
613 | + unset( $this->meta_data[ $array_key ] ); |
|
614 | + } |
|
615 | + } elseif ( empty( $meta->id ) ) { |
|
616 | + $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
617 | + $meta->apply_changes(); |
|
618 | + } else { |
|
619 | + if ( $meta->get_changes() ) { |
|
620 | + $this->data_store->update_meta( $this, $meta ); |
|
621 | + $meta->apply_changes(); |
|
622 | + } |
|
623 | + } |
|
624 | + } |
|
625 | + if ( ! empty( $this->cache_group ) ) { |
|
626 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
627 | + wp_cache_delete( $cache_key, $this->cache_group ); |
|
628 | + } |
|
629 | + } |
|
630 | + |
|
631 | + /** |
|
632 | + * Set ID. |
|
633 | + * |
|
634 | + * @since 1.0.19 |
|
635 | + * @param int $id ID. |
|
636 | + */ |
|
637 | + public function set_id( $id ) { |
|
638 | + $this->id = absint( $id ); |
|
639 | + } |
|
640 | + |
|
641 | + /** |
|
642 | + * Sets item status. |
|
643 | + * |
|
644 | + * @since 1.0.19 |
|
645 | + * @param string $status New status. |
|
646 | + * @return array details of change. |
|
647 | + */ |
|
648 | + public function set_status( $status ) { |
|
649 | 649 | $old_status = $this->get_status(); |
650 | 650 | |
651 | 651 | $this->set_prop( 'status', $status ); |
652 | 652 | |
653 | - return array( |
|
654 | - 'from' => $old_status, |
|
655 | - 'to' => $status, |
|
656 | - ); |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * Set all props to default values. |
|
661 | - * |
|
662 | - * @since 1.0.19 |
|
663 | - */ |
|
664 | - public function set_defaults() { |
|
665 | - $this->data = $this->default_data; |
|
666 | - $this->changes = array(); |
|
667 | - $this->set_object_read( false ); |
|
668 | - } |
|
669 | - |
|
670 | - /** |
|
671 | - * Set object read property. |
|
672 | - * |
|
673 | - * @since 1.0.19 |
|
674 | - * @param boolean $read Should read?. |
|
675 | - */ |
|
676 | - public function set_object_read( $read = true ) { |
|
677 | - $this->object_read = (bool) $read; |
|
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * Get object read property. |
|
682 | - * |
|
683 | - * @since 1.0.19 |
|
684 | - * @return boolean |
|
685 | - */ |
|
686 | - public function get_object_read() { |
|
687 | - return (bool) $this->object_read; |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Set a collection of props in one go, collect any errors, and return the result. |
|
692 | - * Only sets using public methods. |
|
693 | - * |
|
694 | - * @since 1.0.19 |
|
695 | - * |
|
696 | - * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
697 | - * @param string $context In what context to run this. |
|
698 | - * |
|
699 | - * @return bool|WP_Error |
|
700 | - */ |
|
701 | - public function set_props( $props, $context = 'set' ) { |
|
702 | - $errors = false; |
|
703 | - |
|
704 | - foreach ( $props as $prop => $value ) { |
|
705 | - try { |
|
706 | - /** |
|
707 | - * Checks if the prop being set is allowed, and the value is not null. |
|
708 | - */ |
|
709 | - if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
710 | - continue; |
|
711 | - } |
|
712 | - $setter = "set_$prop"; |
|
713 | - |
|
714 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
715 | - $this->{$setter}( $value ); |
|
716 | - } |
|
717 | - } catch ( Exception $e ) { |
|
718 | - if ( ! $errors ) { |
|
719 | - $errors = new WP_Error(); |
|
720 | - } |
|
721 | - $errors->add( $e->getCode(), $e->getMessage() ); |
|
722 | - $this->last_error = $e->getMessage(); |
|
723 | - } |
|
724 | - } |
|
725 | - |
|
726 | - return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
727 | - } |
|
728 | - |
|
729 | - /** |
|
730 | - * Sets a prop for a setter method. |
|
731 | - * |
|
732 | - * This stores changes in a special array so we can track what needs saving |
|
733 | - * the the DB later. |
|
734 | - * |
|
735 | - * @since 1.0.19 |
|
736 | - * @param string $prop Name of prop to set. |
|
737 | - * @param mixed $value Value of the prop. |
|
738 | - */ |
|
739 | - protected function set_prop( $prop, $value ) { |
|
740 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
741 | - if ( true === $this->object_read ) { |
|
742 | - if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
743 | - $this->changes[ $prop ] = $value; |
|
744 | - } |
|
745 | - } else { |
|
746 | - $this->data[ $prop ] = $value; |
|
747 | - } |
|
748 | - } |
|
749 | - } |
|
750 | - |
|
751 | - /** |
|
752 | - * Return data changes only. |
|
753 | - * |
|
754 | - * @since 1.0.19 |
|
755 | - * @return array |
|
756 | - */ |
|
757 | - public function get_changes() { |
|
758 | - return $this->changes; |
|
759 | - } |
|
760 | - |
|
761 | - /** |
|
762 | - * Merge changes with data and clear. |
|
763 | - * |
|
764 | - * @since 1.0.19 |
|
765 | - */ |
|
766 | - public function apply_changes() { |
|
767 | - $this->data = array_replace_recursive( $this->data, $this->changes ); |
|
768 | - $this->changes = array(); |
|
769 | - } |
|
770 | - |
|
771 | - /** |
|
772 | - * Prefix for action and filter hooks on data. |
|
773 | - * |
|
774 | - * @since 1.0.19 |
|
775 | - * @return string |
|
776 | - */ |
|
777 | - protected function get_hook_prefix() { |
|
778 | - return 'wpinv_get_' . $this->object_type . '_'; |
|
779 | - } |
|
780 | - |
|
781 | - /** |
|
782 | - * Gets a prop for a getter method. |
|
783 | - * |
|
784 | - * Gets the value from either current pending changes, or the data itself. |
|
785 | - * Context controls what happens to the value before it's returned. |
|
786 | - * |
|
787 | - * @since 1.0.19 |
|
788 | - * @param string $prop Name of prop to get. |
|
789 | - * @param string $context What the value is for. Valid values are view and edit. |
|
790 | - * @return mixed |
|
791 | - */ |
|
792 | - protected function get_prop( $prop, $context = 'view' ) { |
|
793 | - $value = null; |
|
794 | - |
|
795 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
796 | - $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
797 | - |
|
798 | - if ( 'view' === $context ) { |
|
799 | - $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
800 | - } |
|
801 | - } |
|
802 | - |
|
803 | - return $value; |
|
804 | - } |
|
805 | - |
|
806 | - /** |
|
807 | - * Sets a date prop whilst handling formatting and datetime objects. |
|
808 | - * |
|
809 | - * @since 1.0.19 |
|
810 | - * @param string $prop Name of prop to set. |
|
811 | - * @param string|integer $value Value of the prop. |
|
812 | - */ |
|
813 | - protected function set_date_prop( $prop, $value ) { |
|
814 | - |
|
815 | - if ( empty( $value ) ) { |
|
816 | - $this->set_prop( $prop, null ); |
|
817 | - return; |
|
818 | - } |
|
819 | - $this->set_prop( $prop, $value ); |
|
820 | - |
|
821 | - } |
|
822 | - |
|
823 | - /** |
|
824 | - * When invalid data is found, throw an exception unless reading from the DB. |
|
825 | - * |
|
826 | - * @throws Exception Data Exception. |
|
827 | - * @since 1.0.19 |
|
828 | - * @param string $code Error code. |
|
829 | - * @param string $message Error message. |
|
830 | - */ |
|
831 | - protected function error( $code, $message ) { |
|
832 | - throw new Exception( $message, $code ); |
|
833 | - } |
|
653 | + return array( |
|
654 | + 'from' => $old_status, |
|
655 | + 'to' => $status, |
|
656 | + ); |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * Set all props to default values. |
|
661 | + * |
|
662 | + * @since 1.0.19 |
|
663 | + */ |
|
664 | + public function set_defaults() { |
|
665 | + $this->data = $this->default_data; |
|
666 | + $this->changes = array(); |
|
667 | + $this->set_object_read( false ); |
|
668 | + } |
|
669 | + |
|
670 | + /** |
|
671 | + * Set object read property. |
|
672 | + * |
|
673 | + * @since 1.0.19 |
|
674 | + * @param boolean $read Should read?. |
|
675 | + */ |
|
676 | + public function set_object_read( $read = true ) { |
|
677 | + $this->object_read = (bool) $read; |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * Get object read property. |
|
682 | + * |
|
683 | + * @since 1.0.19 |
|
684 | + * @return boolean |
|
685 | + */ |
|
686 | + public function get_object_read() { |
|
687 | + return (bool) $this->object_read; |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Set a collection of props in one go, collect any errors, and return the result. |
|
692 | + * Only sets using public methods. |
|
693 | + * |
|
694 | + * @since 1.0.19 |
|
695 | + * |
|
696 | + * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
697 | + * @param string $context In what context to run this. |
|
698 | + * |
|
699 | + * @return bool|WP_Error |
|
700 | + */ |
|
701 | + public function set_props( $props, $context = 'set' ) { |
|
702 | + $errors = false; |
|
703 | + |
|
704 | + foreach ( $props as $prop => $value ) { |
|
705 | + try { |
|
706 | + /** |
|
707 | + * Checks if the prop being set is allowed, and the value is not null. |
|
708 | + */ |
|
709 | + if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
710 | + continue; |
|
711 | + } |
|
712 | + $setter = "set_$prop"; |
|
713 | + |
|
714 | + if ( is_callable( array( $this, $setter ) ) ) { |
|
715 | + $this->{$setter}( $value ); |
|
716 | + } |
|
717 | + } catch ( Exception $e ) { |
|
718 | + if ( ! $errors ) { |
|
719 | + $errors = new WP_Error(); |
|
720 | + } |
|
721 | + $errors->add( $e->getCode(), $e->getMessage() ); |
|
722 | + $this->last_error = $e->getMessage(); |
|
723 | + } |
|
724 | + } |
|
725 | + |
|
726 | + return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
727 | + } |
|
728 | + |
|
729 | + /** |
|
730 | + * Sets a prop for a setter method. |
|
731 | + * |
|
732 | + * This stores changes in a special array so we can track what needs saving |
|
733 | + * the the DB later. |
|
734 | + * |
|
735 | + * @since 1.0.19 |
|
736 | + * @param string $prop Name of prop to set. |
|
737 | + * @param mixed $value Value of the prop. |
|
738 | + */ |
|
739 | + protected function set_prop( $prop, $value ) { |
|
740 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
741 | + if ( true === $this->object_read ) { |
|
742 | + if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
743 | + $this->changes[ $prop ] = $value; |
|
744 | + } |
|
745 | + } else { |
|
746 | + $this->data[ $prop ] = $value; |
|
747 | + } |
|
748 | + } |
|
749 | + } |
|
750 | + |
|
751 | + /** |
|
752 | + * Return data changes only. |
|
753 | + * |
|
754 | + * @since 1.0.19 |
|
755 | + * @return array |
|
756 | + */ |
|
757 | + public function get_changes() { |
|
758 | + return $this->changes; |
|
759 | + } |
|
760 | + |
|
761 | + /** |
|
762 | + * Merge changes with data and clear. |
|
763 | + * |
|
764 | + * @since 1.0.19 |
|
765 | + */ |
|
766 | + public function apply_changes() { |
|
767 | + $this->data = array_replace_recursive( $this->data, $this->changes ); |
|
768 | + $this->changes = array(); |
|
769 | + } |
|
770 | + |
|
771 | + /** |
|
772 | + * Prefix for action and filter hooks on data. |
|
773 | + * |
|
774 | + * @since 1.0.19 |
|
775 | + * @return string |
|
776 | + */ |
|
777 | + protected function get_hook_prefix() { |
|
778 | + return 'wpinv_get_' . $this->object_type . '_'; |
|
779 | + } |
|
780 | + |
|
781 | + /** |
|
782 | + * Gets a prop for a getter method. |
|
783 | + * |
|
784 | + * Gets the value from either current pending changes, or the data itself. |
|
785 | + * Context controls what happens to the value before it's returned. |
|
786 | + * |
|
787 | + * @since 1.0.19 |
|
788 | + * @param string $prop Name of prop to get. |
|
789 | + * @param string $context What the value is for. Valid values are view and edit. |
|
790 | + * @return mixed |
|
791 | + */ |
|
792 | + protected function get_prop( $prop, $context = 'view' ) { |
|
793 | + $value = null; |
|
794 | + |
|
795 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
796 | + $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
797 | + |
|
798 | + if ( 'view' === $context ) { |
|
799 | + $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
800 | + } |
|
801 | + } |
|
802 | + |
|
803 | + return $value; |
|
804 | + } |
|
805 | + |
|
806 | + /** |
|
807 | + * Sets a date prop whilst handling formatting and datetime objects. |
|
808 | + * |
|
809 | + * @since 1.0.19 |
|
810 | + * @param string $prop Name of prop to set. |
|
811 | + * @param string|integer $value Value of the prop. |
|
812 | + */ |
|
813 | + protected function set_date_prop( $prop, $value ) { |
|
814 | + |
|
815 | + if ( empty( $value ) ) { |
|
816 | + $this->set_prop( $prop, null ); |
|
817 | + return; |
|
818 | + } |
|
819 | + $this->set_prop( $prop, $value ); |
|
820 | + |
|
821 | + } |
|
822 | + |
|
823 | + /** |
|
824 | + * When invalid data is found, throw an exception unless reading from the DB. |
|
825 | + * |
|
826 | + * @throws Exception Data Exception. |
|
827 | + * @since 1.0.19 |
|
828 | + * @param string $code Error code. |
|
829 | + * @param string $message Error message. |
|
830 | + */ |
|
831 | + protected function error( $code, $message ) { |
|
832 | + throw new Exception( $message, $code ); |
|
833 | + } |
|
834 | 834 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * |
9 | 9 | */ |
10 | 10 | |
11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
11 | +if (!defined('ABSPATH')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @param int|object|array $read ID to load from the DB (optional) or already queried data. |
119 | 119 | */ |
120 | - public function __construct( $read = 0 ) { |
|
121 | - $this->data = array_merge( $this->data, $this->extra_data ); |
|
120 | + public function __construct($read = 0) { |
|
121 | + $this->data = array_merge($this->data, $this->extra_data); |
|
122 | 122 | $this->default_data = $this->data; |
123 | 123 | } |
124 | 124 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @return array |
129 | 129 | */ |
130 | 130 | public function __sleep() { |
131 | - return array( 'id' ); |
|
131 | + return array('id'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -138,10 +138,10 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function __wakeup() { |
140 | 140 | try { |
141 | - $this->__construct( absint( $this->id ) ); |
|
142 | - } catch ( Exception $e ) { |
|
143 | - $this->set_id( 0 ); |
|
144 | - $this->set_object_read( true ); |
|
141 | + $this->__construct(absint($this->id)); |
|
142 | + } catch (Exception $e) { |
|
143 | + $this->set_id(0); |
|
144 | + $this->set_object_read(true); |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
@@ -152,11 +152,11 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function __clone() { |
154 | 154 | $this->maybe_read_meta_data(); |
155 | - if ( ! empty( $this->meta_data ) ) { |
|
156 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
157 | - $this->meta_data[ $array_key ] = clone $meta; |
|
158 | - if ( ! empty( $meta->id ) ) { |
|
159 | - $this->meta_data[ $array_key ]->id = null; |
|
155 | + if (!empty($this->meta_data)) { |
|
156 | + foreach ($this->meta_data as $array_key => $meta) { |
|
157 | + $this->meta_data[$array_key] = clone $meta; |
|
158 | + if (!empty($meta->id)) { |
|
159 | + $this->meta_data[$array_key]->id = null; |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | } |
@@ -199,8 +199,8 @@ discard block |
||
199 | 199 | * @param string $context View or edit context. |
200 | 200 | * @return string |
201 | 201 | */ |
202 | - public function get_status( $context = 'view' ) { |
|
203 | - return $this->get_prop( 'status', $context ); |
|
202 | + public function get_status($context = 'view') { |
|
203 | + return $this->get_prop('status', $context); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -210,10 +210,10 @@ discard block |
||
210 | 210 | * @param bool $force_delete Should the data be deleted permanently. |
211 | 211 | * @return bool result |
212 | 212 | */ |
213 | - public function delete( $force_delete = false ) { |
|
214 | - if ( $this->data_store ) { |
|
215 | - $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
216 | - $this->set_id( 0 ); |
|
213 | + public function delete($force_delete = false) { |
|
214 | + if ($this->data_store) { |
|
215 | + $this->data_store->delete($this, array('force_delete' => $force_delete)); |
|
216 | + $this->set_id(0); |
|
217 | 217 | return true; |
218 | 218 | } |
219 | 219 | return false; |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @return int |
227 | 227 | */ |
228 | 228 | public function save() { |
229 | - if ( ! $this->data_store ) { |
|
229 | + if (!$this->data_store) { |
|
230 | 230 | return $this->get_id(); |
231 | 231 | } |
232 | 232 | |
@@ -236,12 +236,12 @@ discard block |
||
236 | 236 | * @param GetPaid_Data $this The object being saved. |
237 | 237 | * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
238 | 238 | */ |
239 | - do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
239 | + do_action('getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store); |
|
240 | 240 | |
241 | - if ( $this->get_id() ) { |
|
242 | - $this->data_store->update( $this ); |
|
241 | + if ($this->get_id()) { |
|
242 | + $this->data_store->update($this); |
|
243 | 243 | } else { |
244 | - $this->data_store->create( $this ); |
|
244 | + $this->data_store->create($this); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * @param GetPaid_Data $this The object being saved. |
251 | 251 | * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
252 | 252 | */ |
253 | - do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
253 | + do_action('getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store); |
|
254 | 254 | |
255 | 255 | return $this->get_id(); |
256 | 256 | } |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @return string Data in JSON format. |
263 | 263 | */ |
264 | 264 | public function __toString() { |
265 | - return wp_json_encode( $this->get_data() ); |
|
265 | + return wp_json_encode($this->get_data()); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | * @return array |
273 | 273 | */ |
274 | 274 | public function get_data() { |
275 | - return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
275 | + return array_merge(array('id' => $this->get_id()), $this->data, array('meta_data' => $this->get_meta_data())); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @return array |
283 | 283 | */ |
284 | 284 | public function get_data_keys() { |
285 | - return array_keys( $this->data ); |
|
285 | + return array_keys($this->data); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | * @return array |
293 | 293 | */ |
294 | 294 | public function get_extra_data_keys() { |
295 | - return array_keys( $this->extra_data ); |
|
295 | + return array_keys($this->extra_data); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
@@ -302,8 +302,8 @@ discard block |
||
302 | 302 | * @param mixed $meta Meta value to check. |
303 | 303 | * @return bool |
304 | 304 | */ |
305 | - protected function filter_null_meta( $meta ) { |
|
306 | - return ! is_null( $meta->value ); |
|
305 | + protected function filter_null_meta($meta) { |
|
306 | + return !is_null($meta->value); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | */ |
315 | 315 | public function get_meta_data() { |
316 | 316 | $this->maybe_read_meta_data(); |
317 | - return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
317 | + return array_values(array_filter($this->meta_data, array($this, 'filter_null_meta'))); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | /** |
@@ -324,21 +324,21 @@ discard block |
||
324 | 324 | * @param string $key Key to check. |
325 | 325 | * @return bool true if it's an internal key, false otherwise |
326 | 326 | */ |
327 | - protected function is_internal_meta_key( $key ) { |
|
328 | - $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
327 | + protected function is_internal_meta_key($key) { |
|
328 | + $internal_meta_key = !empty($key) && $this->data_store && in_array($key, $this->data_store->get_internal_meta_keys(), true); |
|
329 | 329 | |
330 | - if ( ! $internal_meta_key ) { |
|
330 | + if (!$internal_meta_key) { |
|
331 | 331 | return false; |
332 | 332 | } |
333 | 333 | |
334 | - $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
334 | + $has_setter_or_getter = is_callable(array($this, 'set_' . $key)) || is_callable(array($this, 'get_' . $key)); |
|
335 | 335 | |
336 | - if ( ! $has_setter_or_getter ) { |
|
336 | + if (!$has_setter_or_getter) { |
|
337 | 337 | return false; |
338 | 338 | } |
339 | 339 | |
340 | 340 | /* translators: %s: $key Key to check */ |
341 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
341 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid'), $key), '1.0.19'); |
|
342 | 342 | |
343 | 343 | return true; |
344 | 344 | } |
@@ -352,13 +352,13 @@ discard block |
||
352 | 352 | * @param string $context What the value is for. Valid values are view and edit. |
353 | 353 | * @return mixed |
354 | 354 | */ |
355 | - public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
355 | + public function get_meta($key = '', $single = true, $context = 'view') { |
|
356 | 356 | |
357 | 357 | // Check if this is an internal meta key. |
358 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
358 | + if ($this->is_internal_meta_key($key)) { |
|
359 | 359 | $function = 'get_' . $key; |
360 | 360 | |
361 | - if ( is_callable( array( $this, $function ) ) ) { |
|
361 | + if (is_callable(array($this, $function))) { |
|
362 | 362 | return $this->{$function}(); |
363 | 363 | } |
364 | 364 | } |
@@ -366,20 +366,20 @@ discard block |
||
366 | 366 | // Read the meta data if not yet read. |
367 | 367 | $this->maybe_read_meta_data(); |
368 | 368 | $meta_data = $this->get_meta_data(); |
369 | - $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
369 | + $array_keys = array_keys(wp_list_pluck($meta_data, 'key'), $key, true); |
|
370 | 370 | $value = $single ? '' : array(); |
371 | 371 | |
372 | - if ( ! empty( $array_keys ) ) { |
|
372 | + if (!empty($array_keys)) { |
|
373 | 373 | // 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()). |
374 | - if ( $single ) { |
|
375 | - $value = $meta_data[ current( $array_keys ) ]->value; |
|
374 | + if ($single) { |
|
375 | + $value = $meta_data[current($array_keys)]->value; |
|
376 | 376 | } else { |
377 | - $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
377 | + $value = array_intersect_key($meta_data, array_flip($array_keys)); |
|
378 | 378 | } |
379 | 379 | } |
380 | 380 | |
381 | - if ( 'view' === $context ) { |
|
382 | - $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
381 | + if ('view' === $context) { |
|
382 | + $value = apply_filters($this->get_hook_prefix() . $key, $value, $this); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | return $value; |
@@ -392,10 +392,10 @@ discard block |
||
392 | 392 | * @param string $key Meta Key. |
393 | 393 | * @return boolean |
394 | 394 | */ |
395 | - public function meta_exists( $key = '' ) { |
|
395 | + public function meta_exists($key = '') { |
|
396 | 396 | $this->maybe_read_meta_data(); |
397 | - $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
398 | - return in_array( $key, $array_keys, true ); |
|
397 | + $array_keys = wp_list_pluck($this->get_meta_data(), 'key'); |
|
398 | + return in_array($key, $array_keys, true); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | /** |
@@ -404,12 +404,12 @@ discard block |
||
404 | 404 | * @since 1.0.19 |
405 | 405 | * @param array $data Key/Value pairs. |
406 | 406 | */ |
407 | - public function set_meta_data( $data ) { |
|
408 | - if ( ! empty( $data ) && is_array( $data ) ) { |
|
407 | + public function set_meta_data($data) { |
|
408 | + if (!empty($data) && is_array($data)) { |
|
409 | 409 | $this->maybe_read_meta_data(); |
410 | - foreach ( $data as $meta ) { |
|
410 | + foreach ($data as $meta) { |
|
411 | 411 | $meta = (array) $meta; |
412 | - if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
412 | + if (isset($meta['key'], $meta['value'], $meta['id'])) { |
|
413 | 413 | $this->meta_data[] = new GetPaid_Meta_Data( |
414 | 414 | array( |
415 | 415 | 'id' => $meta['id'], |
@@ -431,18 +431,18 @@ discard block |
||
431 | 431 | * @param string|array $value Meta value. |
432 | 432 | * @param bool $unique Should this be a unique key?. |
433 | 433 | */ |
434 | - public function add_meta_data( $key, $value, $unique = false ) { |
|
435 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
434 | + public function add_meta_data($key, $value, $unique = false) { |
|
435 | + if ($this->is_internal_meta_key($key)) { |
|
436 | 436 | $function = 'set_' . $key; |
437 | 437 | |
438 | - if ( is_callable( array( $this, $function ) ) ) { |
|
439 | - return $this->{$function}( $value ); |
|
438 | + if (is_callable(array($this, $function))) { |
|
439 | + return $this->{$function}($value); |
|
440 | 440 | } |
441 | 441 | } |
442 | 442 | |
443 | 443 | $this->maybe_read_meta_data(); |
444 | - if ( $unique ) { |
|
445 | - $this->delete_meta_data( $key ); |
|
444 | + if ($unique) { |
|
445 | + $this->delete_meta_data($key); |
|
446 | 446 | } |
447 | 447 | $this->meta_data[] = new GetPaid_Meta_Data( |
448 | 448 | array( |
@@ -461,12 +461,12 @@ discard block |
||
461 | 461 | * @param string|array $value Meta value. |
462 | 462 | * @param int $meta_id Meta ID. |
463 | 463 | */ |
464 | - public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
465 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
464 | + public function update_meta_data($key, $value, $meta_id = 0) { |
|
465 | + if ($this->is_internal_meta_key($key)) { |
|
466 | 466 | $function = 'set_' . $key; |
467 | 467 | |
468 | - if ( is_callable( array( $this, $function ) ) ) { |
|
469 | - return $this->{$function}( $value ); |
|
468 | + if (is_callable(array($this, $function))) { |
|
469 | + return $this->{$function}($value); |
|
470 | 470 | } |
471 | 471 | } |
472 | 472 | |
@@ -474,33 +474,33 @@ discard block |
||
474 | 474 | |
475 | 475 | $array_key = false; |
476 | 476 | |
477 | - if ( $meta_id ) { |
|
478 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
479 | - $array_key = $array_keys ? current( $array_keys ) : false; |
|
477 | + if ($meta_id) { |
|
478 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), $meta_id, true); |
|
479 | + $array_key = $array_keys ? current($array_keys) : false; |
|
480 | 480 | } else { |
481 | 481 | // Find matches by key. |
482 | 482 | $matches = array(); |
483 | - foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
484 | - if ( $meta->key === $key ) { |
|
483 | + foreach ($this->meta_data as $meta_data_array_key => $meta) { |
|
484 | + if ($meta->key === $key) { |
|
485 | 485 | $matches[] = $meta_data_array_key; |
486 | 486 | } |
487 | 487 | } |
488 | 488 | |
489 | - if ( ! empty( $matches ) ) { |
|
489 | + if (!empty($matches)) { |
|
490 | 490 | // Set matches to null so only one key gets the new value. |
491 | - foreach ( $matches as $meta_data_array_key ) { |
|
492 | - $this->meta_data[ $meta_data_array_key ]->value = null; |
|
491 | + foreach ($matches as $meta_data_array_key) { |
|
492 | + $this->meta_data[$meta_data_array_key]->value = null; |
|
493 | 493 | } |
494 | - $array_key = current( $matches ); |
|
494 | + $array_key = current($matches); |
|
495 | 495 | } |
496 | 496 | } |
497 | 497 | |
498 | - if ( false !== $array_key ) { |
|
499 | - $meta = $this->meta_data[ $array_key ]; |
|
498 | + if (false !== $array_key) { |
|
499 | + $meta = $this->meta_data[$array_key]; |
|
500 | 500 | $meta->key = $key; |
501 | 501 | $meta->value = $value; |
502 | 502 | } else { |
503 | - $this->add_meta_data( $key, $value, true ); |
|
503 | + $this->add_meta_data($key, $value, true); |
|
504 | 504 | } |
505 | 505 | } |
506 | 506 | |
@@ -510,13 +510,13 @@ discard block |
||
510 | 510 | * @since 1.0.19 |
511 | 511 | * @param string $key Meta key. |
512 | 512 | */ |
513 | - public function delete_meta_data( $key ) { |
|
513 | + public function delete_meta_data($key) { |
|
514 | 514 | $this->maybe_read_meta_data(); |
515 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
515 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'key'), $key, true); |
|
516 | 516 | |
517 | - if ( $array_keys ) { |
|
518 | - foreach ( $array_keys as $array_key ) { |
|
519 | - $this->meta_data[ $array_key ]->value = null; |
|
517 | + if ($array_keys) { |
|
518 | + foreach ($array_keys as $array_key) { |
|
519 | + $this->meta_data[$array_key]->value = null; |
|
520 | 520 | } |
521 | 521 | } |
522 | 522 | } |
@@ -527,13 +527,13 @@ discard block |
||
527 | 527 | * @since 1.0.19 |
528 | 528 | * @param int $mid Meta ID. |
529 | 529 | */ |
530 | - public function delete_meta_data_by_mid( $mid ) { |
|
530 | + public function delete_meta_data_by_mid($mid) { |
|
531 | 531 | $this->maybe_read_meta_data(); |
532 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
532 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), (int) $mid, true); |
|
533 | 533 | |
534 | - if ( $array_keys ) { |
|
535 | - foreach ( $array_keys as $array_key ) { |
|
536 | - $this->meta_data[ $array_key ]->value = null; |
|
534 | + if ($array_keys) { |
|
535 | + foreach ($array_keys as $array_key) { |
|
536 | + $this->meta_data[$array_key]->value = null; |
|
537 | 537 | } |
538 | 538 | } |
539 | 539 | } |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | * @since 1.0.19 |
545 | 545 | */ |
546 | 546 | protected function maybe_read_meta_data() { |
547 | - if ( is_null( $this->meta_data ) ) { |
|
547 | + if (is_null($this->meta_data)) { |
|
548 | 548 | $this->read_meta_data(); |
549 | 549 | } |
550 | 550 | } |
@@ -556,43 +556,43 @@ discard block |
||
556 | 556 | * @since 1.0.19 |
557 | 557 | * @param bool $force_read True to force a new DB read (and update cache). |
558 | 558 | */ |
559 | - public function read_meta_data( $force_read = false ) { |
|
559 | + public function read_meta_data($force_read = false) { |
|
560 | 560 | $this->meta_data = array(); |
561 | 561 | $cache_loaded = false; |
562 | 562 | |
563 | - if ( ! $this->get_id() ) { |
|
563 | + if (!$this->get_id()) { |
|
564 | 564 | return; |
565 | 565 | } |
566 | 566 | |
567 | - if ( ! $this->data_store ) { |
|
567 | + if (!$this->data_store) { |
|
568 | 568 | return; |
569 | 569 | } |
570 | 570 | |
571 | - if ( ! empty( $this->cache_group ) ) { |
|
572 | - $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(); |
|
571 | + if (!empty($this->cache_group)) { |
|
572 | + $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(); |
|
573 | 573 | } |
574 | 574 | |
575 | - if ( ! $force_read ) { |
|
576 | - if ( ! empty( $this->cache_group ) ) { |
|
577 | - $cached_meta = wp_cache_get( $cache_key, $this->cache_group ); |
|
578 | - $cache_loaded = ! empty( $cached_meta ); |
|
575 | + if (!$force_read) { |
|
576 | + if (!empty($this->cache_group)) { |
|
577 | + $cached_meta = wp_cache_get($cache_key, $this->cache_group); |
|
578 | + $cache_loaded = !empty($cached_meta); |
|
579 | 579 | } |
580 | 580 | } |
581 | 581 | |
582 | - $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this ); |
|
583 | - if ( $raw_meta_data ) { |
|
584 | - foreach ( $raw_meta_data as $meta ) { |
|
582 | + $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta($this); |
|
583 | + if ($raw_meta_data) { |
|
584 | + foreach ($raw_meta_data as $meta) { |
|
585 | 585 | $this->meta_data[] = new GetPaid_Meta_Data( |
586 | 586 | array( |
587 | 587 | 'id' => (int) $meta->meta_id, |
588 | 588 | 'key' => $meta->meta_key, |
589 | - 'value' => maybe_unserialize( $meta->meta_value ), |
|
589 | + 'value' => maybe_unserialize($meta->meta_value), |
|
590 | 590 | ) |
591 | 591 | ); |
592 | 592 | } |
593 | 593 | |
594 | - if ( ! $cache_loaded && ! empty( $this->cache_group ) ) { |
|
595 | - wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
594 | + if (!$cache_loaded && !empty($this->cache_group)) { |
|
595 | + wp_cache_set($cache_key, $raw_meta_data, $this->cache_group); |
|
596 | 596 | } |
597 | 597 | } |
598 | 598 | } |
@@ -603,28 +603,28 @@ discard block |
||
603 | 603 | * @since 1.0.19 |
604 | 604 | */ |
605 | 605 | public function save_meta_data() { |
606 | - if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
606 | + if (!$this->data_store || is_null($this->meta_data)) { |
|
607 | 607 | return; |
608 | 608 | } |
609 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
610 | - if ( is_null( $meta->value ) ) { |
|
611 | - if ( ! empty( $meta->id ) ) { |
|
612 | - $this->data_store->delete_meta( $this, $meta ); |
|
613 | - unset( $this->meta_data[ $array_key ] ); |
|
609 | + foreach ($this->meta_data as $array_key => $meta) { |
|
610 | + if (is_null($meta->value)) { |
|
611 | + if (!empty($meta->id)) { |
|
612 | + $this->data_store->delete_meta($this, $meta); |
|
613 | + unset($this->meta_data[$array_key]); |
|
614 | 614 | } |
615 | - } elseif ( empty( $meta->id ) ) { |
|
616 | - $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
615 | + } elseif (empty($meta->id)) { |
|
616 | + $meta->id = $this->data_store->add_meta($this, $meta); |
|
617 | 617 | $meta->apply_changes(); |
618 | 618 | } else { |
619 | - if ( $meta->get_changes() ) { |
|
620 | - $this->data_store->update_meta( $this, $meta ); |
|
619 | + if ($meta->get_changes()) { |
|
620 | + $this->data_store->update_meta($this, $meta); |
|
621 | 621 | $meta->apply_changes(); |
622 | 622 | } |
623 | 623 | } |
624 | 624 | } |
625 | - if ( ! empty( $this->cache_group ) ) { |
|
626 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
627 | - wp_cache_delete( $cache_key, $this->cache_group ); |
|
625 | + if (!empty($this->cache_group)) { |
|
626 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id(); |
|
627 | + wp_cache_delete($cache_key, $this->cache_group); |
|
628 | 628 | } |
629 | 629 | } |
630 | 630 | |
@@ -634,8 +634,8 @@ discard block |
||
634 | 634 | * @since 1.0.19 |
635 | 635 | * @param int $id ID. |
636 | 636 | */ |
637 | - public function set_id( $id ) { |
|
638 | - $this->id = absint( $id ); |
|
637 | + public function set_id($id) { |
|
638 | + $this->id = absint($id); |
|
639 | 639 | } |
640 | 640 | |
641 | 641 | /** |
@@ -645,10 +645,10 @@ discard block |
||
645 | 645 | * @param string $status New status. |
646 | 646 | * @return array details of change. |
647 | 647 | */ |
648 | - public function set_status( $status ) { |
|
648 | + public function set_status($status) { |
|
649 | 649 | $old_status = $this->get_status(); |
650 | 650 | |
651 | - $this->set_prop( 'status', $status ); |
|
651 | + $this->set_prop('status', $status); |
|
652 | 652 | |
653 | 653 | return array( |
654 | 654 | 'from' => $old_status, |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | public function set_defaults() { |
665 | 665 | $this->data = $this->default_data; |
666 | 666 | $this->changes = array(); |
667 | - $this->set_object_read( false ); |
|
667 | + $this->set_object_read(false); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | /** |
@@ -673,7 +673,7 @@ discard block |
||
673 | 673 | * @since 1.0.19 |
674 | 674 | * @param boolean $read Should read?. |
675 | 675 | */ |
676 | - public function set_object_read( $read = true ) { |
|
676 | + public function set_object_read($read = true) { |
|
677 | 677 | $this->object_read = (bool) $read; |
678 | 678 | } |
679 | 679 | |
@@ -698,32 +698,32 @@ discard block |
||
698 | 698 | * |
699 | 699 | * @return bool|WP_Error |
700 | 700 | */ |
701 | - public function set_props( $props, $context = 'set' ) { |
|
701 | + public function set_props($props, $context = 'set') { |
|
702 | 702 | $errors = false; |
703 | 703 | |
704 | - foreach ( $props as $prop => $value ) { |
|
704 | + foreach ($props as $prop => $value) { |
|
705 | 705 | try { |
706 | 706 | /** |
707 | 707 | * Checks if the prop being set is allowed, and the value is not null. |
708 | 708 | */ |
709 | - if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
709 | + if (is_null($value) || in_array($prop, array('prop', 'date_prop', 'meta_data'), true)) { |
|
710 | 710 | continue; |
711 | 711 | } |
712 | 712 | $setter = "set_$prop"; |
713 | 713 | |
714 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
715 | - $this->{$setter}( $value ); |
|
714 | + if (is_callable(array($this, $setter))) { |
|
715 | + $this->{$setter}($value); |
|
716 | 716 | } |
717 | - } catch ( Exception $e ) { |
|
718 | - if ( ! $errors ) { |
|
717 | + } catch (Exception $e) { |
|
718 | + if (!$errors) { |
|
719 | 719 | $errors = new WP_Error(); |
720 | 720 | } |
721 | - $errors->add( $e->getCode(), $e->getMessage() ); |
|
721 | + $errors->add($e->getCode(), $e->getMessage()); |
|
722 | 722 | $this->last_error = $e->getMessage(); |
723 | 723 | } |
724 | 724 | } |
725 | 725 | |
726 | - return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
726 | + return $errors && count($errors->get_error_codes()) ? $errors : true; |
|
727 | 727 | } |
728 | 728 | |
729 | 729 | /** |
@@ -736,14 +736,14 @@ discard block |
||
736 | 736 | * @param string $prop Name of prop to set. |
737 | 737 | * @param mixed $value Value of the prop. |
738 | 738 | */ |
739 | - protected function set_prop( $prop, $value ) { |
|
740 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
741 | - if ( true === $this->object_read ) { |
|
742 | - if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
743 | - $this->changes[ $prop ] = $value; |
|
739 | + protected function set_prop($prop, $value) { |
|
740 | + if (array_key_exists($prop, $this->data)) { |
|
741 | + if (true === $this->object_read) { |
|
742 | + if ($value !== $this->data[$prop] || array_key_exists($prop, $this->changes)) { |
|
743 | + $this->changes[$prop] = $value; |
|
744 | 744 | } |
745 | 745 | } else { |
746 | - $this->data[ $prop ] = $value; |
|
746 | + $this->data[$prop] = $value; |
|
747 | 747 | } |
748 | 748 | } |
749 | 749 | } |
@@ -764,7 +764,7 @@ discard block |
||
764 | 764 | * @since 1.0.19 |
765 | 765 | */ |
766 | 766 | public function apply_changes() { |
767 | - $this->data = array_replace_recursive( $this->data, $this->changes ); |
|
767 | + $this->data = array_replace_recursive($this->data, $this->changes); |
|
768 | 768 | $this->changes = array(); |
769 | 769 | } |
770 | 770 | |
@@ -789,14 +789,14 @@ discard block |
||
789 | 789 | * @param string $context What the value is for. Valid values are view and edit. |
790 | 790 | * @return mixed |
791 | 791 | */ |
792 | - protected function get_prop( $prop, $context = 'view' ) { |
|
792 | + protected function get_prop($prop, $context = 'view') { |
|
793 | 793 | $value = null; |
794 | 794 | |
795 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
796 | - $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
795 | + if (array_key_exists($prop, $this->data)) { |
|
796 | + $value = array_key_exists($prop, $this->changes) ? $this->changes[$prop] : $this->data[$prop]; |
|
797 | 797 | |
798 | - if ( 'view' === $context ) { |
|
799 | - $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
798 | + if ('view' === $context) { |
|
799 | + $value = apply_filters($this->get_hook_prefix() . $prop, $value, $this); |
|
800 | 800 | } |
801 | 801 | } |
802 | 802 | |
@@ -810,13 +810,13 @@ discard block |
||
810 | 810 | * @param string $prop Name of prop to set. |
811 | 811 | * @param string|integer $value Value of the prop. |
812 | 812 | */ |
813 | - protected function set_date_prop( $prop, $value ) { |
|
813 | + protected function set_date_prop($prop, $value) { |
|
814 | 814 | |
815 | - if ( empty( $value ) ) { |
|
816 | - $this->set_prop( $prop, null ); |
|
815 | + if (empty($value)) { |
|
816 | + $this->set_prop($prop, null); |
|
817 | 817 | return; |
818 | 818 | } |
819 | - $this->set_prop( $prop, $value ); |
|
819 | + $this->set_prop($prop, $value); |
|
820 | 820 | |
821 | 821 | } |
822 | 822 | |
@@ -828,7 +828,7 @@ discard block |
||
828 | 828 | * @param string $code Error code. |
829 | 829 | * @param string $message Error message. |
830 | 830 | */ |
831 | - protected function error( $code, $message ) { |
|
832 | - throw new Exception( $message, $code ); |
|
831 | + protected function error($code, $message) { |
|
832 | + throw new Exception($message, $code); |
|
833 | 833 | } |
834 | 834 | } |
@@ -14,341 +14,341 @@ |
||
14 | 14 | */ |
15 | 15 | class GetPaid_Data_Store_WP { |
16 | 16 | |
17 | - /** |
|
18 | - * Meta type. This should match up with |
|
19 | - * the types available at https://developer.wordpress.org/reference/functions/add_metadata/. |
|
20 | - * WP defines 'post', 'user', 'comment', and 'term'. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $meta_type = 'post'; |
|
25 | - |
|
26 | - /** |
|
27 | - * This only needs set if you are using a custom metadata type. |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $object_id_field_for_meta = ''; |
|
32 | - |
|
33 | - /** |
|
34 | - * Data stored in meta keys, but not considered "meta" for an object. |
|
35 | - * |
|
36 | - * @since 1.0.19 |
|
37 | - * |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - protected $internal_meta_keys = array(); |
|
41 | - |
|
42 | - /** |
|
43 | - * Meta data which should exist in the DB, even if empty. |
|
44 | - * |
|
45 | - * @since 1.0.19 |
|
46 | - * |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - protected $must_exist_meta_keys = array(); |
|
50 | - |
|
51 | - /** |
|
52 | - * A map of meta keys to data props. |
|
53 | - * |
|
54 | - * @since 1.0.19 |
|
55 | - * |
|
56 | - * @var array |
|
57 | - */ |
|
58 | - protected $meta_key_to_props = array(); |
|
59 | - |
|
60 | - /** |
|
61 | - * Returns an array of meta for an object. |
|
62 | - * |
|
63 | - * @since 1.0.19 |
|
64 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
65 | - * @return array |
|
66 | - */ |
|
67 | - public function read_meta( &$object ) { |
|
68 | - global $wpdb; |
|
69 | - $db_info = $this->get_db_info(); |
|
70 | - $raw_meta_data = $wpdb->get_results( |
|
71 | - $wpdb->prepare( |
|
72 | - "SELECT {$db_info['meta_id_field']} as meta_id, meta_key, meta_value |
|
17 | + /** |
|
18 | + * Meta type. This should match up with |
|
19 | + * the types available at https://developer.wordpress.org/reference/functions/add_metadata/. |
|
20 | + * WP defines 'post', 'user', 'comment', and 'term'. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $meta_type = 'post'; |
|
25 | + |
|
26 | + /** |
|
27 | + * This only needs set if you are using a custom metadata type. |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $object_id_field_for_meta = ''; |
|
32 | + |
|
33 | + /** |
|
34 | + * Data stored in meta keys, but not considered "meta" for an object. |
|
35 | + * |
|
36 | + * @since 1.0.19 |
|
37 | + * |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + protected $internal_meta_keys = array(); |
|
41 | + |
|
42 | + /** |
|
43 | + * Meta data which should exist in the DB, even if empty. |
|
44 | + * |
|
45 | + * @since 1.0.19 |
|
46 | + * |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + protected $must_exist_meta_keys = array(); |
|
50 | + |
|
51 | + /** |
|
52 | + * A map of meta keys to data props. |
|
53 | + * |
|
54 | + * @since 1.0.19 |
|
55 | + * |
|
56 | + * @var array |
|
57 | + */ |
|
58 | + protected $meta_key_to_props = array(); |
|
59 | + |
|
60 | + /** |
|
61 | + * Returns an array of meta for an object. |
|
62 | + * |
|
63 | + * @since 1.0.19 |
|
64 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
65 | + * @return array |
|
66 | + */ |
|
67 | + public function read_meta( &$object ) { |
|
68 | + global $wpdb; |
|
69 | + $db_info = $this->get_db_info(); |
|
70 | + $raw_meta_data = $wpdb->get_results( |
|
71 | + $wpdb->prepare( |
|
72 | + "SELECT {$db_info['meta_id_field']} as meta_id, meta_key, meta_value |
|
73 | 73 | FROM {$db_info['table']} |
74 | 74 | WHERE {$db_info['object_id_field']} = %d |
75 | 75 | ORDER BY {$db_info['meta_id_field']}", |
76 | - $object->get_id() |
|
77 | - ) |
|
78 | - ); |
|
79 | - |
|
80 | - $this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys ); |
|
81 | - $meta_data = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) ); |
|
82 | - return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this ); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Deletes meta based on meta ID. |
|
87 | - * |
|
88 | - * @since 1.0.19 |
|
89 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
90 | - * @param stdClass $meta (containing at least ->id). |
|
91 | - */ |
|
92 | - public function delete_meta( &$object, $meta ) { |
|
93 | - delete_metadata_by_mid( $this->meta_type, $meta->id ); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Add new piece of meta. |
|
98 | - * |
|
99 | - * @since 1.0.19 |
|
100 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
101 | - * @param stdClass $meta (containing ->key and ->value). |
|
102 | - * @return int meta ID |
|
103 | - */ |
|
104 | - public function add_meta( &$object, $meta ) { |
|
105 | - return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false ); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Update meta. |
|
110 | - * |
|
111 | - * @since 1.0.19 |
|
112 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
113 | - * @param stdClass $meta (containing ->id, ->key and ->value). |
|
114 | - */ |
|
115 | - public function update_meta( &$object, $meta ) { |
|
116 | - update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key ); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Table structure is slightly different between meta types, this function will return what we need to know. |
|
121 | - * |
|
122 | - * @since 1.0.19 |
|
123 | - * @return array Array elements: table, object_id_field, meta_id_field |
|
124 | - */ |
|
125 | - protected function get_db_info() { |
|
126 | - global $wpdb; |
|
127 | - |
|
128 | - $meta_id_field = 'meta_id'; // users table calls this umeta_id so we need to track this as well. |
|
129 | - $table = $wpdb->prefix; |
|
130 | - |
|
131 | - // If we are dealing with a type of metadata that is not a core type, the table should be prefixed. |
|
132 | - if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) { |
|
133 | - $table .= 'getpaid_'; |
|
134 | - } |
|
135 | - |
|
136 | - $table .= $this->meta_type . 'meta'; |
|
137 | - $object_id_field = $this->meta_type . '_id'; |
|
138 | - |
|
139 | - // Figure out our field names. |
|
140 | - if ( 'user' === $this->meta_type ) { |
|
141 | - $meta_id_field = 'umeta_id'; |
|
142 | - $table = $wpdb->usermeta; |
|
143 | - } |
|
144 | - |
|
145 | - if ( ! empty( $this->object_id_field_for_meta ) ) { |
|
146 | - $object_id_field = $this->object_id_field_for_meta; |
|
147 | - } |
|
148 | - |
|
149 | - return array( |
|
150 | - 'table' => $table, |
|
151 | - 'object_id_field' => $object_id_field, |
|
152 | - 'meta_id_field' => $meta_id_field, |
|
153 | - ); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Internal meta keys we don't want exposed as part of meta_data. This is in |
|
158 | - * addition to all data props with _ prefix. |
|
159 | - * |
|
160 | - * @since 1.0.19 |
|
161 | - * |
|
162 | - * @param string $key Prefix to be added to meta keys. |
|
163 | - * @return string |
|
164 | - */ |
|
165 | - protected function prefix_key( $key ) { |
|
166 | - return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key; |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Callback to remove unwanted meta data. |
|
171 | - * |
|
172 | - * @param object $meta Meta object to check if it should be excluded or not. |
|
173 | - * @return bool |
|
174 | - */ |
|
175 | - protected function exclude_internal_meta_keys( $meta ) { |
|
176 | - return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' ); |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Gets a list of props and meta keys that need updated based on change state |
|
181 | - * or if they are present in the database or not. |
|
182 | - * |
|
183 | - * @param GetPaid_Data $object The GetPaid_Data object. |
|
184 | - * @param array $meta_key_to_props A mapping of meta keys => prop names. |
|
185 | - * @param string $meta_type The internal WP meta type (post, user, etc). |
|
186 | - * @return array A mapping of meta keys => prop names, filtered by ones that should be updated. |
|
187 | - */ |
|
188 | - protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) { |
|
189 | - $props_to_update = array(); |
|
190 | - $changed_props = $object->get_changes(); |
|
191 | - |
|
192 | - // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
193 | - foreach ( $meta_key_to_props as $meta_key => $prop ) { |
|
194 | - if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) { |
|
195 | - $props_to_update[ $meta_key ] = $prop; |
|
196 | - } |
|
197 | - } |
|
198 | - |
|
199 | - return $props_to_update; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Read object data. |
|
204 | - * |
|
205 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
206 | - * @param WP_Post $post_object Post object. |
|
207 | - * @since 1.0.19 |
|
208 | - */ |
|
209 | - protected function read_object_data( &$object, $post_object ) { |
|
210 | - $id = $object->get_id(); |
|
211 | - $props = array(); |
|
212 | - |
|
213 | - foreach ( $this->meta_key_to_props as $meta_key => $prop ) { |
|
214 | - $props[ $prop ] = get_post_meta( $id, $meta_key, true ); |
|
215 | - } |
|
216 | - |
|
217 | - // Set object properties. |
|
218 | - $object->set_props( $props ); |
|
219 | - |
|
220 | - // Gets extra data associated with the object if needed. |
|
221 | - foreach ( $object->get_extra_data_keys() as $key ) { |
|
222 | - $function = 'set_' . $key; |
|
223 | - if ( is_callable( array( $object, $function ) ) ) { |
|
224 | - $object->{$function}( get_post_meta( $object->get_id(), $key, true ) ); |
|
225 | - } |
|
226 | - } |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Helper method that updates all the post meta for an object based on it's settings in the GetPaid_Data class. |
|
231 | - * |
|
232 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
233 | - * @since 1.0.19 |
|
234 | - */ |
|
235 | - protected function update_post_meta( &$object ) { |
|
236 | - |
|
237 | - $updated_props = array(); |
|
238 | - $props_to_update = $this->get_props_to_update( $object, $this->meta_key_to_props ); |
|
239 | - $object_type = $object->get_object_type(); |
|
240 | - |
|
241 | - foreach ( $props_to_update as $meta_key => $prop ) { |
|
242 | - $value = $object->{"get_$prop"}( 'edit' ); |
|
243 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
244 | - |
|
245 | - $updated = $this->update_or_delete_post_meta( $object, $meta_key, $value ); |
|
246 | - |
|
247 | - if ( $updated ) { |
|
248 | - $updated_props[] = $prop; |
|
249 | - } |
|
250 | - } |
|
251 | - |
|
252 | - do_action( "getpaid_{$object_type}_object_updated_props", $object, $updated_props ); |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Update meta data in, or delete it from, the database. |
|
257 | - * |
|
258 | - * Avoids storing meta when it's either an empty string or empty array or null. |
|
259 | - * Other empty values such as numeric 0 should still be stored. |
|
260 | - * Data-stores can force meta to exist using `must_exist_meta_keys`. |
|
261 | - * |
|
262 | - * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist. |
|
263 | - * |
|
264 | - * @param GetPaid_Data $object The GetPaid_Data object. |
|
265 | - * @param string $meta_key Meta key to update. |
|
266 | - * @param mixed $meta_value Value to save. |
|
267 | - * |
|
268 | - * @since 1.0.19 Added to prevent empty meta being stored unless required. |
|
269 | - * |
|
270 | - * @return bool True if updated/deleted. |
|
271 | - */ |
|
272 | - protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) { |
|
273 | - if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) { |
|
274 | - $updated = delete_post_meta( $object->get_id(), $meta_key ); |
|
275 | - } else { |
|
276 | - $updated = update_post_meta( $object->get_id(), $meta_key, $meta_value ); |
|
277 | - } |
|
278 | - |
|
279 | - return (bool) $updated; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Return list of internal meta keys. |
|
284 | - * |
|
285 | - * @since 1.0.19 |
|
286 | - * @return array |
|
287 | - */ |
|
288 | - public function get_internal_meta_keys() { |
|
289 | - return $this->internal_meta_keys; |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Clear any caches. |
|
294 | - * |
|
295 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
296 | - * @since 1.0.19 |
|
297 | - */ |
|
298 | - protected function clear_caches( &$object ) { |
|
299 | - clean_post_cache( $object->get_id() ); |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * Method to delete a data object from the database. |
|
304 | - * |
|
305 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
306 | - * @param array $args Array of args to pass to the delete method. |
|
307 | - * |
|
308 | - * @return void |
|
309 | - */ |
|
310 | - public function delete( &$object, $args = array() ) { |
|
311 | - $id = $object->get_id(); |
|
312 | - $object_type = $object->get_object_type(); |
|
313 | - $args = wp_parse_args( |
|
314 | - $args, |
|
315 | - array( |
|
316 | - 'force_delete' => false, |
|
317 | - ) |
|
318 | - ); |
|
319 | - |
|
320 | - if ( ! $id ) { |
|
321 | - return; |
|
322 | - } |
|
323 | - |
|
324 | - if ( $args['force_delete'] ) { |
|
325 | - wp_delete_post( $id, true ); |
|
326 | - $object->set_id( 0 ); |
|
327 | - do_action( "getpaid_delete_$object_type", $id ); |
|
328 | - } else { |
|
329 | - wp_trash_post( $id ); |
|
330 | - $object->set_status( 'trash' ); |
|
331 | - do_action( "getpaid_trash_$object_type", $id ); |
|
332 | - } |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Get the status to save to the post object. |
|
337 | - * |
|
338 | - * |
|
339 | - * @since 1.0.19 |
|
340 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
341 | - * @return string |
|
342 | - */ |
|
343 | - protected function get_post_status( $object ) { |
|
344 | - $object_status = $object->get_status( 'edit' ); |
|
345 | - $object_type = $object->get_object_type(); |
|
346 | - |
|
347 | - if ( ! $object_status ) { |
|
348 | - $object_status = apply_filters( "getpaid_default_{$object_type}_status", 'draft' ); |
|
349 | - } |
|
350 | - |
|
351 | - return $object_status; |
|
352 | - } |
|
76 | + $object->get_id() |
|
77 | + ) |
|
78 | + ); |
|
79 | + |
|
80 | + $this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys ); |
|
81 | + $meta_data = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) ); |
|
82 | + return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this ); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Deletes meta based on meta ID. |
|
87 | + * |
|
88 | + * @since 1.0.19 |
|
89 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
90 | + * @param stdClass $meta (containing at least ->id). |
|
91 | + */ |
|
92 | + public function delete_meta( &$object, $meta ) { |
|
93 | + delete_metadata_by_mid( $this->meta_type, $meta->id ); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Add new piece of meta. |
|
98 | + * |
|
99 | + * @since 1.0.19 |
|
100 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
101 | + * @param stdClass $meta (containing ->key and ->value). |
|
102 | + * @return int meta ID |
|
103 | + */ |
|
104 | + public function add_meta( &$object, $meta ) { |
|
105 | + return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false ); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Update meta. |
|
110 | + * |
|
111 | + * @since 1.0.19 |
|
112 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
113 | + * @param stdClass $meta (containing ->id, ->key and ->value). |
|
114 | + */ |
|
115 | + public function update_meta( &$object, $meta ) { |
|
116 | + update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key ); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Table structure is slightly different between meta types, this function will return what we need to know. |
|
121 | + * |
|
122 | + * @since 1.0.19 |
|
123 | + * @return array Array elements: table, object_id_field, meta_id_field |
|
124 | + */ |
|
125 | + protected function get_db_info() { |
|
126 | + global $wpdb; |
|
127 | + |
|
128 | + $meta_id_field = 'meta_id'; // users table calls this umeta_id so we need to track this as well. |
|
129 | + $table = $wpdb->prefix; |
|
130 | + |
|
131 | + // If we are dealing with a type of metadata that is not a core type, the table should be prefixed. |
|
132 | + if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) { |
|
133 | + $table .= 'getpaid_'; |
|
134 | + } |
|
135 | + |
|
136 | + $table .= $this->meta_type . 'meta'; |
|
137 | + $object_id_field = $this->meta_type . '_id'; |
|
138 | + |
|
139 | + // Figure out our field names. |
|
140 | + if ( 'user' === $this->meta_type ) { |
|
141 | + $meta_id_field = 'umeta_id'; |
|
142 | + $table = $wpdb->usermeta; |
|
143 | + } |
|
144 | + |
|
145 | + if ( ! empty( $this->object_id_field_for_meta ) ) { |
|
146 | + $object_id_field = $this->object_id_field_for_meta; |
|
147 | + } |
|
148 | + |
|
149 | + return array( |
|
150 | + 'table' => $table, |
|
151 | + 'object_id_field' => $object_id_field, |
|
152 | + 'meta_id_field' => $meta_id_field, |
|
153 | + ); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Internal meta keys we don't want exposed as part of meta_data. This is in |
|
158 | + * addition to all data props with _ prefix. |
|
159 | + * |
|
160 | + * @since 1.0.19 |
|
161 | + * |
|
162 | + * @param string $key Prefix to be added to meta keys. |
|
163 | + * @return string |
|
164 | + */ |
|
165 | + protected function prefix_key( $key ) { |
|
166 | + return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key; |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Callback to remove unwanted meta data. |
|
171 | + * |
|
172 | + * @param object $meta Meta object to check if it should be excluded or not. |
|
173 | + * @return bool |
|
174 | + */ |
|
175 | + protected function exclude_internal_meta_keys( $meta ) { |
|
176 | + return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' ); |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Gets a list of props and meta keys that need updated based on change state |
|
181 | + * or if they are present in the database or not. |
|
182 | + * |
|
183 | + * @param GetPaid_Data $object The GetPaid_Data object. |
|
184 | + * @param array $meta_key_to_props A mapping of meta keys => prop names. |
|
185 | + * @param string $meta_type The internal WP meta type (post, user, etc). |
|
186 | + * @return array A mapping of meta keys => prop names, filtered by ones that should be updated. |
|
187 | + */ |
|
188 | + protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) { |
|
189 | + $props_to_update = array(); |
|
190 | + $changed_props = $object->get_changes(); |
|
191 | + |
|
192 | + // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
193 | + foreach ( $meta_key_to_props as $meta_key => $prop ) { |
|
194 | + if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) { |
|
195 | + $props_to_update[ $meta_key ] = $prop; |
|
196 | + } |
|
197 | + } |
|
198 | + |
|
199 | + return $props_to_update; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Read object data. |
|
204 | + * |
|
205 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
206 | + * @param WP_Post $post_object Post object. |
|
207 | + * @since 1.0.19 |
|
208 | + */ |
|
209 | + protected function read_object_data( &$object, $post_object ) { |
|
210 | + $id = $object->get_id(); |
|
211 | + $props = array(); |
|
212 | + |
|
213 | + foreach ( $this->meta_key_to_props as $meta_key => $prop ) { |
|
214 | + $props[ $prop ] = get_post_meta( $id, $meta_key, true ); |
|
215 | + } |
|
216 | + |
|
217 | + // Set object properties. |
|
218 | + $object->set_props( $props ); |
|
219 | + |
|
220 | + // Gets extra data associated with the object if needed. |
|
221 | + foreach ( $object->get_extra_data_keys() as $key ) { |
|
222 | + $function = 'set_' . $key; |
|
223 | + if ( is_callable( array( $object, $function ) ) ) { |
|
224 | + $object->{$function}( get_post_meta( $object->get_id(), $key, true ) ); |
|
225 | + } |
|
226 | + } |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Helper method that updates all the post meta for an object based on it's settings in the GetPaid_Data class. |
|
231 | + * |
|
232 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
233 | + * @since 1.0.19 |
|
234 | + */ |
|
235 | + protected function update_post_meta( &$object ) { |
|
236 | + |
|
237 | + $updated_props = array(); |
|
238 | + $props_to_update = $this->get_props_to_update( $object, $this->meta_key_to_props ); |
|
239 | + $object_type = $object->get_object_type(); |
|
240 | + |
|
241 | + foreach ( $props_to_update as $meta_key => $prop ) { |
|
242 | + $value = $object->{"get_$prop"}( 'edit' ); |
|
243 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
244 | + |
|
245 | + $updated = $this->update_or_delete_post_meta( $object, $meta_key, $value ); |
|
246 | + |
|
247 | + if ( $updated ) { |
|
248 | + $updated_props[] = $prop; |
|
249 | + } |
|
250 | + } |
|
251 | + |
|
252 | + do_action( "getpaid_{$object_type}_object_updated_props", $object, $updated_props ); |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Update meta data in, or delete it from, the database. |
|
257 | + * |
|
258 | + * Avoids storing meta when it's either an empty string or empty array or null. |
|
259 | + * Other empty values such as numeric 0 should still be stored. |
|
260 | + * Data-stores can force meta to exist using `must_exist_meta_keys`. |
|
261 | + * |
|
262 | + * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist. |
|
263 | + * |
|
264 | + * @param GetPaid_Data $object The GetPaid_Data object. |
|
265 | + * @param string $meta_key Meta key to update. |
|
266 | + * @param mixed $meta_value Value to save. |
|
267 | + * |
|
268 | + * @since 1.0.19 Added to prevent empty meta being stored unless required. |
|
269 | + * |
|
270 | + * @return bool True if updated/deleted. |
|
271 | + */ |
|
272 | + protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) { |
|
273 | + if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) { |
|
274 | + $updated = delete_post_meta( $object->get_id(), $meta_key ); |
|
275 | + } else { |
|
276 | + $updated = update_post_meta( $object->get_id(), $meta_key, $meta_value ); |
|
277 | + } |
|
278 | + |
|
279 | + return (bool) $updated; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Return list of internal meta keys. |
|
284 | + * |
|
285 | + * @since 1.0.19 |
|
286 | + * @return array |
|
287 | + */ |
|
288 | + public function get_internal_meta_keys() { |
|
289 | + return $this->internal_meta_keys; |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Clear any caches. |
|
294 | + * |
|
295 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
296 | + * @since 1.0.19 |
|
297 | + */ |
|
298 | + protected function clear_caches( &$object ) { |
|
299 | + clean_post_cache( $object->get_id() ); |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * Method to delete a data object from the database. |
|
304 | + * |
|
305 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
306 | + * @param array $args Array of args to pass to the delete method. |
|
307 | + * |
|
308 | + * @return void |
|
309 | + */ |
|
310 | + public function delete( &$object, $args = array() ) { |
|
311 | + $id = $object->get_id(); |
|
312 | + $object_type = $object->get_object_type(); |
|
313 | + $args = wp_parse_args( |
|
314 | + $args, |
|
315 | + array( |
|
316 | + 'force_delete' => false, |
|
317 | + ) |
|
318 | + ); |
|
319 | + |
|
320 | + if ( ! $id ) { |
|
321 | + return; |
|
322 | + } |
|
323 | + |
|
324 | + if ( $args['force_delete'] ) { |
|
325 | + wp_delete_post( $id, true ); |
|
326 | + $object->set_id( 0 ); |
|
327 | + do_action( "getpaid_delete_$object_type", $id ); |
|
328 | + } else { |
|
329 | + wp_trash_post( $id ); |
|
330 | + $object->set_status( 'trash' ); |
|
331 | + do_action( "getpaid_trash_$object_type", $id ); |
|
332 | + } |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Get the status to save to the post object. |
|
337 | + * |
|
338 | + * |
|
339 | + * @since 1.0.19 |
|
340 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
341 | + * @return string |
|
342 | + */ |
|
343 | + protected function get_post_status( $object ) { |
|
344 | + $object_status = $object->get_status( 'edit' ); |
|
345 | + $object_type = $object->get_object_type(); |
|
346 | + |
|
347 | + if ( ! $object_status ) { |
|
348 | + $object_status = apply_filters( "getpaid_default_{$object_type}_status", 'draft' ); |
|
349 | + } |
|
350 | + |
|
351 | + return $object_status; |
|
352 | + } |
|
353 | 353 | |
354 | 354 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @version 1.0.19 |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Data_Store_WP class. |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @param GetPaid_Data $object GetPaid_Data object. |
65 | 65 | * @return array |
66 | 66 | */ |
67 | - public function read_meta( &$object ) { |
|
67 | + public function read_meta(&$object) { |
|
68 | 68 | global $wpdb; |
69 | 69 | $db_info = $this->get_db_info(); |
70 | 70 | $raw_meta_data = $wpdb->get_results( |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | ) |
78 | 78 | ); |
79 | 79 | |
80 | - $this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys ); |
|
81 | - $meta_data = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) ); |
|
82 | - return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this ); |
|
80 | + $this->internal_meta_keys = array_merge(array_map(array($this, 'prefix_key'), $object->get_data_keys()), $this->internal_meta_keys); |
|
81 | + $meta_data = array_filter($raw_meta_data, array($this, 'exclude_internal_meta_keys')); |
|
82 | + return apply_filters("getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | * @param GetPaid_Data $object GetPaid_Data object. |
90 | 90 | * @param stdClass $meta (containing at least ->id). |
91 | 91 | */ |
92 | - public function delete_meta( &$object, $meta ) { |
|
93 | - delete_metadata_by_mid( $this->meta_type, $meta->id ); |
|
92 | + public function delete_meta(&$object, $meta) { |
|
93 | + delete_metadata_by_mid($this->meta_type, $meta->id); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | * @param stdClass $meta (containing ->key and ->value). |
102 | 102 | * @return int meta ID |
103 | 103 | */ |
104 | - public function add_meta( &$object, $meta ) { |
|
105 | - return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false ); |
|
104 | + public function add_meta(&$object, $meta) { |
|
105 | + return add_metadata($this->meta_type, $object->get_id(), $meta->key, is_string($meta->value) ? wp_slash($meta->value) : $meta->value, false); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | * @param GetPaid_Data $object GetPaid_Data object. |
113 | 113 | * @param stdClass $meta (containing ->id, ->key and ->value). |
114 | 114 | */ |
115 | - public function update_meta( &$object, $meta ) { |
|
116 | - update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key ); |
|
115 | + public function update_meta(&$object, $meta) { |
|
116 | + update_metadata_by_mid($this->meta_type, $meta->id, $meta->value, $meta->key); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | $table = $wpdb->prefix; |
130 | 130 | |
131 | 131 | // If we are dealing with a type of metadata that is not a core type, the table should be prefixed. |
132 | - if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) { |
|
132 | + if (!in_array($this->meta_type, array('post', 'user', 'comment', 'term'), true)) { |
|
133 | 133 | $table .= 'getpaid_'; |
134 | 134 | } |
135 | 135 | |
@@ -137,12 +137,12 @@ discard block |
||
137 | 137 | $object_id_field = $this->meta_type . '_id'; |
138 | 138 | |
139 | 139 | // Figure out our field names. |
140 | - if ( 'user' === $this->meta_type ) { |
|
140 | + if ('user' === $this->meta_type) { |
|
141 | 141 | $meta_id_field = 'umeta_id'; |
142 | 142 | $table = $wpdb->usermeta; |
143 | 143 | } |
144 | 144 | |
145 | - if ( ! empty( $this->object_id_field_for_meta ) ) { |
|
145 | + if (!empty($this->object_id_field_for_meta)) { |
|
146 | 146 | $object_id_field = $this->object_id_field_for_meta; |
147 | 147 | } |
148 | 148 | |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | * @param string $key Prefix to be added to meta keys. |
163 | 163 | * @return string |
164 | 164 | */ |
165 | - protected function prefix_key( $key ) { |
|
166 | - return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key; |
|
165 | + protected function prefix_key($key) { |
|
166 | + return '_' === substr($key, 0, 1) ? $key : '_' . $key; |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | * @param object $meta Meta object to check if it should be excluded or not. |
173 | 173 | * @return bool |
174 | 174 | */ |
175 | - protected function exclude_internal_meta_keys( $meta ) { |
|
176 | - return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' ); |
|
175 | + protected function exclude_internal_meta_keys($meta) { |
|
176 | + return !in_array($meta->meta_key, $this->internal_meta_keys, true) && 0 !== stripos($meta->meta_key, 'wp_'); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -185,14 +185,14 @@ discard block |
||
185 | 185 | * @param string $meta_type The internal WP meta type (post, user, etc). |
186 | 186 | * @return array A mapping of meta keys => prop names, filtered by ones that should be updated. |
187 | 187 | */ |
188 | - protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) { |
|
188 | + protected function get_props_to_update($object, $meta_key_to_props, $meta_type = 'post') { |
|
189 | 189 | $props_to_update = array(); |
190 | 190 | $changed_props = $object->get_changes(); |
191 | 191 | |
192 | 192 | // Props should be updated if they are a part of the $changed array or don't exist yet. |
193 | - foreach ( $meta_key_to_props as $meta_key => $prop ) { |
|
194 | - if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) { |
|
195 | - $props_to_update[ $meta_key ] = $prop; |
|
193 | + foreach ($meta_key_to_props as $meta_key => $prop) { |
|
194 | + if (array_key_exists($prop, $changed_props) || !metadata_exists($meta_type, $object->get_id(), $meta_key)) { |
|
195 | + $props_to_update[$meta_key] = $prop; |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | |
@@ -206,22 +206,22 @@ discard block |
||
206 | 206 | * @param WP_Post $post_object Post object. |
207 | 207 | * @since 1.0.19 |
208 | 208 | */ |
209 | - protected function read_object_data( &$object, $post_object ) { |
|
209 | + protected function read_object_data(&$object, $post_object) { |
|
210 | 210 | $id = $object->get_id(); |
211 | 211 | $props = array(); |
212 | 212 | |
213 | - foreach ( $this->meta_key_to_props as $meta_key => $prop ) { |
|
214 | - $props[ $prop ] = get_post_meta( $id, $meta_key, true ); |
|
213 | + foreach ($this->meta_key_to_props as $meta_key => $prop) { |
|
214 | + $props[$prop] = get_post_meta($id, $meta_key, true); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | // Set object properties. |
218 | - $object->set_props( $props ); |
|
218 | + $object->set_props($props); |
|
219 | 219 | |
220 | 220 | // Gets extra data associated with the object if needed. |
221 | - foreach ( $object->get_extra_data_keys() as $key ) { |
|
221 | + foreach ($object->get_extra_data_keys() as $key) { |
|
222 | 222 | $function = 'set_' . $key; |
223 | - if ( is_callable( array( $object, $function ) ) ) { |
|
224 | - $object->{$function}( get_post_meta( $object->get_id(), $key, true ) ); |
|
223 | + if (is_callable(array($object, $function))) { |
|
224 | + $object->{$function}(get_post_meta($object->get_id(), $key, true)); |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | } |
@@ -232,24 +232,24 @@ discard block |
||
232 | 232 | * @param GetPaid_Data $object GetPaid_Data object. |
233 | 233 | * @since 1.0.19 |
234 | 234 | */ |
235 | - protected function update_post_meta( &$object ) { |
|
235 | + protected function update_post_meta(&$object) { |
|
236 | 236 | |
237 | 237 | $updated_props = array(); |
238 | - $props_to_update = $this->get_props_to_update( $object, $this->meta_key_to_props ); |
|
238 | + $props_to_update = $this->get_props_to_update($object, $this->meta_key_to_props); |
|
239 | 239 | $object_type = $object->get_object_type(); |
240 | 240 | |
241 | - foreach ( $props_to_update as $meta_key => $prop ) { |
|
242 | - $value = $object->{"get_$prop"}( 'edit' ); |
|
243 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
241 | + foreach ($props_to_update as $meta_key => $prop) { |
|
242 | + $value = $object->{"get_$prop"}('edit'); |
|
243 | + $value = is_string($value) ? wp_slash($value) : $value; |
|
244 | 244 | |
245 | - $updated = $this->update_or_delete_post_meta( $object, $meta_key, $value ); |
|
245 | + $updated = $this->update_or_delete_post_meta($object, $meta_key, $value); |
|
246 | 246 | |
247 | - if ( $updated ) { |
|
247 | + if ($updated) { |
|
248 | 248 | $updated_props[] = $prop; |
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
252 | - do_action( "getpaid_{$object_type}_object_updated_props", $object, $updated_props ); |
|
252 | + do_action("getpaid_{$object_type}_object_updated_props", $object, $updated_props); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -269,11 +269,11 @@ discard block |
||
269 | 269 | * |
270 | 270 | * @return bool True if updated/deleted. |
271 | 271 | */ |
272 | - protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) { |
|
273 | - if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) { |
|
274 | - $updated = delete_post_meta( $object->get_id(), $meta_key ); |
|
272 | + protected function update_or_delete_post_meta($object, $meta_key, $meta_value) { |
|
273 | + if (in_array($meta_value, array(array(), '', null), true) && !in_array($meta_key, $this->must_exist_meta_keys, true)) { |
|
274 | + $updated = delete_post_meta($object->get_id(), $meta_key); |
|
275 | 275 | } else { |
276 | - $updated = update_post_meta( $object->get_id(), $meta_key, $meta_value ); |
|
276 | + $updated = update_post_meta($object->get_id(), $meta_key, $meta_value); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | return (bool) $updated; |
@@ -295,8 +295,8 @@ discard block |
||
295 | 295 | * @param GetPaid_Data $object GetPaid_Data object. |
296 | 296 | * @since 1.0.19 |
297 | 297 | */ |
298 | - protected function clear_caches( &$object ) { |
|
299 | - clean_post_cache( $object->get_id() ); |
|
298 | + protected function clear_caches(&$object) { |
|
299 | + clean_post_cache($object->get_id()); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | * |
308 | 308 | * @return void |
309 | 309 | */ |
310 | - public function delete( &$object, $args = array() ) { |
|
310 | + public function delete(&$object, $args = array()) { |
|
311 | 311 | $id = $object->get_id(); |
312 | 312 | $object_type = $object->get_object_type(); |
313 | 313 | $args = wp_parse_args( |
@@ -317,18 +317,18 @@ discard block |
||
317 | 317 | ) |
318 | 318 | ); |
319 | 319 | |
320 | - if ( ! $id ) { |
|
320 | + if (!$id) { |
|
321 | 321 | return; |
322 | 322 | } |
323 | 323 | |
324 | - if ( $args['force_delete'] ) { |
|
325 | - wp_delete_post( $id, true ); |
|
326 | - $object->set_id( 0 ); |
|
327 | - do_action( "getpaid_delete_$object_type", $id ); |
|
324 | + if ($args['force_delete']) { |
|
325 | + wp_delete_post($id, true); |
|
326 | + $object->set_id(0); |
|
327 | + do_action("getpaid_delete_$object_type", $id); |
|
328 | 328 | } else { |
329 | - wp_trash_post( $id ); |
|
330 | - $object->set_status( 'trash' ); |
|
331 | - do_action( "getpaid_trash_$object_type", $id ); |
|
329 | + wp_trash_post($id); |
|
330 | + $object->set_status('trash'); |
|
331 | + do_action("getpaid_trash_$object_type", $id); |
|
332 | 332 | } |
333 | 333 | } |
334 | 334 | |
@@ -340,12 +340,12 @@ discard block |
||
340 | 340 | * @param GetPaid_Data $object GetPaid_Data object. |
341 | 341 | * @return string |
342 | 342 | */ |
343 | - protected function get_post_status( $object ) { |
|
344 | - $object_status = $object->get_status( 'edit' ); |
|
343 | + protected function get_post_status($object) { |
|
344 | + $object_status = $object->get_status('edit'); |
|
345 | 345 | $object_type = $object->get_object_type(); |
346 | 346 | |
347 | - if ( ! $object_status ) { |
|
348 | - $object_status = apply_filters( "getpaid_default_{$object_type}_status", 'draft' ); |
|
347 | + if (!$object_status) { |
|
348 | + $object_status = apply_filters("getpaid_default_{$object_type}_status", 'draft'); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | return $object_status; |