Make WordPress Core

Ticket #34596: 34596.patch

File 34596.patch, 6.0 KB (added by jubstuff, 9 years ago)
  • src/wp-includes/class-wp-customize-manager.php

     
    980980         * @param WP_Customize_Setting|string $id Customize Setting object, or ID.
    981981         * @param array $args                     Setting arguments; passed to WP_Customize_Setting
    982982         *                                        constructor.
     983         * @return WP_Customize_Setting
    983984         */
    984985        public function add_setting( $id, $args = array() ) {
    985986                if ( $id instanceof WP_Customize_Setting ) {
     
    987988                } else {
    988989                        $setting = new WP_Customize_Setting( $this, $id, $args );
    989990                }
    990                 $this->settings[ $setting->id ] = $setting;
     991
     992                return $this->settings[ $setting->id ] = $setting;
    991993        }
    992994
    993995        /**
     
    10841086         *
    10851087         * @param WP_Customize_Panel|string $id   Customize Panel object, or Panel ID.
    10861088         * @param array                     $args Optional. Panel arguments. Default empty array.
     1089         *
     1090         * @return WP_Customize_Panel
    10871091         */
    10881092        public function add_panel( $id, $args = array() ) {
    10891093                if ( $id instanceof WP_Customize_Panel ) {
     
    10921096                        $panel = new WP_Customize_Panel( $this, $id, $args );
    10931097                }
    10941098
    1095                 $this->panels[ $panel->id ] = $panel;
     1099                return $this->panels[ $panel->id ] = $panel;
    10961100        }
    10971101
    10981102        /**
     
    11581162         *
    11591163         * @param WP_Customize_Section|string $id   Customize Section object, or Section ID.
    11601164         * @param array                       $args Section arguments.
     1165         *
     1166         * @return WP_Customize_Section
    11611167         */
    11621168        public function add_section( $id, $args = array() ) {
    11631169                if ( $id instanceof WP_Customize_Section ) {
     
    11651171                } else {
    11661172                        $section = new WP_Customize_Section( $this, $id, $args );
    11671173                }
    1168                 $this->sections[ $section->id ] = $section;
     1174
     1175                return $this->sections[ $section->id ] = $section;
    11691176        }
    11701177
    11711178        /**
     
    12291236         * @param WP_Customize_Control|string $id   Customize Control object, or ID.
    12301237         * @param array                       $args Control arguments; passed to WP_Customize_Control
    12311238         *                                          constructor.
     1239         * @return WP_Customize_Control
    12321240         */
    12331241        public function add_control( $id, $args = array() ) {
    12341242                if ( $id instanceof WP_Customize_Control ) {
     
    12361244                } else {
    12371245                        $control = new WP_Customize_Control( $this, $id, $args );
    12381246                }
    1239                 $this->controls[ $control->id ] = $control;
     1247
     1248                return $this->controls[ $control->id ] = $control;
    12401249        }
    12411250
    12421251        /**
  • tests/phpunit/tests/customize/manager.php

     
    431431                $sorted_control_ids = wp_list_pluck( $manager->get_section( $section_id )->controls, 'id' );
    432432                $this->assertEquals( $added_control_ids, $sorted_control_ids );
    433433        }
     434
     435        /**
     436         * @ticket 34596
     437         */
     438        function test_add_section_return_instance() {
     439                $manager    = new WP_Customize_Manager();
     440                $section_id = 'foo-section';
     441                wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     442
     443                $result_section = $manager->add_section( $section_id, array(
     444                        'title'    => 'Section',
     445                        'priority' => 1,
     446                ) );
     447
     448                $this->assertInstanceOf( 'WP_Customize_Section', $result_section );
     449
     450                $section        = new WP_Customize_Section( $manager, $section_id, array(
     451                        'title'    => 'Section 2',
     452                        'priority' => 2
     453                ) );
     454                $result_section = $manager->add_section( $section );
     455
     456                $this->assertInstanceOf( 'WP_Customize_Section', $result_section );
     457                $this->assertEquals( $section, $result_section );
     458        }
     459
     460        /**
     461         * @ticket 34596
     462         */
     463        function test_add_setting_return_instance() {
     464                $manager = new WP_Customize_Manager();
     465                wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     466
     467                $result_setting = $manager->add_setting( 'return-instance-test' );
     468
     469                $this->assertInstanceOf( 'WP_Customize_Setting', $result_setting );
     470
     471                $setting        = new WP_Customize_Setting( $manager, 'return-instance-test-2' );
     472                $result_setting = $manager->add_setting( $setting );
     473
     474                $this->assertInstanceOf( 'WP_Customize_Setting', $result_setting );
     475                $this->assertEquals( $setting, $result_setting );
     476        }
     477
     478        /**
     479         * @ticket 34596
     480         */
     481        function test_add_panel_return_instance() {
     482                $manager = new WP_Customize_Manager();
     483                wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     484
     485                $result_panel = $manager->add_panel( 'return-instance-test', array(
     486                        'title'    => 'Test Panel',
     487                        'priority' => 2
     488                ) );
     489
     490                $this->assertInstanceOf( 'WP_Customize_Panel', $result_panel );
     491
     492                $panel = new WP_Customize_Panel( $manager, 'return-instance-test-2', array(
     493                        'title' => 'Test Panel 2',
     494                ) );
     495
     496                $result_panel = $manager->add_panel( $panel );
     497                $this->assertInstanceOf( 'WP_Customize_Panel', $result_panel );
     498                $this->assertEquals( $panel, $result_panel );
     499        }
     500
     501        /**
     502         * @ticket 34596
     503         */
     504        function test_add_control_return_instance() {
     505                $manager    = new WP_Customize_Manager();
     506                $section_id = 'foo-section';
     507                wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     508                $manager->add_section( $section_id, array(
     509                        'title'    => 'Section',
     510                        'priority' => 1,
     511                ) );
     512                $id = 'return-instance-test';
     513                $manager->add_setting( $id );
     514                $control        = new WP_Customize_Control( $manager, $id, array(
     515                        'section'  => $section_id,
     516                        'priority' => 1,
     517                        'setting'  => $id,
     518                ) );
     519                $result_control = $manager->add_control( $control );
     520
     521                $this->assertInstanceOf( 'WP_Customize_Control', $result_control );
     522                $this->assertEquals( $control, $result_control );
     523
     524                $result_control = $manager->add_control( 'return-instance-test2', array(
     525                        'section'  => $section_id,
     526                        'priority' => 1,
     527                        'setting'  => $id,
     528                ) );
     529                $this->assertInstanceOf( 'WP_Customize_Control', $result_control );
     530        }
    434531}