Skip to content

Commit 3ba7f52

Browse files
committed
Address second round of PR review feedback
1 parent f5961fc commit 3ba7f52

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

src/wp-includes/comment.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3201,13 +3201,12 @@ function wp_should_disable_pings_for_environment() {
32013201
* priority 10 callbacks. Does not remove `do_all_enclosures`.
32023202
*
32033203
* @since 7.1.0
3204-
* @access private
32053204
*/
3206-
function wp_disable_outgoing_pings_for_environment() {
3205+
function wp_maybe_disable_outgoing_pings_for_environment() {
32073206
if ( wp_should_disable_pings_for_environment() ) {
3208-
remove_action( 'do_all_pings', 'do_all_pingbacks', 10 );
3209-
remove_action( 'do_all_pings', 'do_all_trackbacks', 10 );
3210-
remove_action( 'do_all_pings', 'generic_ping', 10 );
3207+
remove_action( 'do_all_pings', 'do_all_pingbacks' );
3208+
remove_action( 'do_all_pings', 'do_all_trackbacks' );
3209+
remove_action( 'do_all_pings', 'generic_ping' );
32113210
}
32123211
}
32133212

@@ -3219,9 +3218,8 @@ function wp_disable_outgoing_pings_for_environment() {
32193218
* response and terminates the request.
32203219
*
32213220
* @since 7.1.0
3222-
* @access private
32233221
*/
3224-
function wp_disable_trackback_for_environment() {
3222+
function wp_maybe_disable_trackback_for_environment() {
32253223
if ( wp_should_disable_pings_for_environment() ) {
32263224
trackback_response( 1, __( 'Trackbacks are disabled in non-production environments.' ) );
32273225
}
@@ -3231,12 +3229,11 @@ function wp_disable_trackback_for_environment() {
32313229
* Removes the pingback XML-RPC method in non-production environments.
32323230
*
32333231
* @since 7.1.0
3234-
* @access private
32353232
*
32363233
* @param string[] $methods An array of XML-RPC methods, keyed by their methodName.
32373234
* @return string[] Modified array of XML-RPC methods.
32383235
*/
3239-
function wp_disable_xmlrpc_pingback_for_environment( $methods ) {
3236+
function wp_maybe_disable_xmlrpc_pingback_for_environment( $methods ) {
32403237
if ( wp_should_disable_pings_for_environment() ) {
32413238
unset( $methods['pingback.ping'] );
32423239
}

src/wp-includes/default-filters.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,9 @@
423423
add_action( 'do_all_pings', 'generic_ping', 10, 0 );
424424

425425
// Disable pings (pingbacks, trackbacks, and ping service notifications) in non-production environments.
426-
add_action( 'do_all_pings', 'wp_disable_outgoing_pings_for_environment', 1, 0 );
427-
add_action( 'pre_trackback_post', 'wp_disable_trackback_for_environment', 10, 0 );
428-
add_filter( 'xmlrpc_methods', 'wp_disable_xmlrpc_pingback_for_environment' );
426+
add_action( 'do_all_pings', 'wp_maybe_disable_outgoing_pings_for_environment', 1, 0 );
427+
add_action( 'pre_trackback_post', 'wp_maybe_disable_trackback_for_environment', 10, 0 );
428+
add_filter( 'xmlrpc_methods', 'wp_maybe_disable_xmlrpc_pingback_for_environment' );
429429

430430
add_action( 'do_robots', 'do_robots' );
431431
add_action( 'do_favicon', 'do_favicon' );

tests/phpunit/tests/comment/disablePingsForEnvironment.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
*
66
* @group comment
77
* @covers ::wp_should_disable_pings_for_environment
8-
* @covers ::wp_disable_outgoing_pings_for_environment
9-
* @covers ::wp_disable_trackback_for_environment
10-
* @covers ::wp_disable_xmlrpc_pingback_for_environment
8+
* @covers ::wp_maybe_disable_outgoing_pings_for_environment
9+
* @covers ::wp_maybe_disable_trackback_for_environment
10+
* @covers ::wp_maybe_disable_xmlrpc_pingback_for_environment
1111
*
1212
* @ticket 64837
1313
*/
@@ -118,7 +118,7 @@ public function test_outgoing_pingbacks_removed_in_non_production() {
118118
add_action( 'do_all_pings', 'do_all_pingbacks', 10, 0 );
119119

120120
// Fire the priority-1 callback.
121-
wp_disable_outgoing_pings_for_environment();
121+
wp_maybe_disable_outgoing_pings_for_environment();
122122

123123
$this->assertFalse( has_action( 'do_all_pings', 'do_all_pingbacks' ) );
124124
}
@@ -131,7 +131,7 @@ public function test_outgoing_trackbacks_removed_in_non_production() {
131131

132132
add_action( 'do_all_pings', 'do_all_trackbacks', 10, 0 );
133133

134-
wp_disable_outgoing_pings_for_environment();
134+
wp_maybe_disable_outgoing_pings_for_environment();
135135

136136
$this->assertFalse( has_action( 'do_all_pings', 'do_all_trackbacks' ) );
137137
}
@@ -144,7 +144,7 @@ public function test_outgoing_generic_ping_removed_in_non_production() {
144144

145145
add_action( 'do_all_pings', 'generic_ping', 10, 0 );
146146

147-
wp_disable_outgoing_pings_for_environment();
147+
wp_maybe_disable_outgoing_pings_for_environment();
148148

149149
$this->assertFalse( has_action( 'do_all_pings', 'generic_ping' ) );
150150
}
@@ -157,9 +157,9 @@ public function test_enclosures_not_removed_in_non_production() {
157157

158158
add_action( 'do_all_pings', 'do_all_enclosures', 10, 0 );
159159

160-
wp_disable_outgoing_pings_for_environment();
160+
wp_maybe_disable_outgoing_pings_for_environment();
161161

162-
$this->assertSame( 10, has_action( 'do_all_pings', 'do_all_enclosures' ) );
162+
$this->assertTrue( has_action( 'do_all_pings', 'do_all_enclosures', 10 ) );
163163
}
164164

165165
/**
@@ -172,18 +172,18 @@ public function test_outgoing_pings_preserved_in_production() {
172172
add_action( 'do_all_pings', 'do_all_trackbacks', 10, 0 );
173173
add_action( 'do_all_pings', 'generic_ping', 10, 0 );
174174

175-
wp_disable_outgoing_pings_for_environment();
175+
wp_maybe_disable_outgoing_pings_for_environment();
176176

177-
$this->assertSame( 10, has_action( 'do_all_pings', 'do_all_pingbacks' ), 'do_all_pingbacks should still be hooked.' );
178-
$this->assertSame( 10, has_action( 'do_all_pings', 'do_all_trackbacks' ), 'do_all_trackbacks should still be hooked.' );
179-
$this->assertSame( 10, has_action( 'do_all_pings', 'generic_ping' ), 'generic_ping should still be hooked.' );
177+
$this->assertTrue( has_action( 'do_all_pings', 'do_all_pingbacks', 10 ), 'do_all_pingbacks should still be hooked at priority 10.' );
178+
$this->assertTrue( has_action( 'do_all_pings', 'do_all_trackbacks', 10 ), 'do_all_trackbacks should still be hooked at priority 10.' );
179+
$this->assertTrue( has_action( 'do_all_pings', 'generic_ping', 10 ), 'generic_ping should still be hooked at priority 10.' );
180180
}
181181

182182
/**
183183
* @ticket 64837
184184
*/
185185
public function test_trackback_hook_is_registered() {
186-
$this->assertSame( 10, has_action( 'pre_trackback_post', 'wp_disable_trackback_for_environment' ) );
186+
$this->assertTrue( has_action( 'pre_trackback_post', 'wp_maybe_disable_trackback_for_environment', 10 ) );
187187
}
188188

189189
/**
@@ -211,7 +211,7 @@ public function test_xmlrpc_pingback_removed_in_non_production() {
211211
'wp.getUsersBlogs' => 'this:wp_getUsersBlogs',
212212
);
213213

214-
$filtered = wp_disable_xmlrpc_pingback_for_environment( $methods );
214+
$filtered = wp_maybe_disable_xmlrpc_pingback_for_environment( $methods );
215215

216216
$this->assertArrayNotHasKey( 'pingback.ping', $filtered );
217217
}
@@ -227,7 +227,7 @@ public function test_xmlrpc_pingback_preserved_in_production() {
227227
'wp.getUsersBlogs' => 'this:wp_getUsersBlogs',
228228
);
229229

230-
$filtered = wp_disable_xmlrpc_pingback_for_environment( $methods );
230+
$filtered = wp_maybe_disable_xmlrpc_pingback_for_environment( $methods );
231231

232232
$this->assertArrayHasKey( 'pingback.ping', $filtered );
233233
}
@@ -245,7 +245,7 @@ public function test_xmlrpc_other_methods_preserved_in_non_production() {
245245
'wp.getPost' => 'this:wp_getPost',
246246
);
247247

248-
$filtered = wp_disable_xmlrpc_pingback_for_environment( $methods );
248+
$filtered = wp_maybe_disable_xmlrpc_pingback_for_environment( $methods );
249249

250250
$this->assertArrayHasKey( 'pingback.extensions.getPingbacks', $filtered );
251251
$this->assertArrayHasKey( 'wp.getUsersBlogs', $filtered );

0 commit comments

Comments
 (0)