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,114 @@
<?php
class BWFCRM_API_Apply_Field extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::EDITABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/fields';
}
public function default_args_values() {
return array(
'contact_id' => 0,
'email' => '',
'fields' => '',
);
}
public function process_api_call() {
$contact = $this->get_contact_by_id_or_email( 'contact_id', 'email' );
$email = $this->get_sanitized_arg( 'email', 'text_field' );
if ( is_wp_error( $contact ) ) {
return $contact;
}
if ( empty( $email ) || ! is_email( $email ) ) {
$email = $contact->contact->get_email();
}
$sanitize_cb = 'text_field';
if ( is_array( $this->args['fields'] ) ) {
$ids = array_keys( $this->args['fields'] );
$ids = array_filter( $ids, [ $this, 'check_field_type_textarea' ] );
if ( count( $ids ) > 0 ) {
$sanitize_cb = 'textarea_field';
}
}
$fields = $this->get_sanitized_arg( '', $sanitize_cb, $this->args['fields'] );
if ( empty( $fields ) ) {
$response = __( 'Required Fields missing', 'wp-marketing-automations-pro' );
$this->response_code = 400;
return $this->error_response( $response );
}
$field_email = $this->get_sanitized_arg( 'email', 'text_field', $this->args['fields'] );
if ( ! empty( $field_email ) && $email !== $field_email ) {
if ( ! is_email( $field_email ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Email is not valid.', 'wp-marketing-automations-pro' ) );
}
$check_contact = new BWFCRM_Contact( $field_email );
/** If email is already exists with other contacts*/
if ( $check_contact->is_contact_exists() ) {
/** If Only email field to be updated then return error response */
if ( 1 === count( $this->args['fields'] ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Email is already associated with other contact.', 'wp-marketing-automations-pro' ) );
}
/**If other fields also available for update then unset the email */
unset( $fields['email'] );
}
}
$response = $contact->update_custom_fields( $fields );
if ( ! ( $response ) || empty( $response ) ) {
$this->response_code = 200;
return $this->success_response( '', __( 'Unable to Update fields', 'wp-marketing-automations-pro' ) );
}
/** If email changed and email is set for change then hook added */
if ( ! empty( $field_email ) && $email !== $field_email ) {
do_action( 'bwfan_contact_email_changed', $field_email, $email, $contact );
}
return $this->success_response( $contact->get_array( false, true, true, true ), 'Contact updated' );
}
public function check_field_type_textarea( $id ) {
$fields = BWFCRM_Fields::get_custom_fields( null, null, null );
$fields = array_filter( $fields, function ( $val ) {
if ( isset( $val['type'] ) && 3 == $val['type'] ) {
/** 3 is textarea */
return true;
}
return false;
} );
if ( is_array( $fields ) && array_key_exists( $id, $fields ) ) {
return true;
}
return false;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Apply_Field' );

View File

@@ -0,0 +1,89 @@
<?php
class BWFCRM_API_Apply_Lists extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::EDITABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/lists';
}
public function default_args_values() {
return array(
'contact_id' => 0,
'lists' => array(),
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
if ( empty( $contact_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with given id #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$lists = $this->args['lists'];
$lists = array_filter( array_values( $lists ) );
if ( empty( $lists ) ) {
$response = __( 'Required Lists missing', 'wp-marketing-automations-pro' );
$this->response_code = 404;
return $this->error_response( $response );
}
$added_lists = $contact->add_lists( $lists );
if ( is_wp_error( $added_lists ) ) {
$this->response_code = 500;
return $this->error_response( '', $added_lists );
}
if ( empty( $added_lists ) ) {
$this->response_code = 200;
return $this->success_response( '', __( 'Provided lists are applied already.', 'wp-marketing-automations-pro' ) );
}
$result = [];
$lists_added = array_map( function ( $list ) {
return $list->get_array();
}, $added_lists );
$message = __( 'List(s) assigned', 'wp-marketing-automations-pro' );
if ( count( $lists ) !== count( $added_lists ) ) {
$added_lists_names = array_map( function ( $list ) {
return $list->get_name();
}, $added_lists );
$added_lists_names = implode( ', ', $added_lists_names );
$this->response_code = 200;
$message = __( 'Some Lists are applied already. Applied Lists are: ' . $added_lists_names, 'wp-marketing-automations-pro' );
}
$result['list_added'] = is_array( $lists_added ) ? array_values( $lists_added ) : $lists_added;
$result['last_modified'] = $contact->contact->get_last_modified();
return $this->success_response( $result, $message );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Apply_Lists' );

View File

@@ -0,0 +1,85 @@
<?php
class BWFCRM_API_Apply_Tags extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::EDITABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/tags';
}
public function default_args_values() {
return array(
'contact_id' => 0,
'tags' => array(),
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
if ( empty( $contact_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$tags = $this->args['tags'];
$tags = array_filter( array_values( $tags ) );
if ( empty( $tags ) ) {
$response = __( 'No Tags provided', 'wp-marketing-automations-pro' );
$this->response_code = 400;
return $this->error_response( $response );
}
$added_tags = $contact->add_tags( $tags );
if ( is_wp_error( $added_tags ) ) {
$this->response_code = 500;
return $this->error_response( '', $added_tags );
}
if ( empty( $added_tags ) ) {
$this->response_code = 200;
return $this->success_response( '', __( 'Provided tags are applied already.', 'wp-marketing-automations-pro' ) );
}
$tags_added = array_map( function ( $tag ) {
return $tag->get_array();
}, $added_tags );
$result = [];
$message = __( 'Tag(s) added', 'wp-marketing-automations-pro' );
if ( count( $tags ) !== count( $added_tags ) ) {
$applied_tags_names = array_map( function ( $tag ) {
return $tag->get_name();
}, $added_tags );
$applied_tags_names = implode( ', ', $applied_tags_names );
$this->response_code = 200;
$message = __( 'Some Tags are applied already. Applied Tags are: ' . $applied_tags_names, 'wp-marketing-automations-pro' );
}
$result['tags_added'] = is_array( $tags_added ) ? array_values( $tags_added ) : $tags_added;
$result['last_modified'] = $contact->contact->get_last_modified();
return $this->success_response( $result, $message );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Apply_Tags' );

View File

@@ -0,0 +1,82 @@
<?php
class BWFCRM_API_Contact_Listing extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public $count_data = [];
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/listing';
$this->pagination->offset = 0;
$this->pagination->limit = 10;
}
public function process_api_call() {
/** checking if search present in params */
$search = $this->get_sanitized_arg( 'search', 'text_field' );
$filters_collection = empty( $this->args['filters'] ) ? array() : $this->args['filters'];
$get_wc_data = $this->get_sanitized_arg( 'get_wc', 'bool' );
$grab_totals = $this->get_sanitized_arg( 'grab_totals', 'bool' );
$only_count = $this->get_sanitized_arg( 'only_count', 'bool' );
$contact_mode = $this->get_sanitized_arg( 'fetch_base', 'text_field' );
$exclude_unsubs = $this->get_sanitized_arg( 'exclude_unsubs', 'bool' );
$exclude_unsubs_lists = $this->get_sanitized_arg( 'exclude_unsubs_lists', 'bool' );
$grab_custom_fields = $this->get_sanitized_arg( 'grab_custom_fields', 'bool' );
$order = $this->get_sanitized_arg( 'order', 'text_field' );
$order_by = $this->get_sanitized_arg( 'order_by', 'text_field' );
$additional_info = array(
'grab_totals' => $grab_totals,
'only_count' => $only_count,
'fetch_base' => $contact_mode,
'exclude_unsubs' => $exclude_unsubs,
'exclude_unsubs_lists' => $exclude_unsubs_lists,
'grab_custom_fields' => $grab_custom_fields,
);
if ( ! empty( $order ) && ! empty( $order_by ) ) {
$additional_info['order'] = $order;
$additional_info['order_by'] = $order_by;
}
if ( class_exists( 'WooCommerce' ) ) {
$additional_info['customer_data'] = $get_wc_data;
}
$filter_match = isset( $filters_collection['match'] ) && ! empty( $filters_collection['match'] ) ? $filters_collection['match'] : 'all';
$filter_match = ( 'any' === $filter_match ? ' OR ' : ' AND ' );
$normalized_filters = BWFCRM_Filters::_normalize_input_filters( $filters_collection );
// $contacts = BWFCRM_Contact::get_contacts( $search, $this->pagination->offset, $this->pagination->limit, $filters_collection, $additional_info );
$contacts = BWFCRM_Model_Contact::get_contact_listing( $search, $this->pagination->limit, $this->pagination->offset, $normalized_filters, $additional_info, $filter_match );
$this->count_data = BWFAN_PRO_Common::get_contact_data_counts();
$this->total_count = $contacts['total'];
$this->response_code = 200;
return $this->success_response( $contacts['contacts'] );
}
public function get_result_total_count() {
return $this->total_count;
}
public function get_result_count_data() {
return $this->count_data;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Contact_Listing' );

View File

@@ -0,0 +1,61 @@
<?php
class BWFCRM_API_Contact_Resubscribe extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::DELETABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/resubscribe';
$this->request_args = array(
'contact_id' => array(
'description' => __( 'Contact ID to resubscribe contact', 'wp-marketing-automations-pro' ),
'type' => 'integer',
)
);
}
public function default_args_values() {
return array(
'contact_id' => ''
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
$contact = new BWFCRM_Contact( absint( $contact_id ) );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact doesn\'t exist', 'wp-marketing-automations-pro' ) );
}
$unsubscribe_data = $contact->check_contact_unsubscribed( false );
if ( empty( $unsubscribe_data ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact already subscribed', 'wp-marketing-automations-pro' ) );
}
foreach ( $unsubscribe_data as $data ) {
BWFAN_Model_Message_Unsubscribe::delete( $data['ID'] );
}
$contact->save_last_modified();
$this->response_code = 200;
return $this->success_response( [ 'contact_id' => $contact_id ], __( 'Contact subscribed', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Contact_Resubscribe' );

View File

@@ -0,0 +1,101 @@
<?php
class BWFCRM_API_Contact_Status_Change extends BWFCRM_API_Base {
public static $ins;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/execute_status_action/(?P<status>[a-zA-Z0-9-]+)';
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
$status = $this->get_sanitized_arg( 'status', 'text_field' );
$contact = new BWFCRM_Contact( absint( $contact_id ) );
if ( ! $contact->is_contact_exists() ) {
return $this->error_response( __( 'Contact does not exists', 'wp-marketing-automations-pro' ) );
}
$result = false;
$message = __( 'Unable to perform requested action', 'wp-marketing-automations-pro' );
switch ( $status ) {
case 'resubscribe':
$result = $contact->resubscribe();
if ( true === $result ) {
$message = __( 'Contact resubscribed', 'wp-marketing-automations-pro' );
}
break;
case 'unsubscribe':
$result = $contact->unsubscribe();
if ( true === $result ) {
$message = __( 'Contact unsubscribed', 'wp-marketing-automations-pro' );
}
break;
case 'verify':
$result = $contact->verify();
if ( true === $result ) {
$message = __( 'Contact subscribed', 'wp-marketing-automations-pro' );
}
break;
case 'unverify':
$result = $contact->unverify();
if ( true === $result ) {
$message = __( 'Contact unverfied', 'wp-marketing-automations-pro' );
}
break;
case 'bounced':
$result = $contact->mark_as_bounced();
if ( true === $result ) {
$message = __( 'Contact bounced', 'wp-marketing-automations-pro' );
}
break;
case 'softbounced':
if ( method_exists( $contact, 'mark_as_soft_bounced' ) ) {
$result = $contact->mark_as_soft_bounced();
if ( true === $result ) {
$message = __( 'Contact soft bounced', 'wp-marketing-automations-pro' );
}
} else {
$result = $contact->mark_as_bounced();
if ( true === $result ) {
$message = __( 'Contact bounced', 'wp-marketing-automations-pro' );
}
}
break;
case 'complaint':
if ( method_exists( $contact, 'mark_as_complaint' ) ) {
$result = $contact->mark_as_complaint();
if ( true === $result ) {
$message = __( 'Contact complaint', 'wp-marketing-automations-pro' );
}
} else {
$result = $contact->mark_as_bounced();
if ( true === $result ) {
$message = __( 'Contact bounced', 'wp-marketing-automations-pro' );
}
}
break;
}
if ( ! $result ) {
return $this->error_response( $message, null, 500 );
}
return $this->success_response( [
'status' => $contact->get_display_status(),
'data' => $contact->get_array( false, true, true, true, true ),
], $message );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Contact_Status_Change' );

View File

@@ -0,0 +1,81 @@
<?php
class BWFCRM_API_Contact_Unsubscribe extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/unsubscribe';
$this->request_args = array(
'contact_id' => array(
'description' => __( 'Contact ID to unsubscribe contact', 'wp-marketing-automations-pro' ),
'type' => 'integer',
)
);
}
public function default_args_values() {
return array(
'contact_id' => '',
'mode' => '',
'automation_id' => '',
'c_type' => ''
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
$automation_id = $this->get_sanitized_arg( 'automation_id', 'text_field' );
$c_type = $this->get_sanitized_arg( 'c_type', 'text_field' );
$contact = new BWFCRM_Contact( absint( $contact_id ) );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact doesn\'t exist', 'wp-marketing-automations-pro' ) );
}
$unsubscribed = $contact->check_contact_unsubscribed();
if ( ! empty( $unsubscribed['ID'] ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact already unsubscribed', 'wp-marketing-automations-pro' ) );
}
$recipients = [];
$email = $contact->contact->get_email();
$phone = $contact->contact->get_contact_no();
$recipients[] = $email;
if ( ! empty( $phone ) ) {
$recipients[] = $phone;
}
foreach ( $recipients as $recipient ) {
$insert_data = array(
'recipient' => $recipient,
'mode' => is_email( $recipient ) ? 1 : 2,
'c_date' => current_time( 'mysql', 1 ),
'automation_id' => ! empty( $automation_id ) ? absint( $automation_id ) : get_current_user_id(),
'c_type' => ! empty( $c_type ) ? absint( $c_type ) : 3
);
BWFAN_Model_Message_Unsubscribe::insert( $insert_data );
/** hook when any contact unsubscribed */
do_action( 'bwfcrm_after_contact_unsubscribed', $insert_data );
}
$contact->save_last_modified();
return $this->success_response( [ 'contact_id' => $contact_id ], __( 'Contact unsubscribed', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Contact_Unsubscribe' );

View File

@@ -0,0 +1,62 @@
<?php
class BWFCRM_API_Create_Contact_Note extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/notes';
}
public function default_args_values() {
return array(
'contact_id' => 0,
'notes' => array(),
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
if ( empty( $contact_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$notes = $this->args['notes'];
if ( empty( $notes ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Note is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with given id #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$note_added = $contact->add_note_to_contact( $notes );
if ( false === $note_added || is_wp_error( $note_added ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Unable to add note to contact', 'wp-marketing-automations-pro' ) );
}
$this->response_code = 200;
return $this->success_response( [], __( 'Contact note added', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Create_Contact_Note' );

View File

@@ -0,0 +1,75 @@
<?php
class BWFCRM_API_Create_Contact extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/contacts';
}
public function process_api_call() {
$email = $this->get_sanitized_arg( 'email', 'email' );
if ( false === $email || ! is_email( $email ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Email is not valid', 'wp-marketing-automations-pro' ) );
}
$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'] ) : '',
'create_wp_user' => isset( $this->args['create_wp_user'] ) ? rest_sanitize_boolean( $this->args['create_wp_user'] ) : '',
'wp_password' => isset( $this->args['wp_password'] ) ? $this->args['wp_password'] : '',
'contact_no' => isset( $this->args['contact_no'] ) ? $this->get_sanitized_arg( 'contact_no', 'text_field', $this->args['contact_no'] ) : '',
'source' => isset( $this->args['source'] ) ? $this->get_sanitized_arg( 'source', 'text_field', $this->args['source'] ) : '',
'status' => isset( $this->args['status'] ) ? $this->get_sanitized_arg( 'status', 'text_field', $this->args['status'] ) : '',
);
foreach ( $this->args as $key => $value ) {
if ( ! is_numeric( $key ) ) {
continue;
}
$params[ $key ] = $value;
}
$contact = new BWFCRM_Contact( $email, true, $params );
if ( isset( $this->args['tags'] ) ) {
$contact->set_tags( $this->args['tags'], true, false );
}
if ( isset( $this->args['lists'] ) ) {
$contact->set_lists( $this->args['lists'], true, false );
}
$contact->save();
if ( $contact->already_exists ) {
$this->response_code = 422;
return $this->error_response( __( 'Contact already exists', 'wp-marketing-automations-pro' ) );
}
if ( $contact->is_contact_exists() ) {
$this->response_code = 200;
return $this->success_response( $contact->get_array( false, class_exists( 'WooCommerce' ) ), __( 'Contact created', 'wp-marketing-automations-pro' ) );
}
$this->response_code = 500;
return $this->error_response( __( 'Unable to create contact', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Create_Contact' );

View File

@@ -0,0 +1,59 @@
<?php
class BWFCRM_API_DELETE_Contact_Note extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::DELETABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/notes/(?P<note_id>[\\d]+)';
}
public function default_args_values() {
return array(
'contact_id' => 0,
'note_id' => 0,
);
}
public function process_api_call() {
/** checking if search present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
if ( empty( $contact_id ) ) {
return $this->error_response( __( 'Contact id is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact instanceof BWFCRM_Contact || 0 === $contact->get_id() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with id #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$note_id = $this->get_sanitized_arg( 'note_id', 'key' );
$delete_contact_note_result = $contact->delete_notes( $note_id );
if ( ! $delete_contact_note_result ) {
$this->response_code = 404;
return $this->error_response( __( 'Unable to delete the note for contact #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$this->response_code = 200;
$success_message = __( 'Contact notes deleted', 'wp-marketing-automations-pro' );
return $this->success_response( array( 'contact_id' => $contact_id ), $success_message );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_DELETE_Contact_Note' );

View File

@@ -0,0 +1,58 @@
<?php
class BWFCRM_API_DELETE_Contact extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::DELETABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)';
}
public function default_args_values() {
return array(
'contact_id' => '',
);
}
public function process_api_call() {
/** checking if search present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
if ( empty( $contact_id ) ) {
return $this->error_response( __( 'Contact id is missing.', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact instanceof BWFCRM_Contact || 0 === $contact->get_id() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with given contact id: ' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$delete_contact_result = BWFCRM_Model_Contact::delete_contact( $contact_id );
if ( ! $delete_contact_result ) {
$this->response_code = 404;
return $this->error_response( __( 'Some error occurred during deletion of contact and its data.', 'wp-marketing-automations-pro' ) );
}
$this->response_code = 200;
$success_message = __( 'Contact deleted', 'wp-marketing-automations-pro' );
return $this->success_response( array( 'contact_id' => $contact_id ), $success_message );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_DELETE_Contact' );

View File

@@ -0,0 +1,36 @@
<?php
class BWFCRM_API_Delete_Contacts extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::DELETABLE;
$this->route = '/contacts';
}
public function process_api_call() {
$contact_ids = $this->args['contacts'];
if ( empty( $contact_ids ) || ! is_array( $contact_ids ) ) {
return $this->error_response( __( 'Contact ids are missing.', 'wp-marketing-automations-pro' ), null, 500 );
}
BWFCRM_Model_Contact::delete_multiple_contacts( $contact_ids );
$this->response_code = 200;
return $this->success_response( array( 'contacts' => $contact_ids ), __( 'Contacts deleted!', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Delete_Contacts' );

View File

@@ -0,0 +1,91 @@
<?php
class BWFCRM_API_Get_Contact_Automations extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public $contact;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/automations';
}
public function default_args_values() {
return array(
'contact_id' => 0,
);
}
public function process_api_call() {
/** checking if id or email present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
$offset = ! empty( $this->get_sanitized_arg( 'offset', 'text_field' ) ) ? absint( $this->get_sanitized_arg( 'offset', 'text_field' ) ) : 0;
$limit = ! empty( $this->get_sanitized_arg( 'limit', 'text_field' ) ) ? $this->get_sanitized_arg( 'limit', 'text_field' ) : 25;
/** contact id missing than return */
if ( empty( $contact_id ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Contact id is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$contact_automations = [];
if ( class_exists('BWFAN_Common') ) {
$contact_automations = BWFAN_Common::get_automations_for_contact( $contact_id, $limit, $offset );
}
if ( empty( $contact_automations ) ) {
$this->response_code = 200;
return $this->error_response( __( 'No contact automation found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$contact_automations['contacts'] = array_map( function( $contact ) {
/** Get event name */
$event_slug = BWFAN_Model_Automations::get_event_name($contact['aid']);
$event_obj = BWFAN_Core()->sources->get_event( $event_slug );
$event_name = ! empty( $event_obj ) ? $event_obj->get_name(): '';
$automation_meta = BWFAN_Core()->automations->get_automation_data_meta( $contact['aid'] );
$contact['event'] = $event_name;
$contact['automation_title'] = $automation_meta['title'];
return $contact;
}, $contact_automations['contacts'] );
$this->total_count = isset( $contact_automations[ 'total' ] ) ? $contact_automations[ 'total' ] : 0;
$this->response_code = 200;
$success_message = __( 'Got all contact automations', 'wp-marketing-automations-pro' );
return $this->success_response( $contact_automations, $success_message );
}
public function get_result_total_count() {
return $this->total_count;
}
}
if ( function_exists( 'BWFAN_Core' ) ) {
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Automations' );
}

View File

@@ -0,0 +1,91 @@
<?php
class BWFCRM_API_Get_Contact_Funnels extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/funnels';
}
public function default_args_values() {
return array(
'contact_id' => '',
);
}
public function process_api_call() {
/** checking if search present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
$offset = $this->get_sanitized_arg( 'offset', 'key' );
$limit = $this->get_sanitized_arg( 'limit', 'key' );
$offset = empty( $offset ) ? $this->pagination->offset : $offset;
$limit = empty( $offset ) ? $this->pagination->limit : $limit;
if ( empty( $contact_id ) ) {
return $this->error_response( __( 'Contact ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with given id #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$contacts_funnel = array();
$contacts_funnel['funnel'] = $contact->get_contact_funnels_array();
if ( function_exists( 'WFACP_Core' ) ) {
$contacts_funnel['funnel']['checkout'] = [];
}
if ( function_exists( 'WFOB_Core' ) ) {
$contacts_funnel['funnel']['order_bump'] = [];
}
if ( function_exists( 'WFOPP_Core' ) ) {
$optin_etries = $contact->get_contact_optin_array();
if ( is_array( $optin_etries ) && ! empty( $optin_etries ) ) {
/** Add email in optin entry */
$optin_etries = array_map( function ( $optin ) {
$entry = json_decode( $optin['entry'], true );
if ( ! empty( $optin['email'] ) && ! empty( $entry ) ) {
$entry['optin_email'] = $optin['email'];
}
$optin['entry'] = wp_json_encode( $entry );
return $optin;
}, $optin_etries );
}
$contacts_funnel['funnel']['optin'] = $optin_etries;
}
if ( function_exists( 'WFOCU_Core' ) ) {
$contacts_funnel['funnel']['upsells'] = [];
}
$this->response_code = 200;
$success_message = __( 'Contacts funnels', 'wp-marketing-automations-pro' );
return $this->success_response( $contacts_funnel, $success_message );
}
}
if ( class_exists( 'WFFN_Core' ) ) {
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Funnels' );
}

View File

@@ -0,0 +1,89 @@
<?php
class BWFCRM_API_Get_Contact_Lists extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/lists';
$this->pagination->offset = 0;
$this->pagination->limit = 30;
$this->request_args = array(
'search' => array(
'description' => __( 'Search from list name', 'wp-marketing-automations-pro' ),
'type' => 'string',
),
'offset' => array(
'description' => __( 'list Offset', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'limit' => array(
'description' => __( 'Per page limit', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
public function default_args_values() {
return array(
'contact_id' => '',
);
}
public function process_api_call() {
/** checking if search present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
$search = $this->get_sanitized_arg( 'search', 'text_field' );
$offset = $this->get_sanitized_arg( 'offset', 'text_field' );
$limit = $this->get_sanitized_arg( 'limit', 'text_field' );
$offset = empty( $offset ) ? $this->pagination->offset : $offset;
$limit = empty( $offset ) ? $this->pagination->limit : $limit;
if ( empty( $contact_id ) ) {
return $this->error_response( __( 'Contact id is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
// $contact_terms_count = BWFCRM_Model_Contact_Terms::get_contact_terms_count( $contact->get_id(), $search, 1 );
// $contact_terms = BWFCRM_Model_Contact_Terms::get_contact_terms( $contact->get_id(), $offset, $limit, $search, 1 );
$contact_terms = $contact->get_all_lists();
if ( empty( $contact_terms ) ) {
$this->response_code = 404;
$error_message = ! empty( $search ) ? __( 'No Searched lists found for contact with name \'' . $search . '\'', 'wp-marketing-automations-pro' ) : __( 'No contacts lists found', 'wp-marketing-automations-pro' );
return $this->error_response( $error_message );
}
$this->total_count = count( $contact_terms );
$this->response_code = 200;
$success_message = ! empty( $search ) ? __( 'Searched lists for contact \'' . $search . '\'', 'wp-marketing-automations-pro' ) : __( 'Got all contacts lists', 'wp-marketing-automations-pro' );
return $this->success_response( $contact_terms, $success_message );
}
public function get_result_total_count() {
return $this->total_count;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Lists' );

View File

@@ -0,0 +1,67 @@
<?php
class BWFCRM_API_Get_Contact_Note extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/notes';
$this->pagination->limit = 25;
$this->pagination->offset = 0;
}
public function default_args_values() {
return array(
'contact_id' => '',
);
}
public function process_api_call() {
/** checking if search present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
$offset = ! empty( $this->get_sanitized_arg( 'offset', 'key' ) ) ? $this->get_sanitized_arg( 'offset', 'text_field' ) : $this->pagination->offset;
$limit = ! empty( $this->get_sanitized_arg( 'limit', 'key' ) ) ? $this->get_sanitized_arg( 'limit', 'text_field' ) : $this->pagination->limit;
if ( empty( $contact_id ) ) {
return $this->error_response( __( 'Contact ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with given id #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$contact_notes = $contact->get_contact_notes_array( $offset, $limit );
if ( empty( $contact_notes ) ) {
$this->response_code = 200;
return $this->success_response( [], __( 'No contact notes found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$all_contact_notes = $contact->get_contact_notes_array( 0, 0 );
$this->total_count = count( $all_contact_notes );
$this->response_code = 200;
$success_message = __( 'Contact notes reated to contact id :' . $contact_id, 'wp-marketing-automations-pro' );
return $this->success_response( $contact_notes, $success_message );
}
public function get_result_total_count() {
return $this->total_count;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Note' );

View File

@@ -0,0 +1,282 @@
<?php
class BWFCRM_API_Get_Contact_Orders extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public $contact;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/orders';
}
public function default_args_values() {
return array(
'contact_id' => 0,
);
}
public function process_api_call() {
/** checking if id or email present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
/** contact id missing than return */
if ( empty( $contact_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact id is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$limit = $this->get_sanitized_arg( 'limit', 'text_field' );
$offset = $this->get_sanitized_arg( 'offset', 'text_field' );
$limit = ! empty( $limit ) ? $limit : 10;
$offset = ! empty( $offset ) ? $offset : 0;
$order_ids = $contact->get_orders( $offset, $limit );
$orders = $this->get_contact_activity_records( $contact_id, $order_ids );
if ( empty( $orders ) ) {
$response = [
'orders' => [],
];
$this->response_code = 200;
return $this->success_response( $response, __( 'No contact order found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$response = [
'orders' => $orders,
];
$this->total_count = $contact->get_orders_count();
$this->response_code = 200;
$success_message = __( 'Got all contact orders', 'wp-marketing-automations-pro' );
return $this->success_response( $response, $success_message );
}
public function get_contact_activity_records( $cid, $order_ids, $funnel_id = '' ) {
if ( ! is_array( $order_ids ) || count( $order_ids ) === 0 ) {
return [];
}
$all_orders = [];
$sales_data = [];
$order_statuses = wc_get_order_statuses();
foreach ( $order_ids as $order_id ) {
$conv_order = $tags = $categories = [];
$product_data = $this->get_single_order_info( $order_id, $cid );
$conv_data = apply_filters( 'wffn_conversion_tracking_data_activity', [], $cid, $order_id );
$conv_order = array_merge( $conv_order, $conv_data );
$conv_order['products'] = $product_data['products'];
/** Get Products Categories name */
if ( empty( $product_data['cat_ids'] ) ) {
$categories = array_map( function ( $term_id ) {
$cat = get_term( absint( $term_id ) );
return $cat instanceof WP_Term ? $cat->name : false;
}, array_unique( $product_data['cat_ids'] ) );
$categories = array_values( array_filter( $categories ) );
}
/** Get Products Tags name */
if ( ! empty( $product_data['tag_ids'] ) ) {
$tags = array_map( function ( $term_id ) {
$tag = get_term( absint( $term_id ) );
return $tag instanceof WP_Term ? $tag->name : false;
}, array_unique( $product_data['tag_ids'] ) );
$tags = array_values( array_filter( $tags ) );
}
$conv_order['tags'] = $tags;
$conv_order['categories'] = $categories;
$sales_data = array_merge( $sales_data, $product_data['timeline_data'] );
$funnel_ids = array_unique( array_column( $conv_order['products'], 'fid' ) );
$conv_order['order_id'] = $order_id;
if ( isset( $conv_order['overview'] ) ) {
unset( $conv_order['overview'] );
}
if ( isset( $conv_order['conversion'] ) ) {
$conv_order['conversion']['funnel_link'] = '';
$conv_order['conversion']['funnel_title'] = '';
$s_funnel_id = ! empty( $funnel_id ) ? $funnel_id : ( ( is_array( $funnel_ids ) && count( $funnel_ids ) > 0 ) ? $funnel_ids[0] : 0 );
$conv_order['conversion']['funnel_id'] = $s_funnel_id;
$get_funnel = new WFFN_Funnel( $s_funnel_id );
if ( $get_funnel instanceof WFFN_Funnel && 0 !== $get_funnel->get_id() ) {
$funnel_link = ( $get_funnel->get_id() === WFFN_Common::get_store_checkout_id() ) ? admin_url( "admin.php?page=bwf&path=/store-checkout" ) : admin_url( "admin.php?page=bwf&path=/funnels/$s_funnel_id" );
$conv_order['conversion']['funnel_link'] = $funnel_link;
$conv_order['conversion']['funnel_title'] = $get_funnel->get_title();
}
}
$conv_order['customer_info'] = array(
'email' => '',
'phone' => '',
'billing_address' => '',
'shipping_address' => '',
);
$conv_order['coupons'] = [];
if ( ! empty( $order_id ) && absint( $order_id ) > 0 && function_exists( 'wc_get_order' ) ) {
$order_data = wc_get_order( $order_id );
if ( $order_data instanceof WC_Order ) {
$conv_order['coupons'] = $order_data->get_coupon_codes();
$conv_order['customer_info'] = [
'email' => $order_data->get_billing_email(),
'phone' => $order_data->get_billing_phone(),
'billing_address' => wp_kses_post( $order_data->get_formatted_billing_address() ),
'shipping_address' => wp_kses_post( $order_data->get_formatted_shipping_address() ),
'purchased_on' => ! empty( $order_data->get_date_created() ) ? $order_data->get_date_created()->date( 'Y-m-d H:i:s' ) : $product_data['date_added'],
'payment_method' => $order_data->get_payment_method_title(),
];
$conv_order['status'] = [
'label' => isset( $order_statuses[ 'wc-' . $order_data->get_status() ] ) ? $order_statuses[ 'wc-' . $order_data->get_status() ] : $order_data->get_status(),
'value' => 'wc-' . $order_data->get_status()
];
}
}
$all_orders[] = $conv_order;
}
return $all_orders;
}
public function get_single_order_info( $order_id, $cid = '' ) {
$timeline_data = [];
$products = [];
$data = [
'products' => $products,
'date_added' => '',
'timeline_data' => $timeline_data,
'tag_ids' => [],
'cat_ids' => [],
];
$order = wc_get_order( $order_id );
if ( ! $order instanceof \WC_Order ) {
return $data;
}
$items = $order->get_items();
$subtotal = 0;
$i = 0;
foreach ( $items as $item ) {
$product = new stdClass();
$key = 'checkout';
$product->date = '';
/**
* create data for show timeline data
*/
if ( class_exists( 'WFACP_Contacts_Analytics' ) && ! empty( $cid ) && 0 === $i ) {
/*
* show checkout in timeline only one time per order
*/
$aero_obj = WFACP_Contacts_Analytics::get_instance();
$checkout_records = $aero_obj->get_contacts_revenue_records( $cid, $order_id );
if ( is_array( $checkout_records ) && ! isset( $checkout_records['db_error'] ) && isset( $checkout_records[0] ) ) {
$data['date_added'] = $checkout_records[0]->date;
$data['timeline_data'][] = $checkout_records[0];
}
}
if ( 'yes' === $item->get_meta( '_upstroke_purchase' ) ) {
$key = 'upsell';
if ( class_exists( 'WFOCU_Contacts_Analytics' ) ) {
$upsell_obj = WFOCU_Contacts_Analytics::get_instance();
$upsell_records = $upsell_obj->get_contacts_revenue_records( $cid, $order_id );
if ( is_array( $upsell_records ) && ! isset( $upsell_records['db_error'] ) && isset( $upsell_records[0] ) ) {
$data['date_added'] = empty( $data['date_added'] ) ? $upsell_records[0]->date : $data['date_added'];
$data['timeline_data'][] = $upsell_records[0];
}
}
}
if ( 'yes' === $item->get_meta( '_bump_purchase' ) ) {
$key = 'bump';
if ( class_exists( 'WFOB_Contacts_Analytics' ) ) {
$bump_obj = WFOB_Contacts_Analytics::get_instance();
$bump_records = $bump_obj->get_contacts_revenue_records( $cid, $order_id );
if ( is_array( $bump_records ) && ! isset( $bump_records['db_error'] ) && isset( $bump_records[0] ) ) {
$data['date_added'] = empty( $data['date_added'] ) ? $bump_records[0]->date : $data['date_added'];
$data['timeline_data'][] = $bump_records[0];
}
}
}
$sub_total = $item->get_subtotal();
$product->name = $item->get_name();
$product->revenue = $sub_total;
$product->type = $key;
$data['products'][] = $product;
$subtotal += $sub_total;
$i ++;
/** Fetch tags and categories */
$item_data = $item->get_data();
$wc_product = intval( $item_data['product_id'] ) ? wc_get_product( $item_data['product_id'] ) : '';
$tag_ids = $wc_product instanceof WC_Product ? $wc_product->get_tag_ids() : [];
$cat_ids = $wc_product instanceof WC_Product ? $wc_product->get_category_ids() : [];
$data['tag_ids'] = array_merge( $data['tag_ids'], $tag_ids );
$data['cat_ids'] = array_merge( $data['cat_ids'], $cat_ids );
}
$order_total = $order->get_total();
$total_discount = $order->get_total_discount();
$remaining_amount = $order_total - ( $subtotal - $total_discount );
if ( $remaining_amount > 0 ) {
$shipping_tax = new stdClass();
$shipping_tax->name = __( 'Including shipping and taxes ,other costs', 'funnel-builder' );
$shipping_tax->revenue = $remaining_amount;
$shipping_tax->type = 'shipping';
$data['products'][] = $shipping_tax;
}
if ( $order->get_total_discount() > 0 ) {
$discount = new stdClass();
$discount->name = __( 'Discount', 'funnel-builder' );
$discount->revenue = $order->get_total_discount();
$discount->type = 'discount';
$data['products'][] = $discount;
}
return $data;
}
public function get_result_total_count() {
return $this->total_count;
}
}
if ( class_exists( 'woocommerce' ) ) {
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Orders' );
}

View File

@@ -0,0 +1,79 @@
<?php
class BWFCRM_API_Get_Contact_Subscriptions extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public $contact;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/subscriptions';
$this->pagination->limit = 10;
$this->pagination->offset = 0;
}
public function default_args_values() {
return array(
'contact_id' => 0,
);
}
public function process_api_call() {
/** checking if id or email present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
/** contact id missing than return */
if ( empty( $contact_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact id is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$limit = $this->get_sanitized_arg( 'limit', 'text_field' );
$limit = ! empty( $limit ) ? $limit : $this->pagination->limit;
$offset = $this->get_sanitized_arg( 'offset', 'text_field' );
$offset = ! empty( $offset ) ? $offset : 0;
$contact_orders = $contact->get_subscriptions_array( $offset, $limit );
if ( empty( $contact_orders['subscriptions'] ) ) {
$this->response_code = 200;
return $this->success_response( [], __( 'No contact subscriptions found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$total_contact_subscriptions = $contact->get_total_subscriptions();
$this->total_count = empty( $total_contact_subscriptions ) ? 0 : $total_contact_subscriptions;
$this->response_code = 200;
$success_message = __( 'Got all contact subscriptions', 'wp-marketing-automations-pro' );
return $this->success_response( $contact_orders, $success_message );
}
public function get_result_total_count() {
return $this->total_count;
}
}
if ( class_exists( 'WC_Subscriptions' ) ) {
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Subscriptions' );
}

View File

@@ -0,0 +1,77 @@
<?php
class BWFCRM_API_Get_Contact_Tags extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/tags';
$this->pagination->offset = 0;
$this->pagination->limit = 30;
$this->request_args = array(
'search' => array(
'description' => __( 'Search from tag name', 'wp-marketing-automations-pro' ),
'type' => 'string',
),
'offset' => array(
'description' => __( 'Tags list Offset', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'limit' => array(
'description' => __( 'Per page limit', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
public function default_args_values() {
return array(
'contact_id' => '',
);
}
public function process_api_call() {
/** checking if search present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
$search = $this->get_sanitized_arg( 'search', 'text_field' );
$offset = $this->get_sanitized_arg( 'offset', 'text_field' );
$limit = $this->get_sanitized_arg( 'limit', 'text_field' );
$offset = empty( $offset ) ? $this->pagination->offset : $offset;
$limit = empty( $limit ) ? $this->pagination->limit : $limit;
if ( empty( $contact_id ) ) {
return $this->error_response( __( 'Contact ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with given id #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
// $contact_terms = BWFCRM_Model_Contact_Terms::get_contact_terms( $contact->get_id(), $offset, $limit, $search, 0 );
$contact_terms = $contact->get_all_tags();
$this->response_code = 200;
return $this->success_response( $contact_terms );
}
public function get_result_total_count() {
return $this->total_count;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Tags' );

View File

@@ -0,0 +1,62 @@
<?php
class BWFCRM_API_Get_Contact_Tasks extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/tasks';
}
public function default_args_values() {
return array(
'contact_id' => 0,
);
}
public function process_api_call() {
/** checking if id or email present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
/** contact id missing than return */
if ( empty( $contact_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with given id #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$contact_tasks = $contact->get_tasks_array();
if ( empty( $contact_tasks ) ) {
$this->response_code = 404;
return $this->error_response( __( 'No tasks available for the contact', 'wp-marketing-automations-pro' ) );
}
$this->response_code = 200;
$success_message = __( 'Got all contact tasks', 'wp-marketing-automations-pro' );
return $this->success_response( $contact_tasks, $success_message );
}
}
if ( function_exists( 'BWFAN_Core' ) ) {
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Tasks' );
}

View File

@@ -0,0 +1,49 @@
<?php
class BWFCRM_API_Get_Contact extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $contact;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)';
$this->request_args = array(
'contact_id' => array(
'description' => __( 'Contact ID to retrieve', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
public function default_args_values() {
return array(
'contact_id' => 0,
);
}
public function process_api_call() {
/** checking if id or email present in params **/
$id = $this->get_sanitized_arg( 'contact_id', 'key' );
$contact = new BWFCRM_Contact( $id );
if ( $contact->is_contact_exists() ) {
return $this->success_response( $contact->get_array( false, true, true, true, true ) );
} else {
$this->response_code = 404;
return $this->error_response( __( "No contact found with given id #", 'wp-marketing-automations-pro' ) . $id );
}
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact' );

View File

@@ -0,0 +1,151 @@
<?php
class BWFCRM_API_Get_Contacts extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public $count_data = [];
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts';
$this->pagination->offset = 0;
$this->pagination->limit = 10;
$this->request_args = array(
'search' => array(
'description' => __( 'Search from email, first_name or last_name', 'wp-marketing-automations-pro' ),
'type' => 'string',
),
'offset' => array(
'description' => __( 'Contacts list Offset', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'limit' => array(
'description' => __( 'Per page limit', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'get_wc' => array(
'description' => __( 'Get WC Data as well', 'wp-marketing-automations-pro' ),
'type' => 'boolean',
),
'grab_totals' => array(
'description' => __( 'Grab total contact count as well', 'wp-marketing-automations-pro' ),
'type' => 'boolean',
),
'start_indexing' => array(
'description' => __( 'Start Indexing of Contacts in case indexing is pending', 'wp-marketing-automations-pro' ),
'type' => 'boolean',
),
);
}
public function default_args_values() {
return array(
'search' => '',
'filters' => array(),
);
}
public function process_api_call() {
$additional_info = array(
'grab_totals' => $this->get_sanitized_arg( 'grab_totals', 'bool' ),
'only_count' => $this->get_sanitized_arg( 'only_count', 'bool' ),
'fetch_base' => $this->get_sanitized_arg( 'fetch_base', 'text_field' ),
'exclude_unsubs' => $this->get_sanitized_arg( 'exclude_unsubs', 'bool' ),
'exclude_unsubs_lists' => $this->get_sanitized_arg( 'exclude_unsubs_lists', 'bool' ),
'grab_custom_fields' => $this->get_sanitized_arg( 'grab_custom_fields', 'bool' ),
'include_soft_bounce' => $this->get_sanitized_arg( 'includeSoftBounce', 'bool' ), // specific for broadcast
'include_unverified' => $this->get_sanitized_arg( 'includeUnverified', 'bool' ),
'include_unsubscribe' => $this->get_sanitized_arg( 'include_unsubs', 'bool' ),
'include_ids' => isset( $this->args[ 'include_ids' ] ) ? $this->args[ 'include_ids' ] : [],
);
/** Un-Open contacts case */
$un_open_broadcast = $this->get_sanitized_arg( 'unopen_broadcast', 'key' );
if ( ! empty( $un_open_broadcast ) ) {
return $this->get_unopened_broadcast_contacts( $un_open_broadcast, $additional_info );
}
$order = $this->get_sanitized_arg( 'order', 'text_field' );
$order_by = $this->get_sanitized_arg( 'order_by', 'text_field' );
if ( ! empty( $order ) && ! empty( $order_by ) ) {
$additional_info['order'] = $order;
$additional_info['order_by'] = $order_by;
}
if ( class_exists( 'WooCommerce' ) ) {
$additional_info['customer_data'] = $this->get_sanitized_arg( 'get_wc', 'bool' );
}
/** checking if search present in params */
$search = $this->get_sanitized_arg( 'search', 'text_field' );
$filters_collection = empty( $this->args['filters'] ) ? array() : $this->args['filters'];
if ( false === $additional_info['exclude_unsubs'] ) {
$additional_info['exclude_unsubs'] = apply_filters( 'bwfan_force_exclude_unsubscribe_contact', false );
}
$contacts = BWFCRM_Contact::get_contacts( $search, $this->pagination->offset, $this->pagination->limit, $filters_collection, $additional_info );
if ( ! is_array( $contacts ) ) {
$this->response_code = 500;
return $this->error_response( is_string( $contacts ) ? $contacts : __( 'Unknown error occurred', 'wp-marketing-automations-pro' ) );
}
if ( isset( $contacts['total_count'] ) ) {
$this->total_count = absint( $contacts['total_count'] );
}
if ( ! isset( $contacts['contacts'] ) || empty( $contacts['contacts'] ) ) {
return $this->success_response( array() );
}
$this->response_code = 200;
return $this->success_response( $contacts['contacts'] );
}
public function get_result_total_count() {
return $this->total_count;
}
public function get_result_count_data() {
return $this->count_data;
}
public function get_unopened_broadcast_contacts( $broadcast_id, $additional_info ) {
$additional_info['offset'] = $this->pagination->offset;
$additional_info['limit'] = $this->pagination->limit;
$contacts = BWFCRM_Core()->campaigns->get_unopen_broadcast_contacts( absint( $broadcast_id ), $additional_info, );
if ( ! is_array( $contacts ) ) {
$this->response_code = 500;
return $this->error_response( is_string( $contacts ) ? $contacts : __( 'Unknown error occurred', 'wp-marketing-automations-pro' ) );
}
if ( isset( $contacts['total_count'] ) ) {
$this->total_count = absint( $contacts['total_count'] );
}
if ( ! isset( $contacts['contacts'] ) || empty( $contacts['contacts'] ) ) {
return $this->success_response( array() );
}
$this->response_code = 200;
return $this->success_response( $contacts['contacts'] );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contacts' );

View File

@@ -0,0 +1,75 @@
<?php
class BWFCRM_API_Get_Indexing_Status extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/indexing';
}
public function default_args_values() {
return array(
'search' => '',
'filters' => array(),
);
}
public function process_api_call() {
/** Indexing status */
$status = BWFCRM_WC_Importer::get_indexing_status();
if ( ! empty( $status ) || BWFCRM_WC_Importer::$INDEXING_COMPLETE === $status ) {
return $this->success_response( array(
'indexing_required' => true,
'indexing_status' => $status
) );
}
/** checking if search present in params **/
$search = $this->get_sanitized_arg( 'search', 'text_field' );
$filters_collection = empty( $this->args['filters'] ) ? array() : $this->args['filters'];
$get_wc_data = $this->get_sanitized_arg( 'get_wc', 'bool' );
$grab_totals = $this->get_sanitized_arg( 'grab_totals', 'bool' );
$additional_info = class_exists( 'WooCommerce' ) ? [
'customer_data' => $get_wc_data,
'grab_totals' => $grab_totals
] : [];
$filters = $this->get_sanitized_arg( '', 'text_field', $filters_collection );
$contacts = BWFCRM_Contact::get_contacts( $search, $this->pagination->offset, $this->pagination->limit, $filters, $additional_info );
if ( ! is_array( $contacts ) ) {
$this->response_code = 500;
return $this->error_response( is_string( $contacts ) ? $contacts : __( 'Unknown Error', 'wp-marketing-automations-pro' ) );
}
if ( ! isset( $contacts['contacts'] ) || empty( $contacts['contacts'] ) ) {
return $this->success_response( [] );
}
if ( isset( $contacts['total_count'] ) ) {
$this->total_count = absint( $contacts['total_count'] );
}
$this->response_code = 200;
return $this->success_response( $contacts['contacts'] );
}
public function get_result_total_count() {
return $this->total_count;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Indexing_Status' );

View File

@@ -0,0 +1,77 @@
<?php
class BWFCRM_API_Remove_Lists extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::DELETABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/lists';
}
public function default_args_values() {
return array(
'contact_id' => 0,
'lists' => '',
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
$lists = $this->get_sanitized_arg( '', 'key', $this->args['lists'] );
/** No Lists Provided */
if ( empty( $lists ) ) {
$response = __( 'No Lists provided', 'wp-marketing-automations-pro' );
$this->response_code = 404;
return $this->error_response( $response );
}
/** No Contact found */
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with given id #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
/** Check if provided lists ids are valid numbers */
$lists = array_map( 'absint', $lists );
$lists = array_filter( $lists );
if ( empty( absint( $lists ) ) ) {
$this->response_code = 400;
return $this->error_response( __( 'No list found', 'wp-marketing-automations-pro' ) );
}
$removed_lists = $contact->remove_lists( $lists );
$contact->save();
$lists_not_removed = array_diff( $lists, $removed_lists );
if ( count( $lists_not_removed ) === count( $lists ) ) {
$response = __( 'Unable to remove the list', 'wp-marketing-automations-pro' );
$this->response_code = 500;
return $this->error_response( $response );
}
$result = [];
$response = __( 'Lists Unassigned', 'wp-marketing-automations-pro' );
if ( ! empty( $lists_not_removed ) ) {
$removed_lists_text = implode( ', ', $removed_lists );
$response = __( 'Some lists removed: ' . $removed_lists_text, 'wp-marketing-automations-pro' );
}
$result['last_modified'] = $contact->contact->get_last_modified();
return $this->success_response( $result, $response );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Remove_Lists' );

View File

@@ -0,0 +1,96 @@
<?php
class BWFCRM_API_Remove_Tags extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::DELETABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/tags';
$this->request_args = array(
'tags' => array(
'description' => __( 'Tags to remove', 'wp-marketing-automations-pro' ),
'type' => 'array',
),
);
}
public function default_args_values() {
return array(
'contact_id' => 0,
'tags' => '',
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
$tags = $this->get_sanitized_arg( '', 'key', $this->args['tags'] );
/** No Tags Provided */
if ( empty( $tags ) ) {
$response = __( 'No Tags provided', 'wp-marketing-automations-pro' );
$this->response_code = 404;
return $this->error_response( $response );
}
/** No Contact found */
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with given ID #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
/** If provided tags not array */
if ( ! is_array( $tags ) ) {
if ( is_string( $tags ) && false !== strpos( $tags, ',' ) ) {
$tags = explode( ',', $tags );
} else if ( empty( absint( $tags ) ) ) {
$this->response_code = 400;
return $this->error_response( __( 'No tag found', 'wp-marketing-automations-pro' ) );
} else {
$tags = array( absint( $tags ) );
}
}
/** Check if provided tag ids are valid numbers */
$tags = array_map( 'absint', $tags );
$tags = array_filter( $tags );
if ( empty( absint( $tags ) ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Invalid Tags Provided', 'wp-marketing-automations-pro' ) );
}
$removed_tags = $contact->remove_tags( $tags );
$contact->save();
$tags_not_removed = array_diff( $tags, $removed_tags );
if ( count( $tags_not_removed ) === count( $tags ) ) {
$response = __( 'Unable to remove any tag', 'wp-marketing-automations-pro' );
$this->response_code = 500;
return $this->error_response( $response );
}
$result = [];
$response = __( 'Tag removed', 'wp-marketing-automations-pro' );
if ( ! empty( $tags_not_removed ) ) {
$removed_tags_text = implode( ', ', $removed_tags );
$response = __( 'Some tags removed: ' . $removed_tags_text, 'wp-marketing-automations-pro' );
}
$result['last_modified'] = $contact->contact->get_last_modified();
return $this->success_response( $result, $response );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Remove_Tags' );

View File

@@ -0,0 +1,279 @@
<?php
class BWFCRM_API_SendMessage extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/sendmessage';
$this->request_args = array(
'contact_id' => array(
'description' => __( 'Contact ID to send message', 'wp-marketing-automations-pro' ),
'type' => 'integer',
)
);
}
public function default_args_values() {
return array(
'contact_id' => '',
'title' => '',
'message' => '',
'type' => 'email'
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
$title = $this->get_sanitized_arg( 'title', 'text_field' );
$message = $this->args['message'];
$type = $this->get_sanitized_arg( 'type', 'text_field' );
$contact = new BWFCRM_Contact( absint( $contact_id ) );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 400;
return $this->error_response( __( 'No contact found with given ID #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
/** Check if contacts status is bounced */
if ( 4 === $contact->get_display_status() ) {
$this->response_code = 400;
return $this->error_response( __( 'Contact status is bounced', 'wp-marketing-automations-pro' ) );
}
if ( 'email' === $type && empty( $title ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Title is mandatory', 'wp-marketing-automations-pro' ) );
}
if ( empty( $message ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Message is mandatory', 'wp-marketing-automations-pro' ) );
}
$author_id = get_current_user_id();
$mode = BWFAN_Email_Conversations::$MODE_EMAIL;
switch ( $type ) {
case 'sms':
$mode = BWFAN_Email_Conversations::$MODE_SMS;
break;
case 'whatsapp':
$mode = BWFAN_Email_Conversations::$MODE_WHATSAPP;
break;
}
BWFAN_Merge_Tag_Loader::set_data( array(
'contact_id' => $contact->get_id(),
'contact_mode' => $mode
) );
$message = BWFAN_Common::decode_merge_tags( ( 1 === $mode ? wpautop( $message ) : $message ) );
$template = [
'subject' => ( empty( $title ) ? '' : $title ),
'template' => ( empty( $message ) ? '' : $message )
];
$conversation = BWFCRM_Core()->conversation->create_campaign_conversation( $contact, 0, 0, $author_id, $mode, true, $template );
if ( empty( $conversation['conversation_id'] ) ) {
return $this->error_response( $conversation );
}
if ( class_exists( 'BWFAN_Message' ) ) {
$message_obj = new BWFAN_Message();
$message_obj->set_message( 0, $conversation['conversation_id'], $title, $message );
$message_obj->save();
}
$conversation['template'] = $message;
$conversation['subject'] = $title;
if ( 'sms' === $type ) {
$sent = $this->send_single_sms( $conversation, $contact );
} else if ( 'whatsapp' === $type ) {
$sent = $this->send_single_whatsapp_message( $conversation, $contact );
} else {
$sent = $this->send_single_email( $title, $conversation, $contact );
}
if ( true === $sent ) {
return $this->success_response( [], __( 'Message sent', 'wp-marketing-automations-pro' ) );
}
return $this->error_response( $sent, null, 500 );
}
/**
* @param $title
* @param $conversation
* @param $contact BWFCRM_Contact
*
* @return string|true|null
*/
public function send_single_email( $title, $conversation, $contact ) {
$conversation_id = $conversation['conversation_id'];
$contact_id = $contact->contact->get_id();
$email_subject = BWFCRM_Core()->conversation->prepare_email_subject( $title, $contact_id );
try {
$email_body = BWFCRM_Core()->conversation->prepare_email_body( $conversation['conversation_id'], $contact_id, $conversation['hash_code'], 'rich', $conversation['template'] );
} catch ( Error $e ) {
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, $e->getMessage() );
return $e->getMessage();
}
if ( is_wp_error( $email_body ) ) {
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, $email_body->get_error_message() );
return $email_body->get_error_message();
}
$to = $contact->contact->get_email();
if ( ! is_email( $to ) ) {
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, __( 'No email found for this contact: ' . $contact_id, 'wp-marketing-automations-pro' ) );
return __( 'No email found for this contact: ' . $contact_id, 'wp-marketing-automations-pro' );
}
$global_email_settings = BWFAN_Common::get_global_settings();
$headers = array(
'MIME-Version: 1.0',
'Content-type: text/html;charset=UTF-8'
);
$from = '';
if ( isset( $global_email_settings['bwfan_email_from_name'] ) && ! empty( $global_email_settings['bwfan_email_from_name'] ) ) {
$from = 'From: ' . $global_email_settings['bwfan_email_from_name'];
}
if ( isset( $global_email_settings['bwfan_email_from'] ) && ! empty( $global_email_settings['bwfan_email_from'] ) ) {
$headers[] = $from . ' <' . $global_email_settings['bwfan_email_from'] . '>';
}
if ( isset( $global_email_settings['bwfan_email_reply_to'] ) && ! empty( $global_email_settings['bwfan_email_reply_to'] ) ) {
$headers[] = 'Reply-To: ' . $global_email_settings['bwfan_email_reply_to'];
}
/** Set unsubscribe link in header */
$unsubscribe_link = BWFAN_PRO_Common::get_unsubscribe_link( [ 'uid' => $contact->contact->get_uid() ] );
if ( ! empty( $unsubscribe_link ) ) {
$headers[] = "List-Unsubscribe: <$unsubscribe_link>";
$headers[] = "List-Unsubscribe-Post: List-Unsubscribe=One-Click";
}
BWFCRM_Common::bwf_remove_filter_before_wp_mail();
$headers = apply_filters( 'bwfan_email_headers', $headers );
BWFCRM_Common::$captured_email_failed_message = null;
$result = wp_mail( $to, $email_subject, $email_body, $headers );
if ( true === $result ) {
/** Save the time of last sent engagement **/
$data = array( 'cid' => $contact_id );
BWFCRM_Conversation::save_last_sent_engagement( $data );
BWFCRM_Core()->conversation->update_conversation_status( $conversation_id, BWFAN_Email_Conversations::$STATUS_SEND );
} else {
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, __( 'Email not sent', 'wp-marketing-automations-pro' ) );
return __( 'Email not sent', 'wp-marketing-automations-pro' );
}
return $result;
}
public function send_single_sms( $conversation, $contact ) {
$conversation_id = $conversation['conversation_id'];
$contact_id = $contact->contact->get_id();
$sms_body = BWFCRM_Core()->conversation->prepare_sms_body( $conversation['conversation_id'], $contact_id, $conversation['hash_code'], $conversation['template'] );
if ( is_wp_error( $sms_body ) ) {
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, $sms_body->get_error_message() );
return $sms_body->get_error_message();
}
$to = BWFAN_PRO_Common::get_contact_full_number( $contact->contact );
if ( empty( $to ) ) {
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, __( 'No phone number found for this contact: ' . $contact_id, 'wp-marketing-automations-pro' ) );
return __( 'No phone number found for this contact: ' . $contact_id, 'wp-marketing-automations-pro' );
}
$send_sms_result = BWFCRM_Common::send_sms( array(
'to' => $to,
'body' => $sms_body,
) );
if ( $send_sms_result instanceof WP_Error ) {
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, $send_sms_result->get_error_message() );
return $send_sms_result->get_error_message();
}
/** Save the date of last sent engagement **/
$data = array( 'cid' => $contact_id );
BWFCRM_Conversation::save_last_sent_engagement( $data );
BWFCRM_Core()->conversation->update_conversation_status( $conversation_id, BWFAN_Email_Conversations::$STATUS_SEND );
return true;
}
public function send_single_whatsapp_message( $conversation, $contact ) {
$conversation_id = $conversation['conversation_id'];
$contact_id = $contact->contact->get_id();
$message_body = BWFCRM_Core()->conversation->prepare_sms_body( $conversation['conversation_id'], $contact_id, $conversation['hash_code'], $conversation['template'] );
if ( is_wp_error( $message_body ) ) {
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, $message_body->get_error_message() );
return $message_body->get_error_message();
}
$to = BWFAN_PRO_Common::get_contact_full_number( $contact->contact );
if ( empty( $to ) ) {
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, __( 'No phone number found for this contact: ' . $contact_id, 'wp-marketing-automations-pro' ) );
return __( 'No phone number found for this contact: ' . $contact_id, 'wp-marketing-automations-pro' );
}
$response = BWFCRM_Core()->conversation->send_whatsapp_message( $to, array(
array(
'type' => 'text',
'data' => $message_body,
)
) );
if ( $response['status'] == true ) {
/** Save the time of last sent engagement **/
$data = array( 'cid' => $contact_id );
BWFCRM_Conversation::save_last_sent_engagement( $data );
BWFCRM_Core()->conversation->update_conversation_status( $conversation_id, BWFAN_Email_Conversations::$STATUS_SEND );
return true;
}
$error_message = isset( $response['msg'] ) && ! empty( $response['msg'] ) ? $response['msg'] : 'Unable to send message';
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, $error_message );
return $error_message;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_SendMessage' );

View File

@@ -0,0 +1,71 @@
<?php
class BWFCRM_API_Update_Contact_Note extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::EDITABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/notes/(?P<note_id>[\\d]+)';
}
public function default_args_values() {
return array(
'contact_id' => 0,
'note_id' => 0,
'notes' => array(),
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
if ( empty( $contact_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$note_id = $this->get_sanitized_arg( 'note_id', 'key' );
if ( empty( $note_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Note ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$notes = $this->args['notes'];
if ( empty( $notes ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Notes are mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$note_updated = $contact->update_contact_note( $notes, $note_id );
if ( false === $note_updated || is_wp_error( $note_updated ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Unable to update note of contact', 'wp-marketing-automations-pro' ) );
}
$this->response_code = 200;
return $this->success_response( [], __( 'Contact note updated', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Update_Contact_Note' );

View File

@@ -0,0 +1,124 @@
<?php
class BWFCRM_API_Update_Contact extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::EDITABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)';
}
public function default_args_values() {
return array(
'contact_id' => 0,
'first_name' => '',
'last_name' => '',
'meta' => [],
'lists' => [],
'tags' => [],
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
if ( empty( $contact_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$contact_basic_info = array();
$contact_first_name = $this->get_sanitized_arg( 'first_name', 'text_field' );
$contact_last_name = $this->get_sanitized_arg( 'last_name', 'text_field' );
$contact_email = $this->get_sanitized_arg( 'email', 'text_field' );
if ( ! empty( $contact_first_name ) ) {
$contact_basic_info['first_name'] = $contact_first_name;
}
if ( ! empty( $contact_last_name ) ) {
$contact_basic_info['last_name'] = $contact_last_name;
}
if ( ! empty( $contact_email ) ) {
$contact_basic_info['email'] = $contact_email;
}
if ( ! empty( $this->args['meta'] ) && is_array( $this->args['meta'] ) ) {
$contact_basic_info['meta'] = $this->args['meta'];
}
if ( empty( $contact_basic_info ) && empty( $this->args['lists'] ) && empty( $this->args['tags'] ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Unable to update contact as update data missing', 'wp-marketing-automations-pro' ) );
}
if ( ! empty( $contact_basic_info ) ) {
$contact_basic_info['id'] = $contact_id;
/** @var $update_contact_details */
$contact_field_updated = $contact->update( $contact_basic_info );
}
if ( ! empty( $this->args['lists'] ) && is_array( $this->args['lists'] ) ) {
$lists = $this->args['lists'];
$added_lists = $contact->set_lists( $lists );
$lists_added = array_map( function ( $list ) {
return $list->get_array();
}, $added_lists );
}
if ( ! empty( $this->args['tags'] ) && is_array( $this->args['tags'] ) ) {
$tags = $this->args['tags'];
$added_tags = $contact->set_tags( $tags );
$tags_added = array_map( function ( $tags ) {
return $tags->get_array();
}, $added_tags );
}
$contact->save();
if ( false === $contact_field_updated && empty( $added_lists ) && empty( $added_tags ) ) {
$this->response_code = 200;
return $this->error_response( __( 'Unable to update contact fields', 'wp-marketing-automations-pro' ) );
}
$result = [];
if ( ! empty( $contact_field_updated ) ) {
$result['contact'] = $contact_field_updated;
}
if ( ! empty( $lists_added ) ) {
$result['lists'] = $lists_added;
}
if ( ! empty( $tags_added ) ) {
$result['tags'] = $tags_added;
}
return $this->success_response( $result, __( 'Contact updated', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Update_Contact' );

View File

@@ -0,0 +1,60 @@
<?php
class BWFCRM_API_Get_Contact_Conversation extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $contact;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/engagement/(?P<engagement_id>[\\d]+)';
$this->request_args = array(
'contact_id' => array(
'description' => __( 'Contact ID', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'engagement_id' => array(
'description' => __( 'Engagement ID', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
public function default_args_values() {
return array(
'contact_id' => 0,
);
}
public function process_api_call() {
/** checking if id or email present in params */
$id = $this->get_sanitized_arg( 'contact_id', 'key' );
$engagement_id = $this->get_sanitized_arg( 'engagement_id', 'key' );
if ( ! class_exists( 'BWFAN_Email_Conversations' ) || ! isset( BWFAN_Core()->conversations ) || ! BWFAN_Core()->conversations instanceof BWFAN_Email_Conversations ) {
return $this->error_response( __( 'Unable to find Funnelkit Automations message tracking module', 'wp-marketing-automations-pro' ), null, 500 );
}
$this->contact = new BWFCRM_Contact( absint( $id ) );
if ( ! $this->contact instanceof BWFCRM_Contact || ! $this->contact->is_contact_exists() ) {
return $this->error_response( __( 'No contact found with given ID #' . $id, 'wp-marketing-automations-pro' ), null, 500 );
}
$conversation = $this->contact->get_conversation_email( $engagement_id );
if ( $conversation instanceof WP_Error || ( is_array( $conversation ) && isset( $conversation['error'] ) ) ) {
return $this->error_response( ! is_array( $conversation ) ? __( 'Unknown error occurred', 'wp-marketing-automations-pro' ) : $conversation['error'], $conversation instanceof WP_Error ? $conversation : null, 500 );
}
return $this->success_response( $conversation );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Conversation' );

View File

@@ -0,0 +1,65 @@
<?php
class BWFCRM_API_Get_Contact_Conversations extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $contact;
public $mode = null;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/engagements';
$this->request_args = array(
'contact_id' => array(
'description' => __( 'Contact ID for which engagements to retrieve', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
public function default_args_values() {
return array(
'contact_id' => 0,
'mode' => 0,
);
}
public function process_api_call() {
/** checking if id or email present in params **/
$id = $this->get_sanitized_arg( 'contact_id', 'key' );
$this->mode = $this->get_sanitized_arg( 'mode', 'key' );
$limit = ! empty( $this->get_sanitized_arg( 'limit', 'text_field' ) ) ? $this->get_sanitized_arg( 'limit', 'text_field' ) : 25;
$offset = ! empty( $this->get_sanitized_arg( 'offset', 'text_field' ) ) ? $this->get_sanitized_arg( 'offset', 'text_field' ) : 0;
if ( ! class_exists( 'BWFAN_Email_Conversations' ) || ! isset( BWFAN_Core()->conversations ) || ! BWFAN_Core()->conversations instanceof BWFAN_Email_Conversations ) {
return $this->error_response( __( 'Unable to find conversations module', 'wp-marketing-automations-pro' ), null, 500 );
}
$this->contact = new BWFCRM_Contact( absint( $id ) );
if ( ! $this->contact instanceof BWFCRM_Contact || ! $this->contact->is_contact_exists() ) {
return $this->error_response( __( 'Contact doesn\'t exists', 'wp-marketing-automations-pro' ), null, 500 );
}
$conversation = $this->contact->get_conversations( $this->mode, $offset, $limit );
if ( $conversation instanceof WP_Error ) {
return $this->error_response( '', $conversation, 500 );
}
return $this->success_response( $conversation );
}
public function get_result_total_count() {
return $this->contact instanceof BWFCRM_Contact && $this->contact->is_contact_exists() ? $this->contact->get_conversations_total( $this->mode ) : 0;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Conversations' );