Make WordPress Core

Ticket #40413: ticket-40413.2.patch

File ticket-40413.2.patch, 2.0 KB (added by seuser, 8 years ago)
  • 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 ba37a02..558bddd 100644
    a b final class WP_Post_Type { 
    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 $support => $features ) {
     517                                if ( is_array( $features ) ) {
     518                                        add_post_type_support( $this->name, $support, $features );
     519                                } else {
     520                                        add_post_type_support( $this->name, $features );
     521                                }
     522                        }
    517523                        unset( $this->supports );
    518524                } elseif ( false !== $this->supports ) {
    519525                        // Add default features.
  • tests/phpunit/tests/post/wpPostType.php

    diff --git a/tests/phpunit/tests/post/wpPostType.php b/tests/phpunit/tests/post/wpPostType.php
    index a9d046e..c9ca3c2 100644
    a b class Tests_WP_Post_Type extends WP_UnitTestCase { 
    5050                $this->assertEqualSets( array(), $post_type_supports_after );
    5151        }
    5252
     53        /**
     54         * Test that supports can optionally receive nested args.
     55         */
     56        public function test_add_supports_custom_with_args() {
     57                $post_type        = 'cpt';
     58                $post_type_object = new WP_Post_Type( $post_type, array(
     59                        'supports' => array(
     60                                'support_with_args' => array(
     61                                        'arg1',
     62                                        'arg2',
     63                                ),
     64                                'support_without_args',
     65                        ),
     66                ) );
     67
     68                $post_type_object->add_supports();
     69                $post_type_supports = get_all_post_type_supports( $post_type );
     70
     71                $post_type_object->remove_supports();
     72                $post_type_supports_after = get_all_post_type_supports( $post_type );
     73
     74                $this->assertEqualSets( array(
     75                        'support_with_args' => array(
     76                                array(
     77                                        'arg1',
     78                                        'arg2',
     79                                ),
     80                        ),
     81                        'support_without_args'  => true,
     82                ), $post_type_supports );
     83                $this->assertEqualSets( array(), $post_type_supports_after );
     84        }
     85
    5386        public function test_does_not_add_query_var_if_not_public() {
    5487                $this->set_permalink_structure( '/%postname%' );
    5588