WP Rentals Help WP Rentals Help

  • Client Support
  • Video Tutorials
  • WpRentals
  • WpEstate
  • API
Home / Email Notifications / How SMS Notifications Work in WP Rentals (WpestateEmail Class): A Complete Guide

How SMS Notifications Work in WP Rentals (WpestateEmail Class): A Complete Guide

816 views

Overview

WP Rentals includes a robust notification system that can send important alerts both by email and SMS. This guide explains:

  • How SMS notifications are triggered,

  • What configuration is required,

  • How templates and user data are used,

  • How SMS messages are sent using Twilio,

  • Troubleshooting tips for common problems.

  • the code is in plugins\wprentals-core\classes\wpestate_email.php

How the System Works

Whenever a key event occurs (like a booking confirmation or new message), the system sends an email to the user. At the same time, it may also send an SMS to the user’s registered phone number if SMS notifications are enabled and the user is eligible.


1. SMS Notification Flow

Step-by-Step Process

  1. Trigger Event
    An action (e.g., booking confirmation) triggers the wpestate_send_email() function.

  2. Email Preparation and Sending
    The system prepares the email content and sends the email to the user.

  3. SMS Check and Sending
    Right after the email is sent, the system checks if SMS notifications should also be sent to this user for this event.

  4. Template Loading and Placeholder Replacement
    If SMS is enabled and the user is eligible, the system loads the appropriate SMS template, replaces placeholders (like %username or %website_url) with real values, and prepares the SMS message.

  5. SMS Delivery via Twilio
    The system connects to the Twilio SMS gateway and sends the SMS to the user’s phone.


2. When Are SMS Messages Sent?

SMS notifications are sent only if all the following are true:

  • SMS notifications are enabled
    (wp_estate_sms_verification option is set to ‘yes’ in the admin panel)

  • User is eligible

    • The user’s phone number is marked as validated (check_phone_valid == 'yes' in their profile)

    • Or the current user sending the message is an administrator

  • A template exists for that notification type (e.g., wp_estate_sms_booking_confirmed)

  • Twilio credentials are set in the site’s options


3. How to Set Up SMS Notifications

A. Enable SMS Notifications

  • Go to WP Rentals > Settings > SMS Settings

  • Find the Enable SMS Verification/Notifications option (wp_estate_sms_verification)

  • Set to Yes and save

B. Configure Twilio Settings

  • Obtain your Twilio API credentials:

    • Account SID

    • Auth Token

    • Twilio Phone Number

  • In WP Rentals > Settings > SMS Settings enter:

    • wp_estate_twilio_api_key (Twilio Account SID)

    • wp_estate_twilio_auth_token (Twilio Auth Token)

    • wp_estate_twilio_phone_no (Twilio phone number)

C. Add/Validate User Mobile Numbers

  • Each user should enter their mobile number in their profile.

  • An admin (or automated process) must set their check_phone_valid user meta to ‘yes’.

D. Edit SMS Message Templates

  • Each event has its own SMS template in the plugin/theme options:

    • Examples: wp_estate_sms_booking_confirmed, wp_estate_sms_new_message

  • Templates can use placeholders:

    • %username

    • %website_url

    • %website_name

    • %user_email

    • (Other custom arguments as needed)

  • Placeholders are automatically replaced with real data before sending.


4. Technical Details: How It Works Behind the Scenes

A. Email Sending Triggers SMS

php
public function wpestate_send_email($user_email, $type, $arguments) {
// ... prepare and send email ...
$this->wpestate_select_sms_type($user_mobile, $type, $arguments, $user_email, $user_data->ID);
// ... return result ...
}

B. SMS Eligibility and Template Loading

php
public function wpestate_select_sms_type($user_mobile, $type, $arguments, $user_email, $user_data_id) {
// 1. Is SMS enabled? If not, return.
// 2. If user is not admin and not 'validation', check if their phone is validated.
// 3. Get SMS template for this type.
// 4. If eligible, call sms_filter_replace to build message and send.
}

C. Placeholder Replacement

php
private function wpestate_sms_filter_replace($user_phone_no, $message, $arguments, $user_email) {
// Replace placeholders in the template with user/site data
// Clean up message for SMS (plain text)
// Send via Twilio
}

D. Sending SMS with Twilio

php
private function wpstate_call_twilio_sms($user_phone_no, $message) {
// Uses Twilio API credentials from settings
// Sends message using PHP cURL
}

5. Common Questions

Q: What happens if a user’s phone isn’t validated?

A: SMS will not be sent unless the current user is an administrator or the SMS type is 'validation'.

Q: What if SMS sending is disabled in settings?

A: No SMS will be sent, regardless of other configuration.

Q: Can I customize the SMS text?

A: Yes! Each event type has its own template in the options. You can use placeholders that are automatically filled in.

Q: What if Twilio settings are wrong or missing?

A: SMS sending will fail silently; a PHP error will be logged or displayed if cURL fails.

Q: How do I test SMS sending?

A: Enable SMS, use your own phone number (set as validated in your profile), trigger an event (like a booking), and check if you receive the SMS.


6. Troubleshooting

  • Not receiving SMS?

    • Ensure wp_estate_sms_verification is 'yes'

    • User phone is present and validated (check_phone_valid == 'yes')

    • SMS template is set for the event type

    • Twilio credentials are correct

    • Twilio phone number is valid for SMS

  • Error: “No body provided” in Twilio?

    • Make sure your integration is not sending both a template (ContentSid) and a Body. Use one or the other per message.

  • Phone format issues?

    • Phone numbers must be in full international format (e.g., +12345678901) for Twilio to send correctly.


7. Developer Notes

  • You can add more SMS event types by creating new templates in the options and triggering wpestate_send_email with the appropriate type.

  • The SMS sending logic can be extended or replaced by modifying the wpestate_select_sms_type and wpstate_call_twilio_sms functions.

  • All options are fetched with wprentals_get_option(); you can pre-set or override these as needed.


Summary Table

Setting/Meta Description Where Set?
wp_estate_sms_verification Enable/disable SMS notifications Admin > WP Rentals > SMS Settings
wp_estate_twilio_api_key Twilio Account SID Admin > WP Rentals > SMS Settings
wp_estate_twilio_auth_token Twilio Auth Token Admin > WP Rentals > SMS Settings
wp_estate_twilio_phone_no Twilio phone number (sender) Admin > WP Rentals > SMS Settings
mobile (user meta) User’s mobile phone number User Profile
check_phone_valid (user meta) Has this user’s phone been validated? User Profile / Programmatically
wp_estate_sms_[type] SMS template for this event type Admin > WP Rentals > SMS Templates
Email Notifications

Related Articles

  • Trip Details Email in WP Rentals
  • Theme Options – Email Management – Email Settings
  • SMS Management by Twilio
  • Hide Booking Form and Replace with Owner Contact Form

HELP CATEGORIES

  • 61. General
  • 102. Installation & Basic Setup
  • 93. Installation FAQ
  • 394. How Booking Works
  • 145. User dashboard pages
  • 20Advanced Search Options
  • 3Blog Post
  • 9Custom Page Templates
  • 18Elementor Compatibility
  • 13Email Notifications
  • 19FAQ
  • 10Menu Options
  • 26Multi-Languages - 3rd party
  • 9Owner
  • 25Property / Listing
  • 21Shortcodes
  • 11Submit Form
  • 4Supported Maps
  • 93Technical how to
  • 5Third Party plugins
  • 3Translation
  • 13Widgets
  • 2WooCommerce Payments
  • 13WP Rentals Payment
  • 77WP Rentals Theme Options

Join Us On

Powered by WP Estate - All Rights Reserved
  • Client Support
  • Video Tutorials
  • WpRentals
  • WpEstate
  • API