Update API
This commit is contained in:
parent
ff39207b86
commit
d5bb6abe51
@ -115,7 +115,7 @@ class OpalEstate_Agency {
|
||||
* 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 );
|
||||
return get_post_meta( $userID, OPALESTATE_AGENCY_PREFIX . 'avatar', true );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -223,11 +223,19 @@ class OpalEstate_Agency {
|
||||
*/
|
||||
public static function get_link( $agency_id ) {
|
||||
$agency = get_post( $agency_id );
|
||||
if ( ! $agency ) {
|
||||
return [
|
||||
'name' => '',
|
||||
'avatar' => '',
|
||||
'link' => '',
|
||||
];
|
||||
}
|
||||
|
||||
$url = self::get_avatar_url( $agency_id );
|
||||
|
||||
return [
|
||||
'name' => $agency->post_title,
|
||||
'avatar' => $url,
|
||||
'avatar' => $url ? $url : '',
|
||||
'link' => get_permalink( $agency->ID ),
|
||||
];
|
||||
}
|
||||
|
@ -134,6 +134,15 @@ class OpalEstate_Agent {
|
||||
|
||||
public static function get_link( $agent_id ) {
|
||||
$agent = get_post( $agent_id );
|
||||
|
||||
if ( ! $agent ) {
|
||||
return [
|
||||
'name' => '',
|
||||
'avatar' => '',
|
||||
'link' => '',
|
||||
];
|
||||
}
|
||||
|
||||
$url = self::get_avatar_url( $agent_id );
|
||||
|
||||
return [
|
||||
@ -141,7 +150,6 @@ class OpalEstate_Agent {
|
||||
'avatar' => $url,
|
||||
'link' => get_permalink( $agent->ID ),
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
public static function metaboxes_fields() {
|
||||
|
@ -227,8 +227,7 @@ class Property_Api extends Base_Api {
|
||||
$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();
|
||||
|
||||
$property['author_data'] = $data->get_author_link_data();
|
||||
|
||||
return apply_filters( 'opalestate_api_properties_property', $property );
|
||||
}
|
||||
|
@ -427,11 +427,22 @@ class Opalestate_Property {
|
||||
*
|
||||
*/
|
||||
public function render_author_link() {
|
||||
switch ( $this->get_author_type() ) {
|
||||
|
||||
case 'hide':
|
||||
|
||||
$data = $this->get_author_link_data();
|
||||
if ( ! $data ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$avatar = $data['avatar'] ? $data['avatar'] : opalestate_get_image_avatar_placehold();
|
||||
$avatar = '<img class="avatar" src="' . esc_url( $avatar ) . '" alt="' . $data['name'] . '" />';
|
||||
|
||||
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>';
|
||||
}
|
||||
|
||||
public function get_author_link_data() {
|
||||
$data = [];
|
||||
switch ( $this->get_author_type() ) {
|
||||
case 'hide':
|
||||
$data = [];
|
||||
break;
|
||||
|
||||
case 'agent':
|
||||
@ -448,28 +459,25 @@ class Opalestate_Property {
|
||||
break;
|
||||
}
|
||||
|
||||
$avatar = $data['avatar'] ? $data['avatar'] : opalestate_get_image_avatar_placehold();
|
||||
$avatar = '<img class="avatar" src="' . esc_url( $avatar ) . '" alt="' . $data['name'] . '" />';
|
||||
|
||||
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>';
|
||||
return $data;
|
||||
}
|
||||
|
||||
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 );
|
||||
$user_id = get_post_field( 'post_author', $this->get_id() );
|
||||
$image_id = get_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'avatar_id', true );
|
||||
$related_id = get_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', true );
|
||||
|
||||
if ( $image_id ) {
|
||||
$url = wp_get_attachment_url( $image_id );
|
||||
} else {
|
||||
$url = get_avatar_url( get_the_author_meta( 'email' ) );
|
||||
$url = get_avatar_url( get_the_author_meta( 'email', $user_id ) );
|
||||
}
|
||||
|
||||
if ( $related_id ) {
|
||||
$authorlink = get_permalink( $related_id );
|
||||
$author = get_the_title( $related_id );
|
||||
} else {
|
||||
$authorlink = get_author_posts_url( get_the_author_meta( 'ID' ) );
|
||||
$authorlink = get_author_posts_url( $user_id );
|
||||
$author = get_the_author();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user