Skip to content

Commit

Permalink
Implemented disabling of core updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rarst committed Sep 3, 2016
1 parent cd38ced commit 7a215f8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
13 changes: 12 additions & 1 deletion readme.md
@@ -1,6 +1,6 @@
# Update Blocker — for WP repositories

Update Blocker is a lightweight generic blocker of plugin and theme updates from official WordPress repositories.
Update Blocker is a lightweight generic blocker of plugin, theme, and core updates from official WordPress repositories.

It was created as shared reusable plugin for the sake of no longer reinventing that particular wheel.

Expand Down Expand Up @@ -68,13 +68,15 @@ array(
'files' => array( '.git', '.svn', '.hg' ),
'plugins' => array( 'update-blocker/update-blocker.php' ),
'themes' => array(),
'core' => false,
)
```

- `all` — boolean, disables updates completely
- `files` — array of plugin/theme root–relative files to detect for block
- `plugins` — array of plugin base names (`folder-name/plugin-name.php`) to block
- `themes` — array of theme slugs (`theme-name`) to block
- `core` — boolean, disables core updates

Settings pass through `update_blocker_blocked` filter.

Expand All @@ -98,6 +100,15 @@ add_filter( 'update_blocker_blocked', function( $blocked ) {
} );
```

### Core opt–in

```php
add_filter( 'update_blocker_blocked', function ( $blocked ) {
$blocked['core'] = true;
return $blocked;
} );
```

## License

- MIT
23 changes: 22 additions & 1 deletion update-blocker.php
Expand Up @@ -35,6 +35,7 @@
'files' => array( '.git', '.svn', '.hg' ),
'plugins' => array( 'update-blocker/update-blocker.php' ),
'themes' => array(),
'core' => false,
) );

/**
Expand All @@ -55,7 +56,7 @@ public function __construct( $blocked = array() ) {
register_activation_hook( __FILE__, array( $this, 'delete_update_transients' ) );
register_deactivation_hook( __FILE__, array( $this, 'delete_update_transients' ) );

$defaults = array( 'all' => false ) + array_fill_keys( array( 'files', 'plugins', 'themes' ), array() );
$defaults = array( 'all' => false, 'core' => false ) + array_fill_keys( array( 'files', 'plugins', 'themes' ), array() );
$this->blocked = array_merge( $defaults, $blocked );

add_action( 'init', array( $this, 'init' ) );
Expand All @@ -72,6 +73,10 @@ public function init() {
} else {
add_filter( 'http_request_args', array( $this, 'http_request_args' ), 10, 2 );
}

if ( $this->blocked->all || $this->blocked->core ) {
add_filter( 'pre_site_transient_update_core', array( $this, 'return_empty_core_update' ) );
}
}

/**
Expand Down Expand Up @@ -240,4 +245,20 @@ public function has_blocked_file( $path ) {

return false;
}

/**
* Returns faked empty results to short circuit core update check.
*
* @return object
*/
public function return_empty_core_update() {

global $wp_version;

return (object) array(
'updates' => array(),
'version_checked' => $wp_version,
'last_checked' => time(),
);
}
}

0 comments on commit 7a215f8

Please sign in to comment.