From f4cc32fac931b0dbbbd5a2bebf0466a2c832f294 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Sat, 15 Mar 2014 05:08:40 +0000 Subject: [PATCH] XML-RPC: In wp.editPost, Remove all terms in a taxonomy when an empty array is explicitly passed. props jstraitiff, maxcutler. fixes #26686. git-svn-id: https://develop.svn.wordpress.org/trunk@27554 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-xmlrpc-server.php | 1 + tests/phpunit/tests/xmlrpc/wp/editPost.php | 27 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/wp-includes/class-wp-xmlrpc-server.php b/src/wp-includes/class-wp-xmlrpc-server.php index 17657023f1..c52127f20f 100644 --- a/src/wp-includes/class-wp-xmlrpc-server.php +++ b/src/wp-includes/class-wp-xmlrpc-server.php @@ -1131,6 +1131,7 @@ class wp_xmlrpc_server extends IXR_Server { return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) ); $term_ids = $post_data['terms'][$taxonomy]; + $terms[ $taxonomy ] = array(); foreach ( $term_ids as $term_id ) { $term = get_term_by( 'id', $term_id, $taxonomy ); diff --git a/tests/phpunit/tests/xmlrpc/wp/editPost.php b/tests/phpunit/tests/xmlrpc/wp/editPost.php index 3bbd366558..23c0b776aa 100644 --- a/tests/phpunit/tests/xmlrpc/wp/editPost.php +++ b/tests/phpunit/tests/xmlrpc/wp/editPost.php @@ -308,6 +308,33 @@ class Tests_XMLRPC_wp_editPost extends WP_XMLRPC_UnitTestCase { $this->assertContains( $term_id, $term_ids ); } + /** + * @ticket 26686 + */ + function test_clear_categories_on_edit() { + $editor_id = $this->make_user_by_role( 'editor' ); + + $post_id = $this->factory->post->create( array( 'post_author' => $editor_id ) ); + $term_id = $this->factory->category->create(); + $this->factory->term->add_post_terms( $post_id, $term_id, 'category', true ); + $term_ids = wp_list_pluck( get_the_category( $post_id ), 'term_id' ); + $this->assertContains( $term_id, $term_ids ); + + $new_post_content = array( + 'ID' => $post_id, + 'post_title' => 'Updated', + 'terms' => array( + 'category' => array() + ) + ); + $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $new_post_content ) ); + $this->assertNotInstanceOf( 'IXR_Error', $result ); + $this->assertEquals( 'Updated', get_post( $post_id )->post_title ); + + $term_ids = wp_list_pluck( get_the_category( $post_id ), 'term_id' ); + $this->assertNotContains( $term_id, $term_ids ); + } + /** * @ticket 23219 */