class-evf-field-address.php
1 year ago
class-evf-field-ai.php
1 year ago
class-evf-field-captcha.php
4 weeks ago
class-evf-field-checkbox.php
2 months ago
class-evf-field-color.php
4 weeks ago
class-evf-field-country.php
2 months ago
class-evf-field-credit-card.php
4 weeks ago
class-evf-field-date-time.php
4 weeks ago
class-evf-field-divider.php
2 years ago
class-evf-field-email.php
1 year ago
class-evf-field-file-upload.php
1 year ago
class-evf-field-first-name.php
1 year ago
class-evf-field-hcaptcha.php
4 months ago
class-evf-field-hidden.php
1 year ago
class-evf-field-html.php
9 months ago
class-evf-field-image-upload.php
1 year ago
class-evf-field-last-name.php
1 year ago
class-evf-field-likert.php
1 year ago
class-evf-field-lookup.php
4 weeks ago
class-evf-field-number.php
1 year ago
class-evf-field-password.php
4 weeks ago
class-evf-field-payment-authorize-net.php
4 weeks ago
class-evf-field-payment-checkbox.php
4 weeks ago
class-evf-field-payment-coupon.php
4 weeks ago
class-evf-field-payment-gateway-selector.php
4 weeks ago
class-evf-field-payment-quantity.php
4 weeks ago
class-evf-field-payment-radio.php
4 weeks ago
class-evf-field-payment-single.php
4 weeks ago
class-evf-field-payment-square.php
1 year ago
class-evf-field-payment-subscription-plan.php
4 weeks ago
class-evf-field-payment-subtotal.php
4 weeks ago
class-evf-field-payment-total.php
4 weeks ago
class-evf-field-phone.php
1 year ago
class-evf-field-privacy-policy.php
2 months ago
class-evf-field-private-note.php
1 year ago
class-evf-field-progress.php
4 weeks ago
class-evf-field-radio.php
2 months ago
class-evf-field-range-slider.php
4 weeks ago
class-evf-field-rating.php
2 months ago
class-evf-field-recaptcha.php
4 months ago
class-evf-field-repeater.php
4 weeks ago
class-evf-field-reset.php
4 weeks ago
class-evf-field-scale-rating.php
1 year ago
class-evf-field-select.php
1 year ago
class-evf-field-signature.php
4 weeks ago
class-evf-field-text.php
1 year ago
class-evf-field-textarea.php
1 year ago
class-evf-field-title.php
2 years ago
class-evf-field-turnstile.php
4 months ago
class-evf-field-url.php
1 year ago
class-evf-field-wysiwyg.php
2 months ago
class-evf-field-yes-no.php
1 year ago
payment-amount-helpers.php
4 weeks ago
class-evf-field-hcaptcha.php
149 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Hcaptcha field. |
| 4 | * |
| 5 | * @package EverestForms\Fields |
| 6 | * @since 3.0.0 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * EVF_Field_Hcaptcha Class. |
| 13 | */ |
| 14 | class EVF_Field_Hcaptcha extends \EVF_Form_Fields { |
| 15 | |
| 16 | /** |
| 17 | * Constructor. |
| 18 | */ |
| 19 | public function __construct() { |
| 20 | $this->name = esc_html__( 'hCaptcha', 'everest-forms' ); |
| 21 | $this->type = 'hcaptcha'; |
| 22 | $this->icon = 'evf-icon evf-icon-hcaptcha'; |
| 23 | $this->order = 242; |
| 24 | $this->class = $this->get_hcaptcha_class(); |
| 25 | $this->group = 'advanced'; |
| 26 | $this->settings = array( |
| 27 | 'basic-options' => array( |
| 28 | 'field_options' => array( |
| 29 | 'label', |
| 30 | ), |
| 31 | ), |
| 32 | 'advanced-options' => array( |
| 33 | 'field_options' => array( |
| 34 | 'meta', |
| 35 | ), |
| 36 | ), |
| 37 | ); |
| 38 | |
| 39 | parent::__construct(); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Get hCaptcha class. |
| 44 | * |
| 45 | * @return string |
| 46 | */ |
| 47 | private function get_hcaptcha_class() { |
| 48 | $site_key = get_option( 'everest_forms_recaptcha_hcaptcha_site_key' ); |
| 49 | $secret_key = get_option( 'everest_forms_recaptcha_hcaptcha_secret_key' ); |
| 50 | $recaptcha_type = get_option( 'everest_forms_recaptcha_type', 'v2' ); |
| 51 | return ( empty( $site_key ) || empty( $secret_key ) || 'hcaptcha' !== $recaptcha_type ) ? 'hcaptcha_empty_key_validate' : ''; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Field preview inside the builder. |
| 56 | * |
| 57 | * @since 3.0.0 |
| 58 | * |
| 59 | * @param array $field Field data and settings. |
| 60 | */ |
| 61 | public function field_preview( $field ) { |
| 62 | $recaptcha_type = get_option( 'everest_forms_recaptcha_type', '' ); |
| 63 | $hcaptcha_enabled = get_option( 'everest_forms_recaptcha_hcaptcha_enable', 'no' ); |
| 64 | $site_key = get_option( 'everest_forms_recaptcha_hcaptcha_site_key' ); |
| 65 | $secret_key = get_option( 'everest_forms_recaptcha_hcaptcha_secret_key' ); |
| 66 | |
| 67 | if ( 'hcaptcha' !== $recaptcha_type ) { |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | if ( 'yes' !== $hcaptcha_enabled ) { |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | if ( empty( $site_key ) || empty( $secret_key ) ) { |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | // Label. |
| 80 | $this->field_preview_option( 'label', $field ); |
| 81 | |
| 82 | // Default value. |
| 83 | $default_value = isset( $field['default_value'] ) && ! empty( $field['default_value'] ) ? $field['default_value'] : ''; |
| 84 | $image_url = plugins_url( 'assets/images/captcha/hCAPTCHA.png', EVF_PLUGIN_FILE ); |
| 85 | echo '<img src="' . esc_url( $image_url ) . '" class="widefat" disabled />'; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | /** |
| 90 | * Field display on the form front-end. |
| 91 | * |
| 92 | * @since 3.0.0 |
| 93 | * |
| 94 | * @param array $field Field Data. |
| 95 | * @param array $field_atts Field attributes. |
| 96 | * @param array $form_data All Form Data. |
| 97 | */ |
| 98 | public function field_display( $field, $field_atts, $form_data ) { |
| 99 | $recaptcha_type = get_option( 'everest_forms_recaptcha_type', '' ); |
| 100 | $hcaptcha_enabled = get_option( 'everest_forms_recaptcha_hcaptcha_enable', 'no' ); |
| 101 | |
| 102 | if ( 'hcaptcha' !== $recaptcha_type || 'yes' !== $hcaptcha_enabled ) { |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | $site_key = get_option( 'everest_forms_recaptcha_hcaptcha_site_key' ); |
| 107 | $secret_key = get_option( 'everest_forms_recaptcha_hcaptcha_secret_key' ); |
| 108 | |
| 109 | if ( empty( $site_key ) || empty( $secret_key ) ) { |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | $form_id = isset( $form_data['id'] ) ? absint( $form_data['id'] ) : 0; |
| 114 | $visible = ! empty( self::$parts[ $form_id ] ) ? 'style="display:none;"' : ''; |
| 115 | $data = apply_filters( |
| 116 | 'everest_forms_frontend_recaptcha', |
| 117 | array( |
| 118 | 'sitekey' => trim( sanitize_text_field( $site_key ) ), |
| 119 | ), |
| 120 | $form_data |
| 121 | ); |
| 122 | |
| 123 | if ( $site_key && $secret_key ) { |
| 124 | $recaptcha_api = apply_filters( 'everest_forms_frontend_recaptcha_url', 'https://hcaptcha.com/1/api.js??onload=EVFRecaptchaLoad&render=explicit', 'hcaptcha', $form_id ); |
| 125 | $recaptcha_inline = 'var EVFRecaptchaLoad = function(){jQuery(".g-recaptcha").each(function(index, el){var recaptchaID = hcaptcha.render(el,{callback:function(){EVFRecaptchaCallback(el);}},true);jQuery(el).attr( "data-recaptcha-id", recaptchaID);});};'; |
| 126 | $recaptcha_inline .= 'var EVFRecaptchaCallback = function(el){jQuery(el).parent().find(".evf-recaptcha-hidden").val("1").trigger("change").valid();};'; |
| 127 | |
| 128 | wp_enqueue_script( |
| 129 | 'evf-recaptcha', |
| 130 | $recaptcha_api, |
| 131 | array( 'jquery' ), |
| 132 | '2.0.0', |
| 133 | true |
| 134 | ); |
| 135 | |
| 136 | static $count = 1; |
| 137 | if ( 1 === $count ) { |
| 138 | wp_add_inline_script( 'evf-recaptcha', $recaptcha_inline ); |
| 139 | ++$count; |
| 140 | } |
| 141 | |
| 142 | echo '<div class="evf-recaptcha-container" style="display:' . ( ! empty( self::$parts[ $form_id ] ) ? 'none' : 'block' ) . '">'; |
| 143 | echo '<div ' . evf_html_attributes( '', array( 'g-recaptcha' ), $data ) . '></div>'; |
| 144 | echo '<input type="text" name="g-recaptcha-hidden" class="evf-recaptcha-hidden" style="position:absolute!important;clip:rect(0,0,0,0)!important;height:1px!important;width:1px!important;border:0!important;overflow:hidden!important;padding:0!important;margin:0!important;" required>'; |
| 145 | echo '</div>'; |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 |