ID); return new WP_REST_Response( $properties, 200 ); } function bc_select_properties_for_user($userId){ global $wpdb; $sql = $wpdb->prepare("SELECT * FROM wp_rental_properties WHERE user_id = %d;", $userId); return $wpdb->get_results($sql, OBJECT); } function bc_select_property($userId, $propertyId){ global $wpdb; $sql = $wpdb->prepare("SELECT * FROM wp_rental_properties WHERE user_id = %d AND id = %d;", $userId, $propertyId); return $wpdb->get_row($sql); } function bc_update_property( WP_REST_Request $request ) { global $wpdb; global $current_user; $response = new WP_REST_Response(); $userId = $current_user->ID; $table_name = $wpdb->prefix."rental_properties"; $data = $wpdb->update($table_name, array( 'rental_name' => $request['rental_name'], 'address1' => $request['address1'], 'address2' => $request['address2'], 'city' => $request['city'], 'state' => $request['state'], 'zip' => $request['zip'] ), array( 'id' => $request['id'], 'user_id' => $userId, )); if(!empty($request['redirect'])){ $response->set_status( 302 ); $response->header('Location', $request['redirect']); return $response; } $response->data = $data; $response->set_status( 201 ); return $response; } function bc_create_property( WP_REST_Request $request ) { global $wpdb; global $current_user; $response = new WP_REST_Response(); if(!bc_user_can_add_property($current_user->ID)) { $response->set_status(400); $response->data = array( 'error' => 'Subscription plan unit count exceeded.' ); return $response; } $userId = $current_user->ID; $table_name = $wpdb->prefix."rental_properties"; $data = $wpdb->insert($table_name, array( 'user_id' => $userId, 'rental_name' => $request['rental_name'], 'address1' => $request['address1'], 'address2' => $request['address2'], 'city' => $request['city'], 'state' => $request['state'], 'zip' => $request['zip'] )); if(!empty($request['redirect'])){ $response->set_status( 302 ); $response->header('Location', $request['redirect']); return $response; } $response->data = $data; $response->set_status( 201 ); return $response; } function bc_delete_property( WP_REST_Request $request ) { global $wpdb; global $current_user; $response = new WP_REST_Response(); $userId = $current_user->ID; $table_name = $wpdb->prefix."rental_properties"; $data = $wpdb->delete($table_name, array( 'id' => $request['id'], 'user_id' => $userId )); $response->data = $data; $response->set_status(201); return $response; } function bc_user_can_add_property($userId){ return true; // temporary allow any number of props $planCount = bc_get_plan_count_for_user($userId); $unitCount = bc_get_unit_count_for_user($userId); return $unitCount < $planCount; } function bc_get_subscription_for_user($userId){ global $wpdb; $metaKey = '_stripe_customer_id'; $sql = $wpdb->prepare(" SELECT s.* FROM wp_fullstripe_subscribers s JOIN $wpdb->usermeta um ON um.meta_value = s.stripeCustomerID AND um.user_id = %d AND um.meta_key = %s ", $userId, $metaKey); return $wpdb->get_row($sql); } function bc_get_plan_count_for_user($userId){ $subscription = bc_get_subscription_for_user($userId); $planId = $subscription->planID; $planUnitCount = 1; if($planID === ''){ } else if ($planID === ''){ } else if ($planID === ''){ } return $planUnitCount; } function bc_get_unit_count_for_user($userId){ global $wpdb; $sql = $wpdb->prepare("SELECT COUNT(*) FROM wp_rental_properties WHERE user_id = %d", $userId); return $wpdb->get_var($sql); } function bc_get_template( $template ) { $haystack = $template; $needle = 'bauscode'; if ( strpos($haystack, $needle) !== FALSE ) { $page_template = dirname( __FILE__ ) . '/' . $template; } return $page_template; } function bc_rental_shortcode($atts) { ob_start(); include(dirname(__FILE__).'/templates/bauscode-rental-create.php'); $content = ob_get_clean(); return $content; } function bc_plugin_activate(){ bc_init_db_schema(); } function bc_init_db_schema(){ global $wpdb; $table_name = $wpdb->prefix."rental_properties"; if ($wpdb->get_var('SHOW TABLES LIKE '.$table_name) != $table_name) { $sql = 'CREATE TABLE '.$table_name.'( id bigint(20) NOT NULL AUTO_INCREMENT, user_id bigint(20) UNSIGNED NOT NULL, rental_name varchar(50), address1 varchar(50), address2 varchar(50), city varchar(50), state varchar(10), zip varchar(10), PRIMARY KEY (id))'; require_once(ABSPATH.'wp-admin/includes/upgrade.php'); dbDelta($sql); add_option("rental_properties", "1.0"); } } // filters add_shortcode('rental_properties', bc_rental_shortcode); register_activation_hook(__FILE__, bc_plugin_activate); add_action( 'wp_enqueue_scripts', function() { wp_enqueue_script( 'rental_properties', plugin_dir_url( __FILE__ ) . 'rental-properties.js', array( 'jquery' ) ); wp_enqueue_style( 'rental_properties', plugin_dir_url( __FILE__ ) . 'rental-properties.css' ); wp_localize_script('rental_properties', 'RentalProperties', array( 'root' => esc_url_raw( rest_url() ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'current_user_id' => get_current_user_id() ) ); }); // routes add_action( 'rest_api_init', function () { register_rest_route( 'bauscode', '/rental_properties', array( 'methods' => 'GET', 'callback' => 'bc_select_properties', 'args' => array(), 'permission_callback' => function() { return is_user_logged_in(); } ) ); register_rest_route( 'bauscode', '/rental_properties/(?P[\d]+)', array( 'methods' => 'PUT', 'callback' => 'bc_update_property', 'args' => array( 'id' => array(), ), 'permission_callback' => function() { return is_user_logged_in(); } ) ); register_rest_route( 'bauscode', '/rental_properties/(?P[\d]+)/update', array( 'methods' => 'POST', // form-accessible alternate route 'callback' => 'bc_update_property', 'args' => array( 'id' => array(), ), 'permission_callback' => function() { return is_user_logged_in(); } ) ); register_rest_route( 'bauscode', '/rental_properties', array( 'methods' => 'POST', 'callback' => 'bc_create_property', 'args' => array(), 'permission_callback' => function() { return is_user_logged_in(); } ) ); register_rest_route( 'bauscode', '/rental_properties/(?P[\d]+)', array( 'methods' => 'DELETE', 'callback' => 'bc_delete_property', 'args' => array( 'id' => array(), ), 'permission_callback' => function() { return is_user_logged_in(); } ) ); register_rest_route( 'bauscode', '/rental_properties/(?P[\d]+)/delete', array( 'methods' => 'POST', // form-accessible alternate route 'callback' => 'bc_delete_properties', 'args' => array( 'id' => array(), ), 'permission_callback' => function() { return is_user_logged_in(); } ) ); } ); ?> Detect Subletting - Stopbnb Stopbnb

Do you know how to detect whether a tenant is subletting? Do you know why it’s important to detect it? Imagine this: You finally got a few good tenants in your unit. They’re mostly quiet, usually polite, and don’t often call you at odd hours of the night. But one Saturday evening, you get a call from a tenant who says they see a car they don’t recognize in the parking lot in an assigned space. You finish your dinner, wipe your mouth, and go out to inspect. Yep, that’s a strange car alright, but it appears to have a parking lot pass in the window. The next weekend, the same thing happens, but with a different car. And the next, and the next. Finally, you call that tenant to ask about the car in the parking lot that they haven’t registered with you. They tell you they’re halfway across the country and can’t help, then hang up.

While nothing bad has necessarily happened, you still feel uneasy. Other tenants begin calling you complaining about increasing noise problems coming from that apartment, and one other tenant even said they smelled smoke. Do you want to wait until this happens to detect subletting in your apartment?

With the growing popularity of services like AirBnB, VRBO, and even short-term rentals on Craigslist, knowing how to detect subletting in the units you own is becoming more and more important than ever. However, rather than having to sleuth around on your own time like many landlords have to do, only to come up with no hard evidence that your tenant is breaking the terms of your lease agreement, you can keep it simple and use our services right here on StopBnB.com to let us keep track of the threat and detect subletting before it starts.