# contact-forms/trunk/block-editor.php

Contact Forms by Cimatti, version trunk. 66 lines.

- Page: https://pluginprobe.com/plugins/contact-forms/trunk/code/block-editor.php
- Raw: https://pluginprobe.com/plugins/contact-forms/trunk/raw/block-editor.php
- Modified: 2026-08-05T09:37:24+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/contact-forms/trunk/code/block-editor.php#L10-L20`.

```php
<?php
if ( ! defined( 'ABSPATH' ) ) exit;

/**
 * Register the Contact Forms block for the block editor.
 */
function accua_forms_register_block() {
	if ( ! function_exists( 'register_block_type' ) ) {
		return;
	}

	wp_register_script(
		'contact-forms-block-editor',
		plugins_url( 'block-editor/index.js', ACCUA_FORMS_FILE ),
		array( 'wp-blocks', 'wp-element', 'wp-components', 'wp-block-editor', 'wp-i18n', 'wp-server-side-render' ),
		ACCUA_FORMS_JS_VERSION,
		true
	);

	wp_set_script_translations( 'contact-forms-block-editor', 'contact-forms', plugin_dir_path( ACCUA_FORMS_FILE ) . 'languages' );

	// Pass form list to the block editor script
	$forms = get_option( 'accua_forms_saved_forms', array() );
	$form_list = array();
	foreach ( $forms as $fid => $form_data ) {
		$title = ! empty( $form_data['title'] ) ? $form_data['title'] : __( '(untitled)', 'contact-forms' );
		$form_list[] = array(
			'text'  => $title,
			'value' => (string) $fid,
		);
	}
	usort( $form_list, function( $a, $b ) {
		return (int) $b['value'] - (int) $a['value'];
	} );

	wp_add_inline_script(
		'contact-forms-block-editor',
		'var accua_forms_block_data = ' . wp_json_encode( array( 'forms' => $form_list ) ) . ';',
		'before'
	);

	// The "render" property of block.json is only honored from WordPress 6.1,
	// so on 5.9/6.0 (still supported per "Requires at least") the block would
	// register without a render callback and output nothing on the front end.
	// Passing the callback explicitly covers those versions; on 6.1+ the
	// explicit argument wins over the one derived from the metadata, and both
	// resolve to the same render.php.
	register_block_type(
		plugin_dir_path( ACCUA_FORMS_FILE ) . 'block-editor',
		array( 'render_callback' => 'accua_forms_render_block' )
	);
}
add_action( 'init', 'accua_forms_register_block' );

/**
 * Render the Contact Form block.
 *
 * @param array $attributes Block attributes (formId).
 * @return string The rendered form markup, or an empty string.
 */
function accua_forms_render_block( $attributes ) {
	ob_start();
	include plugin_dir_path( ACCUA_FORMS_FILE ) . 'block-editor/render.php';
	return ob_get_clean();
}

```
