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