From 20edeb6e091c84c6a32f12831cbd64daa0abba7e Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Thu, 11 Aug 2022 20:00:10 +0000 Subject: [PATCH] Posts, Post Types: Prevent categories from being overwritten when updating a post using `wp_insert_post()`. This prevents existing category relationships being overridden with the default category when none is provided in the post data. Props markoheijnen, leewillis77, desrosj Fixes #19954 Built from https://develop.svn.wordpress.org/trunk@53883 git-svn-id: http://core.svn.wordpress.org/trunk@53442 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 2 ++ wp-includes/version.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index d999c7bfeb..b434ae52e4 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -4142,6 +4142,8 @@ function wp_insert_post( $postarr, $wp_error = false, $fire_after_hooks = true ) if ( ! empty( $postarr['post_category'] ) ) { // Filter out empty terms. $post_category = array_filter( $postarr['post_category'] ); + } elseif ( $update && ! isset( $postarr['post_category'] ) ) { + $post_category = $post_before->post_category; } // Make sure we set a valid category. diff --git a/wp-includes/version.php b/wp-includes/version.php index e55896f474..e8557ce318 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-53882'; +$wp_version = '6.1-alpha-53883'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.