add-tag-to-company.php
10 months ago
add-tag-to-contact.php
10 months ago
change-status-of-contact.php
10 months ago
create-company.php
6 months ago
create-contact.php
10 months ago
delete-contact.php
10 months ago
delete-contact.php
109 lines
| 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 |