Skip to content

Enable Expiry Date in Frontend Form#2895

Open
masteradhoc wants to merge 4 commits intoAutomattic:trunkfrom
masteradhoc:expirydate
Open

Enable Expiry Date in Frontend Form#2895
masteradhoc wants to merge 4 commits intoAutomattic:trunkfrom
masteradhoc:expirydate

Conversation

@masteradhoc
Copy link
Copy Markdown
Contributor

Fixes #2886

Changes Proposed in this Pull Request

  • Allow Expiry Date to be set in Frontend Form for Job Submissions

Testing Instructions

  • Go to Settings -> Job Submissions and activate "Expiry Date field"
  • Visit Job Submissions Frontend Form
  • add a new job including an expiry date
  • see in wp-admin if the expiry date was set correctly

Release Notes

  • Allow Expiry Date to be set in Frontend Form for Job Submissions

New or Updated Hooks and Templates

Deprecated Code

Screenshot / Video

image

@masteradhoc
Copy link
Copy Markdown
Contributor Author

@donnchawp could you check this PR as well?

Copy link
Copy Markdown
Contributor

@donnchawp donnchawp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR. Some changes here.

}
}

// Validate expiry date field.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ] );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why save _job_expires when it's set again in 1051? For debugging purposes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable Expiry Date in Frontend Form

2 participants