Make WordPress Core

Changeset 31278


Ignore:
Timestamp:
01/25/2015 07:50:31 AM (12 years ago)
Author:
nacin
Message:

Allow $autoload in add_option() to receive false.

props dllh.
fixes #31119.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/option.php

    r30886 r31278  
    347347 * @param mixed          $value       Optional. Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
    348348 * @param string         $deprecated  Optional. Description. Not used anymore.
    349  * @param string|bool    $autoload    Optional. Default is enabled. Whether to load the option when WordPress starts up.
     349 * @param string|bool    $autoload    Optional. Whether to load the option when WordPress starts up.
     350 *                                    Default is enabled. Accepts 'no' to disable for legacy reasons.
    350351 * @return bool False if option was not added and true if option was added.
    351352 */
     
    374375
    375376        $serialized_value = maybe_serialize( $value );
    376         $autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
     377        $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
    377378
    378379        /**
  • trunk/tests/phpunit/tests/option/option.php

    r25002 r31278  
    100100                delete_option( 'notoptions' );
    101101        }
     102
     103        function data_option_autoloading() {
     104                return array(
     105                        array( 'autoload_yes',    'yes',   'yes' ),
     106                        array( 'autoload_true',   true,    'yes' ),
     107                        array( 'autoload_string', 'foo',   'yes' ),
     108                        array( 'autoload_int',    123456,  'yes' ),
     109                        array( 'autoload_array',  array(), 'yes' ),
     110                        array( 'autoload_no',     'no',    'no'  ),
     111                        array( 'autoload_false',  false,   'no'  ),
     112                );
     113        }
     114        /**
     115         * Options should be autoloaded unless they were added with "no" or `false`.
     116         *
     117         * @ticket 31119
     118         * @dataProvider data_option_autoloading
     119         */
     120        function test_option_autoloading( $name, $autoload_value, $expected ) {
     121                global $wpdb;
     122                $added = add_option( $name, 'Autoload test', '', $autoload_value );
     123                $this->assertTrue( $added );
     124
     125                $actual = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s LIMIT 1", $name ) );
     126                $this->assertEquals( $expected, $actual->autoload );
     127        }
    102128}
Note: See TracChangeset for help on using the changeset viewer.