Skip to content

Commit

Permalink
List disallowed HTML tags when user cannot unfiltered_html
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Jul 1, 2017
1 parent e129e78 commit 98b8959
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions blocks/library/html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -77,6 +80,17 @@ registerBlockType( 'core/html', {
<InspectorControls key="inspector">
<BlockDescription>
<p>{ __( 'Arbitrary HTML code.' ) }</p>
{ ! wp.editor.canUnfilteredHtml && this.disallowedHtmlTags.length > 0 &&
<p>
<span>{ __( 'Some HTML tags are not permitted, including:' ) }</span>
{ ' ' }
{ this.disallowedHtmlTags.map( ( tag, i ) => <span key={ i }>
{ 0 !== i && ', ' }
<code>{ tag }</code>
</span> ) }
{ '.' }
</p>
}
</BlockDescription>
</InspectorControls>
}
Expand Down
4 changes: 4 additions & 0 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ); } );' );

Expand Down

0 comments on commit 98b8959

Please sign in to comment.