public static function requestApi($url)
    {
        // Dont verify ssl cert in dev mode
        $args = array(
            'timeout' => 120,
            'sslverify' => defined('DEV_MODE') && DEV_MODE == true ? false : true,
            'headers' => array(
                'ClientSolution' => 'WordPress Integration '.EVENTMANAGERINTEGRATION_ID,
                'PhpVersion' => phpversion(),
                'referrer' => get_home_url(),
            ),
        );
        $request = wp_remote_get($url, $args);
        $responseCode = wp_remote_retrieve_response_code($request);
        $body = wp_remote_retrieve_body($request);

        // Decode JSON
        $body = json_decode($body, true);

        // Return null if the request was successful but result is empty
        if (isset($body['code']) && $body['code'] === 'empty_result') {
            return null;
        }

        // Return WP_Error if response code is not 200 OK or result is empty
        if ($responseCode !== 200 || !is_array($body) || empty($body)) {
            return new \WP_Error('error', __('API request failed.', 'event-integration'));
        }

        return $body;
    }
public static function requestApi($url)
    {
        // Dont verify ssl cert in dev mode
        $args = array(
            'timeout' => 120,
            'sslverify' => defined('DEV_MODE') && DEV_MODE == true ? false : true,
            'headers' => array(
                'ClientSolution' => 'WordPress Integration '.EVENTMANAGERINTEGRATION_ID,
                'PhpVersion' => phpversion(),
                'referrer' => get_home_url(),
            ),
        );
        $request = wp_remote_get($url, $args);
        $responseCode = wp_remote_retrieve_response_code($request);
        $body = wp_remote_retrieve_body($request);

        // Decode JSON
        $body = json_decode($body, true);

        // Return null if the request was successful but result is empty
        if (isset($body['code']) && $body['code'] === 'empty_result') {
            return null;
        }

        // Return WP_Error if response code is not 200 OK or result is empty
        if ($responseCode !== 200 || !is_array($body) || empty($body)) {
            return new \WP_Error('error', __('API request failed.', 'event-integration'));
        }

        return $body;
    }
public static function requestApi ( $ url ) { // Dont verify ssl cert in dev mode $ args = array ( 'timeout' => 120 , 'sslverify' => defined ( 'DEV_MODE' ) && DEV_MODE == true ? false : true , 'headers' => array ( 'ClientSolution' => 'WordPress Integration ' . EVENTMANAGERINTEGRATION_ID , 'PhpVersion' => phpversion ( ) , 'referrer' => get_home_url ( ) , ) , ) ; $ request = wp_remote_get ( $ url , $ args ) ; $ responseCode = wp_remote_retrieve_response_code ( $ request ) ; $ body = wp_remote_retrieve_body ( $ request ) ; // Decode JSON $ body = json_decode ( $ body , true ) ; // Return null if the request was successful but result is empty if ( isset ( $ body [ 'code' ] ) && $ body [ 'code' ] === 'empty_result' ) { return null ; } // Return WP_Error if response code is not 200 OK or result is empty if ( $ responseCode !== 200 || ! is_array ( $ body ) || empty ( $ body ) ) { return new \ WP_Error ( 'error' , __ ( 'API request failed.' , 'event-integration' ) ) ; } return $ body ; }
Request to Api
@param  string $url Request Url
@return array|bool|\WP_Error
Request to Api