Is wp_insert_post exactly the same as publishing a post through the core UI?

I’m building a plugin that will call the wp_insert_post() function. I need to know if it is functionally identical to posting via the UI. For example, would other plugins (I’m thinking particularly of JetPack) share to social media or are there additional steps to replicate manually publishing (or scheduling) a post?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

There’s a bit more to the answer than just wp_insert_post(). That is the canonical way to insert a post and what the Classic Editor used to submit all of the post information at once.

The REST API (and thus Gutenberg) changes it a tad but running wp_insert_post initially just to setup a post in the db, then separately adds all of the meta data and taxonomies, etc (see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php?rev=49172#L577 ).

In terms of Jetpack’s Publicize feature, wp_insert_post will work just fine. We look for the wp_insert_post hook to sync up the post data used for the social media share ( https://github.com/Automattic/jetpack/blob/master/projects/packages/sync/src/modules/class-posts.php#L118 ).


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x