Allow $autoload in add_option() to receive false.
props dllh. fixes #31119. git-svn-id: https://develop.svn.wordpress.org/trunk@31278 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
4e3e98698f
commit
4857c6996c
@ -346,7 +346,8 @@ function update_option( $option, $value ) {
|
|||||||
* @param string $option Name of option to add. Expected to not be SQL-escaped.
|
* @param string $option Name of option to add. Expected to not be SQL-escaped.
|
||||||
* @param mixed $value Optional. Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
|
* @param mixed $value Optional. Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
|
||||||
* @param string $deprecated Optional. Description. Not used anymore.
|
* @param string $deprecated Optional. Description. Not used anymore.
|
||||||
* @param string|bool $autoload Optional. Default is enabled. Whether to load the option when WordPress starts up.
|
* @param string|bool $autoload Optional. Whether to load the option when WordPress starts up.
|
||||||
|
* Default is enabled. Accepts 'no' to disable for legacy reasons.
|
||||||
* @return bool False if option was not added and true if option was added.
|
* @return bool False if option was not added and true if option was added.
|
||||||
*/
|
*/
|
||||||
function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) {
|
function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) {
|
||||||
@ -373,7 +374,7 @@ function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' )
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
$serialized_value = maybe_serialize( $value );
|
$serialized_value = maybe_serialize( $value );
|
||||||
$autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
|
$autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fires before an option is added.
|
* Fires before an option is added.
|
||||||
|
@ -99,4 +99,30 @@ class Tests_Option_Option extends WP_UnitTestCase {
|
|||||||
function test_special_option_name_notoptions() {
|
function test_special_option_name_notoptions() {
|
||||||
delete_option( 'notoptions' );
|
delete_option( 'notoptions' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function data_option_autoloading() {
|
||||||
|
return array(
|
||||||
|
array( 'autoload_yes', 'yes', 'yes' ),
|
||||||
|
array( 'autoload_true', true, 'yes' ),
|
||||||
|
array( 'autoload_string', 'foo', 'yes' ),
|
||||||
|
array( 'autoload_int', 123456, 'yes' ),
|
||||||
|
array( 'autoload_array', array(), 'yes' ),
|
||||||
|
array( 'autoload_no', 'no', 'no' ),
|
||||||
|
array( 'autoload_false', false, 'no' ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Options should be autoloaded unless they were added with "no" or `false`.
|
||||||
|
*
|
||||||
|
* @ticket 31119
|
||||||
|
* @dataProvider data_option_autoloading
|
||||||
|
*/
|
||||||
|
function test_option_autoloading( $name, $autoload_value, $expected ) {
|
||||||
|
global $wpdb;
|
||||||
|
$added = add_option( $name, 'Autoload test', '', $autoload_value );
|
||||||
|
$this->assertTrue( $added );
|
||||||
|
|
||||||
|
$actual = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s LIMIT 1", $name ) );
|
||||||
|
$this->assertEquals( $expected, $actual->autoload );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user