From b83c2e4dfa338b4559a55b7500f87a89523e8ef8 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Thu, 5 Jun 2025 07:13:56 -0700 Subject: [PATCH 1/7] Inform the user if the current theme explicitly supports view transitions with its own configuration, and add a UI control to make overriding that configuration via settings optional. --- .../view-transitions/includes/settings.php | 42 ++++++++++++++++--- plugins/view-transitions/includes/theme.php | 7 ++++ 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/plugins/view-transitions/includes/settings.php b/plugins/view-transitions/includes/settings.php index 81b0827980..1ed9b96321 100644 --- a/plugins/view-transitions/includes/settings.php +++ b/plugins/view-transitions/includes/settings.php @@ -45,9 +45,11 @@ function plvt_get_view_transition_animation_labels(): array { * @since 1.0.0 * @see plvt_sanitize_view_transitions_theme_support() * - * @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 } { + * @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 } { * Default setting value. * + * @type bool $override_theme_config Whether to override the current theme's configuration. Otherwise, + * the other frontend specific settings won't be applied. * @type string $default_transition_animation Default view transition animation. * @type string $header_selector CSS selector for the global header element. * @type string $main_selector CSS selector for the global main element. @@ -58,6 +60,7 @@ function plvt_get_view_transition_animation_labels(): array { */ function plvt_get_setting_default(): array { return array( + 'override_theme_config' => false, 'default_transition_animation' => 'fade', 'header_selector' => 'header', 'main_selector' => 'main', @@ -72,9 +75,11 @@ function plvt_get_setting_default(): array { * * @since 1.0.0 * - * @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 } { + * @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 } { * Stored setting value. * + * @type bool $override_theme_config Whether to override the current theme's configuration. Otherwise, + * the other frontend specific settings won't be applied. * @type string $default_transition_animation Default view transition animation. * @type string $header_selector CSS selector for the global header element. * @type string $main_selector CSS selector for the global main element. @@ -93,9 +98,11 @@ function plvt_get_stored_setting_value(): array { * @since 1.0.0 * * @param mixed $input Setting to sanitize. - * @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 } { + * @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 } { * Sanitized setting. * + * @type bool $override_theme_config Whether to override the current theme's configuration. Otherwise, + * the other frontend specific settings won't be applied. * @type string $default_transition_animation Default view transition animation. * @type string $header_selector CSS selector for the global header element. * @type string $main_selector CSS selector for the global main element. @@ -113,6 +120,10 @@ function plvt_sanitize_setting( $input ): array { $value = $default_value; + if ( isset( $input['override_theme_config'] ) && (bool) $input['override_theme_config'] ) { + $value['override_theme_config'] = true; + } + if ( isset( $input['default_transition_animation'] ) && in_array( $input['default_transition_animation'], array_keys( plvt_get_view_transition_animation_labels() ), true ) @@ -182,17 +193,22 @@ function plvt_register_setting(): void { * @global array $_wp_theme_features Theme support features added and their arguments. */ function plvt_apply_settings_to_theme_support(): void { - global $_wp_theme_features; + global $plvt_has_theme_support_with_args, $_wp_theme_features; // Bail if the feature is disabled. if ( ! isset( $_wp_theme_features['view-transitions'] ) ) { return; } + // Bail if the current theme explicitly supports view transitions and the option to override is turned off. + $options = plvt_get_stored_setting_value(); + if ( $plvt_has_theme_support_with_args && ! $options['override_theme_config'] ) { + return; + } + $args = $_wp_theme_features['view-transitions']; // Apply the settings. - $options = plvt_get_stored_setting_value(); $args['default-animation'] = $options['default_transition_animation']; $selector_options = array( 'global' => array( @@ -230,6 +246,7 @@ function plvt_add_setting_ui(): void { 'plvt_view_transitions', __( 'View Transitions', 'view-transitions' ), static function (): void { + global $plvt_has_theme_support_with_args; ?>

@@ -237,6 +254,15 @@ static function (): void {

'warning', + 'additional_classes' => array( 'inline' ), + ) + ); + } }, 'reading', array( @@ -246,6 +272,10 @@ static function (): void { ); $fields = array( + 'override_theme_config' => array( + 'title' => __( 'Override Theme Configuration', 'view-transitions' ), + 'description' => __( 'Check this to override the theme configuration with the settings below.', 'view-transitions' ), + ), 'default_transition_animation' => array( 'title' => __( 'Default Transition Animation', 'view-transitions' ), 'description' => __( 'Choose the animation that is used for the default view transition type.', 'view-transitions' ), @@ -351,7 +381,7 @@ function plvt_render_settings_field( array $args ): void { " - value="" + value="" class="regular-text code" Date: Thu, 5 Jun 2025 07:31:42 -0700 Subject: [PATCH 2/7] Only render the override UI control if relevant. --- plugins/view-transitions/includes/settings.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/view-transitions/includes/settings.php b/plugins/view-transitions/includes/settings.php index 1ed9b96321..489dbc38fd 100644 --- a/plugins/view-transitions/includes/settings.php +++ b/plugins/view-transitions/includes/settings.php @@ -242,6 +242,8 @@ function plvt_apply_settings_to_theme_support(): void { * @access private */ function plvt_add_setting_ui(): void { + global $plvt_has_theme_support_with_args; + add_settings_section( 'plvt_view_transitions', __( 'View Transitions', 'view-transitions' ), @@ -301,6 +303,12 @@ static function (): void { 'description' => __( 'Provide the CSS selector to detect the post content element.', 'view-transitions' ), ), ); + + // Do not render the checkbox to override if there is no thing to override. + if ( ! $plvt_has_theme_support_with_args ) { + unset( $fields['override_theme_config'] ); + } + foreach ( $fields as $slug => $args ) { add_settings_field( "plvt_view_transitions_{$slug}", From bd381d0db724300085a127b5ba106e9629ec793c Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 20 Jun 2025 09:44:46 -0700 Subject: [PATCH 3/7] Render new field as checkbox, reusing UI control from WP Admin view transition setting. --- .../view-transitions/includes/settings.php | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/plugins/view-transitions/includes/settings.php b/plugins/view-transitions/includes/settings.php index 1e28987958..bdac7403b8 100644 --- a/plugins/view-transitions/includes/settings.php +++ b/plugins/view-transitions/includes/settings.php @@ -124,10 +124,6 @@ function plvt_sanitize_setting( $input ): array { $value = $default_value; - if ( isset( $input['override_theme_config'] ) && (bool) $input['override_theme_config'] ) { - $value['override_theme_config'] = true; - } - if ( isset( $input['default_transition_animation'] ) && in_array( $input['default_transition_animation'], array_keys( plvt_get_view_transition_animation_labels() ), true ) @@ -151,9 +147,14 @@ function plvt_sanitize_setting( $input ): array { } } - // Sanitize "enable_admin_transitions" as a boolean. - if ( isset( $input['enable_admin_transitions'] ) ) { - $value['enable_admin_transitions'] = (bool) $input['enable_admin_transitions']; + $checkbox_options = array( + 'override_theme_config', + 'enable_admin_transitions', + ); + foreach ( $checkbox_options as $checkbox_option ) { + if ( isset( $input[ $checkbox_option ] ) ) { + $value[ $checkbox_option ] = (bool) $input[ $checkbox_option ]; + } } return $value; @@ -285,7 +286,7 @@ static function (): void { $fields = array( 'override_theme_config' => array( 'title' => __( 'Override Theme Configuration', 'view-transitions' ), - 'description' => __( 'Check this to override the theme configuration with the settings below.', 'view-transitions' ), + 'description' => __( 'Override the theme provided configuration with the settings below.', 'view-transitions' ), ), 'default_transition_animation' => array( 'title' => __( 'Default Transition Animation', 'view-transitions' ), @@ -328,8 +329,8 @@ static function (): void { 'label_for' => "plvt-view-transitions-field-{$slug}", ); - // Remove 'label_for' for checkbox field to avoid duplicate label association. - if ( 'enable_admin_transitions' === $slug ) { + // Remove 'label_for' for checkbox fields to avoid duplicate label association. + if ( 'override_theme_config' === $slug || 'enable_admin_transitions' === $slug ) { unset( $additional_args['label_for'] ); } @@ -370,6 +371,7 @@ function plvt_render_settings_field( array $args ): void { $type = 'select'; $choices = plvt_get_view_transition_animation_labels(); break; + case 'override_theme_config': case 'enable_admin_transitions': $type = 'checkbox'; $choices = array(); // Defined just for consistency. From 108c464d83f78633d4803f21b7d09a10664c4741 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Mon, 30 Jun 2025 10:49:08 -0700 Subject: [PATCH 4/7] Use info notice instead of warning notice. --- plugins/view-transitions/includes/settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/view-transitions/includes/settings.php b/plugins/view-transitions/includes/settings.php index bdac7403b8..8e096b26db 100644 --- a/plugins/view-transitions/includes/settings.php +++ b/plugins/view-transitions/includes/settings.php @@ -270,7 +270,7 @@ static function (): void { wp_admin_notice( __( 'Your theme already supports view transitions with its own adapted configuration. The settings below will override those.', 'view-transitions' ), array( - 'type' => 'warning', + 'type' => 'info', 'additional_classes' => array( 'inline' ), ) ); From c10373379c69e8ac0a42f9b80428a17d18aa40b5 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Mon, 30 Jun 2025 10:53:17 -0700 Subject: [PATCH 5/7] Add missing docs for global variables. --- plugins/view-transitions/includes/settings.php | 5 ++++- plugins/view-transitions/includes/theme.php | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/view-transitions/includes/settings.php b/plugins/view-transitions/includes/settings.php index 8e096b26db..cc6c5ff6b5 100644 --- a/plugins/view-transitions/includes/settings.php +++ b/plugins/view-transitions/includes/settings.php @@ -200,7 +200,8 @@ function plvt_register_setting(): void { * @since 1.0.0 * @access private * - * @global array $_wp_theme_features Theme support features added and their arguments. + * @global bool|null $plvt_has_theme_support_with_args Whether the current theme explicitly supports view transitions with custom config. + * @global array $_wp_theme_features Theme support features added and their arguments. */ function plvt_apply_settings_to_theme_support(): void { global $plvt_has_theme_support_with_args, $_wp_theme_features; @@ -250,6 +251,8 @@ function plvt_apply_settings_to_theme_support(): void { * * @since 1.0.0 * @access private + * + * @global bool|null $plvt_has_theme_support_with_args Whether the current theme explicitly supports view transitions with custom config. */ function plvt_add_setting_ui(): void { global $plvt_has_theme_support_with_args; diff --git a/plugins/view-transitions/includes/theme.php b/plugins/view-transitions/includes/theme.php index f0fcd059b1..be46b0f8f8 100644 --- a/plugins/view-transitions/includes/theme.php +++ b/plugins/view-transitions/includes/theme.php @@ -26,6 +26,9 @@ * * @since 1.0.0 * @access private + * + * @global bool|null $plvt_has_theme_support_with_args Whether the current theme explicitly supports view transitions with custom config. + * @global array $_wp_theme_features Theme support features added and their arguments. */ function plvt_polyfill_theme_support(): void { global $plvt_has_theme_support_with_args, $_wp_theme_features; From 2431d7a68d6dc1149dd84389bb555cd1bdab7422 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Mon, 30 Jun 2025 10:53:44 -0700 Subject: [PATCH 6/7] Fix typo. --- plugins/view-transitions/includes/settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/view-transitions/includes/settings.php b/plugins/view-transitions/includes/settings.php index cc6c5ff6b5..933034762c 100644 --- a/plugins/view-transitions/includes/settings.php +++ b/plugins/view-transitions/includes/settings.php @@ -321,7 +321,7 @@ static function (): void { ), ); - // Do not render the checkbox to override if there is no thing to override. + // Do not render the checkbox to override if there is nothing to override. if ( ! $plvt_has_theme_support_with_args ) { unset( $fields['override_theme_config'] ); } From 469b8f0ff40d3dd76d886446d140f3024d4f3c53 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Mon, 30 Jun 2025 11:00:24 -0700 Subject: [PATCH 7/7] Show separate settings section for admin view transitions controls. --- .../view-transitions/includes/settings.php | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/plugins/view-transitions/includes/settings.php b/plugins/view-transitions/includes/settings.php index 933034762c..bf77e7cde0 100644 --- a/plugins/view-transitions/includes/settings.php +++ b/plugins/view-transitions/includes/settings.php @@ -264,7 +264,7 @@ static function (): void { global $plvt_has_theme_support_with_args; ?>

- +

@@ -286,36 +286,61 @@ static function (): void { ) ); + add_settings_section( + 'plvt_admin_view_transitions', + _x( 'Admin View Transitions', 'Settings section', 'view-transitions' ), + static function (): void { + ?> +

+ +

+ '
', + 'after_section' => '
', + ) + ); + $fields = array( 'override_theme_config' => array( + 'section' => 'plvt_view_transitions', 'title' => __( 'Override Theme Configuration', 'view-transitions' ), 'description' => __( 'Override the theme provided configuration with the settings below.', 'view-transitions' ), ), 'default_transition_animation' => array( + 'section' => 'plvt_view_transitions', 'title' => __( 'Default Transition Animation', 'view-transitions' ), 'description' => __( 'Choose the animation that is used for the default view transition type.', 'view-transitions' ), ), 'header_selector' => array( + 'section' => 'plvt_view_transitions', 'title' => __( 'Header Selector', 'view-transitions' ), 'description' => __( 'Provide the CSS selector to detect the global header element.', 'view-transitions' ), ), 'main_selector' => array( + 'section' => 'plvt_view_transitions', 'title' => __( 'Main Selector', 'view-transitions' ), 'description' => __( 'Provide the CSS selector to detect the global main element.', 'view-transitions' ), ), 'post_title_selector' => array( + 'section' => 'plvt_view_transitions', 'title' => __( 'Post Title Selector', 'view-transitions' ), 'description' => __( 'Provide the CSS selector to detect the post title element.', 'view-transitions' ), ), 'post_thumbnail_selector' => array( + 'section' => 'plvt_view_transitions', 'title' => __( 'Post Thumbnail Selector', 'view-transitions' ), 'description' => __( 'Provide the CSS selector to detect the post thumbnail element.', 'view-transitions' ), ), 'post_content_selector' => array( + 'section' => 'plvt_view_transitions', 'title' => __( 'Post Content Selector', 'view-transitions' ), 'description' => __( 'Provide the CSS selector to detect the post content element.', 'view-transitions' ), ), 'enable_admin_transitions' => array( + 'section' => 'plvt_admin_view_transitions', 'title' => __( 'WP Admin', 'view-transitions' ), 'description' => __( 'Enable view transitions in the WordPress admin area.', 'view-transitions' ), ), @@ -327,6 +352,9 @@ static function (): void { } foreach ( $fields as $slug => $args ) { + $section = $args['section']; + unset( $args['section'] ); + $additional_args = array( 'field' => $slug, 'label_for' => "plvt-view-transitions-field-{$slug}", @@ -342,7 +370,7 @@ static function (): void { $args['title'], 'plvt_render_settings_field', 'reading', - 'plvt_view_transitions', + $section, array_merge( $additional_args, $args