PluginProbe
OttoKit: All-in-One Automation Platform / 1.1.34
OttoKit: All-in-One Automation Platform v1.1.34
1.1.38 1.1.37 1.1.36 1.1.35 1.1.34 1.1.33 1.1.32 1.1.31 1.1.30 1.1.29 1.1.28 1.1.27 1.1.9 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 All 124 releases
suretriggers / src / Integrations / jetpack-crm / actions / delete-contact.php
delete-contact.php
109 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * DeleteContact.
4 * php version 5.6
5 *
6 * @category DeleteContact
7 * @package SureTriggers
8 * @author BSF <username@example.com>
9 * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
10 * @link https://www.brainstormforce.com/
11 * @since 1.0.0
12 */
13
14 namespace SureTriggers\Integrations\JetpackCRM\Actions;
15
16 use Exception;
17 use SureTriggers\Integrations\AutomateAction;
18 use SureTriggers\Traits\SingletonLoader;
19
20 /**
21 * DeleteContact
22 *
23 * @category DeleteContact
24 * @package SureTriggers
25 * @author BSF <username@example.com>
26 * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
27 * @link https://www.brainstormforce.com/
28 * @since 1.0.0
29 */
30 class DeleteContact extends AutomateAction {
31
32
33 /**
34 * Integration type.
35 *
36 * @var string
37 */
38 public $integration = 'JetpackCRM';
39
40 /**
41 * Action name.
42 *
43 * @var string
44 */
45 public $action = 'jetpack_crm_delete_contact';
46
47 use SingletonLoader;
48
49 /**
50 * Register an action.
51 *
52 * @param array $actions actions.
53 * @return array
54 */
55 public function register( $actions ) {
56
57 $actions[ $this->integration ][ $this->action ] = [
58 'label' => __( 'Delete Contact', 'suretriggers' ),
59 'action' => $this->action,
60 'function' => [ $this, 'action_listener' ],
61 ];
62 return $actions;
63 }
64
65 /**
66 * Action listener.
67 *
68 * @param int $user_id user_id.
69 * @param int $automation_id automation_id.
70 * @param array $fields fields.
71 * @param array $selected_options selected_options.
72 *
73 * @return array
74 *
75 * @throws Exception Exception.
76 */
77 public function _action_listener( $user_id, $automation_id, $fields, $selected_options ) {
78
79 if ( ! function_exists( 'zeroBS_deleteCustomer' ) ) {
80 return [
81 'status' => 'error',
82 'message' => 'Seems like Jetpack CRM plugin is not installed correctly.',
83 ];
84 }
85
86 $contact = sanitize_text_field( $selected_options['contact'] );
87
88 global $wpdb;
89 $contact_id = $wpdb->get_var( $wpdb->prepare( "SELECT `ID` FROM `{$wpdb->prefix}zbs_contacts` WHERE ID = %d OR zbsc_email LIKE %s", $contact, $contact ) );
90
91 if ( empty( $contact_id ) ) {
92 return [
93 'status' => 'error',
94 'message' => 'Contact not found with this ID or Email.',
95 ];
96 }
97
98 zeroBS_deleteCustomer( $contact_id, false );
99
100 $context = [];
101 $context['contact_id'] = $contact_id;
102
103 return $context;
104 }
105
106 }
107
108 DeleteContact::get_instance();
109