* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved. * @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html * * @website http://www.wpopal.com * @support http://www.wpopal.com/support/forum.html */ // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) { exit; } /** * @class OpalMembership_Checkout * * @version 1.0 */ class Opalestate_Emails { /** * init action to automatic send email when user edit or submit a new submission and init setting form in plugin setting of admin */ public static function init() { self::load(); if ( is_admin() ) { add_filter( 'opalestate_settings_tabs', [ __CLASS__, 'setting_email_tab' ], 1 ); add_filter( 'opalestate_registered_emails_settings', [ __CLASS__, 'setting_email_fields' ], 10, 1 ); } if ( 'on' === opalestate_get_option( 'enable_customer_new_submission', 'on' ) ) { add_action( 'opalestate_processed_new_submission', [ __CLASS__, 'new_submission_email' ], 10, 2 ); } if ( 'on' === opalestate_get_option( 'enable_admin_new_submission', 'on' ) ) { add_action( 'opalestate_processed_new_submission', [ __CLASS__, 'admin_new_submission_email' ], 15, 2 ); } if ( 'on' === opalestate_get_option( 'enable_approve_property_email', 'on' ) ) { add_action( 'transition_post_status', [ __CLASS__, 'send_email_when_publish_property' ], 10, 3 ); add_action( 'opalestate_processed_approve_publish_property', [ __CLASS__, 'approve_publish_property_email' ], 10, 1 ); } /** * Send email when User contact via Enquiry Form and Contact Form */ add_action( 'opalestate_send_email_notifycation', [ __CLASS__, 'send_notifycation' ] ); add_action( 'opalestate_send_email_submitted', [ __CLASS__, 'new_submission_email' ] ); add_action( 'opalestate_send_email_submitted', [ __CLASS__, 'admin_new_submission_email' ] ); add_action( 'opalestate_send_email_request_reviewing', [ __CLASS__, 'send_email_request_reviewing' ] ); } /** * Load. */ public static function load() { require_once OPALESTATE_PLUGIN_DIR . 'inc/email/class-opalestate-abs-email-template.php'; require_once OPALESTATE_PLUGIN_DIR . 'inc/email/class-opalestate-email-notifycation.php'; require_once OPALESTATE_PLUGIN_DIR . 'inc/email/class-opalestate-request-viewing.php'; require_once OPALESTATE_PLUGIN_DIR . 'inc/email/class-opalestate-new-submitted.php'; require_once OPALESTATE_PLUGIN_DIR . 'inc/email/class-opalestate-admin-new-submitted.php'; require_once OPALESTATE_PLUGIN_DIR . 'inc/email/class-opalestate-approve.php'; } /** * Send Email Notifycation with two types: Enquiry or Contact */ public static function send_notifycation( $content ) { $mail = new OpalEstate_Send_Email_Notification(); $mail->set_args( $content ); $return = self::send_mail_now( $mail ); if ( isset( $content['data'] ) ) { $return['data'] = $content['data']; } echo json_encode( $return ); die(); } /** * send email if agent submit a new property */ public static function new_submission_email( $user_id, $post_id ) { $mail = new OpalEstate_Send_Email_New_Submitted(); $mail->set_pros( $post_id, $user_id ); $return = self::send_mail_now( $mail ); } /** * send email if agent submit a new property */ public static function admin_new_submission_email( $user_id, $post_id ) { $mail = new OpalEstate_Send_Email_Admin_New_Submitted(); $mail->set_pros( $post_id, $user_id ); $return = self::send_mail_now( $mail ); } /** * Send email to requet viewing a property */ public static function send_email_request_reviewing( $content ) { $mail = new OpalEstate_Send_Email_Request_Reviewing(); $mail->set_args( $content ); $return = self::send_mail_now( $mail ); echo json_encode( $return ); die(); } /** * */ public static function send_mail_now( $mail ) { $from_name = $mail->from_name(); $from_email = $mail->from_email(); $headers = sprintf( "From: %s <%s>\r\n Content-type: text/html", $from_name, $from_email ); $subject = $mail->get_subject(); $message = $mail->get_body(); if ( $mail->to_email() ) { if ( $mail->get_cc() ) { $status = @wp_mail( $mail->get_cc(), $subject, $message, $headers ); } $status = @wp_mail( $mail->to_email(), $subject, $message, $headers ); if ( $status ) { return [ 'status' => true, 'msg' => esc_html__( 'Message has been successfully sent.', 'opalestate-pro' ) ]; } else { return [ 'status' => true, 'msg' => esc_html__( 'Unable to send a message.', 'opalestate-pro' ) ]; } } return [ 'status' => true, 'msg' => esc_html__( 'Missing some information!', 'opalestate-pro' ) ]; } /** * */ public static function send_email_when_publish_property( $new_status, $old_status, $post ) { if ( is_object( $post ) ) { if ( $post->post_type == 'opalestate_property' ) { if ( $new_status != $old_status ) { if ( $new_status == 'publish' ) { if ( $old_status == 'draft' || $old_status == 'pending' ) { // Send email $post_id = $post->ID; $author_id = $post->post_author; $author = get_userdata( $author_id ); if ( ! in_array( 'administrator', $author->roles ) && ! in_array( 'opalestate_manager', $author->roles ) && ! in_array( 'opalmembership_manager', $author->roles ) ) { do_action( 'opalestate_processed_approve_publish_property', $post_id ); } } } } } } } /** * add new tab Email in opalestate -> setting */ public static function setting_email_tab( $tabs ) { $tabs['emails'] = esc_html__( 'Email', 'opalestate-pro' ); return $tabs; } public static function newproperty_email_body() { } public static function approve_email_body() { } /** * render setting email fields with default values */ public static function setting_email_fields( $fields ) { $contact_list_tags = '

Use the following tags to automatically add property information to the emails. Tags labeled with an asterisk (*) can be used in the email subject as well.

{receive_name} Name of the agent who made the property
{property_link} Link of the property
{name} Name of the user who contact via email form
{email} Email of the user who contact via email form
{message} * Message content of who sent via form
{site_link} A link to this website
{current_time} Current date and time
'; $review_list_tags = '

Use the following tags to automatically add property information to the emails. Tags labeled with an asterisk (*) can be used in the email subject as well.

{receive_name} Name of the agent who made the property
{property_link} Link of the property
{name} Name of the user who contact via email form
{email} Email of the user who contact via email form
{schedule_time} Schedule time
{schedule_date} Schedule date
{message} * Message content of who sent via form
{site_link} A link to this website
{current_time} Current date and time
'; $list_tags = '

Use the following tags to automatically add property information to the emails. Tags labeled with an asterisk (*) can be used in the email subject as well.

{property_name} Email of the user who made the property
{property_link} Link of the property
{property_edit_link} Link for editing of the property (admin)
{user_email} Email of the user who made the property
{submitted_date} Email of the user who made the property
{user_name} * Name of the user who made the property
{date} * Date and time of the property
{site_name} The name of this website
{site_link} A link to this website
{current_time} Current date and time
'; $list_tags = apply_filters( 'opalestate_email_tags', $list_tags ); $fields = [ 'id' => 'options_page', 'title' => esc_html__( 'Email Settings', 'opalestate-pro' ), 'show_on' => [ 'key' => 'options-page', 'value' => [ 'opalestate_settings' ], ], 'fields' => apply_filters( 'opalestate_settings_emails', [ [ 'name' => esc_html__( 'Email Settings', 'opalestate-pro' ), 'desc' => '
', 'id' => 'opalestate_title_email_settings_1', 'type' => 'title', ], [ 'id' => 'from_name', 'name' => esc_html__( 'From Name', 'opalestate-pro' ), 'desc' => esc_html__( 'The name donation receipts are said to come from. This should probably be your site or shop name.', 'opalestate-pro' ), 'default' => get_bloginfo( 'name' ), 'type' => 'text', ], [ 'id' => 'from_email', 'name' => esc_html__( 'From Email', 'opalestate-pro' ), 'desc' => esc_html__( 'Email to send donation receipts from. This will act as the "from" and "reply-to" address.', 'opalestate-pro' ), 'default' => get_bloginfo( 'admin_email' ), 'type' => 'text', ], [ 'name' => esc_html__( 'Email Submission Templates (Template Tags)', 'opalestate-pro' ), 'desc' => $list_tags . '

', 'id' => 'opalestate_title_email_settings_2', 'type' => 'title', ], //------------------------------------------ [ 'name' => esc_html__( 'New Property Submission (Customer)', 'opalestate-pro' ), 'desc' => '
', 'id' => 'opalestate_title_email_settings_3', 'type' => 'title', ], [ 'name' => esc_html__( 'Enable', 'opalestate-pro' ), 'desc' => esc_html__( 'Enable email for customers when they have a submission.', 'opalestate-pro' ), 'id' => 'enable_customer_new_submission', 'type' => 'switch', 'options' => [ 'on' => esc_html__( 'Enable', 'opalestate-pro' ), 'off' => esc_html__( 'Disable', 'opalestate-pro' ), ], 'default' => 'on', ], [ 'id' => 'newproperty_email_subject', 'name' => esc_html__( 'Email Subject', 'opalestate-pro' ), 'type' => 'text', 'desc' => esc_html__( 'The email subject for admin notifications.', 'opalestate-pro' ), 'attributes' => [ 'rows' => 3, ], 'default' => esc_html__( 'New Property Listing Submitted: {property_name}', 'opalestate-pro' ), ], [ 'id' => 'newproperty_email_body', 'name' => esc_html__( 'Email Body', 'opalestate-pro' ), 'type' => 'wysiwyg', 'desc' => esc_html__( 'Enter the email an admin should receive when an initial payment request is made.', 'opalestate-pro' ), 'default' => OpalEstate_Send_Email_New_Submitted::get_default_template(), ], //------------------------------------------ [ 'name' => esc_html__( 'New Property Submission (Admin)', 'opalestate-pro' ), 'desc' => '
', 'id' => 'opalestate_title_email_settings_admin', 'type' => 'title', 'before_row' => '
', ], [ 'name' => esc_html__( 'Enable', 'opalestate-pro' ), 'desc' => esc_html__( 'Enable email for admin when a property is submitted.', 'opalestate-pro' ), 'id' => 'enable_admin_new_submission', 'type' => 'switch', 'options' => [ 'on' => esc_html__( 'Enable', 'opalestate-pro' ), 'off' => esc_html__( 'Disable', 'opalestate-pro' ), ], 'default' => 'on', ], [ 'id' => 'admin_newproperty_email_subject', 'name' => esc_html__( 'Email Subject', 'opalestate-pro' ), 'type' => 'text', 'desc' => esc_html__( 'The email subject for admin notifications.', 'opalestate-pro' ), 'attributes' => [ 'rows' => 3, ], 'default' => esc_html__( 'You received a new submission: {property_name} from {user_mail}', 'opalestate-pro' ), ], [ 'id' => 'admin_newproperty_email_body', 'name' => esc_html__( 'Email Body', 'opalestate-pro' ), 'type' => 'wysiwyg', 'desc' => esc_html__( 'Enter the email an admin should receive when an initial payment request is made.', 'opalestate-pro' ), 'default' => OpalEstate_Send_Email_Admin_New_Submitted::get_default_template(), ], //------------------------------------------ [ 'name' => esc_html__( 'Approved property for publish (Customer)', 'opalestate-pro' ), 'desc' => '
', 'id' => 'opalestate_title_email_settings_4', 'type' => 'title', 'before_row' => '
', ], [ 'name' => esc_html__( 'Enable approve property email', 'opalestate-pro' ), 'desc' => esc_html__( 'Enable approve property email.', 'opalestate-pro' ), 'id' => 'enable_approve_property_email', 'type' => 'switch', 'options' => [ 'on' => esc_html__( 'Enable', 'opalestate-pro' ), 'off' => esc_html__( 'Disable', 'opalestate-pro' ), ], 'default' => 'on', ], [ 'id' => 'approve_email_subject', 'name' => esc_html__( 'Email Subject', 'opalestate-pro' ), 'type' => 'text', 'desc' => esc_html__( 'The email subject a user should receive when they make an initial property request.', 'opalestate-pro' ), 'attributes' => [ 'placeholder' => 'Your property at I Love WordPress is pending', get_bloginfo( 'name' ), 'rows' => 3, ], 'default' => esc_html__( 'New Property Listing Submitted: {property_name}', 'opalestate-pro' ), ], [ 'id' => 'approve_email_body', 'name' => esc_html__( 'Email Body', 'opalestate-pro' ), 'type' => 'wysiwyg', 'desc' => esc_html__( 'Enter the email a user should receive when they make an initial payment request.', 'opalestate-pro' ), 'default' => OpalEstate_Send_Email_Approve::get_default_template(), ], /// enquire contact template //// [ 'name' => esc_html__( 'Email Enquiry Contact Templates (Template Tags)', 'opalestate-pro' ), 'desc' => $contact_list_tags . '

', 'id' => 'opalestate_title_email_settings_6_1', 'type' => 'title', 'before_row' => '
', ], [ 'id' => 'enquiry_email_subject', 'name' => esc_html__( 'Email Subject', 'opalestate-pro' ), 'type' => 'text', 'desc' => esc_html__( 'The email subject a user should receive when they make an initial property request.', 'opalestate-pro' ), 'attributes' => [ 'placeholder' => 'Your property at I Love WordPress is pending', get_bloginfo( 'name' ), 'rows' => 3, ], 'default' => esc_html__( 'You got a message', 'opalestate-pro' ), ], [ 'id' => 'enquiry_email_body', 'name' => esc_html__( 'Email Body', 'opalestate-pro' ), 'type' => 'wysiwyg', 'default' => OpalEstate_Send_Email_Notification::get_default_template( 'enquiry' ), ], /// email contact template //// [ 'name' => esc_html__( 'Email Contact Templates (Template Tags)', 'opalestate-pro' ), 'desc' => $contact_list_tags . '

', 'id' => 'opalestate_title_email_settings_6', 'type' => 'title', 'before_row' => '
', ], [ 'id' => 'contact_email_subject', 'name' => esc_html__( 'Email Subject', 'opalestate-pro' ), 'type' => 'text', 'desc' => esc_html__( 'The email subject a user should receive when they make an initial property request.', 'opalestate-pro' ), 'attributes' => [ 'placeholder' => 'Your property at I Love WordPress is pending', get_bloginfo( 'name' ), 'rows' => 3, ], 'default' => esc_html__( 'You got a message', 'opalestate-pro' ), ], [ 'id' => 'contact_email_body', 'name' => esc_html__( 'Email Body', 'opalestate-pro' ), 'type' => 'wysiwyg', 'default' => OpalEstate_Send_Email_Notification::get_default_template(), ], /// Email Request Review /// [ 'name' => esc_html__( 'Email Request Review Templates (Template Tags)', 'opalestate-pro' ), 'desc' => $review_list_tags . '

', 'id' => 'opalestate_title_email_settings_7', 'type' => 'title', 'before_row' => '
', ], [ 'id' => 'request_review_email_subject', 'name' => esc_html__( 'Email Subject', 'opalestate-pro' ), 'type' => 'text', 'desc' => esc_html__( 'The email subject a user should receive when they make an initial property request.', 'opalestate-pro' ), 'attributes' => [ 'placeholder' => 'Your property at I Love WordPress is pending', get_bloginfo( 'name' ), 'rows' => 3, ], 'default' => esc_html__( 'You have a message request reviewing', 'opalestate-pro' ), ], [ 'id' => 'request_review_email_body', 'name' => esc_html__( 'Email Body', 'opalestate-pro' ), 'type' => 'wysiwyg', 'default' => OpalEstate_Send_Email_Request_Reviewing::get_default_template(), ], ] ), ]; return $fields; } /** * get data of newrequest email * * @return text: message * @var $args array: property_id , $body */ public static function replace_shortcode( $args, $body ) { $tags = [ 'user_name' => "", 'user_mail' => "", 'submitted_date' => "", 'property_name' => "", 'site_name' => '', 'site_link' => '', 'property_link' => '', ]; $tags = array_merge( $tags, $args ); extract( $tags ); $tags = [ "{user_mail}", "{user_name}", "{submitted_date}", "{site_name}", "{site_link}", "{current_time}", '{property_name}', '{property_link}', ]; $values = [ $user_mail, $user_name, $submitted_date, get_bloginfo( 'name' ), get_home_url(), date( "F j, Y, g:i a" ), $property_name, $property_link, ]; $message = str_replace( $tags, $values, $body ); return $message; } public static function approve_publish_property_email( $post_id ) { $mail = new OpalEstate_Send_Email_Approve(); $mail->set_pros( $post_id ); self::send_mail_now( $mail ); } } Opalestate_Emails::init();