app = $app; } public function registerScripts() { $app = $this->app; // We will just register the scripts here. We will not load any scripts from here $fluentFormPublicCss = fluentFormMix('css/fluent-forms-public.css'); $fluentFormPublicDefaultCss = fluentFormMix('css/fluentform-public-default.css'); if (is_rtl()) { $fluentFormPublicCss = fluentFormMix('css/fluent-forms-public-rtl.css'); $fluentFormPublicDefaultCss = fluentFormMix('css/fluentform-public-default-rtl.css'); } wp_register_style( 'fluent-form-styles', $fluentFormPublicCss, [], FLUENTFORM_VERSION ); wp_register_style( 'fluentform-public-default', $fluentFormPublicDefaultCss, [], FLUENTFORM_VERSION ); wp_register_script( 'fluent-form-submission', fluentFormMix('js/form-submission.js'), ['jquery'], FLUENTFORM_VERSION, true ); wp_register_script( 'fluentform-advanced', fluentFormMix('js/fluentform-advanced.js'), ['jquery'], FLUENTFORM_VERSION, true ); // Date Pickckr Style //fix for essential addon event picker conflict if (!wp_script_is('flatpickr', 'registered')) { wp_register_style( 'flatpickr', fluentFormMix('libs/flatpickr/flatpickr.min.css'), [], '4.6.9' ); } // Date Pickckr Script wp_register_script( 'flatpickr', fluentFormMix('libs/flatpickr/flatpickr.min.js'), ['jquery'], '4.6.9', true ); wp_register_script( 'choices', fluentFormMix('libs/choices/choices.min.js'), [], '9.0.1', true ); wp_register_style( 'ff_choices', fluentFormMix('css/choices.css'), [], FLUENTFORM_VERSION ); wp_register_script( 'form-save-progress', fluentFormMix('js/form-save-progress.js'), ['jquery'], FLUENTFORM_VERSION, true ); do_action_deprecated( 'fluentform_scripts_registered', [ ], FLUENTFORM_FRAMEWORK_UPGRADE, 'fluentform/scripts_registered', 'Use fluentform/scripts_registered instead of fluentform_scripts_registered.' ); $this->app->doAction('fluentform/scripts_registered'); $this->maybeLoadFluentFormStyles(); } protected function maybeLoadFluentFormStyles() { global $post; $postId = isset($post->ID) ? $post->ID : false; if (!$postId) { return; } $fluentFormIds = get_post_meta($postId, '_has_fluentform', true); $hasFluentformMeta = is_a($post, 'WP_Post') && $fluentFormIds; $loadStyle = apply_filters_deprecated( 'fluentform_load_styles', [ false, $post ], FLUENTFORM_FRAMEWORK_UPGRADE, 'fluentform/load_styles', 'Use fluentform/load_styles instead of fluentform_load_styles.' ); if ($hasFluentformMeta || apply_filters('fluentform/load_styles', $loadStyle, $post)) { wp_enqueue_style('fluent-form-styles'); $loadPublicStyle = apply_filters_deprecated( 'fluentform_load_default_public', [ true, (object)[], $postId ], FLUENTFORM_FRAMEWORK_UPGRADE, 'fluentform/load_default_public', 'Use fluentform/load_default_public instead of fluentform_load_default_public.' ); if (apply_filters('fluentform/load_default_public', $loadPublicStyle, (object)[], $postId)) { wp_enqueue_style('fluentform-public-default'); } do_action_deprecated( 'fluentform_pre_load_scripts', [ $post ], FLUENTFORM_FRAMEWORK_UPGRADE, 'fluentform/pre_load_scripts', 'Use fluentform/pre_load_scripts instead of fluentform_pre_load_scripts.' ); $this->app->doAction('fluentform/pre_load_scripts', $post); if (!Helper::isElementorEditor()) { wp_enqueue_script('fluent-form-submission'); } } } /** * Get all the available components * @deprecated Use \FluentForm\App\Http\Controllers\FormController::resources * @return void * * @throws \Exception * @throws \FluentForm\Framework\Exception\UnResolveableEntityException */ public function index() { $formId = intval($this->app->request->get('formId')); $components = $this->app->make('components'); do_action_deprecated( 'fluent_editor_init', [ $components ], FLUENTFORM_FRAMEWORK_UPGRADE, 'fluentform/editor_init', 'Use fluentform/editor_init instead of fluent_editor_init.' ); $this->app->doAction('fluentform/editor_init', $components); $editorComponents = $components->sort()->toArray(); $editorComponents = apply_filters_deprecated( 'fluent_editor_components', [ $editorComponents, $formId ], FLUENTFORM_FRAMEWORK_UPGRADE, 'fluentform/editor_components', 'Use fluentform/editor_components instead of fluent_editor_components.' ); $editorComponents = apply_filters('fluentform/editor_components', $editorComponents, $formId); wp_send_json_success([ 'countries' => getFluentFormCountryList(), 'components' => $editorComponents, 'disabled_components' => $this->getDisabledComponents(), ]); } /** * Get disabled components * * @return array */ private function getDisabledComponents() { $isReCaptchaDisabled = !get_option('_fluentform_reCaptcha_keys_status', false); $isHCaptchaDisabled = !get_option('_fluentform_hCaptcha_keys_status', false); $isTurnstileDisabled = !get_option('_fluentform_turnstile_keys_status', false); $disabled = [ 'recaptcha' => [ 'disabled' => $isReCaptchaDisabled, 'title' => __('reCaptcha', 'fluentform'), 'description' => __('Please enter a valid API key on FluentForms->Settings->reCaptcha', 'fluentform'), 'hidePro' => true, ], 'hcaptcha' => [ 'disabled' => $isHCaptchaDisabled, 'title' => __('hCaptcha', 'fluentform'), 'description' => __('Please enter a valid API key on FluentForms->Settings->hCaptcha', 'fluentform'), 'hidePro' => true, ], 'turnstile' => [ 'disabled' => $isTurnstileDisabled, 'title' => __('Turnstile', 'fluentform'), 'description' => __('Please enter a valid API key on FluentForms->Settings->Turnstile', 'fluentform'), 'hidePro' => true, ], 'input_image' => [ 'disabled' => true, 'title' => __('Image Upload', 'fluentform'), 'description' => __('Image Upload is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => '', 'video' => 'https://www.youtube.com/embed/Yb3FSoZl9Zg', ], 'input_file' => [ 'disabled' => true, 'title' => __('File Upload', 'fluentform'), 'description' => __('File Upload is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => '', 'video' => 'https://www.youtube.com/embed/bXbTbNPM_4k', ], 'shortcode' => [ 'disabled' => true, 'title' => __('Shortcode', 'fluentform'), 'description' => __('Shortcode is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => '', 'video' => 'https://www.youtube.com/embed/op3mEQxX1MM', ], 'action_hook' => [ 'disabled' => true, 'title' => __('Action Hook', 'fluentform'), 'description' => __('Action Hook is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => fluentformMix('img/pro-fields/action-hook.png'), 'video' => '', ], 'form_step' => [ 'disabled' => true, 'title' => __('Form Step', 'fluentform'), 'description' => __('Form Step is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => '', 'video' => 'https://www.youtube.com/embed/VQTWnM6BbRU', ], ]; if (!Helper::hasPro()) { $disabled['ratings'] = [ 'disabled' => true, 'title' => __('Ratings', 'fluentform'), 'description' => __('Ratings is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => '', 'video' => 'https://www.youtube.com/embed/YGdkNspMaEs', ]; $disabled['tabular_grid'] = [ 'disabled' => true, 'title' => __('Checkable Grid', 'fluentform'), 'description' => __('Checkable Grid is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => '', 'video' => 'https://www.youtube.com/embed/ayI3TzXXANA', ]; $disabled['chained_select'] = [ 'disabled' => true, 'title' => __('Chained Select Field', 'fluentform'), 'description' => __('Chained Select Field is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => fluentformMix('img/pro-fields/chained-select-field.png'), 'video' => '', ]; $disabled['phone'] = [ 'disabled' => true, 'title' => __('Phone Field', 'fluentform'), 'description' => __('Phone Field is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => fluentformMix('img/pro-fields/phone-field.png'), 'video' => '', ]; $disabled['rich_text_input'] = [ 'disabled' => true, 'title' => __('Rich Text Input', 'fluentform'), 'description' => __('Rich Text Input is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => fluentformMix('img/pro-fields/rich-text-input.png'), 'video' => '', ]; $disabled['save_progress_button'] = [ 'disabled' => true, 'title' => __('Save & Resume', 'fluentform'), 'description' => __('Save & Resume is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => fluentformMix('img/pro-fields/save-progress-button.png'), 'video' => '', ]; $disabled['cpt_selection'] = [ 'disabled' => true, 'title' => __('Post/CPT Selection', 'fluentform'), 'description' => __('Post/CPT Selection is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => fluentformMix('img/pro-fields/post-cpt-selection.png'), 'video' => '', ]; $disabled['quiz_score'] = [ 'disabled' => true, 'title' => __('Quiz Score', 'fluentform'), 'description' => __('Quiz Score is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => '', 'video' => 'https://www.youtube.com/embed/bPjDXR0y_Oo', ]; $disabled['net_promoter_score'] = [ 'disabled' => true, 'title' => __('Net Promoter Score', 'fluentform'), 'description' => __('Net Promoter Score is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => fluentformMix('img/pro-fields/net-promoter-score.png'), 'video' => '', ]; $disabled['dynamic_field'] = [ 'disabled' => true, 'title' => __('Dynamic Field', 'fluentform'), 'description' => __('Dynamic Field is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => '', 'video' => 'https://www.youtube.com/embed/cx3N5y1ddOQ', ]; $disabled['repeater_field'] = [ 'disabled' => true, 'title' => __('Repeat Field', 'fluentform'), 'description' => __('Repeat Field is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => '', 'video' => 'https://www.youtube.com/embed/BXo9Sk-OLnQ', ]; $disabled['rangeslider'] = [ 'disabled' => true, 'title' => __('Range Slider', 'fluentform'), 'description' => __('Range Slider is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => '', 'video' => 'https://www.youtube.com/embed/RaY2VcPWk6I', ]; $disabled['input_ranking'] = [ 'disabled' => true, 'title' => __('Ranking Field', 'fluentform'), 'description' => __('Ranking Field is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => '', 'video' => '', ]; $disabled['color-picker'] = [ 'disabled' => true, 'title' => __('Color Picker', 'fluentform'), 'description' => __('Color Picker is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => fluentformMix('img/pro-fields/color-picker.png'), 'video' => '', ]; $disabled['payment_coupon'] = [ 'disabled' => true, 'title' => __('Coupon', 'fluentform'), 'description' => __('Coupon is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => fluentformMix('img/pro-fields/coupon.png'), 'video' => '', ]; } $disabled = apply_filters_deprecated( 'fluentform_disabled_components', [ $disabled ], FLUENTFORM_FRAMEWORK_UPGRADE, 'fluentform/disabled_components', 'Use fluentform/disabled_components instead of fluentform_disabled_components.' ); return $this->app->applyFilters('fluentform/disabled_components', $disabled); } /** * Get available shortcodes for editor * * @return void * * @throws \Exception */ public function getEditorShortcodes() { $editor_shortcodes = fluentFormEditorShortCodes(); wp_send_json_success(['shortcodes' => $editor_shortcodes], 200); } /** * @deprecated Use \FluentForm\App\Services\Form\FormService::shortcodes * Get all available shortcodes for editor * * @return void * * @throws \Exception */ public function getAllEditorShortcodes() { wp_send_json(fluentFormGetAllEditorShortCodes( $this->app->request->get('formId') ), 200); } /** * Register the form renderer shortcode * * @return void */ public function addFluentFormShortCode() { add_action('wp_enqueue_scripts', [$this, 'registerScripts'], 9); $this->app->addShortCode('fluentform', function ($atts, $content) { $data = [ 'id' => null, 'title' => null, 'css_classes' => '', 'permission' => '', 'type' => 'classic', 'theme' => '', 'permission_message' => __('Sorry, You do not have permission to view this form', 'fluentform') ]; /* This filter is deprecated, will be removed soon */ $data = apply_filters('fluentform_shortcode_defaults', $data, $atts ); $shortcodeDefaults = apply_filters('fluentform/shortcode_defaults', $data, $atts); $atts = shortcode_atts($shortcodeDefaults, $atts); return $this->renderForm($atts); }); $this->registerHelperShortCodes(); } public function renderForm($atts) { $form_id = $atts['id']; $query = wpFluent()->table('fluentform_forms'); if (! $this->app->request->get('preview_id')) { $query->where('status', 'published'); } if ($form_id) { $form = $query->find($form_id); } elseif ($formTitle = $atts['title']) { $form = $query->where('title', $formTitle)->first(); } else { return ''; } if (!$form) { return ''; } if (!empty($atts['permission'])) { if (!current_user_can($atts['permission'])) { return $this->getNotRenderableHtml($form->id, $atts['permission_message']); } } if (is_feed()) { global $post; /* translators: %s is the website URL */ $feedText = sprintf(__('The form can be filled in the actual website url.', 'fluentform'), get_permalink($post)); $feedText = apply_filters_deprecated( 'fluentform_shortcode_feed_text', [ $feedText, $form ], FLUENTFORM_FRAMEWORK_UPGRADE, 'fluentform/shortcode_feed_text', 'Use fluentform/shortcode_feed_text instead of fluentform_shortcode_feed_text.' ); $feedText = apply_filters('fluentform/shortcode_feed_text', $feedText, $form); return $feedText; } $form->settings = Helper::getFormMeta($form->id, 'formSettings', []); if (empty($form->settings)) { return ''; } $form->fields = json_decode($form->form_fields, true); if (!is_array($form->fields) || empty($form->fields['fields'])) { return ''; } $form = apply_filters_deprecated( 'fluentform_rendering_form', [ $form ], FLUENTFORM_FRAMEWORK_UPGRADE, 'fluentform/rendering_form', 'Use fluentform/rendering_form instead of fluentform_rendering_form.' ); $form = $this->app->applyFilters('fluentform/rendering_form', $form); $isRenderable = [ 'status' => true, 'message' => '', ]; $isRenderable = apply_filters('fluentform_is_form_renderable', $isRenderable, $form); $isRenderable = $this->app->applyFilters('fluentform/is_form_renderable', $isRenderable, $form); if (is_array($isRenderable) && !$isRenderable['status']) { return $this->getNotRenderableHtml($form->id, $isRenderable['message']); } $instanceCssClass = Helper::getFormInstaceClass($form->id); $form->instance_css_class = $instanceCssClass; $form->instance_index = Helper::$formInstance; if ('conversational' == $atts['type']) { if (!Helper::isElementorEditor()) { $this->addInlineVars(); } return (new \FluentForm\App\Services\FluentConversational\Classes\Form())->renderShortcode($form); } $formBuilder = $this->app->make('formBuilder'); $cssClasses = trim($instanceCssClass . ' ff-form-loading'); $output = $formBuilder->build($form, $cssClasses, $instanceCssClass, $atts); $output = $this->replaceEditorSmartCodes($output, $form); if (!wp_script_is('fluent-form-submission', 'registered')) { $this->registerScripts(); } wp_enqueue_style('fluent-form-styles'); $postId = get_the_ID() ?: 0; $loadStyle = apply_filters_deprecated( 'fluentform_load_default_public', [ true, $form, $postId ], FLUENTFORM_FRAMEWORK_UPGRADE, 'fluentform/load_default_public', 'Use fluentform/load_default_public instead of fluentform_load_default_public.' ); if (apply_filters('fluentform/load_default_public', $loadStyle, $form, $postId)) { wp_enqueue_style('fluentform-public-default'); } /* * We will load fluentform-advanced if the form has certain fields or feature */ $this->maybeHasAdvandedFields($form, $formBuilder); if (!Helper::isElementorEditor()) { wp_enqueue_script('fluent-form-submission'); } /* translators: %activeStep% is the current step number, %totalStep% is the total number of steps, %stepTitle% is the step title */ $stepText = __('Step %activeStep% of %totalStep% - %stepTitle%', 'fluentform'); $stepText = apply_filters_deprecated( 'fluentform_step_string', [ $stepText ], FLUENTFORM_FRAMEWORK_UPGRADE, 'fluentform/step_string', 'Use fluentform/step_string instead of fluentform_step_string.' ); $stepText = apply_filters('fluentform/step_string', $stepText); $data = [ 'ajaxUrl' => admin_url('admin-ajax.php'), 'forms' => [], 'step_text' => $stepText, 'step_completed_text' => __('Completed', 'fluentform'), 'is_rtl' => is_rtl(), 'date_i18n' => self::getDatei18n(), 'pro_version' => (defined('FLUENTFORMPRO_VERSION')) ? FLUENTFORMPRO_VERSION : false, 'fluentform_version' => FLUENTFORM_VERSION, 'force_init' => false, 'stepAnimationDuration' => 350, 'upload_completed_txt' => __('100% Completed', 'fluentform'), 'upload_start_txt' => __('0% Completed', 'fluentform'), 'uploading_txt' => __('Uploading', 'fluentform'), 'choice_js_vars' => [ 'noResultsText' => __('No results found', 'fluentform'), 'loadingText' => __('Loading...', 'fluentform'), 'noChoicesText' => __('No choices to choose from', 'fluentform'), 'itemSelectText' => __('Press to select', 'fluentform'), 'maxItemTextSingular' => __('Only %%maxItemCount%% option can be added', 'fluentform'), 'maxItemTextPlural' => __('Only %%maxItemCount%% options can be added', 'fluentform'), ], 'input_mask_vars' => [ 'clearIfNotMatch' => false, ], 'nonce' => wp_create_nonce(), 'file_delete_nonce' => wp_create_nonce('fluentform_file_delete'), 'form_id' => $form_id, 'step_change_focus' => true, 'has_cleantalk' => \FluentForm\App\Modules\Form\CleanTalkHandler::isCleantalkActivated(), 'pro_payment_script_compatible' => Helper::isProPaymentScriptCompatible(), ]; $data = apply_filters_deprecated( 'fluentform_global_form_vars', [ $data ], FLUENTFORM_FRAMEWORK_UPGRADE, 'fluentform/global_form_vars', 'Use fluentform/global_form_vars instead of fluentform_global_form_vars.' ); $vars = apply_filters('fluentform/global_form_vars', $data); if (!Helper::isElementorEditor()) { wp_localize_script('fluent-form-submission', 'fluentFormVars', $vars); } // Localize JavaScript messages for translation $this->localizeJavaScriptMessages($form); // Add global messages (only once) if (!wp_script_is('fluent-form-submission', 'done')) { $globalMessages = [ 'javascript_handler_failed' => __('Javascript handler could not be loaded. Form submission has been failed. Reload the page and try again', 'fluentform') ]; $globalMessages = apply_filters('fluentform/form_submission_messages', $globalMessages, $form); wp_localize_script('fluent-form-submission', 'fluentform_submission_messages_global', $globalMessages); // Add global address messages $globalAddressMessages = [ 'please_wait' => __('Please wait ...', 'fluentform'), 'location_not_determined' => __('Could not determine address from location.', 'fluentform'), 'address_fetch_failed' => __('Failed to fetch address from coordinates.', 'fluentform'), 'geolocation_failed' => __('Geolocation failed or was denied.', 'fluentform'), 'geolocation_not_supported' => __('Geolocation is not supported by this browser.', 'fluentform') ]; $globalAddressMessages = apply_filters('fluentform/address_autocomplete_messages', $globalAddressMessages, $form); wp_localize_script('fluent-form-submission', 'fluentform_address_messages_global', $globalAddressMessages); } $formSettings = $form->settings; $formSettings = ArrayHelper::only($formSettings, ['layout', 'id']); // Ensure restrictions array exists before setting denyEmptySubmission if (!isset($formSettings['restrictions']) || !is_array($formSettings['restrictions'])) { $formSettings['restrictions'] = []; } $formSettings['restrictions']['denyEmptySubmission'] = [ 'enabled' => false, ]; if (!empty($formBuilder->validationRules)) { $formBuilder->validationRules = fluentform_backend_sanitizer($formBuilder->validationRules, [ 'message' => 'fluentform_sanitize_html' ]); } $form_vars = [ 'id' => $form->id, 'ajaxUrl' => admin_url('admin-ajax.php'), 'settings' => $formSettings, 'form_instance' => $instanceCssClass, 'form_id_selector' => 'fluentform_' . $form->id, 'rules' => $formBuilder->validationRules, 'debounce_time' => apply_filters('fluentform/show_hide_elements_debounce_time', 300), ]; if ($conditionals = $formBuilder->conditions) { $form_vars['conditionals'] = $conditionals; } $form_vars['file_upload_settings'] = apply_filters( 'fluentform/file_upload_settings_for_js', [], $form ); $form_vars = apply_filters('fluentform/form_vars_for_JS', $form_vars, $form); if ($form->has_payment) { do_action_deprecated( 'fluentform_rendering_payment_form', [ $form ], FLUENTFORM_FRAMEWORK_UPGRADE, 'fluentform/rendering_payment_form', 'Use fluentform/rendering_payment_form instead of fluentform_rendering_payment_form.' ); do_action('fluentform/rendering_payment_form', $form); } $otherScripts = ''; $otherScriptsRenderImmediately = apply_filters('fluentform/load_form_instance_js_var_immediately', false); if (!$otherScriptsRenderImmediately) { ob_start(); } if (!Helper::isElementorEditor()) { ?> addInlineVars(); } if (!$otherScriptsRenderImmediately) { $otherScripts .= ob_get_clean(); } $disableAnalytics = apply_filters_deprecated( 'fluentform-disabled_analytics', [ true ], FLUENTFORM_FRAMEWORK_UPGRADE, 'fluentform/disabled_analytics', 'Use fluentform/disabled_analytics instead of fluentform-disabled_analytics.' ); if (!$this->app->applyFilters('fluentform/disabled_analytics', $disableAnalytics)) { if (!Acl::hasAnyFormPermission($form->id)) { (new \FluentForm\App\Services\Analytics\AnalyticsService())->store($form->id); } } return $output . $otherScripts; } protected function getNotRenderableHtml($formId, $message) { return "