Skip to content

Commit

Permalink
Add prime_option_caches and call it on init
Browse files Browse the repository at this point in the history
  • Loading branch information
Swanand01 committed May 22, 2024
1 parent bde1f75 commit a87297d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions includes/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ class Settings implements Service, Registerable, PluginUninstallAware {
*/
public function __construct( Shopping_Vendors $shopping_vendors ) {
$this->shopping_vendors = $shopping_vendors;
add_action( 'init', [ $this, 'prime_option_caches' ] );
}

/**
* Primes option caches for specified groups if the function exists.
*
* @since 1.37.0
*/
public function prime_option_caches(): void {
if ( \function_exists( 'wp_prime_option_caches_by_group' ) ) {
wp_prime_option_caches_by_group( self::SETTING_GROUP );
wp_prime_option_caches_by_group( self::SETTING_GROUP_EXPERIMENTS );

Check warning on line 177 in includes/Settings.php

View check run for this annotation

Codecov / codecov/patch

includes/Settings.php#L174-L177

Added lines #L174 - L177 were not covered by tests
}
}

/**
Expand Down Expand Up @@ -438,11 +451,6 @@ public function register(): void {
* @return string|array<int|string,mixed>|bool|int Setting value.
*/
public function get_setting( string $key, $default_value = false ) {
if ( \function_exists( 'wp_prime_option_caches_by_group' ) ) {
wp_prime_option_caches_by_group( self::SETTING_GROUP );
wp_prime_option_caches_by_group( self::SETTING_GROUP_EXPERIMENTS );
}

// Distinguish between `false` as a default, and not passing one, just like WordPress.
$passed_default = \func_num_args() > 1;

Expand Down

0 comments on commit a87297d

Please sign in to comment.