danielbachhuber / gutenberg-migration-guide

Documents WordPress Classic Editor integration points and their Gutenberg equivalents
183 stars 14 forks source link

editor.PostFeaturedImage append demo code doesn't allow pre-selected images #20

Open JSalvo220 opened 5 years ago

JSalvo220 commented 5 years ago

I have added our custom plugin to append a string to the Featured Image block (which was originally taken care of using 2 lines of PHP code - just saying).

Here is the JS file:

function addFeaturedImageDescription (original) { 
    return function() { 
        return (
            wp.element.createElement( 
                'div', 
                { key: 'outer' + Math.random() }, 
                [
                    _.extend( original( {} ), { key: 'my-key' } ),
                    'Suggested dimensions: 1104px x 736px'
                ]
            )
        );
    }
}

wp.hooks.addFilter( 
    'editor.PostFeaturedImage', 
    'pluginname/addFeaturedImageDescription', 
    addFeaturedImageDescription 
);

When I run that, I get the Featured button and my text - but when I try to edit a post that already has a featured image, it is not pre-selected. If I try to select an image, I get "t is not a function" in edit-post.min.js:12:7166.

Something is amiss from the code provided (as it works fine when I just return original). Can you please provide functional code on how to handle this.

Thanks.