| @@ -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,20 +10,14 @@ | ||
| 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 | } |
| @@ -33,13 +22,11 @@ | ||
| 33 | 22 | $block_name = 'Formidable Forms'; |
| 34 | 23 | } |
| 35 | 24 | |
| 36 | 25 | $script_vars = array( |
| 37 | - 'forms' => self::get_forms_options(), | |
| 38 | - 'icon' => $icon, | |
| 39 | - 'name' => $block_name, | |
| 40 | - 'link' => FrmAppHelper::admin_upgrade_link( 'block' ), | |
| 41 | - 'url' => FrmAppHelper::plugin_url(), | |
| 26 | + 'forms' => self::get_forms_options(), | |
| 27 | + 'icon' => $icon, | |
| 28 | + 'name' => $block_name, | |
| 42 | 29 | ); |
| 43 | 30 | |
| 44 | 31 | wp_localize_script( 'formidable-form-selector', 'formidable_form_selector', $script_vars ); |
| 45 | 32 | if ( function_exists( 'wp_set_script_translations' ) ) { |
| @@ -91,10 +78,8 @@ | ||
| 91 | 78 | } |
| 92 | 79 | |
| 93 | 80 | /** |
| 94 | 81 | * Registers simple form block |
| 95 | - * | |
| 96 | - * @return void | |
| 97 | 82 | */ |
| 98 | 83 | public static function register_simple_form_block() { |
| 99 | 84 | if ( ! is_callable( 'register_block_type' ) ) { |
| 100 | 85 | return; |
| @@ -134,9 +119,10 @@ | ||
| 134 | 119 | |
| 135 | 120 | /** |
| 136 | 121 | * Renders a form given the specified attributes. |
| 137 | 122 | * |
| 138 | - * @param array $attributes | |
| 123 | + * @param $attributes | |
| 124 | + * | |
| 139 | 125 | * @return string |
| 140 | 126 | */ |
| 141 | 127 | public static function simple_form_render( $attributes ) { |
| 142 | 128 | if ( ! isset( $attributes['formId'] ) ) { |
| @@ -142,32 +128,12 @@ | ||
| 142 | 128 | if ( ! isset( $attributes['formId'] ) ) { |
| 143 | 129 | return ''; |
| 144 | 130 | } |
| 145 | 131 | |
| 146 | - /** | |
| 147 | - * @since 5.5.2 | |
| 148 | - * @param array $attributes | |
| 149 | - */ | |
| 150 | - do_action( 'frm_before_simple_form_render', $attributes ); | |
| 151 | - | |
| 152 | 132 | $params = array_filter( $attributes ); |
| 153 | 133 | $params['id'] = $params['formId']; |
| 154 | 134 | unset( $params['formId'] ); |
| 155 | 135 | |
| 156 | 136 | $form = FrmFormsController::get_form_shortcode( $params ); |
| 157 | - return self::maybe_remove_fade_on_load_for_block_preview( $form ); | |
| 158 | - } | |
| 159 | - | |
| 160 | - /** | |
| 161 | - * Remove fade on load when /wp-json/wp/v2/block-renderer/formidable/simple-form is called. | |
| 162 | - * With the class set, the form never appears in the form block preview. | |
| 163 | - * | |
| 164 | - * @param string $form | |
| 165 | - * @return string | |
| 166 | - */ | |
| 167 | - private static function maybe_remove_fade_on_load_for_block_preview( $form ) { | |
| 168 | - if ( is_callable( 'wp_is_json_request' ) && wp_is_json_request() ) { | |
| 169 | - $form = str_replace( ' frm_logic_form ', ' ', $form ); | |
| 170 | - } | |
| 171 | - return $form; | |
| 137 | + return str_replace( ' frm_logic_form ', ' ', $form ); // prevent the form from hiding | |
| 172 | 138 | } |
| 173 | 139 | } |