Inventory_Presser_Addon_Updater::get_repo_api_data()
Get repo API data from store.
Description Description
Save to cache.
Return Return
(stdClass)
Source Source
File: includes/addon/class-addon-updater.php
public function get_repo_api_data() {
$version_info = $this->get_cached_version_info();
// If cached version info has empty package URL but we have a license key, clear cache and retry.
// This fixes multisite issues where plugins initialize before site options are available.
if ( false !== $version_info && empty( $version_info->package ) && ! empty( $this->api_data['license'] ) ) {
// Clear the cache and retry.
delete_option( $this->cache_key );
$version_info = false;
}
if ( false === $version_info ) {
// If license key is empty, try to retrieve it dynamically.
// This is a fallback for multisite where site options may not be available during initialization.
if ( empty( $this->api_data['license'] ) ) {
// Try to get license key from global plugin data registry.
global $edd_plugin_data;
if ( ! empty( $edd_plugin_data[ $this->slug ]['license'] ) ) {
$this->api_data['license'] = $edd_plugin_data[ $this->slug ]['license'];
}
// If still empty and we're in multisite, try to get license key from site options.
// Map known plugin slugs to their option names.
if ( empty( $this->api_data['license'] ) && is_multisite() ) {
$option_name_map = array(
'make-list-widget' => 'make_list_widget_settings',
'taxonomy-filters-widget' => 'invp_filters_widget_settings',
'taxonomy-drop-down-search-widget' => 'invp_drop_down_widget_settings',
);
if ( isset( $option_name_map[ $this->slug ] ) ) {
$option_name = $option_name_map[ $this->slug ];
$current_blog_id = get_current_blog_id();
// Try current site first.
$options = get_option( $option_name );
if ( ! empty( $options['license_key'] ) ) {
$this->api_data['license'] = $options['license_key'];
} else {
// If not found, check all sites in the network.
$sites = get_sites( array( 'number' => 100 ) );
foreach ( $sites as $site ) {
switch_to_blog( $site->blog_id );
$options = get_option( $option_name );
if ( ! empty( $options['license_key'] ) ) {
$this->api_data['license'] = $options['license_key'];
restore_current_blog();
break;
}
restore_current_blog();
}
}
// Update global registry if we found a license key.
if ( ! empty( $this->api_data['license'] ) ) {
if ( ! isset( $edd_plugin_data ) ) {
$edd_plugin_data = array();
}
if ( ! isset( $edd_plugin_data[ $this->slug ] ) ) {
$edd_plugin_data[ $this->slug ] = array();
}
$edd_plugin_data[ $this->slug ]['license'] = $this->api_data['license'];
}
}
}
}
$version_info = $this->api_request(
'plugin_latest_version',
array(
'slug' => $this->slug,
'beta' => $this->beta,
)
);
if ( ! $version_info ) {
return false;
}
// This is required for your plugin to support auto-updates in WordPress 5.5.
$version_info->plugin = $this->name;
$version_info->id = $this->name;
$this->set_version_info_cache( $version_info );
}
return $version_info;
}
Expand full source codeCollapse full source codeView on Github