[wp-trac] [WordPress Trac] #40142: WP Remote Remaining Methods
WordPress Trac
noreply at wordpress.org
Mon Jun 5 09:34:44 UTC 2017
#40142: WP Remote Remaining Methods
-------------------------------------------------+-------------------------
Reporter: bhubbard | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting
Component: HTTP API | Review
Severity: normal | Version: 2.7
Keywords: has-patch 2nd-opinion needs-unit- | Resolution:
tests | Focuses:
-------------------------------------------------+-------------------------
Comment (by dd32):
Personally I don't think we should add wrappers for each potential method.
`GET` and `POST` are used enough to warrant a top-level function, but the
long tail can probably be catered to better.
We made a huge mistake when we added the `wp_remote_post()` method IMHO,
although it sets the `method` parameter it didn't make it easier to add
the body to the request, resulting in developers having to specify `$args`
still.
Perhaps a new generic function could be offered which spells out the
request a little simpler, I don't think they're needed on the `WP_HTTP`
class directly though as that's not an API developers should be
interacting with.
{{{
function wp_safe_remote_SOMETHING(
$method = 'GET',
$url = '',
$args,
$body = null
) {
$args['method'] = $method;
$args['body'] = $body;
$args['reject_unsafe_urls'] = true;
$http = _wp_http_get_object();
return $http->request( $url, $args );
}
}}}
usage:
{{{ $request = wp_safe_remote_SOMETHING( 'PURGE', 'https://dd32.id.au/',
array( 'timeout' => 1 ), array( 'force' => 1 ) ); }}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40142#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list