From 1e0b024d1c9a8d7ec89e1a7bfbf9b8913cf7d722 Mon Sep 17 00:00:00 2001
From: David Perez
Date: Sat, 28 Mar 2026 22:29:55 +0100
Subject: [PATCH] =?UTF-8?q?Revert=20"Opciones=20de=20actualizaci=C3=B3n=20?=
=?UTF-8?q?de=20contacto"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../crm-library/class-crmlib-clientify.php | 94 +------
.../formscrm-library/class-contactform7.php | 9 -
includes/formscrm-library/class-elementor.php | 17 --
.../formscrm-library/class-gravityforms.php | 17 --
.../formscrm-library/class-woocommerce.php | 12 -
includes/formscrm-library/class-wpforms.php | 28 +-
.../formscrm-library/helpers-library-crm.php | 28 --
tests/API/test-clientify.php | 254 ------------------
tests/bootstrap.php | 5 -
9 files changed, 9 insertions(+), 455 deletions(-)
diff --git a/includes/crm-library/class-crmlib-clientify.php b/includes/crm-library/class-crmlib-clientify.php
index e9cccad..09a826e 100644
--- a/includes/crm-library/class-crmlib-clientify.php
+++ b/includes/crm-library/class-crmlib-clientify.php
@@ -700,80 +700,6 @@ public function list_fields( $settings, $module = 'Contacts' ) {
return $fields;
}
- /**
- * Searches for an existing contact or company by a given field.
- *
- * @param string $module CRM module: 'contacts' or 'companies'.
- * @param string $update_by Strategy key: 'email', 'phone', or 'tax_id'.
- * @param string $value Value to search for.
- * @param string $apikey API authentication token.
- * @return int|false CRM record ID if found, false otherwise.
- */
- private function search_contact( $module, $update_by, $value, $apikey ) {
- if ( empty( $value ) ) {
- return false;
- }
-
- $field_map = array(
- 'email' => 'email',
- 'phone' => 'phone',
- 'tax_id' => 'taxpayer_identification_number',
- );
-
- if ( ! isset( $field_map[ $update_by ] ) ) {
- return false;
- }
-
- $result = $this->request(
- $module . '/',
- array(
- $field_map[ $update_by ] => $value,
- 'fields' => 'id',
- ),
- $apikey,
- 'GET'
- );
-
- if ( 'ok' !== $result['status'] ) {
- return false;
- }
-
- $results = isset( $result['data']['results'] ) ? $result['data']['results'] : array();
- if ( ! empty( $results[0]['id'] ) ) {
- return (int) $results[0]['id'];
- }
-
- return false;
- }
-
- /**
- * Extracts the search value from merge_vars for the given update-by strategy.
- *
- * @param array $merge_vars Array of mapped form field values.
- * @param string $update_by Strategy key: 'email', 'phone', or 'tax_id'.
- * @return string The value to search by, or empty string if not found.
- */
- private function extract_update_by_value( $merge_vars, $update_by ) {
- $field_map = array(
- 'email' => 'email',
- 'phone' => 'phone',
- 'tax_id' => 'taxpayer_identification_number',
- );
-
- if ( ! isset( $field_map[ $update_by ] ) ) {
- return '';
- }
-
- $target = $field_map[ $update_by ];
- foreach ( $merge_vars as $element ) {
- if ( isset( $element['name'] ) && $target === $element['name'] && ! empty( $element['value'] ) ) {
- return (string) $element['value'];
- }
- }
-
- return '';
- }
-
/**
* Creates an entry for given module of a CRM
*
@@ -887,25 +813,9 @@ public function create_entry( $settings, $merge_vars ) {
$contact['tags'] = array_values( array_filter( $contact_tags ) );
}
- $update_by = isset( $settings['fc_crm_update_by'] ) ? $settings['fc_crm_update_by'] : 'none';
- $http_method = 'POST';
- $endpoint = $module . '/';
- $found_id = false;
-
- if ( 'none' !== $update_by ) {
- $search_value = $this->extract_update_by_value( $merge_vars, $update_by );
- if ( ! empty( $search_value ) ) {
- $found_id = $this->search_contact( $module, $update_by, $search_value, $apikey );
- if ( $found_id ) {
- $http_method = 'PATCH';
- $endpoint = $module . '/' . $found_id . '/';
- }
- }
- }
-
- $result = $this->request( $endpoint, $contact, $apikey, $http_method );
+ $result = $this->request( $module . '/', $contact, $apikey );
if ( 'ok' === $result['status'] ) {
- $contact_id = isset( $result['data']['id'] ) ? $result['data']['id'] : ( $found_id ? $found_id : '' );
+ $contact_id = isset( $result['data']['id'] ) ? $result['data']['id'] : '';
$response_result = array(
'status' => 'ok',
'message' => 'success',
diff --git a/includes/formscrm-library/class-contactform7.php b/includes/formscrm-library/class-contactform7.php
index a36c46f..eb22bfe 100644
--- a/includes/formscrm-library/class-contactform7.php
+++ b/includes/formscrm-library/class-contactform7.php
@@ -164,15 +164,6 @@ public function settings_add_crm( $args ) {
-
-
-
-
-
/>
diff --git a/includes/formscrm-library/class-elementor.php b/includes/formscrm-library/class-elementor.php
index b2d38c5..4eb2b0c 100644
--- a/includes/formscrm-library/class-elementor.php
+++ b/includes/formscrm-library/class-elementor.php
@@ -171,23 +171,6 @@ public function register_settings_section( $widget ) {
)
);
- // Contact Update Strategy.
- $update_by_options = array();
- foreach ( formscrm_get_update_by_choices() as $choice ) {
- $update_by_options[ $choice['value'] ] = $choice['label'];
- }
- $widget->add_control(
- 'fc_crm_update_by',
- array(
- 'label' => __( 'Contact Update Strategy', 'formscrm' ),
- 'type' => \Elementor\Controls_Manager::SELECT,
- 'label_block' => true,
- 'description' => __( 'Search for an existing contact before creating. If found, it will be updated instead.', 'formscrm' ),
- 'options' => $update_by_options,
- 'default' => 'none',
- )
- );
-
// Expert Mode.
$widget->add_control(
'fc_crm_mode_expert',
diff --git a/includes/formscrm-library/class-gravityforms.php b/includes/formscrm-library/class-gravityforms.php
index c1460b6..1b57a74 100644
--- a/includes/formscrm-library/class-gravityforms.php
+++ b/includes/formscrm-library/class-gravityforms.php
@@ -576,23 +576,6 @@ private function get_crm_feed_fields( $settings ) {
);
}
- $update_by_choices = array();
- foreach ( formscrm_get_update_by_choices() as $choice ) {
- $update_by_choices[] = array(
- 'label' => $choice['label'],
- 'value' => $choice['value'],
- );
- }
- $crm_feed_fields[] = array(
- 'name' => 'fc_crm_update_by',
- 'label' => __( 'Contact Update Strategy', 'formscrm' ),
- 'type' => 'select',
- 'class' => 'medium',
- 'dependency' => 'fc_crm_module',
- 'tooltip' => '
' . __( 'Contact Update Strategy', 'formscrm' ) . '
' . __( 'Choose whether to search for an existing contact before creating a new one. If a match is found, the record will be updated instead.', 'formscrm' ),
- 'choices' => $update_by_choices,
- );
-
$crm_feed_fields[] = array(
'name' => 'listFields',
'label' => __( 'Map Fields', 'formscrm' ),
diff --git a/includes/formscrm-library/class-woocommerce.php b/includes/formscrm-library/class-woocommerce.php
index f95b8dd..68cd81b 100644
--- a/includes/formscrm-library/class-woocommerce.php
+++ b/includes/formscrm-library/class-woocommerce.php
@@ -189,18 +189,6 @@ public function get_settings() {
);
}
- $options_update_by = array();
- foreach ( formscrm_get_update_by_choices() as $choice ) {
- $options_update_by[ $choice['value'] ] = $choice['label'];
- }
- $settings_crm[] = array(
- 'name' => __( 'Contact Update Strategy', 'formscrm' ),
- 'type' => 'select',
- 'desc' => __( 'Search for an existing contact before creating. If found, it will be updated instead.', 'formscrm' ),
- 'options' => $options_update_by,
- 'id' => 'wc_formscrm[fc_crm_update_by]',
- );
-
$settings_crm[] = array(
'type' => 'sectionend',
'id' => 'wc_settings_formscrm_section_end',
diff --git a/includes/formscrm-library/class-wpforms.php b/includes/formscrm-library/class-wpforms.php
index 418b28a..1f2b241 100644
--- a/includes/formscrm-library/class-wpforms.php
+++ b/includes/formscrm-library/class-wpforms.php
@@ -68,14 +68,13 @@ public function process_entry( $fields, $entry, $form_data, $entry_id = 0 ) {
// Fire for each connection.
foreach ( $form_data['providers'][ $this->slug ] as $connection ) {
- $account_id = $connection['account_id'];
- $settings = $this->api_connect( $account_id );
- $settings['fc_crm_module'] = $connection['list_id'];
- $settings['fc_crm_update_by'] = isset( $connection['fc_crm_update_by'] ) ? $connection['fc_crm_update_by'] : 'none';
- $merge_vars = array();
- $entry_meta = wpforms()->get( 'entry_meta' );
- $form_id = (int) $form_data['id'];
- $title = 'FormsCRM Log
';
+ $account_id = $connection['account_id'];
+ $settings = $this->api_connect( $account_id );
+ $settings['fc_crm_module'] = $connection['list_id'];
+ $merge_vars = array();
+ $entry_meta = wpforms()->get( 'entry_meta' );
+ $form_id = (int) $form_data['id'];
+ $title = 'FormsCRM Log
';
// Check for credentials.
if ( empty( $settings['fc_crm_type'] ) ) {
@@ -545,19 +544,6 @@ public function output_options( $connection_id = '', $connection = array() ) {
$html .= '';
$html .= '';
-
- // Contact Update Strategy select.
- $saved_update_by = isset( $connection['fc_crm_update_by'] ) ? $connection['fc_crm_update_by'] : 'none';
- $html .= '';
- $html .= '
';
- $html .= '
';
- $html .= '
' . esc_html__( 'Search for an existing contact before creating. If found, it will be updated instead.', 'formscrm' ) . '
';
- $html .= '
';
}
}
diff --git a/includes/formscrm-library/helpers-library-crm.php b/includes/formscrm-library/helpers-library-crm.php
index a10de5c..866910a 100644
--- a/includes/formscrm-library/helpers-library-crm.php
+++ b/includes/formscrm-library/helpers-library-crm.php
@@ -170,34 +170,6 @@ function formscrm_get_dependency_odoodb() {
}
}
-if ( ! function_exists( 'formscrm_get_update_by_choices' ) ) {
- /**
- * Returns the choices for the update-by contact strategy setting.
- *
- * @return array
- */
- function formscrm_get_update_by_choices() {
- return array(
- array(
- 'value' => 'none',
- 'label' => __( 'Always create new', 'formscrm' ),
- ),
- array(
- 'value' => 'email',
- 'label' => __( 'Update by Email', 'formscrm' ),
- ),
- array(
- 'value' => 'phone',
- 'label' => __( 'Update by Phone', 'formscrm' ),
- ),
- array(
- 'value' => 'tax_id',
- 'label' => __( 'Update by Tax ID', 'formscrm' ),
- ),
- );
- }
-}
-
// Visitor Key.
add_action( 'init', 'formscrm_visitorkey_session', 1 );
if ( ! function_exists( 'formscrm_visitorkey_session' ) ) {
diff --git a/tests/API/test-clientify.php b/tests/API/test-clientify.php
index 365c56e..d0b3f44 100644
--- a/tests/API/test-clientify.php
+++ b/tests/API/test-clientify.php
@@ -64,115 +64,6 @@ public function mock_http_requests( $pre, $r, $url ) {
$response_file = 'clientify-custom-fields.json';
}
- // V2 contact search by email: existing contact.
- if ( str_contains( $url, '/v2/contacts/' ) && 'GET' === $r['method'] && str_contains( $url, 'email=existing' ) ) {
- return array(
- 'body' => wp_json_encode(
- array(
- 'count' => 1,
- 'next' => null,
- 'results' => array(
- array( 'id' => 99999 ),
- ),
- )
- ),
- 'response' => array(
- 'code' => 200,
- 'message' => 'OK',
- ),
- );
- }
-
- // V2 contact/company search by tax_id: existing record.
- if ( str_contains( $url, '/v2/contacts/' ) && 'GET' === $r['method'] && str_contains( $url, 'taxpayer_identification_number' ) ) {
- return array(
- 'body' => wp_json_encode(
- array(
- 'count' => 1,
- 'next' => null,
- 'results' => array(
- array( 'id' => 99999 ),
- ),
- )
- ),
- 'response' => array(
- 'code' => 200,
- 'message' => 'OK',
- ),
- );
- }
-
- // V2 company search by email: existing company.
- if ( str_contains( $url, '/v2/companies/' ) && 'GET' === $r['method'] && str_contains( $url, 'email=existing' ) ) {
- return array(
- 'body' => wp_json_encode(
- array(
- 'count' => 1,
- 'next' => null,
- 'results' => array(
- array( 'id' => 88888 ),
- ),
- )
- ),
- 'response' => array(
- 'code' => 200,
- 'message' => 'OK',
- ),
- );
- }
-
- // V2 contact/company search: no match.
- if ( ( str_contains( $url, '/v2/contacts/' ) || str_contains( $url, '/v2/companies/' ) ) && 'GET' === $r['method'] ) {
- return array(
- 'body' => wp_json_encode(
- array(
- 'count' => 0,
- 'next' => null,
- 'results' => array(),
- )
- ),
- 'response' => array(
- 'code' => 200,
- 'message' => 'OK',
- ),
- );
- }
-
- // V2 contact update via PATCH.
- if ( str_contains( $url, '/v2/contacts/' ) && 'PATCH' === $r['method'] ) {
- return array(
- 'body' => wp_json_encode(
- array(
- 'id' => 99999,
- 'first_name' => 'Test',
- 'last_name' => 'User',
- 'email' => 'existing@example.com',
- )
- ),
- 'response' => array(
- 'code' => 200,
- 'message' => 'OK',
- ),
- );
- }
-
- // V2 company update via PATCH.
- if ( str_contains( $url, '/v2/companies/' ) && 'PATCH' === $r['method'] ) {
- return array(
- 'body' => wp_json_encode(
- array(
- 'id' => 88888,
- 'name' => 'Existing Company',
- 'email' => 'existing@company.com',
- )
- ),
- 'response' => array(
- 'code' => 200,
- 'message' => 'OK',
- ),
- );
- }
-
// V2 contact creation.
if ( str_contains( $url, '/v2/contacts/' ) && 'POST' === $r['method'] ) {
return array(
@@ -192,22 +83,6 @@ public function mock_http_requests( $pre, $r, $url ) {
);
}
- // V2 company creation.
- if ( str_contains( $url, '/v2/companies/' ) && 'POST' === $r['method'] ) {
- return array(
- 'body' => wp_json_encode(
- array(
- 'id' => 200001,
- 'name' => 'New Company',
- )
- ),
- 'response' => array(
- 'code' => 201,
- 'message' => 'Created',
- ),
- );
- }
-
// V2 deal creation.
if ( str_contains( $url, '/v2/deals/' ) && 'POST' === $r['method'] ) {
return array(
@@ -386,133 +261,4 @@ public function test_create_entry_contact_deal() {
$this->assertEquals( 'ok', $result['status'] );
$this->assertEquals( 'deal', $result['module'] );
}
-
- /**
- * Test update_by = 'none': always creates new contact via POST.
- */
- public function test_create_entry_update_by_none_always_creates() {
- $this->settings['fc_crm_update_by'] = 'none';
-
- $merge_vars = array(
- array(
- 'name' => 'first_name',
- 'value' => 'Test',
- ),
- array(
- 'name' => 'email',
- 'value' => 'test@example.com',
- ),
- );
-
- $result = $this->crm_clientify->create_entry( $this->settings, $merge_vars );
- $this->assertEquals( 'ok', $result['status'] );
- $this->assertEquals( 100597402, $result['id'] );
- }
-
- /**
- * Test update_by = 'email': updates existing contact via PATCH when match found.
- */
- public function test_create_entry_update_by_email_found() {
- $this->settings['fc_crm_update_by'] = 'email';
-
- $merge_vars = array(
- array(
- 'name' => 'first_name',
- 'value' => 'Test',
- ),
- array(
- 'name' => 'email',
- 'value' => 'existing@example.com',
- ),
- );
-
- $result = $this->crm_clientify->create_entry( $this->settings, $merge_vars );
- $this->assertEquals( 'ok', $result['status'] );
- $this->assertEquals( 99999, $result['id'] );
- }
-
- /**
- * Test update_by = 'email': creates new contact via POST when no match found.
- */
- public function test_create_entry_update_by_email_not_found() {
- $this->settings['fc_crm_update_by'] = 'email';
-
- $merge_vars = array(
- array(
- 'name' => 'first_name',
- 'value' => 'New',
- ),
- array(
- 'name' => 'email',
- 'value' => 'new@example.com',
- ),
- );
-
- $result = $this->crm_clientify->create_entry( $this->settings, $merge_vars );
- $this->assertEquals( 'ok', $result['status'] );
- $this->assertEquals( 100597402, $result['id'] );
- }
-
- /**
- * Test update_by = 'email': creates new contact when email field is missing.
- */
- public function test_create_entry_update_by_email_empty_value() {
- $this->settings['fc_crm_update_by'] = 'email';
-
- $merge_vars = array(
- array(
- 'name' => 'first_name',
- 'value' => 'Test',
- ),
- );
-
- $result = $this->crm_clientify->create_entry( $this->settings, $merge_vars );
- $this->assertEquals( 'ok', $result['status'] );
- $this->assertEquals( 100597402, $result['id'] );
- }
-
- /**
- * Test update_by = 'tax_id': updates existing contact via PATCH when match found.
- */
- public function test_create_entry_update_by_tax_id_found() {
- $this->settings['fc_crm_update_by'] = 'tax_id';
-
- $merge_vars = array(
- array(
- 'name' => 'first_name',
- 'value' => 'Test',
- ),
- array(
- 'name' => 'taxpayer_identification_number',
- 'value' => '12345678A',
- ),
- );
-
- $result = $this->crm_clientify->create_entry( $this->settings, $merge_vars );
- $this->assertEquals( 'ok', $result['status'] );
- $this->assertEquals( 99999, $result['id'] );
- }
-
- /**
- * Test update_by = 'email' on companies module: updates existing company via PATCH.
- */
- public function test_create_entry_update_by_email_companies_found() {
- $this->settings['fc_crm_module'] = 'Companies';
- $this->settings['fc_crm_update_by'] = 'email';
-
- $merge_vars = array(
- array(
- 'name' => 'name',
- 'value' => 'Existing Company',
- ),
- array(
- 'name' => 'email',
- 'value' => 'existing@company.com',
- ),
- );
-
- $result = $this->crm_clientify->create_entry( $this->settings, $merge_vars );
- $this->assertEquals( 'ok', $result['status'] );
- $this->assertEquals( 88888, $result['id'] );
- }
}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 4339892..4e7504c 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -33,11 +33,6 @@
exit( 1 );
}
-// Point the test lib bootstrap to the config file in the tests dir (needed when includes/ is symlinked).
-if ( file_exists( "{$_tests_dir}/wp-tests-config.php" ) ) {
- define( 'WP_TESTS_CONFIG_FILE_PATH', "{$_tests_dir}/wp-tests-config.php" );
-}
-
// Give access to tests_add_filter() function.
require_once "{$_tests_dir}/includes/functions.php";