最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

block editor - Deprecated function not working in Gutenberg

programmeradmin2浏览0评论

I'm change the default attributes:

const blockAttrs = {
        avatarSize: {
            type: 'number',
            default: 120, // 70 -> 120
        },
        //other attrs
      };

Deprecated function:

deprecated: [
            {
                attributes: {
                    ...blockAttrs,
                    avatarSize: {
                        type: 'number',
                        default: 70
                    }
                },
                save: function ( { attributes } ) {}
            }
        ]

But when i refresh post, block still display error:

Someone

I'm change the default attributes:

const blockAttrs = {
        avatarSize: {
            type: 'number',
            default: 120, // 70 -> 120
        },
        //other attrs
      };

Deprecated function:

deprecated: [
            {
                attributes: {
                    ...blockAttrs,
                    avatarSize: {
                        type: 'number',
                        default: 70
                    }
                },
                save: function ( { attributes } ) {}
            }
        ]

But when i refresh post, block still display error:

Someone

Share Improve this question edited Oct 16, 2019 at 2:22 pdutie94 asked Oct 15, 2019 at 10:16 pdutie94pdutie94 13 bronze badges 1
  • Can you post the entire block code? – Welcher Commented Oct 21, 2019 at 20:35
Add a comment  | 

2 Answers 2

Reset to default 1

Looking at the documentation from https://developer.wordpress.org/block-editor/developers/block-api/block-deprecation/

I think you may need the following

 migrate( { text } ) {
            return {
                content: text
            };
        },

So in your case:

migrate( { avatarSize } ) {
            avatarSize: {
                    type: 'number',
                    default: 70
                }  content: text
            };
        },

Hopefully points you in the correct direction

Your save function needs to return a valid React component or null.

save: function ( { attributes } ) {}

should be

save: function ( { attributes } ) { return null; }
发布评论

评论列表(0)

  1. 暂无评论