Merge pull request #7 from wpopal/develop

Develop
This commit is contained in:
wpopal 2019-10-21 13:25:04 +07:00 committed by GitHub
commit 962026a37b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 389 additions and 246 deletions

View File

@ -1,8 +1,8 @@
<?php
/**
* Abstract class to define/implement base methods for all controller classes
*
* @since 1.0.0
* @package Opal_Job
* @subpackage Opal_Job/controllers
*/
@ -11,11 +11,10 @@ abstract class Opalestate_Base_API {
/**
* The unique identifier of this plugin.
*
* @since 1.0.0
* @access protected
* @var string $plugin_base_name The string used to uniquely identify this plugin.
*/
public $base ;
public $base;
/**
* Post type.
@ -27,7 +26,6 @@ abstract class Opalestate_Base_API {
/**
* The unique identifier of this plugin.
*
* @since 1.0.0
* @access protected
* @var string $plugin_base_name The string used to uniquely identify this plugin.
*/
@ -36,41 +34,36 @@ abstract class Opalestate_Base_API {
/**
* Definition
*
* Register all Taxonomy related to Job post type as location, category, Specialism, Types
*
* @since 1.0
*
* Register all Taxonomy related to Job post type as location, category, Specialism, Types
*/
public function __construct () {
add_action( 'rest_api_init', array( $this, 'register_routes' ) );
public function __construct() {
add_action( 'rest_api_init', [ $this, 'register_routes' ] );
}
/**
* Definition
*
* Register all Taxonomy related to Job post type as location, category, Specialism, Types
*
* @since 1.0
*
* Register all Taxonomy related to Job post type as location, category, Specialism, Types
*/
public function register_routes() {
}
public function get_response ( $code, $output ) {
public function get_response( $code, $output ) {
$response = array();
$response = [];
$response['status'] = $code;
$response = array_merge( $response, $output );
$response = array_merge( $response, $output );
return new WP_REST_Response( $response );
}
public function output ( $code ) {
public function output( $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,9 +124,8 @@ 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;
@ -147,12 +138,12 @@ abstract class Opalestate_Base_API {
/**
* 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() ) );
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;

View File

@ -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 );
}
/**

View File

@ -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
*

View File

@ -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 {
</div>
<div class="opalestate-template-tags-box">
<strong>{property_link}</strong> Property of the user who made the property
<strong>{property_link}</strong> Link of the property
</div>
<div class="opalestate-template-tags-box">
@ -202,13 +207,58 @@ class Opalestate_Emails {
</div>
<div class="opalestate-template-tags-box">
<strong>{property_link}</strong> * Link of the property
<strong>{message}</strong> * Message content of who sent via form
</div>
<div class="opalestate-template-tags-box">
<strong>{site_link}</strong> A link to this website
</div>
<div class="opalestate-template-tags-box">
<strong>{current_time}</strong> Current date and time
</div>
</div> ';
$review_list_tags = '<div>
<p class="tags-description">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.</p>
<div class="opalestate-template-tags-box">
<strong>{receive_name}</strong> Name of the agent who made the property
</div>
<div class="opalestate-template-tags-box">
<strong>{property_link}</strong> Link of the property
</div>
<div class="opalestate-template-tags-box">
<strong>{name}</strong> Name of the user who contact via email form
</div>
<div class="opalestate-template-tags-box">
<strong>{email}</strong> Email of the user who contact via email form
</div>
<div class="opalestate-template-tags-box">
<strong>{schedule_time}</strong> Schedule time
</div>
<div class="opalestate-template-tags-box">
<strong>{schedule_date}</strong> Schedule date
</div>
<div class="opalestate-template-tags-box">
<strong>{message}</strong> * Message content of who sent via form
</div>
<div class="opalestate-template-tags-box">
<strong>{site_link}</strong> A link to this website
</div>
<div class="opalestate-template-tags-box">
<strong>{current_time}</strong> Current date and time
</div>
</div> ';
$list_tags = '<div>
@ -219,7 +269,11 @@ class Opalestate_Emails {
</div>
<div class="opalestate-template-tags-box">
<strong>{property_link}</strong> Email of the user who made the property
<strong>{property_link}</strong> Link of the property
</div>
<div class="opalestate-template-tags-box">
<strong>{property_edit_link}</strong> Link for editing of the property (admin)
</div>
<div class="opalestate-template-tags-box">
@ -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' => '<hr>',
'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' => '<hr>',
'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' => '<hr>',
@ -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 . '<br><hr>',
'desc' => $review_list_tags . '<br><hr>',
'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(),
],
]
),

View File

@ -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 );

View File

@ -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+/', '', '
Youve received a submission from %s: {user_name},
Youve received a submission from: {user_name},
<br>
You can review it by follow this link: {property_edit_link}
<em>This message was sent by {site_link} on {current_time}.</em>'
@ -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();
}
/**

View File

@ -24,38 +24,35 @@ if ( ! defined( 'ABSPATH' ) ) {
class OpalEstate_Send_Email_Approve extends OpalEstate_Abstract_Email_Template {
/**
*
* Get subject.
*/
public function get_subject () {
$propety_title = '' ;
public function get_subject() {
$subject = esc_html__( 'The Property Listing Approved: {property_name}', 'opalestate-pro' );
$subject = opalestate_options( 'approve_email_body', $subject );
$subject = sprintf( esc_html__( 'The Property Listing Approved: {property_name}', 'opalestate-pro' ), $propety_title );
$subject = opalestate_options( 'approve_email_body' , $subject );
return $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 ){
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;
$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 = [
'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 = 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"),
);
return $this->args ;
return $this->args;
}
/**
@ -63,8 +60,9 @@ class OpalEstate_Send_Email_Approve extends OpalEstate_Abstract_Email_Template {
*/
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;
}
/**
@ -72,7 +70,7 @@ class OpalEstate_Send_Email_Approve extends OpalEstate_Abstract_Email_Template {
*/
public static function get_default_template() {
return trim(preg_replace('/\t+/', '', "Hi {user_name},<br>
return trim( preg_replace( '/\t+/', '', "Hi {user_name},<br>
<br>
Thank you so much for submitting to {site_name}.
<br>
@ -83,20 +81,20 @@ class OpalEstate_Send_Email_Approve extends OpalEstate_Abstract_Email_Template {
<br>
&nbsp;<br>
<br>
<em>This message was sent by {site_link} on {current_time}.</em>"));
<em>This message was sent by {site_link} on {current_time}.</em>" ) );
}
/**
*
*/
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'];
}
@ -107,10 +105,11 @@ class OpalEstate_Send_Email_Approve extends OpalEstate_Abstract_Email_Template {
$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'] = $post->post_title;
return parent::get_body();
}
}
?>

View File

@ -18,8 +18,6 @@ if ( ! defined( 'ABSPATH' ) ) {
/**
* @class OpalEstate_Send_Email_Notification
*
* @version 1.0
*/
class OpalEstate_Send_Email_Notification extends OpalEstate_Abstract_Email_Template {
@ -28,18 +26,18 @@ class OpalEstate_Send_Email_Notification extends OpalEstate_Abstract_Email_Templ
/**
* 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;
@ -49,7 +47,7 @@ class OpalEstate_Send_Email_Notification extends OpalEstate_Abstract_Email_Templ
}
/**
* 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' );
}
}
?>

View File

@ -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 = '' ;
public function get_subject() {
$d = esc_html__( 'New Property Listing Submitted: {property_name}', 'opalestate-pro' );
$s = opalestate_get_option( 'newproperty_email_subject' , $d );
return $s;
$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 ){
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;
$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 = [
'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 = 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"),
);
return $this->args ;
return $this->args;
}
@ -62,8 +60,9 @@ 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;
}
/**
@ -71,7 +70,7 @@ class OpalEstate_Send_Email_New_Submitted extends OpalEstate_Abstract_Email_Temp
*/
public static function get_default_template() {
return trim(preg_replace('/\t+/', '','
return trim( preg_replace( '/\t+/', '', '
Hi {user_name},
<br>
Thanks you so much for submitting {property_name} at {site_name}:<br>
@ -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();
}
}
?>

View File

@ -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' );
}
}

View File

@ -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;

View File

@ -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 );

View File

@ -513,8 +513,13 @@ function opalestate_get_image_placeholder( $size = '', $url = false ) {
return '<img src="' . esc_url( $src ) . '" alt="' . sprintf( esc_html__( 'Placeholder %s', 'opalestate-pro' ), $size ) . '" />';
}
/**
* Get image placeholder src.
*
* @return string
*/
function opalestate_get_image_placeholder_src() {
return OPALESTATE_PLUGIN_URL . 'assets/images/placeholder.png';
return apply_filters( 'opalestate_get_image_placeholder_src', OPALESTATE_PLUGIN_URL . 'assets/images/placeholder.png' );
}
/**

View File

@ -20,11 +20,15 @@ function opalestate_property_mortgage() {
function opalestate_load_template_path( $tpl, $args = [], $layout = '' ) {
return Opalestate_Template_Loader::get_template_part( $tpl, $args, $layout );
}
/**
* Get image avatar placeholder src.
*
* @return string
*/
function opalestate_get_image_avatar_placehold() {
return OPALESTATE_PLUGIN_URL . 'assets/images/avatar-placeholder.png';
return apply_filters( 'opalestate_get_image_avatar_placeholder', OPALESTATE_PLUGIN_URL . 'assets/images/avatar-placeholder.png' );
}
function opalestate_get_admin_view( $file ) {
@ -246,8 +250,8 @@ function opalestate_show_display_modes( $default = 'list' ) {
if ( ! function_exists( 'opalestate_pagination' ) ) {
/**
* Opalestate pagination.
*
* Opalestate pagination.
*
* @param string $pages
* @param int $range
*/

View File

@ -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&#8217; huh?', 'opalestate-pro' ), '1.1.4' );
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; 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

View File

@ -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.

View File

@ -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;

View File

@ -68,7 +68,7 @@
?>
<p class="agent-box-job"><?php echo esc_html( $job ); ?></p>
<?php $email = get_user_meta( $user_id, $prefix . 'email', true ); ?>
<?php $email = get_userdata( $user_id )->user_email; ?>
<?php if ( ! empty( $email ) ) : ?>
<div class="agent-box-email">
<i class="fa fa-envelope"></i>