[wp-trac] [WordPress Trac] #42030: Introduce pre_trash_post filter
WordPress Trac
noreply at wordpress.org
Fri Sep 29 13:05:57 UTC 2017
#42030: Introduce pre_trash_post filter
-------------------------------+-----------------------------
Reporter: bor0 | Owner: SergeyBiryukov
Type: enhancement | Status: reopened
Priority: normal | Milestone: 4.9
Component: Posts, Post Types | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
-------------------------------+-----------------------------
Comment (by SergeyBiryukov):
Replying to [comment:6 bor0]:
> little nitpick, we use:
> `$post_trash = get_post( $id, ARRAY_A );` for `wp_trash_post`
> and
> `$post_delete = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM
$wpdb->posts WHERE ID = %d", $id ) );` for `wp_delete_post`
>
> Thus, we have type `array` in `wp_trash_post`, and type `WP_Post` in
`wp_delete_post`.
Good catch. Luckily, `wp_trash_post()` already has `WP_Post` as one of the
documented return values, as it falls back to `wp_delete_post()` if Trash
is disabled. `wp_untrash_post()` also has `WP_Post` as a return value,
which is not exactly accurate at the moment. Both function only pass the
post ID to their hooks, not an array or object, so the internal
representation should be relatively safe to change.
On a related note, `wp_delete_post()` has `WP_Post` as a documented return
value, but returns a regular object instead. Same for `pre_delete_post`
filter, `$post` parameter type is inaccurate there.
I think it makes sense to standardize on `WP_Post` here.
Replying to [comment:8 ramiy]:
> Why not using `pre_trash_{$post_type}`?
This was meant to complement the existing `pre_delete_post` filter added
in [34082]. There is no corresponding `pre_delete_{$post_type}` filter, it
can be explored in a new ticket though.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42030#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list