How To Programmatically Activate WordPress Plugins

How can I programmatically activate WordPress plugins, e.g I would like to activate plugin A from plugin B

If you would like to activate WordPress plugins programmatically, you need to modify the value of “active_plugins” option.

    $current = get_option( 'active_plugins' );
    $plugin = plugin_basename( trim('akismet/akismet.php') );

    if ( !in_array( $plugin, $current ) ) {
        $current[] = $plugin;
        sort( $current );
        do_action( 'activate_plugin', trim( $plugin ) );
        update_option( 'active_plugins', $current );
        do_action( 'activate_' . trim( $plugin ) );
        do_action( 'activated_plugin', trim( $plugin) );
    }
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments