Opened 3 months ago
Last modified 3 months ago
#61604 new enhancement
Split `wp_insert_post` in two
Reported by: | 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.
@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
likeprocessing
. Once we do all the required processing, we change the CPT status topublish
.Above both have the advantage of querying the data with
WP_Query
and we can take the advantage of WP Object Cache as well.