ll( 0, count( $grouped_options[ $autoload ] ), '%s' ) ) . ')', array_merge( array( $autoload ), $grouped_options[ $autoload ] ) ) ); if ( ! $success ) { // Set option list to an empty array to indicate no options were updated. $grouped_options[ $autoload ] = array(); continue; } // Assume that on success all options were updated, which should be the case given only new values are sent. foreach ( $grouped_options[ $autoload ] as $option ) { $results[ $option ] = true; } } /* * If any options were changed to 'on', delete their individual caches, and delete 'alloptions' cache so that it * is refreshed as needed. * If no options were changed to 'on' but any options were changed to 'no', delete them from the 'alloptions' * cache. This is not necessary when options were changed to 'on', since in that situation the entire cache is * deleted anyway. */ if ( $grouped_options['on'] ) { wp_cache_delete_multiple( $grouped_options['on'], 'options' ); wp_cache_delete( 'alloptions', 'options' ); } elseif ( $grouped_options['off'] ) { $alloptions = wp_load_alloptions( true ); foreach ( $grouped_options['off'] as $option ) { if ( isset( $alloptions[ $option ] ) ) { unset( $alloptions[ $option ] ); } } wp_cache_set( 'alloptions', $alloptions, 'options' ); } return $results; } /** * Sets the autoload value for multiple options in the database. * * This is a wrapper for {@see wp_set_option_autoload_values()}, which can be used to set different autoload values for * each option at once. * * @since 6.4.0 * @since 6.7.0 The autoload values 'yes' and 'no' are deprecated. * * @see wp_set_option_autoload_values() * * @param string[] $options List of option names. Expected to not be SQL-escaped. * @param bool $autoload Autoload value to control whether to load the options when WordPress starts up. * For backward compatibility 'yes' and 'no' are also accepted, though using these values is * deprecated. * @return array Associative array of all provided $options as keys and boolean values for whether their autoload value * was updated. */ function wp_set_options_autoload( array $options, $autoload ) { return wp_set_option_autoload_values( array_fill_keys( $options, $autoload ) ); } /** * Sets the autoload value for an option in the database. * * This is a wrapper for {@see wp_set_option_autoload_values()}, which can be used to set the autoload value for * multiple options at once. * * @since 6.4.0 * @since 6.7.0 The autoload values 'yes' and 'no' are deprecated. * * @see wp_set_option_autoload_values() * * @param string $option Name of the option. Expected to not be SQL-escaped. * @param bool $autoload Autoload value to control whether to load the option when WordPress starts up. * For backward compatibility 'yes' and 'no' are also accepted, though using these values is * deprecated. * @return bool True if the autoload value was modified, false otherwise. */ function wp_set_option_autoload( $option, $autoload ) { $result = wp_set_option_autoload_values( array( $option => $autoload ) ); if ( isset( $result[ $option ] ) ) { return $result[ $option ]; } return false; } /** * Protects WordPress special option from being modified. * * Will die if $option is in protected list. Protected options are 'alloptions' * and 'notoptions' options. * * @since 2.2.0 * * @param string $option Option name. */ function wp_protect_special_option( $option ) { if ( 'alloptions' === $option || 'notoptions' === $option ) { wp_die( sprintf( /* translators: %s: Option name. */ __( '%s is a protected WP option and may not be modified' ), esc_html( $option ) ) ); } } /** * Prints option value after sanitizing for forms. * * @since 1.5.0 * * @param string $option Option name. */ function form_option( $option ) { echo esc_attr( get_option( $option ) ); } /** * Loads and caches all autoloaded options, if available or all options. * * @since 2.2.0 * @since 5.3.1 The `$force_cache` parameter was added. * * @global wpdb $wpdb WordPress database abstraction object. * * @param bool $force_cache Optional. Whether to force an update of the local cache * from the persistent cache. Default false. * @return array List of all options. */ function wp_load_alloptions( $force_cache = false ) { global $wpdb; /** * Filters the array of alloptions before it is populated. * * Returning an array from the filter will effectively short circuit * wp_load_alloptions(), returning that value instead. * * @since 6.2.0 * * @param array|null $alloptions An array of alloptions. Default null. * @param bool $force_cache Whether to force an update of the local cache from the persistent cache. Default false. */ $alloptions = apply_filters( 'pre_wp_load_alloptions', null, $force_cache ); if ( is_array( $alloptions ) ) { return $alloptions; } if ( ! wp_installing() || ! is_multisite() ) { $alloptions = wp_cache_get( 'alloptions', 'options', $force_cache ); } else { $alloptions = false; } if ( ! $alloptions ) { $suppress = $wpdb->suppress_errors(); $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload IN ( '" . implode( "', '", esc_sql( wp_autoload_values_to_autoload() ) ) . "' )" ); if ( ! $alloptions_db ) { $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" ); } $wpdb->suppress_errors( $suppress ); $alloptions = array(); foreach ( (array) $alloptions_db as $o ) { $alloptions[ $o->option_name ] = $o->option_value; } if ( ! wp_installing() || ! is_multisite() ) { /** * Filters all options before caching them. * * @since 4.9.0 * * @param array $alloptions Array with all options. */ $alloptions = apply_filters( 'pre_cache_alloptions', $alloptions ); wp_cache_add( 'alloptions', $alloptions, 'options' ); } } /** * Filters all options after retrieving them. * * @since 4.9.0 * * @param array $alloptions Array with all options. */ return apply_filters( 'alloptions', $alloptions ); } /** * Primes specific network options for the current network into the cache with a single database query. * * Only network options that do not already exist in cache will be loaded. * * If site is not multisite, then call wp_prime_option_caches(). * * @since 6.6.0 * * @see wp_prime_network_option_caches() * * @param string[] $options An array of option names to be loaded. */ function wp_prime_site_option_caches( array $options ) { wp_prime_network_option_caches( null, $options ); } /** * Primes specific network options into the cache with a single database query. * * Only network options that do not already exist in cache will be loaded. * * If site is not multisite, then call wp_prime_option_caches(). * * @since 6.6.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int|null $network_id ID of the network. Can be null to default to the current network ID. * @param string[] $options An array of option names to be loaded. */ function wp_prime_network_option_caches( $network_id, array $options ) { global $wpdb; if ( wp_installing() ) { return; } if ( ! is_multisite() ) { wp_prime_option_caches( $options ); return; } if ( $network_id && ! is_numeric( $network_id ) ) { return; } $network_id = (int) $network_id; // Fallback to the current network if a network ID is not specified. if ( ! $network_id ) { $network_id = get_current_network_id(); } $cache_keys = array(); foreach ( $options as $option ) { $cache_keys[ $option ] = "{$network_id}:{$option}"; } $cache_group = 'site-options'; $cached_options = wp_cache_get_multiple( array_values( $cache_keys ), $cache_group ); $notoptions_key = "$network_id:notoptions"; $notoptions = wp_cache_get( $notoptions_key, $cache_group ); if ( ! is_array( $notoptions ) ) { $notoptions