/** * Check if form provided contains the specified field type. * * @since 1.0.5 * @param string $type * @param mixed $form * @return bool */ function wpforms_has_field_type($type, $form, $multiple = false) { $form_data = ''; $field = false; $type = (array) $type; if ($multiple) { foreach ($form as $single_form) { $field = wpforms_has_field_type($type, $single_form); if ($field) { break; } } return $field; } else { if (is_object($form) && !empty($form->post_content)) { $form_data = wpforms_decode($form->post_content); } elseif (is_array($form)) { $form_data = $form; } if (empty($form_data['fields'])) { return false; } foreach ($form_data['fields'] as $single_field) { if (in_array($single_field['type'], $type)) { $field = true; break; } } return $field; } }
/** * Load the JS assets for frontend output. * * @since 1.0.0 */ public function assets_js() { do_action('wpforms_frontend_js', $this->forms); // Load jquery validation library - http://jqueryvalidation.org/ wp_enqueue_script('wpforms-validation', WPFORMS_PLUGIN_URL . 'assets/js/jquery.validate.min.js', array('jquery'), '1.13.1', true); // Load jquery date/time library - http://http://amsul.ca/pickadate.js/ if ($this->assets_global() || true == wpforms_has_field_type('date-time', $this->forms, true)) { wp_enqueue_script('wpforms-pickadate-core', WPFORMS_PLUGIN_URL . 'assets/js/jquery.picker.js', array('jquery'), '3.5.6', true); wp_enqueue_script('wpforms-pickadate-date', WPFORMS_PLUGIN_URL . 'assets/js/jquery.picker.date.js', array('jquery'), '3.5.6', true); wp_enqueue_script('wpforms-pickadate-time', WPFORMS_PLUGIN_URL . 'assets/js/jquery.picker.time.js', array('jquery'), '3.5.6', true); } // Load jquery input mask library - https://github.com/RobinHerbots/jquery.inputmask if ($this->assets_global() || true == wpforms_has_field_type(array('phone', 'address'), $this->forms, true)) { wp_enqueue_script('wpforms-maskedinput', WPFORMS_PLUGIN_URL . 'assets/js/jquery.inputmask.bundle.min.js', array('jquery'), '3.2.8', true); } // Load CC payment library - https://github.com/stripe/jquery.payment/ if ($this->assets_global() || true == wpforms_has_field_type('credit-card', $this->forms, true)) { wp_enqueue_script('wpforms-payment', WPFORMS_PLUGIN_URL . 'assets/js/jquery.payment.min.js', array('jquery'), WPFORMS_VERSION, true); } // Load base JS wp_enqueue_script('wpforms', WPFORMS_PLUGIN_URL . 'assets/js/wpforms.js', array('jquery'), WPFORMS_VERSION, true); // If we have payment fields then include currency details $payment_fields = array('credit-card', 'payment-single', 'payment-multiple', 'payment-total'); if ($this->assets_global() || true == wpforms_has_field_type($payment_fields, $this->forms, true)) { $currency = wpforms_setting('currency', 'USD'); $currencies = wpforms_get_currencies(); wp_localize_script('wpforms', 'wpforms_currency', array('code' => $currency, 'thousands' => $currencies[$currency]['thousands_separator'], 'decimal' => $currencies[$currency]['decimal_separator'], 'symbol' => $currencies[$currency]['symbol'], 'symbol_pos' => $currencies[$currency]['symbol_pos'])); } // Load reCAPTCHA support if form supports it $site_key = wpforms_setting('recaptcha-site-key'); $secret_key = wpforms_setting('recaptcha-secret-key'); if (!empty($site_key) && !empty($secret_key)) { wp_enqueue_script('wpforms-recaptcha', 'https://www.google.com/recaptcha/api.js', array(), '2.0.0', true); } }