Skip to content

Commit 7908f8b

Browse files
authored
fix: cache issues on settings page
1 parent 18d4a13 commit 7908f8b

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

src/php/settings/settings.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Code_Snippets\Welcome_API;
1212
use function Code_Snippets\clean_snippets_cache;
1313
use function Code_Snippets\code_snippets;
14+
use const Code_Snippets\CACHE_GROUP;
1415

1516
const CACHE_KEY = 'code_snippets_settings';
1617
const OPTION_GROUP = 'code-snippets';
@@ -79,7 +80,7 @@ function are_settings_unified(): bool {
7980
* @return array<string, array<string, mixed>>
8081
*/
8182
function get_settings_values(): array {
82-
$settings = wp_cache_get( CACHE_KEY );
83+
$settings = wp_cache_get( CACHE_KEY, CACHE_GROUP );
8384
if ( $settings ) {
8485
return $settings;
8586
}
@@ -93,7 +94,7 @@ function get_settings_values(): array {
9394
}
9495
}
9596

96-
wp_cache_set( CACHE_KEY, $settings );
97+
wp_cache_set( CACHE_KEY, $settings, CACHE_GROUP );
9798
return $settings;
9899
}
99100

@@ -125,7 +126,7 @@ function update_setting( string $section, string $field, $new_value ): bool {
125126

126127
$settings[ $section ][ $field ] = $new_value;
127128

128-
wp_cache_set( CACHE_KEY, $settings );
129+
wp_cache_set( CACHE_KEY, $settings, CACHE_GROUP );
129130
return update_self_option( are_settings_unified(), OPTION_NAME, $settings );
130131
}
131132

@@ -136,17 +137,11 @@ function update_setting( string $section, string $field, $new_value ): bool {
136137
*/
137138
function get_settings_sections(): array {
138139
$sections = array(
139-
'general' => __( 'General', 'code-snippets' ),
140-
'editor' => __( 'Code Editor', 'code-snippets' ),
141-
'debug' => __( 'Debug', 'code-snippets' ),
140+
'general' => __( 'General', 'code-snippets' ),
141+
'editor' => __( 'Code Editor', 'code-snippets' ),
142+
'debug' => __( 'Debug', 'code-snippets' ),
142143
);
143144

144-
// Only show the Version section when the debug setting to enable version changes is enabled.
145-
$enable_version = get_setting( 'debug', 'enable_version_change' );
146-
if ( $enable_version ) {
147-
$sections['version-switch'] = __( 'Version', 'code-snippets' );
148-
}
149-
150145
return apply_filters( 'code_snippets_settings_sections', $sections );
151146
}
152147

@@ -174,13 +169,8 @@ function register_plugin_settings() {
174169
add_settings_section( $section_id, $section_name, '__return_empty_string', 'code-snippets' );
175170
}
176171

177-
// Register settings fields. Only register fields for sections that exist (some sections may be gated by settings).
178-
$registered_sections = get_settings_sections();
172+
// Register settings fields.
179173
foreach ( get_settings_fields() as $section_id => $fields ) {
180-
if ( ! isset( $registered_sections[ $section_id ] ) ) {
181-
continue;
182-
}
183-
184174
foreach ( $fields as $field_id => $field ) {
185175
$field_object = new Setting_Field( $section_id, $field_id, $field );
186176
add_settings_field( $field_id, $field['name'], [ $field_object, 'render' ], 'code-snippets', $section_id );
@@ -306,7 +296,7 @@ function process_settings_actions( array $input ): ?array {
306296
* @return array<string, array<string, mixed>> The validated settings.
307297
*/
308298
function sanitize_settings( array $input ): array {
309-
wp_cache_delete( CACHE_KEY );
299+
wp_cache_delete( CACHE_KEY, CACHE_GROUP );
310300
$result = process_settings_actions( $input );
311301

312302
if ( ! is_null( $result ) ) {

0 commit comments

Comments
 (0)