Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function acf_forms($post_id)
- {
- if (empty($_POST['acf']) || is_admin()) return;
- $first_name = $_POST['acf']['field_57b7ecfdbe1b0'];
- $last_name = $_POST['acf']['field_57b7ed1dbe1b1'];
- $email = $_POST['acf']['field_57b7ed33be1b2'];
- $language = $_POST['acf']['field_57cdb948c23ad'];
- $user_id = username_exists($email);
- if ($_POST['form_id'] == 'sponsor-application') {
- if (!$user_id and email_exists($email) == false) {
- $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
- $username = $_POST['acf']['field_57afd2f69c880'];
- $userdata = array(
- 'user_login' => $email,
- 'user_email' => $email,
- 'user_url' => $_POST['acf']['field_57ae8dba42529'],
- 'user_pass' => $random_password, // When creating an user, `user_pass` is expected.
- 'user_nicename' => $username,
- 'nickname' => $username,
- 'display_name' => $username,
- 'user_url' => $_POST['acf']['field_57ae8dba42529'],
- 'first_name' => $first_name,
- 'last_name' => $last_name,
- 'description' => $_POST['acf']['field_57a60ce18b0fe'],
- 'role' => 'pending-sponsor'
- );
- $user_id = wp_insert_user($userdata);
- $user = get_userdata($user_id);
- add_user_meta($user_id, 'has_to_be_activated', true);
- wp_clear_auth_cookie();
- wp_set_current_user($user_id);
- wp_set_auth_cookie($user_id);
- update_user_meta('user_'.$user_id, 'billing_first_name', $first_name );
- update_user_meta('user_'.$user_id, 'billing_last_name', $last_name );
- update_field('billing_phone', $_POST['acf']['field_57a60ce18b0f6'], 'user_'.$user_id);
- update_field('business_name', $username, 'user_'.$user_id);
- update_field('user_url', $_POST['acf']['field_57ae8dba42529'], 'user_'.$user_id);
- update_field('description', $_POST['acf']['field_57a60ce18b0fe'], 'user_'.$user_id);
- update_field('location', $_POST['acf']['field_57a60ce18b108'], 'user_'.$user_id);
- var_dump($_POST['acf']['field_5866f9efb321d']->address);
- update_field('industry', $_POST['acf']['field_57b0a6fad1b72'],'user_'.$user_id);
- update_field('user_url', $_POST['acf']['field_57ae8dba42529'],'user_'.$user_id);
- update_field('user_email', $email, 'user_'.$user_id);
- update_field('hours', $_POST['acf']['field_57a60d3084f7c'], 'user_'.$user_id);
- update_field('logo', $_POST['acf']['field_57a60fdd0a024'], 'user_'.$user_id);
- update_field('facebook', $_POST['acf']['field_57b0af5144407'], 'user_'.$user_id);
- update_field('language', $language, 'user_'.$user_id);
- $subject = 'Thank You for Application';
- $message = get_field('field_5802c3820ce8d', 'options') . "\r\n\r\n";
- $message .= 'First Name: ' . $user->first_name . "\r\n\r\n";
- $message .= 'Last Name: ' . $user->last_name . "\r\n\r\n";
- $message .= '<br/>Email: ' . $user->user_email . "\r\n\r\n";
- $message .= '<br/>Language: ' . get_field('language', $post_id) . "\r\n\r\n";
- $message .= '<br/>Message: ' . get_field('message', $post_id) . "\r\n\r\n";
- $message .= '<br/>Join Mailing List: Yes' . "\r\n\r\n";
- // sponsor chunk
- $industryList = '';
- $industries = wp_get_post_terms($current_user->ID, 'industry');
- foreach ($industries as $industry) {
- $industryList .= $industry->name . ', ';
- }
- $message .= '<br/>Business Name: ' . get_user_meta($user_id, 'business_name', true) . "\r\n\r\n";
- $message .= '<br/>Industry: ' . $industryList . "\r\n\r\n";
- $message .= '<br/>Phone: ' . get_user_meta($user_id, 'phone', true) . "\r\n\r\n";
- $message .= '<br/>Website: ' . get_user_meta($user_id, 'user_url', true) . "\r\n\r\n";
- $message .= '<br/>Facebook: ' . get_user_meta($user_id, 'facebook', true) . "\r\n\r\n";
- $message .= '<br/>Description: ' . get_user_meta($user_id, 'description', true) . "\r\n\r\n";
- $message .= '<br/>Location: '. get_user_meta($user_id, 'location', true) . "\r\n\r\n";
- $message .= '<br/>Hours of Operation: '.get_user_meta($user_id, '', true) . "\r\n\r\n";
- $message .= '<br/>Logo: ' . get_user_meta($user_id, 'logo', true) . "\r\n\r\n";
- wp_mail(array($email, 'CHANGEINFUNCTIONSKINGDOM@eliteweblabs.com'), $subject, $message);
- wp_safe_redirect(site_url('/shop/sponsorship/'));
- exit;
- } else {
- echo('Username or Email already exists.');
- } // done creating user
- } elseif ($_POST['form_id'] == 'contact') {
- $subject = 'Thank You for Contacting '.get_bloginfo('name');
- $mailing_list = 'No';
- if ($_POST['acf']['field_57b54b91ae82e'] == true) {
- // lets create a user for the mailing list
- if (!$user_id and email_exists($email) == false) {
- $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
- //random password generate
- $userdata = array(
- 'user_login' => $first_name . ' ' . $last_name,
- 'user_email' => $email,
- 'user_pass' => $random_password, // When creating an user, `user_pass` is expected.
- 'user_nicename' => $first_name . ' ' . $last_name,
- 'nickname' => $first_name . ' ' . $last_name,
- 'display_name' => $first_name . ' ' . $last_name,
- 'first_name' => $first_name,
- 'last_name' => $last_name,
- 'role' => 'subscriber'
- );
- $user_id = wp_insert_user($userdata);
- wp_update_post(array('ID' => $post_id, 'post_author' => $user_id));
- update_user_meta($user_id, 'join_kingdom_trails_mailing_list', true);
- update_user_meta($user_id, 'language', $_POST['acf']['field_57cdb948c23ad']);
- $mailing_list = 'Yes';
- } else {
- echo('Username or Email already exists.');
- }// done creating user
- }
- $message .= 'Dear </b> '.$first_name . ' ' . $last_name . ',<br/><br/> '. "\r\n\r\n";
- $message .= '<p>'.get_field('contact_kingdom_trails', 'options').'</p>'. "\r\n\r\n";
- $message .= '<b>Email:</b> ' . $email . "\r\n\r\n";
- $message .= '<br/><b>Language:</b> ' . get_field('language', 'user_' . $user_id) . "\r\n\r\n";
- $message .= '<br/><p><b>Message:</b> ' . get_field('message', $post_id) . "</p>\r\n\r\n";
- $message .= '<b>Join Mailing List:</b> '.$mailing_list . "\r\n\r\n";
- wp_mail(array($email, 'CHANGEINFUNCTIONSKINGDOM@eliteweblabs.com'), $subject, $message, $headers);
- } elseif ($_POST['form_id'] == 'account') {
- }
- return $post_id;
- }
- add_action('acf/save_post', 'acf_forms');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement