[wp-trac] [WordPress Trac] #45122: Creating/Updating posts via REST API should be handled the same way as done via /wp-admin screen

WordPress Trac noreply at wordpress.org
Thu Oct 18 16:02:31 UTC 2018


#45122: Creating/Updating posts via REST API should be handled the same way as done
via /wp-admin screen
----------------------------+-----------------------------
 Reporter:  manzoorwani.jk  |      Owner:  (none)
     Type:  enhancement     |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  REST API        |    Version:  4.9.8
 Severity:  normal          |   Keywords:
  Focuses:  rest-api        |
----------------------------+-----------------------------
 All of us have posts that we want to be shared/updated/processed (and what
 not) as and when they are published/updated. As an example, if I want to
 share posts to social media based on some criteria/conditions or just
 share them along with the thumbnail, I would usually hook into `save_post`
 or `save_post_{$post_type}` and check if the post satisfies the
 conditions.

 The conditions will obviously be based upon the post **categories**,
 **tags**, **terms**, **meta**, **thumbnail**, **post_format** etc.

 This conditional check is possible only if those parameters are set at the
 time of post creation/update. It works well when done via `wp-admin`
 screen because the request is handled by
 [https://core.trac.wordpress.org/browser/tags/4.9.8/src/wp-admin/post.php
 post.php] which uses `edit_post` and `write_post` to do the job which
 eventually lets `wp_insert_post` handle everything.

 In case of `REST API`, the post is first
 [https://core.trac.wordpress.org/browser/tags/4.9.8/src/wp-includes/rest-
 api/endpoints/class-wp-rest-posts-controller.php#L530
 created]/[https://core.trac.wordpress.org/browser/tags/4.9.8/src/wp-
 includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L668
 updated] using `wp_insert_post` or `wp_update_post` without setting any of
 the above data, making the use of `save_post` or `wp_insert_post` hooks
 useless in the above mentioned example.

 There is not even an action or filter to hook into when all the post
 related stuff is done. #39345 is just a small example of what I want to
 point out.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45122>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list