Last active
July 13, 2020 20:13
-
-
Save morganestes/1808592fffdc82270999f04d17eda33a to your computer and use it in GitHub Desktop.
Change the publish date of a distributed post to the source timestamp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace BigWing\Integrations\Distributor; | |
| /** | |
| * Set the date on distributed posts to the source date. | |
| * | |
| * @param array $post_args The post data to insert into the receiving site. | |
| * @param \WP_Post $post The source post object. | |
| * | |
| * @return array The modified post data. | |
| */ | |
| function set_date_on_push( array $post_args, \WP_Post $post ): array { | |
| $post_args['post_date'] = $post->post_date; | |
| $post_args['post_date_gmt'] = $post->post_date_gmt; | |
| $post_args['post_modified'] = $post->post_modified; | |
| $post_args['post_modified_gmt'] = $post->post_modified_gmt; | |
| // Don't overwrite pub date during updates. | |
| if ( isset( $post_args['ID'] ) ) { | |
| $post_args['post_date'] = date( 'Y-m-d H:i:s', get_post_time( 'U', false, (int) $post_args['ID'] ) ); | |
| $post_args['post_date_gmt'] = date( 'Y-m-d H:i:s', get_post_time( 'U', true, (int) $post_args['ID'] ) ); | |
| } | |
| return $post_args; | |
| } | |
| add_filter( 'dt_push_post_args', __NAMESPACE__ . '\\set_date_on_push', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment