This commit is contained in:
Hoang Huu 2019-10-01 14:04:57 +07:00
commit ff39207b86
13 changed files with 245 additions and 236 deletions

@ -61,9 +61,9 @@ class Opalestate_Agency_Front {
add_filter( 'opalestate_management_user_menu', [ $this, 'render_extra_profile_link' ] );
add_action( "opalestate_user_content_agency_profile_page", [ $this, 'render_profile' ] );
add_action( "opalestate_user_content_agency_team_page", [ $this, 'render_team' ] );
add_action( "opalestate_user_init", [ $this, 'process_action_member' ] );
add_action( 'opalestate_user_content_agency_profile_page', [ $this, 'render_profile' ] );
add_action( 'opalestate_user_content_agency_team_page', [ $this, 'render_team' ] );
add_action( 'opalestate_user_init', [ $this, 'process_action_member' ] );
$this->register_shortcodes();
}
@ -153,7 +153,6 @@ class Opalestate_Agency_Front {
unset( $_POST[ $prefix . 'title' ] );
unset( $_POST[ $prefix . 'text' ] );
if ( $data['ID'] > 0 ) {
$post_id = wp_update_post( $data, true );
} else {
@ -322,13 +321,13 @@ class Opalestate_Agency_Front {
$atts = is_array( $atts ) ? $atts : [];
$default = array(
$default = [
'current_uri' => null,
'column' => 3,
'limit' => 12,
'paged' => 1,
'onlyfeatured' => 0,
);
];
$atts = array_merge( $default, $atts );
@ -343,10 +342,10 @@ class Opalestate_Agency_Front {
$atts = is_array( $atts ) ? $atts : [];
$layout = 'search-agency-form';
$default = array(
$default = [
'current_uri' => null,
'form' => $layout
);
'form' => $layout,
];
$atts = array_merge( $default, $atts );
@ -357,12 +356,20 @@ class Opalestate_Agency_Front {
*
*/
public function render_profile() {
$user_id = get_current_user_id();
$post_id = OpalEstate_User::get_member_id();
if ( isset( $post->ID ) && $post->post_status != 'publish' ) {
opalestate_add_notice( "warning", esc_html__( 'You account is under reviewing! it take some time to process' ) );
add_action( "opalestate_profile_agency_form_before", "opalestate_print_notices" );
// Check if have not any relationship, create a new then update this meta value.
if ( ! $post_id || $post_id < 0 ) {
static::on_set_role( $user_id );
}
$post_id = get_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', true );
$post = get_post( $post_id );
if ( isset( $post->ID ) && ( $post->post_status != 'publish' || $post->ID == get_the_ID() ) ) {
opalestate_add_notice( 'warning', esc_html__( 'You account is under reviewing! It take some time to process.', 'opalestate-pro' ) );
add_action( 'opalestate_profile_agency_form_before', 'opalestate_print_notices' );
}
$metaboxes = $this->render_front_form( [], $post_id );
@ -446,15 +453,12 @@ class Opalestate_Agency_Front {
}
public static function on_set_role( $user_id ) {
if ( $user_id ) {
$args = [
'post_type' => 'opalestate_agency',
'posts_per_page' => 10,
];
$args['meta_key'] = OPALESTATE_AGENCY_PREFIX . 'user_id';
$args['meta_value'] = $user_id;
$args['meta_compare'] = '=';
@ -477,6 +481,8 @@ class Opalestate_Agency_Front {
public static function create_agency( $args = [], $user_id ) {
$data = get_user_by( 'id', $user_id );
$post_title = sprintf( esc_html__( 'User ID: %s', 'opalestate-pro' ), $user_id );
$args = wp_parse_args( $args, [
'first_name' => $data->first_name,
'last_name' => $data->last_name,
@ -495,9 +501,14 @@ class Opalestate_Agency_Front {
'instagram' => '',
] );
if ( $args['first_name'] && $args['last_name'] ) {
$post_title = $args['first_name'] . ' ' . $args['last_name'];
} elseif ( isset( $data->display_name ) && $data->display_name ) {
$post_title = esc_html( $data->display_name );
}
$agency_id = wp_insert_post( [
'post_title' => $args['first_name'] && $args['last_name'] ? $args['first_name'] . ' ' . $args['last_name'] : esc_html__( 'User ID', 'opalestate-pro' ) . ': ' . $user_id,
'post_title' => $post_title,
'post_content' => 'empty description',
'post_excerpt' => 'empty excerpt',
'post_type' => 'opalestate_agency',

@ -90,15 +90,20 @@ class Opalestate_Agent_Front {
* render_profile
*/
public function render_profile() {
$user_id = get_current_user_id();
$post_id = get_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', true );
// Check if have not any relationship, create a new then update this meta value.
if ( ! $post_id || $post_id < 0 ) {
$this->on_set_role( $user_id );
}
$post_id = get_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', true );
$post = get_post( $post_id );
if ( isset( $post->ID ) && $post->post_status != 'publish' ) {
opalestate_add_notice( "warning", esc_html__( 'You account is under reviewing! it take some time to process' ) );
add_action( "opalestate_profile_agency_form_before", "opalestate_print_notices" );
if ( isset( $post->ID ) && ( $post->post_status != 'publish' || $post->ID == get_the_ID() ) ) {
opalestate_add_notice( 'warning', esc_html__( 'You account is under reviewing! It take some time to process.', 'opalestate-pro' ) );
add_action( 'opalestate_profile_agent_form_before', 'opalestate_print_notices' );
}
$metaboxes = $this->render_front_form( [], $post_id );
@ -321,14 +326,14 @@ class Opalestate_Agent_Front {
$atts = is_array( $atts ) ? $atts : [];
$layout = 'search-agency-form';
$default = array(
$default = [
'current_uri' => null,
'column' => 4,
'limit' => 12,
'paged' => 1,
'onlyfeatured' => 0,
'form' => $layout
);
'form' => $layout,
];
$atts = array_merge( $default, $atts );
@ -461,7 +466,6 @@ class Opalestate_Agent_Front {
'posts_per_page' => 10,
];
$args['meta_key'] = OPALESTATE_AGENT_PREFIX . 'user_id';
$args['meta_value'] = $user_id;
$args['meta_compare'] = '=';
@ -478,9 +482,10 @@ class Opalestate_Agent_Front {
}
public function create_agent( $args = [], $user_id ) {
$data = get_user_by( 'id', $user_id );
$post_title = sprintf( esc_html__( 'User ID: %s', 'opalestate-pro' ), $user_id );
$args = wp_parse_args( $args, [
'first_name' => $data->first_name,
'last_name' => $data->last_name,
@ -500,8 +505,14 @@ class Opalestate_Agent_Front {
'instagram' => '',
] );
if ( $args['first_name'] && $args['last_name'] ) {
$post_title = $args['first_name'] . ' ' . $args['last_name'];
} elseif ( isset( $data->display_name ) && $data->display_name ) {
$post_title = esc_html( $data->display_name );
}
$agent_id = wp_insert_post( [
'post_title' => $args['first_name'] && $args['last_name'] ? $args['first_name'] . ' ' . $args['last_name'] : esc_html__( 'User ID', 'opalestate-pro' ) . ': ' . $user_id,
'post_title' => $post_title,
'post_content' => '',
'post_excerpt' => '',
'post_type' => 'opalestate_agent',
@ -509,7 +520,6 @@ class Opalestate_Agent_Front {
'post_author' => $user_id,
], true );
do_action( 'opalesate_insert_user_agent', $agent_id );
return $agent_id;

120
inc/api/v1/property.php Executable file → Normal file

@ -1,23 +1,14 @@
<?php
/**
* Define
* Note: only use for internal purpose.
*
* @package OpalJob
* @copyright Copyright (c) 2019, WpOpal <https://www.wpopal.com>
* @license https://opensource.org/licenses/gpl-license GNU Public License
* @since 1.0
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* @class Job_Api
* Property_Api
*
* @since 1.0.0
* @package Opal_Job
* @subpackage Opal_Job/controllers
* @package Property_Api
*/
class Property_Api extends Base_Api {
@ -35,78 +26,80 @@ class Property_Api extends Base_Api {
*
* Register all CURD actions with POST/GET/PUT and calling function for each
*
* @return avoid
* @since 1.0
*
* @return avoid
*/
public function register_routes() {
/// call http://domain.com/wp-json/job-api/v1/job/list ////
register_rest_route( $this->namespace, $this->base.'/list', array(
/// call http://domain.com/wp-json/estate-api/v1/estate/list ////
register_rest_route( $this->namespace, $this->base . '/list', [
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_list' ),
'permission_callback' => array( $this, 'validate_request' ),
));
'callback' => [ $this, 'get_list' ],
'permission_callback' => [ $this, 'validate_request' ],
] );
/// call http://domain.com/wp-json/job-api/v1/job/featured ////
register_rest_route( $this->namespace, $this->base.'/featured', array(
/// call http://domain.com/wp-json/estate-api/v1/estate/featured ////
register_rest_route( $this->namespace, $this->base . '/featured', [
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_featured_list' ),
'permission_callback' => array( $this, 'validate_request' ),
));
'callback' => [ $this, 'get_featured_list' ],
'permission_callback' => [ $this, 'validate_request' ],
] );
/// call http://domain.com/wp-json/job-api/v1/job/1 ////
register_rest_route( $this->namespace, $this->base.'/(?P<id>\d+)', array(
register_rest_route( $this->namespace, $this->base . '/(?P<id>\d+)', [
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_job' ),
'permission_callback' => array( $this, 'validate_request' ),
));
'callback' => [ $this, 'get_job' ],
'permission_callback' => [ $this, 'validate_request' ],
] );
/// call http://domain.com/wp-json/job-api/v1/job/create ////
register_rest_route( $this->namespace, $this->base.'/create', array(
register_rest_route( $this->namespace, $this->base . '/create', [
'methods' => 'GET',
'callback' => array( $this, 'create' ),
'permission_callback' => array( $this, 'validate_request' ),
));
'callback' => [ $this, 'create' ],
'permission_callback' => [ $this, 'validate_request' ],
] );
/// call http://domain.com/wp-json/job-api/v1/job/edit ////
register_rest_route( $this->namespace, $this->base.'/edit', array(
register_rest_route( $this->namespace, $this->base . '/edit', [
'methods' => 'GET',
'callback' => array( $this, 'edit' ),
));
'callback' => [ $this, 'edit' ],
] );
/// call http://domain.com/wp-json/job-api/v1/job/delete ////
register_rest_route( $this->namespace, $this->base.'/delete', array(
register_rest_route( $this->namespace, $this->base . '/delete', [
'methods' => 'GET',
'callback' => array( $this, 'delete' ),
'permission_callback' => array( $this, 'validate_request' ),
));
'callback' => [ $this, 'delete' ],
'permission_callback' => [ $this, 'validate_request' ],
] );
/**
* List job by tags and taxonmies
*/
/// call http://domain.com/wp-json/job-api/v1/jobs ////
register_rest_route( $this->namespace, $this->base.'/tags', array(
register_rest_route( $this->namespace, $this->base . '/tags', [
'methods' => 'GET',
'callback' => array( $this, 'delete' ),
'permission_callback' => array( $this, 'validate_request' ),
));
'callback' => [ $this, 'delete' ],
'permission_callback' => [ $this, 'validate_request' ],
] );
}
public function get_featured_list() {
$properties = array();
$error = array();
$properties = [];
$error = [];
$property = null;
if ( $property == null ) {
$properties = array();
$properties = [];
$property_list = get_posts( array(
$property_list = get_posts( [
'post_type' => 'opalestate_property',
'posts_per_page' => $this->per_page(),
'suppress_filters' => true,
'meta_key' => OPALESTATE_PROPERTY_PREFIX . 'featured',
'meta_value' => 'on',
'paged' => $this->get_paged()
) );
'paged' => $this->get_paged(),
] );
if ( $property_list ) {
$i = 0;
@ -144,26 +137,26 @@ class Property_Api extends Base_Api {
*
* Based on request to get collection
*
* @return WP_REST_Response is json data
* @since 1.0
*
* @return WP_REST_Response is json data
*/
public function get_list( $request ) {
$properties = array();
$error = array();
$properties = [];
$error = [];
$property = null;
if ( $property == null ) {
$properties = array();
$properties = [];
$property_list = get_posts( array(
$property_list = get_posts( [
'post_type' => 'opalestate_property',
'posts_per_page' => $this->per_page(),
'suppress_filters' => true,
'paged' => $this->get_paged()
) );
'paged' => $this->get_paged(),
] );
if ( $property_list ) {
$i = 0;
@ -192,6 +185,7 @@ class Property_Api extends Base_Api {
$response['collection'] = $properties;
$response['pages'] = 4;
$response['current'] = 1;
return $this->get_response( 200, $response );
}
@ -199,15 +193,15 @@ class Property_Api extends Base_Api {
/**
* Opalestaten a opalestate_property post object, generate the data for the API output
*
* @since 1.1
*
* @param object $property_info The Download Post Object
*
* @return array Array of post data to return back in the API
* @since 1.1
*
*/
private function get_property_data( $property_info ) {
$property = array();
$property = [];
$property['info']['id'] = $property_info->ID;
$property['info']['slug'] = $property_info->post_name;
@ -221,22 +215,22 @@ class Property_Api extends Base_Api {
$data = opalesetate_property( $property_info->ID );
$gallery = $data->get_gallery();
$property['info']['gallery'] = isset($gallery[0]) && !empty($gallery[0]) ? $gallery[0]: array();
$property['info']['gallery'] = isset( $gallery[0] ) && ! empty( $gallery[0] ) ? $gallery[0] : [];
$property['info']['price'] = opalestate_price_format( $data->get_price() );
$property['info']['map'] = $data->get_map();
$property['info']['address'] = $data->get_address();
$property['meta'] = $data->get_meta_shortinfo();
$property['is_featured'] = $data->is_featured();
$property['status'] = $data->get_status();
$property['labels'] = $data->get_labels();
$property['locations'] = $data->get_locations();
$property['amenities'] = $data->get_amenities();
$property['types'] = $data->get_types_tax();
$property['author_type'] = $data->get_author_type();
$property['author_data'] = $data->get_author_link();
return apply_filters( 'opalestate_api_properties_property', $property );
}
/**
@ -244,9 +238,9 @@ class Property_Api extends Base_Api {
*
* Based on request to get collection
*
* @return WP_REST_Response is json data
* @since 1.0
*
* @return WP_REST_Response is json data
*/
public function delete() {

@ -454,7 +454,7 @@ class Opalestate_Property {
return '<a href="' . $data['link'] . '" aria-label="' . $data['name'] . '" class="author-link"><span aria-label="' . $data['name'] . '" class="author-avatar hint--top">' . $avatar . '</span><span class="author-name">' . $data['name'] . '</span></a>';
}
private function get_author_link() {
public function get_author_link() {
$image_id = get_user_meta( get_the_author_meta( 'ID' ), OPALESTATE_USER_PROFILE_PREFIX . 'avatar_id', true );
$related_id = get_user_meta( get_the_author_meta( 'ID' ), OPALESTATE_USER_PROFILE_PREFIX . 'related_id', true );

@ -186,8 +186,8 @@ class Opalestate_User_Form_Handler {
if ( $password !== $password1 ) {
throw new Exception( '<strong>' . esc_html__( 'ERROR', 'opalestate-pro' ) . ':</strong> ' . esc_html__( 'Re-Password is not match.', 'opalestate-pro' ) );
}
$credentials['user_pass'] = $password;
$credentials['user_pass'] = $password;
/* create new user */
$user_id = opalestate_create_user( $credentials );
@ -195,8 +195,7 @@ class Opalestate_User_Form_Handler {
if ( is_wp_error( $user_id ) ) {
throw new Exception( '<strong>' . esc_html__( 'ERROR', 'opalestate-pro' ) . ':</strong> ' . $user_id->get_error_message() );
} else {
/* after register successfully */
/* After register successfully */
do_action( 'opalestate_after_register_successfully', $user_id );
$redirect = home_url();
@ -213,7 +212,7 @@ class Opalestate_User_Form_Handler {
$redirect = apply_filters( 'opalestate_register_redirect_url', $redirect );
/* is ajax request */
/* Is ajax request */
if ( opalestate_is_ajax_request() ) {
wp_send_json( [ 'status' => true, 'redirect' => $redirect ] );
} else {

@ -185,20 +185,24 @@ class OpalEstate_User {
}
/**
* On Register user.
*
* @param int $user_id User ID
*/
public function on_regiser_user( $user_id ) {
if ( isset( $_POST['role'] ) ) {
$roles = opalestate_user_roles_by_user_id( $user_id );
// Fetch the WP_User object of our user.
$u = new WP_User( $user_id );
$u->remove_role( 'subscriber' );
// Replace the current role with 'editor' role
$u->set_role( sanitize_text_field( $_POST['role'] ) );
$roles = opalestate_user_roles_by_user_id( $user_id );
if ( $roles && in_array( $_POST['role'], $roles ) ) {
$role = str_replace( 'opalestate_', '', sanitize_text_field( $_POST['role'] ) );
do_action( 'opalestate_on_set_role_' . $role, $user_id );
}
}

@ -29,7 +29,7 @@ $property = opalesetate_property( get_the_ID() );
<?php endif; ?>
</div>
<p class="property-description">
<?php echo opalestate_fnc_excerpt( 14, '...' ); ?>
<?php echo opalestate_fnc_excerpt( 38, '...' ); ?>
</p>
</div>
</div><!-- .entry-content -->

@ -50,7 +50,8 @@ switch ( $type ) {
break;
}
?>
<div class="opalestate-box-content property-agent-section">
<div class="opalestate-box-content property-agent-section property-author-v2">
<div class="opalestate-box">
<div class="author-content-box">
<div class="property-agent-info">
@ -59,5 +60,3 @@ switch ( $type ) {
</div>
</div>
</div>

@ -44,7 +44,7 @@ switch ( $type ) {
break;
}
?>
<div class="opalestate-box-content property-agent-section">
<div class="opalestate-box-content property-agent-section property-author-v3">
<div class="opalestate-box">
<?php if ( opalestate_get_option( 'enable_single_author_box' , 'on' ) == 'on' ) : ?>
<div class="author-content-box">

@ -44,7 +44,7 @@ switch ( $type ) {
break;
}
?>
<div class="opalestate-box-content property-agent-section">
<div class="opalestate-box-content property-agent-section property-author-v1">
<div class="opalestate-box">
<div class="author-content-box">
<div class="opal-row">

@ -8,8 +8,6 @@
$user_id = $author->ID;
$is_sticky = get_user_meta( $user_id, $prefix . 'sticky', true );
$desciption = get_user_meta( $user_id, 'description', true );
$roles = opalestate_user_roles_by_user_id( $user_id );
@ -75,7 +73,6 @@
</div>
</div><!-- /.agent-preview -->
<div class="agent-box-meta">
<h4 class="agent-box-title">
<a href="<?php echo esc_url( $link ); ?>"><?php echo esc_html( $author_name ); ?></a>
@ -143,11 +140,8 @@
<?php if ( $linkedIn && $linkedIn != "#" && ! empty( $linkedIn ) ) { ?>
<a class="opalestate-social-white radius-x" href="<?php echo esc_url( $linkedIn ); ?>"> <i class="fab fa-linkedIn"></i></a>
<?php } ?>
</div>
</div><!-- /.agent-box-content -->
</div><!-- /.agent-box-->
</div>
<?php endif; ?>

@ -1,4 +1,3 @@
<div class="property-submission-form">
<?php if ( ! empty( $_SESSION['messages'] ) ) : ?>
@ -12,7 +11,8 @@
<?php printf( '%s', $msg ) ?>
</div>
<?php endforeach; unset( $_SESSION['messages'] ); ?>
<?php endforeach;
unset( $_SESSION['messages'] ); ?>
</div>
<?php endif; ?>
@ -24,13 +24,12 @@
<?php
do_action( 'opalestate_profile_agency_form_before' );
// echo '<Pre>'.print_r( $metaboxes ,1 );die;
if ( function_exists( 'cmb2_get_metabox_form' ) ) {
echo cmb2_get_metabox_form( $metaboxes[OPALESTATE_AGENCY_PREFIX.'front'], $post_id, array(
echo cmb2_get_metabox_form( $metaboxes[ OPALESTATE_AGENCY_PREFIX . 'front' ], $post_id, [
'form_format' => '<form action="//' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '" class="cmb-form" method="post" id="%1$s" enctype="multipart/form-data" encoding="multipart/form-data"><input type="hidden" name="object_id" value="%2$s">%3$s<button type="submit" name="submit-cmb" class="button-primary btn btn-primary">%4$s</button></form>',
'save_button' => esc_html__( 'Save Change', 'opalestate-pro' ),
) );
] );
}
do_action( 'opalestate_profile_agency_form_after' );

@ -1,4 +1,3 @@
<div class="property-submission-form">
<div class="opalestate-admin-box">
@ -8,7 +7,7 @@
<?php if ( isset( $metaboxes[ OPALESTATE_AGENT_PREFIX . 'front' ] ) ): ?>
<?php
do_action( 'opalestate_profile_agency_form_before' );
do_action( 'opalestate_profile_agent_form_before' );
if ( function_exists( 'cmb2_get_metabox_form' ) ) {
echo cmb2_get_metabox_form( $metaboxes[ OPALESTATE_AGENT_PREFIX . 'front' ], $post_id, [