Make WordPress Core

Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#33023 closed defect (bug) (fixed)

_get_custom_object_labels should not change data type to Array from Object.

Reported by: zsiteru's profile zsiteru Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.4 Priority: normal
Severity: normal Version: 4.2.2
Component: Posts, Post Types Keywords: has-patch
Focuses: Cc:

Description

When you use construction like this:
$post_type_obj = get_post_type_object ( $post_type );
$labels = get_post_type_labels($post_type_obj)
.............................
global $wp_post_types will be rewrite and property $wp_post_types[$post_type]->labels will be an array and must be object.
It is critical for wp-admin/includes/post.php $sendback_text = get_post_type_object( $post->post_type )->labels->all_items; (~line 1250)

wp-includes/post.php line:1716 - 1718

		$defaults[$key] = $object->hierarchical ? $value[1] : $value[0];
 	}
 	$labels = array_merge( $defaults, $object->labels );
+	$object->labels = (object)$object->labels;
 	return (object) $labels;
 }

Attachments (1)

33023.diff (508 bytes) - added by Toro_Unit 9 years ago.

Download all attachments as: .zip

Change History (7)

#1 @Toro_Unit
9 years ago

  • Keywords has-patch added

Add Test Case.

<?php
class SampleTest extends WP_UnitTestCase {
	function test_sample() {
		$args = array(
			'public' => true,
			'label'  => 'Books'
		);
		register_post_type( 'book', $args );
		$pre = get_post_type_object( 'book' )->labels;
		get_post_type_labels( get_post_type_object( 'book' ) );
		$post = get_post_type_object( 'book' )->labels;
		$this->assertEquals( $pre, $post ); // fail !!!!
	}
}

@Toro_Unit
9 years ago

#2 @Toro_Unit
9 years ago

  • Component changed from General to Posts, Post Types

There is Same Problem in get_taxonomy_labels.

$wp_taxonomies[ $taxonomy ]->labels is converted array from object.

#3 @Toro_Unit
9 years ago

If use get_post_type_labels ,
Notice Error occured in wp_admin_bar_new_content_menu and wp_admin_bar_edit_menu.

Should fix the wp_admin_bar_new_content_menu and wp_admin_bar_edit_menu?

#4 @Toro_Unit
9 years ago

  • Summary changed from Error wp-includes/post.php in _get_custom_object_labels to _get_custom_object_labels should not change data type to Array from Object.

_get_custom_object_labels should not change data type to array from object.

#5 @wonderboymusic
9 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 34102:

Objects are passed by-reference since PHP 5. In _get_custom_object_labels(), cast $object->labels back to object before returning. This function is weird.

Adds unit test.

Props Toro_Unit.
Fixes #33023.

#6 @wonderboymusic
9 years ago

  • Milestone changed from Awaiting Review to 4.4
Note: See TracTickets for help on using tickets.