allcaps['update_plugins'] = 0; /* * Hide maintenance and update nag */ add_filter( 'site_status_tests', [$this, 'site_status_tests'] ); remove_action( 'admin_notices', 'update_nag', 3 ); remove_action( 'network_admin_notices', 'update_nag', 3 ); remove_action( 'admin_notices', 'maintenance_nag' ); remove_action( 'network_admin_notices', 'maintenance_nag' ); /* * Disable Theme Updates * 2.8 to 3.0 */ remove_action( 'load-themes.php', 'wp_update_themes' ); remove_action( 'load-update.php', 'wp_update_themes' ); remove_action( 'admin_init', '_maybe_update_themes' ); remove_action( 'wp_update_themes', 'wp_update_themes' ); wp_clear_scheduled_hook( 'wp_update_themes' ); /* * 3.0 */ remove_action( 'load-update-core.php', 'wp_update_themes' ); wp_clear_scheduled_hook( 'wp_update_themes' ); /* * Disable Plugin Updates * 2.8 to 3.0 */ remove_action( 'load-plugins.php', 'wp_update_plugins' ); remove_action( 'load-update.php', 'wp_update_plugins' ); remove_action( 'admin_init', '_maybe_update_plugins' ); remove_action( 'wp_update_plugins', 'wp_update_plugins' ); wp_clear_scheduled_hook( 'wp_update_plugins' ); /* * 3.0 */ remove_action( 'load-update-core.php', 'wp_update_plugins' ); wp_clear_scheduled_hook( 'wp_update_plugins' ); /* * Disable Core Updates * 2.8 to 3.0 */ add_filter( 'pre_option_update_core', '__return_null' ); remove_action( 'wp_version_check', 'wp_version_check' ); remove_action( 'admin_init', '_maybe_update_core' ); wp_clear_scheduled_hook( 'wp_version_check' ); /* * 3.0 */ wp_clear_scheduled_hook( 'wp_version_check' ); /* * 3.7+ */ remove_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' ); remove_action( 'admin_init', 'wp_maybe_auto_update' ); remove_action( 'admin_init', 'wp_auto_update_core' ); wp_clear_scheduled_hook( 'wp_maybe_auto_update' ); remove_all_filters( 'plugins_api' ); } /** * Hide update checks in the Site Health screen * * @since 1.6.8 */ public function site_status_tests($tests) { unset( $tests['async']['background_updates'] ); unset( $tests['direct']['plugin_theme_auto_updates'] ); return $tests; } /** * Add notice to admin bar when plugin is active * * @since 1.7.0 */ public function add_adminbar_items($admin_bar) { $plugin_data = get_plugin_data( __FILE__ ); $admin_bar->add_menu([ 'id' => 'dwuos-notice', 'title' => '', 'href' => network_admin_url('plugins.php'), 'meta' => [ 'class' => 'wp-admin-bar-dwuos-notice', 'title' => sprintf( /* translators: %s: Name of the plugin */ __('"%s" plugin is enabled!', 'disable-wordpress-updates'), $plugin_data['Name'] ) ], ]); } /** * Apply CSS styles to admin bar notice * * @since 1.7.0 */ public function admin_css_overrides() { wp_add_inline_style( 'admin-bar', '.wp-admin-bar-dwuos-notice { background-color: rgba(190, 0, 0, 0.4) !important; } .wp-admin-bar-dwuos-notice .dashicons { font-family: dashicons !important; }' ); } /** * Check the outgoing request * * @since 1.4.4 */ public function block_request($pre, $args, $url) { /* Empty url */ if( empty( $url ) ) { return $pre; } /* Invalid host */ if( !$host = parse_url($url, PHP_URL_HOST) ) { return $pre; } $url_data = parse_url( $url ); /* block request */ if( false !== stripos( $host, 'api.wordpress.org' ) && isset( $url_data['path'] ) && (false !== stripos( $url_data['path'], 'update-check' ) || false !== stripos( $url_data['path'], 'version-check' ) || false !== stripos( $url_data['path'], 'browse-happy' ) || false !== stripos( $url_data['path'], 'serve-happy' )) ) { return true; } return $pre; } /** * Filter cron events * * @since 1.5.0 */ public function filter_cron_events($event) { switch( $event->hook ) { case 'wp_version_check': case 'wp_update_plugins': case 'wp_update_themes': case 'wp_maybe_auto_update': $event = false; break; } return $event; } /** * Override version check info * * @since 1.6.0 */ public function last_checked_atm( $t ) { include ABSPATH . WPINC . '/version.php'; $current = new stdClass; $current->updates = []; $current->version_checked = $wp_version; $current->last_checked = time(); return $current; } } if ( class_exists('OS_Disable_WordPress_Updates') ) { $OS_Disable_WordPress_Updates = new OS_Disable_WordPress_Updates(); }