WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer
excellent suggestion works perfectly – Ezhil Nov 15 '11 at 13:35

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;
    $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;
share|improve this answer
theme frameworks like hybrid have widgets inside theme, why not plugin? – Ezhil Nov 9 '11 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 Nov 9 '11 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 Nov 9 '11 at 12:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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