Edit File by line
/home/barbar84/www/wp-conte.../plugins/ninja-fo.../includes/Fields
File: Recaptcha.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Class NF_Fields_Recaptcha
[3] Fix | Delete
*/
[4] Fix | Delete
class NF_Fields_Recaptcha extends NF_Abstracts_Field
[5] Fix | Delete
{
[6] Fix | Delete
protected $_name = 'recaptcha';
[7] Fix | Delete
[8] Fix | Delete
protected $_type = 'recaptcha';
[9] Fix | Delete
[10] Fix | Delete
protected $_section = 'misc';
[11] Fix | Delete
[12] Fix | Delete
protected $_icon = 'filter';
[13] Fix | Delete
[14] Fix | Delete
protected $_templates = 'recaptcha';
[15] Fix | Delete
[16] Fix | Delete
protected $_test_value = '';
[17] Fix | Delete
[18] Fix | Delete
protected $_settings = array( 'label', 'classes' );
[19] Fix | Delete
[20] Fix | Delete
public function __construct()
[21] Fix | Delete
{
[22] Fix | Delete
parent::__construct();
[23] Fix | Delete
[24] Fix | Delete
$this->_nicename = esc_html__( 'Recaptcha', 'ninja-forms' );
[25] Fix | Delete
[26] Fix | Delete
$this->_settings[ 'size '] = array(
[27] Fix | Delete
'name' => 'size',
[28] Fix | Delete
'type' => 'select',
[29] Fix | Delete
'label' => esc_html__( 'Visibility', 'ninja-forms' ),
[30] Fix | Delete
'options' => array(
[31] Fix | Delete
array(
[32] Fix | Delete
'label' => esc_html__( 'Visible', 'ninja-forms' ),
[33] Fix | Delete
'value' => 'visible'
[34] Fix | Delete
),
[35] Fix | Delete
array(
[36] Fix | Delete
'label' => esc_html__( 'Invisible', 'ninja-forms' ),
[37] Fix | Delete
'value' => 'invisible'
[38] Fix | Delete
),
[39] Fix | Delete
),
[40] Fix | Delete
'width' => 'one-half',
[41] Fix | Delete
'group' => 'primary',
[42] Fix | Delete
'value' => 'visible',
[43] Fix | Delete
'help' => esc_html__( 'Select whether to display a "I\'m not a robot" field or to detect if the user is a robot in the background.', 'ninja-forms' ),
[44] Fix | Delete
);
[45] Fix | Delete
[46] Fix | Delete
add_filter( 'nf_sub_hidden_field_types', array( $this, 'hide_field_type' ) );
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
public function localize_settings( $settings, $form ) {
[50] Fix | Delete
$settings['site_key'] = Ninja_Forms()->get_setting( 'recaptcha_site_key' );
[51] Fix | Delete
$settings['theme'] = Ninja_Forms()->get_setting( 'recaptcha_theme' );
[52] Fix | Delete
$settings['theme'] = ( $settings['theme'] ) ? $settings['theme'] : 'light';
[53] Fix | Delete
$settings['lang'] = Ninja_Forms()->get_setting( 'recaptcha_lang' );
[54] Fix | Delete
return $settings;
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
public function validate( $field, $data ) {
[58] Fix | Delete
if ( empty( $field['value'] ) ) {
[59] Fix | Delete
return esc_html__( 'Please complete the recaptcha', 'ninja-forms' );
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
$secret_key = Ninja_Forms()->get_setting( 'recaptcha_secret_key' );
[63] Fix | Delete
$url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . $secret_key . '&response='.sanitize_text_field( $field['value'] );
[64] Fix | Delete
$resp = wp_remote_get( esc_url_raw( $url ) );
[65] Fix | Delete
[66] Fix | Delete
if ( !is_wp_error( $resp ) ) {
[67] Fix | Delete
$body = wp_remote_retrieve_body( $resp );
[68] Fix | Delete
$response = json_decode( $body );
[69] Fix | Delete
if ( $response->success === false ) {
[70] Fix | Delete
if ( !empty( $response->{'error-codes'} ) && $response->{'error-codes'} != 'missing-input-response' ) {
[71] Fix | Delete
return array( esc_html__( 'Please make sure you have entered your Site & Secret keys correctly', 'ninja-forms' ) );
[72] Fix | Delete
}else {
[73] Fix | Delete
return array( esc_html__( 'Captcha mismatch. Please enter the correct value in captcha field', 'ninja-forms' ) );
[74] Fix | Delete
}
[75] Fix | Delete
}
[76] Fix | Delete
}
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
function hide_field_type( $field_types )
[80] Fix | Delete
{
[81] Fix | Delete
$field_types[] = $this->_name;
[82] Fix | Delete
return $field_types;
[83] Fix | Delete
}
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function