File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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/**
Original file line number Diff line number Diff line change 424424
425425// Disable pings (pingbacks, trackbacks, and ping service notifications) in non-production environments.
426426add_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 );
428428add_filter ( 'xmlrpc_methods ' , 'wp_disable_xmlrpc_pingback_for_environment ' );
429429
430430add_action ( 'do_robots ' , 'do_robots ' );
Original file line number Diff line number Diff line change 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 /**
Original file line number Diff line number Diff line change 66 */
77class 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 */
Original file line number Diff line number Diff line change 88class 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 */
You can’t perform that action at this time.
0 commit comments