PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.3
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.3
6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 5.6.1 All 34 releases
← All changes | integrations/charitable/includes/triggers/anonymous-donation.php +172 -0 5.7.2 → 6.0.3 View file →
@@ -1,0 +1,172 @@
1 +<?php
2 +/**
3 + * Anonymous Donation
4 + *
5 + * @package AutomatorWP\Integrations\Charitable\Triggers\Anonymous_Donation
6 + * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]>
7 + * @since 1.0.0
8 + */
9 +// Exit if accessed directly
10 +if( !defined( 'ABSPATH' ) ) exit;
11 +
12 +class AutomatorWP_Charitable_Anonymous_Donation extends AutomatorWP_Integration_Trigger {
13 +
14 + public $integration = 'charitable';
15 + public $trigger = 'charitable_anonymous_donation';
16 +
17 + /**
18 + * Register the trigger
19 + *
20 + * @since 1.0.0
21 + */
22 + public function register() {
23 +
24 + automatorwp_register_trigger( $this->trigger, array(
25 + 'integration' => $this->integration,
26 + 'anonymous' => true,
27 + 'label' => __( 'Guest makes a donation', 'automatorwp' ),
28 + 'select_option' => __( 'Guest <strong>makes</strong> a donation', 'automatorwp' ),
29 + /* %1$s: Number of times. */
30 + 'edit_label' => sprintf( __( 'Guest makes a donation %1$s time(s)', 'automatorwp' ), '{times}' ),
31 + 'log_label' => __( 'Guest makes a donation', 'automatorwp' ),
32 + 'action' => 'charitable_donation_save',
33 + 'function' => array( $this, 'listener' ),
34 + 'priority' => 10,
35 + 'accepted_args' => 2,
36 + 'options' => array(
37 + 'times' => automatorwp_utilities_times_option(),
38 + ),
39 + 'tags' => array_merge(
40 + automatorwp_charitable_get_donation_tags(),
41 + automatorwp_utilities_times_tag()
42 + )
43 + ) );
44 +
45 + }
46 +
47 + /**
48 + * Trigger listener
49 + *
50 + * @since 1.0.0
51 + *
52 + * @param int $donation_id The donation ID.
53 + * @param WP_Post $post Instance of `WP_Post`.
54 + */
55 + public function listener( $donation_id, $post ) {
56 +
57 + $donation = charitable_get_donation( $donation_id );
58 +
59 + $donor = $donation->get_donor_data();
60 +
61 + $user = get_user_by( 'email', $donor['email'] );
62 +
63 + // Bail if no user
64 + if ( !empty( $user ) ) {
65 + return;
66 + }
67 +
68 + // Get campaigns.
69 + $campaigns = $donation->get_campaign_donations();
70 +
71 + // Bail no campaigns.
72 + if ( empty( $campaigns ) ) {
73 + return;
74 + }
75 +
76 + foreach ( $campaigns as $campaign ) {
77 + $campaign_id = $campaign->campaign_id;
78 + }
79 +
80 + $campaign = charitable_get_campaign( $campaign_id );
81 +
82 + // Bail if not approved status
83 + if ( ! charitable_is_approved_status( get_post_status( $donation_id ) ) ) {
84 + return false;
85 + }
86 +
87 + $old_status = ! empty( $_POST['original_post_status'] ) ? $_POST['original_post_status'] : '';
88 +
89 + // Bail if same status
90 + if ( $old_status === $post->post_status ) {
91 + return;
92 + }
93 +
94 + // Trigger the become an affiliate
95 + automatorwp_trigger_event( array(
96 + 'trigger' => $this->trigger,
97 + 'donation_id' => $donation_id,
98 + 'donation_title' => get_the_title( $donation_id ),
99 + 'donation_amount' => $donation->get_amount_formatted(),
100 + 'donation_status' => $donation->get_status_label(),
101 + 'donation_payment_method' => $donation->get_gateway_label(),
102 + 'donor_id' => $user_id,
103 + 'donor_first_name' => $donor['first_name'],
104 + 'donor_last_name' => $donor['last_name'],
105 + 'donor_country' => $donor['country'],
106 + 'donor_phone' => $donor['phone'],
107 + 'campaign_id' => $campaign_id,
108 + 'campaign_title' => $campaign->post_title,
109 + 'campaign_goal' => charitable_format_money( $campaign->get_goal() ),
110 + 'campaign_min_donation' => charitable_format_money( charitable_get_minimum_donation_amount( $campaign_id ) ),
111 + 'campaign_end_date' => $campaign->get_end_date(),
112 +
113 + ) );
114 +
115 + }
116 +
117 + /**
118 + * Register the required hooks
119 + *
120 + * @since 1.0.0
121 + */
122 + public function hooks() {
123 +
124 + // Log meta data
125 + add_filter( 'automatorwp_anonymous_completed_trigger_log_meta', array( $this, 'log_meta' ), 10, 5 );
126 +
127 + parent::hooks();
128 + }
129 +
130 + /**
131 + * Trigger custom log meta
132 + *
133 + * @since 1.0.0
134 + *
135 + * @param array $log_meta Log meta data
136 + * @param stdClass $trigger The trigger object
137 + * @param array $event Event information
138 + * @param array $trigger_options The trigger's stored options
139 + * @param stdClass $automation The trigger's automation object
140 + *
141 + * @return array
142 + */
143 + function log_meta( $log_meta, $trigger, $event, $trigger_options, $automation ) {
144 +
145 + // Bail if action type don't match this action
146 + if( $trigger->type !== $this->trigger ) {
147 + return $log_meta;
148 + }
149 +
150 + $log_meta['donation_id'] = ( isset( $event['donation_id'] ) ? $event['donation_id'] : '' );
151 + $log_meta['donation_title'] = ( isset( $event['donation_title'] ) ? $event['donation_title'] : '' );
152 + $log_meta['donation_amount'] = ( isset( $event['donation_amount'] ) ? $event['donation_amount'] : 0.00 );
153 + $log_meta['donation_status'] = ( isset( $event['donation_status'] ) ? $event['donation_status'] : '' );
154 + $log_meta['donation_payment_method'] = ( isset( $event['donation_payment_method'] ) ? $event['donation_payment_method'] : '' );
155 + $log_meta['donor_id'] = ( isset( $event['donor_id'] ) ? $event['donor_id'] : '' );
156 + $log_meta['donor_first_name'] = ( isset( $event['donor_first_name'] ) ? $event['donor_first_name'] : '' );
157 + $log_meta['donor_last_name'] = ( isset( $event['donor_last_name'] ) ? $event['donor_last_name'] : '' );
158 + $log_meta['donor_country'] = ( isset( $event['donor_country'] ) ? $event['donor_country'] : '' );
159 + $log_meta['donor_phone'] = ( isset( $event['donor_phone'] ) ? $event['donor_phone'] : '' );
160 + $log_meta['campaign_id'] = ( isset( $event['campaign_id'] ) ? $event['campaign_id'] : '' );
161 + $log_meta['campaign_title'] = ( isset( $event['campaign_title'] ) ? $event['campaign_title'] : '' );
162 + $log_meta['campaign_goal'] = ( isset( $event['campaign_goal'] ) ? $event['campaign_goal'] : '' );
163 + $log_meta['campaign_min_donation'] = ( isset( $event['campaign_min_donation'] ) ? $event['campaign_min_donation'] : '' );
164 + $log_meta['campaign_end_date'] = ( isset( $event['campaign_end_date'] ) ? $event['campaign_end_date'] : '' );
165 +
166 + return $log_meta;
167 +
168 + }
169 +
170 +}
171 +
172 +new AutomatorWP_Charitable_Anonymous_Donation();