PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/controllers/FrmSimpleBlocksController.php +12 -106 6.295.0 View file →
@@ -6,10 +6,8 @@
6 6 class FrmSimpleBlocksController {
7 7
8 8 /**
9 9 * Enqueue Formidable Simple Blocks' js and CSS for editor in admin.
10 - *
11 - * @return void
12 10 */
13 11 public static function block_editor_assets() {
14 12 $version = FrmAppHelper::plugin_version();
15 13
@@ -15,76 +13,32 @@
15 13
16 14 wp_register_script(
17 15 'formidable-form-selector',
18 16 FrmAppHelper::plugin_url() . '/js/formidable_blocks.js',
19 - array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-components', 'wp-block-editor' ),
17 + array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-components', 'wp-editor' ),
20 18 $version,
21 19 true
22 20 );
23 21
24 - $icon = apply_filters( 'frm_icon', 'svg' );
25 -
26 - if ( str_starts_with( $icon, 'data:image/svg+xml;base64,' ) ) {
27 - $icon = ' ' . FrmAppHelper::get_menu_icon_class();
28 - } else {
29 - $icon = str_replace( 'dashicons-', '', $icon );
30 - }
31 -
22 + $icon = str_replace( 'dashicons-', '', apply_filters( 'frm_icon', 'svg' ) );
32 23 $block_name = FrmAppHelper::get_menu_name();
33 -
34 24 if ( $block_name === 'Formidable' ) {
35 25 $block_name = 'Formidable Forms';
36 26 }
37 27
38 - $modal_addon = self::get_addon_info( 185013 );
39 - $charts_addon = self::get_addon_info( 28248560 );
40 - $views_addon = FrmAddonsController::get_addon( 'views' );
41 - $views_addon_info = self::get_addon_info( 28027505 );
42 -
43 28 $script_vars = array(
44 - 'forms' => self::get_forms_options(),
45 - 'icon' => $icon,
46 - 'name' => $block_name,
47 - 'link' => FrmAppHelper::admin_upgrade_link( 'block' ),
48 - 'url' => FrmAppHelper::plugin_url(),
49 - 'modalAddon' => array(
50 - 'link' => is_array( $modal_addon ) && isset( $modal_addon['link'] ) ? FrmAppHelper::admin_upgrade_link( 'block', $modal_addon['link'] ) : '',
51 - 'hasAccess' => is_array( $modal_addon ) && ! empty( $modal_addon['url'] ),
52 - ),
53 - 'viewsAddon' => array(
54 - 'link' => is_array( $views_addon_info ) && isset( $views_addon_info['link'] ) ? FrmAppHelper::admin_upgrade_link( 'block', $views_addon_info['link'] ) : '',
55 - 'hasAccess' => is_array( $views_addon_info ) && ! empty( $views_addon_info['url'] ),
56 - 'url' => ! empty( $views_addon_info['url'] ) ? $views_addon_info['url'] : '',
57 - 'installed' => is_array( $views_addon ) && 'installed' === $views_addon['status']['type'],
58 - ),
59 - 'chartsAddon' => array(
60 - 'link' => is_array( $charts_addon ) && isset( $charts_addon['link'] ) ? FrmAppHelper::admin_upgrade_link( 'block', $charts_addon['link'] ) : '',
61 - 'hasAccess' => is_array( $charts_addon ) && ! empty( $charts_addon['url'] ),
62 - 'installed' => class_exists( 'FrmChartsAppController' ),
63 - ),
29 + 'forms' => self::get_forms_options(),
30 + 'icon' => $icon,
31 + 'name' => $block_name,
32 + 'link' => FrmAppHelper::admin_upgrade_link( 'block' ),
33 + 'url' => FrmAppHelper::plugin_url(),
64 34 );
65 35
66 36 wp_localize_script( 'formidable-form-selector', 'formidable_form_selector', $script_vars );
67 -
68 37 if ( function_exists( 'wp_set_script_translations' ) ) {
69 38 wp_set_script_translations( 'formidable-form-selector', 'formidable' );
70 39 }
71 - }
72 40
73 - /**
74 - * Enqueue Formidable Simple Blocks' JS and CSS for the content.
75 - *
76 - * @since 6.26
77 - *
78 - * @return void
79 - */
80 - public static function block_assets() {
81 - if ( ! is_admin() ) {
82 - return;
83 - }
84 -
85 - $version = FrmAppHelper::plugin_version();
86 -
87 41 wp_enqueue_style(
88 42 'formidable_block-editor-css',
89 43 FrmAppHelper::plugin_url() . '/css/frm_blocks.css',
90 44 array( 'wp-edit-blocks' ),
@@ -92,28 +46,8 @@
92 46 );
93 47 }
94 48
95 49 /**
96 - * Gets addon info.
97 - *
98 - * @since 6.8
99 - *
100 - * @param int $addon_id Addon ID.
101 - *
102 - * @return array|false
103 - */
104 - private static function get_addon_info( $addon_id ) {
105 - $api = new FrmFormApi();
106 - $addons = $api->get_api_info();
107 -
108 - if ( ! is_array( $addons ) || ! array_key_exists( $addon_id, $addons ) ) {
109 - return false;
110 - }
111 -
112 - return $addons[ $addon_id ];
113 - }
114 -
115 - /**
116 50 * Returns a filtered list of form options with the name as label and the id as value, sorted by label
117 51 *
118 52 * @return array
119 53 */
@@ -136,15 +70,15 @@
136 70
137 71 /**
138 72 * Returns an array for a form with name as label and id as value
139 73 *
140 - * @param object $form
74 + * @param $form
141 75 *
142 76 * @return array
143 77 */
144 78 private static function set_form_options( $form ) {
145 79 return array(
146 - 'label' => FrmFormsHelper::edit_form_link_label( $form ),
80 + 'label' => $form->name,
147 81 'value' => $form->id,
148 82 );
149 83 }
150 84
@@ -149,10 +83,8 @@
149 83 }
150 84
151 85 /**
152 86 * Registers simple form block
153 - *
154 - * @return void
155 87 */
156 88 public static function register_simple_form_block() {
157 89 if ( ! is_callable( 'register_block_type' ) ) {
158 90 return;
@@ -192,9 +124,9 @@
192 124
193 125 /**
194 126 * Renders a form given the specified attributes.
195 127 *
196 - * @param array $attributes
128 + * @param $attributes
197 129 *
198 130 * @return string
199 131 */
200 132 public static function simple_form_render( $attributes ) {
@@ -201,38 +133,13 @@
201 133 if ( ! isset( $attributes['formId'] ) ) {
202 134 return '';
203 135 }
204 136
205 - ob_start();
206 -
207 - /**
208 - * @since 5.5.2
209 - *
210 - * @param array $attributes
211 - */
212 - do_action( 'frm_before_simple_form_render', $attributes );
213 -
214 - $form = ob_get_clean();
215 -
216 - if ( false === $form ) {
217 - $form = '';
218 - }
219 -
220 137 $params = array_filter( $attributes );
221 138 $params['id'] = $params['formId'];
222 139 unset( $params['formId'] );
223 140
224 - // Still pass false for title and description options if nothing is set,
225 - // So a default doesn't overwrite the block option.
226 - $params['title'] = ! empty( $params['title'] );
227 - $params['description'] = ! empty( $params['description'] );
228 -
229 - $form .= FrmFormsController::get_form_shortcode( $params );
230 -
231 - if ( ! empty( $attributes['className'] ) ) {
232 - $form = preg_replace( '/\bfrm_forms\b/', 'frm_forms ' . esc_attr( $attributes['className'] ), $form, 1 );
233 - }
234 -
141 + $form = FrmFormsController::get_form_shortcode( $params );
235 142 return self::maybe_remove_fade_on_load_for_block_preview( $form );
236 143 }
237 144
238 145 /**
@@ -239,14 +146,13 @@
239 146 * Remove fade on load when /wp-json/wp/v2/block-renderer/formidable/simple-form is called.
240 147 * With the class set, the form never appears in the form block preview.
241 148 *
242 149 * @param string $form
243 - *
244 150 * @return string
245 151 */
246 152 private static function maybe_remove_fade_on_load_for_block_preview( $form ) {
247 153 if ( is_callable( 'wp_is_json_request' ) && wp_is_json_request() ) {
248 - return str_replace( ' frm_logic_form ', ' ', $form );
154 + $form = str_replace( ' frm_logic_form ', ' ', $form );
249 155 }
250 156 return $form;
251 157 }
252 158 }