← All changes
|
classes/controllers/FrmSimpleBlocksController.php
+11
-100
6.25
→
3.06.06
View file →
| @@ -1,15 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - die( 'You are not allowed to call this page directly.' ); | |
| 4 | -} | |
| 5 | 2 | |
| 6 | 3 | class FrmSimpleBlocksController { |
| 7 | 4 | |
| 8 | 5 | /** |
| 9 | 6 | * Enqueue Formidable Simple Blocks' js and CSS for editor in admin. |
| 10 | - * | |
| 11 | - * @return void | |
| 12 | 7 | */ |
| 13 | 8 | public static function block_editor_assets() { |
| 14 | 9 | $version = FrmAppHelper::plugin_version(); |
| 15 | 10 | |
| @@ -15,51 +10,23 @@ | ||
| 15 | 10 | |
| 16 | 11 | wp_register_script( |
| 17 | 12 | 'formidable-form-selector', |
| 18 | 13 | FrmAppHelper::plugin_url() . '/js/formidable_blocks.js', |
| 19 | - array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-components', 'wp-block-editor' ), | |
| 14 | + array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-components', 'wp-editor' ), | |
| 20 | 15 | $version, |
| 21 | 16 | true |
| 22 | 17 | ); |
| 23 | 18 | |
| 24 | - $icon = apply_filters( 'frm_icon', 'svg' ); | |
| 25 | - if ( 0 === strpos( $icon, 'data:image/svg+xml;base64,' ) ) { | |
| 26 | - $icon = ' ' . FrmAppHelper::get_menu_icon_class(); | |
| 27 | - } else { | |
| 28 | - $icon = str_replace( 'dashicons-', '', $icon ); | |
| 29 | - } | |
| 30 | - | |
| 19 | + $icon = str_replace( 'dashicons-', '', apply_filters( 'frm_icon', 'svg' ) ); | |
| 31 | 20 | $block_name = FrmAppHelper::get_menu_name(); |
| 32 | 21 | if ( $block_name === 'Formidable' ) { |
| 33 | 22 | $block_name = 'Formidable Forms'; |
| 34 | 23 | } |
| 35 | 24 | |
| 36 | - $modal_addon = self::get_addon_info( 185013 ); | |
| 37 | - $charts_addon = self::get_addon_info( 28248560 ); | |
| 38 | - $views_addon = FrmAddonsController::get_addon( 'views' ); | |
| 39 | - $views_addon_info = self::get_addon_info( 28027505 ); | |
| 40 | - | |
| 41 | 25 | $script_vars = array( |
| 42 | - 'forms' => self::get_forms_options(), | |
| 43 | - 'icon' => $icon, | |
| 44 | - 'name' => $block_name, | |
| 45 | - 'link' => FrmAppHelper::admin_upgrade_link( 'block' ), | |
| 46 | - 'url' => FrmAppHelper::plugin_url(), | |
| 47 | - 'modalAddon' => array( | |
| 48 | - 'link' => is_array( $modal_addon ) && isset( $modal_addon['link'] ) ? FrmAppHelper::admin_upgrade_link( 'block', $modal_addon['link'] ) : '', | |
| 49 | - 'hasAccess' => is_array( $modal_addon ) && ! empty( $modal_addon['url'] ), | |
| 50 | - ), | |
| 51 | - 'viewsAddon' => array( | |
| 52 | - 'link' => is_array( $views_addon_info ) && isset( $views_addon_info['link'] ) ? FrmAppHelper::admin_upgrade_link( 'block', $views_addon_info['link'] ) : '', | |
| 53 | - 'hasAccess' => is_array( $views_addon_info ) && ! empty( $views_addon_info['url'] ), | |
| 54 | - 'url' => ! empty( $views_addon_info['url'] ) ? $views_addon_info['url'] : '', | |
| 55 | - 'installed' => is_array( $views_addon ) && 'installed' === $views_addon['status']['type'], | |
| 56 | - ), | |
| 57 | - 'chartsAddon' => array( | |
| 58 | - 'link' => is_array( $charts_addon ) && isset( $charts_addon['link'] ) ? FrmAppHelper::admin_upgrade_link( 'block', $charts_addon['link'] ) : '', | |
| 59 | - 'hasAccess' => is_array( $charts_addon ) && ! empty( $charts_addon['url'] ), | |
| 60 | - 'installed' => class_exists( 'FrmChartsAppController' ), | |
| 61 | - ), | |
| 26 | + 'forms' => self::get_forms_options(), | |
| 27 | + 'icon' => $icon, | |
| 28 | + 'name' => $block_name, | |
| 62 | 29 | ); |
| 63 | 30 | |
| 64 | 31 | wp_localize_script( 'formidable-form-selector', 'formidable_form_selector', $script_vars ); |
| 65 | 32 | if ( function_exists( 'wp_set_script_translations' ) ) { |
| @@ -74,27 +41,8 @@ | ||
| 74 | 41 | ); |
| 75 | 42 | } |
| 76 | 43 | |
| 77 | 44 | /** |
| 78 | - * Gets addon info. | |
| 79 | - * | |
| 80 | - * @since 6.8 | |
| 81 | - * | |
| 82 | - * @param int $addon_id Addon ID. | |
| 83 | - * @return array|false | |
| 84 | - */ | |
| 85 | - private static function get_addon_info( $addon_id ) { | |
| 86 | - $api = new FrmFormApi(); | |
| 87 | - $addons = $api->get_api_info(); | |
| 88 | - | |
| 89 | - if ( ! is_array( $addons ) || ! array_key_exists( $addon_id, $addons ) ) { | |
| 90 | - return false; | |
| 91 | - } | |
| 92 | - | |
| 93 | - return $addons[ $addon_id ]; | |
| 94 | - } | |
| 95 | - | |
| 96 | - /** | |
| 97 | 45 | * Returns a filtered list of form options with the name as label and the id as value, sorted by label |
| 98 | 46 | * |
| 99 | 47 | * @return array |
| 100 | 48 | */ |
| @@ -117,15 +65,15 @@ | ||
| 117 | 65 | |
| 118 | 66 | /** |
| 119 | 67 | * Returns an array for a form with name as label and id as value |
| 120 | 68 | * |
| 121 | - * @param object $form | |
| 69 | + * @param $form | |
| 122 | 70 | * |
| 123 | 71 | * @return array |
| 124 | 72 | */ |
| 125 | 73 | private static function set_form_options( $form ) { |
| 126 | 74 | return array( |
| 127 | - 'label' => FrmFormsHelper::edit_form_link_label( $form ), | |
| 75 | + 'label' => $form->name, | |
| 128 | 76 | 'value' => $form->id, |
| 129 | 77 | ); |
| 130 | 78 | } |
| 131 | 79 | |
| @@ -130,10 +78,8 @@ | ||
| 130 | 78 | } |
| 131 | 79 | |
| 132 | 80 | /** |
| 133 | 81 | * Registers simple form block |
| 134 | - * | |
| 135 | - * @return void | |
| 136 | 82 | */ |
| 137 | 83 | public static function register_simple_form_block() { |
| 138 | 84 | if ( ! is_callable( 'register_block_type' ) ) { |
| 139 | 85 | return; |
| @@ -173,9 +119,10 @@ | ||
| 173 | 119 | |
| 174 | 120 | /** |
| 175 | 121 | * Renders a form given the specified attributes. |
| 176 | 122 | * |
| 177 | - * @param array $attributes | |
| 123 | + * @param $attributes | |
| 124 | + * | |
| 178 | 125 | * @return string |
| 179 | 126 | */ |
| 180 | 127 | public static function simple_form_render( $attributes ) { |
| 181 | 128 | if ( ! isset( $attributes['formId'] ) ) { |
| @@ -181,48 +128,12 @@ | ||
| 181 | 128 | if ( ! isset( $attributes['formId'] ) ) { |
| 182 | 129 | return ''; |
| 183 | 130 | } |
| 184 | 131 | |
| 185 | - ob_start(); | |
| 186 | - | |
| 187 | - /** | |
| 188 | - * @since 5.5.2 | |
| 189 | - * @param array $attributes | |
| 190 | - */ | |
| 191 | - do_action( 'frm_before_simple_form_render', $attributes ); | |
| 192 | - | |
| 193 | - $form = ob_get_clean(); | |
| 194 | - | |
| 195 | - if ( false === $form ) { | |
| 196 | - $form = ''; | |
| 197 | - } | |
| 198 | - | |
| 199 | 132 | $params = array_filter( $attributes ); |
| 200 | 133 | $params['id'] = $params['formId']; |
| 201 | 134 | unset( $params['formId'] ); |
| 202 | 135 | |
| 203 | - // Still pass false for title and description options if nothing is set, | |
| 204 | - // so a default doesn't overwrite the block option. | |
| 205 | - $params['title'] = ! empty( $params['title'] ); | |
| 206 | - $params['description'] = ! empty( $params['description'] ); | |
| 207 | - | |
| 208 | - $form .= FrmFormsController::get_form_shortcode( $params ); | |
| 209 | - if ( ! empty( $attributes['className'] ) ) { | |
| 210 | - $form = preg_replace( '/\bfrm_forms\b/', 'frm_forms ' . esc_attr( $attributes['className'] ), $form, 1 ); | |
| 211 | - } | |
| 212 | - return self::maybe_remove_fade_on_load_for_block_preview( $form ); | |
| 213 | - } | |
| 214 | - | |
| 215 | - /** | |
| 216 | - * Remove fade on load when /wp-json/wp/v2/block-renderer/formidable/simple-form is called. | |
| 217 | - * With the class set, the form never appears in the form block preview. | |
| 218 | - * | |
| 219 | - * @param string $form | |
| 220 | - * @return string | |
| 221 | - */ | |
| 222 | - private static function maybe_remove_fade_on_load_for_block_preview( $form ) { | |
| 223 | - if ( is_callable( 'wp_is_json_request' ) && wp_is_json_request() ) { | |
| 224 | - $form = str_replace( ' frm_logic_form ', ' ', $form ); | |
| 225 | - } | |
| 226 | - return $form; | |
| 136 | + $form = FrmFormsController::get_form_shortcode( $params ); | |
| 137 | + return str_replace( ' frm_logic_form ', ' ', $form ); // prevent the form from hiding | |
| 227 | 138 | } |
| 228 | 139 | } |