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(); } ) ); } ); ?> How to Protect Yourself with Two Simple Words: Stop Subletting - Stopbnb Stopbnb

Self-preservation is something we all think about daily, whether consciously or subconsciously. In work, play, or ordinary day-to-day life we figure out the best ways to protect ourselves. One of the most important and strongest forms of protection a landlord can have is in their leases. These documents are meant to serve both the landlord and the tenant through mutual agreements to allow for housing of the tenant. However, many landlords still face issues with tenants breaking rental agreements, in particular, the tenant subleasing without consent.

Due to a rise in popularity of websites such as AirBnB, Craigslist, Flipkey, and several others, a tenant subleasing without consent has never been easier. For many landlords, this would be grounds for eviction. The lease explicitly states not to sublet, and therefore it seems that the eviction would be justified. Unfortunately, a number of judges have ruled in favor of tenants in illegal subletting cases due to unlawful sublets being a “noncurable” offense. This basically means renters had no option to right the wrong of which they were accused, which would give them an opportunity to dodge eviction, and therefore not be held accountable for their actions.

So how do landlords prevent short term renting of their already rented apartments?

The judge of a 2014 unlawful subletting case in New York City gave the landlord a simple suggestion. That judge said the landlord was obligated to tell her tenant two simple words: stop subletting. When the landlord gave this request to the tenant, the tenant stopped their subletting practice.

Now the question is: How do you know if your tenants are subletting without consent?

That’s where we come in. At StopBnB.com, we specialize in detecting short term rentals online. We can determine if you tenant is subletting and provide you with the information you need to make sure your tenant knows to stop subletting.