Enable Expiry Date in Frontend Form#2895
Enable Expiry Date in Frontend Form#2895masteradhoc wants to merge 4 commits intoAutomattic:trunkfrom
Conversation
|
@donnchawp could you check this PR as well? |
donnchawp
left a comment
There was a problem hiding this comment.
Thanks for your PR. Some changes here.
| } | ||
| } | ||
|
|
||
| // Validate expiry date field. |
There was a problem hiding this comment.
This block is almost the same as the one at line 592. (Validate expiry date field if enabled and provided.)
It's probably best to just keep the last one that throws an exception as other checks do.
| } | ||
|
|
||
| $today = new DateTimeImmutable( 'now', wp_timezone() ); | ||
| if ( $expires_date < $today ) { |
There was a problem hiding this comment.
There's a good chance this would reject any jobs submitted, with an expiry date of the current date, but if you don't use this block it doesn't matter.
The date/time returned from DateTimeImmutable::createFromFormat on line 544 will fill in the current time, including microseconds.
That may be a couple of microseconds before $today so the check on line 550 will fail.
The second block works correctly, where you use 'today' as the time value on line 600.
ref: https://www.php.net/manual/en/datetimeimmutable.createfromformat.php
|
|
||
| // Validate expiry date field if enabled and provided. | ||
| if ( get_option( 'job_manager_enable_expiry_date_field' ) && ! empty( $values['job']['job_expires'] ) ) { | ||
| $expires_date = DateTimeImmutable::createFromFormat( 'Y-m-d', $values['job']['job_expires'], wp_timezone() ); |
There was a problem hiding this comment.
Probably should use 'Y-m-d|' here so it returns the date and not a date and time.
Jobs submitted with an expiry date today will have $expires_date set to midnight, same as $today further down, so the check will pass.
|
|
||
| // If a date is provided, also set the job expiration. | ||
| if ( ! empty( $values[ $group_key ][ $key ] ) ) { | ||
| $expires_date = DateTimeImmutable::createFromFormat( 'Y-m-d', $values[ $group_key ][ $key ], wp_timezone() ); |
There was a problem hiding this comment.
Change 'Y-m-d' to 'Y-m-d|' so it's definitely a date.
| // Handle custom expiry date field. | ||
| } elseif ( 'job_expires' === $key ) { | ||
| // Always save the raw value first. | ||
| update_post_meta( $this->job_id, '_job_expires', $values[ $group_key ][ $key ] ); |
There was a problem hiding this comment.
Why save _job_expires when it's set again in 1051? For debugging purposes?
Fixes #2886
Changes Proposed in this Pull Request
Testing Instructions
Release Notes
New or Updated Hooks and Templates
Deprecated Code
Screenshot / Video