Forum Replies Created
-
AuthorPosts
-
[email protected]
ParticipantFound a bug as a result of the above where the default data wont save. Another hacky workaround is to edit the compiled JS file in mb-blocks/assets/blocks.js adding the below just after line 160
$(el.current).find('input').trigger('change');(I realise it's not a good idea to edit plugins)
[email protected]
ParticipantHave a workaround for this, but it's not ideal as to implement you'll need edit the plugin.
I install the plugin into the theme so it's not an issue, but if it's via the WP Plugins system the edits will get overridden.
File: mb-blocks/src/Block.php
Find
$attributes = wp_unslash( $attributes );on line 81 and add the following after that.`
if ( empty($attributes['data']) && ! empty($this->meta_box['defaults']) ) {
$attributes['data'] = $this->meta_box['defaults'];
}`Then on the block config array, you can add a
defaultsarray key containing any default values you want the block to render with. In doing this you bypass the UX issue described.[email protected]
ParticipantHi Sam - I normally stick the colours in an array and return these from a php function, so it can go into both
add_theme_support('editor-color-palette', theme_colours());and also the 'palettes' atrribute for the metabox color field.Doing it like this is an ok hack, normally id just use the theme_colours() function to populate a select field though as that gives named colours e.g. 'Primary' => 'is-primary-color' and add the value/class to the html element
[email protected]
ParticipantQuick/dirty work around for this would be to just use the mb_blocks_preview JS callback.
e.g.
function init__container(e) { console.log('init container'); console.log($(e.target)); if ( $(e.target).find('> .components-placeholder').length > 0 ) { setTimeout(() => { $('.mb-block-edit select, .mb-block-edit input').trigger('change') }, 1000); } } $(document).on('mb_blocks_preview/odin-container', init__container); -
AuthorPosts