因此,在进行了一些修补之后,我提出了以下解决方案:
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);
}