Skip to content

Add view transitions for WP Admin #2038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/view-transitions/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
add_action( 'after_setup_theme', 'plvt_polyfill_theme_support', PHP_INT_MAX );
add_action( 'init', 'plvt_sanitize_view_transitions_theme_support', 1 );
add_action( 'wp_enqueue_scripts', 'plvt_load_view_transitions' );
add_action( 'admin_head', 'plvt_print_view_transitions_style' );

Check warning on line 34 in plugins/view-transitions/hooks.php

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/hooks.php#L34

Added line #L34 was not covered by tests

/**
* Hooks related to the View Transitions settings.
Expand Down
44 changes: 39 additions & 5 deletions plugins/view-transitions/includes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* @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{ 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, admin_transition_animation: bool } {
* Default setting value.
*
* @type string $default_transition_animation Default view transition animation.
Expand All @@ -54,6 +54,7 @@
* @type string $post_title_selector CSS selector for the post title element.
* @type string $post_thumbnail_selector CSS selector for the post thumbnail element.
* @type string $post_content_selector CSS selector for the post content element.
* @type bool $admin_transition_animation Whether to use view transitions in the admin area.
* }
*/
function plvt_get_setting_default(): array {
Expand All @@ -64,6 +65,7 @@
'post_title_selector' => '.wp-block-post-title, .entry-title',
'post_thumbnail_selector' => '.wp-post-image',
'post_content_selector' => '.wp-block-post-content, .entry-content',
'admin_transition_animation' => false,

Check warning on line 68 in plugins/view-transitions/includes/settings.php

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/settings.php#L68

Added line #L68 was not covered by tests
);
}

Expand All @@ -72,7 +74,7 @@
*
* @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{ 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, admin_transition_animation: bool|non-empty-string } {
* Stored setting value.
*
* @type string $default_transition_animation Default view transition animation.
Expand All @@ -81,6 +83,7 @@
* @type string $post_title_selector CSS selector for the post title element.
* @type string $post_thumbnail_selector CSS selector for the post thumbnail element.
* @type string $post_content_selector CSS selector for the post content element.
* @type bool $admin_transition_animation Whether to use view transitions in the admin area.
* }
*/
function plvt_get_stored_setting_value(): array {
Expand All @@ -93,7 +96,7 @@
* @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{ 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, admin_transition_animation: bool|non-empty-string } {
* Sanitized setting.
*
* @type string $default_transition_animation Default view transition animation.
Expand All @@ -102,6 +105,7 @@
* @type string $post_title_selector CSS selector for the post title element.
* @type string $post_thumbnail_selector CSS selector for the post thumbnail element.
* @type string $post_content_selector CSS selector for the post content element.
* @type bool $admin_transition_animation Whether to use view transitions in the admin area.
* }
*/
function plvt_sanitize_setting( $input ): array {
Expand All @@ -126,6 +130,7 @@
'post_title_selector',
'post_thumbnail_selector',
'post_content_selector',
'admin_transition_animation',

Check warning on line 133 in plugins/view-transitions/includes/settings.php

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/settings.php#L133

Added line #L133 was not covered by tests
);
foreach ( $selector_options as $selector_option ) {
if ( isset( $input[ $selector_option ] ) && is_string( $input[ $selector_option ] ) ) {
Expand Down Expand Up @@ -270,6 +275,10 @@
'title' => __( 'Post Content Selector', 'view-transitions' ),
'description' => __( 'Provide the CSS selector to detect the post content element.', 'view-transitions' ),
),
'admin_transition_animation' => array(
'title' => __( 'Use transiotion in WP Admin', 'view-transitions' ),
'description' => __( 'Enable view transitions in the WordPress admin area. This will apply the default transition animation to all admin pages.', 'view-transitions' ),
),

Check warning on line 281 in plugins/view-transitions/includes/settings.php

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/settings.php#L278-L281

Added lines #L278 - L281 were not covered by tests
);
foreach ( $fields as $slug => $args ) {
add_settings_field(
Expand Down Expand Up @@ -312,6 +321,10 @@
$type = 'select';
$choices = plvt_get_view_transition_animation_labels();
break;
case 'admin_transition_animation':
$type = 'checkbox';
$choices = array(); // Defined just for consistency.
break;

Check warning on line 327 in plugins/view-transitions/includes/settings.php

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/settings.php#L324-L327

Added lines #L324 - L327 were not covered by tests
default:
$type = 'text';
$choices = array(); // Defined just for consistency.
Expand Down Expand Up @@ -346,12 +359,33 @@
?>
</select>
<?php
} elseif ( 'checkbox' === $type ) {

Check warning on line 362 in plugins/view-transitions/includes/settings.php

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/settings.php#L362

Added line #L362 was not covered by tests
?>
<label>
<input
id="<?php echo esc_attr( $args['label_for'] ); ?>"
name="<?php echo esc_attr( "plvt_view_transitions[{$args['field']}]" ); ?>"

Check warning on line 367 in plugins/view-transitions/includes/settings.php

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/settings.php#L364-L367

Added lines #L364 - L367 were not covered by tests
type="checkbox"
value="1"
<?php checked( $value, 1 ); ?>
class="regular-text code"
<?php
if ( '' !== $args['description'] ) {

Check warning on line 373 in plugins/view-transitions/includes/settings.php

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/settings.php#L370-L373

Added lines #L370 - L373 were not covered by tests
?>
aria-describedby="<?php echo esc_attr( $args['label_for'] . '-description' ); ?>"

Check warning on line 375 in plugins/view-transitions/includes/settings.php

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/settings.php#L375

Added line #L375 was not covered by tests
<?php
}
?>
>
<?php echo esc_html( $args['description'] ); ?>
</label>
<?php

Check warning on line 382 in plugins/view-transitions/includes/settings.php

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/settings.php#L379-L382

Added lines #L379 - L382 were not covered by tests
} else {
?>
<input
id="<?php echo esc_attr( $args['label_for'] ); ?>"
name="<?php echo esc_attr( "plvt_view_transitions[{$args['field']}]" ); ?>"
value="<?php echo esc_attr( $value ); ?>"
value="<?php echo esc_attr( (string) $value ); ?>"

Check warning on line 388 in plugins/view-transitions/includes/settings.php

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/settings.php#L388

Added line #L388 was not covered by tests
class="regular-text code"
<?php
if ( '' !== $args['description'] ) {
Expand All @@ -364,7 +398,7 @@
<?php
}

if ( '' !== $args['description'] ) {
if ( '' !== $args['description'] && 'checkbox' !== $type ) {

Check warning on line 401 in plugins/view-transitions/includes/settings.php

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/settings.php#L401

Added line #L401 was not covered by tests
?>
<p
id="<?php echo esc_attr( $args['label_for'] . '-description' ); ?>"
Expand Down
25 changes: 25 additions & 0 deletions plugins/view-transitions/includes/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,28 @@
wp_add_inline_script( 'plvt-view-transitions', $init_script );
wp_enqueue_script( 'plvt-view-transitions' );
}

/**
* Outputs the necessary CSS styles for view transitions.
*
* This function is responsible for printing the required inline styles
* to enable or enhance view transitions within the theme or plugin.
* It should be hooked to an appropriate action to ensure the styles
* are included in the page output.
*/
function plvt_print_view_transitions_style(): void {
if ( ! current_theme_supports( 'view-transitions' ) ) {
return;

Check warning on line 369 in plugins/view-transitions/includes/theme.php

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/theme.php#L368-L369

Added lines #L368 - L369 were not covered by tests
}

$options = plvt_get_stored_setting_value();
if ( isset( $options['admin_transition_animation'] ) && '1' !== $options['admin_transition_animation'] ) {
return;

Check warning on line 374 in plugins/view-transitions/includes/theme.php

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/theme.php#L372-L374

Added lines #L372 - L374 were not covered by tests
}
?>
<style>
@view-transition { navigation: auto; }

Check warning on line 378 in plugins/view-transitions/includes/theme.php

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/theme.php#L377-L378

Added lines #L377 - L378 were not covered by tests

</style>
<?php

Check warning on line 381 in plugins/view-transitions/includes/theme.php

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/theme.php#L380-L381

Added lines #L380 - L381 were not covered by tests
}