Show warning if plugin is missing

Sorry if this question is a bit to trivial, but I’m writing a theme that depends on a plugin to be installed. It’s a multilingual theme, so I absolutely need the user to have Polylang installed. I thought about just copying the plugin files into my theme, but that would mean my theme users won’t get Polylang updates.

So I hope you agree the best solution is to force the user to install polylang. Now, I would like to know what is the best way to let the user know he needs to install polylang? Is it possible to install a plugin automatically? What should happen if the user uninstalls polylang afterwars, just break the theme, or fall back to twentyeleven theme?

Read More

I would really love to hear some other people’s ideas on this.

Related posts

Leave a Reply

2 comments

  1. sample code that you can addopt and chage… to check is plugin installed.
    // addition check on init hook.

    add_action('admin_init', 'wpse_73859_init');
    function wpse_73859_init(){
        // if - we in wp-admin
        // if - we class of polylang not found
        // and if we can manage_options (there a lot of different 
        //     capabilities you can use install_plugins for example...)
    
        if (!class_exists('Polylang') && current_user_can('manage_options')){
            // message function created on a fly... 
            $msg = create_function('', 'echo "<div class="updated"><p>require polylang plugin</p></div>";');
            // and finaly notice! 
            add_action('admin_notices', $msg);
        }
    }
    

    You actually can install plugin ( do silent download / unziping / actiavation) but its SO unacepted that you can’t imaging. You basicly breaking privacy of person who use your theme.

  2. // The is_plugin_active() function is only included by default in the admin,
    // load it on the front-end too if needed.
    if ( ! function_exists('is_plugin_active'))
    {
        include_once ABSPATH.'wp-admin/includes/plugin.php';
    }
    
    // Check if a certain plugin is activated
    if ( ! is_plugin_active('plugin-directory/plugin-file.php'))
    {
        // It's probably too drastic to simply exit, but do whatever you want here
        exit('Plugin X requires plugin Y. Please, install plugin Y.');
    }
    

    Codex: is_plugin_active()