Make WordPress Core

Ticket #40413: 40413.diff

File 40413.diff, 2.0 KB (added by desrosj, 6 years ago)
  • src/wp-includes/class-wp-post-type.php

     
    513513         */
    514514        public function add_supports() {
    515515                if ( ! empty( $this->supports ) ) {
    516                         add_post_type_support( $this->name, $this->supports );
     516                        foreach ( $this->supports as $feature => $args ) {
     517                                if ( is_array( $args ) ) {
     518                                        add_post_type_support( $this->name, $feature, $args );
     519                                } else {
     520                                        add_post_type_support( $this->name, $args );
     521                                }
     522                        }
    517523                        unset( $this->supports );
    518524                } elseif ( false !== $this->supports ) {
    519525                        // Add default features.
  • tests/phpunit/tests/post/wpPostType.php

     
    6262                $this->assertEqualSets( array(), $post_type_supports_after );
    6363        }
    6464
     65        /**
     66         * Test that supports can optionally receive nested args.
     67         *
     68         * @ticket 40413
     69         */
     70        public function test_add_supports_custom_with_args() {
     71                $post_type        = 'cpt';
     72                $post_type_object = new WP_Post_Type(
     73                        $post_type,
     74                        array(
     75                                'supports' => array(
     76                                        'support_with_args' => array(
     77                                                'arg1',
     78                                                'arg2',
     79                                        ),
     80                                        'support_without_args',
     81                                ),
     82                        )
     83                );
     84
     85                $post_type_object->add_supports();
     86                $post_type_supports = get_all_post_type_supports( $post_type );
     87
     88                $post_type_object->remove_supports();
     89                $post_type_supports_after = get_all_post_type_supports( $post_type );
     90
     91                $this->assertEqualSets(
     92                        array(
     93                                'support_with_args'    => array(
     94                                        array(
     95                                                'arg1',
     96                                                'arg2',
     97                                        ),
     98                                ),
     99                                'support_without_args' => true,
     100                        ),
     101                        $post_type_supports
     102                );
     103                $this->assertEqualSets( array(), $post_type_supports_after );
     104        }
     105
    65106        public function test_does_not_add_query_var_if_not_public() {
    66107                $this->set_permalink_structure( '/%postname%' );
    67108