admin管理员组文章数量:1303670
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?
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?
1 Answer
Reset to default 2There'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/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/Automattic/jetpack/blob/master/projects/packages/sync/src/modules/class-posts.php#L118 ).
本文标签: Is wpinsertpost exactly the same as publishing a post through the core UI
版权声明:本文标题:Is wp_insert_post exactly the same as publishing a post through the core UI? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741769439a2396661.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
wp_insert_post()
. (But that is only an assumption) – kero Commented Jan 15, 2021 at 17:54wp_insert_post()
does do the actions hooked onsave_post
andpost_updated
. So the answer is yes, although you will need to specify post_data like publish date, sanitize post_name if necessary, post_meta etc if you want something other than the defaults (and the $post->ID when updating, otherwise you'll create new posts every time). – tdj Commented Jan 15, 2021 at 18:04