Ticket #30615: 30615.diff
| File 30615.diff, 3.0 KB (added by , 12 years ago) |
|---|
-
src/wp-admin/includes/post.php
diff --git src/wp-admin/includes/post.php src/wp-admin/includes/post.php index b422056..2b13c0d 100644
function edit_post( $post_data = null ) { 314 314 $post_data = apply_filters( 'attachment_fields_to_save', $post_data, $attachment_data ); 315 315 } 316 316 317 // Convert taxonomy input to term IDs, to avoid ambiguity. 318 if ( isset( $post_data['tax_input'] ) ) { 319 foreach ( (array) $post_data['tax_input'] as $taxonomy => $terms ) { 320 // Hierarchical taxonomy data is already sent as term IDs, so no conversion is necessary. 321 if ( is_taxonomy_hierarchical( $taxonomy ) ) { 322 continue; 323 } 324 325 if ( ! is_array( $terms ) ) { 326 $comma = _x( ',', 'tag delimiter' ); 327 if ( ',' !== $comma ) { 328 $terms = str_replace( $comma, ',', $terms ); 329 } 330 $terms = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) ); 331 } 332 333 $clean_terms = array(); 334 foreach ( $terms as $term ) { 335 $_term = get_terms( $taxonomy, array( 336 'name' => $term, 337 'fields' => 'ids', 338 'hide_empty' => false, 339 ) ); 340 341 if ( ! empty( $_term ) ) { 342 $clean_terms[] = intval( $_term[0] ); 343 } else { 344 // No existing term was found, so pass the string. A new term will be created. 345 $clean_terms[] = $term; 346 } 347 } 348 349 $post_data['tax_input'][ $taxonomy ] = $clean_terms; 350 } 351 } 352 317 353 add_meta( $post_ID ); 318 354 319 355 update_post_meta( $post_ID, '_edit_last', get_current_user_id() ); -
tests/phpunit/tests/admin/includesPost.php
diff --git tests/phpunit/tests/admin/includesPost.php tests/phpunit/tests/admin/includesPost.php index f94605a..596cda8 100644
class Tests_Admin_includesPost extends WP_UnitTestCase { 137 137 } 138 138 139 139 /** 140 * @ticket 30615 141 */ 142 public function test_edit_post_should_parse_tax_input_by_name_rather_than_slug_for_nonhierarchical_taxonomies() { 143 $u = $this->factory->user->create( array( 'role' => 'editor' ) ); 144 wp_set_current_user( $u ); 145 146 register_taxonomy( 'wptests_tax', array( 'post' ) ); 147 $t1 = $this->factory->term->create( array( 148 'taxonomy' => 'wptests_tax', 149 'name' => 'foo', 150 'slug' => 'bar', 151 ) ); 152 $t2 = $this->factory->term->create( array( 153 'taxonomy' => 'wptests_tax', 154 'name' => 'bar', 155 'slug' => 'foo', 156 ) ); 157 158 $p = $this->factory->post->create(); 159 160 $post_data = array( 161 'post_ID' => $p, 162 'tax_input' => array( 163 'wptests_tax' => 'foo,baz', 164 ), 165 ); 166 167 edit_post( $post_data ); 168 169 $found = wp_get_post_terms( $p, 'wptests_tax' ); 170 171 // Should contain the term with the name 'foo', not the slug. 172 $this->assertContains( $t1, wp_list_pluck( $found, 'term_id' ) ); 173 174 // The 'baz' tag should have been created. 175 $this->assertContains( 'baz', wp_list_pluck( $found, 'name' ) ); 176 } 177 178 /** 140 179 * @ticket 27792 141 180 */ 142 181 function test_bulk_edit_posts_stomping() { … … class Tests_Admin_includesPost extends WP_UnitTestCase { 178 217 $this->assertEquals( 'closed', $post->ping_status ); 179 218 } 180 219 181 } 182 No newline at end of file 220 }