@@ -45,7 +45,7 @@ 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 } {
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 } {
49
49
* Default setting value.
50
50
*
51
51
* @type string $default_transition_animation Default view transition animation.
@@ -54,6 +54,7 @@ function plvt_get_view_transition_animation_labels(): array {
54
54
* @type string $post_title_selector CSS selector for the post title element.
55
55
* @type string $post_thumbnail_selector CSS selector for the post thumbnail element.
56
56
* @type string $post_content_selector CSS selector for the post content element.
57
+ * @type bool $enable_admin_transitions Whether to use view transitions in the admin area.
57
58
* }
58
59
*/
59
60
function plvt_get_setting_default (): array {
@@ -64,6 +65,7 @@ function plvt_get_setting_default(): array {
64
65
'post_title_selector ' => '.wp-block-post-title, .entry-title ' ,
65
66
'post_thumbnail_selector ' => '.wp-post-image ' ,
66
67
'post_content_selector ' => '.wp-block-post-content, .entry-content ' ,
68
+ 'enable_admin_transitions ' => false ,
67
69
);
68
70
}
69
71
@@ -72,7 +74,7 @@ function plvt_get_setting_default(): array {
72
74
*
73
75
* @since 1.0.0
74
76
*
75
- * @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 } {
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 } {
76
78
* Stored setting value.
77
79
*
78
80
* @type string $default_transition_animation Default view transition animation.
@@ -81,6 +83,7 @@ function plvt_get_setting_default(): array {
81
83
* @type string $post_title_selector CSS selector for the post title element.
82
84
* @type string $post_thumbnail_selector CSS selector for the post thumbnail element.
83
85
* @type string $post_content_selector CSS selector for the post content element.
86
+ * @type bool $enable_admin_transitions Whether to use view transitions in the admin area.
84
87
* }
85
88
*/
86
89
function plvt_get_stored_setting_value (): array {
@@ -93,7 +96,7 @@ function plvt_get_stored_setting_value(): array {
93
96
* @since 1.0.0
94
97
*
95
98
* @param mixed $input Setting to sanitize.
96
- * @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 } {
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 } {
97
100
* Sanitized setting.
98
101
*
99
102
* @type string $default_transition_animation Default view transition animation.
@@ -102,6 +105,7 @@ function plvt_get_stored_setting_value(): array {
102
105
* @type string $post_title_selector CSS selector for the post title element.
103
106
* @type string $post_thumbnail_selector CSS selector for the post thumbnail element.
104
107
* @type string $post_content_selector CSS selector for the post content element.
108
+ * @type bool $enable_admin_transitions Whether to use view transitions in the admin area.
105
109
* }
106
110
*/
107
111
function plvt_sanitize_setting ( $ input ): array {
@@ -136,6 +140,11 @@ function plvt_sanitize_setting( $input ): array {
136
140
}
137
141
}
138
142
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 ' ];
146
+ }
147
+
139
148
return $ value ;
140
149
}
141
150
@@ -270,19 +279,30 @@ static function (): void {
270
279
'title ' => __ ( 'Post Content Selector ' , 'view-transitions ' ),
271
280
'description ' => __ ( 'Provide the CSS selector to detect the post content element. ' , 'view-transitions ' ),
272
281
),
282
+ 'enable_admin_transitions ' => array (
283
+ 'title ' => __ ( 'WP Admin ' , 'view-transitions ' ),
284
+ 'description ' => __ ( 'Enable view transitions in the WordPress admin area. ' , 'view-transitions ' ),
285
+ ),
273
286
);
274
287
foreach ( $ fields as $ slug => $ args ) {
288
+ $ additional_args = array (
289
+ 'field ' => $ slug ,
290
+ 'label_for ' => "plvt-view-transitions-field- {$ slug }" ,
291
+ );
292
+
293
+ // Remove 'label_for' for checkbox field to avoid duplicate label association.
294
+ if ( 'enable_admin_transitions ' === $ slug ) {
295
+ unset( $ additional_args ['label_for ' ] );
296
+ }
297
+
275
298
add_settings_field (
276
299
"plvt_view_transitions_ {$ slug }" ,
277
300
$ args ['title ' ],
278
301
'plvt_render_settings_field ' ,
279
302
'reading ' ,
280
303
'plvt_view_transitions ' ,
281
304
array_merge (
282
- array (
283
- 'field ' => $ slug ,
284
- 'label_for ' => "plvt-view-transitions-field- {$ slug }" ,
285
- ),
305
+ $ additional_args ,
286
306
$ args
287
307
)
288
308
);
@@ -312,6 +332,10 @@ function plvt_render_settings_field( array $args ): void {
312
332
$ type = 'select ' ;
313
333
$ choices = plvt_get_view_transition_animation_labels ();
314
334
break ;
335
+ case 'enable_admin_transitions ' :
336
+ $ type = 'checkbox ' ;
337
+ $ choices = array (); // Defined just for consistency.
338
+ break ;
315
339
default :
316
340
$ type = 'text ' ;
317
341
$ choices = array (); // Defined just for consistency.
@@ -346,12 +370,26 @@ function plvt_render_settings_field( array $args ): void {
346
370
?>
347
371
</select>
348
372
<?php
373
+ } elseif ( 'checkbox ' === $ type ) {
374
+ ?>
375
+ <label for="<?php echo esc_attr ( "plvt-view-transitions-field- {$ args ['field ' ]}" ); ?> ">
376
+ <input
377
+ id="<?php echo esc_attr ( "plvt-view-transitions-field- {$ args ['field ' ]}" ); ?> "
378
+ name="<?php echo esc_attr ( "plvt_view_transitions[ {$ args ['field ' ]}] " ); ?> "
379
+ type="checkbox"
380
+ value="1"
381
+ <?php checked ( $ value , 1 ); ?>
382
+ class="regular-text code"
383
+ >
384
+ <?php echo esc_html ( $ args ['description ' ] ); ?>
385
+ </label>
386
+ <?php
349
387
} else {
350
388
?>
351
389
<input
352
390
id="<?php echo esc_attr ( $ args ['label_for ' ] ); ?> "
353
391
name="<?php echo esc_attr ( "plvt_view_transitions[ {$ args ['field ' ]}] " ); ?> "
354
- value="<?php echo esc_attr ( $ value ); ?> "
392
+ value="<?php echo esc_attr ( ( string ) $ value ); ?> "
355
393
class="regular-text code"
356
394
<?php
357
395
if ( '' !== $ args ['description ' ] ) {
@@ -364,7 +402,7 @@ class="regular-text code"
364
402
<?php
365
403
}
366
404
367
- if ( '' !== $ args ['description ' ] ) {
405
+ if ( '' !== $ args ['description ' ] && ' checkbox ' !== $ type ) {
368
406
?>
369
407
<p
370
408
id="<?php echo esc_attr ( $ args ['label_for ' ] . '-description ' ); ?> "
0 commit comments