From b72478990758d63366c621ba438377039755a214 Mon Sep 17 00:00:00 2001 From: Hoang Huu Date: Mon, 21 Oct 2019 13:24:14 +0700 Subject: [PATCH] Fix email templates. --- inc/api/class-opalestate-base-api.php | 145 ++++++++++++------ .../class-opalestate-rest-authentication.php | 8 +- inc/api/functions.php | 24 +++ inc/class-opalestate-email.php | 138 +++++++++++++---- .../class-opalestate-abs-email-template.php | 19 +-- .../class-opalestate-admin-new-submitted.php | 27 ++-- inc/email/class-opalestate-approve.php | 91 ++++++----- .../class-opalestate-email-notifycation.php | 44 +++--- inc/email/class-opalestate-new-submitted.php | 62 ++++---- .../class-opalestate-request-viewing.php | 8 +- inc/message/class-opalestate-message.php | 31 ++-- .../class-opalestate-request-reviewing.php | 5 +- opal-estate-pro.php | 6 +- readme.txt | 3 + templates/single-property/author-v2.php | 1 + .../single-property/user/author-user-box.php | 2 +- 16 files changed, 374 insertions(+), 240 deletions(-) diff --git a/inc/api/class-opalestate-base-api.php b/inc/api/class-opalestate-base-api.php index c0198a5d..fc4319c3 100644 --- a/inc/api/class-opalestate-base-api.php +++ b/inc/api/class-opalestate-base-api.php @@ -1,21 +1,20 @@ data['status'] = $code; - $this->data['status'] = $code; return new WP_REST_Response( $this->data ); } @@ -83,10 +76,10 @@ abstract class Opalestate_Base_API { public function validate_request( WP_REST_Request $request ) { return true; - $response = array(); + $response = []; // Make sure we have both user and api key - $api_admin = Opalestate_API_Admin::get_instance(); + $api_admin = Opalestate_API_Admin::get_instance(); if ( empty( $request['token'] ) || empty( $request['key'] ) ) { return $this->missing_auth(); @@ -110,16 +103,15 @@ abstract class Opalestate_Base_API { } } - return false; + return false; } /** * Get page number * * @access public - * @since 1.1 - * @global $wp_query * @return int $wp_query->query_vars['page'] if page number returned (default: 1) + * @global $wp_query */ public function get_paged() { global $wp_query; @@ -132,27 +124,26 @@ abstract class Opalestate_Base_API { * Number of results to display per page * * @access public - * @since 1.1 - * @global $wp_query * @return int $per_page Results to display per page (default: 10) + * @global $wp_query */ public function per_page() { global $wp_query; $per_page = isset( $wp_query->query_vars['number'] ) ? $wp_query->query_vars['number'] : 10; - + return apply_filters( 'opalestate_api_results_per_page', $per_page ); } /** * Get object. * - * @param int $id Object ID. + * @param int $id Object ID. * @return object WC_Data object or WP_Error object. */ protected function get_object( $id ) { // translators: %s: Class method name. - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'opalestate-pro' ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'opalestate-pro' ), __METHOD__ ), [ 'status' => 405 ] ); } /** @@ -161,10 +152,9 @@ abstract class Opalestate_Base_API { * * @access private * @return WP_Error with message key rest_forbidden - * @since 1.1 */ - private function missing_auth() { - return new WP_Error( 'rest_forbidden', esc_html__( 'You must specify both a token and API key!' ), array( 'status' => rest_authorization_required_code() ) ); + private function missing_auth() { + return new WP_Error( 'rest_forbidden', esc_html__( 'You must specify both a token and API key!' ), [ 'status' => rest_authorization_required_code() ] ); } /** @@ -175,7 +165,7 @@ abstract class Opalestate_Base_API { * @return WP_Error with message key rest_forbidden */ private function invalid_auth() { - return new WP_Error( 'rest_forbidden', esc_html__( 'Your request could not be authenticated!', 'opaljob' ), array( 'status' => 403 ) ); + return new WP_Error( 'rest_forbidden', esc_html__( 'Your request could not be authenticated!', 'opaljob' ), [ 'status' => 403 ] ); } /** @@ -183,38 +173,93 @@ abstract class Opalestate_Base_API { * validated * * @access private - * @since 1.1 * @return WP_Error with message key rest_forbidden */ private function invalid_key() { - return new WP_Error( 'rest_forbidden', esc_html__( 'Invalid API key!' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( 'rest_forbidden', esc_html__( 'Invalid API key!' ), [ 'status' => rest_authorization_required_code() ] ); } /** * Check if a given request has access to read items. * - * @param WP_REST_Request $request Full details about the request. + * @param WP_REST_Request $request Full details about the request. * @return WP_Error|boolean */ public function get_items_permissions_check( $request ) { + $is_valid = $this->is_valid_api_key( $request ); + if ( is_wp_error( $is_valid ) ) { + return $is_valid; + } + if ( ! opalestate_rest_check_post_permissions( $this->post_type, 'read' ) ) { - return new WP_Error( 'opalestate_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'opalestate-pro' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( 'opalestate_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'opalestate-pro' ), [ 'status' => rest_authorization_required_code() ] ); } return true; } + /** + * Check if a given request has access. + * + * @param WP_REST_Request $request Full details about the request. + * @return WP_Error|boolean + */ + public function is_valid_api_key( $request ) { + // if ( ! $this->is_request_to_rest_api() ) { + // return false; + // } + + if ( isset( $request['consumer_key'] ) && $request['consumer_secret'] ) { + $user = opalestate_get_user_data_by_consumer_key( $request['consumer_key'] ); + + if ( $user ) { + if ( $request['consumer_secret'] === $user->consumer_secret ) { + $route = $request->get_route(); + $endpoint = explode( '/', $route ); + $endpoint = end( $endpoint ); + if ( in_array( $endpoint, [ 'properties' ] ) ) { + return true; + } + } + } + } + + return new WP_Error( 'opalestate_rest_cannot_access', __( 'Sorry, you cannot list resources.', 'opalestate-pro' ), [ 'status' => rest_authorization_required_code() ] ); + } + + /** + * Check if is request to our REST API. + * + * @return bool + */ + protected function is_request_to_rest_api() { + if ( empty( $_SERVER['REQUEST_URI'] ) ) { + return false; + } + + $rest_prefix = trailingslashit( rest_get_url_prefix() ); + $request_uri = esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ); + + // Check if the request is to the Opalestate API endpoints. + $opalestate = ( false !== strpos( $request_uri, $rest_prefix . 'estate-api/' ) ); + + // Allow third party plugins use our authentication methods. + $third_party = ( false !== strpos( $request_uri, $rest_prefix . 'estate-api-' ) ); + + return apply_filters( 'opalestate_rest_is_request_to_rest_api', $opalestate || $third_party ); + } + /** * Check if a given request has access to read an item. * - * @param WP_REST_Request $request Full details about the request. + * @param WP_REST_Request $request Full details about the request. * @return WP_Error|boolean */ public function get_item_permissions_check( $request ) { $object = $this->get_object( (int) $request['id'] ); if ( $object && 0 !== $object->get_id() && ! opalestate_rest_check_post_permissions( $this->post_type, 'read', $object->get_id() ) ) { - return new WP_Error( 'opalestate_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'opalestate-pro' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( 'opalestate_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'opalestate-pro' ), [ 'status' => rest_authorization_required_code() ] ); } return true; @@ -223,12 +268,12 @@ abstract class Opalestate_Base_API { /** * Check if a given request has access to create an item. * - * @param WP_REST_Request $request Full details about the request. + * @param WP_REST_Request $request Full details about the request. * @return WP_Error|boolean */ public function create_item_permissions_check( $request ) { if ( ! opalestate_rest_check_post_permissions( $this->post_type, 'create' ) ) { - return new WP_Error( 'opalestate_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'opalestate-pro' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( 'opalestate_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'opalestate-pro' ), [ 'status' => rest_authorization_required_code() ] ); } return true; @@ -237,14 +282,14 @@ abstract class Opalestate_Base_API { /** * Check if a given request has access to update an item. * - * @param WP_REST_Request $request Full details about the request. + * @param WP_REST_Request $request Full details about the request. * @return WP_Error|boolean */ public function update_item_permissions_check( $request ) { $object = $this->get_object( (int) $request['id'] ); if ( $object && 0 !== $object->get_id() && ! opalestate_rest_check_post_permissions( $this->post_type, 'edit', $object->get_id() ) ) { - return new WP_Error( 'opalestate_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'opalestate-pro' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( 'opalestate_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'opalestate-pro' ), [ 'status' => rest_authorization_required_code() ] ); } return true; diff --git a/inc/api/class-opalestate-rest-authentication.php b/inc/api/class-opalestate-rest-authentication.php index 42761ab1..ad616ac3 100644 --- a/inc/api/class-opalestate-rest-authentication.php +++ b/inc/api/class-opalestate-rest-authentication.php @@ -37,10 +37,10 @@ class Opalestate_REST_Authentication { * Initialize authentication actions. */ public function __construct() { - add_filter( 'determine_current_user', [ $this, 'authenticate' ], 15 ); - add_filter( 'rest_authentication_errors', [ $this, 'check_authentication_error' ], 15 ); - add_filter( 'rest_post_dispatch', [ $this, 'send_unauthorized_headers' ], 50 ); - add_filter( 'rest_pre_dispatch', [ $this, 'check_user_permissions' ], 10, 3 ); + // add_filter( 'determine_current_user', [ $this, 'authenticate' ], 15 ); + // add_filter( 'rest_authentication_errors', [ $this, 'check_authentication_error' ], 15 ); + // add_filter( 'rest_post_dispatch', [ $this, 'send_unauthorized_headers' ], 50 ); + // add_filter( 'rest_pre_dispatch', [ $this, 'check_user_permissions' ], 10, 3 ); } /** diff --git a/inc/api/functions.php b/inc/api/functions.php index dc1426ed..3ffd169e 100644 --- a/inc/api/functions.php +++ b/inc/api/functions.php @@ -27,6 +27,30 @@ function opalestate_rest_check_post_permissions( $post_type, $context = 'read', return apply_filters( 'opalestate_rest_check_permissions', $permission, $context, $object_id, $post_type ); } +/** + * Return the user data for the given consumer_key. + * + * @param string $consumer_key Consumer key. + * @return array + */ +function opalestate_get_user_data_by_consumer_key( $consumer_key ) { + global $wpdb; + + $consumer_key = opalestate_api_hash( sanitize_text_field( $consumer_key ) ); + $user = $wpdb->get_row( + $wpdb->prepare( + " + SELECT key_id, user_id, permissions, consumer_key, consumer_secret, nonces + FROM {$wpdb->prefix}opalestate_api_keys + WHERE consumer_key = %s + ", + $consumer_key + ) + ); + + return $user; +} + /** * The opalestate_property post object, generate the data for the API output * diff --git a/inc/class-opalestate-email.php b/inc/class-opalestate-email.php index 495b4235..348b94bc 100755 --- a/inc/class-opalestate-email.php +++ b/inc/class-opalestate-email.php @@ -23,16 +23,14 @@ if ( ! defined( 'ABSPATH' ) ) { * @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(); add_action( 'opalestate_processed_new_submission', [ __CLASS__, 'new_submission_email' ], 10, 2 ); + add_action( 'opalestate_processed_new_submission', [ __CLASS__, 'admin_new_submission_email' ], 15, 2 ); //add_action( 'opalestate_processed_edit_submission' , array( __CLASS__ , 'new_submission_email'), 10, 2 ); if ( is_admin() ) { add_filter( 'opalestate_settings_tabs', [ __CLASS__, 'setting_email_tab' ], 1 ); @@ -51,18 +49,19 @@ class Opalestate_Emails { */ 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'; } @@ -91,9 +90,15 @@ class Opalestate_Emails { $mail = new OpalEstate_Send_Email_New_Submitted(); $mail->set_pros( $post_id, $user_id ); $return = self::send_mail_now( $mail ); + } - // echo json_encode( $return ); - // die(); + /** + * 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 ); } /** @@ -190,7 +195,7 @@ class Opalestate_Emails {
- {property_link} Property of the user who made the property + {property_link} Link of the property
@@ -200,14 +205,59 @@ class Opalestate_Emails {
{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 + {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 +
'; @@ -219,7 +269,11 @@ class Opalestate_Emails {
- {property_link} Email of the user who made the property + {property_link} Link of the property +
+ +
+ {property_edit_link} Link for editing of the property (admin)
@@ -287,24 +341,19 @@ class Opalestate_Emails { //------------------------------------------ - - [ - 'name' => esc_html__( 'Notification For New Property Submission', 'opalestate-pro' ), + 'name' => esc_html__( 'Notification For New Property Submission (Customer)', 'opalestate-pro' ), 'desc' => '
', 'id' => 'opalestate_title_email_settings_3', 'type' => 'title', ], - - [ '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' => [ - 'placeholder' => 'Your package is expired', - 'rows' => 3, + 'rows' => 3, ], 'default' => esc_html__( 'New Property Listing Submitted: {property_name}', 'opalestate-pro' ), @@ -317,6 +366,33 @@ class Opalestate_Emails { 'default' => OpalEstate_Send_Email_New_Submitted::get_default_template(), ], //------------------------------------------ + + [ + 'name' => esc_html__( 'Notification For New Property Submission (Admin)', 'opalestate-pro' ), + 'desc' => '
', + 'id' => 'opalestate_title_email_settings_admin', + 'type' => 'title', + ], + [ + '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__( 'Approve property for publish', 'opalestate-pro' ), 'desc' => '
', @@ -377,10 +453,10 @@ class Opalestate_Emails { ], [ - 'id' => 'enquiry_email_body', - 'name' => esc_html__( 'Email Body', 'opalestate-pro' ), - 'type' => 'wysiwyg', - 'default' => OpalEstate_Send_Email_Notification::get_default_template( 'enquiry' ) + '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 //// [ @@ -403,15 +479,15 @@ class Opalestate_Emails { ], [ - 'id' => 'contact_email_body', - 'name' => esc_html__( 'Email Body', 'opalestate-pro' ), - 'type' => 'wysiwyg', - 'default' => OpalEstate_Send_Email_Notification::get_default_template() + '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' => $contact_list_tags . '

', + 'desc' => $review_list_tags . '

', 'id' => 'opalestate_title_email_settings_7', 'type' => 'title', ], @@ -425,14 +501,14 @@ class Opalestate_Emails { get_bloginfo( 'name' ), 'rows' => 3, ], - 'default' =>esc_html__( 'You have a message request reviewing at: %s', 'opalestate-pro' ), + '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() + 'id' => 'request_review_email_body', + 'name' => esc_html__( 'Email Body', 'opalestate-pro' ), + 'type' => 'wysiwyg', + 'default' => OpalEstate_Send_Email_Request_Reviewing::get_default_template(), ], ] ), diff --git a/inc/email/class-opalestate-abs-email-template.php b/inc/email/class-opalestate-abs-email-template.php index b2078d11..a29ce569 100755 --- a/inc/email/class-opalestate-abs-email-template.php +++ b/inc/email/class-opalestate-abs-email-template.php @@ -69,15 +69,16 @@ class OpalEstate_Abstract_Email_Template { public function replace_tags( $template ) { $args = $this->args; $default = [ - 'receiver_name' => '', - 'name' => '', - 'receiver_email' => '', - 'property_link' => '', - 'message' => '', - 'site_name' => get_bloginfo(), - 'site_link' => get_home_url(), - 'current_time' => date( "F j, Y, g:i a" ), - 'phone' => '', + 'receiver_name' => '', + 'name' => '', + 'receiver_email' => '', + 'property_link' => '', + 'property_edit_link' => '', + 'message' => '', + 'site_name' => get_bloginfo(), + 'site_link' => get_home_url(), + 'current_time' => date( "F j, Y, g:i a" ), + 'phone' => '', ]; $args = array_merge( $default, $args ); diff --git a/inc/email/class-opalestate-admin-new-submitted.php b/inc/email/class-opalestate-admin-new-submitted.php index 44106023..c30fa5c1 100644 --- a/inc/email/class-opalestate-admin-new-submitted.php +++ b/inc/email/class-opalestate-admin-new-submitted.php @@ -21,11 +21,10 @@ class OpalEstate_Send_Email_Admin_New_Submitted extends OpalEstate_Abstract_Emai * Send Email */ public function get_subject() { - $propety_title = ''; - $d = esc_html__( 'New Property Listing Submitted: {property_name}', 'opalestate-pro' ); - $s = opalestate_get_option( 'admin_newproperty_email_subject', $d ); + $d = esc_html__( 'You received a new submission: {property_name} from {user_mail}', 'opalestate-pro' ); + $s = opalestate_get_option( 'admin_newproperty_email_subject', $d ); - return $s; + return $this->replace_tags( $s ); } /** @@ -38,19 +37,19 @@ class OpalEstate_Send_Email_Admin_New_Submitted extends OpalEstate_Abstract_Emai $email = $email ? $email : $user->data->user_email; $this->args = [ - 'receiver_email' => $email, - 'user_mail' => $email, - 'user_name' => $user->display_name, - 'submitted_date' => $property->post_date, - 'property_name' => $property->post_title, - 'property_link' => get_permalink( $property_id ), - 'current_time' => date( "F j, Y, g:i a" ), + 'receiver_email' => $email, + 'user_mail' => $email, + 'user_name' => $user->display_name, + 'submitted_date' => $property->post_date, + 'property_name' => $property->post_title, + 'property_link' => get_permalink( $property_id ), + 'property_edit_link' => get_edit_post_link( $property_id ), + 'current_time' => date( "F j, Y, g:i a" ), ]; return $this->args; } - /** * Send Email */ @@ -65,7 +64,7 @@ class OpalEstate_Send_Email_Admin_New_Submitted extends OpalEstate_Abstract_Emai */ public static function get_default_template() { return trim( preg_replace( '/\t+/', '', ' - You’ve received a submission from %s: {user_name}, + You’ve received a submission from: {user_name},
You can review it by follow this link: {property_edit_link} This message was sent by {site_link} on {current_time}.' @@ -76,7 +75,7 @@ class OpalEstate_Send_Email_Admin_New_Submitted extends OpalEstate_Abstract_Emai * Send Email */ public function to_email() { - return $this->args ['receiver_email']; + return $this->from_email(); } /** diff --git a/inc/email/class-opalestate-approve.php b/inc/email/class-opalestate-approve.php index 0f5f8441..a33b530a 100644 --- a/inc/email/class-opalestate-approve.php +++ b/inc/email/class-opalestate-approve.php @@ -11,7 +11,7 @@ * @website http://www.wpopal.com * @support http://www.wpopal.com/support/forum.html */ - + if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } @@ -22,57 +22,55 @@ if ( ! defined( 'ABSPATH' ) ) { * @version 1.0 */ class OpalEstate_Send_Email_Approve extends OpalEstate_Abstract_Email_Template { - - /** - * - */ - public function get_subject () { - $propety_title = '' ; - - $subject = sprintf( esc_html__( 'The Property Listing Approved: {property_name}', 'opalestate-pro' ), $propety_title ); - $subject = opalestate_options( 'approve_email_body' , $subject ); - return $subject; + /** + * Get subject. + */ + public function get_subject() { + $subject = esc_html__( 'The Property Listing Approved: {property_name}', 'opalestate-pro' ); + $subject = opalestate_options( 'approve_email_body', $subject ); + + return $this->replace_tags( $subject ); } /** - * get collection of key and value base on tags which using to replace custom tags + * Get collection of key and value base on tags which using to replace custom tags */ - public function set_pros( $property_id ){ - - $property = get_post( $property_id ); - $user = get_userdata( $property->post_author ); - $email = get_user_meta( $property->post_author, OPALESTATE_USER_PROFILE_PREFIX . 'email', true ); - $email = $email ? $email : $user->data->user_email; + public function set_pros( $property_id ) { + $property = get_post( $property_id ); + $user = get_userdata( $property->post_author ); + $email = get_user_meta( $property->post_author, OPALESTATE_USER_PROFILE_PREFIX . 'email', true ); + $email = $email ? $email : $user->data->user_email; - $this->args = array( - 'receiver_email' => $email, - 'user_mail' => $email, - 'user_name' => $user->display_name, - 'submitted_date' => $property->post_date, - 'property_name' => $property->post_title, - 'property_link' => get_permalink( $property_id ), - 'current_time' => date("F j, Y, g:i a"), - ); + $this->args = [ + 'receiver_email' => $email, + 'user_mail' => $email, + 'user_name' => $user->display_name, + 'submitted_date' => $property->post_date, + 'property_name' => $property->post_title, + 'property_link' => get_permalink( $property_id ), + 'current_time' => date( "F j, Y, g:i a" ), + ]; - return $this->args ; + return $this->args; } /** - * + * */ public function get_content_template() { - $content = opalestate_options( 'approve_email_body' , self::get_default_template() ); - return $content; - } + $content = opalestate_options( 'approve_email_body', self::get_default_template() ); + + return $content; + } /** * */ public static function get_default_template() { - - return trim(preg_replace('/\t+/', '', "Hi {user_name},
+ + return trim( preg_replace( '/\t+/', '', "Hi {user_name},

Thank you so much for submitting to {site_name}.
@@ -83,34 +81,35 @@ class OpalEstate_Send_Email_Approve extends OpalEstate_Abstract_Email_Template {
 

- This message was sent by {site_link} on {current_time}.")); + This message was sent by {site_link} on {current_time}." ) ); } /** - * + * */ - public function to_email () { + public function to_email() { return $this->args ['receiver_email']; } /** - * + * */ - public function cc_email () { + public function cc_email() { return $this->args ['sender_email']; } /** - * + * */ public function get_body() { - - $post = get_post( $this->args['post_id'] ); - - $this->args['email'] = $this->args['receiver_email']; - $this->args['property_link'] = $post->post_title; + + $post = get_post( $this->args['post_id'] ); + + $this->args['email'] = $this->args['receiver_email']; + $this->args['property_link'] = $post->post_title; return parent::get_body(); } } -?> \ No newline at end of file + +?> diff --git a/inc/email/class-opalestate-email-notifycation.php b/inc/email/class-opalestate-email-notifycation.php index b28eb837..e75dfdba 100755 --- a/inc/email/class-opalestate-email-notifycation.php +++ b/inc/email/class-opalestate-email-notifycation.php @@ -18,38 +18,36 @@ if ( ! defined( 'ABSPATH' ) ) { /** * @class OpalEstate_Send_Email_Notification - * - * @version 1.0 */ class OpalEstate_Send_Email_Notification extends OpalEstate_Abstract_Email_Template { public $type = ''; - + /** * Send Email */ - public function get_subject () { + public function get_subject() { switch ( $this->type ) { case 'enquiry': - $subject = html_entity_decode( esc_html__('You got a message enquiry', 'opalestate-pro') ); + $subject = html_entity_decode( esc_html__( 'You got a message enquiry', 'opalestate-pro' ) ); $subject = opalestate_options( 'enquiry_email_subject', $subject ); - + break; - + default: - $subject = html_entity_decode( esc_html__('You got a message contact', 'opalestate-pro') ); + $subject = html_entity_decode( esc_html__( 'You got a message contact', 'opalestate-pro' ) ); $subject = opalestate_options( 'contact_email_subject', $subject ); break; } - return $subject; + return $subject; } /** - * Send Email + * Send Email. */ public function get_content_template() { switch ( $this->type ) { @@ -57,32 +55,36 @@ class OpalEstate_Send_Email_Notification extends OpalEstate_Abstract_Email_Templ return opalestate_options( 'enquiry_email_body', self::get_default_template( 'enquiry' ) ); break; default: - return opalestate_options( 'contact_email_body', self::get_default_template( ) ); + return opalestate_options( 'contact_email_body', self::get_default_template() ); break; } - } + } - public function to_email () { + public function to_email() { return $this->args ['receiver_email']; } - public function cc_email () { + public function cc_email() { return $this->args ['sender_email']; } public function get_body() { - $this->args['email'] = $this->args['receiver_email']; + $this->args['email'] = $this->args['sender_email']; + return parent::get_body(); } - /***/ - public static function get_default_template ( $type='contact' ) { - - if( $type == 'enquiry' ) { + /** + * Get default template. + * + * @param string $type + * @return string + */ + public static function get_default_template( $type = 'contact' ) { + if ( $type == 'enquiry' ) { return opalestate_load_template_path( 'emails/enquiry' ); } - return opalestate_load_template_path( 'emails/contact' ); + return opalestate_load_template_path( 'emails/contact' ); } } -?> \ No newline at end of file diff --git a/inc/email/class-opalestate-new-submitted.php b/inc/email/class-opalestate-new-submitted.php index efa4bfc4..8f274fdc 100755 --- a/inc/email/class-opalestate-new-submitted.php +++ b/inc/email/class-opalestate-new-submitted.php @@ -11,7 +11,7 @@ * @website http://www.wpopal.com * @support http://www.wpopal.com/support/forum.html */ - + if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } @@ -19,41 +19,39 @@ if ( ! defined( 'ABSPATH' ) ) { /** * @class OpalEstate_Send_Email_Notification * - * @version 1.0 */ class OpalEstate_Send_Email_New_Submitted extends OpalEstate_Abstract_Email_Template { - + /** * Send Email */ - public function get_subject () { - $propety_title = '' ; - $d = esc_html__( 'New Property Listing Submitted: {property_name}', 'opalestate-pro' ); - $s = opalestate_get_option( 'newproperty_email_subject' , $d ); - return $s; + public function get_subject() { + $d = esc_html__( 'New Property Listing Submitted: {property_name}', 'opalestate-pro' ); + $s = opalestate_get_option( 'newproperty_email_subject', $d ); + + return $this->replace_tags( $s ); } /** * get collection of key and value base on tags which using to replace custom tags */ - public function set_pros( $property_id, $user_id ){ - - $property = get_post( $property_id ); - $user = get_userdata( $property->post_author ); - $email = get_user_meta( $property->post_author, OPALESTATE_USER_PROFILE_PREFIX . 'email', true ); - $email = $email ? $email : $user->data->user_email; + public function set_pros( $property_id, $user_id ) { + $property = get_post( $property_id ); + $user = get_userdata( $property->post_author ); + $email = get_user_meta( $property->post_author, OPALESTATE_USER_PROFILE_PREFIX . 'email', true ); + $email = $email ? $email : $user->data->user_email; - $this->args = array( - 'receiver_email' => $email, - 'user_mail' => $email, - 'user_name' => $user->display_name, - 'submitted_date' => $property->post_date, - 'property_name' => $property->post_title, - 'property_link' => get_permalink( $property_id ), - 'current_time' => date("F j, Y, g:i a"), - ); + $this->args = [ + 'receiver_email' => $email, + 'user_mail' => $email, + 'user_name' => $user->display_name, + 'submitted_date' => $property->post_date, + 'property_name' => $property->post_title, + 'property_link' => get_permalink( $property_id ), + 'current_time' => date( "F j, Y, g:i a" ), + ]; - return $this->args ; + return $this->args; } @@ -62,16 +60,17 @@ class OpalEstate_Send_Email_New_Submitted extends OpalEstate_Abstract_Email_Temp */ public function get_content_template() { - $body = opalestate_get_option( 'newproperty_email_body', self::get_default_template() ); - return $body; - } + $body = opalestate_get_option( 'newproperty_email_body', self::get_default_template() ); + + return $body; + } /** * Send Email */ public static function get_default_template() { - - return trim(preg_replace('/\t+/', '',' + + return trim( preg_replace( '/\t+/', '', ' Hi {user_name},
Thanks you so much for submitting {property_name} at {site_name}:
@@ -87,14 +86,14 @@ class OpalEstate_Send_Email_New_Submitted extends OpalEstate_Abstract_Email_Temp /** * Send Email */ - public function to_email () { + public function to_email() { return $this->args ['receiver_email']; } /** * Send Email */ - public function cc_email () { + public function cc_email() { return $this->args ['sender_email']; } @@ -105,4 +104,3 @@ class OpalEstate_Send_Email_New_Submitted extends OpalEstate_Abstract_Email_Temp return parent::get_body(); } } -?> \ No newline at end of file diff --git a/inc/email/class-opalestate-request-viewing.php b/inc/email/class-opalestate-request-viewing.php index 8eda4242..7d7a8077 100755 --- a/inc/email/class-opalestate-request-viewing.php +++ b/inc/email/class-opalestate-request-viewing.php @@ -27,9 +27,7 @@ class OpalEstate_Send_Email_Request_Reviewing extends OpalEstate_Abstract_Email_ * Send Email */ public function get_subject() { - $propety_title = ''; - - $content = sprintf( esc_html__( 'You have a message request reviewing: %s at', 'opalestate-pro' ), $propety_title ); + $content = esc_html__( 'You have a message request reviewing', 'opalestate-pro' ); $content = opalestate_options( 'request_review_email_subject', $content ); return $content; @@ -40,6 +38,7 @@ class OpalEstate_Send_Email_Request_Reviewing extends OpalEstate_Abstract_Email_ */ public function get_content_template() { $content = opalestate_options( 'request_review_email_body', self::get_default_template() ); + return $content; } @@ -63,7 +62,7 @@ class OpalEstate_Send_Email_Request_Reviewing extends OpalEstate_Abstract_Email_ public function get_body() { $post = get_post( $this->args['post_id'] ); - $this->args['email'] = $this->args['receiver_email']; + // $this->args['email'] = $this->args['receiver_email']; $this->args['property_link'] = get_permalink( $post->ID ); $this->args['property_name'] = $post->post_title; @@ -73,5 +72,4 @@ class OpalEstate_Send_Email_Request_Reviewing extends OpalEstate_Abstract_Email_ public static function get_default_template() { return opalestate_load_template_path( 'emails/request-reviewing' ); } - } diff --git a/inc/message/class-opalestate-message.php b/inc/message/class-opalestate-message.php index 9efe875f..f31a8f9d 100755 --- a/inc/message/class-opalestate-message.php +++ b/inc/message/class-opalestate-message.php @@ -98,7 +98,6 @@ class OpalEstate_User_Message { * Set values when user logined in system */ public function send_equiry( $post, $member ) { - $default = [ 'send_equiry_name' => '', 'action' => '', @@ -109,9 +108,8 @@ class OpalEstate_User_Message { 'message' => '', 'message_action' => '', ]; - $post = array_merge( $default, $post ); - + $post = array_merge( $default, $post ); $post['property_link'] = (int) $post['post_id'] ? get_permalink( $post['post_id'] ) : get_home_url(); $post['receive_name'] = isset( $member['name'] ) ? $member['name'] : ''; $subject = html_entity_decode( esc_html__( 'You got a message', 'opalestate-pro' ) ); @@ -119,11 +117,12 @@ class OpalEstate_User_Message { $output = [ 'subject' => $subject, - 'name' => isset( $member['name'] ) ? $member['name'] : '', + 'name' => isset( $post['name'] ) ? $post['name'] : '', 'receiver_email' => $member['receiver_email'], 'receiver_id' => $member['receiver_id'], 'sender_id' => get_current_user_id(), 'sender_email' => $post['email'], + 'email' => $post['email'], 'phone' => $post['phone'], 'message' => $post['message'], 'post_id' => $post['post_id'], @@ -203,7 +202,6 @@ class OpalEstate_User_Message { * Set values when user logined in system */ public function get_member_email_data( $post_id ) { - return opalestate_get_member_email_data( $post_id ); } @@ -251,7 +249,6 @@ class OpalEstate_User_Message { echo json_encode( $return ); die(); - } /** @@ -284,7 +281,7 @@ class OpalEstate_User_Message { $this->insert( $content ); } - // send email for user to inbox email. + // Send email for user to inbox email. do_action( 'opalestate_send_email_notifycation', $content ); } } @@ -299,7 +296,6 @@ class OpalEstate_User_Message { * */ public function insert( $data ) { - global $wpdb; $args = [ @@ -326,7 +322,6 @@ class OpalEstate_User_Message { } public function insert_reply( $data ) { - global $wpdb; $args = [ @@ -667,11 +662,12 @@ class OpalEstate_User_Message { } public function get_request_review_form_fields( $msg = '' ) { + global $wp_query; $prefix = ''; $id = ''; $sender_id = ''; - $post_id = get_the_ID(); + $post_id = $wp_query->post->ID; $email = ''; $current_user = wp_get_current_user(); $name = ''; @@ -684,25 +680,22 @@ class OpalEstate_User_Message { $fields = [ [ - 'id' => "type", + 'id' => 'type', 'name' => esc_html__( 'Type', 'opalestate-pro' ), 'type' => 'hidden', 'default' => 'send_request_review', - 'description' => "", ], [ - 'id' => "post_id", + 'id' => 'post_id', 'name' => esc_html__( 'Property ID', 'opalestate-pro' ), 'type' => 'hidden', 'default' => $post_id, - 'description' => "", ], [ - 'id' => "sender_id", + 'id' => 'sender_id', 'name' => esc_html__( 'Sender ID', 'opalestate-pro' ), 'type' => 'hidden', 'default' => $sender_id, - 'description' => "", ], [ 'id' => "{$prefix}date", @@ -710,32 +703,26 @@ class OpalEstate_User_Message { 'type' => 'date', 'before_row' => '', 'required' => 'required', - 'description' => "", ], [ 'id' => "{$prefix}time", 'name' => esc_html__( 'Time', 'opalestate-pro' ), 'type' => 'select', 'options' => opalestate_get_time_lapses(), - 'description' => "", ], [ 'id' => "{$prefix}phone", 'name' => esc_html__( 'Phone', 'opalestate-pro' ), 'type' => 'text', - 'description' => "", 'required' => 'required', ], - [ 'id' => "{$prefix}message", 'name' => esc_html__( 'Message', 'opalestate-pro' ), 'type' => 'textarea', - 'description' => "", 'default' => $msg, 'required' => 'required', ], - ]; return $fields; diff --git a/inc/message/class-opalestate-request-reviewing.php b/inc/message/class-opalestate-request-reviewing.php index f1120e02..6de5fafa 100755 --- a/inc/message/class-opalestate-request-reviewing.php +++ b/inc/message/class-opalestate-request-reviewing.php @@ -74,10 +74,10 @@ class OpalEstate_User_Request_Viewing { if ( wp_verify_nonce( $_POST['message_action'], 'property-request-view' ) ) { $post = $_POST; $member = $this->get_member_email_data( absint( $post['post_id'] ) ); - + $user = get_userdata( $this->user_id ); $output = [ 'subject' => isset( $subject ) && $subject ? esc_html( $subject ) : '', - 'name' => esc_html( $member['receiver_name'] ), + 'name' => $user->display_name ? esc_html( $user->display_name ) : esc_html( $user->user_nicename ), 'receiver_email' => sanitize_email( $member['receiver_email'] ), 'receiver_id' => sanitize_text_field( $member['receiver_id'] ), 'sender_id' => get_current_user_id(), @@ -87,6 +87,7 @@ class OpalEstate_User_Request_Viewing { 'schedule_time' => sanitize_text_field( $post['time'] ), 'schedule_date' => sanitize_text_field( $post['date'] ), 'post_id' => absint( $post['post_id'] ), + 'email' => $user->user_email, ]; $this->insert( $output ); diff --git a/opal-estate-pro.php b/opal-estate-pro.php index 065443aa..ce8ba843 100755 --- a/opal-estate-pro.php +++ b/opal-estate-pro.php @@ -3,7 +3,7 @@ * Plugin Name: Opal Estate Pro * Plugin URI: http://www.wpopal.com/product/opal-estate-wordpress-plugin/ * Description: Opal Real Estate Plugin is an ideal solution and brilliant choice for you to set up a professional estate website. - * Version: 1.1.4 + * Version: 1.1.5 * Author: WPOPAL * Author URI: http://www.wpopal.com * Requires at least: 4.6 @@ -151,7 +151,7 @@ if ( ! class_exists( 'OpalEstate' ) ) { */ public function __clone() { // Cloning instances of the class is forbidden - _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'opalestate-pro' ), '1.1.4' ); + _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'opalestate-pro' ), '1.1.5' ); } /** @@ -160,7 +160,7 @@ if ( ! class_exists( 'OpalEstate' ) ) { public function setup_constants() { // Plugin version if ( ! defined( 'OPALESTATE_VERSION' ) ) { - define( 'OPALESTATE_VERSION', '1.1.4' ); + define( 'OPALESTATE_VERSION', '1.1.5' ); } // Plugin Folder Path diff --git a/readme.txt b/readme.txt index d8820c97..53592c52 100755 --- a/readme.txt +++ b/readme.txt @@ -153,6 +153,9 @@ This section describes how to install the plugin and get it working. * System tickets support 24/7 available : [free support](https://wpopal.ticksy.com/ "Visit the Plugin support Page") == Changelog == += 1.1.5 - 2019-10-21 = +* Fixes - Email templates. + = 1.1.4 - 2019-10-17 = * Fixes - Properties collection pagination. * Fixes - Agents collection pagination. diff --git a/templates/single-property/author-v2.php b/templates/single-property/author-v2.php index eacb7d4a..4e6742e7 100755 --- a/templates/single-property/author-v2.php +++ b/templates/single-property/author-v2.php @@ -13,6 +13,7 @@ if ( opalestate_get_option( 'enable_single_author_box' , 'on') != 'on' ) { $type = $property->get_author_type(); $data = get_userdata( $post->post_author ); $layout = ''; + switch ( $type ) { case 'hide': return; diff --git a/templates/single-property/user/author-user-box.php b/templates/single-property/user/author-user-box.php index e4dc32a8..572f9da0 100755 --- a/templates/single-property/user/author-user-box.php +++ b/templates/single-property/user/author-user-box.php @@ -68,7 +68,7 @@ ?>

- + user_email; ?>