Skip to content

Commit

Permalink
Merge pull request #13 from thefrosty/develop
Browse files Browse the repository at this point in the history
Disable Plugin Update Checks + bump PHP >= 7.1
  • Loading branch information
thefrosty authored Feb 13, 2019
2 parents cd619f8 + d959444 commit 956fecf
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 6 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ php:
- '7.3'
- '7.2'
- '7.1'
- '7.0'

install: composer install

Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
PHP Version >= `7.2` will be required by version `1.4`.
PHP Version >= `7.2` will be required by version `1.5`.

## [1.4] - 2019-02-13
### PHP version bumped to >= 7.1
### Added
- Add a new class `TheFrosty\WpUtilities\WpAdmin\DisablePluginUpdateCheck` to disable plugin update checks. All you have
to do is instantiate it in a PluginInterface `add()` method.

## [1.3.1] - 2019-01-07
### Fixed
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "thefrosty/wp-utilities",
"description": "A library containing my standard development resources",
"version": "1.3.1",
"version": "1.4",
"license": "MIT",
"authors": [
{
Expand All @@ -18,7 +18,7 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=7.0"
"php": ">=7.1"
},
"require-dev": {
"phpunit/phpunit": "^6.5",
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/PluginFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class PluginFactory
* Create a plugin instance.
*
* @param string $slug Plugin slug.
* @param string $filename Optional. Absolute path to the main plugin file.
* @param string|null $filename Optional. Absolute path to the main plugin file.
* This should be passed if the calling file is not
* the main plugin file.
* @return Plugin A Plugin object instance.
*/
public static function create(string $slug, string $filename = '') : Plugin
public static function create(string $slug, ?string $filename = '') : Plugin
{
// Use the calling file as the main plugin file.
if (empty($filename)) {
Expand Down
57 changes: 57 additions & 0 deletions src/WpAdmin/DisablePluginUpdateCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php declare(strict_types=1);

namespace TheFrosty\WpUtilities\WpAdmin;

use TheFrosty\WpUtilities\Plugin\AbstractHookProvider;

/**
* Class disablePluginUpdateCheck
* @package TheFrosty\WpUtilities\WpAdmin
*/
class DisablePluginUpdateCheck extends AbstractHookProvider
{
private const WP_ORG_UPDATE_CHECK = 'https://api.wordpress.org/plugins/update-check/';

/**
* Add class hooks
*/
public function addHooks()
{
$this->addFilter('http_request_args', [$this, 'httpRequestRemovePluginBasename']);
$this->addFilter('site_transient_update_plugins', [$this, 'transientRemovePluginBasename']);
}

/**
* Disable plugin update checks for the current plugin
* @link https://stackoverflow.com/a/39217270/558561
* @param array $args An array of HTTP request arguments.
* @param string $url The request URL.
* @return array
*/
protected function httpRequestRemovePluginBasename(array $args, string $url) : array
{
if (\strpos($url, self::WP_ORG_UPDATE_CHECK) === 0) {
if (!empty($args['body']['plugins'])) {
$plugins = \json_decode($args['body']['plugins'], true);
unset($plugins['plugins'][$this->getPlugin()->getBasename()]);
$args['body']['plugins'] = \wp_json_encode($plugins);
}
}
return $args;
}

/**
* Remove this plugin from the transient value via the core filter.
* @link https://gist.github.com/rniswonger/ee1b30e5fd3693bb5f92fbcfabe1654d
* @param mixed $value
* @return mixed
*/
protected function transientRemovePluginBasename($value)
{
if (isset($value) && \is_object($value) && (!empty($value->response) && \is_array($value->response))) {
unset($value->response[$this->getPlugin()->getBasename()]);
}

return $value;
}
}

0 comments on commit 956fecf

Please sign in to comment.