Support » Plugin: Mag products integration for WordPress » WP_Error if cannot reach external URL

  • Resolved onepack

    (@onepack)


    Suggestion to fix Fatal “Cannot use object of type WP_Error as array”.

                $response = wp_remote_get($rest_api_url);
                if (is_array($response) && !empty($response['response']['code'])) {
                    if ($response['response']['code'] == 200) {
                        $products = json_decode($response['body'], true);
                    }
                } else {
                    return false; // wp_remote_get failed somehow
                }

    Otherwise the plugin will break the page when the remote URL is not returning any response or in my case when I worked on a local server and had no wifi for some time.

    • This topic was modified 3 years, 9 months ago by .
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘WP_Error if cannot reach external URL’ is closed to new replies.