From 06a67ae8d23b6045d2a3cf565c6ab9e2b9818e2d Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 1 Aug 2008 04:26:32 +0000 Subject: [PATCH] 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 --- wp-admin/includes/plugin.php | 2 +- wp-includes/cron.php | 1 + wp-includes/update.php | 29 +++++++++++++++++------------ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index cc4d9cb61a..b501c2a3eb 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -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 ]; diff --git a/wp-includes/cron.php b/wp-includes/cron.php index 08fbb0ea8f..6eff54a313 100644 --- a/wp-includes/cron.php +++ b/wp-includes/cron.php @@ -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 ); diff --git a/wp-includes/update.php b/wp-includes/update.php index 1cdba0534a..beeee9fcfe 100644 --- a/wp-includes/update.php +++ b/wp-includes/update.php @@ -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'); ?>