Skip to content

Commit

Permalink
Merge pull request #47 from erikyo/wpcf7-integration
Browse files Browse the repository at this point in the history
WPCF7 Integration + issue #45
  • Loading branch information
erikyo authored Oct 13, 2023
2 parents 0d84a92 + 018ca5d commit bc2a140
Show file tree
Hide file tree
Showing 16 changed files with 350 additions and 50 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,8 @@ out
# OS or Editor folders
.DS_Store
Thumbs.db

# lock files
.lock

**/dist/
9 changes: 6 additions & 3 deletions admin/admin-customizations.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,23 @@ public function cf7a_options_init() {
array( $this, 'cf7a_sanitize_options' )
);


/* Section Bot Fingerprint */
add_settings_section(
'cf7a_subtitle',
__( 'Settings', 'cf7-antispam' ),
array( $this, 'cf7a_print_section_main_subtitle' ),
'cf7a-settings'
);

/* Section Bot Fingerprint */
add_settings_section(
'cf7a_auto_blacklist',
__( 'Ban automatically spammers', 'cf7-antispam' ),
array( $this, 'cf7a_print_section_auto_blacklist' ),
'cf7a-settings'
);

/* Settings autostore_bad_ip */
add_settings_field(
'autostore_bad_ip',
Expand Down Expand Up @@ -977,6 +978,8 @@ public function cf7a_sanitize_options( $input ) {
/* get the existing options */
$new_input = $this->options;

$new_input['cf7a_enable'] = isset( $input['cf7a_enable'] ) ? $input['cf7a_enable'] : $new_input['cf7a_enable'];

/* bot fingerprint */
$new_input['check_bot_fingerprint'] = isset( $input['check_bot_fingerprint'] ) ? 1 : 0;
$new_input['check_bot_fingerprint_extras'] = isset( $input['check_bot_fingerprint_extras'] ) ? 1 : 0;
Expand Down Expand Up @@ -1095,7 +1098,7 @@ public function cf7a_sanitize_options( $input ) {
$score_preset = $this->cf7a_get_scores_presets();

/* Scoring: if the preset name is equal to $selected and (the old score is the same of the new one OR the preset score $selected is changed) */
if ( $input['score'] === $this->options['score'] || $input['cf7a_score_preset'] !== $this->options['cf7a_score_preset'] ) {
if ( $input['score'] !== $this->options['score'] || $input['cf7a_score_preset'] !== $this->options['cf7a_score_preset'] ) {
if ( 'weak' === $input['cf7a_score_preset'] ) {
$new_input['score'] = $score_preset['weak'];
$new_input['cf7a_score_preset'] = 'weak';
Expand Down
1 change: 0 additions & 1 deletion admin/dist/admin-scripts.asset.php

This file was deleted.

1 change: 0 additions & 1 deletion admin/dist/admin-scripts.js

This file was deleted.

2 changes: 0 additions & 2 deletions admin/dist/main.css

This file was deleted.

2 changes: 2 additions & 0 deletions admin/src/admin-scripts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import './dashboard/dashboard';
import './dashboard/dashboard.scss';

import './integration/integration.scss';

import './settings/settings.js';
import './settings/settings.scss';
13 changes: 13 additions & 0 deletions admin/src/integration/integration.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#cf7-antispam{

input {
margin: 0 5px 0 0;
}

.integration-icon {
display: inline-block;
padding-block: inherit;
margin: 0 0 0 0.7em;
width: 30px;
}
}
55 changes: 22 additions & 33 deletions assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 31 additions & 3 deletions cf7-antispam.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,36 @@ function uninstall_cf7_antispam() {
/**
* Initialize the plugin once all other plugins have finished loading.
*/


/**
* call the integration action to mount our plugin as a component
* into the intefration page
*/

function cf7_antispam_register_service() {
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/service.php';
$integration = WPCF7_Integration::get_instance();
$integration->add_service(
'cf7-antispam',
WPCF7_Antispam::get_instance()
);

}
add_action( 'wpcf7_init', 'cf7_antispam_register_service', 1, 0 );



function run_cf7a() {
$cf7a = new CF7_AntiSpam();
$cf7a->run();
$enabled = get_option( 'cf7a_options' );
if ( $enabled && $enabled['cf7a_enable'] === true ) {
$cf7a = new CF7_AntiSpam();
$cf7a->run();
}

}
add_action( 'init', 'run_cf7a', 11 );
add_action( 'init', 'run_cf7a', 11, 0 );




1 change: 1 addition & 0 deletions includes/cf7a-activator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CF7_AntiSpam_Activator {
public static function init_vars() {

self::$default_cf7a_options = array(
'cf7a_enable' => true,
'cf7a_version' => CF7ANTISPAM_VERSION,
'cf7a_customizations_class' => CF7ANTISPAM_HONEYPOT_CLASS,
'cf7a_customizations_prefix' => CF7ANTISPAM_PREFIX,
Expand Down
7 changes: 5 additions & 2 deletions includes/cf7a-antispam-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public static function cf7a_check_dnsbl( $reverse_ip, $dnsbl ) {
return checkdnsrr( $reverse_ip . '.' . $dnsbl . '.', 'A' );
}


/* CF7_AntiSpam_Filters blacklists */

/**
Expand Down Expand Up @@ -294,7 +293,7 @@ public function cf7a_spam_filter( $spam ) {
$mail_tags = $contact_form->scan_form_tags();

/* get the sender email field using the flamingo defined */
$email_tag = sanitize_email( cf7a_get_mail_meta( $contact_form->pref( 'flamingo_email' ) ) );
$email_tag = sanitize_title( cf7a_get_mail_meta( $contact_form->pref( 'flamingo_email' ) ) );
$email = isset( $posted_data[ $email_tag ] ) ? $posted_data[ $email_tag ] : false;

/* Getting the message field(s) from the form. */
Expand Down Expand Up @@ -865,6 +864,10 @@ public function cf7a_spam_filter( $spam ) {
$reason['dsnbl'][] = $dnsbl;
$spam_score += $score_dnsbl;
}
// if ( $this->cf7a_check_emailbl( $dnsbl ) ) {
// $reason['dsnbl'][] = $dnsbl;
// $spam_score += $score_dnsbl;
// }
}

if ( isset( $reason['dsnbl'] ) ) {
Expand Down
7 changes: 5 additions & 2 deletions includes/cf7a-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class CF7_AntiSpam {
* The constructor function is called when the plugin is loaded. It sets the version, plugin name, and options. It loads
* the dependencies, sets the locale, updates the plugin, and loads the admin and frontend areas
*/



public function __construct() {
if ( defined( 'CF7ANTISPAM_VERSION' ) ) {
$this->version = CF7ANTISPAM_VERSION;
Expand Down Expand Up @@ -110,9 +113,9 @@ public function __construct() {
* with WordPress.
*
* @since 0.2.4
* @access private
* @access protected
*/
private function update() {
protected function update() {

require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-activator.php';
do_action( 'cf7a_update' );
Expand Down
1 change: 0 additions & 1 deletion includes/dist/script.asset.php

This file was deleted.

Loading

0 comments on commit bc2a140

Please sign in to comment.