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]; } public static function getCustomCss(array $args): array { $custom_css = wp_get_custom_css(); return ['css' => $custom_css ?: '', 'theme' => get_stylesheet()]; } public static function updateCustomCss(array $args): array { $css = $args['css'] ?? ''; $result = wp_update_custom_css_post($css); if (is_wp_error($result)) throw new \RuntimeException($result->get_error_message()); return ['updated' => true, 'theme' => get_stylesheet()]; } public static function getThemeMods(array $args): array { $mods = get_theme_mods(); return ['theme' => get_stylesheet(), 'mods' => $mods ?: []]; } public static function updateThemeMod(array $args): array { $mod_name = sanitize_key($args['mod_name']); $mod_value = $args['mod_value']; if (empty($mod_name)) throw new \RuntimeException('mod_name is required.'); set_theme_mod($mod_name, $mod_value); return ['mod_name' => $mod_name, 'updated' => true]; } }