afragen / wp-dependency-installer

A lightweight class to add to WordPress plugins/themes to automatically install plugin dependencies.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

If optional is false and dependent plugin is installed, it should be activated when theme is activated

JiveDig opened this issue · comments

Just opening an issue to document my discussion with Andy over DM/Slack.

I have a custom theme that requires another plugin to be active in order to work. My config has "optional": false, which forces the install/activation initially, but if I activate another theme the dependent plugin deactivates (which is what I want), then displays a notice [Dependency] Please activate the Mai Theme Engine plugin. Activate Now ».

Since optional is false I would expect that plugin to be forced activate again, now that my theme is reactivated.

FYI: This works as I would expect it to, given my config:

if ( $this->is_installed( $slug ) ) {
    if ( isset( $dependency['optional'] ) && false === $dependency['optional'] ) {
        $this->activate( $slug );
    } else {
        $this->notices[] = array(
            'action' => 'activate',
            'slug'   => $slug,
            'text'   => sprintf( __( 'Please activate the %s plugin.' ), $dependency['name'] ),
        );
    }
} else {

That's an edited version of https://github.com/afragen/wp-dependency-installer/blob/develop/wp-dependency-installer.php#L170

Thanks for an amazing class guys. This thing rocks.