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?

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

// 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()

| improve this answer | |

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.

| improve this answer | |
  • 1
    1) I wanted to make a few edits in the Answer, but I don't get this: "in SO unacepted that you can't imaging". Can you link to some reading about it? So this can be better explained. ..... 2) Calling admin_init avoids checking for is_admin(). ..... 3) admin_notices requires an echo not a return :o[) – brasofilo Nov 25 '12 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.