wp-customize-fonts.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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. if ( $this->fonts && $this->font_settings ) {
  212. wp_enqueue_script( 'customizer-preview-fonts', get_template_directory_uri() . '/inc/customizer/wp-customize-fonts-preview.js', array( 'customize-preview' ) );
  213. wp_localize_script( 'customizer-preview-fonts', 'googleFonts', $this->fonts );
  214. wp_localize_script( 'customizer-preview-fonts', 'fontSettings', $this->font_settings );
  215. }
  216. }
  217. function customize_control_js() {
  218. if ( $this->font_control_default_body && $this->font_control_default_heading ) {
  219. wp_enqueue_script( 'customizer-font-control', get_template_directory_uri() . '/inc/customizer/wp-customize-fonts-control.js', array( 'customize-controls' ), null, true );
  220. wp_localize_script( 'customizer-font-control', 'fontControlDefaultBody', array( $this->font_control_default_body ) );
  221. wp_localize_script( 'customizer-font-control', 'fontControlDefaultHeading', array( $this->font_control_default_heading ) );
  222. }
  223. }
  224. function enqueue_google_fonts() {
  225. wp_enqueue_style( 'blockbase-google-fonts', $this->google_fonts_url(), array(), null );
  226. }
  227. function create_customization_style_element( $wp_customize ) {
  228. if ( $this->font_settings ) {
  229. wp_enqueue_style( 'global-styles-fonts-customizations', ' ', array( 'global-styles' ) ); // This needs to load after global_styles, hence the dependency
  230. $css = 'body {';
  231. $css .= '--wp--preset--font-family--body-font:' . $this->font_settings['body'] . ';';
  232. $css .= '--wp--preset--font-family--heading-font:' . $this->font_settings['heading'] . ';';
  233. $css .= '}';
  234. wp_add_inline_style( 'global-styles-fonts-customizations', $css );
  235. }
  236. }
  237. function update_font_settings( $wp_customize ) {
  238. $body_setting = $wp_customize->get_setting( $this->section_key . 'body' );
  239. $heading_setting = $wp_customize->get_setting( $this->section_key . 'heading' );
  240. if ( $body_setting && $heading_setting ) {
  241. $body_value = $body_setting->post_value();
  242. if ( $body_value ) {
  243. $body_font_setting = $this->fonts[ $body_value ];
  244. $this->font_settings['body'] = $body_font_setting['fontFamily'];
  245. }
  246. $heading_value = $heading_setting->post_value();
  247. if ( $heading_value ) {
  248. $heading_font_setting = $this->fonts[ $heading_value ];
  249. $this->font_settings['heading'] = $heading_font_setting['fontFamily'];
  250. }
  251. }
  252. }
  253. function google_fonts_url() {
  254. $font_families = array();
  255. foreach ( $this->fonts as $font ) {
  256. if ( ! empty( $font['google'] ) ) {
  257. $font_families[] = $font['google'];
  258. }
  259. }
  260. $font_families[] = 'display=swap';
  261. // Make a single request for the theme fonts.
  262. return esc_url_raw( 'https://fonts.googleapis.com/css2?' . implode( '&', $font_families ) );
  263. }
  264. function initialize( $wp_customize ) {
  265. $theme = wp_get_theme();
  266. //Add a Section to the Customizer for these bits
  267. $wp_customize->add_section(
  268. $this->section_key,
  269. array(
  270. 'capability' => 'edit_theme_options',
  271. 'description' => sprintf( __( 'Font Customization for %1$s', 'blockbase' ), $theme->name ),
  272. 'title' => __( 'Fonts', 'blockbase' ),
  273. )
  274. );
  275. $merged_json = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data()->get_raw_data();
  276. $theme_font_families = $merged_json['settings']['typography']['fontFamilies']['theme'];
  277. $body_font_default_array = array_filter( $theme_font_families, function( $font_family ) {
  278. return $font_family['slug'] === "body-font";
  279. } );
  280. $body_font_default = array_shift( $body_font_default_array );
  281. $heading_font_default_array = array_filter( $theme_font_families, function( $font_family ) {
  282. return $font_family['slug'] === "heading-font";
  283. } );
  284. $heading_font_default = array_shift( $heading_font_default_array );
  285. // See if the child theme has been updated. If not then show a notice.
  286. if ( ! $body_font_default && ! $heading_font_default ) {
  287. $wp_customize->add_control(
  288. $this->section_key . '-v1-blockbase-format-notice',
  289. array(
  290. 'type' => 'hidden',
  291. 'description' => '<div class="notice notice-warning">
  292. <p>' . __( "Your theme needs to be updated before you can customize fonts", 'blockbase' ) . '</p>
  293. </div>',
  294. 'settings' => array(),
  295. 'section' => $this->section_key,
  296. )
  297. );
  298. return;
  299. }
  300. if ( array_key_exists( 'user', $merged_json['settings']['typography']['fontFamilies'] ) ) {
  301. $merged_font_families = $merged_json['settings']['typography']['fontFamilies']['user'];
  302. $body_font_selected_array = array_filter( $merged_font_families, function( $font_family ) {
  303. return $font_family['slug'] === "body-font";
  304. } );
  305. $body_font_selected = array_shift( $body_font_selected_array );
  306. $heading_font_selected_array = array_filter( $merged_font_families, function( $font_family ) {
  307. return $font_family['slug'] === "heading-font";
  308. } );
  309. $heading_font_selected = array_shift( $heading_font_selected_array );
  310. } else {
  311. $body_font_selected = $body_font_default;
  312. $heading_font_selected = $heading_font_default;
  313. }
  314. // If there's no selected font then the user is probably using the old format for font customization
  315. if ( $body_font_selected && $heading_font_selected ) {
  316. $body_font_selected_font_family = $body_font_selected['fontFamily'];
  317. $body_font_selected_font_slug = $body_font_selected['fontSlug'];
  318. $heading_font_selected_font_family = $heading_font_selected['fontFamily'];
  319. $heading_font_selected_font_slug = $heading_font_selected['fontSlug'];
  320. } else {
  321. $body_font_selected_font_family = null;
  322. $body_font_selected_font_slug = null;
  323. $heading_font_selected_font_family = null;
  324. $heading_font_selected_font_slug = null;
  325. }
  326. $this->font_settings = array(
  327. 'body' => $body_font_selected_font_family,
  328. 'heading' => $heading_font_selected_font_family,
  329. );
  330. // Add a reset button
  331. $this->font_control_default_body = $body_font_default['fontSlug'];
  332. $this->font_control_default_heading = $heading_font_default['fontSlug'];
  333. $wp_customize->add_control(
  334. $this->section_key . '-reset-button',
  335. array(
  336. 'type' => 'button',
  337. 'settings' => array(),
  338. 'section' => $this->section_key,
  339. 'input_attrs' => array(
  340. 'value' => __( 'Reset to Default', 'blockbase' ),
  341. 'class' => 'button button-link',
  342. ),
  343. )
  344. );
  345. $this->add_setting_and_control( $wp_customize, 'body', __( 'Body font', 'blockbase' ), $body_font_default['fontSlug'], $body_font_selected_font_slug, 'sanitize_title' );
  346. $this->add_setting_and_control( $wp_customize, 'heading', __( 'Heading font', 'blockbase' ), $heading_font_default['fontSlug'], $heading_font_selected_font_slug, 'sanitize_title' );
  347. }
  348. function get_font_family( $array, $configuration ) {
  349. $variable = get_settings_array( $array, $configuration );
  350. $slug = preg_replace( '/var\(--wp--preset--font-family--(.*)\)/', '$1', $variable );
  351. if ( ! isset( $this->fonts[ $slug ] ) ) {
  352. $this->fonts[ $slug ] = $this->build_font_from_theme_data( $slug, $configuration );
  353. }
  354. return $this->fonts[ $slug ];
  355. }
  356. function build_font_from_theme_data( $slug, $configuration ) {
  357. $new_font = array();
  358. $font_families = $configuration['settings']['typography']['fontFamilies']['theme'];
  359. foreach ( $font_families as $font_family ) {
  360. if ( $font_family['slug'] === $slug ) {
  361. $new_font['fontFamily'] = $font_family['fontFamily'];
  362. $new_font['name'] = $font_family['name'];
  363. if ( ! empty( $font_family['google'] ) ) {
  364. $new_font['google'] = $font_family['google'];
  365. }
  366. }
  367. }
  368. $new_font['slug'] = $slug;
  369. return $new_font;
  370. }
  371. function add_setting_and_control( $wp_customize, $name, $label, $default, $user_value, $sanitize_callback ) {
  372. $setting_name = $this->section_key . $name;
  373. $global_styles_setting = new WP_Customize_Global_Styles_Setting(
  374. $wp_customize,
  375. $setting_name,
  376. array(
  377. 'default' => $default,
  378. 'user_value' => $user_value
  379. )
  380. );
  381. $wp_customize->add_setting( $global_styles_setting,
  382. array(
  383. 'sanitize_callback' => $sanitize_callback
  384. )
  385. );
  386. $choices = array();
  387. foreach ( $this->fonts as $font_slug => $font_setting ) {
  388. $choices[ $font_slug ] = $font_setting['name'];
  389. }
  390. $wp_customize->add_control(
  391. $setting_name,
  392. array(
  393. 'section' => $this->section_key,
  394. 'label' => $label,
  395. 'type' => 'select',
  396. 'choices' => $choices,
  397. )
  398. );
  399. // Update the setting to the dirty value.
  400. // This is needed to preserve the settings when other Customizer settings change.
  401. $dirty_value = $wp_customize->get_setting( $setting_name )->post_value();
  402. if ( ! empty( $dirty_value ) ) {
  403. $wp_customize->get_setting( $setting_name )->user_value = $dirty_value;
  404. }
  405. }
  406. function handle_customize_save_after( $wp_customize ) {
  407. $body_value = $wp_customize->get_setting( $this->section_key . 'body' )->value();
  408. $heading_value = $wp_customize->get_setting( $this->section_key . 'heading' )->value();
  409. if ( ! isset( $body_value ) && ! isset( $heading_value ) ) {
  410. return;
  411. }
  412. $body_default = $wp_customize->get_setting( $this->section_key . 'body' )->default;
  413. $heading_default = $wp_customize->get_setting( $this->section_key . 'heading' )->default;
  414. if ( ! isset( $body_value ) ) {
  415. $body_value = $body_default;
  416. }
  417. if ( ! isset( $heading_value ) ) {
  418. $heading_value = $heading_default;
  419. }
  420. $body_setting = $this->fonts[ $body_value ];
  421. $body_setting['name'] = "Body (" . $body_setting['name'] . ")";
  422. $body_setting['fontSlug'] = $body_setting['slug'];
  423. $body_setting['slug'] = "body-font";
  424. $heading_setting = $this->fonts[ $heading_value ];
  425. $heading_setting['name'] = "Heading (" . $heading_setting['name'] . ")";
  426. $heading_setting['fontSlug'] = $heading_setting['slug'];
  427. $heading_setting['slug'] = "heading-font";
  428. // Set up variables for the theme.json.
  429. $font_families = array(
  430. $body_setting,
  431. $heading_setting,
  432. );
  433. $body_font_family_variable = 'var(--wp--preset--font-family--' . $body_setting['slug'] . ')';
  434. $heading_font_family_variable = 'var(--wp--preset--font-family--' . $heading_setting['slug'] . ')';
  435. // Get the user's theme.json from the CPT.
  436. $user_custom_post_type_id = WP_Theme_JSON_Resolver_Gutenberg::get_user_custom_post_type_id();
  437. $user_theme_json_post = get_post( $user_custom_post_type_id );
  438. $user_theme_json_post_content = json_decode( $user_theme_json_post->post_content );
  439. // Set meta settings.
  440. $user_theme_json_post_content->version = 1;
  441. $user_theme_json_post_content->isGlobalStylesUserThemeJSON = true;
  442. // Set the typography settings.
  443. $user_theme_json_post_content = set_settings_array(
  444. $user_theme_json_post_content,
  445. array( 'settings', 'typography', 'fontFamilies' ),
  446. $font_families
  447. );
  448. //If the typeface choices === the default then we remove it instead
  449. if ( $body_value === $body_default && $heading_value === $heading_default ) {
  450. unset( $user_theme_json_post_content->settings->typography->fontFamilies );
  451. // These lines need to stay for backwards compatibility.
  452. unset( $user_theme_json_post_content->styles->typography->fontFamily );
  453. unset( $user_theme_json_post_content->styles->elements->h1->typography->fontFamily );
  454. unset( $user_theme_json_post_content->styles->elements->h2->typography->fontFamily );
  455. unset( $user_theme_json_post_content->styles->elements->h3->typography->fontFamily );
  456. unset( $user_theme_json_post_content->styles->elements->h4->typography->fontFamily );
  457. unset( $user_theme_json_post_content->styles->elements->h5->typography->fontFamily );
  458. unset( $user_theme_json_post_content->styles->elements->h6->typography->fontFamily );
  459. unset( $user_theme_json_post_content->styles->blocks->{'core/button'}->typography->fontFamily );
  460. unset( $user_theme_json_post_content->styles->blocks->{'core/post-title'}->typography->fontFamily );
  461. unset( $user_theme_json_post_content->styles->blocks->{'core/pullquote'}->typography->fontFamily );
  462. }
  463. // Update the theme.json with the new settings.
  464. $user_theme_json_post->post_content = json_encode( $user_theme_json_post_content );
  465. wp_update_post( $user_theme_json_post );
  466. delete_transient( 'global_styles' );
  467. delete_transient( 'gutenberg_global_styles' );
  468. delete_transient( 'gutenberg_global_styles_' . get_stylesheet() );
  469. }
  470. }
  471. new GlobalStylesFontsCustomizer;