-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhumanid-spam-filter.php
More file actions
162 lines (129 loc) · 4.26 KB
/
Copy pathhumanid-spam-filter.php
File metadata and controls
162 lines (129 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* @link www.human-id.org
* @since 1.0.0
* @package humanid_spam_filter
*
* @wordpress-plugin
* Plugin Name: humanID – Anti-Spam Comment Filter || Stop junk comments & Protect your users' privacy. 100% open source.
* Plugin URI: https://github.com/human-internet/humanid-spam-filter
* Description: Replace ReCAPTCHA with a faster, user-friendly solution and block spammers & bots permanently
* Version: 2.1.0
* Author: humanID
* Author URI: https://human-id.org/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: humanid-spam-filter
* Domain Path: /languages
*/
namespace humanid_spam_filter;
use KMEnv;
use WordPressTools;
defined( 'ABSPATH' ) or die( 'Giving To Cesar What Belongs To Caesar' );
require 'constants.php';
require HIDSF_CORE_DIR . '/HidSpamFilter.php';
require HIDSF_CORE_DIR . '/Module.php';
/**
* Shows an error message on the admin dashboard
* @since v1.0.0
*/
function HIDSFErrorNotice( $message = '' ) {
if ( trim( $message ) != '' ):
?>
<div class="error notice is-dismissible">
<p><strong>Human ID Spam Filter: </strong><?php echo esc_html( $message ) ?></p>
</div>
<?php
endif;
}
add_action( 'admin_notices', 'humanid_spam_filter\\HIDSFErrorNotice', 10, 1 );
/***
* loads classes / files
* @since v1.0.0
***/
function HIDSFLoader(): bool {
$error = false;
// scan directories for requires.php files
foreach ( scandir( __DIR__ ) as $dir ) {
if ( strpos( $dir, '.' ) === false && is_dir( __DIR__ . '/' . $dir ) && is_file( __DIR__ . '/' . $dir . '/requires.php' ) ) {
require_once __DIR__ . '/' . $dir . '/requires.php';
}
}
$requires = apply_filters( 'hidsf_requires_filter', [] );
foreach ( $requires as $file ) {
if ( ! $filepath = file_exists( $file ) ) {
HIDSFErrorNotice( sprintf( __( 'Error locating <b>%s</b> for inclusion', KMCF7MS_TEXT_DOMAIN ), $file ) );
$error = true;
} else {
require_once $file;
}
}
// scan directories for includes.php files
foreach ( scandir( __DIR__ ) as $dir ) {
if ( strpos( $dir, '.' ) === false && is_dir( __DIR__ . '/' . $dir ) && is_file( __DIR__ . '/' . $dir . '/includes.php' ) ) {
require_once __DIR__ . '/' . $dir . '/includes.php';
}
}
$includes = apply_filters( 'hidsf_includes_filter', [] );
foreach ( $includes as $file ) {
if ( ! $filepath = file_exists( $file ) ) {
HIDSFErrorNotice( sprintf( __( 'Error locating <b>%s</b> for inclusion', KMCF7MS_TEXT_DOMAIN ), $file ) );
$error = true;
} else {
include_once $file;
}
}
return $error;
}
/**
* Starts the spam filter
* @since v1.0.0
*/
function HIDSFStart() {
$wordpress_tools = new WordPressTools( __FILE__ );
$wordpress_tools->migration_manager->runMigrations();
$spam_filter = new HidSpamFilter();
$spam_filter->start();
}
if ( ! HIDSFLoader() ) {
HIDSFStart();
}
// remove options upon deactivation
register_deactivation_hook( __FILE__, 'humanid_spam_filter\\HIDSFDeactivation' );
/**
* Set of actions to be performed on deactivation
* @since v1.0.0
*/
function HIDSFDeactivation() {
delete_option( 'hidsf_is_permalink_updated' );
// set options to remove here
}
register_uninstall_hook( __FILE__, 'humanid_spam_filter\\HIDSFUninstall' );
/**
* Set of actions to be performed on uninstallation
* @since v1.0.0
*/
function HIDSFUninstall() {
global $wpdb;
delete_option( 'hidsf_is_permalink_updated' );
$instance = WordPressTools::getInstance( __FILE__ );
$instance->migration_manager->dropAll();
//query the wp options table and delete all options that start with hidsf_
$query = $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name LIKE 'hidsf_%'" );
$wpdb->query( $query );
// todo; drop migrations table
$env = ( new KMEnv( __FILE__ ) )->getEnv();
$table_name = $wpdb->prefix . trim( $env['TABLE_PREFIX'] ) . 'migrations';
$query = $wpdb->prepare( "DROP TABLE IF EXISTS {$table_name}" );
$wpdb->query( $query );
}
register_activation_hook( __FILE__, 'humanid_spam_filter\\HIDSFActivation' );
/**
* Set of actions to be performed on activation
* @since v1.0.0
*/
function HIDSFActivation() {
// set options to add here
}
// todo: for future use
load_plugin_textdomain( HIDSF_TEXT_DOMAIN, false, basename( dirname( __FILE__ ) ) . '/languages' );