1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Override Plugin and Theme Update Checks |
---|
4 | Plugin URI: https://core.trac.wordpress.org/ticket/31011 |
---|
5 | Description: Prevents plugin and theme update checks from being run on each admin page load in WordPress 4.1. See <a href="https://core.trac.wordpress.org/ticket/31011">#31011</a> for more details. |
---|
6 | Author: Sergey Biryukov |
---|
7 | Author URI: http://profiles.wordpress.org/sergeybiryukov/ |
---|
8 | Version: 0.1 |
---|
9 | */ |
---|
10 | |
---|
11 | class Override_Plugin_and_Theme_Update_Checks_31011 { |
---|
12 | |
---|
13 | function __construct() { |
---|
14 | add_filter( 'site_transient_update_plugins', array( $this, 'override_updated_plugins_check' ) ); |
---|
15 | add_filter( 'site_transient_update_themes', array( $this, 'override_updated_themes_check' ) ); |
---|
16 | } |
---|
17 | |
---|
18 | function override_updated_plugins_check( $transient ) { |
---|
19 | $plugins = get_plugins(); |
---|
20 | |
---|
21 | // Reset the timeout if previous requests never succeeded |
---|
22 | if ( ! isset( $transient->checked ) ) { |
---|
23 | $last_update->last_checked = time(); |
---|
24 | } |
---|
25 | |
---|
26 | // Short-circuit the check for changed plugins |
---|
27 | foreach ( $plugins as $file => $plugin ) { |
---|
28 | if ( ! isset( $transient->checked[ $file ] ) ) { |
---|
29 | $transient->checked[ $file ] = $plugin['Version']; |
---|
30 | } |
---|
31 | } |
---|
32 | |
---|
33 | return $transient; |
---|
34 | } |
---|
35 | |
---|
36 | function override_updated_themes_check( $transient ) { |
---|
37 | $themes = wp_get_themes(); |
---|
38 | |
---|
39 | // Reset the timeout if previous requests never succeeded |
---|
40 | if ( ! isset( $transient->checked ) ) { |
---|
41 | $last_update->last_checked = time(); |
---|
42 | } |
---|
43 | |
---|
44 | // Short-circuit the check for changed themes |
---|
45 | foreach ( $themes as $theme ) { |
---|
46 | $stylesheet = $theme->get_stylesheet(); |
---|
47 | if ( ! isset( $transient->checked[ $stylesheet ] ) ) { |
---|
48 | $transient->checked[ $stylesheet ] = $theme->get( 'Version' ); |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | return $transient; |
---|
53 | } |
---|
54 | |
---|
55 | } |
---|
56 | |
---|
57 | new Override_Plugin_and_Theme_Update_Checks_31011; |
---|
58 | ?> |
---|