appearance = $appearance; } /** * Register hooks after the token stylesheet is registered. * * @return void */ public function hooks(): void { add_action( 'init', array( $this, 'addInlineTokens' ), 20 ); } /** * Attach the override block to the tokens handle, or nothing when no valid * override is stored. * * @return void */ public function addInlineTokens(): void { $css = $this->appearance->css( $this->storedOverrides() ); if ( '' === $css ) { return; } // Every value is validated in Appearance. Not esc_html(): it would break // quoted font names. wp_add_inline_style( AssetManager::TOKENS_HANDLE, wp_strip_all_tags( $css ) ); } /** * The stored appearance overrides, or an empty array when none exist. * * @return array The `appearance` sub-array of the option. */ private function storedOverrides(): array { $settings = get_option( self::OPTION ); if ( ! is_array( $settings ) || ! isset( $settings['appearance'] ) || ! is_array( $settings['appearance'] ) ) { return array(); } return $settings['appearance']; } }