PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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 +73 -19 6.4.2 → trunk View file →
@@ -21,9 +21,10 @@
21 21 true
22 22 );
23 23
24 24 $icon = apply_filters( 'frm_icon', 'svg' );
25 - if ( 0 === strpos( $icon, 'data:image/svg+xml;base64,' ) ) {
25 +
26 + if ( str_starts_with( $icon, 'data:image/svg+xml;base64,' ) ) {
26 27 $icon = ' ' . FrmAppHelper::get_menu_icon_class();
27 28 } else {
28 29 $icon = str_replace( 'dashicons-', '', $icon );
29 30 }
@@ -28,31 +29,62 @@
28 29 $icon = str_replace( 'dashicons-', '', $icon );
29 30 }
30 31
31 32 $block_name = FrmAppHelper::get_menu_name();
33 +
32 34 if ( $block_name === 'Formidable' ) {
33 35 $block_name = 'Formidable Forms';
34 36 }
35 37
36 - $modal_addon = self::get_modal_addon_info();
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 );
37 42
38 43 $script_vars = array(
39 - 'forms' => self::get_forms_options(),
40 - 'icon' => $icon,
41 - 'name' => $block_name,
42 - 'link' => FrmAppHelper::admin_upgrade_link( 'block' ),
43 - 'url' => FrmAppHelper::plugin_url(),
44 - 'modalAddon' => array(
45 - 'link' => FrmAppHelper::admin_upgrade_link( 'block', $modal_addon['link'] ),
46 - 'hasAccess' => ! empty( $modal_addon['url'] ),
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'] ),
47 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 + ),
48 64 );
49 65
50 66 wp_localize_script( 'formidable-form-selector', 'formidable_form_selector', $script_vars );
67 +
51 68 if ( function_exists( 'wp_set_script_translations' ) ) {
52 69 wp_set_script_translations( 'formidable-form-selector', 'formidable' );
53 70 }
71 + }
54 72
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 +
55 87 wp_enqueue_style(
56 88 'formidable_block-editor-css',
57 89 FrmAppHelper::plugin_url() . '/css/frm_blocks.css',
58 90 array( 'wp-edit-blocks' ),
@@ -60,18 +92,19 @@
60 92 );
61 93 }
62 94
63 95 /**
64 - * Gets the modal addon info.
96 + * Gets addon info.
65 97 *
66 - * @since 6.3.2
98 + * @since 6.8
67 99 *
100 + * @param int $addon_id Addon ID.
101 + *
68 102 * @return array|false
69 103 */
70 - private static function get_modal_addon_info() {
71 - $api = new FrmFormApi();
72 - $addons = $api->get_api_info();
73 - $addon_id = 185013;
104 + private static function get_addon_info( $addon_id ) {
105 + $api = new FrmFormApi();
106 + $addons = $api->get_api_info();
74 107
75 108 if ( ! is_array( $addons ) || ! array_key_exists( $addon_id, $addons ) ) {
76 109 return false;
77 110 }
@@ -103,9 +136,9 @@
103 136
104 137 /**
105 138 * Returns an array for a form with name as label and id as value
106 139 *
107 - * @param $form
140 + * @param object $form
108 141 *
109 142 * @return array
110 143 */
111 144 private static function set_form_options( $form ) {
@@ -160,8 +193,9 @@
160 193 /**
161 194 * Renders a form given the specified attributes.
162 195 *
163 196 * @param array $attributes
197 + *
164 198 * @return string
165 199 */
166 200 public static function simple_form_render( $attributes ) {
167 201 if ( ! isset( $attributes['formId'] ) ) {
@@ -167,19 +201,38 @@
167 201 if ( ! isset( $attributes['formId'] ) ) {
168 202 return '';
169 203 }
170 204
205 + ob_start();
206 +
171 207 /**
172 208 * @since 5.5.2
209 + *
173 210 * @param array $attributes
174 211 */
175 212 do_action( 'frm_before_simple_form_render', $attributes );
176 213
214 + $form = ob_get_clean();
215 +
216 + if ( false === $form ) {
217 + $form = '';
218 + }
219 +
177 220 $params = array_filter( $attributes );
178 221 $params['id'] = $params['formId'];
179 222 unset( $params['formId'] );
180 223
181 - $form = FrmFormsController::get_form_shortcode( $params );
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 +
182 235 return self::maybe_remove_fade_on_load_for_block_preview( $form );
183 236 }
184 237
185 238 /**
@@ -186,13 +239,14 @@
186 239 * Remove fade on load when /wp-json/wp/v2/block-renderer/formidable/simple-form is called.
187 240 * With the class set, the form never appears in the form block preview.
188 241 *
189 242 * @param string $form
243 + *
190 244 * @return string
191 245 */
192 246 private static function maybe_remove_fade_on_load_for_block_preview( $form ) {
193 247 if ( is_callable( 'wp_is_json_request' ) && wp_is_json_request() ) {
194 - $form = str_replace( ' frm_logic_form ', ' ', $form );
248 + return str_replace( ' frm_logic_form ', ' ', $form );
195 249 }
196 250 return $form;
197 251 }
198 252 }