Origin commit
This commit is contained in:
508
inc/agent/class-opalestate-agent-front.php
Executable file
508
inc/agent/class-opalestate-agent-front.php
Executable file
@@ -0,0 +1,508 @@
|
||||
<?php
|
||||
/**
|
||||
* Opalestate_Agent_Front
|
||||
*
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @copyright Copyright (C) 2014 wpopal.com. All Rights Reserved.
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Opalestate_Agent_Front {
|
||||
|
||||
/**
|
||||
* Instance.
|
||||
*
|
||||
* @access private
|
||||
* @var Opalestate_Agent_Front
|
||||
*/
|
||||
static private $instance;
|
||||
|
||||
/**
|
||||
* Singleton pattern.
|
||||
*
|
||||
* @since $Id
|
||||
* @access private
|
||||
*/
|
||||
private function __construct() {
|
||||
}
|
||||
|
||||
public $new_attachmenet_ids;
|
||||
|
||||
/**
|
||||
* Get instance.
|
||||
*
|
||||
* @access public
|
||||
* @return Opalestate_Agent_Front
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( null === static::$instance ) {
|
||||
self::$instance = new static();
|
||||
|
||||
self::$instance->init();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto update meta information to post from user data updated or created
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
add_action( 'opalestate_on_set_role_agent', [ $this, 'on_set_role' ], 1, 9 );
|
||||
add_filter( 'opalestate_before_render_profile_agent_form', [ $this, 'render_front_form' ], 2, 2 );
|
||||
add_filter( 'pre_get_posts', [ $this, 'archives_query' ], 1 );
|
||||
add_action( 'cmb2_after_init', [ $this, 'on_save_front_data' ] );
|
||||
|
||||
add_action( 'opalestate_user_content_agent_profile_page', [ $this, 'render_profile' ] );
|
||||
add_filter( 'opalestate_management_user_menu', [ $this, 'render_extra_profile_link' ] );
|
||||
|
||||
$this->register_shortcodes();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* render_extra_profile_link.
|
||||
*/
|
||||
public function render_extra_profile_link( $menu ) {
|
||||
global $current_user;
|
||||
|
||||
$user_roles = $current_user->roles;
|
||||
$user_role = array_shift( $user_roles );
|
||||
|
||||
if ( $user_role == 'opalestate_agent' ) {
|
||||
$menu['extra_profile'] = [
|
||||
'icon' => 'fa fa-user',
|
||||
'link' => "agent_profile",
|
||||
'title' => esc_html__( 'Agent Profile', 'opalestate-pro' ),
|
||||
'id' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
return $menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
|
||||
$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" );
|
||||
}
|
||||
|
||||
$metaboxes = $this->render_front_form( [], $post_id );
|
||||
|
||||
return opalestate_load_template_path( 'user/agent/profile-agent', [ 'metaboxes' => $metaboxes, 'post_id' => $post_id ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Process upload images for properties
|
||||
*/
|
||||
public function upload_image( $submitted_file, $parent_id = 0 ) {
|
||||
return opalesate_upload_image( $submitted_file, $parent_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove dirty images of current user
|
||||
*/
|
||||
public function remove_dirty_images( $post_id, $user_id ) {
|
||||
|
||||
if ( isset( $_POST['remove_image_id'] ) && is_array( $_POST['remove_image_id'] ) && $_POST['remove_image_id'] ) {
|
||||
foreach ( $_POST['remove_image_id'] as $key => $value ) {
|
||||
$post = get_post( $value );
|
||||
if ( $post->post_author == $user_id ) {
|
||||
wp_delete_attachment( $value );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function process_upload_files( $post_id ) {
|
||||
|
||||
//upload images for featured and gallery images
|
||||
if ( isset( $_FILES ) && ! empty( $_FILES ) ) {
|
||||
|
||||
///
|
||||
$fields = [
|
||||
$this->get_field_name( 'gallery' ),
|
||||
$this->get_field_name( 'avatar_id' ),
|
||||
$this->get_field_name( 'featured_image' ),
|
||||
];
|
||||
|
||||
foreach ( $_FILES as $key => $value ) {
|
||||
// allow processing in fixed collection
|
||||
if ( in_array( $key, $fields ) ) {
|
||||
$ufile = $_FILES[ $key ];
|
||||
|
||||
/// /////
|
||||
if ( isset( $ufile['name'] ) && is_array( $ufile['name'] ) ) {
|
||||
$output = [];
|
||||
|
||||
foreach ( $ufile['name'] as $f_key => $f_value ) {
|
||||
$loop_file = [
|
||||
'name' => $ufile['name'][ $f_key ],
|
||||
'type' => $ufile['type'][ $f_key ],
|
||||
'tmp_name' => $ufile['tmp_name'][ $f_key ],
|
||||
'error' => $ufile['error'][ $f_key ],
|
||||
'size' => $ufile['size'][ $f_key ],
|
||||
];
|
||||
$new_atm = $this->upload_image( $loop_file, $post_id );
|
||||
if ( $new_atm ) {
|
||||
$_POST[ $key ] = isset( $_POST[ $key ] ) ? sanitize_text_field( $_POST[ $key ] ) : [];
|
||||
$_POST[ $key ][ $new_atm['attachment_id'] ] = $new_atm['url'];
|
||||
$this->new_attachmenet_ids[ $new_atm['attachment_id'] ] = $new_atm['attachment_id'];
|
||||
}
|
||||
}
|
||||
|
||||
} ///
|
||||
elseif ( isset( $ufile['name'] ) ) {
|
||||
$new_atm = $this->upload_image( $ufile, $post_id );
|
||||
if ( $new_atm ) {
|
||||
$_POST[ $key ] = $new_atm['attachment_id'];
|
||||
|
||||
if ( preg_match( "#id#", $key ) ) {
|
||||
$_key = str_replace( "_id", "", $key );
|
||||
$_POST[ $_key ] = $new_atm['url'];
|
||||
}
|
||||
$this->new_attachmenet_ids[ $new_atm['attachment_id'] ] = $new_atm['attachment_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function on_save_front_data() {
|
||||
|
||||
if ( isset( $_POST[ 'nonce_CMB2php' . OPALESTATE_AGENT_PREFIX . 'front' ] ) ) {
|
||||
|
||||
$post_id = $this->update_data_agent_or_agency( OPALESTATE_AGENT_PREFIX );
|
||||
|
||||
if ( $post_id ) {
|
||||
OpalEstate_Agent::update_user_data( get_current_user_id() );
|
||||
}
|
||||
|
||||
return opalestate_output_msg_json( true,
|
||||
__( 'The data updated successful, please wait for redirecting', 'opalestate-pro' ),
|
||||
[
|
||||
'heading' => esc_html__( 'Update Information', 'opalestate-pro' ),
|
||||
'redirect' => opalestate_get_user_management_page_uri( [ 'tab' => 'agent_profile' ] ),
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
return opalestate_output_msg_json( fales,
|
||||
__( 'Currently, The data could not save!', 'opalestate-pro' ),
|
||||
[ 'heading' => esc_html__( 'Update Information', 'opalestate-pro' ) ]
|
||||
);
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function get_field_name( $field ) {
|
||||
return OPALESTATE_AGENT_PREFIX . $field;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function update_data_agent_or_agency( $prefix ) {
|
||||
global $current_user;
|
||||
|
||||
$post_id = isset( $_POST['object_id'] ) && absint( $_POST['object_id'] ) ? $_POST['object_id'] : 0;
|
||||
$user_id = get_current_user_id();
|
||||
$metaboxes = apply_filters( 'opalestate_before_render_profile_agent_form', [], $post_id );
|
||||
$metaboxes = apply_filters( 'cmb2_meta_boxes', $metaboxes );
|
||||
|
||||
if ( isset( $metaboxes[ $prefix . 'front' ] ) ) {
|
||||
if ( ! empty( $post_id ) ) {
|
||||
$old_post = get_post( $post_id );
|
||||
$post_date = $old_post->post_date;
|
||||
} else {
|
||||
$post_date = '';
|
||||
}
|
||||
$post = get_post( $post_id );
|
||||
|
||||
$data = [
|
||||
'ID' => $post->ID ? $post_id : null,
|
||||
'post_title' => sanitize_text_field( $_POST[ $prefix . 'title' ] ),
|
||||
'post_author' => $user_id,
|
||||
'post_type' => 'opalestate_agent',
|
||||
'post_date' => $post_date,
|
||||
'post_content' => wp_kses( $_POST[ $prefix . 'text' ], '<b><strong><i><em><h1><h2><h3><h4><h5><h6><pre><code><span><p>' ),
|
||||
];
|
||||
|
||||
|
||||
unset( $_POST[ $prefix . 'title' ] );
|
||||
unset( $_POST[ $prefix . 'text' ] );
|
||||
|
||||
|
||||
if ( $data['ID'] > 0 ) {
|
||||
$post_id = wp_update_post( $data, true );
|
||||
} else {
|
||||
$data['post_status'] = 'pending';
|
||||
$post_id = wp_insert_post( $data, true );
|
||||
}
|
||||
|
||||
$post = get_post( $post_id );
|
||||
|
||||
update_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', $post_id );
|
||||
|
||||
/*
|
||||
* Processing upload files
|
||||
*/
|
||||
$this->process_upload_files( $post_id, $_POST );
|
||||
|
||||
cmb2_get_metabox_form( $metaboxes[ $prefix . 'front' ], $post_id );
|
||||
$cmb = cmb2_get_metabox( $prefix . 'front', $post_id );
|
||||
$sanitized_values = $cmb->get_sanitized_values( $_POST );
|
||||
$cmb->save_fields( $post_id, 'post', $sanitized_values );
|
||||
/// update
|
||||
// Create featured image
|
||||
$featured_image = get_post_meta( $post_id, $prefix . 'featured_image', true );
|
||||
|
||||
if ( ! empty( $_POST[ $prefix . 'featured_image' ] ) && isset( $_POST[ $prefix . 'featured_image' ] ) ) {
|
||||
|
||||
set_post_thumbnail( $post_id, $_POST[ $prefix . 'featured_image' ] );
|
||||
unset( $_POST[ $prefix . 'featured_image' ] );
|
||||
} else {
|
||||
delete_post_thumbnail( $post_id );
|
||||
}
|
||||
|
||||
// remove dirty images
|
||||
$this->remove_dirty_images( $post_id, $user_id );
|
||||
// set ready of attachment for use.
|
||||
if ( $this->new_attachmenet_ids ) {
|
||||
foreach ( $this->new_attachmenet_ids as $_id ) {
|
||||
delete_post_meta( $_id, '_pending_to_use_', 1 );
|
||||
}
|
||||
}
|
||||
|
||||
return $post_id;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function register_shortcodes() {
|
||||
|
||||
$this->shortcodes = [
|
||||
|
||||
'change_agent_profile' => [ 'code' => 'change_agent_profile', 'label' => esc_html__( 'Agent Profile', 'opalestate-pro' ) ],
|
||||
'search_agents' => [ 'code' => 'search_agents', 'label' => esc_html__( 'Search Agents', 'opalestate-pro' ) ],
|
||||
];
|
||||
|
||||
foreach ( $this->shortcodes as $shortcode ) {
|
||||
add_shortcode( 'opalestate_' . $shortcode['code'], [ $this, $shortcode['code'] ] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function archives_query( $query ) {
|
||||
|
||||
if ( $query->is_main_query() && is_post_type_archive( 'opalestate_agent' ) ) {
|
||||
|
||||
$args = [];
|
||||
|
||||
$min = opalestate_options( 'search_agent_min_price', 0 );
|
||||
$max = opalestate_options( 'search_agent_max_price', 10000000 );
|
||||
|
||||
|
||||
$search_min_price = isset( $_GET['min_price'] ) ? sanitize_text_field( $_GET['min_price'] ) : '';
|
||||
$search_max_price = isset( $_GET['max_price'] ) ? sanitize_text_field( $_GET['max_price'] ) : '';
|
||||
|
||||
$search_min_area = isset( $_GET['min_area'] ) ? sanitize_text_field( $_GET['min_area'] ) : '';
|
||||
$search_max_area = isset( $_GET['max_area'] ) ? sanitize_text_field( $_GET['max_area'] ) : '';
|
||||
$s = isset( $_GET['search_text'] ) ? sanitize_text_field( $_GET['search_text'] ) : null;
|
||||
|
||||
|
||||
$paged = ( get_query_var( 'paged' ) == 0 ) ? 1 : get_query_var( 'paged' );
|
||||
$default = [
|
||||
'post_type' => 'opalestate_agent',
|
||||
'posts_per_page' => apply_filters( 'opalestate_agent_per_page', 12 ),
|
||||
'paged' => $paged,
|
||||
];
|
||||
$args = array_merge( $default, $args );
|
||||
|
||||
$tax_query = [];
|
||||
|
||||
|
||||
if ( isset( $_GET['location'] ) && $_GET['location'] != -1 ) {
|
||||
$tax_query[] =
|
||||
[
|
||||
'taxonomy' => 'opalestate_location',
|
||||
'field' => 'slug',
|
||||
'terms' => sanitize_text_field( $_GET['location'] ),
|
||||
];
|
||||
}
|
||||
|
||||
if ( isset( $_GET['types'] ) && $_GET['types'] != -1 ) {
|
||||
$tax_query[] =
|
||||
[
|
||||
'taxonomy' => 'opalestate_types',
|
||||
'field' => 'slug',
|
||||
'terms' => sanitize_text_field( $_GET['types'] ),
|
||||
];
|
||||
}
|
||||
|
||||
if ( $tax_query ) {
|
||||
$args['tax_query'] = [ 'relation' => 'AND' ];
|
||||
$args['tax_query'] = array_merge( $args['tax_query'], $tax_query );
|
||||
}
|
||||
|
||||
$args['meta_query'] = [ 'relation' => 'AND' ];
|
||||
|
||||
if ( $search_min_price != $min && is_numeric( $search_min_price ) ) {
|
||||
array_push( $args['meta_query'], [
|
||||
'key' => OPALESTATE_AGENT_PREFIX . 'target_min_price',
|
||||
'value' => $search_min_price,
|
||||
'compare' => '>=',
|
||||
'type' => 'NUMERIC',
|
||||
] );
|
||||
}
|
||||
if ( is_numeric( $search_max_price ) && $search_max_price != $max ) {
|
||||
array_push( $args['meta_query'], [
|
||||
'key' => OPALESTATE_AGENT_PREFIX . 'target_max_price',
|
||||
'value' => $search_max_price,
|
||||
'compare' => '<=',
|
||||
'type' => 'NUMERIC',
|
||||
] );
|
||||
}
|
||||
|
||||
|
||||
///// search by address and geo location ///
|
||||
if ( isset( $_GET['geo_long'] ) && isset( $_GET['geo_lat'] ) ) {
|
||||
|
||||
$prefix = OPALESTATE_AGENT_PREFIX;
|
||||
if ( $_GET['location_text'] && ( empty( $_GET['geo_long'] ) || empty( $_GET['geo_lat'] ) ) ) {
|
||||
array_push( $args['meta_query'], [
|
||||
'key' => $prefix . 'map_address',
|
||||
'value' => sanitize_text_field( trim( $_GET['location_text'] ) ),
|
||||
'compare' => 'LIKE',
|
||||
'operator' => 'OR',
|
||||
] );
|
||||
|
||||
} else {
|
||||
$radius = isset( $_GET['geo_radius'] ) ? sanitize_text_field( $_GET['geo_radius'] ) : 5;
|
||||
$post_ids = Opalestate_Query::filter_by_location(
|
||||
sanitize_text_field( $_GET['geo_lat'] ),
|
||||
sanitize_text_field( $_GET['geo_long'] ), $radius, $prefix );
|
||||
|
||||
|
||||
$args['post__in'] = $post_ids;
|
||||
$query->set( 'post__in', $post_ids );
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $args['tax_query'] ) && $args['tax_query'] ) {
|
||||
$query->set( 'tax_query', $args['tax_query'] );
|
||||
}
|
||||
if ( isset( $args['meta_query'] ) && $args['meta_query'] ) {
|
||||
$query->set( 'meta_query', $args['meta_query'] );
|
||||
}
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function search_agents() {
|
||||
return opalestate_load_template_path( 'shortcodes/search-agents' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto update meta information to post from user data updated or created
|
||||
*/
|
||||
public function on_set_role( $user_id ) {
|
||||
if ( $user_id ) {
|
||||
|
||||
$args = [
|
||||
'post_type' => 'opalestate_agent',
|
||||
'posts_per_page' => 10,
|
||||
];
|
||||
|
||||
|
||||
$args['meta_key'] = OPALESTATE_AGENT_PREFIX . 'user_id';
|
||||
$args['meta_value'] = $user_id;
|
||||
$args['meta_compare'] = '=';
|
||||
$args['post_status'] = [ 'publish', 'pending' ];
|
||||
|
||||
$post = get_posts( $args );
|
||||
|
||||
if ( empty( $post ) ) {
|
||||
$agent_id = $this->create_agent( [], $user_id );
|
||||
update_post_meta( $agent_id, OPALESTATE_AGENT_PREFIX . 'user_id', $user_id );
|
||||
update_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', $agent_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function create_agent( $args = [], $user_id ) {
|
||||
|
||||
$data = get_user_by( 'id', $user_id );
|
||||
|
||||
$args = wp_parse_args( $args, [
|
||||
'first_name' => $data->first_name,
|
||||
'last_name' => $data->last_name,
|
||||
'post_author' => $user_id,
|
||||
'avatar' => '',
|
||||
'job' => '',
|
||||
'email' => '',
|
||||
'phone' => '',
|
||||
'mobile' => '',
|
||||
'fax' => '',
|
||||
'web' => '',
|
||||
'address' => '',
|
||||
'twitter' => '',
|
||||
'facebook' => '',
|
||||
'google' => '',
|
||||
'linkedin' => '',
|
||||
'instagram' => '',
|
||||
] );
|
||||
|
||||
$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_content' => '',
|
||||
'post_excerpt' => '',
|
||||
'post_type' => 'opalestate_agent',
|
||||
'post_status' => 'pending',
|
||||
'post_author' => $user_id,
|
||||
], true );
|
||||
|
||||
|
||||
do_action( 'opalesate_insert_user_agent', $agent_id );
|
||||
|
||||
return $agent_id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function render_front_form( $metaboxes, $post_id = 0 ) {
|
||||
$metabox = new Opalestate_Agent_MetaBox();
|
||||
|
||||
return $metabox->render_front_form( $metaboxes, $post_id );
|
||||
}
|
||||
}
|
||||
|
||||
Opalestate_Agent_Front::get_instance();
|
||||
225
inc/agent/class-opalestate-agent-metabox.php
Executable file
225
inc/agent/class-opalestate-agent-metabox.php
Executable file
@@ -0,0 +1,225 @@
|
||||
<?php
|
||||
/**
|
||||
* Opalestate_Agent_MetaBox.
|
||||
*
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
|
||||
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* @website http://www.wpopal.com
|
||||
* @support http://www.wpopal.com/support/forum.html
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Opalestate_Agent_MetaBox extends Opalestate_User_MetaBox {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function metaboxes_admin_fields( $prefix = '' ) {
|
||||
if ( ! $prefix ) {
|
||||
$prefix = OPALESTATE_AGENT_PREFIX;
|
||||
}
|
||||
|
||||
$fields = [];
|
||||
|
||||
$fields = array_merge_recursive( $fields,
|
||||
$this->get_base_fields( $prefix ),
|
||||
$this->get_job_fields( $prefix ),
|
||||
$this->get_address_fields( $prefix )
|
||||
);
|
||||
|
||||
return apply_filters( 'opalestate_postype_agent_metaboxes_fields', $fields );
|
||||
}
|
||||
|
||||
public function metaboxes_target() {
|
||||
|
||||
$prefix = OPALESTATE_AGENT_PREFIX;
|
||||
$fields = [
|
||||
[
|
||||
'id' => "{$prefix}user_id",
|
||||
'name' => esc_html__( 'Link to User', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'Enter User ID to show information without using user info', 'opalestate-pro' ),
|
||||
],
|
||||
|
||||
[
|
||||
'id' => "{$prefix}target_min_price",
|
||||
'name' => esc_html__( 'Target Min Price', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'Enter min price of property which is for sale/rent...', 'opalestate-pro' ),
|
||||
],
|
||||
|
||||
[
|
||||
'id' => "{$prefix}target_max_price",
|
||||
'name' => esc_html__( 'Target Max Price', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'Enter max price of property which is for sale/rent...', 'opalestate-pro' ),
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Types', 'opalestate-pro' ),
|
||||
'desc' => esc_html__( 'Select one, to add new you create in location of estate panel', 'opalestate-pro' ),
|
||||
'id' => $prefix . "type",
|
||||
'taxonomy' => 'opalestate_types', //Enter Taxonomy Slug
|
||||
'type' => 'taxonomy_select',
|
||||
],
|
||||
];
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function metaboxes_front_fields( $prefix = '', $post_id = 0 ) {
|
||||
if ( ! $prefix ) {
|
||||
$prefix = OPALESTATE_AGENT_PREFIX;
|
||||
}
|
||||
$post = get_post( $post_id );
|
||||
|
||||
$fields = [
|
||||
[
|
||||
'id' => $prefix . 'post_type',
|
||||
'type' => 'hidden',
|
||||
'default' => 'opalestate_agent',
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Title/Name', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'title',
|
||||
'type' => 'text',
|
||||
'default' => ! empty( $post ) ? $post->post_title : '',
|
||||
'attributes' => [
|
||||
'required' => 'required',
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Information', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'text',
|
||||
'type' => 'wysiwyg',
|
||||
'default' => ! empty( $post ) ? $post->post_content : '',
|
||||
'attributes' => [
|
||||
'required' => 'required',
|
||||
],
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Types', 'opalestate-pro' ),
|
||||
'desc' => esc_html__( 'Select one, to add new you create in location of estate panel', 'opalestate-pro' ),
|
||||
'id' => $prefix . "type",
|
||||
'taxonomy' => 'opalestate_types', //Enter Taxonomy Slug
|
||||
'type' => 'taxonomy_select',
|
||||
|
||||
],
|
||||
[
|
||||
'id' => "{$prefix}target_min_price",
|
||||
'name' => esc_html__( 'Target Min Price', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'Enter min price of property which is for sale/rent...', 'opalestate-pro' ),
|
||||
],
|
||||
|
||||
[
|
||||
'id' => "{$prefix}target_max_price",
|
||||
'name' => esc_html__( 'Target Max Price', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'Enter max price of property which is for sale/rent...', 'opalestate-pro' ),
|
||||
'after_row' => '</div>',
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
$fields = array_merge_recursive( $fields,
|
||||
$this->get_base_front_fields( $prefix ),
|
||||
$this->get_address_fields( $prefix ),
|
||||
$this->get_social_fields( $prefix )
|
||||
);
|
||||
|
||||
return apply_filters( 'opalestate_postype_agent_metaboxes_fields', $fields );
|
||||
}
|
||||
|
||||
|
||||
public function get_base_front_fields( $prefix ) {
|
||||
return [
|
||||
[
|
||||
'id' => "{$prefix}featured_image",
|
||||
'name' => esc_html__( 'Banner', 'opalestate-pro' ),
|
||||
'type' => 'uploader',
|
||||
'is_featured' => true,
|
||||
'limit' => 1,
|
||||
'single' => 1,
|
||||
'description' => esc_html__( 'Select one or more images to show as gallery', 'opalestate-pro' ),
|
||||
'before_row' => '<hr>',
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Avatar Picture', 'opalestate-pro' ),
|
||||
'desc' => esc_html__( 'This image will display in user detail and profile box information', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'avatar',
|
||||
'type' => 'hidden',
|
||||
'single' => 1,
|
||||
'limit' => 1,
|
||||
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Avatar Picture', 'opalestate-pro' ),
|
||||
'desc' => esc_html__( 'This image will display in user detail and profile box information', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'avatar_id',
|
||||
'type' => 'uploader',
|
||||
'single' => 1,
|
||||
'limit' => 1,
|
||||
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Email', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}email",
|
||||
'type' => 'text',
|
||||
'before_row' => '<div class="field-row-2">',
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Website', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}web",
|
||||
'type' => 'text_url',
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Phone', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}phone",
|
||||
'type' => 'text',
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Mobile', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}mobile",
|
||||
'type' => 'text',
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Fax', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}fax",
|
||||
'type' => 'text',
|
||||
'after_row' => '</div>',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function render_front_form( $metaboxes, $post_id = 0 ) {
|
||||
$prefix = OPALESTATE_AGENT_PREFIX;
|
||||
$metaboxes[ $prefix . 'front' ] = [
|
||||
'id' => $prefix . 'front',
|
||||
'title' => esc_html__( 'Agent Information', 'opalestate-pro' ),
|
||||
'object_types' => [ 'opalestate_agent' ],
|
||||
'context' => 'normal',
|
||||
'priority' => 'high',
|
||||
'show_names' => true,
|
||||
'fields' => $this->metaboxes_front_fields( $prefix, $post_id ),
|
||||
];
|
||||
|
||||
return $metaboxes;
|
||||
}
|
||||
}
|
||||
103
inc/agent/class-opalestate-agent-posttype.php
Executable file
103
inc/agent/class-opalestate-agent-posttype.php
Executable file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Opalestate_PostType_Agent
|
||||
*
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
|
||||
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* @website http://www.wpopal.com
|
||||
* @support http://www.wpopal.com/support/forum.html
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Opalestate_PostType_Agent {
|
||||
|
||||
/**
|
||||
* Opalestate_PostType_Agent constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'init', [ __CLASS__, 'definition' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Post type and taxonomies
|
||||
*/
|
||||
public static function definition() {
|
||||
if ( ! is_blog_installed() || post_type_exists( 'opalestate_agent' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$labels = [
|
||||
'name' => esc_html__( 'Agents', 'opalestate-pro' ),
|
||||
'singular_name' => esc_html__( 'Property', 'opalestate-pro' ),
|
||||
'add_new' => esc_html__( 'Add New Agent', 'opalestate-pro' ),
|
||||
'add_new_item' => esc_html__( 'Add New Agent', 'opalestate-pro' ),
|
||||
'edit_item' => esc_html__( 'Edit Agent', 'opalestate-pro' ),
|
||||
'new_item' => esc_html__( 'New Agent', 'opalestate-pro' ),
|
||||
'all_items' => esc_html__( 'All Agents', 'opalestate-pro' ),
|
||||
'view_item' => esc_html__( 'View Agent', 'opalestate-pro' ),
|
||||
'search_items' => esc_html__( 'Search Agent', 'opalestate-pro' ),
|
||||
'not_found' => esc_html__( 'No Agents found', 'opalestate-pro' ),
|
||||
'not_found_in_trash' => esc_html__( 'No Agents found in Trash', 'opalestate-pro' ),
|
||||
'parent_item_colon' => '',
|
||||
'menu_name' => esc_html__( 'Agents', 'opalestate-pro' ),
|
||||
];
|
||||
|
||||
$labels = apply_filters( 'opalestate_postype_agent_labels', $labels );
|
||||
|
||||
register_post_type( 'opalestate_agent',
|
||||
apply_filters( 'opalestate_agent_post_type_parameters', [
|
||||
'labels' => $labels,
|
||||
'supports' => [ 'title', 'editor', 'thumbnail', 'comments', 'author', 'excerpt' ],
|
||||
'public' => true,
|
||||
'has_archive' => true,
|
||||
'menu_position' => 51,
|
||||
'categories' => [],
|
||||
'menu_icon' => 'dashicons-groups',
|
||||
'rewrite' => [ 'slug' => esc_html_x( 'agent', 'agent slug', 'opalestate-pro' ) ],
|
||||
] )
|
||||
);
|
||||
|
||||
static::register_taxonomies();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Agency Agency Taxonomy
|
||||
*/
|
||||
private static function register_taxonomies() {
|
||||
/// Register Agent Levels
|
||||
$labels = [
|
||||
'name' => esc_html__( 'Agent Levels', 'opalestate-pro' ),
|
||||
'singular_name' => esc_html__( 'Level', 'opalestate-pro' ),
|
||||
'search_items' => esc_html__( 'Search Level', 'opalestate-pro' ),
|
||||
'all_items' => esc_html__( 'All Levels', 'opalestate-pro' ),
|
||||
'parent_item' => esc_html__( 'Parent Level', 'opalestate-pro' ),
|
||||
'parent_item_colon' => esc_html__( 'Parent Level:', 'opalestate-pro' ),
|
||||
'edit_item' => esc_html__( 'Edit Level', 'opalestate-pro' ),
|
||||
'update_item' => esc_html__( 'Update Level', 'opalestate-pro' ),
|
||||
'add_new_item' => esc_html__( 'Add New Level', 'opalestate-pro' ),
|
||||
'new_item_name' => esc_html__( 'New Level Name', 'opalestate-pro' ),
|
||||
'menu_name' => esc_html__( 'Agent Levels', 'opalestate-pro' ),
|
||||
];
|
||||
///
|
||||
register_taxonomy( 'opalestate_agent_level', [ 'opalestate_agent' ],
|
||||
[
|
||||
'hierarchical' => true,
|
||||
'labels' => $labels,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'query_var' => true,
|
||||
'show_in_nav_menus' => true,
|
||||
'rewrite' => [
|
||||
'slug' => esc_html_x( 'agent-level', 'agent level slug', 'opalestate-pro' ),
|
||||
],
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
new Opalestate_PostType_Agent();
|
||||
20
inc/agent/class-opalestate-agent-query.php
Executable file
20
inc/agent/class-opalestate-agent-query.php
Executable file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* $Desc$
|
||||
*
|
||||
* @version $Id$
|
||||
* @package $package$
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @copyright Copyright (C) 2014 wpopal.com. All Rights Reserved.
|
||||
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* @website http://www.wpopal.com
|
||||
* @support http://www.wpopal.com/support/forum.html
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( !defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
class Opalestate_Agent_Query extends OpalEstate_Abstract_Query {
|
||||
|
||||
}
|
||||
277
inc/agent/class-opalestate-agent.php
Executable file
277
inc/agent/class-opalestate-agent.php
Executable file
@@ -0,0 +1,277 @@
|
||||
<?php
|
||||
/**
|
||||
* $Desc$
|
||||
*
|
||||
* @version $Id$
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
|
||||
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* @website http://www.wpopal.com
|
||||
* @support http://www.wpopal.com/support/forum.html
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* @class OpalEstate_Agent
|
||||
*
|
||||
* @version 1.0
|
||||
*/
|
||||
class OpalEstate_Agent {
|
||||
|
||||
/**
|
||||
* @var String $author_name
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected $author_name;
|
||||
|
||||
/**
|
||||
* @var Boolean $is_featured
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected $is_featured;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct( $post_id = null ) {
|
||||
|
||||
global $post;
|
||||
|
||||
if ( $post ) {
|
||||
$this->post = $post;
|
||||
$this->post_id = $post_id ? $post_id : get_the_ID();
|
||||
$this->author = get_userdata( $post->post_author );
|
||||
$this->author_name = ! empty( $this->author ) ? sprintf( '%s %s', $this->author->first_name, $this->author->last_name ) : null;
|
||||
$this->is_featured = $this->get_meta( 'featured' );
|
||||
$this->is_trusted = $this->get_meta( 'trusted' );
|
||||
}
|
||||
}
|
||||
|
||||
public function get_id() {
|
||||
return $this->post_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Collection Of soicals with theirs values
|
||||
*/
|
||||
public function get_socials() {
|
||||
$socials = [
|
||||
'facebook' => '',
|
||||
'twitter' => '',
|
||||
'pinterest' => '',
|
||||
'google' => '',
|
||||
'instagram' => '',
|
||||
'linkedIn' => '',
|
||||
];
|
||||
|
||||
$output = [];
|
||||
|
||||
foreach ( $socials as $social => $k ) {
|
||||
|
||||
$data = $this->get_meta( $social );
|
||||
if ( $data && $data != "#" && ! empty( $data ) ) {
|
||||
$output[ $social ] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get url of user avatar by agent id
|
||||
*/
|
||||
public static function get_avatar_url( $userID ) {
|
||||
return get_post_meta( $userID, OPALESTATE_AGENT_PREFIX . "avatar", true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render list of levels of agent
|
||||
*/
|
||||
public function render_level() {
|
||||
$levels = wp_get_post_terms( $this->get_id(), 'opalestate_agent_level' );
|
||||
|
||||
if ( empty( $levels ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$output = '<span class="agent-levels">';
|
||||
foreach ( $levels as $key => $value ) {
|
||||
$output .= '<span class="agent-label"><span>' . $value->name . '</span></span>';
|
||||
}
|
||||
$output .= '</span>';
|
||||
|
||||
echo $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* get meta data value of key without prefix
|
||||
*/
|
||||
public function get_meta( $key ) {
|
||||
return get_post_meta( $this->get_id(), OPALESTATE_AGENT_PREFIX . $key, true );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return true if this agent is featured
|
||||
*/
|
||||
public function is_featured() {
|
||||
return $this->is_featured;
|
||||
}
|
||||
|
||||
/**
|
||||
* render block information by id
|
||||
*/
|
||||
public static function render_box_info( $post_id ) {
|
||||
|
||||
}
|
||||
|
||||
public static function get_link( $agent_id ) {
|
||||
$agent = get_post( $agent_id );
|
||||
$url = self::get_avatar_url( $agent_id );
|
||||
|
||||
return [
|
||||
'name' => $agent->post_title,
|
||||
'avatar' => $url,
|
||||
'link' => get_permalink( $agent->ID ),
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
public static function metaboxes_fields() {
|
||||
$metabox = new Opalestate_Agent_MetaBox();
|
||||
$fields = $metabox->metaboxes_admin_fields();
|
||||
|
||||
return array_merge_recursive( $fields, $metabox->get_social_fields( OPALESTATE_AGENT_PREFIX ) );
|
||||
}
|
||||
|
||||
public static function update_user_data( $user_id ) {
|
||||
|
||||
$fields = self::metaboxes_fields();
|
||||
|
||||
$others = [
|
||||
'avatar_id' => '',
|
||||
'opalestate_agt_map' => '',
|
||||
'map' => '',
|
||||
];
|
||||
foreach ( $fields as $key => $field ) {
|
||||
$kpos = $field['id'];
|
||||
$tmp = str_replace( OPALESTATE_AGENT_PREFIX, '', $field['id'] );
|
||||
if ( isset( $_POST[ $kpos ] ) && $tmp ) {
|
||||
$data = is_string( $_POST[ $kpos ] ) ? sanitize_text_field( $_POST[ $kpos ] ) : $_POST[ $kpos ];
|
||||
update_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . $tmp, $data );
|
||||
}
|
||||
}
|
||||
|
||||
// update for others
|
||||
foreach ( $others as $key => $value ) {
|
||||
$kpos = OPALESTATE_AGENT_PREFIX . $key;
|
||||
if ( isset( $_POST[ $kpos ] ) ) {
|
||||
$data = is_string( $_POST[ $kpos ] ) ? sanitize_text_field( $_POST[ $kpos ] ) : $_POST[ $kpos ];
|
||||
update_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . $key, $data );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function get_trusted() {
|
||||
return $this->is_trusted;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function update_data_from_user( $related_id ) {
|
||||
|
||||
|
||||
$fields = self::metaboxes_fields();
|
||||
|
||||
$others = [
|
||||
'avatar_id' => '',
|
||||
'map' => '',
|
||||
];
|
||||
foreach ( $fields as $key => $field ) {
|
||||
|
||||
$tmp = str_replace( OPALESTATE_AGENT_PREFIX, "", $field['id'] );
|
||||
$kpos = OPALESTATE_USER_PROFILE_PREFIX . $tmp;
|
||||
|
||||
if ( isset( $_POST[ $kpos ] ) && $tmp ) {
|
||||
$data = is_string( $_POST[ $kpos ] ) ? sanitize_text_field( $_POST[ $kpos ] ) : $_POST[ $kpos ];
|
||||
update_post_meta( $related_id, OPALESTATE_AGENT_PREFIX . $tmp, $data );
|
||||
}
|
||||
}
|
||||
|
||||
// update for others
|
||||
foreach ( $others as $key => $value ) {
|
||||
$kpos = OPALESTATE_USER_PROFILE_PREFIX . $key;
|
||||
if ( isset( $_POST[ $kpos ] ) ) {
|
||||
$data = is_string( $_POST[ $kpos ] ) ? sanitize_text_field( $_POST[ $kpos ] ) : $_POST[ $kpos ];
|
||||
update_post_meta( $related_id, OPALESTATE_AGENT_PREFIX . $key, $data );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rating count.
|
||||
*
|
||||
* @param string $context What the value is for. Valid values are view and edit.
|
||||
* @return int
|
||||
*/
|
||||
public function get_rating_counts() {
|
||||
return $this->get_meta( 'rating_count' ) ? $this->get_meta( 'rating_count' ) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get average rating.
|
||||
*
|
||||
* @param string $context What the value is for. Valid values are view and edit.
|
||||
* @return float
|
||||
*/
|
||||
public function get_average_rating() {
|
||||
return $this->get_meta( 'average_rating' ) ? $this->get_meta( 'average_rating' ) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get review count.
|
||||
*
|
||||
* @param string $context What the value is for. Valid values are view and edit.
|
||||
* @return int
|
||||
*/
|
||||
public function get_review_count() {
|
||||
return $this->get_meta( 'review_count' ) ? $this->get_meta( 'review_count' ) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function get_rating_count_stats() {
|
||||
return $this->get_meta( 'rating_count_stats' ) ? $this->get_meta( 'rating_count_stats' ) : [
|
||||
5 => 0,
|
||||
4 => 0,
|
||||
3 => 0,
|
||||
2 => 0,
|
||||
1 => 0,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function get_rating_average_stats() {
|
||||
return $this->get_meta( 'rating_average_stats' );
|
||||
}
|
||||
|
||||
public function get_count_listing() {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
0
inc/agent/functions.php
Executable file
0
inc/agent/functions.php
Executable file
Reference in New Issue
Block a user