如何激活主题中的插件

时间:2011-11-09 作者:Ezhil

我正在尝试激活我的主题模板目录中的插件,

ie:我在当前主题中有一个名为plugin的文件夹,其中有一些插件

如何从当前的插件选项激活这些插件。

2 个回复
最合适的回答,由SO网友:Dominic 整理而成

TGM Plugin Activation Class 看起来棒极了*

[…]TGM\\U Plugin\\u激活类可以自动安装和激活多个插件,这些插件要么是用主题预打包的,要么是从WordPress插件库下载的。

下面是对它的介绍:http://wp.tutsplus.com/articles/intro-to-tgm-plugin-activation-class-for-wordpress/

*免责声明:我还没有机会亲自尝试。。。然而

SO网友:David Gard

据我所知,你不能。你需要把插件放在Wordpress定义的相关插件文件夹中,否则WP将无法看到它们。

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

把这个放进你的functions.php 文件和编辑$my_plugins_folder 根据您的需要,然后(假设您的插件和主题文件夹位于默认位置)它就会工作。在我的网站上测试过,效果很好。你必须做出的唯一承诺是,它们不会按字母顺序排列,所以你需要写一个usort() 如果您对此感到担忧,请使用函数。

/** 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. 下面是导致整个过程失败的代码-

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

结束

相关推荐

函数deactive_plugins不存在

我正在function deactivate_plugins does not exist 调用此函数时出错function deactivateSelf(){ deactivate_plugins(RSD_PLUGIN, true); //gives error: function deactivate_plugins does not exist header(\"Location: plugins.php?deactivate=true\"); //redirect