'error', 'message' => __( 'Connection is not specified !', 'thrive-dash' ), ) ) ); } if ( empty( $list_id ) ) { exit( json_encode( array( 'status' => 'error', 'message' => __( 'Where should I subscribe this user? List is not specified !', 'thrive-dash' ), ) ) ); } if ( empty( $email ) ) { exit( json_encode( array( 'status' => 'error', 'message' => __( 'Email is not specified !', 'thrive-dash' ), ) ) ); } $data = array( 'email' => $email, 'name' => $name, 'phone' => $phone, 'url' => $url, ); if ( $list_id == "asset" ) { $api = Thrive_Dash_List_Manager::connection_instance( $connection_name ); if ( ! $api ) { $response = __( 'Cannot establish API connection', 'thrive-dash' ); } else { $post_data['_asset_group'] = ! empty( $_POST['_asset_group'] ) ? sanitize_text_field( $_POST['_asset_group'] ) : ''; $post_data['email'] = sanitize_email( $_POST['email'] ); if ( isset( $_POST['name'] ) ) { $post_data['name'] = sanitize_text_field( $_POST['name'] ); } $response = true; try { $api->sendEmail( $post_data ); } catch ( Exception $e ) { $response = $e->getMessage(); } } } else { $response = tve_api_add_subscriber( $connection_name, $list_id, $data, false ); } if ( $response !== true ) { exit( json_encode( array( 'status' => 'error', 'message' => $response, ) ) ); } if ( ! empty( $log_id ) ) { global $wpdb; $delete_result = $wpdb->delete( $wpdb->prefix . 'tcb_api_error_log', array( 'id' => $log_id ), array( '%d' ) ); if ( $delete_result === false ) { exit( json_encode( array( 'status' => 'error', 'message' => __( "Subscription was made with success but we could not delete the log from database !", 'thrive-dash' ), ) ) ); } } exit( json_encode( array( 'status' => 'success', 'message' => __( 'Subscription was made with success !', 'thrive-dash' ), ) ) ); } /** * AJAX call handler to delete API's logs */ function tve_dash_api_delete_log() { check_ajax_referer( 'tve-dash' ); if ( ! current_user_can( TVE_DASH_CAPABILITY ) ) { wp_die( '' ); } $log_id = ! empty( $_POST['log_id'] ) ? intval( $_POST['log_id'] ) : null; if ( empty( $log_id ) ) { exit( json_encode( array( 'status' => 'error', 'message' => __( "Log ID is not valid !", 'thrive-dash' ), ) ) ); } global $wpdb; $delete_result = $wpdb->delete( $wpdb->prefix . 'tcb_api_error_log', array( 'id' => $log_id ), array( '%d' ) ); if ( $delete_result === false ) { exit( json_encode( array( 'status' => 'error', 'message' => sprintf( __( "An error occurred: %s", 'thrive-dash' ), $wpdb->last_error ), ) ) ); } if ( $delete_result === 0 ) { exit( json_encode( array( 'status' => 'error', 'message' => sprintf( __( "The log with ID: %s could not be found !", 'thrive-dash' ), $log_id ), ) ) ); } exit( json_encode( array( 'status' => 'success', 'message' => sprintf( __( "API Log with ID: %s has been deleted with success !", 'thrive-dash' ), $log_id ), ) ) ); } if ( ! class_exists( 'Thrive_List_Manager' ) ) { class Thrive_List_Manager extends Thrive_Dash_List_Manager { } } if ( ! class_exists( 'Thrive_List_Connection_Mandrill' ) ) { class Thrive_List_Connection_Mandrill extends Thrive_Dash_List_Connection_Mandrill { } } if ( ! class_exists( 'Thrive_List_Connection_Postmark' ) ) { class Thrive_List_Connection_Postmark extends Thrive_Dash_List_Connection_Postmark { } } if ( ! class_exists( 'Thrive_List_Connection_SparkPost' ) ) { class Thrive_List_Connection_SparkPost extends Thrive_Dash_List_Connection_SparkPost { } } if ( ! class_exists( 'Thrive_List_Connection_Mailgun' ) ) { class Thrive_List_Connection_Mailgun extends Thrive_Dash_List_Connection_Mailgun { } } if ( ! class_exists( 'Thrive_List_Connection_Awsses' ) ) { class Thrive_List_Connection_Awsses extends Thrive_Dash_List_Connection_Awsses { } } if ( ! class_exists( 'Thrive_List_Connection_SendinblueEmail' ) ) { class Thrive_List_Connection_SendinblueEmail extends Thrive_Dash_List_Connection_SendinblueEmail { } }