PluginProbe
Contact Forms by Cimatti / 2.2.32
Contact Forms by Cimatti v2.2.32
2.3.6 2.3.5 2.3.0 2.2.32 2.2.4 2.2.0 2.1.2 2.1.1 trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 All 62 releases
contact-forms / block-editor.php

block-editor.php in Contact Forms by Cimatti 2.2.32, at block-editor.php

45 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit;
3
4 /**
5 * Register the Contact Forms block for the block editor.
6 */
7 function accua_forms_register_block() {
8 if ( ! function_exists( 'register_block_type' ) ) {
9 return;
10 }
11
12 wp_register_script(
13 'contact-forms-block-editor',
14 plugins_url( 'block-editor/index.js', ACCUA_FORMS_FILE ),
15 array( 'wp-blocks', 'wp-element', 'wp-components', 'wp-block-editor', 'wp-i18n', 'wp-server-side-render' ),
16 ACCUA_FORMS_JS_VERSION,
17 true
18 );
19
20 wp_set_script_translations( 'contact-forms-block-editor', 'contact-forms', plugin_dir_path( ACCUA_FORMS_FILE ) . 'languages' );
21
22 // Pass form list to the block editor script
23 $forms = get_option( 'accua_forms_saved_forms', array() );
24 $form_list = array();
25 foreach ( $forms as $fid => $form_data ) {
26 $title = ! empty( $form_data['title'] ) ? $form_data['title'] : __( '(untitled)', 'contact-forms' );
27 $form_list[] = array(
28 'text' => $title,
29 'value' => (string) $fid,
30 );
31 }
32 usort( $form_list, function( $a, $b ) {
33 return (int) $b['value'] - (int) $a['value'];
34 } );
35
36 wp_add_inline_script(
37 'contact-forms-block-editor',
38 'var accua_forms_block_data = ' . wp_json_encode( array( 'forms' => $form_list ) ) . ';',
39 'before'
40 );
41
42 register_block_type( plugin_dir_path( ACCUA_FORMS_FILE ) . 'block-editor' );
43 }
44 add_action( 'init', 'accua_forms_register_block' );
45