From 95ce1a75cb2fb75b15754f8444178c08e8c6a9e7 Mon Sep 17 00:00:00 2001 From: Codebard Date: Tue, 15 Sep 2020 16:27:54 -0400 Subject: [PATCH] Added option to allow override of post publish dates for synced posts. 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 --- classes/patreon_content_sync.php | 11 +++++++++++ classes/patreon_options.php | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/classes/patreon_content_sync.php b/classes/patreon_content_sync.php index a0efaa0a..b3494946 100644 --- a/classes/patreon_content_sync.php +++ b/classes/patreon_content_sync.php @@ -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 @@ -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: diff --git a/classes/patreon_options.php b/classes/patreon_options.php index bc8f5b2c..df076b69 100644 --- a/classes/patreon_options.php +++ b/classes/patreon_options.php @@ -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' ); } @@ -574,6 +575,31 @@ function patreon_plugin_setup_page(){ + + + Override imported post publish dates +
If 'Yes', this will override the local imported posts' publish dates with the publish dates from Patreon
+ + + + + + Update local posts from the ones at Patreon