diff --git a/blocks/library/html/index.js b/blocks/library/html/index.js index e3eb6a408db8c2..aaee705981bacd 100644 --- a/blocks/library/html/index.js +++ b/blocks/library/html/index.js @@ -41,6 +41,9 @@ registerBlockType( 'core/html', { this.state = { preview: false, }; + const allowedHtmlTags = new Set( Object.keys( wp.editor.allowedPostHtml ) ); + const unsafeHtmlTags = [ 'script', 'iframe', 'form', 'input', 'style' ]; + this.disallowedHtmlTags = unsafeHtmlTags.filter( tag => ! allowedHtmlTags.has( tag ) ); } preview() { @@ -77,6 +80,17 @@ registerBlockType( 'core/html', {

{ __( 'Arbitrary HTML code.' ) }

+ { ! wp.editor.canUnfilteredHtml && this.disallowedHtmlTags.length > 0 && +

+ { __( 'Some HTML tags are not permitted, including:' ) } + { ' ' } + { this.disallowedHtmlTags.map( ( tag, i ) => + { 0 !== i && ', ' } + { tag } + ) } + { '.' } +

+ }
} diff --git a/lib/client-assets.php b/lib/client-assets.php index d13492e66f0058..5d35d6a9f69621 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -445,6 +445,10 @@ function gutenberg_scripts_and_styles( $hook ) { 'before' ); + // Export data required by the Custom HTML block. + wp_add_inline_script( 'wp-editor', sprintf( 'wp.editor.canUnfilteredHtml = %s;', wp_json_encode( current_user_can( 'unfiltered_html' ) ) ) ); + wp_add_inline_script( 'wp-editor', sprintf( 'wp.editor.allowedPostHtml = %s;', wp_json_encode( wp_kses_allowed_html( 'post' ) ) ) ); + // Initialize the editor. wp_add_inline_script( 'wp-editor', 'wp.api.init().done( function() { wp.editor.createEditorInstance( \'editor\', window._wpGutenbergPost ); } );' );