: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Checks the last time plugins were run before checking plugin versions.
* This might have been backported to WordPress 2.6.1 for performance reasons.
* This is used for the wp-admin to check only so often instead of every page
function _maybe_update_plugins() {
$current = get_site_transient( 'update_plugins' );
if ( isset( $current->last_checked )
&& 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked )
* Checks themes versions only after a duration of time.
* This is for performance reasons to make sure that on the theme version
* checker is not run on every page load.
function _maybe_update_themes() {
$current = get_site_transient( 'update_themes' );
if ( isset( $current->last_checked )
&& 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked )
* Schedules core, theme, and plugin update checks.
function wp_schedule_update_checks() {
if ( ! wp_next_scheduled( 'wp_version_check' ) && ! wp_installing() ) {
wp_schedule_event( time(), 'twicedaily', 'wp_version_check' );
if ( ! wp_next_scheduled( 'wp_update_plugins' ) && ! wp_installing() ) {
wp_schedule_event( time(), 'twicedaily', 'wp_update_plugins' );
if ( ! wp_next_scheduled( 'wp_update_themes' ) && ! wp_installing() ) {
wp_schedule_event( time(), 'twicedaily', 'wp_update_themes' );
* Clears existing update caches for plugins, themes, and core.
function wp_clean_update_cache() {
if ( function_exists( 'wp_clean_plugins_cache' ) ) {
wp_clean_plugins_cache();
delete_site_transient( 'update_plugins' );
delete_site_transient( 'update_core' );
* Schedules the removal of all contents in the temporary backup directory.
function wp_delete_all_temp_backups() {
* Check if there is a lock, or if currently performing an Ajax request,
* in which case there is a chance an update is running.
* Reschedule for an hour from now and exit early.
if ( get_option( 'core_updater.lock' ) || get_option( 'auto_updater.lock' ) || wp_doing_ajax() ) {
wp_schedule_single_event( time() + HOUR_IN_SECONDS, 'wp_delete_temp_updater_backups' );
// This action runs on shutdown to make sure there are no plugin updates currently running.
add_action( 'shutdown', '_wp_delete_all_temp_backups' );
* Deletes all contents in the temporary backup directory.
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
* @return void|WP_Error Void on success, or a WP_Error object on failure.
function _wp_delete_all_temp_backups() {
if ( ! function_exists( 'WP_Filesystem' ) ) {
require_once ABSPATH . '/wp-admin/includes/file.php';
$credentials = request_filesystem_credentials( '' );
if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
if ( ! $wp_filesystem->wp_content_dir() ) {
/* translators: %s: Directory name. */
sprintf( __( 'Unable to locate WordPress content directory (%s).' ), 'wp-content' )
$temp_backup_dir = $wp_filesystem->wp_content_dir() . 'upgrade-temp-backup/';
$dirlist = $wp_filesystem->dirlist( $temp_backup_dir );
$dirlist = $dirlist ? $dirlist : array();
foreach ( array_keys( $dirlist ) as $dir ) {
if ( '.' === $dir || '..' === $dir ) {
$wp_filesystem->delete( $temp_backup_dir . $dir, true );
if ( ( ! is_main_site() && ! is_network_admin() ) || wp_doing_ajax() ) {
add_action( 'admin_init', '_maybe_update_core' );
add_action( 'wp_version_check', 'wp_version_check' );
add_action( 'load-plugins.php', 'wp_update_plugins' );
add_action( 'load-update.php', 'wp_update_plugins' );
add_action( 'load-update-core.php', 'wp_update_plugins' );
add_action( 'admin_init', '_maybe_update_plugins' );
add_action( 'wp_update_plugins', 'wp_update_plugins' );
add_action( 'load-themes.php', 'wp_update_themes' );
add_action( 'load-update.php', 'wp_update_themes' );
add_action( 'load-update-core.php', 'wp_update_themes' );
add_action( 'admin_init', '_maybe_update_themes' );
add_action( 'wp_update_themes', 'wp_update_themes' );
add_action( 'update_option_WPLANG', 'wp_clean_update_cache', 10, 0 );
add_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' );
add_action( 'init', 'wp_schedule_update_checks' );
add_action( 'wp_delete_temp_updater_backups', 'wp_delete_all_temp_backups' );