Edit File by line
/home/zeestwma/ajeebong.../wp-conte.../plugins/zero-spa.../modules/fluentfo...
File: class-fluentforms.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Fluent Forms class
[2] Fix | Delete
*
[3] Fix | Delete
* @package ZeroSpam
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
namespace ZeroSpam\Modules\FluentForms;
[7] Fix | Delete
[8] Fix | Delete
// Security Note: Blocks direct access to the plugin PHP files.
[9] Fix | Delete
defined( 'ABSPATH' ) || die();
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Fluent Forms
[13] Fix | Delete
*/
[14] Fix | Delete
class FluentForms {
[15] Fix | Delete
/**
[16] Fix | Delete
* Constructor
[17] Fix | Delete
*/
[18] Fix | Delete
public function __construct() {
[19] Fix | Delete
add_action( 'init', array( $this, 'init' ) );
[20] Fix | Delete
}
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* Fires after WordPress has finished loading but before any headers are sent.
[24] Fix | Delete
*/
[25] Fix | Delete
public function init() {
[26] Fix | Delete
add_filter( 'zerospam_setting_sections', array( $this, 'sections' ) );
[27] Fix | Delete
add_filter( 'zerospam_settings', array( $this, 'settings' ), 10, 1 );
[28] Fix | Delete
add_filter( 'zerospam_types', array( $this, 'types' ), 10, 1 );
[29] Fix | Delete
[30] Fix | Delete
if (
[31] Fix | Delete
'enabled' === \ZeroSpam\Core\Settings::get_settings( 'verify_fluentforms' ) &&
[32] Fix | Delete
\ZeroSpam\Core\Access::process()
[33] Fix | Delete
) {
[34] Fix | Delete
// Load scripts.
[35] Fix | Delete
add_action( 'fluentform_load_form_assets', array( $this, 'scripts' ), 10 );
[36] Fix | Delete
[37] Fix | Delete
// Adds Zero Spam's honeypot field.
[38] Fix | Delete
add_filter( 'fluentform_rendering_form', array( $this, 'render_form' ), 10, 1 );
[39] Fix | Delete
[40] Fix | Delete
// Processes the form.
[41] Fix | Delete
add_action( 'fluentform_before_insert_submission', array( $this, 'process_form' ), 10, 3 );
[42] Fix | Delete
[43] Fix | Delete
// Validates email addresses.
[44] Fix | Delete
add_filter( 'fluentform_validate_input_item_input_email', array( $this, 'validate_email' ), 10, 5 );
[45] Fix | Delete
}
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* Fires before a form is rendered.
[50] Fix | Delete
*/
[51] Fix | Delete
public function scripts() {
[52] Fix | Delete
do_action( 'zerospam_fluentforms_scripts' );
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Adds Zero Spam's custom form fields.
[57] Fix | Delete
*
[58] Fix | Delete
* @see https://fluentforms.com/docs/fluentform_rendering_form/
[59] Fix | Delete
*
[60] Fix | Delete
* @param $form The $form Object.
[61] Fix | Delete
*/
[62] Fix | Delete
public function render_form( $form ) {
[63] Fix | Delete
// Add Zero Spam's honeypot field.
[64] Fix | Delete
$honeypot_field_name = \ZeroSpam\Core\Utilities::get_honeypot();
[65] Fix | Delete
[66] Fix | Delete
$form->fields['fields'][] = array(
[67] Fix | Delete
'element' => 'input_hidden',
[68] Fix | Delete
'attributes' => array(
[69] Fix | Delete
'type' => 'hidden',
[70] Fix | Delete
'name' => $honeypot_field_name,
[71] Fix | Delete
'value' => '',
[72] Fix | Delete
),
[73] Fix | Delete
);
[74] Fix | Delete
[75] Fix | Delete
return $form;
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
/**
[79] Fix | Delete
* Processes a Fluent Form submission after it's validation is completed.
[80] Fix | Delete
*
[81] Fix | Delete
* @see https://fluentforms.com/docs/fluentform_before_insert_submission/
[82] Fix | Delete
*
[83] Fix | Delete
* @param array $insert_data submission_data Array.
[84] Fix | Delete
* @param array $data $_POST[‘data’] from submission.
[85] Fix | Delete
* @param object $form The $form Object.
[86] Fix | Delete
*/
[87] Fix | Delete
public function process_form( $insert_data, $data, $form ) {
[88] Fix | Delete
$error_message = \ZeroSpam\Core\Utilities::detection_message( 'fluentforms_spam_message' );
[89] Fix | Delete
[90] Fix | Delete
// Check Zero Spam's honeypot field.
[91] Fix | Delete
$honeypot_field_name = \ZeroSpam\Core\Utilities::get_honeypot();
[92] Fix | Delete
[93] Fix | Delete
// Create the details array for logging & sharing data.
[94] Fix | Delete
$details = array(
[95] Fix | Delete
'insert_data' => $insert_data,
[96] Fix | Delete
'data' => $data,
[97] Fix | Delete
'form' => array(
[98] Fix | Delete
'id' => $form->id,
[99] Fix | Delete
'title' => $form->title,
[100] Fix | Delete
),
[101] Fix | Delete
);
[102] Fix | Delete
[103] Fix | Delete
if ( ! isset( $data[ $honeypot_field_name ] ) || ! empty( $data[ $honeypot_field_name ] ) ) {
[104] Fix | Delete
// Failed the honeypot check.
[105] Fix | Delete
$details['failed'] = 'honeypot';
[106] Fix | Delete
[107] Fix | Delete
// Log the detection if enabled.
[108] Fix | Delete
if ( 'enabled' === \ZeroSpam\Core\Settings::get_settings( 'log_blocked_fluentforms' ) ) {
[109] Fix | Delete
\ZeroSpam\Includes\DB::log( 'fluent_form', $details );
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
// Share the detection if enabled.
[113] Fix | Delete
if ( 'enabled' === \ZeroSpam\Core\Settings::get_settings( 'share_data' ) ) {
[114] Fix | Delete
$details['type'] = 'fluent_form';
[115] Fix | Delete
do_action( 'zerospam_share_detection', $details );
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
wp_send_json(
[119] Fix | Delete
array(
[120] Fix | Delete
'errors' => array(
[121] Fix | Delete
'zerospam_honeypot' => $error_message,
[122] Fix | Delete
),
[123] Fix | Delete
),
[124] Fix | Delete
422
[125] Fix | Delete
);
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
// Fire hook for additional validation (ex. David Walsh script).
[129] Fix | Delete
$errors = apply_filters( 'zerospam_preprocess_fluentform_submission', array(), $data, 'fluentforms_spam_message' );
[130] Fix | Delete
[131] Fix | Delete
if ( ! empty( $errors ) ) {
[132] Fix | Delete
$errors_array = array();
[133] Fix | Delete
foreach ( $errors as $key => $message ) {
[134] Fix | Delete
$errors_array[ $key ] = $message;
[135] Fix | Delete
[136] Fix | Delete
$details['failed'] = str_replace( 'zerospam_', '', $key );
[137] Fix | Delete
[138] Fix | Delete
// Log the detection if enabled.
[139] Fix | Delete
if ( 'enabled' === \ZeroSpam\Core\Settings::get_settings( 'log_blocked_fluentforms' ) ) {
[140] Fix | Delete
\ZeroSpam\Includes\DB::log( 'fluent_form', $details );
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
// Share the detection if enabled.
[144] Fix | Delete
if ( 'enabled' === \ZeroSpam\Core\Settings::get_settings( 'share_data' ) ) {
[145] Fix | Delete
$details['type'] = 'fluent_form';
[146] Fix | Delete
do_action( 'zerospam_share_detection', $details );
[147] Fix | Delete
}
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
wp_send_json(
[151] Fix | Delete
array(
[152] Fix | Delete
'errors' => $errors_array,
[153] Fix | Delete
),
[154] Fix | Delete
422
[155] Fix | Delete
);
[156] Fix | Delete
}
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
/**
[160] Fix | Delete
* Validates email inputs.
[161] Fix | Delete
*
[162] Fix | Delete
* @see https://fluentforms.com/docs/fluentform_validate_input_item_input_text/
[163] Fix | Delete
*
[164] Fix | Delete
* @param string $error Error message.
[165] Fix | Delete
* @param array $field Contains the fill field settings.
[166] Fix | Delete
* @param array $form_data Contains all the user input values as key pair.
[167] Fix | Delete
* @param array $fields All fields of the form.
[168] Fix | Delete
* @param object $form The $form Object.
[169] Fix | Delete
*/
[170] Fix | Delete
public function validate_email( $error, $field, $form_data, $fields, $form ) {
[171] Fix | Delete
$field_name = $field['name'];
[172] Fix | Delete
if ( empty( $form_data[ $field_name ] ) ) {
[173] Fix | Delete
return $error;
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
// Check blocked email domains.
[177] Fix | Delete
if (
[178] Fix | Delete
! empty( $form_data[ $field_name ] ) &&
[179] Fix | Delete
\ZeroSpam\Core\Utilities::is_email_domain_blocked( $form_data[ $field_name ] ) &&
[180] Fix | Delete
! \ZeroSpam\Core\Utilities::is_email( $form_data[ $field_name ] )
[181] Fix | Delete
) {
[182] Fix | Delete
$error_message = \ZeroSpam\Core\Utilities::detection_message( 'fluentforms_spam_message' );
[183] Fix | Delete
[184] Fix | Delete
return array( $error_message );
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
return $error;
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
[191] Fix | Delete
/**
[192] Fix | Delete
* Add to the types array
[193] Fix | Delete
*
[194] Fix | Delete
* @param array $types Array of available detection types.
[195] Fix | Delete
*/
[196] Fix | Delete
public function types( $types ) {
[197] Fix | Delete
$types['fluent_form'] = array(
[198] Fix | Delete
'label' => __( 'Fluent Form', 'zero-spam' ),
[199] Fix | Delete
'color' => '#0171ff',
[200] Fix | Delete
);
[201] Fix | Delete
[202] Fix | Delete
return $types;
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
/**
[206] Fix | Delete
* Fluent Forms sections
[207] Fix | Delete
*
[208] Fix | Delete
* @param array $sections Array of available setting sections.
[209] Fix | Delete
*/
[210] Fix | Delete
public function sections( $sections ) {
[211] Fix | Delete
$sections['fluent_form'] = array(
[212] Fix | Delete
'title' => __( 'Fluent Forms', 'zero-spam' ),
[213] Fix | Delete
'icon' => 'modules/fluentforms/icon-fluent-forms.svg',
[214] Fix | Delete
);
[215] Fix | Delete
[216] Fix | Delete
return $sections;
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
/**
[220] Fix | Delete
* Admin settings
[221] Fix | Delete
*
[222] Fix | Delete
* @param array $settings Array of available settings.
[223] Fix | Delete
*/
[224] Fix | Delete
public function settings( $settings ) {
[225] Fix | Delete
$options = get_option( 'zero-spam-fluent_form' );
[226] Fix | Delete
[227] Fix | Delete
$settings['verify_fluentforms'] = array(
[228] Fix | Delete
'title' => __( 'Protect Fluent Form Submissions', 'zero-spam' ),
[229] Fix | Delete
'desc' => __( 'Protects & monitors Fluent Form submissions.', 'zero-spam' ),
[230] Fix | Delete
'section' => 'fluent_form',
[231] Fix | Delete
'module' => 'fluent_form',
[232] Fix | Delete
'type' => 'checkbox',
[233] Fix | Delete
'options' => array(
[234] Fix | Delete
'enabled' => false,
[235] Fix | Delete
),
[236] Fix | Delete
'value' => ! empty( $options['verify_fluentforms'] ) ? $options['verify_fluentforms'] : false,
[237] Fix | Delete
'recommended' => 'enabled',
[238] Fix | Delete
);
[239] Fix | Delete
[240] Fix | Delete
$message = __( 'Your IP has been flagged as spam/malicious.', 'zero-spam' );
[241] Fix | Delete
[242] Fix | Delete
$settings['fluentforms_spam_message'] = array(
[243] Fix | Delete
'title' => __( 'Flagged Message', 'zero-spam' ),
[244] Fix | Delete
'desc' => __( 'Message displayed when a submission has been flagged.', 'zero-spam' ),
[245] Fix | Delete
'section' => 'fluent_form',
[246] Fix | Delete
'module' => 'fluent_form',
[247] Fix | Delete
'type' => 'text',
[248] Fix | Delete
'field_class' => 'large-text',
[249] Fix | Delete
'placeholder' => $message,
[250] Fix | Delete
'value' => ! empty( $options['fluentforms_spam_message'] ) ? $options['fluentforms_spam_message'] : $message,
[251] Fix | Delete
'recommended' => $message,
[252] Fix | Delete
);
[253] Fix | Delete
[254] Fix | Delete
$settings['log_blocked_fluentforms'] = array(
[255] Fix | Delete
'title' => __( 'Log Blocked Fluent Form Submissions', 'zero-spam' ),
[256] Fix | Delete
'section' => 'fluent_form',
[257] Fix | Delete
'module' => 'fluent_form',
[258] Fix | Delete
'type' => 'checkbox',
[259] Fix | Delete
'desc' => wp_kses(
[260] Fix | Delete
__( 'When enabled, stores blocked Fluent Form submissions in the database.', 'zero-spam' ),
[261] Fix | Delete
array( 'strong' => array() )
[262] Fix | Delete
),
[263] Fix | Delete
'options' => array(
[264] Fix | Delete
'enabled' => false,
[265] Fix | Delete
),
[266] Fix | Delete
'value' => ! empty( $options['log_blocked_fluentforms'] ) ? $options['log_blocked_fluentforms'] : false,
[267] Fix | Delete
'recommended' => 'enabled',
[268] Fix | Delete
);
[269] Fix | Delete
[270] Fix | Delete
return $settings;
[271] Fix | Delete
}
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function