@@ -49,6 +49,22 @@ function render_settings_page() {
49
49
echo '<div class="notice notice-success is-dismissible"><p> ' . esc_html__ ( 'Settings saved. ' , 'wdsbt ' ) . '</p></div> ' ;
50
50
}
51
51
52
+ // Handle flush pattern registry request.
53
+ if ( isset ( $ _POST ['wdsbt_flush_patterns ' ] ) && check_admin_referer ( 'wdsbt_flush_patterns_action ' ) ) {
54
+ wdsbt_flush_pattern_registry ();
55
+ // Clear object cache.
56
+ if ( function_exists ( 'wp_cache_flush ' ) ) {
57
+ wp_cache_flush ();
58
+ }
59
+ // Delete all transients.
60
+ global $ wpdb ;
61
+ $ wpdb ->query ( "DELETE FROM $ wpdb ->options WHERE option_name LIKE '_transient_%' " );
62
+ echo '<div class="notice notice-success is-dismissible"><p>Block pattern registry, Object cache and transients flushed.</p> ' ;
63
+ echo '<p style="margin-top:1em;"><strong>Note:</strong> Due to WordPress caching, <u>new pattern categories and patterns may only appear after switching to another theme and back, or waiting for the cache to expire</u>. This is a WordPress limitation and does not affect production sites where patterns/categories are set before launch.</p></div> ' ;
64
+ // Inject JS to notify the block editor.
65
+ echo "<script>if (window.localStorage) { localStorage.setItem('wdsbt_patterns_flushed', Date.now()); }</script> " ;
66
+ }
67
+
52
68
// Determine current status summary.
53
69
$ loading_status = $ global_value
54
70
? __ ( 'Speculative Loading is currently <strong>disabled globally</strong>. ' , 'wdsbt ' )
@@ -60,45 +76,80 @@ function render_settings_page() {
60
76
61
77
<div class="wrap">
62
78
<h1><?php esc_html_e ( 'WDSBT Settings ' , 'wdsbt ' ); ?> </h1>
63
- <small ><?php esc_html_e ( 'Control optional features for this block theme. ' , 'wdsbt ' ); ?> </small >
79
+ <h2 ><?php esc_html_e ( 'Control optional features for this block theme. ' , 'wdsbt ' ); ?> </h2 >
64
80
65
81
<div class="notice notice-info" style="margin-top: 20px;">
66
82
<p><?php echo wp_kses_post ( $ loading_status ); ?> </p>
67
83
</div>
68
84
69
- <form method="post" style="margin-top: 2em;">
70
- <?php wp_nonce_field ( 'save_settings ' , 'settings_nonce ' ); ?>
85
+ <div class="options-container" style="display: inline-flex; gap: 20px; width: 100%;">
71
86
72
87
<div class="card">
73
88
<h2 class="title"><?php esc_html_e ( 'Performance Options ' , 'wdsbt ' ); ?> </h2>
74
89
75
- <label style="display: flex; align-items: center; gap: 12px;">
76
- <input type="checkbox" name="<?php echo esc_attr ( $ global_option ); ?> " <?php checked ( $ global_value ); ?> />
77
- <h3><?php esc_html_e ( 'Disable Speculative Loading for the Entire Site ' , 'wdsbt ' ); ?> </h3>
78
- </label>
79
- <p class="description">
80
- <?php esc_html_e ( 'No pages will be prefetched or prerendered. ' , 'wdsbt ' ); ?>
81
- </p>
82
-
83
- <label style="display: flex; align-items: center; gap: 12px; margin-top: 16px;">
84
- <input type="checkbox" name="<?php echo esc_attr ( $ exclude_option ); ?> " <?php checked ( $ exclude_value ); ?> />
85
- <h3><?php esc_html_e ( 'Exclude sensitive pages only (e.g., Cart, Checkout) ' , 'wdsbt ' ); ?> </h3>
86
- </label>
87
- <p class="description">
88
- <?php esc_html_e ( 'Recommended for e-commerce and membership sites. ' , 'wdsbt ' ); ?>
89
- </p>
90
-
91
- <label style="display: flex; align-items: center; gap: 12px; margin-top: 16px;">
92
- <input type="checkbox" name="<?php echo esc_attr ( $ debug_option ); ?> " <?php checked ( $ debug_value ); ?> />
93
- <h3><?php esc_html_e ( 'Enable debug logging for speculative loading in console ' , 'wdsbt ' ); ?> </h3>
94
- </label>
95
- <p class="description">
96
- <?php esc_html_e ( 'Logs whether a page was prerendered, is prerendering, or was loaded normally. ' , 'wdsbt ' ); ?>
97
- </p>
98
-
99
- <?php submit_button ( __ ( 'Save Settings ' , 'wdsbt ' ) ); ?>
90
+ <form method="post" style="margin-top: 2em;">
91
+ <?php wp_nonce_field ( 'save_settings ' , 'settings_nonce ' ); ?>
92
+
93
+ <label style="display: flex; align-items: center; gap: 12px;">
94
+ <input type="checkbox" name="<?php echo esc_attr ( $ global_option ); ?> " <?php checked ( $ global_value ); ?> />
95
+ <h3><?php esc_html_e ( 'Disable Speculative Loading for the Entire Site ' , 'wdsbt ' ); ?> </h3>
96
+ </label>
97
+ <p class="description">
98
+ <?php esc_html_e ( 'No pages will be prefetched or prerendered. ' , 'wdsbt ' ); ?>
99
+ </p>
100
+
101
+ <label style="display: flex; align-items: center; gap: 12px; margin-top: 16px;">
102
+ <input type="checkbox" name="<?php echo esc_attr ( $ exclude_option ); ?> " <?php checked ( $ exclude_value ); ?> />
103
+ <h3><?php esc_html_e ( 'Exclude sensitive pages only (e.g., Cart, Checkout) ' , 'wdsbt ' ); ?> </h3>
104
+ </label>
105
+ <p class="description">
106
+ <?php esc_html_e ( 'Recommended for e-commerce and membership sites. ' , 'wdsbt ' ); ?>
107
+ </p>
108
+
109
+ <label style="display: flex; align-items: center; gap: 12px; margin-top: 16px;">
110
+ <input type="checkbox" name="<?php echo esc_attr ( $ debug_option ); ?> " <?php checked ( $ debug_value ); ?> />
111
+ <h3><?php esc_html_e ( 'Enable debug logging for speculative loading in console ' , 'wdsbt ' ); ?> </h3>
112
+ </label>
113
+ <p class="description">
114
+ <?php esc_html_e ( 'Logs whether a page was prerendered, is prerendering, or was loaded normally. ' , 'wdsbt ' ); ?>
115
+ </p>
116
+
117
+ <?php submit_button ( __ ( 'Save Settings ' , 'wdsbt ' ) ); ?>
118
+ </form>
119
+ </div>
120
+
121
+ <div class="card">
122
+ <h2 class="title"><?php esc_html_e ( 'Development Tools ' , 'wdsbt ' ); ?> </h2>
123
+
124
+ <form method="post">
125
+ <?php wp_nonce_field ( 'wdsbt_flush_patterns_action ' ); ?>
126
+ <p>
127
+ <input type="submit" name="wdsbt_flush_patterns" class="button button-primary" value="<?php esc_attr_e ( 'Flush object cache and transients ' , 'wdsbt ' ); ?> ">
128
+ </p>
129
+ </form>
100
130
</div>
101
- </form >
131
+ </div >
102
132
</div>
103
133
<?php
104
134
}
135
+
136
+ // Add flush pattern registry function if not present.
137
+ if ( ! function_exists ( 'wdsbt_flush_pattern_registry ' ) ) {
138
+
139
+ /**
140
+ * Flush pattern registry.
141
+ */
142
+ function wdsbt_flush_pattern_registry () {
143
+ // Unregister all custom patterns (adjust 'wdsbt/' to your theme slug).
144
+ $ patterns = \WP_Block_Patterns_Registry::get_instance ()->get_all_registered ();
145
+ foreach ( $ patterns as $ pattern ) {
146
+ if ( strpos ( $ pattern ['name ' ], 'wdsbt/ ' ) === 0 ) {
147
+ unregister_block_pattern ( $ pattern ['name ' ] );
148
+ }
149
+ }
150
+ // Re-register categories and patterns.
151
+ if ( function_exists ( 'wdsbt_register_dynamic_block_pattern_categories ' ) ) {
152
+ wdsbt_register_dynamic_block_pattern_categories ();
153
+ }
154
+ }
155
+ }
0 commit comments