Origin commit
This commit is contained in:
482
inc/agency/class-opalestate-agency-front.php
Executable file
482
inc/agency/class-opalestate-agency-front.php
Executable file
@@ -0,0 +1,482 @@
|
||||
<?php
|
||||
/**
|
||||
* Opalestate_Agency_Front
|
||||
*
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Opalestate_Agency_Front {
|
||||
|
||||
/**
|
||||
* Instance.
|
||||
*
|
||||
* @access private
|
||||
* @var Opalestate_Agent_Front
|
||||
*/
|
||||
static private $instance;
|
||||
|
||||
/**
|
||||
* Singleton pattern.
|
||||
*
|
||||
* @since $Id
|
||||
* @access private
|
||||
*/
|
||||
private function __construct() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get instance.
|
||||
*
|
||||
* @return Opalestate_Agent_Front
|
||||
* @since $Id
|
||||
* @access public
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( null === static::$instance ) {
|
||||
self::$instance = new static();
|
||||
|
||||
self::$instance->init();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public $new_attachmenet_ids;
|
||||
|
||||
/**
|
||||
* Auto update meta information to post from user data updated or created
|
||||
*/
|
||||
public function init() {
|
||||
add_action( 'opalestate_on_set_role_agency', [ $this, 'on_set_role' ], 1, 9 );
|
||||
add_filter( 'opalestate_before_render_profile_agency_form', [ $this, 'render_front_form' ], 2, 2 );
|
||||
|
||||
add_action( 'save_post', [ $this, 'on_save_post' ], 13, 2 );
|
||||
add_filter( 'pre_get_posts', [ $this, 'archives_query' ], 1 );
|
||||
add_action( 'cmb2_after_init', [ $this, 'on_save_front_data' ] );
|
||||
|
||||
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' ] );
|
||||
|
||||
$this->register_shortcodes();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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_agency' ) {
|
||||
$menu['agency_profile'] = [
|
||||
'icon' => 'fa fa-user',
|
||||
'link' => "agency_profile",
|
||||
'title' => esc_html__( 'Agency Profile', 'opalestate-pro' ),
|
||||
'id' => 0,
|
||||
];
|
||||
$menu['agency_team'] = [
|
||||
'icon' => 'fa fa-users',
|
||||
'link' => "agency_team",
|
||||
'title' => esc_html__( 'Agency Team', 'opalestate-pro' ),
|
||||
'id' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
return $menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto update meta information to post from user data updated or created
|
||||
*/
|
||||
public function archives_query( $query ) {
|
||||
if ( $query->is_main_query() && is_post_type_archive( 'opalestate_agency' ) ) {
|
||||
if ( isset( $_GET['location'] ) && $_GET['location'] != -1 ) {
|
||||
$tax_query = [];
|
||||
|
||||
$tax_query[] = [
|
||||
'taxonomy' => 'opalestate_location',
|
||||
'field' => 'slug',
|
||||
'terms' => sanitize_text_field( $_GET['location'] ),
|
||||
];
|
||||
$args['tax_query'] = [ 'relation' => 'AND' ];
|
||||
$args['tax_query'] = array_merge( $args['tax_query'], $tax_query );
|
||||
$query->set( 'tax_query', $tax_query );
|
||||
}
|
||||
if ( isset( $_GET['search_text'] ) ) {
|
||||
$query->set( 's', sanitize_text_field( $_GET['search_text'] ) );
|
||||
}
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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_agency_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_agency',
|
||||
'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 );
|
||||
|
||||
if ( empty( $post->post_content ) || empty( $post->post_title ) || ! has_post_thumbnail( $post_id ) ) {
|
||||
|
||||
// $data['post_status'] = 'public';
|
||||
// $data['ID'] = $post_id;
|
||||
// $post_id = wp_update_post( $data , true );
|
||||
}
|
||||
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, sanitize_text_field( $_POST[ $prefix . 'featured_image' ] ) );
|
||||
unset( $_POST[ $prefix . 'featured_image' ] );
|
||||
} else {
|
||||
delete_post_thumbnail( $post_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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private function get_field_name( $field ) {
|
||||
return OPALESTATE_AGENCY_PREFIX . $field;
|
||||
}
|
||||
|
||||
private function process_upload_files( $post_id ) {
|
||||
|
||||
//upload images for featured and gallery images
|
||||
if ( isset( $_FILES ) && ! empty( $_FILES ) ) {
|
||||
|
||||
///
|
||||
$fields = [
|
||||
$this->get_field_name( 'avatar_id' ),
|
||||
$this->get_field_name( 'gallery' ),
|
||||
$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'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process upload images for properties
|
||||
*/
|
||||
public function upload_image( $submitted_file, $parent_id = 0 ) {
|
||||
return opalesate_upload_image( $submitted_file, $parent_id );
|
||||
}
|
||||
|
||||
public function on_save_front_data() {
|
||||
|
||||
if ( isset( $_POST[ 'nonce_CMB2php' . OPALESTATE_AGENCY_PREFIX . 'front' ] ) ) {
|
||||
|
||||
$post_id = isset( $_POST['object_id'] ) && $_POST['object_id'] ? absint( $_POST['object_id'] ) : 0;
|
||||
|
||||
$post = get_post( $post_id );
|
||||
|
||||
$post_id = $this->update_data_agent_or_agency( OPALESTATE_AGENCY_PREFIX );
|
||||
|
||||
if ( $post_id ) {
|
||||
OpalEstate_Agency::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' => 'agency_profile' ] ),
|
||||
]
|
||||
);
|
||||
|
||||
return opalestate_output_msg_json( false,
|
||||
__( 'Currently, The data could not save!', 'opalestate-pro' ),
|
||||
[ 'heading' => esc_html__( 'Update Information', 'opalestate-pro' ) ]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function register_shortcodes() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function render_profile() {
|
||||
|
||||
$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" );
|
||||
}
|
||||
|
||||
$metaboxes = $this->render_front_form( [], $post_id );
|
||||
|
||||
return opalestate_load_template_path( 'user/agency/profile-agency', [ 'metaboxes' => $metaboxes, 'post_id' => $post_id ] );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function render_team() {
|
||||
$user_id = get_current_user_id();
|
||||
$post_id = OpalEstate_User::get_member_id();
|
||||
|
||||
$metaboxes = $this->render_front_form( [], $post_id );
|
||||
|
||||
return opalestate_load_template_path( 'user/agency/agency-team', [ 'metaboxes' => $metaboxes, 'post_id' => $post_id ] );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function process_action_member() {
|
||||
if ( isset( $_POST['add_team_action'] ) && wp_verify_nonce( $_POST['add_team_action'], 'agency-add-member' ) ) {
|
||||
|
||||
if ( isset( $_POST['user_id'] ) ) {
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
$post_id = OpalEstate_User::get_member_id();
|
||||
|
||||
$team = get_post_meta( $post_id, OPALESTATE_AGENCY_PREFIX . 'team', true );
|
||||
|
||||
if ( empty( $team ) ) {
|
||||
$team = [];
|
||||
}
|
||||
$team[] = intval( $_POST['user_id'] );
|
||||
$team = array_unique( $team );
|
||||
|
||||
update_post_meta( $post_id, OPALESTATE_AGENCY_PREFIX . 'team', $team );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $_GET['tab'] ) && $_GET['tab'] == "agency_team" && isset( $_GET['remove_id'] ) && $_GET['remove_id'] ) {
|
||||
|
||||
$remove_id = intval( $_GET['remove_id'] );
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
$post_id = OpalEstate_User::get_member_id();
|
||||
|
||||
$team = get_post_meta( $post_id, OPALESTATE_AGENCY_PREFIX . 'team', true );
|
||||
|
||||
if ( empty( $team ) ) {
|
||||
$team = [];
|
||||
}
|
||||
$team[] = $user_id;
|
||||
$team = array_unique( $team );
|
||||
foreach ( $team as $key => $id ) {
|
||||
if ( $id == $remove_id ) {
|
||||
unset( $team[ $key ] );
|
||||
}
|
||||
}
|
||||
update_post_meta( $post_id, OPALESTATE_AGENCY_PREFIX . 'team', $team );
|
||||
|
||||
wp_redirect( opalestate_get_user_management_page_uri( [ 'tab' => 'agency_team' ] ) );
|
||||
die;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function on_save_post( $post_id ) {
|
||||
$post_type = get_post_type( $post_id );
|
||||
if ( $post_type == 'opalestate_agency' ) {
|
||||
if ( isset( $_POST[ OPALESTATE_AGENCY_PREFIX . 'user_id' ] ) && $_POST[ OPALESTATE_AGENCY_PREFIX . 'user_id' ] ) {
|
||||
update_user_meta( $_POST[ OPALESTATE_AGENCY_PREFIX . 'user_id' ], OPALESTATE_USER_PROFILE_PREFIX . 'related_id', $post_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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'] = '=';
|
||||
$args['post_status'] = [ 'publish', 'pending' ];
|
||||
|
||||
$post = get_posts( $args );
|
||||
|
||||
if ( empty( $post ) ) {
|
||||
|
||||
$agency_id = self::create_agency( [], $user_id );
|
||||
update_post_meta( $agency_id, OPALESTATE_AGENCY_PREFIX . 'user_id', $user_id );
|
||||
update_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', $agency_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function create_agency( $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,
|
||||
'avatar' => '',
|
||||
'job' => '',
|
||||
'email' => '',
|
||||
'phone' => '',
|
||||
'mobile' => '',
|
||||
'fax' => '',
|
||||
'web' => '',
|
||||
'address' => '',
|
||||
'twitter' => '',
|
||||
'facebook' => '',
|
||||
'google' => '',
|
||||
'linkedin' => '',
|
||||
'instagram' => '',
|
||||
] );
|
||||
|
||||
|
||||
$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_content' => 'empty description',
|
||||
'post_excerpt' => 'empty excerpt',
|
||||
'post_type' => 'opalestate_agency',
|
||||
'post_status' => 'pending',
|
||||
'post_author' => $user_id,
|
||||
], true );
|
||||
|
||||
|
||||
do_action( 'opalesate_insert_user_agency', $agency_id );
|
||||
|
||||
return $agency_id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function render_front_form( $metaboxes, $post_id = 0 ) {
|
||||
$metabox = new Opalestate_Agency_MetaBox();
|
||||
|
||||
return $metabox->render_front_form( $metaboxes, $post_id );
|
||||
}
|
||||
}
|
||||
|
||||
Opalestate_Agency_Front::get_instance();
|
||||
389
inc/agency/class-opalestate-agency-metabox.php
Executable file
389
inc/agency/class-opalestate-agency-metabox.php
Executable file
@@ -0,0 +1,389 @@
|
||||
<?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_Agency_MetaBox extends Opalestate_User_MetaBox {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function metaboxes_target() {
|
||||
|
||||
$prefix = OPALESTATE_AGENCY_PREFIX;
|
||||
$fields = [
|
||||
[
|
||||
'id' => "{$prefix}user_id",
|
||||
'name' => esc_html__( 'Link To User ID', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'Set relationship to existed user, allow user can edit Agency profile in front-end and show account info in each property.', 'opalestate-pro' ),
|
||||
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Agent Team', 'opalestate-pro' ),
|
||||
'desc' => esc_html__( 'Select one, to add new you create in location of estate panel', 'opalestate-pro' ),
|
||||
'id' => $prefix . "team",
|
||||
'type' => 'adduser',
|
||||
],
|
||||
];
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function metaboxes_admin_fields( $prefix = '' ) {
|
||||
|
||||
if ( ! $prefix ) {
|
||||
$prefix = OPALESTATE_AGENCY_PREFIX;
|
||||
}
|
||||
|
||||
$fields = [
|
||||
[
|
||||
'id' => "{$prefix}featured",
|
||||
'name' => esc_html__( 'Is Featured', 'opalestate-pro' ),
|
||||
'type' => 'switch',
|
||||
'description' => esc_html__( 'Set this agent as featured', 'opalestate-pro' ),
|
||||
'options' => [
|
||||
0 => esc_html__( 'No', 'opalestate-pro' ),
|
||||
1 => esc_html__( 'Yes', 'opalestate-pro' ),
|
||||
],
|
||||
|
||||
],
|
||||
];
|
||||
|
||||
$fields = array_merge_recursive( $fields,
|
||||
$this->get_base_fields( $prefix ),
|
||||
$this->get_address_fields( $prefix )
|
||||
);
|
||||
|
||||
return apply_filters( 'opalestate_postype_agency_metaboxes_fields', $fields );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function get_front_fields( $prefix ) {
|
||||
return [
|
||||
'id' => $prefix . 'front',
|
||||
'title' => esc_html__( 'Name and Description', 'opalestate-pro' ),
|
||||
'object_types' => [ 'opalestate_property' ],
|
||||
'context' => 'normal',
|
||||
'object_types' => [ 'user' ], // Tells CMB2 to use user_meta vs post_meta
|
||||
'priority' => 'high',
|
||||
'show_names' => true,
|
||||
'fields' => $this->get_fields( $prefix ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function get_fields( $prefix ) {
|
||||
|
||||
$management = [
|
||||
[
|
||||
'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' => is_admin() ? 'file' : 'opal_upload',
|
||||
'avatar' => true,
|
||||
'before_row' => '<div class="' . apply_filters( 'opalestate_row_container_class', 'row opal-row' ) . '"> <div class="col-lg-4">',
|
||||
'after_row' => '</div>',
|
||||
],
|
||||
|
||||
[
|
||||
'id' => 'first_name',
|
||||
'name' => esc_html__( 'First Name', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'attributes' => [
|
||||
'required' => 'required',
|
||||
],
|
||||
'before_row' => '<div class="col-lg-8">',
|
||||
|
||||
],
|
||||
[
|
||||
'id' => 'last_name',
|
||||
'name' => esc_html__( 'Last Name', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'attributes' => [
|
||||
'required' => 'required',
|
||||
],
|
||||
],
|
||||
|
||||
[
|
||||
'id' => 'description',
|
||||
'name' => esc_html__( 'Biographical Info', 'opalestate-pro' ),
|
||||
'type' => 'textarea',
|
||||
'description' => esc_html__( 'Share a little biographical information to fill out your profile. This may be shown publicly.', 'opalestate-pro' ),
|
||||
|
||||
'after_row' => '</div></div>',
|
||||
],
|
||||
[
|
||||
'id' => "{$prefix}job",
|
||||
'name' => esc_html__( 'Title/Job', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'Please enter position or job in your company.', 'opalestate-pro' ),
|
||||
'before_row' => '<div class="clearfix clear"></div><hr><div class="row-group-features group-has-two clearfix"><h3>' . __( 'Information', 'opalestate-pro' ) . '</h3>', // callback
|
||||
],
|
||||
|
||||
[
|
||||
'id' => "{$prefix}company",
|
||||
'name' => esc_html__( 'company', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'Please enter company name.', 'opalestate-pro' ),
|
||||
],
|
||||
[
|
||||
'id' => "{$prefix}email",
|
||||
'name' => esc_html__( 'Contact email', 'opalestate-pro' ),
|
||||
'type' => 'text_email',
|
||||
'description' => esc_html__( 'Enter contact name that allow user contact you via the contact form of website.', 'opalestate-pro' ),
|
||||
],
|
||||
|
||||
[
|
||||
'id' => "{$prefix}phone",
|
||||
'name' => esc_html__( 'Phone', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'Enter your home phone.', 'opalestate-pro' ),
|
||||
],
|
||||
|
||||
[
|
||||
'id' => "{$prefix}skype",
|
||||
'name' => esc_html__( 'Skype', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'Input for skype account.', 'opalestate-pro' ),
|
||||
],
|
||||
|
||||
[
|
||||
'id' => "url",
|
||||
'name' => esc_html__( 'Website URL', 'opalestate-pro' ),
|
||||
'type' => 'text_url',
|
||||
'description' => esc_html__( 'Link to your website', 'opalestate-pro' ),
|
||||
'after_row' => '</div>',
|
||||
],
|
||||
|
||||
[
|
||||
'id' => "{$prefix}facebook",
|
||||
'name' => esc_html__( 'Facebook', 'opalestate-pro' ),
|
||||
'type' => 'text_url',
|
||||
'description' => esc_html__( 'Enter your facebook profile or facebook newfeed', 'opalestate-pro' ),
|
||||
'before_row' => '<div class="row-group-features group-has-two group-price clearfix"><h3>' . __( 'Social', 'opalestate-pro' ) . '</h3>', // callback
|
||||
],
|
||||
|
||||
[
|
||||
'id' => "{$prefix}linkedin",
|
||||
'name' => esc_html__( 'Linkedin URL', 'opalestate-pro' ),
|
||||
'type' => 'text_url',
|
||||
'description' => esc_html__( 'Input for linked in profile.', 'opalestate-pro' ),
|
||||
],
|
||||
[
|
||||
'id' => "{$prefix}instagram",
|
||||
'name' => esc_html__( 'Instagram URL', 'opalestate-pro' ),
|
||||
'type' => 'text_url',
|
||||
'description' => esc_html__( 'Input for instagram profile.', 'opalestate-pro' ),
|
||||
],
|
||||
[
|
||||
'id' => "{$prefix}pinterest",
|
||||
'name' => esc_html__( 'Pinterest Url', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'Input for pinterest feed', 'opalestate-pro' ),
|
||||
],
|
||||
|
||||
[
|
||||
'id' => "{$prefix}googleplus",
|
||||
'name' => esc_html__( 'Google Plus Url', 'opalestate-pro' ),
|
||||
'type' => 'text_url',
|
||||
'description' => esc_html__( 'Input for goolge plus profile or your newfeed.', 'opalestate-pro' ),
|
||||
],
|
||||
|
||||
[
|
||||
'id' => "{$prefix}youtube",
|
||||
'name' => esc_html__( 'Youtube Url', 'opalestate-pro' ),
|
||||
'type' => 'text_url',
|
||||
'description' => esc_html__( 'Input for your channel youtube.', 'opalestate-pro' ),
|
||||
],
|
||||
|
||||
[
|
||||
'id' => "{$prefix}vimeo",
|
||||
'name' => esc_html__( 'Vimeo Url', 'opalestate-pro' ),
|
||||
'type' => 'text_url',
|
||||
'description' => esc_html__( 'Input for your channel Vimeo', 'opalestate-pro' ),
|
||||
'after_row' => '</div>',
|
||||
],
|
||||
];
|
||||
|
||||
return $management;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function metaboxes_front_fields( $prefix = '', $post_id = 0 ) {
|
||||
if ( ! $prefix ) {
|
||||
$prefix = OPALESTATE_AGENCY_PREFIX;
|
||||
}
|
||||
$post = get_post( $post_id );
|
||||
|
||||
$fields = [
|
||||
|
||||
[
|
||||
'id' => $prefix . 'post_type',
|
||||
'type' => 'hidden',
|
||||
'default' => 'opalestate_agency',
|
||||
],
|
||||
[
|
||||
'id' => 'post_id',
|
||||
'type' => 'hidden',
|
||||
'default' => $post_id,
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Title / Name', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'title',
|
||||
'type' => 'text',
|
||||
'default' => ! empty( $post ) ? $post->post_title : '',
|
||||
'attributes' => [
|
||||
'required' => 'required',
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'slogan', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}slogan",
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'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',
|
||||
'type' => 'taxonomy_select',
|
||||
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
$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_office_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,
|
||||
'avatar' => true,
|
||||
|
||||
],
|
||||
[
|
||||
'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,
|
||||
'avatar' => true,
|
||||
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Gallery', 'opalestate-pro' ),
|
||||
'desc' => esc_html__( 'Select one, to add new you create in location of estate panel', 'opalestate-pro' ),
|
||||
'id' => $prefix . "gallery",
|
||||
'type' => 'uploader',
|
||||
'after_row' => '<hr>',
|
||||
],
|
||||
[
|
||||
'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_AGENCY_PREFIX;
|
||||
|
||||
$metaboxes[ $prefix . 'front' ] = [
|
||||
'id' => $prefix . 'front',
|
||||
'title' => esc_html__( 'Agency Information', 'opalestate-pro' ),
|
||||
'object_types' => [ 'opalestate_agency' ],
|
||||
'context' => 'normal',
|
||||
'priority' => 'high',
|
||||
'show_names' => true,
|
||||
'cmb_styles' => false,
|
||||
'fields' => $this->metaboxes_front_fields( $prefix, $post_id ),
|
||||
];
|
||||
|
||||
return $metaboxes;
|
||||
}
|
||||
}
|
||||
103
inc/agency/class-opalestate-agency-posttype.php
Executable file
103
inc/agency/class-opalestate-agency-posttype.php
Executable file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Opalestate_PostType_Agency
|
||||
*
|
||||
* @version $Id$
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @copyright Copyright (C) 2016 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_Agency
|
||||
*
|
||||
* @version 1.0
|
||||
*/
|
||||
class Opalestate_PostType_Agency {
|
||||
|
||||
/**
|
||||
* Init
|
||||
*/
|
||||
public static function init() {
|
||||
add_action( 'init', [ __CLASS__, 'definition' ] );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register Post type and taxonomies
|
||||
*/
|
||||
public static function definition() {
|
||||
if ( ! is_blog_installed() || post_type_exists( 'opalestate_agency' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$labels = [
|
||||
'name' => esc_html__( 'Agencies', 'opalestate-pro' ),
|
||||
'singular_name' => esc_html__( 'Property', 'opalestate-pro' ),
|
||||
'add_new' => esc_html__( 'Add New Agency', 'opalestate-pro' ),
|
||||
'add_new_item' => esc_html__( 'Add New Agency', 'opalestate-pro' ),
|
||||
'edit_item' => esc_html__( 'Edit Agency', 'opalestate-pro' ),
|
||||
'new_item' => esc_html__( 'New Agency', 'opalestate-pro' ),
|
||||
'all_items' => esc_html__( 'All Agencies', 'opalestate-pro' ),
|
||||
'view_item' => esc_html__( 'View Agency', 'opalestate-pro' ),
|
||||
'search_items' => esc_html__( 'Search Agency', 'opalestate-pro' ),
|
||||
'not_found' => esc_html__( 'No Agencies found', 'opalestate-pro' ),
|
||||
'not_found_in_trash' => esc_html__( 'No Agencies found in Trash', 'opalestate-pro' ),
|
||||
'parent_item_colon' => '',
|
||||
'menu_name' => esc_html__( 'Agencies', 'opalestate-pro' ),
|
||||
];
|
||||
|
||||
$labels = apply_filters( 'opalestate_postype_agency_labels', $labels );
|
||||
|
||||
register_post_type( 'opalestate_agency',
|
||||
apply_filters( 'opalestate_agency_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( 'agency', 'agency slug', 'opalestate-pro' ) ],
|
||||
] )
|
||||
);
|
||||
|
||||
///
|
||||
$labels = [
|
||||
'name' => esc_html__( 'Agency Categories', 'opalestate-pro' ),
|
||||
'singular_name' => esc_html__( 'Category', 'opalestate-pro' ),
|
||||
'search_items' => esc_html__( 'Search Category', 'opalestate-pro' ),
|
||||
'all_items' => esc_html__( 'All Categories', 'opalestate-pro' ),
|
||||
'parent_item' => esc_html__( 'Parent Category', 'opalestate-pro' ),
|
||||
'parent_item_colon' => esc_html__( 'Parent Category:', 'opalestate-pro' ),
|
||||
'edit_item' => esc_html__( 'Edit Category', 'opalestate-pro' ),
|
||||
'update_item' => esc_html__( 'Update Category', 'opalestate-pro' ),
|
||||
'add_new_item' => esc_html__( 'Add New Category', 'opalestate-pro' ),
|
||||
'new_item_name' => esc_html__( 'New Category Name', 'opalestate-pro' ),
|
||||
'menu_name' => esc_html__( 'Agency Categories', 'opalestate-pro' ),
|
||||
];
|
||||
///
|
||||
register_taxonomy( 'opalestate_agency_cat', [ 'opalestate_agency' ],
|
||||
[
|
||||
'hierarchical' => true,
|
||||
'labels' => $labels,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'query_var' => true,
|
||||
'show_in_nav_menus' => true,
|
||||
'rewrite' => [
|
||||
'slug' => esc_html_x( 'agency-category', 'agency category slug', 'opalestate-pro' ),
|
||||
],
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
Opalestate_PostType_Agency::init();
|
||||
20
inc/agency/class-opalestate-agency-query.php
Executable file
20
inc/agency/class-opalestate-agency-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_Agency_Query extends OpalEstate_Abstract_Query {
|
||||
|
||||
}
|
||||
306
inc/agency/class-opalestate-agency.php
Executable file
306
inc/agency/class-opalestate-agency.php
Executable file
@@ -0,0 +1,306 @@
|
||||
<?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_Agency
|
||||
*
|
||||
* @version 1.0
|
||||
*/
|
||||
class OpalEstate_Agency {
|
||||
|
||||
/**
|
||||
* @var String $author_name
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected $author_name;
|
||||
|
||||
/**
|
||||
* @var Boolean $is_featured
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected $is_featured;
|
||||
|
||||
/**
|
||||
* Get A Instance Of Opalestate_Property
|
||||
*/
|
||||
public static function get_instance( $post_id = null ) {
|
||||
static $_instance;
|
||||
if ( ! $_instance ) {
|
||||
$_instance = new OpalEstate_Agency( $post_id );
|
||||
}
|
||||
|
||||
return $_instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct( $post_id = null ) {
|
||||
|
||||
global $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 agency id
|
||||
*/
|
||||
public static function get_avatar_url( $userID ) {
|
||||
|
||||
return get_post_meta( $userID, OPALESTATE_AGENCY_PREFIX . "avatar", true );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Render list of levels of agency
|
||||
*/
|
||||
public function render_level() {
|
||||
$levels = wp_get_post_terms( $this->post_id, 'opalestate_agency_cat' );
|
||||
|
||||
if ( empty( $levels ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$output = '<span class="agency-levels">';
|
||||
foreach ( $levels as $key => $value ) {
|
||||
$output .= '<span class="agency-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_AGENCY_PREFIX . $key, true );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return true if this agency is featured
|
||||
*/
|
||||
public function is_featured() {
|
||||
return $this->is_featured;
|
||||
}
|
||||
|
||||
|
||||
public function render_avatar() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* render block information by id
|
||||
*/
|
||||
public static function render_box_info( $post_id ) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function get_gallery() {
|
||||
return $this->get_meta( 'gallery' );
|
||||
}
|
||||
|
||||
|
||||
public function get_trusted() {
|
||||
return $this->is_trusted;
|
||||
}
|
||||
|
||||
public function get_members() {
|
||||
$team = [];
|
||||
$ids = get_post_meta( $this->post_id, OPALESTATE_AGENCY_PREFIX . 'team', true );
|
||||
|
||||
foreach ( $ids as $id ) {
|
||||
$user = get_user_by( 'id', $id ); // echo '<pre>' . print_r( $user, 1 );die;
|
||||
$team[] = [
|
||||
'id' => $user->ID,
|
||||
'name' => $user->display_name,
|
||||
'avatar_url' => OpalEstate_User::get_author_picture( $user->ID ),
|
||||
'username' => $user->user_login,
|
||||
'description' => 'okokok',
|
||||
];
|
||||
}
|
||||
|
||||
return $team;
|
||||
}
|
||||
|
||||
public static function get_link( $agency_id ) {
|
||||
$agency = get_post( $agency_id );
|
||||
$url = self::get_avatar_url( $agency_id );
|
||||
|
||||
return [
|
||||
'name' => $agency->post_title,
|
||||
'avatar' => $url,
|
||||
'link' => get_permalink( $agency->ID ),
|
||||
];
|
||||
}
|
||||
|
||||
public static function metaboxes_fields() {
|
||||
$metabox = new Opalestate_Agency_MetaBox();
|
||||
$fields = $metabox->metaboxes_admin_fields();
|
||||
|
||||
return array_merge_recursive( $fields, $metabox->get_social_fields( OPALESTATE_AGENCY_PREFIX ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 static function update_user_data( $user_id ) {
|
||||
|
||||
$fields = self::metaboxes_fields();
|
||||
|
||||
$others = [
|
||||
'avatar_id' => '',
|
||||
'map' => '',
|
||||
];
|
||||
|
||||
foreach ( $fields as $key => $field ) {
|
||||
$kpos = $field['id'];
|
||||
$tmp = str_replace( OPALESTATE_AGENCY_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_AGENCY_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 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_AGENCY_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_AGENCY_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_AGENCY_PREFIX . $key, $data );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
0
inc/agency/functions.php
Executable file
0
inc/agency/functions.php
Executable file
Reference in New Issue
Block a user