コード例 #1
0
 public function register_rest_api_property_fields()
 {
     $field_array = array('department', 'latitude', 'longitude', 'price', 'price_formatted', 'currency', 'price_qualifier', 'sale_by', 'tenure', 'deposit', 'furnished', 'available_date', 'bedrooms', 'bathrooms', 'reception_rooms', 'property_type', 'parking', 'outside_space', 'featured', 'availability', 'marketing_flags', 'features', 'description', 'office');
     foreach ($field_array as $field) {
         register_rest_field('property', $field, array('get_callback' => function ($object, $field_name, $request) {
             $property = new PH_Property($object['id']);
             switch ($field_name) {
                 case "price":
                     if ($property->poa != 'yes') {
                         if ($property->department == 'residential-lettings') {
                             return $property->rent;
                         } else {
                             return $property->price;
                         }
                     }
                     return '';
                 case "price_formatted":
                     return $property->get_formatted_price();
                     break;
                 case "features":
                     return $property->get_features();
                     break;
                 case "description":
                     return $property->get_formatted_description();
                     break;
                 case "office":
                     return array('name' => $property->office_name, 'address' => $property->office_address, 'telephone_number' => $property->office_telephone_number, 'email_address' => $property->office_email_address);
                     break;
                 default:
                     return $property->{$field_name};
             }
         }, 'update_callback' => null, 'schema' => null));
     }
 }