1/**
2 *
3 */
4function myplugin_wpf2b_register()
5{
6 // Register the plugin
7 try {
8 do_action(
9 'wp_fail2ban_register_plugin',
10 'my-plugin-slug',
11 'My Plugin Name'
12 );
13 } catch(\LengthException $e) {
14 // slug or name too long
15 } catch(\RuntimeException $e) {
16 // database error
17 }
18
19 // Register a message
20 $args = [
21 'slug' => 'my-plugin-msg-slug-1',
22 'fail' => 'hard',
23 'priority' => LOG_NOTICE,
24 'event_class' => 'Password',
25 'event_id' => 0x001F,
26 'message' => 'Message with ___VAR1___ and ___VAR2___',
27 'vars' => [
28 'VAR1' => '\d+',
29 'VAR2' => '*.'
30 ]
31 ];
32 try {
33 do_action(
34 'wp_fail2ban_register_message',
35 'my-plugin-slug',
36 $args
37 );
38 } catch(\InvalidArgumentException $e) {
39 // Missing entry or invalid type
40 } catch(\UnexpectedValueException $e) {
41 // Invalid value
42 }
43}
44add_action(
45 'wp_fail2ban_register',
46 __NAMESPACE__.'\myplugin_wpf2b_register'
47);
48
49/**
50 *
51 */
52function myplugin_foobar()
53{
54 $vars = [
55 'VAR1' => 12345,
56 'VAR2' => 'xyz'
57 ];
58 do_action(
59 'wp_fail2ban_log_message',
60 'my-plugin-slug',
61 'my-plugin-msg-slug-1',
62 $vars
63 );
64}