How can I obtain an option (get_option) inside a block viewScript?

So, if I want to add any custom styles or scripts in a block’s CSS or JS file, I usually add them in the PHP file associated with the block (the render property in block.json). Add the following code to the PHP file at the end – $beautiful_option = get_option(‘beautiful’); wp_add_inline_script(‘some-script’, ‘const BEAUTIFUL_OPTION=’ .$beautiful_option, ‘before’); … Read more

How to import the imagesLoaded and Masonry libs that come with WP in a Gutenberg block?

When developing a block with @wordpress/scripts, wp-scripts uses @wordpress/dependency-extraction-webpack-plugin to allow you to import dependencies from WordPress by replacing the import statements with references to the global variables loaded by the enqueued scripts. For example, this: import { useEffect } from ‘@wordpress/element’ Will become: const { useEffect } = wp.element; And wp-element will be added … Read more

Get field added via attachment_fields_to_edit filter in Gutenberg

Yes, you’re right that the slimImageObject function is the reason why you’re seeing/getting only those limited list of props. But don’t worry, you can use wp.data.select( ‘core’ ).getMedia( <attachment id> ) to get the attribution meta (and any other meta or props in the full attachment object). Here’s an example that worked for me: items.map((item, … Read more