Skip to content

Commit 7eef7c6

Browse files
committed
Added ability to pass string or boolean to 'disable_updates'
1 parent 1bcb18d commit 7eef7c6

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

README.md

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ Simply copy the `common-toolkit.php` file to your `wp-content/mu-plugins` direct
2727

2828
All variables are optional.
2929

30-
| **Variable** | **Description** | **Type** | **Default** |
31-
|---------------------------|--------------------------------------------------------------------------------------------------------------------------|-------------|---------------|
32-
| `environment` | Environment of current instance (ex: 'production', 'development', 'staging') | string | "production" |
33-
| `environment_constant` | Constant used to determine environment, environmental variable name for `getenv()`. | string | "WP_ENV" |
34-
| `environment_production` | The label used to match if production environment. | string | "production" |
35-
| `admin_bar_color` | Change admin bar color in current environment | string | _null_ |
36-
| `disable_emojis` | Remove support for emojis | bool | false |
37-
| `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_ |
39-
| `disable_xmlrpc` | Disable XML-RPC | bool | false |
40-
| `feed_links` | Include RSS feed links in page head | bool | true |
41-
| `heartbeat` | Modify or disable the WordPress heartbeat. Set to integer to change, `false` to disable | bool/int | null |
42-
| `meta_generator` | Enable or change meta generator tags in page head and RSS feeds | bool/string | true |
43-
| `script_attributes` | Enable support for [additional attributes](#add-attributes-to-enqueued-scripts) to script tags via wp_enqueue_script() | bool | flase |
44-
| `shortcodes` | Enable custom [shortcodes](#shortcodes) created by this class | bool | false |
45-
| `windows_live_writer` | Enable [Windows Live Writer](https://is.gd/Q6KjEQ) support | bool | true |
30+
| **Variable** | **Description** | **Type** | **Default** |
31+
|---------------------------|--------------------------------------------------------------------------------------------------------------------------|-------------------|---------------|
32+
| `environment` | Environment of current instance (ex: 'production', 'development', 'staging') | string | "production" |
33+
| `environment_constant` | Constant used to determine environment, environmental variable name for `getenv()`. | string | "WP_ENV" |
34+
| `environment_production` | The label used to match if production environment. | string | "production" |
35+
| `admin_bar_color` | Change admin bar color in current environment | string | _null_ |
36+
| `disable_emojis` | Remove support for emojis | bool | false |
37+
| `disable_search` | Disable WordPress site search | bool | false |
38+
| `disable_updates` | Disable WordPress core, plugin and/or theme updates. Values: 'core', 'plugin', 'theme'; `true` for all | bool/string/array | false |
39+
| `disable_xmlrpc` | Disable XML-RPC | bool | false |
40+
| `feed_links` | Include RSS feed links in page head | bool | true |
41+
| `heartbeat` | Modify or disable the WordPress heartbeat. Set to integer to change, `false` to disable | bool/int | null |
42+
| `meta_generator` | Enable or change meta generator tags in page head and RSS feeds | bool/string | true |
43+
| `script_attributes` | Enable support for [additional attributes](#add-attributes-to-enqueued-scripts) to script tags via wp_enqueue_script() | bool | flase |
44+
| `shortcodes` | Enable custom [shortcodes](#shortcodes) created by this class | bool | false |
45+
| `windows_live_writer` | Enable [Windows Live Writer](https://is.gd/Q6KjEQ) support | bool | true |
4646

4747
### Example
4848

@@ -169,6 +169,21 @@ $parse_uri['fragment'] = 'newhash';
169169
$uri = \MU_Plugins\CommonToolkit::build_url( $parse_uri );
170170
```
171171

172+
### Disable WordPress Core, Plugin and/or Theme Updates
173+
174+
You can disable any of the update notifications or specific. It accepts string, boolean or an array of values. Examples:
175+
176+
```php
177+
// Disable all update notifications
178+
define( 'CTK_CONFIG', [ 'disable_updates' => true ] ); // boolean
179+
180+
// Disable WordPress core and theme updates only (not plugins)
181+
define( 'CTK_CONFIG', [ 'disable_updates' => [ 'core', 'theme' ] ] ); // array
182+
183+
// Disable only plugin updates updates
184+
define( 'CTK_CONFIG', [ 'disable_updates' => 'plugin' ] ); // string
185+
```
186+
172187
## Environment Filter
173188

174189
You can alternately retrieve the current environment using the `ctk_environment` filter:

common-toolkit.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static function init() {
4242
'admin_bar_color' => null,
4343
'disable_emojis' => false,
4444
'disable_search' => false,
45-
'disable_updates' => [],
45+
'disable_updates' => false,
4646
'disable_xmlrpc' => false,
4747
'feed_links' => true,
4848
'heartbeat' => null,
@@ -72,13 +72,14 @@ public static function init() {
7272
];
7373

7474
// 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' ) );
75+
if( $disable_updates = self::get_config( 'common_toolkit/disable_updates' ) ) {
76+
if( $disable_updates === true || in_array( 'core', (array) $disable_updates ) )
77+
add_filter( 'pre_site_transient_update_core', array( self::$instance, 'disable_updates' ) );
78+
if( $disable_updates === true || in_array( 'plugin', (array) $disable_updates ) )
79+
add_filter( 'pre_site_transient_update_plugins', array( self::$instance, 'disable_updates' ) );
80+
if( $disable_updates === true || in_array( 'theme', (array) $disable_updates ) )
81+
add_filter( 'pre_site_transient_update_themes', array( self::$instance, 'disable_updates' ) );
82+
}
8283

8384
// Modify or disable WordPress heartbeat
8485
if( self::get_config( 'common_toolkit/heartbeat' ) === false ) { // Disable heartbeat

0 commit comments

Comments
 (0)