From fa754724e11867a5d45da846840b3c68bf330dc1 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 29 Sep 2017 10:18:11 +0000 Subject: [PATCH] Posts, Post Types: Introduce `pre_trash_post` and `pre_untrash_post` filters to allow for short-circuiting `wp_trash_post()` and `wp_untrash_post()`. This brings parity with `pre_delete_post` filter in `wp_delete_post()`, introduced in [34082]. Props bor0. Fixes #42030. git-svn-id: https://develop.svn.wordpress.org/trunk@41638 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 3ea40d59fc..5e6efb4cb1 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -2595,6 +2595,19 @@ function wp_trash_post( $post_id = 0 ) { if ( $post['post_status'] == 'trash' ) return false; + /** + * Filters whether a post trashing should take place. + * + * @since 4.9.0 + * + * @param bool $trash Whether to go forward with trashing. + * @param WP_Post $post Post object. + */ + $check = apply_filters( 'pre_trash_post', null, $post ); + if ( null !== $check ) { + return $check; + } + /** * Fires before a post is sent to the trash. * @@ -2639,6 +2652,19 @@ function wp_untrash_post( $post_id = 0 ) { if ( $post['post_status'] != 'trash' ) return false; + /** + * Filters whether a post untrashing should take place. + * + * @since 4.9.0 + * + * @param bool $untrash Whether to go forward with untrashing. + * @param WP_Post $post Post object. + */ + $check = apply_filters( 'pre_untrash_post', null, $post ); + if ( null !== $check ) { + return $check; + } + /** * Fires before a post is restored from the trash. *