Skip to content

Add support for importing and exporting fonts - #1054

Merged
wojtekn merged 3 commits into
trunkfrom
add/support-for-fonts-export
Mar 13, 2025
Merged

Add support for importing and exporting fonts#1054
wojtekn merged 3 commits into
trunkfrom
add/support-for-fonts-export

Conversation

@wojtekn

@wojtekn wojtekn commented Mar 11, 2025

Copy link
Copy Markdown
Contributor

Related issues

Proposed Changes

  • I propose to add support for importing and exporting fonts stored in wp-content/fonts/ directory.

Testing Instructions

  1. Create a Studio site
  2. Download font https://fonts.google.com/specimen/Big+Shoulders+Stencil and unpack it
  3. Copy the BigShouldersStencil-VariableFont_opsz,wght.ttf font file to wp-content/fonts
  4. Create a custom-font-loader.php plugin using the snippet shared below and activate it
  5. Confirm that site's frontend uses a custom font
  6. Export the site in Import / Export tab
  7. Confirm that archive includes the wp-content/fonts directory with the font
  8. Create a new Studio site by importing the archive
  9. Confirm the site uses a custom font
  10. Test if Playground, Wpress and Local import still works fine.
<?php
/**
 * Plugin Name: Custom Font Loader
 * Description: A simple plugin to load Big Shoulders Stencil Variable Font from wp-content/fonts directory.
 * Version: 1.0
 * Author: Your Name
 */

function load_custom_fonts() {
	// Register the custom stylesheet
	wp_register_style('custom-fonts', false);
	wp_enqueue_style('custom-fonts');

	// Define the custom CSS
	$custom_css = "
    @font-face {
        font-family: 'Big Shoulders Stencil';
        src: url('" . content_url('/fonts/BigShouldersStencil-VariableFont_opsz,wght.ttf') . "') format('truetype');
        font-weight: 100 900;
        font-style: normal;
    }

    body {
        font-family: 'Big Shoulders Stencil', sans-serif;
    }";

	wp_add_inline_style('custom-fonts', $custom_css);
}
add_action('wp_enqueue_scripts', 'load_custom_fonts');

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@wojtekn wojtekn self-assigned this Mar 11, 2025
@wojtekn
wojtekn requested a review from a team March 12, 2025 11:16
@wojtekn
wojtekn marked this pull request as ready for review March 12, 2025 11:17

@ivan-ottinger ivan-ottinger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great app improvement!

The changes look good and work correctly: the font file is included in the export and imports as it should as well.

I did not observe any regressions. All imports still work as before.

normalize( '/tmp/extracted/sql/wp_posts.sql' ),
],
wpConfig: normalize( '/tmp/extraced/wp-config.php' ),
wpConfig: normalize( '/tmp/extracted/wp-config.php' ),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@wojtekn
wojtekn merged commit 2315da9 into trunk Mar 13, 2025
@wojtekn
wojtekn deleted the add/support-for-fonts-export branch March 13, 2025 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants