bbp_pre_load_options()

Loads & caches bbPress options if a persistent cache is not being used.


Description Description


Source Source

File: includes/core/options.php

function bbp_pre_load_options() {

	// Bail if using object cache or installing
	if ( wp_using_ext_object_cache() || wp_installing() ) {
		return;
	}

	// Maybe intercept
	$strategy  = apply_filters( 'bbp_pre_load_options_strategy', 'notoptions' );
	$intercept = bbp_maybe_intercept( __FUNCTION__, $strategy );
	if ( bbp_is_intercepted( $intercept ) ) {
		return $intercept;
	}

	// Get variables
	$bbp         = bbpress();
	$bbp_options = bbp_get_default_options();
	$all_options = wp_load_alloptions();
	$not_options = (array) wp_cache_get( 'notoptions', 'options' );

	// Loop through all bbPress options to maybe cache their non-existence
	foreach ( $bbp_options as $option => $value ) {

		// Skip if already saved to database
		if ( isset( $all_options[ $option ] ) ) {
			continue;

		// Skip if overloaded
		} elseif ( isset( $bbp->options[ $option ] ) ) {
			continue;

		// Skip if already in cache
		} elseif ( wp_cache_get( $option, 'options' ) !== false ) {
			continue;

		// Needs caching to avoid database hit
		} else {

			// Store internally, for easier identification later
			$bbp->not_options[ $option ] = $value;

			// Cache to notoptions
			if ( 'notoptions' === $strategy ) {
				$not_options[ $option ] = true;
				wp_cache_set( 'notoptions', $not_options, 'options' );

			// Cache to option
			} elseif ( 'option' === $strategy ) {
				wp_cache_set( $option, $value, 'options' );
			}
		}
	}
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.