Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ protected function update_check( $type ) {
add_action( 'http_api_debug', array( $this, 'capture_request_response' ), PHP_INT_MAX, 5 );
add_action( "set_site_transient_{$transient_name}", array( $this, 'capture_transient_as_set' ), PHP_INT_MAX );

// make sure another plugin isn't short circuiting the filter.
add_filter( 'pre_http_request', array( $this, 'capture_pre_http_request' ), 10, 3 );

// Query the API.
switch ( $type ) {
case 'core':
Expand All @@ -208,10 +211,33 @@ protected function update_check( $type ) {
// remove our capture hooks.
remove_action( "set_site_transient_{$transient_name}", array( $this, 'capture_transient_as_set' ), PHP_INT_MAX );
remove_action( 'http_api_debug', array( $this, 'capture_request_response' ) );
remove_filter( 'pre_http_request', array( $this, 'capture_pre_http_request' ) );

return;
}

/**
* Fix for plugins that bypass HTTP requests.
*
* @uses 'pre_http_request' filter.
*
* @param bool $result Default is false, truthy value short circuits the request.
* @param array $args HTTP request args.
* @param string $url HTTP request URL.
*
* @return bool
*/
public function capture_pre_http_request( $result, $args, $url ) {
if ( $result ) {
$this->capture_request_response( $result, 'request', 'Request', $args, $url );
if ( true === $result ) {
return new \WP_Error( 'short-circuit', 'Some developer incorrectly hooked into `pre_http_request` returning true.' );
}
}

return $result;
}

/**
* Capture the API request and response.
*
Expand Down