Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an error notice to the editor when theme.json parsing fail #32369

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private static function read_json_file( $file_path ) {
$json_decoding_error = json_last_error();
if ( JSON_ERROR_NONE !== $json_decoding_error ) {
error_log( 'Error when decoding file schema: ' . json_last_error_msg() );
add_action( 'admin_footer', array( __CLASS__, '_json_decoding_error_notice' ) );
return $config;
}

Expand Down Expand Up @@ -530,6 +531,34 @@ public static function clean_cached_data() {
self::$theme_json_i18n = null;
}

/**
* Print a notice if there was an error decoding the theme.json file.
*
* @return void
*/
public static function _json_decoding_error_notice() {
?>
<div id="theme-json-notice" class="notice notice-error is-dismissible hidden">
<p>
<?php
printf(
/* translators: theme.json. */
esc_html__( 'There was an error decoding the %s file from your theme.', 'gutenberg' ),
'<code>theme.json</code>'
);
?>
</p>
</div>
<script>
setTimeout( function() {
document.getElementById( 'theme-json-notice' ).classList.remove( 'hidden' );
document.querySelector( '.interface-interface-skeleton__header' )
.insertAdjacentElement('afterend', document.getElementById( 'theme-json-notice' ) );
}, 3000 );
</script>
<?php
}

}

add_action( 'switch_theme', array( 'WP_Theme_JSON_Resolver_Gutenberg', 'clean_cached_data' ) );
6 changes: 5 additions & 1 deletion packages/edit-site/src/components/editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@
padding-left: 16px;
padding-right: 16px;
}
@include editor-left(".edit-site .components-editor-notices__snackbar")
@include editor-left(".edit-site .components-editor-notices__snackbar");

#theme-json-notice {
margin: 0;
}