我想激活插件中的主题作为主主题。
/*
* For directory structure like:
*
* /my-plugin/
* - /my-plugin.php
* - /themes/
*
*
*/
register_theme_directory( dirname( __FILE__ ) . \'/themes\' );
然后激活插件激活主题,我遗漏了什么?我想激活插件中的主题作为主主题。
/*
* For directory structure like:
*
* /my-plugin/
* - /my-plugin.php
* - /themes/
*
*
*/
register_theme_directory( dirname( __FILE__ ) . \'/themes\' );
然后激活插件激活主题,我遗漏了什么?因此,在进行了一些修补之后,我提出了以下解决方案:
if($enable_theme == true):
register_theme_directory( plugin_dir_path( __FILE__ ) . \'themes\' );
switch_theme( \'mythemename\'); // my custom template/stylesheet name
else:
switch_theme( \'default\'); // template/stylesheet name
endif;
//Testing purposes
//$current_theme = wp_get_theme();
//$name = $current_theme->get_stylesheet();
//$path = $current_theme->get_stylesheet_directory();
//echo $name;
//echo $path;
或function updateTheme($theme){
update_option(\'template\', $theme);
update_option(\'stylesheet\', $theme);
update_option(\'current_theme\', $theme);
}
add_action( \'setup_theme\', \'change_theme\' );
function change_theme() {
if($enable_theme == true):
register_theme_directory( plugin_dir_path( __FILE__ ) . \'themes\' );
$theme = "mythemename";
else:
$theme = "default";
endif;
updateTheme($theme);
}
你错过了一切。主题不是插件,不应该依赖于插件的活动。管理员用户是唯一应该以任何顺序激活他想要的主题和插件的用户。
如果你的主题需要一个插件来操作,那么最好将其作为主题的一部分分发
我不熟悉脚本,这是一个插件,我想修改它来输出post类。当我尝试使用时:apply_filters( \'post_class\', $page->post_class ) it仅输出array=\" \". 我是否需要一个附加函数来连接到post类?在我的研究中,我无法判断我的语法是否错误,或者我在类中缺少了一个要“拉”的函数apply_filters 抓住。非常感谢你的帮助。 var $db_fields = array (\'parent\' => \'post_parent\',