$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(); }