Repository navigation
Expand file tree
/
Copy pathlib_editor.php
More file actions
65 lines (61 loc) · 2.34 KB
/
Copy pathlib_editor.php
File metadata and controls
65 lines (61 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/*
* Copyright (c) 2026 Bastian Germann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** Registers the cforms2/form Gutenberg block using PHP-only block registration (requires WordPress 7.0+). */
function cforms2_register_block() {
$forms = Cforms2\FormSettings::forms();
$form_names = array();
foreach ( $forms as $form ) {
$name = stripslashes( $form->name() );
if ( $name !== '' ) {
$form_names[] = $name;
}
}
if ( empty( $form_names ) ) {
return;
}
register_block_type(
'cforms2/form',
array(
'title' => __( 'cformsII Form', 'cforms2' ),
'attributes' => array(
'form_name' => array(
'label' => __( 'Form', 'cforms2' ),
'type' => 'string',
'enum' => $form_names,
'default' => $form_names[0],
),
),
'render_callback' => function ( $attributes ) {
if ( empty( $attributes['form_name'] ) ) {
return '';
}
// cforms2() is a legacy renderer that may echo output directly
// (e.g. the file upload size notice or a redirect script).
// Capture any stray output so it is returned as part of the
// block instead of leaking into the page or a REST response.
ob_start();
$form = cforms2( cforms2_check_form_name( $attributes['form_name'] ) );
return ob_get_clean() . $form;
},
'supports' => array(
'autoRegister' => true,
),
)
);
}
add_action( 'init', 'cforms2_register_block' );