mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-04 12:44:31 +00:00
Parse non-hierarchical tag input into term IDs before sending to wp_insert_post().
When editing a post, non-hierarchical taxonomy terms are sent as the comma-separated list entered into the tax_input metabox. Passing these values directly to `wp_update_post()` meant that they were interpreted as term slugs rather than term names, causing mismatches when a typed string matched the slug of one term and the name of a different term. We fix the problem by preprocessing tax_input data sent from post.php, converting it to unambiguous term_ids before saving. Props boonebgorges, ArminBraun. Fixes #30615. git-svn-id: https://develop.svn.wordpress.org/trunk@31359 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -136,6 +136,45 @@ class Tests_Admin_includesPost extends WP_UnitTestCase {
|
||||
$this->assertEquals( 'draft', get_post( $post->ID )->post_status );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 30615
|
||||
*/
|
||||
public function test_edit_post_should_parse_tax_input_by_name_rather_than_slug_for_nonhierarchical_taxonomies() {
|
||||
$u = $this->factory->user->create( array( 'role' => 'editor' ) );
|
||||
wp_set_current_user( $u );
|
||||
|
||||
register_taxonomy( 'wptests_tax', array( 'post' ) );
|
||||
$t1 = $this->factory->term->create( array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
'name' => 'foo',
|
||||
'slug' => 'bar',
|
||||
) );
|
||||
$t2 = $this->factory->term->create( array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
'name' => 'bar',
|
||||
'slug' => 'foo',
|
||||
) );
|
||||
|
||||
$p = $this->factory->post->create();
|
||||
|
||||
$post_data = array(
|
||||
'post_ID' => $p,
|
||||
'tax_input' => array(
|
||||
'wptests_tax' => 'foo,baz',
|
||||
),
|
||||
);
|
||||
|
||||
edit_post( $post_data );
|
||||
|
||||
$found = wp_get_post_terms( $p, 'wptests_tax' );
|
||||
|
||||
// Should contain the term with the name 'foo', not the slug.
|
||||
$this->assertContains( $t1, wp_list_pluck( $found, 'term_id' ) );
|
||||
|
||||
// The 'baz' tag should have been created.
|
||||
$this->assertContains( 'baz', wp_list_pluck( $found, 'name' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 27792
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user