@@ -45,9 +45,11 @@ function plvt_get_view_transition_animation_labels(): array {
45
45
* @since 1.0.0
46
46
* @see plvt_sanitize_view_transitions_theme_support()
47
47
*
48
- * @return array{ default_transition_animation: non-empty-string, header_selector: non-empty-string, main_selector: non-empty-string, post_title_selector: non-empty-string, post_thumbnail_selector: non-empty-string, post_content_selector: non-empty-string, enable_admin_transitions: bool } {
48
+ * @return array{ override_theme_config: bool, default_transition_animation: non-empty-string, header_selector: non-empty-string, main_selector: non-empty-string, post_title_selector: non-empty-string, post_thumbnail_selector: non-empty-string, post_content_selector: non-empty-string, enable_admin_transitions: bool } {
49
49
* Default setting value.
50
50
*
51
+ * @type bool $override_theme_config Whether to override the current theme's configuration. Otherwise,
52
+ * the other frontend specific settings won't be applied.
51
53
* @type string $default_transition_animation Default view transition animation.
52
54
* @type string $header_selector CSS selector for the global header element.
53
55
* @type string $main_selector CSS selector for the global main element.
@@ -59,6 +61,7 @@ function plvt_get_view_transition_animation_labels(): array {
59
61
*/
60
62
function plvt_get_setting_default (): array {
61
63
return array (
64
+ 'override_theme_config ' => false ,
62
65
'default_transition_animation ' => 'fade ' ,
63
66
'header_selector ' => 'header ' ,
64
67
'main_selector ' => 'main ' ,
@@ -74,9 +77,11 @@ function plvt_get_setting_default(): array {
74
77
*
75
78
* @since 1.0.0
76
79
*
77
- * @return array{ default_transition_animation: non-empty-string, header_selector: non-empty-string, main_selector: non-empty-string, post_title_selector: non-empty-string, post_thumbnail_selector: non-empty-string, post_content_selector: non-empty-string, enable_admin_transitions: bool } {
80
+ * @return array{ override_theme_config: bool, default_transition_animation: non-empty-string, header_selector: non-empty-string, main_selector: non-empty-string, post_title_selector: non-empty-string, post_thumbnail_selector: non-empty-string, post_content_selector: non-empty-string, enable_admin_transitions: bool } {
78
81
* Stored setting value.
79
82
*
83
+ * @type bool $override_theme_config Whether to override the current theme's configuration. Otherwise,
84
+ * the other frontend specific settings won't be applied.
80
85
* @type string $default_transition_animation Default view transition animation.
81
86
* @type string $header_selector CSS selector for the global header element.
82
87
* @type string $main_selector CSS selector for the global main element.
@@ -96,9 +101,11 @@ function plvt_get_stored_setting_value(): array {
96
101
* @since 1.0.0
97
102
*
98
103
* @param mixed $input Setting to sanitize.
99
- * @return array{ default_transition_animation: non-empty-string, header_selector: non-empty-string, main_selector: non-empty-string, post_title_selector: non-empty-string, post_thumbnail_selector: non-empty-string, post_content_selector: non-empty-string, enable_admin_transitions: bool } {
104
+ * @return array{ override_theme_config: bool, default_transition_animation: non-empty-string, header_selector: non-empty-string, main_selector: non-empty-string, post_title_selector: non-empty-string, post_thumbnail_selector: non-empty-string, post_content_selector: non-empty-string, enable_admin_transitions: bool } {
100
105
* Sanitized setting.
101
106
*
107
+ * @type bool $override_theme_config Whether to override the current theme's configuration. Otherwise,
108
+ * the other frontend specific settings won't be applied.
102
109
* @type string $default_transition_animation Default view transition animation.
103
110
* @type string $header_selector CSS selector for the global header element.
104
111
* @type string $main_selector CSS selector for the global main element.
@@ -140,9 +147,14 @@ function plvt_sanitize_setting( $input ): array {
140
147
}
141
148
}
142
149
143
- // Sanitize "enable_admin_transitions" as a boolean.
144
- if ( isset ( $ input ['enable_admin_transitions ' ] ) ) {
145
- $ value ['enable_admin_transitions ' ] = (bool ) $ input ['enable_admin_transitions ' ];
150
+ $ checkbox_options = array (
151
+ 'override_theme_config ' ,
152
+ 'enable_admin_transitions ' ,
153
+ );
154
+ foreach ( $ checkbox_options as $ checkbox_option ) {
155
+ if ( isset ( $ input [ $ checkbox_option ] ) ) {
156
+ $ value [ $ checkbox_option ] = (bool ) $ input [ $ checkbox_option ];
157
+ }
146
158
}
147
159
148
160
return $ value ;
@@ -188,20 +200,26 @@ function plvt_register_setting(): void {
188
200
* @since 1.0.0
189
201
* @access private
190
202
*
191
- * @global array<string, mixed> $_wp_theme_features Theme support features added and their arguments.
203
+ * @global bool|null $plvt_has_theme_support_with_args Whether the current theme explicitly supports view transitions with custom config.
204
+ * @global array<string, mixed> $_wp_theme_features Theme support features added and their arguments.
192
205
*/
193
206
function plvt_apply_settings_to_theme_support (): void {
194
- global $ _wp_theme_features ;
207
+ global $ plvt_has_theme_support_with_args , $ _wp_theme_features ;
195
208
196
209
// Bail if the feature is disabled.
197
210
if ( ! isset ( $ _wp_theme_features ['view-transitions ' ] ) ) {
198
211
return ;
199
212
}
200
213
214
+ // Bail if the current theme explicitly supports view transitions and the option to override is turned off.
215
+ $ options = plvt_get_stored_setting_value ();
216
+ if ( $ plvt_has_theme_support_with_args && ! $ options ['override_theme_config ' ] ) {
217
+ return ;
218
+ }
219
+
201
220
$ args = $ _wp_theme_features ['view-transitions ' ];
202
221
203
222
// Apply the settings.
204
- $ options = plvt_get_stored_setting_value ();
205
223
$ args ['default-animation ' ] = $ options ['default_transition_animation ' ];
206
224
$ selector_options = array (
207
225
'global ' => array (
@@ -233,19 +251,33 @@ function plvt_apply_settings_to_theme_support(): void {
233
251
*
234
252
* @since 1.0.0
235
253
* @access private
254
+ *
255
+ * @global bool|null $plvt_has_theme_support_with_args Whether the current theme explicitly supports view transitions with custom config.
236
256
*/
237
257
function plvt_add_setting_ui (): void {
258
+ global $ plvt_has_theme_support_with_args ;
259
+
238
260
add_settings_section (
239
261
'plvt_view_transitions ' ,
240
262
_x ( 'View Transitions ' , 'Settings section ' , 'view-transitions ' ),
241
263
static function (): void {
264
+ global $ plvt_has_theme_support_with_args ;
242
265
?>
243
266
<p class="description">
244
- <?php esc_html_e ( 'This section allows you to control how view transitions are used to enhance the navigation user experience. ' , 'view-transitions ' ); ?>
267
+ <?php esc_html_e ( 'This section allows you to control view transitions usage on your site to enhance the navigation user experience. ' , 'view-transitions ' ); ?>
245
268
<br>
246
269
<?php esc_html_e ( 'To reset any of the selector text inputs, clear the field and save the changes. ' , 'view-transitions ' ); ?>
247
270
</p>
248
271
<?php
272
+ if ( $ plvt_has_theme_support_with_args ) {
273
+ wp_admin_notice (
274
+ __ ( 'Your theme already supports view transitions with its own adapted configuration. The settings below will override those. ' , 'view-transitions ' ),
275
+ array (
276
+ 'type ' => 'info ' ,
277
+ 'additional_classes ' => array ( 'inline ' ),
278
+ )
279
+ );
280
+ }
249
281
},
250
282
'reading ' ,
251
283
array (
@@ -254,44 +286,82 @@ static function (): void {
254
286
)
255
287
);
256
288
289
+ add_settings_section (
290
+ 'plvt_admin_view_transitions ' ,
291
+ _x ( 'Admin View Transitions ' , 'Settings section ' , 'view-transitions ' ),
292
+ static function (): void {
293
+ ?>
294
+ <p class="description">
295
+ <?php esc_html_e ( 'This section allows you to control view transitions usage in the WordPress admin area. ' , 'view-transitions ' ); ?>
296
+ </p>
297
+ <?php
298
+ },
299
+ 'reading ' ,
300
+ array (
301
+ 'before_section ' => '<div id="admin-view-transitions"> ' ,
302
+ 'after_section ' => '</div> ' ,
303
+ )
304
+ );
305
+
257
306
$ fields = array (
307
+ 'override_theme_config ' => array (
308
+ 'section ' => 'plvt_view_transitions ' ,
309
+ 'title ' => __ ( 'Override Theme Configuration ' , 'view-transitions ' ),
310
+ 'description ' => __ ( 'Override the theme provided configuration with the settings below. ' , 'view-transitions ' ),
311
+ ),
258
312
'default_transition_animation ' => array (
313
+ 'section ' => 'plvt_view_transitions ' ,
259
314
'title ' => __ ( 'Default Transition Animation ' , 'view-transitions ' ),
260
315
'description ' => __ ( 'Choose the animation that is used for the default view transition type. ' , 'view-transitions ' ),
261
316
),
262
317
'header_selector ' => array (
318
+ 'section ' => 'plvt_view_transitions ' ,
263
319
'title ' => __ ( 'Header Selector ' , 'view-transitions ' ),
264
320
'description ' => __ ( 'Provide the CSS selector to detect the global header element. ' , 'view-transitions ' ),
265
321
),
266
322
'main_selector ' => array (
323
+ 'section ' => 'plvt_view_transitions ' ,
267
324
'title ' => __ ( 'Main Selector ' , 'view-transitions ' ),
268
325
'description ' => __ ( 'Provide the CSS selector to detect the global main element. ' , 'view-transitions ' ),
269
326
),
270
327
'post_title_selector ' => array (
328
+ 'section ' => 'plvt_view_transitions ' ,
271
329
'title ' => __ ( 'Post Title Selector ' , 'view-transitions ' ),
272
330
'description ' => __ ( 'Provide the CSS selector to detect the post title element. ' , 'view-transitions ' ),
273
331
),
274
332
'post_thumbnail_selector ' => array (
333
+ 'section ' => 'plvt_view_transitions ' ,
275
334
'title ' => __ ( 'Post Thumbnail Selector ' , 'view-transitions ' ),
276
335
'description ' => __ ( 'Provide the CSS selector to detect the post thumbnail element. ' , 'view-transitions ' ),
277
336
),
278
337
'post_content_selector ' => array (
338
+ 'section ' => 'plvt_view_transitions ' ,
279
339
'title ' => __ ( 'Post Content Selector ' , 'view-transitions ' ),
280
340
'description ' => __ ( 'Provide the CSS selector to detect the post content element. ' , 'view-transitions ' ),
281
341
),
282
342
'enable_admin_transitions ' => array (
343
+ 'section ' => 'plvt_admin_view_transitions ' ,
283
344
'title ' => __ ( 'WP Admin ' , 'view-transitions ' ),
284
345
'description ' => __ ( 'Enable view transitions in the WordPress admin area. ' , 'view-transitions ' ),
285
346
),
286
347
);
348
+
349
+ // Do not render the checkbox to override if there is nothing to override.
350
+ if ( ! $ plvt_has_theme_support_with_args ) {
351
+ unset( $ fields ['override_theme_config ' ] );
352
+ }
353
+
287
354
foreach ( $ fields as $ slug => $ args ) {
355
+ $ section = $ args ['section ' ];
356
+ unset( $ args ['section ' ] );
357
+
288
358
$ additional_args = array (
289
359
'field ' => $ slug ,
290
360
'label_for ' => "plvt-view-transitions-field- {$ slug }" ,
291
361
);
292
362
293
- // Remove 'label_for' for checkbox field to avoid duplicate label association.
294
- if ( 'enable_admin_transitions ' === $ slug ) {
363
+ // Remove 'label_for' for checkbox fields to avoid duplicate label association.
364
+ if ( 'override_theme_config ' === $ slug || ' enable_admin_transitions ' === $ slug ) {
295
365
unset( $ additional_args ['label_for ' ] );
296
366
}
297
367
@@ -300,7 +370,7 @@ static function (): void {
300
370
$ args ['title ' ],
301
371
'plvt_render_settings_field ' ,
302
372
'reading ' ,
303
- ' plvt_view_transitions ' ,
373
+ $ section ,
304
374
array_merge (
305
375
$ additional_args ,
306
376
$ args
@@ -332,6 +402,7 @@ function plvt_render_settings_field( array $args ): void {
332
402
$ type = 'select ' ;
333
403
$ choices = plvt_get_view_transition_animation_labels ();
334
404
break ;
405
+ case 'override_theme_config ' :
335
406
case 'enable_admin_transitions ' :
336
407
$ type = 'checkbox ' ;
337
408
$ choices = array (); // Defined just for consistency.
0 commit comments