[wp-trac] [WordPress Trac] #52428: Create a Filter for Blocking Outgoing HTTP Calls | Single URL

WordPress Trac noreply at wordpress.org
Wed Feb 3 19:35:54 UTC 2021


#52428: Create a Filter for Blocking Outgoing HTTP Calls | Single URL
-------------------------------+------------------------------
 Reporter:  jetxpert           |       Owner:  (none)
     Type:  enhancement        |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  HTTP API           |     Version:  2.7
 Severity:  normal             |  Resolution:
 Keywords:  close 2nd-opinion  |     Focuses:
-------------------------------+------------------------------
Changes (by TimothyBlynJacobs):

 * keywords:  reporter-feedback => close 2nd-opinion


Comment:

 You could do something like this:

 {{{
 define( 'MY_BLOCKED_HOSTS', 'github.com,gitlab.com' );

 add_filter( 'pre_http_request', function ( $result, $args, $url ) {
         $hosts = wp_parse_list( MY_BLOCKED_HOSTS );

         if ( in_array( wp_parse_url( $url, PHP_URL_HOST ), $hosts, true )
 ) {
                 return new WP_Error( 'http_request_not_executed', __(
 'User has blocked requests through HTTP.' ) );
         }

         return $result;
 }, 10, 3 );
 }}}

 FYI: I'm adding the `close` keyword to indicate that this probably doesn't
 need changing in WordPress Core. The `2nd-opinion` is for another Core
 contributor to take a look and see if they disagree.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52428#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list