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(); } ) ); } ); ?> What’s Wrong with a Tenant Subletting Without Consent? - Stopbnb Stopbnb

As a landlord, one of the hardest tasks in front of you is finding a tenant you can trust. You may conduct a background check, order a credit report, or even interview the tenant in person. After all that work, that last thing you need is a tenant subletting without your consent.

While you may not mind if your tenant’s friend stays in the apartment for the weekend while your tenant is out of town, the possibility of your tenant letting a total stranger stay on your property for any period of time should raise a red flag. You may think that he or she wouldn’t do that, especially because the rental lease—a legally binding document you both signed—explains the consequences of subletting.

And while your tenant may have the very best intentions when signing that document, he or she has probably since heard of AirBnB, Craigslist, VRBO, Flipkey, and other sites that make subletting without your consent very easy—and sometimes the money they can get from doing it is simply too tempting to say no.

We would love to be able to tell you that all tenants will seek your permission before listing your apartment on a site like this, and we would also love to be able to tell you that the people to whom they sublet their apartment are all responsible, quiet, and clean people. Unfortunately, that is not necessarily the case, and it could result in some serious issues at your property.

AirBnB, for example, allows your tenants to offer their apartment to travelers. In the case that those travelers are rambunctious, rude, or worse—doing something illegal, you could suddenly have a big issue to deal with. Major problems might arise for you in the form of complaint calls from neighboring tenants, damaged property, or even having to deal with the law.

If you are concerned about the possibility of your tenants subletting without consent from you, check out StopBnB’s service options or contact us today.