Skip to content

Commit

Permalink
Added option to allow override of post publish dates for synced posts…
Browse files Browse the repository at this point in the history
…. Added logic to turn UTC timezone post publish date from Patreon to local date to use in publishing post. add_new_patreon_post now uses converted/synced post publish date instead of current date (now) if override post publish date option is set
  • Loading branch information
codebard committed Sep 15, 2020
1 parent 0144aba commit 95ce1a7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
11 changes: 11 additions & 0 deletions classes/patreon_content_sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ public function add_new_patreon_post( $patreon_post ) {

}

$post_date = date( 'Y-m-d H:i:s', time() );

if ( get_option( 'patreon-override-synced-post-publish-date', 'no' ) == 'yes' ) {

$utc_timezone = new DateTimeZone( "UTC" );
$datetime = new DateTime( $patreon_post['data']['attributes']['published_at'], $utc_timezone );
$post_date = $datetime->format( 'Y-m-d H:i:s' );

}

$post_status = 'publish';

// Decide post status - publish or pending
Expand All @@ -221,6 +231,7 @@ public function add_new_patreon_post( $patreon_post ) {
$post['post_status'] = $post_status;
$post['post_author'] = $post_author;
$post['post_type'] = $post_type;
$post['post_date'] = $post_date;

// Parse and handle the images inside the post:

Expand Down
26 changes: 26 additions & 0 deletions classes/patreon_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function patreon_plugin_register_settings() {
register_setting( 'patreon-options', 'patreon-set-featured-image' );
register_setting( 'patreon-options', 'patreon-auto-publish-public-posts' );
register_setting( 'patreon-options', 'patreon-auto-publish-patron-only-posts' );
register_setting( 'patreon-options', 'patreon-override-synced-post-publish-date' );

}

Expand Down Expand Up @@ -574,6 +575,31 @@ function patreon_plugin_setup_page(){
</select>
</td>
</tr>
<tr valign="top">
<th scope="row">
<strong>Override imported post publish dates</strong>
<div class="patreon-options-info">If 'Yes', this will override the local imported posts' publish dates with the publish dates from Patreon</div>
</th>
<td>
<?php

$override_post_publish_dates_from_patreon_selected = '';
$override_post_publish_dates_from_patreon_unselected = '';

if ( get_option( 'patreon-override-synced-post-publish-date', 'no' ) == 'yes' ) {
$override_post_publish_dates_from_patreon_selected = " selected";
}
else {
$override_post_publish_dates_from_patreon_unselected = " selected";
}

?>
<select name="patreon-override-synced-post-publish-date">
<option value="yes" <?php echo $override_post_publish_dates_from_patreon_selected; ?>>Yes</option>
<option value="no" <?php echo $override_post_publish_dates_from_patreon_unselected; ?>>No</option>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row">
<strong>Update local posts from the ones at Patreon</strong>
Expand Down

0 comments on commit 95ce1a7

Please sign in to comment.