Tribe__PUE__Checker::request_info( array $query_args = array() )
Retrieve plugin info from the configured API endpoint.
Contents
In general, this method should not be called directly and it is preferable to call the license_key_status() method instead. That method returns the same result, but also analyses each response to set up appropriate license key notifications in the admin environment.
See also
Parameters
- $query_args
-
(array) (Optional) Additional query arguments to append to the request. Optional.
Default value: array()
Return
(Tribe__PUE__Plugin_Info|string|null) $plugin_info
Source
File: src/Tribe/PUE/Checker.php
public function request_info( $query_args = array() ) {
$query_args = apply_filters( 'tribe_puc_request_info_query_args-' . $this->get_slug(), $query_args );
// Cache the API call so it only needs to be made once per plugin per page load.
static $plugin_info_cache;
// Sort parameter keys
$hash_data = $query_args;
ksort( $hash_data );
// Flatten hashed data
$hash_data = json_encode( $hash_data );
// Generate unique hash
$key = hash( 'sha256', $hash_data );
if ( isset( $plugin_info_cache[ $key ] ) ) {
return $plugin_info_cache[ $key ];
}
//Various options for the wp_remote_get() call. Plugins can filter these, too.
$options = array(
'body' => $query_args,
'timeout' => 15, //seconds
'headers' => array(
'Accept' => 'application/json',
),
);
$options = apply_filters( 'tribe_puc_request_info_options-' . $this->get_slug(), $options );
$url = sprintf( '%s/api/plugins/v2/license/validate', $this->get_pue_update_url() );
$result = wp_remote_post(
$url,
$options
);
// Try to parse the response
$plugin_info = null;
if ( ! is_wp_error( $result ) && isset( $result['response']['code'] ) && ( 200 === (int) $result['response']['code'] ) && ! empty( $result['body'] ) ) {
$plugin_info = Tribe__PUE__Plugin_Info::from_json( $result['body'] );
}
$plugin_info = apply_filters( 'tribe_puc_request_info_result-' . $this->get_slug(), $plugin_info, $result );
$plugin_info_cache[ $key ] = $plugin_info;
return $plugin_info;
}