← All changes
|
includes/utilities/class-charitable-data-processor.php
+32
-3
1.7.0.7
→
1.8.13
View file →
| @@ -5,9 +5,9 @@ | ||
| 5 | 5 | * the type of data (text, checkbox, etc.). |
| 6 | 6 | * |
| 7 | 7 | * @package Charitable/Classes/Charitable_Data_Processor |
| 8 | 8 | * @author David Bisset |
| 9 | - * @copyright Copyright (c) 2022, WP Charitable LLC | |
| 9 | + * @copyright Copyright (c) 2023, WP Charitable LLC | |
| 10 | 10 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 11 | 11 | * @since 1.5.9 |
| 12 | 12 | * @version 1.6.55 |
| 13 | 13 | */ |
| @@ -64,8 +64,17 @@ | ||
| 64 | 64 | */ |
| 65 | 65 | protected $output; |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | + * Whether the data is invalid. | |
| 69 | + * | |
| 70 | + * @since 1.5.9 | |
| 71 | + * | |
| 72 | + * @var boolean | |
| 73 | + */ | |
| 74 | + protected $invalid; | |
| 75 | + | |
| 76 | + /** | |
| 68 | 77 | * Instantiate the formatter with a dataset and array of fields. |
| 69 | 78 | * |
| 70 | 79 | * @since 1.5.9 |
| 71 | 80 | * |
| @@ -308,10 +317,15 @@ | ||
| 308 | 317 | |
| 309 | 318 | /** |
| 310 | 319 | * Sanitize a value received from a datepicker. |
| 311 | 320 | * |
| 312 | - * @since 1.5.9 | |
| 321 | + * When decline_months is on, the JS datepicker sends yy-mm-dd (e.g. 2026-2-1). | |
| 322 | + * We normalize to Y-m-d (e.g. 2026-02-01) so MySQL and PHP never interpret | |
| 323 | + * the string as d-m-y (e.g. January 2 instead of February 1). | |
| 313 | 324 | * |
| 325 | + * @since 1.5.9 | |
| 326 | + * @version 1.8.9.2 | |
| 327 | + * | |
| 314 | 328 | * @param string $value The datepicker value. |
| 315 | 329 | * @return string|int If a date was chosen, returns the date in YYYY-MM-DD format. |
| 316 | 330 | * Otherwise, returns 0. |
| 317 | 331 | */ |
| @@ -321,8 +335,23 @@ | ||
| 321 | 335 | } |
| 322 | 336 | |
| 323 | 337 | if ( ! charitable()->registry()->get( 'i18n' )->decline_months() ) { |
| 324 | 338 | $value = charitable_sanitize_date( $value, 'Y-m-d' ); |
| 339 | + if ( false === $value ) { | |
| 340 | + $value = 0; | |
| 341 | + } | |
| 342 | + } else { | |
| 343 | + // Normalize to canonical Y-m-d so MySQL/PHP never interpret as d-m-y. | |
| 344 | + $value = trim( $value ); | |
| 345 | + $dt = DateTime::createFromFormat( 'Y-m-d', $value ); | |
| 346 | + if ( ! $dt ) { | |
| 347 | + $dt = DateTime::createFromFormat( 'Y-n-j', $value ); | |
| 348 | + } | |
| 349 | + if ( $dt ) { | |
| 350 | + $value = $dt->format( 'Y-m-d' ); | |
| 351 | + } else { | |
| 352 | + $value = 0; | |
| 353 | + } | |
| 325 | 354 | } |
| 326 | 355 | |
| 327 | 356 | return $value; |
| 328 | 357 | } |
| @@ -446,9 +475,9 @@ | ||
| 446 | 475 | * @param string $key The picture file key. |
| 447 | 476 | * @return boolean |
| 448 | 477 | */ |
| 449 | 478 | protected function picture_file_exists( $key ) { |
| 450 | - return isset( $_FILES ) && isset( $_FILES[ $key ] ); | |
| 479 | + return isset( $_FILES ) && isset( $_FILES[ $key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 451 | 480 | } |
| 452 | 481 | |
| 453 | 482 | /** |
| 454 | 483 | * Uploads a file and attaches it to the given post. |