WordPress.org

Make WordPress Core

Ticket #33543: 33543.patch

File 33543.patch, 1.9 KB (added by SergeyBiryukov, 6 years ago)
  • src/wp-includes/post-functions.php

     
    13371337
    13381338        $post_type = $post_type_object->name;
    13391339
     1340        $default_labels = clone $labels;
     1341
    13401342        /**
    13411343         * Filter the labels of a specific post type.
    13421344         *
     
    13491351         *
    13501352         * @param object $labels Object with labels for the post type as member variables.
    13511353         */
    1352         return apply_filters( "post_type_labels_{$post_type}", $labels );
     1354        $labels = apply_filters( "post_type_labels_{$post_type}", $labels );
     1355
     1356        // Ensure that the filtered labels contain all required default values.
     1357        $labels = (object) array_merge( (array) $default_labels, (array) $labels );
     1358
     1359        return $labels;
    13531360}
    13541361
    13551362/**
  • tests/phpunit/tests/post/types.php

     
    101101                update_option( 'permalink_structure', $old_permastruct );
    102102                _unregister_post_type( 'foo' );
    103103        }
     104
     105        /**
     106         * @ticket 33543
     107         */
     108        function test_get_post_type_labels_should_fall_back_on_defaults_when_filtered_labels_do_not_contain_the_keys() {
     109                add_filter( 'post_type_labels_foo', array( $this, 'filter_post_type_labels' ) );
     110                register_post_type( 'foo' );
     111
     112                $this->assertObjectHasAttribute( 'featured_image', get_post_type_object( 'foo' )->labels );
     113                $this->assertObjectHasAttribute( 'set_featured_image', get_post_type_object( 'foo' )->labels );
     114
     115                _unregister_post_type( 'foo' );
     116                remove_filter( 'post_type_labels_foo', array( $this, 'filter_post_type_labels' ) );
     117        }
     118
     119        public function filter_post_type_labels( $labels ) {
     120                unset( $labels->featured_image );
     121                unset( $labels->set_featured_image );
     122                return $labels;
     123        }
     124
    104125}