Skip to content

Commit

Permalink
Fix sermon date not being saved when different date format is used
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikola committed Jan 30, 2018
1 parent 0078fd7 commit 5577cdb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
20 changes: 19 additions & 1 deletion includes/class-sm-dates-wp.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,25 @@ public static function maybe_update_date( $post_ID, $post, $update ) {
if ( $update ) {
// compare sermon date and if user changed it update sermon date and disable auto update
if ( ! empty( $_POST['sermon_date'] ) ) {
$dt = DateTime::createFromFormat( SermonManager::getOption( 'date_format' ) ?: 'm/d/Y', $_POST['sermon_date'] );
switch ( \SermonManager::getOption( 'date_format' ) ) {
case '0':
$date_format = 'm/d/Y';
break;
case '1':
$date_format = 'd/m/Y';
break;
case '2':
$date_format = 'Y/m/d';
break;
case '3':
$date_format = 'Y/d/m';
break;
default:
$date_format = 'm/d/Y';
break;
}

$dt = DateTime::createFromFormat( $date_format, $_POST['sermon_date'] );
$dt_post = DateTime::createFromFormat( 'U', mysql2date( 'U', $post->post_date ) );

$time = array(
Expand Down
39 changes: 22 additions & 17 deletions includes/sm-cmb-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,33 @@ function wpfc_sermon_metaboxes() {
// 'closed' => true, // Keep the metabox closed by default
) );

$date_format = 'm/d/Y';
if ( \SermonManager::getOption( 'date_format' ) !== '' ) {
switch ( \SermonManager::getOption( 'date_format' ) ) {
case '0':
$date_format = 'mm/dd/YYYY';
break;
case '1':
$date_format = 'dd/mm/YYYY';
break;
case '2':
$date_format = 'YYYY/mm/dd';
break;
case '3':
$date_format = 'YYYY/dd/mm';
break;
}
switch ( \SermonManager::getOption( 'date_format' ) ) {
case '0':
$date_format_label = 'mm/dd/YYYY';
$date_format = 'm/d/Y';
break;
case '1':
$date_format_label = 'dd/mm/YYYY';
$date_format = 'd/m/Y';
break;
case '2':
$date_format_label = 'YYYY/mm/dd';
$date_format = 'Y/m/d';
break;
case '3':
$date_format_label = 'YYYY/dd/mm';
$date_format = 'Y/d/m';
break;
default:
$date_format_label = 'mm/dd/YYYY';
$date_format = 'm/d/Y';
break;
}

$cmb->add_field( array(
'name' => esc_html__( 'Date Preached', 'sermon-manager-for-wordpress' ),
'desc' => esc_html__( '(optional)', 'sermon-manager-for-wordpress' ) . '<br>' . wp_sprintf( /* translators: %s date format, effectively <code>d/m/Y</code> or the like */
esc_html__( 'format: %s', 'sermon-manager-for-wordpress' ), $date_format ),
esc_html__( 'format: %s', 'sermon-manager-for-wordpress' ), $date_format_label ),
'id' => 'sermon_date',
'type' => 'text_date_timestamp',
'date_format' => $date_format,
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man

## Changelog ##
### 2.12.0 ###
* Fix: Sermon date not being saved when date format is changed
* Fix: YouTube short URL was not being detected (thanks @macbookandrew)
* Fix: Excerpt saving as "1" when there's no sermon description
* Dev: Added more filters for output
Expand Down

0 comments on commit 5577cdb

Please sign in to comment.