deactivate_plugins function not working for me at all

So I’m using the WordPress Plugin boilerplate and trying to remove a lite version of my plugin before going ahead with the activation of my new one. But for some reason this code simply does not execute. I have included an example below of what I am trying to do:

class Wp_Content_Calendar_Activator {

    /**
     * Short Description. (use period)
     *
     * Long Description.
     *
     * @since    1.0.0
     */      

    public static function activate() {
        if( is_plugin_active('hello.php') ){
             deactivate_plugins('hello.php');
        }
    }

}

Related posts

1 comment

  1. 1. The first parameter of deactivate_plugins() and is_plugin_active() functions refers to the basename of a plugin – see plugin_basename().

    The plugin basename is the path to the plugin file relative to the plugins directory.

    So, if your plugin resides in wp-content/plugins/hello/hello.php, the plugin basename would be hello/hello.php.

    Example:

    // In your hello.php file.
    if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) {
        deactivate_plugins( plugin_basename( __FILE__ ) );
    }
    

    or

    // Anywhere.
    if ( is_plugin_active( 'hello/hello.php' ) ) {
        deactivate_plugins( 'hello/hello.php' );
    }
    

    2. Make sure the wp-admin/includes/plugin.php file has been loaded. It is not always included.

    require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    deactivate_plugins( 'hello/hello.php' );
    

    3. Terminate WordPress execution – see wp_die().

    require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    deactivate_plugins( 'hello/hello.php' );
    wp_die();
    

Comments are closed.