How to set a header in wp_safe_remote_get()?
This will work $args = array( ‘headers’ => array(“Accept” => “application/json”)); $file = wp_safe_remote_get(‘http://xxxxxxxx.xxxx/xapix/xjson/xxxxx.php’, $args); headers is an array. Not a string .
This will work $args = array( ‘headers’ => array(“Accept” => “application/json”)); $file = wp_safe_remote_get(‘http://xxxxxxxx.xxxx/xapix/xjson/xxxxx.php’, $args); headers is an array. Not a string .
The change of method to GET after redirect from POST, PURGE, BAN whatever, is perfectly legal and been there, and will be without WordPress (it has nothing to do with it, really). Welcome to the World Wide Web: Note: For historical reasons, a user agent MAY change the request method from POST to GET for … Read more
One option would be to create a Page dedicated to processing these GET requests. Something like http://example.com/create/?yourquerystringhere`. You can then create a page template, either page-create.php to automatically apply to that page, or a custom template you manually apply from the dropdown. That page template can contain your custom code: <?php // if any variables … Read more
You can block/allow external requests if you like, using a combination of WP_HTTP_BLOCK_EXTERNAL and WP_ACCESSIBLE_HOSTS. Here is the note from /wp-includes/class-http.php: /** * Block requests through the proxy. * * Those who are behind a proxy and want to prevent access to certain hosts may do so. This will * prevent plugins from working and … Read more
Ok, found the problem: I didn’t have to json_encode the body.
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.
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 … Read more
Mark, I’ve had to do something similar for multiple jobs. This is a larger topic but I’ll try break it down in steps and hopefully gets you going in the right direction. I’ve broken the code into steps and outlined them here: if (isset($_POST[‘submit’])) { $example = $_REQUEST[‘example’]; $result = $customcontact->lookupByName( $example ); /** API … Read more
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
Your logic for your updated if statement is wrong. if( !is_wp_error($response) && $response[‘response’][‘code’] != 200 ) Here you are saying; if NOT wp_error AND response code NOT 200 return false. So your not actually catching the WP_Error I believe what you are after is something like: if ( is_wp_error($response) || $response[‘response’][‘code’] != 200 ) return … Read more