In `get_post_type_labels()`, ensure that filtered labels contain all required default values.
fixes #33543. git-svn-id: https://develop.svn.wordpress.org/trunk@33776 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
923498aaa4
commit
28767e1bac
|
@ -1337,6 +1337,8 @@ function get_post_type_labels( $post_type_object ) {
|
|||
|
||||
$post_type = $post_type_object->name;
|
||||
|
||||
$default_labels = clone $labels;
|
||||
|
||||
/**
|
||||
* Filter the labels of a specific post type.
|
||||
*
|
||||
|
@ -1349,7 +1351,12 @@ function get_post_type_labels( $post_type_object ) {
|
|||
*
|
||||
* @param object $labels Object with labels for the post type as member variables.
|
||||
*/
|
||||
return apply_filters( "post_type_labels_{$post_type}", $labels );
|
||||
$labels = apply_filters( "post_type_labels_{$post_type}", $labels );
|
||||
|
||||
// Ensure that the filtered labels contain all required default values.
|
||||
$labels = (object) array_merge( (array) $default_labels, (array) $labels );
|
||||
|
||||
return $labels;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -101,4 +101,25 @@ class Tests_Post_Types extends WP_UnitTestCase {
|
|||
update_option( 'permalink_structure', $old_permastruct );
|
||||
_unregister_post_type( 'foo' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 33543
|
||||
*/
|
||||
function test_get_post_type_labels_should_fall_back_on_defaults_when_filtered_labels_do_not_contain_the_keys() {
|
||||
add_filter( 'post_type_labels_foo', array( $this, 'filter_post_type_labels' ) );
|
||||
register_post_type( 'foo' );
|
||||
|
||||
$this->assertObjectHasAttribute( 'featured_image', get_post_type_object( 'foo' )->labels );
|
||||
$this->assertObjectHasAttribute( 'set_featured_image', get_post_type_object( 'foo' )->labels );
|
||||
|
||||
_unregister_post_type( 'foo' );
|
||||
remove_filter( 'post_type_labels_foo', array( $this, 'filter_post_type_labels' ) );
|
||||
}
|
||||
|
||||
public function filter_post_type_labels( $labels ) {
|
||||
unset( $labels->featured_image );
|
||||
unset( $labels->set_featured_image );
|
||||
return $labels;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue