From 071518faab4f8e333d587d9f0d39d24027e2bc4e Mon Sep 17 00:00:00 2001 From: "m.rainko" Date: Wed, 11 Mar 2026 13:34:39 +0100 Subject: [PATCH 1/2] add ACF options caching to Timber context --- .../juniper-theme/class-startersite.php | 3 +- web/app/themes/juniper-theme/inc/include.php | 1 + .../themes/juniper-theme/inc/optimization.php | 41 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 web/app/themes/juniper-theme/inc/optimization.php diff --git a/web/app/themes/juniper-theme/class-startersite.php b/web/app/themes/juniper-theme/class-startersite.php index d5d8a3e0f..4078e1da7 100644 --- a/web/app/themes/juniper-theme/class-startersite.php +++ b/web/app/themes/juniper-theme/class-startersite.php @@ -19,7 +19,8 @@ public function __construct() { * @param string $context context['this'] Being the Twig's {{ this }}. */ public function add_to_context( $context ) { - $context['site'] = $this; + $context['site'] = $this; + $context['options'] = juniper_get_cached_options(); return $context; } diff --git a/web/app/themes/juniper-theme/inc/include.php b/web/app/themes/juniper-theme/inc/include.php index 14b8d03bc..fece9df23 100644 --- a/web/app/themes/juniper-theme/inc/include.php +++ b/web/app/themes/juniper-theme/inc/include.php @@ -1,5 +1,6 @@ Date: Wed, 11 Mar 2026 13:37:27 +0100 Subject: [PATCH 2/2] phpcs --- web/app/themes/juniper-theme/inc/optimization.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/web/app/themes/juniper-theme/inc/optimization.php b/web/app/themes/juniper-theme/inc/optimization.php index bf1b909fc..314ae4803 100644 --- a/web/app/themes/juniper-theme/inc/optimization.php +++ b/web/app/themes/juniper-theme/inc/optimization.php @@ -17,14 +17,16 @@ function juniper_get_cached_options( bool $use_cache = false ): array { $use_cache = apply_filters( 'juniper_use_options_cache', $use_cache ); if ( ! $use_cache ) { - return get_fields( 'options' ) ?: array(); + $fields = get_fields( 'options' ); + return $fields ? $fields : array(); } $cache_key = 'juniper_acf_options'; $options = get_transient( $cache_key ); if ( false === $options ) { - $options = get_fields( 'options' ) ?: array(); + $options = get_fields( 'options' ); + $options = $options ? $options : array(); set_transient( $cache_key, $options, WEEK_IN_SECONDS ); }