wp_load_alloptions()WP 2.2.0

Loads and caches all autoloaded options, if available or all options.

1 time — 0.003439 sec (very slow) | 50000 times — 0.05 sec (speed of light) | PHP 7.0.32, WP 5.1.1

Return

Array. List of all options.

Usage

wp_load_alloptions( $force_cache );
$force_cache(true|false)
Whether to force an update of the local cache from the persistent cache.
Default: false

Examples

0

#1 Get all the site options

$alloptions = wp_load_alloptions();

As a result $alloptions will contain such an array:

Array (
	[siteurl] => http://wp-kama.com/
	[blogname] => WordPress as in the palm of your hand
	[blogdescription] => Features, hacks, and articles for beginners
	[users_can_register] => 1
	[admin_email] => [email protected]
	[start_of_week] => 1
	[use_balanceTags] => 
	[require_name_email] => 1
	[comments_notify] => 
	[posts_per_rss] => 15
	[rss_use_excerpt] => 1
	[default_category] => 1
	[default_comment_status] => open
	[default_ping_status] => open
	...
0

#2 Get all transient options without timelimit

$all_options = wp_load_alloptions();
$all_transients  = array();

foreach ( $all_options as $name => $value ) {

	if ( strstr( $name, '_transient' ) ) {
		$all_transients[ $name ] = $value;
	}
}

print_r( $all_transients );

Notes

  • Global. wpdb. $wpdb WordPress database abstraction object.

Changelog

Since 2.2.0 Introduced.
Since 5.3.1 The $force_cache parameter was added.

wp_load_alloptions() code WP 6.5.2

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 = 'yes'" );
		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 );
}