v2.0.0: add includes/Tools/ThemeTools.php
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace AskTamMCP\Tools;
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class ThemeTools {
|
||||
public static function listThemes(array $args): array {
|
||||
$themes = wp_get_themes();
|
||||
return ['themes'=>array_map(fn($t)=>['stylesheet'=>$t->get_stylesheet(),'name'=>$t->get('Name'),'version'=>$t->get('Version'),'description'=>$t->get('Description'),'author'=>$t->get('Author')],$themes),'total'=>count($themes)];
|
||||
}
|
||||
public static function getActiveTheme(array $args): array {
|
||||
$t = wp_get_theme();
|
||||
return ['name'=>$t->get('Name'),'version'=>$t->get('Version'),'stylesheet'=>$t->get_stylesheet(),'template'=>$t->get_template(),'author'=>$t->get('Author'),'description'=>$t->get('Description'),'uri'=>$t->get('ThemeURI'),'screenshot'=>$t->get_screenshot()];
|
||||
}
|
||||
public static function switchTheme(array $args): array {
|
||||
$theme = wp_get_theme($args['stylesheet']);
|
||||
if (!$theme->exists()) throw new \RuntimeException("Theme not found: {$args['stylesheet']}");
|
||||
switch_theme($args['stylesheet']);
|
||||
return ['stylesheet'=>$args['stylesheet'],'switched'=>true];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user