function lms_sub_script() {
wp_enqueue_script( 'script-name', get_stylesheet_directory_uri() .
'/assets/js/ajax.js', array(), '1.0.1', true );
wp_localize_script('script-name', 'ajax_var', array(
'url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('ajax-nonce')
));
}
add_action('wp_ajax_nopriv_lms_submit', 'lms_sub');
add_action('wp_ajax_lms_submit', 'lms_sub');
function lms_sub() {
// Check for nonce security
if ( ! wp_verify_nonce( $_POST['nonce'], 'ajax-nonce' ) ) {
die ();
}
$username = sanitize_text_field(get_option('leadtrackr_username'));
$password = sanitize_text_field(get_option('leadtrackr_password'));
$userpass = $username . ':' . $password;
$title = sanitize_text_field(get_option('leadtrackr_title'));
$client_name = sanitize_text_field(get_option('leadtrackr_client_name'));
$endpoint_url = sanitize_text_field(get_option('leadtrackr_website_url'));
$body = array(
'title' => $title . date("dmYHis"),
'status' => 'publish',
// the below is the id of the taxonomy on LMS dashboard
'website' => array(2),
'acf' => array(
'lead_type' => 'phone',
'first_name' => '',
'email' => '',
'utm_source' => $_POST['source'],
'utm_medium' => $_POST['medium'],
'utm_campaign' => $_POST['campaign'],
'utm_content' => $_POST['content'],
'utm_term' => $_POST['term'],
// below needs to be edited for specific client
'client' => $client_name
)
);
$response = wp_remote_post( $endpoint_url, array('headers' => array(
'Authorization' => 'Basic ' . base64_encode( $userpass ),
'Content-Type' => 'application/json'
), 'body' => json_encode($body) ) );
if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
return $error_message;
} else {
return $response;
}
}
Creative Archives - Them Advertising
Skip to content
Bringing it home with a digital campaign for V.I.P.
A pasta-tively brilliant product relaunch
A brand refresh for a leading NFP organisation
Someone say free beer?
Stepping up to the plate with a creative campaign
A masterclass in building an educational brand
A bloomin’ excellent summer campaign
A fundraising campaign worthy of ap-paws
Shattering shelter pet stereotypes
Acing a brand awareness campaign
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it. Ok No Privacy policy