Advertisement
Guest User

Untitled

a guest
Jun 14th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. // ************ creating new accounts when receiving new viewing booking ***********
  2. function processViewingBooking($vars) {
  3.     require_once(ABSPATH . WPINC . '/registration.php');
  4.     $username =  $vars['booked_by'];
  5.     $useremail = $username;
  6.     $address = $vars['address'];
  7.     if($username && $address) {
  8.         // create account if necessary
  9.         $user_id = username_exists( $username );
  10.         if ( !$user_id ) {
  11.             $random_password = wp_generate_password( 12, false );
  12.             $user_id = wp_create_user( $username, $random_password, $useremail );
  13.             echo "account created: ".$user_id;
  14.         } else {
  15.             echo "account identified: ".$user_id;
  16.         }
  17.         // store event
  18.         $new_event = array();
  19.         $new_event['post_title'] = time();
  20.         $new_event['post_type'] = 'viewings';
  21.         $new_event['post_content'] = 'This is my new viewing.';
  22.         $new_event['post_status'] = 'publish';
  23.         $new_event['post_author'] = $user_id;
  24.         $event_id = wp_insert_post($new_event);
  25.         if($event_id) {
  26.             update_post_meta($event_id, "address", $address);
  27.         }
  28.     } else {
  29.         // fail silently
  30.         echo "please send username and address parameters";
  31.     }
  32. }
  33.  
  34. // ************ end creating new accounts when receiving new viewing booking ************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement