Skip to content

Instantly share code, notes, and snippets.

@ginsterbusch
Created May 3, 2014 20:47
Show Gist options
  • Save ginsterbusch/725903f2f3b0ef36f63e to your computer and use it in GitHub Desktop.
Save ginsterbusch/725903f2f3b0ef36f63e to your computer and use it in GitHub Desktop.
Function to disable plugins in WordPress
<?php
/**
* Direct update of the stored active plugins (in wp_options table)
* @see http://perishablepress.com/quickly-disable-or-enable-all-wordpress-plugins-via-the-database/
*
* @author Fabian Wolf (@link http://usability-idealist.de/)
*/
function disable_plugin() {
$active_plugins = get_option( 'active_plugins', array() );
/*echo '<pre>'.print_r( array( 'active_plugins' => $active_plugins, 'plugin_basename' => plugin_basename(__FILE__) ) , true).'</pre>';
exit;*/
if( in_array( plugin_basename(__FILE__), $active_plugins ) != false ) {
$update_active_plugins = array();
for( $n = 0; $n < sizeof( $active_plugins ); $n++ ) {
if( plugin_basename(__FILE__) != $active_plugins[ $n ] ) {
$update_active_plugins[] = $active_plugins[ $n ];
}
}
//print_r( $update_active_plugins );
//exit;
update_option( 'active_plugins', $update_active_plugins );
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment