[wp-trac] [WordPress Trac] #37843: `http_api_curl` hook no longer available for adding custom cURL options
WordPress Trac
noreply at wordpress.org
Sat Oct 1 16:43:05 UTC 2016
#37843: `http_api_curl` hook no longer available for adding custom cURL options
--------------------------+-----------------------
Reporter: ChaseWiseman | Owner: rmccue
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: 4.7
Component: HTTP API | Version: 4.6
Severity: major | Resolution:
Keywords: has-patch | Focuses:
--------------------------+-----------------------
Comment (by reidbusi):
Wouldn't this be a lot simpler?:
WP 4.6.1 wp-includes\class-http.php lines 299-314:
{{{#!php
// Setup arguments
$headers = $r['headers'];
$data = $r['body'];
$type = $r['method'];
$options = array(
'timeout' => $r['timeout'],
'useragent' => $r['user-agent'],
'blocking' => $r['blocking'],
'hooks' => new Requests_Hooks(),
);
// Ensure redirects follow browser behaviour.
$options['hooks']->register( 'requests.before_redirect',
array( get_class(), 'browser_redirect_compatibility' ) );
// Allow registration of additional Requests hooks
apply_filters( 'http_api_requests_lib_hooks',
$options['hooks'] );
}}}
Simply added one comment and a one line apply_filters call. I just tested
this approach and it works fine for me. I don't really see the need for
anything more complicated unless I am missing something?
Thus in my plugin I can just do this:
{{{#!php
if ( version_compare( $wp_version, "4.6", ">=" ) ) {
if ( class_exists( 'Requests' ) ) {
add_filter( 'http_api_requests_lib_hooks',
'rpco_http_api_requests_lib_hooks', PHP_INT_MAX, 1 );
}
} else {
add_action( 'http_api_curl', 'rpco_http_api_curl',
PHP_INT_MAX, 1 );
}
// ...
function rpco_http_api_requests_lib_hooks( $hooks ) {
$hooks->register( 'curl.before_send', 'rpco_http_api_curl',
PHP_INT_MAX );
}
}}}
Also...:
Please note: if you're hooking into this, please consider filtering
something else, as your code won't work if the user doesn't have cURL
installed. The point of WP_Http is to abstract the need for cURL away, so
using this hook is a bad idea.
Thanks for the advice, but I'd prefer if you leave that to us:
https://wordpress.org/plugins/reid-plugins-curl-options/ (the whole point
of the plugin is to be able to control PHP cURL)
e.g.:
{{{#!php
if ( function_exists( 'curl_version' ) ) {
// do cURLy stuff
} else {
echo '<p>PHP cURL is not installed or enabled on your
server, this plugin will not do anything.</p>';
}
}}}
I suppose I can test this patch, but I'm not convinced so complicated a
solution is required.
Also, like others, I would like to see this fixed before WP 4.7. In my
opinion, '''once the best solution is settled, it is worth an immediate
minor version release'''.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/37843#comment:17>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list