How to remove rest api link: in http headers?

The output is generated by the rest_output_link_header(). This function is used in two actions, wp_head and template_redirect in default-filters.php:@line234. You can remove the function from those hooks to remove the output you wanted to remove. Put the following codes in your theme’s functions.php to achieve the desired result. remove_action( ‘wp_head’, ‘rest_output_link_wp_head’, 10); remove_action( ‘template_redirect’, ‘rest_output_link_header’, … Read more

How do I mock HTTP requests for PHPUnit?

If you take a look at WP_HTTP->request() (which all related functions wrap) it provides a filter hook for the purpose of overriding making a request in favor of returning arbitrary data as response: // Allow plugins to short-circuit the request $pre = apply_filters( ‘pre_http_request’, false, $r, $url ); if ( false !== $pre ) return … Read more

How to control accept encoding on HTTP API requests?

Quite an edge case, but the accepted encoding types should be filterable nonetheless. I can see a few situations where fine, granular control over this header would be useful (as in adding an API that uses non-standard encoding). So, while there’s no stock hook for this, I have created a Trac ticket for it and … Read more

Filter any HTTP request URI?

Less than an answer, but just a list of things straight from my experience with it – maybe you’ve overlooked something. Debugging the request & its results Without diggin’ too deep into the update process, but the WP HTTP API uses the WP_HTTP class. It also offers a nice thing: A debug hook. do_action( ‘http_api_debug’, … Read more

Sending JSON string through wp_remote_post()

Try setting the data_format parameter in your request like so: $data = wp_remote_post($url, array( ‘headers’ => array(‘Content-Type’ => ‘application/json; charset=utf-8’), ‘body’ => json_encode($array_with_parameters), ‘method’ => ‘POST’, ‘data_format’ => ‘body’, )); It looks like the format may be defaulting to query, in which case WordPress attempts to format the data using http_build_query, which is giving you … Read more