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.
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.
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;
}