From 78bf24be34b7e9f7ac7df8e485cbad44ef8df159 Mon Sep 17 00:00:00 2001 From: ThemeLexus Date: Wed, 2 Oct 2019 13:34:39 +0700 Subject: [PATCH] uapte --- inc/agency/class-opalestate-agency.php | 10 +++++++- inc/api/v1/property.php | 28 ++++++++++++++++++++-- inc/property/class-opalestate-property.php | 4 ++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/inc/agency/class-opalestate-agency.php b/inc/agency/class-opalestate-agency.php index 55150b02..64b32265 100755 --- a/inc/agency/class-opalestate-agency.php +++ b/inc/agency/class-opalestate-agency.php @@ -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 ); } diff --git a/inc/api/v1/property.php b/inc/api/v1/property.php index 020ab999..46382d54 100644 --- a/inc/api/v1/property.php +++ b/inc/api/v1/property.php @@ -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\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 diff --git a/inc/property/class-opalestate-property.php b/inc/property/class-opalestate-property.php index c6cdb8c8..09ba2235 100755 --- a/inc/property/class-opalestate-property.php +++ b/inc/property/class-opalestate-property.php @@ -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 ) ); }