Custom plugin not appearing

A few parameters need tweaking in midstory_fade_animation_script_register(): function midstory_fade_animation_script_register() { // Handle, script location, dependecies, version, in footer boolean wp_enqueue_script( ‘midstory-animation-fade-block’, plugin_dir_url( __FILE__ ) . ‘/midstory_animation_fade.js’, array( ‘wp-blocks’, ‘wp-i18n’, ‘wp-editor’ ), ‘1.0.1’, false ); } The script location needs a slash between the plugin folder and the filename. What you were calling “WordPress refresh?” is … Read more

How to disable blocks in Gutenberg editor for specific post type

Put this in your Theme’s functions.php file. add_filter( ‘allowed_block_types_all’, ‘rt_allowed_block_types’, 25, 2 ); function rt_allowed_block_types( $allowed_blocks, $editor_context ) { if( ‘custom_post_type’ === $editor_context->post->post_type ) { $allowed_blocks = array( ‘core/image’, ‘core/paragraph’, ‘core/heading’, ‘core/list’ ); return $allowed_blocks; } else { return; } } Here’s what it’s doing. The filter allowed_block_types_all is filtering what block types are allowed. … Read more

Trying to save an object into post meta with wp.data.dispatch(‘core/editor’).editpost

As stated in the Object Meta Type section of the Modifying Responses page in the REST API Handbook: When registering object meta, setting the type to object is not sufficient, you also need to inform WordPress of what properties to allow. This is done by writing a JSON Schema when registering the metadata. Interestingly, register_meta() … Read more

Have parent block’s isSelected be true if an innerblock is selected?

If you only need to know whether or not an inner-block is selected, you can leverage the core/block-editor store’s hasSelectedInnerBlock() selector. For example, if using a useSelect() hook in a functional component, that might look as such: import { useSelect } from ‘@wordpress/data’; export default function Edit( { isSelected, clientId } ) { const is_inner_block_selected … Read more

FormTokenField passing objects to value property

In short, the “title” which the documentation refers to is a title attribute on the <span> which is rendered for the token, which is to say that the token { value: ‘29654’, title: ‘Post Title’ } will (rhetorically) render as <span title=”Post Title”>29654</span> In order to display “Post Title” as the inner text in the … Read more

Get post ancestors in the Block Editor

August 20, 2022 Update: For completeness, I added a JavaScript/Gutenberg solution which does what the findParent() function in question tries to do, i.e. find the top ancestor. You can find the code below the “Original Answer” section. Original Answer The block editor doesn’t (currently) have a function equivalent to get_post_ancestors(), and yes you could create … Read more