Definition:
function wp_update_plugins() {}
Check plugin versions against the latest versions hosted on WordPress.org.
The WordPress version, PHP version, and Locale is sent along with a list of all plugins installed. Checks against the WordPress server at api.wordpress.org. Will only check if WordPress isn’t installing.
Return values
returns:Returns null if update is unsupported. Returns false if check is too soon.
Source code
function wp_update_plugins() { include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version if ( defined('WP_INSTALLING') ) return false; // If running blog-side, bail unless we've not checked in the last 12 hours if ( !function_exists( 'get_plugins' ) ) require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); $plugins = get_plugins(); $active = get_option( 'active_plugins', array() ); $current = get_site_transient( 'update_plugins' ); if ( ! is_object($current) ) $current = new stdClass; $new_option = new stdClass; $new_option->last_checked = time(); // Check for updated every 60 minutes if hitting update pages; else, check every 12 hours. $timeout = in_array( current_filter(), array( 'load-plugins.php', 'load-update.php', 'load-update-core.php' ) ) ? 3600 : 43200; $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked ); $plugin_changed = false; foreach ( $plugins as $file => $p ) { $new_option->checked[ $file ] = $p['Version']; if ( !isset( $current->checked[ $file ] ) || strval($current->checked[ $file ]) !== strval($p['Version']) ) $plugin_changed = true; } if ( isset ( $current->response ) && is_array( $current->response ) ) { foreach ( $current->response as $plugin_file => $update_details ) { if ( ! isset($plugins[ $plugin_file ]) ) { $plugin_changed = true; break; } } } // Bail if we've checked in the last 12 hours and if nothing has changed if ( $time_not_changed && !$plugin_changed ) return false; // Update last_checked for current to prevent multiple blocking requests if request hangs $current->last_checked = time(); set_site_transient( 'update_plugins', $current ); $to_send = (object) compact('plugins', 'active'); $options = array( 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3), 'body' => array( 'plugins' => serialize( $to_send ) ), 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ); $raw_response = wp_remote_post('http://api.wordpress.org/plugins/update-check/1.0/', $options); if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) return false; $response = unserialize( wp_remote_retrieve_body( $raw_response ) ); if ( false !== $response ) $new_option->response = $response; else $new_option->response = array(); set_site_transient( 'update_plugins', $new_option ); }
4231
No comments yet... Be the first to leave a reply!