'GET', 'callback' => [$this, 'fonts'], 'permission_callback' => [Routes::class, 'canManage']], ['methods' => 'POST', 'callback' => [$this, 'saveFonts'], 'permission_callback' => [Routes::class, 'canManage'], 'args' => ['enabled' => ['type' => 'boolean', 'required' => true], 'acknowledged' => ['type' => 'boolean', 'default' => false]]], ]); register_rest_route(Routes::NAMESPACE, '/theme', [ [ 'methods' => 'GET', 'callback' => [$this, 'index'], 'permission_callback' => [Routes::class, 'canManage'], ], ]); } public function fonts(): WP_REST_Response { return new WP_REST_Response(['enabled' => GoogleFonts::enabled()]); } public function saveFonts(WP_REST_Request $request): WP_REST_Response|WP_Error { $enabled = (bool) $request->get_param('enabled'); if ($enabled && !GoogleFonts::enabled() && $request->get_param('acknowledged') !== true) { return new WP_Error('wconvert_font_acknowledgment', __('Confirm that browsers will connect to Google to load fonts.', 'wconvert'), ['status' => 400]); } GoogleFonts::set($enabled); return $this->fonts(); } public function index(): WP_REST_Response { // An empty map is the honest answer for a classic theme with no // `theme.json`: it declares no palette, so there is nothing to copy // and the panel says so rather than offering a button that does // nothing. // // **`fonts` rides the same fetch** rather than earning a route. It is // the same fact about the same site read out of the same settings, and // the panel that asks for one is the panel that asks for the other — // a second route would be a second permission check and a second // round trip for one answer. It degrades the same way: a classic theme // declares no families, the list is empty, and the picker offers the // four system stacks it always did // (`docs/adr/0055-the-font-list-is-the-sites.md`). return new WP_REST_Response([ 'tokens' => ThemeTokens::fromSite(), 'fonts' => ThemeTokens::fontsFromSite(), 'bundled_fonts' => \WConvert\Template\BundledFonts::families(), 'google_fonts_enabled' => GoogleFonts::enabled(), 'font_library_url' => current_user_can('edit_theme_options') && version_compare(get_bloginfo('version'), '6.5', '>=') ? (version_compare(get_bloginfo('version'), '7.0', '>=') ? admin_url('font-library.php') : (wp_is_block_theme() ? admin_url('site-editor.php?path=/styles') : null)) : null, ]); } }