WordPress at a glance

wp_load_alloptions() WP 1.0

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

  • Global. wpdb. $wpdb WordPress database abstraction object.
✈ 1 time = 0.003439s = very slow | 50000 times = 0.05s = speed of light | PHP 7.0.32, WP 5.1.1
Hooks in function
Return

Array. List of all options.

Usage

wp_load_alloptions();

Code of wp load alloptions: wp-includes/option.php WP 5.2.1

<?php
function wp_load_alloptions() {
	global $wpdb;

	if ( ! wp_installing() || ! is_multisite() ) {
		$alloptions = wp_cache_get( 'alloptions', 'options' );
	} else {
		$alloptions = false;
	}

	if ( ! $alloptions ) {
		$suppress = $wpdb->suppress_errors();
		if ( ! $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) ) {
			$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 );
}

Related Functions

From category: Site Options (settings)

No comments
    Hello, !     Log In . Register