This commit is contained in:
ThemeLexus 2019-10-02 13:34:39 +07:00
parent 4f1e33c9a9
commit 78bf24be34
3 changed files with 37 additions and 5 deletions

View File

@ -114,7 +114,15 @@ class OpalEstate_Agency {
/**
* Get url of user avatar by agency id
*/
public static function get_avatar_url( $userID ) {
public static function get_avatar_url( $userID ) {
$id = get_post_meta( $userID, OPALESTATE_AGENCY_PREFIX . 'avatar_id', true );;
$url = wp_get_attachment_image_url( $id, 'thumbnail' );
if( $url ) {
return $url;
}
return get_post_meta( $userID, OPALESTATE_AGENCY_PREFIX . 'avatar', true );
}

View File

@ -45,10 +45,10 @@ class Property_Api extends Base_Api {
'permission_callback' => [ $this, 'validate_request' ],
] );
/// call http://domain.com/wp-json/job-api/v1/job/1 ////
/// call http://domain.com/wp-json/job-api/v1/estate/1 ////
register_rest_route( $this->namespace, $this->base . '/(?P<id>\d+)', [
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'get_job' ],
'callback' => [ $this, 'get_property' ],
'permission_callback' => [ $this, 'validate_request' ],
] );
@ -189,6 +189,30 @@ class Property_Api extends Base_Api {
return $this->get_response( 200, $response );
}
/**
* Get Property
*
* Based on request to get collection
*
* @return WP_REST_Response is json data
* @since 1.0
*
*/
public function get_property( $request ) {
$response = [];
if ( $request['id'] > 0 ) {
$post = get_post( $request['id'] );
if ( $post && 'opalestate_property' == get_post_type( $request['id'] ) ) {
$this->get_response( 200, $response );
}
$property = $this->get_property_data( $post );
$response['property'] = $property ? $property : [];
}
return $this->get_response( 200, $response );
}
/**
* Opalestaten a opalestate_property post object, generate the data for the API output

View File

@ -467,8 +467,8 @@ class Opalestate_Property {
$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 );
if ( $image_id ) {
$url = wp_get_attachment_image_url( $image_id, 'thumbnail' );
} else {
$url = get_avatar_url( get_the_author_meta( 'email', $user_id ) );
}