Make WordPress Core

Ticket #45035: 45035.diff

File 45035.diff, 4.4 KB (added by gwelser, 6 years ago)

Updated patch with unit tests

  • src/wp-admin/includes/dashboard.php

    diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php
    index d45f1e2477..ed10e49354 100644
    a b function wp_dashboard_right_now() { 
    264264        <div class="main">
    265265        <ul>
    266266        <?php
    267         // Posts and Pages
    268         foreach ( array( 'post', 'page' ) as $post_type ) {
     267        // At a Glance Post Types
     268        foreach ( get_post_types( array( 'at_a_glance' => true ) ) as $post_type ) {
    269269                $num_posts = wp_count_posts( $post_type );
    270270                if ( $num_posts && $num_posts->publish ) {
    271                         if ( 'post' == $post_type ) {
    272                                 $text = _n( '%s Post', '%s Posts', $num_posts->publish );
    273                         } else {
    274                                 $text = _n( '%s Page', '%s Pages', $num_posts->publish );
    275                         }
    276                         $text             = sprintf( $text, number_format_i18n( $num_posts->publish ) );
    277271                        $post_type_object = get_post_type_object( $post_type );
     272                        if ( ! $post_type_object ) {
     273                                continue;
     274                        }
     275                        $post_label = 1 === intval( $num_posts->publish ) ? $post_type_object->labels->singular_name : $post_type_object->labels->name;
     276                        $text       = sprintf( '%s %s', number_format_i18n( $num_posts->publish ), $post_label );
    278277                        if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
    279278                                printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text );
    280279                        } else {
  • src/wp-includes/class-wp-post-type.php

    diff --git a/src/wp-includes/class-wp-post-type.php b/src/wp-includes/class-wp-post-type.php
    index f2e14a0a93..e5b4f535ed 100644
    a b final class WP_Post_Type { 
    127127         */
    128128        public $show_in_menu = null;
    129129
     130        /**
     131         * Makes this post type visible in the At a Glance dashboard widget.
     132         *
     133         * Default is the value of $show_in_menu.
     134         *
     135         * @var bool $at_a_glance
     136         */
     137        public $at_a_glance = null;
     138
    130139        /**
    131140         * Makes this post type available for selection in navigation menus.
    132141         *
    final class WP_Post_Type { 
    405414                        'show_in_rest'          => false,
    406415                        'rest_base'             => false,
    407416                        'rest_controller_class' => false,
     417                        'at_a_glance'           => null,
    408418                        '_builtin'              => false,
    409419                        '_edit_link'            => 'post.php?post=%d',
    410420                );
    final class WP_Post_Type { 
    428438                        $args['show_in_menu'] = $args['show_ui'];
    429439                }
    430440
     441                // If not set, default to the setting for show_in_menu
     442                if ( null === $args['at_a_glance'] ) {
     443                        $args['at_a_glance'] = (bool) $args['show_in_menu'];
     444                }
     445
    431446                // If not set, default to the whether the full UI is shown.
    432447                if ( null === $args['show_in_admin_bar'] ) {
    433448                        $args['show_in_admin_bar'] = (bool) $args['show_in_menu'];
  • src/wp-includes/post.php

    diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
    index 7636c3d02b..b76f2757c5 100644
    a b function create_initial_post_types() { 
    7878                        ),
    7979                        'public'                => true,
    8080                        'show_ui'               => true,
     81                        'at_a_glance'           => false,
    8182                        '_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
    8283                        '_edit_link'            => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
    8384                        'capability_type'       => 'post',
  • tests/phpunit/tests/post/types.php

    diff --git a/tests/phpunit/tests/post/types.php b/tests/phpunit/tests/post/types.php
    index cdab0337f3..56ef194498 100644
    a b class Tests_Post_Types extends WP_UnitTestCase { 
    156156                $this->assertSame( $public, $args->show_in_admin_bar );
    157157        }
    158158
     159        /**
     160         * @ticket 45035
     161         * @covers ::register_post_type()
     162         */
     163        function test_register_post_type_at_a_glance_should_default_to_value_of_show_in_menu() {
     164                /*
     165                 * 'public'       Default is false
     166                 * 'show_ui'      Default is null ('public')
     167                 * 'show_in_menu' Default is null ('show_ui' > 'public')
     168                 * 'at_a_glance'  Default is null ('show_in_menu' > 'show_ui' > 'public')
     169                 */
     170                $args = $this->register_post_type( array( 'public' => $public = false ) );
     171
     172                // Should fall back to 'show_in_menu'.
     173                $this->assertSame( $args->show_in_menu, $args->at_a_glance );
     174
     175                // Should fall back to 'show_ui'.
     176                $this->assertSame( $args->show_ui, $args->at_a_glance );
     177
     178                // Should fall back to 'public'.
     179                $this->assertSame( $public, $args->at_a_glance );
     180        }
     181
    159182        function test_register_taxonomy_for_object_type() {
    160183                global $wp_taxonomies;
    161184