app = $app; } public function registerScripts() { $app = $this->app; // We will just register the scripts here. We will not load any scripts from here $fluentFormPublicCss = $app->publicUrl('css/fluent-forms-public.css'); $fluentFormPublicDefaultCss = $app->publicUrl('css/fluentform-public-default.css'); if (is_rtl()) { $fluentFormPublicCss = $app->publicUrl('css/fluent-forms-public-rtl.css'); $fluentFormPublicDefaultCss = $app->publicUrl('css/fluentform-public-default-rtl.css'); } wp_register_style( 'fluent-form-styles', $fluentFormPublicCss, array(), FLUENTFORM_VERSION ); wp_register_style( 'fluentform-public-default', $fluentFormPublicDefaultCss, array(), FLUENTFORM_VERSION ); wp_register_script( 'fluent-form-submission', $app->publicUrl('js/form-submission.js'), array('jquery'), FLUENTFORM_VERSION, true ); wp_register_script( 'fluentform-advanced', $app->publicUrl('js/fluentform-advanced.js'), array('jquery'), FLUENTFORM_VERSION, true ); // Date Pickckr Style //fix for essential addon event picker conflict if (!wp_script_is('flatpickr', 'registered')) { wp_register_style( 'flatpickr', $app->publicUrl('libs/flatpickr/flatpickr.min.css') ); } // Date Pickckr Script wp_register_script( 'flatpickr', $app->publicUrl('libs/flatpickr/flatpickr.js'), array('jquery'), false, true ); wp_register_script( 'choices', $app->publicUrl('libs/choices/choices.min.js'), array(), '9.0.1', true ); wp_register_style( 'ff_choices', $app->publicUrl('css/choices.css'), [], FLUENTFORM_VERSION ); wp_register_script( 'form-save-progress', $app->publicUrl('js/form-save-progress.js'), ['jquery'], FLUENTFORM_VERSION, true ); do_action('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; if ($hasFluentformMeta || apply_filters('fluentform_load_styles', false, $post)) { wp_enqueue_style('fluent-form-styles'); wp_enqueue_style('fluentform-public-default'); do_action('fluentform_pre_load_scripts', $post); wp_enqueue_script('fluent-form-submission'); } } /** * Get all the available components * * @return void * @throws \Exception * @throws \FluentForm\Framework\Exception\UnResolveableEntityException */ public function index() { $formId = intval($_REQUEST['formId']); $components = $this->app->make('components'); $this->app->doAction('fluent_editor_init', $components); $editorComponents = $components->sort()->toArray(); $editorComponents = apply_filters('fluent_editor_components', $editorComponents, $formId); $countries = $this->app->load($this->app->appPath('Services/FormBuilder/CountryNames.php')); wp_send_json_success(array( 'countries' => $countries, '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 = array( 'recaptcha' => array( 'disabled' => $isReCaptchaDisabled, 'title' => __('reCaptcha', 'fluentform'), 'description' => __('Please enter a valid API key on FluentForms->Settings->reCaptcha', 'fluentform'), 'hidePro' => true ), 'hcaptcha' => array( 'disabled' => $isHCaptchaDisabled, 'title' => __('hCaptcha', 'fluentform'), 'description' => __('Please enter a valid API key on FluentForms->Settings->hCaptcha', 'fluentform'), 'hidePro' => true ), 'turnstile' => array( 'disabled' => $isTurnstileDisabled, 'title' => __('Turnstile', 'fluentform'), 'description' => __('Please enter a valid API key on FluentForms->Settings->Turnstile', 'fluentform'), 'hidePro' => true ), 'input_image' => array( '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' => array( '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' => array( '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' => array( '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' => $this->app->publicUrl('img/pro-fields/Action Hook.png'), 'video' => '' ), 'form_step' => array( '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 (!defined('FLUENTFORMPRO')) { $disabled['ratings'] = array( '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'] = array( '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'] = array( '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' => $this->app->publicUrl('img/pro-fields/Chained Select Field.png'), 'video' => '' ); $disabled['phone'] = array( 'disabled' => true, 'title' => 'Phone Field', 'description' => __('Phone Field is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => $this->app->publicUrl('img/pro-fields/Phone Field.png'), 'video' => '' ); $disabled['rich_text_input'] = array( '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' => $this->app->publicUrl('img/pro-fields/Rich Text Input.png'), 'video' => '' ); $disabled['save_progress_button'] = array( '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' => $this->app->publicUrl('img/pro-fields/Save Progress Button.png'), 'video' => '' ); $disabled['cpt_selection'] = array( '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' => $this->app->publicUrl('img/pro-fields/Post_CPT Selection.png'), 'video' => '' ); $disabled['quiz_score'] = array( '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'] = array( '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' => $this->app->publicUrl('img/pro-fields/Net Promoter Score.png'), 'video' => '' ); $disabled['repeater_field'] = array( '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'] = array( '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['color-picker'] = array( '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' => $this->app->publicUrl('img/pro-fields/Color Picker.png'), 'video' => '' ); $disabled['multi_payment_component'] = array( 'disabled' => true, 'is_payment' => true, 'title' => __('Payment Field', 'fluentform'), 'description' => __('Payment Field is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => $this->app->publicUrl('img/pro-fields/Payment Field.png'), 'video' => '' ); $disabled['custom_payment_component'] = array( 'disabled' => true, 'is_payment' => true, 'title' => 'Custom Payment Amount', 'description' => __('Custom Payment Amount is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => $this->app->publicUrl('img/pro-fields/Custom Payment Amount.png'), 'video' => '' ); $disabled['subscription_payment_component'] = array( 'disabled' => true, 'is_payment' => true, 'title' => __('Subscription Field', 'fluentform'), 'description' => __('Subscription Field is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => $this->app->publicUrl('img/pro-fields/Subscription Field.png'), 'video' => '' ); $disabled['item_quantity_component'] = array( 'disabled' => true, 'is_payment' => true, 'title' => __('Item Quantity', 'fluentform'), 'description' => __('Item Quantity is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => $this->app->publicUrl('img/pro-fields/Item Quantity.png'), 'video' => '' ); $disabled['payment_method'] = array( 'disabled' => true, 'is_payment' => true, 'title' => __('Payment Method', 'fluentform'), 'description' => __('Payment Method is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => $this->app->publicUrl('img/pro-fields/Payment Method.png'), 'video' => '' ); $disabled['payment_summary_component'] = array( 'disabled' => true, 'is_payment' => true, 'title' => __('Payment Summary', 'fluentform'), 'description' => __('Payment Summary is not available with the free version. Please upgrade to pro to get all the advanced features.', 'fluentform'), 'image' => $this->app->publicUrl('img/pro-fields/Payment Summary.png'), 'video' => '' ); $disabled['payment_coupon'] = array( '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' => $this->app->publicUrl('img/pro-fields/Coupon.png'), 'video' => '' ); } 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); } /** * 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', array($this, 'registerScripts'), 9); $this->app->addShortCode('fluentform', function ($atts, $content) { $shortcodeDefaults = apply_filters('fluentform_shortcode_defaults', array( 'id' => null, 'title' => null, 'css_classes' => '', 'permission' => '', 'type' => 'classic', 'permission_message' => __('Sorry, You do not have permission to view this form', 'fluentform') ), $atts); $atts = shortcode_atts($shortcodeDefaults, $atts); return $this->renderForm($atts); }); $this->app->addShortCode('fluentform_info', function ($atts) { $shortcodeDefaults = apply_filters('fluentform_info_shortcode_defaults', array( 'id' => null, // This is the form id 'info' => 'submission_count', // submission_count | created_at | updated_at | payment_total 'status' => 'all', // get submission cound of a particular entry status favourites | unread | read 'with_trashed' => 'no', // yes | no 'substract_from' => 0, // [fluentform_info id="2" info="submission_count" substract_from="20"] 'hide_on_zero' => 'no', 'payment_status' => 'all', // it can be all / specific payment status 'currency_formatted' => 'yes', 'date_format' => '' ), $atts); $atts = shortcode_atts($shortcodeDefaults, $atts); $formId = $atts['id']; $form = wpFluent()->table('fluentform_forms')->find($formId); if (!$form) { return ''; } if ($atts['info'] == 'submission_count') { $countQuery = wpFluent()->table('fluentform_submissions') ->where('form_id', $formId); if ($atts['status'] != 'trashed' && $atts['with_trashed'] == 'no') { $countQuery = $countQuery->where('status', '!=', 'trashed'); } if ($atts['status'] == 'all') { // ... } else if ($atts['status'] == 'favourites') { $countQuery = $countQuery->where('is_favourite', '=', 1); } else { $countQuery = $countQuery->where('status', '=', sanitize_key($atts['status'])); } if ($atts['payment_status'] && defined('FLUENTFORMPRO') && $atts['payment_status'] != 'all') { $countQuery = $countQuery->where('payment_status', '=', sanitize_key($atts['payment_status'])); } $total = $countQuery->count(); if ($atts['substract_from']) { $total = intval($atts['substract_from']) - $total; } if ($atts['hide_on_zero'] == 'yes' && !$total || $total < 0) { return ''; } return $total; } else if ($atts['info'] == 'created_at') { if ($atts['date_format']) { $dateFormat = $atts['date_format']; } else { $dateFormat = get_option('date_format') . ' ' . get_option('time_format'); } return date($dateFormat, strtotime($form->created_at)); } else if ($atts['info'] == 'updated_at') { if ($atts['date_format']) { $dateFormat = $atts['date_format']; } else { $dateFormat = get_option('date_format') . ' ' . get_option('time_format'); } return date($dateFormat, strtotime($form->updated_at)); } else if ($atts['info'] == 'payment_total') { if (!defined('FLUENTFORMPRO')) { return ''; } global $wpdb; $countQuery = wpFluent() ->table('fluentform_submissions') ->select(wpFluent()->raw('SUM(payment_total) as payment_total')) ->where('form_id', $formId); if ($atts['status'] != 'trashed' && $atts['with_trashed'] == 'no') { $countQuery = $countQuery->where('status', '!=', 'trashed'); } if ($atts['status'] == 'all') { // ... } else if ($atts['status'] == 'favourites') { $countQuery = $countQuery->where('is_favourite', '=', 1); } else { $countQuery = $countQuery->where('status', '=', sanitize_key($atts['status'])); } if ($atts['payment_status'] == 'all') { // ... } else if ($atts['payment_status']) { $countQuery = $countQuery->where('payment_status', '=', sanitize_key($atts['payment_status'])); } $row = $countQuery->first(); $total = 0; if ($row) { $total = $row->payment_total; } if ($atts['substract_from']) { $total = intval($atts['substract_from'] * 100) - $total; } if ($atts['hide_on_zero'] == 'yes' && !$total) { return ''; } if ($atts['currency_formatted'] == 'yes') { $currency = \FluentFormPro\Payments\PaymentHelper::getFormCurrency($formId); return \FluentFormPro\Payments\PaymentHelper::formatMoney($total, $currency); } if (!$total) { return 0; } return $total / 100; } return ''; }); $this->app->addShortCode('ff_get', function ($atts) { $atts = shortcode_atts(array( 'param' => '', ), $atts); if ($atts['param'] && isset($_GET[$atts['param']])) { $value = $_GET[$atts['param']]; if (is_array($value)) { return implode(', ', $value); } return esc_html($value); } return ''; }); } public function renderForm($atts) { $form_id = $atts['id']; $query = wpFluent()->table('fluentform_forms'); if (!isset($_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 "