Edit File by line
/home/zeestwma/ceyloniy.../wp-inclu...
File: option.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Option API
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Option
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Retrieves an option value based on an option name.
[9] Fix | Delete
*
[10] Fix | Delete
* If the option does not exist, and a default value is not provided,
[11] Fix | Delete
* boolean false is returned. This could be used to check whether you need
[12] Fix | Delete
* to initialize an option during installation of a plugin, however that
[13] Fix | Delete
* can be done better by using add_option() which will not overwrite
[14] Fix | Delete
* existing options.
[15] Fix | Delete
*
[16] Fix | Delete
* Not initializing an option and using boolean `false` as a return value
[17] Fix | Delete
* is a bad practice as it triggers an additional database query.
[18] Fix | Delete
*
[19] Fix | Delete
* The type of the returned value can be different from the type that was passed
[20] Fix | Delete
* when saving or updating the option. If the option value was serialized,
[21] Fix | Delete
* then it will be unserialized when it is returned. In this case the type will
[22] Fix | Delete
* be the same. For example, storing a non-scalar value like an array will
[23] Fix | Delete
* return the same array.
[24] Fix | Delete
*
[25] Fix | Delete
* In most cases non-string scalar and null values will be converted and returned
[26] Fix | Delete
* as string equivalents.
[27] Fix | Delete
*
[28] Fix | Delete
* Exceptions:
[29] Fix | Delete
*
[30] Fix | Delete
* 1. When the option has not been saved in the database, the `$default_value` value
[31] Fix | Delete
* is returned if provided. If not, boolean `false` is returned.
[32] Fix | Delete
* 2. When one of the Options API filters is used: {@see 'pre_option_$option'},
[33] Fix | Delete
* {@see 'default_option_$option'}, or {@see 'option_$option'}, the returned
[34] Fix | Delete
* value may not match the expected type.
[35] Fix | Delete
* 3. When the option has just been saved in the database, and get_option()
[36] Fix | Delete
* is used right after, non-string scalar and null values are not converted to
[37] Fix | Delete
* string equivalents and the original type is returned.
[38] Fix | Delete
*
[39] Fix | Delete
* Examples:
[40] Fix | Delete
*
[41] Fix | Delete
* When adding options like this: `add_option( 'my_option_name', 'value' )`
[42] Fix | Delete
* and then retrieving them with `get_option( 'my_option_name' )`, the returned
[43] Fix | Delete
* values will be:
[44] Fix | Delete
*
[45] Fix | Delete
* - `false` returns `string(0) ""`
[46] Fix | Delete
* - `true` returns `string(1) "1"`
[47] Fix | Delete
* - `0` returns `string(1) "0"`
[48] Fix | Delete
* - `1` returns `string(1) "1"`
[49] Fix | Delete
* - `'0'` returns `string(1) "0"`
[50] Fix | Delete
* - `'1'` returns `string(1) "1"`
[51] Fix | Delete
* - `null` returns `string(0) ""`
[52] Fix | Delete
*
[53] Fix | Delete
* When adding options with non-scalar values like
[54] Fix | Delete
* `add_option( 'my_array', array( false, 'str', null ) )`, the returned value
[55] Fix | Delete
* will be identical to the original as it is serialized before saving
[56] Fix | Delete
* it in the database:
[57] Fix | Delete
*
[58] Fix | Delete
* array(3) {
[59] Fix | Delete
* [0] => bool(false)
[60] Fix | Delete
* [1] => string(3) "str"
[61] Fix | Delete
* [2] => NULL
[62] Fix | Delete
* }
[63] Fix | Delete
*
[64] Fix | Delete
* @since 1.5.0
[65] Fix | Delete
*
[66] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[67] Fix | Delete
*
[68] Fix | Delete
* @param string $option Name of the option to retrieve. Expected to not be SQL-escaped.
[69] Fix | Delete
* @param mixed $default_value Optional. Default value to return if the option does not exist.
[70] Fix | Delete
* @return mixed Value of the option. A value of any type may be returned, including
[71] Fix | Delete
* scalar (string, boolean, float, integer), null, array, object.
[72] Fix | Delete
* Scalar and null values will be returned as strings as long as they originate
[73] Fix | Delete
* from a database stored option value. If there is no option in the database,
[74] Fix | Delete
* boolean `false` is returned.
[75] Fix | Delete
*/
[76] Fix | Delete
function get_option( $option, $default_value = false ) {
[77] Fix | Delete
global $wpdb;
[78] Fix | Delete
[79] Fix | Delete
if ( is_scalar( $option ) ) {
[80] Fix | Delete
$option = trim( $option );
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
if ( empty( $option ) ) {
[84] Fix | Delete
return false;
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
/*
[88] Fix | Delete
* Until a proper _deprecated_option() function can be introduced,
[89] Fix | Delete
* redirect requests to deprecated keys to the new, correct ones.
[90] Fix | Delete
*/
[91] Fix | Delete
$deprecated_keys = array(
[92] Fix | Delete
'blacklist_keys' => 'disallowed_keys',
[93] Fix | Delete
'comment_whitelist' => 'comment_previously_approved',
[94] Fix | Delete
);
[95] Fix | Delete
[96] Fix | Delete
if ( isset( $deprecated_keys[ $option ] ) && ! wp_installing() ) {
[97] Fix | Delete
_deprecated_argument(
[98] Fix | Delete
__FUNCTION__,
[99] Fix | Delete
'5.5.0',
[100] Fix | Delete
sprintf(
[101] Fix | Delete
/* translators: 1: Deprecated option key, 2: New option key. */
[102] Fix | Delete
__( 'The "%1$s" option key has been renamed to "%2$s".' ),
[103] Fix | Delete
$option,
[104] Fix | Delete
$deprecated_keys[ $option ]
[105] Fix | Delete
)
[106] Fix | Delete
);
[107] Fix | Delete
return get_option( $deprecated_keys[ $option ], $default_value );
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
/**
[111] Fix | Delete
* Filters the value of an existing option before it is retrieved.
[112] Fix | Delete
*
[113] Fix | Delete
* The dynamic portion of the hook name, `$option`, refers to the option name.
[114] Fix | Delete
*
[115] Fix | Delete
* Returning a value other than false from the filter will short-circuit retrieval
[116] Fix | Delete
* and return that value instead.
[117] Fix | Delete
*
[118] Fix | Delete
* @since 1.5.0
[119] Fix | Delete
* @since 4.4.0 The `$option` parameter was added.
[120] Fix | Delete
* @since 4.9.0 The `$default_value` parameter was added.
[121] Fix | Delete
*
[122] Fix | Delete
* @param mixed $pre_option The value to return instead of the option value. This differs from
[123] Fix | Delete
* `$default_value`, which is used as the fallback value in the event
[124] Fix | Delete
* the option doesn't exist elsewhere in get_option().
[125] Fix | Delete
* Default false (to skip past the short-circuit).
[126] Fix | Delete
* @param string $option Option name.
[127] Fix | Delete
* @param mixed $default_value The fallback value to return if the option does not exist.
[128] Fix | Delete
* Default false.
[129] Fix | Delete
*/
[130] Fix | Delete
$pre = apply_filters( "pre_option_{$option}", false, $option, $default_value );
[131] Fix | Delete
[132] Fix | Delete
/**
[133] Fix | Delete
* Filters the value of any existing option before it is retrieved.
[134] Fix | Delete
*
[135] Fix | Delete
* Returning a value other than false from the filter will short-circuit retrieval
[136] Fix | Delete
* and return that value instead.
[137] Fix | Delete
*
[138] Fix | Delete
* @since 6.1.0
[139] Fix | Delete
*
[140] Fix | Delete
* @param mixed $pre_option The value to return instead of the option value. This differs from
[141] Fix | Delete
* `$default_value`, which is used as the fallback value in the event
[142] Fix | Delete
* the option doesn't exist elsewhere in get_option().
[143] Fix | Delete
* Default false (to skip past the short-circuit).
[144] Fix | Delete
* @param string $option Name of the option.
[145] Fix | Delete
* @param mixed $default_value The fallback value to return if the option does not exist.
[146] Fix | Delete
* Default false.
[147] Fix | Delete
*/
[148] Fix | Delete
$pre = apply_filters( 'pre_option', $pre, $option, $default_value );
[149] Fix | Delete
[150] Fix | Delete
if ( false !== $pre ) {
[151] Fix | Delete
return $pre;
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
if ( defined( 'WP_SETUP_CONFIG' ) ) {
[155] Fix | Delete
return false;
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
// Distinguish between `false` as a default, and not passing one.
[159] Fix | Delete
$passed_default = func_num_args() > 1;
[160] Fix | Delete
[161] Fix | Delete
if ( ! wp_installing() ) {
[162] Fix | Delete
$alloptions = wp_load_alloptions();
[163] Fix | Delete
/*
[164] Fix | Delete
* When getting an option value, we check in the following order for performance:
[165] Fix | Delete
*
[166] Fix | Delete
* 1. Check the 'alloptions' cache first to prioritize existing loaded options.
[167] Fix | Delete
* 2. Check the 'notoptions' cache before a cache lookup or DB hit.
[168] Fix | Delete
* 3. Check the 'options' cache prior to a DB hit.
[169] Fix | Delete
* 4. Check the DB for the option and cache it in either the 'options' or 'notoptions' cache.
[170] Fix | Delete
*/
[171] Fix | Delete
if ( isset( $alloptions[ $option ] ) ) {
[172] Fix | Delete
$value = $alloptions[ $option ];
[173] Fix | Delete
} else {
[174] Fix | Delete
// Check for non-existent options first to avoid unnecessary object cache lookups and DB hits.
[175] Fix | Delete
$notoptions = wp_cache_get( 'notoptions', 'options' );
[176] Fix | Delete
[177] Fix | Delete
if ( ! is_array( $notoptions ) ) {
[178] Fix | Delete
$notoptions = array();
[179] Fix | Delete
wp_cache_set( 'notoptions', $notoptions, 'options' );
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
if ( isset( $notoptions[ $option ] ) ) {
[183] Fix | Delete
/**
[184] Fix | Delete
* Filters the default value for an option.
[185] Fix | Delete
*
[186] Fix | Delete
* The dynamic portion of the hook name, `$option`, refers to the option name.
[187] Fix | Delete
*
[188] Fix | Delete
* @since 3.4.0
[189] Fix | Delete
* @since 4.4.0 The `$option` parameter was added.
[190] Fix | Delete
* @since 4.7.0 The `$passed_default` parameter was added to distinguish between a `false` value and the default parameter value.
[191] Fix | Delete
*
[192] Fix | Delete
* @param mixed $default_value The default value to return if the option does not exist
[193] Fix | Delete
* in the database.
[194] Fix | Delete
* @param string $option Option name.
[195] Fix | Delete
* @param bool $passed_default Was `get_option()` passed a default value?
[196] Fix | Delete
*/
[197] Fix | Delete
return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default );
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
$value = wp_cache_get( $option, 'options' );
[201] Fix | Delete
[202] Fix | Delete
if ( false === $value ) {
[203] Fix | Delete
[204] Fix | Delete
$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
[205] Fix | Delete
[206] Fix | Delete
// Has to be get_row() instead of get_var() because of funkiness with 0, false, null values.
[207] Fix | Delete
if ( is_object( $row ) ) {
[208] Fix | Delete
$value = $row->option_value;
[209] Fix | Delete
wp_cache_add( $option, $value, 'options' );
[210] Fix | Delete
} else { // Option does not exist, so we must cache its non-existence.
[211] Fix | Delete
$notoptions[ $option ] = true;
[212] Fix | Delete
wp_cache_set( 'notoptions', $notoptions, 'options' );
[213] Fix | Delete
[214] Fix | Delete
/** This filter is documented in wp-includes/option.php */
[215] Fix | Delete
return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default );
[216] Fix | Delete
}
[217] Fix | Delete
}
[218] Fix | Delete
}
[219] Fix | Delete
} else {
[220] Fix | Delete
$suppress = $wpdb->suppress_errors();
[221] Fix | Delete
$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
[222] Fix | Delete
$wpdb->suppress_errors( $suppress );
[223] Fix | Delete
[224] Fix | Delete
if ( is_object( $row ) ) {
[225] Fix | Delete
$value = $row->option_value;
[226] Fix | Delete
} else {
[227] Fix | Delete
/** This filter is documented in wp-includes/option.php */
[228] Fix | Delete
return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default );
[229] Fix | Delete
}
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
// If home is not set, use siteurl.
[233] Fix | Delete
if ( 'home' === $option && '' === $value ) {
[234] Fix | Delete
return get_option( 'siteurl' );
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
if ( in_array( $option, array( 'siteurl', 'home', 'category_base', 'tag_base' ), true ) ) {
[238] Fix | Delete
$value = untrailingslashit( $value );
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
/**
[242] Fix | Delete
* Filters the value of an existing option.
[243] Fix | Delete
*
[244] Fix | Delete
* The dynamic portion of the hook name, `$option`, refers to the option name.
[245] Fix | Delete
*
[246] Fix | Delete
* @since 1.5.0 As 'option_' . $setting
[247] Fix | Delete
* @since 3.0.0
[248] Fix | Delete
* @since 4.4.0 The `$option` parameter was added.
[249] Fix | Delete
*
[250] Fix | Delete
* @param mixed $value Value of the option. If stored serialized, it will be
[251] Fix | Delete
* unserialized prior to being returned.
[252] Fix | Delete
* @param string $option Option name.
[253] Fix | Delete
*/
[254] Fix | Delete
return apply_filters( "option_{$option}", maybe_unserialize( $value ), $option );
[255] Fix | Delete
}
[256] Fix | Delete
[257] Fix | Delete
/**
[258] Fix | Delete
* Primes specific options into the cache with a single database query.
[259] Fix | Delete
*
[260] Fix | Delete
* Only options that do not already exist in cache will be loaded.
[261] Fix | Delete
*
[262] Fix | Delete
* @since 6.4.0
[263] Fix | Delete
*
[264] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[265] Fix | Delete
*
[266] Fix | Delete
* @param string[] $options An array of option names to be loaded.
[267] Fix | Delete
*/
[268] Fix | Delete
function wp_prime_option_caches( $options ) {
[269] Fix | Delete
global $wpdb;
[270] Fix | Delete
[271] Fix | Delete
$alloptions = wp_load_alloptions();
[272] Fix | Delete
$cached_options = wp_cache_get_multiple( $options, 'options' );
[273] Fix | Delete
$notoptions = wp_cache_get( 'notoptions', 'options' );
[274] Fix | Delete
if ( ! is_array( $notoptions ) ) {
[275] Fix | Delete
$notoptions = array();
[276] Fix | Delete
}
[277] Fix | Delete
[278] Fix | Delete
// Filter options that are not in the cache.
[279] Fix | Delete
$options_to_prime = array();
[280] Fix | Delete
foreach ( $options as $option ) {
[281] Fix | Delete
if (
[282] Fix | Delete
( ! isset( $cached_options[ $option ] ) || false === $cached_options[ $option ] )
[283] Fix | Delete
&& ! isset( $alloptions[ $option ] )
[284] Fix | Delete
&& ! isset( $notoptions[ $option ] )
[285] Fix | Delete
) {
[286] Fix | Delete
$options_to_prime[] = $option;
[287] Fix | Delete
}
[288] Fix | Delete
}
[289] Fix | Delete
[290] Fix | Delete
// Bail early if there are no options to be loaded.
[291] Fix | Delete
if ( empty( $options_to_prime ) ) {
[292] Fix | Delete
return;
[293] Fix | Delete
}
[294] Fix | Delete
[295] Fix | Delete
$results = $wpdb->get_results(
[296] Fix | Delete
$wpdb->prepare(
[297] Fix | Delete
sprintf(
[298] Fix | Delete
"SELECT option_name, option_value FROM $wpdb->options WHERE option_name IN (%s)",
[299] Fix | Delete
implode( ',', array_fill( 0, count( $options_to_prime ), '%s' ) )
[300] Fix | Delete
),
[301] Fix | Delete
$options_to_prime
[302] Fix | Delete
)
[303] Fix | Delete
);
[304] Fix | Delete
[305] Fix | Delete
$options_found = array();
[306] Fix | Delete
foreach ( $results as $result ) {
[307] Fix | Delete
/*
[308] Fix | Delete
* The cache is primed with the raw value (i.e. not maybe_unserialized).
[309] Fix | Delete
*
[310] Fix | Delete
* `get_option()` will handle unserializing the value as needed.
[311] Fix | Delete
*/
[312] Fix | Delete
$options_found[ $result->option_name ] = $result->option_value;
[313] Fix | Delete
}
[314] Fix | Delete
wp_cache_set_multiple( $options_found, 'options' );
[315] Fix | Delete
[316] Fix | Delete
// If all options were found, no need to update `notoptions` cache.
[317] Fix | Delete
if ( count( $options_found ) === count( $options_to_prime ) ) {
[318] Fix | Delete
return;
[319] Fix | Delete
}
[320] Fix | Delete
[321] Fix | Delete
$options_not_found = array_diff( $options_to_prime, array_keys( $options_found ) );
[322] Fix | Delete
[323] Fix | Delete
// Add the options that were not found to the cache.
[324] Fix | Delete
$update_notoptions = false;
[325] Fix | Delete
foreach ( $options_not_found as $option_name ) {
[326] Fix | Delete
if ( ! isset( $notoptions[ $option_name ] ) ) {
[327] Fix | Delete
$notoptions[ $option_name ] = true;
[328] Fix | Delete
$update_notoptions = true;
[329] Fix | Delete
}
[330] Fix | Delete
}
[331] Fix | Delete
[332] Fix | Delete
// Only update the cache if it was modified.
[333] Fix | Delete
if ( $update_notoptions ) {
[334] Fix | Delete
wp_cache_set( 'notoptions', $notoptions, 'options' );
[335] Fix | Delete
}
[336] Fix | Delete
}
[337] Fix | Delete
[338] Fix | Delete
/**
[339] Fix | Delete
* Primes the cache of all options registered with a specific option group.
[340] Fix | Delete
*
[341] Fix | Delete
* @since 6.4.0
[342] Fix | Delete
*
[343] Fix | Delete
* @global array $new_allowed_options
[344] Fix | Delete
*
[345] Fix | Delete
* @param string $option_group The option group to load options for.
[346] Fix | Delete
*/
[347] Fix | Delete
function wp_prime_option_caches_by_group( $option_group ) {
[348] Fix | Delete
global $new_allowed_options;
[349] Fix | Delete
[350] Fix | Delete
if ( isset( $new_allowed_options[ $option_group ] ) ) {
[351] Fix | Delete
wp_prime_option_caches( $new_allowed_options[ $option_group ] );
[352] Fix | Delete
}
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
/**
[356] Fix | Delete
* Retrieves multiple options.
[357] Fix | Delete
*
[358] Fix | Delete
* Options are loaded as necessary first in order to use a single database query at most.
[359] Fix | Delete
*
[360] Fix | Delete
* @since 6.4.0
[361] Fix | Delete
*
[362] Fix | Delete
* @param string[] $options An array of option names to retrieve.
[363] Fix | Delete
* @return array An array of key-value pairs for the requested options.
[364] Fix | Delete
*/
[365] Fix | Delete
function get_options( $options ) {
[366] Fix | Delete
wp_prime_option_caches( $options );
[367] Fix | Delete
[368] Fix | Delete
$result = array();
[369] Fix | Delete
foreach ( $options as $option ) {
[370] Fix | Delete
$result[ $option ] = get_option( $option );
[371] Fix | Delete
}
[372] Fix | Delete
[373] Fix | Delete
return $result;
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
/**
[377] Fix | Delete
* Sets the autoload values for multiple options in the database.
[378] Fix | Delete
*
[379] Fix | Delete
* Autoloading too many options can lead to performance problems, especially if the options are not frequently used.
[380] Fix | Delete
* This function allows modifying the autoload value for multiple options without changing the actual option value.
[381] Fix | Delete
* This is for example recommended for plugin activation and deactivation hooks, to ensure any options exclusively used
[382] Fix | Delete
* by the plugin which are generally autoloaded can be set to not autoload when the plugin is inactive.
[383] Fix | Delete
*
[384] Fix | Delete
* @since 6.4.0
[385] Fix | Delete
* @since 6.7.0 The autoload values 'yes' and 'no' are deprecated.
[386] Fix | Delete
*
[387] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[388] Fix | Delete
*
[389] Fix | Delete
* @param array $options Associative array of option names and their autoload values to set. The option names are
[390] Fix | Delete
* expected to not be SQL-escaped. The autoload values should be boolean values. For backward
[391] Fix | Delete
* compatibility 'yes' and 'no' are also accepted, though using these values is deprecated.
[392] Fix | Delete
* @return array Associative array of all provided $options as keys and boolean values for whether their autoload value
[393] Fix | Delete
* was updated.
[394] Fix | Delete
*/
[395] Fix | Delete
function wp_set_option_autoload_values( array $options ) {
[396] Fix | Delete
global $wpdb;
[397] Fix | Delete
[398] Fix | Delete
if ( ! $options ) {
[399] Fix | Delete
return array();
[400] Fix | Delete
}
[401] Fix | Delete
[402] Fix | Delete
$grouped_options = array(
[403] Fix | Delete
'on' => array(),
[404] Fix | Delete
'off' => array(),
[405] Fix | Delete
);
[406] Fix | Delete
$results = array();
[407] Fix | Delete
foreach ( $options as $option => $autoload ) {
[408] Fix | Delete
wp_protect_special_option( $option ); // Ensure only valid options can be passed.
[409] Fix | Delete
[410] Fix | Delete
/*
[411] Fix | Delete
* Sanitize autoload value and categorize accordingly.
[412] Fix | Delete
* The values 'yes', 'no', 'on', and 'off' are supported for backward compatibility.
[413] Fix | Delete
*/
[414] Fix | Delete
if ( 'off' === $autoload || 'no' === $autoload || false === $autoload ) {
[415] Fix | Delete
$grouped_options['off'][] = $option;
[416] Fix | Delete
} else {
[417] Fix | Delete
$grouped_options['on'][] = $option;
[418] Fix | Delete
}
[419] Fix | Delete
$results[ $option ] = false; // Initialize result value.
[420] Fix | Delete
}
[421] Fix | Delete
[422] Fix | Delete
$where = array();
[423] Fix | Delete
$where_args = array();
[424] Fix | Delete
foreach ( $grouped_options as $autoload => $options ) {
[425] Fix | Delete
if ( ! $options ) {
[426] Fix | Delete
continue;
[427] Fix | Delete
}
[428] Fix | Delete
$placeholders = implode( ',', array_fill( 0, count( $options ), '%s' ) );
[429] Fix | Delete
$where[] = "autoload != '%s' AND option_name IN ($placeholders)";
[430] Fix | Delete
$where_args[] = $autoload;
[431] Fix | Delete
foreach ( $options as $option ) {
[432] Fix | Delete
$where_args[] = $option;
[433] Fix | Delete
}
[434] Fix | Delete
}
[435] Fix | Delete
$where = 'WHERE ' . implode( ' OR ', $where );
[436] Fix | Delete
[437] Fix | Delete
/*
[438] Fix | Delete
* Determine the relevant options that do not already use the given autoload value.
[439] Fix | Delete
* If no options are returned, no need to update.
[440] Fix | Delete
*/
[441] Fix | Delete
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
[442] Fix | Delete
$options_to_update = $wpdb->get_col( $wpdb->prepare( "SELECT option_name FROM $wpdb->options $where", $where_args ) );
[443] Fix | Delete
if ( ! $options_to_update ) {
[444] Fix | Delete
return $results;
[445] Fix | Delete
}
[446] Fix | Delete
[447] Fix | Delete
// Run UPDATE queries as needed (maximum 2) to update the relevant options' autoload values to 'yes' or 'no'.
[448] Fix | Delete
foreach ( $grouped_options as $autoload => $options ) {
[449] Fix | Delete
if ( ! $options ) {
[450] Fix | Delete
continue;
[451] Fix | Delete
}
[452] Fix | Delete
$options = array_intersect( $options, $options_to_update );
[453] Fix | Delete
$grouped_options[ $autoload ] = $options;
[454] Fix | Delete
if ( ! $grouped_options[ $autoload ] ) {
[455] Fix | Delete
continue;
[456] Fix | Delete
}
[457] Fix | Delete
[458] Fix | Delete
// Run query to update autoload value for all the options where it is needed.
[459] Fix | Delete
$success = $wpdb->query(
[460] Fix | Delete
$wpdb->prepare(
[461] Fix | Delete
"UPDATE $wpdb->options SET autoload = %s WHERE option_name IN (" . implode( ',', array_fill( 0, count( $grouped_options[ $autoload ] ), '%s' ) ) . ')',
[462] Fix | Delete
array_merge(
[463] Fix | Delete
array( $autoload ),
[464] Fix | Delete
$grouped_options[ $autoload ]
[465] Fix | Delete
)
[466] Fix | Delete
)
[467] Fix | Delete
);
[468] Fix | Delete
if ( ! $success ) {
[469] Fix | Delete
// Set option list to an empty array to indicate no options were updated.
[470] Fix | Delete
$grouped_options[ $autoload ] = array();
[471] Fix | Delete
continue;
[472] Fix | Delete
}
[473] Fix | Delete
[474] Fix | Delete
// Assume that on success all options were updated, which should be the case given only new values are sent.
[475] Fix | Delete
foreach ( $grouped_options[ $autoload ] as $option ) {
[476] Fix | Delete
$results[ $option ] = true;
[477] Fix | Delete
}
[478] Fix | Delete
}
[479] Fix | Delete
[480] Fix | Delete
/*
[481] Fix | Delete
* If any options were changed to 'on', delete their individual caches, and delete 'alloptions' cache so that it
[482] Fix | Delete
* is refreshed as needed.
[483] Fix | Delete
* If no options were changed to 'on' but any options were changed to 'no', delete them from the 'alloptions'
[484] Fix | Delete
* cache. This is not necessary when options were changed to 'on', since in that situation the entire cache is
[485] Fix | Delete
* deleted anyway.
[486] Fix | Delete
*/
[487] Fix | Delete
if ( $grouped_options['on'] ) {
[488] Fix | Delete
wp_cache_delete_multiple( $grouped_options['on'], 'options' );
[489] Fix | Delete
wp_cache_delete( 'alloptions', 'options' );
[490] Fix | Delete
} elseif ( $grouped_options['off'] ) {
[491] Fix | Delete
$alloptions = wp_load_alloptions( true );
[492] Fix | Delete
[493] Fix | Delete
foreach ( $grouped_options['off'] as $option ) {
[494] Fix | Delete
if ( isset( $alloptions[ $option ] ) ) {
[495] Fix | Delete
unset( $alloptions[ $option ] );
[496] Fix | Delete
}
[497] Fix | Delete
}
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function