diff --git a/inc/agent/class-opalestate-agent-front.php b/inc/agent/class-opalestate-agent-front.php index b366b1f6..2ff4d7fa 100755 --- a/inc/agent/class-opalestate-agent-front.php +++ b/inc/agent/class-opalestate-agent-front.php @@ -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 ); - $post = get_post( $post_id ); + // 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 ); + } - 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" ); + $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 ); @@ -310,29 +315,29 @@ class Opalestate_Agent_Front { 'agent_carousel' => [ 'code' => 'agent_carousel', 'label' => esc_html__( 'Agent Carousel', 'opalestate-pro' ) ], ]; - foreach ( $this->shortcodes as $shortcode ) { + foreach ( $this->shortcodes as $shortcode ) { add_shortcode( 'opalestate_' . $shortcode['code'], [ $this, $shortcode['code'] ] ); } } - public function agent_carousel ( $atts ) { + public function agent_carousel( $atts ) { - $atts = is_array( $atts ) ? $atts : []; - $layout = 'search-agency-form'; + $atts = is_array( $atts ) ? $atts : []; + $layout = 'search-agency-form'; + + $default = [ + 'current_uri' => null, + 'column' => 4, + 'limit' => 12, + 'paged' => 1, + 'onlyfeatured' => 0, + 'form' => $layout, + ]; - $default = array( - 'current_uri' => null, - 'column' => 4, - 'limit' => 12, - 'paged' => 1, - 'onlyfeatured' => 0, - 'form' => $layout - ); - $atts = array_merge( $default, $atts ); - return opalestate_load_template_path( 'shortcodes/agent-carousel' , $atts ); + return opalestate_load_template_path( 'shortcodes/agent-carousel', $atts ); } public function archives_query( $query ) { @@ -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; diff --git a/inc/api/v1/property.php b/inc/api/v1/property.php index 9dd7fceb..0c323cf2 100755 --- a/inc/api/v1/property.php +++ b/inc/api/v1/property.php @@ -233,7 +233,9 @@ class Property_Api extends Base_Api { $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 ); } diff --git a/inc/property/class-opalestate-property.php b/inc/property/class-opalestate-property.php index e9669d94..7c75601b 100755 --- a/inc/property/class-opalestate-property.php +++ b/inc/property/class-opalestate-property.php @@ -454,7 +454,7 @@ class Opalestate_Property { return '' . $avatar . '' . $data['name'] . ''; } - 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 ); diff --git a/templates/single-property/author-v2.php b/templates/single-property/author-v2.php index 259e54e4..106e1336 100755 --- a/templates/single-property/author-v2.php +++ b/templates/single-property/author-v2.php @@ -50,7 +50,7 @@ switch ( $type ) { break; } ?> -
+
diff --git a/templates/single-property/author-v3.php b/templates/single-property/author-v3.php index 51c26751..a83e08e5 100755 --- a/templates/single-property/author-v3.php +++ b/templates/single-property/author-v3.php @@ -44,7 +44,7 @@ switch ( $type ) { break; } ?> -
+
diff --git a/templates/single-property/author.php b/templates/single-property/author.php index 876e742d..c0656eab 100755 --- a/templates/single-property/author.php +++ b/templates/single-property/author.php @@ -44,7 +44,7 @@ switch ( $type ) { break; } ?> -
+