Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ************ creating new accounts when receiving new viewing booking ***********
- function processViewingBooking($vars) {
- require_once(ABSPATH . WPINC . '/registration.php');
- $username = $vars['booked_by'];
- $useremail = $username;
- $address = $vars['address'];
- if($username && $address) {
- // create account if necessary
- $user_id = username_exists( $username );
- if ( !$user_id ) {
- $random_password = wp_generate_password( 12, false );
- $user_id = wp_create_user( $username, $random_password, $useremail );
- echo "account created: ".$user_id;
- } else {
- echo "account identified: ".$user_id;
- }
- // store event
- $new_event = array();
- $new_event['post_title'] = time();
- $new_event['post_type'] = 'viewings';
- $new_event['post_content'] = 'This is my new viewing.';
- $new_event['post_status'] = 'publish';
- $new_event['post_author'] = $user_id;
- $event_id = wp_insert_post($new_event);
- if($event_id) {
- update_post_meta($event_id, "address", $address);
- }
- } else {
- // fail silently
- echo "please send username and address parameters";
- }
- }
- if ( ! function_exists( 'post_type_viewings' ) ) :
- function post_type_viewings() {
- register_post_type(
- 'viewings',
- array(
- 'label' => __('Viewings'),
- 'description' => __('Logging booked viewings.'),
- 'public' => true,
- 'show_ui' => true,
- 'supports' => array (
- 'title',
- 'editor',
- 'thumbnail',
- 'excerpt',
- 'custom-fields',
- 'author'
- )
- )
- );
- }
- endif;
- add_action('init', 'post_type_viewings');
- // ************ end creating new accounts when receiving new viewing booking ************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement