/** * Get details about a specific member via the API * * TODO: Clean this mess up. */ function memberful_api_member($member_id) { $response = memberful_wp_get_data_from_api(memberful_admin_member_url($member_id, MEMBERFUL_JSON)); $response_code = (int) wp_remote_retrieve_response_code($response); $response_body = wp_remote_retrieve_body($response); if (is_wp_error($response)) { echo "Couldn't contact api: "; var_dump($response, $url); die; } if (200 !== $response_code or empty($response_body)) { return new WP_Error('memberful_fail', 'Could not get member info from api'); } return json_decode($response_body); }
/** * Gets information about a user from Memberful. * * @param string $access_token An access token which can be used to get info * about the member * @return array */ public function get_member_data($access_token) { $url = memberful_account_url(MEMBERFUL_JSON); $response = memberful_wp_get_data_from_api(add_query_arg('access_token', $access_token, $url), 'get_member_data_for_sign_in'); if (is_wp_error($response)) { return $this->_error('fetch_account_connect_failure', $response); } $body = json_decode($response['body']); $code = $response['response']['code']; if ($code != 200 or $body === NULL) { return $this->_error('fetch_account_response_failure', 'Could not fetch your data from Memberful. ' . $code); } return $body; }