Skip to content

Commit 5429ae0

Browse files
committed
Added: Ability to disable core, plugin and/or theme updates
1 parent cf9185f commit 5429ae0

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
### master
44

55
- Fixed: Firing sequence of `common_toolkit_loaded` hook
6-
- Added: Ability to modify or disable WordPress heartbeat
76
- Added: `ctk_environment` filter
7+
- Added: Ability to disable WordPress core, plugin and/or theme updates
8+
- Added: Ability to modify or disable WordPress heartbeat
89
- Added: Ability to disable WordPress search
910
- Added: Ability to define custom environment constant
1011

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ All variables are optional.
3535
| `admin_bar_color` | Change admin bar color in current environment | string | _null_ |
3636
| `disable_emojis` | Remove support for emojis | bool | false |
3737
| `disable_search` | Disable WordPress site search | bool | false |
38+
| `disable_updates` | Disable WordPress core, plugin and/or theme updates. Valid array values: `[ 'core', 'plugin', 'theme' ]` | array | _empty_ |
3839
| `disable_xmlrpc` | Disable XML-RPC | bool | false |
3940
| `feed_links` | Include RSS feed links in page head | bool | true |
4041
| `heartbeat` | Modify or disable the WordPress heartbeat. Set to integer to change, `false` to disable | bool/int | null |

common-toolkit.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public static function init() {
4242
'admin_bar_color' => null,
4343
'disable_emojis' => false,
4444
'disable_search' => false,
45+
'disable_updates' => [],
4546
'disable_xmlrpc' => false,
4647
'feed_links' => true,
4748
'heartbeat' => null,
@@ -70,6 +71,15 @@ public static function init() {
7071
'is_production' => defined( self::get_config( 'common_toolkit/environment_constant' ) ) ? self::get_config( 'common_toolkit/environment_production' ) == getenv( self::get_config( 'common_toolkit/environment_constant' ) ) : true
7172
];
7273

74+
// Remove WordPress core, plugin and/or theme update notices
75+
$disable_updates = self::get_config( 'common_toolkit/disable_updates' );
76+
if( in_array( 'core', $disable_updates ) )
77+
add_filter( 'pre_site_transient_update_core', array( self::$instance, 'disable_updates' ) );
78+
if( in_array( 'plugin', $disable_updates ) )
79+
add_filter( 'pre_site_transient_update_plugins', array( self::$instance, 'disable_updates' ) );
80+
if( in_array( 'theme', $disable_updates ) )
81+
add_filter( 'pre_site_transient_update_themes', array( self::$instance, 'disable_updates' ) );
82+
7383
// Modify or disable WordPress heartbeat
7484
if( self::get_config( 'common_toolkit/heartbeat' ) === false ) { // Disable heartbeat
7585
add_action( 'init', function() { wp_deregister_script( 'heartbeat' ); }, 1 );
@@ -194,7 +204,7 @@ public static function ctk_config_filter( $key = null ) {
194204
* Usage: echo apply_filters( 'ctk_environment', null ); // Echos current environment string
195205
* var_dump( apply_filters( 'ctk_environment', 'is_production' ) ); // Returns true if in production mode
196206
*
197-
* @since 0.8.1
207+
* @since 0.8.0
198208
*/
199209
public static function ctk_environment_filter( $key = null ) {
200210

@@ -230,10 +240,23 @@ public function disable_emojis() {
230240

231241
}
232242

243+
/*
244+
* Remove WordPress core, plugin and/or theme update notices
245+
* Usage: define( 'CTK_CONFIG', [ 'disable_updates' => [ 'core', 'plugin', 'theme' ] ] );
246+
*
247+
* @since 0.8.0
248+
*/
249+
public function disable_updates() {
250+
251+
global $wp_version;
252+
return (object) array( 'last_checked' => time(), 'version_checked' => $wp_version );
253+
254+
}
255+
233256
/*
234257
* Disables WordPress site search and return 404
235258
*
236-
* @since 0.8.1
259+
* @since 0.8.0
237260
*/
238261
public function disable_search( $query, $error = true ) {
239262

sample-config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"admin_bar_color": null,
77
"disable_emojis": true,
88
"disable_search": false,
9+
"disable_updates": [],
910
"disable_xmlrpc": false,
1011
"feed_links": true,
1112
"heartbeat": null,

0 commit comments

Comments
 (0)