How can I disable WordPress plugin updates? - wordpress

I've found a great plugin for WordPress under GPLv2 license and made a lot of changes in source code, plugin does something else now.
I modified author (with original plugin author's credits), URL, version number (from xxx 1.5 to YYY 1.0).
Everything works great, but when WordPress checks for plugin updates it treats my plugin YYY 1.0 as xxx 1.0 and displays notification about available update.
My changed plugin YYY 1.0 was installed by copying files from my computer, not from WP repository.
What else do I have to change?

Disable plugin update
Add this code in your plugin root file.
add_filter('site_transient_update_plugins', 'remove_update_notification');
function remove_update_notification($value) {
unset($value->response[ plugin_basename(__FILE__) ]);
return $value;
}

Put this code in the theme functions.php file. This is working for me and I'm using it. Also this is for specific plugin. Here you need to change plugin main file url to match to that of your plugin.
function my_filter_plugin_updates( $value ) {
if( isset( $value->response['facebook-comments-plugin/facebook-comments.php'] ) ) {
unset( $value->response['facebook-comments-plugin/facebook-comments.php'] );
}
return $value;
}
add_filter( 'site_transient_update_plugins', 'my_filter_plugin_updates' );
Here:
"facebook-comments-plugin" => facebook comments plugin folder name
"facebook-comments.php" => plugin main file.this may be different like index.php
Hope this would be help.

The simplest and effective way is to change the version of the plugin which you don't want to get update.
For an example
if I don't want wptouch to get updated, I open it's defination file, which is like:
/*
Plugin Name: WPtouch Mobile Plugin
Plugin URI: http://www.wptouch.com/
Version: 4.0.4
*/
Here in the Version change 4.0.4 to 9999
like:
/*
Plugin Name: WPtouch Mobile Plugin
Plugin URI: http://www.wptouch.com/
Version: 9999
*/

In the plugin file, there will be a function that will check for updates. The original author could have named this anything, so you will have to go through the code and check each function and what it does. I would imagine the function will be quite obvious as to what it does.
Alternatively you can add this to your plugin file:
add_filter( 'http_request_args', 'dm_prevent_update_check', 10, 2 );
function dm_prevent_update_check( $r, $url ) {
if ( 0 === strpos( $url, 'http://api.wordpress.org/plugins/update-check/' ) ) {
$my_plugin = plugin_basename( __FILE__ );
$plugins = unserialize( $r['body']['plugins'] );
unset( $plugins->plugins[$my_plugin] );
unset( $plugins->active[array_search( $my_plugin, $plugins->active )] );
$r['body']['plugins'] = serialize( $plugins );
}
return $r;
}
Credits: http://developersmind.com/2010/06/12/preventing-wordpress-from-checking-for-updates-for-a-plugin/

add_filter('site_transient_update_plugins', '__return_false');
in function.php add above code and disable all plugins updates

Add this line to wp-config.php to disable plugin updates:
define('DISALLOW_FILE_MODS',true);

One easy solution was to change the version of plugin in plugin file.
For example if plugin version is 1.2.1. You can make it like below (100.9.5 something that plugin author will never reach to )
<?php
/*
* Plugin Name: Your Plugin Name
* Description: Plugin description.
* Version: 100.9.5
*/

Here's an updated version of Mark Jaquith's script:
WP Updates have switched to HTTPS
Unserialize was blocked on my shared hosting
This uses json_decode and json_encode instead
Credit: Block Plugin Update
.
add_filter( 'http_request_args', 'widget_disable_update', 10, 2 );
function widget_disable_update( $r, $url ) {
if ( 0 === strpos( $url, 'https://api.wordpress.org/plugins/update-check/' ) ) {
$my_plugin = plugin_basename( __FILE__ );
$plugins = json_decode( $r['body']['plugins'], true );
unset( $plugins['plugins'][$my_plugin] );
unset( $plugins['active'][array_search( $my_plugin, $plugins['active'] )] );
$r['body']['plugins'] = json_encode( $plugins );
}
return $r;
}

Disable plugin updates manually:
Open functions.php file (go to your activated themes folder)
Copy and paste the following code:
remove_action( 'load-update-core.php', 'wp_update_plugins' );
add_filter( 'pre_site_transient_update_plugins', create_function( '$a', "return null;" ) );
Save changes, and you’re done

Just for completeness, here is one more plugin meant to block updates of selected other plugins:
https://github.com/daggerhart/lock-plugins
Some information about its background and mode of function can be found here (in German).

Related

Register Stylesheet if a particular plugin is installed

I use a basic custom plugin I have built for various WordPress admin functions.
One of them adds a custom CSS file that hooks into the admin as per the example below:
// Sets A Custom Admin Colour Scheme
function hits_admin_colour_scheme() {
wp_register_style('hits_admin_colour_scheme', plugins_url('/assets/css/admin.css',__FILE__ ));
wp_enqueue_style('hits_admin_colour_scheme');
}
add_action( 'admin_init','hits_admin_colour_scheme');
Is it possible to have an additional stylesheet that is only loaded if a particular plugin is installed? Say WooCommerce or ACF? This way I can reduce the size of the default CSS file and only load what is relevant.
Sorry if this is a newbie question. I appreciate any help.
You can check whether woocommerce(or others by same way) is activated before enqueue the file
function hits_admin_colour_scheme() {
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
wp_register_style('hits_aditional_colour_scheme', plugins_url('/assets/css/additional.css',__FILE__ ));
wp_enqueue_style('hits_aditional_colour_scheme');
}
}
add_action( 'admin_enqueue_scripts', 'hits_admin_colour_scheme');
and please use admin_enqueue_scripts hook to enqueue admin assets.

How to disable specific plugin on Wordpress backend / edit product page

I try to find a solution to disable specific plugins on Wordpress admin area. The problem is that for building WooCommerce shops I use Divi Builder, which on product page can sometimes use 50mb of resources when you try to edit it... if I disable some plugins over there then the load time would be much faster. I've found the following code on other topic:
add_filter( 'option_active_plugins', 'lg_disable_cart66_plugin' );
function lg_disable_cart66_plugin($plugins){
if(strpos($_SERVER['REQUEST_URI'], '/store/') === FALSE AND strpos($_SERVER['REQUEST_URI'], '/wp-admin/') === FALSE) {
$key = array_search( 'cart66/cart66.php' , $plugins );
if ( false !== $key ) unset( $plugins[$key] );
}
return $plugins;
}
But don't know how to modify it, so it only disables the chosen plugin on backend. In other words: I don't want the plugin to load when I edit WooCommerce product page.
Some help will be really appreciated.
As ‘option_active_plugins’ is fired before any plugin is loaded we need to drop our code down into mu-plugins directory. Please also remember that those plugins are run before the main query is initialized – that is why we don’t have any access to many functionalities, especially conditional tags which will always return false.
Please paste below code or download gist in mu-plugins folder in your wp-content folder. It would disable the plugin in post & page areas only.
<?php
/*
Plugin Name: Disable Plugin for URl
Plugin URI: https://www.glowlogix.com
Description: Disable plugins for for specific backend pages.
Author: Muhammad Usama M.
Version: 1.0.0
*/
add_filter( 'option_active_plugins', 'disable_plugins_per_page' );
function disable_plugins_per_page( $plugin_list ) {
// Quit immediately if not post edit area.
global $pagenow;
if (( $pagenow == 'post.php' || $pagenow == 'edit.php' )) {
$disable_plugins = array (
// Plugin Name
'hello.php',
'developer/developer.php'
);
$plugins_to_disable = array();
foreach ( $plugin_list as $plugin ) {
if ( true == in_array( $plugin, $disable_plugins ) ) {
//error_log( "Found $plugin in list of active plugins." );
$plugins_to_disable[] = $plugin;
}
}
// If there are plugins to disable then remove them from the list,
// otherwise return the original list.
if ( count( $plugins_to_disable ) ) {
$new_list = array_diff( $plugin_list, $plugins_to_disable );
return $new_list;
}
}
return $plugin_list;
}
You can replace $disable_plugins with the required list of plugins to disable.

Use my custom CSS just for my WordPress plugin settings page, how?

I'm developing my first WordPress plugin. I need to use a custom CSS for the settings pages that I created for the plugin but when I enqueue my stylesheet file, it affects the whole WordPress backend and not just my plugin's settings page.
Is possible to solve this problem? How?
When you want to add styles or scripts in WordPress you enqueue them using hooks. For the admin side the hook you are looking for is called admin_enqueue_scripts.
You can add something like
/**
* Register and enqueue a custom stylesheet in the WordPress admin.
*/
function wpdocs_enqueue_custom_admin_style() {
wp_register_style( 'custom_wp_admin_css', plugin_dir_url( __FILE__ ) . 'css/woo-solo-api-admin.css', false, '1.0.0' );
wp_enqueue_style( 'custom_wp_admin_css' );
}
add_action( 'admin_enqueue_scripts', 'wpdocs_enqueue_custom_admin_style' );
You just need to be careful to correctly specify the url of the css script you want to enqueue.
Hope this helps.
Oh and https://developer.wordpress.org page is great for finding out about WordPress functionality, core functions, hooks etc.
Also check out the plugin handbook: https://developer.wordpress.org/plugins/
Loads of useful information can be found there :)
EDIT:
admin_enqueue_scripts has a parameter you can use read more
/**
* Register and enqueue a custom stylesheet in the WordPress admin.
*/
function wpdocs_enqueue_custom_admin_style( $hook ) {
if ( $hook === 'edit.php' ) {
wp_register_style( 'custom_wp_admin_css', plugin_dir_url( __FILE__ ) . 'css/woo-solo-api-admin.css', false, '1.0.0' );
wp_enqueue_style( 'custom_wp_admin_css' );
}
}
add_action( 'admin_enqueue_scripts', 'wpdocs_enqueue_custom_admin_style' );
This will load the script only on the edit post screen.
You can see what hook is loaded on your screen by adding
error_log( print_r( $hook, true ) );
In your wpdocs_enqueue_custom_admin_style function before the condition. Enable the debug log in your wp-config.php and you'll get a name of your custom post screen hook.
Alternatively, you could target the $current_screen to match the CPT's screen. This will load the script only on that page.

How can I get current version of custom plugin in wordpress

I want to compare the current version of my custom plug-in with update version of plug-in.
I get updated version of plug-in in response from server.
How can I get current version of my plug-in?
You can use get_file_data() function which is available on frontend and backend. For example:
get_file_data('/some/real/path/to/your/plugin', array('Version'), 'plugin');
if you use get_plugin_data() on the frontend it will throw an error Call to undefined function get_plugin_data(). Here is the correct way to get plugin header data.
if ( is_admin() ) {
if( ! function_exists( 'get_plugin_data' ) ) {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
$plugin_data = get_plugin_data( __FILE__ );
echo "<pre>";
print_r( $plugin_data );
echo "</pre>";
}
You could save you version in the options table for easy retrieval. But you can also use get_plugin_data for more details about a given plugin.
<?php
$data = get_plugin_data( "akismet/akismet.php", false, false );
?>
Please note that get_plugin_data is only available in the WordPress admin, it's not a front-end available function.
For users who land on this question to find out the current version of WordPress itself use this function.
// it will show only numeric value i.e 5.8.2
echo get_bloginfo( 'version' );

Automatically execute plugin in wordpress without activating them?

Whenever we use any plugin in wordpress , we need to go to plugin option and then we have to activate them to use them , its fine !
Now my question is
what if someone wants to execute the plugin by default without activating them ?
It means just install that plugin and that plugin will automatically execute on our site without any activation.
Thanks Mubeen for your answer but i just found another solution which is very simple and easy to understand !
Just create a folder name
mu-plugins
folder directory should be
/wp-content/mu-plugins
just download any plugin from www.wordpress.com and extract them and simply copied them in this folder , you will see a new tab in your wordpress plugins option as
Must-Use
the plugins under this tab will automatically executed on your site but there is a problem that if you want to deactivate that plugin then you have to delete that plugin from mu-plugins folder.
source:
http://justintadlock.com/archives/2011/02/02/creating-a-custom-functions-plugin-for-end-users
You can use this code for auto activation WordPress plugin, this will help you to solve your auto activation plugin problem.
<?php
// example on admin init, control about register_activation_hook()
add_action( 'admin_init', 'your_activate_plugins_function' );
// the exmple function
function your_activate_plugins_function() {
if ( ! current_user_can('activate_plugins') )
wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
$plugins = FALSE;
$plugins = get_option('active_plugins'); // get active plugins
if ( $plugins ){
// plugins to active
$pugins_to_active = array(
'hello.php', // Hello Dolly
'adminimize/adminimize.php', // Adminimize
'akismet/akismet.php', // Akismet
'find-any-think/create-plugin-index.php' // Find any think Plugin
);
foreach ( $pugins_to_active as $plugin ) {
if ( ! in_array( $plugin, $plugins ) ) {
array_push( $plugins, $plugin );
update_option( 'active_plugins', $plugins );
}
}
} // end if $plugins
}
?>
Thanks, I Hope your problem will be solve by this code.

Resources