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
-
Trigger Event
An action (e.g., booking confirmation) triggers thewpestate_send_email()
function. -
Email Preparation and Sending
The system prepares the email content and sends the email to the user. -
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. -
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. -
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
B. SMS Eligibility and Template Loading
C. Placeholder Replacement
D. Sending SMS with Twilio
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
andwpstate_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 |