Inventory_Presser_Addon_Updater::ensure_addon_updaters_initialized( object $_transient_data )
Ensures updaters are initialized for all addon plugins in multisite, even if plugins aren’t active on the main site.
On This Page
Description Description
This is called via a static hook registered in Inventory_Presser_Addon.
Parameters Parameters
- $_transient_data
-
(object) (Required) Update array build by WordPress.
Return Return
(object)
Source Source
File: includes/addon/class-addon-updater.php
public static function ensure_addon_updaters_initialized( $_transient_data ) {
if ( ! is_multisite() ) {
return $_transient_data;
}
// Map of plugin slugs to their details
$addon_plugins = array(
'make-list-widget' => array(
'option_name' => 'make_list_widget_settings',
'item_id' => 607,
'class_name' => 'Make_List_Addon',
),
'taxonomy-filters-widget' => array(
'option_name' => 'invp_filters_widget_settings',
'item_id' => 597,
'class_name' => 'Taxonomy_Filters_Addon',
),
'taxonomy-drop-down-search-widget' => array(
'option_name' => 'invp_drop_down_widget_settings',
'item_id' => 599,
'class_name' => 'Dropdown_Search_Addon',
),
);
// Check if updaters are already initialized
global $edd_plugin_data;
if ( ! isset( $edd_plugin_data ) ) {
$edd_plugin_data = array();
}
// Get all installed plugins
$all_plugins = get_plugins();
foreach ( $addon_plugins as $slug => $plugin_info ) {
// Find the plugin file
$plugin_file = null;
foreach ( $all_plugins as $file => $plugin_data ) {
if ( strpos( $file, $slug ) !== false ) {
$plugin_file = $file;
break;
}
}
if ( ! $plugin_file ) {
continue;
}
// Check if updater is already initialized
if ( isset( $edd_plugin_data[ $slug ] ) ) {
continue;
}
// Try to get license key from any site, and remember which site it came from
$license_key = '';
$license_site_url = '';
$sites = get_sites( array( 'number' => 100 ) );
foreach ( $sites as $site ) {
switch_to_blog( $site->blog_id );
$options = get_option( $plugin_info['option_name'] );
if ( ! empty( $options['license_key'] ) ) {
$license_key = $options['license_key'];
// Use the site URL where the license key was found
// This ensures the license validation matches the registered site
$license_site_url = home_url();
restore_current_blog();
break;
}
restore_current_blog();
}
// If we found a license key, initialize the updater
if ( ! empty( $license_key ) && class_exists( 'Inventory_Presser_Addon_Updater' ) ) {
// Get plugin version from file
$plugin_path = WP_PLUGIN_DIR . '/' . $plugin_file;
if ( file_exists( $plugin_path ) ) {
$plugin_data = get_file_data( $plugin_path, array( 'Version' => 'Version' ) );
$version = ! empty( $plugin_data['Version'] ) ? $plugin_data['Version'] : '1.0.0';
// Use the site URL where the license key was found, or fall back to network URL
$site_url = ! empty( $license_site_url ) ? $license_site_url : network_home_url();
$updater = new Inventory_Presser_Addon_Updater(
'https://inventorypresser.com',
$plugin_file,
array(
'version' => $version,
'license' => $license_key,
'item_id' => $plugin_info['item_id'],
'author' => 'Corey Salzano',
'url' => $site_url,
'beta' => false,
)
);
}
}
}
return $_transient_data;
}
Expand full source codeCollapse full source codeView on Github