← All changes
|
classes/controllers/FrmSimpleBlocksController.php
+10
-122
6.32
→
4.01.02
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,76 +10,30 @@ | ||
| 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 | - | |
| 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 | - | |
| 19 | + $icon = str_replace( 'dashicons-', '', apply_filters( 'frm_icon', 'svg' ) ); | |
| 32 | 20 | $block_name = FrmAppHelper::get_menu_name(); |
| 33 | - | |
| 34 | 21 | if ( $block_name === 'Formidable' ) { |
| 35 | 22 | $block_name = 'Formidable Forms'; |
| 36 | 23 | } |
| 37 | 24 | |
| 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 | 25 | $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 | - ), | |
| 26 | + 'forms' => self::get_forms_options(), | |
| 27 | + 'icon' => $icon, | |
| 28 | + 'name' => $block_name, | |
| 64 | 29 | ); |
| 65 | 30 | |
| 66 | 31 | wp_localize_script( 'formidable-form-selector', 'formidable_form_selector', $script_vars ); |
| 67 | - | |
| 68 | 32 | if ( function_exists( 'wp_set_script_translations' ) ) { |
| 69 | 33 | wp_set_script_translations( 'formidable-form-selector', 'formidable' ); |
| 70 | 34 | } |
| 71 | - } | |
| 72 | 35 | |
| 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 | 36 | wp_enqueue_style( |
| 88 | 37 | 'formidable_block-editor-css', |
| 89 | 38 | FrmAppHelper::plugin_url() . '/css/frm_blocks.css', |
| 90 | 39 | array( 'wp-edit-blocks' ), |
| @@ -92,28 +41,8 @@ | ||
| 92 | 41 | ); |
| 93 | 42 | } |
| 94 | 43 | |
| 95 | 44 | /** |
| 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 | 45 | * Returns a filtered list of form options with the name as label and the id as value, sorted by label |
| 117 | 46 | * |
| 118 | 47 | * @return array |
| 119 | 48 | */ |
| @@ -136,15 +65,15 @@ | ||
| 136 | 65 | |
| 137 | 66 | /** |
| 138 | 67 | * Returns an array for a form with name as label and id as value |
| 139 | 68 | * |
| 140 | - * @param object $form | |
| 69 | + * @param $form | |
| 141 | 70 | * |
| 142 | 71 | * @return array |
| 143 | 72 | */ |
| 144 | 73 | private static function set_form_options( $form ) { |
| 145 | 74 | return array( |
| 146 | - 'label' => FrmFormsHelper::edit_form_link_label( $form ), | |
| 75 | + 'label' => $form->name, | |
| 147 | 76 | 'value' => $form->id, |
| 148 | 77 | ); |
| 149 | 78 | } |
| 150 | 79 | |
| @@ -149,10 +78,8 @@ | ||
| 149 | 78 | } |
| 150 | 79 | |
| 151 | 80 | /** |
| 152 | 81 | * Registers simple form block |
| 153 | - * | |
| 154 | - * @return void | |
| 155 | 82 | */ |
| 156 | 83 | public static function register_simple_form_block() { |
| 157 | 84 | if ( ! is_callable( 'register_block_type' ) ) { |
| 158 | 85 | return; |
| @@ -192,9 +119,9 @@ | ||
| 192 | 119 | |
| 193 | 120 | /** |
| 194 | 121 | * Renders a form given the specified attributes. |
| 195 | 122 | * |
| 196 | - * @param array $attributes | |
| 123 | + * @param $attributes | |
| 197 | 124 | * |
| 198 | 125 | * @return string |
| 199 | 126 | */ |
| 200 | 127 | public static function simple_form_render( $attributes ) { |
| @@ -201,52 +128,13 @@ | ||
| 201 | 128 | if ( ! isset( $attributes['formId'] ) ) { |
| 202 | 129 | return ''; |
| 203 | 130 | } |
| 204 | 131 | |
| 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 | 132 | $params = array_filter( $attributes ); |
| 221 | 133 | $params['id'] = $params['formId']; |
| 222 | 134 | unset( $params['formId'] ); |
| 223 | 135 | |
| 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'] ); | |
| 136 | + $form = FrmFormsController::get_form_shortcode( $params ); | |
| 228 | 137 | |
| 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 | - | |
| 235 | - return self::maybe_remove_fade_on_load_for_block_preview( $form ); | |
| 236 | - } | |
| 237 | - | |
| 238 | - /** | |
| 239 | - * Remove fade on load when /wp-json/wp/v2/block-renderer/formidable/simple-form is called. | |
| 240 | - * With the class set, the form never appears in the form block preview. | |
| 241 | - * | |
| 242 | - * @param string $form | |
| 243 | - * | |
| 244 | - * @return string | |
| 245 | - */ | |
| 246 | - private static function maybe_remove_fade_on_load_for_block_preview( $form ) { | |
| 247 | - if ( is_callable( 'wp_is_json_request' ) && wp_is_json_request() ) { | |
| 248 | - return str_replace( ' frm_logic_form ', ' ', $form ); | |
| 249 | - } | |
| 250 | - return $form; | |
| 138 | + return str_replace( ' frm_logic_form ', ' ', $form ); // prevent the form from hiding | |
| 251 | 139 | } |
| 252 | 140 | } |