Advertisement
Guest User

Untitled

a guest
Dec 7th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.25 KB | None | 0 0
  1.  
  2. function acf_forms($post_id)
  3. {
  4.  
  5. if (empty($_POST['acf']) || is_admin()) return;
  6.  
  7. $first_name = $_POST['acf']['field_57b7ecfdbe1b0'];
  8. $last_name = $_POST['acf']['field_57b7ed1dbe1b1'];
  9. $email = $_POST['acf']['field_57b7ed33be1b2'];
  10. $language = $_POST['acf']['field_57cdb948c23ad'];
  11. $user_id = username_exists($email);
  12.  
  13. if ($_POST['form_id'] == 'sponsor-application') {
  14.  
  15. if (!$user_id and email_exists($email) == false) {
  16.  
  17. $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
  18. $username = $_POST['acf']['field_57afd2f69c880'];
  19.  
  20. $userdata = array(
  21. 'user_login' => $email,
  22. 'user_email' => $email,
  23. 'user_url' => $_POST['acf']['field_57ae8dba42529'],
  24. 'user_pass' => $random_password, // When creating an user, `user_pass` is expected.
  25. 'user_nicename' => $username,
  26. 'nickname' => $username,
  27. 'display_name' => $username,
  28. 'user_url' => $_POST['acf']['field_57ae8dba42529'],
  29. 'first_name' => $first_name,
  30. 'last_name' => $last_name,
  31. 'description' => $_POST['acf']['field_57a60ce18b0fe'],
  32. 'role' => 'pending-sponsor'
  33. );
  34.  
  35. $user_id = wp_insert_user($userdata);
  36. $user = get_userdata($user_id);
  37.  
  38. add_user_meta($user_id, 'has_to_be_activated', true);
  39.  
  40. wp_clear_auth_cookie();
  41. wp_set_current_user($user_id);
  42. wp_set_auth_cookie($user_id);
  43.  
  44. update_user_meta('user_'.$user_id, 'billing_first_name', $first_name );
  45. update_user_meta('user_'.$user_id, 'billing_last_name', $last_name );
  46.  
  47. update_field('billing_phone', $_POST['acf']['field_57a60ce18b0f6'], 'user_'.$user_id);
  48. update_field('business_name', $username, 'user_'.$user_id);
  49. update_field('user_url', $_POST['acf']['field_57ae8dba42529'], 'user_'.$user_id);
  50. update_field('description', $_POST['acf']['field_57a60ce18b0fe'], 'user_'.$user_id);
  51.  
  52. update_field('location', $_POST['acf']['field_57a60ce18b108'], 'user_'.$user_id);
  53.  
  54. var_dump($_POST['acf']['field_5866f9efb321d']->address);
  55.  
  56.  
  57. update_field('industry', $_POST['acf']['field_57b0a6fad1b72'],'user_'.$user_id);
  58. update_field('user_url', $_POST['acf']['field_57ae8dba42529'],'user_'.$user_id);
  59. update_field('user_email', $email, 'user_'.$user_id);
  60. update_field('hours', $_POST['acf']['field_57a60d3084f7c'], 'user_'.$user_id);
  61. update_field('logo', $_POST['acf']['field_57a60fdd0a024'], 'user_'.$user_id);
  62. update_field('facebook', $_POST['acf']['field_57b0af5144407'], 'user_'.$user_id);
  63. update_field('language', $language, 'user_'.$user_id);
  64.  
  65. $subject = 'Thank You for Application';
  66. $message = get_field('field_5802c3820ce8d', 'options') . "\r\n\r\n";
  67. $message .= 'First Name: ' . $user->first_name . "\r\n\r\n";
  68. $message .= 'Last Name: ' . $user->last_name . "\r\n\r\n";
  69.  
  70. $message .= '<br/>Email: ' . $user->user_email . "\r\n\r\n";
  71. $message .= '<br/>Language: ' . get_field('language', $post_id) . "\r\n\r\n";
  72. $message .= '<br/>Message: ' . get_field('message', $post_id) . "\r\n\r\n";
  73. $message .= '<br/>Join Mailing List: Yes' . "\r\n\r\n";
  74.  
  75. // sponsor chunk
  76. $industryList = '';
  77. $industries = wp_get_post_terms($current_user->ID, 'industry');
  78. foreach ($industries as $industry) {
  79. $industryList .= $industry->name . ', ';
  80. }
  81.  
  82. $message .= '<br/>Business Name: ' . get_user_meta($user_id, 'business_name', true) . "\r\n\r\n";
  83. $message .= '<br/>Industry: ' . $industryList . "\r\n\r\n";
  84.  
  85. $message .= '<br/>Phone: ' . get_user_meta($user_id, 'phone', true) . "\r\n\r\n";
  86. $message .= '<br/>Website: ' . get_user_meta($user_id, 'user_url', true) . "\r\n\r\n";
  87. $message .= '<br/>Facebook: ' . get_user_meta($user_id, 'facebook', true) . "\r\n\r\n";
  88. $message .= '<br/>Description: ' . get_user_meta($user_id, 'description', true) . "\r\n\r\n";
  89. $message .= '<br/>Location: '. get_user_meta($user_id, 'location', true) . "\r\n\r\n";
  90. $message .= '<br/>Hours of Operation: '.get_user_meta($user_id, '', true) . "\r\n\r\n";
  91. $message .= '<br/>Logo: ' . get_user_meta($user_id, 'logo', true) . "\r\n\r\n";
  92.  
  93. wp_mail(array($email, 'CHANGEINFUNCTIONSKINGDOM@eliteweblabs.com'), $subject, $message);
  94. wp_safe_redirect(site_url('/shop/sponsorship/'));
  95. exit;
  96.  
  97. } else {
  98.  
  99. echo('Username or Email already exists.');
  100.  
  101. } // done creating user
  102.  
  103. } elseif ($_POST['form_id'] == 'contact') {
  104.  
  105. $subject = 'Thank You for Contacting '.get_bloginfo('name');
  106. $mailing_list = 'No';
  107.  
  108. if ($_POST['acf']['field_57b54b91ae82e'] == true) {
  109.  
  110. // lets create a user for the mailing list
  111.  
  112. if (!$user_id and email_exists($email) == false) {
  113.  
  114. $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
  115. //random password generate
  116.  
  117. $userdata = array(
  118. 'user_login' => $first_name . ' ' . $last_name,
  119. 'user_email' => $email,
  120. 'user_pass' => $random_password, // When creating an user, `user_pass` is expected.
  121. 'user_nicename' => $first_name . ' ' . $last_name,
  122. 'nickname' => $first_name . ' ' . $last_name,
  123. 'display_name' => $first_name . ' ' . $last_name,
  124. 'first_name' => $first_name,
  125. 'last_name' => $last_name,
  126. 'role' => 'subscriber'
  127. );
  128.  
  129. $user_id = wp_insert_user($userdata);
  130.  
  131. wp_update_post(array('ID' => $post_id, 'post_author' => $user_id));
  132. update_user_meta($user_id, 'join_kingdom_trails_mailing_list', true);
  133. update_user_meta($user_id, 'language', $_POST['acf']['field_57cdb948c23ad']);
  134.  
  135. $mailing_list = 'Yes';
  136.  
  137. } else {
  138.  
  139. echo('Username or Email already exists.');
  140.  
  141. }// done creating user
  142.  
  143. }
  144.  
  145. $message .= 'Dear </b> '.$first_name . ' ' . $last_name . ',<br/><br/> '. "\r\n\r\n";
  146. $message .= '<p>'.get_field('contact_kingdom_trails', 'options').'</p>'. "\r\n\r\n";
  147. $message .= '<b>Email:</b> ' . $email . "\r\n\r\n";
  148. $message .= '<br/><b>Language:</b> ' . get_field('language', 'user_' . $user_id) . "\r\n\r\n";
  149. $message .= '<br/><p><b>Message:</b> ' . get_field('message', $post_id) . "</p>\r\n\r\n";
  150. $message .= '<b>Join Mailing List:</b> '.$mailing_list . "\r\n\r\n";
  151.  
  152. wp_mail(array($email, 'CHANGEINFUNCTIONSKINGDOM@eliteweblabs.com'), $subject, $message, $headers);
  153.  
  154. } elseif ($_POST['form_id'] == 'account') {
  155.  
  156. }
  157.  
  158. return $post_id;
  159. }
  160.  
  161. add_action('acf/save_post', 'acf_forms');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement