Created
August 25, 2016 21:05
-
-
Save daggerhart/92ae4eb952c44a22762c09d25c95af82 to your computer and use it in GitHub Desktop.
Simple plugin that prevents requests for updats for a given list of plugins.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Plugin Name: Lock plugin updates | |
* Description: Prevent plugin updates | |
* Version: 1.0.0 | |
* Author: daggerhart | |
*/ | |
add_filter( 'http_request_args', 'lock_plugins_http_request_args', 5, 2 ); | |
/** | |
* Prevent lookup of certain plugin updates | |
* Source: https://markjaquith.wordpress.com/2009/12/14/excluding-your-plugin-or-theme-from-update-checks/ | |
* | |
* @param $request | |
* @param $url | |
* | |
* @return mixed | |
*/ | |
function lock_plugins_http_request_args( $request, $url ) { | |
if ( FALSE === strpos( $url, '//api.wordpress.org/plugins/update-check' ) ) { | |
return $request; // Not a plugin update request. Bail immediately. | |
} | |
if ( empty($request['body']['plugins']) ){ | |
return $request; | |
} | |
$plugins = json_decode( $request['body']['plugins'], true ); | |
// get a list of locked plugins from somewhere | |
$locked_plugins = apply_filters('lock_plugins-locked_plugins', array()); | |
foreach( $locked_plugins as $locked_plugin_basename ) | |
{ | |
$active_index = array_search( $locked_plugin_basename, $plugins->active ); | |
unset( $plugins->active[ $active_index ] ); | |
unset( $plugins->plugins[ $locked_plugin_basename ] ); | |
} | |
$request['body']['plugins'] = wp_json_encode( $plugins ); | |
return $request; | |
} |
Nice plugin. But I get some nasty PHP Warnings. You try to get properties of non-object.
I fixed 2 things:
- First in line 34-39:
foreach( $locked_plugins as $locked_plugin_basename )
{
$active_index = array_search( $locked_plugin_basename, $plugins['active'] );
unset( $plugins['active'][ $active_index ] );
unset( $plugins['plugins'][ $locked_plugin_basename ] );
}
- In your comment you call the filter but do not return the array:
add_filter('lock_plugins-locked_plugins', function($plugins){
$plugins[] = 'akismet/akismet.php';
return $plugins;
});
Awesome, thanks for the help @obstschale. In case something else comes up, I went ahead and made this into a real repo--
https://github.com/daggerhart/lock-plugins
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspiration: https://twitter.com/danielbachhuber/status/768907891294121984
Usage: