Skip to content

Commit de82990

Browse files
authored
Merge pull request #2025 from WordPress/enhance/view-transitions-settings
Implement basic settings for View Transitions plugin
2 parents a64d417 + 95d0b4d commit de82990

12 files changed

+530
-18
lines changed

plugins/view-transitions/hooks.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,16 @@ function plvt_render_generator(): void {
2626
add_action( 'wp_head', 'plvt_render_generator' );
2727

2828
/**
29-
* Filters related to the View Transitions functionality.
29+
* Hooks related to the key View Transitions functionality.
3030
*/
3131
add_action( 'after_setup_theme', 'plvt_polyfill_theme_support', PHP_INT_MAX );
3232
add_action( 'init', 'plvt_sanitize_view_transitions_theme_support', 1 );
3333
add_action( 'wp_enqueue_scripts', 'plvt_load_view_transitions' );
34+
35+
/**
36+
* Hooks related to the View Transitions settings.
37+
*/
38+
add_action( 'init', 'plvt_register_setting' );
39+
add_action( 'init', 'plvt_apply_settings_to_theme_support' );
40+
add_action( 'load-options-reading.php', 'plvt_add_setting_ui' );
41+
add_filter( 'plugin_action_links_' . plugin_basename( VIEW_TRANSITIONS_MAIN_FILE ), 'plvt_add_settings_action_link' );

plugins/view-transitions/includes/class-plvt-view-transition-animation-registry.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@
66
* @since 1.0.0
77
*/
88

9+
// @codeCoverageIgnoreStart
10+
if ( ! defined( 'ABSPATH' ) ) {
11+
exit; // Exit if accessed directly.
12+
}
13+
// @codeCoverageIgnoreEnd
14+
915
/**
1016
* Class representing a view transition animation registry.
1117
*
18+
* @phpstan-import-type AnimationConfig from PLVT_View_Transition_Animation
19+
*
1220
* @since 1.0.0
1321
*/
1422
final class PLVT_View_Transition_Animation_Registry {
@@ -17,7 +25,7 @@ final class PLVT_View_Transition_Animation_Registry {
1725
* Registered animation class instances, keyed by slug.
1826
*
1927
* @since 1.0.0
20-
* @var array<string, PLVT_View_Transition_Animation>
28+
* @var array<non-empty-string, PLVT_View_Transition_Animation>
2129
*/
2230
private $registered_animations = array();
2331

@@ -27,7 +35,7 @@ final class PLVT_View_Transition_Animation_Registry {
2735
* Includes the animation slug itself to avoid unnecessary conditionals.
2836
*
2937
* @since 1.0.0
30-
* @var array<string, string>
38+
* @var array<non-empty-string, non-empty-string>
3139
*/
3240
private $alias_map = array();
3341

@@ -36,7 +44,9 @@ final class PLVT_View_Transition_Animation_Registry {
3644
*
3745
* @since 1.0.0
3846
*
39-
* @param string $slug Unique animation slug.
47+
* @phpstan-param AnimationConfig $config Animation config.
48+
*
49+
* @param non-empty-string $slug Unique animation slug.
4050
* @param array<string, mixed> $config Animation configuration. See
4151
* {@see PLVT_View_Transition_Animation::__construct()} for possible
4252
* values.
@@ -132,14 +142,14 @@ public function use_animation_global_transition_names( string $alias, array $arg
132142
}
133143

134144
/**
135-
* Returns whether to apply the post specific view transition names for the given animation alias.
145+
* Returns whether to apply the post-specific view transition names for the given animation alias.
136146
*
137147
* @since 1.0.0
138148
*
139149
* @param string $alias Slug or alias to reference the animation with. May be used to alter the
140150
* animation's behavior.
141151
* @param array<string, mixed> $args Optional. Animation arguments. Default is the animation's default arguments.
142-
* @return bool True if the post specific view transition names should be applied, false otherwise.
152+
* @return bool True if the post-specific view transition names should be applied, false otherwise.
143153
*/
144154
public function use_animation_post_transition_names( string $alias, array $args = array() ): bool {
145155
if ( ! isset( $this->alias_map[ $alias ] ) ) {

plugins/view-transitions/includes/class-plvt-view-transition-animation.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,23 @@
66
* @since 1.0.0
77
*/
88

9+
// @codeCoverageIgnoreStart
10+
if ( ! defined( 'ABSPATH' ) ) {
11+
exit; // Exit if accessed directly.
12+
}
13+
// @codeCoverageIgnoreEnd
14+
915
/**
1016
* Class representing a view transition animation.
1117
*
18+
* @phpstan-type AnimationConfig array{
19+
* aliases?: non-empty-string[],
20+
* use_stylesheet?: bool|non-empty-string,
21+
* use_global_transition_names?: bool|callable(string, array<string,string>):bool,
22+
* use_post_transition_names?: bool|callable(string, array<string,string>):bool,
23+
* get_stylesheet_callback?: callable(string, string, array<string,string>):string|null
24+
* }
25+
*
1226
* @since 1.0.0
1327
* @access private
1428
*/
@@ -18,15 +32,15 @@ final class PLVT_View_Transition_Animation {
1832
* The unique animation slug.
1933
*
2034
* @since 1.0.0
21-
* @var string
35+
* @var non-empty-string
2236
*/
2337
private $slug;
2438

2539
/**
2640
* Unique aliases for the animation, if any.
2741
*
2842
* @since 1.0.0
29-
* @var string[]
43+
* @var non-empty-string[]
3044
*/
3145
private $aliases = array();
3246

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

5266
/**
53-
* Whether to apply the post specific view transition names while using this animation.
67+
* Whether to apply the post-specific view transition names while using this animation.
5468
*
5569
* @since 1.0.0
5670
* @var bool|callable
@@ -87,7 +101,9 @@ final class PLVT_View_Transition_Animation {
87101
*
88102
* @since 1.0.0
89103
*
90-
* @param string $slug Unique animation slug.
104+
* @phpstan-param AnimationConfig $config Animation config.
105+
*
106+
* @param non-empty-string $slug Unique animation slug.
91107
* @param array<string, mixed> $config {
92108
* Animation configuration.
93109
*
@@ -101,7 +117,7 @@ final class PLVT_View_Transition_Animation {
101117
* using this animation. Alternatively to a concrete value, a
102118
* callback can be specified to determine it dynamically.
103119
* Default true.
104-
* @type bool|callable $use_post_transition_names Whether to apply the post specific view transition names
120+
* @type bool|callable $use_post_transition_names Whether to apply the post-specific view transition names
105121
* while using this animation. Alternatively to a concrete
106122
* value, a callback can be specified to determine it
107123
* dynamically. Default true.
@@ -138,7 +154,7 @@ public function __construct( string $slug, array $config, array $default_args =
138154
*
139155
* @since 1.0.0
140156
*
141-
* @return string Unique animation slug.
157+
* @return non-empty-string Unique animation slug.
142158
*/
143159
public function get_slug(): string {
144160
return $this->slug;
@@ -149,7 +165,7 @@ public function get_slug(): string {
149165
*
150166
* @since 1.0.0
151167
*
152-
* @return string[] Unique aliases for the animation, or empty array if none.
168+
* @return non-empty-string[] Unique aliases for the animation, or empty array if none.
153169
*/
154170
public function get_aliases(): array {
155171
return $this->aliases;
@@ -216,14 +232,14 @@ public function use_global_transition_names( string $alias = '', array $args = a
216232
}
217233

218234
/**
219-
* Returns whether to apply the post specific view transition names while using this animation.
235+
* Returns whether to apply the post-specific view transition names while using this animation.
220236
*
221237
* @since 1.0.0
222238
*
223239
* @param string $alias Optional. Slug or alias to reference the animation with. May be used to alter
224240
* the animation's behavior. Default is the animation's slug.
225241
* @param array<string, mixed> $args Optional. Animation arguments. Default is the animation's default arguments.
226-
* @return bool True if the post specific view transition names should be applied, false otherwise.
242+
* @return bool True if the post-specific view transition names should be applied, false otherwise.
227243
*/
228244
public function use_post_transition_names( string $alias = '', array $args = array() ): bool {
229245
if ( is_bool( $this->use_post_transition_names ) ) {

plugins/view-transitions/includes/functions.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
* @since 1.0.0
77
*/
88

9+
// @codeCoverageIgnoreStart
10+
if ( ! defined( 'ABSPATH' ) ) {
11+
exit; // Exit if accessed directly.
12+
}
13+
// @codeCoverageIgnoreEnd
14+
915
/**
1016
* Gets the path to a script or stylesheet.
1117
*

0 commit comments

Comments
 (0)