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

How to change the selected Template using javascript?

You are already using the correct action, i.e. wp.data.dispatch( ‘core/editor’ ).editPost(), however, you should instead change the property named template. I.e. wp.data.dispatch( ‘core/editor’ ).editPost( { template: ‘article.php’ } ) Yes, _wp_page_template is the meta key in the database, but in the REST API, a property named template exists in place of direct access on that … Read more

WordPress custom Block showing error in Posts editor but working in Pages editor

This should work: <?php if ( is_user_logged_in() ) { echo “This isn’t editable in here”; } else { include get_template_directory() . ‘/template-parts/blocks/form/from/functions.php’; if ( ! isset( $_POST[‘firstFormDisplayed’] ) ) { // we haven’t yet displayed the form asking for numbers, so do that now. displayFirstForm(); } else { // we’ve got the numbers, but not … Read more