is_gravityforms_supported()) { return; } require_once 'class-field-turnstile.php'; } /** * Initialize hooks required for admin. * * @since 1.0 * * @return void */ public function init_admin() { parent::init_admin(); add_action('gform_field_appearance_settings', array($this, 'add_turnstile_theme_field_setting'), 0, 1); } public function scripts() { $enqueue_condition = ! is_admin() ? array(array($this, 'frontend_script_callback')) : array(array($this, 'admin_script_callback')); $turnstile_src = 'https://challenges.cloudflare.com/turnstile/v0/api.js'; // phpcs:ignore PluginCheck.CodeAnalysis.Offloading.OffloadedContent -- Turnstile must load its widget from Cloudflare; disclosed in readme. $scripts = array( array( 'handle' => 'turnstile_script', 'src' => $turnstile_src, 'version' => $this->_version, 'deps' => array(), 'in_footer' => true, 'enqueue' => $enqueue_condition ), array( 'handle' => 'alphagf_turnstile_admin_script', 'src' => trailingslashit($this->get_base_url()) . 'js/turnstile-admin.js', 'version' => $this->_version, 'deps' => array('jquery'), 'in_footer' => true, 'enqueue' => array(array($this, 'admin_script_callback')) ), array( 'handle' => 'alphagf_turnstile_script', 'src' => trailingslashit($this->get_base_url()) . 'js/turnstile.js', 'version' => $this->_version, 'deps' => array('jquery'), 'in_footer' => true, 'enqueue' => $enqueue_condition ), ); return array_merge(parent::scripts(), $scripts); } public function styles() { $styles = array( array( 'handle' => 'alphagf_icon_style', 'src' => ALPHAGF_ASSETS . '/css/font_style.css', 'version' => $this->_version, 'enqueue' => array( array('admin_page' => array('form_editor')), ) ) ); return array_merge(parent::styles(), $styles); } public function plugin_settings_fields() { return array( array( 'title' => esc_html__('Turnstile Settings', 'alpha-addons-for-gravity-forms'), // translators: %1 is an opening tag, and %2 is a closing tag. 'description' => sprintf(esc_html__('To connect your site to Turnstile, create a site on your %1$sCloudflare Dashboard%2$s and enter the associated Site Key and Secret Key below.', 'alpha-addons-for-gravity-forms'), '', ''), // phpcs:ignore PluginCheck.CodeAnalysis.Offloading.OffloadedContent -- Link to the Cloudflare dashboard, not a loaded asset. 'fields' => array( array( 'name' => 'site_key', 'label' => esc_html__('Site Key', 'alpha-addons-for-gravity-forms'), 'type' => 'text', 'class' => 'medium', 'feedback_callback' => [$this, 'is_key_valid'], ), array( 'name' => 'site_secret', 'label' => esc_html__('Secret Key', 'alpha-addons-for-gravity-forms'), 'type' => 'text', 'class' => 'medium', 'feedback_callback' => [$this, 'is_key_valid'], ), ), ), array( 'title' => esc_html__('Field Options', 'alpha-addons-for-gravity-forms'), 'description' => esc_html__('Choose between a Light or Dark theme to tailor the field\'s appearance to your website.', 'alpha-addons-for-gravity-forms'), 'fields' => array( array( 'name' => 'theme', 'label' => esc_html__('Theme', 'alpha-addons-for-gravity-forms'), 'type' => 'select', 'default_value' => 'light', 'choices' => array( array( 'label' => __('Light', 'alpha-addons-for-gravity-forms'), 'value' => 'light', ), array( 'label' => __('Dark', 'alpha-addons-for-gravity-forms'), 'value' => 'dark', ), ), ), ), ), // Preview group array( 'title' => esc_html__('Field Preview', 'alpha-addons-for-gravity-forms'), 'description' => '
' . esc_html__('Below is a preview of how the field will appear in your forms. If you see an error message, check your credentials and try again.', 'alpha-addons-for-gravity-forms') . '
' . esc_html__('Note: ', 'alpha-addons-for-gravity-forms') . '' . esc_html__('Solve the preview and save the settings to activate the Turnstile field on your forms. If your widget is set to the "Invisible" type in Cloudflare, this preview will appear empty.', 'alpha-addons-for-gravity-forms'), 'dependency' => array( 'live' => false, 'fields' => array( array('field' => 'site_key'), array('field' => 'site_secret'), ), ), 'fields' => array( array( 'name' => 'preview', 'type' => 'html', 'html' => array($this, 'get_preview_html'), ), ), ), ); } public function get_preview_html() { $key = $this->get_plugin_setting('site_key'); $secret = $this->get_plugin_setting('site_secret'); $theme = $this->get_plugin_setting('theme'); if (empty($key) || empty($secret)) { return ''; } return '
'; } public function add_turnstile_theme_field_setting($position) { if ((int) $position !== 20) { return; } ?>