Skip to content

Commit

Permalink
adding additional hooks from new language upgrader, removing old `cre…
Browse files Browse the repository at this point in the history
…ate_function` call, and general cleanup
  • Loading branch information
norcross committed Dec 13, 2017
1 parent 3dbf5a5 commit 1220f19
Showing 1 changed file with 49 additions and 47 deletions.
96 changes: 49 additions & 47 deletions airplane-mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,60 +83,60 @@ class Airplane_Mode_Core {
* This is our constructor. There are many like it, but this one is mine.
*/
private function __construct() {
add_action( 'plugins_loaded', array( $this, 'textdomain' ) );
add_action( 'style_loader_src', array( $this, 'block_style_load' ), 100 );
add_action( 'script_loader_src', array( $this, 'block_script_load' ), 100 );
add_action( 'admin_init', array( $this, 'remove_update_crons' ) );
add_action( 'admin_init', array( $this, 'remove_schedule_hook' ) );
add_action( 'plugins_loaded', array( $this, 'textdomain' ) );
add_action( 'style_loader_src', array( $this, 'block_style_load' ), 100 );
add_action( 'script_loader_src', array( $this, 'block_script_load' ), 100 );
add_action( 'admin_init', array( $this, 'remove_update_crons' ) );
add_action( 'admin_init', array( $this, 'remove_schedule_hook' ) );

add_filter( 'embed_oembed_html', array( $this, 'block_oembed_html' ), 1, 4 );
add_filter( 'get_avatar', array( $this, 'replace_gravatar' ), 1, 5 );
add_filter( 'map_meta_cap', array( $this, 'prevent_auto_updates' ), 10, 2 );
add_filter( 'default_avatar_select', array( $this, 'default_avatar' ) );
add_filter( 'embed_oembed_html', array( $this, 'block_oembed_html' ), 1, 4 );
add_filter( 'get_avatar', array( $this, 'replace_gravatar' ), 1, 5 );
add_filter( 'map_meta_cap', array( $this, 'prevent_auto_updates' ), 10, 2 );
add_filter( 'default_avatar_select', array( $this, 'default_avatar' ) );

// Kill all the http requests.
add_filter( 'pre_http_request', array( $this, 'disable_http_reqs' ), 10, 3 );
add_filter( 'pre_http_request', array( $this, 'disable_http_reqs' ), 10, 3 );

// Check for our query string and handle accordingly.
add_action( 'init', array( $this, 'toggle_check' ) );
add_action( 'init', array( $this, 'toggle_check' ) );

// Check for status change and purge transients as needed.
add_action( 'airplane_mode_status_change', array( $this, 'purge_transients' ) );
add_action( 'airplane_mode_status_change', array( $this, 'purge_transients' ) );

// Add our counter action.
add_action( 'airplane_mode_http_args', array( $this, 'count_http_requests' ), 0, 0 );
add_action( 'airplane_mode_http_args', array( $this, 'count_http_requests' ), 0, 0 );

// CSS loader and top toggle.
add_action( 'admin_bar_menu', array( $this, 'admin_bar_toggle' ), 9999 );
add_action( 'wp_enqueue_scripts', array( $this, 'toggle_css' ), 9999 );
add_action( 'admin_enqueue_scripts', array( $this, 'toggle_css' ), 9999 );
add_action( 'admin_bar_menu', array( $this, 'admin_bar_toggle' ), 9999 );
add_action( 'wp_enqueue_scripts', array( $this, 'toggle_css' ), 9999 );
add_action( 'admin_enqueue_scripts', array( $this, 'toggle_css' ), 9999 );

// Body class on each location for the display.
add_filter( 'body_class', array( $this, 'body_class' ) );
add_filter( 'login_body_class', array( $this, 'body_class' ) );
add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
add_filter( 'body_class', array( $this, 'body_class' ) );
add_filter( 'login_body_class', array( $this, 'body_class' ) );
add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );

// Remove bulk action for updating themes/plugins.
add_filter( 'bulk_actions-plugins', array( $this, 'remove_bulk_actions' ) );
add_filter( 'bulk_actions-themes', array( $this, 'remove_bulk_actions' ) );
add_filter( 'bulk_actions-plugins-network', array( $this, 'remove_bulk_actions' ) );
add_filter( 'bulk_actions-themes-network', array( $this, 'remove_bulk_actions' ) );
add_filter( 'bulk_actions-plugins', array( $this, 'remove_bulk_actions' ) );
add_filter( 'bulk_actions-themes', array( $this, 'remove_bulk_actions' ) );
add_filter( 'bulk_actions-plugins-network', array( $this, 'remove_bulk_actions' ) );
add_filter( 'bulk_actions-themes-network', array( $this, 'remove_bulk_actions' ) );

// Admin UI items.
add_action( 'admin_menu', array( $this, 'admin_menu_items' ), 9999 );
add_action( 'network_admin_menu', array( $this, 'ms_admin_menu_items' ), 9999 );
add_filter( 'install_plugins_tabs', array( $this, 'plugin_add_tabs' ) );
add_action( 'admin_menu', array( $this, 'admin_menu_items' ), 9999 );
add_action( 'network_admin_menu', array( $this, 'ms_admin_menu_items' ), 9999 );
add_filter( 'install_plugins_tabs', array( $this, 'plugin_add_tabs' ) );

// Theme update API for different calls.
add_filter( 'themes_api', array( $this, 'bypass_theme_api_call' ), 10, 3 );
add_filter( 'themes_api_result', array( $this, 'bypass_theme_api_result' ), 10, 3 );
add_filter( 'themes_api', array( $this, 'bypass_theme_api_call' ), 10, 3 );
add_filter( 'themes_api_result', array( $this, 'bypass_theme_api_result' ), 10, 3 );

// Time based transient checks.
add_filter( 'pre_site_transient_update_themes', array( $this, 'last_checked_themes' ) );
add_filter( 'pre_site_transient_update_plugins', array( $this, 'last_checked_plugins' ) );
add_filter( 'pre_site_transient_update_core', array( $this, 'last_checked_core' ) );
add_filter( 'site_transient_update_themes', array( $this, 'remove_update_array' ) );
add_filter( 'site_transient_update_plugins', array( $this, 'remove_update_array' ) );
add_filter( 'pre_site_transient_update_themes', array( $this, 'last_checked_themes' ) );
add_filter( 'pre_site_transient_update_plugins', array( $this, 'last_checked_plugins' ) );
add_filter( 'pre_site_transient_update_core', array( $this, 'last_checked_core' ) );
add_filter( 'site_transient_update_themes', array( $this, 'remove_update_array' ) );
add_filter( 'site_transient_update_plugins', array( $this, 'remove_update_array' ) );

// Disable fetching languages from online
add_filter( 'site_transient_available_translations', array( $this, 'available_translations' ), 9999, 1 );
Expand All @@ -146,8 +146,8 @@ private function __construct() {
add_filter( 'airplane_mode_parse_script', array( $this, 'bypass_asset_block' ), 10, 2 );

// Our activation / deactivation triggers.
register_activation_hook( __FILE__, array( $this, 'create_setting' ) );
register_deactivation_hook( __FILE__, array( $this, 'remove_setting' ) );
register_activation_hook( __FILE__, array( $this, 'create_setting' ) );
register_deactivation_hook( __FILE__, array( $this, 'remove_setting' ) );

// All our various filter checks.
if ( $this->enabled() ) {
Expand Down Expand Up @@ -360,13 +360,8 @@ public function bypass_asset_block( $block, $parsed ) {
// Create an array of the approved local domains.
$local = apply_filters( 'airplane_mode_local_hosts', array( 'localhost', '127.0.0.1' ) );

// If our parsed URL host is in that array, return false.
if ( in_array( $parsed, $local ) ) {
return false;
}

// And return our blocking choice.
return $block;
// If our parsed URL host is in that array, return false. Otherwise, return our blocking choice.
return ! empty( $local ) && in_array( $parsed, $local ) ? false : $block;
}

/**
Expand Down Expand Up @@ -485,11 +480,11 @@ public function replace_gravatar( $avatar, $id_or_email, $size, $default, $alt )
}

/**
* Remove avatar images from the default avatar list
* Remove avatar images from the default avatar list.
*
* @param string $avatar_list List of default avatars.
*
* @return string Updated list with images removed
* @return string Updated list with images removed.
*/
public function default_avatar( $avatar_list ) {

Expand Down Expand Up @@ -632,6 +627,7 @@ public function toggle_check() {
// Delete old per-site option.
delete_option( 'airplane-mode' );

// Set our mode based on the toggle action.
self::set_mode( $switch );

// And go about our business.
Expand Down Expand Up @@ -668,6 +664,7 @@ protected static function get_redirect() {
'deleted',
'trashed',
'untrashed',
'force-check',
) );

// Redirect away from the update core page.
Expand All @@ -678,7 +675,7 @@ protected static function get_redirect() {
}

/**
* Add our quick toggle to the admin bar to enable / disable
* Add our quick toggle to the admin bar to enable / disable.
*
* @param WP_Admin_Bar $wp_admin_bar The admin bar object.
*
Expand Down Expand Up @@ -811,8 +808,6 @@ public function remove_update_crons() {
remove_action( 'admin_init', '_maybe_update_plugins' );

// Disable Core updates
// @@ TODO figure out how to do this without a create_function.
add_action( 'init', create_function( '', 'remove_action( \'init\', \'wp_version_check\' );' ), 2 );

// Don't look for WordPress updates. Seriously!
remove_action( 'wp_version_check', 'wp_version_check' );
Expand All @@ -822,6 +817,12 @@ public function remove_update_crons() {
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' );

// Don't forget when the language packs do it.
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
remove_action( 'upgrader_process_complete', 'wp_version_check' );
remove_action( 'upgrader_process_complete', 'wp_update_plugins' );
remove_action( 'upgrader_process_complete', 'wp_update_themes' );
}

/**
Expand All @@ -836,6 +837,7 @@ public function remove_schedule_hook() {
return;
}

// Clear all my hooks.
wp_clear_scheduled_hook( 'wp_update_themes' );
wp_clear_scheduled_hook( 'wp_update_plugins' );
wp_clear_scheduled_hook( 'wp_version_check' );
Expand Down

0 comments on commit 1220f19

Please sign in to comment.