<?php
/**
 * Plugin Name: LWD Automatic Updates
 * Description: Enables automatic updates for all plugins and themes, with a persistent object-cache workaround.
 * Version: 1.0.0
 * LWD Type: mu-plugin
 * LWD Install: existing-only
 * LWD File: lwd-automatic-updates.php
 * Requires PHP: 5.6.0
 * Requires at least: 5.0
 */

// Automatically update all plugins.
add_filter( 'auto_update_plugin', '__return_true' );

// Automatically update all themes.
add_filter( 'auto_update_theme', '__return_true' );

/**
 * Work around stale `notoptions` cache entries when using
 * persistent object caching such as Redis.
 *
 * WordPress upgrader locks are inserted directly into wp_options,
 * which can leave the persistent `notoptions` cache out of sync.
 */
function lwd_prepare_automatic_updates() {
    if ( ! wp_using_ext_object_cache() ) {
        return;
    }

    wp_cache_delete( 'notoptions', 'options' );
}

add_action( 'wp_maybe_auto_update', 'lwd_prepare_automatic_updates', 1 );
