Skip to content

Commit

Permalink
Enhancement / Date format setting (#757)
Browse files Browse the repository at this point in the history
* Added "Date Format" setting to the "Job Listings" section.

* Added "the_job_publish_date" function that outputs the current job published date using the date format defined in the plugin settings.

* Added "get_the_job_publish_date" function that returns the date for a job using the display format selected in the plugin settings.

* Updated the date output for job listings to use the "the_job_publish_date" function.

* Updated the date output for the single job listing to use the "the_job_publish_date" function.

* Updated to use "the_job_publish_date" function for rendering the job listing date.

* Updated the "the_job_publish_date" function to include the <date> element.

* Removed redundent <date> element.

* Updated "the_job_publish_date" to use the <time> element with the datetime attribute defined. This closes #739

* Added the text "Posted on" to the job listing date if the default WP date format is used.

* Updated the "Posted on" text to be translation ready.
  • Loading branch information
cwpnolen authored and dbtlr committed Feb 16, 2017
1 parent eeebc60 commit ab9fce8
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
11 changes: 11 additions & 0 deletions includes/admin/class-wp-job-manager-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ protected function init_settings() {
'all' => __( 'Jobs will be shown if within ALL selected categories', 'wp-job-manager' ),
)
),
array(
'name' => 'job_manager_date_format',
'std' => 'relative',
'label' => __( 'Date Format', 'wp-job-manager' ),
'desc' => __( 'Choose how you want the published date for jobs to be displayed on the front-end.', 'wp-job-manager' ),
'type' => 'select',
'options' => array(
'relative' => __( 'Relative to the current date (e.g., 1 day, 1 week, 1 month ago)', 'wp-job-manager' ),
'default' => __( 'Default date format as defined in Setttings', 'wp-job-manager' ),
)
),
array(
'name' => 'job_manager_enable_types',
'std' => '1',
Expand Down
2 changes: 1 addition & 1 deletion templates/content-job_listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<?php if ( get_option( 'job_manager_enable_types' ) ) { ?>
<li class="job-type <?php echo get_the_job_type() ? sanitize_title( get_the_job_type()->slug ) : ''; ?>"><?php the_job_type(); ?></li>
<?php } ?>
<li class="date"><date><?php printf( __( '%s ago', 'wp-job-manager' ), human_time_diff( get_post_time( 'U' ), current_time( 'timestamp' ) ) ); ?></date></li>
<li class="date"><?php the_job_publish_date(); ?></li>

<?php do_action( 'job_listing_meta_end' ); ?>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion templates/content-single-job_listing-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<li class="location" itemprop="jobLocation"><?php the_job_location(); ?></li>

<li class="date-posted" itemprop="datePosted"><date><?php printf( __( 'Posted %s ago', 'wp-job-manager' ), human_time_diff( get_post_time( 'U' ), current_time( 'timestamp' ) ) ); ?></date></li>
<li class="date-posted" itemprop="datePosted"><?php the_job_publish_date(); ?></li>

<?php if ( is_position_filled() ) : ?>
<li class="position-filled"><?php _e( 'This position has been filled', 'wp-job-manager' ); ?></li>
Expand Down
2 changes: 1 addition & 1 deletion templates/content-summary-job_listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<h1><?php the_title(); ?></h1>

<p class="meta"><?php the_job_location( false ); ?> &mdash; <date><?php printf( __( 'Posted %s ago', 'wp-job-manager' ), human_time_diff( get_post_time( 'U' ), current_time( 'timestamp' ) ) ); ?></date></p>
<p class="meta"><?php the_job_location( false ); ?> &mdash; <?php the_job_publish_date(); ?></p>

</div>
</a>
34 changes: 34 additions & 0 deletions wp-job-manager-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,40 @@ function get_the_job_type( $post = null ) {
}


/**
* the_job_publish_date function.
* @param mixed $post (default: null)
* @return [type]
*/
function the_job_publish_date( $post = null ) {
$date_format = get_option( 'job_manager_date_format' );

if ( $date_format === 'default' ) {
$display_date = __( 'Posted on ', 'wp-job-manager' ) . get_post_time( get_option( 'date_format' ) );
} else {
$display_date = sprintf( __( 'Posted %s ago', 'wp-job-manager' ), human_time_diff( get_post_time( 'U' ), current_time( 'timestamp' ) ) );
}

echo '<time datetime="' . get_post_time( 'Y-m-d' ) . '">' . $display_date . '</time>';
}


/**
* get_the_job_publish_date function.
* @param mixed $post (default: null)
* @return [type]
*/
function get_the_job_publish_date( $post = null ) {
$date_format = get_option( 'job_manager_date_format' );

if ( $date_format === 'default' ) {
return get_post_time( get_option( 'date_format' ) );
} else {
return sprintf( __( 'Posted %s ago', 'wp-job-manager' ), human_time_diff( get_post_time( 'U' ), current_time( 'timestamp' ) ) );
}
}


/**
* the_job_location function.
* @param boolean $map_link whether or not to link to google maps
Expand Down

0 comments on commit ab9fce8

Please sign in to comment.