Make WordPress Core

Ticket #14912: plugin-versions.2.diff

File plugin-versions.2.diff, 1.7 KB (added by scribu, 14 years ago)

Use is_plugin_active_for_network()

  • wp-includes/plugin.php

     
    668668}
    669669
    670670/**
     671 * Set the update hook for a plugin.
     672 *
     673 * Registers the update hook that will be called when the user updates the
     674 * plugin to a newer version than previously installed. 
     675 *
     676 * This function performs calls action called update_plugin- suffixed by the name
     677 * of the plugin.  Plugins can hook update scripts to this action in order to
     678 * clean up options or extra database tables across versions.
     679 *
     680 * @since 3.1
     681 *
     682 * @param string $file
     683 * @param callback $callback The function to run when the hook is called.
     684 * @param string $version The version number to which the plugin is updating.
     685 */
     686function register_update_hook( $file, $callback, $version ) {
     687        $plugin = plugin_basename( $file );
     688
     689        if ( is_plugin_active_for_network( $plugin ) ) {
     690                $current_vers = get_site_option( 'active_plugin_versions', array() );
     691                $network = true;
     692        } elseif ( is_plugin_active( $plugin ) {
     693                $current_vers = get_option( 'active_plugin_versions', array() );
     694                $network = false;
     695        } else {
     696                return false;
     697        }
     698
     699        if ( version_compare( $version, $current_vers[ $plugin ], '>' ) ) {
     700                call_user_func( $callback, $current_vers[ $plugin ], $network );
     701
     702                $current_vers[ $plugin ] = $version;
     703        }
     704
     705        if ( $network ) {
     706                update_site_option( 'active_plugin_versions', $current_vers );
     707        } else {
     708                update_option( 'active_plugin_versions', $current_vers );
     709        }
     710}
     711
     712/**
    671713 * Calls the 'all' hook, which will process the functions hooked into it.
    672714 *
    673715 * The 'all' hook passes all of the arguments or parameters that were used for