Skip to content

Instantly share code, notes, and snippets.

@pagelab
Created July 7, 2014 12:55
Show Gist options
  • Select an option

  • Save pagelab/0f5b01fc7a75c7ea2850 to your computer and use it in GitHub Desktop.

Select an option

Save pagelab/0f5b01fc7a75c7ea2850 to your computer and use it in GitHub Desktop.
Deactivating a WordPress Plugin Automatically
<?php
/**
* Deactivates a WordPress Plugin Automatically
*
* @copyright PressCoders
* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link http://www.presscoders.com/2011/11/deactivate-wordpress-plugin-automatically/
*
*/
function posk_requires_wordpress_version() {
global $wp_version;
$plugin = plugin_basename( __FILE__ );
$plugin_data = get_plugin_data( __FILE__, false );
$require_wp = "3.5";
if ( version_compare( $wp_version, $require_wp, "<" ) ) {
if( is_plugin_active($plugin) ) {
deactivate_plugins( $plugin );
wp_die( "<strong>".$plugin_data['Name']."</strong> requires <strong>WordPress ".$require_wp."</strong> or higher, and has been deactivated! Please upgrade WordPress and try again.<br /><br />Back to the WordPress <a href='".get_admin_url(null, 'plugins.php')."'>Plugins page</a>." );
}
}
}
add_action( 'admin_init', 'posk_requires_wordpress_version' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment