Overview
This technical help explains how WPRentals sends SMS notifications through the notification system.
The SMS flow is connected to the email notification flow. When a supported notification is triggered, WPRentals first prepares the email notification and then checks if an SMS should also be sent for the same notification type.
The main logic is handled in the WPRentals Core plugin file:
plugins/wprentals-core/classes/wpestate_email.php
Main SMS Notification Flow
The SMS notification flow starts from the same notification system used for email notifications.
The general flow is:
- A supported website action is triggered, such as a booking confirmation, new message, listing approval, password reset, or phone validation.
- The notification system calls wpestate_send_email().
- The email notification is prepared and sent.
- The function checks if an SMS notification should also be sent for the same notification type.
- The SMS logic checks if SMS notifications are enabled.
- The SMS logic checks the recipient phone number.
- The SMS logic checks if the user is eligible to receive the SMS.
- The correct SMS template is loaded based on the notification type.
- Template placeholders are replaced with real values.
- The final SMS body is sent through Twilio.
Main File and Related Functions
The SMS notification logic is located in:
plugins/wprentals-core/classes/wpestate_email.php
The main functions involved in the SMS flow are:
| Function | Purpose |
|---|---|
| wpestate_send_email() | Main notification entry point. It prepares and sends the email notification and can trigger the SMS check. |
| wpestate_select_sms_type() | Checks SMS settings, user eligibility, phone validation, notification type, and SMS template. |
| wpestate_sms_filter_replace() | Replaces placeholders in the SMS template and prepares the final SMS body. |
| wpstate_call_twilio_sms() | Sends the prepared SMS message through Twilio. |
wpestate_send_email()
wpestate_send_email() is the main notification function.
It receives the recipient email address, the notification type, and the notification arguments.
After the email content is prepared and the email notification is sent, this function can call wpestate_select_sms_type() with the user mobile number, notification type, notification arguments, user email, and user ID.
The key point is that SMS is triggered from the email notification flow. The SMS logic receives the same notification type and arguments used for the email.
wpestate_select_sms_type()
wpestate_select_sms_type() decides if an SMS should be sent.
This function receives the user mobile number, notification type, notification arguments, user email, and user ID.
This function checks:
- If SMS notifications are enabled.
- If the user is eligible to receive SMS.
- If the user phone is validated when validation is required.
- If an SMS template exists for the current notification type.
- If the SMS template has content.
- If Twilio settings are available.
If all conditions pass, the function prepares the SMS message and sends it through the Twilio SMS function.
wpestate_sms_filter_replace()
wpestate_sms_filter_replace() prepares the final SMS text.
It receives the user phone number, the SMS template, the notification arguments, and the user email address.
This function replaces supported placeholders with real values before the SMS is sent.
Common placeholders can include:
- %username
- %website_url
- %website_name
- %user_email
wpstate_call_twilio_sms()
wpstate_call_twilio_sms() sends the final SMS message through Twilio.
This function depends on the Twilio settings saved in WPRentals options.
The required Twilio option values are:
| Option | Purpose |
|---|---|
| wp_estate_twilio_api_key | Twilio Account SID. |
| wp_estate_twilio_auth_token | Twilio Auth Token. |
| wp_estate_twilio_phone_no | Twilio sender phone number. |
Required Conditions Before SMS Is Sent
An SMS notification is sent only when all required conditions are met.
| Condition | Required Value or Behavior |
|---|---|
| SMS enabled | wp_estate_sms_verification must be set to yes. |
| User mobile number | The recipient user must have a mobile number saved. |
| Phone validation | For most notification types, check_phone_valid must be set to yes. |
| Admin exception | SMS may be allowed when the current user is an administrator, depending on the notification flow. |
| Validation SMS exception | The phone validation SMS can be sent before the phone is marked as validated. |
| SMS template | A template must exist for the current notification type. |
| Twilio credentials | Twilio Account SID, Auth Token, and sender phone number must be configured. |
| Recipient number format | The phone number should be saved in full international format, for example +12345678901. |
Options and User Meta Used by SMS
WPRentals Options
The SMS system uses values saved in the WPRentals options system. These values are loaded with wprentals_get_option().
| Option | Description |
|---|---|
| wp_estate_sms_verification | Enables or disables SMS notifications. |
| wp_estate_twilio_api_key | Stores the Twilio Account SID. |
| wp_estate_twilio_auth_token | Stores the Twilio Auth Token. |
| wp_estate_twilio_phone_no | Stores the Twilio sender phone number. |
| wp_estate_sms_[type] | Stores the SMS template for a specific notification type. |
User Meta
| User Meta | Description |
|---|---|
| mobile | Stores the user mobile phone number. |
| check_phone_valid | Stores whether the user phone number is validated. The expected validated value is yes. |
SMS Templates and Placeholders
Each supported SMS notification type has its own template option.
The template option name follows this general pattern:
wp_estate_sms_[type]
Examples:
- wp_estate_sms_booking_confirmed
- wp_estate_sms_new_message
The notification type passed to wpestate_send_email() is used to determine which SMS template should be loaded.
SMS templates can include placeholders. Placeholders are replaced in wpestate_sms_filter_replace() before the SMS is sent.
Common placeholders include:
- %username
- %website_url
- %website_name
- %user_email
Phone Validation Logic
For most SMS notifications, the recipient phone number must already be validated.
The validation status is stored in user meta:
check_phone_valid = yes
If the user phone number is not validated, SMS is not sent in most cases.
Exceptions can include:
- The SMS type is the phone validation SMS.
- The current user triggering the flow is an administrator.
This validation check prevents regular notifications from being sent to unverified phone numbers.
Twilio Delivery Logic
After the SMS template is prepared, WPRentals sends the message through Twilio.
Twilio delivery depends on:
- The Twilio Account SID.
- The Twilio Auth Token.
- The Twilio sender phone number.
- The destination phone number.
- The destination country and Twilio account permissions.
- The SMS capability of the Twilio sender number.
The recipient phone number should be saved in international format, for example:
+12345678901
Technical Debugging Checklist
Email Is Sent but SMS Is Not Sent
- Confirm the notification action calls wpestate_send_email().
- Confirm wpestate_select_sms_type() is called after the email logic.
- Check the notification type value.
- Check if a matching wp_estate_sms_[type] template exists.
- Check if the SMS template field is not empty.
- Check if the recipient user has a saved mobile number.
- Check if check_phone_valid is set to yes when required.
- Check if SMS notifications are enabled with wp_estate_sms_verification.
SMS Template Is Loaded but Text Is Wrong
- Check the template text saved in WPRentals options.
- Check placeholder spelling.
- Check which placeholders are supported by that notification type.
- Check if the values needed by the placeholders are passed in the notification arguments.
- Check wpestate_sms_filter_replace() for the placeholder replacement logic.
Twilio Call Fails
- Check wp_estate_twilio_api_key.
- Check wp_estate_twilio_auth_token.
- Check wp_estate_twilio_phone_no.
- Check if the Twilio sender number supports SMS.
- Check if the recipient phone number uses international format.
- Check if the destination country is enabled or allowed in Twilio.
- Check Twilio logs for the exact error message.
User Phone Is Not Accepted
- Check the value stored in the user mobile meta.
- Use full international phone format.
- Do not use local-only numbers.
- Check if the user phone validation meta is set correctly.
- Check if the current notification type requires phone validation.
SMS Sends for Admin but Not for Normal Users
- Check the admin exception in the SMS eligibility logic.
- Check if the normal user has check_phone_valid set to yes.
- Check if the normal user has a valid mobile number saved.
- Check if the SMS type is allowed for non-admin users.
Developer Notes
The SMS sending logic is tied to the notification type passed to wpestate_send_email().
To add or debug an SMS notification type, a developer should check:
- Where the notification event calls wpestate_send_email().
- What notification type is passed.
- What values are passed in the notification arguments.
- Whether a matching wp_estate_sms_[type] option exists.
- Whether that option contains an SMS template.
- Whether placeholder replacement supports the required values.
- Whether the user has mobile and validation meta.
- Whether Twilio options are available.
Core values are loaded with:
wprentals_get_option()
Relevant internal values:
- wp_estate_sms_verification
- wp_estate_twilio_api_key
- wp_estate_twilio_auth_token
- wp_estate_twilio_phone_no
- wp_estate_sms_[type]
- mobile
- check_phone_valid
Summary Table
| Setting / Function / Meta | Type | Purpose |
|---|---|---|
| plugins/wprentals-core/classes/wpestate_email.php | File | Main file where the email and SMS notification logic is handled. |
| wpestate_send_email() | Function | Main email notification function. Can trigger SMS flow after email logic. |
| wpestate_select_sms_type() | Function | Checks whether SMS should be sent for the notification type and user. |
| wpestate_sms_filter_replace() | Function | Replaces SMS placeholders and prepares the final message body. |
| wpstate_call_twilio_sms() | Function | Sends the SMS message through Twilio. |
| wp_estate_sms_verification | Option | Enables or disables SMS notifications. |
| wp_estate_twilio_api_key | Option | Stores the Twilio Account SID. |
| wp_estate_twilio_auth_token | Option | Stores the Twilio Auth Token. |
| wp_estate_twilio_phone_no | Option | Stores the Twilio sender phone number. |
| wp_estate_sms_[type] | Option | Stores the SMS template for a notification type. |
| mobile | User meta | Stores the recipient mobile phone number. |
| check_phone_valid | User meta | Stores whether the user phone number is validated. |
Important Notes
- The SMS flow is connected to the WPRentals email notification flow.
- The main logic is in plugins/wprentals-core/classes/wpestate_email.php.
- The SMS notification depends on the notification type.
- The matching SMS template is stored as wp_estate_sms_[type].
- Most SMS notifications require the user phone to be validated with check_phone_valid = yes.
- SMS templates are plain text and use placeholders replaced before sending.
- Twilio credentials must be configured before SMS can be delivered.
- Twilio delivery issues must be checked in the Twilio logs.
- Do not modify WPRentals Core plugin files directly unless you maintain a controlled custom version.