PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.4
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.4
6.0.4 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 All 35 releases
← All changes | integrations/mail-mint/includes/triggers/user-contact-added.php +123 -0 5.8.4 → 6.0.4 View file →
@@ -1,0 +1,123 @@
1 +<?php
2 +/**
3 + * User Contact Added
4 + *
5 + * @package AutomatorWP\Integrations\Mail_Mint\Triggers\User_Contact_Added
6 + * @author AutomatorWP <[email protected]>
7 + * @since 1.0.0
8 + */
9 +
10 +// Exit if accessed directly
11 +if ( ! defined( 'ABSPATH' ) ) exit;
12 +
13 +class AutomatorWP_Mail_Mint_User_Contact_Added extends AutomatorWP_Integration_Trigger
14 +{
15 + public $integration = 'mail_mint';
16 + public $trigger = 'mail_mint_user_contact_added';
17 +
18 + /**
19 + * Register the trigger
20 + *
21 + * @since 1.0.0
22 + */
23 + public function register()
24 + {
25 + automatorwp_register_trigger( $this->trigger, array(
26 + 'integration' => $this->integration,
27 + 'label' => __( 'User added to contacts', 'automatorwp' ),
28 + 'select_option' => __( 'User added to <strong>contacts</strong>', 'automatorwp' ),
29 + /* translators: %1$s: Number of times. */
30 + 'edit_label' => sprintf( __( 'User added to contacts %1$s time(s)', 'automatorwp' ), '{times}' ),
31 + 'log_label' => __( 'User added to contacts', 'automatorwp' ),
32 + 'action' => 'mailmint_contacts_saved',
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_mail_mint_contact_tags(),
41 + automatorwp_utilities_times_tag()
42 + ),
43 + ) );
44 + }
45 +
46 + /**
47 + * Trigger listener
48 + *
49 + * @since 1.0.0
50 + *
51 + * @param int $contact_id Contact ID.
52 + * @param array $params Saved data.
53 + */
54 + public function listener( $contact_id, $params ) {
55 +
56 + if( ! class_exists ( 'Mint\MRM\DataBase\Models\ContactModel' ) )
57 + return;
58 +
59 + // Get contact email
60 + $contact_email = Mint\MRM\DataBase\Models\ContactModel::get_email_by_id( $contact_id );
61 +
62 + // Bail if not contact email
63 + if ( ! $contact_email )
64 + return;
65 +
66 + $user = get_user_by( 'email', $contact_email['email'] );
67 +
68 + // Make sure contact has an user ID assigned
69 + if ( $user->ID === 0 ) {
70 + return;
71 + }
72 +
73 + // Trigger the user added to contacts
74 + automatorwp_trigger_event( array(
75 + 'trigger' => $this->trigger,
76 + 'user_id' => $user->ID,
77 + 'contact_id' => $contact_id,
78 + ) );
79 +
80 + }
81 +
82 + /**
83 + * Register the required hooks
84 + *
85 + * @since 1.0.0
86 + */
87 + public function hooks() {
88 +
89 + // Log meta data
90 + add_filter( 'automatorwp_user_completed_trigger_log_meta', array( $this, 'log_meta' ), 10, 6 );
91 +
92 + parent::hooks();
93 + }
94 +
95 + /**
96 + * Trigger custom log meta
97 + *
98 + * @since 1.0.0
99 + *
100 + * @param array $log_meta Log meta data
101 + * @param stdClass $trigger The trigger object
102 + * @param int $user_id The user ID
103 + * @param array $event Event information
104 + * @param array $trigger_options The trigger's stored options
105 + * @param stdClass $automation The trigger's automation object
106 + *
107 + * @return array
108 + */
109 + function log_meta( $log_meta, $trigger, $user_id, $event, $trigger_options, $automation ) {
110 +
111 + // Bail if action type don't match this action
112 + if( $trigger->type !== $this->trigger ) {
113 + return $log_meta;
114 + }
115 +
116 + $log_meta['contact_id'] = ( isset( $event['contact_id'] ) ? $event['contact_id'] : '' );
117 +
118 + return $log_meta;
119 +
120 + }
121 +}
122 +
123 +new AutomatorWP_Mail_Mint_User_Contact_Added();