Make WordPress Core

Ticket #14912: plugin-versions.diff

File plugin-versions.diff, 1.6 KB (added by ericmann, 14 years ago)

Moves all update handling to register_update_hook. Extends for multisite.

  • 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        $file = plugin_basename($file);
     688
     689        if(is_multisite()) {
     690                $current_vers = get_site_option( 'active_plugin_versions', array() );
     691        } else {
     692                $current_vers = get_option( 'active_plugin_versions', array() );
     693        }
     694       
     695        if(version_compare($version, $current_vers[$file], '>')) {
     696                call_user_func_array( $callback, array($version, $current_vers[$file]) );
     697               
     698                $current_vers[$file] = $version;
     699        }
     700       
     701        if(is_multisite()) {
     702                update_site_option( 'active_plugin_versions', $current_vers );
     703        } else {
     704                update_option( 'active_plugin_versions', $current_vers );
     705        }
     706}
     707
     708/**
    671709 * Calls the 'all' hook, which will process the functions hooked into it.
    672710 *
    673711 * The 'all' hook passes all of the arguments or parameters that were used for