Make WordPress Core

Ticket #51320: 51320.diff

File 51320.diff, 1.5 KB (added by Hareesh Pillai, 4 years ago)

Refreshed patch

  • src/wp-includes/post.php

     
    40914091                        if ( ! empty( $tax_object->default_term ) ) {
    40924092
    40934093                                // Filter out empty terms.
    4094                                 if ( isset( $postarr['tax_input'] ) && is_array( $postarr['tax_input'][ $taxonomy ] ) ) {
     4094                                if ( isset( $postarr['tax_input'][ $taxonomy ] ) && is_array( $postarr['tax_input'][ $taxonomy ] ) ) {
    40954095                                        $postarr['tax_input'][ $taxonomy ] = array_filter( $postarr['tax_input'][ $taxonomy ] );
    40964096                                }
    40974097
  • tests/phpunit/tests/post.php

     
    929929        }
    930930
    931931        /**
     932         * @ticket 51320
     933         */
     934        function test_create_post_with_taxonomies() {
     935                $post_type = 'test_post_type';
     936                $tax1      = 'test_tax1';
     937                $tax2      = 'test_tax2';
     938
     939                register_post_type( $post_type, array( 'taxonomies' => array( $tax1, $tax2 ) ) );
     940                register_taxonomy( $tax1, $post_type, array( 'default_term' => 'term_1' ) );
     941                register_taxonomy( $tax2, $post_type, array( 'default_term' => 'term_2' ) );
     942
     943                $post_id = self::factory()->post->create( array( 'post_type' => $post_type ) );
     944
     945                $taxonomies = get_post_taxonomies( $post_id );
     946
     947                $this->assertContains( $tax1, $taxonomies );
     948                $this->assertContains( $tax2, $taxonomies );
     949        }
     950
     951        /**
    932952         * @ticket 21212
    933953         */
    934954        function test_utf8mb3_post_saves_with_emoji() {