There isn’t really an API for it, because from usage perspective it is quite simple.
If data passed to wp_insert_post() has publish or future value in post_status field and date in the future then it is inserted in database with that date and future in post_status. Effectively it is already considered scheduled.
However something would need to happen to make that post published on that date, so this sets in motion several more pieces of code:
-
When
wp_insert_post()is done it callswp_transition_post_status(). -
Which executes several hooks, including
"{$new_status}_{$post->post_type}"which unwraps to something likefuture_post. - When post type is registered by
register_post_type()it adds_future_post_hook()function to'future_' . $post_typehook and so it executes. - That function creates single
WP-Cronschedule at the date of post, post’s ID in data and name ofpublish_future_post. - That schedule name has
check_and_publish_future_post()function hooked to it, that on run checks if post by that ID is scheduled and up to be live and if so flips its status topublishedusingwp_publish_post().
So the simplest way to create scheduled post is to just follow native mechanics and create it with wp_insert_post(), while passing future date.