Skip to content

Commit 4c0cc64

Browse files
committed
Replace pings_open filter with pre_trackback_post hook
The global pings_open filter suppressed the X-Pingback header which wp_install_maybe_enable_pretty_permalinks() uses to verify rewrite rules, breaking pretty permalinks on fresh non-production installs. Use pre_trackback_post action to reject incoming trackbacks instead, which only affects the wp-trackback.php entry point. Reverts the pingsOpen and sendHeaders test changes since pings_open is no longer filtered.
1 parent efa3dfb commit 4c0cc64

5 files changed

Lines changed: 17 additions & 35 deletions

File tree

src/wp-includes/comment.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3212,21 +3212,23 @@ function wp_disable_outgoing_pings_for_environment() {
32123212
}
32133213

32143214
/**
3215-
* Closes pings for posts in non-production environments.
3215+
* Rejects incoming trackbacks in non-production environments.
3216+
*
3217+
* Hooked to `pre_trackback_post` which fires before the trackback is processed.
3218+
* Sends an error response and exits if pings are disabled for the environment.
32163219
*
32173220
* @since 6.9.0
32183221
* @access private
32193222
*
3220-
* @param bool $pings_open Whether the post is open for pings.
3221-
* @param int $post_id The post ID.
3222-
* @return bool False if pings are disabled for the environment, otherwise the original value.
3223+
* @param int $post_id Post ID related to the trackback.
3224+
* @param string $trackback_url Trackback URL.
32233225
*/
3224-
function wp_disable_pings_open_for_environment( $pings_open, $post_id ) {
3226+
function wp_disable_trackback_for_environment( $post_id, $trackback_url ) {
32253227
if ( wp_should_disable_pings_for_environment() ) {
3226-
return false;
3228+
if ( function_exists( 'trackback_response' ) ) {
3229+
trackback_response( 1, __( 'Sorry, trackbacks are closed for this item.' ) );
3230+
}
32273231
}
3228-
3229-
return $pings_open;
32303232
}
32313233

32323234
/**

src/wp-includes/default-filters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@
424424

425425
// Disable pings (pingbacks, trackbacks, and ping service notifications) in non-production environments.
426426
add_action( 'do_all_pings', 'wp_disable_outgoing_pings_for_environment', 1, 0 );
427-
add_filter( 'pings_open', 'wp_disable_pings_open_for_environment', 10, 2 );
427+
add_action( 'pre_trackback_post', 'wp_disable_trackback_for_environment', 10, 2 );
428428
add_filter( 'xmlrpc_methods', 'wp_disable_xmlrpc_pingback_for_environment' );
429429

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

tests/phpunit/tests/comment/disablePingsForEnvironment.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @group comment
77
* @covers ::wp_should_disable_pings_for_environment
88
* @covers ::wp_disable_outgoing_pings_for_environment
9-
* @covers ::wp_disable_pings_open_for_environment
9+
* @covers ::wp_disable_trackback_for_environment
1010
* @covers ::wp_disable_xmlrpc_pingback_for_environment
1111
*
1212
* @ticket 64837
@@ -182,27 +182,21 @@ public function test_outgoing_pings_preserved_in_production() {
182182
/**
183183
* @ticket 64837
184184
*/
185-
public function test_pings_open_returns_false_in_non_production() {
186-
putenv( 'WP_ENVIRONMENT_TYPE=local' );
187-
188-
$post = self::factory()->post->create_and_get(
189-
array( 'ping_status' => 'open' )
190-
);
191-
192-
$this->assertFalse( wp_disable_pings_open_for_environment( true, $post->ID ) );
185+
public function test_trackback_hook_registered_in_non_production() {
186+
$this->assertSame( 10, has_action( 'pre_trackback_post', 'wp_disable_trackback_for_environment' ) );
193187
}
194188

195189
/**
196190
* @ticket 64837
197191
*/
198-
public function test_pings_open_unchanged_in_production() {
199-
putenv( 'WP_ENVIRONMENT_TYPE=production' );
192+
public function test_pings_open_unaffected_by_environment() {
193+
putenv( 'WP_ENVIRONMENT_TYPE=local' );
200194

201195
$post = self::factory()->post->create_and_get(
202196
array( 'ping_status' => 'open' )
203197
);
204198

205-
$this->assertTrue( wp_disable_pings_open_for_environment( true, $post->ID ) );
199+
$this->assertTrue( pings_open( $post ) );
206200
}
207201

208202
/**

tests/phpunit/tests/comment/pingsOpen.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
*/
77
class Tests_Comment_PingsOpen extends WP_UnitTestCase {
88

9-
public function set_up() {
10-
parent::set_up();
11-
12-
// Remove the environment-based filter to test core pings_open() behavior in isolation.
13-
remove_filter( 'pings_open', 'wp_disable_pings_open_for_environment' );
14-
}
15-
169
/**
1710
* @ticket 54159
1811
*/

tests/phpunit/tests/wp/sendHeaders.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@
88
class Tests_WP_SendHeaders extends WP_UnitTestCase {
99
protected $headers_sent = array();
1010

11-
public function set_up() {
12-
parent::set_up();
13-
14-
// Remove the environment-based filter to test core behavior in isolation.
15-
remove_filter( 'pings_open', 'wp_disable_pings_open_for_environment' );
16-
}
17-
1811
/**
1912
* @ticket 56068
2013
*/

0 commit comments

Comments
 (0)