0

Iam trying to activate a plugin which is inside my theme template directory,

ie : i have a folder called plugin inside my current theme, which has some plugins

how can i activate those plugins from the current plugins options.

2 Answers 2

2

TGM Plugin Activation Class looks awesome!*

[...] the TGM_Plugin_Activation class can automatically install and activate multiple plugins that are either pre-packaged with a theme or downloaded from the WordPress Plugin Repository.

And here's an introduction to it: http://wp.tutsplus.com/articles/intro-to-tgm-plugin-activation-class-for-wordpress/

*Disclaimer: I haven't had a chance to try it out for myself... yet.

1
  • 1
    excellent suggestion works perfectly
    – Ezhil
    Commented Nov 15, 2011 at 13:35
0

As far as I know you can't. You need to put plugins in the relevant plugins folder as defined by Wordpress, otherwise WP will not be able to see them.

See here for instructions on manually installing plugins.

EDIT: Ok, so after our comments above I decided to investigate furter, and it turns out that it is actually pretty easy...

Just put this in your functions.php file and edit $my_plugins_folder as you desire, and then (assuming that your plugins and themes folder are in the default locations) it will work. Tested on my site and it works fine. The only consession that you have to make is that they wont be in alphibetical order, so you'd need to write a usort() function if you were worries about that.

/** Add plugins nested within the theme to the list of plugins in the admin panel */
add_filter('all_plugins', 'add_custom_plugins');
function add_custom_plugins(){
    $plugins = get_plugins();
    $my_plugins_folder_name = 'plugins';
    $my_plugins_path = '../themes/'.get_template().'/'.$my_plugins_folder_name;
    $my_plugins_temp = get_plugins('/'.$my_plugins_path);
    $my_plugins = array();
    if(!empty($my_plugins_temp)) :
        foreach($my_plugins_temp as $key => $value) :
            $my_plugins[$my_plugins_path.'/'.$key] = $value;
        endforeach;
    endif;
    $plugins = array_merge((array)$my_plugins, (array)$plugins);
    return $plugins;
}

ANOTHER EDIT: It looks like this may not work yet, as although WP will add the plugin to your list using the above code, it will not activate it due to having to go up a level. Here is the code that makes the whole process fail -

function validate_file( $file, $allowed_files = '' ) {
    if ( false !== strpos( $file, '..' )) // **!! Code above fails because of this check !!**
        return 1;

    if ( false !== strpos( $file, './' ))
        return 1;

    if (!empty ( $allowed_files ) && (!in_array( $file, $allowed_files ) ) )
        return 3;

    if (':' == substr( $file, 1, 1 ))
        return 2;

    return 0;
}
3
  • theme frameworks like hybrid have widgets inside theme, why not plugin?
    – Ezhil
    Commented Nov 9, 2011 at 11:42
  • The Plugin framework is designed to look for a specific folder, I guess becuase the contents of files need to be read. Adding a Widget Class is much simpler and can be done from anywehre. There may perhaps be a filter for this, but it's not one I'm aware of. I'd suggest researching and finding out which WP file compiles the plugin list to see exactly how it works.
    – David Gard
    Commented Nov 9, 2011 at 12:11
  • Check out the 'all_plugins' filter, that may help. I can't find much documentation on it though. In conjunction with the get_plugins() function you may just be able to do this actually...
    – David Gard
    Commented Nov 9, 2011 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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