From 7efcf03d94357bd0d3cbce0ff70a3c1951252271 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Fri, 7 Feb 2020 17:31:52 +0000 Subject: [PATCH] Posts, Post Types: Introduce a filter which allows the addition of `__trashed` suffixes on post slugs to be skipped. Fixes #46433 git-svn-id: https://develop.svn.wordpress.org/trunk@47203 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 9913223e3f..982c7dc752 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -3843,7 +3843,20 @@ function wp_insert_post( $postarr, $wp_error = false ) { // If a trashed post has the desired slug, change it and let this post have it. if ( 'trash' !== $post_status && $post_name ) { - wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_ID ); + /** + * Filters whether or not to add a `__trashed` suffix to trashed posts that match the name of the updated post. + * + * @since 5.4.0 + * + * @param bool $add_trashed_suffix Whether to attempt to add the suffix. + * @param string $post_name The name of the post being updated. + * @param int $post_ID Post ID. + */ + $add_trashed_suffix = apply_filters( 'add_trashed_suffix_to_trashed_posts', true, $post_name, $post_ID ); + + if ( $add_trashed_suffix ) { + wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_ID ); + } } // When trashing an existing post, change its slug to allow non-trashed posts to use it.