How to add code to HTTP header

WordPress has the action send_headers, which you can use to make it send additional headers: add_action( ‘send_headers’, ‘add_header_acao’ ); function add_header_acao() { header( ‘Access-Control-Allow-Origin: *’ ); } See the documentation http://codex.wordpress.org/Plugin_API/Action_Reference/send_headers

Proper context for wp_remote_post()

You shouldn’t post directly to your plugin file – WordPress won’t be loaded, and you shouldn’t load it manually. Use the AJAX API and an action hook to handle it (note it doesn’t need to be an actual AJAX request): function wpse_180814_post_to_plugin( $name, $email ) { $result = wp_remote_post( admin_url( ‘admin-ajax.php’ ), array( ‘body’ => … Read more

Sending JSON Payload using Request::request_multiple()

You can’t. The requests library that comes bundled in WordPress doesn’t support this. The reason for this is that the request_multiple function only accepts these parameters: * @param array $requests Request data (array of ‘url’, ‘headers’, ‘data’, ‘options’) as per {@see Requests_Transport::request} body is not one of those parameters, which explains why your request is … Read more

Behind-the-scenes HTTP Request?

Only use wp_remote_post() if you are actually posting something. Try using wp_remote_get() with a full url $url=”http://blabla.org/mailinglist/add?” . $user_email; $results = wp_remote_get( $url ); // var_dump( $results );

What’s the best way to detect referrer?

The best way to check the referrer will depends of what are you trying to do. You can use wp_get_referer() or wp_get_original_referer(), but if you want to check the referer for security reasons you should definitely use other functions like check_admin_referer(), check_ajax_referer(), wp_referer_field() or other of the WordPress Nonces related functions.

Posting an XML request using HTTP API

I figured it out. The WordPress HTTP API was doing it’s job; my problem was with the API I was working with. I just modified my code like: $url=”https://www.testurl.com”; $xml = <<<TESTED XML HERE>>>; $response = wp_remote_post( $url, array( ‘method’ => ‘POST’, ‘timeout’ => 45, ‘redirection’ => 5, ‘httpversion’ => ‘1.0’, ‘headers’ => array( ‘Content-Type’ … Read more