Skip to content

Instantly share code, notes, and snippets.

@ironprogrammer
Last active September 22, 2023 00:00
Show Gist options
  • Select an option

  • Save ironprogrammer/8aa37a77cf3989efaadd32f1fa7028ee to your computer and use it in GitHub Desktop.

Select an option

Save ironprogrammer/8aa37a77cf3989efaadd32f1fa7028ee to your computer and use it in GitHub Desktop.
Test mu-plugin for GB PR #53273
<?php
/**
* GB PR #53273
* Add additional sanitization for settings.typography.fontFamilies
* https://github.com/WordPress/gutenberg/pull/53273
*
* Based on test info provided in https://github.com/WordPress/gutenberg/issues/52798.
*
* === REMOVE THIS PLUGIN FILE AFTER TESTING ===
*/
add_action( 'init', 'test_gb_53273' );
function test_gb_53273() {
if ( ! class_exists( 'WP_Theme_JSON_Gutenberg' ) ) {
return;
}
$font_families = [
array (
'badKey4' => 'I am Evil!!!!',
'name' => 'Piazzolla',
'slug' => 'piazzolla',
'fontFamily' => 'Piazzolla',
'fontFace' => array(
array(
'badKey5' => 'I am Evil!!!!',
'fontFamily' => 'Piazzolla',
'fontStyle' => 'italic',
'fontWeight' => '400',
'src' => 'https://example.com/font.ttf',
),
),
)
];
$theme_data = array(
'version' => '2',
'badKey2' => 'I am Evil!!!!',
'settings' => array(
'badKey2' => 'I am Evil!!!!',
'typography' => array(
'badKey3' => 'I am Evil!!!!',
'fontFamilies' => $font_families,
),
),
);
echo '<h1>Test <code>settings.typography.fontFamilies</code> sanitation with <a href="https://github.com/WordPress/gutenberg/pull/53273">GB PR #53273</a></h1>';
// Creates a new WP_Theme_JSON object with the new fonts to leverage sanitization and validation.
$theme_json = new WP_Theme_JSON( $theme_data );
$data = $theme_json->get_data();
echo '<h2>Using <code>WP_Theme_JSON</code></h2>';
echo '<pre>';
print_r($data);
echo '</pre>';
// Now use WP_Theme_JSON_Gutenberg to test the PR.
$theme_json = new WP_Theme_JSON_Gutenberg( $theme_data );
$data = $theme_json->get_data();
echo '<h2>Using <code>WP_Theme_JSON_Gutenberg</code></h2>';
echo '<pre>';
print_r($data);
echo '</pre>';
wp_die();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment