add ACF options caching to Timber context - #26
Conversation
WalkthroughAdds an optimization module that provides transient-cached retrieval and clearing of ACF options, loads that module from the theme includes, and injects the cached options into the Twig template context as Changes
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
web/app/themes/juniper-theme/inc/optimization.php (1)
23-23: Consider extracting the cache key to a constant.The cache key
'juniper_acf_options'is hardcoded in two places. A constant would reduce duplication.Proposed refactor
+const JUNIPER_ACF_OPTIONS_CACHE_KEY = 'juniper_acf_options'; + function juniper_get_cached_options( bool $use_cache = false ): array { // ... - $cache_key = 'juniper_acf_options'; + $cache_key = JUNIPER_ACF_OPTIONS_CACHE_KEY; // ... } function juniper_clear_options_cache(): void { - delete_transient( 'juniper_acf_options' ); + delete_transient( JUNIPER_ACF_OPTIONS_CACHE_KEY ); }Also applies to: 37-38
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@web/app/themes/juniper-theme/inc/optimization.php` at line 23, Extract the hardcoded cache key 'juniper_acf_options' into a constant (e.g. JUNIPER_ACF_OPTIONS_CACHE_KEY) and replace all occurrences where $cache_key is assigned or the literal is used (the instances around the $cache_key assignment and the other occurrence at lines referenced in the review) with that constant; update any functions or checks that reference the string to use the constant so duplication is removed and future changes only require a single constant update.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@web/app/themes/juniper-theme/class-startersite.php`:
- Around line 22-23: The options are being fetched without enabling caching
because juniper_get_cached_options() defaults to $use_cache = false; change the
call that sets $context['options'] to pass true (i.e., call
juniper_get_cached_options(true)) so caching is used; update the assignment
where $context['options'] is set in class-startersite.php to call
juniper_get_cached_options(true) and confirm behavior remains correct for
templates that consume $context['options'].
In `@web/app/themes/juniper-theme/inc/optimization.php`:
- Line 27: The short ternary usage in the assignment to $options using
get_fields('options') (in optimization.php) violates WP coding standards;
replace the short ternary with an explicit full ternary or null-coalescing
equivalent so that $options is set to the result of get_fields('options') when
truthy and to an empty array otherwise (avoid calling get_fields twice by
capturing its return in a temporary variable if needed).
- Line 20: Replace the short ternary expression "get_fields( 'options' ) ?:
array()" with an explicit ternary to satisfy WP coding standards: capture the
result of get_fields('options') into a local variable (e.g., $fields =
get_fields('options')), then return $fields ? $fields : array(); update the
return in the function where this expression appears (the get_fields('options')
return site options code) so you don't call get_fields() twice and the short
ternary operator is removed.
---
Nitpick comments:
In `@web/app/themes/juniper-theme/inc/optimization.php`:
- Line 23: Extract the hardcoded cache key 'juniper_acf_options' into a constant
(e.g. JUNIPER_ACF_OPTIONS_CACHE_KEY) and replace all occurrences where
$cache_key is assigned or the literal is used (the instances around the
$cache_key assignment and the other occurrence at lines referenced in the
review) with that constant; update any functions or checks that reference the
string to use the constant so duplication is removed and future changes only
require a single constant update.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 46d2a269-30b4-4437-ad4c-6fdc08d6010d
📒 Files selected for processing (3)
web/app/themes/juniper-theme/class-startersite.phpweb/app/themes/juniper-theme/inc/include.phpweb/app/themes/juniper-theme/inc/optimization.php
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
web/app/themes/juniper-theme/inc/optimization.php (1)
24-24: Consider extracting the cache key to a constant.
'juniper_acf_options'appears in bothjuniper_get_cached_optionsandjuniper_clear_options_cache. Centralizing it prevents accidental mismatches.Proposed refactor
+const JUNIPER_OPTIONS_CACHE_KEY = 'juniper_acf_options'; + function juniper_get_cached_options( bool $use_cache = false ): array { // ... - $cache_key = 'juniper_acf_options'; + $cache_key = JUNIPER_OPTIONS_CACHE_KEY; // ... } function juniper_clear_options_cache(): void { - delete_transient( 'juniper_acf_options' ); + delete_transient( JUNIPER_OPTIONS_CACHE_KEY ); }Also applies to: 39-41
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@web/app/themes/juniper-theme/inc/optimization.php` at line 24, The literal cache key 'juniper_acf_options' is duplicated in juniper_get_cached_options and juniper_clear_options_cache; extract it to a single constant (e.g., JUNIPER_ACF_OPTIONS_CACHE_KEY) and replace the string occurrences in both functions with that constant to avoid mismatches and centralize configuration.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@web/app/themes/juniper-theme/inc/optimization.php`:
- Line 12: The default should enable caching: change the function signature of
juniper_get_cached_options to default the $use_cache parameter to true (bool
$use_cache = true) so calls that omit the argument (e.g., from StarterSite
class) will use the cache; alternatively, if you prefer explicitness, update the
caller that invokes juniper_get_cached_options() with no args to pass true
instead (juniper_get_cached_options(true)).
---
Nitpick comments:
In `@web/app/themes/juniper-theme/inc/optimization.php`:
- Line 24: The literal cache key 'juniper_acf_options' is duplicated in
juniper_get_cached_options and juniper_clear_options_cache; extract it to a
single constant (e.g., JUNIPER_ACF_OPTIONS_CACHE_KEY) and replace the string
occurrences in both functions with that constant to avoid mismatches and
centralize configuration.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: eb441aa7-1043-4af6-854d-a92c0111d609
📒 Files selected for processing (1)
web/app/themes/juniper-theme/inc/optimization.php
Summary by CodeRabbit
New Features
Performance