External HTTP API calls slowing down WordPress admin [closed]

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

http_response_timeout filter not working

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

Save external API calls in WordPress

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

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

WP_Http response throws “Cannot use object of type WP_Error as array”

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

WP http XML response HTML encoding and image display problems

Registering dependencies WordPress uses the Dependency API for that. It’s fairly simple: Register & enqueue a script, then pass data that you want to pass from WP/PHP to JS using wp_localize_script(), which adds a <script> tag containing an Array to your DOM (exactly before your script gets added to it): add_action( ‘wp_enqueue_scripts’, function() { $name=”handle”; … Read more