Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
LLMS_Abstract_API_Handler::call( string $resource, array $data, string $method = null )
Execute an API request.
Description Description
Parameters Parameters
- $resource
-
(string) (Required) url endpoint or resource to make a request to.
- $data
-
(array) (Required) array of data to pass in the body of the request.
- $method
-
(string) (Optional) method of request (POST, GET, DELETE, PUT, etc...).
Default value: null
Return Return
(void)
Source Source
File: includes/abstracts/llms.abstract.api.handler.php
private function call( $resource, $data, $method = null ) { $method = is_null( $method ) ? $this->default_request_method : $method; // setup headers. $content_type = $this->is_json ? 'application/json; charset=utf-8' : 'application/x-www-form-urlencoded'; $headers = $this->set_request_headers( array( 'content-type' => $content_type, ), $resource, $method ); $args = array( 'headers' => $headers, 'method' => $method, 'timeout' => $this->request_timeout, 'user-agent' => $this->set_user_agent( 'LifterLMS ' . LLMS_VERSION, $resource, $method ), ); // setup body. $body = $this->set_request_body( $data, $method, $resource ); // if "null" if passed to body, don't send a body at all. if ( ! is_null( $body ) ) { $args['body'] = $this->is_json && $body ? json_encode( $body ) : $body; } // attempt to call the API $response = wp_safe_remote_request( $this->set_request_url( $resource, $method ), $args ); // connection error if ( is_wp_error( $response ) ) { return $this->set_error( __( 'There was a problem connecting to the payment gateway.', 'lifterlms' ), 'api_connection', $response ); } // empty body if ( ! $this->allow_empty_response && empty( $response['body'] ) ) { return $this->set_error( __( 'Empty Response.', 'lifterlms' ), 'empty_response', $response ); } $this->parse_response( $response ); }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.30.1 | self::set_request_body() may respond with null in order to send a request with no body |
3.11.2 | Introduced. |
User Contributed Notes User Contributed Notes
Permalink: