Edit File by line
/home/zeestwma/ajeebong.../wp-conte.../plugins/zero-spa.../modules/wpforms
File: class-wpforms.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WPForms integration module
[2] Fix | Delete
*
[3] Fix | Delete
* Malicious user detection techniques available:
[4] Fix | Delete
*
[5] Fix | Delete
* 1. Zero Spam honeypot field
[6] Fix | Delete
* 2. Uses the David Walsh technique
[7] Fix | Delete
*
[8] Fix | Delete
* @package ZeroSpam
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
namespace ZeroSpam\Modules\WPForms;
[12] Fix | Delete
[13] Fix | Delete
// Security Note: Blocks direct access to the plugin PHP files.
[14] Fix | Delete
defined( 'ABSPATH' ) || die();
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* WPForms
[18] Fix | Delete
*/
[19] Fix | Delete
class WPForms {
[20] Fix | Delete
/**
[21] Fix | Delete
* Constructor
[22] Fix | Delete
*/
[23] Fix | Delete
public function __construct() {
[24] Fix | Delete
add_action( 'init', array( $this, 'init' ) );
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Fires after WordPress has finished loading but before any headers are sent.
[29] Fix | Delete
*/
[30] Fix | Delete
public function init() {
[31] Fix | Delete
add_filter( 'zerospam_setting_sections', array( $this, 'sections' ) );
[32] Fix | Delete
add_filter( 'zerospam_settings', array( $this, 'settings' ), 10, 1 );
[33] Fix | Delete
add_filter( 'zerospam_types', array( $this, 'types' ), 10, 1 );
[34] Fix | Delete
[35] Fix | Delete
if (
[36] Fix | Delete
'enabled' === \ZeroSpam\Core\Settings::get_settings( 'verify_wpforms' ) &&
[37] Fix | Delete
\ZeroSpam\Core\Access::process()
[38] Fix | Delete
) {
[39] Fix | Delete
// Adds Zero Spam's honeypot field.
[40] Fix | Delete
add_action( 'wpforms_frontend_output', array( $this, 'honeypot' ), 10, 1 );
[41] Fix | Delete
[42] Fix | Delete
// Load scripts.
[43] Fix | Delete
add_action( 'wpforms_frontend_output', array( $this, 'add_scripts' ) );
[44] Fix | Delete
[45] Fix | Delete
// Processes the form.
[46] Fix | Delete
add_action( 'wpforms_process', array( $this, 'preprocess_submission' ), 10, 3 );
[47] Fix | Delete
}
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* Adds Zero Spam's honeypot field.
[52] Fix | Delete
*/
[53] Fix | Delete
public function honeypot() {
[54] Fix | Delete
// @codingStandardsIgnoreLine
[55] Fix | Delete
echo \ZeroSpam\Core\Utilities::honeypot_field();
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* Preprocess submission
[60] Fix | Delete
*
[61] Fix | Delete
* @param array $fields Sanitized entry field values/properties.
[62] Fix | Delete
* @param array $entry Original $_POST global.
[63] Fix | Delete
* @param array $form_data Form settings/data.
[64] Fix | Delete
*/
[65] Fix | Delete
public function preprocess_submission( $fields, $entry, $form_data ) {
[66] Fix | Delete
// @codingStandardsIgnoreLine
[67] Fix | Delete
$post = \ZeroSpam\Core\Utilities::sanitize_array( $_POST );
[68] Fix | Delete
[69] Fix | Delete
// Get the error message.
[70] Fix | Delete
$error_message = \ZeroSpam\Core\Utilities::detection_message( 'wpforms_spam_message' );
[71] Fix | Delete
[72] Fix | Delete
// Create the details array for logging & sharing data.
[73] Fix | Delete
$details = $fields;
[74] Fix | Delete
$details = array_merge( $details, $entry );
[75] Fix | Delete
$details = array_merge( $details, $form_data );
[76] Fix | Delete
[77] Fix | Delete
$details['type'] = 'wpforms';
[78] Fix | Delete
[79] Fix | Delete
// Begin validation checks.
[80] Fix | Delete
$validation_errors = array();
[81] Fix | Delete
[82] Fix | Delete
// Check individual fields.
[83] Fix | Delete
if ( ! empty( $post['wpforms'] ) && ! empty( $post['wpforms']['fields'] ) ) {
[84] Fix | Delete
foreach ( $post['wpforms']['fields'] as $key => $field ) {
[85] Fix | Delete
if ( is_array( $field ) ) {
[86] Fix | Delete
foreach ( $field as $k => $value ) {
[87] Fix | Delete
if ( \ZeroSpam\Core\Utilities::is_email( $value ) && \ZeroSpam\Core\Utilities::is_email_domain_blocked( $value ) ) {
[88] Fix | Delete
// Email address found & is blocked.
[89] Fix | Delete
$validation_errors[] = 'blocked_email_domain';
[90] Fix | Delete
} else {
[91] Fix | Delete
// Check against disallowed list.
[92] Fix | Delete
if ( \ZeroSpam\Core\Utilities::is_disallowed( $value ) ) {
[93] Fix | Delete
$validation_errors[] = 'disallowed_list';
[94] Fix | Delete
}
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
} elseif ( \ZeroSpam\Core\Utilities::is_email( $field ) && \ZeroSpam\Core\Utilities::is_email_domain_blocked( $field ) ) {
[98] Fix | Delete
// Email address found & is blocked.
[99] Fix | Delete
$validation_errors[] = 'blocked_email_domain';
[100] Fix | Delete
} else {
[101] Fix | Delete
// Check against disallowed list.
[102] Fix | Delete
if ( \ZeroSpam\Core\Utilities::is_disallowed( $field ) ) {
[103] Fix | Delete
$validation_errors[] = 'disallowed_list';
[104] Fix | Delete
}
[105] Fix | Delete
}
[106] Fix | Delete
}
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
// Check Zero Spam's honeypot field.
[110] Fix | Delete
$honeypot_field_name = \ZeroSpam\Core\Utilities::get_honeypot();
[111] Fix | Delete
// @codingStandardsIgnoreLine
[112] Fix | Delete
if ( isset( $post[ $honeypot_field_name ] ) && ! empty( $post[ $honeypot_field_name ] ) ) {
[113] Fix | Delete
// Failed the honeypot check.
[114] Fix | Delete
$details['failed'] = 'honeypot';
[115] Fix | Delete
[116] Fix | Delete
$validation_errors[] = 'honeypot';
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
// Fire hook for additional validation (ex. David Walsh script).
[120] Fix | Delete
$errors = apply_filters( 'zerospam_preprocess_wpforms_submission', array(), $post, 'wpforms_spam_message' );
[121] Fix | Delete
[122] Fix | Delete
if ( ! empty( $errors ) ) {
[123] Fix | Delete
foreach ( $errors as $key => $message ) {
[124] Fix | Delete
$validation_errors[] = str_replace( 'zerospam_', '', $key );
[125] Fix | Delete
}
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
if ( ! empty( $validation_errors ) ) {
[129] Fix | Delete
// Failed validations, log & send details if enabled.
[130] Fix | Delete
foreach ( $validation_errors as $key => $fail ) {
[131] Fix | Delete
$details['failed'] = $fail;
[132] Fix | Delete
[133] Fix | Delete
// Log the detection if enabled.
[134] Fix | Delete
if ( 'enabled' === \ZeroSpam\Core\Settings::get_settings( 'log_blocked_wpforms' ) ) {
[135] Fix | Delete
\ZeroSpam\Includes\DB::log( 'wpforms', $details );
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
// Share the detection if enabled.
[139] Fix | Delete
if ( 'enabled' === \ZeroSpam\Core\Settings::get_settings( 'share_data' ) ) {
[140] Fix | Delete
do_action( 'zerospam_share_detection', $details );
[141] Fix | Delete
}
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
wpforms()->process->errors[ $form_data['id'] ]['header'] = $error_message;
[145] Fix | Delete
}
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
/**
[149] Fix | Delete
* Add to the detection types array
[150] Fix | Delete
*
[151] Fix | Delete
* @param array $types Array of available detection types.
[152] Fix | Delete
*/
[153] Fix | Delete
public function types( $types ) {
[154] Fix | Delete
$types['wpforms'] = array(
[155] Fix | Delete
'label' => __( 'WPForms', 'zero-spam' ),
[156] Fix | Delete
'color' => '#e27730',
[157] Fix | Delete
);
[158] Fix | Delete
[159] Fix | Delete
return $types;
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
/**
[163] Fix | Delete
* Load the scripts
[164] Fix | Delete
*/
[165] Fix | Delete
public function add_scripts() {
[166] Fix | Delete
// Only add scripts to the appropriate pages.
[167] Fix | Delete
if ( 'enabled' === \ZeroSpam\Core\Settings::get_settings( 'davidwalsh' ) ) {
[168] Fix | Delete
wp_enqueue_script( 'zerospam-davidwalsh' );
[169] Fix | Delete
[170] Fix | Delete
add_action(
[171] Fix | Delete
'wp_enqueue_scripts',
[172] Fix | Delete
function () {
[173] Fix | Delete
wp_add_inline_script( 'zerospam-davidwalsh', 'document.addEventListener("DOMContentLoaded", function() { jQuery(".wpforms-form").ZeroSpamDavidWalsh(); });' );
[174] Fix | Delete
}
[175] Fix | Delete
);
[176] Fix | Delete
}
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* Admin setting sections
[181] Fix | Delete
*
[182] Fix | Delete
* @param array $sections Array of admin setting sections.
[183] Fix | Delete
*/
[184] Fix | Delete
public function sections( $sections ) {
[185] Fix | Delete
$sections['wpforms'] = array(
[186] Fix | Delete
'title' => __( 'WPForms', 'zero-spam' ),
[187] Fix | Delete
'icon' => 'modules/wpforms/icon-wpforms.svg',
[188] Fix | Delete
'supports' => array( 'honeypot', 'davidwalsh', 'email', 'words' ),
[189] Fix | Delete
);
[190] Fix | Delete
[191] Fix | Delete
return $sections;
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
/**
[195] Fix | Delete
* Admin settings
[196] Fix | Delete
*
[197] Fix | Delete
* @param array $settings Array of available settings.
[198] Fix | Delete
*/
[199] Fix | Delete
public function settings( $settings ) {
[200] Fix | Delete
$options = get_option( 'zero-spam-wpforms' );
[201] Fix | Delete
[202] Fix | Delete
$settings['verify_wpforms'] = array(
[203] Fix | Delete
'title' => __( 'Protect WPForms Submissions', 'zero-spam' ),
[204] Fix | Delete
'desc' => __( 'Protects & monitors WPForms submissions.', 'zero-spam' ),
[205] Fix | Delete
'section' => 'wpforms',
[206] Fix | Delete
'module' => 'wpforms',
[207] Fix | Delete
'type' => 'checkbox',
[208] Fix | Delete
'options' => array(
[209] Fix | Delete
'enabled' => false,
[210] Fix | Delete
),
[211] Fix | Delete
'value' => ! empty( $options['verify_wpforms'] ) ? $options['verify_wpforms'] : false,
[212] Fix | Delete
'recommended' => 'enabled',
[213] Fix | Delete
);
[214] Fix | Delete
[215] Fix | Delete
$message = __( 'Your IP has been flagged as spam/malicious.', 'zero-spam' );
[216] Fix | Delete
[217] Fix | Delete
$settings['wpforms_spam_message'] = array(
[218] Fix | Delete
'title' => __( 'Flagged Message', 'zero-spam' ),
[219] Fix | Delete
'desc' => __( 'Message displayed when a submission has been flagged.', 'zero-spam' ),
[220] Fix | Delete
'section' => 'wpforms',
[221] Fix | Delete
'module' => 'wpforms',
[222] Fix | Delete
'type' => 'text',
[223] Fix | Delete
'field_class' => 'large-text',
[224] Fix | Delete
'placeholder' => $message,
[225] Fix | Delete
'value' => ! empty( $options['wpforms_spam_message'] ) ? $options['wpforms_spam_message'] : $message,
[226] Fix | Delete
'recommended' => $message,
[227] Fix | Delete
);
[228] Fix | Delete
[229] Fix | Delete
$settings['log_blocked_wpforms'] = array(
[230] Fix | Delete
'title' => __( 'Log Blocked WPForms Submissions', 'zero-spam' ),
[231] Fix | Delete
'section' => 'wpforms',
[232] Fix | Delete
'module' => 'wpforms',
[233] Fix | Delete
'type' => 'checkbox',
[234] Fix | Delete
'desc' => wp_kses(
[235] Fix | Delete
__( 'When enabled, stores blocked WPForms submissions in the database.', 'zero-spam' ),
[236] Fix | Delete
array( 'strong' => array() )
[237] Fix | Delete
),
[238] Fix | Delete
'options' => array(
[239] Fix | Delete
'enabled' => false,
[240] Fix | Delete
),
[241] Fix | Delete
'value' => ! empty( $options['log_blocked_wpforms'] ) ? $options['log_blocked_wpforms'] : false,
[242] Fix | Delete
'recommended' => 'enabled',
[243] Fix | Delete
);
[244] Fix | Delete
[245] Fix | Delete
return $settings;
[246] Fix | Delete
}
[247] Fix | Delete
}
[248] Fix | Delete
[249] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function