create-block-theme icon indicating copy to clipboard operation
create-block-theme copied to clipboard

Add `blueprint.json` file to enable plugin previews

Open mikachan opened this issue 2 years ago • 7 comments

We should consider adding a blueprint.json file to enable plugin previews on the WordPress.org directory.

More info here: https://make.wordpress.org/meta/2023/11/22/plugin-directory-preview-button-revisited/

mikachan avatar Nov 23 '23 17:11 mikachan

I tried testing how Create Block Theme plugin works in Playground.

https://playground.wordpress.net/?plugin=create-block-theme

Unfortunately, most of the features seem to fail due to errors... 😅 Many of Create Block Theme's functions update files and directories, so they might not be compatible with Playground at the moment.

t-hamano avatar Jan 07 '24 12:01 t-hamano

Thanks for testing this out! Could you explain more about which features failed? I think many of the theme creation tools work fine in Playground (creating a new theme, cloning the current theme, creating a blank theme), but I don't think adding custom fonts from both Google and local files works yet. Maybe we could disable these if the plugin is active in a Playground environment (I'm not sure how easy this would be!)

mikachan avatar Jan 08 '24 08:01 mikachan

Sorry, there may have been a problem with the environment or network when I tested it. Many features seem to work correctly.

  • ✅ Export {theme_name}
  • ✅ Create child of {theme_name}
  • ✅ Clone {theme_name}
  • ✅ Overrite {theme_name}
  • ✅ Create blank theme
  • ✅ Create a style variation
  • ❌ Add Google Font: An error occoured.
    Fatal error: Uncaught TypeError: rename(): Argument #1 ($from) must be of type string, WP_Error given in /wordpress/wp-content/plugins/create-block-theme/admin/class-manage-fonts.php:250
    
  • ⚠️ Although a warning error is displayed, the font appears to be installed correctly.

https://github.com/WordPress/create-block-theme/assets/54422211/2f04794b-f84e-49ab-949e-bf28841a35cb

t-hamano avatar Jan 08 '24 11:01 t-hamano

No worries!

❌ Add Google Font: An error occoured.

Yes, this is the same error I was seeing. I thought this was solved with https://github.com/WordPress/wordpress-playground/pull/724, but perhaps this is a different error. It seems to be a problem with accessing the download_url() function, but then it's also strange that the font is installed correctly afterward 😅

mikachan avatar Jan 13 '24 22:01 mikachan

❌ Add Google Font: An error occoured.

From what I've researched, this problem seems to have a similar cause to https://github.com/WordPress/wordpress-playground/issues/396 reported in the Playground repository.

The Create Block Theme plugin attempts to download the font via the download_url() function:

https://github.com/WordPress/create-block-theme/blob/cef22d8a4f622589df4f486a2315141650f80cc9/admin/class-manage-fonts.php#L245

My understanding is that the download_url() function internally calls the wp_http_validate_url() function to check if the URL (fonts.gstatic.com) is safe. However, as discussed in this comment, Playground returns an internal IP (172.29.3.0), so http_request_host_is_external() becomes false, and as a result, the download_url() function returns a WP_Error object.

To resolve this, we would add the following hook to this plugin to force fonts.gstatic.com to be considered an external (safe) host.

function custom_http_request_host_is_external( $external, $host ) {
	if ( 'fonts.gstatic.com' === $host ) {
		return true;
	}
	return $external;
}
add_filter( 'http_request_host_is_external', 'custom_http_request_host_is_external', 10, 2 );

Pinging @adamziel: I see that you have submitted https://github.com/WordPress/wordpress-playground/issues/400 to fundamentally resolve this issue. Is it okay to add a filter like this for now to make the Create Block Theme plugin work properly in the plugin preview environment? 🙇

t-hamano avatar Jan 14 '24 05:01 t-hamano

For network features you'll need to enable the networking access by adding networking=yes to the URL, for example:

https://playground.wordpress.net/?plugin=create-block-theme&url=/wp-admin/admin.php?page=create-block-theme&networking=yes

With that option in place, I was able to interact with Google Fonts in the Playground preview. You can also use it in the Blueprints as follows:

{
    "features": {
        "networking": true
    }
}

Let me know if that solves the issue here.

adamziel avatar Jan 30 '24 11:01 adamziel

@adamziel Thank you for telling me that! I had missed that parameter. After some more testing, I'd like to submit a PR to add a blueprint to this plugin.

t-hamano avatar Jan 30 '24 12:01 t-hamano