Skip to content

Implement basic settings for View Transitions plugin #2025

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 14 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
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
10 changes: 9 additions & 1 deletion plugins/view-transitions/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@
add_action( 'wp_head', 'plvt_render_generator' );

/**
* Filters related to the View Transitions functionality.
* Hooks related to the key View Transitions functionality.
*/
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' );

/**
* Hooks related to the View Transitions settings.
*/
add_action( 'init', 'plvt_register_setting' );
add_action( 'init', 'plvt_apply_settings_to_theme_support' );
add_action( 'load-options-reading.php', 'plvt_add_setting_ui' );
add_filter( 'plugin_action_links_' . plugin_basename( VIEW_TRANSITIONS_MAIN_FILE ), 'plvt_add_settings_action_link' );

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

View check run for this annotation

Codecov / codecov/patch

plugins/view-transitions/hooks.php#L38-L41

Added lines #L38 - L41 were not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@
* @since 1.0.0
*/

// @codeCoverageIgnoreStart
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
// @codeCoverageIgnoreEnd

/**
* Class representing a view transition animation registry.
*
* @phpstan-import-type AnimationConfig from PLVT_View_Transition_Animation
*
* @since 1.0.0
*/
final class PLVT_View_Transition_Animation_Registry {
Expand All @@ -17,7 +25,7 @@ final class PLVT_View_Transition_Animation_Registry {
* Registered animation class instances, keyed by slug.
*
* @since 1.0.0
* @var array<string, PLVT_View_Transition_Animation>
* @var array<non-empty-string, PLVT_View_Transition_Animation>
*/
private $registered_animations = array();

Expand All @@ -27,7 +35,7 @@ final class PLVT_View_Transition_Animation_Registry {
* Includes the animation slug itself to avoid unnecessary conditionals.
*
* @since 1.0.0
* @var array<string, string>
* @var array<non-empty-string, non-empty-string>
*/
private $alias_map = array();

Expand All @@ -36,7 +44,9 @@ final class PLVT_View_Transition_Animation_Registry {
*
* @since 1.0.0
*
* @param string $slug Unique animation slug.
* @phpstan-param AnimationConfig $config Animation config.
*
* @param non-empty-string $slug Unique animation slug.
* @param array<string, mixed> $config Animation configuration. See
* {@see PLVT_View_Transition_Animation::__construct()} for possible
* values.
Expand Down Expand Up @@ -132,14 +142,14 @@ public function use_animation_global_transition_names( string $alias, array $arg
}

/**
* Returns whether to apply the post specific view transition names for the given animation alias.
* Returns whether to apply the post-specific view transition names for the given animation alias.
*
* @since 1.0.0
*
* @param string $alias Slug or alias to reference the animation with. May be used to alter the
* animation's behavior.
* @param array<string, mixed> $args Optional. Animation arguments. Default is the animation's default arguments.
* @return bool True if the post specific view transition names should be applied, false otherwise.
* @return bool True if the post-specific view transition names should be applied, false otherwise.
*/
public function use_animation_post_transition_names( string $alias, array $args = array() ): bool {
if ( ! isset( $this->alias_map[ $alias ] ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,23 @@
* @since 1.0.0
*/

// @codeCoverageIgnoreStart
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
// @codeCoverageIgnoreEnd

/**
* Class representing a view transition animation.
*
* @phpstan-type AnimationConfig array{
* aliases?: non-empty-string[],
* use_stylesheet?: bool|non-empty-string,
* use_global_transition_names?: bool|callable(string, array<string,string>):bool,
* use_post_transition_names?: bool|callable(string, array<string,string>):bool,
* get_stylesheet_callback?: callable(string, string, array<string,string>):string|null
* }
*
* @since 1.0.0
* @access private
*/
Expand All @@ -18,15 +32,15 @@ final class PLVT_View_Transition_Animation {
* The unique animation slug.
*
* @since 1.0.0
* @var string
* @var non-empty-string
*/
private $slug;

/**
* Unique aliases for the animation, if any.
*
* @since 1.0.0
* @var string[]
* @var non-empty-string[]
*/
private $aliases = array();

Expand All @@ -50,7 +64,7 @@ final class PLVT_View_Transition_Animation {
private $use_global_transition_names = true;

/**
* Whether to apply the post specific view transition names while using this animation.
* Whether to apply the post-specific view transition names while using this animation.
*
* @since 1.0.0
* @var bool|callable
Expand Down Expand Up @@ -87,7 +101,9 @@ final class PLVT_View_Transition_Animation {
*
* @since 1.0.0
*
* @param string $slug Unique animation slug.
* @phpstan-param AnimationConfig $config Animation config.
*
* @param non-empty-string $slug Unique animation slug.
* @param array<string, mixed> $config {
* Animation configuration.
*
Expand All @@ -101,7 +117,7 @@ final class PLVT_View_Transition_Animation {
* using this animation. Alternatively to a concrete value, a
* callback can be specified to determine it dynamically.
* Default true.
* @type bool|callable $use_post_transition_names Whether to apply the post specific view transition names
* @type bool|callable $use_post_transition_names Whether to apply the post-specific view transition names
* while using this animation. Alternatively to a concrete
* value, a callback can be specified to determine it
* dynamically. Default true.
Expand Down Expand Up @@ -138,7 +154,7 @@ public function __construct( string $slug, array $config, array $default_args =
*
* @since 1.0.0
*
* @return string Unique animation slug.
* @return non-empty-string Unique animation slug.
*/
public function get_slug(): string {
return $this->slug;
Expand All @@ -149,7 +165,7 @@ public function get_slug(): string {
*
* @since 1.0.0
*
* @return string[] Unique aliases for the animation, or empty array if none.
* @return non-empty-string[] Unique aliases for the animation, or empty array if none.
*/
public function get_aliases(): array {
return $this->aliases;
Expand Down Expand Up @@ -216,14 +232,14 @@ public function use_global_transition_names( string $alias = '', array $args = a
}

/**
* Returns whether to apply the post specific view transition names while using this animation.
* Returns whether to apply the post-specific view transition names while using this animation.
*
* @since 1.0.0
*
* @param string $alias Optional. Slug or alias to reference the animation with. May be used to alter
* the animation's behavior. Default is the animation's slug.
* @param array<string, mixed> $args Optional. Animation arguments. Default is the animation's default arguments.
* @return bool True if the post specific view transition names should be applied, false otherwise.
* @return bool True if the post-specific view transition names should be applied, false otherwise.
*/
public function use_post_transition_names( string $alias = '', array $args = array() ): bool {
if ( is_bool( $this->use_post_transition_names ) ) {
Expand Down
6 changes: 6 additions & 0 deletions plugins/view-transitions/includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
* @since 1.0.0
*/

// @codeCoverageIgnoreStart
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
// @codeCoverageIgnoreEnd

/**
* Gets the path to a script or stylesheet.
*
Expand Down
Loading