Make WordPress Core

Ticket #38218: 38218.2.diff

File 38218.2.diff, 17.4 KB (added by swissspidy, 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
     
    1313 * @since 4.6.0
    1414 *
    1515 * @see register_post_type()
     16 *
     17 * @property string label
     18 * @property object labels
     19 * @property string description
    1620 */
    1721final class WP_Post_Type {
    1822        /**
    final class WP_Post_Type { 
    2731         * Name of the post type shown in the menu. Usually plural.
    2832         *
    2933         * @since 4.6.0
    30          * @var string $label
     34         * @var callable|string $_label
    3135         */
    32         public $label;
     36        private $_label;
    3337
    3438        /**
    3539         * Labels object for this post type.
    final class WP_Post_Type { 
    4044         * @see get_post_type_labels()
    4145         *
    4246         * @since 4.6.0
    43          * @var object $labels
     47         * @var callable|object $_labels
    4448         */
    45         public $labels;
     49        private $_labels;
    4650
    4751        /**
    4852         * A short descriptive summary of what the post type is.
    final class WP_Post_Type { 
    5054         * Default empty.
    5155         *
    5256         * @since 4.6.0
    53          * @var string $description
     57         * @var callable|string $description
    5458         */
    55         public $description = '';
     59        private $_description = '';
    5660
    5761        /**
    5862         * Whether a post type is intended for use publicly either via the admin interface or by front-end users.
    final class WP_Post_Type { 
    498502                        }
    499503                }
    500504
     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
    501515                foreach ( $args as $property_name => $property_value ) {
    502516                        $this->$property_name = $property_value;
    503517                }
     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                }
    504569
    505                 $this->labels = get_post_type_labels( $this );
    506                 $this->label  = $this->labels->name;
     570                return null;
    507571        }
    508572
    509573        /**
  • 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
     
    1111 * Core class used for interacting with taxonomies.
    1212 *
    1313 * @since 4.7.0
     14 *
     15 * @property string label
     16 * @property object labels
     17 * @property string description
    1418 */
    1519final class WP_Taxonomy {
    1620        /**
    final class WP_Taxonomy { 
    2731         * @since 4.7.0
    2832         * @var string
    2933         */
    30         public $label;
     34        private $_label;
    3135
    3236        /**
    3337         * An array of labels for this taxonomy.
    final class WP_Taxonomy { 
    3539         * @since 4.7.0
    3640         * @var object
    3741         */
    38         public $labels = array();
     42        private $_labels = array();
    3943
    4044        /**
    4145         * A short descriptive summary of what the taxonomy is for.
    final class WP_Taxonomy { 
    4347         * @since 4.7.0
    4448         * @var string
    4549         */
    46         public $description = '';
     50        private $_description = '';
    4751
    4852        /**
    4953         * Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users.
    final class WP_Taxonomy { 
    371375                        }
    372376                }
    373377
     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
    374387                foreach ( $args as $property_name => $property_value ) {
    375388                        $this->$property_name = $property_value;
    376389                }
     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                }
    377441
    378                 $this->labels = get_taxonomy_labels( $this );
    379                 $this->label  = $this->labels->name;
     442                return null;
    380443        }
    381444
    382445        /**
  • 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' ) 
    11731173 * @param array|string $args {
    11741174 *     Array or string of arguments for registering a post type.
    11751175 *
    1176  *     @type string      $label                 Name 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.
    11771177 *                                              Default is value of $labels['name'].
    1178  *     @type array       $labels                An array of labels for this post type. If not set, post
     1178 *     @type callable|array       $labels       An array of labels for this post type. If not set, post
    11791179 *                                              labels are inherited for non-hierarchical types and page
    11801180 *                                              labels for hierarchical ones. See get_post_type_labels() for a full
    11811181 *                                              list of supported labels.
    1182  *     @type string      $description           A short descriptive summary of what the post type is.
     1182 *     @type callable|string      $description  A short descriptive summary of what the post type is.
    11831183 *                                              Default empty.
    11841184 *     @type bool        $public                Whether a post type is intended for use publicly either via
    11851185 *                                              the admin interface or by front-end users. While the default
    function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) 
    12571257 *         @type bool   $feeds      Whether the feed permastruct should be built for this post type.
    12581258 *                                  Default is value of $has_archive.
    12591259 *         @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,
    12611261 *                                  inherits from $permalink_epmask. If not specified and permalink_epmask
    12621262 *                                  is not set, defaults to EP_PERMALINK.
    12631263 *     }
  • 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 ) { 
    342342 * @param array|string $args        {
    343343 *     Optional. Array or query string of arguments for registering a taxonomy.
    344344 *
    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
    346348 *                                                used for non-hierarchical taxonomies, and Category labels are used
    347349 *                                                for hierarchical taxonomies. See accepted values in
    348350 *                                                get_taxonomy_labels(). Default empty array.
    349  *     @type string        $description           A 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.
    350352 *     @type bool          $public                Whether a taxonomy is intended for use publicly either via
    351353 *                                                the admin interface or by front-end users. The default settings
    352354 *                                                of `$publicly_queryable`, `$show_ui`, and `$show_in_nav_menus`
    function unregister_taxonomy( $taxonomy ) { 
    495497 * @since 4.4.0 Added the `items_list_navigation` and `items_list` labels.
    496498 * @since 4.9.0 Added the `most_used` and `back_to_items` labels.
    497499 *
    498  * @param WP_Taxonomy $tax Taxonomy object.
     500 * @param object|WP_Taxonomy $tax Taxonomy object.
    499501 * @return object {
    500502 *     Taxonomy labels object. The first default value is for non-hierarchical taxonomies
    501503 *     (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
     
    22# This file is distributed under the same license as the 4.9.x package.
    33msgid ""
    44msgstr ""
    5 "PO-Revision-Date: 2018-08-13 19:19+0300\n"
     5"PO-Revision-Date: 2018-09-14 16:50+0900\n"
    66"MIME-Version: 1.0\n"
    77"Content-Type: text/plain; charset=UTF-8\n"
    88"Content-Transfer-Encoding: 8bit\n"
    99"Plural-Forms: nplurals=2; plural=n != 1;\n"
    10 "X-Generator: Poedit 2.1.1\n"
     10"X-Generator: Poedit 2.1\n"
    1111"Project-Id-Version: Development (4.9.x)\n"
    1212"Language: de_DE\n"
    1313"POT-Creation-Date: \n"
    msgstr "Jetzt %s aktualisieren" 
    4848#: wp-includes/user.php:3445
    4949msgid "[%1$s] Confirm Action: %2$s"
    5050msgstr "[%1$s] Aktion bestätigen: %2$s"
     51
     52#: wp-includes/post.php:1445
     53msgctxt "post type singular name"
     54msgid "Post"
     55msgstr "Beitrag"
     56
     57#: wp-includes/post.php:1445
     58msgctxt "post type singular name"
     59msgid "Page"
     60msgstr "Seite"
     61
     62#: wp-includes/post.php:1444
     63msgctxt "post type general name"
     64msgid "Pages"
     65msgstr "Seiten"
     66
     67#: wp-includes/post.php:1447
     68msgid "Add New Page"
     69msgstr "Neue Seite erstellen"
     70
     71#: wp-includes/post.php:1452
     72msgid "Search Posts"
     73msgstr "Beiträge durchsuchen"
     74
     75#: wp-includes/post.php:1448
     76msgid "Edit Page"
     77msgstr "Seite bearbeiten"
     78
     79#: wp-includes/post.php:1444
     80msgctxt "post type general name"
     81msgid "Posts"
     82msgstr "Beiträge"
     83
     84#: wp-includes/post.php:1455
     85msgid "Parent Page:"
     86msgstr "Übergeordnete Seite:"
     87
     88#: wp-includes/post.php:1447
     89msgid "Add New Post"
     90msgstr "Neuen Beitrag erstellen"
     91
     92#: wp-includes/post.php:1452
     93msgid "Search Pages"
     94msgstr "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 { 
    9696
    9797                unregister_post_type( 'foo' );
    9898
    99                 $this->assertObjectHasAttribute( 'labels', $post_type_object );
    100                 $this->assertObjectHasAttribute( 'label', $post_type_object );
     99                $this->assertInternalType( 'object', $post_type_object->labels );
     100                $this->assertInternalType( 'string', $post_type_object->label );
    101101                $this->assertObjectHasAttribute( 'not_found_in_trash', $post_type_object->labels );
     102                $this->assertObjectHasAttribute( 'parent_item_colon', $post_type_object->labels );
    102103        }
    103104
    104105        public function test_label_should_be_derived_from_labels_when_registering_a_post_type() {
    class Tests_Get_Post_Type_Labels extends WP_UnitTestCase { 
    131132        }
    132133
    133134        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 );
    136136
    137137                return $labels;
    138138        }
     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        }
    139276}