|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * Gravity Wiz // Gravity Forms // Spam Notification |
4 | | - * |
5 | | - * Send notifications when an entry is marked as spam. Will only fire when the entry is marked as spam as part of the |
6 | | - * initial form submission. |
7 | | - * |
8 | | - * Plugin Name: GF Spam Notification |
9 | | - * Plugin URI: http://gravitywiz.com/ |
10 | | - * Description: Send notifications when an entry is marked as spam. |
11 | | - * Author: Gravity Wiz |
12 | | - * Version: 1.0 |
13 | | - * Author URI: http://gravitywiz.com |
14 | | - * |
15 | | - * @todo |
16 | | - * - Add support for generating a one-click link to ham an entry. |
17 | | - * - Add support for auto-processing feeds when an entry is hammed. |
| 3 | + * This snippet is now available as a free plugin with Spellbook. ✨ |
| 4 | + * Instructions for installing this plugin can be found here: |
| 5 | + * https://gravitywiz.com/gravity-forms-spam-notification/ |
18 | 6 | */ |
19 | | -class GW_Spam_Notification { |
20 | | - |
21 | | - private static $instance = null; |
22 | | - |
23 | | - public static function get_instance() { |
24 | | - if ( null == self::$instance ) { |
25 | | - self::$instance = new self; |
26 | | - } |
27 | | - return self::$instance; |
28 | | - } |
29 | | - |
30 | | - private function __construct() { |
31 | | - |
32 | | - add_filter( 'gform_notification_events', array( $this, 'add_spammed_notification_event' ) ); |
33 | | - add_filter( 'gform_before_resend_notifications', array( $this, 'add_notification_filter' ) ); |
34 | | - |
35 | | - add_action( 'gform_entry_created', array( $this, 'maybe_trigger_spammed_notification_event' ), 10, 2 ); |
36 | | - |
37 | | - } |
38 | | - |
39 | | - public function add_notification_filter( $form ) { |
40 | | - add_filter( 'gform_notification', array( $this, 'evaluate_notification_conditional_logic' ), 10, 3 ); |
41 | | - return $form; |
42 | | - } |
43 | | - |
44 | | - public function add_spammed_notification_event( $events ) { |
45 | | - $events['spammed'] = __( 'Entry marked as spam' ); |
46 | | - return $events; |
47 | | - } |
48 | | - |
49 | | - public function maybe_trigger_spammed_notification_event( $entry, $form ) { |
50 | | - if ( $entry['status'] === 'spam' ) { |
51 | | - GFAPI::send_notifications( $form, $entry, 'spammed' ); |
52 | | - } |
53 | | - } |
54 | | - |
55 | | - public function evaluate_notification_conditional_logic( $notification, $form, $entry ) { |
56 | | - |
57 | | - // if it fails conditional logic, suppress it |
58 | | - if ( $notification['event'] === 'spammed' && ! GFCommon::evaluate_conditional_logic( rgar( $notification, 'conditionalLogic' ), $form, $entry ) ) { |
59 | | - add_filter( 'gform_pre_send_email', array( $this, 'abort_next_notification' ) ); |
60 | | - } |
61 | | - |
62 | | - return $notification; |
63 | | - } |
64 | | - |
65 | | - public function abort_next_notification( $args ) { |
66 | | - remove_filter( 'gform_pre_send_email', array( $this, 'abort_next_notification' ) ); |
67 | | - $args['abort_email'] = true; |
68 | | - return $args; |
69 | | - } |
70 | | - |
71 | | -} |
72 | | - |
73 | | -function gw_spam_notification() { |
74 | | - return GW_Spam_Notification::get_instance(); |
75 | | -} |
76 | | - |
77 | | -gw_spam_notification(); |
0 commit comments