Ticket #38218: 38218.2.diff
File 38218.2.diff, 17.4 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-post-type.php
diff --git src/wp-includes/class-wp-post-type.php src/wp-includes/class-wp-post-type.php index ba37a02fb5..595120488c 100644
13 13 * @since 4.6.0 14 14 * 15 15 * @see register_post_type() 16 * 17 * @property string label 18 * @property object labels 19 * @property string description 16 20 */ 17 21 final class WP_Post_Type { 18 22 /** … … final class WP_Post_Type { 27 31 * Name of the post type shown in the menu. Usually plural. 28 32 * 29 33 * @since 4.6.0 30 * @var string $label34 * @var callable|string $_label 31 35 */ 32 p ublic $label;36 private $_label; 33 37 34 38 /** 35 39 * Labels object for this post type. … … final class WP_Post_Type { 40 44 * @see get_post_type_labels() 41 45 * 42 46 * @since 4.6.0 43 * @var object $labels47 * @var callable|object $_labels 44 48 */ 45 p ublic $labels;49 private $_labels; 46 50 47 51 /** 48 52 * A short descriptive summary of what the post type is. … … final class WP_Post_Type { 50 54 * Default empty. 51 55 * 52 56 * @since 4.6.0 53 * @var string $description57 * @var callable|string $description 54 58 */ 55 p ublic $description = '';59 private $_description = ''; 56 60 57 61 /** 58 62 * Whether a post type is intended for use publicly either via the admin interface or by front-end users. … … final class WP_Post_Type { 498 502 } 499 503 } 500 504 505 506 $args['_labels'] = $args['labels']; 507 $args['_description'] = $args['description']; 508 509 if ( isset( $args['label'] ) ) { 510 $args['_label'] = $args['label']; 511 } 512 513 unset( $args['label'], $args['labels'], $args['description'] ); 514 501 515 foreach ( $args as $property_name => $property_value ) { 502 516 $this->$property_name = $property_value; 503 517 } 518 } 519 520 /** 521 * Magic method for accessing the post type labels. 522 * 523 * @since 5.0.0 524 * @access public 525 * 526 * @param string $key Label to retrieve. 527 * @return object|string Post type labels. 528 */ 529 public function __get( $key ) { 530 if ( 'label' === $key ) { 531 if ( is_callable( $this->_label ) ) { 532 return call_user_func( $this->_label ); 533 } 534 535 if ( is_string( $this->_label ) ) { 536 return $this->_label; 537 } 538 539 return $this->labels->name; 540 } 541 542 if ( 'labels' === $key ) { 543 $labels = array(); 544 545 if ( is_callable( $this->_labels ) ) { 546 $labels = call_user_func( $this->_labels ); 547 } 548 549 if ( is_array( $this->_labels ) ) { 550 $labels = $this->_labels; 551 } 552 553 $post_type_object = (object) array( 554 'name' => $this->name, 555 'hierarchical' => $this->hierarchical, 556 'labels' => (object) $labels, 557 ); 558 559 return get_post_type_labels( $post_type_object ); 560 } 561 562 if ( 'description' === $key ) { 563 if ( is_callable( $this->_description ) ) { 564 return call_user_func( $this->_description ); 565 } 566 567 return $this->_description; 568 } 504 569 505 $this->labels = get_post_type_labels( $this ); 506 $this->label = $this->labels->name; 570 return null; 507 571 } 508 572 509 573 /** -
src/wp-includes/class-wp-taxonomy.php
diff --git src/wp-includes/class-wp-taxonomy.php src/wp-includes/class-wp-taxonomy.php index 92ad89b557..242e5e9571 100644
11 11 * Core class used for interacting with taxonomies. 12 12 * 13 13 * @since 4.7.0 14 * 15 * @property string label 16 * @property object labels 17 * @property string description 14 18 */ 15 19 final class WP_Taxonomy { 16 20 /** … … final class WP_Taxonomy { 27 31 * @since 4.7.0 28 32 * @var string 29 33 */ 30 p ublic $label;34 private $_label; 31 35 32 36 /** 33 37 * An array of labels for this taxonomy. … … final class WP_Taxonomy { 35 39 * @since 4.7.0 36 40 * @var object 37 41 */ 38 p ublic $labels = array();42 private $_labels = array(); 39 43 40 44 /** 41 45 * A short descriptive summary of what the taxonomy is for. … … final class WP_Taxonomy { 43 47 * @since 4.7.0 44 48 * @var string 45 49 */ 46 p ublic $description = '';50 private $_description = ''; 47 51 48 52 /** 49 53 * Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users. … … final class WP_Taxonomy { 371 375 } 372 376 } 373 377 378 $args['_labels'] = $args['labels']; 379 $args['_description'] = $args['description']; 380 381 if ( isset( $args['label'] ) ) { 382 $args['_label'] = $args['label']; 383 } 384 385 unset( $args['label'], $args['labels'], $args['description'] ); 386 374 387 foreach ( $args as $property_name => $property_value ) { 375 388 $this->$property_name = $property_value; 376 389 } 390 } 391 392 /** 393 * Magic method for accessing the taxonomy labels. 394 * 395 * @since 5.0.0 396 * @access public 397 * 398 * @param string $key Label to retrieve. 399 * @return object|string Taxonomy labels. 400 */ 401 public function __get( $key ) { 402 if ( 'label' === $key ) { 403 if ( is_callable( $this->_label ) ) { 404 return call_user_func( $this->_label ); 405 } 406 407 if ( is_string( $this->_label ) ) { 408 return $this->_label; 409 } 410 411 return $this->labels->name; 412 } 413 414 if ( 'labels' === $key ) { 415 $labels = array(); 416 417 if ( is_callable( $this->_labels ) ) { 418 $labels = call_user_func( $this->_labels ); 419 } 420 421 if ( is_array( $this->_labels ) ) { 422 $labels = $this->_labels; 423 } 424 425 $taxonomy_object = (object) array( 426 'name' => $this->name, 427 'hierarchical' => $this->hierarchical, 428 'labels' => (object) $labels, 429 ); 430 431 return get_taxonomy_labels( $taxonomy_object ); 432 } 433 434 if ( 'description' === $key ) { 435 if ( is_callable( $this->_description ) ) { 436 return call_user_func( $this->_description ); 437 } 438 439 return $this->_description; 440 } 377 441 378 $this->labels = get_taxonomy_labels( $this ); 379 $this->label = $this->labels->name; 442 return null; 380 443 } 381 444 382 445 /** -
src/wp-includes/post.php
diff --git src/wp-includes/post.php src/wp-includes/post.php index 7feb284e85..f8030226c6 100644
function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) 1173 1173 * @param array|string $args { 1174 1174 * Array or string of arguments for registering a post type. 1175 1175 * 1176 * @type string $labelName of the post type shown in the menu. Usually plural.1176 * @type callable|string $label Name of the post type shown in the menu. Usually plural. 1177 1177 * Default is value of $labels['name']. 1178 * @type array $labelsAn array of labels for this post type. If not set, post1178 * @type callable|array $labels An array of labels for this post type. If not set, post 1179 1179 * labels are inherited for non-hierarchical types and page 1180 1180 * labels for hierarchical ones. See get_post_type_labels() for a full 1181 1181 * list of supported labels. 1182 * @type string $descriptionA short descriptive summary of what the post type is.1182 * @type callable|string $description A short descriptive summary of what the post type is. 1183 1183 * Default empty. 1184 1184 * @type bool $public Whether a post type is intended for use publicly either via 1185 1185 * the admin interface or by front-end users. While the default … … function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) 1257 1257 * @type bool $feeds Whether the feed permastruct should be built for this post type. 1258 1258 * Default is value of $has_archive. 1259 1259 * @type bool $pages Whether the permastruct should provide for pagination. Default true. 1260 * @type const$ep_mask Endpoint mask to assign. If not specified and permalink_epmask is set,1260 * @type string $ep_mask Endpoint mask to assign. If not specified and permalink_epmask is set, 1261 1261 * inherits from $permalink_epmask. If not specified and permalink_epmask 1262 1262 * is not set, defaults to EP_PERMALINK. 1263 1263 * } -
src/wp-includes/taxonomy.php
diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php index 7a278323af..5bb55b2f9b 100644
function is_taxonomy_hierarchical( $taxonomy ) { 342 342 * @param array|string $args { 343 343 * Optional. Array or query string of arguments for registering a taxonomy. 344 344 * 345 * @type array $labels An array of labels for this taxonomy. By default, Tag labels are 345 * @type callable|string $label Name of the taxonomy shown in the menu. Usually plural. 346 * Default is value of $labels['name']. 347 * @type callable|array $labels An array of labels for this taxonomy. By default, Tag labels are 346 348 * used for non-hierarchical taxonomies, and Category labels are used 347 349 * for hierarchical taxonomies. See accepted values in 348 350 * get_taxonomy_labels(). Default empty array. 349 * @type string $descriptionA short descriptive summary of what the taxonomy is for. Default empty.351 * @type callable|string $description A short descriptive summary of what the taxonomy is for. Default empty. 350 352 * @type bool $public Whether a taxonomy is intended for use publicly either via 351 353 * the admin interface or by front-end users. The default settings 352 354 * of `$publicly_queryable`, `$show_ui`, and `$show_in_nav_menus` … … function unregister_taxonomy( $taxonomy ) { 495 497 * @since 4.4.0 Added the `items_list_navigation` and `items_list` labels. 496 498 * @since 4.9.0 Added the `most_used` and `back_to_items` labels. 497 499 * 498 * @param WP_Taxonomy $tax Taxonomy object.500 * @param object|WP_Taxonomy $tax Taxonomy object. 499 501 * @return object { 500 502 * Taxonomy labels object. The first default value is for non-hierarchical taxonomies 501 503 * (like tags) and the second one is for hierarchical taxonomies (like categories). -
tests/phpunit/data/languages/de_DE.po
diff --git tests/phpunit/data/languages/de_DE.mo tests/phpunit/data/languages/de_DE.mo index b65a14e19c..87dca3b265 100644 Binary files tests/phpunit/data/languages/de_DE.mo and tests/phpunit/data/languages/de_DE.mo differ diff --git tests/phpunit/data/languages/de_DE.po tests/phpunit/data/languages/de_DE.po index 4d66b76c10..b372f97fd2 100644
2 2 # This file is distributed under the same license as the 4.9.x package. 3 3 msgid "" 4 4 msgstr "" 5 "PO-Revision-Date: 2018-0 8-13 19:19+0300\n"5 "PO-Revision-Date: 2018-09-14 16:50+0900\n" 6 6 "MIME-Version: 1.0\n" 7 7 "Content-Type: text/plain; charset=UTF-8\n" 8 8 "Content-Transfer-Encoding: 8bit\n" 9 9 "Plural-Forms: nplurals=2; plural=n != 1;\n" 10 "X-Generator: Poedit 2.1 .1\n"10 "X-Generator: Poedit 2.1\n" 11 11 "Project-Id-Version: Development (4.9.x)\n" 12 12 "Language: de_DE\n" 13 13 "POT-Creation-Date: \n" … … msgstr "Jetzt %s aktualisieren" 48 48 #: wp-includes/user.php:3445 49 49 msgid "[%1$s] Confirm Action: %2$s" 50 50 msgstr "[%1$s] Aktion bestätigen: %2$s" 51 52 #: wp-includes/post.php:1445 53 msgctxt "post type singular name" 54 msgid "Post" 55 msgstr "Beitrag" 56 57 #: wp-includes/post.php:1445 58 msgctxt "post type singular name" 59 msgid "Page" 60 msgstr "Seite" 61 62 #: wp-includes/post.php:1444 63 msgctxt "post type general name" 64 msgid "Pages" 65 msgstr "Seiten" 66 67 #: wp-includes/post.php:1447 68 msgid "Add New Page" 69 msgstr "Neue Seite erstellen" 70 71 #: wp-includes/post.php:1452 72 msgid "Search Posts" 73 msgstr "Beiträge durchsuchen" 74 75 #: wp-includes/post.php:1448 76 msgid "Edit Page" 77 msgstr "Seite bearbeiten" 78 79 #: wp-includes/post.php:1444 80 msgctxt "post type general name" 81 msgid "Posts" 82 msgstr "Beiträge" 83 84 #: wp-includes/post.php:1455 85 msgid "Parent Page:" 86 msgstr "Übergeordnete Seite:" 87 88 #: wp-includes/post.php:1447 89 msgid "Add New Post" 90 msgstr "Neuen Beitrag erstellen" 91 92 #: wp-includes/post.php:1452 93 msgid "Search Pages" 94 msgstr "Seiten durchsuchen" -
tests/phpunit/tests/post/getPostTypeLabels.php
diff --git tests/phpunit/tests/post/getPostTypeLabels.php tests/phpunit/tests/post/getPostTypeLabels.php index aff320e641..b919970568 100644
class Tests_Get_Post_Type_Labels extends WP_UnitTestCase { 96 96 97 97 unregister_post_type( 'foo' ); 98 98 99 $this->assert ObjectHasAttribute( 'labels', $post_type_object);100 $this->assert ObjectHasAttribute( 'label', $post_type_object);99 $this->assertInternalType( 'object', $post_type_object->labels ); 100 $this->assertInternalType( 'string', $post_type_object->label ); 101 101 $this->assertObjectHasAttribute( 'not_found_in_trash', $post_type_object->labels ); 102 $this->assertObjectHasAttribute( 'parent_item_colon', $post_type_object->labels ); 102 103 } 103 104 104 105 public function test_label_should_be_derived_from_labels_when_registering_a_post_type() { … … class Tests_Get_Post_Type_Labels extends WP_UnitTestCase { 131 132 } 132 133 133 134 public function filter_post_type_labels( $labels ) { 134 unset( $labels->featured_image ); 135 unset( $labels->set_featured_image ); 135 unset( $labels->featured_image, $labels->set_featured_image ); 136 136 137 137 return $labels; 138 138 } 139 140 /** 141 * @ticket 26511 142 */ 143 public function test_post_type_menu_label() { 144 register_post_type( 145 'foo', 146 array( 147 'label' => 'Foos', 148 ) 149 ); 150 151 register_post_type( 'bar' ); 152 153 $this->assertSame( 'Foos', get_post_type_object( 'foo' )->label ); 154 $this->assertSame( 'Posts', get_post_type_object( 'bar' )->label ); 155 } 156 157 /** 158 * @ticket 26511 159 */ 160 public function test_post_type_menu_label_callback() { 161 register_post_type( 162 'foo', 163 array( 164 'label' => function () { 165 return 'Foos'; 166 }, 167 ) 168 ); 169 170 register_post_type( 'bar' ); 171 172 $this->assertSame( 'Foos', get_post_type_object( 'foo' )->label ); 173 $this->assertSame( 'Posts', get_post_type_object( 'bar' )->label ); 174 } 175 176 /** 177 * @ticket 26511 178 */ 179 public function test_post_type_labels_callback() { 180 register_post_type( 181 'foo', 182 array( 183 'labels' => function () { 184 return array( 185 'singular_name' => 'Bar', 186 ); 187 }, 188 ) 189 ); 190 191 $this->assertSame( 'Posts', get_post_type_object( 'foo' )->labels->name ); 192 $this->assertSame( 'Bar', get_post_type_object( 'foo' )->labels->singular_name ); 193 } 194 195 /** 196 * @ticket 26511 197 */ 198 public function test_post_type_labels_should_be_translated_after_locale_switching() { 199 register_post_type( 'foo' ); 200 201 $post_type_object = get_post_type_object( 'foo' ); 202 203 $labels_en = $post_type_object->labels; 204 205 switch_to_locale( 'de_DE' ); 206 207 $labels_de = $post_type_object->labels; 208 209 // Cleanup. 210 restore_current_locale(); 211 212 $this->assertEqualSetsWithIndex( 213 array( 214 'name' => 'Posts', 215 'singular_name' => 'Post', 216 'add_new' => 'Add New', 217 'add_new_item' => 'Add New Post', 218 'edit_item' => 'Edit Post', 219 'new_item' => 'New Post', 220 'view_item' => 'View Post', 221 'view_items' => 'View Posts', 222 'search_items' => 'Search Posts', 223 'not_found' => 'No posts found.', 224 'not_found_in_trash' => 'No posts found in Trash.', 225 'parent_item_colon' => null, 226 'all_items' => 'All Posts', 227 'archives' => 'Post Archives', 228 'attributes' => 'Post Attributes', 229 'insert_into_item' => 'Insert into post', 230 'uploaded_to_this_item' => 'Uploaded to this post', 231 'featured_image' => 'Featured Image', 232 'set_featured_image' => 'Set featured image', 233 'remove_featured_image' => 'Remove featured image', 234 'use_featured_image' => 'Use as featured image', 235 'filter_items_list' => 'Filter posts list', 236 'items_list_navigation' => 'Posts list navigation', 237 'items_list' => 'Posts list', 238 'menu_name' => 'Posts', 239 'name_admin_bar' => 'foo', 240 ), 241 (array) $labels_en 242 ); 243 244 $this->assertEqualSetsWithIndex( 245 array( 246 'name' => 'Beiträge', 247 'singular_name' => 'Beitrag', 248 'add_new' => 'Add New', 249 'add_new_item' => 'Neuen Beitrag erstellen', 250 'edit_item' => 'Edit Post', 251 'new_item' => 'New Post', 252 'view_item' => 'View Post', 253 'view_items' => 'View Posts', 254 'search_items' => 'Beiträge durchsuchen', 255 'not_found' => 'No posts found.', 256 'not_found_in_trash' => 'No posts found in Trash.', 257 'parent_item_colon' => null, 258 'all_items' => 'All Posts', 259 'archives' => 'Post Archives', 260 'attributes' => 'Post Attributes', 261 'insert_into_item' => 'Insert into post', 262 'uploaded_to_this_item' => 'Uploaded to this post', 263 'featured_image' => 'Featured Image', 264 'set_featured_image' => 'Set featured image', 265 'remove_featured_image' => 'Remove featured image', 266 'use_featured_image' => 'Use as featured image', 267 'filter_items_list' => 'Filter posts list', 268 'items_list_navigation' => 'Posts list navigation', 269 'items_list' => 'Posts list', 270 'menu_name' => 'Beiträge', 271 'name_admin_bar' => 'foo', 272 ), 273 (array) $labels_de 274 ); 275 } 139 276 }