Make WordPress Core

Opened 4 weeks ago

Last modified 4 weeks ago

#61604 new enhancement

Split `wp_insert_post` in two

Reported by: drzraf's profile drzraf Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version:
Component: Database Keywords:
Focuses: coding-standards Cc:

Description

I suggest to split this function in two, after the wp_insert_post_data filter (before the if ( $update ) { clause)

This key function is huge and its first half is idempotent but does handy processing on a post array (filtering/sanitation/defaults).
If could be named something like preprocess_post_data()

By splitting it in two, the first half would become a dedicated routine a developer could rely on in order to go from "raw" post-data to an insertable one.

In my use-case I need to insert temporary posts (inside a temporary table sharing the structure of wp_posts). The first half of wp_insert_post is exactly how I would like to process my data but I've currently no way to reuse that code.

Another benefit would be more granular and easier-to-test interfaces.

Change History (1)

#1 @mi5t4n
4 weeks ago

@drzraf If the temporary table will have the same structure as wp_posts, we probably can register and use some sort of custom private CPT. After we do the required processing, we can change the CPT type.

We can use another way also, save the CPT with different post_status like processing. Once we do all the required processing, we change the CPT status to publish.

Above both have the advantage of querying the data with WP_Query and we can take the advantage of WP Object Cache as well.

Last edited 4 weeks ago by mi5t4n (previous) (diff)
Note: See TracTickets for help on using tickets.