add_meta_boxes action with refresh on save

So I managed to cobble something together with a bit of javascript… It’s hacky but somewhat elegant I think. add_action(‘admin_init’, function () { if ( current_user_can(“send_notifications”) ) { $post_types = [“post”, “go_live”]; foreach ($post_types as $post_type) { add_meta_box( ‘cabtv_notif_on_post’, ‘Notifications’, function ($post) { wp_nonce_field( ‘cabtv_notif_metabox’, ‘cabtv_notif_metabox’ ); $sent = (bool) get_post_meta( $post->ID, ‘cabtv_notifications_sent’, true ); … Read more

Gutenberg Custom Block

to 1. You closed registerBlockType too early and to avoid further react errors, you should print your return in the same line as return in your edit/save functions. var el = wp.element.createElement; wp.blocks.registerBlockType(‘test/blocks’, { title: ‘Test Blocks’, icon: ‘smiley’, category: ‘common’, attributes: { content: {type: ‘string’} }, edit: function(props) { return el( ‘div’, {}, el( … Read more

Gutenberg block get categories in SelectControl

The problem is that calling wp.data.select triggers a fetch and the data takes some time to be available. Until that happens the value returned is an empty array. My suggestion here is to use wp.data.useSelect, which is a React hook made specifically for this, so the component re-renders when there is a change in the … Read more

Gutenberg: How to Change Post Status Programmatically?

You need to call savePost after calling editPost. Referring to the source’s way of handling it:https://github.com/WordPress/gutenberg/blob/trunk/packages/editor/src/components/post-visibility/index.js it shows savePost being called right after changing the visibility. In practice: import { PluginPostStatusInfo } from ‘@wordpress/edit-post’; import { __ } from ‘@wordpress/i18n’; import { registerPlugin } from ‘@wordpress/plugins’; import { ToggleControl } from ‘@wordpress/components’; import { useSelect, … Read more