10up / distributor

Share content between your websites.
https://distributorplugin.com
GNU General Public License v2.0
618 stars 156 forks source link

Original date not used on pull (after use of snippet) #1215

Open Zodiac1978 opened 3 months ago

Zodiac1978 commented 3 months ago

Describe the bug

I added the snippet from here: https://10up.github.io/distributor/tutorial-snippets.html#push-original-publication-date

Pushing a post does leave the date intact, but pulling it, does not.

Steps to Reproduce

  1. Network activated Distributor plugin
  2. Add https://10up.github.io/distributor/tutorial-snippets.html#push-original-publication-date somewhere
  3. Go to /wp-admin/admin.php?page=pull on Subdomain A in multisite
  4. Pull post from blog on main site
  5. Go to posts list table and see the wrong publish date

Screenshots, screen recording, code snippet

The headline says "Push original publication date", but as there is an additional function using dt_pull_post_args I assumed this is the code for pulling.

If not, a new snippet would be great. Or repair the existing one (and fix the headline ;) )

Environment information

No response

WordPress information

WordPress 6.5.2

Code of Conduct

kirtangajjar commented 1 month ago

@dkotter @peterwilsoncc We can update the pull filter code like this, since while pulling, we only clone date if post_status is future:

/**
 * This filters the the arguments passed into wp_insert_post during a pull
 */
add_filter( 'dt_pull_post_args', function( $post_array, $remote_id, $post ) {
   // Date carry forward is only possible on scheduled post
    if ( ! isset( $post_array['post_status'] )
            || 'future' !== $post_array['post_status'] ) {
        return $post_array
    }
    $post_array['post_date'] = $post->post_date;
    $post_array['post_date_gmt'] = $post->post_date_gmt;

    return $post_array;
}, 10, 3 );