| Server IP : 192.241.186.36 / Your IP : 216.73.216.164 Web Server : Apache/2.4.29 (Ubuntu) System : Linux webserver7 4.15.0-194-generic #205-Ubuntu SMP Fri Sep 16 19:49:27 UTC 2022 x86_64 User : root ( 0) PHP Version : 7.4.32 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/carsdaddy/wp-content/plugins/cardealer-helper-library/includes/ |
Upload File : |
<?php
/**
* This function use for subscribe user in mailchimp.
*
* @author TeamWP @Potenza Global Solutions
* @package car-dealer-helper/functions
* @version 1.0.0
*/
add_action( 'wp_ajax_mailchimp_singup', 'cdhl_mailchimp_signup_action' );
add_action( 'wp_ajax_nopriv_mailchimp_singup', 'cdhl_mailchimp_signup_action' );
if ( ! function_exists( 'cdhl_mailchimp_signup_action' ) ) {
/**
* Mailchimp signup ajax call.
*
* @return void
*/
function cdhl_mailchimp_signup_action() {
require_once trailingslashit( CDHL_PATH ) . 'includes/lib/mailchimp/Mailchimp.php'; // mailchimp class library.
global $car_dealer_options;
$mailchimp_api_key = isset( $car_dealer_options['mailchimp_api_key'] ) ? $car_dealer_options['mailchimp_api_key'] : '';
$mailchimp_list_id = isset( $car_dealer_options['mailchimp_list_id'] ) ? $car_dealer_options['mailchimp_list_id'] : '';
// INCLUDE DEFAULT MAILCHIMP FILES FINISH.
$apikey = $mailchimp_api_key;
// $list_id : YOUR MAILCHIMP LIST ID - see lists() method.
$list_id = $mailchimp_list_id;
if ( ! isset( $_REQUEST['mailchimp_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['mailchimp_nonce'] ), 'mailchimp_news' ) ) {
esc_html_e( 'Sorry, Something went wrong, Please refresh page and try again.', 'cardealer-helper' );
wp_die();
}
if ( isset( $_REQUEST['news_letter_email'] ) && ! empty( $_REQUEST['news_letter_email'] ) ) {
$email = sanitize_email( wp_unslash( $_REQUEST['news_letter_email'] ) );
if ( is_email( $email ) ) {
// trigger exception in a "try" block.
try {
$mailchimp = new Mailchimp( $apikey );
$post_params = array(
'email' => $email,
'status' => 'subscribed',
);
// Trigger exception in a "try" block.
try {
$result = $mailchimp->lists->subscribe( $list_id, $post_params );
if ( is_array( $result ) && ( isset( $result['email'] ) && ! empty( $result['email'] ) ) && ( isset( $result['euid'] ) && ! empty( $result['euid'] ) ) && ( isset( $result['leid'] ) && ! empty( $result['leid'] ) ) ) {
$msg = esc_html__( 'Successfully Subscribed. Please check confirmation email.', 'cardealer-helper' );
}
} catch ( Exception $e ) {
$msg = $e->getMessage();
}
} catch ( Exception $e ) {
$msg = $e->getMessage();
}
} else {
$msg = esc_html__( 'Please enter a valid email address.', 'cardealer-helper' );
}
} else {
$msg = esc_html__( 'Please enter a valid email address.', 'cardealer-helper' );
}
echo esc_html( $msg );
wp_die();
}
}