function ( $attributes ) {
$id = sanitize_key( (string) ( $attributes['formId'] ?? '' ) );
if ( '' === $id ) {
return '';
}
$wrapper = get_block_wrapper_attributes( array( 'class' => 'wp-block-stackmime-form' ) );
return '
' . stackmime_forms_render( $id ) . '
';
},
)
);
},
20
);
add_action(
'enqueue_block_editor_assets',
function () {
$forms = array();
foreach ( stackmime_forms_all() as $id => $form ) {
$forms[] = array(
'id' => (string) $id,
'title' => (string) $form['title'],
);
}
wp_add_inline_script(
'stackmime-form-editor-script',
'window.StackMimeFormsBlock = ' . wp_json_encode(
array(
'forms' => $forms,
'newUrl' => current_user_can( 'manage_options' ) ? admin_url( 'admin.php?page=stackmime-forms-builder' ) : '',
)
) . ';',
'before'
);
wp_set_script_translations( 'stackmime-form-editor-script', 'stackmime-forms' );
}
);
// Form styles inside the editor canvas (which is an iframe), so the preview matches the site.
add_action(
'enqueue_block_assets',
function () {
if ( is_admin() ) {
stackmime_forms_enqueue_style();
}
}
);