Changeset 62233
- Timestamp:
- 04/14/2026 11:37:02 AM (11 hours ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 2 edited
-
src/wp-includes/comment.php (modified) (1 diff)
-
src/wp-includes/default-filters.php (modified) (1 diff)
-
tests/phpunit/tests/comment/disablePingsForEnvironment.php (deleted)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment.php
r62231 r62233 3165 3165 3166 3166 /** 3167 * Determines whether pings should be disabled for the current environment.3168 *3169 * By default, all pings (outgoing pingbacks, trackbacks, and ping service3170 * notifications, as well as incoming pingbacks and trackbacks) are disabled3171 * for non-production environments ('local', 'development', 'staging').3172 *3173 * @since 7.1.03174 *3175 * @return bool True if pings should be disabled, false otherwise.3176 */3177 function wp_should_disable_pings_for_environment() {3178 $environment_type = wp_get_environment_type();3179 $should_disable = 'production' !== $environment_type;3180 3181 /**3182 * Filters whether pings should be disabled for the current environment.3183 *3184 * Returning false re-enables pings in non-production environments.3185 * Returning true disables pings even in production.3186 *3187 * @since 7.1.03188 *3189 * @param bool $should_disable Whether pings should be disabled. Default true3190 * for non-production environments, false for production.3191 * @param string $environment_type The current environment type as returned by3192 * wp_get_environment_type().3193 */3194 return apply_filters( 'wp_should_disable_pings_for_environment', $should_disable, $environment_type );3195 }3196 3197 /**3198 * Removes outgoing ping callbacks in non-production environments.3199 *3200 * Hooked to `do_all_pings` at priority 1 so it runs before the default3201 * priority 10 callbacks. Does not remove `do_all_enclosures`.3202 *3203 * @since 7.1.03204 */3205 function wp_maybe_disable_outgoing_pings_for_environment() {3206 if ( wp_should_disable_pings_for_environment() ) {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' );3210 }3211 }3212 3213 /**3214 * Rejects incoming trackbacks in non-production environments.3215 *3216 * Hooked to `pre_trackback_post` which fires in `wp-trackback.php` before the3217 * trackback is processed. Calls `trackback_response()` which sends an XML error3218 * response and terminates the request.3219 *3220 * @since 7.1.03221 */3222 function wp_maybe_disable_trackback_for_environment() {3223 if ( wp_should_disable_pings_for_environment() ) {3224 trackback_response( 1, __( 'Trackbacks are disabled in non-production environments.' ) );3225 }3226 }3227 3228 /**3229 * Removes the pingback XML-RPC method in non-production environments.3230 *3231 * @since 7.1.03232 *3233 * @param string[] $methods An array of XML-RPC methods, keyed by their methodName.3234 * @return string[] Modified array of XML-RPC methods.3235 */3236 function wp_maybe_disable_xmlrpc_pingback_for_environment( $methods ) {3237 if ( wp_should_disable_pings_for_environment() ) {3238 unset( $methods['pingback.ping'] );3239 }3240 3241 return $methods;3242 }3243 3244 /**3245 3167 * Pings back the links found in a post. 3246 3168 * -
trunk/src/wp-includes/default-filters.php
r62231 r62233 422 422 add_action( 'do_all_pings', 'do_all_trackbacks', 10, 0 ); 423 423 add_action( 'do_all_pings', 'generic_ping', 10, 0 ); 424 425 // Disable pings (pingbacks, trackbacks, and ping service notifications) in non-production environments.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' );429 430 424 add_action( 'do_robots', 'do_robots' ); 431 425 add_action( 'do_favicon', 'do_favicon' );
Note: See TracChangeset
for help on using the changeset viewer.