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

wordpress.stackexchange https://wordpress.stackexchange.com/questions/381588

  •  22-04-2021
  •  | 
  •  

Вопрос

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?

Это было полезно?

Решение

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 ).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с wordpress.stackexchange
scroll top