Skip to content

Commit

Permalink
Merge pull request #903 from turtlepod/issue/1_expired-listing
Browse files Browse the repository at this point in the history
Expired listing inconsistency issue and additional settings
  • Loading branch information
jom committed May 8, 2017
2 parents bc56e50 + 858be25 commit 4075c3a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
1 change: 0 additions & 1 deletion assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jQuery(document).ready(function($) {
$( 'input.job-manager-datepicker, input#_job_expires' ).datepicker({
altFormat : 'yy-mm-dd',
dateFormat : job_manager_admin.date_format,
minDate : 0
});

$( 'input.job-manager-datepicker, input#_job_expires' ).each( function(){
Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions includes/admin/class-wp-job-manager-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,20 @@ protected function init_settings() {
'type' => 'checkbox',
'attributes' => array()
),
array(
'name' => 'job_manager_hide_expired',
'std' => get_option( 'job_manager_hide_expired_content' ) ? '1' : '0', // back compat
'label' => __( 'Hide Expired Listings', 'wp-job-manager' ),
'cb_label' => __( 'Hide expired listings in job archive/search', 'wp-job-manager' ),
'desc' => __( 'If enabled, expired job listing is not searchable.', 'wp-job-manager' ),
'type' => 'checkbox',
'attributes' => array()
),
array(
'name' => 'job_manager_hide_expired_content',
'std' => '1',
'label' => __( 'Expired Listings', 'wp-job-manager' ),
'cb_label' => __( 'Hide content within expired listings', 'wp-job-manager' ),
'label' => __( 'Hide Expired Listings Content', 'wp-job-manager' ),
'cb_label' => __( 'Hide expired listing content in single job listing (singular)', 'wp-job-manager' ),
'desc' => __( 'If enabled, the content within expired listings will be hidden. Otherwise, expired listings will be displayed as normal (without the application area).', 'wp-job-manager' ),
'type' => 'checkbox',
'attributes' => array()
Expand Down
22 changes: 18 additions & 4 deletions includes/admin/class-wp-job-manager-writepanels.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public function job_listing_fields() {
'priority' => 11,
'classes' => array( 'job-manager-datepicker' ),
/* translators: date format placeholder, see https://secure.php.net/date */
'placeholder' => _x( 'yyyy-mm-dd', 'Date format placeholder.', 'wp-job-manager' ),
'value' => metadata_exists( 'post', $post->ID, '_job_expires' ) ? get_post_meta( $post->ID, '_job_expires', true ) : calculate_job_expiry( $post->ID ),
'placeholder' => metadata_exists( 'post', $post->ID, '_job_expires' ) ? _x( 'yyyy-mm-dd', 'Date format placeholder.', 'wp-job-manager' ) : calculate_job_expiry( $post->ID ),
'value' => get_post_meta( $post->ID, '_job_expires', true ),
);
}
if ( $current_user->has_cap( 'edit_others_job_listings' ) ) {
Expand Down Expand Up @@ -283,7 +283,7 @@ public static function input_text( $key, $field ) {
?>
<p class="form-field">
<label for="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $field['label'] ) ; ?>: <?php if ( ! empty( $field['description'] ) ) : ?><span class="tips" data-tip="<?php echo esc_attr( $field['description'] ); ?>">[?]</span><?php endif; ?></label>
<input type="text" name="<?php echo esc_attr( $name ); ?>" class="<?php echo esc_attr( $classes ); ?>" id="<?php echo esc_attr( $key ); ?>" placeholder="<?php echo esc_attr( $field['placeholder'] ); ?>" value="<?php echo esc_attr( $field['value'] ); ?>" />
<input type="text" autocomplete="off" name="<?php echo esc_attr( $name ); ?>" class="<?php echo esc_attr( $classes ); ?>" id="<?php echo esc_attr( $key ); ?>" placeholder="<?php echo esc_attr( $field['placeholder'] ); ?>" value="<?php echo esc_attr( $field['value'] ); ?>" />
</p>
<?php
}
Expand Down Expand Up @@ -533,7 +533,7 @@ public function save_job_listing_data( $post_id, $post ) {
if ( ! empty( $_POST[ $key ] ) ) {
update_post_meta( $post_id, $key, date( 'Y-m-d', strtotime( sanitize_text_field( $_POST[ $key ] ) ) ) );
} else {
update_post_meta( $post_id, $key, '' );
update_post_meta( $post_id, $key, calculate_job_expiry( $post_id ) );
}
}

Expand Down Expand Up @@ -581,6 +581,20 @@ public function save_job_listing_data( $post_id, $post ) {
}
}
}

/* Set Post Status To Expired If Already Expired */
$expiry_date = get_post_meta( $post_id, '_job_expires', true );
$today_date = date( 'Y-m-d', current_time( 'timestamp' ) );
$post_status = $expiry_date && $today_date > $expiry_date ? 'expired' : false;
if( $post_status ) {
remove_action( 'job_manager_save_job_listing', array( $this, 'save_job_listing_data' ), 20, 2 );
$job_data = array(
'ID' => $post_id,
'post_status' => $post_status,
);
wp_update_post( $job_data );
add_action( 'job_manager_save_job_listing', array( $this, 'save_job_listing_data' ), 20, 2 );
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion wp-job-manager-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function get_job_listings( $args = array() ) {
'fields' => 'all'
) );

if ( false == get_option( 'job_manager_hide_expired_content', 1 ) ) {
if ( false == get_option( 'job_manager_hide_expired', get_option( 'job_manager_hide_expired_content', 1 ) ) ) {
$post_status = array( 'publish', 'expired' );
} else {
$post_status = 'publish';
Expand Down

0 comments on commit 4075c3a

Please sign in to comment.