Tag Info

Hot answers tagged

7

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', $response, 'response', $class, ...


6

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 get one: https://developers.google.com/webfonts/docs/developer_api It's ...


6

Check out download_url() - it's only loaded in the admin, so you'll have to include it (or write your own) if needed on the front-end. From download_url() you can use: $response = wp_remote_get( TCS_CPDF_REMOTE_ZIP, array( 'timeout' => 300, 'stream' => true, 'filename' => TCS_CPDF_LOCAL_ZIP ) );


5

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 ...


5

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 in transient ...


4

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 submitted a patch. If you voice support on ...


4

Based on @kaiser’s useful answer I have written some code that seems to work well. That is the reason why I marked it as The Answer. Let me explain my solution … The logic When a request it sent through the API is runs through WP_Http::request(). That’s the method with … @todo Refactor this code. … in its header. I couldn’t agree more. Now, there ...


4

The proxy settings work just like a regular HTTP requests but in this case obviously routed through a proxy. In terms of WordPress the API's transport layers all support proxy connections(fsockopen, fopen, cURL, ). The things about proxy configurations are they come in several flavors and each setup is different so it makes answering this difficult, it ...


4

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 $pre;


3

Update & the internal WP HTTP API A slightly modified version of my answer to this question, but also as a plugin that shows how it could work. Note: The code is not tested - I don't know your server setup, etc. - and just written out of my head. You'll have to test it, find the proper position for merging the arguments and set your URL, etc. The ...


3

As a general note, there's the http-api (you've already used it to tag your question) that has an archive. WP HTTP API Here's a list of "How to"-answers about the HTTP API basics chose the right protocol filter the request uri/url. download a file from a remote location deactivate HTTP requests Post Data Yes, you just use wp_insert_post() and similar ...


3

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' => ...


3

Try this in wp-config.php: define( 'WP_HTTP_BLOCK_EXTERNAL', true );


3

It does not. Some functionality actively uses HTTP API and is cached - feed fetching, updates checking. But caching is always implemented at wrapper's level. Making HTTP request without context is too unspecific to make educated guess about caching needs (one minute or one hour).


2

So far as I know, it's available to use. Your site already hits it a few times each day for plugin updates, theme updates, etc. It's not really well-documented, though ... so when you start building your code, please document what calls you're using and how you're using them in the Codex so everyone else can benefit.


2

There is very little documentation, the link in EAMann's comment is the best I have seen. To grab plugin specific data you can use the following url and it will return XML with a lot of info. http://api.wordpress.org/plugins/info/1.0/plugin-name.xml For example: http://api.wordpress.org/plugins/info/1.0/akismet.xml


2

'test:8888/?p=1' isn't a valid URL. Try 'http://test:8888/?p=1' instead.


2

PHP allows you to send header information using the header() command. More specific to WordPress is the send_headers action hook. Also: always remember that you have to send all your headers before any output is sent to the screen.


2

Short answer: No, there's no hook for that. Long answer: You could possibly submit a patch at WordPress Trac, if you really need to adjust this option. Personally, I didn't ever had problemes with WP_Http_Encoding::accept_encoding() and the question you mentioned could be answered by manually gzinflate() the response. IMHO, this seems to be the only ...


2

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.


2

There is no filter named "http_response_timeout" in the WordPress core. Where are you finding this filter name from? The timeout parameter as passed to a wp_remote call has a default of five seconds, and that default can be changed using the "http_request_timeout" filter, which is a different name than you used. Maybe you're just using the wrong word?


2

Take the results you get from a valid or invalid request, serialize them into strings, then add code that unserializes the string back into the variable instead of doing the request.


2

In order to isolate your code further, I would wrap the wp_remote_get etc calls in an interface with two implementations. One implementation calls wp_remote_get, and the other returns test data. Using a tool such as runkit in this situation sidesteps the actual problem you have, which is that your code and the APIs are too tightly coupled, and a level of ...


1

In one (two) word(s): Mock Data. PHPUnit got getMock() available exactly for that. As the other answers already have perfectly summoned… where to get valid mock data (Otto) - make sure you occasionally fetch fresh data and where to intercept the data (Rarst) and what tools to use (TomJNowell) …there only (might be) the issue left that your ...


1

After quite some time letting the error message bugging my screen, I figured out a way to solve this. Yes, it's a timeout issue, and the codex didn't help me much. So I tried another approach, by setting a filter; add_filter( 'http_request_timeout', 'wp9838c_timeout_extend' ); function wp9838c_timeout_extend( $time ) { // Default timeout is 5 ...


1

You can get it using wp_get_referer() and wp_get_original_referer() functions.


1

use wp_get_referer(); to Retrieve referer from '_wp_http_referer', HTTP referer, or current page respectively. for more info read codex


1

Ad Timeout You should be able to get around the timeout using a filter add_filter( 'http_request_timeout', 'wpse35826_timeout_extd' ); function wpse35826_timeout_extd( $time ) { // Default timeout is 5 return 10; } Choose the right protocol/scheme About your protocol/scheme problem: If it's your local install, you can use the conditional. ...


1

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 );


1

Since I want to easily review the http returns together with the logfiles I log them in a request database. during development handy since i have a second database that stores the metadata of the physical cache. so when i delete that one (over and over again). I can keep on doing requests from the request database and will not bother external servers time ...



Only top voted, non community-wiki answers of a minimum length are eligible