wp-customize-fonts.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <?php
  2. require_once 'wp-customize-global-styles-setting.php';
  3. require_once 'wp-customize-utils.php';
  4. class GlobalStylesFontsCustomizer {
  5. private $section_key = 'customize-global-styles-fonts';
  6. private $font_settings;
  7. private $font_control_default_body;
  8. private $font_control_default_heading;
  9. //Not all fonts support v2 of the API that allows for the shorter URls
  10. //list of supported fonts: https://fonts.google.com/variablefonts
  11. private $fonts = array(
  12. 'system-font' => array(
  13. 'fontFamily' => '-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif',
  14. 'slug' => 'system-font',
  15. 'name' => 'System Font',
  16. ),
  17. 'arvo' => array(
  18. 'fontFamily' => '"Arvo", serif',
  19. 'slug' => 'arvo',
  20. 'name' => 'Arvo',
  21. 'google' => 'family=Arvo:ital,wght@0,400;0,700;1,400;1,700',
  22. ),
  23. 'bodoni-moda' => array(
  24. 'fontFamily' => '"Bodoni Moda", serif',
  25. 'slug' => 'bodoni-moda',
  26. 'name' => 'Bodoni Moda',
  27. 'google' => 'family=Bodoni+Moda:ital,wght@0,400..900;1,400..900',
  28. ),
  29. 'cabin' => array(
  30. 'fontFamily' => '"Cabin", sans-serif',
  31. 'slug' => 'cabin',
  32. 'name' => 'Cabin',
  33. 'google' => 'family=Cabin:ital,wght@0,400..700;1,400..700',
  34. ),
  35. 'chivo' => array(
  36. 'fontFamily' => '"Chivo", sans-serif',
  37. 'slug' => 'chivo',
  38. 'name' => 'Chivo',
  39. 'google' => 'family=Chivo:ital,wght@0,300;0,400;0,700;0,900;1,300;1,400;1,700;1,900',
  40. ),
  41. 'courier-prime' => array(
  42. 'fontFamily' => '"Courier Prime", serif',
  43. 'slug' => 'courier-prime',
  44. 'name' => 'Courier Prime',
  45. 'google' => 'family=Courier+Prime:ital,wght@0,400;0,700;1,400;1,700',
  46. ),
  47. 'dm-sans' => array(
  48. 'fontFamily' => '"DM Sans", sans-serif',
  49. 'slug' => 'dm-sans',
  50. 'name' => 'DM Sans',
  51. 'google' => 'family=DM+Sans:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700"',
  52. ),
  53. 'domine' => array(
  54. 'fontFamily' => '"Domine", serif',
  55. 'slug' => 'domine',
  56. 'name' => 'Domine',
  57. 'google' => 'family=Domine:wght@400..700',
  58. ),
  59. 'eb-garamond' => array(
  60. 'fontFamily' => '"EB Garamond", serif',
  61. 'slug' => 'eb-garamond',
  62. 'name' => 'EB Garamond',
  63. 'google' => 'family=EB+Garamond:ital,wght@0,400..800;1,400..800',
  64. ),
  65. 'fira-sans' => array(
  66. 'fontFamily' => '"Fira Sans", sans-serif',
  67. 'slug' => 'fira-sans',
  68. 'name' => 'Fira Sans',
  69. 'google' => 'family=Fira+Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
  70. ),
  71. 'inter' => array(
  72. 'fontFamily' => '"Inter", sans-serif',
  73. 'slug' => 'inter',
  74. 'name' => 'Inter',
  75. 'google' => 'family=Inter:wght@100..900',
  76. ),
  77. 'josefin-sans' => array(
  78. 'fontFamily' => '"Josefin Sans", sans-serif',
  79. 'slug' => 'josefin-sans',
  80. 'name' => 'Josefin Sans',
  81. 'google' => 'family=Josefin+Sans:ital,wght@0,100..700;1,100..700',
  82. ),
  83. 'libre-baskerville' => array(
  84. 'fontFamily' => '"Libre Baskerville", serif',
  85. 'slug' => 'libre-baskerville',
  86. 'name' => 'Libre Baskerville',
  87. 'google' => 'family=Libre+Baskerville:ital,wght@0,400;0,700;1,400',
  88. ),
  89. 'libre-franklin' => array(
  90. 'fontFamily' => '"Libre Franklin", sans-serif',
  91. 'slug' => 'libre-franklin',
  92. 'name' => 'Libre Franklin',
  93. 'google' => 'family=Libre+Franklin:ital,wght@0,100..900;1,100..900',
  94. ),
  95. 'lora' => array(
  96. 'fontFamily' => '"Lora", serif',
  97. 'slug' => 'lora',
  98. 'name' => 'Lora',
  99. 'google' => 'family=Lora:ital,wght@0,400..700;1,400..700',
  100. ),
  101. 'merriweather' => array(
  102. 'fontFamily' => '"Merriweather", serif',
  103. 'slug' => 'merriweather',
  104. 'name' => 'Merriweather',
  105. 'google' => 'family=Merriweather:ital,wght@0,300;0,400;0,700;0,900;1,300;1,400;1,700;1,900',
  106. ),
  107. 'montserrat' => array(
  108. 'fontFamily' => '"Montserrat", sans-serif',
  109. 'slug' => 'montserrat',
  110. 'name' => 'Montserrat',
  111. 'google' => 'family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
  112. ),
  113. 'nunito' => array(
  114. 'fontFamily' => '"Nunito", sans-serif',
  115. 'slug' => 'nunito',
  116. 'name' => 'Nunito',
  117. 'google' => 'family=Nunito:ital,wght@0,200;0,300;0,400;0,600;0,700;0,800;0,900;1,200;1,300;1,400;1,600;1,700;1,800;1,900',
  118. ),
  119. 'open-sans' => array(
  120. 'fontFamily' => '"Open Sans", sans-serif',
  121. 'slug' => 'open-sans',
  122. 'name' => 'Open Sans',
  123. 'google' => 'family=Open+Sans:ital,wght@0,300;0,400;0,600;0,700;0,800;1,300;1,400;1,600;1,700;1,800',
  124. ),
  125. 'overpass' => array(
  126. 'fontFamily' => '"Overpass", sans-serif',
  127. 'slug' => 'overpass',
  128. 'name' => 'Overpass',
  129. 'google' => 'family=Overpass:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
  130. ),
  131. 'playfair-display' => array(
  132. 'fontFamily' => '"Playfair Display", serif',
  133. 'slug' => 'playfair-display',
  134. 'name' => 'Playfair Display',
  135. 'google' => 'family=Playfair+Display:ital,wght@0,400..900;1,400..900',
  136. ),
  137. 'poppins' => array(
  138. 'fontFamily' => '"Poppins", sans-serif',
  139. 'slug' => 'poppins',
  140. 'name' => 'Poppins',
  141. 'google' => 'family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
  142. ),
  143. 'raleway' => array(
  144. 'fontFamily' => '"Raleway", sans-serif',
  145. 'slug' => 'raleway',
  146. 'name' => 'Raleway',
  147. 'google' => 'family=Raleway:ital,wght@0,100..900;1,100..900',
  148. ),
  149. 'red-hat-display' => array(
  150. 'fontFamily' => '"Red Hat Display", sans-serif',
  151. 'slug' => 'red-hat-display',
  152. 'name' => 'Red Hat Display',
  153. 'google' => 'family=Red+Hat+Display:ital,wght@0,400;0,500;0,700;0,900;1,400;1,500;1,700;1,900',
  154. ),
  155. 'roboto' => array(
  156. 'fontFamily' => '"Roboto", sans-serif',
  157. 'slug' => 'roboto',
  158. 'name' => 'Roboto',
  159. 'google' => 'family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,800;1,900',
  160. ),
  161. 'roboto-slab' => array(
  162. 'fontFamily' => '"Roboto Slab", sans-serif',
  163. 'slug' => 'roboto-slab',
  164. 'name' => 'Roboto Slab',
  165. 'google' => 'family=Roboto+Slab:wght@100..900',
  166. ),
  167. 'rubik' => array(
  168. 'fontFamily' => '"Rubik", sans-serif',
  169. 'slug' => 'rubik',
  170. 'name' => 'Rubik',
  171. 'google' => 'family=Rubik:ital,wght@0,300..900;1,300..900',
  172. ),
  173. 'source-sans-pro' => array(
  174. 'fontFamily' => '"Source Sans Pro", sans-serif',
  175. 'slug' => 'source-sans-pro',
  176. 'name' => 'Source Sans Pro',
  177. 'google' => 'family=Source+Sans+Pro:ital,wght@0,200;0,300;0,400;0,600;0,700;0,900;1,200;1,300;1,400;1,600;1,700;1,900',
  178. ),
  179. 'source-serif-pro' => array(
  180. 'fontFamily' => '"Source Serif Pro", serif',
  181. 'slug' => 'source-serif-pro',
  182. 'name' => 'Source Serif Pro',
  183. 'google' => 'family=Source+Serif+Pro:ital,wght@0,200;0,300;0,400;0,600;0,700;0,900;1,200;1,300;1,400;1,600;1,700;1,900',
  184. ),
  185. 'space-mono' => array(
  186. 'fontFamily' => '"Space Mono", sans-serif',
  187. 'slug' => 'space-mono',
  188. 'name' => 'Space Mono',
  189. 'google' => 'family=Space+Mono:ital,wght@0,400;0,700;1,400;1,700',
  190. ),
  191. 'work-sans' => array(
  192. 'fontFamily' => '"Work Sans", sans-serif',
  193. 'slug' => 'work-sans',
  194. 'name' => 'Work Sans',
  195. 'google' => 'family=Work+Sans:ital,wght@0,100..900;1,100..900',
  196. ),
  197. );
  198. function __construct() {
  199. add_action( 'customize_register', array( $this, 'initialize' ) );
  200. add_action( 'customize_preview_init', array( $this, 'handle_customize_preview_init' ) );
  201. add_action( 'customize_register', array( $this, 'enqueue_google_fonts' ) );
  202. add_action( 'customize_save_after', array( $this, 'handle_customize_save_after' ) );
  203. add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_control_js' ) );
  204. }
  205. function handle_customize_preview_init( $wp_customize ) {
  206. $this->update_font_settings( $wp_customize );
  207. $this->customize_preview_js( $wp_customize );
  208. $this->create_customization_style_element( $wp_customize );
  209. }
  210. function customize_preview_js( $wp_customize ) {
  211. wp_enqueue_script( 'customizer-preview-fonts', get_template_directory_uri() . '/inc/customizer/wp-customize-fonts-preview.js', array( 'customize-preview' ) );
  212. wp_localize_script( 'customizer-preview-fonts', 'googleFonts', $this->fonts );
  213. wp_localize_script( 'customizer-preview-fonts', 'fontSettings', $this->font_settings );
  214. }
  215. function customize_control_js() {
  216. wp_enqueue_script( 'customizer-font-control', get_template_directory_uri() . '/inc/customizer/wp-customize-fonts-control.js', array( 'customize-controls' ), null, true );
  217. wp_localize_script( 'customizer-font-control', 'fontControlDefaultBody', array( $this->font_control_default_body ) );
  218. wp_localize_script( 'customizer-font-control', 'fontControlDefaultHeading', array( $this->font_control_default_heading ) );
  219. }
  220. function enqueue_google_fonts() {
  221. wp_enqueue_style( 'blockbase-google-fonts', $this->google_fonts_url(), array(), null );
  222. }
  223. function create_customization_style_element( $wp_customize ) {
  224. wp_enqueue_style( 'global-styles-fonts-customizations', ' ', array( 'global-styles' ) ); // This needs to load after global_styles, hence the dependency
  225. $css = 'body{';
  226. $css .= 'font-family:' . $this->font_settings['body'] . ';';
  227. $css .= '}';
  228. $css .= 'h1,h2,h3,h4,h5,h6,.wp-block-post-title,.wp-block-pullquote{';
  229. $css .= 'font-family:' . $this->font_settings['heading'] . ';';
  230. $css .= '}';
  231. wp_add_inline_style( 'global-styles-fonts-customizations', $css );
  232. }
  233. function update_font_settings( $wp_customize ) {
  234. $body_value = $wp_customize->get_setting( $this->section_key . 'body' )->post_value();
  235. if ( $body_value ) {
  236. $body_font_setting = $this->fonts[ $body_value ];
  237. $this->font_settings['body'] = $body_font_setting['fontFamily'];
  238. }
  239. $heading_value = $wp_customize->get_setting( $this->section_key . 'heading' )->post_value();
  240. if ( $heading_value ) {
  241. $heading_font_setting = $this->fonts[ $heading_value ];
  242. $this->font_settings['heading'] = $heading_font_setting['fontFamily'];
  243. }
  244. }
  245. function google_fonts_url() {
  246. $font_families = array();
  247. foreach ( $this->fonts as $font ) {
  248. if ( ! empty( $font['google'] ) ) {
  249. $font_families[] = $font['google'];
  250. }
  251. }
  252. $font_families[] = 'display=swap';
  253. // Make a single request for the theme fonts.
  254. return esc_url_raw( 'https://fonts.googleapis.com/css2?' . implode( '&', $font_families ) );
  255. }
  256. function initialize( $wp_customize ) {
  257. $theme = wp_get_theme();
  258. $merged_json = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data()->get_raw_data();
  259. $theme_json = WP_Theme_JSON_Resolver_Gutenberg::get_theme_data()->get_raw_data();
  260. $body_font_default = $this->get_font_family( array( 'styles', 'typography', 'fontFamily' ), $theme_json );
  261. $heading_font_default = $this->get_font_family( array( 'styles', 'elements', 'h1', 'typography', 'fontFamily' ), $theme_json );
  262. $body_font_selected = $this->get_font_family( array( 'styles', 'typography', 'fontFamily' ), $merged_json );
  263. $heading_font_selected = $this->get_font_family( array( 'styles', 'elements', 'h1', 'typography', 'fontFamily' ), $merged_json );
  264. $this->font_settings = array(
  265. 'body' => $body_font_selected['fontFamily'],
  266. 'heading' => $heading_font_selected['fontFamily'],
  267. );
  268. //Add a Section to the Customizer for these bits
  269. $wp_customize->add_section(
  270. $this->section_key,
  271. array(
  272. 'capability' => 'edit_theme_options',
  273. 'description' => sprintf( __( 'Font Customization for %1$s', 'blockbase' ), $theme->name ),
  274. 'title' => __( 'Fonts', 'blockbase' ),
  275. )
  276. );
  277. // Add a reset button
  278. $this->font_control_default_body = $body_font_default['slug'];
  279. $this->font_control_default_heading = $heading_font_default['slug'];
  280. $wp_customize->add_control(
  281. $this->section_key . '-reset-button',
  282. array(
  283. 'type' => 'button',
  284. 'settings' => array(),
  285. 'section' => $this->section_key,
  286. 'input_attrs' => array(
  287. 'value' => __( 'Reset to Default', 'blockbase' ),
  288. 'class' => 'button button-link',
  289. ),
  290. )
  291. );
  292. $this->add_setting_and_control( $wp_customize, 'body', __( 'Body font', 'blockbase' ), $body_font_default['slug'], $body_font_selected['slug'], 'sanitize_title' );
  293. $this->add_setting_and_control( $wp_customize, 'heading', __( 'Heading font', 'blockbase' ), $heading_font_default['slug'], $heading_font_selected['slug'], 'sanitize_title' );
  294. }
  295. function get_font_family( $array, $configuration ) {
  296. $variable = get_settings_array( $array, $configuration );
  297. $slug = preg_replace( '/var\(--wp--preset--font-family--(.*)\)/', '$1', $variable );
  298. if ( ! isset( $this->fonts[ $slug ] ) ) {
  299. $this->fonts[ $slug ] = $this->build_font_from_theme_data( $slug, $configuration );
  300. }
  301. return $this->fonts[ $slug ];
  302. }
  303. function build_font_from_theme_data( $slug, $configuration ) {
  304. $new_font = array();
  305. $font_families = $configuration['settings']['typography']['fontFamilies']['theme'];
  306. foreach ( $font_families as $font_family ) {
  307. if ( $font_family['slug'] === $slug ) {
  308. $new_font['fontFamily'] = $font_family['fontFamily'];
  309. $new_font['name'] = $font_family['name'];
  310. if ( ! empty( $font_family['google'] ) ) {
  311. $new_font['google'] = $font_family['google'];
  312. }
  313. }
  314. }
  315. $new_font['slug'] = $slug;
  316. return $new_font;
  317. }
  318. function add_setting_and_control( $wp_customize, $name, $label, $default, $user_value, $sanitize_callback ) {
  319. $setting_name = $this->section_key . $name;
  320. $global_styles_setting = new WP_Customize_Global_Styles_Setting(
  321. $wp_customize,
  322. $setting_name,
  323. array(
  324. 'default' => $default,
  325. 'user_value' => $user_value
  326. )
  327. );
  328. $wp_customize->add_setting( $global_styles_setting,
  329. array(
  330. 'sanitize_callback' => $sanitize_callback
  331. )
  332. );
  333. $choices = array();
  334. foreach ( $this->fonts as $font_slug => $font_setting ) {
  335. $choices[ $font_slug ] = $font_setting['name'];
  336. }
  337. $wp_customize->add_control(
  338. $setting_name,
  339. array(
  340. 'section' => $this->section_key,
  341. 'label' => $label,
  342. 'type' => 'select',
  343. 'choices' => $choices,
  344. )
  345. );
  346. // Update the setting to the dirty value.
  347. // This is needed to preserve the settings when other Customizer settings change.
  348. $dirty_value = $wp_customize->get_setting( $setting_name )->post_value();
  349. if ( ! empty( $dirty_value ) ) {
  350. $wp_customize->get_setting( $setting_name )->user_value = $dirty_value;
  351. }
  352. }
  353. function handle_customize_save_after( $wp_customize ) {
  354. $body_value = $wp_customize->get_setting( $this->section_key . 'body' )->value();
  355. $heading_value = $wp_customize->get_setting( $this->section_key . 'heading' )->value();
  356. if ( ! isset( $body_value ) && ! isset( $heading_value ) ) {
  357. return;
  358. }
  359. $body_default = $wp_customize->get_setting( $this->section_key . 'body' )->default;
  360. $heading_default = $wp_customize->get_setting( $this->section_key . 'heading' )->default;
  361. if ( ! isset( $body_value ) ) {
  362. $body_value = $body_default;
  363. }
  364. if ( ! isset( $heading_value ) ) {
  365. $heading_value = $heading_default;
  366. }
  367. $body_setting = $this->fonts[ $body_value ];
  368. $heading_setting = $this->fonts[ $heading_value ];
  369. // Set up variables for the theme.json.
  370. $font_families = array(
  371. $body_setting,
  372. $heading_setting,
  373. );
  374. $body_font_family_variable = 'var(--wp--preset--font-family--' . $body_setting['slug'] . ')';
  375. $heading_font_family_variable = 'var(--wp--preset--font-family--' . $heading_setting['slug'] . ')';
  376. // Get the user's theme.json from the CPT.
  377. $user_custom_post_type_id = WP_Theme_JSON_Resolver_Gutenberg::get_user_custom_post_type_id();
  378. $user_theme_json_post = get_post( $user_custom_post_type_id );
  379. $user_theme_json_post_content = json_decode( $user_theme_json_post->post_content );
  380. // Set meta settings.
  381. $user_theme_json_post_content->version = 1;
  382. $user_theme_json_post_content->isGlobalStylesUserThemeJSON = true;
  383. // Set the typography settings.
  384. $user_theme_json_post_content = set_settings_array(
  385. $user_theme_json_post_content,
  386. array( 'settings', 'typography', 'fontFamilies' ),
  387. $font_families
  388. );
  389. // Set the body typography settings.
  390. $user_theme_json_post_content = set_settings_array(
  391. $user_theme_json_post_content,
  392. array( 'styles', 'typography', 'fontFamily' ),
  393. $body_font_family_variable
  394. );
  395. $user_theme_json_post_content = set_settings_array(
  396. $user_theme_json_post_content,
  397. array( 'styles', 'blocks', 'core/button', 'typography', 'fontFamily' ),
  398. $heading_font_family_variable
  399. );
  400. // Set the heading typography settings.
  401. $user_theme_json_post_content = set_settings_array(
  402. $user_theme_json_post_content,
  403. array( 'styles', 'elements', 'h1', 'typography', 'fontFamily' ),
  404. $heading_font_family_variable
  405. );
  406. $user_theme_json_post_content = set_settings_array(
  407. $user_theme_json_post_content,
  408. array( 'styles', 'elements', 'h2', 'typography', 'fontFamily' ),
  409. $heading_font_family_variable
  410. );
  411. $user_theme_json_post_content = set_settings_array(
  412. $user_theme_json_post_content,
  413. array( 'styles', 'elements', 'h3', 'typography', 'fontFamily' ),
  414. $heading_font_family_variable
  415. );
  416. $user_theme_json_post_content = set_settings_array(
  417. $user_theme_json_post_content,
  418. array( 'styles', 'elements', 'h4', 'typography', 'fontFamily' ),
  419. $heading_font_family_variable
  420. );
  421. $user_theme_json_post_content = set_settings_array(
  422. $user_theme_json_post_content,
  423. array( 'styles', 'elements', 'h5', 'typography', 'fontFamily' ),
  424. $heading_font_family_variable
  425. );
  426. $user_theme_json_post_content = set_settings_array(
  427. $user_theme_json_post_content,
  428. array( 'styles', 'elements', 'h6', 'typography', 'fontFamily' ),
  429. $heading_font_family_variable
  430. );
  431. $user_theme_json_post_content = set_settings_array(
  432. $user_theme_json_post_content,
  433. array( 'styles', 'blocks', 'core/post-title', 'typography', 'fontFamily' ),
  434. $heading_font_family_variable
  435. );
  436. $user_theme_json_post_content = set_settings_array(
  437. $user_theme_json_post_content,
  438. array( 'styles', 'blocks', 'core/pullquote', 'typography', 'fontFamily' ),
  439. $heading_font_family_variable
  440. );
  441. //If the typeface choices === the default then we remove it instead
  442. if ( $body_value === $body_default && $heading_value === $heading_default ) {
  443. unset( $user_theme_json_post_content->settings->typography->fontFamilies );
  444. unset( $user_theme_json_post_content->styles->typography->fontFamily );
  445. unset( $user_theme_json_post_content->styles->elements->h1->typography->fontFamily );
  446. unset( $user_theme_json_post_content->styles->elements->h2->typography->fontFamily );
  447. unset( $user_theme_json_post_content->styles->elements->h3->typography->fontFamily );
  448. unset( $user_theme_json_post_content->styles->elements->h4->typography->fontFamily );
  449. unset( $user_theme_json_post_content->styles->elements->h5->typography->fontFamily );
  450. unset( $user_theme_json_post_content->styles->elements->h6->typography->fontFamily );
  451. unset( $user_theme_json_post_content->styles->blocks->{'core/button'}->typography->fontFamily );
  452. unset( $user_theme_json_post_content->styles->blocks->{'core/post-title'}->typography->fontFamily );
  453. unset( $user_theme_json_post_content->styles->blocks->{'core/pullquote'}->typography->fontFamily );
  454. }
  455. // Update the theme.json with the new settings.
  456. $user_theme_json_post->post_content = json_encode( $user_theme_json_post_content );
  457. wp_update_post( $user_theme_json_post );
  458. delete_transient( 'global_styles' );
  459. delete_transient( 'gutenberg_global_styles' );
  460. delete_transient( 'gutenberg_global_styles_' . get_stylesheet() );
  461. }
  462. }
  463. new GlobalStylesFontsCustomizer;