• The MPD function mpd_get_post_statuses() uses a WP function get_post_statuses() to get post statuses which are then deemed by MPD to be the only post statuses that are valid. This is problematic, because that function is very old and doesn’t return eg. The valid ‘future’ post_status (for scheduled posts) (or custom post statuses for that matter. This causes the checks for a persisting link to fail as they check if the post_status is in array of “valid” statuses. A persist link is added to the DB table, but it’s not therefore not functioning.

    Simple fix is as follows.

    Replace all usages of get_post_statuses() in all MPD files with get_post_stati() which actually does return all valid post statuses.

    In file multisite-post-duplicator\inc\mpd-functions.php:

    Replace these lines in function mpd_set_published_date(..):

    
        $mdp_post['post_date'] = $mpd_process_info['post_date'];
        $mdp_post['post_status'] = 'publish';
    

    with:

    
        $mdp_post['post_date'] = $mpd_process_info['post_date'];
        // Get post date (GMT)
        $mdp_post['post_date_gmt'] = get_gmt_from_date( $mdp_post['post_date'] );
        // Compare post date (GMT) to current date/time (GMT) to see if we need to Schedule or Publish
        $now = gmdate('Y-m-d H:i:59');
        if ( mysql2date('U', $mdp_post['post_date_gmt'], false) > mysql2date('U', $now, false) ) {
          $mdp_post['post_status'] = 'future';
        } else {
          $mdp_post['post_status'] = 'publish';
        }
    

    Replace this line in function mpd_update_published_date(..):

    
        $mpd_post['post_date'] = get_post_field('post_date', $persist_post->source_post_id);
    

    with:

    
        $mpd_post['post_date'] = get_post_field('post_date', $persist_post->source_post_id);
        // Get post date (GMT)
        $mpd_post['post_date_gmt'] = get_gmt_from_date( $mpd_post['post_date'] );
        // Compare post date (GMT) to current date/time (GMT) to see if we need to Schedule or Publish
        $now = gmdate('Y-m-d H:i:59');
        if ( mysql2date('U', $mpd_post['post_date_gmt'], false) > mysql2date('U', $now, false) ) {
          $mpd_post['post_status'] = 'future';
        } else {
          $mpd_post['post_status'] = 'publish';
        }
    

    The 2 gmt date compare lines is code copied from wp-includes/post.php, function wp_insert_post().

    Reference:
    https://codex.www.ads-software.com/Function_Reference/get_post_statuses
    https://codex.www.ads-software.com/Function_Reference/get_post_stati

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author MagicStick

    (@magicstick)

    Hey man. Thanks for that. Used stati in a recent project. Appreciate the time you put into the post. If you want you could create a pull request over at github which would make the process cleaner? No worries if not tho!

    Thanks again.

    Thread Starter y0uri

    (@y0uri)

    With the above fix almost everything works as expected:
    Create a new post, select dupe+link, choose a scheduled date/time and hit the blue button. You can update the post, even unschedule the post, reschedule the post, and change the scheduled date/time, the linked duplicate will follow suit.

    The only thing that doesn’t work is trashing the post. The linked duplicate (scheduled) post is not trashed, presumably also related to post_status=future.

    • This reply was modified 6 years, 7 months ago by y0uri.
    • This reply was modified 6 years, 7 months ago by y0uri.
    Thread Starter y0uri

    (@y0uri)

    Sorry, was typing reply to my post, hadn’t seen your reply. You’re welcome and thanks for maintaining the plugin!

    Can’t help with the pull request, sorry.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[FIX] Persisting links to scheduled posts do not work’ is closed to new replies.