WordPress.org

Make WordPress Core

Ticket #14912: plugin-versions.3.diff

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

Uses is_multisite() so the hook works for themes.

  • 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_multisite()) { 
     690                $current_vers = get_site_option( 'active_plugin_versions', array() ); 
     691                $network = true; 
     692        } else { 
     693                $current_vers = get_option( 'active_plugin_versions', array() ); 
     694                network = false; 
     695        } 
     696         
     697        if( version_compare( $version, $current_vers[ $plugin ], '>' ) ) { 
     698                call_user_func( $callback, $current_vers[ $plugin ], $network ) ); 
     699                 
     700                $current_vers[ $plugin ] = $version; 
     701        } 
     702         
     703        if( $network ) { 
     704                update_site_option( 'active_plugin_versions', $current_vers ); 
     705        } else { 
     706                update_option( 'active_plugin_versions', $current_vers ); 
     707        } 
     708} 
     709 
     710/** 
    671711 * Calls the 'all' hook, which will process the functions hooked into it. 
    672712 * 
    673713 * The 'all' hook passes all of the arguments or parameters that were used for