Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. function ajax_registration(){
  2.  
  3. // First check the nonce, if it fails the function will break
  4. check_ajax_referer( 'ajax-registration-nonce', 'regsecurity' );
  5.  
  6. // Nonce is checked, get the POST data and sign user on
  7. $info = array();
  8.  
  9. $regname = $_POST['regname'];
  10. $regemail = $_POST['regemail'];
  11. $regusername = explode("@",$regemail);
  12. $regusername = $regusername[0];
  13. $regpassword =wp_generate_password(12);
  14.  
  15. $myerror = '';
  16.  
  17. if($regemail == ''){
  18. $myerror .= 'Please enter email address';
  19. }
  20. else if($regpassword == ''){
  21. $myerror .= ($myerror != '')?'<br>':'';
  22. $myerror .= 'Please enter password';
  23. }
  24. if($myerror != ''){
  25. echo json_encode(array('signupresponse'=>false, 'message'=>__("$myerror")));
  26. }
  27. else {
  28. if ( email_exists($regemail) == false ) {
  29. $user_id = wp_create_user( $regusername, $regpassword, $regemail );
  30. update_user_option( $user_id, 'firstname', $regname);
  31. echo json_encode(array('signupresponse'=>true, 'message'=>__('Register successful!\n You can login now')));
  32. } else {
  33. echo json_encode(array('signupresponse'=>false, 'message'=>__('Email already exists.')));
  34. }
  35. }
  36.  
  37. die();
  38. }
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. //ajax
  50. $.ajax({
  51. type: 'POST',
  52. // dataType: 'json',
  53. url: ajax_registration_object.ajaxurl,
  54. data: {
  55. 'action': 'ajaxregistration', //calls wp_ajax_nopriv_ajaxregistration
  56. 'regname': $('form#registration #regname').val(),
  57. 'regemail': $('form#registration #regemail').val(),
  58. 'regpassword': $('form#registration #regpassword').val(),
  59. 'regsecurity': $('form#registration #regsecurity').val() },
  60. success: function(data){
  61. $('form#registration p.status').text(data.message);
  62. if (data.signupresponse == true){
  63. document.location.href = ajax_registration_object.redirecturl;
  64. }
  65. }
  66. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement