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

How do I get URL from WP_HTTP object?

I’m not sure what you’re after here, but you can try to get the HTTP response object from the WP_HTTP_Requests_Response::get_response_object() method. Here’s an example to retrieve the url: if( ! is_wp_error( $test ) && isset( $test[‘http_response’] ) && $test[‘http_response’] instanceof \WP_HTTP_Requests_Response && method_exists( $test[‘http_response’], ‘get_response_object’ ) ) echo $test[‘http_response’]->get_response_object()->url;

Storing an XML Response (Transient)?

According to this ticket: Cannot serialize object wrapping 3rd party library structs. Must serialize the xml (to a string) and store that to session and reload the xml when restoring from session When you are storing object in transient it gets serialized and not all objects are capable of that correctly. Store textual XML data … Read more

API JSON Data in WordPress

Here is some quick first draft code for populating a dropdown from the Google Font API, I do not know about the options framework so this will not deal with that. 1. Get an API Access Key from Google Your request will need a valid key, you can follow the instruction here on how to … Read more

cURL vs WP_Http for safety?

The WP_Http class is essentially a wrapper for cURL in the same way that wpdb is essentially a wrapper for mysqli. As such, implemented properly, using cURL directly is exactly as safe as using WP_Http (since WP_Http uses cURL to make the requests). That said, implementing cURL functions optimally isn’t the easiest thing in the … Read more

Connect external web app to wordpress

There’s the XML RPC – the Remote Posting Protocol – that is already in use by WP.org Applications. What you’re searching for is wp.newPost. The API is extensible. The URL for the XML RPC is http://example.com/xmlrpc.php To send data to WP, use xmlrpc_encode_request() where the first argument would be wp.newPost and second one your arguments … Read more

POST to a REST API from a wordpress form

I don’t know of a plugin that does it in a general way; for the most part, you’ll need to build something custom for each specific API you intend to communicate with. For your purposes, the key function will be wp_remote_post(), which is a wrapper for the POST method of WP’s HTTP class. (Use this … Read more

parse XML from URL (via SOAP)

Lots of places in WordPress use xml_parse including the Atom library, the XML-RPC Library that we use, and SimplePie The oembed class uses SimpleXML. The WordPress Importer and Jetpack actually use both (Jetpack for different things, and the importer tries to use SimpleXML and falls back if it doesn’t exist). Basically, there’s nothing built into … Read more