Is there a way to prevent WordPress from activating a plugin, when I click "Activate", and PHP or WP have the wrong versions?
Asked
Active
Viewed 791 times
2 Answers
1
<?php
register_activation_hook( __FILE__, 'bh_proljece_boj_install' );
function bh_proljece_boj_install()
{
if ( version_compare( get_bloginfo( 'version' ), '3.3', ' < ' ) )
{
deactivate_plugins( basename( __FILE__ ) ); // Deactivate our plugin
}
}
?>

user3042036
- 325
- 1
- 2
- 14
-
While not technically preventing the activation to happen, this is the less bad answer. – 7heo.tk Aug 19 '16 at 16:39
-
FYI: This feature is being developed in the WordPress core [reference](https://core.trac.wordpress.org/ticket/43992). – Marcio Duarte Apr 20 '20 at 15:33
-1
There is a global variable $wp_version
or you could use get_bloginfo('version')
to get the WordPress version. You could also use the version_compare(...)
PHP function for PHP version comparison where both verifications could be evaluated in your plugin activation function.

Mario Peshev
- 1,063
- 8
- 16
-
1No no, that's not what I`m asking. I know how to verify that, but I want to know if there's a way to prevent WordPress from activating the plugin. – Marian May 28 '12 at 16:08
-
WP plugins have activation hooks - see [register_activation_hook function](http://codex.wordpress.org/Function_Reference/register_activation_hook) and you can use the function to decide if a plugin is activatable or not. – Mario Peshev May 28 '12 at 16:48
-