Skip to content

Commit 341e216

Browse files
authored
Merge branch 'trunk' into backport/connector-is-active-callback
2 parents eee44dc + c31e5ef commit 341e216

15 files changed

Lines changed: 122 additions & 53 deletions

File tree

src/wp-admin/css/common.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3340,7 +3340,7 @@ img {
33403340
.postbox .handle-order-higher:focus,
33413341
.postbox .handle-order-lower:focus,
33423342
.postbox .handlediv:focus {
3343-
box-shadow: 0 0 0 var(--wp-admin-border-width-focus, 1.5px) var(--wp-admin-theme-color);
3343+
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus, 1.5px) var(--wp-admin-theme-color);
33443344
border-radius: 50%;
33453345
/* Only visible in Windows High Contrast mode */
33463346
outline: 2px solid transparent;

src/wp-admin/css/install.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ body {
1616
}
1717

1818
a {
19-
color: #2271b1;
19+
color: var(--wp-admin-theme-color);
2020
}
2121

2222
a:hover,
2323
a:active {
24-
color: #135e96;
24+
color: var(--wp-admin-theme-color-darker-20);
2525
}
2626

2727
a:focus {
28-
color: #043959;
28+
color: var(--wp-admin-theme-color-darker-20);
2929
border-radius: 2px;
3030
box-shadow: 0 0 0 var(--wp-admin-border-width-focus, 1.5px) var(--wp-admin-theme-color, #3858e9);
3131
/* Only visible in Windows High Contrast mode */

src/wp-includes/abilities-api/class-wp-ability.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,15 +502,27 @@ public function validate_input( $input = null ) {
502502
*
503503
* @param callable $callback The callable to invoke.
504504
* @param mixed $input Optional. The input data for the ability. Default `null`.
505-
* @return mixed The result of the callable execution.
505+
* @return mixed The result of the callable execution, or a `WP_Error` if the callback threw.
506506
*/
507507
protected function invoke_callback( callable $callback, $input = null ) {
508508
$args = array();
509509
if ( ! empty( $this->get_input_schema() ) ) {
510510
$args[] = $input;
511511
}
512512

513-
return $callback( ...$args );
513+
try {
514+
return $callback( ...$args );
515+
} catch ( Throwable $e ) {
516+
return new WP_Error(
517+
'ability_callback_exception',
518+
sprintf(
519+
/* translators: 1: Ability name, 2: Exception message. */
520+
__( 'Ability "%1$s" callback threw an exception: %2$s' ),
521+
esc_html( $this->name ),
522+
esc_html( $e->getMessage() )
523+
)
524+
);
525+
}
514526
}
515527

516528
/**

src/wp-includes/ai-client.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,22 @@
1717
* @return bool Whether AI features are supported.
1818
*/
1919
function wp_supports_ai(): bool {
20-
$is_enabled = defined( 'WP_AI_SUPPORT' ) ? WP_AI_SUPPORT : true;
20+
// Return early if AI is disabled by the current environment.
21+
if ( defined( 'WP_AI_SUPPORT' ) && ! WP_AI_SUPPORT ) {
22+
return false;
23+
}
2124

2225
/**
23-
* Filters whether the current request should use AI.
26+
* Filters whether the current request can use AI.
2427
*
2528
* This allows plugins and 3rd-party code to disable AI features on a per-request basis, or to even override explicit
2629
* preferences defined by the site owner.
2730
*
2831
* @since 7.0.0
2932
*
30-
* @param bool $is_enabled Whether the current request should use AI. Default to WP_AI_SUPPORT constant, or true if
31-
* the constant is not defined.
33+
* @param bool $is_enabled Whether AI is available. Default to true.
3234
*/
33-
return (bool) apply_filters( 'wp_supports_ai', $is_enabled );
35+
return (bool) apply_filters( 'wp_supports_ai', true );
3436
}
3537

3638
/**

src/wp-includes/functions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3975,14 +3975,14 @@ function _default_wp_die_handler( $message, $title = '', $args = array() ) {
39753975
font-size: 14px ;
39763976
}
39773977
a {
3978-
color: #2271b1;
3978+
color: #3858e9;
39793979
}
39803980
a:hover,
39813981
a:active {
3982-
color: #135e96;
3982+
color: #183ad6;
39833983
}
39843984
a:focus {
3985-
color: #043959;
3985+
color: #183ad6;
39863986
box-shadow: 0 0 0 var(--wp-admin-border-width-focus, 1.5px) var(--wp-admin-theme-color, #3858e9);
39873987
outline: 2px solid transparent;
39883988
}

tests/phpunit/tests/abilities-api/wpAbility.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,54 @@ public function test_execute_no_input() {
497497
$this->assertSame( 42, $ability->execute() );
498498
}
499499

500+
/**
501+
* Tests that an exception thrown by the execute callback is converted to a WP_Error
502+
* instead of being propagated as an uncaught throwable.
503+
*
504+
* @ticket 65058
505+
*/
506+
public function test_execute_catches_callback_exception() {
507+
$args = array_merge(
508+
self::$test_ability_properties,
509+
array(
510+
'execute_callback' => static function (): int {
511+
throw new RuntimeException( 'boom' );
512+
},
513+
)
514+
);
515+
516+
$ability = new WP_Ability( self::$test_ability_name, $args );
517+
$result = $ability->execute();
518+
519+
$this->assertWPError( $result, 'Ability::execute() should return WP_Error when the callback throws.' );
520+
$this->assertSame( 'ability_callback_exception', $result->get_error_code() );
521+
$this->assertStringContainsString( 'boom', $result->get_error_message() );
522+
}
523+
524+
/**
525+
* Tests that an exception thrown by the permission callback is converted to a WP_Error
526+
* instead of being propagated as an uncaught throwable.
527+
*
528+
* @ticket 65058
529+
*/
530+
public function test_check_permissions_catches_callback_exception() {
531+
$args = array_merge(
532+
self::$test_ability_properties,
533+
array(
534+
'permission_callback' => static function (): bool {
535+
throw new RuntimeException( 'permission exploded' );
536+
},
537+
)
538+
);
539+
540+
$ability = new WP_Ability( self::$test_ability_name, $args );
541+
$result = $ability->check_permissions();
542+
543+
$this->assertWPError( $result, 'Ability::check_permissions() should return WP_Error when the callback throws.' );
544+
$this->assertSame( 'ability_callback_exception', $result->get_error_code() );
545+
$this->assertStringContainsString( 'permission exploded', $result->get_error_message() );
546+
}
547+
500548
/**
501549
* Tests that before_execute_ability action is fired with correct parameters.
502550
*

tests/phpunit/tests/admin/includesTheme.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ public function test_get_theme_featured_list_api() {
241241
*
242242
* Differences in the structure can also trigger failure by causing PHP notices/warnings.
243243
*
244-
* @group external-http
245244
* @ticket 28121
246245
*/
247246
public function test_get_theme_featured_list_hardcoded() {

tests/phpunit/tests/blocks/wpBlockTypeRegistry.php

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* @since 5.0.0
88
*
99
* @group blocks
10+
*
11+
* @coversDefaultClass WP_Block_Type_Registry
1012
*/
1113
class Tests_Blocks_wpBlockTypeRegistry extends WP_UnitTestCase {
1214

@@ -41,57 +43,42 @@ public function tear_down() {
4143
}
4244

4345
/**
44-
* Should reject numbers
46+
* Should reject invalid block names.
4547
*
4648
* @ticket 45097
4749
*
48-
* @expectedIncorrectUsage WP_Block_Type_Registry::register
49-
*/
50-
public function test_invalid_non_string_names() {
51-
$result = $this->registry->register( 1, array() );
52-
$this->assertFalse( $result );
53-
}
54-
55-
/**
56-
* Should reject blocks without a namespace
50+
* @covers ::register
5751
*
58-
* @ticket 45097
52+
* @dataProvider data_invalid_block_names
5953
*
6054
* @expectedIncorrectUsage WP_Block_Type_Registry::register
6155
*/
62-
public function test_invalid_names_without_namespace() {
63-
$result = $this->registry->register( 'paragraph', array() );
56+
public function test_invalid_block_names( $name ) {
57+
$result = $this->registry->register( $name, array() );
6458
$this->assertFalse( $result );
6559
}
6660

6761
/**
68-
* Should reject blocks with invalid characters
69-
*
70-
* @ticket 45097
62+
* Data provider for test_invalid_block_names().
7163
*
72-
* @expectedIncorrectUsage WP_Block_Type_Registry::register
64+
* @return array<string, array{ 0: mixed }>
7365
*/
74-
public function test_invalid_characters() {
75-
$result = $this->registry->register( 'still/_doing_it_wrong', array() );
76-
$this->assertFalse( $result );
66+
public function data_invalid_block_names(): array {
67+
return array(
68+
'non-string name' => array( 1 ),
69+
'no namespace' => array( 'paragraph' ),
70+
'invalid characters' => array( 'still/_doing_it_wrong' ),
71+
'uppercase characters' => array( 'Core/Paragraph' ),
72+
);
7773
}
7874

7975
/**
80-
* Should reject blocks with uppercase characters
76+
* Should accept valid block names.
8177
*
8278
* @ticket 45097
8379
*
84-
* @expectedIncorrectUsage WP_Block_Type_Registry::register
85-
*/
86-
public function test_uppercase_characters() {
87-
$result = $this->registry->register( 'Core/Paragraph', array() );
88-
$this->assertFalse( $result );
89-
}
90-
91-
/**
92-
* Should accept valid block names
93-
*
94-
* @ticket 45097
80+
* @covers ::register
81+
* @covers ::get_registered
9582
*/
9683
public function test_register_block_type() {
9784
$name = 'core/paragraph';
@@ -106,10 +93,12 @@ public function test_register_block_type() {
10693
}
10794

10895
/**
109-
* Should fail to re-register the same block
96+
* Should fail to re-register the same block.
11097
*
11198
* @ticket 45097
11299
*
100+
* @covers ::register
101+
*
113102
* @expectedIncorrectUsage WP_Block_Type_Registry::register
114103
*/
115104
public function test_register_block_type_twice() {
@@ -125,9 +114,11 @@ public function test_register_block_type_twice() {
125114
}
126115

127116
/**
128-
* Should accept a WP_Block_Type instance
117+
* Should accept a WP_Block_Type instance.
129118
*
130119
* @ticket 45097
120+
*
121+
* @covers ::register
131122
*/
132123
public function test_register_block_type_instance() {
133124
$block_type = new WP_Fake_Block_Type( 'core/fake' );
@@ -137,10 +128,12 @@ public function test_register_block_type_instance() {
137128
}
138129

139130
/**
140-
* Unregistering should fail if a block is not registered
131+
* Unregistering should fail if a block is not registered.
141132
*
142133
* @ticket 45097
143134
*
135+
* @covers ::unregister
136+
*
144137
* @expectedIncorrectUsage WP_Block_Type_Registry::unregister
145138
*/
146139
public function test_unregister_not_registered_block() {
@@ -149,9 +142,12 @@ public function test_unregister_not_registered_block() {
149142
}
150143

151144
/**
152-
* Should unregister existing blocks
145+
* Should unregister existing blocks.
153146
*
154147
* @ticket 45097
148+
*
149+
* @covers ::unregister
150+
* @covers ::is_registered
155151
*/
156152
public function test_unregister_block_type() {
157153
$name = 'core/paragraph';
@@ -168,6 +164,8 @@ public function test_unregister_block_type() {
168164

169165
/**
170166
* @ticket 45097
167+
*
168+
* @covers ::get_all_registered
171169
*/
172170
public function test_get_all_registered() {
173171
$names = array( 'core/paragraph', 'core/image', 'core/blockquote' );

tests/phpunit/tests/multisite/getBlogDetails.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* @group ms-required
66
* @group ms-site
77
* @group multisite
8+
*
9+
* @covers ::get_blog_details
810
*/
911
class Tests_Multisite_GetBlogDetails extends WP_UnitTestCase {
1012

tests/phpunit/tests/multisite/updateBlogDetails.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* @group ms-required
55
* @group ms-site
66
* @group multisite
7+
*
8+
* @covers ::update_blog_details
79
*/
810
class Tests_Multisite_UpdateBlogDetails extends WP_UnitTestCase {
911

0 commit comments

Comments
 (0)