Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
<?php
/**
* Class BWFAN_Rest_API_Add_Contact
*/
namespace BWFAN\Rest_API;
class Add_Contact extends \BWFAN_Rest_API_Base {
public static $ins;
public function __construct() {
parent::__construct();
$this->method = \WP_REST_Server::CREATABLE;
$this->route = '/contact/add';
$this->required = [ 'email' ];
$this->validate = [ 'contact_already_exists' ];
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* @param \BWFCRM_Contact $contact
*
* @return mixed
*/
public function process_api_call( $contact = '' ) {
$result = array();
$email = $this->get_sanitized_arg( 'email', 'email' );
if ( ! is_email( $email ) ) {
$this->error_response( null, 422, 'email_invalid' );
}
$fields = isset( $this->args['fields'] ) && ! empty( $this->args['fields'] ) ? $this->args['fields'] : array();
$stop_automation = isset( $this->args['stop_automation'] ) ? $this->args['stop_automation'] : false;
// creating array of data
$params = array(
'f_name' => isset( $this->args['f_name'] ) ? $this->get_sanitized_arg( 'f_name', 'text_field', $this->args['f_name'] ) : '',
'l_name' => isset( $this->args['l_name'] ) ? $this->get_sanitized_arg( 'l_name', 'text_field', $this->args['l_name'] ) : '',
'country' => isset( $this->args['country'] ) ? $this->get_sanitized_arg( 'country', 'text_field', $this->args['country'] ) : '',
'state' => isset( $this->args['state'] ) ? $this->get_sanitized_arg( 'state', 'text_field', $this->args['state'] ) : '',
'source' => isset( $this->args['source'] ) ? $this->get_sanitized_arg( 'source', 'text_field', $this->args['source'] ) : 'public_api',
'contact_no' => isset( $this->args['contact_no'] ) ? $this->get_sanitized_arg( 'contact_no', 'text_field', $this->args['contact_no'] ) : '',
);
if ( ! empty( $fields ) ) {
// check and remove the fields which does not exists
$field_data = \BWFAN_Rest_API_Common::remove_invalid_fields( $fields );
// store fields which does not exists
if ( ! empty( $field_data['field_not_exists'] ) ) {
$result['field_not_exists'] = $field_data['field_not_exists'];
}
$params = array_replace( $params, $field_data['fields'] );
}
$contact = \BWFAN_Rest_API_Common::create_contact( $email, $params, true );
// setting tags if provided
if ( isset( $this->args['tags'] ) ) {
$tag_ids = is_array( $this->args['tags'] ) ? $this->args['tags'] : array( $this->args['tags'] );
$contact->set_tags_v2( $tag_ids, $stop_automation );
}
// setting lists if provided
if ( isset( $this->args['lists'] ) ) {
$list_ids = is_array( $this->args['lists'] ) ? $this->args['lists'] : array( $this->args['lists'] );
$contact->set_lists_v2( $list_ids, $stop_automation );
}
// saving contact
$contact->save();
// return if not able to create or some error occurred
if ( ! $contact->is_contact_exists() ) {
$this->error_response( '', 422, 'unknown_error' );
}
// validating status if provided and updating it only when update contact is successful
if ( isset( $this->args['status'] ) ) {
\BWFAN_Rest_API_Common::change_contact_status( $contact, $this->args['status'] );
}
return $this->success_response( [ 'contact' => \BWFAN_Rest_API_Common::set_contact_status( $contact ) ], 'Contact created successfully' );
}
}
\BWFAN_Rest_API_Loader::register( 'BWFAN\Rest_API\Add_Contact' );

View File

@@ -0,0 +1,63 @@
<?php
/**
* Class BWFAN_Rest_API_Assign_List
*/
namespace BWFAN\Rest_API;
class Assign_List extends \BWFAN_Rest_API_Base {
public static $ins;
public function __construct() {
parent::__construct();
$this->method = \WP_REST_Server::EDITABLE;
$this->route = '/contact/list-assign/(?P<id>[\\d]+)';
$this->required = [ 'id', 'lists' ];
$this->validate = [ 'contact_not_exists' ];
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* @param \BWFCRM_Contact $contact
*
* @return mixed
*/
public function process_api_call( $contact = '' ) {
$lists = isset( $this->args['lists'] ) ? $this->args['lists'] : array();
$stop_automation = isset( $this->args['stop_automation'] ) ? (bool) $this->args['stop_automation'] : false;
if ( ! is_array( $lists ) ) {
$this->error_response( null, 422, 'unprocessable_entity' );
}
$list_data = \BWFCRM_Lists::get_lists( $lists );
if ( empty( $list_data ) ) {
$this->error_response( 'List(s) not found', 422, 'unprocessable_entity' );
}
$old_lists = $contact->get_lists();
$list_ids = array_column( $list_data, 'ID' );
$assign_lists = $contact->set_lists_v2( $list_ids, $stop_automation );
$contact->save();
if ( ! is_array( $assign_lists ) ) {
$this->error_response( 'No list(s) to update', 422, 'unprocessable_entity' );
}
if ( is_wp_error( $assign_lists ) ) {
$this->error_response( $assign_lists->get_error_messages(), 422, 'unknown_error' );
}
$newly_assigned_lists = array_diff( $assign_lists, $old_lists );
$list_results = \BWFCRM_Lists::get_lists( $newly_assigned_lists );
return $this->success_response( [ 'lists' => $list_results ], __( 'List(s) assigned successfully', 'wp-marketing-automations-pro' ) );
}
}
\BWFAN_Rest_API_Loader::register( 'BWFAN\Rest_API\Assign_List' );

View File

@@ -0,0 +1,62 @@
<?php
/**
* Class BWFAN_Rest_API_Assign_Tag
*/
namespace BWFAN\Rest_API;
class Assign_Tag extends \BWFAN_Rest_API_Base {
public static $ins;
public function __construct() {
parent::__construct();
$this->method = \WP_REST_Server::EDITABLE;
$this->route = '/contact/tag-assign/(?P<id>[\\d]+)';
$this->required = [ 'id', 'tags' ];
$this->validate = [ 'contact_not_exists' ];
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* @param \BWFCRM_Contact $contact
*
* @return mixed|void
*/
public function process_api_call( $contact = '' ) {
$tags = isset( $this->args['tags'] ) ? $this->args['tags'] : array();
$stop_automation = isset( $this->args['stop_automation'] ) ? $this->args['stop_automation'] : false;
if ( ! is_array( $tags ) ) {
$this->error_response( null, 422, 'unprocessable_entity' );
}
$tag_data = \BWFCRM_Tag::get_tags( $tags );
if ( empty( $tag_data ) ) {
$this->error_response( 'Tag(s) not found', 422, 'unprocessable_entity' );
}
$tag_ids = array_column( $tag_data, 'ID' );
$old_tags = $contact->get_tags();
$assign_tags = $contact->set_tags_v2( $tag_ids, $stop_automation );
$contact->save();
if ( ! is_array( $assign_tags ) ) {
$this->error_response( 'No tag(s) to update', 422, 'unprocessable_entity' );
}
if ( is_wp_error( $assign_tags ) ) {
$this->error_response( $assign_tags->get_error_messages(), 422, 'unknown_error' );
}
$newly_assigned_tags = array_diff( $assign_tags, $old_tags );
$tag_results = \BWFCRM_Tag::get_tags( $newly_assigned_tags );
return $this->success_response( [ 'tags' => $tag_results ], __( 'Tag(s) assigned successfully', 'wp-marketing-automations-pro' ) );
}
}
\BWFAN_Rest_API_Loader::register( 'BWFAN\Rest_API\Assign_Tag' );

View File

@@ -0,0 +1,52 @@
<?php
/**
* Class BWFAN_Rest_API_Change_Status
*/
namespace BWFAN\Rest_API;
class Change_Status extends \BWFAN_Rest_API_Base {
public static $ins;
public function __construct() {
parent::__construct();
$this->method = \WP_REST_Server::EDITABLE;
$this->route = '/contact/change-status/(?P<id>[\\d]+)';
$this->required = [ 'id', 'status' ];
$this->validate = [ 'contact_not_exists' ];
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* @param \BWFCRM_Contact $contact
*
* @return mixed|void
*/
public function process_api_call( $contact = '' ) {
$status = $this->get_sanitized_arg( 'status', 'text_field' );
$status = ! empty( $status ) ? strtolower( $status ) : $status;
$allowed_statuses = [ 'unverified', 'subscribed', 'bounced', 'unsubscribed', 'softbounced', 'complaint' ];
/** Validate the status */
if ( ! in_array( $status, $allowed_statuses ) ) {
$this->error_response( sprintf( __( 'Invalid status. Allowed values are: %s', 'wp-marketing-automations-pro' ), implode( ', ', $allowed_statuses ) ), 422, 'invalid_status' );
}
$result = \BWFAN_Rest_API_Common::change_contact_status( $contact, $status );
if ( ! $result ) {
$this->error_response( '', 422, 'unknown_error' );
}
return $this->success_response( [ 'contact' => \BWFAN_Rest_API_Common::get_formatted_contact_data( $contact ) ], __( "Status changed successfully", "autonami-automations-pro" ) );
}
}
\BWFAN_Rest_API_Loader::register( 'BWFAN\Rest_API\Change_Status' );

View File

@@ -0,0 +1,39 @@
<?php
/**
* Class BWFAN_Rest_API_Delete_Contact
*/
namespace BWFAN\Rest_API;
class Delete_Contact extends \BWFAN_Rest_API_Base {
public static $ins;
public function __construct() {
parent::__construct();
$this->method = \WP_REST_Server::DELETABLE;
$this->route = '/contact/(?P<id>[\\d]+)';
$this->required = [ 'id' ];
$this->validate = [ 'contact_not_exists' ];
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function process_api_call() {
$id = $this->get_sanitized_arg( 'id', 'text_field' );
$delete_contact = \BWFCRM_Model_Contact::delete_contact( $id );
if ( ! $delete_contact ) {
$this->error_response( '', 422, 'unknown_error' );
}
return $this->success_response( [], __( 'Contact deleted successfully', 'wp-marketing-automations-pro' ) );
}
}
\BWFAN_Rest_API_Loader::register( 'BWFAN\Rest_API\Delete_Contact' );

View File

@@ -0,0 +1,44 @@
<?php
/**
* Class BWFAN_Rest_API_Get_Contact_By_Id_Or_Email
*/
namespace BWFAN\Rest_API;
class Get_Contact_By_Id_Or_Email extends \BWFAN_Rest_API_Base {
public static $ins;
public function __construct() {
parent::__construct();
$this->method = \WP_REST_Server::READABLE;
$this->route = '/contact';
$this->validate = [ 'contact_not_exists' ];
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* /**
* @param \BWFCRM_Contact $contact
*
* @return mixed
*/
public function process_api_call( $contact = '' ) {
$id = $this->get_sanitized_arg( 'id', 'text_field' );
$email = $this->get_sanitized_arg( 'email', 'email' );
$search_by = empty( $id ) ? $email : $id;
// either id or email should be present
if ( empty( $search_by ) ) {
$this->error_response( null, 400, 'required_fields_missing' );
}
return $this->success_response( [ 'contact' => \BWFAN_Rest_API_Common::get_formatted_contact_data( $contact ) ], __( 'Contact fetched successfully', 'wp-marketing-automations-pro' ) ); }
}
\BWFAN_Rest_API_Loader::register( 'BWFAN\Rest_API\Get_Contact_By_Id_Or_Email' );

View File

@@ -0,0 +1,154 @@
<?php
/**
* Class BWFAN_Rest_API_Get_Contacts
*/
namespace BWFAN\Rest_API;
class Get_Contacts extends \BWFAN_Rest_API_Base {
public static $ins;
public function __construct() {
parent::__construct();
$this->method = \WP_REST_Server::READABLE;
$this->route = '/contacts';
add_filter( 'bwfan_contact_sql_final_where_query', [ $this, 'bwfan_public_api_contact_where_sql' ], 10, 1 );
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function process_api_call() {
$email = $this->get_sanitized_arg( 'email', 'email' );
$limit = isset( $this->args['limit'] ) ? $this->args['limit'] : 30;
$offset = isset( $this->args['offset'] ) ? $this->args['offset'] : 0;
$sort_order = isset( $this->args['sort_order'] ) ? $this->args['sort_order'] : 'DESC';
$sort_field = isset( $this->args['sort_field'] ) ? $this->args['sort_field'] : 'creation_date';
$status = isset( $this->args['status'] ) ? $this->args['status'] : '';
// setting filters statically as only 'status' is being used to filter the contact
$filters = array();
if ( ! empty( $status ) ) {
//formatting the filters
$filters['c'][] = array(
'key' => 'status',
'rule' => 'is',
'type' => \BWFCRM_Filters::$TYPE_NUMBER_EXACT,
'value' => $status
);
}
// if not provided, then taking the defaults
$additional_info = array( 'order_by' => $sort_field, 'order' => $sort_order, 'grab_totals' => true );
$contact_data = \BWFCRM_Model_Contact::get_contacts( $email, $limit, $offset, $filters, $additional_info );
if ( empty( $contact_data ) ) {
$this->error_response( '', 422, 'data_not_found' );
}
/** Modify the status if contact email/phone is in unsubscribe table */
$unsubscribed = self::get_unsubscribed_contacts( $contact_data );
if ( ! empty( $unsubscribed ) ) {
$processed_contacts = array_map( function ( $contact ) use ( $unsubscribed ) {
$email = $contact['email'] ?? '';
$contact_no = $contact['contact_no'] ?? '';
if ( in_array( $email, $unsubscribed, true ) || in_array( $contact_no, $unsubscribed, true ) ) {
$contact['status'] = '3';
}
return $contact;
}, $contact_data['contacts'] );
$contact_data['contacts'] = $processed_contacts;
}
return $this->success_response( [ 'contact' => $contact_data ], __( 'Contact(s) listed successfully', 'wp-marketing-automations-pro' ) );
}
/**
* Get all un-subscriber
*
* @param $contact_data
*
* @return array
*/
public static function get_unsubscribed_contacts( $contact_data ) {
if ( ! isset( $contact_data['contacts'] ) || empty( $contact_data['contacts'] ) ) {
return [];
}
$emails = array_column( $contact_data['contacts'], 'email' );
$contact_nos = array_column( $contact_data['contacts'], 'contact_no' );
$recipients = array_filter( array_unique( array_merge( $emails, $contact_nos ) ) );
if ( empty( $recipients ) ) {
return [];
}
global $wpdb;
$placeholders = implode( ',', array_fill( 0, count( $recipients ), '%s' ) );
$query = " SELECT recipient FROM {$wpdb->prefix}bwfan_message_unsubscribe WHERE recipient IN ($placeholders)";
return $wpdb->get_col( $wpdb->prepare( $query, $recipients ) );//phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL
}
/**
* @param $filter_where
* appending apis filters to contacts where query
*
* @return mixed|string
*/
public function bwfan_public_api_contact_where_sql( $filter_where ) {
$from = isset( $this->args['from'] ) ? date( 'Y-m-d', strtotime( $this->args['from'] ) ) : '';
$to = isset( $this->args['to'] ) ? date( 'Y-m-d', strtotime( $this->args['to'] ) ) : '';
$updated_from = isset( $this->args['updated_from'] ) ? date( 'Y-m-d', strtotime( $this->args['updated_from'] ) ) : '';
$updated_to = isset( $this->args['updated_to'] ) ? date( 'Y-m-d', strtotime( $this->args['updated_to'] ) ) : '';
$tags = isset( $this->args['tag'] ) ? $this->args['tag'] : array();
$lists = isset( $this->args['list'] ) ? $this->args['list'] : array();
if ( ! empty( $from ) ) {
$filter_where .= "AND (c.creation_date >='$from')";
}
if ( ! empty( $to ) ) {
$filter_where .= "AND (c.creation_date <='$to')";
}
if ( ! empty( $updated_from ) ) {
$filter_where .= "AND (c.last_modified >'$updated_from')";
}
if ( ! empty( $updated_to ) ) {
$filter_where .= "AND (c.last_modified <'$updated_to')";
}
// formatting tags with 'like' and 'or' operator
if ( ! empty( $tags ) ) {
$tags = array_map( function ( $tag ) {
return "c.tags LIKE '%\"$tag\"%'";
}, $tags );
$tags = implode( ' OR ', $tags );
$filter_where .= "AND ($tags)";
}
// formatting list with 'like' and 'or' operator
if ( ! empty( $lists ) ) {
$lists = array_map( function ( $list ) {
return "c.lists LIKE '%\"$list\"%'";
}, $lists );
$lists = implode( ' OR ', $lists );
$filter_where .= "AND ($lists)";
}
return $filter_where;
}
}
\BWFAN_Rest_API_Loader::register( 'BWFAN\Rest_API\Get_Contacts' );

View File

@@ -0,0 +1,55 @@
<?php
/**
* Class BWFAN_Rest_API_Unassign_List
*/
namespace BWFAN\Rest_API;
class Unassign_List extends \BWFAN_Rest_API_Base {
public static $ins;
public function __construct() {
parent::__construct();
$this->method = \WP_REST_Server::EDITABLE;
$this->route = '/contact/list-unassign/(?P<id>[\\d]+)';
$this->required = [ 'id', 'listId' ];
$this->validate = [ 'contact_not_exists' ];
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* @param \BWFCRM_Contact $contact
*
* @return mixed
*/
public function process_api_call( $contact = '' ) {
$lists = isset( $this->args['listId'] ) ? $this->args['listId'] : array();
if ( ! is_array( $lists ) ) {
$this->error_response( '', 422, 'unprocessable_entity' );
}
$unassign_lists = $contact->remove_lists( $lists );
$contact->save();
if ( empty( $unassign_lists ) ) {
$this->error_response( 'No list to unassign', 422, 'unprocessable_entity' );
}
if ( is_wp_error( $unassign_lists ) ) {
$this->error_response( $unassign_lists->get_error_messages(), 422, 'unknown_error' );
}
$unassign_lists = \BWFCRM_Lists::get_lists( $unassign_lists );
return $this->success_response( [ 'lists' => $unassign_lists ], __( 'List(s) unassigned successfully', 'wp-marketing-automations-pro' ) );
}
}
\BWFAN_Rest_API_Loader::register( 'BWFAN\Rest_API\Unassign_List' );

View File

@@ -0,0 +1,55 @@
<?php
/**
* Class BWFAN_Rest_API_Unassign_Tag
*/
namespace BWFAN\Rest_API;
class Unassign_Tag extends \BWFAN_Rest_API_Base {
public static $ins;
public function __construct() {
parent::__construct();
$this->method = \WP_REST_Server::EDITABLE;
$this->route = '/contact/tag-unassign/(?P<id>[\\d]+)';
$this->required = [ 'id', 'tagId' ];
$this->validate = [ 'contact_not_exists' ];
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* @param \BWFCRM_Contact $contact
*
* @return mixed
*/
public function process_api_call( $contact = '' ) {
$tags = isset( $this->args['tagId'] ) ? $this->args['tagId'] : array();
if ( ! is_array( $tags ) ) {
$this->error_response( '', 422, 'unprocessable_entity' );
}
$tags_data = $contact->remove_tags( $tags );
$contact->save();
if ( empty( $tags_data ) ) {
$this->error_response( 'No tag to unassign', 422, 'unprocessable_entity' );
}
if ( is_wp_error( $tags_data ) ) {
$this->error_response( $tags_data->get_error_messages(), 422, 'unknown_error' );
}
$unassign_tags = \BWFCRM_Tag::get_tags( $tags_data );
return $this->success_response( [ 'tags' => $unassign_tags ], __( 'Tag(s) unassigned successfully', 'wp-marketing-automations-pro' ) );
}
}
\BWFAN_Rest_API_Loader::register( 'BWFAN\Rest_API\Unassign_Tag' );

View File

@@ -0,0 +1,114 @@
<?php
/**
* Class BWFAN_Rest_API_Update_Contact
*/
namespace BWFAN\Rest_API;
class Update_Contact extends \BWFAN_Rest_API_Base {
public static $ins;
public function __construct() {
parent::__construct();
$this->method = \WP_REST_Server::EDITABLE;
$this->route = '/contact/update/(?P<id>[\\d]+)';
$this->required = [ 'id' ];
$this->validate = [ 'contact_not_exists' ];
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* @param \BWFCRM_Contact $contact
*
* @return mixed
*/
public function process_api_call( $contact = '' ) {
$id = $this->get_sanitized_arg( 'id', 'text_field' );
/** creating array of data */
$params = array(
'id' => $id,
'f_name' => isset( $this->args['f_name'] ) ? $this->get_sanitized_arg( 'f_name', 'text_field', $this->args['f_name'] ) : '',
'l_name' => isset( $this->args['l_name'] ) ? $this->get_sanitized_arg( 'l_name', 'text_field', $this->args['l_name'] ) : '',
'country' => isset( $this->args['country'] ) ? $this->get_sanitized_arg( 'country', 'text_field', $this->args['country'] ) : '',
'state' => isset( $this->args['state'] ) ? $this->get_sanitized_arg( 'state', 'text_field', $this->args['state'] ) : '',
'source' => isset( $this->args['source'] ) ? $this->get_sanitized_arg( 'source', 'text_field', $this->args['source'] ) : '',
'contact_no' => isset( $this->args['contact_no'] ) ? $this->get_sanitized_arg( 'contact_no', 'text_field', $this->args['contact_no'] ) : '',
);
/** Validating email if provided */
if ( isset( $this->args['email'] ) ) {
$email = $this->get_sanitized_arg( 'email', 'email' );
if ( ! is_email( $email ) ) {
$this->error_response( null, 422, 'email_invalid' );
}
/** Checking if contact already exist */
if ( ! empty( \BWFAN_Rest_API_Common::is_contact_exists( $email ) ) ) {
$this->error_response( null, 422, 'already_exists' );
}
$params['email'] = $email;
}
/** Setting fields if provided */
$result = array();
$fields = isset( $this->args['fields'] ) && ! empty( $this->args['fields'] ) ? $this->args['fields'] : array();
if ( ! empty( $fields ) ) {
$field_data = \BWFAN_Rest_API_Common::remove_invalid_fields( $fields );
if ( ! empty( $field_data['field_not_exists'] ) ) {
$result['field_not_exists'] = $field_data['field_not_exists'];
}
if ( ! empty( $field_data['fields'] ) ) {
$contact->set_fields( $field_data['fields'] );
}
}
/** Removing empty keys */
$params = array_filter( $params );
/** Setting tags if provided */
if ( isset( $this->args['tags'] ) && ! empty( $this->args['tags'] ) ) {
$tags = is_array( $this->args['tags'] ) ? $this->args['tags'] : array( $this->args['tags'] );
$tag_data = \BWFCRM_Tag::get_tags( $tags );
$tag_ids = array_column( $tag_data, 'ID' );
$contact->set_tags_v2( $tag_ids );
}
/** Setting lists if provided */
if ( isset( $this->args['lists'] ) && ! empty( $this->args['tags'] ) ) {
$lists = is_array( $this->args['lists'] ) ? $this->args['lists'] : array( $this->args['lists'] );
$lists_data = \BWFCRM_Lists::get_lists( $lists );
$list_ids = array_column( $lists_data, 'ID' );
$contact->set_lists_v2( $list_ids );
}
/** Updating contact by contact id */
$update_contact = $contact->update( $params );
if ( is_wp_error( $update_contact ) || ! $update_contact ) {
$this->error_response( '', 422, 'unknown_error' );
}
/** Validating status if provided and updating it only when update contact is successful */
if ( isset( $this->args['status'] ) ) {
\BWFAN_Rest_API_Common::change_contact_status( $contact, $this->args['status'] );
}
/** Re-fetching contact obj after updating */
$contact = new \BWFCRM_Contact( $contact->get_id() );
return $this->success_response( [ 'contact' => \BWFAN_Rest_API_Common::get_formatted_contact_data( $contact ) ], __( 'Contact updated successfully', 'wp-marketing-automations-pro' ) );
}
}
\BWFAN_Rest_API_Loader::register( 'BWFAN\Rest_API\Update_Contact' );

View File

@@ -0,0 +1,60 @@
<?php
/**
* Class BWFAN_Rest_API_Update_Email
*/
namespace BWFAN\Rest_API;
class Update_Email extends \BWFAN_Rest_API_Base {
public static $ins;
public function __construct() {
parent::__construct();
$this->method = \WP_REST_Server::EDITABLE;
$this->route = '/contact/update-email/(?P<id>[\\d]+)';
$this->required = [ 'id', 'email' ];
$this->validate = [ 'contact_not_exists' ];
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* @param \BWFCRM_Contact $contact
*
* @return mixed
*/
public function process_api_call( $contact = '' ) {
$id = $this->get_sanitized_arg( 'id', 'text_field' );
$email = $this->get_sanitized_arg( 'email', 'email' );
if ( ! is_email( $email ) ) {
$this->error_response( null, 422, ' email_invalid' );
}
// checking if contact already exits
if ( ! empty( \BWFAN_Rest_API_Common::is_contact_exists( $email ) ) ) {
$this->error_response( null, 422, 'already_exists' );
}
// updating email by contact id
$update_contact = $contact->set_data( array( 'email' => $email ) );
if ( is_wp_error( $update_contact ) ) {
$this->error_response( $update_contact->get_error_messages(), 422, 'unknown_error' );
}
$contact->save();
/** Re-fetching contact obj after updating */
$contact = new \BWFCRM_Contact( $contact->get_id() );
return $this->success_response( [ 'contact' => \BWFAN_Rest_API_Common::get_formatted_contact_data( $contact ) ], __( 'Email updated successfully', 'wp-marketing-automations-pro' ) );
}
}
\BWFAN_Rest_API_Loader::register( 'BWFAN\Rest_API\Update_Email' );