Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multisite Update Check when only activated on subsite #1589

Open
jakejackson1 opened this issue Nov 8, 2024 · 1 comment
Open

Multisite Update Check when only activated on subsite #1589

jakejackson1 opened this issue Nov 8, 2024 · 1 comment
Milestone

Comments

@jakejackson1
Copy link
Member

Multisite won't check for updates if the plugin isn't activated on the primary site of the multisite. The Easy Digital Downloads update module does a check on the Plugins admin page of an active subsite, but the admins will need to visit that page for an update check to occur. You see this with any plugin that receives updates from a source outside wp.org, including Gravity Forms and its extensions.

@jakejackson1
Copy link
Member Author

jakejackson1 commented Nov 8, 2024

Partial success with this snippet:

/**
 * Show upgrade notice on Network Admin if plugin is not network activated
 */
add_action( 'added_option', function ( $option, $value ) {
	if ( is_network_admin() || ! is_multisite() ) {
		return $value;
	}

	if ( strpos( $option, 'edd_sl_' ) !== 0 ) {
		return $value;
	}

	if ( ! isset( $value['timeout'], $value['value'] ) ) {
		return $value;
	}

	$update_info = json_decode( $value['value'] );
	if ( strpos( $update_info->slug, 'gravity-pdf' ) !== 0 ) {
		return $value;
	}

	/* force the network plugins to get updated */
	$_transient_data = get_site_transient( 'update_plugins' );

	$plugins = get_plugins();

	// @TODO - handle case where the transient data is false

	if ( $_transient_data !== false && $update_info !== null && is_object( $update_info ) && isset( $update_info->new_version ) && isset( $plugins[ $update_info->id ] ) ) {
		if ( version_compare( $plugins[ $update_info->id ]['Version'], $update_info->new_version, '<' ) ) {
			$_transient_data->response[ $update_info->id ] = $update_info;
			unset( $_transient_data->no_update[ $update_info->id ] );
		} else {
			// Populating the no_update information is required to support auto-updates in WordPress 5.5.
			$_transient_data->no_update[ $update_info->id ] = $update_info;
			unset( $_transient_data->response[ $update_info->id ] );
		}

		set_site_transient( 'update_plugins', $_transient_data );
	}

}, 10, 2 );

There are a few issues that would need addressing:

  1. Ensure the subsite the plugin is active on runs a scheduled update check
  2. If the network doesn't have anything saved in the update_plugins transient nothing happens
  3. Extending EDD licensing class would make this work easier
  4. The Network Admin won't show the changelog

@jakejackson1 jakejackson1 added this to the 6.12 milestone Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant