Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#45122 closed enhancement (wontfix)

Creating/Updating posts via REST API should be handled the same way as done via /wp-admin screen

Reported by: manzoorwanijk's profile manzoorwani.jk Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.9.8
Component: Posts, Post Types Keywords:
Focuses: rest-api Cc:

Description

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 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 created/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.

Change History (3)

#1 @manzoorwani.jk
5 years ago

Why ca't we prepare the post data array before calling wp_insert_post and then let it handle everything?

#2 @SergeyBiryukov
5 years ago

  • Component changed from REST API to Posts, Post Types

#3 @danielbachhuber
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Hi @manzoorwani.jk,

Thanks for the report! While we can't significantly change how the REST API behaves at this point, #42864 (slated for WordPress 5.0) will provide what you need.

Note: See TracTickets for help on using tickets.