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.
Inventory_Presser_Addon_Updater::api_request( string $_action, array $_data )
Calls the API and, if successfull, returns the object delivered by the API.
Parameters Parameters
- $_action
-
(string) (Required) The requested action.
- $_data
-
(array) (Required) Parameters for the API action.
Return Return
(false|object)
Source Source
File: includes/addon/class-addon-updater.php
private function api_request( $_action, $_data ) {
global $wp_version, $edd_plugin_url_available;
$verify_ssl = $this->verify_ssl();
// Do a quick status check on this domain if we haven't already checked it.
$store_hash = md5( $this->api_url );
if ( ! is_array( $edd_plugin_url_available ) || ! isset( $edd_plugin_url_available[ $store_hash ] ) ) {
$test_url_parts = wp_parse_url( $this->api_url );
$scheme = ! empty( $test_url_parts['scheme'] ) ? $test_url_parts['scheme'] : 'http';
$host = ! empty( $test_url_parts['host'] ) ? $test_url_parts['host'] : '';
$port = ! empty( $test_url_parts['port'] ) ? ':' . $test_url_parts['port'] : '';
if ( empty( $host ) ) {
$edd_plugin_url_available[ $store_hash ] = false;
} else {
$test_url = $scheme . '://' . $host . $port;
$response = wp_remote_get(
$test_url,
array(
'timeout' => $this->health_check_timeout,
'sslverify' => $verify_ssl,
)
);
$edd_plugin_url_available[ $store_hash ] = is_wp_error( $response ) ? false : true;
}
}
if ( false === $edd_plugin_url_available[ $store_hash ] ) {
return false;
}
$data = array_merge( $this->api_data, $_data );
if ( $data['slug'] !== $this->slug ) {
return false;
}
if ( $this->api_url === trailingslashit( home_url() ) ) {
return false; // Don't allow a plugin to ping itself.
}
// Use the URL from api_data if set (this is the site URL where the license key was found)
// Otherwise fall back to home_url() for backward compatibility
$request_url = ! empty( $data['url'] ) ? $data['url'] : home_url();
$api_params = array(
'edd_action' => 'get_version',
'license' => ! empty( $data['license'] ) ? $data['license'] : '',
'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false,
'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false,
'version' => isset( $data['version'] ) ? $data['version'] : false,
'slug' => $data['slug'],
'author' => $data['author'],
'url' => $request_url,
'beta' => ! empty( $data['beta'] ),
);
$request = wp_remote_post(
$this->api_url,
array(
'timeout' => 15,
'sslverify' => $verify_ssl,
'body' => $api_params,
)
);
if ( ! is_wp_error( $request ) ) {
$request = json_decode( wp_remote_retrieve_body( $request ) );
}
if ( $request && isset( $request->sections ) ) {
$request->sections = maybe_unserialize( $request->sections );
} else {
$request = false;
}
if ( $request && isset( $request->banners ) ) {
$request->banners = maybe_unserialize( $request->banners );
}
if ( $request && isset( $request->icons ) ) {
$request->icons = maybe_unserialize( $request->icons );
}
if ( ! empty( $request->sections ) ) {
foreach ( $request->sections as $key => $section ) {
$request->$key = (array) $section;
}
}
return $request;
}
Expand full source codeCollapse full source codeView on Github