user roles - Custom Gutenberg Block and unfiltered_html capability

admin2025-06-03  2

This is more a "am I understanding this right" kind of question:

When I create a custum Gutenberg Block that should be used by an user of role Editor(which has no unfiltered_html capability on a multisite), I am limited to whatever html wordpress allows this user to post.

Example:

My save function has jsx like this:

<p style={myStyles}>{props.attributes.text}</p>

which gets rendered to

<p style="opacity:0.5">Hello World</p>

This would get filtered out and the block would not work.

Additionally, this Block would work for a Super-Admin and when he creates a post using this block and an Editor comes in later to adapt it, it would break the block, because it expects the mark-up that was filtered out.

Is this the expected behaviour?

This is more a "am I understanding this right" kind of question:

When I create a custum Gutenberg Block that should be used by an user of role Editor(which has no unfiltered_html capability on a multisite), I am limited to whatever html wordpress allows this user to post.

Example:

My save function has jsx like this:

<p style={myStyles}>{props.attributes.text}</p>

which gets rendered to

<p style="opacity:0.5">Hello World</p>

This would get filtered out and the block would not work.

Additionally, this Block would work for a Super-Admin and when he creates a post using this block and an Editor comes in later to adapt it, it would break the block, because it expects the mark-up that was filtered out.

Is this the expected behaviour?

Share Improve this question edited Feb 7, 2019 at 13:38 mtthias asked Feb 7, 2019 at 11:12 mtthiasmtthias 1862 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The recommended way of using RichText Component inside save function is -

     <RichText.Content
            tagName="p"
            style={ styles }
            className={ className ? className : undefined }
            value={ content }
            dir={ direction }
        />

See, how this core paragraph block is doing it. Instead of using normal HTML use RichText Content on text fields

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748918945a314814.html

最新回复(0)