PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 8.8.3
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v8.8.3
8.8.3 8.8.2 8.8.1 8.8.0 8.7.9 8.7.8 8.7.7 8.7.6 8.7.5 8.7.4 8.7.3 8.7.2 8.7.1 8.7.0 8.6.9 8.6.8 8.6.7 8.6.6 8.6.5 8.6.4 8.6.2 8.6.1 8.6.0 8.5.9 8.5.8 All 539 releases
← All changes | addons/automator/includes/actions/fluentcrm-actions.php +118 -118 8.7.9 → 8.8.3 View file →
@@ -1,118 +1,118 @@
1 -<?php
2 -/**
3 - * FluentCRM Actions
4 - *
5 - * @package WPbot_Automator
6 - */
7 -
8 -namespace WPbot_Automator\Actions;
9 -
10 -if ( ! defined( 'ABSPATH' ) ) {
11 - exit;
12 -}
13 -
14 -/**
15 - * Class FluentCRM_Actions
16 - */
17 -class FluentCRM_Actions extends Action {
18 -
19 - /**
20 - * Constructor
21 - */
22 - public function __construct() {
23 - $this->id = 'fluentcrm';
24 - $this->group = __( 'FluentCRM', 'wpbot-automator' );
25 - }
26 -
27 - /**
28 - * Execute the action
29 - *
30 - * @param array $action_data Configuration for this action from the workflow.
31 - * @param array $trigger_data Data passed from the trigger.
32 - * @return bool|array
33 - */
34 - public function execute( $action_data, $trigger_data ) {
35 - $action_id = isset( $action_data['actionId'] ) ? $action_data['actionId'] : '';
36 -
37 - if ( empty( $action_id ) ) {
38 - return false;
39 - }
40 -
41 - switch ( $action_id ) {
42 - case 'create_contact':
43 - return $this->create_contact( $action_data, $trigger_data );
44 - default:
45 - return false;
46 - }
47 - }
48 -
49 - /**
50 - * Create or Update Contact in FluentCRM
51 - */
52 - private function create_contact( $action_data, $trigger_data ) {
53 - if ( ! function_exists( 'FluentCrmApi' ) ) {
54 - return array(
55 - 'success' => false,
56 - 'message' => 'FluentCRM plugin is not active.',
57 - );
58 - }
59 -
60 - $cfg = isset( $action_data['config'] ) ? $action_data['config'] : array();
61 - $email = trim( $this->parse_tokens( $cfg['email'] ?? '', $trigger_data ) );
62 -
63 - if ( empty( $email ) ) {
64 - //error_log( 'WPbot Automator - FluentCRM: Email is empty after parsing tokens.' );
65 - return array(
66 - 'success' => false,
67 - 'message' => 'Email address is required for FluentCRM contact creation.',
68 - );
69 - }
70 -
71 - if ( ! is_email( $email ) ) {
72 - //error_log( 'WPbot Automator - FluentCRM: Invalid email address: ' . $email );
73 - return array(
74 - 'success' => false,
75 - 'message' => 'Invalid email address provided for FluentCRM.',
76 - );
77 - }
78 -
79 - $contact_data = array(
80 - 'email' => $email,
81 - 'first_name' => $this->parse_tokens( $cfg['first_name'] ?? '', $trigger_data ),
82 - 'last_name' => $this->parse_tokens( $cfg['last_name'] ?? '', $trigger_data ),
83 - 'status' => $cfg['status'] ?? 'subscribed',
84 - );
85 -
86 - //error_log( 'WPbot Automator - FluentCRM Contact Data: ' . wp_json_encode( $contact_data ) );
87 -
88 - try {
89 - $api = FluentCrmApi( 'contacts' );
90 - //error_log( 'WPbot Automator - FluentCRM API object type: ' . gettype( $api ) );
91 - if ( is_object( $api ) ) {
92 - //error_log( 'WPbot Automator - FluentCRM API class: ' . get_class( $api ) );
93 - }
94 -
95 - $contact = $api->createOrUpdate( $contact_data );
96 - //error_log( 'WPbot Automator - FluentCRM createOrUpdate result: ' . ( is_object( $contact ) ? 'OBJECT (ID: ' . $contact->id . ')' : ( $contact ? 'TRUE/POS' : 'FALSE/NEG' ) ) );
97 -
98 - if ( $contact ) {
99 - return array(
100 - 'success' => true,
101 - 'message' => sprintf( 'Contact %s successfully created/updated in FluentCRM.', $email ),
102 - 'fluentcrm_contact_id' => isset( $contact->id ) ? $contact->id : 0,
103 - );
104 - }
105 - } catch ( \Exception $e ) {
106 - //error_log( 'WPbot Automator - FluentCRM Exception: ' . $e->getMessage() );
107 - return array(
108 - 'success' => false,
109 - 'message' => 'FluentCRM Error: ' . $e->getMessage(),
110 - );
111 - }
112 -
113 - return array(
114 - 'success' => false,
115 - 'message' => 'Failed to create contact in FluentCRM.',
116 - );
117 - }
118 -}
1 +<?php
2 +/**
3 + * FluentCRM Actions
4 + *
5 + * @package WPbot_Automator
6 + */
7 +
8 +namespace WPbot_Automator\Actions;
9 +
10 +if ( ! defined( 'ABSPATH' ) ) {
11 + exit;
12 +}
13 +
14 +/**
15 + * Class FluentCRM_Actions
16 + */
17 +class FluentCRM_Actions extends Action {
18 +
19 + /**
20 + * Constructor
21 + */
22 + public function __construct() {
23 + $this->id = 'fluentcrm';
24 + $this->group = __( 'FluentCRM', 'wpbot-automator' );
25 + }
26 +
27 + /**
28 + * Execute the action
29 + *
30 + * @param array $action_data Configuration for this action from the workflow.
31 + * @param array $trigger_data Data passed from the trigger.
32 + * @return bool|array
33 + */
34 + public function execute( $action_data, $trigger_data ) {
35 + $action_id = isset( $action_data['actionId'] ) ? $action_data['actionId'] : '';
36 +
37 + if ( empty( $action_id ) ) {
38 + return false;
39 + }
40 +
41 + switch ( $action_id ) {
42 + case 'create_contact':
43 + return $this->create_contact( $action_data, $trigger_data );
44 + default:
45 + return false;
46 + }
47 + }
48 +
49 + /**
50 + * Create or Update Contact in FluentCRM
51 + */
52 + private function create_contact( $action_data, $trigger_data ) {
53 + if ( ! function_exists( 'FluentCrmApi' ) ) {
54 + return array(
55 + 'success' => false,
56 + 'message' => 'FluentCRM plugin is not active.',
57 + );
58 + }
59 +
60 + $cfg = isset( $action_data['config'] ) ? $action_data['config'] : array();
61 + $email = trim( $this->parse_tokens( $cfg['email'] ?? '', $trigger_data ) );
62 +
63 + if ( empty( $email ) ) {
64 + //error_log( 'WPbot Automator - FluentCRM: Email is empty after parsing tokens.' );
65 + return array(
66 + 'success' => false,
67 + 'message' => 'Email address is required for FluentCRM contact creation.',
68 + );
69 + }
70 +
71 + if ( ! is_email( $email ) ) {
72 + //error_log( 'WPbot Automator - FluentCRM: Invalid email address: ' . $email );
73 + return array(
74 + 'success' => false,
75 + 'message' => 'Invalid email address provided for FluentCRM.',
76 + );
77 + }
78 +
79 + $contact_data = array(
80 + 'email' => $email,
81 + 'first_name' => $this->parse_tokens( $cfg['first_name'] ?? '', $trigger_data ),
82 + 'last_name' => $this->parse_tokens( $cfg['last_name'] ?? '', $trigger_data ),
83 + 'status' => $cfg['status'] ?? 'subscribed',
84 + );
85 +
86 + //error_log( 'WPbot Automator - FluentCRM Contact Data: ' . wp_json_encode( $contact_data ) );
87 +
88 + try {
89 + $api = FluentCrmApi( 'contacts' );
90 + //error_log( 'WPbot Automator - FluentCRM API object type: ' . gettype( $api ) );
91 + if ( is_object( $api ) ) {
92 + //error_log( 'WPbot Automator - FluentCRM API class: ' . get_class( $api ) );
93 + }
94 +
95 + $contact = $api->createOrUpdate( $contact_data );
96 + //error_log( 'WPbot Automator - FluentCRM createOrUpdate result: ' . ( is_object( $contact ) ? 'OBJECT (ID: ' . $contact->id . ')' : ( $contact ? 'TRUE/POS' : 'FALSE/NEG' ) ) );
97 +
98 + if ( $contact ) {
99 + return array(
100 + 'success' => true,
101 + 'message' => sprintf( 'Contact %s successfully created/updated in FluentCRM.', $email ),
102 + 'fluentcrm_contact_id' => isset( $contact->id ) ? $contact->id : 0,
103 + );
104 + }
105 + } catch ( \Exception $e ) {
106 + //error_log( 'WPbot Automator - FluentCRM Exception: ' . $e->getMessage() );
107 + return array(
108 + 'success' => false,
109 + 'message' => 'FluentCRM Error: ' . $e->getMessage(),
110 + );
111 + }
112 +
113 + return array(
114 + 'success' => false,
115 + 'message' => 'Failed to create contact in FluentCRM.',
116 + );
117 + }
118 +}