gform_recaptcha_init_script

Description

This filter is no longer available since Gravity Forms 2.0.

Use this filter to change the look and feel of the reCAPTCHA field.

Usage

add_filter( 'gform_recaptcha_init_script', 'custom_translation', 10, 3 );

Parameters

  • $script string

    No value currently passed.

  • $form_id integer

    The current Form ID.

  • $field Field Object

    The field that recaptcha applies to.

Examples

This example changes the text displayed in the reCaptcha box to Italian translations, and also changes the theme from the default red one to white. This only works with V1 of reCAPTCHA.

V1 reCAPTCHA

add_filter( 'gform_recaptcha_init_script', 'custom_translation', 10, 3 );
function custom_translation( $script, $form_id, $field ) {
$script = 'RecaptchaOptions.custom_translations = {
instructions_visual : "Scrivi le due parole:",
instructions_audio : "Trascrivi ciu00f2 che senti:",
play_again : "Riascolta la traccia audio",
cant_hear_this : "Scarica la traccia in formato MP3",
visual_challenge : "Modalitu00e0 visiva",
audio_challenge : "Modalitu00e0 auditiva",
refresh_btn : "Chiedi due nuove parole",
help_btn : "Aiuto",
incorrect_try_again : "Scorretto. Riprova."
};RecaptchaOptions.theme = "white"';
return $script;
}

V2 reCAPTCHA

This version of reCAPTCHA is planned to be released with Gravity Forms 2.0 and new reCAPTCHA fields added will use this version. There are only a few customizations that may be done in this version. Please see https://developers.google.com/recaptcha/docs/display for more details.

The example below changes the theme (dark vs. light default) and the type (audio vs. image default).

add_filter( 'gform_recaptcha_init_script','custom_translation', 10, 3 );
function custom_translation( $script, $form_id, $field ) {
$script = 'RecaptchaOptions.theme = "dark";RecaptchaOptions.type = "audio"';
return $script;
}

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in GF_Field_CAPTCHA::get_field_input() in includes/fields/class-gf-field-captcha.php