General process: If the release time of an edit is later than the current server time, the system registers a one-time crontab script with wP_schedule_single_event ().

Change the entry file for post: wordpress-wp-admin post.php

case 'editpost': check_admin_referer( 'update-post_' . $post_id ); $post_id = edit_post(); // Session cookie flag that the post was saved. if ( isset( $_COOKIE['wp-saving-post'] ) && $_COOKIE['wp-saving-post'] === $post_id . '-check' ) { setcookie( 'wp-saving-post', $post_id . '-saved', time() + DAY_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, is_ssl() ); } redirect_post( $post_id ); // Send user on their way while we keep working. exit;Copy the code

Two: Modify the POST. wordpress\wp-admin\includes\post.php edit_post()->wp_update_post()

***** add_meta( $post_ID ); update_post_meta( $post_ID, '_edit_last', get_current_user_id() ); // Modify post $success = wp_update_POST ($translated); * * * * *Copy the code

Three: After processing the data, update the data to DB. wordpress\wp-includes\post.php wp_update_post()->wp_insert_post()

*******
return wp_insert_post( $postarr, $wp_error );
}
Copy the code

Four: update DB, insert data, trigger hook.

******* if ( 'attachment' ! $post_status($data['post_status'], $previous_status, $postarr[' post_status']) { $post ); } * * * * * * * * * *Copy the code

Wp_transition_post_status () ->do_action()

function wp_transition_post_status( $new_status, $old_status, $post ) { do_action( 'transition_post_status', $new_status, $old_status, $post ); do_action( "{$old_status}_to_{$new_status}", $post ); / / when released in the future: do_action (" future_post $post - > ID, $post) do_action (" {$new_status} _ {$post - > post_type} ", $post - > ID, $post). }Copy the code

Future_post is triggered and executed.

Function _future_post_hook($deprecated, $POST) {// Delete the previous hook wp_clear_scheduled_hook(' publish_future_POST ', array( $post->ID ) ); // register cron wP_SCHEdule_singLE_event (strtotime(get_gmT_froM_date ($POST ->post_date). 'GMT'),' publish_future_POST ', array( $post->ID ) ); }Copy the code

7: Use WP-CLI to view cron. You can see that publish_future_POST is white registered with cron

+------------------------------------+---------------------+-----------------------+---------------+ | hook | next_run_gmt | next_run_relative | recurrence | +------------------------------------+---------------------+-----------------------+---------------+ | publish_future_post | 2020-12-16 09:18:00 | 1 minute 11 seconds | Non-repeating | | wp_privacy_delete_old_export_files |  2020-12-16 09:44:35 | 27 minutes 46 seconds | 1 hour | | wp_version_check | 2020-12-16 14:44:35 | 5 hours 27 minutes | 12 hours | | wp_update_plugins | 2020-12-16 14:44:35 | 5 hours 27 minutes | 12 hours | | wp_update_themes | 2020-12-16 14:44:35 | 5 hours 27 minutes | 12 hours | | recovery_mode_clean_expired_keys | 2020-12-17 02:44:35 | 17 hours 27 minutes | 1 day | | wp_scheduled_delete | 2020-12-17 02:46:22 | 17 hours 29 minutes | 1 day | | delete_expired_transients | 2020-12-17 02:46:22 | 17 hours 29 minutes | 1 day | | wp_scheduled_auto_draft_delete | 2020-12-17 03:35:03 | 18 hours 18 minutes | 1 day | | wsal_delete_logins | 2020-12-17 07:51:11 | 22 hours 34 minutes | 1  day | | wsal_log_files_pruning | 2020-12-17 07:51:11 | 22 hours 34 minutes | 1 day | | wpseo-reindex | 2020-12-17 08:30:35 | 23 hours 13 minutes | 1 day | | wpseo_permalink_structure_check | 2020-12-17 08:30:35 | 23 hours 13 minutes |  1 day | | wp_site_health_scheduled_check | 2020-12-23 02:44:35 | 6 days 17 hours | 1 week | +------------------------------------+---------------------+-----------------------+---------------+Copy the code