Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
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_admin_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
63 changes: 54 additions & 9 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 Down Expand Up @@ -136,6 +140,11 @@
}
}

// Sanitize "admin_transition_animation" as a boolean.
if ( isset( $input['admin_transition_animation'] ) ) {
$value['admin_transition_animation'] = (bool) $input['admin_transition_animation'];

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

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/settings.php#L144-L145

Added lines #L144 - L145 were not covered by tests
}

return $value;
}

Expand Down Expand Up @@ -270,19 +279,30 @@
'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 transition in WP Admin', 'view-transitions' ),
'description' => __( 'Enable view transitions in the WordPress admin area.', 'view-transitions' ),
),

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

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/settings.php#L282-L285

Added lines #L282 - L285 were not covered by tests
);
foreach ( $fields as $slug => $args ) {
$additional_args = array(
'field' => $slug,
'label_for' => "plvt-view-transitions-field-{$slug}",
);

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

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/settings.php#L288-L291

Added lines #L288 - L291 were not covered by tests

// Remove 'label_for' for checkbox field to avoid duplicate label association.
if ( 'admin_transition_animation' === $slug ) {
unset( $additional_args['label_for'] );

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

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/settings.php#L294-L295

Added lines #L294 - L295 were not covered by tests
}

add_settings_field(
"plvt_view_transitions_{$slug}",
$args['title'],
'plvt_render_settings_field',
'reading',
'plvt_view_transitions',
array_merge(
array(
'field' => $slug,
'label_for' => "plvt-view-transitions-field-{$slug}",
),
$additional_args,

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L305 was not covered by tests
$args
)
);
Expand Down Expand Up @@ -312,6 +332,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 338 in plugins/view-transitions/includes/settings.php

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/settings.php#L335-L338

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

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#L373

Added line #L373 was not covered by tests
?>
<label for="<?php echo esc_attr( "plvt-view-transitions-field-{$args['field']}" ); ?>">

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
<input
id="<?php echo esc_attr( "plvt-view-transitions-field-{$args['field']}" ); ?>"
name="<?php echo esc_attr( "plvt_view_transitions[{$args['field']}]" ); ?>"

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L377 - L378 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 384 in plugins/view-transitions/includes/settings.php

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/settings.php#L381-L384

Added lines #L381 - L384 were not covered by tests
?>
aria-describedby="<?php echo esc_attr( "plvt-view-transitions-field-{$args['field']}-description" ); ?>"

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

View check run for this annotation

Codecov / codecov/patch

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

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

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

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/includes/settings.php#L390-L393

Added lines #L390 - L393 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 399 in plugins/view-transitions/includes/settings.php

View check run for this annotation

Codecov / codecov/patch

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

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

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

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L412 was not covered by tests
?>
<p
id="<?php echo esc_attr( $args['label_for'] . '-description' ); ?>"
Expand Down
24 changes: 24 additions & 0 deletions plugins/view-transitions/includes/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,27 @@
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_admin_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'] ) || true !== $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; }
</style>
<?php

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

View check run for this annotation

Codecov / codecov/patch

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

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