PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 1.5.4
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v1.5.4
3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / includes / class-evf-form-block.php
everest-forms / includes Last commit date
abstracts 6 years ago admin 6 years ago export 6 years ago fields 6 years ago interfaces 8 years ago libraries 7 years ago log-handlers 8 years ago shortcodes 6 years ago templates 7 years ago class-everest-forms.php 6 years ago class-evf-ajax.php 6 years ago class-evf-autoloader.php 7 years ago class-evf-background-updater.php 7 years ago class-evf-cache-helper.php 8 years ago class-evf-deprecated-action-hooks.php 7 years ago class-evf-deprecated-filter-hooks.php 7 years ago class-evf-emails.php 7 years ago class-evf-fields.php 7 years ago class-evf-form-block.php 6 years ago class-evf-form-handler.php 6 years ago class-evf-form-task.php 6 years ago class-evf-forms-features.php 7 years ago class-evf-frontend-scripts.php 7 years ago class-evf-install.php 6 years ago class-evf-integrations.php 7 years ago class-evf-log-levels.php 8 years ago class-evf-logger.php 8 years ago class-evf-post-types.php 7 years ago class-evf-privacy.php 7 years ago class-evf-session-handler.php 7 years ago class-evf-shortcodes.php 7 years ago class-evf-smart-tags.php 7 years ago class-evf-template-loader.php 7 years ago class-evf-validation.php 8 years ago evf-conditional-functions.php 7 years ago evf-core-functions.php 6 years ago evf-deprecated-functions.php 7 years ago evf-entry-functions.php 6 years ago evf-formatting-functions.php 7 years ago evf-notice-functions.php 6 years ago evf-template-functions.php 7 years ago evf-template-hooks.php 7 years ago evf-update-functions.php 6 years ago
class-evf-form-block.php
159 lines
1 <?php
2 /**
3 * EverestForm Gutenberg blocks
4 *
5 * @package EverstForms\Class
6 * @version 1.3.4
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * Guten Block Class.
13 */
14 class EVF_Form_Block {
15
16 /**
17 * Constructor.
18 */
19 public function __construct() {
20 add_action( 'init', array( $this, 'register_block' ) );
21 add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) );
22 }
23
24 /**
25 * Register the block and its scripts.
26 */
27 public function register_block() {
28 if ( ! function_exists( 'register_block_type' ) ) {
29 return;
30 }
31
32 register_block_type(
33 'everest-forms/form-selector',
34 array(
35 'attributes' => array(
36 'formId' => array(
37 'type' => 'string',
38 ),
39 'className' => array(
40 'type' => 'string',
41 ),
42 'displayTitle' => array(
43 'type' => 'boolean',
44 ),
45 'displayDescription' => array(
46 'type' => 'boolean',
47 ),
48 ),
49 'editor_style' => 'everest-forms-block-editor',
50 'editor_script' => 'everest-forms-block-editor',
51 'render_callback' => array( $this, 'get_form_html' ),
52 )
53 );
54 }
55
56 /**
57 * Load Gutenberg block scripts.
58 */
59 public function enqueue_block_editor_assets() {
60 wp_register_style(
61 'everest-forms-block-editor',
62 EVF()->plugin_url() . '/assets/css/everest-forms.css',
63 array( 'wp-edit-blocks' ),
64 defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? filemtime( EVF()->plugin_path() . '/assets/css/everest-forms.css' ) : EVF_VERSION
65 );
66
67 wp_register_script(
68 'everest-forms-block-editor',
69 EVF()->plugin_url() . '/assets/js/admin/gutenberg/form-block.min.js',
70 array( 'wp-blocks', 'wp-element', 'wp-i18n', 'wp-editor', 'wp-components' ),
71 defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? filemtime( EVF()->plugin_path() . '/assets/js/admin/gutenberg/form-block.min.js' ) : EVF_VERSION,
72 true
73 );
74
75 $form_block_data = array(
76 'forms' => EVF()->form->get( '', array( 'order' => 'DESC' ) ),
77 'i18n' => array(
78 'title' => esc_html__( 'Everest Forms', 'everest-forms' ),
79 'description' => esc_html__( 'Select and display one of your forms.', 'everest-forms' ),
80 'form_keywords' => array(
81 esc_html__( 'form', 'everest-forms' ),
82 esc_html__( 'contact', 'everest-forms' ),
83 esc_html__( 'survey', 'everest-forms' ),
84 ),
85 'form_select' => esc_html__( 'Select a Form', 'everest-forms' ),
86 'form_settings' => esc_html__( 'Form Settings', 'everest-forms' ),
87 'form_selected' => esc_html__( 'Form', 'everest-forms' ),
88 'show_title' => esc_html__( 'Show Title', 'everest-forms' ),
89 'show_description' => esc_html__( 'Show Description', 'everest-forms' ),
90 ),
91 );
92 wp_localize_script( 'everest-forms-block-editor', 'evf_form_block_data', $form_block_data );
93 }
94
95 /**
96 * Get form HTML to display in a Gutenberg block.
97 *
98 * @param array $attr Attributes passed by Gutenberg block.
99 * @return string
100 */
101 public function get_form_html( $attr ) {
102 $form_id = ! empty( $attr['formId'] ) ? absint( $attr['formId'] ) : 0;
103
104 if ( empty( $form_id ) ) {
105 return '';
106 }
107
108 // Wrapper classes.
109 $classes = 'everest-forms';
110 if ( isset( $attr['className'] ) ) {
111 $classes .= ' ' . $attr['className'];
112 }
113
114 $is_gb_editor = defined( 'REST_REQUEST' ) && REST_REQUEST && ! empty( $_REQUEST['context'] ) && 'edit' === $_REQUEST['context'];
115 $title = ! empty( $attr['displayTitle'] ) ? true : false;
116 $description = ! empty( $attr['displayDescription'] ) ? true : false;
117
118 // Disable form fields if called from the Gutenberg editor.
119 if ( $is_gb_editor ) {
120 add_filter(
121 'everest_forms_frontend_container_class',
122 function ( $classes ) {
123 $classes[] = 'evf-gutenberg-form-selector';
124 $classes[] = 'evf-container-full';
125 return $classes;
126 }
127 );
128 add_action(
129 'everest_forms_frontend_output',
130 function () {
131 echo '<fieldset disabled>';
132 },
133 3
134 );
135 add_action(
136 'everest_forms_frontend_output',
137 function () {
138 echo '</fieldset>';
139 },
140 30
141 );
142 }
143
144 return EVF_Shortcodes::shortcode_wrapper(
145 array( 'EVF_Shortcode_Form', 'output' ),
146 array(
147 'id' => $form_id,
148 'title' => $title,
149 'description' => $description,
150 ),
151 array(
152 'class' => evf_sanitize_classes( $classes ),
153 )
154 );
155 }
156 }
157
158 new EVF_Form_Block();
159