SHARE
TWEET

Untitled

a guest Jun 17th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //split name into first and last
  2. function split_name($name) {
  3.     $name = trim($name);
  4.     $last_name = (strpos($name, ' ') === false) ? '' : preg_replace('#.*\s([\w-]*)$#', '$1', $name);
  5.     $first_name = trim( preg_replace('#'.$last_name.'#', '', $name ) );
  6.     return array($first_name, $last_name);
  7. }
  8.  
  9. add_action("cp_after_subscribe","add_my_user",10,2);
  10. function add_my_user( $email, $service ){
  11.     $posteddata = ConvertPlugHelper::get_post_data();
  12.     global $response;
  13.     if(!username_exists( $user_name ))
  14.     {
  15.         if(!email_exists($email)){
  16.             $name = $posteddata["param"]["textfield_8062"];
  17.             $name_splitted = split_name($posteddata["param"]["textfield_8062"]);
  18.             $password = $posteddata["param"]["textarea_8481"];
  19.             $user_email = $email;
  20.             $user_id = wp_create_user( $user_email, $password, $user_email );
  21.             if($user_id){
  22.                 $response['user_id'] = $user_id;
  23.                 $user_info = get_userdata($user_id);
  24.                 // create md5 code to verify later
  25.                 $code = md5(time());
  26.                 // make it into a code to send it to user via email
  27.                 $string = array('id'=>$user_id, 'code'=>$code , 'password' => $password , 'email' => $user_email);
  28.                 // create the activation code and activation status
  29.                 update_user_meta($user_id, 'account_activated', 0);
  30.                 update_user_meta($user_id, 'activation_code', $code);
  31.                 update_user_meta($user_id , 'display_name' , $name);
  32.                 update_user_meta($user_id , 'first_name' , $name_splitted[0]);
  33.                 update_user_meta($user_id , 'last_name' , $name_splitted[1]);
  34.                 // create the url
  35.                 $url = get_site_url(). '/verify/?act=' .base64_encode( serialize($string));
  36.                
  37.                 // basically we will edit here to make this nicer
  38.                 $html = 'Please click the following links <br/><br/> <a href="'.$url.'">'.$url.'</a>';
  39.                 // send an email out to user
  40.                 wp_mail( $user_info->user_email, __('Verify Your Account to Access the services','text-domain') , $html);
  41.             }
  42.         }
  43.         else{
  44.             $response['error'] = true;
  45.             $response['error_content'] = 'email id already exists';
  46.             return $response;
  47.         }
  48.     }
  49.     else{
  50.         $response['error'] = true;
  51.         $response['error_content'] = 'username already used';
  52.         return $response;
  53.     }
  54. }
  55.  
  56.  
  57. add_action( 'init', 'verify_user_code' );
  58. function verify_user_code(){
  59.     if(isset($_GET['act'])){
  60.         $data = unserialize(base64_decode($_GET['act']));
  61.         $code = get_user_meta($data['id'], 'activation_code', true);
  62.         // verify whether the code given is the same as ours
  63.         if($code == $data['code']){
  64.             // update the user meta    
  65.                 update_user_meta($data['id'], 'is_activated', 1);
  66.                 $user = new WP_User($data['id']);
  67.                 $user->set_role('custom_role1');
  68.                 $creds = array(
  69.                     'user_login'    => $data['email'],
  70.                     'user_password' => $data['password'],
  71.                     'remember'      => true
  72.                 );
  73.                 //var_dump($creds);            
  74.                 $user = wp_signon( $creds, false );
  75.                 if($user){
  76.                     $location = pmpro_url( "checkout", "?level=" . 12);
  77.                     wp_safe_redirect($location);
  78.                     //var_dump($location);
  79.                     exit;
  80.                 }
  81.                 else if( is_wp_error( $user ) ) {
  82.                     echo $user->get_error_message();
  83.                 }
  84.         }
  85.     }
  86. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top