Skip to content

Commit

Permalink
Set the default dateFormat if it’s empty (#2779)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeyarce authored Mar 14, 2024
1 parent 881c4f3 commit 03f7745
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 18 deletions.
4 changes: 3 additions & 1 deletion assets/js/datepicker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* global job_manager_datepicker */
jQuery(document).ready( function() {
if ( jQuery.datepicker._defaults.dateFormat == '' ) {
jQuery.datepicker._defaults.dateFormat = 'MM d, yy';
}
var $date_today = new Date();
var datePickerOptions = {
altFormat : 'yy-mm-dd',
Expand All @@ -21,7 +24,6 @@ jQuery(document).ready( function() {
}
} );
$target.datepicker( jQuery.extend( {}, datePickerOptions, { altField: $hidden_input } ) );
$target.datepicker("option", "dateFormat", $target.datepicker("option", "dateFormat") || "MM d, yy");
if ( $target.val() ) {
var dateParts = $target.val().split('-');
if ( 3 === dateParts.length ) {
Expand Down
8 changes: 5 additions & 3 deletions includes/admin/class-wp-job-manager-cpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ public function enter_title_here( $text, $post ) {
*/
public function post_updated_messages( $messages ) {
global $post, $post_ID, $wp_post_types;
$wp_date_format = get_option( 'date_format' ) ?: JOB_MANAGER_DATE_FORMAT_FALLBACK;

// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No changes based on input.
$revision_title = isset( $_GET['revision'] ) ? wp_post_revision_title( (int) $_GET['revision'], false ) : false;
Expand All @@ -470,7 +471,7 @@ public function post_updated_messages( $messages ) {
// translators: %1$s is the singular name of the post type; %2$s is the date the post will be published; %3$s is the URL to preview the listing.
__( '%1$s scheduled for: <strong>%2$s</strong>. <a target="_blank" href="%3$s">Preview</a>', 'wp-job-manager' ),
$wp_post_types[ \WP_Job_Manager_Post_Types::PT_LISTING ]->labels->singular_name,
wp_date( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), get_post_timestamp() ),
wp_date( $wp_date_format . ' @ ' . get_option( 'time_format' ), get_post_timestamp() ),
esc_url( get_permalink( $post_ID ) )
),
// translators: %1$s is the singular name of the job listing post type; %2$s is the URL to view the listing.
Expand Down Expand Up @@ -593,6 +594,7 @@ public function row_actions( $actions, $post ) {
*/
public function custom_columns( $column ) {
global $post;
$date_format = get_option( 'date_format' ) ?: 'F j, Y';

switch ( $column ) {
case \WP_Job_Manager_Post_Types::TAX_LISTING_TYPE:
Expand Down Expand Up @@ -658,14 +660,14 @@ public function custom_columns( $column ) {
}
break;
case 'job_posted':
echo '<strong>' . esc_html( wp_date( get_option( 'date_format' ), get_post_timestamp() ) ) . '</strong><span>';
echo '<strong>' . esc_html( wp_date( $date_format, get_post_timestamp() ) ) . '</strong><span>';
// translators: %s placeholder is the username of the user.
echo ( empty( $post->post_author ) ? esc_html__( 'by a guest', 'wp-job-manager' ) : sprintf( esc_html__( 'by %s', 'wp-job-manager' ), '<a href="' . esc_url( add_query_arg( 'author', $post->post_author ) ) . '">' . esc_html( get_the_author() ) . '</a>' ) ) . '</span>';
break;
case 'job_expires':
$job_expiration = WP_Job_Manager_Post_Types::instance()->get_job_expiration( $post );
if ( $job_expiration ) {
echo '<strong>' . esc_html( wp_date( get_option( 'date_format' ), $job_expiration->getTimestamp() ) ) . '</strong>';
echo '<strong>' . esc_html( wp_date( $date_format, $job_expiration->getTimestamp() ) ) . '</strong>';
} else {
echo '&ndash;';
}
Expand Down
12 changes: 6 additions & 6 deletions includes/admin/class-wp-job-manager-writepanels.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ public function job_listing_fields() {
}

if ( isset( $fields['_job_expires'] ) && ! isset( $fields['_job_expires']['value'] ) ) {
$job_expires = WP_Job_Manager_Post_Types::instance()->get_job_expiration( $post_id );

$job_expires = WP_Job_Manager_Post_Types::instance()->get_job_expiration( $post_id );
$wp_date_format = get_option( 'date_format' ) ?: 'F j, Y';
$fields['_job_expires']['placeholder'] = null;
if ( ! empty( $job_expires ) ) {
$fields['_job_expires']['value'] = $job_expires->format( 'Y-m-d' );
} else {
$assumed_expiration_date = calculate_job_expiry( $post_id, true );
if ( $assumed_expiration_date ) {
$fields['_job_expires']['placeholder'] = wp_date( get_option( 'date_format' ), $assumed_expiration_date->getTimestamp() );
$fields['_job_expires']['placeholder'] = wp_date( $wp_date_format, $assumed_expiration_date->getTimestamp() );
}
$fields['_job_expires']['value'] = '';
}
Expand Down Expand Up @@ -584,8 +584,8 @@ public static function input_radio( $key, $field ) {
public function job_listing_data( $post ) {
global $post, $thepostid, $wp_post_types;

$thepostid = $post->ID;

$thepostid = $post->ID;
$wp_date_format = get_option( 'date_format' ) ?: JOB_MANAGER_DATE_FORMAT_FALLBACK;
echo '<div class="wp_job_manager_meta_data">';

wp_nonce_field( 'save_meta_data', 'job_manager_nonce' );
Expand Down Expand Up @@ -618,7 +618,7 @@ public function job_listing_data( $post ) {
// translators: %1$s is placeholder for singular name of the job listing post type; %2$s is the intl formatted date the listing was last modified.
esc_html__( '%1$s was last modified by the user on %2$s.', 'wp-job-manager' ),
esc_html( $wp_post_types[ \WP_Job_Manager_Post_Types::PT_LISTING ]->labels->singular_name ),
esc_html( wp_date( get_option( 'date_format' ), (int) $user_edited_timestamp ) )
esc_html( wp_date( $wp_date_format, (int) $user_edited_timestamp ) )
);
echo '</em>';
echo '</p>';
Expand Down
5 changes: 3 additions & 2 deletions includes/class-wp-job-manager-email-notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,10 @@ private static function get_job_detail_fields( WP_Post $job, $sent_to_admin, $pl
];
}

$job_expires = WP_Job_Manager_Post_Types::instance()->get_job_expiration( $job );
$job_expires = WP_Job_Manager_Post_Types::instance()->get_job_expiration( $job );
$wp_date_format = get_option( 'date_format' ) ?: JOB_MANAGER_DATE_FORMAT_FALLBACK;
if ( ! empty( $job_expires ) ) {
$job_expires_str = wp_date( get_option( 'date_format' ), $job_expires->getTimestamp() );
$job_expires_str = wp_date( $wp_date_format, $job_expires->getTimestamp() );
$fields['job_expires'] = [
'label' => __( 'Listing expires', 'wp-job-manager' ),
'value' => $job_expires_str,
Expand Down
5 changes: 3 additions & 2 deletions templates/job-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

$submission_limit = ! empty( get_option( 'job_manager_submission_limit' ) ) ? absint( get_option( 'job_manager_submission_limit' ) ) : false;
$submit_job_form_page_id = get_option( 'job_manager_submit_job_form_page_id' );
$wp_date_format = get_option( 'date_format' ) ?: 'F j, Y';
?>
<div id="job-manager-job-dashboard">
<p><?php esc_html_e( 'Your listings are shown in the table below.', 'wp-job-manager' ); ?></p>
Expand Down Expand Up @@ -73,11 +74,11 @@
?>
</ul>
<?php elseif ('date' === $key ) : ?>
<?php echo esc_html( wp_date( get_option( 'date_format' ), get_post_datetime( $job )->getTimestamp() ) ); ?>
<?php echo esc_html( wp_date( $wp_date_format, get_post_datetime( $job )->getTimestamp() ) ); ?>
<?php elseif ('expires' === $key ) : ?>
<?php
$job_expires = WP_Job_Manager_Post_Types::instance()->get_job_expiration( $job );
echo esc_html( $job_expires ? wp_date( get_option( 'date_format' ), $job_expires->getTimestamp() ) : '&ndash;' );
echo esc_html( $job_expires ? wp_date( $wp_date_format, $job_expires->getTimestamp() ) : '&ndash;' );
?>
<?php elseif ('filled' === $key ) : ?>
<?php echo is_position_filled( $job ) ? '&#10004;' : '&ndash;'; ?>
Expand Down
10 changes: 6 additions & 4 deletions wp-job-manager-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,10 +758,11 @@ function wpjm_get_registration_fields() {
* @param int|WP_Post $post (default: null).
*/
function the_job_publish_date( $post = null ) {
$date_format = get_option( 'job_manager_date_format' );
$date_format = get_option( 'job_manager_date_format' );
$wp_date_format = get_option( 'date_format' ) ?: JOB_MANAGER_DATE_FORMAT_FALLBACK;

if ( 'default' === $date_format ) {
$display_date = esc_html__( 'Posted on ', 'wp-job-manager' ) . wp_date( get_option( 'date_format' ), get_post_timestamp( $post ) );
$display_date = esc_html__( 'Posted on ', 'wp-job-manager' ) . wp_date( $wp_date_format, get_post_timestamp( $post ) );
} else {
$post_timestamp = get_post_timestamp( $post );
$current_time = time();
Expand All @@ -786,10 +787,11 @@ function the_job_publish_date( $post = null ) {
* @return string|int|false
*/
function get_the_job_publish_date( $post = null ) {
$date_format = get_option( 'job_manager_date_format' );
$date_format = get_option( 'job_manager_date_format' );
$wp_date_format = get_option( 'date_format' ) ?: JOB_MANAGER_DATE_FORMAT_FALLBACK;

if ( 'default' === $date_format ) {
return wp_date( get_option( 'date_format' ), get_post_datetime()->getTimestamp() );
return wp_date( $wp_date_format, get_post_datetime()->getTimestamp() );
} else {
// translators: Placeholder %s is the relative, human readable time since the job listing was posted.
return sprintf( __( 'Posted %s ago', 'wp-job-manager' ), human_time_diff( get_post_timestamp(), time() ) );
Expand Down
1 change: 1 addition & 0 deletions wp-job-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
define( 'JOB_MANAGER_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
define( 'JOB_MANAGER_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
define( 'JOB_MANAGER_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
define( 'JOB_MANAGER_DATE_FORMAT_FALLBACK', 'F j, Y' );

require_once dirname( __FILE__ ) . '/wp-job-manager-autoload.php';
WP_Job_Manager_Autoload::init();
Expand Down

0 comments on commit 03f7745

Please sign in to comment.