Last active
August 26, 2016 07:21
-
-
Save onnimonni/4d9d6f10f50bcaa547ca692086d30a3f to your computer and use it in GitHub Desktop.
Instead of using this small hack consider using this plugin https://github.com/devgeniem/wp-core-blocker. It takes care of much more edge cases and core functionality.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Disable All Updates and External Connections | |
* Description: Plugin which disables core, plugin and theme updates and connections to wordpress.org This is quite useful in local development | |
* Version: 1.0.0 | |
* Author: Onni Hakala | |
* Author URI: https://github.com/onnimonni | |
* License: MIT License | |
*/ | |
namespace geniem\helper; | |
use stdClass; | |
/** | |
* Contains small snippets to disable | |
*/ | |
class DisableUpdatesAndConnections { | |
/** | |
* Activate hooks into wordpress | |
*/ | |
static function init() { | |
// Tell wordpress that everything is just fine | |
add_filter( 'pre_site_transient_update_core', array( __CLASS__, 'current_core_theme_and_plugins_are_just_fine' ) ); | |
add_filter( 'pre_site_transient_update_plugins', array( __CLASS__, 'current_core_theme_and_plugins_are_just_fine' ) ); | |
add_filter( 'pre_site_transient_update_themes', array( __CLASS__, 'current_core_theme_and_plugins_are_just_fine' ) ); | |
// Disable wp-cron update checks | |
wp_clear_scheduled_hook( 'wp_version_check' ); | |
wp_clear_scheduled_hook( 'wp_update_plugins' ); | |
wp_clear_scheduled_hook( 'wp_update_themes' ); | |
// Remove admin news dashboard widget | |
add_action( 'admin_init', array( __CLASS__, 'remove_dashboards' ) ); | |
// If user didn't define these few core variables we add them now | |
if ( ! defined( 'WP_AUTO_UPDATE_CORE' ) ) { | |
define( 'WP_AUTO_UPDATE_CORE', false ); | |
} | |
if ( ! defined( 'WP_HTTP_BLOCK_EXTERNAL' ) ) { | |
define( 'WP_HTTP_BLOCK_EXTERNAL', true ); | |
} | |
} | |
/** | |
* Always returns information that current version is okay. | |
* This way wordpress doesn't make additional requests to wordpress.org | |
* and we dictate updating process always | |
*/ | |
static function current_core_theme_and_plugins_are_just_fine() { | |
global $wp_version; | |
$current = new stdClass(); | |
// wp-includes/update.php:604 _maybe_update_core() checks these two variables | |
// wp-includes/update.php:627 _maybe_update_plugins() checks only last_checked | |
// wp-includes/update.php:643 _maybe_update_themes() checks only last_checked | |
$current->version_checked = $wp_version; | |
$current->last_checked = time(); | |
return $current_core; | |
} | |
/** | |
* Remove WordPress news dashboard widget | |
*/ | |
static function remove_dashboards() { | |
remove_meta_box( 'dashboard_primary', 'dashboard', 'normal' ); | |
} | |
} | |
DisableUpdatesAndConnections::init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment