WordPress.org

Make WordPress Core

Changeset 33776


Ignore:
Timestamp:
08/28/2015 03:38:26 AM (6 years ago)
Author:
SergeyBiryukov
Message:

In get_post_type_labels(), ensure that filtered labels contain all required default values.

fixes #33543.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post-functions.php

    r33759 r33776  
    13381338    $post_type = $post_type_object->name;
    13391339
     1340    $default_labels = clone $labels;
     1341
    13401342    /**
    13411343     * Filter the labels of a specific post type.
     
    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
  • trunk/tests/phpunit/tests/post/types.php

    r31457 r33776  
    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}
Note: See TracChangeset for help on using the changeset viewer.