[wp-trac] [WordPress Trac] #64837: Disable pings/trackbacks for local, development, and staging environments
WordPress Trac
noreply at wordpress.org
Wed Mar 11 05:12:32 UTC 2026
#64837: Disable pings/trackbacks for local, development, and staging environments
------------------------------+------------------------------
Reporter: cagrimmett | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Pings/Trackbacks | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
------------------------------+------------------------------
Comment (by khushipatel15):
Inlcude this code snippet in wp-includes/default-filters.php folder and
perform unit test.
<?php
/**
* Core environment-specific filters for pingbacks and trackbacks.
*
* @package WordPress
* @subpackage Core
* @since 6.6.0
*/
/**
* Conditionally disables outgoing pingbacks/trackbacks in non-production
environments.
*
* Prevents the dispatch of pingbacks/trackbacks when the environment type
is 'local',
* 'development', or 'staging', unless overridden by a filter.
*
* @since 6.6.0
*
* @param bool $send Whether to send the pingback. Default true.
* @return bool True to send, false to prevent sending.
*/
function wp_disable_outgoing_pings_trackbacks_in_dev_envs( $send ) {
$env_type = wp_get_environment_type();
/**
* Filters whether to prevent WordPress from disabling
pings/trackbacks
* in non-production environments.
*
* Returning `true` will allow pings and trackbacks to function
normally
* even when the environment type is 'local', 'development', or
'staging'.
* This filter can be used to re-enable pings/trackbacks if they
are
* intentionally needed in a development environment.
*
* @since 6.6.0
*
* @param bool $override If `true`, the disablement logic is
skipped. Default `false`.
* @param string $env_type The current environment type (e.g.,
'local', 'development', 'staging', 'production').
*/
if ( apply_filters(
'wp_override_disable_pings_trackbacks_in_dev_envs', false, $env_type ) ) {
return $send;
}
if ( in_array( $env_type, array( 'local', 'development', 'staging'
), true ) ) {
return false; // Prevent outgoing pingbacks.
}
return $send;
}
add_filter( 'pre_pingback_send',
'wp_disable_outgoing_pings_trackbacks_in_dev_envs' );
/**
* Conditionally disables incoming pingbacks/trackbacks in non-production
environments
* by removing the 'pingback.ping' XML-RPC method.
*
* Prevents WordPress from processing incoming pingbacks/trackbacks when
the
* environment type is 'local', 'development', or 'staging', unless
overridden by a filter.
*
* @since 6.6.0
*
* @param array<string, callable> $methods Associative array of XML-RPC
methods.
* @return array<string, callable> Modified associative array of XML-RPC
methods.
*/
function wp_disable_incoming_pings_trackbacks_in_dev_envs( $methods ) {
$env_type = wp_get_environment_type();
/** This filter is documented in
wp_disable_outgoing_pings_trackbacks_in_dev_envs() */
if ( apply_filters(
'wp_override_disable_pings_trackbacks_in_dev_envs', false, $env_type ) ) {
return $methods;
}
if ( in_array( $env_type, array( 'local', 'development', 'staging'
), true ) ) {
// Remove the 'pingback.ping' method to disable incoming
pingbacks.
if ( isset( $methods['pingback.ping'] ) ) {
unset( $methods['pingback.ping'] );
}
}
return $methods;
}
add_filter( 'xmlrpc_methods',
'wp_disable_incoming_pings_trackbacks_in_dev_envs' );
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64837#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list