Make WordPress Core


Ignore:
Timestamp:
10/20/2015 09:18:04 PM (11 years ago)
Author:
westonruter
Message:

Customizer: Allow new option settings to not be saved as autoloaded by passing an autoload arg value of false.

The autoload argument value is passed along to update_option() which has accepted an $autoload parameter since [31628].

Props westonruter, dlh.
See #26394.
Fixes #33499.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/setting.php

    r35242 r35305  
    473473                restore_current_blog();
    474474        }
     475
     476        /**
     477         * @ticket 33499
     478         */
     479        function test_option_autoloading() {
     480                global $wpdb;
     481                wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     482
     483                $name = 'autoloaded1';
     484                $setting = new WP_Customize_Setting( $this->manager, $name, array(
     485                        'type' => 'option',
     486                ) );
     487                $value = 'value1';
     488                $this->manager->set_post_value( $setting->id, $value );
     489                $setting->save();
     490                $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $setting->id ) );
     491                $this->assertEquals( 'yes', $autoload );
     492                $this->assertEquals( $value, get_option( $name ) );
     493
     494                $name = 'autoloaded2';
     495                $setting = new WP_Customize_Setting( $this->manager, $name, array(
     496                        'type' => 'option',
     497                        'autoload' => true,
     498                ) );
     499                $value = 'value2';
     500                $this->manager->set_post_value( $setting->id, $value );
     501                $setting->save();
     502                $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $setting->id ) );
     503                $this->assertEquals( 'yes', $autoload );
     504                $this->assertEquals( $value, get_option( $name ) );
     505
     506                $name = 'not-autoloaded1';
     507                $setting = new WP_Customize_Setting( $this->manager, $name, array(
     508                        'type' => 'option',
     509                        'autoload' => false,
     510                ) );
     511                $value = 'value3';
     512                $this->manager->set_post_value( $setting->id, $value );
     513                $setting->save();
     514                $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $setting->id ) );
     515                $this->assertEquals( 'no', $autoload );
     516                $this->assertEquals( $value, get_option( $name ) );
     517
     518                $id_base = 'multi-not-autoloaded';
     519                $setting1 = new WP_Customize_Setting( $this->manager, $id_base . '[foo]', array(
     520                        'type' => 'option',
     521                ) );
     522                $setting2 = new WP_Customize_Setting( $this->manager, $id_base . '[bar]', array(
     523                        'type' => 'option',
     524                        'autoload' => false,
     525                ) );
     526                $this->manager->set_post_value( $setting1->id, 'value1' );
     527                $this->manager->set_post_value( $setting2->id, 'value2' );
     528                $setting1->save();
     529                $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $id_base ) );
     530                $this->assertEquals( 'no', $autoload, 'Even though setting1 did not indicate autoload (thus normally true), since another multidimensional option setting of the base did say autoload=false, it should be autoload=no' );
     531        }
    475532}
    476533
Note: See TracChangeset for help on using the changeset viewer.