[FIX] Persisting links to scheduled posts do not work
-
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 withget_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
- The topic ‘[FIX] Persisting links to scheduled posts do not work’ is closed to new replies.