Ticket #14912: plugin-versions.4.diff

File plugin-versions.4.diff, 1.5 KB (added by scribu, 3 years ago)

Only fire if is_admin(); updated docblock

  • wp-includes/plugin.php

     
    668668} 
    669669 
    670670/** 
     671 * Register a routine to be called when a plugin has been updated 
     672 * 
     673 * It works by comparing the current version with the version previously stored in the database. 
     674 * 
     675 * @since 3.1 
     676 * 
     677 * @param string $file A reference to the main plugin file 
     678 * @param callback $callback The function to run when the hook is called. 
     679 * @param string $version The version to which the plugin is updating. 
     680 */ 
     681function register_update_hook( $file, $callback, $version ) { 
     682        if ( !is_admin() ) 
     683                return; 
     684 
     685        $plugin = plugin_basename( $file ); 
     686 
     687        if ( is_plugin_active_for_network( $plugin ) ) { 
     688                $current_vers = get_site_option( 'active_plugin_versions', array() ); 
     689                $network = true; 
     690        } elseif ( is_plugin_active( $plugin ) ) { 
     691                $current_vers = get_option( 'active_plugin_versions', array() ); 
     692                $network = false; 
     693        } else { 
     694                return 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