WordPress.org

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/deactivate plugins

Description

This function deactivates plugins. It is often used by a plugin to deactivate itself if the plugin requires the presence of certain features that are missing in environment after an administrator has activated it. This is usually the last step in a dependency-checking function.

Usage

 <?php deactivate_pluginsplugin_basename__FILE__ ) ); ?> 

It is recommended to use the admin_init action to call this function.

Parameters

$plugins
(string/array) (required) Single plugin or list of plugins to deactivate.
Default: None
$silent
(bool) (optional) Prevent calling deactivation hooks. Default is `false`.
Default: false
$network_wide
(mixed) (optional) Whether to deactivate the plugin for all sites in the network. A value of null (the default) will deactivate plugins for both the site and the network.
Default: null

Example

<?php

class myPlugin {

	public function __construct() {
		register_activation_hook( __FILE__, array( $this , 'activate' ) );
	}

	public function activate() {
	
		// Check PHP Version and deactivate & die if it doesn't meet minimum requirements.
		if ( 0 > check_version( PHP_VERSION, '5.2' ) ) {
			deactivate_plugins( plugin_basename( __FILE__ ) );
			wp_die( 'This plugin requires PHP Version 5.2.  Sorry about that.' );
		}
		
		// Do activate Stuff now.
	}
}

Changelog

Source File

deactivate_plugins() is located in wp-admin/includes/plugin.php.

Resources

Related