Don't run get_plugins() on every admin page load. Use cron for async update plugin requests. see #7372
git-svn-id: http://svn.automattic.com/wordpress/trunk@8514 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
4d78593e80
commit
06a67ae8d2
|
@ -99,7 +99,7 @@ function get_plugin_data( $plugin_file ) {
|
|||
function get_plugins($plugin_folder = '') {
|
||||
|
||||
if ( ! $cache_plugins = wp_cache_get('plugins', 'plugins') )
|
||||
$cached_plugins = array();
|
||||
$cache_plugins = array();
|
||||
|
||||
if ( isset($cache_plugins[ $plugin_folder ]) )
|
||||
return $cache_plugins[ $plugin_folder ];
|
||||
|
|
|
@ -133,6 +133,7 @@ function wp_cron() {
|
|||
function wp_get_schedules() {
|
||||
$schedules = array(
|
||||
'hourly' => array( 'interval' => 3600, 'display' => __('Once Hourly') ),
|
||||
'twicedaily' => array( 'interval' => 43200, 'display' => __('Twice Daily') ),
|
||||
'daily' => array( 'interval' => 86400, 'display' => __('Once Daily') ),
|
||||
);
|
||||
return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );
|
||||
|
|
|
@ -90,22 +90,17 @@ function wp_update_plugins() {
|
|||
if ( !function_exists('fsockopen') || defined('WP_INSTALLING') )
|
||||
return false;
|
||||
|
||||
$current = get_option( 'update_plugins' );
|
||||
|
||||
$time_not_changed = isset( $current->last_checked ) && 43200 > ( time() - $current->last_checked );
|
||||
|
||||
// If running blog-side, bail unless we've not checked in the last 12 hours
|
||||
if ( !function_exists( 'get_plugins' ) ) {
|
||||
if ( $time_not_changed )
|
||||
return false;
|
||||
if ( !function_exists( 'get_plugins' ) )
|
||||
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
||||
}
|
||||
|
||||
$plugins = get_plugins();
|
||||
$active = get_option( 'active_plugins' );
|
||||
$current = get_option( 'update_plugins' );
|
||||
|
||||
$new_option = '';
|
||||
$new_option->last_checked = time();
|
||||
$time_not_changed = isset( $current->last_checked ) && 43200 > ( time() - $current->last_checked );
|
||||
|
||||
$plugin_changed = false;
|
||||
foreach ( $plugins as $file => $p ) {
|
||||
|
@ -160,9 +155,19 @@ function wp_update_plugins() {
|
|||
|
||||
update_option( 'update_plugins', $new_option );
|
||||
}
|
||||
if ( defined( 'WP_ADMIN' ) && WP_ADMIN )
|
||||
add_action( 'admin_init', 'wp_update_plugins' );
|
||||
else
|
||||
add_action( 'init', 'wp_update_plugins' );
|
||||
|
||||
function _maybe_update_plugins() {
|
||||
$current = get_option( 'update_plugins' );
|
||||
if ( isset( $current->last_checked ) && 43200 > ( time() - $current->last_checked ) )
|
||||
return;
|
||||
wp_update_plugins();
|
||||
}
|
||||
|
||||
add_action( 'load-plugins.php', 'wp_update_plugins' );
|
||||
add_action( 'admin_init', '_maybe_update_plugins' );
|
||||
add_action( 'wp_update_plugins', 'wp_update_plugins' );
|
||||
|
||||
if ( !wp_next_scheduled('wp_update_plugins') )
|
||||
wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins');
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue